feat(host): web assistants per company, joined to the remote door (P15 B3)

WebAssistants is the switch per company: turning one on makes the link's address,
starts the books server's remote door at it (the door listens on 127.0.0.1 and
gives the app its per-start secret), offers the company, and hands the link the
door; turning off withdraws the company and, with none left, closes the line
first and then the door. A new address stops the door, makes a new label, and
restarts the door at the new issuer, so every token made at the old address is
refused. The switches are kept in a private file and put back for the companies
that are open at the next start. Nothing is half-on after a failed step.

The line runs in the window's process (the viewer owner holds it), so it ends
with the window and never outlives the books it offers. THIRD-PARTY-NOTICES.txt
is regenerated with scripts/notices.sh: the app now links instant-acme, the relay
crate's client side and hickory-proto.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Fable 5.2 committed 2026-11-21 13:40:00 -07:00
1 parent 0f9420aa30
commit 861ed57d82
8 files changed
+2085 -26

No files matched your search

+17 -2
View File
@@ -15,10 +15,11 @@ path = "src/main.rs"
default = ["gui"]
# The viewer. Off in the server-only build for another machine (plan
# D-22, P9), so a headless machine carries no window libraries.
gui = ["dep:ledger-gui"]
gui = ["dep:ledger-gui", "dep:ledger-link"]
[dependencies]
ledger-host = { path = "../ledger-host" }
ledger-link = { path = "../ledger-link", optional = true }
ledger-mcp = { path = "../ledger-mcp" }
ledger-store = { path = "../ledger-store" }
ledger-gui = { path = "../ledger-gui", optional = true }
@@ -36,7 +37,21 @@ reqwest = "0.13"
rusqlite = { version = "0.41", features = ["bundled", "fallible_uint"] }
rust_decimal = "1"
rmcp = { version = "3", features = ["client", "transport-streamable-http-client-reqwest"] }
tokio = { version = "1", features = ["macros", "rt-multi-thread", "time"] }
tokio = { version = "1", features = ["macros", "rt-multi-thread", "time", "net", "io-util"] }
# The web link end to end (tests/web_link.rs): an in-process relay and
# certificate authority, and a web caller that speaks HTTP/1.1 and HTTP/2.
relay = { path = "../relay" }
ledger-link = { path = "../ledger-link" }
rcgen = { version = "0.14", default-features = false, features = ["ring", "pem"] }
rustls = { version = "0.23", default-features = false, features = ["ring", "std", "tls12"] }
tokio-rustls = { version = "0.26", default-features = false, features = ["ring", "tls12"] }
hyper = { version = "1", features = ["client", "http2"] }
hyper-util = { version = "0.1", features = ["tokio"] }
http-body-util = "0.1"
bytes = "1"
futures = "0.3"
zeroize = "1"
time = "0.3"
ledger-config = { path = "../ledger-config" }
ledger-core = { path = "../ledger-core" }
ledger-package = { path = "../ledger-package" }
+53 -3
View File
@@ -76,13 +76,22 @@ struct ViewerOwner {
/// 3.1): started with the window, closed with it. All of what is done
/// with it is `AppHost`'s, which the tests drive.
server: ledger_host::app_server::AppHost,
/// Web assistants: the switch per company, the address and the line to
/// the relay (ledger-host web.rs), in this window's process: the line
/// ends with the window.
web: ledger_host::web::WebAssistants,
}
#[cfg(feature = "gui")]
impl ViewerOwner {
fn new(common: ledger_host::commands::Common) -> Self {
let server = ledger_host::app_server::AppHost::new(common.root.clone());
Self { common, server }
let web = ledger_host::web::WebAssistants::new(common.root.clone());
Self {
common,
server,
web,
}
}
}
@@ -93,7 +102,11 @@ impl ledger_gui::owner::Owner for ViewerOwner {
}
fn serve_start(&self, open: &[String]) -> Result<(), String> {
self.server.start(open)
self.server.start(open)?;
// What was on when the window closed is on again, for the
// companies that are open.
self.web.restore(&self.server, open);
Ok(())
}
fn serve_host_holds(&self) -> bool {
@@ -105,7 +118,9 @@ impl ledger_gui::owner::Owner for ViewerOwner {
}
fn serve_open(&self, book: &str) -> Result<Option<String>, String> {
self.server.open_book(book)
let opened = self.server.open_book(book)?;
self.web.restore(&self.server, &[book.to_string()]);
Ok(opened)
}
fn serve_close(&self, book: &str) -> Result<Option<String>, String> {
@@ -117,6 +132,8 @@ impl ledger_gui::owner::Owner for ViewerOwner {
}
fn serve_stop(&self) -> Result<Option<String>, String> {
// The line closes first: nothing arrives for books that are closing.
self.web.shutdown();
self.server.stop(ledger_host::app_server::STOP_WAIT)
}
@@ -207,6 +224,39 @@ impl ledger_gui::owner::Owner for ViewerOwner {
self.server.web_set_post(approval, post)
}
fn web_state(&self, book: &str) -> Option<ledger_gui::owner::WebConnect> {
use ledger_gui::owner::WebStep;
let s = self.web.state(book);
Some(ledger_gui::owner::WebConnect {
on: s.on,
step: match s.step {
ledger_link::Step::Off => WebStep::Off,
ledger_link::Step::GettingAddress => WebStep::GettingAddress,
ledger_link::Step::Connecting => WebStep::Connecting,
ledger_link::Step::GettingCertificate => WebStep::GettingCertificate,
ledger_link::Step::Connected => WebStep::Connected,
},
address: s.address,
connector: s.connector,
words: s.words,
problem: s.problem,
needs_person: s.needs_person,
kept: s.kept,
})
}
fn web_turn_on(&self, book: &str) -> Result<String, String> {
self.web.turn_on(&self.server, book)
}
fn web_turn_off(&self, book: &str) -> Result<String, String> {
self.web.turn_off(&self.server, book)
}
fn web_new_address(&self, _book: &str) -> Result<String, String> {
self.web.new_address(&self.server)
}
fn serve_revoke(&self, book: &str, name: &str, id: &str) -> Result<String, String> {
self.server.revoke_token(book, name, id)
}