@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
@@ -2,21 +2,22 @@ import { z } from "zod";
2
2
  export declare const ViewportSize: z.ZodObject<{
3
3
  width: z.ZodNumber;
4
4
  height: z.ZodNumber;
5
- }, "strict", z.ZodTypeAny, {
6
- width: number;
7
- height: number;
8
- }, {
9
- width: number;
10
- height: number;
11
- }>;
5
+ }, z.core.$strict>;
12
6
  export type ViewportSize = z.infer<typeof ViewportSize>;
13
- export declare const ViewportPreset: z.ZodEnum<["desktop", "tablet", "mobile"]>;
7
+ export declare const ViewportPreset: z.ZodEnum<{
8
+ desktop: "desktop";
9
+ tablet: "tablet";
10
+ mobile: "mobile";
11
+ }>;
14
12
  export type ViewportPreset = z.infer<typeof ViewportPreset>;
15
- /** Named viewport presets — `desktop` 1440×900, `tablet` 834×1112, `mobile` 390×844. */
13
+ /** Named viewport presets, `desktop` 1440×900, `tablet` 834×1112, `mobile` 390×844. */
16
14
  export declare const VIEWPORT_PRESETS: Record<ViewportPreset, ViewportSize>;
17
15
  /** BCP-47 language tag (e.g. `en-GB`); shared by `environment.locale`, matrix locales and `copy_by_locale` keys. */
18
16
  export declare const LocaleTag: z.ZodString;
19
- export declare const ColorScheme: z.ZodEnum<["light", "dark"]>;
17
+ export declare const ColorScheme: z.ZodEnum<{
18
+ light: "light";
19
+ dark: "dark";
20
+ }>;
20
21
  export type ColorScheme = z.infer<typeof ColorScheme>;
21
22
  /**
22
23
  * Deterministic execution environment for a flow. All fields optional; applied at browser-context
@@ -24,44 +25,35 @@ export type ColorScheme = z.infer<typeof ColorScheme>;
24
25
  * wins per-key over the parent's (a child can pin just `viewport` and inherit the parent's clock).
25
26
  */
26
27
  export declare const EnvironmentSpec: z.ZodObject<{
27
- /** ISO-8601 instant the page clock is frozen at — `new Date()` etc. return this for the whole run. */
28
28
  clock: z.ZodOptional<z.ZodString>;
29
- /** BCP-47 language tag (e.g. `en-GB`). */
30
29
  locale: z.ZodOptional<z.ZodString>;
31
- /** IANA timezone (e.g. `Europe/Amsterdam`). */
32
30
  timezone: z.ZodOptional<z.ZodString>;
33
- /** `{ width, height }` in CSS pixels, or a named preset — see {@link VIEWPORT_PRESETS}. */
34
- viewport: z.ZodOptional<z.ZodUnion<[z.ZodEnum<["desktop", "tablet", "mobile"]>, z.ZodObject<{
31
+ viewport: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
32
+ desktop: "desktop";
33
+ tablet: "tablet";
34
+ mobile: "mobile";
35
+ }>, z.ZodObject<{
35
36
  width: z.ZodNumber;
36
37
  height: z.ZodNumber;
37
- }, "strict", z.ZodTypeAny, {
38
- width: number;
39
- height: number;
40
- }, {
41
- width: number;
42
- height: number;
43
- }>]>>;
44
- color_scheme: z.ZodOptional<z.ZodEnum<["light", "dark"]>>;
38
+ }, z.core.$strict>]>>;
39
+ color_scheme: z.ZodOptional<z.ZodEnum<{
40
+ light: "light";
41
+ dark: "dark";
42
+ }>>;
45
43
  reduced_motion: z.ZodOptional<z.ZodBoolean>;
