@neuroverseos/governance 0.4.3 → 0.5.1

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 (68) hide show
  1. package/README.md +189 -0
  2. package/dist/adapters/autoresearch.js +2 -2
  3. package/dist/adapters/deep-agents.js +2 -2
  4. package/dist/adapters/express.js +2 -2
  5. package/dist/adapters/github.js +2 -2
  6. package/dist/adapters/index.js +23 -21
  7. package/dist/adapters/langchain.js +2 -2
  8. package/dist/adapters/mentraos.js +8 -6
  9. package/dist/adapters/openai.js +2 -2
  10. package/dist/adapters/openclaw.js +2 -2
  11. package/dist/{add-XSANI3FK.js → add-JP7TC2K3.js} +1 -1
  12. package/dist/admin/index.cjs +2214 -0
  13. package/dist/admin/index.d.cts +362 -0
  14. package/dist/admin/index.d.ts +362 -0
  15. package/dist/admin/index.js +703 -0
  16. package/dist/{build-EGBGZFIJ.js → build-THUEYMVT.js} +5 -5
  17. package/dist/{chunk-YJ34R5NB.js → chunk-5RAQ5DZW.js} +3 -3
  18. package/dist/{chunk-RDA7ISWC.js → chunk-6UPEUMJ2.js} +3 -3
  19. package/dist/chunk-7UU7V3AD.js +447 -0
  20. package/dist/{chunk-ZEIT2QLM.js → chunk-EK77AJAH.js} +22 -4
  21. package/dist/{chunk-3S5AD4AB.js → chunk-FGOSKQDE.js} +3 -3
  22. package/dist/{chunk-GTPV2XGO.js → chunk-GJ6LM4JZ.js} +1 -441
  23. package/dist/chunk-H3REGQRI.js +107 -0
  24. package/dist/{chunk-J2IZBHXJ.js → chunk-LAKUB76X.js} +3 -3
  25. package/dist/{chunk-FVOGUCB6.js → chunk-R23T5SZG.js} +3 -3
  26. package/dist/{chunk-A7SHG75T.js → chunk-RF2L5SYG.js} +3 -3
  27. package/dist/{chunk-QMVQ6KPL.js → chunk-TL4DLMMW.js} +3 -3
  28. package/dist/{chunk-AV7XJJWK.js → chunk-TZBERHFM.js} +3 -3
  29. package/dist/{chunk-3AYKQHYI.js → chunk-UZBW44KD.js} +3 -3
  30. package/dist/{chunk-FS2UUJJO.js → chunk-XPMZB46F.js} +3 -3
  31. package/dist/cli/neuroverse.cjs +962 -284
  32. package/dist/cli/neuroverse.js +46 -22
  33. package/dist/cli/plan.js +1 -1
  34. package/dist/cli/run.cjs +242 -139
  35. package/dist/cli/run.js +23 -3
  36. package/dist/{demo-6OQYWRR6.js → demo-N5K4VXJW.js} +3 -3
  37. package/dist/{derive-7Y7YWVLU.js → derive-5LOMN7GO.js} +4 -4
  38. package/dist/{equity-penalties-NVBAB5WL.js → equity-penalties-PYCJ3Q4U.js} +6 -6
  39. package/dist/{explain-HDFN4ION.js → explain-42TVC3QD.js} +1 -1
  40. package/dist/{guard-6KSCWT2W.js → guard-TPYDFG6V.js} +16 -4
  41. package/dist/{improve-2PWGGO5B.js → improve-HLZGJ54Z.js} +3 -3
  42. package/dist/index.cjs +19 -1
  43. package/dist/index.d.cts +2 -0
  44. package/dist/index.d.ts +2 -0
  45. package/dist/index.js +27 -27
  46. package/dist/keygen-BSZH3NM2.js +77 -0
  47. package/dist/{lens-MHMUDCMQ.js → lens-NFGZHD76.js} +1 -1
  48. package/dist/{mcp-server-TNIWZ7B5.js → mcp-server-5XXNG6VC.js} +2 -2
  49. package/dist/migrate-NH5PVMX4.js +221 -0
  50. package/dist/{playground-3FLDGBET.js → playground-2EU5CFIH.js} +4 -4
  51. package/dist/{redteam-HV6LMKEH.js → redteam-VK6OVHAE.js} +3 -3
  52. package/dist/{session-XZP2754M.js → session-NGA4DUPL.js} +2 -2
  53. package/dist/sign-RRELHKWM.js +11 -0
  54. package/dist/{simulate-VT437EEL.js → simulate-4YNOBMES.js} +1 -1
  55. package/dist/{test-4WTX6RKQ.js → test-HDBPMQTG.js} +3 -3
  56. package/dist/{validate-M52DX22Y.js → validate-6MFQZ2EG.js} +1 -1
  57. package/dist/verify-6AVTWX75.js +151 -0
  58. package/dist/{world-O4HTQPDP.js → world-H5WVURKU.js} +1 -1
  59. package/dist/{world-loader-YTYFOP7D.js → world-loader-J47PCPDZ.js} +1 -1
  60. package/package.json +22 -10
  61. package/dist/{behavioral-SLW7ALEK.js → behavioral-SPWPGYXL.js} +3 -3
  62. package/dist/{bootstrap-2OW5ZLBL.js → bootstrap-IP5QMC3Q.js} +3 -3
  63. package/dist/{chunk-I4RTIMLX.js → chunk-EQUAWNXW.js} +0 -0
  64. package/dist/{chunk-DA5MHFRR.js → chunk-NTHXZAW4.js} +3 -3
  65. package/dist/{chunk-FHXXD2TI.js → chunk-QZ666FCV.js} +6 -6
  66. package/dist/{configure-ai-LL3VAPQW.js → configure-ai-5MP5DWTT.js} +3 -3
  67. package/dist/{decision-flow-3K4D72G4.js → decision-flow-IJPNMVQK.js} +3 -3
  68. /package/dist/{doctor-EC5OYTI3.js → doctor-Q5APJOTS.js} +0 -0
