Skip to content

feat(context): kit context check — per-project CLI context lock - #4

Merged
sandstream merged 3 commits into
mainfrom
feat/context-lock
Jun 17, 2026
Merged

sandstream merged 3 commits into
mainfrom
feat/context-lock

Conversation

@sandstream

Copy link
Copy Markdown
Owner

Why

A push can deploy to a project left over from a repo's previous purpose, and a CLI's default config can pair the wrong account with the wrong project. Root cause: the ambient CLI state (what is logged in / selected) gets trusted as if it were the right pairing. It is not.

What

  • .kit.toml [context] declares each tool's exact account + project: gcloud (account/project/config/region), vercel (team/project), github (org/remote), git (email), npm (registry).
  • kit context check reads the LIVE state per tool and verifies it matches the declaration. A right account + wrong project = mismatch. Unreadable/absent tool = unknown (does not block).
  • Read-only. Exits non-zero on a mismatch, so it can gate a git hook or an agent before any outward/destructive command.
  • Non-secret pointers live in config; credentials stay in the vault (same split kit already uses).

Design

  • compareContext is pure + table-driven (one row per CLI field) so "only the exact declared pair passes" is unit-tested and adding a CLI is one row.
  • Live readers use execFile (no shell), fail soft to null.

Scope / next

Verifier only. Enforcement slices next: a pre-push hook that runs kit context check (blocks a push to the wrong org), and kit context use to activate a context atomically. The dashboard-side host/git integration case needs the host API to detect fully; the local .vercel/project.json link is checked now.

Full suite green, tsc + eslint clean. No version bump (bump once after merging all open PRs).

🤖 Generated with Claude Code

Declare each tool's exact (account, project) pair in .kit.toml [context]
(gcloud, vercel, github, git, npm). kit context check reads the live tool state
and verifies it matches, and never infers a pairing from whatever happens to be
logged in or selected: a right account with the wrong project is a mismatch,
not a pass. Read-only; exits non-zero on a mismatch so it can gate a git hook
or an agent before an outward/destructive command. Context pointers live in
config; the credentials they authenticate with stay in the vault.

Catches the contamination class where a CLI is pointed at the wrong
account/project, or a repo carries a stale deploy connection from a previous
purpose. Table-driven field specs (adding a CLI is one row). Tests cover the
exact-pair principle, unknown handling, and remote parsing.

No version bump; we bump once after merging all open PRs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

✅ Docker image built successfully

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

`kit hooks add context-check` installs a pre-push hook that runs
`kit context check` and blocks the push on a mismatch. Turns the verifier into
an actual gate: a push to the wrong account/project (or a repo carrying a stale
deploy connection) is stopped before it leaves the machine. One declarative
entry in the built-in hook registry; the existing hook generator handles the
rest.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

✅ Docker image built successfully

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

Completes the context-lock story (check + use + visibility):
- `kit context use` activates the declared context — gcloud config + repo git
  identity — so every CLI points at the right account/project. Touches only
  local config (never an account or a deploy); vercel/npm get guidance. Plan is
  pure + unit-tested.
- `kit context --prompt` prints a fast, read-only active-gcloud indicator
  (e.g. [gcp:my-project]) read from gcloud's config files (no subprocess) for
  the shell prompt.
- Help text, README (Context lock section + shortlist), and CHANGELOG updated.

9 context tests, full suite 2227 green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

✅ Docker image built successfully

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

@sandstream sandstream mentioned this pull request Jun 17, 2026
@sandstream
sandstream merged commit cd618fe into main Jun 17, 2026
16 checks passed
@sandstream
sandstream deleted the feat/context-lock branch June 20, 2026 05:36
sandstream pushed a commit that referenced this pull request Jun 30, 2026
)

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
sandstream pushed a commit that referenced this pull request Jun 30, 2026
…clone/scp/USB)

Gap #4 shipped a git-remote transport; the encrypted blob is the real unit and
git is just one way to move it. This adds a second, transport-agnostic option so
you're not locked into git: set `transport = "command"` in ~/.kit/sync.toml with
push_cmd / pull_cmd, and kit runs your command with the encrypted blob path
exposed as $KIT_MEMORY_BLOB.

  [memory.sync]
  transport = "command"
  push_cmd = "aws s3 cp \"$KIT_MEMORY_BLOB\" s3://my-bucket/kit-memory.enc"
  pull_cmd = "aws s3 cp s3://my-bucket/kit-memory.enc \"$KIT_MEMORY_BLOB\""