46
- }, "strict", z.ZodTypeAny, {
47
- clock?: string | undefined;
48
- locale?: string | undefined;
49
- timezone?: string | undefined;
50
- viewport?: {
51
- width: number;
52
- height: number;
53
- } | "desktop" | "tablet" | "mobile" | undefined;
54
- color_scheme?: "light" | "dark" | undefined;
55
- reduced_motion?: boolean | undefined;
56
- }, {
57
- clock?: string | undefined;
58
- locale?: string | undefined;
59
- timezone?: string | undefined;
60
- viewport?: {
61
- width: number;
62
- height: number;
63
- } | "desktop" | "tablet" | "mobile" | undefined;
64
- color_scheme?: "light" | "dark" | undefined;
65
- reduced_motion?: boolean | undefined;
66
- }>;
44
+ }, z.core.$strict>;
67
45
  export type EnvironmentSpec = z.infer<typeof EnvironmentSpec>;
46
+ /**
47
+ * The stderr line for a CDP attach, which cannot apply context-level settings to a context the
48
+ * operator owns: names every `environment` field and the `contextOptions` that were skipped.
49
+ * `undefined` when nothing was skipped. The clock is a page-level install, so it still applies.
50
+ */
51
+ export declare function attachSkipNotice(env: EnvironmentSpec | undefined, hasContextOptions: boolean): string | undefined;
52
+ /** Map an {@link EnvironmentSpec} to the Playwright context options it pins (clock excluded, that's a page-level install). */
53
+ export declare function environmentContextOptions(env: EnvironmentSpec): {
54
+ locale?: string;
55
+ timezoneId?: string;
56
+ viewport?: ViewportSize;
57
+ colorScheme?: "light" | "dark";
58
+ reducedMotion?: "reduce" | "no-preference";
59
+ };
@@ -6,7 +6,7 @@ export const ViewportSize = z
6
6
  .object({ width: z.number().int().positive(), height: z.number().int().positive() })
7
7
  .strict();
8
8
  export const ViewportPreset = z.enum(["desktop", "tablet", "mobile"]);
