Skip to content

feat(memory): private cross-device sync over your own git remote (gap #4) - #176

Merged
sandstream merged 1 commit into
mainfrom
claude/headroom-kit-integration-cmjw7t
Jun 30, 2026
Merged

sandstream merged 1 commit into
mainfrom
claude/headroom-kit-integration-cmjw7t

Conversation

@sandstream

Copy link
Copy Markdown
Owner

Description

Memory design gap #4: the personal store (~/.kit/memory.db) is per-machine. This wires the existing encrypted-backup + mergeDb primitives to an opt-in transport — your own private git repo — so one machine pushes and another pulls (last-write-wins), with no manual file copy. kit memory push / kit memory pull.

It answers the question raised in review — "can the remote be chosen, or does that open a backdoor?" — by being configurable without being a backdoor, by construction.

Type of Change

  • New feature (non-breaking change that adds functionality)

Related Issues

Changes Made

New module src/memory/remote-sync.ts:

  • loadSyncConfig() — reads [memory.sync] only from ~/.kit/sync.toml.
  • normalizeRemote() / assertRemoteNotProjectOrigin() — the anti-exfil guard.
  • pushMemory() / pullMemory() — clone the private remote, encrypt/decrypt the blob, commit+push / merge.
  • Wired push + pull into kit memory (handlers + help).

Four guards make a configurable remote safe, not a backdoor:

  1. Local-only config — read from ~/.kit/sync.toml, never the project tree. A malicious committed .kit.toml/.kit/* in a cloned repo therefore cannot redirect your private memory to an attacker's remote.
  2. remote ≠ project origin — normalized compare refuses to sync if the configured remote is this project's origin; your secret-dense brain can't be pushed into the (often shared/public) project repo.
  3. Encrypted payload — AES-256-GCM (backupEncrypted); the remote sees only ciphertext. Passphrase via KIT_MEMORY_PASSPHRASE, never stored.
  4. Opt-in — no sync.toml → the command does nothing but print setup guidance.

Zero new dependencies (git + node:crypto).

Testing

Test Coverage

  • Added new tests (src/memory/remote-sync.test.ts)
  • All tests pass (npm test) — 1942 pass, 0 fail

Manual Testing

  1. End-to-end against a local bare git repo: machine A seeds a message → push → blob present + encrypted on the remote → machine B (empty store) pull → recalls A's message.
  2. Guard tests: assertRemoteNotProjectOrigin throws when the remote equals the project origin (even across URL forms); loadSyncConfig returns null when unconfigured and rejects a path-traversal blob filename; normalizeRemote folds ssh/scp/https forms.
  3. pull on an empty remote reports "not found" cleanly.

🤖 Generated with Claude Code

https://claude.ai/code/session_015ERHw6bVUz39sAuoQZ1iyg


Generated by Claude Code

)

The personal store (~/.kit/memory.db) is per-machine; `syncFromExport` +
encrypted backup already let you move it by hand. This wires them to an
opt-in transport — YOUR private git repo — so one machine pushes and
another pulls (last-write-wins via mergeDb). `kit memory push` / `kit
memory pull`.

Configurable WITHOUT being a backdoor, by construction:
  1. Config is read ONLY from ~/.kit/sync.toml (LOCAL), never the project
     tree — a malicious committed .kit.toml/.kit/* in a cloned repo can't
     redirect your private memory to an attacker's remote.
  2. The sync remote MUST differ from the project's origin (normalized
     compare) — your secret-dense brain can't be pushed into the project
     repo by mistake.
  3. Payload is AES-256-GCM encrypted (backupEncrypted); the remote sees
     only ciphertext. Passphrase via KIT_MEMORY_PASSPHRASE, never stored.
  4. Fully opt-in: no sync.toml → the command only explains setup.

New module src/memory/remote-sync.ts (loadSyncConfig / normalizeRemote /
assertRemoteNotProjectOrigin / pushMemory / pullMemory); push/pull wired
into `kit memory`. Tested end-to-end against a local bare repo (A push →
B pull → recall) plus the guards. Zero new dependencies (git + node:crypto).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ERHw6bVUz39sAuoQZ1iyg
@github-actions

Copy link
Copy Markdown

✅ Docker image built successfully

  • CLI image: docker.io/sandstream/kit:test

@sandstream
sandstream merged commit adc5d5b into main Jun 30, 2026
17 checks passed
sandstream pushed a commit that referenced this pull request Jun 30, 2026
…ne-time nudge

Closes the usability gaps in gap #4 (#176/#178): you had to hand-write
~/.kit/sync.toml and nothing synced automatically — which made the
ephemeral-container flow (push before the box is reclaimed) a manual chore.

A. `kit memory sync init` — writes the LOCAL ~/.kit/sync.toml template
   (--remote <url> for git, or --command with --push-cmd/--pull-cmd; --auto
   enables the hooks; --force overwrites). Won't clobber an existing config;
   reminds you to set KIT_MEMORY_PASSPHRASE and to create the private repo
   (kit makes the branch + blob, not the repo).

B. Opt-in auto-sync wired into the memory hooks:
   - [memory.sync] pull_on_start = true  → pull+merge at SessionStart, BEFORE
     the "where you left off" recovery, so it reflects the merged store.
   - [memory.sync] push_on_end = true    → index+push at SessionEnd — the
     missing piece for ephemeral containers.
   Both fail-soft (tryAutoPull/tryAutoPush never throw): a session is never
   blocked by sync. Notes go to stderr; the injected recovery stays on stdout.

C. One-time upgrade nudge: when sync isn't configured but a non-trivial memory
   store exists, suggest `kit memory sync init` once (a ~/.kit marker suppresses
   it thereafter).

New exports in remote-sync.ts: initSyncConfig, tryAutoPull, tryAutoPush,
maybeSyncNudge; SyncConfig gains pullOnStart/pushOnEnd. `sync init` routed in
the memory dispatcher; auto-pull/push + nudge wired into memHook. 4 new tests
(init round-trip, auto-sync gating, command push_on_end, nudge once). 1952 pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ERHw6bVUz39sAuoQZ1iyg
sandstream added a commit that referenced this pull request Jun 30, 2026
…-time nudge (#179)

Closes the usability gaps in gap #4 (#176/#178): you had to hand-write
~/.kit/sync.toml and nothing synced automatically — which made the
ephemeral-container flow (push before the box is reclaimed) a manual chore.

A. `kit memory sync init` — writes the LOCAL ~/.kit/sync.toml template
   (--remote <url> for git, or --command with --push-cmd/--pull-cmd; --auto
   enables the hooks; --force overwrites). Won't clobber an existing config;
   reminds you to set KIT_MEMORY_PASSPHRASE and to create the private repo
   (kit makes the branch + blob, not the repo).

B. Opt-in auto-sync wired into the memory hooks:
   - [memory.sync] pull_on_start = true  → pull+merge at SessionStart, BEFORE
     the "where you left off" recovery, so it reflects the merged store.
   - [memory.sync] push_on_end = true    → index+push at SessionEnd — the
     missing piece for ephemeral containers.
   Both fail-soft (tryAutoPull/tryAutoPush never throw): a session is never
   blocked by sync. Notes go to stderr; the injected recovery stays on stdout.

C. One-time upgrade nudge: when sync isn't configured but a non-trivial memory
   store exists, suggest `kit memory sync init` once (a ~/.kit marker suppresses
   it thereafter).

New exports in remote-sync.ts: initSyncConfig, tryAutoPull, tryAutoPush,
maybeSyncNudge; SyncConfig gains pullOnStart/pushOnEnd. `sync init` routed in
the memory dispatcher; auto-pull/push + nudge wired into memHook. 4 new tests
(init round-trip, auto-sync gating, command push_on_end, nudge once). 1952 pass.


Claude-Session: https://claude.ai/code/session_015ERHw6bVUz39sAuoQZ1iyg

Co-authored-by: Claude <noreply@anthropic.com>
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.

2 participants