Skip to content

feat(audit): kit audit verify --all — the union view over every sealed log - #492

Merged
sandstream merged 1 commit into
mainfrom
feat/audit-union-view
Aug 20, 2026
Merged

sandstream merged 1 commit into
mainfrom
feat/audit-union-view

Conversation

@sandstream

Copy link
Copy Markdown
Owner

Closes #470 (part 1). Part 2 of that issue is already in main — see On part 2 below.

What

kit audit verify --all [--json] — the union view over every audit log this machine has sealed, instead of the one in cwd.

~/.kit/audit-anchor.json already keyed the HMAC tip per log path and is shared by every working tree on the machine; before this, the only reader outside audit-anchor.ts looked up a single path (hints.ts). The iteration was the whole missing feature.

The outcome split is the requirement, not a nicety

Most anchored paths on a dev machine are short-lived test temp dirs (12 of the 15 measured in #470), so a command that alarms on a vanished log is a command nobody reads — and an unread report is the failure mode #470 is about, one level up. So four outcomes:

outcome means counts toward the verdict
verified sealed prefix reproduces the tip, nothing past the seal —
stalled log is there but the seal no longer covers it: unsealed tail, or a rotated anchor key warns; fails under --strict / [governance.audit].require_anchor
missing log path is gone (temp dir, deleted clone) never
failed chain break, truncation, tip mismatch, or a seal that could not be checked at all exit 1

Two deliberate constraints:

  • The exit policy is the one decideAnchorVerdict already applies to a single tree. An unsealed tail warns there and fails under strict; diverging would mean the same log verifies green in one command and red in the other, which is its own false verdict.
  • Exit codes stay [0, 1]. src/public-surface.ts declares that set for every stable command, so the missing/stalled distinction is carried by the report and --json, not by a third exit code. (gate-* uses 2, but those are x-kit-audience: harness.)

Coverage that could not run is failed, never verified: an unreadable log, an unreadable anchor key, and an anchor record that vanished mid-walk all land there.

On part 2 (thread cwd in elevation.ts)

Measured, not assumed — that threading is already present, and was present at the version the issue measured:

$ git show v6.6.3:src/elevation.ts | sed -n '56,78p'
async function auditElevationDecision(operation, granted, reason, method, cwd) {
  return appendAuditEventDirect({ operation: "elevation-check", ... }, { cwd });
}

requireElevation(operation, cwd) and consumeElevation(operation, cwd) thread it through every decision path including the KIT_ELEVATED=1 branch, and elevation.test.ts:226 already asserts the bypass entry lands in the handed tree. Nothing to change, so nothing was changed.

What the issue was right about is the reader, and that is what this PR fixes: the elevation record was being written into one of N logs that no command read together.

Two observations for a follow-up rather than scope creep here:

  • appendAuditEventDirect is called without cwd in environment.ts:127, read-only-mode.ts:42, policy.ts:144 and commands/panic.ts:94. Each defaults to process.cwd(), which for a CLI is the governed tree, so none is a live bug — but they are the same shape as the call site Audit: nothing reads the anchor record, so N working trees give N green verdicts and no union view #470 flagged.
  • Anchor keys are absolute paths, not realpaths. A log reached through a symlinked path (/tmp → /private/tmp on macOS) anchors under one spelling and verifies under the other. It cost this PR a test failure before the fixtures were realpathSync'd; on a real machine it would show as no-anchor on a log that is in fact sealed.

Tests

src/audit-anchor-all.test.ts — 19 tests, and deliberately not only over the classifier: #470 is an instance of trap 5 (a correct data structure with no reader), so the second half runs the compiled CLI against a real ~/.kit-shaped anchor dir holding real hash-chained logs.

  • classification: verified · unsealed tail · rotated key · gone · present-but-unreadable · chain-broken · truncated · a valid-but-substituted chain (writer-only re-chain → tip-mismatch) · unreadable key
  • verdict policy: 12 missing paths never fail, at either strictness; stalled warns then fails under --strict; one failed path sinks a set of verified ones
  • end-to-end: three trees in one anchor dir report verified / stalled / missing with exit 0; --strict turns the stalled one into exit 1; a rewritten sealed prefix in another tree exits 1 while kit audit verify in the clean cwd still exits 0 and never mentions it — the two-greens problem, asserted

Verification

🤖 Generated with Claude Code

…d log

`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 under a worktree-per-session agent harness — that produced N
green verdicts and no whole-machine answer.

The data was already on disk and unread: ~/.kit/audit-anchor.json keys the HMAC
tip per log path and is shared by every tree (15 paths on the machine that filed
#470), and the only reader outside audit-anchor.ts looked up a single path.

Four outcomes, because collapsing them is what makes such a report unreadable:
verified; stalled (log present, seal no longer covers it — unsealed tail or a
rotated anchor key); missing (log path gone: temp dir or deleted clone, which is
most of those 15 paths and never a finding); failed (chain break, truncation,
tip mismatch, or a seal that could not be checked at all).

Exit 1 on any failed; a stalled seal warns and fails under --strict /
[governance.audit].require_anchor — deliberately the same policy
decideAnchorVerdict already applies to a single tree, since the same evidence
must not verify green in one command and red in the other. Exit codes stay
[0, 1] per public-surface.ts, so the missing/stalled distinction is carried by
the report and --json, not by a third code.

Tests cover the classifier and, because #470 is itself an instance of trap 5
(a correct data structure with no reader), the compiled CLI against a real
anchor dir holding three trees: one verified, one stalled, one vanished, plus a
rewritten sealed prefix in another tree that the clean cwd's own verify cannot
see.

Refs #470

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 6148085 into main Aug 20, 2026
19 checks passed
@sandstream
sandstream deleted the feat/audit-union-view branch August 20, 2026 08:11
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.

Audit: nothing reads the anchor record, so N working trees give N green verdicts and no union view

1 participant