@jini-ai/diagnostics 0.1.2 → 0.5.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/CHANGELOG.md +97 -0
- package/README.md +114 -0
- package/dist/agent-logs.d.ts +9 -4
- package/dist/agent-logs.js +14 -15
- package/dist/domain-dns/index.d.ts +136 -0
- package/dist/domain-dns/index.js +117 -0
- package/dist/index.d.ts +41 -3
- package/dist/index.js +38 -1
- package/dist/manifest.d.ts +22 -16
- package/dist/manifest.js +9 -19
- package/dist/node-ports.d.ts +6 -0
- package/dist/node-ports.js +57 -0
- package/dist/observability/config.d.ts +24 -0
- package/dist/observability/config.js +21 -0
- package/dist/observability/hooks.d.ts +19 -0
- package/dist/observability/hooks.js +32 -0
- package/dist/observability/index.d.ts +17 -0
- package/dist/observability/index.js +16 -0
- package/dist/observability/instrumentation.d.ts +61 -0
- package/dist/observability/instrumentation.js +139 -0
- package/dist/observability/node.d.ts +12 -0
- package/dist/observability/node.js +15 -0
- package/dist/observability/noop.d.ts +7 -0
- package/dist/observability/noop.js +22 -0
- package/dist/observability/otel.d.ts +28 -0
- package/dist/observability/otel.js +120 -0
- package/dist/observability/ports.d.ts +150 -0
- package/dist/observability/ports.js +2 -0
- package/dist/ports.d.ts +45 -0
- package/dist/ports.js +2 -0
- package/dist/redaction/secrets-only.d.ts +44 -0
- package/dist/redaction/secrets-only.js +179 -0
- package/dist/redaction.d.ts +12 -3
- package/dist/redaction.js +18 -8
- package/dist/sources.d.ts +22 -12
- package/dist/sources.js +22 -42
- package/dist/types.d.ts +24 -0
- package/dist/types.js +2 -0
- package/dist/web-evidence/browser-port.d.ts +166 -0
- package/dist/web-evidence/browser-port.js +6 -0
- package/dist/web-evidence/collect-page-evidence.d.ts +160 -0
- package/dist/web-evidence/collect-page-evidence.js +215 -0
- package/dist/web-evidence/index.d.ts +5 -0
- package/dist/web-evidence/index.js +5 -0
- package/dist/web-evidence/page-structure-script.d.ts +53 -0
- package/dist/web-evidence/page-structure-script.js +338 -0
- package/dist/web-evidence/page-work-budget.d.ts +27 -0
- package/dist/web-evidence/page-work-budget.js +53 -0
- package/dist/web-evidence/playwright-browser.d.ts +131 -0
- package/dist/web-evidence/playwright-browser.js +349 -0
- package/dist/web-evidence/same-origin.d.ts +126 -0
- package/dist/web-evidence/same-origin.js +141 -0
- package/dist/zip.d.ts +8 -3
- package/dist/zip.js +23 -16
- package/package.json +50 -5
- package/dist/agent-logs.d.ts.map +0 -1
- package/dist/agent-logs.js.map +0 -1
- package/dist/contract.d.ts.map +0 -1
- package/dist/contract.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/manifest.d.ts.map +0 -1
- package/dist/manifest.js.map +0 -1
- package/dist/redaction.d.ts.map +0 -1
- package/dist/redaction.js.map +0 -1
- package/dist/sources.d.ts.map +0 -1
- package/dist/sources.js.map +0 -1
- package/dist/zip.d.ts.map +0 -1
- package/dist/zip.js.map +0 -1
package/dist/sources.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import type { Clock } from "@jini-ai/core/primitives";
|
|
2
|
+
import type { DiagnosticsFilesystemPort, DiagnosticsSystemPort } from "./ports.js";
|
|
3
|
+
import type { CollectedFile } from "./types.js";
|
|
4
|
+
export type { CollectedFile } from "./types.js";
|
|
1
5
|
import { type RedactionOptions } from "./redaction.js";
|
|
2
6
|
export type LogSourceKind = "json" | "text";
|
|
3
7
|
export interface LogSource {
|
|
@@ -10,20 +14,21 @@ export interface LogSource {
|
|
|
10
14
|
/** Optional max bytes to read from the file tail; omit for whole file. */
|
|
11
15
|
tailBytes?: number;
|
|
12
16
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
export declare function collectLogSources(sources: LogSource[], opts?: RedactionOptions): Promise<CollectedFile[]>;
|
|
17
|
+
/** Reads through the filesystem port and records read failures as unavailable entries. */
|
|
18
|
+
export declare function collectLogSource({ source, filesystem }: {
|
|
19
|
+
source: LogSource;
|
|
20
|
+
filesystem: DiagnosticsFilesystemPort;
|
|
21
|
+
}, opts?: RedactionOptions): Promise<CollectedFile>;
|
|
22
|
+
/** Collects in parallel while preserving the supplied source order, including failures. */
|
|
23
|
+
export declare function collectLogSources({ sources, filesystem }: {
|
|
24
|
+
sources: LogSource[];
|
|
25
|
+
filesystem: DiagnosticsFilesystemPort;
|
|
26
|
+
}, opts?: RedactionOptions): Promise<CollectedFile[]>;
|
|
24
27
|
export interface CrashReportLookup {
|
|
25
28
|
/** Filenames must contain at least one of these substrings (case-insensitive). */
|
|
26
29
|
matchSubstrings: string[];
|
|
30
|
+
}
|
|
31
|
+
export interface CrashReportOptions {
|
|
27
32
|
/** Only include files modified within this many days. */
|
|
28
33
|
withinDays?: number;
|
|
29
34
|
/** Limit how many reports to include. */
|
|
@@ -33,5 +38,10 @@ export interface CrashReportLookup {
|
|
|
33
38
|
/** Home directory to derive ~/Library/Logs/DiagnosticReports from. */
|
|
34
39
|
homeDir?: string;
|
|
35
40
|
}
|
|
36
|
-
|
|
41
|
+
/** Scans matching reports with an explicit platform, clock and filesystem. */
|
|
42
|
+
export declare function findMacOSCrashReports({ matchSubstrings, filesystem, clock, system }: CrashReportLookup & {
|
|
43
|
+
filesystem: DiagnosticsFilesystemPort;
|
|
44
|
+
clock: Clock;
|
|
45
|
+
system: DiagnosticsSystemPort;
|
|
46
|
+
}, options?: CrashReportOptions): Promise<LogSource[]>;
|
|
37
47
|
//# sourceMappingURL=sources.d.ts.map
|
package/dist/sources.js
CHANGED
|
@@ -1,34 +1,12 @@
|
|
|
1
|
-
import { open, readFile, readdir, stat } from "node:fs/promises";
|
|
2
1
|
import { join } from "node:path";
|
|
3
2
|
import { redactJsonText, redactText } from "./redaction.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const buf = await readFile(absolutePath);
|
|
7
|
-
return { text: buf.toString("utf8"), bytes: buf.byteLength };
|
|
8
|
-
}
|
|
9
|
-
const info = await stat(absolutePath);
|
|
10
|
-
if (info.size <= tailBytes) {
|
|
11
|
-
const buf = await readFile(absolutePath);
|
|
12
|
-
return { text: buf.toString("utf8"), bytes: buf.byteLength };
|
|
13
|
-
}
|
|
14
|
-
// For large files we do NOT want to load the whole thing into memory just
|
|
15
|
-
// to slice off the tail — open the fd and read the trailing window
|
|
16
|
-
// directly. Long-running daemon logs can be multi-GB.
|
|
17
|
-
const fd = await open(absolutePath, "r");
|
|
18
|
-
try {
|
|
19
|
-
const start = info.size - tailBytes;
|
|
20
|
-
const buffer = Buffer.alloc(tailBytes);
|
|
21
|
-
const { bytesRead } = await fd.read(buffer, 0, tailBytes, start);
|
|
22
|
-
return { text: buffer.subarray(0, bytesRead).toString("utf8"), bytes: bytesRead };
|
|
23
|
-
}
|
|
24
|
-
finally {
|
|
25
|
-
await fd.close();
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
export async function collectLogSource(source, opts = {}) {
|
|
3
|
+
/** Reads through the filesystem port and records read failures as unavailable entries. */
|
|
4
|
+
export async function collectLogSource({ source, filesystem }, opts = {}) {
|
|
29
5
|
try {
|
|
30
|
-
const
|
|
31
|
-
const
|
|
6
|
+
const buffer = await filesystem.readFile({ absolutePath: source.absolutePath }, { tailBytes: source.tailBytes });
|
|
7
|
+
const text = buffer.toString("utf8");
|
|
8
|
+
const bytes = buffer.byteLength;
|
|
9
|
+
const redacted = source.kind === "json" ? redactJsonText({ text }, opts) : redactText({ text }, opts);
|
|
32
10
|
return { name: source.name, absolutePath: source.absolutePath, content: redacted, bytes };
|
|
33
11
|
}
|
|
34
12
|
catch (error) {
|
|
@@ -41,40 +19,42 @@ export async function collectLogSource(source, opts = {}) {
|
|
|
41
19
|
};
|
|
42
20
|
}
|
|
43
21
|
}
|
|
44
|
-
|
|
45
|
-
|
|
22
|
+
/** Collects in parallel while preserving the supplied source order, including failures. */
|
|
23
|
+
export async function collectLogSources({ sources, filesystem }, opts = {}) {
|
|
24
|
+
return await Promise.all(sources.map((source) => collectLogSource({ source, filesystem }, opts)));
|
|
46
25
|
}
|
|
47
26
|
const DEFAULT_CRASH_DIRS_DARWIN = [
|
|
48
27
|
"/Library/Logs/DiagnosticReports",
|
|
49
28
|
];
|
|
50
|
-
|
|
51
|
-
|
|
29
|
+
/** Scans matching reports with an explicit platform, clock and filesystem. */
|
|
30
|
+
export async function findMacOSCrashReports({ matchSubstrings, filesystem, clock, system }, options = {}) {
|
|
31
|
+
if (system.platform({}) !== "darwin")
|
|
52
32
|
return [];
|
|
53
|
-
const within = (
|
|
54
|
-
const cutoff =
|
|
55
|
-
const max =
|
|
56
|
-
const dirs =
|
|
57
|
-
...(
|
|
33
|
+
const within = (options.withinDays ?? 7) * 24 * 60 * 60 * 1000;
|
|
34
|
+
const cutoff = clock.nowMs() - within;
|
|
35
|
+
const max = options.maxReports ?? 20;
|
|
36
|
+
const dirs = options.searchDirs ?? [
|
|
37
|
+
...(options.homeDir ? [join(options.homeDir, "Library/Logs/DiagnosticReports")] : []),
|
|
58
38
|
...DEFAULT_CRASH_DIRS_DARWIN,
|
|
59
39
|
];
|
|
60
|
-
const matches =
|
|
40
|
+
const matches = matchSubstrings.map((entry) => entry.toLowerCase());
|
|
61
41
|
const found = [];
|
|
62
42
|
for (const dir of dirs) {
|
|
63
43
|
let entries;
|
|
64
44
|
try {
|
|
65
|
-
entries = await
|
|
45
|
+
entries = await filesystem.readDirectory({ absolutePath: dir });
|
|
66
46
|
}
|
|
67
47
|
catch {
|
|
68
48
|
continue;
|
|
69
49
|
}
|
|
70
|
-
for (const entry of entries) {
|
|
50
|
+
for (const { name: entry } of entries) {
|
|
71
51
|
const lower = entry.toLowerCase();
|
|
72
52
|
if (!matches.some((needle) => lower.includes(needle)))
|
|
73
53
|
continue;
|
|
74
54
|
const absolutePath = join(dir, entry);
|
|
75
55
|
try {
|
|
76
|
-
const info = await stat(absolutePath);
|
|
77
|
-
if (!info.isFile
|
|
56
|
+
const info = await filesystem.stat({ absolutePath });
|
|
57
|
+
if (!info.isFile)
|
|
78
58
|
continue;
|
|
79
59
|
if (info.mtimeMs < cutoff)
|
|
80
60
|
continue;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** Bundle value contracts shared by collection, manifest assembly and host ports. */
|
|
2
|
+
export interface MachineInfo {
|
|
3
|
+
hostname: string;
|
|
4
|
+
platform: string;
|
|
5
|
+
release: string;
|
|
6
|
+
arch: string;
|
|
7
|
+
type: string;
|
|
8
|
+
totalMemoryBytes: number;
|
|
9
|
+
nodeVersion: string;
|
|
10
|
+
pid: number;
|
|
11
|
+
ppid: number;
|
|
12
|
+
cwd: string;
|
|
13
|
+
username?: string | undefined;
|
|
14
|
+
}
|
|
15
|
+
export interface CollectedFile {
|
|
16
|
+
name: string;
|
|
17
|
+
absolutePath: string;
|
|
18
|
+
/** Redacted contents to put into the zip. Null when the file could not be read. */
|
|
19
|
+
content: string | null;
|
|
20
|
+
bytes: number;
|
|
21
|
+
/** Reason the file is missing or unreadable. */
|
|
22
|
+
error?: string;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/** Evidence and browser ports. Cookie values, request bodies, and form values are never modelled. */
|
|
2
|
+
/** Which side of the consent interaction an observation belongs to. `before` is everything seen
|
|
3
|
+
* from navigation up to the consent click; `after` is everything seen following it. A run that was
|
|
4
|
+
* not asked to perform a consent action reports everything as `before` — there was no transition,
|
|
5
|
+
* so nothing is "after" anything. */
|
|
6
|
+
export type ObservationPhase = "before" | "after";
|
|
7
|
+
/** One cookie observed in the browser context. No value field — see this file's header. */
|
|
8
|
+
export interface CookieEvidence {
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly domain: string;
|
|
11
|
+
readonly path: string;
|
|
12
|
+
readonly secure: boolean;
|
|
13
|
+
readonly httpOnly: boolean;
|
|
14
|
+
readonly sameSite: string;
|
|
15
|
+
/** `null` when the cookie is a session cookie (no expiry). */
|
|
16
|
+
readonly expiresAt: string | null;
|
|
17
|
+
/** Whether the cookie's domain is the inspected origin's host. First-party/third-party is the
|
|
18
|
+
* distinction most consent rules turn on, and it is a fact about the observation, not a
|
|
19
|
+
* judgement about it. */
|
|
20
|
+
readonly firstParty: boolean;
|
|
21
|
+
readonly phase: ObservationPhase;
|
|
22
|
+
}
|
|
23
|
+
/** One network request the page attempted. No body, no headers — see this file's header. */
|
|
24
|
+
export interface RequestEvidence {
|
|
25
|
+
readonly method: string;
|
|
26
|
+
readonly host: string;
|
|
27
|
+
readonly pathname: string;
|
|
28
|
+
/** The browser's own classification (`document`, `script`, `image`, `xhr`, `fetch`, …). */
|
|
29
|
+
readonly resourceType: string;
|
|
30
|
+
readonly firstParty: boolean;
|
|
31
|
+
readonly phase: ObservationPhase;
|
|
32
|
+
/** Set when the collector refused to let the request proceed — see
|
|
33
|
+
* `collect-page-evidence.ts`'s non-GET rule. The attempt is still evidence; completing it is
|
|
34
|
+
* not required to observe that it happened. */
|
|
35
|
+
readonly blockedReason?: string;
|
|
36
|
+
}
|
|
37
|
+
/** One response header observed on the main document response. */
|
|
38
|
+
export interface HeaderEvidence {
|
|
39
|
+
readonly name: string;
|
|
40
|
+
readonly value: string;
|
|
41
|
+
}
|
|
42
|
+
/** A landmark region in the rendered accessibility tree. */
|
|
43
|
+
export interface LandmarkEvidence {
|
|
44
|
+
readonly role: string;
|
|
45
|
+
readonly selector: string;
|
|
46
|
+
readonly accessibleName: string | null;
|
|
47
|
+
}
|
|
48
|
+
/** One heading, in document order, with its level — the raw material for an outline check. */
|
|
49
|
+
export interface HeadingEvidence {
|
|
50
|
+
readonly level: number;
|
|
51
|
+
readonly selector: string;
|
|
52
|
+
readonly text: string;
|
|
53
|
+
}
|
|
54
|
+
/** One image and whether it carries alternative text. `alt: null` means the attribute is absent;
|
|
55
|
+
* `alt: ""` means it is present and empty (a deliberate decorative marking), and the two are not
|
|
56
|
+
* the same observation. */
|
|
57
|
+
export interface ImageEvidence {
|
|
58
|
+
readonly selector: string;
|
|
59
|
+
readonly src: string;
|
|
60
|
+
readonly alt: string | null;
|
|
61
|
+
readonly ariaHidden: boolean;
|
|
62
|
+
}
|
|
63
|
+
/** One form control and how (or whether) it is labelled. Never its value. */
|
|
64
|
+
export interface FormControlEvidence {
|
|
65
|
+
readonly selector: string;
|
|
66
|
+
readonly tag: string;
|
|
67
|
+
readonly type: string | null;
|
|
68
|
+
readonly name: string | null;
|
|
69
|
+
readonly accessibleName: string | null;
|
|
70
|
+
/** How the accessible name was derived, when it was: `label-for`, `label-wrap`, `aria-label`,
|
|
71
|
+
* `aria-labelledby`, `title`, or `none`. */
|
|
72
|
+
readonly labelSource: string;
|
|
73
|
+
readonly required: boolean;
|
|
74
|
+
}
|
|
75
|
+
/** One sampled text/background colour pair and its computed contrast ratio. A sample, explicitly:
|
|
76
|
+
* the collector caps how many it takes, and says so in the result. */
|
|
77
|
+
export interface ContrastSampleEvidence {
|
|
78
|
+
readonly selector: string;
|
|
79
|
+
readonly foreground: string;
|
|
80
|
+
readonly background: string;
|
|
81
|
+
readonly ratio: number;
|
|
82
|
+
readonly fontSizePx: number;
|
|
83
|
+
readonly fontWeight: number;
|
|
84
|
+
}
|
|
85
|
+
export interface AccessibilityEvidence {
|
|
86
|
+
readonly landmarks: readonly LandmarkEvidence[];
|
|
87
|
+
readonly headings: readonly HeadingEvidence[];
|
|
88
|
+
readonly images: readonly ImageEvidence[];
|
|
89
|
+
readonly formControls: readonly FormControlEvidence[];
|
|
90
|
+
readonly contrastSamples: readonly ContrastSampleEvidence[];
|
|
91
|
+
/** Names any category whose cap was reached, plus omitted contrast samples
|
|
92
|
+
* (`contrastSamples:unparsed-colour`), so an incomplete list cannot read as exhaustive. */
|
|
93
|
+
readonly truncated: readonly string[];
|
|
94
|
+
}
|
|
95
|
+
export interface DocumentEvidence {
|
|
96
|
+
readonly httpStatus: number;
|
|
97
|
+
/** The URL actually loaded, after redirects — what `isSameOriginUrl` is re-checked against. */
|
|
98
|
+
readonly finalUrl: string;
|
|
99
|
+
readonly redirected: boolean;
|
|
100
|
+
readonly title: string;
|
|
101
|
+
/** The `<html lang>` attribute, or `null` when absent. */
|
|
102
|
+
readonly lang: string | null;
|
|
103
|
+
readonly headers: readonly HeaderEvidence[];
|
|
104
|
+
/** A bounded excerpt of the page's visible text, for quoting placeholder/boilerplate copy. */
|
|
105
|
+
readonly textExcerpt: string;
|
|
106
|
+
readonly textTruncated: boolean;
|
|
107
|
+
}
|
|
108
|
+
/** Everything one page load produced. Every field is optional-by-absence rather than defaulted:
|
|
109
|
+
* a section that was not collected is missing, and a report must treat missing as
|
|
110
|
+
* "not observed", never as "observed to be empty". */
|
|
111
|
+
export interface PageObservation {
|
|
112
|
+
readonly document: DocumentEvidence;
|
|
113
|
+
readonly cookies: readonly CookieEvidence[];
|
|
114
|
+
readonly requests: readonly RequestEvidence[];
|
|
115
|
+
readonly accessibility?: AccessibilityEvidence;
|
|
116
|
+
/** Free-text notes the adapter produced about the observation itself (e.g. "consent selector
|
|
117
|
+
* matched no element"). Never findings — the adapter has no opinion about compliance. */
|
|
118
|
+
readonly notes: readonly string[];
|
|
119
|
+
}
|
|
120
|
+
/** What the collector asks the browser to do for one page. */
|
|
121
|
+
export interface ObservePageRequest {
|
|
122
|
+
/** Already normalized and already joined to the workspace's own verified origin. The adapter
|
|
123
|
+
* does not re-derive it and must not accept anything else. */
|
|
124
|
+
readonly url: string;
|
|
125
|
+
/** The origin every `firstParty` flag is computed against. */
|
|
126
|
+
readonly originBaseUrl: string;
|
|
127
|
+
/** A CSS selector for the site's consent-accept control. When present the adapter clicks it once
|
|
128
|
+
* and re-observes; when absent no interaction happens at all. */
|
|
129
|
+
readonly collectAccessibility: boolean;
|
|
130
|
+
readonly timeoutMs: number;
|
|
131
|
+
readonly maxTextExcerptChars: number;
|
|
132
|
+
readonly maxCookies: number;
|
|
133
|
+
readonly maxRequests: number;
|
|
134
|
+
readonly maxAccessibilityNodesPerCategory: number;
|
|
135
|
+
readonly maxContrastSamples: number;
|
|
136
|
+
}
|
|
137
|
+
export type ObservePageResult = {
|
|
138
|
+
readonly ok: true;
|
|
139
|
+
readonly observation: PageObservation;
|
|
140
|
+
} | {
|
|
141
|
+
readonly ok: false;
|
|
142
|
+
readonly reason: string;
|
|
143
|
+
};
|
|
144
|
+
/** A supplied consent selector triggers one click and a second observation; absence means no
|
|
145
|
+
* interaction. This belongs to call options rather than the required page/limit contract. */
|
|
146
|
+
export interface ObservePageOptions {
|
|
147
|
+
readonly consentAcceptSelector?: string;
|
|
148
|
+
}
|
|
149
|
+
export interface SiteEvidenceBrowserPort {
|
|
150
|
+
/** Loads one page in a fresh, isolated, non-persistent context and returns what was observed.
|
|
151
|
+
* Never throws for an expected failure (navigation error, timeout) — those come back as
|
|
152
|
+
* `{ ok: false, reason }` so one bad page does not end the run. */
|
|
153
|
+
observe(request: ObservePageRequest, options?: ObservePageOptions): Promise<ObservePageResult>;
|
|
154
|
+
/** Releases the underlying browser. Always called by the collector, including on failure. */
|
|
155
|
+
close(required: Record<string, never>): Promise<void>;
|
|
156
|
+
}
|
|
157
|
+
export type SiteEvidenceBrowserAvailability = {
|
|
158
|
+
readonly available: true;
|
|
159
|
+
readonly browser: SiteEvidenceBrowserPort;
|
|
160
|
+
} | {
|
|
161
|
+
readonly available: false;
|
|
162
|
+
readonly reason: string;
|
|
163
|
+
};
|
|
164
|
+
/** Opens a browser, or explains why this deployment has none. See this file's header, point 1. */
|
|
165
|
+
export type SiteEvidenceBrowserFactory = (required: Record<string, never>) => Promise<SiteEvidenceBrowserAvailability>;
|
|
166
|
+
//# sourceMappingURL=browser-port.d.ts.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Evidence and browser ports. Cookie values, request bodies, and form values are never modelled. */
|
|
2
|
+
export {};
|
|
3
|
+
// Keep browser vendors behind this port so caps, same-origin refusals and privacy rules can be
|
|
4
|
+
// checked with a lightweight fake. Omitting sensitive fields from the contract is stronger than
|
|
5
|
+
// relying on each adapter to remember a redaction pass; bounded excerpts are not full documents.
|
|
6
|
+
//# sourceMappingURL=browser-port.js.map
|
|
@@ -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
|