Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,27 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).

### Added

- **`kit check` now reports the git-hook floor: where it is, and whether it can fail.** README
calls git hooks the agent-agnostic enforcement floor, and nothing reported on them — there was
a row for memory hooks and one for the PreToolUse gates, none for these. Two measured states
were therefore invisible (#496, #497):

- **The floor can live outside the repo.** `resolveHooksDir()` honors `core.hooksPath`, which
is correct (installing into `.git/hooks` while git reads elsewhere is a silent no-op) — but
only the WRITER used it. `check-hooks.ts` and `kit hooks add`'s own already-installed
pre-check hardcoded `<gitDir>/hooks`, so with an external `core.hooksPath` kit installed to
one directory and reported on another. Both readers now use the same resolver, so writer and
reader can no longer disagree. Measured consequence of the silence: a checkout copied from
another inherits its absolute `core.hooksPath`, so its hooks live in the other clone's tree
— deleting that unrelated directory let a staged fake credential commit cleanly, exit 0.
- **A dangling `core.hooksPath` means every hook is OFF**, and now fails the gate instead of
reading like a repo that never wired hooks.

New `git hook floor` row: `fail` for a gone directory or an unarmed gate, `warn` when the floor
resolves outside the repo, `pass` naming the hooks actually wired, and `skip` when the repo has
no kit-managed hooks — kit does not claim a floor nobody asked for. `kit hooks add` also prints
the resolved directory when it is external, instead of a bare `✓ installed`.

- **`kit audit verify --all` — the union view over every audit log this machine sealed.**
`kit audit verify` answers for one working tree, correctly: a git worktree IS a distinct
working tree, so it gets its own chain. On a machine running several — the normal case
Expand Down Expand Up @@ -82,6 +103,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).

### Fixed

