Skip to main content

Crate kcode_k1_daemon_lib

Crate kcode_k1_daemon_lib 

Source
Expand description

§K1 daemon library

kcode-k1-daemon-lib is the library-only composition root for one private K1 loopback daemon. Each public operation owns a process-lifetime Tokio runtime, startup, readiness output, SIGINT/SIGTERM shutdown, and fixed safe failure output. Call an operation exactly once from a small local binary.

§Operations and local models

run(PathBuf) is the compatibility operation. It starts the current daemon with an empty process-local model catalog, so its behavior remains unchanged apart from using the current People generation:

use std::path::PathBuf;

fn main() -> std::process::ExitCode {
    kcode_k1_daemon_lib::run(PathBuf::from("/srv/k1"))
}

run_with_models(PathBuf, Arc<[LocalModel]>) starts the same daemon with an immutable, caller-owned local-host model catalog. Construct each LocalModel with kcode_k1_http_people::LocalModel (also re-exported by this crate), build an Arc<[LocalModel]>, and retain no expectation that this library will persist, probe, or discover those models. Under this operation, the People model GET, PUT, and DELETE API is available through the K1 HTTP People leaf. Duplicate model IDs fail safe during startup and reveal no identity details.

use std::{path::PathBuf, sync::Arc};
use kcode_k1_daemon_lib::{LocalModel, run_with_models};

fn main() -> std::process::ExitCode {
    let models: Arc<[LocalModel]> = Arc::from([]);
    run_with_models(PathBuf::from("/srv/k1"), models)
}

This crate defines no binary target, CLI parsing, environment configuration, installation, migration, deployment behavior, or model configuration source.

§Root and state

The supplied trusted root maps only to <root>/state/. That state root retains the current DaemonFiles, ordering, peering, invites, accounts, groups, access-profile, replay, and invite-stock ownership and formats. It creates no Web roots and validates or serves neither web/ nor web-modules/.

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 authentication, signing, replay, CORS, envelopes, and route semantics. Unknown non-API paths use Axum’s ordinary 404.

Kennedy Server may serve the browser UI separately on port 4321. Fresh stock links resolve the latest stable published K1 UI through Kennedy Server’s SemVer route and have the form http://localhost:4321/lib/kcode-k1-ui/*/account.html?invite=<code>. This is distinct from the http://localhost:4450 backend public/signing origin. This library remains only the loopback API backend and preserves the existing cross-origin K1 HTTP behavior; it does not serve, copy, proxy, or discover the UI.

§Output and failure

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. This library has no Web hosting, static fallback, SemVer module routes, proxy, UI copying, or browser acceptance guarantee.

Structs§

LocalModel

Functions§

run
Runs one K1 daemon with an empty local model catalog until SIGINT or SIGTERM.
run_with_models
Runs one K1 daemon with a process-local immutable local model catalog.