@docsxai/engine 0.3.0-rc.2 → 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 +45 -35
  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 +5 -5
  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 +28 -6
  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 +35 -0
  76. package/dist/cli-messages.js +104 -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 +16 -0
  86. package/dist/cli-unexpected.js +76 -0
  87. package/dist/cli-usage.d.ts +1 -1
  88. package/dist/cli-usage.js +116 -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 +3 -0
  94. package/dist/cli.js +46 -20
  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 +95 -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
package/dist/flow-lint.js CHANGED
@@ -1,9 +1,9 @@
1
1
  // Static analysis of flow-files. Catches common authoring mistakes at write-time, before a run.
2
- // Pure-static — no Playwright, no live page. Run via `docsxai lint`.
2
+ // Pure-static: no Playwright, no live page. Run via `docsxai lint`.
3
3
  import { locatorRefName, referencedLocatorNames } from "./flow-file.js";
4
4
  import { hiddenAtEachStep } from "./flow-hidden.js";
5
5
  import { lintMatrix } from "./flow-matrix-lint.js";
6
- /** Heuristic — names that suggest a step kicks off a multi-minute backend op. */
6
+ /** Heuristic, names that suggest a step kicks off a multi-minute backend op. */
7
7
  const LONG_ASYNC = /generate|create|process|submit|upload|translate|render|publish|export/i;
8
8
  /** A "bare" data-attribute selector like `[data-foo="x"]` with no further qualifier. */
9
9
  const BARE_DATA_ATTR = /^\[data-[a-z][a-z0-9-]*="[^"]+"\]$/;
@@ -31,7 +31,20 @@ function waitsFullDefault(step) {
31
31
  }
32
32
  export async function lintFlow(flow, opts = {}) {
33
33
  const issues = [];
34
- // R001 — extends chain depth; R005 — extends target missing
34
+ // R017: the flow's `name:` is not its file name; `extends:`, `--flow` and docs/<name>/ use the name
35
+ if (opts.fileName !== undefined) {
36
+ const stem = opts.fileName.replace(/\.flow\.yaml$/, "");
37
+ if (stem !== flow.name) {
38
+ issues.push({
39
+ code: "R017",
40
+ severity: "warning",
41
+ flow: flow.name,
42
+ message: `flow name \`${flow.name}\` differs from its file name ${opts.fileName}; \`extends\`, \`--flow\` and docs/${flow.name}/ use the name, so the file is easy to miss`,
43
+ suggestion: `rename the file to flows/${flow.name}.flow.yaml, or set \`name: ${stem}\``,
44
+ });
45
+ }
46
+ }
47
+ // R001: extends chain depth; R005, extends target missing
35
48
  if (opts.loadFlow && flow.extends) {
36
49
  const chain = await walkChain(flow, opts.loadFlow);
37
50
  if (chain.missing !== undefined) {
@@ -49,11 +62,11 @@ export async function lintFlow(flow, opts = {}) {
49
62
  severity: "info",
50
63
  flow: flow.name,
51
64
  message: `extends chain depth is ${chain.depth}`,
52
- suggestion: "consider flattening — deep chains add per-run setup cost and obscure the step order",
65
+ suggestion: "consider flattening: deep chains add per-run setup cost and obscure the step order",
53
66
  });
54
67
  }
55
68
  }
56
- // R006 — locator defined but never referenced
69
+ // R006: locator defined but never referenced
57
70
  const referenced = referencedLocatorNames(flow);
58
71
  for (const name of Object.keys(flow.locators)) {
59
72
  if (!referenced.has(name)) {
@@ -62,13 +75,13 @@ export async function lintFlow(flow, opts = {}) {
62
75
  severity: "info",
63
76
  flow: flow.name,
64
77
  message: `locator \`${name}\` is defined but never referenced by any step, wait, success, annotation, or redaction`,
65
- suggestion: "remove it — unless a child flow references it via `extends` (references in children count only in the child)",
78
+ suggestion: "remove it, unless a child flow references it via `extends` (references in children count only in the child)",
66
79
  });
67
80
  }
