臨時實作計畫 是做什麼的?
快速將粗略構想轉化為可提交實作的就緒成品。 犧牲文件完整性以換取速度。
使用時機
- 你已與使用者討論過粗略計畫或構想
- 你想要 implement-commit 的 TDD 驗證,但不想經歷完整的 propose-* 鏈
- 功能已充分理解,可跳過廣泛的設計迭代
先決條件
- 使用者核准的粗略計畫(可以是對話、Markdown 或心智模型)
- 已知的工作區路徑
- 已知要修改的檔案
協調者角色
你是一個機械化路由器。你不思考功能的細節。 你的工作:
- 收集使用者提供的最低必要資訊
- 建立功能目錄結構
- 以適當技能作為上下文,產生子代理(subagent)
- 在階段之間傳遞輸出
- 驗證交叉引用
設定
from pydantic import BaseModel
from pathlib import Path
import os
class GatherResult(BaseModel):
feature_name: str
feature_id: str # NNNN 格式
workspace: str
files_to_modify: list[str]
constraints: list[str]
test_names: list[str]
rough_plan_summary: str
class PhaseResult(BaseModel):
success: bool
artifact_path: str
errors: list[str]
# 子代理上下文的技能路徑
skills = {
"design": "skills/propose-feature-design/SKILL.md",
"test_plan": "skills/propose-feature-test-plan/SKILL.md",
"impl_plan": "skills/propose-implementation-plan/SKILL.md",
}
# 風格指南(如果可用)
style_guides = [
"docs/style/rust-design.md",
"docs/style/rust-test.md",
"docs/style/rust-impl.md",
]
階段 0:收集
以互動方式收集或從粗略計畫推斷:
# 如果尚未知道,請詢問使用者:
# 1. 功能名稱 → 建立 docs/features/NNNN-name/
# 2. 要修改的檔案 → commits[].files
# 3. 關鍵限制條件 → CC 表格條目
# 4. 測試名稱 → test-plan + commits[].tests
# 決定下一個功能 ID
existing = list(Path("docs/features").glob("[0-9][0-9][0-9][0-9]-*"))
next_id = f"{len(existing):04d}"
feature_dir = f"docs/features/{next_id}-{feature_name}"
os.makedirs(feature_dir, exist_ok=True)
階段 1:最小化設計
使用 propose-feature-design 技能產生子代理,但指示產生最小化輸出。
result = spawn(
prompt=draft_spawn_prompt(SkillDefined(
"依照技能流程建立最小化的 design.md。"
"僅產生:概述(1 段落)、關鍵限制條件表格、模組結構。"
"跳過:架構圖、解決方案機制說明、設計模式、設計決策。"
)),
context_files=[
skills["design"],
*[g for g in style_guides if exists(g)],
],
context_data={
"feature_dir": feature_dir,
"feature_name": gathered.feature_name,
"constraints": gathered.constraints,
"files": gathered.files_to_modify,
"rough_plan": gathered.rough_plan_summary,
"minimal_mode": True,
},
response_model=PhaseResult,
isolate_to=Cwd(gathered.workspace)
)
階段 2:最小化測試計畫
使用 propose-feature-test-plan 技能產生子代理。
result = spawn(
prompt=draft_spawn_prompt(SkillDefined(
"依照技能流程建立最小化的 test-plan.md。"
"僅產生:需求覆蓋率表格、關鍵限制條件驗證表格。"
"跳過:詳細測試實作筆記、整合測試說明。"
)),
context_files=[
skills["test_plan"],
f"{feature_dir}/design.md", # 來自階段 1
*[g for g in style_guides if exists(g)],
],
context_data={
"feature_dir": feature_dir,
"test_names": gathered.test_names,
"constraints": gathered.constraints,
"minimal_mode": True,
},
response_model=PhaseResult,
isolate_to=Cwd(gathered.workspace)
)
階段 3:實作計畫
使用 propose-implementation-plan 技能產生子代理。
result = spawn(
prompt=draft_spawn_prompt(SkillDefined(
"依照技能流程建立 implementation-plan.toml。"
"所有欄位都需要 - 沒有最小化模式。"
"確保 tests[] 與 test-plan.md 的測試名稱完全相符。"
)),
context_files=[
skills["impl_plan"],
f"{feature_dir}/design.md",
f"{feature_dir}/test-plan.md",
*[g for g in style_guides if exists(g)],
],
context_data={
"feature_dir": feature_dir,
"workspace": gathered.workspace,
"files": gathered.files_to_modify,
"rough_plan": gathered.rough_plan_summary,
},
response_model=PhaseResult,
isolate_to=Cwd(gathered.workspace)
)
階段 4:驗證交叉引用
產生驗證器以檢查測試覆蓋率。
class VerifyResult(BaseModel):
valid: bool
missing_tests: list[str] # 在 test-plan 中但不在 impl-plan 中
orphan_tests: list[str] # 在 impl-plan 中但不在 test-plan 中
missing_constraints: list[str] # 未被覆蓋的 CC-N
result = spawn(
prompt=draft_spawn_prompt(AdHoc(
intents=["驗證 implementation-plan.toml 對 implement-commit 有效"],
context=["檢查所有成品之間的交叉引用"],
goal=Verify(constraints=[
"test-plan.md 中的每個測試在 commits[].tests 中恰好出現一次",
"design.md 中的每個 CC-N 在 test-plan.md 中都有驗證",
"所有 commits[].files 都存在或將被建立",
"TOML 正確解析",
])
)),
context_files=[
f"{feature_dir}/design.md",
f"{feature_dir}/test-plan.md",
f"{feature_dir}/implementation-plan.toml",
],
response_model=VerifyResult,
read_only=True
)
if not result.parsed.valid:
# 返回階段 3 並帶入錯誤
pass
交接
驗證通過後,成品即可供 implement-commit 使用:
docs/features/NNNN-feature-name/
├── design.md # 最小化:概述 + CC 表 + 模組結構
├── test-plan.md # 最小化:僅覆蓋率表
└── implementation-plan.toml # 完整:所有必填欄位
通知使用者:
成品已就緒。執行 implement-commit 技能以啟動 TDD 管線。