agentic-qe 2.8.0 → 2.8.2

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 (226) hide show
  1. package/CHANGELOG.md +148 -0
  2. package/README.md +1 -1
  3. package/dist/agents/BaseAgent.d.ts +329 -0
  4. package/dist/agents/BaseAgent.d.ts.map +1 -1
  5. package/dist/agents/BaseAgent.js +657 -0
  6. package/dist/agents/BaseAgent.js.map +1 -1
  7. package/dist/cli/commands/supabase/index.d.ts +20 -0
  8. package/dist/cli/commands/supabase/index.d.ts.map +1 -0
  9. package/dist/cli/commands/supabase/index.js +632 -0
  10. package/dist/cli/commands/supabase/index.js.map +1 -0
  11. package/dist/cli/index.js +3 -0
  12. package/dist/cli/index.js.map +1 -1
  13. package/dist/code-intelligence/embeddings/EmbeddingCacheFactory.d.ts +135 -0
  14. package/dist/code-intelligence/embeddings/EmbeddingCacheFactory.d.ts.map +1 -0
  15. package/dist/code-intelligence/embeddings/EmbeddingCacheFactory.js +301 -0
  16. package/dist/code-intelligence/embeddings/EmbeddingCacheFactory.js.map +1 -0
  17. package/dist/code-intelligence/embeddings/NomicEmbedder.d.ts +78 -6
  18. package/dist/code-intelligence/embeddings/NomicEmbedder.d.ts.map +1 -1
  19. package/dist/code-intelligence/embeddings/NomicEmbedder.js +162 -21
  20. package/dist/code-intelligence/embeddings/NomicEmbedder.js.map +1 -1
  21. package/dist/code-intelligence/embeddings/backends/MemoryBackend.d.ts +59 -0
  22. package/dist/code-intelligence/embeddings/backends/MemoryBackend.d.ts.map +1 -0
  23. package/dist/code-intelligence/embeddings/backends/MemoryBackend.js +173 -0
  24. package/dist/code-intelligence/embeddings/backends/MemoryBackend.js.map +1 -0
  25. package/dist/code-intelligence/embeddings/backends/RedisBackend.d.ts +50 -0
  26. package/dist/code-intelligence/embeddings/backends/RedisBackend.d.ts.map +1 -0
  27. package/dist/code-intelligence/embeddings/backends/RedisBackend.js +279 -0
  28. package/dist/code-intelligence/embeddings/backends/RedisBackend.js.map +1 -0
  29. package/dist/code-intelligence/embeddings/backends/SQLiteBackend.d.ts +64 -0
  30. package/dist/code-intelligence/embeddings/backends/SQLiteBackend.d.ts.map +1 -0
  31. package/dist/code-intelligence/embeddings/backends/SQLiteBackend.js +314 -0
  32. package/dist/code-intelligence/embeddings/backends/SQLiteBackend.js.map +1 -0
  33. package/dist/code-intelligence/embeddings/backends/index.d.ts +16 -0
  34. package/dist/code-intelligence/embeddings/backends/index.d.ts.map +1 -0
  35. package/dist/code-intelligence/embeddings/backends/index.js +28 -0
  36. package/dist/code-intelligence/embeddings/backends/index.js.map +1 -0
  37. package/dist/code-intelligence/embeddings/backends/types.d.ts +177 -0
  38. package/dist/code-intelligence/embeddings/backends/types.d.ts.map +1 -0
  39. package/dist/code-intelligence/embeddings/backends/types.js +30 -0
  40. package/dist/code-intelligence/embeddings/backends/types.js.map +1 -0
  41. package/dist/code-intelligence/embeddings/index.d.ts +7 -0
  42. package/dist/code-intelligence/embeddings/index.d.ts.map +1 -1
  43. package/dist/code-intelligence/embeddings/index.js +16 -1
  44. package/dist/code-intelligence/embeddings/index.js.map +1 -1
  45. package/dist/core/memory/HNSWVectorMemory.js +1 -1
  46. package/dist/infrastructure/index.d.ts +15 -0
  47. package/dist/infrastructure/index.d.ts.map +1 -0
  48. package/dist/infrastructure/index.js +44 -0
  49. package/dist/infrastructure/index.js.map +1 -0
  50. package/dist/infrastructure/network/AgentRateLimiter.d.ts +59 -0
  51. package/dist/infrastructure/network/AgentRateLimiter.d.ts.map +1 -0
  52. package/dist/infrastructure/network/AgentRateLimiter.js +186 -0
  53. package/dist/infrastructure/network/AgentRateLimiter.js.map +1 -0
  54. package/dist/infrastructure/network/AuditLogger.d.ts +102 -0
  55. package/dist/infrastructure/network/AuditLogger.d.ts.map +1 -0
  56. package/dist/infrastructure/network/AuditLogger.js +284 -0
  57. package/dist/infrastructure/network/AuditLogger.js.map +1 -0
  58. package/dist/infrastructure/network/DomainWhitelist.d.ts +111 -0
  59. package/dist/infrastructure/network/DomainWhitelist.d.ts.map +1 -0
  60. package/dist/infrastructure/network/DomainWhitelist.js +216 -0
  61. package/dist/infrastructure/network/DomainWhitelist.js.map +1 -0
  62. package/dist/infrastructure/network/NetworkPolicyManager.d.ts +97 -0
  63. package/dist/infrastructure/network/NetworkPolicyManager.d.ts.map +1 -0
  64. package/dist/infrastructure/network/NetworkPolicyManager.js +309 -0
  65. package/dist/infrastructure/network/NetworkPolicyManager.js.map +1 -0
  66. package/dist/infrastructure/network/index.d.ts +19 -0
  67. package/dist/infrastructure/network/index.d.ts.map +1 -0
  68. package/dist/infrastructure/network/index.js +46 -0
  69. package/dist/infrastructure/network/index.js.map +1 -0
  70. package/dist/infrastructure/network/policies/default-policies.d.ts +78 -0
  71. package/dist/infrastructure/network/policies/default-policies.d.ts.map +1 -0
  72. package/dist/infrastructure/network/policies/default-policies.js +312 -0
  73. package/dist/infrastructure/network/policies/default-policies.js.map +1 -0
  74. package/dist/infrastructure/network/types.d.ts +214 -0
  75. package/dist/infrastructure/network/types.d.ts.map +1 -0
  76. package/dist/infrastructure/network/types.js +25 -0
  77. package/dist/infrastructure/network/types.js.map +1 -0
  78. package/dist/infrastructure/sandbox/ResourceMonitor.d.ts +124 -0
  79. package/dist/infrastructure/sandbox/ResourceMonitor.d.ts.map +1 -0
  80. package/dist/infrastructure/sandbox/ResourceMonitor.js +305 -0
  81. package/dist/infrastructure/sandbox/ResourceMonitor.js.map +1 -0
  82. package/dist/infrastructure/sandbox/SandboxManager.d.ts +122 -0
  83. package/dist/infrastructure/sandbox/SandboxManager.d.ts.map +1 -0
  84. package/dist/infrastructure/sandbox/SandboxManager.js +527 -0
  85. package/dist/infrastructure/sandbox/SandboxManager.js.map +1 -0
  86. package/dist/infrastructure/sandbox/index.d.ts +18 -0
  87. package/dist/infrastructure/sandbox/index.d.ts.map +1 -0
  88. package/dist/infrastructure/sandbox/index.js +38 -0
  89. package/dist/infrastructure/sandbox/index.js.map +1 -0
  90. package/dist/infrastructure/sandbox/profiles/agent-profiles.d.ts +53 -0
  91. package/dist/infrastructure/sandbox/profiles/agent-profiles.d.ts.map +1 -0
  92. package/dist/infrastructure/sandbox/profiles/agent-profiles.js +433 -0
  93. package/dist/infrastructure/sandbox/profiles/agent-profiles.js.map +1 -0
  94. package/dist/infrastructure/sandbox/types.d.ts +227 -0
  95. package/dist/infrastructure/sandbox/types.d.ts.map +1 -0
  96. package/dist/infrastructure/sandbox/types.js +63 -0
  97. package/dist/infrastructure/sandbox/types.js.map +1 -0
  98. package/dist/mcp/handlers/NewDomainToolsHandler.d.ts +8 -8
  99. package/dist/mcp/handlers/NewDomainToolsHandler.d.ts.map +1 -1
  100. package/dist/mcp/handlers/NewDomainToolsHandler.js.map +1 -1
  101. package/dist/mcp/handlers/ruvector/RuVectorHandler.d.ts +54 -0
  102. package/dist/mcp/handlers/ruvector/RuVectorHandler.d.ts.map +1 -0
  103. package/dist/mcp/handlers/ruvector/RuVectorHandler.js +325 -0
  104. package/dist/mcp/handlers/ruvector/RuVectorHandler.js.map +1 -0
  105. package/dist/mcp/handlers/ruvector/index.d.ts +5 -0
  106. package/dist/mcp/handlers/ruvector/index.d.ts.map +1 -0
  107. package/dist/mcp/handlers/ruvector/index.js +9 -0
  108. package/dist/mcp/handlers/ruvector/index.js.map +1 -0
  109. package/dist/mcp/server-instructions.d.ts +1 -1
  110. package/dist/mcp/server-instructions.js +1 -1
  111. package/dist/mcp/server.d.ts.map +1 -1
  112. package/dist/mcp/server.js +100 -22
  113. package/dist/mcp/server.js.map +1 -1
  114. package/dist/nervous-system/adapters/BTSPAdapter.d.ts +342 -0
  115. package/dist/nervous-system/adapters/BTSPAdapter.d.ts.map +1 -0
  116. package/dist/nervous-system/adapters/BTSPAdapter.js +494 -0
  117. package/dist/nervous-system/adapters/BTSPAdapter.js.map +1 -0
  118. package/dist/nervous-system/adapters/CircadianController.d.ts +560 -0
  119. package/dist/nervous-system/adapters/CircadianController.d.ts.map +1 -0
  120. package/dist/nervous-system/adapters/CircadianController.js +882 -0
  121. package/dist/nervous-system/adapters/CircadianController.js.map +1 -0
  122. package/dist/nervous-system/adapters/GlobalWorkspaceAdapter.d.ts +337 -0
  123. package/dist/nervous-system/adapters/GlobalWorkspaceAdapter.d.ts.map +1 -0
  124. package/dist/nervous-system/adapters/GlobalWorkspaceAdapter.js +532 -0
  125. package/dist/nervous-system/adapters/GlobalWorkspaceAdapter.js.map +1 -0
  126. package/dist/nervous-system/adapters/HdcMemoryAdapter.d.ts +444 -0
  127. package/dist/nervous-system/adapters/HdcMemoryAdapter.d.ts.map +1 -0
  128. package/dist/nervous-system/adapters/HdcMemoryAdapter.js +715 -0
  129. package/dist/nervous-system/adapters/HdcMemoryAdapter.js.map +1 -0
  130. package/dist/nervous-system/adapters/ReflexLayer.d.ts +231 -0
  131. package/dist/nervous-system/adapters/ReflexLayer.d.ts.map +1 -0
  132. package/dist/nervous-system/adapters/ReflexLayer.js +309 -0
  133. package/dist/nervous-system/adapters/ReflexLayer.js.map +1 -0
  134. package/dist/nervous-system/index.d.ts +25 -0
  135. package/dist/nervous-system/index.d.ts.map +1 -0
  136. package/dist/nervous-system/index.js +80 -0
  137. package/dist/nervous-system/index.js.map +1 -0
  138. package/dist/nervous-system/integration/BTSPLearningEngine.d.ts +266 -0
  139. package/dist/nervous-system/integration/BTSPLearningEngine.d.ts.map +1 -0
  140. package/dist/nervous-system/integration/BTSPLearningEngine.js +587 -0
  141. package/dist/nervous-system/integration/BTSPLearningEngine.js.map +1 -0
  142. package/dist/nervous-system/integration/CircadianAgent.d.ts +389 -0
  143. package/dist/nervous-system/integration/CircadianAgent.d.ts.map +1 -0
  144. package/dist/nervous-system/integration/CircadianAgent.js +696 -0
  145. package/dist/nervous-system/integration/CircadianAgent.js.map +1 -0
  146. package/dist/nervous-system/integration/HybridPatternStore.d.ts +244 -0
  147. package/dist/nervous-system/integration/HybridPatternStore.d.ts.map +1 -0
  148. package/dist/nervous-system/integration/HybridPatternStore.js +622 -0
  149. package/dist/nervous-system/integration/HybridPatternStore.js.map +1 -0
  150. package/dist/nervous-system/integration/NervousSystemEnhancement.d.ts +459 -0
  151. package/dist/nervous-system/integration/NervousSystemEnhancement.d.ts.map +1 -0
  152. package/dist/nervous-system/integration/NervousSystemEnhancement.js +921 -0
  153. package/dist/nervous-system/integration/NervousSystemEnhancement.js.map +1 -0
  154. package/dist/nervous-system/integration/WorkspaceAgent.d.ts +398 -0
  155. package/dist/nervous-system/integration/WorkspaceAgent.d.ts.map +1 -0
  156. package/dist/nervous-system/integration/WorkspaceAgent.js +722 -0
  157. package/dist/nervous-system/integration/WorkspaceAgent.js.map +1 -0
  158. package/dist/nervous-system/integration/index.d.ts +22 -0
  159. package/dist/nervous-system/integration/index.d.ts.map +1 -0
  160. package/dist/nervous-system/integration/index.js +44 -0
  161. package/dist/nervous-system/integration/index.js.map +1 -0
  162. package/dist/nervous-system/persistence/BTSPSerializer.d.ts +96 -0
  163. package/dist/nervous-system/persistence/BTSPSerializer.d.ts.map +1 -0
  164. package/dist/nervous-system/persistence/BTSPSerializer.js +223 -0
  165. package/dist/nervous-system/persistence/BTSPSerializer.js.map +1 -0
  166. package/dist/nervous-system/persistence/CircadianSerializer.d.ts +90 -0
  167. package/dist/nervous-system/persistence/CircadianSerializer.d.ts.map +1 -0
  168. package/dist/nervous-system/persistence/CircadianSerializer.js +239 -0
  169. package/dist/nervous-system/persistence/CircadianSerializer.js.map +1 -0
  170. package/dist/nervous-system/persistence/HdcSerializer.d.ts +100 -0
  171. package/dist/nervous-system/persistence/HdcSerializer.d.ts.map +1 -0
  172. package/dist/nervous-system/persistence/HdcSerializer.js +259 -0
  173. package/dist/nervous-system/persistence/HdcSerializer.js.map +1 -0
  174. package/dist/nervous-system/persistence/INervousSystemStore.d.ts +208 -0
  175. package/dist/nervous-system/persistence/INervousSystemStore.d.ts.map +1 -0
  176. package/dist/nervous-system/persistence/INervousSystemStore.js +11 -0
  177. package/dist/nervous-system/persistence/INervousSystemStore.js.map +1 -0
  178. package/dist/nervous-system/persistence/NervousSystemPersistenceManager.d.ts +187 -0
  179. package/dist/nervous-system/persistence/NervousSystemPersistenceManager.d.ts.map +1 -0
  180. package/dist/nervous-system/persistence/NervousSystemPersistenceManager.js +411 -0
  181. package/dist/nervous-system/persistence/NervousSystemPersistenceManager.js.map +1 -0
  182. package/dist/nervous-system/persistence/SQLiteNervousSystemStore.d.ts +98 -0
  183. package/dist/nervous-system/persistence/SQLiteNervousSystemStore.d.ts.map +1 -0
  184. package/dist/nervous-system/persistence/SQLiteNervousSystemStore.js +510 -0
  185. package/dist/nervous-system/persistence/SQLiteNervousSystemStore.js.map +1 -0
  186. package/dist/nervous-system/persistence/index.d.ts +22 -0
  187. package/dist/nervous-system/persistence/index.d.ts.map +1 -0
  188. package/dist/nervous-system/persistence/index.js +45 -0
  189. package/dist/nervous-system/persistence/index.js.map +1 -0
  190. package/dist/nervous-system/wasm-loader.d.ts +52 -0
  191. package/dist/nervous-system/wasm-loader.d.ts.map +1 -0
  192. package/dist/nervous-system/wasm-loader.js +188 -0
  193. package/dist/nervous-system/wasm-loader.js.map +1 -0
  194. package/dist/persistence/HybridPersistenceProvider.d.ts +184 -0
  195. package/dist/persistence/HybridPersistenceProvider.d.ts.map +1 -0
  196. package/dist/persistence/HybridPersistenceProvider.js +1086 -0
  197. package/dist/persistence/HybridPersistenceProvider.js.map +1 -0
  198. package/dist/persistence/IPersistenceProvider.d.ts +657 -0
  199. package/dist/persistence/IPersistenceProvider.d.ts.map +1 -0
  200. package/dist/persistence/IPersistenceProvider.js +11 -0
  201. package/dist/persistence/IPersistenceProvider.js.map +1 -0
  202. package/dist/persistence/SupabaseConfig.d.ts +176 -0
  203. package/dist/persistence/SupabaseConfig.d.ts.map +1 -0
  204. package/dist/persistence/SupabaseConfig.js +277 -0
  205. package/dist/persistence/SupabaseConfig.js.map +1 -0
  206. package/dist/persistence/SupabasePersistenceProvider.d.ts +143 -0
  207. package/dist/persistence/SupabasePersistenceProvider.d.ts.map +1 -0
  208. package/dist/persistence/SupabasePersistenceProvider.js +959 -0
  209. package/dist/persistence/SupabasePersistenceProvider.js.map +1 -0
  210. package/dist/persistence/adapters/CodeIntelligenceSyncAdapter.d.ts +213 -0
  211. package/dist/persistence/adapters/CodeIntelligenceSyncAdapter.d.ts.map +1 -0
  212. package/dist/persistence/adapters/CodeIntelligenceSyncAdapter.js +468 -0
  213. package/dist/persistence/adapters/CodeIntelligenceSyncAdapter.js.map +1 -0
  214. package/dist/persistence/adapters/MemorySyncAdapter.d.ts +115 -0
  215. package/dist/persistence/adapters/MemorySyncAdapter.d.ts.map +1 -0
  216. package/dist/persistence/adapters/MemorySyncAdapter.js +291 -0
  217. package/dist/persistence/adapters/MemorySyncAdapter.js.map +1 -0
  218. package/dist/persistence/adapters/index.d.ts +11 -0
  219. package/dist/persistence/adapters/index.d.ts.map +1 -0
  220. package/dist/persistence/adapters/index.js +20 -0
  221. package/dist/persistence/adapters/index.js.map +1 -0
  222. package/dist/persistence/index.d.ts +14 -0
  223. package/dist/persistence/index.d.ts.map +1 -1
  224. package/dist/persistence/index.js +36 -1
  225. package/dist/persistence/index.js.map +1 -1
  226. package/package.json +7 -1
