cc-devflow 4.5.9 → 4.5.11

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 (122) hide show
  1. package/.claude/skills/cc-act/CHANGELOG.md +11 -0
  2. package/.claude/skills/cc-act/SKILL.md +19 -10
  3. package/.claude/skills/cc-act/assets/PR_BRIEF_TEMPLATE.md +1 -1
  4. package/.claude/skills/cc-act/references/closure-contract.md +1 -1
  5. package/.claude/skills/cc-act/references/git-commit-guidelines.md +1 -1
  6. package/.claude/skills/cc-check/CHANGELOG.md +23 -0
  7. package/.claude/skills/cc-check/PLAYBOOK.md +1 -0
  8. package/.claude/skills/cc-check/SKILL.md +15 -9
  9. package/.claude/skills/cc-check/references/review-contract.md +7 -0
  10. package/.claude/skills/cc-check/scripts/render-report-card.js +6 -1
  11. package/.claude/skills/cc-dev/CHANGELOG.md +10 -0
  12. package/.claude/skills/cc-dev/SKILL.md +34 -2
  13. package/.claude/skills/cc-do/CHANGELOG.md +18 -0
  14. package/.claude/skills/cc-do/PLAYBOOK.md +7 -7
  15. package/.claude/skills/cc-do/SKILL.md +47 -40
  16. package/.claude/skills/cc-do/references/execution-recovery.md +18 -13
  17. package/.claude/skills/cc-do/scripts/build-task-context.sh +4 -17
  18. package/.claude/skills/cc-do/scripts/record-review-decision.sh +4 -5
  19. package/.claude/skills/cc-do/scripts/recover-workflow.sh +9 -11
  20. package/.claude/skills/cc-do/scripts/verify-task-gates.sh +12 -10
  21. package/.claude/skills/cc-do/scripts/write-task-checkpoint.sh +7 -29
  22. package/.claude/skills/cc-investigate/CHANGELOG.md +24 -0
  23. package/.claude/skills/cc-investigate/PLAYBOOK.md +10 -9
  24. package/.claude/skills/cc-investigate/SKILL.md +163 -417
  25. package/.claude/skills/cc-investigate/assets/TASKS_TEMPLATE.md +56 -10
  26. package/.claude/skills/cc-investigate/assets/TASK_MANIFEST_TEMPLATE.json +6 -6
  27. package/.claude/skills/cc-investigate/assets/{ANALYSIS_TEMPLATE.md → legacy/ANALYSIS_TEMPLATE.md} +1 -0
  28. package/.claude/skills/cc-investigate/references/investigation-contract.md +5 -4
  29. package/.claude/skills/cc-investigate/scripts/bootstrap-analysis.sh +1 -1
  30. package/.claude/skills/cc-plan/CHANGELOG.md +32 -0
  31. package/.claude/skills/cc-plan/PLAYBOOK.md +55 -53
  32. package/.claude/skills/cc-plan/SKILL.md +209 -536
  33. package/.claude/skills/cc-plan/assets/TASKS_TEMPLATE.md +50 -14
  34. package/.claude/skills/cc-plan/assets/TASK_MANIFEST_TEMPLATE.json +5 -4
  35. package/.claude/skills/cc-plan/assets/{DESIGN_TEMPLATE.md → legacy/DESIGN_TEMPLATE.md} +1 -0
  36. package/.claude/skills/cc-plan/assets/{TINY_DESIGN_TEMPLATE.md → legacy/TINY_DESIGN_TEMPLATE.md} +1 -1
  37. package/.claude/skills/cc-plan/references/planning-contract.md +12 -10
  38. package/.claude/skills/cc-review/CHANGELOG.md +6 -0
  39. package/.claude/skills/cc-review/PLAYBOOK.md +9 -11
  40. package/.claude/skills/cc-review/SKILL.md +37 -61
  41. package/.claude/skills/cc-review/references/e2e-and-plugin-verification.md +1 -1
  42. package/.claude/skills/cc-review/references/implementation-review-branch.md +5 -5
  43. package/.claude/skills/cc-review/references/plan-review-branch.md +1 -1
  44. package/.claude/skills/cc-review/references/review-methods.md +4 -4
  45. package/.claude/skills/cc-review/scripts/collect-review-context.sh +14 -7
  46. package/CHANGELOG.md +30 -0
  47. package/CONTRIBUTING.md +40 -4
  48. package/CONTRIBUTING.zh-CN.md +40 -4
  49. package/README.md +22 -8
  50. package/README.zh-CN.md +22 -8
  51. package/bin/cc-devflow-cli.js +293 -36
  52. package/docs/examples/START-HERE.md +6 -4
  53. package/docs/examples/example-bindings.json +8 -8
  54. package/docs/examples/full-design-blocked/README.md +2 -2
  55. package/docs/examples/full-design-blocked/changes/REQ-002-bulk-invite-import/planning/design.md +2 -1
  56. package/docs/examples/full-design-blocked/changes/REQ-002-bulk-invite-import/planning/task-manifest.json +3 -2
  57. package/docs/examples/full-design-blocked/changes/REQ-002-bulk-invite-import/planning/tasks.md +11 -8
  58. package/docs/examples/full-design-blocked/changes/REQ-002-bulk-invite-import/review/report-card.json +4 -4
  59. package/docs/examples/local-handoff/README.md +2 -2
  60. package/docs/examples/local-handoff/changes/REQ-003-audit-log-export/planning/design.md +2 -1
  61. package/docs/examples/local-handoff/changes/REQ-003-audit-log-export/planning/task-manifest.json +3 -2
  62. package/docs/examples/local-handoff/changes/REQ-003-audit-log-export/planning/tasks.md +9 -6
  63. package/docs/examples/local-handoff/changes/REQ-003-audit-log-export/review/report-card.json +1 -1
  64. package/docs/examples/pdca-loop/README.md +2 -2
  65. package/docs/examples/pdca-loop/changes/REQ-001-copy-invite-link/handoff/pr-brief.md +2 -2
  66. package/docs/examples/pdca-loop/changes/REQ-001-copy-invite-link/planning/design.md +2 -1
  67. package/docs/examples/pdca-loop/changes/REQ-001-copy-invite-link/planning/task-manifest.json +2 -1
  68. package/docs/examples/pdca-loop/changes/REQ-001-copy-invite-link/planning/tasks.md +9 -6
  69. package/docs/examples/pdca-loop/changes/REQ-001-copy-invite-link/review/report-card.json +1 -1
  70. package/docs/examples/scripts/check-example-bindings.sh +2 -0
  71. package/docs/get-shit-done-strategy-audit.md +22 -22
  72. package/docs/guides/artifact-contract.md +5 -1
  73. package/docs/guides/getting-started.md +11 -8
  74. package/docs/guides/getting-started.zh-CN.md +11 -8
  75. package/docs/guides/minimize-artifacts.md +137 -0
  76. package/lib/compiler/__tests__/skills-registry.test.js +2 -2
  77. package/lib/skill-runtime/CLAUDE.md +1 -1
  78. package/lib/skill-runtime/__tests__/autopilot.test.js +42 -6
  79. package/lib/skill-runtime/__tests__/benchmark-artifacts.test.js +165 -0
  80. package/lib/skill-runtime/__tests__/benchmark-skills.test.js +109 -0
  81. package/lib/skill-runtime/__tests__/cli-bootstrap.integration.test.js +2 -2
  82. package/lib/skill-runtime/__tests__/dispatch.test.js +8 -38
  83. package/lib/skill-runtime/__tests__/intent.test.js +4 -20
  84. package/lib/skill-runtime/__tests__/lifecycle.test.js +1 -1
  85. package/lib/skill-runtime/__tests__/paths.test.js +7 -1
  86. package/lib/skill-runtime/__tests__/planner.tdd.test.js +61 -0
  87. package/lib/skill-runtime/__tests__/prepare-pr.test.js +3 -16
  88. package/lib/skill-runtime/__tests__/query.test.js +388 -7
  89. package/lib/skill-runtime/__tests__/review-check-integration.test.js +148 -0
  90. package/lib/skill-runtime/__tests__/review-records.test.js +619 -0
  91. package/lib/skill-runtime/__tests__/runtime.integration.test.js +64 -23
  92. package/lib/skill-runtime/__tests__/schemas.test.js +43 -0
  93. package/lib/skill-runtime/__tests__/task-contract-migrate.test.js +137 -0
  94. package/lib/skill-runtime/__tests__/task-contract.test.js +874 -0
  95. package/lib/skill-runtime/__tests__/verify-artifacts.test.js +203 -0
  96. package/lib/skill-runtime/__tests__/worker-run.test.js +4 -11
  97. package/lib/skill-runtime/__tests__/workflow-context-legacy-fallback.test.js +31 -0
  98. package/lib/skill-runtime/__tests__/workflow-context.test.js +98 -0
  99. package/lib/skill-runtime/artifacts.js +0 -5
  100. package/lib/skill-runtime/context-index.js +545 -0
  101. package/lib/skill-runtime/intent.js +9 -33
  102. package/lib/skill-runtime/lifecycle.js +1 -1
  103. package/lib/skill-runtime/operations/CLAUDE.md +2 -2
  104. package/lib/skill-runtime/operations/dispatch.js +4 -42
  105. package/lib/skill-runtime/operations/init.js +2 -6
  106. package/lib/skill-runtime/operations/janitor.js +2 -18
  107. package/lib/skill-runtime/operations/resume.js +21 -38
  108. package/lib/skill-runtime/operations/review-records.js +265 -0
  109. package/lib/skill-runtime/operations/snapshot.js +1 -1
  110. package/lib/skill-runtime/operations/task-contract.js +593 -0
  111. package/lib/skill-runtime/operations/worker-run.js +2 -30
  112. package/lib/skill-runtime/paths.js +4 -4
  113. package/lib/skill-runtime/planner.js +24 -11
  114. package/lib/skill-runtime/query-registry.js +2 -2
  115. package/lib/skill-runtime/query.js +15 -2
  116. package/lib/skill-runtime/review-records.js +123 -0
  117. package/lib/skill-runtime/review.js +246 -11
  118. package/lib/skill-runtime/schemas.js +174 -12
  119. package/lib/skill-runtime/store.js +0 -10
  120. package/lib/skill-runtime/task-contract.js +188 -0
  121. package/lib/skill-runtime/workflow-context.js +748 -0
  122. package/package.json +6 -2
