Personal_AI_Infrastructure icon indicating copy to clipboard operation
Personal_AI_Infrastructure copied to clipboard

ISACloseGate: BASH_WRITE_RE misses Node/Bun writeFileSync, so a script-written ISA still trips the gate

Open lockyer-tech opened this issue 3 months ago • 1 comments

isaEditedThisTurn() decides "was the ISA edited this turn?" from the transcript — an edit event, or a command event matching both ISA_MENTION_RE and BASH_WRITE_RE:

const BASH_WRITE_RE = /(write_text|sed\s+-i\b|perl\s+-i\b|>>|\btee\b|git\s+add\b[^&|;]*ISA\.md)/;

The comment above it already names the failure mode from the 2026-08-11 fix:

2026-08-11 false positive: the ISA was updated via a python heredoc and committed in the SAME turn, and this gate blocked anyway because it only read edit events (a gate reading a proxy — the D-63 class — in our own hook).

That diagnosis is right, and the remedy was another proxy. The pattern was widened by one language. The next writer slips through.

Reproduction

Update an ISA from a Bun/Node one-liner, then make a completion claim in the same turn:

bun -e 'const fs=require("fs"); const f="…/MEMORY/WORK/<slug>/ISA.md";
        let t=fs.readFileSync(f,"utf8"); fs.writeFileSync(f, t.replace(a,b));'

ISA_MENTION_RE matches (the path contains ISA.md). BASH_WRITE_RE does not — there is no write_text, no sed -i, no >>, no tee, no git add. The && fails, isaEditedThisTurn() returns false, and the gate blocks with "the ISA hasn't been edited in N tool calls and wasn't updated this turn" — immediately after the ISA was, in fact, rewritten.

Hit live on 2026-08-16 on a downstream fork running the same hook. Same turn, real edit, gate blocked.

Why this class won't close by widening

Every writer that isn't in the list is a future false positive: python -c with open().write(), jq piped through sponge, install -m, cp from a staged temp file, ex/ed, an editor plugin, a bun/node script. The regex enumerates pens; the question is about a file.

Suggested fix

Read the fact instead of the proxy:

statSync(isaPath).mtimeMs > turnStartMs

One syscall, writer-agnostic, and it cannot be defeated by an unanticipated tool.

The honest caveat: this needs a turnStartMs the hook may not currently carry — the earliest transcript event timestamp for the turn is the obvious candidate. If that baseline isn't reachable, a cheaper partial improvement is to keep the transcript check as a fast path and fall back to mtime only when it says "no edit", which turns a false block into a correct pass without changing the common case.

Either way the regex stops being load-bearing, which is the point of the D-63 note in your own comment.

lockyer-tech avatar Aug 16 '26 04:08 lockyer-tech

Fixed in source: the transcript regex stays as the fast path, and when it says "no edit" the gate now checks the fact—the ISA file's mtime against turn start—before blocking (hooks/ISACloseGate.hook.ts). You were right that the class doesn't close by widening the pen list, and right that our own D-63 comment said so. Thanks.

danielmiessler avatar Aug 17 '26 23:08 danielmiessler