@docsxai/engine 0.3.0-rc.3 → 0.3.0-rc.5

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 (181) hide show
  1. package/README.md +44 -34
  2. package/dist/atomic-write.d.ts +19 -0
  3. package/dist/atomic-write.js +127 -0
  4. package/dist/auth/api-login.d.ts +9 -51
  5. package/dist/auth/api-login.js +3 -3
  6. package/dist/auth/browser-session.js +1 -1
  7. package/dist/auth/cookie-jar.d.ts +4 -4
  8. package/dist/auth/cookie-jar.js +4 -4
  9. package/dist/auth/email-otp.d.ts +11 -147
  10. package/dist/auth/email-otp.js +4 -4
  11. package/dist/auth/http-basic.js +1 -1
  12. package/dist/auth/index.js +3 -3
  13. package/dist/auth/jwt-injection.d.ts +7 -131
  14. package/dist/auth/jwt-injection.js +5 -5
  15. package/dist/auth/manual-capture.d.ts +3 -3
  16. package/dist/auth/manual-capture.js +2 -2
  17. package/dist/auth/mtls.d.ts +1 -6
  18. package/dist/auth/mtls.js +1 -1
  19. package/dist/auth/pat-header.d.ts +1 -9
  20. package/dist/auth/pat-header.js +1 -1
  21. package/dist/auth/storage-state-cache.d.ts +16 -6
  22. package/dist/auth/storage-state-cache.js +65 -15
  23. package/dist/auth/test-backdoor.d.ts +2 -13
  24. package/dist/auth/test-backdoor.js +3 -3
  25. package/dist/auth/totp.d.ts +1 -1
  26. package/dist/auth/totp.js +4 -4
  27. package/dist/auth/types.d.ts +3 -3
  28. package/dist/auth/types.js +4 -4
  29. package/dist/auth/ui-form.d.ts +24 -153
  30. package/dist/auth/ui-form.js +3 -3
  31. package/dist/auth/webauthn.d.ts +7 -67
  32. package/dist/auth/webauthn.js +3 -3
  33. package/dist/auth.js +1 -1
  34. package/dist/backend-client-contracts.d.ts +1 -1
  35. package/dist/backend-client-contracts.js +2 -2
  36. package/dist/backend-client-oauth-login.js +1 -1
  37. package/dist/backend-client-state-cache.d.ts +2 -2
  38. package/dist/backend-client-state-cache.js +8 -8
  39. package/dist/backend-client-token.js +4 -4
  40. package/dist/backend-client-transport.d.ts +2 -2
  41. package/dist/backend-client-transport.js +3 -3
  42. package/dist/backend-client.js +6 -6
  43. package/dist/browser-build.d.ts +6 -0
  44. package/dist/browser-build.js +12 -0
  45. package/dist/browser-launch-error.d.ts +18 -0
  46. package/dist/browser-launch-error.js +63 -0
  47. package/dist/browser-wait.d.ts +7 -0
  48. package/dist/browser-wait.js +12 -0
  49. package/dist/calibrate.d.ts +6 -2
  50. package/dist/calibrate.js +20 -13
  51. package/dist/cli-backend-errors.d.ts +5 -0
  52. package/dist/cli-backend-errors.js +24 -3
  53. package/dist/cli-commands-auth.d.ts +1 -0
  54. package/dist/cli-commands-auth.js +114 -0
  55. package/dist/cli-commands-authoring.d.ts +0 -1
  56. package/dist/cli-commands-authoring.js +124 -101
  57. package/dist/cli-commands-backend.d.ts +1 -1
  58. package/dist/cli-commands-backend.js +76 -21
  59. package/dist/cli-commands-docpack.d.ts +3 -1
  60. package/dist/cli-commands-docpack.js +145 -39
  61. package/dist/cli-commands-init.d.ts +1 -0
  62. package/dist/cli-commands-init.js +100 -0
  63. package/dist/cli-commands-pack.d.ts +1 -1
  64. package/dist/cli-commands-pack.js +6 -4
  65. package/dist/cli-commands-session.d.ts +1 -3
  66. package/dist/cli-commands-session.js +109 -180
  67. package/dist/cli-commands-site.d.ts +2 -0
  68. package/dist/cli-commands-site.js +77 -0
  69. package/dist/cli-commands-style.d.ts +1 -0
  70. package/dist/cli-commands-style.js +85 -0
  71. package/dist/cli-flags.d.ts +18 -0
  72. package/dist/cli-flags.js +77 -0
  73. package/dist/cli-help.d.ts +30 -0
  74. package/dist/cli-help.js +174 -0
  75. package/dist/cli-messages.d.ts +30 -0
  76. package/dist/cli-messages.js +97 -0
  77. package/dist/cli-node-guard.d.ts +1 -0
  78. package/dist/cli-node-guard.js +8 -0
  79. package/dist/cli-retired.js +6 -0
  80. package/dist/cli-run-stale.d.ts +2 -0
  81. package/dist/cli-run-stale.js +13 -0
  82. package/dist/cli-run-summary.js +7 -3
  83. package/dist/cli-shared.d.ts +30 -1
  84. package/dist/cli-shared.js +112 -12
  85. package/dist/cli-unexpected.d.ts +12 -2
  86. package/dist/cli-unexpected.js +50 -4
  87. package/dist/cli-usage.d.ts +1 -1
  88. package/dist/cli-usage.js +115 -66
  89. package/dist/cli-value-flags.d.ts +8 -0
  90. package/dist/cli-value-flags.js +34 -0
  91. package/dist/cli-version.d.ts +6 -0
  92. package/dist/cli-version.js +25 -0
  93. package/dist/cli.d.ts +1 -0
  94. package/dist/cli.js +42 -19
  95. package/dist/deprecation.d.ts +2 -0
  96. package/dist/deprecation.js +2 -0
  97. package/dist/device-scale-factor.d.ts +14 -0
  98. package/dist/device-scale-factor.js +38 -0
  99. package/dist/diagnose.js +14 -13
  100. package/dist/diff-compute.js +22 -8
  101. package/dist/diff-report.js +3 -3
  102. package/dist/diff-types.js +1 -1
  103. package/dist/diff.js +3 -3
  104. package/dist/doc-pack-io.js +62 -47
  105. package/dist/doc-pack.d.ts +567 -3487
  106. package/dist/doc-pack.js +47 -33
  107. package/dist/doctor-checks-config.d.ts +12 -0
  108. package/dist/doctor-checks-config.js +229 -0
  109. package/dist/doctor-checks-plugins.js +2 -2
  110. package/dist/doctor-checks-site.d.ts +3 -0
  111. package/dist/doctor-checks-site.js +21 -0
  112. package/dist/doctor-checks.d.ts +13 -2
  113. package/dist/doctor-checks.js +94 -79
  114. package/dist/doctor-next.d.ts +5 -0
  115. package/dist/doctor-next.js +52 -0
  116. package/dist/doctor.d.ts +36 -2
  117. package/dist/doctor.js +88 -29
  118. package/dist/environment-spec.d.ts +36 -44
  119. package/dist/environment-spec.js +31 -3
  120. package/dist/export/adf.d.ts +1 -1
  121. package/dist/export/adf.js +16 -27
  122. package/dist/export/playwright-test.d.ts +1 -1
  123. package/dist/export/playwright-test.js +13 -15
  124. package/dist/flow-file.d.ts +1 -1
  125. package/dist/flow-file.js +22 -4
  126. package/dist/flow-halt.d.ts +1 -1
  127. package/dist/flow-halt.js +15 -3
  128. package/dist/flow-lint.d.ts +3 -1
  129. package/dist/flow-lint.js +39 -26
  130. package/dist/flow-matrix-lint.js +2 -2
  131. package/dist/flow-runtime.d.ts +17 -6
  132. package/dist/flow-runtime.js +48 -17
  133. package/dist/flow-success.js +4 -4
  134. package/dist/flow-tree.js +2 -2
  135. package/dist/index.d.ts +2 -0
  136. package/dist/index.js +2 -0
  137. package/dist/main-module.d.ts +1 -0
  138. package/dist/main-module.js +17 -0
  139. package/dist/matrix-spec.d.ts +33 -106
  140. package/dist/matrix-spec.js +12 -3
  141. package/dist/node-floor.d.ts +4 -0
  142. package/dist/node-floor.js +14 -0
  143. package/dist/obstacles.js +1 -1
  144. package/dist/open-in-browser.d.ts +22 -0
  145. package/dist/open-in-browser.js +37 -0
  146. package/dist/playwright-driver.d.ts +8 -12
  147. package/dist/playwright-driver.js +75 -70
  148. package/dist/playwright-instrumented-browser.d.ts +10 -7
  149. package/dist/playwright-instrumented-browser.js +35 -12
  150. package/dist/plugins/load.d.ts +1 -1
  151. package/dist/plugins/load.js +4 -4
  152. package/dist/plugins/lock.js +11 -8
  153. package/dist/plugins/manifest.d.ts +16 -35
  154. package/dist/plugins/manifest.js +5 -5
  155. package/dist/plugins/plan.d.ts +3 -3
  156. package/dist/plugins/plan.js +14 -14
  157. package/dist/plugins/registry.d.ts +1 -1
  158. package/dist/plugins/registry.js +1 -1
  159. package/dist/plugins/runtime.js +3 -3
  160. package/dist/plugins/types.d.ts +1 -1
  161. package/dist/plugins-cli.js +36 -28
  162. package/dist/posix-path.d.ts +2 -0
  163. package/dist/posix-path.js +7 -0
  164. package/dist/redact.js +2 -2
  165. package/dist/run-flows.d.ts +7 -0
  166. package/dist/run-flows.js +75 -27
  167. package/dist/style.d.ts +2 -2
  168. package/dist/style.js +13 -11
  169. package/dist/verify-determinism.js +2 -1
  170. package/dist/verify-next-step.d.ts +2 -0
  171. package/dist/verify-next-step.js +24 -0
  172. package/dist/verify-report.js +3 -2
  173. package/dist/viewer-bin.d.ts +9 -3
  174. package/dist/viewer-bin.js +35 -12
  175. package/dist/workspace-templates.d.ts +15 -0
  176. package/dist/workspace-templates.js +88 -0
  177. package/dist/workspace.d.ts +78 -5
  178. package/dist/workspace.js +47 -28
  179. package/dist/zip.d.ts +1 -1
  180. package/dist/zip.js +23 -6
  181. package/package.json +6 -6
