# workspace-cli AINative 实施记录

本文档记录 AINative 研发平台按步骤实施的实际进展。每个步骤只记录已经落地并验证的内容，未完成项保留为后续批次。

## Step 26: Lease-bound capability and residual ownership closure

- 日期：2026-07-11
- daemon 不再为缺失或过期 lease 使用固定五分钟 token。`IssueCapabilityForJobLease` 在同一事务验证 Job active 状态、lease owner、严格未过期边界和不存在其他 active token，并把 capability expiry 固定为数据库 lease expiry。
- `RetryAgentJob`、`RequeueAgentJobAfterFailure` 和 approval resume 在更新前检查有效 lease 与 running run；live Job 返回 `ErrAgentJobStillOwned`。daemon 的 request/provider 失败先原子终结 active Job，再按 attempts requeue，不能直接抢占所有权。
- heartbeat 要求恰好续期一个当前 run-bound capability；Provider 启动前没有 run 时只允许唯一 unbound token。零个或多个匹配 token 都回滚 lease、Worker heartbeat 和 token 更新并返回 ownership-lost。
- migration 0011 与 daemon recovery 收敛没有 running run 但残留 Worker/token 的 queued/terminal Job，并清理引用不存在 Job 的 Worker、run 和 capability。
- active Worker pool 统计和 MCP active-run 查询只接受未过期 lease。succeeded orphan run 收敛时 `error` 保持 NULL，诊断原因仅写用户可见 terminal event。
- 新增 lease capability 边界、live Retry/Requeue、heartbeat token cardinality、residual Worker/token、migration 0011 和 succeeded-run error 回归测试。
- 最终验证：`go test -count=1 ./...`、`go test -race -count=1 ./...`、`go vet ./...`、`go build ./cmd/workspace`、built-binary 33-tool MCP health、daemon start/status/stop、真实 Codex smoke、diff/gofmt/Markdown checks 全部通过；Claude CLI 本机不可用，A18 保持 Partial。

## Step 25: Worker sandbox, lease ownership and orphan-run closure

- 日期：2026-07-11
- migration 0010 按历史 `sandbox` 正确回填 `workspace_policy`：只有 `read-only` 保持只读，其他值限制为 `workspace-write`；升级前 active `danger-full-access` grant 再次强制失效。
- daemon 和 CodexRunner 双层规范化 Worker sandbox。Agent 配置与 permission grant 中的 `danger-full-access` 都只能得到当前登记 worktree 内的 `workspace-write`；未知 Worker sandbox 配置直接拒绝，主 Agent 交互权限模型保持独立。
- heartbeat 必须同时持有未过期 job lease、匹配的 lease owner、Worker current job 和未过期 run-bound capability。等于或晚于 lease/token expiry 的 heartbeat 返回 `ErrWorkerOwnershipLost`，不能复活 job、Worker 或 token。
- migration、daemon recovery、run create、resume、retry 和 approval resume 共用单 job reconciliation。queued/blocked/waiting/terminal job 的 orphan running run 分别收敛为 `lost`、`cancelled`、`failed` 或 `succeeded`，并写递增序号的用户可见终态事件。
- `BlockAgentJob` 和 `CancelAgentJob` 在同一事务更新 job/run、写 `run_blocked`/`run_cancelled`、撤销 capability 并回收 Worker；事件写入失败时整体回滚。
- Provider workspace 对所有父级和最终路径组件执行 `Lstat`；除 macOS 固定 `/var`、`/tmp`、`/etc` 系统别名外，任意业务 symlink 都 fail closed，并在 token 签发前再次检查。Worker/coordinator 的历史非法 workspace 会在同一事务创建 preflight diagnostic run、进入 blocked 并写 `run_blocked` 事件。
- 新增 Worker 初始 sandbox、迟到 heartbeat、migration policy/orphan fixture、Block/Cancel 原子终态和外部父级 symlink 攻击测试。
- 最终验证：`go test -count=1 ./...`、`go test -race -count=1 ./...`、`go vet ./...`、`go build ./cmd/workspace`、built-binary 33-tool MCP health、daemon start/status/stop、真实 Codex smoke、diff/gofmt/Markdown checks 全部通过；Claude CLI 本机不可用，A18 保持 Partial。

## Step 24: Trusted workspace, renewable capability and run reconciliation

- 日期：2026-07-11
- migration 0009 为 capability 增加 run binding 和索引，为 permission grant 增加规范化 workspace policy，并使升级前 active `danger-full-access` grant 失效。
- Job workspace 只从 requirement/release/bug 登记数据派生；Worker MCP 禁止提交 `input_json.workspace_path`，service 对 coordinator/历史输入执行 canonical consistency 校验，daemon 拒绝 control-plane、runtime root、未登记和 symlink escape 路径。
- Provider permission 不再把 `danger-full-access` 传给 Codex；所有可写授权都收敛为当前登记 worktree 的 `workspace-write` envelope。Claude 不再获得 `~/.codex`，仅对 Claude session/cache 子目录开放写权限。
- capability 在 run 创建后绑定 run ID；Worker heartbeat 在同一事务延长 lease 和 token expiry；成功、失败、等待输入和取消终态在业务事务内撤销 job token。
- expired-job reconciliation 在同一事务关闭 running run 为 `lost`/`failed`、写 run event、回收 worker、撤销 token，并将 job 重排队或最终失败。migration 同时清理历史重复 running run 并建立单 active-run 唯一索引。
- finalization 对 SQLite busy 进行有界重试；启动前失败必须成功撤销 capability，否则返回组合错误。Agent health 输出 Worker isolation backend 并在 backend 不可用时 fail closed。
- 新增 workspace 注入、MCP read-only workspace、heartbeat token 续期、终态撤销、expired run reconciliation、Claude cross-provider credential 和 atomic recovery 测试。

## Step 23: Provider control-plane isolation and lifecycle closure

- 日期：2026-07-11
- daemon 新增 owner-only Unix provider socket；Worker 的 MCP stdio 子进程只做代理，不再直接打开 workspace SQLite。
- Codex Worker 强制使用 Codex `workspace-write`/`read-only` 原生 sandbox；Claude Worker 在 macOS 通过外层 `sandbox-exec` allow-list fail-closed 启动。两类 Worker 都通过 daemon socket 访问控制面，Worker 环境不再暴露 `WORKSPACE_CLI_HOME`；Claude 外层 sandbox 的数据库读取攻击测试通过。
- Worker capability 根据 job lease 使用短期有效期，并在 ProcessRunner 所有退出路径按 job 撤销；main Agent capability 轮换后立即撤销旧 token。
- MCP token 校验改为只读，SQLite 启用 WAL 和 5 秒 busy timeout，避免高频只读 MCP 请求升级成写竞争。
- Provider 非零退出和协议错误优先于 approval；多个 approval 作为协议错误处理。approval/run/job/event 继续在单事务内提交并增加注入失败回滚测试。
- daemon migration 0008 保存 executable identity 和 OS process start identity；force stop 在 kill 前执行两次身份校验，拒绝无身份、PID 重用或非 daemon child 进程。
- 新增 Unix proxy、job revoke、Provider failure/approval precedence、sandbox deny-list、approval finalization rollback 和 unrelated PID 测试。

## Step 22: Security and stability hardening

- 日期：2026-07-11
- MCP capability 从 config 中的共享 HMAC secret 改为 256-bit 随机 opaque token；数据库仅保存 SHA-256 hash、scope、过期、撤销和最近使用时间。未知、伪造、过期、已撤销 token 均拒绝，每次 MCP 调用重新校验。
- 主 Agent capability 轮换继续使用原子文件替换；session 正常结束、启动失败或异常退出都会撤销该 session 全部 token。
- Provider 请求人工确认时，approval、`approval_requested` event、run `waiting_user_input` 和 job `waiting_user_input` 在同一数据库事务提交，任一步失败会整体回滚。
- daemon 并发启动等待期间接受已经取得 lease 的健康实例；status 把超时 heartbeat 显示为 `stale`；stop 超时默认不发送信号，`--force` 只有在 PID command 同时匹配 workspace home、daemon child 参数时才允许 kill。
- 删除 `mcp_secret` 配置项和兼容派生 secret，避免同 UID Provider 读取共享签发材料后自行扩大权限。

## Step 21: Runtime hardening and dual-provider closure

- 日期：2026-07-11
- 状态：完成；最终 Review 无 blocking 或 important finding
- daemon：migration 0006、后台单实例、PID/heartbeat、真实 status/stop、实例级 Worker 回收和错误隔离。
- provider：failed event/run/job 原子收敛，故障注入验证回滚。
- main Agent：短期 capability file 轮换、session 状态撤销、stale session 回收和结束清理。
- scheduling：requirement priority 进入 job 排序并保留阶段内部顺序。
- providers：Codex 与 Claude Code 主会话和 Worker 协议均进入固定测试；真实 Codex smoke 通过，真实 Claude smoke 因本机未安装而跳过。
- Review：`docs/ai-native-review-runtime-hardening-final.md`。
- 验证：full test/race/vet/build、33-tool MCP health、daemon start/status/stop/restart、diff/gofmt/Markdown checks 全部通过。

## Step 20: Completion hardening - Batches 1-4

- 日期：2026-07-11
- 状态：完成；最终总体 Review 已批准，无 blocking 或 important finding
- Batch 1：requirement 新增 acceptance criteria、priority、analysis/development review policy binding；新增 policy CLI/MCP；clarification 专用事务持久化需求字段和 repo scope。
- Batch 2：允许 parallelism 大于 max workers；生产 daemon 异步运行 provider、按 pool interval 调度、原子续租 worker/job，并注入当前 workspace 可执行文件。
- Batch 3：ProcessRunner 统一异常终结路径，启动成功后才消费 permission grant，raw tail 严格按 max bytes 分页。
- Batch 4：capability 强制过期；config、database、runtime MCP config、prompt 和 provider raw output 收紧为 owner-only。
- Review 记录：
  - `docs/ai-native-review-hardening-requirement-policy.md`
  - `docs/ai-native-review-hardening-worker-scheduler.md`
  - `docs/ai-native-review-hardening-provider-lifecycle.md`
  - `docs/ai-native-review-hardening-capability-permissions.md`
  - `docs/ai-native-review-hardening-final.md`
- 最终验证：`go test -count=1 ./...`、`go test -race -count=1 ./...`、`go vet ./...`、`go build ./cmd/workspace`、built-binary 33-tool MCP health、real Codex smoke、diff/gofmt/Markdown checks 全部通过。

## Step 19: Overall completion Round 13 closure - Batch 18

- 日期：2026-07-11
- 状态：完成；Codex-only A01-A19 matrix 已由独立 Round 13 Review 批准并通过 fresh final verification
- 范围：
  - 独立 reviewer 复核 real `ProcessRunner` malformed output -> `ErrInvalidProviderOutput` -> daemon atomic release-test blocker 的完整组合路径。
  - 独立 reviewer 逐项关闭 A01-A19，没有 blocking 或 important finding。
  - 完成度审计、README 和 docs index 更新到 Round 13 closure；ClaudeCode 明确保留为未来范围。
- 最终验证：
  - `go test -count=1 ./...`
  - `go test -race -count=1 ./...`
  - `go vet ./...`
  - `go build -o /private/tmp/workspace-cli-ai-native-final ./cmd/workspace`
  - built binary `init` + `mcp health`：`status=available`、`transport=stdio`、33 tools。
  - `WORKSPACE_CLI_REAL_PROVIDER_SMOKE=codex go test -count=1 ./internal/agent -run TestCodexProviderSmoke -v`
  - `git diff --check`、`gofmt -l internal cmd` 和 Markdown fence balance。
- Review 记录：
  - Round 13 独立总体 Review：`docs/ai-native-review-overall-completion-round-13.md`；结论 Approved，无 blocking 或 important finding。

## Step 19: Overall completion Round 12 fix - Batch 17

- 日期：2026-07-11
- 状态：完成；Round 12 real ProcessRunner invalid-output gap 已修复，并由 Round 13 总体 Review 批准
- 范围：
  - provider protocol/result decode failure 使用 `ErrInvalidProviderOutput` 稳定分类，并携带已经持久化的 failed run result 返回。
  - daemon 在 release-test runner error 分支优先识别该分类，调用既有 atomic invalid-output blocker，不进入通用重试。
  - blocker transaction 自身失败时仍回到 retry recovery，保持 test run/job/run/release event 的全有或全无语义。
- TDD 记录：
  - `TestProcessRunnerClassifiesMalformedOutputJSON` 红灯为缺少稳定 error classification；绿灯验证真实进程 malformed `output.json`、failed run/job 和返回 run identity。
  - `TestDaemonBlocksMalformedReleaseTestOutputFromProcessRunner` 红灯为 job queued retry、test run 仍 running；绿灯验证 one attempt、job/test run blocked、run failed 和 `release_test_output_blocked` event。
- 当前验证：
  - `go test -count=1 ./internal/agent ./internal/coordinator -run 'TestProcessRunnerClassifiesMalformedOutputJSON|TestDaemonBlocksMalformedReleaseTestOutputFromProcessRunner|TestDaemonBlocksMalformedReleaseTestOutput|TestInvalidReleaseTestOutputEventFailureRollsBackBlockedState'`
- Review 记录：
  - Round 12 独立总体 Review：`docs/ai-native-review-overall-completion-round-12.md`；结论 Changes required，唯一 finding 已修复。
  - Round 13 已复核 real ProcessRunner -> daemon -> atomic blocker 的组合路径和完整 A01-A19 matrix，结论 Approved。

## Step 19: Overall completion Round 11 fixes - Batch 16

- 日期：2026-07-11
- 状态：Round 11 三项 run-binding/invalid-output blocker 已修复，Round 12 总体 Review 与 fresh final verification 待执行
- 范围：
  - test-run capability 的 `created_by_job_id` 固定为 capability job，显式冲突立即拒绝；active run 只从该 audited job 解析。
  - service/store 对所有 test-run bug 强制 matching created-by job + run，不能省略 realtime event ownership。
  - 所有 release-test provider result 解析/校验错误统一进入 atomic invalid-output execution blocker。
- TDD 记录：
  - MCP wrong-job test 红灯证明 bug/event 可绑定另一个 running job；绿灯验证 capability job equality guard。
  - service/store missing-run tests 红灯证明 test-run bug 可落库；绿灯验证两层写边界都拒绝。
  - malformed JSON daemon test 红灯证明 job requeue 且 test run 留在 running；绿灯验证 job/test run blocked 和结构化诊断。
- 当前验证：
  - `go test -count=1 ./internal/mcp ./internal/workspace ./internal/store ./internal/coordinator -run 'TestMCPBugToolsCreateListAndUpdateScoped|TestCreateBugValidatesReleaseTestMembershipAndReleaseTestJob|TestAINativeStoreRequiresRunForReleaseTestBug|TestDaemonBlocksMalformedReleaseTestOutput|TestDaemonBlocksFailedReleaseTestWithoutBugOutput' -v`
  - `go test -count=1 ./internal/store ./internal/workspace ./internal/coordinator ./internal/mcp`
- Review 记录：
  - Round 11 独立总体 Review：`docs/ai-native-review-overall-completion-round-11.md`；结论 Changes required，三项 finding 均已修复。
  - Round 12 必须复核 capability job/run binding、所有 test-run bug 写入口、全部 provider output validation blocker 和完整 A01-A19 matrix。

## Step 19: Overall completion Round 10 fixes - Batch 15

- 日期：2026-07-11
- 状态：Round 10 三项 persistence/realtime blocker 已修复，Round 11 总体 Review 与 fresh final verification 待执行
- 范围：
  - `publish_confirmation` 只能创建为 pending，不能通过 create API 绕过 `confirm=true` responder invariant。
  - MCP test-run `bug_create` 必须找到 audited job 的 active running Agent run，并把 run ID 传入 atomic bug transaction。
  - invalid output 与 release-worktree mutation 共用 `BlockReleaseTestExecution` transaction；pre-provider mutation 允许无 run，post-provider mutation 原子写 run event/run failure。
- TDD 记录：
  - direct store creation test 红灯证明 `Status=approved` 可直接写入；绿灯验证 pending-only creation guard。
  - MCP bug test 红灯证明 active run 没有 `bug_created` event；绿灯验证 run tail 数据与 bug/workflow 同步提交。
  - dirty-worktree release-event trigger 红灯证明 test run 已 blocked 但 job 被 retry；绿灯验证 blocker transaction 回滚到 running/queued pre-block state。
- 当前验证：
  - `go test -count=1 ./internal/store ./internal/mcp ./internal/coordinator -run 'TestAINativeStoreRejectsApprovedPublishConfirmationWithoutConfirm|TestMCPBugToolsCreateListAndUpdateScoped|TestReleaseWorkspaceMutationEventFailureRollsBackBlockedState|TestDaemonBlocksReleaseTestWhenReleaseWorktreeIsAlreadyDirty|TestDaemonBlocksReleaseTestWhenProviderModifiesReleaseWorktree|TestInvalidReleaseTestOutputEventFailureRollsBackBlockedState' -v`
  - `go test -count=1 ./internal/store ./internal/workspace ./internal/coordinator ./internal/mcp`
- Review 记录：
  - Round 10 独立总体 Review：`docs/ai-native-review-overall-completion-round-10.md`；结论 Changes required，三项 finding 均已修复。
  - Round 11 必须复核 publish creation/response 全部入口、MCP realtime bug event、全部 release-test blocker transaction 和完整 A01-A19 matrix。

## Step 19: Overall completion Round 9 fixes - Batch 14

- 日期：2026-07-11
- 状态：Round 9 四项 cross-boundary blocker 已修复，Round 10 总体 Review 与 fresh final verification 待执行
- 范围：
  - 有命令和缺命令的 release test cycle 都原子创建 test run 与完整 requirement+repo+commit snapshots；daemon 消费旧 queued/waiting run 前校验 snapshot 完整性。
  - invalid failed-output blocker 原子更新 test run、run event、agent run、agent job 和 release status event。
  - service 写边界为 test-run bug 唯一推断 repo 或拒绝多 repo 歧义，MCP 无法通过省略 `repo_id` 绕过。
  - store 专用与通用 approval responder 都阻止 publish confirmation 在没有 `confirm=true` 时进入 approved。
- TDD 记录：
  - service/daemon snapshot trigger tests 红灯证明 commanded run 在 snapshot 失败后留存；绿灯验证 run+snapshot 全回滚。
  - historical queued-run test 红灯证明空 snapshot 被创建 job 并执行；绿灯验证 run 先进入 blocked 且不创建 job。
  - invalid-output run-event trigger 红灯证明 test run 已 blocked、job 却被 requeue；绿灯验证 blocker transaction 全回滚。
  - service multi-repo test 红灯证明无 repo bug 可落库；绿灯验证歧义拒绝与显式 repo 成功。
  - direct store publish test 红灯证明 specialized responder 可 approved；绿灯验证 specialized/generic 两条路径都保持 pending。
- 当前验证：
  - `go test -count=1 ./internal/store ./internal/workspace ./internal/coordinator ./internal/mcp -run 'TestAINativeStoreRejectsApprovedPublishConfirmationWithoutConfirm|TestCreateBugRequiresRepoForMultiRepoTestRunScope|TestStartReleaseTestSnapshotFailureRollsBackCommandedTestRun|TestDaemonCommandedSnapshotFailureRollsBackTestRun|TestDaemonBlocksQueuedReleaseTestRunWithIncompleteSnapshots|TestInvalidReleaseTestOutputEventFailureRollsBackBlockedState|TestMCPBugToolsCreateListAndUpdateScoped' -v`
  - `go test -count=1 ./internal/store ./internal/workspace ./internal/coordinator ./internal/mcp`
- Review 记录：
  - Round 9 独立总体 Review：`docs/ai-native-review-overall-completion-round-9.md`；结论 Changes required，四项 finding 均已修复。
  - Round 10 必须复核所有 test-cycle transaction、invalid-output rollback、bug repo write boundary、publish store invariant 和完整 A01-A19 matrix。

## Step 19: Overall completion Round 8 fixes - Batch 13

- 日期：2026-07-11
- 状态：Round 8 四项 approval/test recovery blocker 已修复，Round 9 总体 Review 与 fresh final verification 待执行
- 范围：
  - `publish_confirmation choice=confirm` 直接生成 approved + `confirm=true`；任何缺少 true confirmation 的 approved response 在持久化前拒绝并保持 pending。
  - failed release-test output 必须包含至少一个 bug；缺失时 job/test run 进入 blocked，并写用户可见 run/release diagnostics。
  - bug 省略 repo 时仅可从单 repo snapshot 唯一推断；多 repo requirement 必须显式指定 included repo，ID/name 同时给出时必须一致。
  - 缺测试命令时，test run、requirement+repo snapshots、`test_command_missing` approval 和 approval-request event 由同一 store transaction 创建；daemon 与 service 共用该路径。
  - 当前验收范围明确为 Codex-only；已存在的 Claude 兼容代码与历史调研不作为完成门槛。
- TDD 记录：
  - publish tests 红灯分别为 `confirm` choice 无效、无 confirm 的 approve 被提交；绿灯验证 alias 与 pending guard。
  - failed-without-bugs parser/daemon tests 红灯证明 job 被 requeue 且 release 无可操作对象；绿灯验证 blocked job/test run。
  - multi-repo bug test 红灯证明空 repo 返回 nil；绿灯验证歧义 target 被拒绝。
  - service/daemon SQLite trigger tests 红灯证明 approval insert 失败后 waiting test run 留存；绿灯验证 run/snapshot/approval/event 全部回滚。
- 当前验证：
  - `go test -count=1 ./internal/workspace ./internal/coordinator -run 'TestRespondPublishConfirmation(ApproveWritesReleaseStatusEvent|ApproveWithoutConfirmStaysPending)|TestStartReleaseTestMissingCommandApprovalFailureRollsBackTestRun|TestReleaseTestBugOutputRejectsRequirementAndRepoOutsideSnapshot|TestParseReleaseTestOutputRejectsFailedResultWithoutBugs|TestDaemonBlocksFailedReleaseTestWithoutBugOutput|TestDaemonMissingCommandApprovalFailureRollsBackTestRunAndSnapshots' -v`
  - `go test -count=1 ./internal/store ./internal/workspace ./internal/coordinator`
- Review 记录：
  - Round 8 独立总体 Review：`docs/ai-native-review-overall-completion-round-8.md`；结论 Changes required，四项 finding 均已修复。
  - Round 9 必须复核 publish terminal semantics、failed-test recovery、repo targeting、missing-command transaction 和完整 A01-A19 matrix。

## Step 19: Overall completion Round 7 fixes - Batch 12

- 日期：2026-07-11
- 状态：Round 7 三项 snapshot/transaction blocker 已修复，Round 8 总体 Review 与 fresh final verification 待执行
- 范围：
  - release-test provider 输出中的显式 requirement ID/key 与 repo ID/name 必须命中当前 immutable test-run snapshot，不能指向同 release 的其他需求或仓库。
  - release-test bug、requirement `pending_development` transition、status event 和用户可见 `bug_created` run event 由同一个 store transaction 提交。
  - `publish_confirmation` approve/cancel/reject response、release status event 和可用 run event 在同一个 store transaction 提交；reject 保留专用 next-action reason。
- TDD 记录：
  - 新增 `TestReleaseTestBugOutputRejectsRequirementAndRepoOutsideSnapshot`；红灯为 resolver 无错误返回值且直接信任显式 ID，绿灯验证 requirement/repo 越界均被拒绝。
  - 扩展 `TestCreateBugAdvancesRequirementWithStatusEventAtomically`；SQLite trigger 强制 `bug_created` run event 失败，绿灯验证 bug、workflow 和 requirement status event 全部回滚。
  - 新增 `TestRespondPublishConfirmationStatusEventFailureRollsBackResponse`；红灯证明 approval 已 approved 后才遇到 event failure，绿灯验证 response 和 event 原子回滚。
- 当前验证：
  - `go test -count=1 ./internal/coordinator ./internal/workspace -run 'TestReleaseTestBugOutputRejectsRequirementAndRepoOutsideSnapshot|TestDaemonRunOnceCreatesRequirementBugWhenReleaseTestFails|TestCreateBugAdvancesRequirementWithStatusEventAtomically|TestRespondPublishConfirmation(ApproveWritesReleaseStatusEvent|CancelWritesReleaseStatusEvent|RejectWritesReleaseStatusEvent|StatusEventFailureRollsBackResponse)' -v`
  - `go test -count=1 ./internal/store ./internal/workspace ./internal/coordinator ./internal/mcp ./internal/agent ./internal/cli`
- Review 记录：
  - Round 7 独立总体 Review：`docs/ai-native-review-overall-completion-round-7.md`；结论 Changes required，三项 finding 均已修复。
  - Round 8 必须复核 provider output snapshot boundary、bug/publish response atomicity 和完整 A01-A19 matrix。

## Step 19: Overall completion Round 6 fixes - Batch 11

- 日期：2026-07-10
- 状态：Round 6 两项 isolation edge case 已修复，Round 7 总体 Review 与 fresh final verification 待执行
- 范围：
  - run-scoped `job_create` 的 omitted input 先规范化为 `{}`，再写入 capability `release_test_run_id`。
  - requirement list/show/watch 的 status events 按 event job 所属 test run 过滤；无 job scope 的 event 对 run-scoped worker fail closed。
  - coordinator capability 和不带 test-run 的兼容 capability 仍保留完整 requirement event history。
- TDD 记录：
  - 扩展 bug MCP test；红灯为 omitted input 返回 `unexpected end of JSON input`，绿灯验证 persisted job input 自动包含 current run。
  - 扩展 mixed-scope test；红灯证明 req list 泄漏 run B job 写入的 requirement event，绿灯覆盖 req list/show/watch。
- 当前验证：
  - `go test -count=1 ./internal/mcp -run 'TestMCPMixedReleaseTestRunScopeDoesNotFallBackToRelease|TestMCPBugToolsCreateListAndUpdateScoped' -v`
  - `go test -count=1 ./internal/mcp`
- Review 记录：
  - Round 6 独立总体 Review：`docs/ai-native-review-overall-completion-round-6.md`；结论 Changes required，两项 finding 均已修复。
  - Round 7 必须复核 omitted/mismatched child job input、requirement status-event filtering 和完整 A01-A19 matrix。

## Step 19: Overall completion Round 5 fixes - Batch 10

- 日期：2026-07-10
- 状态：Round 5 mixed release/test-run capability blocker 已修复，Round 6 总体 Review 与 fresh final verification 待执行
- 范围：
  - capability 同时带 `release_id` 与 `release_test_run_id` 时，所有 MCP access helper 都以 immutable test-run scope 为最高优先级。
  - requirement list/show/watch、job list/show/watch、run tail、approval list/show、release-test artifact 和 bug fixed-by job 都拒绝同 release 其他 test run。
  - worker `job_create` 自动写入 capability test run，显式冲突立即拒绝。
  - release/requirement watch 为 run-scoped token 过滤 active membership、test runs、jobs、approvals、bugs、status/run events 和 snapshots；主 Agent coordinator 仍可看到完整视图。
  - run-scoped worker 不得调用 `release_test_start` 或 `release_integrate` 创建/改变后续测试周期。
- TDD 记录：
  - 新增 `TestMCPMixedReleaseTestRunScopeDoesNotFallBackToRelease`；红灯首先证明 `req_list` 通过 release fallback 泄漏 run B requirement。
  - 扩展同一回归后，继续红灯证明 `req_watch` 泄漏另一个 test run 的 bugfix job。
  - 绿灯覆盖 requirement/job/run/approval/artifact/bug/watch 全部 surfaces，以及 start/integrate mutation guards。
  - 扩展 bug MCP test，验证 current-run `job_create` 自动绑定 run，mismatched input 被拒绝。
- 当前验证：
  - `go test -count=1 ./internal/mcp -run TestMCPMixedReleaseTestRunScopeDoesNotFallBackToRelease -v`
  - `go test -count=1 ./internal/mcp -run 'TestMCPMixedReleaseTestRunScopeDoesNotFallBackToRelease|TestMCPArtifactReleaseTestRunScopeRequiresRunOrReleaseScope|TestMCPBugToolsCreateListAndUpdateScoped|TestMCPWatchToolsReturnScopedSnapshotsAndRedactedRunTail' -v`
  - `go test -count=1 ./internal/mcp`
- Review 记录：
  - Round 5 独立总体 Review：`docs/ai-native-review-overall-completion-round-5.md`；结论 Changes required，mixed-scope finding 已修复。
  - Round 6 必须复核所有 mixed release/test-run read/write surfaces、watch filtering 和完整 A01-A19 matrix。

## Step 19: Overall completion Round 4 fixes - Batch 9

- 日期：2026-07-10
- 状态：三项 Round 4 blocker 和 stale/retest 回归已修复，Round 5 总体 Review 与 fresh final verification 待执行
- 范围：
  - MCP `bug_create` 在 capability 带 `release_test_run_id` 时默认绑定该 run；显式传入同 release 的其他 run 也会被拒绝。
  - snapshot stale 写入失败不再被语义 stale error 覆盖；release scope、reopen 和外部变化路径都传播事务失败。
  - requirement submit、repo binding、Agent assignment、pending-development advancement 及 daemon requirement/release transitions 通过 store transaction 原子写 workflow 和 status event。
  - `ReopenRequirement` 在同一事务中把受影响 AINative release 标为 legacy/workflow stale 并写 event；manual release 仍只保留 legacy stale 兼容行为。
  - stale workflow 成为 bugfix re-integrate/retest 的权威入口；兼容扫描旧数据中 `workflow=testing + status=stale` 的记录。
- TDD 记录：
  - 扩展 MCP bug scope test，红灯证明 omitted test run 和 same-release mismatched run 可越过 immutable scope；绿灯覆盖默认绑定与拒绝。
  - 新增 requirement workflow event rollback test，分别强制 submit、pending-development 和 Agent assignment event 写入失败，验证业务状态全部回滚。
  - 新增 daemon workflow event rollback test，验证 requirement/release transition 和 event 原子提交。
  - 扩展 reopen integration test 和 release scope stale rollback test，验证 stale workflow/event 以及 membership rollback。
  - package suite 首轮暴露 stale workflow 后 re-test scanner 仍只扫描 testing；修复后 bugfix/retest/publish 三条 E2E 均恢复通过。
- 当前验证：
  - `go test -count=1 ./internal/mcp -run TestMCPBugToolsCreateListAndUpdateScoped -v`
  - `go test -count=1 ./internal/workspace -run 'TestRequirementWorkflowStatusEventFailureRollsBackTransitions|TestReopenReadyRequirementRestoresWorktreeAndClearsReady|TestAINativeReleaseScopeStaleEventFailureRollsBackMembership' -v`
  - `go test -count=1 ./internal/coordinator -run 'TestDaemonWorkflowStatusEventFailureRollsBackTransitions|TestDaemonRunOnceReintegratesReleaseAndQueuesRetestAfterBugfix|TestDaemonRunOnceReleaseBugfixRetestWatchAndPublishE2E|TestDaemonRunOnceFullAINativeFakeProviderE2E' -v`
  - `go test -count=1 ./internal/store ./internal/workspace ./internal/coordinator ./internal/mcp ./internal/agent`
- Review 记录：
  - Round 4 独立总体 Review：`docs/ai-native-review-overall-completion-round-4.md`；结论 Changes required，三项 finding 均已修复。
  - Round 5 必须复核 capability test-run binding、所有 workflow/event transaction、reopen stale/retest 和完整 A01-A19 matrix。

## Step 19: Overall completion Round 3 fixes - Batch 8

- 日期：2026-07-10
- 状态：四项 Round 3 blocker 已实现修复，Round 4 总体 Review 和 fresh final verification 待执行
- 范围：
  - provider event 持久化先按当前 job token exact-redact；通用 redactor 同时识别 signed capability value，覆盖 JSON argv、standalone output 和 MCP raw tail。
  - testing token 带 `release_test_run_id` 时，bug list/update 和 bug-scoped job create 必须命中该 test run 和 requirement snapshot；同 release 的其他 test run 不再被 release id 放宽。
  - `CompleteReleaseTesting` 对相同 completed test run 幂等且不新增 event；其他调用只接受 `workflow_status=testing` 和该 release 最新 test run，晚到 job 不得回退 pending-release/releasing/released/stale。
  - AINative release scope add/remove 与 external feature/base/release branch stale 路径统一写 `status=stale`、`workflow_status=stale` 和 `release_status_events`；legacy `manual_release` 保持兼容。
- TDD 记录：
  - 扩展 provider stream/redactor tests，红灯证明 JSON argv 和 standalone capability 同时泄漏到 event；绿灯验证 event 和 MCP raw tail 只含 `[REDACTED]`。
  - 扩展 `TestMCPBugToolsCreateListAndUpdateScoped`，红灯证明 current test-run token 能 list 另一个 test run 的 bug；绿灯同时覆盖 list、update 和 job_create forbidden。
  - 扩展 release completion store test，红灯证明重复完成写第二组 no-op events，且 pending release 可被回退；绿灯增加 same-run idempotency、workflow guard 和 latest-run guard。
  - 扩展 stale unit/integration tests，红灯证明 add/remove 和 feature refresh 只改 legacy status；绿灯验证 workflow stale、old/new event 和 reason。
- 当前验证：
  - `go test -count=1 ./internal/agent -run 'TestProcessRunnerStreamsRedactedOutputAndCompletesJob|TestRedactProviderLineHandlesStructuredSecrets|TestProcessRunnerRedactsCapabilityTokenFromPersistedCommand' -v`
  - `go test -count=1 ./internal/mcp -run 'TestMCPWatchToolsReturnScopedSnapshotsAndRedactedRunTail|TestMCPBugToolsCreateListAndUpdateScoped|TestMCPJobToolsCreateListShowAndUpdateScoped' -v`
  - `go test -count=1 ./internal/store -run 'TestAINativeStore(CompletesReleaseTestingAndRecordsStatusEvent|StartsReleasePendingReleaseAndCreatesPublishApproval|ReleaseRequirementStatusEventFailureRollsBackLifecycleTransition)' -v`
  - `go test -count=1 ./internal/workspace -run 'TestIntegratedReleaseAddRemoveRequirementMarksStale|TestReleaseStatusMarksIntegratedReleaseStaleWhenFeatureChanges' -v`
  - `go test -count=1 ./internal/agent ./internal/mcp ./internal/store ./internal/workspace`
- Review 记录：
  - Round 3 独立总体 Review：`docs/ai-native-review-overall-completion-round-3.md`；结论 Changes required，四项 finding 均已修复。
  - Round 4 必须复核 event/raw-tail secrecy、test-run bug scope、late completion ordering和所有 stale write paths。

## Step 19: Overall completion Round 2 fixes - Batch 7

- 日期：2026-07-10
- 状态：四项 Round 2 blocker 已实现修复，Round 3 总体 Review 和 fresh full verification 待执行
- 范围：
  - `ProcessRunner` 持久化 `agent_runs.command` 前按 exact job token 脱敏，独立参数和 Codex `-c mcp_servers...args` 内嵌 token 都替换为 `[REDACTED]`；真实进程参数不变。
  - `CompleteReleaseTesting`、`StartReleasePendingRelease`、`StartReleasePublishing` 和 `FinalizeAINativeReleasePublished` 在同一 transaction 内为每个被推进的 requirement 写 old/new status、actor、reason 和可用 job id。
  - testing capability 可以读取 scoped release active membership 或 scoped release-test snapshot 内 requirement artifact；存在 test-run scope 时以 immutable snapshot 为准，不能借 release id 扩大范围。
  - service `CreateBug` 校验 requirement 必须属于 test-run snapshot 或 active release membership；MCP 同时执行 capability membership guard。
  - MCP `bug_create` 未显式传入 `created_by_job_id` 时使用 `capability.job_id`；release-test job 只有 release id 和 input 中的 `release_test_run_id` 都匹配时才能作为创建审计来源。
- TDD 记录：
  - `TestProcessRunnerRedactsCapabilityTokenFromPersistedCommand` 红灯证明 token 同时泄漏到返回 run 和 DB run，绿灯验证两处只有 `[REDACTED]`。
  - 扩展 release lifecycle store tests，红灯证明 requirement status events 缺失；绿灯覆盖 testing -> testing_completed -> pending_release -> releasing -> released。
  - 扩展 `TestMCPArtifactReleaseTestRunScopeRequiresRunOrReleaseScope`，红灯证明 release/test-run testing token 无法读取 included requirement artifact；绿灯同时验证 outside requirement forbidden。
  - 新增 `TestCreateBugValidatesReleaseTestMembershipAndReleaseTestJob`，覆盖 snapshot、active membership、release-test job 和 mismatched test run。
  - 扩展 `TestMCPBugToolsCreateListAndUpdateScoped`，验证 capability job 自动审计、status event job id、outside snapshot forbidden 和 requirement-only testing scope 兼容。
- 当前验证：
  - `go test -count=1 ./internal/agent -run TestProcessRunnerRedactsCapabilityTokenFromPersistedCommand -v`
  - `go test -count=1 ./internal/store -run 'TestAINativeStore(CompletesReleaseTestingAndRecordsStatusEvent|StartsReleasePendingReleaseAndCreatesPublishApproval|PublishingRecordsRequirementStatusEvents)' -v`
  - `go test -count=1 ./internal/workspace -run 'TestCreateBug(ValidatesReleaseTestMembershipAndReleaseTestJob|AdvancesRequirementWithStatusEventAtomically)' -v`
  - `go test -count=1 ./internal/mcp -run 'TestMCP(BugToolsCreateListAndUpdateScoped|ArtifactReleaseTestRunScopeRequiresRunOrReleaseScope)' -v`
  - `go test -count=1 ./internal/agent ./internal/store ./internal/workspace ./internal/mcp`
- Review 记录：
  - Round 2 独立总体 Review：`docs/ai-native-review-overall-completion-round-2.md`；结论 Changes required，四项 finding 均已按 TDD 修复。
  - Round 3 必须独立复核 capability secrecy、release requirement event atomicity、artifact/bug membership 和 release-test job audit。

## Step 19: Overall completion audit findings - Batch 6

