fullcourtdefense-cli 1.26.2 → 1.26.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/dist/commands/hook.js +14 -1
- package/dist/commands/mcpGateway.js +10 -0
- package/dist/telemetry.d.ts +37 -0
- package/dist/telemetry.js +47 -0
- package/dist/verdictIpc.d.ts +9 -1
- package/dist/verdictIpc.js +11 -6
- package/dist/version.json +1 -1
- package/package.json +1 -1
package/dist/commands/hook.js
CHANGED
|
@@ -684,6 +684,13 @@ async function evaluateHookRequest(args, stdinRaw, config) {
|
|
|
684
684
|
* through respond() inside and never reach this catch.
|
|
685
685
|
*/
|
|
686
686
|
async function hookCommand(args, config) {
|
|
687
|
+
// Start of the developer's wait. Taken once here and carried (in-memory) so
|
|
688
|
+
// every event this hook spools reports real latency, and the daemon can
|
|
689
|
+
// report the FULL wait rather than just its own slice. No probe, no timer.
|
|
690
|
+
const startedAt = Date.now();
|
|
691
|
+
return (0, telemetry_1.markVerdictTiming)({ startedAt, path: 'local' }, () => hookCommandOuter(args, config, startedAt));
|
|
692
|
+
}
|
|
693
|
+
async function hookCommandOuter(args, config, startedAt) {
|
|
687
694
|
try {
|
|
688
695
|
let raw = '';
|
|
689
696
|
let stdinErr = '';
|
|
@@ -700,7 +707,7 @@ async function hookCommand(args, config) {
|
|
|
700
707
|
// the full local evaluation below, so the daemon can never make a hook
|
|
701
708
|
// slower than it was before this feature. FCD_VERDICT_IPC=off opts out.
|
|
702
709
|
if (process.env.FCD_VERDICT_IPC !== 'off') {
|
|
703
|
-
const ipc = await (0, verdictIpc_1.requestDaemonVerdict)(args, raw);
|
|
710
|
+
const ipc = await (0, verdictIpc_1.requestDaemonVerdict)(args, raw, undefined, startedAt);
|
|
704
711
|
if (ipc.outcome === 'verdict') {
|
|
705
712
|
dbg({ phase: 'ipc_verdict', event: args.event, exitCode: ipc.exitCode });
|
|
706
713
|
if (ipc.stderr) {
|
|
@@ -744,6 +751,12 @@ async function hookCommand(args, config) {
|
|
|
744
751
|
*/
|
|
745
752
|
function failOpenOutcome(event, message) {
|
|
746
753
|
const toolName = event || 'unknown';
|
|
754
|
+
// Label the spooled event below as a crash-allow: a rising fail_open rate is
|
|
755
|
+
// the fleet's earliest signal that the guard itself is broken on a machine.
|
|
756
|
+
try {
|
|
757
|
+
(0, telemetry_1.setVerdictPath)('fail_open');
|
|
758
|
+
}
|
|
759
|
+
catch { /* never throw */ }
|
|
747
760
|
let suspended = false;
|
|
748
761
|
try {
|
|
749
762
|
suspended = (0, runtimeConfig_1.isSuspendedByCache)();
|
|
@@ -878,6 +878,13 @@ class McpGatewayServer {
|
|
|
878
878
|
(0, telemetry_1.triggerFlush)(decision === 'block');
|
|
879
879
|
}
|
|
880
880
|
async handleToolCall(params) {
|
|
881
|
+
// Passive perf stamp for every event this call spools: how long the agent
|
|
882
|
+
// waited for OUR decision (path 'gateway'). Pure in-memory context — no
|
|
883
|
+
// probe, no I/O; the clock is restarted after the downstream call so the
|
|
884
|
+
// tool's own runtime is never billed to FullCourtDefense.
|
|
885
|
+
return (0, telemetry_1.markVerdictTiming)({ startedAt: Date.now(), path: 'gateway' }, () => this.handleToolCallInner(params));
|
|
886
|
+
}
|
|
887
|
+
async handleToolCallInner(params) {
|
|
881
888
|
await this.ensureDownstream();
|
|
882
889
|
const toolName = String(params.name || '');
|
|
883
890
|
if (!toolName)
|
|
@@ -1248,6 +1255,9 @@ class McpGatewayServer {
|
|
|
1248
1255
|
let rawResult = await this.downstream.callTool(toolName, toolArgs);
|
|
1249
1256
|
downstreamRan = true;
|
|
1250
1257
|
downstreamResult = rawResult;
|
|
1258
|
+
// Response-side events must measure our scanning overhead, not the
|
|
1259
|
+
// tool's execution time (see restartVerdictTiming).
|
|
1260
|
+
(0, telemetry_1.restartVerdictTiming)();
|
|
1251
1261
|
const responseOutcome = (0, deterministicGuard_1.resolveDeterministicTextResponse)(contentToText(rawResult), (0, localSafetySnapshot_1.snapshotToScanOptions)(snapshot));
|
|
1252
1262
|
for (const warning of responseOutcome.warnings) {
|
|
1253
1263
|
this.spoolLocalFinding(warning, toolName, operation, 'warn');
|
package/dist/telemetry.d.ts
CHANGED
|
@@ -16,8 +16,44 @@ export interface SpoolEvent {
|
|
|
16
16
|
policyHash?: string;
|
|
17
17
|
/** True when this decision was enforced locally while the backend was unreachable. */
|
|
18
18
|
offlineEnforced?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Wall time the developer actually waited for this verdict, in ms — measured
|
|
21
|
+
* from the moment the hook process started to the moment the decision was
|
|
22
|
+
* spooled. Passive: computed from timestamps already taken on the hot path
|
|
23
|
+
* (see markVerdictTiming), never an extra probe, timer, or process.
|
|
24
|
+
*/
|
|
25
|
+
latencyMs?: number;
|
|
26
|
+
/** Which path produced the verdict (see VerdictPath). */
|
|
27
|
+
verdictPath?: VerdictPath;
|
|
19
28
|
occurredAt: string;
|
|
20
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* How a verdict was produced — the difference between a healthy machine and a
|
|
32
|
+
* degraded one:
|
|
33
|
+
* - `ipc` resident daemon answered the thin client (the fast path)
|
|
34
|
+
* - `local` full local evaluation in the hook process (daemon down/busy)
|
|
35
|
+
* - `gateway` resident MCP gateway decided in-process (its own fast path)
|
|
36
|
+
* - `fail_open` the hook crashed and allowed by contract
|
|
37
|
+
*/
|
|
38
|
+
export type VerdictPath = 'ipc' | 'local' | 'fail_open' | 'gateway';
|
|
39
|
+
interface VerdictTiming {
|
|
40
|
+
startedAt: number;
|
|
41
|
+
path: VerdictPath;
|
|
42
|
+
}
|
|
43
|
+
/** Run one hook evaluation with timing attached to everything it spools. */
|
|
44
|
+
export declare function markVerdictTiming<T>(timing: VerdictTiming, fn: () => T): T;
|
|
45
|
+
/**
|
|
46
|
+
* Re-label the current evaluation (e.g. it ended in the fail-open handler).
|
|
47
|
+
* Keeps the original start time so latency still covers the full wait.
|
|
48
|
+
*/
|
|
49
|
+
export declare function setVerdictPath(path: VerdictPath): void;
|
|
50
|
+
/**
|
|
51
|
+
* Restart the current evaluation's clock. Used by the MCP gateway right after
|
|
52
|
+
* the downstream tool returns: everything spooled from then on (response
|
|
53
|
+
* scanning, masking, bookkeeping) must report OUR overhead, not the tool's own
|
|
54
|
+
* runtime — a 30s build tool is not a 30s FullCourtDefense stall.
|
|
55
|
+
*/
|
|
56
|
+
export declare function restartVerdictTiming(): void;
|
|
21
57
|
/** Append one decision to the spool. Never throws (telemetry must not break the hook). */
|
|
22
58
|
export declare function spoolEvent(event: Omit<SpoolEvent, 'eventId' | 'occurredAt' | 'type'> & Partial<Pick<SpoolEvent, 'occurredAt' | 'type'>>): void;
|
|
23
59
|
export interface FlushInput {
|
|
@@ -76,3 +112,4 @@ export declare function flushSpool(input: FlushInput): Promise<{
|
|
|
76
112
|
* (used for critical blocks). The child reads creds from ~/.fullcourtdefense.yml.
|
|
77
113
|
*/
|
|
78
114
|
export declare function triggerFlush(immediate?: boolean): void;
|
|
115
|
+
export {};
|
package/dist/telemetry.js
CHANGED
|
@@ -33,9 +33,13 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.markVerdictTiming = markVerdictTiming;
|
|
37
|
+
exports.setVerdictPath = setVerdictPath;
|
|
38
|
+
exports.restartVerdictTiming = restartVerdictTiming;
|
|
36
39
|
exports.spoolEvent = spoolEvent;
|
|
37
40
|
exports.flushSpool = flushSpool;
|
|
38
41
|
exports.triggerFlush = triggerFlush;
|
|
42
|
+
const async_hooks_1 = require("async_hooks");
|
|
39
43
|
const child_process_1 = require("child_process");
|
|
40
44
|
const crypto = __importStar(require("crypto"));
|
|
41
45
|
const fs = __importStar(require("fs"));
|
|
@@ -63,9 +67,50 @@ const MAX_BATCH = 200;
|
|
|
63
67
|
const MAX_SPOOL_EVENTS = 2_000;
|
|
64
68
|
/** Cheap pre-check: skip the trim parse entirely until the file is plausibly over cap. */
|
|
65
69
|
const SPOOL_TRIM_BYTES = 2 * 1024 * 1024;
|
|
70
|
+
/**
|
|
71
|
+
* Per-evaluation timing context.
|
|
72
|
+
*
|
|
73
|
+
* AsyncLocalStorage (not a module variable) because the daemon evaluates
|
|
74
|
+
* several hook requests CONCURRENTLY in one process: a shared variable would
|
|
75
|
+
* attribute one hook's start time to another hook's event. The store follows
|
|
76
|
+
* each request's own async chain, so every spooled event gets its own numbers.
|
|
77
|
+
*
|
|
78
|
+
* Cost on the hot path: one object allocation per hook evaluation. No I/O, no
|
|
79
|
+
* timer, no network — the fields ride along on the verdict event the CLI was
|
|
80
|
+
* already spooling.
|
|
81
|
+
*/
|
|
82
|
+
const verdictTiming = new async_hooks_1.AsyncLocalStorage();
|
|
83
|
+
/** Run one hook evaluation with timing attached to everything it spools. */
|
|
84
|
+
function markVerdictTiming(timing, fn) {
|
|
85
|
+
return verdictTiming.run(timing, fn);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Re-label the current evaluation (e.g. it ended in the fail-open handler).
|
|
89
|
+
* Keeps the original start time so latency still covers the full wait.
|
|
90
|
+
*/
|
|
91
|
+
function setVerdictPath(path) {
|
|
92
|
+
const store = verdictTiming.getStore();
|
|
93
|
+
if (store)
|
|
94
|
+
store.path = path;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Restart the current evaluation's clock. Used by the MCP gateway right after
|
|
98
|
+
* the downstream tool returns: everything spooled from then on (response
|
|
99
|
+
* scanning, masking, bookkeeping) must report OUR overhead, not the tool's own
|
|
100
|
+
* runtime — a 30s build tool is not a 30s FullCourtDefense stall.
|
|
101
|
+
*/
|
|
102
|
+
function restartVerdictTiming() {
|
|
103
|
+
const store = verdictTiming.getStore();
|
|
104
|
+
if (store)
|
|
105
|
+
store.startedAt = Date.now();
|
|
106
|
+
}
|
|
66
107
|
/** Append one decision to the spool. Never throws (telemetry must not break the hook). */
|
|
67
108
|
function spoolEvent(event) {
|
|
68
109
|
try {
|
|
110
|
+
// Passive perf stamp: pure arithmetic on a timestamp the hot path already
|
|
111
|
+
// took. Absent when a caller spools outside a hook evaluation (guards,
|
|
112
|
+
// onboard) — the backend treats missing fields as "no sample".
|
|
113
|
+
const timing = verdictTiming.getStore();
|
|
69
114
|
const full = {
|
|
70
115
|
eventId: crypto.randomUUID(),
|
|
71
116
|
occurredAt: event.occurredAt || new Date().toISOString(),
|
|
@@ -84,6 +129,8 @@ function spoolEvent(event) {
|
|
|
84
129
|
explanation: event.explanation,
|
|
85
130
|
policyHash: event.policyHash,
|
|
86
131
|
offlineEnforced: event.offlineEnforced,
|
|
132
|
+
latencyMs: timing ? Math.max(0, Date.now() - timing.startedAt) : undefined,
|
|
133
|
+
verdictPath: timing?.path,
|
|
87
134
|
};
|
|
88
135
|
fs.appendFileSync(SPOOL_PATH, JSON.stringify(full) + '\n', { encoding: 'utf-8', mode: 0o600 });
|
|
89
136
|
enforceSpoolCap();
|
package/dist/verdictIpc.d.ts
CHANGED
|
@@ -33,6 +33,14 @@ export interface VerdictRequest {
|
|
|
33
33
|
args: Record<string, string | undefined>;
|
|
34
34
|
/** Raw stdin payload exactly as the IDE piped it (BOM already stripped). */
|
|
35
35
|
stdin: string;
|
|
36
|
+
/**
|
|
37
|
+
* Client's `Date.now()` at hook start, so the daemon-written telemetry event
|
|
38
|
+
* carries the wall time the DEVELOPER waited (process spawn + pipe + verdict),
|
|
39
|
+
* not just the daemon's own evaluation slice. Optional on purpose: during a
|
|
40
|
+
* staged rollout an old client omits it (daemon falls back to its own clock)
|
|
41
|
+
* and an old daemon ignores it — same-machine clock, so no skew.
|
|
42
|
+
*/
|
|
43
|
+
t0?: number;
|
|
36
44
|
}
|
|
37
45
|
export interface VerdictResponse {
|
|
38
46
|
v: number;
|
|
@@ -68,7 +76,7 @@ export declare function verdictPipePath(): string;
|
|
|
68
76
|
* get ONE short jittered retry; hard failures (ENOENT stale pipe, refused)
|
|
69
77
|
* still fall back to local evaluation instantly.
|
|
70
78
|
*/
|
|
71
|
-
export declare function requestDaemonVerdict(args: Record<string, string | undefined>, stdin: string, responseTimeoutMs?: number): Promise<VerdictClientResult>;
|
|
79
|
+
export declare function requestDaemonVerdict(args: Record<string, string | undefined>, stdin: string, responseTimeoutMs?: number, clientStartedAt?: number): Promise<VerdictClientResult>;
|
|
72
80
|
export interface VerdictServerHandle {
|
|
73
81
|
close(): void;
|
|
74
82
|
}
|
package/dist/verdictIpc.js
CHANGED
|
@@ -43,6 +43,7 @@ const fs = __importStar(require("fs"));
|
|
|
43
43
|
const net = __importStar(require("net"));
|
|
44
44
|
const os = __importStar(require("os"));
|
|
45
45
|
const path = __importStar(require("path"));
|
|
46
|
+
const telemetry_1 = require("./telemetry");
|
|
46
47
|
/**
|
|
47
48
|
* Daemon verdict IPC — the resident-agent pattern real endpoint products use
|
|
48
49
|
* (one resident process; per-event interceptors are thin clients that ask it
|
|
@@ -118,15 +119,15 @@ const RESPONSE_TIMEOUT_MS = 2_500;
|
|
|
118
119
|
* get ONE short jittered retry; hard failures (ENOENT stale pipe, refused)
|
|
119
120
|
* still fall back to local evaluation instantly.
|
|
120
121
|
*/
|
|
121
|
-
async function requestDaemonVerdict(args, stdin, responseTimeoutMs = RESPONSE_TIMEOUT_MS) {
|
|
122
|
-
const first = await attemptDaemonVerdict(args, stdin, responseTimeoutMs);
|
|
122
|
+
async function requestDaemonVerdict(args, stdin, responseTimeoutMs = RESPONSE_TIMEOUT_MS, clientStartedAt) {
|
|
123
|
+
const first = await attemptDaemonVerdict(args, stdin, responseTimeoutMs, clientStartedAt);
|
|
123
124
|
if (first.outcome === 'unavailable' && /EBUSY|busy|EAGAIN|connect timeout/i.test(first.detail || '')) {
|
|
124
125
|
await new Promise((r) => setTimeout(r, 20 + Math.floor(Math.random() * 30)));
|
|
125
|
-
return attemptDaemonVerdict(args, stdin, responseTimeoutMs);
|
|
126
|
+
return attemptDaemonVerdict(args, stdin, responseTimeoutMs, clientStartedAt);
|
|
126
127
|
}
|
|
127
128
|
return first;
|
|
128
129
|
}
|
|
129
|
-
function attemptDaemonVerdict(args, stdin, responseTimeoutMs) {
|
|
130
|
+
function attemptDaemonVerdict(args, stdin, responseTimeoutMs, clientStartedAt) {
|
|
130
131
|
return new Promise((resolve) => {
|
|
131
132
|
const token = readToken();
|
|
132
133
|
if (!token) {
|
|
@@ -153,7 +154,7 @@ function attemptDaemonVerdict(args, stdin, responseTimeoutMs) {
|
|
|
153
154
|
socket.on('error', (err) => fail(err.message));
|
|
154
155
|
socket.on('connect', () => {
|
|
155
156
|
clearTimeout(connectTimer);
|
|
156
|
-
const request = { v: exports.VERDICT_IPC_PROTOCOL_VERSION, token, args, stdin };
|
|
157
|
+
const request = { v: exports.VERDICT_IPC_PROTOCOL_VERSION, token, args, stdin, t0: clientStartedAt };
|
|
157
158
|
try {
|
|
158
159
|
socket.write(JSON.stringify(request) + '\n');
|
|
159
160
|
}
|
|
@@ -258,7 +259,11 @@ function startVerdictServer(evaluate, log) {
|
|
|
258
259
|
return;
|
|
259
260
|
}
|
|
260
261
|
try {
|
|
261
|
-
|
|
262
|
+
// Attach the requesting hook's own start time to whatever this
|
|
263
|
+
// evaluation spools, so fleet telemetry reports the wall time the
|
|
264
|
+
// developer waited. Per-request (AsyncLocalStorage), so concurrent
|
|
265
|
+
// hooks in this one daemon never borrow each other's timings.
|
|
266
|
+
const result = await (0, telemetry_1.markVerdictTiming)({ startedAt: typeof request.t0 === 'number' ? request.t0 : Date.now(), path: 'ipc' }, () => evaluate(request.args || {}, String(request.stdin ?? '')));
|
|
262
267
|
reply({ v: exports.VERDICT_IPC_PROTOCOL_VERSION, ...result });
|
|
263
268
|
}
|
|
264
269
|
catch (err) {
|
package/dist/version.json
CHANGED