hackmyagent 0.16.5 → 0.16.7
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/.integrity-manifest.json +1 -1
- package/dist/arp/crypto/hybrid-signing.d.ts +107 -0
- package/dist/arp/crypto/hybrid-signing.d.ts.map +1 -0
- package/dist/arp/crypto/hybrid-signing.js +321 -0
- package/dist/arp/crypto/hybrid-signing.js.map +1 -0
- package/dist/arp/crypto/index.d.ts +13 -0
- package/dist/arp/crypto/index.d.ts.map +1 -0
- package/dist/arp/crypto/index.js +33 -0
- package/dist/arp/crypto/index.js.map +1 -0
- package/dist/arp/crypto/manifest-loader.d.ts +117 -0
- package/dist/arp/crypto/manifest-loader.d.ts.map +1 -0
- package/dist/arp/crypto/manifest-loader.js +361 -0
- package/dist/arp/crypto/manifest-loader.js.map +1 -0
- package/dist/arp/crypto/types.d.ts +69 -0
- package/dist/arp/crypto/types.d.ts.map +1 -0
- package/dist/arp/crypto/types.js +11 -0
- package/dist/arp/crypto/types.js.map +1 -0
- package/dist/arp/index.d.ts +27 -0
- package/dist/arp/index.d.ts.map +1 -1
- package/dist/arp/index.js +94 -1
- package/dist/arp/index.js.map +1 -1
- package/dist/arp/intelligence/behavioral-risk-server.d.ts +82 -0
- package/dist/arp/intelligence/behavioral-risk-server.d.ts.map +1 -0
- package/dist/arp/intelligence/behavioral-risk-server.js +258 -0
- package/dist/arp/intelligence/behavioral-risk-server.js.map +1 -0
- package/dist/arp/intelligence/behavioral-risk.d.ts +217 -0
- package/dist/arp/intelligence/behavioral-risk.d.ts.map +1 -0
- package/dist/arp/intelligence/behavioral-risk.js +429 -0
- package/dist/arp/intelligence/behavioral-risk.js.map +1 -0
- package/dist/arp/intelligence/coordinator.d.ts +93 -2
- package/dist/arp/intelligence/coordinator.d.ts.map +1 -1
- package/dist/arp/intelligence/coordinator.js +281 -1
- package/dist/arp/intelligence/coordinator.js.map +1 -1
- package/dist/arp/intelligence/guard-anomaly.d.ts +349 -0
- package/dist/arp/intelligence/guard-anomaly.d.ts.map +1 -0
- package/dist/arp/intelligence/guard-anomaly.js +399 -0
- package/dist/arp/intelligence/guard-anomaly.js.map +1 -0
- package/dist/arp/intelligence/nanomind-l1.d.ts +37 -0
- package/dist/arp/intelligence/nanomind-l1.d.ts.map +1 -1
- package/dist/arp/intelligence/nanomind-l1.js +78 -0
- package/dist/arp/intelligence/nanomind-l1.js.map +1 -1
- package/dist/arp/intelligence/verify-classification.d.ts +124 -0
- package/dist/arp/intelligence/verify-classification.d.ts.map +1 -0
- package/dist/arp/intelligence/verify-classification.js +329 -0
- package/dist/arp/intelligence/verify-classification.js.map +1 -0
- package/dist/arp/proxy/server.d.ts +38 -8
- package/dist/arp/proxy/server.d.ts.map +1 -1
- package/dist/arp/proxy/server.js +89 -0
- package/dist/arp/proxy/server.js.map +1 -1
- package/dist/arp/types.d.ts +228 -1
- package/dist/arp/types.d.ts.map +1 -1
- package/dist/cli.js +85 -18
- package/dist/cli.js.map +1 -1
- package/dist/nanomind-core/compiler/semantic-compiler.d.ts.map +1 -1
- package/dist/nanomind-core/compiler/semantic-compiler.js +170 -10
- package/dist/nanomind-core/compiler/semantic-compiler.js.map +1 -1
- package/dist/nanomind-core/compiler/source-code-preprocessor.d.ts +64 -0
- package/dist/nanomind-core/compiler/source-code-preprocessor.d.ts.map +1 -0
- package/dist/nanomind-core/compiler/source-code-preprocessor.js +656 -0
- package/dist/nanomind-core/compiler/source-code-preprocessor.js.map +1 -0
- package/dist/nanomind-core/ingestion/artifact-parser.d.ts.map +1 -1
- package/dist/nanomind-core/ingestion/artifact-parser.js +15 -6
- package/dist/nanomind-core/ingestion/artifact-parser.js.map +1 -1
- package/package.json +3 -1
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Behavioral risk signal channel (AIComply P1, coordinator hot path).
|
|
4
|
+
*
|
|
5
|
+
* The `IntelligenceCoordinator` needs a way to ask the behavioral twin
|
|
6
|
+
* (`NanoMindL1` in `nanomind-l1.ts`) "how anomalous does this event look
|
|
7
|
+
* against the agent's behavioral baseline?" without importing the twin
|
|
8
|
+
* directly into the comply path. Direct coupling would re-introduce the
|
|
9
|
+
* layering break that the L0-comply gate was added to prevent: the twin
|
|
10
|
+
* would sit inline with the crypto verifier, and a bug in the twin would
|
|
11
|
+
* cascade into every classified event.
|
|
12
|
+
*
|
|
13
|
+
* The solution here is an IPC contract. The coordinator holds a
|
|
14
|
+
* `BehavioralRiskSource` that abstracts transport. Two implementations
|
|
15
|
+
* ship in this module:
|
|
16
|
+
*
|
|
17
|
+
* - `InProcessBehavioralRiskSource` wraps any object that exposes
|
|
18
|
+
* `scoreARPEvent(event)`. This is the single-process fast path: no
|
|
19
|
+
* serialization, no socket, just a direct call guarded by a try/catch.
|
|
20
|
+
* `NanoMindL1` satisfies the interface via its readonly scoreARPEvent
|
|
21
|
+
* method, but tests can inject any stub.
|
|
22
|
+
*
|
|
23
|
+
* - `UnixSocketBehavioralRiskSource` speaks newline-delimited JSON over
|
|
24
|
+
* a unix domain socket (or a Windows named pipe via node `net`). This
|
|
25
|
+
* is the cross-process variant, used when the twin runs in its own
|
|
26
|
+
* daemon to isolate a crashy baseline from the enforcement path.
|
|
27
|
+
*
|
|
28
|
+
* Every caller-visible method is bounded:
|
|
29
|
+
*
|
|
30
|
+
* - `getBehavioralRiskSignal(event, timeoutMs)` enforces a deadline on
|
|
31
|
+
* every call. The unix socket transport destroys the socket on timeout
|
|
32
|
+
* and resolves to `{status: 'unavailable', code: 'TIMEOUT'}`; the
|
|
33
|
+
* in-process source has no IO but still wraps the call in a bounded
|
|
34
|
+
* try/catch so a throwing twin cannot take down the coordinator.
|
|
35
|
+
*
|
|
36
|
+
* - A five-failure circuit breaker opens the unix socket transport for
|
|
37
|
+
* 30 seconds on repeated unavailable outcomes. A wedged IPC source
|
|
38
|
+
* therefore cannot cascade-block the coordinator indefinitely: after
|
|
39
|
+
* the breaker opens, calls resolve instantly with a cached error until
|
|
40
|
+
* cooldown expires.
|
|
41
|
+
*
|
|
42
|
+
* Parse-to-deny (CR-001) is honored on every path: the public surface
|
|
43
|
+
* never throws. Every error branch resolves to a typed
|
|
44
|
+
* `{status: 'unavailable', code, reason}` so the coordinator can route on
|
|
45
|
+
* the code without string scraping. What "deny" means when the twin is
|
|
46
|
+
* unavailable is the coordinator's policy, not this module's: the
|
|
47
|
+
* coordinator records the unavailable signal on `event.data.behavioralRisk`
|
|
48
|
+
* for downstream audit and leaves severity untouched. An IPC outage is
|
|
49
|
+
* not evidence of threat, and raising severity on every event during twin
|
|
50
|
+
* startup would be a regression; security-paranoid deployments can layer
|
|
51
|
+
* a stricter policy on top of the recorded signal.
|
|
52
|
+
*/
|
|
53
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
54
|
+
if (k2 === undefined) k2 = k;
|
|
55
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
56
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
57
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
58
|
+
}
|
|
59
|
+
Object.defineProperty(o, k2, desc);
|
|
60
|
+
}) : (function(o, m, k, k2) {
|
|
61
|
+
if (k2 === undefined) k2 = k;
|
|
62
|
+
o[k2] = m[k];
|
|
63
|
+
}));
|
|
64
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
65
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
66
|
+
}) : function(o, v) {
|
|
67
|
+
o["default"] = v;
|
|
68
|
+
});
|
|
69
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
70
|
+
var ownKeys = function(o) {
|
|
71
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
72
|
+
var ar = [];
|
|
73
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
74
|
+
return ar;
|
|
75
|
+
};
|
|
76
|
+
return ownKeys(o);
|
|
77
|
+
};
|
|
78
|
+
return function (mod) {
|
|
79
|
+
if (mod && mod.__esModule) return mod;
|
|
80
|
+
var result = {};
|
|
81
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
82
|
+
__setModuleDefault(result, mod);
|
|
83
|
+
return result;
|
|
84
|
+
};
|
|
85
|
+
})();
|
|
86
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
87
|
+
exports.UnixSocketBehavioralRiskSource = exports.InProcessBehavioralRiskSource = exports.BEHAVIORAL_RISK_WIRE_VERSION = exports.CIRCUIT_BREAKER_COOLDOWN_MS = exports.CIRCUIT_BREAKER_THRESHOLD = exports.DEFAULT_BEHAVIORAL_RISK_TIMEOUT_MS = void 0;
|
|
88
|
+
exports.defaultBehavioralRiskSocketPath = defaultBehavioralRiskSocketPath;
|
|
89
|
+
const net = __importStar(require("net"));
|
|
90
|
+
const os = __importStar(require("os"));
|
|
91
|
+
const path = __importStar(require("path"));
|
|
92
|
+
/**
|
|
93
|
+
* Default timeout for a single risk signal request. Chosen to keep the
|
|
94
|
+
* comply hot path well under a frame budget even under transport jitter.
|
|
95
|
+
* The in-process source ignores this; the unix socket source enforces it.
|
|
96
|
+
*/
|
|
97
|
+
exports.DEFAULT_BEHAVIORAL_RISK_TIMEOUT_MS = 25;
|
|
98
|
+
/**
|
|
99
|
+
* Number of consecutive unavailable outcomes that open the circuit
|
|
100
|
+
* breaker on the unix socket source. A wedged twin daemon will hit this
|
|
101
|
+
* after five calls and stop consuming coordinator time.
|
|
102
|
+
*/
|
|
103
|
+
exports.CIRCUIT_BREAKER_THRESHOLD = 5;
|
|
104
|
+
/**
|
|
105
|
+
* Cooldown before the circuit breaker allows a single probe call to try
|
|
106
|
+
* the transport again. 30 seconds is long enough to absorb transient
|
|
107
|
+
* restarts without burning too many coordinator cycles on probes.
|
|
108
|
+
*/
|
|
109
|
+
exports.CIRCUIT_BREAKER_COOLDOWN_MS = 30000;
|
|
110
|
+
/**
|
|
111
|
+
* IPC wire format version. Clients and servers both advertise `version: 1`
|
|
112
|
+
* in every message; mismatched versions are treated as PARSE_ERROR rather
|
|
113
|
+
* than silently accepted, so a future protocol change cannot be downgraded.
|
|
114
|
+
*/
|
|
115
|
+
exports.BEHAVIORAL_RISK_WIRE_VERSION = 1;
|
|
116
|
+
/**
|
|
117
|
+
* Resolve the platform-appropriate default socket path for the behavioral
|
|
118
|
+
* risk server. Unix-like systems get a socket under
|
|
119
|
+
* `~/.opena2a/arp/behavioral-risk-<agentId>.sock`; Windows gets a named
|
|
120
|
+
* pipe in the `\\.\pipe\opena2a-arp-behavioral-risk-<agentId>` namespace.
|
|
121
|
+
* Callers are free to override this.
|
|
122
|
+
*/
|
|
123
|
+
function defaultBehavioralRiskSocketPath(agentId) {
|
|
124
|
+
const safe = agentId.replace(/[^a-zA-Z0-9_-]/g, '_');
|
|
125
|
+
if (process.platform === 'win32') {
|
|
126
|
+
return `\\\\.\\pipe\\opena2a-arp-behavioral-risk-${safe}`;
|
|
127
|
+
}
|
|
128
|
+
return path.join(os.homedir(), '.opena2a', 'arp', `behavioral-risk-${safe}.sock`);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* In-process risk source. Wraps a handle that implements
|
|
132
|
+
* `scoreARPEvent`. Intended for single-process deployments where the
|
|
133
|
+
* twin and the coordinator live in the same Node process. Synchronous by
|
|
134
|
+
* construction, so the timeout is only a safety net against a
|
|
135
|
+
* misbehaving twin that throws.
|
|
136
|
+
*
|
|
137
|
+
* Decoupling rationale: the coordinator holds this as a
|
|
138
|
+
* `BehavioralRiskSource`, not as a `NanoMindL1`. The comply path has no
|
|
139
|
+
* knowledge of twin internals and a bug in the twin surfaces as an
|
|
140
|
+
* `unavailable` result, not a cascade failure.
|
|
141
|
+
*/
|
|
142
|
+
class InProcessBehavioralRiskSource {
|
|
143
|
+
constructor(twin, sourceName = 'nanomind-l1-inproc') {
|
|
144
|
+
this.twin = twin;
|
|
145
|
+
this.sourceName = sourceName;
|
|
146
|
+
}
|
|
147
|
+
async getBehavioralRiskSignal(event, _timeoutMs) {
|
|
148
|
+
// Synchronous call wrapped in try/catch. The twin's scoreARPEvent is
|
|
149
|
+
// contract-bound to return null on not-ready; we map that to the
|
|
150
|
+
// NOT_READY code so the coordinator can tell apart "no baseline" from
|
|
151
|
+
// a runtime error.
|
|
152
|
+
try {
|
|
153
|
+
const result = this.twin.scoreARPEvent(event);
|
|
154
|
+
if (result === null) {
|
|
155
|
+
return {
|
|
156
|
+
status: 'unavailable',
|
|
157
|
+
code: 'NOT_READY',
|
|
158
|
+
reason: 'behavioral twin baseline is not yet trained',
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
return {
|
|
162
|
+
status: 'ok',
|
|
163
|
+
signal: {
|
|
164
|
+
score: result.score,
|
|
165
|
+
action: result.action,
|
|
166
|
+
reason: result.reason,
|
|
167
|
+
source: this.sourceName,
|
|
168
|
+
computedAtMs: Date.now(),
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
catch (err) {
|
|
173
|
+
// A throwing twin is a twin bug, not a threat signal. Surface it as
|
|
174
|
+
// INTERNAL_ERROR; the coordinator's unavailable policy handles the
|
|
175
|
+
// rest.
|
|
176
|
+
return {
|
|
177
|
+
status: 'unavailable',
|
|
178
|
+
code: 'INTERNAL_ERROR',
|
|
179
|
+
reason: `scoreARPEvent threw: ${err.message ?? String(err)}`,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
async close() {
|
|
184
|
+
// No transport resources to release.
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
exports.InProcessBehavioralRiskSource = InProcessBehavioralRiskSource;
|
|
188
|
+
/**
|
|
189
|
+
* Unix-socket (or Windows named pipe) risk source. Opens a fresh
|
|
190
|
+
* connection per request. Rationale: per-request connections keep the
|
|
191
|
+
* transport state machine trivial (no pooling, no reconnection dance) and
|
|
192
|
+
* the request cost is dominated by the twin's scoring latency, not the
|
|
193
|
+
* connect itself. If perf measurement later shows connect-per-request is
|
|
194
|
+
* a bottleneck, a pooled variant can be added without changing the
|
|
195
|
+
* public BehavioralRiskSource interface.
|
|
196
|
+
*
|
|
197
|
+
* Circuit breaker semantics:
|
|
198
|
+
* - After `CIRCUIT_BREAKER_THRESHOLD` consecutive unavailable outcomes,
|
|
199
|
+
* the breaker opens and subsequent calls fast-fail with
|
|
200
|
+
* `CIRCUIT_OPEN` without touching the socket.
|
|
201
|
+
* - After `CIRCUIT_BREAKER_COOLDOWN_MS`, the breaker half-opens: the
|
|
202
|
+
* next call is allowed through. A successful call resets the failure
|
|
203
|
+
* counter and closes the breaker. A failed probe leaves the breaker
|
|
204
|
+
* open and restarts the cooldown.
|
|
205
|
+
*/
|
|
206
|
+
class UnixSocketBehavioralRiskSource {
|
|
207
|
+
constructor(socketPath, options = {}) {
|
|
208
|
+
this.consecutiveFailures = 0;
|
|
209
|
+
this.circuitOpen = false;
|
|
210
|
+
this.circuitOpenedAtMs = 0;
|
|
211
|
+
this.socketPath = socketPath;
|
|
212
|
+
this.sourceName = options.sourceName ?? 'nanomind-l1-ipc';
|
|
213
|
+
this.now = options.now ?? Date.now;
|
|
214
|
+
}
|
|
215
|
+
async getBehavioralRiskSignal(event, timeoutMs) {
|
|
216
|
+
// Fast path: breaker open. Check cooldown. If still open, fast-fail.
|
|
217
|
+
// Otherwise allow a single probe through.
|
|
218
|
+
if (this.circuitOpen) {
|
|
219
|
+
const elapsed = this.now() - this.circuitOpenedAtMs;
|
|
220
|
+
if (elapsed < exports.CIRCUIT_BREAKER_COOLDOWN_MS) {
|
|
221
|
+
return {
|
|
222
|
+
status: 'unavailable',
|
|
223
|
+
code: 'CIRCUIT_OPEN',
|
|
224
|
+
reason: `circuit breaker open, ${exports.CIRCUIT_BREAKER_COOLDOWN_MS - elapsed} ms remaining`,
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
// Half-open: let the next call through. The breaker stays flagged
|
|
228
|
+
// open until the call actually resolves; on success we close it.
|
|
229
|
+
}
|
|
230
|
+
const result = await this.roundTrip(event, timeoutMs);
|
|
231
|
+
this.recordOutcome(result);
|
|
232
|
+
return result;
|
|
233
|
+
}
|
|
234
|
+
roundTrip(event, timeoutMs) {
|
|
235
|
+
return new Promise((resolve) => {
|
|
236
|
+
let settled = false;
|
|
237
|
+
let socket = null;
|
|
238
|
+
const chunks = [];
|
|
239
|
+
const settle = (r) => {
|
|
240
|
+
if (settled)
|
|
241
|
+
return;
|
|
242
|
+
settled = true;
|
|
243
|
+
clearTimeout(timer);
|
|
244
|
+
if (socket && !socket.destroyed) {
|
|
245
|
+
socket.destroy();
|
|
246
|
+
}
|
|
247
|
+
resolve(r);
|
|
248
|
+
};
|
|
249
|
+
const timer = setTimeout(() => {
|
|
250
|
+
settle({
|
|
251
|
+
status: 'unavailable',
|
|
252
|
+
code: 'TIMEOUT',
|
|
253
|
+
reason: `behavioral risk ipc exceeded ${timeoutMs} ms deadline`,
|
|
254
|
+
});
|
|
255
|
+
}, timeoutMs);
|
|
256
|
+
if (typeof timer.unref === 'function')
|
|
257
|
+
timer.unref();
|
|
258
|
+
try {
|
|
259
|
+
socket = net.createConnection(this.socketPath);
|
|
260
|
+
}
|
|
261
|
+
catch (err) {
|
|
262
|
+
settle({
|
|
263
|
+
status: 'unavailable',
|
|
264
|
+
code: 'TRANSPORT_ERROR',
|
|
265
|
+
reason: `failed to initiate connection: ${err.message}`,
|
|
266
|
+
});
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
socket.on('connect', () => {
|
|
270
|
+
const request = JSON.stringify({
|
|
271
|
+
kind: 'risk_signal_request',
|
|
272
|
+
version: exports.BEHAVIORAL_RISK_WIRE_VERSION,
|
|
273
|
+
event,
|
|
274
|
+
}) + '\n';
|
|
275
|
+
try {
|
|
276
|
+
socket.write(request);
|
|
277
|
+
}
|
|
278
|
+
catch (err) {
|
|
279
|
+
settle({
|
|
280
|
+
status: 'unavailable',
|
|
281
|
+
code: 'TRANSPORT_ERROR',
|
|
282
|
+
reason: `failed to write request: ${err.message}`,
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
socket.on('data', (chunk) => {
|
|
287
|
+
chunks.push(chunk);
|
|
288
|
+
const buf = Buffer.concat(chunks).toString('utf8');
|
|
289
|
+
const nl = buf.indexOf('\n');
|
|
290
|
+
if (nl < 0)
|
|
291
|
+
return;
|
|
292
|
+
const line = buf.slice(0, nl);
|
|
293
|
+
settle(this.parseResponse(line));
|
|
294
|
+
});
|
|
295
|
+
socket.on('error', (err) => {
|
|
296
|
+
settle({
|
|
297
|
+
status: 'unavailable',
|
|
298
|
+
code: 'TRANSPORT_ERROR',
|
|
299
|
+
reason: `socket error: ${err.message}`,
|
|
300
|
+
});
|
|
301
|
+
});
|
|
302
|
+
socket.on('close', () => {
|
|
303
|
+
settle({
|
|
304
|
+
status: 'unavailable',
|
|
305
|
+
code: 'TRANSPORT_ERROR',
|
|
306
|
+
reason: 'socket closed before response received',
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
parseResponse(line) {
|
|
312
|
+
let msg;
|
|
313
|
+
try {
|
|
314
|
+
msg = JSON.parse(line);
|
|
315
|
+
}
|
|
316
|
+
catch (err) {
|
|
317
|
+
return {
|
|
318
|
+
status: 'unavailable',
|
|
319
|
+
code: 'PARSE_ERROR',
|
|
320
|
+
reason: `invalid json response: ${err.message}`,
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
if (msg === null || typeof msg !== 'object') {
|
|
324
|
+
return {
|
|
325
|
+
status: 'unavailable',
|
|
326
|
+
code: 'PARSE_ERROR',
|
|
327
|
+
reason: 'response body is not an object',
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
const obj = msg;
|
|
331
|
+
if (obj.version !== exports.BEHAVIORAL_RISK_WIRE_VERSION) {
|
|
332
|
+
return {
|
|
333
|
+
status: 'unavailable',
|
|
334
|
+
code: 'PARSE_ERROR',
|
|
335
|
+
reason: `unsupported wire version: ${JSON.stringify(obj.version)}`,
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
if (obj.kind === 'risk_signal_error') {
|
|
339
|
+
const code = isUnavailableCode(obj.code) ? obj.code : 'TRANSPORT_ERROR';
|
|
340
|
+
const reason = typeof obj.reason === 'string' ? obj.reason : 'server reported error';
|
|
341
|
+
return { status: 'unavailable', code, reason };
|
|
342
|
+
}
|
|
343
|
+
if (obj.kind !== 'risk_signal_response') {
|
|
344
|
+
return {
|
|
345
|
+
status: 'unavailable',
|
|
346
|
+
code: 'PARSE_ERROR',
|
|
347
|
+
reason: `unexpected message kind: ${JSON.stringify(obj.kind)}`,
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
if (typeof obj.score !== 'number' ||
|
|
351
|
+
!Number.isFinite(obj.score) ||
|
|
352
|
+
obj.score < 0 ||
|
|
353
|
+
obj.score > 1) {
|
|
354
|
+
return {
|
|
355
|
+
status: 'unavailable',
|
|
356
|
+
code: 'PARSE_ERROR',
|
|
357
|
+
reason: `score must be a finite number in [0,1], got ${JSON.stringify(obj.score)}`,
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
if (!isRiskAction(obj.action)) {
|
|
361
|
+
return {
|
|
362
|
+
status: 'unavailable',
|
|
363
|
+
code: 'PARSE_ERROR',
|
|
364
|
+
reason: `action must be one of allow|alert|throttle|suspend|kill, got ${JSON.stringify(obj.action)}`,
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
return {
|
|
368
|
+
status: 'ok',
|
|
369
|
+
signal: {
|
|
370
|
+
score: obj.score,
|
|
371
|
+
action: obj.action,
|
|
372
|
+
reason: typeof obj.reason === 'string' ? obj.reason : '',
|
|
373
|
+
source: typeof obj.source === 'string' && obj.source.length > 0
|
|
374
|
+
? obj.source
|
|
375
|
+
: this.sourceName,
|
|
376
|
+
computedAtMs: typeof obj.computedAtMs === 'number' && Number.isFinite(obj.computedAtMs)
|
|
377
|
+
? obj.computedAtMs
|
|
378
|
+
: this.now(),
|
|
379
|
+
},
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
recordOutcome(result) {
|
|
383
|
+
if (result.status === 'ok') {
|
|
384
|
+
this.consecutiveFailures = 0;
|
|
385
|
+
this.circuitOpen = false;
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
// CIRCUIT_OPEN outcomes do not increment the failure counter; they
|
|
389
|
+
// are already a symptom of the breaker being open. Counting them
|
|
390
|
+
// would extend the cooldown indefinitely every time a caller probed
|
|
391
|
+
// while the breaker is still cooling.
|
|
392
|
+
if (result.code === 'CIRCUIT_OPEN')
|
|
393
|
+
return;
|
|
394
|
+
this.consecutiveFailures++;
|
|
395
|
+
if (this.consecutiveFailures >= exports.CIRCUIT_BREAKER_THRESHOLD) {
|
|
396
|
+
this.circuitOpen = true;
|
|
397
|
+
this.circuitOpenedAtMs = this.now();
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Test-only accessor for the current breaker state. Exposed so tests
|
|
402
|
+
* can assert breaker opens at the threshold and closes on a successful
|
|
403
|
+
* probe without scraping internals through reflection.
|
|
404
|
+
*/
|
|
405
|
+
_getBreakerStateForTest() {
|
|
406
|
+
return {
|
|
407
|
+
open: this.circuitOpen,
|
|
408
|
+
failures: this.consecutiveFailures,
|
|
409
|
+
openedAtMs: this.circuitOpenedAtMs,
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
async close() {
|
|
413
|
+
// No pooled resources.
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
exports.UnixSocketBehavioralRiskSource = UnixSocketBehavioralRiskSource;
|
|
417
|
+
function isUnavailableCode(v) {
|
|
418
|
+
return (v === 'NOT_READY' ||
|
|
419
|
+
v === 'TIMEOUT' ||
|
|
420
|
+
v === 'TRANSPORT_ERROR' ||
|
|
421
|
+
v === 'PARSE_ERROR' ||
|
|
422
|
+
v === 'CIRCUIT_OPEN' ||
|
|
423
|
+
v === 'DISABLED' ||
|
|
424
|
+
v === 'INTERNAL_ERROR');
|
|
425
|
+
}
|
|
426
|
+
function isRiskAction(v) {
|
|
427
|
+
return v === 'allow' || v === 'alert' || v === 'throttle' || v === 'suspend' || v === 'kill';
|
|
428
|
+
}
|
|
429
|
+
//# sourceMappingURL=behavioral-risk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"behavioral-risk.js","sourceRoot":"","sources":["../../../src/arp/intelligence/behavioral-risk.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsHH,0EAMC;AA1HD,yCAA2B;AAC3B,uCAAyB;AACzB,2CAA6B;AA+E7B;;;;GAIG;AACU,QAAA,kCAAkC,GAAG,EAAE,CAAC;AAErD;;;;GAIG;AACU,QAAA,yBAAyB,GAAG,CAAC,CAAC;AAE3C;;;;GAIG;AACU,QAAA,2BAA2B,GAAG,KAAM,CAAC;AAElD;;;;GAIG;AACU,QAAA,4BAA4B,GAAG,CAAC,CAAC;AAE9C;;;;;;GAMG;AACH,SAAgB,+BAA+B,CAAC,OAAe;IAC7D,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,iBAAiB,EAAE,GAAG,CAAC,CAAC;IACrD,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;QACjC,OAAO,4CAA4C,IAAI,EAAE,CAAC;IAC5D,CAAC;IACD,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,mBAAmB,IAAI,OAAO,CAAC,CAAC;AACpF,CAAC;AAED;;;;;;;;;;;GAWG;AAC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AAC,CAAC;YAC7B,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;YACzB,OAAO;QACT,CAAC;QACD,mEAAmE;QACnE,iEAAiE;QACjE,oEAAoE;QACpE,sCAAsC;QACtC,IAAI,MAAM,CAAC,IAAI,KAAK,cAAc;YAAE,OAAO;QAC3C,IAAI,CAAC,mBAAmB,EAAE,CAAC;QAC3B,IAAI,IAAI,CAAC,mBAAmB,IAAI,iCAAyB,EAAE,CAAC;YAC1D,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;YACxB,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACtC,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,uBAAuB;QACrB,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,WAAW;YACtB,QAAQ,EAAE,IAAI,CAAC,mBAAmB;YAClC,UAAU,EAAE,IAAI,CAAC,iBAAiB;SACnC,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,KAAK;QACT,uBAAuB;IACzB,CAAC;CACF;AAzOD,wEAyOC;AAED,SAAS,iBAAiB,CAAC,CAAU;IACnC,OAAO,CACL,CAAC,KAAK,WAAW;QACjB,CAAC,KAAK,SAAS;QACf,CAAC,KAAK,iBAAiB;QACvB,CAAC,KAAK,aAAa;QACnB,CAAC,KAAK,cAAc;QACpB,CAAC,KAAK,UAAU;QAChB,CAAC,KAAK,gBAAgB,CACvB,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CAAC,CAAU;IAC9B,OAAO,CAAC,KAAK,OAAO,IAAI,CAAC,KAAK,OAAO,IAAI,CAAC,KAAK,UAAU,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,MAAM,CAAC;AAC/F,CAAC"}
|
|
@@ -1,4 +1,46 @@
|
|
|
1
|
-
import type { ARPEvent, ARPConfig, LLMAssessment } from '../types';
|
|
1
|
+
import type { ARPEvent, ARPConfig, CapabilityManifest, ComplyOnViolation, LLMAssessment } from '../types';
|
|
2
|
+
import { type BehavioralRiskSource, type BehavioralRiskUnavailableCode } from './behavioral-risk';
|
|
3
|
+
import type { GuardAnomalySource } from './guard-anomaly';
|
|
4
|
+
/**
|
|
5
|
+
* Reason the comply gate denied a classified event. `prohibited` means the
|
|
6
|
+
* class is on the explicit deny list; `unknown` means the class is not on
|
|
7
|
+
* the allow list and parse-to-deny applies (per CR-001).
|
|
8
|
+
*/
|
|
9
|
+
export type ComplyDenyReason = 'prohibited' | 'unknown';
|
|
10
|
+
/**
|
|
11
|
+
* Record written to `event.data.behavioralRisk` by the coordinator after
|
|
12
|
+
* it queries the behavioral twin. The ok branch carries the fused score
|
|
13
|
+
* and the band the coordinator used; the unavailable branch carries a
|
|
14
|
+
* code so downstream audit can tell a healthy 0.0 from an IPC outage.
|
|
15
|
+
*
|
|
16
|
+
* The coordinator's unavailable policy is record-and-ignore: an IPC
|
|
17
|
+
* failure is not evidence of threat, so severity is not mutated. A
|
|
18
|
+
* deployment that wants a stricter policy can layer it on top by
|
|
19
|
+
* reading `event.data.behavioralRisk` after analyze() returns.
|
|
20
|
+
*/
|
|
21
|
+
export type BehavioralRiskRecord = {
|
|
22
|
+
status: 'ok';
|
|
23
|
+
score: number;
|
|
24
|
+
action: 'allow' | 'alert' | 'throttle' | 'suspend' | 'kill';
|
|
25
|
+
source: string;
|
|
26
|
+
band: 'low' | 'elevated' | 'high' | 'critical';
|
|
27
|
+
} | {
|
|
28
|
+
status: 'unavailable';
|
|
29
|
+
code: BehavioralRiskUnavailableCode;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Structured record of a comply gate decision. Written to `event.data.comply`
|
|
33
|
+
* so downstream enforcement can route on the reason without re-checking the
|
|
34
|
+
* manifest, and so tests can assert the outcome without scraping logs.
|
|
35
|
+
*/
|
|
36
|
+
export interface ComplyDecision {
|
|
37
|
+
/** Classification label the gate evaluated. */
|
|
38
|
+
classification: string;
|
|
39
|
+
/** Reason for the deny: `prohibited` or `unknown` (parse-to-deny). */
|
|
40
|
+
reason: ComplyDenyReason;
|
|
41
|
+
/** Action routed from the manifest's `comply.on_violation` field. */
|
|
42
|
+
action: ComplyOnViolation;
|
|
43
|
+
}
|
|
2
44
|
/**
|
|
3
45
|
* The 3-Layer Intelligence Coordinator.
|
|
4
46
|
*
|
|
@@ -16,7 +58,56 @@ export declare class IntelligenceCoordinator {
|
|
|
16
58
|
private adapter;
|
|
17
59
|
private batchQueue;
|
|
18
60
|
private batchTimer?;
|
|
19
|
-
|
|
61
|
+
/**
|
|
62
|
+
* Capability manifest used to enforce the `comply` envelope on classified
|
|
63
|
+
* events. Optional: when null the comply gate is inert and the coordinator
|
|
64
|
+
* runs the L0/L1/L2 stack unchanged.
|
|
65
|
+
*/
|
|
66
|
+
private manifest;
|
|
67
|
+
/**
|
|
68
|
+
* Optional behavioral risk source. When set, `analyze()` fuses the
|
|
69
|
+
* signal returned by the source with the classification decision after
|
|
70
|
+
* the comply gate and before L1 statistical. When null, the coordinator
|
|
71
|
+
* runs the L0/L1/L2 stack unchanged. See `behavioral-risk.ts` for the
|
|
72
|
+
* IPC contract and the two shipping implementations.
|
|
73
|
+
*/
|
|
74
|
+
private behavioralRiskSource;
|
|
75
|
+
/**
|
|
76
|
+
* Optional guard anomaly (classification drift) detector. When set,
|
|
77
|
+
* `analyze()` records every classified event's label before the
|
|
78
|
+
* comply gate runs, so drift observations include denied attempts.
|
|
79
|
+
* Drift state is written to `event.data.guardAnomaly` in every
|
|
80
|
+
* branch (baseline-pending, normal, drift); only the drift branch
|
|
81
|
+
* raises severity. See `guard-anomaly.ts` for the bounded memory
|
|
82
|
+
* contract and the chi-square drift model.
|
|
83
|
+
*/
|
|
84
|
+
private guardAnomaly;
|
|
85
|
+
constructor(arpConfig: ARPConfig, dataDir: string, manifest?: CapabilityManifest | null, behavioralRiskSource?: BehavioralRiskSource | null, guardAnomaly?: GuardAnomalySource | null);
|
|
86
|
+
/**
|
|
87
|
+
* Replace or clear the capability manifest used for the comply gate.
|
|
88
|
+
* Exposed so the hosting runtime (e.g. the ARP proxy) can reload the
|
|
89
|
+
* manifest without tearing down the coordinator.
|
|
90
|
+
*/
|
|
91
|
+
setCapabilityManifest(manifest: CapabilityManifest | null): void;
|
|
92
|
+
/** The currently installed manifest, or null if none is set. */
|
|
93
|
+
getCapabilityManifest(): CapabilityManifest | null;
|
|
94
|
+
/**
|
|
95
|
+
* Replace or clear the behavioral risk source. Exposed so a hosting
|
|
96
|
+
* runtime can swap from an in-process source to a unix socket source
|
|
97
|
+
* (or vice versa) without tearing down the coordinator.
|
|
98
|
+
*/
|
|
99
|
+
setBehavioralRiskSource(source: BehavioralRiskSource | null): void;
|
|
100
|
+
/** The currently installed behavioral risk source, or null. */
|
|
101
|
+
getBehavioralRiskSource(): BehavioralRiskSource | null;
|
|
102
|
+
/**
|
|
103
|
+
* Replace or clear the guard anomaly detector. Exposed so a
|
|
104
|
+
* hosting runtime can hot-swap the drift model (for example to
|
|
105
|
+
* install a refreshed baseline from the Registry) without tearing
|
|
106
|
+
* down the coordinator.
|
|
107
|
+
*/
|
|
108
|
+
setGuardAnomaly(guardAnomaly: GuardAnomalySource | null): void;
|
|
109
|
+
/** The currently installed guard anomaly detector, or null. */
|
|
110
|
+
getGuardAnomaly(): GuardAnomalySource | null;
|
|
20
111
|
/**
|
|
21
112
|
* Analyze an event through the 3-layer stack.
|
|
22
113
|
* Mutates the event's category, severity, and classifiedBy fields.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coordinator.d.ts","sourceRoot":"","sources":["../../../src/arp/intelligence/coordinator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,SAAS,
|
|
1
|
+
{"version":3,"file":"coordinator.d.ts","sourceRoot":"","sources":["../../../src/arp/intelligence/coordinator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,SAAS,EACT,kBAAkB,EAClB,iBAAiB,EAGjB,aAAa,EAGd,MAAM,UAAU,CAAC;AAI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