@spendgraph/workflows 0.2.0

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 (210) hide show
  1. package/README.md +149 -0
  2. package/dist/index.d.ts +1 -0
  3. package/dist/index.js +1 -0
  4. package/dist/noesis/attribution.d.ts +24 -0
  5. package/dist/noesis/attribution.js +43 -0
  6. package/dist/noesis/context.d.ts +18 -0
  7. package/dist/noesis/context.js +16 -0
  8. package/dist/noesis/draft/draft.d.ts +18 -0
  9. package/dist/noesis/draft/draft.js +50 -0
  10. package/dist/noesis/draft/index.d.ts +2 -0
  11. package/dist/noesis/draft/index.js +1 -0
  12. package/dist/noesis/draft/types.d.ts +27 -0
  13. package/dist/noesis/draft/types.js +1 -0
  14. package/dist/noesis/events.d.ts +158 -0
  15. package/dist/noesis/events.js +24 -0
  16. package/dist/noesis/execute/execute.d.ts +22 -0
  17. package/dist/noesis/execute/execute.js +85 -0
  18. package/dist/noesis/execute/index.d.ts +3 -0
  19. package/dist/noesis/execute/index.js +2 -0
  20. package/dist/noesis/execute/order.d.ts +11 -0
  21. package/dist/noesis/execute/order.js +28 -0
  22. package/dist/noesis/execute/types.d.ts +37 -0
  23. package/dist/noesis/execute/types.js +1 -0
  24. package/dist/noesis/gates/closure-checklist/index.d.ts +3 -0
  25. package/dist/noesis/gates/closure-checklist/index.js +2 -0
  26. package/dist/noesis/gates/closure-checklist/invoke.d.ts +5 -0
  27. package/dist/noesis/gates/closure-checklist/invoke.js +6 -0
  28. package/dist/noesis/gates/closure-checklist/prompt.d.ts +5 -0
  29. package/dist/noesis/gates/closure-checklist/prompt.js +32 -0
  30. package/dist/noesis/gates/closure-checklist/types.d.ts +20 -0
  31. package/dist/noesis/gates/closure-checklist/types.js +1 -0
  32. package/dist/noesis/gates/cqot-gate/index.d.ts +3 -0
  33. package/dist/noesis/gates/cqot-gate/index.js +2 -0
  34. package/dist/noesis/gates/cqot-gate/invoke.d.ts +5 -0
  35. package/dist/noesis/gates/cqot-gate/invoke.js +6 -0
  36. package/dist/noesis/gates/cqot-gate/prompt.d.ts +5 -0
  37. package/dist/noesis/gates/cqot-gate/prompt.js +27 -0
  38. package/dist/noesis/gates/cqot-gate/types.d.ts +23 -0
  39. package/dist/noesis/gates/cqot-gate/types.js +1 -0
  40. package/dist/noesis/gates/premortem/index.d.ts +3 -0
  41. package/dist/noesis/gates/premortem/index.js +2 -0
  42. package/dist/noesis/gates/premortem/invoke.d.ts +5 -0
  43. package/dist/noesis/gates/premortem/invoke.js +6 -0
  44. package/dist/noesis/gates/premortem/prompt.d.ts +5 -0
  45. package/dist/noesis/gates/premortem/prompt.js +37 -0
  46. package/dist/noesis/gates/premortem/types.d.ts +28 -0
  47. package/dist/noesis/gates/premortem/types.js +1 -0
  48. package/dist/noesis/gates/red-team/index.d.ts +3 -0
  49. package/dist/noesis/gates/red-team/index.js +2 -0
  50. package/dist/noesis/gates/red-team/invoke.d.ts +5 -0
  51. package/dist/noesis/gates/red-team/invoke.js +6 -0
  52. package/dist/noesis/gates/red-team/prompt.d.ts +5 -0
  53. package/dist/noesis/gates/red-team/prompt.js +25 -0
  54. package/dist/noesis/gates/red-team/types.d.ts +21 -0
  55. package/dist/noesis/gates/red-team/types.js +1 -0
  56. package/dist/noesis/gates/standards-review/index.d.ts +3 -0
  57. package/dist/noesis/gates/standards-review/index.js +2 -0
  58. package/dist/noesis/gates/standards-review/invoke.d.ts +5 -0
  59. package/dist/noesis/gates/standards-review/invoke.js +6 -0
  60. package/dist/noesis/gates/standards-review/prompt.d.ts +5 -0
  61. package/dist/noesis/gates/standards-review/prompt.js +26 -0
  62. package/dist/noesis/gates/standards-review/types.d.ts +20 -0
  63. package/dist/noesis/gates/standards-review/types.js +1 -0
  64. package/dist/noesis/gates/think-checkpoint/index.d.ts +3 -0
  65. package/dist/noesis/gates/think-checkpoint/index.js +2 -0
  66. package/dist/noesis/gates/think-checkpoint/invoke.d.ts +5 -0
  67. package/dist/noesis/gates/think-checkpoint/invoke.js +6 -0
  68. package/dist/noesis/gates/think-checkpoint/prompt.d.ts +5 -0
  69. package/dist/noesis/gates/think-checkpoint/prompt.js +28 -0
  70. package/dist/noesis/gates/think-checkpoint/types.d.ts +21 -0
  71. package/dist/noesis/gates/think-checkpoint/types.js +1 -0
  72. package/dist/noesis/index.d.ts +51 -0
  73. package/dist/noesis/index.js +27 -0
  74. package/dist/noesis/producers/cove-answers/index.d.ts +3 -0
  75. package/dist/noesis/producers/cove-answers/index.js +2 -0
  76. package/dist/noesis/producers/cove-answers/invoke.d.ts +5 -0
  77. package/dist/noesis/producers/cove-answers/invoke.js +6 -0
  78. package/dist/noesis/producers/cove-answers/prompt.d.ts +5 -0
  79. package/dist/noesis/producers/cove-answers/prompt.js +27 -0
  80. package/dist/noesis/producers/cove-answers/types.d.ts +32 -0
  81. package/dist/noesis/producers/cove-answers/types.js +1 -0
  82. package/dist/noesis/producers/cove-questions/index.d.ts +3 -0
  83. package/dist/noesis/producers/cove-questions/index.js +2 -0
  84. package/dist/noesis/producers/cove-questions/invoke.d.ts +5 -0
  85. package/dist/noesis/producers/cove-questions/invoke.js +6 -0
  86. package/dist/noesis/producers/cove-questions/prompt.d.ts +5 -0
  87. package/dist/noesis/producers/cove-questions/prompt.js +26 -0
  88. package/dist/noesis/producers/cove-questions/types.d.ts +17 -0
  89. package/dist/noesis/producers/cove-questions/types.js +1 -0
  90. package/dist/noesis/producers/decompose/index.d.ts +3 -0
  91. package/dist/noesis/producers/decompose/index.js +2 -0
  92. package/dist/noesis/producers/decompose/invoke.d.ts +5 -0
  93. package/dist/noesis/producers/decompose/invoke.js +6 -0
  94. package/dist/noesis/producers/decompose/prompt.d.ts +22 -0
  95. package/dist/noesis/producers/decompose/prompt.js +68 -0
  96. package/dist/noesis/producers/decompose/types.d.ts +41 -0
  97. package/dist/noesis/producers/decompose/types.js +1 -0
  98. package/dist/noesis/producers/discriminating-test/index.d.ts +3 -0
  99. package/dist/noesis/producers/discriminating-test/index.js +2 -0
  100. package/dist/noesis/producers/discriminating-test/invoke.d.ts +5 -0
  101. package/dist/noesis/producers/discriminating-test/invoke.js +6 -0
  102. package/dist/noesis/producers/discriminating-test/prompt.d.ts +5 -0
  103. package/dist/noesis/producers/discriminating-test/prompt.js +67 -0
  104. package/dist/noesis/producers/discriminating-test/types.d.ts +32 -0
  105. package/dist/noesis/producers/discriminating-test/types.js +1 -0
  106. package/dist/noesis/producers/plan-candidates/index.d.ts +3 -0
  107. package/dist/noesis/producers/plan-candidates/index.js +2 -0
  108. package/dist/noesis/producers/plan-candidates/invoke.d.ts +5 -0
  109. package/dist/noesis/producers/plan-candidates/invoke.js +6 -0
  110. package/dist/noesis/producers/plan-candidates/prompt.d.ts +5 -0
  111. package/dist/noesis/producers/plan-candidates/prompt.js +46 -0
  112. package/dist/noesis/producers/plan-candidates/types.d.ts +32 -0
  113. package/dist/noesis/producers/plan-candidates/types.js +1 -0
  114. package/dist/noesis/producers/qn-brief/index.d.ts +3 -0
  115. package/dist/noesis/producers/qn-brief/index.js +2 -0
  116. package/dist/noesis/producers/qn-brief/invoke.d.ts +5 -0
  117. package/dist/noesis/producers/qn-brief/invoke.js +6 -0
  118. package/dist/noesis/producers/qn-brief/prompt.d.ts +12 -0
  119. package/dist/noesis/producers/qn-brief/prompt.js +65 -0
  120. package/dist/noesis/producers/qn-brief/types.d.ts +42 -0
  121. package/dist/noesis/producers/qn-brief/types.js +1 -0
  122. package/dist/noesis/producers/toulmin/answer.d.ts +18 -0
  123. package/dist/noesis/producers/toulmin/answer.js +87 -0
  124. package/dist/noesis/producers/toulmin/index.d.ts +5 -0
  125. package/dist/noesis/producers/toulmin/index.js +4 -0
  126. package/dist/noesis/producers/toulmin/invoke.d.ts +18 -0
  127. package/dist/noesis/producers/toulmin/invoke.js +53 -0
  128. package/dist/noesis/producers/toulmin/prompt.d.ts +12 -0
  129. package/dist/noesis/producers/toulmin/prompt.js +60 -0
  130. package/dist/noesis/producers/toulmin/render.d.ts +14 -0
  131. package/dist/noesis/producers/toulmin/render.js +82 -0
  132. package/dist/noesis/producers/toulmin/types.d.ts +126 -0
  133. package/dist/noesis/producers/toulmin/types.js +1 -0
  134. package/dist/noesis/question.d.ts +24 -0
  135. package/dist/noesis/question.js +37 -0
  136. package/dist/noesis/repair/reflection/index.d.ts +3 -0
  137. package/dist/noesis/repair/reflection/index.js +2 -0
  138. package/dist/noesis/repair/reflection/invoke.d.ts +5 -0
  139. package/dist/noesis/repair/reflection/invoke.js +6 -0
  140. package/dist/noesis/repair/reflection/prompt.d.ts +5 -0
  141. package/dist/noesis/repair/reflection/prompt.js +26 -0
  142. package/dist/noesis/repair/reflection/types.d.ts +17 -0
  143. package/dist/noesis/repair/reflection/types.js +1 -0
  144. package/dist/noesis/retry.d.ts +25 -0
  145. package/dist/noesis/retry.js +60 -0
  146. package/dist/noesis/route.d.ts +29 -0
  147. package/dist/noesis/route.js +69 -0
  148. package/dist/noesis/router/triage/index.d.ts +3 -0
  149. package/dist/noesis/router/triage/index.js +2 -0
  150. package/dist/noesis/router/triage/invoke.d.ts +31 -0
  151. package/dist/noesis/router/triage/invoke.js +76 -0
  152. package/dist/noesis/router/triage/prompt.d.ts +11 -0
  153. package/dist/noesis/router/triage/prompt.js +34 -0
  154. package/dist/noesis/router/triage/types.d.ts +70 -0
  155. package/dist/noesis/router/triage/types.js +1 -0
  156. package/dist/noesis/run/artifacts.d.ts +12 -0
  157. package/dist/noesis/run/artifacts.js +31 -0
  158. package/dist/noesis/run/errors.d.ts +38 -0
  159. package/dist/noesis/run/errors.js +55 -0
  160. package/dist/noesis/run/index.d.ts +6 -0
  161. package/dist/noesis/run/index.js +4 -0
  162. package/dist/noesis/run/ledger.d.ts +110 -0
  163. package/dist/noesis/run/ledger.js +184 -0
  164. package/dist/noesis/run/loop.d.ts +15 -0
  165. package/dist/noesis/run/loop.js +91 -0
  166. package/dist/noesis/run/plan.d.ts +18 -0
  167. package/dist/noesis/run/plan.js +39 -0
  168. package/dist/noesis/run/produce.d.ts +50 -0
  169. package/dist/noesis/run/produce.js +114 -0
  170. package/dist/noesis/run/redo.d.ts +24 -0
  171. package/dist/noesis/run/redo.js +41 -0
  172. package/dist/noesis/run/result.d.ts +5 -0
  173. package/dist/noesis/run/result.js +51 -0
  174. package/dist/noesis/run/run.d.ts +4 -0
  175. package/dist/noesis/run/run.js +73 -0
  176. package/dist/noesis/run/stages/classify.d.ts +7 -0
  177. package/dist/noesis/run/stages/classify.js +23 -0
  178. package/dist/noesis/run/stages/direct.d.ts +6 -0
  179. package/dist/noesis/run/stages/direct.js +8 -0
  180. package/dist/noesis/run/stages/full.d.ts +14 -0
  181. package/dist/noesis/run/stages/full.js +21 -0
  182. package/dist/noesis/run/stages/index.d.ts +5 -0
  183. package/dist/noesis/run/stages/index.js +5 -0
  184. package/dist/noesis/run/stages/retrieve.d.ts +13 -0
  185. package/dist/noesis/run/stages/retrieve.js +38 -0
  186. package/dist/noesis/run/stages/standard.d.ts +12 -0
  187. package/dist/noesis/run/stages/standard.js +19 -0
  188. package/dist/noesis/run/state.d.ts +26 -0
  189. package/dist/noesis/run/state.js +13 -0
  190. package/dist/noesis/run/stream.d.ts +28 -0
  191. package/dist/noesis/run/stream.js +33 -0
  192. package/dist/noesis/run/verify.d.ts +27 -0
  193. package/dist/noesis/run/verify.js +78 -0
  194. package/dist/noesis/slugs.d.ts +16 -0
  195. package/dist/noesis/slugs.js +46 -0
  196. package/dist/noesis/stage.d.ts +56 -0
  197. package/dist/noesis/stage.js +52 -0
  198. package/dist/noesis/started.d.ts +18 -0
  199. package/dist/noesis/started.js +39 -0
  200. package/dist/noesis/types.d.ts +167 -0
  201. package/dist/noesis/types.js +1 -0
  202. package/dist/noesis/usage.d.ts +49 -0
  203. package/dist/noesis/usage.js +56 -0
  204. package/dist/noesis/verify/index.d.ts +2 -0
  205. package/dist/noesis/verify/index.js +1 -0
  206. package/dist/noesis/verify/types.d.ts +54 -0
  207. package/dist/noesis/verify/types.js +1 -0
  208. package/dist/noesis/verify/verify.d.ts +36 -0
  209. package/dist/noesis/verify/verify.js +94 -0
  210. package/package.json +59 -0
