寫給星期日的自己:使用免費額度前的三項檢查
Letter to Sunday-Me: Three Checks Before You Burn a Free Allowance
作者分享自己曾把 AI 智能體指向程式碼庫,結果免費額度耗盡、產生的 diff 無法使用,並提出三項事前檢查。檢查包括在 worktree 隔離改動並設定可寫路徑、記錄每次執行的 token 用量且在額度 60% 時停止探索,以及關機前保存基準 SHA、ledger.jsonl 和快照雜湊。
Sunday, 08:40. I opened a free cloud box and pointed an agent at a repo. By 14:10 the allowance was gone and the diff was useless.
This is not a story about a weak model. The model did what I asked. The harness around it had no boundary, no counter, and no snapshot.
Three cheap checks would have saved the day. Here is the letter I should have read at 08:35.
Mistake 1: I handed the runner my whole checkout
The agent edited a vendored folder and two lockfiles. Reverting took forty minutes. The real cost was trust: I stopped reading diffs carefully.
A model with file access is a process with file access. Treat it that way. Give it a worktree, never your live branch.
Step 1 — Commit and record the base SHA.
git switch -c agent/2026-10-19
git commit -am "checkpoint before agent run" --allow-empty
git rev-parse HEAD | tee .agent-base-sha
Step 2 — Create a detached worktree for the run.
git worktree add --detach .agent/work "$(cat .agent-base-sha)"
The agent writes inside .agent/work. Your checkout stays clean. Review becomes git diff against a known SHA.
Step 3 — Put the writable allowlist in the task brief. The runner reads it. You read it too, before the first prompt.
# AGENT_TASK.md
Writable: src/, tests/
Read-only: vendor/, package-lock.json, pnpm-lock.yaml, migrations/
Done when: `pnpm test --filter unit` exits 0 AND the diff touches <= 6 files.
A worktree is not a sandbox. It only limits blast radius. If the agent can also run shell commands, you still need process isolation.
Mistake 2: I treated the free allowance as bottomless
I never counted tokens per run. So the wall arrived mid-task, with no summary and no exit state. I had to re-prompt from memory and paid twice.
One appended JSON line per run fixes this. The snippet below is a sketch, not executed in this post.
mkdir -p .agent
ledger() {
local run="$1" tokens="$2" secs="$3" status="$4"
printf '{"run":"%s","tokens":%s,"seconds":%s,"status":"%s","at":"%s"}\n' \
"$run" "$tokens" "$secs" "$status" "$(date -u +%FT%TZ)" \
>> .agent/ledger.jsonl
}
budget_guard() {
: "${FREE_ALLOWANCE:?copy the current number from the dashboard}"
local spent
spent=$(jq -s 'map(.tokens) | add // 0' .agent/ledger.jsonl)
awk -v s="$spent" -v a="$FREE_ALLOWANCE" \
'BEGIN { exit (s > a * 0.6) ? 1 : 0 }' \
&& echo "ok: $spent of $a" \
|| echo "STOP: switch to summary mode"
}
Two rules made the ledger useful to me:
- Stop the exploration phase at 60% of the allowance.
- Spend the remainder on the fix pass, not on new features.
Read FREE_ALLOWANCE from the provider dashboard every session. Free quotas move. A number you memorized last month is a guess, not a fact.
Mistake 3: I tore down the box with nothing on disk
I deleted the server and lost the ledger, the prompt history, and the partial patch. Nothing was replayable. I could not even prove which command produced which file.
Step 1 — Snapshot before shutdown.
tar -czf "snap-$(date -u +%Y%m%dT%H%MZ).tgz" \
--exclude=.agent/work/node_modules \
.agent .agent-base-sha
tar -tzf snap-*.tgz | head -n 20
sha256sum snap-*.tgz | tee snap.sha256
Step 2 — Store the triple. Base SHA, ledger.jsonl, and the snapshot hash travel together. That triple is your replay record.
Step 3 — Diff before you apply. Apply only paths in the allowlist. Anything else goes back to the agent as a question.
Choosing where the run lives
| Situation | Local container | Free hosted server | Paid capacity |
|---|---|---|---|
| Repo already cloned, laptop cool | Best fit | Fine | Unnecessary |
| Laptop thermally throttled | Weak | Good fit | Fine |
| Run may exceed an hour | Fine | Risky, quota unknown | Best fit |
| Repo contains production secrets | Fine if network is off | Do not | Do not |
| You need a guaranteed wall clock | Fine | No | Yes |
| You want a replayable snapshot | You must script it | You must script it | You must script it |
Notice that the last row never changes. Snapshotting is your job on every option.
Where MonkeyCode fits in this loop
Disclosure: This article was prepared as part of MonkeyCode's product outreach.
MonkeyCode is an open-source project offering free model access and a free server option. Those two availability claims come from the operator, and quota details can change, so confirm the current numbers on the project's site before you plan a session around them.
In this workflow, the free model access removes the key-provisioning step. The free server removes the "my laptop fan is screaming" problem. Neither removes the need for the three checks above.
Use it for short, bounded runs: one allowlisted task, one ledger entry, one snapshot. Do not schedule a multi-day unattended pipeline on free capacity. That is not what free tiers are for, and you will not enjoy the failure mode.
Where this approach does not apply
- Regulated environments that forbid third-party compute.
- Repos you cannot push to any remote, including a private mirror.
- Teams that cannot review every diff. This harness assumes a human reads the patch.
- Long migrations where the run must survive a box restart.
If you are in one of those groups, keep the allowlist and the ledger, drop the hosted box.
What I would tell Sunday-Me
Commit first. Count second. Snapshot third. Only then open the prompt.
The checks cost about ten minutes to write and one line per run to maintain. The day they cost me nothing was the day I skipped them.
If you try the free allowance, put ledger.jsonl next to it and tell me what your first run actually cost. That number is worth more than any recommendation, mine included.
來源:DEV Community · dev.to