e3bbeabb6b
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>
56 lines
1.7 KiB
Bash
Executable File
56 lines
1.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Run the official MCP conformance suite against a knox MCP HTTP endpoint.
|
|
#
|
|
# scripts/conformance.sh # start a throwaway node
|
|
# KNOX_MCP_URL=http://host:8930/ scripts/conformance.sh # test a running node
|
|
#
|
|
# A throwaway node uses a temporary database, so nothing here touches the real
|
|
# index. Exit code is the suite's: 0 when everything outside the baseline passes.
|
|
set -euo pipefail
|
|
|
|
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
addr="${KNOX_CONF_ADDR:-127.0.0.1:18940}"
|
|
url="${KNOX_MCP_URL:-http://${addr}/}"
|
|
|
|
cleanup() {
|
|
if [[ -n "${pid:-}" ]]; then
|
|
kill "$pid" 2>/dev/null || true
|
|
wait "$pid" 2>/dev/null || true
|
|
fi
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
if [[ -z "${KNOX_MCP_URL:-}" ]]; then
|
|
tmpdb="$(mktemp -d)"
|
|
go build -o "${tmpdb}/knox" "$root"
|
|
KNOX_DB="${tmpdb}/index.db" "${tmpdb}/knox" mcp --http "$addr" &
|
|
pid=$!
|
|
# Wait for the endpoint to accept requests rather than sleeping blindly. A
|
|
# stale listener on the port would otherwise be tested by mistake, so fail
|
|
# loudly if the child never comes up.
|
|
ready=""
|
|
for _ in $(seq 1 50); do
|
|
if ! kill -0 "$pid" 2>/dev/null; then
|
|
echo "error: knox exited before serving on ${addr} (port in use?)" >&2
|
|
exit 1
|
|
fi
|
|
if curl -sf -o /dev/null -X POST "$url" \
|
|
-H 'Content-Type: application/json' \
|
|
-H 'Accept: application/json, text/event-stream' \
|
|
-d '{"jsonrpc":"2.0","id":1,"method":"ping"}'; then
|
|
ready=1
|
|
break
|
|
fi
|
|
sleep 0.2
|
|
done
|
|
if [[ -z "$ready" ]]; then
|
|
echo "error: knox did not become ready on ${addr}" >&2
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
npx -y @modelcontextprotocol/conformance@latest server \
|
|
--url "$url" \
|
|
--expected-failures "$root/conformance-baseline.yml" \
|
|
"$@"
|