@plune-ai/cairn 0.2.1 → 0.3.2

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 (143) hide show
  1. package/LICENSE +201 -674
  2. package/README.md +275 -181
  3. package/dist/agent/finalize.d.ts +20 -0
  4. package/dist/agent/finalize.d.ts.map +1 -0
  5. package/dist/agent/finalize.js +42 -0
  6. package/dist/agent/finalize.js.map +1 -0
  7. package/dist/agent/graph.d.ts +40 -0
  8. package/dist/agent/graph.d.ts.map +1 -1
  9. package/dist/agent/graph.js +0 -0
  10. package/dist/agent/graph.js.map +1 -1
  11. package/dist/agent/index.d.ts +18 -0
  12. package/dist/agent/index.d.ts.map +1 -1
  13. package/dist/agent/index.js +166 -64
  14. package/dist/agent/index.js.map +1 -1
  15. package/dist/agent/observe-guard.d.ts +14 -0
  16. package/dist/agent/observe-guard.d.ts.map +1 -0
  17. package/dist/agent/observe-guard.js +46 -0
  18. package/dist/agent/observe-guard.js.map +1 -0
  19. package/dist/agent/progress.d.ts +22 -0
  20. package/dist/agent/progress.d.ts.map +1 -0
  21. package/dist/agent/progress.js +25 -0
  22. package/dist/agent/progress.js.map +1 -0
  23. package/dist/agent/repair-loop.d.ts +26 -0
  24. package/dist/agent/repair-loop.d.ts.map +1 -0
  25. package/dist/agent/repair-loop.js +42 -0
  26. package/dist/agent/repair-loop.js.map +1 -0
  27. package/dist/agent/summary.d.ts +53 -0
  28. package/dist/agent/summary.d.ts.map +1 -0
  29. package/dist/agent/summary.js +103 -0
  30. package/dist/agent/summary.js.map +1 -0
  31. package/dist/agent/testcase-docs.d.ts +20 -0
  32. package/dist/agent/testcase-docs.d.ts.map +1 -0
  33. package/dist/agent/testcase-docs.js +30 -0
  34. package/dist/agent/testcase-docs.js.map +1 -0
  35. package/dist/artifacts/report.d.ts +10 -0
  36. package/dist/artifacts/report.d.ts.map +1 -1
  37. package/dist/artifacts/report.js +16 -0
  38. package/dist/artifacts/report.js.map +1 -1
  39. package/dist/browser/backends/playwright-lib.d.ts.map +1 -1
  40. package/dist/browser/backends/playwright-lib.js +17 -6
  41. package/dist/browser/backends/playwright-lib.js.map +1 -1
  42. package/dist/browser/preflight.d.ts +46 -0
  43. package/dist/browser/preflight.d.ts.map +1 -0
  44. package/dist/browser/preflight.js +73 -0
  45. package/dist/browser/preflight.js.map +1 -0
  46. package/dist/cli/index.d.ts +10 -1
  47. package/dist/cli/index.d.ts.map +1 -1
  48. package/dist/cli/index.js +327 -266
  49. package/dist/cli/index.js.map +1 -1
  50. package/dist/cli/is-main.d.ts +10 -0
  51. package/dist/cli/is-main.d.ts.map +1 -0
  52. package/dist/cli/is-main.js +21 -0
  53. package/dist/cli/is-main.js.map +1 -0
  54. package/dist/codegen/index.d.ts +3 -1
  55. package/dist/codegen/index.d.ts.map +1 -1
  56. package/dist/codegen/index.js +7 -2
  57. package/dist/codegen/index.js.map +1 -1
  58. package/dist/config/index.d.ts +1 -1
  59. package/dist/config/index.d.ts.map +1 -1
  60. package/dist/config/index.js +80 -2
  61. package/dist/config/index.js.map +1 -1
  62. package/dist/config/profiles.d.ts +14 -1
  63. package/dist/config/profiles.d.ts.map +1 -1
  64. package/dist/config/profiles.js +30 -0
  65. package/dist/config/profiles.js.map +1 -1
  66. package/dist/config/schema.d.ts +23 -1
  67. package/dist/config/schema.d.ts.map +1 -1
  68. package/dist/config/schema.js +7 -2
  69. package/dist/config/schema.js.map +1 -1
  70. package/dist/core/config.d.ts +18 -0
  71. package/dist/core/config.d.ts.map +1 -0
  72. package/dist/core/config.js +23 -0
  73. package/dist/core/config.js.map +1 -0
  74. package/dist/core/index.d.ts +15 -0
  75. package/dist/core/index.d.ts.map +1 -0
  76. package/dist/core/index.js +13 -0
  77. package/dist/core/index.js.map +1 -0
  78. package/dist/core/modalities/explore.d.ts +3 -0
  79. package/dist/core/modalities/explore.d.ts.map +1 -0
  80. package/dist/core/modalities/explore.js +82 -0
  81. package/dist/core/modalities/explore.js.map +1 -0
  82. package/dist/core/modality.d.ts +49 -0
  83. package/dist/core/modality.d.ts.map +1 -0
  84. package/dist/core/modality.js +24 -0
  85. package/dist/core/modality.js.map +1 -0
  86. package/dist/core/registry.d.ts +11 -0
  87. package/dist/core/registry.d.ts.map +1 -0
  88. package/dist/core/registry.js +43 -0
  89. package/dist/core/registry.js.map +1 -0
  90. package/dist/core/reporting.d.ts +11 -0
  91. package/dist/core/reporting.d.ts.map +1 -0
  92. package/dist/core/reporting.js +13 -0
  93. package/dist/core/reporting.js.map +1 -0
  94. package/dist/index.d.ts +6 -8
  95. package/dist/index.d.ts.map +1 -1
  96. package/dist/index.js +6 -1
  97. package/dist/index.js.map +1 -1
  98. package/dist/llm/cost.d.ts +53 -0
  99. package/dist/llm/cost.d.ts.map +1 -0
  100. package/dist/llm/cost.js +99 -0
  101. package/dist/llm/cost.js.map +1 -0
  102. package/dist/llm/factory.d.ts +18 -0
  103. package/dist/llm/factory.d.ts.map +1 -1
  104. package/dist/llm/factory.js +24 -0
  105. package/dist/llm/factory.js.map +1 -1
  106. package/dist/llm/index.d.ts +6 -1
  107. package/dist/llm/index.d.ts.map +1 -1
  108. package/dist/llm/index.js +5 -1
  109. package/dist/llm/index.js.map +1 -1
  110. package/dist/llm/routing.d.ts +40 -0
  111. package/dist/llm/routing.d.ts.map +1 -0
  112. package/dist/llm/routing.js +52 -0
  113. package/dist/llm/routing.js.map +1 -0
  114. package/dist/llm/structured.d.ts +28 -5
  115. package/dist/llm/structured.d.ts.map +1 -1
  116. package/dist/llm/structured.js +42 -9
  117. package/dist/llm/structured.js.map +1 -1
  118. package/dist/prompts/local/identify-elements.js +15 -15
  119. package/dist/prompts/local/judge-checklist-coverage.js +8 -8
  120. package/dist/prompts/local/judge-test-cases.js +8 -8
  121. package/dist/prompts/local/pilot-review.js +10 -10
  122. package/dist/prompts/local/qa-manual-test-designer.d.ts +1 -1
  123. package/dist/prompts/local/qa-manual-test-designer.js +7 -7
  124. package/dist/prompts/local/qa-playwright-ts-writer.d.ts +1 -1
  125. package/dist/prompts/local/qa-playwright-ts-writer.js +35 -35
  126. package/dist/prompts/local/qa-testcase-from-ui.d.ts +1 -1
  127. package/dist/prompts/local/qa-testcase-from-ui.js +47 -47
  128. package/dist/session/capture.d.ts +31 -0
  129. package/dist/session/capture.d.ts.map +1 -0
  130. package/dist/session/capture.js +84 -0
  131. package/dist/session/capture.js.map +1 -0
  132. package/dist/session/index.d.ts +16 -0
  133. package/dist/session/index.d.ts.map +1 -1
  134. package/dist/session/index.js +52 -2
  135. package/dist/session/index.js.map +1 -1
  136. package/dist/tui/screens/summary-screen.d.ts.map +1 -1
  137. package/dist/tui/screens/summary-screen.js +13 -1
  138. package/dist/tui/screens/summary-screen.js.map +1 -1
  139. package/dist/validate/runner.d.ts +6 -0
  140. package/dist/validate/runner.d.ts.map +1 -1
  141. package/dist/validate/runner.js +28 -9
  142. package/dist/validate/runner.js.map +1 -1
  143. package/package.json +98 -97
