@docsxai/engine 0.2.1-rc.1 → 0.3.0-rc.1

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 (94) hide show
  1. package/README.md +18 -5
  2. package/dist/address-class.d.ts +14 -0
  3. package/dist/address-class.js +151 -0
  4. package/dist/auth/api-login.d.ts +3 -3
  5. package/dist/auth/email-otp.d.ts +60 -60
  6. package/dist/auth/jwt-injection.d.ts +45 -45
  7. package/dist/auth/pat-header.d.ts +2 -2
  8. package/dist/auth/types.d.ts +2 -2
  9. package/dist/auth/ui-form.d.ts +54 -54
  10. package/dist/auth/webauthn.d.ts +22 -22
  11. package/dist/backend-client-contracts.d.ts +4 -2
  12. package/dist/calibrate.d.ts +2 -2
  13. package/dist/calibrate.js +5 -0
  14. package/dist/cli-commands-authoring.js +23 -4
  15. package/dist/cli-commands-backend.js +2 -2
  16. package/dist/cli-commands-docpack.d.ts +5 -0
  17. package/dist/cli-commands-docpack.js +70 -24
  18. package/dist/cli-commands-pack.d.ts +2 -0
  19. package/dist/cli-commands-pack.js +69 -0
  20. package/dist/cli-commands-session.js +92 -89
  21. package/dist/cli-retired.d.ts +6 -0
  22. package/dist/cli-retired.js +12 -0
  23. package/dist/cli-usage.d.ts +1 -1
  24. package/dist/cli-usage.js +52 -4
  25. package/dist/cli-verify.d.ts +14 -0
  26. package/dist/cli-verify.js +54 -0
  27. package/dist/cli.js +14 -1
  28. package/dist/deprecation.d.ts +19 -0
  29. package/dist/deprecation.js +32 -0
  30. package/dist/diagnose.d.ts +25 -0
  31. package/dist/diagnose.js +69 -3
  32. package/dist/diff-compute.js +1 -0
  33. package/dist/doc-pack-io.d.ts +14 -0
  34. package/dist/doc-pack-io.js +121 -14
  35. package/dist/doc-pack.d.ts +2282 -387
  36. package/dist/doc-pack.js +135 -43
  37. package/dist/doctor-checks.d.ts +1 -1
  38. package/dist/doctor-checks.js +25 -1
  39. package/dist/driver-budget.d.ts +6 -0
  40. package/dist/driver-budget.js +15 -0
  41. package/dist/egress-guard.d.ts +58 -0
  42. package/dist/egress-guard.js +136 -0
  43. package/dist/environment-spec.d.ts +67 -0
  44. package/dist/environment-spec.js +38 -0
  45. package/dist/export/playwright-test.js +42 -10
  46. package/dist/flow-file.d.ts +9 -3
  47. package/dist/flow-file.js +21 -1
  48. package/dist/flow-halt.d.ts +16 -0
  49. package/dist/flow-halt.js +76 -0
  50. package/dist/flow-hidden.d.ts +9 -0
  51. package/dist/flow-hidden.js +20 -0
  52. package/dist/flow-lint.js +91 -1
  53. package/dist/flow-matrix-lint.d.ts +10 -0
  54. package/dist/flow-matrix-lint.js +40 -0
  55. package/dist/flow-matrix.d.ts +44 -0
  56. package/dist/flow-matrix.js +238 -0
  57. package/dist/flow-name-rules.d.ts +15 -0
  58. package/dist/flow-name-rules.js +39 -0
  59. package/dist/flow-runtime.d.ts +52 -22
  60. package/dist/flow-runtime.js +63 -117
  61. package/dist/flow-success.d.ts +3 -0
  62. package/dist/flow-success.js +37 -0
  63. package/dist/flow-tree.d.ts +2 -0
  64. package/dist/flow-tree.js +17 -5
  65. package/dist/flow-wait.d.ts +3 -0
  66. package/dist/flow-wait.js +22 -0
  67. package/dist/index.d.ts +5 -0
  68. package/dist/index.js +5 -0
  69. package/dist/matrix-spec.d.ts +145 -0
  70. package/dist/matrix-spec.js +120 -0
  71. package/dist/page-hide.d.ts +10 -0
  72. package/dist/page-hide.js +45 -0
  73. package/dist/page-settle.d.ts +39 -0
  74. package/dist/page-settle.js +142 -0
  75. package/dist/playwright-driver.d.ts +28 -8
  76. package/dist/playwright-driver.js +73 -28
  77. package/dist/plugins/manifest.d.ts +9 -9
  78. package/dist/run-flows.d.ts +40 -0
  79. package/dist/run-flows.js +129 -0
  80. package/dist/style.d.ts +2 -2
  81. package/dist/upload-path.d.ts +15 -0
  82. package/dist/upload-path.js +63 -0
  83. package/dist/verify-compare.d.ts +43 -0
  84. package/dist/verify-compare.js +237 -0
  85. package/dist/verify-determinism.d.ts +16 -0
  86. package/dist/verify-determinism.js +88 -0
  87. package/dist/verify-report.d.ts +53 -0
  88. package/dist/verify-report.js +141 -0
  89. package/dist/verify-tree.d.ts +27 -0
  90. package/dist/verify-tree.js +95 -0
  91. package/dist/viewer-bin.d.ts +6 -0
  92. package/dist/viewer-bin.js +24 -0
  93. package/dist/zip.d.ts +2 -2
  94. package/package.json +3 -2
