@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
package/dist/doc-pack.js CHANGED
@@ -1,14 +1,14 @@
1
- // Doc-pack schema — the artifacts a calibration run produces and an execution run consumes.
1
+ // Doc-pack schema, the artifacts a calibration run produces and an execution run consumes.
2
2
  //
3
3
  // Layout on disk:
4
- // <project>/flows/<flow>.flow.yaml — flow-file (source of truth for execution)
5
- // <project>/docs/<flow>/<step>.md — step write-ups (user-facing prose)
4
+ // <project>/flows/<flow>.flow.yaml: flow-file (source of truth for execution)
5
+ // <project>/docs/<flow>/<step>.md: step write-ups (user-facing prose)
6
6
  // <project>/docs/<flow>/screenshots/<step>.png
7
- // <project>/docs/<flow>/annotations.json — per-step annotation records (this module's AnnotationsFile)
7
+ // <project>/docs/<flow>/annotations.json: per-step annotation records (this module's AnnotationsFile)
8
8
  // A flow with a `matrix` writes the two lines above under docs/<flow>/<variant>/ instead.
9
- // <project>/docs/style.yaml + style.json — style artifact (canonical + derived)
10
- // <project>/docs/locators.yaml — locator manifest (one canonical locator per step)
11
- // <project>/auth/strategy.yaml — target-site auth-strategy descriptor
9
+ // <project>/docs/style.yaml + style.json, style artifact (canonical + derived)
10
+ // <project>/docs/locators.yaml: locator manifest (one canonical locator per step)
11
+ // <project>/auth/strategy.yaml: target-site auth-strategy descriptor
12
12
  //
13
13
  // Runtime validation is done with zod; the exported TS types are inferred from the schemas
14
14
  // so the two never drift.
