Expand description
tcode serve --http daemon discovery file (issue #3415, DOC-50 §3.4).
Why: tcode tui (crate::tui_client::CodeEngine) needs to find a running
tcode serve --http daemon without the operator copying a port number by
hand. DOC-50 §3.4’s prose sketched a NEW, tcode-specific JSON file
(~/.trusty-code/daemon.json, {daemon_url, pid, started_at}) for this —
but this crate’s siblings already solve the identical problem, and their
convention is different: trusty-memory (which wrote one until #6286 retired both the file and its listener)
and trusty-search (crates/trusty-search/src/service/daemon.rs) both
write the bound host:port as PLAIN TEXT to a file named http_addr
under trusty_common::resolve_data_dir(<app_name>), atomically (tmp +
rename) so a reader never observes a half-written value. This module
follows THAT established convention for tcode instead of inventing a
second, JSON-shaped one: pid/started_at have no consumer anywhere in
this codebase yet, and a plain-text host:port is exactly what
discover_daemon_url (crate::tui_client::discovery) needs to build
http://{addr}.
What: http_addr_path resolves {resolve_data_dir("trusty-code")}/http_addr
(server AND client side share this one path-resolution function so they
can never drift onto two different locations); [write_http_addr_file]
(called from crate::serve::http::run_http after binding) atomically
writes the bound address; [remove_http_addr_file] (called on graceful
shutdown) clears it so a stopped daemon doesn’t leave a stale pointer for
the next reader; [read_http_addr_file] (called from
crate::tui_client::discovery) reads and trims it back. Every operation
is best-effort: a write/remove failure only degrades discovery to the
TCODE_DAEMON_URL env var; a read failure (file absent, stale content,
unreadable) means “no candidate from this source,” not a hard error — the
caller’s overall discovery still fails with a clear, actionable message
when no source yields a live daemon.
Test: discovery_tests::*.
Constants§
- HTTP_
ADDR_ FILENAME - Filename of the discovery file, written under
resolve_data_dir("trusty-code")— mirrors whattrusty-memory’shttp_addrconvention exactly (same filename, same directory-resolution helper, same plain-texthost:portcontent).
Functions§
- http_
addr_ path - Resolve
{resolve_data_dir("trusty-code")}/http_addr, orNoneif the data directory cannot be resolved (matches retiredhttp_addr_pathdid: the degrade-gracefully contract — a resolution failure here is never fatal, only a missing discovery source).