@pinta-ai/mcp-logger 0.4.0 → 0.4.2-dev.1010
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 +12 -0
- package/dist/cli/index.js +1 -1
- package/node_modules/@pinta-ai/core/README.md +180 -0
- package/node_modules/@pinta-ai/core/dist/atomic-write.d.ts +9 -0
- package/node_modules/@pinta-ai/core/dist/atomic-write.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/atomic-write.js +20 -0
- package/node_modules/@pinta-ai/core/dist/atomic-write.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/credential-semantics.d.ts +20 -0
- package/node_modules/@pinta-ai/core/dist/credential-semantics.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/credential-semantics.js +156 -0
- package/node_modules/@pinta-ai/core/dist/credential-semantics.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/env-file.d.ts +17 -0
- package/node_modules/@pinta-ai/core/dist/env-file.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/env-file.js +81 -0
- package/node_modules/@pinta-ai/core/dist/env-file.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/export-mask.d.ts +26 -0
- package/node_modules/@pinta-ai/core/dist/export-mask.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/export-mask.js +202 -0
- package/node_modules/@pinta-ai/core/dist/export-mask.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/guard.d.ts +196 -0
- package/node_modules/@pinta-ai/core/dist/guard.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/guard.js +275 -0
- package/node_modules/@pinta-ai/core/dist/guard.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/index.d.ts +23 -0
- package/node_modules/@pinta-ai/core/dist/index.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/index.js +85 -0
- package/node_modules/@pinta-ai/core/dist/index.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/json-text.d.ts +45 -0
- package/node_modules/@pinta-ai/core/dist/json-text.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/json-text.js +116 -0
- package/node_modules/@pinta-ai/core/dist/json-text.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/lifecycle.d.ts +143 -0
- package/node_modules/@pinta-ai/core/dist/lifecycle.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/lifecycle.js +20 -0
- package/node_modules/@pinta-ai/core/dist/lifecycle.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/matches.d.ts +24 -0
- package/node_modules/@pinta-ai/core/dist/matches.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/matches.js +39 -0
- package/node_modules/@pinta-ai/core/dist/matches.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/mysql-password.d.ts +15 -0
- package/node_modules/@pinta-ai/core/dist/mysql-password.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/mysql-password.js +375 -0
- package/node_modules/@pinta-ai/core/dist/mysql-password.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/otlp-types.d.ts +41 -0
- package/node_modules/@pinta-ai/core/dist/otlp-types.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/otlp-types.js +7 -0
- package/node_modules/@pinta-ai/core/dist/otlp-types.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/otlp.d.ts +142 -0
- package/node_modules/@pinta-ai/core/dist/otlp.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/otlp.js +638 -0
- package/node_modules/@pinta-ai/core/dist/otlp.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/output-denial.d.ts +69 -0
- package/node_modules/@pinta-ai/core/dist/output-denial.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/output-denial.js +105 -0
- package/node_modules/@pinta-ai/core/dist/output-denial.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/redact.d.ts +65 -0
- package/node_modules/@pinta-ai/core/dist/redact.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/redact.js +193 -0
- package/node_modules/@pinta-ai/core/dist/redact.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/retry-queue.d.ts +47 -0
- package/node_modules/@pinta-ai/core/dist/retry-queue.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/retry-queue.js +177 -0
- package/node_modules/@pinta-ai/core/dist/retry-queue.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/secret-shapes.d.ts +47 -0
- package/node_modules/@pinta-ai/core/dist/secret-shapes.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/secret-shapes.js +377 -0
- package/node_modules/@pinta-ai/core/dist/secret-shapes.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/session-trace.d.ts +50 -0
- package/node_modules/@pinta-ai/core/dist/session-trace.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/session-trace.js +103 -0
- package/node_modules/@pinta-ai/core/dist/session-trace.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/shape-rules.d.ts +117 -0
- package/node_modules/@pinta-ai/core/dist/shape-rules.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/shape-rules.js +592 -0
- package/node_modules/@pinta-ai/core/dist/shape-rules.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/trace.d.ts +17 -0
- package/node_modules/@pinta-ai/core/dist/trace.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/trace.js +78 -0
- package/node_modules/@pinta-ai/core/dist/trace.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/transport.d.ts +75 -0
- package/node_modules/@pinta-ai/core/dist/transport.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/transport.js +260 -0
- package/node_modules/@pinta-ai/core/dist/transport.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/value-copies.d.ts +46 -0
- package/node_modules/@pinta-ai/core/dist/value-copies.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/value-copies.js +279 -0
- package/node_modules/@pinta-ai/core/dist/value-copies.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/value-masking.d.ts +22 -0
- package/node_modules/@pinta-ai/core/dist/value-masking.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/value-masking.js +243 -0
- package/node_modules/@pinta-ai/core/dist/value-masking.js.map +1 -0
- package/node_modules/@pinta-ai/core/package.json +50 -0
- package/package.json +3 -1
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.TraceManager = void 0;
|
|
7
|
+
exports.generateUlid = generateUlid;
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
11
|
+
const atomic_write_js_1 = require("./atomic-write.js");
|
|
12
|
+
const CROCKFORD = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
13
|
+
/** Generate a 26-char Crockford ULID (48-bit ms timestamp + 80-bit randomness). */
|
|
14
|
+
function generateUlid() {
|
|
15
|
+
const now = Date.now();
|
|
16
|
+
// 10 chars timestamp (48-bit ms)
|
|
17
|
+
let ts = "";
|
|
18
|
+
let t = now;
|
|
19
|
+
for (let i = 0; i < 10; i++) {
|
|
20
|
+
ts = CROCKFORD[t & 31] + ts;
|
|
21
|
+
t = Math.floor(t / 32);
|
|
22
|
+
}
|
|
23
|
+
// 16 chars randomness (80-bit)
|
|
24
|
+
const rand = crypto_1.default.randomBytes(10);
|
|
25
|
+
let r = "";
|
|
26
|
+
for (let i = 0; i < 10; i++) {
|
|
27
|
+
r += CROCKFORD[rand[i] & 31];
|
|
28
|
+
}
|
|
29
|
+
// pad to 16 chars
|
|
30
|
+
while (r.length < 16)
|
|
31
|
+
r += CROCKFORD[0];
|
|
32
|
+
return ts + r;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Persists the current trace id to a JSON file so successive short-lived hook
|
|
36
|
+
* processes share one trace per session. `tracePath` is adapter-specific
|
|
37
|
+
* (derived from the adapter's plugin-data dir).
|
|
38
|
+
*/
|
|
39
|
+
class TraceManager {
|
|
40
|
+
tracePath;
|
|
41
|
+
constructor(tracePath) {
|
|
42
|
+
this.tracePath = tracePath;
|
|
43
|
+
}
|
|
44
|
+
/** Generate and persist a fresh trace id (e.g. on UserPromptSubmit). */
|
|
45
|
+
newTrace() {
|
|
46
|
+
const traceId = generateUlid();
|
|
47
|
+
this.save(traceId);
|
|
48
|
+
return traceId;
|
|
49
|
+
}
|
|
50
|
+
/** Return the current trace id, generating one if no trace file exists. */
|
|
51
|
+
currentTrace() {
|
|
52
|
+
try {
|
|
53
|
+
const data = fs_1.default.readFileSync(this.tracePath, "utf-8");
|
|
54
|
+
const { traceId } = JSON.parse(data);
|
|
55
|
+
if (traceId)
|
|
56
|
+
return traceId;
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
// no trace file yet
|
|
60
|
+
}
|
|
61
|
+
return this.newTrace();
|
|
62
|
+
}
|
|
63
|
+
save(traceId) {
|
|
64
|
+
// Best-effort persistence: ENOSPC/EACCES/read-only home must never throw out
|
|
65
|
+
// of the public currentTrace()/newTrace() and kill a host hook. The span is
|
|
66
|
+
// still built with the returned traceId; only cross-process persistence is
|
|
67
|
+
// lost. Matches DiskSessionTraceManager.write()'s swallow-on-failure contract.
|
|
68
|
+
try {
|
|
69
|
+
fs_1.default.mkdirSync(path_1.default.dirname(this.tracePath), { recursive: true });
|
|
70
|
+
(0, atomic_write_js_1.atomicWriteFileSync)(this.tracePath, JSON.stringify({ traceId }));
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
process.stderr.write(`[pinta-core] trace persistence failed: ${err}\n`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.TraceManager = TraceManager;
|
|
78
|
+
//# sourceMappingURL=trace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace.js","sourceRoot":"","sources":["../src/trace.ts"],"names":[],"mappings":";;;;;;AAQA,oCAkBC;AA1BD,4CAAoB;AACpB,gDAAwB;AACxB,oDAA4B;AAC5B,uDAAwD;AAExD,MAAM,SAAS,GAAG,kCAAkC,CAAC;AAErD,mFAAmF;AACnF,SAAgB,YAAY;IAC1B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACvB,iCAAiC;IACjC,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,IAAI,CAAC,GAAG,GAAG,CAAC;IACZ,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5B,EAAE,GAAG,SAAS,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC;QAC5B,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;IACzB,CAAC;IACD,+BAA+B;IAC/B,MAAM,IAAI,GAAG,gBAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;IACpC,IAAI,CAAC,GAAG,EAAE,CAAC;IACX,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5B,CAAC,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;IAC/B,CAAC;IACD,kBAAkB;IAClB,OAAO,CAAC,CAAC,MAAM,GAAG,EAAE;QAAE,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC;IACxC,OAAO,EAAE,GAAG,CAAC,CAAC;AAChB,CAAC;AAED;;;;GAIG;AACH,MAAa,YAAY;IACf,SA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4
|
+
*
|
|
5
|
+
* Mirrors the manager's per-entry relay budget (pinta-manager
|
|
6
|
+
* `sidecar/src/relay/split.ts` `MAX_ENTRY_BYTES`): aware-backend caps
|
|
7
|
+
* `POST /traces` at 1,000,000 B (one Firehose `PutRecord`, whose 1,024,000 B
|
|
8
|
+
* limit is a hard AWS ceiling), so 900 KiB leaves headroom for header
|
|
9
|
+
* overhead and re-serialization drift. A request over this budget is not
|
|
10
|
+
* retryable — the backend rejects it permanently — so the transports never
|
|
11
|
+
* emit one: `flush()` chunks the backlog on payload boundaries, and a single
|
|
12
|
+
* payload that alone exceeds the budget is dropped with a diagnostic.
|
|
13
|
+
*/
|
|
14
|
+
export declare const MAX_POST_BYTES: number;
|
|
15
|
+
export interface OtlpTransportOptions {
|
|
16
|
+
/** Full traces URL — no path is appended by the transport. */
|
|
17
|
+
endpoint: string;
|
|
18
|
+
headers: Record<string, string>;
|
|
19
|
+
}
|
|
20
|
+
/** Resolver returning the active OTLP options, or null to silently disable. */
|
|
21
|
+
export type OptionsResolver = () => OtlpTransportOptions | null;
|
|
22
|
+
export declare function parseHeadersEnv(raw: string | Record<string, string> | undefined): Record<string, string>;
|
|
23
|
+
/**
|
|
24
|
+
* Default resolver reading the standard OTEL_EXPORTER_OTLP_* env vars.
|
|
25
|
+
* TRACES_ENDPOINT is treated as a full URL; ENDPOINT is a base URL the
|
|
26
|
+
* transport appends `/v1/traces` to.
|
|
27
|
+
*/
|
|
28
|
+
export declare function envOptionsResolver(): OtlpTransportOptions | null;
|
|
29
|
+
/**
|
|
30
|
+
* POST a payload to the OTLP endpoint. Returns true on 2xx, false on any
|
|
31
|
+
* failure (with a diagnostic written to stderr). Never throws.
|
|
32
|
+
*/
|
|
33
|
+
export declare function postOtlp(payload: OtlpPayload, opts: OtlpTransportOptions, logPrefix: string): Promise<boolean>;
|
|
34
|
+
/**
|
|
35
|
+
* Disk-backed transport for short-lived hook adapters (cc/codex/copilot/gemini).
|
|
36
|
+
* On send failure the payload is persisted; a later hook's `flush()` drains it
|
|
37
|
+
* under a file lock.
|
|
38
|
+
*/
|
|
39
|
+
export declare class DiskTransport {
|
|
40
|
+
private queue;
|
|
41
|
+
private logPrefix;
|
|
42
|
+
private resolveOptions;
|
|
43
|
+
constructor(opts: {
|
|
44
|
+
pluginData: string;
|
|
45
|
+
logPrefix: string;
|
|
46
|
+
resolveOptions?: OptionsResolver;
|
|
47
|
+
});
|
|
48
|
+
send(payload: OtlpPayload): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Drain the backlog in POST-budget-sized chunks. On a mid-flush failure the
|
|
51
|
+
* unsent tail stays queued for the next flush — earlier chunks that already
|
|
52
|
+
* landed are not re-sent (at-most-once per flush attempt, unchanged from the
|
|
53
|
+
* pre-chunking behavior where the whole batch either landed or stayed).
|
|
54
|
+
*/
|
|
55
|
+
flush(): Promise<void>;
|
|
56
|
+
/** True (and logged) when the payload alone exceeds the POST budget. */
|
|
57
|
+
private dropIfOversized;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* In-memory transport for the long-lived opencode plugin. Failed payloads are
|
|
61
|
+
* buffered in memory and re-sent (batched) on the next flush.
|
|
62
|
+
*/
|
|
63
|
+
export declare class MemoryTransport {
|
|
64
|
+
private queue;
|
|
65
|
+
private logPrefix;
|
|
66
|
+
private resolveOptions;
|
|
67
|
+
constructor(opts: {
|
|
68
|
+
logPrefix: string;
|
|
69
|
+
resolveOptions: OptionsResolver;
|
|
70
|
+
});
|
|
71
|
+
send(payload: OtlpPayload): Promise<void>;
|
|
72
|
+
/** Chunked drain — see DiskTransport.flush; the unsent tail is re-buffered. */
|
|
73
|
+
flush(): Promise<void>;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB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AAS,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,eAAe,CAAA;KAAE;IAKlE,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAa/C,+EAA+E;IACzE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAoB7B"}
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MemoryTransport = exports.DiskTransport = exports.MAX_POST_BYTES = void 0;
|
|
4
|
+
exports.parseHeadersEnv = parseHeadersEnv;
|
|
5
|
+
exports.envOptionsResolver = envOptionsResolver;
|
|
6
|
+
exports.postOtlp = postOtlp;
|
|
7
|
+
const retry_queue_js_1 = require("./retry-queue.js");
|
|
8
|
+
const otlp_js_1 = require("./otlp.js");
|
|
9
|
+
const TIMEOUT_MS = 5000;
|
|
10
|
+
/**
|
|
11
|
+
* Max serialized bytes of a single OTLP POST body.
|
|
12
|
+
*
|
|
13
|
+
* Mirrors the manager's per-entry relay budget (pinta-manager
|
|
14
|
+
* `sidecar/src/relay/split.ts` `MAX_ENTRY_BYTES`): aware-backend caps
|
|
15
|
+
* `POST /traces` at 1,000,000 B (one Firehose `PutRecord`, whose 1,024,000 B
|
|
16
|
+
* limit is a hard AWS ceiling), so 900 KiB leaves headroom for header
|
|
17
|
+
* overhead and re-serialization drift. A request over this budget is not
|
|
18
|
+
* retryable — the backend rejects it permanently — so the transports never
|
|
19
|
+
* emit one: `flush()` chunks the backlog on payload boundaries, and a single
|
|
20
|
+
* payload that alone exceeds the budget is dropped with a diagnostic.
|
|
21
|
+
*/
|
|
22
|
+
exports.MAX_POST_BYTES = 900 * 1024;
|
|
23
|
+
function payloadBytes(payload) {
|
|
24
|
+
const json = JSON.stringify(payload);
|
|
25
|
+
return json === undefined ? 0 : Buffer.byteLength(json, "utf-8");
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Greedily pack items into chunks whose summed serialized size stays within
|
|
29
|
+
* `maxBytes`. Chunks are packed as FULL as possible (not one item each):
|
|
30
|
+
* the backend bills per Firehose record rounded up, so many small requests
|
|
31
|
+
* cost strictly more than few large ones. Summing member sizes overestimates
|
|
32
|
+
* the merged body slightly (each member's own envelope is counted), which
|
|
33
|
+
* only adds safety margin.
|
|
34
|
+
*/
|
|
35
|
+
function chunkByBytes(items, sizeOf, maxBytes) {
|
|
36
|
+
const chunks = [];
|
|
37
|
+
const oversize = [];
|
|
38
|
+
let current = [];
|
|
39
|
+
let currentBytes = 0;
|
|
40
|
+
for (const item of items) {
|
|
41
|
+
const bytes = sizeOf(item);
|
|
42
|
+
if (bytes > maxBytes) {
|
|
43
|
+
oversize.push(item);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (current.length > 0 && currentBytes + bytes > maxBytes) {
|
|
47
|
+
chunks.push(current);
|
|
48
|
+
current = [];
|
|
49
|
+
currentBytes = 0;
|
|
50
|
+
}
|
|
51
|
+
current.push(item);
|
|
52
|
+
currentBytes += bytes;
|
|
53
|
+
}
|
|
54
|
+
if (current.length > 0)
|
|
55
|
+
chunks.push(current);
|
|
56
|
+
return { chunks, oversize };
|
|
57
|
+
}
|
|
58
|
+
function parseHeadersEnv(raw) {
|
|
59
|
+
if (!raw)
|
|
60
|
+
return {};
|
|
61
|
+
// Already-parsed map (e.g. plugin options) → shallow-copy passthrough.
|
|
62
|
+
if (typeof raw === "object")
|
|
63
|
+
return { ...raw };
|
|
64
|
+
const out = {};
|
|
65
|
+
for (const pair of raw.split(",")) {
|
|
66
|
+
const [k, ...rest] = pair.split("=");
|
|
67
|
+
if (k && rest.length > 0)
|
|
68
|
+
out[k.trim()] = rest.join("=").trim();
|
|
69
|
+
}
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Default resolver reading the standard OTEL_EXPORTER_OTLP_* env vars.
|
|
74
|
+
* TRACES_ENDPOINT is treated as a full URL; ENDPOINT is a base URL the
|
|
75
|
+
* transport appends `/v1/traces` to.
|
|
76
|
+
*/
|
|
77
|
+
function envOptionsResolver() {
|
|
78
|
+
const tracesEndpoint = process.env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT;
|
|
79
|
+
const baseEndpoint = process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
|
|
80
|
+
let endpoint;
|
|
81
|
+
if (tracesEndpoint) {
|
|
82
|
+
endpoint = tracesEndpoint.replace(/\/+$/, "");
|
|
83
|
+
}
|
|
84
|
+
else if (baseEndpoint) {
|
|
85
|
+
endpoint = baseEndpoint.replace(/\/+$/, "") + "/v1/traces";
|
|
86
|
+
}
|
|
87
|
+
if (!endpoint)
|
|
88
|
+
return null;
|
|
89
|
+
return {
|
|
90
|
+
endpoint,
|
|
91
|
+
headers: parseHeadersEnv(process.env.OTEL_EXPORTER_OTLP_HEADERS),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* POST a payload to the OTLP endpoint. Returns true on 2xx, false on any
|
|
96
|
+
* failure (with a diagnostic written to stderr). Never throws.
|
|
97
|
+
*/
|
|
98
|
+
async function postOtlp(payload, opts, logPrefix) {
|
|
99
|
+
const ctrl = new AbortController();
|
|
100
|
+
const timer = setTimeout(() => ctrl.abort(), TIMEOUT_MS);
|
|
101
|
+
try {
|
|
102
|
+
const res = await fetch(opts.endpoint, {
|
|
103
|
+
method: "POST",
|
|
104
|
+
headers: { "Content-Type": "application/json", ...opts.headers },
|
|
105
|
+
body: JSON.stringify(payload),
|
|
106
|
+
signal: ctrl.signal,
|
|
107
|
+
});
|
|
108
|
+
if (!res.ok) {
|
|
109
|
+
let body = "";
|
|
110
|
+
try {
|
|
111
|
+
body = (await res.text()).slice(0, 200);
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
/* ignore */
|
|
115
|
+
}
|
|
116
|
+
const hint = res.status === 401 || res.status === 403
|
|
117
|
+
? " — check OTEL_EXPORTER_OTLP_HEADERS (relay token)"
|
|
118
|
+
: res.status === 404
|
|
119
|
+
? " — check OTEL_EXPORTER_OTLP_TRACES_ENDPOINT path"
|
|
120
|
+
: res.status >= 500
|
|
121
|
+
? " — collector may be down"
|
|
122
|
+
: "";
|
|
123
|
+
process.stderr.write(`[${logPrefix}] OTLP POST ${res.status} ${opts.endpoint}${hint}${body ? ` body=${body}` : ""}\n`);
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
catch (err) {
|
|
129
|
+
process.stderr.write(`[${logPrefix}] OTLP POST failed: ${err.message ?? String(err)}\n`);
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
finally {
|
|
133
|
+
clearTimeout(timer);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Disk-backed transport for short-lived hook adapters (cc/codex/copilot/gemini).
|
|
138
|
+
* On send failure the payload is persisted; a later hook's `flush()` drains it
|
|
139
|
+
* under a file lock.
|
|
140
|
+
*/
|
|
141
|
+
class DiskTransport {
|
|
142
|
+
queue;
|
|
143
|
+
logPrefix;
|
|
144
|
+
resolveOptions;
|
|
145
|
+
constructor(opts) {
|
|
146
|
+
this.queue = new retry_queue_js_1.DiskRetryQueue(opts.pluginData, opts.logPrefix);
|
|
147
|
+
this.logPrefix = opts.logPrefix;
|
|
148
|
+
this.resolveOptions = opts.resolveOptions ?? envOptionsResolver;
|
|
149
|
+
}
|
|
150
|
+
async send(payload) {
|
|
151
|
+
const opts = this.resolveOptions();
|
|
152
|
+
if (!opts)
|
|
153
|
+
return; // silent disable when no endpoint configured
|
|
154
|
+
if (this.dropIfOversized(payload))
|
|
155
|
+
return;
|
|
156
|
+
const ok = await postOtlp(payload, opts, this.logPrefix);
|
|
157
|
+
if (!ok)
|
|
158
|
+
this.queue.enqueue(payload);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Drain the backlog in POST-budget-sized chunks. On a mid-flush failure the
|
|
162
|
+
* unsent tail stays queued for the next flush — earlier chunks that already
|
|
163
|
+
* landed are not re-sent (at-most-once per flush attempt, unchanged from the
|
|
164
|
+
* pre-chunking behavior where the whole batch either landed or stayed).
|
|
165
|
+
*/
|
|
166
|
+
async flush() {
|
|
167
|
+
const opts = this.resolveOptions();
|
|
168
|
+
if (!opts)
|
|
169
|
+
return;
|
|
170
|
+
if (!this.queue.tryAcquireLock())
|
|
171
|
+
return;
|
|
172
|
+
try {
|
|
173
|
+
const entries = this.queue.readAll();
|
|
174
|
+
if (entries.length === 0)
|
|
175
|
+
return;
|
|
176
|
+
const { chunks, oversize } = chunkByBytes(entries, (e) => payloadBytes(e.payload), exports.MAX_POST_BYTES);
|
|
177
|
+
if (oversize.length > 0) {
|
|
178
|
+
process.stderr.write(`[${this.logPrefix}] dropping ${oversize.length} oversized retry ${oversize.length === 1 ? "entry" : "entries"} (each > ${exports.MAX_POST_BYTES} bytes — the backend caps the request body, so they can never be delivered)\n`);
|
|
179
|
+
}
|
|
180
|
+
const ordered = [].concat(...chunks);
|
|
181
|
+
let sent = 0;
|
|
182
|
+
for (const chunk of chunks) {
|
|
183
|
+
const ok = await postOtlp((0, otlp_js_1.mergeBatch)(chunk.map((e) => e.payload)), opts, this.logPrefix);
|
|
184
|
+
if (!ok)
|
|
185
|
+
break;
|
|
186
|
+
sent += chunk.length;
|
|
187
|
+
}
|
|
188
|
+
this.queue.rewrite(ordered.slice(sent));
|
|
189
|
+
}
|
|
190
|
+
catch (err) {
|
|
191
|
+
// Belt-and-suspenders: flush() is called as `void transport.flush()` by
|
|
192
|
+
// short-lived adapters, so an unforeseen throw would surface as an
|
|
193
|
+
// unhandled rejection. Honor the "never throws" contract and degrade to
|
|
194
|
+
// a no-op — the queue is left intact for a later flush to retry.
|
|
195
|
+
process.stderr.write(`[${this.logPrefix}] flush failed: ${err?.message ?? String(err)}\n`);
|
|
196
|
+
}
|
|
197
|
+
finally {
|
|
198
|
+
this.queue.release();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
/** True (and logged) when the payload alone exceeds the POST budget. */
|
|
202
|
+
dropIfOversized(payload) {
|
|
203
|
+
const bytes = payloadBytes(payload);
|
|
204
|
+
if (bytes <= exports.MAX_POST_BYTES)
|
|
205
|
+
return false;
|
|
206
|
+
process.stderr.write(`[${this.logPrefix}] dropping oversized span payload (${bytes} > ${exports.MAX_POST_BYTES} bytes) — undeliverable, not queued\n`);
|
|
207
|
+
return true;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
exports.DiskTransport = DiskTransport;
|
|
211
|
+
/**
|
|
212
|
+
* In-memory transport for the long-lived opencode plugin. Failed payloads are
|
|
213
|
+
* buffered in memory and re-sent (batched) on the next flush.
|
|
214
|
+
*/
|
|
215
|
+
class MemoryTransport {
|
|
216
|
+
queue = new retry_queue_js_1.MemoryRetryQueue();
|
|
217
|
+
logPrefix;
|
|
218
|
+
resolveOptions;
|
|
219
|
+
constructor(opts) {
|
|
220
|
+
this.logPrefix = opts.logPrefix;
|
|
221
|
+
this.resolveOptions = opts.resolveOptions;
|
|
222
|
+
}
|
|
223
|
+
async send(payload) {
|
|
224
|
+
const opts = this.resolveOptions();
|
|
225
|
+
if (!opts)
|
|
226
|
+
return;
|
|
227
|
+
if (payloadBytes(payload) > exports.MAX_POST_BYTES) {
|
|
228
|
+
process.stderr.write(`[${this.logPrefix}] dropping oversized span payload (> ${exports.MAX_POST_BYTES} bytes) — undeliverable, not buffered\n`);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
const ok = await postOtlp(payload, opts, this.logPrefix);
|
|
232
|
+
if (!ok)
|
|
233
|
+
this.queue.enqueue(payload);
|
|
234
|
+
}
|
|
235
|
+
/** Chunked drain — see DiskTransport.flush; the unsent tail is re-buffered. */
|
|
236
|
+
async flush() {
|
|
237
|
+
const opts = this.resolveOptions();
|
|
238
|
+
if (!opts)
|
|
239
|
+
return;
|
|
240
|
+
const buffered = this.queue.drain();
|
|
241
|
+
if (buffered.length === 0)
|
|
242
|
+
return;
|
|
243
|
+
const { chunks, oversize } = chunkByBytes(buffered, payloadBytes, exports.MAX_POST_BYTES);
|
|
244
|
+
if (oversize.length > 0) {
|
|
245
|
+
process.stderr.write(`[${this.logPrefix}] dropping ${oversize.length} oversized buffered ${oversize.length === 1 ? "payload" : "payloads"} (each > ${exports.MAX_POST_BYTES} bytes — undeliverable)\n`);
|
|
246
|
+
}
|
|
247
|
+
const ordered = [].concat(...chunks);
|
|
248
|
+
let sent = 0;
|
|
249
|
+
for (const chunk of chunks) {
|
|
250
|
+
const ok = await postOtlp((0, otlp_js_1.mergeBatch)(chunk), opts, this.logPrefix);
|
|
251
|
+
if (!ok)
|
|
252
|
+
break;
|
|
253
|
+
sent += chunk.length;
|
|
254
|
+
}
|
|
255
|
+
for (const p of ordered.slice(sent))
|
|
256
|
+
this.queue.enqueue(p); // re-buffer on failure
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
exports.MemoryTransport = MemoryTransport;
|
|
260
|
+
//# sourceMappingURL=transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":";;;AAwEA,0CAYC;AAOD,gDAcC;AAMD,4BA2CC;AA1JD,qDAAqF;AACrF,uCAAuC;AAGvC,MAAM,UAAU,GAAG,IAAI,CAAC;AAExB;;;;;;;;;;;GAWG;AACU,QAAA,cAAc,GAAG,GAAG,GAAG,IAAI,CAAC;AAEzC,SAAS,YAAY,CAAC,OAAoB;IACxC,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACrC,OAAO,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AACnE,CAAC;AASD;;;;;;;GAOG;AACH,SAAS,YAAY,CAAI,KAAU,EAAE,M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,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,YAAY,CAAC,QAAQ,EAAE,YAAY,EAAE,sBAAc,CAAC,CAAC;QAClF,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACxB,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,IAAI,IAAI,CAAC,SAAS,cAAc,QAAQ,CAAC,MAAM,uBAAuB,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,YAAY,sBAAc,2BAA2B,CAC1K,CAAC;QACJ,CAAC;QACD,MAAM,OAAO,GAAmB,EAAoB,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC;QACvE,IAAI,IAAI,GAAG,CAAC,CAAC;QACb,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,MAAM,EAAE,GAAG,MAAM,QAAQ,CAAC,IAAA,oBAAU,EAAC,KAAK,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;YACnE,IAAI,CAAC,EAAE;gBAAE,MAAM;YACf,IAAI,IAAI,KAAK,CAAC,MAAM,CAAC;QACvB,CAAC;QACD,KAAK,MAAM,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC;YAAE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,uBAAuB;IACrF,CAAC;CACF;AA5CD,0CA4CC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Literal copies of values that were already detected (never an entropy
|
|
3
|
+
* detector), in two forms (PTA-735):
|
|
4
|
+
*
|
|
5
|
+
* - `createDetectedValueMasker` returns the masked text, as `pinta-core` has
|
|
6
|
+
* always done. The guard sees the span built with it, so it is the same
|
|
7
|
+
* string main produced: a JSON text is read token by token and a token that
|
|
8
|
+
* changed is written again (`JSON.stringify`).
|
|
9
|
+
* - `createCopyEditor` returns the ranges of the text as written. The span that
|
|
10
|
+
* is stored is the original text with only those ranges replaced, so a
|
|
11
|
+
* value found in a decoded JSON string changes that value and nothing else.
|
|
12
|
+
*
|
|
13
|
+
* Both look for a value with one pass over the text, however many values there
|
|
14
|
+
* are (the time does not grow with the number of distinct values).
|
|
15
|
+
*/
|
|
16
|
+
import { type DetectedValue, type Match } from "./matches.js";
|
|
17
|
+
export interface DetectedValueMaskerOptions {
|
|
18
|
+
/** JSON member names left as written (see `STRUCTURAL_JSON_KEYS` in `redact.ts`). */
|
|
19
|
+
keepJsonKeys?: ReadonlySet<string>;
|
|
20
|
+
}
|
|
21
|
+
/** Literal copies of already-detected values, never an entropy detector. */
|
|
22
|
+
export declare function createDetectedValueMasker(values: readonly DetectedValue[], options?: DetectedValueMaskerOptions): (input: string) => string;
|
|
23
|
+
/** A value to look for as a copy. `site` says to check the place of each copy before replacing it. */
|
|
24
|
+
export interface CopyEntry extends DetectedValue {
|
|
25
|
+
site?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface CopyEditorOptions {
|
|
28
|
+
/** JSON member names left as written. */
|
|
29
|
+
keepJsonKeys?: ReadonlySet<string>;
|
|
30
|
+
}
|
|
31
|
+
/** What the editor found: the ranges to replace (in the text it was given) and the values behind them. */
|
|
32
|
+
export interface CopyEdits {
|
|
33
|
+
edits: Match[];
|
|
34
|
+
/** The distinct values that have a range in this text. */
|
|
35
|
+
found: Set<string>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The ranges of a text where a copy of one of `values` stands, as the text is
|
|
39
|
+
* written. A JSON text is read by its strings, decoded, so the same copies are
|
|
40
|
+
* found as `createDetectedValueMasker` finds; a copy inside a string maps back
|
|
41
|
+
* to the exact characters of the source, so a range is never part of an
|
|
42
|
+
* escape. A value marked `site` is replaced only where its place passes
|
|
43
|
+
* ①-④ (design contract 4 ⑤).
|
|
44
|
+
*/
|
|
45
|
+
export declare function createCopyEditor(values: readonly CopyEntry[], options?: CopyEditorOptions): (input: string, command?: boolean) => CopyEdits;
|
|
46
|
+
//# sourceMappingURL=value-copies.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"value-copies.d.ts","sourceRoot":"","sources":["../src/value-copies.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAiC,KAAK,aAAa,EAAE,KAAK,KAAK,EAAE,MAAM,cAAc,CAAC;AA4G7F,MAAM,WAAW,0BAA0B;IACzC,qFAAqF;IACrF,YAAY,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CACpC;AASD,4EAA4E;AAC5E,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,SAAS,aAAa,EAAE,EAChC,OAAO,GAAE,0BAA+B,GACvC,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAoC3B;AAED,sGAAsG;AACtG,MAAM,WAAW,SAAU,SAAQ,aAAa;IAC9C,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAKD,MAAM,WAAW,iBAAiB;IAChC,yCAAyC;IACzC,YAAY,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CACpC;AAED,0GAA0G;AAC1G,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,KAAK,EAAE,CAAC;IACf,0DAA0D;IAC1D,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CACpB;AAcD;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,SAAS,SAAS,EAAE,EAC5B,OAAO,GAAE,iBAAsB,GAC9B,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,KAAK,SAAS,CAwEjD"}
|