@@ -0,0 +1,593 @@
1
+ /**
2
+ * [INPUT]: 接收 repoRoot/changeId/changeKey,读取 planning/tasks.md。
3
+ * [OUTPUT]: 对外提供 task-contract compile / validate / migrate,生成、检查、迁移最小 workflow artifacts。
4
+ * [POS]: REQ-003 task-contract CLI operation 层。
5
+ * [PROTOCOL]: 变更时更新此头部,然后检查 CLAUDE.md
6
+ */
7
+
8
+ const { createTaskManifest } = require('../planner');
9
+ const fsp = require('fs/promises');
10
+ const path = require('path');
11
+ const { getChangePaths } = require('../paths');
12
+ const {
13
+ extractTasksContractSummary,
14
+ extractTasksRootCauseContract
15
+ } = require('../task-contract');
16
+ const {
17
+ exists,
18
+ ensureDir,
19
+ getTaskManifestPath,
20
+ getTasksMarkdownPath,
21
+ readText,
22
+ readJson,
23
+ writeText,
24
+ writeJson
25
+ } = require('../store');
26
+
27
+ const GENERATED_BY = 'cc-devflow task-contract';
28
+ const ACCEPTED_GENERATORS = new Set(['cc-devflow task-contract', 'skill:cc-plan']);
29
+ const PROFILE_BUDGETS = {
30
+ tiny: 1200,
31
+ standard: 2500,
32
+ deep: 5000
33
+ };
34
+
35
+ function listField(value) {
36
+ if (Array.isArray(value)) return value;
37
+ return value ? [value] : [];
38
+ }
39
+
40
+ function buildSummaryChangeMeta(change, fields) {
41
+ const contractChange = fields.change || change.changeKey;
42
+ return {
43
+ changeId: contractChange,
44
+ requirementId: contractChange,
45
+ goal: listField(fields.goal),
46
+ acceptance: listField(fields.acceptance),
47
+ specReference: {
48
+ source: 'planning/tasks.md#contract-summary',
49
+ change: contractChange,
50
+ mode: fields.mode || '',
51
+ profile: fields.profile || '',
52
+ approval: fields.approval || ''
53
+ },
54
+ _meta: {
55
+ generatedBy: GENERATED_BY,
56
+ generatedAt: new Date().toISOString()
57
+ }
58
+ };
59
+ }
60
+
61
+ function buildRootCauseChangeMeta(change, fields) {
62
+ const contractChange = fields.change || change.changeKey;
63
+ return {
64
+ changeId: contractChange,
65
+ requirementId: contractChange,
66
+ goal: listField(fields.rootCause || fields.symptom || `Repair confirmed root cause for ${contractChange}`),
67
+ acceptance: [
68
+ ...listField(fields.repairBoundary),
69
+ ...listField(fields.verification)
70
+ ],
71
+ specReference: {
72
+ source: 'planning/tasks.md#root-cause-contract',
73
+ change: contractChange,
74
+ mode: fields.mode || 'investigation',
75
+ profile: fields.profile || '',
76
+ approval: fields.diagnosis || ''
77
+ },
78
+ rootCause: {
79
+ diagnosis: fields.diagnosis || '',
80
+ symptom: listField(fields.symptom),
81
+ reproduction: listField(fields.reproduction),
82
+ confirmed: listField(fields.rootCause),
83
+ repairBoundary: listField(fields.repairBoundary),
84
+ prevention: listField(fields.prevention)
85
+ },
86
+ _meta: {
87
+ generatedBy: GENERATED_BY,
88
+ generatedAt: new Date().toISOString()
89
+ }
90
+ };
91
+ }
92
+
93
+ function extractCompileContract(tasksText) {
94
+ const summary = extractTasksContractSummary(tasksText);
95
+ if (summary.found) {
96
+ return {
97
+ type: 'summary',
98
+ source: 'planning/tasks.md#contract-summary',
99
+ fields: summary.fields
100
+ };
101
+ }
102
+
103
+ const rootCause = extractTasksRootCauseContract(tasksText);
104
+ if (rootCause.found) {
105
+ return {
106
+ type: 'root-cause',
107
+ source: 'planning/tasks.md#root-cause-contract',
108
+ fields: rootCause.fields
109
+ };
110
+ }
111
+
112
+ return null;
113
+ }
114
+
115
+ function buildChangeMeta(change, contract) {
116
+ if (contract.type === 'root-cause') {
117
+ return buildRootCauseChangeMeta(change, contract.fields);
118
+ }
119
+ return buildSummaryChangeMeta(change, contract.fields);
120
+ }
121
+
122
+ function summarizeContractGoal(contract) {
123
+ const fields = contract.fields || {};
124
+ if (contract.type === 'root-cause') {
125
+ return listField(fields.rootCause)[0] || listField(fields.symptom)[0] || '';
126
+ }
127
+ return listField(fields.goal)[0] || '';
128
+ }
129
+
130
+ async function relativeExists(change, relativePath) {
131
+ return exists(path.join(change.changeDir, relativePath));
132
+ }
133
+
134
+ async function readJsonSafe(filePath) {
135
+ try {
136
+ return await readJson(filePath, null);
137
+ } catch {
138
+ return null;
139
+ }
140
+ }
141
+
142
+ function estimateTokens(text) {
143
+ return Math.ceil(String(text || '').length / 4);
144
+ }
145
+
146
+ function contractProfile(tasksText) {
147
+ const contract = extractTasksContractSummary(tasksText);
148
+ if (contract.found) return contract.fields.profile || 'standard';
149
+ const rootCause = extractTasksRootCauseContract(tasksText);
150
+ if (rootCause.found) return rootCause.fields.profile || 'standard';
151
+ return 'standard';
152
+ }
153
+
154
+ function hasAnyContract(tasksText) {
155
+ return extractTasksContractSummary(tasksText).found || extractTasksRootCauseContract(tasksText).found;
156
+ }
157
+
158
+ function countTracerSlices(tasksText) {
159
+ const matches = [...String(tasksText || '').matchAll(/Vertical slice:\s*([^\n]+)/gi)];
160
+ if (matches.length > 0) {
161
+ return new Set(matches.map((match) => match[1].trim())).size;
162
+ }
163
+ return [...String(tasksText || '').matchAll(/^- \[[ xX]\]\s+T\d{3}\b/gm)].length;
164
+ }
165
+
166
+ function quoteLegacyMarkdown(text) {
167
+ return String(text || '')
168
+ .replace(/\r\n/g, '\n')
169
+ .replace(/\n*$/, '')
170
+ .split('\n')
171
+ .map((line) => (line.length > 0 ? `> ${line}` : '>'))
172
+ .join('\n');
173
+ }
174
+
175
+ function appendToSection(tasksText, heading, addition) {
176
+ const lines = String(tasksText || '').replace(/\r\n/g, '\n').split('\n');
177
+ const start = lines.findIndex((line) => line.trimEnd() === heading);
178
+ if (start === -1) return '';
179
+ let end = start + 1;
180
+ while (end < lines.length && !lines[end].startsWith('## ')) end += 1;
181
+ return [...lines.slice(0, end), '', addition, '', ...lines.slice(end)].join('\n').replace(/\n*$/, '\n');
182
+ }
183
+
184
+ function insertAfterTitle(tasksText, section) {
185
+ const lines = String(tasksText || '').replace(/\r\n/g, '\n').split('\n');
186
+ if (!lines[0]?.startsWith('# ')) {
187
+ return `${section}\n\n${String(tasksText || '').replace(/\n*$/, '\n')}`;
188
+ }
189
+ let tailStart = 1;
190
+ while (lines[tailStart] === '') tailStart += 1;
191
+ return [lines[0], '', section, '', ...lines.slice(tailStart)].join('\n').replace(/\n*$/, '\n');
192
+ }
193
+
194
+ function upsertContractSection(tasksText, heading, section, addition) {
195
+ return appendToSection(tasksText, heading, addition) || insertAfterTitle(tasksText, section);
196
+ }
197
+
198
+ function legacyBlock(label, content) {
199
+ return [`${label}:`, quoteLegacyMarkdown(content)].join('\n');
200
+ }
201
+
202
+ function designContractSection(change, content) {
203
+ const block = legacyBlock('Legacy Design', content);
204
+ return [
205
+ '## Contract Summary',
206
+ '',
207
+ `Change: ${change.changeKey}`,
208
+ 'Mode: migrated',
209
+ 'Profile: standard',
210
+ 'Approval: migrated',
211
+ '',
212
+ 'Goal:',
213
+ '- Preserve the legacy planning contract inside tasks.md.',
214
+ '',
215
+ 'Do Not Do:',
216
+ '- Do not auto-run this migration during compile.',
217
+ '',
218
+ 'Approved Direction:',
219
+ '- Use tasks.md as the canonical human-authored contract after migration.',
220
+ '',
221
+ 'Acceptance:',
222
+ '- Legacy planning/design.md content is folded into this section.',
223
+ '- planning/design.md is archived to assets/legacy/design.md.bak.',
224
+ '',
225
+ 'Verification:',
226
+ '',
227
+ '```bash',
228
+ 'npm test -- -t "task-contract migrate"',
229
+ '```',
230
+ '',
231
+ 'Risk / Escalate If:',
232
+ '- Review migrated content before deleting any legacy references.',
233
+ '',
234
+ block
235
+ ].join('\n');
236
+ }
237
+
238
+ function analysisContractSection(change, content) {
239
+ const block = legacyBlock('Legacy Analysis', content);
240
+ return [
241
+ '## Root Cause Contract',
242
+ '',
243
+ `Change: ${change.changeKey}`,
244
+ 'Mode: migrated',
245
+ 'Profile: standard',
246
+ 'Diagnosis: Migrated from legacy planning/analysis.md.',
247
+ '',
248
+ 'Symptom:',
249
+ '- Legacy investigation contract lived outside tasks.md.',
250
+ '',
251
+ 'Reproduction:',
252
+ '- Run task-contract migrate with --fold-analysis.',
253
+ '',
254
+ 'Expected:',
255
+ '- tasks.md owns the root-cause contract.',
256
+ '',
257
+ 'Actual:',
258
+ '- planning/analysis.md was the legacy contract file.',
259
+ '',
260
+ 'Root Cause:',
261
+ '- The pre-minimization workflow used a separate analysis.md artifact.',
262
+ '',
263
+ 'Evidence Chain:',
264
+ '- Migrated content is quoted below.',
265
+ '',
266
+ 'Repair Boundary:',
267
+ '- Archive only the requested legacy analysis file.',
268
+ '',
269
+ 'Prevention:',
270
+ '- Keep future root-cause contracts in tasks.md.',
271
+ '',
272
+ 'Risk / Escalate If:',
273
+ '- Review migrated content before deleting any legacy references.',
274
+ '',
275
+ block
276
+ ].join('\n');
277
+ }
278
+
279
+ function firstViolation(violations) {
280
+ if (violations.length === 0) {
281
+ return {
282
+ code: 0,
283
+ ok: true,
284
+ violations: [],
285
+ stderr: ''
286
+ };
287
+ }
288
+ const code = violations[0].exitCode;
289
+ return {
290
+ code,
291
+ ok: false,
292
+ violations,
293
+ stderr: violations.map((violation) => `${violation.ruleId}: ${violation.message}`).join('\n')
294
+ };
295
+ }
296
+
297
+ const VALIDATE_RULES = [
298
+ {
299
+ id: 'C1',
300
+ exitCode: 2,
301
+ check: async ({ change }) => (await relativeExists(change, 'planning/design.md'))
302
+ ? 'planning/design.md is a legacy default artifact'
303
+ : ''
304
+ },
305
+ {
306
+ id: 'C2',
307
+ exitCode: 2,
308
+ check: async ({ change }) => (await relativeExists(change, 'planning/analysis.md'))
309
+ ? 'planning/analysis.md is a legacy default artifact'
310
+ : ''
311
+ },
312
+ {
313
+ id: 'C3',
314
+ exitCode: 2,
315
+ check: async ({ change }) => {
316
+ const legacy = [];
317
+ if (await relativeExists(change, 'review/cc-review-report.md')) legacy.push('review/cc-review-report.md');
318
+ if (await relativeExists(change, 'review/cc-review-plan.md')) legacy.push('review/cc-review-plan.md');
319
+ return legacy.length > 0 ? `legacy review Markdown exists: ${legacy.join(', ')}` : '';
320
+ }
321
+ },
322
+ {
323
+ id: 'C4',
324
+ exitCode: 3,
325
+ check: async ({ tasksText }) => hasAnyContract(tasksText)
326
+ ? ''
327
+ : 'planning/tasks.md is missing ## Contract Summary or ## Root Cause Contract'
328
+ },
329
+ {
330
+ id: 'C5',
331
+ exitCode: 3,
332
+ check: async ({ manifestPath }) => {
333
+ const manifest = await readJsonSafe(manifestPath);
334
+ const generator = manifest?.metadata?.generatedBy || '';
335
+ return ACCEPTED_GENERATORS.has(generator) ? '' : `task-manifest.json generatedBy is unknown: ${generator || '<missing>'}`;
336
+ }
337
+ },
338
+ {
339
+ id: 'C6',
340
+ exitCode: 3,
341
+ check: async ({ changeMetaPath }) => {
342
+ const changeMeta = await readJsonSafe(changeMetaPath);
343
+ const generator = changeMeta?._meta?.generatedBy || '';
344
+ return ACCEPTED_GENERATORS.has(generator) ? '' : `change-meta.json _meta.generatedBy is unknown: ${generator || '<missing>'}`;
345
+ }
346
+ },
347
+ {
348
+ id: 'C7',
349
+ exitCode: 4,
350
+ check: async ({ tasksText }) => {
351
+ const profile = contractProfile(tasksText);
352
+ const slices = countTracerSlices(tasksText);
353
+ return profile === 'tiny' && slices > 1 ? `tiny profile has ${slices} tracer slices` : '';
354
+ }
355
+ },
356
+ {
357
+ id: 'C8',
358
+ exitCode: 5,
359
+ check: async ({ change }) => {
360
+ const ledgerPath = path.join(change.changeDir, 'review', 'review-ledger.jsonl');
361
+ if (!(await exists(ledgerPath))) return '';
362
+ const lines = (await readText(ledgerPath)).split(/\r?\n/).filter(Boolean);
363
+ const missing = lines.some((line) => {
364
+ try {
365
+ return !JSON.parse(line).createdBy;
366
+ } catch {
367
+ return true;
368
+ }
369
+ });
370
+ return missing ? 'review-ledger.jsonl has a row without createdBy' : '';
371
+ }
372
+ },
373
+ {
374
+ id: 'C9',
375
+ exitCode: 5,
376
+ check: async ({ change }) => {
377
+ const reportPath = path.join(change.changeDir, 'review', 'report-card.json');
378
+ if (!(await exists(reportPath))) return '';
379
+ const report = await readJsonSafe(reportPath);
380
+ const generator = report?._meta?.generatedBy || '';
381
+ return ACCEPTED_GENERATORS.has(generator) ? '' : `report-card.json generatedBy is unknown: ${generator || '<missing>'}`;
382
+ }
383
+ },
384
+ {
385
+ id: 'C10',
386
+ exitCode: 6,
387
+ check: async ({ tasksText }) => {
388
+ const profile = contractProfile(tasksText);
389
+ const budget = PROFILE_BUDGETS[profile] || PROFILE_BUDGETS.standard;
390
+ const tokens = estimateTokens(tasksText);
391
+ return tokens > budget ? `tasks.md token estimate ${tokens} exceeds ${profile} budget ${budget}` : '';
392
+ }
393
+ }
394
+ ];
395
+
396
+ async function runCompile({
397
+ repoRoot,
398
+ changeId,
399
+ changeKey,
400
+ goal,
401
+ overwrite = true
402
+ }) {
403
+ const pathOptions = changeKey ? { changeKey } : {};
404
+ const change = getChangePaths(repoRoot, changeId, pathOptions);
405
+ const tasksPath = getTasksMarkdownPath(repoRoot, changeId, { changeKey: change.changeKey });
406
+
407
+ if (!(await exists(tasksPath))) {
408
+ return {
409
+ code: 3,
410
+ changeId,
411
+ changeKey: change.changeKey,
412
+ error: `Missing planning/tasks.md: ${tasksPath}`
413
+ };
414
+ }
415
+
416
+ const contract = extractCompileContract(await readText(tasksPath));
417
+ if (!contract) {
418
+ return {
419
+ code: 3,
420
+ changeId,
421
+ changeKey: change.changeKey,
422
+ error: `Missing ## Contract Summary or ## Root Cause Contract in planning/tasks.md: ${tasksPath}`
423
+ };
424
+ }
425
+
426
+ await createTaskManifest({
427
+ repoRoot,
428
+ changeId,
429
+ changeKey: change.changeKey,
430
+ goal: goal || summarizeContractGoal(contract),
431
+ overwrite
432
+ });
433
+
434
+ const manifestPath = getTaskManifestPath(repoRoot, changeId, { changeKey: change.changeKey });
435
+ const changeMetaPath = path.join(change.changeDir, 'change-meta.json');
436
+ const manifest = await readJson(manifestPath);
437
+ const compiled = {
438
+ ...manifest,
439
+ metadata: {
440
+ ...manifest.metadata,
441
+ source: 'tasks.md',
442
+ generatedBy: GENERATED_BY
443
+ }
444
+ };
445
+
446
+ await writeJson(manifestPath, compiled);
447
+ await writeJson(changeMetaPath, buildChangeMeta(change, contract));
448
+
449
+ return {
450
+ code: 0,
451
+ changeId,
452
+ changeKey: change.changeKey,
453
+ manifestPath,
454
+ changeMetaPath,
455
+ metadata: compiled.metadata
456
+ };
457
+ }
458
+
459
+ async function runValidate({ repoRoot, changeId, changeKey }) {
460
+ const pathOptions = changeKey ? { changeKey } : {};
461
+ const change = getChangePaths(repoRoot, changeId, pathOptions);
462
+ const tasksPath = getTasksMarkdownPath(repoRoot, changeId, { changeKey: change.changeKey });
463
+ const manifestPath = getTaskManifestPath(repoRoot, changeId, { changeKey: change.changeKey });
464
+ const changeMetaPath = path.join(change.changeDir, 'change-meta.json');
465
+ const tasksText = await readText(tasksPath);
466
+ const context = { change, tasksPath, manifestPath, changeMetaPath, tasksText };
467
+ const violations = [];
468
+
469
+ for (const rule of VALIDATE_RULES) {
470
+ const message = await rule.check(context);
471
+ if (message) {
472
+ violations.push({ ruleId: rule.id, exitCode: rule.exitCode, message });
473
+ }
474
+ }
475
+
476
+ return {
477
+ ...firstViolation(violations),
478
+ changeId,
479
+ changeKey: change.changeKey
480
+ };
481
+ }
482
+
483
+ async function prepareLegacyFold(change, tasksText, config) {
484
+ const sourcePath = path.join(change.changeDir, 'planning', config.fileName);
485
+ if (!(await exists(sourcePath))) {
486
+ return { code: 3, error: `Missing planning/${config.fileName}: ${sourcePath}` };
487
+ }
488
+
489
+ let legacyText;
490
+ try {
491
+ legacyText = await readText(sourcePath);
492
+ } catch (error) {
493
+ return { code: 4, error: `Unable to read planning/${config.fileName}: ${error.message}` };
494
+ }
495
+
496
+ const archivePath = path.join(change.changeDir, 'assets', 'legacy', `${config.fileName}.bak`);
497
+ if (await exists(archivePath)) {
498
+ return { code: 4, error: `Legacy archive already exists: ${archivePath}` };
499
+ }
500
+
501
+ return {
502
+ code: 0,
503
+ fileName: config.fileName,
504
+ sourcePath,
505
+ archivePath,
506
+ tasksText: upsertContractSection(
507
+ tasksText,
508
+ config.heading,
509
+ config.section(change, legacyText),
510
+ legacyBlock(config.label, legacyText)
511
+ )
512
+ };
513
+ }
514
+
515
+ async function runMigrate({
516
+ repoRoot,
517
+ changeId,
518
+ changeKey,
519
+ foldDesign = false,
520
+ foldAnalysis = false
521
+ }) {
522
+ if (!foldDesign && !foldAnalysis) {
523
+ return {
524
+ code: 3,
525
+ changeId,
526
+ changeKey,
527
+ error: 'task-contract migrate requires --fold-design and/or --fold-analysis'
528
+ };
529
+ }
530
+
531
+ const pathOptions = changeKey ? { changeKey } : {};
532
+ const change = getChangePaths(repoRoot, changeId, pathOptions);
533
+ const tasksPath = getTasksMarkdownPath(repoRoot, changeId, { changeKey: change.changeKey });
534
+ if (!(await exists(tasksPath))) {
535
+ return {
536
+ code: 3,
537
+ changeId,
538
+ changeKey: change.changeKey,
539
+ error: `Missing planning/tasks.md: ${tasksPath}`
540
+ };
541
+ }
542
+
543
+ let tasksText = await readText(tasksPath);
544
+ const folds = [];
545
+ if (foldDesign) {
546
+ folds.push({
547
+ fileName: 'design.md',
548
+ heading: '## Contract Summary',
549
+ label: 'Legacy Design',
550
+ section: designContractSection
551
+ });
552
+ }
553
+ if (foldAnalysis) {
554
+ folds.push({
555
+ fileName: 'analysis.md',
556
+ heading: '## Root Cause Contract',
557
+ label: 'Legacy Analysis',
558
+ section: analysisContractSection
559
+ });
560
+ }
561
+
562
+ const prepared = [];
563
+ for (const fold of folds) {
564
+ const result = await prepareLegacyFold(change, tasksText, fold);
565
+ if (result.code !== 0) {
566
+ return { ...result, changeId, changeKey: change.changeKey };
567
+ }
568
+ tasksText = result.tasksText;
569
+ prepared.push(result);
570
+ }
571
+
572
+ await writeText(tasksPath, tasksText);
573
+ for (const fold of prepared) {
574
+ await ensureDir(path.dirname(fold.archivePath));
575
+ await fsp.rename(fold.sourcePath, fold.archivePath);
576
+ }
577
+
578
+ return {
579
+ code: 0,
580
+ changeId,
581
+ changeKey: change.changeKey,
582
+ tasksPath,
583
+ migrated: prepared.map((fold) => fold.fileName),
584
+ archives: prepared.map((fold) => fold.archivePath)
585
+ };
586
+ }
587
+
588
+ module.exports = {
589
+ GENERATED_BY,
590
+ runCompile,
591
+ runValidate,
592
+ runMigrate
593
+ };
@@ -20,17 +20,14 @@ const {
20
20
  readJson,
21
21
  writeText,
22
22
  nowIso,
23
- ensureDir,
24
23
  writeJson,
25
24
  appendJsonl,
26
25
  runCommand,
27
- getRuntimeTaskDir,
28
- getCheckpointPath,
29
26
  getEventsPath,
30
27
  getTaskManifestPath,
31
28
  getRuntimeStatePath
32
29
  } = require('../store');