@@ -8,12 +8,12 @@ export declare const PreStep: z.ZodObject<{
8
8
  /** Env var *name* holding the fill value (required for `fill`). */
9
9
  value_env: z.ZodOptional<z.ZodString>;
10
10
  }, "strict", z.ZodTypeAny, {
11
- action: "click" | "fill";
12
11
  selector: string;
12
+ action: "fill" | "click";
13
13
  value_env?: string | undefined;
14
14
  }, {
15
- action: "click" | "fill";
16
15
  selector: string;
16
+ action: "fill" | "click";
17
17
  value_env?: string | undefined;
18
18
  }>;
19
19
  export type PreStep = z.infer<typeof PreStep>;
@@ -32,19 +32,19 @@ export declare const UiFormTotpOptions: z.ZodObject<{
32
32
  period: z.ZodDefault<z.ZodNumber>;
33
33
  algorithm: z.ZodDefault<z.ZodEnum<["sha1", "sha256"]>>;
34
34
  }, "strict", z.ZodTypeAny, {
35
+ digits: 8 | 6;
36
+ period: number;
37
+ algorithm: "sha1" | "sha256";
35
38
  secret_env: string;
36
39
  otp_selector: string;
37
40
  submit_selector?: string | undefined;
38
- digits: 6 | 8;
39
- period: number;
40
- algorithm: "sha1" | "sha256";
41
41
  }, {
42
42
  secret_env: string;
43
43
  otp_selector: string;
44
- submit_selector?: string | undefined;
45
- digits?: 6 | 8 | undefined;
44
+ digits?: 8 | 6 | undefined;
46
45
  period?: number | undefined;
47
46
  algorithm?: "sha1" | "sha256" | undefined;
47
+ submit_selector?: string | undefined;
48
48
  }>;
49
49
  export type UiFormTotpOptions = z.infer<typeof UiFormTotpOptions>;