@@ -1,17 +1,18 @@
1
1
  // Resolution of the `docsxai-viewer` bin for `docsxai render`. The viewer is its own package and
2
2
  // the engine doesn't depend on it at build time, so the bin is located at run time, in order:
3
3
  //
4
- // 1. `DOCSX_VIEWER_BIN` — explicit operator override; a path to the viewer's bin script
4
+ // 1. `DOCSX_VIEWER_BIN`, explicit operator override; a path to the viewer's bin script
5
5
  // (run with the current Node when it's a `.js`/`.mjs`/`.cjs` file) or to an executable.
6
6
  // 2. The `@docsxai/viewer` package installed next to the engine: its `package.json` is
7
7
  // looked up along the engine's node_modules ancestor chain and the `bin` entry is run with
8
- // the current Node — covers installs where the package is present but no PATH shim is.
9
- // (A direct manifest read, not `require.resolve("…/package.json")` — the viewer's `exports`
8
+ // the current Node, covers installs where the package is present but no PATH shim is.
9
+ // (A direct manifest read, not `require.resolve("…/package.json")`, the viewer's `exports`
10
10
  // map doesn't export its package.json. The chain is walked explicitly rather than via
11
11
  // `require.resolve.paths()`, which test runners extend with extra lookup dirs.)
