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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) 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/backend-client-token.js +2 -1
  13. package/dist/calibrate.d.ts +2 -2
  14. package/dist/calibrate.js +5 -0
  15. package/dist/cli-backend-errors.d.ts +7 -0
  16. package/dist/cli-backend-errors.js +65 -0
  17. package/dist/cli-commands-authoring.js +57 -51
  18. package/dist/cli-commands-backend.js +49 -42
  19. package/dist/cli-commands-docpack.d.ts +5 -0
  20. package/dist/cli-commands-docpack.js +106 -66
  21. package/dist/cli-commands-pack.d.ts +2 -0
  22. package/dist/cli-commands-pack.js +65 -0
  23. package/dist/cli-commands-session.js +120 -125
  24. package/dist/cli-messages.d.ts +17 -0
  25. package/dist/cli-messages.js +80 -0
  26. package/dist/cli-retired.d.ts +6 -0
  27. package/dist/cli-retired.js +12 -0
  28. package/dist/cli-run-summary.d.ts +15 -0
  29. package/dist/cli-run-summary.js +33 -0
  30. package/dist/cli-usage.d.ts +1 -1
  31. package/dist/cli-usage.js +78 -5
  32. package/dist/cli-verify.d.ts +14 -0
  33. package/dist/cli-verify.js +54 -0
  34. package/dist/cli.js +15 -2
  35. package/dist/deprecation.d.ts +19 -0
  36. package/dist/deprecation.js +32 -0
  37. package/dist/diagnose.d.ts +25 -0
  38. package/dist/diagnose.js +69 -3
  39. package/dist/diff-compute.js +1 -0
  40. package/dist/doc-pack-io.d.ts +14 -0
  41. package/dist/doc-pack-io.js +121 -14
  42. package/dist/doc-pack.d.ts +2282 -387
  43. package/dist/doc-pack.js +135 -43
  44. package/dist/doctor-checks-plugins.js +4 -3
  45. package/dist/doctor-checks.d.ts +1 -1
  46. package/dist/doctor-checks.js +31 -6
  47. package/dist/doctor.d.ts +2 -0
  48. package/dist/doctor.js +27 -3
  49. package/dist/driver-budget.d.ts +6 -0
  50. package/dist/driver-budget.js +15 -0
  51. package/dist/egress-guard.d.ts +58 -0
  52. package/dist/egress-guard.js +136 -0
  53. package/dist/environment-spec.d.ts +67 -0
  54. package/dist/environment-spec.js +38 -0
  55. package/dist/export/playwright-test.js +42 -10
  56. package/dist/flow-file.d.ts +9 -3
  57. package/dist/flow-file.js +21 -1
  58. package/dist/flow-halt.d.ts +16 -0
  59. package/dist/flow-halt.js +76 -0
  60. package/dist/flow-hidden.d.ts +9 -0
  61. package/dist/flow-hidden.js +20 -0
  62. package/dist/flow-lint.js +91 -1
  63. package/dist/flow-matrix-lint.d.ts +10 -0
  64. package/dist/flow-matrix-lint.js +40 -0
  65. package/dist/flow-matrix.d.ts +44 -0
  66. package/dist/flow-matrix.js +238 -0
  67. package/dist/flow-name-rules.d.ts +15 -0
  68. package/dist/flow-name-rules.js +39 -0
  69. package/dist/flow-runtime.d.ts +52 -22
  70. package/dist/flow-runtime.js +63 -117
  71. package/dist/flow-success.d.ts +3 -0
  72. package/dist/flow-success.js +37 -0
  73. package/dist/flow-tree.d.ts +2 -0
  74. package/dist/flow-tree.js +17 -5
  75. package/dist/flow-wait.d.ts +3 -0
  76. package/dist/flow-wait.js +22 -0
  77. package/dist/index.d.ts +5 -0
  78. package/dist/index.js +5 -0
  79. package/dist/matrix-spec.d.ts +145 -0
  80. package/dist/matrix-spec.js +120 -0
  81. package/dist/page-hide.d.ts +10 -0
  82. package/dist/page-hide.js +45 -0
  83. package/dist/page-settle.d.ts +39 -0
  84. package/dist/page-settle.js +142 -0
  85. package/dist/playwright-driver.d.ts +28 -8
  86. package/dist/playwright-driver.js +73 -28
  87. package/dist/plugins/manifest.d.ts +9 -9
  88. package/dist/run-flows.d.ts +40 -0
  89. package/dist/run-flows.js +129 -0
  90. package/dist/style.d.ts +2 -2
  91. package/dist/upload-path.d.ts +15 -0
  92. package/dist/upload-path.js +63 -0
  93. package/dist/verify-compare.d.ts +43 -0
  94. package/dist/verify-compare.js +237 -0
  95. package/dist/verify-determinism.d.ts +16 -0
  96. package/dist/verify-determinism.js +88 -0
  97. package/dist/verify-report.d.ts +53 -0
  98. package/dist/verify-report.js +141 -0
  99. package/dist/verify-tree.d.ts +27 -0
  100. package/dist/verify-tree.js +95 -0
  101. package/dist/viewer-bin.d.ts +6 -0
  102. package/dist/viewer-bin.js +24 -0
  103. package/dist/zip.d.ts +2 -2
  104. package/package.json +3 -2
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,12 +147,64 @@ 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
135
183
  persisted to the config). --kind defaults to "calibrate"; --author defaults to the OS user.
