Skip to content

feat(identity): schema v29 — portable project key, host, profile; remote checkpoint/resume - #15

Merged
luiscota99 merged 1 commit into
mainfrom
feat/identity-v29
Oct 15, 2026
Merged

luiscota99 merged 1 commit into
mainfrom
feat/identity-v29

Conversation

@luiscota99

Copy link
Copy Markdown
Owner

Summary

Second server-side slice of ADR-0009 Phase 1 (#12): the identity migration and the two endpoints that depended on it.

Schema v29

  • checkpoints gains project_key, host, profile; unique key becomes (project_key, host, profile, session_id). SQLite cannot drop the old UNIQUE(project_path, session_id) in place, so the migration rebuilds the table and backfills legacy rows with project_key = project_path, host = <this machine>, profile = default.
  • The five content tables gain a code-set provenance column (local | remote:<host>). memory_ops.create_* take provenance=, the MCP add handlers forward it, and the server sets it — a caller cannot forge it. Same mechanism as the v27 relation edges, as the portable-brains plan proposed.
  • schema_meta.instance_id, set by init_db.

Identity (src/identity.py): project_key_for() = normalized git origin remote (every spelling of github.com/owner/repo collapses to one key) → ENGRAM_PROJECT_KEY → host:realpath. host_name(), profile_name() (ENGRAM_PROFILE, default default). One git subprocess at most, no DB.

Checkpoints and resume

  • upsert_checkpoint / record_milestone take the three identity fields; local callers compute them, the server passes what the client sent.
  • engram resume matches on key OR path (legacy rows stay reachable), is profile-scoped by default (--all-profiles widens), shows the originating host, and computes "commits since" only against this machine's own checkpoints.
  • The Stop hook prefers Claude Code's last_assistant_message over the transcript tail (the docs say the file "may lag").
  • Echo detection refactored to run from text (record_echoes_from_text), so the server can do it without the client's transcript; the transcript path remains as fallback.

Server: POST /v1/checkpoint (answers 204 — a Stop hook that returned context would keep Claude working) and GET /v1/resume?project_key=&profile=&host=&all_profiles=&limit=.

Verification

  • New tests: identity (URL normalization matrix, git-remote key, fallback, env overrides); migration v29 (rebuild, backfill, unique index, old UNIQUE gone, provenance default); checkpoints (same session on two hosts, profile scoping, legacy rows, last_assistant_message, echoes from text); serve (checkpoint→resume across hosts, provenance stamp, caps matrix)
  • Full suite: 1480 passed. The command-reference test caught the new --all-profiles flag before docs/COMMANDS.md was regenerated; regenerated and re-run green.
  • ruff clean, pyright 0 errors, Cloak 0 errors
  • CHANGELOG entry

Rebased onto main after #14 merged.

🤖 Generated with Claude Code

…ote checkpoint/resume

ADR-0009 §3/§4/§7. A local realpath cannot key work across the Mac, Linux
and WSL. Checkpoints now carry project_key (normalized git origin remote,
else ENGRAM_PROJECT_KEY, else host:realpath), host and profile
(ENGRAM_PROFILE); the unique key is (project_key, host, profile,
session_id). SQLite cannot drop the old UNIQUE(project_path, session_id)
in place, so v29 rebuilds the table and backfills legacy rows with
project_key = project_path, host = this machine, profile = default.

- src/identity.py: normalize_remote_url, project_key_for, host_name,
  profile_name (one git subprocess at most, no DB)
- checkpoint: upsert/milestone take project_key/host/profile; resume
  matches key OR path, profile-scoped by default (--all-profiles), shows
  the originating host, computes "commits since" only for this host's
  checkpoints; Stop hook prefers last_assistant_message over the
  transcript tail; echo detection refactored to run from text
  (record_echoes_from_text) so the server can do it without the
  client's transcript
- provenance: code-set column on mistakes/patterns/skills/conversations/
  prompts ('local' | 'remote:<host>'); memory_ops.create_* take
  provenance=, MCP add handlers forward it, the server sets it (a caller
  cannot forge it)
- schema_meta.instance_id set by init_db (ensure_instance_id)
- serve: POST /v1/checkpoint (204) and GET /v1/resume
- migration test for v29 (rebuild, backfill, index, old UNIQUE gone,
  provenance default); identity tests; checkpoint tests (two hosts, one
  session; profile scoping; legacy rows; last_assistant_message; echoes
  from text); serve tests (checkpoint→resume across hosts, provenance
  stamp, caps matrix)

Verification: ruff clean, pyright 0 errors, Cloak 0 errors, full suite
1480 passed after regenerating docs/COMMANDS.md (the command-reference
test caught the new --all-profiles flag before the regen).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@luiscota99
luiscota99 merged commit 6917daf into main Oct 15, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant