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

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 (207) hide show
  1. package/CHANGELOG.md +19 -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 +680 -53
  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 +109 -35
  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 +173 -51
  21. package/dist/builtin/web-access/index.bundle.mjs +109 -35
  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-29wrp38a.js +199 -0
  28. package/dist/builtin/workflows/builtin/chunk-2dqb5s2q.js +602 -0
  29. package/dist/builtin/workflows/builtin/chunk-4febxsv4.js +264 -0
  30. package/dist/builtin/workflows/builtin/chunk-5n10x7j2.js +69730 -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-bfkmzv9h.js +156 -0
  37. package/dist/builtin/workflows/builtin/chunk-c53y8bdh.js +345 -0
  38. package/dist/builtin/workflows/builtin/chunk-cdtd3m3w.js +529 -0
  39. package/dist/builtin/workflows/builtin/chunk-cg9tmks0.js +206 -0
  40. package/dist/builtin/workflows/builtin/chunk-hdpj1dkw.js +2447 -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-qwzvgxnq.js +404 -0
  44. package/dist/builtin/workflows/builtin/chunk-qx2ptjs3.js +215 -0
  45. package/dist/builtin/workflows/builtin/chunk-v04c5qmd.js +1207 -0
  46. package/dist/builtin/workflows/builtin/chunk-wpckd35c.js +12 -0
  47. package/dist/builtin/workflows/builtin/chunk-x2ghn0je.js +4110 -0
  48. package/dist/builtin/workflows/builtin/chunk-zf28603f.js +1080 -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 +1228 -428
  63. package/dist/builtin/workflows/src/{index.bundle.mjs → index.js} +956 -427
  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/context-types.d.ts +35 -0
  91. package/dist/core/extensions/context-types.d.ts.map +1 -1
  92. package/dist/core/extensions/context-types.js.map +1 -1
  93. package/dist/core/extensions/index.d.ts +1 -1
  94. package/dist/core/extensions/index.d.ts.map +1 -1
  95. package/dist/core/extensions/index.js.map +1 -1
  96. package/dist/core/extensions/loader-virtual-modules.d.ts.map +1 -1
  97. package/dist/core/extensions/loader-virtual-modules.js +6 -1
  98. package/dist/core/extensions/loader-virtual-modules.js.map +1 -1
  99. package/dist/core/model-runtime.d.ts +2 -0
  100. package/dist/core/model-runtime.d.ts.map +1 -1
  101. package/dist/core/model-runtime.js +4 -0
  102. package/dist/core/model-runtime.js.map +1 -1
  103. package/dist/core/runtime-credentials.d.ts +1 -0
  104. package/dist/core/runtime-credentials.d.ts.map +1 -1
  105. package/dist/core/runtime-credentials.js +8 -0
  106. package/dist/core/runtime-credentials.js.map +1 -1
  107. package/dist/core/sdk.d.ts.map +1 -1
  108. package/dist/core/sdk.js +5 -5
  109. package/dist/core/sdk.js.map +1 -1
  110. package/dist/core/session-manager-storage.d.ts +2 -0
  111. package/dist/core/session-manager-storage.d.ts.map +1 -1
  112. package/dist/core/session-manager-storage.js +4 -2
  113. package/dist/core/session-manager-storage.js.map +1 -1
  114. package/dist/core/slash-commands.js +1 -1
  115. package/dist/core/slash-commands.js.map +1 -1
  116. package/dist/core/workflow-stage-admission.d.ts +6 -1
  117. package/dist/core/workflow-stage-admission.d.ts.map +1 -1
  118. package/dist/core/workflow-stage-admission.js +8 -9
  119. package/dist/core/workflow-stage-admission.js.map +1 -1
  120. package/dist/index.d.ts +0 -1
  121. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  122. package/dist/modes/interactive/components/footer.js +1 -1
  123. package/dist/modes/interactive/components/footer.js.map +1 -1
  124. package/dist/modes/interactive/interactive-autocomplete.js +1 -1
  125. package/dist/modes/interactive/interactive-autocomplete.js.map +1 -1
  126. package/dist/modes/interactive/interactive-startup.js +1 -1
  127. package/dist/modes/interactive/interactive-startup.js.map +1 -1
  128. package/dist/modes/interactive-engine/isolated-runtime.d.ts +4 -0
  129. package/dist/modes/interactive-engine/isolated-runtime.d.ts.map +1 -1
  130. package/dist/modes/interactive-engine/isolated-runtime.js +69 -10
  131. package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
  132. package/dist/modes/rpc/rpc-client-api.d.ts +18 -2
  133. package/dist/modes/rpc/rpc-client-api.d.ts.map +1 -1
  134. package/dist/modes/rpc/rpc-client-api.js +33 -5
  135. package/dist/modes/rpc/rpc-client-api.js.map +1 -1
  136. package/dist/modes/rpc/rpc-command-handler.d.ts.map +1 -1
  137. package/dist/modes/rpc/rpc-command-handler.js +8 -4
  138. package/dist/modes/rpc/rpc-command-handler.js.map +1 -1
  139. package/dist/modes/rpc/rpc-types.d.ts +13 -0
  140. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  141. package/dist/modes/rpc/rpc-types.js.map +1 -1
  142. package/docs/intercom.md +15 -6
  143. package/docs/packages.md +2 -2
  144. package/docs/providers.md +8 -3
  145. package/docs/quickstart.md +2 -2
  146. package/docs/rpc.md +21 -4
  147. package/docs/settings.md +6 -4
  148. package/docs/subagents.md +1 -1
  149. package/docs/usage.md +1 -1
  150. package/docs/workflows.md +108 -239
  151. package/npm-shrinkwrap.json +32 -32
  152. package/package.json +9 -13
  153. package/dist/builtin/workflows/ambient.d.ts +0 -61
  154. package/dist/builtin/workflows/builtin/adversarial-verification-prompts.ts +0 -26
  155. package/dist/builtin/workflows/builtin/adversarial-verification-runner.ts +0 -391
  156. package/dist/builtin/workflows/builtin/adversarial-verification.ts +0 -34
  157. package/dist/builtin/workflows/builtin/classify-and-act-prompts.ts +0 -14
  158. package/dist/builtin/workflows/builtin/classify-and-act-runner.ts +0 -108
  159. package/dist/builtin/workflows/builtin/classify-and-act.ts +0 -40
  160. package/dist/builtin/workflows/builtin/fan-out-and-synthesize-prompts.ts +0 -14
  161. package/dist/builtin/workflows/builtin/fan-out-and-synthesize-runner.ts +0 -96
  162. package/dist/builtin/workflows/builtin/fan-out-and-synthesize.ts +0 -37
  163. package/dist/builtin/workflows/builtin/generate-and-filter-prompts.ts +0 -41
  164. package/dist/builtin/workflows/builtin/generate-and-filter-runner.ts +0 -90
  165. package/dist/builtin/workflows/builtin/generate-and-filter.ts +0 -31
  166. package/dist/builtin/workflows/builtin/goal-artifacts.ts +0 -64
  167. package/dist/builtin/workflows/builtin/goal-convergence.ts +0 -87
  168. package/dist/builtin/workflows/builtin/goal-ledger.ts +0 -139
  169. package/dist/builtin/workflows/builtin/goal-models.ts +0 -72
  170. package/dist/builtin/workflows/builtin/goal-orchestrator-prompts.ts +0 -94
  171. package/dist/builtin/workflows/builtin/goal-prompts.ts +0 -217
  172. package/dist/builtin/workflows/builtin/goal-reducer.ts +0 -176
  173. package/dist/builtin/workflows/builtin/goal-reports.ts +0 -76
  174. package/dist/builtin/workflows/builtin/goal-reverify.ts +0 -305
  175. package/dist/builtin/workflows/builtin/goal-review.ts +0 -139
  176. package/dist/builtin/workflows/builtin/goal-runner.ts +0 -504
  177. package/dist/builtin/workflows/builtin/goal-schemas.ts +0 -89
  178. package/dist/builtin/workflows/builtin/goal-types.ts +0 -164
  179. package/dist/builtin/workflows/builtin/goal.ts +0 -78
  180. package/dist/builtin/workflows/builtin/index.ts +0 -16
  181. package/dist/builtin/workflows/builtin/loop-until-done-prompts.ts +0 -87
  182. package/dist/builtin/workflows/builtin/loop-until-done-runner.ts +0 -282
  183. package/dist/builtin/workflows/builtin/loop-until-done.ts +0 -51
  184. package/dist/builtin/workflows/builtin/open-claude-design-live-protocol.ts +0 -305
  185. package/dist/builtin/workflows/builtin/open-claude-design-phases.ts +0 -337
  186. package/dist/builtin/workflows/builtin/open-claude-design-runner.ts +0 -347
  187. package/dist/builtin/workflows/builtin/open-claude-design-setup.ts +0 -313
  188. package/dist/builtin/workflows/builtin/open-claude-design-utils.ts +0 -311
  189. package/dist/builtin/workflows/builtin/open-claude-design.ts +0 -57
  190. package/dist/builtin/workflows/builtin/pattern-artifact-root.ts +0 -28
  191. package/dist/builtin/workflows/builtin/progress-scoring.ts +0 -230
  192. package/dist/builtin/workflows/builtin/ralph-core.ts +0 -449
  193. package/dist/builtin/workflows/builtin/ralph-forked-prompts.ts +0 -100
  194. package/dist/builtin/workflows/builtin/ralph-models.ts +0 -183
  195. package/dist/builtin/workflows/builtin/ralph-review-gate.ts +0 -103
  196. package/dist/builtin/workflows/builtin/ralph-reviewer-prompt.ts +0 -104
  197. package/dist/builtin/workflows/builtin/ralph-runner.ts +0 -459
  198. package/dist/builtin/workflows/builtin/ralph.ts +0 -82
  199. package/dist/builtin/workflows/builtin/review-convergence.ts +0 -229
  200. package/dist/builtin/workflows/builtin/selection-math.ts +0 -156
  201. package/dist/builtin/workflows/builtin/steering-context.ts +0 -51
  202. package/dist/builtin/workflows/builtin/tournament-prompts.ts +0 -70
  203. package/dist/builtin/workflows/builtin/tournament-runner.ts +0 -400
  204. package/dist/builtin/workflows/builtin/tournament.ts +0 -73
  205. package/dist/builtin/workflows/builtin/verification-criteria.ts +0 -330
  206. package/dist/builtin/workflows/builtin/verification-prompts.ts +0 -206
  207. package/dist/builtin/workflows/builtin/verification-usage.ts +0 -44
