@jini-ai/diagnostics 0.1.1 → 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.
Files changed (67) hide show
  1. package/CHANGELOG.md +79 -0
  2. package/README.md +114 -0
  3. package/dist/agent-logs.d.ts +9 -4
  4. package/dist/agent-logs.js +14 -15
  5. package/dist/domain-dns/index.d.ts +136 -0
  6. package/dist/domain-dns/index.js +117 -0
  7. package/dist/index.d.ts +41 -3
  8. package/dist/index.js +38 -1
  9. package/dist/manifest.d.ts +22 -16
  10. package/dist/manifest.js +9 -19
  11. package/dist/node-ports.d.ts +6 -0
  12. package/dist/node-ports.js +57 -0
  13. package/dist/observability/config.d.ts +24 -0
  14. package/dist/observability/config.js +21 -0
  15. package/dist/observability/hooks.d.ts +18 -0
  16. package/dist/observability/hooks.js +24 -0
  17. package/dist/observability/index.d.ts +14 -0
  18. package/dist/observability/index.js +14 -0
  19. package/dist/observability/noop.d.ts +4 -0
  20. package/dist/observability/noop.js +6 -0
  21. package/dist/observability/otel.d.ts +14 -0
  22. package/dist/observability/otel.js +28 -0
  23. package/dist/observability/ports.d.ts +79 -0
  24. package/dist/observability/ports.js +2 -0
  25. package/dist/ports.d.ts +45 -0
  26. package/dist/ports.js +2 -0
  27. package/dist/redaction/secret-patterns.d.ts +8 -0
  28. package/dist/redaction/secret-patterns.js +18 -0
  29. package/dist/redaction/secrets-only.d.ts +44 -0
  30. package/dist/redaction/secrets-only.js +179 -0
  31. package/dist/redaction.d.ts +12 -3
  32. package/dist/redaction.js +18 -8
  33. package/dist/sources.d.ts +22 -12
  34. package/dist/sources.js +22 -42
  35. package/dist/types.d.ts +24 -0
  36. package/dist/types.js +2 -0
  37. package/dist/web-evidence/browser-port.d.ts +166 -0
  38. package/dist/web-evidence/browser-port.js +6 -0
  39. package/dist/web-evidence/collect-page-evidence.d.ts +160 -0
  40. package/dist/web-evidence/collect-page-evidence.js +215 -0
  41. package/dist/web-evidence/index.d.ts +5 -0
  42. package/dist/web-evidence/index.js +5 -0
  43. package/dist/web-evidence/page-structure-script.d.ts +53 -0
  44. package/dist/web-evidence/page-structure-script.js +338 -0
  45. package/dist/web-evidence/page-work-budget.d.ts +27 -0
  46. package/dist/web-evidence/page-work-budget.js +53 -0
  47. package/dist/web-evidence/playwright-browser.d.ts +131 -0
  48. package/dist/web-evidence/playwright-browser.js +349 -0
  49. package/dist/web-evidence/same-origin.d.ts +126 -0
  50. package/dist/web-evidence/same-origin.js +141 -0
  51. package/dist/zip.d.ts +8 -3
  52. package/dist/zip.js +23 -16
  53. package/package.json +46 -5
  54. package/dist/agent-logs.d.ts.map +0 -1
  55. package/dist/agent-logs.js.map +0 -1
  56. package/dist/contract.d.ts.map +0 -1
  57. package/dist/contract.js.map +0 -1
  58. package/dist/index.d.ts.map +0 -1
  59. package/dist/index.js.map +0 -1
  60. package/dist/manifest.d.ts.map +0 -1
  61. package/dist/manifest.js.map +0 -1
  62. package/dist/redaction.d.ts.map +0 -1
  63. package/dist/redaction.js.map +0 -1
  64. package/dist/sources.d.ts.map +0 -1
  65. package/dist/sources.js.map +0 -1
  66. package/dist/zip.d.ts.map +0 -1
  67. package/dist/zip.js.map +0 -1
