@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.
- package/LICENSE +201 -674
- package/README.md +275 -181
- package/dist/agent/finalize.d.ts +20 -0
- package/dist/agent/finalize.d.ts.map +1 -0
- package/dist/agent/finalize.js +42 -0
- package/dist/agent/finalize.js.map +1 -0
- package/dist/agent/graph.d.ts +40 -0
- package/dist/agent/graph.d.ts.map +1 -1
- package/dist/agent/graph.js +0 -0
- package/dist/agent/graph.js.map +1 -1
- package/dist/agent/index.d.ts +18 -0
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +166 -64
- package/dist/agent/index.js.map +1 -1
- package/dist/agent/observe-guard.d.ts +14 -0
- package/dist/agent/observe-guard.d.ts.map +1 -0
- package/dist/agent/observe-guard.js +46 -0
- package/dist/agent/observe-guard.js.map +1 -0
- package/dist/agent/progress.d.ts +22 -0
- package/dist/agent/progress.d.ts.map +1 -0
- package/dist/agent/progress.js +25 -0
- package/dist/agent/progress.js.map +1 -0
- package/dist/agent/repair-loop.d.ts +26 -0
- package/dist/agent/repair-loop.d.ts.map +1 -0
- package/dist/agent/repair-loop.js +42 -0
- package/dist/agent/repair-loop.js.map +1 -0
- package/dist/agent/summary.d.ts +53 -0
- package/dist/agent/summary.d.ts.map +1 -0
- package/dist/agent/summary.js +103 -0
- package/dist/agent/summary.js.map +1 -0
- package/dist/agent/testcase-docs.d.ts +20 -0
- package/dist/agent/testcase-docs.d.ts.map +1 -0
- package/dist/agent/testcase-docs.js +30 -0
- package/dist/agent/testcase-docs.js.map +1 -0
- package/dist/artifacts/report.d.ts +10 -0
- package/dist/artifacts/report.d.ts.map +1 -1
- package/dist/artifacts/report.js +16 -0
- package/dist/artifacts/report.js.map +1 -1
- package/dist/browser/backends/playwright-lib.d.ts.map +1 -1
- package/dist/browser/backends/playwright-lib.js +17 -6
- package/dist/browser/backends/playwright-lib.js.map +1 -1
- package/dist/browser/preflight.d.ts +46 -0
- package/dist/browser/preflight.d.ts.map +1 -0
- package/dist/browser/preflight.js +73 -0
- package/dist/browser/preflight.js.map +1 -0
- package/dist/cli/index.d.ts +10 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +327 -266
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/is-main.d.ts +10 -0
- package/dist/cli/is-main.d.ts.map +1 -0
- package/dist/cli/is-main.js +21 -0
- package/dist/cli/is-main.js.map +1 -0
- package/dist/codegen/index.d.ts +3 -1
- package/dist/codegen/index.d.ts.map +1 -1
- package/dist/codegen/index.js +7 -2
- package/dist/codegen/index.js.map +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +80 -2
- package/dist/config/index.js.map +1 -1
- package/dist/config/profiles.d.ts +14 -1
- package/dist/config/profiles.d.ts.map +1 -1
- package/dist/config/profiles.js +30 -0
- package/dist/config/profiles.js.map +1 -1
- package/dist/config/schema.d.ts +23 -1
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js +7 -2
- package/dist/config/schema.js.map +1 -1
- package/dist/core/config.d.ts +18 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +23 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/index.d.ts +15 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +13 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/modalities/explore.d.ts +3 -0
- package/dist/core/modalities/explore.d.ts.map +1 -0
- package/dist/core/modalities/explore.js +82 -0
- package/dist/core/modalities/explore.js.map +1 -0
- package/dist/core/modality.d.ts +49 -0
- package/dist/core/modality.d.ts.map +1 -0
- package/dist/core/modality.js +24 -0
- package/dist/core/modality.js.map +1 -0
- package/dist/core/registry.d.ts +11 -0
- package/dist/core/registry.d.ts.map +1 -0
- package/dist/core/registry.js +43 -0
- package/dist/core/registry.js.map +1 -0
- package/dist/core/reporting.d.ts +11 -0
- package/dist/core/reporting.d.ts.map +1 -0
- package/dist/core/reporting.js +13 -0
- package/dist/core/reporting.js.map +1 -0
- package/dist/index.d.ts +6 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/llm/cost.d.ts +53 -0
- package/dist/llm/cost.d.ts.map +1 -0
- package/dist/llm/cost.js +99 -0
- package/dist/llm/cost.js.map +1 -0
- package/dist/llm/factory.d.ts +18 -0
- package/dist/llm/factory.d.ts.map +1 -1
- package/dist/llm/factory.js +24 -0
- package/dist/llm/factory.js.map +1 -1
- package/dist/llm/index.d.ts +6 -1
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js +5 -1
- package/dist/llm/index.js.map +1 -1
- package/dist/llm/routing.d.ts +40 -0
- package/dist/llm/routing.d.ts.map +1 -0
- package/dist/llm/routing.js +52 -0
- package/dist/llm/routing.js.map +1 -0
- package/dist/llm/structured.d.ts +28 -5
- package/dist/llm/structured.d.ts.map +1 -1
- package/dist/llm/structured.js +42 -9
- package/dist/llm/structured.js.map +1 -1
- package/dist/prompts/local/identify-elements.js +15 -15
- package/dist/prompts/local/judge-checklist-coverage.js +8 -8
- package/dist/prompts/local/judge-test-cases.js +8 -8
- package/dist/prompts/local/pilot-review.js +10 -10
- package/dist/prompts/local/qa-manual-test-designer.d.ts +1 -1
- package/dist/prompts/local/qa-manual-test-designer.js +7 -7
- package/dist/prompts/local/qa-playwright-ts-writer.d.ts +1 -1
- package/dist/prompts/local/qa-playwright-ts-writer.js +35 -35
- package/dist/prompts/local/qa-testcase-from-ui.d.ts +1 -1
- package/dist/prompts/local/qa-testcase-from-ui.js +47 -47
- package/dist/session/capture.d.ts +31 -0
- package/dist/session/capture.d.ts.map +1 -0
- package/dist/session/capture.js +84 -0
- package/dist/session/capture.js.map +1 -0
- package/dist/session/index.d.ts +16 -0
- package/dist/session/index.d.ts.map +1 -1
- package/dist/session/index.js +52 -2
- package/dist/session/index.js.map +1 -1
- package/dist/tui/screens/summary-screen.d.ts.map +1 -1
- package/dist/tui/screens/summary-screen.js +13 -1
- package/dist/tui/screens/summary-screen.js.map +1 -1
- package/dist/validate/runner.d.ts +6 -0
- package/dist/validate/runner.d.ts.map +1 -1
- package/dist/validate/runner.js +28 -9
- package/dist/validate/runner.js.map +1 -1
- package/package.json +98 -97
package/dist/cli/index.js
CHANGED
|
@@ -1,300 +1,360 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* CLI `cairn`. Commands: observe · explore · design · automate · dataset-add · experiment
|
|
3
|
+
* CLI `cairn`. Commands: observe · explore · design · automate · dataset-add · experiment ·
|
|
4
|
+
* promote · session · login, plus GATED modality stubs (ui|e2e / api / unit / docs — C1-01).
|
|
5
|
+
* The umbrella router is thin: each modality command dispatches through the shared core
|
|
6
|
+
* (`runModality`), so a future modality is a thin add, not a fork.
|
|
4
7
|
* `lex-bot` stays as a hidden, deprecated alias (see ./lex-bot.ts) → same code path.
|
|
5
8
|
*/
|
|
6
9
|
import "dotenv/config";
|
|
7
10
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
8
11
|
import { dirname, join, resolve } from "node:path";
|
|
9
|
-
import { pathToFileURL } from "node:url";
|
|
10
12
|
import { Command } from "commander";
|
|
13
|
+
import { isMainEntry } from "./is-main.js";
|
|
11
14
|
import { BOT_NAME, BOT_VERSION } from "../index.js";
|
|
12
15
|
import { makeGateway } from "../browser/index.js";
|
|
13
16
|
import { capture } from "../observe/index.js";
|
|
14
|
-
import { SessionStore } from "../session/index.js";
|
|
17
|
+
import { SessionStore, captureSession } from "../session/index.js";
|
|
15
18
|
import { loadConfig } from "../config/index.js";
|
|
16
|
-
import {
|
|
19
|
+
import { runDesign, runAutomate } from "../agent/index.js";
|
|
20
|
+
import { renderRunSummary } from "../agent/summary.js";
|
|
17
21
|
import { promoteCase, locatorFor } from "../promote/index.js";
|
|
18
|
-
import { makeModel } from "../llm/index.js";
|
|
22
|
+
import { makeModel, structuredMethodFor } from "../llm/index.js";
|
|
19
23
|
import { structuredInvoker } from "../llm/structured.js";
|
|
20
24
|
import { PromptRegistry, LOCAL_PROMPTS } from "../prompts/index.js";
|
|
21
25
|
import { runExperiment } from "../eval/experiment.js";
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
.description("Explore a page: ARIA snapshot + interactive elements + screenshot")
|
|
30
|
-
.requiredOption("--url <url>", "page URL")
|
|
31
|
-
.option("--backend <kind>", "lib | cli", "lib")
|
|
32
|
-
.option("--session <name>", "name of the saved session (.auth/<name>.storageState.json)")
|
|
33
|
-
.option("--out <file>", "where to save the screenshot", "observe-screenshot.png")
|
|
34
|
-
.action(async (opts) => {
|
|
35
|
-
const backend = opts.backend === "cli" ? "cli" : "lib";
|
|
26
|
+
// C1-01 — shared umbrella core: flag→config, the cost footer, and the modality registry/dispatch.
|
|
27
|
+
import { resolveConfig, printCost, runModality, MODALITIES } from "../core/index.js";
|
|
28
|
+
/**
|
|
29
|
+
* Shared capture action for `cairn session capture` and the flat `cairn login` alias.
|
|
30
|
+
* Opens a headed browser, waits for login, and persists the session (L1-05). Never prints secrets.
|
|
31
|
+
*/
|
|
32
|
+
async function runCapture(opts) {
|
|
36
33
|
const config = loadConfig(process.env);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
storageState = await new SessionStore(resolve(".auth")).load(opts.session);
|
|
40
|
-
}
|
|
41
|
-
const gateway = makeGateway({ backend, storageState, channel: config.browser.channel });
|
|
42
|
-
try {
|
|
43
|
-
const study = await capture(gateway, opts.url);
|
|
44
|
-
const interactive = study.elements.filter((e) => e.interactive);
|
|
45
|
-
process.stdout.write(`URL: ${study.url} (backend: ${study.capturedBy})\n`);
|
|
46
|
-
process.stdout.write(`Elements: ${study.elements.length}, interactive: ${interactive.length}\n\n`);
|
|
47
|
-
process.stdout.write(`${study.ariaYaml}\n\nInteractive:\n`);
|
|
48
|
-
for (const e of interactive) {
|
|
49
|
-
process.stdout.write(` [${e.ref}] ${e.role}${e.name ? ` "${e.name}"` : ""}\n`);
|
|
50
|
-
}
|
|
51
|
-
await mkdir(dirname(opts.out), { recursive: true });
|
|
52
|
-
await writeFile(opts.out, Buffer.from(study.screenshotB64, "base64"));
|
|
53
|
-
process.stdout.write(`\nScreenshot → ${opts.out}\n`);
|
|
54
|
-
}
|
|
55
|
-
finally {
|
|
56
|
-
await gateway.close();
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
program
|
|
60
|
-
.command("explore")
|
|
61
|
-
.description("Explore a page and generate methodology-based test cases (Sprint 2: no code)")
|
|
62
|
-
.requiredOption("--url <url>", "page URL")
|
|
63
|
-
.option("--backend <kind>", "lib | cli (overrides BROWSER_BACKEND)")
|
|
64
|
-
.option("--session <name>", "name of the saved session (.auth/<name>.storageState.json)")
|
|
65
|
-
.option("--session-file <path>", "direct path to a storageState file (any name)")
|
|
66
|
-
.option("--headed", "visible browser (debug)")
|
|
67
|
-
.option("--checklist <file>", "checklist file (md/text) — guides what to test")
|
|
68
|
-
.option("--style <s>", "planning style: happy | negative | coverage | all")
|
|
69
|
-
.action(async (opts) => {
|
|
70
|
-
const env = { ...process.env };
|
|
71
|
-
if (opts.backend)
|
|
72
|
-
env.BROWSER_BACKEND = opts.backend;
|
|
73
|
-
const config = loadConfig(env);
|
|
74
|
-
const checklistText = opts.checklist ? await readFile(opts.checklist, "utf8") : undefined;
|
|
75
|
-
process.stderr.write(`▸ Exploring ${opts.url}${opts.session ? ` (session: ${opts.session})` : ""}${opts.checklist ? ` (checklist: ${opts.checklist})` : ""}…\n`);
|
|
76
|
-
const result = await runExploration({
|
|
34
|
+
process.stderr.write(`▸ Capturing a session at ${opts.url}…\n`);
|
|
35
|
+
const res = await captureSession({
|
|
77
36
|
url: opts.url,
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
checklistText,
|
|
83
|
-
style: opts.style,
|
|
84
|
-
onProgress: (e) => process.stderr.write(` ▸ ${e}\n`),
|
|
37
|
+
name: opts.name,
|
|
38
|
+
channel: opts.channel ?? config.browser.channel,
|
|
39
|
+
dir: opts.dir,
|
|
40
|
+
onLog: (m) => process.stderr.write(` ▸ ${m}\n`),
|
|
85
41
|
});
|
|
86
|
-
process.stdout.write(`\n
|
|
87
|
-
process.stdout.write(`
|
|
88
|
-
process.stdout.write(`
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
42
|
+
process.stdout.write(`\n✓ Session "${res.name}" saved → ${res.path}\n`);
|
|
43
|
+
process.stdout.write(` Next: cairn explore --url <app-url> --session ${res.name}\n`);
|
|
44
|
+
process.stdout.write(` Note: .auth/ is gitignored — never commit session files.\n`);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Build the `cairn` commander program. Exported (C1-02) so tests can drive commands and snapshot
|
|
48
|
+
* `--help` without running the process entry point. Each call returns a fresh, independent program.
|
|
49
|
+
*/
|
|
50
|
+
export function buildProgram() {
|
|
51
|
+
const program = new Command();
|
|
52
|
+
program
|
|
53
|
+
.name("cairn")
|
|
54
|
+
.description(`${BOT_NAME} — autonomous UI test generator`)
|
|
55
|
+
.version(BOT_VERSION);
|
|
56
|
+
program
|
|
57
|
+
.command("observe")
|
|
58
|
+
.description("Explore a page: ARIA snapshot + interactive elements + screenshot")
|
|
59
|
+
.requiredOption("--url <url>", "page URL")
|
|
60
|
+
.option("--backend <kind>", "lib | cli", "lib")
|
|
61
|
+
.option("--session <name>", "name of the saved session (.auth/<name>.storageState.json)")
|
|
62
|
+
.option("--out <file>", "where to save the screenshot", "observe-screenshot.png")
|
|
63
|
+
.action(async (opts) => {
|
|
64
|
+
const backend = opts.backend === "cli" ? "cli" : "lib";
|
|
65
|
+
const config = loadConfig(process.env);
|
|
66
|
+
let storageState;
|
|
67
|
+
if (opts.session) {
|
|
68
|
+
storageState = await new SessionStore(resolve(".auth")).load(opts.session);
|
|
104
69
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
process.stdout.write(`
|
|
70
|
+
const gateway = makeGateway({ backend, storageState, channel: config.browser.channel });
|
|
71
|
+
try {
|
|
72
|
+
const study = await capture(gateway, opts.url);
|
|
73
|
+
const interactive = study.elements.filter((e) => e.interactive);
|
|
74
|
+
process.stdout.write(`URL: ${study.url} (backend: ${study.capturedBy})\n`);
|
|
75
|
+
process.stdout.write(`Elements: ${study.elements.length}, interactive: ${interactive.length}\n\n`);
|
|
76
|
+
process.stdout.write(`${study.ariaYaml}\n\nInteractive:\n`);
|
|
77
|
+
for (const e of interactive) {
|
|
78
|
+
process.stdout.write(` [${e.ref}] ${e.role}${e.name ? ` "${e.name}"` : ""}\n`);
|
|
79
|
+
}
|
|
80
|
+
await mkdir(dirname(opts.out), { recursive: true });
|
|
81
|
+
await writeFile(opts.out, Buffer.from(study.screenshotB64, "base64"));
|
|
82
|
+
process.stdout.write(`\nScreenshot → ${opts.out}\n`);
|
|
110
83
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
process.stdout.write(`\n=== Pilot: ${result.pilot.verdict.toUpperCase()} ===\n ${result.pilot.reason}\n → ${result.pilot.guidance}\n`);
|
|
114
|
-
}
|
|
115
|
-
process.stdout.write(`\nArtifacts: ${result.runDir}\n`);
|
|
116
|
-
});
|
|
117
|
-
program
|
|
118
|
-
.command("dataset-add")
|
|
119
|
-
.description("Add a run (study.json) to an experiment dataset")
|
|
120
|
-
.requiredOption("--from-run <dir>", "runs/<id> folder")
|
|
121
|
-
.requiredOption("--to <file>", "dataset file (JSON)")
|
|
122
|
-
.action(async (opts) => {
|
|
123
|
-
const study = JSON.parse(await readFile(join(opts.fromRun, "study.json"), "utf8"));
|
|
124
|
-
let pageSemantics = "";
|
|
125
|
-
try {
|
|
126
|
-
const rep = JSON.parse(await readFile(join(opts.fromRun, "report.json"), "utf8"));
|
|
127
|
-
pageSemantics = rep.pageSemantics ?? "";
|
|
128
|
-
}
|
|
129
|
-
catch {
|
|
130
|
-
// report.json is optional
|
|
131
|
-
}
|
|
132
|
-
let ds = { items: [] };
|
|
133
|
-
try {
|
|
134
|
-
ds = JSON.parse(await readFile(opts.to, "utf8"));
|
|
135
|
-
}
|
|
136
|
-
catch {
|
|
137
|
-
// new dataset
|
|
138
|
-
}
|
|
139
|
-
const id = `item-${ds.items.length + 1}`;
|
|
140
|
-
ds.items.push({ id, study, pageSemantics });
|
|
141
|
-
await mkdir(dirname(opts.to) || ".", { recursive: true });
|
|
142
|
-
await writeFile(opts.to, JSON.stringify(ds, null, 2), "utf8");
|
|
143
|
-
process.stdout.write(`Added ${id} → ${opts.to} (total items: ${ds.items.length})\n`);
|
|
144
|
-
});
|
|
145
|
-
program
|
|
146
|
-
.command("experiment")
|
|
147
|
-
.description("Compare prompt versions on a dataset (B2 self-improvement)")
|
|
148
|
-
.requiredOption("--dataset <file>", "dataset file (JSON)")
|
|
149
|
-
.option("--candidate <spec>", "promptName=file.md — candidate prompt vs production")
|
|
150
|
-
.option("--target <metric>", "target verdict metric", "grounding")
|
|
151
|
-
.action(async (opts) => {
|
|
152
|
-
const config = loadConfig(process.env);
|
|
153
|
-
const keys = {
|
|
154
|
-
anthropicApiKey: config.anthropicApiKey,
|
|
155
|
-
openrouterApiKey: config.openrouterApiKey,
|
|
156
|
-
};
|
|
157
|
-
const ds = JSON.parse(await readFile(opts.dataset, "utf8"));
|
|
158
|
-
const variants = [{ label: "production", prompts: new PromptRegistry() }];
|
|
159
|
-
if (opts.candidate) {
|
|
160
|
-
const eq = opts.candidate.indexOf("=");
|
|
161
|
-
const name = opts.candidate.slice(0, eq);
|
|
162
|
-
const text = await readFile(opts.candidate.slice(eq + 1), "utf8");
|
|
163
|
-
variants.push({
|
|
164
|
-
label: "candidate",
|
|
165
|
-
prompts: new PromptRegistry({ local: { ...LOCAL_PROMPTS, [name]: text } }),
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
process.stderr.write(`▸ Experiment: ${ds.items.length} items × ${variants.length} versions…\n`);
|
|
169
|
-
const result = await runExperiment(ds.items, variants, {
|
|
170
|
-
designInvoke: structuredInvoker(makeModel(config.models.reasoning, keys)),
|
|
171
|
-
judgeInvoke: structuredInvoker(makeModel(config.models.judge, keys)),
|
|
172
|
-
}, { target: opts.target });
|
|
173
|
-
process.stdout.write(`\n=== Experiment (${ds.items.length} items) ===\n`);
|
|
174
|
-
for (const v of result.perVariant) {
|
|
175
|
-
process.stdout.write(`\n[${v.label}]\n`);
|
|
176
|
-
for (const [name, val] of Object.entries(v.meanScores)) {
|
|
177
|
-
process.stdout.write(` ${name}: ${val.toFixed(3)}\n`);
|
|
84
|
+
finally {
|
|
85
|
+
await gateway.close();
|
|
178
86
|
}
|
|
179
|
-
}
|
|
180
|
-
if (result.verdict) {
|
|
181
|
-
const vd = result.verdict;
|
|
182
|
-
const reg = vd.guardrailRegressions.length ? `; regressions: ${vd.guardrailRegressions.join(", ")}` : "";
|
|
183
|
-
process.stdout.write(`\n=== Verdict: candidate ${vd.improved ? "BETTER ✓" : "NOT better ✗"} (${vd.target} Δ=${vd.delta.toFixed(3)})${reg} ===\n`);
|
|
184
|
-
process.stdout.write(vd.improved
|
|
185
|
-
? " → the version can be promoted (Langfuse label=production) — runbook promote-prompt.\n"
|
|
186
|
-
: " → reject/iterate the prompt.\n");
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
program
|
|
190
|
-
.command("design")
|
|
191
|
-
.description("Explore a page and WRITE test cases in ATC format (.md, with selectors), WITHOUT code")
|
|
192
|
-
.requiredOption("--url <url>", "page URL")
|
|
193
|
-
.option("--session <name>", "name of the saved session")
|
|
194
|
-
.option("--session-file <path>", "path to a storageState file")
|
|
195
|
-
.option("--checklist <file>", "checklist file — guides what to test")
|
|
196
|
-
.option("--style <s>", "planning style: happy | negative | coverage | all")
|
|
197
|
-
.option("--headed", "visible browser (debug)")
|
|
198
|
-
.action(async (opts) => {
|
|
199
|
-
const config = loadConfig(process.env);
|
|
200
|
-
const checklistText = opts.checklist ? await readFile(opts.checklist, "utf8") : undefined;
|
|
201
|
-
process.stderr.write(`▸ Designing test cases for ${opts.url}${opts.session ? ` (session: ${opts.session})` : ""}…\n`);
|
|
202
|
-
const result = await runDesign({
|
|
203
|
-
url: opts.url,
|
|
204
|
-
config,
|
|
205
|
-
sessionName: opts.session,
|
|
206
|
-
sessionFile: opts.sessionFile,
|
|
207
|
-
checklistText,
|
|
208
|
-
style: opts.style,
|
|
209
|
-
headed: opts.headed,
|
|
210
|
-
onProgress: (e) => process.stderr.write(` ▸ ${e}\n`),
|
|
211
87
|
});
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
88
|
+
// explore = the first REAL modality. The command keeps its exact flags/description (parity,
|
|
89
|
+
// C1-02); its action delegates to the shared core (runModality → exploreModality.run).
|
|
90
|
+
program
|
|
91
|
+
.command("explore")
|
|
92
|
+
.description("Explore a page and generate methodology-based test cases (Sprint 2: no code)")
|
|
93
|
+
.requiredOption("--url <url>", "page URL")
|
|
94
|
+
.option("--backend <kind>", "lib | cli (overrides BROWSER_BACKEND)")
|
|
95
|
+
.option("--session <name>", "name of the saved session (.auth/<name>.storageState.json)")
|
|
96
|
+
.option("--session-file <path>", "direct path to a storageState file (any name)")
|
|
97
|
+
.option("--headed", "visible browser (debug)")
|
|
98
|
+
.option("--checklist <file>", "checklist file (md/text) — guides what to test")
|
|
99
|
+
.option("--style <s>", "planning style: happy | negative | coverage | all")
|
|
100
|
+
.option("--routing <preset>", "role-routing preset: fast (Groq worker) | volume (OpenRouter worker) (sets LLM_ROUTING)")
|
|
101
|
+
.action(async (opts) => {
|
|
102
|
+
await runModality("explore", opts);
|
|
103
|
+
});
|
|
104
|
+
program
|
|
105
|
+
.command("dataset-add")
|
|
106
|
+
.description("Add a run (study.json) to an experiment dataset")
|
|
107
|
+
.requiredOption("--from-run <dir>", "runs/<id> folder")
|
|
108
|
+
.requiredOption("--to <file>", "dataset file (JSON)")
|
|
109
|
+
.action(async (opts) => {
|
|
110
|
+
const study = JSON.parse(await readFile(join(opts.fromRun, "study.json"), "utf8"));
|
|
111
|
+
let pageSemantics = "";
|
|
112
|
+
try {
|
|
113
|
+
const rep = JSON.parse(await readFile(join(opts.fromRun, "report.json"), "utf8"));
|
|
114
|
+
pageSemantics = rep.pageSemantics ?? "";
|
|
223
115
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
validate: opts.validate,
|
|
240
|
-
sessionName: opts.session,
|
|
241
|
-
sessionFile: opts.sessionFile,
|
|
242
|
-
onProgress: (e) => process.stderr.write(` ▸ ${e}\n`),
|
|
116
|
+
catch {
|
|
117
|
+
// report.json is optional
|
|
118
|
+
}
|
|
119
|
+
let ds = { items: [] };
|
|
120
|
+
try {
|
|
121
|
+
ds = JSON.parse(await readFile(opts.to, "utf8"));
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
// new dataset
|
|
125
|
+
}
|
|
126
|
+
const id = `item-${ds.items.length + 1}`;
|
|
127
|
+
ds.items.push({ id, study, pageSemantics });
|
|
128
|
+
await mkdir(dirname(opts.to) || ".", { recursive: true });
|
|
129
|
+
await writeFile(opts.to, JSON.stringify(ds, null, 2), "utf8");
|
|
130
|
+
process.stdout.write(`Added ${id} → ${opts.to} (total items: ${ds.items.length})\n`);
|
|
243
131
|
});
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
out.set(v.ref, locatorFor(v));
|
|
279
|
-
return out;
|
|
132
|
+
program
|
|
133
|
+
.command("experiment")
|
|
134
|
+
.description("Compare prompt versions on a dataset (B2 self-improvement)")
|
|
135
|
+
.requiredOption("--dataset <file>", "dataset file (JSON)")
|
|
136
|
+
.option("--candidate <spec>", "promptName=file.md — candidate prompt vs production")
|
|
137
|
+
.option("--target <metric>", "target verdict metric", "grounding")
|
|
138
|
+
.action(async (opts) => {
|
|
139
|
+
const config = loadConfig(process.env);
|
|
140
|
+
const keys = {
|
|
141
|
+
anthropicApiKey: config.anthropicApiKey,
|
|
142
|
+
openrouterApiKey: config.openrouterApiKey,
|
|
143
|
+
groqApiKey: config.groqApiKey,
|
|
144
|
+
};
|
|
145
|
+
const ds = JSON.parse(await readFile(opts.dataset, "utf8"));
|
|
146
|
+
const variants = [{ label: "production", prompts: new PromptRegistry() }];
|
|
147
|
+
if (opts.candidate) {
|
|
148
|
+
const eq = opts.candidate.indexOf("=");
|
|
149
|
+
const name = opts.candidate.slice(0, eq);
|
|
150
|
+
const text = await readFile(opts.candidate.slice(eq + 1), "utf8");
|
|
151
|
+
variants.push({
|
|
152
|
+
label: "candidate",
|
|
153
|
+
prompts: new PromptRegistry({ local: { ...LOCAL_PROMPTS, [name]: text } }),
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
process.stderr.write(`▸ Experiment: ${ds.items.length} items × ${variants.length} versions…\n`);
|
|
157
|
+
const result = await runExperiment(ds.items, variants, {
|
|
158
|
+
designInvoke: structuredInvoker(makeModel(config.models.reasoning, keys), structuredMethodFor(config.models.reasoning.provider)),
|
|
159
|
+
judgeInvoke: structuredInvoker(makeModel(config.models.judge, keys), structuredMethodFor(config.models.judge.provider)),
|
|
160
|
+
}, { target: opts.target });
|
|
161
|
+
process.stdout.write(`\n=== Experiment (${ds.items.length} items) ===\n`);
|
|
162
|
+
for (const v of result.perVariant) {
|
|
163
|
+
process.stdout.write(`\n[${v.label}]\n`);
|
|
164
|
+
for (const [name, val] of Object.entries(v.meanScores)) {
|
|
165
|
+
process.stdout.write(` ${name}: ${val.toFixed(3)}\n`);
|
|
280
166
|
}
|
|
281
|
-
|
|
282
|
-
|
|
167
|
+
}
|
|
168
|
+
if (result.verdict) {
|
|
169
|
+
const vd = result.verdict;
|
|
170
|
+
const reg = vd.guardrailRegressions.length ? `; regressions: ${vd.guardrailRegressions.join(", ")}` : "";
|
|
171
|
+
process.stdout.write(`\n=== Verdict: candidate ${vd.improved ? "BETTER ✓" : "NOT better ✗"} (${vd.target} Δ=${vd.delta.toFixed(3)})${reg} ===\n`);
|
|
172
|
+
process.stdout.write(vd.improved
|
|
173
|
+
? " → the version can be promoted (Langfuse label=production) — runbook promote-prompt.\n"
|
|
174
|
+
: " → reject/iterate the prompt.\n");
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
program
|
|
178
|
+
.command("design")
|
|
179
|
+
.description("Explore a page and WRITE test cases in ATC format (.md, with selectors), WITHOUT code")
|
|
180
|
+
.requiredOption("--url <url>", "page URL")
|
|
181
|
+
.option("--session <name>", "name of the saved session")
|
|
182
|
+
.option("--session-file <path>", "path to a storageState file")
|
|
183
|
+
.option("--checklist <file>", "checklist file — guides what to test")
|
|
184
|
+
.option("--style <s>", "planning style: happy | negative | coverage | all")
|
|
185
|
+
.option("--routing <preset>", "role-routing preset: fast (Groq worker) | volume (OpenRouter worker) (sets LLM_ROUTING)")
|
|
186
|
+
.option("--headed", "visible browser (debug)")
|
|
187
|
+
.action(async (opts) => {
|
|
188
|
+
const config = resolveConfig({ routing: opts.routing });
|
|
189
|
+
const checklistText = opts.checklist ? await readFile(opts.checklist, "utf8") : undefined;
|
|
190
|
+
process.stderr.write(`▸ Designing test cases for ${opts.url}${opts.session ? ` (session: ${opts.session})` : ""}…\n`);
|
|
191
|
+
const result = await runDesign({
|
|
192
|
+
url: opts.url,
|
|
193
|
+
config,
|
|
194
|
+
sessionName: opts.session,
|
|
195
|
+
sessionFile: opts.sessionFile,
|
|
196
|
+
checklistText,
|
|
197
|
+
style: opts.style,
|
|
198
|
+
headed: opts.headed,
|
|
199
|
+
onProgress: (e) => process.stderr.write(` ▸ ${e}\n`),
|
|
200
|
+
});
|
|
201
|
+
process.stdout.write(`\n=== ${result.testCases.length} test cases → ${result.runDir}\\testcases\\ ===\n`);
|
|
202
|
+
for (const tc of result.testCases) {
|
|
203
|
+
const exec = tc.execution === "manual" ? "MTC/manual" : "ATC/auto";
|
|
204
|
+
process.stdout.write(`[${exec} · ${tc.priority}/${tc.type}] ${tc.title}\n`);
|
|
205
|
+
}
|
|
206
|
+
for (const f of result.testCaseFiles)
|
|
207
|
+
process.stdout.write(` ${f}\n`);
|
|
208
|
+
if (result.scores.length > 0) {
|
|
209
|
+
process.stdout.write("\n=== Metrics ===\n");
|
|
210
|
+
for (const s of result.scores) {
|
|
211
|
+
process.stdout.write(` ${s.name}: ${s.value.toFixed(2)}${s.comment ? ` — ${s.comment}` : ""}\n`);
|
|
283
212
|
}
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
213
|
+
}
|
|
214
|
+
printCost(result.cost);
|
|
215
|
+
});
|
|
216
|
+
program
|
|
217
|
+
.command("automate")
|
|
218
|
+
.description("Generate @playwright/test from ready cases (runs/<id>/testcases/*.md)")
|
|
219
|
+
.requiredOption("--run <dir>", "design run folder (runs/<id>)")
|
|
220
|
+
.option("--validate", "run the generated tests (a session is required)")
|
|
221
|
+
.option("--session <name>", "session name for validation")
|
|
222
|
+
.option("--session-file <path>", "path to storageState for validation")
|
|
223
|
+
.option("--routing <preset>", "role-routing preset: fast (Groq worker) | volume (OpenRouter worker) (sets LLM_ROUTING)")
|
|
224
|
+
.action(async (opts) => {
|
|
225
|
+
const config = resolveConfig({ routing: opts.routing });
|
|
226
|
+
process.stderr.write(`▸ Automating cases from ${opts.run}…\n`);
|
|
227
|
+
const result = await runAutomate({
|
|
228
|
+
runDir: opts.run,
|
|
229
|
+
config,
|
|
230
|
+
validate: opts.validate,
|
|
231
|
+
sessionName: opts.session,
|
|
232
|
+
sessionFile: opts.sessionFile,
|
|
233
|
+
onProgress: (e) => process.stderr.write(` ▸ ${e}\n`),
|
|
234
|
+
});
|
|
235
|
+
process.stdout.write(`\n=== ${result.specFiles.length} spec files → ${result.runDir}\\tests\\ ===\n`);
|
|
236
|
+
for (const f of result.specFiles)
|
|
237
|
+
process.stdout.write(` ${f}\n`);
|
|
238
|
+
if (result.validation) {
|
|
239
|
+
process.stdout.write(`\nValidation: ${Math.round(result.validation.greenRatio * 100)}% green out of ${result.validation.results.length} tests\n`);
|
|
240
|
+
}
|
|
241
|
+
printCost(result.cost);
|
|
242
|
+
// L1-04 (Box 4): same consolidated footer as `explore` — pass/fail · cost · budget · path.
|
|
243
|
+
process.stdout.write("\n");
|
|
244
|
+
for (const line of renderRunSummary({
|
|
245
|
+
runDir: result.runDir,
|
|
246
|
+
validation: result.validation,
|
|
247
|
+
cost: result.cost,
|
|
248
|
+
budget: result.budget,
|
|
249
|
+
stoppedEarly: result.stoppedEarly,
|
|
250
|
+
})) {
|
|
251
|
+
process.stdout.write(`${line}\n`);
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
program
|
|
255
|
+
.command("promote")
|
|
256
|
+
.description("Promote manual MTC case(s) to automatable ATC (.md only; run `automate` to generate code)")
|
|
257
|
+
.requiredOption("--run <dir>", "run folder (runs/<id>)")
|
|
258
|
+
.requiredOption("--cases <ids>", "comma-separated MTC ids, e.g. MTC-DEMO-001,MTC-DEMO-003")
|
|
259
|
+
.option("--session <name>", "session for the live selector fallback")
|
|
260
|
+
.option("--session-file <path>", "storageState path for the live selector fallback")
|
|
261
|
+
.action(async (opts) => {
|
|
262
|
+
const config = loadConfig(process.env);
|
|
263
|
+
const runDir = resolve(opts.run);
|
|
264
|
+
const ids = opts.cases.split(",").map((s) => s.trim()).filter(Boolean);
|
|
265
|
+
// Live fallback only when a session is provided (best-effort — see note).
|
|
266
|
+
let collectLive;
|
|
267
|
+
let storageState;
|
|
268
|
+
if (opts.sessionFile)
|
|
269
|
+
storageState = await new SessionStore(resolve(".auth")).loadFile(resolve(opts.sessionFile));
|
|
270
|
+
else if (opts.session)
|
|
271
|
+
storageState = await new SessionStore(resolve(".auth")).load(opts.session);
|
|
272
|
+
if (storageState) {
|
|
273
|
+
collectLive = async (url, refs) => {
|
|
274
|
+
const gateway = makeGateway({ backend: config.browser.backend, storageState, channel: config.browser.channel });
|
|
275
|
+
try {
|
|
276
|
+
await gateway.observe({ url });
|
|
277
|
+
const verified = await gateway.verify(refs.map((ref) => ({ ref, role: "", name: undefined, interactive: true, rank: 0 })));
|
|
278
|
+
const out = new Map();
|
|
279
|
+
for (const v of verified)
|
|
280
|
+
if (v.verified)
|
|
281
|
+
out.set(v.ref, locatorFor(v));
|
|
282
|
+
return out;
|
|
283
|
+
}
|
|
284
|
+
finally {
|
|
285
|
+
await gateway.close();
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
process.stderr.write(`▸ Promoting ${String(ids.length)} case(s) from ${opts.run}…\n`);
|
|
290
|
+
for (const id of ids) {
|
|
291
|
+
const res = await promoteCase(runDir, id, { collectLive });
|
|
292
|
+
process.stdout.write(`${res.oldId} → ${res.newId}${res.warning ? ` (⚠ ${res.warning})` : ""}\n`);
|
|
293
|
+
}
|
|
294
|
+
process.stdout.write(`\nDone. Run \`cairn automate --run ${opts.run}\` to generate code for the new ATC case(s).\n`);
|
|
295
|
+
});
|
|
296
|
+
// `cairn session <capture|ls|rm>` — first-class management of saved login sessions (L1-05).
|
|
297
|
+
const session = program.command("session").description("Manage saved login sessions (.auth/)");
|
|
298
|
+
session
|
|
299
|
+
.command("capture")
|
|
300
|
+
.description("Capture a login session interactively (opens a headed browser; press Enter when logged in)")
|
|
301
|
+
.requiredOption("--url <loginUrl>", "login page URL to open")
|
|
302
|
+
.option("--name <name>", "session name (default: derived from the URL host)")
|
|
303
|
+
.option("--channel <channel>", "browser channel, e.g. chrome (helps with OAuth; default from config)")
|
|
304
|
+
.option("--dir <dir>", "sessions directory", ".auth")
|
|
305
|
+
.action(runCapture);
|
|
306
|
+
session
|
|
307
|
+
.command("ls")
|
|
308
|
+
.description("List saved sessions")
|
|
309
|
+
.option("--dir <dir>", "sessions directory", ".auth")
|
|
310
|
+
.action(async (opts) => {
|
|
311
|
+
const names = await new SessionStore(resolve(opts.dir)).list();
|
|
312
|
+
if (names.length === 0) {
|
|
313
|
+
process.stdout.write("No saved sessions. Capture one: cairn session capture --url <loginUrl> --name <name>\n");
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
process.stdout.write(`Saved sessions (${opts.dir}):\n`);
|
|
317
|
+
for (const n of names)
|
|
318
|
+
process.stdout.write(` ${n}\n`);
|
|
319
|
+
});
|
|
320
|
+
session
|
|
321
|
+
.command("rm <name>")
|
|
322
|
+
.description("Remove a saved session")
|
|
323
|
+
.option("--dir <dir>", "sessions directory", ".auth")
|
|
324
|
+
.action(async (name, opts) => {
|
|
325
|
+
const removed = await new SessionStore(resolve(opts.dir)).remove(name);
|
|
326
|
+
process.stdout.write(removed ? `✓ Removed session "${name}".\n` : `No session "${name}" to remove.\n`);
|
|
327
|
+
});
|
|
328
|
+
// Flat alias: `cairn login` == `cairn session capture` (issue #27 — acceptable shorthand).
|
|
329
|
+
program
|
|
330
|
+
.command("login")
|
|
331
|
+
.description("Alias for `cairn session capture` — capture a login session interactively")
|
|
332
|
+
.requiredOption("--url <loginUrl>", "login page URL to open")
|
|
333
|
+
.option("--name <name>", "session name (default: derived from the URL host)")
|
|
334
|
+
.option("--channel <channel>", "browser channel, e.g. chrome (helps with OAuth; default from config)")
|
|
335
|
+
.option("--dir <dir>", "sessions directory", ".auth")
|
|
336
|
+
.action(runCapture);
|
|
337
|
+
// C1-01: GATED modality stubs (ui|e2e, api, unit, docs). Discoverable placeholders with ZERO
|
|
338
|
+
// generation logic — each dispatches through runModality, which prints the coming-soon notice and
|
|
339
|
+
// exits 0. #21–24 stay gated behind a named-user pull (L-G2 / #25): build by demand, one at a time.
|
|
340
|
+
for (const m of MODALITIES.filter((x) => x.gated)) {
|
|
341
|
+
const c = program
|
|
342
|
+
.command(m.name)
|
|
343
|
+
.description(`${m.summary} — coming soon (gated; see L-G2)`)
|
|
344
|
+
.action(async () => {
|
|
345
|
+
await runModality(m.name, {});
|
|
346
|
+
});
|
|
347
|
+
if (m.aliases?.length)
|
|
348
|
+
c.aliases(m.aliases);
|
|
290
349
|
}
|
|
291
|
-
|
|
292
|
-
}
|
|
350
|
+
return program;
|
|
351
|
+
}
|
|
293
352
|
/**
|
|
294
353
|
* Run the CLI. Shared by the primary `cairn` entry (this file) and the deprecated
|
|
295
354
|
* `lex-bot` alias shim (./lex-bot.ts), so both go through the exact same code path.
|
|
296
355
|
*/
|
|
297
356
|
export async function runCli() {
|
|
357
|
+
const program = buildProgram();
|
|
298
358
|
const cliArgs = process.argv.slice(2);
|
|
299
359
|
if (cliArgs.length === 0 && process.stdin.isTTY && process.stdout.isTTY) {
|
|
300
360
|
// No command in an interactive terminal → launch the TUI (lazy: keeps React/Ink
|
|
@@ -315,8 +375,9 @@ export async function runCli() {
|
|
|
315
375
|
}
|
|
316
376
|
// Auto-run only when invoked directly as the `cairn` bin — NOT when imported by the
|
|
317
377
|
// `lex-bot` alias shim (which calls runCli() itself after printing the deprecation notice).
|
|
318
|
-
|
|
319
|
-
|
|
378
|
+
// isMainEntry resolves symlinks, so this still fires under `npm link` and `npm i -g` on
|
|
379
|
+
// Linux/macOS (where the global bin is a symlink) — a naive URL compare would silently no-op.
|
|
380
|
+
if (isMainEntry(process.argv[1], import.meta.url)) {
|
|
320
381
|
await runCli();
|
|
321
382
|
}
|
|
322
383
|
//# sourceMappingURL=index.js.map
|