david a5430b7d25
build / test (push) Successful in 3m33s
build / image (push) Successful in 18s
feat: remove peers (CLI + HTTP) so retired nodes stop being retried (#11)
Closes #10.

Peers were append-only: `UpsertPeer`/`MergePeer` existed, nothing could remove a row. A retired node therefore stayed in the table forever and failed on every anti-entropy sweep — the laptop node has been retrying a dead LAN peer (`http://192.168.8.240:8931`) every minute for weeks, with no fix short of hand-editing SQLite.

## Changes

- `KnoxDB.DeletePeer(identifier)` — exact match on `peer_id` **or** `addr`; empty identifier rejected.
- `DELETE /v1/peers/{peer_id}` and `DELETE /v1/peers?addr=<url>` — the query form exists because addresses contain slashes. Both sit behind the same bearer-token middleware as the rest of the gossip API, so they inherit TLS + `KNOX_AUTH_TOKEN`.
- `knox gossip peer list` / `knox gossip peer rm <peer-id|address>`.
- The CLI warns when the removed address is still in `KNOX_PEERS`, because a static seed is re-merged on the next sweep and would silently come back.

## Caveat worth knowing
Deletion only sticks for peers learned through membership gossip. Anything still listed in `KNOX_PEERS` will be re-learned; remove it from the environment too.

## Verification
- `internal/db/gossip_test.go` — delete by id, by address, unknown peer is a no-op, empty identifier rejected
- `internal/watch/gossip_test.go` — 404 for unknown, 200 by id, 200 by `?addr=`
- `go vet ./...`, `go test ./...` green
- Used live: removed the stale `192.168.8.240` peer on the laptop node; the every-minute `no route to host` errors stopped on the next sweep

Reviewed-on: #11
Co-authored-by: David Gwilliam <dhgwilliam@gmail.com>
Co-committed-by: David Gwilliam <dhgwilliam@gmail.com>
2026-11-05 02:27:52 +00:00

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.

S
Description
Knowledge index & session tracker for opencode
Readme 1.9 MiB
Languages
Go 95.3%
TypeScript 2.3%
HTML 2%
Shell 0.2%
Dockerfile 0.2%