@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
@@ -2,60 +2,104 @@
2
2
  // They read the rendered artifacts (flows/docs/screenshots) and emit something derived; none of
3
3
  // them drive a live browser:
4
4
  // render — build the static viewer by spawning the docsxai-viewer bin
5
+ // burn — bake the annotations into PNG copies by spawning the same bin
5
6
  // zip — deterministic single-archive hand-off bundle
6
7
  // export — project the doc pack to ADF (Confluence) or self-contained Playwright specs
7
8
  // baseline — snapshot the doc pack into .baseline/ as the "before" for diff
8
9
  // diff — drift report against a baseline (the after-vs-before)
9
- import { spawn } from "node:child_process";
10
10
  import { promises as fs } from "node:fs";
11
11
  import * as path from "node:path";
12
- import { FlowFileError } from "./flow-file.js";
13
12
  import { diffDocPacks, formatDriftReportMarkdown, formatDriftReportText, severityAtLeast, } from "./diff.js";
14
13
  import { projectDocPackToAdf } from "./export/adf.js";
15
14
  import { exportWorkspaceFlowsAsPlaywrightTests } from "./export/playwright-test.js";
16
- import { formatViewerBinFailure, resolveViewerBin } from "./viewer-bin.js";
15
+ import { runViewerBin } from "./viewer-bin.js";
17
16
  import { ZipError, zipDocPack } from "./zip.js";
18
17
  import { resolveWorkspacePath } from "./workspace.js";
19
18
  import { parseFlags } from "./cli-shared.js";
20
- import { USAGE } from "./cli-usage.js";
19
+ import { shellQuote, usageError, withNext } from "./cli-messages.js";
21
20
  export async function cmdRender(args) {
22
21
  const { positionals } = parseFlags(args);
23
22
  const projectDir = positionals[0];
24
- if (!projectDir) {
25
- process.stderr.write("render: missing <project-dir>\n\n" + USAGE + "\n");
26
- return 2;
27
- }
23
+ if (!projectDir)
24
+ return usageError("render", "missing <workspace-dir>");
28
25
  const docsDir = resolveWorkspacePath(projectDir, "docs");
29
26
  const outDir = resolveWorkspacePath(projectDir, ".viewer");
30
- // The viewer is its own package/bin; spawn it so the engine doesn't depend on it at build time.
31
- const viewerBin = await resolveViewerBin();
32
- return new Promise((resolve) => {
33
- const child = spawn(viewerBin.command, [...viewerBin.prefixArgs, "build", docsDir, outDir], {
34
- stdio: "inherit",
35
- });
36
- child.on("error", (e) => {
37
- if (e.code === "ENOENT") {
38
- process.stderr.write(`render: ${formatViewerBinFailure(viewerBin)}\n`);
39
- }
40
- else {
41
- process.stderr.write(`render: ${e.message}\n`);
42
- }
43
- resolve(1);
44
- });
45
- child.on("exit", (code) => {
46
- if ((code ?? 1) === 0) {
47
- process.stdout.write(`render: open ${path.join(outDir, "index.html")} (the index links the flows; each flow page shows the screenshots — hover a pulsing halo to read its callout)\n`);
48
- }
49
- resolve(code ?? 1);
50
- });
51
- });
27
+ if (!(await fs.stat(docsDir).then((s) => s.isDirectory(), () => false))) {
28
+ const note = withNext(`warning — ${docsDir} does not exist, so the viewer will be empty`, `docsxai run ${shellQuote(projectDir)}`);
29
+ process.stderr.write(`render: ${note}\n`);
30
+ }
31
+ const code = await runViewerBin("render", ["build", docsDir, outDir]);
32
+ if (code === 0) {
33
+ process.stdout.write(`render: open ${path.join(outDir, "index.html")} (the index links the flows; each flow page shows the screenshots — hover a pulsing halo to read its callout)\n`);
34
+ }
35
+ return code;
36
+ }
37
+ /** A flow name as `burn` passes it on: no separators, and no leading dot, so it can't name a parent or hidden path. */
38
+ const FLOW_NAME = /^[A-Za-z0-9_-][A-Za-z0-9._-]*$/;
39
+ /** Parse `burn`'s argv. Returns the usage-error message when the argv is malformed. */
40
+ function parseBurnArgs(args) {
41
+ const parsed = { workspace: "", flows: [], plainConnectors: false };
42
+ const positionals = [];
43
+ for (let i = 0; i < args.length; i++) {
44
+ const a = args[i];
45
+ if (a === "--no-connector-outline") {
46
+ parsed.plainConnectors = true;
47
+ }
48
+ else if (a === "--flow" || a === "--out" || a === "--report") {
49
+ const value = args[++i];
50
+ if (value === undefined || value.startsWith("--"))
51
+ return `${a} needs a value`;
52
+ if (a === "--flow")
53
+ parsed.flows.push(value);
54
+ else if (a === "--out")
55
+ parsed.out = value;
56
+ else
57
+ parsed.report = value;
58
+ }
59
+ else if (a.startsWith("--")) {
60
+ return `unknown flag ${a}`;
61
+ }
62
+ else {
63
+ positionals.push(a);
64
+ }
65
+ }
66
+ if (positionals.length === 0)
67
+ return "missing <workspace-dir>";
68
+ if (positionals.length > 1)
69
+ return `unexpected argument "${positionals[1]}"`;
70
+ parsed.workspace = positionals[0];
71
+ const bad = parsed.flows.find((f) => !FLOW_NAME.test(f));
72
+ if (bad !== undefined)
73
+ return `--flow "${bad}" is not a flow name`;
74
+ return parsed;
75
+ }
76
+ /**
77
+ * `burn` — bake each annotation into a copy of its screenshot, for surfaces that can't run the
78
+ * interactive viewer. The renderer lives in `@docsxai/viewer`; this runs its `burn` command.
79
+ */
80
+ export async function cmdBurn(args) {
81
+ const parsed = parseBurnArgs(args);
82
+ if (typeof parsed === "string")
83
+ return usageError("burn", parsed);
84
+ const docsDir = resolveWorkspacePath(parsed.workspace, "docs");
85
+ if (!(await fs.stat(docsDir).then((s) => s.isDirectory(), () => false))) {
86
+ const note = withNext(`${parsed.workspace} has no docs/ directory (expected ${docsDir})`, `docsxai run ${shellQuote(parsed.workspace)}`);
87
+ process.stderr.write(`burn: ${note}\n`);
88
+ return 1;
89
+ }
90
+ return runViewerBin("burn", [
91
+ "burn",
92
+ parsed.workspace,
93
+ ...parsed.flows.flatMap((f) => ["--flow", f]),
94
+ ...(parsed.out !== undefined ? ["--out", parsed.out] : []),
95
+ ...(parsed.report !== undefined ? ["--report", parsed.report] : []),
96
+ ...(parsed.plainConnectors ? ["--no-connector-outline"] : []),
97
+ ]);
52
98
  }
