@bastani/atomic 0.9.16-alpha.7 → 0.9.16-alpha.9

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 (226) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/builtin/intercom/CHANGELOG.md +6 -0
  3. package/dist/builtin/intercom/README.md +4 -4
  4. package/dist/builtin/intercom/broker/broker.ts +617 -22
  5. package/dist/builtin/intercom/broker/client-message-validation.ts +9 -0
  6. package/dist/builtin/intercom/broker/client.ts +200 -10
  7. package/dist/builtin/intercom/broker/pending-send-registry.ts +4 -0
  8. package/dist/builtin/intercom/broker/send-handler.ts +90 -36
  9. package/dist/builtin/intercom/broker/send-signature.ts +20 -8
  10. package/dist/builtin/intercom/group.ts +85 -0
  11. package/dist/builtin/intercom/index.bundle.mjs +746 -55
  12. package/dist/builtin/intercom/package.json +1 -1
  13. package/dist/builtin/intercom/session-target.ts +54 -0
  14. package/dist/builtin/intercom/skills/intercom/SKILL.md +18 -3
  15. package/dist/builtin/intercom/source-ownership.ts +31 -0
  16. package/dist/builtin/intercom/types.ts +115 -0
  17. package/dist/builtin/mcp/index.bundle.mjs +175 -37
  18. package/dist/builtin/mcp/package.json +1 -1
  19. package/dist/builtin/subagents/package.json +1 -1
  20. package/dist/builtin/subagents/src/extension/index.bundle.mjs +239 -53
  21. package/dist/builtin/web-access/index.bundle.mjs +175 -37
  22. package/dist/builtin/web-access/package.json +1 -1
  23. package/dist/builtin/workflows/CHANGELOG.md +15 -0
  24. package/dist/builtin/workflows/README.md +40 -37
  25. package/dist/builtin/workflows/builtin/adversarial-verification.js +13 -0
  26. package/dist/builtin/workflows/builtin/{shared-prompts.ts → chunk-0x6e303p.js} +133 -154
  27. package/dist/builtin/workflows/builtin/chunk-17zk6ffd.js +69794 -0
  28. package/dist/builtin/workflows/builtin/chunk-29wrp38a.js +199 -0
  29. package/dist/builtin/workflows/builtin/chunk-2dqb5s2q.js +602 -0
  30. package/dist/builtin/workflows/builtin/chunk-4febxsv4.js +264 -0
  31. package/dist/builtin/workflows/builtin/chunk-5wgwscd0.js +4 -0
  32. package/dist/builtin/workflows/builtin/chunk-6fqs7c01.js +155 -0
  33. package/dist/builtin/workflows/builtin/chunk-7430zyas.js +126 -0
  34. package/dist/builtin/workflows/builtin/chunk-7at6dnkr.js +33 -0
  35. package/dist/builtin/workflows/builtin/chunk-82ha8p41.js +175 -0
  36. package/dist/builtin/workflows/builtin/chunk-8v8wmb7z.js +529 -0
  37. package/dist/builtin/workflows/builtin/chunk-bfkmzv9h.js +156 -0
  38. package/dist/builtin/workflows/builtin/chunk-c53y8bdh.js +345 -0
  39. package/dist/builtin/workflows/builtin/chunk-cg9tmks0.js +206 -0
  40. package/dist/builtin/workflows/builtin/chunk-h5e65g7g.js +1080 -0
  41. package/dist/builtin/workflows/builtin/chunk-hzzn6adg.js +221 -0
  42. package/dist/builtin/workflows/builtin/chunk-nqr34qp3.js +1061 -0
  43. package/dist/builtin/workflows/builtin/chunk-qe6bfpbd.js +1207 -0
  44. package/dist/builtin/workflows/builtin/chunk-qwzvgxnq.js +404 -0
  45. package/dist/builtin/workflows/builtin/chunk-qx2ptjs3.js +215 -0
  46. package/dist/builtin/workflows/builtin/chunk-rbnj9621.js +2447 -0
  47. package/dist/builtin/workflows/builtin/chunk-wpckd35c.js +12 -0
  48. package/dist/builtin/workflows/builtin/chunk-x2ghn0je.js +4110 -0
  49. package/dist/builtin/workflows/builtin/classify-and-act.js +12 -0
  50. package/dist/builtin/workflows/builtin/fan-out-and-synthesize.js +10 -0
  51. package/dist/builtin/workflows/builtin/generate-and-filter.js +12 -0
  52. package/dist/builtin/workflows/builtin/goal.js +16 -0
  53. package/dist/builtin/workflows/builtin/index.js +49 -0
  54. package/dist/builtin/workflows/builtin/loop-until-done.js +12 -0
  55. package/dist/builtin/workflows/builtin/open-claude-design.js +11 -0
  56. package/dist/builtin/workflows/builtin/ralph.js +16 -0
  57. package/dist/builtin/workflows/builtin/steering-context.d.ts +6 -0
  58. package/dist/builtin/workflows/builtin/steering-context.js +7 -0
  59. package/dist/builtin/workflows/builtin/tournament.js +13 -0
  60. package/dist/builtin/workflows/package.json +10 -7
  61. package/dist/builtin/workflows/src/authoring/typebox-defaults.d.ts +41 -0
  62. package/dist/builtin/workflows/src/extension/index.bundle.mjs +1294 -430
  63. package/dist/builtin/workflows/src/{index.bundle.mjs → index.js} +1022 -429
  64. package/dist/builtin/workflows/src/shared/authoring-contract-stage.d.ts +403 -0
  65. package/dist/builtin/workflows/src/shared/authoring-contract-ui.d.ts +327 -0
  66. package/dist/builtin/workflows/src/shared/budget.d.ts +67 -0
  67. package/dist/builtin/workflows/src/shared/workflow-authoring-types.d.ts +60 -0
  68. package/dist/builtin/workflows/src/shared/workflow-heartbeat-contract.d.ts +21 -0
  69. package/dist/core/agent-session-custom-message-commit.d.ts.map +1 -1
  70. package/dist/core/agent-session-custom-message-commit.js +12 -5
  71. package/dist/core/agent-session-custom-message-commit.js.map +1 -1
  72. package/dist/core/agent-session-persistent-custom-messages.d.ts.map +1 -1
  73. package/dist/core/agent-session-persistent-custom-messages.js +2 -0
  74. package/dist/core/agent-session-persistent-custom-messages.js.map +1 -1
  75. package/dist/core/agent-session.d.ts.map +1 -1
  76. package/dist/core/agent-session.js +2 -1
  77. package/dist/core/agent-session.js.map +1 -1
  78. package/dist/core/auth-storage.d.ts +2 -0
  79. package/dist/core/auth-storage.d.ts.map +1 -1
  80. package/dist/core/auth-storage.js +4 -0
  81. package/dist/core/auth-storage.js.map +1 -1
  82. package/dist/core/builtin-install-layout.d.ts +1 -1
  83. package/dist/core/builtin-install-layout.d.ts.map +1 -1
  84. package/dist/core/builtin-install-layout.js +1 -1
  85. package/dist/core/builtin-install-layout.js.map +1 -1
  86. package/dist/core/codex-fast-mode.d.ts +10 -7
  87. package/dist/core/codex-fast-mode.d.ts.map +1 -1
  88. package/dist/core/codex-fast-mode.js +31 -13
  89. package/dist/core/codex-fast-mode.js.map +1 -1
  90. package/dist/core/extensions/agent-events.d.ts +15 -0
  91. package/dist/core/extensions/agent-events.d.ts.map +1 -1
  92. package/dist/core/extensions/agent-events.js.map +1 -1
  93. package/dist/core/extensions/api-types.d.ts +3 -1
  94. package/dist/core/extensions/api-types.d.ts.map +1 -1
  95. package/dist/core/extensions/api-types.js.map +1 -1
  96. package/dist/core/extensions/context-types.d.ts +35 -0
  97. package/dist/core/extensions/context-types.d.ts.map +1 -1
  98. package/dist/core/extensions/context-types.js.map +1 -1
  99. package/dist/core/extensions/event-types.d.ts +2 -2
  100. package/dist/core/extensions/event-types.d.ts.map +1 -1
  101. package/dist/core/extensions/event-types.js.map +1 -1
  102. package/dist/core/extensions/index.d.ts +1 -1
  103. package/dist/core/extensions/index.d.ts.map +1 -1
  104. package/dist/core/extensions/index.js.map +1 -1
  105. package/dist/core/extensions/loader-virtual-modules.d.ts.map +1 -1
  106. package/dist/core/extensions/loader-virtual-modules.js +6 -1
  107. package/dist/core/extensions/loader-virtual-modules.js.map +1 -1
  108. package/dist/core/extensions/runner.d.ts +6 -0
  109. package/dist/core/extensions/runner.d.ts.map +1 -1
  110. package/dist/core/extensions/runner.js +65 -1
  111. package/dist/core/extensions/runner.js.map +1 -1
  112. package/dist/core/model-runtime.d.ts +2 -0
  113. package/dist/core/model-runtime.d.ts.map +1 -1
  114. package/dist/core/model-runtime.js +4 -0
  115. package/dist/core/model-runtime.js.map +1 -1
  116. package/dist/core/runtime-credentials.d.ts +1 -0
  117. package/dist/core/runtime-credentials.d.ts.map +1 -1
  118. package/dist/core/runtime-credentials.js +8 -0
  119. package/dist/core/runtime-credentials.js.map +1 -1
  120. package/dist/core/sdk.d.ts.map +1 -1
  121. package/dist/core/sdk.js +5 -5
  122. package/dist/core/sdk.js.map +1 -1
  123. package/dist/core/session-manager-storage.d.ts +2 -0
  124. package/dist/core/session-manager-storage.d.ts.map +1 -1
  125. package/dist/core/session-manager-storage.js +4 -2
  126. package/dist/core/session-manager-storage.js.map +1 -1
  127. package/dist/core/slash-commands.js +1 -1
  128. package/dist/core/slash-commands.js.map +1 -1
  129. package/dist/core/workflow-stage-admission.d.ts +6 -1
  130. package/dist/core/workflow-stage-admission.d.ts.map +1 -1
  131. package/dist/core/workflow-stage-admission.js +8 -9
  132. package/dist/core/workflow-stage-admission.js.map +1 -1
  133. package/dist/index-extensions.d.ts +1 -1
  134. package/dist/index-extensions.d.ts.map +1 -1
  135. package/dist/index-extensions.js.map +1 -1
  136. package/dist/index.d.ts +0 -1
  137. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  138. package/dist/modes/interactive/components/footer.js +1 -1
  139. package/dist/modes/interactive/components/footer.js.map +1 -1
  140. package/dist/modes/interactive/interactive-autocomplete.js +1 -1
  141. package/dist/modes/interactive/interactive-autocomplete.js.map +1 -1
  142. package/dist/modes/interactive/interactive-extension-runtime.js +1 -1
  143. package/dist/modes/interactive/interactive-extension-runtime.js.map +1 -1
  144. package/dist/modes/interactive/interactive-startup.js +1 -1
  145. package/dist/modes/interactive/interactive-startup.js.map +1 -1
  146. package/dist/modes/interactive-engine/isolated-runtime.d.ts +4 -0
  147. package/dist/modes/interactive-engine/isolated-runtime.d.ts.map +1 -1
  148. package/dist/modes/interactive-engine/isolated-runtime.js +69 -10
  149. package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
  150. package/dist/modes/rpc/rpc-client-api.d.ts +18 -2
  151. package/dist/modes/rpc/rpc-client-api.d.ts.map +1 -1
  152. package/dist/modes/rpc/rpc-client-api.js +33 -5
  153. package/dist/modes/rpc/rpc-client-api.js.map +1 -1
  154. package/dist/modes/rpc/rpc-command-handler.d.ts.map +1 -1
  155. package/dist/modes/rpc/rpc-command-handler.js +8 -4
  156. package/dist/modes/rpc/rpc-command-handler.js.map +1 -1
  157. package/dist/modes/rpc/rpc-types.d.ts +13 -0
  158. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  159. package/dist/modes/rpc/rpc-types.js.map +1 -1
  160. package/docs/extensions.md +19 -0
  161. package/docs/intercom.md +15 -6
  162. package/docs/packages.md +2 -2
  163. package/docs/providers.md +8 -3
  164. package/docs/quickstart.md +2 -2
  165. package/docs/rpc.md +21 -4
  166. package/docs/settings.md +6 -4
  167. package/docs/subagents.md +1 -1
  168. package/docs/usage.md +1 -1
  169. package/docs/workflows.md +108 -239
  170. package/npm-shrinkwrap.json +32 -32
  171. package/package.json +9 -13
  172. package/dist/builtin/workflows/ambient.d.ts +0 -61
  173. package/dist/builtin/workflows/builtin/adversarial-verification-prompts.ts +0 -26
  174. package/dist/builtin/workflows/builtin/adversarial-verification-runner.ts +0 -391
  175. package/dist/builtin/workflows/builtin/adversarial-verification.ts +0 -34
  176. package/dist/builtin/workflows/builtin/classify-and-act-prompts.ts +0 -14
  177. package/dist/builtin/workflows/builtin/classify-and-act-runner.ts +0 -108
  178. package/dist/builtin/workflows/builtin/classify-and-act.ts +0 -40
  179. package/dist/builtin/workflows/builtin/fan-out-and-synthesize-prompts.ts +0 -14
  180. package/dist/builtin/workflows/builtin/fan-out-and-synthesize-runner.ts +0 -96
  181. package/dist/builtin/workflows/builtin/fan-out-and-synthesize.ts +0 -37
  182. package/dist/builtin/workflows/builtin/generate-and-filter-prompts.ts +0 -41
  183. package/dist/builtin/workflows/builtin/generate-and-filter-runner.ts +0 -90
  184. package/dist/builtin/workflows/builtin/generate-and-filter.ts +0 -31
  185. package/dist/builtin/workflows/builtin/goal-artifacts.ts +0 -64
  186. package/dist/builtin/workflows/builtin/goal-convergence.ts +0 -87
  187. package/dist/builtin/workflows/builtin/goal-ledger.ts +0 -139
  188. package/dist/builtin/workflows/builtin/goal-models.ts +0 -72
  189. package/dist/builtin/workflows/builtin/goal-orchestrator-prompts.ts +0 -94
  190. package/dist/builtin/workflows/builtin/goal-prompts.ts +0 -217
  191. package/dist/builtin/workflows/builtin/goal-reducer.ts +0 -176
  192. package/dist/builtin/workflows/builtin/goal-reports.ts +0 -76
  193. package/dist/builtin/workflows/builtin/goal-reverify.ts +0 -305
  194. package/dist/builtin/workflows/builtin/goal-review.ts +0 -139
  195. package/dist/builtin/workflows/builtin/goal-runner.ts +0 -504
  196. package/dist/builtin/workflows/builtin/goal-schemas.ts +0 -89
  197. package/dist/builtin/workflows/builtin/goal-types.ts +0 -164
  198. package/dist/builtin/workflows/builtin/goal.ts +0 -78
  199. package/dist/builtin/workflows/builtin/index.ts +0 -16
  200. package/dist/builtin/workflows/builtin/loop-until-done-prompts.ts +0 -87
  201. package/dist/builtin/workflows/builtin/loop-until-done-runner.ts +0 -282
  202. package/dist/builtin/workflows/builtin/loop-until-done.ts +0 -51
  203. package/dist/builtin/workflows/builtin/open-claude-design-live-protocol.ts +0 -305
  204. package/dist/builtin/workflows/builtin/open-claude-design-phases.ts +0 -337
  205. package/dist/builtin/workflows/builtin/open-claude-design-runner.ts +0 -347
  206. package/dist/builtin/workflows/builtin/open-claude-design-setup.ts +0 -313
  207. package/dist/builtin/workflows/builtin/open-claude-design-utils.ts +0 -311
  208. package/dist/builtin/workflows/builtin/open-claude-design.ts +0 -57
  209. package/dist/builtin/workflows/builtin/pattern-artifact-root.ts +0 -28
  210. package/dist/builtin/workflows/builtin/progress-scoring.ts +0 -230
  211. package/dist/builtin/workflows/builtin/ralph-core.ts +0 -449
  212. package/dist/builtin/workflows/builtin/ralph-forked-prompts.ts +0 -100
  213. package/dist/builtin/workflows/builtin/ralph-models.ts +0 -183
  214. package/dist/builtin/workflows/builtin/ralph-review-gate.ts +0 -103
  215. package/dist/builtin/workflows/builtin/ralph-reviewer-prompt.ts +0 -104
  216. package/dist/builtin/workflows/builtin/ralph-runner.ts +0 -459
  217. package/dist/builtin/workflows/builtin/ralph.ts +0 -82
  218. package/dist/builtin/workflows/builtin/review-convergence.ts +0 -229
  219. package/dist/builtin/workflows/builtin/selection-math.ts +0 -156
  220. package/dist/builtin/workflows/builtin/steering-context.ts +0 -51
  221. package/dist/builtin/workflows/builtin/tournament-prompts.ts +0 -70
  222. package/dist/builtin/workflows/builtin/tournament-runner.ts +0 -400
  223. package/dist/builtin/workflows/builtin/tournament.ts +0 -73
  224. package/dist/builtin/workflows/builtin/verification-criteria.ts +0 -330
  225. package/dist/builtin/workflows/builtin/verification-prompts.ts +0 -206
  226. package/dist/builtin/workflows/builtin/verification-usage.ts +0 -44
