@docsxai/engine 0.2.1-rc.1 → 0.3.0-rc.1

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 (94) hide show
  1. package/README.md +18 -5
  2. package/dist/address-class.d.ts +14 -0
  3. package/dist/address-class.js +151 -0
  4. package/dist/auth/api-login.d.ts +3 -3
  5. package/dist/auth/email-otp.d.ts +60 -60
  6. package/dist/auth/jwt-injection.d.ts +45 -45
  7. package/dist/auth/pat-header.d.ts +2 -2
  8. package/dist/auth/types.d.ts +2 -2
  9. package/dist/auth/ui-form.d.ts +54 -54
  10. package/dist/auth/webauthn.d.ts +22 -22
  11. package/dist/backend-client-contracts.d.ts +4 -2
  12. package/dist/calibrate.d.ts +2 -2
  13. package/dist/calibrate.js +5 -0
  14. package/dist/cli-commands-authoring.js +23 -4
  15. package/dist/cli-commands-backend.js +2 -2
  16. package/dist/cli-commands-docpack.d.ts +5 -0
  17. package/dist/cli-commands-docpack.js +70 -24
  18. package/dist/cli-commands-pack.d.ts +2 -0
  19. package/dist/cli-commands-pack.js +69 -0
  20. package/dist/cli-commands-session.js +92 -89
  21. package/dist/cli-retired.d.ts +6 -0
  22. package/dist/cli-retired.js +12 -0
  23. package/dist/cli-usage.d.ts +1 -1
  24. package/dist/cli-usage.js +52 -4
  25. package/dist/cli-verify.d.ts +14 -0
  26. package/dist/cli-verify.js +54 -0
  27. package/dist/cli.js +14 -1
  28. package/dist/deprecation.d.ts +19 -0
  29. package/dist/deprecation.js +32 -0
  30. package/dist/diagnose.d.ts +25 -0
  31. package/dist/diagnose.js +69 -3
  32. package/dist/diff-compute.js +1 -0
  33. package/dist/doc-pack-io.d.ts +14 -0
  34. package/dist/doc-pack-io.js +121 -14
  35. package/dist/doc-pack.d.ts +2282 -387
  36. package/dist/doc-pack.js +135 -43
  37. package/dist/doctor-checks.d.ts +1 -1
  38. package/dist/doctor-checks.js +25 -1
  39. package/dist/driver-budget.d.ts +6 -0
  40. package/dist/driver-budget.js +15 -0
  41. package/dist/egress-guard.d.ts +58 -0
  42. package/dist/egress-guard.js +136 -0
  43. package/dist/environment-spec.d.ts +67 -0
  44. package/dist/environment-spec.js +38 -0
  45. package/dist/export/playwright-test.js +42 -10
  46. package/dist/flow-file.d.ts +9 -3
  47. package/dist/flow-file.js +21 -1
  48. package/dist/flow-halt.d.ts +16 -0
  49. package/dist/flow-halt.js +76 -0
  50. package/dist/flow-hidden.d.ts +9 -0
  51. package/dist/flow-hidden.js +20 -0
  52. package/dist/flow-lint.js +91 -1
  53. package/dist/flow-matrix-lint.d.ts +10 -0
  54. package/dist/flow-matrix-lint.js +40 -0
  55. package/dist/flow-matrix.d.ts +44 -0
  56. package/dist/flow-matrix.js +238 -0
  57. package/dist/flow-name-rules.d.ts +15 -0
  58. package/dist/flow-name-rules.js +39 -0
  59. package/dist/flow-runtime.d.ts +52 -22
  60. package/dist/flow-runtime.js +63 -117
  61. package/dist/flow-success.d.ts +3 -0
  62. package/dist/flow-success.js +37 -0
  63. package/dist/flow-tree.d.ts +2 -0
  64. package/dist/flow-tree.js +17 -5
  65. package/dist/flow-wait.d.ts +3 -0
  66. package/dist/flow-wait.js +22 -0
  67. package/dist/index.d.ts +5 -0
  68. package/dist/index.js +5 -0
  69. package/dist/matrix-spec.d.ts +145 -0
  70. package/dist/matrix-spec.js +120 -0
  71. package/dist/page-hide.d.ts +10 -0
  72. package/dist/page-hide.js +45 -0
  73. package/dist/page-settle.d.ts +39 -0
  74. package/dist/page-settle.js +142 -0
  75. package/dist/playwright-driver.d.ts +28 -8
  76. package/dist/playwright-driver.js +73 -28
  77. package/dist/plugins/manifest.d.ts +9 -9
  78. package/dist/run-flows.d.ts +40 -0
  79. package/dist/run-flows.js +129 -0
  80. package/dist/style.d.ts +2 -2
  81. package/dist/upload-path.d.ts +15 -0
  82. package/dist/upload-path.js +63 -0
  83. package/dist/verify-compare.d.ts +43 -0
  84. package/dist/verify-compare.js +237 -0
  85. package/dist/verify-determinism.d.ts +16 -0
  86. package/dist/verify-determinism.js +88 -0
  87. package/dist/verify-report.d.ts +53 -0
  88. package/dist/verify-report.js +141 -0
  89. package/dist/verify-tree.d.ts +27 -0
  90. package/dist/verify-tree.js +95 -0
  91. package/dist/viewer-bin.d.ts +6 -0
  92. package/dist/viewer-bin.js +24 -0
  93. package/dist/zip.d.ts +2 -2
  94. package/package.json +3 -2
@@ -10,13 +10,16 @@ import { promises as fs } from "node:fs";
10
10
  import * as path from "node:path";
11
11
  import { LocalStorageStateCache, makeStrategy, parseAuthStrategyFile, resolveCredsEnv, resolveStateCache, } from "./auth.js";
12
12
  import { calibrate } from "./calibrate.js";
13
- import { FlowFileError, parseFlowFile, resolveFlowExtends } from "./flow-file.js";
13
+ import { expandFlowVariants, FlowFileError, parseFlowFile, resolveFlowExtends, } from "./flow-file.js";
14
+ import { assertNoCaseCollision } from "./flow-name-rules.js";
14
15
  import { recordRunHistory } from "./backend-client.js";
15
- import { runFlow } from "./flow-runtime.js";
16
- import { launchPlaywrightSession } from "./playwright-driver.js";
16
+ import { runFlowsInSessions } from "./run-flows.js";
17
17
  import { PlaywrightInstrumentedBrowser } from "./playwright-instrumented-browser.js";
18
- import { initWorkspace, loadWorkspaceConfig, resolveWorkspacePath, resolveWorkspacePathReal, } from "./workspace.js";
18
+ import { initWorkspace, loadWorkspaceConfig, resolveWorkspacePath } from "./workspace.js";
19
19
  import { listFlowFiles, parseFlags } from "./cli-shared.js";
20
+ import { emitVerifyReport, parseVerifyArgs } from "./cli-verify.js";
21
+ import { verifyDeterminism } from "./verify-determinism.js";
22
+ import { VerifyTreeError } from "./verify-tree.js";
20
23
  import { USAGE } from "./cli-usage.js";