- 日期：2026-07-10
- 状态：两项 Round 1 blocker 已实现修复，Round 2 总体 Review 待执行
- 范围：
  - MCP/service `bug_create` 现在通过 store transaction 原子创建 bug、更新 requirement workflow 和写 status event。
  - bug status event 保留 actor、reason 和 created-by job；event insert 失败时 bug 和 workflow 一并回滚。
  - MCP testing Agent 创建 bug 时写 `actor=mcp:testing`，`req_watch` 可见 `pending_development` transition。
  - daemon-generated worker key 改为 pool-qualified prefix，并跳过同 pool 所有 retained lost/stopped/live key；不再按 live count 复用旧 key。
  - create 窗口遇到已存在 key 时继续下一 sequence，避免单次 unique collision 终止容量恢复。
- TDD 记录：
  - 新增 `TestCreateBugAdvancesRequirementWithStatusEventAtomically`；初始红灯为 `CreateBugParams` 没有 actor/reason，且原 service 没有 event/transaction。
  - rollback 子测试用 SQLite trigger 强制 status event insert 失败，要求 bug 不存在且 workflow 保持 testing。
  - 扩展 `TestMCPBugToolsCreateListAndUpdateScoped`，验证 MCP bug_create 的 pending-development event actor/reason。
  - 新增 `TestDaemonRunOnceReplacesLostGeneratedWorkerWithoutKeyCollision`；红灯为 replacement 创建 `daemon-1-1` 触发 `UNIQUE constraint failed: worker_instances.worker_key`。
  - 绿灯：atomic bug/event rollback、MCP audit 和 distinct lost-worker replacement 均通过。
- 当前验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test ./internal/workspace ./internal/mcp ./internal/coordinator -run 'TestCreateBugAdvancesRequirementWithStatusEventAtomically|TestMCPBugToolsCreateListAndUpdateScoped|TestDaemonRunOnceReplacesLostGeneratedWorkerWithoutKeyCollision' -count=1`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -race -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`、`gofmt -l internal` 和 Markdown fence 检查。
- Review 记录：
  - Round 1 独立总体 Review：`docs/ai-native-review-overall-completion.md`；结论 Changes required，发现 bug transition 缺 status event 和 lost worker replacement key collision。
  - Round 2 独立总体 Review 待执行。

## Step 9: MCP stdio health check - Batch 14

- 日期：2026-07-10
- 状态：完成，stdio MCP control plane 具备可执行健康检查
- 范围：
  - 新增 `workspace mcp health`，为本次检查生成 5 分钟有效的 coordinator capability，不复用用户或 worker token。
  - `Server.Health` 通过同一个 `Server.Serve` stdio JSON-RPC 边界发送 `tools/list`，解析 RPC error、拒绝空工具集，并返回 available/stdio、tool count 和 tool names。
  - `workspace mcp serve` 从硬编码 `os.Stdin` 改为 `cmd.InOrStdin()`；生产默认仍是 stdin，同时 Cobra 命令测试可以直接覆盖真实 serve 路径。
  - health 只执行只读 `tools/list`，不调用任何业务 tool 或改变 workspace 状态。
- TDD 记录：
  - 新增 `TestMCPHealthChecksStdioToolsList`；红灯为 `Server.Health undefined`。
  - 新增 `TestMCPServeCommandAndHealthUseStdioToolsList`；红灯证明 `mcp serve` 忽略 Cobra input，且 `mcp health` 命令不存在。
  - 扩展 root command surface，要求 `mcp health` 可发现。
  - 绿灯：server health、真实 Cobra stdio serve、health CLI output 和 command surface 均通过。
  - Round 1 Review 新增 `TestMCPHealthRejectsInvalidCapability`，覆盖 health RPC authorization error。
  - Round 1 Review 新增 `TestMCPServeAcceptsLargeStdioToolRequest`；红灯为 128 KiB request 触发 `bufio.Scanner: token too long`。
  - Round 1 修复为 stdio scanner 设置 4 MiB 有界上限；大请求 focused test 和 health failure path 通过。
- 当前验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test ./internal/mcp ./internal/cli -run 'TestMCPHealthChecksStdioToolsList|TestMCPServeCommandAndHealthUseStdioToolsList|TestRootCommandIncludesDocumentedCommandSurface' -count=1`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test ./internal/mcp ./internal/cli -count=1`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test ./internal/mcp -run 'TestMCPHealth(ChecksStdioToolsList|RejectsInvalidCapability)|TestMCPServeAcceptsLargeStdioToolRequest' -count=1`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -race -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - 实际构建产物完成临时 home `init` 和 `mcp health` smoke，输出 `status=available`、`transport=stdio`、`tool-count=30`。
  - provider CWD/control-home 变更后重新执行 `WORKSPACE_CLI_REAL_PROVIDER_SMOKE=codex ... TestCodexProviderSmoke -v`，真实 Codex CLI smoke 通过。
- Review 记录：
  - Round 1 独立 Review 文档：`docs/ai-native-review-step-09-mcp-health.md`；原 scope 通过，同时提出 scanner 默认上限和 invalid-token coverage 两项 non-blocking notes，均已修复。
  - Round 2 独立 Review 文档：`docs/ai-native-review-step-09-mcp-health-round-2.md`；复核 bounded request、invalid capability、token secrecy 和 CLI stdio，结论为 Approved with no findings。
- 当前边界：
  - health 证明本进程的 stdio protocol、capability authorization 和 tools registry 可用；它不探测 provider CLI 健康，provider 仍由 `workspace agent health` 检查。

## Step 7: Provider workspace isolation and prerequisite preflight - Batch 6

- 日期：2026-07-10
- 状态：完成，provider CWD 与控制面 home 隔离并具备启动前置检查
- 范围：
  - 主 Agent 的 Codex `--cd`、Codex/Claude `CommandSpec.Dir` 从 workspace home 根目录改为 session-scoped `work/runtime/main-agent/<agent>/<session>/workspace`。
  - MCP config、`WORKSPACE_CLI_HOME` 和 workspace binary 注入仍指向真实控制面 home，provider 登录态和 MCP 操作方式不变。
  - analysis、后台 coordinator 等没有 `workspace_path` 的 job 使用 `work/runtime/agent-workspaces/job-<id>/attempt-<n>`，不再把包含 `workspace.db` 的 home 作为 workspace-write CWD。
  - 带 `workspace_path` 的 Coding/testing job 在 provider 启动前校验路径存在且为目录；所有 provider job 同时校验 artifact 目录。
  - preflight 失败复用正常 job retry/max-attempts 路径，保存 path-specific `last_error`，不启动 provider，worker 恢复 idle。
- TDD 记录：
  - 新增 `TestMainSessionCommandsUseIsolatedRuntimeWorkingDirectory`；红灯证明 Codex/Claude main session 原先都使用 workspace home 作为 process CWD。
  - 新增 `TestDaemonRunRequestIsolatesJobsWithoutWorkspacePath`；红灯证明 analysis/coordinator request 默认 CWD 是 workspace home。
  - 新增 `TestDaemonRunRequestRejectsMissingWorkspaceAndArtifactPrerequisites`；红灯证明缺失目录不会在 provider 启动前被识别。
  - 新增 `TestDaemonRetriesWorkerJobWithoutStartingProviderWhenWorkspacePrerequisiteIsMissing`；红灯证明缺失 workspace 时 fake provider 仍被调用并把 job 标为 succeeded。
  - 绿灯：main session/job isolation、workspace/artifact preflight、无 provider 调用、retry 和 worker idle 均通过。
  - Round 1 Review 新增 Codex/Claude worker control-plane env 断言；红灯证明两个 builder 的 `CommandSpec.Env` 都为空。
  - Round 1 修复新增共享 `workerControlPlaneEnv`，显式注入真实 `WORKSPACE_CLI_HOME` 和 workspace binary，同时不覆盖 `CODEX_HOME`；focused provider tests 通过。
- 当前验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test ./internal/agent ./internal/coordinator -run 'TestMainSessionCommandsUseIsolatedRuntimeWorkingDirectory|TestDaemonRunRequest(IsolatesJobsWithoutWorkspacePath|RejectsMissingWorkspaceAndArtifactPrerequisites)|TestDaemonRetriesWorkerJobWithoutStartingProviderWhenWorkspacePrerequisiteIsMissing' -count=1`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test ./internal/agent ./internal/coordinator ./internal/cli -count=1`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test ./internal/agent -run 'TestCodexRunnerBuildsCommandAndMCPConfig|TestClaudeRunnerBuildsCommandAndMCPConfig' -count=1`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -race -count=1 ./internal/agent ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -race -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
- Review 记录：
  - Round 1 独立 Review 文档：`docs/ai-native-review-step-07-provider-workspace-isolation.md`；发现 worker provider 未显式继承真实 control home，结论为 Changes required，已修复。
  - Round 2 独立 Review 文档：`docs/ai-native-review-step-07-provider-workspace-isolation-round-2.md`；复核 control-home env、CWD 隔离、preflight、retry/idle 和 provider 兼容性，结论为 Approved with no findings。
- 当前边界：
  - 本批防止 workspace-write provider 直接写控制面 home；读取权限仍由 provider sandbox 决定，所有平台状态变更继续要求 capability-scoped MCP。
  - MCP stdio `tools/list` 健康检查仍是完成度矩阵 A04 的下一批缺口。

## Step 8: Coordinator status-change observation - Batch 13

- 日期：2026-07-10
- 状态：完成，关键 workflow 状态变化已进入主 Agent coordinator lane
- 范围：
  - coordinator watch loop 从仅处理 `pending_acceptance` 扩展为监听 `analysis_completed`、`development_completed`、open requirement bug、release `stale`、release `publish_in_progress` 和非 coordinator blocked job。
  - 需求/release coordinator job 使用最新匹配当前状态的 status event ID 区分观察代次；同一事件重复 tick 不重复创建，新同状态事件可以触发新的主 Agent 判断。
  - legacy 无 status event 数据使用实体+状态 fallback key；原 `coordinator-decide-<requirement-key>` pending-acceptance key 保持兼容。
  - open bug 使用 bug ID 幂等；blocked source job 使用 job ID + attempt 幂等，并排除 `role=coordinator`，避免协调任务递归派生。
  - coordinator job input 增加 trigger type、状态事件 actor/reason、bug 详情或 source job last error，以及明确的 coordination request 和不可绕过 gate。
  - `RunOnce` 在 coordinator scan 前写入 `publish_in_progress` 幂等 manual-recovery diagnostic，使主 Agent 使用最新诊断原因，同时保持该状态不可自动降级为 stale。
  - coordinator lane 仍固定串行执行；本批只扩展 watcher 和输入上下文，不改变 worker pool 并发语义。
- TDD 记录：
  - 新增 `TestDaemonEnsureCoordinatorDecisionJobsObservesWorkflowChangesBugsAndBlockersIdempotently`。
  - 红灯：原 watcher 只创建 pending-acceptance job，analysis/development completed、release 状态、bug 和 blocker key 全部不存在。
  - 新增 `TestDaemonEnsureCoordinatorDecisionJobsUsesStatusEventGeneration`。
  - 红灯：同一 requirement 的第二个相关 status event 不会产生新的协调代次。
  - 新增 `TestDaemonEnsureCoordinatorDecisionJobsUsesBlockedAttemptAndSkipsCoordinatorRecursion`，覆盖 source job retry 后的新 blocker 代次和 coordinator blocker 递归排除。
  - 扩展 `TestDaemonRunOnceRecordsPublishInProgressDiagnostic`，证明同一 tick 先写 manual-recovery diagnostic，再用该最新 event 创建并运行 coordinator job。
  - 绿灯：七类触发、完整 input、重复扫描幂等、同状态新事件、blocked attempt 代次、递归排除和 publish diagnostic 顺序均通过。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test ./internal/coordinator -run 'TestDaemonEnsureCoordinatorDecisionJobs|TestDaemonRunOnceRecordsPublishInProgressDiagnostic' -count=1`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test ./internal/coordinator -count=1`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -race -count=1 ./internal/store ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`、focused `gofmt -l` 和 Markdown fence 检查。
- Review 记录：
  - Round 1 独立 Review 文档：`docs/ai-native-review-step-08-coordinator-status-observation.md`；覆盖触发完整性、事件代次、block retry、publish diagnostic 顺序、递归排除和 workflow gate，结论为 Approved with no findings。
- 当前边界：
  - watcher 负责生成主 Agent 判断任务；业务状态变更仍只能由 coordinator 通过已有 workspace-cli MCP/service gate 执行。
  - `analysis_completed` 和 `development_completed` 不因监听本身自动推进；发布仍保留测试快照和用户确认入口。

## Step 7: Worker agent model and system prompt - Batch 5

- 日期：2026-07-10
- 状态：完成，worker Agent model 和 system prompt 已进入真实 provider 请求
- 范围：
  - worker `RunRequest` 新增 `Model`，daemon 从绑定 Agent 读取 model；Codex 和 Claude worker command 都在配置非空时加入 `--model`。
  - daemon 读取 Agent inline system prompt 和 system prompt file，按 inline、file、job input 固定顺序构造 worker 最终 prompt。
  - 没有 system prompt 时保持原始 `job.InputJSON`，兼容现有 fake/provider runner 和审计内容。
  - system prompt file 不可读时在 provider 构造/启动前返回明确错误，不静默降级到无 prompt。
  - Codex CLI 参数形态通过本机 `codex exec --help` 核验，`--model` 是当前支持的非交互选项；官方 manual helper 因响应缺少 `x-content-sha256` 未能刷新，未依赖该失败结果推断参数。
- TDD 记录：
  - 新增 `TestWorkerProviderCommandsUseConfiguredModel`。
  - 红灯：`RunRequest` 没有 Model 字段，测试构建失败，证明 Agent model 未进入 worker provider contract。
  - 新增 `TestDaemonRunRequestAppliesWorkerAgentModelAndSystemPrompts` 和 `TestDaemonRunRequestRejectsUnreadableWorkerSystemPromptFile`。
  - 红灯：worker run request 无 model，prompt 仍只有 job input，system prompt 配置完全未使用。
  - 绿灯：两类 provider model 参数、inline/file/job prompt 顺序和文件错误均通过。
  - Round 1 新增 `TestDaemonRetriesWorkerJobWhenSystemPromptFileIsUnreadable` 和 `TestDaemonRetriesCoordinatorJobWhenSystemPromptFileIsUnreadable`。
  - Review 红灯：两条路径都让 `RunOnce` 直接返回 prompt 文件错误；worker job 保持 leased/running，coordinator job 也没有 retry 或 `last_error`。
  - Review 绿灯：request preparation error 进入正常 failure/retry，路径写入 `last_error`，worker 回 idle；达到 max attempts 且 provider 尚未启动时显式标记 job failed。
  - Round 2 把两条测试扩展到第三次 claim；红灯显示 job 已 failed 但原 prompt 错误仍从 `RunOnce` 返回并终止 daemon。
  - Round 2 绿灯：terminal failure 写入成功后作为已处理 outcome 返回，worker/coordinator job 保持 failed、worker idle、provider 调用次数为零，daemon 继续运行。
- Review 记录：
  - Round 1 独立 Review 文档：`docs/ai-native-review-step-07-worker-agent-model-system-prompt.md`；发现 worker/coordinator prompt-file preparation error 绕过 retry 和 worker idle 清理，结论为 Changes required。
  - Round 2 独立 Review 文档：`docs/ai-native-review-step-07-worker-agent-model-system-prompt-round-2.md`；发现 max attempts 已写 failed 但错误仍终止 daemon，结论为 Changes required。
  - Round 3 独立 Review 文档：`docs/ai-native-review-step-07-worker-agent-model-system-prompt-round-3.md`；复核完整批次和两轮修复，结论为 Approved with no findings。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/agent ./internal/coordinator -run 'TestWorkerProviderCommandsUseConfiguredModel|TestDaemonRunRequestAppliesWorkerAgentModelAndSystemPrompts|TestDaemonRunRequestRejectsUnreadableWorkerSystemPromptFile' -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/agent ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -race -count=1 ./internal/agent ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check` 和 Markdown fence 检查。
- 当前边界：
  - Worker system prompt 作为 provider 初始指令前缀传入；Codex/Claude 的 job-scoped MCP 和 capability token 注入方式不变。

## Step 14: Release workspace immutability guard - Batch 19

- 日期：2026-07-10
- 状态：完成，release test 前后完整性门禁已落地
- 范围：
  - release test provider 启动前逐 repo 运行 Git dirty 检查；已有 tracked/untracked 变更时不启动 Testing Agent。
  - provider 返回后再次检查；Testing Agent 产生变更时拒绝其 passed/failed 业务结果，并把已经完成的 agent run 改记为 failed。
  - 两类完整性失败都把 release test job 和 test run 标为 blocked，保持 release/requirement 当前业务阶段，并写 release status diagnostic；provider 已启动时额外写 `release_workspace_modified` run event。
  - daemon 不自动 reset/clean release worktree，保留现场供用户查看；用户清理后可显式 retry，同一 test run 会重新进入 running。
  - release test fixture 使用真实 Git worktree；命令推断测试产生的 fixture 文件先提交，避免把测试前置数据误判为 Agent 修改。
- TDD 记录：
  - 新增 `TestDaemonBlocksReleaseTestWhenReleaseWorktreeIsAlreadyDirty`。
  - 红灯：dirty release worktree 下 provider 仍执行一次，job 被计为 completed。
  - 新增 `TestDaemonBlocksReleaseTestWhenProviderModifiesReleaseWorktree`。
  - 红灯：provider 修改 release repo 后 passed 结果仍被采纳，job/test run 没有 blocked 或实时完整性事件。
  - 绿灯：preflight 不启动 provider；postflight 拒绝结果并记录 failed run、blocked job/test run、run event 和 release diagnostic，两条路径都不失败重试。
- Review 记录：
  - Round 1 独立 Review 文档：`docs/ai-native-review-step-14-release-workspace-immutability.md`；结论为 Approved with no findings。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run 'TestDaemonBlocksReleaseTestWhenReleaseWorktreeIsAlreadyDirty|TestDaemonBlocksReleaseTestWhenProviderModifiesReleaseWorktree' -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator`
- 当前边界：
  - 完整性门禁检查 Git 可见的 tracked/untracked 变化；被 `.gitignore` 忽略的测试缓存和构建输出不视为 release 代码修改。
  - 本批阻塞并保留 dirty 现场，不新增自动清理命令或隐式回滚。

## Step 8: Concurrent worker execution - Batch 12

- 日期：2026-07-10
- 状态：完成，worker pool parallelism 已对应真实并发 provider 执行
- 范围：
  - `RunOnce` 先串行计算 pool capacity、创建/复用 worker instance 并 claim job，再为每个 claimed slot 启动独立 goroutine；同一 pool 的 provider job 现在真正并发执行。
  - `RunOnce` 等待本轮所有 worker outcome，集中汇总 completed/failed/retried 和阶段计数；任一 worker 错误不会让其他已启动 goroutine 脱离 daemon 生命周期。
  - `ClaimAgentJob` 排除已有 leased/running job 的相同 requirement 或 release scope，保护 feature/release workspace，同时保留不同 scope 的并行能力。
  - SQLite DB 使用单一共享连接串行短状态事务，避免并发 provider run 的状态写入产生 `SQLITE_BUSY`；provider 进程、runtime 文件和外部工具执行仍并行。
- TDD 记录：
  - 新增 `TestDaemonRunOnceExecutesWorkerPoolJobsConcurrently`。
  - 红灯：第一个 blocking provider 未释放前，第二个 job 从未启动，证明原调度只是同 tick 串行执行。
  - 中间红灯：并发 goroutine 已启动但 SQLite 状态写竞争导致只有一个 provider 到达 runner；单一共享连接串行短事务后通过。
  - 新增 `TestClaimAgentJobSerializesSharedRequirementScope`。
  - 红灯：首个 requirement-scoped job leased 后，第二个同 scope job仍被 claim；加入 active scope exclusion 后，只有首个 job 退出 active 状态才可 claim 第二个。
  - Round 1 新增 `TestClaimAgentJobAllowsDifferentRequirementWorkspacesInSameRelease` 和 `TestClaimAgentJobSerializesSharedReleaseOnlyScope`；红灯证明 release association 让不同 requirement bugfix 过度串行，改为 requirement-first、release-only scope 后两类语义同时通过。
  - Round 1 新增 `TestDaemonRunOnceHonorsLoweredMaxWorkersWithExistingIdleInstances`；红灯显示已有三个 idle instance 时把 `max_workers` 降为 1 仍 claim 三个 job，capacity 同时扣除 active jobs 并受新 max 限制后通过。
- Review 记录：
  - Round 1 独立 Review 文档：`docs/ai-native-review-step-08-concurrent-worker-execution.md`；发现 bugfix release association 过度串行化，以及降低配置后 idle workers 可绕过 `max_workers`，结论为 Changes required。
  - Round 2 独立 Review 文档：`docs/ai-native-review-step-08-concurrent-worker-execution-round-2.md`；复核完整批次和两项修复，结论为 Approved with no findings。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run TestDaemonRunOnceExecutesWorkerPoolJobsConcurrently -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/store -run TestClaimAgentJobSerializesSharedRequirementScope -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/store ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -race -count=1 ./internal/store ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check` 和 Markdown fence 检查。
- 当前边界：
  - coordinator lane 继续保持固定并行度 1；本批只并发 analysis/coding/testing worker pool job。
  - worker instance 是 daemon 内的持久执行槽记录；每个 job 仍启动独立 provider 子进程，不新增后台 supervisor 或常驻 provider 进程。

## Step 13: Automatic implementation blocker - Batch 10

- 日期：2026-07-10
- 状态：完成，Coding Agent 的结构化不可实施结果已自动进入 blocker artifact 和人工决策闭环
- 范围：
  - implementation step 和 step fix input 增加 `result_contract`，向真实 Coding Agent 声明成功输出和 `implementation_blocker` 阻塞输出结构。
  - step/fix succeeded result 出现 `implementation_blocker.reason` 时，不创建后续 Review；daemon 自动创建 requirement-scoped `implementation_blocker` artifact。
  - approval payload 记录 blocker artifact、implementation plan、step index/key/title 和 reason；options 固定为 continue/replan/block，默认建议 replan。
  - `CreateHumanApprovalRequest` 支持 blocker 专用原子联动，在同一事务内校验 artifact/job/requirement scope、创建或复用 pending approval、写 approval requested status/run events并把 source job 标为 blocked。
  - blocker artifact 按 job+run 幂等：同一次 post-run retry 复用，新的 run 可以产生新 artifact version 和 approval key。
  - blocked business outcome 不计为 daemon completed job，worker 正常恢复 idle。
- TDD 记录：
  - 新增 `TestDaemonImplementationStepCreatesBlockerArtifactApprovalAndBlocksJob`。
  - 红灯：step result 已包含 blocker，但 job 仍 succeeded 并创建 step Review，没有 artifact 或 approval。
  - 绿灯：自动 artifact、typed approval、blocked job、实时 events、无 step Review和同 run 幂等均通过。
  - 新增 `TestDaemonImplementationStepFixCanCreateImplementationBlocker`，覆盖 fix 阻塞且不创建 rereview。
  - 新增 `TestCreateImplementationBlockerApprovalBlocksJobAtomically`，用 SQLite trigger 证明 job block 失败时 approval 和 approval events 完整回滚；成功路径原子进入 blocked。
  - Round 1 Review 红灯新增 `TestCreateImplementationBlockerApprovalKeepsDifferentJobsSeparate`：同一 requirement 的第二个 blocker 原先错误复用第一个 job 的 pending approval；pending lookup 改为 requirement+job+run scope 后，两个 source job 各自拥有 approval 并分别 blocked。
- Review 记录：
  - Round 1 独立 Review 文档：`docs/ai-native-review-step-13-automatic-implementation-blocker.md`；发现 blocker pending approval 只按 requirement 去重，结论为 Changes required。
  - Round 2 独立 Review 文档：`docs/ai-native-review-step-13-automatic-implementation-blocker-round-2.md`；复核修复、完整批次和兼容路径，结论为 Approved with no findings。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/store -run TestCreateImplementationBlockerApprovalBlocksJobAtomically -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run 'TestDaemonImplementationStepCreatesBlockerArtifactApprovalAndBlocksJob|TestDaemonImplementationStepFixCanCreateImplementationBlocker' -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -race -count=1 ./internal/store ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check` 和 Markdown fence 检查。
- 当前边界：
  - 本批次以 job structured result 为自动入口；provider stdout 的通用 `WORKSPACE_APPROVAL_REQUEST` 协议继续服务澄清和权限请求，不重复推断 blocker。

## Step 13: Replan development cycle isolation - Batch 9

- 日期：2026-07-10
- 状态：完成，重新规划后的开发作业和报告已与历史开发周期隔离
- 范围：
  - 首个 `implementation_plan` 继续使用兼容 key；当前终稿 technical design 与首个 plan input 不同时，创建绑定新 technical artifact ID 的 plan job。
  - 第二个及后续 implementation plan artifact 使用 `-p<plan-artifact-id>` cycle suffix，隔离 step、step Review、fix、re-review 和 report job key。
  - step Review 轮次按 `implementation_plan_artifact_id + step_index` 统计，旧周期 Review 不消耗新周期门槛。
  - implementation report 选择最新 plan artifact，并只聚合该 plan 的 step 和 Review；旧周期未完成或已完成作业均不阻塞、不污染新报告。
  - queued stale development job 在 claim 前取消；claim 后和 provider 启动前再次复核，关闭 scan/claim TOCTOU 窗口。
  - development provider 运行期间定期复核 current cycle，replan 或终稿切换后通过 context cancellation 停止旧 Agent；superseded job 不失败、不重试、不计完成。
  - plan/report success post-processing 和 FinishRequirement 前保留 current-cycle gate，防止运行结束边界上的迟到结果。
  - 首周期不带 suffix 的既有 key 和行为保持兼容。
- TDD 记录：
  - 新增 `TestDaemonImplementationReplanCreatesIsolatedDevelopmentCycle`，预置完整旧周期、定稿 requirement/technical design v2，再执行新 plan、step、Review、fix、re-review 和 report 流程。
  - 红灯：已有 `implementation-plan-pay-flow` 使 coordinator 直接跳过，无法找到 `implementation-plan-pay-flow-technical-<artifact-id>`。
  - 绿灯：新 plan job 成功，所有下游 job 使用新 plan artifact suffix；新 report input 包含新 step key 且不包含旧 step key。
  - Review 红灯把旧 report 保持 queued，并模拟 stale running report success；claim 前取消和 success gate 落地后不再生成旧 report/review artifact。
  - Review 红灯创建 version 更高但 source plan 绑定旧 technical design 的迟到 artifact；current plan 追溯 source job 后，新 report 仍绑定新 plan artifact。
  - Review 红灯加入 malformed historical review artifact；轻量读取 plan ID 后先过滤历史周期，旧坏数据不再阻塞新 Review 轮次或报告。
  - Round 2 红灯 `TestDaemonCancelsDevelopmentJobWhenReplanStartsDuringProviderRun` 证明旧 provider 可在 replan 后到达模拟 workspace side effect；运行时 current-cycle monitor 和 context cancellation 落地后通过。
  - Round 3 红灯 `TestDaemonCancelsDevelopmentJobWhenReplanLandsAtProviderReturn` 覆盖 succeeded、failed、waiting 三种 monitor tick 前返回；统一 post-run gate 和显式 cancelled disposition 后全部通过且计数为零。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-13-replan-development-cycle.md`。
  - Round 2 独立 Review 文档：`docs/ai-native-review-step-13-replan-development-cycle-round-2.md`。
  - Round 3 独立 Review 文档：`docs/ai-native-review-step-13-replan-development-cycle-round-3.md`。
  - Round 4 独立 Review 文档：`docs/ai-native-review-step-13-replan-development-cycle-round-4.md`；结论为 Approved with no findings。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run 'TestDaemonImplementationReplanCreatesIsolatedDevelopmentCycle|TestDaemonCancelsDevelopmentJobWhenReplanStartsDuringProviderRun|TestDaemonCancelsDevelopmentJobWhenReplanLandsAtProviderReturn|TestDaemonRunOncePreparesDevelopmentWorkspaceAndCreatesImplementationPlanJob|TestDaemonRunOnceCreatesImplementationPlanArtifactAndStepJobs|TestDaemonRunOnceRunsImplementationStepInRequirementWorkspaceAndCreatesReviewJob|TestDaemonRunOnceCompletesImplementationStepReviewAndCreatesFixJobForHighRiskFindings|TestDaemonRunOnceRunsImplementationStepFixAndCreatesNextReviewRound|TestDaemonRunOnceCompletesImplementationStepReviewWithoutFixWhenPolicyPasses' -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -race -count=1 ./internal/coordinator -run 'TestDaemonCancelsDevelopmentJobWhenReplanStartsDuringProviderRun|TestDaemonImplementationReplanCreatesIsolatedDevelopmentCycle' -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check` 和 Markdown fence 检查。
- 当前边界：
  - cycle identity 当前由终稿 technical design artifact 和生成的 implementation plan artifact 派生，不新增 migration 或持久化 cycle 表。
  - blocker artifact/request 的自动创建入口仍按 Step 16 Batch 13 边界留给后续批次。

## Step 16: Implementation blocker typed response - Batch 13

- 日期：2026-07-10
- 状态：完成，`implementation_blocker` 的 continue/replan/block 决策和原子业务联动已落地
- 范围：
  - workspace service 在通用 approve/reject/cancel 校验前分派 `implementation_blocker` typed response。
  - top-level typed flags 和结构化 `response_json` 都只接受 `choice=continue|replan|block`；approve/reject/cancel/unknown 保持 approval pending。
  - continue 原子关闭 approval 并把原 blocked/waiting job 恢复为 queued。
  - block 原子关闭 approval 并保持原 job blocked。
  - replan 在 transaction 内重新校验 requirement 当前 assigned analysis Agent，并校验 enabled Agent/worker pool 绑定后，原子保持原 job blocked、创建 queued `analysis_revise` job、关闭 approval并写 response audit events。
  - replan job input 包含 requirement、原 blocker approval/job、blocker payload 和用户 decision，供分析 Agent 重做方案。
  - `ApprovalResponseView.NextJob` 向 MCP 返回新 analysis job；CLI 输出 `next-job:` 和新 job 摘要。
- TDD 记录：
  - 新增 `TestRespondImplementationBlockerApprovalChoices`，覆盖 continue、block 和结构化 replan。
  - 新增 `TestRespondImplementationBlockerApprovalRejectsUntypedChoices`，覆盖 approve/reject/cancel/unknown typed guard。
  - 新增 `TestRespondImplementationBlockerReplanRollsBackWhenWorkflowWriteFails`，覆盖 current-job/replan-job/approval/status-event/run-event 五个写点。
  - 红灯：continue/block/replan 均被通用 choice 校验拒绝，approve/reject/cancel 反而会错误关闭 blocker；rollback 测试无法到达业务写点。
  - 绿灯：typed service 和专用 store transaction 落地后所有 choice、guard 和五项完整回滚通过。
  - 新增 CLI `TestApprovalRespondImplementationBlockerReplanShowsNextJob`；红灯为 replan 已创建但 CLI 未显示 next job，补充输出后通过。
  - 新增 `TestMCPApprovalRespondImplementationBlockerReplanReturnsNextJob`，确认主 Agent 使用结构化 response 时可取得 replan job。
  - Review 红灯新增 `TestRespondImplementationBlockerReplanRejectsStaleAnalysisAssignment`：store 使用 service 事务前读取的旧 Agent 仍可创建 replan job；事务内复核 assignment 后通过。
  - Review 红灯新增 `TestAfterWorkerClaimMarksImplementationBlockerReplanAnalyzing`：`analysis_revise` claim 未计入 analysis job，也未推进 requirement；扩展 coordinator claim lifecycle 后通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-16-implementation-blocker.md`。
  - Round 2 独立 Review 文档：`docs/ai-native-review-step-16-implementation-blocker-round-2.md`。
  - Round 3 独立 Review 文档：`docs/ai-native-review-step-16-implementation-blocker-round-3.md`；结论为 Approved with no findings。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/workspace -run 'TestRespondImplementationBlockerApprovalChoices|TestRespondImplementationBlockerApprovalRejectsUntypedChoices|TestRespondImplementationBlockerReplanRollsBackWhenWorkflowWriteFails' -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli -run 'TestApprovalRespondImplementationBlockerReplanShowsNextJob|TestApprovalCommandsListShowAndRespondProviderPermission' -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/mcp -run 'TestMCPApprovalRespondImplementationBlockerReplanReturnsNextJob|TestMCPApprovalRespondAcceptsStructuredTestCommandWithoutTopLevelChoice' -v`
- 当前边界：
  - replan job 被 worker claim 时，既有 coordinator lifecycle 会把 requirement 推进到 analyzing；response transaction 本身不提前改变业务 workflow。
  - Coding Agent 仍需先通过 artifact/MCP 和 approval request protocol 记录 blocker artifact 与人工确认；自动从 coding result 推断 blocker 留给后续批次。
  - replan 分析重新定稿后，需要让新 implementation plan/step/report 与旧开发 cycle 的 job key 隔离；该完整重入闭环留给后续批次。
- 后续批次：
  - 审计无 job-scoped generic approval 调用方和 implementation blocker artifact/request 自动化入口。

## Step 16: Job-scoped approval response transaction - Batch 12

- 日期：2026-07-10
- 状态：完成，job-scoped approval 的业务联动和 response audit events 已原子提交
- 范围：
  - store 新增 `RespondJobScopedApproval` 专用事务，校验 pending approval、job/run/scope 和专用 approval transaction 边界。
  - requirement clarification approve 在同一事务内追加结构化 clarification response 到 job input，并把 waiting job 恢复为 queued。
  - provider permission approve 在同一事务内创建 active grant，并把 waiting/blocked/failed job 恢复为 queued。
  - reject/cancel 在同一事务内关闭 approval 并把关联 job 标记为 failed 或 cancelled。
  - requirement/release response status event 和 optional `approval_responded` run event 与 approval、job、grant 一起提交。
  - artifact finalization approve、test command missing 和 publish confirmation 继续走各自的专用事务。
- TDD 记录：
  - 新增 `TestRespondRequirementClarificationApprovalRollsBackWhenWorkflowWriteFails`，覆盖 job-input/job-state/status-event/run-event 四个失败写点。
  - 新增 `TestRespondProviderPermissionApprovalRollsBackWhenWorkflowWriteFails`，覆盖 grant/job-state/status-event/run-event 四个失败写点。
  - 红灯：八个故障注入路径都观察到 approval 已 approved，且部分路径已经修改 job input、创建 grant、恢复 job 或写入 run event。
  - 绿灯：专用事务落地后八个路径均保持 approval pending、job `waiting_user_input`、原 job input、无 grant，且只保留 request status/run events。
  - 原 clarification resume、provider permission grant、权限升级拒绝测试继续通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-16-job-scoped-response-transaction.md`。
  - Round 2 独立 Review 文档：`docs/ai-native-review-step-16-job-scoped-response-transaction-round-2.md`；结论为 Approved with no findings。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/workspace -run 'TestRespondApprovalRestoresWaitingJobAndWritesAuditEvents|TestRespondRequirementClarificationApprovalRollsBackWhenWorkflowWriteFails|TestRespondProviderPermissionApprovalCreatesGrantAndResumesJob|TestRespondProviderPermissionApprovalRollsBackWhenWorkflowWriteFails|TestRespondProviderPermissionApprovalRejectsPermissionEscalation' -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/workspace`
- 当前边界：
  - 无 job scope 的通用 approval response 仍使用基础 approval close 和后续 status event 写入；后续继续审计这类路径是否存在实际调用方。
- 后续批次：
  - 审计 implementation_blocker 的 `continue/replan/block` typed contract 和无 job-scoped approval response。

## Step 1: 文档和范围冻结

- 日期：2026-07-02
- 状态：完成
- 内容：
  - 新增 AINative 需求方案、技术实现方案和实施步骤三份文档。
  - README 和 GitHub Pages 首页增加 AINative 规划入口。
  - 多轮文档 review 后补齐实时可见性、人工确认、release test run、test command source、`active_test_run_id` 和发布确认状态线。
- 验证：
  - `git diff --check`
  - README/docs index 链接检查
  - Markdown fence 检查

## Step 2: SQLite migration 和 store 类型 - Batch 1

- 日期：2026-07-02
- 状态：完成，Step 2 整体仍在进行中
- 范围：
  - 新增 migration 常量 `MigrationAINativeWorkflow = "0003_ai_native_workflow"`。
  - 在 migration 链中追加 `0003_ai_native_workflow`。
  - 扩展 `requirements`：`description`、`workflow_status`、`analysis_agent_id`、`coding_agent_id`、`test_agent_id`、`analysis_final_artifact_id`、`technical_final_artifact_id`。
  - 扩展 `releases`：`workflow_status`、`test_agent_id`、`active_test_run_id`、`default_test_command`。
  - 创建 AINative V1 基础表：`agents`、`worker_pools`、`worker_instances`、`review_policies`、`artifacts`、`requirement_status_events`、`release_status_events`、`agent_jobs`、`agent_runs`、`agent_run_events`、`human_approval_requests`、`provider_permission_grants`、`requirement_bugs`、`release_test_runs`、`release_test_run_requirements`。
  - 创建关键唯一索引：artifact version、artifact final、run event sequence、release test run requirement snapshot。
  - 插入默认 review policies，并通过 `INSERT OR IGNORE` 保持重复 migration 幂等。
  - 增加第一批 store 类型：Agent、Worker pool、Worker instance、Review policy、Artifact、Agent job/run、Release test run 和 Release test run requirement。
- TDD 记录：
  - 先新增 `TestMigrateCreatesAINativeWorkflowSchemaAndDefaults`、`TestMigrateUpgradesLegacyDatabaseWithManualAINativeWorkflowStatus`、`TestAINativeSchemaConstraints`。
  - 红灯：测试因 `MigrationAINativeWorkflow` 和 `RequirementWorkflowStatusManualActive` 未定义而构建失败。
  - 绿灯：实现 migration 后 focused store 测试通过。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test ./internal/store -run 'TestMigrateCreatesAINativeWorkflowSchemaAndDefaults|TestMigrateUpgradesLegacyDatabaseWithManualAINativeWorkflowStatus|TestAINativeSchemaConstraints'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test ./internal/store`
