cc-devflow 4.5.11 → 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 (185) hide show
  1. package/.claude/skills/cc-act/CHANGELOG.md +18 -0
  2. package/.claude/skills/cc-act/PLAYBOOK.md +17 -269
  3. package/.claude/skills/cc-act/SKILL.md +38 -425
  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 +18 -0
  15. package/.claude/skills/cc-check/PLAYBOOK.md +19 -273
  16. package/.claude/skills/cc-check/SKILL.md +33 -456
  17. package/.claude/skills/cc-check/references/review-contract.md +12 -147
  18. package/.claude/skills/cc-dev/CHANGELOG.md +15 -0
  19. package/.claude/skills/cc-dev/PLAYBOOK.md +1 -1
  20. package/.claude/skills/cc-dev/SKILL.md +52 -137
  21. package/.claude/skills/cc-dev/scripts/resolve-cc-devflow.sh +181 -0
  22. package/.claude/skills/cc-do/CHANGELOG.md +11 -0
  23. package/.claude/skills/cc-do/PLAYBOOK.md +19 -113
  24. package/.claude/skills/cc-do/SKILL.md +39 -245
  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 +16 -0
  31. package/.claude/skills/cc-investigate/PLAYBOOK.md +20 -180
  32. package/.claude/skills/cc-investigate/SKILL.md +64 -246
  33. package/.claude/skills/cc-investigate/assets/TASKS_TEMPLATE.md +48 -98
  34. package/.claude/skills/cc-investigate/references/investigation-contract.md +14 -218
  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 +16 -0
  39. package/.claude/skills/cc-plan/PLAYBOOK.md +22 -161
  40. package/.claude/skills/cc-plan/SKILL.md +45 -295
  41. package/.claude/skills/cc-plan/assets/TASKS_TEMPLATE.md +30 -228
  42. package/.claude/skills/cc-plan/references/planning-contract.md +24 -161
  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 +13 -0
  65. package/bin/cc-devflow-cli.js +20 -260
  66. package/bin/cc-devflow.js +44 -7
  67. package/docs/commands/README.md +1 -1
  68. package/docs/commands/README.zh-CN.md +1 -1
  69. package/docs/examples/README.md +1 -1
  70. package/docs/examples/START-HERE.md +14 -15
  71. package/docs/examples/example-bindings.json +11 -11
  72. package/docs/examples/full-design-blocked/README.md +4 -6
  73. package/docs/examples/full-design-blocked/changes/REQ-002-bulk-invite-import/{planning/tasks.md → task.md} +20 -15
  74. package/docs/examples/local-handoff/README.md +8 -11
  75. package/docs/examples/local-handoff/changes/REQ-003-audit-log-export/handoff/pr-brief.md +31 -0
  76. package/docs/examples/local-handoff/changes/REQ-003-audit-log-export/{planning/tasks.md → task.md} +18 -13
  77. package/docs/examples/pdca-loop/README.md +6 -9
  78. package/docs/examples/pdca-loop/changes/REQ-001-copy-invite-link/handoff/pr-brief.md +9 -11
  79. package/docs/examples/pdca-loop/changes/REQ-001-copy-invite-link/{planning/tasks.md → task.md} +18 -13
  80. package/docs/examples/scripts/check-example-bindings.sh +11 -62
  81. package/docs/guides/artifact-contract.md +10 -40
  82. package/docs/guides/getting-started.md +8 -8
  83. package/docs/guides/getting-started.zh-CN.md +8 -8
  84. package/docs/guides/minimize-artifacts.md +16 -130
  85. package/docs/guides/project-postmortem.md +14 -71
  86. package/lib/compiler/__tests__/skills-registry.test.js +9 -8
  87. package/lib/compiler/resource-copier.js +29 -0
  88. package/lib/skill-runtime/__tests__/archive-change.test.js +2 -2
  89. package/lib/skill-runtime/__tests__/benchmark-skills.test.js +3 -3
  90. package/lib/skill-runtime/__tests__/cli-bootstrap.integration.test.js +14 -4
  91. package/lib/skill-runtime/errors.js +3 -3
  92. package/lib/skill-runtime/index.js +5 -23
  93. package/lib/skill-runtime/paths.js +5 -52
  94. package/lib/skill-runtime/query-registry.js +4 -4
  95. package/lib/skill-runtime/query.js +89 -201
  96. package/lib/skill-runtime/store.js +4 -40
  97. package/lib/skill-runtime/trace.js +2 -2
  98. package/package.json +2 -5
  99. package/.claude/skills/cc-act/assets/PROJECT_POSTMORTEM_PRINCIPLES_TEMPLATE.md +0 -29
  100. package/.claude/skills/cc-act/assets/RELEASE_NOTE_TEMPLATE.md +0 -54
  101. package/.claude/skills/cc-act/scripts/generate-status-report.sh +0 -92
  102. package/.claude/skills/cc-act/scripts/sync-act-docs.sh +0 -355
  103. package/.claude/skills/cc-check/assets/REPORT_CARD_TEMPLATE.json +0 -234
  104. package/.claude/skills/cc-check/scripts/render-report-card.js +0 -438
  105. package/.claude/skills/cc-check/scripts/verify-gate.sh +0 -85
  106. package/.claude/skills/cc-do/scripts/build-task-context.sh +0 -175
  107. package/.claude/skills/cc-do/scripts/record-review-decision.sh +0 -88
  108. package/.claude/skills/cc-do/scripts/recover-workflow.sh +0 -82
  109. package/.claude/skills/cc-do/scripts/run-problem-analysis.sh +0 -70
  110. package/.claude/skills/cc-do/scripts/verify-task-gates.sh +0 -109
  111. package/.claude/skills/cc-do/scripts/write-task-checkpoint.sh +0 -92
  112. package/.claude/skills/cc-investigate/assets/TASK_MANIFEST_TEMPLATE.json +0 -224
  113. package/.claude/skills/cc-plan/assets/TASK_MANIFEST_TEMPLATE.json +0 -178
  114. package/.claude/skills/cc-spec-init/assets/CHANGE_META_TEMPLATE.json +0 -28
  115. package/.claude/skills/cc-spec-init/scripts/validate-spec-links.sh +0 -45
  116. package/docs/examples/full-design-blocked/changes/REQ-002-bulk-invite-import/planning/design.md +0 -234
  117. package/docs/examples/full-design-blocked/changes/REQ-002-bulk-invite-import/planning/task-manifest.json +0 -488
  118. package/docs/examples/full-design-blocked/changes/REQ-002-bulk-invite-import/review/report-card.json +0 -189
  119. package/docs/examples/local-handoff/changes/REQ-003-audit-log-export/handoff/resume-index.md +0 -39
  120. package/docs/examples/local-handoff/changes/REQ-003-audit-log-export/handoff/status.md +0 -29
  121. package/docs/examples/local-handoff/changes/REQ-003-audit-log-export/planning/design.md +0 -123
  122. package/docs/examples/local-handoff/changes/REQ-003-audit-log-export/planning/task-manifest.json +0 -292
  123. package/docs/examples/local-handoff/changes/REQ-003-audit-log-export/review/report-card.json +0 -136
  124. package/docs/examples/pdca-loop/changes/REQ-001-copy-invite-link/handoff/status.md +0 -29
  125. package/docs/examples/pdca-loop/changes/REQ-001-copy-invite-link/planning/design.md +0 -124
  126. package/docs/examples/pdca-loop/changes/REQ-001-copy-invite-link/planning/task-manifest.json +0 -292
  127. package/docs/examples/pdca-loop/changes/REQ-001-copy-invite-link/review/report-card.json +0 -136
  128. package/docs/get-shit-done-strategy-audit.md +0 -518
  129. package/docs/skill-runtime-migration.md +0 -46
  130. package/lib/skill-runtime/__tests__/approve.test.js +0 -92
  131. package/lib/skill-runtime/__tests__/autopilot.test.js +0 -253
  132. package/lib/skill-runtime/__tests__/benchmark-artifacts.test.js +0 -165
  133. package/lib/skill-runtime/__tests__/delegation.test.js +0 -97
  134. package/lib/skill-runtime/__tests__/dispatch.test.js +0 -237
  135. package/lib/skill-runtime/__tests__/intent.test.js +0 -203
  136. package/lib/skill-runtime/__tests__/lifecycle.test.js +0 -169
  137. package/lib/skill-runtime/__tests__/planner.tdd.test.js +0 -331
  138. package/lib/skill-runtime/__tests__/prepare-pr.test.js +0 -126
  139. package/lib/skill-runtime/__tests__/query.test.js +0 -860
  140. package/lib/skill-runtime/__tests__/readiness.test.js +0 -53
  141. package/lib/skill-runtime/__tests__/release.test.js +0 -85
  142. package/lib/skill-runtime/__tests__/review-check-integration.test.js +0 -148
  143. package/lib/skill-runtime/__tests__/review-records.test.js +0 -619
  144. package/lib/skill-runtime/__tests__/runtime.integration.test.js +0 -351
  145. package/lib/skill-runtime/__tests__/schemas.test.js +0 -337
  146. package/lib/skill-runtime/__tests__/task-contract-migrate.test.js +0 -137
  147. package/lib/skill-runtime/__tests__/task-contract.test.js +0 -874
  148. package/lib/skill-runtime/__tests__/team-state.test.js +0 -51
  149. package/lib/skill-runtime/__tests__/verify-artifacts.test.js +0 -203
  150. package/lib/skill-runtime/__tests__/worker-run.test.js +0 -275
  151. package/lib/skill-runtime/__tests__/worker.test.js +0 -56
  152. package/lib/skill-runtime/__tests__/workflow-context-legacy-fallback.test.js +0 -31
  153. package/lib/skill-runtime/__tests__/workflow-context.test.js +0 -98
  154. package/lib/skill-runtime/artifacts.js +0 -88
  155. package/lib/skill-runtime/context-index.js +0 -545
  156. package/lib/skill-runtime/delegation.js +0 -533
  157. package/lib/skill-runtime/intent.js +0 -309
  158. package/lib/skill-runtime/lifecycle.js +0 -294
  159. package/lib/skill-runtime/operations/CLAUDE.md +0 -19
  160. package/lib/skill-runtime/operations/approve.js +0 -81
  161. package/lib/skill-runtime/operations/autopilot-core.js +0 -337
  162. package/lib/skill-runtime/operations/autopilot-execution.js +0 -307
  163. package/lib/skill-runtime/operations/autopilot-shared.js +0 -48
  164. package/lib/skill-runtime/operations/autopilot.js +0 -163
  165. package/lib/skill-runtime/operations/dispatch.js +0 -416
  166. package/lib/skill-runtime/operations/init.js +0 -60
  167. package/lib/skill-runtime/operations/janitor.js +0 -61
  168. package/lib/skill-runtime/operations/plan.js +0 -59
  169. package/lib/skill-runtime/operations/prepare-pr.js +0 -25
  170. package/lib/skill-runtime/operations/release.js +0 -99
  171. package/lib/skill-runtime/operations/resume.js +0 -126
  172. package/lib/skill-runtime/operations/review-records.js +0 -265
  173. package/lib/skill-runtime/operations/snapshot.js +0 -45
  174. package/lib/skill-runtime/operations/task-contract.js +0 -593
  175. package/lib/skill-runtime/operations/verify.js +0 -170
  176. package/lib/skill-runtime/operations/worker-run.js +0 -531
  177. package/lib/skill-runtime/operations/worker.js +0 -33
  178. package/lib/skill-runtime/planner.js +0 -539
  179. package/lib/skill-runtime/readiness.js +0 -84
  180. package/lib/skill-runtime/review-records.js +0 -123
  181. package/lib/skill-runtime/review.js +0 -855
  182. package/lib/skill-runtime/schemas.js +0 -746
  183. package/lib/skill-runtime/task-contract.js +0 -188
  184. package/lib/skill-runtime/team-state.js +0 -122
  185. package/lib/skill-runtime/workflow-context.js +0 -748
