ccgx-workflow 2.4.2 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +134 -277
  2. package/README.zh-CN.md +134 -272
  3. package/dist/chunks/version-build.mjs +1 -1
  4. package/dist/cli.mjs +1 -1
  5. package/dist/index.d.mts +709 -16
  6. package/dist/index.d.ts +709 -16
  7. package/dist/index.mjs +1061 -30
  8. package/dist/shared/{ccgx-workflow.eLNeCiD8.mjs → ccgx-workflow.CdHnJLak.mjs} +106 -22
  9. package/package.json +1 -1
  10. package/templates/commands/agents/code-fixer.md +6 -6
  11. package/templates/commands/agents/phase-runner.md +46 -14
  12. package/templates/commands/agents/plan-checker.md +10 -0
  13. package/templates/commands/analyze.md +66 -25
  14. package/templates/commands/autonomous.md +428 -225
  15. package/templates/commands/cancel.md +9 -0
  16. package/templates/commands/codex-exec.md +12 -11
  17. package/templates/commands/context.md +14 -0
  18. package/templates/commands/debate.md +10 -6
  19. package/templates/commands/execute.md +76 -28
  20. package/templates/commands/optimize.md +53 -25
  21. package/templates/commands/plan.md +78 -28
  22. package/templates/commands/review.md +26 -19
  23. package/templates/commands/spec-impl.md +68 -127
  24. package/templates/commands/spec-plan.md +61 -82
  25. package/templates/commands/spec-research.md +35 -92
  26. package/templates/commands/spec-review.md +34 -119
  27. package/templates/commands/status.md +1 -0
  28. package/templates/commands/team-exec.md +45 -13
  29. package/templates/commands/team.md +64 -167
  30. package/templates/commands/test.md +56 -34
  31. package/templates/commands/verify-work.md +36 -13
  32. package/templates/commands/verify.md +35 -0
  33. package/templates/commands/workflow.md +22 -37
  34. package/templates/hooks/ccg-loop-detector.cjs +39 -8
  35. package/templates/hooks/ccg-statusline.js +142 -2
  36. package/templates/hooks/ccg-stop-gate.cjs +241 -16
  37. package/templates/hooks/ccg-subagent-context.cjs +505 -0
  38. package/templates/scripts/ccg-state-lock.cjs +510 -0
  39. package/templates/scripts/ccg-team-schedule.cjs +328 -0
  40. package/templates/scripts/ccgx-call-plugin.mjs +494 -141
  41. package/templates/scripts/invoke-model.mjs +28 -1
  42. package/templates/scripts/task-store.cjs +614 -0
  43. package/templates/skills/tools/verify-change/SKILL.md +7 -0
  44. package/templates/skills/tools/verify-module/SKILL.md +7 -0
  45. package/templates/skills/tools/verify-quality/SKILL.md +7 -0
  46. package/templates/skills/tools/verify-security/SKILL.md +8 -0
@@ -85,6 +85,15 @@ allowed-tools:
85
85
  Status: canceled (forced via kill-tree)
86
86
  ```
87
87
 
88
+ ## Workflow 模式 job(state.json `run_mode: 'workflow'`)
89
+
90
+ `/ccg:autonomous` 原生 Workflow 编排 job 由引擎后台托管,**state.json 无 `cli_pid`**:
91
+
92
+ - Step 4 kill-tree **不适用**——没有可杀的 OS 子进程记录,跳过并向用户说明
93
+ - cancel.flag 协作生效点 = **下一 phase 开工前**:phase-runner 按契约开工前 Read `cancel.flag`,存在则返回 `cancel-flag-detected` 摘要,workflow 脚本 break、后续 phase 不再启动
94
+ - **当前正在跑的 phase 不会被本命令中断**——中断进行中 phase 需引擎级中止(如 `/workflows` 面板操作,以运行时实际能力为准);flag 只保证后续 phase 不再启动
95
+ - 取消后续跑:`/ccg:autonomous --resume <job-id>`(已完成 phase 的 agent() 调用缓存重放,不重跑)
96
+
88
97
  ## 严格约束
89
98
 
90
99
  - ✅ **协作优先**——总是先写 cancel.flag 给子进程自己退的机会,避免半写文件
@@ -48,13 +48,13 @@ $ARGUMENTS
48
48
 
49
49
  **调用通道路由(CCG codeagent 退役,v2.2.0+)**
50
50
 
51
- 1. **优先 plugin spawn**(默认):plugin 已装 → `Agent(subagent_type="codex:codex-rescue")`,session 复用通过 prompt 内 `--resume` flag 表达(subagent 映射为 codex `--resume-last`)。
51
+ 1. **优先 plugin 路径**(默认):plugin 已装 → codex 执行用 `Agent(subagent_type="codex:codex-rescue")`(codex 自家 thin forwarder,无 ACP 慢路径问题;session 复用通过 prompt 内 `--resume` flag 映射 codex `--resume-last`);**双模型审核(含 gemini)改走 Bash 直调快路径**(`{{CODEX_BASH_TASK}}` / `{{GEMINI_BASH_TASK}}` + `--prompt-file`),绕开 `gemini-companion→ACP` 5+min 慢路径与 sonnet wrapper silent-fallback。
52
52
  2. **降级 codeagent-wrapper**(BC fallback):plugin 未装 → Bash 调用,保留 `resume <SESSION_ID>` 显式会话管理。
53
53
 
54
54
  **判定**:preflight `Bash` 跑 `node ~/.claude/.ccg/scripts/check-plugins.cjs`(解析 Claude Code 权威 `installed_plugins.json`)。exit `0` + stdout `{"codex":"<ver>","gemini":"<ver>"}` → 通道 A(plugin 默认);非 `0` → 通道 B(wrapper BC fallback)。
55
55
 
56
56
  **会话模型差异**:
57
- - **通道 A(plugin)**:session 是同一 Claude session 内的最近 codex/gemini thread(`--resume-last`)。同任务多 phase 顺序执行 OK;不支持跨任务跳点 resume by ID。
57
+ - **通道 A(plugin)**:codex Agent session 是同一 Claude session 内的最近 codex thread(`--resume-last`);Bash 直调审核从 `JSON.parse(stdout).threadId` 取会话标识。同任务多 phase 顺序执行 OK;不支持跨任务跳点 resume by ID。
58
58
  - **通道 B(wrapper)**:显式 `SESSION_ID`,可跨流程任意复用历史 thread。
59
59
 
60
60
  ---
@@ -78,6 +78,7 @@ ${implementerRole}
78
78
  </task>
79
79
 
80
80
  <action_safety>
81
+ - **必须前台执行,禁止 --background / --wait**(ccgx 编排层已用 Agent 包裹,插件内再 background = 双重后台,stop-gate / status / cancel 全盲)
81
82
  - Stay strictly within the plan scope
82
83
  - Run lint/typecheck if available before reporting completion
83
84
  </action_safety>`