@@ -0,0 +1,11 @@
1
+ import type { SubQuestion } from "../producers/decompose/index.js";
2
+ import type { Waves } from "./types.js";
3
+ /**
4
+ * The plan, grouped into what may run together.
5
+ *
6
+ * `read_only` siblings share a wave and `synthesis` takes one alone, which is
7
+ * the distinction the stage went to the trouble of typing. A dependency on an
8
+ * id nothing created can never be satisfied, so it lands in `unresolved`
9
+ * alongside a cycle rather than being run in the wrong order.
10
+ */
11
+ export declare function order(plan: SubQuestion[]): Waves;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The plan, grouped into what may run together.
3
+ *
4
+ * `read_only` siblings share a wave and `synthesis` takes one alone, which is
5
+ * the distinction the stage went to the trouble of typing. A dependency on an
6
+ * id nothing created can never be satisfied, so it lands in `unresolved`
7
+ * alongside a cycle rather than being run in the wrong order.
8
+ */
9
+ export function order(plan) {
10
+ const known = new Set(plan.map((sub) => sub.id));
11
+ const done = new Set();
12
+ const waves = [];
13
+ let left = [...plan];
14
+ while (left.length) {
15
+ const ready = left.filter((sub) => sub.depends_on.every((id) => known.has(id) && done.has(id)));
16
+ if (!ready.length)
17
+ break;
18
+ const together = ready.filter((sub) => sub.kind === "read_only");
19
+ if (together.length)
20
+ waves.push(together);
21
+ for (const alone of ready.filter((sub) => sub.kind !== "read_only"))
22
+ waves.push([alone]);
23
+ for (const sub of ready)
24
+ done.add(sub.id);
25
+ left = left.filter((sub) => !done.has(sub.id));
26
+ }
27
+ return { waves, unresolved: left.map((sub) => sub.id) };
28
+ }
@@ -0,0 +1,37 @@
1
+ import type { Emit } from "../events.js";
2
+ import type { SubQuestion, SubQuestionTool } from "../producers/decompose/index.js";
3
+ /** Which tool answers a sub-question, and the argument its question fills. */
4
+ export interface Wiring {
5
+ name: string;
6
+ arg: string;
7
+ }
8
+ export interface ExecuteOptions {
9
+ /** Merged over the defaults. A deployment names its own tools here. */
10
+ tools?: Partial<Record<SubQuestionTool, Wiring>>;
11
+ /** Where the dispatcher says which wave is running and what each call did. */
12
+ emit?: Emit;
13
+ }
14
+ /** What one sub-question came back with. */
15
+ export interface SubAnswer {
16
+ id: string;
17
+ question: string;
18
+ tool: SubQuestionTool;
19
+ status: "answered" | "skipped" | "failed";
20
+ /** The tool's output, parsed where it was JSON. Absent unless answered. */
21
+ result?: unknown;
22
+ /** Why it was skipped, or how it failed. */
23
+ reason?: string;
24
+ latencyMs: number;
25
+ }
26
+ export interface Execution {
27
+ answers: SubAnswer[];
28
+ /** Ids that could never run: a cycle, or a dependency nothing created. */
29
+ unresolved: string[];
30
+ /** Time spent inside tools. Not wall clock — a wave runs together. */
31
+ toolMs: number;
32
+ }
33
+ /** Sub-questions grouped into what may run together, in the order they run. */
34
+ export interface Waves {
35
+ waves: SubQuestion[][];
36
+ unresolved: string[];
37
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ export { invoke } from "./invoke.js";
2
+ export { CLOSURE_SCHEMA, CLOSURE_SLUG } from "./prompt.js";
3
+ export type { ClosureChecklist, ClosureChecklistInput, ClosureChecklistOptions, ClosureChecklistResult, ClosureGate, } from "./types.js";
@@ -0,0 +1,2 @@
1
+ export { invoke } from "./invoke.js";
2
+ export { CLOSURE_SCHEMA, CLOSURE_SLUG } from "./prompt.js";
@@ -0,0 +1,5 @@
1
+ import type { Llm } from "@spendgraph/llms";
2
+ import type { PromptClient } from "@spendgraph/prompt";
3
+ import type { ClosureChecklistInput, ClosureChecklistOptions, ClosureChecklistResult } from "./types.js";
4
+ /** Stage 6A. The last questions before an answer is allowed to close. */
5
+ export declare function invoke(client: PromptClient, llm: Llm, input: ClosureChecklistInput, opts?: ClosureChecklistOptions): Promise<ClosureChecklistResult>;
@@ -0,0 +1,6 @@
1
+ import { runStage } from "../../stage.js";
2
+ import { CLOSURE_SCHEMA, CLOSURE_SLUG } from "./prompt.js";
3
+ /** Stage 6A. The last questions before an answer is allowed to close. */
4
+ export function invoke(client, llm, input, opts = {}) {
5
+ return runStage(client, llm, CLOSURE_SLUG, CLOSURE_SCHEMA, input, opts);
6
+ }
@@ -0,0 +1,5 @@
1
+ import type { JsonSchema } from "@spendgraph/llms";
2
+ /** Stage 6A. Pulled by slug, so an edit needs no release here. */
3
+ export declare const CLOSURE_SLUG = "ctr-6a-closure-checklist-292xfc";
4
+ /** What the reply must be, as the prompt itself specifies it. */
5
+ export declare const CLOSURE_SCHEMA: JsonSchema;
@@ -0,0 +1,32 @@
1
+ /** Stage 6A. Pulled by slug, so an edit needs no release here. */
2
+ export const CLOSURE_SLUG = "ctr-6a-closure-checklist-292xfc";
3
+ /** What the reply must be, as the prompt itself specifies it. */
4
+ export const CLOSURE_SCHEMA = {
5
+ type: "object",
6
+ properties: {
7
+ what_else_could_this_be: { type: "array", items: { type: "string" } },
8
+ evidence_that_does_not_fit: { type: "array", items: { type: "string" } },
9
+ not_checked: { type: "array", items: { type: "string" } },
10
+ hostile_reviewer_attacks: { type: "array", items: { type: "string" } },
11
+ weakest_link: { type: "string" },
12
+ most_likely_reason_wrong: { type: "string" },
13
+ all_sub_questions_answered: { type: "boolean" },
14
+ unanswered: { type: "array", items: { type: "string" } },
15
+ gate: { type: "string", enum: ["close", "loop_back", "escalate"] },
16
+ loop_back_to: { type: ["string", "null"] },
17
+ reason: { type: "string" },
18
+ },
19
+ required: [
20
+ "what_else_could_this_be",
21
+ "evidence_that_does_not_fit",
22
+ "not_checked",
23
+ "hostile_reviewer_attacks",
24
+ "weakest_link",
25
+ "most_likely_reason_wrong",
26
+ "all_sub_questions_answered",
27
+ "unanswered",
28
+ "gate",
29
+ "loop_back_to",
30
+ "reason",
31
+ ],
32
+ };
@@ -0,0 +1,20 @@
1
+ import type { Asked } from "../../context.js";
2
+ import type { StageOptions, StageOutcome } from "../../stage.js";
3
+ export type ClosureGate = "close" | "loop_back" | "escalate";
4
+ export interface ClosureChecklist {
5
+ what_else_could_this_be: string[];
6
+ evidence_that_does_not_fit: string[];
7
+ not_checked: string[];
8
+ hostile_reviewer_attacks: string[];
9
+ weakest_link: string;
10
+ most_likely_reason_wrong: string;
11
+ all_sub_questions_answered: boolean;
12
+ unanswered: string[];
13
+ gate: ClosureGate;
14
+ /** The stage id to redo, or null. */
15
+ loop_back_to: string | null;
16
+ reason: string;
17
+ }
18
+ export type ClosureChecklistInput = Asked;
19
+ export type ClosureChecklistOptions = StageOptions;
20
+ export type ClosureChecklistResult = StageOutcome<ClosureChecklist>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ export { invoke } from "./invoke.js";
2
+ export { GATE_SCHEMA, GATE_SLUG } from "./prompt.js";
3
+ export type { CqotGate, CqotGateInput, CqotGateOptions, CqotGateResult, Gate, GateQuestion, GateVerdict, } from "./types.js";
@@ -0,0 +1,2 @@
1
+ export { invoke } from "./invoke.js";
2
+ export { GATE_SCHEMA, GATE_SLUG } from "./prompt.js";
@@ -0,0 +1,5 @@
1
+ import type { Llm } from "@spendgraph/llms";
2
+ import type { PromptClient } from "@spendgraph/prompt";
3
+ import type { CqotGateInput, CqotGateOptions, CqotGateResult } from "./types.js";
4
+ /** Stage 3C. Eight questions asked of the plan, and whether it may proceed. */
5
+ export declare function invoke(client: PromptClient, llm: Llm, input: CqotGateInput, opts?: CqotGateOptions): Promise<CqotGateResult>;
@@ -0,0 +1,6 @@
1
+ import { runStage } from "../../stage.js";
2
+ import { GATE_SCHEMA, GATE_SLUG } from "./prompt.js";
3
+ /** Stage 3C. Eight questions asked of the plan, and whether it may proceed. */
4
+ export function invoke(client, llm, input, opts = {}) {
5
+ return runStage(client, llm, GATE_SLUG, GATE_SCHEMA, input, opts);
6
+ }
@@ -0,0 +1,5 @@
1
+ import type { JsonSchema } from "@spendgraph/llms";
2
+ /** Stage 3C. Pulled by slug, so an edit needs no release here. */
3
+ export declare const GATE_SLUG = "ctr-3c-cqot-gate-7128w7";
4
+ /** What the reply must be, as the prompt itself specifies it. */
5
+ export declare const GATE_SCHEMA: JsonSchema;
@@ -0,0 +1,27 @@
1
+ /** Stage 3C. Pulled by slug, so an edit needs no release here. */
2
+ export const GATE_SLUG = "ctr-3c-cqot-gate-7128w7";
3
+ /** What the reply must be, as the prompt itself specifies it. */
4
+ export const GATE_SCHEMA = {
5
+ type: "object",
6
+ properties: {
7
+ questions: {
8
+ type: "array",
9
+ items: {
10
+ type: "object",
11
+ properties: {
12
+ n: { type: "number" },
13
+ verdict: { type: "string", enum: ["pass", "fail"] },
14
+ reason: { type: "string" },
15
+ step_at_fault: { type: ["string", "null"] },
16
+ },
17
+ required: ["n", "verdict", "reason", "step_at_fault"],
18
+ },
19
+ minItems: 8,
20
+ maxItems: 8,
21
+ },
22
+ passed_count: { type: "number" },
23
+ gate: { type: "string", enum: ["pass", "revise"] },
24
+ blocking: { type: "array", items: { type: "number" } },
25
+ },
26
+ required: ["questions", "passed_count", "gate", "blocking"],
27
+ };
@@ -0,0 +1,23 @@
1
+ import type { Asked } from "../../context.js";
2
+ import type { StageOptions, StageOutcome } from "../../stage.js";
3
+ export type GateVerdict = "pass" | "fail";
4
+ /** `pass` at seven of eight or better, otherwise `revise`. */
5
+ export type Gate = "pass" | "revise";
6
+ export interface GateQuestion {
7
+ n: number;
8
+ verdict: GateVerdict;
9
+ reason: string;
10
+ /** The step at fault, or null on a pass. */
11
+ step_at_fault: string | null;
12
+ }
13
+ export interface CqotGate {
14
+ /** All eight, `n` from 1 to 8, in order. */
15
+ questions: GateQuestion[];
16
+ passed_count: number;
17
+ gate: Gate;
18
+ /** The `n` values that must be fixed before re-submission. */
19
+ blocking: number[];
20
+ }
21
+ export type CqotGateInput = Asked;
22
+ export type CqotGateOptions = StageOptions;
23
+ export type CqotGateResult = StageOutcome<CqotGate>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ export { invoke } from "./invoke.js";
2
+ export { PREMORTEM_SCHEMA, PREMORTEM_SLUG } from "./prompt.js";
3
+ export type { Damage, FailureCause, Inversion, Likelihood, Premortem, PremortemInput, PremortemOptions, PremortemResult, PremortemVerdict, } from "./types.js";
@@ -0,0 +1,2 @@
1
+ export { invoke } from "./invoke.js";
2
+ export { PREMORTEM_SCHEMA, PREMORTEM_SLUG } from "./prompt.js";
@@ -0,0 +1,5 @@
1
+ import type { Llm } from "@spendgraph/llms";
2
+ import type { PromptClient } from "@spendgraph/prompt";
3
+ import type { PremortemInput, PremortemOptions, PremortemResult } from "./types.js";
4
+ /** Stage 3B. The plan assumed dead, and what killed it. */
5
+ export declare function invoke(client: PromptClient, llm: Llm, input: PremortemInput, opts?: PremortemOptions): Promise<PremortemResult>;
@@ -0,0 +1,6 @@
1
+ import { runStage } from "../../stage.js";
2
+ import { PREMORTEM_SCHEMA, PREMORTEM_SLUG } from "./prompt.js";
3
+ /** Stage 3B. The plan assumed dead, and what killed it. */
4
+ export function invoke(client, llm, input, opts = {}) {
5
+ return runStage(client, llm, PREMORTEM_SLUG, PREMORTEM_SCHEMA, input, opts);
6
+ }
@@ -0,0 +1,5 @@
1
+ import type { JsonSchema } from "@spendgraph/llms";
2
+ /** Stage 3B. Pulled by slug, so an edit needs no release here. */
3
+ export declare const PREMORTEM_SLUG = "ctr-3b-premortem-0w34wx";
4
+ /** What the reply must be, as the prompt itself specifies it. */
5
+ export declare const PREMORTEM_SCHEMA: JsonSchema;
@@ -0,0 +1,37 @@
1
+ /** Stage 3B. Pulled by slug, so an edit needs no release here. */
2
+ export const PREMORTEM_SLUG = "ctr-3b-premortem-0w34wx";
3
+ /** What the reply must be, as the prompt itself specifies it. */
4
+ export const PREMORTEM_SCHEMA = {
5
+ type: "object",
6
+ properties: {
7
+ failure_causes: {
8
+ type: "array",
9
+ items: {
10
+ type: "object",
11
+ properties: {
12
+ cause: { type: "string" },
13
+ mechanism: { type: "string" },
14
+ likelihood: { type: "string", enum: ["low", "medium", "high"] },
15
+ damage: { type: "string", enum: ["low", "medium", "high"] },
16
+ detect_by: { type: "string" },
17
+ patch: { type: "string" },
18
+ },
19
+ required: ["cause", "mechanism", "likelihood", "damage", "detect_by", "patch"],
20
+ },
21
+ },
22
+ inversion: {
23
+ type: "array",
24
+ items: {
25
+ type: "object",
26
+ properties: {
27
+ guaranteed_failure: { type: "string" },
28
+ plan_does_this: { type: "boolean" },
29
+ },
30
+ required: ["guaranteed_failure", "plan_does_this"],
31
+ },
32
+ },
33
+ fatal: { type: "boolean" },
34
+ verdict: { type: "string", enum: ["proceed", "patch_and_proceed", "replan"] },
35
+ },
36
+ required: ["failure_causes", "inversion", "fatal", "verdict"],
37
+ };
@@ -0,0 +1,28 @@
1
+ import type { Asked } from "../../context.js";
2
+ import type { StageOptions, StageOutcome } from "../../stage.js";
3
+ export type Likelihood = "low" | "medium" | "high";
4
+ export type Damage = "low" | "medium" | "high";
5
+ /** What to do with the plan. */
6
+ export type PremortemVerdict = "proceed" | "patch_and_proceed" | "replan";
7
+ export interface FailureCause {
8
+ cause: string;
9
+ mechanism: string;
10
+ likelihood: Likelihood;
11
+ damage: Damage;
12
+ detect_by: string;
13
+ patch: string;
14
+ }
15
+ /** A guaranteed way to fail, and whether the plan already does it. */
16
+ export interface Inversion {
17
+ guaranteed_failure: string;
18
+ plan_does_this: boolean;
19
+ }
20
+ export interface Premortem {
21
+ failure_causes: FailureCause[];
22
+ inversion: Inversion[];
23
+ fatal: boolean;
24
+ verdict: PremortemVerdict;
25
+ }
26
+ export type PremortemInput = Asked;
27
+ export type PremortemOptions = StageOptions;
28
+ export type PremortemResult = StageOutcome<Premortem>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ export { invoke } from "./invoke.js";
2
+ export { RED_TEAM_SCHEMA, RED_TEAM_SLUG } from "./prompt.js";
3
+ export type { Objection, RedTeam, RedTeamInput, RedTeamOptions, RedTeamResult, RedTeamVerdict, Severity, } from "./types.js";
@@ -0,0 +1,2 @@
1
+ export { invoke } from "./invoke.js";
2
+ export { RED_TEAM_SCHEMA, RED_TEAM_SLUG } from "./prompt.js";
@@ -0,0 +1,5 @@
1
+ import type { Llm } from "@spendgraph/llms";
2
+ import type { PromptClient } from "@spendgraph/prompt";
3
+ import type { RedTeamInput, RedTeamOptions, RedTeamResult } from "./types.js";
4
+ /** Stage 6B. The answer attacked, and whether it survived. */
5
+ export declare function invoke(client: PromptClient, llm: Llm, input: RedTeamInput, opts?: RedTeamOptions): Promise<RedTeamResult>;
@@ -0,0 +1,6 @@
1
+ import { runStage } from "../../stage.js";
2
+ import { RED_TEAM_SCHEMA, RED_TEAM_SLUG } from "./prompt.js";
3
+ /** Stage 6B. The answer attacked, and whether it survived. */
4
+ export function invoke(client, llm, input, opts = {}) {
5
+ return runStage(client, llm, RED_TEAM_SLUG, RED_TEAM_SCHEMA, input, opts);
6
+ }
@@ -0,0 +1,5 @@
1
+ import type { JsonSchema } from "@spendgraph/llms";
2
+ /** Stage 6B. Pulled by slug, so an edit needs no release here. */
3
+ export declare const RED_TEAM_SLUG = "ctr-6b-red-team-f084c0";
4
+ /** What the reply must be, as the prompt itself specifies it. */
5
+ export declare const RED_TEAM_SCHEMA: JsonSchema;
@@ -0,0 +1,25 @@
1
+ /** Stage 6B. Pulled by slug, so an edit needs no release here. */
2
+ export const RED_TEAM_SLUG = "ctr-6b-red-team-f084c0";
3
+ /** What the reply must be, as the prompt itself specifies it. */
4
+ export const RED_TEAM_SCHEMA = {
5
+ type: "object",
6
+ properties: {
7
+ objections: {
8
+ type: "array",
9
+ items: {
10
+ type: "object",
11
+ properties: {
12
+ claim_attacked: { type: "string" },
13
+ objection: { type: "string" },
14
+ severity: { type: "string", enum: ["fatal", "serious", "minor"] },
15
+ settled_by: { type: "string" },
16
+ },
17
+ required: ["claim_attacked", "objection", "severity", "settled_by"],
18
+ },
19
+ },
20
+ fatal_found: { type: "boolean" },
21
+ verdict: { type: "string", enum: ["survives", "revise", "reject"] },
22
+ would_break_it: { type: "string" },
23
+ },
24
+ required: ["objections", "fatal_found", "verdict", "would_break_it"],
25
+ };
@@ -0,0 +1,21 @@
1
+ import type { Asked } from "../../context.js";
2
+ import type { StageOptions, StageOutcome } from "../../stage.js";
3
+ export type Severity = "fatal" | "serious" | "minor";
4
+ /** `survives` with nothing serious standing, `revise` with serious ones, `reject` with a fatal one. */
5
+ export type RedTeamVerdict = "survives" | "revise" | "reject";
6
+ export interface Objection {
7
+ claim_attacked: string;
8
+ objection: string;
9
+ severity: Severity;
10
+ settled_by: string;
11
+ }
12
+ export interface RedTeam {
13
+ objections: Objection[];
14
+ fatal_found: boolean;
15
+ verdict: RedTeamVerdict;
16
+ /** The evidence that would overturn the conclusion. Required even when nothing was found. */
17
+ would_break_it: string;
18
+ }
19
+ export type RedTeamInput = Asked;
20
+ export type RedTeamOptions = StageOptions;
21
+ export type RedTeamResult = StageOutcome<RedTeam>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ export { invoke } from "./invoke.js";
2
+ export { STANDARDS_SCHEMA, STANDARDS_SLUG } from "./prompt.js";
3
+ export type { Criterion, CriterionVerdict, ReviewOutcome, StandardsReview, StandardsReviewInput, StandardsReviewOptions, StandardsReviewResult, } from "./types.js";
@@ -0,0 +1,2 @@
1
+ export { invoke } from "./invoke.js";
2
+ export { STANDARDS_SCHEMA, STANDARDS_SLUG } from "./prompt.js";
@@ -0,0 +1,5 @@
1
+ import type { Llm } from "@spendgraph/llms";
2
+ import type { PromptClient } from "@spendgraph/prompt";
3
+ import type { StandardsReviewInput, StandardsReviewOptions, StandardsReviewResult } from "./types.js";
4
+ /** Stage 5C. The answer against eight standards, each passed or failed on the evidence. */
5
+ export declare function invoke(client: PromptClient, llm: Llm, input: StandardsReviewInput, opts?: StandardsReviewOptions): Promise<StandardsReviewResult>;
@@ -0,0 +1,6 @@
1
+ import { runStage } from "../../stage.js";
2
+ import { STANDARDS_SCHEMA, STANDARDS_SLUG } from "./prompt.js";
3
+ /** Stage 5C. The answer against eight standards, each passed or failed on the evidence. */
4
+ export function invoke(client, llm, input, opts = {}) {
5
+ return runStage(client, llm, STANDARDS_SLUG, STANDARDS_SCHEMA, input, opts);
6
+ }
@@ -0,0 +1,5 @@
1
+ import type { JsonSchema } from "@spendgraph/llms";
2
+ /** Stage 5C. Pulled by slug, so an edit needs no release here. */
3
+ export declare const STANDARDS_SLUG = "ctr-5c-standards-review-17c6w4";
4
+ /** What the reply must be, as the prompt itself specifies it. */
5
+ export declare const STANDARDS_SCHEMA: JsonSchema;
@@ -0,0 +1,26 @@
1
+ /** Stage 5C. Pulled by slug, so an edit needs no release here. */
2
+ export const STANDARDS_SLUG = "ctr-5c-standards-review-17c6w4";
3
+ /** What the reply must be, as the prompt itself specifies it. */
4
+ export const STANDARDS_SCHEMA = {
5
+ type: "object",
6
+ properties: {
7
+ criteria: {
8
+ type: "array",
9
+ items: {
10
+ type: "object",
11
+ properties: {
12
+ name: { type: "string" },
13
+ verdict: { type: "string", enum: ["pass", "fail"] },
14
+ critique: { type: "string" },
15
+ locus: { type: ["string", "null"] },
16
+ },
17
+ required: ["name", "verdict", "critique", "locus"],
18
+ },
19
+ minItems: 8,
20
+ maxItems: 8,
21
+ },
22
+ failed: { type: "array", items: { type: "string" } },
23
+ overall: { type: "string", enum: ["accept", "revise", "reject"] },
24
+ },
25
+ required: ["criteria", "failed", "overall"],
26
+ };
@@ -0,0 +1,20 @@
1
+ import type { Asked } from "../../context.js";
2
+ import type { StageOptions, StageOutcome } from "../../stage.js";
3
+ export type CriterionVerdict = "pass" | "fail";
4
+ export type ReviewOutcome = "accept" | "revise" | "reject";
5
+ export interface Criterion {
6
+ name: string;
7
+ verdict: CriterionVerdict;
8
+ critique: string;
9
+ /** The quoted span at fault, or null on a pass. */
10
+ locus: string | null;
11
+ }
12
+ export interface StandardsReview {
13
+ /** All eight, in the order the prompt lists them. */
14
+ criteria: Criterion[];
15
+ failed: string[];
16
+ overall: ReviewOutcome;
17
+ }
18
+ export type StandardsReviewInput = Asked;
19
+ export type StandardsReviewOptions = StageOptions;
20
+ export type StandardsReviewResult = StageOutcome<StandardsReview>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ export { invoke } from "./invoke.js";
2
+ export { CHECKPOINT_SCHEMA, CHECKPOINT_SLUG } from "./prompt.js";
3
+ export type { Divergence, NextAction, ThinkCheckpoint, ThinkCheckpointInput, ThinkCheckpointOptions, ThinkCheckpointResult, } from "./types.js";
@@ -0,0 +1,2 @@
1
+ export { invoke } from "./invoke.js";
2
+ export { CHECKPOINT_SCHEMA, CHECKPOINT_SLUG } from "./prompt.js";
@@ -0,0 +1,5 @@
1
+ import type { Llm } from "@spendgraph/llms";
2
+ import type { PromptClient } from "@spendgraph/prompt";
3
+ import type { ThinkCheckpointInput, ThinkCheckpointOptions, ThinkCheckpointResult } from "./types.js";
4
+ /** Stage 4A. What was predicted against what happened, and whether to carry on. */
5
+ export declare function invoke(client: PromptClient, llm: Llm, input: ThinkCheckpointInput, opts?: ThinkCheckpointOptions): Promise<ThinkCheckpointResult>;
@@ -0,0 +1,6 @@
1
+ import { runStage } from "../../stage.js";
2
+ import { CHECKPOINT_SCHEMA, CHECKPOINT_SLUG } from "./prompt.js";
3
+ /** Stage 4A. What was predicted against what happened, and whether to carry on. */
4
+ export function invoke(client, llm, input, opts = {}) {
5
+ return runStage(client, llm, CHECKPOINT_SLUG, CHECKPOINT_SCHEMA, input, opts);
6
+ }
@@ -0,0 +1,5 @@
1
+ import type { JsonSchema } from "@spendgraph/llms";
2
+ /** Stage 4A. Pulled by slug, so an edit needs no release here. */
3
+ export declare const CHECKPOINT_SLUG = "ctr-4a-think-checkpoint-8d5302";
4
+ /** What the reply must be, as the prompt itself specifies it. */
5
+ export declare const CHECKPOINT_SCHEMA: JsonSchema;
@@ -0,0 +1,28 @@
1
+ /** Stage 4A. Pulled by slug, so an edit needs no release here. */
2
+ export const CHECKPOINT_SLUG = "ctr-4a-think-checkpoint-8d5302";
3
+ /** What the reply must be, as the prompt itself specifies it. */
4
+ export const CHECKPOINT_SCHEMA = {
5
+ type: "object",
6
+ properties: {
7
+ predicted: { type: "string" },
8
+ actual: { type: "string" },
9
+ divergence: { type: "string", enum: ["none", "minor", "beyond_tolerance"] },
10
+ contradicted_assumption: { type: ["string", "null"] },
11
+ next_action: { type: "string", enum: ["continue", "replan", "escalate"] },
12
+ replan_from_step: { type: ["number", "null"] },
13
+ confidence_now: { type: "number", minimum: 0, maximum: 1 },
14
+ surprises: { type: "array", items: { type: "string" } },
15
+ why: { type: "string" },
16
+ },
17
+ required: [
18
+ "predicted",
19
+ "actual",
20
+ "divergence",
21
+ "contradicted_assumption",
22
+ "next_action",
23
+ "replan_from_step",
24
+ "confidence_now",
25
+ "surprises",
26
+ "why",
27
+ ],
28
+ };
@@ -0,0 +1,21 @@
1
+ import type { Asked } from "../../context.js";
2
+ import type { StageOptions, StageOutcome } from "../../stage.js";
3
+ export type Divergence = "none" | "minor" | "beyond_tolerance";
4
+ export type NextAction = "continue" | "replan" | "escalate";
5
+ export interface ThinkCheckpoint {
6
+ predicted: string;
7
+ actual: string;
8
+ divergence: Divergence;
9
+ /** The assumption the result contradicted, or null. */
10
+ contradicted_assumption: string | null;
11
+ next_action: NextAction;
12
+ /** Where re-planning starts, or null when it is not replanning. */
13
+ replan_from_step: number | null;
14
+ /** Calibrated, two decimals. */
15
+ confidence_now: number;
16
+ surprises: string[];
17
+ why: string;
18
+ }
19
+ export type ThinkCheckpointInput = Asked;
20
+ export type ThinkCheckpointOptions = StageOptions;
21
+ export type ThinkCheckpointResult = StageOutcome<ThinkCheckpoint>;
@@ -0,0 +1 @@
1
+ export {};