@jini-ai/diagnostics 0.4.0 → 0.5.1
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 +24 -0
- package/dist/core/secrets-only.d.ts +44 -0
- package/dist/core/secrets-only.js +179 -0
- package/dist/index.d.ts +4 -43
- package/dist/index.js +4 -43
- package/dist/observability/hooks.d.ts +2 -1
- package/dist/observability/hooks.js +12 -4
- package/dist/observability/index.d.ts +5 -2
- package/dist/observability/index.js +5 -3
- 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 +3 -0
- package/dist/observability/noop.js +18 -2
- package/dist/observability/otel.d.ts +19 -5
- package/dist/observability/otel.js +105 -13
- package/dist/observability/ports.d.ts +72 -1
- package/dist/redaction/secrets-only.d.ts +1 -43
- package/dist/redaction/secrets-only.js +2 -178
- package/package.json +20 -5
- package/dist/redaction/secret-patterns.d.ts +0 -8
- package/dist/redaction/secret-patterns.js +0 -18
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# @jini-ai/diagnostics
|
|
2
2
|
|
|
3
|
+
## 0.5.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Tovu clean-up release (2026-10-08): code Tovu moved into Jini, plus the Jini clean-up (see the commit log since 0.5.0).
|
|
8
|
+
|
|
9
|
+
## 0.5.0 — 2026-10-05
|
|
10
|
+
|
|
11
|
+
### BREAKING (for hosts that implement the observability ports themselves)
|
|
12
|
+
|
|
13
|
+
- `ObservabilityPort` gains `trackDbQuery`, `trackOutboundCall` and `trackAgentRun`; `TraceSpanPort` gains `addEvent`, and `setStatus` takes an optional `description`; `TracerPort.startSpan` takes `kind: 'server' | 'client' | 'internal'` and an optional `{ parent }`. Ports built with `createObservabilityPort`/`createOtelObservabilityPort` or the no-op port need no change. `RequestTracker.run` is optional, so request trackers written before scoping still satisfy the port.
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
- DB, outbound and agent-run signals: `instrumentStorageKernel` (in place, via a Kysely capture plugin; no SQL text crosses the port), `trackHttpClient`, and `trackFetch` (one outbound span per call of any fetch-shaped function; identity for the no-op port). The OTel adapter redacts: outbound URLs keep scheme/host/port only, inbound targets drop the query and blank secret shapes, errors are exported by type only.
|
|
18
|
+
- `isNoopObservabilityPort` and shared frozen no-op trackers, so decorators skip wrapping when observability is off.
|
|
19
|
+
- New `./observability/node` entry with `createAsyncLocalSpanScope` (`SpanScopePort` on `AsyncLocalStorage`); without a span scope every span is a root.
|
|
20
|
+
|
|
21
|
+
### Fixed
|
|
22
|
+
|
|
23
|
+
- The OTel adapter's `trackRequest` records the `requestId` option as the `http.request.id` span attribute (it was ignored) and returns it on the tracker.
|
|
24
|
+
- Internal `@jini-ai/core` dependency is a caret range (`workspace:^`) instead of an exact pin.
|
|
25
|
+
|
|
3
26
|
## 0.4.0 — 2026-10-02
|
|
4
27
|
|
|
5
28
|
### BREAKING
|
|
@@ -9,6 +32,7 @@
|
|
|
9
32
|
|
|
10
33
|
## Unreleased
|
|
11
34
|
|
|
35
|
+
- The OTel adapter's `trackRequest` now honors `{ requestId }`: the id is recorded as the `http.request.id` span attribute and returned on the tracker. It was previously dropped.
|
|
12
36
|
- **BREAKING:** Remove local `ClockPort`/`DiagnosticsClockPort`; all clocks use `Clock.nowMs()` from `@jini-ai/core/primitives`. Add core as a package dependency.
|
|
13
37
|
- Share the eleven byte-pinned credential patterns with core while retaining all redaction/scanner export names and diagnostics-specific policy. Bundle text and JSON redaction also mask standalone provider credential shapes; ordinary IDs, hashes and paths stay readable.
|
|
14
38
|
- Off-origin evidence copy now says "the inspected origin".
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** Secret-only error-display policy. Preserves paths, network addresses, emails, timestamps,
|
|
2
|
+
* tool IDs and ordinary prose. Ordered rules are idempotent; product formats come from policy. */
|
|
3
|
+
/** One (text in, text + count out) redaction pass. `redactions` is the number of values blanked —
|
|
4
|
+
* zero for text with nothing secret-shaped in it. */
|
|
5
|
+
export interface SecretRedaction {
|
|
6
|
+
readonly text: string;
|
|
7
|
+
readonly redactions: number;
|
|
8
|
+
}
|
|
9
|
+
/** One ordered rule: a global pattern and how to rebuild its replacement from the match's capture
|
|
10
|
+
* groups. Private — callers only ever see {@link redactSecretShapes}'s aggregate result. */
|
|
11
|
+
export interface RedactionRule {
|
|
12
|
+
readonly kind: string;
|
|
13
|
+
readonly pattern: RegExp;
|
|
14
|
+
readonly replacement: (required: {
|
|
15
|
+
match: readonly (string | undefined)[];
|
|
16
|
+
}) => string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Blanks every secret-shaped VALUE in `text`, leaving everything else — including IPs, absolute
|
|
20
|
+
* paths, emails, tool ids, and ordinary prose — untouched.
|
|
21
|
+
*
|
|
22
|
+
* @param required - Text and the caller's redaction policy. The text is arbitrary error text. Never re-interpreted as anything other than plain text (no
|
|
23
|
+
* parsing, no partial JSON awareness).
|
|
24
|
+
* @returns The redacted text plus how many values were blanked. `redactions: 0` means nothing
|
|
25
|
+
* secret-shaped was found — the returned `text` is then reference-identical in content (though
|
|
26
|
+
* not necessarily the same string instance) to the input.
|
|
27
|
+
* @complexity O(r*n): each of the fixed, small rule count `r` makes one linear pass over the
|
|
28
|
+
* (at most `n`-length) text. Rules only ever shrink or hold text length steady, so the total work
|
|
29
|
+
* is bounded by `r` passes over the original length.
|
|
30
|
+
* @example
|
|
31
|
+
* redactSecretShapes({ text: "password=hunter2hunter2", policy: {} }); // { text: "password=[REDACTED:labeled_secret]", redactions: 1 }
|
|
32
|
+
* @overallScore 100
|
|
33
|
+
*/
|
|
34
|
+
export interface RedactionPolicy {
|
|
35
|
+
/** Rules for caller-owned formats, applied after vendor/JWT rules and before bearer/labeled rules. Must be idempotent. */
|
|
36
|
+
readonly additionalRules?: readonly RedactionRule[];
|
|
37
|
+
}
|
|
38
|
+
/** Redacts credential values with a required policy; returns text and replacement count. */
|
|
39
|
+
export declare function redactSecretShapes({ text, policy }: {
|
|
40
|
+
text: string;
|
|
41
|
+
policy: RedactionPolicy;
|
|
42
|
+
}): SecretRedaction;
|
|
43
|
+
export { SECRET_SHAPE_PATTERNS as SECRET_PATTERNS, PEM_PATTERN_NAME, type SecretShapePattern as SecretPattern } from "@jini-ai/core";
|
|
44
|
+
//# sourceMappingURL=secrets-only.d.ts.map
|
|
@@ -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/index.d.ts
CHANGED
|
@@ -1,48 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module @jini-ai/diagnostics
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* builder, and a zip packager. See `archived provenance ledger` for full provenance and
|
|
8
|
-
* scope-decision notes (this package is NOT yet in extraction-plan.md's
|
|
9
|
-
* locked §3 package set — see that file for details).
|
|
10
|
-
|
|
11
|
-
* Archived provenance rationale:
|
|
12
|
-
* ## Design decision: `agent-logs.ts` carries real agent-CLI vocabulary, ported anyway
|
|
13
|
-
*
|
|
14
|
-
* `r2-packages.md`'s coupling grade for this package ("LOW... daemon-endpoint
|
|
15
|
-
* comments") was assessed at the whole-package level. Read in isolation,
|
|
16
|
-
* `agent-logs.ts` carries more domain content than the other six files: it
|
|
17
|
-
* hardcodes knowledge of four specific coding-agent CLIs — Claude Code, Codex,
|
|
18
|
-
* OpenCode, and an "AMR"-style OpenCode runtime — including their default
|
|
19
|
-
* config-home directory names (`.claude`, `.codex`, `opencode`) and env-var
|
|
20
|
-
* override names (`CLAUDE_CONFIG_DIR`, `CODEX_HOME`, `OPENCODE_TEST_HOME`,
|
|
21
|
-
* `XDG_DATA_HOME`). "AMR" itself is OD's own internal name for an agent
|
|
22
|
-
* orchestration layer, not a generic term.
|
|
23
|
-
*
|
|
24
|
-
* This was ported anyway, deliberately, not dropped or trimmed, for three
|
|
25
|
-
* reasons: (1) the task brief explicitly lists `agent-logs` as one of the
|
|
26
|
-
* seven modules that make up "diagnostics-bundle tooling" and does not flag it
|
|
27
|
-
* for exclusion the way Target 2's task brief explicitly excluded
|
|
28
|
-
* `project-storage.ts`; (2) every one of these CLI integrations is optional
|
|
29
|
-
* and caller-parameterized (`homeDir`/`claudeConfigDir`/`codexHome`/
|
|
30
|
-
* `amrOpenCodeHome`/`xdgDataHome` are all inputs, not hardcoded paths the
|
|
31
|
-
* function reaches for on its own) — a Jini-based product that drives the same
|
|
32
|
-
* external agent CLIs (Claude Code, Codex, OpenCode are all plausible
|
|
33
|
-
* `@jini/agent-runtime` targets per extraction-plan.md's roadmap) can reuse
|
|
34
|
-
* this verbatim, and one that doesn't simply never calls
|
|
35
|
-
* `buildAgentCliLogSources`; (3) the "AMR" agent slot is additive-only (only
|
|
36
|
-
* appended to `agentDirs` when `amrOpenCodeHome`/`dataDir` is supplied) so a
|
|
37
|
-
* non-OD consumer never sees it activate. Flagged here explicitly rather than
|
|
38
|
-
* silently ported, per this porting session's own standard: a future
|
|
39
|
-
* Coordinator/Software-Architect review of this not-yet-locked package should
|
|
40
|
-
* weigh whether the Claude/Codex/OpenCode/AMR-specific vocabulary belongs in a
|
|
41
|
-
* neutral diagnostics package or should be generalized further (e.g. a
|
|
42
|
-
* caller-supplied list of `{agent, dir}` pairs instead of the four names being
|
|
43
|
-
* baked into the function body). Not resolved here — this is exactly the kind
|
|
44
|
-
* of judgment call flagged for sign-off, not a decision this task should make
|
|
45
|
-
* unilaterally.
|
|
3
|
+
* Host HTTP/desktop diagnostic exports: redaction, log collection, manifest building and ZIPs.
|
|
4
|
+
* Agent-CLI log integrations are optional and caller-parameterized. The AMR slot activates only
|
|
5
|
+
* when its home/data directory is supplied. Whether this named CLI vocabulary should become a
|
|
6
|
+
* generic {agent, dir} list remains an owner decision; it must not change silently during cleanup.
|
|
46
7
|
*/
|
|
47
8
|
export { DIAGNOSTICS_CONTENT_TYPE, DIAGNOSTICS_EXPORT_PATH, DIAGNOSTICS_FILENAME_PREFIX, } from "./contract.js";
|
|
48
9
|
export { redactJsonValue, redactJsonText, redactText, type RedactionOptions, } from "./redaction.js";
|
package/dist/index.js
CHANGED
|
@@ -1,48 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module @jini-ai/diagnostics
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* builder, and a zip packager. See `archived provenance ledger` for full provenance and
|
|
8
|
-
* scope-decision notes (this package is NOT yet in extraction-plan.md's
|
|
9
|
-
* locked §3 package set — see that file for details).
|
|
10
|
-
|
|
11
|
-
* Archived provenance rationale:
|
|
12
|
-
* ## Design decision: `agent-logs.ts` carries real agent-CLI vocabulary, ported anyway
|
|
13
|
-
*
|
|
14
|
-
* `r2-packages.md`'s coupling grade for this package ("LOW... daemon-endpoint
|
|
15
|
-
* comments") was assessed at the whole-package level. Read in isolation,
|
|
16
|
-
* `agent-logs.ts` carries more domain content than the other six files: it
|
|
17
|
-
* hardcodes knowledge of four specific coding-agent CLIs — Claude Code, Codex,
|
|
18
|
-
* OpenCode, and an "AMR"-style OpenCode runtime — including their default
|
|
19
|
-
* config-home directory names (`.claude`, `.codex`, `opencode`) and env-var
|
|
20
|
-
* override names (`CLAUDE_CONFIG_DIR`, `CODEX_HOME`, `OPENCODE_TEST_HOME`,
|
|
21
|
-
* `XDG_DATA_HOME`). "AMR" itself is OD's own internal name for an agent
|
|
22
|
-
* orchestration layer, not a generic term.
|
|
23
|
-
*
|
|
24
|
-
* This was ported anyway, deliberately, not dropped or trimmed, for three
|
|
25
|
-
* reasons: (1) the task brief explicitly lists `agent-logs` as one of the
|
|
26
|
-
* seven modules that make up "diagnostics-bundle tooling" and does not flag it
|
|
27
|
-
* for exclusion the way Target 2's task brief explicitly excluded
|
|
28
|
-
* `project-storage.ts`; (2) every one of these CLI integrations is optional
|
|
29
|
-
* and caller-parameterized (`homeDir`/`claudeConfigDir`/`codexHome`/
|
|
30
|
-
* `amrOpenCodeHome`/`xdgDataHome` are all inputs, not hardcoded paths the
|
|
31
|
-
* function reaches for on its own) — a Jini-based product that drives the same
|
|
32
|
-
* external agent CLIs (Claude Code, Codex, OpenCode are all plausible
|
|
33
|
-
* `@jini/agent-runtime` targets per extraction-plan.md's roadmap) can reuse
|
|
34
|
-
* this verbatim, and one that doesn't simply never calls
|
|
35
|
-
* `buildAgentCliLogSources`; (3) the "AMR" agent slot is additive-only (only
|
|
36
|
-
* appended to `agentDirs` when `amrOpenCodeHome`/`dataDir` is supplied) so a
|
|
37
|
-
* non-OD consumer never sees it activate. Flagged here explicitly rather than
|
|
38
|
-
* silently ported, per this porting session's own standard: a future
|
|
39
|
-
* Coordinator/Software-Architect review of this not-yet-locked package should
|
|
40
|
-
* weigh whether the Claude/Codex/OpenCode/AMR-specific vocabulary belongs in a
|
|
41
|
-
* neutral diagnostics package or should be generalized further (e.g. a
|
|
42
|
-
* caller-supplied list of `{agent, dir}` pairs instead of the four names being
|
|
43
|
-
* baked into the function body). Not resolved here — this is exactly the kind
|
|
44
|
-
* of judgment call flagged for sign-off, not a decision this task should make
|
|
45
|
-
* unilaterally.
|
|
3
|
+
* Host HTTP/desktop diagnostic exports: redaction, log collection, manifest building and ZIPs.
|
|
4
|
+
* Agent-CLI log integrations are optional and caller-parameterized. The AMR slot activates only
|
|
5
|
+
* when its home/data directory is supplied. Whether this named CLI vocabulary should become a
|
|
6
|
+
* generic {agent, dir} list remains an owner decision; it must not change silently during cleanup.
|
|
46
7
|
*/
|
|
47
8
|
export { DIAGNOSTICS_CONTENT_TYPE, DIAGNOSTICS_EXPORT_PATH, DIAGNOSTICS_FILENAME_PREFIX, } from "./contract.js";
|
|
48
9
|
export { redactJsonValue, redactJsonText, redactText, } from "./redaction.js";
|
|
@@ -8,7 +8,8 @@ export interface RequestHookOptions {
|
|
|
8
8
|
/** Adds request correlation and completed-request hooks using explicit ID and clock ports.
|
|
9
9
|
* @param required Clock and request ID generator, scoped by the host.
|
|
10
10
|
* @param options Optional logging, metrics and tracing adapters.
|
|
11
|
-
* @returns Request tracking with exactly one completion event per request
|
|
11
|
+
* @returns Request tracking with exactly one completion event per request; DB, outbound and
|
|
12
|
+
* agent-run signals go straight to the tracing adapter (the no-op without one).
|
|
12
13
|
* @throws Hook errors propagate to the caller; adapters choose their own error policy.
|
|
13
14
|
*/
|
|
14
15
|
export declare function createHookObservabilityPort({ clock, requestIdGenerator }: {
|
|
@@ -1,16 +1,20 @@
|
|
|
1
|
+
import { createNoopObservabilityPort } from './noop.js';
|
|
1
2
|
/** Adds request correlation and completed-request hooks using explicit ID and clock ports.
|
|
2
3
|
* @param required Clock and request ID generator, scoped by the host.
|
|
3
4
|
* @param options Optional logging, metrics and tracing adapters.
|
|
4
|
-
* @returns Request tracking with exactly one completion event per request
|
|
5
|
+
* @returns Request tracking with exactly one completion event per request; DB, outbound and
|
|
6
|
+
* agent-run signals go straight to the tracing adapter (the no-op without one).
|
|
5
7
|
* @throws Hook errors propagate to the caller; adapters choose their own error policy.
|
|
6
8
|
*/
|
|
7
9
|
export function createHookObservabilityPort({ clock, requestIdGenerator }, { logger, metrics, tracing } = {}) {
|
|
8
|
-
|
|
10
|
+
const signals = tracing ?? createNoopObservabilityPort({});
|
|
11
|
+
return {
|
|
12
|
+
trackRequest(input, options = {}) {
|
|
9
13
|
const requestId = options.requestId ?? requestIdGenerator.generate({});
|
|
10
14
|
const startedAt = clock.nowMs();
|
|
11
15
|
const tracker = tracing?.trackRequest(input, { requestId });
|
|
12
16
|
let ended = false;
|
|
13
|
-
return { requestId, end(outcome) {
|
|
17
|
+
return { requestId, run: (fn) => (tracker?.run ? tracker.run(fn) : fn()), end(outcome) {
|
|
14
18
|
if (ended)
|
|
15
19
|
return;
|
|
16
20
|
ended = true;
|
|
@@ -19,6 +23,10 @@ export function createHookObservabilityPort({ clock, requestIdGenerator }, { log
|
|
|
19
23
|
logger?.log(event);
|
|
20
24
|
metrics?.recordRequest(event);
|
|
21
25
|
} };
|
|
22
|
-
}
|
|
26
|
+
},
|
|
27
|
+
trackDbQuery: (input) => signals.trackDbQuery(input),
|
|
28
|
+
trackOutboundCall: (input) => signals.trackOutboundCall(input),
|
|
29
|
+
trackAgentRun: (input, options) => signals.trackAgentRun(input, options),
|
|
30
|
+
};
|
|
23
31
|
}
|
|
24
32
|
//# sourceMappingURL=hooks.js.map
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import type { ObservabilityConfig } from './config.js';
|
|
2
2
|
import type { ExporterFactory, TracerProviderFactory, ObservabilityPort } from './ports.js';
|
|
3
|
+
import { type OtelAdapterOptions } from './otel.js';
|
|
3
4
|
export * from './config.js';
|
|
4
5
|
export * from './ports.js';
|
|
5
6
|
export * from './noop.js';
|
|
6
7
|
export * from './otel.js';
|
|
7
8
|
export * from './hooks.js';
|
|
8
|
-
|
|
9
|
+
export * from './instrumentation.js';
|
|
10
|
+
/** Selects an adapter from explicit config; disabled telemetry never invokes either factory.
|
|
11
|
+
* @param options Adapter options (host span scope); ignored when telemetry is disabled. */
|
|
9
12
|
export declare function createObservabilityPort({ config, exporterFactory, tracerProviderFactory }: {
|
|
10
13
|
config: ObservabilityConfig;
|
|
11
14
|
exporterFactory: ExporterFactory;
|
|
12
15
|
tracerProviderFactory: TracerProviderFactory;
|
|
13
|
-
}): ObservabilityPort;
|
|
16
|
+
}, options?: OtelAdapterOptions): ObservabilityPort;
|
|
14
17
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -5,10 +5,12 @@ export * from './ports.js';
|
|
|
5
5
|
export * from './noop.js';
|
|
6
6
|
export * from './otel.js';
|
|
7
7
|
export * from './hooks.js';
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
export * from './instrumentation.js';
|
|
9
|
+
/** Selects an adapter from explicit config; disabled telemetry never invokes either factory.
|
|
10
|
+
* @param options Adapter options (host span scope); ignored when telemetry is disabled. */
|
|
11
|
+
export function createObservabilityPort({ config, exporterFactory, tracerProviderFactory }, options = {}) {
|
|
10
12
|
if (!config.enabled)
|
|
11
13
|
return createNoopObservabilityPort({});
|
|
12
|
-
return createOtelObservabilityPort({ config, exporterFactory, tracerProviderFactory });
|
|
14
|
+
return createOtelObservabilityPort({ config, exporterFactory, tracerProviderFactory }, options);
|
|
13
15
|
}
|
|
14
16
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { HttpClientPort } from "@jini-ai/core/primitives";
|
|
2
|
+
import type { ObservabilityPort } from './ports.js';
|
|
3
|
+
/**
|
|
4
|
+
* @file Decorators that put a host's existing chokepoints on the observability port: the storage
|
|
5
|
+
* kernel (every repo query, on every dialect) and the guarded HTTP client (every vetted egress call).
|
|
6
|
+
* Both return their input untouched for the no-op port, so a disabled install keeps the exact
|
|
7
|
+
* objects and call paths it had — no wrapper frame, no per-query plugin, no allocation.
|
|
8
|
+
*/
|
|
9
|
+
export interface QueryDescription {
|
|
10
|
+
operation: string;
|
|
11
|
+
table?: string;
|
|
12
|
+
}
|
|
13
|
+
/** Operation and table of one Kysely operation node. Reads node kinds and identifiers only — never
|
|
14
|
+
* parameter values or statement text, so the description is safe to export whatever the query binds.
|
|
15
|
+
* A raw statement contributes its leading keyword alone (`pragma`, `select`), or `raw`. */
|
|
16
|
+
export declare function describeQueryNode({ node }: {
|
|
17
|
+
node: unknown;
|
|
18
|
+
}): QueryDescription;
|
|
19
|
+
/** The kernel surface the decorator replaces; `StorageKernel<DB>` from `@jini-ai/db/kernel` fits it. */
|
|
20
|
+
export interface InstrumentableKernel {
|
|
21
|
+
readonly dialect: string;
|
|
22
|
+
run(fn: (db: any) => unknown): Promise<unknown>;
|
|
23
|
+
transaction(fn: () => Promise<unknown>): Promise<unknown>;
|
|
24
|
+
query(statement: any): Promise<unknown>;
|
|
25
|
+
execute(statement: any): Promise<unknown>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Tracks every kernel `run`/`transaction`/`query`/`execute` as one DB span, decorating the kernel
|
|
29
|
+
* IN PLACE. A replacement object would break identity-keyed lookups hosts already rely on (the
|
|
30
|
+
* SQLite driver's connection reverse cache, kernels cached per connection), and in-place keeps every
|
|
31
|
+
* holder of the same kernel covered. `run` bodies get the builder with a capture plugin, so the span
|
|
32
|
+
* is named from the first query the body builds (operation + table), never its SQL text.
|
|
33
|
+
* @param required The kernel and the port. A no-op port, or a kernel already decorated, is left alone.
|
|
34
|
+
* @returns The same kernel object.
|
|
35
|
+
* @complexity O(1) per call beyond one plugin pass per built query.
|
|
36
|
+
*/
|
|
37
|
+
export declare function instrumentStorageKernel<K extends InstrumentableKernel>({ kernel, observability }: {
|
|
38
|
+
kernel: K;
|
|
39
|
+
observability: ObservabilityPort;
|
|
40
|
+
}): K;
|
|
41
|
+
/** Any `fetch`-shaped function: the global, a timeout wrapper, a SigV4 client's `fetch`. Structural,
|
|
42
|
+
* so this universal entry needs no DOM or undici types. */
|
|
43
|
+
export type FetchLike = (input: any, init?: any) => Promise<{
|
|
44
|
+
status: number;
|
|
45
|
+
}>;
|
|
46
|
+
/** One outbound span per call of a raw `fetch` — the egress paths that do not go through a guarded
|
|
47
|
+
* client (deploy hosts, git hosts, object stores, loopback). Input, init and the response pass through
|
|
48
|
+
* untouched; the span gets scheme/host/port and status only, like {@link trackHttpClient}.
|
|
49
|
+
* @returns `fetch` itself for the no-op port.
|
|
50
|
+
* @complexity O(1) per call. */
|
|
51
|
+
export declare function trackFetch<F extends FetchLike>({ fetch, observability }: {
|
|
52
|
+
fetch: F;
|
|
53
|
+
observability: ObservabilityPort;
|
|
54
|
+
}): F;
|
|
55
|
+
/** One outbound span per `send`, with the response status or the transport failure; the call itself
|
|
56
|
+
* is unchanged. Returns `client` itself for the no-op port. */
|
|
57
|
+
export declare function trackHttpClient({ client, observability }: {
|
|
58
|
+
client: HttpClientPort;
|
|
59
|
+
observability: ObservabilityPort;
|
|
60
|
+
}): HttpClientPort;
|
|
61
|
+
//# sourceMappingURL=instrumentation.d.ts.map
|