Same guards as the git transport: the command is read ONLY from the LOCAL
~/.kit/sync.toml (never the project tree, so a cloned repo can't inject it), the
payload stays AES-256-GCM encrypted (the store sees only ciphertext), and it's
opt-in. push encrypts → runs push_cmd; pull runs pull_cmd → merges (last-write-
wins) if a blob arrived, else reports "not found".

SyncConfig gains a `transport` discriminator (git | command); push/pull branch
on it; result field `remote` → `target` (the URL, or "command transport"). Help
text shows both forms. 3 new tests (config validation, cp-based round trip,
empty-pull) over the existing git ones. 1948 tests 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
…e/scp/USB) (#178)

Gap #4 shipped a git-remote transport; the encrypted blob is the real unit and
git is just one way to move it. This adds a second, transport-agnostic option so
you're not locked into git: set `transport = "command"` in ~/.kit/sync.toml with
push_cmd / pull_cmd, and kit runs your command with the encrypted blob path
exposed as $KIT_MEMORY_BLOB.

  [memory.sync]
  transport = "command"
  push_cmd = "aws s3 cp \"$KIT_MEMORY_BLOB\" s3://my-bucket/kit-memory.enc"
  pull_cmd = "aws s3 cp s3://my-bucket/kit-memory.enc \"$KIT_MEMORY_BLOB\""

Same guards as the git transport: the command is read ONLY from the LOCAL
~/.kit/sync.toml (never the project tree, so a cloned repo can't inject it), the
payload stays AES-256-GCM encrypted (the store sees only ciphertext), and it's
opt-in. push encrypts → runs push_cmd; pull runs pull_cmd → merges (last-write-
wins) if a blob arrived, else reports "not found".

SyncConfig gains a `transport` discriminator (git | command); push/pull branch
on it; result field `remote` → `target` (the URL, or "command transport"). Help
text shows both forms. 3 new tests (config validation, cp-based round trip,
empty-pull) over the existing git ones. 1948 tests pass.


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

Co-authored-by: Claude <noreply@anthropic.com>
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>
sandstream pushed a commit that referenced this pull request Jun 30, 2026
…our device

You can land a "blocked-on-you" item in a throwaway container/scratch dir; today
it persists in ~/.kit and (with gap-#4 sync) can follow you to your laptop and
nag forever. This couples PAL items to where they were created.

  - schema v5: pending_actions gains origin_device + origin_root, stamped at
    palAdd / palSyncFindings. origin_device = KIT_DEVICE_ID or a stable
    sha256(hostname+user) — an ephemeral container gets its own throwaway id.
  - palList device-filters by DEFAULT: only this device's items (+ legacy
    NULL-origin rows) surface, so reminders, the statusline ⚠ count, and
    `kit memory pal list` stop nagging about another device's / an ephemeral
    session's work. `--all` opts back in to every device.
  - `kit memory pal prune`: closes THIS device's open items whose origin_root no
    longer exists (dead ephemeral/scratch dirs). Only this device's items (we
    can't judge another device's paths); pre-v5 rows (no origin_root) untouched.

Backward-compatible: legacy rows have NULL origin and always show. 7 new tests
(stamping, default device filter + --all, NULL-legacy visibility, prune
keep/close/other-device, stable+overridable deviceId). 1969 tests 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
…our device (#182)

You can land a "blocked-on-you" item in a throwaway container/scratch dir; today
it persists in ~/.kit and (with gap-#4 sync) can follow you to your laptop and
nag forever. This couples PAL items to where they were created.

  - schema v5: pending_actions gains origin_device + origin_root, stamped at
    palAdd / palSyncFindings. origin_device = KIT_DEVICE_ID or a stable
    sha256(hostname+user) — an ephemeral container gets its own throwaway id.
  - palList device-filters by DEFAULT: only this device's items (+ legacy
    NULL-origin rows) surface, so reminders, the statusline ⚠ count, and
    `kit memory pal list` stop nagging about another device's / an ephemeral
    session's work. `--all` opts back in to every device.
  - `kit memory pal prune`: closes THIS device's open items whose origin_root no
    longer exists (dead ephemeral/scratch dirs). Only this device's items (we
    can't judge another device's paths); pre-v5 rows (no origin_root) untouched.

Backward-compatible: legacy rows have NULL origin and always show. 7 new tests
(stamping, default device filter + --all, NULL-legacy visibility, prune
keep/close/other-device, stable+overridable deviceId). 1969 tests pass.


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

Co-authored-by: Claude <noreply@anthropic.com>
sandstream pushed a commit that referenced this pull request Jul 1, 2026
…s, ephemeral)