@@ -0,0 +1,3 @@
1
+ import type { Modality } from "../modality.js";
2
+ export declare const exploreModality: Modality;
3
+ //# sourceMappingURL=explore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"explore.d.ts","sourceRoot":"","sources":["../../../src/core/modalities/explore.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,QAAQ,EAAmB,MAAM,gBAAgB,CAAC;AAchE,eAAO,MAAM,eAAe,EAAE,QA0E7B,CAAC"}
@@ -0,0 +1,82 @@
1
+ /**
2
+ * C1-01 — the `explore` modality: the first REAL modality consuming the shared core.
3
+ *
4
+ * It wraps {@link runExploration} plus the shared render/cost/summary helpers (resolveConfig +
5
+ * printCost + renderRunSummary). The CLI `explore` command is now a thin delegate to this `run`,
6
+ * so its output is identical to the pre-extraction inline action (locked by the C1-02 parity test).
7
+ */
8
+ import { readFile } from "node:fs/promises";
9
+ import { runExploration } from "../../agent/index.js";
10
+ import { renderRunSummary } from "../../agent/summary.js";
11
+ import { resolveConfig } from "../config.js";
12
+ import { printCost } from "../reporting.js";
13
+ export const exploreModality = {
14
+ name: "explore",
15
+ gated: false,
16
+ summary: "Explore a page and generate methodology-based UI test cases (validate ⇄ repair)",
17
+ async run(ctx) {
18
+ // commander hands the action untyped options; the command's option defs guarantee this shape.
19
+ const opts = ctx.flags;
20
+ const config = resolveConfig({ backend: opts.backend, routing: opts.routing });
21
+ const checklistText = opts.checklist ? await readFile(opts.checklist, "utf8") : undefined;
22
+ ctx.err(`▸ Exploring ${opts.url}${opts.session ? ` (session: ${opts.session})` : ""}${opts.checklist ? ` (checklist: ${opts.checklist})` : ""}…\n`);
23
+ const result = await runExploration({
24
+ url: opts.url,
25
+ config,
26
+ sessionName: opts.session,
27
+ sessionFile: opts.sessionFile,
28
+ headed: opts.headed,
29
+ checklistText,
30
+ style: opts.style,
31
+ onProgress: (e) => ctx.err(` ▸ ${e}\n`),
32
+ });
33
+ ctx.out(`\n=== Exploration of ${result.study.url} (run ${result.runId}) ===\n`);
34
+ ctx.out(`Purpose: ${result.analysis.pageSemantics}\n`);
35
+ ctx.out(`LLM profile: ${config.llmProfile} · test cases: ${result.testCases.length}\n\n`);
36
+ for (const tc of result.testCases) {
37
+ ctx.out(`[${tc.id}] (${tc.priority} · ${tc.technique}) ${tc.title}\n`);
38
+ for (const step of tc.steps)
39
+ ctx.out(` - ${step}\n`);
40
+ ctx.out(` ⇒ ${tc.expected}\n`);
41
+ if (tc.elementRefs.length)
42
+ ctx.out(` refs: ${tc.elementRefs.join(", ")}\n`);
43
+ ctx.out("\n");
44
+ }
45
+ if (result.validation) {
46
+ const v = result.validation;
47
+ ctx.out(`=== Validation: ${Math.round(v.greenRatio * 100)}% green (flaky: ${v.flakyCount}) ===\n`);
48
+ for (const r of v.results) {
49
+ const mark = r.status === "passed" ? "✓" : r.status === "flaky" ? "~" : "✗";
50
+ ctx.out(` ${mark} ${r.test}\n`);
51
+ }
52
+ }
53
+ if (result.scores.length > 0) {
54
+ ctx.out("\n=== Metrics ===\n");
55
+ for (const s of result.scores) {
56
+ ctx.out(` ${s.name}: ${s.value.toFixed(2)}${s.comment ? ` — ${s.comment}` : ""}\n`);
57
+ }
58
+ }
59
+ if (result.pilot) {
60
+ ctx.out(`\n=== Pilot: ${result.pilot.verdict.toUpperCase()} ===\n ${result.pilot.reason}\n → ${result.pilot.guidance}\n`);
61
+ }
62
+ printCost(result.cost, ctx.out);
63
+ // L1-04 (Box 4): one unambiguous footer — pass/fail · cost+tokens · budget used · artifact path.
64
+ ctx.out("\n");
65
+ for (const line of renderRunSummary({
66
+ runDir: result.runDir,
67
+ validation: result.validation,
68
+ cost: result.cost,
69
+ budget: result.budget,
70
+ testCaseCount: result.testCases.length,
71
+ stoppedEarly: result.stoppedEarly,
72
+ })) {
73
+ ctx.out(`${line}\n`);
74
+ }
75
+ // #39: explore now also writes ATC/MTC cases, and points at the review-first flow for next time.
76
+ if (result.testCaseFiles.length > 0) {
77
+ ctx.out(` Cases (ATC/MTC .md): ${result.runDir}\\testcases\\\n`);
78
+ }
79
+ ctx.out("\nTip: to review cases BEFORE generating code, run `cairn design` then `cairn automate`.\n");
80
+ },
81
+ };
82
+ //# sourceMappingURL=explore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"explore.js","sourceRoot":"","sources":["../../../src/core/modalities/explore.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAe5C,MAAM,CAAC,MAAM,eAAe,GAAa;IACvC,IAAI,EAAE,SAAS;IACf,KAAK,EAAE,KAAK;IACZ,OAAO,EAAE,iFAAiF;IAC1F,KAAK,CAAC,GAAG,CAAC,GAAoB;QAC5B,8F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,CAAC,GAAG,CAAC,0BAA0B,MAAM,CAAC,MAAM,iBAAiB,CAAC,CAAC;QACpE,CAAC;QACD,GAAG,CAAC,GAAG,CACL,4FAA4F,CAC7F,CAAC;IACJ,CAAC;CACF,CAAC"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * C1-01 — shared core: the `Modality` type + its supporting IO and the gated-stub notice.
3
+ *
4
+ * A "modality" is one kind of test artifact Cairn can generate (UI/API/unit/docs…). Today only
5
+ * `explore` (UI) is REAL; the rest are GATED stubs (L-G2 / #25): discoverable placeholders with
6
+ * ZERO generation logic. A future modality is a thin add — register an entry and give it a `run`
7
+ * that consumes the shared core — not a fork of the whole CLI.
8
+ */
9
+ /** Sink for one chunk of CLI output (stdout or stderr). */
10
+ export type Sink = (s: string) => void;
11
+ /** The stdout/stderr sinks a modality writes through — injected in tests, real streams in the CLI. */
12
+ export interface IO {
13
+ out: Sink;
14
+ err: Sink;
15
+ }
16
+ /** Default IO → the process streams (the production CLI path). */
17
+ export declare const defaultIO: IO;
18
+ /** Everything a modality's `run` needs: the parsed CLI flags + output sinks. */
19
+ export interface ModalityContext {
20
+ /** Parsed commander options for this modality's command. */
21
+ flags: Record<string, unknown>;
22
+ out: Sink;
23
+ err: Sink;
24
+ }
25
+ /**
26
+ * One generation modality. `run` is ABSENT for gated stubs — that absence IS the gate: a stub
27
+ * carries no runner, so it can never trigger generation. The real `explore` modality supplies a
28
+ * `run` that wraps {@link runExploration} + the shared render/cost/summary helpers.
29
+ */
30
+ export interface Modality {
31
+ /** Command name as typed: `cairn <name>`. */
32
+ name: string;
33
+ /** Extra command aliases (e.g. ui ⇄ e2e). */
34
+ aliases?: string[];
35
+ /** Gated = coming-soon placeholder; built one at a time, by named demand (L-G2). */
36
+ gated: boolean;
37
+ /** One-line description shown in `cairn --help`. */
38
+ summary: string;
39
+ /** Optional extra line appended to the gated notice (e.g. ui → points at `cairn explore`). */
40
+ hint?: string;
41
+ /** Run the modality. Absent for gated stubs. */
42
+ run?(ctx: ModalityContext): Promise<void>;
43
+ }
44
+ /**
45
+ * The notice printed when a user runs a gated modality. Pure (returns lines, like
46
+ * {@link renderRunSummary}) so it is trivially testable: the canonical one-liner + the optional hint.
47
+ */
48
+ export declare function gatedNotice(m: Modality): string[];
49
+ //# sourceMappingURL=modality.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modality.d.ts","sourceRoot":"","sources":["../../src/core/modality.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,2DAA2D;AAC3D,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;AAEvC,sGAAsG;AACtG,MAAM,WAAW,EAAE;IACjB,GAAG,EAAE,IAAI,CAAC;IACV,GAAG,EAAE,IAAI,CAAC;CACX;AAED,kEAAkE;AAClE,eAAO,MAAM,SAAS,EAAE,EAGvB,CAAC;AAEF,gFAAgF;AAChF,MAAM,WAAW,eAAe;IAC9B,4DAA4D;IAC5D,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,GAAG,EAAE,IAAI,CAAC;IACV,GAAG,EAAE,IAAI,CAAC;CACX;AAED;;;;GAIG;AACH,MAAM,WAAW,QAAQ;IACvB,6CAA6C;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,6CAA6C;IAC7C,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,oFAAoF;IACpF,KAAK,EAAE,OAAO,CAAC;IACf,oDAAoD;IACpD,OAAO,EAAE,MAAM,CAAC;IAChB,8FAA8F;IAC9F,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gDAAgD;IAChD,GAAG,CAAC,CAAC,GAAG,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3C;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,QAAQ,GAAG,MAAM,EAAE,CAIjD"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * C1-01 — shared core: the `Modality` type + its supporting IO and the gated-stub notice.
3
+ *
4
+ * A "modality" is one kind of test artifact Cairn can generate (UI/API/unit/docs…). Today only
5
+ * `explore` (UI) is REAL; the rest are GATED stubs (L-G2 / #25): discoverable placeholders with
6
+ * ZERO generation logic. A future modality is a thin add — register an entry and give it a `run`
7
+ * that consumes the shared core — not a fork of the whole CLI.
8
+ */
9
+ /** Default IO → the process streams (the production CLI path). */
10
+ export const defaultIO = {
11
+ out: (s) => void process.stdout.write(s),
12
+ err: (s) => void process.stderr.write(s),
13
+ };
14
+ /**
15
+ * The notice printed when a user runs a gated modality. Pure (returns lines, like
16
+ * {@link renderRunSummary}) so it is trivially testable: the canonical one-liner + the optional hint.
17
+ */
18
+ export function gatedNotice(m) {
19
+ const lines = [`${m.name}: coming soon — gated (see L-G2). Build by demand, one at a time.`];
20
+ if (m.hint)
21
+ lines.push(m.hint);
22
+ return lines;
23
+ }
24
+ //# sourceMappingURL=modality.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modality.js","sourceRoot":"","sources":["../../src/core/modality.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAWH,kEAAkE;AAClE,MAAM,CAAC,MAAM,SAAS,GAAO;IAC3B,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACxC,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;CACzC,CAAC;AA8BF;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,CAAW;IACrC,MAAM,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,mEAAmE,CAAC,CAAC;IAC7F,IAAI,CAAC,CAAC,IAAI;QAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAC/B,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { IO, Modality } from "./modality.js";
2
+ export declare const MODALITIES: Modality[];
3
+ /** Look up a modality by its name or one of its aliases (e.g. `e2e` → the `ui` modality). */
4
+ export declare function getModality(nameOrAlias: string): Modality | undefined;
5
+ /**
6
+ * Dispatch a modality command — the single entry point the CLI actions and tests both drive.
7
+ * Gated stubs print the coming-soon notice (no generation logic ever runs); a real modality runs
8
+ * through its `run`. An unknown name throws.
9
+ */
10
+ export declare function runModality(name: string, flags: Record<string, unknown>, io?: IO): Promise<void>;
11
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/core/registry.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGlD,eAAO,MAAM,UAAU,EAAE,QAAQ,EAYhC,CAAC;AAEF,6FAA6F;AAC7F,wBAAgB,WAAW,CAAC,WAAW,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAErE;AAED;;;;GAIG;AACH,wBAAsB,WAAW,CAC/B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,EAAE,GAAE,EAAc,GACjB,OAAO,CAAC,IAAI,CAAC,CAQf"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * C1-01 — the modality registry: the single list every surface (CLI, tests) reads.
3
+ *
4
+ * `explore` (UI) is the only REAL modality today. ui/api/unit/docs are GATED stubs (L-G2 / #25):
5
+ * placeholders with no `run`, pulled one at a time by named demand. Adding a modality = append one
6
+ * entry (+ a `run` that consumes the shared core). #21–24 stay gated until a named user pulls.
7
+ */
8
+ import { defaultIO, gatedNotice } from "./modality.js";
9
+ import { exploreModality } from "./modalities/explore.js";
10
+ export const MODALITIES = [
11
+ exploreModality,
12
+ {
13
+ name: "ui",
14
+ aliases: ["e2e"],
15
+ gated: true,
16
+ summary: "Generate UI / end-to-end tests",
17
+ hint: "For UI test generation today, use: cairn explore --url <url>",
18
+ },
19
+ { name: "api", gated: true, summary: "Generate API / contract tests" },
20
+ { name: "unit", gated: true, summary: "Generate unit tests" },
21
+ { name: "docs", gated: true, summary: "Generate docs / doctest examples" },
22
+ ];
23
+ /** Look up a modality by its name or one of its aliases (e.g. `e2e` → the `ui` modality). */
24
+ export function getModality(nameOrAlias) {
25
+ return MODALITIES.find((m) => m.name === nameOrAlias || (m.aliases?.includes(nameOrAlias) ?? false));
26
+ }
27
+ /**
28
+ * Dispatch a modality command — the single entry point the CLI actions and tests both drive.
29
+ * Gated stubs print the coming-soon notice (no generation logic ever runs); a real modality runs
30
+ * through its `run`. An unknown name throws.
31
+ */
32
+ export async function runModality(name, flags, io = defaultIO) {
33
+ const m = getModality(name);
34
+ if (!m)
35
+ throw new Error(`Unknown modality "${name}".`);
36
+ if (!m.run) {
37
+ for (const line of gatedNotice(m))
38
+ io.out(`${line}\n`);
39
+ return;
40
+ }
41
+ await m.run({ flags, out: io.out, err: io.err });
42
+ }
43
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/core/registry.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEvD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE1D,MAAM,CAAC,MAAM,UAAU,GAAe;IACpC,eAAe;IACf;QACE,IAAI,EAAE,IAAI;QACV,OAAO,EAAE,CAAC,KAAK,CAAC;QAChB,KAAK,EAAE,IAAI;QACX,OAAO,EAAE,gCAAgC;QACzC,IAAI,EAAE,8DAA8D;KACrE;IACD,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,+BAA+B,EAAE;IACtE,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,qBAAqB,EAAE;IAC7D,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,kCAAkC,EAAE;CAC3E,CAAC;AAEF,6FAA6F;AAC7F,MAAM,UAAU,WAAW,CAAC,WAAmB;IAC7C,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,WAAW,IAAI,CAAC,CAAC,CAAC,OAAO,EAAE,QAAQ,CAAC,WAAW,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC;AACvG,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,IAAY,EACZ,KAA8B,EAC9B,KAAS,SAAS;IAElB,MAAM,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;IAC5B,IAAI,CAAC,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,qBAAqB,IAAI,IAAI,CAAC,CAAC;IACvD,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;QACX,KAAK,MAAM,IAAI,IAAI,WAAW,CAAC,CAAC,CAAC;YAAE,EAAE,CAAC,GAAG,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC;QACvD,OAAO;IACT,CAAC;IACD,MAAM,CAAC,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;AACnD,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * C1-01 — shared core: the cost/summary footer every modality prints.
3
+ *
4
+ * `printCost` moved here verbatim out of cli/index.ts so all modalities print the SAME footer.
5
+ * The default `write` is stdout, so output is byte-identical to the pre-extraction helper.
6
+ */
7
+ import type { CostReport } from "../llm/cost.js";
8
+ import type { Sink } from "./modality.js";
9
+ /** Print the per-role cost + token summary (L1-01). `write` is injectable for tests. */
10
+ export declare function printCost(cost: CostReport, write?: Sink): void;
11
+ //# sourceMappingURL=reporting.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reporting.d.ts","sourceRoot":"","sources":["../../src/core/reporting.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1C,wFAAwF;AACxF,wBAAgB,SAAS,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,GAAE,IAA0C,GAAG,IAAI,CASnG"}
@@ -0,0 +1,13 @@
1
+ /** Print the per-role cost + token summary (L1-01). `write` is injectable for tests. */
2
+ export function printCost(cost, write = (s) => void process.stdout.write(s)) {
3
+ if (cost.perRole.length === 0)
4
+ return;
5
+ write("\n=== Cost (per role) ===\n");
6
+ for (const c of cost.perRole) {
7
+ const usd = c.costUsd === null ? "n/a" : `$${c.costUsd.toFixed(4)}`;
8
+ write(` ${c.role.padEnd(9)} ${c.calls} call(s) ${c.inputTokens}→${c.outputTokens} tok ${usd}\n`);
9
+ }
10
+ const total = cost.totalCostUsd === null ? "n/a (some prices unknown)" : `$${cost.totalCostUsd.toFixed(4)}`;
11
+ write(` ${"total".padEnd(9)} ${cost.totalTokens} tok ${total}\n`);
12
+ }
13
+ //# sourceMappingURL=reporting.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reporting.js","sourceRoot":"","sources":["../../src/core/reporting.ts"],"names":[],"mappings":"AASA,wFAAwF;AACxF,MAAM,UAAU,SAAS,CAAC,IAAgB,EAAE,QAAc,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAC3F,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO;IACtC,KAAK,CAAC,6BAA6B,CAAC,CAAC;IACrC,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;QAC7B,MAAM,GAAG,GAAG,CAAC,CAAC,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;QACpE,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,aAAa,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,YAAY,SAAS,GAAG,IAAI,CAAC,CAAC;IACtG,CAAC;IACD,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,KAAK,IAAI,CAAC,CAAC,CAAC,2BAA2B,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5G,KAAK,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,WAAW,SAAS,KAAK,IAAI,CAAC,CAAC;AACtE,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,15 +1,13 @@
1
- /**
2
- * QA Explorer Bot — public library API (Sprint 6: frozen for embedding).
3
- *
4
- * Example: import { runDesign, runAutomate, runExploration } from "@plune-ai/cairn";
5
- * Three entry points: explore (everything), design (cases only), automate (code from cases).
6
- */
7
1
  export declare const BOT_NAME: "@plune-ai/cairn";
8
- export declare const BOT_VERSION: "0.1.0";
2
+ /** Read from package.json at load time — single source of truth, no manual drift. */
3
+ export declare const BOT_VERSION: string;
9
4
  export { runExploration, runDesign, runAutomate, buildExploreGraph, ExploreState } from "./agent/index.js";
10
5
  export type { ExploreInput, ExploreResult, DesignResult, AutomateResult, ExploreDeps, } from "./agent/index.js";
11
6
  export { loadConfig } from "./config/index.js";
12
- export type { AppConfig } from "./config/index.js";
7
+ export type { AppConfig, Role, RolesConfig } from "./config/index.js";
8
+ export type { CostReport, RoleCost } from "./llm/cost.js";
9
+ export { renderRunSummary } from "./agent/summary.js";
10
+ export type { BudgetReport, RunSummaryInput } from "./agent/summary.js";
13
11
  export type { TestCase, DesignedCase } from "./design/index.js";
14
12
  export type { PageStudy } from "./observe/index.js";
15
13
  export type { GeneratedSuite } from "./codegen/index.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,QAAQ,EAAG,iBAA0B,CAAC;AACnD,eAAO,MAAM,WAAW,EAAG,OAAgB,CAAC;AAG5C,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,WAAW,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC3G,YAAY,EACV,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,cAAc,EACd,WAAW,GACZ,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,YAAY,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAGnD,YAAY,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAChE,YAAY,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,YAAY,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC/C,YAAY,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,YAAY,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,YAAY,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,YAAY,EAAE,UAAU,EAAE,eAAe,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,QAAQ,EAAG,iBAA0B,CAAC;AACnD,qFAAqF;AACrF,eAAO,MAAM,WAAW,EAAE,MAAoB,CAAC;AAG/C,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,WAAW,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC3G,YAAY,EACV,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,cAAc,EACd,WAAW,GACZ,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,YAAY,EAAE,SAAS,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGtE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAG1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAGxE,YAAY,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAChE,YAAY,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,YAAY,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC/C,YAAY,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,YAAY,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,YAAY,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,YAAY,EAAE,UAAU,EAAE,eAAe,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC"}
package/dist/index.js CHANGED
@@ -4,10 +4,15 @@
4
4
  * Example: import { runDesign, runAutomate, runExploration } from "@plune-ai/cairn";
5
5
  * Three entry points: explore (everything), design (cases only), automate (code from cases).
6
6
  */
7
+ import { readFileSync } from "node:fs";
8
+ const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
7
9
  export const BOT_NAME = "@plune-ai/cairn";
8
- export const BOT_VERSION = "0.1.0";
10
+ /** Read from package.json at load time — single source of truth, no manual drift. */
11
+ export const BOT_VERSION = pkg.version;
9
12
  // Entry points.
10
13
  export { runExploration, runDesign, runAutomate, buildExploreGraph, ExploreState } from "./agent/index.js";
11
14
  // Config.
12
15
  export { loadConfig } from "./config/index.js";
16
+ // Run summary + LLM-call budget surfacing (L1-04, Box 3/4).
17
+ export { renderRunSummary } from "./agent/summary.js";
13
18
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,QAAQ,GAAG,iBAA0B,CAAC;AACnD,MAAM,CAAC,MAAM,WAAW,GAAG,OAAgB,CAAC;AAE5C,gBAAgB;AAChB,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,WAAW,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAS3G,UAAU;AACV,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CACpB,YAAY,CAAC,IAAI,GAAG,CAAC,iBAAiB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAC3C,CAAC;AAEzB,MAAM,CAAC,MAAM,QAAQ,GAAG,iBAA0B,CAAC;AACnD,qFAAqF;AACrF,MAAM,CAAC,MAAM,WAAW,GAAW,GAAG,CAAC,OAAO,CAAC;AAE/C,gBAAgB;AAChB,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,WAAW,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAS3G,UAAU;AACV,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAM/C,4DAA4D;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Per-role cost + token accounting (L1-01, ADR-0011). Pure — no SDK, no network.
3
+ *
4
+ * `CallBudget` (structured.ts) counts CALLS as a guardrail; this is its sibling that
5
+ * counts tokens and prices them per role. Capture happens in `meteredInvoker`.
6
+ */
7
+ export interface TokenUsage {
8
+ inputTokens: number;
9
+ outputTokens: number;
10
+ }
11
+ export interface ModelPrice {
12
+ inputPer1M: number;
13
+ outputPer1M: number;
14
+ }
15
+ /**
16
+ * Default price table (USD per 1M tokens). Anthropic prices are authoritative
17
+ * (claude-api skill, 2026-06). OpenRouter prices are APPROXIMATE and move
18
+ * (ADR-0002) — any model absent here yields a null (unknown) cost; tokens are
19
+ * still counted. Override by passing a table to `CostLedger`.
20
+ */
21
+ export declare const DEFAULT_PRICING: Record<string, ModelPrice>;
22
+ export declare function priceFor(model: string, table?: Record<string, ModelPrice>): ModelPrice | undefined;
23
+ /**
24
+ * Read token usage off a LangChain message. Prefers `usage_metadata` (normalized by
25
+ * LangChain across providers), then `response_metadata.usage` (OpenAI/OpenRouter), then
26
+ * `tokenUsage`. Never throws — missing usage yields zeros (graceful per ADR-0002).
27
+ */
28
+ export declare function extractUsage(raw: unknown): TokenUsage;
29
+ export interface RoleCost {
30
+ role: string;
31
+ models: string[];
32
+ calls: number;
33
+ inputTokens: number;
34
+ outputTokens: number;
35
+ totalTokens: number;
36
+ /** null when any contributing model has no configured price (tokens still reported). */
37
+ costUsd: number | null;
38
+ }
39
+ export interface CostReport {
40
+ perRole: RoleCost[];
41
+ totalTokens: number;
42
+ /** null when any role's cost is unknown. */
43
+ totalCostUsd: number | null;
44
+ }
45
+ /** Accumulates usage per role and prices it. Sibling to CallBudget; one per run. */
46
+ export declare class CostLedger {
47
+ private readonly pricing;
48
+ private readonly rows;
49
+ constructor(pricing?: Record<string, ModelPrice>);
50
+ record(role: string, model: string, usage: TokenUsage): void;
51
+ report(): CostReport;
52
+ }
53
+ //# sourceMappingURL=cost.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cost.d.ts","sourceRoot":"","sources":["../../src/llm/cost.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,WAAW,UAAU;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,UAAU;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;;GAKG;AACH,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAYtD,CAAC;AAEF,wBAAgB,QAAQ,CACtB,KAAK,EAAE,MAAM,EACb,KAAK,GAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAmB,GAClD,UAAU,GAAG,SAAS,CAExB;AAWD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,GAAG,UAAU,CAgBrD;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,wFAAwF;IACxF,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,QAAQ,EAAE,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,4CAA4C;IAC5C,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAaD,oFAAoF;AACpF,qBAAa,UAAU;IAGT,OAAO,CAAC,QAAQ,CAAC,OAAO;IAFpC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA0B;gBAElB,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAmB;IAElF,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI;IAY5D,MAAM,IAAI,UAAU;CAyBrB"}
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Per-role cost + token accounting (L1-01, ADR-0011). Pure — no SDK, no network.
3
+ *
4
+ * `CallBudget` (structured.ts) counts CALLS as a guardrail; this is its sibling that
5
+ * counts tokens and prices them per role. Capture happens in `meteredInvoker`.
6
+ */
7
+ /**
8
+ * Default price table (USD per 1M tokens). Anthropic prices are authoritative
9
+ * (claude-api skill, 2026-06). OpenRouter prices are APPROXIMATE and move
10
+ * (ADR-0002) — any model absent here yields a null (unknown) cost; tokens are
11
+ * still counted. Override by passing a table to `CostLedger`.
12
+ */
13
+ export const DEFAULT_PRICING = {
14
+ "claude-opus-4-8": { inputPer1M: 5, outputPer1M: 25 },
15
+ "claude-sonnet-4-6": { inputPer1M: 3, outputPer1M: 15 },
16
+ "claude-haiku-4-5": { inputPer1M: 1, outputPer1M: 5 },
17
+ // OpenRouter — approximate, movable (ADR-0002, self-hosted Langfuse needs custom pricing).
18
+ "deepseek/deepseek-chat": { inputPer1M: 0.28, outputPer1M: 0.88 },
19
+ "deepseek/deepseek-r1": { inputPer1M: 0.55, outputPer1M: 2.19 },
20
+ "qwen/qwen-2.5-72b-instruct": { inputPer1M: 0.35, outputPer1M: 0.4 },
21
+ "qwen/qwen-2-vl-72b-instruct": { inputPer1M: 0.4, outputPer1M: 0.4 },
22
+ // Groq — approximate, movable (L1-02; the lowest-latency `fast`-preset worker).
23
+ // Any Groq model absent here still yields a null cost (graceful), tokens are still counted.
24
+ "llama-3.3-70b-versatile": { inputPer1M: 0.59, outputPer1M: 0.79 },
25
+ };
26
+ export function priceFor(model, table = DEFAULT_PRICING) {
27
+ return table[model];
28
+ }
29
+ /**
30
+ * Read token usage off a LangChain message. Prefers `usage_metadata` (normalized by
31
+ * LangChain across providers), then `response_metadata.usage` (OpenAI/OpenRouter), then
32
+ * `tokenUsage`. Never throws — missing usage yields zeros (graceful per ADR-0002).
33
+ */
34
+ export function extractUsage(raw) {
35
+ const m = (raw ?? {});
36
+ const um = m.usage_metadata;
37
+ if (um && (um.input_tokens !== undefined || um.output_tokens !== undefined)) {
38
+ return { inputTokens: um.input_tokens ?? 0, outputTokens: um.output_tokens ?? 0 };
39
+ }
40
+ const u = m.response_metadata?.usage;
41
+ if (u) {
42
+ return {
43
+ inputTokens: u.input_tokens ?? u.prompt_tokens ?? 0,
44
+ outputTokens: u.output_tokens ?? u.completion_tokens ?? 0,
45
+ };
46
+ }
47
+ const t = m.response_metadata?.tokenUsage;
48
+ if (t)
49
+ return { inputTokens: t.promptTokens ?? 0, outputTokens: t.completionTokens ?? 0 };
50
+ return { inputTokens: 0, outputTokens: 0 };
51
+ }
52
+ const ROLE_ORDER = ["worker", "reasoner", "judge"];
53
+ /** Accumulates usage per role and prices it. Sibling to CallBudget; one per run. */
54
+ export class CostLedger {
55
+ pricing;
56
+ rows = new Map();
57
+ constructor(pricing = DEFAULT_PRICING) {
58
+ this.pricing = pricing;
59
+ }
60
+ record(role, model, usage) {
61
+ const row = this.rows.get(role) ?? { models: new Set(), calls: 0, in: 0, out: 0, cost: 0, costKnown: true };
62
+ row.calls += 1;
63
+ row.in += usage.inputTokens;
64
+ row.out += usage.outputTokens;
65
+ row.models.add(model);
66
+ const p = this.pricing[model];
67
+ if (p)
68
+ row.cost += (usage.inputTokens / 1e6) * p.inputPer1M + (usage.outputTokens / 1e6) * p.outputPer1M;
69
+ else
70
+ row.costKnown = false;
71
+ this.rows.set(role, row);
72
+ }
73
+ report() {
74
+ const rank = (r) => {
75
+ const i = ROLE_ORDER.indexOf(r);
76
+ return i === -1 ? ROLE_ORDER.length : i;
77
+ };
78
+ const roles = [...this.rows.keys()].sort((a, b) => rank(a) - rank(b));
79
+ const perRole = roles.map((role) => {
80
+ const r = this.rows.get(role);
81
+ return {
82
+ role,
83
+ models: [...r.models],
84
+ calls: r.calls,
85
+ inputTokens: r.in,
86
+ outputTokens: r.out,
87
+ totalTokens: r.in + r.out,
88
+ costUsd: r.costKnown ? Number(r.cost.toFixed(6)) : null,
89
+ };
90
+ });
91
+ const totalTokens = perRole.reduce((s, r) => s + r.totalTokens, 0);
92
+ const anyUnknown = perRole.some((r) => r.costUsd === null);
93
+ const totalCostUsd = anyUnknown
94
+ ? null
95
+ : Number(perRole.reduce((s, r) => s + (r.costUsd ?? 0), 0).toFixed(6));
96
+ return { perRole, totalTokens, totalCostUsd };
97
+ }
98
+ }
99
+ //# sourceMappingURL=cost.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cost.js","sourceRoot":"","sources":["../../src/llm/cost.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAYH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAA+B;IACzD,iBAAiB,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE;IACrD,mBAAmB,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE;IACvD,kBAAkB,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE;IACrD,2FAA2F;IAC3F,wBAAwB,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE;IACjE,sBAAsB,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE;IAC/D,4BAA4B,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE;IACpE,6BAA6B,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE;IACpE,gFAAgF;IAChF,4FAA4F;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CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;QACzE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,CAAC;IAChD,CAAC;CACF"}
@@ -1,10 +1,21 @@
1
1
  import type { BaseChatModel } from "@langchain/core/language_models/chat_models";
2
2
  import type { ModelTier } from "../config/index.js";
3
+ import type { StructuredMethod } from "./structured.js";
4
+ /**
5
+ * Which `withStructuredOutput` method to use for a provider. Groq's OpenAI-compatible endpoint
6
+ * rejects `response_format: json_schema` for most models (e.g. llama-3.3-70b-versatile → HTTP 400),
7
+ * so force `functionCalling` (tool-calling), which those models support (L1-02 fix). Anthropic and
8
+ * OpenRouter keep the LangChain default (`undefined`).
9
+ */
10
+ export declare function structuredMethodFor(provider: ModelTier["provider"]): StructuredMethod | undefined;
3
11
  /** OpenRouter — OpenAI-compatible API; we connect via the ChatOpenAI baseURL (ADR-0002). */
4
12
  export declare const OPENROUTER_BASE_URL = "https://openrouter.ai/api/v1";
13
+ /** Groq — also OpenAI-compatible; same ChatOpenAI + baseURL path, no new dependency (L1-02). */
14
+ export declare const GROQ_BASE_URL = "https://api.groq.com/openai/v1";
5
15
  export interface ProviderKeys {
6
16
  anthropicApiKey?: string;
7
17
  openrouterApiKey?: string;
18
+ groqApiKey?: string;
8
19
  }
9
20
  /** Resolved model specification (pure result, no side effects). */
10
21
  export type ModelSpec = {
@@ -20,6 +31,13 @@ export type ModelSpec = {
20
31
  baseURL: string;
21
32
  temperature?: number;
22
33
  supportsVision: boolean;
34
+ } | {
35
+ provider: "groq";
36
+ model: string;
37
+ apiKey: string;
38
+ baseURL: string;
39
+ temperature?: number;
40
+ supportsVision: boolean;
23
41
  };
24
42
  /**
25
43
  * Pure function: tier + keys → ModelSpec. Throws if the required provider's key is missing.
@@ -1 +1 @@
1
- {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/llm/factory.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAC;AACjF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEpD,4FAA4F;AAC5F,eAAO,MAAM,mBAAmB,iCAAiC,CAAC;AAElE,MAAM,WAAW,YAAY;IAC3B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,mEAAmE;AACnE,MAAM,MAAM,SAAS,GACjB;IACE,QAAQ,EAAE,WAAW,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,OAAO,CAAC;CACzB,GACD;IACE,QAAQ,EAAE,YAAY,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,OAAO,CAAC;CACzB,CAAC;AAEN;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,YAAY,GAAG,SAAS,CAwB/E;AAED,mFAAmF;AACnF,wBAAgB,SAAS,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,YAAY,GAAG,aAAa,CAa5E"}
1
+ {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/llm/factory.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAC;AACjF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAExD;;;;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OpenAI } from "@langchain/openai";
3
+ /**
4
+ * Which `withStructuredOutput` method to use for a provider. Groq's OpenAI-compatible endpoint
5
+ * rejects `response_format: json_schema` for most models (e.g. llama-3.3-70b-versatile → HTTP 400),
6
+ * so force `functionCalling` (tool-calling), which those models support (L1-02 fix). Anthropic and
7
+ * OpenRouter keep the LangChain default (`undefined`).
8
+ */
9
+ export function structuredMethodFor(provider) {
10
+ return provider === "groq" ? "functionCalling" : undefined;
11
+ }
3
12
  /** OpenRouter — OpenAI-compatible API; we connect via the ChatOpenAI baseURL (ADR-0002). */
4
13
  export const OPENROUTER_BASE_URL = "https://openrouter.ai/api/v1";
14
+ /** Groq — also OpenAI-compatible; same ChatOpenAI + baseURL path, no new dependency (L1-02). */
15
+ export const GROQ_BASE_URL = "https://api.groq.com/openai/v1";
5
16
  /**
6
17
  * Pure function: tier + keys → ModelSpec. Throws if the required provider's key is missing.
7
18
  * Separated from instantiation so it is fully testable without the SDK.
@@ -19,6 +30,19 @@ export function resolveModelSpec(tier, keys) {
19
30
  supportsVision: tier.supportsVision,
20
31
  };
21
32
  }
33
+ if (tier.provider === "groq") {
34
+ if (!keys.groqApiKey) {
35
+ throw new Error(`Tier '${tier.model}' requires Groq, but GROQ_API_KEY is not set.`);
36
+ }
37
+ return {
38
+ provider: "groq",
39
+ model: tier.model,
40
+ apiKey: keys.groqApiKey,
41
+ baseURL: GROQ_BASE_URL,
42
+ temperature: tier.temperature,
43
+ supportsVision: tier.supportsVision,
44
+ };
45
+ }
22
46
  if (!keys.openrouterApiKey) {
23
47
  throw new Error(`Tier '${tier.model}' requires OpenRouter, but OPENROUTER_API_KEY is not set.`);
24
48
  }
@@ -1 +1 @@
1
- {"version":3,"file":"factory.js","sourceRoot":"","sources":["../../src/llm/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI/C,4FAA4F;AAC5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,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,GAAG,WAAW,EAAE,CAAC,CAAC;IACvF,CAAC;IACD,OAAO,IAAI,UAAU,CAAC;QACpB,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,aAAa,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE;QACxC,GAAG,WAAW;KACf,CAAC,CAAC;AACL,CAAC"}
@@ -1,5 +1,10 @@
1
- export { OPENROUTER_BASE_URL, resolveModelSpec, makeModel } from "./factory.js";
1
+ export { OPENROUTER_BASE_URL, GROQ_BASE_URL, resolveModelSpec, makeModel, structuredMethodFor } from "./factory.js";
2
2
  export type { ModelSpec, ProviderKeys } from "./factory.js";
3
3
  export { imageBlock } from "./vision.js";
4
4
  export type { ImageBlock } from "./vision.js";
5
+ export { structuredInvoker, meteredInvoker, retryInvoke, CallBudget, cappedInvoke } from "./structured.js";
6
+ export type { StructuredInvoke, StructuredMethod } from "./structured.js";
7
+ export { RoleRouter, resolveRoleTier, KNOWN_ROLES } from "./routing.js";
8
+ export { CostLedger, DEFAULT_PRICING, priceFor, extractUsage } from "./cost.js";
9
+ export type { CostReport, RoleCost, TokenUsage, ModelPrice } from "./cost.js";
5
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/llm/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAChF,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/llm/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,gBAAgB,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACpH,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,WAAW,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC3G,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAChF,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC"}