12
- // 3. `docsxai-viewer` on PATH (the npm bin shim) — the legacy behavior, kept as the fallback.
12
+ // 3. `docsxai-viewer` on PATH (the npm bin shim), the legacy behavior, kept as the fallback.
13
13
  import { spawn } from "node:child_process";
14
14
  import { promises as fs } from "node:fs";
15
+ import { constants as osConstants } from "node:os";
15
16
  import * as path from "node:path";
16
17
  import { fileURLToPath } from "node:url";
17
18
  export const VIEWER_BIN_ENV = "DOCSX_VIEWER_BIN";
@@ -60,7 +61,7 @@ export async function resolveViewerBin(opts = {}) {
60
61
  attempts.push(`$${VIEWER_BIN_ENV} → ${envBin} (no such file)`);
61
62
  }
62
63
  else {
63
- attempts.push(`$${VIEWER_BIN_ENV} — not set`);
64
+ attempts.push(`$${VIEWER_BIN_ENV}: not set`);
64
65
  }
65
66
  const searchDirs = opts.resolveFrom
66
67
  ? opts.resolveFrom.map((d) => path.join(d, "node_modules"))
@@ -75,31 +76,48 @@ export async function resolveViewerBin(opts = {}) {
75
76
  attempts.push(`${VIEWER_PACKAGE} (installed package) → ${binAbs}`);
76
77
  return { command: process.execPath, prefixArgs: [binAbs], source: "package", attempts };
77
78
  }
78
- attempts.push(`${VIEWER_PACKAGE} (installed package) → ${binAbs} (bin file missing — is the package built?)`);
79
+ attempts.push(`${VIEWER_PACKAGE} (installed package) → ${binAbs} (bin file missing; is the package built?)`);
79
80
  }
80
81
  else {
81
82
  attempts.push(`${VIEWER_PACKAGE} (installed package) → ${manifestPath} (no "${VIEWER_BIN_NAME}" bin entry)`);
82
83
  }
83
84
  }
84
85
  else {
85
- attempts.push(`${VIEWER_PACKAGE} (installed package) — not found next to the engine`);
86
+ attempts.push(`${VIEWER_PACKAGE} (installed package): not found next to the engine`);
86
87
  }
87
88
  attempts.push(`\`${VIEWER_BIN_NAME}\` on PATH`);
88
89
  return { command: VIEWER_BIN_NAME, prefixArgs: [], source: "path", attempts };
89
90
  }
90
91
  /** Failure message for when the resolved command could not be launched (spawn ENOENT). */
91
92
  export function formatViewerBinFailure(resolution) {
92
- const lines = resolution.attempts.map((a, i, all) => ` ${i + 1}. ${a}${i === all.length - 1 ? " — not found" : ""}`);
93
+ const lines = resolution.attempts.map((a, i, all) => ` ${i + 1}. ${a}${i === all.length - 1 ? ": not found" : ""}`);
93
94
  return [
94
95
  `\`${VIEWER_BIN_NAME}\` could not be launched. Tried, in order:`,
95
96
  ...lines,
96
97
  `Install ${VIEWER_PACKAGE} next to the engine (or globally), or point ${VIEWER_BIN_ENV} at its bin script.`,
97
98
  ].join("\n");
98
99
  }
100
+ /** Viewer children that are running now, so a signal sent to the engine can reach them. */
101
+ const runningViewers = new Set();
99
102
  /**
100
- * Run the viewer's CLI with `args` and resolve to its exit code. The viewer is its own package/bin;
101
- * spawning it keeps the engine from depending on it at build time. `label` prefixes the failure
102
- * line when the bin can't be launched.
103
+ * Send `signal` to every viewer child that is running. Returns false when none is, so the caller
104
+ * can end the process itself; true means a child got the signal and {@link runViewerBin} resolves
105
+ * once it has exited.
106
+ */
107
+ export function forwardSignalToViewer(signal) {
108
+ let sent = false;
109
+ for (const child of runningViewers)
110
+ sent = child.kill(signal) || sent;
111
+ return sent;
112
+ }
113
+ /** The exit code a shell reports for a process the signal ended: 128 plus the signal number. */
114
+ function signalExitCode(signal) {
115
+ return 128 + (osConstants.signals[signal] ?? 1);
116
+ }
117
+ /**
118
+ * Run the viewer's CLI with `args` and resolve to its exit code, or 128 plus the signal number
119
+ * when a signal ended it. The viewer is its own package/bin; spawning it keeps the engine from
120
+ * depending on it at build time. `label` prefixes the failure line when the bin can't be launched.
103
121
  */
104
122
  export async function runViewerBin(label, args) {
105
123
  const viewerBin = await resolveViewerBin();
@@ -107,7 +125,9 @@ export async function runViewerBin(label, args) {
107
125
  const child = spawn(viewerBin.command, [...viewerBin.prefixArgs, ...args], {
108
126
  stdio: "inherit",
109
127
  });
128
+ runningViewers.add(child);
110
129
  child.on("error", (e) => {
130
+ runningViewers.delete(child);
111
131
  if (e.code === "ENOENT") {
112
132
  process.stderr.write(`${label}: ${formatViewerBinFailure(viewerBin)}\n`);
113
133
  }
@@ -116,6 +136,9 @@ export async function runViewerBin(label, args) {
116
136
  }
117
137
  resolve(1);
118
138
  });
119
- child.on("exit", (code) => resolve(code ?? 1));
139
+ child.on("exit", (code, signal) => {
140
+ runningViewers.delete(child);
141
+ resolve(code ?? (signal ? signalExitCode(signal) : 1));
142
+ });
120
143
  });
