@intutic/mcp-governance-proxy 2.3.0 → 2.4.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.
Files changed (41) hide show
  1. package/README.md +1 -1
  2. package/dist/agentTools.d.ts +15 -0
  3. package/dist/agentTools.d.ts.map +1 -1
  4. package/dist/agentTools.js +21 -1
  5. package/dist/agentTools.js.map +1 -1
  6. package/dist/daemon/policyCache.d.ts +7 -0
  7. package/dist/daemon/policyCache.d.ts.map +1 -1
  8. package/dist/daemon/policyCache.js +2 -0
  9. package/dist/daemon/policyCache.js.map +1 -1
  10. package/dist/emitter.d.ts +40 -2
  11. package/dist/emitter.d.ts.map +1 -1
  12. package/dist/emitter.js +7 -1
  13. package/dist/emitter.js.map +1 -1
  14. package/dist/httpJson.d.ts +7 -0
  15. package/dist/httpJson.d.ts.map +1 -1
  16. package/dist/httpJson.js +39 -0
  17. package/dist/httpJson.js.map +1 -1
  18. package/dist/interceptor.d.ts +12 -0
  19. package/dist/interceptor.d.ts.map +1 -1
  20. package/dist/interceptor.js +37 -5
  21. package/dist/interceptor.js.map +1 -1
  22. package/dist/policy.d.ts +17 -1
  23. package/dist/policy.d.ts.map +1 -1
  24. package/dist/policy.js +34 -2
  25. package/dist/policy.js.map +1 -1
  26. package/dist/proxy.d.ts +5 -3
  27. package/dist/proxy.d.ts.map +1 -1
  28. package/dist/proxy.js +15 -7
  29. package/dist/proxy.js.map +1 -1
  30. package/dist/wasm/cloudRules.d.ts +138 -0
  31. package/dist/wasm/cloudRules.d.ts.map +1 -0
  32. package/dist/wasm/cloudRules.js +242 -0
  33. package/dist/wasm/cloudRules.js.map +1 -0
  34. package/dist/wasm/loader.d.ts +3 -1
  35. package/dist/wasm/loader.d.ts.map +1 -1
  36. package/dist/wasm/loader.js.map +1 -1
  37. package/dist/wasm/runner.d.ts +63 -9
  38. package/dist/wasm/runner.d.ts.map +1 -1
  39. package/dist/wasm/runner.js +107 -12
  40. package/dist/wasm/runner.js.map +1 -1
  41. package/package.json +4 -4
