The build
Why this exists
It started as a prompt I kept pasting into a chat window, and became a tool the moment I noticed I didn't trust the answers.
Project vitals
- Stack
- TypeScript (strict, NodeNext)Claude Agent SDK · commander · picocolors
- Surface
- 3 commandsanalyze · apply · clean
- Tests
- 6/6 guard · 16/16 parityPure functions — no API key needed
- Runtime deps
- 3
- Licence
- MIT
The itch
I had a long spec I'd paste into a chat: compare my repo to this one, tell me what's missing, don't just list everything. It worked, sort of. What came back was always agreeable. Every reference repo apparently had fifteen things mine needed. The list never shrank no matter how small my project was.
The second problem was worse. When I let the model actually make the changes, I got one commit touching a dozen files, some of which I hadn't asked for. Reviewing it took longer than doing the work.
So the tool got built around the two things the chat window couldn't do: make the model's "no" trustworthy, and make its write access narrow enough that I'd actually run it.
Timeline
Five months, one honest wall
-
March 2026 · Ideation
A spec file I kept copy-pasting
Wrote
GAP_ANALYSIS_SPEC.md— a long prompt with ground rules about licences, approval gates and no padding. Used it manually on four of my own repos. It was clearly a tool wearing a document's clothes. -
April 2026 · Scoping
Two phases, hard boundary between them
Settled the shape: analysis produces a report and touches nothing; implementation happens later, per item, only after approval. Everything since has been in service of keeping that boundary real.
-
May 2026 · MVP
First working run on the Agent SDK
Wired up
query(), streamed the tool calls, got a report out the other end. It worked and I didn't trust it — the read-only rule was still just a sentence in a prompt. -
June 2026 · Where it got hard
The rails had to move out of the prompt
This is the part that broke everything and then fixed it. Rewriting the constraints as a
canUseToolinterceptor meant reasoning about tool inputs I didn't control — and I got the first version wrong. A read-only prefix laundered a destructive suffix:ls && rm -rf srcsailed through because I checked the command, not its segments. That bug is now test three. -
June 2026 · Licence policy
Reading LICENSE before reading code
Realised the agent was happily describing GPL implementations in enough detail to reproduce them. Added classification up front, so the policy is in the system prompt before the first file is opened.
-
July 2026 · Polish & launch
Two bugs found by running it badly
A starved turn budget produced a thorough exploration and zero output. A finished report came back stamped with a date from the model's training prior. Both fixed — one in the prompt, one in code. Then the docs, the guard suite, and this site.
Technical decisions
The three that mattered
Constraints as interceptors, not instructions
The problem: "Phase 1 is read-only" in a system prompt is a request. A model that decides the rule doesn't apply will act, and you find out afterwards.
The solve: every constraint that matters lives in canUseTool, which runs before the tool does. Writes outside the report file are denied. Bash is allowlisted per chained segment. Denials return a reason, so the model adapts instead of retrying blindly.
The tradeoff: the allowlist is conservative, so occasionally the agent can't run a command it would have found useful. It routes around with Read and Grep. I'd rather it be mildly inconvenienced than mildly destructive.
Licence classification before analysis
The problem: "port this pattern" is fine for MIT and a licensing problem for AGPL. Deciding afterwards is too late — by then the model has already written the description.
The solve: read LICENSE immediately after cloning, classify it into permissive / copyleft / unlicensed, and turn that into a policy sentence injected into the system prompt. No licence file is treated as the strictest case, not the loosest — all rights reserved by default.
Post-hoc correction of facts the programme owns
The problem: the first real run stamped the report 2025-01-21, ignoring the correct date interpolated into its own prompt.
The solve: the licence and date lines are rewritten in code after generation. It's a small module, and it encodes a rule I now apply everywhere — if the programme can know something, the programme decides it. Don't ask a model to carry a fact you already hold.
Stack
Why each piece
| Piece | Why this one |
|---|---|
@anthropic-ai/claude-agent-sdk | Ships the agent loop, the tool set, and — critically — a permission callback. The rails exist because the SDK exposes that hook. |
TypeScript (strict, NodeNext) | The SDK's union types do real work here. Narrowing SDKMessage by type catches mistakes the docs wouldn't have. |
commander | Two subcommands with flags. Anything heavier would be furniture. |
picocolors | Terminal colour in ~2 kB. The output is the interface, so it needed to read well. |
node:test | Built in. The guards are pure functions, so the suite needs no API key and no mocking framework. |
git (shallow clone) | --depth 1 into the temp directory. Fast, and structurally incapable of landing in your history. |
Honest limits
What it doesn't do
- Single-shot. It doesn't watch the repo or re-run on changes.
- Shallow clone means findings reflect the reference's current
HEAD, not its history or its reasoning. - Quality of the report tracks quality of the goal you give it. A vague goal gets a vague report — the scoring has nothing to score against.
- Bash allowlisting is deliberately conservative and will occasionally be annoying.
Links
Go read the code
The interesting file is src/guard.ts. It's about a hundred lines and it's the whole argument.
Want to build something, or collaborate?
Want to build something — or break something interesting? Let's talk.