21
24
  async function loadAuthStorageState(projectDir) {
22
25
  const descriptorPath = resolveWorkspacePath(projectDir, "auth", "strategy.yaml");
@@ -48,12 +51,18 @@ export async function cmdRun(args) {
48
51
  const stopAfter = typeof flags.get("stop-after") === "string" ? flags.get("stop-after") : undefined;
49
52
  const startFrom = typeof flags.get("start-from") === "string" ? flags.get("start-from") : undefined;
50
53
  const cdpEndpoint = typeof flags.get("cdp") === "string" ? flags.get("cdp") : undefined;
54
+ const onlyVariant = typeof flags.get("variant") === "string" ? flags.get("variant") : undefined;
51
55
  const pause = flags.get("pause") === true;
52
56
  const headed = flags.get("headed") === true || pause; // --pause implies --headed
53
57
  if (startFrom && !onlyFlow) {
54
58
  process.stderr.write(`run: --start-from requires --flow <name> (single-flow calibration aid)\n`);
55
59
  return 2;
56
60
  }
61
+ const verify = parseVerifyArgs(flags);
62
+ if (typeof verify === "string") {
63
+ process.stderr.write(`run: ${verify}\n\n${USAGE}\n`);
64
+ return 2;
65
+ }
57
66
  const wsCfg = await loadWorkspaceConfig(projectDir);
58
67
  const baseURL = (typeof flags.get("base-url") === "string" ? flags.get("base-url") : undefined) ??
59
68
  wsCfg?.app_url;
@@ -77,12 +86,19 @@ export async function cmdRun(args) {
77
86
  }
78
87
  return parseFlowFile(text, fp);
79
88
  };
89
+ // `flows` goes to the run loop, which expands each matrix flow itself; `units` is the same
90
+ // expansion here, for the checks and messages that need the variant ids before anything launches.
80
91
  const flows = [];
92
+ const units = [];
93
+ const matrixFlows = new Set();
94
+ let flowCount = 0;
81
95
  for (const fp of flowPaths) {
82
96
  let flow;
97
+ let variants;
83
98
  try {
84
99
  const parsed = parseFlowFile(await fs.readFile(fp, "utf8"), fp);
85
100
  flow = parsed.extends ? await resolveFlowExtends(parsed, loadFlowFile) : parsed;
101
+ variants = expandFlowVariants(flow, fp);
86
102
  }
87
103
  catch (e) {
88
104
  if (e instanceof FlowFileError) {
@@ -91,15 +107,48 @@ export async function cmdRun(args) {
91
107
  }
92
108
  throw e;
93
109
  }
94
- if (!onlyFlow || flow.name === onlyFlow)
95
- flows.push(flow);
96
- }
97
- if (flows.length === 0) {
110
+ if (onlyFlow && flow.name !== onlyFlow)
111
+ continue;
112
+ flowCount++;
113
+ flows.push(flow);
114
+ if (flow.matrix)
115
+ matrixFlows.add(flow.name);
116
+ units.push(...variants);
117
+ }
118
+ if (flowCount === 0) {
98
119
  process.stderr.write(onlyFlow
99
120
  ? `run: no flow named "${onlyFlow}"\n`
100
121
  : `run: no flow-files in ${projectDir}/flows\n`);
101
122
  return 1;
102
123
  }
124
+ try {
125
+ assertNoCaseCollision(flows.map((f) => f.name), "flow names");
126
+ }
127
+ catch (e) {
128
+ process.stderr.write(`run: ${e.message}\n`);
129
+ return 1;
130
+ }
131
+ if (cdpEndpoint && matrixFlows.size > 0) {
132
+ process.stderr.write(`run: --cdp attaches to a browser that owns its viewport, color scheme and locale, so it cannot run the matrix of ${[...matrixFlows].join(", ")}\n`);
133
+ return 1;
134
+ }
135
+ if (onlyVariant) {
136
+ const wanted = units.filter((u) => u.id === onlyVariant);
137
+ if (wanted.length === 0) {
138
+ process.stderr.write(`run: no variant "${onlyVariant}" (variants: ${units
139
+ .map((u) => u.id)
140
+ .filter(Boolean)
141
+ .join(", ") || "none, no flow has a matrix"})\n`);
142
+ return 1;
143
+ }
144
+ units.splice(0, units.length, ...wanted);
145
+ }
146
+ for (const name of matrixFlows) {
147
+ const stale = resolveWorkspacePath(projectDir, "docs", name, "annotations.json");
148
+ if (await fs.access(stale).then(() => true, () => false)) {
149
+ process.stderr.write(`run: warning — docs/${name}/annotations.json is from before ${name} had a matrix; its variants write to docs/${name}/<variant>/, so remove the old docs/${name}/ outputs\n`);
150
+ }
151
+ }
103
152
  let storageState;
104
153
  try {
105
154
  storageState = await loadAuthStorageState(projectDir);
@@ -118,101 +167,55 @@ export async function cmdRun(args) {
118
167
  if (forceSingle && requestedConcurrency > 1) {
119
168
  process.stderr.write(`run: --pause / --stop-after / --start-from / --cdp force --concurrency 1 (ignoring --concurrency ${requestedConcurrency})\n`);
120
169
  }
121
- const tag = concurrency > 1 ? (name) => `run [${name}]: ` : () => "run: ";
122
- async function runOne(flow) {
123
- const name = flow.name;
124
- let session;
125
- try {
126
- // When attaching to an existing Chrome via --cdp, the operator owns its auth state — don't
127
- // load cached `storageState` over it (would replace cookies). When launching fresh, do.
128
- session = await launchPlaywrightSession({
129
- baseURL,
130
- headed,
131
- ignoreHTTPSErrors,
132
- ...(cdpEndpoint ? { connectOverCdp: cdpEndpoint } : { storageState }),
133
- ...(flow.environment ? { environment: flow.environment } : {}),
134
- docPackRoot: projectDir,
135
- });
136
- }
137
- catch (e) {
138
- const msg = e.message;
139
- if (/Executable doesn't exist|browserType\.launch|playwright install/i.test(msg)) {
140
- process.stderr.write(`${tag(name)}no Chromium binary found. Install one: npx playwright-core install chromium (source checkout: pnpm -C packages/engine exec playwright-core install chromium)\n`);
141
- }
142
- else {
143
- process.stderr.write(`${tag(name)}failed to launch browser: ${msg}\n`);
144
- }
145
- return false;
146
- }
170
+ const noun = matrixFlows.size > 0 ? "flow variants" : "flows";
171
+ const runOptions = {
172
+ projectDir,
173
+ flows,
174
+ variant: onlyVariant,
175
+ storageState,
176
+ baseURL,
177
+ headed,
178
+ ignoreHTTPSErrors,
179
+ cdpEndpoint,
180
+ stopAfter,
181
+ startFrom,
182
+ obstacles: wsCfg?.annotations?.obstacles === true,
183
+ concurrency,
184
+ };
185
+ // Verification runs the same loop N times into isolated roots and prints the report on stdout, so
186
+ // its progress lines go to stderr.
187
+ if (verify) {
147
188
  try {
148
- const result = await runFlow(flow, session.driver, {
149
- resolveLocator: (n) => flow.locators[n],
150
- ...(stopAfter ? { stopAfter } : {}),
151
- ...(startFrom ? { startFrom } : {}),
152
- ...(wsCfg?.annotations?.obstacles === true ? { obstacles: true } : {}),
189
+ const report = await verifyDeterminism({
190
+ ...runOptions,
191
+ runs: verify.runs,
192
+ progress: (line) => process.stderr.write(line),
153
193
  });
154
- await fs.mkdir(resolveWorkspacePath(projectDir, "docs", flow.name), { recursive: true });
155
- // Flow names come from the flow-files — resolve the write target symlink-aware.
156
- const annotationsPath = await resolveWorkspacePathReal(projectDir, "docs", flow.name, "annotations.json");
157
- // With `startFrom`, only the post-startFrom steps emit annotations — merge them into the
158
- // existing file (if any) by step id so the prior steps' annotations stay in place. Same
159
- // story for screenshots (they live as separate PNGs and are simply not re-captured).
160
- let toWrite = result.annotations;
161
- if (startFrom) {
162
- try {
163
- const existingText = await fs.readFile(annotationsPath, "utf8");
164
- const existing = JSON.parse(existingText);
165
- const newStepIds = new Set(result.annotations.annotations.map((a) => a.step));
166
- const merged = [
167
- ...existing.annotations.filter((a) => !newStepIds.has(a.step)),
168
- ...result.annotations.annotations,
169
- ];
170
- toWrite = { ...result.annotations, annotations: merged };
171
- }
172
- catch {
173
- // No existing file (or unreadable) — just write what we have.
174
- }
175
- }
176
- await fs.writeFile(annotationsPath, JSON.stringify(toWrite, null, 2) + "\n", "utf8");
177
- process.stdout.write(`${tag(name)}${name} — ${result.steps.length} step(s) executed, ${result.annotations.annotations.length} annotation(s) ${startFrom ? "merged" : "written"}\n`);
178
- return true;
194
+ return emitVerifyReport(report, verify.format);
179
195
  }
180
196
  catch (e) {
181
- process.stderr.write(`${tag(name)}${e.message}\n`);
182
- return false;
183
- }
184
- finally {
185
- if (pause) {
186
- process.stdout.write("run: --pause — browser is open at the last step run; close it to exit.\n");
187
- await new Promise((resolve) => session.browser.on("disconnected", () => resolve()));
197
+ if (e instanceof VerifyTreeError) {
198
+ process.stderr.write(`run: --verify-determinism: ${e.message}\n`);
199
+ return 1;
188
200
  }
189
- await session.close();
201
+ throw e;
190
202
  }
191
203
  }
192
- let idx = 0;
193
- let anyFailed = false;
194
- let okCount = 0;
195
204
  const startedAt = Date.now();
196
- async function worker() {
197
- while (idx < flows.length) {
198
- const flow = flows[idx++];
199
- if (await runOne(flow))
200
- okCount++;
201
- else
202
- anyFailed = true;
203
- }
204
- }
205
- const workers = Math.min(concurrency, flows.length);
206
- if (workers > 1)
207
- process.stdout.write(`run: running ${flows.length} flows with ${workers} parallel worker(s)…\n`);
208
- await Promise.all(Array.from({ length: workers }, () => worker()));
205
+ const { okCount, failures } = await runFlowsInSessions({
206
+ ...runOptions,
207
+ outputRoot: projectDir,
208
+ pause,
209
+ progress: (line) => process.stdout.write(line),
210
+ });
211
+ const anyFailed = failures.length > 0;
209
212
  // Backend-bound workspaces get a run record appended; offline-tolerant (warn, never fail the run).
210
213
  const history = await recordRunHistory({
211
214
  workspaceDir: projectDir,
212
215
  config: wsCfg ?? {},
213
216
  ok: !anyFailed,
214
217
  durationMs: Date.now() - startedAt,
215
- summary: `${okCount}/${flows.length} flows ok`,
218
+ summary: `${okCount}/${units.length} ${noun} ok`,
216
219
  });
217
220
  if (history.warning)
218
221
  process.stderr.write(`run: warning — ${history.warning}\n`);
@@ -0,0 +1,6 @@
1
+ import { type RetiredEntry } from "./deprecation.js";
2
+ export interface RetiredCommand extends RetiredEntry {
3
+ /** The argv of the replacement command, from the arguments the retired one was given. */
4
+ rewrite(args: string[]): string[];
5
+ }
6
+ export declare const RETIRED_COMMANDS: Readonly<Record<string, RetiredCommand>>;
@@ -0,0 +1,12 @@
1
+ // CLI commands that were valid and are retired. `main` looks a command up here before it
2
+ // dispatches: a retired command prints one deprecation warning and runs its replacement, so a
3
+ // script that still calls it keeps working for the deprecation window. Retired commands are not
4
+ // listed in `--help`.
5
+ export const RETIRED_COMMANDS = {
6
+ drift: {
7
+ since: "0.3.0",
8
+ replacement: "`docsxai pack --check`",
9
+ note: "same flags, `--check` added",
10
+ rewrite: (args) => ["pack", ...args, "--check"],
11
+ },
12
+ };
@@ -1 +1 @@
1
- export declare const USAGE = "docsxai \u2014 deterministic execution CLI\n\nUsage:\n docsxai init <workspace-dir> [--app-url <url>] [--auth manual-capture|none] [--role <name>] [--ttl <dur>]\n [--capture-trigger console|button] [--auth-cookie <name>] [--ignore-https-errors]\n [--persist tmp] [--force]\n docsxai calibrate <workspace-dir> --from <flow.md|.yaml> [--name <flow>]\n docsxai inspect <workspace-dir> [--url <url>] [--selector <css>] [--cdp <endpoint>] [--wait <ms>] [--wait-for <css>] [--headed] [--role <role>]\n docsxai run <workspace-dir> [--flow <name>] [--base-url <url>] [--headed] [--ignore-https-errors] [--stop-after <step-id>] [--start-from <step-id>] [--cdp <endpoint>] [--pause] [--concurrency <N>]\n docsxai lint <workspace-dir> [--flow <name>] [--format text|json]\n docsxai flow-tree <workspace-dir> [--format text|json]\n docsxai diagnose <workspace-dir> --flow <name> --step <step-id> [--cdp <endpoint>] [--format text|json]\n docsxai doctor [<workspace-dir>]\n docsxai style <workspace-dir> [--check] [--format text|json]\n docsxai zip <workspace-dir> [--out <output.zip>] [--include-viewer]\n docsxai baseline <workspace-dir> [--out <dir>]\n docsxai diff <workspace-dir> [--against <dir>] [--format json|md|text] [--fail-on warn|fail]\n docsxai export adf <workspace-dir> [--flow <name>] [--mode single|page-tree] [--title <text>] [--out <dir>]\n docsxai export playwright <workspace-dir> [--flow <name>] [--out <dir>]\n docsxai plugins <list|info|sync> <workspace-dir> [<namespace>] [--format text|json]\n docsxai login --backend-url <url>\n docsxai push <workspace-dir> [--kind calibrate|run|edit] [--author <name>]\n docsxai pull <workspace-dir> [--rev <id>]\n docsxai render <workspace-dir>\n docsxai capture-auth <workspace-dir> [--base-url <url>] [--role <role>] [--auth-cookie <name>] [--cdp <endpoint>] [--fresh] [--headless] [--ignore-https-errors]\n docsxai --help\n\nNotes:\n \u2022 A *workspace* (created by `init`) holds flows/<flow>.flow.yaml, docs/, auth/strategy.yaml, .auth/, .viewer/,\n and a .docsxai.json config. Put it OUTSIDE the app's source repo \u2014 docsxai documents a running app from\n outside and never writes into the app repo.\n \u2022 run / capture-auth read app_url + ignore_https_errors from .docsxai.json if you don't pass the flags.\n \u2022 run launches Chromium; if no browser binary is present, install one: npx playwright-core install chromium\n (source checkout: pnpm -C packages/engine exec playwright-core install chromium)\n \u2022 --ignore-https-errors accepts self-signed/invalid TLS (e.g. an app's local HTTPS dev cert)\n \u2022 run --stop-after <step-id> runs only a prefix of the flow (up to & incl. that step); --pause keeps the\n (headed) browser open at the last step run \u2014 so you can inspect the live state mid-flow when calibrating\n (pair with --flow <name>). For waiting on a slow backend op, give a step a wait_for of the form\n { selector: $x, timeout_ms: 180000 } \u2014 a per-step override of the default ~30s selector-wait timeout.\n \u2022 run --concurrency <N> runs up to N flows in parallel (each its own Chromium session, isolated; default 1).\n Useful when several flows share a long preamble \u2014 total wall time = max(per-flow), not sum. Force-clamped\n to 1 when --pause / --stop-after / --start-from / --cdp is set. The target app must tolerate multiple sessions from one user.\n \u2022 run --start-from <step-id> --flow <name> SKIPS every step before <step-id> and starts execution there \u2014\n the inverse of --stop-after. Pair with --cdp to attach to a Chrome that's already in the post-prior-steps\n state (e.g. left over from a paused previous run) and iterate on the new tail step in seconds rather\n than re-walking the whole extends chain. New annotations MERGE into the existing annotations.json by\n step id; the prior steps' annotations and screenshots are preserved.\n \u2022 run --cdp <endpoint> attaches to a running Chrome (start it with --remote-debugging-port=N) instead of\n launching one. docsxai won't close that Chrome. When --cdp is set, the cached storageState is NOT\n loaded into the context \u2014 the operator's Chrome owns its auth state. Useful with --start-from for the\n sub-3-sec iteration loop on long-async flows.\n \u2022 capture-auth runs the role's auth strategy (MVP: manual-capture \u2014 a headed, instrumented browser the\n engineer logs into; window.__docsxai.capture() or an injected button snapshots the session) and caches\n it to <workspace-dir>/.auth/<role>.json for subsequent `run`s. It prints the captured cookie jar so you\n can identify the app's real auth/session cookie.\n \u2022 capture-auth keeps a persistent Chrome profile at <workspace>/.auth/chrome-profile/ (gitignored) \u2014 re-running\n it reuses the login (just trigger capture again). Use --fresh for a clean profile (forces a fresh login).\n \u2022 --cdp <endpoint> makes capture-auth *attach to an already-running Chrome* (start it with\n --remote-debugging-port=N --disable-web-security --user-data-dir=<dir>) instead of launching a fresh one \u2014\n use this to capture from the same Chrome the engineer is already logged into (and that Claude in Chrome is\n driving for discovery), so they don't log in twice. docsxai won't close that Chrome. (--cdp ignores --fresh.)\n \u2022 auth_cookie (set via `init --auth-cookie`, `capture-auth --auth-cookie`, or hand-edited into\n auth/strategy.yaml) names that cookie; when set, the cached session's expiry tracks *that* cookie's\n expiry rather than the `ttl` guess (an interactive SSO login leaves ephemeral IdP scratch cookies, so\n `min(cookie.expires)` \u2248 now \u2014 don't rely on it). If unset/unfound, `ttl` (or a 1h default) is used.\n \u2022 inspect opens the app in a headless (or --headed) browser *with the cached session loaded* and prints the\n page's [data-testid] elements (or, with --selector, matching elements' HTML) \u2014 for pinning locators when\n hand-authoring a flow-file (the captured session can't be replayed in a browser the agent's MCP controls\n because the auth cookie is usually httpOnly; inspect does the storageState\u2192Playwright bridge for you). On a\n slow SPA, settle before the snapshot with --wait <ms> (default 800) or --wait-for '<css>'. --cdp <endpoint>\n attaches to an already-running Chrome (e.g. the one from capture-auth --cdp) instead of launching one.\n \u2022 calibrate takes a *structured flow-guide* (a flow-file in YAML, or a .md with a yaml fenced block) and\n writes flows/<name>.flow.yaml + a default docs/style.yaml. Loose-prose descriptions / live element-picking\n need the host agent \u2014 that's the /docsxai:calibrate *skill* (see the plugin), which then refines/produces\n the flow-file; this CLI command covers only the deterministic structured-input case.\n \u2022 lint runs pure-static checks across the workspace's flow-files \u2014 no Playwright, no live page. Rules:\n R001 (deep extends chain), R002 (annotation anchored to a likely-unmounting click/navigate target \u2014\n suggest annotation.target override), R003 (wait_for with no timeout_ms on a long-async-looking step),\n R004 (bare [data-*=\u2026] selector \u2014 may have hidden duplicates; suggest :visible / :has-text qualifier).\n Exit 1 if any warning/error; 0 otherwise. --format json emits machine-readable output for tooling.\n \u2022 flow-tree prints the workspace's extends graph (root flows + their descendants), plus any orphans\n (flows whose extends parent isn't in the workspace) and resolution issues (cycles / step-id collisions\n across the merge). Pure-static, ~no I/O beyond reading the flow files. Exit 1 if any issues.\n \u2022 diagnose gathers halt context for a specific step (the step's selector/wait_for/success, the halt\n screenshot if one exists, and \u2014 with --cdp \u2014 a live actionable() probe of the target on the running\n page) and prints recommendations (selector / wait_for / success / annotation_target / split_step /\n investigate). The engine never patches the flow-file itself \u2014 that's the agent's explicit opt-in\n action. --format json emits machine-readable output for an agent to act on. Pair with\n --start-from <step-id> --cdp on a follow-up run to validate the fix in seconds.\n \u2022 doctor health-checks the environment + workspace: Node >= 26, Chromium presence, .docsxai.json\n found + parseable (cwd or the arg), flow-file parses, auth descriptor + cached-session freshness,\n backend reachability (when backend_url is set), the plugin declarations (same inspection as\n `plugins list` \u2014 no plugin code is executed), viewer-bin resolution (which of the three layers\n hit), and DOCSX_* env sanity. \u2713/\u2717 rows with a one-line fix per failure; \u2212 rows are informational\n and never fail. Exit 1 if any \u2717.\n \u2022 style initialises docs/style.yaml + derived docs/style.json if absent (otherwise validates the\n existing YAML against the schema and rederives the JSON). --check additionally scans every\n docs/<flow>/<step>.md user-facing write-up for jargon leaks against the style's pruning_rules\n (e.g. VERIFY / WAIT / data-testid leaking into user-facing prose). The engine never re-shapes\n prose itself (LLM-agnostic) \u2014 the agent does that at calibration time; this command is the\n enforcement layer for the semantic-reshape exit criterion. --format json emits machine-readable\n output for tooling.\n \u2022 zip packages the workspace's doc pack into a single archive for hand-off. Includes flows/, docs/,\n .docsxai.json, auth/strategy.yaml (env-var names only, no creds), README.md. Excludes .auth/\n (operator-local session state), **/halts/ (debug screenshots), .viewer/ by default (re-renderable\n from the doc pack; pass --include-viewer to bundle it). Defaults output to <workspace-name>.zip\n in the current dir; override with --out <path>. Zips in-process (no system 'zip' binary needed)\n and deterministically \u2014 sorted entries, fixed mtime, fixed compression \u2014 so the same doc pack\n always produces a byte-identical archive.\n \u2022 baseline snapshots the doc pack \u2014 flows/, docs/<flow>/*.md, annotations.json, screenshots/, and\n docs/locators.yaml \u2014 into <ws>/.baseline/ (or --out <dir>). Commit the baseline: it's the \"before\"\n that diff compares against in CI.\n \u2022 diff compares the workspace against a baseline (default <ws>/.baseline/, or --against <dir>) and\n emits a deterministic drift report: per flow, step field deltas (id-keyed), annotation moves,\n screenshot pixel diffs (changed-pixel count / % / changed-region bbox; dimension changes flagged\n distinctly), prose line-change counts, and locator changes. --format md is PR-comment-ready.\n --fail-on warn|fail exits 1 when the report severity is at/above the threshold (screenshot\n severity: \u22651% changed pixels = warn, \u22655% = fail; structural changes = warn).\n \u2022 export playwright emits one self-contained Playwright .spec.ts per flow (extends resolved) into\n <ws>/.export/tests/ (or --out <dir>) \u2014 locators as consts, steps as page actions, success criteria\n as expect() assertions, environment as test.use(); optional steps are try/catch-wrapped. Generated\n files say so in a header: regenerate, don't hand-edit.\n \u2022 render builds the static viewer by spawning the docsxai-viewer bin, resolved in order: the\n DOCSX_VIEWER_BIN env var (path to the viewer's bin script), the @docsxai/viewer\n package installed next to the engine, then `docsxai-viewer` on PATH.\n \u2022 login validates a bearer token against a backend URL \u2014 hits /v1/health, /v1/workspaces. Reads\n the token from DOCSX_TOKEN env var. Prints what the backend sees if the call succeeds,\n or a clear error if not. Stateless: doesn't store anything; configure the env var in your shell.\n \u2022 push serialises the workspace's doc pack (flows + annotations + screenshots + style + locators)\n and POSTs it as a new revision against the backend named in .docsxai.json (backend_url +\n optionally backend_workspace_id / backend_project_id; created on first push if absent and\n persisted to the config). --kind defaults to \"calibrate\"; --author defaults to the OS user.\n \u2022 pull fetches a revision's artifacts back into the workspace files (default: HEAD). Useful for\n syncing with a different operator's edits or rolling back to a named revision.";
1
+ export declare const USAGE = "docsxai \u2014 deterministic execution CLI\n\nUsage:\n docsxai init <workspace-dir> [--app-url <url>] [--auth manual-capture|none] [--role <name>] [--ttl <dur>]\n [--capture-trigger console|button] [--auth-cookie <name>] [--ignore-https-errors]\n [--persist tmp] [--force]\n docsxai calibrate <workspace-dir> --from <flow.md|.yaml> [--name <flow>]\n docsxai inspect <workspace-dir> [--url <url>] [--selector <css>] [--cdp <endpoint>] [--wait <ms>] [--wait-for <css>] [--headed] [--ignore-https-errors] [--role <role>]\n docsxai run <workspace-dir> [--flow <name>] [--base-url <url>] [--headed] [--ignore-https-errors] [--stop-after <step-id>] [--start-from <step-id>] [--variant <id>] [--cdp <endpoint>] [--pause] [--concurrency <N>]\n docsxai run <workspace-dir> --verify-determinism [--runs <2-5>] [--format json|md|text] [--flow <name>] [--base-url <url>] [--concurrency <N>]\n docsxai lint <workspace-dir> [--flow <name>] [--format text|json]\n docsxai flow-tree <workspace-dir> [--format text|json]\n docsxai diagnose <workspace-dir> --flow <name> --step <step-id> [--variant <id>] [--cdp <endpoint>] [--format text|json]\n docsxai doctor [<workspace-dir>]\n docsxai style <workspace-dir> [--check] [--format text|json]\n docsxai zip <workspace-dir> [--out <output.zip>] [--include-viewer]\n docsxai baseline <workspace-dir> [--out <dir>]\n docsxai diff <workspace-dir> [--against <dir>] [--format json|md|text] [--fail-on warn|fail]\n docsxai export adf <workspace-dir> [--flow <name>] [--mode single|page-tree] [--title <text>] [--out <dir>]\n docsxai export playwright <workspace-dir> [--flow <name>] [--out <dir>]\n docsxai plugins <list|info|sync> <workspace-dir> [<namespace>] [--format text|json]\n docsxai login --backend-url <url> [--oauth <workspace-dir>]\n docsxai push <workspace-dir> [--kind calibrate|run|edit] [--author <name>]\n docsxai pull <workspace-dir> [--rev <id>]\n docsxai render <workspace-dir>\n docsxai burn <workspace-dir> [--flow <name>] [--out <dir>] [--report <file>] [--no-connector-outline]\n docsxai pack <workspace-or-raw-dir> [--from-raw] [--out <dir>] [--public-prefix <path>] [--no-optimise] [--generated-for <text>]\n docsxai pack <workspace-or-raw-dir> --check --against <pack-dir> [--from-raw] [--threshold <pct>]\n docsxai capture-auth <workspace-dir> [--base-url <url>] [--role <role>] [--auth-cookie <name>] [--cdp <endpoint>] [--fresh] [--headless] [--ignore-https-errors]\n docsxai --help\n\nNotes:\n \u2022 A *workspace* (created by `init`) holds flows/<flow>.flow.yaml, docs/, auth/strategy.yaml, .auth/, .viewer/,\n and a .docsxai.json config. Put it OUTSIDE the app's source repo \u2014 docsxai documents a running app from\n outside and never writes into the app repo.\n \u2022 run / capture-auth read app_url + ignore_https_errors from .docsxai.json if you don't pass the flags.\n \u2022 run launches Chromium; if no browser binary is present, install one: npx playwright-core install chromium\n (source checkout: pnpm -C packages/engine exec playwright-core install chromium)\n \u2022 --ignore-https-errors accepts self-signed/invalid TLS (e.g. an app's local HTTPS dev cert)\n \u2022 run --stop-after <step-id> runs only a prefix of the flow (up to & incl. that step); --pause keeps the\n (headed) browser open at the last step run \u2014 so you can inspect the live state mid-flow when calibrating\n (pair with --flow <name>). For waiting on a slow backend op, give a step a wait_for of the form\n { selector: $x, timeout_ms: 180000 } \u2014 a per-step override of the default ~30s selector-wait timeout.\n For a page that settles late (web fonts swapping, images arriving), use wait_for: settled: it waits for\n fonts, the images in view and the layout of what's on screen to stop changing, within the step's\n timeout_ms (default 10s), and halts with the cause if the page never settles.\n \u2022 run --concurrency <N> runs up to N flows in parallel (each its own Chromium session, isolated; default 1).\n Useful when several flows share a long preamble \u2014 total wall time = max(per-flow), not sum. Force-clamped\n to 1 when --pause / --stop-after / --start-from / --cdp is set. The target app must tolerate multiple sessions from one user.\n \u2022 run --start-from <step-id> --flow <name> SKIPS every step before <step-id> and starts execution there \u2014\n the inverse of --stop-after. Pair with --cdp to attach to a Chrome that's already in the post-prior-steps\n state (e.g. left over from a paused previous run) and iterate on the new tail step in seconds rather\n than re-walking the whole extends chain. New annotations MERGE into the existing annotations.json by\n step id; the prior steps' annotations and screenshots are preserved.\n \u2022 A flow with a top-level `matrix:` (locales, color_schemes, viewports) expands into one variant per\n combination. run gives each variant its own Chromium session and writes docs/<flow>/<variant>/\n {screenshots/, annotations.json, halts/} (variant id: <locale>.<scheme>.<viewport>, axes the matrix\n leaves out are dropped). run --variant <id> runs one variant. lint lists the variants (R015), flow-tree\n prints them, diagnose --variant <id> picks one. --cdp cannot run a matrix flow.\n \u2022 run --cdp <endpoint> attaches to a running Chrome (start it with --remote-debugging-port=N) instead of\n launching one. docsxai won't close that Chrome. When --cdp is set, the cached storageState is NOT\n loaded into the context \u2014 the operator's Chrome owns its auth state. Useful with --start-from for the\n sub-3-sec iteration loop on long-async flows.\n \u2022 run --verify-determinism runs the selected flows N times (--runs, 2 to 5, default 2), each into its own\n root under <ws>/.docsxai-verify/run-<k>/, then byte-compares every artefact: annotations.json, screenshots,\n step markdown, locators, halt context. The workspace output is written only when every run agrees (run 1's\n files are copied in, the bytes a plain run writes); on any difference or halt it is left untouched. The run\n roots are removed at the end. The report goes to stdout (--format text|md|json, default text; progress goes to\n stderr) and names the first differing artefact by path with a cause: the JSON key path, the changed-pixel\n region of a PNG, the first differing line of text, or the sizes. Exit 0 identical, 1 differing or a flow\n halted, 2 bad flags. Not combinable with --pause / --stop-after / --start-from / --cdp.\n \u2022 capture-auth runs the role's auth strategy (MVP: manual-capture \u2014 a headed, instrumented browser the\n engineer logs into; window.__docsxai.capture() or an injected button snapshots the session) and caches\n it to <workspace-dir>/.auth/<role>.json for subsequent `run`s. It prints the captured cookie jar so you\n can identify the app's real auth/session cookie.\n \u2022 capture-auth keeps a persistent Chrome profile at <workspace>/.auth/chrome-profile/ (gitignored) \u2014 re-running\n it reuses the login (just trigger capture again). Use --fresh for a clean profile (forces a fresh login).\n \u2022 --cdp <endpoint> makes capture-auth *attach to an already-running Chrome* (start it with\n --remote-debugging-port=N --disable-web-security --user-data-dir=<dir>) instead of launching a fresh one \u2014\n use this to capture from the same Chrome the engineer is already logged into (and that Claude in Chrome is\n driving for discovery), so they don't log in twice. docsxai won't close that Chrome. (--cdp ignores --fresh.)\n \u2022 auth_cookie (set via `init --auth-cookie`, `capture-auth --auth-cookie`, or hand-edited into\n auth/strategy.yaml) names that cookie; when set, the cached session's expiry tracks *that* cookie's\n expiry rather than the `ttl` guess (an interactive SSO login leaves ephemeral IdP scratch cookies, so\n `min(cookie.expires)` \u2248 now \u2014 don't rely on it). If unset/unfound, `ttl` (or a 1h default) is used.\n \u2022 inspect opens the app in a headless (or --headed) browser *with the cached session loaded* and prints the\n page's [data-testid] elements (or, with --selector, matching elements' HTML) \u2014 for pinning locators when\n hand-authoring a flow-file (the captured session can't be replayed in a browser the agent's MCP controls\n because the auth cookie is usually httpOnly; inspect does the storageState\u2192Playwright bridge for you). On a\n slow SPA, settle before the snapshot with --wait <ms> (default 800) or --wait-for '<css>'. --cdp <endpoint>\n attaches to an already-running Chrome (e.g. the one from capture-auth --cdp) instead of launching one.\n --ignore-https-errors accepts a self-signed/invalid TLS certificate (also read from ignore_https_errors in .docsxai.json).\n \u2022 calibrate takes a *structured flow-guide* (a flow-file in YAML, or a .md with a yaml fenced block) and\n writes flows/<name>.flow.yaml + a default docs/style.yaml. Loose-prose descriptions / live element-picking\n need the host agent \u2014 that's the /docsxai:calibrate *skill* (see the plugin), which then refines/produces\n the flow-file; this CLI command covers only the deterministic structured-input case.\n \u2022 lint runs pure-static checks across the workspace's flow-files \u2014 no Playwright, no live page. Rules:\n R001 (deep extends chain), R002 (annotation anchored to a likely-unmounting click/navigate target \u2014\n suggest annotation.target override), R003 (wait_for with no timeout_ms on a long-async-looking step),\n R004 (bare [data-*=\u2026] selector \u2014 may have hidden duplicates; suggest :visible / :has-text qualifier).\n Exit 1 if any warning/error; 0 otherwise. --format json emits machine-readable output for tooling.\n \u2022 flow-tree prints the workspace's extends graph (root flows + their descendants), plus any orphans\n (flows whose extends parent isn't in the workspace) and resolution issues (cycles / step-id collisions\n across the merge). Pure-static, ~no I/O beyond reading the flow files. Exit 1 if any issues.\n \u2022 diagnose gathers halt context for a specific step (the step's selector/wait_for/success, the halt\n screenshot if one exists, and \u2014 with --cdp \u2014 a live actionable() probe of the target on the running\n page) and prints recommendations (selector / wait_for / success / annotation_target / split_step /\n investigate). The engine never patches the flow-file itself \u2014 that's the agent's explicit opt-in\n action. --format json emits machine-readable output for an agent to act on. Pair with\n --start-from <step-id> --cdp on a follow-up run to validate the fix in seconds.\n \u2022 doctor health-checks the environment + workspace: Node >= 26, Chromium presence, .docsxai.json\n found + parseable (cwd or the arg), flow-file parses, auth descriptor + cached-session freshness,\n backend reachability (when backend_url is set), the plugin declarations (same inspection as\n `plugins list` \u2014 no plugin code is executed), viewer-bin resolution (which of the three layers\n hit), and DOCSX_* env sanity. \u2713/\u2717 rows with a one-line fix per failure; \u2212 rows are informational\n and never fail. Exit 1 if any \u2717.\n \u2022 style initialises docs/style.yaml + derived docs/style.json if absent (otherwise validates the\n existing YAML against the schema and rederives the JSON). --check additionally scans every\n docs/<flow>/<step>.md user-facing write-up for jargon leaks against the style's pruning_rules\n (e.g. VERIFY / WAIT / data-testid leaking into user-facing prose). The engine never re-shapes\n prose itself (LLM-agnostic) \u2014 the agent does that at calibration time; this command is the\n enforcement layer for the semantic-reshape exit criterion. --format json emits machine-readable\n output for tooling.\n \u2022 zip packages the workspace's doc pack into a single archive for hand-off. Includes flows/, docs/,\n .docsxai.json, auth/strategy.yaml (env-var names only, no creds), README.md. Excludes .auth/\n (operator-local session state), **/halts/ (debug screenshots), .viewer/ by default (re-renderable\n from the doc pack; pass --include-viewer to bundle it). Defaults output to <workspace-name>.zip\n in the current dir; override with --out <path>. Zips in-process (no system 'zip' binary needed)\n and deterministically \u2014 sorted entries, fixed mtime, fixed compression \u2014 so the same doc pack\n always produces a byte-identical archive.\n \u2022 baseline snapshots the doc pack \u2014 flows/, docs/<flow>/*.md, annotations.json, screenshots/, and\n docs/locators.yaml \u2014 into <ws>/.baseline/ (or --out <dir>). Commit the baseline: it's the \"before\"\n that diff compares against in CI.\n \u2022 diff compares the workspace against a baseline (default <ws>/.baseline/, or --against <dir>) and\n emits a deterministic drift report: per flow, step field deltas (id-keyed), annotation moves,\n screenshot pixel diffs (changed-pixel count / % / changed-region bbox; dimension changes flagged\n distinctly), prose line-change counts, and locator changes. --format md is PR-comment-ready.\n --fail-on warn|fail exits 1 when the report severity is at/above the threshold (screenshot\n severity: \u22651% changed pixels = warn, \u22655% = fail; structural changes = warn).\n \u2022 export playwright emits one self-contained Playwright .spec.ts per flow (extends resolved) into\n <ws>/.export/tests/ (or --out <dir>) \u2014 locators as consts, steps as page actions, success criteria\n as expect() assertions, environment as test.use(); optional steps are try/catch-wrapped. Generated\n files say so in a header: regenerate, don't hand-edit.\n \u2022 render builds the static viewer by spawning the docsxai-viewer bin, resolved in order: the\n DOCSX_VIEWER_BIN env var (path to the viewer's bin script), the @docsxai/viewer\n package installed next to the engine, then `docsxai-viewer` on PATH.\n \u2022 burn bakes each flow's annotations (halo, badge, callout) into copies of its clean screenshots, for\n surfaces that can't run the interactive viewer, via the same viewer bin as render. Reads\n <ws>/docs/<flow>/annotations.json and writes docs/<flow>/burned/<step>.png (or <out>/<flow>/<step>.png\n with --out). --flow limits it to named flows (repeatable); the default is every flow with annotations.\n --report <file> writes a JSON placement report (callout and badge boxes, overlaps, callouts flagged\n unplaceable), resolved under the workspace when relative. --no-connector-outline keeps every arrow and\n stem plain ink; by default one over a dark part of the screenshot gets a white outline.\n \u2022 pack builds the screenshot pack a docs site or README ships: it burns each step's annotations into its\n clean screenshot, optimises the PNG losslessly with the external `oxipng` binary (on PATH, or\n $DOCSX_OXIPNG_BIN; `brew install oxipng`; --no-optimise skips it), names it\n <flow>/<step>.<hash8>.png from the final bytes, and writes manifest.json (docsxai/screens-pack@2: flows,\n steps, localised alt, variants keyed <locale>.<theme>.<viewport> with src, size and callouts). <dir> is a\n workspace (docs/ plus a pack.json naming which capture flow feeds which variant, and the alt text) or,\n with --from-raw or no docs/, a raw capture directory (<flow>/<step>/<locale>.<theme>.<viewport>.png with a\n .json sidecar, step.json and flow.json). --out defaults to <workspace>/.screens and is required for a raw\n directory. Files the previous manifest listed and the new one does not are deleted by exact path; nothing\n else in --out is touched. Loopback and private-network addresses, emails, non-Bearer Authorization headers,\n URL-query tokens and obvious secrets in alt, caption, title or callout text stop the build. Runs the\n viewer's `pack` through the same bin resolution as render.\n \u2022 pack --check rebuilds the pack in memory (no oxipng, nothing written) and compares it with the committed pack\n in --against (required): equal hash is unchanged, otherwise a pixel diff gives changed %, the changed region and\n a pass or fail against --threshold (default 0.5). A resized, new or missing variant, or a committed file\n that does not match its name, always fails. Exit 1 on any failure, 2 on a bad argument. The report has no\n timestamps. The old `docsxai drift` still works for now: it prints a deprecation warning and runs pack --check.\n \u2022 login validates a bearer token against a backend URL \u2014 hits /v1/health, /v1/workspaces. Reads\n the token from DOCSX_TOKEN env var. Prints what the backend sees if the call succeeds,\n or a clear error if not. Stateless: doesn't store anything; configure the env var in your shell.\n login --oauth <workspace-dir> instead signs in as a person: OAuth 2.1 authorization code + PKCE against\n the backend. It prints a URL to open in a browser and stores the tokens at\n <workspace-dir>/.auth/backend-token.json (mode 0600); push, pull and run read them from there.\n \u2022 push serialises the workspace's doc pack (flows + annotations + screenshots + style + locators)\n and POSTs it as a new revision against the backend named in .docsxai.json (backend_url +\n optionally backend_workspace_id / backend_project_id; created on first push if absent and\n persisted to the config). --kind defaults to \"calibrate\"; --author defaults to the OS user.\n \u2022 pull fetches a revision's artifacts back into the workspace files (default: HEAD). Useful for\n syncing with a different operator's edits or rolling back to a named revision.";
package/dist/cli-usage.js CHANGED
@@ -8,11 +8,12 @@ Usage:
8
8
  [--capture-trigger console|button] [--auth-cookie <name>] [--ignore-https-errors]
9
9
  [--persist tmp] [--force]
10
10
  docsxai calibrate <workspace-dir> --from <flow.md|.yaml> [--name <flow>]
11
- docsxai inspect <workspace-dir> [--url <url>] [--selector <css>] [--cdp <endpoint>] [--wait <ms>] [--wait-for <css>] [--headed] [--role <role>]
12
- docsxai run <workspace-dir> [--flow <name>] [--base-url <url>] [--headed] [--ignore-https-errors] [--stop-after <step-id>] [--start-from <step-id>] [--cdp <endpoint>] [--pause] [--concurrency <N>]
11
+ docsxai inspect <workspace-dir> [--url <url>] [--selector <css>] [--cdp <endpoint>] [--wait <ms>] [--wait-for <css>] [--headed] [--ignore-https-errors] [--role <role>]
12
+ docsxai run <workspace-dir> [--flow <name>] [--base-url <url>] [--headed] [--ignore-https-errors] [--stop-after <step-id>] [--start-from <step-id>] [--variant <id>] [--cdp <endpoint>] [--pause] [--concurrency <N>]
13
+ docsxai run <workspace-dir> --verify-determinism [--runs <2-5>] [--format json|md|text] [--flow <name>] [--base-url <url>] [--concurrency <N>]
13
14
  docsxai lint <workspace-dir> [--flow <name>] [--format text|json]
14
15
  docsxai flow-tree <workspace-dir> [--format text|json]
15
- docsxai diagnose <workspace-dir> --flow <name> --step <step-id> [--cdp <endpoint>] [--format text|json]
16
+ docsxai diagnose <workspace-dir> --flow <name> --step <step-id> [--variant <id>] [--cdp <endpoint>] [--format text|json]
16
17
  docsxai doctor [<workspace-dir>]
17
18
  docsxai style <workspace-dir> [--check] [--format text|json]
18
19
  docsxai zip <workspace-dir> [--out <output.zip>] [--include-viewer]
@@ -21,10 +22,13 @@ Usage:
21
22
  docsxai export adf <workspace-dir> [--flow <name>] [--mode single|page-tree] [--title <text>] [--out <dir>]
22
23
  docsxai export playwright <workspace-dir> [--flow <name>] [--out <dir>]
23
24
  docsxai plugins <list|info|sync> <workspace-dir> [<namespace>] [--format text|json]
24
- docsxai login --backend-url <url>
25
+ docsxai login --backend-url <url> [--oauth <workspace-dir>]
25
26
  docsxai push <workspace-dir> [--kind calibrate|run|edit] [--author <name>]
26
27
  docsxai pull <workspace-dir> [--rev <id>]
27
28
  docsxai render <workspace-dir>
29
+ docsxai burn <workspace-dir> [--flow <name>] [--out <dir>] [--report <file>] [--no-connector-outline]
30
+ docsxai pack <workspace-or-raw-dir> [--from-raw] [--out <dir>] [--public-prefix <path>] [--no-optimise] [--generated-for <text>]
31
+ docsxai pack <workspace-or-raw-dir> --check --against <pack-dir> [--from-raw] [--threshold <pct>]
28
32
  docsxai capture-auth <workspace-dir> [--base-url <url>] [--role <role>] [--auth-cookie <name>] [--cdp <endpoint>] [--fresh] [--headless] [--ignore-https-errors]
29
33
  docsxai --help
30
34
 
@@ -40,6 +44,9 @@ Notes:
40
44
  (headed) browser open at the last step run — so you can inspect the live state mid-flow when calibrating
41
45
  (pair with --flow <name>). For waiting on a slow backend op, give a step a wait_for of the form
42
46
  { selector: $x, timeout_ms: 180000 } — a per-step override of the default ~30s selector-wait timeout.
47
+ For a page that settles late (web fonts swapping, images arriving), use wait_for: settled: it waits for
48
+ fonts, the images in view and the layout of what's on screen to stop changing, within the step's
49
+ timeout_ms (default 10s), and halts with the cause if the page never settles.
43
50
  • run --concurrency <N> runs up to N flows in parallel (each its own Chromium session, isolated; default 1).
44
51
  Useful when several flows share a long preamble — total wall time = max(per-flow), not sum. Force-clamped
45
52
  to 1 when --pause / --stop-after / --start-from / --cdp is set. The target app must tolerate multiple sessions from one user.
@@ -48,10 +55,23 @@ Notes:
48
55
  state (e.g. left over from a paused previous run) and iterate on the new tail step in seconds rather
49
56
  than re-walking the whole extends chain. New annotations MERGE into the existing annotations.json by
50
57
  step id; the prior steps' annotations and screenshots are preserved.
58
+ • A flow with a top-level \`matrix:\` (locales, color_schemes, viewports) expands into one variant per
59
+ combination. run gives each variant its own Chromium session and writes docs/<flow>/<variant>/
60
+ {screenshots/, annotations.json, halts/} (variant id: <locale>.<scheme>.<viewport>, axes the matrix
61
+ leaves out are dropped). run --variant <id> runs one variant. lint lists the variants (R015), flow-tree
62
+ prints them, diagnose --variant <id> picks one. --cdp cannot run a matrix flow.
51
63
  • run --cdp <endpoint> attaches to a running Chrome (start it with --remote-debugging-port=N) instead of
52
64
  launching one. docsxai won't close that Chrome. When --cdp is set, the cached storageState is NOT
53
65
  loaded into the context — the operator's Chrome owns its auth state. Useful with --start-from for the
54
66
  sub-3-sec iteration loop on long-async flows.
67
+ • run --verify-determinism runs the selected flows N times (--runs, 2 to 5, default 2), each into its own
68
+ root under <ws>/.docsxai-verify/run-<k>/, then byte-compares every artefact: annotations.json, screenshots,
69
+ step markdown, locators, halt context. The workspace output is written only when every run agrees (run 1's
70
+ files are copied in, the bytes a plain run writes); on any difference or halt it is left untouched. The run
71
+ roots are removed at the end. The report goes to stdout (--format text|md|json, default text; progress goes to
72
+ stderr) and names the first differing artefact by path with a cause: the JSON key path, the changed-pixel
73
+ region of a PNG, the first differing line of text, or the sizes. Exit 0 identical, 1 differing or a flow
74
+ halted, 2 bad flags. Not combinable with --pause / --stop-after / --start-from / --cdp.
55
75
  • capture-auth runs the role's auth strategy (MVP: manual-capture — a headed, instrumented browser the
56
76
  engineer logs into; window.__docsxai.capture() or an injected button snapshots the session) and caches
57
77
  it to <workspace-dir>/.auth/<role>.json for subsequent \`run\`s. It prints the captured cookie jar so you
@@ -72,6 +92,7 @@ Notes:
72
92
  because the auth cookie is usually httpOnly; inspect does the storageState→Playwright bridge for you). On a
73
93
  slow SPA, settle before the snapshot with --wait <ms> (default 800) or --wait-for '<css>'. --cdp <endpoint>
74
94
  attaches to an already-running Chrome (e.g. the one from capture-auth --cdp) instead of launching one.
95
+ --ignore-https-errors accepts a self-signed/invalid TLS certificate (also read from ignore_https_errors in .docsxai.json).
75
96
  • calibrate takes a *structured flow-guide* (a flow-file in YAML, or a .md with a yaml fenced block) and
76
97
  writes flows/<name>.flow.yaml + a default docs/style.yaml. Loose-prose descriptions / live element-picking
77
98
  need the host agent — that's the /docsxai:calibrate *skill* (see the plugin), which then refines/produces
@@ -126,9 +147,36 @@ Notes:
126
147
  • render builds the static viewer by spawning the docsxai-viewer bin, resolved in order: the
127
148
  DOCSX_VIEWER_BIN env var (path to the viewer's bin script), the @docsxai/viewer
128
149
  package installed next to the engine, then \`docsxai-viewer\` on PATH.
150
+ • burn bakes each flow's annotations (halo, badge, callout) into copies of its clean screenshots, for
151
+ surfaces that can't run the interactive viewer, via the same viewer bin as render. Reads
152
+ <ws>/docs/<flow>/annotations.json and writes docs/<flow>/burned/<step>.png (or <out>/<flow>/<step>.png
153
+ with --out). --flow limits it to named flows (repeatable); the default is every flow with annotations.
154
+ --report <file> writes a JSON placement report (callout and badge boxes, overlaps, callouts flagged
155
+ unplaceable), resolved under the workspace when relative. --no-connector-outline keeps every arrow and
156
+ stem plain ink; by default one over a dark part of the screenshot gets a white outline.
157
+ • pack builds the screenshot pack a docs site or README ships: it burns each step's annotations into its
158
+ clean screenshot, optimises the PNG losslessly with the external \`oxipng\` binary (on PATH, or
159
+ $DOCSX_OXIPNG_BIN; \`brew install oxipng\`; --no-optimise skips it), names it
160
+ <flow>/<step>.<hash8>.png from the final bytes, and writes manifest.json (docsxai/screens-pack@2: flows,
161
+ steps, localised alt, variants keyed <locale>.<theme>.<viewport> with src, size and callouts). <dir> is a
162
+ workspace (docs/ plus a pack.json naming which capture flow feeds which variant, and the alt text) or,
163
+ with --from-raw or no docs/, a raw capture directory (<flow>/<step>/<locale>.<theme>.<viewport>.png with a
164
+ .json sidecar, step.json and flow.json). --out defaults to <workspace>/.screens and is required for a raw
165
+ directory. Files the previous manifest listed and the new one does not are deleted by exact path; nothing
166
+ else in --out is touched. Loopback and private-network addresses, emails, non-Bearer Authorization headers,
167
+ URL-query tokens and obvious secrets in alt, caption, title or callout text stop the build. Runs the
168
+ viewer's \`pack\` through the same bin resolution as render.
169
+ • pack --check rebuilds the pack in memory (no oxipng, nothing written) and compares it with the committed pack
170
+ in --against (required): equal hash is unchanged, otherwise a pixel diff gives changed %, the changed region and
171
+ a pass or fail against --threshold (default 0.5). A resized, new or missing variant, or a committed file
172
+ that does not match its name, always fails. Exit 1 on any failure, 2 on a bad argument. The report has no
173
+ timestamps. The old \`docsxai drift\` still works for now: it prints a deprecation warning and runs pack --check.
129
174
  • login validates a bearer token against a backend URL — hits /v1/health, /v1/workspaces. Reads
130
175
  the token from DOCSX_TOKEN env var. Prints what the backend sees if the call succeeds,
131
176
  or a clear error if not. Stateless: doesn't store anything; configure the env var in your shell.
177
+ login --oauth <workspace-dir> instead signs in as a person: OAuth 2.1 authorization code + PKCE against
178
+ the backend. It prints a URL to open in a browser and stores the tokens at
179
+ <workspace-dir>/.auth/backend-token.json (mode 0600); push, pull and run read them from there.
132
180
  • push serialises the workspace's doc pack (flows + annotations + screenshots + style + locators)
133
181
  and POSTs it as a new revision against the backend named in .docsxai.json (backend_url +
134
182
  optionally backend_workspace_id / backend_project_id; created on first push if absent and
@@ -0,0 +1,14 @@
1
+ import { type VerifyReport } from "./verify-report.js";
2
+ export type VerifyFormat = "json" | "md" | "text";
3
+ export interface VerifyArgs {
4
+ runs: number;
5
+ format: VerifyFormat;
6
+ }
7
+ /**
8
+ * Read the verification flags of `run`. Returns `null` when verification is off, the usage-error
9
+ * message when the flags are wrong, and the parsed arguments otherwise. `--runs` and `--format`
10
+ * belong to verification, so they are rejected without `--verify-determinism`.
11
+ */
12
+ export declare function parseVerifyArgs(flags: Map<string, string | true>): VerifyArgs | string | null;
13
+ /** Print the report on stdout and return the exit code it maps to (0 identical, 1 differing or halted). */
14
+ export declare function emitVerifyReport(report: VerifyReport, format: VerifyFormat): number;
@@ -0,0 +1,54 @@
1
+ // CLI glue for `docsxai run --verify-determinism`: parse and validate its flags (usage errors are
2
+ // exit 2), and print the finished report in the chosen format. The verification itself lives in
3
+ // verify-determinism.ts; this file only knows argv and stdout.
4
+ import { DEFAULT_RUNS, MAX_RUNS, MIN_RUNS } from "./verify-determinism.js";
5
+ import { formatVerifyReportJson, formatVerifyReportMarkdown, formatVerifyReportText, verifyExitCode, } from "./verify-report.js";
6
+ /** Flags that make a verification meaningless: they stop a flow early, keep a browser open or attach to someone else's. */
7
+ const INCOMPATIBLE = ["pause", "stop-after", "start-from", "cdp"];
8
+ /**
9
+ * Read the verification flags of `run`. Returns `null` when verification is off, the usage-error
10
+ * message when the flags are wrong, and the parsed arguments otherwise. `--runs` and `--format`
11
+ * belong to verification, so they are rejected without `--verify-determinism`.
12
+ */
13
+ export function parseVerifyArgs(flags) {
14
+ const verify = flags.get("verify-determinism");
15
+ if (verify === undefined) {
16
+ for (const f of ["runs", "format"]) {
17
+ if (flags.has(f))
18
+ return `--${f} requires --verify-determinism`;
19
+ }
20
+ return null;
21
+ }
22
+ if (verify !== true) {
23
+ return `--verify-determinism takes no value (got "${verify}"); put <workspace-dir> before it`;
24
+ }
25
+ for (const f of INCOMPATIBLE) {
26
+ if (flags.has(f))
27
+ return `--verify-determinism cannot be combined with --${f}`;
28
+ }
29
+ const runsFlag = flags.get("runs");
30
+ let runs = DEFAULT_RUNS;
31
+ if (runsFlag !== undefined) {
32
+ const n = typeof runsFlag === "string" && /^\d+$/.test(runsFlag) ? Number(runsFlag) : NaN;
33
+ if (!(n >= MIN_RUNS && n <= MAX_RUNS)) {
34
+ return `--runs must be an integer from ${MIN_RUNS} to ${MAX_RUNS} (got "${String(runsFlag)}")`;
35
+ }
36
+ runs = n;
37
+ }
38
+ const formatFlag = flags.get("format");
39
+ const format = formatFlag === undefined ? "text" : formatFlag;
40
+ if (format !== "json" && format !== "md" && format !== "text") {
41
+ return `--format must be json | md | text (got "${String(format)}")`;
42
+ }
43
+ return { runs, format };
44
+ }
45
+ /** Print the report on stdout and return the exit code it maps to (0 identical, 1 differing or halted). */
46
+ export function emitVerifyReport(report, format) {
47
+ const text = format === "json"
48
+ ? formatVerifyReportJson(report)
49
+ : format === "md"
50
+ ? formatVerifyReportMarkdown(report)
51
+ : formatVerifyReportText(report);
52
+ process.stdout.write(text);
53
+ return verifyExitCode(report);
54
+ }
package/dist/cli.js CHANGED
@@ -11,16 +11,25 @@
11
11
  // • cli-commands-session.ts — init / capture-auth / calibrate / run (live-browser + scaffolding)
12
12
  // • cli-commands-authoring.ts — inspect / lint / flow-tree / diagnose / style (calibration aids)
13
13
  // • cli-commands-docpack.ts — render / zip / export / baseline / diff (doc-pack ops)
14
+ // • cli-commands-pack.ts — pack / pack --check (screenshot pack + drift check, run by the viewer bin)
14
15
  // • cli-commands-backend.ts — login / push / pull / plugins (backend + sync)
15
16
  import { pathToFileURL } from "node:url";
16
17
  import { runDoctor } from "./doctor.js";
17
18
  import { USAGE } from "./cli-usage.js";
18
19
  import { cmdCalibrate, cmdCaptureAuth, cmdInit, cmdRun } from "./cli-commands-session.js";
19
20
  import { cmdDiagnose, cmdFlowTree, cmdInspect, cmdLint, cmdStyle, } from "./cli-commands-authoring.js";
20
- import { cmdBaseline, cmdDiff, cmdExport, cmdRender, cmdZip } from "./cli-commands-docpack.js";
21
+ import { cmdBaseline, cmdBurn, cmdDiff, cmdExport, cmdRender, cmdZip, } from "./cli-commands-docpack.js";
21
22
  import { cmdLogin, cmdPlugins, cmdPull, cmdPush } from "./cli-commands-backend.js";
23
+ import { cmdPack } from "./cli-commands-pack.js";
24
+ import { RETIRED_COMMANDS } from "./cli-retired.js";
25
+ import { findRetired, warnDeprecated } from "./deprecation.js";
22
26
  export async function main(argv) {
23
27
  const [cmd, ...rest] = argv;
28
+ const retired = cmd === undefined ? undefined : findRetired(RETIRED_COMMANDS, cmd);
29
+ if (retired) {
30
+ warnDeprecated(`the ${cmd} command`, retired);
31
+ return main(retired.rewrite(rest));
32
+ }
24
33
  switch (cmd) {
25
34
  case undefined:
26
35
  case "--help":
@@ -38,6 +47,10 @@ export async function main(argv) {
38
47
  return cmdRun(rest);
39
48
  case "render":
40
49
  return cmdRender(rest);
50
+ case "burn":
51
+ return cmdBurn(rest);
52
+ case "pack":
53
+ return cmdPack(rest);
41
54
  case "capture-auth":
42
55
  return cmdCaptureAuth(rest);
43
56
  case "lint":
@@ -0,0 +1,19 @@
1
+ export interface RetiredEntry {
2
+ /** The release that deprecated it. */
3
+ since: string;
4
+ /** What to use instead. Omitted when nothing replaces it. */
5
+ replacement?: string;
6
+ /** One extra clause, for example why. */
7
+ note?: string;
8
+ }
9
+ /** The warning line (without a trailing newline) for a retired `item`. */
10
+ export declare function deprecationMessage(item: string, entry: RetiredEntry): string;
11
+ /**
12
+ * Print the warning for `item` to stderr, once per process. Returns whether it printed. `write`
13
+ * is injectable for tests and for hosts that route diagnostics elsewhere.
14
+ */
15
+ export declare function warnDeprecated(item: string, entry: RetiredEntry, write?: (line: string) => void): boolean;
16
+ /** Forget which items already warned. For tests; a CLI invocation is one process. */
17
+ export declare function resetDeprecationWarnings(): void;
18
+ /** Look `name` up as an own key of a retired registry, so `constructor` and `toString` are never retired. */
19
+ export declare function findRetired<T extends RetiredEntry>(registry: Readonly<Record<string, T>>, name: string): T | undefined;
@@ -0,0 +1,32 @@
1
+ // Deprecation warnings: the code behind the policy in docs/public-surface.md. An input that was
2
+ // valid and is being retired (a CLI command or flag, a flow-file field, a config key, an
3
+ // environment variable) keeps working for at least one minor release and prints one warning per
4
+ // invocation: `docsxai: <item> is deprecated since <version>, use <replacement>`. The registry
5
+ // shape and the accept-warn-ignore rule are in docs/ai-context/release-process/retired-registry-pattern.md.
6
+ // An unknown input is not here: it is a typo and stays a loud error.
7
+ /** The warning line (without a trailing newline) for a retired `item`. */
8
+ export function deprecationMessage(item, entry) {
9
+ const use = entry.replacement ? `, use ${entry.replacement}` : "";
10
+ const note = entry.note ? ` (${entry.note})` : "";
11
+ return `docsxai: ${item} is deprecated since ${entry.since}${use}${note}`;
12
+ }
13
+ const warned = new Set();
14
+ /**
15
+ * Print the warning for `item` to stderr, once per process. Returns whether it printed. `write`
16
+ * is injectable for tests and for hosts that route diagnostics elsewhere.
17
+ */
18
+ export function warnDeprecated(item, entry, write = (line) => void process.stderr.write(line)) {
19
+ if (warned.has(item))
20
+ return false;
21
+ warned.add(item);
22
+ write(`${deprecationMessage(item, entry)}\n`);
23
+ return true;
24
+ }
25
+ /** Forget which items already warned. For tests; a CLI invocation is one process. */
26
+ export function resetDeprecationWarnings() {
27
+ warned.clear();
28
+ }
29
+ /** Look `name` up as an own key of a retired registry, so `constructor` and `toString` are never retired. */
30
+ export function findRetired(registry, name) {
31
+ return Object.prototype.hasOwnProperty.call(registry, name) ? registry[name] : undefined;
32
+ }