@@ -0,0 +1,138 @@
1
+ /**
2
+ * wasm/cloudRules.ts — the workspace's custom rules from the control plane:
3
+ * the rules uploaded from the dashboard, the CLI or Terraform, which the LLM
4
+ * proxy enforces too.
5
+ *
6
+ * Port of the control-plane half of `packages/proxy/src/wasm/registry.rs`
7
+ * (`ensure_up_to_date`, `load_descriptor`, `report_refusal`). The descriptors
8
+ * arrive with the workspace policy this proxy already fetches (`wasmRules` on
9
+ * `GET /api/v1/sop/rules`, or on the MCP daemon's cached
10
+ * `GET /api/v1/policy/resolve`), so they refresh when the policy does. Each
11
+ * binary is fetched by the SHA-256 its descriptor names, only when no loaded
12
+ * rule already has that hash, and must hash to it before it is compiled:
13
+ * whoever can answer for that hash could otherwise swap a governance rule for
14
+ * one that allows everything.
15
+ *
16
+ * A version that cannot load — binary missing, hash mismatch, or a module the
17
+ * worker refuses — is reported once per hash and reason, and the version of
18
+ * that rule already loaded, if any, keeps enforcing. A control plane that
19
+ * cannot be reached for a binary leaves the whole loaded set as it was, as
20
+ * `registry.rs` does when its fetch fails.
21
+ *
22
+ * @module
23
+ */
24
+ import type { WasmRuleDescriptor, WasmRuleMode } from '@intutic/shared-types';
25
+ import type { WasmRuleRefusalDetail } from '../emitter.js';
26
+ import { type CompileBridge, type CompileFailureReason } from './loader.js';
27
+ /**
28
+ * Minimum time between attempts after a sync that could not reach the control
29
+ * plane or refused a version — the Rust proxy's 5-second rescan, so a binary
30
+ * published a moment after its descriptor is picked up as quickly there.
31
+ */
32
+ export declare const CLOUD_RETRY_MS = 5000;
33
+ /** A control-plane rule loaded into the worker. */
34
+ export interface CloudRuleMeta {
35
+ /** The control plane's rule id (`wasm_…`), reported as is, like the Rust proxy does. */
36
+ ruleId: string;
37
+ name: string;
38
+ sha256: string;
39
+ priority: number;
40
+ mode: WasmRuleMode;
41
+ readsReferencedFiles: boolean;
42
+ rego: boolean;
43
+ /** Kept so a worker respawn can recompile without fetching again. */
44
+ bytes: Uint8Array;
45
+ }
46
+ /**
47
+ * Why a control-plane rule version was not loaded (`registry.rs`'s `Refusal`).
48
+ * `kind` is the reason the control plane files the incident under
49
+ * (`RULE_LOAD_FAILURE_REASONS`): a module the worker refuses carries the
50
+ * worker's own reason for it.
51
+ */
52
+ export type CloudRuleRefusal = {
53
+ kind: 'missing';
54
+ } | {
55
+ kind: 'hash_mismatch';
56
+ actual: string;
57
+ } | {
58
+ kind: CompileFailureReason;
59
+ error: string;
60
+ };
61
+ /** One refused version, reported once per hash and reason. */
62
+ export interface CloudRuleRefusalReport {
63
+ descriptor: WasmRuleDescriptor;
64
+ refusal: CloudRuleRefusal;
65
+ /** Whether an earlier version of the rule stays in force. */
66
+ hasPrevious: boolean;
67
+ /** The sentence the incident and the log line carry, in the Rust proxy's words. */
68
+ description: string;
69
+ }
70
+ /**
71
+ * The binary a hash names: its bytes, or `null` when the control plane has
72
+ * none. Throws when the control plane cannot be asked.
73
+ */
74
+ export type FetchRuleBinary = (sha256: string) => Promise<Uint8Array | null>;
75
+ /** What the sync needs from the worker, implemented by `WasmRunner`. */
76
+ export interface CloudRuleBridge extends CompileBridge {
77
+ /** A rule's loaded version changed: whatever the previous version did no longer counts against it. */
78
+ replaced(ruleId: string): void;
79
+ }
80
+ /**
81
+ * Fetches binaries from the control plane's rule store by hash. A 404 is a
82
+ * binary the control plane does not have; any other failure means it could
83
+ * not be asked.
84
+ */
85
+ export declare function fetchRuleBinaryFrom(controlPlaneUrl: string, apiKey: string): FetchRuleBinary;
86
+ /** A refusal as the `wasm_rule_refused` event carries it. */
87
+ export declare function refusalDetail(report: CloudRuleRefusalReport): WasmRuleRefusalDetail;
88
+ /** Whether `bytes` are the binary `sha256` names; case is not significant in hex. */
89
+ export declare function binaryMatches(bytes: Uint8Array, sha256: string): {
90
+ matches: boolean;
91
+ actual: string;
92
+ };
93
+ export declare function describeRefusal(descriptor: WasmRuleDescriptor, refusal: CloudRuleRefusal, hasPrevious: boolean): string;
94
+ export declare class CloudRuleSet {
95
+ private readonly fetchBinary;
96
+ private readonly report;
97
+ private rules;
98
+ /** The descriptor list last applied, serialized; `undefined` until one has been. */
99
+ private appliedKey;
100
+ /** The list of the last attempt, applied or not, and when it ran. */
101
+ private attemptedKey;
102
+ private attemptedAt;
103
+ /** Whether the applied list left a version unloaded, so it is retried. */
104
+ private incomplete;
105
+ private syncing;
106
+ private readonly refusalsReported;
107
+ constructor(fetchBinary: FetchRuleBinary, report: (report: CloudRuleRefusalReport) => void);
108
+ /** Whether a descriptor list has been applied, so the loaded set is the workspace's. */
109
+ isLoaded(): boolean;
110
+ /** The loaded rules, in descriptor order. */
111
+ getRules(): readonly CloudRuleMeta[];
112
+ /**
113
+ * Brings the loaded set in line with `descriptors`.
114
+ *
115
+ * A changed list is applied before this resolves, so the call that follows
116
+ * a policy refresh is judged by the new set. Retrying versions the applied
117
+ * list refused, at most every {@link CLOUD_RETRY_MS}, runs in the
118
+ * background: the loaded set is already the workspace's. A list that could
119
+ * not be applied is retried no sooner either, so an unreachable control
120
+ * plane costs a call one fetch timeout at most every few seconds rather
121
+ * than on every call.
122
+ */
123
+ sync(descriptors: readonly WasmRuleDescriptor[], bridge: CloudRuleBridge): Promise<void>;
124
+ /**
125
+ * Recompiles every loaded rule from its kept bytes — the worker that held
126
+ * them was replaced. Waits for a sync in flight, which may have compiled
127
+ * into the old worker.
128
+ */
129
+ reload(bridge: CompileBridge): Promise<void>;
130
+ private run;
131
+ private apply;
132
+ /** A binary some loaded rule already has: compiled again only when it is new to this rule id. */
133
+ private reuse;
134
+ /** `load_descriptor`: the hash, then the same load checks as a local rule. */
135
+ private load;
136
+ private reportOnce;
137
+ }
138
+ //# sourceMappingURL=cloudRules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloudRules.d.ts","sourceRoot":"","sources":["../../src/wasm/cloudRules.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAGH,OAAO,KAAK,EAAE,kBAAkB,EA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AAO,CAAC,GAAG;YAcG,KAAK;IAyDnB,iGAAiG;YACnF,KAAK;IAYnB,8EAA8E;YAChE,IAAI;IAalB,OAAO,CAAC,UAAU;CAQnB"}
@@ -0,0 +1,242 @@
1
+ /**
2
+ * wasm/cloudRules.ts — the workspace's custom rules from the control plane:
3
+ * the rules uploaded from the dashboard, the CLI or Terraform, which the LLM
4
+ * proxy enforces too.
5
+ *
6
+ * Port of the control-plane half of `packages/proxy/src/wasm/registry.rs`
7
+ * (`ensure_up_to_date`, `load_descriptor`, `report_refusal`). The descriptors
8
+ * arrive with the workspace policy this proxy already fetches (`wasmRules` on
9
+ * `GET /api/v1/sop/rules`, or on the MCP daemon's cached
10
+ * `GET /api/v1/policy/resolve`), so they refresh when the policy does. Each
11
+ * binary is fetched by the SHA-256 its descriptor names, only when no loaded
12
+ * rule already has that hash, and must hash to it before it is compiled:
13
+ * whoever can answer for that hash could otherwise swap a governance rule for
14
+ * one that allows everything.
15
+ *
16
+ * A version that cannot load — binary missing, hash mismatch, or a module the
17
+ * worker refuses — is reported once per hash and reason, and the version of
18
+ * that rule already loaded, if any, keeps enforcing. A control plane that
19
+ * cannot be reached for a binary leaves the whole loaded set as it was, as
20
+ * `registry.rs` does when its fetch fails.
21
+ *
22
+ * @module
23
+ */
24
+ import { createHash } from 'node:crypto';
25
+ import { createStderrLogger as createLogger } from '../stderrLog.js';
26
+ import { HttpStatusError, getBytes } from '../httpJson.js';
27
+ import { MAX_RULE_FILE_BYTES } from './loader.js';
28
+ const log = createLogger('mcp-proxy-wasm-cloud');
29
+ /**
30
+ * Minimum time between attempts after a sync that could not reach the control
31
+ * plane or refused a version — the Rust proxy's 5-second rescan, so a binary
32
+ * published a moment after its descriptor is picked up as quickly there.
33
+ */
34
+ export const CLOUD_RETRY_MS = 5_000;
35
+ /**
36
+ * Fetches binaries from the control plane's rule store by hash. A 404 is a
37
+ * binary the control plane does not have; any other failure means it could
38
+ * not be asked.
39
+ */
40
+ export function fetchRuleBinaryFrom(controlPlaneUrl, apiKey) {
41
+ return async (sha256) => {
42
+ const url = `${controlPlaneUrl}/api/v1/wasm-rules/binaries/${encodeURIComponent(sha256)}`;
43
+ try {
44
+ return await getBytes(url, apiKey, MAX_RULE_FILE_BYTES);
45
+ }
46
+ catch (err) {
47
+ if (err instanceof HttpStatusError && err.status === 404)
48
+ return null;
49
+ throw err;
50
+ }
51
+ };
52
+ }
53
+ /** A refusal as the `wasm_rule_refused` event carries it. */
54
+ export function refusalDetail(report) {
55
+ const { descriptor, refusal } = report;
56
+ return {
57
+ ruleId: descriptor.ruleId,
58
+ name: descriptor.name,
59
+ sha256: descriptor.sha256,
60
+ refusal: refusal.kind,
61
+ ...(refusal.kind === 'hash_mismatch' ? { actualSha256: refusal.actual } : {}),
62
+ previousInForce: report.hasPrevious,
63
+ };
64
+ }
65
+ /** Whether `bytes` are the binary `sha256` names; case is not significant in hex. */
66
+ export function binaryMatches(bytes, sha256) {
67
+ const actual = createHash('sha256').update(bytes).digest('hex');
68
+ return { matches: actual === sha256.toLowerCase(), actual };
69
+ }
70
+ /** What makes two refusals of one version the same report (`Refusal::key`). */
71
+ function refusalKey(refusal) {
72
+ if (refusal.kind === 'hash_mismatch')
73
+ return refusal.actual;
74
+ return refusal.kind;
75
+ }
76
+ export function describeRefusal(descriptor, refusal, hasPrevious) {
77
+ const why = refusal.kind === 'missing'
78
+ ? "its binary is missing from the control plane"
79
+ : refusal.kind === 'hash_mismatch'
80
+ ? `its binary hashes to ${refusal.actual} but its descriptor names ${descriptor.sha256}`
81
+ : `it cannot be loaded: ${refusal.error}`;
82
+ const consequence = hasPrevious
83
+ ? 'The previously loaded version stays in force.'
84
+ : 'No version of this rule has loaded on this proxy, so it enforces nothing until one does.';
85
+ return `WASM rule '${descriptor.name}' (${descriptor.ruleId}) was refused: ${why}. ${consequence}`;
86
+ }
87
+ export class CloudRuleSet {
88
+ fetchBinary;
89
+ report;
90
+ rules = [];
91
+ /** The descriptor list last applied, serialized; `undefined` until one has been. */
92
+ appliedKey;
93
+ /** The list of the last attempt, applied or not, and when it ran. */
94
+ attemptedKey;
95
+ attemptedAt = 0;
96
+ /** Whether the applied list left a version unloaded, so it is retried. */
97
+ incomplete = false;
98
+ syncing = null;
99
+ refusalsReported = new Set();
100
+ constructor(fetchBinary, report) {
101
+ this.fetchBinary = fetchBinary;
102
+ this.report = report;
103
+ }
104
+ /** Whether a descriptor list has been applied, so the loaded set is the workspace's. */
105
+ isLoaded() {
106
+ return this.appliedKey !== undefined;
107
+ }
108
+ /** The loaded rules, in descriptor order. */
109
+ getRules() {
110
+ return this.rules;
111
+ }
112
+ /**
113
+ * Brings the loaded set in line with `descriptors`.
114
+ *
115
+ * A changed list is applied before this resolves, so the call that follows
116
+ * a policy refresh is judged by the new set. Retrying versions the applied
117
+ * list refused, at most every {@link CLOUD_RETRY_MS}, runs in the
118
+ * background: the loaded set is already the workspace's. A list that could
119
+ * not be applied is retried no sooner either, so an unreachable control
120
+ * plane costs a call one fetch timeout at most every few seconds rather
121
+ * than on every call.
122
+ */
123
+ async sync(descriptors, bridge) {
124
+ while (this.syncing)
125
+ await this.syncing;
126
+ const key = JSON.stringify(descriptors);
127
+ const due = Date.now() - this.attemptedAt >= CLOUD_RETRY_MS;
128
+ if (key === this.appliedKey) {
129
+ if (this.incomplete && due)
130
+ void this.run(descriptors, key, bridge);
131
+ return;
132
+ }
133
+ if (key === this.attemptedKey && !due)
134
+ return;
135
+ await this.run(descriptors, key, bridge);
136
+ }
137
+ /**
138
+ * Recompiles every loaded rule from its kept bytes — the worker that held
139
+ * them was replaced. Waits for a sync in flight, which may have compiled
140
+ * into the old worker.
141
+ */
142
+ async reload(bridge) {
143
+ while (this.syncing)
144
+ await this.syncing;
145
+ for (const rule of this.rules)
146
+ await bridge.compile(rule.ruleId, rule.bytes);
147
+ }
148
+ run(descriptors, key, bridge) {
149
+ const run = this.apply(descriptors, key, bridge)
150
+ .catch((err) => {
151
+ // The worker itself failed under the sync; the loaded set is unchanged
152
+ // and the next sync tries again.
153
+ log.warn({ action: 'wasm_cloud_sync_failed', err: err.message }, "Syncing the workspace's custom rules failed");
154
+ })
155
+ .finally(() => {
156
+ if (this.syncing === run)
157
+ this.syncing = null;
158
+ });
159
+ this.syncing = run;
160
+ return run;
161
+ }
162
+ async apply(descriptors, key, bridge) {
163
+ this.attemptedKey = key;
164
+ this.attemptedAt = Date.now();
165
+ const previousBySha = new Map(this.rules.map((r) => [r.sha256, r]));
166
+ const previousByRule = new Map(this.rules.map((r) => [r.ruleId, r]));
167
+ // Every binary no loaded rule already has, fetched before anything
168
+ // changes: a control plane that cannot be reached leaves the loaded set
169
+ // exactly as it was.
170
+ const wanted = [...new Set(descriptors.map((d) => d.sha256).filter((sha) => !previousBySha.has(sha)))];
171
+ let fetched;
172
+ try {
173
+ fetched = new Map(await Promise.all(wanted.map(async (sha) => [sha, await this.fetchBinary(sha)])));
174
+ }
175
+ catch (err) {
176
+ log.warn({ action: 'wasm_cloud_fetch_failed', err: err.message, loaded: this.rules.length }, this.isLoaded()
177
+ ? "Could not fetch the workspace's custom rules; the loaded set stays in force"
178
+ : "Could not fetch the workspace's custom rules; none have loaded yet");
179
+ return;
180
+ }
181
+ const next = [];
182
+ let incomplete = false;
183
+ for (const descriptor of descriptors) {
184
+ const reuse = previousBySha.get(descriptor.sha256);
185
+ const outcome = reuse
186
+ ? await this.reuse(descriptor, reuse, bridge)
187
+ : await this.load(descriptor, fetched.get(descriptor.sha256) ?? null, bridge);
188
+ if ('kind' in outcome) {
189
+ incomplete = true;
190
+ const previous = previousByRule.get(descriptor.ruleId);
191
+ this.reportOnce(descriptor, outcome, previous !== undefined);
192
+ if (previous)
193
+ next.push(previous);
194
+ continue;
195
+ }
196
+ if (previousByRule.get(descriptor.ruleId)?.sha256 !== descriptor.sha256)
197
+ bridge.replaced(descriptor.ruleId);
198
+ next.push(outcome);
199
+ }
200
+ // A rule no longer listed — deleted, or switched off — stops enforcing.
201
+ const kept = new Set(next.map((r) => r.ruleId));
202
+ for (const rule of this.rules) {
203
+ if (!kept.has(rule.ruleId))
204
+ bridge.remove(rule.ruleId);
205
+ }
206
+ this.rules = next;
207
+ this.appliedKey = key;
208
+ this.incomplete = incomplete;
209
+ log.info({ action: 'wasm_cloud_rules_loaded', rules: next.length, listed: descriptors.length }, "Workspace's custom rules loaded");
210
+ }
211
+ /** A binary some loaded rule already has: compiled again only when it is new to this rule id. */
212
+ async reuse(descriptor, loaded, bridge) {
213
+ if (loaded.ruleId !== descriptor.ruleId) {
214
+ const result = await bridge.compile(descriptor.ruleId, loaded.bytes);
215
+ if (!result.ok)
216
+ return { kind: result.reason, error: result.error };
217
+ }
218
+ return { ...loaded, ...descriptor };
219
+ }
220
+ /** `load_descriptor`: the hash, then the same load checks as a local rule. */
221
+ async load(descriptor, bytes, bridge) {
222
+ if (!bytes)
223
+ return { kind: 'missing' };
224
+ const { matches, actual } = binaryMatches(bytes, descriptor.sha256);
225
+ if (!matches)
226
+ return { kind: 'hash_mismatch', actual };
227
+ const result = await bridge.compile(descriptor.ruleId, bytes);
228
+ if (!result.ok)
229
+ return { kind: result.reason, error: result.error };
230
+ return { ...descriptor, readsReferencedFiles: result.readsReferencedFiles, rego: result.rego, bytes };
231
+ }
232
+ reportOnce(descriptor, refusal, hasPrevious) {
233
+ const id = [descriptor.sha256, refusalKey(refusal)].join('\u0000');
234
+ if (this.refusalsReported.has(id))
235
+ return;
236
+ this.refusalsReported.add(id);
237
+ const description = describeRefusal(descriptor, refusal, hasPrevious);
238
+ log.error({ action: 'wasm_cloud_rule_refused', ruleId: descriptor.ruleId, sha256: descriptor.sha256, refusal: refusal.kind }, description);
239
+ this.report({ descriptor, refusal, hasPrevious, description });
240
+ }
241
+ }
242
+ //# sourceMappingURL=cloudRules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloudRules.js","sourceRoot":"","sources":["../../src/wasm/cloudRules.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EA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CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QAClE,IAAI,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,EAAE,CAAC;YAAE,OAAM;QACzC,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;QAC7B,MAAM,WAAW,GAAG,eAAe,CAAC,UAAU,EAAE,OAAO,EAAE,WAAW,CAAC,CAAA;QACrE,GAAG,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,yBAAyB,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,EAAE,EAAE,WAAW,CAAC,CAAA;QAC1I,IAAI,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC,CAAA;IAChE,CAAC;CACF"}
@@ -61,6 +61,8 @@ export interface LoadedRuleMeta {
61
61
  * currently-loaded rule without re-reading the directory from disk. */
62
62
  bytes: Uint8Array;
63
63
  }