- 后续批次：
  - 补齐剩余 store 类型和 CRUD 参数。
  - 增加 release test run summary artifact、provider permission grant、approval request 的 focused store/service 校验。
  - 开始实现 Step 3 artifact service 前，先补 store 层 artifact CRUD 的 TDD。

## Step 2: SQLite migration 和 store 类型 - Batch 2

- 日期：2026-07-02
- 状态：完成，Step 2 整体仍在进行中
- 范围：
  - 增加 store CRUD 参数和方法：`CreateAgent`、`GetAgentByName`、`CreateWorkerPool`、`CreateArtifact`、`GetArtifact`、`CreateReleaseTestRun`、`CreateReleaseTestRunRequirement`、`ListReleaseTestRunRequirements`、`CreateAgentJob`、`CreateHumanApprovalRequest`、`CreateProviderPermissionGrant`。
  - 增加缺失的 store 类型：`HumanApprovalRequest`、`ProviderPermissionGrant` 及对应 create params。
  - `CreateProviderPermissionGrant` 在 store 层拒绝空 `scope`、`sandbox`、`approval_policy`，避免 runner 后续读取到不完整授权。
  - Release test run snapshot CRUD 可以保存 `requirement + repo + commit` 快照，并按 test run 查询。
- TDD 记录：
  - 先新增 `TestAINativeStoreCreatesAgentWorkerPoolAndArtifact`、`TestAINativeStoreCreatesReleaseTestRunAndRequirementSnapshot`、`TestAINativeStoreRejectsInvalidProviderPermissionGrant`。
  - 红灯：测试因 `CreateAgent`、`CreateWorkerPool`、`CreateArtifact`、`CreateReleaseTestRun`、`CreateProviderPermissionGrant` 等方法和参数类型不存在而构建失败。
  - 绿灯：实现 store CRUD 和扫描 helper 后 focused store 测试通过。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test ./internal/store -run 'TestAINativeStoreCreatesAgentWorkerPoolAndArtifact|TestAINativeStoreCreatesReleaseTestRunAndRequirementSnapshot|TestAINativeStoreRejectsInvalidProviderPermissionGrant'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test ./internal/store`
- 后续批次：
  - 增加 artifact finalize、release test run summary artifact 同 run 校验和 provider grant active/used/expired 查询方法。
  - 增加 approval 去重和 response 事务语义。
  - 之后进入 Step 3 artifact service，把文件写入、hash、version、finalize 串起来。

## Step 2: SQLite migration 和 store 类型 - Batch 3

- 日期：2026-07-02
- 状态：完成，Step 2 整体仍在进行中
- 范围：
  - 增加 artifact 定稿 API：`FinalizeArtifact` 会按 `entity_type + entity_id + artifact_type` 清理旧终稿，再把目标 artifact 标记为终稿，保证同一类产物只有一个最终版本。
  - 增加 release test run 总结报告绑定 API：`SetReleaseTestRunSummaryArtifact` 只接受同一个 `release_test_run` 下的 `test_report` artifact，避免把开发报告、分析文档或其他 run 的报告误挂到集成测试结果上。
  - 增加 `GetReleaseTestRun`、`GetProviderPermissionGrant`、`GetActiveProviderPermissionGrant`、`MarkProviderPermissionGrantUsed`、`ExpireProviderPermissionGrants`，支撑 runner 在执行前获取有效授权、执行后消费授权、定期过期授权。
  - 增加 pending 人工确认去重：同一 `approval_type` 和同一业务作用域内再次创建确认请求时，更新原请求的标题、提示和 payload，并保留原 `approval_key`，避免用户实时界面出现重复待办。
  - 增加 `RespondHumanApproval` 和 `RespondHumanApprovalParams`，用户响应后写入 `status`、`response_json`、`responded_by`、`responded_at`，并只允许响应 pending 请求。
- TDD 记录：
  - 先新增 `TestAINativeStoreFinalizesArtifactsAndSetsReleaseTestRunSummary`、`TestAINativeStoreProviderPermissionGrantLifecycle`、`TestAINativeStoreDeduplicatesAndRespondsHumanApprovals`。
  - 红灯：测试因 `FinalizeArtifact`、`SetReleaseTestRunSummaryArtifact`、`GetActiveProviderPermissionGrant`、`RespondHumanApproval` 等方法和响应参数类型不存在而构建失败。
  - 绿灯：实现生命周期 API、审批去重和响应后，focused store 测试通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-02-store-lifecycle.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/store -run 'TestAINativeStoreFinalizesArtifactsAndSetsReleaseTestRunSummary|TestAINativeStoreProviderPermissionGrantLifecycle|TestAINativeStoreDeduplicatesAndRespondsHumanApprovals'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/store`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `git diff --check`
  - Markdown fence 计数检查
- 后续批次：
  - Step 3 artifact service 需要基于当前 store API 实现文件写入、hash、version 分配、终稿切换和报告入库。
  - 后续 runner/service 层需要把 `RespondHumanApproval` 与实时事件流连接起来，让用户能看到执行过程并处理澄清/授权请求。
  - Worker 调度层接入 provider permission grant 时，需要在进程启动前查询 active grant，在命令启动后立即标记 used。

## Step 3: Artifact service - Batch 1

- 日期：2026-07-02
- 状态：完成，Step 3 整体仍在进行中
- 范围：
  - `config.Config` 增加 `ArtifactDir`，默认路径为 `work/artifacts`；`config.Init` 创建该目录，`config.yaml` 写入并可读取 `artifacts_dir`。
  - 新增 `internal/artifact` 包，提供 `Service`、`CreateParams` 和 entity 常量：`requirement`、`release`、`release_test_run`。
  - `artifact.Service.Create` 支持按 entity 生成路径、写入 Markdown 内容、计算 sha256、按同一 `entity_type + entity_id + artifact_type` 分配递增 version，并写入 DB。
  - 路径规则已覆盖：
    - requirement：`work/artifacts/requirements/<req-slug>/<stage>/<artifact-type>-v<n>.md`
    - release：`work/artifacts/releases/<release-slug>/<stage>/<artifact-type>-v<n>.md`
    - release test run：`work/artifacts/releases/<release-slug>/test-runs/<test-run-id>/<artifact-type>-v<n>.md`
  - `artifact.Service.List/Get/Finalize` 会校验 artifact 所属 entity；`Finalize` 复用 store 事务保证同类 artifact 只有一个 final。
  - `artifact.Service.SetReleaseTestRunSummaryArtifact` 复用 store 校验，只允许同一个 test run 下的 `test_report` 作为 summary。
  - store 增加 `ListArtifacts`、`NextArtifactVersion`、`GetRequirementByID`、`GetReleaseByID`，供 artifact service 做 entity 校验和版本分配。
  - workspace service 增加通用 artifact 方法：`CreateArtifact`、`ListArtifacts`、`GetArtifact`、`FinalizeArtifact`。
  - workspace service 增加 requirement 便捷包装：`CreateRequirementArtifact`、`ListRequirementArtifacts`、`FinalizeRequirementArtifact`。
- TDD 记录：
  - 先新增 config、artifact service、workspace convenience focused 测试。
  - 红灯：测试因 `ArtifactDir`、`NewService`、`CreateParams`、entity 常量、workspace artifact wrapper 不存在而构建失败。
  - 绿灯：实现配置、artifact service、store 查询和 workspace wrapper 后 focused 测试通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-03-artifact-service.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/artifact ./internal/workspace -run Artifact`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/config ./internal/artifact ./internal/workspace -run 'Artifact|TestInitCreatesDefaultConfigAndDirectories'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/store -run 'TestAINativeStoreCreatesAgentWorkerPoolAndArtifact|TestAINativeStoreFinalizesArtifactsAndSetsReleaseTestRunSummary'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `git diff --check`
  - Markdown fence 计数检查
- 后续批次：
  - Step 3 Batch 2 需要补 CLI/MCP 前的 list/show 输出模型和 `workspace req artifact ...` 命令面。
  - 用户编辑 artifact 生成新版本、analysis finalization approval 同事务 finalize 两类 artifact，已在后续 Step 12 批次补齐。
  - 并行 worker 同时写同一类 artifact 时，当前版本分配依赖 DB 唯一约束兜底；后续 runner 并发接入前应补重试或更强事务封装。

## Step 3: Artifact service - Batch 2

- 日期：2026-07-02
- 状态：完成，Step 3 整体仍在进行中
- 范围：
  - Root command 增加通用 `workspace artifact` 命令组。
  - 新增 `workspace artifact list --entity-type <requirement|release|release_test_run> --entity-id <id>`，输出 artifact id、entity、type、version、final 状态和 path。
  - 新增 `workspace artifact show <artifact-id>`，输出 artifact 的 id、entity、type、stage、version、final、title、path、sha256、created-by。
  - `workspace req` 增加 `artifact` 子命令组。
  - 新增 `workspace req artifact list <req>`、`workspace req artifact show <req> <artifact-id>`、`workspace req artifact finalize <req> <artifact-id>`。
  - `req artifact show/finalize` 通过 workspace service 校验 artifact 必须属于该 requirement，不能拿其他需求的 artifact。
  - workspace service 增加 `GetArtifactByID`，用于通用 artifact show；需求侧 show/finalize 仍使用 entity 校验方法。
- TDD 记录：
  - 先新增 `TestArtifactCommandsListShowAndFinalizeRequirementArtifacts` 和 `TestReqArtifactShowRejectsArtifactFromAnotherRequirement`，并扩展 `TestRootCommandIncludesDocumentedCommandSurface`。
  - 红灯：测试因 root 缺少 `artifact` 命令而失败，`workspace artifact list` 返回 unknown command。
  - 绿灯：实现通用 artifact 命令和 req artifact 便捷命令后 focused CLI 测试通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-03-artifact-cli.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli -run 'TestRootCommandIncludesDocumentedCommandSurface|TestArtifactCommandsListShowAndFinalizeRequirementArtifacts'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli -run 'Artifact|TestRootCommandIncludesDocumentedCommandSurface'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `git diff --check`
  - Markdown fence 计数检查
- 后续批次：
  - 用户编辑 artifact 生成新版本的 CLI/service 入口已由 Step 12 Batch 6 的 `req artifact create` 补齐。
  - MCP artifact tools 已由 Step 9 Batch 7 落地，复用同一 service 和 entity 校验语义。
  - Agent 创建 artifact 仍应优先走 MCP/service；`req artifact create` 面向用户编辑分析方案后的手动新版本。

## Step 4: Agent 配置命令 - Batch 1

- 日期：2026-07-02
- 状态：完成，Step 4 整体仍在进行中
- 范围：
  - 新增 `workspace agent` 命令组。
  - 新增 `workspace agent add <name>`，支持 `--provider`、`--role`、`--model`、`--system-prompt`、`--system-prompt-file`、`--sandbox`、`--approval-policy`、`--command`、`--metadata-json`、`--disabled`。
  - 新增 `workspace agent list`、`workspace agent show <name>`、`workspace agent update <name>`、`workspace agent remove <name>`、`workspace agent health <name>`。
  - provider 仅允许 `codex`、`claude`；role 仅允许 `coordinator`、`analysis`、`coding`、`testing`。
  - health check 使用 agent 配置的 `command` 执行 `--help`；失败时写回 `health_status=unavailable` 和错误消息，不删除配置。
  - agent 被 worker pool 引用时，`remove` 会拒绝删除。
  - store 增加 agent list/update/delete/health update 和 worker pool 引用检查。
  - docs 首页命令列表增加 AINative Agent 命令入口。
- TDD 记录：
  - 先新增 `TestAgentCommandsAddListShowUpdateAndRemove`、`TestAgentAddRejectsInvalidProviderAndRole`、`TestAgentHealthMarksUnavailable`、`TestAgentRemoveRejectsWorkerPoolReference`，并扩展 `TestRootCommandIncludesDocumentedCommandSurface`。
  - 红灯：测试因 root 缺少 `agent` 命令而失败。
  - 绿灯：实现 store CRUD、workspace service 校验和 CLI 命令面后 focused CLI 测试通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-04-agent-config.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli -run 'TestRootCommandIncludesDocumentedCommandSurface|TestAgent'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli ./internal/workspace -run Agent`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `git diff --check`
  - Markdown fence 计数检查
- 后续批次：
  - Step 4 后续可补 store/service 层更细的 agent update/remove 单元测试，以及 provider command builder 的真实 Codex/Claude 参数策略。
  - Step 5 需要实现 worker pool 命令，复用本批 agent 引用保护逻辑。
  - daemon/coordinator 接入前，需要把默认主 Agent 配置和 worker pool 调度配置连接起来。

## Step 5: Worker pool 命令 - Batch 1

- 日期：2026-07-02
- 状态：完成，Step 5 整体仍在进行中
- 范围：
  - 新增 `workspace worker` 命令组。
  - 新增 `workspace worker add <name> --role analysis|coding|testing --agent <agent>`，支持 `--parallelism`、`--max-workers`、`--poll-interval-ms`、`--lease-seconds`。
  - 新增 `worker list/show/update/enable/disable`。
  - worker role 只允许 `analysis`、`coding`、`testing`；不允许普通 worker pool 处理 `coordinator`。
  - 校验 `parallelism > 0`、`max_workers > 0`、`parallelism <= max_workers`、`poll_interval_ms > 0`、`lease_seconds > 0`。
  - 校验 worker pool 绑定的 agent 存在，且 agent role 必须和 worker role 一致。
  - `worker show` 展示 active job 数和 live worker instance 数；当前 active job 统计 `leased/running` job，live worker 统计 `starting/idle/running/stopping` instance。
  - store 增加 worker pool list/get/update 和 active/live 计数方法。
  - docs 首页命令列表增加 AINative Worker 命令入口。
- TDD 记录：
  - 先新增 `TestWorkerCommandsAddListShowUpdateEnableAndDisable`、`TestWorkerAddRejectsMissingAgentAndInvalidCapacity`，并扩展 `TestRootCommandIncludesDocumentedCommandSurface`。
  - 红灯：测试因 root 缺少 `worker` 命令而失败。
  - 绿灯：实现 store、workspace service 和 CLI 命令面后 focused CLI 测试通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-05-worker-pool.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli -run 'TestRootCommandIncludesDocumentedCommandSurface|TestWorker'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli ./internal/workspace -run Worker`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `git diff --check`
  - Markdown fence 计数检查
- 后续批次：
  - Step 5 后续可补 `worker remove` 或更明确的引用清理策略；当前只实现 enable/disable。
  - Step 6 job queue 需要复用 worker pool 的 active/live 计数，真正 claim 前还需要 lease 和 worker instance heartbeat 逻辑。
  - daemon 接入时需要让 `max_workers` 控制 live worker instance，`parallelism` 控制 active job claim。

## Step 6: Job queue 和 run 记录 - Batch 1

- 日期：2026-07-02
- 状态：完成，Step 6 整体仍在进行中
- 范围：
  - store 增加 `GetAgentJob`、`ClaimAgentJob`、`RecoverExpiredJobs`、`StartAgentJob`、`CompleteAgentJob`、`FailAgentJob`、`RetryAgentJob`、`CancelAgentJob`。
  - `ClaimAgentJob` 在事务中按 `role + worker_pool_id` 原子领取 `queued` job，写入 lease owner、lease expiry，并递增 attempts。
  - `RecoverExpiredJobs` 会把未达到最大 attempts 的过期 `leased/running` job 恢复为 `queued`，把已达到最大 attempts 的过期 job 标记为 `failed`。
  - job 状态流转会清理互斥字段：进入 `running` 清理旧 terminal 时间戳，进入 `succeeded/failed` 清理相反 terminal 字段，retry 回 `queued` 时清理 lease 和运行/终态时间戳。
  - store 增加 `CreateAgentRun`、`CompleteAgentRun`、`AppendAgentRunEvent`、`ListRunEventsAfter`、`ListJobEventsAfter`。
  - `AppendAgentRunEvent` 在事务中为同一 run 生成连续的 `event_seq`，调用方不传入序号。
  - `ListRunEventsAfter` 使用 run 内 `event_seq` 游标；`ListJobEventsAfter` 使用全局 event id 游标，避免 job 重试后新 run 的 `event_seq` 从 1 开始导致 watch 漏事件。
- TDD 记录：
  - 先新增 `TestAINativeStoreClaimsAndRecoversAgentJobs` 和 `TestAINativeStoreRunsAndEventsLifecycle`。
  - 红灯：测试因 `ClaimAgentJob`、`RecoverExpiredJobs`、`GetAgentJob`、`CancelAgentJob`、`CreateAgentRun`、`AppendAgentRunEvent` 等 API 不存在而构建失败。
  - 新增 `TestAINativeStoreAgentJobStatusTransitions` 覆盖 start/fail/retry/complete 状态机。
  - 红灯：retry 后 job 仍残留 `started_at` 和 `failed_at`，随后修复为 retry 清理运行和终态时间戳。
  - 新增多 run job event cursor 场景。
  - 红灯：job 级事件列表仍使用 run 内 `event_seq` 语义，随后修复为全局 event id 游标。
  - 绿灯：实现 job 生命周期、run 生命周期和 event append/list 后 focused store 测试通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-06-job-run-store.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/store -run 'TestAINativeStoreClaimsAndRecoversAgentJobs|TestAINativeStoreAgentJobStatusTransitions|TestAINativeStoreRunsAndEventsLifecycle'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/store ./internal/workspace -run 'Job|Lease|Run'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/store`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `git diff --check`
  - Markdown fence 计数检查
- 后续批次：
  - Step 6 后续需要补 service/CLI/MCP 的 job list/show/cancel/retry/watch 命令面。
  - Step 6 后续需要把 `ClaimAgentJob` 和 worker pool `parallelism/max_workers`、worker instance heartbeat 组合成真实 claim gate。
  - Step 8 runner 接入时需要把 provider stdout/stderr 通过 `AppendAgentRunEvent` 流式写入，并在等待人工输入时写 `approval_requested` event。

## Step 6: Job service/CLI 和 watch - Batch 2

- 日期：2026-07-02
- 状态：完成，Step 6 整体仍在进行中
- 范围：
  - store 增加 `GetAgentJobByKey`、`ListAgentJobs`、`ListAgentRunsForJob`，支持按 `status`、`role` 筛选 job，并让 job show 可以读取关联 run。
  - workspace service 增加 `ListJobs`、`GetJob`、`WatchJobEvents`、`CancelJob`、`RetryJob`。
  - CLI 新增 `workspace job` 命令组。
  - 新增 `workspace job list [--status <status>] [--role <role>]`，展示 job key、role、type、status 和 attempts。
  - 新增 `workspace job show <job-key>`，展示 attempts、lease owner、lease expiry、last error、latest run status 和 stdout/stderr/output JSON path。
  - 新增 `workspace job watch <job-key> [--after-event <id>] [--follow]`，默认拉取一次事件；`--follow` 每 2 秒轮询新增 event。
  - `job watch` 输出 `event_id`、`event_type`、`visibility`、`severity`、`message`，让用户能区分 user/debug 可见性和 severity。
  - 新增 `workspace job cancel <job-key> --reason <text>` 和 `workspace job retry <job-key>`。
  - README 和 docs 首页增加 job watch/job 命令入口。
- TDD 记录：
  - 先扩展 `TestRootCommandIncludesDocumentedCommandSurface`，并新增 `TestJobCommandsListShowWatchCancelAndRetry`。
  - 红灯：测试因 root 缺少 `job` 命令而失败。
  - 绿灯前修正一次 watch 输出：原先只打印 severity，无法体现 debug/user 可见性；改为同时打印 visibility 和 severity。
  - 绿灯：实现 store 查询、workspace wrapper 和 CLI 命令面后 focused CLI 测试通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-06-job-cli-watch.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli -run 'TestRootCommandIncludesDocumentedCommandSurface|TestJobCommandsListShowWatchCancelAndRetry'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli ./internal/workspace -run Job`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `git diff --check`
  - Markdown fence 计数检查
- 后续批次：
  - Step 6 仍需补 MCP `job_watch/run_tail`，让主 Agent 能通过工具读取同一事件流。
  - Step 6 仍需补 worker instance heartbeat 和基于 `parallelism/max_workers` 的 claim gate。
  - Step 8 runner 接入后需要把真实 provider stdout/stderr 持续写入 `agent_run_events`，此时 `job watch --follow` 才有实时滚动输出源。

## Step 6: Run event artifact scope - Batch 3

- 日期：2026-07-10
- 状态：完成，`agent_run_events.artifact_id` 归属校验已落地
- 范围：
  - `AppendAgentRunEvent` 在事务中根据显式 scope 或 job scope 校验 `artifact_id`。
  - requirement artifact 必须属于同一 `requirement_id`。
  - release artifact 必须属于同一 `release_id`。
  - release test run artifact 必须属于同一 release scope。
  - 缺失 artifact 或 unsupported entity type 会拒绝写入 event。
- TDD 记录：
  - 新增 `TestAINativeStoreValidatesRunEventArtifactScope`。
  - 红灯：requirement scoped run event 可以引用另一个 requirement 的 artifact。
  - 绿灯：增加 artifact scope 校验后 focused test 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-06-run-event-artifact-scope.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/store -run TestAINativeStoreValidatesRunEventArtifactScope -v`
- 当前边界：
  - 本批只校验 event 引用 artifact 的归属；artifact 创建权限仍由 artifact service 和 MCP capability scope 负责。

## Step 6: Human approval scope validation - Batch 4

- 日期：2026-07-10
- 状态：完成，`human_approval_requests` 创建 scope 校验已落地
- 范围：
  - `CreateHumanApprovalRequest` 新增 type-specific scope validation：需求类 approval 必须有 requirement scope，测试命令缺失必须有 release test run scope，发布确认必须有 release + release test run scope，provider permission 必须有 job scope。
  - 创建 approval 时会从 `run_id` 补齐 `job_id`，从 `job_id` 补齐 requirement/release scope，从 `release_test_run_id` 补齐 release scope。
  - 显式传入的 `job_id/run_id`、`requirement_id/job_id`、`release_id/job_id`、`release_id/release_test_run_id` 互相矛盾时拒绝创建。
  - pending approval 去重改为按 approval type 固定业务 scope，避免 provider permission 带 requirement scope 时跨 job 误去重。
- TDD 记录：
  - 新增 `TestAINativeStoreValidatesHumanApprovalScopeByType`。
  - 红灯：known approval type 缺少业务 scope 仍能创建，且从 job/run 创建时不会自动补齐 scope。
  - 绿灯：增加 scope normalization、type-specific validation 和 type-specific pending dedupe 后 focused test 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-06-human-approval-scope.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/store -run TestAINativeStoreValidatesHumanApprovalScopeByType -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/store`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/store ./internal/workspace ./internal/agent ./internal/coordinator ./internal/mcp ./internal/cli`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md` and `README.md`
- 当前边界：
  - 本批收紧 approval 创建 scope；用户响应后的 typed payload 校验仍由 workspace service 的 response handler 负责。

## Step 7: Provider runner - Batch 1

- 日期：2026-07-02
- 状态：完成，Step 7 整体仍在进行中
- 范围：
  - config 增加 `RuntimeDir`，默认 `work/runtime`，`init` 时创建目录，`config.yaml` 写入 `runtime_dir`。
  - 新增 `internal/agent/provider.go`，定义 `ProviderRunner`、`RunRequest`、`RunResult`、`CommandSpec`。
  - 新增 `CodexRunner.BuildCommand`，最初生成 `codex exec --json --cd <cwd> --sandbox workspace-write ... <prompt>` 参数；Step 18 Batch 2 已修正为 `-c approval_policy=...`、`--output-last-message` 和 `-c mcp_servers.workspace_cli.*`。
  - Codex runner 生成 job-scoped `work/runtime/mcp/<job-key>/codex/config.toml`，设置 `[mcp_servers.workspace_cli]`，不使用 `--mcp-config`；Step 18 Batch 2 已修正为保留用户默认 `CODEX_HOME`，不再把该目录写入 provider 环境变量。
  - 新增 `ClaudeRunner.BuildCommand`，生成 `claude -p --output-format stream-json --mcp-config <path> --permission-mode acceptEdits <prompt>` 参数。
  - Claude runner 生成 job-scoped `work/runtime/mcp/<job-key>/claude/mcp-config.json`，不设置 `CODEX_HOME`。
  - command builder 会创建 `work/runtime/jobs/<job-key>/<attempt>/`，并返回 `stdout.jsonl`、`stderr.log`、`output.json` 路径。
  - 新增 `FakeRunner`，用于 daemon/watch/workflow 测试：启动 job、创建 run、写 `run_started`、写 fake event、写 `run_completed`，并把 run/job 标记为 succeeded 或 failed。
- TDD 记录：
  - 先扩展 config 测试期待 `RuntimeDir`。
  - 新增 `TestCodexRunnerBuildsCommandAndMCPConfig`、`TestClaudeRunnerBuildsCommandAndMCPConfig`、`TestFakeRunnerWritesRunEventsAndCompletesJob`、`TestFakeRunnerFailureMarksRunAndJobFailed`。
  - 红灯：测试因 `RuntimeDir`、`RunRequest`、`CodexRunner`、`ClaudeRunner`、`FakeRunner` 等类型和方法不存在而构建失败。
  - 绿灯：实现 config runtime 目录、provider command builder 和 fake runner 后 focused agent/config 测试通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-07-provider-runner.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/config ./internal/agent -run 'TestInitCreatesDefaultConfigAndDirectories|TestCodexRunnerBuildsCommandAndMCPConfig|TestClaudeRunnerBuildsCommandAndMCPConfig|TestFakeRunner'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/agent ./internal/config`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `git diff --check`
  - Markdown fence 计数检查
- 后续批次：
  - Step 7 后续需要实现真实 provider 进程启动、stdout/stderr 流式读取、secret redaction 和 event offset payload。
  - Step 7 后续需要接入 active `provider_permission_grants`，在 grant 有效且 scope 匹配时覆盖 sandbox/approval policy，并标记 grant used。
  - Step 7 后续需要处理 provider 触发的澄清/人工确认：创建 approval、写 `approval_requested` event，并把 job 标记为 `waiting_user_input`。

## Step 7: Provider process runner - Batch 2

- 日期：2026-07-02
- 状态：完成，Step 7 整体仍在进行中
- 范围：
  - 新增 `ProcessRunner`，接收任意 `ProviderRunner` command builder，启动真实本地进程。
  - `ProcessRunner` 会先把 job 从 leased 推进到 running，创建 `agent_runs`，写 `run_started` event。
  - 使用 stdout/stderr pipe 读取 provider 输出，原始 stdout 写入 `stdout.jsonl`，原始 stderr 写入 `stderr.log`。
  - stdout/stderr 每行都会写入 `agent_run_events.event_type=provider_output`，并记录 stream payload；DB event message 会做基础 secret redaction。
  - redaction 当前覆盖包含 `API_KEY`、`TOKEN`、`SECRET` 且形如 `KEY=value` 的 token，避免 job watch 泄露常见密钥值。
  - 进程 exit code 为 0 时，run/job 标记为 succeeded；非 0 时，run/job 标记为 failed，last error 保存 exit status。
  - provider 二进制启动失败时，也会写 `run_completed` error event，并把 run/job 收敛为 failed，避免 job 长时间停在 running。
- TDD 记录：
  - 新增 `TestProcessRunnerStreamsRedactedOutputAndCompletesJob`，使用临时 shell 脚本输出 stdout、stderr 和伪 secret。
  - 新增 `TestProcessRunnerNonZeroExitFailsRunAndJob`，验证非零退出会同步 run/job failed。
  - 红灯：测试因 `ProcessRunner` 不存在而构建失败。
  - 绿灯：实现 process runner、stream scanner、runtime 文件写入、event redaction 和退出码处理后 ProcessRunner focused 测试通过。
  - 新增 `TestProcessRunnerStartFailureFailsRunAndJob`。
  - 红灯：provider 启动失败会返回空 result，且 job/run 未收敛。
  - 绿灯：补 `failStartedRun`，启动失败也写 failed run/job。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-07-process-runner.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/agent -run 'TestProcessRunner'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/agent`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `git diff --check`
  - Markdown fence 计数检查
- 后续批次：
  - Step 7 仍需把 active `provider_permission_grants` 接入 command builder/request，使用有效 grant 覆盖 sandbox/approval policy 并标记 used。
  - Step 7 仍需把 provider 输出中的澄清/确认协议转成 `human_approval_requests` 和 `approval_requested` event。
  - Step 16 的 `run tail --raw` 需要基于本批生成的 stdout/stderr 文件实现 raw tail 和更完整的 redaction 策略。

## Step 7: Provider permission grant - Batch 3

- 日期：2026-07-02
- 状态：完成，Step 7 整体仍在进行中
- 范围：
  - `RunRequest` 增加 `PermissionScope`，用于表达本次 provider 启动需要的权限范围。
  - `ProcessRunner` 启动前调用 `ExpireProviderPermissionGrants`，避免过期 grant 被继续使用。
  - `ProcessRunner` 读取同一 job 的 active provider permission grant；只有 grant scope 覆盖本次 `PermissionScope` 时，才把 grant 的 `sandbox` 和 `approval_policy` 写入 `RunRequest`。
  - 有效 grant 被应用到 command builder 后立即标记 `used`，并写 `used_at`。
  - scope mismatch 的 grant 不提升权限、不标记 used，保持 active，等待后续正确 scope 或重新授权。
  - 过期 grant 会被标记 expired，不提升权限、不标记 used。
  - `ClaudeRunner.BuildCommand` 支持使用 `RunRequest.ApprovalPolicy` 覆盖 `--permission-mode`，默认仍为 `acceptEdits`。
- TDD 记录：
  - 新增 `TestClaudeRunnerUsesApprovalPolicyAsPermissionMode`。
  - 新增 `TestProcessRunnerAppliesActiveProviderPermissionGrantAndMarksUsed`。
  - 新增 `TestProcessRunnerDoesNotApplyExpiredOrMismatchedProviderPermissionGrant`。
  - 红灯：测试因 `PermissionScope`、grant 应用逻辑和 `containsArgSequence` 不存在而构建失败。
  - 绿灯：实现 grant 应用、scope 覆盖、过期处理、used 标记和 Claude permission mode 覆盖后 focused agent 测试通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-07-provider-permission-grant.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/agent -run 'TestClaudeRunnerUsesApprovalPolicyAsPermissionMode|TestProcessRunnerAppliesActiveProviderPermissionGrantAndMarksUsed|TestProcessRunnerDoesNotApplyExpiredOrMismatchedProviderPermissionGrant'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/agent`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `git diff --check`
  - Markdown fence 计数检查
- 后续批次：
  - Step 7 仍需把 provider 输出中的澄清/确认协议转成 `human_approval_requests` 和 `approval_requested` event。
  - Step 7/11 后续需要通过 MCP capability token 区分 worker/coordinator 权限，防止 worker 自行代表用户 respond approval。
  - JSON、URL query、Bearer token 和 capability token flag 脱敏已由 Step 16 Batch 7 补齐。

## Step 7: Provider approval request - Batch 4

- 日期：2026-07-02
- 状态：完成，Step 7 整体仍在进行中
- 范围：
  - 新增 provider 输出控制协议：stdout/stderr 任一行以 `WORKSPACE_APPROVAL_REQUEST ` 开头并跟随 JSON payload 时，视为人工确认请求。
  - 控制行仍按原 provider 输出路径写入 raw stdout/stderr 文件，并作为脱敏后的 `provider_output` event 记录，保证用户实时 watch 能看到 agent 执行上下文。
  - `ProcessRunner` 识别首个有效确认请求后，创建 pending `human_approval_requests`，approval 默认绑定 job/run，并继承 job 的 requirement/release scope。
  - 支持 provider 显式传入 `requirement_id`、`release_id`、`release_test_run_id` 覆盖或补充 approval scope。
  - 新增 `approval_requested` event，visibility 为 user，payload 包含 `approval_key` 和 `approval_type`，供 `job watch`、后续 `req watch`、MCP watch 工具实时展示。
  - run 完成时若存在 pending approval，run/job 状态收敛为 `waiting_user_input`，job lease 被释放，且不进入 succeeded/failed，也不触发自动 retry。
  - Store 新增 `WaitAgentJobForUserInput`，用于把 running job 原子更新为 `waiting_user_input` 并清理 lease/terminal timestamps。
  - approval `payload`/`options` 支持原生 JSON；`payload_json`/`options_json` 支持 JSON 字符串，并校验字符串内容仍为合法 JSON。
- TDD 记录：
  - 先扩展 `TestAINativeStoreAgentJobStatusTransitions`，期待 `WaitAgentJobForUserInput` 清理 lease 并保持非终态。
  - 红灯：store 测试因 `WaitAgentJobForUserInput` 不存在而构建失败。
  - 新增 `TestProcessRunnerApprovalRequestCreatesPendingApprovalAndWaitsForUser`，使用临时 provider 脚本输出 `WORKSPACE_APPROVAL_REQUEST` 控制行。
  - 红灯：provider 测试中 run/job 仍然进入 succeeded，未创建 pending approval。
  - 绿灯：实现 store waiting 状态、provider 控制行解析、approval 创建、`approval_requested` event 和 run/job waiting 收敛后 focused 测试通过。
  - 新增 `TestApprovalRawJSONRejectsInvalidQuotedJSON`，红灯暴露 quoted `payload_json` 未校验内容是否为 JSON；补校验后转绿。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-07-provider-approval-request.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test ./internal/store -run TestAINativeStoreAgentJobStatusTransitions`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test ./internal/agent -run 'TestProcessRunnerApprovalRequestCreatesPendingApprovalAndWaitsForUser|TestApprovalRawJSONRejectsInvalidQuotedJSON'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/agent ./internal/store`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fence balance check
- 后续批次：
  - Step 7 后续需要把 daemon/worker 调度接到 `ProcessRunner`，让真实 Codex/Claude job 从 worker pool 自动启动。
  - Step 11/16 后续需要补用户 respond approval 后恢复 job queued、取消 job 或继续 workflow 的服务层闭环。
  - Step 16 后续需要把 pending approvals 聚合进 `req watch`、`release watch` 和 MCP watch 工具。

## Step 10: AI main agent start - Batch 1

- 日期：2026-07-09
- 状态：完成，`workspace ai start` 第一版交互启动入口已落地
- 范围：
  - 新增 CLI `workspace ai start [--agent <name>]`。
  - 默认读取 `agent_default_main_agent`，显式 `--agent` 可覆盖。
  - 启动前校验主 Agent 存在、enabled、role=`coordinator`，并通过 provider command `--help` health check。
  - 生成 coordinator capability token，并写入 session-scoped Codex/Claude MCP 配置。
  - Codex session 生成 session-scoped `config.toml`，配置 `[mcp_servers.workspace_cli]` 指向当前 workspace binary 的 `mcp serve --home <home> --capability-token <token>`；Step 18 Batch 2 已修正为通过 `-c mcp_servers.workspace_cli.*` 注入并保留用户默认 `CODEX_HOME`。
  - 注入 `WORKSPACE_CLI_HOME` 和 `WORKSPACE_CLI_BIN` 环境变量。
  - 生成主 Agent prompt，明确实时查看工具、artifact 工具、release test 状态、bug_create、release_publish 前确认、pending approval 展示和用户明确确认后才能 `approval_respond`。
  - Claude session 生成 `mcp-config.json` 并传入 `--append-system-prompt-file`。
- TDD 记录：
  - 扩展 `TestRootCommandIncludesDocumentedCommandSurface`，要求 `ai` 和 `ai start` 存在。
  - 新增 `TestAIStartCodexBuildsMCPConfigAndPrompt`，用 fake codex command 捕获参数、环境变量、MCP config 和 prompt 文件，覆盖实时查看、artifact、bug 记录、发布确认和 approval 规则。
  - 新增 `TestAIStartRequiresConfiguredMainAgent`。
  - 新增 `TestAIStartRejectsUnavailableMainAgent`。
  - 红灯：`workspace ai` command 不存在，`ai start` 返回 unknown command。
  - 绿灯：新增 main session builder、service 校验和 CLI `ai start` 后 focused tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-10-ai-start.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli -run 'TestAIStart|TestRootCommandIncludesDocumentedCommandSurface'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/agent ./internal/cli ./internal/workspace -run 'TestAIStart|TestRootCommandIncludesDocumentedCommandSurface|TestCodexRunnerBuildsCommandAndMCPConfig|TestClaudeRunnerBuildsCommandAndMCPConfig'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/config ./internal/store ./internal/workspace ./internal/mcp ./internal/cli ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md`
- 当前边界：
  - Codex prompt 目前作为初始 prompt 传入，并同时写 session prompt 文件；后续可在 Codex CLI 暴露稳定 system-prompt flag 后切换。
  - `workspace ai start` 是用户交互入口，不创建 coordinator job；daemon coordinator lane 仍负责后台系统 job。
  - 自动化测试使用 fake command 验证参数和配置，不启动真实 Codex/Claude TUI。
- 后续批次：
  - Step 10 后续需要补真实 Codex/Claude smoke 或可跳过的手动验证脚本，确认 TUI 能读取 MCP 工具。
  - Step 10 主 Agent 会话审计已由 Batch 2 落地。
  - E2E 需要覆盖主 Agent 聊天提交需求、展示 approval、用户确认、coordinator relay respond、worker 继续执行。

## Step 10: Main agent session audit - Batch 2

- 日期：2026-07-09
- 状态：完成，主 Agent 会话审计和查询入口已落地
- 范围：
  - 新增 `0004_main_agent_sessions` migration，创建 `main_agent_sessions` 表。
  - `workspace ai start` 在启动主 Agent 前记录 agent、provider、workspace、runtime dir、prompt path、MCP config path、workspace binary 和 started_at。
  - 主 Agent 进程退出后，CLI 会更新会话状态为 `exited` 或 `failed`，并记录 exit code。
  - 新增 `workspace ai sessions [--limit N]`，查看最近主 Agent 会话审计记录。
  - 审计记录不保存 capability token，避免权限凭证落库。
- TDD 记录：
  - 扩展 `TestMigrateCreatesAINativeWorkflowSchemaAndDefaults`，要求创建 `main_agent_sessions` 并记录 `0004_main_agent_sessions`。
  - 扩展 `TestRootCommandIncludesDocumentedCommandSurface`，要求 `ai sessions` 存在。
  - 扩展 `TestAIStartCodexBuildsMCPConfigAndPrompt`，要求 `ai sessions` 输出 fake Codex 会话的 agent、provider、状态、prompt path 和 MCP config path。
  - 红灯：migration 缺少 `main_agent_sessions` 表，`workspace ai sessions` 只能显示 `workspace ai` help。
  - 绿灯：新增 store audit API、service 会话记录、CLI completion 更新和 `ai sessions` 查询后 focused tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-10-ai-session-audit.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/store ./internal/cli -run 'TestMigrateCreatesAINativeWorkflowSchemaAndDefaults|TestAIStart|TestRootCommandIncludesDocumentedCommandSurface'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/config ./internal/store ./internal/workspace ./internal/mcp ./internal/cli ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md` and `README.md`
