@mxf-dev/core 1.0.1 → 2.0.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 (298) hide show
  1. package/README.md +18 -0
  2. package/dist/adapters/FrameworkAdapter.js +1 -1
  3. package/dist/adapters/FrameworkAdapter.js.map +1 -1
  4. package/dist/config/ConfigManager.d.ts +9 -8
  5. package/dist/config/ConfigManager.d.ts.map +1 -1
  6. package/dist/config/ConfigManager.js +47 -17
  7. package/dist/config/ConfigManager.js.map +1 -1
  8. package/dist/config/memory-strata.config.d.ts +25 -0
  9. package/dist/config/memory-strata.config.d.ts.map +1 -0
  10. package/dist/config/memory-strata.config.js +107 -0
  11. package/dist/config/memory-strata.config.js.map +1 -0
  12. package/dist/constants/ToolNames.d.ts +1 -29
  13. package/dist/constants/ToolNames.d.ts.map +1 -1
  14. package/dist/constants/ToolNames.js +4 -17
  15. package/dist/constants/ToolNames.js.map +1 -1
  16. package/dist/database/DatabaseAdapterFactory.d.ts +14 -2
  17. package/dist/database/DatabaseAdapterFactory.d.ts.map +1 -1
  18. package/dist/database/DatabaseAdapterFactory.js +21 -6
  19. package/dist/database/DatabaseAdapterFactory.js.map +1 -1
  20. package/dist/database/adapters/mongodb/MongoBaseRepository.d.ts +7 -1
  21. package/dist/database/adapters/mongodb/MongoBaseRepository.d.ts.map +1 -1
  22. package/dist/database/adapters/mongodb/MongoBaseRepository.js +12 -2
  23. package/dist/database/adapters/mongodb/MongoBaseRepository.js.map +1 -1
  24. package/dist/events/ClientEventBus.d.ts +16 -77
  25. package/dist/events/ClientEventBus.d.ts.map +1 -1
  26. package/dist/events/ClientEventBus.js +38 -311
  27. package/dist/events/ClientEventBus.js.map +1 -1
  28. package/dist/events/EventBus.d.ts +1 -1
  29. package/dist/events/EventBus.d.ts.map +1 -1
  30. package/dist/events/EventBus.js +5 -4
  31. package/dist/events/EventBus.js.map +1 -1
  32. package/dist/events/EventBusBase.d.ts +139 -34
  33. package/dist/events/EventBusBase.d.ts.map +1 -1
  34. package/dist/events/EventBusBase.js +366 -88
  35. package/dist/events/EventBusBase.js.map +1 -1
  36. package/dist/events/EventNames.d.ts +10 -1
  37. package/dist/events/EventNames.d.ts.map +1 -1
  38. package/dist/events/EventNames.js +3 -0
  39. package/dist/events/EventNames.js.map +1 -1
  40. package/dist/events/PublicEvents.d.ts +6 -2
  41. package/dist/events/PublicEvents.d.ts.map +1 -1
  42. package/dist/events/PublicEvents.js +7 -4
  43. package/dist/events/PublicEvents.js.map +1 -1
  44. package/dist/events/ServerEventBus.d.ts +23 -112
  45. package/dist/events/ServerEventBus.d.ts.map +1 -1
  46. package/dist/events/ServerEventBus.js +58 -323
  47. package/dist/events/ServerEventBus.js.map +1 -1
  48. package/dist/events/event-definitions/LlmBudgetEvents.d.ts +68 -0
  49. package/dist/events/event-definitions/LlmBudgetEvents.d.ts.map +1 -0
  50. package/dist/events/event-definitions/LlmBudgetEvents.js +35 -0
  51. package/dist/events/event-definitions/LlmBudgetEvents.js.map +1 -0
  52. package/dist/interfaces/IMemoryPersistence.d.ts +41 -0
  53. package/dist/interfaces/IMemoryPersistence.d.ts.map +1 -0
  54. package/dist/interfaces/IMemoryPersistence.js +15 -0
  55. package/dist/interfaces/IMemoryPersistence.js.map +1 -0
  56. package/dist/middleware/MxpMiddleware.d.ts +8 -1
  57. package/dist/middleware/MxpMiddleware.d.ts.map +1 -1
  58. package/dist/middleware/MxpMiddleware.js +42 -20
  59. package/dist/middleware/MxpMiddleware.js.map +1 -1
  60. package/dist/models/channelKey.d.ts +1 -0
  61. package/dist/models/channelKey.d.ts.map +1 -1
  62. package/dist/models/channelKey.js +5 -0
  63. package/dist/models/channelKey.js.map +1 -1
  64. package/dist/models/memoryUtility.d.ts +39 -0
  65. package/dist/models/memoryUtility.d.ts.map +1 -0
  66. package/dist/models/memoryUtility.js +39 -0
  67. package/dist/models/memoryUtility.js.map +1 -0
  68. package/dist/models/user.d.ts.map +1 -1
  69. package/dist/models/user.js +23 -1
  70. package/dist/models/user.js.map +1 -1
  71. package/dist/mxp/BinaryProtocolLayer.d.ts +24 -8
  72. package/dist/mxp/BinaryProtocolLayer.d.ts.map +1 -1
  73. package/dist/mxp/BinaryProtocolLayer.js +90 -103
  74. package/dist/mxp/BinaryProtocolLayer.js.map +1 -1
  75. package/dist/mxp/ContextCompressionEngine.d.ts +57 -10
  76. package/dist/mxp/ContextCompressionEngine.d.ts.map +1 -1
  77. package/dist/mxp/ContextCompressionEngine.js +170 -128
  78. package/dist/mxp/ContextCompressionEngine.js.map +1 -1
  79. package/dist/mxp/MxpTokenOptimizer.d.ts +7 -3
  80. package/dist/mxp/MxpTokenOptimizer.d.ts.map +1 -1
  81. package/dist/mxp/MxpTokenOptimizer.js +8 -5
  82. package/dist/mxp/MxpTokenOptimizer.js.map +1 -1
  83. package/dist/prompts/MxfAgentSystemPrompt.d.ts +1 -1
  84. package/dist/prompts/MxfAgentSystemPrompt.d.ts.map +1 -1
  85. package/dist/prompts/MxfAgentSystemPrompt.js +47 -57
  86. package/dist/prompts/MxfAgentSystemPrompt.js.map +1 -1
  87. package/dist/protocols/mcp/ToolError.d.ts +123 -0
  88. package/dist/protocols/mcp/ToolError.d.ts.map +1 -0
  89. package/dist/protocols/mcp/ToolError.js +108 -0
  90. package/dist/protocols/mcp/ToolError.js.map +1 -0
  91. package/dist/protocols/mcp/defineTool.d.ts +133 -0
  92. package/dist/protocols/mcp/defineTool.d.ts.map +1 -0
  93. package/dist/protocols/mcp/defineTool.js +236 -0
  94. package/dist/protocols/mcp/defineTool.js.map +1 -0
  95. package/dist/protocols/mcp/security/HttpTargetGuard.d.ts +38 -0
  96. package/dist/protocols/mcp/security/HttpTargetGuard.d.ts.map +1 -0
  97. package/dist/protocols/mcp/security/HttpTargetGuard.js +227 -0
  98. package/dist/protocols/mcp/security/HttpTargetGuard.js.map +1 -0
  99. package/dist/protocols/mcp/security/McpSecurityGuard.d.ts +9 -1
  100. package/dist/protocols/mcp/security/McpSecurityGuard.d.ts.map +1 -1
  101. package/dist/protocols/mcp/security/McpSecurityGuard.js +10 -2
  102. package/dist/protocols/mcp/security/McpSecurityGuard.js.map +1 -1
  103. package/dist/protocols/mcp/security/McpToolPolicy.d.ts +81 -0
  104. package/dist/protocols/mcp/security/McpToolPolicy.d.ts.map +1 -0
  105. package/dist/protocols/mcp/security/McpToolPolicy.js +202 -0
  106. package/dist/protocols/mcp/security/McpToolPolicy.js.map +1 -0
  107. package/dist/protocols/mcp/services/ExternalMcpServerManager.d.ts +51 -18
  108. package/dist/protocols/mcp/services/ExternalMcpServerManager.d.ts.map +1 -1
  109. package/dist/protocols/mcp/services/ExternalMcpServerManager.js +256 -283
  110. package/dist/protocols/mcp/services/ExternalMcpServerManager.js.map +1 -1
  111. package/dist/protocols/mcp/services/ExternalServerConfigs.d.ts +39 -6
  112. package/dist/protocols/mcp/services/ExternalServerConfigs.d.ts.map +1 -1
  113. package/dist/protocols/mcp/services/ExternalServerConfigs.js +76 -18
  114. package/dist/protocols/mcp/services/ExternalServerConfigs.js.map +1 -1
  115. package/dist/protocols/mcp/tools/AnalyticsTools.js +1 -1
  116. package/dist/protocols/mcp/tools/AnalyticsTools.js.map +1 -1
  117. package/dist/protocols/mcp/tools/CodeAnalysisTools.d.ts.map +1 -1
  118. package/dist/protocols/mcp/tools/CodeAnalysisTools.js +15 -0
  119. package/dist/protocols/mcp/tools/CodeAnalysisTools.js.map +1 -1
  120. package/dist/protocols/mcp/tools/EffectivenessTools.js +3 -3
  121. package/dist/protocols/mcp/tools/EffectivenessTools.js.map +1 -1
  122. package/dist/protocols/mcp/tools/GitTools.d.ts +9 -369
  123. package/dist/protocols/mcp/tools/GitTools.d.ts.map +1 -1
  124. package/dist/protocols/mcp/tools/GitTools.js +222 -517
  125. package/dist/protocols/mcp/tools/GitTools.js.map +1 -1
  126. package/dist/protocols/mcp/tools/InfrastructureTools.d.ts +56 -24
  127. package/dist/protocols/mcp/tools/InfrastructureTools.d.ts.map +1 -1
  128. package/dist/protocols/mcp/tools/InfrastructureTools.js +117 -26
  129. package/dist/protocols/mcp/tools/InfrastructureTools.js.map +1 -1
  130. package/dist/protocols/mcp/tools/MemorySearchTools.d.ts +0 -3
  131. package/dist/protocols/mcp/tools/MemorySearchTools.d.ts.map +1 -1
  132. package/dist/protocols/mcp/tools/MemorySearchTools.js +58 -1
  133. package/dist/protocols/mcp/tools/MemorySearchTools.js.map +1 -1
  134. package/dist/protocols/mcp/tools/OrparTools.d.ts +8 -0
  135. package/dist/protocols/mcp/tools/OrparTools.d.ts.map +1 -1
  136. package/dist/protocols/mcp/tools/OrparTools.js +66 -0
  137. package/dist/protocols/mcp/tools/OrparTools.js.map +1 -1
  138. package/dist/protocols/mcp/tools/SafetyTools.d.ts +7 -525
  139. package/dist/protocols/mcp/tools/SafetyTools.d.ts.map +1 -1
  140. package/dist/protocols/mcp/tools/SafetyTools.js +349 -514
  141. package/dist/protocols/mcp/tools/SafetyTools.js.map +1 -1
  142. package/dist/protocols/mcp/tools/TaskPlanningTools.d.ts.map +1 -1
  143. package/dist/protocols/mcp/tools/TaskPlanningTools.js +56 -26
  144. package/dist/protocols/mcp/tools/TaskPlanningTools.js.map +1 -1
  145. package/dist/protocols/mcp/tools/TestTools.d.ts +15 -376
  146. package/dist/protocols/mcp/tools/TestTools.d.ts.map +1 -1
  147. package/dist/protocols/mcp/tools/TestTools.js +241 -363
  148. package/dist/protocols/mcp/tools/TestTools.js.map +1 -1
  149. package/dist/protocols/mcp/tools/TypeScriptTools.d.ts +6 -276
  150. package/dist/protocols/mcp/tools/TypeScriptTools.d.ts.map +1 -1
  151. package/dist/protocols/mcp/tools/TypeScriptTools.js +223 -337
  152. package/dist/protocols/mcp/tools/TypeScriptTools.js.map +1 -1
  153. package/dist/protocols/mcp/tools/WebTools.d.ts +15 -728
  154. package/dist/protocols/mcp/tools/WebTools.d.ts.map +1 -1
  155. package/dist/protocols/mcp/tools/WebTools.js +151 -257
  156. package/dist/protocols/mcp/tools/WebTools.js.map +1 -1
  157. package/dist/protocols/mcp/tools/shell/ShellExecuteHandler.d.ts +5 -3
  158. package/dist/protocols/mcp/tools/shell/ShellExecuteHandler.d.ts.map +1 -1
  159. package/dist/protocols/mcp/tools/shell/ShellExecuteHandler.js +31 -6
  160. package/dist/protocols/mcp/tools/shell/ShellExecuteHandler.js.map +1 -1
  161. package/dist/schemas/EventPayloadSchema.d.ts +21 -0
  162. package/dist/schemas/EventPayloadSchema.d.ts.map +1 -1
  163. package/dist/schemas/EventPayloadSchema.js +14 -0
  164. package/dist/schemas/EventPayloadSchema.js.map +1 -1
  165. package/dist/services/BackgroundTaskManager.d.ts.map +1 -1
  166. package/dist/services/BackgroundTaskManager.js +12 -4
  167. package/dist/services/BackgroundTaskManager.js.map +1 -1
  168. package/dist/services/BrowserManager.d.ts +1 -1
  169. package/dist/services/BrowserManager.d.ts.map +1 -1
  170. package/dist/services/BrowserManager.js +26 -3
  171. package/dist/services/BrowserManager.js.map +1 -1
  172. package/dist/services/MemoryCompressor.d.ts +11 -2
  173. package/dist/services/MemoryCompressor.d.ts.map +1 -1
  174. package/dist/services/MemoryCompressor.js +8 -26
  175. package/dist/services/MemoryCompressor.js.map +1 -1
  176. package/dist/services/MemoryService.d.ts +16 -3
  177. package/dist/services/MemoryService.d.ts.map +1 -1
  178. package/dist/services/MemoryService.js +79 -55
  179. package/dist/services/MemoryService.js.map +1 -1
  180. package/dist/services/PredictiveAnalyticsService.d.ts +34 -4
  181. package/dist/services/PredictiveAnalyticsService.d.ts.map +1 -1
  182. package/dist/services/PredictiveAnalyticsService.js +41 -25
  183. package/dist/services/PredictiveAnalyticsService.js.map +1 -1
  184. package/dist/services/QValueManager.d.ts +7 -0
  185. package/dist/services/QValueManager.d.ts.map +1 -1
  186. package/dist/services/QValueManager.js +9 -0
  187. package/dist/services/QValueManager.js.map +1 -1
  188. package/dist/services/RewardSignalProcessor.d.ts +38 -1
  189. package/dist/services/RewardSignalProcessor.d.ts.map +1 -1
  190. package/dist/services/RewardSignalProcessor.js +109 -7
  191. package/dist/services/RewardSignalProcessor.js.map +1 -1
  192. package/dist/services/SharedStateService.d.ts +16 -2
  193. package/dist/services/SharedStateService.d.ts.map +1 -1
  194. package/dist/services/SharedStateService.js +44 -3
  195. package/dist/services/SharedStateService.js.map +1 -1
  196. package/dist/services/TaskEffectivenessService.d.ts +34 -18
  197. package/dist/services/TaskEffectivenessService.d.ts.map +1 -1
  198. package/dist/services/TaskEffectivenessService.js +91 -155
  199. package/dist/services/TaskEffectivenessService.js.map +1 -1
  200. package/dist/services/WebSearchService.d.ts.map +1 -1
  201. package/dist/services/WebSearchService.js.map +1 -1
  202. package/dist/services/dag/TaskDagService.d.ts.map +1 -1
  203. package/dist/services/dag/TaskDagService.js +2 -0
  204. package/dist/services/dag/TaskDagService.js.map +1 -1
  205. package/dist/services/orpar-memory/OrparMemoryCoordinator.d.ts +7 -0
  206. package/dist/services/orpar-memory/OrparMemoryCoordinator.d.ts.map +1 -1
  207. package/dist/services/orpar-memory/OrparMemoryCoordinator.js +71 -10
  208. package/dist/services/orpar-memory/OrparMemoryCoordinator.js.map +1 -1
  209. package/dist/types/MemoryUtilityTypes.d.ts +2 -0
  210. package/dist/types/MemoryUtilityTypes.d.ts.map +1 -1
  211. package/dist/types/MemoryUtilityTypes.js.map +1 -1
  212. package/dist/utils/Logger.d.ts +43 -3
  213. package/dist/utils/Logger.d.ts.map +1 -1
  214. package/dist/utils/Logger.js +78 -36
  215. package/dist/utils/Logger.js.map +1 -1
  216. package/dist/utils/MxpEncryption.d.ts +19 -6
  217. package/dist/utils/MxpEncryption.d.ts.map +1 -1
  218. package/dist/utils/MxpEncryption.js +48 -16
  219. package/dist/utils/MxpEncryption.js.map +1 -1
  220. package/package.json +19 -4
  221. package/src/adapters/FrameworkAdapter.ts +1 -1
  222. package/src/config/ConfigManager.ts +52 -19
  223. package/src/config/memory-strata.config.ts +136 -0
  224. package/src/constants/ToolNames.ts +4 -18
  225. package/src/database/DatabaseAdapterFactory.ts +23 -6
  226. package/src/database/adapters/mongodb/MongoBaseRepository.ts +16 -2
  227. package/src/events/ClientEventBus.ts +68 -403
  228. package/src/events/EventBus.ts +7 -8
  229. package/src/events/EventBusBase.ts +479 -116
  230. package/src/events/EventNames.ts +6 -0
  231. package/src/events/PublicEvents.ts +7 -4
  232. package/src/events/ServerEventBus.ts +78 -473
  233. package/src/events/event-definitions/LlmBudgetEvents.ts +74 -0
  234. package/src/interfaces/IMemoryPersistence.ts +51 -0
  235. package/src/middleware/MxpMiddleware.ts +51 -24
  236. package/src/models/channelKey.ts +18 -4
  237. package/src/models/memoryUtility.ts +64 -0
  238. package/src/models/user.ts +36 -4
  239. package/src/mxp/BinaryProtocolLayer.ts +108 -124
  240. package/src/mxp/ContextCompressionEngine.ts +219 -161
  241. package/src/mxp/MxpTokenOptimizer.ts +10 -10
  242. package/src/prompts/MxfAgentSystemPrompt.ts +45 -55
  243. package/src/protocols/mcp/ToolError.ts +201 -0
  244. package/src/protocols/mcp/defineTool.ts +379 -0
  245. package/src/protocols/mcp/security/HttpTargetGuard.ts +267 -0
  246. package/src/protocols/mcp/security/McpSecurityGuard.ts +10 -3
  247. package/src/protocols/mcp/security/McpToolPolicy.ts +221 -0
  248. package/src/protocols/mcp/services/ExternalMcpServerManager.ts +340 -322
  249. package/src/protocols/mcp/services/ExternalServerConfigs.ts +82 -19
  250. package/src/protocols/mcp/tools/AnalyticsTools.ts +1 -1
  251. package/src/protocols/mcp/tools/CodeAnalysisTools.ts +15 -0
  252. package/src/protocols/mcp/tools/EffectivenessTools.ts +3 -3
  253. package/src/protocols/mcp/tools/GitTools.ts +290 -569
  254. package/src/protocols/mcp/tools/InfrastructureTools.ts +189 -43
  255. package/src/protocols/mcp/tools/MemorySearchTools.ts +77 -1
  256. package/src/protocols/mcp/tools/OrparTools.ts +87 -0
  257. package/src/protocols/mcp/tools/SafetyTools.ts +501 -579
  258. package/src/protocols/mcp/tools/TaskPlanningTools.ts +81 -39
  259. package/src/protocols/mcp/tools/TestTools.ts +339 -419
  260. package/src/protocols/mcp/tools/TypeScriptTools.ts +316 -376
  261. package/src/protocols/mcp/tools/WebTools.ts +209 -307
  262. package/src/protocols/mcp/tools/shell/ShellExecuteHandler.ts +53 -14
  263. package/src/schemas/EventPayloadSchema.ts +37 -0
  264. package/src/services/BackgroundTaskManager.ts +12 -4
  265. package/src/services/BrowserManager.ts +41 -1
  266. package/src/services/MemoryCompressor.ts +20 -32
  267. package/src/services/MemoryService.ts +96 -58
  268. package/src/services/PredictiveAnalyticsService.ts +55 -32
  269. package/src/services/QValueManager.ts +10 -0
  270. package/src/services/RewardSignalProcessor.ts +138 -9
  271. package/src/services/SharedStateService.ts +56 -8
  272. package/src/services/TaskEffectivenessService.ts +114 -187
  273. package/src/services/WebSearchService.ts +2 -1
  274. package/src/services/dag/TaskDagService.ts +2 -0
  275. package/src/services/orpar-memory/OrparMemoryCoordinator.ts +86 -10
  276. package/src/types/MemoryUtilityTypes.ts +2 -0
  277. package/src/utils/Logger.ts +116 -40
  278. package/src/utils/MxpEncryption.ts +69 -34
  279. package/dist/mxp/MxpEventForwardingEnhancer.d.ts +0 -134
  280. package/dist/mxp/MxpEventForwardingEnhancer.d.ts.map +0 -1
  281. package/dist/mxp/MxpEventForwardingEnhancer.js +0 -361
  282. package/dist/mxp/MxpEventForwardingEnhancer.js.map +0 -1
  283. package/dist/protocols/mcp/services/ToolSchemaEnhancements.d.ts +0 -56
  284. package/dist/protocols/mcp/services/ToolSchemaEnhancements.d.ts.map +0 -1
  285. package/dist/protocols/mcp/services/ToolSchemaEnhancements.js +0 -57
  286. package/dist/protocols/mcp/services/ToolSchemaEnhancements.js.map +0 -1
  287. package/dist/protocols/mcp/tools/ControlLoopLifecycle.d.ts +0 -270
  288. package/dist/protocols/mcp/tools/ControlLoopLifecycle.d.ts.map +0 -1
  289. package/dist/protocols/mcp/tools/ControlLoopLifecycle.js +0 -256
  290. package/dist/protocols/mcp/tools/ControlLoopLifecycle.js.map +0 -1
  291. package/dist/protocols/mcp/tools/LspTools.d.ts +0 -495
  292. package/dist/protocols/mcp/tools/LspTools.d.ts.map +0 -1
  293. package/dist/protocols/mcp/tools/LspTools.js +0 -469
  294. package/dist/protocols/mcp/tools/LspTools.js.map +0 -1
  295. package/src/mxp/MxpEventForwardingEnhancer.ts +0 -471
  296. package/src/protocols/mcp/services/ToolSchemaEnhancements.ts +0 -92
  297. package/src/protocols/mcp/tools/ControlLoopLifecycle.ts +0 -302
  298. package/src/protocols/mcp/tools/LspTools.ts +0 -476