@@ -1,188 +0,0 @@
1
- /**
2
- * [INPUT]: 接收 tasks.md 原始 Markdown 字符串;无文件 IO、无全局状态。
3
- * [OUTPUT]: 对外暴露 extractTasksContractSummary / extractTasksRootCauseContract → {found, content, fields}。
4
- * [POS]: REQ-003 task-contract 纯函数层;后续 compile / validate / migrate 复用本文件的解析 engine。
5
- * [PROTOCOL]: 变更时更新此头部,然后检查 CLAUDE.md
6
- */
7
-
8
- // ============================================================================
9
- // Section field schema
10
- // ============================================================================
11
-
12
- const CONTRACT_FIELD_MAP = {
13
- 'Change': 'change',
14
- 'Mode': 'mode',
15
- 'Profile': 'profile',
16
- 'Approval': 'approval',
17
- 'Goal': 'goal',
18
- 'Do Not Do': 'doNotDo',
19
- 'Approved Direction': 'approvedDirection',
20
- 'Acceptance': 'acceptance',
21
- 'Verification': 'verification',
22
- 'Risk / Escalate If': 'risk'
23
- };
24
-
25
- const CONTRACT_SINGLE_LINE = new Set(['change', 'mode', 'profile', 'approval']);
26
- const CONTRACT_LIST = new Set(['goal', 'doNotDo', 'approvedDirection', 'acceptance', 'risk']);
27
- const CONTRACT_VERIFICATION = new Set(['verification']);
28
-
29
- const ROOT_CAUSE_FIELD_MAP = {
30
- 'Change': 'change',
31
- 'Mode': 'mode',
32
- 'Profile': 'profile',
33
- 'Diagnosis': 'diagnosis',
34
- 'Symptom': 'symptom',
35
- 'Reproduction': 'reproduction',
36
- 'Expected': 'expected',
37
- 'Actual': 'actual',
38
- 'Root Cause': 'rootCause',
39
- 'Evidence Chain': 'evidenceChain',
40
- 'Repair Boundary': 'repairBoundary',
41
- 'Verification': 'verification',
42
- 'Prevention': 'prevention',
43
- 'Risk / Escalate If': 'risk'
44
- };
45
-
46
- const ROOT_CAUSE_SINGLE_LINE = new Set(['change', 'mode', 'profile', 'diagnosis']);
47
- const ROOT_CAUSE_LIST = new Set([
48
- 'symptom',
49
- 'reproduction',
50
- 'expected',
51
- 'actual',
52
- 'rootCause',
53
- 'evidenceChain',
54
- 'repairBoundary',
55
- 'prevention',
56
- 'risk'
57
- ]);
58
- const ROOT_CAUSE_VERIFICATION = new Set(['verification']);
59
-
60
- // ============================================================================
61
- // Heading block extraction (shared engine)
62
- // ============================================================================
63
-
64
- function extractHeadingBlock(text, heading) {
65
- if (typeof text !== 'string') {
66
- throw new TypeError('task-contract parser expects a string input');
67
- }
68
- const escaped = heading.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
69
- const pattern = new RegExp(`(^|\\n)(${escaped}\\r?\\n?)`);
70
- const match = text.match(pattern);
71
- if (!match) {
72
- return { found: false, content: '', body: '' };
73
- }
74
- const headingStart = match.index + match[1].length;
75
- const headingLineEnd = headingStart + match[2].length;
76
- const rest = text.slice(headingLineEnd);
77
- const nextIdx = rest.search(/\n## /);
78
- const blockEnd = nextIdx === -1 ? text.length : headingLineEnd + nextIdx;
79
- return {
80
- found: true,
81
- content: text.slice(headingStart, blockEnd),
82
- body: text.slice(headingLineEnd, blockEnd)
83
- };
84
- }
85
-
86
- // ============================================================================
87
- // Generic section parser
88
- // ============================================================================
89
-
90
- function parseSectionFields(body, schema) {
91
- const { fieldMap, singleLineKeys, listKeys, verificationKeys } = schema;
92
- const lines = body.split('\n');
93
- const fields = {};
94
- let currentLabel = null;
95
- let currentInline = null;
96
- let currentLines = [];
97
-
98
- const flush = () => {
99
- if (!currentLabel) return;
100
- const key = fieldMap[currentLabel];
101
- if (key) {
102
- const value = finalizeFieldValue(key, currentInline, currentLines, singleLineKeys, listKeys, verificationKeys);
103
- if (value !== undefined) fields[key] = value;
104
- }
105
- currentLabel = null;
106
- currentInline = null;
107
- currentLines = [];
108
- };
109
-
110
- for (const line of lines) {
111
- const kv = line.match(/^([A-Z][A-Za-z /]+?):\s*(.*)$/);
112
- if (kv && Object.prototype.hasOwnProperty.call(fieldMap, kv[1])) {
113
- flush();
114
- currentLabel = kv[1];
115
- currentInline = kv[2].length > 0 ? kv[2].trim() : null;
116
- } else if (currentLabel) {
117
- currentLines.push(line);
118
- }
119
- }
120
- flush();
121
- return fields;
122
- }
123
-
124
- function finalizeFieldValue(key, inline, lines, singleLineKeys, listKeys, verificationKeys) {
125
- if (singleLineKeys.has(key)) {
126
- return inline !== null ? inline : undefined;
127
- }
128
- if (listKeys.has(key)) {
129
- const items = lines
130
- .map(line => line.match(/^\s*-\s+(.*)$/))
131
- .filter(Boolean)
132
- .map(match => match[1].trim());
133
- if (items.length > 0) return items;
134
- return inline !== null ? inline : undefined;
135
- }
136
- if (verificationKeys.has(key)) {
137
- const joined = lines.join('\n');
138
- const fenceMatch = joined.match(/```[^\n]*\n([\s\S]*?)```/);
139
- if (fenceMatch) return fenceMatch[1].replace(/^\n+|\n+$/g, '');
140
- const trimmed = joined.replace(/^\n+|\n+$/g, '');
141
- if (trimmed.length > 0) return trimmed;
142
- return inline !== null ? inline : undefined;
143
- }
144
- return undefined;
145
- }
146
-
147
- // ============================================================================
148
- // Public parsers
149
- // ============================================================================
150
-
151
- function extractTasksContractSummary(text) {
152
- const block = extractHeadingBlock(text, '## Contract Summary');
153
- if (!block.found) {
154
- return { found: false, content: '', fields: {} };
155
- }
156
- return {
157
- found: true,
158
- content: block.content,
159
- fields: parseSectionFields(block.body, {
160
- fieldMap: CONTRACT_FIELD_MAP,
161
- singleLineKeys: CONTRACT_SINGLE_LINE,
162
- listKeys: CONTRACT_LIST,
163
- verificationKeys: CONTRACT_VERIFICATION
164
- })
165
- };
166
- }
167
-
168
- function extractTasksRootCauseContract(text) {
169
- const block = extractHeadingBlock(text, '## Root Cause Contract');
170
- if (!block.found) {
171
- return { found: false, content: '', fields: {} };
172
- }
173
- return {
174
- found: true,
175
- content: block.content,
176
- fields: parseSectionFields(block.body, {
177
- fieldMap: ROOT_CAUSE_FIELD_MAP,
178
- singleLineKeys: ROOT_CAUSE_SINGLE_LINE,
179
- listKeys: ROOT_CAUSE_LIST,
180
- verificationKeys: ROOT_CAUSE_VERIFICATION
181
- })
182
- };
183
- }
184
-
185
- module.exports = {
186
- extractTasksContractSummary,
187
- extractTasksRootCauseContract
188
- };
@@ -1,122 +0,0 @@
1
- /**
2
- * [INPUT]: 依赖 canonical path/store 的文件读写能力,接收 repoRoot/changeId 以维护 Team 真相源。
3
- * [OUTPUT]: 对外提供 Team state 真相源路径与读写能力。
4
- * [POS]: skill runtime 的 Team 状态桥接层,让 delegate/team runtime 统一落到 devflow/changes。
5
- * [PROTOCOL]: 变更时更新此头部,然后检查 CLAUDE.md
6
- */
7
-
8
- const fs = require('fs');
9
- const path = require('path');
10
- const { ensureDir, readJson, writeJson, nowIso } = require('./store');
11
- const { getChangePaths } = require('./paths');
12
-
13
- function getTeamStatePath(repoRoot, changeId) {
14
- return path.join(getChangePaths(repoRoot, changeId).executionDir, 'team-state.json');
15
- }
16
-
17
- function normalizeTeamState(changeId, payload = {}) {
18
- return {
19
- changeId,
20
- status: payload.status || 'delegated',
21
- phase: payload.phase || 'delegate',
22
- branch: payload.branch || 'unknown',
23
- updatedAt: payload.updatedAt || nowIso(),
24
- planVersion: payload.planVersion || 1,
25
- source: payload.source || {
26
- kind: 'skill-runtime-autopilot',
27
- derivedFrom: 'devflow/changes'
28
- },
29
- team: payload.team || null,
30
- ralphLoop: payload.ralphLoop || undefined
31
- };
32
- }
33
-
34
- async function readTeamState(repoRoot, changeId) {
35
- const truth = await readJson(getTeamStatePath(repoRoot, changeId), null);
36
- return truth?.team ? normalizeTeamState(changeId, truth) : null;
37
- }
38
-
39
- async function writeTeamState(repoRoot, changeId, payload) {
40
- const next = normalizeTeamState(changeId, payload);
41
- const truthPath = getTeamStatePath(repoRoot, changeId);
42
- await ensureDir(path.dirname(truthPath));
43
- await writeJson(truthPath, next);
44
-
45
- return next;
46
- }
47
-
48
- async function updateTeamState(repoRoot, changeId, updater) {
49
- const current = (await readTeamState(repoRoot, changeId)) || normalizeTeamState(changeId, {});
50
- const nextPayload = await updater(current);
51
- if (!nextPayload) {
52
- return current;
53
- }
54
- return writeTeamState(repoRoot, changeId, nextPayload);
55
- }
56
-
57
- function buildInitialTeamState(changeId, manifest, assignments, branch) {
58
- const delegateAssignments = assignments.filter((item) => item.route !== 'direct');
59
- const uniqueWorkers = Array.from(
60
- delegateAssignments.reduce((map, item) => {
61
- if (!map.has(item.workerId)) {
62
- map.set(item.workerId, {
63
- id: item.workerId,
64
- role: item.role,
65
- status: 'idle',
66
- currentTask: null,
67
- completedTasks: [],
68
- lastActiveAt: nowIso()
69
- });
70
- }
71
- return map;
72
- }, new Map()).values()
73
- );
74
-
75
- return normalizeTeamState(changeId, {
76
- status: 'delegated',
77
- phase: 'delegate',
78
- branch,
79
- planVersion: manifest.metadata?.planVersion || 1,
80
- source: {
81
- kind: 'skill-runtime-autopilot',
82
- derivedFrom: 'devflow/changes'
83
- },
84
- team: {
85
- mode: delegateAssignments.some((item) => item.route === 'team') ? 'parallel' : 'sequential',
86
- lead: 'main-agent',
87
- teammates: uniqueWorkers,
88
- taskAssignments: Object.fromEntries(delegateAssignments.map((item) => [item.taskId, item.workerId])),
89
- createdAt: nowIso(),
90
- updatedAt: nowIso()
91
- }
92
- });
93
- }
94
-
95
- function findLatestTeamStatePath(repoRoot) {
96
- const changesRoot = path.join(repoRoot, 'devflow', 'changes');
97
- if (!fs.existsSync(changesRoot)) {
98
- return null;
99
- }
100
-
101
- const candidates = fs.readdirSync(changesRoot)
102
- .map((name) => ({
103
- path: path.join(changesRoot, name, 'execution', 'team-state.json'),
104
- mtime: fs.existsSync(path.join(changesRoot, name))
105
- ? fs.statSync(path.join(changesRoot, name)).mtime.getTime()
106
- : 0
107
- }))
108
- .filter((item) => fs.existsSync(item.path))
109
- .sort((a, b) => b.mtime - a.mtime);
110
-
111
- return candidates[0]?.path || null;
112
- }
113
-
114
- module.exports = {
115
- getTeamStatePath,
116
- normalizeTeamState,
117
- readTeamState,
118
- writeTeamState,
119
- updateTeamState,
120
- buildInitialTeamState,
121
- findLatestTeamStatePath
122
- };