9
- /** Named viewport presets — `desktop` 1440×900, `tablet` 834×1112, `mobile` 390×844. */
9
+ /** Named viewport presets, `desktop` 1440×900, `tablet` 834×1112, `mobile` 390×844. */
10
10
  export const VIEWPORT_PRESETS = {
11
11
  desktop: { width: 1440, height: 900 },
12
12
  tablet: { width: 834, height: 1112 },
@@ -24,15 +24,43 @@ export const ColorScheme = z.enum(["light", "dark"]);
24
24
  */
25
25
  export const EnvironmentSpec = z
26
26
  .object({
27
- /** ISO-8601 instant the page clock is frozen at — `new Date()` etc. return this for the whole run. */
27
+ /** ISO-8601 instant the page clock is frozen at, `new Date()` etc. return this for the whole run. */
28
28
  clock: z.string().datetime({ offset: true, local: true }).optional(),
29
29
  /** BCP-47 language tag (e.g. `en-GB`). */
30
30
  locale: LocaleTag.optional(),
31
31
  /** IANA timezone (e.g. `Europe/Amsterdam`). */
32
32
  timezone: z.string().min(1).optional(),
33
- /** `{ width, height }` in CSS pixels, or a named preset — see {@link VIEWPORT_PRESETS}. */
33
+ /** `{ width, height }` in CSS pixels, or a named preset, see {@link VIEWPORT_PRESETS}. */
34
34
  viewport: z.union([ViewportPreset, ViewportSize]).optional(),
35
35
  color_scheme: ColorScheme.optional(),
36
36
  reduced_motion: z.boolean().optional(),
37
37
  })
38
38
  .strict();
39
+ /**
40
+ * The stderr line for a CDP attach, which cannot apply context-level settings to a context the
41
+ * operator owns: names every `environment` field and the `contextOptions` that were skipped.
42
+ * `undefined` when nothing was skipped. The clock is a page-level install, so it still applies.
43
+ */
44
+ export function attachSkipNotice(env, hasContextOptions) {
45
+ const fields = ["locale", "timezone", "viewport", "color_scheme", "reduced_motion"]
46
+ .filter((k) => env?.[k] !== undefined)
47
+ .map((k) => `environment.${k}`);
48
+ if (hasContextOptions)
49
+ fields.push("contextOptions");
50
+ return fields.length
51
+ ? `launchPlaywrightSession: attached over CDP, where the browser context is externally owned; skipped: ${fields.join(", ")}\n`
52
+ : undefined;
53
+ }
54
+ /** Map an {@link EnvironmentSpec} to the Playwright context options it pins (clock excluded, that's a page-level install). */
55
+ export function environmentContextOptions(env) {
56
+ const viewport = typeof env.viewport === "string" ? VIEWPORT_PRESETS[env.viewport] : env.viewport;
57
+ return {
58
+ ...(env.locale ? { locale: env.locale } : {}),
59
+ ...(env.timezone ? { timezoneId: env.timezone } : {}),
60
+ ...(viewport ? { viewport } : {}),
61
+ ...(env.color_scheme ? { colorScheme: env.color_scheme } : {}),
62
+ ...(env.reduced_motion !== undefined
63
+ ? { reducedMotion: env.reduced_motion ? "reduce" : "no-preference" }
64
+ : {}),
65
+ };
66
+ }
@@ -20,7 +20,7 @@ export interface AdfAttachment {
20
20
  fileName: string;
21
21
  /** Absolute path of the source PNG inside the workspace. */
22
22
  sourcePath: string;
23
- /** sha256 (hex) of the source bytes — the publisher's skip-unchanged key. */
23
+ /** sha256 (hex) of the source bytes, the publisher's skip-unchanged key. */
24
24
  sha256: string;
25
25
  }
26
26
  export interface AdfDocument {
@@ -1,28 +1,27 @@
1
- // ADF (Atlassian Document Format) projection of a doc pack — pure, deterministic, zero HTTP.
1
+ // ADF (Atlassian Document Format) projection of a doc pack, pure, deterministic, zero HTTP.
2
2
  //
3
3
  // The engine emits projections only; all Confluence egress lives in the capability-declared
4
4
  // publisher plugin (`@docsxai/plugin-confluence`). This module turns a workspace's
5
5
  // doc pack (flow-files + step write-ups + burned screenshots) into Confluence Cloud REST v2
6
6
  // `atlas_doc_format` documents plus an attachments manifest, in one of two shapes:
7
7
  //
8
- // - `single` (default): ONE consolidated document for the whole project — every flow is an
9
- // anchored H2 section, every step an H3 — published as one page.
8
+ // - `single` (default): ONE consolidated document for the whole project, every flow is an
9
+ // anchored H2 section, every step an H3, published as one page.
10
10
  // - `page-tree`: a parent overview document (section "project") plus one child document per
11
11
  // flow (section = flow name).
12
12
  //
13
- // Media nodes reference attachments by `alt` file name with empty `id`/`collection` — the
13
+ // Media nodes reference attachments by `alt` file name with empty `id`/`collection`, the
14
14
  // publisher (or a host agent handing the projection to the Atlassian MCP) fills the file ids
15
15
  // in after upload. Attachment file names are `<flow>--<step>.png`, unique per document and
16
16
  // stable across modes.
17
17
  import { createHash } from "node:crypto";
18
- import { promises as fs } from "node:fs";
19
18
  import { parseFlowFile, resolveFlowExtends } from "../flow-file.js";
20
- import { resolveWorkspacePath } from "../workspace.js";
19
+ import { listFlowNamesInside, readFileInside, resolveWorkspacePath } from "../workspace.js";
21
20
  // ---------------------------------------------------------------------------
22
21
  // markdown → ADF (subset converter)
23
22
  // ---------------------------------------------------------------------------
24
23
  // Supported: paragraphs, fenced code blocks, bullet/ordered lists, `code`, **bold**, *em* /
25
- // _em_, [links](url). Anything else — raw HTML included — stays literal text inside an ADF
24
+ // _em_, [links](url). Anything else, raw HTML included, stays literal text inside an ADF
26
25
  // text node (ADF text is plain text, so markup can never be smuggled through).
27
26
  function text(value, marks) {
28
27
  return marks.length > 0 ? { type: "text", text: value, marks } : { type: "text", text: value };
@@ -87,7 +86,7 @@ export function inlineMarkdownToAdf(source, marks = []) {
87
86
  if (token.start > 0)
88
87
  out.push(text(rest.slice(0, token.start), marks));
89
88
  if (token.kind === "code") {
90
- // Code spans take no nested marks — literal content.
89
+ // Code spans take no nested marks, literal content.
91
90
  out.push(text(token.inner, [...marks, { type: "code" }]));
92
91
  }
93
92
  else if (token.kind === "link") {
@@ -184,32 +183,23 @@ function mediaSingle(fileName) {
184
183
  ],
185
184
  };
186
185
  }
187
- async function readIfExists(p) {
188
- try {
189
- return await fs.readFile(p);
190
- }
191
- catch {
192
- return null;
193
- }
194
- }
195
186
  async function projectFlow(workspaceDir, flowName, flow, warnings) {
196
187
  const nodes = [heading(2, flow.name)];
197
188
  const attachments = [];
198
189
  for (const step of flow.steps) {
199
- const mdPath = resolveWorkspacePath(workspaceDir, "docs", flowName, `${step.id}.md`);
200
- const md = await readIfExists(mdPath);
190
+ const md = await readFileInside(workspaceDir, "docs", flowName, `${step.id}.md`);
201
191
  const burnedPath = resolveWorkspacePath(workspaceDir, "docs", flowName, "burned", `${step.id}.png`);
202
192
  const cleanPath = resolveWorkspacePath(workspaceDir, "docs", flowName, "screenshots", `${step.id}.png`);
203
193
  let shotPath = null;
204
- let shot = await readIfExists(burnedPath);
194
+ let shot = await readFileInside(workspaceDir, "docs", flowName, "burned", `${step.id}.png`);
205
195
  if (shot) {
206
196
  shotPath = burnedPath;
207
197
  }
208
198
  else {
209
- shot = await readIfExists(cleanPath);
199
+ shot = await readFileInside(workspaceDir, "docs", flowName, "screenshots", `${step.id}.png`);
210
200
  if (shot) {
211
201
  shotPath = cleanPath;
212
- warnings.push(`flow "${flowName}" step "${step.id}": burned screenshot missing — falling back to the clean screenshot`);
202
+ warnings.push(`flow "${flowName}" step "${step.id}": burned screenshot missing, falling back to the clean screenshot`);
213
203
  }
214
204
  }
215
205
  if (md === null && shot === null)
@@ -234,11 +224,7 @@ async function projectFlow(workspaceDir, flowName, flow, warnings) {
234
224
  }
235
225
  async function loadFlows(workspaceDir, only) {
236
226
  const flowsDir = resolveWorkspacePath(workspaceDir, "flows");
237
- const entries = await fs.readdir(flowsDir).catch(() => []);
238
- const names = entries
239
- .filter((e) => e.endsWith(".flow.yaml"))
240
- .map((e) => e.slice(0, -".flow.yaml".length))
241
- .sort();
227
+ const names = await listFlowNamesInside(workspaceDir);
242
228
  const wanted = only && only.length > 0 ? names.filter((n) => only.includes(n)) : names;
243
229
  if (only) {
244
230
  for (const o of only) {
@@ -248,7 +234,10 @@ async function loadFlows(workspaceDir, only) {
248
234
  }
249
235
  const load = async (name) => {
250
236
  const p = resolveWorkspacePath(workspaceDir, "flows", `${name}.flow.yaml`);
251
- return parseFlowFile(await fs.readFile(p, "utf8"), p);
237
+ const text = await readFileInside(workspaceDir, "flows", `${name}.flow.yaml`);
238
+ if (text === null)
239
+ throw new Error(`no flow named "${name}" at ${p}`);
240
+ return parseFlowFile(text.toString("utf8"), p);
252
241
  };
253
242
  const out = [];
254
243
  for (const name of wanted) {
@@ -6,7 +6,7 @@ export interface PlaywrightExportOptions {
6
6
  /**
7
7
  * Render a flow as a self-contained Playwright `.spec.ts`. The flow must have its `extends`
8
8
  * chain resolved first (see `resolveFlowExtends`) so the emitted spec carries the merged steps.
9
- * Pure string transform — deterministic for a given flow.
9
+ * Pure string transform, deterministic for a given flow.
10
10
  */
11
11
  export declare function exportFlowAsPlaywrightTest(flow: FlowFile, options?: PlaywrightExportOptions): string;
12
12
  export interface ExportedSpec {
@@ -1,16 +1,15 @@
1
- // Flow-file → Playwright test export — pure, deterministic, zero HTTP.
1
+ // Flow-file → Playwright test export, pure, deterministic, zero HTTP.
2
2
  //
3
3
  // Each flow becomes one self-contained `.spec.ts`: locator const declarations from the flow's
4
4
  // `locators` map, steps translated to Playwright actions, `wait_for` to waits, `success` to
5
5
  // `expect(...)` assertions, the `environment` block to `test.use({...})` (+ `page.clock` for a
6
- // frozen clock), and `optional: true` steps wrapped in try/catch (conditionally-present UI — a
6
+ // frozen clock), and `optional: true` steps wrapped in try/catch (conditionally-present UI, a
7
7
  // miss is tolerated, mirroring the runtime). The flow-file stays the source of truth: generated
8
8
  // specs carry a "regenerate, don't hand-edit" header and are meant to live in the consumer's
9
9
  // Playwright suite as a drift tripwire between docs and reality.
10
- import { promises as fs } from "node:fs";
11
10
  import { VIEWPORT_PRESETS, } from "../doc-pack.js";
12
11
  import { locatorRefName, parseFlowFile, resolveFlowExtends } from "../flow-file.js";
13
- import { resolveWorkspacePath } from "../workspace.js";
12
+ import { listFlowNamesInside, readFileInside, resolveWorkspacePath } from "../workspace.js";
14
13
  const RESERVED = new Set([
15
14
  // ES reserved words + the identifiers the generated scaffold itself uses.
16
15
  ...`await break case catch class const continue debugger default delete do else enum export
@@ -67,7 +66,7 @@ function actionLines(step, ids) {
67
66
  const target = step.target !== undefined ? locatorExpr(step.target, ids) : null;
68
67
  const value = step.value;
69
68
  const missing = (what) => [
70
- `// step "${step.id}": ${step.action} without ${what} — nothing to emit`,
69
+ `// step "${step.id}": ${step.action} without ${what}, nothing to emit`,
71
70
  ];
72
71
  // A step's `timeout_ms` becomes Playwright's per-call `{ timeout }`; absent, the call is unchanged.
73
72
  const callOpts = step.timeout_ms !== undefined ? `{ timeout: ${step.timeout_ms} }` : null;
@@ -143,7 +142,7 @@ function waitLines(wait, step, ids) {
143
142
  // visibility wait on the step target when there is one.
144
143
  return step.target !== undefined
145
144
  ? [`await ${locatorExpr(step.target, ids)}.waitFor({ state: "visible" }); // element_stable`]
146
- : [`// wait_for: element_stable — Playwright auto-waits on the next action`];
145
+ : [`// wait_for: element_stable. Playwright auto-waits on the next action`];
147
146
  }
148
147
  if ("selector" in wait) {
149
148
  const opts = wait.timeout_ms !== undefined
@@ -179,14 +178,14 @@ function stepLines(step, ids) {
179
178
  "try {",
180
179
  ...body.map((l) => ` ${l}`),
181
180
  "} catch {",
182
- " // optional step — conditionally-present UI; a miss is tolerated",
181
+ " // optional step: conditionally-present UI; a miss is tolerated",
183
182
  "}",
184
183
  ];
185
184
  }
186
185
  /**
187
186
  * Render a flow as a self-contained Playwright `.spec.ts`. The flow must have its `extends`
188
187
  * chain resolved first (see `resolveFlowExtends`) so the emitted spec carries the merged steps.
189
- * Pure string transform — deterministic for a given flow.
188
+ * Pure string transform, deterministic for a given flow.
190
189
  */
191
190
  export function exportFlowAsPlaywrightTest(flow, options = {}) {
192
191
  if (flow.extends) {
@@ -198,7 +197,7 @@ export function exportFlowAsPlaywrightTest(flow, options = {}) {
198
197
  const fileName = options.flowFileName ?? flow.name;
199
198
  const ids = locatorIdentifiers(flow);
200
199
  const lines = [
201
- `// generated from ${fileName}.flow.yaml — regenerate, don't hand-edit`,
200
+ `// generated from ${fileName}.flow.yaml. Regenerate, don't hand-edit`,
202
201
  `import { expect, test } from "@playwright/test";`,
203
202
  "",
204
203
  ];
@@ -226,11 +225,7 @@ export function exportFlowAsPlaywrightTest(flow, options = {}) {
226
225
  */
227
226
  export async function exportWorkspaceFlowsAsPlaywrightTests(opts) {
228
227
  const flowsDir = resolveWorkspacePath(opts.workspaceDir, "flows");
229
- const entries = await fs.readdir(flowsDir).catch(() => []);
230
- const names = entries
231
- .filter((e) => e.endsWith(".flow.yaml"))
232
- .map((e) => e.slice(0, -".flow.yaml".length))
233
- .sort();
228
+ const names = await listFlowNamesInside(opts.workspaceDir);
234
229
  const wanted = opts.flows && opts.flows.length > 0 ? opts.flows : names;
235
230
  for (const w of wanted) {
236
231
  if (!names.includes(w))
@@ -238,7 +233,10 @@ export async function exportWorkspaceFlowsAsPlaywrightTests(opts) {
238
233
  }
239
234
  const load = async (name) => {
240
235
  const p = resolveWorkspacePath(opts.workspaceDir, "flows", `${name}.flow.yaml`);
241
- return parseFlowFile(await fs.readFile(p, "utf8"), p);
236
+ const text = await readFileInside(opts.workspaceDir, "flows", `${name}.flow.yaml`);
237
+ if (text === null)
238
+ throw new Error(`no flow named "${name}" at ${p}`);
239
+ return parseFlowFile(text.toString("utf8"), p);
242
240
  };
243
241
  const out = [];
244
242
  for (const name of wanted) {
@@ -22,6 +22,6 @@ export declare function referencedLocatorNames(flow: FlowFile): Set<string>;
22
22
  * `prerequisites` are merged (this flow wins on locator-name collisions); `environment` merges per-key with
23
23
  * this flow's keys winning; `redactions` concatenate (parent's first); step ids must be unique across the
24
24
  * merge. `matrix` is the child's own (never inherited). Chains are followed recursively; cycles throw. `loadFlowFile(name)` parses `flows/<name>.flow.yaml`
25
- * (a flow with its own `extends` un-resolved — this function recurses). The result has no `extends`.
25
+ * (a flow with its own `extends` un-resolved, this function recurses). The result has no `extends`.
26
26
  */
27
27
  export declare function resolveFlowExtends(flow: FlowFile, loadFlowFile: (name: string) => Promise<FlowFile> | FlowFile, visited?: Set<string>): Promise<FlowFile>;
package/dist/flow-file.js CHANGED
@@ -2,7 +2,7 @@
2
2
  //
3
3
  // A flow-file is the source of truth for execution: declarative YAML, hand-editable,
4
4
  // translated to Playwright at run time (see flow-runtime, to come). This module is the
5
- // parse/validate/serialize boundary — everything downstream works with the validated
5
+ // parse/validate/serialize boundary, everything downstream works with the validated
6
6
  // `FlowFile` value, never raw YAML.
7
7
  import { parse as parseYaml, stringify as stringifyYaml } from "yaml";
8
8
  import { FlowFile } from "./doc-pack.js";
@@ -15,8 +15,23 @@ export class FlowFileError extends Error {
15
15
  this.name = "FlowFileError";
16
16
  }
17
17
  }
18
+ /** The issues to print for `issue`: a union failure is replaced by the issues of its closest branch. */
19
+ function expandIssue(issue) {
20
+ if (issue.code !== "invalid_union")
21
+ return [issue];
22
+ // Zod 4 keeps the issues of each branch in `errors`, with paths relative to the union.
23
+ const branches = issue.errors;
24
+ if (branches.length === 0)
25
+ return [issue];
26
+ // The branch that got deepest into the value is the one the author meant; ties go to fewer issues.
27
+ const depth = (b) => Math.max(0, ...b.map((i) => i.path.length));
28
+ const best = branches.reduce((a, b) => depth(b) > depth(a) || (depth(b) === depth(a) && b.length < a.length) ? b : a);
29
+ const inPlace = best.map((i) => ({ ...i, path: [...issue.path, ...i.path] }));
30
+ return inPlace.length > 0 ? inPlace.flatMap(expandIssue) : [issue];
31
+ }
18
32
  function formatZodIssues(err) {
19
33
  return err.issues
34
+ .flatMap(expandIssue)
20
35
  .map((i) => {
21
36
  const path = i.path.length ? i.path.join(".") : "(root)";
22
37
  return ` • ${path}: ${i.message}`;
@@ -30,14 +45,14 @@ export function parseFlowFile(yamlText, source = "<flow-file>") {
30
45
  raw = parseYaml(yamlText);
31
46
  }
32
47
  catch (e) {
33
- throw new FlowFileError(`${source}: not valid YAML — ${e.message}`, e);
48
+ throw new FlowFileError(`${source}: not valid YAML: ${e.message}`, e);
34
49
  }
35
50
  const result = FlowFile.safeParse(raw);
36
51
  if (!result.success) {
37
52
  throw new FlowFileError(`${source}: invalid flow-file:\n${formatZodIssues(result.error)}`, result.error);
38
53
  }
39
54
  const flow = result.data;
40
- // A flow with `extends` may reference locators it inherits from the parent — defer the ref check to
55
+ // A flow with `extends` may reference locators it inherits from the parent, defer the ref check to
41
56
  // `resolveFlowExtends`, which runs it on the merged flow.
42
57
  if (!flow.extends)
43
58
  assertLocatorRefsResolve(flow, source);
@@ -157,7 +172,7 @@ function assertStepIdsUnique(flow, source) {
157
172
  * `prerequisites` are merged (this flow wins on locator-name collisions); `environment` merges per-key with
158
173
  * this flow's keys winning; `redactions` concatenate (parent's first); step ids must be unique across the
159
174
  * merge. `matrix` is the child's own (never inherited). Chains are followed recursively; cycles throw. `loadFlowFile(name)` parses `flows/<name>.flow.yaml`
160
- * (a flow with its own `extends` un-resolved — this function recurses). The result has no `extends`.
175
+ * (a flow with its own `extends` un-resolved, this function recurses). The result has no `extends`.
161
176
  */
162
177
  export async function resolveFlowExtends(flow, loadFlowFile, visited = new Set()) {
163
178
  if (!flow.extends)
@@ -171,6 +186,9 @@ export async function resolveFlowExtends(flow, loadFlowFile, visited = new Set()
171
186
  parentRaw = await loadFlowFile(flow.extends);
172
187
  }
173
188
  catch (e) {
189
+ if (e?.code === "ENOENT") {
190
+ throw new FlowFileError(`flow "${flow.name}" extends "${flow.extends}", but flows/${flow.extends}.flow.yaml does not exist`, e);
191
+ }
174
192
  throw e instanceof FlowFileError
175
193
  ? e
176
194
  : new FlowFileError(`flow "${flow.name}": cannot load \`extends\` target "${flow.extends}": ${e.message}`, e);
@@ -9,7 +9,7 @@ export declare class FlowExecutionError extends Error {
9
9
  }
10
10
  /**
11
11
  * Best-effort 1-line cause extracted from a Playwright actionability log (or similar driver
12
- * error). Returns undefined when nothing matches — keeps the halt message short rather than
12
+ * error). Returns undefined when nothing matches, keeps the halt message short rather than
13
13
  * guessing. Surfaced as a `[cause]` prefix on the halt message so the agent doesn't have to
14
14
  * scan the multi-line actionability log.
15
15
  */
package/dist/flow-halt.js CHANGED
@@ -17,7 +17,7 @@ export class FlowExecutionError extends Error {
17
17
  }
18
18
  /**
19
19
  * Best-effort 1-line cause extracted from a Playwright actionability log (or similar driver
20
- * error). Returns undefined when nothing matches — keeps the halt message short rather than
20
+ * error). Returns undefined when nothing matches, keeps the halt message short rather than
21
21
  * guessing. Surfaced as a `[cause]` prefix on the halt message so the agent doesn't have to
22
22
  * scan the multi-line actionability log.
23
23
  */
@@ -27,6 +27,18 @@ export function inferHaltCause(rawError) {
27
27
  /docsxai: cannot hide/i,
28
28
  "the browser can't apply the hide rule (no constructable stylesheets), so the element would stay visible",
29
29
  ],
30
+ [
31
+ /net::ERR_(?:CONNECTION_REFUSED|CONNECTION_RESET|CONNECTION_TIMED_OUT|NAME_NOT_RESOLVED|ADDRESS_UNREACHABLE|INTERNET_DISCONNECTED)\b/i,
32
+ "the app did not answer: start it, then check app_url in .docsxai.json or pass --base-url",
33
+ ],
34
+ [
35
+ /net::ERR_(?:CERT|SSL)_\w+/i,
36
+ "the app's TLS certificate was rejected: pass --ignore-https-errors, or set ignore_https_errors in .docsxai.json",
37
+ ],
38
+ [
39
+ /Cannot navigate to invalid URL/i,
40
+ "a relative path has no app_url to resolve against: set app_url in .docsxai.json or pass --base-url",
41
+ ],
30
42
  [/element is disabled\b/i, "target is disabled"],
31
43
  [/element is not enabled\b/i, "target is not enabled"],
32
44
  [
@@ -58,11 +70,11 @@ export function inferHaltCause(rawError) {
58
70
  [/intercepts? pointer events\b/i, "target is covered by another element"],
59
71
  [
60
72
  /strict mode violation\b/i,
61
- "selector matched multiple elements (strict-mode violation) — scope with :visible / :nth-match",
73
+ "selector matched multiple elements (strict-mode violation); scope with :visible / :nth-match",
62
74
  ],
63
75
  [
64
76
  /timeout .* exceeded.*waiting for/is,
65
- "timeout waiting for selector — element didn't appear in time (consider raising timeout_ms or revisiting the locator)",
77
+ "timeout waiting for selector: element didn't appear in time (consider raising timeout_ms or revisiting the locator)",
66
78
  ],
67
79
  ];
68
80
  for (const [re, msg] of hints) {
@@ -8,7 +8,7 @@ export type LintIssue = {
8
8
  message: string;
9
9
  suggestion?: string;
10
10
  };
11
- /** An injectable lint rule — the open hinge for the plugins runtime. Runs after the built-ins. */
11
+ /** An injectable lint rule, the open hinge for the plugins runtime. Runs after the built-ins. */
12
12
  export type LintRule = {
13
13
  /** Stable diagnostic code (the built-ins use `RNNN`; injected rules should pick another prefix). */
14
14
  code: string;
@@ -19,6 +19,8 @@ export type LintOptions = {
19
19
  loadFlow?: (name: string) => Promise<FlowFile> | FlowFile;
20
20
  /** Additional rules run after the built-ins (same flow, same options). */
21
21
  extraRules?: LintRule[];
22
+ /** The flow's file name (`checkout.flow.yaml`), for the rules that compare it with the flow's name. */
23
+ fileName?: string;
22
24
  };
23
25
  export declare function lintFlow(flow: FlowFile, opts?: LintOptions): Promise<LintIssue[]>;
24
26
  export declare function formatIssuesText(issues: LintIssue[]): string;