@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,229 +0,0 @@
1
- export type ReviewNextAction =
2
- | "implementation"
3
- | "pull-request"
4
- | "finish"
5
- | "blocked"
6
- | "needs_human";
7
-
8
- export type ParseDiagnostics = {
9
- readonly kind: "structured_output_parse_failure";
10
- readonly message: string;
11
- readonly raw_text_preview?: string;
12
- };
13
-
14
- export type ReviewConvergenceSummary = {
15
- readonly parsed: boolean;
16
- readonly approved: boolean;
17
- readonly stopReviewLoop: boolean;
18
- readonly nextAction: ReviewNextAction;
19
- readonly finalActionRemaining: boolean;
20
- readonly diagnostics: readonly string[];
21
- };
22
-
23
- export type ParsedReviewDecision<TDecision> = {
24
- readonly decision: TDecision;
25
- readonly parsed: boolean;
26
- readonly diagnostics: readonly string[];
27
- };
28
-
29
- export type RequirementTraceabilityLike = {
30
- readonly requirement: string;
31
- readonly status: "proven" | "contradicted" | "missing" | "unverified";
32
- readonly evidence: string;
33
- };
34
-
35
- const FINAL_ACTION_PATTERN = /\b(?:pr|pull[- ]request|merge[- ]request|review request|github pr|create pr)\b/iu;
36
-
37
- export function isFinalActionTraceability(
38
- entry: RequirementTraceabilityLike,
39
- ): boolean {
40
- return FINAL_ACTION_PATTERN.test(`${entry.requirement}\n${entry.evidence}`);
41
- }
42
-
43
- export function finalActionRemaining(
44
- traceability: readonly RequirementTraceabilityLike[],
45
- ): boolean {
46
- return traceability.some(
47
- (entry) => entry.status !== "proven" && isFinalActionTraceability(entry),
48
- );
49
- }
50
-
51
- export function traceabilityProvenExceptFinalAction(args: {
52
- readonly traceability: readonly RequirementTraceabilityLike[];
53
- readonly allowFinalActionRemaining: boolean;
54
- }): boolean {
55
- return args.traceability.length > 0 && args.traceability.every((entry) => {
56
- if (entry.status === "proven") return true;
57
- return args.allowFinalActionRemaining &&
58
- entry.status !== "contradicted" &&
59
- isFinalActionTraceability(entry);
60
- });
61
- }
62
-
63
- /**
64
- * Highest numeric finding priority that still blocks evidence closure for
65
- * in-scope (`consistent_with_objective`) findings. P0=0, P1=1, P2=2 block;
66
- * P3=3 is a dismissible nice-to-have only when the finding is not required by
67
- * the objective.
68
- */
69
- export const MAX_BLOCKING_PRIORITY = 2;
70
-
71
- export type ObjectiveAlignedFindingLike = {
72
- readonly objective_alignment?: string;
73
- readonly priority?: number | null;
74
- };
75
-
76
- /**
77
- * Shared evidence-closure predicate for reviewer findings.
78
- *
79
- * A finding keeps the convergence loop open when it is objective-relevant and
80
- * unresolved:
81
- * - `required_by_objective` findings block at ANY priority — severity labels
82
- * alone never dismiss work the literal contract requires.
83
- * - `consistent_with_objective` findings block at P0/P1/P2; P3 is a
84
- * non-blocking nice-to-have. Missing/`null` priority blocks so ambiguity
85
- * never silently approves.
86
- * - `beyond_objective` / `contradicts_objective` findings never block: the
87
- * literal contract's scope controls stay authoritative.
88
- * - Unknown or missing alignment blocks, so unclassified findings cannot be
89
- * waved through.
90
- */
91
- export function findingBlocksClosure(finding: ObjectiveAlignedFindingLike): boolean {
92
- const alignment = finding.objective_alignment;
93
- if (alignment === "beyond_objective" || alignment === "contradicts_objective") {
94
- return false;
95
- }
96
- if (alignment === "required_by_objective") return true;
97
- if (alignment !== "consistent_with_objective") return true;
98
- const priority = finding.priority;
99
- if (priority === undefined || priority === null) return true;
100
- return priority <= MAX_BLOCKING_PRIORITY;
101
- }
102
-
103
- export type ConsolidatableFinding = ObjectiveAlignedFindingLike & {
104
- readonly title: string;
105
- readonly code_location?: {
106
- readonly absolute_file_path: string;
107
- };
108
- };
109
-
110
- export type ConsolidatedFinding<F extends ConsolidatableFinding> = {
111
- readonly finding: F;
112
- readonly reviewers: readonly string[];
113
- readonly blocking: boolean;
114
- };
115
-
116
- function findingConsolidationKey(finding: ConsolidatableFinding): string {
117
- const normalizedTitle = finding.title
118
- .replace(/^\s*\[P[0-3]\]\s*/iu, "")
119
- .toLowerCase()
120
- .replace(/\s+/gu, " ")
121
- .trim();
122
- return `${finding.code_location?.absolute_file_path ?? ""}::${normalizedTitle}`;
123
- }
124
-
125
- /**
126
- * Consolidate the current review round's findings into one deduplicated batch
127
- * so repair work is planned and executed batch-wise instead of one finding per
128
- * turn. Findings from different reviewers that name the same location and
129
- * (priority-tag-insensitive) title merge into a single entry; blocking status
130
- * is the OR of the merged findings, and blocking entries sort first.
131
- */
132
- export function consolidateFindingsBatch<F extends ConsolidatableFinding>(
133
- reviews: readonly { readonly reviewer: string; readonly findings: readonly F[] }[],
134
- ): ConsolidatedFinding<F>[] {
135
- const byKey = new Map<string, { finding: F; reviewers: string[]; blocking: boolean }>();
136
- for (const review of reviews) {
137
- for (const finding of review.findings) {
138
- const key = findingConsolidationKey(finding);
139
- const existing = byKey.get(key);
140
- if (existing === undefined) {
141
- byKey.set(key, {
142
- finding,
143
- reviewers: [review.reviewer],
144
- blocking: findingBlocksClosure(finding),
145
- });
146
- continue;
147
- }
148
- if (!existing.reviewers.includes(review.reviewer)) {
149
- existing.reviewers.push(review.reviewer);
150
- }
151
- existing.blocking = existing.blocking || findingBlocksClosure(finding);
152
- }
153
- }
154
- return [...byKey.values()].sort((a, b) => Number(b.blocking) - Number(a.blocking));
155
- }
156
-
157
- /**
158
- * The unresolved objective-relevant findings that veto evidence closure for a
159
- * review round, regardless of how many reviewers individually approved.
160
- */
161
- export function unresolvedClosureFindings<F extends ConsolidatableFinding>(
162
- reviews: readonly { readonly reviewer: string; readonly findings: readonly F[] }[],
163
- ): ConsolidatedFinding<F>[] {
164
- return consolidateFindingsBatch(reviews).filter((entry) => entry.blocking);
165
- }
166
-
167
- /** Short, inspectable summary of the findings that keep closure open. */
168
- export function closureGapSummary(
169
- unresolved: readonly ConsolidatedFinding<ConsolidatableFinding>[],
170
- ): string {
171
- const preview = unresolved
172
- .slice(0, 5)
173
- .map((entry) => entry.finding.title)
174
- .join("; ");
175
- const suffix = unresolved.length > 5 ? "; …" : "";
176
- return `${unresolved.length} unresolved objective-relevant blocking finding(s)${
177
- preview.length > 0 ? `: ${preview}${suffix}` : ""
178
- }`;
179
- }
180
-
181
- const PREVIEW_LIMIT = 500;
182
-
183
- function rawTextPreview(rawText: string): string | undefined {
184
- const trimmed = rawText.trim();
185
- if (trimmed.length === 0) return undefined;
186
- return trimmed.slice(0, PREVIEW_LIMIT);
187
- }
188
-
189
- export function parseFailureDiagnostics(
190
- reviewer: string,
191
- rawText: string,
192
- ): readonly string[] {
193
- const preview = rawTextPreview(rawText);
194
- const base = `Structured reviewer decision parse failed for ${reviewer}: no schema-valid JSON decision was returned.`;
195
- return preview === undefined ? [base] : [base, `Raw reviewer output preview: ${preview}`];
196
- }
197
-
198
- function errorMessage(error: unknown): string {
199
- return error instanceof Error ? error.message : String(error);
200
- }
201
-
202
- export function reviewerFailureText(error: unknown): string {
203
- const messages = [errorMessage(error)];
204
- if (error instanceof AggregateError) {
205
- for (const nested of error.errors) {
206
- messages.push(errorMessage(nested));
207
- }
208
- }
209
- return [...new Set(messages.map((message) => message.trim()).filter(Boolean))]
210
- .join("\n");
211
- }
212
-
213
- export function summarizeReviewConvergence(args: {
214
- readonly parsed: boolean;
215
- readonly approved: boolean;
216
- readonly stopReviewLoop: boolean;
217
- readonly nextAction: ReviewNextAction;
218
- readonly finalActionRemaining?: boolean;
219
- readonly diagnostics: readonly string[];
220
- }): ReviewConvergenceSummary {
221
- return {
222
- parsed: args.parsed,
223
- approved: args.approved,
224
- stopReviewLoop: args.stopReviewLoop,
225
- nextAction: args.nextAction,
226
- finalActionRemaining: args.finalActionRemaining ?? args.nextAction === "pull-request",
227
- diagnostics: args.diagnostics,
228
- };
229
- }
@@ -1,156 +0,0 @@
1
- /** Pure, seeded selection math for the probabilistic pivot tournament. */
2
- import { VERIFICATION_SCALE } from "./verification-criteria.js";
3
-
4
- export interface DirectedPair {
5
- a: number;
6
- b: number;
7
- }
8
-
9
- export interface ScoringJob {
10
- a: number;
11
- b: number;
12
- criterionId: string;
13
- rep: number;
14
- swapped: boolean;
15
- }
16
-
17
- export interface ComparisonPlan {
18
- ring: DirectedPair[];
19
- pivotRounds: (pivots: number[]) => DirectedPair[];
20
- jobs: (pairs: readonly DirectedPair[], criterionIds: readonly string[]) => ScoringJob[];
21
- }
22
-
23
- export interface Preference {
24
- a: number;
25
- b: number;
26
- p: number;
27
- }
28
-
29
- export interface RankingEntry {
30
- index: number;
31
- meanPreference: number;
32
- }
33
-
34
- export type Ranking = RankingEntry[];
35
-
36
- const UINT32_RANGE = 0x1_0000_0000;
37
- const MULBERRY_INCREMENT = 0x6d2b79f5;
38
-
39
- /** Return a deterministic Mulberry32-class random-float generator. */
40
- export function seeded_rng(seed: number): () => number {
41
- let state = seed >>> 0;
42
- return () => {
43
- state = (state + MULBERRY_INCREMENT) >>> 0;
44
- let t = state;
45
- t = Math.imul(t ^ (t >>> 15), t | 1);
46
- t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
47
- return ((t ^ (t >>> 14)) >>> 0) / UINT32_RANGE;
48
- };
49
- }
50
-
51
- function ring_cycle(n: number, rng: () => number): DirectedPair[] {
52
- const permutation = Array.from({ length: n }, (_, index) => index);
53
- for (let index = n - 1; index > 0; index -= 1) {
54
- const other = Math.floor(rng() * (index + 1));
55
- [permutation[index], permutation[other]] = [permutation[other]!, permutation[index]!];
56
- }
57
- return permutation.map((a, index) => ({ a, b: permutation[(index + 1) % n]! }));
58
- }
59
-
60
- function pair_key(a: number, b: number): string {
61
- return a < b ? `${a}:${b}` : `${b}:${a}`;
62
- }
63
-
64
-
65
- /** Build a deterministic ring and expose the later pivot/job phases as pure closures. */
66
- export function plan_comparisons(input: {
67
- n: number;
68
- pivots: number;
69
- repeats: number;
70
- seed: number;
71
- }): ComparisonPlan {
72
- const { n, pivots: pivotCount, repeats, seed } = input;
73
- if (n < 2) throw new RangeError("n must be at least 2");
74
- if (pivotCount < 1) throw new RangeError("pivots must be at least 1");
75
- if (repeats < 1) throw new RangeError("repeats must be at least 1");
76
-
77
- const ring = ring_cycle(n, seeded_rng(seed));
78
- return {
79
- ring,
80
- pivotRounds: (pivots) => {
81
- const scheduled = new Set(ring.map(({ a, b }) => pair_key(a, b)));
82
- const pivotSet = new Set(pivots);
83
- const pairs: DirectedPair[] = [];
84
- const add = (a: number, b: number): void => {
85
- if (a === b) return;
86
- const key = pair_key(a, b);
87
- if (scheduled.has(key)) return;
88
- scheduled.add(key);
89
- pairs.push({ a, b });
90
- };
91
- for (let candidate = 0; candidate < n; candidate += 1) {
92
- if (pivotSet.has(candidate)) continue;
93
- for (const pivot of pivots) add(candidate, pivot);
94
- }
95
- for (let first = 0; first < pivots.length; first += 1) {
96
- for (let second = first + 1; second < pivots.length; second += 1) {
97
- add(pivots[first]!, pivots[second]!);
98
- }
99
- }
100
- return pairs;
101
- },
102
- jobs: (pairs, criterionIds) => {
103
- const jobs: ScoringJob[] = [];
104
- for (const pair of pairs) {
105
- for (const criterionId of criterionIds) {
106
- for (let rep = 0; rep < repeats; rep += 1) {
107
- jobs.push({ a: pair.a, b: pair.b, criterionId, rep, swapped: rep % 2 === 1 });
108
- }
109
- }
110
- }
111
- return jobs;
112
- },
113
- };
114
- }
115
-
116
- /** Convert a verification score to the reward range used by Bradley-Terry. */
117
- function normalize_score(score: number): number {
118
- return (score - VERIFICATION_SCALE.min) / (VERIFICATION_SCALE.max - VERIFICATION_SCALE.min);
119
- }
120
-
121
- /** Return the Bradley-Terry soft preference for the first score. */
122
- export function soft_win(scoreA: number, scoreB: number): number {
123
- const difference = normalize_score(scoreA) - normalize_score(scoreB);
124
- return 1 / (1 + Math.exp(-difference));
125
- }
126
-
127
- /** Add each preference to both candidates' win mass and comparison count. */
128
- export function accumulate(prefs: readonly Preference[], w: number[], c: number[]): void {
129
- for (const { a, b, p } of prefs) {
130
- w[a]! += p;
131
- c[a]! += 1;
132
- w[b]! += 1 - p;
133
- c[b]! += 1;
134
- }
135
- }
136
-
137
- function mean_preference(w: number[], c: number[], index: number): number {
138
- return c[index] === 0 ? 0 : w[index]! / c[index]!;
139
- }
140
-
141
- function candidate_order(w: number[], c: number[]): number[] {
142
- return Array.from({ length: w.length }, (_, index) => index).sort((left, right) => {
143
- const difference = mean_preference(w, c, right) - mean_preference(w, c, left);
144
- return difference === 0 ? left - right : difference;
145
- });
146
- }
147
-
148
- /** Return the top-k candidate indices, resolving equal means by index. */
149
- export function select_pivots(w: number[], c: number[], k: number): number[] {
150
- return candidate_order(w, c).slice(0, k);
151
- }
152
-
153
- /** Return every candidate ordered by mean preference, including unscored ones. */
154
- export function rank_candidates(w: number[], c: number[]): Ranking {
155
- return candidate_order(w, c).map((index) => ({ index, meanPreference: mean_preference(w, c, index) }));
156
- }
@@ -1,51 +0,0 @@
1
- /**
2
- * Steering propagation wrapper for builtin workflow run contexts.
3
- *
4
- * Every builtin workflow wraps its run context once, at the definition entry
5
- * point, so each `ctx.task` / `ctx.chain` / `ctx.parallel` prompt carries the
6
- * steering propagation contract. Wrapping the context rather than every call
7
- * site means a stage added later inherits the pattern instead of silently
8
- * dropping user amendments on the floor.
9
- *
10
- * The wrapper delegates through the prototype chain rather than spreading:
11
- * the runtime context exposes `cwd` as a getter that resolves the workflow's
12
- * current working directory on each read, and a spread would snapshot it.
13
- *
14
- * cross-ref:
15
- * - builtin/shared-prompts.ts (STEERING_PROPAGATION_CONTRACT)
16
- * - test/unit/builtin-workflow-steering-propagation.test.ts (enforcement)
17
- */
18
- import type {
19
- WorkflowInputValues,
20
- WorkflowOutputValues,
21
- WorkflowRunContext,
22
- WorkflowTaskOptions,
23
- WorkflowTaskStep,
24
- } from "../src/shared/types.js";
25
- import { withSteeringPropagation } from "./shared-prompts.js";
26
-
27
- function withPromptContract(options: WorkflowTaskOptions): WorkflowTaskOptions {
28
- return options.prompt === undefined
29
- ? options
30
- : { ...options, prompt: withSteeringPropagation(options.prompt) };
31
- }
32
-
33
- function withStepContract(step: WorkflowTaskStep): WorkflowTaskStep {
34
- const withPrompt = step.prompt === undefined
35
- ? step
36
- : { ...step, prompt: withSteeringPropagation(step.prompt) };
37
- return withPrompt.task === undefined
38
- ? withPrompt
39
- : { ...withPrompt, task: withSteeringPropagation(withPrompt.task) };
40
- }
41
-
42
- export function withSteeringPropagationContext<
43
- TInputs extends WorkflowInputValues,
44
- TOutputs extends WorkflowOutputValues,
45
- >(ctx: WorkflowRunContext<TInputs, TOutputs>): WorkflowRunContext<TInputs, TOutputs> {
46
- const wrapped = Object.create(ctx) as WorkflowRunContext<TInputs, TOutputs>;
47
- wrapped.task = (name, options) => ctx.task(name, withPromptContract(options));
48
- wrapped.chain = (steps, options) => ctx.chain(steps.map(withStepContract), options);
49
- wrapped.parallel = (steps, options) => ctx.parallel(steps.map(withStepContract), options);
50
- return wrapped;
51
- }
@@ -1,70 +0,0 @@
1
- type PromptSection = readonly [tag: string, content: string];
2
-
3
- const 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.";
4
- const 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.";
5
-
6
- /** The default three-criterion decomposition of the tournament rubric. */
7
- export const DEFAULT_TOURNAMENT_CRITERIA = [
8
- { name: "Correctness", description: "Satisfies the task without material errors." },
9
- { name: "Completeness", description: "Covers required outcomes and important edge cases." },
10
- {
11
- name: "Evidence and task fit",
12
- description: "Supports claims with observable evidence or checks and is directly usable without irrelevant work.",
13
- },
14
- ] as const;
15
-
16
- function taggedPrompt(sections: readonly PromptSection[]): string {
17
- return sections
18
- .map(([tag, content]) => `<${tag}>\n${content.trim()}\n</${tag}>`)
19
- .join("\n\n");
20
- }
21
-
22
- export function renderTournamentAttemptPrompt(task: string, attempt: number): string {
23
- return taggedPrompt([
24
- ["role", "You are an independent solution author competing on solution quality."],
25
- ["attempt", `Produce attempt ${attempt} without assuming another attempt's approach or conclusions.`],
26
- ["success_criteria", "A judge can evaluate this artifact directly against correctness, completeness, evidence, and task fit."],
27
- ["requirements", [
28
- "Deliver a complete, self-contained solution rather than commentary about how to solve it.",
29
- "Ground important claims in observable evidence or executable checks.",
30
- "State assumptions, limitations, and validation performed.",
31
- "Optimize for correctness and usefulness, not length.",
32
- GROUNDED_REPORTING,
33
- ].join("\n")],
34
- ["stop_rules", "Stop when the solution is complete, supported, validated where practical, and its residual risks are stated."],
35
- ["output_format", `Markdown with Solution, Evidence and validation, Assumptions, and Residual risks. ${READABLE_REPORT}`],
36
- ["objective", task],
37
- ]);
38
- }
39
-
40
- export function renderComparisonsReducerPrompt(options: {
41
- readonly task: string;
42
- readonly comparisonsPath: string;
43
- readonly ranking: readonly { readonly label: string; readonly meanPreference: number }[];
44
- readonly winnerLabel: string;
45
- readonly winnerPath: string;
46
- }): string {
47
- const rankingText = options.ranking
48
- .map((entry, index) => `${index + 1}. ${entry.label} (mean preference ${entry.meanPreference})`)
49
- .join("\n");
50
- return taggedPrompt([
51
- ["artifacts", [
52
- `Comparisons ledger: ${options.comparisonsPath}`,
53
- `Winning artifact (${options.winnerLabel}): ${options.winnerPath}`,
54
- "Read the ledger and winning artifact before reporting.",
55
- ].join("\n")],
56
- ["role", "You are the soft-scored tournament reducer and final reporter."],
57
- ["ranking", rankingText],
58
- ["requirements", [
59
- "Return the winning solution faithfully; do not silently combine losing material into it.",
60
- "Report the full ranking exactly as recorded in the comparisons ledger.",
61
- "Identify notable score disagreements, invalid reports, or other limitations recorded by judges.",
62
- "Cite the comparisons ledger and winning artifact paths.",
63
- GROUNDED_REPORTING,
64
- ].join("\n")],
65
- ["success_criteria", "A reader can use the winning solution and recompute the ranking from the durable comparisons ledger."],
66
- ["stop_rules", "Stop after faithfully presenting the winner, full ranking, decision evidence, and residual risks."],
67
- ["output_format", `Markdown with Winner, Full ranking, Decision trail, Evidence, Notable disagreements, and Residual risks. ${READABLE_REPORT}`],
68
- ["objective", options.task],
69
- ]);
70
- }