Deploys knox as a headless, always-on replica so agents keep their memory when the laptop is off. Closes #8. **Supersedes #5** (its hardening commit is merged in here; close #5 after this lands). ## What changed **MCP transport + SDK** - Moves from `mark3labs/mcp-go` v0.17 (stdio only, five releases behind) to the official `modelcontextprotocol/go-sdk` v1.8. Tool inputs are typed structs, so schemas are generated instead of hand-built. - Adds `knox mcp --http` (Streamable HTTP). stdio remains the default. **Transport security without a public name** - `KNOX_AUTH_TOKEN` guards gossip and MCP HTTP; `KNOX_TLS_CERT/KEY` serve TLS; `knox tls init` mints a self-signed cert whose SANs are whatever addresses clients dial. Verified: 401 without the token, 200 with, cert valid for the overlay IP. **Daemon hygiene** - SIGTERM shuts down the gossip and metrics servers. - `--version` reports the VCS revision. - `KNOX_LOCAL_SOURCES=none` makes a node ingest nothing but still derive. - Default watch dirs skip paths that do not exist. **Deployment topology fixes** (all found by actually running a replica) - `KNOX_LISTEN_ADDR` split from `KNOX_PEER_ADDR`: a container cannot bind the host's overlay IP, and previously the gossip server silently failed to start. - Reconcile now fires on push and on startup, not only on pull. Three separate bugs left `entries` empty on a push-only node. - Pushes batch by byte budget, not just row count — 500 content-heavy rows exceeded the 4 MiB body limit and the log stalled permanently at 3,000 observations. - Threads and snippets derive on replicas: gating them with the ingesters left the server holding 11.5k observations and 4.9k entries but 2 of 28 threads. **Packaging + CI** - Multi-stage Dockerfile (static, non-root, `/data` volume). - Gitea workflow builds on the dhg.lol daemon through the runner socket, tags `:latest` + `:<sha>`, and restarts the stack when installed. BuildKit cache mounts keep module downloads warm. **sqlc pilot** - Schema extracted to `internal/db/schema.sql` (embedded); read paths behind the MCP tools are generated. - The pilot found real drift: `entries.created_at` existed only as a runtime `ALTER`. It is now declared in the schema, and `sqlcdb_pilot_test.go` fails if generated code disagrees with `db.Open`. - FTS5 stays hand-written: sqlc ignores `CREATE VIRTUAL TABLE`, so `MATCH`/`bm25` cannot be generated. ## Verification - `go vet ./...`, `go test ./...`, `gofmt` clean - `scripts/conformance.sh` — official MCP suite, exit 0 against `conformance-baseline.yml` (documents the capabilities knox does not implement: resources, prompts, completions, fixture tools) - Live: both containers healthy on dhg.lol, ports bound only to the ZeroTier address, 11,553 observations / 4,943 entries replicated and reconciled ## Deploy Infrastructure lives in `tf-net/apps/knox` (separate repo); this branch is what is currently running in production. Reviewed-on: #9 Co-authored-by: David Gwilliam <dhgwilliam@gmail.com> Co-committed-by: David Gwilliam <dhgwilliam@gmail.com>
3.3 KiB
knox
Knowledge index and long-term memory for agents: it ingests opencode sessions, logs, git/Gitea activity, browser history, Obsidian notes and Karakeep bookmarks into a SQLite index with FTS5 search, and exposes it over MCP.
Materialized state is derived from an append-only observation log, so nodes converge by exchanging that log and reconciling — no consensus, no shared writer.
Running it
knox watch # daemon: ingest, gossip sync, Prometheus metrics
knox mcp # MCP over stdio (how an editor/agent runs it locally)
knox query "zig" # one-off search
knox tls init --host 172.30.170.155 --out /data/tls # self-signed cert
State lives in KNOX_DB (default ~/.local/share/knox/index.db).
Remote node (always-on server)
knox watch plus knox mcp --http turn a machine into a replica that answers
MCP requests even when the origin laptop is off. Nothing here requires a public
DNS name: a self-signed certificate and a shared bearer token are enough.
| Variable | Purpose |
|---|---|
KNOX_AUTH_TOKEN |
Bearer token required on gossip and MCP HTTP. Empty disables auth (loopback only). |
KNOX_TLS_CERT / KNOX_TLS_KEY |
Serve TLS. Generate with knox tls init. |
KNOX_TLS_CA |
Client side: trust a peer's self-signed cert. |
KNOX_INSECURE_TLS=1 |
Client side: skip verification (trusted overlay only). |
KNOX_LISTEN_ADDR |
Address the gossip server binds (use 0.0.0.0:8931 in a container). |
KNOX_PEER_ADDR |
Address this node advertises to peers. |
KNOX_PEERS |
Comma-separated seed peers, e.g. https://172.30.170.155:8931. |
KNOX_LOCAL_SOURCES=none |
Replicate only: skip ingest of local files/sessions. |
KNOX_METRICS_ADDR |
Prometheus scrape address (default :8932). |
Ports: 8931 gossip/REST, 8932 metrics, 8930 MCP HTTP.
Seeding a new replica: start it empty and pull, rather than copying index.db —
a copied database carries the origin's node_id, which breaks ownership and
echo suppression.
KNOX_PEERS=https://172.30.170.155:8931 knox gossip sync
knox gossip status
Docker
docker build -t knox:latest .
docker run -d --name knox -p 8931:8931 -p 8932:8932 \
-v /DATA/AppData/knox:/data \
-e KNOX_AUTH_TOKEN=... \
-e KNOX_TLS_CERT=/data/tls/cert.pem -e KNOX_TLS_KEY=/data/tls/key.pem \
knox:latest
A two-process Compose definition (daemon + MCP) lives in the homelab repo under
apps/knox.
Checking the MCP surface
scripts/conformance.sh # throwaway node on a temp DB
KNOX_MCP_URL=https://... scripts/conformance.sh # a running node
Scenarios outside conformance-baseline.yml must pass; the baseline documents
capabilities knox deliberately does not implement (resources, prompts,
completions, and the suite's own fixture tools).
Database changes
Schema lives in internal/db/schema.sql. Queries under internal/db/queries
are compiled to typed Go by sqlc:
go generate ./internal/db # after editing schema.sql or a query
Because sqlc reads schema.sql, every column added by a runtime migration in
db.go must also be declared in that file — internal/db/sqlcdb_pilot_test.go
fails if the generated queries disagree with a schema built by db.Open.
FTS5 virtual tables are invisible to sqlc, so entries_fts/snippets_fts
queries stay hand-written in db.go.