- **`kit hooks add context-check` installed a gate that could not fail.** With no `[context]`
block there is nothing to compare the live CLI state against, so the pre-push hook passed every
push while reporting `✓ installed` — the false green kit exists to refuse (#497). It now
refuses, points at `kit context check` (which prints a ready-to-paste block from the live CLI
state), and takes `--force` for someone about to declare the block. The installed hook runs
`kit context check --require-declaration`, so a `[context]` block that disappears later fails
the push instead of passing it; the bare command still exits 0, since a repo may legitimately
have no lock and a read-only report should not invent one.

- **Every hook printed secret-scan's test recipe.** `kit hooks add post-pull-audit` and
`context-check` both told you to stage a fake credential and commit — advice that exercises
nothing for a post-merge or pre-push gate. Each built-in now prints how to exercise itself.

- **`triage`'s pip score is no longer higher than npm's for running fewer probes.** The
score is a flat penalty count (`100 - 45*critical - 12*warning`), so it fell out of how
many probes an ecosystem HAS: `pip opensandbox-server` printed 100/100 next to
Expand Down Expand Up @@ -112,7 +146,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
`ensureMiseActivation` — the appender — has no production caller at all (it sits in
self-audit's unwired-code advisory). `kit doctor` reports the gap and prints the line. The
claim is corrected rather than the feature quietly invented: writing to a user's shell
profile needs its own consent design.
profile needs its own consent design. `fix.ts` carried the same shape of false claim —
git-hook installs "land inside the repo, which the repo-rooted `[scope].fs` covers" — which
holds only while `core.hooksPath` is unset or repo-relative; an absolute one puts the write
outside the repo. Both are now corrected.

- **`self-audit`'s flag-validation row now measures verbs, not file text.** It grepped
`src/commands/*.ts` for the string `unknownFlags(`, which measured the shape of the fix:
Expand Down
3 changes: 2 additions & 1 deletion docs/COMMANDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ required = ["NEXT_PUBLIC_SENTRY_DSN", "NEXT_PUBLIC_SENTRY_ENVIRONMENT"]
| Command | Purpose |
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| `kit hooks install` | Install hooks declared in `[hooks]`. If no `[hooks]` section exists, it explains that nothing was installed and points to `kit hooks add <name>`. |
| `kit hooks add <name>` | Add a built-in hook (`secret-scan`, `post-pull-audit`, `context-check`) without requiring `[hooks]`. |
| `kit hooks add <name> [--force]` | Add a built-in hook (`secret-scan`, `post-pull-audit`, `context-check`) without requiring `[hooks]`. Installs into the directory git will actually use — `core.hooksPath` is honored, and the path is printed when it resolves OUTSIDE the repo, since deleting that directory then removes the gate silently. `context-check` is **refused** when `.kit.toml` has no `[context]` block: the hook would pass every push and report a gate you do not have. `--force` installs it anyway. |
| `kit hooks sync` | Reconcile installed hooks with config. |
| `kit hooks uninstall` | Remove the configured git hooks. **Enforcement is off until re-installed** — git hooks are the agent-agnostic floor, so this disables the gate that fires in any agent or none. |

Expand Down Expand Up @@ -343,6 +343,7 @@ scope/RoE, so a profile can move to a fresh host without trusting the transport.
| `kit escalate` | Collect failures + format for manual handoff. |
| `kit ci [--strict] [--attest]` | One-shot CI gate (check + design + tests). Scanner-health gate: a crashed / missing / token-less scanner can no longer exit 0 (default warns); `--strict` / `KIT_CI_STRICT=1` (or `[governance.scan].required_scanners`) hard-fails any non-running scanner. |
| `kit context [--format json]` | Print kit context for agent introspection. |
| `kit context check [--json] [--require-declaration]` | Verify the live CLI state against `[context]` — each tool's declared (account, project) pair, never inferred from whatever is logged in. With no `[context]` block it prints a ready-to-paste one from the detected state and exits 0; `--require-declaration` makes that absence a **failure** instead, which is what the `context-check` pre-push hook runs — a gate with nothing to compare against is a check that could not run, not a pass. |
| `kit create-plugin <name>` | Scaffold a new adapter. |
| `kit add <service>` · `kit add --list` | Add service to `.kit.toml`; `--list` prints every available adapter (so does bare `kit add`, which exits 1 as a usage error). |
| `kit version` | Print kit version + exit. |
Expand Down
6 changes: 5 additions & 1 deletion src/check-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ export async function checkHooks(
cwd = process.cwd(),
): Promise<HookCheckResult[]> {
const results: HookCheckResult[] = [];
const hooksDir = resolve(cwd, gitDir, "hooks");
// The SAME resolver the writer uses. Hardcoding `<gitDir>/hooks` here meant that with an
// external `core.hooksPath`, kit installed to one directory and reported on another: the
// declared hooks read as "not installed" while they were installed and firing (#496).
const { resolveHooksDir } = await import("./hooks.js");
const hooksDir = resolveHooksDir(gitDir, cwd);

for (const [hookName, commands] of Object.entries(config)) {
if (!commands || commands.length === 0) {
Expand Down
32 changes: 32 additions & 0 deletions src/check-security.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,36 @@ export async function checkMemoryHooksLiveness(): Promise<SecurityCheckResult> {
};
}

/**
* Git-hook floor — WHERE it is and whether it can fail.
*
* README calls git hooks the agent-agnostic enforcement floor, and nothing reported on them:
* `kit check` had a row for memory hooks and for the PreToolUse gates, none for these. Two
* measured states were therefore invisible (#496, #497): a floor resolved OUTSIDE the repo
* through an absolute `core.hooksPath` (deleting that unrelated directory removed the gate,
* exit 0, no warning), and `context-check` installed with no `[context]` block, which passes
* every push. Skips when the repo has no kit-managed hooks — kit does not claim a floor nobody
* asked for.
*/
export async function checkGitHookFloor(cwd?: string): Promise<SecurityCheckResult> {
const name = "git hook floor";
const category = "exposure" as const;
const root = cwd ?? process.cwd();
const { describeHookFloor, judgeHookFloor } = await import("./hook-floor.js");
let config;
try {
const { loadConfig } = await import("./config.js");
const { resolve } = await import("node:path");
config = await loadConfig(resolve(root, ".kit.toml"));
} catch {
config = undefined;
}
const verdict = judgeHookFloor(describeHookFloor(root, config));
return verdict.severity
? { category, name, status: verdict.status, severity: verdict.severity, detail: verdict.detail }
: { category, name, status: verdict.status, detail: verdict.detail };
}

/**
* Gate liveness — the enforcement floor must prove it exists. If kit installed the
* PreToolUse gates on THIS machine (machine-local marker present) but a gate has
Expand Down Expand Up @@ -2588,6 +2618,8 @@ export async function checkSecurity(cwd?: string): Promise<SecurityCheckResult[]
// has vanished — the agent runs un-gated while kit still reads green. The floor
// must prove it exists.
results.push(await checkGateLiveness(root));
// The git-hook floor: where it resolves to, and whether an installed gate can actually fail.
results.push(await checkGitHookFloor(root));
results.push(await checkDeviceIdOverride());
// `[policy.agent_writes]` posture: an entry naming an op kit never asks about grants nothing while
// still declaring the vendor — which refuses that vendor's real ops. Four documents claimed this
Expand Down
13 changes: 13 additions & 0 deletions src/commands/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ async function cmdContextCheck(): Promise<boolean> {
return findings.every((f) => f.status !== "mismatch");
}
if (!config.context) {
// The hook path passes --require-declaration: for a gate someone installed on purpose,
// "nothing declared" is not a pass, it is a check that could not run (#497). The bare
// command keeps exiting 0 — it is a read-only report, and a repo may legitimately have no
// lock — so only the caller that asked for enforcement gets the strict answer.
if (hasFlag(process.argv, "--require-declaration")) {
console.error(
`${c.red}✗ no [context] block in .kit.toml, so there is nothing to verify — refusing to report a context lock that does not exist.${c.reset}`,
);
console.error(
`${c.dim}Run 'kit context check' without --require-declaration for a ready-to-paste block, or remove the context-check hook.${c.reset}`,
);
return false;
}
console.log(
`${c.dim}No [context] declared in .kit.toml — each CLI is unlocked from its account + project.${c.reset}`,
);
Expand Down
62 changes: 56 additions & 6 deletions src/commands/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ const BUILTIN_HOOKS: Record<string, { hookName: string; commands: string[]; desc
},
"context-check": {
hookName: "pre-push",
commands: ["kit context check"],
// --require-declaration: without a [context] block the check has nothing to compare
// against, and a push gate that always passes is worse than no gate (#497).
commands: ["kit context check --require-declaration"],
description:
"Block a push when the live CLI context (account/project) does not match .kit.toml [context]. Stops pushes to the wrong org/project.",
},
Expand Down Expand Up @@ -194,6 +196,27 @@ async function cmdHooksAdd(): Promise<boolean> {
return false;
}

// A gate that cannot fail must not be installed silently. `kit context check` with no
// [context] block has nothing to compare the live CLI state against, so the pre-push hook
// passed unconditionally while reporting `✓ installed` (#497) — the false green kit exists
// to refuse. --force installs anyway, for someone who is about to add the block.
if (name === "context-check") {
const { hasFlag } = await import("../utils/flags.js");
const cfg = await loadConfig(resolveConfigPath()).catch(() => null);
if (!cfg?.context && !hasFlag(process.argv, "--force")) {
console.error(
`${c.red}✗ refusing to install context-check: no [context] block in ${KIT_FILE}.${c.reset}`,
);
console.error(
`${c.dim}The hook runs \`kit context check\`, which has nothing to compare against without one — it would pass every push and report a gate you do not have.${c.reset}`,
);
console.error(
`${c.dim}Run ${c.bold}kit context check${c.reset}${c.dim} first: it prints a ready-to-paste [context] block from the live CLI state. Then re-run this. Or ${c.bold}--force${c.reset}${c.dim} to install it now and declare the block after.${c.reset}`,
);
return false;
}
}

console.log(
`${c.bold}${c.cyan}kit hooks add ${name}${c.reset} ${c.dim}(git ${builtin.hookName})${c.reset}`,
);
Expand Down Expand Up @@ -238,13 +261,40 @@ async function cmdHooksAdd(): Promise<boolean> {
console.log(
` ${c.green}✓${c.reset} ${builtin.hookName} ${c.green}${r.action}${c.reset} ${c.dim}${r.detail}${c.reset}`,
);
console.log(
`\n${c.dim}Test by staging a file with a fake credential (e.g. ${c.bold}sk_${"test"}_${"A".repeat(20)}${c.reset}${c.dim}) and running ${c.bold}git commit${c.reset}${c.dim} — the commit should be blocked.${c.reset}\n`,
);
// Where it landed, when that is not inside the repo. `✓ installed` with no path is what let a
// floor live in another clone's tree unnoticed (#496).
const { describeHookFloor } = await import("../hook-floor.js");
const floor = describeHookFloor(process.cwd());
if (floor.external) {
console.log(
`\n ${c.yellow}!${c.reset} written to ${c.bold}${floor.dir}${c.reset} ${c.dim}— OUTSIDE this repo (core.hooksPath).` +
` Hooks fire, but deleting that directory silently removes the gate.${c.reset}` +
`\n ${c.dim}keep the floor in the repo with:${c.reset} git config --unset core.hooksPath`,
);
}

// Per-hook test recipe. Every hook used to print secret-scan's, which tells you to stage a
// credential and commit — advice that exercises nothing for a pre-push or post-merge gate.
console.log(`\n${c.dim}${TEST_HINTS[name]}${c.reset}\n`);
return true;
}

/** How to actually exercise each built-in hook, so the hint matches the hook. */
const TEST_HINTS: Record<string, string> = {
"secret-scan": `Test: stage a file containing sk_${"test"}_${"A".repeat(20)} and run git commit — the commit should be blocked.`,
"post-pull-audit":
"Test: merge or pull a branch that adds a dependency — the audit runs after the merge and reports new deps, gitignore drops and introduced secrets.",
"context-check":
"Test: temporarily change one value in [context] (e.g. github.org) and run `kit context check` — it must exit 1 naming the mismatch. Restore it afterwards.",
};

/**
* The directory the install will actually write to — `resolveHooksDir()`, not
* `<repo>/.git/hooks`. The already-installed pre-check below reads this; when it hardcoded
* `.git/hooks` and `core.hooksPath` pointed elsewhere, the check looked at an empty directory
* and every run reported a fresh "installed" for a hook that was already there (#496).
*/
async function ensureHooksDir(): Promise<{ hooksDir: string }> {
const { resolve } = await import("node:path");
return { hooksDir: resolve(process.cwd(), ".git", "hooks") };
const { resolveHooksDir } = await import("../hooks.js");
return { hooksDir: resolveHooksDir(".git", process.cwd()) };
}
7 changes: 5 additions & 2 deletions src/fix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,11 @@ export async function cmdFix(cwd: string = process.cwd()): Promise<boolean> {
// Tool installs go through mise into $HOME — infrastructure provisioning the
// project [scope] RoE does not govern (mirrors the MCP kit_fix site's
// `infrastructure: true`). Git-hook installs resolve their target via
// `core.hooksPath` at runtime; they land inside the repo, which the
// repo-rooted [scope].fs covers.
// `core.hooksPath` at runtime. They land inside the repo ONLY when hooksPath is unset or
// repo-relative: an absolute hooksPath pointing at another checkout puts the write
// outside the repo, i.e. outside what a repo-rooted [scope].fs covers (measured in #496).
// `kit check`'s "git hook floor" row reports that case; declaring the resolved directory
// here would need a dynamic scopeNeeds, which this static declaration cannot express.
scopeNeeds: {
fsWrites: ["skills-lock.json", "cli-lock.json", ".env.template", ".gitignore"],
},
Expand Down
8 changes: 6 additions & 2 deletions src/flag-surface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const COMMAND_FLAGS: Record<string, readonly string[]> = {
"--fail-on-worse",
"--fix",
"--fly-app",
"--force",
"--force-history",
"--from",
"--github-repo",
Expand Down Expand Up @@ -180,7 +181,7 @@ export const COMMAND_FLAGS: Record<string, readonly string[]> = {
"--yes",
],
config: ["--check", "--dry-run", "--force", "--help", "--json"],
context: ["--format", "--json", "--prompt"],
context: ["--format", "--json", "--prompt", "--require-declaration"],
coverage: [
"--attest",
"--claude",
Expand Down Expand Up @@ -224,6 +225,7 @@ export const COMMAND_FLAGS: Record<string, readonly string[]> = {
"--fail-on-worse",
"--fix",
"--fly-app",
"--force",
"--force-history",
"--from",
"--github-repo",
Expand Down Expand Up @@ -279,7 +281,7 @@ export const COMMAND_FLAGS: Record<string, readonly string[]> = {
"guard-observe": ["--all", "--allow-scripts-pending", "--call", "--dry-run", "--help", "--with"],
heal: ["--agent", "--dry-run", "--help"],
health: ["--attest", "--json", "--mode", "--no-auto-install", "--non-interactive"],
hooks: ["--non-interactive"],
hooks: ["--force", "--non-interactive"],
identity: ["--public"],
ingest: ["--attest", "--json", "--mode", "--no-auto-install", "--non-interactive"],
init: [
Expand All @@ -293,6 +295,7 @@ export const COMMAND_FLAGS: Record<string, readonly string[]> = {
"--fail-on-worse",
"--fix",
"--fly-app",
"--force",
"--force-history",
"--from",
"--github-repo",
Expand Down Expand Up @@ -526,6 +529,7 @@ export const COMMAND_FLAGS: Record<string, readonly string[]> = {
"--fail-on-worse",
"--fix",
"--fly-app",
"--force",
"--force-history",
"--from",
"--github-repo",
Expand Down
Loading
Loading