Communitygithub.com

yli769227-jpg/agent-discipline

8 個經過實戰考驗的紀律技能,能阻止你的 AI 編碼代理信心滿滿地寫出有問題的程式碼——每個技能都附有可驗證的完成判據。中英雙語。

agent-discipline 是什麼?

Log First (日誌優先) 是一項軟體開發紀律,要求所有新程式碼在關鍵路徑上加入結構化日誌,包括連接建立、狀態變更、錯誤發生、以及請求/回應等節點。這項紀律通過統一的日誌格式和模組前綴,讓開發者能夠在生產環境中快速定位問題,避免在錯誤發生時盲目除錯。它支援任何程式語言和框架,無論是手動編寫還是 AI 代理生成的程式碼都適用。該紀律明確了觸發時機(如撰寫新模組或除錯無日誌程式碼時),並提供了可驗證的完成判據:你可以通過 `grep` 命令檢查每個關鍵路徑是否都有帶上下文的日誌。對於 AI 代理使用者,這項紀律特別重要——在指派子任務時必須明確要求加入關鍵路徑日誌。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add yli769227-jpg/agent-discipline

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

Log First / 日誌優先

Writing buggy code is normal. Locating the bug is the hard part — logs are how you win that part. 寫程式碼犯錯是正常的,定位問題才是真正困難的——日誌就是你贏下這一關的方式。

The discipline / 紀律

  1. All new code carries key-path logs: connection established, state change, error raised, request/response. 所有新程式碼帶關鍵路徑日誌:連接建立、狀態變化、錯誤發生、請求/回應。
  2. Keep log format consistent and prefix each line with a module tag so it greps cleanly. 日誌格式統一,每行帶模組前綴,便於 grep。
  3. Error logs must carry context: which operation, which arguments, which error. 錯誤日誌必須帶上下文:什麼操作、什麼參數、什麼錯誤。
  4. This applies to agent-written code too — a sub-task to write code must require key-path logging. agent 寫的程式碼同樣適用——派寫程式碼的子任務時要寫明「加關鍵路徑日誌」。(派子任務的完整必含項見 agent-team 的「派子任務必含清單」)

When this triggers / 觸發時機

  • About to write a new module / interface / external call / async task.
  • Debugging a stretch of code that has no logs (add them first).
  • Before handing an agent a code-writing sub-task (require "add key-path logs").

Done criterion (verifiable) / 完成判據(可驗證)

✅ A grep over the new code (e.g. grep -nE 'log\.(info|warn|error)' <file>) shows a line at each key path — connect, state change, error, request/response — each module-prefixed and carrying context. ⚠️ Some paths logged, some missing — name the gaps. ❌ The new code is silent. If it fails in prod, you'll be blind. Add logs before shipping.

Worked examples / 實戰反例

Real before/after cases for this discipline live in EXAMPLES.md — read them before you act. 本紀律的真實 before/after 反例見 EXAMPLES.md —— 動手前先對照。

相關技能