- 当前边界：
  - 如果用户强制杀掉 `workspace ai start` 进程，审计记录可能停留在 `running`；后续可增加 stale session 标记或 heartbeat。
  - `ai sessions` 当前只展示最近 N 条会话，不提供清理命令。
- 后续批次：
  - Step 10/E2E 需要补真实 Codex/Claude smoke 或可跳过的手动验证脚本，确认 TUI 能读取 MCP 工具。
  - E2E 需要覆盖主 Agent 聊天提交需求、展示 approval、用户确认、coordinator relay respond、worker 继续执行。

## Step 11: Requirement CLI entry - Batch 1

- 日期：2026-07-09
- 状态：完成，用户 CLI 的需求提交、Agent 分配和开发 workspace 准备入口已落地
- 范围：
  - 新增 `workspace req submit <title>`。
  - `req submit` 支持 `--description`、`--description-file`、`--repo`、`--key`。
  - `req submit` 复用 `SubmitRequirement` service：创建 requirement，保存 description/repo scope，workflow 进入 `pending_acceptance`，但不创建 worktree。
  - 新增 `workspace req assign-agents <req>`，支持 `--analysis-agent`、`--coding-agent`、`--test-agent`，默认推进到 `pending_analysis`。
  - 新增 `workspace req prepare-workspace <req>`，复用 `PrepareRequirementWorkspace` 创建或复用干净 feature worktree。
  - `req list` 在原有字段后追加 AINative workflow 状态，`req show` 追加 workflow、Agent id、description 和 status event。
- TDD 记录：
  - 扩展 `TestRootCommandIncludesDocumentedCommandSurface`，要求 `req submit`、`req assign-agents`、`req prepare-workspace` 存在。
  - 新增 `TestReqSubmitAssignAgentsAndPrepareWorkspaceCLI`，覆盖提交、description-file、状态可见性、Agent 分配、worktree 延迟创建和幂等复用。
  - 新增 `TestReqSubmitRejectsConflictingDescriptionInputs`，覆盖 description 输入来源互斥。
  - 红灯：`req submit` command/flag 不存在，测试返回 unknown flag。
  - 绿灯：新增 CLI command、输出 helper、description-file 读取和 workflow 展示后 focused tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-11-cli-requirement.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli -run 'TestReqSubmit|TestRootCommandIncludesDocumentedCommandSurface'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/workspace ./internal/cli -run 'Submit|AssignAgents|PrepareRequirementWorkspace|WorkflowStatus|TestReqSubmit|TestRootCommandIncludesDocumentedCommandSurface'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/config ./internal/store ./internal/workspace ./internal/mcp ./internal/cli ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md` and `README.md`
- 当前边界：
  - `req assign-agents` 默认推进到 `pending_analysis`，可用 `--no-advance` 只绑定 Agent。
  - `req prepare-workspace` 只准备 worktree，不创建开发 job；开发 job 仍由 coordinator/daemon 流程负责。
  - `req list` 保持原有字段顺序并在 title 后追加 workflow，以降低现有脚本兼容风险。
- 后续批次：
  - Step 10/E2E 需要覆盖主 Agent 聊天提交需求、展示 approval、用户确认、coordinator relay respond、worker 继续执行。
  - Step 11/12 需要补 `pending_analysis` 后 coordinator lane 创建 analysis job 的端到端 fake provider 场景。

## Step 9: MCP release create tool - Batch 13

- 日期：2026-07-09
- 状态：完成，coordinator-only `release_create` 已落地；Step 9 文档列出的 MCP 工具矩阵已全部实现
- 范围：
  - MCP 注册 `release_create`。
  - `release_create` 复用 `CreateRelease` service，创建 draft release 并写入 release requirement membership。
  - `release_create` 支持 `title`、`key`、`requirements` / `requirement_keys` / `req` 和 `test_command` 参数。
  - store/service release create 参数新增 `DefaultTestCommand`，保存到 `releases.default_test_command`，供后续 release test 使用 `release_default` 来源。
  - CLI `workspace release create` 同步支持 `--test-command`，与 MCP 共享同一 service 字段。
  - worker token 仍不能调用 `release_create`；创建 release 只允许 coordinator token。
- TDD 记录：
  - 扩展 `TestMCPToolsListAndInvalidToken`，要求 tools/list 包含 `release_create`。
  - 新增 `TestMCPReleaseCreateToolCoordinatorOnly`，覆盖 worker 禁止、coordinator 创建、默认测试命令和 release membership。
  - 新增 `TestReleaseCreateStoresDefaultTestCommand`，覆盖 CLI `--test-command` 写入 `default_test_command`。
  - 红灯：MCP tools/list 缺少 `release_create`，`release_create` 返回 unknown tool，CLI `release create --test-command` 返回 unknown flag。
  - 绿灯：扩展 store/service release create 参数、注册 MCP tool、补 callTool dispatch、补 CLI flag 后 focused tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-09-mcp-release-create.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/mcp -run 'TestMCPReleaseCreate|TestMCPToolsList'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli -run 'TestReleaseCreateStoresDefaultTestCommand'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/mcp ./internal/cli -run 'TestMCP|TestReleaseCreateStoresDefaultTestCommand|TestRootCommandIncludesDocumentedCommandSurface'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/config ./internal/store ./internal/workspace ./internal/mcp ./internal/cli ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md`
- 当前边界：
  - `release_create` 只创建 draft release，不自动 integrate/test/publish。
  - 显式单次测试命令仍通过 `release_test_start test_command` 覆盖 release 默认命令。
  - Step 9 MCP 工具矩阵已完成；后续新增 MCP tool 需要先补权限矩阵和 tests。
- 后续批次：
  - Step 11 CLI 需求提交、Agent 分配和 workspace 准备入口已由 Step 11 Batch 1 落地。

## Step 9: MCP job management tools - Batch 12

- 日期：2026-07-09
- 状态：完成，MCP job 创建、列表、详情和 coordinator 管理更新入口已落地；MCP `release_create` 已由 Batch 13 落地，Step 9 工具矩阵已完成
- 范围：
  - MCP 注册 `job_create`、`job_list`、`job_show` 和 `job_update`。
  - workspace service 新增 `CreateJob` 包装，统一校验 `job_key`、`role`、`job_type`、`input_json` 和 requirement/release/agent 引用。
  - `ListJobs` 扩展 requirement/release 过滤字段，供 MCP job 列表按 scope 收窄。
  - `job_create` 支持 `input` object 或 `input_json` string，最终都通过 service 写入 `agent_jobs.input_json`。
  - worker `job_create` 按角色限制：analysis 只能创建 review job，coding 只能创建 fix job，testing 只能基于 scoped bug 创建 coding `bugfix` job。
  - `job_update` 只开放 coordinator-only 的 `cancel` 与 `retry` 受控动作，不提供任意 status 改写。
  - job scope 校验扩展到 release test run 和 bug，保证测试 Agent 可以实时查看自己发现 bug 对应的 bugfix job 执行过程。
- TDD 记录：
  - 扩展 `TestMCPToolsListAndInvalidToken`，要求 tools/list 包含 job 管理工具。
  - 新增 `TestMCPJobToolsCreateListShowAndUpdateScoped`，覆盖 scoped create/list/show、越权拒绝、worker update 拒绝、coordinator cancel，以及 testing scoped bugfix job 创建。
  - 红灯：MCP tools/list 缺少 job 管理工具，worker 调用 `job_create` 被 capability guard 拒绝。
  - 绿灯：新增 service 包装、注册 MCP tools、补 callTool dispatch 和 scope 校验后 focused tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-09-mcp-job-tools.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/mcp -run 'TestMCPJobTools|TestMCPToolsList'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/mcp ./internal/cli -run 'TestMCP|TestRootCommandIncludesDocumentedCommandSurface'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/config ./internal/store ./internal/workspace ./internal/mcp ./internal/cli ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md`
- 当前边界：
  - worker 只能通过受控角色/scope 创建 job；通用 job 调度仍由 coordinator 或 service 内部流程负责。
  - `job_update` 只支持 `cancel` 和 `retry`，worker job 完成、失败、阻塞、等待用户输入仍必须走 runner/service 受控路径。
  - Step 9 MCP 工具矩阵已完成。
- 后续批次：
  - Step 11/CLI 如需要用户手动调度 job，再补 `workspace job create`；当前 CLI 已有 list/show/watch/cancel/retry。

## Step 9: MCP requirement management tools - Batch 11

- 日期：2026-07-09
- 状态：完成，MCP requirement 提交、查询、Agent 分配、受控 workflow 推进和 workspace 准备入口已落地；MCP job 管理工具已由 Batch 12 落地，`release_create` 已由 Batch 13 落地，Step 9 工具矩阵已完成
- 范围：
  - MCP 注册 `req_submit`、`req_list`、`req_show`、`req_assign_agents`、`req_update_workflow_status` 和 `req_prepare_workspace`。
  - 新增 `SubmitRequirement` service 方法：创建 AINative requirement，保存 description 和 repo scope，进入 `pending_acceptance`，但不创建 feature worktree。
  - 新增 `AssignRequirementAgents` service 方法：校验 analysis/coding/testing Agent role，写入三类 Agent，并默认推进到 `pending_analysis`。
  - 新增 `RequirementView`，聚合 requirement、workflow、description、repo scope 和 status events，供 MCP list/show/submit/assign/update 返回结构化状态。
  - 新增 requirement status event store 方法；`SubmitRequirement`、`AssignRequirementAgents` 和 `UpdateRequirementWorkflowStatus` 会写 `requirement_status_events`。
  - `req_update_workflow_status` 只开放已有受控推进，进入 `pending_development` 仍必须满足分析终稿 guard。
  - `req_prepare_workspace` 只允许 coordinator 或 scoped coding token 调用，复用现有 workspace 准备 service。
- TDD 记录：
  - 扩展 `TestMCPToolsListAndInvalidToken`，要求 tools/list 包含 requirement 管理工具。
  - 新增 `TestMCPRequirementToolsSubmitListShowAssignUpdateAndPrepareScoped`，覆盖提交、列表过滤、详情 scope、分配权限、workflow guard 和 workspace 准备权限。
  - 红灯：MCP tools/list 缺少 requirement 管理工具，`req_submit` 返回 unknown tool。
  - 绿灯：新增 requirement service/store 能力、注册 MCP tools、补 callTool dispatch 和权限矩阵后 focused tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-09-mcp-requirement-tools.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/mcp -run 'TestMCPRequirementTools|TestMCPToolsList'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/store ./internal/workspace ./internal/mcp -run 'Requirement|MCP'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/mcp ./internal/cli -run 'TestMCP|TestRootCommandIncludesDocumentedCommandSurface'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/config ./internal/store ./internal/workspace ./internal/mcp ./internal/cli ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md`
- 当前边界：
  - `req_submit` 只记录 repo scope，不创建 worktree；开发前仍需 `req_prepare_workspace`。
  - `req_update_workflow_status` 不提供任意 workflow 改写，只通过 service guard 推进当前已实现的受控目标。
  - Step 9 MCP 工具矩阵已完成。
- 后续批次：
  - Step 11 CLI 需求提交、Agent 分配和 workspace 准备入口已由 Step 11 Batch 1 落地。

## Step 9: MCP release integrate/publish tools - Batch 10

- 日期：2026-07-09
- 状态：完成，MCP release integrate/publish 入口和权限矩阵已落地；MCP requirement 管理工具已由 Batch 11 落地，job 管理工具已由 Batch 12 落地，`release_create` 已由 Batch 13 落地，Step 9 工具矩阵已完成
- 范围：
  - MCP 注册 `release_integrate` 和 `release_publish`。
  - `release_integrate` 复用现有 `workspace.Service.IntegrateRelease`，testing token 只能操作自己 release scope 内的 release。
  - `release_publish` 复用现有 `workspace.Service.PublishRelease`，coordinator-only，并保留 `tested=true`、`publish_confirmation confirm=true`、release test run snapshot freshness、dirty guard 和 external commit guard。
  - role matrix 明确 analysis/coding 不能调用 release integrate/publish，testing 只能调用 scoped `release_integrate`，不能调用 `release_publish`。
- TDD 记录：
  - 扩展 `TestMCPToolsListAndInvalidToken`，要求 tools/list 包含 `release_integrate` 和 `release_publish`。
  - 新增 `TestMCPReleaseToolsIntegrateAndPublishScopedGuards`，覆盖 analysis forbidden、testing scoped integrate、testing publish forbidden、coordinator publish confirmation guard。
  - 红灯：MCP tools/list 缺少 release integrate/publish tools，testing token 调用 `release_integrate` 被 capability guard 拒绝。
  - 绿灯：注册 release integrate/publish tools、补 callTool dispatch、扩展 role matrix 后 focused tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-09-mcp-release-tools.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/mcp -run 'TestMCPReleaseTools|TestMCPToolsList'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/mcp ./internal/cli -run 'TestMCP|TestRootCommandIncludesDocumentedCommandSurface'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/config ./internal/mcp ./internal/cli ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md`
- 当前边界：
  - 本批次覆盖 release integrate/publish 的 MCP 入口；实际 git merge/push 行为仍由既有 workspace service 和 release integration/publish 测试覆盖。
  - `release_integrate` 要求 release scope 命中，不能只凭 release test run scope 集成整个 release。
  - `release_publish` coordinator-only，worker 只能通过 watch/status/approval 工具暴露状态，不能直接发布。
  - requirement 管理工具已由 Batch 11 落地；job 管理工具已由 Batch 12 落地；`release_create` 已由 Batch 13 落地。
- 后续批次：
  - Step 9 MCP 工具矩阵已完成。
  - Step 10 Batch 1 主 Agent prompt 已要求发布前展示 `release_status`/`release_watch` 和 pending `publish_confirmation`，用户确认后再调用 coordinator-only `release_publish`。

## Step 9: MCP release test tools - Batch 9

- 日期：2026-07-09
- 状态：完成，测试 Agent 可通过 MCP 启动和查询 release test run；MCP release integrate/publish 已由 Batch 10 落地，requirement/job/release_create 已由 Batch 11-13 落地，Step 9 工具矩阵已完成
- 范围：
  - MCP 注册 `release_test_start` 和 `release_test_status`。
  - workspace service 新增 `StartReleaseTest`，负责创建 release test run 并保存当前 release 的 requirement+repo+commit 快照。
  - `release_test_start` 支持 `test_command`，写入 `test_command_source=explicit`；未显式提供时按 release default、agent default、缺失命令顺序解析。
  - `release_test_status` 复用 `ReleaseWatchSnapshot`，返回 release workflow、test run、summary artifact、pending approval、open bug 和最近事件上下文。
  - testing token 持有 release scope 时可以调用 start/status；analysis/coding token 不能调用 release test tools。
- TDD 记录：
  - 扩展 `TestMCPToolsListAndInvalidToken`，要求 tools/list 包含 release test tools。
  - 新增 `TestMCPReleaseTestToolsStartAndStatusScoped`。
  - 红灯：MCP tools/list 缺少 release test tools，testing token 调用 `release_test_start` 被 capability guard 拒绝。
  - 绿灯：新增 `StartReleaseTest` service 方法、注册 release test tools、扩展 role matrix 和 release/test-run scope 校验后 focused tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-09-mcp-release-test.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/mcp -run 'TestMCPReleaseTest|TestMCPToolsList'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/mcp ./internal/cli -run 'TestMCP|TestRootCommandIncludesDocumentedCommandSurface'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/config ./internal/mcp ./internal/cli ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md`
- 当前边界：
  - 本批次只覆盖 MCP release test 工具；Step 9 完整工具矩阵已由 Batch 13 完成。
  - `release_test_start` 创建/排队 release test run 和快照；实际 release test job 创建仍由 coordinator daemon pending testing 扫描负责。
  - 无测试命令时 `release_test_start` 会创建 `waiting_user_input` test run；`test_command_missing` approval 仍由后续 daemon 扫描补齐。
  - CLI `workspace release test start/status` 已由 Step 14 Batch 9 落地，并复用 `StartReleaseTest`。
  - release integrate/publish 已由 Batch 10 落地；requirement 管理工具已由 Batch 11 落地；job 管理工具已由 Batch 12 落地；`release_create` 已由 Batch 13 落地。
- 后续批次：
  - Step 9 MCP 工具矩阵已完成。
  - Step 14 CLI `workspace release test start/status` 已由 Step 14 Batch 9 落地。
  - Step 10 Batch 1 主 Agent prompt 已要求通过 `release_test_status`、`release_watch` 和 `run_tail` 展示实时进度。

## Step 9: MCP bug tools - Batch 8

- 日期：2026-07-09
- 状态：完成，测试 Agent 可通过 MCP 在 scope 内创建、查询和关闭 bug；MCP release test 已由 Batch 9 落地，release integrate/publish 已由 Batch 10 落地，requirement/job/release_create 已由 Batch 11-13 落地，Step 9 工具矩阵已完成
- 范围：
  - MCP 注册 `bug_create`、`bug_list`、`bug_update`。
  - workspace service 新增 `CreateBug`、`ListBugs`、`GetBug`、`UpdateBug` 包装，MCP tool 不直接操作 store。
  - store 暴露 `GetRequirementBug`，供 service 和 MCP scope 校验读取单个 bug。
  - `bug_create` 校验 requirement、release 和 release test run 关系，保存 title、description、severity、file path、reproduction、release id 和 test run id。
  - `bug_create` 创建 open bug 后把 requirement workflow 推进到 `pending_development`。
  - `bug_list` 按 capability scope 过滤返回结果。
  - `bug_update` 当前支持将 scoped bug 标记为 fixed；analysis/coding token 不能调用，testing token 只能更新自己 scope 内的 bug。
- TDD 记录：
  - 扩展 `TestMCPToolsListAndInvalidToken`，要求 tools/list 包含 bug tools。
  - 新增 `TestMCPBugToolsCreateListAndUpdateScoped`。
  - 红灯：MCP tools/list 缺少 bug tools，testing token 调用 `bug_create` 被 capability guard 拒绝。
  - 绿灯：新增 service bug 包装、注册 bug tools、扩展 role matrix、实现 bug scope 校验和 update 语义后 focused tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-09-mcp-bug.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/mcp -run 'TestMCPBug|TestMCPToolsList'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/mcp ./internal/cli -run 'TestMCP|TestRootCommandIncludesDocumentedCommandSurface'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/config ./internal/mcp ./internal/cli ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md`
- 当前边界：
  - 本批次只覆盖 bug MCP 工具；Step 9 完整工具矩阵已由 Batch 13 完成。
  - `bug_update` V1 只支持关闭 bug 为 fixed；尚未支持编辑 bug 字段或 reopen。
  - `bug_create` 不自动创建 bugfix job；bugfix job 仍由 coordinator daemon 的 pending development / bugfix loop 负责。
  - release test tools 已由 Batch 9 落地；release integrate/publish 已由 Batch 10 落地；requirement 管理工具已由 Batch 11 落地；job 管理工具已由 Batch 12 落地；`release_create` 已由 Batch 13 落地。
- 后续批次：
  - Step 9 MCP 工具矩阵已完成。
  - Step 10 Batch 1 主 Agent prompt 已要求测试发现问题时优先调用 `bug_create`，修复验证后通过受控路径关闭 bug。

## Step 9: MCP artifact tools - Batch 7

- 日期：2026-07-09
- 状态：完成，Agent 可通过 MCP 在 scope 内创建、读取 artifact；MCP bug 已由 Batch 8 落地，release test 已由 Batch 9 落地，release integrate/publish 已由 Batch 10 落地，requirement/job/release_create 已由 Batch 11-13 落地，Step 9 工具矩阵已完成
- 范围：
  - MCP 注册 `artifact_create`、`artifact_list`、`artifact_show`、`artifact_finalize`。
  - artifact tools 统一要求 `entity_type=requirement|release|release_test_run` 和 `entity_id`。
  - `artifact_create` 复用 workspace artifact service 写入 artifact 文件、计算 sha256、分配 version 并入库；默认 `created_by=mcp:<role>`。
  - `artifact_list` 和 `artifact_show` 复用 service entity 校验，返回 artifact id、entity、type、version、path、sha256、is_final 和 created_by 等结构化字段。
  - capability scope 校验覆盖 requirement、release 和 release test run；release test run 可通过 `release_test_run_id` 或归属 `release_id` 授权。
  - `artifact_finalize` 只允许 coordinator token 调用，worker token 不能自行定稿。
- TDD 记录：
  - 扩展 `TestMCPToolsListAndInvalidToken`，要求 tools/list 包含 artifact tools。
  - 新增 `TestMCPArtifactToolsCreateListShowFinalizeAndScopeRequirement`。
  - 新增 `TestMCPArtifactReleaseTestRunScopeRequiresRunOrReleaseScope`。
  - 红灯：MCP tools/list 缺少 artifact tools，worker token 调用 `artifact_create` 和 `artifact_list` 被 capability guard 拒绝。
  - 绿灯：注册 artifact tools、扩展 role matrix、实现 entity scope 校验和 service 参数映射后 focused tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-09-mcp-artifact.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/mcp -run 'TestMCPArtifact|TestMCPToolsList'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/mcp ./internal/cli -run 'TestMCP|TestRootCommandIncludesDocumentedCommandSurface'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/config ./internal/mcp ./internal/cli ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md`
- 当前边界：
  - 本批次只覆盖 artifact MCP 工具；Step 9 完整工具矩阵已由 Batch 13 完成。
  - `artifact_create` 接收 content 并由 artifact service 写本地文件；暂未提供 MCP 从已有文件导入 artifact 的工具。
  - 分析阶段两份终稿同事务 finalize 仍走 `artifact_finalization` approval service；MCP `artifact_finalize` 只做单个 artifact 的 coordinator-only 终稿切换。
  - bug tools 已由 Batch 8 落地，release test tools 已由 Batch 9 落地，release integrate/publish 已由 Batch 10 落地，requirement 管理工具已由 Batch 11 落地，job 管理工具已由 Batch 12 落地；`release_create` 已由 Batch 13 落地。
- 后续批次：
  - Step 9 MCP 工具矩阵已完成。
  - Step 10 Batch 1 已基于 artifact/approval/watch tools 完成 `workspace ai start` 主 Agent 启动链路。

## Step 16: Test command response transaction - Batch 11

- 日期：2026-07-10
- 状态：完成，test_command_missing provide/block 的 approval、test run 和 release event 已原子提交
- 范围：
  - store 新增 `RespondTestCommandMissingApproval` 专用事务。
  - 校验 approval type/status、release/test-run scope 和 test run `waiting_user_input` 状态。
  - provide command 原子写入 user-supplied command 并把 test run 恢复为 queued。
  - block 原子把 test run 标记为 blocked。
  - 同一事务关闭 approval、写 response JSON/responded_by 和 release next-action event。
  - optional run scope 复用事务内 `approval_responded` helper。
  - `test_command_missing` 在通用 choice 校验前进入专用响应解析；结构化 provide 支持 `choice=provide_test_command`、兼容 `choice=approve`，也支持有 `test_command` 时省略 choice。
  - MCP `approval_respond` 不再强制 top-level choice，结构化 response 可交由 typed service validator 处理；其他 approval 的必要 choice 校验不变。
  - workspace service 不再分步关闭 approval、更新 test run 和写 release event。
- TDD 记录：
  - 新增 `TestRespondTestCommandMissingApprovalRollsBackWhenWorkflowWriteFails`。
  - 覆盖 provide/block × test-run-update/approval-update/status-event/run-event 八种失败组合。
  - 红灯：四个失败路径中 approval 均已 approved。
  - 绿灯：专用事务落地后八个失败路径中 approval 保持 pending、test run 保持 waiting_user_input，且只保留 request status event 和 `approval_requested` run event。
  - 新增 `TestRespondTestCommandMissingApprovalAcceptsStructuredResponseJSON`；首个红灯复现结构化 response 被空 top-level choice 拒绝；Review 后扩展无 choice、`provide_test_command`、`approve` alias 和 block，第二个红灯复现无 choice 与 `provide_test_command` 被拒绝，choice normalization 后四种输入均通过。
  - 新增 `TestMCPApprovalRespondAcceptsStructuredTestCommandWithoutTopLevelChoice`；红灯复现 MCP 返回 `choice is required`，handler 改为 optional choice 后结构化 command 经 service 事务写入并恢复同一 test run。
  - 原成功路径和 coordinator user-supplied command 排队测试继续通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-16-test-command-response-transaction.md`。
  - Round 2 独立 Review 文档：`docs/ai-native-review-step-16-test-command-response-transaction-round-2.md`。
  - Round 3 独立 Review 文档：`docs/ai-native-review-step-16-test-command-response-transaction-round-3.md`。
  - Round 4 独立 Review 文档：`docs/ai-native-review-step-16-test-command-response-transaction-round-4.md`。
  - Round 5 独立 Review 文档：`docs/ai-native-review-step-16-test-command-response-transaction-round-5.md`；结论为 Approved with no findings。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/workspace -run 'TestRespondTestCommandMissingApprovalAcceptsStructuredResponseJSON|TestRespondTestCommandMissingApprovalRollsBackWhenWorkflowWriteFails|TestRespondTestCommandMissingApprovalRejectAndCancelKeepApprovalPending|TestRespondTestCommandMissingApprovalQueuesSameTestRun|TestRespondTestCommandMissingApprovalWritesReleaseStatusEvent' -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/mcp -run 'TestMCPApprovalRespondAcceptsStructuredTestCommandWithoutTopLevelChoice|TestMCPApprovalToolsListShowRespondAndRejectWorkerRespond' -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run 'TestDaemonRunOnceQueuesUserSuppliedTestCommandAfterApproval|TestDaemonRunOnceCreatesTestCommandMissingApprovalWithoutTestCommand' -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/store ./internal/workspace ./internal/agent ./internal/coordinator ./internal/mcp ./internal/cli`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md` and `README.md`
- 后续批次：
  - 继续收敛 publish_confirmation 和通用 job-scoped approval response 事务。

## Step 16: Artifact finalization response transaction - Batch 10

- 日期：2026-07-10
- 状态：完成，artifact finalization approve 的业务更新与 response audit events 已原子提交
- 范围：
  - `RespondArtifactFinalizationApproval` 在原有 artifact 校验、两类终稿切换、requirement final ids 和 approval close 事务中追加 response audit events。
  - requirement response event 使用当前 workflow、responded_by、approval type/status 和 optional job id。
  - run-scoped response 在同一事务中分配 event_seq 并写 `approval_responded` payload。
  - workspace service 不再在 store 提交后重复写 artifact finalization status/run events。
  - status event 或 run event 失败会回滚 artifact final flags、requirement final ids 和 approval response。
- TDD 记录：
  - 新增 `TestRespondArtifactFinalizationApprovalRollsBackWhenAuditEventFails`，覆盖 status event 和 run event failure triggers。
  - 红灯：事件失败后 approval 已 approved、artifact 已 final。
  - 绿灯：事件移入定稿事务后，失败路径保持 approval pending、artifact 非 final、final ids 为空，只保留 request events。
  - 原成功路径、wrong artifact type 和 coordinator finalization E2E 继续通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-16-artifact-finalization-response-transaction.md`。
  - 第二轮独立 Review：`docs/ai-native-review-step-16-artifact-finalization-response-transaction-round-2.md`，结论 Approved with no findings。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/workspace -run 'TestRespondArtifactFinalizationApprovalFinalizesRequirementDesignAndTechnicalDesign|TestRespondArtifactFinalizationApprovalRollsBackWhenAuditEventFails|TestRespondArtifactFinalizationApprovalRejectsWrongArtifactType' -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run TestDaemonRunOnceResumesClarificationAndFinalizesAnalysisArtifacts -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/store ./internal/workspace ./internal/agent ./internal/coordinator ./internal/mcp ./internal/cli`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md` and `README.md`
- 后续批次：
  - 继续把 test_command_missing、publish_confirmation 和通用 approval response 的业务更新与 audit events 收敛到专用事务。

## Step 16: Approval request status events - Batch 9

- 日期：2026-07-10
- 状态：完成，pending approval 创建侧现在原子写入 requirement/release 业务诊断事件
- 范围：
  - `CreateHumanApprovalRequest` 成为 request status event 的统一 store 边界。
  - requirement-scoped request 写当前 workflow 的 `requirement_status_events`，绑定 requested_by、approval key 和 optional job id。
  - release-scoped request 写当前 workflow 的 `release_status_events`，绑定 requested_by、approval key、optional test run id 和 job id。
  - reason 使用 `<approval_type> approval requested: <approval_key>`，确保同一 scope 的后续新 approval 有独立事件。
  - 重复确保同一个 pending approval 时复用 approval，并按 approval key 幂等复用已有 request event。
  - approval insert/update、request status event 和 run-scoped `approval_requested` 使用同一 SQLite 事务；任一事件失败时全部回滚。
  - store 统一生成 run event payload/scope/event_seq；provider、analysis coordinator 不再在事务外重复追加。
  - provider clarification、artifact finalization、daemon/service `test_command_missing` 路径自动接入；`publish_confirmation` 继续使用 `StartReleasePendingRelease` 的原子 workflow/event/approval 事务。
- TDD 记录：
  - 扩展 provider、analysis artifact finalization、daemon test-command-missing 和 service StartReleaseTest 测试。
  - 扩展 `TestAINativeStoreDeduplicatesAndRespondsHumanApprovals`，验证 pending 幂等与后续新 approval 独立事件。
  - 新增 `TestAINativeStoreRollsBackApprovalWhenRequestedStatusEventFails`。
  - 新增 `TestAINativeStoreRollsBackApprovalWhenRequestedRunEventFails`。
  - 红灯：approval 创建后 requirement/release status events 为空。
  - Review 红灯：只按 type/scope/status 去重会吞掉同一 scope 的后续新 approval request。
  - 事务红灯：status event 触发器失败后 approval insert 未回滚。
  - 独立 Review 红灯：run-scoped `approval_requested` 仍在 approval 事务后追加，存在 watch 事件缺失窗口。
  - 重复事件红灯：store 加入 run event 后，旧 provider/coordinator 追加逻辑导致同一 approval 出现两条事件。
  - 绿灯：统一原子创建边界和 approval-key 幂等落地、删除调用方重复追加后 focused tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-16-approval-request-status-events.md`。
  - 第二轮独立 Review 与修复记录：`docs/ai-native-review-step-16-approval-request-status-events-round-2.md`。
  - 第三轮独立 Review：代码 Approved；发现初始 Review 文档仍把 run event 归属写为 runner，已修复并记录于 `docs/ai-native-review-step-16-approval-request-status-events-round-3.md`。
  - 第四轮独立 Review：`docs/ai-native-review-step-16-approval-request-status-events-round-4.md`，结论 Approved with no findings。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/store -run 'TestAINativeStoreDeduplicatesAndRespondsHumanApprovals|TestAINativeStoreRollsBackApprovalWhenRequestedStatusEventFails|TestAINativeStoreRollsBackApprovalWhenRequestedRunEventFails' -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/agent -run TestProcessRunnerApprovalRequestCreatesPendingApprovalAndWaitsForUser -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run 'TestDaemonRunOnceCompletesAnalysisReviewWhenNoHighRiskFindings|TestDaemonRunOnceCreatesTestCommandMissingApprovalWithoutTestCommand' -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/workspace -run 'TestRespondApprovalRestoresWaitingJobAndWritesAuditEvents|TestRespondArtifactFinalizationApprovalFinalizesRequirementDesignAndTechnicalDesign|TestRespondTestCommandMissingApprovalRejectAndCancelKeepApprovalPending|TestRespondTestCommandMissingApprovalWritesReleaseStatusEvent|TestStartReleaseTestWithoutCommandCreatesMissingCommandApproval|TestRespondPublishConfirmationRejectWritesReleaseStatusEvent|TestRespondPublishConfirmationApproveWritesReleaseStatusEvent|TestRespondPublishConfirmationCancelWritesReleaseStatusEvent' -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/store ./internal/workspace ./internal/agent ./internal/coordinator ./internal/mcp ./internal/cli`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md` and `README.md`
- 后续批次：
  - 继续审计 response 侧 approval close、job/run 恢复和 status event 的统一事务边界。

## Step 16: Approval response status events - Batch 8

- 日期：2026-07-10
- 状态：完成，scoped approval response 现在同时写 requirement/release 业务诊断事件；approval request 创建侧事件仍待后续审计
- 范围：
  - 新增统一的 approval response status event 记录逻辑。
  - requirement-scoped response 写 `requirement_status_events`，old/new status 均为当前 requirement workflow，并绑定 responder、reason 和 optional job id。
  - release-scoped response 写 `release_status_events`，old/new status 均为当前 release workflow，并绑定 responder、reason、optional test run id 和 job id。
  - `requirement_clarification`、`artifact_finalization` 和通用 requirement/release scoped approval 接入统一事件记录。
  - `publish_confirmation` approve/cancel 接入通用 release 事件；reject 继续使用原有专用事务事件，避免重复。
  - `test_command_missing` 继续使用 Batch 18 的专用 next-action release 事件。
- TDD 记录：
  - 将 `TestRespondApprovalRestoresWaitingJobAndWritesRunEvent` 扩展为 `TestRespondApprovalRestoresWaitingJobAndWritesAuditEvents`。
  - 扩展 `TestRespondArtifactFinalizationApprovalFinalizesRequirementDesignAndTechnicalDesign`。
  - 新增 `TestRespondPublishConfirmationApproveWritesReleaseStatusEvent`。
  - 新增 `TestRespondPublishConfirmationCancelWritesReleaseStatusEvent`。
  - 新增 `TestRespondTestCommandMissingApprovalRejectAndCancelKeepApprovalPending`。
  - 红灯：三类 response 完成后 requirement/release status events 为空。
  - Review 红灯：`test_command_missing` reject/cancel 会关闭 approval，但 release test run 仍停留在 `waiting_user_input`。
  - 绿灯：统一记录 scoped response 诊断事件后 focused tests 通过。
  - Review 绿灯：reject/cancel 被 typed guard 拒绝，approval/test run 保持可继续响应的状态；publish confirmation cancel 事件也有 focused 覆盖。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-16-approval-response-status-events.md`。
  - 第二轮独立 Review 与修复记录：`docs/ai-native-review-step-16-approval-response-status-events-round-2.md`。
  - 第三轮独立 Review：`docs/ai-native-review-step-16-approval-response-status-events-round-3.md`，结论 Approved，无 Blocking/Important issue。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/workspace -run 'TestRespondApprovalRestoresWaitingJobAndWritesAuditEvents|TestRespondArtifactFinalizationApprovalFinalizesRequirementDesignAndTechnicalDesign|TestRespondPublishConfirmationApproveWritesReleaseStatusEvent|TestRespondPublishConfirmationRejectWritesReleaseStatusEvent|TestRespondPublishConfirmationCancelWritesReleaseStatusEvent|TestRespondTestCommandMissingApprovalQueuesSameTestRun|TestRespondTestCommandMissingApprovalRejectAndCancelKeepApprovalPending|TestRespondTestCommandMissingApprovalWritesReleaseStatusEvent' -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/workspace`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/store ./internal/workspace ./internal/agent ./internal/coordinator ./internal/mcp ./internal/cli`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md` and `README.md`
- 后续批次：
  - 审计 approval request 创建侧的 requirement/release status event，确保 pending approval 在 watch 中立即留下 next action。
  - approval close 与后续 run/status event 的统一事务边界作为可靠性加固项单独设计，不在本批扩大修改范围。

## Step 16: MCP approval tools - Batch 6

- 日期：2026-07-09
- 状态：完成，主 Agent 可通过 MCP 查看和响应 approval；MCP artifact 已由 Batch 7 落地，Step 9 完整 MCP 工具矩阵已由 Batch 13 完成
- 范围：
  - MCP 注册 `approval_list`、`approval_show`、`approval_respond`。
  - `approval_list` 支持 `status` 和 `type` 过滤，并按 capability token scope 过滤返回结果。
  - `approval_show` 校验 approval 必须落在 token 的 requirement、release、release test run 或 job scope 内。
  - `approval_respond` 只允许 coordinator token 调用，worker token 只能 list/show，不能代表用户确认。
  - MCP respond 参数映射到 service typed 参数：`response_json`、`response` object、`message`、`test_command`、`confirm`、provider permission grant 参数和 artifact finalization artifact id。
  - coordinator relay respond 写入 `responded_by=mcp:coordinator`，复用 service 恢复 waiting job、创建 provider permission grant 和写 run event。
- TDD 记录：
  - 扩展 `TestMCPToolsListAndInvalidToken`，要求 tools/list 包含 approval 工具。
  - 新增 `TestMCPApprovalToolsListShowRespondAndRejectWorkerRespond`。
  - 新增 `TestMCPApprovalRespondMapsProviderPermissionTypedArguments`。
  - 红灯：MCP server 未注册 approval 工具，`approval_list` 被 capability guard 拒绝。
  - 绿灯：实现 tool registration、role matrix、approval scope check 和 respond 参数映射后 focused tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-16-mcp-approval.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/mcp -run 'TestMCPApproval|TestMCPToolsList'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/mcp ./internal/cli -run 'TestMCP|TestRootCommandIncludesDocumentedCommandSurface'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/config ./internal/mcp ./internal/cli ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md`
