hackmyagent 0.16.5 → 0.17.0
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 +28 -1
- package/dist/arp/index.d.ts.map +1 -1
- package/dist/arp/index.js +97 -4
- 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/runtime-twin.d.ts +157 -0
- package/dist/arp/intelligence/runtime-twin.d.ts.map +1 -0
- package/dist/arp/intelligence/runtime-twin.js +479 -0
- package/dist/arp/intelligence/runtime-twin.js.map +1 -0
- 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 +229 -1
- package/dist/arp/types.d.ts.map +1 -1
- package/dist/cli.js +691 -154
- package/dist/cli.js.map +1 -1
- package/dist/hardening/scanner.d.ts.map +1 -1
- package/dist/hardening/scanner.js +11 -1
- package/dist/hardening/scanner.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,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Behavioral risk signal channel (AIComply P1, coordinator hot path).
|
|
3
|
+
*
|
|
4
|
+
* The `IntelligenceCoordinator` needs a way to ask the behavioral twin
|
|
5
|
+
* (`RuntimeTwin` in `runtime-twin.ts`) "how anomalous does this event
|
|
6
|
+
* look against the agent's behavioral baseline?" without importing the
|
|
7
|
+
* twin directly into the comply path. Direct coupling would re-introduce the
|
|
8
|
+
* layering break that the L0-comply gate was added to prevent: the twin
|
|
9
|
+
* would sit inline with the crypto verifier, and a bug in the twin would
|
|
10
|
+
* cascade into every classified event.
|
|
11
|
+
*
|
|
12
|
+
* The solution here is an IPC contract. The coordinator holds a
|
|
13
|
+
* `BehavioralRiskSource` that abstracts transport. Two implementations
|
|
14
|
+
* ship in this module:
|
|
15
|
+
*
|
|
16
|
+
* - `InProcessBehavioralRiskSource` wraps any object that exposes
|
|
17
|
+
* `scoreARPEvent(event)`. This is the single-process fast path: no
|
|
18
|
+
* serialization, no socket, just a direct call guarded by a try/catch.
|
|
19
|
+
* `RuntimeTwin` satisfies the interface via its readonly
|
|
20
|
+
* scoreARPEvent method, but tests can inject any stub.
|
|
21
|
+
*
|
|
22
|
+
* - `UnixSocketBehavioralRiskSource` speaks newline-delimited JSON over
|
|
23
|
+
* a unix domain socket (or a Windows named pipe via node `net`). This
|
|
24
|
+
* is the cross-process variant, used when the twin runs in its own
|
|
25
|
+
* daemon to isolate a crashy baseline from the enforcement path.
|
|
26
|
+
*
|
|
27
|
+
* Every caller-visible method is bounded:
|
|
28
|
+
*
|
|
29
|
+
* - `getBehavioralRiskSignal(event, timeoutMs)` enforces a deadline on
|
|
30
|
+
* every call. The unix socket transport destroys the socket on timeout
|
|
31
|
+
* and resolves to `{status: 'unavailable', code: 'TIMEOUT'}`; the
|
|
32
|
+
* in-process source has no IO but still wraps the call in a bounded
|
|
33
|
+
* try/catch so a throwing twin cannot take down the coordinator.
|
|
34
|
+
*
|
|
35
|
+
* - A five-failure circuit breaker opens the unix socket transport for
|
|
36
|
+
* 30 seconds on repeated unavailable outcomes. A wedged IPC source
|
|
37
|
+
* therefore cannot cascade-block the coordinator indefinitely: after
|
|
38
|
+
* the breaker opens, calls resolve instantly with a cached error until
|
|
39
|
+
* cooldown expires.
|
|
40
|
+
*
|
|
41
|
+
* Parse-to-deny (CR-001) is honored on every path: the public surface
|
|
42
|
+
* never throws. Every error branch resolves to a typed
|
|
43
|
+
* `{status: 'unavailable', code, reason}` so the coordinator can route on
|
|
44
|
+
* the code without string scraping. What "deny" means when the twin is
|
|
45
|
+
* unavailable is the coordinator's policy, not this module's: the
|
|
46
|
+
* coordinator records the unavailable signal on `event.data.behavioralRisk`
|
|
47
|
+
* for downstream audit and leaves severity untouched. An IPC outage is
|
|
48
|
+
* not evidence of threat, and raising severity on every event during twin
|
|
49
|
+
* startup would be a regression; security-paranoid deployments can layer
|
|
50
|
+
* a stricter policy on top of the recorded signal.
|
|
51
|
+
*/
|
|
52
|
+
import type { ARPEvent } from '../types';
|
|
53
|
+
/**
|
|
54
|
+
* Shape returned by the twin's on-demand scorer. Mirrors RuntimeTwin's
|
|
55
|
+
* internal AnomalyResult so this module does not need to import the twin
|
|
56
|
+
* directly, and so test stubs can produce it without depending on the
|
|
57
|
+
* full RuntimeTwin class surface.
|
|
58
|
+
*/
|
|
59
|
+
export interface BehavioralRiskScore {
|
|
60
|
+
/** Normalized anomaly score in [0, 1]. Higher is riskier. */
|
|
61
|
+
score: number;
|
|
62
|
+
/** Response mapping derived from the score band. */
|
|
63
|
+
action: 'allow' | 'alert' | 'throttle' | 'suspend' | 'kill';
|
|
64
|
+
/** Human-readable reason for the action, safe to log. */
|
|
65
|
+
reason: string;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Minimum interface an in-process twin handle must satisfy to be plugged
|
|
69
|
+
* into `InProcessBehavioralRiskSource`. RuntimeTwin.scoreARPEvent matches
|
|
70
|
+
* this shape by construction.
|
|
71
|
+
*/
|
|
72
|
+
export interface BehavioralRiskScoreable {
|
|
73
|
+
scoreARPEvent(event: ARPEvent): BehavioralRiskScore | null;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Ok branch returned to the coordinator when the twin scored the event.
|
|
77
|
+
* The `source` string identifies which twin produced the signal (for
|
|
78
|
+
* audit) and `computedAtMs` is the wall clock at the time of scoring so
|
|
79
|
+
* callers can age out old values if they cache.
|
|
80
|
+
*/
|
|
81
|
+
export interface BehavioralRiskSignal extends BehavioralRiskScore {
|
|
82
|
+
source: string;
|
|
83
|
+
computedAtMs: number;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Discrete error codes on the unavailable branch. Kept as a closed union
|
|
87
|
+
* so the coordinator can route on the code without parsing strings.
|
|
88
|
+
*/
|
|
89
|
+
export type BehavioralRiskUnavailableCode = 'NOT_READY' | 'TIMEOUT' | 'TRANSPORT_ERROR' | 'PARSE_ERROR' | 'CIRCUIT_OPEN' | 'DISABLED' | 'INTERNAL_ERROR';
|
|
90
|
+
/**
|
|
91
|
+
* Discriminated union a caller routes on. The ok branch carries the full
|
|
92
|
+
* signal; the unavailable branch carries a code and a short reason.
|
|
93
|
+
*/
|
|
94
|
+
export type BehavioralRiskResult = {
|
|
95
|
+
status: 'ok';
|
|
96
|
+
signal: BehavioralRiskSignal;
|
|
97
|
+
} | {
|
|
98
|
+
status: 'unavailable';
|
|
99
|
+
code: BehavioralRiskUnavailableCode;
|
|
100
|
+
reason: string;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Abstract transport the coordinator holds. All error paths resolve to an
|
|
104
|
+
* `unavailable` result; `getBehavioralRiskSignal` must never throw and
|
|
105
|
+
* must honor the timeout deadline.
|
|
106
|
+
*/
|
|
107
|
+
export interface BehavioralRiskSource {
|
|
108
|
+
/**
|
|
109
|
+
* Ask the twin for the behavioral risk signal associated with `event`.
|
|
110
|
+
* Must resolve within `timeoutMs`. Must never throw. Must never block
|
|
111
|
+
* the caller beyond the timeout: implementations that wait on IO must
|
|
112
|
+
* tear down any pending work on deadline.
|
|
113
|
+
*/
|
|
114
|
+
getBehavioralRiskSignal(event: ARPEvent, timeoutMs: number): Promise<BehavioralRiskResult>;
|
|
115
|
+
/**
|
|
116
|
+
* Release any transport resources. Coordinator calls this on shutdown.
|
|
117
|
+
* Safe to call repeatedly.
|
|
118
|
+
*/
|
|
119
|
+
close(): Promise<void>;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Default timeout for a single risk signal request. Chosen to keep the
|
|
123
|
+
* comply hot path well under a frame budget even under transport jitter.
|
|
124
|
+
* The in-process source ignores this; the unix socket source enforces it.
|
|
125
|
+
*/
|
|
126
|
+
export declare const DEFAULT_BEHAVIORAL_RISK_TIMEOUT_MS = 25;
|
|
127
|
+
/**
|
|
128
|
+
* Number of consecutive unavailable outcomes that open the circuit
|
|
129
|
+
* breaker on the unix socket source. A wedged twin daemon will hit this
|
|
130
|
+
* after five calls and stop consuming coordinator time.
|
|
131
|
+
*/
|
|
132
|
+
export declare const CIRCUIT_BREAKER_THRESHOLD = 5;
|
|
133
|
+
/**
|
|
134
|
+
* Cooldown before the circuit breaker allows a single probe call to try
|
|
135
|
+
* the transport again. 30 seconds is long enough to absorb transient
|
|
136
|
+
* restarts without burning too many coordinator cycles on probes.
|
|
137
|
+
*/
|
|
138
|
+
export declare const CIRCUIT_BREAKER_COOLDOWN_MS = 30000;
|
|
139
|
+
/**
|
|
140
|
+
* IPC wire format version. Clients and servers both advertise `version: 1`
|
|
141
|
+
* in every message; mismatched versions are treated as PARSE_ERROR rather
|
|
142
|
+
* than silently accepted, so a future protocol change cannot be downgraded.
|
|
143
|
+
*/
|
|
144
|
+
export declare const BEHAVIORAL_RISK_WIRE_VERSION = 1;
|
|
145
|
+
/**
|
|
146
|
+
* Resolve the platform-appropriate default socket path for the behavioral
|
|
147
|
+
* risk server. Unix-like systems get a socket under
|
|
148
|
+
* `~/.opena2a/arp/behavioral-risk-<agentId>.sock`; Windows gets a named
|
|
149
|
+
* pipe in the `\\.\pipe\opena2a-arp-behavioral-risk-<agentId>` namespace.
|
|
150
|
+
* Callers are free to override this.
|
|
151
|
+
*/
|
|
152
|
+
export declare function defaultBehavioralRiskSocketPath(agentId: string): string;
|
|
153
|
+
/**
|
|
154
|
+
* In-process risk source. Wraps a handle that implements
|
|
155
|
+
* `scoreARPEvent`. Intended for single-process deployments where the
|
|
156
|
+
* twin and the coordinator live in the same Node process. Synchronous by
|
|
157
|
+
* construction, so the timeout is only a safety net against a
|
|
158
|
+
* misbehaving twin that throws.
|
|
159
|
+
*
|
|
160
|
+
* Decoupling rationale: the coordinator holds this as a
|
|
161
|
+
* `BehavioralRiskSource`, not as a `RuntimeTwin`. The comply path has no
|
|
162
|
+
* knowledge of twin internals and a bug in the twin surfaces as an
|
|
163
|
+
* `unavailable` result, not a cascade failure.
|
|
164
|
+
*/
|
|
165
|
+
export declare class InProcessBehavioralRiskSource implements BehavioralRiskSource {
|
|
166
|
+
private readonly twin;
|
|
167
|
+
private readonly sourceName;
|
|
168
|
+
constructor(twin: BehavioralRiskScoreable, sourceName?: string);
|
|
169
|
+
getBehavioralRiskSignal(event: ARPEvent, _timeoutMs: number): Promise<BehavioralRiskResult>;
|
|
170
|
+
close(): Promise<void>;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Unix-socket (or Windows named pipe) risk source. Opens a fresh
|
|
174
|
+
* connection per request. Rationale: per-request connections keep the
|
|
175
|
+
* transport state machine trivial (no pooling, no reconnection dance) and
|
|
176
|
+
* the request cost is dominated by the twin's scoring latency, not the
|
|
177
|
+
* connect itself. If perf measurement later shows connect-per-request is
|
|
178
|
+
* a bottleneck, a pooled variant can be added without changing the
|
|
179
|
+
* public BehavioralRiskSource interface.
|
|
180
|
+
*
|
|
181
|
+
* Circuit breaker semantics:
|
|
182
|
+
* - After `CIRCUIT_BREAKER_THRESHOLD` consecutive unavailable outcomes,
|
|
183
|
+
* the breaker opens and subsequent calls fast-fail with
|
|
184
|
+
* `CIRCUIT_OPEN` without touching the socket.
|
|
185
|
+
* - After `CIRCUIT_BREAKER_COOLDOWN_MS`, the breaker half-opens: the
|
|
186
|
+
* next call is allowed through. A successful call resets the failure
|
|
187
|
+
* counter and closes the breaker. A failed probe leaves the breaker
|
|
188
|
+
* open and restarts the cooldown.
|
|
189
|
+
*/
|
|
190
|
+
export declare class UnixSocketBehavioralRiskSource implements BehavioralRiskSource {
|
|
191
|
+
private readonly socketPath;
|
|
192
|
+
private readonly sourceName;
|
|
193
|
+
private readonly now;
|
|
194
|
+
private consecutiveFailures;
|
|
195
|
+
private circuitOpen;
|
|
196
|
+
private circuitOpenedAtMs;
|
|
197
|
+
constructor(socketPath: string, options?: {
|
|
198
|
+
sourceName?: string;
|
|
199
|
+
now?: () => number;
|
|
200
|
+
});
|
|
201
|
+
getBehavioralRiskSignal(event: ARPEvent, timeoutMs: number): Promise<BehavioralRiskResult>;
|
|
202
|
+
private roundTrip;
|
|
203
|
+
private parseResponse;
|
|
204
|
+
private recordOutcome;
|
|
205
|
+
/**
|
|
206
|
+
* Test-only accessor for the current breaker state. Exposed so tests
|
|
207
|
+
* can assert breaker opens at the threshold and closes on a successful
|
|
208
|
+
* probe without scraping internals through reflection.
|
|
209
|
+
*/
|
|
210
|
+
_getBreakerStateForTest(): {
|
|
211
|
+
open: boolean;
|
|
212
|
+
failures: number;
|
|
213
|
+
openedAtMs: number;
|
|
214
|
+
};
|
|
215
|
+
close(): Promise<void>;
|
|
216
|
+
}
|
|
217
|
+
//# sourceMappingURL=behavioral-risk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"behavioral-risk.d.ts","sourceRoot":"","sources":["../../../src/arp/intelligence/behavioral-risk.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE;IAQ5E,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B"}
|
|
@@ -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
|
+
* (`RuntimeTwin` in `runtime-twin.ts`) "how anomalous does this event
|
|
7
|
+
* look against the agent's behavioral baseline?" without importing the
|
|
8
|
+
* twin 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
|
+
* `RuntimeTwin` satisfies the interface via its readonly
|
|
21
|
+
* scoreARPEvent 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 `RuntimeTwin`. 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;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