cc-devflow 4.5.10 → 4.5.12

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 (187) hide show
  1. package/.claude/skills/cc-act/CHANGELOG.md +23 -0
  2. package/.claude/skills/cc-act/PLAYBOOK.md +17 -269
  3. package/.claude/skills/cc-act/SKILL.md +38 -418
  4. package/.claude/skills/cc-act/assets/PROJECT_POSTMORTEM_INDEX_TEMPLATE.md +2 -13
  5. package/.claude/skills/cc-act/assets/PROJECT_POSTMORTEM_TEMPLATE.md +1 -9
  6. package/.claude/skills/cc-act/assets/PR_BRIEF_TEMPLATE.md +21 -177
  7. package/.claude/skills/cc-act/references/closure-contract.md +12 -63
  8. package/.claude/skills/cc-act/references/git-commit-guidelines.md +5 -5
  9. package/.claude/skills/cc-act/scripts/cc-act-common.sh +5 -322
  10. package/.claude/skills/cc-act/scripts/detect-ship-target.sh +11 -2
  11. package/.claude/skills/cc-act/scripts/inspect-git-index.sh +58 -0
  12. package/.claude/skills/cc-act/scripts/render-pr-brief.sh +40 -440
  13. package/.claude/skills/cc-act/scripts/verify-act-gate.sh +10 -50
  14. package/.claude/skills/cc-check/CHANGELOG.md +24 -0
  15. package/.claude/skills/cc-check/PLAYBOOK.md +19 -273
  16. package/.claude/skills/cc-check/SKILL.md +33 -454
  17. package/.claude/skills/cc-check/references/review-contract.md +12 -147
  18. package/.claude/skills/cc-dev/CHANGELOG.md +20 -0
  19. package/.claude/skills/cc-dev/PLAYBOOK.md +1 -1
  20. package/.claude/skills/cc-dev/SKILL.md +52 -130
  21. package/.claude/skills/cc-dev/scripts/resolve-cc-devflow.sh +181 -0
  22. package/.claude/skills/cc-do/CHANGELOG.md +17 -0
  23. package/.claude/skills/cc-do/PLAYBOOK.md +19 -113
  24. package/.claude/skills/cc-do/SKILL.md +39 -236
  25. package/.claude/skills/cc-do/references/execution-recovery.md +15 -109
  26. package/.claude/skills/cc-do/scripts/cc-do-common.sh +5 -57
  27. package/.claude/skills/cc-do/scripts/check-task-status.sh +35 -65
  28. package/.claude/skills/cc-do/scripts/mark-task-complete.sh +9 -46
  29. package/.claude/skills/cc-do/scripts/select-ready-tasks.sh +29 -97
  30. package/.claude/skills/cc-investigate/CHANGELOG.md +23 -0
  31. package/.claude/skills/cc-investigate/PLAYBOOK.md +20 -180
  32. package/.claude/skills/cc-investigate/SKILL.md +65 -513
  33. package/.claude/skills/cc-investigate/assets/TASKS_TEMPLATE.md +48 -95
  34. package/.claude/skills/cc-investigate/references/investigation-contract.md +14 -217
  35. package/.claude/skills/cc-next/CHANGELOG.md +6 -0
  36. package/.claude/skills/cc-next/PLAYBOOK.md +12 -8
  37. package/.claude/skills/cc-next/SKILL.md +34 -140
  38. package/.claude/skills/cc-plan/CHANGELOG.md +29 -0
  39. package/.claude/skills/cc-plan/PLAYBOOK.md +22 -161
  40. package/.claude/skills/cc-plan/SKILL.md +47 -640
  41. package/.claude/skills/cc-plan/assets/TASKS_TEMPLATE.md +30 -225
  42. package/.claude/skills/cc-plan/references/planning-contract.md +24 -160
  43. package/.claude/skills/cc-plan/scripts/next-change-key.sh +8 -44
  44. package/.claude/skills/cc-plan/scripts/parse-task-dependencies.js +2 -2
  45. package/.claude/skills/cc-plan/scripts/validate-scope.sh +1 -1
  46. package/.claude/skills/cc-pr-land/SKILL.md +14 -114
  47. package/.claude/skills/cc-pr-review/CHANGELOG.md +4 -0
  48. package/.claude/skills/cc-pr-review/SKILL.md +20 -103
  49. package/.claude/skills/cc-review/CHANGELOG.md +17 -0
  50. package/.claude/skills/cc-review/PLAYBOOK.md +13 -86
  51. package/.claude/skills/cc-review/SKILL.md +53 -241
  52. package/.claude/skills/cc-review/references/e2e-and-plugin-verification.md +2 -2
  53. package/.claude/skills/cc-review/references/implementation-review-branch.md +7 -147
  54. package/.claude/skills/cc-review/references/plan-review-branch.md +5 -147
  55. package/.claude/skills/cc-review/references/review-methods.md +10 -218
  56. package/.claude/skills/cc-review/scripts/collect-review-context.sh +4 -63
  57. package/.claude/skills/cc-roadmap/PLAYBOOK.md +1 -1
  58. package/.claude/skills/cc-roadmap/SKILL.md +3 -3
  59. package/.claude/skills/cc-simplify/CHANGELOG.md +7 -0
  60. package/.claude/skills/cc-simplify/SKILL.md +26 -21
  61. package/.claude/skills/cc-spec-init/PLAYBOOK.md +12 -48
  62. package/.claude/skills/cc-spec-init/SKILL.md +29 -132
  63. package/.claude/skills/cc-spec-init/references/spec-contract.md +8 -17
  64. package/CHANGELOG.md +27 -0
  65. package/README.md +5 -3
  66. package/README.zh-CN.md +5 -3
  67. package/bin/cc-devflow-cli.js +20 -260
  68. package/bin/cc-devflow.js +44 -7
  69. package/docs/commands/README.md +1 -1
  70. package/docs/commands/README.zh-CN.md +1 -1
  71. package/docs/examples/README.md +1 -1
  72. package/docs/examples/START-HERE.md +14 -14
  73. package/docs/examples/example-bindings.json +11 -11
  74. package/docs/examples/full-design-blocked/README.md +4 -6
  75. package/docs/examples/full-design-blocked/changes/REQ-002-bulk-invite-import/{planning/tasks.md → task.md} +20 -15
  76. package/docs/examples/local-handoff/README.md +8 -11
  77. package/docs/examples/local-handoff/changes/REQ-003-audit-log-export/handoff/pr-brief.md +31 -0
  78. package/docs/examples/local-handoff/changes/REQ-003-audit-log-export/{planning/tasks.md → task.md} +18 -13
  79. package/docs/examples/pdca-loop/README.md +6 -9
  80. package/docs/examples/pdca-loop/changes/REQ-001-copy-invite-link/handoff/pr-brief.md +9 -11
  81. package/docs/examples/pdca-loop/changes/REQ-001-copy-invite-link/{planning/tasks.md → task.md} +18 -13
  82. package/docs/examples/scripts/check-example-bindings.sh +11 -62
  83. package/docs/guides/artifact-contract.md +10 -36
  84. package/docs/guides/getting-started.md +8 -7
  85. package/docs/guides/getting-started.zh-CN.md +8 -7
  86. package/docs/guides/minimize-artifacts.md +16 -116
  87. package/docs/guides/project-postmortem.md +14 -71
  88. package/lib/compiler/__tests__/skills-registry.test.js +9 -8
  89. package/lib/compiler/resource-copier.js +29 -0
  90. package/lib/skill-runtime/__tests__/archive-change.test.js +2 -2
  91. package/lib/skill-runtime/__tests__/benchmark-skills.test.js +109 -0
  92. package/lib/skill-runtime/__tests__/cli-bootstrap.integration.test.js +14 -4
  93. package/lib/skill-runtime/errors.js +3 -3
  94. package/lib/skill-runtime/index.js +5 -23
  95. package/lib/skill-runtime/paths.js +5 -52
  96. package/lib/skill-runtime/query-registry.js +4 -4
  97. package/lib/skill-runtime/query.js +89 -201
  98. package/lib/skill-runtime/store.js +4 -40
  99. package/lib/skill-runtime/trace.js +2 -2
  100. package/package.json +5 -7
  101. package/.claude/skills/cc-act/assets/PROJECT_POSTMORTEM_PRINCIPLES_TEMPLATE.md +0 -29
  102. package/.claude/skills/cc-act/assets/RELEASE_NOTE_TEMPLATE.md +0 -54
  103. package/.claude/skills/cc-act/scripts/generate-status-report.sh +0 -92
  104. package/.claude/skills/cc-act/scripts/sync-act-docs.sh +0 -355
  105. package/.claude/skills/cc-check/assets/REPORT_CARD_TEMPLATE.json +0 -234
  106. package/.claude/skills/cc-check/scripts/render-report-card.js +0 -438
  107. package/.claude/skills/cc-check/scripts/verify-gate.sh +0 -85
  108. package/.claude/skills/cc-do/scripts/build-task-context.sh +0 -175
  109. package/.claude/skills/cc-do/scripts/record-review-decision.sh +0 -88
  110. package/.claude/skills/cc-do/scripts/recover-workflow.sh +0 -82
  111. package/.claude/skills/cc-do/scripts/run-problem-analysis.sh +0 -70
  112. package/.claude/skills/cc-do/scripts/verify-task-gates.sh +0 -109
  113. package/.claude/skills/cc-do/scripts/write-task-checkpoint.sh +0 -92
  114. package/.claude/skills/cc-investigate/assets/TASK_MANIFEST_TEMPLATE.json +0 -225
  115. package/.claude/skills/cc-plan/assets/TASK_MANIFEST_TEMPLATE.json +0 -179
  116. package/.claude/skills/cc-spec-init/assets/CHANGE_META_TEMPLATE.json +0 -28
  117. package/.claude/skills/cc-spec-init/scripts/validate-spec-links.sh +0 -45
  118. package/docs/examples/full-design-blocked/changes/REQ-002-bulk-invite-import/planning/design.md +0 -234
  119. package/docs/examples/full-design-blocked/changes/REQ-002-bulk-invite-import/planning/task-manifest.json +0 -488
  120. package/docs/examples/full-design-blocked/changes/REQ-002-bulk-invite-import/review/report-card.json +0 -189
  121. package/docs/examples/local-handoff/changes/REQ-003-audit-log-export/handoff/resume-index.md +0 -39
  122. package/docs/examples/local-handoff/changes/REQ-003-audit-log-export/handoff/status.md +0 -29
  123. package/docs/examples/local-handoff/changes/REQ-003-audit-log-export/planning/design.md +0 -123
  124. package/docs/examples/local-handoff/changes/REQ-003-audit-log-export/planning/task-manifest.json +0 -292
  125. package/docs/examples/local-handoff/changes/REQ-003-audit-log-export/review/report-card.json +0 -136
  126. package/docs/examples/pdca-loop/changes/REQ-001-copy-invite-link/handoff/status.md +0 -29
  127. package/docs/examples/pdca-loop/changes/REQ-001-copy-invite-link/planning/design.md +0 -124
  128. package/docs/examples/pdca-loop/changes/REQ-001-copy-invite-link/planning/task-manifest.json +0 -292
  129. package/docs/examples/pdca-loop/changes/REQ-001-copy-invite-link/review/report-card.json +0 -136
  130. package/docs/get-shit-done-strategy-audit.md +0 -518
  131. package/docs/skill-runtime-migration.md +0 -46
  132. package/lib/skill-runtime/__tests__/approve.test.js +0 -92
  133. package/lib/skill-runtime/__tests__/autopilot.test.js +0 -253
  134. package/lib/skill-runtime/__tests__/benchmark-artifacts.test.js +0 -165
  135. package/lib/skill-runtime/__tests__/delegation.test.js +0 -97
  136. package/lib/skill-runtime/__tests__/dispatch.test.js +0 -237
  137. package/lib/skill-runtime/__tests__/intent.test.js +0 -203
  138. package/lib/skill-runtime/__tests__/lifecycle.test.js +0 -169
  139. package/lib/skill-runtime/__tests__/planner.tdd.test.js +0 -331
  140. package/lib/skill-runtime/__tests__/prepare-pr.test.js +0 -126
  141. package/lib/skill-runtime/__tests__/query.test.js +0 -860
  142. package/lib/skill-runtime/__tests__/readiness.test.js +0 -53
  143. package/lib/skill-runtime/__tests__/release.test.js +0 -85
  144. package/lib/skill-runtime/__tests__/review-check-integration.test.js +0 -148
  145. package/lib/skill-runtime/__tests__/review-records.test.js +0 -619
  146. package/lib/skill-runtime/__tests__/runtime.integration.test.js +0 -351
  147. package/lib/skill-runtime/__tests__/schemas.test.js +0 -337
  148. package/lib/skill-runtime/__tests__/task-contract-migrate.test.js +0 -137
  149. package/lib/skill-runtime/__tests__/task-contract.test.js +0 -783
  150. package/lib/skill-runtime/__tests__/team-state.test.js +0 -51
  151. package/lib/skill-runtime/__tests__/verify-artifacts.test.js +0 -203
  152. package/lib/skill-runtime/__tests__/worker-run.test.js +0 -275
  153. package/lib/skill-runtime/__tests__/worker.test.js +0 -56
  154. package/lib/skill-runtime/__tests__/workflow-context-legacy-fallback.test.js +0 -31
  155. package/lib/skill-runtime/__tests__/workflow-context.test.js +0 -98
  156. package/lib/skill-runtime/artifacts.js +0 -88
  157. package/lib/skill-runtime/context-index.js +0 -545
  158. package/lib/skill-runtime/delegation.js +0 -533
  159. package/lib/skill-runtime/intent.js +0 -309
  160. package/lib/skill-runtime/lifecycle.js +0 -294
  161. package/lib/skill-runtime/operations/CLAUDE.md +0 -19
  162. package/lib/skill-runtime/operations/approve.js +0 -81
  163. package/lib/skill-runtime/operations/autopilot-core.js +0 -337
  164. package/lib/skill-runtime/operations/autopilot-execution.js +0 -307
  165. package/lib/skill-runtime/operations/autopilot-shared.js +0 -48
  166. package/lib/skill-runtime/operations/autopilot.js +0 -163
  167. package/lib/skill-runtime/operations/dispatch.js +0 -416
  168. package/lib/skill-runtime/operations/init.js +0 -60
  169. package/lib/skill-runtime/operations/janitor.js +0 -61
  170. package/lib/skill-runtime/operations/plan.js +0 -59
  171. package/lib/skill-runtime/operations/prepare-pr.js +0 -25
  172. package/lib/skill-runtime/operations/release.js +0 -99
  173. package/lib/skill-runtime/operations/resume.js +0 -126
  174. package/lib/skill-runtime/operations/review-records.js +0 -265
  175. package/lib/skill-runtime/operations/snapshot.js +0 -45
  176. package/lib/skill-runtime/operations/task-contract.js +0 -524
  177. package/lib/skill-runtime/operations/verify.js +0 -170
  178. package/lib/skill-runtime/operations/worker-run.js +0 -531
  179. package/lib/skill-runtime/operations/worker.js +0 -33
  180. package/lib/skill-runtime/planner.js +0 -539
  181. package/lib/skill-runtime/readiness.js +0 -84
  182. package/lib/skill-runtime/review-records.js +0 -123
  183. package/lib/skill-runtime/review.js +0 -855
  184. package/lib/skill-runtime/schemas.js +0 -746
  185. package/lib/skill-runtime/task-contract.js +0 -187
  186. package/lib/skill-runtime/team-state.js +0 -122
  187. package/lib/skill-runtime/workflow-context.js +0 -748