@@ -81,16 +81,16 @@ function stepTimeoutHasEffect(s) {
81
81
  /**
82
82
  * What to wait for after a step's action settles. `network_idle` / `element_stable` / `load` / `settled` are
83
83
  * named primitives (`settled` = fonts loaded, visible images loaded, viewport layout still, bounded by the
84
- * step's `timeout_ms`); `{ selector }` waits for an element to appear (Playwright's default timeout, ~30s) — give it
84
+ * step's `timeout_ms`); `{ selector }` waits for an element to appear (Playwright's default timeout, ~30s), give it
85
85
  * `timeout_ms` to override that (e.g. waiting on a multi-minute backend op that mounts a "done" element);
86
- * `{ timeout_ms }` alone is a blind sleep (last resort — for animations, not state).
86
+ * `{ timeout_ms }` alone is a blind sleep (last resort, for animations, not state).
87
87
  */
88
88
  export const WaitSpec = z.union([
89
89
  z.enum(["network_idle", "element_stable", "load", "settled"]),
90
90
  z.object({ timeout_ms: z.number().int().positive() }).strict(),
91
91
  z.object({ selector: LocatorRef, timeout_ms: z.number().int().positive().optional() }).strict(),
92
92
  ]);
93
- /** Post-step success criterion. Execution halts if it fails (no selector fallbacks — drift is a signal). */
93
+ /** Post-step success criterion. Execution halts if it fails (no selector fallbacks, drift is a signal). */
94
94
  export const SuccessSpec = z.union([
95
95
  z.object({ visible: LocatorRef }).strict(),
96
96
  z.object({ hidden: LocatorRef }).strict(),
@@ -101,7 +101,7 @@ export const SuccessSpec = z.union([
101
101
  ]);
102
102
  export const NudgeOffset = z.object({ x: z.number(), y: z.number() }).strict();
103
103
  // ---------------------------------------------------------------------------
104
- // Redactions (`redactions:` — flow-level and per-step)
104
+ // Redactions (`redactions:`, flow-level and per-step)
105
105
  // ---------------------------------------------------------------------------
106
106
  export const RedactionStyle = z.enum(["box", "pixelate"]);
107
107
  /** A fixed rectangle in CSS pixels (viewport coordinates), scaled to device pixels at capture time. */
@@ -117,7 +117,7 @@ export const RedactionRegion = z
117
117
  * One area to mask on every screenshot it applies to (step shots *and* halt shots): either an
118
118
  * element (locator ref / inline selector, resolved to its bounding box at capture time) or a fixed
119
119
  * `region`. Default `style` is `box` (solid #000 fill); `pixelate` is a 16-px mosaic. A selector
120
- * that matches nothing at capture time is skipped with a stderr warning — redacting an absent
120
+ * that matches nothing at capture time is skipped with a stderr warning, redacting an absent
121
121
  * element is vacuously satisfied, never a halt. Flow-level `redactions` apply to every step;
122
122
  * per-step `redactions` are additive.
123
123
  */
@@ -162,15 +162,15 @@ export const StepAnnotation = z
162
162
  /**
163
163
  * Optional pixel offset applied to the callout + arrow after Popper-like placement. The halo (which
164
164
  * highlights the target element) stays on the target. Use this when two annotations on the same
165
- * screenshot would otherwise overlap each other — nudge one aside so both are readable.
166
- * Image-space pixels; small values (5–40 px in either direction) typically suffice.
165
+ * screenshot would otherwise overlap each other, nudge one aside so both are readable.
166
+ * Image-space pixels; small values (5-40 px in either direction) typically suffice.
167
167
  */
168
168
  nudge: NudgeOffset.optional(),
169
- /** Optional burner placement settings — see {@link AnnotationPlacement}. Copied onto the annotation record. */
169
+ /** Optional burner placement settings, see {@link AnnotationPlacement}. Copied onto the annotation record. */
170
170
  placement: AnnotationPlacement.optional(),
171
171
  /**
172
172
  * Optional override: the locator to anchor the halo/arrow to. Default = the step's `target`. Use this on
173
- * a step whose action *transitions the UI* — the action target vanishes (gets unmounted / replaced) and
173
+ * a step whose action *transitions the UI*, the action target vanishes (gets unmounted / replaced) and
174
174
  * a *different* element is what you want to highlight in the resulting state. Point this at the
175
175
  * surviving / appearing element.
176
176
  */
@@ -182,7 +182,7 @@ export const StepAnnotation = z
182
182
  */
183
183
  copy_by_locale: z
184
184
  .record(LocaleTag, z.string().min(1))
185
- .refine((m) => Object.keys(m).length > 0, { message: "needs at least one locale" })
185
+ .refine((m) => Object.keys(m).length > 0, { error: "needs at least one locale" })
186
186
  .optional(),
187
187
  /** Variants this call-out is kept for. Needs a `matrix`; see {@link VariantSelector}. */
188
188
  only: VariantSelector.optional(),
@@ -197,13 +197,13 @@ export const Step = z
197
197
  /**
198
198
  * Best-effort step: if the action / `wait_for` / `success` check throws (target absent, wait timed
199
199
  * out, etc.), **skip this step and continue** instead of halting the flow. For conditionally-present
200
- * UI — a confirmation modal that sometimes appears, a first-run tooltip, a cookie banner. A skipped
200
+ * UI: a confirmation modal that sometimes appears, a first-run tooltip, a cookie banner. A skipped
201
201
  * optional step emits no screenshot / annotation (same as a step skipped by `--start-from`). Prefer
202
202
  * this over a permissive comma-selector that no-ops on one branch.
203
203
  */
204
204
  optional: z.boolean().optional(),
205
205
  /**
206
- * How long, in ms, this step waits for its `target` before giving up (100–30000). Unset keeps the
206
+ * How long, in ms, this step waits for its `target` before giving up (100-30000). Unset keeps the
207
207
  * driver default (Playwright's 30 s), so existing flows run exactly as before. The reason to set it
208
208
  * is an `optional: true` step whose target is usually absent: a short value (e.g. 1500) skips it fast
209
209
  * instead of holding the run for the full default. On a `wait` step it bounds the `wait_for`
@@ -220,9 +220,9 @@ export const Step = z
220
220
  /** Single call-out on this step's screenshot. Shorthand for a one-element `annotations` array. */
221
221
  annotation: StepAnnotation.optional(),
222
222
  /**
223
- * Multiple call-outs on the same screenshot — rendered as numbered badges (1, 2, …) so the reader sees
223
+ * Multiple call-outs on the same screenshot, rendered as numbered badges (1, 2, …) so the reader sees
224
224
  * up front that there's more than one thing to look at without having to hover everything. Each entry
225
- * has its own `target` (defaults to the step's `target`) and `copy` / `arrow` — see {@link StepAnnotation}.
225
+ * has its own `target` (defaults to the step's `target`) and `copy` / `arrow`, see {@link StepAnnotation}.
226
226
  * Mutually exclusive with `annotation`.
227
227
  */
228
228
  annotations: z.array(StepAnnotation).min(1).optional(),
@@ -235,11 +235,11 @@ export const Step = z
235
235
  })
236
236
  .strict()
237
237
  .refine((s) => !(s.annotation && s.annotations), {
238
- message: "step has both `annotation` and `annotations`; use one (`annotations: [...]` for the multi-callout form)",
238
+ error: "step has both `annotation` and `annotations`; use one (`annotations: [...]` for the multi-callout form)",
239
239
  path: ["annotations"],
240
240
  })
241
241
  .refine((s) => s.timeout_ms === undefined || stepTimeoutHasEffect(s), {
242
- message: "`timeout_ms` has no effect on this step: it bounds the wait for a `target` (click, fill, upload, press, hover, select, check, uncheck, hide), a `wait_for: settled`, or a `wait` step's `wait_for: { selector }` that has no `timeout_ms` of its own",
242
+ error: "`timeout_ms` has no effect on this step: it bounds the wait for a `target` (click, fill, upload, press, hover, select, check, uncheck, hide), a `wait_for: settled`, or a `wait` step's `wait_for: { selector }` that has no `timeout_ms` of its own",
243
243
  path: ["timeout_ms"],
244
244
  });
245
245
  /** A precondition the flow assumes (e.g. `{ logged_in_as: "editor" }`, `{ feature_flag: "recap.enabled" }`). */
@@ -259,10 +259,10 @@ export const FlowName = z
259
259
  .min(1)
260
260
  .max(MAX_FLOW_NAME_LENGTH)
261
261
  .regex(/^[A-Za-z0-9][A-Za-z0-9._-]*$/, "must start with a letter or digit and use only letters, digits, `.`, `_` and `-`")
262
- .refine((n) => !n.includes(".."), { message: "must not contain `..`" })
263
- .refine((n) => !hasTrailingDot(n), { message: "must not end with `.`" })
262
+ .refine((n) => !n.includes(".."), { error: "must not contain `..`" })
263
+ .refine((n) => !hasTrailingDot(n), { error: "must not end with `.`" })
264
264
  .refine((n) => !isWindowsDeviceName(n), {
265
- message: "must not be a Windows device name (con, prn, aux, nul, com1-9, lpt1-9)",
265
+ error: "must not be a Windows device name (con, prn, aux, nul, com1-9, lpt1-9)",
266
266
  });
267
267
  export const FlowFile = z
268
268
  .object({
@@ -277,7 +277,7 @@ export const FlowFile = z
277
277
  extends: FlowName.optional(),
278
278
  /**
279
279
  * Deterministic execution environment (frozen clock, locale, timezone, viewport, color scheme,
280
- * reduced motion). With `extends`, merged per-key — this flow's keys win over the parent's.
280
+ * reduced motion). With `extends`, merged per-key, this flow's keys win over the parent's.
281
281
  */
282
282
  environment: EnvironmentSpec.optional(),
283
283
  /**
@@ -313,7 +313,7 @@ export const AnnotationRecord = z
313
313
  bounding_box: BoundingBox.optional(),
314
314
  copy: z.string().min(1),
315
315
  arrow_style: ArrowStyle.optional(),
316
- /** Optional pixel offset applied to the callout + arrow at render time — see {@link NudgeOffset}. */
316
+ /** Optional pixel offset applied to the callout + arrow at render time, see {@link NudgeOffset}. */
317
317
  nudge: NudgeOffset.optional(),
318
318
  /**
319
319
  * Optional boxes of page content (text, controls), in screenshot pixels, that the burner keeps this
@@ -325,9 +325,9 @@ export const AnnotationRecord = z
325
325
  * carries the same field.
326
326
  */
327
327
  obstacles: z.array(BoundingBox).max(MAX_OBSTACLES).optional(),
328
- /** Optional burner placement settings (inside the target, side, alignment, pinned arrow, width) — see {@link AnnotationPlacement}. */
328
+ /** Optional burner placement settings (inside the target, side, alignment, pinned arrow, width), see {@link AnnotationPlacement}. */
329
329
  placement: AnnotationPlacement.optional(),
330
- /** 1-based index of this annotation *within its step's screenshot* — set only when the step has > 1 annotation, so the viewer can render a numbered badge. Absent → render as a plain (un-numbered) halo. */
330
+ /** 1-based index of this annotation *within its step's screenshot*, set only when the step has > 1 annotation, so the viewer can render a numbered badge. Absent → render as a plain (un-numbered) halo. */
331
331
  index: z.number().int().positive().optional(),
332
332
  })
333
333
  .strict();
@@ -337,6 +337,20 @@ export const AnnotationsFile = z
337
337
  flow: z.string().min(1),
338
338
  /** The matrix variant these annotations belong to. Absent for a flow without a `matrix`. */
339
339
  variant: VariantInfo.optional(),
340
+ /**
341
+ * Device pixels per CSS pixel the screenshots were captured at (1 to 4, one decimal). Written by
342
+ * `docsxai run --device-scale-factor` above 1; absent means 1. Every `bounding_box` and `obstacle`
343
+ * in the file is in the screenshot's own device pixels, so the PNG is this many times its CSS
344
+ * viewport. The burner reads it as its pixel ratio.
345
+ */
346
+ device_scale_factor: z.number().min(1).max(4).optional(),
347
+ /**
348
+ * The browser that captured the screenshots, as `Chromium <version>` (what the browser reports).
349
+ * Written by `docsxai run` when the session reports a version; absent in files from older
350
+ * releases and never a reason to fail a comparison. Screenshots are byte-identical per docsxai
351
+ * and browser build, so a reader can tell a build change from a UI change.
352
+ */
353
+ browser_build: z.string().min(1).max(100).optional(),
340
354
  annotations: z.array(AnnotationRecord),
341
355
  })