- 当前边界：
  - 本批次只覆盖 approval MCP 工具；Step 9 完整工具矩阵已由 Batch 13 完成。
  - 主 Agent 必须只在用户明确选择后调用 `approval_respond`；当前代码通过 coordinator-only role matrix、`mcp:coordinator` 审计和 Step 10 Batch 1 prompt 约束来源，真实聊天 E2E 仍需补齐。
  - artifact tools 已由 Batch 7 落地，bug tools 已由 Batch 8 落地，release test tools 已由 Batch 9 落地，release integrate/publish 已由 Batch 10 落地，requirement 管理工具已由 Batch 11 落地，job 管理工具已由 Batch 12 落地；`release_create` 已由 Batch 13 落地。
- 后续批次：
  - Step 9 MCP 工具矩阵已完成。
  - Step 10 Batch 1 已基于 `mcp serve`、signed coordinator token 和 approval tools 实现 `workspace ai start`。
  - E2E 需要覆盖主 Agent 聊天展示 approval、用户确认、coordinator relay respond、worker 继续执行的完整链路。

## Step 16: MCP watch/tail/status - Batch 5

- 日期：2026-07-09
- 状态：完成，主 Agent 可通过 MCP 读取 req/release/job/run 的 watch/status/tail；MCP approval 已由 Batch 6 落地，Step 9 完整 MCP 工具矩阵已由 Batch 13 完成
- 范围：
  - 新增 `internal/mcp`，实现 stdio JSON-RPC MCP server 的 `tools/list` 和 `tools/call` 基础协议。
  - 注册 `req_watch`、`release_watch`、`release_status`、`job_watch`、`run_tail` 工具，复用 `RequirementWatchSnapshot`、`ReleaseWatchSnapshot`、`WatchJobEvents`、`TailRunEvents` 和 `TailRunRaw`。
  - config 初始化写入 `mcp_secret`，MCP capability token 使用 HMAC JSON payload 签名、校验签名和过期时间。
  - 新增 `workspace mcp serve --capability-token <token>`。
  - daemon provider run token 从占位 `job-<id>` 改为签名 job-scoped token，包含 role、job、requirement、release 和 release test run scope。
  - MCP `run_tail raw=true` 默认脱敏，并显式拒绝 `unsafe_unredacted=true`。
- TDD 记录：
  - 扩展 `TestRootCommandIncludesDocumentedCommandSurface`，要求存在 `mcp serve`。
  - 新增 `TestMCPWatchToolsReturnScopedSnapshotsAndRedactedRunTail`、`TestMCPToolsListAndInvalidToken`、`TestMCPServeHandlesToolsList`。
  - 新增 `TestDaemonRunRequestUsesSignedScopedCapabilityToken`。
  - 红灯：`internal/mcp` 包、`mcp serve` 命令、`MCPSecret` 和 capability signing API 均不存在。
  - 绿灯：实现 MCP auth/server/tools、CLI mcp serve、config secret 和 daemon signed token 后 focused tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-16-mcp-watch-tail.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/mcp ./internal/cli -run 'TestMCP|TestRootCommandIncludesDocumentedCommandSurface'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run TestDaemonRunRequestUsesSignedScopedCapabilityToken`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/config ./internal/mcp ./internal/cli ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md`
- 当前边界：
  - 本批次只覆盖 watch/tail/status 查询子集；Step 9 完整工具矩阵已由 Batch 13 完成。
  - MCP approval 已由 Batch 6 落地，artifact tools 已由 Batch 7 落地，bug tools 已由 Batch 8 落地，release test tools 已由 Batch 9 落地，release integrate/publish 已由 Batch 10 落地，requirement 管理工具已由 Batch 11 落地，job 管理工具已由 Batch 12 落地；`release_create` 已由 Batch 13 落地。
  - 历史 config 缺少 `mcp_secret` 时使用基于 home 的兼容派生 secret；后续可补显式 token 管理和 config migration。
- 后续批次：
  - Step 9 MCP 工具矩阵已完成。
  - Step 10 Batch 1 已基于 `mcp serve` 和 signed coordinator token 实现 `workspace ai start`。

## Step 16: Run tail - Batch 4

- 日期：2026-07-09
- 状态：完成，Step 16 run 维度结构化 event 和 raw tail 入口已落地；MCP redacted run_tail 已由 Batch 5 落地
- 范围：
  - store 新增 `GetAgentRun`，按 run id 读取 provider run metadata 和 stdout/stderr 路径。
  - service 新增 `TailRunEvents` 和 `TailRunRaw`，分别读取结构化 `agent_run_events` 与 stdout/stderr 文件尾部。
  - provider runner 的输出脱敏函数导出为 `agent.RedactProviderLine`，供 raw tail 默认脱敏复用同一规则。
  - 新增 `workspace run tail <run-id> [--follow] [--raw] [--unsafe-unredacted]`。
  - `run tail` 默认输出结构化 event；`--raw` 输出 stdout/stderr tail 并默认脱敏；`--unsafe-unredacted` 仅在本地 CLI 显式配合 `--raw` 时允许未脱敏输出。
- TDD 记录：
  - 扩展 `TestRootCommandIncludesDocumentedCommandSurface`，要求存在 `run tail`。
  - 新增 `TestRunTailShowsEventsAndRedactsRawOutput`。
  - 红灯：root command 未提供 `run` 命令，`workspace run tail <id>` 返回 unknown command。
  - 绿灯：实现 store run 查询、service tail 方法和 CLI run tail 输出后 focused CLI tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-16-run-tail.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli -run 'TestRootCommandIncludesDocumentedCommandSurface|TestRunTailShowsEventsAndRedactsRawOutput|TestReqWatchShowsWorkflowJobsApprovalsArtifactsAndEvents|TestReleaseWatchShowsAINativeReleaseContext'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/agent`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md`
- 当前边界：
  - raw tail 默认读取最后 32KB，暂不提供 `--bytes` 或 `--lines` 配置。
  - JSON value、URL query、Bearer token、capability token flag 和 secret header 已由 Step 16 Batch 7 的 redaction hardening 补齐。
  - MCP `run_tail` 脱敏读取已由 Batch 5 落地，且不提供未脱敏能力。
- 后续批次：
  - 如需进一步 hardening，可补跨行重组、结构化日志解析或用户自定义 secret pattern。

## Step 16: Redaction hardening - Batch 7

- 日期：2026-07-10
- 状态：完成，provider/run tail/MCP raw tail 共享脱敏能力已补强
- 范围：
  - `agent.RedactProviderLine` 从简单 `KEY=value` 扩展为共享 pattern redaction。
  - 覆盖 JSON secret 字段，如 `api_key`、`refresh_token`、`secret`、`password`。
  - 覆盖 URL query secret，如 `?token=...&api_key=...`，保留非敏感 query。
  - 覆盖 `Authorization: Bearer ...`、secret header、敏感 CLI flag，如 `--capability-token ...`。
  - provider output event、CLI `run tail --raw` 和 MCP `run_tail raw=true` 继续复用同一脱敏函数。
- TDD 记录：
  - 新增 `TestRedactProviderLineHandlesStructuredSecrets`。
  - 红灯：JSON、URL query、Bearer token、capability token flag 和 secret header 均未被脱敏。
  - 绿灯：实现共享 regex redaction 后 focused test 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-16-redaction-hardening.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/agent -run TestRedactProviderLineHandlesStructuredSecrets -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/agent`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli ./internal/mcp -run 'TestRunTailShowsEventsAndRedactsRawOutput|TestMCPWatchToolsReturnScopedSnapshotsAndRedactedRunTail'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md` and `README.md`
- 后续批次：
  - Redaction 仍是模式脱敏，不做跨行重组或完整结构化日志解析；如需更强防护，可继续补用户自定义 secret pattern。

## Step 16: Requirement watch - Batch 3

- 日期：2026-07-09
- 状态：完成，Step 16 requirement 维度实时状态聚合入口已落地；MCP req_watch 已由 Batch 5 落地
- 范围：
  - store 新增 `ListRequirementRunEventsAfter`，按 requirement id 和 event id 游标读取 requirement scoped `agent_run_events`。
  - store 扩展 `ListAgentJobs`，支持按 `requirement_id` 和 `release_id` 过滤，避免 service 侧扫描所有 job。
  - service 新增 `RequirementWatchSnapshot`，聚合 requirement workflow、repos、active jobs、pending approvals、latest artifacts、open bugs 和最近 run events。
  - 新增 `workspace req watch <req> [--follow] [--after-event <id>]`，输出需求执行上下文，供用户和主 Agent 实时查看分析/开发/bugfix 进展。
  - pending approvals 按 `requirement_id` 或当前需求 active job 的 `job_id` 聚合，覆盖需求澄清、产物定稿、provider permission 等人工确认入口。
- TDD 记录：
  - 扩展 `TestRootCommandIncludesDocumentedCommandSurface`，要求存在 `req watch`。
  - 新增 `TestReqWatchShowsWorkflowJobsApprovalsArtifactsAndEvents`。
  - 红灯：root command 未提供 `req watch`，调用只能得到 `workspace req` 帮助信息。
  - 绿灯：实现 store 查询、service snapshot 和 CLI watch 输出后 focused CLI tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-16-req-watch.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli -run 'TestRootCommandIncludesDocumentedCommandSurface|TestReqWatchShowsWorkflowJobsApprovalsArtifactsAndEvents|TestReleaseWatchShowsAINativeReleaseContext'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md`
- 当前边界：
  - `req watch --follow` 当前按轮询输出聚合快照和新增 requirement run events；不会建立长连接或远程服务。
  - 本批次聚合 requirement scoped run events；未带 `requirement_id` 的历史 job event 仍需通过 `job watch` 查看。
  - MCP `req_watch` 已由 Batch 5 复用 `RequirementWatchSnapshot` 落地。
- 后续批次：
  - Step 9 MCP 工具矩阵已由后续 Batch 13 完成。

## Step 16: Release status/watch - Batch 2

- 日期：2026-07-09
- 状态：完成，Step 16 release 维度实时状态聚合入口已落地；MCP release_watch/release_status 已由 Batch 5 落地
- 范围：
  - store 新增 `ListReleaseRunEventsAfter`，按 release id 和 event id 游标读取 release scoped `agent_run_events`。
  - service 新增 `ReleaseWatchSnapshot`，聚合 release workflow、diagnostics、requirements、repos、feature snapshots、release status events、test runs、test run requirement snapshots、open bugs、pending approvals 和 release scoped run events。
  - `release status` 保留原有 stale/manual/publish-in-progress 诊断输出，并追加 AINative workflow、active test run、status event、test run、test report、bug、approval 和 run event 摘要。
  - 新增 `workspace release watch <release> [--follow] [--after-event <id>]`，使用同一 `ReleaseWatchSnapshot` 输出 release 执行上下文。
  - pending approvals 按 `release_id` 或当前 release 的 `release_test_run_id` 聚合，覆盖 `publish_confirmation` 这类 release/test-run scoped 人工确认。
- TDD 记录：
  - 扩展 `TestRootCommandIncludesDocumentedCommandSurface`，要求存在 `release watch`。
  - 新增 `TestReleaseWatchShowsAINativeReleaseContext`。
  - 红灯：`release status` 缺少 `workflow: pending_release`，且 root command 未提供 `release watch` 聚合入口。
  - 绿灯：实现 service snapshot、store release event 查询和 CLI status/watch 输出后 focused CLI tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-16-release-watch.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli -run 'TestRootCommandIncludesDocumentedCommandSurface|TestReleaseWatchShowsAINativeReleaseContext|TestReleaseStatus'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md`
- 当前边界：
  - `release watch --follow` 当前按轮询输出聚合快照和新增 release run events；不会建立长连接或远程服务。
  - 本批次聚合 release scoped run events；requirement-only bugfix run event 仍留给 `req watch` 或后续 release watch 增强按 release 关联 bugfix job 聚合。
  - MCP `release_watch` / `release_status` 已由 Batch 5 复用 `ReleaseWatchSnapshot` 落地。
- 后续批次：
  - Step 9 MCP 工具矩阵已由后续 Batch 13 完成。

## Step 16: Approval respond control - Batch 1

- 日期：2026-07-02
- 状态：完成，Step 16 整体仍在进行中
- 范围：
  - Store 新增 `ListHumanApprovals`，支持按 status 和 approval type 查询。
  - Store 新增 `ResumeAgentJobAfterApproval`，用于 approval approve 后把 `waiting_user_input`、`blocked` 或 `failed` job 恢复为 `queued`，并清理 lease、not_before、started/completed/failed timestamps 和 last_error。
  - Service 新增 `ListApprovals`、`GetApproval`、`RespondApproval`。
  - `RespondApproval` 支持 `approve`、`reject`、`cancel` 三类 choice，并写结构化 `response_json` 和 `responded_at`。
  - 普通 approval approve 后会追加 `approval_responded` run event，并恢复关联 job queued。
  - `provider_permission` approve 会校验 response 包含 `scope`、`expires_at`、`sandbox`、`approval_policy`，创建 active `provider_permission_grants`，再恢复 job queued。
  - `provider_permission` response 不允许超过 payload 中的 `requested_scope`、`requested_sandbox`、`requested_approval_policy`。
  - 新增 `workspace approval list/show/respond` CLI；respond 支持 `--response-json`、`--confirm`、`--scope`、`--expires-at`、`--sandbox`、`--approval-policy`。
  - docs 首页增加 AINative Approval 命令入口。
- TDD 记录：
  - 新增 `TestRespondApprovalRestoresWaitingJobAndWritesRunEvent`。
  - 新增 `TestRespondProviderPermissionApprovalCreatesGrantAndResumesJob`。
  - 红灯：workspace tests 因 `RespondApproval` 和 `RespondApprovalParams` 不存在而构建失败。
  - 新增 `TestRootCommandIncludesDocumentedCommandSurface` 中 approval command surface 断言，并新增 `TestApprovalCommandsListShowAndRespondProviderPermission`。
  - 红灯：CLI test 因 root 缺少 `approval` 命令失败。
  - 绿灯：实现 store/service/CLI 后 focused workspace test 通过，CLI test 先暴露 approval list 期望写成 job key 的测试问题，修正为当前数据模型中的 `job:<id>` 后通过。
  - 新增 `TestRespondProviderPermissionApprovalRejectsPermissionEscalation`，覆盖 provider permission 越权 sandbox/policy response 被拒绝且 approval 保持 pending、job 保持 waiting。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-16-approval-respond.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test ./internal/workspace -run 'TestRespondApproval|TestRespondProviderPermission'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test ./internal/cli -run 'TestRootCommandIncludesDocumentedCommandSurface|TestApprovalCommandsListShowAndRespondProviderPermission'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fence balance check
- 后续批次：
  - pending approvals 聚合已由后续 Step 16 watch/MCP 批次落地。
  - `artifact_finalization`、`test_command_missing` 和 `publish_confirmation` 的业务联动已由后续 Step 12/14/15 批次落地。
  - daemon/worker 调度接入 `ProcessRunner` 已由后续 Step 8 批次落地。

## Step 8: Daemon RunOnce - Batch 1

- 日期：2026-07-02
- 状态：完成，Step 8 整体仍在进行中
- 范围：
  - 新增 `internal/coordinator` package。
  - 新增 `Daemon.RunOnce`，单次扫描 enabled worker pools。
  - daemon 会跳过 disabled pool 和 disabled agent。
  - daemon 基于 `CountWorkerPoolActiveJobs` 计算本轮 tick capacity，按 pool `parallelism` claim queued job。
  - `parallelism=1` 时同一 RunOnce 只 claim 一个 job，后续 queued job 保留到下一次 RunOnce。
  - daemon claim job 后构造 `agent.RunRequest`，把 workspace home、runtime dir、job id/key、attempt、provider、agent、worker key、sandbox、approval policy 和 job input 传给 runner。
  - `RunnerFactory` 可注入测试 runner；默认 factory 按 agent provider 创建 Codex 或 Claude `ProcessRunner`。
  - CLI 新增 `workspace agent daemon start --once`，以及 foreground 模式说明性质的 `workspace agent daemon status/stop`。
  - README 的 AINative 示例已在 Step 10 Batch 1 重新加入 `workspace ai start --agent main-codex`。
  - docs 首页补充 agent daemon 命令入口。
- TDD 记录：
  - 新增 `TestDaemonRunOnceExecutesQueuedJobWithFakeRunner`。
  - 新增 `TestDaemonRunOnceSkipsDisabledPool`。
  - 新增 `TestDaemonRunOnceHonorsParallelismCapacityPerTick`。
  - 红灯：coordinator tests 因 `Daemon` 和 `JobRunner` 不存在而构建失败。
  - 新增 `TestAgentDaemonCommandSurfaceIsStrict`，严格校验 `agent daemon start/status/stop` 解析到正确子命令。
  - 红灯：CLI strict test 解析到 `agent` 而不是 `start`。
  - 绿灯：实现 coordinator daemon、default runner factory、CLI daemon commands 后 focused coordinator/CLI tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-08-daemon-run-once.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test ./internal/coordinator -run DaemonRunOnce`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test ./internal/cli -run 'TestAgentDaemonCommandSurfaceIsStrict|TestRootCommandIncludesDocumentedCommandSurface'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fence balance check
- 后续批次：
  - Step 8 后续需要创建/复用 `worker_instances`，维护 heartbeat、current_job_id、idle/running/stopped 状态，并让 live workers 不超过 `max_workers`。
  - Step 8 后续需要 runner failure retry/backoff，而不是直接让 daemon 返回错误。
  - Step 8 后续需要 coordinator lane 和 workflow watch loop：pending acceptance/analysis/development/release bug/release stale/publish-in-progress 的幂等 job 创建。

## Step 8: Worker instance heartbeat and retry - Batch 2

- 日期：2026-07-02
- 状态：完成，Step 8 整体仍在进行中
- 范围：
  - Store 新增 `CreateWorkerInstance`、`GetWorkerInstanceByKey`、`ListWorkerInstances`、`MarkWorkerInstanceRunning`、`MarkWorkerInstanceIdle`。
  - Store 新增 `RequeueAgentJobAfterFailure`，用于 runner failure 后带 `not_before` 和 `last_error` 回到 `queued`。
  - daemon 每轮调度会按 pool 查找 idle worker instance；idle 不足且 live worker 数小于 `max_workers` 时创建新的 worker instance。
  - daemon claim job 时使用具体 `worker_key` 作为 lease owner，让 job/run/event 能关联到执行 worker。
  - worker 执行 job 前进入 `running`，写入 `current_job_id`、`heartbeat_at` 和 message；执行成功后回到 `idle`。
  - runner 返回失败或错误且 job 未达到 `max_attempts` 时，daemon 将 job 以 30 秒 backoff 重排到 `queued`，释放 worker 回 `idle`，并在 `RunOnceResult` 记录 `RetriedJobs`。
  - `parallelism` 继续限制 active job 数，`max_workers` 限制 live worker instance 数；单 tick 不会创建或使用超过 `max_workers` 的 worker。
- TDD 记录：
  - 扩展 `TestAINativeStoreAgentJobStatusTransitions`，期待失败后可以通过 `RequeueAgentJobAfterFailure` 带 backoff 回到 queued。
  - 新增 `TestAINativeStoreWorkerInstanceLifecycle`，覆盖 worker instance 创建、running、idle 和 list。
  - 红灯：store tests 因 worker instance API 和 `RequeueAgentJobAfterFailure` 不存在而构建失败。
  - 新增 `TestDaemonRunOnceCreatesWorkerInstanceAndHeartbeat`。
  - 新增 `TestDaemonRunOnceHonorsMaxWorkersPerTick`。
  - 新增 `TestDaemonRunOnceRetriesFailedJobWithBackoff`。
  - 红灯：coordinator tests 因 `ListWorkerInstances`、worker lifecycle 和 `RunOnceResult.RetriedJobs` 不存在而构建失败。
  - 绿灯：实现 store API、daemon worker 分配、heartbeat、max worker gate 和失败 backoff 后 focused store/coordinator tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-08-worker-instance-retry.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test ./internal/store -run 'TestAINativeStoreAgentJobStatusTransitions|TestAINativeStoreWorkerInstanceLifecycle'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test ./internal/coordinator -run 'TestDaemonRunOnceCreatesWorkerInstanceAndHeartbeat|TestDaemonRunOnceHonorsMaxWorkersPerTick|TestDaemonRunOnceRetriesFailedJobWithBackoff'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/store ./internal/coordinator ./internal/cli`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fence balance check
- 后续批次：
  - Step 8 后续需要实现 daemon foreground loop/supervisor，而不是仅支持 `--once` 单 tick。
  - Step 8 后续需要根据 heartbeat 超时把 stale worker instance 标记为 `lost`，并在 daemon stop 时收敛为 `stopping/stopped`。
  - Step 8 后续需要实现 coordinator lane 和 workflow watch loop，创建 pending analysis/development/testing/release/publish 相关系统 job。
  - Step 8 后续需要把固定 30 秒 retry backoff 演进为可配置策略，并补 max attempts 终态报告。

## Step 8: Daemon loop and worker recovery - Batch 3

- 日期：2026-07-02
- 状态：完成，Step 8 整体仍在进行中
- 范围：
  - Store 新增 `MarkStaleWorkerInstancesLost`，按 heartbeat 阈值把 `starting/idle/running/stopping` worker 标记为 `lost`，清空 `current_job_id` 并写 `stopped_at/message`。
  - Store 新增 `MarkLiveWorkerInstancesStopped`，用于 daemon shutdown 时把 live worker instance 收敛为 `stopped`。
  - `Daemon` 新增 `Run(ctx)` 前台循环 API；非 `--once` CLI 路径改为调用该 API。
  - `Daemon` 新增 `PollInterval`、`WorkerHeartbeatTimeout`、`AfterTick` 和默认值 helper，便于测试和后续配置接入。
  - 每次 `RunOnce` 在 job claim 前先调用 stale worker cleanup；清理数量写入 `RunOnceResult.LostWorkers`。
  - `Run(ctx)` 捕获 context cancel 并返回 nil，退出前调用 shutdown 收敛 live worker instance。
  - daemon CLI 输出增加 `retried` 和 `lost-workers`，用户可以在前台实时看到 retry 与 stale worker 回收计数。
- TDD 记录：
  - 新增 `TestAINativeStoreMarksStaleAndStoppedWorkerInstances`。
  - 红灯：store tests 因 `MarkStaleWorkerInstancesLost` 和 `MarkLiveWorkerInstancesStopped` 不存在而构建失败。
  - 新增 `TestDaemonRunOnceMarksStaleWorkersLostBeforeCapacityCheck`。
  - 新增 `TestDaemonRunStopsLiveWorkersOnContextCancel`。
  - 红灯：coordinator tests 因 `WorkerHeartbeatTimeout`、`LostWorkers`、`PollInterval`、`AfterTick` 和 `Run` 不存在而构建失败。
  - 绿灯：实现 store worker recovery API、daemon foreground loop、stale cleanup、shutdown 收敛和 CLI loop 复用后 focused tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-08-daemon-loop-worker-recovery.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test ./internal/store -run 'TestAINativeStoreMarksStaleAndStoppedWorkerInstances'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test ./internal/coordinator -run 'TestDaemonRunOnceMarksStaleWorkersLostBeforeCapacityCheck|TestDaemonRunStopsLiveWorkersOnContextCancel'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/store -run 'TestAINativeStoreWorkerInstanceLifecycle|TestAINativeStoreMarksStaleAndStoppedWorkerInstances|TestAINativeStoreAgentJobStatusTransitions'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli -run 'TestAgentDaemonCommandSurfaceIsStrict|TestRootCommandIncludesDocumentedCommandSurface'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/store ./internal/coordinator ./internal/cli`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fence balance check
- 后续批次：
  - Step 8 后续需要实现 coordinator lane，使用默认主 Agent 串行 claim/执行 `role=coordinator` job。
  - Step 8 后续需要实现 workflow watch loop 的第一批幂等 job 创建，优先覆盖 `pending_acceptance` 到 `coordinator_decide`。
  - provider 执行期间的周期性 worker heartbeat 已由 Step 8 Batch 6 补齐。
  - `PollInterval`、`WorkerHeartbeatTimeout`、`WorkerHeartbeatInterval` 和 retry backoff 已由 Step 8 Batch 7 接入配置。

## Step 8: Coordinator lane pending acceptance - Batch 4

- 日期：2026-07-02
- 状态：完成，Step 8 整体仍在进行中
- 范围：
  - config 新增 AINative agent defaults：`agent_default_review_policy`、`agent_default_main_agent`、`agent_default_test_command`、`agent_coordinator_watch_interval_ms`。
  - `config.Default` 默认 `agent_default_main_agent=main-codex`，watch interval 默认为 2000ms；`config.Load` 支持从 `config.yaml` 覆盖。
  - Store 新增 `RequirementWorkflow` 视图和 `RequirementWorkflowStatusPendingAcceptance` 常量。
  - Store 新增 `ListRequirementWorkflowsByStatus`，用于 workflow watch loop 查询 `pending_acceptance` 等状态。
  - Store 新增 `SetRequirementWorkflowStatus`，供测试和后续 `req submit/advance` service 复用。
  - Store 新增 `ClaimCoordinatorJob`，只 claim `role=coordinator`、`worker_pool_id IS NULL`、绑定默认主 Agent 的 queued job。
  - daemon 每轮 `RunOnce` 在普通 worker pool 前读取默认主 Agent；默认主 Agent 缺失、禁用或 role 非 coordinator 时跳过 coordinator lane。
  - daemon 对 `pending_acceptance` 需求幂等创建 `coordinator-decide-<req-key>` job，`job_type=coordinator_decide`，输入 JSON 包含 requirement id/key/title/workflow status。
  - coordinator lane 串行执行一个 coordinator job，并复用 provider runner、run/event 记录和失败 retry/backoff 逻辑。
  - `RunOnceResult` 增加 `CoordinatorJobs`；CLI daemon 输出增加 `coordinator` 计数。
- TDD 记录：
  - 扩展 `TestInitCreatesDefaultConfigAndDirectories`，并新增 `TestLoadCustomAINativeAgentDefaults`。
  - 红灯：config tests 因 `AgentDefaultMainAgent`、`AgentCoordinatorWatchIntervalMs` 等字段不存在而构建失败。
  - 新增 `TestAINativeStoreListsRequirementWorkflowsByStatus`。
  - 红灯：store tests 因 `RequirementWorkflowStatusPendingAcceptance` 和 `ListRequirementWorkflowsByStatus` 不存在而构建失败。
  - 新增 `TestDaemonRunOnceCreatesAndRunsCoordinatorDecisionForPendingAcceptance`。
  - 新增 `TestDaemonRunOnceSkipsPendingAcceptanceWithoutDefaultMainAgent`。
  - 红灯：coordinator tests 因 `SetRequirementWorkflowStatus`、`CoordinatorJobs` 和 config 默认主 Agent 字段不存在而构建失败。
  - 绿灯：实现 config defaults、store workflow API、coordinator job claim、pending acceptance watcher 和 coordinator lane 后 focused tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-08-coordinator-lane-pending-acceptance.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/config -run 'TestInitCreatesDefaultConfigAndDirectories|TestLoadCustomAINativeAgentDefaults'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/store -run 'TestAINativeStoreListsRequirementWorkflowsByStatus'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run 'TestDaemonRunOnceCreatesAndRunsCoordinatorDecisionForPendingAcceptance|TestDaemonRunOnceSkipsPendingAcceptanceWithoutDefaultMainAgent'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/config ./internal/store ./internal/coordinator ./internal/cli`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fence balance check
- 后续批次：
  - Step 8 后续需要实现 `pending_analysis` 的幂等 `analysis_generate` job 创建。
  - Step 8/12 后续需要让 analysis worker claim 后把需求推进到 `analyzing`，并在完成后写 analysis/technical artifacts。
  - daemon-driven requirement workflow status event 审计已由 Step 8 Batch 9 补齐；低层 `SetRequirementWorkflowStatus` 继续作为无事件 store primitive。
  - Step 8 后续需要扩展 coordinator lane 对 run result 的业务解释，让主 Agent 可以分配 analysis/coding/testing Agent 或保持待采纳并写阻塞说明。

## Step 8: Pending analysis job - Batch 5

- 日期：2026-07-03
- 状态：完成，Step 8 整体仍在进行中
- 范围：
  - Store 新增 `RequirementWorkflowStatusPendingAnalysis` 和 `RequirementWorkflowStatusAnalyzing`。
  - Store 新增 `AssignRequirementAgents` 和 `AssignRequirementAgentsParams`，支持为 requirement 设置 analysis/coding/testing Agent。
  - daemon 每轮 `RunOnce` 扫描 `workflow_status=pending_analysis` 的 requirements。
  - daemon 仅在 requirement 已设置 enabled analysis Agent，且存在该 Agent 对应 enabled analysis worker pool 时，创建 `analysis_generate` job。
  - `analysis_generate` job key 为 `analysis-generate-<req-key>`，重复扫描不会重复创建。
  - `analysis_generate` job 绑定 requirement、analysis Agent 和 analysis worker pool，后续由普通 worker pool claim。
  - analysis worker claim 到 `analysis_generate` job 后，daemon 将 requirement `workflow_status` 推进到 `analyzing`，再执行 provider runner。
  - `RunOnceResult` 增加 `AnalysisJobs`；CLI daemon 输出增加 `analysis` 计数。
- TDD 记录：
  - 新增 `TestAINativeStoreAssignsRequirementAgents`。
  - 红灯：store tests 因 `AssignRequirementAgents` 和 `AssignRequirementAgentsParams` 不存在而构建失败。
  - 新增 `TestDaemonRunOnceCreatesAnalysisJobAndAdvancesToAnalyzing`。
  - 新增 `TestDaemonRunOnceSkipsPendingAnalysisWithoutAssignedAgent`。
  - 红灯：coordinator tests 因 `AssignRequirementAgents`、`RequirementWorkflowStatusPendingAnalysis`、`RequirementWorkflowStatusAnalyzing` 和 `RunOnceResult.AnalysisJobs` 不存在而构建失败。
  - 绿灯：实现 requirement Agent assignment、pending analysis watcher、analysis worker pool 绑定和 claim 后状态推进后 focused tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-08-pending-analysis-job.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/store -run 'TestAINativeStoreAssignsRequirementAgents'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run 'TestDaemonRunOnceCreatesAnalysisJobAndAdvancesToAnalyzing|TestDaemonRunOnceSkipsPendingAnalysisWithoutAssignedAgent'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/store ./internal/coordinator ./internal/cli`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fence balance check
- 后续批次：
  - Step 12/analysis loop 需要让 analysis runner 生成需求设计方案和技术实现方案 artifact，并记录每轮 Review。
  - Step 12/16 后续需要实现 analysis artifact finalization approval。
  - Step 8 后续需要实现 `analysis_completed` 后不自动进入开发、等待终稿确认的状态闭环。
  - `AssignRequirementAgents` service/MCP/CLI 权限与状态事件审计已由 Step 11/9/16 覆盖；daemon 自动推进状态事件已由 Step 8 Batch 9 补齐。

## Step 8: Worker heartbeat during run - Batch 6

- 日期：2026-07-10
- 状态：完成，长运行 provider job 期间的 worker heartbeat 刷新已落地
- 范围：
  - `Daemon` 新增 `WorkerHeartbeatInterval`。
  - 默认 heartbeat interval 由 `WorkerHeartbeatTimeout` 推导，测试可显式设置短间隔。
  - 普通 worker claim job 并进入 running 后，daemon 在 `runner.Run` 外层启动 heartbeat ticker。
  - ticker 周期性调用 `MarkWorkerInstanceRunning`，刷新 `heartbeat_at`、`current_job_id` 和 running message。
  - runner 返回后停止 ticker，并继续沿用原有 succeeded、waiting_user_input、retry 和 idle 收敛路径。
  - 该能力让 `worker show`、DB 状态和主 Agent 轮询在长运行 provider job 期间看到 worker 仍活跃。
- TDD 记录：
  - 新增 `TestDaemonRunOnceRefreshesHeartbeatDuringLongRunner`。
  - 红灯：`Daemon` 缺少 `WorkerHeartbeatInterval`，且长运行 runner 期间 heartbeat 不会刷新。
  - 绿灯：heartbeat ticker 落地后，测试在释放 blocking runner 前观察到 heartbeat 前进。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-08-worker-heartbeat-during-run.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run TestDaemonRunOnceRefreshesHeartbeatDuringLongRunner -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md` and `README.md`
- 后续批次：
  - `WorkerHeartbeatInterval` 已由 Step 8 Batch 7 暴露为配置项。
  - 如果单次 heartbeat DB update 碰到临时锁或写入失败，ticker 会跳过该次并在下一轮继续尝试；后续可把连续 heartbeat health error 记录为 daemon warning event。

## Step 8: Daemon timing config - Batch 7

- 日期：2026-07-10
- 状态：完成，daemon 调度和 retry timing 已接入配置
- 范围：
  - config 新增 `agent_worker_heartbeat_timeout_ms`，默认 `30000`。
  - config 新增 `agent_worker_heartbeat_interval_ms`，默认 `5000`。
  - config 新增 `agent_job_retry_backoff_ms`，默认 `30000`。
  - `agent_coordinator_watch_interval_ms` 继续作为 daemon poll interval 配置源。
  - `Daemon` 新增 `RetryBackoff` field，和既有 `PollInterval`、`WorkerHeartbeatTimeout`、`WorkerHeartbeatInterval` 一样支持测试/调用方显式 override。
  - `Daemon` timing helper 统一按显式 field > config 毫秒值 > 兼容默认值读取。
  - 配置化 heartbeat interval 如果大于或等于 heartbeat timeout，会自动回落到基于 timeout 的安全 interval。
  - `retryFailedJob` 改为使用 `retryBackoff()`，失败 job 的 `not_before` 不再固定为 30 秒。
- TDD 记录：
  - 扩展 `TestInitCreatesDefaultConfigAndDirectories` 和 `TestLoadCustomAINativeAgentDefaults`。
  - 新增 `TestDaemonUsesConfigDrivenTimingDefaults`。
  - 追加 unsafe heartbeat interval 用例，覆盖 config interval 大于 timeout 时的安全回落。
  - 扩展 `TestDaemonRunOnceRetriesFailedJobWithBackoff`，断言 configured 7 秒 backoff。
  - 红灯：config 字段和 `Daemon.retryBackoff` 不存在，retry 仍固定 30 秒；unsafe heartbeat 用例先失败于 interval 超过 timeout。
  - 绿灯：新增 config 字段、daemon helper、安全 heartbeat interval 回落和 retry backoff 接入后 focused tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-08-daemon-timing-config.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/config -run 'TestInitCreatesDefaultConfigAndDirectories|TestLoadCustomAINativeAgentDefaults'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run 'TestDaemonUsesConfigDrivenTimingDefaults|TestDaemonRunOnceRetriesFailedJobWithBackoff'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/config ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md` and `README.md`
- 后续批次：
  - 如果单次 heartbeat DB update 碰到临时锁或写入失败，ticker 会跳过该次并在下一轮继续尝试；后续可把连续 heartbeat health error 记录为 daemon warning event。

## Step 8: Publish-in-progress diagnostic - Batch 8

- 日期：2026-07-10
- 状态：完成，daemon workflow watch loop 已覆盖 `publish_in_progress` 诊断
- 范围：
  - `Daemon.RunOnce` 新增 `ensurePublishInProgressDiagnostics`。
  - daemon 扫描 `workflow_status=publish_in_progress` 且存在 `active_test_run_id` 的 release。
  - store 新增 `RecordReleasePublishInProgressDiagnostic`，写入 `publish_in_progress -> publish_in_progress` 的 release status event。
  - 诊断事件按 release、test run、actor、reason 幂等去重，避免 daemon 每轮重复刷屏。
  - 诊断 reason 明确提示用户或主 Agent 先查看 `workspace release watch <release>`，修复失败发布仓库状态后再执行 `workspace release publish <release>`。
  - 本批只生成可见诊断和 next action，不自动创建发布 job，也不绕过发布确认。
- TDD 记录：
  - 新增 `TestDaemonRunOnceRecordsPublishInProgressDiagnostic`。
  - 红灯：构造 `publish_in_progress` release 后，`RunOnce` 没有新增 release status event。
  - 绿灯：新增 daemon 扫描和 store 幂等诊断事件后 focused test 通过，并覆盖重复 `RunOnce` 不重复写事件。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-08-publish-in-progress-diagnostic.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run TestDaemonRunOnceRecordsPublishInProgressDiagnostic -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run 'TestDaemonRunOnceRecordsPublishInProgressDiagnostic|TestDaemonRunOnceCreatesPublishConfirmationForTestingCompletedRelease'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/store ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md` and `README.md`
- 后续批次：
  - 当前 batch 不自动创建发布重试 job；发布仍需要用户或主 Agent 在人工确认边界内主动调用 `release_publish`。

## Step 8: Requirement status events - Batch 9

- 日期：2026-07-10
- 状态：完成，daemon 自动推进 requirement workflow 时的 status event 审计已落地
- 范围：
  - daemon 新增 `setRequirementWorkflowStatus` helper。
  - helper 更新 requirement workflow 前读取旧状态，状态实际变化后写入 `requirement_status_events`。
  - 事件 actor 固定为 `workspace-daemon`，reason 按具体自动流程写入，job 触发的状态变化会绑定 job id。
  - 替换 coordinator 生产路径中的直接 `SetRequirementWorkflowStatus` 调用，覆盖 analysis claim、analysis completed、development entry、development completed、bugfix started/completed、release testing started、release test bug 回退和 retest。
  - 重复设置相同状态不会重复写 status event。
- TDD 记录：
  - 扩展 `TestDaemonRunOnceCreatesAnalysisJobAndAdvancesToAnalyzing`，要求 `analysis_generate` claim 后写 `pending_analysis -> analyzing` event，并绑定 analysis job id。
  - 红灯：analysis job 已推进到 `analyzing`，但 `requirement_status_events` 为空。
  - 绿灯：新增 daemon helper 并替换生产路径后 focused test 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-08-requirement-status-events.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run TestDaemonRunOnceCreatesAnalysisJobAndAdvancesToAnalyzing -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/store ./internal/coordinator ./internal/workspace ./internal/cli`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md` and `README.md`
