for task in execution_order:
# B-0. 作業ディレクトリ分離
worktree_path = "/tmp/worker-{task.number}-$$"
branch_name = "worker-{task.number}-$$"
git worktree add -b {branch_name} {worktree_path}
TASK_BASE_REF = git rev-parse HEAD
# B-1. sprint-contract を生成
contract_path = bash("node \"${HARNESS_PLUGIN_ROOT}/scripts/generate-sprint-contract.js\" {task.number}")
contract_path = bash("scripts/enrich-sprint-contract.sh {contract_path} --check \"DoD を reviewer 観点で確認\" --approve")
bash("scripts/ensure-sprint-contract-ready.sh {contract_path}")
# B-2. Worker 委託
Plans.md: task.status = "cc:WIP"
resolver_backend_arg = ""
if explicit_backend_value in ["claude", "codex", "cursor"]:
resolver_backend_arg = "--backend {explicit_backend_value}"
backend = bash("bash \"${HARNESS_PLUGIN_ROOT}/scripts/resolve-impl-backend.sh\" {resolver_backend_arg}")
if explicit_flag == "--cursor":
backend = "cursor"
if explicit_flag == "--codex":
backend = "codex"
if backend == "cursor":
print("🚀 cursor / $(bash \"${HARNESS_PLUGIN_ROOT}/scripts/model-routing.sh\" --host cursor --role worker --field model) / {branch_name} / {task.ID}")
companion_prompt = "{task prompt}\n\nAfter making changes, create exactly one git commit in this worktree before returning."
companion_output = bash("bash \"${HARNESS_PLUGIN_ROOT}/scripts/cursor-companion.sh\" task --write --workspace {worktree_path} \"{companion_prompt}\"")
latest_commit = git("-C", worktree_path, "rev-parse", "HEAD")
if git("-C", worktree_path, "status", "--porcelain") != "":
git("-C", worktree_path, "add", "-A")
git("-C", worktree_path, "-c", "user.name=cursor-composer", "-c", "user.email=cursor-composer@local", "commit", "--no-verify", "-m", "cursor: breezing delegated change")
latest_commit = git("-C", worktree_path, "rev-parse", "HEAD")
if latest_commit == TASK_BASE_REF:
raise EscalationError("cursor companion produced no commit")
worker_result = {type: "companion-result.v1", baseCommit: TASK_BASE_REF, commit: latest_commit, worktreePath: worktree_path, branch: branch_name, files_changed: git("-C", worktree_path, "diff", "--name-only", "{TASK_BASE_REF}..HEAD"), summary: companion_output}
worker_id = null
elif backend == "codex":
companion_prompt = "{task prompt}\n\nAfter making changes, create exactly one git commit in this worktree before returning."
companion_state_file = "{worktree_path}/.claude/state/codex-primary-environment.json"
companion_output = bash("HARNESS_CODEX_PRIMARY_ENV_STATE_FILE={companion_state_file} bash \"${HARNESS_PLUGIN_ROOT}/scripts/codex-companion.sh\" task --write -C {worktree_path} \"{companion_prompt}\"")
latest_commit = git("-C", worktree_path, "rev-parse", "HEAD")
if latest_commit == TASK_BASE_REF:
raise EscalationError("codex companion produced no commit")
worker_result = {type: "companion-result.v1", baseCommit: TASK_BASE_REF, commit: latest_commit, worktreePath: worktree_path, branch: branch_name, files_changed: git("-C", worktree_path, "diff", "--name-only", "{TASK_BASE_REF}..HEAD"), summary: companion_output}
worker_id = null
else:
print("🚀 claude / native-subagent / {branch_name} / {task.ID}")
worker_id = spawn_agent({
message: "作業ディレクトリ: {worktree_path} で作業してください。\n\nタスク: {task.内容}\nDoD: {task.DoD}\ncontract_path: {contract_path}\n\n実装してください。完了後 git commit してください。\n\n完了時、以下の JSON を返してください:\n{\"commit\": \"<hash>\", \"files_changed\": [...], \"summary\": \"...\"}",
fork_context: true
})
worker_result = wait_agent({ targets: [worker_id] })
# B-3. Worker が advice request を返した時だけ、Lead が Advisor を呼ぶ
if backend == "claude" and worker_result.type == "advisor-request.v1":
advisor_id = spawn_agent({
agent_type: "default",
message: worker_result.request_json,
fork_context: true
})
advisor_result = wait_agent({ targets: [advisor_id] })
close_agent({ target: advisor_id })
send_input({
target: worker_id,
message: "advisor-response.v1: {advisor_result}"
})
worker_result = wait_agent({ targets: [worker_id] })
# B-4. Lead がレビュー実行(TASK_BASE_REF 起点)
# 公式プラグイン companion review を使用(harness-work の「レビューループ」参照):
# bash "${HARNESS_PLUGIN_ROOT}/scripts/codex-companion.sh" review --base {TASK_BASE_REF}
# → verdict マッピング: approve→APPROVE, needs-attention→REQUEST_CHANGES
VERDICT = review_task(worktree_path, TASK_BASE_REF) # static review(harness-work 参照)
PROFILE = jq(contract_path, ".review.reviewer_profile")
BROWSER_MODE = jq(contract_path, ".review.browser_mode // \"scripted\"")
REVIEW_INPUT = "review-output.json"
if PROFILE == "runtime":
# worktree 内で runtime checks を実行
REVIEW_INPUT = bash("cd {worktree_path} && scripts/run-contract-review-checks.sh {contract_path}")
RUNTIME_VERDICT = jq(REVIEW_INPUT, ".verdict")
if RUNTIME_VERDICT == "REQUEST_CHANGES":
VERDICT = "REQUEST_CHANGES"
elif RUNTIME_VERDICT == "DOWNGRADE_TO_STATIC":
REVIEW_INPUT = "review-output.json" # static review にフォールバック
if PROFILE == "browser":
# browser artifact は PENDING_BROWSER scaffold。reviewer agent が後続で実行。
BROWSER_ARTIFACT = bash("scripts/generate-browser-review-artifact.sh {contract_path}")
# REVIEW_INPUT は static review のまま維持
if REVIEW_INPUT != "review-output.json" and jq(REVIEW_INPUT, ".verdict") == "DOWNGRADE_TO_STATIC":
REVIEW_INPUT = "review-output.json"
bash("scripts/write-review-result.sh {REVIEW_INPUT} {commit_hash}")
# B-5. 修正ループ(REQUEST_CHANGES 時、contract の max_iterations まで)
review_count = 0
# sprint-contract が存在するときのみ max_iterations を読む。存在しない場合は 3(後方互換)
MAX_REVIEWS = read_contract(contract_path, ".review.max_iterations") or 3
while VERDICT == "REQUEST_CHANGES" and review_count < MAX_REVIEWS:
if backend == "claude":
send_input({
target: worker_id,
message: "指摘内容: {issues}\n修正して git commit --amend してください。修正後 JSON を再出力してください。"
})
wait_agent({ targets: [worker_id] })
elif backend == "cursor":
previous_commit = git("-C", worktree_path, "rev-parse", "HEAD")
bash("bash \"${HARNESS_PLUGIN_ROOT}/scripts/cursor-companion.sh\" task --write --workspace {worktree_path} \"Review findings:\n{issues}\n\nFix the findings and create one new git commit before returning.\"")
latest_commit = git("-C", worktree_path, "rev-parse", "HEAD")
if git("-C", worktree_path, "status", "--porcelain") != "":
git("-C", worktree_path, "add", "-A")
git("-C", worktree_path, "-c", "user.name=cursor-composer", "-c", "user.email=cursor-composer@local", "commit", "--no-verify", "-m", "cursor: breezing review fix")
latest_commit = git("-C", worktree_path, "rev-parse", "HEAD")
if latest_commit == previous_commit:
raise EscalationError("cursor companion retry produced no new commit")
else:
previous_commit = git("-C", worktree_path, "rev-parse", "HEAD")
companion_state_file = "{worktree_path}/.claude/state/codex-primary-environment.json"
bash("HARNESS_CODEX_PRIMARY_ENV_STATE_FILE={companion_state_file} bash \"${HARNESS_PLUGIN_ROOT}/scripts/codex-companion.sh\" task --write -C {worktree_path} \"Review findings:\n{issues}\n\nFix the findings and create one new git commit before returning.\"")
latest_commit = git("-C", worktree_path, "rev-parse", "HEAD")
if latest_commit == previous_commit:
raise EscalationError("codex companion retry produced no new commit")
VERDICT = review_task(worktree_path, TASK_BASE_REF)
review_count++
# B-6. Worker 終了
if backend == "claude":
close_agent({ target: worker_id })
# B-7. 結果処理
if VERDICT == "APPROVE":
commit_hash = git("-C", worktree_path, "rev-parse", "HEAD")
git cherry-pick --no-commit {TASK_BASE_REF}..{commit_hash}
git commit -m "{task.内容}"
Plans.md: task.status = "cc:完了 [{short_hash}]"
else:
→ ユーザーにエスカレーション(Plans.md は cc:WIP のまま)
→ 後続タスクも停止
# B-8. Worktree クリーンアップ
git worktree remove {worktree_path}
git branch -D {branch_name}
# B-9. Progress feed
print("📊 Progress: Task {completed}/{total} 完了 — {task.内容}")