milieu-cli 0.3.2 → 0.4.0
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 +177 -76
- package/dist/bridges/context/agents-json.d.ts +0 -1
- package/dist/bridges/context/agents-json.js +21 -12
- package/dist/bridges/context/auth-clarity.d.ts +0 -1
- package/dist/bridges/context/auth-clarity.js +11 -9
- package/dist/bridges/context/auth-legibility.d.ts +2 -2
- package/dist/bridges/context/auth-legibility.js +67 -60
- package/dist/bridges/context/index.d.ts +1 -2
- package/dist/bridges/context/index.js +19 -40
- package/dist/bridges/context/oauth-metadata.d.ts +14 -0
- package/dist/bridges/context/oauth-metadata.js +127 -0
- package/dist/bridges/context/probe.d.ts +33 -0
- package/dist/bridges/context/probe.js +157 -0
- package/dist/bridges/context/rate-limits.d.ts +5 -2
- package/dist/bridges/context/rate-limits.js +27 -51
- package/dist/bridges/context/tos-contact.d.ts +13 -4
- package/dist/bridges/context/tos-contact.js +108 -46
- package/dist/bridges/context/versioning.d.ts +1 -2
- package/dist/bridges/context/versioning.js +42 -7
- package/dist/bridges/index.d.ts +0 -1
- package/dist/bridges/index.js +0 -1
- package/dist/bridges/reachability/crawler-policy.d.ts +30 -10
- package/dist/bridges/reachability/crawler-policy.js +41 -56
- package/dist/bridges/reachability/http-status.d.ts +3 -2
- package/dist/bridges/reachability/http-status.js +18 -3
- package/dist/bridges/reachability/https-check.d.ts +2 -2
- package/dist/bridges/reachability/https-check.js +6 -3
- package/dist/bridges/reachability/index.d.ts +1 -2
- package/dist/bridges/reachability/index.js +34 -43
- package/dist/bridges/reachability/meta-robots.d.ts +0 -13
- package/dist/bridges/reachability/meta-robots.js +89 -101
- package/dist/bridges/reachability/robots-parser.d.ts +7 -7
- package/dist/bridges/reachability/robots-parser.js +65 -15
- package/dist/bridges/reachability/robots-txt.d.ts +4 -2
- package/dist/bridges/reachability/robots-txt.js +33 -60
- package/dist/bridges/schema/descriptions.d.ts +2 -2
- package/dist/bridges/schema/descriptions.js +79 -44
- package/dist/bridges/schema/error-schemas.d.ts +2 -2
- package/dist/bridges/schema/error-schemas.js +31 -18
- package/dist/bridges/schema/index.d.ts +2 -2
- package/dist/bridges/schema/index.js +48 -30
- package/dist/bridges/schema/oas-types.d.ts +65 -26
- package/dist/bridges/schema/oas-types.js +37 -7
- package/dist/bridges/schema/operation-ids.d.ts +2 -2
- package/dist/bridges/schema/operation-ids.js +2 -3
- package/dist/bridges/schema/required-fields.d.ts +2 -2
- package/dist/bridges/schema/required-fields.js +12 -10
- package/dist/bridges/schema/schema-sources.d.ts +19 -0
- package/dist/bridges/schema/schema-sources.js +182 -0
- package/dist/bridges/schema/schema-types.d.ts +2 -2
- package/dist/bridges/schema/schema-types.js +20 -21
- package/dist/bridges/separation/api-presence.d.ts +3 -15
- package/dist/bridges/separation/api-presence.js +34 -85
- package/dist/bridges/separation/developer-docs.d.ts +6 -18
- package/dist/bridges/separation/developer-docs.js +100 -99
- package/dist/bridges/separation/docs-discovery.d.ts +28 -0
- package/dist/bridges/separation/docs-discovery.js +95 -0
- package/dist/bridges/separation/evidence-summary.d.ts +2 -0
- package/dist/bridges/separation/evidence-summary.js +67 -0
- package/dist/bridges/separation/index.d.ts +2 -19
- package/dist/bridges/separation/index.js +35 -39
- package/dist/bridges/separation/published-routes.d.ts +69 -0
- package/dist/bridges/separation/published-routes.js +271 -0
- package/dist/bridges/separation/sdk-references.d.ts +8 -3
- package/dist/bridges/separation/sdk-references.js +86 -61
- package/dist/bridges/separation/webhook-support.d.ts +3 -23
- package/dist/bridges/separation/webhook-support.js +61 -162
- package/dist/bridges/standards/a2a-agent-card.d.ts +0 -1
- package/dist/bridges/standards/a2a-agent-card.js +24 -9
- package/dist/bridges/standards/graphql.d.ts +3 -4
- package/dist/bridges/standards/graphql.js +70 -66
- package/dist/bridges/standards/index.d.ts +1 -2
- package/dist/bridges/standards/index.js +57 -47
- package/dist/bridges/standards/json-ld.d.ts +25 -11
- package/dist/bridges/standards/json-ld.js +114 -56
- package/dist/bridges/standards/llms-txt.d.ts +4 -2
- package/dist/bridges/standards/llms-txt.js +46 -32
- package/dist/bridges/standards/markdown-negotiation.d.ts +4 -1
- package/dist/bridges/standards/markdown-negotiation.js +16 -11
- package/dist/bridges/standards/mcp.d.ts +3 -12
- package/dist/bridges/standards/mcp.js +89 -132
- package/dist/bridges/standards/openapi.d.ts +7 -15
- package/dist/bridges/standards/openapi.js +657 -207
- package/dist/bridges/standards/probe-evidence.d.ts +30 -0
- package/dist/bridges/standards/probe-evidence.js +90 -0
- package/dist/bridges/standards/schema-org.d.ts +15 -9
- package/dist/bridges/standards/schema-org.js +38 -64
- package/dist/bridges/standards/sitemap.d.ts +2 -3
- package/dist/bridges/standards/sitemap.js +161 -169
- package/dist/bridges/standards/well-known.d.ts +3 -7
- package/dist/bridges/standards/well-known.js +28 -12
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +107 -22
- package/dist/cli/journey-commands.d.ts +3 -0
- package/dist/cli/journey-commands.js +35 -0
- package/dist/cli/read-report.d.ts +2 -0
- package/dist/cli/read-report.js +11 -0
- package/dist/core/bridge-output.d.ts +11 -0
- package/dist/core/bridge-output.js +86 -0
- package/dist/core/bridge-session.d.ts +28 -0
- package/dist/core/bridge-session.js +58 -0
- package/dist/core/bridge-worker.d.ts +1 -0
- package/dist/core/bridge-worker.js +66 -0
- package/dist/core/diff.d.ts +79 -0
- package/dist/core/diff.js +499 -0
- package/dist/core/explanations.d.ts +1 -3
- package/dist/core/explanations.js +36 -59
- package/dist/core/index.d.ts +4 -2
- package/dist/core/index.js +2 -3
- package/dist/core/scan-options.d.ts +0 -1
- package/dist/core/scan-options.js +14 -6
- package/dist/core/scan.d.ts +0 -1
- package/dist/core/scan.js +91 -41
- package/dist/core/scoring.d.ts +6 -0
- package/dist/core/scoring.js +27 -0
- package/dist/core/types.d.ts +97 -61
- package/dist/core/types.js +9 -3
- package/dist/core/validate-report.d.ts +5 -0
- package/dist/core/validate-report.js +95 -0
- package/dist/core/version.d.ts +0 -1
- package/dist/core/version.js +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/journey/body-worker.d.ts +27 -0
- package/dist/journey/body-worker.js +140 -0
- package/dist/journey/case.d.ts +74 -0
- package/dist/journey/case.js +187 -0
- package/dist/journey/cli.d.ts +14 -0
- package/dist/journey/cli.js +226 -0
- package/dist/journey/compare.d.ts +43 -0
- package/dist/journey/compare.js +83 -0
- package/dist/journey/contracts.d.ts +143 -0
- package/dist/journey/contracts.js +37 -0
- package/dist/journey/decision.d.ts +72 -0
- package/dist/journey/decision.js +121 -0
- package/dist/journey/demo.d.ts +36 -0
- package/dist/journey/demo.js +137 -0
- package/dist/journey/document.d.ts +8 -0
- package/dist/journey/document.js +113 -0
- package/dist/journey/excerpt.d.ts +6 -0
- package/dist/journey/excerpt.js +54 -0
- package/dist/journey/name-guidance.d.ts +2 -0
- package/dist/journey/name-guidance.js +41 -0
- package/dist/journey/providers.d.ts +34 -0
- package/dist/journey/providers.js +197 -0
- package/dist/journey/report-validation.d.ts +3 -0
- package/dist/journey/report-validation.js +457 -0
- package/dist/journey/runner.d.ts +12 -0
- package/dist/journey/runner.js +321 -0
- package/dist/journey/scope.d.ts +8 -0
- package/dist/journey/scope.js +50 -0
- package/dist/journey/transport.d.ts +3 -0
- package/dist/journey/transport.js +45 -0
- package/dist/journey/verify.d.ts +21 -0
- package/dist/journey/verify.js +213 -0
- package/dist/render/colors.d.ts +6 -7
- package/dist/render/colors.js +16 -25
- package/dist/render/discovery-guidance.d.ts +3 -0
- package/dist/render/discovery-guidance.js +66 -0
- package/dist/render/format-bridge.d.ts +1 -2
- package/dist/render/format-bridge.js +22 -17
- package/dist/render/format-diff.d.ts +2 -0
- package/dist/render/format-diff.js +169 -0
- package/dist/render/format-scan.d.ts +0 -1
- package/dist/render/format-scan.js +6 -4
- package/dist/render/format-verbose.d.ts +0 -1
- package/dist/render/format-verbose.js +7 -4
- package/dist/render/index.d.ts +0 -1
- package/dist/render/index.js +1 -2
- package/dist/render/oauth-observations.d.ts +4 -0
- package/dist/render/oauth-observations.js +27 -0
- package/dist/render/progress-bar.d.ts +1 -2
- package/dist/render/progress-bar.js +8 -6
- package/dist/render/robots-inventory.d.ts +3 -0
- package/dist/render/robots-inventory.js +38 -0
- package/dist/render/symbols.d.ts +4 -10
- package/dist/render/symbols.js +15 -17
- package/dist/render/terminal-text.d.ts +1 -3
- package/dist/render/terminal-text.js +1 -5
- package/dist/utils/analysis-worker-entry.d.ts +3 -0
- package/dist/utils/analysis-worker-entry.js +12 -0
- package/dist/utils/analysis-worker.d.ts +12 -0
- package/dist/utils/analysis-worker.js +54 -0
- package/dist/utils/html.d.ts +39 -0
- package/dist/utils/html.js +261 -0
- package/dist/utils/http-client.d.ts +24 -17
- package/dist/utils/http-client.js +166 -200
- package/dist/utils/http-types.d.ts +43 -0
- package/dist/utils/http-types.js +11 -0
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.js +0 -1
- package/dist/utils/package-registry.d.ts +11 -0
- package/dist/utils/package-registry.js +69 -0
- package/dist/utils/read-json-file.d.ts +3 -0
- package/dist/utils/read-json-file.js +41 -0
- package/dist/utils/record.d.ts +1 -0
- package/dist/utils/record.js +3 -0
- package/dist/utils/response-body.d.ts +7 -0
- package/dist/utils/response-body.js +71 -0
- package/dist/utils/ssrf.d.ts +11 -15
- package/dist/utils/ssrf.js +80 -44
- package/dist/utils/terminal-text.d.ts +2 -0
- package/dist/utils/terminal-text.js +4 -0
- package/dist/utils/url.d.ts +29 -1
- package/dist/utils/url.js +147 -17
- package/docs/examples/onboarding/account-claim.json +25 -0
- package/docs/examples/onboarding/pages/account-claim.html +3 -0
- package/docs/examples/onboarding/pages/production-activation.html +3 -0
- package/docs/examples/onboarding/pages/test-credential.html +3 -0
- package/docs/examples/onboarding/production-activation.json +25 -0
- package/docs/examples/onboarding/test-credential.json +25 -0
- package/docs/journey-qualification.md +46 -0
- package/docs/journeys.md +83 -0
- package/package.json +28 -8
- package/dist/bridges/context/agents-json.d.ts.map +0 -1
- package/dist/bridges/context/agents-json.js.map +0 -1
- package/dist/bridges/context/auth-clarity.d.ts.map +0 -1
- package/dist/bridges/context/auth-clarity.js.map +0 -1
- package/dist/bridges/context/auth-legibility.d.ts.map +0 -1
- package/dist/bridges/context/auth-legibility.js.map +0 -1
- package/dist/bridges/context/index.d.ts.map +0 -1
- package/dist/bridges/context/index.js.map +0 -1
- package/dist/bridges/context/rate-limits.d.ts.map +0 -1
- package/dist/bridges/context/rate-limits.js.map +0 -1
- package/dist/bridges/context/tos-contact.d.ts.map +0 -1
- package/dist/bridges/context/tos-contact.js.map +0 -1
- package/dist/bridges/context/versioning.d.ts.map +0 -1
- package/dist/bridges/context/versioning.js.map +0 -1
- package/dist/bridges/index.d.ts.map +0 -1
- package/dist/bridges/index.js.map +0 -1
- package/dist/bridges/reachability/crawler-policy.d.ts.map +0 -1
- package/dist/bridges/reachability/crawler-policy.js.map +0 -1
- package/dist/bridges/reachability/http-status.d.ts.map +0 -1
- package/dist/bridges/reachability/http-status.js.map +0 -1
- package/dist/bridges/reachability/https-check.d.ts.map +0 -1
- package/dist/bridges/reachability/https-check.js.map +0 -1
- package/dist/bridges/reachability/index.d.ts.map +0 -1
- package/dist/bridges/reachability/index.js.map +0 -1
- package/dist/bridges/reachability/meta-robots.d.ts.map +0 -1
- package/dist/bridges/reachability/meta-robots.js.map +0 -1
- package/dist/bridges/reachability/robots-parser.d.ts.map +0 -1
- package/dist/bridges/reachability/robots-parser.js.map +0 -1
- package/dist/bridges/reachability/robots-txt.d.ts.map +0 -1
- package/dist/bridges/reachability/robots-txt.js.map +0 -1
- package/dist/bridges/schema/descriptions.d.ts.map +0 -1
- package/dist/bridges/schema/descriptions.js.map +0 -1
- package/dist/bridges/schema/error-schemas.d.ts.map +0 -1
- package/dist/bridges/schema/error-schemas.js.map +0 -1
- package/dist/bridges/schema/index.d.ts.map +0 -1
- package/dist/bridges/schema/index.js.map +0 -1
- package/dist/bridges/schema/oas-types.d.ts.map +0 -1
- package/dist/bridges/schema/oas-types.js.map +0 -1
- package/dist/bridges/schema/operation-ids.d.ts.map +0 -1
- package/dist/bridges/schema/operation-ids.js.map +0 -1
- package/dist/bridges/schema/required-fields.d.ts.map +0 -1
- package/dist/bridges/schema/required-fields.js.map +0 -1
- package/dist/bridges/schema/schema-types.d.ts.map +0 -1
- package/dist/bridges/schema/schema-types.js.map +0 -1
- package/dist/bridges/separation/api-presence.d.ts.map +0 -1
- package/dist/bridges/separation/api-presence.js.map +0 -1
- package/dist/bridges/separation/developer-docs.d.ts.map +0 -1
- package/dist/bridges/separation/developer-docs.js.map +0 -1
- package/dist/bridges/separation/index.d.ts.map +0 -1
- package/dist/bridges/separation/index.js.map +0 -1
- package/dist/bridges/separation/sdk-references.d.ts.map +0 -1
- package/dist/bridges/separation/sdk-references.js.map +0 -1
- package/dist/bridges/separation/webhook-support.d.ts.map +0 -1
- package/dist/bridges/separation/webhook-support.js.map +0 -1
- package/dist/bridges/standards/a2a-agent-card.d.ts.map +0 -1
- package/dist/bridges/standards/a2a-agent-card.js.map +0 -1
- package/dist/bridges/standards/graphql.d.ts.map +0 -1
- package/dist/bridges/standards/graphql.js.map +0 -1
- package/dist/bridges/standards/index.d.ts.map +0 -1
- package/dist/bridges/standards/index.js.map +0 -1
- package/dist/bridges/standards/json-ld.d.ts.map +0 -1
- package/dist/bridges/standards/json-ld.js.map +0 -1
- package/dist/bridges/standards/llms-txt.d.ts.map +0 -1
- package/dist/bridges/standards/llms-txt.js.map +0 -1
- package/dist/bridges/standards/markdown-negotiation.d.ts.map +0 -1
- package/dist/bridges/standards/markdown-negotiation.js.map +0 -1
- package/dist/bridges/standards/mcp.d.ts.map +0 -1
- package/dist/bridges/standards/mcp.js.map +0 -1
- package/dist/bridges/standards/openapi.d.ts.map +0 -1
- package/dist/bridges/standards/openapi.js.map +0 -1
- package/dist/bridges/standards/schema-org.d.ts.map +0 -1
- package/dist/bridges/standards/schema-org.js.map +0 -1
- package/dist/bridges/standards/sitemap.d.ts.map +0 -1
- package/dist/bridges/standards/sitemap.js.map +0 -1
- package/dist/bridges/standards/well-known.d.ts.map +0 -1
- package/dist/bridges/standards/well-known.js.map +0 -1
- package/dist/cli/index.d.ts.map +0 -1
- package/dist/cli/index.js.map +0 -1
- package/dist/core/explanations.d.ts.map +0 -1
- package/dist/core/explanations.js.map +0 -1
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/index.js.map +0 -1
- package/dist/core/scan-options.d.ts.map +0 -1
- package/dist/core/scan-options.js.map +0 -1
- package/dist/core/scan.d.ts.map +0 -1
- package/dist/core/scan.js.map +0 -1
- package/dist/core/types.d.ts.map +0 -1
- package/dist/core/types.js.map +0 -1
- package/dist/core/version.d.ts.map +0 -1
- package/dist/core/version.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/render/colors.d.ts.map +0 -1
- package/dist/render/colors.js.map +0 -1
- package/dist/render/format-bridge.d.ts.map +0 -1
- package/dist/render/format-bridge.js.map +0 -1
- package/dist/render/format-scan.d.ts.map +0 -1
- package/dist/render/format-scan.js.map +0 -1
- package/dist/render/format-verbose.d.ts.map +0 -1
- package/dist/render/format-verbose.js.map +0 -1
- package/dist/render/index.d.ts.map +0 -1
- package/dist/render/index.js.map +0 -1
- package/dist/render/progress-bar.d.ts.map +0 -1
- package/dist/render/progress-bar.js.map +0 -1
- package/dist/render/symbols.d.ts.map +0 -1
- package/dist/render/symbols.js.map +0 -1
- package/dist/render/terminal-text.d.ts.map +0 -1
- package/dist/render/terminal-text.js.map +0 -1
- package/dist/utils/http-client.d.ts.map +0 -1
- package/dist/utils/http-client.js.map +0 -1
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/ssrf.d.ts.map +0 -1
- package/dist/utils/ssrf.js.map +0 -1
- package/dist/utils/url.d.ts.map +0 -1
- package/dist/utils/url.js.map +0 -1
package/dist/cli/index.js
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
2
|
+
import ora from "ora";
|
|
3
|
+
import { Command, CommanderError } from "commander";
|
|
3
4
|
import { realpathSync } from "node:fs";
|
|
5
|
+
import { createRequire } from "node:module";
|
|
6
|
+
import { resolve } from "node:path";
|
|
4
7
|
import { fileURLToPath } from "node:url";
|
|
8
|
+
import { stripVTControlCharacters } from "node:util";
|
|
5
9
|
import { scan } from "../core/scan.js";
|
|
10
|
+
import { compareReports } from "../core/diff.js";
|
|
6
11
|
import { validateScanOptions } from "../core/scan-options.js";
|
|
7
12
|
import { getVersion } from "../core/version.js";
|
|
8
|
-
import {
|
|
13
|
+
import { addJourney } from "./journey-commands.js";
|
|
14
|
+
import { readReport } from "./read-report.js";
|
|
15
|
+
import { formatReportDiff } from "../render/format-diff.js";
|
|
9
16
|
import { formatScanOutput } from "../render/format-scan.js";
|
|
10
17
|
import { terminalText } from "../render/terminal-text.js";
|
|
11
18
|
function writeFailure(error, jsonMode) {
|
|
@@ -23,10 +30,10 @@ function reportJson(value, pretty = false) {
|
|
|
23
30
|
return JSON.stringify(value, null, pretty ? 2 : undefined)
|
|
24
31
|
.replace(/[\u007f-\u009f\p{Bidi_Control}\u2028\u2029]/gu, char => "\\u" + char.charCodeAt(0).toString(16).padStart(4, "0"));
|
|
25
32
|
}
|
|
26
|
-
function numericFlag(value) {
|
|
33
|
+
function numericFlag(value, decimal = false) {
|
|
27
34
|
if (value === undefined)
|
|
28
35
|
return undefined;
|
|
29
|
-
return typeof value === "string" &&
|
|
36
|
+
return typeof value === "string" && (decimal ? /^\d+(?:\.\d+)?$/ : /^\d+$/).test(value) ? Number(value) : NaN;
|
|
30
37
|
}
|
|
31
38
|
export function buildProgram() {
|
|
32
39
|
const program = new Command();
|
|
@@ -41,64 +48,142 @@ export function buildProgram() {
|
|
|
41
48
|
.option("--json", "Output result as JSON")
|
|
42
49
|
.option("--pretty", "Pretty-print JSON output (use with --json)")
|
|
43
50
|
.option("--timeout <ms>", "Per-request timeout in milliseconds", "10000")
|
|
51
|
+
.option("--deadline <ms>", "Overall scan time limit in milliseconds")
|
|
52
|
+
.option("--no-registry-lookup", "Skip the external APIs.guru hostname lookup")
|
|
44
53
|
.option("--max-concurrency <n>", "Maximum simultaneous outbound requests (default: 8)")
|
|
45
54
|
.option("--max-requests <n>", "Maximum request attempts for the whole scan, counting redirects and retries (default: 150)")
|
|
46
55
|
.option("--threshold <score>", "Exit non-zero if overall score is below this threshold (0 to 100)")
|
|
56
|
+
.option("--require-complete", "Exit non-zero if the request budget ran out, a bridge was skipped, or a check errored")
|
|
47
57
|
.option("--verbose", "Show individual check details")
|
|
48
58
|
.option("--explain-all", "Show explanations on all checks, not just failures (use with --verbose)")
|
|
59
|
+
.option("--no-color", "Disable colored terminal output")
|
|
49
60
|
.option("--quiet", "Suppress terminal output")
|
|
50
61
|
.action(async (url, opts) => {
|
|
51
62
|
const jsonMode = Boolean(opts.json);
|
|
52
63
|
const quiet = Boolean(opts.quiet);
|
|
53
64
|
const verbose = Boolean(opts.verbose);
|
|
54
65
|
const explainAll = Boolean(opts.explainAll);
|
|
55
|
-
|
|
66
|
+
if ((opts.pretty && !jsonMode) || (explainAll && !verbose)) {
|
|
67
|
+
return writeFailure({ kind: "usage_error", message: opts.pretty && !jsonMode
|
|
68
|
+
? "--pretty requires --json" : "--explain-all requires --verbose" }, jsonMode);
|
|
69
|
+
}
|
|
70
|
+
const threshold = numericFlag(opts.threshold, true);
|
|
56
71
|
const options = {
|
|
57
72
|
timeout: numericFlag(opts.timeout),
|
|
73
|
+
deadlineMs: numericFlag(opts.deadline),
|
|
74
|
+
registryLookup: opts.registryLookup !== false,
|
|
58
75
|
verbose,
|
|
59
76
|
silent: jsonMode || quiet,
|
|
60
77
|
maxConcurrency: numericFlag(opts.maxConcurrency),
|
|
61
78
|
maxRequests: numericFlag(opts.maxRequests),
|
|
62
79
|
};
|
|
63
80
|
const optionError = validateScanOptions(options);
|
|
64
|
-
if (optionError)
|
|
65
|
-
|
|
81
|
+
if (optionError) {
|
|
82
|
+
const message = optionError.replace(/^timeout/, "--timeout").replace(/^deadlineMs/, "--deadline")
|
|
83
|
+
.replace(/^maxConcurrency/, "--max-concurrency").replace(/^maxRequests/, "--max-requests");
|
|
84
|
+
return writeFailure({ kind: "invalid_options", message }, jsonMode);
|
|
85
|
+
}
|
|
66
86
|
if (threshold !== undefined && (!Number.isFinite(threshold) || threshold < 0 || threshold > 100)) {
|
|
67
|
-
return writeFailure({ kind: "
|
|
87
|
+
return writeFailure({ kind: "invalid_options", message: "--threshold requires a number between 0 and 100" }, jsonMode);
|
|
88
|
+
}
|
|
89
|
+
// ora treats 0 columns as a real width and then loops forever clearing lines.
|
|
90
|
+
const spinner = jsonMode || quiet || !process.stderr.isTTY || !((process.stderr.columns ?? 0) > 0) ? undefined : ora({ text: "Scanning...", ...(opts.color === false && { color: false }) }).start();
|
|
91
|
+
let outcome;
|
|
92
|
+
try {
|
|
93
|
+
outcome = await scan(url, { ...options, onProgress: spinner ? stage => { spinner.text = stage; } : undefined });
|
|
94
|
+
}
|
|
95
|
+
finally {
|
|
96
|
+
spinner?.stop();
|
|
68
97
|
}
|
|
69
|
-
const outcome = await scan(url, options);
|
|
70
98
|
if (!outcome.ok) {
|
|
71
99
|
return writeFailure(outcome.error, jsonMode);
|
|
72
100
|
}
|
|
73
101
|
const result = outcome;
|
|
74
|
-
// Attach "why this matters" explanations to each check
|
|
75
|
-
for (const bridge of result.bridges) {
|
|
76
|
-
for (const check of bridge.checks) {
|
|
77
|
-
check.why = resolveExplanation(check.id, check.status);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
102
|
if (jsonMode) {
|
|
81
103
|
process.stdout.write(reportJson(result, Boolean(opts.pretty)) + "\n");
|
|
82
104
|
}
|
|
83
105
|
else if (!quiet) {
|
|
84
|
-
|
|
106
|
+
const output = formatScanOutput(result, verbose, explainAll);
|
|
107
|
+
console.log(opts.color === false ? stripVTControlCharacters(output) : output);
|
|
108
|
+
}
|
|
109
|
+
if (result.bridges[0].abort) {
|
|
110
|
+
process.exitCode = 1;
|
|
111
|
+
if (!jsonMode && !quiet)
|
|
112
|
+
process.stderr.write("Target unreachable: " + terminalText(result.bridges[0].abortReason ?? "unknown") + "\n");
|
|
113
|
+
}
|
|
114
|
+
else if (result.bridges[0].status === "not_evaluated") {
|
|
115
|
+
process.exitCode = 1;
|
|
116
|
+
if (!jsonMode && !quiet)
|
|
117
|
+
process.stderr.write("Reachability not evaluated: " + terminalText(result.bridges[0].message ?? "unknown") + "\n");
|
|
85
118
|
}
|
|
86
119
|
if (threshold !== undefined && result.overallScore < threshold) {
|
|
87
120
|
process.exitCode = 1;
|
|
88
121
|
}
|
|
122
|
+
if (opts.requireComplete && (result.incomplete || result.bridges.some(bridge => bridge.status === "not_evaluated" || bridge.checks.some(check => check.status === "error")))) {
|
|
123
|
+
process.exitCode = 1;
|
|
124
|
+
if (!quiet && !jsonMode)
|
|
125
|
+
process.stderr.write("Scan did not meet --require-complete. Review skipped bridges and errored checks.\n");
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
program.command("diff")
|
|
129
|
+
.description("Compare two saved scan reports without making network requests")
|
|
130
|
+
.argument("<base>", "Base scan JSON file")
|
|
131
|
+
.argument("<candidate>", "Candidate scan JSON file")
|
|
132
|
+
.option("--map-origin <base=candidate>", "Compare explicitly paired preview origins")
|
|
133
|
+
.option("--markdown", "Render a Markdown job summary")
|
|
134
|
+
.option("--json", "Output the comparison as JSON")
|
|
135
|
+
.action(async (basePath, candidatePath, opts) => {
|
|
136
|
+
try {
|
|
137
|
+
if (opts.json && opts.markdown)
|
|
138
|
+
throw new Error("Choose one of --markdown and --json");
|
|
139
|
+
const pair = opts.mapOrigin?.split("=");
|
|
140
|
+
if (pair && (pair.length !== 2 || !pair[0] || !pair[1])) {
|
|
141
|
+
throw new Error("--map-origin requires base-origin=candidate-origin");
|
|
142
|
+
}
|
|
143
|
+
const [base, candidate] = await Promise.all([readReport(basePath), readReport(candidatePath)]);
|
|
144
|
+
const diff = compareReports(base, candidate, { originMap: pair ? { base: pair[0], head: pair[1] } : undefined });
|
|
145
|
+
process.stdout.write((opts.json ? reportJson(diff) : formatReportDiff(diff, Boolean(opts.markdown))) + "\n");
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
writeFailure({ kind: "diff_failed", message: error instanceof Error ? error.message : "Comparison failed" }, Boolean(opts.json));
|
|
149
|
+
}
|
|
89
150
|
});
|
|
151
|
+
for (const command of [program, ...program.commands])
|
|
152
|
+
command.configureOutput({ outputError: () => { } }).exitOverride();
|
|
153
|
+
addJourney(program);
|
|
90
154
|
return program;
|
|
91
155
|
}
|
|
92
|
-
// Resolve
|
|
93
|
-
|
|
156
|
+
// Resolve argv[1] as Node resolves its entry point (extensionless or directory
|
|
157
|
+
// paths, npm bin symlinks). Compare real paths on both sides because
|
|
158
|
+
// --preserve-symlinks-main keeps the symlink in import.meta.url. Embedded
|
|
159
|
+
// callers may have no script on disk.
|
|
160
|
+
let isMain = false;
|
|
94
161
|
try {
|
|
95
162
|
if (process.argv[1])
|
|
96
|
-
|
|
163
|
+
isMain = realpathSync(createRequire(import.meta.url).resolve(resolve(process.argv[1]))) === realpathSync(fileURLToPath(import.meta.url));
|
|
97
164
|
}
|
|
98
165
|
catch {
|
|
99
166
|
// No on-disk entry point.
|
|
100
167
|
}
|
|
101
|
-
if (
|
|
102
|
-
|
|
168
|
+
if (isMain) {
|
|
169
|
+
try {
|
|
170
|
+
await buildProgram().parseAsync(process.argv);
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
if (!(error instanceof CommanderError))
|
|
174
|
+
throw error;
|
|
175
|
+
if (error.exitCode !== 0) {
|
|
176
|
+
if (process.argv[2] !== "journey") {
|
|
177
|
+
// Commander already wrote the usage text for a bare `milieu` or `milieu help <unknown command>`.
|
|
178
|
+
if (error.code === "commander.help")
|
|
179
|
+
process.exitCode = error.exitCode;
|
|
180
|
+
else
|
|
181
|
+
writeFailure({ kind: "usage_error", message: error.message.replace(/^error: /, "").replace(/\n/g, " ") }, process.argv.slice(2).includes("--json"));
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
const { writeJourneyError } = await import("../journey/cli.js");
|
|
185
|
+
writeJourneyError("INVALID_ARGUMENT", error.message, process.argv.slice(3).includes("--json"));
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
103
189
|
}
|
|
104
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** Register only command metadata at startup. Scanner and library callers stay independent. */
|
|
2
|
+
export function addJourney(program) {
|
|
3
|
+
const journey = program.command("journey")
|
|
4
|
+
.description("Observe and verify a scoped documentation or API task")
|
|
5
|
+
.configureOutput({
|
|
6
|
+
// Commander emits help before it parses options. Its text is static CLI metadata.
|
|
7
|
+
writeOut: text => process.stdout.write(process.argv.slice(3).includes("--json")
|
|
8
|
+
? JSON.stringify({ schemaVersion: 1, kind: "journey_help", help: text }) + "\n" : text),
|
|
9
|
+
outputError: () => { }
|
|
10
|
+
})
|
|
11
|
+
.exitOverride();
|
|
12
|
+
const command = (name, description) => journey.command(name)
|
|
13
|
+
.description(description).option("--json", "Write one versioned JSON document")
|
|
14
|
+
.action(async (...args) => {
|
|
15
|
+
const cmd = args.at(-1);
|
|
16
|
+
const { executeJourney } = await import("../journey/cli.js");
|
|
17
|
+
await executeJourney(cmd.name(), cmd.processedArgs, cmd.opts());
|
|
18
|
+
});
|
|
19
|
+
command("demo", "Run both scripted working and broken cases offline");
|
|
20
|
+
command("init", "Create a case template").argument("<case.json>")
|
|
21
|
+
.requiredOption("--kind <kind>", "grounded_answer or api_read");
|
|
22
|
+
command("validate", "Validate a case and all its targets offline").argument("<case.json>");
|
|
23
|
+
command("doctor", "Check provider setup").option("--provider <provider>", "ollama or openai")
|
|
24
|
+
.option("--model <id>", "Model identifier").option("--probe", "Send one synthetic model request");
|
|
25
|
+
command("run", "Run one case against one approved public target").argument("<case.json>")
|
|
26
|
+
.requiredOption("--target <name>", "Target in the case")
|
|
27
|
+
.requiredOption("--provider <provider>", "ollama or openai")
|
|
28
|
+
.requiredOption("--model <id>", "Model identifier")
|
|
29
|
+
.option("--repeat <n>", "Number of fresh serial attempts, 1 through 10", "1");
|
|
30
|
+
command("inspect", "Explain one saved Journey run offline").argument("<run.json>")
|
|
31
|
+
.option("--verbose", "Show every assertion and the ordered event trace");
|
|
32
|
+
command("compare", "Compare two completed reports offline")
|
|
33
|
+
.argument("<baseline.json>").argument("<candidate.json>")
|
|
34
|
+
.option("--gate", "Exit 1 for a matched direct API control regression");
|
|
35
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { parseScanReport } from "../core/validate-report.js";
|
|
2
|
+
import { readJsonFile } from "../utils/read-json-file.js";
|
|
3
|
+
export async function readReport(path) {
|
|
4
|
+
try {
|
|
5
|
+
const value = await readJsonFile(path, 32 * 1024 * 1024);
|
|
6
|
+
return parseScanReport(value);
|
|
7
|
+
}
|
|
8
|
+
catch (error) {
|
|
9
|
+
throw new Error(path + ": " + (error instanceof Error ? error.message : "could not read report"));
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { HttpFailure, SharedState } from "./types.js";
|
|
2
|
+
/** Account for a plain-data graph before V8 allocates its serialization buffer outside the worker heap.
|
|
3
|
+
* The report is consumed as JSON, where each occurrence is written in full. Snapshots preserve object identity.
|
|
4
|
+
*/
|
|
5
|
+
export declare function fitsBridgeOutput(value: unknown, budget: number, preserveReferences: boolean): boolean;
|
|
6
|
+
/** Shared evidence as it crosses to the next bridge: a response whose body is named beside it crosses without it. */
|
|
7
|
+
export declare function packEvidence(shared: SharedState): SharedState;
|
|
8
|
+
/** The evidence a bridge receives, with each such response given its body back. */
|
|
9
|
+
export declare function unpackEvidence(shared: SharedState): SharedState;
|
|
10
|
+
/** A probe request too large to post fails on its own, as a request that was never sent. */
|
|
11
|
+
export declare function oversizedProbe(url: string, options: unknown): HttpFailure | undefined;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Containers one snapshot may hold. The walk tracks each in a table that is a single allocation and doubles as it
|
|
3
|
+
* fills. A worker that could not grow it near its heap limit ended the whole process, not only itself.
|
|
4
|
+
*/
|
|
5
|
+
const SNAPSHOT_MAX_CONTAINERS = 300_000;
|
|
6
|
+
/** Account for a plain-data graph before V8 allocates its serialization buffer outside the worker heap.
|
|
7
|
+
* The report is consumed as JSON, where each occurrence is written in full. Snapshots preserve object identity.
|
|
8
|
+
*/
|
|
9
|
+
export function fitsBridgeOutput(value, budget, preserveReferences) {
|
|
10
|
+
const seen = preserveReferences ? new WeakSet() : undefined;
|
|
11
|
+
let tracked = 0;
|
|
12
|
+
// A snapshot is charged near what V8 writes: Latin-1 text at one byte per character, any number as a double, and a
|
|
13
|
+
// tag with a few length bytes around each value. V8 can hold Latin-1 text in two bytes per character, which is not
|
|
14
|
+
// observable here, so the charge can be up to half the written size. The serialized size stays authoritative.
|
|
15
|
+
const text = (item) => preserveReferences && !/[^\x00-\xff]/.test(item) ? item.length : 2 * item.length;
|
|
16
|
+
const node = (item) => !preserveReferences ? 16
|
|
17
|
+
: typeof item === "number" ? 10 : typeof item === "string" ? 6 : typeof item === "object" && item !== null ? 12 : 1;
|
|
18
|
+
function visit(item, depth) {
|
|
19
|
+
budget -= node(item);
|
|
20
|
+
if (budget < 0 || depth > 256)
|
|
21
|
+
return false;
|
|
22
|
+
if (typeof item === "string") {
|
|
23
|
+
budget -= text(item);
|
|
24
|
+
return budget >= 0;
|
|
25
|
+
}
|
|
26
|
+
if (item == null || typeof item === "boolean" || typeof item === "number")
|
|
27
|
+
return true;
|
|
28
|
+
if (typeof item !== "object")
|
|
29
|
+
return false;
|
|
30
|
+
if (seen) {
|
|
31
|
+
if (seen.has(item))
|
|
32
|
+
return true;
|
|
33
|
+
if (++tracked > SNAPSHOT_MAX_CONTAINERS)
|
|
34
|
+
return false;
|
|
35
|
+
seen.add(item);
|
|
36
|
+
}
|
|
37
|
+
if (Array.isArray(item)) {
|
|
38
|
+
for (const child of item)
|
|
39
|
+
if (!visit(child, depth + 1))
|
|
40
|
+
return false;
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
const prototype = Object.getPrototypeOf(item);
|
|
44
|
+
if (prototype !== null && prototype !== Object.prototype)
|
|
45
|
+
return false;
|
|
46
|
+
for (const key of Object.keys(item)) {
|
|
47
|
+
budget -= (preserveReferences ? 6 : 8) + text(key);
|
|
48
|
+
if (!visit(item[key], depth + 1))
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
return visit(value, 0);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The bodies shared evidence names twice: on their own, and in the response they arrived in. V8 writes a string once
|
|
57
|
+
* for each name and rebuilds each as its own copy, so a 5 MiB homepage with one character outside Latin-1 reached
|
|
58
|
+
* every later bridge as 20 MB, and four such documents were more evidence than a snapshot may hold.
|
|
59
|
+
*/
|
|
60
|
+
const REPEATED = [["pageBody", "pageResponse"], ["llmsTxtBody", "rootLlmsResponse"]];
|
|
61
|
+
/** Shared evidence as it crosses to the next bridge: a response whose body is named beside it crosses without it. */
|
|
62
|
+
export function packEvidence(shared) {
|
|
63
|
+
const packed = { ...shared };
|
|
64
|
+
for (const [body, response] of REPEATED) {
|
|
65
|
+
const held = packed[response];
|
|
66
|
+
if (held?.ok && held.body === packed[body])
|
|
67
|
+
packed[response] = { ...held, body: undefined };
|
|
68
|
+
}
|
|
69
|
+
return packed;
|
|
70
|
+
}
|
|
71
|
+
/** The evidence a bridge receives, with each such response given its body back. */
|
|
72
|
+
export function unpackEvidence(shared) {
|
|
73
|
+
for (const [body, response] of REPEATED) {
|
|
74
|
+
const held = shared[response];
|
|
75
|
+
if (held?.ok && held.body === undefined)
|
|
76
|
+
held.body = shared[body];
|
|
77
|
+
}
|
|
78
|
+
return shared;
|
|
79
|
+
}
|
|
80
|
+
/** A probe request too large to post fails on its own, as a request that was never sent. */
|
|
81
|
+
export function oversizedProbe(url, options) {
|
|
82
|
+
if (fitsBridgeOutput({ url, options }, 64 * 1024, false))
|
|
83
|
+
return undefined;
|
|
84
|
+
// The caller may record the failed URL, so it gets a bounded copy.
|
|
85
|
+
return { ok: false, error: { kind: "unknown", message: "Probe exceeds the analysis output limit", url: url.slice(0, 2048) } };
|
|
86
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type MessagePort } from "node:worker_threads";
|
|
2
|
+
import { type HttpGetOptions } from "../utils/http-client.js";
|
|
3
|
+
import type { BridgeId, BridgeResult, HttpFailure, ScanContext } from "./types.js";
|
|
4
|
+
export interface BridgeJob {
|
|
5
|
+
id: BridgeId;
|
|
6
|
+
context: Omit<ScanContext, "shared">;
|
|
7
|
+
snapshot?: Uint8Array;
|
|
8
|
+
transport: MessagePort;
|
|
9
|
+
}
|
|
10
|
+
export interface BridgeProbe {
|
|
11
|
+
url: string;
|
|
12
|
+
options?: HttpGetOptions;
|
|
13
|
+
binary: boolean;
|
|
14
|
+
reply: MessagePort;
|
|
15
|
+
}
|
|
16
|
+
export interface BridgeReply<Id extends BridgeId> {
|
|
17
|
+
result: BridgeResult<Id>;
|
|
18
|
+
snapshot?: Uint8Array;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* What a probe answers its bridge. One the probe deadline cut off answers as a timeout: "cancelled" is the caller's
|
|
22
|
+
* own cancellation, which no check has to grade. Any other answer stands, however late it arrived.
|
|
23
|
+
*/
|
|
24
|
+
export declare function probeReply<Response extends {
|
|
25
|
+
ok: true;
|
|
26
|
+
} | HttpFailure>(response: Response, deadlinePassed: boolean): Response | HttpFailure;
|
|
27
|
+
/** Keep the shared evidence opaque in the parent. Only bridge workers reconstruct and inspect it. */
|
|
28
|
+
export declare function createBridgeRunner(ctx: ScanContext): <Id extends BridgeId>(id: Id) => Promise<BridgeResult<Id>>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { MessageChannel } from "node:worker_threads";
|
|
2
|
+
import { ANALYSIS_TIME_LIMIT_MS, runAnalysisWorker } from "../utils/analysis-worker.js";
|
|
3
|
+
import { httpGet, httpGetBytes } from "../utils/http-client.js";
|
|
4
|
+
/**
|
|
5
|
+
* What a probe answers its bridge. One the probe deadline cut off answers as a timeout: "cancelled" is the caller's
|
|
6
|
+
* own cancellation, which no check has to grade. Any other answer stands, however late it arrived.
|
|
7
|
+
*/
|
|
8
|
+
export function probeReply(response, deadlinePassed) {
|
|
9
|
+
return deadlinePassed && !response.ok && response.error.kind === "cancelled"
|
|
10
|
+
? { ok: false, error: { kind: "timeout", message: "Bridge time limit reached", url: response.error.url } } : response;
|
|
11
|
+
}
|
|
12
|
+
/** Keep the shared evidence opaque in the parent. Only bridge workers reconstruct and inspect it. */
|
|
13
|
+
export function createBridgeRunner(ctx) {
|
|
14
|
+
let snapshot;
|
|
15
|
+
const { signal, timeout, registryLookup } = ctx.options;
|
|
16
|
+
const context = { url: ctx.url, domain: ctx.domain, baseUrl: ctx.baseUrl, options: { timeout, registryLookup } };
|
|
17
|
+
return async (id) => {
|
|
18
|
+
const { port1, port2 } = new MessageChannel();
|
|
19
|
+
const lifetime = new AbortController();
|
|
20
|
+
// Probes stop before the bridge time limit, so the bridge can still report what it measured.
|
|
21
|
+
// Reachability keeps the whole limit: it reads a timeout as the site being unreachable, and a probe ended
|
|
22
|
+
// early, or never sent, would say that of a homepage that was not given its time.
|
|
23
|
+
const probes = new AbortController();
|
|
24
|
+
const deadline = id === 1 ? undefined : setTimeout(() => probes.abort(), ANALYSIS_TIME_LIMIT_MS * 5 / 6);
|
|
25
|
+
const probeSignal = AbortSignal.any([lifetime.signal, probes.signal]);
|
|
26
|
+
port1.on("message", async ({ url, options: probe, binary, reply }) => {
|
|
27
|
+
try {
|
|
28
|
+
if (lifetime.signal.aborted)
|
|
29
|
+
return;
|
|
30
|
+
const request = { ...probe, signal: probeSignal };
|
|
31
|
+
const response = await (binary ? httpGetBytes(url, request) : httpGet(url, request));
|
|
32
|
+
if (lifetime.signal.aborted)
|
|
33
|
+
return;
|
|
34
|
+
reply.postMessage(probeReply(response, probes.signal.aborted));
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
if (!lifetime.signal.aborted)
|
|
38
|
+
reply.postMessage({ ok: false, error: { kind: "unknown", url, message: "Probe failed" } });
|
|
39
|
+
}
|
|
40
|
+
finally {
|
|
41
|
+
reply.close();
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
try {
|
|
45
|
+
const job = { id, context, snapshot, transport: port2 };
|
|
46
|
+
const output = await runAnalysisWorker(new URL("./bridge-worker.js", import.meta.url), job, { signal, timeoutMs: ANALYSIS_TIME_LIMIT_MS, transferList: [port2] });
|
|
47
|
+
if (output.snapshot)
|
|
48
|
+
snapshot = output.snapshot;
|
|
49
|
+
return output.result;
|
|
50
|
+
}
|
|
51
|
+
finally {
|
|
52
|
+
clearTimeout(deadline);
|
|
53
|
+
lifetime.abort();
|
|
54
|
+
port1.close();
|
|
55
|
+
port2.close();
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { workerData, MessageChannel } from "node:worker_threads";
|
|
2
|
+
import { serialize, deserialize } from "node:v8";
|
|
3
|
+
import { runReachabilityBridge, runStandardsBridge, runSeparationBridge, runSchemaBridge, runContextBridge, } from "../bridges/index.js";
|
|
4
|
+
import { runWithBridgeTransport } from "../utils/http-client.js";
|
|
5
|
+
import { analysisLimit, finishAnalysis } from "../utils/analysis-worker-entry.js";
|
|
6
|
+
import { fitsBridgeOutput, oversizedProbe, packEvidence, unpackEvidence } from "./bridge-output.js";
|
|
7
|
+
const job = workerData;
|
|
8
|
+
const runners = { 1: runReachabilityBridge, 2: runStandardsBridge, 3: runSeparationBridge, 4: runSchemaBridge, 5: runContextBridge };
|
|
9
|
+
function probe(url, options, binary) {
|
|
10
|
+
// Not retried, not counted against the request budget, and never read as the target being unreachable.
|
|
11
|
+
const refused = oversizedProbe(url, options);
|
|
12
|
+
if (refused)
|
|
13
|
+
return Promise.resolve(refused);
|
|
14
|
+
return new Promise(resolve => {
|
|
15
|
+
const { port1, port2 } = new MessageChannel();
|
|
16
|
+
port1.once("message", (value) => { port1.close(); resolve(value); });
|
|
17
|
+
const request = { url, options, binary, reply: port2 };
|
|
18
|
+
job.transport.postMessage(request, [port2]);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
async function analyzeBridge() {
|
|
22
|
+
const shared = job.snapshot ? unpackEvidence(deserialize(job.snapshot)) : {};
|
|
23
|
+
// Parsed here, in the bridges that read it. As a structured clone the spec cost every later bridge several times
|
|
24
|
+
// its JSON text, and Separation does not read it at all.
|
|
25
|
+
if (job.id >= 4 && shared.openApiSpecText)
|
|
26
|
+
shared.openApiSpec = JSON.parse(shared.openApiSpecText);
|
|
27
|
+
const context = { ...job.context, shared };
|
|
28
|
+
const result = await runWithBridgeTransport({
|
|
29
|
+
get: (url, options) => probe(url, options, false),
|
|
30
|
+
bytes: (url, options) => probe(url, options, true),
|
|
31
|
+
}, () => runners[job.id](context));
|
|
32
|
+
// Bound both structured data crossing to the caller and evidence retained for the next bridge.
|
|
33
|
+
const reportLimit = 2 * 1024 * 1024;
|
|
34
|
+
const snapshotLimit = 48 * 1024 * 1024;
|
|
35
|
+
if (!fitsBridgeOutput(result, reportLimit, false)) {
|
|
36
|
+
analysisLimit("Bridge report exceeds the analysis output limit");
|
|
37
|
+
}
|
|
38
|
+
else if (job.id <= 2 && !result.abort) {
|
|
39
|
+
const evidence = packEvidence(context.shared);
|
|
40
|
+
if (!fitsBridgeOutput(evidence, snapshotLimit, true)) {
|
|
41
|
+
analysisLimit("Shared evidence exceeds the analysis output limit");
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
const snapshot = serialize(evidence);
|
|
45
|
+
if (snapshot.byteLength > snapshotLimit)
|
|
46
|
+
analysisLimit("Shared evidence exceeds the analysis output limit");
|
|
47
|
+
else
|
|
48
|
+
finishAnalysis({ result, snapshot }, [snapshot.buffer]);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
finishAnalysis({ result });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
await analyzeBridge();
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
if (error instanceof RangeError)
|
|
60
|
+
analysisLimit("Bridge exceeds analysis capacity");
|
|
61
|
+
else
|
|
62
|
+
throw new Error("Bridge analysis failed");
|
|
63
|
+
}
|
|
64
|
+
finally {
|
|
65
|
+
job.transport.close();
|
|
66
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { BridgeId, BridgeName, CheckStatus, ScanResult } from "./types.js";
|
|
2
|
+
export interface DiffOptions {
|
|
3
|
+
/** Map only these two scan origins. External resources retain their absolute identity. */
|
|
4
|
+
originMap?: {
|
|
5
|
+
base: string;
|
|
6
|
+
head: string;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export type AuthSummary = {
|
|
10
|
+
httpStatus?: number;
|
|
11
|
+
guidance?: string[];
|
|
12
|
+
challenged: boolean;
|
|
13
|
+
};
|
|
14
|
+
export type RouteSummary = {
|
|
15
|
+
count: number;
|
|
16
|
+
complete: boolean;
|
|
17
|
+
} | null;
|
|
18
|
+
export type Coverage = "complete" | "incomplete" | "unavailable" | "evaluated" | "not evaluated" | "schema verified" | "schema unverified";
|
|
19
|
+
/** Structured observations for the shareable summary. Local descriptions can contain site-provided text. */
|
|
20
|
+
export type FindingEvidence = {
|
|
21
|
+
kind: "status";
|
|
22
|
+
before: CheckStatus | null;
|
|
23
|
+
after: CheckStatus | null;
|
|
24
|
+
} | {
|
|
25
|
+
kind: "coverage";
|
|
26
|
+
source: "bridge" | "docs" | "linked" | "fetched" | "package";
|
|
27
|
+
before: Coverage;
|
|
28
|
+
after: Coverage;
|
|
29
|
+
beforeTarget?: string;
|
|
30
|
+
afterTarget?: string;
|
|
31
|
+
} | {
|
|
32
|
+
kind: "auth";
|
|
33
|
+
before: AuthSummary;
|
|
34
|
+
after: AuthSummary;
|
|
35
|
+
} | {
|
|
36
|
+
kind: "routes";
|
|
37
|
+
before: RouteSummary;
|
|
38
|
+
after: RouteSummary;
|
|
39
|
+
contract?: string;
|
|
40
|
+
} | {
|
|
41
|
+
kind: "link";
|
|
42
|
+
channel: "linked" | "fetched" | "package";
|
|
43
|
+
before: boolean;
|
|
44
|
+
after: boolean;
|
|
45
|
+
};
|
|
46
|
+
interface Change {
|
|
47
|
+
kind: "regression" | "improvement" | "inventory" | "inconclusive";
|
|
48
|
+
before: string;
|
|
49
|
+
after: string;
|
|
50
|
+
verification: string;
|
|
51
|
+
target?: string;
|
|
52
|
+
evidence?: FindingEvidence;
|
|
53
|
+
/** Stable capability identifier for a change in its published entry routes. */
|
|
54
|
+
capabilityId?: string;
|
|
55
|
+
}
|
|
56
|
+
export interface DiffFinding extends Change {
|
|
57
|
+
bridgeId: BridgeId;
|
|
58
|
+
bridgeName: BridgeName;
|
|
59
|
+
checkId: string | null;
|
|
60
|
+
label: string;
|
|
61
|
+
}
|
|
62
|
+
declare const SCAN_SETTINGS: readonly ["timeoutMs", "maxConcurrency", "maxRequests", "deadlineMs", "registryLookup"];
|
|
63
|
+
export interface ReportDiff {
|
|
64
|
+
baseOrigin: string;
|
|
65
|
+
headOrigin: string;
|
|
66
|
+
baseIncomplete: boolean;
|
|
67
|
+
headIncomplete: boolean;
|
|
68
|
+
version: string;
|
|
69
|
+
findings: DiffFinding[];
|
|
70
|
+
/** Effective settings. Counts describe execution and are not configuration changes. */
|
|
71
|
+
settingsChanges?: {
|
|
72
|
+
setting: typeof SCAN_SETTINGS[number];
|
|
73
|
+
before: number | boolean | null;
|
|
74
|
+
after: number | boolean | null;
|
|
75
|
+
}[];
|
|
76
|
+
}
|
|
77
|
+
/** Compare observations offline. Scores, timings, prose-only changes and result ordering are ignored. */
|
|
78
|
+
export declare function compareReports(base: ScanResult, head: ScanResult, options?: DiffOptions): ReportDiff;
|
|
79
|
+
export {};
|