@bastani/atomic 0.9.16-alpha.6 → 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 (214) 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/CHANGELOG.md +6 -0
  20. package/dist/builtin/subagents/package.json +1 -1
  21. package/dist/builtin/subagents/skills/qlty/SKILL.md +123 -0
  22. package/dist/builtin/subagents/skills/qlty/references/coding-with-ai-agents.md +64 -0
  23. package/dist/builtin/subagents/skills/qlty/references/commands.md +291 -0
  24. package/dist/builtin/subagents/skills/qlty/references/plugins-and-extensions.md +228 -0
  25. package/dist/builtin/subagents/skills/qlty/references/quickstart.md +110 -0
  26. package/dist/builtin/subagents/src/extension/index.bundle.mjs +173 -51
  27. package/dist/builtin/web-access/index.bundle.mjs +109 -35
  28. package/dist/builtin/web-access/package.json +1 -1
  29. package/dist/builtin/workflows/CHANGELOG.md +23 -0
  30. package/dist/builtin/workflows/README.md +40 -37
  31. package/dist/builtin/workflows/builtin/adversarial-verification.js +13 -0
  32. package/dist/builtin/workflows/builtin/{shared-prompts.ts → chunk-0x6e303p.js} +137 -133
  33. package/dist/builtin/workflows/builtin/chunk-29wrp38a.js +199 -0
  34. package/dist/builtin/workflows/builtin/chunk-2dqb5s2q.js +602 -0
  35. package/dist/builtin/workflows/builtin/chunk-4febxsv4.js +264 -0
  36. package/dist/builtin/workflows/builtin/chunk-5n10x7j2.js +69730 -0
  37. package/dist/builtin/workflows/builtin/chunk-5wgwscd0.js +4 -0
  38. package/dist/builtin/workflows/builtin/chunk-6fqs7c01.js +155 -0
  39. package/dist/builtin/workflows/builtin/chunk-7430zyas.js +126 -0
  40. package/dist/builtin/workflows/builtin/chunk-7at6dnkr.js +33 -0
  41. package/dist/builtin/workflows/builtin/chunk-82ha8p41.js +175 -0
  42. package/dist/builtin/workflows/builtin/chunk-bfkmzv9h.js +156 -0
  43. package/dist/builtin/workflows/builtin/chunk-c53y8bdh.js +345 -0
  44. package/dist/builtin/workflows/builtin/chunk-cdtd3m3w.js +529 -0
  45. package/dist/builtin/workflows/builtin/chunk-cg9tmks0.js +206 -0
  46. package/dist/builtin/workflows/builtin/chunk-hdpj1dkw.js +2447 -0
  47. package/dist/builtin/workflows/builtin/chunk-hzzn6adg.js +221 -0
  48. package/dist/builtin/workflows/builtin/chunk-nqr34qp3.js +1061 -0
  49. package/dist/builtin/workflows/builtin/chunk-qwzvgxnq.js +404 -0
  50. package/dist/builtin/workflows/builtin/chunk-qx2ptjs3.js +215 -0
  51. package/dist/builtin/workflows/builtin/chunk-v04c5qmd.js +1207 -0
  52. package/dist/builtin/workflows/builtin/chunk-wpckd35c.js +12 -0
  53. package/dist/builtin/workflows/builtin/chunk-x2ghn0je.js +4110 -0
  54. package/dist/builtin/workflows/builtin/chunk-zf28603f.js +1080 -0
  55. package/dist/builtin/workflows/builtin/classify-and-act.js +12 -0
  56. package/dist/builtin/workflows/builtin/fan-out-and-synthesize.js +10 -0
  57. package/dist/builtin/workflows/builtin/generate-and-filter.js +12 -0
  58. package/dist/builtin/workflows/builtin/goal.js +16 -0
  59. package/dist/builtin/workflows/builtin/index.js +49 -0
  60. package/dist/builtin/workflows/builtin/loop-until-done.js +12 -0
  61. package/dist/builtin/workflows/builtin/open-claude-design.js +11 -0
  62. package/dist/builtin/workflows/builtin/ralph.js +16 -0
  63. package/dist/builtin/workflows/builtin/steering-context.d.ts +6 -0
  64. package/dist/builtin/workflows/builtin/steering-context.js +7 -0
  65. package/dist/builtin/workflows/builtin/tournament.js +13 -0
  66. package/dist/builtin/workflows/package.json +10 -7
  67. package/dist/builtin/workflows/src/authoring/typebox-defaults.d.ts +41 -0
  68. package/dist/builtin/workflows/src/extension/index.bundle.mjs +1250 -428
  69. package/dist/builtin/workflows/src/{index.bundle.mjs → index.js} +956 -427
  70. package/dist/builtin/workflows/src/shared/authoring-contract-stage.d.ts +403 -0
  71. package/dist/builtin/workflows/src/shared/authoring-contract-ui.d.ts +327 -0
  72. package/dist/builtin/workflows/src/shared/budget.d.ts +67 -0
  73. package/dist/builtin/workflows/src/shared/workflow-authoring-types.d.ts +60 -0
  74. package/dist/builtin/workflows/src/shared/workflow-heartbeat-contract.d.ts +21 -0
  75. package/dist/core/agent-session-custom-message-commit.d.ts.map +1 -1
  76. package/dist/core/agent-session-custom-message-commit.js +12 -5
  77. package/dist/core/agent-session-custom-message-commit.js.map +1 -1
  78. package/dist/core/agent-session-persistent-custom-messages.d.ts.map +1 -1
  79. package/dist/core/agent-session-persistent-custom-messages.js +2 -0
  80. package/dist/core/agent-session-persistent-custom-messages.js.map +1 -1
  81. package/dist/core/agent-session.d.ts.map +1 -1
  82. package/dist/core/agent-session.js +2 -1
  83. package/dist/core/agent-session.js.map +1 -1
  84. package/dist/core/auth-storage.d.ts +2 -0
  85. package/dist/core/auth-storage.d.ts.map +1 -1
  86. package/dist/core/auth-storage.js +4 -0
  87. package/dist/core/auth-storage.js.map +1 -1
  88. package/dist/core/builtin-install-layout.d.ts +1 -1
  89. package/dist/core/builtin-install-layout.d.ts.map +1 -1
  90. package/dist/core/builtin-install-layout.js +1 -1
  91. package/dist/core/builtin-install-layout.js.map +1 -1
  92. package/dist/core/codex-fast-mode.d.ts +10 -7
  93. package/dist/core/codex-fast-mode.d.ts.map +1 -1
  94. package/dist/core/codex-fast-mode.js +31 -13
  95. package/dist/core/codex-fast-mode.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/index.d.ts +1 -1
  100. package/dist/core/extensions/index.d.ts.map +1 -1
  101. package/dist/core/extensions/index.js.map +1 -1
  102. package/dist/core/extensions/loader-virtual-modules.d.ts.map +1 -1
  103. package/dist/core/extensions/loader-virtual-modules.js +6 -1
  104. package/dist/core/extensions/loader-virtual-modules.js.map +1 -1
  105. package/dist/core/model-runtime.d.ts +2 -0
  106. package/dist/core/model-runtime.d.ts.map +1 -1
  107. package/dist/core/model-runtime.js +4 -0
  108. package/dist/core/model-runtime.js.map +1 -1
  109. package/dist/core/runtime-credentials.d.ts +1 -0
  110. package/dist/core/runtime-credentials.d.ts.map +1 -1
  111. package/dist/core/runtime-credentials.js +8 -0
  112. package/dist/core/runtime-credentials.js.map +1 -1
  113. package/dist/core/sdk.d.ts.map +1 -1
  114. package/dist/core/sdk.js +5 -5
  115. package/dist/core/sdk.js.map +1 -1
  116. package/dist/core/session-manager-storage.d.ts +2 -0
  117. package/dist/core/session-manager-storage.d.ts.map +1 -1
  118. package/dist/core/session-manager-storage.js +4 -2
  119. package/dist/core/session-manager-storage.js.map +1 -1
  120. package/dist/core/slash-commands.js +1 -1
  121. package/dist/core/slash-commands.js.map +1 -1
  122. package/dist/core/workflow-stage-admission.d.ts +6 -1
  123. package/dist/core/workflow-stage-admission.d.ts.map +1 -1
  124. package/dist/core/workflow-stage-admission.js +8 -9
  125. package/dist/core/workflow-stage-admission.js.map +1 -1
  126. package/dist/index.d.ts +0 -1
  127. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  128. package/dist/modes/interactive/components/footer.js +1 -1
  129. package/dist/modes/interactive/components/footer.js.map +1 -1
  130. package/dist/modes/interactive/interactive-autocomplete.js +1 -1
  131. package/dist/modes/interactive/interactive-autocomplete.js.map +1 -1
  132. package/dist/modes/interactive/interactive-startup.js +1 -1
  133. package/dist/modes/interactive/interactive-startup.js.map +1 -1
  134. package/dist/modes/interactive-engine/isolated-runtime.d.ts +4 -0
  135. package/dist/modes/interactive-engine/isolated-runtime.d.ts.map +1 -1
  136. package/dist/modes/interactive-engine/isolated-runtime.js +69 -10
  137. package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
  138. package/dist/modes/rpc/rpc-client-api.d.ts +18 -2
  139. package/dist/modes/rpc/rpc-client-api.d.ts.map +1 -1
  140. package/dist/modes/rpc/rpc-client-api.js +33 -5
  141. package/dist/modes/rpc/rpc-client-api.js.map +1 -1
  142. package/dist/modes/rpc/rpc-command-handler.d.ts.map +1 -1
  143. package/dist/modes/rpc/rpc-command-handler.js +8 -4
  144. package/dist/modes/rpc/rpc-command-handler.js.map +1 -1
  145. package/dist/modes/rpc/rpc-types.d.ts +13 -0
  146. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  147. package/dist/modes/rpc/rpc-types.js.map +1 -1
  148. package/docs/intercom.md +15 -6
  149. package/docs/packages.md +2 -2
  150. package/docs/providers.md +8 -3
  151. package/docs/quickstart.md +3 -2
  152. package/docs/rpc.md +21 -4
  153. package/docs/settings.md +6 -4
  154. package/docs/skills.md +4 -0
  155. package/docs/subagents.md +1 -1
  156. package/docs/usage.md +1 -1
  157. package/docs/workflows.md +112 -239
  158. package/npm-shrinkwrap.json +32 -32
  159. package/package.json +9 -13
  160. package/dist/builtin/workflows/ambient.d.ts +0 -61
  161. package/dist/builtin/workflows/builtin/adversarial-verification-prompts.ts +0 -26
  162. package/dist/builtin/workflows/builtin/adversarial-verification-runner.ts +0 -391
  163. package/dist/builtin/workflows/builtin/adversarial-verification.ts +0 -34
  164. package/dist/builtin/workflows/builtin/classify-and-act-prompts.ts +0 -14
  165. package/dist/builtin/workflows/builtin/classify-and-act-runner.ts +0 -108
  166. package/dist/builtin/workflows/builtin/classify-and-act.ts +0 -40
  167. package/dist/builtin/workflows/builtin/fan-out-and-synthesize-prompts.ts +0 -14
  168. package/dist/builtin/workflows/builtin/fan-out-and-synthesize-runner.ts +0 -96
  169. package/dist/builtin/workflows/builtin/fan-out-and-synthesize.ts +0 -37
  170. package/dist/builtin/workflows/builtin/generate-and-filter-prompts.ts +0 -41
  171. package/dist/builtin/workflows/builtin/generate-and-filter-runner.ts +0 -90
  172. package/dist/builtin/workflows/builtin/generate-and-filter.ts +0 -31
  173. package/dist/builtin/workflows/builtin/goal-artifacts.ts +0 -64
  174. package/dist/builtin/workflows/builtin/goal-convergence.ts +0 -87
  175. package/dist/builtin/workflows/builtin/goal-ledger.ts +0 -139
  176. package/dist/builtin/workflows/builtin/goal-models.ts +0 -72
  177. package/dist/builtin/workflows/builtin/goal-orchestrator-prompts.ts +0 -94
  178. package/dist/builtin/workflows/builtin/goal-prompts.ts +0 -211
  179. package/dist/builtin/workflows/builtin/goal-reducer.ts +0 -176
  180. package/dist/builtin/workflows/builtin/goal-reports.ts +0 -76
  181. package/dist/builtin/workflows/builtin/goal-reverify.ts +0 -305
  182. package/dist/builtin/workflows/builtin/goal-review.ts +0 -139
  183. package/dist/builtin/workflows/builtin/goal-runner.ts +0 -504
  184. package/dist/builtin/workflows/builtin/goal-schemas.ts +0 -89
  185. package/dist/builtin/workflows/builtin/goal-types.ts +0 -164
  186. package/dist/builtin/workflows/builtin/goal.ts +0 -78
  187. package/dist/builtin/workflows/builtin/index.ts +0 -16
  188. package/dist/builtin/workflows/builtin/loop-until-done-prompts.ts +0 -87
  189. package/dist/builtin/workflows/builtin/loop-until-done-runner.ts +0 -282
  190. package/dist/builtin/workflows/builtin/loop-until-done.ts +0 -51
  191. package/dist/builtin/workflows/builtin/open-claude-design-live-protocol.ts +0 -305
  192. package/dist/builtin/workflows/builtin/open-claude-design-phases.ts +0 -337
  193. package/dist/builtin/workflows/builtin/open-claude-design-runner.ts +0 -347
  194. package/dist/builtin/workflows/builtin/open-claude-design-setup.ts +0 -313
  195. package/dist/builtin/workflows/builtin/open-claude-design-utils.ts +0 -311
  196. package/dist/builtin/workflows/builtin/open-claude-design.ts +0 -57
  197. package/dist/builtin/workflows/builtin/pattern-artifact-root.ts +0 -28
  198. package/dist/builtin/workflows/builtin/progress-scoring.ts +0 -230
  199. package/dist/builtin/workflows/builtin/ralph-core.ts +0 -449
  200. package/dist/builtin/workflows/builtin/ralph-forked-prompts.ts +0 -100
  201. package/dist/builtin/workflows/builtin/ralph-models.ts +0 -183
  202. package/dist/builtin/workflows/builtin/ralph-review-gate.ts +0 -103
  203. package/dist/builtin/workflows/builtin/ralph-reviewer-prompt.ts +0 -100
  204. package/dist/builtin/workflows/builtin/ralph-runner.ts +0 -455
  205. package/dist/builtin/workflows/builtin/ralph.ts +0 -82
  206. package/dist/builtin/workflows/builtin/review-convergence.ts +0 -229
  207. package/dist/builtin/workflows/builtin/selection-math.ts +0 -156
  208. package/dist/builtin/workflows/builtin/steering-context.ts +0 -51
  209. package/dist/builtin/workflows/builtin/tournament-prompts.ts +0 -70
  210. package/dist/builtin/workflows/builtin/tournament-runner.ts +0 -400
  211. package/dist/builtin/workflows/builtin/tournament.ts +0 -73
  212. package/dist/builtin/workflows/builtin/verification-criteria.ts +0 -330
  213. package/dist/builtin/workflows/builtin/verification-prompts.ts +0 -206
  214. package/dist/builtin/workflows/builtin/verification-usage.ts +0 -44
