@dailephd/my-dev-kit-orchestrator 1.0.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 (110) hide show
  1. package/README.md +295 -0
  2. package/dist/artifactChecker.d.ts +31 -0
  3. package/dist/artifactChecker.d.ts.map +1 -0
  4. package/dist/artifactChecker.js +341 -0
  5. package/dist/artifactChecker.js.map +1 -0
  6. package/dist/artifactLifecycle.d.ts +30 -0
  7. package/dist/artifactLifecycle.d.ts.map +1 -0
  8. package/dist/artifactLifecycle.js +176 -0
  9. package/dist/artifactLifecycle.js.map +1 -0
  10. package/dist/cli.d.ts +3 -0
  11. package/dist/cli.d.ts.map +1 -0
  12. package/dist/cli.js +7 -0
  13. package/dist/cli.js.map +1 -0
  14. package/dist/commands/check.d.ts +3 -0
  15. package/dist/commands/check.d.ts.map +1 -0
  16. package/dist/commands/check.js +494 -0
  17. package/dist/commands/check.js.map +1 -0
  18. package/dist/commands/export.d.ts +16 -0
  19. package/dist/commands/export.d.ts.map +1 -0
  20. package/dist/commands/export.js +248 -0
  21. package/dist/commands/export.js.map +1 -0
  22. package/dist/commands/init.d.ts +3 -0
  23. package/dist/commands/init.d.ts.map +1 -0
  24. package/dist/commands/init.js +59 -0
  25. package/dist/commands/init.js.map +1 -0
  26. package/dist/commands/list.d.ts +3 -0
  27. package/dist/commands/list.d.ts.map +1 -0
  28. package/dist/commands/list.js +101 -0
  29. package/dist/commands/list.js.map +1 -0
  30. package/dist/commands/mark.d.ts +3 -0
  31. package/dist/commands/mark.d.ts.map +1 -0
  32. package/dist/commands/mark.js +139 -0
  33. package/dist/commands/mark.js.map +1 -0
  34. package/dist/commands/prompt.d.ts +3 -0
  35. package/dist/commands/prompt.d.ts.map +1 -0
  36. package/dist/commands/prompt.js +198 -0
  37. package/dist/commands/prompt.js.map +1 -0
  38. package/dist/commands/start.d.ts +3 -0
  39. package/dist/commands/start.d.ts.map +1 -0
  40. package/dist/commands/start.js +100 -0
  41. package/dist/commands/start.js.map +1 -0
  42. package/dist/commands/status.d.ts +3 -0
  43. package/dist/commands/status.d.ts.map +1 -0
  44. package/dist/commands/status.js +191 -0
  45. package/dist/commands/status.js.map +1 -0
  46. package/dist/contractChecker.d.ts +53 -0
  47. package/dist/contractChecker.d.ts.map +1 -0
  48. package/dist/contractChecker.js +319 -0
  49. package/dist/contractChecker.js.map +1 -0
  50. package/dist/correctionRouter.d.ts +37 -0
  51. package/dist/correctionRouter.d.ts.map +1 -0
  52. package/dist/correctionRouter.js +142 -0
  53. package/dist/correctionRouter.js.map +1 -0
  54. package/dist/correctionState.d.ts +16 -0
  55. package/dist/correctionState.d.ts.map +1 -0
  56. package/dist/correctionState.js +64 -0
  57. package/dist/correctionState.js.map +1 -0
  58. package/dist/index.d.ts +4 -0
  59. package/dist/index.d.ts.map +1 -0
  60. package/dist/index.js +9 -0
  61. package/dist/index.js.map +1 -0
  62. package/dist/judgeParser.d.ts +16 -0
  63. package/dist/judgeParser.d.ts.map +1 -0
  64. package/dist/judgeParser.js +52 -0
  65. package/dist/judgeParser.js.map +1 -0
  66. package/dist/program.d.ts +3 -0
  67. package/dist/program.d.ts.map +1 -0
  68. package/dist/program.js +33 -0
  69. package/dist/program.js.map +1 -0
  70. package/dist/promptChecker.d.ts +27 -0
  71. package/dist/promptChecker.d.ts.map +1 -0
  72. package/dist/promptChecker.js +152 -0
  73. package/dist/promptChecker.js.map +1 -0
  74. package/dist/promptGenerator.d.ts +12 -0
  75. package/dist/promptGenerator.d.ts.map +1 -0
  76. package/dist/promptGenerator.js +2556 -0
  77. package/dist/promptGenerator.js.map +1 -0
  78. package/dist/run.d.ts +30 -0
  79. package/dist/run.d.ts.map +1 -0
  80. package/dist/run.js +141 -0
  81. package/dist/run.js.map +1 -0
  82. package/dist/stageDetector.d.ts +29 -0
  83. package/dist/stageDetector.d.ts.map +1 -0
  84. package/dist/stageDetector.js +161 -0
  85. package/dist/stageDetector.js.map +1 -0
  86. package/dist/traceChecker.d.ts +46 -0
  87. package/dist/traceChecker.d.ts.map +1 -0
  88. package/dist/traceChecker.js +257 -0
  89. package/dist/traceChecker.js.map +1 -0
  90. package/dist/traceModel.d.ts +7 -0
  91. package/dist/traceModel.d.ts.map +1 -0
  92. package/dist/traceModel.js +37 -0
  93. package/dist/traceModel.js.map +1 -0
  94. package/dist/traceParser.d.ts +27 -0
  95. package/dist/traceParser.d.ts.map +1 -0
  96. package/dist/traceParser.js +102 -0
  97. package/dist/traceParser.js.map +1 -0
  98. package/dist/types.d.ts +11 -0
  99. package/dist/types.d.ts.map +1 -0
  100. package/dist/types.js +9 -0
  101. package/dist/types.js.map +1 -0
  102. package/dist/workflows.d.ts +16 -0
  103. package/dist/workflows.d.ts.map +1 -0
  104. package/dist/workflows.js +170 -0
  105. package/dist/workflows.js.map +1 -0
  106. package/dist/workspace.d.ts +13 -0
  107. package/dist/workspace.d.ts.map +1 -0
  108. package/dist/workspace.js +70 -0
  109. package/dist/workspace.js.map +1 -0
  110. package/package.json +62 -0
