02 · AI 風控機制02 · AI risk controls
AI 操作防護閘AI action guard
讓 AI 自動工作,但不准它擅自刪檔。每一條 AI 要執行的指令,先過一道檢查;危險的一律攔下,等我決定。Let AIs work on their own, but never delete files on their own. Every command an AI wants to run goes through a check first; anything dangerous is stopped until I decide.
解決什麼問題The problem
AI 編程助手可以自己執行指令,效率很高,但一個誤判就可能刪掉整個資料夾。我定下的底線是:檔案可以寫,但不可以刪除或移動,任何刪除、搬移、對外發送都要我批准。光靠「叫 AI 小心」不夠,要用程式去擋。AI coding assistants can run commands by themselves, which is efficient, but one misjudgement could wipe a whole folder. My bottom line is that files may be written but never deleted or moved, and anything that deletes, moves or sends something outside needs my approval. Telling an AI to “be careful” is not enough; it has to be enforced in code.
系統怎樣運作How it works
- 在指令執行前攔截。掛在 Claude Code 和 Codex 的執行前掛鉤上,讀取將要執行的指令文字。Intercept before running. It hooks into the pre-execution step of Claude Code and Codex and reads the command text about to run.
- 分類風險。寫入放行;刪除、移動或改名、丟棄未儲存的改動、對外動作(上傳、部署、發佈)一律攔截。Classify the risk. Writing is allowed; deleting, moving or renaming, discarding unsaved changes and outward actions (pushing, deploying, publishing) are all intercepted.
- 按場合處理。我在場時彈出確認,由我按;自動或無人值守時直接拒絕,並寫入待批准清單。Handle by situation. When I am present a confirmation prompt appears and I press the button; in automatic or unattended runs the action is refused outright and added to an approval list.
- 只放行暫存資料夾。清理暫存目錄內的檔案是例外,因為那些檔案本來就是可丟棄的。Only the temp folder is exempt. Clearing files inside the temporary directory is allowed because those files are disposable by nature.
- 留下紀錄。每次攔截都寫進紀錄檔,之後可以回看。Leave a record. Every interception is written to a log that can be reviewed later.
展示什麼能力What it demonstrates
- 風險分級:分清楚哪些動作可放行、要確認、要拒絕。Risk tiering: telling apart what can pass, what needs confirmation and what must be refused.
- 權限設計:同一個動作在「我在場」和「無人值守」下有不同處理。Permission design: the same action is handled differently when I am present and when nobody is watching.
- 實測而非假設:每次改動都用真實的 AI 工具去試。Testing rather than assuming: every change is tried against the real AI tools.
重點數字Key facts
- 21 個自動測試。21 automated tests.
- Claude Code 和 Codex 兩套工具都經實測:刪除專案檔被攔截,刪除暫存檔放行。Tested against both Claude Code and Codex: deleting a project file is blocked, deleting a temp file is allowed.
- 自動或無人值守的環境一律拒絕確認提示,並寫入待批准清單。In automatic or unattended runs, confirmation prompts are always refused and logged to a pending-approval list.
工具與技術Tools and technology
Python(guard.py)、Claude Code 的 PreToolUse 掛鉤、Codex 掛鉤、待批准清單與紀錄檔。Python (guard.py), Claude Code's PreToolUse hook, Codex hooks, an approval list and a log file.