gap #4 shipped (git/command transports, passphrase + public-key modes, gzip) but
the memory docs still said "no sync service" and referenced a future Turso sync.

- docs/MEMORY.md: new "Cross-device sync" section — kit memory push/pull, the two
  transports (git remote / command), passphrase vs public-key (recipient) modes,
  kit memory keygen, gzip, and the seamless ephemeral-capture setup. Fixed the two
  stale claims; added OpenCode to the multi-harness list (8th).
- README.md: "seven" → "eight" agents (+ OpenCode); note cross-device sync +
  public-key mode in the Memory blurb.

Docs only. Suite 1986 green.

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 Jul 1, 2026
…s, ephemeral) (#194)

gap #4 shipped (git/command transports, passphrase + public-key modes, gzip) but
the memory docs still said "no sync service" and referenced a future Turso sync.

- docs/MEMORY.md: new "Cross-device sync" section — kit memory push/pull, the two
  transports (git remote / command), passphrase vs public-key (recipient) modes,
  kit memory keygen, gzip, and the seamless ephemeral-capture setup. Fixed the two
  stale claims; added OpenCode to the multi-harness list (8th).
- README.md: "seven" → "eight" agents (+ OpenCode); note cross-device sync +
  public-key mode in the Memory blurb.

Docs only. Suite 1986 green.


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

Co-authored-by: Claude <noreply@anthropic.com>
sandstream pushed a commit that referenced this pull request Jul 5, 2026
…found false green)

Adversarial verify found the mandate was a false green: KIT_REQUIRE_HARDWARE_IDENTITY
was enforced ONLY in `kit policy sign`, while audit-chain entries, shared-memory notes,
and revocations kept signing with the same-UID-readable file key — and `init` still minted
a file key that coexists. So a mandate operator got a green light over a key an attacker
could still read and use. Fixed so NO file-key signature escapes under the mandate.

- Universal backstop: signWithIdentity() (the file-key primitive) now FAILS CLOSED under
  KIT_REQUIRE_HARDWARE_IDENTITY — every caller that reaches it (revocations, elevation,
  any un-routed signer) refuses the file key. mandate.js is a zero-import module so
  identity.ts can guard without an import cycle.
- loadOrCreateIdentity refuses to MINT a file key under the mandate (Finding #4: no
  coexisting same-UID key to steal).
- Routed the audit-chain signer (audit.ts) and shared-memory signer (memory/shared.ts)
  through the keystore: a `command` backend now signs them via hardware, and under a
  mandate with only a file key they fall back to KEYLESS (chain still protects them)
  rather than emitting a forbidden file-key signature. Also unifies the signing kid.
- Command signer no longer receives kit's env wholesale (Finding #3): minimal allowlist
  (PATH/HOME/KIT_SIGN_ALGO), so KIT_* secrets/vault tokens aren't exposed to the signer
  subprocess — the comment now matches the code.
- Honesty (Findings #2/#6): the command backend and `kit identity keystore` no longer
  claim "hardware-rooted" (kit can't attest the operator's command fronts a secure
  element) — labeled "external key — operator-fronted" with an explicit caveat.

Regression tests: comprehensive-mandate suite (signWithIdentity / loadOrCreate /
recordRevocation fail closed; audit falls back to keyless) + signer env-isolation.
Full suite green (2261 tests).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbF4MFePXWNCd4dxBQvqH2
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