@@ -0,0 +1,2556 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.generateStagePrompt = generateStagePrompt;
37
+ exports.generateCorrectionPrompt = generateCorrectionPrompt;
38
+ exports.writeStagePrompts = writeStagePrompts;
39
+ const fs = __importStar(require("fs"));
40
+ const path = __importStar(require("path"));
41
+ function header(ctx) {
42
+ const lines = [
43
+ `Stage: ${ctx.stage}`,
44
+ `Workflow mode: ${ctx.mode}`,
45
+ `Run ID: ${ctx.runId}`,
46
+ `Project root: ${ctx.projectRoot}`,
47
+ `Run folder: ${ctx.runFolder}`,
48
+ ];
49
+ if (ctx.sourceRepoRoot)
50
+ lines.push(`Source repository: ${ctx.sourceRepoRoot}`);
51
+ if (ctx.targetRepoRoot)
52
+ lines.push(`Target repository: ${ctx.targetRepoRoot}`);
53
+ lines.push('');
54
+ return lines.join('\n');
55
+ }
56
+ // ─── Core shared stages ───────────────────────────────────────────────────────
57
+ function requestBriefPrompt(ctx) {
58
+ return `${header(ctx)}
59
+ Inputs:
60
+ - original request: ${ctx.runFolder}/00-request.txt
61
+
62
+ Task:
63
+ Produce ${ctx.runFolder}/artifacts/request-brief.txt (artifact: RequestBrief).
64
+
65
+ The RequestBrief must define:
66
+ - original request (verbatim from 00-request.txt)
67
+ - requested change
68
+ - target area (project, component, workflow, or command) if identifiable
69
+ - user-visible or externally observable behavior
70
+ - constraints
71
+ - non-goals
72
+ - success criteria
73
+ - ambiguity or missing information
74
+ - expected next stage: architecture-context
75
+
76
+ Required output artifact: RequestBrief
77
+ Output file: ${ctx.runFolder}/artifacts/request-brief.txt
78
+
79
+ Stop conditions:
80
+ - do not inspect code deeply in this stage
81
+ - do not write pseudocode
82
+ - do not write tests
83
+ - do not implement code
84
+
85
+ Return format:
86
+ Produce the artifact as a plain-text file using the template:
87
+ Artifact: RequestBrief
88
+ Workflow mode: ...
89
+ Original request: ...
90
+ Requested change: ...
91
+ Target area: ...
92
+ User-visible or external behavior: ...
93
+ Constraints: ...
94
+ Non-goals: ...
95
+ Success criteria: ...
96
+ Ambiguity or missing information: ...
97
+ Expected next stage: architecture-context
98
+ Status: complete | incomplete | blocked
99
+ `;
100
+ }
101
+ function architectureContextPrompt(ctx) {
102
+ return `${header(ctx)}
103
+ Inputs:
104
+ - ${ctx.runFolder}/artifacts/request-brief.txt
105
+ - project root: ${ctx.projectRoot}
106
+
107
+ Task:
108
+ Retrieve bounded project context and synthesize it into the required workflow artifact.
109
+
110
+ Produce two output files:
111
+ 1. Supporting retrieval report: ${ctx.runFolder}/reports/architecture-context-retrieval-report.txt
112
+ 2. Required workflow artifact: ${ctx.runFolder}/artifacts/architecture-context-packet.txt (artifact: ArchitectureContextPacket)
113
+
114
+ Later workflow stages consume ArchitectureContextPacket.
115
+ Do not dump raw retrieval output directly into ArchitectureContextPacket.
116
+ Synthesize retrieval evidence into the artifact before writing it.
117
+
118
+ Graph-guided context acquisition sequence (when my-dev-kit is available):
119
+
120
+ Step 1 - Index or refresh the target repository:
121
+ npx @dailephd/my-dev-kit index --root . --src src --out .my-dev-kit --call-graph --json
122
+
123
+ Step 2 - Search for task-specific candidate nodes:
124
+ npx @dailephd/my-dev-kit search --index .my-dev-kit --query "<task-specific term>" --limit 20 --json
125
+ Run multiple queries for different aspects of the request.
126
+
127
+ Step 3 - Look up selected nodes and their relationships:
128
+ npx @dailephd/my-dev-kit lookup --index .my-dev-kit --node "<selected-node-id>" --depth 1 --json
129
+
130
+ Step 4 - Slice around the strongest relevant node:
131
+ npx @dailephd/my-dev-kit slice --index .my-dev-kit --node "<strongest-node-id>" --depth 2 --direction both --out .my-dev-kit/<task-name>-slice.json --json
132
+
133
+ Step 5 - Retrieve exact symbol source (preferred):
134
+ npx @dailephd/my-dev-kit source --index .my-dev-kit --node "<symbol-node-id>" --max-lines 160 --format numbered
135
+ or:
136
+ npx @dailephd/my-dev-kit source --index .my-dev-kit --file "<file-path>" --symbol "<symbol-name>" --max-lines 160 --format numbered
137
+
138
+ Step 6 - Use line-range retrieval only as fallback when symbol retrieval is insufficient:
139
+ npx @dailephd/my-dev-kit source --index .my-dev-kit --file "<file-path>" --start <start-line> --end <end-line> --max-lines <cap> --format numbered
140
+
141
+ Step 7 - Inspect semantic artifacts, tests, docs, or data-model artifacts only when relevant to the task.
142
+
143
+ Step 8 - Avoid whole-file reading unless bounded retrieval is insufficient. If a whole file must be read, state why.
144
+
145
+ If my-dev-kit is unavailable, use focused manual inspection of relevant files and symbols. Document what was inspected, why, and what bounded context was gathered.
146
+
147
+ The ArchitectureContextPacket must identify:
148
+ - relevant files
149
+ - relevant symbols
150
+ - relevant components, modules, routes, commands, services, or data boundaries
151
+ - relevant tests
152
+ - relevant docs
153
+ - state owners and data owners
154
+ - upstream dependencies
155
+ - downstream consumers
156
+ - existing patterns to preserve
157
+ - likely files or modules involved in this change
158
+ - context gaps or uncertainty
159
+ - selection rationale for each major file or symbol chosen
160
+
161
+ Required output artifact: ArchitectureContextPacket
162
+ Output file: ${ctx.runFolder}/artifacts/architecture-context-packet.txt
163
+
164
+ Supporting report output file: ${ctx.runFolder}/reports/architecture-context-retrieval-report.txt
165
+
166
+ Stop conditions:
167
+ - do not redesign the feature
168
+ - do not write pseudocode
169
+ - do not implement code
170
+ - do not write test files
171
+ - do not claim implementation or test implementation work in this stage
172
+
173
+ Return format:
174
+
175
+ Write the supporting retrieval report using this template:
176
+
177
+ Retrieval evidence report
178
+
179
+ Index artifacts used:
180
+ - Index directory:
181
+ - Refreshed or reused:
182
+ - manifest.json status:
183
+ - Semantic artifacts available:
184
+
185
+ Search queries run:
186
+ - Query:
187
+ Reason:
188
+
189
+ Candidate nodes selected:
190
+ - Node ID:
191
+ Reason:
192
+
193
+ Lookup commands run:
194
+ - Node ID:
195
+ Useful relationships found:
196
+
197
+ Graph slices created:
198
+ - Focus node:
199
+ - Depth:
200
+ - Direction:
201
+ - Output path:
202
+ - Reason:
203
+
204
+ Source symbols retrieved:
205
+ - Symbol node ID:
206
+ - File path:
207
+ - Reason:
208
+
209
+ Line-range fallback retrieval used:
210
+ - File path or none:
211
+ - Lines:
212
+ - Reason:
213
+
214
+ Full files read beyond retrieved source:
215
+ - File path or none:
216
+ - Reason:
217
+ - Missing context provided:
218
+
219
+ Semantic artifacts inspected:
220
+ - Artifact or command:
221
+ - Reason:
222
+
223
+ Context gaps or uncertainty:
224
+ - Gap:
225
+ Impact:
226
+
227
+ Then write ArchitectureContextPacket using this template:
228
+
229
+ Artifact: ArchitectureContextPacket
230
+ Workflow mode: ...
231
+ Project root: ...
232
+
233
+ Retrieval evidence used:
234
+ - Retrieval report: ${ctx.runFolder}/reports/architecture-context-retrieval-report.txt
235
+ - Index directory:
236
+ - Graph slice files:
237
+ - Source excerpts:
238
+ - Semantic artifacts:
239
+
240
+ Retrieval method:
241
+ - my-dev-kit used: yes | no
242
+ - graph-guided retrieval used: yes | no
243
+ - manual inspection used: yes | no
244
+
245
+ Relevant files: ...
246
+ Relevant symbols: ...
247
+ Relevant components / modules / commands / routes / services / boundaries: ...
248
+ Relevant tests: ...
249
+ Relevant docs: ...
250
+ State owners: ...
251
+ Data owners: ...
252
+ Upstream dependencies: ...
253
+ Downstream consumers: ...
254
+ Existing patterns to preserve: ...
255
+ Likely files or modules involved: ...
256
+ Context gaps or uncertainty: ...
257
+ Selection rationale: ...
258
+ Expected next stage: (next in workflow)
259
+ Status: complete | incomplete | blocked
260
+ `;
261
+ }
262
+ function behaviorModelPrompt(ctx) {
263
+ return `${header(ctx)}
264
+ Inputs:
265
+ - ${ctx.runFolder}/artifacts/request-brief.txt
266
+ - ${ctx.runFolder}/artifacts/architecture-context-packet.txt
267
+
268
+ Task:
269
+ Produce ${ctx.runFolder}/artifacts/behavior-model.txt (artifact: BehaviorModel).
270
+
271
+ Define intended behavior before pseudocode, implementation, or test writing begins.
272
+
273
+ The BehaviorModel must define:
274
+ - behavior summary
275
+ - externally visible behavior
276
+ - internal supporting behavior
277
+ - state variables
278
+ - inputs
279
+ - events
280
+ - derived values
281
+ - invariants
282
+ - valid states
283
+ - invalid states
284
+ - boundaries and partitions
285
+ - empty states
286
+ - error states
287
+ - loading or pending states when relevant
288
+ - external contracts
289
+ - state transitions
290
+ - behavior to preserve
291
+ - behavior intentionally changed
292
+ - unresolved design questions
293
+
294
+ Trace IDs (optional):
295
+ Assign trace IDs to behaviors, invariants, and transitions to enable downstream traceability.
296
+ Format: BEH-001: description, INV-001: description, TRN-001: description.
297
+ If trace IDs are used, link related items using: FROM_ID -> TO_ID.
298
+ Use canonical format (PREFIX-NNN with 3+ digits). Run: my-dev-kit-orchestrator check --trace
299
+
300
+ Required output artifact: BehaviorModel
301
+ Output file: ${ctx.runFolder}/artifacts/behavior-model.txt
302
+
303
+ Stop conditions:
304
+ - do not write production code
305
+ - do not write test files
306
+ - do not produce implementation-specific code
307
+
308
+ Return format:
309
+ Produce the artifact as a plain-text file following the BehaviorModel template.
310
+ Artifact: BehaviorModel
311
+ Workflow mode: ...
312
+ Inputs used: ...
313
+ Behavior summary: ...
314
+ [all required sections]
315
+ Status: complete | incomplete | blocked
316
+ `;
317
+ }
318
+ function pseudocodePacketPrompt(ctx) {
319
+ return `${header(ctx)}
320
+ Inputs:
321
+ - ${ctx.runFolder}/artifacts/request-brief.txt
322
+ - ${ctx.runFolder}/artifacts/architecture-context-packet.txt
323
+ - ${ctx.runFolder}/artifacts/behavior-model.txt
324
+
325
+ Task:
326
+ Produce ${ctx.runFolder}/artifacts/pseudocode-packet.txt (artifact: PseudocodePacket).
327
+
328
+ Convert the BehaviorModel into implementation-neutral pseudocode.
329
+ This is the shared design contract for both implementation and testing.
330
+
331
+ The PseudocodePacket must define:
332
+ - behavior references
333
+ - data flow
334
+ - state flow
335
+ - state transitions
336
+ - derived-value rules
337
+ - validation rules
338
+ - empty-state handling
339
+ - error-state handling
340
+ - external contract handling
341
+ - component, module, service, route, command, or helper contracts
342
+ - acceptance criteria
343
+ - likely files or modules to modify
344
+ - implementation constraints
345
+ - assumptions preserved
346
+ - assumptions removed or guarded
347
+ - unresolved implementation questions
348
+
349
+ Trace IDs (optional):
350
+ Assign PSE-NNN trace IDs to pseudocode entries to enable downstream traceability.
351
+ Format: PSE-001: pseudocode entry. Link to behavior IDs using: BEH-001 -> PSE-001.
352
+ Use canonical format (PREFIX-NNN with 3+ digits). Run: my-dev-kit-orchestrator check --trace
353
+
354
+ Required output artifact: PseudocodePacket
355
+ Output file: ${ctx.runFolder}/artifacts/pseudocode-packet.txt
356
+
357
+ Stop conditions:
358
+ - do not write production code
359
+ - do not write test files
360
+ - do not modify files
361
+
362
+ Return format:
363
+ Produce the artifact as a plain-text file following the PseudocodePacket template.
364
+ Artifact: PseudocodePacket
365
+ Workflow mode: ...
366
+ Inputs used: ...
367
+ [all required sections]
368
+ Status: complete | incomplete | blocked
369
+ `;
370
+ }
371
+ function testStrategyPrompt(ctx) {
372
+ return `${header(ctx)}
373
+ Inputs:
374
+ - ${ctx.runFolder}/artifacts/request-brief.txt
375
+ - ${ctx.runFolder}/artifacts/architecture-context-packet.txt
376
+ - ${ctx.runFolder}/artifacts/behavior-model.txt
377
+ - ${ctx.runFolder}/artifacts/pseudocode-packet.txt
378
+
379
+ Task:
380
+ Produce ${ctx.runFolder}/artifacts/test-strategy-packet.txt (artifact: TestStrategyPacket).
381
+
382
+ Derive test responsibilities from the BehaviorModel and PseudocodePacket.
383
+ Do not write test files in this stage.
384
+
385
+ The TestStrategyPacket must identify:
386
+ - behavior under test
387
+ - participating layers
388
+ - state variables
389
+ - events
390
+ - derived values
391
+ - invariants
392
+ - boundaries and partitions
393
+ - external contracts
394
+ - state transitions when relevant
395
+ - relevant failure modes
396
+ - existing tests
397
+ - test matrix
398
+ - test level assignment (unit / component / integration / end-to-end)
399
+ - required verification commands
400
+ - coverage gaps
401
+ - risks not covered and why
402
+
403
+ Each test responsibility must trace to at least one of:
404
+ - behavior
405
+ - invariant
406
+ - state transition
407
+ - derived value
408
+ - boundary
409
+ - external contract
410
+ - failure mode
411
+
412
+ Trace IDs (optional):
413
+ Assign TST-NNN trace IDs to test responsibilities to enable downstream traceability.
414
+ Format: TST-001: test responsibility. Link to behaviors or pseudocode: PSE-001 -> TST-001.
415
+ Use canonical format (PREFIX-NNN with 3+ digits). Run: my-dev-kit-orchestrator check --trace
416
+
417
+ Required output artifact: TestStrategyPacket
418
+ Output file: ${ctx.runFolder}/artifacts/test-strategy-packet.txt
419
+
420
+ Stop conditions:
421
+ - do not write test files in this stage
422
+ - do not write production code
423
+ - do not invent behavior not supported by prior artifacts
424
+ - do not include test responsibilities that cannot be traced to behavior, invariant, transition, derived value, boundary, contract, or failure mode
425
+
426
+ Return format:
427
+ Produce the artifact as a plain-text file following the TestStrategyPacket template.
428
+ Artifact: TestStrategyPacket
429
+ Workflow mode: ...
430
+ Inputs used: ...
431
+ [all required sections]
432
+ Status: complete | incomplete | blocked
433
+ `;
434
+ }
435
+ function implementationPrompt(ctx, extraInputs = []) {
436
+ const inputs = [
437
+ `- ${ctx.runFolder}/artifacts/request-brief.txt`,
438
+ `- ${ctx.runFolder}/artifacts/architecture-context-packet.txt`,
439
+ `- ${ctx.runFolder}/artifacts/behavior-model.txt`,
440
+ `- ${ctx.runFolder}/artifacts/pseudocode-packet.txt`,
441
+ ...extraInputs.map((i) => `- ${ctx.runFolder}/artifacts/${i}`),
442
+ ].join('\n');
443
+ return `${header(ctx)}
444
+ Inputs:
445
+ ${inputs}
446
+
447
+ Task:
448
+ Implement the PseudocodePacket in the current project and produce ${ctx.runFolder}/artifacts/implementation-report.txt (artifact: ImplementationReport).
449
+
450
+ Read required source files and implement from the PseudocodePacket.
451
+ Follow the architecture and patterns identified in the ArchitectureContextPacket.
452
+ Preserve the BehaviorModel.
453
+
454
+ The ImplementationReport must include:
455
+ - files read
456
+ - files changed
457
+ - behavior implemented
458
+ - pseudocode sections implemented
459
+ - assumptions preserved
460
+ - assumptions removed or guarded
461
+ - deviations from the PseudocodePacket
462
+ - reason for each deviation
463
+ - blockers encountered
464
+ - unresolved risks
465
+ - tests that should be run
466
+ - notes for the test implementation stage
467
+
468
+ Required output artifact: ImplementationReport
469
+ Output file: ${ctx.runFolder}/artifacts/implementation-report.txt
470
+
471
+ Stop conditions:
472
+ - do not broaden scope without reporting a blocker
473
+ - do not create parallel architecture
474
+ - do not claim verification success without command evidence
475
+ - do not ignore contradictions in prior artifacts
476
+ - do not modify files outside justified scope
477
+
478
+ Return format:
479
+ Produce the artifact as a plain-text file following the ImplementationReport template.
480
+ Artifact: ImplementationReport
481
+ Workflow mode: ...
482
+ Inputs used: ...
483
+ [all required sections]
484
+ Status: complete | incomplete | blocked
485
+ `;
486
+ }
487
+ function testImplementationPrompt(ctx, extraInputs = []) {
488
+ const inputs = [
489
+ `- ${ctx.runFolder}/artifacts/behavior-model.txt`,
490
+ `- ${ctx.runFolder}/artifacts/pseudocode-packet.txt`,
491
+ `- ${ctx.runFolder}/artifacts/test-strategy-packet.txt`,
492
+ ...extraInputs.map((i) => `- ${ctx.runFolder}/artifacts/${i}`),
493
+ `- ${ctx.runFolder}/artifacts/implementation-report.txt (if available)`,
494
+ ].join('\n');
495
+ return `${header(ctx)}
496
+ Inputs:
497
+ ${inputs}
498
+
499
+ Task:
500
+ Implement tests from the TestStrategyPacket and produce ${ctx.runFolder}/artifacts/test-implementation-report.txt (artifact: TestImplementationReport).
501
+
502
+ Follow the TestStrategyPacket. Do not invent a separate test strategy.
503
+
504
+ The TestImplementationReport must include:
505
+ - test files changed
506
+ - tests added
507
+ - tests updated
508
+ - behaviors covered
509
+ - invariants covered
510
+ - state transitions covered
511
+ - derived values covered
512
+ - boundaries covered
513
+ - external contracts covered
514
+ - failure modes covered
515
+ - TestStrategyPacket items not implemented
516
+ - reason for each missing test
517
+ - verification commands to run
518
+
519
+ Required output artifact: TestImplementationReport
520
+ Output file: ${ctx.runFolder}/artifacts/test-implementation-report.txt
521
+
522
+ Stop conditions:
523
+ - do not replace the TestStrategyPacket with a new unrelated strategy
524
+ - do not change production behavior unless reporting a blocker
525
+ - do not claim tests passed unless command evidence is included
526
+
527
+ Return format:
528
+ Produce the artifact as a plain-text file following the TestImplementationReport template.
529
+ Artifact: TestImplementationReport
530
+ Workflow mode: ...
531
+ [all required sections]
532
+ Status: complete | incomplete | blocked
533
+ `;
534
+ }
535
+ function verificationPrompt(ctx) {
536
+ return `${header(ctx)}
537
+ Inputs:
538
+ - ${ctx.runFolder}/artifacts/test-strategy-packet.txt
539
+ - ${ctx.runFolder}/artifacts/implementation-report.txt
540
+ - ${ctx.runFolder}/artifacts/test-implementation-report.txt
541
+
542
+ Task:
543
+ Run the required verification commands and produce ${ctx.runFolder}/artifacts/verification-report.txt (artifact: VerificationReport).
544
+
545
+ Use the commands identified in the TestStrategyPacket, ImplementationReport, and TestImplementationReport.
546
+ Run the narrowest relevant checks first, then broader validation.
547
+
548
+ The VerificationReport must include:
549
+ - commands run
550
+ - working directory for each command
551
+ - exit codes
552
+ - pass/fail status
553
+ - output summary
554
+ - failed tests if any
555
+ - skipped checks
556
+ - reason for skipped checks
557
+ - environment notes if relevant
558
+ - remaining verification gaps
559
+
560
+ Required output artifact: VerificationReport
561
+ Output file: ${ctx.runFolder}/artifacts/verification-report.txt
562
+
563
+ Stop conditions:
564
+ - do not claim checks passed unless command output was produced
565
+ - do not hide failed commands
566
+ - do not omit skipped required checks
567
+
568
+ Return format:
569
+ Produce the artifact as a plain-text file following the VerificationReport template.
570
+ Artifact: VerificationReport
571
+ Workflow mode: ...
572
+ [all required sections]
573
+ Status: complete | incomplete | blocked
574
+ `;
575
+ }
576
+ function judgePrompt(ctx) {
577
+ return `${header(ctx)}
578
+ Inputs:
579
+ - ${ctx.runFolder}/artifacts/request-brief.txt (or mode-specific entry artifact)
580
+ - ${ctx.runFolder}/artifacts/architecture-context-packet.txt
581
+ - ${ctx.runFolder}/artifacts/behavior-model.txt (or reconstruction)
582
+ - ${ctx.runFolder}/artifacts/pseudocode-packet.txt (or mode-specific equivalent)
583
+ - ${ctx.runFolder}/artifacts/test-strategy-packet.txt (or mode-specific strategy)
584
+ - ${ctx.runFolder}/artifacts/implementation-report.txt
585
+ - ${ctx.runFolder}/artifacts/test-implementation-report.txt
586
+ - ${ctx.runFolder}/artifacts/verification-report.txt
587
+
588
+ Task:
589
+ Review the implementation and tests against the workflow artifacts and produce ${ctx.runFolder}/artifacts/judge-report.txt (artifact: JudgeReport).
590
+
591
+ The JudgeReport must assess:
592
+ - implementation vs PseudocodePacket
593
+ - tests vs TestStrategyPacket
594
+ - behavior coverage
595
+ - architecture alignment
596
+ - scope control
597
+ - verification evidence
598
+ - risks and gaps
599
+ - trace link integrity (if trace IDs were used): check for orphan IDs, missing link targets,
600
+ and malformed IDs by running: my-dev-kit-orchestrator check --trace
601
+ Include trace check results or note that trace IDs were not used in this run.
602
+
603
+ Verdict must be one of:
604
+ PASS | DESIGN_INCOMPLETE | PSEUDOCODE_INCOMPLETE | IMPLEMENTATION_MISMATCH |
605
+ TEST_COVERAGE_INCOMPLETE | ARCHITECTURE_MISMATCH | NEED_CONTEXT | SCOPE_VIOLATION |
606
+ NEED_VERIFICATION | BLOCKED
607
+
608
+ Required output artifact: JudgeReport
609
+ Output file: ${ctx.runFolder}/artifacts/judge-report.txt
610
+
611
+ Stop conditions:
612
+ - do not rewrite code
613
+ - do not approve without verification evidence
614
+ - do not hide uncertainty or gaps
615
+ - do not skip trace check if trace IDs are present in prior artifacts
616
+
617
+ Return format:
618
+ Produce the artifact as a plain-text file.
619
+ Artifact: JudgeReport
620
+ Workflow mode: ...
621
+ Verdict: ...
622
+ Recommended next stage if not PASS: ...
623
+ Status: complete
624
+ `;
625
+ }
626
+ function finalReportPrompt(ctx) {
627
+ return `${header(ctx)}
628
+ Inputs:
629
+ - ${ctx.runFolder}/artifacts/judge-report.txt
630
+ - ${ctx.runFolder}/artifacts/verification-report.txt
631
+ - ${ctx.runFolder}/artifacts/request-brief.txt (or mode-specific entry artifact)
632
+ - major design and implementation artifacts
633
+
634
+ Task:
635
+ Summarize the completed workflow and produce ${ctx.runFolder}/artifacts/final-report.txt (artifact: FinalReport).
636
+
637
+ The FinalReport must include:
638
+ - original request
639
+ - workflow mode
640
+ - run ID: ${ctx.runId}
641
+ - stages completed
642
+ - behavior designed
643
+ - architecture context used
644
+ - pseudocode summary
645
+ - tests designed
646
+ - implementation summary
647
+ - tests added or updated
648
+ - verification summary
649
+ - judge verdict
650
+ - unresolved risks
651
+ - follow-up recommendations if needed
652
+
653
+ Required output artifact: FinalReport
654
+ Output file: ${ctx.runFolder}/artifacts/final-report.txt
655
+
656
+ Stop conditions:
657
+ - do not exaggerate success
658
+ - do not omit failed or skipped verification
659
+ - do not hide unresolved risks
660
+
661
+ Return format:
662
+ Produce the artifact as a plain-text file following the FinalReport template.
663
+ Artifact: FinalReport
664
+ Workflow mode: ...
665
+ Run ID: ...
666
+ [all required sections]
667
+ Status: complete
668
+ `;
669
+ }
670
+ // ─── Repair-specific stages ───────────────────────────────────────────────────
671
+ function observedBehaviorReportPrompt(ctx) {
672
+ return `${header(ctx)}
673
+ Inputs:
674
+ - original request / observed behavior description: ${ctx.runFolder}/00-request.txt
675
+
676
+ Task:
677
+ Produce ${ctx.runFolder}/artifacts/observed-behavior-report.txt (artifact: ObservedBehaviorReport).
678
+
679
+ Capture the wrong or unexpected behavior without jumping to code-level causes.
680
+
681
+ The ObservedBehaviorReport must define:
682
+ - observed behavior (verbatim or close description)
683
+ - expected behavior if known
684
+ - triggering action or system event
685
+ - visible output or runtime symptom
686
+ - affected workflow or area
687
+ - frequency or reproducibility
688
+ - evidence available
689
+ - uncertainty
690
+
691
+ Required output artifact: ObservedBehaviorReport
692
+ Output file: ${ctx.runFolder}/artifacts/observed-behavior-report.txt
693
+
694
+ Stop conditions:
695
+ - do not guess code-level causes yet
696
+ - do not write pseudocode
697
+ - do not write tests
698
+ - do not implement code
699
+
700
+ Return format:
701
+ Produce the artifact as a plain-text file following the ObservedBehaviorReport template.
702
+ Artifact: ObservedBehaviorReport
703
+ Observed behavior: ...
704
+ Expected behavior: ...
705
+ [all required sections]
706
+ Status: complete | incomplete | blocked
707
+ `;
708
+ }
709
+ function behaviorTracePrompt(ctx) {
710
+ return `${header(ctx)}
711
+ Inputs:
712
+ - ${ctx.runFolder}/artifacts/observed-behavior-report.txt
713
+ - ${ctx.runFolder}/artifacts/architecture-context-packet.txt
714
+
715
+ Task:
716
+ Produce ${ctx.runFolder}/artifacts/behavior-trace.txt (artifact: BehaviorTrace).
717
+
718
+ Connect the observed behavior to the intended behavior model or pseudocode path.
719
+
720
+ The BehaviorTrace must identify:
721
+ - observed behavior reference
722
+ - matched behavior artifact if available
723
+ - matched behavior rule
724
+ - matched pseudocode section if available
725
+ - expected data flow
726
+ - expected state flow
727
+ - expected output
728
+ - missing design artifact if no match found
729
+
730
+ Required output artifact: BehaviorTrace
731
+ Output file: ${ctx.runFolder}/artifacts/behavior-trace.txt
732
+
733
+ Stop conditions:
734
+ - do not modify code
735
+ - do not write tests
736
+ - do not implement fixes yet
737
+
738
+ Return format:
739
+ Artifact: BehaviorTrace
740
+ [all required sections]
741
+ Status: complete | incomplete | blocked
742
+ `;
743
+ }
744
+ function divergenceReportPrompt(ctx) {
745
+ return `${header(ctx)}
746
+ Inputs:
747
+ - ${ctx.runFolder}/artifacts/observed-behavior-report.txt
748
+ - ${ctx.runFolder}/artifacts/architecture-context-packet.txt
749
+ - ${ctx.runFolder}/artifacts/behavior-trace.txt
750
+
751
+ Task:
752
+ Produce ${ctx.runFolder}/artifacts/divergence-report.txt (artifact: DivergenceReport).
753
+
754
+ Identify the first point where actual behavior diverges from intended behavior.
755
+
756
+ The DivergenceReport must include:
757
+ - expected path
758
+ - actual path
759
+ - first divergence point
760
+ - affected layer
761
+ - evidence
762
+ - correction category (behavior design update / pseudocode update / implementation correction / test correction / external contract correction / runtime state ordering correction / artifact update)
763
+ - uncertainty
764
+
765
+ Required output artifact: DivergenceReport
766
+ Output file: ${ctx.runFolder}/artifacts/divergence-report.txt
767
+
768
+ Stop conditions:
769
+ - do not modify code
770
+ - do not implement fixes yet
771
+
772
+ Return format:
773
+ Artifact: DivergenceReport
774
+ [all required sections]
775
+ Status: complete | incomplete | blocked
776
+ `;
777
+ }
778
+ function correctionDesignPrompt(ctx) {
779
+ return `${header(ctx)}
780
+ Inputs:
781
+ - ${ctx.runFolder}/artifacts/observed-behavior-report.txt
782
+ - ${ctx.runFolder}/artifacts/behavior-trace.txt
783
+ - ${ctx.runFolder}/artifacts/divergence-report.txt
784
+ - ${ctx.runFolder}/artifacts/architecture-context-packet.txt
785
+
786
+ Task:
787
+ Produce ${ctx.runFolder}/artifacts/correction-design.txt (artifact: CorrectionDesign).
788
+
789
+ Define how the system should be corrected before implementation.
790
+
791
+ The CorrectionDesign must include:
792
+ - correction goal
793
+ - artifact to update if any
794
+ - code behavior to change
795
+ - tests to add or update
796
+ - acceptance criteria
797
+ - risks
798
+
799
+ Required output artifact: CorrectionDesign
800
+ Output file: ${ctx.runFolder}/artifacts/correction-design.txt
801
+
802
+ Stop conditions:
803
+ - do not implement code in this stage
804
+ - do not write test files
805
+
806
+ Return format:
807
+ Artifact: CorrectionDesign
808
+ [all required sections]
809
+ Status: complete | incomplete | blocked
810
+ `;
811
+ }
812
+ function regressionTestStrategyPrompt(ctx) {
813
+ return `${header(ctx)}
814
+ Inputs:
815
+ - ${ctx.runFolder}/artifacts/divergence-report.txt
816
+ - ${ctx.runFolder}/artifacts/correction-design.txt
817
+ - ${ctx.runFolder}/artifacts/architecture-context-packet.txt
818
+
819
+ Task:
820
+ Produce ${ctx.runFolder}/artifacts/regression-test-strategy.txt (artifact: RegressionTestStrategy).
821
+
822
+ Define tests that prove the observed divergence cannot recur and cover related behavior.
823
+
824
+ The RegressionTestStrategy must include:
825
+ - divergence being protected against
826
+ - behavior or pseudocode rule being protected
827
+ - regression test responsibilities
828
+ - related boundary or transition coverage
829
+ - verification commands
830
+
831
+ Each test responsibility must trace to behavior, invariant, transition, derived value, boundary, contract, or failure mode.
832
+ Do not write test files in this stage.
833
+
834
+ Required output artifact: RegressionTestStrategy
835
+ Output file: ${ctx.runFolder}/artifacts/regression-test-strategy.txt
836
+
837
+ Stop conditions:
838
+ - do not write test files in this stage
839
+ - do not implement code
840
+
841
+ Return format:
842
+ Artifact: RegressionTestStrategy
843
+ [all required sections]
844
+ Status: complete | incomplete | blocked
845
+ `;
846
+ }
847
+ // ─── Test-mode-specific stages ────────────────────────────────────────────────
848
+ function testTargetBriefPrompt(ctx) {
849
+ return `${header(ctx)}
850
+ Inputs:
851
+ - original test target description: ${ctx.runFolder}/00-request.txt
852
+
853
+ Task:
854
+ Produce ${ctx.runFolder}/artifacts/test-target-brief.txt (artifact: TestTargetBrief).
855
+
856
+ Define the target of this test-design or test-implementation run.
857
+
858
+ The TestTargetBrief must include:
859
+ - test target
860
+ - target behavior or workflow
861
+ - whether code changes are allowed
862
+ - desired test depth
863
+ - constraints
864
+ - success criteria
865
+
866
+ Required output artifact: TestTargetBrief
867
+ Output file: ${ctx.runFolder}/artifacts/test-target-brief.txt
868
+
869
+ Stop conditions:
870
+ - do not write test files yet
871
+ - do not implement code
872
+ - do not write pseudocode
873
+
874
+ Return format:
875
+ Artifact: TestTargetBrief
876
+ [all required sections]
877
+ Status: complete | incomplete | blocked
878
+ `;
879
+ }
880
+ function behaviorReconstructionPrompt(ctx) {
881
+ return `${header(ctx)}
882
+ Inputs:
883
+ - ${ctx.runFolder}/artifacts/test-target-brief.txt
884
+ - ${ctx.runFolder}/artifacts/architecture-context-packet.txt
885
+
886
+ Task:
887
+ Produce ${ctx.runFolder}/artifacts/behavior-reconstruction.txt (artifact: BehaviorReconstruction).
888
+
889
+ Reconstruct behavior for the target feature when no BehaviorModel exists yet.
890
+
891
+ The BehaviorReconstruction must include:
892
+ - observed existing behavior
893
+ - current architecture evidence
894
+ - state variables
895
+ - events
896
+ - derived values
897
+ - invariants
898
+ - external contracts
899
+ - uncertainty
900
+
901
+ Required output artifact: BehaviorReconstruction
902
+ Output file: ${ctx.runFolder}/artifacts/behavior-reconstruction.txt
903
+
904
+ Stop conditions:
905
+ - do not write test files
906
+ - do not implement code
907
+
908
+ Return format:
909
+ Artifact: BehaviorReconstruction
910
+ [all required sections]
911
+ Status: complete | incomplete | blocked
912
+ `;
913
+ }
914
+ function pseudocodeSummaryPrompt(ctx) {
915
+ return `${header(ctx)}
916
+ Inputs:
917
+ - ${ctx.runFolder}/artifacts/test-target-brief.txt
918
+ - ${ctx.runFolder}/artifacts/architecture-context-packet.txt
919
+ - ${ctx.runFolder}/artifacts/behavior-reconstruction.txt
920
+
921
+ Task:
922
+ Produce ${ctx.runFolder}/artifacts/pseudocode-summary.txt (artifact: PseudocodeSummary).
923
+
924
+ Summarize existing implementation behavior in pseudocode form when no full PseudocodePacket exists.
925
+
926
+ The PseudocodeSummary must include:
927
+ - implementation-neutral behavior summary
928
+ - data flow
929
+ - state flow
930
+ - derived values
931
+ - validation rules
932
+ - error or empty state handling
933
+ - uncertainty
934
+
935
+ Required output artifact: PseudocodeSummary
936
+ Output file: ${ctx.runFolder}/artifacts/pseudocode-summary.txt
937
+
938
+ Stop conditions:
939
+ - do not write test files
940
+ - do not implement code
941
+
942
+ Return format:
943
+ Artifact: PseudocodeSummary
944
+ [all required sections]
945
+ Status: complete | incomplete | blocked
946
+ `;
947
+ }
948
+ // ─── Refactor-mode-specific stages ───────────────────────────────────────────
949
+ function refactorBriefPrompt(ctx) {
950
+ return `${header(ctx)}
951
+ Inputs:
952
+ - original refactor goal: ${ctx.runFolder}/00-request.txt
953
+
954
+ Task:
955
+ Produce ${ctx.runFolder}/artifacts/refactor-brief.txt (artifact: RefactorBrief).
956
+
957
+ Define the intended code-structure change and behavior-preservation requirement.
958
+
959
+ The RefactorBrief must include:
960
+ - refactor goal
961
+ - behavior that must remain unchanged
962
+ - target area
963
+ - constraints
964
+ - non-goals
965
+ - success criteria
966
+
967
+ Required output artifact: RefactorBrief
968
+ Output file: ${ctx.runFolder}/artifacts/refactor-brief.txt
969
+
970
+ Stop conditions:
971
+ - do not inspect code deeply
972
+ - do not write pseudocode
973
+ - do not implement code
974
+ - do not write tests
975
+
976
+ Return format:
977
+ Artifact: RefactorBrief
978
+ [all required sections]
979
+ Status: complete | incomplete | blocked
980
+ `;
981
+ }
982
+ function existingBehaviorMapPrompt(ctx) {
983
+ return `${header(ctx)}
984
+ Inputs:
985
+ - ${ctx.runFolder}/artifacts/refactor-brief.txt
986
+ - ${ctx.runFolder}/artifacts/architecture-context-packet.txt
987
+
988
+ Task:
989
+ Produce ${ctx.runFolder}/artifacts/existing-behavior-map.txt (artifact: ExistingBehaviorMap).
990
+
991
+ Map the behavior that must remain stable during the refactor.
992
+
993
+ The ExistingBehaviorMap must include:
994
+ - current behaviors
995
+ - state variables
996
+ - events
997
+ - derived values
998
+ - invariants
999
+ - external contracts
1000
+ - existing tests
1001
+ - behavior gaps
1002
+
1003
+ Required output artifact: ExistingBehaviorMap
1004
+ Output file: ${ctx.runFolder}/artifacts/existing-behavior-map.txt
1005
+
1006
+ Stop conditions:
1007
+ - do not implement code
1008
+ - do not write tests
1009
+ - do not write pseudocode
1010
+
1011
+ Return format:
1012
+ Artifact: ExistingBehaviorMap
1013
+ [all required sections]
1014
+ Status: complete | incomplete | blocked
1015
+ `;
1016
+ }
1017
+ function preservedInvariantListPrompt(ctx) {
1018
+ return `${header(ctx)}
1019
+ Inputs:
1020
+ - ${ctx.runFolder}/artifacts/refactor-brief.txt
1021
+ - ${ctx.runFolder}/artifacts/existing-behavior-map.txt
1022
+
1023
+ Task:
1024
+ Produce ${ctx.runFolder}/artifacts/preserved-invariant-list.txt (artifact: PreservedInvariantList).
1025
+
1026
+ Define what must remain true after the refactor.
1027
+
1028
+ The PreservedInvariantList must include:
1029
+ - invariants to preserve
1030
+ - affected code areas
1031
+ - tests protecting each invariant
1032
+ - missing tests
1033
+
1034
+ Required output artifact: PreservedInvariantList
1035
+ Output file: ${ctx.runFolder}/artifacts/preserved-invariant-list.txt
1036
+
1037
+ Stop conditions:
1038
+ - do not implement code
1039
+ - do not write test files yet
1040
+
1041
+ Return format:
1042
+ Artifact: PreservedInvariantList
1043
+ [all required sections]
1044
+ Status: complete | incomplete | blocked
1045
+ `;
1046
+ }
1047
+ function compatibilityTestStrategyPrompt(ctx) {
1048
+ return `${header(ctx)}
1049
+ Inputs:
1050
+ - ${ctx.runFolder}/artifacts/existing-behavior-map.txt
1051
+ - ${ctx.runFolder}/artifacts/preserved-invariant-list.txt
1052
+ - ${ctx.runFolder}/artifacts/architecture-context-packet.txt
1053
+
1054
+ Task:
1055
+ Produce ${ctx.runFolder}/artifacts/compatibility-test-strategy.txt (artifact: CompatibilityTestStrategy).
1056
+
1057
+ Define tests that prove the refactor preserved behavior.
1058
+
1059
+ The CompatibilityTestStrategy must include:
1060
+ - preserved behavior
1061
+ - compatibility test responsibilities
1062
+ - existing tests to run
1063
+ - new tests needed
1064
+ - verification commands
1065
+
1066
+ Each test responsibility must trace to behavior, invariant, transition, derived value, boundary, contract, or failure mode.
1067
+ Do not write test files in this stage.
1068
+
1069
+ Required output artifact: CompatibilityTestStrategy
1070
+ Output file: ${ctx.runFolder}/artifacts/compatibility-test-strategy.txt
1071
+
1072
+ Stop conditions:
1073
+ - do not write test files in this stage
1074
+ - do not implement code
1075
+
1076
+ Return format:
1077
+ Artifact: CompatibilityTestStrategy
1078
+ [all required sections]
1079
+ Status: complete | incomplete | blocked
1080
+ `;
1081
+ }
1082
+ function refactorPseudocodePacketPrompt(ctx) {
1083
+ return `${header(ctx)}
1084
+ Inputs:
1085
+ - ${ctx.runFolder}/artifacts/refactor-brief.txt
1086
+ - ${ctx.runFolder}/artifacts/architecture-context-packet.txt
1087
+ - ${ctx.runFolder}/artifacts/existing-behavior-map.txt
1088
+ - ${ctx.runFolder}/artifacts/preserved-invariant-list.txt
1089
+ - ${ctx.runFolder}/artifacts/compatibility-test-strategy.txt
1090
+
1091
+ Task:
1092
+ Produce ${ctx.runFolder}/artifacts/refactor-pseudocode-packet.txt (artifact: RefactorPseudocodePacket).
1093
+
1094
+ Define the implementation-neutral design for the refactor. Preserve the behavior identified in ExistingBehaviorMap.
1095
+
1096
+ The RefactorPseudocodePacket must include:
1097
+ - target structure
1098
+ - data flow changes
1099
+ - invariants preserved
1100
+ - files allowed to change
1101
+ - component or module contracts
1102
+ - acceptance criteria
1103
+ - assumptions preserved
1104
+ - unresolved implementation questions
1105
+
1106
+ Required output artifact: RefactorPseudocodePacket
1107
+ Output file: ${ctx.runFolder}/artifacts/refactor-pseudocode-packet.txt
1108
+
1109
+ Stop conditions:
1110
+ - do not write production code
1111
+ - do not write test files
1112
+ - do not modify files
1113
+
1114
+ Return format:
1115
+ Artifact: RefactorPseudocodePacket
1116
+ [all required sections]
1117
+ Status: complete | incomplete | blocked
1118
+ `;
1119
+ }
1120
+ // ─── Harden-mode-specific stages ─────────────────────────────────────────────
1121
+ function hardeningBriefPrompt(ctx) {
1122
+ return `${header(ctx)}
1123
+ Inputs:
1124
+ - original hardening goal: ${ctx.runFolder}/00-request.txt
1125
+
1126
+ Task:
1127
+ Produce ${ctx.runFolder}/artifacts/hardening-brief.txt (artifact: HardeningBrief).
1128
+
1129
+ Define the robustness or failure-handling improvement requested.
1130
+
1131
+ The HardeningBrief must include:
1132
+ - hardening goal
1133
+ - target behavior or boundary
1134
+ - current risk
1135
+ - constraints
1136
+ - success criteria
1137
+
1138
+ Required output artifact: HardeningBrief
1139
+ Output file: ${ctx.runFolder}/artifacts/hardening-brief.txt
1140
+
1141
+ Stop conditions:
1142
+ - do not inspect code deeply
1143
+ - do not write pseudocode
1144
+ - do not implement code
1145
+ - do not write tests
1146
+
1147
+ Return format:
1148
+ Artifact: HardeningBrief
1149
+ [all required sections]
1150
+ Status: complete | incomplete | blocked
1151
+ `;
1152
+ }
1153
+ function assumptionReportPrompt(ctx) {
1154
+ return `${header(ctx)}
1155
+ Inputs:
1156
+ - ${ctx.runFolder}/artifacts/hardening-brief.txt
1157
+ - ${ctx.runFolder}/artifacts/architecture-context-packet.txt
1158
+
1159
+ Task:
1160
+ Produce ${ctx.runFolder}/artifacts/assumption-report.txt (artifact: AssumptionReport).
1161
+
1162
+ Identify assumptions currently made by the code or design.
1163
+
1164
+ For each assumption include:
1165
+ - assumption statement
1166
+ - source of assumption
1167
+ - where it is used
1168
+ - what breaks if false
1169
+ - decision (preserve / remove / validate / guard)
1170
+ - required follow-up
1171
+
1172
+ Required output artifact: AssumptionReport
1173
+ Output file: ${ctx.runFolder}/artifacts/assumption-report.txt
1174
+
1175
+ Stop conditions:
1176
+ - do not implement code
1177
+ - do not write tests
1178
+
1179
+ Return format:
1180
+ Artifact: AssumptionReport
1181
+ [all required sections]
1182
+ Status: complete | incomplete | blocked
1183
+ `;
1184
+ }
1185
+ function failureModeMatrixPrompt(ctx) {
1186
+ return `${header(ctx)}
1187
+ Inputs:
1188
+ - ${ctx.runFolder}/artifacts/hardening-brief.txt
1189
+ - ${ctx.runFolder}/artifacts/architecture-context-packet.txt
1190
+ - ${ctx.runFolder}/artifacts/assumption-report.txt
1191
+
1192
+ Task:
1193
+ Produce ${ctx.runFolder}/artifacts/failure-mode-matrix.txt (artifact: FailureModeMatrix).
1194
+
1195
+ Classify realistic ways the behavior can fail and decide how each should be handled.
1196
+
1197
+ For each failure mode include:
1198
+ - failure mode
1199
+ - category (input / state / contract / parser / storage / async / rendering / data volume / configuration / environment)
1200
+ - trigger
1201
+ - affected layer
1202
+ - current behavior
1203
+ - desired behavior
1204
+ - handling strategy (prevent / recover / surface to user / log / retry / ignore safely / fail fast)
1205
+ - required code change
1206
+ - required test
1207
+ - priority
1208
+
1209
+ Required output artifact: FailureModeMatrix
1210
+ Output file: ${ctx.runFolder}/artifacts/failure-mode-matrix.txt
1211
+
1212
+ Stop conditions:
1213
+ - do not implement code
1214
+ - do not write tests yet
1215
+
1216
+ Return format:
1217
+ Artifact: FailureModeMatrix
1218
+ [all required sections]
1219
+ Status: complete | incomplete | blocked
1220
+ `;
1221
+ }
1222
+ function guardPseudocodePacketPrompt(ctx) {
1223
+ return `${header(ctx)}
1224
+ Inputs:
1225
+ - ${ctx.runFolder}/artifacts/hardening-brief.txt
1226
+ - ${ctx.runFolder}/artifacts/architecture-context-packet.txt
1227
+ - ${ctx.runFolder}/artifacts/assumption-report.txt
1228
+ - ${ctx.runFolder}/artifacts/failure-mode-matrix.txt
1229
+
1230
+ Task:
1231
+ Produce ${ctx.runFolder}/artifacts/guard-pseudocode-packet.txt (artifact: GuardPseudocodePacket).
1232
+
1233
+ Define pseudocode for validation, guards, recovery paths, and error or empty states.
1234
+
1235
+ The GuardPseudocodePacket must include:
1236
+ - assumptions being guarded
1237
+ - failure modes handled
1238
+ - validation rules
1239
+ - guard rules
1240
+ - recovery behavior
1241
+ - error-state behavior
1242
+ - acceptance criteria
1243
+
1244
+ Required output artifact: GuardPseudocodePacket
1245
+ Output file: ${ctx.runFolder}/artifacts/guard-pseudocode-packet.txt
1246
+
1247
+ Stop conditions:
1248
+ - do not write production code
1249
+ - do not write test files
1250
+ - do not modify files
1251
+
1252
+ Return format:
1253
+ Artifact: GuardPseudocodePacket
1254
+ [all required sections]
1255
+ Status: complete | incomplete | blocked
1256
+ `;
1257
+ }
1258
+ function resilienceTestStrategyPrompt(ctx) {
1259
+ return `${header(ctx)}
1260
+ Inputs:
1261
+ - ${ctx.runFolder}/artifacts/assumption-report.txt
1262
+ - ${ctx.runFolder}/artifacts/failure-mode-matrix.txt
1263
+ - ${ctx.runFolder}/artifacts/guard-pseudocode-packet.txt
1264
+ - ${ctx.runFolder}/artifacts/architecture-context-packet.txt
1265
+
1266
+ Task:
1267
+ Produce ${ctx.runFolder}/artifacts/resilience-test-strategy.txt (artifact: ResilienceTestStrategy).
1268
+
1269
+ Define tests that verify hardening behavior.
1270
+
1271
+ The ResilienceTestStrategy must include:
1272
+ - assumptions tested
1273
+ - failure modes tested
1274
+ - validation tests
1275
+ - guard tests
1276
+ - recovery tests
1277
+ - error-state tests
1278
+ - verification commands
1279
+ - remaining risks
1280
+
1281
+ Each test responsibility must trace to assumption, failure mode, boundary, contract, or behavior.
1282
+ Do not write test files in this stage.
1283
+
1284
+ Required output artifact: ResilienceTestStrategy
1285
+ Output file: ${ctx.runFolder}/artifacts/resilience-test-strategy.txt
1286
+
1287
+ Stop conditions:
1288
+ - do not write test files in this stage
1289
+ - do not implement code
1290
+
1291
+ Return format:
1292
+ Artifact: ResilienceTestStrategy
1293
+ [all required sections]
1294
+ Status: complete | incomplete | blocked
1295
+ `;
1296
+ }
1297
+ // ─── Extraction-mode-specific stages ─────────────────────────────────────────
1298
+ function extractionRequestBriefPrompt(ctx) {
1299
+ const sourceDir = ctx.sourceRepoRoot ?? '<source-repo-root>';
1300
+ const targetDir = ctx.targetRepoRoot ?? '<target-repo-root>';
1301
+ return `${header(ctx)}
1302
+ Inputs:
1303
+ - original extraction request: ${ctx.runFolder}/00-request.txt
1304
+
1305
+ Task:
1306
+ Produce ${ctx.runFolder}/artifacts/request-brief.txt (artifact: ExtractionRequestBrief).
1307
+
1308
+ Extraction guardrails:
1309
+ - The source repository is evidence, not destiny. Do not port code just because it exists.
1310
+ - Do not start by copying files from source to target.
1311
+ - Do not assume the source architecture is the desired target architecture.
1312
+ - Do not implement anything in the target repository in this stage.
1313
+
1314
+ The ExtractionRequestBrief must define:
1315
+ - original request (verbatim from 00-request.txt)
1316
+ - source repository: ${sourceDir}
1317
+ - target repository: ${targetDir}
1318
+ - workflow or feature to extract
1319
+ - desired target scope (what should exist in the target when complete)
1320
+ - features explicitly excluded from the extraction
1321
+ - critical behaviors to preserve from the source workflow
1322
+ - expected deliverables
1323
+ - constraints
1324
+ - success criteria
1325
+ - ambiguity or missing information
1326
+ - expected next stage: source-architecture-context
1327
+
1328
+ Required output artifact: ExtractionRequestBrief
1329
+ Output file: ${ctx.runFolder}/artifacts/request-brief.txt
1330
+
1331
+ Stop conditions:
1332
+ - do not inspect source code deeply in this stage
1333
+ - do not write pseudocode
1334
+ - do not write tests
1335
+ - do not start implementing in this stage
1336
+ - do not port files
1337
+
1338
+ Return format:
1339
+ Produce the artifact as a plain-text file using this template:
1340
+ Artifact: ExtractionRequestBrief
1341
+ Workflow mode: extraction
1342
+ Original request: ...
1343
+ Source repository: ${sourceDir}
1344
+ Target repository: ${targetDir}
1345
+ Workflow or feature to extract: ...
1346
+ Desired target scope: ...
1347
+ Excluded features: ...
1348
+ Critical behaviors to preserve: ...
1349
+ Expected deliverables: ...
1350
+ Constraints: ...
1351
+ Success criteria: ...
1352
+ Ambiguity or missing information: ...
1353
+ Expected next stage: source-architecture-context
1354
+ Status: complete | incomplete | blocked
1355
+ `;
1356
+ }
1357
+ function sourceArchitectureContextPrompt(ctx) {
1358
+ const sourceDir = ctx.sourceRepoRoot ?? '<source-repo-root>';
1359
+ const targetDir = ctx.targetRepoRoot ?? '<target-repo-root>';
1360
+ return `${header(ctx)}
1361
+ Inputs:
1362
+ - ${ctx.runFolder}/artifacts/request-brief.txt
1363
+ - source repository: ${sourceDir}
1364
+
1365
+ Task:
1366
+ Use my-dev-kit to inspect the source repository and produce a supporting retrieval report and source architecture context artifact.
1367
+
1368
+ Produce two output files:
1369
+ 1. Supporting retrieval report: ${ctx.runFolder}/reports/source-architecture-context-retrieval-report.txt
1370
+ 2. Required workflow artifact: ${ctx.runFolder}/artifacts/source-architecture-context-packet.txt (artifact: SourceArchitectureContextPacket)
1371
+
1372
+ Extraction guardrails:
1373
+ - The source repository is evidence, not destiny. Do not port code just because it exists.
1374
+ - Do not start by reading whole source files.
1375
+ - Do not use target repository indexing to infer source behavior.
1376
+ - Do not modify the source repository.
1377
+ - Do not decide porting strategy in this stage.
1378
+ - Do not modify the target repository in this stage.
1379
+ - Source and target index directories must stay separate.
1380
+
1381
+ Source repository inspection sequence (when my-dev-kit is available):
1382
+
1383
+ Step 1 - Index the source repository into its own index directory:
1384
+ npx @dailephd/my-dev-kit index --root ${sourceDir} --src src --out ${sourceDir}/.my-dev-kit --call-graph --json
1385
+
1386
+ Do not use ${targetDir}/.my-dev-kit to infer source behavior.
1387
+
1388
+ Step 2 - Search for task-specific candidate nodes in the source repository:
1389
+ npx @dailephd/my-dev-kit search --index ${sourceDir}/.my-dev-kit --query "<task-specific term>" --limit 20 --json
1390
+ Run multiple queries for different aspects of the extraction request.
1391
+
1392
+ Step 3 - Look up selected nodes and their relationships:
1393
+ npx @dailephd/my-dev-kit lookup --index ${sourceDir}/.my-dev-kit --node "<selected-node-id>" --depth 1 --json
1394
+
1395
+ Step 4 - Slice around the strongest relevant node:
1396
+ npx @dailephd/my-dev-kit slice --index ${sourceDir}/.my-dev-kit --node "<strongest-node-id>" --depth 2 --direction both --json
1397
+
1398
+ Step 5 - Retrieve exact symbol source (preferred):
1399
+ npx @dailephd/my-dev-kit source --index ${sourceDir}/.my-dev-kit --node "<symbol-node-id>" --max-lines 160 --format numbered
1400
+
1401
+ Step 6 - Use line-range retrieval only as fallback when symbol retrieval is insufficient:
1402
+ npx @dailephd/my-dev-kit source --index ${sourceDir}/.my-dev-kit --file "<file-path>" --start <start-line> --end <end-line> --max-lines 220 --format numbered
1403
+
1404
+ Step 7 - Avoid reading whole source files unless bounded retrieval is insufficient. If a whole file must be read, state why.
1405
+
1406
+ If my-dev-kit is unavailable, use focused manual inspection of relevant files and symbols in the source repository. Document what was inspected and why.
1407
+
1408
+ The SourceArchitectureContextPacket must identify relevant source architecture context without deciding what to port.
1409
+
1410
+ Required output artifact: SourceArchitectureContextPacket
1411
+ Output file: ${ctx.runFolder}/artifacts/source-architecture-context-packet.txt
1412
+
1413
+ Supporting report output file: ${ctx.runFolder}/reports/source-architecture-context-retrieval-report.txt
1414
+
1415
+ Stop conditions:
1416
+ - do not decide porting strategy in this stage
1417
+ - do not write pseudocode
1418
+ - do not start implementing in this stage
1419
+ - do not write test files
1420
+ - do not modify source or target repositories
1421
+
1422
+ Return format:
1423
+
1424
+ Write the supporting retrieval report using this template:
1425
+
1426
+ Source retrieval evidence report
1427
+
1428
+ Source repository: ${sourceDir}
1429
+ Index directory: ${sourceDir}/.my-dev-kit
1430
+
1431
+ Refreshed or reused:
1432
+ manifest.json status:
1433
+ Semantic artifacts available:
1434
+
1435
+ Search queries run:
1436
+ - Query:
1437
+ Reason:
1438
+
1439
+ Candidate nodes selected:
1440
+ - Node ID:
1441
+ Reason:
1442
+
1443
+ Lookup commands run:
1444
+ - Node ID:
1445
+ Useful relationships found:
1446
+
1447
+ Graph slices created:
1448
+ - Focus node:
1449
+ - Depth:
1450
+ - Direction:
1451
+ - Reason:
1452
+
1453
+ Source symbols retrieved:
1454
+ - Symbol node ID:
1455
+ - File path:
1456
+ - Reason:
1457
+
1458
+ Full files read beyond retrieved source:
1459
+ - File path or none:
1460
+ - Reason:
1461
+
1462
+ Context gaps or uncertainty:
1463
+ - Gap:
1464
+ Impact:
1465
+
1466
+ Then write SourceArchitectureContextPacket using this template:
1467
+
1468
+ Artifact: SourceArchitectureContextPacket
1469
+ Workflow mode: extraction
1470
+ Source repository: ${sourceDir}
1471
+
1472
+ Relevant source files: ...
1473
+ Relevant source symbols: ...
1474
+ Relevant source components / modules / routes / services: ...
1475
+ Source data contracts: ...
1476
+ Source persistence dependencies: ...
1477
+ Source external service dependencies: ...
1478
+ Source state owners: ...
1479
+ Source tests found: ...
1480
+ Source patterns: ...
1481
+ Context gaps or uncertainty: ...
1482
+ Expected next stage: source-workflow-map
1483
+ Status: complete | incomplete | blocked
1484
+ `;
1485
+ }
1486
+ function sourceWorkflowMapPrompt(ctx) {
1487
+ const sourceDir = ctx.sourceRepoRoot ?? '<source-repo-root>';
1488
+ return `${header(ctx)}
1489
+ Inputs:
1490
+ - ${ctx.runFolder}/artifacts/request-brief.txt
1491
+ - ${ctx.runFolder}/artifacts/source-architecture-context-packet.txt
1492
+ - source repository (read-only evidence): ${sourceDir}
1493
+
1494
+ Task:
1495
+ Produce ${ctx.runFolder}/artifacts/source-workflow-map.txt (artifact: SourceWorkflowMap).
1496
+
1497
+ This stage describes what exists in the source repository. It does not decide what to port.
1498
+
1499
+ Extraction guardrails:
1500
+ - The source repository is evidence, not destiny. Do not port code just because it exists.
1501
+ - Do not decide porting strategy in this stage.
1502
+ - Do not start by copying files.
1503
+ - Do not modify the source repository.
1504
+ - Do not modify the target repository in this stage.
1505
+ - do not start implementing in this stage.
1506
+
1507
+ Required sections for SourceWorkflowMap:
1508
+ - Source repo path
1509
+ - Workflow entry point
1510
+ - User-facing steps
1511
+ - Frontend components
1512
+ - Frontend state owners
1513
+ - API routes
1514
+ - Backend services
1515
+ - Data contracts
1516
+ - Persistence dependencies
1517
+ - External service dependencies
1518
+ - Tests found
1519
+ - Known behavior risks
1520
+ - Ambiguous or missing context
1521
+
1522
+ Required output artifact: SourceWorkflowMap
1523
+ Output file: ${ctx.runFolder}/artifacts/source-workflow-map.txt
1524
+
1525
+ Stop conditions:
1526
+ - do not include porting decisions
1527
+ - do not include implementation plans
1528
+ - do not include target architecture details
1529
+ - do not write pseudocode
1530
+ - do not implement code
1531
+ - do not write test files
1532
+ - completion criteria: all required sections are present; the map describes what exists in the source, not what should be built in the target
1533
+
1534
+ Return format:
1535
+ Produce the artifact as a plain-text file using this template:
1536
+
1537
+ Artifact: SourceWorkflowMap
1538
+ Workflow mode: extraction
1539
+ Source repo path: ${sourceDir}
1540
+ Workflow entry point: <entry point file or component>
1541
+
1542
+ User-facing steps:
1543
+ 1. <step>
1544
+ 2. <step>
1545
+
1546
+ Frontend components: <list>
1547
+ Frontend state owners: <list>
1548
+
1549
+ API routes: <list>
1550
+ Backend services: <list>
1551
+ Data contracts: <list>
1552
+
1553
+ Persistence dependencies: <list>
1554
+ External service dependencies: <list>
1555
+
1556
+ Tests found: <list>
1557
+
1558
+ Known behavior risks:
1559
+ - <risk>
1560
+
1561
+ Ambiguous or missing context:
1562
+ - <gap>
1563
+
1564
+ Status: complete | incomplete | blocked
1565
+ `;
1566
+ }
1567
+ function portingMapPrompt(ctx) {
1568
+ const sourceDir = ctx.sourceRepoRoot ?? '<source-repo-root>';
1569
+ const targetDir = ctx.targetRepoRoot ?? '<target-repo-root>';
1570
+ return `${header(ctx)}
1571
+ Inputs:
1572
+ - ${ctx.runFolder}/artifacts/request-brief.txt
1573
+ - ${ctx.runFolder}/artifacts/source-architecture-context-packet.txt
1574
+ - ${ctx.runFolder}/artifacts/source-workflow-map.txt
1575
+
1576
+ Task:
1577
+ Produce TWO output files:
1578
+ 1. ${ctx.runFolder}/artifacts/source-to-target-porting-map.txt (artifact: SourceToTargetPortingMap)
1579
+ 2. ${ctx.runFolder}/artifacts/do-not-port-list.txt (artifact: DoNotPortList)
1580
+
1581
+ Classify each source subsystem as: port as-is, port with refactor, rewrite cleanly, discard, or postpone.
1582
+ Explicitly list every source system that must not be ported.
1583
+
1584
+ Extraction guardrails:
1585
+ - The source repository is evidence, not destiny. Do not port code just because it exists.
1586
+ - Do not create a second copy of the old architecture inside the target project.
1587
+ - Do not port authentication, persistence, workspaces, database schema, background jobs, or downstream workflows unless explicitly in scope.
1588
+ - Do not preserve old UI labels if they conflict with the new workflow.
1589
+ - do not start implementing in this stage.
1590
+ - Do not modify source or target repositories.
1591
+
1592
+ SourceToTargetPortingMap required structure for each item:
1593
+ - Source behavior
1594
+ - Source files or symbols
1595
+ - Target behavior
1596
+ - Target module or component (planned target location in ${targetDir})
1597
+ - Decision: port as-is | port with refactor | rewrite cleanly | discard | postpone
1598
+ - Reason
1599
+ - Required tests
1600
+ - Risks
1601
+
1602
+ DoNotPortList required sections:
1603
+ - Systems excluded from the target project
1604
+ - UI labels excluded from the target project
1605
+ - Backend routes excluded from the target project
1606
+ - Persistence layers excluded from the target project
1607
+ - Downstream workflows excluded from the target project
1608
+ - Reason each exclusion exists
1609
+ - Consequences if accidentally ported
1610
+
1611
+ Completion criteria:
1612
+ - Every significant source subsystem has a documented decision in SourceToTargetPortingMap
1613
+ - Every discarded subsystem also appears in DoNotPortList
1614
+ - Both artifact files must be present before the next stage can proceed
1615
+
1616
+ Required output artifact: SourceToTargetPortingMap
1617
+ Output file: ${ctx.runFolder}/artifacts/source-to-target-porting-map.txt
1618
+
1619
+ Required output artifact: DoNotPortList
1620
+ Output file: ${ctx.runFolder}/artifacts/do-not-port-list.txt
1621
+
1622
+ Stop conditions:
1623
+ - do not include implementation code
1624
+ - do not start implementing
1625
+ - do not write test files
1626
+ - do not modify source or target repositories
1627
+
1628
+ Return format:
1629
+ Produce both artifacts as plain-text files.
1630
+
1631
+ SourceToTargetPortingMap template:
1632
+
1633
+ Artifact: SourceToTargetPortingMap
1634
+ Workflow mode: extraction
1635
+ Source repository: ${sourceDir}
1636
+ Target repository: ${targetDir}
1637
+
1638
+ --- Item ---
1639
+ Source behavior: <description>
1640
+ Source files or symbols: <list>
1641
+ Target behavior: <description>
1642
+ Target module or component: <planned target location>
1643
+ Decision: <port as-is | port with refactor | rewrite cleanly | discard | postpone>
1644
+ Reason: <explanation>
1645
+ Required tests: <list>
1646
+ Risks: <list>
1647
+
1648
+ --- Item ---
1649
+ ...
1650
+
1651
+ Status: complete | incomplete | blocked
1652
+
1653
+ DoNotPortList template:
1654
+
1655
+ Artifact: DoNotPortList
1656
+ Workflow mode: extraction
1657
+ Source repository: ${sourceDir}
1658
+ Target repository: ${targetDir}
1659
+
1660
+ Systems excluded from the target project:
1661
+ - <system name>: <reason>
1662
+
1663
+ UI labels excluded:
1664
+ - <label>: <reason for exclusion>
1665
+
1666
+ Backend routes excluded:
1667
+ - <route>: <reason>
1668
+
1669
+ Persistence layers excluded:
1670
+ - <persistence layer>: <reason>
1671
+
1672
+ Downstream workflows excluded:
1673
+ - <workflow>: <reason>
1674
+
1675
+ Consequences if accidentally ported:
1676
+ - <consequence>
1677
+
1678
+ Status: complete | incomplete | blocked
1679
+ `;
1680
+ }
1681
+ function goldenBehaviorContractPrompt(ctx) {
1682
+ const targetDir = ctx.targetRepoRoot ?? '<target-repo-root>';
1683
+ return `${header(ctx)}
1684
+ Inputs:
1685
+ - ${ctx.runFolder}/artifacts/request-brief.txt
1686
+ - ${ctx.runFolder}/artifacts/source-workflow-map.txt
1687
+ - ${ctx.runFolder}/artifacts/source-to-target-porting-map.txt
1688
+ - ${ctx.runFolder}/artifacts/do-not-port-list.txt
1689
+
1690
+ Task:
1691
+ Produce ${ctx.runFolder}/artifacts/golden-behavior-contract.txt (artifact: GoldenBehaviorContract).
1692
+
1693
+ Define the exact behavior that the target implementation must satisfy.
1694
+ This is the primary source of truth for the target implementation and the judge stage.
1695
+ No production implementation should begin before this artifact exists.
1696
+
1697
+ Extraction guardrails:
1698
+ - Do not include source implementation details as requirements.
1699
+ - Do not include source file paths or source architecture references as requirements.
1700
+ - Do not reference source architecture as the target design.
1701
+ - do not start implementing in this stage.
1702
+ - Do not modify source or target repositories in this stage.
1703
+ - The source repository is evidence. This artifact defines what must be true in the target, not what exists in the source.
1704
+
1705
+ Required sections:
1706
+ - User-visible behavior
1707
+ - API behavior
1708
+ - State behavior
1709
+ - Sorting and ranking behavior
1710
+ - Pagination behavior
1711
+ - Selection behavior
1712
+ - Error and empty-state behavior
1713
+ - Edge cases
1714
+ - Non-negotiable regression tests
1715
+ - Acceptance criteria
1716
+
1717
+ For fragile or complex workflows, define specific testable statements. Examples:
1718
+ - Search results must be ordered by relevance descending.
1719
+ - Page-size options must be 10, 30, 50, and 100.
1720
+ - Pagination must use Previous, numbered pages, ellipsis, last page, and Next.
1721
+ - Selection must be stored by stable item ID, not page index.
1722
+ - Select all current page must select only visible page items.
1723
+ - Deselect all current page must deselect only visible page items.
1724
+ - Automatic mode must use top N valid ranked results, not the first N visible rows.
1725
+ - Manual mode must use only user-selected items.
1726
+ - Changing page size must preserve valid selections.
1727
+ - Out-of-range pages must be clamped.
1728
+
1729
+ Completion criteria:
1730
+ - Every user-visible behavior item is described precisely enough that a developer could implement it without reading the source repository.
1731
+ - Every non-negotiable regression test is listed.
1732
+
1733
+ Required output artifact: GoldenBehaviorContract
1734
+ Output file: ${ctx.runFolder}/artifacts/golden-behavior-contract.txt
1735
+
1736
+ Stop conditions:
1737
+ - do not write pseudocode
1738
+ - do not write test files
1739
+ - do not implement code
1740
+ - do not reference source architecture as the target design
1741
+
1742
+ Return format:
1743
+ Produce the artifact as a plain-text file using this template:
1744
+
1745
+ Artifact: GoldenBehaviorContract
1746
+ Workflow mode: extraction
1747
+ Target repository: ${targetDir}
1748
+
1749
+ User-visible behavior:
1750
+ 1. <behavior>
1751
+ 2. <behavior>
1752
+
1753
+ API behavior:
1754
+ - <endpoint>: <contract>
1755
+
1756
+ State behavior:
1757
+ - <state item>: <contract>
1758
+
1759
+ Sorting and ranking behavior:
1760
+ - <rule>
1761
+
1762
+ Pagination behavior:
1763
+ - <rule>
1764
+
1765
+ Selection behavior:
1766
+ - <rule>
1767
+
1768
+ Error and empty-state behavior:
1769
+ - <case>: <expected result>
1770
+
1771
+ Edge cases:
1772
+ - <case>: <expected result>
1773
+
1774
+ Non-negotiable regression tests:
1775
+ 1. <test description>
1776
+ 2. <test description>
1777
+
1778
+ Acceptance criteria:
1779
+ - <criterion>
1780
+
1781
+ Status: complete | incomplete | blocked
1782
+ `;
1783
+ }
1784
+ function targetArchitecturePrompt(ctx) {
1785
+ const sourceDir = ctx.sourceRepoRoot ?? '<source-repo-root>';
1786
+ const targetDir = ctx.targetRepoRoot ?? '<target-repo-root>';
1787
+ return `${header(ctx)}
1788
+ Inputs:
1789
+ - ${ctx.runFolder}/artifacts/request-brief.txt
1790
+ - ${ctx.runFolder}/artifacts/source-to-target-porting-map.txt
1791
+ - ${ctx.runFolder}/artifacts/do-not-port-list.txt
1792
+ - ${ctx.runFolder}/artifacts/golden-behavior-contract.txt
1793
+
1794
+ Task:
1795
+ Produce ${ctx.runFolder}/artifacts/target-architecture-proposal.txt (artifact: TargetArchitectureProposal).
1796
+
1797
+ Describe the clean target architecture before implementation begins.
1798
+
1799
+ Extraction guardrails:
1800
+ - Do not carry source implementation details forward without an explicit porting decision.
1801
+ - Do not include any architecture items from the DoNotPortList.
1802
+ - do not start implementing in this stage.
1803
+ - The proposal must be sufficient for implementation to begin without consulting the source repository again.
1804
+ - Every item must map back to the SourceToTargetPortingMap or be a new target-side concern.
1805
+
1806
+ If the target repository already exists, use my-dev-kit to inspect it separately from the source repository:
1807
+ npx @dailephd/my-dev-kit index --root ${targetDir} --src src --out ${targetDir}/.my-dev-kit --call-graph --json
1808
+ npx @dailephd/my-dev-kit search --index ${targetDir}/.my-dev-kit --query "<task term>" --limit 20 --json
1809
+
1810
+ Do not mix source (${sourceDir}/.my-dev-kit) and target (${targetDir}/.my-dev-kit) retrieval results.
1811
+
1812
+ If the target repository does not exist yet, define the planned structure and contracts before any scaffolding begins.
1813
+
1814
+ Required sections:
1815
+ - Target repo path
1816
+ - Target project purpose
1817
+ - Target workflow
1818
+ - Frontend components
1819
+ - Backend services
1820
+ - API routes
1821
+ - Shared contracts
1822
+ - State ownership
1823
+ - Persistence policy
1824
+ - External dependencies
1825
+ - Testing strategy overview
1826
+ - Source components reused
1827
+ - Source components rewritten
1828
+ - Source components discarded
1829
+ - Architecture guardrails
1830
+
1831
+ Required output artifact: TargetArchitectureProposal
1832
+ Output file: ${ctx.runFolder}/artifacts/target-architecture-proposal.txt
1833
+
1834
+ Stop conditions:
1835
+ - do not write production code
1836
+ - do not write test files
1837
+ - do not include items from DoNotPortList
1838
+ - do not reference source implementation without a porting decision
1839
+
1840
+ Return format:
1841
+ Produce the artifact as a plain-text file using this template:
1842
+
1843
+ Artifact: TargetArchitectureProposal
1844
+ Workflow mode: extraction
1845
+ Target repo path: ${targetDir}
1846
+ Target project purpose: <description>
1847
+
1848
+ Target workflow:
1849
+ 1. <step>
1850
+ 2. <step>
1851
+
1852
+ Frontend components: <list>
1853
+ Backend services: <list>
1854
+ API routes: <list>
1855
+ Shared contracts: <list>
1856
+
1857
+ State ownership:
1858
+ - <state>: owned by <component>
1859
+
1860
+ Persistence policy: <description>
1861
+ External dependencies: <list>
1862
+
1863
+ Testing strategy overview: <description>
1864
+
1865
+ Source components reused: <list>
1866
+ Source components rewritten: <list>
1867
+ Source components discarded: <list>
1868
+
1869
+ Architecture guardrails:
1870
+ - <guardrail>
1871
+
1872
+ Status: complete | incomplete | blocked
1873
+ `;
1874
+ }
1875
+ function extractionBehaviorModelPrompt(ctx) {
1876
+ const targetDir = ctx.targetRepoRoot ?? '<target-repo-root>';
1877
+ return `${header(ctx)}
1878
+ Inputs:
1879
+ - ${ctx.runFolder}/artifacts/request-brief.txt
1880
+ - ${ctx.runFolder}/artifacts/golden-behavior-contract.txt
1881
+ - ${ctx.runFolder}/artifacts/target-architecture-proposal.txt
1882
+ - ${ctx.runFolder}/artifacts/source-to-target-porting-map.txt
1883
+
1884
+ Task:
1885
+ Produce ${ctx.runFolder}/artifacts/behavior-model.txt (artifact: BehaviorModel).
1886
+
1887
+ Use the GoldenBehaviorContract as the primary source of truth for the target behavior.
1888
+ Map behavior to the target system in ${targetDir}, not to the source architecture.
1889
+
1890
+ Extraction guardrails:
1891
+ - Do not use source implementation details as the behavior definition.
1892
+ - Do not port behavior not listed in the SourceToTargetPortingMap or GoldenBehaviorContract.
1893
+ - do not start implementing in this stage.
1894
+ - Do not write test files.
1895
+
1896
+ The BehaviorModel must define:
1897
+ - behavior summary (target system only)
1898
+ - externally visible behavior
1899
+ - internal supporting behavior
1900
+ - state variables
1901
+ - inputs
1902
+ - events
1903
+ - derived values
1904
+ - invariants
1905
+ - valid states
1906
+ - invalid states
1907
+ - boundaries and partitions
1908
+ - empty states
1909
+ - error states
1910
+ - loading or pending states when relevant
1911
+ - external contracts
1912
+ - state transitions
1913
+ - behavior from the GoldenBehaviorContract to preserve
1914
+ - behavior intentionally changed from source
1915
+ - unresolved design questions
1916
+
1917
+ Required output artifact: BehaviorModel
1918
+ Output file: ${ctx.runFolder}/artifacts/behavior-model.txt
1919
+
1920
+ Stop conditions:
1921
+ - do not write production code
1922
+ - do not write test files
1923
+ - do not produce source architecture in behavior descriptions
1924
+
1925
+ Return format:
1926
+ Produce the artifact as a plain-text file following the BehaviorModel template.
1927
+ Artifact: BehaviorModel
1928
+ Workflow mode: extraction
1929
+ Target repository: ${targetDir}
1930
+ Inputs used: ...
1931
+ Behavior summary: ...
1932
+ [all required sections]
1933
+ Status: complete | incomplete | blocked
1934
+ `;
1935
+ }
1936
+ function extractionPseudocodePacketPrompt(ctx) {
1937
+ const targetDir = ctx.targetRepoRoot ?? '<target-repo-root>';
1938
+ return `${header(ctx)}
1939
+ Inputs:
1940
+ - ${ctx.runFolder}/artifacts/request-brief.txt
1941
+ - ${ctx.runFolder}/artifacts/golden-behavior-contract.txt
1942
+ - ${ctx.runFolder}/artifacts/target-architecture-proposal.txt
1943
+ - ${ctx.runFolder}/artifacts/behavior-model.txt
1944
+
1945
+ Task:
1946
+ Produce ${ctx.runFolder}/artifacts/pseudocode-packet.txt (artifact: PseudocodePacket).
1947
+
1948
+ Convert the BehaviorModel into implementation-neutral pseudocode for the target system.
1949
+ Map to the target architecture in ${targetDir}, not to the source architecture.
1950
+ This is the shared design contract for both implementation and testing.
1951
+
1952
+ Extraction guardrails:
1953
+ - Do not copy source implementation code into this artifact.
1954
+ - Do not reference source module paths as the target module paths.
1955
+ - Do not port patterns from the DoNotPortList.
1956
+ - do not start implementing in this stage.
1957
+
1958
+ The PseudocodePacket must define:
1959
+ - behavior references (from GoldenBehaviorContract)
1960
+ - data flow
1961
+ - state flow
1962
+ - state transitions
1963
+ - derived-value rules
1964
+ - validation rules
1965
+ - empty-state handling
1966
+ - error-state handling
1967
+ - external contract handling
1968
+ - target component, module, service, route, command, or helper contracts
1969
+ - acceptance criteria
1970
+ - likely files or modules to create or modify in the target repository
1971
+ - implementation constraints
1972
+ - assumptions preserved
1973
+ - unresolved implementation questions
1974
+
1975
+ Required output artifact: PseudocodePacket
1976
+ Output file: ${ctx.runFolder}/artifacts/pseudocode-packet.txt
1977
+
1978
+ Stop conditions:
1979
+ - do not write production code
1980
+ - do not write test files
1981
+ - do not modify source or target repositories
1982
+
1983
+ Return format:
1984
+ Produce the artifact as a plain-text file following the PseudocodePacket template.
1985
+ Artifact: PseudocodePacket
1986
+ Workflow mode: extraction
1987
+ Target repository: ${targetDir}
1988
+ Inputs used: ...
1989
+ [all required sections]
1990
+ Status: complete | incomplete | blocked
1991
+ `;
1992
+ }
1993
+ function extractionTestStrategyPrompt(ctx) {
1994
+ const targetDir = ctx.targetRepoRoot ?? '<target-repo-root>';
1995
+ return `${header(ctx)}
1996
+ Inputs:
1997
+ - ${ctx.runFolder}/artifacts/request-brief.txt
1998
+ - ${ctx.runFolder}/artifacts/golden-behavior-contract.txt
1999
+ - ${ctx.runFolder}/artifacts/target-architecture-proposal.txt
2000
+ - ${ctx.runFolder}/artifacts/behavior-model.txt
2001
+ - ${ctx.runFolder}/artifacts/pseudocode-packet.txt
2002
+
2003
+ Task:
2004
+ Produce ${ctx.runFolder}/artifacts/test-strategy-packet.txt (artifact: TestStrategyPacket).
2005
+
2006
+ Derive test responsibilities from the GoldenBehaviorContract, BehaviorModel, and PseudocodePacket.
2007
+ All tests must target the target repository in ${targetDir}.
2008
+ Do not write test files in this stage.
2009
+
2010
+ Extraction guardrails:
2011
+ - Do not test source repository behavior.
2012
+ - Do not write test files in this stage.
2013
+ - Do not start implementing code.
2014
+
2015
+ The TestStrategyPacket must include:
2016
+ - contract tests (from GoldenBehaviorContract)
2017
+ - backend unit tests
2018
+ - frontend component tests
2019
+ - state behavior tests
2020
+ - integration tests
2021
+ - E2E tests for the full extracted workflow
2022
+ - regression tests for every non-negotiable item in the GoldenBehaviorContract
2023
+ - behavior under test
2024
+ - participating layers
2025
+ - state variables
2026
+ - events
2027
+ - derived values
2028
+ - invariants
2029
+ - boundaries and partitions
2030
+ - external contracts
2031
+ - relevant failure modes
2032
+ - test matrix
2033
+ - test level assignment (unit / component / integration / end-to-end)
2034
+ - required verification commands
2035
+ - coverage gaps
2036
+
2037
+ Each test responsibility must trace to at least one of:
2038
+ - golden behavior contract item
2039
+ - behavior
2040
+ - invariant
2041
+ - state transition
2042
+ - derived value
2043
+ - boundary
2044
+ - external contract
2045
+ - failure mode
2046
+
2047
+ Required output artifact: TestStrategyPacket
2048
+ Output file: ${ctx.runFolder}/artifacts/test-strategy-packet.txt
2049
+
2050
+ Stop conditions:
2051
+ - do not write test files in this stage
2052
+ - do not write production code
2053
+ - do not invent behavior not in GoldenBehaviorContract or BehaviorModel
2054
+
2055
+ Return format:
2056
+ Produce the artifact as a plain-text file following the TestStrategyPacket template.
2057
+ Artifact: TestStrategyPacket
2058
+ Workflow mode: extraction
2059
+ Target repository: ${targetDir}
2060
+ Inputs used: ...
2061
+ [all required sections]
2062
+ Status: complete | incomplete | blocked
2063
+ `;
2064
+ }
2065
+ function extractionImplementationPrompt(ctx) {
2066
+ const sourceDir = ctx.sourceRepoRoot ?? '<source-repo-root>';
2067
+ const targetDir = ctx.targetRepoRoot ?? '<target-repo-root>';
2068
+ return `${header(ctx)}
2069
+ Inputs:
2070
+ - ${ctx.runFolder}/artifacts/request-brief.txt
2071
+ - ${ctx.runFolder}/artifacts/golden-behavior-contract.txt
2072
+ - ${ctx.runFolder}/artifacts/target-architecture-proposal.txt
2073
+ - ${ctx.runFolder}/artifacts/source-to-target-porting-map.txt
2074
+ - ${ctx.runFolder}/artifacts/do-not-port-list.txt
2075
+ - ${ctx.runFolder}/artifacts/behavior-model.txt
2076
+ - ${ctx.runFolder}/artifacts/pseudocode-packet.txt
2077
+
2078
+ Task:
2079
+ Implement the extracted workflow in the target repository and produce ${ctx.runFolder}/artifacts/implementation-report.txt (artifact: ImplementationReport).
2080
+
2081
+ Implement in ${targetDir} only. The source repository (${sourceDir}) is read-only evidence.
2082
+ Use the GoldenBehaviorContract as the implementation source of truth.
2083
+ Follow the TargetArchitectureProposal and PseudocodePacket.
2084
+
2085
+ Extraction guardrails:
2086
+ - Implement only in the target repository (${targetDir}) unless source repository changes are explicitly permitted by the request brief.
2087
+ - Do not copy files directly from source to target.
2088
+ - Do not port systems listed in the DoNotPortList.
2089
+ - Do not import source repository modules into the target.
2090
+ - Do not assume source architecture is the required target architecture.
2091
+ - The GoldenBehaviorContract defines what must be true - not the source code.
2092
+
2093
+ The ImplementationReport must include:
2094
+ - files read (source and target)
2095
+ - files created or changed (target only)
2096
+ - behavior implemented (must map to GoldenBehaviorContract items)
2097
+ - pseudocode sections implemented
2098
+ - porting decisions applied (from SourceToTargetPortingMap)
2099
+ - systems excluded (from DoNotPortList)
2100
+ - deviations from the PseudocodePacket and reason for each
2101
+ - source repository changes made, if any (normally: none)
2102
+ - blockers encountered
2103
+ - unresolved risks
2104
+ - tests that should be run
2105
+ - notes for the test implementation stage
2106
+
2107
+ Required output artifact: ImplementationReport
2108
+ Output file: ${ctx.runFolder}/artifacts/implementation-report.txt
2109
+
2110
+ Stop conditions:
2111
+ - do not port DoNotPortList systems
2112
+ - do not modify the source repository unless explicitly allowed by the request brief
2113
+ - do not claim verification success without command evidence
2114
+ - do not broaden scope without reporting a blocker
2115
+
2116
+ Return format:
2117
+ Produce the artifact as a plain-text file following the ImplementationReport template.
2118
+ Artifact: ImplementationReport
2119
+ Workflow mode: extraction
2120
+ Source repository: ${sourceDir}
2121
+ Target repository: ${targetDir}
2122
+ Inputs used: ...
2123
+ [all required sections]
2124
+ Status: complete | incomplete | blocked
2125
+ `;
2126
+ }
2127
+ function extractionTestImplementationPrompt(ctx) {
2128
+ const targetDir = ctx.targetRepoRoot ?? '<target-repo-root>';
2129
+ return `${header(ctx)}
2130
+ Inputs:
2131
+ - ${ctx.runFolder}/artifacts/golden-behavior-contract.txt
2132
+ - ${ctx.runFolder}/artifacts/behavior-model.txt
2133
+ - ${ctx.runFolder}/artifacts/pseudocode-packet.txt
2134
+ - ${ctx.runFolder}/artifacts/test-strategy-packet.txt
2135
+ - ${ctx.runFolder}/artifacts/implementation-report.txt (if available)
2136
+
2137
+ Task:
2138
+ Add or update tests in the target repository and produce ${ctx.runFolder}/artifacts/test-implementation-report.txt (artifact: TestImplementationReport).
2139
+
2140
+ All test work must happen in ${targetDir}.
2141
+ Prioritize non-negotiable regression tests from the GoldenBehaviorContract.
2142
+ Follow the TestStrategyPacket. Do not invent a separate test strategy.
2143
+
2144
+ Extraction guardrails:
2145
+ - Add or update tests in the target repository only.
2146
+ - Do not add tests to the source repository.
2147
+ - Regression tests must cover every non-negotiable item in the GoldenBehaviorContract.
2148
+ - Do not claim tests passed unless command evidence is included.
2149
+
2150
+ The TestImplementationReport must include:
2151
+ - test files changed (target repository only)
2152
+ - tests added
2153
+ - tests updated
2154
+ - GoldenBehaviorContract items covered
2155
+ - behaviors covered
2156
+ - invariants covered
2157
+ - state transitions covered
2158
+ - derived values covered
2159
+ - boundaries covered
2160
+ - external contracts covered
2161
+ - failure modes covered
2162
+ - TestStrategyPacket items not implemented
2163
+ - reason for each missing test
2164
+ - verification commands to run
2165
+
2166
+ Required output artifact: TestImplementationReport
2167
+ Output file: ${ctx.runFolder}/artifacts/test-implementation-report.txt
2168
+
2169
+ Stop conditions:
2170
+ - do not replace the TestStrategyPacket with a new unrelated strategy
2171
+ - do not change production behavior unless reporting a blocker
2172
+ - do not add tests to the source repository
2173
+
2174
+ Return format:
2175
+ Produce the artifact as a plain-text file following the TestImplementationReport template.
2176
+ Artifact: TestImplementationReport
2177
+ Workflow mode: extraction
2178
+ Target repository: ${targetDir}
2179
+ [all required sections]
2180
+ Status: complete | incomplete | blocked
2181
+ `;
2182
+ }
2183
+ function extractionVerificationPrompt(ctx) {
2184
+ const targetDir = ctx.targetRepoRoot ?? '<target-repo-root>';
2185
+ return `${header(ctx)}
2186
+ Inputs:
2187
+ - ${ctx.runFolder}/artifacts/golden-behavior-contract.txt
2188
+ - ${ctx.runFolder}/artifacts/test-strategy-packet.txt
2189
+ - ${ctx.runFolder}/artifacts/implementation-report.txt
2190
+ - ${ctx.runFolder}/artifacts/test-implementation-report.txt
2191
+
2192
+ Task:
2193
+ Run validation commands in the target repository and produce ${ctx.runFolder}/artifacts/verification-report.txt (artifact: VerificationReport).
2194
+
2195
+ Run target project validation commands in ${targetDir}.
2196
+ Do not validate the source repository unless explicitly requested by the request brief.
2197
+
2198
+ Extraction guardrails:
2199
+ - Run all validation commands from inside the target repository.
2200
+ - Do not claim checks passed unless actual command output was produced.
2201
+ - Do not hide failed commands.
2202
+
2203
+ The VerificationReport must include:
2204
+ - commands run and working directory for each (should be ${targetDir})
2205
+ - exit codes
2206
+ - pass/fail status
2207
+ - output summary
2208
+ - failed tests if any
2209
+ - GoldenBehaviorContract items verified by tests
2210
+ - skipped checks
2211
+ - reason for skipped checks
2212
+ - environment notes if relevant
2213
+ - remaining verification gaps
2214
+
2215
+ Required output artifact: VerificationReport
2216
+ Output file: ${ctx.runFolder}/artifacts/verification-report.txt
2217
+
2218
+ Stop conditions:
2219
+ - do not claim checks passed unless command output was produced
2220
+ - do not hide failed commands
2221
+ - do not validate source repository unless explicitly requested
2222
+
2223
+ Return format:
2224
+ Produce the artifact as a plain-text file following the VerificationReport template.
2225
+ Artifact: VerificationReport
2226
+ Workflow mode: extraction
2227
+ Target repository: ${targetDir}
2228
+ [all required sections]
2229
+ Status: complete | incomplete | blocked
2230
+ `;
2231
+ }
2232
+ function extractionJudgePrompt(ctx) {
2233
+ const sourceDir = ctx.sourceRepoRoot ?? '<source-repo-root>';
2234
+ const targetDir = ctx.targetRepoRoot ?? '<target-repo-root>';
2235
+ return `${header(ctx)}
2236
+ Inputs:
2237
+ - ${ctx.runFolder}/artifacts/request-brief.txt
2238
+ - ${ctx.runFolder}/artifacts/source-workflow-map.txt
2239
+ - ${ctx.runFolder}/artifacts/source-to-target-porting-map.txt
2240
+ - ${ctx.runFolder}/artifacts/do-not-port-list.txt
2241
+ - ${ctx.runFolder}/artifacts/golden-behavior-contract.txt
2242
+ - ${ctx.runFolder}/artifacts/target-architecture-proposal.txt
2243
+ - ${ctx.runFolder}/artifacts/behavior-model.txt
2244
+ - ${ctx.runFolder}/artifacts/pseudocode-packet.txt
2245
+ - ${ctx.runFolder}/artifacts/test-strategy-packet.txt
2246
+ - ${ctx.runFolder}/artifacts/implementation-report.txt
2247
+ - ${ctx.runFolder}/artifacts/test-implementation-report.txt
2248
+ - ${ctx.runFolder}/artifacts/verification-report.txt
2249
+
2250
+ Task:
2251
+ Review the target implementation against all extraction artifacts and produce ${ctx.runFolder}/artifacts/judge-report.txt (artifact: JudgeReport).
2252
+
2253
+ Do not mark the run as passed unless the target implementation satisfies the GoldenBehaviorContract.
2254
+
2255
+ The JudgeReport must assess:
2256
+ - implementation vs GoldenBehaviorContract (primary gate)
2257
+ - implementation vs PseudocodePacket
2258
+ - implementation vs TargetArchitectureProposal
2259
+ - tests vs TestStrategyPacket
2260
+ - tests vs GoldenBehaviorContract non-negotiable regression tests
2261
+ - DoNotPortList compliance: no excluded systems were ported
2262
+ - SourceToTargetPortingMap decisions followed
2263
+ - source repository read-only compliance: was the source repository modified?
2264
+ - behavior coverage
2265
+ - verification evidence
2266
+ - scope control
2267
+ - risks and gaps
2268
+
2269
+ Verdict must be one of:
2270
+ PASS | DESIGN_INCOMPLETE | PSEUDOCODE_INCOMPLETE | IMPLEMENTATION_MISMATCH |
2271
+ TEST_COVERAGE_INCOMPLETE | ARCHITECTURE_MISMATCH | DO_NOT_PORT_VIOLATION |
2272
+ GOLDEN_CONTRACT_NOT_SATISFIED | NEED_VERIFICATION | SCOPE_VIOLATION | BLOCKED
2273
+
2274
+ Required output artifact: JudgeReport
2275
+ Output file: ${ctx.runFolder}/artifacts/judge-report.txt
2276
+
2277
+ Source repository: ${sourceDir}
2278
+ Target repository: ${targetDir}
2279
+
2280
+ Stop conditions:
2281
+ - do not rewrite code
2282
+ - do not approve without verification evidence
2283
+ - do not hide gaps in GoldenBehaviorContract coverage
2284
+
2285
+ Return format:
2286
+ Produce the artifact as a plain-text file.
2287
+ Artifact: JudgeReport
2288
+ Workflow mode: extraction
2289
+ Source repository: ${sourceDir}
2290
+ Target repository: ${targetDir}
2291
+ Verdict: ...
2292
+ GoldenBehaviorContract satisfied: yes | no | partial
2293
+ DoNotPortList compliant: yes | no
2294
+ Source repository modified: yes | no
2295
+ Recommended next stage if not PASS: ...
2296
+ Status: complete
2297
+ `;
2298
+ }
2299
+ function extractionFinalReportPrompt(ctx) {
2300
+ const sourceDir = ctx.sourceRepoRoot ?? '<source-repo-root>';
2301
+ const targetDir = ctx.targetRepoRoot ?? '<target-repo-root>';
2302
+ return `${header(ctx)}
2303
+ Inputs:
2304
+ - ${ctx.runFolder}/artifacts/request-brief.txt
2305
+ - ${ctx.runFolder}/artifacts/source-workflow-map.txt
2306
+ - ${ctx.runFolder}/artifacts/source-to-target-porting-map.txt
2307
+ - ${ctx.runFolder}/artifacts/do-not-port-list.txt
2308
+ - ${ctx.runFolder}/artifacts/golden-behavior-contract.txt
2309
+ - ${ctx.runFolder}/artifacts/target-architecture-proposal.txt
2310
+ - ${ctx.runFolder}/artifacts/behavior-model.txt
2311
+ - ${ctx.runFolder}/artifacts/pseudocode-packet.txt
2312
+ - ${ctx.runFolder}/artifacts/test-strategy-packet.txt
2313
+ - ${ctx.runFolder}/artifacts/implementation-report.txt
2314
+ - ${ctx.runFolder}/artifacts/test-implementation-report.txt
2315
+ - ${ctx.runFolder}/artifacts/verification-report.txt
2316
+ - ${ctx.runFolder}/artifacts/judge-report.txt
2317
+
2318
+ Task:
2319
+ Summarize the completed extraction workflow and produce ${ctx.runFolder}/artifacts/final-report.txt (artifact: FinalReport).
2320
+
2321
+ The FinalReport must include:
2322
+ - Mode: extraction
2323
+ - Run ID: ${ctx.runId}
2324
+ - Original extraction request
2325
+ - Source repository: ${sourceDir}
2326
+ - Target repository: ${targetDir}
2327
+ - Final status (judge verdict)
2328
+ - Source workflow map: ${ctx.runFolder}/artifacts/source-workflow-map.txt
2329
+ - Source-to-target porting map: ${ctx.runFolder}/artifacts/source-to-target-porting-map.txt
2330
+ - Do-not-port list: ${ctx.runFolder}/artifacts/do-not-port-list.txt
2331
+ - Golden behavior contract: ${ctx.runFolder}/artifacts/golden-behavior-contract.txt
2332
+ - Target architecture proposal: ${ctx.runFolder}/artifacts/target-architecture-proposal.txt
2333
+ - Source components reused
2334
+ - Source components rewritten
2335
+ - Source components discarded
2336
+ - Files changed in target repository
2337
+ - Files changed in source repository (normally: none)
2338
+ - Tests added or updated
2339
+ - Verification commands and results
2340
+ - Judge result
2341
+ - Remaining risks
2342
+ - Recommended next extraction or implementation step
2343
+
2344
+ Required output artifact: FinalReport
2345
+ Output file: ${ctx.runFolder}/artifacts/final-report.txt
2346
+
2347
+ Stop conditions:
2348
+ - do not exaggerate success
2349
+ - do not omit failed or skipped verification
2350
+ - do not hide unresolved risks
2351
+
2352
+ Return format:
2353
+ Produce the artifact as a plain-text file following the FinalReport template.
2354
+ Artifact: FinalReport
2355
+ Workflow mode: extraction
2356
+ Run ID: ${ctx.runId}
2357
+ Source repository: ${sourceDir}
2358
+ Target repository: ${targetDir}
2359
+ [all required sections]
2360
+ Status: complete
2361
+ `;
2362
+ }
2363
+ // ─── Stage router ─────────────────────────────────────────────────────────────
2364
+ function generateStagePrompt(meta, stageName) {
2365
+ const stageIndex = meta.stages.findIndex((s) => s.name === stageName);
2366
+ if (stageIndex === -1) {
2367
+ throw new Error(`Stage "${stageName}" not found in ${meta.mode} workflow`);
2368
+ }
2369
+ const ctx = {
2370
+ stage: stageName,
2371
+ mode: meta.mode,
2372
+ runId: meta.runId,
2373
+ projectRoot: meta.projectRoot,
2374
+ runFolder: meta.runFolder,
2375
+ stageNumber: stageIndex + 1,
2376
+ totalStages: meta.stages.length,
2377
+ sourceRepoRoot: meta.sourceRepoRoot,
2378
+ targetRepoRoot: meta.targetRepoRoot,
2379
+ };
2380
+ const isExtraction = meta.mode === 'extraction';
2381
+ switch (stageName) {
2382
+ // shared - non-extraction
2383
+ case 'architecture-context': return architectureContextPrompt(ctx);
2384
+ case 'verification': return isExtraction ? extractionVerificationPrompt(ctx) : verificationPrompt(ctx);
2385
+ case 'judge': return isExtraction ? extractionJudgePrompt(ctx) : judgePrompt(ctx);
2386
+ case 'final-report': return isExtraction ? extractionFinalReportPrompt(ctx) : finalReportPrompt(ctx);
2387
+ // shared stages with extraction-specific overrides
2388
+ case 'behavior-model': return isExtraction ? extractionBehaviorModelPrompt(ctx) : behaviorModelPrompt(ctx);
2389
+ case 'pseudocode-packet': return isExtraction ? extractionPseudocodePacketPrompt(ctx) : pseudocodePacketPrompt(ctx);
2390
+ case 'test-strategy': return isExtraction ? extractionTestStrategyPrompt(ctx) : testStrategyPrompt(ctx);
2391
+ case 'implementation': return isExtraction ? extractionImplementationPrompt(ctx) : implementationPrompt(ctx);
2392
+ case 'test-implementation': return isExtraction ? extractionTestImplementationPrompt(ctx) : testImplementationPrompt(ctx);
2393
+ // feature
2394
+ case 'request-brief': return isExtraction ? extractionRequestBriefPrompt(ctx) : requestBriefPrompt(ctx);
2395
+ // repair
2396
+ case 'observed-behavior-report': return observedBehaviorReportPrompt(ctx);
2397
+ case 'behavior-trace': return behaviorTracePrompt(ctx);
2398
+ case 'divergence-report': return divergenceReportPrompt(ctx);
2399
+ case 'correction-design': return correctionDesignPrompt(ctx);
2400
+ case 'regression-test-strategy': return regressionTestStrategyPrompt(ctx);
2401
+ // test
2402
+ case 'test-target-brief': return testTargetBriefPrompt(ctx);
2403
+ case 'behavior-reconstruction': return behaviorReconstructionPrompt(ctx);
2404
+ case 'pseudocode-summary': return pseudocodeSummaryPrompt(ctx);
2405
+ // refactor
2406
+ case 'refactor-brief': return refactorBriefPrompt(ctx);
2407
+ case 'existing-behavior-map': return existingBehaviorMapPrompt(ctx);
2408
+ case 'preserved-invariant-list': return preservedInvariantListPrompt(ctx);
2409
+ case 'compatibility-test-strategy': return compatibilityTestStrategyPrompt(ctx);
2410
+ case 'refactor-pseudocode-packet': return refactorPseudocodePacketPrompt(ctx);
2411
+ // harden
2412
+ case 'hardening-brief': return hardeningBriefPrompt(ctx);
2413
+ case 'assumption-report': return assumptionReportPrompt(ctx);
2414
+ case 'failure-mode-matrix': return failureModeMatrixPrompt(ctx);
2415
+ case 'guard-pseudocode-packet': return guardPseudocodePacketPrompt(ctx);
2416
+ case 'resilience-test-strategy': return resilienceTestStrategyPrompt(ctx);
2417
+ // extraction-specific
2418
+ case 'source-architecture-context': return sourceArchitectureContextPrompt(ctx);
2419
+ case 'source-workflow-map': return sourceWorkflowMapPrompt(ctx);
2420
+ case 'porting-map': return portingMapPrompt(ctx);
2421
+ case 'golden-behavior-contract': return goldenBehaviorContractPrompt(ctx);
2422
+ case 'target-architecture': return targetArchitecturePrompt(ctx);
2423
+ default:
2424
+ throw new Error(`No prompt generator for stage: "${stageName}"`);
2425
+ }
2426
+ }
2427
+ // Artifact files used as inputs for each correctable stage
2428
+ const CORRECTION_STAGE_INPUTS = {
2429
+ 'architecture-context': ['artifacts/request-brief.txt'],
2430
+ 'behavior-model': [
2431
+ 'artifacts/request-brief.txt',
2432
+ 'artifacts/architecture-context-packet.txt',
2433
+ ],
2434
+ 'pseudocode-packet': [
2435
+ 'artifacts/request-brief.txt',
2436
+ 'artifacts/architecture-context-packet.txt',
2437
+ 'artifacts/behavior-model.txt',
2438
+ ],
2439
+ 'test-strategy': [
2440
+ 'artifacts/behavior-model.txt',
2441
+ 'artifacts/pseudocode-packet.txt',
2442
+ ],
2443
+ 'test-implementation': [
2444
+ 'artifacts/behavior-model.txt',
2445
+ 'artifacts/pseudocode-packet.txt',
2446
+ 'artifacts/test-strategy-packet.txt',
2447
+ ],
2448
+ 'implementation': [
2449
+ 'artifacts/request-brief.txt',
2450
+ 'artifacts/architecture-context-packet.txt',
2451
+ 'artifacts/pseudocode-packet.txt',
2452
+ ],
2453
+ 'verification': [
2454
+ 'artifacts/implementation-report.txt',
2455
+ 'artifacts/test-implementation-report.txt',
2456
+ 'artifacts/test-strategy-packet.txt',
2457
+ ],
2458
+ };
2459
+ /**
2460
+ * Generates a bounded, stage-specific correction prompt.
2461
+ * The prompt instructs the coding agent to revise only the failed stage artifact
2462
+ * based on the judge report finding - without broadening scope, modifying code
2463
+ * automatically, or invoking any external runtime.
2464
+ */
2465
+ function generateCorrectionPrompt(meta, correctionState) {
2466
+ const routedStage = correctionState.routedStage;
2467
+ const verdict = correctionState.verdict ?? 'UNKNOWN';
2468
+ const runFolder = meta.runFolder;
2469
+ const priorInputs = CORRECTION_STAGE_INPUTS[routedStage] ?? [];
2470
+ const designMapPath = path.join(runFolder, 'artifacts', 'design-map.txt');
2471
+ const designMapExists = fs.existsSync(designMapPath);
2472
+ const inputLines = [
2473
+ `- ${runFolder}/artifacts/judge-report.txt`,
2474
+ ...priorInputs.map((f) => `- ${runFolder}/${f}`),
2475
+ ];
2476
+ if (designMapExists) {
2477
+ inputLines.push(`- ${runFolder}/artifacts/design-map.txt`);
2478
+ }
2479
+ const outputFile = path.join(runFolder, 'artifacts', stageToArtifactBasename(routedStage));
2480
+ const warningLines = correctionState.warnings.length > 0
2481
+ ? [`\nWarning from routing:\n${correctionState.warnings.map((w) => ` ${w}`).join('\n')}\n`]
2482
+ : [];
2483
+ return [
2484
+ `Stage: ${routedStage} (correction)`,
2485
+ `Workflow mode: ${meta.mode}`,
2486
+ `Run ID: ${meta.runId}`,
2487
+ `Project root: ${meta.projectRoot}`,
2488
+ `Run folder: ${runFolder}`,
2489
+ ``,
2490
+ `Correction context:`,
2491
+ ` Judge verdict: ${verdict}`,
2492
+ ` Routed correction stage: ${routedStage}`,
2493
+ ...(correctionState.recommendedStage
2494
+ ? [` Judge recommended: ${correctionState.recommendedStage}`]
2495
+ : []),
2496
+ ...warningLines,
2497
+ ``,
2498
+ `Inputs:`,
2499
+ ...inputLines,
2500
+ ``,
2501
+ `Task:`,
2502
+ `Revise the ${routedStage} artifact to resolve the judge finding.`,
2503
+ `Read the judge-report.txt to understand what was found insufficient.`,
2504
+ `Read the prior artifacts listed above to understand the current design state.`,
2505
+ `Produce an updated artifact that addresses the judge finding.`,
2506
+ ``,
2507
+ `Required output artifact: ${artifactKindForStage(routedStage)}`,
2508
+ `Output file: ${outputFile}`,
2509
+ ``,
2510
+ `Stop conditions:`,
2511
+ `- revise only the artifact for this stage`,
2512
+ `- do not modify production code unless this stage is implementation`,
2513
+ `- do not write test files unless this stage is test-strategy or test-implementation`,
2514
+ `- do not broaden scope beyond what the judge finding requires`,
2515
+ `- do not route back further unless the prior artifact is also found insufficient`,
2516
+ `- do not run any external agent, LLM call, or automated tool`,
2517
+ `- do not claim the issue is resolved without updating the artifact`,
2518
+ ``,
2519
+ `Return format:`,
2520
+ `Produce the updated artifact as a plain-text file.`,
2521
+ `Update the Status: field to complete when the correction is done.`,
2522
+ ``,
2523
+ ].join('\n');
2524
+ }
2525
+ function stageToArtifactBasename(stageName) {
2526
+ const map = {
2527
+ 'architecture-context': 'architecture-context-packet.txt',
2528
+ 'behavior-model': 'behavior-model.txt',
2529
+ 'pseudocode-packet': 'pseudocode-packet.txt',
2530
+ 'test-strategy': 'test-strategy-packet.txt',
2531
+ 'test-implementation': 'test-implementation-report.txt',
2532
+ 'implementation': 'implementation-report.txt',
2533
+ 'verification': 'verification-report.txt',
2534
+ };
2535
+ return map[stageName] ?? `${stageName}.txt`;
2536
+ }
2537
+ function artifactKindForStage(stageName) {
2538
+ const map = {
2539
+ 'architecture-context': 'ArchitectureContextPacket',
2540
+ 'behavior-model': 'BehaviorModel',
2541
+ 'pseudocode-packet': 'PseudocodePacket',
2542
+ 'test-strategy': 'TestStrategyPacket',
2543
+ 'test-implementation': 'TestImplementationReport',
2544
+ 'implementation': 'ImplementationReport',
2545
+ 'verification': 'VerificationReport',
2546
+ };
2547
+ return map[stageName] ?? stageName;
2548
+ }
2549
+ function writeStagePrompts(meta) {
2550
+ for (const stage of meta.stages) {
2551
+ const promptContent = generateStagePrompt(meta, stage.name);
2552
+ const promptPath = path.join(meta.runFolder, stage.promptFile);
2553
+ fs.writeFileSync(promptPath, promptContent, 'utf8');
2554
+ }
2555
+ }
2556
+ //# sourceMappingURL=promptGenerator.js.map