@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.
- package/CHANGELOG.md +79 -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 +18 -0
- package/dist/observability/hooks.js +24 -0
- package/dist/observability/index.d.ts +14 -0
- package/dist/observability/index.js +14 -0
- package/dist/observability/noop.d.ts +4 -0
- package/dist/observability/noop.js +6 -0
- package/dist/observability/otel.d.ts +14 -0
- package/dist/observability/otel.js +28 -0
- package/dist/observability/ports.d.ts +79 -0
- package/dist/observability/ports.js +2 -0
- package/dist/ports.d.ts +45 -0
- package/dist/ports.js +2 -0
- package/dist/redaction/secret-patterns.d.ts +8 -0
- package/dist/redaction/secret-patterns.js +18 -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 +46 -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
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { SECRET_SHAPE_PATTERNS } from "@jini-ai/core";
|
|
2
|
+
/** Adds the `g` flag when a source pattern (e.g. one of {@link SECRET_SHAPE_PATTERNS}, authored for a
|
|
3
|
+
* single `RegExp.exec` caller) does not already carry it — `String.replace` only replaces every
|
|
4
|
+
* match when the pattern is global. Mirrors `secret-scan-guard.ts`'s own `scanTextForSecrets`. */
|
|
5
|
+
function withGlobalFlag(flags) {
|
|
6
|
+
return flags.includes("g") ? flags : `${flags}g`;
|
|
7
|
+
}
|
|
8
|
+
/** {@link SECRET_SHAPE_PATTERNS} reused for redaction — see this file's header. Each vendor pattern is
|
|
9
|
+
* wrapped in the same `RedactionRule` shape as every rule below, so the loop in
|
|
10
|
+
* {@link redactSecretShapes} treats them identically. */
|
|
11
|
+
const REUSED_CREDENTIAL_RULES = SECRET_SHAPE_PATTERNS.map((vendor) => ({
|
|
12
|
+
kind: "credential",
|
|
13
|
+
pattern: new RegExp(vendor.pattern.source, withGlobalFlag(vendor.pattern.flags)),
|
|
14
|
+
replacement: () => "[REDACTED:credential]",
|
|
15
|
+
}));
|
|
16
|
+
/** Labels a bare `label=value`, `"label":"value"`, or `?label=value` assignment may carry — see
|
|
17
|
+
* this file's header's Must NOT change list for why a bare prose colon (`password: must be...`)
|
|
18
|
+
* is deliberately excluded from all three shapes below. */
|
|
19
|
+
const LABELED_SECRET_LABELS = "password|passwd|pwd|secret|client_secret|api_key|apikey|access_token|refresh_token|id_token|auth_token|token|private_key|secret_access_key|signing_secret|webhook_secret";
|
|
20
|
+
/**
|
|
21
|
+
* Every rule this module applies, in order. Order matters: `private_key` must run before the
|
|
22
|
+
* reused header-only PEM pattern (inside {@link REUSED_CREDENTIAL_RULES}) so a full block is
|
|
23
|
+
* blanked as one unit rather than leaving its header re-matched separately; `auth_header` must run
|
|
24
|
+
* before the bare `bearer_token` rule so a header's own scheme+token is not ALSO caught by the
|
|
25
|
+
* looser bare-token rule.
|
|
26
|
+
*/
|
|
27
|
+
const REDACTION_RULES = [
|
|
28
|
+
{
|
|
29
|
+
kind: "private_key",
|
|
30
|
+
// Matches a full PEM block, including a truncated one with no `-----END-----` line (the
|
|
31
|
+
// `$` alternative). `\1` backreferences the captured key type (e.g. "RSA ") so a
|
|
32
|
+
// "BEGIN RSA PRIVATE KEY" block cannot be closed by an unrelated "END EC PRIVATE KEY" line.
|
|
33
|
+
pattern: /-----BEGIN ([A-Z ]*)PRIVATE KEY-----[\s\S]*?(?:-----END \1PRIVATE KEY-----|$)/g,
|
|
34
|
+
replacement: () => "[REDACTED:private_key]",
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
kind: "auth_header",
|
|
38
|
+
// The value is ONE token after an optional known scheme, never the rest of the line — a
|
|
39
|
+
// rest-of-line value would eat a trailing IP/cause in a message like `request failed
|
|
40
|
+
// (Authorization: Bearer <tok>): connect ECONNREFUSED 10.0.4.7:443`.
|
|
41
|
+
//
|
|
42
|
+
// Split into two non-overlapping alternatives (scheme+value vs. no-scheme+value) rather than
|
|
43
|
+
// one optional scheme group, for idempotency: with a single optional group, a second pass over
|
|
44
|
+
// already-redacted text (`Authorization: Bearer [REDACTED:auth_header]`) would fail the
|
|
45
|
+
// `(?!\[REDACTED)` lookahead on the "with scheme" attempt, backtrack the optional group away,
|
|
46
|
+
// and then match the bare word "Bearer" itself as the "value" — corrupting already-redacted
|
|
47
|
+
// text. The second alternative's own `(?!(?:Bearer|...)\s)` explicitly refuses to start on a
|
|
48
|
+
// scheme keyword, so when the first alternative's lookahead fails there is no fallback left to
|
|
49
|
+
// backtrack into, and the whole rule correctly finds no match on a second pass.
|
|
50
|
+
pattern: /(?<![A-Za-z0-9-])((?:proxy-)?authorization|x-api-key|api-key|x-goog-api-key|x-auth-token)(\s*["']?\s*[:=]\s*["']?)(?:((?:Bearer|Basic|Token|Digest|ApiKey)\s+)(?!\[REDACTED)[^\s"'),;]+|(?!\[REDACTED)(?!(?:Bearer|Basic|Token|Digest|ApiKey)\s)[^\s"'),;]+)/gi,
|
|
51
|
+
replacement: ({ match: m }) => `${m[1]}${m[2]}${m[3] ?? ""}[REDACTED:auth_header]`,
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
kind: "auth_header",
|
|
55
|
+
pattern: /(?<![A-Za-z0-9-])((?:set-)?cookie)(\s*[:=]\s*)(?!\[REDACTED)[^\s"'),;]+(?:;\s*[^\s"'),;]+)*/gi,
|
|
56
|
+
replacement: ({ match: m }) => `${m[1]}${m[2]}[REDACTED:auth_header]`,
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
kind: "url_credentials",
|
|
60
|
+
// Host, port, IP and path all stay — only the `user:pass@` half is replaced. The password class
|
|
61
|
+
// ADMITS `@` and backtracks to the LAST one before the authority ends (2026-09-16 security
|
|
62
|
+
// review): a password that was never percent-encoded — `postgres://u:p@ss4@host/db` — otherwise
|
|
63
|
+
// matched only up to its FIRST `@`, leaving the tail (`ss4`) of the password in the output.
|
|
64
|
+
// `?` is excluded so a query string's own `@` cannot drag the match past the authority.
|
|
65
|
+
pattern: /\b([a-z][a-z0-9+.-]*:\/\/)(?!\[REDACTED)[^\s/@:]+:[^\s/?]+@/gi,
|
|
66
|
+
replacement: ({ match: m }) => `${m[1]}[REDACTED:url_credentials]@`,
|
|
67
|
+
},
|
|
68
|
+
...REUSED_CREDENTIAL_RULES,
|
|
69
|
+
{
|
|
70
|
+
kind: "stripe_key",
|
|
71
|
+
pattern: /(?<![A-Za-z0-9_])(?:sk|rk)_(?:live|test)_[0-9A-Za-z]{16,}/g,
|
|
72
|
+
replacement: () => "[REDACTED:stripe_key]",
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
kind: "stripe_key",
|
|
76
|
+
pattern: /(?<![A-Za-z0-9_])whsec_[A-Za-z0-9]{24,}/g,
|
|
77
|
+
replacement: () => "[REDACTED:stripe_key]",
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
kind: "github_token",
|
|
81
|
+
// Covers `ghs_`/`ghu_`/`ghr_` and lengths the exact-length SECRET_SHAPE_PATTERNS entries miss.
|
|
82
|
+
pattern: /(?<![A-Za-z0-9_])gh[pousr]_[A-Za-z0-9]{30,}/g,
|
|
83
|
+
replacement: () => "[REDACTED:github_token]",
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
kind: "openai_key",
|
|
87
|
+
pattern: /(?<![A-Za-z0-9_-])sk-(?:proj|svcacct|admin)-[A-Za-z0-9_-]{20,}/g,
|
|
88
|
+
replacement: () => "[REDACTED:openai_key]",
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
kind: "anthropic_key",
|
|
92
|
+
// SECRET_SHAPE_PATTERNS' own `sk-ant-` entry needs 90+ trailing characters, which is right for the
|
|
93
|
+
// repo-wide static check (a committed key is whole) but wrong here (2026-09-16 security review):
|
|
94
|
+
// an upstream 401 often echoes a TRUNCATED key, and `sk-[A-Za-z0-9]{40,}` cannot cover it either
|
|
95
|
+
// because `sk-ant-api03-` carries hyphens. The prefix alone is specific enough at this length.
|
|
96
|
+
pattern: /(?<![A-Za-z0-9_-])sk-ant-[A-Za-z0-9_-]{20,}/g,
|
|
97
|
+
replacement: () => "[REDACTED:anthropic_key]",
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
kind: "google_api_key",
|
|
101
|
+
pattern: /(?<![A-Za-z0-9_.-])AQ\.[A-Za-z0-9_-]{20,}/g,
|
|
102
|
+
replacement: () => "[REDACTED:google_api_key]",
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
kind: "aws_access_key",
|
|
106
|
+
pattern: /(?<![0-9A-Z])ASIA[0-9A-Z]{16}(?![0-9A-Z])/g,
|
|
107
|
+
replacement: () => "[REDACTED:aws_access_key]",
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
kind: "jwt",
|
|
111
|
+
pattern: /(?<![A-Za-z0-9_-])eyJ[A-Za-z0-9_-]{8,}\.eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/g,
|
|
112
|
+
replacement: () => "[REDACTED:jwt]",
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
kind: "bearer_token",
|
|
116
|
+
// Bare scheme outside a header line. The value must be at least 16 characters AND contain a
|
|
117
|
+
// digit, so ordinary prose ("Bearer token", "Basic authentication is not supported") is
|
|
118
|
+
// untouched.
|
|
119
|
+
pattern: /\b(Bearer|Basic|Token)\s+(?!\[REDACTED)(?=[A-Za-z0-9._~+/=:-]*\d)[A-Za-z0-9._~+/=:-]{16,}/g,
|
|
120
|
+
replacement: ({ match: m }) => `${m[1]} [REDACTED:bearer_token]`,
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
kind: "labeled_secret",
|
|
124
|
+
// Assignment form only — never a bare prose colon (`password: must be...` is untouched).
|
|
125
|
+
pattern: new RegExp(`(?<![A-Za-z0-9])(${LABELED_SECRET_LABELS})(\\s*=\\s*)(?!\\[REDACTED)([^\\s"'&,;})]+)`, "gi"),
|
|
126
|
+
replacement: ({ match: m }) => `${m[1]}${m[2]}[REDACTED:labeled_secret]`,
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
kind: "labeled_secret",
|
|
130
|
+
// JSON form: `"label":"value"`.
|
|
131
|
+
pattern: new RegExp(`"(${LABELED_SECRET_LABELS})"(\\s*:\\s*)"(?!\\[REDACTED)[^"]+"`, "gi"),
|
|
132
|
+
replacement: ({ match: m }) => `"${m[1]}"${m[2]}"[REDACTED:labeled_secret]"`,
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
kind: "labeled_secret",
|
|
136
|
+
// Colon form: `api_key: <value>`, `{ api_key: 'value' }`, `\"api_key\":\"value\"` (2026-09-16
|
|
137
|
+
// security review). The `=` and double-quoted-JSON rules above miss every one of these, and they
|
|
138
|
+
// are the shapes a real failure arrives in most often — `util.inspect` of a request config, a
|
|
139
|
+
// YAML/pretty-printed body, or a JSON error body embedded inside ANOTHER JSON string, where the
|
|
140
|
+
// escaped `\"` defeats the plain JSON rule.
|
|
141
|
+
//
|
|
142
|
+
// Prose is kept out by the VALUE's own shape rather than by banning the colon: a quoted value is
|
|
143
|
+
// always taken, an unquoted one only when it is a single ≥12-character token. That is what keeps
|
|
144
|
+
// this file's Must NOT change list intact — `password: must be at least 8 characters` stops at
|
|
145
|
+
// the 4-character `must`, and `token expired at ...` has no colon at all.
|
|
146
|
+
pattern: new RegExp(`(?<![A-Za-z0-9])(${LABELED_SECRET_LABELS})(\\\\?["']?\\s*:\\s*)(?:(\\\\?["'])(?!\\[REDACTED)[^"'\\\\\\r\\n]+\\3|(?!\\[REDACTED)[^\\s"',;}]{12,})`, "gi"),
|
|
147
|
+
replacement: ({ match: m }) => `${m[1]}${m[2]}${m[3] ?? ""}[REDACTED:labeled_secret]${m[3] ?? ""}`,
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
kind: "labeled_secret",
|
|
151
|
+
// Query-string form: `?key=value` / `&token=value`.
|
|
152
|
+
pattern: /([?&](?:key|api_key|api-key|token|access_token|sig|signature)=)(?!\[REDACTED)[^&#\s"']+/gi,
|
|
153
|
+
replacement: ({ match: m }) => `${m[1]}[REDACTED:labeled_secret]`,
|
|
154
|
+
},
|
|
155
|
+
];
|
|
156
|
+
/** Redacts credential values with a required policy; returns text and replacement count. */
|
|
157
|
+
export function redactSecretShapes({ text, policy }) {
|
|
158
|
+
if (text.length === 0)
|
|
159
|
+
return { text, redactions: 0 };
|
|
160
|
+
let redactions = 0;
|
|
161
|
+
let result = text;
|
|
162
|
+
// Preserve the original policy slot: vendor/JWT matches take precedence over host formats.
|
|
163
|
+
const applicationRuleSlot = REDACTION_RULES.findIndex(rule => rule.kind === "bearer_token");
|
|
164
|
+
const rules = [
|
|
165
|
+
...REDACTION_RULES.slice(0, applicationRuleSlot),
|
|
166
|
+
...(policy.additionalRules ?? []),
|
|
167
|
+
...REDACTION_RULES.slice(applicationRuleSlot),
|
|
168
|
+
];
|
|
169
|
+
for (const rule of rules) {
|
|
170
|
+
result = result.replace(new RegExp(rule.pattern.source, withGlobalFlag(rule.pattern.flags)), (...args) => {
|
|
171
|
+
redactions += 1;
|
|
172
|
+
return rule.replacement({ match: args });
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
return { text: result, redactions };
|
|
176
|
+
}
|
|
177
|
+
// Preserve the public scanner vocabulary while core owns the single pattern catalog.
|
|
178
|
+
export { SECRET_SHAPE_PATTERNS as SECRET_PATTERNS, PEM_PATTERN_NAME } from "@jini-ai/core";
|
|
179
|
+
//# sourceMappingURL=secrets-only.js.map
|
package/dist/redaction.d.ts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
export interface RedactionOptions {
|
|
2
2
|
username?: string | undefined;
|
|
3
3
|
}
|
|
4
|
-
|
|
5
|
-
export declare function
|
|
6
|
-
|
|
4
|
+
/** Returns a redacted copy; the required input value is separate from optional path policy. */
|
|
5
|
+
export declare function redactJsonValue({ value }: {
|
|
6
|
+
value: unknown;
|
|
7
|
+
}, opts?: RedactionOptions): unknown;
|
|
8
|
+
/** Redacts credentials while optional username policy masks that user's home paths. */
|
|
9
|
+
export declare function redactText({ text }: {
|
|
10
|
+
text: string;
|
|
11
|
+
}, opts?: RedactionOptions): string;
|
|
12
|
+
/** Redacts valid JSON recursively and falls back to text redaction for invalid JSON. */
|
|
13
|
+
export declare function redactJsonText({ text }: {
|
|
14
|
+
text: string;
|
|
15
|
+
}, opts?: RedactionOptions): string;
|
|
7
16
|
//# sourceMappingURL=redaction.d.ts.map
|
package/dist/redaction.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SECRET_SHAPE_PATTERNS } from "@jini-ai/core";
|
|
1
2
|
const SENSITIVE_KEY_RE = /token|password|secret|key|dsn|authorization|cookie/i;
|
|
2
3
|
const URL_QUERY_SECRET_RE = /([?&#])(token|password|secret|key|dsn|api[_-]?key|auth|access_token|refresh_token|id_token)(=)([^&\s#"']*)/gi;
|
|
3
4
|
// Catch loose key=value pairs in log lines that aren't inside a URL — e.g. env
|
|
@@ -16,9 +17,10 @@ const BARE_SECRET_RE = /(^|[\s,;])(access_token|refresh_token|id_token|api[_-]?k
|
|
|
16
17
|
// previously left tokens like `Bearer abcd~efgh` partially exposed.
|
|
17
18
|
const HTTP_AUTH_SCHEME_RE = /\b(Bearer|Token|Basic)\s+([A-Za-z0-9._~\-+/=:]{4,})/gi;
|
|
18
19
|
const REDACTED = "[REDACTED]";
|
|
19
|
-
|
|
20
|
+
/** Returns a redacted copy; the required input value is separate from optional path policy. */
|
|
21
|
+
export function redactJsonValue({ value }, opts = {}) {
|
|
20
22
|
if (Array.isArray(value))
|
|
21
|
-
return value.map((entry) => redactJsonValue(entry, opts));
|
|
23
|
+
return value.map((entry) => redactJsonValue({ value: entry }, opts));
|
|
22
24
|
if (value !== null && typeof value === "object") {
|
|
23
25
|
const out = {};
|
|
24
26
|
for (const [key, raw] of Object.entries(value)) {
|
|
@@ -26,22 +28,29 @@ export function redactJsonValue(value, opts = {}) {
|
|
|
26
28
|
out[key] = REDACTED;
|
|
27
29
|
}
|
|
28
30
|
else {
|
|
29
|
-
out[key] = redactJsonValue(raw, opts);
|
|
31
|
+
out[key] = redactJsonValue({ value: raw }, opts);
|
|
30
32
|
}
|
|
31
33
|
}
|
|
32
34
|
return out;
|
|
33
35
|
}
|
|
34
36
|
if (typeof value === "string")
|
|
35
|
-
return redactText(value, opts);
|
|
37
|
+
return redactText({ text: value }, opts);
|
|
36
38
|
return value;
|
|
37
39
|
}
|
|
38
|
-
|
|
40
|
+
/** Redacts credentials while optional username policy masks that user's home paths. */
|
|
41
|
+
export function redactText({ text }, opts = {}) {
|
|
39
42
|
// Run the HTTP auth scheme replacement first so the credential after
|
|
40
43
|
// `Bearer` / `Token` / `Basic` is captured before BARE_SECRET_RE swallows
|
|
41
44
|
// the `Authorization: Bearer` prefix and stops at the space.
|
|
42
45
|
let out = text.replace(HTTP_AUTH_SCHEME_RE, (_match, scheme) => `${scheme} ${REDACTED}`);
|
|
43
46
|
out = out.replace(URL_QUERY_SECRET_RE, (_match, sep, name, eq) => `${sep}${name}${eq}${REDACTED}`);
|
|
44
47
|
out = out.replace(BARE_SECRET_RE, (_match, lead, name, sep) => `${lead}${name}${sep}${REDACTED}`);
|
|
48
|
+
// Bundle redaction shares only the credential catalog; diagnostic IDs and paths must remain
|
|
49
|
+
// readable, so the kernel's general-purpose redaction policy is deliberately not invoked.
|
|
50
|
+
for (const { pattern } of SECRET_SHAPE_PATTERNS) {
|
|
51
|
+
const flags = pattern.flags.includes("g") ? pattern.flags : `${pattern.flags}g`;
|
|
52
|
+
out = out.replace(new RegExp(pattern.source, flags), REDACTED);
|
|
53
|
+
}
|
|
45
54
|
const username = opts.username;
|
|
46
55
|
if (username && username.length > 1) {
|
|
47
56
|
const escaped = username.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
@@ -51,14 +60,15 @@ export function redactText(text, opts = {}) {
|
|
|
51
60
|
}
|
|
52
61
|
return out;
|
|
53
62
|
}
|
|
54
|
-
|
|
63
|
+
/** Redacts valid JSON recursively and falls back to text redaction for invalid JSON. */
|
|
64
|
+
export function redactJsonText({ text }, opts = {}) {
|
|
55
65
|
let parsed;
|
|
56
66
|
try {
|
|
57
67
|
parsed = JSON.parse(text);
|
|
58
68
|
}
|
|
59
69
|
catch {
|
|
60
|
-
return redactText(text, opts);
|
|
70
|
+
return redactText({ text }, opts);
|
|
61
71
|
}
|
|
62
|
-
return JSON.stringify(redactJsonValue(parsed, opts), null, 2);
|
|
72
|
+
return JSON.stringify(redactJsonValue({ value: parsed }, opts), null, 2);
|
|
63
73
|
}
|
|
64
74
|
//# sourceMappingURL=redaction.js.map
|
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
|