@@ -2,19 +2,19 @@ import {
2
2
  DeriveInputError,
3
3
  DeriveProviderError,
4
4
  deriveWorld
5
- } from "./chunk-FHXXD2TI.js";
5
+ } from "./chunk-QZ666FCV.js";
6
6
  import {
7
7
  DERIVE_EXIT_CODES
8
8
  } from "./chunk-FMSTRBBS.js";
9
- import "./chunk-INWQHLPS.js";
10
9
  import "./chunk-OT6PXH54.js";
10
+ import "./chunk-INWQHLPS.js";
11
11
  import "./chunk-7P3S7MAY.js";
12
- import {
13
- emitWorldDefinition
14
- } from "./chunk-YPCVY4GS.js";
15
12
  import {
16
13
  parseWorldMarkdown
17
14
  } from "./chunk-3NZMMSOW.js";
15
+ import {
16
+ emitWorldDefinition
17
+ } from "./chunk-YPCVY4GS.js";
18
18
  import "./chunk-QWGCMQQD.js";
19
19
 
20
20
  // src/cli/build.ts
@@ -4,12 +4,12 @@ import {
4
4
  extractScope,
5
5
  trackPlanProgress
6
6
  } from "./chunk-5U2MQO5P.js";
7
+ import {
8
+ loadWorld
9
+ } from "./chunk-EQUAWNXW.js";
7
10
  import {
8
11
  evaluateGuard
9
12
  } from "./chunk-ZAF6JH23.js";
10
- import {
11
- loadWorld
12
- } from "./chunk-I4RTIMLX.js";
13
13
 
14
14
  // src/engine/tool-classifier.ts