@@ -35,7 +35,6 @@ import { Logger } from '../utils/Logger.js';
35
35
  import { createStrictValidator } from '../utils/validation.js';
36
36
  import {
37
37
  COMMUNICATION_TOOLS,
38
- CONTROL_LOOP_TOOLS,
39
38
  CONTEXT_MEMORY_TOOLS,
40
39
  META_TOOLS
41
40
  } from '../constants/ToolNames.js';
@@ -145,7 +144,7 @@ Execute immediately when you have sufficient information. Take decisive action b
145
144
  private static buildMxfIdentity(agentConfig: AgentConfig, availableTools?: string[]): string {
146
145
  // Determine available capabilities based on tools
147
146
  const toolSet = availableTools || [];
148
- const hasControlLoop = toolSet.some(tool => tool.startsWith('controlLoop_'));
147
+ const hasOrpar = toolSet.some(tool => tool.startsWith('orpar_'));
149
148
  const hasCommunication = toolSet.some(tool => tool.startsWith('messaging_') || tool.startsWith('agent_'));
150
149
  const hasMemoryContext = toolSet.some(tool => tool.includes('context_') || tool.includes('memory_'));
151
150
 
@@ -165,7 +164,7 @@ Execute immediately when you have sufficient information. Take decisive action b
165
164
  MXF enables you to collaborate with other AI agents`;
166
165
 
167
166
  // Only mention ORPAR if control loop tools are available
168
- if (hasControlLoop) {
167
+ if (hasOrpar) {
169
168
  content += `, execute complex workflows through ORPAR cognitive cycles,`;
170
169
  }
171
170
 
@@ -261,15 +260,18 @@ Use tools to take actions - the system will automatically execute your tool requ
261
260
  }
262
261
 
263
262
  // Control Loop - only if control loop tools are available
264
- const hasControlLoop = toolSet.some(tool => tool.startsWith('controlLoop_'));
265
- if (hasControlLoop) {
266
- const controlCapabilities: string[] = [];
267
- if (toolSet.includes('controlLoop_start')) controlCapabilities.push(`- **${CONTROL_LOOP_TOOLS.START}**: Start new ORPAR cognitive cycles`);
268
- if (toolSet.includes('controlLoop_observe')) controlCapabilities.push(`- **${CONTROL_LOOP_TOOLS.OBSERVE}**: Submit observations to active control loops`);
269
- if (toolSet.includes('controlLoop_execute')) controlCapabilities.push(`- **${CONTROL_LOOP_TOOLS.EXECUTE}**: Execute planned actions within control loops`);
270
-
271
- if (controlCapabilities.length > 0) {
272
- sections.push(`**Control Loop (ORPAR Integration):**\n${controlCapabilities.join('\n')}`);
263
+ const hasOrpar = toolSet.some(tool => tool.startsWith('orpar_'));
264
+ if (hasOrpar) {
265
+ const orparCapabilities: string[] = [];
266
+ if (toolSet.includes('orpar_observe')) orparCapabilities.push('- **orpar_observe**: Record what you observed, starting a cognitive cycle');
267
+ if (toolSet.includes('orpar_reason')) orparCapabilities.push('- **orpar_reason**: Record your reasoning about the observation');
268
+ if (toolSet.includes('orpar_plan')) orparCapabilities.push('- **orpar_plan**: Record the plan you intend to carry out');
269
+ if (toolSet.includes('orpar_act')) orparCapabilities.push('- **orpar_act**: Record the action you took');
270
+ if (toolSet.includes('orpar_reflect')) orparCapabilities.push('- **orpar_reflect**: Record what you learned, completing the cycle');
271
+ if (toolSet.includes('orpar_status')) orparCapabilities.push('- **orpar_status**: Check which phase of the cycle you are in');
272
+
273
+ if (orparCapabilities.length > 0) {
274
+ sections.push(`**ORPAR cognitive cycle:**\n${orparCapabilities.join('\n')}`);
273
275
  }
274
276
  }
275
277
 
@@ -304,43 +306,26 @@ Use tools to take actions - the system will automatically execute your tool requ
304
306
 
305
307
  /**
306
308
  * Detailed Tool Schemas with JSON Examples
307
- * Now respects allowedTools to only show documentation for tools the agent can actually use
309
+ * Only documents tools the registry actually provided and the agent is allowed to use.
308
310
  */
309
311
  private static async buildToolSchemas(config: MxfSystemPromptConfig, availableTools?: any[], toolNames?: string[], agentConfig?: AgentConfig): Promise<string> {
310
312
  if (!config.includeToolSchemas) return '';
311
313
 
312
- // Use provided tools from the actual tool registry
313
- let tools: any[] = availableTools || [];
314
+ // Tools come from the registry. Nothing else is a valid source.
315
+ //
316
+ // An earlier version, when handed no tools, invented them: it took the
317
+ // list of tool NAMES and built "mock tool objects" with made-up
318
+ // descriptions and guessed input schemas, then presented them to the
319
+ // agent as documentation. The agent then called those tools with the
320
+ // guessed arguments, producing malformed calls. If the registry has no
321
+ // tools, the honest output is no tool-schema section at all.
322
+ const tools: any[] = availableTools || [];
314
323
  if (tools.length === 0) {
315
- // Core tools fallback - create mock tool objects for allowed tools (or all core tools if no allowedTools)
316
- const toolsToMock = (toolNames && toolNames.length > 0) ? toolNames : CORE_MXF_TOOLS;
317
- tools = toolsToMock.map(toolName => ({
318
- name: toolName,
319
- description: `${toolName} - Core MXF ${toolName.includes('memory') ? 'Memory Management' : toolName.includes('messaging') ? 'Communication' : toolName.includes('controlLoop') ? 'ORPAR Control Loop' : toolName.includes('task') ? 'Task Management' : 'Meta'} tool`,
320
- inputSchema: {
321
- type: 'object',
322
- properties: {
323
- ...(toolName.includes('messaging') && {
324
- targetAgentId: { type: 'string' },
325
- message: { type: 'string' }
326
- }),
327
- ...(toolName.includes('memory') && {
328
- key: { type: 'string' },
329
- value: { type: 'string' }
330
- }),
331
- ...(toolName.includes('controlLoop') && {
332
- observation: { type: 'string' },
333
- confidence: { type: 'number' }
334
- }),
335
- ...(toolName === 'task_complete' && {
336
- summary: { type: 'string', required: true },
337
- success: { type: 'boolean', default: true },
338
- details: { type: 'object', optional: true },
339
- nextSteps: { type: 'string', optional: true }
340
- })
341
- }
342
- }
343
- }));
324
+ logger.error(
325
+ 'SYSTEM PROMPT: the tool registry returned no tools, so no tool schemas can be documented. ' +
326
+ 'Check that the agent has tools registered and that allowedTools is not empty.'
327
+ );
328
+ return '';
344
329
  }
345
330
 
346
331
  // Deduplicate tools by name (keep first occurrence)
@@ -370,8 +355,13 @@ Use tools to take actions - the system will automatically execute your tool requ
370
355
  const finalToolsForDocumentation = mxfCoreTools;
371
356
 
372
357
  if (finalToolsForDocumentation.length === 0) {
373
- logger.error('❌ SYSTEM PROMPT: No allowed tools found for this agent - this indicates a configuration issue');
374
- return '## Tool Usage Reference\n\n❌ **ERROR: No allowed tools found**\n\nThis agent has no tools configured in its allowedTools list.';
358
+ // Emit no section rather than writing an error notice into the
359
+ // agent's system prompt, which the model would read as instructions.
360
+ logger.error(
361
+ 'SYSTEM PROMPT: none of the registry tools match this agent\'s allowedTools, ' +
362
+ 'so no tool schemas can be documented. This is a configuration issue.'
363
+ );
364
+ return '';
375
365
  }
376
366
 
377
367
  // Apply deferred tool schema disclosure if enabled — tier-2 tools get
@@ -400,7 +390,7 @@ Use tools to take actions - the system will automatically execute your tool requ
400
390
 
401
391
  // Group allowed tools by category (only show documentation for tools this agent can actually use)
402
392
  const communicationTools = toolsForFullDocs.filter(t => t.name.startsWith('messaging_'));
403
- const controlLoopTools = toolsForFullDocs.filter(t => t.name.startsWith('controlLoop_'));
393
+ const orparTools = toolsForFullDocs.filter(t => t.name.startsWith('orpar_'));
404
394
  const infrastructureTools = toolsForFullDocs.filter(t =>
405
395
  t.name === 'filesystem_read' || t.name === 'filesystem_write' ||
406
396
  t.name === 'filesystem_list' || t.name === 'shell_execute' ||
@@ -424,9 +414,9 @@ Use tools to take actions - the system will automatically execute your tool requ
424
414
  }
425
415
 
426
416
  // Control Loop Tools Section
427
- if (controlLoopTools.length > 0) {
417
+ if (orparTools.length > 0) {
428
418
  toolSections.push('### Control Loop Tools\n');
429
- for (const tool of controlLoopTools) {
419
+ for (const tool of orparTools) {
430
420
  toolSections.push(this.buildToolExample(tool, agentConfig?.mxpEnabled, compactionConfig.toolBehavioralGuidanceEnabled));
431
421
  }
432
422
  }
@@ -534,12 +524,12 @@ ${toolSections.join('\n')}${deferredSummary}`;
534
524
  }