53
99
  export async function cmdZip(args) {
54
100
  const { positionals, flags } = parseFlags(args);
55
- if (!positionals[0]) {
56
- process.stderr.write(`zip: missing <workspace-dir>\n`);
57
- return 2;
58
- }
101
+ if (!positionals[0])
102
+ return usageError("zip", "missing <workspace-dir>");
59
103
  const projectDir = positionals[0];
60
104
  const output = typeof flags.get("out") === "string"
61
105
  ? flags.get("out")
@@ -69,7 +113,12 @@ export async function cmdZip(args) {
69
113
  }
70
114
  catch (e) {
71
115
  if (e instanceof ZipError) {
72
- process.stderr.write(`zip: ${e.message}\n`);
116
+ const next = /nothing to zip/.test(e.message)
117
+ ? `docsxai run ${shellQuote(projectDir)}`
118
+ : /doesn't exist/.test(e.message)
119
+ ? `docsxai init ${shellQuote(projectDir)} (or fix the path)`
120
+ : undefined;
121
+ process.stderr.write(`zip: ${next ? withNext(e.message, next) : e.message}\n`);
73
122
  return 1;
74
123
  }
75
124
  throw e;
@@ -83,23 +132,21 @@ export async function cmdExport(args) {
83
132
  case "playwright":
84
133
  return cmdExportPlaywright(rest);
85
134
  default:
86
- process.stderr.write(`export: unknown format "${format ?? ""}" — supported: adf, playwright\n`);
87
- return 2;
135
+ return usageError("export", format === undefined
136
+ ? "missing format — supported: adf, playwright"
137
+ : `unknown format "${format}" — supported: adf, playwright`);
88
138
  }
89
139
  }
90
140
  async function cmdExportAdf(rest) {
91
141
  const { positionals, flags } = parseFlags(rest);
92
- if (!positionals[0]) {
93
- process.stderr.write(`export adf: missing <workspace-dir>\n`);
94
- return 2;
95
- }
142
+ if (!positionals[0])
143
+ return usageError("export adf", "missing <workspace-dir>");
96
144
  const projectDir = positionals[0];
97
145
  const modeFlag = flags.get("mode");
98
146
  let mode = "single";
99
147
  if (typeof modeFlag === "string") {
100
148
  if (modeFlag !== "single" && modeFlag !== "page-tree") {
101
- process.stderr.write(`export adf: --mode must be "single" or "page-tree" (got "${modeFlag}")\n`);
102
- return 2;
149
+ return usageError("export adf", `--mode must be "single" or "page-tree" (got "${modeFlag}")`);
103
150
  }
104
151
  mode = modeFlag;
105
152
  }
@@ -129,16 +176,14 @@ async function cmdExportAdf(rest) {
129
176
  return 0;
130
177
  }
131
178
  catch (e) {
132
- process.stderr.write(`export adf: ${e.message}\n`);
179
+ process.stderr.write(`export adf: ${withNext(e.message, `docsxai lint ${shellQuote(projectDir)}`)}\n`);
133
180
  return 1;
134
181
  }
135
182
  }
136
183
  async function cmdExportPlaywright(rest) {
137
184
  const { positionals, flags } = parseFlags(rest);
138
- if (!positionals[0]) {
139
- process.stderr.write(`export playwright: missing <workspace-dir>\n`);
140
- return 2;
141
- }
185
+ if (!positionals[0])
186
+ return usageError("export playwright", "missing <workspace-dir>");
142
187
  const projectDir = positionals[0];
143
188
  const flow = flags.get("flow");
144
189
  const outFlag = flags.get("out");
@@ -158,11 +203,7 @@ async function cmdExportPlaywright(rest) {
158
203
  return 0;
159
204
  }
160
205
  catch (e) {
161
- if (e instanceof FlowFileError) {
162
- process.stderr.write(`export playwright: ${e.message}\n`);
163
- return 1;
164
- }
165
- process.stderr.write(`export playwright: ${e.message}\n`);
206
+ process.stderr.write(`export playwright: ${withNext(e.message, `docsxai lint ${shellQuote(projectDir)}`)}\n`);
166
207
  return 1;
167
208
  }
168
209
  }
@@ -180,10 +221,8 @@ async function copyIfExists(src, dest) {
180
221
  }
181
222
  export async function cmdBaseline(args) {
182
223
  const { positionals, flags } = parseFlags(args);
183
- if (!positionals[0]) {
184
- process.stderr.write(`baseline: missing <workspace-dir>\n`);
185
- return 2;
186
- }
224
+ if (!positionals[0])
225
+ return usageError("baseline", "missing <workspace-dir>");
187
226
  const projectDir = positionals[0];
188
227
  const outFlag = flags.get("out");
189
228
  const outDir = typeof outFlag === "string"
@@ -222,6 +261,10 @@ export async function cmdBaseline(args) {
222
261
  }
223
262
  }
224
263
  process.stdout.write(`baseline: snapshotted ${copied} file${copied === 1 ? "" : "s"} to ${outDir}\n`);
264
+ if (copied === 0) {
265
+ const note = withNext("warning — no flows/ or docs/ files found to snapshot", `docsxai run ${shellQuote(projectDir)}`);
266
+ process.stderr.write(`baseline: ${note}\n`);
267
+ }
225
268
  return 0;
226
269
  }