136
184
  • pull fetches a revision's artifacts back into the workspace files (default: HEAD). Useful for
137
- syncing with a different operator's edits or rolling back to a named revision.`;
185
+ syncing with a different operator's edits or rolling back to a named revision.
186
+ • A command that works on a workspace takes its directory as the first argument. Reports and data go to
187
+ stdout; progress lines and warnings go to stderr where a command already splits them. Output has no
188
+ colour. An error prints \`<command>: what failed\`, then \`next: <command to run>\` when there is one.
189
+ Exit 0 success, 1 runtime failure, 2 usage error.
190
+ • --format json (lint, flow-tree, diagnose, style, diff, plugins, run --verify-determinism) is the
191
+ machine-readable output; the text formats are for people and may change.
192
+ • run, calibrate, burn, pack, zip, baseline, push, pull and doctor end with one line,
193
+ \`<command>: <result> …\`, naming the counts and where the output went (run --verify-determinism
194
+ ends with its report).
195
+
196
+ Examples:
197
+ docsxai init ~/docsxai/my-app --app-url https://app.example.com
198
+ docsxai capture-auth ~/docsxai/my-app
199
+ docsxai calibrate ~/docsxai/my-app --from login.flow.yaml
200
+ docsxai run ~/docsxai/my-app --flow login
201
+ docsxai run ~/docsxai/my-app --verify-determinism --runs 3 --format md
202
+ docsxai lint ~/docsxai/my-app --format json
203
+ docsxai render ~/docsxai/my-app
204
+ docsxai burn ~/docsxai/my-app --flow login --out ~/docsxai/my-app/burned
205
+ docsxai pack ~/docsxai/my-app --out ~/docsxai/my-app/.screens
206
+ docsxai pack ~/docsxai/my-app --check --against ./public/screens
207
+ docsxai baseline ~/docsxai/my-app
208
+ docsxai diff ~/docsxai/my-app --fail-on warn
209
+ docsxai doctor ~/docsxai/my-app
210
+ docsxai push ~/docsxai/my-app --kind run`;
@@ -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":
@@ -67,7 +80,7 @@ export async function main(argv) {
67
80
  case "pull":
68
81
  return cmdPull(rest);
69
82
  default:
70
- process.stderr.write(`unknown command: ${cmd}\n\n${USAGE}\n`);
83
+ process.stderr.write(`unknown command: ${cmd}\nrun \`docsxai --help\` to list the commands\n`);
71
84
  return 2;
72
85
  }
73
86
  }
@@ -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
+ }
@@ -1,4 +1,5 @@
1
1
  import type { BoundingBox, FlowFile, Step } from "./doc-pack.js";
2
+ import { type FlowVariant } from "./flow-matrix.js";
2
3
  import type { ActionableState, BrowserDriver } from "./flow-runtime.js";