64
+ /** Why a module did not compile or load: the reasons a compile can reach, never a missing binary or a hash mismatch. */
65
+ export type CompileFailureReason = Exclude<RuleLoadFailureReason, 'missing' | 'hash_mismatch'>;
64
66
  export type CompileOutcome = {
65
67
  ok: true;
66
68
  readsReferencedFiles: boolean;
@@ -70,7 +72,7 @@ export type CompileOutcome = {
70
72
  | {
71
73
  ok: false;
72
74
  error: string;
73
- reason: RuleLoadFailureReason;
75
+ reason: CompileFailureReason;
74
76
  unsupportedImports?: string[];
75
77
  };
76
78
  /** What `WasmLoader` needs from the worker to load/unload a rule — implemented by `WasmRunner`. */
@@ -1 +1 @@
1
- {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/wasm/loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAKH,OAAO,KAAK,EAAE,qBAAqB,EA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O,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;YAC1C,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,GAAG,CAAC,IAAI,CACN,EAAE,MAAM,EAAE,sBAAsB,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAG,GAAa,CAAC,OAAO,EAAE,EAC/E,oEAAoE,CACrE,CAAA;gBACD,SAAQ;YACV,CAAC;YAED,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;YAClD,IAAI,MAAM,CAAC,EAAE,EAAE,CAAC;gBACd,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAA;gBAClD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE;oBACxB,MAAM;oBACN,QAAQ;oBACR,IAAI;oBACJ,QAAQ;oBACR,oBAAoB,EAAE,MAAM,CAAC,oBAAoB;oBACjD,IAAI,EAAE,MAAM,CAAC,IAAI;oBACjB,KAAK;iBACN,CAAC,CAAA;YACJ,CAAC;iBAAM,CAAC;gBACN,GAAG,CAAC,IAAI,CACN;oBACE,MAAM,EAAE,sBAAsB;oBAC9B,IAAI,EAAE,QAAQ;oBACd,MAAM,EAAE,MAAM,CAAC,MAAM;oBACrB,KAAK,EAAE,MAAM,CAAC,KAAK;oBACnB,kBAAkB,EAAE,MAAM,CAAC,kBAAkB;iBAC9C,EACD,oEAAoE,CACrE,CAAA;gBACD,mEAAmE;gBACnE,oEAAoE;YACtE,CAAC;QACH,CAAC;QAED,IAAI,CAAC,UAAU,GAAG,aAAa,CAAA;IACjC,CAAC;CACF"}
@@ -1,9 +1,17 @@
1
1
  /**
2
2
  * wasm/runner.ts — WasmRunner: owns the one dedicated `worker_threads`
3
- * Worker (worker.ts), the local-rules loader (loader.ts), and the
4
- * evaluate-all-rules union logic ported from
5
- * `packages/proxy/src/wasm/registry.rs`'s `evaluate_inner` (most-restrictive-
6
- * wins, short-circuit on a block, carry the first reask through).
3
+ * Worker (worker.ts), the local-rules loader (loader.ts), the workspace's
4
+ * control-plane rules (cloudRules.ts), and the evaluate-all-rules union logic
5
+ * ported from `packages/proxy/src/wasm/registry.rs`'s `evaluate_inner`
6
+ * (most-restrictive-wins, short-circuit on a block, carry the first reask
7
+ * through).
8
+ *
9
+ * Both sources run as one list in priority order, lower first; on a tie a
10
+ * control-plane rule runs before a local one, as in `registry.rs`. Local rules
11
+ * are `local:<file name>`; a control-plane rule keeps the control plane's id,
12
+ * the one the LLM proxy and the dashboard name it by. A control-plane rule in
13
+ * `SHADOW` mode is evaluated like any other and logged, and never decides the
14
+ * call — not even when it reaches no verdict.
7
15
  *
8
16
  * ## Divergences from the Rust runner (all recorded as TD entries)
9
17
  *
@@ -35,7 +43,9 @@
35
43
  *
36
44
  * @module
37
45
  */
38
- import { type CompileBridge, type CompileOutcome } from './loader.js';
46
+ import type { WasmRuleDescriptor } from '@intutic/shared-types';
47
+ import { type CompileOutcome } from './loader.js';
48
+ import type { CloudRuleBridge, CloudRuleSet } from './cloudRules.js';
39
49
  import { type WasmContextInput } from './context.js';
40
50
  /**
41
51
  * A native rule's deadline: a backstop for stalls the instruction budget
@@ -98,7 +108,18 @@ export type WasmVerdict = {
98
108
  ruleId: string;
99
109
  stop: RuleStop;
100
110
  };
101
- export declare class WasmRunner implements CompileBridge {
111
+ /**
112
+ * One shadowed rule's outcome on one call, as the LLM proxy reports it on a
113
+ * trace (`registry.rs`'s `ShadowReport`): the bypasses are reported too,
114
+ * because they are the denominator promotion divides by.
115
+ */
116
+ export interface ShadowReport {
117
+ ruleId: string;
118
+ /** False when the rule allowed the call; true for a block, a reask, a hold, or no verdict. */
119
+ wouldAct: boolean;
120
+ }
121
+ export declare class WasmRunner implements CloudRuleBridge {
122
+ private readonly cloud?;
102
123
  private readonly loader;
103
124
  private worker;
104
125
  private nextRequestId;
@@ -107,17 +128,43 @@ export declare class WasmRunner implements CompileBridge {
107
128
  /** The worker replacing one that missed a deadline, while its rules recompile. */
108
129
  private respawning;
109
130
  private quarantined;
110
- constructor(dirOverride?: string);
131
+ /**
132
+ * @param dirOverride - the local rules directory (see `resolveWasmDir`).
133
+ * @param cloud - the workspace's control-plane rules; absent where there is
134
+ * no control plane to fetch them from (tests, local-only use).
135
+ */
136
+ constructor(dirOverride?: string, cloud?: CloudRuleSet | undefined);
111
137
  /** The resolved local rules directory, for logging. */
112
138
  getDir(): string;
113
- /** Currently loaded rule ids (`local:<file name>`), priority order — observability for callers/tests. */
139
+ /** Currently loaded rule ids, in evaluation order — observability for callers/tests. */
114
140
  getLoadedRuleIds(): string[];
141
+ /**
142
+ * Every loaded rule in evaluation order: by priority, and on a tie the
143
+ * control-plane rules first (a stable sort over cloud-then-local, as
144
+ * `registry.rs` sorts).
145
+ */
146
+ private activeRules;
147
+ /**
148
+ * Brings the control-plane rules in line with the descriptors the policy
149
+ * carries. `undefined` — no policy from the control plane yet — leaves them
150
+ * as they are. See `CloudRuleSet.sync` for when this waits.
151
+ */
152
+ syncCloudRules(descriptors: readonly WasmRuleDescriptor[] | undefined): Promise<void>;
153
+ /**
154
+ * Whether the workspace's control-plane rules are known: a descriptor list
155
+ * has been applied (or this runner has no control plane to ask). Until then,
156
+ * a call is judged without them, which the interceptor allows only under
157
+ * the fail-open setting.
158
+ */
159
+ cloudRulesLoaded(): boolean;
115
160
  private ensureWorker;
116
161
  /** Send one message and wait for its correlated reply, or `null` on timeout. */
117
162
  private send;
118
163
  private allocId;
119
164
  compile(ruleId: string, bytes: Uint8Array): Promise<CompileOutcome>;
120
165
  remove(ruleId: string): void;
166
+ /** A control-plane rule's version changed: the old version's runaways do not count against the new one. */
167
+ replaced(ruleId: string): void;
121
168
  /**
122
169
  * Rescans `~/.intutic/wasm/` and (re)compiles anything changed. Also
123
170
  * releases every quarantined rule — "quarantined until the next
@@ -154,8 +201,15 @@ export declare class WasmRunner implements CompileBridge {
154
201
  *
155
202
  * A quarantined rule (see {@link countRunaway}) refuses at once, without
156
203
  * anything being evaluated, until the next rescan.
204
+ *
205
+ * A `SHADOW` rule is evaluated in its place and decides nothing: what it
206
+ * would have done, a refusal for reaching no verdict included, leaves the
207
+ * call as the other rules decide it. Each evaluation is appended to
208
+ * `shadowOut`, the evidence promotion out of shadow is judged on, and a
209
+ * would-act is logged. A quarantined one is skipped, and reported as
210
+ * nothing, since nothing ran.
157
211
  */
158
- evaluate(input: WasmContextInput): Promise<WasmVerdict>;
212
+ evaluate(input: WasmContextInput, shadowOut?: ShadowReport[]): Promise<WasmVerdict>;
159
213
  /**
160
214
  * The referenced-files table for this evaluation. With no
161
215
  * `INTUTIC_WASM_MANIFEST_ROOT` the table is empty and every read refuses.
@@ -1 +1 @@
1
- {"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../../src/wasm/runner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAOH,OAAO,EAA8B,KAAK,aAAa,EAAE,KAAK,cAAc,EAAE,MAAM,aAAa,CAAA;AACjG,OAAO,EAAoC,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAKtF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,mBAAmB,OAAQ,CAAA;AAExC;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,QAAS,CAAA;AAM9C;;;GAGG;AACH,eAAO,MAAM,wBAAwB,IAAI,CAAA;AAEzC;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG,UAAU,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,GAAG,aAAa,CAAA;AAEjF,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,GACjB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACjD;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,M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