121
144
  }
@@ -0,0 +1,15 @@
1
+ import type { WorkspaceConfig } from "./workspace.js";
2
+ /** Where the sample flow lands. The `.sample` suffix keeps `run`, `lint` and `render` from loading it. */
3
+ export declare const SAMPLE_FLOW_PATH = "flows/example.flow.yaml.sample";
4
+ export declare const SAMPLE_FLOW = "# Sample flow-file. Edit the locators and steps for your app, then:\n# docsxai add-flow . --from flows/example.flow.yaml.sample\n# which writes flows/example.flow.yaml. Full format: docs/agent-runbook.md in the docsxai repo.\nname: example\nlocators:\n heading: h1\nsteps:\n - id: open-home\n action: navigate\n value: / # a path resolved against app_url in .docsxai.json\n wait_for: load\n success: { visible: $heading }\n - id: point-at-heading\n action: hover\n target: $heading\n success: { visible: $heading }\n";
5
+ /** The site `init --example` documents: public, no login. */
6
+ export declare const EXAMPLE_APP_URL = "https://example.com";
7
+ /** Where `init --example` writes its flow. */
8
+ export declare const EXAMPLE_FLOW_PATH = "flows/hello.flow.yaml";
9
+ /** The README's hello flow: open the home page and point at its English paragraph (the page has no heading). */
10
+ export declare const EXAMPLE_FLOW = "# Written by docsxai init --example. Run it, then build the viewer:\n# docsxai run .\n# docsxai render . --open\nname: hello\nlocators:\n text: 'p[lang=\"en\"]'\nsteps:\n - id: open-home\n action: navigate\n value: /\n wait_for: load\n success: { visible: $text }\n annotation: { copy: \"This is the page text\", target: $text, arrow: bottom }\n";
11
+ export interface ReadmeOptions {
12
+ auth: "manual-capture" | "none";
13
+ configFile: string;
14
+ }
15
+ export declare function workspaceReadme(cfg: WorkspaceConfig, opts: ReadmeOptions): string;
@@ -0,0 +1,88 @@
1
+ // Text of the files `docsxai init` scaffolds: the workspace README and the sample flow-file.
2
+ // Kept apart from workspace.ts so commands and keys named here are easy to review against
3
+ // `docsxai --help`.
4
+ /** Where the sample flow lands. The `.sample` suffix keeps `run`, `lint` and `render` from loading it. */
5
+ export const SAMPLE_FLOW_PATH = "flows/example.flow.yaml.sample";
6
+ export const SAMPLE_FLOW = `# Sample flow-file. Edit the locators and steps for your app, then:
7
+ # docsxai add-flow . --from ${SAMPLE_FLOW_PATH}
8
+ # which writes flows/example.flow.yaml. Full format: docs/agent-runbook.md in the docsxai repo.
9
+ name: example
10
+ locators:
11
+ heading: h1
12
+ steps:
13
+ - id: open-home
14
+ action: navigate
15
+ value: / # a path resolved against app_url in .docsxai.json
16
+ wait_for: load
17
+ success: { visible: $heading }
18
+ - id: point-at-heading
19
+ action: hover
20
+ target: $heading
21
+ success: { visible: $heading }
22
+ `;
23
+ /** The site `init --example` documents: public, no login. */
24
+ export const EXAMPLE_APP_URL = "https://example.com";
25
+ /** Where `init --example` writes its flow. */
26
+ export const EXAMPLE_FLOW_PATH = "flows/hello.flow.yaml";
27
+ /** The README's hello flow: open the home page and point at its English paragraph (the page has no heading). */
28
+ export const EXAMPLE_FLOW = `# Written by docsxai init --example. Run it, then build the viewer:
29
+ # docsxai run .
30
+ # docsxai render . --open
31
+ name: hello
32
+ locators:
33
+ text: 'p[lang="en"]'
34
+ steps:
35
+ - id: open-home
36
+ action: navigate
37
+ value: /
38
+ wait_for: load
39
+ success: { visible: $text }
40
+ annotation: { copy: "This is the page text", target: $text, arrow: bottom }
41
+ `;
42
+ export function workspaceReadme(cfg, opts) {
43
+ const login = opts.auth === "manual-capture";
44
+ const authLine = login
45
+ ? "- `auth/strategy.yaml`, how execution authenticates to the app\n- `.auth/<role>.json`, captured session(s) (gitignored; never committed; never leaves this machine)"
46
+ : "- no `auth/` descriptor: this workspace was made with `--auth none`, so flows run without a login";
47
+ const steps = [
48
+ "docsxai doctor . # check Node, Chromium, this config and app_url reachability",
49
+ ...(login
50
+ ? [
51
+ "docsxai capture-auth . # opens an instrumented browser; log in, then run window.__docsxai.capture()",
52
+ ]
53
+ : []),
54
+ `docsxai add-flow . --from ${SAMPLE_FLOW_PATH} # edit the sample first, or pass a flow-file you wrote`,
55
+ "docsxai run . # replay the flow-files headlessly; refresh annotations + screenshots",
56
+ "docsxai render . && open .viewer/index.html",
57
+ ];
58
+ return `# docsxai workspace
59
+
60
+ This directory is a **docsxai workspace**, it holds the doc pack for one running app:
61
+
62
+ - \`flows/<flow>.flow.yaml\`, hand-editable flow-files (the source of truth for execution)
63
+ - \`${SAMPLE_FLOW_PATH}\`: a sample flow-file to copy from (ignored until you add it with add-flow)
64
+ - \`docs/<flow>/{annotations.json, screenshots/, <step>.md}\`, \`docs/{style.yaml, locators.yaml}\`, the generated docs
65
+ ${authLine}
66
+ - \`.viewer/\`, the generated interactive viewer (gitignored)
67
+ - \`${opts.configFile}\`, workspace config (\`app_url${cfg.app_url ? ` = ${cfg.app_url}` : ""}\`, \`ignore_https_errors = ${!!cfg.ignore_https_errors}\`)
68
+
69
+ **Do NOT place this directory inside the app's source repo.** docsxai documents the *running* app from outside;
70
+ keeping the workspace separate is what guarantees zero traces in the app repo.
71
+ ${login ? "\nThe app needs no login? Scaffold with `docsxai init <dir> --auth none` and skip `capture-auth`.\n" : ""}
72
+ Usage (from this directory):
73
+
74
+ \`\`\`
75
+ ${steps.join("\n")}
76
+ \`\`\`
77
+
78
+ ## Optional: caption theme
79
+
80
+ Add a \`burn.theme\` block to \`${opts.configFile}\` to restyle burned captions and the viewer overlay:
81
+
82
+ \`\`\`json
83
+ { "burn": { "theme": { "preset": "readable", "accent": "#0b6e4f" } } }
84
+ \`\`\`
85
+
86
+ Presets: \`clean\`, \`soft\`, \`high-contrast\`, \`readable\`. \`docsxai burn .\` lists theme problems and contrast warnings. Keys: docs/burn-theming.md in the docsxai repo.
87
+ `;
88
+ }
@@ -11,16 +11,85 @@ export declare function resolveWorkspacePath(workspaceDir: string, ...segments:
11
11
  * Like {@link resolveWorkspacePath}, but additionally defends against symlink escape: the deepest
12
12
  * existing ancestor of the resolved path is realpath'd and containment re-verified against the
13
13
  * realpath'd workspace root. Use before writing to a path whose segments are user-influenced
14
- * (flow names, step ids, role names) — a symlink inside the workspace pointing outside must throw.
14
+ * (flow names, step ids, role names), a symlink inside the workspace pointing outside must throw.
15
15
  */
16
16
  export declare function resolveWorkspacePathReal(workspaceDir: string, ...segments: string[]): Promise<string>;
17
+ /**
18
+ * The bytes of a workspace file, or `null` when it is missing or reaches outside the workspace
19
+ * through a symlink. For reads whose content leaves the machine (a push, an export): a linked
20
+ * file must not be read.
21
+ */
22
+ export declare function readFileInside(workspaceDir: string, ...segments: string[]): Promise<Buffer | null>;
23
+ /**
24
+ * The names of the workspace's `flows/<name>.flow.yaml` files, sorted. A flow file that is a
25
+ * symlink to somewhere outside the workspace is left out.
26
+ */
27
+ export declare function listFlowNamesInside(workspaceDir: string): Promise<string[]>;
28
+ /**
29
+ * The `burn.theme` block: the look of burned captions and of the viewer's overlay. Every key is
30
+ * optional; no block means the original look. `@docsxai/viewer` checks the values and layers them
31
+ * (default look, then `preset`, then the tokens file named by `from`, then the keys written here).
32
+ * Keys, ranges and the token mapping: docs/burn-theming.md.
33
+ */
34
+ export interface BurnThemeConfig {
35
+ /** `clean`, `soft`, `high-contrast` or `readable`. */
36
+ preset?: string;
37
+ /** Tokens file (W3C design tokens or a flat map), relative to the workspace. */
38
+ from?: string;
39
+ /** Theme key to token path, for keys that must be found in the tokens file. */
40
+ tokens?: Record<string, string>;
41
+ accent?: string;
42
+ ink?: string;
43
+ callout_background?: string;
44
+ callout_border_color?: string;
45
+ callout_border_width?: number;
46
+ radius?: number;
47
+ /** A CSS box-shadow, or `none`. */
48
+ shadow?: string;
49
+ /** `circle`, `rounded` or `square`. */
50
+ badge_shape?: string;
51
+ badge_fill?: string;
52
+ font_size?: number;
53
+ line_height?: number;
54
+ padding_x?: number;
55
+ padding_y?: number;
56
+ /** TTF or OTF file inside the workspace; the bundled Inter when unset. */
57
+ font?: string;
58
+ /**
59
+ * Up to 8 TTF or OTF files inside the workspace, tried in order for characters `font` lacks,
60
+ * before the bundled Noto Sans Arabic, Hebrew, Thai and Devanagari. Burned images only.
61
+ */
62
+ font_fallback?: string[];
63
+ /** 400 or 600; the font file must have that weight (the bundled Inter is 400 only). */
64
+ font_weight?: number;
65
+ /** `auto`, `line`, `chevron` or `arrow`: how a callout joins its target. */
66
+ connector_style?: string;
67
+ /** `full`, `badge` or `auto`: caption, or numbered badge only. */
68
+ caption_style?: string;
69
+ /** Arrow length in px, 4 to 24. */
70
+ arrow_size?: number;
71
+ /** Widest callout as a share of the screenshot's width, 0.2 to 1. */
72
+ max_width_ratio?: number;
73
+ /** Multiplier of every caption dimension, 0.5 to 4, or `"auto"` (screenshot width over `display_width`, 1 to 4). */
74
+ scale?: number | "auto";
75
+ /**
76
+ * CSS px the screenshot is shown at on the docs page, 240 to 2400. Read by `scale: "auto"`.
77
+ * The object form picks `narrow` for screenshots narrower than `narrow_below` px (default 900)
78
+ * and `default` (720 when absent) for the rest.
79
+ */
80
+ display_width?: number | {
81
+ default?: number;
82
+ narrow: number;
83
+ narrow_below?: number;
84
+ };
85
+ }
17
86
  export interface WorkspaceConfig {
18
87
  schema: "docsxai/workspace@1";
19
88
  /** Base URL of the running app this workspace documents. Used as the default for `run`/`capture-auth`. */
20
89
  app_url?: string;
21
90
  /** Accept self-signed/invalid TLS for `app_url` (e.g. a local HTTPS dev cert). */
22
91
  ignore_https_errors?: boolean;
23
- /** Backend stub/service URL for `push`/`pull` (e.g. `http://localhost:4477`). Optional — workspaces operate fully locally without it. */
92
+ /** Backend stub/service URL for `push`/`pull` (e.g. `http://localhost:4477`). Optional, workspaces operate fully locally without it. */
24
93
  backend_url?: string;
25
94
  /** How `run` records annotations. Absent keys keep today's output. */
26
95
  annotations?: {
@@ -30,6 +99,10 @@ export interface WorkspaceConfig {
30
99
  */
31
100
  obstacles?: boolean;
32
101
  };
102
+ /** How `burn`, `pack` and `render` draw captions. Absent keys keep today's look. */
103
+ burn?: {
104
+ theme?: BurnThemeConfig;
105
+ };
33
106
  /** Backend workspace ID, set by `push` after first round-trip. */
34
107
  backend_workspace_id?: string;
35
108
  /** Backend project ID, set by `push` after first round-trip. */
@@ -42,12 +115,12 @@ export interface InitWorkspaceOptions {
42
115
  /** Create the workspace in a throwaway temp dir instead of `dir`. */
43
116
  persistTmp?: boolean;
44
117
  appUrl?: string;
45
- /** `manual-capture` (default) writes an `auth/strategy.yaml`; `none` skips it. */
118
+ /** `manual-capture` (default) writes an `auth/strategy.yaml`; `none` skips it, for an app that needs no login. */
46
119
  auth?: "manual-capture" | "none";
47
120
  role?: string;
48
- /** Cache TTL for the captured session (`session`, or a duration like `1h`/`30m`). Default `1h` — a *fallback* used only when `authCookie` isn't set/found. */
121
+ /** Cache TTL for the captured session (`session`, or a duration like `1h`/`30m`). Default `1h`, a *fallback* used only when `authCookie` isn't set/found. */
49
122
  ttl?: string;
50
- /** Name of the app's auth/session cookie — when set, the cached session's expiry tracks this cookie, not `ttl`. */
123
+ /** Name of the app's auth/session cookie, when set, the cached session's expiry tracks this cookie, not `ttl`. */
51
124
  authCookie?: string;
52
125
  captureTrigger?: "console" | "button";
53
126
  ignoreHttpsErrors?: boolean;
package/dist/workspace.js CHANGED
@@ -2,7 +2,7 @@
2
2
  //
3
3
  // A *workspace* is the directory docsxai reads/writes for a project: `flows/`, `docs/`, `auth/`, plus
4
4
  // (gitignored) `.auth/` and `.viewer/`, plus a small `.docsxai.json` config so `run`/`render`/`capture-auth`
5
- // don't need `--base-url` / `--ignore-https-errors` on every call. **It must live outside the app repo** — docsxai
5
+ // don't need `--base-url` / `--ignore-https-errors` on every call. **It must live outside the app repo**, docsxai
6
6
  // operates *on* a running app from outside; it never writes into the app's source tree.
7
7
  //
8
8
  // `docsxai init <dir> --app-url <url>` scaffolds one; `--persist tmp` puts it in a throwaway temp dir.
@@ -10,6 +10,7 @@ import { promises as fs } from "node:fs";
10
10
  import * as os from "node:os";
11
11
  import * as path from "node:path";
12
12
  import { stringify as stringifyYaml } from "yaml";
13
+ import { SAMPLE_FLOW, SAMPLE_FLOW_PATH, workspaceReadme } from "./workspace-templates.js";
13
14
  export const WORKSPACE_CONFIG_FILE = ".docsxai.json";
14
15
  /** Thrown when a workspace-relative path resolves outside the workspace root. */
15
16
  export class WorkspacePathEscapeError extends Error {
@@ -47,7 +48,7 @@ async function realpathDeepestExisting(p) {
47
48
  catch {
48
49
  const parent = path.dirname(probe);
49
50
  if (parent === probe)
50
- return p; // not even the filesystem root resolves — give up lexically
51
+ return p; // not even the filesystem root resolves, give up lexically
51
52
  suffix = suffix ? path.join(path.basename(probe), suffix) : path.basename(probe);
52
53
  probe = parent;
53
54
  }
@@ -57,7 +58,7 @@ async function realpathDeepestExisting(p) {
57
58
  * Like {@link resolveWorkspacePath}, but additionally defends against symlink escape: the deepest
58
59
  * existing ancestor of the resolved path is realpath'd and containment re-verified against the
59
60
  * realpath'd workspace root. Use before writing to a path whose segments are user-influenced
60
- * (flow names, step ids, role names) — a symlink inside the workspace pointing outside must throw.
61
+ * (flow names, step ids, role names), a symlink inside the workspace pointing outside must throw.
61
62
  */
62
63
  export async function resolveWorkspacePathReal(workspaceDir, ...segments) {
63
64
  const resolved = resolveWorkspacePath(workspaceDir, ...segments);
@@ -66,29 +67,45 @@ export async function resolveWorkspacePathReal(workspaceDir, ...segments) {
66
67
  assertContained(rootReal, resolvedReal);
67
68
  return resolved;
68
69
  }
69
- const README = (cfg) => `# docsxai workspace
70
-
71
- This directory is a **docsxai workspace** — it holds the doc pack for one running app:
72
-
73
- - \`flows/<flow>.flow.yaml\` — hand-editable flow-files (the source of truth for execution)
74
- - \`docs/<flow>/{annotations.json, screenshots/, <step>.md}\`, \`docs/{style.yaml, locators.yaml}\` — the generated docs
75
- - \`auth/strategy.yaml\` — how execution authenticates to the app
76
- - \`.auth/<role>.json\` — captured session(s) (gitignored; never committed; never leaves this machine)
77
- - \`.viewer/\` — the generated interactive viewer (gitignored)
78
- - \`${WORKSPACE_CONFIG_FILE}\` — workspace config (\`app_url${cfg.app_url ? ` = ${cfg.app_url}` : ""}\`, \`ignore_https_errors = ${!!cfg.ignore_https_errors}\`)
79
-
80
- **Do NOT place this directory inside the app's source repo.** docsxai documents the *running* app from outside;
81
- keeping the workspace separate is what guarantees zero traces in the app repo.
82
-
83
- Usage (from this directory):
84
-
85
- \`\`\`
86
- docsxai capture-auth . # if auth is manual-capture: opens an instrumented browser; log in, then run window.__docsxai.capture()
87
- docsxai calibrate . --description path/to/flow.md # (when the calibration stages land) produce/refresh flow-files
88
- docsxai run . # replay the flow-files headlessly; refresh annotations + screenshots
89
- docsxai render . && open .viewer/index.html
90
- \`\`\`
91
- `;
70
+ /**
71
+ * The bytes of a workspace file, or `null` when it is missing or reaches outside the workspace
72
+ * through a symlink. For reads whose content leaves the machine (a push, an export): a linked
73
+ * file must not be read.
74
+ */
75
+ export async function readFileInside(workspaceDir, ...segments) {
76
+ let abs;
77
+ try {
78
+ abs = await resolveWorkspacePathReal(workspaceDir, ...segments);
79
+ }
80
+ catch (e) {
81
+ if (e instanceof WorkspacePathEscapeError)
82
+ return null;
83
+ throw e;
84
+ }
85
+ return fs.readFile(abs).catch(() => null);
86
+ }
87
+ /**
88
+ * The names of the workspace's `flows/<name>.flow.yaml` files, sorted. A flow file that is a
89
+ * symlink to somewhere outside the workspace is left out.
90
+ */
91
+ export async function listFlowNamesInside(workspaceDir) {
92
+ const entries = await fs
93
+ .readdir(resolveWorkspacePath(workspaceDir, "flows"))
94
+ .catch(() => []);
95
+ const names = [];
96
+ for (const e of entries) {
97
+ if (!e.endsWith(".flow.yaml"))
98
+ continue;
99
+ const abs = await resolveWorkspacePathReal(workspaceDir, "flows", e).catch((err) => {
100
+ if (err instanceof WorkspacePathEscapeError)
101
+ return null;
102
+ throw err;
103
+ });
104
+ if (abs !== null)
105
+ names.push(e.slice(0, -".flow.yaml".length));
106
+ }
107
+ return names.sort();
108
+ }
92
109
  async function isNonEmptyDir(p) {
93
110
  try {
94
111
  const entries = await fs.readdir(p);
@@ -111,7 +128,7 @@ export async function initWorkspace(opts) {
111
128
  throw new Error("init: a target directory is required (or use --persist tmp)");
112
129
  dir = path.resolve(opts.dir);
113
130
  if (!opts.force && (await isNonEmptyDir(dir))) {
114
- throw new Error(`init: ${dir} exists and is not empty — pick another dir or pass --force`);
131
+ throw new Error(`init: ${dir} exists and is not empty; pick another dir or pass --force`);
115
132
  }
116
133
  }
117
134
  const role = opts.role ?? "editor";
@@ -153,7 +170,9 @@ export async function initWorkspace(opts) {
153
170
  await fs.writeFile(resolveWorkspacePath(dir, "auth", "strategy.yaml"), stringifyYaml(descriptor, { lineWidth: 100 }), "utf8");
154
171
  created.push("auth/strategy.yaml");
155
172
  }
156
- await fs.writeFile(resolveWorkspacePath(dir, "README.md"), README(cfg), "utf8");
173
+ await fs.writeFile(resolveWorkspacePath(dir, SAMPLE_FLOW_PATH), SAMPLE_FLOW, "utf8");
174
+ created.push(SAMPLE_FLOW_PATH);
175
+ await fs.writeFile(resolveWorkspacePath(dir, "README.md"), workspaceReadme(cfg, { auth, configFile: WORKSPACE_CONFIG_FILE }), "utf8");
157
176
  created.push("README.md");
158
177
  return { dir, created, ephemeral };
159
178
  }
package/dist/zip.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export interface ZipOptions {
2
2
  workspace: string;
3
3
  output: string;
4
- /** Include the rendered viewer (`.viewer/`) in the archive. Default false — viewers are derived from the doc pack and re-rendering is cheap. */
4
+ /** Include the rendered viewer (`.viewer/`) in the archive. Default false, viewers are derived from the doc pack and re-rendering is cheap. */
5
5
  includeViewer?: boolean;
6
6
  }
7
7
  export interface ZipResult {
package/dist/zip.js CHANGED
@@ -1,4 +1,4 @@
1
- // Package a workspace's doc pack into a single archive for hand-off. Zips in-process (fflate) —
1
+ // Package a workspace's doc pack into a single archive for hand-off. Zips in-process (fflate),
2
2
  // no system `zip` binary required. Excludes operator-local state (`.auth/`, halt screenshots, the
3
3
  // rendered `.viewer/` by default) so the archive is reviewer-ready without manual cleanup.
4
4
  //
@@ -8,6 +8,7 @@
8
8
  import { promises as fs } from "node:fs";
9
9
  import * as path from "node:path";
10
10
  import { zipSync } from "fflate";
11
+ import { writeFileAtomic } from "./atomic-write.js";
11
12
  import { resolveWorkspacePath, resolveWorkspacePathReal, WorkspacePathEscapeError, } from "./workspace.js";
12
13
  export class ZipError extends Error {
13
14
  cause;
@@ -22,7 +23,11 @@ const FIXED_MTIME = new Date(1980, 0, 1);
22
23
  const FIXED_LEVEL = 6;
23
24
  function isExcluded(relPath, includeViewer) {
24
25
  const segments = relPath.split("/");
25
- if (segments.includes(".auth") || segments.includes("halts"))
26
+ if (segments.includes(".auth"))
27
+ return true;
28
+ // Halt context sits under `docs/<flow>[/<variant>]/halts/`. The segment after `docs` is the flow's
29
+ // name, so a flow called `halts` keeps its own outputs.
30
+ if (segments.indexOf("halts", segments[0] === "docs" ? 2 : 0) !== -1)
26
31
  return true;
27
32
  if (!includeViewer && segments[0] === ".viewer")
28
33
  return true;
@@ -46,7 +51,7 @@ async function collectFiles(workspace, relDir, includeViewer, out) {
46
51
  }
47
52
  else if (entry.isSymbolicLink()) {
48
53
  // The archive is a hand-off artifact: follow a symlink only if its target stays inside the
49
- // workspace — a link escaping the root must not exfiltrate whatever it points at.
54
+ // workspace: a link escaping the root must not exfiltrate whatever it points at.
50
55
  let stat;
51
56
  try {
52
57
  await resolveWorkspacePathReal(workspace, rel);
@@ -55,7 +60,7 @@ async function collectFiles(workspace, relDir, includeViewer, out) {
55
60
  catch (e) {
56
61
  if (e instanceof WorkspacePathEscapeError)
57
62
  continue;
58
- continue; // broken symlink — nothing to archive
63
+ continue; // broken symlink, nothing to archive
59
64
  }
60
65
  if (stat.isDirectory())
61
66
  await collectFiles(workspace, rel, includeViewer, out);
@@ -73,7 +78,9 @@ export async function zipDocPack(opts) {
73
78
  throw new ZipError(`workspace doesn't exist: ${workspace}`);
74
79
  }
75
80
  const outAbs = path.resolve(output);
76
- await fs.mkdir(path.dirname(outAbs), { recursive: true });
81
+ if ((await fs.stat(outAbs).catch(() => null))?.isDirectory()) {
82
+ throw new ZipError(`${output} is a directory, but --out needs a .zip file path`);
83
+ }
77
84
  const includesAll = includeViewer ? [...DEFAULT_INCLUDES, ".viewer/"] : DEFAULT_INCLUDES;
78
85
  const files = [];
79
86
  let anyIncludePresent = false;
@@ -86,6 +93,15 @@ export async function zipDocPack(opts) {
86
93
  catch {
87
94
  continue; // skip absent
88
95
  }
96
+ try {
97
+ // A top-level entry that is a link out of the workspace is left out, like one found below it.
98
+ await resolveWorkspacePathReal(workspace, rel);
99
+ }
100
+ catch (e) {
101
+ if (e instanceof WorkspacePathEscapeError)
102
+ continue;
103
+ throw e;
104
+ }
89
105
  anyIncludePresent = true;
90
106
  if (stat.isDirectory())
91
107
  await collectFiles(workspace, rel, includeViewer, files);
@@ -108,6 +124,7 @@ export async function zipDocPack(opts) {
108
124
  catch (e) {
109
125
  throw new ZipError(`failed to build archive: ${e.message}`, e);
110
126
  }
111
- await fs.writeFile(outAbs, bytes);
127
+ await fs.mkdir(path.dirname(outAbs), { recursive: true });
128
+ await writeFileAtomic(outAbs, bytes);
112
129
  return { output: outAbs, bytes: bytes.length, entries: files };
113
130
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docsxai/engine",
3
- "version": "0.3.0-rc.3",
3
+ "version": "0.3.0-rc.5",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -41,17 +41,17 @@
41
41
  },
42
42
  "dependencies": {
43
43
  "fflate": "^0.8.3",
44
- "playwright-core": "^1.63.0",
44
+ "playwright-core": "^1.64.1",
45
45
  "pngjs": "^7.0.0",
46
46
  "yaml": "^2.9.1",
47
- "zod": "^3.23.0"
47
+ "zod": "^4.6.6"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@types/node": "^20.19.43",
51
51
  "@types/pngjs": "^6.0.5",
52
52
  "typescript": "^5.5.0",
53
- "vitest": "^2.0.0",
54
- "@docsxai/backend": "0.3.0-rc.3"
53
+ "vitest": "^4.1.12",
54
+ "@docsxai/backend": "0.3.0-rc.5"
55
55
  },
56
56
  "author": "Kalebtec <security@kalebtec.com>",
57
57
  "engines": {
@@ -60,6 +60,6 @@
60
60
  "scripts": {
61
61
  "build": "node ../../scripts/clean-dist.mjs && tsc -b tsconfig.build.json",
62
62
  "typecheck": "tsc --noEmit",
63
- "test": "vitest run --passWithNoTests"
63
+ "test": "vitest run --passWithNoTests --testTimeout=30000"
64
64
  }
65
65
  }