@@ -0,0 +1,345 @@
1
+ import {
2
+ stableArtifactRoot
3
+ } from "./chunk-wpckd35c.js";
4
+ import {
5
+ classify_trend,
6
+ score_progress
7
+ } from "./chunk-6fqs7c01.js";
8
+ import {
9
+ workflow
10
+ } from "./chunk-bfkmzv9h.js";
11
+ import {
12
+ withSteeringPropagationContext
13
+ } from "./chunk-0x6e303p.js";
14
+
15
+ // dist/builtin/workflows/builtin/loop-until-done.ts
16
+ import { Type as Type2 } from "typebox";
17
+
18
+ // dist/builtin/workflows/builtin/loop-until-done-runner.ts
19
+ import { mkdir, writeFile } from "node:fs/promises";
20
+ import { join } from "node:path";
21
+ import { Type } from "typebox";
22
+
23
+ // dist/builtin/workflows/builtin/loop-until-done-prompts.ts
24
+ 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.";
25
+ 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.";
26
+ function taggedPrompt(sections) {
27
+ return sections.map(([tag, content]) => `<${tag}>
28
+ ${content.trim()}
29
+ </${tag}>`).join(`
30
+
31
+ `);
32
+ }
33
+ function renderIterationPrompt(options) {
34
+ return taggedPrompt([
35
+ ["progress_ledger", `Read ${options.ledgerPath} first. It is the durable source of truth for attempted work, findings, failures, validation evidence, and remaining work.`],
36
+ ["role", "You are the active worker in a bounded evidence-driven completion loop."],
37
+ ["iteration", `${options.iteration} of ${options.maxIterations}`],
38
+ ["success_criteria", "This iteration makes measurable progress or supplies decisive evidence that the explicit objective is complete."],
39
+ ["requirements", [
40
+ "Select the highest-value unfinished item supported by the ledger and current state.",
41
+ "Perform concrete work; do not merely restate the objective or ledger.",
42
+ "Avoid repeating failed approaches unless new evidence justifies the retry.",
43
+ "Run the strongest practical validation for the work completed in this iteration.",
44
+ "Report exactly what changed, evidence gathered, failures encountered, and what remains.",
45
+ GROUNDED_REPORTING
46
+ ].join(`
47
+ `)],
48
+ ["stop_rules", "End this iteration after delivering measurable progress, or after evidence shows the objective is complete."],
49
+ ["output_format", `Markdown with Work performed, Changes, Validation evidence, New findings, Failures, and Remaining work. ${READABLE_REPORT}`],
50
+ ["objective", options.task]
51
+ ]);
52
+ }
53
+ function renderEvaluationPrompt(options) {
54
+ return taggedPrompt([
55
+ ["artifacts", [
56
+ `Durable progress ledger: ${options.ledgerPath}`,
57
+ `Current iteration artifact: ${options.iterationPath}`,
58
+ "Read both files before deciding."
59
+ ].join(`
60
+ `)],
61
+ ["role", "You are an independent completion evaluator. Judge evidence, not the worker's confidence."],
62
+ ["stop_condition", [
63
+ "Set done=true only when the objective is fully satisfied and current validation evidence proves it.",
64
+ "Set done=false when any required behavior, validation, cleanup, or evidence remains missing or uncertain.",
65
+ "Do not invent requirements beyond the objective."
66
+ ].join(`
67
+ `)],
68
+ ["evidence_rules", [
69
+ "List concrete validation evidence supporting the decision, including commands and observed output; cite file:line where applicable.",
70
+ "Record new findings and failures distinctly.",
71
+ "When incomplete, state actionable remaining work for the next iteration.",
72
+ GROUNDED_REPORTING
73
+ ].join(`
74
+ `)],
75
+ ["success_criteria", `The iteration ${options.iteration} decision is reproducible from cited artifact evidence.`],
76
+ ["output_format", `Return only the required structured decision with done, summary, new_findings, failures, validation_evidence, and remaining_work. ${READABLE_REPORT}`],
77
+ ["objective", options.task]
78
+ ]);
79
+ }
80
+ function renderCompletionPrompt(options) {
81
+ return taggedPrompt([
82
+ ["artifacts", `Read the complete ledger at ${options.ledgerPath} and final iteration artifact at ${options.iterationPath}.`],
83
+ ["role", "You are the final completion reporter."],
84
+ ["requirements", [
85
+ "Summarize the delivered outcome without adding unsupported claims.",
86
+ "Cite the validation evidence that satisfied the stop condition.",
87
+ "List artifact paths needed to audit the work.",
88
+ "Report residual risks even when no work remains.",
89
+ GROUNDED_REPORTING
90
+ ].join(`
91
+ `)],
92
+ ["success_criteria", "The final report is evidence-backed and independently auditable from the ledger."],
93
+ ["stop_rules", "Stop after accounting for the outcome, supporting evidence, audit artifacts, residual risks, and any remaining work."],
94
+ ["output_format", `Markdown with Outcome, Evidence, Artifacts, Residual risks, and Remaining work (None). ${READABLE_REPORT}`],
95
+ ["objective", options.task]
96
+ ]);
97
+ }
98
+
99
+ // dist/builtin/workflows/builtin/loop-until-done-runner.ts
100
+ var PROGRESS_DISCLAIMER = "Progress scores are a monitoring signal; VOC separation +0.079; never authoritative.";
101
+ var evaluationSchema = Type.Object({
102
+ done: Type.Boolean(),
103
+ summary: Type.String(),
104
+ new_findings: Type.Array(Type.String()),
105
+ failures: Type.Array(Type.String()),
106
+ validation_evidence: Type.Array(Type.String()),
107
+ remaining_work: Type.String()
108
+ }, { additionalProperties: false });
109
+ function progressCurve(entries) {
110
+ return entries.flatMap((entry) => entry.progress === undefined ? [] : [entry.progress.score]);
111
+ }
112
+ function progressReport(entries) {
113
+ const curve = progressCurve(entries);
114
+ return { curve, trend: classify_trend(curve).trend };
115
+ }
116
+ function formatProgressReport(report) {
117
+ return [
118
+ `Progress curve: ${JSON.stringify(report.curve)}`,
119
+ `Final trend: ${report.trend}`,
120
+ PROGRESS_DISCLAIMER
121
+ ].join(`
122
+ `);
123
+ }
124
+ function repeatCount(input) {
125
+ const repeats = input.progress_repeats;
126
+ return typeof repeats === "number" && Number.isInteger(repeats) && repeats > 0 ? repeats : 1;
127
+ }
128
+ async function scoreIteration(ctx, task, entries, repeats) {
129
+ try {
130
+ const curve = await score_progress(ctx, {
131
+ problem: task,
132
+ steps: entries.map((entry) => entry.summary),
133
+ checkpoints: [entries.length],
134
+ repeats
135
+ });
136
+ const score = curve.scores[0];
137
+ if (score === null || score === undefined)
138
+ return;
139
+ const trend = classify_trend([...progressCurve(entries), score]);
140
+ return {
141
+ score,
142
+ perRepeat: curve.perRepeat,
143
+ trend: trend.trend,
144
+ window: trend.evidence.window
145
+ };
146
+ } catch {
147
+ return;
148
+ }
149
+ }
150
+ function serializableObject(value) {
151
+ if (value === null || Array.isArray(value) || typeof value !== "object")
152
+ return;
153
+ return value;
154
+ }
155
+ function stringArray(value) {
156
+ return Array.isArray(value) && value.every((item) => typeof item === "string") ? value : undefined;
157
+ }
158
+ function evaluationFrom(result) {
159
+ const value = serializableObject(result.structured);
160
+ if (value === undefined) {
161
+ throw new Error(`loop-until-done: evaluator ${result.stageName} did not return a structured decision`);
162
+ }
163
+ const done = value.done;
164
+ const summary = value.summary;
165
+ const newFindings = stringArray(value.new_findings);
166
+ const failures = stringArray(value.failures);
167
+ const validationEvidence = stringArray(value.validation_evidence);
168
+ const remainingWork = value.remaining_work;
169
+ if (typeof done !== "boolean" || typeof summary !== "string" || newFindings === undefined || failures === undefined || validationEvidence === undefined || typeof remainingWork !== "string") {
170
+ throw new Error(`loop-until-done: evaluator ${result.stageName} returned an invalid decision`);
171
+ }
172
+ return { done, summary, newFindings, failures, validationEvidence, remainingWork };
173
+ }
174
+ async function writeLedger(path, task, maxIterations, status, entries) {
175
+ const report = progressReport(entries);
176
+ await writeFile(path, `${JSON.stringify({
177
+ task,
178
+ max_iterations: maxIterations,
179
+ status,
180
+ iterations_completed: entries.length,
181
+ entries,
182
+ progress_curve: report.curve,
183
+ final_trend: report.trend,
184
+ progress_disclaimer: PROGRESS_DISCLAIMER
185
+ }, null, 2)}
186
+ `);
187
+ }
188
+ async function runLoopUntilDone(ctx) {
189
+ const artifactDir = await stableArtifactRoot(ctx, "loop-until-done");
190
+ const iterationsDir = join(artifactDir, "iterations");
191
+ const evaluationsDir = join(artifactDir, "evaluations");
192
+ await mkdir(iterationsDir, { recursive: true });
193
+ await mkdir(evaluationsDir, { recursive: true });
194
+ const ledgerPath = join(artifactDir, "progress-ledger.json");
195
+ const entries = [];
196
+ const iterationArtifactPaths = [];
197
+ const evaluationArtifactPaths = [];
198
+ await writeLedger(ledgerPath, ctx.inputs.prompt, ctx.inputs.max_iterations, "active", entries);
199
+ for (let iteration = 1;iteration <= ctx.inputs.max_iterations; iteration += 1) {
200
+ const iterationPath = join(iterationsDir, `iteration-${iteration}.md`);
201
+ const evaluationPath = join(evaluationsDir, `evaluation-${iteration}.json`);
202
+ iterationArtifactPaths.push(iterationPath);
203
+ evaluationArtifactPaths.push(evaluationPath);
204
+ await ctx.task(`iteration-${iteration}`, {
205
+ prompt: renderIterationPrompt({
206
+ task: ctx.inputs.prompt,
207
+ iteration,
208
+ maxIterations: ctx.inputs.max_iterations,
209
+ ledgerPath
210
+ }),
211
+ context: "fresh",
212
+ reads: [ledgerPath, ...iteration > 1 ? [iterationArtifactPaths[iteration - 2]] : []],
213
+ output: iterationPath,
214
+ outputMode: "file-only"
215
+ });
216
+ const evaluator = await ctx.task(`evaluate-${iteration}`, {
217
+ prompt: renderEvaluationPrompt({
218
+ task: ctx.inputs.prompt,
219
+ iteration,
220
+ ledgerPath,
221
+ iterationPath
222
+ }),
223
+ context: "fresh",
224
+ reads: [ledgerPath, iterationPath],
225
+ schema: evaluationSchema
226
+ });
227
+ const decision = evaluationFrom(evaluator);
228
+ await writeFile(evaluationPath, `${JSON.stringify(evaluator.structured, null, 2)}
229
+ `);
230
+ const entry = {
231
+ iteration,
232
+ artifact_path: iterationPath,
233
+ evaluation_artifact_path: evaluationPath,
234
+ summary: decision.summary,
235
+ findings: decision.newFindings,
236
+ failures: decision.failures,
237
+ validation_evidence: decision.validationEvidence,
238
+ done: decision.done,
239
+ remaining_work: decision.remainingWork
240
+ };
241
+ entries.push(entry);
242
+ if (ctx.inputs.progress_scoring !== false) {
243
+ const progress = await scoreIteration(ctx, ctx.inputs.prompt, entries, repeatCount(ctx.inputs));
244
+ if (progress !== undefined)
245
+ entries[entries.length - 1] = { ...entry, progress };
246
+ }
247
+ await writeLedger(ledgerPath, ctx.inputs.prompt, ctx.inputs.max_iterations, decision.done ? "complete" : "active", entries);
248
+ if (decision.done) {
249
+ const report2 = progressReport(entries);
250
+ const resultPath = join(artifactDir, "result.md");
251
+ const final = await ctx.task("completion-summary", {
252
+ prompt: renderCompletionPrompt({ task: ctx.inputs.prompt, ledgerPath, iterationPath }),
253
+ context: "fresh",
254
+ reads: [ledgerPath, iterationPath],
255
+ output: resultPath,
256
+ outputMode: "file-only"
257
+ });
258
+ const result2 = `${final.text ? `${final.text.trimEnd()}
259
+
260
+ ` : ""}${formatProgressReport(report2)}
261
+ `;
262
+ return {
263
+ result: result2,
264
+ status: "complete",
265
+ iterations_completed: iteration,
266
+ ledger_path: ledgerPath,
267
+ iteration_artifact_paths: iterationArtifactPaths,
268
+ evaluation_artifact_paths: evaluationArtifactPaths,
269
+ result_path: resultPath,
270
+ remaining_work: "",
271
+ artifact_dir: artifactDir,
272
+ progress_curve: report2.curve,
273
+ final_trend: report2.trend,
274
+ progress_disclaimer: PROGRESS_DISCLAIMER
275
+ };
276
+ }
277
+ }
278
+ const last = entries.at(-1);
279
+ const report = progressReport(entries);
280
+ await writeLedger(ledgerPath, ctx.inputs.prompt, ctx.inputs.max_iterations, "failed", entries);
281
+ const result = [
282
+ `Iteration limit exhausted after ${ctx.inputs.max_iterations} iterations. Inspect ${ledgerPath}.`,
283
+ formatProgressReport(report)
284
+ ].join(`
285
+
286
+ `);
287
+ return {
288
+ result,
289
+ status: "failed",
290
+ iterations_completed: ctx.inputs.max_iterations,
291
+ ledger_path: ledgerPath,
292
+ iteration_artifact_paths: iterationArtifactPaths,
293
+ evaluation_artifact_paths: evaluationArtifactPaths,
294
+ result_path: ledgerPath,
295
+ remaining_work: last.remaining_work,
296
+ artifact_dir: artifactDir,
297
+ progress_curve: report.curve,
298
+ final_trend: report.trend,
299
+ progress_disclaimer: PROGRESS_DISCLAIMER
300
+ };
301
+ }
302
+
303
+ // dist/builtin/workflows/builtin/loop-until-done.ts
304
+ var loop_until_done_default = workflow({
305
+ name: "loop-until-done",
306
+ description: "Repeat evidence-producing work and independent completion evaluation against a durable ledger until done or an inspectable iteration-limit failure.",
307
+ heartbeatIntervalMinutes: 15,
308
+ inputs: {
309
+ prompt: Type2.String({ description: "Objective whose explicit completion condition controls the bounded loop." }),
310
+ max_iterations: Type2.Integer({
311
+ minimum: 1,
312
+ maximum: 20,
313
+ default: 5,
314
+ description: "Maximum work/evaluation iterations before returning an inspectable failed status (1-20)."
315
+ }),
316
+ progress_scoring: Type2.Boolean({
317
+ default: true,
318
+ description: "Enable advisory progress scoring after each completed iteration."
319
+ }),
320
+ progress_repeats: Type2.Integer({
321
+ minimum: 1,
322
+ default: 1,
323
+ description: "Number of advisory progress-scoring repeats per iteration."
324
+ })
325
+ },
326
+ outputs: {
327
+ result: Type2.String({ description: "Compact reference to the evidence-backed completion report, or the deterministic exhaustion report; read `result_path` for the full report." }),
328
+ status: Type2.Union([Type2.Literal("complete"), Type2.Literal("failed")], {
329
+ description: "Complete when evidence satisfies the stop condition; failed when max_iterations is exhausted."
330
+ }),
331
+ iterations_completed: Type2.Integer({ description: "Number of completed work/evaluation iterations." }),
332
+ ledger_path: Type2.String({ description: "Path to the durable JSON progress ledger." }),
333
+ iteration_artifact_paths: Type2.Array(Type2.String(), { description: "Ordered paths to per-iteration work artifacts." }),
334
+ evaluation_artifact_paths: Type2.Array(Type2.String(), { description: "Ordered paths to structured evaluation artifacts." }),
335
+ result_path: Type2.String({ description: "Path to the final report, or the ledger on exhausted failure." }),
336
+ remaining_work: Type2.String({ description: "Actionable remaining work; empty only after proven completion." }),
337
+ artifact_dir: Type2.String({ description: "Run-specific directory containing loop artifacts." }),
338
+ progress_curve: Type2.Array(Type2.Number(), { description: "Advisory progress scores in iteration order." }),
339
+ final_trend: Type2.Union([Type2.Literal("rising"), Type2.Literal("flat"), Type2.Literal("regressing")], { description: "Final advisory trend classification; never a stop decision." }),
340
+ progress_disclaimer: Type2.String({ description: "Calibration disclaimer for the advisory progress signal." })
341
+ },
342
+ run: async (ctx) => await runLoopUntilDone(withSteeringPropagationContext(ctx))
343
+ });
344
+
345
+ export { loop_until_done_default };