Skip to content

fix(wrapper): point the machine-wide wrapper at the installed kit, not at whoever wrote it - #510

Merged
sandstream merged 1 commit into
mainfrom
fix/509-wrapper-entrypoint
Aug 21, 2026
Merged

sandstream merged 1 commit into
mainfrom
fix/509-wrapper-entrypoint

Conversation

@sandstream

Copy link
Copy Markdown
Owner

Closes #509.

What went wrong

~/.kit/bin/kit is what every kit hook in every repo execs. It was written with whatever entrypoint happened to be running:

// src/kit-wrapper.ts:162 (before)
const cliEntry = opts.cliPath ?? (process.argv[1] ? resolve(process.argv[1]) : undefined);

So one kit hooks add run as node dist/cli.js … from a development checkout aimed the whole machine's enforcement floor at …/kit-public/dist/cli.js — a path npm run build deletes on its first step (clean-dist.mjs). It happened here, and the failure landed in an unrelated repo:

PreToolUse:Bash hook error
Failed with non-blocking status code: [kit] hook cannot start:
kit CLI entrypoint missing: /Users/…/kit-public/dist/cli.js

The hook died and the session continued ungated.

Four properties made it worse than a stale path, and each one is addressed:

property fix
a repo-local command had a machine-wide effect the entrypoint no longer depends on where the command ran
a dev build is transient by design an installed kit is preferred, because its path is stable by construction
it failed open kit check now fails high when the wrapper's entrypoint is missing
it was silent both ways the wrapper result names the entrypoint; a working-tree pin warns at write time and in the gate

The choice, and its one deliberate exception

chooseWrapperEntry() is pure and injectable, so every branch is a table row rather than a machine state:

running entrypoint installed kit present result
a checkout yes installed wins
a checkout yes, but KIT_WRAPPER_ALLOW_DEV=1 the checkout, with a warning — an explicit dev pin must not be silently overridden
a checkout no the checkout, loud: naming what a build will do, and how to fix it (npm i -g sandstream-kit)
already an install — kept as-is
none yes installed
none no null — no wrapper written, rather than a path invented

The third row is the judgement call: refusing outright would leave the hooks with no wrapper at all, which is worse than a fragile one. So it writes and says so.

The gate reports it

The git hook floor row (#496/#497) reported the hook directory; the wrapper is the other half of the same question, since every hook resolves through it. judgeWrapper():

  • fail (high) — the entrypoint does not exist: "EVERY kit hook on this machine is dead until it returns, and a hook that cannot start is non-blocking, so sessions run ungated"
  • warn (medium) — the entrypoint is inside a git working tree: it works until the next build
  • pass — naming the entrypoint
  • skip — no kit-managed wrapper, or an unmanaged file at that path (never claimed as kit's)

Knobs

KIT_WRAPPER_ALLOW_DEV is registered in kit config knobs, marked dangerous. KIT_TOOL_LATEST_TTL_H was missing from that surface since it was introduced yesterday and is now registered too — a documented knob that kit config knobs does not list is the same class of gap as the rest of this arc.

Tests

src/kit-wrapper-entry.test.ts — 14:

  • the six chooseWrapperEntry branches above, including that allowDev beats the installed-kit preference (the first implementation had that ordering wrong, caught by the table)
  • pathInWorkingTree finds a .git above a path and says no for an install layout
  • describeWrapper / judgeWrapper against real temp homes: absent wrapper → skip; an unmanaged file at that path → skip, never claimed; a missing entrypoint → fail high with the ungated-sessions wording; an entrypoint inside a real .git tree → warn; an installed entrypoint → pass, named

Verification on this machine

The wrapper was regenerated from the installed kit before this change, as the workaround:

before:  exec node /Users/…/kit-public/dist/cli.js
after:   exec /usr/local/bin/node /Users/…/.npm-global/bin/kit

and verified by moving the checkout's dist/ aside — ~/.kit/bin/kit --version still answered. With this change, the same regeneration run from a checkout produces the installed path by default rather than needing the workaround.

  • npm test: 4429 tests, 0 fail, 0 skipped (macOS, non-root)
  • eslint src: 0 errors · prettier --check "src/**/*.ts" clean · kit self-audit: 16 rules, 0 fail, 0 warn

Not in this change

Failing closed when the wrapper cannot start (issue proposal 5). A broken wrapper blocking every tool call is its own outage, and the useful half — making it loud rather than a single non-blocking line — belongs in the harness contract, not in kit's wrapper.

🤖 Generated with Claude Code

…t at whoever wrote it

~/.kit/bin/kit is what every kit hook in every repo execs, and ensureKitWrapper()
baked in process.argv[1]. So one `kit hooks add` run as `node dist/cli.js …` from
a development checkout aimed the whole machine's enforcement floor at
…/dist/cli.js — a path `npm run build` deletes on its first step. It happened
here, and the failure landed in an unrelated repo:

  PreToolUse:Bash hook error
  Failed with non-blocking status code: [kit] hook cannot start:
  kit CLI entrypoint missing: …/kit-public/dist/cli.js

The hook died and the session continued UNGATED.

Four properties made it worse than a stale path: a repo-local command had a
machine-wide effect; a dev build is transient by design; it failed open; and it
was silent in both directions. Each is addressed.

chooseWrapperEntry() is pure and prefers an INSTALLED kit over a checkout,
probing the usual global bin dirs. KIT_WRAPPER_ALLOW_DEV=1 still wins over that
preference — an explicit dev pin must not be silently overridden, which the first
implementation got wrong until the table test caught it. A checkout with no
install to fall back on is written but LOUD: refusing outright would leave the
hooks with no wrapper at all, which is worse than a fragile one. The result line
now names the entrypoint instead of only saying "refreshed".

`kit check`'s git hook floor row also judges the wrapper, since every hook
resolves through it: a missing entrypoint fails high (every hook on the machine
is dead, and it fails open), an entrypoint inside a git working tree warns (it
works until the next build), an unmanaged file at that path is never claimed.

KIT_WRAPPER_ALLOW_DEV is registered in `kit config knobs`, marked dangerous, and
KIT_TOOL_LATEST_TTL_H is registered too — it had been missing from that surface
since it was introduced, which is the same class of gap as the rest of this arc.

Closes #509

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

✅ Docker image built successfully

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

@sandstream
sandstream merged commit 5ca2eb0 into main Aug 21, 2026
19 checks passed
@sandstream
sandstream deleted the fix/509-wrapper-entrypoint branch August 21, 2026 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant