Expand description
§K1 daemon library
kcode-k1-daemon-lib is the library-only composition root for one private K1 loopback daemon.
§Public API
use std::{path::PathBuf, process::ExitCode};
fn main() -> ExitCode {
kcode_k1_daemon_lib::run(PathBuf::from("/srv/k1"))
}run(PathBuf) -> ExitCode is the sole public operation. Call it exactly once from a small local binary. It owns a process-lifetime Tokio runtime, startup, readiness output, SIGINT/SIGTERM shutdown, and fixed safe failure output.
§State and HTTP
The supplied trusted root maps only to <root>/state/. Existing ordering, peering, invites, accounts, groups, access profiles, replay, invite stock, and daemon-file state retain their ownership and formats. Person state is stored under <root>/state/persons/; missing storage is initialized under the Persons contract, while malformed or incompatible state fails startup without migration or reset.
Registration creates each new user’s permanent Person anchor. User reads resolve that anchor to the current canonical Person, while HTTP authentication and Groups/Access authorization continue to use UserId.
The daemon binds only 127.0.0.1:4450; its backend public/signing origin and accepted single Host authority are exactly http://localhost:4450 and localhost:4450. It serves /config.json, Terms, registration, /me, exact-ID People, Groups, and Access Profiles through the existing K1 HTTP leaves. Those leaves retain signing, replay, CORS, envelopes, and route semantics. Unknown non-API paths use Axum’s ordinary 404.
Fresh stock links retain the form http://localhost:4321/lib/kcode-k1-ui/*/account.html?invite=<code>. This library defines no binary target, CLI, static Web serving, model or audio host integration, reverse Person lookup, Person listing, migration, reset, proxy, or deployment behavior.
§Output and performance
On readiness, stdout receives one flushed JSON line with event, public_origin, and the reconciled unused invite count. Startup over 100 ms emits the existing structured stderr warning. Startup failure emits only kcode-k1-daemon: startup failed and returns exit code 1; listener failure emits its fixed concise line and returns 1. SIGINT or SIGTERM returns success.
Startup work is linear in retained dependency state and invite reconciliation; request performance follows the selected HTTP leaf and its state owners.