@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
@@ -0,0 +1,264 @@
1
+ import"./chunk-5wgwscd0.js";
2
+
3
+ // src/core/export-html/ansi-to-html.ts
4
+ var ANSI_COLORS = [
5
+ "#000000",
6
+ "#800000",
7
+ "#008000",
8
+ "#808000",
9
+ "#000080",
10
+ "#800080",
11
+ "#008080",
12
+ "#c0c0c0",
13
+ "#808080",
14
+ "#ff0000",
15
+ "#00ff00",
16
+ "#ffff00",
17
+ "#0000ff",
18
+ "#ff00ff",
19
+ "#00ffff",
20
+ "#ffffff"
21
+ ];
22
+ function color256ToHex(index) {
23
+ if (index < 16) {
24
+ return ANSI_COLORS[index];
25
+ }
26
+ if (index < 232) {
27
+ const cubeIndex = index - 16;
28
+ const r = Math.floor(cubeIndex / 36);
29
+ const g = Math.floor(cubeIndex % 36 / 6);
30
+ const b = cubeIndex % 6;
31
+ const toComponent = (n) => n === 0 ? 0 : 55 + n * 40;
32
+ const toHex = (n) => toComponent(n).toString(16).padStart(2, "0");
33
+ return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
34
+ }
35
+ const gray = 8 + (index - 232) * 10;
36
+ const grayHex = gray.toString(16).padStart(2, "0");
37
+ return `#${grayHex}${grayHex}${grayHex}`;
38
+ }
39
+ function escapeHtml(text) {
40
+ return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
41
+ }
42
+ function createEmptyStyle() {
43
+ return {
44
+ fg: null,
45
+ bg: null,
46
+ bold: false,
47
+ dim: false,
48
+ italic: false,
49
+ underline: false
50
+ };
51
+ }
52
+ function styleToInlineCSS(style) {
53
+ const parts = [];
54
+ if (style.fg)
55
+ parts.push(`color:${style.fg}`);
56
+ if (style.bg)
57
+ parts.push(`background-color:${style.bg}`);
58
+ if (style.bold)
59
+ parts.push("font-weight:bold");
60
+ if (style.dim)
61
+ parts.push("opacity:0.6");
62
+ if (style.italic)
63
+ parts.push("font-style:italic");
64
+ if (style.underline)
65
+ parts.push("text-decoration:underline");
66
+ return parts.join(";");
67
+ }
68
+ function hasStyle(style) {
69
+ return style.fg !== null || style.bg !== null || style.bold || style.dim || style.italic || style.underline;
70
+ }
71
+ function applySgrCode(params, style) {
72
+ let i = 0;
73
+ while (i < params.length) {
74
+ const code = params[i];
75
+ if (code === 0) {
76
+ style.fg = null;
77
+ style.bg = null;
78
+ style.bold = false;
79
+ style.dim = false;
80
+ style.italic = false;
81
+ style.underline = false;
82
+ } else if (code === 1) {
83
+ style.bold = true;
84
+ } else if (code === 2) {
85
+ style.dim = true;
86
+ } else if (code === 3) {
87
+ style.italic = true;
88
+ } else if (code === 4) {
89
+ style.underline = true;
90
+ } else if (code === 22) {
91
+ style.bold = false;
92
+ style.dim = false;
93
+ } else if (code === 23) {
94
+ style.italic = false;
95
+ } else if (code === 24) {
96
+ style.underline = false;
97
+ } else if (code >= 30 && code <= 37) {
98
+ style.fg = ANSI_COLORS[code - 30];
99
+ } else if (code === 38) {
100
+ if (params[i + 1] === 5 && params.length > i + 2) {
101
+ style.fg = color256ToHex(params[i + 2]);
102
+ i += 2;
103
+ } else if (params[i + 1] === 2 && params.length > i + 4) {
104
+ const r = params[i + 2];
105
+ const g = params[i + 3];
106
+ const b = params[i + 4];
107
+ style.fg = `rgb(${r},${g},${b})`;
108
+ i += 4;
109
+ }
110
+ } else if (code === 39) {
111
+ style.fg = null;
112
+ } else if (code >= 40 && code <= 47) {
113
+ style.bg = ANSI_COLORS[code - 40];
114
+ } else if (code === 48) {
115
+ if (params[i + 1] === 5 && params.length > i + 2) {
116
+ style.bg = color256ToHex(params[i + 2]);
117
+ i += 2;
118
+ } else if (params[i + 1] === 2 && params.length > i + 4) {
119
+ const r = params[i + 2];
120
+ const g = params[i + 3];
121
+ const b = params[i + 4];
122
+ style.bg = `rgb(${r},${g},${b})`;
123
+ i += 4;
124
+ }
125
+ } else if (code === 49) {
126
+ style.bg = null;
127
+ } else if (code >= 90 && code <= 97) {
128
+ style.fg = ANSI_COLORS[code - 90 + 8];
129
+ } else if (code >= 100 && code <= 107) {
130
+ style.bg = ANSI_COLORS[code - 100 + 8];
131
+ }
132
+ i++;
133
+ }
134
+ }
135
+ var ANSI_REGEX = /\x1b\[([\d;]*)m/g;
136
+ function ansiToHtml(text) {
137
+ const style = createEmptyStyle();
138
+ let result = "";
139
+ let lastIndex = 0;
140
+ let inSpan = false;
141
+ ANSI_REGEX.lastIndex = 0;
142
+ let match = ANSI_REGEX.exec(text);
143
+ while (match !== null) {
144
+ const beforeText = text.slice(lastIndex, match.index);
145
+ if (beforeText) {
146
+ result += escapeHtml(beforeText);
147
+ }
148
+ const paramStr = match[1];
149
+ const params = paramStr ? paramStr.split(";").map((p) => parseInt(p, 10) || 0) : [0];
150
+ if (inSpan) {
151
+ result += "</span>";
152
+ inSpan = false;
153
+ }
154
+ applySgrCode(params, style);
155
+ if (hasStyle(style)) {
156
+ result += `<span style="${styleToInlineCSS(style)}">`;
157
+ inSpan = true;
158
+ }
159
+ lastIndex = match.index + match[0].length;
160
+ match = ANSI_REGEX.exec(text);
161
+ }
162
+ const remainingText = text.slice(lastIndex);
163
+ if (remainingText) {
164
+ result += escapeHtml(remainingText);
165
+ }
166
+ if (inSpan) {
167
+ result += "</span>";
168
+ }
169
+ return result;
170
+ }
171
+ function ansiLinesToHtml(lines) {
172
+ return lines.map((line) => `<div class="ansi-line">${ansiToHtml(line) || "&nbsp;"}</div>`).join("");
173
+ }
174
+
175
+ // src/core/export-html/tool-renderer.ts
176
+ var ANSI_ESCAPE_REGEX = /\x1b\[[\d;]*m/g;
177
+ function isBlankRenderedLine(line) {
178
+ return line.replace(ANSI_ESCAPE_REGEX, "").trim().length === 0;
179
+ }
180
+ function trimRenderedResultLines(lines) {
181
+ let start = 0;
182
+ let end = lines.length;
183
+ while (start < end && isBlankRenderedLine(lines[start]))
184
+ start++;
185
+ while (end > start && isBlankRenderedLine(lines[end - 1]))
186
+ end--;
187
+ return lines.slice(start, end);
188
+ }
189
+ function createToolHtmlRenderer(deps) {
190
+ const { getToolDefinition, theme, cwd, width = 100 } = deps;
191
+ const renderedCallComponents = new Map;
192
+ const renderedResultComponents = new Map;
193
+ const renderedStates = new Map;
194
+ const renderedArgs = new Map;
195
+ const getState = (toolCallId) => {
196
+ let state = renderedStates.get(toolCallId);
197
+ if (!state) {
198
+ state = {};
199
+ renderedStates.set(toolCallId, state);
200
+ }
201
+ return state;
202
+ };
203
+ const createRenderContext = (toolCallId, lastComponent, expanded, isPartial, isError) => {
204
+ return {
205
+ args: renderedArgs.get(toolCallId),
206
+ toolCallId,
207
+ invalidate: () => {},
208
+ lastComponent,
209
+ state: getState(toolCallId),
210
+ cwd,
211
+ executionStarted: true,
212
+ argsComplete: true,
213
+ isPartial,
214
+ expanded,
215
+ showImages: false,
216
+ isError
217
+ };
218
+ };
219
+ return {
220
+ renderCall(toolCallId, toolName, args) {
221
+ try {
222
+ renderedArgs.set(toolCallId, args);
223
+ const toolDef = getToolDefinition(toolName);
224
+ if (!toolDef?.renderCall) {
225
+ return;
226
+ }
227
+ const component = toolDef.renderCall(args, theme, createRenderContext(toolCallId, renderedCallComponents.get(toolCallId), false, true, false));
228
+ renderedCallComponents.set(toolCallId, component);
229
+ const lines = component.render(width);
230
+ return ansiLinesToHtml(lines);
231
+ } catch {
232
+ return;
233
+ }
234
+ },
235
+ renderResult(toolCallId, toolName, result, details, isError) {
236
+ try {
237
+ const toolDef = getToolDefinition(toolName);
238
+ if (!toolDef?.renderResult) {
239
+ return;
240
+ }
241
+ const agentToolResult = {
242
+ content: result,
243
+ details,
244
+ isError
245
+ };
246
+ const collapsedComponent = toolDef.renderResult(agentToolResult, { expanded: false, isPartial: false }, theme, createRenderContext(toolCallId, renderedResultComponents.get(toolCallId), false, false, isError));
247
+ renderedResultComponents.set(toolCallId, collapsedComponent);
248
+ const collapsed = ansiLinesToHtml(trimRenderedResultLines(collapsedComponent.render(width)));
249
+ const expandedComponent = toolDef.renderResult(agentToolResult, { expanded: true, isPartial: false }, theme, createRenderContext(toolCallId, renderedResultComponents.get(toolCallId), true, false, isError));
250
+ renderedResultComponents.set(toolCallId, expandedComponent);
251
+ const expanded = ansiLinesToHtml(trimRenderedResultLines(expandedComponent.render(width)));
252
+ return {
253
+ ...collapsed && collapsed !== expanded ? { collapsed } : {},
254
+ expanded
255
+ };
256
+ } catch {
257
+ return;
258
+ }
259
+ }
260
+ };
261
+ }
262
+ export {
263
+ createToolHtmlRenderer
264
+ };
@@ -0,0 +1,4 @@
1
+ import { createRequire } from "node:module";
2
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
3
+
4
+ export { __require };
@@ -0,0 +1,155 @@
1
+ import {
2
+ VERIFICATION_SCALE
3
+ } from "./chunk-cg9tmks0.js";
4
+
5
+ // dist/builtin/workflows/builtin/progress-scoring.ts
6
+ import { Type } from "typebox";
7
+ var DEFAULT_TREND_WINDOW = 3;
8
+ var DEFAULT_RISE_DELTA = 1.5;
9
+ var DEFAULT_FALL_DELTA = -1.5;
10
+ var DEFAULT_REPEATS = 1;
11
+ var CALIBRATION_RULES = [
12
+ "Trust observed output, not the agent's narration.",
13
+ "Effort and step count are NOT progress.",
14
+ 'Agent declarations of success ("done!", "all tests pass") are ZERO evidence.',
15
+ "Scores may plateau or fall; wrong approaches plateau, and regressions decrease."
16
+ ];
17
+ var PROGRESS_SCALE_ORIENTATION = `${VERIFICATION_SCALE.min} = certainly would not satisfy the acceptance criteria … ${VERIFICATION_SCALE.max} = verified satisfaction with observed output`;
18
+ var progressSchema = Type.Object({
19
+ scores: Type.Array(Type.Object({
20
+ checkpoint: Type.Integer({ minimum: 1 }),
21
+ score: VERIFICATION_SCALE.schema
22
+ }, { additionalProperties: false }))
23
+ }, { additionalProperties: false });
24
+ function isRecord(value) {
25
+ return value !== null && typeof value === "object" && !Array.isArray(value);
26
+ }
27
+ function isProgressStructuredOutput(value) {
28
+ if (!isRecord(value) || Object.keys(value).length !== 1 || !Object.hasOwn(value, "scores"))
29
+ return false;
30
+ return Array.isArray(value.scores);
31
+ }
32
+ function nullScores(checkpointCount) {
33
+ return Array.from({ length: checkpointCount }, () => null);
34
+ }
35
+ function defaultCheckpoints(stepCount) {
36
+ const result = [];
37
+ for (let checkpoint = 2;checkpoint <= stepCount - 1; checkpoint += 1)
38
+ result.push(checkpoint);
39
+ return result;
40
+ }
41
+ function validateCheckpoints(checkpoints, stepCount) {
42
+ for (const checkpoint of checkpoints) {
43
+ if (!Number.isInteger(checkpoint) || checkpoint < 1 || checkpoint > stepCount) {
44
+ throw new RangeError(`Progress checkpoint ${checkpoint} is outside the step range 1..${stepCount}.`);
45
+ }
46
+ }
47
+ }
48
+ function scoresFromStructured(value, checkpoints) {
49
+ if (!isProgressStructuredOutput(value))
50
+ return nullScores(checkpoints.length);
51
+ const requested = new Set(checkpoints);
52
+ const seen = new Set;
53
+ const scoresByCheckpoint = new Map;
54
+ for (const candidate of value.scores) {
55
+ if (!isRecord(candidate) || Object.keys(candidate).length !== 2 || !Object.hasOwn(candidate, "checkpoint") || !Object.hasOwn(candidate, "score"))
56
+ continue;
57
+ const checkpoint = candidate.checkpoint;
58
+ const score = candidate.score;
59
+ if (typeof checkpoint !== "number" || !Number.isInteger(checkpoint) || seen.has(checkpoint))
60
+ continue;
61
+ if (!requested.has(checkpoint) || typeof score !== "number" || !Number.isInteger(score) || score < VERIFICATION_SCALE.min || score > VERIFICATION_SCALE.max)
62
+ continue;
63
+ seen.add(checkpoint);
64
+ scoresByCheckpoint.set(checkpoint, score);
65
+ }
66
+ return checkpoints.map((checkpoint) => scoresByCheckpoint.get(checkpoint) ?? null);
67
+ }
68
+ async function scoreRepeat(ctx, input, checkpoints, repeat) {
69
+ try {
70
+ const result = await ctx.task(`progress-score-${repeat + 1}`, {
71
+ prompt: build_progress_prompt({ ...input, checkpoints }),
72
+ context: "fresh",
73
+ schema: progressSchema
74
+ });
75
+ return scoresFromStructured(result.structured, checkpoints);
76
+ } catch {
77
+ return nullScores(checkpoints.length);
78
+ }
79
+ }
80
+ async function score_progress(ctx, input) {
81
+ if (input.steps.length === 0)
82
+ throw new RangeError("Progress scoring requires a non-empty step prefix.");
83
+ const checkpoints = Array.from(input.checkpoints ?? defaultCheckpoints(input.steps.length));
84
+ validateCheckpoints(checkpoints, input.steps.length);
85
+ const repeats = input.repeats ?? DEFAULT_REPEATS;
86
+ const perRepeat = [];
87
+ for (let repeat = 0;repeat < repeats; repeat += 1) {
88
+ perRepeat.push(await scoreRepeat(ctx, input, checkpoints, repeat));
89
+ }
90
+ const scores = checkpoints.map((_, checkpointIndex) => {
91
+ const valid = perRepeat.map((repeat) => repeat[checkpointIndex]).filter((score) => score !== null);
92
+ if (valid.length === 0)
93
+ return null;
94
+ return valid.reduce((total, score) => total + score, 0) / valid.length;
95
+ });
96
+ return { checkpoints, scores, perRepeat };
97
+ }
98
+ function build_progress_prompt(input) {
99
+ const numberedSteps = input.steps.map((step, index) => `${index + 1}. ${step}`);
100
+ const sharedHead = [
101
+ "<progress_head>",
102
+ "<problem>",
103
+ input.problem,
104
+ "</problem>",
105
+ "<steps>",
106
+ ...numberedSteps,
107
+ "</steps>",
108
+ "<calibration>",
109
+ ...CALIBRATION_RULES,
110
+ "</calibration>",
111
+ "<scale>",
112
+ `Use VERIFICATION_SCALE ${VERIFICATION_SCALE.min}..${VERIFICATION_SCALE.max} to answer: would the CURRENT state satisfy the acceptance criteria?`,
113
+ PROGRESS_SCALE_ORIENTATION,
114
+ "Score only the supplied current state from observed output.",
115
+ "</scale>",
116
+ "</progress_head>"
117
+ ].join(`
118
+ `);
119
+ const checkpointTail = [
120
+ "<checkpoints>",
121
+ "Score each listed 1-indexed checkpoint.",
122
+ ...input.checkpoints.map((checkpoint) => `- ${checkpoint}`),
123
+ "</checkpoints>",
124
+ "<output_format>",
125
+ `Return structured_output with scores: [{ checkpoint, score }], using integer scores from ${VERIFICATION_SCALE.min} through ${VERIFICATION_SCALE.max}.`,
126
+ "</output_format>"
127
+ ].join(`
128
+ `);
129
+ return `${sharedHead}
130
+
131
+ ${checkpointTail}`;
132
+ }
133
+ function mean(values) {
134
+ if (values.length === 0)
135
+ return 0;
136
+ return values.reduce((total, value) => total + value, 0) / values.length;
137
+ }
138
+ function classify_trend(series, config = {}) {
139
+ const window = config.window ?? DEFAULT_TREND_WINDOW;
140
+ const riseDelta = config.riseDelta ?? DEFAULT_RISE_DELTA;
141
+ const fallDelta = config.fallDelta ?? DEFAULT_FALL_DELTA;
142
+ if (series.length < window + 1) {
143
+ return { trend: "flat", evidence: { series, window, delta: 0 } };
144
+ }
145
+ const sample = series.slice(-2 * window);
146
+ const usableLength = sample.length % 2 === 1 ? sample.length - 1 : sample.length;
147
+ const halfLength = usableLength / 2;
148
+ const leading = sample.slice(0, halfLength);
149
+ const trailing = sample.slice(sample.length - halfLength);
150
+ const delta = halfLength === 0 ? 0 : mean(trailing) - mean(leading);
151
+ const trend = delta >= riseDelta ? "rising" : delta <= fallDelta ? "regressing" : "flat";
152
+ return { trend, evidence: { series, window, delta } };
153
+ }
154
+
155
+ export { DEFAULT_RISE_DELTA, DEFAULT_FALL_DELTA, score_progress, classify_trend };
@@ -0,0 +1,126 @@
1
+ import {
2
+ VERIFICATION_SCALE
3
+ } from "./chunk-cg9tmks0.js";
4
+
5
+ // dist/builtin/workflows/builtin/verification-prompts.ts
6
+ var MAX_INLINE_CANDIDATE_BYTES = 32 * 1024;
7
+ var DEFAULT_WARM_CONCURRENCY = 4;
8
+ var DEFAULT_OUTPUT_FORMAT = "Call structured_output with criterion_id, score (1–20), evidence, and findings containing finding and severity.";
9
+ function inlineCandidates(head) {
10
+ return head.candidates.every((candidate) => Buffer.byteLength(candidate.body, "utf8") <= MAX_INLINE_CANDIDATE_BYTES);
11
+ }
12
+ function fallbackReadPaths(head) {
13
+ if (inlineCandidates(head))
14
+ return;
15
+ const paths = [];
16
+ for (const [index, candidate] of head.candidates.entries()) {
17
+ if (candidate.path === undefined) {
18
+ throw new TypeError(`Oversized candidate family requires a caller-bound path for every candidate; candidate ${index + 1} has no path.`);
19
+ }
20
+ paths.push(candidate.path);
21
+ }
22
+ return paths;
23
+ }
24
+ function candidateSection(head, readPaths) {
25
+ return head.candidates.map((candidate, index) => {
26
+ if (readPaths === undefined) {
27
+ return `<candidate index="${index + 1}">
28
+ ${candidate.body}
29
+ </candidate>`;
30
+ }
31
+ return `<candidate index="${index + 1}" source="read">
32
+ Read candidate from ${readPaths[index]}.
33
+ </candidate>`;
34
+ }).join(`
35
+ `);
36
+ }
37
+ function scoring_prompt_reads(head) {
38
+ return fallbackReadPaths(head) ?? [];
39
+ }
40
+ function build_scoring_prompt(head, criterion) {
41
+ const readPaths = fallbackReadPaths(head);
42
+ const sharedHead = [
43
+ "<scoring_head>",
44
+ "<task_statement>",
45
+ head.task,
46
+ "</task_statement>",
47
+ "<ground_truth_note>",
48
+ head.groundTruthNote,
49
+ "</ground_truth_note>",
50
+ "<candidates>",
51
+ candidateSection(head, readPaths),
52
+ "</candidates>",
53
+ "<scale_anchors>",
54
+ head.scaleAnchors ?? VERIFICATION_SCALE.anchors,
55
+ "</scale_anchors>"
56
+ ].join(`
57
+ `);
58
+ const varyingTail = [
59
+ "<criterion>",
60
+ `<name>${criterion.name}</name>`,
61
+ `<description>${criterion.description}</description>`,
62
+ "</criterion>",
63
+ "<output_format>",
64
+ head.outputFormat ?? DEFAULT_OUTPUT_FORMAT,
65
+ "</output_format>"
66
+ ].join(`
67
+ `);
68
+ return `${sharedHead}
69
+
70
+ ${varyingTail}`;
71
+ }
72
+ function boundedConcurrency(stepCount, phaseCap, inheritedCap) {
73
+ return Math.min(stepCount, phaseCap ?? stepCount, inheritedCap ?? stepCount);
74
+ }
75
+ async function warm_first_fan_out(ctx, steps, prefixKeyOf, options = {}) {
76
+ const warmIndices = [];
77
+ const restIndices = [];
78
+ const seen = new Set;
79
+ for (const [index, step] of steps.entries()) {
80
+ const prefixKey = prefixKeyOf(step, index);
81
+ if (seen.has(prefixKey))
82
+ restIndices.push(index);
83
+ else {
84
+ seen.add(prefixKey);
85
+ warmIndices.push(index);
86
+ }
87
+ }
88
+ const { warmConcurrency, ...parallelOptions } = options;
89
+ const inheritedConcurrency = parallelOptions.concurrency;
90
+ const resultsByIndex = new Map;
91
+ let warmFailure;
92
+ if (warmIndices.length > 0) {
93
+ const warmSteps = warmIndices.map((index) => steps[index]);
94
+ try {
95
+ const warmResults = await ctx.parallel(warmSteps, {
96
+ ...parallelOptions,
97
+ concurrency: boundedConcurrency(warmSteps.length, warmConcurrency ?? DEFAULT_WARM_CONCURRENCY, inheritedConcurrency),
98
+ failFast: false
99
+ });
100
+ for (const [resultIndex, result] of warmResults.entries()) {
101
+ const originalIndex = warmIndices[resultIndex];
102
+ if (originalIndex !== undefined)
103
+ resultsByIndex.set(originalIndex, result);
104
+ }
105
+ } catch (error) {
106
+ warmFailure = error instanceof Error ? error : new Error(String(error));
107
+ }
108
+ }
109
+ if (restIndices.length > 0) {
110
+ const restSteps = restIndices.map((index) => steps[index]);
111
+ const restResults = await ctx.parallel(restSteps, {
112
+ ...parallelOptions,
113
+ concurrency: boundedConcurrency(restSteps.length, undefined, inheritedConcurrency)
114
+ });
115
+ for (const [resultIndex, result] of restResults.entries()) {
116
+ const originalIndex = restIndices[resultIndex];
117
+ if (originalIndex !== undefined)
118
+ resultsByIndex.set(originalIndex, result);
119
+ }
120
+ }
121
+ if (warmFailure !== undefined)
122
+ throw warmFailure;
123
+ return steps.map((_, index) => resultsByIndex.get(index)).filter((result) => result !== undefined);
124
+ }
125
+
126
+ export { scoring_prompt_reads, build_scoring_prompt, warm_first_fan_out };
@@ -0,0 +1,33 @@
1
+ // dist/builtin/workflows/builtin/verification-usage.ts
2
+ function fold_usage(results) {
3
+ const totals = {
4
+ calls: 0,
5
+ input: 0,
6
+ output: 0,
7
+ cacheRead: 0,
8
+ cacheWrite: 0,
9
+ cost: 0,
10
+ turns: 0
11
+ };
12
+ for (const result of results) {
13
+ for (const attempt of result.modelAttempts ?? []) {
14
+ totals.calls += 1;
15
+ const usage = attempt.usage;
16
+ if (usage === undefined)
17
+ continue;
18
+ totals.input += usage.input ?? 0;
19
+ totals.output += usage.output ?? 0;
20
+ totals.cacheRead += usage.cacheRead ?? 0;
21
+ totals.cacheWrite += usage.cacheWrite ?? 0;
22
+ totals.cost += usage.cost ?? 0;
23
+ totals.turns += usage.turns ?? 0;
24
+ }
25
+ }
26
+ const cacheDenominator = totals.input + totals.cacheRead;
27
+ return {
28
+ ...totals,
29
+ cacheHitRate: cacheDenominator === 0 ? 0 : totals.cacheRead / cacheDenominator
30
+ };
31
+ }
32
+
33
+ export { fold_usage };