Skip to main content

Module server

Module server 

Source
Expand description

The server module: the shared server of this checkout, and of every other checkout of the same git repository — what each lease says, whether the server it names answers, and whether what answers is the code on disk.

The lease has always carried this — the pid, the address, when the server started, the executable it runs — and nothing served it: a person read the file with cat, a shell recipe parsed it with sed, and a client learned only what the election happened to log. Two readers had grown their own ideas of “ready” on the way (the environment’s connection attempt, the health route’s registry count), and neither asked the question the lease can answer: is the process behind this address current? This is that answer, on every surface the registry projects to, from the one typed reading of the file (crate::lease::LeaseFile).

§One repository, every server of it

A server serves a checkout; a linked worktree is a checkout of its own with a lease of its own, and until now nothing said that the two belong to one repository. The status lists every checkout git registers for the repository, reads the lease of each (through the worktree topology reader), and names the git repository they share (crate::repository::git_identity), so that a session in one worktree can see the servers — and through them the peers — of the others.

§Two questions, two costs

Listing every checkout costs a lease read and a probe per checkout, and a machine with forty worktrees registered pays forty of each. A caller that only wants to know about the checkout it is in says so — checkouts: this — and that answer reads one lease and probes one server; no other checkout is enumerated, read or probed. The default is repository, the whole list, because that is what every caller of this capability got before the field existed.

Read on every call and never cached: the lease is written by other processes.

use majordomus_cli::capability::builtin::server::{
    module, standing_of, Checkouts, ServerStanding, ServerStatusInput,
};
use majordomus_cli::lease::LeaseFile;
use std::time::Duration;

// asking nothing asks the wide question, as it always did
assert_eq!(
    serde_json::from_str::<ServerStatusInput>("{}").unwrap().checkouts,
    Checkouts::Repository
);

// the module composes one capability, and its decision is a pure function
let m = module();
assert_eq!(m.id.as_str(), "server");
assert!(m.capabilities.iter().any(|e| e.capability.id.to_string() == "server.status"));
let (standing, reason) = standing_of(&LeaseFile::Absent, Duration::ZERO, |_| false, "1.0.0");
assert_eq!(standing, ServerStanding::Absent);
assert!(reason.is_none());

Structs§

Desired
What this executable would want a server of this checkout to be: the address it would bind, the version and the executable it would serve from. What standing is measured against.
LeaseView
A lease as a reader sees it: what the server wrote about itself, without the token that makes the file the server’s own.
ServerStatus
The shared server of this checkout and of every other checkout of the repository.
ServerStatusInput
What to ask of server.status: how wide the answer is.
ServerView
One checkout of the repository, and the server its lease names.

Enums§

Checkouts
Which checkouts a reading of the server status covers.
ServerStanding
Where a checkout’s server stands, decided from its lease, whether the server the lease names answers for that checkout, and whether what answers is this executable’s code.

Constants§

SERVER_URI
The URI under which server.status is read as an MCP resource.

Functions§

local_half
The repository-relative path of a checkout’s local half — the directory its lease is written into — or the layer’s default when no manifest can be read at that checkout.
module
The module: one capability, server.status, composed into the application by builtin::modules; adding a second capability to it touches this file alone.
standing_at
Where the server of one checkout stands, with the lease the verdict was read from.
standing_of
Decide where a server stands from what its lease file holds, how old the file is, whether the server it names answers for the checkout, and this executable’s version.