@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
|
@@ -2,14 +2,14 @@ import { type CaptureTrigger, type InstrumentedBrowser, type StorageState } from
|
|
|
2
2
|
/** Security-lowered Chromium args (see the module note). */
|
|
3
3
|
export declare const SECURITY_LOWERED_ARGS: readonly string[];
|
|
4
4
|
export interface PlaywrightInstrumentedBrowserOptions {
|
|
5
|
-
/** Headed by default (the human logs in there). Set true to run headless
|
|
5
|
+
/** Headed by default (the human logs in there). Set true to run headless, for automated tests only. (Ignored when attaching.) */
|
|
6
6
|
headless?: boolean;
|
|
7
7
|
/** Accept self-signed / invalid TLS certs (e.g. the target app's local HTTPS dev cert). Default: false. (Ignored when attaching.) */
|
|
8
8
|
ignoreHTTPSErrors?: boolean;
|
|
9
9
|
/** Extra Chromium args appended after {@link SECURITY_LOWERED_ARGS}. (Ignored when attaching.) */
|
|
10
10
|
extraArgs?: string[];
|
|
11
11
|
/**
|
|
12
|
-
* If set, launch with a **persistent profile** at this directory (a `userDataDir`)
|
|
12
|
+
* If set, launch with a **persistent profile** at this directory (a `userDataDir`), cookies, localStorage and
|
|
13
13
|
* login state survive between captures, so re-running `capture-auth` reuses the login instead of a fresh Chrome.
|
|
14
14
|
* `capture-auth` defaults this to `<workspace>/.auth/chrome-profile/` (gitignored, never leaves the machine).
|
|
15
15
|
* Mutually exclusive with `connectOverCdp` (attach short-circuits launching).
|
|
@@ -17,18 +17,18 @@ export interface PlaywrightInstrumentedBrowserOptions {
|
|
|
17
17
|
profileDir?: string;
|
|
18
18
|
/**
|
|
19
19
|
* If set, **attach to an already-running Chrome** at this CDP endpoint (e.g. `http://localhost:9222`) instead
|
|
20
|
-
* of launching a fresh one. Use this to capture from the *same* Chrome the engineer is already logged into
|
|
21
|
-
* and that Claude in Chrome is driving for discovery
|
|
20
|
+
* of launching a fresh one. Use this to capture from the *same* Chrome the engineer is already logged into,
|
|
21
|
+
* and that Claude in Chrome is driving for discovery, so they don't log in twice. Start that Chrome with
|
|
22
22
|
* `--remote-debugging-port=9222 --disable-web-security --disable-features=IsolateOrigins,site-per-process --user-data-dir=<dir>`.
|
|
23
|
-
* docsxai will **not** close it on `close()
|
|
23
|
+
* docsxai will **not** close it on `close()`, it's the engineer's session.
|
|
24
24
|
*/
|
|
25
25
|
connectOverCdp?: string;
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
28
|
* The injected page-side helper. Self-cleans when the Node-side binding is gone (which happens
|
|
29
|
-
* when the Playwright client detaches
|
|
29
|
+
* when the Playwright client detaches, e.g. `capture-auth` finishes and disconnects from a
|
|
30
30
|
* shared `--cdp` Chrome that stays alive). Without this guard, a stale `__docsxai.capture()`
|
|
31
|
-
* call after detach throws `Function "__docsxai_capture" is not exposed` in the page console
|
|
31
|
+
* call after detach throws `Function "__docsxai_capture" is not exposed` in the page console,
|
|
32
32
|
* cosmetic, but alarming to operators sharing the Chrome with another tool.
|
|
33
33
|
*
|
|
34
34
|
* Exported for unit-testing (run the returned script in a `vm` sandbox against a mock window).
|
|
@@ -40,11 +40,14 @@ export declare class PlaywrightInstrumentedBrowser implements InstrumentedBrowse
|
|
|
40
40
|
private context?;
|
|
41
41
|
private page?;
|
|
42
42
|
private attached;
|
|
43
|
+
/** An attached browser had no context, so this process created one and closes it. */
|
|
44
|
+
private ownsContext;
|
|
43
45
|
private persistent;
|
|
44
46
|
private captured;
|
|
45
47
|
private resolveCaptured;
|
|
46
48
|
constructor(opts?: PlaywrightInstrumentedBrowserOptions);
|
|
47
49
|
open(baseURL: string): Promise<void>;
|
|
50
|
+
private openBrowser;
|
|
48
51
|
waitForCapture(trigger: CaptureTrigger): Promise<void>;
|
|
49
52
|
storageState(): Promise<StorageState>;
|
|
50
53
|
close(): Promise<void>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
// Playwright-backed InstrumentedBrowser
|
|
1
|
+
// Playwright-backed InstrumentedBrowser, the security-lowered, instrumented Chrome `manual-capture` drives.
|
|
2
2
|
//
|
|
3
3
|
// The plugin spawns this; the engineer logs into the target site interactively (Azure AD SSO, MFA,
|
|
4
|
-
// conditional access
|
|
4
|
+
// conditional access, anything a human can click through); a console call `window.__docsxai.capture()`
|
|
5
5
|
// (or an injected on-page button) snapshots `storageState`. `--disable-web-security` etc. let the injected
|
|
6
|
-
// helper work across the SSO-redirect origins and relaxed CSP. Headed by default
|
|
6
|
+
// helper work across the SSO-redirect origins and relaxed CSP. Headed by default, the human needs to see it.
|
|
7
7
|
import { chromium } from "playwright-core";
|
|
8
8
|
/** Security-lowered Chromium args (see the module note). */
|
|
9
9
|
export const SECURITY_LOWERED_ARGS = [
|
|
@@ -14,9 +14,9 @@ export const SECURITY_LOWERED_ARGS = [
|
|
|
14
14
|
const CAPTURE_BINDING = "__docsxai_capture";
|
|
15
15
|
/**
|
|
16
16
|
* The injected page-side helper. Self-cleans when the Node-side binding is gone (which happens
|
|
17
|
-
* when the Playwright client detaches
|
|
17
|
+
* when the Playwright client detaches, e.g. `capture-auth` finishes and disconnects from a
|
|
18
18
|
* shared `--cdp` Chrome that stays alive). Without this guard, a stale `__docsxai.capture()`
|
|
19
|
-
* call after detach throws `Function "__docsxai_capture" is not exposed` in the page console
|
|
19
|
+
* call after detach throws `Function "__docsxai_capture" is not exposed` in the page console,
|
|
20
20
|
* cosmetic, but alarming to operators sharing the Chrome with another tool.
|
|
21
21
|
*
|
|
22
22
|
* Exported for unit-testing (run the returned script in a `vm` sandbox against a mock window).
|
|
@@ -57,6 +57,8 @@ export class PlaywrightInstrumentedBrowser {
|
|
|
57
57
|
context;
|
|
58
58
|
page;
|
|
59
59
|
attached = false;
|
|
60
|
+
/** An attached browser had no context, so this process created one and closes it. */
|
|
61
|
+
ownsContext = false;
|
|
60
62
|
persistent = false;
|
|
61
63
|
captured = Promise.resolve();
|
|
62
64
|
resolveCaptured = () => { };
|
|
@@ -64,15 +66,29 @@ export class PlaywrightInstrumentedBrowser {
|
|
|
64
66
|
this.opts = opts;
|
|
65
67
|
}
|
|
66
68
|
async open(baseURL) {
|
|
69
|
+
try {
|
|
70
|
+
await this.openBrowser(baseURL);
|
|
71
|
+
}
|
|
72
|
+
catch (e) {
|
|
73
|
+
// The caller never gets a browser to close, so release whatever was started.
|
|
74
|
+
await this.close();
|
|
75
|
+
throw e;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
async openBrowser(baseURL) {
|
|
67
79
|
this.captured = new Promise((resolve) => {
|
|
68
80
|
this.resolveCaptured = resolve;
|
|
69
81
|
});
|
|
70
82
|
if (this.opts.connectOverCdp) {
|
|
71
|
-
// Attach to an already-running Chrome
|
|
83
|
+
// Attach to an already-running Chrome, the engineer's, already logged in (and being driven by Claude
|
|
72
84
|
// in Chrome for discovery). One login, one browser. We never close it.
|
|
73
85
|
this.attached = true;
|
|
74
86
|
this.browser = await chromium.connectOverCDP(this.opts.connectOverCdp);
|
|
75
|
-
this.context = this.browser.contexts()[0]
|
|
87
|
+
this.context = this.browser.contexts()[0];
|
|
88
|
+
if (!this.context) {
|
|
89
|
+
this.context = await this.browser.newContext();
|
|
90
|
+
this.ownsContext = true;
|
|
91
|
+
}
|
|
76
92
|
await this.context.exposeFunction(CAPTURE_BINDING, () => {
|
|
77
93
|
this.resolveCaptured();
|
|
78
94
|
});
|
|
@@ -85,7 +101,7 @@ export class PlaywrightInstrumentedBrowser {
|
|
|
85
101
|
}
|
|
86
102
|
this.attached = false;
|
|
87
103
|
if (this.opts.profileDir) {
|
|
88
|
-
// Launch with a persistent profile
|
|
104
|
+
// Launch with a persistent profile, cookies/login survive between captures.
|
|
89
105
|
this.persistent = true;
|
|
90
106
|
this.context = await chromium.launchPersistentContext(this.opts.profileDir, {
|
|
91
107
|
headless: this.opts.headless ?? false,
|
|
@@ -169,13 +185,20 @@ export class PlaywrightInstrumentedBrowser {
|
|
|
169
185
|
}
|
|
170
186
|
async close() {
|
|
171
187
|
if (this.attached) {
|
|
172
|
-
// Don't touch the engineer's Chrome
|
|
173
|
-
//
|
|
174
|
-
//
|
|
175
|
-
// share the Chrome with
|
|
188
|
+
// Don't touch the engineer's Chrome: drop the connection and nothing else (a context this
|
|
189
|
+
// process created goes first). The injected `__docsxai` helper detects the backing binding
|
|
190
|
+
// is gone on its next invocation, removes its injected button if any, logs a friendly info
|
|
191
|
+
// message, and self-deletes from `window.__docsxai.capture`. Safe to share the Chrome with
|
|
192
|
+
// other automation clients.
|
|
193
|
+
const { browser, context, ownsContext } = this;
|
|
176
194
|
this.context = undefined;
|
|
177
195
|
this.browser = undefined;
|
|
178
196
|
this.page = undefined;
|
|
197
|
+
this.attached = false;
|
|
198
|
+
this.ownsContext = false;
|
|
199
|
+
if (ownsContext)
|
|
200
|
+
await context?.close().catch(() => undefined);
|
|
201
|
+
await browser?.close().catch(() => undefined);
|
|
179
202
|
return;
|
|
180
203
|
}
|
|
181
204
|
// For a persistent context, `context.close()` flushes the profile to disk and closes the browser.
|
package/dist/plugins/load.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export interface PluginRegisterApi {
|
|
|
12
12
|
registerLintRules(name: string, rules: PluginLintRule[]): void;
|
|
13
13
|
registerAuthStrategy(name: string, impl: AuthStrategyPlugin): void;
|
|
14
14
|
readonly log: PluginLogger;
|
|
15
|
-
/** Workspace-contained path resolution
|
|
15
|
+
/** Workspace-contained path resolution, the only filesystem root a plugin may write under. */
|
|
16
16
|
workspacePath(...segments: string[]): string;
|
|
17
17
|
}
|
|
18
18
|
/**
|
package/dist/plugins/load.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
// Plugin loading
|
|
1
|
+
// Plugin loading, the impure half of the runtime pipeline, and the SOLE place plugin code runs.
|
|
2
2
|
//
|
|
3
3
|
// Given a plan (survivors in topological order), this:
|
|
4
4
|
// 7. Capability subset check against the operator-enabled set (disables, not fatal).
|
|
5
5
|
// 8. Import each register module in topological order; call register(api) exactly once.
|
|
6
6
|
//
|
|
7
|
-
// Plugins are in-process Node modules
|
|
7
|
+
// Plugins are in-process Node modules, NOT sandboxed. Trust is a review signal, not a boundary.
|
|
8
8
|
// A register() failure rolls back that plugin's artifacts and lands as a load-error status.
|
|
9
9
|
// This is the only module that dynamically imports plugin modules and invokes register().
|
|
10
10
|
import { pathToFileURL } from "node:url";
|
|
@@ -25,7 +25,7 @@ export async function loadPlugins(opts, plan) {
|
|
|
25
25
|
const c = live.get(name);
|
|
26
26
|
const missing = c.manifest.capabilities.filter((cap) => !enabled.has(cap));
|
|
27
27
|
if (missing.length > 0) {
|
|
28
|
-
registry.commit(candidateRecord(c, "disabled-by-capability-mismatch", `plugin declares capabilities [${missing.join(", ")}] not enabled for this workspace
|
|
28
|
+
registry.commit(candidateRecord(c, "disabled-by-capability-mismatch", `plugin declares capabilities [${missing.join(", ")}] not enabled for this workspace; ` +
|
|
29
29
|
`add them to "plugin_capabilities" in .docsxai.json to opt in`));
|
|
30
30
|
continue;
|
|
31
31
|
}
|
|
@@ -38,7 +38,7 @@ export async function loadPlugins(opts, plan) {
|
|
|
38
38
|
const ARTIFACT_NAME = /^[a-z][a-z0-9-]*$/;
|
|
39
39
|
const qualify = (kind, bare, taken) => {
|
|
40
40
|
if (!c.manifest.kinds.includes(kind)) {
|
|
41
|
-
throw new Error(`plugin "${c.name}": registered a "${kind}" but the manifest's kinds are [${c.manifest.kinds.join(", ")}]
|
|
41
|
+
throw new Error(`plugin "${c.name}": registered a "${kind}" but the manifest's kinds are [${c.manifest.kinds.join(", ")}]; declare every extension point the plugin registers`);
|
|
42
42
|
}
|
|
43
43
|
if (!ARTIFACT_NAME.test(bare)) {
|
|
44
44
|
throw new Error(`plugin "${c.name}": artifact name "${bare}" must be bare kebab-case (the runtime prefixes "${ns}:")`);
|
package/dist/plugins/lock.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// plugins-lock.json + the plugin keys of `.docsxai.json`.
|
|
2
2
|
//
|
|
3
3
|
// The lock pins the sha256 of each plugin's register-module bytes. When the file exists, every
|
|
4
|
-
// resolve verifies the hash BEFORE importing
|
|
4
|
+
// resolve verifies the hash BEFORE importing, a silently-swapped module fails closed with a
|
|
5
5
|
// "run `docsxai plugins sync`" message. `docsxai plugins sync` (re)writes it without ever
|
|
6
6
|
// executing plugin code.
|
|
7
7
|
import { createHash } from "node:crypto";
|
|
@@ -19,7 +19,7 @@ export class PluginsLockError extends Error {
|
|
|
19
19
|
const lockSchema = z
|
|
20
20
|
.object({
|
|
21
21
|
schema: z.literal(PLUGINS_LOCK_SCHEMA),
|
|
22
|
-
plugins: z.record(z.object({ source: z.string(), version: z.string(), sha256: z.string() }).strict()),
|
|
22
|
+
plugins: z.record(z.string(), z.object({ source: z.string(), version: z.string(), sha256: z.string() }).strict()),
|
|
23
23
|
})
|
|
24
24
|
.strict();
|
|
25
25
|
export function sha256Hex(bytes) {
|
|
@@ -43,11 +43,11 @@ export async function readPluginsLock(workspaceDir) {
|
|
|
43
43
|
raw = JSON.parse(text);
|
|
44
44
|
}
|
|
45
45
|
catch {
|
|
46
|
-
throw new PluginsLockError(`${p} is not valid JSON
|
|
46
|
+
throw new PluginsLockError(`${p} is not valid JSON: fix or delete it, then run \`docsxai plugins sync\``);
|
|
47
47
|
}
|
|
48
48
|
const result = lockSchema.safeParse(raw);
|
|
49
49
|
if (!result.success) {
|
|
50
|
-
throw new PluginsLockError(`${p} does not match schema "${PLUGINS_LOCK_SCHEMA}"
|
|
50
|
+
throw new PluginsLockError(`${p} does not match schema "${PLUGINS_LOCK_SCHEMA}": delete it and run \`docsxai plugins sync\``);
|
|
51
51
|
}
|
|
52
52
|
return result.data;
|
|
53
53
|
}
|
|
@@ -68,15 +68,15 @@ export async function writePluginsLock(workspaceDir, lock) {
|
|
|
68
68
|
export function verifyLock(lock, namespace, registerBytes) {
|
|
69
69
|
const entry = lock.plugins[namespace];
|
|
70
70
|
if (!entry) {
|
|
71
|
-
return `plugin "${namespace}" is not in ${PLUGINS_LOCK_FILE}
|
|
71
|
+
return `plugin "${namespace}" is not in ${PLUGINS_LOCK_FILE}: run \`docsxai plugins sync\``;
|
|
72
72
|
}
|
|
73
73
|
if (registerBytes === null) {
|
|
74
|
-
return `plugin "${namespace}" register module is unreadable
|
|
74
|
+
return `plugin "${namespace}" register module is unreadable: reinstall it, then run \`docsxai plugins sync\``;
|
|
75
75
|
}
|
|
76
76
|
const actual = sha256Hex(registerBytes);
|
|
77
77
|
if (actual !== entry.sha256) {
|
|
78
78
|
return (`lock mismatch for plugin "${namespace}": register module sha256 ${actual} does not match ` +
|
|
79
|
-
`${PLUGINS_LOCK_FILE} (${entry.sha256})
|
|
79
|
+
`${PLUGINS_LOCK_FILE} (${entry.sha256}): if the change is intentional, run \`docsxai plugins sync\``);
|
|
80
80
|
}
|
|
81
81
|
return null;
|
|
82
82
|
}
|
|
@@ -116,7 +116,10 @@ export async function readWorkspacePluginsConfig(workspaceDir) {
|
|
|
116
116
|
const detail = result.error.issues
|
|
117
117
|
.map((i) => `${i.path.length ? i.path.join(".") + ": " : ""}${i.message}`)
|
|
118
118
|
.join("; ");
|
|
119
|
-
|
|
119
|
+
const shapes = result.error.issues.some((i) => i.path[0] === "plugins")
|
|
120
|
+
? '; each "plugins" entry is {"package": "<name>"} or {"path": "<dir>"}'
|
|
121
|
+
: "";
|
|
122
|
+
throw new PluginsConfigError(`${p}: invalid plugin configuration: ${detail}${shapes}`);
|
|
120
123
|
}
|
|
121
124
|
return { sources: result.data.plugins, capabilities: result.data.plugin_capabilities };
|
|
122
125
|
}
|
|
@@ -2,7 +2,7 @@ import { z } from "zod";
|
|
|
2
2
|
/** The plugin-runtime contract version this engine build advertises. */
|
|
3
3
|
export declare const RUNTIME_API_VERSION = "1.0.0";
|
|
4
4
|
/**
|
|
5
|
-
* Namespaces plugins can never claim
|
|
5
|
+
* Namespaces plugins can never claim, the engine's own surfaces live here.
|
|
6
6
|
* `site-docs` (the pre-rename CLI/product name) stays reserved defensively so a
|
|
7
7
|
* plugin can never squat the old identity.
|
|
8
8
|
*/
|
|
@@ -12,44 +12,25 @@ export type PluginKind = (typeof PLUGIN_KINDS)[number];
|
|
|
12
12
|
export type PluginTrust = "kalebtec" | "community" | "local";
|
|
13
13
|
declare const manifestSchema: z.ZodObject<{
|
|
14
14
|
apiVersion: z.ZodString;
|
|
15
|
-
namespace: z.
|
|
15
|
+
namespace: z.ZodString;
|
|
16
16
|
register: z.ZodString;
|
|
17
|
-
kinds: z.ZodArray<z.ZodEnum<
|
|
18
|
-
|
|
17
|
+
kinds: z.ZodArray<z.ZodEnum<{
|
|
18
|
+
publisher: "publisher";
|
|
19
|
+
renderer: "renderer";
|
|
20
|
+
"lint-rules": "lint-rules";
|
|
21
|
+
"auth-strategy": "auth-strategy";
|
|
22
|
+
}>>;
|
|
23
|
+
capabilities: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
19
24
|
dependsOn: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
20
25
|
plugin: z.ZodString;
|
|
21
26
|
version: z.ZodString;
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
trust: z.ZodDefault<z.ZodEnum<["kalebtec", "community", "local"]>>;
|
|
30
|
-
}, "strict", z.ZodTypeAny, {
|
|
31
|
-
capabilities: string[];
|
|
32
|
-
apiVersion: string;
|
|
33
|
-
namespace: string;
|
|
34
|
-
register: string;
|
|
35
|
-
kinds: ("publisher" | "renderer" | "lint-rules" | "auth-strategy")[];
|
|
36
|
-
dependsOn: {
|
|
37
|
-
version: string;
|
|
38
|
-
plugin: string;
|
|
39
|
-
}[];
|
|
40
|
-
trust: "local" | "kalebtec" | "community";
|
|
41
|
-
}, {
|
|
42
|
-
apiVersion: string;
|
|
43
|
-
namespace: string;
|
|
44
|
-
register: string;
|
|
45
|
-
kinds: ("publisher" | "renderer" | "lint-rules" | "auth-strategy")[];
|
|
46
|
-
capabilities?: string[] | undefined;
|
|
47
|
-
dependsOn?: {
|
|
48
|
-
version: string;
|
|
49
|
-
plugin: string;
|
|
50
|
-
}[] | undefined;
|
|
51
|
-
trust?: "local" | "kalebtec" | "community" | undefined;
|
|
52
|
-
}>;
|
|
27
|
+
}, z.core.$strict>>>;
|
|
28
|
+
trust: z.ZodDefault<z.ZodEnum<{
|
|
29
|
+
local: "local";
|
|
30
|
+
kalebtec: "kalebtec";
|
|
31
|
+
community: "community";
|
|
32
|
+
}>>;
|
|
33
|
+
}, z.core.$strict>;
|
|
53
34
|
export type PluginManifest = z.infer<typeof manifestSchema>;
|
|
54
35
|
export declare class PluginManifestError extends Error {
|
|
55
36
|
constructor(message: string);
|
package/dist/plugins/manifest.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// Plugin manifest: the `docsxai` field on a plugin package's package.json. Zod-validated; the
|
|
2
|
-
// rejections here are load-errors, not warnings
|
|
2
|
+
// rejections here are load-errors, not warnings, a plugin with a lying or malformed manifest
|
|
3
3
|
// never reaches `register()`.
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
/** The plugin-runtime contract version this engine build advertises. */
|
|
6
6
|
export const RUNTIME_API_VERSION = "1.0.0";
|
|
7
7
|
/**
|
|
8
|
-
* Namespaces plugins can never claim
|
|
8
|
+
* Namespaces plugins can never claim, the engine's own surfaces live here.
|
|
9
9
|
* `site-docs` (the pre-rename CLI/product name) stays reserved defensively so a
|
|
10
10
|
* plugin can never squat the old identity.
|
|
11
11
|
*/
|
|
@@ -28,7 +28,7 @@ const manifestSchema = z
|
|
|
28
28
|
.string()
|
|
29
29
|
.regex(NAMESPACE, "namespace must match /^[a-z][a-z0-9-]*$/ (kebab-case)")
|
|
30
30
|
.refine((ns) => !RESERVED_NAMESPACES.includes(ns), {
|
|
31
|
-
|
|
31
|
+
error: `namespace is reserved (${RESERVED_NAMESPACES.join(", ")})`,
|
|
32
32
|
}),
|
|
33
33
|
register: z.string().min(1, "register must be a relative path to the register module"),
|
|
34
34
|
kinds: z.array(z.enum(PLUGIN_KINDS)).min(1, "kinds must declare at least one extension point"),
|
|
@@ -52,14 +52,14 @@ export class PluginManifestError extends Error {
|
|
|
52
52
|
/** Validate the `docsxai` field of a plugin's package.json. Throws {@link PluginManifestError}. */
|
|
53
53
|
export function parsePluginManifest(raw, source) {
|
|
54
54
|
if (raw === undefined || raw === null) {
|
|
55
|
-
throw new PluginManifestError(`${source}: package.json has no "docsxai" field
|
|
55
|
+
throw new PluginManifestError(`${source}: package.json has no "docsxai" field, so it is not a plugin`);
|
|
56
56
|
}
|
|
57
57
|
const result = manifestSchema.safeParse(raw);
|
|
58
58
|
if (!result.success) {
|
|
59
59
|
const detail = result.error.issues
|
|
60
60
|
.map((i) => `${i.path.length ? i.path.join(".") + ": " : ""}${i.message}`)
|
|
61
61
|
.join("; ");
|
|
62
|
-
throw new PluginManifestError(`${source}: invalid "docsxai" manifest
|
|
62
|
+
throw new PluginManifestError(`${source}: invalid "docsxai" manifest: ${detail}`);
|
|
63
63
|
}
|
|
64
64
|
return result.data;
|
|
65
65
|
}
|
package/dist/plugins/plan.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ export interface ResolvePluginsOptions {
|
|
|
28
28
|
}
|
|
29
29
|
/** The deterministic output of planning: disabled records, plus survivors in load order. */
|
|
30
30
|
export interface PluginPlan {
|
|
31
|
-
/** Records for every rejected/disabled source
|
|
31
|
+
/** Records for every rejected/disabled source, committed before any plugin loads. */
|
|
32
32
|
disabled: PluginRecord[];
|
|
33
33
|
/** Surviving candidates keyed by package name, used by the load half. */
|
|
34
34
|
live: Map<string, ResolvedPluginSource>;
|
|
@@ -39,12 +39,12 @@ export interface PluginPlan {
|
|
|
39
39
|
export declare function candidateRecord(c: ResolvedPluginSource, status: PluginRecord["status"], reason?: string): PluginRecord;
|
|
40
40
|
/**
|
|
41
41
|
* Stage 1 only: resolve every source to a validated manifest (or a load-error record). Never
|
|
42
|
-
* imports plugin code
|
|
42
|
+
* imports plugin code, `docsxai plugins sync` pins hashes through this without executing
|
|
43
43
|
* anything.
|
|
44
44
|
*/
|
|
45
45
|
export declare function resolvePluginSources(workspaceDir: string, sources: ReadonlyArray<PluginSourceSpec>): Promise<PluginSourceResolution[]>;
|
|
46
46
|
/**
|
|
47
|
-
* Run the deterministic planning pipeline (stages 1
|
|
47
|
+
* Run the deterministic planning pipeline (stages 1-6) over the configured sources. Never imports
|
|
48
48
|
* plugin code; the surviving `loadOrder` is consumed by the load half, which performs the
|
|
49
49
|
* capability subset check and the actual import + register().
|
|
50
50
|
*/
|
package/dist/plugins/plan.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
// Plugin planning
|
|
1
|
+
// Plugin planning, the deterministic, code-free half of the runtime pipeline.
|
|
2
2
|
//
|
|
3
3
|
// Resolves every configured source to a validated manifest, then runs the ordering/rejection
|
|
4
|
-
// stages purely over manifest metadata
|
|
4
|
+
// stages purely over manifest metadata, NEVER importing or executing plugin code:
|
|
5
5
|
// 1. Resolve each source ({package} via Node resolution, {path} realpath'd) to a manifest.
|
|
6
6
|
// 2. Reject api-version-incompatible manifests (load-error, precise message).
|
|
7
7
|
// 3. Verify plugins-lock.json sha256 of the register-module bytes BEFORE the load half imports.
|
|
8
8
|
// 4. Namespace conflicts: every claimant of a contested namespace is disabled (deterministic).
|
|
9
|
-
// 5. dependsOn presence + version-range checks (fixpoint
|
|
9
|
+
// 5. dependsOn presence + version-range checks (fixpoint, a disabled dep disables dependents).
|
|
10
10
|
// 6. Tarjan-SCC cycle rejection: a cycle is refused as a unit, never partially loaded.
|
|
11
11
|
//
|
|
12
12
|
// The output is a plan: the disabled records, plus the surviving candidates in topological load
|
|
@@ -49,7 +49,7 @@ export function candidateRecord(c, status, reason) {
|
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
51
51
|
* Stage 1 only: resolve every source to a validated manifest (or a load-error record). Never
|
|
52
|
-
* imports plugin code
|
|
52
|
+
* imports plugin code, `docsxai plugins sync` pins hashes through this without executing
|
|
53
53
|
* anything.
|
|
54
54
|
*/
|
|
55
55
|
export async function resolvePluginSources(workspaceDir, sources) {
|
|
@@ -65,7 +65,7 @@ export async function resolvePluginSources(workspaceDir, sources) {
|
|
|
65
65
|
catch (e) {
|
|
66
66
|
out.push({
|
|
67
67
|
ok: false,
|
|
68
|
-
record: failureRecord(spec.package, label, `cannot resolve package "${spec.package}"
|
|
68
|
+
record: failureRecord(spec.package, label, `cannot resolve package "${spec.package}" (is it installed? ${e.message})`),
|
|
69
69
|
});
|
|
70
70
|
continue;
|
|
71
71
|
}
|
|
@@ -162,7 +162,7 @@ function tarjanSccs(nodes, edges) {
|
|
|
162
162
|
return sccs;
|
|
163
163
|
}
|
|
164
164
|
/**
|
|
165
|
-
* Run the deterministic planning pipeline (stages 1
|
|
165
|
+
* Run the deterministic planning pipeline (stages 1-6) over the configured sources. Never imports
|
|
166
166
|
* plugin code; the surviving `loadOrder` is consumed by the load half, which performs the
|
|
167
167
|
* capability subset check and the actual import + register().
|
|
168
168
|
*/
|
|
@@ -173,14 +173,14 @@ export async function planPlugins(opts) {
|
|
|
173
173
|
if (!r.ok)
|
|
174
174
|
disabled.push(r.record);
|
|
175
175
|
let candidates = resolutions.filter((r) => r.ok).map((r) => r.candidate);
|
|
176
|
-
// Duplicate package names break dep-graph identity
|
|
176
|
+
// Duplicate package names break dep-graph identity, refuse both, deterministically.
|
|
177
177
|
const byName = new Map();
|
|
178
178
|
for (const c of candidates)
|
|
179
179
|
byName.set(c.name, [...(byName.get(c.name) ?? []), c]);
|
|
180
180
|
for (const [name, group] of byName) {
|
|
181
181
|
if (group.length > 1) {
|
|
182
182
|
for (const c of group) {
|
|
183
|
-
disabled.push(candidateRecord(c, "load-error", `plugin package "${name}" is configured more than once (${group.map((g) => g.source).join(", ")})
|
|
183
|
+
disabled.push(candidateRecord(c, "load-error", `plugin package "${name}" is configured more than once (${group.map((g) => g.source).join(", ")}); remove the duplicate`));
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
186
|
}
|
|
@@ -190,10 +190,10 @@ export async function planPlugins(opts) {
|
|
|
190
190
|
if (isApiVersionCompatible(c.manifest.apiVersion))
|
|
191
191
|
return true;
|
|
192
192
|
disabled.push(candidateRecord(c, "load-error", `plugin apiVersion "${c.manifest.apiVersion}" is incompatible with the runtime apiVersion "${RUNTIME_API_VERSION}" ` +
|
|
193
|
-
`(requires same major and minor ≤ runtime)
|
|
193
|
+
`(requires same major and minor ≤ runtime); upgrade the plugin or the engine`));
|
|
194
194
|
return false;
|
|
195
195
|
});
|
|
196
|
-
// Lock verification
|
|
196
|
+
// Lock verification, BEFORE any import, so unverified bytes never execute.
|
|
197
197
|
if (opts.lock) {
|
|
198
198
|
const lock = opts.lock;
|
|
199
199
|
const verified = [];
|
|
@@ -213,7 +213,7 @@ export async function planPlugins(opts) {
|
|
|
213
213
|
}
|
|
214
214
|
candidates = verified;
|
|
215
215
|
}
|
|
216
|
-
// Namespace conflicts: every claimant disabled
|
|
216
|
+
// Namespace conflicts: every claimant disabled, load order must not pick winners.
|
|
217
217
|
const byNamespace = new Map();
|
|
218
218
|
for (const c of candidates) {
|
|
219
219
|
byNamespace.set(c.manifest.namespace, [...(byNamespace.get(c.manifest.namespace) ?? []), c]);
|
|
@@ -221,7 +221,7 @@ export async function planPlugins(opts) {
|
|
|
221
221
|
for (const [ns, group] of byNamespace) {
|
|
222
222
|
if (group.length > 1) {
|
|
223
223
|
for (const c of group) {
|
|
224
|
-
disabled.push(candidateRecord(c, "disabled-by-namespace-conflict", `namespace "${ns}" is claimed by ${group.map((g) => `"${g.name}"`).join(" and ")}
|
|
224
|
+
disabled.push(candidateRecord(c, "disabled-by-namespace-conflict", `namespace "${ns}" is claimed by ${group.map((g) => `"${g.name}"`).join(" and ")}; namespaces must be unique, so rename one`));
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
227
|
}
|
|
@@ -235,7 +235,7 @@ export async function planPlugins(opts) {
|
|
|
235
235
|
const target = live.get(dep.plugin);
|
|
236
236
|
let reason;
|
|
237
237
|
if (!target) {
|
|
238
|
-
reason = `dependsOn "${dep.plugin}" is not loadable
|
|
238
|
+
reason = `dependsOn "${dep.plugin}" is not loadable; configure it in the workspace "plugins" and ensure it resolves`;
|
|
239
239
|
}
|
|
240
240
|
else if (!satisfiesRange(target.version, dep.version)) {
|
|
241
241
|
reason = `dependsOn "${dep.plugin}" version ${target.version} does not satisfy the declared range "${dep.version}"`;
|
|
@@ -264,7 +264,7 @@ export async function planPlugins(opts) {
|
|
|
264
264
|
if (scc.length > 1 || selfLoop) {
|
|
265
265
|
const cycle = [...scc].sort();
|
|
266
266
|
for (const name of scc) {
|
|
267
|
-
disabled.push(candidateRecord(live.get(name), "disabled-by-cycle", `dependsOn cycle: ${cycle.join(" → ")} → ${cycle[0]}
|
|
267
|
+
disabled.push(candidateRecord(live.get(name), "disabled-by-cycle", `dependsOn cycle: ${cycle.join(" → ")} → ${cycle[0]}; break the cycle, none of its members load`));
|
|
268
268
|
live.delete(name);
|
|
269
269
|
}
|
|
270
270
|
}
|
|
@@ -43,7 +43,7 @@ export declare class PluginRegistry {
|
|
|
43
43
|
private readonly authStrategies;
|
|
44
44
|
private readonly lintRules;
|
|
45
45
|
constructor(workspaceDir: string);
|
|
46
|
-
/** Workspace-contained path resolution
|
|
46
|
+
/** Workspace-contained path resolution, the only filesystem root plugins may touch. */
|
|
47
47
|
workspacePath(...segments: string[]): string;
|
|
48
48
|
/** Runtime-facing: record a plugin's outcome (and, when loaded, its artifacts) atomically. */
|
|
49
49
|
commit(record: PluginRecord, artifacts?: RegisteredArtifacts): void;
|
package/dist/plugins/registry.js
CHANGED
|
@@ -19,7 +19,7 @@ export class PluginRegistry {
|
|
|
19
19
|
constructor(workspaceDir) {
|
|
20
20
|
this.workspaceDir = workspaceDir;
|
|
21
21
|
}
|
|
22
|
-
/** Workspace-contained path resolution
|
|
22
|
+
/** Workspace-contained path resolution, the only filesystem root plugins may touch. */
|
|
23
23
|
workspacePath(...segments) {
|
|
24
24
|
return resolveWorkspacePath(this.workspaceDir, ...segments);
|
|
25
25
|
}
|
package/dist/plugins/runtime.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Plugin runtime
|
|
1
|
+
// Plugin runtime, resolves the configured plugin set once per CLI invocation.
|
|
2
2
|
//
|
|
3
3
|
// This module is the orchestration barrel: it composes the two halves of the pipeline and
|
|
4
4
|
// re-exports their public surface. The split keeps the deterministic, code-free planning half
|
|
@@ -10,12 +10,12 @@
|
|
|
10
10
|
// 2. Reject api-version-incompatible manifests (load-error, precise message). │
|
|
11
11
|
// 3. Verify plugins-lock.json sha256 of the register-module bytes BEFORE importing. │ plan.ts
|
|
12
12
|
// 4. Namespace conflicts: every claimant of a contested namespace is disabled. │
|
|
13
|
-
// 5. dependsOn presence + version-range checks (fixpoint
|
|
13
|
+
// 5. dependsOn presence + version-range checks (fixpoint, a disabled dep disables deps). │
|
|
14
14
|
// 6. Tarjan-SCC cycle rejection: a cycle is refused as a unit, never partially loaded. ┘
|
|
15
15
|
// 7. Capability subset check against the operator-enabled set (disables, not fatal). ┐ load.ts
|
|
16
16
|
// 8. Import each register module in topological order; call register(api) exactly once. ┘
|
|
17
17
|
//
|
|
18
|
-
// Plugins are in-process Node modules
|
|
18
|
+
// Plugins are in-process Node modules, NOT sandboxed. Trust is a review signal, not a boundary.
|
|
19
19
|
// A register() failure rolls back that plugin's artifacts and lands as a load-error status.
|
|
20
20
|
import { planPlugins } from "./plan.js";
|
|
21
21
|
import { loadPlugins } from "./load.js";
|
package/dist/plugins/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { LintRule } from "../flow-lint.js";
|
|
2
|
-
/** Plugin-scoped logger. Writes to stderr prefixed `[plugin:<ns>]
|
|
2
|
+
/** Plugin-scoped logger. Writes to stderr prefixed `[plugin:<ns>]`, stdout stays clean for CLI output. */
|
|
3
3
|
export interface PluginLogger {
|
|
4
4
|
info(message: string): void;
|
|
5
5
|
warn(message: string): void;
|