4.1
A rule in a prompt is a request提示裡的規則只是請求提示里的规则只是请求
This chapter assumes you have read Hooks: a hook is code that tool calls pass through, and it can refuse the call.
讀這一章,請先讀過 Hooks:每次呼叫都會經過的執行點:hook 是工具呼叫都要經過的程式碼,它可以拒絕這次呼叫。
读这一章,请先读过 Hook:每次调用都会经过的执行点:hook 是工具调用必经的一段代码,它可以拒绝这次调用。
The Knowledge經驗分享经验分享
In one sentence
A rule in a prompt is only a request; a rule in code is a rule. Start with words, and move a rule into code when it keeps being broken or the harm cannot be undone.
This chapter is about how firmly a rule is held (safety). It is not about which is the cheapest thing that can make a call; that is Who decides.
一句話
寫在提示裡的規則只是請求;寫在程式碼裡的規則才是規則。先從文字開始,當一條規則一直被違反、或傷害無法挽回時,再把它搬進程式碼。
這一章談的是一條規則守得多牢(安全)。它不談哪個最便宜的東西能做出判斷;那是誰來判斷:程式、便宜模型、主模型、人。
一句话
写在 prompt 里的规则只是请求;写在代码里的规则才是规则。先从文字开始,等一条规则老被违反,或者造成的伤害无法挽回,再把它挪进代码。
这一章讲的是规则守得有多牢(安全)。至于由谁来做判断最划算,那是谁来判断:代码、便宜模型、主模型、人的话题。
For leaders
- The decision: decide which rules may stay as written words and which must be enforced by code. A rule moves to code when it keeps being broken, when the harm cannot be undone, or when other steps rely on it.
- The risk: a rule written in a prompt is only a request. In my own setup, a hook that put my rules at the start of each prompt ran every time, yet many prompts still arrived without them. That was one setup and one batch in October 2026, not a general rate, and I have no numbers on how often written rules are broken.
- The cost of doing it right: code has a price: it must be written, tested and kept up when the platform changes. Most rules do not need it, so this is a few rules, not all of them.
- Ask the team: "Which of our rules would do damage we cannot undo if the agent broke it once, and is each of those held by code or only written in a prompt?"
給主管
- 要做的決定:決定哪些規則可以只留作寫下來的文字,哪些必須由程式碼強制執行。一條規則在一直被違反、傷害無法挽回、或其他步驟依賴它時,就搬進程式碼。
- 風險:寫在提示裡的規則只是請求。在我自己的設定裡,有個 hook 把我的規則放在每個 prompt 的開頭,它每次都執行了,但還是有很多 prompt 到達時沒有帶著規則。那是一個設定、2026 年 10 月的一批資料,不是一般的比率,而寫下來的規則多常被違反,我沒有數字。
- 做對的成本:程式碼有價錢:要寫、要測、平台變動時要維護。大多數規則不需要它,所以是少數幾條規則,不是全部。
- 可以問團隊:「我們的規則裡,哪些如果 agent 違反一次就會造成無法挽回的傷害?其中每一條是由程式碼守著,還是只寫在提示裡?」
写给管理者
- 要拍板的事:决定哪些规则可以只用文字写着,哪些必须由代码强制执行。一条规则老被违反、伤害无法挽回,或者别的步骤依赖它时,就该挪进代码。
- 风险:写在 prompt 里的规则只是请求。在我自己的配置里,有个 hook 会把我的规则放到每条 prompt 的开头,它每次都运行了,可还是有很多 prompt 到达时没有带上这些规则。那只是一套配置、2026 年 10 月的一批数据,不是普遍的比率,写下来的规则多久被违反一次,我没有数字。
- 做对的代价:代码是有成本的:要写、要测,平台一变还要维护。大多数规则用不着,所以是少数几条,不是全部。
- 可以问团队:“我们的规则里,哪些一旦 agent 违反一次就会造成无法挽回的损害?这些规则每一条,是由代码守着,还是只写在 prompt 里?”
The problem
You write a rule in the instruction file: "never touch the generated files". The agent follows it for a week. Then it does not. You read the rule again. It is still there, and it is clear. Nothing in the file changed. What changed is that the agent had other things to think about.
A prompt is the text the model reads: your request, the instruction files, the skills it loaded. A rule written there is a sentence like any other. The model weighs it against the other sentences, and sometimes the others win. The longer the chat, the more other sentences there are (Long chats get worse).
Even getting the sentence in front of the model is not certain. In Hooks I counted a batch of prompts in my own setup in October 2026: a hook that put my rules at the start of each prompt ran every time, yet many prompts still arrived without them. It is one setup and one batch, not a general rate. If delivering a rule can fail, obeying it can fail more.
So there are two kinds of rule, and they are easy to mix up:
- A request. You ask the model to behave. It usually does. No one can promise it always will.
- A rule. Code stands in the way. As long as the code runs and sees the call, it is refused whatever the model thinks.
Anything that must hold has to be the second kind. But code is not free, and most rules do not need it. The question of this chapter is: which rule goes where?
問題
你在指令檔裡寫了一條規則:「絕對不要碰產生出來的檔案」。agent 遵守了一個星期。然後它沒有。你再讀一遍規則。它還在,也很清楚。檔案裡什麼都沒變。變的是,agent 有別的事要想。
prompt 是模型讀的文字:你的請求、指令檔、它載入的 skill。寫在那裡的規則,和別的句子一樣是一句話。模型把它和其他句子放在一起權衡,有時其他句子贏。對話越長,其他句子越多(長對話會變差)。
就連把這句話送到模型面前,也不是確定的。在 Hooks:每次呼叫都會經過的執行點裡,我數了我自己設定在 2026 年 10 月的一批 prompt:有個 hook 把我的規則放在每個 prompt 的開頭,它每次都執行了,但還是有很多 prompt 到達時沒有帶著規則。那是一個設定、一批資料,不是一般的比率。傳達規則都可能失敗,遵守規則更可能失敗。
所以規則有兩種,而且很容易搞混:
- 請求。你請模型照這樣做。它通常會。沒有人能保證它永遠會。
- 規則。有程式碼擋在路上。只要程式碼在執行、看得到這次呼叫,不管模型怎麼想,它都會被拒絕。
任何一定要成立的東西,必須是第二種。但程式碼不是免費的,大多數規則也不需要它。這一章的問題是:哪條規則放在哪裡?
问题
你在指令文件里写了一条规则:“绝不碰生成的文件”。agent 遵守了一周。然后它不守了。你再读这条规则。它还在那里,写得很清楚。文件里什么也没变。变的是,agent 当时有别的事要考虑。
prompt 是模型读到的文本:你的需求、指令文件、它加载的 skill。写在那里的规则,和别的句子一样,只是一句话。模型会把它和别的句子放在一起权衡,有时别的句子胜出。对话越长,别的句子就越多(长对话会变差)。
连能不能把这句话送到模型面前,都不确定。在 Hook:每次调用都会经过的执行点里,我数过自己配置里 2026 年 10 月的一批 prompt:有个 hook 会把我的规则放到每条 prompt 的开头,它每次都运行了,可还是有很多 prompt 到达时没有带上这些规则。这是一套配置、一批数据,不是普遍的比率。如果送达一条规则都可能失败,那遵守它失败的可能还要更大。
所以规则有两种,而且很容易混淆:
- 请求。 你请模型守规矩。它通常会守。没人能保证它永远会守。
- 规则。 有代码挡在路上。只要代码在运行、看得到这次调用,不管模型怎么想,调用都会被拒绝。
凡是必须成立的事,都要是第二种。但代码不是免费的,大多数规则用不着。这一章要回答的问题是:哪条规则放在哪里?
How it works
Four levels of firmness
A rule can be held at four levels. Each one promises something different, and each one has a limit.
| Level | What it is | What it promises | Its limit |
|---|---|---|---|
| Words | The rule is written in an instruction file, a skill, or the body of an agent | The agent knows the rule and why it exists | It may not comply |
| A command that checks itself | The agent does the operation through a small program of yours, which checks the conditions before it acts | The same result every time, on any platform | It guards only what goes through it. If the agent edits the file by hand, the command is never called |
| A hook that refuses | Code the platform runs before tool calls, which can say no | The call is stopped, in the modes I tried, even when no one is watching | It depends on the platform, and it sees the call, not the effect (Hooks) |
| Found afterwards | A health check (a command that tests whether the setup is sound), a test run, a read of the logs | A breach can be found and counted | It cannot prevent anything. It is detection, not prevention |
The last level is different in kind. It does not hold the rule; it tells you whether the others held. You need it at every level, because a rule you cannot see being broken is a rule you are guessing about.
The middle two need a word of explanation. A command here is a program you give the agent next to its built-in tools. Instead of "create the folder, copy the files, write the state", the agent runs one command that does all three and refuses to start if a precondition is false. The rule is inside the command. A hook is the other way round: the agent does what it likes, and the hook looks at each call before it runs.
Where does a rule go
Start every rule at the bottom, in words. A sentence is cheap to write and cheap to change, and for most rules the model will follow it. Move it up when one of three things is true.
- It keeps being broken. You have seen it happen more than once, and a better sentence did not fix it. Rewording is the wrong answer to a rule that is ignored for being far away; code is the right one.
- The harm cannot be undone. A deleted branch, a pushed commit, an overwritten file nobody backed up. One breach is one too many, so do not wait for the second.
- Other parts rely on it. If a later step trusts that an earlier rule held (a "check passed" record, an approval), then a broken rule breaks the later step too.
Then pick the lowest level that is enough. If a command can hold the rule, do not build a hook. A hook has to be written, tested, and kept alive across platform changes (Enforcement design). Use the hook when the agent can get to the thing in many ways and you cannot route them all through your command.
Stop with code, teach with text
When you move a rule into code, do not delete the sentence. Keep one. They do different jobs.
- The code stops. It does not depend on what the model remembers.
- The text teaches. It tells the agent why the rule exists and what to do instead, before it runs into the wall.
Without the text, the agent runs into the refusal again and again, and tries other ways round it. Without the code, the text is a request again. The refusal message is the bridge: it is code that carries a sentence. A good one says why it was refused and what to do next (Asking is not a limit is about writing these).
The other side of the same split: do not put into code what only a judgment can decide. "Is this the right requirement?" and "is this change good?" have no pattern to match. Those stay as words, and you check them from outside, with an independent reviewer (Use subagents sparingly).
An example of moving up
Say your rule is: "generated files are never edited by hand". The steps look like this.
- Words. One line in the instructions, with the reason: they are rebuilt, and hand edits are lost.
- It happens twice. You add a check at the level of the hook: a call to the edit tool on those paths is refused, with the reason and the command that regenerates them.
- A new gap. The agent now uses the terminal to write the file. You add the common spellings of that to the hook. You also know it will not catch a script written first and run later, so you keep the one sentence of words, and a test that finds changed generated files after the fact.
This is a made-up case to show the steps. At each step a level was added and none was removed.
Test your own setup
A three-minute exercise. Write down three rules you give your agent today. For each, answer: is it words, a command, a hook, or a check afterwards? Would one breach be undoable? Has it been broken twice? Any rule that is "no" to the first question, "cannot undo" to the second, and "yes" to the third is the one to move up first.
原理
四個牢固程度
一條規則可以守在四個程度。每一個保證的東西不同,每一個也都有限制。
| 程度 | 它是什麼 | 它保證什麼 | 它的限制 |
|---|---|---|---|
| 文字 | 規則寫在指令檔、skill 或 agent 的正文裡 | agent 知道這條規則和它存在的理由 | 它可能不遵守 |
| 自己檢查的指令 | agent 透過你的一個小程式來做這個操作,程式在動手之前先檢查條件 | 在任何平台上,每次都是同樣的結果 | 它只守經過它的東西。agent 如果手動編輯檔案,這個指令根本不會被呼叫 |
| 會拒絕的 hook | 平台在工具呼叫之前執行的程式碼,可以說不 | 在我試過的模式裡,呼叫會被擋下,即使沒有人看著 | 它依賴平台,而且它看到的是呼叫,不是效果(Hooks:每次呼叫都會經過的執行點) |
| 事後發現 | 健康檢查(一個測試設定是否健全的指令)、跑一次測試、讀紀錄 | 違反可以被發現、被計數 | 它什麼也預防不了。它是偵測,不是預防 |
最後一個程度的種類不同。它不守規則;它告訴你其他的有沒有守住。每一個程度你都需要它,因為你看不到它被違反的規則,是你在猜的規則。
中間兩個需要解釋一下。這裡的指令,是你在 agent 內建工具旁邊給它的一個程式。agent 不再「建資料夾、複製檔案、寫狀態」,而是執行一個指令,三件事一次做完,如果前提條件不成立,就拒絕開始。規則在指令裡面。hook 則相反:agent 想做什麼就做什麼,hook 在每次呼叫執行前先看一眼。
規則該放哪裡
每條規則都從最底層開始,用文字。一句話寫起來便宜、改起來也便宜,而且對大多數規則,模型會照做。三件事有一件成立時,再往上搬。
- 它一直被違反。你看到它發生不止一次,而更好的句子沒有解決。對一條因為離得太遠而被無視的規則,重新措辭是錯的答案;程式碼才是對的。
- 傷害無法挽回。一個被刪掉的分支、一個推上去的 commit、一個沒人備份就被覆寫的檔案。違反一次就太多了,所以不要等第二次。
- 其他部分依賴它。如果後面的步驟相信前面的規則守住了(一筆「檢查通過」的紀錄、一個批准),那麼規則一破,後面的步驟也跟著破。
然後選夠用的最低程度。如果指令能守住這條規則,就不要做 hook。hook 要寫、要測、要在平台變動中一直維持(把執行層當軟體來設計)。agent 有很多方式可以接觸到那樣東西、而你無法把它們全部導到你的指令時,才用 hook。
用程式碼擋,用文字教
把一條規則搬進程式碼時,不要刪掉那句話。留一句。它們做不同的事。
- 程式碼負責擋。它不依賴模型記得什麼。
- 文字負責教。它在 agent 撞上牆之前,告訴它這條規則為什麼存在、該改做什麼。
沒有文字,agent 一次又一次撞上拒絕,並試別的方式繞過去。沒有程式碼,文字又變回請求。拒絕的訊息是橋樑:它是帶著一句話的程式碼。好的訊息說明為什麼被拒絕、接下來做什麼(怎麼寫這些,見詢問不是限制)。
同一種拆分的另一面:只有判斷才能決定的事,不要放進程式碼。「這是對的需求嗎?」「這個改動好不好?」沒有可以比對的模式。這些仍然是文字,你從外面去檢查,用獨立的 reviewer(慎用子 agent)。
一個往上搬的例子
假設你的規則是:「產生出來的檔案絕不手動編輯」。步驟看起來是這樣。
- 文字。指令裡一行,附上理由:它們會被重新建置,手動編輯會丟掉。
- 它發生了兩次。你加一個 hook 層級的檢查:對那些路徑呼叫編輯工具,會被拒絕,附上理由和重新產生它們的指令。
- 出現新的缺口。agent 現在用終端機去寫那個檔案。你把這個做法常見的寫法加進 hook。你也知道它抓不到先寫好一支腳本、之後再執行的情況,所以你留著那一句文字,再加一個測試,事後找出被改過的產生檔案。
這是一個編出來顯示步驟的案例。每一步都加上了一個程度,沒有拿掉任何一個。
測一測你自己的設定
一個三分鐘的練習。寫下你今天給 agent 的三條規則。每一條回答:它是文字、指令、hook,還是事後檢查?違反一次能挽回嗎?它被違反過兩次嗎?第一個問題答「不是」、第二個答「不能挽回」、第三個答「是」的規則,就是最先要往上搬的。
原理
四级牢固程度
一条规则可以在四个级别上守着。每一级承诺的东西不同,每一级也有它的限度。
| 级别 | 它是什么 | 它承诺什么 | 它的限度 |
|---|---|---|---|
| 文字 | 规则写在指令文件、skill,或者 agent 的正文里 | agent 知道这条规则,也知道它为什么存在 | 它可能不遵守 |
| 自带检查的命令 | agent 通过你写的一个小程序来做这个操作,程序在动手之前先检查条件 | 在任何平台上,每次结果都一样 | 它只守经过它的东西。如果 agent 手动去改文件,这个命令根本不会被调用 |
| 会拒绝的 hook | 平台在工具调用之前运行的代码,可以说不 | 调用会被拦下,在我试过的模式里,即使没人盯着也是如此 | 它依赖平台,而且它看到的是调用,不是效果(Hook:每次调用都会经过的执行点) |
| 事后发现 | 健康检查(一条用来测试配置是否健全的命令)、一次测试运行、翻一遍日志 | 违规可以被发现并计数 | 它什么也阻止不了。这是检测,不是预防 |
最后一级在性质上不同。它不守规则;它告诉你其他几级守住了没有。每一级都需要它,因为一条你看不到有没有被违反的规则,是一条你只能猜的规则。
中间两级要多解释一句。这里的命令,是你在 agent 的内置工具之外给它的一个程序。不是“创建文件夹、复制文件、写入状态”,而是 agent 运行一条命令,把这三件事都做了,并且在某个前提不成立时拒绝开始。规则就在命令里面。hook 则相反:agent 想做什么就做什么,hook 在每次调用运行之前先看一眼。
规则该放在哪
每条规则都从最底下的文字开始。写一句话成本低,改起来也容易,对大多数规则来说,模型会遵守。下面三种情况有一种成立时,再往上挪。
- 老被违反。 你看到它发生过不止一次,换一句更好的话也没有解决。规则因为离得太远而被无视,改措辞是错的答案;代码才是对的答案。
- 伤害无法挽回。 删掉的分支、推送出去的提交、没人备份过的被覆盖的文件。一次违反就太多了,所以别等第二次。
- 别的部分依赖它。 如果后面的某一步信任前面的规则守住了(“检查通过”的记录、一次审批),那么规则一破,后面的那一步也跟着破。
然后选刚好够用的最低一级。如果一条命令就能守住规则,就别造 hook。hook 要写、要测,还要在平台变化时让它继续有效(把执行层当软件来设计)。agent 能通过很多条路碰到那个东西、你又没法把它们全都引到你的命令上时,才用 hook。
用代码拦,用文字教
把一条规则挪进代码时,别把那句话删了。留一句。它们做的是不同的事。
- 代码负责拦。 它不依赖模型记得什么。
- 文字负责教。 它在 agent 撞上墙之前,就告诉它这条规则为什么存在,以及该怎么做。
没有文字,agent 就会一次又一次撞上拒绝,并试别的办法绕过去。没有代码,文字又变回了请求。拒绝的消息是两者之间的桥:它是带着一句话的代码。好的拒绝消息会说明为什么被拒绝、接下来该做什么(询问不是限制讲的就是怎么写这类消息)。
同一个划分的另一面:只能靠判断来决定的事,不要放进代码。“这是对的需求吗?”“这个改动好不好?”没有可以匹配的模式。这些仍然用文字,从外面来检查,用独立的 reviewer(慎用子 agent)。
往上挪的一个例子
假设你的规则是:“生成的文件绝不手动编辑”。步骤大致如下。
- 文字。 指令里写一行,附上理由:它们会被重新生成,手动编辑的内容会丢。
- 发生了两次。 你在 hook 这一级加一条检查:对这些路径调用编辑工具,会被拒绝,并附上理由和重新生成它们的命令。
- 又出现一个缺口。 agent 现在改用终端来写这个文件。你把这种做法的常见写法加到 hook 里。你也知道它拦不住先写好一个脚本、之后再运行的做法,所以保留那一句文字,再加一个测试,事后找出被改动过的生成文件。
这是一个编出来的例子,用来演示这些步骤。每一步都是加了一级,没有哪一级被去掉。
检验你自己的配置
一个三分钟的练习。 写下你今天给 agent 的三条规则。对每一条回答:它是文字、命令、hook,还是事后检查?违反一次,能挽回吗?它被违反过两次吗?对第一个问题回答“不是”、第二个回答“无法挽回”、第三个回答“是”的规则,就是最先要往上挪的。
Costs and traps
Code has a price. It has to be written, tested, and updated when the platform changes tool names or events. The more rules you move into code, the more of that you carry.
Code stops the wrong things too. A pattern that is too wide blocks real work. The agent cannot argue with a refusal, so a false refusal is a stuck task. Every code rule needs a reason in the message, and a way to see which rule fired.
A hook only sees calls. A rule in a hook holds for the spellings it knows. It does not hold against an agent set on getting around it. For things that must never be touched, see Least privilege.
Code can fail too. A hook is software. If it breaks, the platform may refuse every call, or let every call through, depending on how it broke (Enforcement design).
A rule that only the agent keeps is not a record. Do not let the agent be the only witness that it followed a rule. For anything you will rely on later, have code write the record (Counted checks).
I did not count how often each level fails. The ladder comes from experience with one harness and from the docs. I do not have numbers for how often words alone are broken, and I would not trust anyone who gave you one without saying what model and what task.
代價和陷阱
程式碼有價錢。它要寫、要測,平台改工具名稱或事件時要更新。你搬進程式碼的規則越多,要背的就越多。
程式碼也會擋錯東西。太寬的模式會擋掉真正的工作。agent 沒辦法跟拒絕爭辯,所以一次誤拒絕,就是一個卡住的任務。每條程式碼規則,訊息裡都需要一個理由,還要有辦法看出是哪條規則觸發了。
hook 只看得到呼叫。hook 裡的規則,對它認得的寫法有效。對一個一心想繞過它的 agent,它守不住。對於絕不能碰的東西,見有些東西根本不給。
程式碼也會失敗。hook 是軟體。它壞了,平台可能拒絕每一次呼叫,也可能放行每一次呼叫,看它是怎麼壞的(把執行層當軟體來設計)。
只有 agent 自己守著的規則,不算紀錄。別讓 agent 成為它遵守了規則的唯一見證。凡是之後你要依賴的,都讓程式碼來寫紀錄(讓「通過」可信)。
我沒有數每個程度多常失敗。這個階梯來自對一個 harness 的經驗和文件。光靠文字多常被違反,我沒有數字,而任何人如果給你一個數字、卻不說是什麼模型和什麼任務,我不會相信。
代价和坑
代码是有成本的。 平台改了工具名或事件,代码就得更新,还要写、要测。挪进代码的规则越多,你要扛的就越多。
代码也会拦错东西。 太宽的模式会挡住正常的工作。agent 没法跟拒绝争辩,所以一次误拒就是一个卡住的任务。每条代码规则的消息里都要有理由,还要有办法看到是哪条规则触发的。
hook 只看得到调用。 hook 里的规则,对它认识的那些写法有效。它挡不住一个铁了心要绕过它的 agent。对于绝不能碰的东西,见有些东西根本不给。
代码也会出故障。 hook 是软件。它坏了,平台可能拒绝每一次调用,也可能放过每一次调用,取决于它是怎么坏的(把执行层当软件来设计)。
只有 agent 自己守的规则,不算记录。 不要让 agent 成为它守了规则的唯一见证人。凡是你以后要依赖的东西,都让代码来写记录(让“通过”可信)。
我没数过每一级多久失败一次。 这个梯子来自我对一个 harness 的经验和文档。光靠文字,多久会被违反一次,我没有数字,而且如果有人给你一个数字却不说是什么模型、什么任务,我也不会信。
What the industry says Industry practice
The platform docs agree on the split, though they put it in their own words. The VS Code hooks page says hooks and instructions are not substitutes for enforced permissions, sandboxing or enterprise controls (hooks). Read that both ways: instructions are the weakest level, and a hook is not the strongest level either. The next chapters go up that ladder.
業界怎麼說 業界做法
平台文件在這種拆分上是一致的,只是各有各的說法。VS Code 的 hooks 頁面說,hook 和指令不能替代強制執行的權限、沙箱或企業控制(hooks)。兩個方向都要這樣讀:指令是最弱的程度,而 hook 也不是最強的程度。接下來的幾章,就是沿著這個階梯往上走。
业界怎么说 业界做法
平台文档在这个划分上是一致的,只是各用各的话。VS Code 的 hooks 页面说,hook 和指令不能替代强制执行的权限、沙箱或企业级管控(hooks)。这句话要两头读:指令是最弱的一级,而 hook 也不是最强的一级。接下来的几章就沿着这个梯子往上走。
When to delete it Industry practice
Two things shrink the ladder over time.
- The model gets better at following words. Some rules you moved to code because the model ignored them may now be followed. The way to find out is to run the same tasks with the code rule switched off and count (When the model is upgraded). Choose tasks that used to trip the rule, run each a few times, and count the breaches. A handful of runs shows only a large change. I have not run this. Switch it off only where a breach can be undone.
- The platform takes over. When the platform itself can refuse a path or a command in every mode, your own hook for it can go. Keep the sentence of text.
What does not go away is the question: which rule is held how firmly, and why.
什麼時候可以刪掉 業界做法
有兩件事會讓這個階梯隨時間縮短。
- 模型越來越會遵守文字。有些你因為模型無視而搬進程式碼的規則,現在可能已經被遵守了。找出來的辦法,是把程式碼規則關掉,跑同樣的任務並計數(模型升級了,就要刪)。選過去曾經觸發這條規則的任務,每個跑幾次,數違反的次數。跑幾次只能看出很大的變化。我沒有跑過。只在違反可以挽回的地方才關掉。
- 平台接手。當平台自己能在每種模式下拒絕一個路徑或指令時,你自己為它做的 hook 就可以去掉。留著那一句文字。
不會消失的是這個問題:哪條規則守得多牢,為什麼。
什么时候可以删掉 业界做法
有两件事会让这个梯子随时间缩短。
- 模型更善于遵守文字。 你当初因为模型无视而挪进代码的有些规则,现在可能已经被遵守了。要知道,就把代码规则关掉,跑同样的任务并计数(模型升级了,就要删)。挑过去会触发这条规则的任务,每个跑几次,数一数违反了几次。跑几次只能看出很大的变化。我还没有跑过。只在违反了可以挽回的地方才关。
- 平台接管了。 平台自己能在每种模式下拒绝某个路径或命令时,你自己为它写的 hook 就可以去掉。那一句文字保留。
不会消失的,是这个问题:哪条规则守得多牢,为什么。
Try it on your own setup
No harness needed. Open your agent in your own repository and paste:
Read every rule this project gives the agent: instruction files, skills, agent files, hook and permission settings. For each rule, say which level holds it: words only, a command that checks itself, a hook or permission setting that refuses, or a check run afterwards. Then list the rules that are words only but would cause harm that cannot be undone, or that other steps rely on. Output a table with the rule, its level, and your recommendation to keep or move up. Do not change any files.在你自己的環境試試
不用裝 harness。在你自己的倉庫裡打開 agent,貼上:
讀這個專案給 agent 的每一條規則:指令檔、skill、agent 檔、hook 和權限設定。每一條規則,說明它由哪個程度守著:只有文字、自己檢查的指令、會拒絕的 hook 或權限設定,還是事後執行的檢查。然後列出只有文字、但違反會造成無法挽回的傷害、或其他步驟依賴它的規則。輸出一張表,包含規則、它的程度,以及你建議保留還是往上搬。不要改任何檔案。在你自己的环境里试试
不用装 harness。在你自己的仓库里打开 agent,粘贴:
读这个项目给 agent 的每条规则:指令文件、skill、agent 文件、hook 和权限设置。对每条规则,说明由哪一级守着:只有文字、自带检查的命令、会拒绝的 hook 或权限设置,还是事后运行的检查。然后列出那些只有文字、但一旦出错会造成无法挽回的伤害、或者别的步骤依赖它的规则。输出一张表:规则、它所在的级别、你建议保持不变还是往上挪。不要修改任何文件。Go deeper
- VS Code docs: Hooks
- In this book: Hooks, Instructions and skills, Asking is not a limit
延伸閱讀
- VS Code 文件:Hooks
- 本書:Hooks:每次呼叫都會經過的執行點、指令與 skill:只載入需要的、詢問不是限制
延伸阅读
- VS Code 文档:Hooks
- 本书:Hook:每次调用都会经过的执行点、指令与 skill:只加载需要的、询问不是限制
You can stop here: that is the whole idea. The next part shows where it runs, so you can look inside.讀到這裡就夠了,這就是整個想法。下一部分告訴你它在哪裡運行,可以進去看看。读到这里就够了,核心思路就是这些。下一部分告诉你它在哪里跑,可以进去看看。
In my practice (Copilot Harness)實作实战
Copilot Harness is my open-source harness for VS Code Copilot.
Repository: https://github.com/Smars-Bin-Hu/copilot-agentic-harness
Get started: clone it, open it in VS Code, and type /harness-rookie-get-me-ready in Copilot Chat. You need Python 3.9 or later and git.
Copilot Harness 是我開源的 VS Code Copilot harness。
倉庫: https://github.com/Smars-Bin-Hu/copilot-agentic-harness
開始:clone 下來,用 VS Code 打開,在 Copilot Chat 裡輸入 /harness-rookie-get-me-ready。需要 Python 3.9 以上和 git。
Copilot Harness 是我开源的 VS Code Copilot harness。
仓库: https://github.com/Smars-Bin-Hu/copilot-agentic-harness
上手:把仓库 clone 下来,用 VS Code 打开,在 Copilot Chat 里输入 /harness-rookie-get-me-ready。需要 Python 3.9 及以上版本和 git。
Explore it in the harness
The four levels all exist in Copilot Harness: rules in text, commands that check their own conditions, a hook that refuses, and checks that look back. The harness can show you which rule sits at which level, and why, with the real files. After the setup above, type:
/harness-rookie-wondering I have read the chapter "A rule in a prompt is a request". Teach me how this harness decides where each rule lives: the ladder of enforcement (topic 14) and the design choices behind it (topic 15). Pick three rules, show me which level each one is at and what would make you move it, and open the real files with me.It teaches one small piece at a time, stops to ask if you are following, and opens the files with you.
在 harness 裡探索
四個程度在 Copilot Harness 裡都有:文字寫的規則、自己檢查條件的指令、會拒絕的 hook,和往回看的檢查。harness 可以用真實的檔案讓你看到哪條規則在哪個程度、為什麼。照上面的說明準備好之後,輸入:
/harness-rookie-wondering 我讀完了「提示裡的規則只是請求」這一章。請教我這個 harness 怎麼決定每條規則放在哪裡:執行的階梯(主題 14)和背後的設計選擇(主題 15)。挑三條規則,告訴我每一條在哪個程度、什麼情況會讓你把它往上搬,並帶我打開真實的檔案。它一次教一小塊,停下來確認你跟得上,然後和你一起打開檔案。
在 harness 里探索
这四级在 Copilot Harness 里都有:写成文字的规则、自己检查条件的命令、会拒绝的 hook,以及往回看的检查。harness 能用真实的文件告诉你哪条规则在哪一级,为什么。按上面的说明准备好之后,输入:
/harness-rookie-wondering 我读完了“提示里的规则只是请求”这一章。请教我这个 harness 是怎么决定每条规则放在哪里的:强制执行的梯子(主题 14)和它背后的设计选择(主题 15)。挑三条规则,告诉我每条在哪一级,什么情况会让你把它往上挪,并带我打开真实的文件。它一次只教一小块,停下来确认你跟上了,再和你一起打开文件。