Repository navigation
feat(serve): remote-mode HTTP server — ADR-0009 Phase 1, first slice - #14
Merged
Merged
Conversation
`engram serve` hosts the existing modules unchanged behind a small JSON-over-HTTP API on 127.0.0.1: GET /v1/health, POST /v1/search|recall| guard|add|route|extract, GET /v1/inbox (read-only). Each endpoint is a thin mapping over what the local CLI/MCP already calls — no new business logic, single write path preserved. Security per ADR-0009 §6: loopback bind only (non-loopback refused unless --allow-nonlocal); meant to sit behind `tailscale serve`, which injects Tailscale-App-Capabilities. Authorization keys on that grant (read/write/ add/*, cap name ENGRAM_SERVE_CAP_NAME, default engram.dev/cap/engram); Tailscale-User-Login is attribution only; --auth none for tests. 401 when the header is missing, 403 when the grant lacks the endpoint's action. Measured, not vibes: every call writes a `remote_call` ledger row (endpoint, status, outcome ok|denied|client_error|error, server_ms, caller, host/profile/session_id when sent) via search_audit.append_remote_call_audit, so `engram roi` can report remote latency and denied/unreachable rates. The guard endpoint also writes the same guard_inject row the local hook writes (echo detection joins on it). Not in this slice (tracked in #12): /v1/checkpoint and /v1/resume (wait for the v29 identity migration), project affinity by project_key, the systemd unit, roi reporting of the new rows, and the client side (ENGRAM_REMOTE_URL). Tests: tests/test_serve.py (15) — endpoints round-trip on a scratch DB, 404/405/400/413 paths, caps auth matrix, bind policy, ledger rows. Verification: ruff clean, pyright 0 errors (src/serve.py and src/search_audit.py added to the include list), Cloak 0 errors, full suite 1459 passed. docs/COMMANDS.md regenerated via scripts.gen_docs. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
7 of 18 tasks
CI (3.11) caught a race in test_every_call_writes_a_remote_call_ledger_row: the row was appended in a finally block after the reply had been sent, so a caller reading the ledger right after the response could miss the call. The ledger now lands before the response is written; status/outcome are known by then and the append is a local file write. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Merged
4 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
First server-side slice of ADR-0009 Phase 1 (#12):
engram serve, a JSON-over-HTTP API that hosts the existing modules unchanged against this host's SQLite. No new business logic; each endpoint is a thin mapping over a function the local CLI/MCP already calls.GET /v1/healthPOST /v1/searchsearch()POST /v1/recallbuild_recall_context(writes the recall_inject ledger row)POST /v1/guard_probe_guard_warnings(writes the guard_inject ledger row)POST /v1/addhandle_memory_add(dedup gate, FTS, trigger index, embedding queue as today)POST /v1/routehandle_memory_routePOST /v1/extracthandle_memory_auto_extractGET /v1/inboxinbox.list_items, read-onlySecurity (ADR-0009 §6). Binds
127.0.0.1only; anything else is refused unless--allow-nonlocal. Designed to sit behindtailscale serve, which injectsTailscale-App-Capabilities; authorization keys on that grant (read/write/add/*; cap nameENGRAM_SERVE_CAP_NAME, defaultengram.dev/cap/engram).Tailscale-User-Loginis attribution only.--auth nonetrusts every caller, for tests.Measured, not vibes. Every call writes a
remote_callledger row (endpoint, status, outcome,server_ms, caller, and host/profile/session when the client sends them) throughsearch_audit.append_remote_call_audit.Not in this slice (stays on #12)
/v1/checkpointand/v1/resume(wait for the v29 identity migration), project affinity byproject_key(recall/search passproject_path=Nonefor now), the systemd unit,engram roireporting of the new rows, and the client side (ENGRAM_REMOTE_URL).Verification
tests/test_serve.py: 15 tests on a scratch DB — endpoint round-trips, 404/405/400 paths, the caps auth matrix (401 missing header, 403 wrong grant, add-only vs write vs*), bind policy, ledger rowssrc/serve.py,src/search_audit.pyadded to the include list); Cloak 0 errorsengram serve --auth none --port 17437answered/v1/healthand/v1/search, returned 405 on a wrong method, and refused--host 0.0.0.0docs/COMMANDS.mdregenerated; CHANGELOG entry added🤖 Generated with Claude Code