這一課會完成什麼
- 將 repository 要求分成 prose guidance、generated facts 與可機械檢查 invariant
- 實作 import direction、generated file、protected path、secret 與 diff budget 規則
- 讓 local、CI 與 release gate 使用相同 rule ID 與結果
- 用 owner、reason、scope、expiry 與 issue 管理暫時 exception
開始前先準備
- • 模組 01 到 05 的 map、contract、environment、ledger 與 typed feedback
- • 一份通過的 Release Desk baseline,可新增 lint、dependency 與 diff-policy checks
先把定義說清楚
機械式規則
Mechanical enforcement 是由 repository 執行的 deterministic policy。它保護一項能可靠檢查的 invariant,同樣輸入就得到同樣決定,失敗會指出 rule ID、邊界與安全修復,必要例外也有正式且會過期的流程。Prose 繼續承載意圖與需要 judgment 的內容;generated map 呈現當前 facts;規則只守住一再造成風險或 reviewer 重工的少數條件。
『Domain logic 不要放 route handler』可以提醒人和 agent,卻擋不住 invalid dependency。自治修改量增加後,reviewer 會反覆抓相同 import、手改 generated client、secret 進 log、功能外 schema 變更。快速規則能把回饋移到檔案剛改動時,agent 也拿得到具體 repair target。
規則太多也會傷害 harness。Brittle checker 擋合法修改,exception 永久留著,preflight 太慢便鼓勵 bypass。每一條規則都要能說明保護什麼、訊號是否可靠、誰維護、如何修、何時刪,不能把 policy 數量當成熟度。
現場情境
一個快速功能穿過三條看不見的邊界
Dependency graph、secret canary、protected files 與 exception 都是合成 fixture。
- 負責人
- 你是準備放長 unattended run 的技術主管。
- 要做的決策
- 哪些邊界適合快速規則,migration 如何通過又不留下永久 bypass?
- 目前狀態
- Candidate 從 UI route import database、手改 generated client,並把 fixture token 寫進 screenshot log。功能可操作,三個問題都由 reviewer 手動發現。
- 預期成果
- Rule pack 抓到全部 seeded violations,回 stable repair code,只接受一份 scoped exception,local 與 CI receipt 一致。
限制條件
- • Rules 不得使用 production credential、network 或 model judge
- • 課程 local preflight 目標低於十二秒
- • 合法 migration 只可拿一份七天且限定單一路徑的 exception
實作範例
三條規則取代三次重複 review
證據類型: 具名模擬情境歷史 fixture diff 一直出現 route-to-database import、generated API file 手改與 canary 進 test artifact。三項都有 prose,但每次仍要 reviewer 重查。
Harness 增加 DEP-001 檢查 package direction、GEN-002 檢查 generated provenance、SEC-004 掃 diff、log、receipt 與 screenshot。Migration exception 只 match 一個 manifest path、一張 issue、一位 owner 與七天期限。
Seeded bad patch 在本機快速回三個 code,修正後通過。CI 使用相同 rule version 與 fixture,結果一致。Exception 到期時自動失敗,直到恢復 generation workflow 並移除紀錄。
主張限制
Static 與 fixture checks 無法證明整體架構安全或適切;runtime authorization、端到端 eval、threat review 與 release owner 仍不可省略。
做法
照著做,每一步都有檢查點
現場情境
哪些邊界適合快速規則,migration 如何通過又不留下永久 bypass?
- 01選可執行 invariant
- 02實作快速 check 與 stable code
- 03加入窄 exception
驗收條件
Coding session 會立即收到五條重要 boundary 的具體回饋,無法放寬 migration exception,push 前後看到同一判定。
- 01
選可執行 invariant
每個 candidate 寫 bad state、deterministic input、expected output、false-positive risk、owner 與 repair。Style 或 product judgment 若訊號不可靠,就保留給 guidance 與 human review。
檢查點 · 五條 selected rules 都有可靠訊號與 owner;被拒項目也留下不機械化的理由。
- 02
實作快速 check 與 stable code
建立 dependency、generated、protected-path、secret 與 diff-budget checker。從 verified repository root 解析路徑、限制輸出、連 evidence,失敗要回 rule ID 與精確 repair。
檢查點 · 每個 seeded violation 只觸發預期 rule;clean fixture 通過;checker 不讀 task root 之外。
- 03
加入窄 exception
建立 migration exception,驗 rule ID、exact paths、owner、issue、reason、createdAt 與 expiry。測 missing field、path widening、wrong rule 與 expired date。
檢查點 · 合法 migration 只在七天 scope 內通過;其他 generated file 與 malformed exception 都被擋。
- 04
證明 local 與 CI parity
以同一份 manifest 與 corpus 跑 local preflight 與 CI simulator,比 rule version、commit、outcome、runtime 與 evidence hash。出現環境差異要修 implementation,不能接受 known mismatch。
檢查點 · Pass、fail、exception fixtures 在兩邊一致,local pack 也維持時間目標。
實務脈絡
展示版之後
建立 rule ladder
從 baseline 與 code review evidence 開始。需要設計判斷的 expectation 留在 instructions 並附正反例;package ownership、route inventory、schema status 與 public export 交給 generator;只有 reviewer 穩定拒絕、checker 低歧義的狀態才升成 rule。
每條規則記 id、目的、owner、scope、severity、local command、CI stage、repair hint 與 exception policy。Local 與 CI 顯示相同 id;兩邊 implementation 不一致會造成 local 假信心與 push 後 surprise。
把 exception 當成會到期的工作
Migration 偶爾需要暫時跨 dependency 或修改 protected manifest。Exception 要指明 exact rule、exact paths、owner、reason、issue、createdAt 與 expiresAt。Checker 驗所有欄位,expired 或 path widening 一律拒絕;blanket disable 不在 task contract。
Rule health 也要量:violation、repair success、false positive、exception age、runtime、CI drift 與 bypass attempt。失去真實邊界的 rule 應刪除。少而可信的規則,比一長串人人忽略的紅字更有用。
交付補強
Diff budget 不應只限制檔案數。先由 contract 列 allowed roots、protected files、generated surfaces、migration policy 與預期 artifact,再由 checker 比新增、刪除、rename、binary、lockfile 與 dependency change。十個小檔案可能完全合理,一個 package lock 大改卻可能擴張 supply-chain surface。超出 budget 時回需要 review 與差異摘要,不讓 agent 為了過門檻把大改拆成多次 commit。
Secret rule 要掃的不只有 source。Fixture canary 可能進 terminal log、JSON receipt、browser screenshot metadata、trace、coverage output、patch description 與 generated docs。每個 surface 都設 retained fail case,並確認 checker 自己不把命中的完整值印到報告。真正 incident 還要有 revoke、rotate、history review 與通知流程;課程 canary 通過只能證明已列 surface 沒有洩漏,不能宣稱整體沒有秘密風險。
Architecture rule 需要跟 ownership map 對齊。DEP-001 讀 package graph 與 public export,而不是靠字串搜尋 import path。允許 dependency 變更時先更新 architecture decision、owner 與 retained fixtures,再改 rule manifest。若 agent 直接編輯 generated graph,GEN-002 應先擋;正確流程是改 authoritative config 或 source,再執行 generator。這能維持 rule、map 與實際 code 同一套真相。
Exception review 要看使用紀錄。某條 exception 在七天內被三個無關 task match,即使尚未到期也可能 scope 過寬;health report 應列 matched commits、paths 與 actors。Owner 可選縮小、提早撤銷或正式修改 invariant。期限到了不能自動續期,更不能因 CI 壓力改成 warning;新 exception 必須重新說明原因與風險,並重跑 affected critical fixtures。
保護路徑規則要區分禁止修改與需額外核准。Fixture 的憑證設定、部署清單與資料刪除程序可以完全禁止 agent 觸碰;核心狀態機或 migration registry 可能允許修改,但必須有對應合約、owner review 與完整回歸。Checker 回傳 policy class、需要的證據與申請位置,不建議 agent 移動檔案或改名來避開 glob。Rename、symlink 與 generated output 也要解析到實際目標,避免表面路徑不同便穿過保護。
規則失敗的修復文字本身要受測。若依賴方向錯誤,提示應指向 public service 或 domain boundary,不要只說禁止 import;generated file 被改,提示要指出 authoritative source 與 generation command;secret 命中則只顯示檔案、類型與遮蔽片段,不能重印完整值。Fresh agent 依提示修復後,除了原規則通過,也要跑相關功能,避免為了消掉紅字而刪除必要行為。
Release 前抽查規則是否真的阻擋實際執行路徑。某些檢查只掃 Git diff,卻漏掉 runtime 產生的 log 或 screenshot;另一些只在 CI 跑,agent 本機無法取得及時回饋。將 invariant 對到產生、提交、建置、執行與歸檔各階段,選最早且可靠的位置攔截,較晚階段再做整體防線。多層檢查可以共用 rule ID,但各自證明的表面要在 receipt 寫清楚。
Policy change 也要像功能 change 一樣經過 before/after fixture。新增規則先在歷史乾淨變更上跑,估 false positive 與修復時間;放寬規則則重播曾被它擋下的違規 patch,確認仍有其他 control 或已由正式架構決策接受。Owner 簽的是具體差異與殘餘風險,不是一個規則檔案已被修改的事實。若新規則讓 local preflight 超過團隊可接受時間,拆成快速 blocking 與較慢 advisory/CI 層,不能直接鼓勵跳過整包檢查。規則發佈後觀察一個週期,再決定保留、調整或撤回。
每次規則發佈都附一個最小壞 patch 與一個合法邊界 patch。前者證明它真的攔住風險,後者防止維護者只測失敗路徑,卻讓正常工作全被誤傷。
動手實作
建立 Release Desk mechanical rule pack
實作 dependency、generated files、protected paths、secret canary 與 task diff budget 五條規則,seed failure、加入一份到期 exception,再比 local/CI。
準備項目
- • 從實際 review finding 選 objective signal 與 owner,不為了湊數造規則
- • 保存 current dependency graph、generated manifest、protected paths、canary 與 runtime baseline
本課產出
Versioned manifest、五個 checks、pass/fail fixtures、一份 expiring exception、repair notes 與 local/CI parity receipts。
起始模板: Mechanical rule manifest
YAMLrules:
- id: DEP-001
owner: platform
severity: blocking
scope: ["src/app/**", "src/domain/**", "src/data/**"]
check: "node scripts/check-dependencies.mjs"
exceptionRequired: ["owner", "reason", "issue", "expiresAt", "paths"]可下載的實作檔
Mechanical rule manifest
mechanical-rules.yml · YAML
An editable course fixture for the main lab. Save it inside the Release Desk repository before running the acceptance command.
Run receipt template
he-06-receipt.json · JSON
A compact evidence record for the check, environment, result, and limits that another reviewer must be able to inspect.
驗收指令
npm run harness:rules -- --manifest .harness/mechanical-rules.yml --parity預期 receipt
PASS he-06 mechanical-enforcement
rules=5 seededViolationsCaught=5
localCiMismatches=0 invalidExceptionsAccepted=0預期結果
Coding session 會立即收到五條重要 boundary 的具體回饋,無法放寬 migration exception,push 前後看到同一判定。
留給下一課
Rule pack 會成為 verification ladder 第一層。Rule result、false positive 與 exception age 也要進 observability、parallel decision 與 capstone Harness Card。
驗收條件
- 01五個 seeded violations 皆回預期 rule ID、evidence、owner 與 repair
- 02Clean fixtures 通過且 local pack 低於課程 runtime target
- 03Exception validator 拒 missing owner、issue、expired、widened path 與 wrong rule
- 04Local 與 CI outcome、rule version、commit 與 evidence hash 相符
常見故障
故障診間
F1Agent 經常加 ignore comment 才能做合法修改。
- 先檢查
- 檢查 false-positive fixture、bypass、scope、parser assumption 與 owner response。
- 可能原因
- Rule 守的是 broad proxy,不是真正 invariant,或沒有可維護 exception。
- 修復方式
- 透過 owned change 暫停該 rule、縮小 signal、補 valid fixture,清除未授權 bypass。
- 下次怎麼避免
- 逐 rule 追 false positive 與 repair time,policy 變更必須有 owner 和 test。
F2Local 通過,CI 報不同 dependency violation。
- 先檢查
- 比較 package、manifest hash、working directory、generated state、runtime 與 ignored files。
- 可能原因
- 兩邊用不同 implementation 或 repository root 解析方式。
- 修復方式
- 統一 versioned checker entry 與 explicit root,把 mismatch 加進 parity fixture。
- 下次怎麼避免
- 兩份 receipt 都發布 rule version 與 input hash。
F3Temporary exception 幾個月後仍 active。
- 先檢查
- 列 owner、created、expires、matched paths、usage 與 linked issue。
- 可能原因
- Exception 只是 comment 或 blanket flag,沒有 enforced expiry。
- 修復方式
- 使紀錄到期,恢復 invariant 或開 reviewed rule change。
- 下次怎麼避免
- Expired record 自動 fail,harness health 顯示 exception age。
展示版之後
正式上線前的邊界
- 01每條 rule 有 invariant、signal、scope、severity、owner 與 repair path
- 02路徑與 environment identity 安全解析,不使用 broad root、空變數或 unowned process
- 03Local、CI、release 使用相同 versioned checker 與 receipt
- 04Exception 需要 exact rule/path、owner、reason、issue、created 與 enforced expiry
- 05Fixtures 包含 valid change、seeded violation、malformed exception、drift 與 redaction
- 06Rule health 追 runtime、violation、false positive、repair、bypass 與 exception age
證據類型
資料來源與主張限制
資料來源只支撐本課標示的主張,不代表換一個系統也會得到相同結果。
- [1]Harness engineering:在 agent-first 開發環境中運用 Codex知識留在 repository · 讓系統對 agent 可讀 · 機械式規則 · 處理 repository entropy
OpenAI · 公開案例 · 2026-08-26
- [2]Harness Engineering 學習指南repository 是工作紀錄 · 機械式規則 · agent 可讀性 · 持續整理
deusyu · 公開案例 · 2026-08-26
- [3]Learn Harness Engineering專案式學習順序 · 五個 harness 子系統 · 迴圈工程 · 工作圖工程
Walking Labs · 公開案例 · 2026-08-26
- [4]Harness Engineering Guide執行環境邊界 · 工具系統 · sandbox · 復原模式
Nexu · 公開案例 · 2026-08-26
- [5]長時間執行 agent 的有效 harnessinitializer 模式 · feature ledger · session 交接 · 端到端驗證
Anthropic · 已發表研究 · 2026-08-26
延伸的 Tenten 資源