docs: how an assistant and a command reach the books under the app (WB-app-1, 3, 5)

WB-app-1 and WB-app-3 lose the permanent run/app-hosted marker; WB-app-5 is
new: a command finds what runs, never starts a host, and with nothing running
runs a server of its own for the work or says "Start Wanderbooks first", with
the table command by command. architecture.md, deploy/README.md and
mcp-interface.md say the app is the host and only serve keeps a detached one.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Fable 5.2 committed 2026-11-21 11:34:19 -07:00
1 parent e9a520138d
commit 6b95ce59ad
4 files changed
+147 -32

No files matched your search

+9
View File
@@ -203,6 +203,15 @@ door with the token. Logs:
journalctl -u wanderbooks-server -f
```
`serve` is the one program that starts a host: on this machine there is no
app, so an assistant's bridge (`wanderbooks mcp`) reaches the books only
while `serve` runs, and otherwise says in words that Wanderbooks isn't
running and to run `wanderbooks serve`. The owner's commands (`wanderbooks
books …`, `token …`) work with `serve` stopped, running a server of their
own for the length of the work, except those that need a company open
(`books open`/`close`, `upload`, `download`), which say to start
Wanderbooks first.
The server runs no jobs in the background: `serve` holds the books open
until systemd stops it. On a stop it finishes the call in progress, makes
a last backup and closes (3.9), so `TimeoutStopSec=600` is generous rather
+32 -4
View File
@@ -36,7 +36,7 @@ the specification in `bookspec/` (which never depends on the engine).
| `ledger-import` | formats: QuickBooks CSV in; IIF, XLSX, Typst PDFs (statements, the invoice, labels, the audit workpaper) out | `ledger-core`, `ledger-reader` |
| `ledger-package` | the shared read-only view over `Store` or `Snapshot` (`PackageBooks`): the CPA package, the 1099 worksheet, the invoice document, Needs attention | `ledger-core`, `ledger-store`, `ledger-config`, `ledger-import`, `ledger-vault` |
| `ledger-mcp` | the books server: the MCP tools (122), resources, the handbook, scopes, the door and the access log, backups' scheduling | all of the above |
| `ledger-host` | the host and its leases, the agent bridge (`wanderbooks mcp`), tokens in 0600 files under the data root (D-63), the owner's commands, uploads and downloads, `update` and `rollback` (P11a), books homes and how to start an agent in one (P11b) | `ledger-store`, `ledger-mcp`, `ledger-config` |
| `ledger-host` | the app's books server as the window's child (`app_server`, P15), the headless host and its leases (`serve` alone starts one), the agent bridge (`wanderbooks mcp`, a line to whatever runs), tokens in 0600 files under the data root (D-63), the owner's commands, uploads and downloads, `update` and `rollback` (P11a), books homes and how to start an agent in one (P11b) | `ledger-store`, `ledger-mcp`, `ledger-config` |
| `ledger-gui` | the viewer: read-only, live, egui, one window with a tab per open company (P15); the Books menu hands work to the server; the agent dock and the first-run page (P11b) | `ledger-core`, `ledger-store`, `ledger-config`, `ledger-import`, `ledger-package`, `ledger-vault`, `ledger-host` |
| `ledger-cli` | `wanderbooks`, the one executable: every mode (`serve`, `server`, `host`, `mcp`, `gui`, `setup`, `books`, `token`, `connect`, `doctor`, `licenses`, …) and the over-the-wire test suites | everything |
| `bookspec/checker`, `bookspec/runner` | the example schema and parser, the rule catalogue, the `Engine` trait; the per-rule runner | nothing of ours (the adapter in `ledger-core`'s tests depends on them) |
@@ -432,6 +432,32 @@ inward from the adapter. `just check` runs the bookspec workspace's
format, clippy and tests beside the wanderbooks workspace's, so an example
cannot rot (P13 step 1).
## How an assistant, or a command, reaches the books (P15, D-77, D-84)
The desktop app is the host. It starts the books server as its own child
(`ledger-host`'s `app_server.rs`) and closes it by closing its input. No
other program on the desktop starts a detached host: a company is reachable
by an assistant exactly while the app has it open.
- `wanderbooks mcp --book X` (the bridge) is a line to `run/mcp.sock`. With
the app closed it answers the assistant in words that Wanderbooks isn't
running and how to start it (the app, or `wanderbooks serve` on a computer
with no screen); it is never a host and holds no lease unless a headless
host holds the root.
- The owner's commands (`books`, `token`, `connect`, `doctor`, `close`) find
what holds the root. With the app (or a `serve` host) running they ask its
server. With nothing running, a command that only reads or manages the
books' files runs a server of its own for the length of the work and
closes it, under the same `run/server.lock` and `run/books.lock`; one that
needs a company held open says "Start Wanderbooks first". WB-app-5 has the
table, command by command.
- `wanderbooks serve` keeps the host, its leases, the 10 s close delay, the
scrubbed start, the restart onto a replaced program and the daily update
look, for the headless build (P9a); it is the only program that starts one.
- Nothing marks a root as the app's; whose the books are is read from the
locks and the admin socket. The `run/app-hosted` file an earlier build
wrote is ignored and removed.
## Self-host: the same server, another account (P9a, D-51)
The books can live on a machine the owner controls (plan 3.8). It is the
@@ -510,15 +536,17 @@ downgrading is theirs). Anything else (an AppImage, whose file is named by
looks at the feed at most once a day (`update_check` knob; the look is
noted in `updates/checked`), and only downloads and verifies a newer
release into `<root>/updates/staged/`. It never swaps. The staged program
is applied by an opener just before it starts a host (no host runs, so no
call is cut off), after a second check against the key, or by
is applied by `wanderbooks serve` just before it starts its host (no host
runs, so no call is cut off), after a second check against the key, or by
`wanderbooks update`, the owner's say-so, which reuses the staged copy. A
local release is named in `<root>/updates/feed` (a `file://` address, then
the key file), the same rule as `--trusted-key`;
- **the owner accepts one in the app**: the viewer reads the staged
`meta.json` (`Owner::update_waiting`) and shows a notice with "Update
now", and Books has "Check for updates" (`Owner::check_for_updates`) and
"Update to X"; accepting is the host's lease intent `apply_update`, which
"Update to X"; accepting is the headless host's lease intent `apply_update`
(with no host, the program installs the staged copy itself; the desktop app's
own update is an ordinary app update, settled by the packaging unit), which
installs the staged copy as `update` does and lets the host's own
replaced-program watch restart onto it once no call runs. `books.start`
carries the same notice to an agent as `update_waiting`, with a next step
+8 -5
View File
@@ -187,8 +187,8 @@ features) is refused before anything is journaled, its error beginning
go-ahead, with the owner passphrase, in the app or with `wanderbooks
books upgrade ID` at a terminal, and that no tool can. No tool consents:
none is offered, and the server takes the go-ahead only on its admin
socket, from the host's lease intent `consent_format_upgrade` (the app's
dialog, `books upgrade`), with the passphrase it checks. Before the
socket, as an admin request from the app's dialog or `books upgrade` (or the
headless host's lease intent `consent_format_upgrade`), with the passphrase it checks. Before the
upgrade the server commits the books to their own backup repository and
proves the copy holds them exactly (journal, stored files, vault, keys);
then one `journal.format_set` declares the whole format, and the same
@@ -264,9 +264,12 @@ as it is made.
Books are served one way (plan D-44): by the books server, which agents
reach through the bridge.
- **Served books** (`wanderbooks server`, started by the host; an agent
connects with `wanderbooks mcp --book ID`, the bridge: stdio to the
agent, the server's socket upstream): every book
- **Served books** (`wanderbooks server`, started by the desktop app as its
child, or by the host `wanderbooks serve` keeps on a headless machine; an
agent connects with `wanderbooks mcp --book ID`, the bridge: stdio to the
agent, the server's socket upstream; with nothing running it answers in
words that Wanderbooks isn't running and to start the app or `wanderbooks
serve`: WB-app-3): every book
in the data root that is open (all of them at the start, unless
`wanderbooks server --open none|ID[,ID…]` says otherwise; one is opened
or closed while the server runs, "Opening and closing one book" below),
+98 -23
View File
@@ -28,14 +28,17 @@ by the window or stopped: one that is alive but not yet ready (opening big
companies, or waiting for another server to finish) is waited for, in view;
a start that fails, or a window closed before the start has the child,
closes the child's input and waits for it, so none is left running that
nothing manages. The `run/app-hosted` marker, written by every start, is
permanent: nothing ever removes it, so a root the app has served is the
app's for good. A headless user who ran the desktop app once on a root sees,
from then on, an agent's bridge (`wanderbooks mcp`) answer "Wanderbooks isn't
running" when no app runs, and not start a host on demand as it did before;
a host they start themselves (`wanderbooks serve`) holds the root and the
bridge uses it as always (WB-app-3). Deleting the marker by hand gives the
root back to the on-demand host.
nothing manages. Nothing marks a root as the app's: an earlier build wrote a permanent
`run/app-hosted` file, which means nothing now and is removed at the next
start of the app's server; a root that has one works as one that does not.
Whose the books are is read from what runs (WB-app-5). The server is in a
process group of its own on Unix, so a Ctrl+C at the terminal the window
was started from reaches the window alone and never closes the books under
an open window; on Windows it breaks away from the job a launcher runs the
window in (and, where that job does not allow it, runs inside it), so a
launcher whose job kills everything in it when the window dies does not kill
the server in the middle of a backup: the window's death reaches it as the
end of its input, and it closes cleanly.
*Enforced:* `ledger_host::app_server::AppServer` (`start_in`, `stop`, its
drop), `AppHost::start` and `AppHost::stop`, `ANOTHER_HAS_THEM`; the server's own close, ledger-mcp
`local::run` (INVARIANT 6).
@@ -45,7 +48,10 @@ drop), `AppHost::start` and `AppHost::stop`, `ANOTHER_HAS_THEM`; the server's ow
`a_stop_that_runs_out_of_time_leaves_the_server_closing_and_says_so`,
`a_server_that_never_gets_ready_is_stopped_with_the_window_and_not_left_behind`,
`a_window_closed_before_the_child_was_stored_stops_the_child`,
`a_late_server_is_waited_for_and_stays_the_windows_to_manage`).
`a_late_server_is_waited_for_and_stays_the_windows_to_manage`,
`a_mark_an_earlier_build_left_is_ignored_and_removed`,
`a_terminal_ctrl_c_reaches_the_window_and_never_the_server`). The Windows
breakaway is checked by type only; no test runs it.
**WB-app-2 A tab is a company open in the server.** A company has a tab
exactly while the server has it open to assistants: the companies the
@@ -81,24 +87,34 @@ request to this same server (`UpgradeFormat`), since there is no host.
`an_open_that_did_not_happen_says_why`).
**WB-app-3 The bridge speaks to the running app and says so in words.**
`wanderbooks mcp --book X` connects to the root's `run/mcp.sock`. For a
root the app has served (it wrote `run/app-hosted`) with no host holding
it, the bridge holds no lease and starts no host. With the app not
running, every call is answered "Wanderbooks isn't running: start
Wanderbooks and open X."; with the app running but the company not open in
it, "Company X isn't open: open it in Wanderbooks." Neither answer is
final: the call after the app starts, or the company is opened, goes
through, in a session already running. A root no app has served, and any
root a host holds (`wanderbooks serve`, the headless host), behave as they
did: the bridge holds a lease and starts a host.
*Enforced:* `ledger_host::bridge` (`serves_the_app`, `keep_in_app`,
`not_running_words`, `not_open_words`), INVARIANT 12.
`wanderbooks mcp --book X` connects to the root's `run/mcp.sock`. With no
host holding the root (every root but a headless `wanderbooks serve`'s), it
holds no lease and starts no host: no program starts one but `serve`. With
nothing running, every call is answered "Wanderbooks isn't running: start
Wanderbooks and open X (on a computer with no screen, run `wanderbooks
serve`), then try again."; with a server holding the books and no socket yet
(the app opening large companies, or finishing a last backup), "Wanderbooks
is still opening its companies, or finishing the last backup of the last
session: X can be reached in a moment. Try again shortly."; with the app
running but the company not open in it, "Company X isn't open: open it in
Wanderbooks." None is final: the call after the app starts, or the company
is opened, goes through, in a session already running. A root a host holds
(`wanderbooks serve`) is served as it was: the bridge holds a lease on the
host; and when that host goes and nothing takes its place the bridge says
the words above instead of starting another.
*Enforced:* `ledger_host::bridge` (`serves_the_app`, `keep_in_app`, `keep`,
`not_running_words`, `opening_words`, `not_open_words`), INVARIANT 12;
`ledger_host::opener::Opener::hold` (INVARIANTS 6, 7).
*Checked:* `ledger-host` bridge tests (`with_the_app_not_running_every_call_is_answered_in_words`,
`with_a_server_still_opening_the_answer_says_so_and_not_that_nothing_runs`,
`with_the_app_running_a_company_that_is_not_open_is_said_in_words`,
`a_host_bridge_passes_the_servers_words_on_as_they_are`);
`a_host_bridge_passes_the_servers_words_on_as_they_are`,
`a_root_is_the_line_to_the_app_when_no_host_holds_it`);
`ledger-cli` `app_server.rs` (`the_bridge_says_the_app_isnt_running_then_works_once_it_is`: not
running, then running with the company closed, then open, then closed
again, then the window closed, in one session, with no host started).
again, then the window closed, in one session, with no host started);
`open_while_held.rs` (`a_command_leaves_nothing_running_and_serve_closes_after_its_last_holder`:
a bridge with nothing running starts no host).
**WB-app-4 Closing the window is bounded and visible.** Asked to close, the
window stays up and says it is closing the books (finishing what is
@@ -121,3 +137,62 @@ their companies.
(`a_stop_that_runs_out_of_time_leaves_the_server_closing_and_says_so`,
`a_closing_backup_that_was_not_whole_is_said_when_the_window_closes`,
`a_server_that_exits_badly_is_said_when_the_window_closes`).
**WB-app-5 A command finds what runs, never starts a host, and does its
work or says to start Wanderbooks.** Every `wanderbooks …` command that
needs the books, and the window's own menu work, finds what holds the root:
a host (`wanderbooks serve`: it takes a lease, as before), the app's server
(no host holds the root, a server holds `run/server.lock`, and its admin
socket answers: it asks that server and leaves it running), or nothing. A
server that holds the lock and has no admin socket yet is opening its
companies or finishing a backup: the command says so ("Wanderbooks is still
opening (or closing) the books: waiting for it…") and waits, for as long as
its own wait lasts (`open_wait`, 120 s), then says it is still opening and
to try again; it never fails with a connection error and never starts a
second server beside it. With nothing running, no command starts a host.
One that only reads, or manages the books' files and tokens, runs a books
server of its own, the one the app starts, for the length of the work and
closes it (waiting for its last backup, 90 s at most, and saying so if it
is still finishing); it takes the same `run/server.lock` and `run/books.lock`
the app's server takes, so two programs never hold one set of books, and a
start is refused in words when another has them. One that needs a company
held open by Wanderbooks says "Start Wanderbooks first: nothing has the
books open. Open the Wanderbooks app, or, on a computer with no screen, run
`wanderbooks serve` and leave it running." `wanderbooks serve` is the only
program that starts a detached host (the headless path); it keeps the lease
protocol, the 10 s close delay, the scrubbed environment, the restart onto a
replaced program and its daily look for an update.
| Command | The app (or `serve`) running | Nothing running |
|---|---|---|
| `books list` | the server's list, open or closed | the folder's companies, "not open", no lock taken (nothing is read of them) |
| `books create`, `adopt`, `restore` | the server does it | its own server, no company open, closed after |
| `books put-aside` | works on the folder itself, as it always has: it never asked a server, and moves only copies outside the root into `legacy/` after reading the company's journal head; it takes no lock | the same |
| `books back-up ID`, `books upgrade ID`, `books extract ID N` | the server does it (the upgrade as an admin request when there is no host) | its own server with ID open, closed after |
| `books open ID`, `books close ID` | the server opens or closes ID | "Start Wanderbooks first" (there is no server to open it in) |
| `token create`, `list`, `check`, `revoke` | the server's admin socket | its own server (ID open when one is named) |
| `token print` | the token file | the token file (it never asked a server) |
| `connect`, the books home | a token as above, the pointer file | the same, its own server for the token |
| `upload`, `download` | the book's door, with the token's file | "Start Wanderbooks first" |
| `doctor` | says whose the books are and lists them, tokens and assistants | says the books are closed and Wanderbooks isn't running, and how to start it |
| `close` | on a host, closes the books; on the app, says the app's tabs and window do | "already closed" |
| `serve` | on the app, refuses ("the app has these books open"); on a host, joins it | starts the host |
| `mcp` | the bridge (WB-app-3) | the bridge says it in words |
There is no "Close the books" in the app: closing a company's tab closes
the company (WB-app-2) and closing the window closes them all (WB-app-4).
*Enforced:* `ledger_host::opener::Opener::hold` (`HoldError::NotRunning`,
`admin_answers`), `ledger_host::commands` (`direct_for`, `reach`,
`Reached::release`, `listed_while_closed`, `upgrade_by_admin`, `doctor`,
`close`).
*Checked:* `ledger-cli` `app_server.rs`
(`a_command_with_the_app_running_goes_to_its_server_and_leaves_it_running`,
`with_nothing_running_a_command_runs_its_own_server_or_says_to_start_wanderbooks`,
`a_command_waits_in_words_for_a_server_that_is_still_opening`);
`open_while_held.rs` (`a_command_leaves_nothing_running_and_serve_closes_after_its_last_holder`,
`serve_and_the_bridges_share_one_host_and_one_server`,
`books_commands_hold_the_books_while_they_run`,
`a_command_ends_at_its_deadline_during_a_restart`,
`the_viewers_new_books_are_made_by_the_server`);
`format_upgrade.rs` (`format_upgrade_waits_for_consent`: a command's own
server shows the upgrade its company waits for).