Repository navigation
feat(audit): kit audit verify --all — the union view over every sealed log - #492
Merged
Merged
Conversation
…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>
|
✅ Docker image built successfully
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 incwd.~/.kit/audit-anchor.jsonalready keyed the HMAC tip per log path and is shared by every working tree on the machine; before this, the only reader outsideaudit-anchor.tslooked 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:
verifiedstalled--strict/[governance.audit].require_anchormissingfailedTwo deliberate constraints:
decideAnchorVerdictalready 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.[0, 1].src/public-surface.tsdeclares 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 arex-kit-audience: harness.)Coverage that could not run is
failed, neververified: an unreadable log, an unreadable anchor key, and an anchor record that vanished mid-walk all land there.On part 2 (thread
cwdinelevation.ts)Measured, not assumed — that threading is already present, and was present at the version the issue measured:
requireElevation(operation, cwd)andconsumeElevation(operation, cwd)thread it through every decision path including theKIT_ELEVATED=1branch, andelevation.test.ts:226already 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:
appendAuditEventDirectis called withoutcwdinenvironment.ts:127,read-only-mode.ts:42,policy.ts:144andcommands/panic.ts:94. Each defaults toprocess.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./tmp→/private/tmpon macOS) anchors under one spelling and verifies under the other. It cost this PR a test failure before the fixtures wererealpathSync'd; on a real machine it would show asno-anchoron 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.tip-mismatch) · unreadable key--strict; one failed path sinks a set of verified onesverified/stalled/missingwith exit 0;--strictturns the stalled one into exit 1; a rewritten sealed prefix in another tree exits 1 whilekit audit verifyin the clean cwd still exits 0 and never mentions it — the two-greens problem, assertedVerification
npm teston this branch: 4307 tests, 0 fail, 0 skipped (macOS, non-root)kit self-audit: 16 rules, 0 fail — including theundocumented commandsrule from feat(self-audit): check documentation in the other direction too #491npx tscclean;prettierapplied to the touched.tsfiles🤖 Generated with Claude Code