@@ -0,0 +1,160 @@
1
+ import type { Clock } from "@jini-ai/core/primitives";
2
+ /**
3
+ * @file `collectPageEvidence()` — the bounded orchestration behind the `site_collect_page_evidence`
4
+ * agent tool. Resolves the workspace's own verified origin, normalizes each requested path, drives
5
+ * the browser port once per page, and returns observed evidence.
6
+ *
7
+ * ---------------------------------------------------------------------------
8
+ * The one rule this module exists to enforce: evidence, never a verdict
9
+ * ---------------------------------------------------------------------------
10
+ * Nothing here scores, grades, passes, fails, or maps an observation to a regulation. There is no
11
+ * `compliant` field and no place to put one. The tool reports what was seen and where it was seen;
12
+ * deciding what that means is the `site-compliance` skill's job, under an output contract that
13
+ * forbids it from stating a verdict either. Both halves have to hold — a tool that returned
14
+ * `{ gdprCookieCheck: "pass" }` would make the skill's contract unenforceable, because the verdict
15
+ * would already have been asserted upstream of it.
16
+ *
17
+ * Two consequences worth naming, because they look like missing features and are not:
18
+ * - A page that could not be loaded produces a `skipped` entry with a reason, never an empty
19
+ * observation. "Nothing observed" and "observed nothing" are different facts and a report that
20
+ * confuses them is worse than no report.
21
+ * - When the browser is unavailable, EVERY page is `skipped` with that reason and `pages` is empty.
22
+ * There is no configuration-derived fallback, because a fallback would be a guess wearing the
23
+ * evidence tool's credibility.
24
+ *
25
+ * ---------------------------------------------------------------------------
26
+ * Bounds
27
+ * ---------------------------------------------------------------------------
28
+ * Every axis a hostile or careless caller could drive unbounded is capped by
29
+ * {@link SITE_EVIDENCE_LIMITS}, and each cap is reported back in the result so a reader can tell a
30
+ * truncated list from a complete one. Per skills/implementation-guardrails' resource-bounds rule:
31
+ * maximum collection size (`maxPagesPerCall`), per-call timeout (`maxPageLoadMs`), overall deadline
32
+ * (`maxTotalMs`), and explicit behaviour at the cap (excess pages are `skipped` with reason
33
+ * `page-cap`, never silently dropped).
34
+ *
35
+ * ---------------------------------------------------------------------------
36
+ * Nothing is persisted
37
+ * ---------------------------------------------------------------------------
38
+ * This module writes no file, no database row, and no cache. The browser adapter uses an ephemeral
39
+ * context with no user-data directory. What the tool observed exists only in the value it returns,
40
+ * and the shapes in `browser-port.ts` cannot represent a cookie value, a request body, or a form
41
+ * field's contents in the first place.
42
+ *
43
+ * Architectural role:
44
+ * Pure orchestration over two injected dependencies (an origin resolver and a browser factory).
45
+ * No global state, no module-level singletons — `tool-registrations.ts` supplies both.
46
+ */
47
+ import type { VerifiedOriginPort } from "./same-origin.js";
48
+ import type { ObservationPhase, PageObservation, SiteEvidenceBrowserFactory } from "./browser-port.js";
49
+ /**
50
+ * Every bound this tool operates under, in one place so the values reported to the caller and the
51
+ * values actually enforced cannot drift apart (they are the same constant).
52
+ *
53
+ * The numbers are deliberately small. This is an interactive tool an agent calls mid-conversation,
54
+ * not a crawler: five pages is enough to screen a home page, a form page, and the policy pages,
55
+ * and a caller who needs more can call again with the next five and say so in its report.
56
+ */
57
+ export declare const SITE_EVIDENCE_LIMITS: {
58
+ /** Hard cap on pages per call. Excess requested paths are returned as `skipped`. */
59
+ readonly maxPagesPerCall: 5;
60
+ /** Per-page navigation + settle budget, including evaluation and cookie capture. */
61
+ readonly maxPageLoadMs: 15000;
62
+ /** Whole-call deadline. Once passed, remaining pages are `skipped` with `deadline`. */
63
+ readonly maxTotalMs: 60000;
64
+ /** Cap on the visible-text excerpt returned per page. */
65
+ readonly maxTextExcerptChars: 2000;
66
+ readonly maxCookies: 100;
67
+ readonly maxRequests: 200;
68
+ /** Cap per accessibility category (landmarks, headings, images, form controls). */
69
+ readonly maxAccessibilityNodesPerCategory: 200;
70
+ readonly maxContrastSamples: 40;
71
+ };
72
+ /** Stated in every result. Not decoration: it is the tool half of the no-verdict contract, and it
73
+ * travels with the data into whatever context the model is reasoning in. */
74
+ export declare const SITE_EVIDENCE_DISCLAIMER: string;
75
+ export type SkippedPageReason = "invalid-path" | "page-cap" | "deadline" | "browser-unavailable" | "off-origin-redirect" | "navigation-failed";
76
+ export interface SkippedPage {
77
+ readonly path: string;
78
+ readonly reason: SkippedPageReason;
79
+ readonly message: string;
80
+ }
81
+ export interface PageEvidence {
82
+ /** The site-relative path as normalized — the citation key a report should quote. */
83
+ readonly path: string;
84
+ readonly url: string;
85
+ readonly observation: PageObservation;
86
+ }
87
+ export type BrowserAvailabilityReport = {
88
+ readonly status: "available";
89
+ } | {
90
+ readonly status: "unavailable";
91
+ readonly reason: string;
92
+ };
93
+ export interface SiteEvidenceResult {
94
+ readonly schemaVersion: "1";
95
+ readonly collectedAt: string;
96
+ /** The workspace's own verified origin — every URL below is on it, by construction. */
97
+ readonly origin: string;
98
+ readonly browser: BrowserAvailabilityReport;
99
+ /** Whether a consent interaction was performed, and therefore whether `phase: "after"` evidence
100
+ * means anything on this run. */
101
+ readonly consentTransition: ConsentTransitionReport;
102
+ readonly limits: typeof SITE_EVIDENCE_LIMITS;
103
+ readonly pages: readonly PageEvidence[];
104
+ readonly skipped: readonly SkippedPage[];
105
+ readonly disclaimer: string;
106
+ }
107
+ export type ConsentTransitionReport = {
108
+ readonly attempted: false;
109
+ readonly reason: string;
110
+ } | {
111
+ readonly attempted: true;
112
+ readonly selector: string;
113
+ };
114
+ export interface CollectPageEvidenceDeps {
115
+ readonly workspaceId: string;
116
+ readonly originRegistry: VerifiedOriginPort;
117
+ readonly openBrowser: SiteEvidenceBrowserFactory;
118
+ readonly observationPolicy: ObservationPolicy;
119
+ }
120
+ /** Host policy runs before any browser-derived observation or failure message is returned. */
121
+ export interface ObservationPolicy {
122
+ redactObservation(required: {
123
+ observation: PageObservation;
124
+ }): PageObservation;
125
+ redactMessage(required: {
126
+ message: string;
127
+ }): string;
128
+ }
129
+ export interface CollectPageEvidenceOptions {
130
+ readonly clock?: Clock;
131
+ /** CSS selector for the site's own consent-accept control. Without it no interaction happens and
132
+ * no `after`-phase evidence is produced — an omission the result states explicitly rather than
133
+ * leaving the caller to infer from an empty phase. */
134
+ readonly consentAcceptSelector?: string;
135
+ /** Defaults to true. Turning it off is a token-cost choice for a caller that only wants
136
+ * cookie/request evidence, not a way to make a page load cheaper. */
137
+ readonly collectAccessibility?: boolean;
138
+ }
139
+ /**
140
+ * Collects observed evidence for up to {@link SITE_EVIDENCE_LIMITS.maxPagesPerCall} pages of this
141
+ * workspace's own published site.
142
+ *
143
+ * @param deps - Requested paths, verified-origin resolver, browser factory, and observation policy.
144
+ * @param input - Optional clock, accessibility capture and consent selector.
145
+ * @returns Observed evidence plus an explicit account of everything that was not observed and why.
146
+ * @throws The origin port's error if the workspace has no verified
147
+ * canonical origin. Deliberately propagated rather than converted into a per-page skip: with no
148
+ * origin there is no same-origin boundary to enforce, and guessing one from a request host is
149
+ * precisely what F2 forbids. The tool handler turns it into an actionable message.
150
+ * @complexity O(p) page loads bounded by `maxPagesPerCall`, each bounded by `maxPageLoadMs`, the
151
+ * whole call bounded by `maxTotalMs`. Space is bounded by the per-category caps above.
152
+ * See docs/decisions/DR-001-trusted-evidence-addresses.md.
153
+ */
154
+ export declare function collectPageEvidence(deps: CollectPageEvidenceDeps & {
155
+ readonly paths: readonly string[];
156
+ }, input?: CollectPageEvidenceOptions): Promise<SiteEvidenceResult>;
157
+ /** Re-exported so a caller building a report has the phase vocabulary without importing the port
158
+ * module directly. */
159
+ export type { ObservationPhase };
160
+ //# sourceMappingURL=collect-page-evidence.d.ts.map
@@ -0,0 +1,215 @@
1
+ import { PageWorkBudget, PageWorkTimeout } from "./page-work-budget.js";
2
+ import { isSameOriginUrl, normalizeSitePath, resolveSameOriginUrl, verifiedOriginToBaseUrl } from "./same-origin.js";
3
+ /**
4
+ * Every bound this tool operates under, in one place so the values reported to the caller and the
5
+ * values actually enforced cannot drift apart (they are the same constant).
6
+ *
7
+ * The numbers are deliberately small. This is an interactive tool an agent calls mid-conversation,
8
+ * not a crawler: five pages is enough to screen a home page, a form page, and the policy pages,
9
+ * and a caller who needs more can call again with the next five and say so in its report.
10
+ */
11
+ export const SITE_EVIDENCE_LIMITS = {
12
+ /** Hard cap on pages per call. Excess requested paths are returned as `skipped`. */
13
+ maxPagesPerCall: 5,
14
+ /** Per-page navigation + settle budget, including evaluation and cookie capture. */
15
+ maxPageLoadMs: 15_000,
16
+ /** Whole-call deadline. Once passed, remaining pages are `skipped` with `deadline`. */
17
+ maxTotalMs: 60_000,
18
+ /** Cap on the visible-text excerpt returned per page. */
19
+ maxTextExcerptChars: 2_000,
20
+ maxCookies: 100,
21
+ maxRequests: 200,
22
+ /** Cap per accessibility category (landmarks, headings, images, form controls). */
23
+ maxAccessibilityNodesPerCategory: 200,
24
+ maxContrastSamples: 40,
25
+ };
26
+ /** Stated in every result. Not decoration: it is the tool half of the no-verdict contract, and it
27
+ * travels with the data into whatever context the model is reasoning in. */
28
+ export const SITE_EVIDENCE_DISCLAIMER = "Observed evidence only. This tool reports what was rendered, requested, and set when these pages " +
29
+ "were loaded. It does not evaluate, score, or determine compliance with GDPR, CCPA/CPRA, WCAG, or " +
30
+ "any other law or standard, and the absence of an observation is not evidence that something is " +
31
+ "absent — it may mean it was not inspected.";
32
+ /**
33
+ * Collects observed evidence for up to {@link SITE_EVIDENCE_LIMITS.maxPagesPerCall} pages of this
34
+ * workspace's own published site.
35
+ *
36
+ * @param deps - Requested paths, verified-origin resolver, browser factory, and observation policy.
37
+ * @param input - Optional clock, accessibility capture and consent selector.
38
+ * @returns Observed evidence plus an explicit account of everything that was not observed and why.
39
+ * @throws The origin port's error if the workspace has no verified
40
+ * canonical origin. Deliberately propagated rather than converted into a per-page skip: with no
41
+ * origin there is no same-origin boundary to enforce, and guessing one from a request host is
42
+ * precisely what F2 forbids. The tool handler turns it into an actionable message.
43
+ * @complexity O(p) page loads bounded by `maxPagesPerCall`, each bounded by `maxPageLoadMs`, the
44
+ * whole call bounded by `maxTotalMs`. Space is bounded by the per-category caps above.
45
+ * See docs/decisions/DR-001-trusted-evidence-addresses.md.
46
+ */
47
+ export async function collectPageEvidence(deps, input = {}) {
48
+ const clock = input.clock;
49
+ const now = clock ? () => clock.nowMs() : Date.now;
50
+ const startedAt = now();
51
+ const origin = await deps.originRegistry.canonicalOrigin({ workspaceId: deps.workspaceId });
52
+ const originBaseUrl = verifiedOriginToBaseUrl({ origin });
53
+ const { accepted, skipped } = partitionRequestedPaths(deps.paths);
54
+ const availability = await deps.openBrowser({});
55
+ if (!availability.available) {
56
+ const reason = deps.observationPolicy.redactMessage({ message: availability.reason });
57
+ return {
58
+ schemaVersion: "1",
59
+ collectedAt: new Date(startedAt).toISOString(),
60
+ origin: originBaseUrl,
61
+ browser: { status: "unavailable", reason },
62
+ consentTransition: consentTransitionReport(input.consentAcceptSelector),
63
+ limits: SITE_EVIDENCE_LIMITS,
64
+ pages: [],
65
+ skipped: [
66
+ ...skipped,
67
+ ...accepted.map((path) => skip(path, "browser-unavailable", reason)),
68
+ ],
69
+ disclaimer: SITE_EVIDENCE_DISCLAIMER,
70
+ };
71
+ }
72
+ const pages = [];
73
+ const runtimeSkipped = [];
74
+ try {
75
+ for (const path of accepted) {
76
+ const remainingMs = SITE_EVIDENCE_LIMITS.maxTotalMs - (now() - startedAt);
77
+ if (remainingMs <= 0) {
78
+ runtimeSkipped.push(skip(path, "deadline", `the ${SITE_EVIDENCE_LIMITS.maxTotalMs}ms whole-call budget was exhausted before this page was loaded`));
79
+ continue;
80
+ }
81
+ // A THROWING `observe()` (a port implementation that does not honor the `{ ok: false, reason }`
82
+ // contract for every failure — e.g. the page navigating away between the load and the read
83
+ // that follows it) must not end the whole run any more than an ordinary `ok: false` does. One
84
+ // bad page is recorded as skipped; every OTHER requested page still gets its own attempt.
85
+ try {
86
+ // The port's timeout is advisory for custom adapters; bound our own await as well.
87
+ const timeoutMs = Math.min(SITE_EVIDENCE_LIMITS.maxPageLoadMs, remainingMs);
88
+ const outcome = await new PageWorkBudget({ timeoutMs }).run({
89
+ work: () => observeOnePage(availability.browser, originBaseUrl, path, input, timeoutMs),
90
+ });
91
+ if (outcome.kind === "skipped") {
92
+ runtimeSkipped.push({ ...outcome.skipped, message: deps.observationPolicy.redactMessage({ message: outcome.skipped.message }) });
93
+ }
94
+ else {
95
+ pages.push({ ...outcome.page, observation: deps.observationPolicy.redactObservation({ observation: outcome.page.observation }) });
96
+ }
97
+ }
98
+ catch (error) {
99
+ const reason = error instanceof PageWorkTimeout && remainingMs <= SITE_EVIDENCE_LIMITS.maxPageLoadMs ? "deadline" : "navigation-failed";
100
+ runtimeSkipped.push(skip(path, reason, deps.observationPolicy.redactMessage({ message: messageOf(error) })));
101
+ }
102
+ }
103
+ }
104
+ finally {
105
+ // Release is still attempted after expiry; cleanup cannot add an unbounded wait to the call.
106
+ await new PageWorkBudget({ timeoutMs: Math.max(0, SITE_EVIDENCE_LIMITS.maxTotalMs - (now() - startedAt)) })
107
+ .release({ close: () => availability.browser.close({}) });
108
+ }
109
+ return {
110
+ schemaVersion: "1",
111
+ collectedAt: new Date(startedAt).toISOString(),
112
+ origin: originBaseUrl,
113
+ browser: { status: "available" },
114
+ consentTransition: consentTransitionReport(input.consentAcceptSelector),
115
+ limits: SITE_EVIDENCE_LIMITS,
116
+ pages,
117
+ skipped: [...skipped, ...runtimeSkipped],
118
+ disclaimer: SITE_EVIDENCE_DISCLAIMER,
119
+ };
120
+ }
121
+ /**
122
+ * Resolves, loads, and validates exactly one requested page. Split out of
123
+ * {@link collectPageEvidence} purely to keep that function's own cognitive complexity below the
124
+ * repo's gate — the request shape, the failure handling, and the second same-origin check
125
+ * (`same-origin.ts`'s header, layer 2) are unchanged.
126
+ *
127
+ * @complexity O(1) plus one browser page load.
128
+ */
129
+ async function observeOnePage(browser, originBaseUrl, path, input, timeoutMs) {
130
+ const url = resolveSameOriginUrl({ baseUrl: originBaseUrl, path });
131
+ const result = await browser.observe({
132
+ url,
133
+ originBaseUrl,
134
+ collectAccessibility: input.collectAccessibility ?? true,
135
+ timeoutMs,
136
+ maxTextExcerptChars: SITE_EVIDENCE_LIMITS.maxTextExcerptChars,
137
+ maxCookies: SITE_EVIDENCE_LIMITS.maxCookies,
138
+ maxRequests: SITE_EVIDENCE_LIMITS.maxRequests,
139
+ maxAccessibilityNodesPerCategory: SITE_EVIDENCE_LIMITS.maxAccessibilityNodesPerCategory,
140
+ maxContrastSamples: SITE_EVIDENCE_LIMITS.maxContrastSamples,
141
+ }, input.consentAcceptSelector === undefined ? {} : { consentAcceptSelector: input.consentAcceptSelector });
142
+ if (!result.ok) {
143
+ return { kind: "skipped", skipped: skip(path, "navigation-failed", result.reason) };
144
+ }
145
+ // Second same-origin layer (`same-origin.ts`'s header, layer 2): the path could not name
146
+ // another origin, but the SERVER can redirect to one. A page that left the origin is reported
147
+ // as evidence of the redirect and its content is discarded — this tool does not inspect
148
+ // anybody else's site, including one the inspected origin chose to point at.
149
+ const finalUrl = result.observation.document.finalUrl;
150
+ if (!isSameOriginUrl({ baseUrl: originBaseUrl, candidateUrl: finalUrl })) {
151
+ return {
152
+ kind: "skipped",
153
+ skipped: skip(path, "off-origin-redirect", `redirected off the inspected origin to '${redactToOrigin(finalUrl)}' — not inspected; this tool only observes ${originBaseUrl}`),
154
+ };
155
+ }
156
+ return { kind: "observed", page: { path, url, observation: result.observation } };
157
+ }
158
+ /**
159
+ * Splits the requested paths into the ones this call will attempt and the ones it will not,
160
+ * applying the syntactic guard first and the page cap second.
161
+ *
162
+ * Order matters and is not arbitrary: validating before capping means five valid paths followed by
163
+ * an absolute URL still reports the absolute URL as `invalid-path` rather than hiding it behind
164
+ * `page-cap`, so a caller that is doing something the tool refuses always learns that it was
165
+ * refused rather than that it was merely truncated.
166
+ *
167
+ * @complexity O(n) in the requested-path count.
168
+ */
169
+ function partitionRequestedPaths(paths) {
170
+ const accepted = [];
171
+ const skipped = [];
172
+ for (const raw of paths) {
173
+ const normalized = normalizeSitePath({ raw });
174
+ if (!normalized.ok) {
175
+ skipped.push(skip(raw, "invalid-path", `${normalized.message} (${normalized.reason})`));
176
+ continue;
177
+ }
178
+ if (accepted.length >= SITE_EVIDENCE_LIMITS.maxPagesPerCall) {
179
+ skipped.push(skip(normalized.path, "page-cap", `this call already accepted the maximum of ${SITE_EVIDENCE_LIMITS.maxPagesPerCall} pages — request the remaining paths in a follow-up call`));
180
+ continue;
181
+ }
182
+ accepted.push(normalized.path);
183
+ }
184
+ return { accepted, skipped };
185
+ }
186
+ function consentTransitionReport(selector) {
187
+ if (selector === undefined) {
188
+ return {
189
+ attempted: false,
190
+ reason: "no consentAcceptSelector was supplied, so no consent interaction was performed. Every cookie and " +
191
+ "request below was observed in the pre-consent phase; nothing here shows what changes after a visitor accepts.",
192
+ };
193
+ }
194
+ return { attempted: true, selector };
195
+ }
196
+ /** Reduces an off-origin URL to its origin before it appears in a skip reason. The redirect target
197
+ * is the evidence; its path and query are somebody else's data and may carry identifiers this tool
198
+ * has no business echoing back into a model's context. */
199
+ function redactToOrigin(url) {
200
+ try {
201
+ return new URL(url).origin;
202
+ }
203
+ catch {
204
+ return "(unparseable URL)";
205
+ }
206
+ }
207
+ function skip(path, reason, message) {
208
+ return { path, reason, message };
209
+ }
210
+ /** Same tiny helper as `playwright-browser.ts`'s own — duplicated rather than imported, matching
211
+ * this feature's existing convention for a helper this small. */
212
+ function messageOf(error) {
213
+ return error instanceof Error ? error.message : String(error);
214
+ }
215
+ //# sourceMappingURL=collect-page-evidence.js.map
@@ -0,0 +1,5 @@
1
+ export * from "./browser-port.js";
2
+ export * from "./collect-page-evidence.js";
3
+ export * from "./same-origin.js";
4
+ export { collectPageStructure, type PageStructureCapture, type PageStructureLimits } from "./page-structure-script.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,5 @@
1
+ export * from "./browser-port.js";
2
+ export * from "./collect-page-evidence.js";
3
+ export * from "./same-origin.js";
4
+ export { collectPageStructure } from "./page-structure-script.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @file `collectPageStructure` — the function that runs INSIDE the page, serialized across to
3
+ * Chromium by `page.evaluate` in `playwright-browser.ts`.
4
+ *
5
+ * ---------------------------------------------------------------------------
6
+ * Read this before editing: this function has no scope
7
+ * ---------------------------------------------------------------------------
8
+ * Playwright serializes the function source and evaluates it in the browser. It therefore CANNOT
9
+ * reference anything outside its own body — no import, no module-level constant, no helper declared
10
+ * beside it in this file. Every helper it uses is nested inside it. That is not a style choice and
11
+ * a "cleanup" that hoists a helper out will fail at runtime, in the browser, with a
12
+ * `ReferenceError` no typechecker can see.
13
+ *
14
+ * Its return value crosses a structured-clone boundary, so it may only contain JSON-ish values:
15
+ * no DOM nodes, no functions, no `undefined` in object positions.
16
+ *
17
+ * ---------------------------------------------------------------------------
18
+ * What it does and does not read
19
+ * ---------------------------------------------------------------------------
20
+ * It reads structure: landmarks, heading levels, image alt text, how form controls are labelled,
21
+ * and colour pairs. It never reads a form control's `.value`, and it never reads
22
+ * `document.cookie` — cookies come from the browser context's own jar in the adapter, where the
23
+ * value can be dropped rather than copied.
24
+ *
25
+ * The contrast numbers are SAMPLES over a bounded set of text-bearing elements, not a full-page
26
+ * audit. `AccessibilityEvidence.truncated` names every category that hit its cap so a report can
27
+ * never read a sample as a census.
28
+ */
29
+ import type { AccessibilityEvidence } from "./browser-port.js";
30
+ export interface PageStructureLimits {
31
+ readonly maxTextExcerptChars: number;
32
+ readonly maxNodesPerCategory: number;
33
+ readonly maxContrastSamples: number;
34
+ readonly collectAccessibility: boolean;
35
+ }
36
+ export interface PageStructureCapture {
37
+ readonly title: string;
38
+ readonly lang: string | null;
39
+ readonly textExcerpt: string;
40
+ readonly textTruncated: boolean;
41
+ readonly accessibility: AccessibilityEvidence;
42
+ }
43
+ /**
44
+ * Walks the rendered document and returns the structural evidence the compliance skill cites.
45
+ *
46
+ * Runs in the browser. See this file's header for the constraints that implies.
47
+ *
48
+ * @param limits - Per-category caps, passed in rather than hardcoded so the collector's single
49
+ * `SITE_EVIDENCE_LIMITS` constant is the only place any bound is defined.
50
+ * @complexity O(n) in rendered element count, with every output list capped by `limits`.
51
+ */
52
+ export declare function collectPageStructure(limits: PageStructureLimits): PageStructureCapture;
53
+ //# sourceMappingURL=page-structure-script.d.ts.map