342
356
  .strict();
@@ -390,7 +404,7 @@ export const CacheTtl = z.union([
390
404
  export const RoleAuth = z
391
405
  .object({
392
406
  strategy: StrategyName,
393
- /** Env-var *names* holding credentials — never the values. May be `{}` (e.g. `manual-capture` needs none). */
407
+ /** Env-var *names* holding credentials, never the values. May be `{}` (e.g. `manual-capture` needs none). */
394
408
  creds_env: z.record(z.string(), z.string()).default({}),
395
409
  options: z.record(z.string(), z.unknown()).default({}),
396
410
  cache: z
@@ -401,7 +415,7 @@ export const RoleAuth = z
401
415
  ttl: CacheTtl.default("session"),
402
416
  /**
403
417
  * Name of the app's actual auth/session cookie. When set, the cached session's `expiresAt` is *that*
404
- * cookie's expiry — the real bound — rather than the `ttl` guess. Identify it from the captured jar
418
+ * cookie's expiry, the real bound, rather than the `ttl` guess. Identify it from the captured jar
405
419
  * (`capture-auth` prints it): it's on the app's domain, long-lived (not an ephemeral IdP scratch
406
420
  * cookie), e.g. `AppSession.Production` / `.AspNetCore.Cookies` / `session`. Optional.
407
421
  */
@@ -419,7 +433,7 @@ export const AuthStrategyDescriptor = z
419
433
  })
420
434
  .strict()
421
435
  .refine((d) => d.default_role in d.roles, {
422
- message: "default_role must be one of the keys in roles",
436
+ error: "default_role must be one of the keys in roles",
423
437
  path: ["default_role"],
424
438
  });
425
439
  // ---------------------------------------------------------------------------
@@ -0,0 +1,12 @@
1
+ import type { DoctorCheck } from "./doctor-checks.js";
2
+ type Config = Record<string, unknown> | null;
3
+ export declare const APP_URL_TIMEOUT_MS = 3000;
4
+ /** Field-level validity of `.docsxai.json` (the schema id is checked by `checkWorkspace`). */
5
+ export declare function checkConfigFields(config: Config): DoctorCheck[];
6
+ /** Write access to the workspace root and the dirs `run`, `burn` and `render` write into. */
7
+ export declare function checkWritable(workspaceDir: string): Promise<DoctorCheck>;
8
+ /** One HEAD against `app_url`. Any HTTP answer counts as reachable. */
9
+ export declare function checkAppUrl(config: Config, fetchImpl: typeof globalThis.fetch, offline: boolean): Promise<DoctorCheck | null>;
10
+ /** Backend login state: only meaningful when `backend_url` is set. */
11
+ export declare function checkLogin(workspaceDir: string, config: Config, env: NodeJS.ProcessEnv): DoctorCheck;
12
+ export {};
@@ -0,0 +1,229 @@
1
+ // `docsxai doctor` - the workspace-config probes: field validity (including the `burn.theme`
2
+ // block's shape), write access, the `app_url` reachability HEAD and the backend login state.
3
+ // Split out of doctor-checks.ts to keep each module small. Pure inspection: the only network touch
4
+ // is one short HEAD against the operator's own `app_url`, skipped under `--offline` or when the
5
+ // machine has no network.
6
+ //
7
+ // The viewer's full `burn.theme` validator (values, tokens file, contrast) lives in
8
+ // `@docsxai/viewer`. The engine does not depend on that package, and importing it from here would
9
+ // couple the two, so doctor checks the block's shape and the preset name only and points at
10
+ // `docsxai burn`, which prints every problem and contrast warning.
11
+ import { existsSync, promises as fs, constants as fsConstants } from "node:fs";
12
+ import * as path from "node:path";
13
+ import { redactUrl, redactUrlsIn, shellQuote } from "./cli-messages.js";
14
+ import { WORKSPACE_CONFIG_FILE } from "./workspace.js";
15
+ const THEME_PRESETS = ["clean", "soft", "high-contrast", "readable"];
16
+ export const APP_URL_TIMEOUT_MS = 3000;
17
+ function httpUrlProblem(key, value) {
18
+ if (typeof value !== "string")
19
+ return `${key} must be a string`;
20
+ try {
21
+ const u = new URL(value);
22
+ if (u.protocol !== "http:" && u.protocol !== "https:") {
23
+ return `${key} must start with http:// or https://`;
24
+ }
25
+ }
26
+ catch {
27
+ return `${key} is not a valid URL`;
28
+ }
29
+ return null;
30
+ }
31
+ function themeProblems(burn) {
32
+ if (typeof burn !== "object" || burn === null || Array.isArray(burn)) {
33
+ return ["burn must be an object holding a theme block"];
34
+ }
35
+ const problems = Object.keys(burn)
36
+ .filter((k) => k !== "theme")
37
+ .map((k) => `burn.${k} is not a known key (the only key is theme)`);
38
+ const theme = burn.theme;
39
+ if (theme === undefined)
40
+ return problems;
41
+ if (typeof theme !== "object" || theme === null || Array.isArray(theme)) {
42
+ return [...problems, "burn.theme must be an object"];
43
+ }
44
+ const preset = theme.preset;
45
+ if (preset !== undefined && (typeof preset !== "string" || !THEME_PRESETS.includes(preset))) {
46
+ const shown = typeof preset === "string" ? preset : JSON.stringify(preset);
47
+ problems.push(`burn.theme.preset "${shown}" is not one of ${THEME_PRESETS.join(", ")}`);
48
+ }
49
+ return problems;
50
+ }
51
+ /** Field-level validity of `.docsxai.json` (the schema id is checked by `checkWorkspace`). */
52
+ export function checkConfigFields(config) {
53
+ if (!config)
54
+ return [];
55
+ const problems = [];
56
+ for (const key of ["app_url", "backend_url"]) {
57
+ if (config[key] === undefined)
58
+ continue;
59
+ const p = httpUrlProblem(key, config[key]);
60
+ if (p)
61
+ problems.push(p);
62
+ }
63
+ if (config.ignore_https_errors !== undefined && typeof config.ignore_https_errors !== "boolean") {
64
+ problems.push("ignore_https_errors must be true or false");
65
+ }
66
+ if (config.burn !== undefined)
67
+ problems.push(...themeProblems(config.burn));
68
+ const checks = [];
69
+ if (problems.length > 0) {
70
+ checks.push({
71
+ name: "config",
72
+ ok: false,
73
+ detail: `${WORKSPACE_CONFIG_FILE}: ${problems.join("; ")}`,
74
+ fix: `edit ${WORKSPACE_CONFIG_FILE} (keys and ranges: docs/burn-theming.md for burn.theme)`,
75
+ });
76
+ }
77
+ else {
78
+ checks.push({ name: "config", ok: true, detail: `${WORKSPACE_CONFIG_FILE} fields are valid` });
79
+ }
80
+ if (config.burn !== undefined && problems.length === 0) {
81
+ checks.push({
82
+ name: "theme",
83
+ ok: true,
84
+ info: true,
85
+ detail: "burn.theme block present and well-formed; its values and contrast are checked by the viewer, not by doctor",
86
+ fix: "run `docsxai burn <workspace-dir>` to see every theme problem and contrast warning",
87
+ });
88
+ }
89
+ return checks;
90
+ }
91
+ /** Write access to the workspace root and the dirs `run`, `burn` and `render` write into. */
92
+ export async function checkWritable(workspaceDir) {
93
+ const root = path.resolve(workspaceDir);
94
+ const candidates = [
95
+ root,
96
+ ...["flows", "docs", ".auth", ".viewer"].map((d) => path.join(root, d)),
97
+ ];
98
+ const blocked = [];
99
+ const files = [];
100
+ for (const dir of candidates) {
101
+ if (dir !== root && !existsSync(dir))
102
+ continue;
103
+ const stat = await fs.stat(dir).catch(() => null);
104
+ if (stat && !stat.isDirectory()) {
105
+ files.push(dir);
106
+ continue;
107
+ }
108
+ try {
109
+ await fs.access(dir, fsConstants.W_OK);
110
+ }
111
+ catch {
112
+ blocked.push(dir);
113
+ }
114
+ }
115
+ if (files.length > 0) {
116
+ return {
117
+ name: "writable",
118
+ ok: false,
119
+ detail: files.map((f) => `${f} is a file, but docsxai needs a directory there`).join("; "),
120
+ fix: `${files.map((f) => `mv ${shellQuote(f)} ${shellQuote(`${f}.bak`)}`).join(" && ")}, or use another workspace dir`,
121
+ };
122
+ }
123
+ if (blocked.length === 0) {
124
+ return { name: "writable", ok: true, detail: `${root} and its output dirs are writable` };
125
+ }
126
+ return {
127
+ name: "writable",
128
+ ok: false,
129
+ detail: `no write access to ${blocked.join(", ")}`,
130
+ fix: `chmod u+w ${blocked.map(shellQuote).join(" ")}, or use another workspace dir`,
131
+ };
132
+ }
133
+ function errorCodes(e) {
134
+ const codes = [];
135
+ let cur = e;
136
+ for (let i = 0; i < 4 && cur && typeof cur === "object"; i++) {
137
+ const code = cur.code;
138
+ if (typeof code === "string")
139
+ codes.push(code);
140
+ cur = cur.cause;
141
+ }
142
+ return codes;
143
+ }
144
+ const OFFLINE_CODES = ["ENOTFOUND", "EAI_AGAIN", "ENETUNREACH", "ENETDOWN", "EHOSTUNREACH"];
145
+ const TLS_CODE = /^(CERT_|DEPTH_ZERO|UNABLE_TO_|SELF_SIGNED|ERR_TLS_)/;
146
+ const LOOPBACK = /^(localhost|127\.|\[?::1\]?$)|\.localhost$/;
147
+ /** One HEAD against `app_url`. Any HTTP answer counts as reachable. */
148
+ export async function checkAppUrl(config, fetchImpl, offline) {
149
+ const raw = typeof config?.app_url === "string" ? config.app_url : undefined;
150
+ if (!raw || httpUrlProblem("app_url", raw))
151
+ return null;
152
+ const shown = redactUrl(raw);
153
+ if (offline) {
154
+ return {
155
+ name: "app_url",
156
+ ok: true,
157
+ info: true,
158
+ detail: `${shown} not probed (--offline)`,
159
+ fix: "run docsxai doctor without --offline to test reachability",
160
+ };
161
+ }
162
+ try {
163
+ const res = await fetchImpl(raw, {
164
+ method: "HEAD",
165
+ redirect: "manual",
166
+ signal: AbortSignal.timeout(APP_URL_TIMEOUT_MS),
167
+ });
168
+ return { name: "app_url", ok: true, detail: `${shown} answered HTTP ${res.status}` };
169
+ }
170
+ catch (e) {
171
+ const codes = errorCodes(e);
172
+ const host = new URL(raw).hostname;
173
+ if (codes.some((c) => OFFLINE_CODES.includes(c)) && !LOOPBACK.test(host)) {
174
+ return {
175
+ name: "app_url",
176
+ ok: true,
177
+ info: true,
178
+ detail: `${shown} not probed, this machine looks offline (${codes[0]})`,
179
+ fix: "reconnect and run docsxai doctor again before `docsxai run`",
180
+ };
181
+ }
182
+ if (codes.some((c) => TLS_CODE.test(c))) {
183
+ return config?.ignore_https_errors === true
184
+ ? {
185
+ name: "app_url",
186
+ ok: true,
187
+ detail: `${shown} presents a certificate this probe rejects (${codes[0]}); ignore_https_errors is set, so run accepts it`,
188
+ }
189
+ : {
190
+ name: "app_url",
191
+ ok: false,
192
+ detail: `${shown} certificate rejected (${codes[0]})`,
193
+ fix: 'set "ignore_https_errors": true in .docsxai.json (or re-run init with --ignore-https-errors)',
194
+ };
195
+ }
196
+ const timedOut = e.name === "TimeoutError";
197
+ return {
198
+ name: "app_url",
199
+ ok: false,
200
+ detail: timedOut
201
+ ? `${shown} did not answer within ${APP_URL_TIMEOUT_MS / 1000}s`
202
+ : `${shown} unreachable (${codes[0] ?? redactUrlsIn(e.message)})`,
203
+ fix: "start the app, or fix app_url in .docsxai.json",
204
+ };
205
+ }
206
+ }
207
+ /** Backend login state: only meaningful when `backend_url` is set. */
208
+ export function checkLogin(workspaceDir, config, env) {
209
+ const backendUrl = typeof config?.backend_url === "string" ? config.backend_url : undefined;
210
+ if (!backendUrl) {
211
+ return {
212
+ name: "login",
213
+ ok: true,
214
+ info: true,
215
+ detail: "no backend_url, so no backend login is needed",
216
+ };
217
+ }
218
+ if (env.DOCSX_TOKEN)
219
+ return { name: "login", ok: true, detail: "DOCSX_TOKEN is set" };
220
+ if (existsSync(path.join(path.resolve(workspaceDir), ".auth", "backend-token.json"))) {
221
+ return { name: "login", ok: true, detail: "OAuth tokens at .auth/backend-token.json" };
222
+ }
223
+ return {
224
+ name: "login",
225
+ ok: false,
226
+ detail: `not logged in to ${redactUrl(backendUrl)}; push and pull need a token`,
227
+ fix: `docsxai login --backend-url ${shellQuote(redactUrl(backendUrl))} --oauth ${shellQuote(workspaceDir)}, or export DOCSX_TOKEN`,
228
+ };
229
+ }
@@ -58,7 +58,7 @@ export async function checkPlugins(workspaceDir) {
58
58
  checks.push({
59
59
  name: "plugins",
60
60
  ok: false,
61
- detail: `${PLUGINS_LOCK_FILE} missing (${cfg.sources.length} plugin(s) configured — no reproducibility pin)`,
61
+ detail: `${PLUGINS_LOCK_FILE} missing (${cfg.sources.length} plugin(s) configured, no reproducibility pin)`,
62
62
  fix: `docsxai plugins sync ${shellQuote(workspaceDir)}`,
63
63
  });
64
64
  }
@@ -87,7 +87,7 @@ export async function checkPlugins(workspaceDir) {
87
87
  const prior = namespaceOwner.get(ns);
88
88
  if (prior) {
89
89
  issues.push({
90
- detail: `${c.name} namespace "${ns}" already claimed by ${prior} — neither will load`,
90
+ detail: `${c.name} namespace "${ns}" already claimed by ${prior}, neither will load`,
91
91
  fix: "namespaces are unique across the configured set; rename one",
92
92
  });
93
93
  }
@@ -0,0 +1,3 @@
1
+ import type { DoctorCheck } from "./doctor-checks.js";
2
+ /** The row for `<workspaceDir>/site`, or `null` when there is nothing to say. */
3
+ export declare function checkSite(workspaceDir: string): DoctorCheck | null;
@@ -0,0 +1,21 @@
1
+ // `docsxai doctor`: the site row. A workspace with an emitted site folder (`docsxai site`
2
+ // writes `<workspace>/site` by default) that has no astro installed cannot build with
3
+ // `npm run build`; the row says to install there first. No site folder, or astro present,
4
+ // adds no row.
5
+ import { existsSync } from "node:fs";
6
+ import * as path from "node:path";
7
+ import { shellQuote } from "./cli-messages.js";
8
+ /** The row for `<workspaceDir>/site`, or `null` when there is nothing to say. */
9
+ export function checkSite(workspaceDir) {
10
+ const dir = path.join(workspaceDir, "site");
11
+ const emitted = existsSync(path.join(dir, "package.json")) && existsSync(path.join(dir, "astro.config.mjs"));
12
+ if (!emitted || existsSync(path.join(dir, "node_modules", "astro", "package.json")))
13
+ return null;
14
+ return {
15
+ name: "site",
16
+ ok: true,
17
+ info: true,
18
+ detail: `${dir} has no astro installed`,
19
+ fix: `cd ${shellQuote(dir)} && npm install, then npm run build`,
20
+ };
21
+ }
@@ -3,7 +3,7 @@ export interface DoctorCheck {
3
3
  ok: boolean;
4
4
  detail: string;
5
5
  fix?: string;
6
- /** Informational row — printed with − instead of ✓/✗; never fails doctor. */
6
+ /** Informational row, printed with − instead of ✓/✗; never fails doctor. */
7
7
  info?: boolean;
8
8
  }
9
9
  export interface DoctorOptions {
@@ -22,6 +22,8 @@ export interface DoctorOptions {
22
22
  fetchImpl?: typeof globalThis.fetch;
23
23
  /** Clock override for session-freshness checks (tests inject). */
24
24
  now?: number;
25
+ /** Skip the `app_url` reachability probe (`--offline`). */
26
+ offline?: boolean;
25
27
  }
26
28
  /** Layer-3 default probe: does playwright-core have a cached Chromium binary?
27
29
  * Synchronous - the sole work is the sanctioned `chromiumExecutablePath()`
@@ -40,7 +42,7 @@ export declare function checkChromium(probe: () => {
40
42
  }>): Promise<DoctorCheck>;
41
43
  interface WorkspaceProbe {
42
44
  check: DoctorCheck;
43
- /** Parsed `.docsxai.json` when valid (doctor reads the raw JSON — schema-checked here). */
45
+ /** Parsed `.docsxai.json` when valid (doctor reads the raw JSON, schema-checked here). */
44
46
  config: Record<string, unknown> | null;
45
47
  /** True when the dir looks like a workspace at all (config file or flows/ present). */
46
48
  present: boolean;
@@ -49,8 +51,17 @@ export declare function checkWorkspace(workspaceDir: string): Promise<WorkspaceP
49
51
  export declare function checkFlows(workspaceDir: string): Promise<DoctorCheck>;
50
52
  export declare function checkAuth(workspaceDir: string, now: number): Promise<DoctorCheck[]>;
51
53
  export declare function checkBackend(workspaceDir: string, config: Record<string, unknown> | null, env: NodeJS.ProcessEnv, fetchImpl: typeof globalThis.fetch): Promise<DoctorCheck>;
54
+ /**
55
+ * The viewer row. It names the path that resolved, never the variable or lookup order: the
56
+ * `docsxai` bin sets the variable itself, so naming it would show users a setting they never made.
57
+ */
52
58
  export declare function checkViewer(env: NodeJS.ProcessEnv, resolveFrom?: string[]): Promise<DoctorCheck>;
53
59
  /** DOCSX_* env vars the docsxai packages read (engine, viewer, backend + mcp). */
54
60
  export declare const KNOWN_DOCSX_ENV_VARS: ReadonlyArray<string>;
61
+ /**
62
+ * The env rows. A passing row counts the recognised variables and names none of them; the viewer
63
+ * bin variable is left out because the `docsxai` bin sets it. A failing row names the one variable
64
+ * the user set wrong, since that is what they have to fix.
65
+ */
55
66
  export declare function checkEnv(env: NodeJS.ProcessEnv): DoctorCheck[];
56
67
  export {};