33
- const { parseCheckpoint, parseManifest, parseRuntimeState } = require('../schemas');
30
+ const { parseManifest, parseRuntimeState } = require('../schemas');
34
31
  const { applyManifestExecutionState } = require('../planner');
35
32
  const { syncIntentMemory } = require('../intent');
36
33
  const { namedError } = require('../errors');
@@ -356,11 +353,9 @@ async function runWorkerCommand({
356
353
  const sessionId = `${workerId}-${Date.now()}`;
357
354
  const startedAt = nowIso();
358
355
  const sessionLogPath = handoff.sessionLogPath || getWorkerSessionLogPath(repoRoot, changeId, workerId);
359
- const runtimeTaskDir = getRuntimeTaskDir(repoRoot, changeId, primaryTaskId);
360
356
  const providerPromptPath = getProviderPromptPath(handoff, primaryTaskId);
361
357
  const providerLastMessagePath = getProviderLastMessagePath(handoff, primaryTaskId);
362
358
  const providerTranscriptPath = provider ? getProviderTranscriptPath(handoff, primaryTaskId, provider) : null;
363
- await ensureDir(runtimeTaskDir);
364
359
  await markRuntimeInProgress(repoRoot, changeId);
365
360
  const providerPrompt = provider ? await buildProviderPrompt(repoRoot, handoff, primaryTaskId) : null;
366
361
  if (providerPrompt) {
@@ -452,12 +447,6 @@ async function runWorkerCommand({
452
447
  const finishedAt = nowIso();
453
448
  const finalStatus = result.code === 0 ? 'completed' : 'failed';
454
449
  const summary = summarizeOutput(result);
455
- const providerOutputRaw = provider === 'codex'
456
- ? await readText(providerLastMessagePath, '')
457
- : provider === 'claude'
458
- ? result.stdout
459
- : result.stdout;
460
- const providerOutput = providerOutputRaw.trim();
461
450
  const codexTranscript = provider === 'codex' ? parseCodexTranscript(result.stdout) : null;
462
451
 
463
452
  await appendSessionLog(sessionLogPath, [
@@ -471,25 +460,8 @@ async function runWorkerCommand({
471
460
  ''
472
461
  ].filter(Boolean));
473
462
 
474
- const checkpointStatus = result.code === 0 ? 'passed' : 'failed';
475
- const checkpointSummary = providerOutput
476
- ? providerOutput.slice(0, 400)
477
- : `${provider || 'custom'} execution ${checkpointStatus}`;
478
- const checkpoint = parseCheckpoint({
479
- changeId,
480
- taskId: primaryTaskId,
481
- sessionId,
482
- planVersion: handoff.planVersion,
483
- status: checkpointStatus,
484
- summary: checkpointSummary,
485
- error: result.code === 0 ? '' : (result.stderr || result.stdout || '').trim(),
486
- outputExcerpt: providerOutput.slice(0, 400),
487
- timestamp: finishedAt,
488
- attempt: 1
489
- });
490
- await writeJson(getCheckpointPath(repoRoot, changeId, primaryTaskId), checkpoint);
491
463
  await updateManifestTaskState(repoRoot, changeId, primaryTaskId, {
492
- status: checkpointStatus,
464
+ status: result.code === 0 ? 'passed' : 'failed',
493
465
  attempts: 1,
494
466
  lastError: result.code === 0 ? undefined : (result.stderr || result.stdout || '').trim()
495
467
  });
@@ -8,7 +8,7 @@
8
8
  const fs = require('fs');
9
9
  const path = require('path');
10
10
 
11
- const CHANGE_ID_PATTERN = /^(REQ|FIX)-\d+$/;
11
+ const CHANGE_ID_PATTERN = /^(REQ|FIX)-\d+(?:-[a-z0-9-]+)?$/;
12
12
 
13
13
  function slugifySegment(value, fallback = 'change') {
14
14
  const normalized = String(value || '')
@@ -26,7 +26,7 @@ function assertChangeId(changeId) {
26
26
  const value = String(changeId || '').trim();
27
27
  if (!CHANGE_ID_PATTERN.test(value)) {
28
28
  throw new Error(
29
- `Invalid changeId "${value}". Use REQ-<number> or FIX-<number>.`
29
+ `Invalid changeId "${value}". Use REQ-<number>[-description] or FIX-<number>[-description].`
30
30
  );
31
31
  }
32
32
 
@@ -34,7 +34,8 @@ function assertChangeId(changeId) {
34
34
  }
35
35
 
36
36
  function getChangeKeyPrefix(changeId) {
37
- return assertChangeId(changeId);
37
+ const value = assertChangeId(changeId);
38
+ return value.match(/^(REQ|FIX)-\d+/)[0];
38
39
  }
39
40
 
40
41
  function stripChangeIdPrefix(changeId, value) {
@@ -224,7 +225,6 @@ function getTaskPaths(repoRoot, changeId, taskId, options = {}) {
224
225
  ...change,
225
226
  taskId,
226
227
  taskDir,
227
- checkpointPath: path.join(taskDir, 'checkpoint.json'),
228
228
  eventsPath: path.join(taskDir, 'events.jsonl')
229
229
  };
230
230
  }