@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
package/dist/matrix-spec.d.ts
CHANGED
|
@@ -3,19 +3,15 @@ import { type ViewportSize } from "./environment-spec.js";
|
|
|
3
3
|
/** Most variants one flow may expand to. A flow over the cap is rejected at parse time. */
|
|
4
4
|
export declare const MAX_MATRIX_VARIANTS = 64;
|
|
5
5
|
/** A matrix viewport: a preset name, or a size with an optional name (default `<width>x<height>`). */
|
|
6
|
-
export declare const MatrixViewport: z.ZodUnion<[z.ZodEnum<
|
|
6
|
+
export declare const MatrixViewport: z.ZodUnion<readonly [z.ZodEnum<{
|
|
7
|
+
desktop: "desktop";
|
|
8
|
+
tablet: "tablet";
|
|
9
|
+
mobile: "mobile";
|
|
10
|
+
}>, z.ZodObject<{
|
|
7
11
|
name: z.ZodOptional<z.ZodString>;
|
|
8
12
|
width: z.ZodNumber;
|
|
9
13
|
height: z.ZodNumber;
|
|
10
|
-
},
|
|
11
|
-
width: number;
|
|
12
|
-
height: number;
|
|
13
|
-
name?: string | undefined;
|
|
14
|
-
}, {
|
|
15
|
-
width: number;
|
|
16
|
-
height: number;
|
|
17
|
-
name?: string | undefined;
|
|
18
|
-
}>]>;
|
|
14
|
+
}, z.core.$strict>]>;
|
|
19
15
|
export type MatrixViewport = z.infer<typeof MatrixViewport>;
|
|
20
16
|
/** A matrix viewport with its name and size spelled out. */
|
|
21
17
|
export interface ResolvedMatrixViewport extends ViewportSize {
|
|
@@ -27,55 +23,22 @@ export declare function resolveMatrixViewport(entry: MatrixViewport): ResolvedMa
|
|
|
27
23
|
* of the axes it names. Locale and viewport entries must be unique (locales ignoring case,
|
|
28
24
|
* viewports by name), and the product may not pass {@link MAX_MATRIX_VARIANTS}.
|
|
29
25
|
*/
|
|
30
|
-
export declare const MatrixSpec: z.
|
|
31
|
-
locales: z.ZodOptional<z.ZodArray<z.ZodString
|
|
32
|
-
color_schemes: z.ZodOptional<z.ZodArray<z.ZodEnum<
|
|
33
|
-
|
|
26
|
+
export declare const MatrixSpec: z.ZodObject<{
|
|
27
|
+
locales: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
28
|
+
color_schemes: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
29
|
+
light: "light";
|
|
30
|
+
dark: "dark";
|
|
31
|
+
}>>>;
|
|
32
|
+
viewports: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodEnum<{
|
|
33
|
+
desktop: "desktop";
|
|
34
|
+
tablet: "tablet";
|
|
35
|
+
mobile: "mobile";
|
|
36
|
+
}>, z.ZodObject<{
|
|
34
37
|
name: z.ZodOptional<z.ZodString>;
|
|
35
38
|
width: z.ZodNumber;
|
|
36
39
|
height: z.ZodNumber;
|
|
37
|
-
},
|
|
38
|
-
|
|
39
|
-
height: number;
|
|
40
|
-
name?: string | undefined;
|
|
41
|
-
}, {
|
|
42
|
-
width: number;
|
|
43
|
-
height: number;
|
|
44
|
-
name?: string | undefined;
|
|
45
|
-
}>]>, "many">>;
|
|
46
|
-
}, "strict", z.ZodTypeAny, {
|
|
47
|
-
locales?: string[] | undefined;
|
|
48
|
-
color_schemes?: ("light" | "dark")[] | undefined;
|
|
49
|
-
viewports?: ("desktop" | "tablet" | "mobile" | {
|
|
50
|
-
width: number;
|
|
51
|
-
height: number;
|
|
52
|
-
name?: string | undefined;
|
|
53
|
-
})[] | undefined;
|
|
54
|
-
}, {
|
|
55
|
-
locales?: string[] | undefined;
|
|
56
|
-
color_schemes?: ("light" | "dark")[] | undefined;
|
|
57
|
-
viewports?: ("desktop" | "tablet" | "mobile" | {
|
|
58
|
-
width: number;
|
|
59
|
-
height: number;
|
|
60
|
-
name?: string | undefined;
|
|
61
|
-
})[] | undefined;
|
|
62
|
-
}>, {
|
|
63
|
-
locales?: string[] | undefined;
|
|
64
|
-
color_schemes?: ("light" | "dark")[] | undefined;
|
|
65
|
-
viewports?: ("desktop" | "tablet" | "mobile" | {
|
|
66
|
-
width: number;
|
|
67
|
-
height: number;
|
|
68
|
-
name?: string | undefined;
|
|
69
|
-
})[] | undefined;
|
|
70
|
-
}, {
|
|
71
|
-
locales?: string[] | undefined;
|
|
72
|
-
color_schemes?: ("light" | "dark")[] | undefined;
|
|
73
|
-
viewports?: ("desktop" | "tablet" | "mobile" | {
|
|
74
|
-
width: number;
|
|
75
|
-
height: number;
|
|
76
|
-
name?: string | undefined;
|
|
77
|
-
})[] | undefined;
|
|
78
|
-
}>;
|
|
40
|
+
}, z.core.$strict>]>>>;
|
|
41
|
+
}, z.core.$strict>;
|
|
79
42
|
export type MatrixSpec = z.infer<typeof MatrixSpec>;
|
|
80
43
|
/**
|
|
81
44
|
* Which variants a step or annotation applies to (`only`) or is dropped from (`skip`). A clause
|
|
@@ -83,63 +46,27 @@ export type MatrixSpec = z.infer<typeof MatrixSpec>;
|
|
|
83
46
|
* `viewport` values are matrix viewport names, `locale` values match exactly or by language
|
|
84
47
|
* (`es` matches `es-ES`).
|
|
85
48
|
*/
|
|
86
|
-
export declare const VariantSelector: z.
|
|
87
|
-
viewport: z.ZodOptional<z.ZodArray<z.ZodString
|
|
88
|
-
color_scheme: z.ZodOptional<z.ZodArray<z.ZodEnum<
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}, {
|
|
95
|
-
locale?: string[] | undefined;
|
|
96
|
-
viewport?: string[] | undefined;
|
|
97
|
-
color_scheme?: ("light" | "dark")[] | undefined;
|
|
98
|
-
}>, {
|
|
99
|
-
locale?: string[] | undefined;
|
|
100
|
-
viewport?: string[] | undefined;
|
|
101
|
-
color_scheme?: ("light" | "dark")[] | undefined;
|
|
102
|
-
}, {
|
|
103
|
-
locale?: string[] | undefined;
|
|
104
|
-
viewport?: string[] | undefined;
|
|
105
|
-
color_scheme?: ("light" | "dark")[] | undefined;
|
|
106
|
-
}>;
|
|
49
|
+
export declare const VariantSelector: z.ZodObject<{
|
|
50
|
+
viewport: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
51
|
+
color_scheme: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
52
|
+
light: "light";
|
|
53
|
+
dark: "dark";
|
|
54
|
+
}>>>;
|
|
55
|
+
locale: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
56
|
+
}, z.core.$strict>;
|
|
107
57
|
export type VariantSelector = z.infer<typeof VariantSelector>;
|
|
108
58
|
/** The variant a run executed, recorded as `variant` in `annotations.json`. */
|
|
109
59
|
export declare const VariantInfo: z.ZodObject<{
|
|
110
60
|
id: z.ZodString;
|
|
111
61
|
locale: z.ZodOptional<z.ZodString>;
|
|
112
|
-
color_scheme: z.ZodOptional<z.ZodEnum<
|
|
62
|
+
color_scheme: z.ZodOptional<z.ZodEnum<{
|
|
63
|
+
light: "light";
|
|
64
|
+
dark: "dark";
|
|
65
|
+
}>>;
|
|
113
66
|
viewport: z.ZodOptional<z.ZodObject<{
|
|
114
67
|
name: z.ZodString;
|
|
115
68
|
width: z.ZodNumber;
|
|
116
69
|
height: z.ZodNumber;
|
|
117
|
-
},
|
|
118
|
-
|
|
119
|
-
height: number;
|
|
120
|
-
name: string;
|
|
121
|
-
}, {
|
|
122
|
-
width: number;
|
|
123
|
-
height: number;
|
|
124
|
-
name: string;
|
|
125
|
-
}>>;
|
|
126
|
-
}, "strict", z.ZodTypeAny, {
|
|
127
|
-
id: string;
|
|
128
|
-
locale?: string | undefined;
|
|
129
|
-
viewport?: {
|
|
130
|
-
width: number;
|
|
131
|
-
height: number;
|
|
132
|
-
name: string;
|
|
133
|
-
} | undefined;
|
|
134
|
-
color_scheme?: "light" | "dark" | undefined;
|
|
135
|
-
}, {
|
|
136
|
-
id: string;
|
|
137
|
-
locale?: string | undefined;
|
|
138
|
-
viewport?: {
|
|
139
|
-
width: number;
|
|
140
|
-
height: number;
|
|
141
|
-
name: string;
|
|
142
|
-
} | undefined;
|
|
143
|
-
color_scheme?: "light" | "dark" | undefined;
|
|
144
|
-
}>;
|
|
70
|
+
}, z.core.$strict>>;
|
|
71
|
+
}, z.core.$strict>;
|
|
145
72
|
export type VariantInfo = z.infer<typeof VariantInfo>;
|
package/dist/matrix-spec.js
CHANGED
|
@@ -3,12 +3,21 @@
|
|
|
3
3
|
// schema); `doc-pack.ts` re-exports it. Expansion itself lives in `flow-matrix.ts`.
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import { ColorScheme, LocaleTag, VIEWPORT_PRESETS, ViewportPreset, } from "./environment-spec.js";
|
|
6
|
+
import { isWindowsDeviceName } from "./flow-name-rules.js";
|
|
6
7
|
/** Most variants one flow may expand to. A flow over the cap is rejected at parse time. */
|
|
7
8
|
export const MAX_MATRIX_VARIANTS = 64;
|
|
8
|
-
/**
|
|
9
|
+
/** Directory names a flow already holds, so a variant directory cannot take them. */
|
|
10
|
+
const RESERVED_VARIANT_NAMES = new Set(["screenshots", "halts"]);
|
|
11
|
+
/**
|
|
12
|
+
* A viewport's matrix name: also a directory segment, so no dots, slashes or capitals, and not a
|
|
13
|
+
* name `pull` refuses on the way back (`screenshots`, a Windows device name such as `con`).
|
|
14
|
+
*/
|
|
9
15
|
const ViewportName = z
|
|
10
16
|
.string()
|
|
11
|
-
.regex(/^[a-z0-9][a-z0-9-]*$/, "must be lowercase letters, digits and dashes (e.g. mobile-390)")
|
|
17
|
+
.regex(/^[a-z0-9][a-z0-9-]*$/, "must be lowercase letters, digits and dashes (e.g. mobile-390)")
|
|
18
|
+
.refine((name) => !RESERVED_VARIANT_NAMES.has(name) && !isWindowsDeviceName(name), {
|
|
19
|
+
error: "is reserved: it names a directory a flow already holds, or a Windows device",
|
|
20
|
+
});
|
|
12
21
|
/** A matrix viewport: a preset name, or a size with an optional name (default `<width>x<height>`). */
|
|
13
22
|
export const MatrixViewport = z.union([
|
|
14
23
|
ViewportPreset,
|
|
@@ -100,7 +109,7 @@ export const VariantSelector = z
|
|
|
100
109
|
})
|
|
101
110
|
.strict()
|
|
102
111
|
.refine((s) => Object.keys(s).length > 0, {
|
|
103
|
-
|
|
112
|
+
error: "name at least one of `viewport`, `color_scheme`, `locale`",
|
|
104
113
|
});
|
|
105
114
|
/** The variant a run executed, recorded as `variant` in `annotations.json`. */
|
|
106
115
|
export const VariantInfo = z
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// The Node version below which the `docsxai` bin cannot start. Playwright refuses to load on
|
|
2
|
+
// Node 18 and older with its own text and no exit-code contract; this says what is wrong in the
|
|
3
|
+
// CLI's voice before anything else loads. The engine requires Node >= 26 (`doctor` reports that
|
|
4
|
+
// for any version); this floor only covers the versions that cannot run at all.
|
|
5
|
+
import { withNext } from "./cli-messages.js";
|
|
6
|
+
/** Oldest Node major the dependencies load on. */
|
|
7
|
+
export const NODE_FLOOR_MAJOR = 20;
|
|
8
|
+
/** The stderr text for a Node that is too old to start, or `undefined` when it can. */
|
|
9
|
+
export function nodeFloorMessage(version) {
|
|
10
|
+
const major = Number(version.split(".")[0]);
|
|
11
|
+
if (!Number.isFinite(major) || major >= NODE_FLOOR_MAJOR)
|
|
12
|
+
return undefined;
|
|
13
|
+
return `docsxai: ${withNext(`Node v${version} is too old to start (the engine requires Node >= 26)`, "install Node 26 or newer (https://nodejs.org), then rerun the command")}\n`;
|
|
14
|
+
}
|
package/dist/obstacles.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Obstacle selection
|
|
1
|
+
// Obstacle selection, the pure half of `annotations.obstacles`.
|
|
2
2
|
//
|
|
3
3
|
// A driver reports the boxes of visible text and controls near an annotation's target
|
|
4
4
|
// ({@link NearbyBoxes}). This module turns that raw scan into the `obstacles` array written on an
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface OpenCommand {
|
|
2
|
+
command: string;
|
|
3
|
+
args: string[];
|
|
4
|
+
}
|
|
5
|
+
/** The minimal child-process surface {@link openInBrowser} uses, so tests can stand in for it. */
|
|
6
|
+
export type SpawnLike = (command: string, args: string[], options: {
|
|
7
|
+
stdio: "ignore";
|
|
8
|
+
detached: true;
|
|
9
|
+
}) => {
|
|
10
|
+
once(event: "spawn", listener: () => void): unknown;
|
|
11
|
+
once(event: "error", listener: (e: Error) => void): unknown;
|
|
12
|
+
unref(): void;
|
|
13
|
+
};
|
|
14
|
+
/** The opener for `platform`, or `undefined` on a Linux or BSD host with no display. */
|
|
15
|
+
export declare function browserOpener(target: string, platform?: NodeJS.Platform, env?: NodeJS.ProcessEnv): OpenCommand | undefined;
|
|
16
|
+
export interface OpenOptions {
|
|
17
|
+
platform?: NodeJS.Platform;
|
|
18
|
+
env?: NodeJS.ProcessEnv;
|
|
19
|
+
spawn?: SpawnLike;
|
|
20
|
+
}
|
|
21
|
+
/** Hand `target` to the platform's opener. Resolves `true` once the opener started, `false` otherwise. */
|
|
22
|
+
export declare function openInBrowser(target: string, opts?: OpenOptions): Promise<boolean>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Open a local file in the default browser, for `docsxai render --open`. One argv array per
|
|
2
|
+
// platform and no shell, so a path with spaces, quotes or `&` reaches the opener as one argument:
|
|
3
|
+
// `open` on macOS, `explorer.exe` on Windows (cmd's `start` would need a shell to parse the line),
|
|
4
|
+
// `xdg-open` elsewhere. Never throws: it resolves `false` when it can't open anything.
|
|
5
|
+
import { spawn as nodeSpawn } from "node:child_process";
|
|
6
|
+
/** The opener for `platform`, or `undefined` on a Linux or BSD host with no display. */
|
|
7
|
+
export function browserOpener(target, platform = process.platform, env = process.env) {
|
|
8
|
+
if (platform === "darwin")
|
|
9
|
+
return { command: "open", args: [target] };
|
|
10
|
+
if (platform === "win32")
|
|
11
|
+
return { command: "explorer.exe", args: [target] };
|
|
12
|
+
if (!env.DISPLAY && !env.WAYLAND_DISPLAY)
|
|
13
|
+
return undefined;
|
|
14
|
+
return { command: "xdg-open", args: [target] };
|
|
15
|
+
}
|
|
16
|
+
/** Hand `target` to the platform's opener. Resolves `true` once the opener started, `false` otherwise. */
|
|
17
|
+
export function openInBrowser(target, opts = {}) {
|
|
18
|
+
const opener = browserOpener(target, opts.platform, opts.env);
|
|
19
|
+
if (!opener)
|
|
20
|
+
return Promise.resolve(false);
|
|
21
|
+
const spawn = opts.spawn ?? nodeSpawn;
|
|
22
|
+
return new Promise((resolve) => {
|
|
23
|
+
let child;
|
|
24
|
+
try {
|
|
25
|
+
child = spawn(opener.command, opener.args, { stdio: "ignore", detached: true });
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
resolve(false);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
child.once("error", () => resolve(false));
|
|
32
|
+
child.once("spawn", () => {
|
|
33
|
+
child.unref();
|
|
34
|
+
resolve(true);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { type Browser, type BrowserContext, type Page } from "playwright-core";
|
|
2
|
-
import { type BoundingBox, type EnvironmentSpec
|
|
2
|
+
import { type BoundingBox, type EnvironmentSpec } from "./doc-pack.js";
|
|
3
|
+
import { environmentContextOptions } from "./environment-spec.js";
|
|
4
|
+
export { environmentContextOptions };
|
|
3
5
|
import { type EgressGuardOptions } from "./egress-guard.js";
|
|
4
6
|
import { type ActionableState, type BrowserDriver, type ResolvedRedaction } from "./flow-runtime.js";
|
|
5
7
|
import { type StorageState } from "./auth.js";
|
|
@@ -50,22 +52,16 @@ export interface PlaywrightSessionOptions {
|
|
|
50
52
|
* Deterministic execution environment (a flow-file's resolved `environment` block). Locale /
|
|
51
53
|
* timezone / viewport / color-scheme / reduced-motion are context options; the clock is frozen
|
|
52
54
|
* via Playwright's clock API on the session's page. With `connectOverCdp` the context is
|
|
53
|
-
* externally owned
|
|
55
|
+
* externally owned, only the clock applies; the rest is skipped with one stderr warning.
|
|
54
56
|
*/
|
|
55
57
|
environment?: EnvironmentSpec;
|
|
56
|
-
/**
|
|
58
|
+
/** Device pixels per CSS pixel of the context (screenshots come out that many times larger). Absent or 1: the browser default. Ignored with `connectOverCdp`. */
|
|
59
|
+
deviceScaleFactor?: number;
|
|
60
|
+
/** Extra `browser.newContext` options, see {@link SessionContextOptions}. Ignored with `connectOverCdp`. */
|
|
57
61
|
contextOptions?: SessionContextOptions;
|
|
58
62
|
/** Refuse requests to link-local and metadata addresses (see `egress-guard.ts`). Default: `DOCSX_EGRESS_GUARD` in the environment decides. */
|
|
59
63
|
egressGuard?: EgressGuardOptions;
|
|
60
64
|
}
|
|
61
|
-
/** Map an {@link EnvironmentSpec} to the Playwright context options it pins (clock excluded — that's a page-level install). */
|
|
62
|
-
export declare function environmentContextOptions(env: EnvironmentSpec): {
|
|
63
|
-
locale?: string;
|
|
64
|
-
timezoneId?: string;
|
|
65
|
-
viewport?: ViewportSize;
|
|
66
|
-
colorScheme?: "light" | "dark";
|
|
67
|
-
reducedMotion?: "reduce" | "no-preference";
|
|
68
|
-
};
|
|
69
65
|
/** A launched Playwright browser + context + page, plus the driver bound to it. Call `close()` when done. */
|
|
70
66
|
export interface PlaywrightSession {
|
|
71
67
|
browser: Browser;
|
|
@@ -119,7 +115,7 @@ export declare class PlaywrightDriver implements BrowserDriver {
|
|
|
119
115
|
/**
|
|
120
116
|
* Resolve redactions to pixel rects in the screenshot's device-pixel space: selector entries via
|
|
121
117
|
* {@link boundingBox} (already dpr-scaled), fixed regions scaled by the page's devicePixelRatio.
|
|
122
|
-
* A selector matching nothing on-page is skipped with a warning
|
|
118
|
+
* A selector matching nothing on-page is skipped with a warning, an absent element is vacuously
|
|
123
119
|
* redacted; halting would punish flows for UI that legitimately isn't there.
|
|
124
120
|
*/
|
|
125
121
|
private resolveRedactionBoxes;
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
// Playwright-backed BrowserDriver
|
|
1
|
+
// Playwright-backed BrowserDriver, the real execution-mode browser.
|
|
2
2
|
//
|
|
3
3
|
// Implements the {@link BrowserDriver} the flow-runtime is written against, over a Playwright
|
|
4
4
|
// `Page`. The runtime stays browser-agnostic; this is the one place that touches Playwright.
|
|
5
5
|
//
|
|
6
|
-
// Needs a browser binary. `playwright-core` ships the API but not the binaries
|
|
6
|
+
// Needs a browser binary. `playwright-core` ships the API but not the binaries, install one with
|
|
7
7
|
// `pnpm -C packages/engine exec playwright-core install chromium` (source checkout) or
|
|
8
8
|
// `npx playwright-core install chromium` (global/npx installs). For execution
|
|
9
9
|
// against an authed site, the context is created with a captured `storageState` (see the auth layer).
|
|
10
10
|
import { existsSync, promises as fs } from "node:fs";
|
|
11
11
|
import * as path from "node:path";
|
|
12
12
|
import { chromium, } from "playwright-core";
|
|
13
|
-
import {
|
|
13
|
+
import { attachSkipNotice, environmentContextOptions } from "./environment-spec.js";
|
|
14
|
+
export { environmentContextOptions };
|
|
14
15
|
import { egressContextOptions, installEgressGuard, resolveEgressGuard, } from "./egress-guard.js";
|
|
15
16
|
import { budget, withTimeout } from "./driver-budget.js";
|
|
16
17
|
import { HIDDEN_ATTR, markHidden, unmarkHidden } from "./page-hide.js";
|
|
@@ -31,47 +32,72 @@ export function chromiumExecutablePath() {
|
|
|
31
32
|
const p = chromium.executablePath();
|
|
32
33
|
return p && existsSync(p) ? p : undefined;
|
|
33
34
|
}
|
|
34
|
-
/** Map an {@link EnvironmentSpec} to the Playwright context options it pins (clock excluded — that's a page-level install). */
|
|
35
|
-
export function environmentContextOptions(env) {
|
|
36
|
-
const viewport = typeof env.viewport === "string" ? VIEWPORT_PRESETS[env.viewport] : env.viewport;
|
|
37
|
-
return {
|
|
38
|
-
...(env.locale ? { locale: env.locale } : {}),
|
|
39
|
-
...(env.timezone ? { timezoneId: env.timezone } : {}),
|
|
40
|
-
...(viewport ? { viewport } : {}),
|
|
41
|
-
...(env.color_scheme ? { colorScheme: env.color_scheme } : {}),
|
|
42
|
-
...(env.reduced_motion !== undefined
|
|
43
|
-
? { reducedMotion: env.reduced_motion ? "reduce" : "no-preference" }
|
|
44
|
-
: {}),
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
35
|
async function installClock(page, env) {
|
|
48
36
|
if (!env?.clock)
|
|
49
37
|
return;
|
|
50
|
-
// `install({ time })` anchors the fake timers but still ticks with real time
|
|
38
|
+
// `install({ time })` anchors the fake timers but still ticks with real time, millisecond
|
|
51
39
|
// jitter between runs would break byte-identical screenshots. `setFixedTime` is what actually
|
|
52
40
|
// freezes `Date`; timers keep running so timer-driven SPAs don't stall. The clock is
|
|
53
41
|
// context-wide in Playwright, so one install covers every page in the session.
|
|
54
42
|
await page.clock.install({ time: env.clock });
|
|
55
43
|
await page.clock.setFixedTime(env.clock);
|
|
56
44
|
}
|
|
45
|
+
/** Drop a CDP connection: close the context this process created (if any), then disconnect. Never throws. */
|
|
46
|
+
async function releaseAttached(browser, ownContext) {
|
|
47
|
+
await ownContext?.close().catch(() => { });
|
|
48
|
+
await browser.close().catch(() => { });
|
|
49
|
+
}
|
|
57
50
|
/** Launch Chromium (or, with `connectOverCdp`, attach to a running one) and return a {@link PlaywrightSession}. */
|
|
58
51
|
export async function launchPlaywrightSession(opts = {}) {
|
|
59
52
|
const guard = resolveEgressGuard(opts.egressGuard);
|
|
60
53
|
if (opts.connectOverCdp) {
|
|
61
54
|
const browser = await chromium.connectOverCDP(opts.connectOverCdp);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
55
|
+
// Closing a CDP-attached browser only drops the connection; the operator's Chrome keeps running.
|
|
56
|
+
// A context made here is ours and goes first; the operator's own context and tabs stay as they are.
|
|
57
|
+
let ownContext;
|
|
58
|
+
try {
|
|
59
|
+
const context = browser.contexts()[0] ?? (ownContext = await browser.newContext());
|
|
60
|
+
await installEgressGuard(context, guard);
|
|
61
|
+
const pages = context.pages();
|
|
62
|
+
const page = pages.find((p) => /^https?:/.test(p.url())) ?? pages[0] ?? (await context.newPage());
|
|
63
|
+
const notice = attachSkipNotice(opts.environment, !!opts.contextOptions);
|
|
64
|
+
if (notice)
|
|
65
|
+
process.stderr.write(notice);
|
|
66
|
+
await installClock(page, opts.environment);
|
|
67
|
+
const driver = new PlaywrightDriver(page, opts.docPackRoot ?? ".", opts.outputRoot);
|
|
68
|
+
let released;
|
|
69
|
+
return {
|
|
70
|
+
browser,
|
|
71
|
+
context,
|
|
72
|
+
page,
|
|
73
|
+
driver,
|
|
74
|
+
storageState: () => context.storageState(),
|
|
75
|
+
close: () => (released ??= releaseAttached(browser, ownContext)),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
// The caller never receives the session, so nothing else would drop this connection.
|
|
80
|
+
await releaseAttached(browser, ownContext);
|
|
81
|
+
throw e;
|
|
74
82
|
}
|
|
83
|
+
}
|
|
84
|
+
const browser = await chromium.launch({
|
|
85
|
+
headless: !opts.headed,
|
|
86
|
+
...(opts.chromiumArgs ? { args: opts.chromiumArgs } : {}),
|
|
87
|
+
});
|
|
88
|
+
try {
|
|
89
|
+
// Playwright's `newContext({ storageState })` accepts the `{ cookies, origins }` object directly.
|
|
90
|
+
const context = await browser.newContext({
|
|
91
|
+
...(opts.baseURL ? { baseURL: opts.baseURL } : {}),
|
|
92
|
+
...(opts.storageState ? { storageState: opts.storageState } : {}),
|
|
93
|
+
...(opts.ignoreHTTPSErrors ? { ignoreHTTPSErrors: true } : {}),
|
|
94
|
+
...(opts.environment ? environmentContextOptions(opts.environment) : {}),
|
|
95
|
+
...((opts.deviceScaleFactor ?? 1) > 1 ? { deviceScaleFactor: opts.deviceScaleFactor } : {}),
|
|
96
|
+
...(opts.contextOptions ?? {}),
|
|
97
|
+
...egressContextOptions(guard),
|
|
98
|
+
});
|
|
99
|
+
await installEgressGuard(context, guard);
|
|
100
|
+
const page = await context.newPage();
|
|
75
101
|
await installClock(page, opts.environment);
|
|
76
102
|
const driver = new PlaywrightDriver(page, opts.docPackRoot ?? ".", opts.outputRoot);
|
|
77
103
|
return {
|
|
@@ -80,38 +106,17 @@ export async function launchPlaywrightSession(opts = {}) {
|
|
|
80
106
|
page,
|
|
81
107
|
driver,
|
|
82
108
|
storageState: () => context.storageState(),
|
|
83
|
-
|
|
84
|
-
|
|
109
|
+
close: async () => {
|
|
110
|
+
await context.close().catch(() => { });
|
|
111
|
+
await browser.close().catch(() => { });
|
|
112
|
+
},
|
|
85
113
|
};
|
|
86
114
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const context = await browser.newContext({
|
|
93
|
-
...(opts.baseURL ? { baseURL: opts.baseURL } : {}),
|
|
94
|
-
...(opts.storageState ? { storageState: opts.storageState } : {}),
|
|
95
|
-
...(opts.ignoreHTTPSErrors ? { ignoreHTTPSErrors: true } : {}),
|
|
96
|
-
...(opts.environment ? environmentContextOptions(opts.environment) : {}),
|
|
97
|
-
...(opts.contextOptions ?? {}),
|
|
98
|
-
...egressContextOptions(guard),
|
|
99
|
-
});
|
|
100
|
-
await installEgressGuard(context, guard);
|
|
101
|
-
const page = await context.newPage();
|
|
102
|
-
await installClock(page, opts.environment);
|
|
103
|
-
const driver = new PlaywrightDriver(page, opts.docPackRoot ?? ".", opts.outputRoot);
|
|
104
|
-
return {
|
|
105
|
-
browser,
|
|
106
|
-
context,
|
|
107
|
-
page,
|
|
108
|
-
driver,
|
|
109
|
-
storageState: () => context.storageState(),
|
|
110
|
-
close: async () => {
|
|
111
|
-
await context.close().catch(() => { });
|
|
112
|
-
await browser.close().catch(() => { });
|
|
113
|
-
},
|
|
114
|
-
};
|
|
115
|
+
catch (e) {
|
|
116
|
+
// The caller never receives the session, so nothing else would close this browser.
|
|
117
|
+
await browser.close().catch(() => { });
|
|
118
|
+
throw e;
|
|
119
|
+
}
|
|
115
120
|
}
|
|
116
121
|
export class PlaywrightDriver {
|
|
117
122
|
page;
|
|
@@ -193,7 +198,7 @@ export class PlaywrightDriver {
|
|
|
193
198
|
async waitForElementStable(selector) {
|
|
194
199
|
// Stable = two consecutive identical bounding boxes (±0.5 px), polled every 100 ms. Best-effort
|
|
195
200
|
// with a 10 s budget: a perpetually-animating element proceeds after the budget rather than
|
|
196
|
-
// wedging the run
|
|
201
|
+
// wedging the run, Playwright's per-action stability check still guards the action itself.
|
|
197
202
|
const loc = this.page.locator(selector).first();
|
|
198
203
|
const deadline = Date.now() + 10_000;
|
|
199
204
|
let prev = null;
|
|
@@ -250,9 +255,9 @@ export class PlaywrightDriver {
|
|
|
250
255
|
.catch(() => null);
|
|
251
256
|
}
|
|
252
257
|
async boundingBox(selector, timeoutMs) {
|
|
253
|
-
// Visible rect, not the element's own rect
|
|
258
|
+
// Visible rect, not the element's own rect, intersect with each clipping ancestor (overflow != visible)
|
|
254
259
|
// and the viewport. Playwright's `Locator.boundingBox()` returns the element's geometry, which for an
|
|
255
|
-
// element inside a scroll container includes parts that are clipped *off-screen-within-the-scroller
|
|
260
|
+
// element inside a scroll container includes parts that are clipped *off-screen-within-the-scroller*,
|
|
256
261
|
// the screenshot doesn't show those, so a halo drawn from that rect overflows into the void.
|
|
257
262
|
const loc = this.page.locator(selector).first();
|
|
258
263
|
try {
|
|
@@ -299,7 +304,7 @@ export class PlaywrightDriver {
|
|
|
299
304
|
if (right <= x || bottom <= y)
|
|
300
305
|
return null;
|
|
301
306
|
// `getBoundingClientRect` + innerWidth/Height are CSS pixels; `page.screenshot()` produces a
|
|
302
|
-
// *device-pixel* image (CSS × devicePixelRatio
|
|
307
|
+
// *device-pixel* image (CSS × devicePixelRatio, e.g. ~2× on a Retina/zoomed Chrome attached
|
|
303
308
|
// over CDP). The viewer scales the bbox by clientWidth/naturalWidth where naturalWidth is the
|
|
304
309
|
// PNG's device-pixel width, so the stored bbox must be in that same device-pixel space or the
|
|
305
310
|
// halo lands at CSS-coords-÷-dpr (badly mispositioned, and a wrong target rect throws the
|
|
@@ -324,7 +329,7 @@ export class PlaywrightDriver {
|
|
|
324
329
|
return withTimeout(loc.evaluate(collectNearbyBoxes, radius), timeoutMs);
|
|
325
330
|
}
|
|
326
331
|
async screenshot(relPath, redactions = []) {
|
|
327
|
-
// relPath segments carry flow names + step ids from the flow-file
|
|
332
|
+
// relPath segments carry flow names + step ids from the flow-file, containment-checked
|
|
328
333
|
// (symlink-aware) against the doc-pack root before writing.
|
|
329
334
|
const abs = await resolveWorkspacePathReal(this.outputRoot, relPath);
|
|
330
335
|
await fs.mkdir(path.dirname(abs), { recursive: true });
|
|
@@ -339,7 +344,7 @@ export class PlaywrightDriver {
|
|
|
339
344
|
await this.page.screenshot({ path: abs, ...shotOptions });
|
|
340
345
|
return;
|
|
341
346
|
}
|
|
342
|
-
// Redacted path: capture to a buffer, mask, then write
|
|
347
|
+
// Redacted path: capture to a buffer, mask, then write, the unredacted bytes never hit disk.
|
|
343
348
|
const boxes = await this.resolveRedactionBoxes(redactions);
|
|
344
349
|
const png = await this.page.screenshot(shotOptions);
|
|
345
350
|
await fs.writeFile(abs, applyRedactions(png, boxes));
|
|
@@ -347,7 +352,7 @@ export class PlaywrightDriver {
|
|
|
347
352
|
/**
|
|
348
353
|
* Resolve redactions to pixel rects in the screenshot's device-pixel space: selector entries via
|
|
349
354
|
* {@link boundingBox} (already dpr-scaled), fixed regions scaled by the page's devicePixelRatio.
|
|
350
|
-
* A selector matching nothing on-page is skipped with a warning
|
|
355
|
+
* A selector matching nothing on-page is skipped with a warning, an absent element is vacuously
|
|
351
356
|
* redacted; halting would punish flows for UI that legitimately isn't there.
|
|
352
357
|
*/
|
|
353
358
|
async resolveRedactionBoxes(redactions) {
|
|
@@ -357,7 +362,7 @@ export class PlaywrightDriver {
|
|
|
357
362
|
if ("selector" in r) {
|
|
358
363
|
const bbox = await this.boundingBox(r.selector, 1000);
|
|
359
364
|
if (!bbox || bbox.width <= 0 || bbox.height <= 0) {
|
|
360
|
-
process.stderr.write(`screenshot: redaction selector ${r.selector} has no visible box
|
|
365
|
+
process.stderr.write(`screenshot: redaction selector ${r.selector} has no visible box, so it was skipped\n`);
|
|
361
366
|
continue;
|
|
362
367
|
}
|
|
363
368
|
boxes.push({ ...bbox, style: r.style });
|
|
@@ -401,7 +406,7 @@ export class PlaywrightDriver {
|
|
|
401
406
|
if (!visible)
|
|
402
407
|
return "not-visible";
|
|
403
408
|
// Off-screen check via the visible-rect bbox we already compute (intersects with clipping ancestors
|
|
404
|
-
// + the viewport). `null` from bbox here means fully clipped
|
|
409
|
+
// + the viewport). `null` from bbox here means fully clipped, caller's most useful framing is
|
|
405
410
|
// "off-screen" rather than "not-visible" since CSS-wise the element IS visible.
|
|
406
411
|
const bbox = await this.boundingBox(selector, timeoutMs).catch(() => null);
|
|
407
412
|
if (!bbox)
|
|
@@ -409,7 +414,7 @@ export class PlaywrightDriver {
|
|
|
409
414
|
const enabled = await first.isEnabled().catch(() => true);
|
|
410
415
|
if (!enabled)
|
|
411
416
|
return "disabled";
|
|
412
|
-
// "Covered"
|
|
417
|
+
// "Covered", hit-test the bbox center; if elementFromPoint returns something that isn't this
|
|
413
418
|
// element or a descendant of it, another layer is on top.
|
|
414
419
|
try {
|
|
415
420
|
const covered = await first.evaluate((el) => {
|
|
@@ -426,7 +431,7 @@ export class PlaywrightDriver {
|
|
|
426
431
|
return "covered";
|
|
427
432
|
}
|
|
428
433
|
catch {
|
|
429
|
-
// ignore
|
|
434
|
+
// ignore: covered check is best-effort
|
|
430
435
|
}
|
|
431
436
|
return "actionable";
|
|
432
437
|
}
|