@docsxai/engine 0.2.1-rc.1 → 0.3.0-rc.2
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 +18 -5
- package/dist/address-class.d.ts +14 -0
- package/dist/address-class.js +151 -0
- package/dist/auth/api-login.d.ts +3 -3
- package/dist/auth/email-otp.d.ts +60 -60
- package/dist/auth/jwt-injection.d.ts +45 -45
- package/dist/auth/pat-header.d.ts +2 -2
- package/dist/auth/types.d.ts +2 -2
- package/dist/auth/ui-form.d.ts +54 -54
- package/dist/auth/webauthn.d.ts +22 -22
- package/dist/backend-client-contracts.d.ts +4 -2
- package/dist/backend-client-token.js +2 -1
- package/dist/calibrate.d.ts +2 -2
- package/dist/calibrate.js +5 -0
- package/dist/cli-backend-errors.d.ts +7 -0
- package/dist/cli-backend-errors.js +65 -0
- package/dist/cli-commands-authoring.js +57 -51
- package/dist/cli-commands-backend.js +49 -42
- package/dist/cli-commands-docpack.d.ts +5 -0
- package/dist/cli-commands-docpack.js +106 -66
- package/dist/cli-commands-pack.d.ts +2 -0
- package/dist/cli-commands-pack.js +65 -0
- package/dist/cli-commands-session.js +120 -125
- package/dist/cli-messages.d.ts +17 -0
- package/dist/cli-messages.js +80 -0
- package/dist/cli-retired.d.ts +6 -0
- package/dist/cli-retired.js +12 -0
- package/dist/cli-run-summary.d.ts +15 -0
- package/dist/cli-run-summary.js +33 -0
- package/dist/cli-usage.d.ts +1 -1
- package/dist/cli-usage.js +78 -5
- package/dist/cli-verify.d.ts +14 -0
- package/dist/cli-verify.js +54 -0
- package/dist/cli.js +15 -2
- package/dist/deprecation.d.ts +19 -0
- package/dist/deprecation.js +32 -0
- package/dist/diagnose.d.ts +25 -0
- package/dist/diagnose.js +69 -3
- package/dist/diff-compute.js +1 -0
- package/dist/doc-pack-io.d.ts +14 -0
- package/dist/doc-pack-io.js +121 -14
- package/dist/doc-pack.d.ts +2282 -387
- package/dist/doc-pack.js +135 -43
- package/dist/doctor-checks-plugins.js +4 -3
- package/dist/doctor-checks.d.ts +1 -1
- package/dist/doctor-checks.js +31 -6
- package/dist/doctor.d.ts +2 -0
- package/dist/doctor.js +27 -3
- package/dist/driver-budget.d.ts +6 -0
- package/dist/driver-budget.js +15 -0
- package/dist/egress-guard.d.ts +58 -0
- package/dist/egress-guard.js +136 -0
- package/dist/environment-spec.d.ts +67 -0
- package/dist/environment-spec.js +38 -0
- package/dist/export/playwright-test.js +42 -10
- package/dist/flow-file.d.ts +9 -3
- package/dist/flow-file.js +21 -1
- package/dist/flow-halt.d.ts +16 -0
- package/dist/flow-halt.js +76 -0
- package/dist/flow-hidden.d.ts +9 -0
- package/dist/flow-hidden.js +20 -0
- package/dist/flow-lint.js +91 -1
- package/dist/flow-matrix-lint.d.ts +10 -0
- package/dist/flow-matrix-lint.js +40 -0
- package/dist/flow-matrix.d.ts +44 -0
- package/dist/flow-matrix.js +238 -0
- package/dist/flow-name-rules.d.ts +15 -0
- package/dist/flow-name-rules.js +39 -0
- package/dist/flow-runtime.d.ts +52 -22
- package/dist/flow-runtime.js +63 -117
- package/dist/flow-success.d.ts +3 -0
- package/dist/flow-success.js +37 -0
- package/dist/flow-tree.d.ts +2 -0
- package/dist/flow-tree.js +17 -5
- package/dist/flow-wait.d.ts +3 -0
- package/dist/flow-wait.js +22 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/matrix-spec.d.ts +145 -0
- package/dist/matrix-spec.js +120 -0
- package/dist/page-hide.d.ts +10 -0
- package/dist/page-hide.js +45 -0
- package/dist/page-settle.d.ts +39 -0
- package/dist/page-settle.js +142 -0
- package/dist/playwright-driver.d.ts +28 -8
- package/dist/playwright-driver.js +73 -28
- package/dist/plugins/manifest.d.ts +9 -9
- package/dist/run-flows.d.ts +40 -0
- package/dist/run-flows.js +129 -0
- package/dist/style.d.ts +2 -2
- package/dist/upload-path.d.ts +15 -0
- package/dist/upload-path.js +63 -0
- package/dist/verify-compare.d.ts +43 -0
- package/dist/verify-compare.js +237 -0
- package/dist/verify-determinism.d.ts +16 -0
- package/dist/verify-determinism.js +88 -0
- package/dist/verify-report.d.ts +53 -0
- package/dist/verify-report.js +141 -0
- package/dist/verify-tree.d.ts +27 -0
- package/dist/verify-tree.js +95 -0
- package/dist/viewer-bin.d.ts +6 -0
- package/dist/viewer-bin.js +24 -0
- package/dist/zip.d.ts +2 -2
- package/package.json +3 -2
package/dist/doc-pack-io.js
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
import { createHash } from "node:crypto";
|
|
8
8
|
import { promises as fs } from "node:fs";
|
|
9
9
|
import * as path from "node:path";
|
|
10
|
+
import { FlowName } from "./doc-pack.js";
|
|
11
|
+
import { findCaseCollision, hasTrailingDot, isWindowsDeviceName } from "./flow-name-rules.js";
|
|
10
12
|
import { resolveWorkspacePath, resolveWorkspacePathReal } from "./workspace.js";
|
|
11
13
|
/** Read the workspace's doc pack from disk into the per-artifact payload shape the backend accepts. */
|
|
12
14
|
export async function readDocPack(workspace) {
|
|
@@ -32,19 +34,36 @@ async function readFlows(workspace) {
|
|
|
32
34
|
}
|
|
33
35
|
return { schema: "docsxai/flows@1", files };
|
|
34
36
|
}
|
|
35
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Directories under `docs/` that can hold a flow's outputs, relative to it: `<flow>`, then each
|
|
39
|
+
* `<flow>/<variant>` (a flow with a `matrix` writes there). A directory without outputs is harmless.
|
|
40
|
+
*/
|
|
41
|
+
async function outputDirs(workspace) {
|
|
36
42
|
const docsDir = resolveWorkspacePath(workspace, "docs");
|
|
37
43
|
const flows = await fs.readdir(docsDir, { withFileTypes: true }).catch(() => []);
|
|
38
|
-
const
|
|
44
|
+
const dirs = [];
|
|
39
45
|
for (const ent of flows) {
|
|
40
46
|
if (!ent.isDirectory())
|
|
41
47
|
continue;
|
|
42
|
-
|
|
48
|
+
dirs.push(ent.name);
|
|
49
|
+
const subs = await fs
|
|
50
|
+
.readdir(resolveWorkspacePath(workspace, "docs", ent.name), { withFileTypes: true })
|
|
51
|
+
.catch(() => []);
|
|
52
|
+
for (const sub of subs)
|
|
53
|
+
if (sub.isDirectory())
|
|
54
|
+
dirs.push(`${ent.name}/${sub.name}`);
|
|
55
|
+
}
|
|
56
|
+
return dirs;
|
|
57
|
+
}
|
|
58
|
+
async function readAnnotations(workspace) {
|
|
59
|
+
const files = {};
|
|
60
|
+
for (const dir of await outputDirs(workspace)) {
|
|
61
|
+
const annPath = resolveWorkspacePath(workspace, "docs", dir, "annotations.json");
|
|
43
62
|
const text = await fs.readFile(annPath, "utf8").catch(() => null);
|
|
44
63
|
if (text === null)
|
|
45
64
|
continue;
|
|
46
65
|
try {
|
|
47
|
-
files[`${
|
|
66
|
+
files[`${dir}/annotations.json`] = JSON.parse(text);
|
|
48
67
|
}
|
|
49
68
|
catch {
|
|
50
69
|
// skip unparseable files (push surfaces them in lint output, not here)
|
|
@@ -55,21 +74,17 @@ async function readAnnotations(workspace) {
|
|
|
55
74
|
return { schema: "docsxai/annotations-bundle@1", files };
|
|
56
75
|
}
|
|
57
76
|
async function readScreenshots(workspace) {
|
|
58
|
-
const docsDir = resolveWorkspacePath(workspace, "docs");
|
|
59
|
-
const flows = await fs.readdir(docsDir, { withFileTypes: true }).catch(() => []);
|
|
60
77
|
const files = {};
|
|
61
|
-
for (const
|
|
62
|
-
|
|
63
|
-
continue;
|
|
64
|
-
const screenDir = resolveWorkspacePath(workspace, "docs", ent.name, "screenshots");
|
|
78
|
+
for (const dir of await outputDirs(workspace)) {
|
|
79
|
+
const screenDir = resolveWorkspacePath(workspace, "docs", dir, "screenshots");
|
|
65
80
|
const shots = await fs.readdir(screenDir).catch(() => null);
|
|
66
81
|
if (!shots)
|
|
67
82
|
continue;
|
|
68
83
|
for (const f of shots) {
|
|
69
84
|
if (!/\.(png|jpg|jpeg|webp)$/i.test(f))
|
|
70
85
|
continue;
|
|
71
|
-
const buf = await fs.readFile(resolveWorkspacePath(workspace, "docs",
|
|
72
|
-
files[`${
|
|
86
|
+
const buf = await fs.readFile(resolveWorkspacePath(workspace, "docs", dir, "screenshots", f));
|
|
87
|
+
files[`${dir}/screenshots/${f}`] = {
|
|
73
88
|
sha256: createHash("sha256").update(buf).digest("hex"),
|
|
74
89
|
bytes: buf.byteLength,
|
|
75
90
|
};
|
|
@@ -128,10 +143,102 @@ async function readLocators(workspace) {
|
|
|
128
143
|
return { schema: "docsxai/locators@1", yaml };
|
|
129
144
|
}
|
|
130
145
|
// --- write back (pull) ------------------------------------------------------
|
|
146
|
+
/** A pulled payload named a file the workspace would not have produced; nothing was written. */
|
|
147
|
+
export class UnsafePackNameError extends Error {
|
|
148
|
+
constructor(message) {
|
|
149
|
+
super(message);
|
|
150
|
+
this.name = "UnsafePackNameError";
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
const FLOW_FILE_SUFFIX = ".flow.yaml";
|
|
154
|
+
const SAFE_SEGMENT = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
155
|
+
const SCREENSHOT_FILE = /^[A-Za-z0-9][A-Za-z0-9._-]*\.(?:png|jpe?g|webp)$/i;
|
|
156
|
+
const isFlowName = (name) => FlowName.safeParse(name).success;
|
|
157
|
+
/** Names a variant directory cannot take: they are what the flow directory holds already. */
|
|
158
|
+
const RESERVED_SEGMENTS = new Set(["annotations.json", "screenshots"]);
|
|
159
|
+
/**
|
|
160
|
+
* A path segment or file name a workspace can hold on every disk: safe characters, no `..`, no
|
|
161
|
+
* trailing dot and not a Windows device name (`con`, `nul`, `com1`, ..., with or without an extension).
|
|
162
|
+
*/
|
|
163
|
+
const isSafeSegment = (seg) => seg.length <= 128 &&
|
|
164
|
+
!RESERVED_SEGMENTS.has(seg.toLowerCase()) &&
|
|
165
|
+
SAFE_SEGMENT.test(seg) &&
|
|
166
|
+
!seg.includes("..") &&
|
|
167
|
+
!hasTrailingDot(seg) &&
|
|
168
|
+
!isWindowsDeviceName(seg);
|
|
169
|
+
/** `<stem>.png|jpg|jpeg|webp` with the stem held to the same rules as a segment. */
|
|
170
|
+
const isScreenshotFile = (file) => SCREENSHOT_FILE.test(file) && isSafeSegment(file) && isSafeSegment(file.replace(/\.[^.]+$/, ""));
|
|
171
|
+
/** `<flow>[/<variant>]`, every segment safe, the flow segment a valid flow name. */
|
|
172
|
+
function isOutputDir(segments) {
|
|
173
|
+
const [flow, ...variants] = segments;
|
|
174
|
+
return (flow !== undefined && isFlowName(flow) && variants.length <= 1 && variants.every(isSafeSegment));
|
|
175
|
+
}
|
|
176
|
+
/** `flows/<name>.flow.yaml`: the file name is `<valid flow name>.flow.yaml`. */
|
|
177
|
+
function isFlowFileName(file) {
|
|
178
|
+
return file.endsWith(FLOW_FILE_SUFFIX) && isFlowName(file.slice(0, -FLOW_FILE_SUFFIX.length));
|
|
179
|
+
}
|
|
180
|
+
/** `docs/<flow>[/<variant>]/annotations.json`, relative to `docs/`. */
|
|
181
|
+
function isAnnotationsPath(rel) {
|
|
182
|
+
const segments = rel.split("/");
|
|
183
|
+
return segments.pop() === "annotations.json" && isOutputDir(segments);
|
|
184
|
+
}
|
|
185
|
+
/** `docs/<flow>[/<variant>]/screenshots/<file>`, relative to `docs/`. */
|
|
186
|
+
function isScreenshotPath(rel) {
|
|
187
|
+
const segments = rel.split("/");
|
|
188
|
+
const file = segments.pop() ?? "";
|
|
189
|
+
return isScreenshotFile(file) && segments.pop() === "screenshots" && isOutputDir(segments);
|
|
190
|
+
}
|
|
191
|
+
function describeName(name) {
|
|
192
|
+
const shown = name.length > 80 ? `${name.slice(0, 80)}...` : name;
|
|
193
|
+
return JSON.stringify(shown);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Throws {@link UnsafePackNameError} on the first file name in `payloads` that is not one a
|
|
197
|
+
* workspace produces: a flow file that is not `<flow name>.flow.yaml`, an annotations file that is
|
|
198
|
+
* not `<flow>[/<variant>]/annotations.json`, a screenshot that is not under a `screenshots/`
|
|
199
|
+
* directory of such a path, a variant segment or screenshot stem that is a Windows device name or
|
|
200
|
+
* ends in a dot, or two flow files, annotation paths, screenshot paths or output directories that
|
|
201
|
+
* differ only by case. The backend is not trusted
|
|
202
|
+
* with names, and a name like `../.docsxai.json` would otherwise land on workspace config.
|
|
203
|
+
*/
|
|
204
|
+
export function assertSafePackNames(payloads) {
|
|
205
|
+
const checks = [
|
|
206
|
+
["flows", Object.keys(payloads.flows?.files ?? {}), isFlowFileName],
|
|
207
|
+
["annotations", Object.keys(payloads.annotations?.files ?? {}), isAnnotationsPath],
|
|
208
|
+
["screenshots", Object.keys(payloads.screenshots?.files ?? {}), isScreenshotPath],
|
|
209
|
+
];
|
|
210
|
+
for (const [artifact, names, ok] of checks) {
|
|
211
|
+
const bad = names.find((n) => !ok(n));
|
|
212
|
+
if (bad !== undefined) {
|
|
213
|
+
throw new UnsafePackNameError(`refusing the pulled doc pack, nothing written: ${artifact} file name ${describeName(bad)} is not a valid ${artifact} path`);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
const annotationNames = Object.keys(payloads.annotations?.files ?? {});
|
|
217
|
+
const screenshotNames = Object.keys(payloads.screenshots?.files ?? {});
|
|
218
|
+
// Directories are compared across annotations and screenshots: `Tour/` and `tour/` are one
|
|
219
|
+
// directory on a case-insensitive disk, whichever artifact names them.
|
|
220
|
+
const outputDirs = [
|
|
221
|
+
...annotationNames.map((n) => n.split("/").slice(0, -1).join("/")),
|
|
222
|
+
...screenshotNames.map((n) => n.split("/").slice(0, -2).join("/")),
|
|
223
|
+
];
|
|
224
|
+
const collisions = [
|
|
225
|
+
["flows", Object.keys(payloads.flows?.files ?? {})],
|
|
226
|
+
["annotations", annotationNames],
|
|
227
|
+
["screenshots", screenshotNames],
|
|
228
|
+
["output directories", outputDirs],
|
|
229
|
+
];
|
|
230
|
+
for (const [artifact, names] of collisions) {
|
|
231
|
+
const clash = findCaseCollision(names);
|
|
232
|
+
if (clash) {
|
|
233
|
+
throw new UnsafePackNameError(`refusing the pulled doc pack, nothing written: ${artifact} ${describeName(clash[0])} and ${describeName(clash[1])} differ only by case`);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
131
237
|
export async function writeDocPack(workspace, payloads, extras = {}) {
|
|
132
238
|
let n = 0;
|
|
133
|
-
// Pulled payload file names come from the backend
|
|
134
|
-
// symlink-aware variant
|
|
239
|
+
// Pulled payload file names come from the backend: check every one before the first write, then
|
|
240
|
+
// resolve with the symlink-aware variant.
|
|
241
|
+
assertSafePackNames(payloads);
|
|
135
242
|
if (payloads.flows) {
|
|
136
243
|
await fs.mkdir(resolveWorkspacePath(workspace, "flows"), { recursive: true });
|
|
137
244
|
for (const [f, text] of Object.entries(payloads.flows.files)) {
|