@docsxai/engine 0.2.0 → 0.3.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -6
- package/dist/address-class.d.ts +14 -0
- package/dist/address-class.js +151 -0
- package/dist/auth/api-login.js +6 -2
- package/dist/backend-client-contracts.d.ts +2 -0
- package/dist/calibrate.js +5 -0
- package/dist/cli-commands-authoring.js +23 -4
- package/dist/cli-commands-backend.js +2 -2
- package/dist/cli-commands-docpack.d.ts +5 -0
- package/dist/cli-commands-docpack.js +70 -24
- package/dist/cli-commands-pack.d.ts +2 -0
- package/dist/cli-commands-pack.js +69 -0
- package/dist/cli-commands-session.js +92 -88
- package/dist/cli-retired.d.ts +6 -0
- package/dist/cli-retired.js +12 -0
- package/dist/cli-usage.d.ts +1 -1
- package/dist/cli-usage.js +53 -5
- package/dist/cli-verify.d.ts +14 -0
- package/dist/cli-verify.js +54 -0
- package/dist/cli.js +14 -1
- 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 +2165 -181
- package/dist/doc-pack.js +152 -42
- package/dist/doctor-checks.d.ts +1 -1
- package/dist/doctor-checks.js +29 -5
- 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 +7 -1
- 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 +67 -21
- package/dist/flow-runtime.js +72 -110
- 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 +6 -0
- package/dist/index.js +6 -0
- package/dist/matrix-spec.d.ts +145 -0
- package/dist/matrix-spec.js +120 -0
- package/dist/obstacles.d.ts +33 -0
- package/dist/obstacles.js +72 -0
- package/dist/page-hide.d.ts +10 -0
- package/dist/page-hide.js +45 -0
- package/dist/page-nearby-boxes.d.ts +9 -0
- package/dist/page-nearby-boxes.js +92 -0
- package/dist/page-settle.d.ts +39 -0
- package/dist/page-settle.js +142 -0
- package/dist/playwright-driver.d.ts +30 -8
- package/dist/playwright-driver.js +88 -18
- package/dist/run-flows.d.ts +40 -0
- package/dist/run-flows.js +129 -0
- 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/workspace.d.ts +8 -0
- package/package.json +7 -6
package/README.md
CHANGED
|
@@ -6,10 +6,14 @@ The engine **never** calls a model API. Calibration-time inference is supplied b
|
|
|
6
6
|
|
|
7
7
|
## Surface
|
|
8
8
|
|
|
9
|
-
- **Flow-file** — declarative YAML at `<workspace>/flows/<name>.flow.yaml`: `prerequisites` + `locators` + `steps[]` (`action`, `target`, `wait_for`, `success`, `annotation` / `annotations`, per-step `redactions`). Hand-editable; schema-validated. `extends:` composition for shared preambles (with `environment` merged per-key, child wins; `redactions` concatenated).
|
|
9
|
+
- **Flow-file** — declarative YAML at `<workspace>/flows/<name>.flow.yaml`: `prerequisites` + `locators` + `steps[]` (`action`, `target`, `wait_for`, `success`, `annotation` / `annotations`, per-step `redactions`, `timeout_ms`). Actions: `navigate`, `click`, `fill`, `upload`, `press`, `hover`, `select`, `check`, `uncheck`, `wait`, `hide`, `show`. Hand-editable; schema-validated. `extends:` composition for shared preambles (with `environment` merged per-key, child wins; `redactions` concatenated).
|
|
10
10
|
- **Execution environment** — optional `environment` block (`EnvironmentSpec`): frozen `clock` (Playwright clock API), `locale`, `timezone`, `viewport` (`VIEWPORT_PRESETS`: desktop / tablet / mobile, or explicit size), `color_scheme`, `reduced_motion`. Applied at context creation by `launchPlaywrightSession({ environment })`; on CDP-attached sessions only the clock applies (one stderr warning lists skipped fields). `contextOptions` passes `httpCredentials` / `clientCertificates` / `extraHTTPHeaders` through to `browser.newContext`.
|
|
11
|
+
- **Request guard (opt-in)** — `DOCSX_EGRESS_GUARD=1` (or `launchPlaywrightSession({ egressGuard })`) routes every request of the browser context through `egress-guard.ts`: a host that is, or resolves (`dns.lookup`, all addresses) to, a link-local or cloud-metadata address is aborted, redirect hops and WebSocket connections included, and a failed lookup aborts too (the printed reason is generic: `address not allowed`); `DOCSX_EGRESS_DENY_PRIVATE=1` adds loopback and private ranges. Both take `1`, `true` or `yes`. Off by default for a local `run`; the backend runner turns it on for webhook runs. It does not stop DNS rebinding (`SECURITY.md`). An `upload` step reads only regular files under the workspace (`upload-path.ts`). The address rules in `address-class.ts` are a byte-identical copy of the backend's.
|
|
12
|
+
- **Hiding + step timeouts** — `hide` sets `visibility: hidden !important` on every element its `target` matches until a `show` (no target lifts all, a target lifts the `hide` that used the same selector). `PlaywrightDriver` marks the elements with a data attribute and adopts a fixed stylesheet keyed on it (`page-hide.ts`, in-page and engine-owned; the selector is data, never CSS or script). The rule lives on each element's own root, so it reaches shadow trees, and constructable stylesheets are not blocked by a page's CSP. Visibility keeps the box, so nothing reflows; there is deliberately no `display: none` option and no general CSS-injection step. The driver keeps the selectors and re-marks before every screenshot (halt shots included), so the hiding survives navigations and re-renders. `hide` waits for the element to exist (`attached`) and throws when none does, so `optional: true` covers dev-only UI such as `nextjs-portal`. A step's `timeout_ms` (100–30000) is passed to the driver call (`click(selector, timeoutMs?)`, `hideElements(selector, timeoutMs?)`, …); unset, nothing is passed and Playwright's 30 s default applies, so existing flows and non-optional steps are unchanged. `optional` does not shorten the wait by itself, so a missing optional target costs 30 s unless `timeout_ms` is set; `lint` R011 says so. `BrowserDriver` gains `hideElements` / `showElements` (required). The pure `hiddenAtEachStep` (`flow-hidden.ts`) tells `lint` (R013) and `diagnose` which selectors an earlier `hide` hid.
|
|
11
13
|
- **Redactions** — flow-level + per-step `RedactionSpec[]` (`{ selector }` or `{ region }`, style `box` | `pixelate`) masked deterministically before any screenshot (halt shots included) hits disk. The pure pixel transform is `applyRedactions` in `redact.ts`.
|
|
12
|
-
- **`BrowserDriver`** interface — what the runtime needs from a browser. The `PlaywrightDriver` implementation includes the `actionable()` predicate (see [`docs/actionability-contract.md`](../../docs/actionability-contract.md)) that browser-bridge consumers can mirror, plus a real `element_stable` wait (bounding-box polling, 10 s best-effort budget).
|
|
14
|
+
- **`BrowserDriver`** interface — what the runtime needs from a browser. The `PlaywrightDriver` implementation includes the `actionable()` predicate (see [`docs/actionability-contract.md`](../../docs/actionability-contract.md)) that browser-bridge consumers can mirror, plus a real `element_stable` wait (bounding-box polling, 10 s best-effort budget). `waitForSettled?`, `hideElements?`, `showElements?` and `nearbyBoxes?` are **optional** methods (behind `wait_for: settled`, the `hide` and `show` actions and `annotations.obstacles`), so a driver written before they existed still compiles; the runtime halts a step that needs a missing method with a message naming it (`obstacles` only when the workspace turned it on), and never calls a method the flow does not use. `PlaywrightDriver` runs the fixed in-page poll in `page-settle.ts` (fonts loaded, visible images complete, viewport box geometry unchanged for two consecutive polls, every 50 ms, bounded by the step's `timeout_ms`, default 10 s) and rejects with `settled: page did not settle within N ms ...` naming what kept moving; `inferHaltCause` turns that into the `[page never settled: ...]` prefix.
|
|
15
|
+
- **Annotation obstacles** — opt-in (`.docsxai.json` → `"annotations": { "obstacles": true }`, default off). After a step's screenshot, `runFlow` asks the driver for `nearbyBoxes(selector, 320)`: the visible text (per rendered line) and interactive elements around the target, in screenshot pixels, the target's subtree and elements containing it excluded. The pure `selectObstacles` (`obstacles.ts`) rounds boxes outward to whole pixels, clips them to the screenshot, drops duplicates, boxes inside the target and boxes covered by another kept box, caps at the 40 nearest and sorts by y, x, width, height. The result lands as `obstacles` on the annotation record, where the viewer's `burn` uses it to keep callouts off page content. The scan reads the page's own DOM (no iframe or shadow-root content) and runs only through the driver, so any `BrowserDriver` must implement `nearbyBoxes`. Off or absent, records and screenshots are unchanged.
|
|
16
|
+
- **Per-annotation placement** — a step annotation takes an optional `placement` object (`AnnotationPlacement`: `inside`, `side`, `align`, `pin_arrow`, `max_width`, `obstacle_radius`, `obstacle_limit`), bounded like `obstacles` (finite numbers in range, `max_width` 120 to 560, `obstacle_radius` 0 to 2000 CSS px, `obstacle_limit` 1 to 40) and copied onto the annotation record when set. `runFlow` scans with the annotation's own `obstacle_radius` and keeps its own `obstacle_limit` nearest boxes; the burner reads the rest. Absent, records and scans are exactly as before.
|
|
13
17
|
- **Auth strategies** — `auth/strategy.yaml` descriptor + a catalogue of scripted strategies (`api-login`, `ui-form` with a TOTP hop, `email-otp`, `webauthn`, `jwt-injection`, `http-basic`, `pat-header`, `mtls`, `test-backdoor`) alongside the human-in-the-loop `manual-capture`. See [Auth strategies](#auth-strategies) below.
|
|
14
18
|
- **CLI** — `docsxai <command>`. See `--help` or the [top-level README](../../README.md) for the full surface; this package's `dist/cli.js` is the binary.
|
|
15
19
|
|
|
@@ -20,9 +24,11 @@ init scaffold a workspace
|
|
|
20
24
|
capture-auth cache an authed session
|
|
21
25
|
calibrate extract a flow-file from a structured guide
|
|
22
26
|
inspect discover [data-testid] locators on the live page
|
|
23
|
-
run execute flows headless; emit annotations + screenshots
|
|
27
|
+
run execute flows headless; emit annotations + screenshots (`--verify-determinism` byte-compares N isolated runs)
|
|
24
28
|
render build the static viewer (spawns the @docsxai/viewer bin)
|
|
25
|
-
|
|
29
|
+
burn bake annotations into PNG copies (spawns the same bin's `burn`)
|
|
30
|
+
pack build the screenshot pack: burn, optimise, hash-name, manifest; `--check` compares a rebuild with the committed pack (spawns the viewer bin's `pack`)
|
|
31
|
+
lint static checks across flow-files (R001-R016; `extraRules` injectable via `lintFlow`)
|
|
26
32
|
flow-tree visualise the `extends` graph
|
|
27
33
|
diagnose halt-context + recommendations after a halt
|
|
28
34
|
doctor environment + workspace health-check (✓/✗ + one-line fixes; no plugin code runs)
|
|
@@ -31,8 +37,14 @@ zip package the doc pack for hand-off
|
|
|
31
37
|
baseline snapshot the doc pack (flows, prose, annotations, screenshots, locators) for drift comparison
|
|
32
38
|
diff deterministic drift report against a baseline (--fail-on warn|fail gates CI)
|
|
33
39
|
export project the doc pack to a publisher format (`export adf` — Confluence ADF; `export playwright` — Playwright specs)
|
|
40
|
+
plugins list / info / sync the workspace plugin set (see Plugins below)
|
|
41
|
+
login validate a backend bearer token (`--oauth` runs the OAuth 2.1 + PKCE flow)
|
|
42
|
+
push upload the doc pack to the backend as a new revision
|
|
43
|
+
pull fetch a backend revision's artifacts into the workspace
|
|
34
44
|
```
|
|
35
45
|
|
|
46
|
+
A flow with a top-level `matrix:` (`locales`, `color_schemes`, `viewports`; at most 64 variants) expands at parse time (`expandFlow` in `flow-matrix.ts`, schema in `matrix-spec.ts`) into one flow per variant, each under its own `environment`, with `only`/`skip` on steps and annotations and `copy_by_locale` on annotations. `run` starts one session per variant (`run-flows.ts`) and writes `docs/<flow>/<variant>/{screenshots/, annotations.json, halts/}`; `annotations.json` records the variant, and a halt message names it. Without a matrix the layout and every output byte are unchanged. `lint` (R015, R016), `flow-tree` and `diagnose --variant` read the matrix. Design note: `docs/ai-context/architecture/flow-matrix-decision.md`.
|
|
47
|
+
|
|
36
48
|
`run` has a sub-3-second iteration mode for long-async flows: `--start-from <step-id> --cdp <endpoint>` skips every step before the target and attaches to an already-warm Chrome.
|
|
37
49
|
|
|
38
50
|
`zip` packages the doc pack in-process (via fflate) — no system `zip` binary required — and **deterministically**: entries are sorted, every entry's mtime is pinned to the zip epoch (1980-01-01), and the compression level is fixed, so the same doc pack always produces a byte-identical archive. Includes `flows/`, `docs/`, `.docsxai.json`, `auth/strategy.yaml`, `README.md`; excludes `.auth/`, `**/halts/`, and (unless `--include-viewer`) `.viewer/`. Symlinks that point outside the workspace are never followed into the archive.
|
|
@@ -41,9 +53,15 @@ export project the doc pack to a publisher format (`export adf` — Conf
|
|
|
41
53
|
|
|
42
54
|
`baseline` + `diff` are the drift-detection pair. `baseline` snapshots `flows/` + `docs/` (step `.md`s, `annotations.json`, `screenshots/`, `locators.yaml`) into `<workspace>/.baseline/` (or `--out <dir>`); `diff` compares the live workspace against it (`diffDocPacks` on the library surface) and emits a deterministic `docsxai/drift@1` report — per flow: id-keyed step field deltas, annotation moves beyond a pixel tolerance, screenshot pixel diffs via pngjs (changed-pixel count / pct / changed-region bbox; dimension changes flagged distinctly; `ignore_regions` excluded), prose line-change counts, and locator changes. `--format md` (`formatDriftReportMarkdown`) is PR-comment-ready; `--fail-on warn|fail` exits 1 at/above the threshold (defaults: ≥1% changed pixels = warn, ≥5% = fail, structural change = warn). The engine detects and reports; proposing flow-file patches stays with the host agent (`diagnose`).
|
|
43
55
|
|
|
56
|
+
`run --verify-determinism [--runs <2-5>] [--format json|md|text]` runs the selected flows N times (default 2) through the same flow loop as a plain `run` (`runFlowsInSessions`), each into its own output root under `<workspace>/.docsxai-verify/run-<k>/` (`PlaywrightSessionOptions.outputRoot` redirects the screenshots; `upload` sources still resolve against the workspace), then byte-compares every file under the roots (`compareRuns` in `verify-compare.ts`, exported). The first differing artefact is named by path with a cause: JSON key path, PNG changed-pixel count and region (the `diffPngBuffers` of `diff`), first differing text line, or sizes. A halt is recorded as `docs/<flow>/halts/halt-context.json` in the run root, so halt context is compared like any artefact; a halted flow makes the verdict `halted` (exit 1). Run 1's tree is copied into the workspace only when every run agrees and none halted; otherwise the workspace is untouched. The roots are removed by their listing (unlink each file, rmdir each directory deepest first; `verify-tree.ts`), never recursively. The `docsxai/verify-determinism@1` report has no timestamps or paths and is ordered by ordinal path then run: exit 0 identical, 1 differing or halted, 2 usage. Nightly recipes for GitHub Actions, GitLab CI and Woodpecker are in `docs/ci-recipes.md` and `examples/ci/`.
|
|
57
|
+
|
|
44
58
|
`export playwright` renders each flow (with `extends` resolved) as a self-contained Playwright `.spec.ts` (`exportFlowAsPlaywrightTest`) into `<workspace>/.export/tests/`: locator consts, steps as page actions, `wait_for` as waits, `success` as `expect()` assertions, `environment` as `test.use()` + `page.clock.setFixedTime`, `optional` steps in try/catch. Deterministic; generated files carry a "regenerate, don't hand-edit" header.
|
|
45
59
|
|
|
46
|
-
`render`
|
|
60
|
+
`render` and `burn` locate the viewer bin in order: `DOCSX_VIEWER_BIN` (path to the viewer's bin script or an executable), the `@docsxai/viewer` package installed next to the engine (its `bin` run with the current Node), then `docsxai-viewer` on PATH. A launch failure reports all three attempts.
|
|
61
|
+
|
|
62
|
+
`burn <workspace-dir> [--flow <name>] [--out <dir>] [--report <file>] [--no-connector-outline]` bakes the annotations into PNG copies by running the viewer's `burn` through that same resolution (the engine does not depend on `@docsxai/viewer`). It checks the workspace has a `docs/` directory, passes the flags through, and returns the viewer's exit code; an unknown flag or a path-like `--flow` exits 2.
|
|
63
|
+
|
|
64
|
+
`pack <workspace-or-raw-dir> [--from-raw] [--out <dir>] [--public-prefix <path>] [--no-optimise] [--generated-for <text>]` and `pack <workspace-or-raw-dir> --check --against <pack-dir> [--from-raw] [--threshold <pct>]` (`cli-commands-pack.ts`) are the screenshot-pack pair. The old `drift` command is retired: `cli-retired.ts` maps it to `pack --check` with a deprecation warning (`deprecation.ts`). Like `burn`, the engine validates the argv edge (an unknown flag, a flag with no value, a second positional, no `--against`, a `--threshold` that is not a number >= 0 all exit 2), then runs the viewer's `pack` or `drift` through the same bin resolution (`runViewerBin` in `viewer-bin.ts`) and returns its exit code. The viewer owns the logic (burn, `oxipng`, hashing, manifest, drift); the engine does not import it. See the [viewer README](../viewer/README.md#screenshot-pack).
|
|
47
65
|
|
|
48
66
|
## Auth strategies
|
|
49
67
|
|
|
@@ -104,7 +122,7 @@ The register module exports a `register(api)` function (named or default). `api`
|
|
|
104
122
|
|
|
105
123
|
### Workspace config + lock
|
|
106
124
|
|
|
107
|
-
Two optional `.docsxai.json` keys wire plugins into a workspace:
|
|
125
|
+
Two optional `.docsxai.json` keys wire plugins into a workspace (a third, `annotations.obstacles`, switches on obstacle scanning for `run`; see the engine overview above):
|
|
108
126
|
|
|
109
127
|
```json
|
|
110
128
|
{
|
|
@@ -113,6 +131,8 @@ Two optional `.docsxai.json` keys wire plugins into a workspace:
|
|
|
113
131
|
}
|
|
114
132
|
```
|
|
115
133
|
|
|
134
|
+
`@docsxai/plugin-confluence` is repo-only (`private: true`, not on npm). Build it in a checkout (`pnpm -r build`) and wire it by path instead: `{ "path": "<checkout>/packages/plugin-confluence" }`. The `{ "package": ... }` form resolves only once the package is installed in the workspace.
|
|
135
|
+
|
|
116
136
|
`plugins-lock.json` (schema `docsxai/plugins-lock@1`, next to the config) pins each plugin's register-module sha256. When it exists, every resolve verifies the bytes **before** importing; a mismatch fails closed with a "run `docsxai plugins sync`" message.
|
|
117
137
|
|
|
118
138
|
### CLI
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Why an address is refused: link-local ranges and cloud instance-metadata endpoints. */
|
|
2
|
+
export declare const LINK_LOCAL_OR_METADATA = "link-local or cloud-metadata";
|
|
3
|
+
/** Why an address is refused under `denyPrivate`: loopback, RFC 1918, CGNAT, ULA and the like. */
|
|
4
|
+
export declare const LOOPBACK_OR_PRIVATE = "loopback or private-network";
|
|
5
|
+
export type Ipv4 = [number, number, number, number];
|
|
6
|
+
export declare function parseIpv4(host: string): Ipv4 | null;
|
|
7
|
+
/** The eight 16-bit groups of an IPv6 literal (brackets and a zone id optional), or null. */
|
|
8
|
+
export declare function parseIpv6(host: string): number[] | null;
|
|
9
|
+
/**
|
|
10
|
+
* Why `hostname` (as `URL.hostname` prints it, or an address a resolver returned) is refused, or
|
|
11
|
+
* null: an IPv4 or IPv6 literal in any spelling the URL parser normalises, or one of the names
|
|
12
|
+
* that always mean the local machine or a metadata service. A DNS name is not resolved here.
|
|
13
|
+
*/
|
|
14
|
+
export declare function hostProblem(hostname: string, denyPrivate: boolean): string | null;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// Address classification shared by two packages that cannot import each other: the backend's
|
|
2
|
+
// `app_url` filter and the engine's request guard each carry a byte-identical copy of this file
|
|
3
|
+
// (`packages/backend/src/address-class.ts`, `packages/engine/src/address-class.ts`), and a test in
|
|
4
|
+
// `packages/docsxai/test` fails when the two differ. Edit both together.
|
|
5
|
+
//
|
|
6
|
+
// jscpd:ignore-start
|
|
7
|
+
/** Why an address is refused: link-local ranges and cloud instance-metadata endpoints. */
|
|
8
|
+
export const LINK_LOCAL_OR_METADATA = "link-local or cloud-metadata";
|
|
9
|
+
/** Why an address is refused under `denyPrivate`: loopback, RFC 1918, CGNAT, ULA and the like. */
|
|
10
|
+
export const LOOPBACK_OR_PRIVATE = "loopback or private-network";
|
|
11
|
+
const METADATA_HOSTNAMES = new Set(["metadata.google.internal", "instance-data"]);
|
|
12
|
+
const LOCAL_HOSTNAMES = new Set([
|
|
13
|
+
"localhost",
|
|
14
|
+
"localhost.localdomain",
|
|
15
|
+
"ip6-localhost",
|
|
16
|
+
"ip6-loopback",
|
|
17
|
+
]);
|
|
18
|
+
export function parseIpv4(host) {
|
|
19
|
+
const m = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(host);
|
|
20
|
+
if (!m)
|
|
21
|
+
return null;
|
|
22
|
+
const parts = m.slice(1).map(Number);
|
|
23
|
+
return parts.every((n) => n <= 255) ? parts : null;
|
|
24
|
+
}
|
|
25
|
+
/** The eight 16-bit groups of an IPv6 literal (brackets and a zone id optional), or null. */
|
|
26
|
+
export function parseIpv6(host) {
|
|
27
|
+
const bare = host.replace(/^\[|\]$/g, "").replace(/%.*$/, "");
|
|
28
|
+
if (!bare.includes(":"))
|
|
29
|
+
return null;
|
|
30
|
+
const halves = bare.split("::");
|
|
31
|
+
if (halves.length > 2)
|
|
32
|
+
return null;
|
|
33
|
+
const toGroups = (part) => {
|
|
34
|
+
if (part === "")
|
|
35
|
+
return [];
|
|
36
|
+
const groups = [];
|
|
37
|
+
const pieces = part.split(":");
|
|
38
|
+
for (const [i, piece] of pieces.entries()) {
|
|
39
|
+
if (piece.includes(".")) {
|
|
40
|
+
const v4 = i === pieces.length - 1 ? parseIpv4(piece) : null;
|
|
41
|
+
if (!v4)
|
|
42
|
+
return null;
|
|
43
|
+
groups.push(v4[0] * 256 + v4[1], v4[2] * 256 + v4[3]);
|
|
44
|
+
}
|
|
45
|
+
else if (/^[0-9a-f]{1,4}$/i.test(piece)) {
|
|
46
|
+
groups.push(parseInt(piece, 16));
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return groups;
|
|
53
|
+
};
|
|
54
|
+
const head = toGroups(halves[0]);
|
|
55
|
+
const tail = halves.length === 2 ? toGroups(halves[1]) : [];
|
|
56
|
+
if (!head || !tail)
|
|
57
|
+
return null;
|
|
58
|
+
if (halves.length === 1)
|
|
59
|
+
return head.length === 8 ? head : null;
|
|
60
|
+
const fill = 8 - head.length - tail.length;
|
|
61
|
+
return fill >= 1 ? [...head, ...new Array(fill).fill(0), ...tail] : null;
|
|
62
|
+
}
|
|
63
|
+
/** Why an IPv4 address is refused, or null. */
|
|
64
|
+
function ipv4Problem(ip, denyPrivate) {
|
|
65
|
+
const [a, b, c, d] = ip;
|
|
66
|
+
const metadata = (a === 169 && b === 254) ||
|
|
67
|
+
(a === 100 && b === 100 && c === 100 && d === 200) ||
|
|
68
|
+
(a === 168 && b === 63 && c === 129 && d === 16);
|
|
69
|
+
if (metadata)
|
|
70
|
+
return LINK_LOCAL_OR_METADATA;
|
|
71
|
+
if (!denyPrivate)
|
|
72
|
+
return null;
|
|
73
|
+
const isPrivate = a === 0 ||
|
|
74
|
+
a === 10 ||
|
|
75
|
+
a === 127 ||
|
|
76
|
+
(a === 100 && b >= 64 && b <= 127) ||
|
|
77
|
+
(a === 172 && b >= 16 && b <= 31) ||
|
|
78
|
+
(a === 192 && b === 168);
|
|
79
|
+
return isPrivate ? LOOPBACK_OR_PRIVATE : null;
|
|
80
|
+
}
|
|
81
|
+
/** The IPv4 address held in groups `i` and `i + 1`, each XORed with `mask`. */
|
|
82
|
+
function v4At(g, i, mask = 0) {
|
|
83
|
+
const hi = (g[i] ?? 0) ^ mask;
|
|
84
|
+
const lo = (g[i + 1] ?? 0) ^ mask;
|
|
85
|
+
return [hi >> 8, hi & 255, lo >> 8, lo & 255];
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The IPv4 addresses an IPv6 address stands for: IPv4-mapped, IPv4-compatible, NAT64
|
|
89
|
+
* (`64:ff9b::/96` and the local-use `64:ff9b:1::/48`), 6to4 (`2002::/16`, the address in groups 1
|
|
90
|
+
* and 2) and Teredo (`2001::/32`, the server in groups 2 and 3 and the client, stored inverted, in
|
|
91
|
+
* groups 6 and 7).
|
|
92
|
+
*/
|
|
93
|
+
function embeddedIpv4(g) {
|
|
94
|
+
const at = (i) => g[i] ?? 0;
|
|
95
|
+
const zeros = (from, to) => g.slice(from, to).every((n) => n === 0);
|
|
96
|
+
if (zeros(0, 5) && at(5) === 0xffff)
|
|
97
|
+
return [v4At(g, 6)];
|
|
98
|
+
if (zeros(0, 6) && at(6) !== 0)
|
|
99
|
+
return [v4At(g, 6)];
|
|
100
|
+
if (at(0) === 0x64 && at(1) === 0xff9b && (zeros(2, 6) || at(2) === 1))
|
|
101
|
+
return [v4At(g, 6)];
|
|
102
|
+
if (at(0) === 0x2002)
|
|
103
|
+
return [v4At(g, 1)];
|
|
104
|
+
if (at(0) === 0x2001 && at(1) === 0)
|
|
105
|
+
return [v4At(g, 2), v4At(g, 6, 0xffff)];
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
/** Why an IPv6 address is refused, or null. An embedded IPv4 address is checked as IPv4. */
|
|
109
|
+
function ipv6Problem(g, denyPrivate) {
|
|
110
|
+
const at = (i) => g[i] ?? 0;
|
|
111
|
+
const zeros = (from, to) => g.slice(from, to).every((n) => n === 0);
|
|
112
|
+
for (const v4 of embeddedIpv4(g)) {
|
|
113
|
+
const embedded = ipv4Problem(v4, denyPrivate);
|
|
114
|
+
if (embedded)
|
|
115
|
+
return embedded;
|
|
116
|
+
}
|
|
117
|
+
const metadata = at(0) === 0xfd00 && at(1) === 0x0ec2 && zeros(2, 7) && at(7) === 0x254;
|
|
118
|
+
if ((at(0) & 0xffc0) === 0xfe80 || metadata)
|
|
119
|
+
return LINK_LOCAL_OR_METADATA;
|
|
120
|
+
if (!denyPrivate)
|
|
121
|
+
return null;
|
|
122
|
+
const unspecified = zeros(0, 8);
|
|
123
|
+
const loopback = zeros(0, 7) && at(7) === 1;
|
|
124
|
+
const uniqueLocal = (at(0) & 0xfe00) === 0xfc00;
|
|
125
|
+
const siteLocal = (at(0) & 0xffc0) === 0xfec0;
|
|
126
|
+
const localNat64 = at(0) === 0x64 && at(1) === 0xff9b && at(2) === 1;
|
|
127
|
+
return unspecified || loopback || uniqueLocal || siteLocal || localNat64
|
|
128
|
+
? LOOPBACK_OR_PRIVATE
|
|
129
|
+
: null;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Why `hostname` (as `URL.hostname` prints it, or an address a resolver returned) is refused, or
|
|
133
|
+
* null: an IPv4 or IPv6 literal in any spelling the URL parser normalises, or one of the names
|
|
134
|
+
* that always mean the local machine or a metadata service. A DNS name is not resolved here.
|
|
135
|
+
*/
|
|
136
|
+
export function hostProblem(hostname, denyPrivate) {
|
|
137
|
+
const host = hostname.toLowerCase().replace(/\.+$/, "");
|
|
138
|
+
const v4 = parseIpv4(host);
|
|
139
|
+
if (v4)
|
|
140
|
+
return ipv4Problem(v4, denyPrivate);
|
|
141
|
+
const v6 = parseIpv6(host);
|
|
142
|
+
if (v6)
|
|
143
|
+
return ipv6Problem(v6, denyPrivate);
|
|
144
|
+
if (METADATA_HOSTNAMES.has(host))
|
|
145
|
+
return LINK_LOCAL_OR_METADATA;
|
|
146
|
+
if (denyPrivate && (LOCAL_HOSTNAMES.has(host) || host.endsWith(".localhost"))) {
|
|
147
|
+
return LOOPBACK_OR_PRIVATE;
|
|
148
|
+
}
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
// jscpd:ignore-end
|
package/dist/auth/api-login.js
CHANGED
|
@@ -45,14 +45,18 @@ export class ApiLoginStrategy {
|
|
|
45
45
|
const opts = parseStrategyOptions(this.name, ApiLoginOptions, ctx.options);
|
|
46
46
|
const url = new URL(opts.login_url, ctx.baseURL);
|
|
47
47
|
const isJson = opts.body_format === "json";
|
|
48
|
+
// GET and HEAD cannot carry a body (fetch throws), so a link-style login sends none.
|
|
49
|
+
const hasBody = !["GET", "HEAD"].includes(opts.method.toUpperCase());
|
|
48
50
|
const body = isJson ? JSON.stringify(ctx.creds) : new URLSearchParams(ctx.creds).toString();
|
|
49
51
|
const result = await fetchCollectingCookies(url, {
|
|
50
52
|
method: opts.method,
|
|
51
53
|
headers: {
|
|
52
|
-
|
|
54
|
+
...(hasBody
|
|
55
|
+
? { "content-type": isJson ? "application/json" : "application/x-www-form-urlencoded" }
|
|
56
|
+
: {}),
|
|
53
57
|
accept: "application/json, text/html;q=0.9, */*;q=0.8",
|
|
54
58
|
},
|
|
55
|
-
body,
|
|
59
|
+
...(hasBody ? { body } : {}),
|
|
56
60
|
}, { fetchImpl: this.fetchImpl });
|
|
57
61
|
// Failure messages name the endpoint and the check — never the credential values.
|
|
58
62
|
const check = opts.success_check;
|
|
@@ -13,6 +13,8 @@ export interface Project {
|
|
|
13
13
|
name: string;
|
|
14
14
|
created_at: string;
|
|
15
15
|
head_revision_id: string | null;
|
|
16
|
+
/** Base URL of the running app the project documents; webhook runs use it as the workspace `app_url`. */
|
|
17
|
+
app_url?: string;
|
|
16
18
|
}
|
|
17
19
|
export interface Revision {
|
|
18
20
|
id: string;
|
package/dist/calibrate.js
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
// that's the `/docsxai:calibrate` *skill* (see packages/plugin/skills/calibrate/SKILL.md); ambiguity
|
|
11
11
|
// signalling lives at the MCP/skill layer. This module covers only the part that's deterministic.
|
|
12
12
|
import { promises as fs } from "node:fs";
|
|
13
|
+
import { FlowName } from "./doc-pack.js";
|
|
13
14
|
import { FlowFileError, parseFlowFile, serializeFlowFile } from "./flow-file.js";
|
|
14
15
|
import { initStyleIfAbsent } from "./style.js";
|
|
15
16
|
import { resolveWorkspacePath, resolveWorkspacePathReal } from "./workspace.js";
|
|
@@ -59,6 +60,10 @@ export function extractFlowFile(text, source = "<flow-guide>") {
|
|
|
59
60
|
export async function calibrate(opts) {
|
|
60
61
|
const flow = extractFlowFile(opts.fromText, opts.fromSource ?? "<flow-guide>");
|
|
61
62
|
const name = opts.flowName ?? flow.name;
|
|
63
|
+
const checked = FlowName.safeParse(name);
|
|
64
|
+
if (!checked.success) {
|
|
65
|
+
throw new CalibrateError(`flow name "${name}" is not usable: ${checked.error.issues.map((i) => i.message).join("; ")}`);
|
|
66
|
+
}
|
|
62
67
|
await fs.mkdir(resolveWorkspacePath(opts.workspaceDir, "flows"), { recursive: true });
|
|
63
68
|
// The flow name is guide-supplied — resolve with the symlink-aware variant before writing.
|
|
64
69
|
const flowFilePath = await resolveWorkspacePathReal(opts.workspaceDir, "flows", `${name}.flow.yaml`);
|
|
@@ -8,8 +8,9 @@
|
|
|
8
8
|
import { promises as fs } from "node:fs";
|
|
9
9
|
import * as path from "node:path";
|
|
10
10
|
import { LocalStorageStateCache, parseAuthStrategyFile } from "./auth.js";
|
|
11
|
-
import { FlowFileError, parseFlowFile, resolveFlowExtends } from "./flow-file.js";
|
|
12
|
-
import {
|
|
11
|
+
import { expandFlowVariants, FlowFileError, parseFlowFile, resolveFlowExtends, } from "./flow-file.js";
|
|
12
|
+
import { variantDocDir } from "./flow-matrix.js";
|
|
13
|
+
import { buildDiagnoseReport, formatReportText, pickDiagnoseVariant, probeLive, } from "./diagnose.js";
|
|
13
14
|
import { formatIssuesText, lintFlow } from "./flow-lint.js";
|
|
14
15
|
import { buildFlowTree, formatTreeText } from "./flow-tree.js";
|
|
15
16
|
import { formatJargonHitsText, initStyleIfAbsent, loadStyle, scanWorkspaceForJargon, StyleError, writeStyle, } from "./style.js";
|
|
@@ -266,6 +267,7 @@ export async function cmdDiagnose(args) {
|
|
|
266
267
|
const flowName = typeof flags.get("flow") === "string" ? flags.get("flow") : undefined;
|
|
267
268
|
const stepId = typeof flags.get("step") === "string" ? flags.get("step") : undefined;
|
|
268
269
|
const cdpEndpoint = typeof flags.get("cdp") === "string" ? flags.get("cdp") : undefined;
|
|
270
|
+
const variantFlag = typeof flags.get("variant") === "string" ? flags.get("variant") : undefined;
|
|
269
271
|
const format = typeof flags.get("format") === "string" ? flags.get("format") : "text";
|
|
270
272
|
if (!flowName) {
|
|
271
273
|
process.stderr.write(`diagnose: --flow <name> required\n`);
|
|
@@ -292,18 +294,34 @@ export async function cmdDiagnose(args) {
|
|
|
292
294
|
return parseFlowFile(text, fp);
|
|
293
295
|
};
|
|
294
296
|
let flow;
|
|
297
|
+
let variants;
|
|
295
298
|
try {
|
|
296
299
|
const parsed = await loadFlowFile(flowName);
|
|
297
300
|
flow = parsed.extends ? await resolveFlowExtends(parsed, loadFlowFile) : parsed;
|
|
301
|
+
variants = expandFlowVariants(flow);
|
|
298
302
|
}
|
|
299
303
|
catch (e) {
|
|
300
304
|
const msg = e instanceof FlowFileError ? e.message : e.message;
|
|
301
305
|
process.stderr.write(`diagnose: ${msg}\n`);
|
|
302
306
|
return 1;
|
|
303
307
|
}
|
|
308
|
+
// A flow with a `matrix` is diagnosed one variant at a time: its steps and halt shot are the variant's.
|
|
309
|
+
const picked = await pickDiagnoseVariant({
|
|
310
|
+
workspace: projectDir,
|
|
311
|
+
flow: flowName,
|
|
312
|
+
stepId,
|
|
313
|
+
variants,
|
|
314
|
+
requested: variantFlag,
|
|
315
|
+
});
|
|
316
|
+
if ("error" in picked) {
|
|
317
|
+
process.stderr.write(`diagnose: ${picked.error}\n`);
|
|
318
|
+
return 2;
|
|
319
|
+
}
|
|
320
|
+
const variantId = picked.variant.id;
|
|
321
|
+
flow = picked.variant.flow;
|
|
304
322
|
const step = flow.steps.find((s) => s.id === stepId);
|
|
305
323
|
if (!step) {
|
|
306
|
-
process.stderr.write(`diagnose: no step "${stepId}" in flow "${flowName}" (merged step list: ${flow.steps.map((s) => s.id).join(", ")})\n`);
|
|
324
|
+
process.stderr.write(`diagnose: no step "${stepId}" in flow "${flowName}"${variantId ? ` variant "${variantId}"` : ""} (${variantId ? "variant" : "merged"} step list: ${flow.steps.map((s) => s.id).join(", ")})\n`);
|
|
307
325
|
return 1;
|
|
308
326
|
}
|
|
309
327
|
const resolvedSelector = step.target
|
|
@@ -311,7 +329,7 @@ export async function cmdDiagnose(args) {
|
|
|
311
329
|
? (flow.locators[step.target.slice(1)] ?? step.target)
|
|
312
330
|
: step.target
|
|
313
331
|
: undefined;
|
|
314
|
-
const haltScreenshotAbsPath = resolveWorkspacePath(projectDir,
|
|
332
|
+
const haltScreenshotAbsPath = resolveWorkspacePath(projectDir, variantDocDir(flowName, variantId), "halts", `${stepId}.png`);
|
|
315
333
|
// Optional live probe via --cdp.
|
|
316
334
|
let liveProbe;
|
|
317
335
|
let liveSession;
|
|
@@ -333,6 +351,7 @@ export async function cmdDiagnose(args) {
|
|
|
333
351
|
...(resolvedSelector ? { resolvedSelector } : {}),
|
|
334
352
|
haltScreenshotAbsPath,
|
|
335
353
|
...(liveProbe ? { liveProbe } : {}),
|
|
354
|
+
...(variantId ? { variant: { id: variantId, all: picked.ids } } : {}),
|
|
336
355
|
});
|
|
337
356
|
}
|
|
338
357
|
catch (e) {
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import { promises as fs } from "node:fs";
|
|
8
8
|
import * as path from "node:path";
|
|
9
9
|
import { BackendClient, BackendClientError, createBackendClient, oauthLogin, saveBackendTokenFile, } from "./backend-client.js";
|
|
10
|
-
import { fetchScreenshotBlobs, readDocPack, uploadScreenshotBlobs, writeDocPack, } from "./doc-pack-io.js";
|
|
10
|
+
import { fetchScreenshotBlobs, readDocPack, UnsafePackNameError, uploadScreenshotBlobs, writeDocPack, } from "./doc-pack-io.js";
|
|
11
11
|
import { pluginsCli } from "./plugins-cli.js";
|
|
12
12
|
import { loadWorkspaceConfig, resolveWorkspacePath } from "./workspace.js";
|
|
13
13
|
import { parseFlags } from "./cli-shared.js";
|
|
@@ -198,7 +198,7 @@ export async function cmdPull(args) {
|
|
|
198
198
|
return 0;
|
|
199
199
|
}
|
|
200
200
|
catch (e) {
|
|
201
|
-
if (e instanceof BackendClientError) {
|
|
201
|
+
if (e instanceof BackendClientError || e instanceof UnsafePackNameError) {
|
|
202
202
|
process.stderr.write(`pull: ${e.message}\n`);
|
|
203
203
|
return 1;
|
|
204
204
|
}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
export declare function cmdRender(args: string[]): Promise<number>;
|
|
2
|
+
/**
|
|
3
|
+
* `burn` — bake each annotation into a copy of its screenshot, for surfaces that can't run the
|
|
4
|
+
* interactive viewer. The renderer lives in `@docsxai/viewer`; this runs its `burn` command.
|
|
5
|
+
*/
|
|
6
|
+
export declare function cmdBurn(args: string[]): Promise<number>;
|
|
2
7
|
export declare function cmdZip(args: string[]): Promise<number>;
|
|
3
8
|
export declare function cmdExport(args: string[]): Promise<number>;
|
|
4
9
|
export declare function cmdBaseline(args: string[]): Promise<number>;
|
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
// They read the rendered artifacts (flows/docs/screenshots) and emit something derived; none of
|
|
3
3
|
// them drive a live browser:
|
|
4
4
|
// render — build the static viewer by spawning the docsxai-viewer bin
|
|
5
|
+
// burn — bake the annotations into PNG copies by spawning the same bin
|
|
5
6
|
// zip — deterministic single-archive hand-off bundle
|
|
6
7
|
// export — project the doc pack to ADF (Confluence) or self-contained Playwright specs
|
|
7
8
|
// baseline — snapshot the doc pack into .baseline/ as the "before" for diff
|
|
8
9
|
// diff — drift report against a baseline (the after-vs-before)
|
|
9
|
-
import { spawn } from "node:child_process";
|
|
10
10
|
import { promises as fs } from "node:fs";
|
|
11
11
|
import * as path from "node:path";
|
|
12
12
|
import { FlowFileError } from "./flow-file.js";
|
|
13
13
|
import { diffDocPacks, formatDriftReportMarkdown, formatDriftReportText, severityAtLeast, } from "./diff.js";
|
|
14
14
|
import { projectDocPackToAdf } from "./export/adf.js";
|
|
15
15
|
import { exportWorkspaceFlowsAsPlaywrightTests } from "./export/playwright-test.js";
|
|
16
|
-
import {
|
|
16
|
+
import { runViewerBin } from "./viewer-bin.js";
|
|
17
17
|
import { ZipError, zipDocPack } from "./zip.js";
|
|
18
18
|
import { resolveWorkspacePath } from "./workspace.js";
|
|
19
19
|
import { parseFlags } from "./cli-shared.js";
|
|
@@ -27,28 +27,74 @@ export async function cmdRender(args) {
|
|
|
27
27
|
}
|
|
28
28
|
const docsDir = resolveWorkspacePath(projectDir, "docs");
|
|
29
29
|
const outDir = resolveWorkspacePath(projectDir, ".viewer");
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
30
|
+
const code = await runViewerBin("render", ["build", docsDir, outDir]);
|
|
31
|
+
if (code === 0) {
|
|
32
|
+
process.stdout.write(`render: open ${path.join(outDir, "index.html")} (the index links the flows; each flow page shows the screenshots — hover a pulsing halo to read its callout)\n`);
|
|
33
|
+
}
|
|
34
|
+
return code;
|
|
35
|
+
}
|
|
36
|
+
/** A flow name as `burn` passes it on: no separators, and no leading dot, so it can't name a parent or hidden path. */
|
|
37
|
+
const FLOW_NAME = /^[A-Za-z0-9_-][A-Za-z0-9._-]*$/;
|
|
38
|
+
/** Parse `burn`'s argv. Returns the usage-error message when the argv is malformed. */
|
|
39
|
+
function parseBurnArgs(args) {
|
|
40
|
+
const parsed = { workspace: "", flows: [], plainConnectors: false };
|
|
41
|
+
const positionals = [];
|
|
42
|
+
for (let i = 0; i < args.length; i++) {
|
|
43
|
+
const a = args[i];
|
|
44
|
+
if (a === "--no-connector-outline") {
|
|
45
|
+
parsed.plainConnectors = true;
|
|
46
|
+
}
|
|
47
|
+
else if (a === "--flow" || a === "--out" || a === "--report") {
|
|
48
|
+
const value = args[++i];
|
|
49
|
+
if (value === undefined || value.startsWith("--"))
|
|
50
|
+
return `${a} needs a value`;
|
|
51
|
+
if (a === "--flow")
|
|
52
|
+
parsed.flows.push(value);
|
|
53
|
+
else if (a === "--out")
|
|
54
|
+
parsed.out = value;
|
|
55
|
+
else
|
|
56
|
+
parsed.report = value;
|
|
57
|
+
}
|
|
58
|
+
else if (a.startsWith("--")) {
|
|
59
|
+
return `unknown flag ${a}`;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
positionals.push(a);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (positionals.length === 0)
|
|
66
|
+
return "missing <workspace-dir>";
|
|
67
|
+
if (positionals.length > 1)
|
|
68
|
+
return `unexpected argument "${positionals[1]}"`;
|
|
69
|
+
parsed.workspace = positionals[0];
|
|
70
|
+
const bad = parsed.flows.find((f) => !FLOW_NAME.test(f));
|
|
71
|
+
if (bad !== undefined)
|
|
72
|
+
return `--flow "${bad}" is not a flow name`;
|
|
73
|
+
return parsed;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* `burn` — bake each annotation into a copy of its screenshot, for surfaces that can't run the
|
|
77
|
+
* interactive viewer. The renderer lives in `@docsxai/viewer`; this runs its `burn` command.
|
|
78
|
+
*/
|
|
79
|
+
export async function cmdBurn(args) {
|
|
80
|
+
const parsed = parseBurnArgs(args);
|
|
81
|
+
if (typeof parsed === "string") {
|
|
82
|
+
process.stderr.write(`burn: ${parsed}\n\n${USAGE}\n`);
|
|
83
|
+
return 2;
|
|
84
|
+
}
|
|
85
|
+
const docsDir = resolveWorkspacePath(parsed.workspace, "docs");
|
|
86
|
+
if (!(await fs.stat(docsDir).then((s) => s.isDirectory(), () => false))) {
|
|
87
|
+
process.stderr.write(`burn: ${parsed.workspace} has no docs/ directory (expected ${docsDir}). Run \`docsxai run\` first.\n`);
|
|
88
|
+
return 1;
|
|
89
|
+
}
|
|
90
|
+
return runViewerBin("burn", [
|
|
91
|
+
"burn",
|
|
92
|
+
parsed.workspace,
|
|
93
|
+
...parsed.flows.flatMap((f) => ["--flow", f]),
|
|
94
|
+
...(parsed.out !== undefined ? ["--out", parsed.out] : []),
|
|
95
|
+
...(parsed.report !== undefined ? ["--report", parsed.report] : []),
|
|
96
|
+
...(parsed.plainConnectors ? ["--no-connector-outline"] : []),
|
|
97
|
+
]);
|
|
52
98
|
}
|
|
53
99
|
export async function cmdZip(args) {
|
|
54
100
|
const { positionals, flags } = parseFlags(args);
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// Screenshot-pack command — `pack` builds the hash-named, optimised PNG set plus manifest.json a
|
|
2
|
+
// docs site or README consumes, and `pack --check` rebuilds it in memory and compares it with the
|
|
3
|
+
// committed pack. The logic lives in `@docsxai/viewer` (it owns the burner); like `burn`, these
|
|
4
|
+
// validate the argv edge and run the viewer's command through the shared bin resolution, so the
|
|
5
|
+
// engine still does not depend on the viewer.
|
|
6
|
+
import { USAGE } from "./cli-usage.js";
|
|
7
|
+
import { runViewerBin } from "./viewer-bin.js";
|
|
8
|
+
/** Parse argv against a spec. Returns the argv to pass on (flags in the order given) or the usage-error message. */
|
|
9
|
+
function checkArgs(args, spec) {
|
|
10
|
+
const rest = [];
|
|
11
|
+
const positionals = [];
|
|
12
|
+
for (let i = 0; i < args.length; i++) {
|
|
13
|
+
const a = args[i];
|
|
14
|
+
if (spec.bare.includes(a)) {
|
|
15
|
+
rest.push(a);
|
|
16
|
+
}
|
|
17
|
+
else if (spec.valued.includes(a)) {
|
|
18
|
+
const value = args[++i];
|
|
19
|
+
if (value === undefined || value.startsWith("--"))
|
|
20
|
+
return `${a} needs a value`;
|
|
21
|
+
rest.push(a, value);
|
|
22
|
+
}
|
|
23
|
+
else if (a.startsWith("--")) {
|
|
24
|
+
return `unknown flag ${a}`;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
positionals.push(a);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (positionals.length === 0)
|
|
31
|
+
return "missing <workspace-or-raw-dir>";
|
|
32
|
+
if (positionals.length > 1)
|
|
33
|
+
return `unexpected argument "${positionals[1]}"`;
|
|
34
|
+
return { dir: positionals[0], rest };
|
|
35
|
+
}
|
|
36
|
+
function usageError(command, message) {
|
|
37
|
+
process.stderr.write(`${command}: ${message}\n\n${USAGE}\n`);
|
|
38
|
+
return 2;
|
|
39
|
+
}
|
|
40
|
+
/** `pack` — burn, optimise, hash-name and write the screenshot pack; with `--check`, compare instead of write. */
|
|
41
|
+
export async function cmdPack(args) {
|
|
42
|
+
if (args.includes("--check"))
|
|
43
|
+
return cmdPackCheck(args.filter((a) => a !== "--check"));
|
|
44
|
+
const parsed = checkArgs(args, {
|
|
45
|
+
valued: ["--out", "--public-prefix", "--generated-for"],
|
|
46
|
+
bare: ["--from-raw", "--no-optimise"],
|
|
47
|
+
});
|
|
48
|
+
if (typeof parsed === "string")
|
|
49
|
+
return usageError("pack", parsed);
|
|
50
|
+
return runViewerBin("pack", ["pack", parsed.dir, ...parsed.rest]);
|
|
51
|
+
}
|
|
52
|
+
/** `pack --check` — rebuild the pack in memory and compare it with the committed one. `args` has no `--check`. */
|
|
53
|
+
async function cmdPackCheck(args) {
|
|
54
|
+
const label = "pack --check";
|
|
55
|
+
const parsed = checkArgs(args, { valued: ["--against", "--threshold"], bare: ["--from-raw"] });
|
|
56
|
+
if (typeof parsed === "string")
|
|
57
|
+
return usageError(label, parsed);
|
|
58
|
+
const against = parsed.rest.indexOf("--against");
|
|
59
|
+
if (against === -1)
|
|
60
|
+
return usageError(label, "--against <pack-dir> is required");
|
|
61
|
+
const pct = parsed.rest.indexOf("--threshold");
|
|
62
|
+
if (pct !== -1) {
|
|
63
|
+
const value = Number(parsed.rest[pct + 1]);
|
|
64
|
+
if (!Number.isFinite(value) || value < 0) {
|
|
65
|
+
return usageError(label, "--threshold needs a percentage >= 0");
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return runViewerBin(label, ["pack", parsed.dir, "--check", ...parsed.rest]);
|
|
69
|
+
}
|