Task Contract 在 Agentic Coding 中的角色
.作者:Jollen/
.日期:Wed Jul 01 2026 08:00:00 GMT+0800 (台北標準時間)
任務契約(Task Contract)的本質是一份提示詞(Prompt),這份提示詞就是讓 AI 寫程式(Vibe Coding)的指令;也就是所謂的「用自然語言寫程式」。
認識任務契約(Task Contract)
Claude Code 可以接收自然語言任務,但開發任務不應只寫成一句話;例如,不建議以下寫法:
請幫我打造一個半導體新聞閱讀器 Web App
當然,以現在 Base Model 的強大能力,這一句話也是能創造出神奇的結果。
但是,有更好的做法:「列出功能規格」、「描述技術規格」以及「實作邊界」,有些開發者稱此為 Spec-Driven Development;目前,則統稱為「任務契約 Task Contract」。
所謂的「邊界」指的是「能做什麼」、「不該做什麼」的限制。
一份穩定的任務契約應包含:goal、scope、constraints、acceptance criteria 與 validation command。
以下是一個任務契約範例:
Task goal
Build the backend REST API for Fullstack News Reader.
Scope
Create server/data/semiconductorNews.js.
Create server/api/semiconductor-news.get.js.
Do not modify the frontend yet.
Constraints
Use ES module syntax.
Do not add external dependencies.
Keep the response JSON stable and easy for the frontend to render.
Acceptance criteria
GET /api/semiconductor-news returns updatedAt and topics.
Each topic has id, title, summary, keyPoints, watchNext, and sources.
Each source has title and url.
Validation
Run npm run build.
Show changed files and build result.
任務契約的各段落說明如下表:
| 欄位 | 對應工作流 | 作用 |
|---|---|---|
| Task goal | Observe | 定義任務目標 |
| Scope | Permission Boundary | 限制可修改範圍 |
| Constraints | Plan | 限制技術決策 |
| Acceptance criteria | Verify | 定義驗收條件 |
| Validation | Evidence | 產生可審查證據 |
這份契約比單純要求「幫我做…」更穩定,且「可控」。因為任務契約能明確指出檔案名、實作限制、資料格式與驗證方式。
所謂的「可控」在 Vibe Coding 語義中,代表:AI 寫出來的程式跟「我的預期」是否有很大落差。
一份完整的任務契約,能讓 Claude Code 生成的程式碼更「可控」:
- AI 生成的程式碼,更貼近自己的想像
- 生成可審查的 Patch 檔
關於「可審查的 Patch 檔」類似 git diff 歷史紀錄,這對於軟體專案管理是很重要的資料庫。
Also read
Tags: vibe, agentic, skills, claude