@@ -118,7 +119,7 @@ Bash({
118
119
  })
119
120
  ```
120
121
 
121
- **审核调用(通道 A,双模型并行)**:参照 `/ccg:spec-review` Step 3.1 pattern——`Agent(codex:codex-rescue)` + `Agent(gemini:gemini-rescue)` 同 message 并行,预读 `reviewer.md` 拼入 `<role>` 块。通道 B 同 `<<'REVIEW_EOF'... wrapper` 模式(已 deprecated)。
122
+ **审核调用(通道 A,双模型并行 Bash 直调)**:参照 `/ccg:spec-review` Step 3.1(已迁 Bash 直调快路径)——Write 两个 tmpfile(≤2KB,让模型自己 Read `reviewer.md` + `git diff` 读变更,加硬约束"必须前台执行,禁止 --background"),再 `{{CODEX_BASH_TASK}} --prompt-file <tmpfile-codex>` + `{{GEMINI_BASH_TASK}} --prompt-file <tmpfile-gemini>` 同 message 并行 `run_in_background: true`,绕开 `Agent→gemini-companion→ACP` 慢路径与 sonnet wrapper silent-fallback,主线 `JSON.parse(stdout).text`。通道 B 同 `<<'REVIEW_EOF'... wrapper` 模式(已 deprecated)。
122
123
 
123
124
  **角色提示词**:
124
125
 
@@ -343,19 +344,19 @@ Bash({
343
344
  Bash({ command: "git diff HEAD", description: "获取完整变更 diff" })
344
345
  ```
345
346
 
346
- 2. **并行调用**(`run_in_background: true`):
347
+ 2. **并行 Bash 直调 helper**(先 Write 两个 tmpfile,再 `{{CODEX_BASH_TASK}}` / `{{GEMINI_BASH_TASK}}` + `--prompt-file`,`run_in_background: true`):
347
348
 
348
- - **{{BACKEND_PRIMARY}} 审查**:
349
- - ROLE_FILE: `~/.claude/.ccg/prompts/{{BACKEND_PRIMARY}}/reviewer.md`
350
- - 输入:变更 Diff + 计划文件内容
349
+ - **{{BACKEND_PRIMARY}} 审查**(`{{CODEX_BASH_TASK}} --prompt-file <tmpfile>`):
350
+ - 角色:tmpfile 内写"角色定义见 `~/.claude/.ccg/prompts/{{BACKEND_PRIMARY}}/reviewer.md`,先用 Read 工具读取再开始"
351
+ - 输入:让模型自己 `git diff HEAD` 读变更(主线不重传);硬约束"必须前台执行,禁止 --background"
351
352
  - 关注:安全性、性能、错误处理、逻辑正确性
352
353
 
353
- - **{{FRONTEND_PRIMARY}} 审查**:
354
- - ROLE_FILE: `~/.claude/.ccg/prompts/{{FRONTEND_PRIMARY}}/reviewer.md`
355
- - 输入:变更 Diff + 计划文件内容
354
+ - **{{FRONTEND_PRIMARY}} 审查**(`{{GEMINI_BASH_TASK}} --prompt-file <tmpfile>`):
355
+ - 角色:tmpfile 内写"角色定义见 `~/.claude/.ccg/prompts/{{FRONTEND_PRIMARY}}/reviewer.md`,先用 Read 工具读取再开始"
356
+ - 输入:让模型自己 `git diff HEAD` 读变更(主线不重传);硬约束"必须前台执行,禁止 --background"
356
357
  - 关注:代码可读性、设计一致性、可维护性
357
358
 
358
- `TaskOutput` 等待两个模型的完整审查结果。
359
+ 事件驱动等待两个 task 的 notification(**不调 TaskOutput**),Read stdout 后 `JSON.parse(stdout).text` 取真实审查输出。
359
360
 
360
361
  3. **整合审查意见**:
361
362
  - 按信任规则:后端问题以 {{BACKEND_PRIMARY}} 为准,前端问题以 {{FRONTEND_PRIMARY}} 为准
@@ -43,6 +43,9 @@ description: '项目上下文管理:初始化 .context 目录、记录决策
43
43
  .context/
44
44
  ├── .gitignore
45
45
  ├── .gitattributes
46
+ ├── STATE.json # 项目级生命周期投影(task-store 派生,机器态,本地不入 repo)
47
+ ├── tasks/ # task-store 持久化容器:每任务一目录 + task.json(artifacts[] 指针登记)
48
+ │ └── archive/ # 已归档任务(YYYY-MM/<task-id>/)
46
49
  ├── prefs/
47
50
  │ ├── coding-style.md
48
51
  │ └── workflow.md
@@ -56,12 +59,22 @@ description: '项目上下文管理:初始化 .context 目录、记录决策
56
59
  └── .gitkeep
