@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.
- package/README.md +44 -34
- package/dist/atomic-write.d.ts +19 -0
- package/dist/atomic-write.js +127 -0
- package/dist/auth/api-login.d.ts +9 -51
- package/dist/auth/api-login.js +3 -3
- package/dist/auth/browser-session.js +1 -1
- package/dist/auth/cookie-jar.d.ts +4 -4
- package/dist/auth/cookie-jar.js +4 -4
- package/dist/auth/email-otp.d.ts +11 -147
- package/dist/auth/email-otp.js +4 -4
- package/dist/auth/http-basic.js +1 -1
- package/dist/auth/index.js +3 -3
- package/dist/auth/jwt-injection.d.ts +7 -131
- package/dist/auth/jwt-injection.js +5 -5
- package/dist/auth/manual-capture.d.ts +3 -3
- package/dist/auth/manual-capture.js +2 -2
- package/dist/auth/mtls.d.ts +1 -6
- package/dist/auth/mtls.js +1 -1
- package/dist/auth/pat-header.d.ts +1 -9
- package/dist/auth/pat-header.js +1 -1
- package/dist/auth/storage-state-cache.d.ts +16 -6
- package/dist/auth/storage-state-cache.js +65 -15
- package/dist/auth/test-backdoor.d.ts +2 -13
- package/dist/auth/test-backdoor.js +3 -3
- package/dist/auth/totp.d.ts +1 -1
- package/dist/auth/totp.js +4 -4
- package/dist/auth/types.d.ts +3 -3
- package/dist/auth/types.js +4 -4
- package/dist/auth/ui-form.d.ts +24 -153
- package/dist/auth/ui-form.js +3 -3
- package/dist/auth/webauthn.d.ts +7 -67
- package/dist/auth/webauthn.js +3 -3
- package/dist/auth.js +1 -1
- package/dist/backend-client-contracts.d.ts +1 -1
- package/dist/backend-client-contracts.js +2 -2
- package/dist/backend-client-oauth-login.js +1 -1
- package/dist/backend-client-state-cache.d.ts +2 -2
- package/dist/backend-client-state-cache.js +8 -8
- package/dist/backend-client-token.js +4 -4
- package/dist/backend-client-transport.d.ts +2 -2
- package/dist/backend-client-transport.js +3 -3
- package/dist/backend-client.js +6 -6
- package/dist/browser-build.d.ts +6 -0
- package/dist/browser-build.js +12 -0
- package/dist/browser-launch-error.d.ts +18 -0
- package/dist/browser-launch-error.js +63 -0
- package/dist/browser-wait.d.ts +7 -0
- package/dist/browser-wait.js +12 -0
- package/dist/calibrate.d.ts +6 -2
- package/dist/calibrate.js +20 -13
- package/dist/cli-backend-errors.d.ts +5 -0
- package/dist/cli-backend-errors.js +24 -3
- package/dist/cli-commands-auth.d.ts +1 -0
- package/dist/cli-commands-auth.js +114 -0
- package/dist/cli-commands-authoring.d.ts +0 -1
- package/dist/cli-commands-authoring.js +124 -101
- package/dist/cli-commands-backend.d.ts +1 -1
- package/dist/cli-commands-backend.js +76 -21
- package/dist/cli-commands-docpack.d.ts +3 -1
- package/dist/cli-commands-docpack.js +145 -39
- package/dist/cli-commands-init.d.ts +1 -0
- package/dist/cli-commands-init.js +100 -0
- package/dist/cli-commands-pack.d.ts +1 -1
- package/dist/cli-commands-pack.js +6 -4
- package/dist/cli-commands-session.d.ts +1 -3
- package/dist/cli-commands-session.js +109 -180
- package/dist/cli-commands-site.d.ts +2 -0
- package/dist/cli-commands-site.js +77 -0
- package/dist/cli-commands-style.d.ts +1 -0
- package/dist/cli-commands-style.js +85 -0
- package/dist/cli-flags.d.ts +18 -0
- package/dist/cli-flags.js +77 -0
- package/dist/cli-help.d.ts +30 -0
- package/dist/cli-help.js +174 -0
- package/dist/cli-messages.d.ts +30 -0
- package/dist/cli-messages.js +97 -0
- package/dist/cli-node-guard.d.ts +1 -0
- package/dist/cli-node-guard.js +8 -0
- package/dist/cli-retired.js +6 -0
- package/dist/cli-run-stale.d.ts +2 -0
- package/dist/cli-run-stale.js +13 -0
- package/dist/cli-run-summary.js +7 -3
- package/dist/cli-shared.d.ts +30 -1
- package/dist/cli-shared.js +112 -12
- package/dist/cli-unexpected.d.ts +12 -2
- package/dist/cli-unexpected.js +50 -4
- package/dist/cli-usage.d.ts +1 -1
- package/dist/cli-usage.js +115 -66
- package/dist/cli-value-flags.d.ts +8 -0
- package/dist/cli-value-flags.js +34 -0
- package/dist/cli-version.d.ts +6 -0
- package/dist/cli-version.js +25 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +42 -19
- package/dist/deprecation.d.ts +2 -0
- package/dist/deprecation.js +2 -0
- package/dist/device-scale-factor.d.ts +14 -0
- package/dist/device-scale-factor.js +38 -0
- package/dist/diagnose.js +14 -13
- package/dist/diff-compute.js +22 -8
- package/dist/diff-report.js +3 -3
- package/dist/diff-types.js +1 -1
- package/dist/diff.js +3 -3
- package/dist/doc-pack-io.js +62 -47
- package/dist/doc-pack.d.ts +567 -3487
- package/dist/doc-pack.js +47 -33
- package/dist/doctor-checks-config.d.ts +12 -0
- package/dist/doctor-checks-config.js +229 -0
- package/dist/doctor-checks-plugins.js +2 -2
- package/dist/doctor-checks-site.d.ts +3 -0
- package/dist/doctor-checks-site.js +21 -0
- package/dist/doctor-checks.d.ts +13 -2
- package/dist/doctor-checks.js +94 -79
- package/dist/doctor-next.d.ts +5 -0
- package/dist/doctor-next.js +52 -0
- package/dist/doctor.d.ts +36 -2
- package/dist/doctor.js +88 -29
- package/dist/environment-spec.d.ts +36 -44
- package/dist/environment-spec.js +31 -3
- package/dist/export/adf.d.ts +1 -1
- package/dist/export/adf.js +16 -27
- package/dist/export/playwright-test.d.ts +1 -1
- package/dist/export/playwright-test.js +13 -15
- package/dist/flow-file.d.ts +1 -1
- package/dist/flow-file.js +22 -4
- package/dist/flow-halt.d.ts +1 -1
- package/dist/flow-halt.js +15 -3
- package/dist/flow-lint.d.ts +3 -1
- package/dist/flow-lint.js +39 -26
- package/dist/flow-matrix-lint.js +2 -2
- package/dist/flow-runtime.d.ts +17 -6
- package/dist/flow-runtime.js +48 -17
- package/dist/flow-success.js +4 -4
- package/dist/flow-tree.js +2 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/main-module.d.ts +1 -0
- package/dist/main-module.js +17 -0
- package/dist/matrix-spec.d.ts +33 -106
- package/dist/matrix-spec.js +12 -3
- package/dist/node-floor.d.ts +4 -0
- package/dist/node-floor.js +14 -0
- package/dist/obstacles.js +1 -1
- package/dist/open-in-browser.d.ts +22 -0
- package/dist/open-in-browser.js +37 -0
- package/dist/playwright-driver.d.ts +8 -12
- package/dist/playwright-driver.js +75 -70
- package/dist/playwright-instrumented-browser.d.ts +10 -7
- package/dist/playwright-instrumented-browser.js +35 -12
- package/dist/plugins/load.d.ts +1 -1
- package/dist/plugins/load.js +4 -4
- package/dist/plugins/lock.js +11 -8
- package/dist/plugins/manifest.d.ts +16 -35
- package/dist/plugins/manifest.js +5 -5
- package/dist/plugins/plan.d.ts +3 -3
- package/dist/plugins/plan.js +14 -14
- package/dist/plugins/registry.d.ts +1 -1
- package/dist/plugins/registry.js +1 -1
- package/dist/plugins/runtime.js +3 -3
- package/dist/plugins/types.d.ts +1 -1
- package/dist/plugins-cli.js +36 -28
- package/dist/posix-path.d.ts +2 -0
- package/dist/posix-path.js +7 -0
- package/dist/redact.js +2 -2
- package/dist/run-flows.d.ts +7 -0
- package/dist/run-flows.js +75 -27
- package/dist/style.d.ts +2 -2
- package/dist/style.js +13 -11
- package/dist/verify-determinism.js +2 -1
- package/dist/verify-next-step.d.ts +2 -0
- package/dist/verify-next-step.js +24 -0
- package/dist/verify-report.js +3 -2
- package/dist/viewer-bin.d.ts +9 -3
- package/dist/viewer-bin.js +35 -12
- package/dist/workspace-templates.d.ts +15 -0
- package/dist/workspace-templates.js +88 -0
- package/dist/workspace.d.ts +78 -5
- package/dist/workspace.js +47 -28
- package/dist/zip.d.ts +1 -1
- package/dist/zip.js +23 -6
- package/package.json +6 -6
|
@@ -1,41 +1,62 @@
|
|
|
1
|
-
// Doc-pack ops
|
|
1
|
+
// Doc-pack ops, the commands that package, render, snapshot, and compare the produced doc pack.
|
|
2
2
|
// They read the rendered artifacts (flows/docs/screenshots) and emit something derived; none of
|
|
3
3
|
// them drive a live browser:
|
|
4
|
-
// render
|
|
5
|
-
// burn
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
4
|
+
// render: build the static viewer by spawning the docsxai-viewer bin (--open shows it)
|
|
5
|
+
// burn: bake the annotations into PNG copies by spawning the same bin
|
|
6
|
+
// (`site`, which runs the same bin's docs-site emitter, is in cli-commands-site.ts)
|
|
7
|
+
// zip: deterministic single-archive hand-off bundle
|
|
8
|
+
// export: project the doc pack to ADF (Confluence) or self-contained Playwright specs
|
|
9
|
+
// baseline: snapshot the doc pack into .baseline/ as the "before" for diff
|
|
10
|
+
// diff: drift report against a baseline (the after-vs-before)
|
|
11
|
+
import { randomBytes } from "node:crypto";
|
|
10
12
|
import { promises as fs } from "node:fs";
|
|
11
13
|
import * as path from "node:path";
|
|
12
14
|
import { diffDocPacks, formatDriftReportMarkdown, formatDriftReportText, severityAtLeast, } from "./diff.js";
|
|
13
15
|
import { projectDocPackToAdf } from "./export/adf.js";
|
|
14
16
|
import { exportWorkspaceFlowsAsPlaywrightTests } from "./export/playwright-test.js";
|
|
17
|
+
import { writeFileAtomic } from "./atomic-write.js";
|
|
15
18
|
import { runViewerBin } from "./viewer-bin.js";
|
|
19
|
+
import { openInBrowser } from "./open-in-browser.js";
|
|
16
20
|
import { ZipError, zipDocPack } from "./zip.js";
|
|
17
21
|
import { resolveWorkspacePath } from "./workspace.js";
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
22
|
+
import { bareValueFlagExit, flagMissingValue, workspaceDirProblem } from "./cli-shared.js";
|
|
23
|
+
import { parseCommandFlags } from "./cli-flags.js";
|
|
24
|
+
import { describeFsError, shellQuote, usageError, withNext } from "./cli-messages.js";
|
|
20
25
|
export async function cmdRender(args) {
|
|
21
|
-
const
|
|
26
|
+
const parsed = parseCommandFlags("render", args);
|
|
27
|
+
if (typeof parsed === "number")
|
|
28
|
+
return parsed;
|
|
29
|
+
const { positionals, flags } = parsed;
|
|
22
30
|
const projectDir = positionals[0];
|
|
23
31
|
if (!projectDir)
|
|
24
32
|
return usageError("render", "missing <workspace-dir>");
|
|
33
|
+
const lang = flags.get("lang");
|
|
25
34
|
const docsDir = resolveWorkspacePath(projectDir, "docs");
|
|
26
35
|
const outDir = resolveWorkspacePath(projectDir, ".viewer");
|
|
27
36
|
if (!(await fs.stat(docsDir).then((s) => s.isDirectory(), () => false))) {
|
|
28
|
-
const note = withNext(`warning
|
|
37
|
+
const note = withNext(`warning: ${docsDir} does not exist, so the viewer will be empty`, `docsxai run ${shellQuote(projectDir)}`);
|
|
29
38
|
process.stderr.write(`render: ${note}\n`);
|
|
30
39
|
}
|
|
31
|
-
const code = await runViewerBin("render", [
|
|
32
|
-
|
|
33
|
-
|
|
40
|
+
const code = await runViewerBin("render", [
|
|
41
|
+
"build",
|
|
42
|
+
docsDir,
|
|
43
|
+
outDir,
|
|
44
|
+
...(typeof lang === "string" ? ["--lang", lang] : []),
|
|
45
|
+
]);
|
|
46
|
+
if (code !== 0)
|
|
47
|
+
return code;
|
|
48
|
+
const index = path.join(outDir, "index.html");
|
|
49
|
+
process.stdout.write(`render: open ${index} (the index links the flows; each flow page shows the screenshots, hover a pulsing halo to read its callout)\n`);
|
|
50
|
+
if (flags.get("open") === true) {
|
|
51
|
+
if (await openInBrowser(index))
|
|
52
|
+
process.stdout.write("render: opened it in your browser\n");
|
|
53
|
+
else
|
|
54
|
+
process.stderr.write(`render: couldn't open a browser here, open ${index} yourself\n`);
|
|
34
55
|
}
|
|
35
|
-
return
|
|
56
|
+
return 0;
|
|
36
57
|
}
|
|
37
58
|
/** A flow name as `burn` passes it on: no separators, and no leading dot, so it can't name a parent or hidden path. */
|
|
38
|
-
const FLOW_NAME = /^[A-Za-z0-9_-][A-Za-z0-9._-]*$/;
|
|
59
|
+
export const FLOW_NAME = /^[A-Za-z0-9_-][A-Za-z0-9._-]*$/;
|
|
39
60
|
/** Parse `burn`'s argv. Returns the usage-error message when the argv is malformed. */
|
|
40
61
|
function parseBurnArgs(args) {
|
|
41
62
|
const parsed = { workspace: "", flows: [], plainConnectors: false };
|
|
@@ -45,6 +66,9 @@ function parseBurnArgs(args) {
|
|
|
45
66
|
if (a === "--no-connector-outline") {
|
|
46
67
|
parsed.plainConnectors = true;
|
|
47
68
|
}
|
|
69
|
+
else if (a === "--strict-glyphs") {
|
|
70
|
+
parsed.strictGlyphs = true;
|
|
71
|
+
}
|
|
48
72
|
else if (a === "--flow" || a === "--out" || a === "--report") {
|
|
49
73
|
const value = args[++i];
|
|
50
74
|
if (value === undefined || value.startsWith("--"))
|
|
@@ -74,7 +98,7 @@ function parseBurnArgs(args) {
|
|
|
74
98
|
return parsed;
|
|
75
99
|
}
|
|
76
100
|
/**
|
|
77
|
-
* `burn
|
|
101
|
+
* `burn`: bake each annotation into a copy of its screenshot, for surfaces that can't run the
|
|
78
102
|
* interactive viewer. The renderer lives in `@docsxai/viewer`; this runs its `burn` command.
|
|
79
103
|
*/
|
|
80
104
|
export async function cmdBurn(args) {
|
|
@@ -94,13 +118,20 @@ export async function cmdBurn(args) {
|
|
|
94
118
|
...(parsed.out !== undefined ? ["--out", parsed.out] : []),
|
|
95
119
|
...(parsed.report !== undefined ? ["--report", parsed.report] : []),
|
|
96
120
|
...(parsed.plainConnectors ? ["--no-connector-outline"] : []),
|
|
121
|
+
...(parsed.strictGlyphs ? ["--strict-glyphs"] : []),
|
|
97
122
|
]);
|
|
98
123
|
}
|
|
99
124
|
export async function cmdZip(args) {
|
|
100
|
-
const
|
|
125
|
+
const parsed = parseCommandFlags("zip", args);
|
|
126
|
+
if (typeof parsed === "number")
|
|
127
|
+
return parsed;
|
|
128
|
+
const { positionals, flags } = parsed;
|
|
101
129
|
if (!positionals[0])
|
|
102
130
|
return usageError("zip", "missing <workspace-dir>");
|
|
103
131
|
const projectDir = positionals[0];
|
|
132
|
+
const bareZip = bareValueFlagExit("zip", flags, ["out"]);
|
|
133
|
+
if (bareZip !== undefined)
|
|
134
|
+
return bareZip;
|
|
104
135
|
const output = typeof flags.get("out") === "string"
|
|
105
136
|
? flags.get("out")
|
|
106
137
|
: path.join(process.cwd(), `${path.basename(path.resolve(projectDir))}.zip`);
|
|
@@ -117,13 +148,28 @@ export async function cmdZip(args) {
|
|
|
117
148
|
? `docsxai run ${shellQuote(projectDir)}`
|
|
118
149
|
: /doesn't exist/.test(e.message)
|
|
119
150
|
? `docsxai init ${shellQuote(projectDir)} (or fix the path)`
|
|
120
|
-
:
|
|
151
|
+
: /is a directory/.test(e.message)
|
|
152
|
+
? `docsxai zip ${shellQuote(projectDir)} --out ${shellQuote(path.join(output, `${path.basename(path.resolve(projectDir))}.zip`))}`
|
|
153
|
+
: undefined;
|
|
121
154
|
process.stderr.write(`zip: ${next ? withNext(e.message, next) : e.message}\n`);
|
|
122
155
|
return 1;
|
|
123
156
|
}
|
|
124
|
-
|
|
157
|
+
const fsLine = describeFsError(e);
|
|
158
|
+
if (fsLine === undefined)
|
|
159
|
+
throw e;
|
|
160
|
+
process.stderr.write(`zip: ${fsLine}\n`);
|
|
161
|
+
return 1;
|
|
125
162
|
}
|
|
126
163
|
}
|
|
164
|
+
/** The text after `<label>: ` for an export that failed: the disk's refusal, or the exporter's message once, with the command that helps. */
|
|
165
|
+
function exportFailure(label, e, projectDir) {
|
|
166
|
+
const fsLine = describeFsError(e);
|
|
167
|
+
if (fsLine !== undefined)
|
|
168
|
+
return fsLine;
|
|
169
|
+
const message = e.message.replace(`${label}: `, "");
|
|
170
|
+
const dir = shellQuote(projectDir);
|
|
171
|
+
return withNext(message, /no flow named/.test(message) ? `docsxai flow-tree ${dir}` : `docsxai lint ${dir}`);
|
|
172
|
+
}
|
|
127
173
|
export async function cmdExport(args) {
|
|
128
174
|
const [format, ...rest] = args;
|
|
129
175
|
switch (format) {
|
|
@@ -133,15 +179,21 @@ export async function cmdExport(args) {
|
|
|
133
179
|
return cmdExportPlaywright(rest);
|
|
134
180
|
default:
|
|
135
181
|
return usageError("export", format === undefined
|
|
136
|
-
? "missing format
|
|
137
|
-
: `unknown format "${format}"
|
|
182
|
+
? "missing format (supported: adf, playwright)"
|
|
183
|
+
: `unknown format "${format}" (supported: adf, playwright)`);
|
|
138
184
|
}
|
|
139
185
|
}
|
|
140
186
|
async function cmdExportAdf(rest) {
|
|
141
|
-
const
|
|
187
|
+
const parsed = parseCommandFlags("export adf", rest);
|
|
188
|
+
if (typeof parsed === "number")
|
|
189
|
+
return parsed;
|
|
190
|
+
const { positionals, flags } = parsed;
|
|
142
191
|
if (!positionals[0])
|
|
143
192
|
return usageError("export adf", "missing <workspace-dir>");
|
|
144
193
|
const projectDir = positionals[0];
|
|
194
|
+
const bareAdf = bareValueFlagExit("export adf", flags, ["mode", "flow", "title", "out"]);
|
|
195
|
+
if (bareAdf !== undefined)
|
|
196
|
+
return bareAdf;
|
|
145
197
|
const modeFlag = flags.get("mode");
|
|
146
198
|
let mode = "single";
|
|
147
199
|
if (typeof modeFlag === "string") {
|
|
@@ -152,6 +204,11 @@ async function cmdExportAdf(rest) {
|
|
|
152
204
|
}
|
|
153
205
|
const flow = flags.get("flow");
|
|
154
206
|
const title = flags.get("title");
|
|
207
|
+
const problem = await workspaceDirProblem(projectDir);
|
|
208
|
+
if (problem) {
|
|
209
|
+
process.stderr.write(`export adf: ${problem}\n`);
|
|
210
|
+
return 1;
|
|
211
|
+
}
|
|
155
212
|
try {
|
|
156
213
|
const projection = await projectDocPackToAdf({
|
|
157
214
|
workspaceDir: projectDir,
|
|
@@ -167,29 +224,40 @@ async function cmdExportAdf(rest) {
|
|
|
167
224
|
await fs.mkdir(outDir, { recursive: true });
|
|
168
225
|
const projectionPath = path.join(outDir, "projection.json");
|
|
169
226
|
const attachmentsPath = path.join(outDir, "attachments.json");
|
|
170
|
-
await
|
|
227
|
+
await writeFileAtomic(projectionPath, JSON.stringify(projection, null, 2) + "\n", "utf8");
|
|
171
228
|
const manifest = projection.documents.flatMap((d) => d.attachments.map((a) => ({ section: d.section, ...a })));
|
|
172
|
-
await
|
|
229
|
+
await writeFileAtomic(attachmentsPath, JSON.stringify(manifest, null, 2) + "\n", "utf8");
|
|
173
230
|
process.stdout.write(`export adf: wrote ${projectionPath} (${projection.documents.length} document${projection.documents.length === 1 ? "" : "s"}, mode ${projection.mode}) + ${attachmentsPath} (${manifest.length} attachment${manifest.length === 1 ? "" : "s"})\n`);
|
|
174
231
|
for (const w of projection.warnings)
|
|
175
232
|
process.stderr.write(`export adf: warning: ${w}\n`);
|
|
176
233
|
return 0;
|
|
177
234
|
}
|
|
178
235
|
catch (e) {
|
|
179
|
-
process.stderr.write(`export adf: ${
|
|
236
|
+
process.stderr.write(`export adf: ${exportFailure("export adf", e, projectDir)}\n`);
|
|
180
237
|
return 1;
|
|
181
238
|
}
|
|
182
239
|
}
|
|
183
240
|
async function cmdExportPlaywright(rest) {
|
|
184
|
-
const
|
|
241
|
+
const parsed = parseCommandFlags("export playwright", rest);
|
|
242
|
+
if (typeof parsed === "number")
|
|
243
|
+
return parsed;
|
|
244
|
+
const { positionals, flags } = parsed;
|
|
185
245
|
if (!positionals[0])
|
|
186
246
|
return usageError("export playwright", "missing <workspace-dir>");
|
|
187
247
|
const projectDir = positionals[0];
|
|
248
|
+
const barePlaywright = bareValueFlagExit("export playwright", flags, ["flow", "out"]);
|
|
249
|
+
if (barePlaywright !== undefined)
|
|
250
|
+
return barePlaywright;
|
|
188
251
|
const flow = flags.get("flow");
|
|
189
252
|
const outFlag = flags.get("out");
|
|
190
253
|
const outDir = typeof outFlag === "string"
|
|
191
254
|
? path.resolve(outFlag)
|
|
192
255
|
: resolveWorkspacePath(projectDir, ".export", "tests");
|
|
256
|
+
const problem = await workspaceDirProblem(projectDir);
|
|
257
|
+
if (problem) {
|
|
258
|
+
process.stderr.write(`export playwright: ${problem}\n`);
|
|
259
|
+
return 1;
|
|
260
|
+
}
|
|
193
261
|
try {
|
|
194
262
|
const specs = await exportWorkspaceFlowsAsPlaywrightTests({
|
|
195
263
|
workspaceDir: projectDir,
|
|
@@ -203,7 +271,7 @@ async function cmdExportPlaywright(rest) {
|
|
|
203
271
|
return 0;
|
|
204
272
|
}
|
|
205
273
|
catch (e) {
|
|
206
|
-
process.stderr.write(`export playwright: ${
|
|
274
|
+
process.stderr.write(`export playwright: ${exportFailure("export playwright", e, projectDir)}\n`);
|
|
207
275
|
return 1;
|
|
208
276
|
}
|
|
209
277
|
}
|
|
@@ -220,34 +288,49 @@ async function copyIfExists(src, dest) {
|
|
|
220
288
|
return 1;
|
|
221
289
|
}
|
|
222
290
|
export async function cmdBaseline(args) {
|
|
223
|
-
const
|
|
291
|
+
const parsed = parseCommandFlags("baseline", args);
|
|
292
|
+
if (typeof parsed === "number")
|
|
293
|
+
return parsed;
|
|
294
|
+
const { positionals, flags } = parsed;
|
|
224
295
|
if (!positionals[0])
|
|
225
296
|
return usageError("baseline", "missing <workspace-dir>");
|
|
226
297
|
const projectDir = positionals[0];
|
|
298
|
+
const bare = flagMissingValue(flags, ["out"]);
|
|
299
|
+
if (bare)
|
|
300
|
+
return usageError("baseline", `--${bare} needs a value`);
|
|
227
301
|
const outFlag = flags.get("out");
|
|
228
302
|
const outDir = typeof outFlag === "string"
|
|
229
303
|
? path.resolve(outFlag)
|
|
230
304
|
: resolveWorkspacePath(projectDir, ".baseline");
|
|
305
|
+
if (outDir === path.resolve(projectDir)) {
|
|
306
|
+
return usageError("baseline", "--out cannot be the workspace itself: a refresh clears <out>/flows and <out>/docs first");
|
|
307
|
+
}
|
|
308
|
+
const problem = await workspaceDirProblem(projectDir);
|
|
309
|
+
if (problem) {
|
|
310
|
+
process.stderr.write(`baseline: ${problem}\n`);
|
|
311
|
+
return 1;
|
|
312
|
+
}
|
|
313
|
+
let stage = "";
|
|
231
314
|
try {
|
|
232
315
|
// Refresh = replace: a baseline is a derived snapshot, so the previous one is dropped whole
|
|
233
|
-
// rather than merged (a stale leftover file would read as drift).
|
|
234
|
-
|
|
235
|
-
|
|
316
|
+
// rather than merged (a stale leftover file would read as drift). The new snapshot is built
|
|
317
|
+
// in a staging directory first and swapped in, so a failed copy keeps the previous baseline.
|
|
318
|
+
stage = path.join(outDir, `.staging-${process.pid}-${randomBytes(4).toString("hex")}`);
|
|
236
319
|
let copied = 0;
|
|
237
320
|
const flowsDir = resolveWorkspacePath(projectDir, "flows");
|
|
238
321
|
for (const entry of (await fs.readdir(flowsDir).catch(() => [])).sort()) {
|
|
239
322
|
if (!entry.endsWith(".flow.yaml"))
|
|
240
323
|
continue;
|
|
241
|
-
copied += await copyIfExists(path.join(flowsDir, entry), path.join(
|
|
324
|
+
copied += await copyIfExists(path.join(flowsDir, entry), path.join(stage, "flows", entry));
|
|
242
325
|
}
|
|
243
326
|
const docsDir = resolveWorkspacePath(projectDir, "docs");
|
|
244
|
-
copied += await copyIfExists(path.join(docsDir, "locators.yaml"), path.join(
|
|
327
|
+
copied += await copyIfExists(path.join(docsDir, "locators.yaml"), path.join(stage, "docs", "locators.yaml"));
|
|
245
328
|
const docEntries = await fs.readdir(docsDir, { withFileTypes: true }).catch(() => []);
|
|
246
329
|
for (const entry of docEntries.sort((x, y) => x.name.localeCompare(y.name))) {
|
|
247
330
|
if (!entry.isDirectory())
|
|
248
331
|
continue;
|
|
249
332
|
const flowDir = path.join(docsDir, entry.name);
|
|
250
|
-
const outFlowDir = path.join(
|
|
333
|
+
const outFlowDir = path.join(stage, "docs", entry.name);
|
|
251
334
|
for (const f of (await fs.readdir(flowDir).catch(() => [])).sort()) {
|
|
252
335
|
if (f.endsWith(".md") || f === "annotations.json") {
|
|
253
336
|
copied += await copyIfExists(path.join(flowDir, f), path.join(outFlowDir, f));
|
|
@@ -260,23 +343,44 @@ export async function cmdBaseline(args) {
|
|
|
260
343
|
copied += await copyIfExists(path.join(shotsDir, f), path.join(outFlowDir, "screenshots", f));
|
|
261
344
|
}
|
|
262
345
|
}
|
|
346
|
+
for (const part of ["flows", "docs"]) {
|
|
347
|
+
await fs.rm(path.join(outDir, part), { recursive: true, force: true });
|
|
348
|
+
await fs.rename(path.join(stage, part), path.join(outDir, part)).catch((e) => {
|
|
349
|
+
if (e.code !== "ENOENT")
|
|
350
|
+
throw e;
|
|
351
|
+
});
|
|
352
|
+
}
|
|
263
353
|
process.stdout.write(`baseline: snapshotted ${copied} file${copied === 1 ? "" : "s"} to ${outDir}\n`);
|
|
264
354
|
if (copied === 0) {
|
|
265
|
-
const note = withNext("warning
|
|
355
|
+
const note = withNext("warning: no flows/ or docs/ files found to snapshot", `docsxai run ${shellQuote(projectDir)}`);
|
|
266
356
|
process.stderr.write(`baseline: ${note}\n`);
|
|
267
357
|
}
|
|
268
358
|
return 0;
|
|
269
359
|
}
|
|
270
360
|
catch (e) {
|
|
271
|
-
|
|
361
|
+
// The staging directory is an implementation detail; report the output directory instead.
|
|
362
|
+
const err = e;
|
|
363
|
+
if (stage && err.path?.startsWith(stage))
|
|
364
|
+
err.path = outDir;
|
|
365
|
+
process.stderr.write(`baseline: ${describeFsError(e) ?? e.message}\n`);
|
|
272
366
|
return 1;
|
|
273
367
|
}
|
|
368
|
+
finally {
|
|
369
|
+
if (stage)
|
|
370
|
+
await fs.rm(stage, { recursive: true, force: true }).catch(() => undefined);
|
|
371
|
+
}
|
|
274
372
|
}
|
|
275
373
|
export async function cmdDiff(args) {
|
|
276
|
-
const
|
|
374
|
+
const parsed = parseCommandFlags("diff", args);
|
|
375
|
+
if (typeof parsed === "number")
|
|
376
|
+
return parsed;
|
|
377
|
+
const { positionals, flags } = parsed;
|
|
277
378
|
if (!positionals[0])
|
|
278
379
|
return usageError("diff", "missing <workspace-dir>");
|
|
279
380
|
const projectDir = positionals[0];
|
|
381
|
+
const bare = flagMissingValue(flags, ["against", "format"]);
|
|
382
|
+
if (bare)
|
|
383
|
+
return usageError("diff", `--${bare} needs a value`);
|
|
280
384
|
const againstFlag = flags.get("against");
|
|
281
385
|
const againstDir = typeof againstFlag === "string"
|
|
282
386
|
? path.resolve(againstFlag)
|
|
@@ -302,7 +406,9 @@ export async function cmdDiff(args) {
|
|
|
302
406
|
return 2;
|
|
303
407
|
}
|
|
304
408
|
try {
|
|
305
|
-
|
|
409
|
+
// The report is pasted into pull requests: print the baseline as it was typed, not as an absolute path.
|
|
410
|
+
const shownBaseline = typeof againstFlag === "string" ? againstFlag : path.join(projectDir, ".baseline");
|
|
411
|
+
const report = { ...(await diffDocPacks(againstDir, projectDir)), a: shownBaseline };
|
|
306
412
|
if (format === "json")
|
|
307
413
|
process.stdout.write(JSON.stringify(report, null, 2) + "\n");
|
|
308
414
|
else if (format === "md")
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function cmdInit(args: string[]): Promise<number>;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// `docsxai init`: scaffold a workspace, and with --example write the hello flow for example.com so
|
|
2
|
+
// `run` and `render --open` are all that's left. Split from cli-commands-session.ts.
|
|
3
|
+
import { promises as fs } from "node:fs";
|
|
4
|
+
import * as path from "node:path";
|
|
5
|
+
import { bareValueFlagExit, isHttpUrl } from "./cli-shared.js";
|
|
6
|
+
import { parseCommandFlags } from "./cli-flags.js";
|
|
7
|
+
import { describeFsError, sanitizeForTerminal, shellQuote, usageError, withNext, } from "./cli-messages.js";
|
|
8
|
+
import { initStyleIfAbsent } from "./style.js";
|
|
9
|
+
import { initWorkspace, resolveWorkspacePath } from "./workspace.js";
|
|
10
|
+
import { EXAMPLE_APP_URL, EXAMPLE_FLOW, EXAMPLE_FLOW_PATH } from "./workspace-templates.js";
|
|
11
|
+
/** The flags of `init` that take a value. */
|
|
12
|
+
const INIT_VALUE_FLAGS = [
|
|
13
|
+
"app-url",
|
|
14
|
+
"auth",
|
|
15
|
+
"role",
|
|
16
|
+
"ttl",
|
|
17
|
+
"capture-trigger",
|
|
18
|
+
"auth-cookie",
|
|
19
|
+
"persist",
|
|
20
|
+
];
|
|
21
|
+
/** The `init` flags `--example` rules out: it sets its own app URL and needs no login. */
|
|
22
|
+
const EXAMPLE_EXCLUDES = ["app-url", "auth", "role", "ttl", "capture-trigger", "auth-cookie"];
|
|
23
|
+
/** Write the `init --example` flow and the default style. Returns the paths, relative to `dir`. */
|
|
24
|
+
async function writeExampleFlow(dir) {
|
|
25
|
+
await fs.writeFile(resolveWorkspacePath(dir, EXAMPLE_FLOW_PATH), EXAMPLE_FLOW, "utf8");
|
|
26
|
+
const { created } = await initStyleIfAbsent(dir);
|
|
27
|
+
return [EXAMPLE_FLOW_PATH, ...(created ? ["docs/style.yaml"] : [])];
|
|
28
|
+
}
|
|
29
|
+
export async function cmdInit(args) {
|
|
30
|
+
const parsed = parseCommandFlags("init", args);
|
|
31
|
+
if (typeof parsed === "number")
|
|
32
|
+
return parsed;
|
|
33
|
+
const { positionals, flags } = parsed;
|
|
34
|
+
const persistTmp = flags.get("persist") === "tmp";
|
|
35
|
+
const dir = positionals[0];
|
|
36
|
+
const bareInit = bareValueFlagExit("init", flags, INIT_VALUE_FLAGS);
|
|
37
|
+
if (bareInit !== undefined)
|
|
38
|
+
return bareInit;
|
|
39
|
+
const persist = flags.get("persist");
|
|
40
|
+
if (persist !== undefined && persist !== "tmp") {
|
|
41
|
+
return usageError("init", `--persist must be "tmp" (got "${String(persist)}")`);
|
|
42
|
+
}
|
|
43
|
+
if (!persistTmp && !dir)
|
|
44
|
+
return usageError("init", "missing <workspace-dir> (or use --persist tmp)");
|
|
45
|
+
const example = flags.get("example") === true;
|
|
46
|
+
const clash = example ? EXAMPLE_EXCLUDES.find((k) => flags.has(k)) : undefined;
|
|
47
|
+
if (clash)
|
|
48
|
+
return usageError("init", `--example can't be combined with --${clash}`);
|
|
49
|
+
const str = (k) => typeof flags.get(k) === "string" ? flags.get(k) : undefined;
|
|
50
|
+
const auth = example ? "none" : str("auth");
|
|
51
|
+
if (auth !== undefined && auth !== "manual-capture" && auth !== "none") {
|
|
52
|
+
return usageError("init", `--auth must be manual-capture or none (got "${sanitizeForTerminal(auth)}")`);
|
|
53
|
+
}
|
|
54
|
+
const trigger = str("capture-trigger");
|
|
55
|
+
if (trigger !== undefined && trigger !== "console" && trigger !== "button") {
|
|
56
|
+
return usageError("init", `--capture-trigger must be console or button (got "${sanitizeForTerminal(trigger)}")`);
|
|
57
|
+
}
|
|
58
|
+
const appUrl = example ? EXAMPLE_APP_URL : str("app-url");
|
|
59
|
+
if (appUrl !== undefined && !isHttpUrl(appUrl)) {
|
|
60
|
+
return usageError("init", "--app-url must be an http:// or https:// URL");
|
|
61
|
+
}
|
|
62
|
+
const role = str("role");
|
|
63
|
+
const ttl = str("ttl");
|
|
64
|
+
const authCookie = str("auth-cookie");
|
|
65
|
+
if (dir && (await fs.stat(dir).catch(() => null))?.isFile()) {
|
|
66
|
+
const next = "docsxai init <new-dir> (a workspace is a directory)";
|
|
67
|
+
process.stderr.write(`init: ${withNext(`${path.resolve(dir)} is a file, not a directory`, next)}\n`);
|
|
68
|
+
return 1;
|
|
69
|
+
}
|
|
70
|
+
try {
|
|
71
|
+
const r = await initWorkspace({
|
|
72
|
+
...(dir ? { dir } : {}),
|
|
73
|
+
persistTmp,
|
|
74
|
+
...(appUrl ? { appUrl } : {}),
|
|
75
|
+
...(auth ? { auth } : {}),
|
|
76
|
+
...(role ? { role } : {}),
|
|
77
|
+
...(ttl ? { ttl } : {}),
|
|
78
|
+
...(trigger ? { captureTrigger: trigger } : {}),
|
|
79
|
+
...(authCookie ? { authCookie } : {}),
|
|
80
|
+
ignoreHttpsErrors: flags.get("ignore-https-errors") === true,
|
|
81
|
+
force: flags.get("force") === true,
|
|
82
|
+
});
|
|
83
|
+
if (example)
|
|
84
|
+
r.created.push(...(await writeExampleFlow(r.dir)));
|
|
85
|
+
process.stdout.write(`init: workspace ${r.ephemeral ? "(ephemeral) " : ""}at ${r.dir}\n created: ${r.created.join(", ")}\n`);
|
|
86
|
+
const dirArg = shellQuote(r.dir);
|
|
87
|
+
if (example) {
|
|
88
|
+
process.stdout.write(` next: docsxai run ${dirArg} → docsxai render ${dirArg} --open\n`);
|
|
89
|
+
return 0;
|
|
90
|
+
}
|
|
91
|
+
// An `--auth none` workspace has no auth descriptor, so capture-auth has nothing to run.
|
|
92
|
+
const login = auth === "none" ? "" : `docsxai capture-auth ${dirArg} → `;
|
|
93
|
+
process.stdout.write(` next: ${appUrl ? "" : "(set app_url in .docsxai.json, then) "}${login}docsxai add-flow ${dirArg} --from <flow.yaml> → docsxai run ${dirArg} → docsxai render ${dirArg}\n`);
|
|
94
|
+
return 0;
|
|
95
|
+
}
|
|
96
|
+
catch (e) {
|
|
97
|
+
process.stderr.write(`init: ${describeFsError(e, { creating: true }) ?? e.message.replace(/^init: /, "")}\n`);
|
|
98
|
+
return 1;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/** `pack
|
|
1
|
+
/** `pack`: burn, optimise, hash-name and write the screenshot pack; with `--check`, compare instead of write. */
|
|
2
2
|
export declare function cmdPack(args: string[]): Promise<number>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Screenshot-pack command
|
|
1
|
+
// Screenshot-pack command, `pack` builds the hash-named, optimised PNG set plus manifest.json a
|
|
2
2
|
// docs site or README consumes, and `pack --check` rebuilds it in memory and compares it with the
|
|
3
3
|
// committed pack. The logic lives in `@docsxai/viewer` (it owns the burner); like `burn`, these
|
|
4
4
|
// validate the argv edge and run the viewer's command through the shared bin resolution, so the
|
|
@@ -33,7 +33,7 @@ function checkArgs(args, spec) {
|
|
|
33
33
|
return `unexpected argument "${positionals[1]}"`;
|
|
34
34
|
return { dir: positionals[0], rest };
|
|
35
35
|
}
|
|
36
|
-
/** `pack
|
|
36
|
+
/** `pack`: burn, optimise, hash-name and write the screenshot pack; with `--check`, compare instead of write. */
|
|
37
37
|
export async function cmdPack(args) {
|
|
38
38
|
if (args.includes("--check"))
|
|
39
39
|
return cmdPackCheck(args.filter((a) => a !== "--check"));
|
|
@@ -45,7 +45,7 @@ export async function cmdPack(args) {
|
|
|
45
45
|
return usageError("pack", parsed);
|
|
46
46
|
return runViewerBin("pack", ["pack", parsed.dir, ...parsed.rest]);
|
|
47
47
|
}
|
|
48
|
-
/** `pack --check
|
|
48
|
+
/** `pack --check`: rebuild the pack in memory and compare it with the committed one. `args` has no `--check`. */
|
|
49
49
|
async function cmdPackCheck(args) {
|
|
50
50
|
const label = "pack --check";
|
|
51
51
|
const parsed = checkArgs(args, { valued: ["--against", "--threshold"], bare: ["--from-raw"] });
|
|
@@ -56,7 +56,9 @@ async function cmdPackCheck(args) {
|
|
|
56
56
|
return usageError(label, "--against <pack-dir> is required");
|
|
57
57
|
const pct = parsed.rest.indexOf("--threshold");
|
|
58
58
|
if (pct !== -1) {
|
|
59
|
-
const
|
|
59
|
+
const raw = parsed.rest[pct + 1] ?? "";
|
|
60
|
+
// `Number("")` is 0: an empty value would read as a threshold of zero.
|
|
61
|
+
const value = raw.trim() === "" ? Number.NaN : Number(raw);
|
|
60
62
|
if (!Number.isFinite(value) || value < 0) {
|
|
61
63
|
return usageError(label, "--threshold needs a percentage >= 0");
|
|
62
64
|
}
|
|
@@ -1,4 +1,2 @@
|
|
|
1
1
|
export declare function cmdRun(args: string[]): Promise<number>;
|
|
2
|
-
export declare function
|
|
3
|
-
export declare function cmdInit(args: string[]): Promise<number>;
|
|
4
|
-
export declare function cmdCalibrate(args: string[]): Promise<number>;
|
|
2
|
+
export declare function cmdAddFlow(args: string[]): Promise<number>;
|