227
270
  catch (e) {
@@ -231,10 +274,8 @@ export async function cmdBaseline(args) {
231
274
  }
232
275
  export async function cmdDiff(args) {
233
276
  const { positionals, flags } = parseFlags(args);
234
- if (!positionals[0]) {
235
- process.stderr.write(`diff: missing <workspace-dir>\n`);
236
- return 2;
237
- }
277
+ if (!positionals[0])
278
+ return usageError("diff", "missing <workspace-dir>");
238
279
  const projectDir = positionals[0];
239
280
  const againstFlag = flags.get("against");
240
281
  const againstDir = typeof againstFlag === "string"
@@ -242,15 +283,13 @@ export async function cmdDiff(args) {
242
283
  : resolveWorkspacePath(projectDir, ".baseline");
243
284
  const format = typeof flags.get("format") === "string" ? flags.get("format") : "text";
244
285
  if (format !== "json" && format !== "md" && format !== "text") {
245
- process.stderr.write(`diff: --format must be json | md | text (got "${format}")\n`);
246
- return 2;
286
+ return usageError("diff", `--format must be json | md | text (got "${format}")`);
247
287
  }
248
288
  const failOnFlag = flags.get("fail-on");
249
289
  let failOn = null;
250
290
  if (failOnFlag !== undefined) {
251
291
  if (failOnFlag !== "warn" && failOnFlag !== "fail") {
252
- process.stderr.write(`diff: --fail-on must be warn | fail (got "${String(failOnFlag)}")\n`);
253
- return 2;
292
+ return usageError("diff", `--fail-on must be warn | fail (got "${String(failOnFlag)}")`);
254
293
  }
255
294
  failOn = failOnFlag;
256
295
  }
@@ -258,7 +297,8 @@ export async function cmdDiff(args) {
258
297
  await fs.access(path.join(againstDir, "flows"));
259
298
  }
260
299
  catch {
261
- process.stderr.write(`diff: no baseline at ${againstDir} — run \`docsxai baseline ${projectDir}\` first (or pass --against <dir>)\n`);
300
+ const note = withNext(`no baseline at ${againstDir}`, `docsxai baseline ${shellQuote(projectDir)} (or pass --against <dir>)`);
301
+ process.stderr.write(`diff: ${note}\n`);
262
302
  return 2;
263
303
  }
264
304
  try {
@@ -0,0 +1,2 @@
1
+ /** `pack` — burn, optimise, hash-name and write the screenshot pack; with `--check`, compare instead of write. */
2
+ export declare function cmdPack(args: string[]): Promise<number>;
@@ -0,0 +1,65 @@
1
+ // Screenshot-pack command — `pack` builds the hash-named, optimised PNG set plus manifest.json a
2
+ // docs site or README consumes, and `pack --check` rebuilds it in memory and compares it with the
3
+ // committed pack. The logic lives in `@docsxai/viewer` (it owns the burner); like `burn`, these
4
+ // validate the argv edge and run the viewer's command through the shared bin resolution, so the
5
+ // engine still does not depend on the viewer.
6
+ import { usageError } from "./cli-messages.js";
7
+ import { runViewerBin } from "./viewer-bin.js";
8
+ /** Parse argv against a spec. Returns the argv to pass on (flags in the order given) or the usage-error message. */
9
+ function checkArgs(args, spec) {
10
+ const rest = [];
11
+ const positionals = [];
12
+ for (let i = 0; i < args.length; i++) {
13
+ const a = args[i];
14
+ if (spec.bare.includes(a)) {
15
+ rest.push(a);
16
+ }
17
+ else if (spec.valued.includes(a)) {
18
+ const value = args[++i];
19
+ if (value === undefined || value.startsWith("--"))
20
+ return `${a} needs a value`;
21
+ rest.push(a, value);
22
+ }
23
+ else if (a.startsWith("--")) {
24
+ return `unknown flag ${a}`;
25
+ }
26
+ else {
27
+ positionals.push(a);
28
+ }
29
+ }
30
+ if (positionals.length === 0)
31
+ return "missing <workspace-or-raw-dir>";
32
+ if (positionals.length > 1)
33
+ return `unexpected argument "${positionals[1]}"`;
34
+ return { dir: positionals[0], rest };
35
+ }
36
+ /** `pack` — burn, optimise, hash-name and write the screenshot pack; with `--check`, compare instead of write. */
37
+ export async function cmdPack(args) {
38
+ if (args.includes("--check"))
39
+ return cmdPackCheck(args.filter((a) => a !== "--check"));
40
+ const parsed = checkArgs(args, {
41
+ valued: ["--out", "--public-prefix", "--generated-for"],
42
+ bare: ["--from-raw", "--no-optimise"],
43
+ });
44
+ if (typeof parsed === "string")
45
+ return usageError("pack", parsed);
46
+ return runViewerBin("pack", ["pack", parsed.dir, ...parsed.rest]);
47
+ }
48
+ /** `pack --check` — rebuild the pack in memory and compare it with the committed one. `args` has no `--check`. */
49
+ async function cmdPackCheck(args) {
50
+ const label = "pack --check";
51
+ const parsed = checkArgs(args, { valued: ["--against", "--threshold"], bare: ["--from-raw"] });
52
+ if (typeof parsed === "string")
53
+ return usageError(label, parsed);
54
+ const against = parsed.rest.indexOf("--against");
55
+ if (against === -1)
56
+ return usageError(label, "--against <pack-dir> is required");
57
+ const pct = parsed.rest.indexOf("--threshold");
58
+ if (pct !== -1) {
59
+ const value = Number(parsed.rest[pct + 1]);
60
+ if (!Number.isFinite(value) || value < 0) {
61
+ return usageError(label, "--threshold needs a percentage >= 0");
62
+ }
63
+ }
64
+ return runViewerBin(label, ["pack", parsed.dir, "--check", ...parsed.rest]);
65
+ }