15
15
  var TOOL_CATEGORY_MAP = {
@@ -1,9 +1,9 @@
1
+ import {
2
+ loadWorld
3
+ } from "./chunk-EQUAWNXW.js";
1
4
  import {
2
5
  evaluateGuard
3
6
  } from "./chunk-ZAF6JH23.js";
4
- import {
5
- loadWorld
6
- } from "./chunk-I4RTIMLX.js";
7
7
 
8
8
  // src/adapters/express.ts
9
9
  function methodToCategory(method) {
@@ -0,0 +1,447 @@
1
+ import {
2
+ MENTRA_KNOWN_INTENTS,
3
+ getMentraIntent,
4
+ isAIIntent
5
+ } from "./chunk-GJ6LM4JZ.js";
6
+ import {
7
+ buildEngineOptions,
8
+ trackPlanProgress
9
+ } from "./chunk-5U2MQO5P.js";
10
+ import {
11
+ loadWorld
12
+ } from "./chunk-EQUAWNXW.js";
13
+ import {
14
+ evaluateGuard
15
+ } from "./chunk-ZAF6JH23.js";
16
+
17
+ // src/adapters/mentraos.ts
18
+ var DEFAULT_USER_RULES = {
19
+ aiDataPolicy: "declared_only",
20
+ aiActionPolicy: "confirm_all",
21
+ aiPurchasePolicy: "confirm_each",
22
+ aiMessagingPolicy: "confirm_each",
23
+ dataRetentionPolicy: "app_declared",
24
+ maxAIProviders: 5
25
+ };
26
+ function evaluateUserRules(intent, rules, appContext) {
27
+ const def = getMentraIntent(intent);
28
+ if (!def) return null;
29
+ if (def.domain === "ai_data" && intent !== "ai_retain_session_data") {
30
+ if (rules.aiDataPolicy === "block_all") {
31
+ return {
32
+ verdict: {
33
+ status: "BLOCK",
34
+ ruleId: "user-rule-ai-data-block",
35
+ reason: `User rules block all AI data sends. Intent: ${intent}`,
36
+ evidence: makeEvidence("user-rule-ai-data-block")
37
+ },
38
+ reason: "User has blocked all AI data sends"
39
+ };
40
+ }
41
+ if (rules.aiDataPolicy === "confirm_each") {
42
+ return {
43
+ verdict: {
44
+ status: "PAUSE",
45
+ ruleId: "user-rule-ai-data-confirm",
46
+ reason: `User rules require confirmation for every AI data send. Intent: ${intent}`,
47
+ evidence: makeEvidence("user-rule-ai-data-confirm")
48
+ },
49
+ reason: "User requires confirmation for each AI data send"
50
+ };
51
+ }
52
+ if (!appContext.aiProviderDeclared) {
53
+ return {
54
+ verdict: {
55
+ status: "BLOCK",
56
+ ruleId: "user-rule-undeclared-provider",
57
+ reason: `App "${appContext.appId}" has not declared its AI provider. User rules require declared providers only.`,
58
+ evidence: makeEvidence("user-rule-undeclared-provider")
59
+ },
60
+ reason: "App has not declared its AI provider"
61
+ };
62
+ }
63
+ }
64
+ if (intent === "ai_retain_session_data") {
65
+ if (rules.dataRetentionPolicy === "never") {
66
+ return {
67
+ verdict: {
68
+ status: "BLOCK",
69
+ ruleId: "user-rule-no-retention",
70
+ reason: `User rules block all data retention. App "${appContext.appId}" cannot retain session data.`,
71
+ evidence: makeEvidence("user-rule-no-retention")
72
+ },
73
+ reason: "User has blocked all data retention"
74
+ };
75
+ }
76
+ if (!appContext.dataRetentionOptedIn) {
77
+ return {
78
+ verdict: {
79
+ status: "BLOCK",
80
+ ruleId: "user-rule-retention-no-optin",
81
+ reason: `User has not opted in to data retention for app "${appContext.appId}".`,
82
+ evidence: makeEvidence("user-rule-retention-no-optin")
83
+ },
84
+ reason: "User has not opted in to data retention for this app"
85
+ };
86
+ }
87
+ }
88
+ if (intent === "ai_auto_purchase") {
89
+ if (rules.aiPurchasePolicy === "block_all") {
90
+ return {
91
+ verdict: {
92
+ status: "BLOCK",
93
+ ruleId: "user-rule-no-purchases",
94
+ reason: "User rules block all AI-initiated purchases.",
95
+ evidence: makeEvidence("user-rule-no-purchases")
96
+ },
97
+ reason: "User has blocked all AI purchases"
98
+ };
99
+ }
100
+ return {
101
+ verdict: {
102
+ status: "PAUSE",
103
+ ruleId: "user-rule-purchase-confirm",
104
+ reason: `AI wants to make a purchase. User rules require per-transaction confirmation.`,
105
+ evidence: makeEvidence("user-rule-purchase-confirm")
106
+ },
107
+ reason: "User requires per-transaction confirmation for AI purchases"
108
+ };
109
+ }
110
+ if (intent === "ai_auto_respond_message") {
111
+ if (rules.aiMessagingPolicy === "block_all") {
112
+ return {
113
+ verdict: {
114
+ status: "BLOCK",
115
+ ruleId: "user-rule-no-messaging",
116
+ reason: "User rules block all AI-initiated messaging.",
117
+ evidence: makeEvidence("user-rule-no-messaging")
118
+ },
119
+ reason: "User has blocked all AI messaging"
120
+ };
121
+ }
122
+ return {
123
+ verdict: {
124
+ status: "PAUSE",
125
+ ruleId: "user-rule-message-confirm",
126
+ reason: `AI wants to send a message on your behalf. User rules require per-message confirmation.`,
127
+ evidence: makeEvidence("user-rule-message-confirm")
128
+ },
129
+ reason: "User requires per-message confirmation for AI messaging"
130
+ };
131
+ }
132
+ if (def.domain === "ai_action" && intent !== "ai_auto_purchase" && intent !== "ai_auto_respond_message") {
133
+ if (rules.aiActionPolicy === "block_all") {
134
+ return {
135
+ verdict: {
136
+ status: "BLOCK",
137
+ ruleId: "user-rule-no-ai-actions",
138
+ reason: `User rules block all AI auto-actions. Intent: ${intent}`,
139
+ evidence: makeEvidence("user-rule-no-ai-actions")
140
+ },
141
+ reason: "User has blocked all AI auto-actions"
142
+ };
143
+ }
144
+ if (rules.aiActionPolicy === "confirm_all") {
145
+ return {
146
+ verdict: {
147
+ status: "PAUSE",
148
+ ruleId: "user-rule-action-confirm",
149
+ reason: `AI wants to take action: ${intent}. User rules require confirmation.`,
150
+ evidence: makeEvidence("user-rule-action-confirm")
151
+ },
152
+ reason: "User requires confirmation for all AI actions"
153
+ };
154
+ }
155
+ if (def.base_risk === "high" || def.base_risk === "critical") {
156
+ return {
157
+ verdict: {
158
+ status: "PAUSE",
159
+ ruleId: "user-rule-high-risk-confirm",
160
+ reason: `AI wants to take high-risk action: ${intent}. User rules require confirmation for high-risk actions.`,
161
+ evidence: makeEvidence("user-rule-high-risk-confirm")
162
+ },
163
+ reason: "User requires confirmation for high-risk AI actions"
164
+ };
165
+ }
166
+ }
167
+ if (intent === "ai_share_with_third_party") {
168
+ return {
169
+ verdict: {
170
+ status: "PAUSE",
171
+ ruleId: "user-rule-third-party-confirm",
172
+ reason: `App wants to share your data with a third party beyond its declared AI provider. Confirmation required.`,
173
+ evidence: makeEvidence("user-rule-third-party-confirm")
174
+ },
175
+ reason: "Third-party data sharing requires user confirmation"
176
+ };
177
+ }
178
+ return null;
179
+ }
180
+ function makeEvidence(ruleId) {
181
+ return {
182
+ worldId: "mentraos-user-rules",
183
+ worldName: "MentraOS User Rules",
184
+ worldVersion: "1.0.0",
185
+ evaluatedAt: Date.now(),
186
+ invariantsSatisfied: 0,
187
+ invariantsTotal: 0,
188
+ guardsMatched: [ruleId],
189
+ rulesMatched: [],
190
+ enforcementLevel: "strict"
191
+ };
192
+ }
193
+ var MentraGovernedExecutor = class {
194
+ world;
195
+ engineOptions;
196
+ options;
197
+ planState;
198
+ planCallbacks;
199
+ _userRules;
200
+ _emergencyOverride = false;
201
+ _emergencyActivatedAt = null;
202
+ _spatialSession = null;
203
+ constructor(world, options = {}, userRules = DEFAULT_USER_RULES) {
204
+ this.world = world;
205
+ this.options = options;
206
+ this._userRules = userRules;
207
+ this.engineOptions = buildEngineOptions(options, options.plan);
208
+ this.planState = { activePlan: options.plan, engineOptions: this.engineOptions };
209
+ this.planCallbacks = {
210
+ onPlanProgress: options.onPlanProgress,
211
+ onPlanComplete: options.onPlanComplete
212
+ };
213
+ }
214
+ /** Get the current user rules */
215
+ get userRules() {
216
+ return this._userRules;
217
+ }
218
+ /** Update user rules at runtime (e.g., user changes preferences in phone app) */
219
+ updateUserRules(rules) {
220
+ this._userRules = { ...this._userRules, ...rules };
221
+ }
222
+ /**
223
+ * Activate emergency override — user is king.
224
+ *
225
+ * Bypasses all NeuroVerse governance rules (user rules, platform rules).
226
+ * Does NOT bypass MentraOS platform constraints (hardware capability,
227
+ * declared permissions, session isolation). You can't override physics.
228
+ *
229
+ * Returns the timestamp of activation for audit trail.
230
+ */
231
+ activateEmergencyOverride() {
232
+ this._emergencyOverride = true;
233
+ this._emergencyActivatedAt = Date.now();
234
+ this.engineOptions = { ...this.engineOptions, emergencyOverride: true };
235
+ return this._emergencyActivatedAt;
236
+ }
237
+ /**
238
+ * Deactivate emergency override — governance resumes.
239
+ * Returns the duration the override was active (ms).
240
+ */
241
+ deactivateEmergencyOverride() {
242
+ if (!this._emergencyOverride || !this._emergencyActivatedAt) {
243
+ return 0;
244
+ }
245
+ const duration = Date.now() - this._emergencyActivatedAt;
246
+ this._emergencyOverride = false;
247
+ this._emergencyActivatedAt = null;
248
+ this.engineOptions = { ...this.engineOptions, emergencyOverride: false };
249
+ return duration;
250
+ }
251
+ /** Whether emergency override is currently active */
252
+ get isEmergencyOverrideActive() {
253
+ return this._emergencyOverride;
254
+ }
255
+ /** Timestamp when emergency override was activated, or null */
256
+ get emergencyActivatedAt() {
257
+ return this._emergencyActivatedAt;
258
+ }
259
+ // ── Spatial Governance (optional) ────────────────────────────────────────
260
+ /**
261
+ * Attach a spatial session to this executor.
262
+ *
263
+ * When attached, intents are evaluated against the spatial context
264
+ * (zone rules + handshake rules) AFTER user rules but BEFORE
265
+ * hardware and platform checks. This is Layer 1.5.
266
+ *
267
+ * Pass null to detach (e.g., when leaving a zone).
268
+ */
269
+ setSpatialSession(session) {
270
+ this._spatialSession = session;
271
+ }
272
+ /** Whether a spatial session is currently active */
273
+ get hasSpatialSession() {
274
+ return this._spatialSession !== null;
275
+ }
276
+ /** Get the current spatial session description */
277
+ get spatialDescription() {
278
+ return this._spatialSession?.description ?? null;
279
+ }
280
+ /**
281
+ * Evaluate an intent against user rules + platform world.
282
+ *
283
+ * Three-layer evaluation:
284
+ * 0. Emergency override — if active, skip governance (layers 1 + 1.5 + 3),
285
+ * but STILL enforce platform constraints (layer 2)
286
+ * 1. User rules check — personal governance override, can BLOCK or PAUSE
287
+ * 1.5. Spatial governance — zone + handshake rules (optional, temporary)
288
+ * ↑ ONLY ACTIVE when a spatial session is attached
289
+ * 2. Hardware capability check — validates glasses support
290
+ * ↑ THIS IS A PLATFORM CONSTRAINT — never overridden
291
+ * 3. Platform guard engine — full world rule evaluation
292
+ */
293
+ evaluate(intent, appContext) {
294
+ const intentDef = getMentraIntent(intent);
295
+ const glassesModel = appContext.glassesModel;
296
+ if (!this._emergencyOverride) {
297
+ const userRulesResult = evaluateUserRules(intent, this._userRules, appContext);
298
+ if (userRulesResult) {
299
+ const allowed2 = false;
300
+ const requiresConfirmation2 = userRulesResult.verdict.status === "PAUSE";
301
+ const result2 = {
302
+ allowed: requiresConfirmation2 ? false : false,
303
+ requiresConfirmation: requiresConfirmation2,
304
+ verdict: userRulesResult.verdict,
305
+ intentDef,
306
+ userRulesResult: { reason: userRulesResult.reason },
307
+ appContext,
308
+ decidingLayer: "user_rules"
309
+ };
310
+ if (requiresConfirmation2) {
311
+ this.options.onPause?.(result2);
312
+ } else {
313
+ this.options.onBlock?.(result2);
314
+ }
315
+ this.options.onEvaluate?.(result2);
316
+ return result2;
317
+ }
318
+ }
319
+ if (!this._emergencyOverride && this._spatialSession) {
320
+ const spatialResult = this._spatialSession.evaluate(intent);
321
+ if (!spatialResult.allowed && !spatialResult.requiresConfirmation) {
322
+ const verdict2 = {
323
+ status: "BLOCK",
324
+ ruleId: "spatial-zone-rule",
325
+ reason: spatialResult.reason,
326
+ evidence: makeEvidence("spatial-zone-rule")
327
+ };
328
+ const result2 = {
329
+ allowed: false,
330
+ requiresConfirmation: false,
331
+ verdict: verdict2,
332
+ intentDef,
333
+ appContext,
334
+ decidingLayer: "spatial"
335
+ };
336
+ this.options.onBlock?.(result2);
337
+ this.options.onEvaluate?.(result2);
338
+ return result2;
339
+ }
340
+ if (spatialResult.requiresConfirmation) {
341
+ const verdict2 = {
342
+ status: "PAUSE",
343
+ ruleId: "spatial-zone-rule",
344
+ reason: spatialResult.reason,
345
+ evidence: makeEvidence("spatial-zone-rule")
346
+ };
347
+ const result2 = {
348
+ allowed: false,
349
+ requiresConfirmation: true,
350
+ verdict: verdict2,
351
+ intentDef,
352
+ appContext,
353
+ decidingLayer: "spatial"
354
+ };
355
+ this.options.onPause?.(result2);
356
+ this.options.onEvaluate?.(result2);
357
+ return result2;
358
+ }
359
+ }
360
+ if (intentDef && glassesModel && !intentDef.supported_glasses.includes(glassesModel)) {
361
+ const verdict2 = {
362
+ status: "BLOCK",
363
+ ruleId: "hardware-capability",
364
+ reason: `${intent} not supported on ${glassesModel} \u2014 requires: ${intentDef.supported_glasses.join(", ")}`,
365
+ evidence: {
366
+ worldId: this.world.world?.world_id ?? "unknown",
367
+ worldName: this.world.world?.name ?? "unknown",
368
+ worldVersion: this.world.world?.version ?? "unknown",
369
+ evaluatedAt: Date.now(),
370
+ invariantsSatisfied: 0,
371
+ invariantsTotal: 0,
372
+ guardsMatched: ["hardware-capability"],
373
+ rulesMatched: [],
374
+ enforcementLevel: "strict"
375
+ }
376
+ };
377
+ const result2 = {
378
+ allowed: false,
379
+ requiresConfirmation: false,
380
+ verdict: verdict2,
381
+ intentDef,
382
+ appContext,
383
+ decidingLayer: "hardware"
384
+ };
385
+ this.options.onBlock?.(result2);
386
+ this.options.onEvaluate?.(result2);
387
+ return result2;
388
+ }
389
+ const event = {
390
+ intent,
391
+ tool: intentDef?.sdk_method ?? intent,
392
+ scope: intentDef?.domain ?? "unknown",
393
+ actionCategory: intentDef?.action_category,
394
+ riskLevel: intentDef?.base_risk ?? "medium",
395
+ irreversible: intentDef ? !intentDef.reversible : false,
396
+ args: {
397
+ app_id: appContext.appId,
398
+ ai_provider_declared: appContext.aiProviderDeclared ? 1 : 0,
399
+ ai_data_types_sent: appContext.aiDataTypesSent,
400
+ ai_retention_opted_in: appContext.dataRetentionOptedIn ? 1 : 0,
401
+ glasses_model: glassesModel ?? "unknown",
402
+ is_ai_intent: isAIIntent(intent) ? 1 : 0
403
+ }
404
+ };
405
+ const verdict = evaluateGuard(event, this.world, this.engineOptions);
406
+ const allowed = verdict.status === "ALLOW" || verdict.status === "REWARD";
407
+ const requiresConfirmation = verdict.status === "PAUSE";
408
+ if (allowed) {
409
+ trackPlanProgress(event, this.planState, this.planCallbacks);
410
+ }
411
+ const result = {
412
+ allowed,
413
+ requiresConfirmation,
414
+ verdict,
415
+ intentDef,
416
+ appContext,
417
+ decidingLayer: this._emergencyOverride ? "emergency_override" : "platform"
418
+ };
419
+ if (!allowed && !requiresConfirmation) {
420
+ this.options.onBlock?.(result);
421
+ }
422
+ if (requiresConfirmation) {
423
+ this.options.onPause?.(result);
424
+ }
425
+ this.options.onEvaluate?.(result);
426
+ return result;
427
+ }
428
+ /** Get all known intents for this adapter */
429
+ get knownIntents() {
430
+ return MENTRA_KNOWN_INTENTS;
431
+ }
432
+ };
433
+ async function createMentraGovernedExecutor(worldPath, options = {}, userRules = DEFAULT_USER_RULES) {
434
+ const world = await loadWorld(worldPath);
435
+ return new MentraGovernedExecutor(world, options, userRules);
436
+ }
437
+ function createMentraGovernedExecutorFromWorld(world, options = {}, userRules = DEFAULT_USER_RULES) {
438
+ return new MentraGovernedExecutor(world, options, userRules);
439
+ }
440
+
441
+ export {
442
+ DEFAULT_USER_RULES,
443
+ evaluateUserRules,
444
+ MentraGovernedExecutor,
445
+ createMentraGovernedExecutor,
446
+ createMentraGovernedExecutorFromWorld
447
+ };
@@ -4,12 +4,12 @@ import {
4
4
  createAgentState,
5
5
  tickAgentStates
6
6
  } from "./chunk-D2UCV5AK.js";
7
+ import {
8
+ loadWorld
9
+ } from "./chunk-EQUAWNXW.js";
7
10
  import {
8
11
  evaluateGuard
9
12
  } from "./chunk-ZAF6JH23.js";
10
- import {
11
- loadWorld
12
- } from "./chunk-I4RTIMLX.js";
13
13
  import {
14
14
  advancePlan,
15
15
  evaluatePlan,
@@ -20,7 +20,9 @@ import {
20
20
  async function defaultToolExecutor(name, args) {
21
21
  return `Tool "${name}" executed successfully with args: ${JSON.stringify(args)}`;
22
22
  }
23
- var SessionManager = class {
23
+ var SessionManager = class _SessionManager {
24
+ /** Maximum unique agent IDs tracked before eviction. Prevents unbounded memory growth. */
25
+ static MAX_AGENTS = 1e4;
24
26
  config;
25
27
  state;
26
28
  engineOptions;
@@ -84,6 +86,16 @@ var SessionManager = class {
84
86
  if (verdict.status === "REWARD" && verdict.reward) {
85
87
  agentState = applyReward(agentState, verdict.reward, verdict.ruleId ?? "unknown");
86
88
  }
89
+ if (this.state.agentStates.size >= _SessionManager.MAX_AGENTS && !this.state.agentStates.has(event.roleId)) {
90
+ const oldest = this.state.agentStates.keys().next().value;
91
+ if (oldest !== void 0) {
92
+ this.state.agentStates.delete(oldest);
93
+ }
94
+ process.stderr.write(
95
+ `[neuroverse] Warning: agent state map at capacity (${_SessionManager.MAX_AGENTS}), evicted oldest entry
96
+ `
97
+ );
98
+ }
87
99
  this.state.agentStates.set(event.roleId, agentState);
88
100
  }
89
101
  this.config.onVerdict?.(verdict, event);
@@ -194,11 +206,17 @@ async function runPipeMode(config) {
194
206
  process.stderr.write(`[neuroverse] Plan: ${state.plan.plan_id} (${state.plan.objective})
195
207
  `);
196
208
  }
209
+ const MAX_BUFFER_SIZE = 1e6;
197
210
  return new Promise((resolve, reject) => {
198
211
  let buffer = "";
199
212
  process.stdin.setEncoding("utf-8");
200
213
  process.stdin.on("data", (chunk) => {
201
214
  buffer += chunk;
215
+ if (buffer.length > MAX_BUFFER_SIZE) {
216
+ process.stderr.write("[neuroverse] Warning: pipe buffer exceeded 1MB, resetting\n");
217
+ buffer = "";
218
+ return;
219
+ }
202
220
  const lines = buffer.split("\n");
203
221
  buffer = lines.pop() ?? "";
204
222
  for (const line of lines) {
@@ -3,12 +3,12 @@ import {
3
3
  buildEngineOptions,
4
4
  trackPlanProgress
5
5
  } from "./chunk-5U2MQO5P.js";
6
+ import {
7
+ loadWorld
8
+ } from "./chunk-EQUAWNXW.js";
6
9
  import {
7
10
  evaluateGuard
8
11
  } from "./chunk-ZAF6JH23.js";
9
- import {
10
- loadWorld
11
- } from "./chunk-I4RTIMLX.js";
12
12
 
13
13
  // src/adapters/github.ts
14
14
  var GitHubGovernanceBlockedError = class extends GovernanceBlockedError {