68
81
  }
69
- // R015 — the variants a `matrix` expands to; R016 — `copy_by_locale` keys no variant uses
82
+ // R015: the variants a `matrix` expands to; R016, `copy_by_locale` keys no variant uses
70
83
  issues.push(...lintMatrix(flow));
71
- // R007 — terminal step lacks `success` (with `extends`, this flow's steps run last, so its
84
+ // R007: terminal step lacks `success` (with `extends`, this flow's steps run last, so its
72
85
  // final step IS the merged flow's terminal step)
73
86
  const lastStep = flow.steps[flow.steps.length - 1];
74
87
  if (lastStep && !lastStep.success) {
@@ -77,7 +90,7 @@ export async function lintFlow(flow, opts = {}) {
77
90
  severity: "warning",
78
91
  flow: flow.name,
79
92
  stepId: lastStep.id,
80
- message: "the flow's terminal step has no `success` criterion — the run can end without verifying the end state",
93
+ message: "the flow's terminal step has no `success` criterion; the run can end without verifying the end state",
81
94
  suggestion: "add `success: { visible: $… }` (or url_matches / text_contains) to the last step",
82
95
  });
83
96
  }
@@ -91,7 +104,7 @@ export async function lintFlow(flow, opts = {}) {
91
104
  const hiddenAt = hiddenAtEachStep(flow, resolveMaybe);
92
105
  for (const [index, step] of flow.steps.entries()) {
93
106
  const anns = step.annotation ? [step.annotation] : (step.annotations ?? []);
94
- // R002 — annotation anchored to a likely-unmounting action target
107
+ // R002: annotation anchored to a likely-unmounting action target
95
108
  if (anns.length && (step.action === "click" || step.action === "navigate") && step.target) {
96
109
  const anyWithoutOverride = anns.some((a) => !a.target);
97
110
  if (anyWithoutOverride) {
@@ -105,7 +118,7 @@ export async function lintFlow(flow, opts = {}) {
105
118
  });
106
119
  }
107
120
  }
108
- // R003 — wait_for object form without timeout_ms on a long-async-looking step
121
+ // R003: wait_for object form without timeout_ms on a long-async-looking step
109
122
  const w = step.wait_for;
110
123
  if (w && typeof w === "object" && !Array.isArray(w) && "selector" in w && !w.timeout_ms) {
111
124
  const targetText = step.target ? (locatorRefName(step.target) ?? step.target) : "";
@@ -120,7 +133,7 @@ export async function lintFlow(flow, opts = {}) {
120
133
  });
121
134
  }
122
135
  }
123
- // R004 — bare `[data-*=…]` selector — may have hidden duplicates
136
+ // R004: bare `[data-*=…]` selector, may have hidden duplicates
124
137
  if (step.target) {
125
138
  const sel = step.target.startsWith("$")
126
139
  ? flow.locators[locatorRefName(step.target) ?? ""]
@@ -131,47 +144,47 @@ export async function lintFlow(flow, opts = {}) {
131
144
  severity: "info",
132
145
  flow: flow.name,
133
146
  stepId: step.id,
134
- message: `selector \`${sel}\` is a bare \`[data-*=…]\` match — may resolve to multiple DOM nodes (visible + hidden duplicate)`,
147
+ message: `selector \`${sel}\` is a bare \`[data-*=…]\` match; it may resolve to multiple DOM nodes (visible + hidden duplicate)`,
135
148
  suggestion: "if duplicates exist, scope with `:visible` or add a `:has-text(...)` qualifier",
136
149
  });
137
150
  }
138
151
  }
139
- // R008 — un-guarded optional step
152
+ // R008: un-guarded optional step
140
153
  if (step.optional && !step.wait_for && !step.success) {
141
154
  issues.push({
142
155
  code: "R008",
143
156
  severity: "warning",
144
157
  flow: flow.name,
145
158
  stepId: step.id,
146
- message: "`optional: true` with no `wait_for` or `success` — every failure is silently swallowed, so a real regression on this step would be masked",
159
+ message: "`optional: true` with no `wait_for` or `success`; every failure is silently swallowed, so a real regression on this step would be masked",
147
160
  suggestion: "add a `wait_for: { selector: … }` or a `success:` check to make the presence test explicit",
148
161
  });
149
162
  }