50
50
  export declare const UiFormOptions: z.ZodEffects<z.ZodObject<{
@@ -67,12 +67,12 @@ export declare const UiFormOptions: z.ZodEffects<z.ZodObject<{
67
67
  /** Env var *name* holding the fill value (required for `fill`). */
68
68
  value_env: z.ZodOptional<z.ZodString>;
69
69
  }, "strict", z.ZodTypeAny, {
70
- action: "click" | "fill";
71
70
  selector: string;
71
+ action: "fill" | "click";
72
72
  value_env?: string | undefined;
73
73
  }, {
74
- action: "click" | "fill";
75
74
  selector: string;
75
+ action: "fill" | "click";
76
76
  value_env?: string | undefined;
77
77
  }>, "many">>;
78
78
  totp: z.ZodOptional<z.ZodObject<{
@@ -84,108 +84,108 @@ export declare const UiFormOptions: z.ZodEffects<z.ZodObject<{
84
84
  period: z.ZodDefault<z.ZodNumber>;
85
85
  algorithm: z.ZodDefault<z.ZodEnum<["sha1", "sha256"]>>;
86
86
  }, "strict", z.ZodTypeAny, {
87
+ digits: 8 | 6;
88
+ period: number;
89
+ algorithm: "sha1" | "sha256";
87
90
  secret_env: string;
88
91
  otp_selector: string;
89
92
  submit_selector?: string | undefined;
90
- digits: 6 | 8;
91
- period: number;
92
- algorithm: "sha1" | "sha256";
93
93
  }, {
94
94
  secret_env: string;
95
95
  otp_selector: string;
96
- submit_selector?: string | undefined;
97
- digits?: 6 | 8 | undefined;
96
+ digits?: 8 | 6 | undefined;
98
97
  period?: number | undefined;
99
98
  algorithm?: "sha1" | "sha256" | undefined;
99
+ submit_selector?: string | undefined;
100
100
  }>>;
101
101
  }, "strict", z.ZodTypeAny, {
102
+ timeout_ms: number;
102
103
  login_url: string;
104
+ ignore_https_errors: boolean;
105
+ submit_selector: string;
103
106
  username_selector: string;
104
107
  password_selector: string;
105
- submit_selector: string;
106
- success_selector?: string | undefined;
107
- url_matches?: string | undefined;
108
- timeout_ms: number;
109
- ignore_https_errors: boolean;
110
108
  pre_steps: {
111
- action: "click" | "fill";
112
109
  selector: string;
110
+ action: "fill" | "click";
113
111
  value_env?: string | undefined;
114
112
  }[];
113
+ url_matches?: string | undefined;
115
114
  totp?: {
115
+ digits: 8 | 6;
116
+ period: number;
117
+ algorithm: "sha1" | "sha256";
116
118
  secret_env: string;
117
119
  otp_selector: string;
118
120
  submit_selector?: string | undefined;
119
- digits: 6 | 8;
120
- period: number;
121
- algorithm: "sha1" | "sha256";
122
121
  } | undefined;
122
+ success_selector?: string | undefined;
123
123
  }, {
124
124
  login_url: string;
125
+ submit_selector: string;
125
126
  username_selector: string;
126
127
  password_selector: string;
127
- submit_selector: string;
128
- success_selector?: string | undefined;
129
- url_matches?: string | undefined;
130
128
  timeout_ms?: number | undefined;
131
- ignore_https_errors?: boolean | undefined;
132
- pre_steps?: {
133
- action: "click" | "fill";
134
- selector: string;
135
- value_env?: string | undefined;
136
- }[] | undefined;
129
+ url_matches?: string | undefined;
137
130
  totp?: {
138
131
  secret_env: string;
139
132
  otp_selector: string;
140
- submit_selector?: string | undefined;
141
- digits?: 6 | 8 | undefined;
133
+ digits?: 8 | 6 | undefined;
142
134
  period?: number | undefined;
143
135
  algorithm?: "sha1" | "sha256" | undefined;
136
+ submit_selector?: string | undefined;
144
137
  } | undefined;
138
+ ignore_https_errors?: boolean | undefined;
139
+ success_selector?: string | undefined;
140
+ pre_steps?: {
141
+ selector: string;
142
+ action: "fill" | "click";
143
+ value_env?: string | undefined;
144
+ }[] | undefined;
145
145
  }>, {
146
+ timeout_ms: number;
146
147
  login_url: string;
148
+ ignore_https_errors: boolean;
149
+ submit_selector: string;
147
150
  username_selector: string;
148
151
  password_selector: string;
149
- submit_selector: string;
150
- success_selector?: string | undefined;
151
- url_matches?: string | undefined;
152
- timeout_ms: number;
153
- ignore_https_errors: boolean;
154
152
  pre_steps: {
155
- action: "click" | "fill";
156
153
  selector: string;
154
+ action: "fill" | "click";
157
155
  value_env?: string | undefined;
158
156
  }[];
157
+ url_matches?: string | undefined;
159
158
  totp?: {
159
+ digits: 8 | 6;
160
+ period: number;
161
+ algorithm: "sha1" | "sha256";
160
162
  secret_env: string;
161
163
  otp_selector: string;
162
164
  submit_selector?: string | undefined;
163
- digits: 6 | 8;
164
- period: number;
165
- algorithm: "sha1" | "sha256";
166
165
  } | undefined;
166
+ success_selector?: string | undefined;
167
167
  }, {
168
168
  login_url: string;
169
+ submit_selector: string;
169
170
  username_selector: string;
170
171
  password_selector: string;
171
- submit_selector: string;
172
- success_selector?: string | undefined;
173
- url_matches?: string | undefined;
174
172
  timeout_ms?: number | undefined;
175
- ignore_https_errors?: boolean | undefined;
176
- pre_steps?: {
177
- action: "click" | "fill";
178
- selector: string;
179
- value_env?: string | undefined;
180
- }[] | undefined;
173
+ url_matches?: string | undefined;
181
174
  totp?: {
182
175
  secret_env: string;
183
176
  otp_selector: string;
184
- submit_selector?: string | undefined;
185
- digits?: 6 | 8 | undefined;
177
+ digits?: 8 | 6 | undefined;
186
178
  period?: number | undefined;
187
179
  algorithm?: "sha1" | "sha256" | undefined;
180
+ submit_selector?: string | undefined;
188
181
  } | undefined;
182
+ ignore_https_errors?: boolean | undefined;
183
+ success_selector?: string | undefined;
184
+ pre_steps?: {
185
+ selector: string;
186
+ action: "fill" | "click";
187
+ value_env?: string | undefined;
188
+ }[] | undefined;
189
189
  }>;
190
190
  export type UiFormOptions = z.infer<typeof UiFormOptions>;
191
191
  export declare class UiFormStrategy implements AuthStrategy {
@@ -17,64 +17,64 @@ export declare const WebauthnOptions: z.ZodEffects<z.ZodObject<{
17
17
  selector: z.ZodString;
18
18
  value_env: z.ZodOptional<z.ZodString>;
19
19
  }, "strict", z.ZodTypeAny, {
20
- action: "click" | "fill";
21
20
  selector: string;
21
+ action: "fill" | "click";
22
22
  value_env?: string | undefined;
23
23
  }, {
24
- action: "click" | "fill";
25
24
  selector: string;
25
+ action: "fill" | "click";
26
26
  value_env?: string | undefined;
27
27
  }>, "many">>;
28
28
  }, "strict", z.ZodTypeAny, {
29
- login_url: string;
30
- trigger_selector: string;
31
- username_selector?: string | undefined;
32
- success_selector?: string | undefined;
33
- url_matches?: string | undefined;
34
29
  timeout_ms: number;
30
+ login_url: string;
35
31
  ignore_https_errors: boolean;
36
32
  pre_steps: {
37
- action: "click" | "fill";
38
33
  selector: string;
34
+ action: "fill" | "click";
39
35
  value_env?: string | undefined;
40
36
  }[];
41
- }, {
42
- login_url: string;
43
37
  trigger_selector: string;
38
+ url_matches?: string | undefined;
44
39
  username_selector?: string | undefined;
45
40
  success_selector?: string | undefined;
46
- url_matches?: string | undefined;
41
+ }, {
42
+ login_url: string;
43
+ trigger_selector: string;
47
44
  timeout_ms?: number | undefined;
45
+ url_matches?: string | undefined;
48
46
  ignore_https_errors?: boolean | undefined;
47
+ username_selector?: string | undefined;
48
+ success_selector?: string | undefined;
49
49
  pre_steps?: {
50
- action: "click" | "fill";
51
50
  selector: string;
51
+ action: "fill" | "click";
52
52
  value_env?: string | undefined;
53
53
  }[] | undefined;
54
54
  }>, {
55
- login_url: string;
56
- trigger_selector: string;
57
- username_selector?: string | undefined;
58
- success_selector?: string | undefined;
59
- url_matches?: string | undefined;
60
55
  timeout_ms: number;
56
+ login_url: string;
61
57
  ignore_https_errors: boolean;
62
58
  pre_steps: {
63
- action: "click" | "fill";
64
59
  selector: string;
60
+ action: "fill" | "click";
65
61
  value_env?: string | undefined;
66
62
  }[];
67
- }, {
68
- login_url: string;
69
63
  trigger_selector: string;
64
+ url_matches?: string | undefined;
70
65
  username_selector?: string | undefined;
71
66
  success_selector?: string | undefined;
72
- url_matches?: string | undefined;
67
+ }, {
68
+ login_url: string;
69
+ trigger_selector: string;
73
70
  timeout_ms?: number | undefined;
71
+ url_matches?: string | undefined;
74
72
  ignore_https_errors?: boolean | undefined;
73
+ username_selector?: string | undefined;
74
+ success_selector?: string | undefined;
75
75
  pre_steps?: {
76
- action: "click" | "fill";
77
76
  selector: string;
77
+ action: "fill" | "click";
78
78
  value_env?: string | undefined;
79
79
  }[] | undefined;
80
80
  }>;
@@ -13,6 +13,8 @@ export interface Project {
13
13
  name: string;
14
14
  created_at: string;
15
15
  head_revision_id: string | null;
16
+ /** Base URL of the running app the project documents; webhook runs use it as the workspace `app_url`. */
17
+ app_url?: string;
16
18
  }
17
19
  export interface Revision {
18
20
  id: string;
@@ -41,8 +43,8 @@ export interface BlobRef {
41
43
  }
42
44
  export declare class BackendClientError extends Error {
43
45
  readonly status?: number | undefined;
44
- readonly body?: unknown;
45
- constructor(message: string, status?: number | undefined, body?: unknown);
46
+ readonly body?: unknown | undefined;
47
+ constructor(message: string, status?: number | undefined, body?: unknown | undefined);
46
48
  }
47
49
  export interface BackendClientOptions {
48
50
  baseUrl: string;
@@ -1,7 +1,7 @@
1
1
  import { type FlowFile } from "./doc-pack.js";
2
2
  export declare class CalibrateError extends Error {
3
- readonly cause?: unknown;
4
- constructor(message: string, cause?: unknown);
3
+ readonly cause?: unknown | undefined;
4
+ constructor(message: string, cause?: unknown | undefined);
5
5
  }
6
6
  /**
7
7
  * Extract a flow-file from a structured flow-guide. Accepts: the YAML of a flow-file directly, or a Markdown
package/dist/calibrate.js CHANGED
@@ -10,6 +10,7 @@
10
10
  // that's the `/docsxai:calibrate` *skill* (see packages/plugin/skills/calibrate/SKILL.md); ambiguity
11
11
  // signalling lives at the MCP/skill layer. This module covers only the part that's deterministic.
12
12
  import { promises as fs } from "node:fs";
13
+ import { FlowName } from "./doc-pack.js";
13
14
  import { FlowFileError, parseFlowFile, serializeFlowFile } from "./flow-file.js";
14
15
  import { initStyleIfAbsent } from "./style.js";
15
16
  import { resolveWorkspacePath, resolveWorkspacePathReal } from "./workspace.js";
@@ -59,6 +60,10 @@ export function extractFlowFile(text, source = "<flow-guide>") {
59
60
  export async function calibrate(opts) {
60
61
  const flow = extractFlowFile(opts.fromText, opts.fromSource ?? "<flow-guide>");
61
62
  const name = opts.flowName ?? flow.name;
63
+ const checked = FlowName.safeParse(name);
64
+ if (!checked.success) {
65
+ throw new CalibrateError(`flow name "${name}" is not usable: ${checked.error.issues.map((i) => i.message).join("; ")}`);
66
+ }
62
67
  await fs.mkdir(resolveWorkspacePath(opts.workspaceDir, "flows"), { recursive: true });
63
68
  // The flow name is guide-supplied — resolve with the symlink-aware variant before writing.
64
69
  const flowFilePath = await resolveWorkspacePathReal(opts.workspaceDir, "flows", `${name}.flow.yaml`);
@@ -8,8 +8,9 @@
8
8
  import { promises as fs } from "node:fs";
9
9
  import * as path from "node:path";
10
10
  import { LocalStorageStateCache, parseAuthStrategyFile } from "./auth.js";
11
- import { FlowFileError, parseFlowFile, resolveFlowExtends } from "./flow-file.js";
12
- import { buildDiagnoseReport, formatReportText, probeLive, } from "./diagnose.js";
11
+ import { expandFlowVariants, FlowFileError, parseFlowFile, resolveFlowExtends, } from "./flow-file.js";
12
+ import { variantDocDir } from "./flow-matrix.js";
13
+ import { buildDiagnoseReport, formatReportText, pickDiagnoseVariant, probeLive, } from "./diagnose.js";
13
14
  import { formatIssuesText, lintFlow } from "./flow-lint.js";
14
15
  import { buildFlowTree, formatTreeText } from "./flow-tree.js";
15
16
  import { formatJargonHitsText, initStyleIfAbsent, loadStyle, scanWorkspaceForJargon, StyleError, writeStyle, } from "./style.js";
@@ -266,6 +267,7 @@ export async function cmdDiagnose(args) {
266
267
  const flowName = typeof flags.get("flow") === "string" ? flags.get("flow") : undefined;
267
268
  const stepId = typeof flags.get("step") === "string" ? flags.get("step") : undefined;
268
269
  const cdpEndpoint = typeof flags.get("cdp") === "string" ? flags.get("cdp") : undefined;
270
+ const variantFlag = typeof flags.get("variant") === "string" ? flags.get("variant") : undefined;
269
271
  const format = typeof flags.get("format") === "string" ? flags.get("format") : "text";
270
272
  if (!flowName) {
271
273
  process.stderr.write(`diagnose: --flow <name> required\n`);
@@ -292,18 +294,34 @@ export async function cmdDiagnose(args) {
292
294
  return parseFlowFile(text, fp);
293
295
  };
294
296
  let flow;
297
+ let variants;
295
298
  try {
296
299
  const parsed = await loadFlowFile(flowName);
297
300
  flow = parsed.extends ? await resolveFlowExtends(parsed, loadFlowFile) : parsed;
301
+ variants = expandFlowVariants(flow);
298
302
  }
299
303
  catch (e) {
300
304
  const msg = e instanceof FlowFileError ? e.message : e.message;
301
305
  process.stderr.write(`diagnose: ${msg}\n`);
302
306
  return 1;
303
307
  }
308
+ // A flow with a `matrix` is diagnosed one variant at a time: its steps and halt shot are the variant's.
309
+ const picked = await pickDiagnoseVariant({
310
+ workspace: projectDir,
311
+ flow: flowName,
312
+ stepId,
313
+ variants,
314
+ requested: variantFlag,
315
+ });
316
+ if ("error" in picked) {
317
+ process.stderr.write(`diagnose: ${picked.error}\n`);
318
+ return 2;
319
+ }
320
+ const variantId = picked.variant.id;
321
+ flow = picked.variant.flow;
304
322
  const step = flow.steps.find((s) => s.id === stepId);
305
323
  if (!step) {
306
- process.stderr.write(`diagnose: no step "${stepId}" in flow "${flowName}" (merged step list: ${flow.steps.map((s) => s.id).join(", ")})\n`);
324
+ process.stderr.write(`diagnose: no step "${stepId}" in flow "${flowName}"${variantId ? ` variant "${variantId}"` : ""} (${variantId ? "variant" : "merged"} step list: ${flow.steps.map((s) => s.id).join(", ")})\n`);
307
325
  return 1;
308
326
  }
309
327
  const resolvedSelector = step.target
@@ -311,7 +329,7 @@ export async function cmdDiagnose(args) {
311
329
  ? (flow.locators[step.target.slice(1)] ?? step.target)
312
330
  : step.target
313
331
  : undefined;
314
- const haltScreenshotAbsPath = resolveWorkspacePath(projectDir, "docs", flowName, "halts", `${stepId}.png`);
332
+ const haltScreenshotAbsPath = resolveWorkspacePath(projectDir, variantDocDir(flowName, variantId), "halts", `${stepId}.png`);
315
333
  // Optional live probe via --cdp.
316
334
  let liveProbe;
317
335
  let liveSession;
@@ -333,6 +351,7 @@ export async function cmdDiagnose(args) {
333
351
  ...(resolvedSelector ? { resolvedSelector } : {}),
334
352
  haltScreenshotAbsPath,
335
353
  ...(liveProbe ? { liveProbe } : {}),
354
+ ...(variantId ? { variant: { id: variantId, all: picked.ids } } : {}),
336
355
  });
337
356
  }
338
357
  catch (e) {
@@ -7,7 +7,7 @@
7
7
  import { promises as fs } from "node:fs";
8
8
  import * as path from "node:path";
9
9
  import { BackendClient, BackendClientError, createBackendClient, oauthLogin, saveBackendTokenFile, } from "./backend-client.js";
10
- import { fetchScreenshotBlobs, readDocPack, uploadScreenshotBlobs, writeDocPack, } from "./doc-pack-io.js";
10
+ import { fetchScreenshotBlobs, readDocPack, UnsafePackNameError, uploadScreenshotBlobs, writeDocPack, } from "./doc-pack-io.js";
11
11
  import { pluginsCli } from "./plugins-cli.js";
12
12
  import { loadWorkspaceConfig, resolveWorkspacePath } from "./workspace.js";
13
13
  import { parseFlags } from "./cli-shared.js";
@@ -198,7 +198,7 @@ export async function cmdPull(args) {
198
198
  return 0;
199
199
  }
200
200
  catch (e) {
201
- if (e instanceof BackendClientError) {
201
+ if (e instanceof BackendClientError || e instanceof UnsafePackNameError) {
202
202
  process.stderr.write(`pull: ${e.message}\n`);
203
203
  return 1;
204
204
  }
@@ -1,4 +1,9 @@
1
1
  export declare function cmdRender(args: string[]): Promise<number>;
2
+ /**
3
+ * `burn` — bake each annotation into a copy of its screenshot, for surfaces that can't run the
4
+ * interactive viewer. The renderer lives in `@docsxai/viewer`; this runs its `burn` command.
5
+ */
6
+ export declare function cmdBurn(args: string[]): Promise<number>;
2
7
  export declare function cmdZip(args: string[]): Promise<number>;
3
8
  export declare function cmdExport(args: string[]): Promise<number>;
4
9
  export declare function cmdBaseline(args: string[]): Promise<number>;
@@ -2,18 +2,18 @@
2
2
  // They read the rendered artifacts (flows/docs/screenshots) and emit something derived; none of
3
3
  // them drive a live browser:
4
4
  // render — build the static viewer by spawning the docsxai-viewer bin
5
+ // burn — bake the annotations into PNG copies by spawning the same bin
5
6
  // zip — deterministic single-archive hand-off bundle
6
7
  // export — project the doc pack to ADF (Confluence) or self-contained Playwright specs
7
8
  // baseline — snapshot the doc pack into .baseline/ as the "before" for diff
8
9
  // diff — drift report against a baseline (the after-vs-before)
9
- import { spawn } from "node:child_process";
10
10
  import { promises as fs } from "node:fs";
11
11
  import * as path from "node:path";
12
12
  import { FlowFileError } from "./flow-file.js";
13
13
  import { diffDocPacks, formatDriftReportMarkdown, formatDriftReportText, severityAtLeast, } from "./diff.js";
14
14
  import { projectDocPackToAdf } from "./export/adf.js";
15
15
  import { exportWorkspaceFlowsAsPlaywrightTests } from "./export/playwright-test.js";
16
- import { formatViewerBinFailure, resolveViewerBin } from "./viewer-bin.js";
16
+ import { runViewerBin } from "./viewer-bin.js";
17
17
  import { ZipError, zipDocPack } from "./zip.js";
18
18
  import { resolveWorkspacePath } from "./workspace.js";
19
19
  import { parseFlags } from "./cli-shared.js";
@@ -27,28 +27,74 @@ export async function cmdRender(args) {
27
27
  }
28
28
  const docsDir = resolveWorkspacePath(projectDir, "docs");
29
29
  const outDir = resolveWorkspacePath(projectDir, ".viewer");
30
- // The viewer is its own package/bin; spawn it so the engine doesn't depend on it at build time.
31
- const viewerBin = await resolveViewerBin();
32
- return new Promise((resolve) => {
33
- const child = spawn(viewerBin.command, [...viewerBin.prefixArgs, "build", docsDir, outDir], {
34
- stdio: "inherit",
35
- });
36
- child.on("error", (e) => {
37
- if (e.code === "ENOENT") {
38
- process.stderr.write(`render: ${formatViewerBinFailure(viewerBin)}\n`);
39
- }
40
- else {
41
- process.stderr.write(`render: ${e.message}\n`);
42
- }
43
- resolve(1);
44
- });
45
- child.on("exit", (code) => {
46
- if ((code ?? 1) === 0) {
47
- process.stdout.write(`render: open ${path.join(outDir, "index.html")} (the index links the flows; each flow page shows the screenshots — hover a pulsing halo to read its callout)\n`);
48
- }
49
- resolve(code ?? 1);
50
- });
51
- });
30
+ const code = await runViewerBin("render", ["build", docsDir, outDir]);
31
+ if (code === 0) {
32
+ process.stdout.write(`render: open ${path.join(outDir, "index.html")} (the index links the flows; each flow page shows the screenshots — hover a pulsing halo to read its callout)\n`);
33
+ }
34
+ return code;
35
+ }
36
+ /** A flow name as `burn` passes it on: no separators, and no leading dot, so it can't name a parent or hidden path. */
37
+ const FLOW_NAME = /^[A-Za-z0-9_-][A-Za-z0-9._-]*$/;
38
+ /** Parse `burn`'s argv. Returns the usage-error message when the argv is malformed. */
39
+ function parseBurnArgs(args) {
40
+ const parsed = { workspace: "", flows: [], plainConnectors: false };
41
+ const positionals = [];
42
+ for (let i = 0; i < args.length; i++) {
43
+ const a = args[i];
44
+ if (a === "--no-connector-outline") {
45
+ parsed.plainConnectors = true;
46
+ }
47
+ else if (a === "--flow" || a === "--out" || a === "--report") {
48
+ const value = args[++i];
49
+ if (value === undefined || value.startsWith("--"))
50
+ return `${a} needs a value`;
51
+ if (a === "--flow")
52
+ parsed.flows.push(value);
53
+ else if (a === "--out")
54
+ parsed.out = value;
55
+ else
56
+ parsed.report = value;
57
+ }
58
+ else if (a.startsWith("--")) {
59
+ return `unknown flag ${a}`;
60
+ }
61
+ else {
62
+ positionals.push(a);
63
+ }
64
+ }
65
+ if (positionals.length === 0)
66
+ return "missing <workspace-dir>";
67
+ if (positionals.length > 1)
68
+ return `unexpected argument "${positionals[1]}"`;
69
+ parsed.workspace = positionals[0];
70
+ const bad = parsed.flows.find((f) => !FLOW_NAME.test(f));
71
+ if (bad !== undefined)
72
+ return `--flow "${bad}" is not a flow name`;
73
+ return parsed;
74
+ }
75
+ /**
76
+ * `burn` — bake each annotation into a copy of its screenshot, for surfaces that can't run the
77
+ * interactive viewer. The renderer lives in `@docsxai/viewer`; this runs its `burn` command.
78
+ */
79
+ export async function cmdBurn(args) {
80
+ const parsed = parseBurnArgs(args);
81
+ if (typeof parsed === "string") {
82
+ process.stderr.write(`burn: ${parsed}\n\n${USAGE}\n`);
83
+ return 2;
84
+ }
85
+ const docsDir = resolveWorkspacePath(parsed.workspace, "docs");
86
+ if (!(await fs.stat(docsDir).then((s) => s.isDirectory(), () => false))) {
87
+ process.stderr.write(`burn: ${parsed.workspace} has no docs/ directory (expected ${docsDir}). Run \`docsxai run\` first.\n`);
88
+ return 1;
89
+ }
90
+ return runViewerBin("burn", [
91
+ "burn",
92
+ parsed.workspace,
93
+ ...parsed.flows.flatMap((f) => ["--flow", f]),
94
+ ...(parsed.out !== undefined ? ["--out", parsed.out] : []),
95
+ ...(parsed.report !== undefined ? ["--report", parsed.report] : []),
96
+ ...(parsed.plainConnectors ? ["--no-connector-outline"] : []),
97
+ ]);
52
98
  }
53
99
  export async function cmdZip(args) {
54
100
  const { positionals, flags } = parseFlags(args);
@@ -0,0 +1,2 @@
1
+ /** `pack` — burn, optimise, hash-name and write the screenshot pack; with `--check`, compare instead of write. */
2
+ export declare function cmdPack(args: string[]): Promise<number>;
@@ -0,0 +1,69 @@
1
+ // Screenshot-pack command — `pack` builds the hash-named, optimised PNG set plus manifest.json a
2
+ // docs site or README consumes, and `pack --check` rebuilds it in memory and compares it with the
3
+ // committed pack. The logic lives in `@docsxai/viewer` (it owns the burner); like `burn`, these
4
+ // validate the argv edge and run the viewer's command through the shared bin resolution, so the
5
+ // engine still does not depend on the viewer.
6
+ import { USAGE } from "./cli-usage.js";
7
+ import { runViewerBin } from "./viewer-bin.js";
8
+ /** Parse argv against a spec. Returns the argv to pass on (flags in the order given) or the usage-error message. */
9
+ function checkArgs(args, spec) {
10
+ const rest = [];
11
+ const positionals = [];
12
+ for (let i = 0; i < args.length; i++) {
13
+ const a = args[i];
14
+ if (spec.bare.includes(a)) {
15
+ rest.push(a);
16
+ }
17
+ else if (spec.valued.includes(a)) {
18
+ const value = args[++i];
19
+ if (value === undefined || value.startsWith("--"))
20
+ return `${a} needs a value`;
21
+ rest.push(a, value);
22
+ }
23
+ else if (a.startsWith("--")) {
24
+ return `unknown flag ${a}`;
25
+ }
26
+ else {
27
+ positionals.push(a);
28
+ }
29
+ }
30
+ if (positionals.length === 0)
31
+ return "missing <workspace-or-raw-dir>";
32
+ if (positionals.length > 1)
33
+ return `unexpected argument "${positionals[1]}"`;
34
+ return { dir: positionals[0], rest };
35
+ }
36
+ function usageError(command, message) {
37
+ process.stderr.write(`${command}: ${message}\n\n${USAGE}\n`);
38
+ return 2;
39
+ }
40
+ /** `pack` — burn, optimise, hash-name and write the screenshot pack; with `--check`, compare instead of write. */
41
+ export async function cmdPack(args) {
42
+ if (args.includes("--check"))
43
+ return cmdPackCheck(args.filter((a) => a !== "--check"));
44
+ const parsed = checkArgs(args, {
45
+ valued: ["--out", "--public-prefix", "--generated-for"],
46
+ bare: ["--from-raw", "--no-optimise"],
47
+ });
48
+ if (typeof parsed === "string")
49
+ return usageError("pack", parsed);
50
+ return runViewerBin("pack", ["pack", parsed.dir, ...parsed.rest]);
51
+ }
52
+ /** `pack --check` — rebuild the pack in memory and compare it with the committed one. `args` has no `--check`. */
53
+ async function cmdPackCheck(args) {
54
+ const label = "pack --check";
55
+ const parsed = checkArgs(args, { valued: ["--against", "--threshold"], bare: ["--from-raw"] });
56
+ if (typeof parsed === "string")
57
+ return usageError(label, parsed);
58
+ const against = parsed.rest.indexOf("--against");
59
+ if (against === -1)
60
+ return usageError(label, "--against <pack-dir> is required");
61
+ const pct = parsed.rest.indexOf("--threshold");
62
+ if (pct !== -1) {
63
+ const value = Number(parsed.rest[pct + 1]);
64
+ if (!Number.isFinite(value) || value < 0) {
65
+ return usageError(label, "--threshold needs a percentage >= 0");
66
+ }
67
+ }
68
+ return runViewerBin(label, ["pack", parsed.dir, "--check", ...parsed.rest]);
69
+ }