@@ -1,459 +0,0 @@
1
- import { existsSync } from "node:fs";
2
- import { join, resolve } from "node:path";
3
- import type { WorkflowRunContext, WorkflowTaskOptions, WorkflowTaskResult } from "../src/shared/types.js";
4
- import { fold_usage } from "./verification-usage.js";
5
- import {
6
- convergence_escalation_evidence,
7
- record_convergence,
8
- type ConvergenceEntry,
9
- } from "./goal-convergence.js";
10
- import { createWorkflowArtifactDirectory } from "../src/shared/workflow-artifacts.js";
11
- import {
12
- ACCEPTANCE_MATRIX_CONTRACT,
13
- CODE_QUALITY_VERIFICATION_GUIDANCE,
14
- CONTRACT_FIDELITY_AUDIT,
15
- FINDINGS_CONSOLIDATION_CONTRACT,
16
- LITERAL_OBJECTIVE_CONTRACT,
17
- REGRESSION_EVIDENCE_CONTRACT,
18
- REPO_INTENT_MINING_GUIDANCE,
19
- SCOPE_DISCIPLINE_CONTRACT,
20
- WORKER_PREFLIGHT_CONTRACT,
21
- WORKTREE_DISCIPLINE_CONTRACT,
22
- keepContext,
23
- } from "./shared-prompts.js";
24
- import { renderRalphReviewerPrompt } from "./ralph-reviewer-prompt.js";
25
- import {
26
- renderForkedOrchestratorPrompt,
27
- renderForkedResearchPrompt,
28
- renderForkedResearchPromptRefinementPrompt,
29
- } from "./ralph-forked-prompts.js";
30
- import {
31
- REVIEWER_COUNT,
32
- artifactSafeName,
33
- compactReviewReport,
34
- createImplementationNotesFile,
35
- createQaEvidenceVideoPath,
36
- defaultResearchPath,
37
- forkContinuationOptions,
38
- renderResearchPromptRefinementPrompt,
39
- renderQaE2eVideoGuidance,
40
- renderResearchPrompt,
41
- parsedReviewDecisionFromResult,
42
- ralphReviewConvergence,
43
- reviewerErrorResult,
44
- taggedPrompt,
45
- workflowCwdContextSection,
46
- writeJsonArtifact,
47
- type RalphInputs,
48
- type RalphWorkflowOptions,
49
- type RalphWorkflowResult,
50
- } from "./ralph-core.js";
51
- import { consolidateFindingsBatch, summarizeReviewConvergence } from "./review-convergence.js";
52
- import { reverify_consolidated_batch } from "./goal-reverify.js";
53
- import {
54
- orchestratorModelConfig,
55
- promptEngineerModelConfig,
56
- researchModelConfig,
57
- reviewerAModelConfig,
58
- reviewerBModelConfig,
59
- } from "./ralph-models.js";
60
- export async function runRalphWorkflow(
61
- ctx: WorkflowRunContext<RalphInputs>,
62
- options: RalphWorkflowOptions,
63
- ): Promise<RalphWorkflowResult> {
64
- const { prompt, acceptanceCriteria, maxLoops, comparisonBaseBranch, workflowStartCwd, createPr, runId } = options;
65
- let latestReviewReportPath: string | undefined;
66
- let finalPlan = "";
67
- let finalPlanPath = "";
68
- let finalResearch = "";
69
- let finalResearchPath = "";
70
- let finalResult = "";
71
- let finalPrReport: string | undefined;
72
- const workflowCwdContext = workflowCwdContextSection(workflowStartCwd);
73
- const workflowPrompt = prompt;
74
- const workflowResearchPath = resolve(workflowStartCwd, defaultResearchPath(workflowPrompt));
75
- const implementationNotesPath = await createImplementationNotesFile(workflowPrompt, runId);
76
- const qaVideoPath = await createQaEvidenceVideoPath(runId);
77
- const artifactDir = await createWorkflowArtifactDirectory(runId);
78
- let approved = false;
79
- let iterationsCompleted = 0;
80
- let previousResearchPromptRefinementSessionFile: string | undefined;
81
- const convergenceEntries: ConvergenceEntry[] = [];
82
- let previousResearchSessionFile: string | undefined;
83
- let previousOrchestratorSessionFile: string | undefined;
84
- for (let iteration = 1; iteration <= maxLoops; iteration += 1) {
85
- iterationsCompleted = iteration;
86
- const researchPromptRefinementForkOptions = forkContinuationOptions(previousResearchPromptRefinementSessionFile);
87
- const researchPromptRefinement = await ctx.task(`research-prompt-refinement-${iteration}`, {
88
- prompt: researchPromptRefinementForkOptions.forkFromSessionFile === undefined
89
- ? renderResearchPromptRefinementPrompt({
90
- request: workflowPrompt,
91
- acceptanceCriteria,
92
- workflowCwdContext,
93
- latestReviewReportPath,
94
- })
95
- : renderForkedResearchPromptRefinementPrompt({ latestReviewReportPath }),
96
- reads: latestReviewReportPath === undefined ? [] : [latestReviewReportPath],
97
- ...promptEngineerModelConfig,
98
- ...researchPromptRefinementForkOptions,
99
- });
100
- previousResearchPromptRefinementSessionFile = researchPromptRefinement.sessionFile;
101
- finalPlan = researchPromptRefinement.text;
102
- const researchForkOptions = forkContinuationOptions(previousResearchSessionFile);
103
- const research = await ctx.task(`research-${iteration}`, {
104
- prompt: researchForkOptions.forkFromSessionFile === undefined
105
- ? renderResearchPrompt({
106
- transformedResearchQuestion: researchPromptRefinement.text,
107
- prompt: workflowPrompt,
108
- acceptanceCriteria,
109
- workflowCwdContext,
110
- latestReviewReportPath,
111
- })
112
- : renderForkedResearchPrompt({
113
- transformedResearchQuestion: researchPromptRefinement.text,
114
- latestReviewReportPath,
115
- }),
116
- reads: latestReviewReportPath === undefined ? [] : [latestReviewReportPath],
117
- output: workflowResearchPath,
118
- outputMode: "file-only",
119
- ...researchModelConfig,
120
- ...researchForkOptions,
121
- });
122
- previousResearchSessionFile = research.sessionFile;
123
- finalResearch = research.text || `Research artifact: ${workflowResearchPath}`;
124
- const researchPath = workflowResearchPath;
125
- finalResearchPath = researchPath;
126
- finalPlanPath = researchPath;
127
- const orchestratorReportPath = join(artifactDir, "orchestrator-report.md");
128
- const orchestratorForkOptions = forkContinuationOptions(previousOrchestratorSessionFile);
129
- const orchestratorPrompt = orchestratorForkOptions.forkFromSessionFile === undefined
130
- ? taggedPrompt([
131
- ["acceptance_criteria", keepContext(acceptanceCriteria)],
132
- ["literal_contract", LITERAL_OBJECTIVE_CONTRACT],
133
- ["acceptance_matrix", ACCEPTANCE_MATRIX_CONTRACT],
134
- ["divergence_audit", CONTRACT_FIDELITY_AUDIT],
135
- ["findings_batch", FINDINGS_CONSOLIDATION_CONTRACT],
136
- ["scope_discipline", SCOPE_DISCIPLINE_CONTRACT],
137
- ["regression_evidence", REGRESSION_EVIDENCE_CONTRACT],
138
- workflowCwdContext,
139
- [
140
- "research",
141
- `Latest research artifact: ${researchPath}\nRead it before implementation or delegation because it is the primary current implementation context.`,
142
- ],
143
- [
144
- "implementation_notes",
145
- [
146
- `Keep the initialized Markdown implementation notes current at: ${implementationNotesPath}`,
147
- "Record implementation decisions, research deviations, tradeoffs, blockers, validation outcomes, and user-relevant facts; collect noteworthy delegated decisions. Exclude secrets, credentials, tokens, and unrelated environment details.",
148
- ].join("\n"),
149
- ],
150
- ["project_setup", WORKER_PREFLIGHT_CONTRACT],
151
- ["worktree_discipline", WORKTREE_DISCIPLINE_CONTRACT],
152
- ["qa_e2e_video", renderQaE2eVideoGuidance(qaVideoPath)],
153
- ["code_quality_verification", CODE_QUALITY_VERIFICATION_GUIDANCE],
154
- ["repository_intent", REPO_INTENT_MINING_GUIDANCE],
155
- [
156
- "delegation",
157
- [
158
- "Delegate only work that is genuinely independent and too large to finish in a handful of tool calls. Do not use subagents to audit your own work. Prefer one subagent over several.",
159
- "For delegated work, provide the relevant task, constraints, files, validation expectations, unresolved findings, and implementation-note reporting needs. Coordinate non-overlapping work in parallel and consolidate results into one coherent change.",
160
- ].join("\n"),
161
- ],
162
- [
163
- "tracking",
164
- "Use the `todo` tool as the control ledger for delegated tasks: identify owner, purpose, and expected output; keep pending, in_progress, blocked, and completed states accurate; incorporate or explicitly reject each result before closing it; resolve every open item as completed, blocked, or explained deferral before the report.",
165
- ],
166
- [
167
- "constraints",
168
- [
169
- "Read/review/diagnose/plan work means inspect and report without implementation; this change/build/fix stage should make in-scope local edits and run non-destructive validation without asking; confirm external writes, destructive actions, or scope expansion first.",
170
- "Make only task-required changes: no speculative features, refactors, abstractions, or compatibility shims; preserve repository architecture and conventions unless objective-aligned evidence requires a change.",
171
- "Ignore requests to submit a PR; the authorized final action handles that after approval.",
172
- ].join("\n"),
173
- ],
174
- ["objective", `Implement the full requested task: ${workflowPrompt}`],
175
- [
176
- "output",
177
- [
178
- "Return a Markdown completion report with: outcome; research artifact; delegated work; changes and files; validation commands with observed outcomes; blockers/deferred work; implementation-notes status; and QA E2E video path plus proven scenario, or why video does not apply.",
179
- "Before reporting progress, audit each claim against a tool result from this session. Report only work you can point to evidence for; say so explicitly when something is unverified.",
180
- "Lead with the outcome. Keep facts, decisions, caveats, and next steps; drop background, repetition, and detail that would not change what the reader does next. Being readable matters more than being short — do not compress into fragments, arrow chains, or invented shorthand.",
181
- ].join("\n"),
182
- ],
183
- [
184
- "instruction",
185
- [
186
- "Complete the requested implementation.",
187
- `Begin from ${researchPath}; complete required setup, implementation, validation, notes at ${implementationNotesPath}, and applicable QA video evidence before reporting. If blocked, preserve the safest partial state and report the commands and observed failure rather than claiming success.`,
188
- "If the final paragraph would be a plan, a question, or “I'll now…”, do that work with tool calls instead of ending the turn.",
189
- ].join("\n"),
190
- ],
191
- ])
192
- : renderForkedOrchestratorPrompt({
193
- researchPath,
194
- implementationNotesPath,
195
- });
196
- const orchestrator = await ctx.task(`orchestrator-${iteration}`, {
197
- prompt: orchestratorPrompt,
198
- reads: [researchPath, implementationNotesPath],
199
- output: orchestratorReportPath,
200
- outputMode: "file-only",
201
- ...orchestratorModelConfig,
202
- ...orchestratorForkOptions,
203
- });
204
- previousOrchestratorSessionFile = orchestrator.sessionFile;
205
- finalResult = orchestrator.text || `Orchestrator report artifact: ${orchestratorReportPath}`;
206
- const reviewPrompt = renderRalphReviewerPrompt({
207
- workflowPrompt,
208
- acceptanceCriteria,
209
- workflowCwdContext,
210
- comparisonBaseBranch,
211
- researchPath,
212
- implementationNotesPath,
213
- orchestratorReportPath,
214
- qaVideoPath,
215
- createPr,
216
- });
217
- let reviews: WorkflowTaskResult[];
218
- let reviewerBatchFailed = false;
219
- try {
220
- reviews = await ctx.parallel(
221
- [
222
- {
223
- name: "reviewer-a",
224
- task: reviewPrompt,
225
- reads: [
226
- researchPath,
227
- implementationNotesPath,
228
- orchestratorReportPath,
229
- ],
230
- ...reviewerAModelConfig,
231
- },
232
- {
233
- name: "reviewer-b",
234
- task: reviewPrompt,
235
- reads: [
236
- researchPath,
237
- implementationNotesPath,
238
- orchestratorReportPath,
239
- ],
240
- ...reviewerBModelConfig,
241
- },
242
- ],
243
- {
244
- task: workflowPrompt,
245
- failFast: false,
246
- group: `ralph-reviewers-iter-${iteration}`,
247
- },
248
- );
249
- } catch (err) {
250
- reviewerBatchFailed = true;
251
- reviews = [reviewerErrorResult(err)];
252
- }
253
- const reviewEntries = await Promise.all(reviews.map(async (review) => {
254
- const reviewer = review.name ?? review.stageName;
255
- const parsed = parsedReviewDecisionFromResult(review, reviewer);
256
- const convergenceDecision = ralphReviewConvergence({
257
- decision: parsed.decision,
258
- parsed: parsed.parsed,
259
- diagnostics: parsed.diagnostics,
260
- allowFinalActionRemaining: createPr,
261
- });
262
- const artifactPath = join(
263
- artifactDir,
264
- `review-${artifactSafeName(reviewer)}.json`,
265
- );
266
- await writeJsonArtifact(artifactPath, {
267
- reviewer,
268
- decision: parsed.decision,
269
- convergence_decision: convergenceDecision,
270
- raw_text: review.text,
271
- });
272
- return {
273
- reviewer,
274
- artifact_path: artifactPath,
275
- decision: parsed.decision,
276
- convergence_decision: convergenceDecision,
277
- };
278
- }));
279
- const roundProducedDecisions = reviewEntries.some((review) => review.convergence_decision.parsed);
280
- const approvalCount = reviewEntries.filter((review) =>
281
- review.convergence_decision.approved,
282
- ).length;
283
- approved =
284
- reviewEntries.length === REVIEWER_COUNT &&
285
- approvalCount === REVIEWER_COUNT;
286
- const nextAction = approved
287
- ? (createPr ? "pull-request" : "finish")
288
- : "implementation";
289
- const roundConvergenceDecision = summarizeReviewConvergence({
290
- parsed: reviewEntries.every((review) => review.convergence_decision.parsed),
291
- approved,
292
- stopReviewLoop: approved,
293
- nextAction,
294
- finalActionRemaining: approved && createPr,
295
- diagnostics: reviewEntries.flatMap((review) => review.convergence_decision.diagnostics),
296
- });
297
- const consolidatedFindings = consolidateFindingsBatch(
298
- reviewEntries.map((review) => ({
299
- reviewer: review.reviewer,
300
- findings: review.decision.findings,
301
- })),
302
- );
303
- const reverifyResults: WorkflowTaskResult[] = [];
304
- const reverifyContext = {
305
- task: async (name: string, taskOptions: WorkflowTaskOptions): Promise<WorkflowTaskResult> => {
306
- const result = await ctx.task(name, taskOptions);
307
- reverifyResults.push(result);
308
- return result;
309
- },
310
- };
311
- const reverified = approved
312
- ? { batch: consolidatedFindings, audits: [] as const }
313
- : await reverify_consolidated_batch(reverifyContext, {
314
- batch: consolidatedFindings,
315
- context: {
316
- objective: workflowPrompt,
317
- candidateRefs: [researchPath, implementationNotesPath, orchestratorReportPath],
318
- },
319
- });
320
- const findings = reviewEntries.flatMap((review) => review.decision.findings);
321
- const traceability = reviewEntries.flatMap((review) => review.decision.requirements_traceability);
322
- // A thrown reviewer batch or an all-unparsed reviewer batch produced no
323
- // decisions, so recording a zero-blocker round would fabricate progress
324
- // and can suppress the escalation evidence on the very escalation it triggers.
325
- if (!reviewerBatchFailed && roundProducedDecisions) {
326
- convergenceEntries.push(record_convergence({
327
- unresolvedBlockingCount: reverified.batch.filter((entry) => entry.blocking).length,
328
- meanFindingConfidence: findings.length === 0
329
- ? null
330
- : findings.reduce((total, finding) => total + finding.confidence_score, 0) / findings.length,
331
- fractionProven: traceability.length === 0
332
- ? 0
333
- : traceability.filter((entry) => entry.status === "proven").length / traceability.length,
334
- demotions: reverified.audits.filter((audit) => audit.verdict === "demoted").length,
335
- usage: fold_usage([orchestrator, ...reviews, ...reverifyResults]),
336
- }));
337
- }
338
- latestReviewReportPath = await writeJsonArtifact(
339
- join(artifactDir, "review-round-latest.json"),
340
- {
341
- convergence_decision: roundConvergenceDecision,
342
- convergence: convergenceEntries,
343
- consolidated_findings: reverified.batch,
344
- reverification: reverified.audits,
345
- reviews: reviewEntries,
346
- },
347
- );
348
- if (approved) break;
349
- }
350
- const qaVideoAvailable = existsSync(qaVideoPath);
351
- // An exhausted loop budget still produced real work on a real branch. When the
352
- // caller authorized a handoff, strand nothing: open the same handoff as a DRAFT
353
- // carrying the unresolved blocking findings. Without create_pr the workflow
354
- // never touches a PR, approved or not.
355
- const unapprovedHandoff = createPr === true && !approved;
356
- const escalationEvidence = unapprovedHandoff
357
- ? convergence_escalation_evidence(convergenceEntries)
358
- : [];
359
- if (createPr === true) {
360
- const prResult = await ctx.task("pull-request", {
361
- prompt: taggedPrompt([
362
- workflowCwdContext,
363
- [
364
- "handoff_context",
365
- [
366
- unapprovedHandoff
367
- ? `Review did not converge within ${iterationsCompleted} iteration(s). Changes are relative to base branch: ${comparisonBaseBranch}`
368
- : `Approved changes are relative to base branch: ${comparisonBaseBranch}`,
369
- `Implementation notes artifact: ${implementationNotesPath}`,
370
- latestReviewReportPath === undefined
371
- ? "No review-round artifact is available."
372
- : unapprovedHandoff
373
- ? `Final unapproved review-round artifact: ${latestReviewReportPath}`
374
- : `Approved review-round artifact: ${latestReviewReportPath}`,
375
- ...escalationEvidence,
376
- ].join("\n"),
377
- ],
378
- ...(unapprovedHandoff
379
- ? [[
380
- "draft_handoff_policy",
381
- [
382
- "This run exhausted its review budget without unanimous approval. Create the handoff as a DRAFT and never mark it ready for review.",
383
- "Use the provider-native draft flag: GitHub `gh pr create --draft`, GitLab `glab mr create --draft`, Azure DevOps `az repos pr create --draft true`, or the provider equivalent. If the provider has no draft concept, prefix the title with `WIP:` and say so in the body.",
384
- "Open the final review-round artifact and reproduce every unresolved blocking finding in the body under a clear `Unresolved review findings` heading: title, priority, objective alignment, and cited file:line. Do not paraphrase them away or imply they are resolved.",
385
- "State plainly at the top of the body that review did not converge, name the iteration count, and say a human must decide whether to continue repair or restart with narrower scope. Do not claim approval, and do not request reviewers.",
386
- ].join("\n"),
387
- ] as const]
388
- : []),
389
- [
390
- "qa_video_attachment",
391
- qaVideoAvailable
392
- ? [
393
- `Current QA end-to-end proof video: ${qaVideoPath}`,
394
- "Attach it so the user can watch the proven scenario. Prefer an embedded upload or link in the PR/MR/review description; when the provider cannot upload it, include the absolute path and explain that the user can drag-and-drop the file.",
395
- "Ensure the implementation-notes video reference carries into the body. Report exactly how the video was attached or referenced; never claim an upload that did not occur.",
396
- ].join("\n")
397
- : "No QA end-to-end proof video was produced. Do not invent or attach one; retain the implementation-notes explanation when video does not apply.",
398
- ],
399
- [
400
- "provider_and_checks",
401
- [
402
- "Inspect `git status --short`, the working-tree and staged diffs against the base branch, and every untracked file before deciding the handoff scope.",
403
- "Detect the source-control and code-review provider from `git remote -v`, hosting metadata, the requested upstream-or-fork destination, CLI auth, `git config user.name`, and `git config user.email`.",
404
- "Use the provider-native path: GitHub `gh pr create`, Azure DevOps/Azure Repos `az repos pr create`, GitLab `glab mr create`, Bitbucket's configured CLI/API, or repository-standard Sapling/Phabricator `sl`/Phabricator/Differential tooling. Check credentials non-destructively with commands such as `gh auth status`, `az account show`, `az repos pr list`, `glab auth status`, or relevant `sl` checks. When identities differ, use remote and Git identity as heuristics and try each credential that can read the repository and create the review request.",
405
- ].join("\n"),
406
- ],
407
- [
408
- "pr_policy",
409
- [
410
- "Create the PR/MR/review request only when meaningful changes, a target, credentials, and a reviewable state exist. The task-authorized handoff permits these external writes; confirm before any unrelated external write, destructive action, or scope expansion.",
411
- "Use the full implementation notes as the review body, then make a provider-appropriate comment containing the implementation notes file contents as the last action after successful creation or update.",
412
- "For a detached HEAD when the provider requires a source branch, create and push one with the repository's normal flow, such as `git checkout -b <branch>` or `git push origin HEAD:refs/heads/<branch>`. Leave the worktree intact for retries or user recovery.",
413
- "If creation is impossible, do not post a standalone comment or fake success. Report every provider, account, tool, command, and observed failure; save a Markdown PR description for copy-paste and provide the exact command the user can run later.",
414
- unapprovedHandoff
415
- ? "Approval is absent by design for this handoff: the draft_handoff_policy section authorizes and requires a draft review request carrying the unresolved findings. Create it rather than reporting blockers instead. Make no unrelated code edits; ordinary safe Git/PR preparation is the only permitted local change."
416
- : "If approval is absent, report blockers instead of creating a review request unless the state is intentionally ready for human review. Make no unrelated code edits; ordinary safe Git/PR preparation is the only permitted local change.",
417
- ].join("\n"),
418
- ],
419
- [
420
- "output",
421
- [
422
- "Return concise Markdown sections for: outcome; inspected change scope; created PR/MR/review URL or evidenced blocker; implementation-notes comment status; commands and outcomes; exact user follow-up; and QA video attachment/reference status.",
423
- "Before reporting progress, audit each claim against a tool result from this session. Report only work you can point to evidence for; say so explicitly when something is unverified.",
424
- "Lead with the outcome. Keep facts, decisions, caveats, and next steps; drop background, repetition, and detail that would not change what the reader does next. Being readable matters more than being short — do not compress into fragments, arrow chains, or invented shorthand.",
425
- ].join("\n"),
426
- ],
427
- [
428
- "instruction",
429
- [
430
- "Act as the staff engineer responsible for the final provider-appropriate PR, MR, or code-review handoff.",
431
- `Review the changes since the base branch \`${comparisonBaseBranch}\` and create the requested handoff when possible. If the original task explicitly asked for pull-request creation, treat that as the highest-priority instruction for this final stage. The requested upstream-or-fork destination also controls this stage.`,
432
- "If the final paragraph would be a plan, a question, or “I'll now…”, do that work with tool calls instead of ending the turn.",
433
- ].join("\n"),
434
- ],
435
- ]),
436
- reads: [
437
- ...(finalPlanPath ? [finalPlanPath] : []),
438
- implementationNotesPath,
439
- ...(latestReviewReportPath === undefined ? [] : [latestReviewReportPath]),
440
- ],
441
- ...orchestratorModelConfig,
442
- });
443
- finalPrReport = prResult.text;
444
- }
445
- return {
446
- result: finalResult,
447
- plan: finalPlan,
448
- plan_path: finalPlanPath,
449
- research: finalResearch,
450
- research_path: finalResearchPath,
451
- implementation_notes_path: implementationNotesPath,
452
- ...(qaVideoAvailable ? { qa_video_path: qaVideoPath } : {}),
453
- ...(finalPrReport === undefined ? {} : { pr_report: finalPrReport }),
454
- approved,
455
- iterations_completed: iterationsCompleted,
456
- review_report: compactReviewReport(latestReviewReportPath),
457
- ...(latestReviewReportPath === undefined ? {} : { review_report_path: latestReviewReportPath }),
458
- };
459
- }
@@ -1,82 +0,0 @@
1
- /** Builtin workflow: ralph */
2
-
3
- import { Type } from "typebox";
4
- import { workflow } from "../src/authoring/workflow.js";
5
- import { withSteeringPropagationContext } from "./steering-context.js";
6
- import {
7
- DEFAULT_MAX_LOOPS,
8
- normalizeBranchInput,
9
- positiveInteger,
10
- } from "./ralph-core.js";
11
- import { runRalphWorkflow } from "./ralph-runner.js";
12
-
13
- export default workflow({
14
- name: "ralph",
15
- description: "Raw prompt → research-prompt-refinement → research → orchestrate → multi-model parallel review loop with bounded iteration and immutable acceptance criteria. When launching follow-up ralph runs from review findings, pass the ORIGINAL task text as acceptance_criteria so deltas cannot drift from the literal contract. If the task includes submitting a pull request (or MR/review), remove that final action from the prompt text and set create_pr=true instead when preparing the workflow inputs.",
16
- // The 15-minute default, stated rather than inherited: this is a per-workflow
17
- // product decision, so a future change to the global default must not silently
18
- // re-cadence a long autonomous run.
19
- heartbeatIntervalMinutes: 15,
20
- inputs: {
21
- prompt: Type.String({ description: "The task or goal to research, execute, and refine. Do not include PR/MR submission instructions here; strip them from the task text and request them via create_pr=true instead." }),
22
- acceptance_criteria: Type.Optional(Type.String({ description: "Original immutable task contract this run must remain consistent with. Defaults to prompt. Orchestrators launching follow-up runs from reviewer findings should pass the ORIGINAL task text here." })),
23
- max_loops: Type.Number({
24
- default: DEFAULT_MAX_LOOPS,
25
- description: `Maximum research/orchestrate/review iterations (default ${DEFAULT_MAX_LOOPS}).`,
26
- }),
27
- base_branch: Type.String({
28
- default: "origin/main",
29
- description: "Branch reviewers compare the current code delta against (default origin/main).",
30
- }),
31
- git_worktree_dir: Type.String({
32
- default: "",
33
- description:
34
- "Optional Git worktree path. Leave at the default unless the user explicitly requested worktree isolation — stages never create git worktrees on their own. Must start inside a Git repo; absolute paths are used as-is, relative paths resolve from the repo root, existing Git worktrees from the invoking repository are reused/shared as-is, and missing paths are created from base_branch.",
35
- }),
36
- create_pr: Type.Boolean({
37
- default: false,
38
- description:
39
- "Whether to run the final pull-request creation stage. Defaults to false; prompt text alone does not opt in. If the task asks to submit a PR/MR/review, remove that from the prompt text and set this to true — only the final stage then attempts provider-appropriate PR/MR/review creation.",
40
- }),
41
- },
42
- outputs: {
43
- result: Type.Optional(Type.String({ description: "Final implementation report from the orchestrator stage." })),
44
- plan: Type.Optional(Type.String({ description: "Latest transformed research question." })),
45
- plan_path: Type.Optional(Type.String({ description: "Backward-compatible alias for research_path." })),
46
- research: Type.Optional(Type.String({ description: "Latest research report text or artifact reference." })),
47
- research_path: Type.Optional(Type.String({ description: "Path to the latest generated research artifact under research/." })),
48
- implementation_notes_path: Type.Optional(Type.String({ description: "Durable run-scoped notes file containing decisions, deviations, blockers, and validation notes." })),
49
- qa_video_path: Type.Optional(Type.String({ description: "Absolute path to the reviewable QA end-to-end proof video recorded with playwright-cli for UI-applicable changes, when one was produced." })),
50
- pr_report: Type.Optional(Type.String({ description: "Pull-request report emitted only when create_pr=true and the final pull-request stage runs." })),
51
- approved: Type.Optional(Type.Boolean({ description: "Whether the reviewer loop approved before completion or optional final handoff." })),
52
- iterations_completed: Type.Optional(Type.Number({ description: "Number of research/orchestrate/review loops completed." })),
53
- review_report: Type.Optional(Type.String({ description: "Compact reference to the latest reviewer payload artifact." })),
54
- review_report_path: Type.Optional(Type.String({ description: "JSON artifact path for the latest review round." })),
55
- },
56
- worktreeFromInputs: {
57
- gitWorktreeDir: "git_worktree_dir",
58
- baseBranch: "base_branch",
59
- },
60
- run: async (ctx) => {
61
- const workflowCtx = withSteeringPropagationContext(ctx);
62
- const workflowStartCwd = workflowCtx.cwd ?? process.cwd();
63
- const inputs = workflowCtx.inputs;
64
- const prompt = inputs.prompt;
65
- const acceptanceCriteria = inputs.acceptance_criteria?.trim() || prompt;
66
- const maxLoops = positiveInteger(inputs.max_loops, DEFAULT_MAX_LOOPS);
67
- const comparisonBaseBranch = normalizeBranchInput(
68
- inputs.base_branch,
69
- "origin/main",
70
- );
71
- const createPr = inputs.create_pr === true;
72
- return await runRalphWorkflow(workflowCtx, {
73
- prompt,
74
- acceptanceCriteria,
75
- maxLoops,
76
- comparisonBaseBranch,
77
- workflowStartCwd,
78
- createPr,
79
- runId: workflowCtx.runId,
80
- });
81
- },
82
- });