跳到正文
DEV Community· Heinrich Neb·· 59 分鐘前AI 評分68

proof-gate 如何用單一 Node 檔案核驗 AI 智能體的任務完成聲明

My AI swore all tests passed. Here's the free one-file fix that makes it prove it.

AI 導讀

作者介紹 proof-gate:這個單一 Node 檔案會執行設定的任務檢查並生成執行憑證,讓 AI 智能體以退出碼證明任務完成。憑證記錄 commit、時間、各指令退出碼及輸出末 20 行;控制項須在預期錯誤情況下失敗,否則閘門會判紅。

正文

My agent told me "All tests pass." It had run 74 of our 105 test files. Another time it wrote "The email went out at 08:45." The clock said 08:37. A third time: "14 people clicked Sign in." Those were page views. Nobody had counted clicks.

None of that was lying. The agent said what it believed. The trouble is that "done" is a sentence, and a sentence costs nothing to write.

So I stopped accepting sentences. A task is done when one command exits 0. The command writes a receipt, and the agent pastes the receipt instead of the word "done". Here is the free version of that, in a single file.

What you get

proof-gate is one Node file. No dependencies, MIT, 8 tests of its own. It does two things for every task:

  1. It runs your checks (tests, build, lint, anything with an exit code).
  2. It writes a receipt: the commit, the time, every command and its exit code.

It works the same with Claude Code, Cursor, Copilot or a plain shell. It does not talk to any model. It only reads exit codes.

Step 1: put the file in your repo

git clone https://github.com/cachly-dev/proof-gate
cp proof-gate/proof-gate.mjs ./proof-gate.mjs

You need Node 18 or newer. That is the whole install.

Step 2: describe one task

Create proof-gate.json in your project root. This one guards a rate limiter:

{
  "tasks": {
    "rate-limit": {
      "checks": [
        { "name": "acceptance", "run": "node --test test/rate-limit.test.mjs" },
        { "name": "build", "run": "npm run build" }
      ],
      "controls": [
        {
          "name": "says no when the limit is off",
          "run": "node --test test/rate-limit.test.mjs",
          "env": { "RATE_LIMIT_DISABLED": "1" }
        }
      ]
    }
  }
}

The controls block is the part people skip, so one line on it. A control is the same check pointed at something that is supposed to be wrong. It must fail. If it passes, the gate goes red, because a check that cannot fail proves nothing. I cover that in a separate post. For now, copy the block and adapt it.

Step 3: run it

node proof-gate.mjs rate-limit
TASK: rate-limit
GATE: 0 (3/3)
RECEIPT: .proof-gate/receipts/rate-limit.json
NOTE: -

Four lines. Exit code 0 means green, 1 means red, 2 means refused (the setup is incomplete and nothing was judged). Refused is never green.

When something is wrong you get the first problem in NOTE:

TASK: rate-limit
GATE: 1 (2/3)
RECEIPT: .proof-gate/receipts/rate-limit.json
NOTE: control passed, so the check cannot say no: says no when the limit is off

Step 4: make the agent hand over the receipt

Add this to CLAUDE.md, AGENTS.md or your Cursor rules:

## Done means
- A task is done when `node proof-gate.mjs <task>` exits 0. Paste its four lines.
- If the gate is red, say so. Do not call the task done.

That is the change. The agent can still be wrong, but it can no longer be wrong quietly.

Why a receipt and not just the exit code

The receipt is .proof-gate/receipts/rate-limit.json. It holds the commit hash, a dirty flag, the time, and the last 20 lines of output from every command.

On 24 November my own worker agent reported "gate green". I looked at the receipt. The commit in it was the one before the agent's change. The agent had run the gate before it committed, so the green belonged to the old code. Without the commit in the receipt I would have believed it.

The same day, a feature gate of mine was green with 6 of 6 steps. The full server tests were red. One of them requires that every server route has a caller in the app, or a written reason why not. My gate had never included the full tests. I found it before the push, and now the full test run is part of the gate. A gate is only as honest as the list of things in it, and the receipt makes that list visible. If the checks you expected are not in the receipt, you see it.

Where it runs

The gate is a plain command, so it fits wherever you can run a shell command:

  • In Claude Code, the agent runs it itself. The rule in CLAUDE.md tells it to.
  • In Cursor or Copilot, put the same rule in your rules file or instructions, and run the gate yourself if the agent does not.
  • In CI, add one line: node proof-gate.mjs rate-limit. The exit code decides whether the job passes.

You can also run it after the agent says "done" and before you read a single line of the diff. If it is red, you saved yourself the reading.

What it is not

  • Not a test runner. It calls yours.
  • Not an AI judge. Every decision comes from an exit code.
  • Receipts keep the last 20 lines of each command's output. Keep secrets out of your test output, or add .proof-gate/receipts/ to .gitignore.

Try it tonight

Pick one task you gave an agent this week. Write its proof-gate.json entry with one check and one control. Run it. Two things can happen. It goes green and you now have a receipt. Or it goes red or refused, and you just learned something about a task you thought was finished.

The repo is here: github.com/cachly-dev/proof-gate. There is also a full version, free: the Agent Proof Kit, with task packs, a model ladder and a ledger around the gate. Leave your address at cachly.dev/forge and the download link arrives after you confirm. That is all I will say about it here.

What is the last "done" from an agent that turned out not to be?


I build cachly. It keeps what you explain to your AI: your rules, your decisions and the bugs you already solved. Claude Code, Cursor, Copilot and the others read it in every session, for you alone or for your whole team, and every lesson carries the name of whoever learned it.

Try it, in increasing order of commitment:

  • 30 seconds, no account: npx @cachly-dev/mcp-server@latest demo in any git repo. It reads your log locally and prints what an assistant would already know about the project. After npx fetches the package, the command makes no network calls.
  • Claude Code plugin: /plugin marketplace add cachly-dev/cachly-mcp, then /plugin install cachly-brain@cachly.
  • 5 minutes, free tier: npx @cachly-dev/mcp-server@latest autopilot writes the MCP configuration for whichever assistant you use.
  • Or from the web: cachly.dev · free tier, servers in Germany.

On Product Hunt from 1 December: cachly on Product Hunt. Follow it there if you want a note on launch day.

Written with AI assistance.

來源:DEV Community · dev.to