@@ -1,337 +0,0 @@
1
- /**
2
- * [INPUT]: 依赖 store/intent/delegation 与 discover/converge/delegate/verify/release 原语,接收阶段上下文。
3
- * [OUTPUT]: 对外提供 autopilot 的阶段判定、approval gate、state 读取与非执行类 stage runner。
4
- * [POS]: autopilot 的核心生命周期层,负责阶段顺序、记忆写点与 finish 收尾,而不处理具体执行循环。
5
- * [PROTOCOL]: 变更时更新此头部,然后检查 CLAUDE.md
6
- */
7
-
8
- const { getIntentPrBriefPath } = require('../artifacts');
9
- const { syncIntentMemory } = require('../intent');
10
- const { syncDelegationRuntime } = require('../delegation');
11
- const { isTaskSettledStatus } = require('../lifecycle');
12
- const { runInit } = require('./init');
13
- const { runPlanningSnapshot } = require('./snapshot');
14
- const { runPlan } = require('./plan');
15
- const { runPreparePr } = require('./prepare-pr');
16
- const { runVerify } = require('./verify');
17
- const { runRelease } = require('./release');
18
- const {
19
- normalizeStage,
20
- stageIndex,
21
- hasUnresolvedTasks,
22
- loadState,
23
- getApprovalState
24
- } = require('./autopilot-shared');
25
-
26
- function allTasksSettled(manifest) {
27
- if (!manifest) {
28
- return false;
29
- }
30
-
31
- return manifest.tasks.every((task) => isTaskSettledStatus(task.status));
32
- }
33
-
34
- function shouldRunVerify(from, snapshot) {
35
- if (!snapshot.manifest || !allTasksSettled(snapshot.manifest)) {
36
- return false;
37
- }
38
-
39
- return (
40
- !snapshot.report ||
41
- snapshot.report.overall === 'fail' ||
42
- normalizeStage(from) === 'verify' ||
43
- normalizeStage(from) === 'document' ||
44
- normalizeStage(from) === 'prepare-pr'
45
- );
46
- }
47
-
48
- function resolveCompletedStage(snapshot) {
49
- if (snapshot.state?.status === 'released') {
50
- return 'release';
51
- }
52
-
53
- const approval = getApprovalState(snapshot.state, snapshot.manifest);
54
-
55
- if (snapshot.report?.overall === 'pass') {
56
- return 'prepare-pr';
57
- }
58
-
59
- if (snapshot.manifest && approval.status !== 'approved') {
60
- return 'approve';
61
- }
62
-
63
- if (snapshot.manifest && hasUnresolvedTasks(snapshot.manifest)) {
64
- return 'execute';
65
- }
66
-
67
- return snapshot.manifest ? 'verify' : 'converge';
68
- }
69
-
70
- async function runVerificationStage({
71
- repoRoot,
72
- changeId,
73
- from,
74
- strict,
75
- skipReview,
76
- executed,
77
- snapshot
78
- }) {
79
- if (!shouldRunVerify(from, snapshot)) {
80
- return snapshot;
81
- }
82
-
83
- const result = await runVerify({
84
- repoRoot,
85
- changeId,
86
- strict,
87
- skipReview
88
- });
89
- executed.push('verify');
90
-
91
- await syncIntentMemory(repoRoot, changeId, {
92
- event: result.overall === 'pass' ? 'autopilot_verify_passed' : 'autopilot_verify_failed',
93
- reason: result.overall === 'pass' ? 'Verification passed' : 'Verification produced blocking findings'
94
- });
95
-
96
- return loadState(repoRoot, changeId);
97
- }
98
-
99
- async function runPreparePrStage({
100
- repoRoot,
101
- changeId,
102
- fromIndex,
103
- executed,
104
- snapshot
105
- }) {
106
- if (fromIndex > stageIndex('prepare-pr') || snapshot.report?.overall !== 'pass') {
107
- return {
108
- snapshot,
109
- prBriefPath: snapshot.report?.overall === 'pass' ? getIntentPrBriefPath(repoRoot, changeId) : null
110
- };
111
- }
112
-
113
- const prepared = await runPreparePr({ repoRoot, changeId });
114
- executed.push('prepare-pr');
115
-
116
- return {
117
- snapshot: await loadState(repoRoot, changeId),
118
- prBriefPath: prepared.prBriefPath
119
- };
120
- }
121
-
122
- async function runReleaseStage({
123
- repoRoot,
124
- changeId,
125
- release,
126
- executed,
127
- snapshot
128
- }) {
129
- if (!release || snapshot.report?.overall !== 'pass') {
130
- return snapshot;
131
- }
132
-
133
- await runRelease({ repoRoot, changeId });
134
- executed.push('release');
135
-
136
- await syncIntentMemory(repoRoot, changeId, {
137
- event: 'autopilot_release_completed',
138
- reason: 'Release stage completed after successful verification'
139
- });
140
-
141
- return loadState(repoRoot, changeId);
142
- }
143
-
144
- async function runDiscoverStage({
145
- repoRoot,
146
- changeId,
147
- goal,
148
- fromIndex,
149
- executed,
150
- snapshot
151
- }) {
152
- if (fromIndex > stageIndex('discover') && snapshot.state) {
153
- return snapshot;
154
- }
155
-
156
- if (!snapshot.state) {
157
- await runInit({ repoRoot, changeId, goal });
158
- executed.push('init');
159
- }
160
-
161
- await runPlanningSnapshot({ repoRoot, changeId, goal });
162
- executed.push('snapshot');
163
-
164
- await syncIntentMemory(repoRoot, changeId, {
165
- event: 'autopilot_discover_completed',
166
- reason: 'Requirement state and planning snapshot are ready'
167
- });
168
-
169
- return loadState(repoRoot, changeId);
170
- }
171
-
172
- async function runConvergeStage({
173
- repoRoot,
174
- changeId,
175
- goal,
176
- fromIndex,
177
- overwrite,
178
- executed,
179
- snapshot
180
- }) {
181
- if (fromIndex > stageIndex('converge') && snapshot.manifest && !overwrite) {
182
- return snapshot;
183
- }
184
-
185
- const plannedFresh = !snapshot.manifest || overwrite;
186
- if (!snapshot.manifest || overwrite) {
187
- await runPlan({ repoRoot, changeId, goal, overwrite });
188
- executed.push('plan');
189
- }
190
-
191
- await syncIntentMemory(repoRoot, changeId, {
192
- event: 'autopilot_converge_completed',
193
- reason: plannedFresh ? 'Execution plan is ready and waiting for approval' : 'Plan already existed and was reused'
194
- });
195
-
196
- return loadState(repoRoot, changeId);
197
- }
198
-
199
- async function runApprovalStage({
200
- repoRoot,
201
- changeId,
202
- fromIndex,
203
- executed,
204
- snapshot
205
- }) {
206
- if (!snapshot.manifest) {
207
- return {
208
- snapshot,
209
- shouldStop: false
210
- };
211
- }
212
-
213
- const approval = getApprovalState(snapshot.state, snapshot.manifest);
214
- if (approval.status !== 'approved') {
215
- await syncIntentMemory(repoRoot, changeId, {
216
- event: 'autopilot_awaiting_approval',
217
- reason: `Plan version ${approval.planVersion || 1} is waiting for explicit approval before execute`
218
- });
219
-
220
- return {
221
- snapshot: await loadState(repoRoot, changeId),
222
- shouldStop: true
223
- };
224
- }
225
-
226
- if (fromIndex <= stageIndex('approve')) {
227
- executed.push('approve');
228
- }
229
-
230
- await syncIntentMemory(repoRoot, changeId, {
231
- event: 'autopilot_approval_confirmed',
232
- reason: `Plan version ${approval.planVersion || 1} approved for ${approval.executionMode} execution`
233
- });
234
-
235
- return {
236
- snapshot: await loadState(repoRoot, changeId),
237
- shouldStop: false
238
- };
239
- }
240
-
241
- async function runDelegateStage({
242
- repoRoot,
243
- changeId,
244
- fromIndex,
245
- executed,
246
- snapshot
247
- }) {
248
- if (fromIndex > stageIndex('delegate')) {
249
- return snapshot;
250
- }
251
-
252
- const approval = getApprovalState(snapshot.state, snapshot.manifest);
253
- if (approval.status !== 'approved') {
254
- return snapshot;
255
- }
256
-
257
- let delegationSummary = null;
258
- if (snapshot.manifest && approval.executionMode !== 'direct') {
259
- delegationSummary = await syncDelegationRuntime(repoRoot, changeId, snapshot.manifest, snapshot.state);
260
- }
261
-
262
- if (delegationSummary && delegationSummary.delegatedCount > 0) {
263
- executed.push('delegate');
264
- }
265
-
266
- await syncIntentMemory(repoRoot, changeId, {
267
- event: 'autopilot_delegate_completed',
268
- reason: approval.executionMode === 'direct'
269
- ? 'Approved plan stays in direct mode, so delegation runtime was skipped'
270
- : delegationSummary && delegationSummary.delegatedCount > 0
271
- ? `Prepared ${delegationSummary.delegatedCount} delegated assignment(s) for local execution`
272
- : 'Current plan stays on direct execution'
273
- });
274
-
275
- return loadState(repoRoot, changeId);
276
- }
277
-
278
- async function runFinishStages({
279
- repoRoot,
280
- changeId,
281
- from,
282
- fromIndex,
283
- strict,
284
- skipReview,
285
- release,
286
- executed,
287
- snapshot
288
- }) {
289
- let nextSnapshot = snapshot;
290
-
291
- if (fromIndex <= stageIndex('verify')) {
292
- nextSnapshot = await runVerificationStage({
293
- repoRoot,
294
- changeId,
295
- from,
296
- strict,
297
- skipReview,
298
- executed,
299
- snapshot: nextSnapshot
300
- });
301
- }
302
-
303
- const preparePrResult = await runPreparePrStage({
304
- repoRoot,
305
- changeId,
306
- fromIndex,
307
- executed,
308
- snapshot: nextSnapshot
309
- });
310
- nextSnapshot = preparePrResult.snapshot;
311
-
312
- nextSnapshot = await runReleaseStage({
313
- repoRoot,
314
- changeId,
315
- release,
316
- executed,
317
- snapshot: nextSnapshot
318
- });
319
-
320
- return {
321
- snapshot: nextSnapshot,
322
- prBriefPath: preparePrResult.prBriefPath
323
- };
324
- }
325
-
326
- module.exports = {
327
- normalizeStage,
328
- stageIndex,
329
- hasUnresolvedTasks,
330
- loadState,
331
- resolveCompletedStage,
332
- runDiscoverStage,
333
- runConvergeStage,
334
- runApprovalStage,
335
- runDelegateStage,
336
- runFinishStages
337
- };
@@ -1,307 +0,0 @@
1
- /**
2
- * [INPUT]: 依赖 store/intent/delegation 与 dispatch/resume/worker-run,接收执行阶段上下文与 worker 配置。
3
- * [OUTPUT]: 对外提供 autopilot 的执行阶段工具与 runner,返回更新后的 snapshot 与 executed。
4
- * [POS]: autopilot 的执行层,负责 direct/controller 与 delegated worker 的混合执行循环。
5
- * [PROTOCOL]: 变更时更新此头部,然后检查 CLAUDE.md
6
- */
7
-
8
- const {
9
- readJson,
10
- writeJson,
11
- getTaskManifestPath
12
- } = require('../store');
13
- const { applyManifestExecutionState } = require('../planner');
14
- const {
15
- syncIntentMemory
16
- } = require('../intent');
17
- const { findAssignment } = require('../delegation');
18
- const { runDispatch } = require('./dispatch');
19
- const { runResume } = require('./resume');
20
- const { runWorkerCommand } = require('./worker-run');
21
- const { classifyDelegationMode } = require('../lifecycle');
22
- const {
23
- stageIndex,
24
- hasUnresolvedTasks,
25
- loadState,
26
- isExecutionApproved
27
- } = require('./autopilot-shared');
28
-
29
- function hasDirectUnresolvedTasks(manifest, state = {}) {
30
- if (!manifest) {
31
- return false;
32
- }
33
-
34
- return manifest.tasks.some((task) =>
35
- classifyDelegationMode(task, state) === 'direct' &&
36
- ['pending', 'running', 'failed'].includes(task.status)
37
- );
38
- }
39
-
40
- function dependenciesPassed(task, taskMap) {
41
- return task.dependsOn.every((depId) => {
42
- const dep = taskMap.get(depId);
43
- return dep && dep.status === 'passed';
44
- });
45
- }
46
-
47
- function usesWorkerPool(workerProvider, workerCommand) {
48
- return Boolean(workerProvider || workerCommand);
49
- }
50
-
51
- function shouldResumeTasks(manifest, executionScope = 'all', state = {}) {
52
- if (!manifest) {
53
- return false;
54
- }
55
-
56
- return manifest.tasks.some((task) => {
57
- if (executionScope === 'direct' && classifyDelegationMode(task, state) !== 'direct') {
58
- return false;
59
- }
60
-
61
- return task.status === 'failed' || task.status === 'running';
62
- });
63
- }
64
-
65
- async function requeueDelegatedTasksForResume(repoRoot, changeId, state = {}) {
66
- const manifestPath = getTaskManifestPath(repoRoot, changeId);
67
- const manifest = await readJson(manifestPath, null);
68
- if (!manifest) {
69
- return 0;
70
- }
71
-
72
- let updated = 0;
73
- for (const task of manifest.tasks) {
74
- if (classifyDelegationMode(task, state) === 'direct') {
75
- continue;
76
- }
77
-
78
- if (task.status === 'running' || task.status === 'failed') {
79
- task.status = 'pending';
80
- updated += 1;
81
- }
82
- }
83
-
84
- if (updated > 0) {
85
- applyManifestExecutionState(manifest, new Date().toISOString());
86
- await writeJson(manifestPath, manifest);
87
- }
88
-
89
- return updated;
90
- }
91
-
92
- async function runDelegatedAutopilotWorkers({
93
- repoRoot,
94
- changeId,
95
- state,
96
- workerProvider,
97
- workerProviderArgs,
98
- workerCommand
99
- }) {
100
- const manifest = await readJson(getTaskManifestPath(repoRoot, changeId), null);
101
- if (!manifest) {
102
- return { executedCount: 0 };
103
- }
104
-
105
- const taskMap = new Map(manifest.tasks.map((task) => [task.id, task]));
106
- const readyDelegatedTasks = manifest.tasks.filter((task) =>
107
- classifyDelegationMode(task, state || {}) !== 'direct' &&
108
- task.status === 'pending' &&
109
- dependenciesPassed(task, taskMap)
110
- );
111
-
112
- let executedCount = 0;
113
-
114
- for (const task of readyDelegatedTasks) {
115
- const assignment = await findAssignment(repoRoot, changeId, task.id);
116
- if (!assignment) {
117
- continue;
118
- }
119
-
120
- await runWorkerCommand({
121
- repoRoot,
122
- changeId,
123
- workerId: assignment.workerId,
124
- taskId: task.id,
125
- provider: workerProvider,
126
- providerArgs: workerProviderArgs,
127
- command: workerCommand
128
- });
129
- executedCount += 1;
130
- }
131
-
132
- return { executedCount };
133
- }
134
-
135
- async function runControllerExecutionPass({
136
- repoRoot,
137
- changeId,
138
- manifest,
139
- parallel,
140
- maxRetries,
141
- resume,
142
- state,
143
- executionScope = 'all'
144
- }) {
145
- const shouldResume = resume || shouldResumeTasks(manifest, executionScope, state);
146
- const command = shouldResume ? 'resume' : 'dispatch';
147
- const runnerArgs = {
148
- repoRoot,
149
- changeId,
150
- parallel,
151
- maxRetries
152
- };
153
-
154
- if (executionScope === 'direct') {
155
- runnerArgs.executionScope = 'direct';
156
- }
157
-
158
- const result = shouldResume
159
- ? await runResume(runnerArgs)
160
- : await runDispatch(runnerArgs);
161
-
162
- await syncIntentMemory(repoRoot, changeId, {
163
- event: shouldResume ? 'autopilot_resume_completed' : 'autopilot_execute_completed',
164
- reason: result.success
165
- ? (executionScope === 'direct'
166
- ? 'Controller execution completed current direct frontier'
167
- : 'Execution stage completed without unresolved tasks')
168
- : result.reason || 'Execution stopped with unresolved tasks'
169
- });
170
-
171
- return {
172
- command,
173
- snapshot: await loadState(repoRoot, changeId)
174
- };
175
- }
176
-
177
- async function runHybridExecutionStage({
178
- repoRoot,
179
- changeId,
180
- snapshot,
181
- executed,
182
- parallel,
183
- maxRetries,
184
- resume,
185
- workerProvider,
186
- workerProviderArgs,
187
- workerCommand
188
- }) {
189
- let nextSnapshot = snapshot;
190
- let workerResumeApplied = !resume;
191
- let executedWorkerPool = false;
192
-
193
- while (nextSnapshot.manifest && hasUnresolvedTasks(nextSnapshot.manifest)) {
194
- let progressed = false;
195
-
196
- if (!workerResumeApplied) {
197
- const requeued = await requeueDelegatedTasksForResume(repoRoot, changeId, nextSnapshot.state);
198
- workerResumeApplied = true;
199
-
200
- if (requeued > 0) {
201
- progressed = true;
202
- nextSnapshot = await loadState(repoRoot, changeId);
203
- }
204
- }
205
-
206
- const workerResult = await runDelegatedAutopilotWorkers({
207
- repoRoot,
208
- changeId,
209
- state: nextSnapshot.state,
210
- workerProvider,
211
- workerProviderArgs,
212
- workerCommand
213
- });
214
-
215
- if (workerResult.executedCount > 0) {
216
- executedWorkerPool = true;
217
- progressed = true;
218
- nextSnapshot = await loadState(repoRoot, changeId);
219
- }
220
-
221
- if (nextSnapshot.manifest && hasDirectUnresolvedTasks(nextSnapshot.manifest, nextSnapshot.state)) {
222
- const controllerPass = await runControllerExecutionPass({
223
- repoRoot,
224
- changeId,
225
- manifest: nextSnapshot.manifest,
226
- parallel,
227
- maxRetries,
228
- resume,
229
- state: nextSnapshot.state,
230
- executionScope: 'direct'
231
- });
232
-
233
- executed.push(controllerPass.command);
234
- nextSnapshot = controllerPass.snapshot;
235
- progressed = true;
236
- }
237
-
238
- if (!progressed) {
239
- break;
240
- }
241
- }
242
-
243
- if (executedWorkerPool) {
244
- executed.push('worker-run');
245
- await syncIntentMemory(repoRoot, changeId, {
246
- event: 'autopilot_worker_pool_completed',
247
- reason: `Delegated worker pool executed via ${workerProvider || 'custom-command'}`
248
- });
249
- nextSnapshot = await loadState(repoRoot, changeId);
250
- }
251
-
252
- return nextSnapshot;
253
- }
254
-
255
- async function runExecutionStage({
256
- repoRoot,
257
- changeId,
258
- fromIndex,
259
- snapshot,
260
- executed,
261
- parallel,
262
- maxRetries,
263
- resume,
264
- workerProvider,
265
- workerProviderArgs,
266
- workerCommand
267
- }) {
268
- if (fromIndex > stageIndex('execute') || !snapshot.manifest || !hasUnresolvedTasks(snapshot.manifest)) {
269
- return snapshot;
270
- }
271
-
272
- if (!isExecutionApproved(snapshot.state, snapshot.manifest)) {
273
- return snapshot;
274
- }
275
-
276
- if (usesWorkerPool(workerProvider, workerCommand)) {
277
- return runHybridExecutionStage({
278
- repoRoot,
279
- changeId,
280
- snapshot,
281
- executed,
282
- parallel,
283
- maxRetries,
284
- resume,
285
- workerProvider,
286
- workerProviderArgs,
287
- workerCommand
288
- });
289
- }
290
-
291
- const controllerPass = await runControllerExecutionPass({
292
- repoRoot,
293
- changeId,
294
- manifest: snapshot.manifest,
295
- parallel,
296
- maxRetries,
297
- resume,
298
- state: snapshot.state
299
- });
300
-
301
- executed.push(controllerPass.command);
302
- return controllerPass.snapshot;
303
- }
304
-
305
- module.exports = {
306
- runExecutionStage
307
- };
@@ -1,48 +0,0 @@
1
- /**
2
- * [INPUT]: 依赖 store 提供的 requirement 状态读取能力,接收阶段名与 repo/change 标识。
3
- * [OUTPUT]: 对外提供 autopilot 共享阶段工具、approval 判定与 snapshot 读取函数。
4
- * [POS]: autopilot 的共享基础层,被 core 与 execution 共同复用,避免跨层互相借实现。
5
- * [PROTOCOL]: 变更时更新此头部,然后检查 CLAUDE.md
6
- */
7
-
8
- const {
9
- readJson,
10
- getRuntimeStatePath,
11
- getTaskManifestPath,
12
- getReportCardPath
13
- } = require('../store');
14
- const {
15
- normalizeStage,
16
- stageIndex,
17
- getApprovalState,
18
- isExecutionApproved
19
- } = require('../lifecycle');
20
-
21
- function hasUnresolvedTasks(manifest) {
22
- if (!manifest) {
23
- return false;
24
- }
25
-
26
- return manifest.tasks.some((task) =>
27
- ['pending', 'running', 'failed'].includes(task.status)
28
- );
29
- }
30
-
31
- async function loadState(repoRoot, changeId, options = {}) {
32
- const [state, manifest, report] = await Promise.all([
33
- readJson(getRuntimeStatePath(repoRoot, changeId, options), null),
34
- readJson(getTaskManifestPath(repoRoot, changeId, options), null),
35
- readJson(getReportCardPath(repoRoot, changeId, options), null)
36
- ]);
37
-
38
- return { state, manifest, report };
39
- }
40
-
41
- module.exports = {
42
- normalizeStage,
43
- stageIndex,
44
- hasUnresolvedTasks,
45
- loadState,
46
- getApprovalState,
47
- isExecutionApproved
48
- };