@jini-ai/diagnostics 0.7.3-next.2 → 0.7.3-next.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -0
- package/dist/browser-diagnostics.d.ts +43 -0
- package/dist/browser-diagnostics.js +92 -0
- package/dist/console-tee.d.ts +21 -6
- package/dist/console-tee.js +16 -4
- package/dist/domain-dns/index.d.ts +6 -14
- package/dist/domain-dns/index.js +4 -6
- package/dist/local-text.d.ts +4 -1
- package/dist/local-text.js +3 -2
- package/dist/observability/error-events.d.ts +32 -0
- package/dist/observability/error-events.js +32 -0
- package/dist/observability/fanout.js +9 -1
- package/dist/observability/index.d.ts +2 -1
- package/dist/observability/index.js +1 -0
- package/dist/observability/report-error.d.ts +9 -4
- package/dist/observability/report-error.js +7 -6
- package/dist/observability/telemetry-test.d.ts +1 -1
- package/dist/observability/tool-registrations.d.ts +21 -0
- package/dist/observability/tool-registrations.js +38 -0
- package/dist/observability/tracker-noop.d.ts +1 -1
- package/dist/observability/tracker-types.d.ts +2 -57
- package/dist/observability/tracker.d.ts +2 -1
- package/dist/observability/tracker.js +5 -1
- package/dist/redaction/repo-secret-scan.d.ts +48 -0
- package/dist/redaction/repo-secret-scan.js +77 -0
- package/dist/redaction/repo-secret-scan.node.d.ts +56 -0
- package/dist/redaction/repo-secret-scan.node.js +174 -0
- package/dist/redaction/secret-scan.d.ts +15 -0
- package/dist/redaction/secret-scan.js +18 -0
- package/dist/redaction/secrets-only.d.ts +1 -0
- package/dist/redaction/secrets-only.js +2 -0
- package/dist/redaction.d.ts +6 -0
- package/dist/redaction.js +9 -5
- package/dist/server-logs/agent-tools.d.ts +34 -0
- package/dist/server-logs/agent-tools.js +19 -0
- package/dist/server-logs/read-server-logs.d.ts +49 -0
- package/dist/server-logs/read-server-logs.js +90 -0
- package/dist/server-logs/tool-registrations.d.ts +25 -0
- package/dist/server-logs/tool-registrations.js +39 -0
- package/dist/tool-audit/repo.d.ts +107 -0
- package/dist/tool-audit/repo.js +117 -0
- package/dist/tool-audit/repo.memory.d.ts +31 -0
- package/dist/tool-audit/repo.memory.js +30 -0
- package/dist/tool-audit/repo.rows.d.ts +19 -0
- package/dist/tool-audit/repo.rows.js +2 -0
- package/dist/tool-audit/tool-gaps.repo.d.ts +22 -0
- package/dist/tool-audit/tool-gaps.repo.js +36 -0
- package/dist/web-evidence/agent-tools.d.ts +31 -0
- package/dist/web-evidence/agent-tools.js +61 -0
- package/dist/web-evidence/capture-budget.d.ts +3 -10
- package/dist/web-evidence/live-url.d.ts +86 -0
- package/dist/web-evidence/live-url.js +191 -0
- package/dist/web-evidence/page-performance-script.js +30 -32
- package/dist/web-evidence/playwright-browser.d.ts +2 -0
- package/dist/web-evidence/playwright-page-capture.d.ts +129 -0
- package/dist/web-evidence/playwright-page-capture.js +226 -0
- package/dist/web-evidence/public-page.d.ts +2 -1
- package/dist/web-evidence/published-page.d.ts +180 -0
- package/dist/web-evidence/published-page.js +172 -0
- package/dist/web-evidence/request-guard.d.ts +1 -31
- package/dist/web-evidence/site-path-policy.d.ts +20 -0
- package/dist/web-evidence/site-path-policy.js +54 -0
- package/dist/web-evidence/web-screenshot/agent-tools.d.ts +28 -0
- package/dist/web-evidence/web-screenshot/agent-tools.js +34 -0
- package/dist/web-evidence/web-screenshot/tool-registrations.d.ts +79 -0
- package/dist/web-evidence/web-screenshot/tool-registrations.js +47 -0
- package/package.json +114 -6
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
interface CaptureEvent {
|
|
4
|
-
name: string;
|
|
5
|
-
userId: string;
|
|
6
|
-
properties?: Readonly<Record<string, string | number | boolean>>;
|
|
7
|
-
}
|
|
1
|
+
import type { ObservabilityPort } from "@jini-ai/core/contracts/observability";
|
|
2
|
+
import type { CaptureEvent } from "@jini-ai/core/contracts/site/diagnostics-observability";
|
|
8
3
|
interface CapturePort {
|
|
9
4
|
capture(event: CaptureEvent): void | Promise<void>;
|
|
10
5
|
/** Retained for existing provider literals; the tracker never identifies users. */
|
|
@@ -13,56 +8,6 @@ interface CapturePort {
|
|
|
13
8
|
traits?: CaptureEvent['properties'];
|
|
14
9
|
}): void;
|
|
15
10
|
}
|
|
16
|
-
/** Signals share one dependency; each method retains its own typed payload. */
|
|
17
|
-
export interface TrackerErrorContext {
|
|
18
|
-
level?: 'warning' | 'error';
|
|
19
|
-
operation?: string;
|
|
20
|
-
attributes?: OperationAttributes;
|
|
21
|
-
/** Convenience label for callers that only know the route. */
|
|
22
|
-
route?: string;
|
|
23
|
-
exactSecrets?: readonly string[];
|
|
24
|
-
}
|
|
25
|
-
/** Record a semantic outcome; the facade owns ending the underlying lifecycle. First outcome wins unless work throws; explicit cancellation is preserved. */
|
|
26
|
-
export interface TrackerSpan<Outcome = OperationTrackingOutcome> {
|
|
27
|
-
setOutcome(outcome: Outcome): void;
|
|
28
|
-
}
|
|
29
|
-
/** Fixed labels and ids only; never pass user text or credential values as span attributes. */
|
|
30
|
-
export interface OperationSpanOptions {
|
|
31
|
-
attributes?: OperationAttributes;
|
|
32
|
-
}
|
|
33
|
-
export interface RequestSpanOptions {
|
|
34
|
-
request: RequestTrackingInput & RequestTrackingOptions;
|
|
35
|
-
}
|
|
36
|
-
export interface AgentSpanOptions {
|
|
37
|
-
agent: AgentRunTrackingInput & AgentRunTrackingOptions;
|
|
38
|
-
}
|
|
39
|
-
/** Provider failures never escape. Application callback errors retain their original identity.
|
|
40
|
-
* Required fields precede optional settings; no provider-specific types cross this boundary. */
|
|
41
|
-
export interface Tracker {
|
|
42
|
-
/** Current tracing IDs, absent without an active span; optional for older host facades. */
|
|
43
|
-
activeTraceIds?(required?: Record<string, never>, optional?: Record<string, never>): import('@jini-ai/core/contracts/observability').TraceIds | undefined;
|
|
44
|
-
/** Awaitable local admission; does not wait for remote delivery. */
|
|
45
|
-
capture(input: Pick<CaptureEvent, "name" | "userId">, options?: Pick<CaptureEvent, "properties">): void | Promise<void>;
|
|
46
|
-
error(input: {
|
|
47
|
-
error: Error;
|
|
48
|
-
}, options?: {
|
|
49
|
-
context?: TrackerErrorContext;
|
|
50
|
-
}): void;
|
|
51
|
-
trace<T>(input: {
|
|
52
|
-
name: string;
|
|
53
|
-
run: (span: TrackerSpan<RequestTrackingOutcome>) => T | Promise<T>;
|
|
54
|
-
}, options: RequestSpanOptions): Promise<T>;
|
|
55
|
-
trace<T>(input: {
|
|
56
|
-
name: string;
|
|
57
|
-
run: (span: TrackerSpan<AgentRunTrackingOutcome>) => T | Promise<T>;
|
|
58
|
-
}, options: AgentSpanOptions): Promise<T>;
|
|
59
|
-
trace<T>(input: {
|
|
60
|
-
name: string;
|
|
61
|
-
run: (span: TrackerSpan) => T | Promise<T>;
|
|
62
|
-
}, options?: OperationSpanOptions): Promise<T>;
|
|
63
|
-
/** Numeric measurement; defaults to a gauge. Fixed names and low-cardinality attributes only. */
|
|
64
|
-
metric(input: MetricInput, options?: MetricOptions): void;
|
|
65
|
-
}
|
|
66
11
|
export interface TrackerProviders {
|
|
67
12
|
/** Already guarded by the host's existing consent policy; never guard a second time. */
|
|
68
13
|
productAnalytics?: CapturePort | undefined;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { Tracker
|
|
1
|
+
import type { Tracker } from "@jini-ai/core/contracts/site/diagnostics-observability";
|
|
2
|
+
import type { TrackerOptions, TrackerProviders } from "./tracker-types.js";
|
|
2
3
|
/** Fixed diagnostic, once per facade; provider errors can contain credentials and are never logged.
|
|
3
4
|
* @complexity O(1) time/space. */
|
|
4
5
|
export declare function createTrackerWarning(_required: Record<string, never>, { warn }?: TrackerOptions): () => void;
|
|
@@ -27,7 +27,11 @@ function startSpan({ observability, name, options }) {
|
|
|
27
27
|
...(options.agent.conversationId === undefined ? {} : { conversationId: options.agent.conversationId }),
|
|
28
28
|
...(options.agent.agentName === undefined ? {} : { agentName: options.agent.agentName }),
|
|
29
29
|
});
|
|
30
|
-
return observability.trackOperation({
|
|
30
|
+
return observability.trackOperation({
|
|
31
|
+
name,
|
|
32
|
+
...(options.attributes ? { attributes: options.attributes } : {}),
|
|
33
|
+
...(options.traceparent ? { traceparent: options.traceparent } : {}),
|
|
34
|
+
});
|
|
31
35
|
}
|
|
32
36
|
/** Choose the lifecycle's typed default or failure outcome. @complexity O(1). */
|
|
33
37
|
function spanOutcome({ options, failure }) {
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export interface SecretScanViolation {
|
|
2
|
+
/** Repo-root-relative path, forward slashes. */
|
|
3
|
+
file: string;
|
|
4
|
+
patternName: string;
|
|
5
|
+
/** 1-based line number, or "binary" when the file's content is not text (a NUL byte was found in
|
|
6
|
+
* its first 8000 bytes — the same heuristic `git`/`grep -I` use to classify binaries), or "path"
|
|
7
|
+
* when the match sits in the file or directory NAME itself. */
|
|
8
|
+
line: number | "binary" | "path";
|
|
9
|
+
}
|
|
10
|
+
/** One tracked file's (or historical blob's) already-read, latin1-decoded content, ready to scan. */
|
|
11
|
+
interface ScannableContent {
|
|
12
|
+
readonly text: string;
|
|
13
|
+
readonly isBinary: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare function scanTrackedRepo({ ports, policy }: {
|
|
16
|
+
ports: {
|
|
17
|
+
trackedPaths: () => readonly string[];
|
|
18
|
+
readTracked: (required: {
|
|
19
|
+
file: string;
|
|
20
|
+
}) => ScannableContent | null;
|
|
21
|
+
};
|
|
22
|
+
policy: {
|
|
23
|
+
selectPath: (required: {
|
|
24
|
+
file: string;
|
|
25
|
+
}) => boolean;
|
|
26
|
+
maxScanBytes: number;
|
|
27
|
+
isAllowlisted: (required: {
|
|
28
|
+
file: string;
|
|
29
|
+
patternName: string;
|
|
30
|
+
value: string;
|
|
31
|
+
}) => boolean;
|
|
32
|
+
};
|
|
33
|
+
}, _optional?: Record<string, never>): SecretScanViolation[];
|
|
34
|
+
export declare function scanRepoHistory({ ports, policy }: {
|
|
35
|
+
ports: {
|
|
36
|
+
historicalPaths: () => readonly string[];
|
|
37
|
+
historicalBlobs: () => readonly {
|
|
38
|
+
sha: string;
|
|
39
|
+
path: string;
|
|
40
|
+
}[];
|
|
41
|
+
readBlobContents: (required: {
|
|
42
|
+
shas: readonly string[];
|
|
43
|
+
}) => ReadonlyMap<string, string>;
|
|
44
|
+
};
|
|
45
|
+
policy: Parameters<typeof scanTrackedRepo>[0]["policy"];
|
|
46
|
+
}, _optional?: Record<string, never>): SecretScanViolation[];
|
|
47
|
+
export {};
|
|
48
|
+
//# sourceMappingURL=repo-secret-scan.d.ts.map
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { scanTextForSecrets } from "./secret-scan.js";
|
|
2
|
+
function lineNumberAt({ text, index }, _optional = {}) {
|
|
3
|
+
let line = 1;
|
|
4
|
+
for (let i = 0; i < index; i++)
|
|
5
|
+
if (text.charCodeAt(i) === 10)
|
|
6
|
+
line++;
|
|
7
|
+
return line;
|
|
8
|
+
}
|
|
9
|
+
/** Stands in for every credential-shaped substring of a reported path. */
|
|
10
|
+
const REDACTED = "[redacted]";
|
|
11
|
+
/** A report must never repeat the value it found: redact credential-shaped substrings of a path. */
|
|
12
|
+
function redactPath({ file }, _optional = {}) {
|
|
13
|
+
let redacted = file;
|
|
14
|
+
for (const hit of scanTextForSecrets({ text: file }))
|
|
15
|
+
redacted = redacted.split(hit.value).join(REDACTED);
|
|
16
|
+
return redacted;
|
|
17
|
+
}
|
|
18
|
+
/** A file or directory NAME can carry a credential too (an empty file still has one), so every
|
|
19
|
+
* tracked and historical path is scanned before extension filtering or blob dedupe. */
|
|
20
|
+
function scanPathForViolations({ file, policy }, _optional = {}) {
|
|
21
|
+
return scanTextForSecrets({ text: file })
|
|
22
|
+
.filter((hit) => !policy.isAllowlisted({ file, patternName: hit.patternName, value: hit.value }))
|
|
23
|
+
.map((hit) => ({ file: redactPath({ file }), patternName: hit.patternName, line: "path" }));
|
|
24
|
+
}
|
|
25
|
+
/** Scans one already-read file's content for secret-shaped hits, filtering out allowlisted ones
|
|
26
|
+
* and shaping each remaining hit into a reportable {@link SecretScanViolation}. Shared by the
|
|
27
|
+
* tip scan ({@link scanRepoForSecrets}) and the history scan ({@link scanGitHistoryForSecrets}). */
|
|
28
|
+
function scanContentForViolations({ file, content, policy }, _optional = {}) {
|
|
29
|
+
const violations = [];
|
|
30
|
+
for (const hit of scanTextForSecrets({ text: content.text })) {
|
|
31
|
+
if (policy.isAllowlisted({ file, patternName: hit.patternName, value: hit.value }))
|
|
32
|
+
continue;
|
|
33
|
+
violations.push({
|
|
34
|
+
file: redactPath({ file }),
|
|
35
|
+
patternName: hit.patternName,
|
|
36
|
+
line: content.isBinary ? "binary" : lineNumberAt({ text: content.text, index: hit.index }),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return violations;
|
|
40
|
+
}
|
|
41
|
+
// A single NUL character, built via fromCharCode rather than an inline escape literal so this
|
|
42
|
+
// file's own source never embeds a raw control byte.
|
|
43
|
+
const NUL_CHAR = String.fromCharCode(0);
|
|
44
|
+
/** Converts one historical blob's raw latin1-decoded content into {@link ScannableContent}, or
|
|
45
|
+
* `null` when it's missing (shouldn't happen — `readBlobContents` was given this exact sha) or
|
|
46
|
+
* over the size cap (see file header's size-cap rationale). */
|
|
47
|
+
function toScannableBlob({ text, policy }, _optional = {}) {
|
|
48
|
+
if (text === undefined || text.length > policy.maxScanBytes)
|
|
49
|
+
return null;
|
|
50
|
+
return { text, isBinary: text.slice(0, 8000).includes(NUL_CHAR) };
|
|
51
|
+
}
|
|
52
|
+
export function scanTrackedRepo({ ports, policy }, _optional = {}) {
|
|
53
|
+
const violations = [];
|
|
54
|
+
for (const relFile of ports.trackedPaths()) {
|
|
55
|
+
violations.push(...scanPathForViolations({ file: relFile, policy }));
|
|
56
|
+
if (!policy.selectPath({ file: relFile }))
|
|
57
|
+
continue;
|
|
58
|
+
const content = ports.readTracked({ file: relFile });
|
|
59
|
+
if (!content || content.text.length > policy.maxScanBytes)
|
|
60
|
+
continue;
|
|
61
|
+
violations.push(...scanContentForViolations({ file: relFile, content, policy }));
|
|
62
|
+
}
|
|
63
|
+
return violations;
|
|
64
|
+
}
|
|
65
|
+
export function scanRepoHistory({ ports, policy }, _optional = {}) {
|
|
66
|
+
const violations = ports.historicalPaths().flatMap((file) => scanPathForViolations({ file, policy }));
|
|
67
|
+
const blobs = ports.historicalBlobs().filter((b) => policy.selectPath({ file: b.path }));
|
|
68
|
+
const contents = ports.readBlobContents({ shas: blobs.map((b) => b.sha) });
|
|
69
|
+
for (const { path: relPath, sha } of blobs) {
|
|
70
|
+
const content = toScannableBlob({ text: contents.get(sha), policy });
|
|
71
|
+
if (!content)
|
|
72
|
+
continue;
|
|
73
|
+
violations.push(...scanContentForViolations({ file: relPath, content, policy }));
|
|
74
|
+
}
|
|
75
|
+
return violations;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=repo-secret-scan.js.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { scanTrackedRepo, type SecretScanViolation } from "./repo-secret-scan.js";
|
|
2
|
+
/** Real-repo scan: every tracked file (per `git ls-files`), latin1-decoded so binary content is
|
|
3
|
+
* scanned byte-for-byte alongside text (see file header). */
|
|
4
|
+
export declare function scanRepoForSecrets({ repoRoot, runner, fs, policy }: {
|
|
5
|
+
repoRoot: string;
|
|
6
|
+
runner: (args: readonly string[], options: {
|
|
7
|
+
cwd: string;
|
|
8
|
+
encoding: "utf8" | "latin1";
|
|
9
|
+
input?: string;
|
|
10
|
+
maxBuffer?: number;
|
|
11
|
+
}) => string;
|
|
12
|
+
fs: {
|
|
13
|
+
statSync(file: string): {
|
|
14
|
+
size: number;
|
|
15
|
+
isFile(): boolean;
|
|
16
|
+
};
|
|
17
|
+
readFileSync(file: string): Buffer;
|
|
18
|
+
};
|
|
19
|
+
policy: Parameters<typeof scanTrackedRepo>[0]["policy"];
|
|
20
|
+
}, _optional?: Record<string, never>): SecretScanViolation[];
|
|
21
|
+
/** History scan: every blob ever committed to any local branch/tag, not just the current tip.
|
|
22
|
+
* Closes the gap where a secret committed then removed in a later commit is still fully
|
|
23
|
+
* recoverable from `git log`/`git show` while `scanRepoForSecrets` (tip-only) reports clean.
|
|
24
|
+
* `repoRoot` defaults to this repo but is overridable so tests can point it at a throwaway repo
|
|
25
|
+
* instead of mutating real history. */
|
|
26
|
+
export declare function scanGitHistoryForSecrets({ repoRoot, runner, policy }: Parameters<typeof scanRepoForSecrets>[0], _optional?: Record<string, never>): SecretScanViolation[];
|
|
27
|
+
export declare function createRepoSecretCheck({ repoRoot, runner, fs, skipExtensions, maxScanBytes, exemptions, stdout, stderr, copy }: {
|
|
28
|
+
repoRoot: string;
|
|
29
|
+
runner: Parameters<typeof scanRepoForSecrets>[0]["runner"];
|
|
30
|
+
fs: Parameters<typeof scanRepoForSecrets>[0]["fs"];
|
|
31
|
+
skipExtensions: ReadonlySet<string>;
|
|
32
|
+
maxScanBytes: number;
|
|
33
|
+
exemptions: readonly {
|
|
34
|
+
file: string;
|
|
35
|
+
patternName: string;
|
|
36
|
+
value: string;
|
|
37
|
+
}[];
|
|
38
|
+
stdout: (text: string) => void;
|
|
39
|
+
stderr: (text: string) => void;
|
|
40
|
+
copy: {
|
|
41
|
+
clean: string;
|
|
42
|
+
tip: (count: number) => string;
|
|
43
|
+
history: (count: number) => string;
|
|
44
|
+
guidance: string;
|
|
45
|
+
};
|
|
46
|
+
}, _optional?: {}): {
|
|
47
|
+
scanTip: (_required?: Record<string, never>, _optional?: {}) => SecretScanViolation[];
|
|
48
|
+
scanHistory: (_required?: Record<string, never>, _optional?: {}) => SecretScanViolation[];
|
|
49
|
+
isAllowlisted: ({ file, patternName, value }: {
|
|
50
|
+
file: string;
|
|
51
|
+
patternName: string;
|
|
52
|
+
value: string;
|
|
53
|
+
}, _optional?: {}) => boolean;
|
|
54
|
+
run: (_required: Record<string, never>, _optional?: {}) => 0 | 1;
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=repo-secret-scan.node.d.ts.map
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { scanTrackedRepo, scanRepoHistory } from "./repo-secret-scan.js";
|
|
3
|
+
function listTrackedFiles({ repoRoot, runner }, _optional = {}) {
|
|
4
|
+
const out = runner(["ls-files", "-z"], { cwd: repoRoot, encoding: "utf8" });
|
|
5
|
+
return out.split("\0").filter(Boolean);
|
|
6
|
+
}
|
|
7
|
+
/** Reads one tracked file's content for scanning, or `null` if it should be skipped: a skipped
|
|
8
|
+
* binary-media extension, missing from disk (e.g. removed locally but not yet staged as
|
|
9
|
+
* deleted), not a regular file, or over the size cap (see file header). */
|
|
10
|
+
function readScannableFile({ repoRoot, relFile, fs, maxScanBytes }, _optional = {}) {
|
|
11
|
+
const absFile = path.join(repoRoot, relFile);
|
|
12
|
+
let stat;
|
|
13
|
+
try {
|
|
14
|
+
stat = fs.statSync(absFile);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
if (!stat.isFile() || stat.size > maxScanBytes)
|
|
20
|
+
return null;
|
|
21
|
+
const buf = fs.readFileSync(absFile);
|
|
22
|
+
return { text: buf.toString("latin1"), isBinary: buf.subarray(0, 8000).includes(0) };
|
|
23
|
+
}
|
|
24
|
+
/** Real-repo scan: every tracked file (per `git ls-files`), latin1-decoded so binary content is
|
|
25
|
+
* scanned byte-for-byte alongside text (see file header). */
|
|
26
|
+
export function scanRepoForSecrets({ repoRoot, runner, fs, policy }, _optional = {}) {
|
|
27
|
+
return scanTrackedRepo({
|
|
28
|
+
ports: {
|
|
29
|
+
trackedPaths: () => listTrackedFiles({ repoRoot, runner }),
|
|
30
|
+
readTracked: ({ file }) => readScannableFile({ repoRoot, relFile: file, fs, maxScanBytes: policy.maxScanBytes }),
|
|
31
|
+
},
|
|
32
|
+
policy,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/** Every blob object reachable from any local branch or tag, deduped by blob SHA (a content hash,
|
|
36
|
+
* so identical file content is scanned exactly once regardless of how many commits or paths
|
|
37
|
+
* reference it). See file header's History scanning section. */
|
|
38
|
+
/** Parses `git rev-list --objects --all` output into a sha -> first-seen-path map. Commit objects
|
|
39
|
+
* (listed with no path suffix) are skipped; only the first path seen per sha is kept (content,
|
|
40
|
+
* not path, is what {@link listHistoricalBlobs} dedupes on). */
|
|
41
|
+
function parseObjectPaths({ objectsOut }, _optional = {}) {
|
|
42
|
+
const pathBySha = new Map();
|
|
43
|
+
for (const line of objectsOut.split("\n")) {
|
|
44
|
+
const spaceIdx = line.indexOf(" ");
|
|
45
|
+
if (spaceIdx === -1)
|
|
46
|
+
continue; // commit objects are listed with no path suffix
|
|
47
|
+
const sha = line.slice(0, spaceIdx);
|
|
48
|
+
const relPath = line.slice(spaceIdx + 1);
|
|
49
|
+
if (relPath && !pathBySha.has(sha))
|
|
50
|
+
pathBySha.set(sha, relPath);
|
|
51
|
+
}
|
|
52
|
+
return pathBySha;
|
|
53
|
+
}
|
|
54
|
+
/** Parses `git cat-file --batch-check` output, keeping only blob objects — `rev-list --objects`
|
|
55
|
+
* also lists tree objects (which carry a path but aren't scannable file content). */
|
|
56
|
+
function filterBlobShas({ typeCheckOut, pathBySha }, _optional = {}) {
|
|
57
|
+
const blobs = [];
|
|
58
|
+
for (const line of typeCheckOut.split("\n")) {
|
|
59
|
+
if (!line)
|
|
60
|
+
continue;
|
|
61
|
+
const [sha, type] = line.split(" ");
|
|
62
|
+
if (type === "blob" && sha !== undefined) {
|
|
63
|
+
const path = pathBySha.get(sha);
|
|
64
|
+
if (path === undefined)
|
|
65
|
+
throw new Error(`Historical blob ${sha} has no source path`);
|
|
66
|
+
blobs.push({ sha, path });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return blobs;
|
|
70
|
+
}
|
|
71
|
+
function listHistoricalBlobs({ repoRoot, runner }, _optional = {}) {
|
|
72
|
+
const objectsOut = runner(["rev-list", "--objects", "--all"], {
|
|
73
|
+
cwd: repoRoot,
|
|
74
|
+
encoding: "utf8",
|
|
75
|
+
maxBuffer: 256 * 1024 * 1024,
|
|
76
|
+
});
|
|
77
|
+
const pathBySha = parseObjectPaths({ objectsOut });
|
|
78
|
+
if (pathBySha.size === 0)
|
|
79
|
+
return [];
|
|
80
|
+
const shas = [...pathBySha.keys()];
|
|
81
|
+
const typeCheckOut = runner(["cat-file", "--batch-check=%(objectname) %(objecttype)"], {
|
|
82
|
+
cwd: repoRoot,
|
|
83
|
+
input: shas.join("\n") + "\n",
|
|
84
|
+
encoding: "utf8",
|
|
85
|
+
maxBuffer: 256 * 1024 * 1024,
|
|
86
|
+
});
|
|
87
|
+
return filterBlobShas({ typeCheckOut, pathBySha });
|
|
88
|
+
}
|
|
89
|
+
/** Reads every listed blob's content in one `git cat-file --batch` pass, latin1-decoded (same
|
|
90
|
+
* binary-preserving technique `scanRepoForSecrets` uses; see file header). Keyed by blob SHA. */
|
|
91
|
+
function readBlobContents({ repoRoot, shas, runner }, _optional = {}) {
|
|
92
|
+
const contents = new Map();
|
|
93
|
+
if (shas.length === 0)
|
|
94
|
+
return contents;
|
|
95
|
+
const out = runner(["cat-file", "--batch"], {
|
|
96
|
+
cwd: repoRoot,
|
|
97
|
+
input: shas.join("\n") + "\n",
|
|
98
|
+
encoding: "latin1",
|
|
99
|
+
maxBuffer: 512 * 1024 * 1024,
|
|
100
|
+
});
|
|
101
|
+
let offset = 0;
|
|
102
|
+
while (offset < out.length) {
|
|
103
|
+
const headerEnd = out.indexOf("\n", offset);
|
|
104
|
+
if (headerEnd === -1)
|
|
105
|
+
break;
|
|
106
|
+
const [sha, , sizeStr] = out.slice(offset, headerEnd).split(" ");
|
|
107
|
+
// Malformed/unexpected batch records stop the scan rather than misparse.
|
|
108
|
+
if (sha === undefined || sizeStr === undefined)
|
|
109
|
+
return contents;
|
|
110
|
+
const size = Number(sizeStr);
|
|
111
|
+
const contentStart = headerEnd + 1;
|
|
112
|
+
contents.set(sha, out.slice(contentStart, contentStart + size));
|
|
113
|
+
offset = contentStart + size + 1; // +1 for the trailing newline git appends after each record
|
|
114
|
+
}
|
|
115
|
+
return contents;
|
|
116
|
+
}
|
|
117
|
+
/** Every distinct path any commit on any local branch/tag ever added or changed (merges included),
|
|
118
|
+
* sorted. Blob dedupe keys on content, so a credential-named file sharing its blob with another
|
|
119
|
+
* file never reaches the blob list under its own name; paths are listed separately. */
|
|
120
|
+
function listHistoricalPaths({ repoRoot, runner }, _optional = {}) {
|
|
121
|
+
const out = runner(["log", "--all", "-m", "--no-renames", "--format=", "--name-only", "-z"], {
|
|
122
|
+
cwd: repoRoot,
|
|
123
|
+
encoding: "utf8",
|
|
124
|
+
maxBuffer: 256 * 1024 * 1024,
|
|
125
|
+
});
|
|
126
|
+
return [...new Set(out.split("\0").map((entry) => entry.replace(/^\n+/, "")).filter(Boolean))].sort();
|
|
127
|
+
}
|
|
128
|
+
/** History scan: every blob ever committed to any local branch/tag, not just the current tip.
|
|
129
|
+
* Closes the gap where a secret committed then removed in a later commit is still fully
|
|
130
|
+
* recoverable from `git log`/`git show` while `scanRepoForSecrets` (tip-only) reports clean.
|
|
131
|
+
* `repoRoot` defaults to this repo but is overridable so tests can point it at a throwaway repo
|
|
132
|
+
* instead of mutating real history. */
|
|
133
|
+
export function scanGitHistoryForSecrets({ repoRoot, runner, policy }, _optional = {}) {
|
|
134
|
+
return scanRepoHistory({
|
|
135
|
+
ports: {
|
|
136
|
+
historicalPaths: () => listHistoricalPaths({ repoRoot, runner }),
|
|
137
|
+
historicalBlobs: () => listHistoricalBlobs({ repoRoot, runner }),
|
|
138
|
+
readBlobContents: ({ shas }) => readBlobContents({ repoRoot, shas, runner }),
|
|
139
|
+
},
|
|
140
|
+
policy,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
export function createRepoSecretCheck({ repoRoot, runner, fs, skipExtensions, maxScanBytes, exemptions, stdout, stderr, copy }, _optional = {}) {
|
|
144
|
+
function isAllowlisted({ file, patternName, value }, _optional = {}) {
|
|
145
|
+
return exemptions.some((e) => e.file === file && e.patternName === patternName && e.value === value);
|
|
146
|
+
}
|
|
147
|
+
const policy = { selectPath: ({ file }) => !skipExtensions.has(path.extname(file).toLowerCase()), maxScanBytes, isAllowlisted };
|
|
148
|
+
const scanTip = (_required = {}, _optional = {}) => scanRepoForSecrets({ repoRoot, runner, fs, policy });
|
|
149
|
+
const scanHistory = (_required = {}, _optional = {}) => scanGitHistoryForSecrets({ repoRoot, runner, fs, policy });
|
|
150
|
+
function run(_required, _optional = {}) {
|
|
151
|
+
const tipViolations = scanTip();
|
|
152
|
+
const historyViolations = scanHistory();
|
|
153
|
+
if (tipViolations.length === 0 && historyViolations.length === 0) {
|
|
154
|
+
stdout(copy.clean);
|
|
155
|
+
return 0;
|
|
156
|
+
}
|
|
157
|
+
if (tipViolations.length > 0) {
|
|
158
|
+
stderr(copy.tip(tipViolations.length));
|
|
159
|
+
for (const v of tipViolations) {
|
|
160
|
+
stderr(` - ${v.file}:${v.line} [${v.patternName}]`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (historyViolations.length > 0) {
|
|
164
|
+
stderr(copy.history(historyViolations.length));
|
|
165
|
+
for (const v of historyViolations) {
|
|
166
|
+
stderr(` - ${v.file}:${v.line} [${v.patternName}]`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
stderr(copy.guidance);
|
|
170
|
+
return 1;
|
|
171
|
+
}
|
|
172
|
+
return { scanTip, scanHistory, isAllowlisted, run };
|
|
173
|
+
}
|
|
174
|
+
//# sourceMappingURL=repo-secret-scan.node.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface SecretScanHit {
|
|
2
|
+
readonly patternName: string;
|
|
3
|
+
/** Character offset within the scanned text where the match starts. */
|
|
4
|
+
readonly index: number;
|
|
5
|
+
/** The exact matched substring — the allowlist is scoped to this, not just (file, patternName),
|
|
6
|
+
* so a NEW different secret matching the same pattern in an already-allowlisted file is still
|
|
7
|
+
* caught (see file header's Allowlist section). */
|
|
8
|
+
readonly value: string;
|
|
9
|
+
}
|
|
10
|
+
/** Core scanner, unit-testable directly against synthetic text (no filesystem, no git).
|
|
11
|
+
* @complexity O(p*n), p = pattern count (fixed, small), n = text length. */
|
|
12
|
+
export declare function scanTextForSecrets({ text }: {
|
|
13
|
+
text: string;
|
|
14
|
+
}, _optional?: {}): SecretScanHit[];
|
|
15
|
+
//# sourceMappingURL=secret-scan.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SECRET_PATTERNS } from "../core/secrets-only.js";
|
|
2
|
+
/** Core scanner, unit-testable directly against synthetic text (no filesystem, no git).
|
|
3
|
+
* @complexity O(p*n), p = pattern count (fixed, small), n = text length. */
|
|
4
|
+
export function scanTextForSecrets({ text }, _optional = {}) {
|
|
5
|
+
const hits = [];
|
|
6
|
+
for (const { name, pattern } of SECRET_PATTERNS) {
|
|
7
|
+
const flags = pattern.flags.includes("g") ? pattern.flags : `${pattern.flags}g`;
|
|
8
|
+
const re = new RegExp(pattern.source, flags);
|
|
9
|
+
let match;
|
|
10
|
+
while ((match = re.exec(text)) !== null) {
|
|
11
|
+
hits.push({ patternName: name, index: match.index, value: match[0] });
|
|
12
|
+
if (match[0].length === 0)
|
|
13
|
+
re.lastIndex += 1; // guard against zero-length matches looping
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return hits;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=secret-scan.js.map
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
// Compatibility path; the shared implementation lives in core.
|
|
2
2
|
export * from '../core/secrets-only.js';
|
|
3
|
+
// Text scanner built on the same vendor catalog, so a scan and a redaction can never disagree.
|
|
4
|
+
export * from './secret-scan.js';
|
|
3
5
|
//# sourceMappingURL=secrets-only.js.map
|
package/dist/redaction.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
+
import { type SecretRedactionPattern } from "@jini-ai/core";
|
|
1
2
|
export interface RedactionOptions {
|
|
2
3
|
username?: string | undefined;
|
|
4
|
+
/**
|
|
5
|
+
* Host-owned credential shapes (e.g. a product's own API-key format) that Jini's neutral catalog
|
|
6
|
+
* cannot know. Injected per call, never registered globally; same shape as core's `redactSecrets`.
|
|
7
|
+
*/
|
|
8
|
+
extraPatterns?: readonly SecretRedactionPattern[] | undefined;
|
|
3
9
|
}
|
|
4
10
|
/** Returns a redacted copy; the required input value is separate from optional path policy. */
|
|
5
11
|
export declare function redactJsonValue({ value }: {
|
package/dist/redaction.js
CHANGED
|
@@ -20,6 +20,11 @@ const BARE_SECRET_RE = /(^|[\s,;])(access_token|refresh_token|id_token|api[_-]?k
|
|
|
20
20
|
// Case-insensitive, so the class needs only one letter case.
|
|
21
21
|
const HTTP_AUTH_SCHEME_RE = /\b(Bearer|Token|Basic)\s+([a-z0-9._~\-+/=:]{4,})/gi;
|
|
22
22
|
const REDACTED = "[REDACTED]";
|
|
23
|
+
/** `String.replace` needs a global pattern to replace every match; strip-then-append keeps an
|
|
24
|
+
* already-global pattern valid (a duplicated `g` flag would throw). */
|
|
25
|
+
function replaceAll({ text, pattern }, _options = {}) {
|
|
26
|
+
return text.replace(new RegExp(pattern.source, `${pattern.flags.replace("g", "")}g`), REDACTED);
|
|
27
|
+
}
|
|
23
28
|
function redactJsonObject({ value }, opts = {}) {
|
|
24
29
|
const out = {};
|
|
25
30
|
for (const [key, raw] of Object.entries(value)) {
|
|
@@ -53,11 +58,10 @@ export function redactText({ text }, opts = {}) {
|
|
|
53
58
|
out = out.replace(BARE_SECRET_RE, (_match, lead, name, sep) => `${lead}${name}${sep}${REDACTED}`);
|
|
54
59
|
// Bundle redaction shares only the credential catalog; diagnostic IDs and paths must remain
|
|
55
60
|
// readable, so the kernel's general-purpose redaction policy is deliberately not invoked.
|
|
56
|
-
for (const { pattern } of SECRET_SHAPE_PATTERNS)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
out =
|
|
60
|
-
}
|
|
61
|
+
for (const { pattern } of SECRET_SHAPE_PATTERNS)
|
|
62
|
+
out = replaceAll({ text: out, pattern });
|
|
63
|
+
for (const { regex } of opts.extraPatterns ?? [])
|
|
64
|
+
out = replaceAll({ text: out, pattern: regex });
|
|
61
65
|
const username = opts.username;
|
|
62
66
|
if (username && username.length > 1) {
|
|
63
67
|
const escaped = username.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** Catalog for the read-only server-log diagnostic (gap A-04). */
|
|
2
|
+
export declare const serverLogsAgentToolCatalog: {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
sideEffects: "none";
|
|
6
|
+
authorization: {
|
|
7
|
+
permission: string;
|
|
8
|
+
};
|
|
9
|
+
inputSchema: {
|
|
10
|
+
type: string;
|
|
11
|
+
additionalProperties: boolean;
|
|
12
|
+
properties: {
|
|
13
|
+
level: {
|
|
14
|
+
type: string;
|
|
15
|
+
enum: ("error" | "debug" | "info" | "warn")[];
|
|
16
|
+
};
|
|
17
|
+
sinceIso: {
|
|
18
|
+
type: string;
|
|
19
|
+
format: string;
|
|
20
|
+
};
|
|
21
|
+
contains: {
|
|
22
|
+
type: string;
|
|
23
|
+
maxLength: number;
|
|
24
|
+
};
|
|
25
|
+
limit: {
|
|
26
|
+
type: string;
|
|
27
|
+
minimum: number;
|
|
28
|
+
maximum: number;
|
|
29
|
+
clamp: boolean;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
}[];
|
|
34
|
+
//# sourceMappingURL=agent-tools.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { MAX_CONTAINS_LENGTH, MAX_SERVER_LOG_LIMIT, SERVER_LOG_LEVELS } from "./read-server-logs.js";
|
|
2
|
+
/** Catalog for the read-only server-log diagnostic (gap A-04). */
|
|
3
|
+
export const serverLogsAgentToolCatalog = [{
|
|
4
|
+
name: "system_read_server_logs",
|
|
5
|
+
description: `Reads this site's recent server log lines: console output of the server and its assistant daemon (source "server" or "daemon"), including errors, warnings and unhandled rejections, kept across restarts. Use when the owner asks what went wrong, for recent server errors, or why something failed on the server. Optional input: level (minimum severity: ${SERVER_LOG_LEVELS.join(", ")}; "warn" returns warnings and errors), sinceIso (ISO-8601 date-time), contains (case-insensitive text, at most ${MAX_CONTAINS_LENGTH} characters), limit (1-${MAX_SERVER_LOG_LIMIT}, default 100). Returns {entries: [{seq, at, level, source, message}], matched, buffered, truncated, capturing}; entries are oldest first and are the newest matching lines. Secret values are redacted. capturing false means no log is being recorded, so an empty list is not proof of no errors. seq restarts at 1 after a server restart. Read-only; requires system.read, like the admin server-logs route.`,
|
|
6
|
+
sideEffects: "none",
|
|
7
|
+
authorization: { permission: "system.read" },
|
|
8
|
+
inputSchema: {
|
|
9
|
+
type: "object",
|
|
10
|
+
additionalProperties: false,
|
|
11
|
+
properties: {
|
|
12
|
+
level: { type: "string", enum: [...SERVER_LOG_LEVELS] },
|
|
13
|
+
sinceIso: { type: "string", format: "date-time" },
|
|
14
|
+
contains: { type: "string", maxLength: MAX_CONTAINS_LENGTH },
|
|
15
|
+
limit: { type: "integer", minimum: 1, maximum: MAX_SERVER_LOG_LIMIT, clamp: true },
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
}];
|
|
19
|
+
//# sourceMappingURL=agent-tools.js.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { ServerLogEntry, ServerLogFilters, ServerLogsResult } from "@jini-ai/core/contracts/site/platform-server-logs";
|
|
2
|
+
/**
|
|
3
|
+
* @file `readServerLogs` — the ONE read behind both the admin route
|
|
4
|
+
* (`GET /api/admin/v1/workspaces/:ws/system/server-logs`) and the `system_read_server_logs` chat
|
|
5
|
+
* tool (gap A-04). Both call `parseServerLogFilters` then `readServerLogs`, so a filter means the
|
|
6
|
+
* same thing in the UI and in chat.
|
|
7
|
+
* Now: the route and the chat tool are a host's, and so is where the lines live: it injects a
|
|
8
|
+
* {@link ServerLogSourcePort}.
|
|
9
|
+
*/
|
|
10
|
+
export declare const SERVER_LOG_LEVELS: readonly ["debug", "info", "warn", "error"];
|
|
11
|
+
export declare const DEFAULT_SERVER_LOG_LIMIT = 100;
|
|
12
|
+
export declare const MAX_SERVER_LOG_LIMIT = 500;
|
|
13
|
+
export declare const MAX_CONTAINS_LENGTH = 200;
|
|
14
|
+
/** What a reader needs from wherever the lines live (the in-memory buffer, or a log file). */
|
|
15
|
+
export interface ServerLogSourcePort {
|
|
16
|
+
/** `capturing` is false when nothing records lines, so an empty result is not "no errors". */
|
|
17
|
+
read(): {
|
|
18
|
+
entries: readonly ServerLogEntry[];
|
|
19
|
+
capturing: boolean;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/** A filter value the caller sent that cannot be used. The message names the field. */
|
|
23
|
+
export declare class ServerLogFilterError extends Error {
|
|
24
|
+
constructor({ message }: {
|
|
25
|
+
message: string;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Validates filters from either a JSON tool input or an HTTP query (where every value is a string).
|
|
30
|
+
* @param required The raw record; unknown keys are ignored here (the tool schema refuses them).
|
|
31
|
+
* @returns Normalized filters.
|
|
32
|
+
* @throws {ServerLogFilterError} Naming the first unusable field.
|
|
33
|
+
* @complexity O(1).
|
|
34
|
+
*/
|
|
35
|
+
export declare function parseServerLogFilters(required: {
|
|
36
|
+
raw: Record<string, unknown>;
|
|
37
|
+
}): ServerLogFilters;
|
|
38
|
+
/**
|
|
39
|
+
* Returns the newest matching server log lines. Read-only; lines were redacted when captured.
|
|
40
|
+
* @param required The log source port.
|
|
41
|
+
* @param optional Filters from `parseServerLogFilters`.
|
|
42
|
+
* @returns Matching lines (oldest first) plus counts so a caller can say what was left out.
|
|
43
|
+
* @complexity O(n) over buffered lines (n <= the buffer cap).
|
|
44
|
+
* @example readServerLogs({ logs }, { level: "error", limit: 20 });
|
|
45
|
+
*/
|
|
46
|
+
export declare function readServerLogs(required: {
|
|
47
|
+
logs: ServerLogSourcePort;
|
|
48
|
+
}, optional?: ServerLogFilters): ServerLogsResult;
|
|
49
|
+
//# sourceMappingURL=read-server-logs.d.ts.map
|