150
- // R011 — optional step with no short timeout: a miss costs the full default wait
163
+ // R011: optional step with no short timeout: a miss costs the full default wait
151
164
  if (step.optional && waitsFullDefault(step)) {
152
165
  issues.push({
153
166
  code: "R011",
154
167
  severity: "info",
155
168
  flow: flow.name,
156
169
  stepId: step.id,
157
- message: "`optional: true` step has no `timeout_ms` — when its element is absent the run waits Playwright's full 30 s default before skipping it",
170
+ message: "`optional: true` step has no `timeout_ms`; when its element is absent the run waits Playwright's full 30 s default before skipping it",
158
171
  suggestion: step.action === "wait"
159
172
  ? "add `timeout_ms: 1500` to the step (or to its `wait_for`) so a miss is skipped fast"
160
- : "add `timeout_ms: 1500` (100–30000) so a miss is skipped fast; keep the default only if the element can legitimately take longer to appear",
173
+ : "add `timeout_ms: 1500` (100-30000) so a miss is skipped fast; keep the default only if the element can legitimately take longer to appear",
161
174
  });
162
175
  }
163
- // R012 — `hide` with no target (the runtime would halt on it)
176
+ // R012: `hide` with no target (the runtime would halt on it)
164
177
  if (step.action === "hide" && !step.target) {
165
178
  issues.push({
166
179
  code: "R012",
167
180
  severity: "error",
168
181
  flow: flow.name,
169
182
  stepId: step.id,
170
- message: "`hide` has no `target` — there is nothing to hide, and the run halts on this step",
183
+ message: "`hide` has no `target`; there is nothing to hide, and the run halts on this step",
171
184
  suggestion: "set `target` to the element (a `$ref` or an inline selector) to hide",
172
185
  });
173
186
  }
174
- // R013 — step reaches an element an earlier `hide` step hid: a hidden element isn't visible,
187
+ // R013: step reaches an element an earlier `hide` step hid: a hidden element isn't visible,
175
188
  // so a click waits out its timeout, an annotation has nothing to anchor to, a visible-wait never ends
176
189
  const reached = [];
177
190
  if (step.target && !["hide", "show", "navigate"].includes(step.action))
@@ -197,18 +210,18 @@ export async function lintFlow(flow, opts = {}) {
197
210
  suggestion: "add a `show` step (with this target, or none to show everything) before this step, or move the `hide` after it",
198
211
  });
199
212
  }
200
- // R009 — element_stable with no selector context (a no-op)
213
+ // R009: element_stable with no selector context (a no-op)
201
214
  if (step.wait_for === "element_stable" && !step.target) {
202
215
  issues.push({
203
216
  code: "R009",
204
217
  severity: "warning",
205
218
  flow: flow.name,
206
219
  stepId: step.id,
207
- message: "`wait_for: element_stable` has no selector context (the step has no `target`) — it waits on nothing",
220
+ message: "`wait_for: element_stable` has no selector context (the step has no `target`); it waits on nothing",
208
221
  suggestion: "give the step a `target`, or wait on a concrete element with `wait_for: { selector: $x }`",
209
222
  });
210
223
  }
211
- // R014 — a bare `wait` step that only sleeps (a guess at how long the page needs to settle)
224
+ // R014: a bare `wait` step that only sleeps (a guess at how long the page needs to settle)
212
225
  if (step.action === "wait" &&
213
226
  typeof step.wait_for === "object" &&
214
227
  "timeout_ms" in step.wait_for &&
@@ -222,7 +235,7 @@ export async function lintFlow(flow, opts = {}) {
222
235
  suggestion: "use `wait_for: settled` (fonts, visible images and layout), or wait on a concrete element with `wait_for: { selector: $x }`; keep the sleep only for an animation nothing else can detect",
223
236
  });
224
237
  }