- 后续批次：
  - 低层 `SetRequirementWorkflowStatus` 仍保持无事件 store primitive，测试和 service 可以按需要显式决定 actor、reason 和 job id。

## Step 8: Agent health scheduling - Batch 10

- 日期：2026-07-10
- 状态：完成，daemon worker pool 调度会跳过 `health_status=unavailable` 的 Agent
- 范围：
  - daemon RunOnce 在读取 worker pool 的 provider Agent 后，除了 disabled Agent 之外，也跳过 `health_status=unavailable` 的 Agent。
  - unavailable Agent 绑定的 queued job 不会被 claim，不会启动 runner，也不会增加 attempts。
  - 保持 `workspace agent health <name>` 作为显式 health check 入口；daemon 使用已保存的 health status，不在每个 tick 自动执行真实 provider `--help`。
- TDD 记录：
  - 新增 `TestDaemonRunOnceSkipsUnavailableAgentPool`。
  - 红灯：Agent 已被标记为 `unavailable` 后，daemon 仍 claim 并完成了 job。
  - 绿灯：调度 worker pool 时跳过 unavailable Agent 后，focused test 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-08-agent-health-scheduling.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run TestDaemonRunOnceSkipsUnavailableAgentPool -v`
- 当前边界：
  - daemon 不主动刷新 provider health；用户或主 Agent 需要通过 `workspace agent health <name>` 更新 unavailable/available 状态。

## Step 8: Release status events - Batch 11

- 日期：2026-07-10
- 状态：完成，daemon 自动推进 release workflow 时的 release status event 审计已落地
- 范围：
  - store 新增 `CreateReleaseStatusEvent`，支持显式写入 old/new status、actor、reason、test run id 和 job id。
  - daemon 新增 `setReleaseWorkflowStatus` helper，更新 release workflow 前读取旧状态，状态实际变化后写入 `release_status_events`。
  - `release_test` job 被 claim 后，release 从 `pending_testing` 进入 `testing` 时写事件，绑定当前 `release_test_run_id` 和 release test job id。
  - bugfix 后 release re-integrate 成功时，release 从 `testing` 回到 `pending_testing` 时写事件，reason 为 `release re-integrated for retest`。
  - retest 同轮创建并 claim 新 release test job 后，继续写新 test run 的 `pending_testing -> testing` 事件。
  - 已由 store 原子方法写事件的 publish、stale、testing completed、pending release 流程保持不重复记录。
- TDD 记录：
  - 扩展 `TestDaemonRunOnceCreatesReleaseTestRunSnapshotAndJobForPendingTesting`，要求 release test 启动写 `pending_testing -> testing` event。
  - 扩展 `TestDaemonRunOnceReintegratesReleaseAndQueuesRetestAfterBugfix`，要求 re-integrate 写 `testing -> pending_testing` event，并要求 retest 启动写新 test run 的 `pending_testing -> testing` event。
  - 红灯：release test 启动后 `release_status_events` 为空；retest 场景只看到最终 passed 后的 `testing -> testing_completed`。
  - 绿灯：新增 release status event helper 并替换 release testing/retest 生产路径后 focused tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-08-release-status-events.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run 'TestDaemonRunOnceCreatesReleaseTestRunSnapshotAndJobForPendingTesting|TestDaemonRunOnceReintegratesReleaseAndQueuesRetestAfterBugfix' -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/store ./internal/workspace ./internal/agent ./internal/coordinator ./internal/mcp ./internal/cli`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md` and `README.md`
- 后续批次：
  - 低层 `SetReleaseWorkflowStatus` 仍保持无事件 store primitive，生产路径如果需要实时 watch 可见，应使用 helper 或事务型 store 方法显式记录事件。

## Step 12: Analysis artifacts - Batch 1

- 日期：2026-07-03
- 状态：完成，Step 12 整体仍在进行中
- 范围：
  - 新增 `internal/coordinator/analysis.go`，承接 analysis 阶段 job 成功后的业务 post-processing。
  - `analysis_generate` 成功后解析 runner `result_json`，要求包含 `requirement_design` 和 `technical_design`。
  - 支持 artifact 输出为纯字符串，或 `{title, content}` / `{title, markdown}` 对象。
  - 使用 artifact service 写入 requirement 级 `requirement_design` 与 `technical_design` artifact，stage 为 `analysis`，并记录 job/run id、version、hash 和创建者。
  - 每个 artifact 写入后追加 `artifact_created` run event，保证用户 watch 执行流时能看到方案产物已生成。
  - artifact 写入完成后幂等创建 `analysis_review` job，job key 为 `analysis-review-<req-slug>-v<n>`，input 包含两份 artifact id/path 和默认 review policy。
  - post-run artifact 解析或写入失败时，把 job 重新排队并设置 backoff；达到最大尝试次数后标记 failed，避免产物缺失时静默成功。
  - 既有 pending analysis 测试更新为：第二轮可以消费新建的 review job，但不得重复创建 `analysis_generate`。
- TDD 记录：
  - 新增 `TestDaemonRunOnceCreatesAnalysisArtifactsAndReviewJob`。
  - 红灯：测试失败于 artifacts 为空，说明 `analysis_generate` 成功后尚未把 runner 输出落库。
  - 绿灯：实现 analysis post-processing、artifact 写入、`artifact_created` event 和 review job 创建后 focused test 通过。
  - 回归：更新 `TestDaemonRunOnceCreatesAnalysisJobAndAdvancesToAnalyzing`，确认不会重复创建 `analysis_generate`，并允许后续 `analysis_review` job 被正常消费。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-12-analysis-artifacts.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run TestDaemonRunOnceCreatesAnalysisArtifactsAndReviewJob`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/artifact ./internal/store ./internal/coordinator ./internal/cli`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fence balance check
- 后续批次：
  - Step 12 batch 2 需要执行 `analysis_review` job 的结果解析，生成独立 `analysis_review` artifact。
  - Step 12 batch 2 需要根据 `strict` / `no_high_risk` review policy 判定通过、创建 `analysis_revise` job 或标记 blocked。
  - Step 12/16 后续需要在 `analysis_completed` 后创建 `artifact_finalization` approval，并在 approval respond 时同事务 finalize 两类 artifact。

## Step 12: Analysis review policy - Batch 2

- 日期：2026-07-03
- 状态：完成，Step 12 整体仍在进行中
- 范围：
  - Store 新增 `RequirementWorkflowStatusAnalysisCompleted` 常量。
  - Store 新增 `GetReviewPolicyByName`，从 `review_policies` 表读取当前分析阶段 policy。
  - daemon 支持 `analysis_review` job 成功后的业务 post-processing。
  - `analysis_review` 成功后解析 runner `result_json`，要求包含独立 `analysis_review` 内容，并读取 `findings[].severity` / `max_severity`。
  - 使用 artifact service 写入 requirement 级 `analysis_review` artifact，stage 为 `analysis`，并记录 job/run id。
  - 每次 Review 写入 `artifact_created` 和 `review_result` run event，payload 包含 policy、是否通过、最高风险和 finding 数量。
  - `analysis-no-high-risk` policy 下，最高风险 `medium` 或以下通过，并把 requirement workflow 推进到 `analysis_completed`。
  - `high` / `critical` finding 不通过时，requirement 保持 `analyzing`，并幂等创建 `analysis_revise` job。
  - `analysis_revise` job key 为 `analysis-revise-<req-slug>-v<n>`，input 包含 review artifact id/path、policy、最高风险和 findings。
- TDD 记录：
  - 新增 `TestDaemonRunOnceCompletesAnalysisReviewWhenNoHighRiskFindings`。
  - 新增 `TestDaemonRunOnceCreatesAnalysisReviseJobWhenReviewHasHighRiskFinding`。
  - 红灯：coordinator tests 因 `RequirementWorkflowStatusAnalysisCompleted` 不存在而构建失败，说明通过状态尚未实现。
  - 绿灯：实现 review output 解析、review artifact、policy 判定、状态推进和 revise job 后 focused tests 通过。
  - 回归：更新 `TestDaemonRunOnceCreatesAnalysisJobAndAdvancesToAnalyzing` 的 fake runner，让第二轮 review job 返回 review JSON，避免用 generate JSON 误测 review post-processing。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-12-analysis-review-policy.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run 'TestDaemonRunOnceCompletesAnalysisReviewWhenNoHighRiskFindings|TestDaemonRunOnceCreatesAnalysisReviseJobWhenReviewHasHighRiskFinding'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/store ./internal/coordinator ./internal/cli`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fence balance check
- 后续批次：
  - Step 12 batch 3 需要实现 `analysis_revise` job 输出新版 `requirement_design` / `technical_design` artifact，并重新创建下一轮 `analysis_review` job。
  - Step 12 batch 3 需要补最大 review 轮次耗尽后的 blocked 处理。
  - Step 12/16 后续需要在 `analysis_completed` 后创建 `artifact_finalization` approval，并在 approval respond 时同事务 finalize 两类 artifact。

## Step 12: Analysis revise loop - Batch 3

- 日期：2026-07-03
- 状态：完成，Step 12 整体仍在进行中
- 范围：
  - daemon 支持 `analysis_revise` job 成功后的业务 post-processing。
  - `analysis_revise` 复用 `analysis_generate` 的 runner `result_json` 格式，要求包含新版 `requirement_design` 和 `technical_design`。
  - revise job 成功后写入新版 requirement 级 `requirement_design` / `technical_design` artifact，stage 为 `analysis`，并记录 job/run id。
  - 新版技术方案 artifact 创建完成后，幂等创建下一轮 `analysis_review` job，例如 `analysis-review-pay-flow-v2`。
  - Store 新增 `BlockAgentJob`，用于把 job 标记为 `blocked` 并保存阻塞原因。
  - Review 不通过时按 `analysis_review` artifact version 判断当前轮次；达到 `review_policies.max_review_rounds` 后不再创建 revise job。
  - 最大轮次耗尽时写入 `blocked` run event，并把当前 review job 标记为 `blocked`。
- TDD 记录：
  - 新增 `TestDaemonRunOnceCreatesNewAnalysisArtifactsFromReviseJob`。
  - 红灯：测试失败于找不到 `requirement_design` v2，说明 `analysis_revise` 尚未生成新版方案 artifact。
  - 新增 `TestDaemonRunOnceBlocksAnalysisWhenReviewRoundsAreExhausted`。
  - 红灯：第 5 轮 Review 后 job 仍为 `succeeded`，说明 max review rounds 尚未阻塞循环。
  - 绿灯：实现 `analysis_revise` post-processing、`BlockAgentJob` 和 max round blocked 后 focused tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-12-analysis-revise-loop.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run 'TestDaemonRunOnceCreatesNewAnalysisArtifactsFromReviseJob|TestDaemonRunOnceBlocksAnalysisWhenReviewRoundsAreExhausted'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/store ./internal/coordinator ./internal/cli`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fence balance check
- 后续批次：
  - Step 12 batch 4 需要在 `analysis_completed` 后创建 `artifact_finalization` approval。
  - Step 12/16 需要在 approval respond 时同事务 finalize `requirement_design` 和 `technical_design`。
  - 用户编辑 artifact 后再 finalize 的 CLI/service 闭环已由 Step 12 Batch 6 补齐。

## Step 12: Artifact finalization - Batch 4

- 日期：2026-07-03
- 状态：完成，Step 12 整体仍在进行中
- 范围：
  - `analysis_review` 通过并推进到 `analysis_completed` 后，daemon 创建 `artifact_finalization` approval。
  - approval key 为 `artifact-finalization-<req-slug>`，按 requirement + approval type 幂等去重。
  - approval payload 包含候选 `requirement_design_artifact_ids` 和 `technical_design_artifact_ids`；options 默认使用最新两类 artifact。
  - daemon 写入 `approval_requested` run event，保证用户实时 watch 能看到终稿确认请求。
  - Store 新增 `RespondArtifactFinalizationApproval` 专用事务方法。
  - artifact finalization approve 时，同一事务内完成：校验 approval pending、校验两份 artifact 属于同一 requirement 且类型正确、清理同类旧 final、设置两份新 final、更新 requirement final artifact id、关闭 approval。
  - workspace service 新增 artifact finalization response 解析，支持 response JSON 或 typed params。
  - CLI `approval respond` 新增 `--final-requirement-design-artifact` 和 `--final-technical-design-artifact`。
- TDD 记录：
  - 扩展 `TestDaemonRunOnceCompletesAnalysisReviewWhenNoHighRiskFindings`，要求 Review 通过后生成 pending `artifact_finalization` approval，并写 `approval_requested` event。
  - 红灯：coordinator focused test 失败于没有 pending artifact finalization approval。
  - 新增 `TestRespondArtifactFinalizationApprovalFinalizesRequirementDesignAndTechnicalDesign`。
  - 红灯：workspace test 因 `RespondApprovalParams` 缺少 final artifact id 字段而构建失败。
  - 新增 `TestRespondArtifactFinalizationApprovalRejectsWrongArtifactType`，覆盖类型不匹配时 approval 保持 pending 且 artifact 不被 finalize。
  - 新增 `TestApprovalRespondArtifactFinalizationFlags`，覆盖 CLI typed flags。
  - 绿灯：实现 coordinator approval、store 同事务 finalize、workspace response parser 和 CLI flags 后 focused tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-12-artifact-finalization.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run TestDaemonRunOnceCompletesAnalysisReviewWhenNoHighRiskFindings`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/workspace -run 'TestRespondArtifactFinalizationApprovalFinalizesRequirementDesignAndTechnicalDesign|TestRespondArtifactFinalizationApprovalRejectsWrongArtifactType'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli -run TestApprovalRespondArtifactFinalizationFlags`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/store ./internal/coordinator ./internal/workspace ./internal/cli`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fence balance check
- 后续批次：
  - Step 12 batch 5 需要实现 `req advance <req> pending_development`，并要求两类 final artifact 都存在。
  - 用户编辑 artifact 生成新版本后再 finalize 的 CLI/service 闭环已由 Step 12 Batch 6 补齐。
  - Step 13 可以在 pending development guard 完成后开始接开发阶段 loop。

## Step 12: Pending development advance - Batch 5

- 日期：2026-07-03
- 状态：完成，Step 12 整体仍在进行中
- 范围：
  - CLI 新增 `req advance <req> pending_development`。
  - workspace service 新增 `AdvanceRequirementWorkflow`，只开放当前实现的 `pending_development` target。
  - Store 新增 `RequirementWorkflowStatusPendingDevelopment` 和 `AdvanceRequirementToPendingDevelopment`。
  - `analysis_completed -> pending_development` 在同一事务内校验当前状态、final `requirement_design`、final `technical_design`，并同步 `analysis_final_artifact_id` / `technical_final_artifact_id`。
  - 终稿门禁以 artifact `is_final` 为准，兼容 `artifact_finalization` approval 和 `req artifact finalize` 两条定稿路径。
