@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
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
// Wire contracts for `@docsxai/backend
|
|
1
|
+
// Wire contracts for `@docsxai/backend`, the leaf shared by the transport, token, OAuth-login and
|
|
2
2
|
// state-cache siblings (`backend-client-*.ts`), re-exported in full from `./backend-client.js`.
|
|
3
3
|
//
|
|
4
4
|
// The contract types are *redeclared* here (not imported from the backend package) so the engine
|
|
5
|
-
// stays decoupled at the package level
|
|
5
|
+
// stays decoupled at the package level, there's no runtime nor build-time dep on the backend.
|
|
6
6
|
// Drift is caught by the round-trip integration test that spins up a real stub. The shapes mirror
|
|
7
7
|
// the backend's `api.ts` exactly; if you change one, update the other and the test will tell you.
|
|
8
8
|
export const API_VERSION = "1";
|
|
@@ -34,7 +34,7 @@ export async function oauthLogin(opts) {
|
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
36
36
|
res.writeHead(200, { "content-type": "text/plain" });
|
|
37
|
-
res.end("docsxai login complete
|
|
37
|
+
res.end("docsxai login complete, you can close this tab.\n");
|
|
38
38
|
resolveCode(gotCode);
|
|
39
39
|
});
|
|
40
40
|
const port = await new Promise((resolve, reject) => {
|
|
@@ -36,14 +36,14 @@ export interface BackendStateCacheOptions {
|
|
|
36
36
|
baseUrl: string;
|
|
37
37
|
token: string;
|
|
38
38
|
workspaceId: string;
|
|
39
|
-
/** Base64-encoded 32-byte AES key
|
|
39
|
+
/** Base64-encoded 32-byte AES key, the resolved value of `DOCSX_CACHE_KEY`. */
|
|
40
40
|
cacheKey: string;
|
|
41
41
|
fetch?: typeof globalThis.fetch;
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
44
|
* Backend-relayed storage-state cache. Same `load` / `save` / `clear` contract as the local
|
|
45
45
|
* `.auth/<role>.json` cache (incl. the expiry-priority rules), but the entry lives on the backend
|
|
46
|
-
* as a client-side-encrypted envelope
|
|
46
|
+
* as a client-side-encrypted envelope, usable by a team sharing one backend, opaque to the server.
|
|
47
47
|
*/
|
|
48
48
|
export declare class BackendStateCache {
|
|
49
49
|
private readonly baseUrl;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
//
|
|
3
3
|
// Client-side encryption: the backend stores an opaque AES-256-GCM envelope and never sees the
|
|
4
4
|
// plaintext session. The shapes below are structural mirrors of the engine's auth layer
|
|
5
|
-
// (`StorageState` / `AuthResult` / `RoleAuth.cache`)
|
|
5
|
+
// (`StorageState` / `AuthResult` / `RoleAuth.cache`), deliberately not imported from auth.ts so
|
|
6
6
|
// the modules stay decoupled; the auth layer satisfies them structurally.
|
|
7
7
|
//
|
|
8
8
|
// NOTE: the ttl-to-ms / cookie-expiry math here is the same shape that also lives in
|
|
@@ -36,7 +36,7 @@ function ttlToMs(ttl) {
|
|
|
36
36
|
return n * 3_600_000;
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
/** Expiry (epoch ms) of the cookie named `name
|
|
39
|
+
/** Expiry (epoch ms) of the cookie named `name`, the latest if several; `undefined` if absent or session-only. */
|
|
40
40
|
function cookieExpiryByName(state, name) {
|
|
41
41
|
const expiries = state.cookies
|
|
42
42
|
.filter((c) => c.name === name && typeof c.expires === "number" && c.expires > 0)
|
|
@@ -46,7 +46,7 @@ function cookieExpiryByName(state, name) {
|
|
|
46
46
|
/**
|
|
47
47
|
* Backend-relayed storage-state cache. Same `load` / `save` / `clear` contract as the local
|
|
48
48
|
* `.auth/<role>.json` cache (incl. the expiry-priority rules), but the entry lives on the backend
|
|
49
|
-
* as a client-side-encrypted envelope
|
|
49
|
+
* as a client-side-encrypted envelope, usable by a team sharing one backend, opaque to the server.
|
|
50
50
|
*/
|
|
51
51
|
export class BackendStateCache {
|
|
52
52
|
baseUrl;
|
|
@@ -56,11 +56,11 @@ export class BackendStateCache {
|
|
|
56
56
|
doFetch;
|
|
57
57
|
constructor(opts) {
|
|
58
58
|
if (!opts.cacheKey) {
|
|
59
|
-
throw new BackendStateCacheError("missing cache key
|
|
59
|
+
throw new BackendStateCacheError("missing cache key: set DOCSX_CACHE_KEY to a base64-encoded 32-byte key");
|
|
60
60
|
}
|
|
61
61
|
const key = Buffer.from(opts.cacheKey, "base64");
|
|
62
62
|
if (key.length !== 32) {
|
|
63
|
-
throw new BackendStateCacheError(`malformed cache key
|
|
63
|
+
throw new BackendStateCacheError(`malformed cache key: DOCSX_CACHE_KEY must decode to exactly 32 bytes (got ${key.length})`);
|
|
64
64
|
}
|
|
65
65
|
this.baseUrl = opts.baseUrl.replace(/\/+$/, "");
|
|
66
66
|
this.token = opts.token;
|
|
@@ -109,7 +109,7 @@ export class BackendStateCache {
|
|
|
109
109
|
}
|
|
110
110
|
else if (authCookieName) {
|
|
111
111
|
expiresAt = typeof ttlMs === "number" ? now + ttlMs : now + 3_600_000;
|
|
112
|
-
source = `ttl (fallback
|
|
112
|
+
source = `ttl (fallback: auth-cookie "${authCookieName}" not in the jar or has no expiry)`;
|
|
113
113
|
}
|
|
114
114
|
else if (typeof ttlMs === "number") {
|
|
115
115
|
expiresAt = now + ttlMs;
|
|
@@ -121,7 +121,7 @@ export class BackendStateCache {
|
|
|
121
121
|
source = reported ? "strategy-reported expiresAt" : "1h default";
|
|
122
122
|
}
|
|
123
123
|
if (expiresAt <= now) {
|
|
124
|
-
throw new BackendStateCacheError(`computed cache expiry (${new Date(expiresAt).toISOString()}, from ${source}) is not in the future
|
|
124
|
+
throw new BackendStateCacheError(`computed cache expiry (${new Date(expiresAt).toISOString()}, from ${source}) is not in the future; refusing to cache a dead session`);
|
|
125
125
|
}
|
|
126
126
|
const entry = { storageState: result.storageState, writtenAt: now, expiresAt };
|
|
127
127
|
const envelope = {
|
|
@@ -179,7 +179,7 @@ export class BackendStateCache {
|
|
|
179
179
|
]).toString("utf8");
|
|
180
180
|
}
|
|
181
181
|
catch {
|
|
182
|
-
throw new BackendStateCacheError("auth-cache decryption failed
|
|
182
|
+
throw new BackendStateCacheError("auth-cache decryption failed: wrong DOCSX_CACHE_KEY or tampered ciphertext");
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
185
|
}
|
|
@@ -56,16 +56,16 @@ export async function resolveBackendToken(opts) {
|
|
|
56
56
|
return process.env.DOCSX_TOKEN;
|
|
57
57
|
const reloginHint = `set DOCSX_TOKEN or run \`docsxai login --backend-url ${shellQuote(redactUrl(opts.baseUrl))} --oauth <workspace-dir>\``;
|
|
58
58
|
if (!opts.workspaceDir) {
|
|
59
|
-
throw new BackendClientError(`no bearer token
|
|
59
|
+
throw new BackendClientError(`no bearer token: ${reloginHint}`);
|
|
60
60
|
}
|
|
61
61
|
const stored = await loadBackendTokenFile(opts.workspaceDir);
|
|
62
62
|
if (!stored) {
|
|
63
|
-
throw new BackendClientError(`no bearer token
|
|
63
|
+
throw new BackendClientError(`no bearer token: ${reloginHint}`);
|
|
64
64
|
}
|
|
65
65
|
const now = opts.now ?? Date.now();
|
|
66
66
|
if (stored.expires_at > now + 30_000)
|
|
67
67
|
return stored.access_token;
|
|
68
|
-
// Expired (or about to)
|
|
68
|
+
// Expired (or about to), attempt a refresh-token rotation.
|
|
69
69
|
const doFetch = opts.fetch ?? globalThis.fetch;
|
|
70
70
|
const base = opts.baseUrl.replace(/\/+$/, "");
|
|
71
71
|
let refreshed;
|
|
@@ -83,7 +83,7 @@ export async function resolveBackendToken(opts) {
|
|
|
83
83
|
refreshed = (await res.json());
|
|
84
84
|
}
|
|
85
85
|
catch (e) {
|
|
86
|
-
throw new BackendClientError(`stored backend token expired and the refresh failed (${redactUrlsIn(e.message)})
|
|
86
|
+
throw new BackendClientError(`stored backend token expired and the refresh failed (${redactUrlsIn(e.message)}): ${reloginHint}`);
|
|
87
87
|
}
|
|
88
88
|
const tokens = {
|
|
89
89
|
access_token: refreshed.access_token,
|
|
@@ -36,7 +36,7 @@ export declare class BackendClient {
|
|
|
36
36
|
listRuns(wsId: string, projectId: string): Promise<RunRecord[]>;
|
|
37
37
|
/** Upload raw bytes; the backend stores them under their sha256. Idempotent. */
|
|
38
38
|
putBlob(data: Uint8Array): Promise<BlobRef>;
|
|
39
|
-
/** HEAD-probe a blob
|
|
39
|
+
/** HEAD-probe a blob, true when the backend already has these bytes. */
|
|
40
40
|
hasBlob(sha256: string): Promise<boolean>;
|
|
41
41
|
getBlob(sha256: string): Promise<Uint8Array>;
|
|
42
42
|
}
|
|
@@ -46,7 +46,7 @@ export declare function createBackendClient(opts: BackendClientOptions & {
|
|
|
46
46
|
}): Promise<BackendClient>;
|
|
47
47
|
/**
|
|
48
48
|
* Append an execution-run record for a backend-bound workspace. A no-op when the workspace config
|
|
49
|
-
* lacks the backend binding; never throws
|
|
49
|
+
* lacks the backend binding; never throws, `docsxai run` must stay offline-tolerant, so failures
|
|
50
50
|
* come back as a warning string for the caller to surface.
|
|
51
51
|
*/
|
|
52
52
|
export declare function recordRunHistory(opts: {
|
|
@@ -14,7 +14,7 @@ export class BackendClient {
|
|
|
14
14
|
this.token = opts.token ?? process.env.DOCSX_TOKEN ?? "";
|
|
15
15
|
this.doFetch = opts.fetch ?? globalThis.fetch;
|
|
16
16
|
if (!this.token) {
|
|
17
|
-
throw new BackendClientError("no bearer token
|
|
17
|
+
throw new BackendClientError("no bearer token: set DOCSX_TOKEN env var or pass `token`. Run `docsxai login` to validate.");
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
headers(extra) {
|
|
@@ -116,7 +116,7 @@ export class BackendClient {
|
|
|
116
116
|
}
|
|
117
117
|
return (await res.json());
|
|
118
118
|
}
|
|
119
|
-
/** HEAD-probe a blob
|
|
119
|
+
/** HEAD-probe a blob, true when the backend already has these bytes. */
|
|
120
120
|
async hasBlob(sha256) {
|
|
121
121
|
const res = await this.doFetch(`${this.baseUrl}/v1/blobs/${encodeURIComponent(sha256)}`, {
|
|
122
122
|
method: "HEAD",
|
|
@@ -154,7 +154,7 @@ export async function createBackendClient(opts) {
|
|
|
154
154
|
// --- run-history wiring (`docsxai run`) -------------------------------------
|
|
155
155
|
/**
|
|
156
156
|
* Append an execution-run record for a backend-bound workspace. A no-op when the workspace config
|
|
157
|
-
* lacks the backend binding; never throws
|
|
157
|
+
* lacks the backend binding; never throws, `docsxai run` must stay offline-tolerant, so failures
|
|
158
158
|
* come back as a warning string for the caller to surface.
|
|
159
159
|
*/
|
|
160
160
|
export async function recordRunHistory(opts) {
|
package/dist/backend-client.js
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
//
|
|
3
3
|
// Barrel: the implementation lives in flat siblings, split by reason-to-change. This file preserves
|
|
4
4
|
// the original public surface so `./backend-client.js` importers (and colocated tests) don't move.
|
|
5
|
-
// • backend-client-contracts.ts
|
|
6
|
-
// • backend-client-transport.ts
|
|
7
|
-
// • backend-client-token.ts
|
|
8
|
-
// • backend-client-oauth-login.ts
|
|
9
|
-
// • backend-client-state-cache.ts
|
|
5
|
+
// • backend-client-contracts.ts: wire DTOs / payloads / error class / option shapes (the leaf)
|
|
6
|
+
// • backend-client-transport.ts: the REST `BackendClient` + `createBackendClient` + run history
|
|
7
|
+
// • backend-client-token.ts: stored-token file + bearer-token resolution / refresh
|
|
8
|
+
// • backend-client-oauth-login.ts: the OAuth 2.1 + PKCE login flow
|
|
9
|
+
// • backend-client-state-cache.ts: the AES-256-GCM `BackendStateCache` relay
|
|
10
10
|
//
|
|
11
11
|
// The contract types are *redeclared* in the contracts leaf (not imported from the backend package)
|
|
12
|
-
// so the engine stays decoupled at the package level
|
|
12
|
+
// so the engine stays decoupled at the package level, there's no runtime nor build-time dep on the
|
|
13
13
|
// backend. Drift is caught by the round-trip integration test that spins up a real stub.
|
|
14
14
|
export * from "./backend-client-contracts.js";
|
|
15
15
|
export * from "./backend-client-transport.js";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// The browser build a run captured with, for `browser_build` in annotations.json. Screenshots are
|
|
2
|
+
// byte-identical per docsxai and browser build, so the build is worth keeping next to them.
|
|
3
|
+
/** `Chromium <version>` from what the session's browser reports, or undefined when it reports none. */
|
|
4
|
+
export function browserBuildOf(session) {
|
|
5
|
+
try {
|
|
6
|
+
const version = session.browser?.version?.();
|
|
7
|
+
return version ? `Chromium ${version}`.slice(0, 100) : undefined;
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** The command that installs the Chromium binary Playwright looks for. */
|
|
2
|
+
export declare const CHROMIUM_INSTALL = "npx playwright-core install chromium";
|
|
3
|
+
/** The start of the reason `describeBrowserLaunch` gives for a refused `--cdp` endpoint. */
|
|
4
|
+
export declare const CDP_UNREACHABLE = "cannot attach to the browser at";
|
|
5
|
+
export interface BrowserLaunchProblem {
|
|
6
|
+
/** One line: what failed and why. */
|
|
7
|
+
reason: string;
|
|
8
|
+
/** The command to run next, when the cause is one the operator can fix. */
|
|
9
|
+
next?: string;
|
|
10
|
+
}
|
|
11
|
+
/** Explain a launch or attach error from Playwright. `cdp` is the `--cdp` endpoint when one was given. */
|
|
12
|
+
export declare function describeBrowserLaunch(raw: string, cdp?: string): BrowserLaunchProblem;
|
|
13
|
+
/**
|
|
14
|
+
* Why `page.goto(url)` failed, in one line: the address (without user:password or query), the
|
|
15
|
+
* network error code and what to change. Playwright's `page.goto:` prefix, call log and repeated
|
|
16
|
+
* URL are dropped. `inspect` prints it as a warning.
|
|
17
|
+
*/
|
|
18
|
+
export declare function describePageLoad(raw: string, url: string): string;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// What a browser that would not start looks like to the operator. Playwright's own text carries a
|
|
2
|
+
// banner, a call log and a bare `browserType.launch...` prefix; this turns the three causes an
|
|
3
|
+
// operator can fix (no Chromium binary, a `--cdp` endpoint nobody listens on, a file where the
|
|
4
|
+
// profile directory goes) into a reason plus the command to run next. Any other launch error keeps Playwright's wording. Leaf module.
|
|
5
|
+
import { notDirectoryProblem, redactUrl, sanitizeForTerminal } from "./cli-messages.js";
|
|
6
|
+
const MISSING_BINARY = /Executable doesn't exist|playwright install/i;
|
|
7
|
+
/** Playwright's text for a profile directory it cannot make because a file is in the way. */
|
|
8
|
+
const NOT_A_DIRECTORY = /ENOTDIR: not a directory, \w+ '([^'\n]+)'/;
|
|
9
|
+
/** The command that installs the Chromium binary Playwright looks for. */
|
|
10
|
+
export const CHROMIUM_INSTALL = "npx playwright-core install chromium";
|
|
11
|
+
/** The start of the reason `describeBrowserLaunch` gives for a refused `--cdp` endpoint. */
|
|
12
|
+
export const CDP_UNREACHABLE = "cannot attach to the browser at";
|
|
13
|
+
/** The port of a `--cdp` endpoint, for the Chrome flag in the hint. */
|
|
14
|
+
function cdpPort(endpoint) {
|
|
15
|
+
try {
|
|
16
|
+
return new URL(endpoint).port || "9222";
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return "9222";
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** Explain a launch or attach error from Playwright. `cdp` is the `--cdp` endpoint when one was given. */
|
|
23
|
+
export function describeBrowserLaunch(raw, cdp) {
|
|
24
|
+
if (cdp !== undefined && /connectOverCDP/.test(raw)) {
|
|
25
|
+
const code = /\b(ECONNREFUSED|ENOTFOUND|ETIMEDOUT|ECONNRESET)\b/.exec(raw)?.[1];
|
|
26
|
+
const first = sanitizeForTerminal(raw.split("\n")[0] ?? "");
|
|
27
|
+
return {
|
|
28
|
+
reason: `${CDP_UNREACHABLE} ${redactUrl(cdp)} (${code ?? first}); --cdp needs a running Chrome`,
|
|
29
|
+
next: `start Chrome with --remote-debugging-port=${cdpPort(cdp)}, then rerun the command`,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
if (MISSING_BINARY.test(raw)) {
|
|
33
|
+
return {
|
|
34
|
+
reason: "no Chromium binary found",
|
|
35
|
+
next: `${CHROMIUM_INSTALL}, then rerun the command`,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const blocked = NOT_A_DIRECTORY.exec(raw)?.[1];
|
|
39
|
+
if (blocked !== undefined)
|
|
40
|
+
return notDirectoryProblem(blocked);
|
|
41
|
+
return { reason: `failed to launch browser: ${sanitizeForTerminal(raw, true)}` };
|
|
42
|
+
}
|
|
43
|
+
const NET_ERROR = /net::(ERR_[A-Z_]+)/;
|
|
44
|
+
const UNREACHABLE = /^ERR_(?:CONNECTION_(?:REFUSED|RESET|TIMED_OUT)|NAME_NOT_RESOLVED|ADDRESS_UNREACHABLE|INTERNET_DISCONNECTED)$/;
|
|
45
|
+
/**
|
|
46
|
+
* Why `page.goto(url)` failed, in one line: the address (without user:password or query), the
|
|
47
|
+
* network error code and what to change. Playwright's `page.goto:` prefix, call log and repeated
|
|
48
|
+
* URL are dropped. `inspect` prints it as a warning.
|
|
49
|
+
*/
|
|
50
|
+
export function describePageLoad(raw, url) {
|
|
51
|
+
const where = redactUrl(url);
|
|
52
|
+
const code = NET_ERROR.exec(raw)?.[1];
|
|
53
|
+
if (code !== undefined && UNREACHABLE.test(code)) {
|
|
54
|
+
return `could not load ${where} (net::${code}): the app did not answer; start it, or fix --url or app_url in .docsxai.json`;
|
|
55
|
+
}
|
|
56
|
+
if (code !== undefined && /^ERR_(?:CERT|SSL)_/.test(code)) {
|
|
57
|
+
return `could not load ${where} (net::${code}): the TLS certificate was rejected; pass --ignore-https-errors`;
|
|
58
|
+
}
|
|
59
|
+
const first = sanitizeForTerminal(raw.split("\n")[0] ?? "")
|
|
60
|
+
.replace(/^page\.goto: /, "")
|
|
61
|
+
.replace(/ at https?:\/\/\S+$/, "");
|
|
62
|
+
return `could not load ${where}: ${first}; is the app running?`;
|
|
63
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** The part of a Playwright `Browser` the wait needs. */
|
|
2
|
+
export interface DisconnectableBrowser {
|
|
3
|
+
isConnected(): boolean;
|
|
4
|
+
on(event: "disconnected", listener: () => void): unknown;
|
|
5
|
+
}
|
|
6
|
+
/** Resolve when `browser` disconnects, or at once when it already has. */
|
|
7
|
+
export declare function waitForBrowserClose(browser: DisconnectableBrowser): Promise<void>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Wait for the operator to close a headed browser (`run --pause`, `inspect --headed`). The browser
|
|
2
|
+
// emits `disconnected` once, so a browser that is already gone (closed during the last step) would
|
|
3
|
+
// never wake a wait that only listens for the event.
|
|
4
|
+
/** Resolve when `browser` disconnects, or at once when it already has. */
|
|
5
|
+
export function waitForBrowserClose(browser) {
|
|
6
|
+
return new Promise((resolve) => {
|
|
7
|
+
// Listen first, then check: a close between the two still resolves.
|
|
8
|
+
browser.on("disconnected", () => resolve());
|
|
9
|
+
if (!browser.isConnected())
|
|
10
|
+
resolve();
|
|
11
|
+
});
|
|
12
|
+
}
|
package/dist/calibrate.d.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { type FlowFile } from "./doc-pack.js";
|
|
2
2
|
export declare class CalibrateError extends Error {
|
|
3
3
|
readonly cause?: unknown | undefined;
|
|
4
|
-
|
|
4
|
+
/** `"name-flag"` when the `--name` the operator passed is the problem, so the fix is not in the guide. */
|
|
5
|
+
readonly field?: "name-flag" | undefined;
|
|
6
|
+
constructor(message: string, cause?: unknown | undefined,
|
|
7
|
+
/** `"name-flag"` when the `--name` the operator passed is the problem, so the fix is not in the guide. */
|
|
8
|
+
field?: "name-flag" | undefined);
|
|
5
9
|
}
|
|
6
10
|
/**
|
|
7
11
|
* Extract a flow-file from a structured flow-guide. Accepts: the YAML of a flow-file directly, or a Markdown
|
|
8
12
|
* doc whose first ```yaml fenced block parses as one. Throws {@link CalibrateError} if neither works (which is
|
|
9
|
-
* the signal that the input is loose prose → use the
|
|
13
|
+
* the signal that the input is loose prose → use the add-flow skill / agent path instead).
|
|
10
14
|
*/
|
|
11
15
|
export declare function extractFlowFile(text: string, source?: string): FlowFile;
|
|
12
16
|
export interface CalibrateOptions {
|
package/dist/calibrate.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
// Calibration
|
|
1
|
+
// Calibration: the deterministic, structured-input path.
|
|
2
2
|
//
|
|
3
|
-
// `docsxai
|
|
3
|
+
// `docsxai add-flow <workspace> --from <flow.md|.yaml>` takes a *structured flow-guide*, a flow-file in
|
|
4
4
|
// YAML, or a Markdown doc containing a ```yaml fenced block that parses as one (the the first-consumer testing guide
|
|
5
|
-
// shape: prerequisites + locators reference + per-step actions + success criteria)
|
|
5
|
+
// shape: prerequisites + locators reference + per-step actions + success criteria), and writes it as
|
|
6
6
|
// `<workspace>/flows/<name>.flow.yaml`, plus a default `docs/style.yaml` if absent. Then `docsxai run`
|
|
7
7
|
// exercises it against the live app to fill in screenshots + bounding boxes + the real `annotations.json`.
|
|
8
8
|
//
|
|
9
|
-
// Loose-prose flow descriptions (and live element-picking / ambiguity resolution) need the host agent
|
|
10
|
-
// that's the `/docsxai:
|
|
9
|
+
// Loose-prose flow descriptions (and live element-picking / ambiguity resolution) need the host agent,
|
|
10
|
+
// that's the `/docsxai:add-flow` *skill* (see packages/plugin/skills/add-flow/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
13
|
import { FlowName } from "./doc-pack.js";
|
|
@@ -16,9 +16,13 @@ import { initStyleIfAbsent } from "./style.js";
|
|
|
16
16
|
import { resolveWorkspacePath, resolveWorkspacePathReal } from "./workspace.js";
|
|
17
17
|
export class CalibrateError extends Error {
|
|
18
18
|
cause;
|
|
19
|
-
|
|
19
|
+
field;
|
|
20
|
+
constructor(message, cause,
|
|
21
|
+
/** `"name-flag"` when the `--name` the operator passed is the problem, so the fix is not in the guide. */
|
|
22
|
+
field) {
|
|
20
23
|
super(message);
|
|
21
24
|
this.cause = cause;
|
|
25
|
+
this.field = field;
|
|
22
26
|
this.name = "CalibrateError";
|
|
23
27
|
}
|
|
24
28
|
}
|
|
@@ -26,7 +30,7 @@ const YAML_FENCE = /```ya?ml\s*\n([\s\S]*?)\n```/i;
|
|
|
26
30
|
/**
|
|
27
31
|
* Extract a flow-file from a structured flow-guide. Accepts: the YAML of a flow-file directly, or a Markdown
|
|
28
32
|
* doc whose first ```yaml fenced block parses as one. Throws {@link CalibrateError} if neither works (which is
|
|
29
|
-
* the signal that the input is loose prose → use the
|
|
33
|
+
* the signal that the input is loose prose → use the add-flow skill / agent path instead).
|
|
30
34
|
*/
|
|
31
35
|
export function extractFlowFile(text, source = "<flow-guide>") {
|
|
32
36
|
// 1. The whole text as flow-file YAML.
|
|
@@ -36,6 +40,9 @@ export function extractFlowFile(text, source = "<flow-guide>") {
|
|
|
36
40
|
catch (e) {
|
|
37
41
|
if (!(e instanceof FlowFileError))
|
|
38
42
|
throw e;
|
|
43
|
+
// A `.yaml` file is a flow-file, not a guide: its own error names the field or the line.
|
|
44
|
+
if (/\.ya?ml$/i.test(source))
|
|
45
|
+
throw new CalibrateError(e.message, e);
|
|
39
46
|
}
|
|
40
47
|
// 2. A ```yaml fenced block.
|
|
41
48
|
const m = YAML_FENCE.exec(text);
|
|
@@ -51,10 +58,10 @@ export function extractFlowFile(text, source = "<flow-guide>") {
|
|
|
51
58
|
}
|
|
52
59
|
}
|
|
53
60
|
throw new CalibrateError(`${source}: not a structured flow-guide (no parseable flow-file YAML found).\n` +
|
|
54
|
-
`\`
|
|
55
|
-
`Loose prose
|
|
56
|
-
`to *test
|
|
57
|
-
`(walk the live app via Claude in Chrome, pin one canonical locator per step), then \`
|
|
61
|
+
`\`add-flow --from\` only takes a flow-file in YAML, or a Markdown doc with a \`\`\`yaml fenced block that *is* one.\n` +
|
|
62
|
+
`Loose prose (a hand-written test guide whose fenced blocks are numbered prose pseudo-steps for an agent\n` +
|
|
63
|
+
`to *test*, not flow-file YAML) must be turned into a flow-file by hand: follow the /docsxai:add-flow skill\n` +
|
|
64
|
+
`(walk the live app via Claude in Chrome, pin one canonical locator per step), then \`add-flow --from\` it or just \`run\`.`);
|
|
58
65
|
}
|
|
59
66
|
/** Run the deterministic calibration step: extract the flow-file from a structured guide, write it + a default style. */
|
|
60
67
|
export async function calibrate(opts) {
|
|
@@ -62,10 +69,10 @@ export async function calibrate(opts) {
|
|
|
62
69
|
const name = opts.flowName ?? flow.name;
|
|
63
70
|
const checked = FlowName.safeParse(name);
|
|
64
71
|
if (!checked.success) {
|
|
65
|
-
throw new CalibrateError(`flow name "${name}" is not usable: ${checked.error.issues.map((i) => i.message).join("; ")}
|
|
72
|
+
throw new CalibrateError(`flow name "${name}" is not usable: ${checked.error.issues.map((i) => i.message).join("; ")}`, undefined, opts.flowName === undefined ? undefined : "name-flag");
|
|
66
73
|
}
|
|
67
74
|
await fs.mkdir(resolveWorkspacePath(opts.workspaceDir, "flows"), { recursive: true });
|
|
68
|
-
// The flow name is guide-supplied
|
|
75
|
+
// The flow name is guide-supplied, resolve with the symlink-aware variant before writing.
|
|
69
76
|
const flowFilePath = await resolveWorkspacePathReal(opts.workspaceDir, "flows", `${name}.flow.yaml`);
|
|
70
77
|
await fs.writeFile(flowFilePath, serializeFlowFile(flow), "utf8");
|
|
71
78
|
const { paths, created } = await initStyleIfAbsent(opts.workspaceDir);
|
|
@@ -5,3 +5,8 @@
|
|
|
5
5
|
export declare function explainBackendFailure(e: unknown, backendUrl: string, workspaceDir?: string): string | undefined;
|
|
6
6
|
/** Why `.docsxai.json` did not load as a workspace config, as a phrase for parentheses. */
|
|
7
7
|
export declare function configProblem(workspaceDir: string): Promise<string>;
|
|
8
|
+
/**
|
|
9
|
+
* Warn on stderr when `.docsxai.json` exists but did not load, so a typo does not read as "no
|
|
10
|
+
* app_url". A missing file is the normal case for a bare directory and stays silent.
|
|
11
|
+
*/
|
|
12
|
+
export declare function warnUnusableConfig(label: string, workspaceDir: string): Promise<void>;
|
|
@@ -33,6 +33,12 @@ export function explainBackendFailure(e, backendUrl, workspaceDir) {
|
|
|
33
33
|
// The message carries the start of the response body, which the backend controls, and can
|
|
34
34
|
// quote a URL with its credentials or query.
|
|
35
35
|
const message = sanitizeForTerminal(redactUrlsIn(e.message));
|
|
36
|
+
// No usable token (never logged in, or the stored one lapsed): the client's own hint becomes the next line.
|
|
37
|
+
const tokenGap = e.status === undefined ? /^(.*?): set DOCSX_TOKEN or run /s.exec(message) : null;
|
|
38
|
+
if (tokenGap) {
|
|
39
|
+
const ws = workspaceDir ? shellQuote(workspaceDir) : "<workspace-dir>";
|
|
40
|
+
return withNext(`${tokenGap[1]} for ${url}`, `${login} --oauth ${ws} (or set DOCSX_TOKEN to a CI token)`);
|
|
41
|
+
}
|
|
36
42
|
if (e.status === 401 || e.status === 403) {
|
|
37
43
|
const oauth = workspaceDir
|
|
38
44
|
? ` (or add --oauth ${shellQuote(workspaceDir)} to sign in as a person)`
|
|
@@ -43,7 +49,7 @@ export function explainBackendFailure(e, backendUrl, workspaceDir) {
|
|
|
43
49
|
return withNext(message, `check backend_workspace_id and backend_project_id in ${WORKSPACE_CONFIG_FILE}, or remove them and push again`);
|
|
44
50
|
}
|
|
45
51
|
if (e.status !== undefined && e.status >= 500) {
|
|
46
|
-
return withNext(`${message}\n why: ${url} failed on its side`, "
|
|
52
|
+
return withNext(`${message}\n why: ${url} failed on its side`, "try again, then contact whoever runs the backend");
|
|
47
53
|
}
|
|
48
54
|
return message;
|
|
49
55
|
}
|
|
@@ -53,8 +59,11 @@ export async function configProblem(workspaceDir) {
|
|
|
53
59
|
try {
|
|
54
60
|
text = await fs.readFile(resolveWorkspacePath(workspaceDir, WORKSPACE_CONFIG_FILE), "utf8");
|
|
55
61
|
}
|
|
56
|
-
catch {
|
|
57
|
-
|
|
62
|
+
catch (e) {
|
|
63
|
+
const code = e.code;
|
|
64
|
+
return code === "ENOENT" || code === "ENOTDIR"
|
|
65
|
+
? "the file does not exist"
|
|
66
|
+
: `it cannot be read, ${code ?? "unreadable"}`;
|
|
58
67
|
}
|
|
59
68
|
try {
|
|
60
69
|
JSON.parse(text);
|
|
@@ -64,3 +73,15 @@ export async function configProblem(workspaceDir) {
|
|
|
64
73
|
}
|
|
65
74
|
return 'its "schema" must be "docsxai/workspace@1"';
|
|
66
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Warn on stderr when `.docsxai.json` exists but did not load, so a typo does not read as "no
|
|
78
|
+
* app_url". A missing file is the normal case for a bare directory and stays silent.
|
|
79
|
+
*/
|
|
80
|
+
export async function warnUnusableConfig(label, workspaceDir) {
|
|
81
|
+
const problem = await configProblem(workspaceDir);
|
|
82
|
+
if (problem === "the file does not exist")
|
|
83
|
+
return;
|
|
84
|
+
const file = resolveWorkspacePath(workspaceDir, WORKSPACE_CONFIG_FILE);
|
|
85
|
+
const note = withNext(`warning, ${file} was ignored (${problem})`, `fix ${shellQuote(file)}, then docsxai ${label} ${shellQuote(workspaceDir)}`);
|
|
86
|
+
process.stderr.write(`${label}: ${note}\n`);
|
|
87
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function cmdCaptureAuth(args: string[]): Promise<number>;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// capture-auth: run a role's auth strategy against a live browser and cache the session.
|
|
2
|
+
// Split from cli-commands-session.ts to keep both files under the max-lines ceiling.
|
|
3
|
+
import { promises as fs } from "node:fs";
|
|
4
|
+
import * as path from "node:path";
|
|
5
|
+
import { LocalStorageStateCache, makeStrategy, parseAuthStrategyFile, resolveCredsEnv, storageStateFileName, } from "./auth.js";
|
|
6
|
+
import { describeBrowserLaunch } from "./browser-launch-error.js";
|
|
7
|
+
import { PlaywrightInstrumentedBrowser } from "./playwright-instrumented-browser.js";
|
|
8
|
+
import { loadWorkspaceConfig, resolveWorkspacePath } from "./workspace.js";
|
|
9
|
+
import { bareValueFlagExit } from "./cli-shared.js";
|
|
10
|
+
import { parseCommandFlags } from "./cli-flags.js";
|
|
11
|
+
import { shellQuote, usageError, withNext } from "./cli-messages.js";
|
|
12
|
+
import { warnUnusableConfig } from "./cli-backend-errors.js";
|
|
13
|
+
export async function cmdCaptureAuth(args) {
|
|
14
|
+
const parsed = parseCommandFlags("capture-auth", args);
|
|
15
|
+
if (typeof parsed === "number")
|
|
16
|
+
return parsed;
|
|
17
|
+
const { positionals, flags } = parsed;
|
|
18
|
+
const projectDir = positionals[0];
|
|
19
|
+
if (!projectDir)
|
|
20
|
+
return usageError("capture-auth", "missing <workspace-dir>");
|
|
21
|
+
const bare = bareValueFlagExit("capture-auth", flags, ["base-url", "role", "auth-cookie", "cdp"]);
|
|
22
|
+
if (bare !== undefined)
|
|
23
|
+
return bare;
|
|
24
|
+
const wsCfg = await loadWorkspaceConfig(projectDir);
|
|
25
|
+
if (!wsCfg)
|
|
26
|
+
await warnUnusableConfig("capture-auth", projectDir);
|
|
27
|
+
const baseURL = (typeof flags.get("base-url") === "string" ? flags.get("base-url") : undefined) ??
|
|
28
|
+
wsCfg?.app_url;
|
|
29
|
+
if (!baseURL) {
|
|
30
|
+
return usageError("capture-auth", "--base-url <url> is required (or set app_url in the workspace's .docsxai.json)");
|
|
31
|
+
}
|
|
32
|
+
const headless = flags.get("headless") === true;
|
|
33
|
+
const ignoreHTTPSErrors = flags.get("ignore-https-errors") === true || !!wsCfg?.ignore_https_errors;
|
|
34
|
+
const authCookie = typeof flags.get("auth-cookie") === "string" ? flags.get("auth-cookie") : undefined;
|
|
35
|
+
const cdp = typeof flags.get("cdp") === "string" ? flags.get("cdp") : undefined;
|
|
36
|
+
const fresh = flags.get("fresh") === true;
|
|
37
|
+
// Persistent Chrome profile under the workspace, re-running capture-auth reuses the login. (Not when attaching, or with --fresh.)
|
|
38
|
+
const profileDir = fresh || cdp ? undefined : resolveWorkspacePath(projectDir, ".auth", "chrome-profile");
|
|
39
|
+
const descriptorPath = resolveWorkspacePath(projectDir, "auth", "strategy.yaml");
|
|
40
|
+
let descriptorText;
|
|
41
|
+
try {
|
|
42
|
+
descriptorText = await fs.readFile(descriptorPath, "utf8");
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
process.stderr.write(`capture-auth: ${withNext(`no auth descriptor at ${descriptorPath} (a workspace made with --auth none has none; if the app needs no login, skip capture-auth)`, "write auth/strategy.yaml (`docsxai init <new-dir>` scaffolds an example to copy)")}\n`);
|
|
46
|
+
return 1;
|
|
47
|
+
}
|
|
48
|
+
let role;
|
|
49
|
+
let roleAuth;
|
|
50
|
+
try {
|
|
51
|
+
const descriptor = parseAuthStrategyFile(descriptorText, descriptorPath);
|
|
52
|
+
role =
|
|
53
|
+
typeof flags.get("role") === "string"
|
|
54
|
+
? flags.get("role")
|
|
55
|
+
: descriptor.default_role;
|
|
56
|
+
const ra = descriptor.roles[role];
|
|
57
|
+
if (!ra) {
|
|
58
|
+
const roles = Object.keys(descriptor.roles).join(", ");
|
|
59
|
+
process.stderr.write(`capture-auth: role "${role}" not in ${descriptorPath} (roles: ${roles}); pass --role <role>\n`);
|
|
60
|
+
return 1;
|
|
61
|
+
}
|
|
62
|
+
roleAuth = ra;
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
process.stderr.write(`capture-auth: ${withNext(e.message, `fix ${shellQuote(descriptorPath)}, then docsxai capture-auth ${shellQuote(projectDir)}`)}\n`);
|
|
66
|
+
return 1;
|
|
67
|
+
}
|
|
68
|
+
let creds;
|
|
69
|
+
try {
|
|
70
|
+
creds = resolveCredsEnv(roleAuth);
|
|
71
|
+
}
|
|
72
|
+
catch (e) {
|
|
73
|
+
process.stderr.write(`capture-auth: ${withNext(e.message, `export the variables named above, then docsxai capture-auth ${shellQuote(projectDir)}`)}\n`);
|
|
74
|
+
return 1;
|
|
75
|
+
}
|
|
76
|
+
let strategy;
|
|
77
|
+
try {
|
|
78
|
+
strategy = makeStrategy(roleAuth, {
|
|
79
|
+
instrumentedBrowser: () => new PlaywrightInstrumentedBrowser({
|
|
80
|
+
headless,
|
|
81
|
+
ignoreHTTPSErrors,
|
|
82
|
+
...(cdp ? { connectOverCdp: cdp } : {}),
|
|
83
|
+
...(profileDir ? { profileDir } : {}),
|
|
84
|
+
}),
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
catch (e) {
|
|
88
|
+
process.stderr.write(`capture-auth: ${e.message}\n`);
|
|
89
|
+
return 1;
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
process.stdout.write(`capture-auth: launching browser for role "${role}" (${roleAuth.strategy})${cdp ? `, attaching to ${cdp}` : profileDir ? ", reusing saved profile if present" : ", fresh profile"}; log in if prompted, then trigger capture…\n`);
|
|
93
|
+
const result = await strategy.authenticate({ creds, options: roleAuth.options, baseURL, role });
|
|
94
|
+
const cookies = result.storageState.cookies ?? [];
|
|
95
|
+
process.stdout.write(`capture-auth: captured ${cookies.length} cookie(s)${cookies.length ? " (newest expiry first):" : ""}\n`);
|
|
96
|
+
for (const c of [...cookies].sort((a, b) => (b.expires || 0) - (a.expires || 0))) {
|
|
97
|
+
const exp = c.expires && c.expires > 0 ? new Date(c.expires * 1000).toISOString() : "(session)";
|
|
98
|
+
process.stdout.write(` ${c.name} @${c.domain} expires ${exp}\n`);
|
|
99
|
+
}
|
|
100
|
+
const { expiresAt, source } = await new LocalStorageStateCache(resolveWorkspacePath(projectDir, ".auth")).save(role, result, roleAuth, Date.now(), authCookie ? { authCookie } : {});
|
|
101
|
+
process.stdout.write(`capture-auth: cached ${role} → ${path.join(projectDir, ".auth", storageStateFileName(role))}\n` +
|
|
102
|
+
` expires ${new Date(expiresAt).toISOString()} (from ${source}; re-run when it lapses)\n`);
|
|
103
|
+
if (!/^auth-cookie/.test(source)) {
|
|
104
|
+
process.stdout.write(` tip: pick the app's auth/session cookie from the list above and set 'cache.auth_cookie: <name>' in\n` +
|
|
105
|
+
` ${path.join(projectDir, "auth", "strategy.yaml")} (or pass --auth-cookie <name>) so the cache tracks its real expiry.\n`);
|
|
106
|
+
}
|
|
107
|
+
return 0;
|
|
108
|
+
}
|
|
109
|
+
catch (e) {
|
|
110
|
+
const problem = describeBrowserLaunch(e.message, cdp);
|
|
111
|
+
process.stderr.write(`capture-auth: ${problem.next ? withNext(problem.reason, problem.next) : e.message}\n`);
|
|
112
|
+
return 1;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -2,4 +2,3 @@ export declare function cmdInspect(args: string[]): Promise<number>;
|
|
|
2
2
|
export declare function cmdLint(args: string[]): Promise<number>;
|
|
3
3
|
export declare function cmdFlowTree(args: string[]): Promise<number>;
|
|
4
4
|
export declare function cmdDiagnose(args: string[]): Promise<number>;
|
|
5
|
-
export declare function cmdStyle(args: string[]): Promise<number>;
|