@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
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { ArtefactDifference } from "./verify-compare.js";
|
|
2
|
+
export type VerifyStatus = "identical" | "differing" | "halted";
|
|
3
|
+
/**
|
|
4
|
+
* What a halt message becomes in the report: its first line, with every absolute path (POSIX,
|
|
5
|
+
* Windows drive, UNC, `file://`) replaced by `<path>`. A path under `/tmp`, `/Users`, `/home` or one
|
|
6
|
+
* of `roots` (the workspace root, the home and temp directories of the machine) is scrubbed to the
|
|
7
|
+
* end of its token run first. A run on one machine and a run on another then print the same
|
|
8
|
+
* report, and a CI log does not carry a home directory.
|
|
9
|
+
*/
|
|
10
|
+
export declare function scrubHaltMessage(message: string, roots?: readonly string[]): string;
|
|
11
|
+
/** A flow that did not finish in one of the runs. */
|
|
12
|
+
export interface VerifyHalt {
|
|
13
|
+
run: number;
|
|
14
|
+
flow: string;
|
|
15
|
+
/** The step the runtime halted on; null when the flow never started (browser launch failure). */
|
|
16
|
+
step: string | null;
|
|
17
|
+
message: string;
|
|
18
|
+
}
|
|
19
|
+
export interface VerifyReport {
|
|
20
|
+
schema: "docsxai/verify-determinism@1";
|
|
21
|
+
runs: number;
|
|
22
|
+
/** Names of the flows that ran, sorted. */
|
|
23
|
+
flows: string[];
|
|
24
|
+
/**
|
|
25
|
+
* `identical`: every run wrote the same bytes and finished. `differing`: at least one artefact
|
|
26
|
+
* differs between runs. `halted`: a flow halted in some run, so there is nothing to verify as a doc pack.
|
|
27
|
+
*/
|
|
28
|
+
status: VerifyStatus;
|
|
29
|
+
/** Artefacts in run 1. */
|
|
30
|
+
artefacts_compared: number;
|
|
31
|
+
/** The first differing artefact by path, run order breaking ties. */
|
|
32
|
+
first: ArtefactDifference | null;
|
|
33
|
+
/** Every differing artefact, ordered by path then run. */
|
|
34
|
+
differences: ArtefactDifference[];
|
|
35
|
+
halts: VerifyHalt[];
|
|
36
|
+
/** True when run 1's output replaced the workspace output (only when status is `identical`). */
|
|
37
|
+
promoted: boolean;
|
|
38
|
+
}
|
|
39
|
+
/** Exit code for a finished verification: 0 identical, 1 differing or halted. Usage errors (2) never reach a report. */
|
|
40
|
+
export declare function verifyExitCode(report: VerifyReport): 0 | 1;
|
|
41
|
+
export declare function buildVerifyReport(input: {
|
|
42
|
+
runs: number;
|
|
43
|
+
flows: string[];
|
|
44
|
+
artefactsCompared: number;
|
|
45
|
+
differences: ArtefactDifference[];
|
|
46
|
+
halts: VerifyHalt[];
|
|
47
|
+
promoted: boolean;
|
|
48
|
+
/** Directories whose paths are scrubbed from halt messages: the workspace root, home, temp. */
|
|
49
|
+
scrubRoots?: readonly string[];
|
|
50
|
+
}): VerifyReport;
|
|
51
|
+
export declare function formatVerifyReportText(r: VerifyReport): string;
|
|
52
|
+
export declare function formatVerifyReportMarkdown(r: VerifyReport): string;
|
|
53
|
+
export declare function formatVerifyReportJson(r: VerifyReport): string;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// The `run --verify-determinism` report: the shape, its three renderings (json, md, text) and the
|
|
2
|
+
// exit code it maps to. No timestamps, no absolute paths, no durations: the same runs always
|
|
3
|
+
// render the same bytes, so the report can be diffed, cached and attached to a pipeline. Halt
|
|
4
|
+
// messages are cut to their first line and scrubbed of absolute paths (`scrubHaltMessage`); every
|
|
5
|
+
// other path in the report is relative to a run root.
|
|
6
|
+
// Each pattern finds one kind of absolute path. A POSIX path needs two segments and must not follow a
|
|
7
|
+
// word character, `:`, `/` or `.`, so URLs (`http://host/a/b`), `a/b` and a lone `/done` stay.
|
|
8
|
+
const ABSOLUTE_PATH_PATTERNS = [
|
|
9
|
+
/file:\/\/[^\s"'`<>()[\]{}]*/g,
|
|
10
|
+
/(?<![\w:/.~-])(?:\/[^\s"'`<>()[\]{}/]+){2,}/g,
|
|
11
|
+
/(?<!\w)[A-Za-z]:[\\/][^\s"'`<>()[\]{}]*/g,
|
|
12
|
+
/\\\\[^\s\\"'`<>]+\\[^\s"'`<>()[\]{}]*/g,
|
|
13
|
+
];
|
|
14
|
+
// Roots that identify a machine or a user. A path under one is scrubbed whole, even a single
|
|
15
|
+
// segment (`/tmp`) and even one with a space in a directory name.
|
|
16
|
+
const FIXED_ROOTS = ["/tmp", "/var/tmp", "/private/tmp", "/Users", "/home"];
|
|
17
|
+
const PATH_CHAR = "[^\\s\"'`<>()[\\]{}]";
|
|
18
|
+
const TRAIL_PUNCTUATION = /[.,;:!?]+$/;
|
|
19
|
+
function escapeRegExp(text) {
|
|
20
|
+
return text.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&");
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* One pattern for a path under any of `roots`. Inside quotes or brackets the run goes to the
|
|
24
|
+
* closing delimiter, spaces included. Outside them it goes to the next space, and across a space
|
|
25
|
+
* when the next word holds a separator (`/Users/me/My Projects/app`) or starts with a capital or
|
|
26
|
+
* digit and does not follow sentence punctuation (`/Users/me/My Projects`, where nothing after the
|
|
27
|
+
* space tells the directory name from prose). A lowercase last word is left.
|
|
28
|
+
*/
|
|
29
|
+
function rootedPathPattern(roots) {
|
|
30
|
+
const alt = roots
|
|
31
|
+
.map(escapeRegExp)
|
|
32
|
+
.sort((a, b) => b.length - a.length || (a < b ? -1 : 1))
|
|
33
|
+
.join("|");
|
|
34
|
+
const inside = `(?<=["'\`(\\[<])(?:${alt})(?:[\\\\/][^"'\`<>()\\[\\]{}\\n]*|(?![\\w-]))`;
|
|
35
|
+
const outside = `(?<![\\w:/.~-])(?:${alt})(?:[\\\\/]${PATH_CHAR}*(?: +(?:(?=${PATH_CHAR}*[\\\\/])|(?<![.,;:!?] )(?=[A-Z0-9]))${PATH_CHAR}+)*|(?![\\w-]))`;
|
|
36
|
+
return new RegExp(`${inside}|${outside}`, "g");
|
|
37
|
+
}
|
|
38
|
+
function replacePath(match) {
|
|
39
|
+
return `<path>${TRAIL_PUNCTUATION.exec(match)?.[0] ?? ""}`;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* What a halt message becomes in the report: its first line, with every absolute path (POSIX,
|
|
43
|
+
* Windows drive, UNC, `file://`) replaced by `<path>`. A path under `/tmp`, `/Users`, `/home` or one
|
|
44
|
+
* of `roots` (the workspace root, the home and temp directories of the machine) is scrubbed to the
|
|
45
|
+
* end of its token run first. A run on one machine and a run on another then print the same
|
|
46
|
+
* report, and a CI log does not carry a home directory.
|
|
47
|
+
*/
|
|
48
|
+
export function scrubHaltMessage(message, roots = []) {
|
|
49
|
+
const known = new Set(FIXED_ROOTS);
|
|
50
|
+
for (const root of roots) {
|
|
51
|
+
const trimmed = root.replace(/[\\/]+$/, "");
|
|
52
|
+
if (trimmed.length > 1)
|
|
53
|
+
known.add(trimmed);
|
|
54
|
+
}
|
|
55
|
+
let line = (message.split("\n")[0] ?? "").replace(rootedPathPattern([...known]), replacePath);
|
|
56
|
+
for (const pattern of ABSOLUTE_PATH_PATTERNS)
|
|
57
|
+
line = line.replace(pattern, replacePath);
|
|
58
|
+
return line;
|
|
59
|
+
}
|
|
60
|
+
/** Exit code for a finished verification: 0 identical, 1 differing or halted. Usage errors (2) never reach a report. */
|
|
61
|
+
export function verifyExitCode(report) {
|
|
62
|
+
return report.status === "identical" ? 0 : 1;
|
|
63
|
+
}
|
|
64
|
+
export function buildVerifyReport(input) {
|
|
65
|
+
const status = input.halts.length > 0 ? "halted" : input.differences.length > 0 ? "differing" : "identical";
|
|
66
|
+
return {
|
|
67
|
+
schema: "docsxai/verify-determinism@1",
|
|
68
|
+
runs: input.runs,
|
|
69
|
+
flows: [...input.flows].sort((a, b) => (a < b ? -1 : a > b ? 1 : 0)),
|
|
70
|
+
status,
|
|
71
|
+
artefacts_compared: input.artefactsCompared,
|
|
72
|
+
first: input.differences[0] ?? null,
|
|
73
|
+
differences: input.differences,
|
|
74
|
+
halts: input.halts.map((h) => ({
|
|
75
|
+
...h,
|
|
76
|
+
message: scrubHaltMessage(h.message, input.scrubRoots),
|
|
77
|
+
})),
|
|
78
|
+
promoted: input.promoted,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function headline(r) {
|
|
82
|
+
const n = r.flows.length;
|
|
83
|
+
return `${r.runs} runs of ${n} flow${n === 1 ? "" : "s"} (${r.flows.join(", ")}), ${r.artefacts_compared} artefact${r.artefacts_compared === 1 ? "" : "s"} per run`;
|
|
84
|
+
}
|
|
85
|
+
function outcome(r) {
|
|
86
|
+
if (r.status === "identical") {
|
|
87
|
+
return "All runs wrote identical bytes; run 1's output is now the workspace output";
|
|
88
|
+
}
|
|
89
|
+
return "The workspace output was not touched";
|
|
90
|
+
}
|
|
91
|
+
function plural(n, word) {
|
|
92
|
+
return `${n} ${word}${n === 1 ? "" : "s"}`;
|
|
93
|
+
}
|
|
94
|
+
export function formatVerifyReportText(r) {
|
|
95
|
+
const lines = [`verify-determinism: ${headline(r)}`, `result: ${r.status.toUpperCase()}`];
|
|
96
|
+
if (r.first) {
|
|
97
|
+
lines.push(`first differing artefact: ${r.first.path} (run ${r.first.run} vs run 1)`, ` cause: ${r.first.hint}`);
|
|
98
|
+
const rest = r.differences.filter((d) => d !== r.first);
|
|
99
|
+
if (rest.length > 0)
|
|
100
|
+
lines.push(`also differing (${rest.length}):`);
|
|
101
|
+
for (const d of rest)
|
|
102
|
+
lines.push(` ${d.path} (run ${d.run}): ${d.hint}`);
|
|
103
|
+
}
|
|
104
|
+
if (r.halts.length > 0)
|
|
105
|
+
lines.push(`halted flows (${r.halts.length}):`);
|
|
106
|
+
for (const h of r.halts) {
|
|
107
|
+
lines.push(` run ${h.run}, ${h.flow}${h.step ? `, step ${h.step}` : ""}: ${h.message.split("\n")[0]}`);
|
|
108
|
+
}
|
|
109
|
+
lines.push(outcome(r));
|
|
110
|
+
return lines.join("\n") + "\n";
|
|
111
|
+
}
|
|
112
|
+
export function formatVerifyReportMarkdown(r) {
|
|
113
|
+
const lines = [
|
|
114
|
+
"## docsxai determinism check",
|
|
115
|
+
"",
|
|
116
|
+
`**${r.status.toUpperCase()}**: ${headline(r)}.`,
|
|
117
|
+
"",
|
|
118
|
+
];
|
|
119
|
+
if (r.first) {
|
|
120
|
+
lines.push(`First differing artefact: \`${r.first.path}\` (run ${r.first.run} vs run 1).`, "", `- Cause: ${r.first.hint}`, "");
|
|
121
|
+
if (r.differences.length > 1) {
|
|
122
|
+
lines.push(`All ${plural(r.differences.length, "difference")}:`, "", "| Artefact | Run | Cause |", "| --- | --- | --- |");
|
|
123
|
+
for (const d of r.differences) {
|
|
124
|
+
lines.push(`| \`${d.path}\` | ${d.run} | ${d.hint.replace(/\|/g, "\\|")} |`);
|
|
125
|
+
}
|
|
126
|
+
lines.push("");
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (r.halts.length > 0) {
|
|
130
|
+
lines.push(`Halted flows (${r.halts.length}):`, "");
|
|
131
|
+
for (const h of r.halts) {
|
|
132
|
+
lines.push(`- run ${h.run}, \`${h.flow}\`${h.step ? `, step \`${h.step}\`` : ""}: ${h.message.split("\n")[0]}`);
|
|
133
|
+
}
|
|
134
|
+
lines.push("");
|
|
135
|
+
}
|
|
136
|
+
lines.push(`${outcome(r)}.`, "");
|
|
137
|
+
return lines.join("\n");
|
|
138
|
+
}
|
|
139
|
+
export function formatVerifyReportJson(r) {
|
|
140
|
+
return JSON.stringify(r, null, 2) + "\n";
|
|
141
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Ordinal string order: the same on every machine, unlike `localeCompare`. */
|
|
2
|
+
export declare function byOrdinal(a: string, b: string): number;
|
|
3
|
+
export interface TreeListing {
|
|
4
|
+
/** Regular files, root-relative, `/`-separated, sorted ordinally. */
|
|
5
|
+
files: string[];
|
|
6
|
+
/** Directories, root-relative, `/`-separated, sorted ordinally (parents before children). */
|
|
7
|
+
dirs: string[];
|
|
8
|
+
}
|
|
9
|
+
/** List every file and directory under `root`. A symlink counts as a file and is never followed. */
|
|
10
|
+
export declare function listTree(root: string): Promise<TreeListing>;
|
|
11
|
+
/** A run root holds something the verifier will not copy into the workspace. */
|
|
12
|
+
export declare class VerifyTreeError extends Error {
|
|
13
|
+
constructor(message: string);
|
|
14
|
+
}
|
|
15
|
+
/** {@link assertRegularFiles} over everything listed under `root`. */
|
|
16
|
+
export declare function assertRegularTree(root: string): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Copy every file of `fromRoot` to the same relative path under `toRoot`. Returns the paths copied.
|
|
19
|
+
* Every entry is checked with `lstat` first, so a symlink in the root stops the copy before any file moves.
|
|
20
|
+
*/
|
|
21
|
+
export declare function copyTree(fromRoot: string, toRoot: string): Promise<string[]>;
|
|
22
|
+
/**
|
|
23
|
+
* Remove `root` and everything in it by listing it: each file is unlinked, then each directory is
|
|
24
|
+
* removed deepest first, then `root` itself. A directory that is not empty after its listed
|
|
25
|
+
* contents went (something else wrote there) is left in place.
|
|
26
|
+
*/
|
|
27
|
+
export declare function removeListedTree(root: string): Promise<void>;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// File-tree helpers for `run --verify-determinism`: list the artefacts of a run root, copy a verified
|
|
2
|
+
// root into the workspace, and remove a run root by the exact paths listed. No recursive delete
|
|
3
|
+
// anywhere: every file and directory the verifier created is named and removed one by one, so a
|
|
4
|
+
// path it did not list is never touched.
|
|
5
|
+
import { promises as fs } from "node:fs";
|
|
6
|
+
import * as path from "node:path";
|
|
7
|
+
import { resolveWorkspacePath, resolveWorkspacePathReal } from "./workspace.js";
|
|
8
|
+
/** Ordinal string order: the same on every machine, unlike `localeCompare`. */
|
|
9
|
+
export function byOrdinal(a, b) {
|
|
10
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
11
|
+
}
|
|
12
|
+
/** List every file and directory under `root`. A symlink counts as a file and is never followed. */
|
|
13
|
+
export async function listTree(root) {
|
|
14
|
+
const files = [];
|
|
15
|
+
const dirs = [];
|
|
16
|
+
async function walk(rel) {
|
|
17
|
+
const entries = await fs
|
|
18
|
+
.readdir(resolveWorkspacePath(root, ...rel), { withFileTypes: true })
|
|
19
|
+
.catch((e) => {
|
|
20
|
+
if (e.code === "ENOENT" || e.code === "ENOTDIR")
|
|
21
|
+
return [];
|
|
22
|
+
throw e;
|
|
23
|
+
});
|
|
24
|
+
for (const entry of entries) {
|
|
25
|
+
const next = [...rel, entry.name];
|
|
26
|
+
if (entry.isDirectory()) {
|
|
27
|
+
dirs.push(next.join("/"));
|
|
28
|
+
await walk(next);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
files.push(next.join("/"));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
await walk([]);
|
|
36
|
+
return { files: files.sort(byOrdinal), dirs: dirs.sort(byOrdinal) };
|
|
37
|
+
}
|
|
38
|
+
/** A run root holds something the verifier will not copy into the workspace. */
|
|
39
|
+
export class VerifyTreeError extends Error {
|
|
40
|
+
constructor(message) {
|
|
41
|
+
super(message);
|
|
42
|
+
this.name = "VerifyTreeError";
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/** Throws {@link VerifyTreeError} naming the first listed entry that is not a regular file (a symlink, say). */
|
|
46
|
+
async function assertRegularFiles(root, files) {
|
|
47
|
+
for (const rel of files) {
|
|
48
|
+
const stat = await fs.lstat(resolveWorkspacePath(root, ...rel.split("/")));
|
|
49
|
+
if (!stat.isFile()) {
|
|
50
|
+
throw new VerifyTreeError(`refusing to copy ${rel}: it is ${stat.isSymbolicLink() ? "a symlink" : "not a regular file"}, and a run only writes regular files. Nothing was copied into the workspace.`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** {@link assertRegularFiles} over everything listed under `root`. */
|
|
55
|
+
export async function assertRegularTree(root) {
|
|
56
|
+
await assertRegularFiles(root, (await listTree(root)).files);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Copy every file of `fromRoot` to the same relative path under `toRoot`. Returns the paths copied.
|
|
60
|
+
* Every entry is checked with `lstat` first, so a symlink in the root stops the copy before any file moves.
|
|
61
|
+
*/
|
|
62
|
+
export async function copyTree(fromRoot, toRoot) {
|
|
63
|
+
const { files } = await listTree(fromRoot);
|
|
64
|
+
await assertRegularFiles(fromRoot, files);
|
|
65
|
+
for (const rel of files) {
|
|
66
|
+
const segments = rel.split("/");
|
|
67
|
+
const dest = await resolveWorkspacePathReal(toRoot, ...segments);
|
|
68
|
+
await fs.mkdir(path.dirname(dest), { recursive: true });
|
|
69
|
+
await fs.copyFile(resolveWorkspacePath(fromRoot, ...segments), dest);
|
|
70
|
+
}
|
|
71
|
+
return files;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Remove `root` and everything in it by listing it: each file is unlinked, then each directory is
|
|
75
|
+
* removed deepest first, then `root` itself. A directory that is not empty after its listed
|
|
76
|
+
* contents went (something else wrote there) is left in place.
|
|
77
|
+
*/
|
|
78
|
+
export async function removeListedTree(root) {
|
|
79
|
+
const { files, dirs } = await listTree(root);
|
|
80
|
+
for (const rel of files) {
|
|
81
|
+
await fs.unlink(resolveWorkspacePath(root, ...rel.split("/"))).catch(ignoreMissing);
|
|
82
|
+
}
|
|
83
|
+
for (const rel of [...dirs].reverse()) {
|
|
84
|
+
await fs.rmdir(resolveWorkspacePath(root, ...rel.split("/"))).catch(ignoreBusy);
|
|
85
|
+
}
|
|
86
|
+
await fs.rmdir(path.resolve(root)).catch(ignoreBusy);
|
|
87
|
+
}
|
|
88
|
+
function ignoreMissing(e) {
|
|
89
|
+
if (e.code !== "ENOENT")
|
|
90
|
+
throw e;
|
|
91
|
+
}
|
|
92
|
+
function ignoreBusy(e) {
|
|
93
|
+
if (e.code !== "ENOENT" && e.code !== "ENOTEMPTY" && e.code !== "EEXIST")
|
|
94
|
+
throw e;
|
|
95
|
+
}
|
package/dist/viewer-bin.d.ts
CHANGED
|
@@ -18,3 +18,9 @@ export interface ResolveViewerBinOptions {
|
|
|
18
18
|
export declare function resolveViewerBin(opts?: ResolveViewerBinOptions): Promise<ViewerBinResolution>;
|
|
19
19
|
/** Failure message for when the resolved command could not be launched (spawn ENOENT). */
|
|
20
20
|
export declare function formatViewerBinFailure(resolution: ViewerBinResolution): string;
|
|
21
|
+
/**
|
|
22
|
+
* Run the viewer's CLI with `args` and resolve to its exit code. The viewer is its own package/bin;
|
|
23
|
+
* spawning it keeps the engine from depending on it at build time. `label` prefixes the failure
|
|
24
|
+
* line when the bin can't be launched.
|
|
25
|
+
*/
|
|
26
|
+
export declare function runViewerBin(label: string, args: string[]): Promise<number>;
|
package/dist/viewer-bin.js
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
// map doesn't export its package.json. The chain is walked explicitly rather than via
|
|
11
11
|
// `require.resolve.paths()`, which test runners extend with extra lookup dirs.)
|
|
12
12
|
// 3. `docsxai-viewer` on PATH (the npm bin shim) — the legacy behavior, kept as the fallback.
|
|
13
|
+
import { spawn } from "node:child_process";
|
|
13
14
|
import { promises as fs } from "node:fs";
|
|
14
15
|
import * as path from "node:path";
|
|
15
16
|
import { fileURLToPath } from "node:url";
|
|
@@ -95,3 +96,26 @@ export function formatViewerBinFailure(resolution) {
|
|
|
95
96
|
`Install ${VIEWER_PACKAGE} next to the engine (or globally), or point ${VIEWER_BIN_ENV} at its bin script.`,
|
|
96
97
|
].join("\n");
|
|
97
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Run the viewer's CLI with `args` and resolve to its exit code. The viewer is its own package/bin;
|
|
101
|
+
* spawning it keeps the engine from depending on it at build time. `label` prefixes the failure
|
|
102
|
+
* line when the bin can't be launched.
|
|
103
|
+
*/
|
|
104
|
+
export async function runViewerBin(label, args) {
|
|
105
|
+
const viewerBin = await resolveViewerBin();
|
|
106
|
+
return new Promise((resolve) => {
|
|
107
|
+
const child = spawn(viewerBin.command, [...viewerBin.prefixArgs, ...args], {
|
|
108
|
+
stdio: "inherit",
|
|
109
|
+
});
|
|
110
|
+
child.on("error", (e) => {
|
|
111
|
+
if (e.code === "ENOENT") {
|
|
112
|
+
process.stderr.write(`${label}: ${formatViewerBinFailure(viewerBin)}\n`);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
process.stderr.write(`${label}: ${e.message}\n`);
|
|
116
|
+
}
|
|
117
|
+
resolve(1);
|
|
118
|
+
});
|
|
119
|
+
child.on("exit", (code) => resolve(code ?? 1));
|
|
120
|
+
});
|
|
121
|
+
}
|
package/dist/zip.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export interface ZipResult {
|
|
|
11
11
|
entries: string[];
|
|
12
12
|
}
|
|
13
13
|
export declare class ZipError extends Error {
|
|
14
|
-
readonly cause?: unknown;
|
|
15
|
-
constructor(message: string, cause?: unknown);
|
|
14
|
+
readonly cause?: unknown | undefined;
|
|
15
|
+
constructor(message: string, cause?: unknown | undefined);
|
|
16
16
|
}
|
|
17
17
|
export declare function zipDocPack(opts: ZipOptions): Promise<ZipResult>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docsxai/engine",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-rc.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -49,8 +49,9 @@
|
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@types/node": "^20.19.43",
|
|
51
51
|
"@types/pngjs": "^6.0.5",
|
|
52
|
+
"typescript": "^5.5.0",
|
|
52
53
|
"vitest": "^2.0.0",
|
|
53
|
-
"@docsxai/backend": "0.
|
|
54
|
+
"@docsxai/backend": "0.3.0-rc.2"
|
|
54
55
|
},
|
|
55
56
|
"author": "Kalebtec <security@kalebtec.com>",
|
|
56
57
|
"engines": {
|