535
525
 
536
526
  // Pattern 2: ORPAR Integration - only if control loop tools are available
537
- const hasControlLoop = toolSet.some(tool => tool.startsWith('controlLoop_'));
538
- if (hasControlLoop) {
539
- const observeTool = toolSet.find(tool => tool === 'controlLoop_observe');
527
+ const hasOrpar = toolSet.some(tool => tool.startsWith('orpar_'));
528
+ if (hasOrpar) {
529
+ const observeTool = toolSet.find(tool => tool === 'orpar_observe');
540
530
  if (observeTool) {
541
531
  sections.push(`**Pattern 2: ORPAR Integration**
542
- - Submit observations using 'controlLoop_observe'
532
+ - Submit observations using 'orpar_observe'
543
533
  - Include confidence scores and data sources
544
534
  - Provide rich metadata for better reasoning`);
545
535
  }
@@ -638,9 +628,9 @@ When you need capabilities beyond your core tools:
638
628
 
639
629
  // Only include ORPAR if control loop tools are available
640
630
  const toolSet = availableTools || [];
641
- const hasControlLoop = toolSet.some(tool => tool.startsWith('controlLoop_'));
631
+ const hasOrpar = toolSet.some(tool => tool.startsWith('orpar_'));
642
632
 
643
- if (!hasControlLoop) return '';
633
+ if (!hasOrpar) return '';
644
634
 
645
635
  return `## MXF Operational Guidelines
646
636
 
@@ -0,0 +1,201 @@
1
+ /**
2
+ * Copyright 2024 Brad Anderson
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ * @author Brad Anderson <BradA1878@pm.me>
17
+ * @repository https://github.com/BradA1878/model-exchange-framework
18
+ * @documentation https://mxf-dev.github.io/mxf/
19
+ */
20
+
21
+ /**
22
+ * ToolError.ts
23
+ *
24
+ * The single error type for MCP tool handlers.
25
+ *
26
+ * Before this existed, tool failures were encoded three different ways — a thrown
27
+ * Error, a `{ success: false }` object, or a result whose `data` happened to hold
28
+ * an `error` string — so callers could not tell a failure from a result. Handlers
29
+ * written with `defineTool` throw a ToolError; the factory turns it into one
30
+ * result envelope with `isError: true`.
31
+ *
32
+ * `code` is a stable, machine-readable classification. `message` is written for
33
+ * the model that will read it: say what failed and what to do next.
34
+ */
35
+
36
+ /**
37
+ * Machine-readable failure classifications.
38
+ *
39
+ * These map to how a caller should react, not to where the failure happened:
40
+ * - INVALID_INPUT: arguments did not satisfy the tool's schema or its own checks.
41
+ * The model should fix the arguments and retry.
42
+ * - NOT_FOUND: a referenced entity (task, plan, file, server) does not exist.
43
+ * - PERMISSION_DENIED: the operation was blocked by a security policy.
44
+ * - PRECONDITION_FAILED: the system is not in a state where this can run
45
+ * (for example a required service is not initialized).
46
+ * - EXECUTION_FAILED: the tool ran but the underlying operation failed.
47
+ * - UPSTREAM_ERROR: a dependency the tool calls out to failed (external MCP
48
+ * server, HTTP API, database).
49
+ * - NOT_IMPLEMENTED: the requested mode or option is not supported.
50
+ */
51
+ export type ToolErrorCode =
52
+ | 'INVALID_INPUT'
53
+ | 'NOT_FOUND'
54
+ | 'PERMISSION_DENIED'
55
+ | 'PRECONDITION_FAILED'
56
+ | 'EXECUTION_FAILED'
57
+ | 'UPSTREAM_ERROR'
58
+ | 'NOT_IMPLEMENTED';
59
+
60
+ /**
61
+ * Serialized form of a ToolError, carried as the `data` of an error envelope.
62
+ */
63
+ export interface ToolErrorData {
64
+ /** Always true — lets a reader detect an error payload without shape sniffing */
65
+ error: true;
66
+ /** Stable classification */
67
+ code: ToolErrorCode;
68
+ /** Human/model-readable description of what failed */
69
+ message: string;
70
+ /** Name of the tool that failed */
71
+ tool?: string;
72
+ /** Structured, tool-specific context (never secrets) */
73
+ details?: Record<string, unknown>;
74
+ }
75
+
76
+ /**
77
+ * The error type thrown by tool handlers.
78
+ *
79
+ * Use the static constructors rather than `new ToolError(...)` where one fits —
80
+ * they keep codes consistent across the ~184 tools.
81
+ */
82
+ export class ToolError extends Error {
83
+ /** Stable, machine-readable classification */
84
+ public readonly code: ToolErrorCode;
85
+ /** Structured context for the caller. Must not contain secrets. */
86
+ public readonly details?: Record<string, unknown>;
87
+ /**
88
+ * The original error, when this ToolError wraps one.
89
+ *
90
+ * Set as a plain property rather than through the ES2022 `Error(msg, { cause })`
91
+ * option, because the test tsconfig compiles against an older lib where that
92
+ * constructor overload does not exist.
93
+ */
94
+ public readonly cause?: unknown;
95
+ /** Tool name, set by defineTool when the error passes through the factory */
96
+ public toolName?: string;
97
+
98
+ constructor(
99
+ code: ToolErrorCode,
100
+ message: string,
101
+ options?: { details?: Record<string, unknown>; cause?: unknown }
102
+ ) {
103
+ super(message);
104
+ this.name = 'ToolError';
105
+ this.code = code;
106
+ this.details = options?.details;
107
+ this.cause = options?.cause;
108
+
109
+ // Restore the prototype chain — required for `instanceof` to work when
110
+ // the compile target is ES5/ES2015 and Error is subclassed.
111
+ Object.setPrototypeOf(this, ToolError.prototype);
112
+ }
113
+
114
+ /** Arguments did not satisfy the schema or the handler's own checks. */
115
+ public static invalidInput(
116
+ message: string,
117
+ details?: Record<string, unknown>
118
+ ): ToolError {
119
+ return new ToolError('INVALID_INPUT', message, { details });
120
+ }
121
+
122
+ /** A referenced entity does not exist. */
123
+ public static notFound(
124
+ message: string,
125
+ details?: Record<string, unknown>
126
+ ): ToolError {
127
+ return new ToolError('NOT_FOUND', message, { details });
128
+ }
129
+
130
+ /** Blocked by a security policy. */
131
+ public static permissionDenied(
132
+ message: string,
133
+ details?: Record<string, unknown>
134
+ ): ToolError {
135
+ return new ToolError('PERMISSION_DENIED', message, { details });
136
+ }
137
+
138
+ /** The system is not in a state where this operation can run. */
139
+ public static preconditionFailed(
140
+ message: string,
141
+ details?: Record<string, unknown>
142
+ ): ToolError {
143
+ return new ToolError('PRECONDITION_FAILED', message, { details });
144
+ }
145
+
146
+ /** The tool ran but the underlying operation failed. */
147
+ public static executionFailed(
148
+ message: string,
149
+ options?: { details?: Record<string, unknown>; cause?: unknown }
150
+ ): ToolError {
151
+ return new ToolError('EXECUTION_FAILED', message, options);
152
+ }
153
+
154
+ /** A dependency the tool calls out to failed. */
155
+ public static upstream(
156
+ message: string,
157
+ options?: { details?: Record<string, unknown>; cause?: unknown }
158
+ ): ToolError {
159
+ return new ToolError('UPSTREAM_ERROR', message, options);
160
+ }
161
+
162
+ /** The requested mode or option is not supported. */
163
+ public static notImplemented(
164
+ message: string,
165
+ details?: Record<string, unknown>
166
+ ): ToolError {
167
+ return new ToolError('NOT_IMPLEMENTED', message, { details });
168
+ }
169
+
170
+ /**
171
+ * Serialize to the payload carried in an error result envelope.
172
+ */
173
+ public toData(): ToolErrorData {
174
+ return {
175
+ error: true,
176
+ code: this.code,
177
+ message: this.message,
178
+ ...(this.toolName ? { tool: this.toolName } : {}),
179
+ ...(this.details ? { details: this.details } : {})
180
+ };
181
+ }
182
+ }
183
+
184
+ /**
185
+ * Coerce any thrown value into a ToolError.
186
+ *
187
+ * A plain `throw new Error(...)` from a handler (or from a library it calls)
188
+ * becomes an EXECUTION_FAILED ToolError with the original attached as `cause`,
189
+ * so every failure leaves the factory in the same shape.
190
+ */
191
+ export function toToolError(thrown: unknown): ToolError {
192
+ if (thrown instanceof ToolError) {
193
+ return thrown;
194
+ }
195
+
196
+ if (thrown instanceof Error) {
197
+ return new ToolError('EXECUTION_FAILED', thrown.message, { cause: thrown });
198
+ }
199
+
200
+ return new ToolError('EXECUTION_FAILED', String(thrown), { cause: thrown });
201
+ }