225
- // R010 — annotation anchored to a redacted element (the call-out would point at a black box)
238
+ // R010: annotation anchored to a redacted element (the call-out would point at a black box)
226
239
  const stepRedactionSelectors = new Set([
227
240
  ...flowRedactionSelectors,
228
241
  ...(step.redactions ?? []).flatMap((r) => "selector" in r ? [resolveMaybe(r.selector)] : []),
@@ -236,7 +249,7 @@ export async function lintFlow(flow, opts = {}) {
236
249
  severity: "warning",
237
250
  flow: flow.name,
238
251
  stepId: step.id,
239
- message: `annotation is anchored to \`${anchor}\`, which a redaction on this step masks — the call-out would point at a black box`,
252
+ message: `annotation is anchored to \`${anchor}\`, which a redaction on this step masks; the call-out would point at a black box`,
240
253
  suggestion: "anchor the annotation to a different element, or drop the redaction",
241
254
  });
242
255
  }
@@ -1,6 +1,6 @@
1
1
  // Lint rules for the flow matrix. Pure-static, like `flow-lint.ts`, which runs them.
2
- // R015 (info) — the variants the flow's `matrix` expands to, in run order
3
- // R016 (warning) — a `copy_by_locale` key that no variant locale can use
2
+ // R015 (info), the variants the flow's `matrix` expands to, in run order
3
+ // R016 (warning), a `copy_by_locale` key that no variant locale can use
4
4
  import { matrixVariantIds } from "./flow-matrix.js";
5
5
  /** A `copy_by_locale` key serves a locale when it is that tag or its language. */