3
4
  export type DiagnoseRecommendationKind = "selector" | "wait_for" | "success" | "annotation_target" | "split_step" | "investigate";
4
5
  export interface DiagnoseRecommendation {
@@ -15,6 +16,10 @@ export interface DiagnoseLiveProbe {
15
16
  export interface DiagnoseReport {
16
17
  workspace: string;
17
18
  flow: string;
19
+ /** The matrix variant diagnosed. Absent for a flow without a `matrix`. */
20
+ variant?: string;
21
+ /** Every variant id the flow's `matrix` expands to (present with `variant`). */
22
+ variants?: string[];
18
23
  step: {
19
24
  id: string;
20
25
  action: Step["action"];
@@ -36,6 +41,21 @@ export declare function recommendFromActionable(state: ActionableState): Diagnos
36
41
  export declare function recommendStatic(step: Step, halt: {
37
42
  screenshotRelPath?: string;
38
43
  }): DiagnoseRecommendation[];
44
+ /** The step reaches an element an earlier `hide` step hid: a hidden element is never visible, so waits on it run out. */
45
+ export declare function recommendHiddenTarget(flow: FlowFile, step: Step): DiagnoseRecommendation[];
46
+ /** Pick the matrix variant to diagnose: the requested one, else the only one with a halt shot for the step. */
47
+ export declare function pickDiagnoseVariant(opts: {
48
+ workspace: string;
49
+ flow: string;
50
+ stepId: string;
51
+ variants: FlowVariant[];
52
+ requested: string | undefined;
53
+ }): Promise<{
54
+ variant: FlowVariant;
55
+ ids: string[];
56
+ } | {
57
+ error: string;
58
+ }>;
39
59
  /** Build the full report. `liveProbe` is invoked lazily (only if a driver is supplied). */
40
60
  export declare function buildDiagnoseReport(opts: {
41
61
  workspace: string;
@@ -44,6 +64,11 @@ export declare function buildDiagnoseReport(opts: {
44
64
  resolvedSelector?: string;
45
65
  haltScreenshotAbsPath?: string;
46
66
  liveProbe?: () => Promise<DiagnoseLiveProbe>;
67
+ /** The matrix variant `flow` was expanded for, and every variant of the matrix. */
68
+ variant?: {
69
+ id: string;
70
+ all: string[];
71
+ };
47
72
  }): Promise<DiagnoseReport>;
48
73
  /** Live-probe helper that uses any driver implementing the runtime's `BrowserDriver` interface. */
49
74
  export declare function probeLive(driver: BrowserDriver, selector: string, cdpEndpoint: string): Promise<DiagnoseLiveProbe>;
package/dist/diagnose.js CHANGED
@@ -5,6 +5,10 @@
5
5
  // <step-id> --cdp <endpoint>` then validates the edit in seconds.
6
6
  import { promises as fs } from "node:fs";
7
7
  import * as path from "node:path";
8
+ import { hiddenAtEachStep } from "./flow-hidden.js";
9
+ import { locatorRefName } from "./flow-file.js";
10
+ import { variantDocDir } from "./flow-matrix.js";
11
+ import { resolveWorkspacePath } from "./workspace.js";
8
12
  /** Map an `ActionableState` to concrete recommendations for the agent. */
9
13
  export function recommendFromActionable(state) {
10
14
  switch (state) {
@@ -13,7 +17,7 @@ export function recommendFromActionable(state) {
13
17
  {
14
18
  kind: "investigate",
15
19
  rationale: "The current target is actionable on the live page right now.",
16
- suggestion: "Drift may be intermittent (race condition) or in the `success` criterion. Consider adding `wait_for: network_idle` or `element_stable`; re-check the `success` clause against the live target state.",
20
+ suggestion: "Drift may be intermittent (race condition) or in the `success` criterion. Consider adding `wait_for: network_idle`, `settled` (fonts, images and layout) or `element_stable`; re-check the `success` clause against the live target state.",
17
21
  },
18
22
  ];
19
23
  case "not-found":
@@ -21,7 +25,7 @@ export function recommendFromActionable(state) {
21
25
  {
22
26
  kind: "selector",
23
27
  rationale: "Selector matches 0 elements on the live page — the element was renamed, moved, or removed.",
24
- suggestion: "Re-discover the element via the calibration loop (browxai's `find()`, or `docsxai inspect`). Pick a new canonical locator and commit it as the step's `target` (or update the named entry in the flow's `locators:` block).",
28
+ suggestion: "Re-discover the element via the calibration loop (browxai's `find()`, or `docsxai inspect`). Pick a new canonical locator and commit it as the step's `target` (or update the named entry in the flow's `locators:` block). If the element is only sometimes there, declare that instead: `optional: true` with a short `timeout_ms` (e.g. 1500) skips a miss in seconds, not after the full 30 s default.",
25
29
  },
26
30
  ];
27
31
  case "multiple-matches":
@@ -84,6 +88,13 @@ export function recommendStatic(step, halt) {
84
88
  suggestion: "Open the screenshot; compare the visual state to what the step expects.",
85
89
  });
86
90
  }
91
+ if (step.action === "hide") {
92
+ recs.push({
93
+ kind: "selector",
94
+ rationale: "A `hide` step waits for its target to exist (not to be visible); it halts when no element matched within the step's budget.",
95
+ suggestion: "Check the locator against the live page. If the element is conditionally present (a dev-only overlay, a banner), set `optional: true` with a short `timeout_ms` (e.g. 1500) so a miss is skipped quickly.",
96
+ });
97
+ }
87
98
  const success = step.success;
88
99
  if (success && typeof success === "object" && success !== null && "text_contains" in success) {
89
100
  recs.push({
@@ -94,6 +105,56 @@ export function recommendStatic(step, halt) {
94
105
  }
95
106
  return recs;
96
107
  }
108
+ /** The step reaches an element an earlier `hide` step hid: a hidden element is never visible, so waits on it run out. */
109
+ export function recommendHiddenTarget(flow, step) {
110
+ const index = flow.steps.findIndex((s) => s.id === step.id);
111
+ if (index < 0 || !step.target || step.action === "hide" || step.action === "show")
112
+ return [];
113
+ const resolve = (v) => {
114
+ const name = locatorRefName(v);
115
+ return name ? (flow.locators[name] ?? v) : v;
116
+ };
117
+ if (!hiddenAtEachStep(flow, resolve)[index].before.has(resolve(step.target)))
118
+ return [];
119
+ return [
120
+ {
121
+ kind: "split_step",
122
+ rationale: "An earlier `hide` step hides this step's target (`visibility: hidden`), so it is never visible or actionable here.",
123
+ suggestion: "Insert a `show` step with this target (or none, to show everything) before this step, or move the `hide` step after it.",
124
+ },
125
+ ];
126
+ }
127
+ /** Pick the matrix variant to diagnose: the requested one, else the only one with a halt shot for the step. */
128
+ export async function pickDiagnoseVariant(opts) {
129
+ const ids = opts.variants.flatMap((v) => (v.id ? [v.id] : []));
130
+ if (ids.length === 0) {
131
+ return opts.requested
132
+ ? { error: `--variant "${opts.requested}": flow "${opts.flow}" has no matrix` }
133
+ : { variant: opts.variants[0], ids };
134
+ }
135
+ if (opts.requested) {
136
+ const hit = opts.variants.find((v) => v.id === opts.requested);
137
+ return hit
138
+ ? { variant: hit, ids }
139
+ : {
140
+ error: `no variant "${opts.requested}" in flow "${opts.flow}" (variants: ${ids.join(", ")})`,
141
+ };
142
+ }
143
+ const halted = [];
144
+ for (const v of opts.variants) {
145
+ const shot = resolveWorkspacePath(opts.workspace, variantDocDir(opts.flow, v.id), "halts", `${opts.stepId}.png`);
146
+ if (await fs.access(shot).then(() => true, () => false))
147
+ halted.push(v);
148
+ }
149
+ if (halted.length === 1)
150
+ return { variant: halted[0], ids };
151
+ return {
152
+ error: `flow "${opts.flow}" has a matrix: pass --variant <id> (variants: ${ids.join(", ")}; ` +
153
+ (halted.length > 0
154
+ ? `halt screenshots for step "${opts.stepId}" in: ${halted.map((v) => v.id).join(", ")})`
155
+ : `no halt screenshot found for step "${opts.stepId}")`),
156
+ };
157
+ }
97
158
  /** Build the full report. `liveProbe` is invoked lazily (only if a driver is supplied). */
98
159
  export async function buildDiagnoseReport(opts) {
99
160
  const haltExists = opts.haltScreenshotAbsPath
@@ -108,11 +169,13 @@ export async function buildDiagnoseReport(opts) {
108
169
  const live = opts.liveProbe ? await opts.liveProbe() : undefined;
109
170
  const recommendations = [
110
171
  ...recommendStatic(opts.step, { screenshotRelPath: haltRel }),
172
+ ...recommendHiddenTarget(opts.flow, opts.step),
111
173
  ...(live ? recommendFromActionable(live.actionable) : []),
112
174
  ];
113
175
  return {
114
176
  workspace: opts.workspace,
115
177
  flow: opts.flow.name,
178
+ ...(opts.variant ? { variant: opts.variant.id, variants: opts.variant.all } : {}),
116
179
  step: {
117
180
  id: opts.step.id,
118
181
  action: opts.step.action,
@@ -137,7 +200,10 @@ export async function probeLive(driver, selector, cdpEndpoint) {
137
200
  return { cdpEndpoint, url, actionable, bbox };
138
201
  }
139
202
  export function formatReportText(r) {
140
- let out = `diagnose: flow=${r.flow} step=${r.step.id}\n\n`;
203
+ let out = `diagnose: flow=${r.flow}${r.variant ? ` variant=${r.variant}` : ""} step=${r.step.id}\n`;
204
+ if (r.variants)
205
+ out += `variants: ${r.variants.join(", ")}\n`;
206
+ out += "\n";
141
207
  out += `Current step:\n`;
142
208
  out += ` action: ${r.step.action}\n`;
143
209
  if (r.step.target)
@@ -135,6 +135,7 @@ async function loadAnnotations(dir, flow) {
135
135
  const STEP_FIELDS = [
136
136
  "action",
137
137
  "optional",
138
+ "timeout_ms",
138
139
  "target",
139
140
  "value",
140
141
  "wait_for",
@@ -22,6 +22,20 @@ export declare function uploadScreenshotBlobs(workspace: string, manifest: Scree
22
22
  }>;
23
23
  /** Fetch the bytes behind a screenshots manifest, verifying each blob against its sha256. */
24
24
  export declare function fetchScreenshotBlobs(manifest: ScreenshotsPayload, blobs: BlobFetcher): Promise<Record<string, Uint8Array>>;
25
+ /** A pulled payload named a file the workspace would not have produced; nothing was written. */
26
+ export declare class UnsafePackNameError extends Error {
27
+ constructor(message: string);
28
+ }
29
+ /**
30
+ * Throws {@link UnsafePackNameError} on the first file name in `payloads` that is not one a
31
+ * workspace produces: a flow file that is not `<flow name>.flow.yaml`, an annotations file that is
32
+ * not `<flow>[/<variant>]/annotations.json`, a screenshot that is not under a `screenshots/`
33
+ * directory of such a path, a variant segment or screenshot stem that is a Windows device name or
34
+ * ends in a dot, or two flow files, annotation paths, screenshot paths or output directories that
35
+ * differ only by case. The backend is not trusted
36
+ * with names, and a name like `../.docsxai.json` would otherwise land on workspace config.
37
+ */
38
+ export declare function assertSafePackNames(payloads: Partial<DocPackPayloads>): void;
25
39
  export declare function writeDocPack(workspace: string, payloads: Partial<DocPackPayloads>, extras?: {
26
40
  /** Screenshot bytes keyed by manifest path (from {@link fetchScreenshotBlobs}). */
27
41
  screenshotBytes?: Record<string, Uint8Array>;