@@ -31,6 +31,13 @@ Object.defineProperty(exports, "isSwarmMemoryManager", { enumerable: true, get:
31
31
  Object.defineProperty(exports, "validateLearningConfig", { enumerable: true, get: function () { return utils_1.validateLearningConfig; } });
32
32
  // Code Intelligence Context (Wave 6 - Knowledge Graph Integration)
33
33
  const KnowledgeGraphContextBuilder_js_1 = require("./context/KnowledgeGraphContextBuilder.js");
34
+ const NervousSystemEnhancement_js_1 = require("../nervous-system/integration/NervousSystemEnhancement.js");
35
+ // Nervous System Persistence (Wave 7.1 - State Persistence)
36
+ const NervousSystemPersistenceManager_js_1 = require("../nervous-system/persistence/NervousSystemPersistenceManager.js");
37
+ const NetworkPolicyManager_js_1 = require("../infrastructure/network/NetworkPolicyManager.js");
38
+ const default_policies_js_1 = require("../infrastructure/network/policies/default-policies.js");
39
+ const SandboxManager_js_1 = require("../infrastructure/sandbox/SandboxManager.js");
40
+ const agent_profiles_js_1 = require("../infrastructure/sandbox/profiles/agent-profiles.js");
34
41
  class BaseAgent extends events_1.EventEmitter {
35
42
  constructor(config) {
36
43
  super();
@@ -38,6 +45,11 @@ class BaseAgent extends events_1.EventEmitter {
38
45
  this.performanceMetrics = { tasksCompleted: 0, averageExecutionTime: 0, errorCount: 0, lastActivity: new Date() };
39
46
  this.federatedInitialized = false;
40
47
  this.patternStoreInitialized = false;
48
+ this.nervousSystemEnhanced = false;
49
+ this.networkPolicyInitialized = false;
50
+ this.networkPolicyOwned = false; // true if we created the manager (not shared)
51
+ this.sandboxInitialized = false;
52
+ this.sandboxOwned = false; // true if we created the manager (not shared)
41
53
  this.agentId = { id: config.id || (0, utils_1.generateAgentId)(config.type), type: config.type, created: new Date() };
42
54
  this.capabilities = new Map((config.capabilities || []).map(cap => [cap.name, cap]));
43
55
  this.context = config.context;
@@ -65,6 +77,14 @@ class BaseAgent extends events_1.EventEmitter {
65
77
  };
66
78
  // Code Intelligence configuration (Wave 6 - Knowledge Graph Integration)
67
79
  this.codeIntelligenceConfig = config.codeIntelligence;
80
+ // Nervous System configuration (Wave 7 - Bio-Inspired Intelligence)
81
+ this.nervousSystemConfig = config.nervousSystem;
82
+ // Network Policy configuration (SP-3 - Issue #146)
83
+ // Default enabled for security, opt-out available
84
+ this.networkPolicyConfig = config.networkPolicy ?? { enabled: true };
85
+ // Sandbox configuration (SP-1 - Issue #146)
86
+ // Default disabled (opt-in) - requires Docker infrastructure
87
+ this.sandboxConfig = config.sandbox ?? { enabled: false };
68
88
  // Early validation (Issue #137)
69
89
  const validation = (0, utils_1.validateLearningConfig)(config);
70
90
  if (!validation.valid && validation.warning) {
@@ -133,6 +153,12 @@ class BaseAgent extends events_1.EventEmitter {
133
153
  await this.initializePatternStore();
134
154
  // Initialize Code Intelligence Context Builder (Wave 6)
135
155
  await this.initializeCodeIntelligence();
156
+ // Initialize Nervous System (Wave 7 - Bio-Inspired Intelligence)
157
+ await this.initializeNervousSystem();
158
+ // Initialize Network Policy (SP-3 - Issue #146)
159
+ await this.initializeNetworkPolicy();
160
+ // Initialize Sandbox (SP-1 - Issue #146)
161
+ await this.initializeSandbox();
136
162
  await this.initializeComponents();
137
163
  await this.executeHook('post-initialization');
138
164
  this.coordinator.emitEvent('agent.initialized', { agentId: this.agentId });
@@ -189,6 +215,9 @@ class BaseAgent extends events_1.EventEmitter {
189
215
  await this.cleanupLLM(); // Phase 0: Cleanup LLM resources
190
216
  await this.cleanupFederated(); // Phase 0 M0.5: Cleanup federated learning
191
217
  await this.cleanupPatternStore(); // Phase 0.5: Cleanup pattern store
218
+ await this.cleanupNervousSystem(); // Wave 7: Cleanup nervous system
219
+ await this.cleanupNetworkPolicy(); // SP-3: Cleanup network policy
220
+ await this.cleanupSandbox(); // SP-1: Cleanup sandbox container
192
221
  this.coordinator.clearAllHandlers();
193
222
  },
194
223
  onPostTermination: async () => {
@@ -1424,6 +1453,634 @@ class BaseAgent extends events_1.EventEmitter {
1424
1453
  this.federatedManager = undefined;
1425
1454
  }
1426
1455
  }
1456
+ // ============================================
1457
+ // Nervous System Methods (Wave 7 - Bio-Inspired Intelligence)
1458
+ // ============================================
1459
+ /**
1460
+ * Initialize Nervous System for bio-inspired intelligence
1461
+ *
1462
+ * Enables:
1463
+ * - HDC-accelerated pattern storage (50ns binding operations)
1464
+ * - BTSP one-shot learning from failures (vs 10+ examples with RL)
1465
+ * - Global Workspace attention coordination (Miller's Law: 7±2 items)
1466
+ * - Circadian duty cycling (5-50x compute savings)
1467
+ */
1468
+ async initializeNervousSystem() {
1469
+ if (!this.nervousSystemConfig) {
1470
+ return;
1471
+ }
1472
+ // Skip if no features are enabled
1473
+ const hasEnabledFeature = this.nervousSystemConfig.enableHdcPatterns ||
1474
+ this.nervousSystemConfig.enableOneShotLearning ||
1475
+ this.nervousSystemConfig.enableWorkspaceCoordination ||
1476
+ this.nervousSystemConfig.enableCircadianCycling;
1477
+ if (!hasEnabledFeature) {
1478
+ return;
1479
+ }
1480
+ try {
1481
+ // Enhance this agent with nervous system capabilities
1482
+ const enhanced = await (0, NervousSystemEnhancement_js_1.enhanceWithNervousSystem)(this, this.nervousSystemConfig);
1483
+ // Store the methods for access
1484
+ this.nervousSystemMethods = enhanced;
1485
+ this.nervousSystemEnhanced = true;
1486
+ this.logger.info(`[${this.agentId.id}] Nervous System initialized with: ` +
1487
+ `HDC=${!!this.nervousSystemConfig.enableHdcPatterns}, ` +
1488
+ `BTSP=${!!this.nervousSystemConfig.enableOneShotLearning}, ` +
1489
+ `Workspace=${!!this.nervousSystemConfig.enableWorkspaceCoordination}, ` +
1490
+ `Circadian=${!!this.nervousSystemConfig.enableCircadianCycling}`);
1491
+ // Wave 7.1: Initialize persistence and restore prior state
1492
+ try {
1493
+ this.nervousSystemPersistence = await (0, NervousSystemPersistenceManager_js_1.getSharedPersistenceManager)();
1494
+ await (0, NervousSystemEnhancement_js_1.restoreNervousSystemState)(this, this.nervousSystemPersistence);
1495
+ this.logger.debug(`[${this.agentId.id}] Nervous System state restored from persistence`);
1496
+ }
1497
+ catch (persistError) {
1498
+ this.logger.debug(`[${this.agentId.id}] No prior nervous system state to restore:`, persistError.message);
1499
+ // Not an error - agent starts with fresh state
1500
+ }
1501
+ }
1502
+ catch (error) {
1503
+ this.logger.warn(`[${this.agentId.id}] Nervous System initialization failed:`, error.message);
1504
+ // Don't throw - agent can work without nervous system (graceful degradation)
1505
+ }
1506
+ }
1507
+ /**
1508
+ * Check if nervous system is enabled
1509
+ */
1510
+ hasNervousSystem() {
1511
+ return this.nervousSystemEnhanced && this.nervousSystemMethods !== undefined;
1512
+ }
1513
+ /**
1514
+ * Get nervous system statistics
1515
+ *
1516
+ * Returns comprehensive stats for HDC patterns, BTSP learning,
1517
+ * workspace coordination, and circadian cycling.
1518
+ */
1519
+ getNervousSystemStats() {
1520
+ if (!this.nervousSystemMethods) {
1521
+ return null;
1522
+ }
1523
+ return this.nervousSystemMethods.getNervousSystemStats();
1524
+ }
1525
+ // === HDC Pattern Methods ===
1526
+ /**
1527
+ * Store a pattern using HDC acceleration (50ns binding)
1528
+ *
1529
+ * Uses Hyperdimensional Computing for sub-microsecond pattern binding,
1530
+ * enabling 1000x faster pattern storage than traditional methods.
1531
+ *
1532
+ * @param pattern - The test pattern to store
1533
+ */
1534
+ async storePatternHdc(pattern) {
1535
+ if (!this.nervousSystemMethods?.storePatternHdc) {
1536
+ throw new Error(`[${this.agentId.id}] HDC Pattern Store not available - enable nervousSystem.enableHdcPatterns`);
1537
+ }
1538
+ await this.nervousSystemMethods.storePatternHdc(pattern);
1539
+ }
1540
+ /**
1541
+ * Search patterns using HDC acceleration
1542
+ *
1543
+ * Uses hypervector similarity for pre-filtering, then HNSW for precision.
1544
+ * Achieves O(1) candidate selection vs O(log n) for pure HNSW.
1545
+ *
1546
+ * @param embedding - Query embedding vector
1547
+ * @param k - Number of results to return
1548
+ * @returns Array of matching patterns with similarity scores
1549
+ */
1550
+ async searchPatternsHdc(embedding, k = 10) {
1551
+ if (!this.nervousSystemMethods?.searchPatternsHdc) {
1552
+ return [];
1553
+ }
1554
+ return this.nervousSystemMethods.searchPatternsHdc(embedding, k);
1555
+ }
1556
+ // === BTSP One-Shot Learning Methods ===
1557
+ /**
1558
+ * Learn from a single task failure using BTSP (Behavioral Timescale Synaptic Plasticity)
1559
+ *
1560
+ * Unlike traditional RL which requires 10+ examples, BTSP enables one-shot learning
1561
+ * from a single failure, dramatically reducing time-to-learning.
1562
+ *
1563
+ * @param failure - Information about the task failure
1564
+ */
1565
+ async learnOneShot(failure) {
1566
+ if (!this.nervousSystemMethods?.learnOneShot) {
1567
+ throw new Error(`[${this.agentId.id}] BTSP Learning not available - enable nervousSystem.enableOneShotLearning`);
1568
+ }
1569
+ await this.nervousSystemMethods.learnOneShot(failure);
1570
+ }
1571
+ /**
1572
+ * Recall a strategy based on task state using BTSP associative memory
1573
+ *
1574
+ * Uses one-shot learned patterns for instant strategy recall with
1575
+ * high confidence (vs gradual Q-value learning).
1576
+ *
1577
+ * @param state - Current task state
1578
+ * @returns Strategy recommendation or null if no match
1579
+ */
1580
+ async recallStrategy(state) {
1581
+ if (!this.nervousSystemMethods?.recallStrategy) {
1582
+ return null;
1583
+ }
1584
+ return this.nervousSystemMethods.recallStrategy(state);
1585
+ }
1586
+ // === Workspace Coordination Methods ===
1587
+ /**
1588
+ * Broadcast an item to the Global Workspace for attention competition
1589
+ *
1590
+ * Uses biological Global Workspace Theory where only 7±2 items can
1591
+ * occupy conscious attention at once, enabling focused coordination.
1592
+ *
1593
+ * @param item - The workspace item to broadcast
1594
+ * @returns Whether broadcast succeeded
1595
+ */
1596
+ async broadcastToWorkspace(item) {
1597
+ if (!this.nervousSystemMethods?.broadcastToWorkspace) {
1598
+ return false;
1599
+ }
1600
+ return this.nervousSystemMethods.broadcastToWorkspace(item);
1601
+ }
1602
+ /**
1603
+ * Get items currently in the workspace relevant to this agent
1604
+ *
1605
+ * @returns Array of workspace items
1606
+ */
1607
+ async getWorkspaceItems() {
1608
+ if (!this.nervousSystemMethods?.getWorkspaceItems) {
1609
+ return [];
1610
+ }
1611
+ return this.nervousSystemMethods.getWorkspaceItems();
1612
+ }
1613
+ /**
1614
+ * Check if this agent currently has attention in the Global Workspace
1615
+ *
1616
+ * Agents with attention should proceed with full execution.
1617
+ * Agents without attention should defer or reduce activity.
1618
+ *
1619
+ * @returns Whether this agent has attention
1620
+ */
1621
+ async hasAttention() {
1622
+ if (!this.nervousSystemMethods?.hasAttention) {
1623
+ return true; // Default to true if workspace not enabled
1624
+ }
1625
+ return this.nervousSystemMethods.hasAttention();
1626
+ }
1627
+ // === Circadian Cycling Methods ===
1628
+ /**
1629
+ * Get current circadian phase (Active, Dawn, Dusk, Rest)
1630
+ *
1631
+ * Agents should adjust behavior based on phase:
1632
+ * - Active: Full compute operations
1633
+ * - Dawn/Dusk: Transition states
1634
+ * - Rest: Minimal activity for 5-50x compute savings
1635
+ */
1636
+ getCurrentPhase() {
1637
+ if (!this.nervousSystemMethods?.getCurrentPhase) {
1638
+ return 'Active'; // Default to active if circadian not enabled
1639
+ }
1640
+ return this.nervousSystemMethods.getCurrentPhase();
1641
+ }
1642
+ /**
1643
+ * Check if agent should be active based on circadian phase and criticality
1644
+ *
1645
+ * Critical agents stay active even during rest phase.
1646
+ * Non-critical agents can sleep for compute savings.
1647
+ *
1648
+ * @returns Whether agent should be active
1649
+ */
1650
+ shouldBeActive() {
1651
+ if (!this.nervousSystemMethods?.shouldBeActive) {
1652
+ return true; // Default to active if circadian not enabled
1653
+ }
1654
+ return this.nervousSystemMethods.shouldBeActive();
1655
+ }
1656
+ /**
1657
+ * Get energy savings report from circadian cycling
1658
+ *
1659
+ * Shows saved compute cycles, total rest time, and cost reduction factor.
1660
+ */
1661
+ getEnergySavings() {
1662
+ if (!this.nervousSystemMethods?.getEnergySavings) {
1663
+ return {
1664
+ savedCycles: 0,
1665
+ savingsPercentage: 0,
1666
+ totalRestTime: 0,
1667
+ totalActiveTime: 0,
1668
+ averageDutyFactor: 1,
1669
+ costReductionFactor: 1,
1670
+ };
1671
+ }
1672
+ return this.nervousSystemMethods.getEnergySavings();
1673
+ }
1674
+ /**
1675
+ * Cleanup nervous system resources on agent termination
1676
+ */
1677
+ async cleanupNervousSystem() {
1678
+ if (!this.nervousSystemEnhanced) {
1679
+ return;
1680
+ }
1681
+ try {
1682
+ // Wave 7.1: Save nervous system state before cleanup
1683
+ if (this.nervousSystemPersistence) {
1684
+ try {
1685
+ await (0, NervousSystemEnhancement_js_1.saveNervousSystemState)(this, this.nervousSystemPersistence);
1686
+ this.logger.info(`[${this.agentId.id}] Nervous System state saved to persistence`);
1687
+ }
1688
+ catch (saveError) {
1689
+ this.logger.warn(`[${this.agentId.id}] Failed to save nervous system state:`, saveError.message);
1690
+ }
1691
+ }
1692
+ // The enhancement uses WeakMap, so cleanup happens automatically
1693
+ // when agent reference is garbage collected. We just need to clear our flags.
1694
+ this.nervousSystemMethods = undefined;
1695
+ this.nervousSystemEnhanced = false;
1696
+ this.nervousSystemPersistence = undefined;
1697
+ this.logger.info(`[${this.agentId.id}] Nervous System cleanup complete`);
1698
+ }
1699
+ catch (error) {
1700
+ this.logger.warn(`[${this.agentId.id}] Nervous System cleanup error:`, error.message);
1701
+ }
1702
+ }
1703
+ // ============================================
1704
+ // Network Policy Methods (SP-3 - Issue #146)
1705
+ // ============================================
1706
+ /**
1707
+ * Initialize Network Policy Manager for domain whitelisting and rate limiting
1708
+ * Provides security hardening for agent network access
1709
+ */
1710
+ async initializeNetworkPolicy() {
1711
+ if (this.networkPolicyConfig.enabled === false) {
1712
+ this.logger.info(`[${this.agentId.id}] Network Policy disabled by configuration`);
1713
+ return;
1714
+ }
1715
+ try {
1716
+ // Use shared manager if provided, otherwise create a new one
1717
+ if (this.networkPolicyConfig.sharedManager) {
1718
+ this.networkPolicyManager = this.networkPolicyConfig.sharedManager;
1719
+ this.networkPolicyOwned = false;
1720
+ }
1721
+ else {
1722
+ this.networkPolicyManager = (0, NetworkPolicyManager_js_1.createNetworkPolicyManager)({
1723
+ enableAuditLogging: this.networkPolicyConfig.enableAuditLogging ?? true,
1724
+ debug: this.networkPolicyConfig.debug ?? false,
1725
+ });
1726
+ await this.networkPolicyManager.initialize();
1727
+ this.networkPolicyOwned = true;
1728
+ }
1729
+ // Apply any policy overrides for this agent type
1730
+ if (this.networkPolicyConfig.policyOverrides) {
1731
+ this.networkPolicyManager.updatePolicy(this.agentId.type, this.networkPolicyConfig.policyOverrides);
1732
+ }
1733
+ this.networkPolicyInitialized = true;
1734
+ this.logger.info(`[${this.agentId.id}] Network Policy initialized (owned: ${this.networkPolicyOwned})`);
1735
+ }
1736
+ catch (error) {
1737
+ this.logger.warn(`[${this.agentId.id}] Network Policy initialization failed:`, error.message);
1738
+ // Don't throw - agent can work without network policy (graceful degradation)
1739
+ }
1740
+ }
1741
+ /**
1742
+ * Check if network policy enforcement is available
1743
+ */
1744
+ hasNetworkPolicy() {
1745
+ return this.networkPolicyInitialized && this.networkPolicyManager !== undefined;
1746
+ }
1747
+ /**
1748
+ * Get the network policy for this agent type
1749
+ */
1750
+ getNetworkPolicy() {
1751
+ if (!this.networkPolicyManager) {
1752
+ return (0, default_policies_js_1.getNetworkPolicy)(this.agentId.type);
1753
+ }
1754
+ return this.networkPolicyManager.getPolicy(this.agentId.type);
1755
+ }
1756
+ /**
1757
+ * Check if a network request to a domain is allowed
1758
+ * Does NOT consume rate limit tokens - use for pre-flight checks
1759
+ *
1760
+ * @param domain - The target domain (e.g., "api.anthropic.com")
1761
+ * @returns PolicyCheckResult with allowed status and details
1762
+ */
1763
+ async checkNetworkRequest(domain) {
1764
+ if (!this.networkPolicyManager) {
1765
+ // No policy enforcement - allow all
1766
+ return {
1767
+ allowed: true,
1768
+ policy: (0, default_policies_js_1.getNetworkPolicy)(this.agentId.type),
1769
+ };
1770
+ }
1771
+ return this.networkPolicyManager.checkRequest(this.agentId.id, this.agentId.type, domain);
1772
+ }
1773
+ /**
1774
+ * Record a network request (consumes rate limit token)
1775
+ * Call this after making an actual network request
1776
+ *
1777
+ * @param domain - The target domain
1778
+ * @param allowed - Whether the request was allowed
1779
+ * @param responseTimeMs - Response time in milliseconds (optional)
1780
+ */
1781
+ async recordNetworkRequest(domain, allowed, responseTimeMs) {
1782
+ if (!this.networkPolicyManager) {
1783
+ return;
1784
+ }
1785
+ await this.networkPolicyManager.recordRequest(this.agentId.id, this.agentId.type, domain, allowed, responseTimeMs);
1786
+ }
1787
+ /**
1788
+ * Make a policy-enforced network request
1789
+ * Checks domain whitelist and rate limits before allowing the request
1790
+ *
1791
+ * @param url - The full URL to request
1792
+ * @param requestFn - Function that performs the actual request
1793
+ * @returns The result of requestFn if allowed
1794
+ * @throws Error if request is blocked by policy
1795
+ *
1796
+ * @example
1797
+ * ```typescript
1798
+ * const response = await this.makeNetworkRequest(
1799
+ * 'https://api.anthropic.com/v1/messages',
1800
+ * async () => fetch('https://api.anthropic.com/v1/messages', { method: 'POST', ... })
1801
+ * );
1802
+ * ```
1803
+ */
1804
+ async makeNetworkRequest(url, requestFn) {
1805
+ // Extract domain from URL
1806
+ let domain;
1807
+ try {
1808
+ const parsedUrl = new URL(url);
1809
+ domain = parsedUrl.hostname;
1810
+ }
1811
+ catch {
1812
+ throw new Error(`Invalid URL: ${url}`);
1813
+ }
1814
+ // Check if request is allowed
1815
+ const check = await this.checkNetworkRequest(domain);
1816
+ if (!check.allowed) {
1817
+ const error = new Error(`Network request blocked: ${check.reason} - ${check.details || domain}`);
1818
+ error.policyCheckResult = check;
1819
+ throw error;
1820
+ }
1821
+ // Make the actual request
1822
+ const startTime = Date.now();
1823
+ try {
1824
+ const result = await requestFn();
1825
+ const responseTime = Date.now() - startTime;
1826
+ await this.recordNetworkRequest(domain, true, responseTime);
1827
+ return result;
1828
+ }
1829
+ catch (error) {
1830
+ const responseTime = Date.now() - startTime;
1831
+ await this.recordNetworkRequest(domain, false, responseTime);
1832
+ throw error;
1833
+ }
1834
+ }
1835
+ /**
1836
+ * Get rate limit status for this agent
1837
+ */
1838
+ getNetworkRateLimitStatus() {
1839
+ if (!this.networkPolicyManager) {
1840
+ return null;
1841
+ }
1842
+ return this.networkPolicyManager.getRateLimitStatus(this.agentId.id, this.agentId.type);
1843
+ }
1844
+ /**
1845
+ * Get network audit statistics
1846
+ * @param since - Optional start date for stats
1847
+ */
1848
+ async getNetworkAuditStats(since) {
1849
+ if (!this.networkPolicyManager) {
1850
+ return null;
1851
+ }
1852
+ return this.networkPolicyManager.getAuditStats(since);
1853
+ }
1854
+ /**
1855
+ * Get network policy statistics for this agent
1856
+ */
1857
+ getNetworkPolicyStats() {
1858
+ if (!this.hasNetworkPolicy()) {
1859
+ return { enabled: false };
1860
+ }
1861
+ return {
1862
+ enabled: true,
1863
+ policy: this.getNetworkPolicy(),
1864
+ rateLimitStatus: this.getNetworkRateLimitStatus(),
1865
+ };
1866
+ }
1867
+ /**
1868
+ * Cleanup network policy resources on agent termination
1869
+ */
1870
+ async cleanupNetworkPolicy() {
1871
+ if (!this.networkPolicyInitialized) {
1872
+ return;
1873
+ }
1874
+ try {
1875
+ // Only shutdown if we own the manager (not shared)
1876
+ if (this.networkPolicyOwned && this.networkPolicyManager) {
1877
+ await this.networkPolicyManager.shutdown();
1878
+ this.logger.info(`[${this.agentId.id}] Network Policy cleanup complete`);
1879
+ }
1880
+ }
1881
+ catch (error) {
1882
+ this.logger.warn(`[${this.agentId.id}] Network Policy cleanup error:`, error.message);
1883
+ }
1884
+ this.networkPolicyInitialized = false;
1885
+ this.networkPolicyManager = undefined;
1886
+ }
1887
+ // ============================================
1888
+ // Sandbox Infrastructure Methods (SP-1 - Issue #146)
1889
+ // ============================================
1890
+ /**
1891
+ * Initialize Sandbox Manager for Docker-based agent isolation
1892
+ * Provides secure, isolated execution environments with resource limits
1893
+ */
1894
+ async initializeSandbox() {
1895
+ if (this.sandboxConfig.enabled === false) {
1896
+ this.logger.debug(`[${this.agentId.id}] Sandbox disabled by configuration`);
1897
+ return;
1898
+ }
1899
+ try {
1900
+ // Use shared manager if provided, otherwise create a new one
1901
+ if (this.sandboxConfig.sharedManager) {
1902
+ this.sandboxManager = this.sandboxConfig.sharedManager;
1903
+ this.sandboxOwned = false;
1904
+ }
1905
+ else {
1906
+ this.sandboxManager = (0, SandboxManager_js_1.createSandboxManager)({
1907
+ agentImage: process.env.AQE_SANDBOX_IMAGE || 'agentic-qe-agent',
1908
+ imageTag: process.env.AQE_SANDBOX_TAG || 'latest',
1909
+ cleanupOnShutdown: true,
1910
+ });
1911
+ await this.sandboxManager.initialize();
1912
+ this.sandboxOwned = true;
1913
+ }
1914
+ // Auto-create sandbox container if configured
1915
+ if (this.sandboxConfig.autoCreateSandbox !== false) {
1916
+ const result = await this.createSandboxContainer();
1917
+ if (result.success && result.container) {
1918
+ this.containerId = result.container.containerId;
1919
+ }
1920
+ else if (!result.success) {
1921
+ // Docker not available - graceful degradation
1922
+ this.logger.info(`[${this.agentId.id}] Sandbox container creation skipped: ${result.error}`);
1923
+ }
1924
+ }
1925
+ this.sandboxInitialized = true;
1926
+ this.logger.info(`[${this.agentId.id}] Sandbox initialized (owned: ${this.sandboxOwned}, container: ${this.containerId || 'none'})`);
1927
+ }
1928
+ catch (error) {
1929
+ this.logger.warn(`[${this.agentId.id}] Sandbox initialization failed:`, error.message);
1930
+ // Don't throw - agent can work without sandbox (graceful degradation)
1931
+ }
1932
+ }
1933
+ /**
1934
+ * Check if sandbox isolation is available
1935
+ */
1936
+ hasSandbox() {
1937
+ return this.sandboxInitialized && this.sandboxManager !== undefined;
1938
+ }
1939
+ /**
1940
+ * Check if agent is running in a sandbox container
1941
+ */
1942
+ isInSandbox() {
1943
+ return this.containerId !== undefined;
1944
+ }
1945
+ /**
1946
+ * Get the container ID if running in sandbox
1947
+ */
1948
+ getContainerId() {
1949
+ return this.containerId;
1950
+ }
1951
+ /**
1952
+ * Get sandbox configuration for this agent type
1953
+ */
1954
+ getSandboxConfig() {
1955
+ return (0, agent_profiles_js_1.getAgentSandboxConfig)(this.agentId.type);
1956
+ }
1957
+ /**
1958
+ * Create a sandbox container for this agent
1959
+ * @param customConfig - Optional custom sandbox configuration
1960
+ */
1961
+ async createSandboxContainer(customConfig) {
1962
+ if (!this.sandboxManager) {
1963
+ return {
1964
+ success: false,
1965
+ error: 'Sandbox manager not initialized',
1966
+ };
1967
+ }
1968
+ // Check if Docker is available
1969
+ const dockerAvailable = await this.sandboxManager.isDockerAvailable();
1970
+ if (!dockerAvailable) {
1971
+ return {
1972
+ success: false,
1973
+ error: 'Docker not available',
1974
+ };
1975
+ }
1976
+ // Merge profile config with any overrides
1977
+ const mergedConfig = {
1978
+ ...this.sandboxConfig.sandboxOverrides,
1979
+ ...customConfig,
1980
+ };
1981
+ return this.sandboxManager.createSandbox(this.agentId.id, this.agentId.type, mergedConfig);
1982
+ }
1983
+ /**
1984
+ * Get resource usage for the sandbox container
1985
+ */
1986
+ async getSandboxResourceUsage() {
1987
+ if (!this.sandboxManager || !this.containerId) {
1988
+ return null;
1989
+ }
1990
+ return this.sandboxManager.getResourceUsage(this.containerId);
1991
+ }
1992
+ /**
1993
+ * Check sandbox container health
1994
+ */
1995
+ async checkSandboxHealth() {
1996
+ if (!this.sandboxManager || !this.containerId) {
1997
+ return null;
1998
+ }
1999
+ return this.sandboxManager.healthCheck(this.containerId);
2000
+ }
2001
+ /**
2002
+ * Execute a command in the sandbox container
2003
+ * @param command - Command to execute as array of strings
2004
+ */
2005
+ async execInSandbox(command) {
2006
+ if (!this.sandboxManager || !this.containerId) {
2007
+ return null;
2008
+ }
2009
+ return this.sandboxManager.exec(this.containerId, command);
2010
+ }
2011
+ /**
2012
+ * Get sandbox container logs
2013
+ * @param options - Log retrieval options
2014
+ */
2015
+ async getSandboxLogs(options) {
2016
+ if (!this.sandboxManager || !this.containerId) {
2017
+ return null;
2018
+ }
2019
+ return this.sandboxManager.getLogs(this.containerId, options);
2020
+ }
2021
+ /**
2022
+ * Subscribe to sandbox events
2023
+ * @param handler - Event handler function
2024
+ */
2025
+ onSandboxEvent(handler) {
2026
+ if (this.sandboxManager) {
2027
+ this.sandboxManager.on(handler);
2028
+ }
2029
+ }
2030
+ /**
2031
+ * Unsubscribe from sandbox events
2032
+ * @param handler - Event handler to remove
2033
+ */
2034
+ offSandboxEvent(handler) {
2035
+ if (this.sandboxManager) {
2036
+ this.sandboxManager.off(handler);
2037
+ }
2038
+ }
2039
+ /**
2040
+ * Get sandbox statistics for this agent
2041
+ */
2042
+ getSandboxStats() {
2043
+ if (!this.hasSandbox()) {
2044
+ return { enabled: false, inSandbox: false };
2045
+ }
2046
+ return {
2047
+ enabled: true,
2048
+ inSandbox: this.isInSandbox(),
2049
+ containerId: this.containerId,
2050
+ sandboxConfig: this.getSandboxConfig(),
2051
+ };
2052
+ }
2053
+ /**
2054
+ * Cleanup sandbox resources on agent termination
2055
+ */
2056
+ async cleanupSandbox() {
2057
+ if (!this.sandboxInitialized) {
2058
+ return;
2059
+ }
2060
+ try {
2061
+ // Destroy our container if we have one
2062
+ if (this.containerId && this.sandboxManager) {
2063
+ const result = await this.sandboxManager.destroySandbox(this.containerId, true);
2064
+ if (result.success) {
2065
+ this.logger.info(`[${this.agentId.id}] Sandbox container ${this.containerId} destroyed`);
2066
+ }
2067
+ else {
2068
+ this.logger.warn(`[${this.agentId.id}] Sandbox container destruction failed: ${result.error}`);
2069
+ }
2070
+ }
2071
+ // Only shutdown manager if we own it (not shared)
2072
+ if (this.sandboxOwned && this.sandboxManager) {
2073
+ await this.sandboxManager.shutdown();
2074
+ this.logger.info(`[${this.agentId.id}] Sandbox manager shutdown complete`);
2075
+ }
2076
+ }
2077
+ catch (error) {
2078
+ this.logger.warn(`[${this.agentId.id}] Sandbox cleanup error:`, error.message);
2079
+ }
2080
+ this.sandboxInitialized = false;
2081
+ this.sandboxManager = undefined;
2082
+ this.containerId = undefined;
2083
+ }
1427
2084
  }
1428
2085
  exports.BaseAgent = BaseAgent;
1429
2086
  class BaseAgentFactory {