- TDD 记录：
  - 新增 `TestAdvanceRequirementWorkflowToPendingDevelopmentRequiresFinalAnalysisArtifacts`。
  - 红灯：service 缺少 `AdvanceRequirementWorkflow`，store 缺少 `RequirementWorkflowStatusPendingDevelopment`。
  - 新增 `TestAdvanceRequirementWorkflowToPendingDevelopmentSyncsFinalArtifactIDs`，覆盖推进时同步 final artifact id。
  - 新增 `TestReqAdvanceToPendingDevelopmentRequiresFinalAnalysisArtifacts`，覆盖 CLI 缺终稿报错与成功输出。
  - 扩展 `TestRootCommandIncludesDocumentedCommandSurface`，要求存在 `req advance`。
  - 绿灯：实现 store 事务门禁、service target guard 和 CLI command 后 focused tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-12-pending-development-advance.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/workspace ./internal/cli`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fence balance check
- 后续批次：
  - 用户编辑 artifact 生成新版本后再 finalize 的 CLI/service 闭环已由 Step 12 Batch 6 补齐。
  - Step 13 可以开始实现 `pending_development` 到 `developing` 的开发阶段入口：准备 workspace、创建 implementation plan job、进入 coding loop。

## Step 12: Artifact edit CLI - Batch 6

- 日期：2026-07-09
- 状态：完成，Step 12 用户编辑 artifact 新版本闭环已落地
- 范围：
  - CLI 新增 `req artifact create <req>`，作为 requirement artifact 的用户编辑入口。
  - 命令支持 `--type`、`--stage`、`--title`、`--content` 和 `--content-file`。
  - `--content` 与 `--content-file` 互斥；缺少内容输入时直接报错，不进入 service。
  - 创建 artifact 时复用 workspace service 的 `CreateRequirementArtifact`，因此沿用 entity 校验、文件落盘、sha256 和同类版本自增。
  - 用户编辑创建的新 artifact 记录 `created_by=user`，默认不自动 final。
  - 用户可以随后用 `req artifact finalize <req> <artifact-id>` 定稿新版；同类旧 final 会被事务性清除。
  - README、技术方案和实施步骤补充 `req artifact create` 命令面。
- TDD 记录：
  - 扩展 `TestRootCommandIncludesDocumentedCommandSurface`，要求存在 `req artifact create`。
  - 新增 `TestReqArtifactCreateCreatesEditableRequirementArtifactVersion`，覆盖从文件创建 v2、created-by=user、list 可见、finalize v2 后旧 final 清除。
  - 新增 `TestReqArtifactCreateRejectsConflictingContentInputs`，覆盖 `--content` 和 `--content-file` 互斥。
  - 红灯：focused CLI 测试失败于 `unknown flag: --type`，说明 create 命令尚未接入。
  - 绿灯：实现 `newReqArtifactCreateCommand` 和内容输入解析后 focused CLI 测试通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-12-artifact-edit-cli.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli -run 'TestReqArtifactCreate|TestArtifactCommands|TestRootCommandIncludesDocumentedCommandSurface'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/config ./internal/store ./internal/workspace ./internal/mcp ./internal/cli ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fence balance check over `docs/*.md` and `README.md`
- 后续批次：
  - Step 12 的分析方案生成、Review loop、终稿选择、进入待开发门禁和用户编辑 artifact 新版本闭环均已落地；后续工作继续推进 Step 13/14/15 中已记录的开发、测试、发布剩余能力。

## Step 13: Prepare requirement workspace - Batch 1

- 日期：2026-07-03
- 状态：完成，Step 13 整体仍在进行中
- 范围：
  - workspace service 新增 `PrepareRequirementWorkspace(ctx, keyOrSlug)`。
  - 新增 `PrepareRequirementWorkspaceResult`，返回 requirement、repo binding 快照、创建 worktree 数和复用 worktree 数。
  - 方法只处理已存在 requirement，不调用 `CreateRequirement`，不插入新的 requirement row。
  - requirement 没有 repo binding 时返回可恢复错误。
  - 每个绑定 repo 会先 fetch，再按 relation 记录的 worktree path 准备 feature worktree。
  - 缺失 worktree 时创建；已有 worktree 时要求是 Git working tree、当前 branch 是 requirement feature branch、且没有未提交改动。
  - 任一 repo 失败时清理本次新创建的 worktree，不删除进入方法前已存在的 worktree。
  - 成功后把可开发 relation 恢复为 `active`，用于后续 coding/finish 流程。
  - Git manager 新增 `CurrentBranch`，用于复用已有 worktree 前的分支门禁。
- TDD 记录：
  - 新增 `TestPrepareRequirementWorkspaceForDevelopmentRequiresRepoBindings`。
  - 新增 `TestPrepareRequirementWorkspaceForDevelopmentCreatesMissingWorktree`。
  - 新增 `TestPrepareRequirementWorkspaceForDevelopmentReusesCleanWorktree`。
  - 新增 `TestPrepareRequirementWorkspaceForDevelopmentBlocksDirtyOrWrongBranchWorktree`。
  - 红灯：workspace focused test 因 `Service.PrepareRequirementWorkspace` 未定义而构建失败。
  - 绿灯：实现 service 准备逻辑和 Git `CurrentBranch` 后 `go test -count=1 ./internal/workspace -run Development` 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-13-prepare-workspace.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/workspace -run Development`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/workspace`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fence balance check
- 后续批次：
  - Step 13 batch 2 需要让 daemon/coordinator 扫描 `pending_development`，调用 `PrepareRequirementWorkspace`，成功后推进到 `developing` 并创建 `implementation_plan` job。
  - Step 13 后续需要实现 plan artifact 拆分 step job、step review/fix loop、implementation report/review 和 `FinishRequirement` 后的 `development_completed`。

## Step 13: Development entry - Batch 2

- 日期：2026-07-03
- 状态：完成，Step 13 整体仍在进行中
- 范围：
  - Store 新增 `RequirementWorkflowStatusDeveloping` 常量。
  - daemon `RunOnce` 新增 development entry lane：在补齐 analysis job 后、worker pool claim 前扫描 `pending_development`。
  - `pending_development` requirement 必须已指定 enabled coding agent、存在 enabled coding worker pool，且 requirement final artifact id 齐全。
  - daemon 调用 `PrepareRequirementWorkspace`，成功后把需求推进到 `developing`。
  - 幂等创建 `implementation-plan-<req-key>` coding job，`job_type=implementation_plan`，`priority=70`。
  - implementation plan job input 包含 requirement id/key/title、`developing` workflow status、workspace path、final `requirement_design` / `technical_design` artifact id、worktree 创建/复用统计和 repo binding 数。
  - `RunOnceResult` 新增 `DevelopmentJobs`，记录被 claim 的 `implementation_plan` job 数量。
- TDD 记录：
  - 新增 `TestDaemonRunOncePreparesDevelopmentWorkspaceAndCreatesImplementationPlanJob`。
  - 红灯：coordinator focused test 因 `RequirementWorkflowStatusDeveloping` 未定义而构建失败。
  - 绿灯：实现 developing 常量、development entry lane、coding worker pool 查找、workspace 准备、workflow 推进和 implementation plan job 创建后 focused test 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-13-development-entry.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run TestDaemonRunOncePreparesDevelopmentWorkspaceAndCreatesImplementationPlanJob`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fence balance check
- 后续批次：
  - Step 13 batch 3 需要处理 `implementation_plan` job 成功输出，生成 `implementation_plan` artifact，并拆分 coding step jobs。
  - Step 13 后续继续实现 step review/fix loop、implementation report/review 和 `FinishRequirement` 后的 `development_completed`。

## Step 13: Implementation plan artifact and step jobs - Batch 3

- 日期：2026-07-03
- 状态：完成，Step 13 整体仍在进行中
- 范围：
  - coordinator 新增 development post-processing，`afterWorkerSuccess` 支持 `implementation_plan` job。
  - 解析 `implementation_plan` job 的 `result_json`：
    - `implementation_plan` 写入 requirement 级 artifact。
    - `steps` 至少一项，每项 `prompt` 必填。
  - 生成 `stage=development`、`artifact_type=implementation_plan` 的 artifact，并关联 source job/run。
  - artifact 创建后写 `artifact_created` run event，保证用户实时 watch 可见。
  - 按 step 顺序幂等创建 `implementation-step-<req-slug>-<NNN>` coding jobs。
  - step job input 包含 requirement、workspace path、plan artifact id/path、step index/key/title/prompt。
- TDD 记录：
  - 新增 `TestDaemonRunOnceCreatesImplementationPlanArtifactAndStepJobs`。
  - 红灯：focused test 失败于未生成 `implementation_plan` artifact。
  - 绿灯：新增 `internal/coordinator/development.go`，实现 plan output parser、artifact 创建、run event 和 step job 拆分后 focused tests 通过。
  - 调整 Batch 2 入口测试断言：第二次 RunOnce 可能继续领取 step job，测试只要求没有重复创建 implementation plan job。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-13-implementation-plan.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run TestDaemonRunOnceCreatesImplementationPlanArtifactAndStepJobs`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run 'TestDaemonRunOncePreparesDevelopmentWorkspaceAndCreatesImplementationPlanJob|TestDaemonRunOnceCreatesImplementationPlanArtifactAndStepJobs'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fence balance check
- 后续批次：
  - Step 13 batch 4 需要执行 `implementation_step` job，并在每步完成后创建 `implementation_step_review` job。
  - Step 13 后续继续实现 step review/fix loop、implementation report/review 和 `FinishRequirement` 后的 `development_completed`。

## Step 13: Step review job - Batch 4

- 日期：2026-07-03
- 状态：完成，Step 13 整体仍在进行中
- 范围：
  - daemon `RunRequest` 支持从 job input JSON 读取 `workspace_path`，存在时作为 provider CWD。
  - `implementation_step` job 因此在 requirement workspace 中执行。
  - `afterWorkerSuccess` 支持 `implementation_step` job。
  - `implementation_step` 成功后解析 step input，并幂等创建 `implementation-step-review-<req-slug>-<NNN>` job。
  - review job 使用 role `coding`、job type `implementation_step_review`。
  - review job input 包含 requirement、workspace path、implementation plan artifact id/path、step job id/key、step result JSON、step index/key/title/prompt。
  - review job priority 与当前 step 顺序匹配，确保同一步 review 优先于后续 step。
- TDD 记录：
  - 新增 `TestDaemonRunOnceRunsImplementationStepInRequirementWorkspaceAndCreatesReviewJob`。
  - 红灯：focused test 失败于 `implementation_step` CWD 仍为 workspace home，而非 requirement workspace。
  - 绿灯：实现 job input workspace path 解析、step success post-processing 和 review job 创建后 focused tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-13-step-review-job.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run TestDaemonRunOnceRunsImplementationStepInRequirementWorkspaceAndCreatesReviewJob`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run 'TestDaemonRunOncePreparesDevelopmentWorkspaceAndCreatesImplementationPlanJob|TestDaemonRunOnceCreatesImplementationPlanArtifactAndStepJobs|TestDaemonRunOnceRunsImplementationStepInRequirementWorkspaceAndCreatesReviewJob'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fence balance check
- 后续批次：
  - Step 13 batch 5 需要处理 `implementation_step_review` 输出，按 review policy 决定继续下一步或创建 step fix job。
  - Step 13 后续继续实现 implementation report/review 和 `FinishRequirement` 后的 `development_completed`。

## Step 13: Step review output and fix job - Batch 5

- 日期：2026-07-03
- 状态：完成，Step 13 整体仍在进行中
- 范围：
  - `afterWorkerSuccess` 支持 `implementation_step_review` job。
  - `implementation_step_review` result JSON 会解析为 review artifact 内容、findings 和 max severity。
  - 成功解析后创建 requirement 级 `implementation_step_review` artifact，stage 为 `development`，并关联 review job/run。
  - review artifact 创建后写入用户可见 `artifact_created` event。
  - 开发阶段 review policy 使用默认种子策略 `development-no-high-risk`。
  - review 通过时写入用户可见 `review_result` event，不创建 fix job，队列继续后续 step。
  - review 不通过时幂等创建 `implementation-step-fix-<req-slug>-<NNN>-v<review-version>` job。
  - fix job input 携带 requirement、workspace path、review policy、max severity、findings、implementation plan artifact、step job result 和 review artifact 信息。
  - `max_review_rounds` 按同一个 step 的 review round 统计，不使用 requirement 下 `implementation_step_review` artifact 的全局 version。
  - 同一个 step 达到 policy `max_review_rounds` 后仍不通过时，review job 会被标记为 blocked，并写入 `blocked` event。
- TDD 记录：
  - 新增 `TestDaemonRunOnceCompletesImplementationStepReviewAndCreatesFixJobForHighRiskFindings`。
  - 新增 `TestDaemonRunOnceCompletesImplementationStepReviewWithoutFixWhenPolicyPasses`。
  - 红灯：focused test 失败于缺少 `implementation_step_review` artifact。
  - 绿灯：实现 review output post-processing、开发阶段策略判定和 fix job 创建后 focused tests 通过。
  - 自审补充 `TestDaemonRunOnceUsesPerStepReviewRoundForDevelopmentMaxReviewRounds`。
  - 红灯：当同一 requirement 下已有两个其他 step review artifact 时，当前 step 首轮 high-risk review 被全局 artifact version 误判为超限，未创建 fix job。
  - 绿灯：改为按同一 step 的 review round 统计后，当前 step 首轮 high-risk review 正常创建 fix job。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-13-step-review-output.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run 'TestDaemonRunOnceCompletesImplementationStepReview'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run TestDaemonRunOnceUsesPerStepReviewRoundForDevelopmentMaxReviewRounds`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run 'TestDaemonRunOncePreparesDevelopmentWorkspaceAndCreatesImplementationPlanJob|TestDaemonRunOnceCreatesImplementationPlanArtifactAndStepJobs|TestDaemonRunOnceRunsImplementationStepInRequirementWorkspaceAndCreatesReviewJob|TestDaemonRunOnceCompletesImplementationStepReview'`
- 后续批次：
  - Step 13 batch 6 需要处理 `implementation_step_fix` job 执行结果，并在修复完成后创建新一轮 step review。
  - Step 13 后续继续实现全部 step 通过后的 implementation report/review 和 `FinishRequirement` 后的 `development_completed`。

## Step 13: Fix job re-review - Batch 6

- 日期：2026-07-09
- 状态：完成，Step 13 整体仍在进行中
- 范围：
  - `afterWorkerSuccess` 支持 `implementation_step_fix` job。
  - `implementation_step_fix` job 成功后解析 fix input，校验 workspace path、step index、原始 step job key 和触发 fix 的 review artifact。
  - fix job 继续在 requirement workspace 中执行。
  - fix job 成功后按同一个 step 的 review artifact 数量计算下一轮 review round。
  - 幂等创建 `implementation-step-review-<req-slug>-<NNN>-r<round>` job，例如第二轮 review 为 `implementation-step-review-pay-flow-001-r2`。
  - 下一轮 review job input 携带上一轮 review policy、max severity、findings、触发 fix 的 review artifact、原始 step job result、fix job id/key/result 和 step 元数据。
  - 下一轮 review job 复用 Batch 5 的 review artifact、review_result、fix job 和 max round 逻辑。
- TDD 记录：
  - 新增 `TestDaemonRunOnceRunsImplementationStepFixAndCreatesNextReviewRound`。
  - 红灯：focused test 失败于 `implementation-step-review-pay-flow-001-r2` 不存在。
  - 绿灯：实现 fix job post-processing 和 after-fix review job 创建后 focused tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-13-fix-rereview.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run TestDaemonRunOnceRunsImplementationStepFixAndCreatesNextReviewRound`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run 'TestDaemonRunOncePreparesDevelopmentWorkspaceAndCreatesImplementationPlanJob|TestDaemonRunOnceCreatesImplementationPlanArtifactAndStepJobs|TestDaemonRunOnceRunsImplementationStepInRequirementWorkspaceAndCreatesReviewJob|TestDaemonRunOnceCompletesImplementationStepReview|TestDaemonRunOnceUsesPerStepReviewRoundForDevelopmentMaxReviewRounds|TestDaemonRunOnceRunsImplementationStepFixAndCreatesNextReviewRound'`
- 后续批次：
  - Step 13 batch 7 需要在所有 implementation steps 和 step reviews 通过后生成 `implementation_report` 和 `implementation_review`。
  - Step 13 后续继续实现 `FinishRequirement` 调用和 `development_completed` 状态推进。

## Step 13: Development reports - Batch 7

- 日期：2026-07-09
- 状态：完成，Step 13 整体仍在进行中
- 范围：
  - `implementation_step_review` 通过后会检查 development report readiness。
  - readiness 要求 requirement 已有 `implementation_plan` artifact，至少有一个 `implementation_step` job，所有 step job 均为 `succeeded`，且每个 step 的最新 `implementation_step_review` 按 `development-no-high-risk` 策略通过。
  - readiness 未满足时不创建报告 job，避免 step 未完成、缺少 review、或最新 review 失败时提前生成报告。
  - readiness 满足时幂等创建 `implementation-report-<req-slug>` job。
  - report job 使用 role `coding`、job type `implementation_report`、priority `95`。
  - report job input 包含 requirement、workspace path、implementation plan artifact、step job snapshots 和 step review snapshots。
  - report job 在 requirement workspace 中执行。
  - `implementation_report` job 成功后解析 result JSON，并创建 `implementation_report` 和 `implementation_review` 两类 requirement development artifacts。
  - 两类 artifact 均关联 report job/run，并写入用户可见 `artifact_created` event。
- TDD 记录：
  - 新增 `TestDaemonRunOnceCreatesDevelopmentReportsAfterAllStepReviewsPass`。
  - 红灯：focused test 失败于 `implementation-report-pay-flow` 不存在。
  - 绿灯：实现 report readiness 检测、report job 创建和 report artifact 落库后 focused tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-13-development-reports.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run TestDaemonRunOnceCreatesDevelopmentReportsAfterAllStepReviewsPass`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run 'TestDaemonRunOncePreparesDevelopmentWorkspaceAndCreatesImplementationPlanJob|TestDaemonRunOnceCreatesImplementationPlanArtifactAndStepJobs|TestDaemonRunOnceRunsImplementationStepInRequirementWorkspaceAndCreatesReviewJob|TestDaemonRunOnceCompletesImplementationStepReview|TestDaemonRunOnceUsesPerStepReviewRoundForDevelopmentMaxReviewRounds|TestDaemonRunOnceRunsImplementationStepFixAndCreatesNextReviewRound|TestDaemonRunOnceCreatesDevelopmentReportsAfterAllStepReviewsPass'`
- 后续批次：
  - Step 13 batch 8 需要在 development reports 落库后调用 `FinishRequirement`。
  - 只有当底层 requirement stage 进入 `ready` 时，才能推进 `workflow_status=development_completed`。

## Step 13: Finish development - Batch 8

- 日期：2026-07-09
- 状态：完成，Step 13 主开发闭环具备最小可执行路径
- 范围：
  - `implementation_report` job 成功后，在创建 `implementation_report` 和 `implementation_review` artifacts 之后调用底层 workspace service `FinishRequirement`。
  - `FinishRequirement` 复用现有 `req finish` 语义，负责提交 active worktree、推送 feature branch、清理 requirement worktree，并把底层 requirement 标记为 ready。
  - daemon 重新读取 requirement，只有 `ReadyAt` 有值时才推进 `workflow_status=development_completed`。
  - 新增 `RequirementWorkflowStatusDevelopmentCompleted` store 常量。
  - 本批 workflow 推进先使用 `SetRequirementWorkflowStatus`；daemon status event 审计已由后续 Step 8 Batch 9 补齐。
- TDD 记录：
  - 新增 `TestDaemonRunOnceFinishesRequirementAndMarksDevelopmentCompletedAfterReports`。
  - 红灯 1：测试因 `RequirementWorkflowStatusDevelopmentCompleted` 常量缺失而构建失败。
  - 红灯 2：补齐常量后，focused test 失败于 report job 后 requirement `ReadyAt` 未设置。
  - 绿灯：report job 后处理调用 `FinishRequirement`，并在 `ReadyAt` guard 通过后设置 `development_completed`，focused tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-13-finish-development.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run TestDaemonRunOnceFinishesRequirementAndMarksDevelopmentCompletedAfterReports`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run 'TestDaemonRunOncePreparesDevelopmentWorkspaceAndCreatesImplementationPlanJob|TestDaemonRunOnceCreatesImplementationPlanArtifactAndStepJobs|TestDaemonRunOnceRunsImplementationStepInRequirementWorkspaceAndCreatesReviewJob|TestDaemonRunOnceCompletesImplementationStepReview|TestDaemonRunOnceUsesPerStepReviewRoundForDevelopmentMaxReviewRounds|TestDaemonRunOnceRunsImplementationStepFixAndCreatesNextReviewRound|TestDaemonRunOnceCreatesDevelopmentReportsAfterAllStepReviewsPass|TestDaemonRunOnceFinishesRequirementAndMarksDevelopmentCompletedAfterReports'`
- 后续批次：
  - Step 14 可以开始实现 release 测试和 bugfix loop。
  - `requirement_status_events` 审计已由后续 Step 8 Batch 9 补齐；finish failure 后 artifact 重试幂等策略、cleanup-pending 异常路径测试仍可继续补强。

## Step 14: Release test entry - Batch 1

- 日期：2026-07-09
- 状态：完成，Step 14 集成测试闭环仍在进行中
- 范围：
  - 新增 requirement workflow 状态 `pending_testing`、`testing`。
  - 新增 release workflow 状态 `pending_testing`、`testing`。
  - store 支持 release workflow 查询和更新：`SetReleaseWorkflowStatus`、`AssignReleaseTestAgent`、`ListReleaseWorkflowsByStatus`。
  - daemon 每轮扫描 `pending_testing` release，校验 testing agent 和 testing worker pool 后创建 release test run。
  - release test run 保存 release、testing agent、工作目录、测试命令和 `test_command_source`。
  - 测试命令解析支持 `release_default` 和 `agent_default`；显式 `--test-command` 已由后续 `StartReleaseTest` service 和 Step 14 Batch 9 CLI 落地。
  - 缺少测试命令时不会创建 `release_test` job；该边界已在 Step 14 batch 3 补齐为 `test_command_missing` approval 和 `waiting_user_input` test run。
  - daemon 基于 release integration 快照创建 `release_test_run_requirements`，记录 requirement+repo+feature commit+release commit 以及当时的 requirement workflow status。
  - 幂等创建 `release-test-<release-slug>` job，role 为 `testing`，job type 为 `release_test`。
  - `release_test` job input 携带 `release_test_run_id`、测试命令、命令来源、工作目录和快照摘要。
  - worker claim `release_test` job 后，release workflow 推进到 `testing`，release 内 active requirements 推进到 `testing`。
- TDD 记录：
  - 新增 `TestDaemonRunOnceCreatesReleaseTestRunSnapshotAndJobForPendingTesting`。
  - 新增无命令保护测试，防止无命令时直接生成 `release_test` job。
  - 红灯 1：测试构建失败，缺少 testing 状态常量、release workflow store 方法和 JSON import。
  - 红灯 2：补齐 store/test 编译问题后，focused test 失败于 daemon 没有创建 release test job。
  - 红灯 3：无测试命令场景会错误创建 `release_test` job。
  - 绿灯：实现 release test entry daemon lane、快照落库、job input、claim 状态推进和缺少命令时保留 pending 状态后 focused tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-14-release-test-entry.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run TestDaemonRunOnceCreatesReleaseTestRunSnapshotAndJobForPendingTesting`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run 'TestDaemonRunOnceCreatesReleaseTestRunSnapshotAndJobForPendingTesting|TestDaemonRunOnceCreatesTestCommandMissingApprovalWithoutTestCommand'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md`
- 后续批次：
  - Step 14 batch 2 需要实现 `release_test` 输出解析、`test_report` artifact 和 `release_test_runs.summary_artifact_id`。
  - Step 14 batch 3 需要实现缺少测试命令时的 `test_command_missing` approval。
  - Step 14 batch 4 需要实现测试失败创建 bug、CodingAgent 修复和重新集成测试。

## Step 14: Release test report - Batch 2

- 日期：2026-07-09
- 状态：完成，Step 14 集成测试闭环仍在进行中
- 范围：
  - `afterWorkerSuccess` 支持 `release_test` job。
  - `release_test` job claim 后解析 input 中的 `release_test_run_id`，并把对应 test run 标记为 `running`。
  - `release_test` job 成功后解析 testing agent 的 `result_json`，要求包含 `status=passed|failed` 和非空 `test_report`。
  - `test_report` 支持字符串或 `{title, content}` 对象格式，复用既有 artifact 输出解析。
  - daemon 创建 `entity_type=release_test_run`、`artifact_type=test_report`、`stage=testing` 的 artifact。
  - test report artifact 关联 release test job/run，并写入用户可见 `artifact_created` event。
  - daemon 调用 artifact service 设置 `release_test_runs.summary_artifact_id`，复用 service/store 的同 entity、同 test run、同 artifact type 校验。
  - summary 设置成功后，daemon 按输出 status 把 test run 更新为 `passed` 或 `failed`。
- TDD 记录：
  - 新增 `TestDaemonRunOnceCreatesReleaseTestReportArtifactAndSummary`。
  - 红灯：focused test 失败于 release test run status 仍为 `queued`，且没有 summary artifact。
  - 绿灯：实现 test run status 更新、release test 输出解析、test report artifact 创建、summary 绑定和 artifact event 后 focused tests 通过。
  - 回归调整：Step 14 batch 1 的 release test entry 测试 FakeRunner 输出改为合法 `test_report`，匹配当前 testing agent contract。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-14-test-report.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run 'TestDaemonRunOnceCreatesReleaseTestRunSnapshotAndJobForPendingTesting|TestDaemonRunOnceCreatesReleaseTestReportArtifactAndSummary|TestDaemonRunOnceCreatesTestCommandMissingApprovalWithoutTestCommand'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md`
- 后续批次：
  - Step 14 batch 4 需要实现测试失败创建 bug、CodingAgent 修复和重新集成测试。
  - Step 14 batch 5 需要实现无 open bug 且测试通过后的 `testing_completed` 和 `active_test_run_id`。

## Step 17: Waiting user input in daemon E2E - Batch 1

- 日期：2026-07-09
- 状态：完成，fake provider E2E 的人工确认前置门禁已落地
- 范围：
  - daemon 现在识别 runner 返回的 `waiting_user_input` 状态。
  - provider 或 fake runner 创建 pending approval 并把 job 标记为 `waiting_user_input` 后，daemon 不再把该状态当成失败。
  - 等待用户输入的 job 不会触发 automatic retry，也不会递增 failed/retried 统计。
  - worker instance 会回到 idle，避免一个等待人工确认的 job 占住 worker pool capacity。
  - 第二轮 daemon tick 不会重复 claim 等待中的 job，直到用户通过 `approval respond` 恢复为 queued。
  - 新增 test-only `waitingUserInputRunner`，模拟 fake provider 创建 `requirement_clarification` approval、写 `approval_requested` / `run_completed` events，并返回 `waiting_user_input`。
- TDD 记录：
  - 新增 `TestDaemonRunOnceLeavesWaitingUserInputJobForApproval`。
  - 红灯：测试失败，`RunOnce()` 把 `waiting_user_input` 计为 failed 并执行 retry，说明 daemon 尚未保留人工确认等待态。
  - 绿灯：daemon worker loop 增加 `waiting_user_input` 分支，只释放 worker，不重试、不失败。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-17-waiting-user-input.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run 'TestDaemonRunOnceLeavesWaitingUserInputJobForApproval|TestDaemonRunOnceExecutesQueuedJobWithFakeRunner'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/config ./internal/store ./internal/workspace ./internal/mcp ./internal/cli ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md` and `README.md`
- 后续批次：
  - Step 17 Batch 2 需要把 approval respond 后恢复 queued 的 analysis job 接入 fake provider E2E，并继续覆盖分析 artifact、终稿确认和进入开发阶段。

## Step 17: Clarification resume analysis E2E - Batch 2

- 日期：2026-07-09
- 状态：完成，人工澄清后的 analysis job 恢复链路已闭环到 `pending_development`
- 范围：
  - `RespondApproval` 在 `requirement_clarification` approval approved 后，把用户响应追加到原 agent job 的 `input_json.clarification_responses`。
  - 追加内容包含 `approval_key`、`status`、澄清 `prompt`、请求 `payload` 和用户 `response`，并同步维护 `last_clarification_response` 方便 agent 获取最近一次人工确认。
  - 新增 store 方法 `UpdateAgentJobInputJSON`，用于保留原 job 并原地补充恢复执行上下文。
  - waiting job 被补充上下文后仍通过既有 `ResumeAgentJobAfterApproval` 恢复为 `queued`。
  - 新增 fake provider E2E：pending analysis 创建 `analysis_generate` job，首次运行进入 `waiting_user_input`，用户响应 clarification 后第二次运行能读到补充上下文。
  - E2E 继续覆盖 requirement/technical analysis artifacts、analysis review artifact、artifact finalization approval、用户终稿确认和推进到 `pending_development`。
- TDD 记录：
  - 扩展 `TestRespondApprovalRestoresWaitingJobAndWritesRunEvent`，要求 resumed job input 包含 `clarification_responses` 和用户响应。
  - 新增 `TestDaemonRunOnceResumesClarificationAndFinalizesAnalysisArtifacts`。
  - 红灯 1：service focused test 失败，resumed job input 仍为 `{}`。
  - 红灯 2：coordinator E2E 失败，第二次 analysis prompt 没有包含 `answer=stripe`。
  - 绿灯：实现 job input 补充和原 job 恢复后，service 与 coordinator focused tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-17-clarification-resume.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/workspace -run TestRespondApprovalRestoresWaitingJobAndWritesRunEvent`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run TestDaemonRunOnceResumesClarificationAndFinalizesAnalysisArtifacts`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/config ./internal/store ./internal/workspace ./internal/mcp ./internal/cli ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md` and `README.md`
- 后续批次：
  - Step 17 Batch 3 需要把等待人工输入与恢复执行扩展到 development/test/bugfix/publish 关键节点。
  - Step 17 Batch 4 需要增加长链路实时可见性回归，覆盖 job/run/event/approval watch 的持续输出。

## Step 17: Development provider events in watch E2E - Batch 3

- 日期：2026-07-09
- 状态：完成，开发阶段 provider 输出已能被 job watch 和 req watch 同时读取
- 范围：
  - `AppendAgentRunEvent` 在调用方未显式传入 `requirement_id` / `release_id` 时，会根据 `agent_jobs.job_id` 自动补齐事件 scope。
  - FakeRunner / ProcessRunner 写 `provider_output` 只需要绑定 `job_id`，req watch / release watch 后续即可按业务对象聚合执行过程。
  - 新增 development fake provider E2E：pending development 创建 implementation plan 和 step job，step run 输出两条 `provider_output`。
  - E2E 验证 `WatchJobEvents` 可以按 job 看到两条输出，也验证 `RequirementWatchSnapshot` 可以按 requirement 聚合看到同一批 provider 输出。
- TDD 记录：
  - 新增 `TestDaemonRunOnceScopesDevelopmentProviderEventsToRequirementWatch`。
  - 红灯：focused test 失败，job watch 能看到 step provider 输出，但 req watch 只看到 `artifact_created`，看不到 `provider_output`。
  - 绿灯：store `AppendAgentRunEvent` 自动从 job 补齐 requirement/release scope 后，focused test 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-17-development-watch-events.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run TestDaemonRunOnceScopesDevelopmentProviderEventsToRequirementWatch`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/store`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/workspace`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/config ./internal/store ./internal/workspace ./internal/mcp ./internal/cli ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md` and `README.md`
- 后续批次：
  - Step 17 Batch 4 需要覆盖 release test、bugfix 和 publish_confirmation 的 fake provider E2E，并验证 release watch 聚合。

## Step 17: Release bugfix retest watch publish E2E - Batch 4

- 日期：2026-07-10
- 状态：完成，release 测试失败到 bugfix、重测、发布确认和发布收口的 fake provider E2E 已落地
- 范围：
  - 新增 `TestDaemonRunOnceReleaseBugfixRetestWatchAndPublishE2E`。
  - fake testing provider 首轮输出 release test failure、`test_report` 和 bug，触发 requirement 回到 `pending_development`。
  - fake coding provider 在 bugfix job 执行前修改 feature worktree，生成 `bugfix_report`，并让既有 bugfix completion 路径提交/推送 feature branch、关闭 bug、清理 worktree。
  - bugfix 后 release 进入 stale，并由 daemon 重新 integrate；第二轮 release test 使用新的 test run 和 fresh snapshots。
  - 第二轮 fake testing provider 输出 passed retest report，release 和 requirement 推进到 `testing_completed`，下一轮 daemon 创建 `publish_confirmation` 并进入 `pending_release`。
  - `release watch` E2E 验证首轮测试、bugfix 和重测的 `provider_output` 都按 release 聚合可见，同时展示两个 test runs、summary artifacts、无 open bug 和 pending publish approval。
  - `req watch` E2E 验证 bugfix provider 输出按 requirement 聚合可见。
  - 用户通过 service 响应 `publish_confirmation`，写入 `confirm=true`，随后 `PublishRelease` 完成发布，requirement workflow 和 release workflow 均进入 `released`。
  - 发布后验证 bugfix 文件已经进入远端 `main` 分支。
- TDD 记录：
  - 新增 E2E 后先出现编译红灯：测试错误地从 `store.Requirement` 读取 workflow status。
  - 修正为显式读取 `GetRequirementWorkflowByID` 后继续红灯：发布结果校验误把 repo remote 名称当作远端 bare repo 路径。
  - 绿灯：改用 `repo.URL` 校验远端 `main` 后 focused E2E 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-17-release-bugfix-publish-e2e.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run TestDaemonRunOnceReleaseBugfixRetestWatchAndPublishE2E`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/config ./internal/store ./internal/workspace ./internal/mcp ./internal/cli ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md` and `README.md`
- 后续批次：
  - Step 17 Batch 5 需要把 analysis clarification、artifact finalization、development plan/step/review 和本批 release loop 合并为单一长链路 E2E。
  - 仍需补真实 provider smoke，验证 Codex/Claude CLI 在最小实际 job 中可以读写 artifact 与 event stream。

## Step 17: Full fake provider E2E - Batch 5

- 日期：2026-07-10
- 状态：完成，需求提交到发布完成的单一 fake provider 长链路回归已落地
- 范围：
  - 新增 `TestDaemonRunOnceFullAINativeFakeProviderE2E`。
  - E2E 从 `SubmitRequirement` 开始创建需求记录，并用 `AssignRequirementAgents(...AdvanceToPendingAnalysis)` 模拟主 Agent 分配 analysis/coding/testing Agents。
  - analysis fake provider 首次运行创建 `requirement_clarification` approval 并进入 `waiting_user_input`；用户响应后同一 analysis job 恢复为 queued，第二次运行能读取澄清答案。
  - analysis fake provider 生成 requirement design、technical design 和 analysis review；用户通过 `artifact_finalization` approval 选择终稿，并推进到 `pending_development`。
  - coding fake provider 执行 implementation plan、两个 implementation step、两个 step review 和 implementation report/review；step provider 输出会被 `req watch` 聚合。
  - development report 完成后，daemon 调用 `FinishRequirement` 提交并清理 feature worktree，需求进入 `development_completed`。
  - release 创建后执行 integrate，并进入 pending testing；testing fake provider 先失败并创建 bug，再由 coding fake provider 执行 bugfix、修改 feature worktree、生成 `bugfix_report`。
  - bugfix 后 release 重新 integrate 并 retest passed，随后 daemon 创建 `publish_confirmation` 并进入 `pending_release`。
  - `release watch` E2E 验证测试、bugfix 和重测 provider 输出均按 release 聚合。
  - 用户确认 `publish_confirmation` 后执行 `PublishRelease`，最终 requirement 为 completed/released，release workflow 为 released，远端 `main` 包含 bugfix 内容。
  - E2E 还校验关键 artifacts 全部存在、所有 jobs succeeded、所有 approvals 已响应。
- TDD 记录：
  - 新增长链路 E2E 后 focused test 首次通过，说明 Step 17 Batch 1-4 的已实现能力能够组合满足该长链路；本批因此不需要生产代码修复。
  - 该测试作为防回归网，后续真实 provider smoke 或主 Agent 协调能力改动时必须保持通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-17-full-fake-provider-e2e.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run TestDaemonRunOnceFullAINativeFakeProviderE2E`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/config ./internal/store ./internal/workspace ./internal/mcp ./internal/cli ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md` and `README.md`
- 后续批次：
  - Step 18 需要补真实 provider smoke，验证本机 Codex/Claude CLI 最小 job 可以创建 artifact、写 event stream，并能被 watch/tail 读取。
  - Step 19 需要做文档、帮助和兼容性审计，确认未完成能力仍被标注为规划或 smoke-only。

## Step 18: Codex provider smoke - Batch 1

- 日期：2026-07-10
- 状态：完成，真实 Codex provider smoke 的 output capture 和默认跳过测试入口已落地
- 范围：
  - `CodexRunner` 的 `codex exec --json` 命令增加 `--output-last-message <job-runtime>/output.json`。
  - `ProcessRunner` 在 provider 成功退出后读取 `OutputJSONPath`；如果文件存在且非空，必须是合法 JSON，并写入 `agent_jobs.result_json`。
  - 输出文件不存在或为空时保持兼容，仍允许只依赖 stdout/stderr events 的 provider run succeeded。
  - 新增 `TestProcessRunnerStoresOutputJSONFileAsJobResult`，覆盖真实 provider/脚本把结构化输出写入 output file 后，job result JSON 可被 coordinator 后处理读取。
  - 新增 `TestCodexProviderSmoke`，默认 skip；设置 `WORKSPACE_CLI_REAL_PROVIDER_SMOKE=codex` 或 `all` 时才调用真实 `codex` 跑最小只读 job。
  - smoke test 验证真实 provider run succeeded、result JSON 包含 `{"smoke":"ok"}`，且 run events 包含 provider output 与 run completed。
- TDD 记录：
  - 红灯：`TestProcessRunnerStoresOutputJSONFileAsJobResult` 失败，`agent_jobs.result_json` 为空，说明 ProcessRunner 没有读取 provider output file。
  - 红灯：`TestCodexRunnerBuildsCommandAndMCPConfig` 失败，Codex args 缺少 `--output-last-message`。
  - 绿灯：ProcessRunner 读取并校验 output JSON，CodexRunner 追加 output file 参数后 focused tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-18-codex-provider-smoke.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/agent -run 'TestCodexRunnerBuildsCommandAndMCPConfig|TestProcessRunnerStoresOutputJSONFileAsJobResult|TestCodexProviderSmoke'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/agent`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/config ./internal/store ./internal/workspace ./internal/mcp ./internal/cli ./internal/coordinator ./internal/agent`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md` and `README.md`
- 当前边界：
  - 真实 Codex smoke 默认跳过；本批没有设置 `WORKSPACE_CLI_REAL_PROVIDER_SMOKE=codex` 实际调用模型。
  - Claude Code smoke gate 已由 Step 18 Batch 4 补齐；当前环境未检测到可用 `claude` 命令，真实调用仍需在安装 Claude Code 后运行。
- 后续批次：
  - 在用户允许或指定环境中运行 `WORKSPACE_CLI_REAL_PROVIDER_SMOKE=codex`，记录真实 provider 输出、事件和 result JSON。
  - 如 `claude --help` 可用，运行 Claude smoke gate 并记录真实 provider 输出、事件和 result JSON。

## Step 18: Real Codex provider smoke - Batch 2

- 日期：2026-07-10
- 状态：完成，Step 18 仍可继续补 Claude smoke 或更完整真实 provider E2E
- 范围：
  - 调研本地 `codex exec --help`，确认当前 exec 子命令不支持 `--ask-for-approval`，需要用 `-c approval_policy=...`。
  - 复现 job-scoped `CODEX_HOME` 真实 smoke 失败：临时 home 只有 MCP config，没有用户登录态，Codex 请求返回 401 Unauthorized。
  - `CodexRunner` 改为保留用户默认 `CODEX_HOME`，通过 `-c mcp_servers.workspace_cli.command=...` 和 `-c mcp_servers.workspace_cli.args=[...]` 注入 job-scoped MCP server。
  - `CodexRunner` 继续生成 `work/runtime/mcp/<job-key>/codex/config.toml`，作为审计、session 记录和排障材料。
  - `workspace ai start` 的 Codex 主 Agent 同步改为保留用户默认 `CODEX_HOME`，通过 `-c mcp_servers.workspace_cli.*` 注入 coordinator MCP server。
  - 更新需求方案、技术方案、实施步骤和相关 Review 文档，避免继续描述临时 `CODEX_HOME` 方案。
- TDD 记录：
  - 红灯：`WORKSPACE_CLI_REAL_PROVIDER_SMOKE=codex go test ... TestCodexProviderSmoke` 首次失败，先因 `--ask-for-approval` 不被 `codex exec` 接受，修正后又因临时 `CODEX_HOME` 缺失认证返回 401。
  - 绿灯：改为 `-c approval_policy=...` 和 `-c mcp_servers.workspace_cli.*` 后，真实 Codex smoke 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-18-real-codex-smoke.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/agent -run 'TestCodexRunnerBuildsCommandAndMCPConfig|TestProcessRunnerStoresOutputJSONFileAsJobResult|TestCodexProviderSmoke'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli -run TestAIStartCodexBuildsMCPConfigAndPrompt`
  - `env WORKSPACE_CLI_REAL_PROVIDER_SMOKE=codex GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/agent -run TestCodexProviderSmoke -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/agent ./internal/cli`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md` and `README.md`
- 后续批次：
  - Claude stream-json 结果解析已由 Step 18 Batch 3 补齐；真实 Claude smoke 仍按本机 `claude --help` 可用性后续执行。
  - 增加真实 provider 长链路 E2E，覆盖 artifact 写入、watch/tail 和 approval resume。

## Step 18: Claude stream-json result capture - Batch 3

- 日期：2026-07-10
- 状态：完成，Claude stream-json stdout 的结构化 result 入库能力已落地
- 范围：
  - `ProcessRunner` 成功退出后优先读取 provider `OutputJSONPath`。
  - 当 output file 缺失或为空时，继续扫描 stdout NDJSON。
  - 对 `type=result` 的 stream-json 行，若 `result` 是 JSON object/array 或包含 JSON object/array 的字符串，则写入 `agent_jobs.result_json`。
  - 保持 Codex `--output-last-message` 路径优先，不改变已有 Codex smoke 和 output file 行为。
  - 自然语言 result 不强制失败，仍作为 provider output event 保留，避免非结构化只读 job 被误判。
- TDD 记录：
  - 新增 `TestProcessRunnerExtractsClaudeStreamJSONResult`，模拟 Claude stream-json stdout。
  - 红灯：job succeeded 但 `agent_jobs.result_json` 为空。
  - 绿灯：增加 stream-json result parser 后 focused test 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-18-claude-stream-json.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/agent -run TestProcessRunnerExtractsClaudeStreamJSONResult -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/agent`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md` and `README.md`
- 后续批次：
  - 本批没有实际调用真实 `claude` CLI；真实 Claude smoke 仍按本机 `claude --help` 可用性后续执行。
  - 更完整真实 provider E2E 仍可继续覆盖 artifact 写入、watch/tail 和 approval resume。

## Step 18: Claude provider smoke gate - Batch 4

- 日期：2026-07-10
- 状态：完成，真实 Claude provider smoke 的 gated 测试入口已落地；本机缺少 `claude` 时会记录 skip
- 范围：
  - 新增 `TestClaudeProviderSmoke`，默认 skip；设置 `WORKSPACE_CLI_REAL_PROVIDER_SMOKE=claude` 或 `all` 时才尝试调用真实 `claude`。
  - smoke test 使用真实 `ProcessRunner + ClaudeRunner`，在临时 git workspace 中运行最小只读 prompt。
  - smoke test 验证 provider run succeeded、`agent_jobs.result_json` 包含 `{"smoke":"ok","provider":"claude"}`，且 run events 包含 `provider_output` 与 `run_completed`。
  - 新增 `seedProviderRunnerJobWithProvider`，让真实 Claude smoke 的 agent provider 能记录为 `claude`，保留原 `seedProviderRunnerJob` 的 Codex 默认行为。
  - 当前环境 `claude` 不在 PATH 中，显式启用 Claude smoke 时按可用性 skip，避免把本机工具缺失误判成代码失败。
- TDD/调研记录：
  - 事实调研：`claude` 当前不可用，无法在本机完成真实 Claude Code 调用。
  - 绿灯：默认 skip 路径通过；`WORKSPACE_CLI_REAL_PROVIDER_SMOKE=claude` 时缺少 `claude` 的 skip 路径通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-18-claude-provider-smoke.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/agent -run TestClaudeProviderSmoke -v`
  - `env WORKSPACE_CLI_REAL_PROVIDER_SMOKE=claude GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/agent -run TestClaudeProviderSmoke -v`
- 当前边界：
  - 真正调用 Claude Code CLI 的 smoke 仍需在安装、登录并确认 `claude --help` 可用后运行。
  - 更完整真实 provider E2E 仍可继续覆盖 artifact 写入、watch/tail 和 approval resume。

## Step 19: Docs and compatibility audit - Batch 1

- 日期：2026-07-10
- 状态：完成，Step 19 文档和兼容性审计仍在进行中
- 范围：
  - README 的 AINative 章节从“下一阶段规划”更新为“AINative 高级模式”的当前边界说明：普通本地流程仍独立可用，AINative 是叠加在同一 SQLite 状态库和 Git/release 状态机上的高级入口。
  - README 明确当前已落地 agent/worker/job/MCP/daemon/fake-provider 全链路测试和真实 Codex 最小 smoke，Claude smoke 和更完整真实 provider E2E 仍后续推进。
  - `ProcessRunner` 对超过 4096 bytes 的 provider output event 只写摘要，payload 写入 `stream`、`truncated=true`、`raw_path` 和 `original_bytes`。
  - 原始 provider stdout/stderr 仍完整写入 job-scoped raw 文件，用户可通过 `run tail --raw` 查看，避免 DB event 存储超大输出。
- TDD 记录：
  - 红灯：新增 `TestProcessRunnerSummarizesLargeProviderOutputEvents` 后失败，70000 bytes 单行输出完整进入 `agent_run_events.message`。
  - 绿灯：新增 `providerOutputEvent` 摘要逻辑后，focused test 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-19-docs-compat-output.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/agent -run TestProcessRunnerSummarizesLargeProviderOutputEvents -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/agent -run 'TestProcessRunnerStreamsRedactedOutputAndCompletesJob|TestProcessRunnerSummarizesLargeProviderOutputEvents|TestProcessRunnerStoresOutputJSONFileAsJobResult'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/agent ./internal/cli`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md` and `README.md`
- 后续批次：
  - 继续审计 CLI help 文案，确保没有把后续真实 provider E2E 或 Claude smoke 写成已完成能力。
  - 继续核对 release publish dirty guard、external commit guard、publish confirmation 和 snapshot freshness 的测试覆盖。

## Step 19: CLI help audit - Batch 2

- 日期：2026-07-10
- 状态：完成，Step 19 文档和兼容性审计仍在进行中
- 范围：
  - 审计新增 AINative CLI help 文案，发现 `workspace agent daemon stop --help` 原文案承诺 `background daemon supervisor`。
  - 当前 daemon 只支持 foreground 模式和 `--once` 单 tick；`stop` 命令运行时也只说明 `supervisor: not-configured`。
  - 修正 `agent daemon stop` Short 文案为 `show how to stop the foreground daemon`，避免把尚未实现的后台 supervisor 写成已完成能力。
- TDD 记录：
  - 红灯：新增 `TestAINativeHelpDoesNotPromiseBackgroundDaemonSupervisor` 后失败，help 中仍包含 `background daemon supervisor`。
  - 绿灯：修正 help 文案后 focused CLI 测试通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-19-cli-help.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli -run TestAINativeHelpDoesNotPromiseBackgroundDaemonSupervisor -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli -run 'TestAINativeHelpDoesNotPromiseBackgroundDaemonSupervisor|TestRootCommandIncludesDocumentedCommandSurface|TestAgentDaemonCommandSurfaceIsStrict'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/agent ./internal/cli`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md` and `README.md`
- 后续批次：
  - 继续核对 release publish dirty guard、external commit guard、publish confirmation 和 snapshot freshness 的测试覆盖。
  - 继续审计文档中历史 “后续批次” 描述，确认已经被后续批次补齐的内容有清晰的 later-batch 标注。

## Step 19: Publish-in-progress snapshot guard - Batch 3

- 日期：2026-07-10
- 状态：完成，Step 19 文档和兼容性审计仍在进行中
- 范围：
  - 审计 AINative `release_publish` 的 publish confirmation、active release test snapshot freshness 和 `publish_in_progress` 重试保护。
  - 修复 `publish_in_progress` release 在 snapshot mismatch 时被错误标记为 stale 的问题。
  - `ensureAINativePublishConfirmation`、`ensureAINativeReleaseTestSnapshotCurrent` 和 snapshot stale helper 现在传递 `publishInProgress` 上下文。
  - 非 publish-in-progress 的 stale snapshot 仍进入 `stale` 并要求 retest。
  - publish-in-progress 的 snapshot mismatch 返回 manual handling 错误，保持 release workflow 为 `publish_in_progress`，不创建 stale workflow。
- TDD 记录：
  - 新增 `TestAINativePublishInProgressSnapshotMismatchRequiresManualHandlingWithoutStale`。
  - 红灯：双 repo release 部分发布成功后，制造 snapshot mismatch 并重试 publish，release 被标记为 stale，错误提示要求 retest。
  - 绿灯：传递 `publishInProgress` 并在 snapshot mismatch 中返回 manual handling 后，focused release publish tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-19-publish-in-progress-snapshot.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/workspace -run TestAINativePublishInProgressSnapshotMismatchRequiresManualHandlingWithoutStale`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/workspace -run 'TestAINativePublishInProgressSnapshotMismatchRequiresManualHandlingWithoutStale|TestAINativePublishReleaseRejectsStaleReleaseTestSnapshot|TestAINativePublishReleaseMarksPublishInProgressAfterPartialFailure'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/workspace`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md` and `README.md`
- 后续批次：
  - 继续审计历史 Review 文档中的后续批次描述，确认已完成项被标注为 later-batch landed 或从开放问题中移除。
  - 继续扩展真实 provider 长链路 smoke，覆盖 artifact 写入、watch/tail 和 approval resume。

## Step 19: Docs index current mode wording - Batch 4

- 日期：2026-07-10
- 状态：完成，Step 19 文档和兼容性审计仍在进行中
- 范围：
  - 审计 GitHub Pages 首页 AINative 卡片的当前状态表述。
  - 修正 `docs/index.html` 中仍把 AINative 写成 `AINative 协作规划` 和 `下一阶段将引入主 Agent...` 的过期描述。
  - 首页改为 `AINative 高级模式`，并明确当前已接入主 Agent、Worker pool、MCP 控制面和分析/开发/测试循环。
  - 对真实 provider 长链路保持后续验证边界，不把未完成的 Claude smoke 或完整真实 provider E2E 写成已完成。
  - docs index 补充 Step 19 Batch 4 Review 链接。
- TDD 记录：
  - 新增 `TestAINativeDocsIndexDoesNotDescribeImplementedModeAsFuturePlanning`。
  - 红灯：focused test 发现 docs index 仍包含 `AINative 协作规划`。
  - 绿灯：修正首页文案后，focused docs index 测试通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-19-docs-index-current-mode.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli -run TestAINativeDocsIndexDoesNotDescribeImplementedModeAsFuturePlanning -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli -run 'TestAINativeDocsIndexDoesNotDescribeImplementedModeAsFuturePlanning|TestRootCommandIncludesDocumentedCommandSurface|TestAINativeHelpDoesNotPromiseBackgroundDaemonSupervisor'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md` and `README.md`
- 后续批次：
  - 继续审计历史 Review 文档里的“后续批次”段落，优先处理仍会误导当前能力边界的表述。
  - 继续扩展真实 provider 长链路 smoke，覆盖 artifact 写入、watch/tail 和 approval resume。

## Step 19: Requirements current mode wording - Batch 5

- 日期：2026-07-10
- 状态：完成，Step 19 文档和兼容性审计仍在进行中
- 范围：
  - 审计核心 AINative 需求方案的产品定位表述。
  - 修正 `docs/ai-native-requirements.md` 中仍把 AINative 写成 `下一阶段目标` 的过期描述。
  - 需求方案开篇改为在现有本地需求开发空间管理工具基础上扩展为 AINative 研发协作平台。
  - 保留 V1 本地单用户、SQLite、Git/release 状态机和真实 provider 后续验证边界。
- TDD 记录：
  - 新增 `TestAINativeRequirementsDocUsesCurrentPlatformWording`。
  - 红灯：focused test 发现需求方案仍包含 `下一阶段目标`。
  - 绿灯：修正需求方案开篇文案后，focused docs wording 测试通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-19-requirements-current-mode.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli -run TestAINativeRequirementsDocUsesCurrentPlatformWording -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli -run 'TestAINativeRequirementsDocUsesCurrentPlatformWording|TestAINativeDocsIndexDoesNotDescribeImplementedModeAsFuturePlanning'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md` and `README.md`
- 后续批次：
  - 继续审计非历史性的核心文档，确认当前能力边界和真实 provider 后续验证边界一致。
  - 历史 Review 文档中的批次当时状态应保留历史事实；只有会误导当前入口或核心方案的表述才改写或补 later-batch 标注。

## Step 15: Publish confirmation reject event - Batch 6

- 日期：2026-07-10
- 状态：完成，用户拒绝发布确认后的 release 级状态事件已落地
- 范围：
  - store 新增 `RespondPublishConfirmationApproval`，在同一事务内关闭 `publish_confirmation` approval，并在 reject 时写 release status event。
  - service 的 `RespondApproval` 对 `publish_confirmation` 改走专门事务方法，避免 approval 已关闭但 release 诊断事件缺失。
  - 用户 reject 后 release workflow 保持 `pending_release`，不推进到发布。
  - reject 事件写入 `release_status_events`，使用 `pending_release -> pending_release` 诊断形式，actor 使用 `responded_by`，并绑定当前 `release_test_run_id`。
  - approved publish confirmation 仍只记录 approval response；真正发布仍由后续 `release_publish` 单独触发并重新校验 guard。
- TDD 记录：
  - 新增 `TestRespondPublishConfirmationRejectWritesReleaseStatusEvent`。
  - 红灯：`RespondApproval(publish_confirmation reject)` 后 `release_status_events` 为空。
  - 绿灯：新增 store 事务方法并接入 service 后，focused test 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-15-publish-confirmation-reject.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/workspace -run TestRespondPublishConfirmationRejectWritesReleaseStatusEvent -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/workspace`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/store ./internal/workspace ./internal/agent ./internal/coordinator ./internal/mcp ./internal/cli`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md` and `README.md`
- 后续批次：
  - 继续审计 release test failure 等非状态推进类事件，确认需要用户实时看到的 release 级诊断都写入 `release_status_events`。

## Step 15: Publish in progress - Batch 5

- 日期：2026-07-09
- 状态：完成，Step 15 部分发布失败后的 AINative `publish_in_progress` 和重试收口已落地
- 范围：
  - store 新增 `MarkReleasePublishInProgress`，在 release 已处于 `releasing` 且至少一个 release repo 已标记 `published` 时推进到 `publish_in_progress`。
  - `MarkReleasePublishInProgress` 校验 `active_test_run_id` 仍等于当前 publish guard 返回的 release test run，避免过期测试结果驱动状态变化。
  - `MarkReleasePublishInProgress` 写入 `releasing -> publish_in_progress` release status event，并关联当前 `release_test_run_id`。
  - `PublishRelease` 在 AINative 发布开始后的 repo publish 失败路径调用 `MarkReleasePublishInProgress`；发布开始前的 preflight 失败不会改变 workflow。
  - requirements 在部分发布失败时保持 `releasing`，不会提前进入 `released`。
  - `StartReleasePublishing` 对 `publish_in_progress` 幂等，`FinalizeAINativeReleasePublished` 支持 `publish_in_progress -> released`，允许修复环境后重试并完成发布。
- TDD 记录：
  - 新增 `TestAINativePublishReleaseMarksPublishInProgressAfterPartialFailure`。
  - 红灯：两 repo AINative release 中第二个 repo push 被 hook 拒绝后，release workflow 没有进入 `publish_in_progress`。
  - 绿灯：实现 `MarkReleasePublishInProgress` 并接入发布失败路径后 focused test 通过；同一测试覆盖修复 hook 后重试发布，并从 `publish_in_progress` 收口到 `released`。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-15-publish-in-progress.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/workspace -run 'TestAINativePublishReleaseMarksPublishInProgressAfterPartialFailure|TestAINativePublishReleaseAdvancesWorkflowToReleased|TestAINativePublishReleaseAllowsConfirmedPublishConfirmation|TestAINativePublishReleaseRejectsStaleReleaseTestSnapshot'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/workspace`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md`
- 当前边界：
  - 只有 DB 已记录至少一个 release repo 为 `published` 时才推进 `publish_in_progress`；发布开始后但尚无 repo 成功的失败仍保持 `releasing`，供用户重试。
  - release business status 仍沿用既有 `integrated` / `published` / `stale` 等值，`publish_in_progress` 是 AINative workflow status。
  - `release watch` CLI 和 `publish_in_progress` 诊断事件已由后续 Step 16 和 Step 8 Batch 8 补齐。
- 后续批次：
  - 后续如要进一步自动化发布重试，仍必须保留人工确认边界，不能由 daemon 自动绕过 `publish_confirmation`。

## Step 15: Publish workflow released - Batch 4

- 日期：2026-07-09
- 状态：完成，Step 15 发布开始和成功后的 AINative workflow 收口已落地；publish-in-progress 细化仍在后续批次
- 范围：
  - `PublishRelease` 的 AINative guard 现在返回当前 `active_test_run_id`，用于绑定后续 publish workflow 状态更新。
  - store 新增 `StartReleasePublishing`，在发布实际 merge/push 前把 release workflow 从 `pending_release` 推进到 `releasing`。
  - `StartReleasePublishing` 同事务把本次 release test run 覆盖的 requirements 推进到 `releasing`，并写入 `pending_release -> releasing` release status event。
  - store 新增 `FinalizeAINativeReleasePublished`，发布成功后同事务把 release workflow 推进到 `released`，把 requirements workflow 推进到 `released`。
  - `FinalizeAINativeReleasePublished` 沿用既有业务状态收口：release status 进入 `published`，requirements status 进入 `completed`，并写入 `releasing -> released` release status event。
  - publishing/released 状态更新都校验 release 仍绑定同一个 `active_test_run_id`，避免使用过期测试结果完成发布。
- TDD 记录：
  - 新增 `TestAINativePublishReleaseAdvancesWorkflowToReleased`。
  - 红灯：已确认 `PublishRelease` 成功后 release workflow 仍未进入 `released`，requirements 也未进入 `released`。
  - 绿灯：实现 publishing/released store 事务和 service publish 接入后 focused tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-15-publish-workflow.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/workspace -run 'TestAINativePublishReleaseAdvancesWorkflowToReleased|TestAINativePublishReleaseAllowsConfirmedPublishConfirmation|TestAINativePublishReleaseRejectsStaleReleaseTestSnapshot'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/workspace`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md`
- 当前边界：
  - `releasing` 在全部 preflight 通过、实际 merge/push 前写入；preflight 失败不会提前改变 workflow。
  - 发布开始后如果 merge/push 或 finalization 失败，本批次保留 workflow 为 `releasing`，允许用户修复环境后重试。
  - 本批次不把部分 repo 已 push 的失败态标记为 `publish_in_progress`；该状态和更细粒度的发布恢复事件留给 Step 15 Batch 5。
- 后续批次：
  - Step 15 Batch 5 需要在 publish-in-progress 时同步 release workflow 为 `publish_in_progress`，requirements 保持 `releasing`，并补充状态事件。
  - Step 16 需要增加用户实时可见的 watch/status 入口，展示 agent run events、release status events、artifact 和 pending human approvals。

## Step 15: Snapshot freshness guard - Batch 3

- 日期：2026-07-09
- 状态：完成，Step 15 发布前 release/test-run snapshot freshness guard 已落地；workflow released 收口仍在后续批次
- 范围：
  - `PublishRelease` 在确认 `publish_confirmation confirm=true` 后继续校验 release test snapshot freshness。
  - workspace service 新增 `ensureAINativeReleaseTestSnapshotCurrent`，比较当前 release snapshots 与 active test run snapshots。
  - guard 比较 requirement id、repo id、repo name、feature branch、feature commit 和 release commit。
  - test run snapshot 缺少 repo id、scope 不一致、当前 release repo snapshot 缺失或 commit 不一致都会拒绝 publish。
  - store 新增 `MarkReleaseWorkflowStale`，同时设置 release status 为 `stale`、workflow status 为 `stale`。
  - snapshot 不一致时写入 `release_status_events`，事件包含 `new_status=stale` 和当前 `release_test_run_id`。
  - stale publish 不会继续执行 merge/push。
- TDD 记录：
  - 新增 `TestAINativePublishReleaseRejectsStaleReleaseTestSnapshot`。
  - 红灯：测试构造 stale test snapshot 后，`PublishRelease` 仍然成功发布。
  - 绿灯：实现 `ensureAINativeReleaseTestSnapshotCurrent`、`MarkReleaseWorkflowStale` 和 stale event 后 focused tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-15-snapshot-freshness.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/workspace -run 'TestAINativePublishReleaseRejectsStaleReleaseTestSnapshot|TestAINativePublishReleaseRejectsPendingPublishConfirmation|TestAINativePublishReleaseRejectsFalsePublishConfirmation|TestAINativePublishReleaseAllowsConfirmedPublishConfirmation'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/workspace`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md`
- 当前边界：
  - 本批次校验 release/test-run snapshot freshness，不处理 target branch 外部 commit 的 workflow stale event。
  - 本批次不推进 `releasing`、`publish_in_progress` 或 `released`。
  - 本批次不处理 publish 成功后的 AINative workflow 收口。
- 后续批次：
  - Step 15 Batch 4 需要在 publish 开始和成功时推进 AINative workflow 到 `releasing` / `released`，并写 release status events。
  - Step 15 Batch 5 需要在 publish-in-progress 时同步 release workflow 为 `publish_in_progress`，requirements 保持 `releasing`，并补充状态事件。

## Step 15: Publish confirmation guard - Batch 2

- 日期：2026-07-09
- 状态：完成，Step 15 发布前确认 guard 已落地；snapshot freshness 和 released 收口仍在后续批次
- 范围：
  - `PublishRelease` 对 `manual_release` workflow 不启用新 guard，避免影响既有手动 release 流程。
  - AINative release publish 要求 workflow 为 `pending_release`、`releasing` 或 `publish_in_progress`。
  - AINative release publish 要求 `active_test_run_id` 存在，且对应 test run 属于当前 release。
  - AINative release publish 要求 active test run status 为 `passed`。
  - store 新增 `GetReleaseWorkflowByID`，让 workspace service 可以读取 release workflow。
  - store 新增 `GetApprovedPublishConfirmation`，按 release/test run 定位 approved `publish_confirmation`。
  - workspace service 新增 `ensureAINativePublishConfirmation`，校验 approved publish confirmation 的 response 必须包含 `confirm=true`。
  - 没有 approved `publish_confirmation` 时拒绝 publish，并保持 release status 为 `integrated`、requirements workflow 为 `pending_release`。
  - `publish_confirmation` 已 approved 但 response 为 `{"confirm":false}` 时拒绝 publish。
  - `publish_confirmation` approved 且 `{"confirm":true}` 时允许继续复用现有 publish 流程，把 release branch 合并到目标分支。
- TDD 记录：
  - 新增 `TestAINativePublishReleaseRejectsPendingPublishConfirmation`。
  - 新增 `TestAINativePublishReleaseRejectsFalsePublishConfirmation`。
  - 新增 `TestAINativePublishReleaseAllowsConfirmedPublishConfirmation`。
  - 红灯：前两个 focused tests 失败，`PublishRelease` 在 pending approval 和 `confirm=false` approval 下仍成功发布。
  - 绿灯：实现 `ensureAINativePublishConfirmation` 和 approved publish confirmation 查询后 focused tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-15-publish-guard.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/workspace -run 'TestAINativePublishReleaseRejectsPendingPublishConfirmation|TestAINativePublishReleaseRejectsFalsePublishConfirmation|TestAINativePublishReleaseAllowsConfirmedPublishConfirmation'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/workspace`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md`
- 当前边界：
  - 本批次只校验 publish confirmation，不实现 snapshot freshness guard。
  - 本批次不把 workflow 推进到 `releasing`、`publish_in_progress` 或 `released`。
  - 本批次不处理 publish 成功后的 AINative requirement/release workflow 收口。
- 后续批次：
  - Step 15 Batch 3 需要实现 release/test-run snapshot freshness guard，拒绝 scope、feature commit、release commit 或 target branch 已变化的 stale publish。
  - Step 15 Batch 4 需要在 publish 开始和成功时推进 AINative workflow 到 `releasing` / `released`，并写 release status events。

## Step 15: Publish confirmation entry - Batch 1

- 日期：2026-07-09
- 状态：完成，Step 15 发布状态联动进入发布确认入口；publish guard 和 released 收口仍在后续批次
- 范围：
  - daemon 扫描 `workflow_status=testing_completed` 的 release，并要求 `active_test_run_id` 指向 `passed` release test run。
  - daemon 创建 release/test-run scoped `publish_confirmation` approval，稳定 key 为 `publish-confirmation-<release-slug>-run-<release_test_run_id>`。
  - approval payload 包含 release、target branch、test command、requirements 和 release test run requirement+repo+commit snapshots。
  - store 新增 `StartReleasePendingRelease`，在事务内校验 release 当前状态、active test run、test run 所属 release 和 test run 状态。
  - store 在同一事务内把 release 推进到 `pending_release`，保持 `active_test_run_id`，并把相关 requirements 推进到 `pending_release`。
  - store 写入 `release_status_events`，记录 `testing_completed -> pending_release` 和当前 test run。
  - daemon 重复扫描不会重复创建同一 publish confirmation。
  - 用户 reject 当前 publish confirmation 后，release 保持 `pending_release`，daemon 不会自动为同一 release/test run 创建新的 pending approval。
- TDD 记录：
  - 新增 `TestDaemonRunOnceCreatesPublishConfirmationForTestingCompletedRelease`。
  - 新增 `TestAINativeStoreStartsReleasePendingReleaseAndCreatesPublishApproval`。
  - 红灯：focused test 编译失败，缺少 `StartReleasePendingRelease`、`StartReleasePendingReleaseParams`、`ReleaseWorkflowStatusPendingRelease` 和 `RequirementWorkflowStatusPendingRelease`。
  - 绿灯：实现 pending release 常量、store 原子转换、publish confirmation 创建和 daemon 扫描入口后 focused tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-15-publish-confirmation.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator ./internal/store -run 'TestDaemonRunOnceCreatesPublishConfirmationForTestingCompletedRelease|TestAINativeStoreStartsReleasePendingReleaseAndCreatesPublishApproval'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator ./internal/store`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md`
- 当前边界：
  - 本批次只创建发布确认，不执行 publish。
  - 本批次不校验 approved `confirm=true`；该 guard 留给 Step 15 后续 batch。
  - 本批次不实现 snapshot freshness guard；release scope、feature commit 或 target branch 外部变化后的 stale 处理留给后续 batch。
  - 本批次不推进 `releasing`、`publish_in_progress` 或 `released`。
- 后续批次：
  - Step 15 Batch 2 需要在 `release_publish` 前校验当前 test run 存在 approved 且 `confirm=true` 的 `publish_confirmation`。
  - Step 15 Batch 3 需要实现 release/test-run snapshot freshness guard，拒绝 stale publish 并触发重新 integrate/test。

## Step 14: Testing completed - Batch 8

- 日期：2026-07-09
- 状态：完成，Step 14 集成测试闭环已收口到 `testing_completed`，发布确认仍待 Step 15
- 范围：
  - `release_test` job 成功输出 `status=passed` 后，daemon 在生成 test report artifact 和更新 test run status 后进入 testing completed 收口。
  - daemon 在推进前查询 release open bugs；仍有 open bug 时不会把 release 标记为 `testing_completed`。
  - store 新增 `CompleteReleaseTesting`，在事务内校验 release test run 属于目标 release，且状态必须为 `passed`。
  - store 在同一事务内校验 release 没有 open bug，避免测试通过但 bug 未关闭时误推进。
  - store 设置 release workflow 为 `testing_completed`，并写入 `active_test_run_id=<当前 passed release_test_run>`。
  - store 把本次 release test run snapshot 覆盖的 requirements 推进到 `testing_completed`。
  - store 写入 `release_status_events`，记录 old/new status、actor、reason、test_run_id 和 job_id。
  - store 新增 `ListReleaseStatusEvents`，为后续 release watch 和发布确认追踪提供查询入口。
- TDD 记录：
  - 新增 `TestDaemonRunOnceMarksTestingCompletedWhenReleaseTestPasses`。
  - 新增 `TestAINativeStoreCompletesReleaseTestingAndRecordsStatusEvent`。
  - 红灯：focused test 编译失败，缺少 `CompleteReleaseTesting`、`ListReleaseStatusEvents` 和 `testing_completed` workflow 常量。
  - 绿灯：实现 release testing completed 原子 store 方法、release status event 查询和 daemon passed 分支后 focused tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-14-testing-completed.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator ./internal/store -run 'TestDaemonRunOnceMarksTestingCompletedWhenReleaseTestPasses|TestAINativeStoreCompletesReleaseTestingAndRecordsStatusEvent'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator ./internal/store`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md`
- 当前边界：
  - 本批次不创建 `publish_confirmation`。
  - 本批次不推进 `pending_release`、`releasing` 或 `published`。
  - 本批次不实现发布前 snapshot freshness 校验。
  - 本批次不新增 release watch CLI；状态事件查询先在 store 层落地。
- 后续批次：
  - Step 15 需要基于 `active_test_run_id` 创建 release/test-run scoped `publish_confirmation`。
  - Step 15 发布入口需要重新校验 release test run 的 requirement+repo+commit snapshot 与当前 release snapshot 一致。

## Step 14: Release test CLI - Batch 9

- 日期：2026-07-09
- 状态：完成，release test 的用户 CLI start/status 入口已落地
- 范围：
  - 新增 `workspace release test` command group。
  - 新增 `workspace release test start <release>`，复用 `StartReleaseTest` 创建 release test run 和 requirement/repo/commit 快照。
  - `release test start` 支持 `--test-command` 显式覆盖本次测试命令。
  - `release test start` 支持 `--test-agent <name>` 和 `--test-agent-id <id>`，并复用 service 对 testing Agent 的校验。
  - 新增 `workspace release test status <release>`，复用 `ReleaseWatchSnapshot` 输出 test run、命令来源、summary artifact、snapshot、pending approval、bug 和 run event。
- TDD 记录：
  - 扩展 `TestRootCommandIncludesDocumentedCommandSurface`，要求 `release test`、`release test start` 和 `release test status` 存在。
  - 新增 `TestReleaseTestStartAndStatusCLI`，覆盖 release 默认测试命令、测试 Agent 名称解析、test run 创建和 status 输出。
  - 新增 `TestReleaseTestStartRejectsConflictingTestAgentInputs`，覆盖 `--test-agent` 与 `--test-agent-id` 互斥。
  - 红灯：`release test start --test-agent` 返回 unknown flag。
  - 绿灯：新增 release test CLI command group、Agent 名称解析和 status 输出后 focused tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-14-release-test-cli.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli -run 'TestReleaseTest|TestRootCommandIncludesDocumentedCommandSurface'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/workspace ./internal/mcp ./internal/cli -run 'StartReleaseTest|ReleaseTest|TestReleaseTest|TestMCPReleaseTest|TestRootCommandIncludesDocumentedCommandSurface'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/config ./internal/store ./internal/workspace ./internal/mcp ./internal/cli ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md` and `README.md`
- 当前边界：
  - `release test start` 只创建 release test run 和快照；实际测试 job 仍由 daemon pending testing/retest lane 创建和执行。
  - `release test status` 聚合 release 维度所有 test runs；provider 输出仍通过 `release watch` 或 `run tail` 查看。
  - 本批不新增 release workflow 状态推进。
- 后续批次：
  - E2E 需要覆盖主 Agent 创建 release test、用户实时查看 test run、测试失败创建 bug、CodingAgent 修复并 retest 的完整链路。

## Step 14: Bugs list CLI - Batch 10

- 日期：2026-07-09
- 状态：完成，需求和 release 维度的 bug 查询 CLI 已落地
- 范围：
  - `workspace req` 新增 `bugs` command group。
  - 新增 `workspace req bugs list <req> [--status open|fixed]`，按 requirement 查询 bug。
  - `workspace release` 新增 `bugs` command group。
  - 新增 `workspace release bugs list <release> [--status open|fixed]`，按 release 查询 bug。
  - CLI 复用 workspace service 的 `ListBugs`，因此与 MCP `bug_list`、release watch 和 req watch 使用同一 store 查询语义。
  - 输出包含 bug id、status、severity、title、requirement id、release id、test run id、repo 和 file path，方便用户或主 Agent 从单独命令定位修复对象。
  - README 和技术方案命令面补充 `--status` 示例，docs 首页加入独立 Review 链接。
- TDD 记录：
  - 扩展 `TestRootCommandIncludesDocumentedCommandSurface`，要求存在 `req bugs list` 和 `release bugs list`。
  - 新增 `TestReqAndReleaseBugsListCLI`，覆盖 release test 产生 open bug 后，需求维度和 release 维度均可查询，且 `--status fixed` 不返回 open bug。
  - 红灯：`req bugs list` 只显示 `req` 父命令 help，说明 bugs command group 尚未注册。
  - 绿灯：实现 req/release bugs command group、status filter 和 bug 输出 helper 后 focused CLI 测试通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-14-bugs-list-cli.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli -run 'TestReqAndReleaseBugsListCLI|TestRootCommandIncludesDocumentedCommandSurface'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/config ./internal/store ./internal/workspace ./internal/mcp ./internal/cli ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md` and `README.md`
- 后续批次：
  - E2E 仍需要覆盖主 Agent 创建 release test、用户通过 bug list/watch 查看 bug、CodingAgent 修复并 retest 的完整链路。

## Step 14: Test command inference - Batch 11

- 日期：2026-07-10
- 状态：完成，Step 14 集成测试命令推断已落地
- 范围：
  - daemon pending-testing lane 在缺少显式、release 默认和全局默认 test command 时，尝试从 release repo worktree 推断命令。
  - `workspace release test start` 复用同一推断逻辑。
  - release repo worktree 存在 `go.mod` 时，test command 记录为 `cd <repo-name> && go test ./...`。
  - `release_test_runs.test_command_source` 写入 `inferred`。
  - 推断成功时不创建 `test_command_missing` approval。
  - repo 名称生成命令时进行 shell quote。
  - 同一路径预留 `package.json -> npm test` 和 `pyproject.toml -> pytest`。
- TDD 记录：
  - 新增 `TestDaemonRunOnceInfersReleaseTestCommandFromGoModule`。
  - 新增 `TestReleaseTestStartInfersGoModuleCommand`。
  - 红灯：daemon 无命令时仍创建 approval，没有创建 inferred release test job。
  - 红灯：`release test start` 无命令时创建 `waiting_user_input` test run。
  - 绿灯：实现 release worktree 推断后 focused tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-14-test-command-inference.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run TestDaemonRunOnceInfersReleaseTestCommandFromGoModule -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli -run TestReleaseTestStartInfersGoModuleCommand -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli ./internal/coordinator -run 'TestReleaseTestStartInfersGoModuleCommand|TestDaemonRunOnceInfersReleaseTestCommandFromGoModule|TestDaemonRunOnceCreatesTestCommandMissingApprovalWithoutTestCommand|TestDaemonRunOnceCreatesReleaseTestRunSnapshotAndJobForPendingTesting'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md` and `README.md`
- 后续批次：
  - 多 repo release 组合命令已在 Step 14 Batch 12 补齐。
  - 推断规则仍是保守白名单；更复杂的 monorepo、workspace 文件或自定义 package scripts 继续由用户命令或测试 Agent 报告补充。

## Step 14: Multi-repo test command inference - Batch 12

- 日期：2026-07-10
- 状态：完成，多 repo release 的测试命令组合推断已落地
- 范围：
  - 修复多 repo release 推断测试命令时只取第一个可推断 repo 的问题。
  - daemon pending-testing lane 会把所有可推断 repo 的命令组合为一个 release-level test command。
  - 组合命令格式为 `(cd backend && go test ./...) && (cd frontend && npm test)`。
  - 单 repo release 仍保持原有 `cd <repo> && <command>` 格式。
  - `test_command_source` 继续记录为 `inferred`。
- TDD 记录：
  - 新增 `TestDaemonRunOnceInfersReleaseTestCommandForMultipleRepos`。
  - 红灯：backend `go.mod` 和 frontend `package.json` 同时存在时，daemon 只生成 `cd backend && go test ./...`。
  - 绿灯：组合所有可推断 repo 命令后 focused tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-14-test-command-inference-multi-repo.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run TestDaemonRunOnceInfersReleaseTestCommandForMultipleRepos -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator ./internal/cli -run 'TestDaemonRunOnceInfersReleaseTestCommandForMultipleRepos|TestDaemonRunOnceInfersReleaseTestCommandFromGoModule|TestReleaseTestStartInfersGoModuleCommand'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md` and `README.md`
- 后续批次：
  - 推断规则仍是保守白名单；更复杂的 monorepo、workspace 文件或自定义 package scripts 继续由用户命令或测试 Agent 报告补充。
  - 组合命令使用 shell 串联语义；逐 repo inferred plan 已在 Step 14 Batch 13 写入 job input。

## Step 14: Inferred command plan in job input - Batch 13

- 日期：2026-07-10
- 状态：完成，测试 Agent 可见的逐 repo inferred command plan 已落地
- 范围：
  - `release_test` job input 在 `test_command_source=inferred` 时写入 `inferred_commands` 数组。
  - 每条 inferred command 包含 `repo_id`、`repo_name`、`worktree_path`、repo-local `command` 和完整 `full_command`。
  - 多 repo release 的合并 `test_command` 保持原有 shell 串联语义。
  - 单 repo release 的 `test_command` 保持原有 `cd <repo> && <command>` 格式。
  - 结构化数组让测试 Agent 可以逐 repo 执行、展示和写入测试报告，不需要反向解析合并后的 shell 命令。
- TDD 记录：
  - 扩展 `TestDaemonRunOnceInfersReleaseTestCommandForMultipleRepos`，要求 job input 包含 backend/frontend 两条 `inferred_commands`。
  - 红灯：job input 中 `inferred_commands` 为空。
  - 绿灯：daemon 保存 inferred command plan 并写入 job input 后 focused tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-14-inferred-command-plan.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run TestDaemonRunOnceInfersReleaseTestCommandForMultipleRepos -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run 'TestDaemonRunOnceInfersReleaseTestCommandForMultipleRepos|TestDaemonRunOnceInfersReleaseTestCommandFromGoModule'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md` and `README.md`
- 后续批次：
  - `workspace release test start/status/watch` 已在 Step 14 Batch 14 展示逐 repo inferred command 明细。
  - 如需历史不可变展示，再把 inferred plan 持久化到 dedicated store 字段或 artifact，避免重载 `test_command`。

## Step 14: Inferred command watch visibility - Batch 14

- 日期：2026-07-10
- 状态：完成，用户实时可见的 inferred command 明细已落地
- 范围：
  - `ReleaseWatchSnapshot` 为 `test_command_source=inferred` 的 release test run 生成逐 repo `InferredCommands`。
  - `workspace release test start`、`workspace release test status` 和 `workspace release watch` 输出 `test-command-inferred` 行。
  - 输出包含 test run id、repo name、repo-local command、full command 和 worktree path。
  - 用户和主 Agent 可以在 test run 创建后立即看到 inferred command 的来源，不需要等待 daemon job input 或解析合并后的 shell 命令。
- TDD 记录：
  - 扩展 `TestReleaseTestStartInfersGoModuleCommand`，要求 CLI 输出 `test-command-inferred`、repo name 和 repo-local command。
  - 红灯：CLI 只输出 `test-run ... inferred <combined-command>`，没有逐 repo 明细。
  - 绿灯：ReleaseWatchSnapshot 和 CLI 输出 inferred command 明细后 focused test 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-14-inferred-command-watch.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli -run TestReleaseTestStartInfersGoModuleCommand -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/cli -run TestReleaseTestStartInfersGoModuleCommand`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/workspace ./internal/cli ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md` and `README.md`
- 后续批次：
  - `ReleaseWatchSnapshot` 目前根据当前 release worktree 重新计算 inferred 明细；如需历史不可变展示，可在后续把 inferred plan 持久化到 release test run artifact 或 store 字段。

## Step 14: Release test failed event - Batch 15

- 日期：2026-07-10
- 状态：完成，release test failed 的 release 级诊断事件已落地
- 范围：
  - release test job 输出 `status=failed` 后，daemon 在创建 bug 前写入 release status event。
  - 失败诊断事件使用当前 release workflow 的 `testing -> testing` 形式，不推进 release workflow。
  - 事件 actor 为 `workspace-daemon`，reason 为 `release test failed`。
  - 事件绑定当前 `release_test_run_id` 和 release test job id，方便 release watch 与主 Agent 关联 test report、job event 和 bug。
  - 保持原有 bug 创建、需求回退 `pending_development` 和 `bug_created` run event 行为不变。
- TDD 记录：
  - 扩展 `TestDaemonRunOnceCreatesRequirementBugWhenReleaseTestFails`，要求 failed release test 写 release status event。
  - 红灯：release test failed 后 `release_status_events` 只有启动事件，缺少失败诊断。
  - 绿灯：在 failed post-processing 中写入 release status event 后 focused test 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-14-release-test-failed-event.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run TestDaemonRunOnceCreatesRequirementBugWhenReleaseTestFails -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/store ./internal/workspace ./internal/agent ./internal/coordinator ./internal/mcp ./internal/cli`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md` and `README.md`
- 后续批次：
  - 继续审计 release stale 之外的诊断型事件，确保用户不需要只靠 job event 才能理解 release 当前阻塞原因。

## Step 14: Release test start missing command approval - Batch 16

- 日期：2026-07-10
- 状态：完成，service/MCP/CLI 直接启动 release test 的无命令人工确认已落地
- 范围：
  - `StartReleaseTest` 在没有显式命令、release 默认命令、Agent 默认命令或 inferred 命令时，继续创建 `waiting_user_input` test run。
  - service 创建 requirement snapshot 后同步创建 `approval_type=test_command_missing` 的 pending approval。
  - approval 绑定当前 `release_id` 和 `release_test_run_id`，避免用户只能看到等待态 test run 而没有可响应确认项。
  - approval payload 写入 `release_id`、`release_key`、`release_test_run_id`、尝试过的命令来源、缺失原因、`required_user_action` 和 `test_command_required`。
  - 保持既有 `workspace approval respond ... --test-command <cmd>` 复用同一 test run 更新为 `queued` 的流程。
- TDD 记录：
  - 新增 `TestStartReleaseTestWithoutCommandCreatesMissingCommandApproval`。
  - 红灯：直接调用 `StartReleaseTest` 无命令时没有 pending `test_command_missing` approval。
  - 绿灯：service 创建 test run 快照后立即创建 scoped approval，focused test 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-14-release-test-start-missing-command-approval.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/workspace -run TestStartReleaseTestWithoutCommandCreatesMissingCommandApproval -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/workspace`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/store ./internal/workspace ./internal/agent ./internal/coordinator ./internal/mcp ./internal/cli`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md` and `README.md`
- 后续批次：
  - 继续审计 CLI/MCP/service 直接入口与 daemon 自动入口是否存在同类等待态可见但无 pending approval 的差异。

## Step 14: Test command missing rerun approval key - Batch 17

- 日期：2026-07-10
- 状态：完成，`test_command_missing` approval key 已按 release test run 隔离
- 范围：
  - service 和 daemon 创建 `test_command_missing` approval 时，key 改为 `test-command-missing-<release-slug>-run-<release_test_run_id>`。
  - 修复旧 key 只包含 release slug 时，用户 block 第一次缺少命令后，第二次无命令 test run 创建 approval 会触发唯一约束的问题。
  - 同一 test run 的 pending approval 仍按 `release_test_run_id` 去重并更新原 request。
  - 用户补充命令或选择 block 的响应流程不变，仍作用于 approval 绑定的同一个 test run。
- TDD 记录：
  - 新增 `TestStartReleaseTestWithoutCommandCreatesNewApprovalAfterBlockedRun`。
  - 红灯：第二次 `StartReleaseTest` 无命令时因重复 `approval_key` 触发 SQLite unique constraint。
  - 绿灯：approval key 纳入 `release_test_run_id` 后，第二次 test run 能创建新的 pending approval。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-14-test-command-missing-rerun-key.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/workspace -run 'TestStartReleaseTestWithoutCommandCreatesMissingCommandApproval|TestStartReleaseTestWithoutCommandCreatesNewApprovalAfterBlockedRun' -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run 'TestDaemonRunOnceCreatesTestCommandMissingApprovalWithoutTestCommand|TestDaemonRunOnceQueuesUserSuppliedTestCommandAfterApproval' -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/workspace`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/store ./internal/workspace ./internal/agent ./internal/coordinator ./internal/mcp ./internal/cli`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md` and `README.md`
- 后续批次：
  - 继续审计其他长周期人工确认 key，确认所有可能重复发生的 approval 都包含足够的业务 scope。

## Step 14: Test command missing response event - Batch 18

- 日期：2026-07-10
- 状态：完成，`test_command_missing` 响应后的 release 级可见性已补齐
- 范围：
  - 用户 approve `test_command_missing` 并提供 `--test-command` 后，service 仍把同一个 test run 更新为 `queued` 和 `test_command_source=user_supplied`。
  - 用户选择 `block` 时，service 仍把同一个 test run 更新为 `blocked`。
  - 两种响应都会写入 `release_status_events`，old/new status 均为当前 release workflow，不推进状态机。
  - 事件 actor 使用响应人，reason 分别记录 `test command provided; release test run queued` 或 `test command blocked; release test run blocked`。
  - 事件绑定当前 `release_test_run_id`，让 `release watch` 和主 Agent 能实时展示人工确认后的 next action。
- TDD 记录：
  - 新增 `TestRespondTestCommandMissingApprovalWritesReleaseStatusEvent`。
  - 红灯：`test_command_missing` 响应后 `release_status_events` 为空。
  - 绿灯：响应后写入 release 级诊断事件，focused test 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-14-test-command-response-event.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/workspace -run 'TestRespondTestCommandMissingApprovalQueuesSameTestRun|TestRespondTestCommandMissingApprovalWritesReleaseStatusEvent' -v`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/workspace`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/store ./internal/workspace ./internal/agent ./internal/coordinator ./internal/mcp ./internal/cli`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md` and `README.md`
- 后续批次：
  - 继续审计其他人工确认响应，确认 requirement/release 级的 next action 都有 status event 可供 watch 展示。

## Step 14: Release re-integrate and retest - Batch 7

- 日期：2026-07-09
- 状态：完成，Step 14 集成测试闭环仍在进行中
- 范围：
  - daemon 扫描 `workflow_status=testing` 且 `status=stale` 的 release，作为 bugfix 后 re-integrate/retest 入口。
  - release 仍有 open bug 时不会重新 integrate。
  - release 内所有 active requirements 必须 ready，且 workflow 必须是 `development_completed`、`pending_testing` 或 `testing`，才允许重新 integrate。
  - daemon 调用现有 `IntegrateRelease`，复用 release worktree dirty guard、feature SHA、release SHA 和 snapshot 刷新逻辑。
  - re-integrate 成功后，release workflow 回到 `pending_testing`，active requirements 回到 `pending_testing`。
  - 同一 tick 继续复用 `ensureReleaseTestJobs` 创建新的 `release_test_runs` 和 `release_test_run_requirements`。
  - release test job key 支持 rerun：首轮仍使用 `release-test-<release-slug>`，后续 test run 使用 `release-test-<release-slug>-run-<release_test_run_id>`，避免旧 failed job key 阻塞重测。
  - 新 test run 的 requirement snapshot 使用 re-integrate 后的新 feature commit 和 release commit。
- TDD 记录：
  - 新增 `TestDaemonRunOnceReintegratesReleaseAndQueuesRetestAfterBugfix`。
  - 红灯：bugfix 完成后下一轮 daemon 没有重新 integrate，也没有创建新的 release test job。
  - 绿灯：实现 release retest 扫描、re-integrate、workflow 回退 pending testing、release test rerun job key 后 focused test 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-14-release-retest.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run TestDaemonRunOnceReintegratesReleaseAndQueuesRetestAfterBugfix`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md`
- 后续批次：
  - Step 14 batch 8 需要实现 release test passed 且无 open bug 后的 `testing_completed` 和 `active_test_run_id`。
  - Step 15 需要实现 `publish_confirmation` 和 pending release/publish 入口。

## Step 14: Bugfix completion - Batch 6

- 日期：2026-07-09
- 状态：完成，Step 14 集成测试闭环仍在进行中
- 范围：
  - daemon 创建 `bugfix` job 前会恢复 requirement feature worktree：
    - requirement 仍是 ready 状态时调用 `ReopenRequirement`。
    - requirement 已经 reopened 时调用 `PrepareRequirementWorkspace` 校验/复用 worktree，支持 retry。
  - `bugfix` job 成功输出必须包含非空 `bugfix_report`。
  - daemon 在 post-run 阶段调用 `FinishRequirement`，确保 feature branch 已提交/推送、repo relation 回到 `completed`、worktree 已清理、`ready_at` 已恢复。
  - daemon 创建 requirement 级 `artifact_type=bugfix_report`、`stage=development` 的修复报告 artifact。
  - store 新增 `CloseRequirementBug`，把 `requirement_bugs.status` 从 `open` 更新为 `fixed`，写入 `fixed_by_job_id` 和 `closed_at`。
  - `CloseRequirementBug` 对重复关闭保持幂等，并校验 `fixed_by_job_id` 必须是绑定同一 bug/requirement 的 `bugfix` job。
  - bugfix 成功后 requirement workflow 推进到 `development_completed`，等待后续 release 重新 integrate/test。
  - bugfix job 写入用户可见 `artifact_created` 和 `bug_fixed` run events。
- TDD 记录：
  - 新增 `TestDaemonRunOnceCompletesBugfixReportAndClosesBug`。
  - 新增 `TestAINativeStoreClosesRequirementBug`。
  - 红灯：`bugfix` job 成功后没有 `bugfix_report` artifact，bug 仍为 open。
  - 红灯：store 缺少 `CloseRequirementBug`。
  - 绿灯：实现 bugfix workspace reopen/prepare、bugfix 输出解析、FinishRequirement、报告 artifact、bug close 和用户可见事件后 focused tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-14-bugfix-complete.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator ./internal/store -run 'TestDaemonRunOnceCompletesBugfixReportAndClosesBug|TestDaemonRunOnceCreatesBugfixJobForOpenReleaseBug|TestAINativeStoreClosesRequirementBug|TestAINativeStoreValidatesBugfixJobBugID'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator ./internal/store`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md`
- 后续批次：
  - Step 14 batch 7 需要实现 bug 关闭后的 release stale/re-integrate 和重新 test。
  - Step 14 batch 8 需要实现测试通过后的 `testing_completed`、`active_test_run_id` 和发布确认入口。

## Step 14: Release bugfix job - Batch 5

- 日期：2026-07-09
- 状态：完成，Step 14 集成测试闭环仍在进行中
- 范围：
  - daemon 在 development plan 前扫描 open `requirement_bugs`。
  - 为 `pending_development` 且配置了 enabled CodingAgent 和 coding worker pool 的 open bug 创建 `job_type=bugfix` 的 coding job。
  - `bugfix` job 使用 `bugfix-<requirement-slug>-<bug-id>` 稳定 key，避免重复 tick 重复排队。
  - `bugfix` job 绑定 `requirement_id`、`release_id`、`bug_id`、`agent_id` 和 `worker_pool_id`。
  - `bugfix` job input 写入 bug title、description、severity、repo、file path、reproduction、release test run id 和 required actions。
  - daemon 为 provider 创建 requirement workspace 根目录；feature repo worktree 由 CodingAgent 后续调用 `ReopenRequirement` 创建。
  - worker claim `bugfix` job 后把 requirement workflow 推进到 `developing`。
  - open bug 存在时，通用 `pending_development -> implementation_plan` 入口会跳过该需求，避免把 bugfix 当成新一轮完整开发。
  - store 层校验 `bug_id` 只能用于 `job_type=bugfix`，并校验 job 的 requirement/release 与 bug 归属一致。
- TDD 记录：
  - 新增 `TestDaemonRunOnceCreatesBugfixJobForOpenReleaseBug`。
  - 新增 `TestAINativeStoreValidatesBugfixJobBugID`。
  - 红灯：release test 创建 open bug 后，下一轮 daemon 没有创建 `bugfix` job。
  - 红灯：store 允许非 bugfix job 设置 `bug_id`。
  - 绿灯：实现 bugfix job 扫描、job input、claim 状态推进、development plan open bug guard 和 store bug 归属校验后 focused tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-14-bugfix-job.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run TestDaemonRunOnceCreatesBugfixJobForOpenReleaseBug`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/store -run TestAINativeStoreValidatesBugfixJobBugID`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md`
- 后续批次：
  - Step 14 batch 6 需要实现 bugfix job 的 `ReopenRequirement`、`FinishRequirement`、`bugfix_report` 和 bug close。
  - Step 14 batch 7 需要实现 bug 关闭后的 release 重新 integrate/test。

## Step 14: Release test bug creation - Batch 4

- 日期：2026-07-09
- 状态：完成，Step 14 集成测试闭环仍在进行中
- 范围：
  - 新增 `RequirementBug` store 模型。
  - 新增 `CreateRequirementBug` 和 `ListRequirementBugs`。
  - `release_test` 输出支持 `bugs` 数组。
  - bug 可以通过 `requirement_id` 直接定位，也可以通过 release test job input snapshot 中的 `requirement_key` 定位。
  - bug repo 可以通过 `repo_id` 直接定位，也可以通过 snapshot 中的 `repo_name` 定位。
  - `release_test` failed 后仍生成 `test_report` artifact，并把 test run 标记为 `failed`。
  - daemon 为每个 bug 创建 open `requirement_bugs`，记录 requirement、release、test run、severity、repo、file path、reproduction 和 created_by_job_id。
  - 创建 bug 后对应 requirement workflow 从 `testing` 退回 `pending_development`。
  - 创建 bug 后写入用户可见 `bug_created` run event。
  - 同一 test run、同一 requirement、同一 title 的 open bug 复用已有记录，避免 post-run retry 重复建 bug。
- TDD 记录：
  - 新增 `TestDaemonRunOnceCreatesRequirementBugWhenReleaseTestFails`。
  - 红灯：focused test 构建失败，缺少 `ListRequirementBugs` 和 `ListRequirementBugsParams`。
  - 绿灯：实现 requirement bug store、release test bug 输出解析、bug 创建、workflow 回退和 `bug_created` event 后 focused test 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-14-bug-create.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run TestDaemonRunOnceCreatesRequirementBugWhenReleaseTestFails`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md`
- 后续批次：
  - Step 14 batch 5 需要为 open bug 创建 `bugfix` job，并让 CodingAgent 进入 feature 分支修复。
  - Step 14 batch 6 需要实现 bugfix job 的 `ReopenRequirement`、`FinishRequirement`、`bugfix_report` 和 bug close。
  - Step 14 batch 7 需要实现 bug 关闭后的 release 重新 integrate/test。

## Step 14: Test command missing approval - Batch 3

- 日期：2026-07-09
- 状态：完成，Step 14 集成测试闭环仍在进行中
- 范围：
  - daemon 在 `pending_testing` release 无法解析测试命令时创建 `release_test_runs.status=waiting_user_input` 的 test run。
  - 缺少命令的 test run 仍创建 `release_test_run_requirements`，保存 requirement+repo+feature commit+release commit 快照。
  - daemon 创建 `approval_type=test_command_missing` 的 pending approval，并绑定 `release_id` 与 `release_test_run_id`。
  - approval payload 写入 `release_test_run_id`、已尝试的 `test_command_sources`、失败原因和用户动作提示。
  - daemon 遇到已有 `waiting_user_input` test run 时保持等待，避免重复创建 test run 或 approval。
  - `workspace approval respond <approval-key> --choice approve --test-command <cmd>` 会把同一个 test run 更新为 `queued`、`test_command=<cmd>`、`test_command_source=user_supplied`。
  - `test_command_missing` response 支持 `choice=block`，会把同一个 test run 标记为 `blocked`。
  - 用户补充命令后，下一轮 daemon 复用同一个 `release_test_run_id` 创建 `release-test-<release-slug>` job，job input 写入 `test_command_source=user_supplied`。
  - CLI `workspace approval respond` 新增 `--test-command` 参数。
- TDD 记录：
  - 将无命令场景升级为 `TestDaemonRunOnceCreatesTestCommandMissingApprovalWithoutTestCommand`。
  - 新增 `TestRespondTestCommandMissingApprovalQueuesSameTestRun`。
  - 新增 `TestDaemonRunOnceQueuesUserSuppliedTestCommandAfterApproval`。
  - 红灯 1：测试构建失败，`RespondApprovalParams` 缺少 `TestCommand`。
  - 红灯 2：daemon 无命令路径没有创建 `test_command_missing` approval 和 waiting test run。
  - 绿灯：实现 store test run command 更新、approval response 处理、daemon approval 创建、active test run 复用和 user supplied command job 创建后 focused tests 通过。
- Review 记录：
  - 独立 Review 文档：`docs/ai-native-review-step-14-test-command-missing.md`。
- 验证：
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/workspace -run TestRespondTestCommandMissingApprovalQueuesSameTestRun`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator -run 'TestDaemonRunOnceCreatesTestCommandMissingApprovalWithoutTestCommand|TestDaemonRunOnceQueuesUserSuppliedTestCommandAfterApproval'`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./internal/coordinator ./internal/workspace ./internal/cli`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go test -count=1 ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go vet ./...`
  - `env GOCACHE=/private/tmp/workspace-cli-gocache GOMODCACHE=/private/tmp/workspace-cli-gomodcache GOSUMDB=off go build ./cmd/workspace`
  - `git diff --check`
  - Markdown fenced code block balance check over `docs/*.md`
- 后续批次：
  - Step 14 batch 4 需要实现测试失败创建 bug、CodingAgent 修复和重新集成测试。
  - Step 14 batch 5 需要实现无 open bug 且测试通过后的 `testing_completed` 和 `active_test_run_id`。
