docs(hooks): document the absolute-path assumption in state-line-guard

currentLineCountOf() swallows a read failure as current=0. A relative
file_path resolving against the wrong cwd would silently collapse the
ratchet back to a flat gate (Write) or disable enforcement entirely
(Edit). The Write/Edit tool contracts require an absolute file_path, so
this can't happen in practice -- noted advisor concern, verified against
the tool schemas, recorded in the hook's own comment so a future change
doesn't harden this without re-reading why it was never needed.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0186kZGKddxfA9N84HqMLbb2
This commit is contained in:
Kjell Tore Guttormsen 2026-08-14 17:12:59 +02:00
commit bf11cbf89d

View file

@ -16,6 +16,15 @@
// pre-write-pathguard.mjs, the only other PreToolUse Write/Edit guard in
// this marketplace.
//
// currentLineCountOf() assumes file_path arrives ABSOLUTE - the Write and
// Edit tool contracts both require it, so a relative path never reaches this
// hook in practice. This matters because a read failure is swallowed as
// current=0: a relative path resolving against the wrong cwd would silently
// collapse the ratchet back into the flat gate it exists to avoid (Write) or
// fail open with no enforcement at all (Edit, via the outer readFileSync
// catch). Do not "harden" this away with input.cwd without re-reading why
// it was never needed.
//
// Protocol:
// - Read JSON from stdin: { tool_name, tool_input }
// - Only Write/Edit targeting a file named exactly STATE.md (any