57
60
  ```
58
61
 
62
+ > `tasks/` 与 `STATE.json` 由 task-store 维护(`node ~/.claude/.ccg/scripts/task-store.cjs`),
63
+ > init 时无需预创建——首次 `create` / `register-artifact` 会自动建目录。
64
+ > 容器需 `node ~/.claude/.ccg/scripts/task-store.cjs create --id <slug> --title <t>` 显式激活,
65
+ > 标准工作流当前不自动创建;完成后用 `complete` 归档。
66
+
59
67
  4. **创建 `.context/.gitignore`**:
60
68
 
61
69
  ```gitignore
62
70
  # Ephemeral workspace — never commit
63
71
  current/
64
72
 
73
+ # task-store 机器态 — 本地审计,不入 repo(与 fix-log.jsonl 策略一致,
74
+ # 避免 task.json / STATE.json 在多人协作时产生合并冲突)
75
+ STATE.json
76
+ tasks/
77
+
65
78
  # Raw interaction logs — always local only
66
79
  **/session.log
67
80
  **/session.raw.log
@@ -330,3 +343,4 @@ history/archives/*.jsonl merge=union
330
343
  5. **UUIDv7 为主键** — 不依赖 commit SHA(rebase-safe)
331
344
  6. **merge=union** — JSONL append 冲突自动合并
332
345
  7. **脱敏先于一切** — 任何写入 history 前必须脱敏
346
+ 8. **tasks/ 与 STATE.json 由 task-store 维护** — `artifacts[]` 只存指针不搬产物;STATE.json 是派生投影,可随时由 `syncProjectState`(或任意一次 task-store 变更命令)重建,损坏直接删除即可
@@ -60,11 +60,13 @@ argument-hint: "<topic> [--max-rounds N] [--layer backend|frontend|fullstack]"
60
60
 
61
61
  1. 取 `round = plan[i]`
62
62
  2. 对 `round.models` 中的每个 model:
63
- - **plugin 路径**(`pluginSubagent` = `codex:codex-rescue` `gemini:gemini-rescue`):spawn `Agent(subagent_type=round.pluginSubagent[idx], prompt=<下面的 prompt 模板>)`
64
- - codex 模型 `Agent(subagent_type="codex:codex-rescue", ...)`
65
- - gemini 模型 `Agent(subagent_type="gemini:gemini-rescue", ...)`
63
+ - **plugin 路径(Bash 直调快路径,默认)**:占位符 `{{CODEX_BASH_TASK}}`(codex 模型)/ `{{GEMINI_BASH_TASK}}`(gemini 模型)已由 install 渲染为 `node <ccgx-call-plugin.mjs 绝对路径> <vendor> --json`。
64
+ - Write 本轮 prompt 到 tmpfile(≤2KB,内容 = 下方 Round prompt 模板 + 硬约束"角色定义见 `round.ccgPromptFiles[idx]`,先 Read 再开始;**必须前台执行,禁止 --background / --wait**")
65
+ - **propose(首轮)/ challenge 轮**(对辩纯讨论只读,一律加 `--no-write`):`Bash({ command: \`{{CODEX_BASH_TASK 或 GEMINI_BASH_TASK}} --no-write --prompt-file <tmpfile>\`, run_in_background: true })`
66
+ - **respond 轮(C5 增量)**:加 `--resume-last` 接续本 vendor 上一轮 thread,tmpfile **只写 delta**("respond 上一轮 challenge:<challenge 内容>"),不重述完整方案——`Bash({ command: \`{{CODEX_BASH_TASK 或 GEMINI_BASH_TASK}} --resume-last --no-write --prompt-file <delta-tmpfile>\`, run_in_background: true })`
67
+ - 主线 Read stdout 后 `JSON.parse(stdout).text` 取模型 ≤200 token 摘要
66
68
  - **降级路径**(`models[idx] === 'general-purpose'`):spawn `Agent(subagent_type="general-purpose", prompt=<内嵌 round.ccgPromptFiles[idx] 文件全文> + <下面的 prompt 模板>)`
67
- 3. ⛔ **plugin spawn 失败必须重试**:若 `Agent(subagent_type="codex:codex-rescue"|"gemini:gemini-rescue")` 调用失败(spawn 抛错 / 返回非结构化错误 / `parseRoundSummary` 返回 `parsed=false`),最多重试 **2 次**(间隔 **5 秒**)。仅当 **3 次全部失败**时才把该模型本轮替换为 general-purpose 降级路径,并在合成的 `RoundSummary.notes` 标 `plugin spawn failed after 3 attempts, degraded: <具体根因>`。⛔ **禁止**单次失败或单次 broker 负信号即降级——broker 懒启动属正常态。
69
+ 3. ⛔ **Bash 直调失败必须重试**:若 helper 调用失败(exit 0 / stdout < 100B / `JSON.parse` 抛错 / `parseRoundSummary` 返回 `parsed=false`),最多重试 **2 次**(间隔 **5 秒**)。仅当 **3 次全部失败**时才把该模型本轮替换为 general-purpose 降级路径,并在合成的 `RoundSummary.notes` 标 `plugin spawn failed after 3 attempts, degraded: <具体根因>`。⛔ **禁止**单次失败即降级。Bash 直调消除了 `Agent→gemini-companion→ACP` 慢路径与 sonnet wrapper silent-fallback(broker 故障时自答 fabricated challenge 视角)。
68
70
 
69
71
  **schema 硬约束**:标记格式必须是 `plugin spawn failed after N attempts, degraded: <reason>` 三段式(N 必须 ≥ 3,reason 必须给具体根因如 `broker timeout` / `API quota` / `parse-failed`,禁用占位文本如 `unknown` / `n/a`)。`parseRoundSummary` 自动从 NOTES 抽取 populate `RoundSummary.degraded`,Step 2 综合阶段会调 `validateRetryProtocol(累积 RoundSummary[])` 校验合规——违规会出现在最终输出的 ⚠️ 协议违规区段(用户可见)。这是把"3 次重试 + degraded 标记"从 prompt 软约束硬化为 schema-level 校验。
70
72
  4. **等待所有 model 返回**(`run_in_background: true` + 事件驱动等通知(不调 TaskOutput))
@@ -153,8 +155,10 @@ helper 暴露:
153
155
 
154
156
  ## 不做
155
157
 
156
- - ❌ **不**改源代码 / 不写文件(debate 是纯讨论原语)
157
- - ❌ **不**调 codeagent-wrapper(debate 走 plugin spawn 范式)
158
+ - ❌ **不**改源代码 / 不写文件(debate 是纯讨论原语;tmpfile 是临时 prompt 载体不算产物)
159
+ - ❌ **不**调 codeagent-wrapper(debate 走 Bash 直调 plugin 快路径)
160
+ - ❌ **不**写 `Agent(subagent_type="gemini:gemini-rescue")`(ACP 慢路径 + silent-fallback)——plugin 路径一律 Bash 直调 helper
161
+ - ❌ **不**让 plugin 内部 `--background`(双重后台,stop-gate/status/cancel 全盲)
158
162
  - ❌ **不** spawn debate-manager subagent 让它管对辩——主线自己管,逐轮接摘要
159
163
 
160
164
  ## 与其他命令的关系
@@ -22,14 +22,14 @@ $ARGUMENTS
22
22
 
23
23
  ## 调用通道路由(CCG codeagent 退役)
24
24
 
25
- CCG 把 6 核心命令的"双模型并行"通道从 `Bash(codeagent-wrapper)` **默认切换**为 plugin spawn。判定流程:
25
+ CCG 把"双模型并行"通道从 `Bash(codeagent-wrapper)` **默认切换**为 Bash 直调 plugin 快路径。判定流程:
26
26
 
27
- 1. **优先 plugin spawn 路径**(默认):用户已装 `codex@openai-codex` 和 gemini plugin(推荐 `gemini@gemini-ccgx` fork,已含全部 patch;或上游 `gemini@google-gemini` 配 repatch)→ 用 `Agent(subagent_type="codex:codex-rescue")` + `Agent(subagent_type="gemini:gemini-rescue")` 并行 spawn,主线只接 plugin 自家 ≤200 token 摘要。
27
+ 1. **优先 Bash 直调 plugin 快路径**(默认):用户已装 `codex@openai-codex` 和 gemini plugin(推荐 `gemini@gemini-ccgx` fork,已含全部 patch;或上游 `gemini@google-gemini` 配 repatch)→ 用 `{{CODEX_BASH_TASK}}` / `{{GEMINI_BASH_TASK}}` 占位符 + `--prompt-file` 并行 Bash 直调(review.md 同款),绕开 sonnet wrapper silent-fallback;**仅 `gemini-ccgx` fork 走 gemini-batch 29s 快路径,上游 + repatch 仍走 companion(ACP) 慢路径**(Windows 实测 5+min 卡死风险仍在),主线 `JSON.parse(stdout)` `.text` / `.threadId`。
28
28
  2. **降级 codeagent-wrapper 路径**(BC fallback):plugin 未装 → fallback 到 `Bash(~/.claude/bin/codeagent-wrapper ...)`,行为与 plugin 路径等价。
29
29
 
30
30
  **判断方法**:preflight `Bash` 跑 `node ~/.claude/.ccg/scripts/check-plugins.cjs`(解析 Claude Code 权威 `installed_plugins.json`)。返回 JSON `{"codex":"<ver>"|null,"gemini":"<ver>"|null}`,两个 plugin 独立判定,可 mix-and-match(仅 codex 装了 → backend 走 plugin、frontend 走 codeagent)。exit `0` = 两 plugin 都在;非 `0` = 至少一个缺。
31
31
 
32
- ⚠️ Execute 命令在主线 context 内,**允许**调 `Agent(...)`——与 subagent "引擎层禁止嵌套 spawn" 约束不冲突。
32
+ ⚠️ Execute 命令在主线 context 内执行,通道 A 走 Bash 直调(不再 spawn `Agent(...)`),无嵌套 spawn 顾虑。
33
33
 
34
34
  ---
35
35
 
@@ -42,28 +42,47 @@ CCG 把 6 核心命令的"双模型并行"通道从 `Bash(codeagent-wrapper)` **
42
42
 
43
43
  **调用语法**(双通道):
44
44
 
45
- **通道 A — plugin spawn(默认,原型生成)**:
45
+ **通道 A — Bash 直调 plugin 快路径(默认,原型生成)**:
46
+
47
+ > 占位符 `{{CODEX_BASH_TASK}}` / `{{GEMINI_BASH_TASK}}` 由 install 时渲染为
48
+ > `node <ccgx-call-plugin.mjs 绝对路径> <vendor> --json`。LLM **只需把 prompt
49
+ > 写入 tmpfile、追加 `--prompt-file <tmpfile>`、运行**,不写 `Agent(...)`。
46
50
 
47
51
  ```
48
- Agent({
49
- subagent_type: "<codex:codex-rescue|gemini:gemini-rescue>",
50
- description: "Execute prototype: <backend|frontend>",
51
- prompt: `ROLE_FILE: <角色提示词路径>
52
+ Step 1. 用 Write 把任务描述写到 tmpfile(≤2KB,计划/目标文件用路径引用,不内联大段源码):
53
+ Write({ file_path: ".context/tmp/ccg-exec-codex-$JOB.txt", content: <下方"任务描述模板"> })
54
+ Write({ 同上,gemini 版本,file_path: ".context/tmp/ccg-exec-gemini-$JOB.txt" })
55
+
56
+ Step 2. 用 Bash 调 helper(占位符已渲染;并行两个在同一 message 内 run_in_background: true):
57
+ Bash({ command: `{{CODEX_BASH_TASK}} --prompt-file .context/tmp/ccg-exec-codex-$JOB.txt`, description: "Execute prototype: backend (codex direct)", run_in_background: true })
58
+ Bash({ command: `{{GEMINI_BASH_TASK}} --prompt-file .context/tmp/ccg-exec-gemini-$JOB.txt`, description: "Execute prototype: frontend (gemini direct)", run_in_background: true })
59
+
60
+ Step 3. 等 task-notification 后 Read 各自 stdout,`JSON.parse(stdout)` 取 `.text`(= Unified Diff)与
61
+ `.threadId`(保存为 CODEX_SESSION / GEMINI_SESSION,**审计阶段用 `--resume-last` 增量复用同一会话**,无需重发计划上下文)。
62
+ ```
63
+
64
+ **任务描述模板**(写到 tmpfile 的内容;保持 ≤2KB):
65
+
66
+ ```
67
+ # 任务:实现原型(生成 Unified Diff,不落盘)
68
+
69
+ 工作目录:<工作目录绝对路径>(你已在此,可直接用 Bash/Read)
70
+ 角色定义见 <角色提示词路径>(codex 用 ~/.claude/.ccg/prompts/{{BACKEND_PRIMARY}}/architect.md,gemini 用 {{FRONTEND_PRIMARY}}/frontend.md),**先用 Read 工具读取该文件再开始**。
71
+
72
+ ## 你要做的事
52
73
 
53
- <TASK>
54
74
  需求:<任务描述>
55
- 上下文:<计划内容 + 目标文件>
56
- </TASK>
75
+ 上下文:<计划文件路径 + 目标文件路径,自己 Read,不内联大段源码>
57
76
 
58
- OUTPUT: Unified Diff Patch ONLY. Strictly prohibit any actual modifications.
59
- Return ≤200 token structured summary (plugin-native protocol).
60
- `
61
- })
77
+ ## 硬约束
78
+
79
+ - **必须前台执行,禁止 `--background` / `--wait`**(ccgx 编排层已用 Agent run_in_background 包裹,插件内再 background = 双重后台,stop-gate / status / cancel 全盲)。
80
+ - OUTPUT: Unified Diff Patch ONLY. Strictly prohibit any actual file modifications.
62
81
  ```
63
82
 
64
- > Plugin 上下文不需要 `resume <SESSION_ID>` —— plugin advisor 自己管理跨调用 session(用 `description` 区分阶段即可)。
83
+ **严禁**:内联大段源码(撞 argv ~32KB 上限);写 `Agent(subagent_type="gemini:gemini-rescue")`(走 ACP 慢路径);heredoc / `-p "..."` 内联;硬编码 plugin 路径。**唯一允许**:copy 占位符 + 追加 `--prompt-file <tmpfile>`(增量轮加 `--resume-last`)。
65
84
 
66
- **通道 B — codeagent-wrapper fallback**(plugin 未装时降级,并行用 `run_in_background: true`):
85
+ **通道 B — codeagent-wrapper fallback**(plugin 未装时降级,并行用 `run_in_background: true`;wrapper 的 `ROLE_FILE:` 由 `invoke-model.mjs` 解析故保留):
67
86
 
68
87
  ```
69
88
  # 复用会话调用(推荐)- 原型生成(Implementation Prototype)
@@ -97,7 +116,34 @@ EOF",
97
116
  })
98
117
  ```
99
118
 
100
- **审计调用语法**(Code Review / Audit):
119
+ **审计调用语法(通道 A 优先,Code Review / Audit)**:
120
+
121
+ > C5 增量:审计阶段复用实施阶段的会话——**仅对本任务在 Phase 3 实际有过实施会话的 vendor** 加 `--resume-last`,只发"审计上面刚生成的实现"
122
+ > 这条增量指令,**不重发计划 / 目标文件**。helper 透传到 `codex exec resume --last`,省 token 且避免上下文漂移。
123
+ > 另一侧 vendor(Route A/B 单端实施时)无可接续会话,走无状态审查——**不加** `--resume-last`,tmpfile 已指示模型自己跑 `git diff` 读变更。
124
+
125
+ ```
126
+ Step 1. Write 审计任务到 tmpfile(≤1KB,只放审计指令 + 让模型自己 git diff 读 patch):
127
+ Write({ file_path: ".context/tmp/ccg-exec-audit-codex-$JOB.txt", content: <下方审计任务模板> })
128
+
129
+ Step 2. Bash 直调 helper(只读审计加 --no-write;resume 增量仅限有实施会话的 vendor):
130
+ Bash({ command: `{{CODEX_BASH_TASK}} --resume-last --no-write --prompt-file .context/tmp/ccg-exec-audit-codex-$JOB.txt`, description: "Audit (codex resume)", run_in_background: true })
131
+ ```
132
+
133
+ 审计任务模板(写入 tmpfile):
134
+
135
+ ```
136
+ # 任务:审计刚生成的代码变更(接续上一轮会话)
137
+
138
+ 工作目录:<工作目录绝对路径>
139
+ 角色定义见 ~/.claude/.ccg/prompts/{{BACKEND_PRIMARY}}/reviewer.md,**先用 Read 工具读取再开始**。
140
+ **必须前台执行,禁止 --background。**
141
+
142
+ 自己跑 `git diff HEAD` 看已落盘的最终 patch(主线不重传)。
143
+ OUTPUT (JSON): { "issues": [{severity, file, rationale}], "fixes": [...] }。只输出 JSON。
144
+ ```
145
+
146
+ **审计调用语法(通道 B,codeagent-wrapper fallback)**:
101
147
 
102
148
  ```
103
149
  Bash({
@@ -129,9 +175,9 @@ EOF",
129
175
  | 实施 | `~/.claude/.ccg/prompts/{{BACKEND_PRIMARY}}/architect.md` | `~/.claude/.ccg/prompts/{{FRONTEND_PRIMARY}}/frontend.md` |
130
176
  | 审查 | `~/.claude/.ccg/prompts/{{BACKEND_PRIMARY}}/reviewer.md` | `~/.claude/.ccg/prompts/{{FRONTEND_PRIMARY}}/reviewer.md` |
131
177
 
132
- **会话复用**:如果 `/ccg:plan` 提供了 SESSION_ID,使用 `resume <SESSION_ID>` 复用上下文。
178
+ **会话复用**:通道 A 用 `--resume-last` 接续上一轮(codex 即刻可用;gemini 需 gemini-ccgx plugin ≥1.3.0——helper 有版本闸门,过旧会显式报错),或显式保存 `.threadId`;通道 B 用 `resume <SESSION_ID>`。`/ccg:plan` 交接的 `CODEX_SESSION` / `GEMINI_SESSION` 供通道 B `resume` 使用。
133
179
 
134
- **事件驱动等待**:spawn 后主线说明 task-id 然后 **turn end**,引擎自动 `<task-notification>` 触发新 turn 处理结果。**不调 TaskOutput**。
180
+ **事件驱动等待**:spawn 后主线说明 task-id 然后 **turn end**,引擎自动 `<task-notification>` 触发新 turn,Read stdout 后 `JSON.parse(stdout).text`(通道 A)/ `--progress` 行(通道 B)。**不调 TaskOutput**。
135
181
 
136
182
  ⛔ **禁止**:调 `TaskOutput({block: true, timeout: 600000})` 旧 freeze poll 模式 / Kill task。
137
183
 
@@ -227,7 +273,7 @@ EOF",
227
273
  1. **并行调用**(`run_in_background: true`):
228
274
  - {{FRONTEND_PRIMARY}}:处理前端部分
229
275
  - {{BACKEND_PRIMARY}}:处理后端部分
230
- 2. `TaskOutput` 等待两个模型的完整结果
276
+ 2. 事件驱动等待 task-notification(**不调 TaskOutput**),各自 Read stdout 取完整结果
231
277
  3. 各自使用计划中对应的 `SESSION_ID` 进行 `resume`(若缺失则创建新会话)
232
278
 
233
279
  **务必遵循上方 `多模型调用规范` 的 `重要` 指示**
@@ -275,17 +321,19 @@ EOF",
275
321
 
276
322
  **变更生效后,强制立即并行调用** {{BACKEND_PRIMARY}} 和 {{FRONTEND_PRIMARY}} 进行 Code Review:
277
323
 
278
- 1. **{{BACKEND_PRIMARY}} 审查**(`run_in_background: true`):
279
- - ROLE_FILE: `~/.claude/.ccg/prompts/{{BACKEND_PRIMARY}}/reviewer.md`
280
- - 输入:变更的 Diff + 目标文件
324
+ **`--resume-last` 守卫**:仅对本任务在 Phase 3 实际有过实施会话的 vendor 追加 `--resume-last`(Route C 全栈 = 双侧都加;Route A/B 单端 = 只加实施侧);另一侧 vendor 无可接续会话,走无状态审查——**不加** `--resume-last`,tmpfile 已指示模型自己跑 `git diff HEAD` 读变更。审查为只读,两侧一律加 `--no-write`。
325
+
326
+ 1. **{{BACKEND_PRIMARY}} 审查**(`{{CODEX_BASH_TASK}} --no-write --prompt-file <tmpfile>`,Phase 3 有 codex 实施会话时加 `--resume-last`,`run_in_background: true`):
327
+ - 角色:tmpfile 内写"角色定义见 `~/.claude/.ccg/prompts/{{BACKEND_PRIMARY}}/reviewer.md`,先用 Read 工具读取再开始"
328
+ - 输入:让模型自己 `git diff HEAD` 读已落盘变更(主线不重传)
281
329
  - 关注:安全性、性能、错误处理、逻辑正确性
282
330
 
283
- 2. **{{FRONTEND_PRIMARY}} 审查**(`run_in_background: true`):
284
- - ROLE_FILE: `~/.claude/.ccg/prompts/{{FRONTEND_PRIMARY}}/reviewer.md`
285
- - 输入:变更的 Diff + 目标文件
331
+ 2. **{{FRONTEND_PRIMARY}} 审查**(`{{GEMINI_BASH_TASK}} --no-write --prompt-file <tmpfile>`,Phase 3 有 gemini 实施会话时加 `--resume-last`,`run_in_background: true`):
332
+ - 角色:tmpfile 内写"角色定义见 `~/.claude/.ccg/prompts/{{FRONTEND_PRIMARY}}/reviewer.md`,先用 Read 工具读取再开始"
333
+ - 输入:让模型自己 `git diff HEAD` 读已落盘变更(主线不重传)
286
334
  - 关注:可访问性、设计一致性、用户体验
287
335
 
288
- `TaskOutput` 等待两个模型的完整审查结果。优先复用 Phase 3 的会话(`resume <SESSION_ID>`)以保持上下文一致。
336
+ 事件驱动等待两个模型的审查结果(task-notification 唤醒,**不调 TaskOutput**)。C5 增量:对 Phase 3 实施过的 vendor 用 `--resume-last` 接续其实施会话,只发"审计上面的实现",不重发计划上下文;无实施会话的另一侧走无状态审查。
289
337
 
290
338
  #### 5.2 整合修复
291
339
 
@@ -42,14 +42,14 @@ argument-hint: "<优化目标> [--role=architect|critic|implementer|tester|write
42
42
 
43
43
  ## 调用通道路由(CCG codeagent 退役)
44
44
 
45
- CCG 把双模型并行通道从 `Bash(codeagent-wrapper)` **默认切换**为 plugin spawn:
45
+ CCG 把双模型并行通道从 `Bash(codeagent-wrapper)` **默认切换**为 Bash 直调 plugin 快路径:
46
46
 
47
- 1. **优先 plugin spawn**(默认):装了 `codex@openai-codex` + gemini plugin(推荐 `gemini@gemini-ccgx` fork,含 P-1..P-21 + W1/W2/I1 patch;或上游 `gemini@google-gemini` 配 repatch 脚本)→ 用 `Agent(subagent_type="codex:codex-rescue")` + `Agent(subagent_type="gemini:gemini-rescue")` 并行,主线接 ≤200 token 摘要。
47
+ 1. **优先 Bash 直调 plugin 快路径**(默认):装了 `codex@openai-codex` + gemini plugin(推荐 `gemini@gemini-ccgx` fork,含 P-1..P-21 + W1/W2/I1 patch;或上游 `gemini@google-gemini` 配 repatch 脚本)→ 用 `{{CODEX_BASH_TASK}}` / `{{GEMINI_BASH_TASK}}` 占位符 + `--prompt-file` 并行 Bash 直调(review.md 同款),绕开 sonnet wrapper silent-fallback;**仅 `gemini-ccgx` fork 走 gemini-batch 29s 快路径,上游 + repatch 仍走 companion(ACP) 慢路径**(Windows 实测 5+min 卡死风险仍在),主线 `JSON.parse(stdout)` 取 `.text`。
48
48
  2. **降级 codeagent-wrapper**(BC fallback):plugin 未装 → fallback 到 Bash 调用,行为与 plugin 路径等价。
49
49
 
50
- **判定**:preflight `Bash` 跑 `node ~/.claude/.ccg/scripts/check-plugins.cjs`(解析 Claude Code 权威 `installed_plugins.json`)。exit `0` + stdout `{"codex":"<ver>","gemini":"<ver>"}` → 通道 A(plugin 默认);非 `0` → 通道 B(wrapper BC fallback)。
50
+ **判定**:preflight `Bash` 跑 `node ~/.claude/.ccg/scripts/check-plugins.cjs`(解析 Claude Code 权威 `installed_plugins.json`)。exit `0` + stdout `{"codex":"<ver>","gemini":"<ver>"}` → 通道 A(Bash 直调快路径,默认);非 `0` → 通道 B(wrapper BC fallback)。
51
51
 
52
- ⚠️ Optimize 命令在主线 context 内,**允许** `Agent(...)`——与 subagent "禁止嵌套 spawn" 约束不冲突。
52
+ ⚠️ Optimize 命令在主线 context 内执行,通道 A 走 Bash 直调(不再 spawn `Agent(...)`),无嵌套 spawn 顾虑。
53
53
 
54
54
  ---
55
55
 
@@ -62,28 +62,56 @@ CCG 把双模型并行通道从 `Bash(codeagent-wrapper)` **默认切换**为 pl
62
62
 
63
63
  **调用语法**(双通道):
64
64
 
65
- **通道 A — plugin spawn(默认)**:
65
+ **通道 A — Bash 直调 plugin 快路径(默认,绕开 sonnet wrapper + ACP 慢路径)**:
66
+
67
+ > 占位符 `{{CODEX_BASH_TASK}}` / `{{GEMINI_BASH_TASK}}` 由 install 时渲染为
68
+ > `node <ccgx-call-plugin.mjs 绝对路径> <vendor> --json`。LLM **只需把 prompt
69
+ > 写入 tmpfile、追加 `--prompt-file <tmpfile>`、运行**,不写 `Agent(...)`。
70
+ > 这条 Bash 直调通道自动吃到 gemini-batch 29s 快路径,消除 `Agent→gemini-companion→ACP`
71
+ > 的 5+min 卡死与 sonnet wrapper silent-fallback。
66
72
 
67
73
  ```
68
- Agent({
69
- subagent_type: "<codex:codex-rescue|gemini:gemini-rescue>",
70
- description: "Optimize: <backend|frontend>",
71
- prompt: `ROLE_FILE: <角色提示词路径>
74
+ Step 1. 用 Write 把任务描述写到 tmpfile(≤2KB,只放任务说明 + 角色提示词路径,不塞大段代码):
75
+ Write({ file_path: ".context/tmp/ccg-optimize-codex-$JOB.txt", content: <下方"任务描述模板"> })
76
+ Write({ 同上,gemini 版本,file_path: ".context/tmp/ccg-optimize-gemini-$JOB.txt" })
77
+
78
+ Step 2. 用 Bash 调 helper(占位符已渲染;本调用为纯分析只读,加 `--no-write`;并行两个在同一 message 内 run_in_background: true):
79
+ Bash({ command: `{{CODEX_BASH_TASK}} --no-write --prompt-file .context/tmp/ccg-optimize-codex-$JOB.txt`, description: "Optimize: backend (codex direct)", run_in_background: true })
80
+ Bash({ command: `{{GEMINI_BASH_TASK}} --no-write --prompt-file .context/tmp/ccg-optimize-gemini-$JOB.txt`, description: "Optimize: frontend (gemini direct)", run_in_background: true })
81
+
82
+ Step 3. 等 task-notification 后 Read 各自 stdout,`JSON.parse(stdout)` 取 helper 扁平化后的 `.text` 字段。
83
+ ```
84
+
85
+ **任务描述模板**(写到 tmpfile 的内容;保持 ≤2KB):
86
+
87
+ ```
88
+ # 任务:性能优化分析
89
+
90
+ 工作目录:<工作目录绝对路径>(你已在此,可直接用 Bash/Read)
91
+ 角色定义见 <角色提示词路径>(codex 用 ~/.claude/.ccg/prompts/{{BACKEND_PRIMARY}}/optimizer.md,gemini 用 {{FRONTEND_PRIMARY}}/optimizer.md),**先用 Read 工具读取该文件再开始**。
92
+
93
+ ## 你要做的事
72
94
 
73
- <TASK>
74
95
  需求:<增强后的需求(如未增强则用 $ARGUMENTS)>
75
- 上下文:<目标代码、现有性能指标等>
76
- </TASK>
96
+ 上下文:<目标代码路径 + 现有性能指标,不塞大段源码,让你自己 Read>
77
97
 
78
- OUTPUT: 性能瓶颈列表、优化方案、预期收益
79
- Return ≤200 token structured summary (plugin-native protocol).
80
- `
81
- })
98
+ - codex (backend):数据库、算法、缓存层瓶颈
99
+ - gemini (frontend):渲染、加载、交互(Core Web Vitals)
100
+
101
+ ## 硬约束
102
+
103
+ - **必须前台执行,禁止 `--background` / `--wait`**(ccgx 编排层已用 Agent run_in_background 包裹,插件内再 background = 双重后台,stop-gate / status / cancel 全盲)。
104
+ - 对文件系统零写入,仅分析。
105
+
106
+ ## 输出(JSON)
107
+
108
+ { "bottlenecks": [...], "fixes": [...], "expected_gain": "..." }
109
+ 只输出 JSON,无其他文本。
82
110
  ```
83
111
 
84
- 并行**两个 Agent 在同一 message 内同时 spawn**。
112
+ **严禁**:塞大段源码(撞 argv ~32KB 上限);写 `Agent(subagent_type="gemini:gemini-rescue")`(走 ACP 慢路径);heredoc / `-p "..."` 内联;硬编码 plugin 路径。**唯一允许**:copy 占位符 + 追加 `--prompt-file <tmpfile>`(纯分析只读流另加 `--no-write`)。
85
113
 
86
- **通道 B — codeagent-wrapper fallback**(plugin 未装时降级,并行用 `run_in_background: true`):
114
+ **通道 B — codeagent-wrapper fallback**(plugin 未装时降级,并行用 `run_in_background: true`;wrapper 的 `ROLE_FILE:` 由 `invoke-model.mjs` 解析故保留):
87
115
 
88
116
  ```
89
117
  Bash({
@@ -101,7 +129,7 @@ EOF",
101
129
  })
102
130
  ```
103
131
 
104
- > ⚠️ 通道 B `codeagent-wrapper` 已标 **deprecated**。
132
+ > ⚠️ 通道 B `codeagent-wrapper` 已标 **deprecated**,仅 plugin 未装时使用。
105
133
 
106
134
  **角色提示词**:
107
135
 
@@ -115,7 +143,7 @@ EOF",
115
143
  1. 同 message 内 spawn 多个 `Bash(run_in_background: true)` 并行任务
116
144
  2. spawn 完后主线说明已启动 task-id,**直接 turn end**,**不调 TaskOutput**
117
145
  3. Claude Code 引擎在每个 task 完成时自动发 `<task-notification>` system-reminder 触发主线新 turn
118
- 4. 主线在新 turn 处理:从 `<output-file>` 路径 read stdout,按通道 schema parse 结果
146
+ 4. 主线在新 turn 处理:从 `<output-file>` 路径 read stdout,`JSON.parse(stdout)` helper 扁平化后的 `.text`(通道 A)/ `--progress` 行(通道 B)
119
147
  5. **必须等所有相关 task 都收到通知**才进入下一阶段(按 task-id 计数已收齐)
120
148
 
121
149
  ⛔ **禁止**:
@@ -153,15 +181,15 @@ EOF",
153
181
 
154
182
  `[模式:分析]`
155
183
 
156
- **⚠️ 必须发起两个并行 Bash 调用**(参照上方调用规范):
184
+ **⚠️ 必须发起两个并行 Bash 直调 helper 调用**(参照上方调用规范,先 Write tmpfile 再 `{{CODEX_BASH_TASK}}` / `{{GEMINI_BASH_TASK}}` + `--prompt-file`):
157
185
 
158
- 1. **{{BACKEND_PRIMARY}} 后端分析**:`Bash({ command: "...--backend {{BACKEND_PRIMARY}}...", run_in_background: true })`
159
- - ROLE_FILE: `~/.claude/.ccg/prompts/{{BACKEND_PRIMARY}}/optimizer.md`
186
+ 1. **{{BACKEND_PRIMARY}} 后端分析**:`{{CODEX_BASH_TASK}} --prompt-file <tmpfile>`(`run_in_background: true`)
187
+ - 角色:tmpfile 内写"角色定义见 `~/.claude/.ccg/prompts/{{BACKEND_PRIMARY}}/optimizer.md`,先用 Read 工具读取再开始"
160
188
  - 需求:分析后端性能问题($ARGUMENTS)
161
189
  - OUTPUT:性能瓶颈列表、优化方案、预期收益
162
190
 
163
- 2. **{{FRONTEND_PRIMARY}} 前端分析**:`Bash({ command: "...--backend {{FRONTEND_PRIMARY}}...", run_in_background: true })`
164
- - ROLE_FILE: `~/.claude/.ccg/prompts/{{FRONTEND_PRIMARY}}/optimizer.md`
191
+ 2. **{{FRONTEND_PRIMARY}} 前端分析**:`{{GEMINI_BASH_TASK}} --prompt-file <tmpfile>`(`run_in_background: true`)
192
+ - 角色:tmpfile 内写"角色定义见 `~/.claude/.ccg/prompts/{{FRONTEND_PRIMARY}}/optimizer.md`,先用 Read 工具读取再开始"
165
193
  - 需求:分析前端性能问题(Core Web Vitals)
166
194
  - OUTPUT:性能瓶颈列表、优化方案、预期收益
167
195