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