6
6
  function serves(key, locale) {
@@ -3,7 +3,7 @@ import { type NearbyBoxes } from "./obstacles.js";
3
3
  /**
4
4
  * A redaction with its locator ref already resolved to a concrete selector. `selector` entries are
5
5
  * turned into bounding boxes by the driver at capture time (absent/zero-box selectors are skipped
6
- * with a stderr warning — never a halt); `region` rects are in CSS pixels and the driver scales
6
+ * with a stderr warning, never a halt); `region` rects are in CSS pixels and the driver scales
7
7
  * them to the screenshot's device-pixel space.
8
8
  */
9
9
  export type ResolvedRedaction = {
@@ -89,10 +89,10 @@ export interface BrowserDriver {
89
89
  /**
90
90
  * Probe the actionability state of `selector` at write-time / calibration-time, without trying
91
91
  * to act on it. Returns one of {@link ActionableState}. Designed to mirror the same Playwright
92
- * actionability checks the runtime would hit at execution-time — so a calibration agent (or an
92
+ * actionability checks the runtime would hit at execution-time, so a calibration agent (or an
93
93
  * MCP browser bridge consuming this driver's contract) can decide "no point fill'ing a disabled
94
- * input" or "scope this selector with `:visible` — it matches multiple" *before* the step is
95
- * written into a flow-file. `timeoutMs` is the *budget per check*, not a wait — keep small
94
+ * input" or "scope this selector with `:visible`, it matches multiple" *before* the step is
95
+ * written into a flow-file. `timeoutMs` is the *budget per check*, not a wait, keep small
96
96
  * (≤500 ms) to avoid stalling calibration. The runtime itself doesn't call this on every step
97
97
  * (Playwright's per-action actionability already covers that); it's an exposed contract for
98
98
  * consumers that want to read the state without acting.
@@ -119,10 +119,10 @@ export interface RunFlowOptions {
119
119
  variant?: VariantInfo;
120
120
  /** If false, skip screenshot/annotation capture (pure flow validation). Default: true. */
121
121
  captureDocs?: boolean;
122
- /** If set, stop after executing the step with this id — run only a prefix of the flow (for calibration). */
122
+ /** If set, stop after executing the step with this id, run only a prefix of the flow (for calibration). */
123
123
  stopAfter?: string;
124
124
  /**
125
- * If set, **skip** every step *before* the one with this id — start executing from this step onward.
125
+ * If set, **skip** every step *before* the one with this id, start executing from this step onward.
126
126
  * Assumes the browser is already in the state the prior steps would have produced (typical use:
127
127
  * paired with `connectOverCdp` to attach to a Chrome that's already been driven there manually or
128
128
  * by an earlier partial run). The skipped steps emit no annotations / screenshots / executed records;
@@ -135,6 +135,17 @@ export interface RunFlowOptions {
135
135
  * false: records are then exactly what they were before the field existed.
136
136
  */
137
137
  obstacles?: boolean;
138
+ /**
139
+ * Device pixels per CSS pixel of the session the driver runs in. Above 1 it is recorded as
140
+ * `device_scale_factor` in the returned annotations, so a reader of the file knows the screenshot
141
+ * and every box in it are that many times the CSS size. The driver already works in device pixels.
142
+ */
143
+ deviceScaleFactor?: number;
144
+ /**
145
+ * The browser build the driver runs in, as `Chromium <version>`. Recorded as `browser_build` in
146
+ * the returned annotations. Left out when the session cannot report one.
147
+ */
148
+ browserBuild?: string;
138
149
  }
139
150
  export interface ExecutedStep {
140
151
  id: string;
@@ -1,9 +1,9 @@
1
- // Flow-file runtime — the deterministic execution side.
1
+ // Flow-file runtime, the deterministic execution side.
2
2
  //
3
3
  // `docsxai run` translates a parsed flow-file into a sequence of browser actions, executes
4
4
  // them headlessly with zero LLM involvement, re-captures screenshots, and re-emits the doc-pack
5
5
  // artifacts (annotations, etc.). One canonical locator per step; execution halts on locator or
6
- // success-criterion failure — drift is a signal to recalibrate, not to absorb (no fallbacks).
6
+ // success-criterion failure, drift is a signal to recalibrate, not to absorb (no fallbacks).
7
7
  //
8
8
  // The runtime is written against a thin {@link BrowserDriver} abstraction so it's testable
9
9
  // without a real browser; the Playwright-backed driver lives in a separate module.
@@ -44,7 +44,7 @@ async function obstaclesAround(driver, selector, target, stepId, placement) {
44
44
  : [];
45
45
  }
46
46
  catch (e) {
47
- process.stderr.write(`runFlow: step "${stepId}" — obstacle scan skipped (${e.message})\n`);
47
+ process.stderr.write(`run: step "${stepId}": obstacle scan skipped (${firstLine(e)})\n`);
48
48
  return [];
49
49
  }
50
50
  }
@@ -90,10 +90,23 @@ async function executeAction(driver, step, selector) {
90
90
  return driver.showElements(selector); // no target = show everything hidden so far
91
91
  }
92
92
  }
93
+ /** The first line of a caught error's message: Playwright's call log stays out of a one-line note. */
94
+ function firstLine(e) {
95
+ const text = e instanceof Error ? e.message : String(e);
96
+ return text.split("\n")[0] || "unknown error";
97
+ }
93
98
  /** The halt message for a step whose optional driver method is missing. `halt-cause` keys on its shape. */
94
99
  function missingMethod(feature, method) {
95
100
  return `${feature}: driver has no ${method} (this browser driver doesn't implement it)`;
96
101
  }
102
+ /** The error for a `--start-from` or `--stop-after` step id the flow does not have: the id, the flow and the ids it has. */
103
+ function unknownStep(verb, id, flow) {
104
+ const ids = flow.steps.map((s) => s.id);
105
+ const shown = ids.length > 12
106
+ ? `${ids.slice(0, 12).join(", ")}, and ${ids.length - 12} more`
107
+ : ids.join(", ");
108
+ return new Error(`cannot ${verb} step "${id}": flow "${flow.name}" has no such step (steps: ${shown})`);
109
+ }
97
110
  function needSelector(selector, step) {
98
111
  if (selector === null)
99
112
  throw new FlowExecutionError(`action "${step.action}" requires a \`target\``, step.id);
@@ -119,7 +132,11 @@ export async function runFlow(flow, driver, opts = {}) {
119
132
  // startFrom validation: if set, must name an actual step id in this (already-merged) flow.
120
133
  // Catching the typo here is cheaper than running, halting, and reading the wall of Playwright noise.
121
134
  if (opts.startFrom && !flow.steps.some((s) => s.id === opts.startFrom)) {
122
- throw new Error(`startFrom: no step with id "${opts.startFrom}" in flow "${flow.name}"`);
135
+ throw unknownStep("start from", opts.startFrom, flow);
136
+ }
137
+ // Same for stopAfter: a typo would otherwise run the whole flow and overwrite its outputs.
138
+ if (opts.stopAfter && !flow.steps.some((s) => s.id === opts.stopAfter)) {
139
+ throw unknownStep("stop after", opts.stopAfter, flow);
123
140
  }
124
141
  let skipping = !!opts.startFrom;
125
142
  // Flow-level redactions apply to every screenshot; per-step ones are additive. Resolved up
@@ -134,9 +151,14 @@ export async function runFlow(flow, driver, opts = {}) {
134
151
  else
135
152
  continue;
136
153
  }
137
- const selector = step.target ? resolve(step.target) : null;
138
- const redactions = redactionsFor(step);
154
+ let selector = null;
155
+ let redactions = [];
156
+ let redactionsResolved = false;
139
157
  try {
158
+ // Resolved inside the try so an unresolved ref halts with the step id like any other failure.
159
+ redactions = redactionsFor(step);
160
+ redactionsResolved = true;
161
+ selector = step.target ? resolve(step.target) : null;
140
162
  await executeAction(driver, step, selector);
141
163
  if (step.wait_for) {
142
164
  if (step.wait_for === "element_stable" && selector)
@@ -149,27 +171,32 @@ export async function runFlow(flow, driver, opts = {}) {
149
171
  }
150
172
  catch (e) {
151
173
  // Optional step (conditionally-present UI): swallow the failure, log it, move on.
152
- // No screenshot / annotation for a skipped step — same as a `--start-from`-skipped one.
174
+ // No screenshot / annotation for a skipped step, same as a `--start-from`-skipped one.
153
175
  if (step.optional) {
154
- process.stderr.write(`runFlow: optional step "${step.id}" (${step.action}) skipped — ${e.message}\n`);
176
+ process.stderr.write(`run: optional step "${step.id}" (${step.action}) skipped: ${firstLine(e)}\n`);
177
+ if (opts.stopAfter && step.id === opts.stopAfter)
178
+ break;
155
179
  continue;
156
180
  }
157
181
  // Halt: dump a screenshot for triage (best-effort), prepend a 1-line inferred cause
158
182
  // (parsed from Playwright's actionability log so the agent doesn't have to scan ~20 lines
159
183
  // to know why), then surface step id + url + halt-shot path uniformly.
160
184
  const haltShot = `${variantDocDir(flow.name, variantId)}/halts/${step.id}.png`;
161
- // Halt shots can capture the same sensitive UI as step shots — same redactions apply.
162
- if (captureDocs)
185
+ // Halt shots can capture the same sensitive UI as step shots, same redactions apply.
186
+ // With the redactions unresolved the shot would go out unmasked, so none is taken.
187
+ const haltShotWanted = captureDocs && redactionsResolved;
188
+ if (haltShotWanted)
163
189
  await driver.screenshot(haltShot, redactions).catch(() => undefined);
164
- const suffix = captureDocs ? ` (halt screenshot: ${haltShot})` : "";
165
- const cause = inferHaltCause(e.message ?? "");
190
+ const suffix = haltShotWanted ? ` (halt screenshot: ${haltShot})` : "";
191
+ const raw = e instanceof Error ? e.message : String(e);
192
+ const cause = inferHaltCause(raw);
166
193
  const causePrefix = cause ? `[${cause}] ` : "";
167
194
  const variantTag = variantId ? `[variant ${variantId}] ` : "";
168
195
  if (e instanceof FlowExecutionError) {
169
196
  throw new FlowExecutionError(`${causePrefix}${variantTag}${e.message}${suffix}`, e.stepId, e.cause, variantId);
170
197
  }
171
198
  const where = await driver.currentUrl().catch(() => "?");
172
- throw new FlowExecutionError(`${causePrefix}${variantTag}step "${step.id}" (${step.action}) failed at ${where}: ${e.message}${suffix}`, step.id, e, variantId);
199
+ throw new FlowExecutionError(`${causePrefix}${variantTag}step "${step.id}" (${step.action}) failed at ${where}: ${raw}${suffix}`, step.id, e, variantId);
173
200
  }
174
201
  const ex = {
175
202
  id: step.id,
@@ -177,10 +204,10 @@ export async function runFlow(flow, driver, opts = {}) {
177
204
  ...(selector ? { selector } : {}),
178
205
  };
179
206
  // Doc capture is best-effort. When a step's action *transitions the UI* the action target is often
180
- // unmounted by the time we capture — `boundingBox` would hang for the driver's default 30s. Short
207
+ // unmounted by the time we capture, `boundingBox` would hang for the driver's default 30s. Short
181
208
  // timeout + try/catch → continue with no annotation for this step. `annotation.target` (if set)
182
- // overrides the anchor — point the halo at a different element that *does* exist in the new state.
183
- // A step can also have `annotations: [...]` to put multiple numbered call-outs on the same screenshot —
209
+ // overrides the anchor, point the halo at a different element that *does* exist in the new state.
210
+ // A step can also have `annotations: [...]` to put multiple numbered call-outs on the same screenshot,
184
211
  // each becomes one record with a 1-based `index`; an `annotation` (singular) emits one record without
185
212
  // `index` (un-numbered, back-compat).
186
213
  const anns = step.annotations ?? (step.annotation ? [step.annotation] : []);
@@ -215,7 +242,7 @@ export async function runFlow(flow, driver, opts = {}) {
215
242
  }
216
243
  }
217
244
  catch (e) {
218
- process.stderr.write(`runFlow: step "${step.id}" — annotation capture skipped (${e.message})\n`);
245
+ process.stderr.write(`run: step "${step.id}": annotation capture skipped (${firstLine(e)})\n`);
219
246
  }
220
247
  }
221
248
  executed.push(ex);
@@ -229,6 +256,10 @@ export async function runFlow(flow, driver, opts = {}) {
229
256
  schema: "docsxai/annotations@1",
230
257
  flow: flow.name,
231
258
  ...(opts.variant ? { variant: opts.variant } : {}),
259
+ ...(opts.deviceScaleFactor !== undefined && opts.deviceScaleFactor > 1
260
+ ? { device_scale_factor: opts.deviceScaleFactor }
261
+ : {}),
262
+ ...(opts.browserBuild ? { browser_build: opts.browserBuild } : {}),
232
263
  annotations,
233
264
  },
234
265
  };
@@ -6,20 +6,20 @@ export async function checkSuccess(driver, success, resolve, stepId) {
6
6
  if ("visible" in success) {
7
7
  const sel = resolve(success.visible);
8
8
  if (!(await driver.isVisible(sel))) {
9
- throw new FlowExecutionError(`expected ${success.visible} to be visible — ${await at()}; ${await driver.count(sel).catch(() => "?")} element(s) match the selector`, stepId);
9
+ throw new FlowExecutionError(`expected ${success.visible} to be visible: ${await at()}; ${await driver.count(sel).catch(() => "?")} element(s) match the selector`, stepId);
10
10
  }
11
11
  return;
12
12
  }
13
13
  if ("hidden" in success) {
14
14
  const sel = resolve(success.hidden);
15
15
  if (await driver.isVisible(sel)) {
16
- throw new FlowExecutionError(`expected ${success.hidden} to be hidden but a match is visible — ${await at()}; ${await driver.count(sel).catch(() => "?")} element(s) match`, stepId);
16
+ throw new FlowExecutionError(`expected ${success.hidden} to be hidden but a match is visible: ${await at()}; ${await driver.count(sel).catch(() => "?")} element(s) match`, stepId);
17
17
  }
18
18
  return;
19
19
  }
20
20
  if ("url_matches" in success) {
21
21
  if (!(await driver.urlMatches(success.url_matches))) {
22
- throw new FlowExecutionError(`expected URL to match /${success.url_matches}/ — actual: ${await driver.currentUrl().catch(() => "?")}`, stepId);
22
+ throw new FlowExecutionError(`expected URL to match /${success.url_matches}/; actual: ${await driver.currentUrl().catch(() => "?")}`, stepId);
23
23
  }
24
24
  return;
25
25
  }
@@ -31,7 +31,7 @@ export async function checkSuccess(driver, success, resolve, stepId) {
31
31
  .replace(/\s+/g, " ")
32
32
  .trim()
33
33
  .slice(0, 200);
34
- throw new FlowExecutionError(`expected ${selector} to contain ${JSON.stringify(text)} — ${await at()}; actual text: ${JSON.stringify(actual)}`, stepId);
34
+ throw new FlowExecutionError(`expected ${selector} to contain ${JSON.stringify(text)}: ${await at()}; actual text: ${JSON.stringify(actual)}`, stepId);
35
35
  }
36
36
  }
37
37
  }
package/dist/flow-tree.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // Visualise the `extends` graph across a workspace's flow-files; report step-id collisions
2
- // across the merged step list. Pure-static — no Playwright, no live page. Run via `docsxai flow-tree`.
2
+ // across the merged step list. Pure-static, no Playwright, no live page. Run via `docsxai flow-tree`.
3
3
  import { expandFlowVariants, resolveFlowExtends } from "./flow-file.js";
4
4
  import { matrixVariantIds } from "./flow-matrix.js";
5
5
  export async function buildFlowTree(flowsByName) {
@@ -60,7 +60,7 @@ export function formatTreeText(result) {
60
60
  out += "\n";
61
61
  }
62
62
  if (result.orphans.length) {
63
- out += "(extends parent not in workspace — orphan flows)\n";
63
+ out += "(extends parent not in workspace, orphan flows)\n";
64
64
  for (const o of result.orphans)
65
65
  out += renderRoot(o);
66
66
  out += "\n";
package/dist/index.d.ts CHANGED
@@ -8,6 +8,8 @@ export * from "./obstacles.js";
8
8
  export * from "./flow-lint.js";
9
9
  export * from "./flow-tree.js";
10
10
  export * from "./auth.js";
11
+ export * from "./browser-launch-error.js";
12
+ export { describeFsProblem, type FsProblem } from "./cli-messages.js";
11
13
  export * from "./backend-client.js";
12
14
  export * from "./calibrate.js";
13
15
  export * from "./diagnose.js";
package/dist/index.js CHANGED
@@ -12,6 +12,8 @@ export * from "./obstacles.js";
12
12
  export * from "./flow-lint.js";
13
13
  export * from "./flow-tree.js";
14
14
  export * from "./auth.js";
15
+ export * from "./browser-launch-error.js";
16
+ export { describeFsProblem } from "./cli-messages.js";
15
17
  export * from "./backend-client.js";
16
18
  export * from "./calibrate.js";
17
19
  export * from "./diagnose.js";
@@ -0,0 +1 @@
1
+ export declare function isMainModule(metaUrl: string, argv1: string | undefined): boolean;
@@ -0,0 +1,17 @@
1
+ // Entry-point check for the bin. `process.argv[1]` keeps the path the shell used, so a bin that
2
+ // npm or pnpm installed as a symlink never equals `import.meta.url`, which Node resolves to the
3
+ // real file. Comparing the real path as well makes the bin start through its symlink.
4
+ import { realpathSync } from "node:fs";
5
+ import { pathToFileURL } from "node:url";
6
+ export function isMainModule(metaUrl, argv1) {
7
+ if (!argv1)
8
+ return false;
9
+ if (metaUrl === pathToFileURL(argv1).href)
10
+ return true;
11
+ try {
12
+ return metaUrl === pathToFileURL(realpathSync(argv1)).href;
13
+ }
14
+ catch {
15
+ return false;
16
+ }
17
+ }