Skip to content

feat(memory): public-key sync mode — ephemeral sessions push with no secret - #192

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

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

Conversation

@sandstream

Copy link
Copy Markdown
Owner

Why

Cross-device memory sync used a symmetric passphrase — every machine that pushes needs the same secret. An ephemeral cloud session (Claude Code on the web) can't safely hold it: its env-vars field is explicitly "not for secrets", it has no SSH key, and the container is thrown away. So ephemeral sessions couldn't contribute their memory to the hub without either leaking a secret or losing the data on teardown.

What

An asymmetric (public-key) mode that flips the trust model:

  • A session encrypts to a public recipient key (kitmem-pub-…) — not a secret, safe to put in a setup script, an env var, or even commit.
  • Only machines holding the matching private key (~/.kit/memory-key.json, 0600) can decrypt on pull.
  • So an ephemeral session needs only a public key + a reachable private repo to push its memory. Nothing secret leaves it, and push_on_end / pull_on_start work passphrase-free.

How (zero new deps)

  • backup.ts — MAGIC_V3: fresh ephemeral X25519 keypair per blob → ECDH(eph, recipient) → HKDF-SHA256(salt = ephPub‖recipPub, info="kit-memory-v3") → AES-256-GCM. libsodium sealed-box shape, pure node:crypto. New helpers: generateMemoryKeypair, saveMemoryKey, loadMemoryKey, parseRecipient, backupToRecipient, restoreWithKey, isAsymmetricBackup.
  • sync.ts — syncFromExport decrypts a V3 blob with the local private key (no passphrase); clear error if the key is missing.
  • remote-sync.ts — [memory.sync] recipient = "kitmem-pub-…"; push encrypts to it; tryAutoPush no longer requires KIT_MEMORY_PASSPHRASE when a recipient is configured.
  • kit memory keygen — mint the keypair (private 0600), print the shareable public recipient; refuses to overwrite an existing key without --force (a new key would orphan old blobs).

The passphrase mode is unchanged and remains the default; asymmetric is opt-in via recipient.

Tests

3 new: encrypt-to-public / decrypt-with-private round-trip; a different private key cannot decrypt (confidentiality); parseRecipient rejects malformed keys. Plus a live end-to-end run (push with undefined passphrase → pull with the private key → real content recovered). Full suite 1985 green, prettier clean, public surface unchanged.

Setup (ephemeral web sessions, seamless)

# once, on a durable machine:
kit memory keygen                 # → prints kitmem-pub-…, writes private key 0600
# in the web environment's setup script + [memory.sync]:
recipient = "kitmem-pub-…"        # public, non-secret

No passphrase, no SSH key, no token to manage in the container.

🤖 Generated with Claude Code

https://claude.ai/code/session_015ERHw6bVUz39sAuoQZ1iyg


Generated by Claude Code

…secret

The passphrase mode needs the same secret on every pushing machine, which an
ephemeral cloud session can't safely hold (no secret-store, no SSH key). Add an
asymmetric mode so a session encrypts to a PUBLIC recipient key (not a secret)
and only private-key holders can decrypt.

- backup.ts: MAGIC_V3 = ephemeral X25519 → HKDF-SHA256(salt=ephPub|recipPub) →
  AES-256-GCM (sealed-box shape), pure node:crypto, zero deps. New:
  generateMemoryKeypair / saveMemoryKey / loadMemoryKey / parseRecipient /
  backupToRecipient / restoreWithKey / isAsymmetricBackup.
- sync.ts: syncFromExport decrypts V3 with the local private key (no passphrase);
  clear error if the key is missing.
- remote-sync.ts: [memory.sync] recipient = "kitmem-pub-…"; push encrypts to it;
  tryAutoPush no longer requires KIT_MEMORY_PASSPHRASE when a recipient is set.
- kit memory keygen: mint the keypair (private 0600), print the shareable public
  recipient; refuses to clobber an existing key without --force.

Private key stays only on durable machines (~/.kit/memory-key.json). 3 new tests
(round-trip, wrong-key confidentiality, malformed-recipient); live end-to-end
verified passphrase-free. Suite 1985 green.

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

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown

✅ Docker image built successfully

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

@sandstream
sandstream merged commit 67892d0 into main Jul 1, 2026
17 checks passed
sandstream added a commit that referenced this pull request Jul 1, 2026
#196)

Cut 3.1.0 from [Unreleased]:
- gzip-compress memory sync blobs before encryption (~3x smaller, #193)
- public-key sync mode — ephemeral sessions push with no secret (#192)
- kit agent-config wires GitHub Copilot (#195)
- external timestamp anchor via command transport (#186)
- plus device-identity hardening + transport fixes

Co-authored-by: Claude Opus 4.8 <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