@@ -1,121 +1,96 @@
1
- // Builtin prompts use the same public `keepContext` helper workflow authors do, so the
2
- // protection semantics cannot drift between builtin and user-authored workflows.
3
- import { keepContext } from "../src/authoring/keep-context.js";
4
-
5
- export { keepContext };
1
+ // dist/builtin/workflows/src/authoring/keep-context.ts
2
+ var KEEP_CONTEXT_OPEN_TAG = "<keepContext>";
3
+ var KEEP_CONTEXT_CLOSE_TAG = "</keepContext>";
4
+ function keepContext(text) {
5
+ const trimmed = text.trim();
6
+ if (trimmed.startsWith(KEEP_CONTEXT_OPEN_TAG) && trimmed.endsWith(KEEP_CONTEXT_CLOSE_TAG))
7
+ return trimmed;
8
+ return `${KEEP_CONTEXT_OPEN_TAG}
9
+ ${trimmed}
10
+ ${KEEP_CONTEXT_CLOSE_TAG}`;
11
+ }
6
12
 
7
- /**
8
- * Steering propagation is a whole-repository pattern, not a per-workflow
9
- * option: every builtin stage prompt carries STEERING_PROPAGATION_CONTRACT
10
- * through `withSteeringPropagation`, and `test/unit/builtin-workflow-steering-propagation.test.ts`
11
- * fails when a stage prompt omits it.
12
- *
13
- * A run's contract can change mid-flight, but only the user may change it. A
14
- * steered amendment that stays inside one stage's session is invisible to every
15
- * later stage, so the implementer builds to the amended contract while reviewers
16
- * still score the launch contract and mark the added work as unrequested scope.
17
- * Each stage therefore restates the amendments it received in its own handoff.
18
- */
19
- export const STEERING_PROPAGATION_CONTRACT = [
13
+ // dist/builtin/workflows/builtin/shared-prompts.ts
14
+ var PENDING_STAGE_DELIVERY_GUIDANCE_LINES = [
15
+ "Send material updates through Intercom to every affected workflow stage, including stages that have not started.",
16
+ "Atomic queues messages for known pending stages addressed as `<runId>:<stageKey>` and delivers them when their sessions initialize."
17
+ ];
18
+ var PENDING_STAGE_DELIVERY_GUIDANCE = PENDING_STAGE_DELIVERY_GUIDANCE_LINES.join(`
19
+ `);
20
+ var STEERING_PROPAGATION_CONTRACT = [
20
21
  "Steering propagation contract:",
21
22
  "- Mid-run user messages (steering, follow-ups, resume text) are authoritative and may amend this run's objective or acceptance criteria. Adopt an amendment as required behavior from the moment you receive it.",
22
23
  "- An amendment that stays in your session is lost. Restate every objective-relevant steering message in your final report or handoff artifact, verbatim when short, under an explicit `Contract amendments received` heading.",
23
24
  "- Keep user-authored amendments visibly separate from your own observations, so later stages can tell a required clause from an agent proposal.",
24
25
  "- Treat amendments inherited from an upstream stage as contract clauses. Cover them in acceptance and traceability work; never classify inherited user amendments as beyond_objective, unrequested scope, or speculative expansion.",
25
26
  "- If an amendment is ambiguous, or conflicts with the launch contract or another amendment, resolve it before implementing: ask through `intercom` when a supervisor or originating stage is reachable, otherwise state the conflict in your report and implement the narrowest reading consistent with the launch contract.",
26
- "- Propagate nothing else this way. Guidance about how to work, tool preferences, and your own improvement ideas are not amendments; those follow the scope discipline contract.",
27
- ].join("\n");
28
-
29
- /**
30
- * Add the steering propagation contract to a stage prompt. Builtin runners wrap
31
- * every `ctx.task` / `ctx.parallel` / `ctx.chain` prompt with this so the pattern
32
- * cannot be forgotten when a stage is added.
33
- *
34
- * Stage prompts in this package deliberately end with their `<instruction>`
35
- * section, which carries the strongest positional weight. The contract is
36
- * inserted immediately before that closing section rather than after it, so a
37
- * stage's final words remain its instruction.
38
- *
39
- * The contract is `keepContext`-protected because only the user may amend a run's contract,
40
- * and an amendment reaches later stages solely through this restatement duty. Compacted away,
41
- * the run silently reverts to the launch contract while the implementer builds to the amended
42
- * one — the exact split this pattern exists to prevent.
43
- */
44
- export function withSteeringPropagation(prompt: string): string {
45
- if (prompt.includes("<steering_propagation>")) return prompt;
46
- const tagged = `<steering_propagation>\n${keepContext(STEERING_PROPAGATION_CONTRACT)}\n</steering_propagation>`;
47
- const instructionAt = prompt.lastIndexOf("\n\n<instruction>");
48
- if (instructionAt === -1) return `${prompt}\n\n${tagged}`;
49
- return `${prompt.slice(0, instructionAt)}\n\n${tagged}${prompt.slice(instructionAt)}`;
27
+ ...PENDING_STAGE_DELIVERY_GUIDANCE_LINES.map((line) => `- ${line}`),
28
+ "- Propagate nothing else this way. Guidance about how to work, tool preferences, and your own improvement ideas are not amendments; those follow the scope discipline contract."
29
+ ].join(`
30
+ `);
31
+ function withSteeringPropagation(prompt) {
32
+ if (prompt.includes("<steering_propagation>"))
33
+ return prompt;
34
+ const tagged = `<steering_propagation>
35
+ ${keepContext(STEERING_PROPAGATION_CONTRACT)}
36
+ </steering_propagation>`;
37
+ const instructionAt = prompt.lastIndexOf(`
38
+
39
+ <instruction>`);
40
+ if (instructionAt === -1)
41
+ return `${prompt}
42
+
43
+ ${tagged}`;
44
+ return `${prompt.slice(0, instructionAt)}
45
+
46
+ ${tagged}${prompt.slice(instructionAt)}`;
50
47
  }
51
-
52
- export const REVIEWER_CALIBRATION_RULES = [
48
+ var REVIEWER_CALIBRATION_RULES = [
53
49
  "Trust observed output over the agent's narration.",
54
- 'Agent declarations of success ("done", "all tests pass") are ZERO evidence on their own.',
55
- ].join("\n");
56
-
57
- export const WORKER_PREFLIGHT_CONTRACT = [
50
+ 'Agent declarations of success ("done", "all tests pass") are ZERO evidence on their own.'
51
+ ].join(`
52
+ `);
53
+ var WORKER_PREFLIGHT_CONTRACT = [
58
54
  "Before implementation delegation, infer the checkout's language, framework, build system, and setup requirements from repository evidence rather than ecosystem assumptions.",
59
55
  "Inspect source layout, setup docs, manifests, lockfiles, toolchain and codegen files, CI/workflow configuration, scripts, and generated-artifact conventions for missing dependencies, generated files, toolchains, submodules, or other initialization artifacts.",
60
56
  "When setup is missing, run or delegate the documented setup before implementation; missing initialization is setup work, not a user handoff or implementation failure.",
61
- "If requirements are unclear, delegate focused discovery rather than guessing. If evidence-based discovery and setup attempts remain blocked, report the commands tried and exact evidence needed to continue.",
62
- ].join("\n");
63
-
64
- export const E2E_VERIFICATION_GUIDANCE = [
57
+ "If requirements are unclear, delegate focused discovery rather than guessing. If evidence-based discovery and setup attempts remain blocked, report the commands tried and exact evidence needed to continue."
58
+ ].join(`
59
+ `);
60
+ var E2E_VERIFICATION_GUIDANCE = [
65
61
  "Verify correctness end-to-end whenever practical for user-visible behavior; an executable scenario is stronger proof than code inspection, unit tests, or stage summaries alone.",
66
- "For web or frontend flows, including frontend changes whose correctness depends on backend/API behavior, use the playwright-cli skill or delegate with `skill: \"playwright-cli\"`; capture snapshot, screenshot, DOM, or network evidence suited to the objective.",
67
- "For TUI/terminal flows, use the tmux skill or delegate with `skill: \"tmux\"` to exercise the scenario and capture pane output.",
62
+ 'For web or frontend flows, including frontend changes whose correctness depends on backend/API behavior, use the playwright-cli skill or delegate with `skill: "playwright-cli"`; capture snapshot, screenshot, DOM, or network evidence suited to the objective.',
63
+ 'For TUI/terminal flows, use the tmux skill or delegate with `skill: "tmux"` to exercise the scenario and capture pane output.',
68
64
  "Assume credentials, auth, and environment access for playwright-cli/tmux E2E exist until a concrete attempt proves otherwise. Before calling E2E impractical, check existing sessions, config, env vars, and CLI auth, then attempt the launch or flow.",
69
- "If E2E remains impractical, record the commands attempted, observed failure output, smallest missing prerequisite, and narrower validation run; an unattempted assumption is never valid grounds to skip.",
70
- ].join("\n");
71
-
72
- /**
73
- * Code-quality verification is the lint/format/metrics/smells counterpart to
74
- * E2E_VERIFICATION_GUIDANCE, and is included at the same call sites so goal and
75
- * ralph stages — implementation, orchestrator, and reviewer alike — receive it.
76
- */
77
- export const CODE_QUALITY_VERIFICATION_GUIDANCE = [
78
- "For code-quality verification — linting, auto-formatting, complexity and duplication metrics, and code smells — use the qlty skill or delegate with `skill: \"qlty\"`; it drives one CLI across the repository's languages instead of ad-hoc per-tool linter invocations.",
65
+ "If E2E remains impractical, record the commands attempted, observed failure output, smallest missing prerequisite, and narrower validation run; an unattempted assumption is never valid grounds to skip."
66
+ ].join(`
67
+ `);
68
+ var CODE_QUALITY_VERIFICATION_GUIDANCE = [
69
+ 'For code-quality verification linting, auto-formatting, complexity and duplication metrics, and code smells use the qlty skill or delegate with `skill: "qlty"`; it drives one CLI across the repository\'s languages instead of ad-hoc per-tool linter invocations.',
79
70
  "Weight this higher when the objective asks for verifiers or high code quality: enable the qlty plugins that fit this codebase, then run the check/format/metrics/smells loop and act on what it reports.",
80
- "Repository-defined checks in AGENTS.md/CLAUDE.md, package scripts, and CI stay authoritative; qlty supplements them rather than replacing them, and its findings count as evidence only with the command and observed output recorded.",
81
- ].join("\n");
82
-
83
- /**
84
- * Repositories carry behavioral norms written docs never state — commit
85
- * signing, message style, changelog discipline, review etiquette — and they
86
- * are inferable from history. Included at the same goal/ralph call sites as
87
- * the E2E and code-quality guidance so implementers match inferred
88
- * conventions and reviewers check delivered work against them.
89
- */
90
- export const REPO_INTENT_MINING_GUIDANCE = [
71
+ "Repository-defined checks in AGENTS.md/CLAUDE.md, package scripts, and CI stay authoritative; qlty supplements them rather than replacing them, and its findings count as evidence only with the command and observed output recorded."
72
+ ].join(`
73
+ `);
74
+ var REPO_INTENT_MINING_GUIDANCE = [
91
75
  "Infer maintainer and requesting-user intent from repository behavior, not only written docs: mine git history (`git log`, `git log --show-signature`), merged PRs, issues and their comments, review comments, commit subjects and trailers, and CI/branch-protection config for unwritten conventions.",
92
76
  "Read for commit-signing habits, commit-message style and issue linking, changelog discipline, PR size and stacking norms, review etiquette, formatting and lint norms, and branch naming. Prefer the dominant, recent, intentional pattern over accidental drift; when signals conflict, the requesting user's own commits, PRs, and comments weigh highest — different users of one repository keep different preferences.",
93
77
  "Match inferred conventions in delivered work (for example, sign commits when the surrounding history is signed rather than skipping signing because no doc required it); in review, report deviations as convention findings backed by the mined evidence.",
94
- "Behavioral evidence fills gaps where the contract is silent; it never overrides the literal objective, acceptance criteria, or explicit AGENTS.md/CLAUDE.md guidance, and it does not license new contract requirements.",
95
- ].join("\n");
96
-
97
- export function renderE2eQaVideoReviewGuidance(
98
- knownVideoPath?: string,
99
- ): string {
100
- const target = knownVideoPath === undefined || knownVideoPath.length === 0
101
- ? "Look for QA E2E video references in the goal ledger, implementation receipt, implementation notes, orchestrator report, or other review context artifacts."
102
- : `Known QA E2E video path for this run: ${knownVideoPath}`;
78
+ "Behavioral evidence fills gaps where the contract is silent; it never overrides the literal objective, acceptance criteria, or explicit AGENTS.md/CLAUDE.md guidance, and it does not license new contract requirements."
79
+ ].join(`
80
+ `);
81
+ function renderE2eQaVideoReviewGuidance(knownVideoPath) {
82
+ const target = knownVideoPath === undefined || knownVideoPath.length === 0 ? "Look for QA E2E video references in the goal ledger, implementation receipt, implementation notes, orchestrator report, or other review context artifacts." : `Known QA E2E video path for this run: ${knownVideoPath}`;
103
83
  return [
104
84
  target,
105
85
  "Inspect the actual video before approving any claimed QA E2E evidence; a path, filename, transcript summary, or stage claim is not proof.",
106
86
  "Use available video/file tooling such as `fetch_content` on the local video path with an objective-focused prompt, or inspect representative frames and metadata when full analysis is unavailable.",
107
87
  "Confirm the video reflects the current repository/application state, exercises the objective-relevant user path through its expected result, and does not hide errors, stale UI, broken loading states, or skipped steps.",
108
88
  "For UI-applicable or full-stack changes, missing, stale, unreadable, or inconclusive video is missing E2E evidence unless the receipt or notes explain why video does not apply and provide adequate alternate end-to-end proof.",
109
- "Treat E2E skipped for assumed-missing credentials, auth, or environment access as missing evidence unless the implementation agent checked that state, attempted the launch or flow, and reported exact commands plus observed failure output.",
110
- ].join("\n");
89
+ "Treat E2E skipped for assumed-missing credentials, auth, or environment access as missing evidence unless the implementation agent checked that state, attempted the launch or flow, and reported exact commands plus observed failure output."
90
+ ].join(`
91
+ `);
111
92
  }
112
-
113
- /**
114
- * `keepContext`-protected: this is the run's immutable contract and its central prohibition
115
- * ("You may never widen the contract yourself"). A prohibition deleted from context reads as
116
- * permission, so losing it turns scope creep into apparently sanctioned work.
117
- */
118
- export const LITERAL_OBJECTIVE_CONTRACT = keepContext([
93
+ var LITERAL_OBJECTIVE_CONTRACT = keepContext([
119
94
  "Literal objective contract:",
120
95
  "- The objective and acceptance criteria are the sole literal source of required behavior; the run objective must not contradict them.",
121
96
  "- Only the user may change the contract. A mid-run user message — steering, a follow-up, or resume text — is authoritative: adopt it as required behavior from that point on, and carry it forward under the steering propagation contract. You may never widen the contract yourself; an improvement you thought of is deferred work, not a new criterion.",
@@ -123,40 +98,36 @@ export const LITERAL_OBJECTIVE_CONTRACT = keepContext([
123
98
  "- For an enumerated error, message, or rejection, prefer the widest plausible trigger over silently reinterpreting ambiguous nearby input. Narrow it only when the contract or pre-existing required tests explicitly require acceptance.",
124
99
  "- That loud-error preference applies only to enumerated errors. Otherwise accept permissively: do not invent behavior, restrictions, validation errors, required fields, uniqueness/format constraints, or follow-up requirements.",
125
100
  "- Produce named types, shapes, and formats exactly; do not substitute proxies, frozen collections, tuples-for-lists, or wrappers unless required because consumers may check identity.",
126
- "- Where behavior is unspecified, preserve input verbatim rather than normalizing, deduplicating, reordering, or rewriting it.",
127
- ].join("\n"));
128
-
129
- export const REVIEWER_SPEC_VS_OBJECTIVE_GUARD =
130
- "External spec/standard conformance alone does not make a wide trigger for an enumerated error defective; classify that spec-vs-objective tension as beyond_objective, not blocking.";
131
-
132
- export const REVIEWER_OVERIMPLEMENTATION_GUARD =
133
- "Treat unrequired validation errors, required fields, uniqueness/format constraints, immutability wrappers, and normalization as required_by_objective defects when they reject permitted inputs or change permitted shapes. Probe at least one contract-permitted input absent from implementation-authored tests.";
134
-
135
- export const ACCEPTANCE_MATRIX_CONTRACT = [
101
+ "- Where behavior is unspecified, preserve input verbatim rather than normalizing, deduplicating, reordering, or rewriting it."
102
+ ].join(`
103
+ `));
104
+ var REVIEWER_SPEC_VS_OBJECTIVE_GUARD = "External spec/standard conformance alone does not make a wide trigger for an enumerated error defective; classify that spec-vs-objective tension as beyond_objective, not blocking.";
105
+ var REVIEWER_OVERIMPLEMENTATION_GUARD = "Treat unrequired validation errors, required fields, uniqueness/format constraints, immutability wrappers, and normalization as required_by_objective defects when they reject permitted inputs or change permitted shapes. Probe at least one contract-permitted input absent from implementation-authored tests.";
106
+ var ACCEPTANCE_MATRIX_CONTRACT = [
136
107
  "Acceptance matrix:",
137
108
  "- Derive one row per explicit objective/criteria clause, requirement, named artifact, command, gate, invariant, deliverable, and literal example; map each to a current-checkout command, test, scenario, artifact inspection, or state assertion. Check literal examples character-for-character.",
138
109
  "- Record it in the first receipt/implementation notes, keep it current, map completion claims to current evidence, and neither add out-of-contract rows nor omit inconvenient ones.",
139
110
  "- Include constrained interface decisions: exact return/field identity, required versus optional fields, duplicate handling, ordering, and raw versus normalized text; when open, record the permissive/preserving choice.",
140
- "- For stateful work, enumerate states, legal transitions, cross-state invariants, and handling of illegal transitions/unexpected inputs; tie relevant rows to transition and invariant checks, not only happy-path end states.",
141
- ].join("\n");
142
-
143
- export const CONTRACT_FIDELITY_AUDIT = [
111
+ "- For stateful work, enumerate states, legal transitions, cross-state invariants, and handling of illegal transitions/unexpected inputs; tie relevant rows to transition and invariant checks, not only happy-path end states."
112
+ ].join(`
113
+ `);
114
+ var CONTRACT_FIDELITY_AUDIT = [
144
115
  "Contract-fidelity risk classes:",
145
116
  "- Select only classes supported by the literal contract and repository: exact public API/type identity; positive and negative build tags/features/configuration variants; schemas/generated artifacts and omitted/zero-value fields; states/transitions/invariants; configurable paths, working directories, precedence, and caller-controlled state; low-level APIs across feature flags; permitted omitted, empty, zero, duplicate, aliased, ordered, unusual, or verbatim-text inputs; and unenumerated errors.",
146
- "- Before claiming readiness, probe each applicable class against the current checkout. Fix divergence or record its evidence-based justification in the receipt/notes; do not manufacture requirements outside the literal contract.",
147
- ].join("\n");
148
-
149
- export const REVIEWER_INTERCOM_COORDINATION_PROTOCOL = [
117
+ "- Before claiming readiness, probe each applicable class against the current checkout. Fix divergence or record its evidence-based justification in the receipt/notes; do not manufacture requirements outside the literal contract."
118
+ ].join(`
119
+ `);
120
+ var REVIEWER_INTERCOM_COORDINATION_PROTOCOL = [
150
121
  "Concurrent reviewer coordination (constructive quorum):",
151
122
  "- At review start, use Intercom to discover sibling reviewers and share validation plans and check ownership.",
152
123
  "- Claim, serialize, announce, and release expensive or conflicting shared-checkout/environment work such as suites, builds, package operations, browser/E2E sessions, migrations, and generated-artifact steps; share reusable command evidence.",
153
124
  "- First, inspect independently and form a preliminary assessment before reading or relying on sibling findings or verdicts. After the exchange, inspect independently and return your own verdict rather than copying or deferring to sibling conclusions.",
154
125
  "- Then run exactly one bounded evidence-exchange round over Intercom: share your preliminary verdict, concise findings, and evidence; challenge blocking findings, surface defects a sibling missed, and correct objective/acceptance-criteria misreadings. Do not start a second round or continue substantive discussion.",
155
126
  "- Verdicts change only through concrete evidence, never through deference to a sibling's approval or rejection; inspect shared evidence yourself before deciding.",
156
- "- In `overall_explanation`, record whether deliberation changed your preliminary verdict and, if it did, which concrete evidence caused the change. If it did not, say so; return your own structured decision even when dissent remains.",
157
- ].join("\n");
158
-
159
- export const REVIEWER_INDEPENDENT_VERIFICATION_CONTRACT = [
127
+ "- In `overall_explanation`, record whether deliberation changed your preliminary verdict and, if it did, which concrete evidence caused the change. If it did not, say so; return your own structured decision even when dissent remains."
128
+ ].join(`
129
+ `);
130
+ var REVIEWER_INDEPENDENT_VERIFICATION_CONTRACT = [
160
131
  "Independent verification:",
161
132
  "- Before reading receipts, implementation-authored tests, or prior reviews, derive per-clause observable checks from the literal objective/criteria, including supported boundary, edge, negative, invalid, permitted-input, exact type/shape/text, and state-transition probes.",
162
133
  CONTRACT_FIDELITY_AUDIT,
@@ -164,60 +135,68 @@ export const REVIEWER_INDEPENDENT_VERIFICATION_CONTRACT = [
164
135
  "- Implementation-authored tests, snapshots, and receipts corroborate but never replace independently derived checks; exact API, build, or schema clauses require the applicable independent compile, type, build-variant, or schema probe.",
165
136
  "- A missing applicable compile/type/build/schema probe remains missing in requirements_traceability; explain it, add an objective-aligned finding when materially deficient, and set stop_review_loop=false.",
166
137
  "- For any missing, blocked, or failed material probe, record its command/scenario and observed result or limitation in overall_explanation and requirements_traceability, use the remaining-verification or finding fields, and set stop_review_loop=false. If tools or dependencies still prevent necessary verification after reasonable recovery, populate reviewer_error.",
167
- "- Before stop_review_loop=true, require overall_correctness to be patch is correct, every objective-relevant implementation and validation requirements_traceability entry proven, no blocking objective-aligned finding, direct evidence or a clear not-applicable justification for each applicable risk, and reviewer_error null or omitted. Otherwise set stop_review_loop=false and report the gap consistently.",
168
- ].join("\n");
169
-
170
- export const REGRESSION_EVIDENCE_CONTRACT = [
138
+ "- Before stop_review_loop=true, require overall_correctness to be patch is correct, every objective-relevant implementation and validation requirements_traceability entry proven, no blocking objective-aligned finding, direct evidence or a clear not-applicable justification for each applicable risk, and reviewer_error null or omitted. Otherwise set stop_review_loop=false and report the gap consistently."
139
+ ].join(`
140
+ `);
141
+ var REGRESSION_EVIDENCE_CONTRACT = [
171
142
  "Durable regression evidence:",
172
143
  "- A reproduced defect is fixed only when a focused test or repeatable check covers the failing scenario and passes after the fix (and fails before it or demonstrably exercises it). Persist it in the test suite where norms allow; otherwise record an exact rerunnable command and observed output in the receipt/notes.",
173
- "- Keep a reproduced finding unresolved when its fix has only a one-off manual check.",
174
- ].join("\n");
175
-
176
- export const FINDINGS_CONSOLIDATION_CONTRACT = [
144
+ "- Keep a reproduced finding unresolved when its fix has only a one-off manual check."
145
+ ].join(`
146
+ `);
147
+ var FINDINGS_CONSOLIDATION_CONTRACT = [
177
148
  "Treat the latest review round as one consolidated batch: read all blocking findings, group shared root causes, and repair the full batch with validation and durable regression evidence in this turn.",
178
- "Defer only a genuinely blocked or contract-contradicting finding, recording the reason in the receipt.",
179
- ].join("\n");
180
-
181
- /**
182
- * `keepContext`-protected: every clause here is a prohibition, and prohibitions are the class
183
- * compaction erodes first — they are terse, stated once, and low-density next to the objective
184
- * they bound. Losing this reads as license to keep going.
185
- */
186
- export const SCOPE_DISCIPLINE_CONTRACT = keepContext([
149
+ "Defer only a genuinely blocked or contract-contradicting finding, recording the reason in the receipt."
150
+ ].join(`
151
+ `);
152
+ var SCOPE_DISCIPLINE_CONTRACT = keepContext([
187
153
  "Scope discipline:",
188
154
  "- Before writing code, state the goal in one sentence and list the acceptance criteria. That list is the contract. Freeze it.",
189
- "- Done means the contract, not \"good.\" When all criteria pass, stop. Polish, refactors, and \"while I'm here\" fixes are new work, not this work.",
155
+ `- Done means the contract, not "good." When all criteria pass, stop. Polish, refactors, and "while I'm here" fixes are new work, not this work.`,
190
156
  "- Every addition must trace to a criterion. If you cannot point at the criterion a change serves, do not make it. Log it instead.",
191
157
  "- Keep a deferred list, not a growing diff. When you notice a bug, smell, or missing feature outside the contract, write one line in a deferred note and move on. Surface it at the end.",
192
158
  "- Distinguish blockers from improvements. Change scope only if a criterion is impossible or wrong as written — and say so explicitly before proceeding; never silently absorb the work.",
193
- "- Watch for the tells. \"It would be cleaner if...\", \"we should also...\", \"this really ought to...\" mean you are about to move the goalpost. Stop and check the contract.",
159
+ '- Watch for the tells. "It would be cleaner if...", "we should also...", "this really ought to..." mean you are about to move the goalpost. Stop and check the contract.',
194
160
  "- Prefer the smallest diff that satisfies the contract: fewer files touched, fewer abstractions introduced, no speculative generality for futures nobody asked for.",
195
- "- Report three things at the end: what the contract was, evidence each criterion passes, and the deferred list. Scope changes belong in the report, never in the diff.",
196
- ].join("\n"));
197
-
198
- export const EVIDENCE_CLOSURE_POLICY = [
161
+ "- Report three things at the end: what the contract was, evidence each criterion passes, and the deferred list. Scope changes belong in the report, never in the diff."
162
+ ].join(`
163
+ `));
164
+ var EVIDENCE_CLOSURE_POLICY = [
199
165
  "Convergence flag (stop_review_loop):",
200
166
  "- stop_review_loop is the single authoritative convergence signal; the harness trusts it without recomputing approval from findings, priorities, or requirements_traceability.",
201
167
  "- Derive stop_review_loop=false while any objective-relevant blocking work remains: a P0/P1/P2 finding, a required_by_objective finding at any priority including P3, or an unproven implementation/validation requirement.",
202
168
  "- Derive stop_review_loop=true when independent verification proves implementation and validation and only non-blocking items remain: consistent_with_objective P3 items, beyond_objective/contradicts_objective observations, an authorized post-approval PR/MR/review action, or reviewer quorum. Never hold it false for those items.",
203
- "- If the bounded loop ends first, preserve unresolved findings and remaining work for a human rather than relabeling them.",
204
- ].join("\n");
205
-
206
- /**
207
- * `keepContext`-protected: this binds the stage to a specific checkout, and a checkout is
208
- * exactly the kind of identifier a stage must not lose. Compacted away during a long run, an
209
- * agent hitting a lock or dirty state invents a second worktree and the delivered delta lands
210
- * somewhere the reviewers never look. It is two lines, so protection costs almost nothing.
211
- */
212
- export const WORKTREE_DISCIPLINE_CONTRACT = keepContext([
169
+ "- If the bounded loop ends first, preserve unresolved findings and remaining work for a human rather than relabeling them."
170
+ ].join(`
171
+ `);
172
+ var WORKTREE_DISCIPLINE_CONTRACT = keepContext([
213
173
  "Work in the workflow-designated checkout. Do not create another worktree, clone, or repository copy unless the task requests it; conflicts, locks, dirty state, and failed commands do not authorize one.",
214
- "Bring required work found elsewhere into this checkout by applying, cherry-picking, or replaying it before continuing.",
215
- ].join("\n"));
216
-
217
- export const REVIEW_CODE_DELTA_CONTRACT = [
174
+ "Bring required work found elsewhere into this checkout by applying, cherry-picking, or replaying it before continuing."
175
+ ].join(`
176
+ `));
177
+ var REVIEW_CODE_DELTA_CONTRACT = [
218
178
  "Code delta integrity:",
219
179
  "- Inspect the delivered checkout with version-control tooling (for git: `git worktree list`, `git status --short`, baseline diff, staged diff, and untracked files) and prove an objective-related delta exists before trusting receipts.",
220
180
  "- If summaries claim implementation but the checkout lacks it, return a blocking [P0] required_by_objective finding and require the work to be brought here. Never set stop_review_loop=true for an empty or unrelated implementation delta.",
221
181
  "- Unless the objective forbids committing, uncommitted claimed-ready work remains work: require a commit or intentional discard so delivery is durable.",
222
- "- Treat modification, rename, or deletion of pre-existing tests or test functions as a finding requiring literal-contract justification; validating existing tests means running, not editing, them.",
223
- ].join("\n");
182
+ "- Treat modification, rename, or deletion of pre-existing tests or test functions as a finding requiring literal-contract justification; validating existing tests means running, not editing, them."
183
+ ].join(`
184
+ `);
185
+
186
+ // dist/builtin/workflows/builtin/steering-context.ts
187
+ function withPromptContract(options) {
188
+ return options.prompt === undefined ? options : { ...options, prompt: withSteeringPropagation(options.prompt) };
189
+ }
190
+ function withStepContract(step) {
191
+ const withPrompt = step.prompt === undefined ? step : { ...step, prompt: withSteeringPropagation(step.prompt) };
192
+ return withPrompt.task === undefined ? withPrompt : { ...withPrompt, task: withSteeringPropagation(withPrompt.task) };
193
+ }
194
+ function withSteeringPropagationContext(ctx) {
195
+ const wrapped = Object.create(ctx);
196
+ wrapped.task = (name, options) => ctx.task(name, withPromptContract(options));
197
+ wrapped.chain = (steps, options) => ctx.chain(steps.map(withStepContract), options);
198
+ wrapped.parallel = (steps, options) => ctx.parallel(steps.map(withStepContract), options);
199
+ return wrapped;
200
+ }
201
+
202
+ export { keepContext, REVIEWER_CALIBRATION_RULES, WORKER_PREFLIGHT_CONTRACT, E2E_VERIFICATION_GUIDANCE, CODE_QUALITY_VERIFICATION_GUIDANCE, REPO_INTENT_MINING_GUIDANCE, renderE2eQaVideoReviewGuidance, LITERAL_OBJECTIVE_CONTRACT, REVIEWER_SPEC_VS_OBJECTIVE_GUARD, REVIEWER_OVERIMPLEMENTATION_GUARD, ACCEPTANCE_MATRIX_CONTRACT, CONTRACT_FIDELITY_AUDIT, REVIEWER_INTERCOM_COORDINATION_PROTOCOL, REVIEWER_INDEPENDENT_VERIFICATION_CONTRACT, REGRESSION_EVIDENCE_CONTRACT, FINDINGS_CONSOLIDATION_CONTRACT, SCOPE_DISCIPLINE_CONTRACT, EVIDENCE_CLOSURE_POLICY, WORKTREE_DISCIPLINE_CONTRACT, REVIEW_CODE_DELTA_CONTRACT, withSteeringPropagationContext };
@@ -0,0 +1,199 @@
1
+ import {
2
+ stableArtifactRoot
3
+ } from "./chunk-wpckd35c.js";
4
+ import {
5
+ workflow
6
+ } from "./chunk-bfkmzv9h.js";
7
+ import {
8
+ withSteeringPropagationContext
9
+ } from "./chunk-0x6e303p.js";
10
+
11
+ // dist/builtin/workflows/builtin/fan-out-and-synthesize.ts
12
+ import { Type as Type2 } from "typebox";
13
+
14
+ // dist/builtin/workflows/builtin/fan-out-and-synthesize-runner.ts
15
+ import { writeFile } from "node:fs/promises";
16
+ import { join } from "node:path";
17
+ import { Type } from "typebox";
18
+
19
+ // dist/builtin/workflows/builtin/fan-out-and-synthesize-prompts.ts
20
+ var GROUNDED_REPORTING = "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.";
21
+ var READABLE_REPORT = "Lead with the outcome. Keep facts, decisions, caveats, and next steps; drop background and repetition. Use complete, readable sentences rather than compressed fragments.";
22
+ function partitionPrompt(prompt, maxBranches) {
23
+ return `<role>
24
+ You partition work into independent evidence-producing branches.
25
+ </role>
26
+
27
+ <success_criteria>
28
+ The plan has between 1 and ${maxBranches} non-overlapping partitions whose labels and objectives are self-contained.
29
+ </success_criteria>
30
+
31
+ <decision_rules>
32
+ Split by files, sources, claims, candidates, or work items that can be evaluated independently. Avoid duplicate scope and identify boundaries explicitly. Stop when every required part of the task belongs to one partition.
33
+ </decision_rules>
34
+
35
+ <output_format>
36
+ Return only the structured result requested by the schema, with concise labels and self-contained objectives.
37
+ </output_format>
38
+
39
+ <objective>
40
+ Partition this task: ${prompt}
41
+ </objective>`;
42
+ }
43
+ function branchPrompt(input) {
44
+ return `<overall_task>
45
+ ${input.prompt}
46
+ </overall_task>
47
+
48
+ <role>
49
+ You own one independent branch of a larger task. Your artifact lets a synthesizer audit this branch without its conversation context.
50
+ </role>
51
+
52
+ <success_criteria>
53
+ Cite concrete files, sources, commands, or other observable evidence, distinguish findings from uncertainty, and produce a standalone artifact.
54
+ </success_criteria>
55
+
56
+ <stop_rules>
57
+ Stop when the branch objective is supported or when unresolved uncertainty and the evidence needed to resolve it are explicit.
58
+ </stop_rules>
59
+
60
+ <output_format>
61
+ Markdown with Scope, Findings, Evidence, Conflicts or uncertainty, and Recommendations headings. ${READABLE_REPORT}
62
+ ${GROUNDED_REPORTING}
63
+ </output_format>
64
+
65
+ <branch>
66
+ Investigate only ${input.label}: ${input.objective}
67
+ </branch>`;
68
+ }
69
+ function synthesisPrompt(prompt, manifestPath) {
70
+ return `<artifact_contract>
71
+ Read ${manifestPath} first, then read every branch artifact listed there. Do not omit a completed branch and do not assume access to branch conversations.
72
+ </artifact_contract>
73
+
74
+ <role>
75
+ You synthesize independent branch artifacts at a strict barrier. The final reader needs conclusions traceable to branch evidence rather than majority vote.
76
+ </role>
77
+
78
+ <success_criteria>
79
+ Deduplicate overlapping findings, explicitly resolve or preserve conflicting claims, retain material uncertainty, and cite branch labels and artifact paths for important conclusions.
80
+ </success_criteria>
81
+
82
+ <stop_rules>
83
+ Stop after every completed branch is accounted for and each material conflict is resolved or preserved as uncertainty.
84
+ </stop_rules>
85
+
86
+ <output_format>
87
+ Markdown with Executive synthesis, Consolidated findings, Conflicts and resolutions, Evidence index, and Remaining uncertainty headings. ${READABLE_REPORT}
88
+ ${GROUNDED_REPORTING}
89
+ </output_format>
90
+
91
+ <objective>
92
+ Produce the final answer for: ${prompt}
93
+ </objective>`;
94
+ }
95
+
96
+ // dist/builtin/workflows/builtin/fan-out-and-synthesize-runner.ts
97
+ var partitionSchema = Type.Object({
98
+ partitions: Type.Array(Type.Object({
99
+ label: Type.String({ minLength: 1 }),
100
+ objective: Type.String({ minLength: 1 })
101
+ }, { additionalProperties: false }), { minItems: 1, maxItems: 12 })
102
+ }, { additionalProperties: false });
103
+ function safeName(value, index) {
104
+ const normalized = value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
105
+ return `${String(index + 1).padStart(2, "0")}-${normalized || "branch"}`;
106
+ }
107
+ function parsedPartitions(value, limit, prompt) {
108
+ if (typeof value !== "object" || value === null || !("partitions" in value) || !Array.isArray(value.partitions)) {
109
+ return [{ label: "whole-task", objective: prompt }];
110
+ }
111
+ const result = [];
112
+ for (const candidate of value.partitions) {
113
+ if (typeof candidate !== "object" || candidate === null || !("label" in candidate) || !("objective" in candidate))
114
+ continue;
115
+ const label = String(candidate.label).trim();
116
+ const objective = String(candidate.objective).trim();
117
+ if (label !== "" && objective !== "")
118
+ result.push({ label, objective });
119
+ if (result.length >= limit)
120
+ break;
121
+ }
122
+ return result.length > 0 ? result : [{ label: "whole-task", objective: prompt }];
123
+ }
124
+ async function runFanOutAndSynthesize(ctx) {
125
+ const artifactDir = await stableArtifactRoot(ctx, "fan-out-and-synthesize");
126
+ const plan = await ctx.task("partition", {
127
+ prompt: partitionPrompt(ctx.inputs.prompt, ctx.inputs.max_branches),
128
+ schema: partitionSchema,
129
+ context: "fresh"
130
+ });
131
+ const partitions = parsedPartitions(plan.structured, ctx.inputs.max_branches, ctx.inputs.prompt);
132
+ const partitionPath = join(artifactDir, "partition-plan.json");
133
+ await writeFile(partitionPath, JSON.stringify({ task: ctx.inputs.prompt, partitions }, null, 2));
134
+ const branchPaths = partitions.map((partition, index) => join(artifactDir, `branch-${safeName(partition.label, index)}.md`));
135
+ const steps = partitions.map((partition, index) => ({
136
+ name: `branch-${safeName(partition.label, index)}`,
137
+ prompt: branchPrompt({ prompt: ctx.inputs.prompt, ...partition }),
138
+ context: "fresh",
139
+ reads: [partitionPath],
140
+ output: branchPaths[index],
141
+ outputMode: "file-only"
142
+ }));
143
+ await ctx.parallel(steps, { concurrency: Math.min(ctx.inputs.max_concurrency, partitions.length), failFast: false });
144
+ const manifestPath = join(artifactDir, "manifest.json");
145
+ await writeFile(manifestPath, JSON.stringify({
146
+ task: ctx.inputs.prompt,
147
+ partition_plan: partitionPath,
148
+ branches: partitions.map((partition, index) => ({ ...partition, artifact_path: branchPaths[index] }))
149
+ }, null, 2));
150
+ const synthesisPath = join(artifactDir, "synthesis.md");
151
+ const synthesis = await ctx.task("synthesize", {
152
+ prompt: synthesisPrompt(ctx.inputs.prompt, manifestPath),
153
+ context: "fresh",
154
+ reads: [manifestPath, ...branchPaths],
155
+ output: synthesisPath,
156
+ outputMode: "file-only"
157
+ });
158
+ return {
159
+ result: synthesis.text,
160
+ partitions: partitions.map((partition) => partition.label),
161
+ branch_artifact_paths: branchPaths,
162
+ synthesis_path: synthesisPath,
163
+ artifact_dir: artifactDir,
164
+ manifest_path: manifestPath
165
+ };
166
+ }
167
+
168
+ // dist/builtin/workflows/builtin/fan-out-and-synthesize.ts
169
+ var fan_out_and_synthesize_default = workflow({
170
+ name: "fan-out-and-synthesize",
171
+ description: "Partition a task, run bounded independent artifact branches, then synthesize all evidence at an explicit barrier.",
172
+ heartbeatIntervalMinutes: 15,
173
+ inputs: {
174
+ prompt: Type2.String({ description: "Task to partition, investigate, and synthesize." }),
175
+ max_branches: Type2.Integer({
176
+ minimum: 1,
177
+ maximum: 12,
178
+ default: 4,
179
+ description: "Maximum number of independent partitions produced and executed."
180
+ }),
181
+ max_concurrency: Type2.Integer({
182
+ minimum: 1,
183
+ maximum: 12,
184
+ default: 4,
185
+ description: "Maximum number of branch agents running concurrently."
186
+ })
187
+ },
188
+ outputs: {
189
+ result: Type2.String({ description: "Compact reference to the evidence-citing synthesis artifact; read `synthesis_path` for the full report." }),
190
+ partitions: Type2.Array(Type2.String(), { description: "Ordered labels for executed partitions." }),
191
+ branch_artifact_paths: Type2.Array(Type2.String(), { description: "Ordered branch artifact paths consumed by synthesis." }),
192
+ synthesis_path: Type2.String({ description: "Final synthesis artifact path." }),
193
+ artifact_dir: Type2.String({ description: "Per-run artifact directory." }),
194
+ manifest_path: Type2.String({ description: "Barrier manifest linking partitions to branch artifacts." })
195
+ },
196
+ run: async (ctx) => await runFanOutAndSynthesize(withSteeringPropagationContext(ctx))
197
+ });
198
+
199
+ export { fan_out_and_synthesize_default };