@noorm/marie-cli 0.1.17 → 0.1.25

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 (299) hide show
  1. package/README.md +7 -15
  2. package/SENTINEL.md +4 -7
  3. package/dist/cli-new/components/AgenticSpinner.js +28 -0
  4. package/dist/cli-new/components/AgenticSpinner.js.map +1 -0
  5. package/dist/cli-new/components/App.js +16 -63
  6. package/dist/cli-new/components/App.js.map +1 -1
  7. package/dist/cli-new/components/ApprovalDialog.js +3 -2
  8. package/dist/cli-new/components/ApprovalDialog.js.map +1 -1
  9. package/dist/cli-new/components/Banner.js +16 -5
  10. package/dist/cli-new/components/Banner.js.map +1 -1
  11. package/dist/cli-new/components/ChatArea.js +6 -7
  12. package/dist/cli-new/components/ChatArea.js.map +1 -1
  13. package/dist/cli-new/components/Header.js +14 -8
  14. package/dist/cli-new/components/Header.js.map +1 -1
  15. package/dist/cli-new/components/InputArea.js +98 -31
  16. package/dist/cli-new/components/InputArea.js.map +1 -1
  17. package/dist/cli-new/components/MessageBubble.js +28 -19
  18. package/dist/cli-new/components/MessageBubble.js.map +1 -1
  19. package/dist/cli-new/components/SessionSwitcher.js +6 -9
  20. package/dist/cli-new/components/SessionSwitcher.js.map +1 -1
  21. package/dist/cli-new/components/SetupWizard.js +80 -257
  22. package/dist/cli-new/components/SetupWizard.js.map +1 -1
  23. package/dist/cli-new/components/ToolCallDisplay.js +20 -5
  24. package/dist/cli-new/components/ToolCallDisplay.js.map +1 -1
  25. package/dist/cli-new/components/WizardSteps.js +22 -0
  26. package/dist/cli-new/components/WizardSteps.js.map +1 -0
  27. package/dist/cli-new/constants/SetupConstants.js +42 -0
  28. package/dist/cli-new/constants/SetupConstants.js.map +1 -0
  29. package/dist/cli-new/hooks/useGit.js +19 -62
  30. package/dist/cli-new/hooks/useGit.js.map +1 -1
  31. package/dist/cli-new/hooks/useMarie.js +26 -18
  32. package/dist/cli-new/hooks/useMarie.js.map +1 -1
  33. package/dist/cli-new/hooks/useSessions.js +1 -1
  34. package/dist/cli-new/hooks/useSessions.js.map +1 -1
  35. package/dist/cli-new/hooks/useSetupWizard.js +88 -0
  36. package/dist/cli-new/hooks/useSetupWizard.js.map +1 -0
  37. package/dist/cli-new/hooks/useUpdateCheck.js +4 -3
  38. package/dist/cli-new/hooks/useUpdateCheck.js.map +1 -1
  39. package/dist/cli-new/index.js +2 -4
  40. package/dist/cli-new/index.js.map +1 -1
  41. package/dist/cli-new/services/CommandService.js +104 -0
  42. package/dist/cli-new/services/CommandService.js.map +1 -0
  43. package/dist/cli-new/services/GitService.js +91 -0
  44. package/dist/cli-new/services/GitService.js.map +1 -0
  45. package/dist/cli-new/services/MarieService.js +77 -0
  46. package/dist/cli-new/services/MarieService.js.map +1 -0
  47. package/dist/cli-new/services/auth-server.js +128 -0
  48. package/dist/cli-new/services/auth-server.js.map +1 -0
  49. package/dist/cli-new/styles/theme.js +17 -17
  50. package/dist/cli-new/styles/theme.js.map +1 -1
  51. package/dist/cli-new/utils/version.js +24 -0
  52. package/dist/cli-new/utils/version.js.map +1 -0
  53. package/dist/monolith/adapters/CliMarieAdapter.js +19 -18
  54. package/dist/monolith/adapters/CliMarieAdapter.js.map +1 -1
  55. package/dist/monolith/cli/CliFileSystemPort.js +17 -3
  56. package/dist/monolith/cli/CliFileSystemPort.js.map +1 -1
  57. package/dist/monolith/cli/MarieToolDefinitionsCLI.js +44 -33
  58. package/dist/monolith/cli/MarieToolDefinitionsCLI.js.map +1 -1
  59. package/dist/monolith/cli/index.js +11 -20
  60. package/dist/monolith/cli/index.js.map +1 -1
  61. package/dist/monolith/cli/services/JoyAutomationServiceCLI.js +15 -62
  62. package/dist/monolith/cli/services/JoyAutomationServiceCLI.js.map +1 -1
  63. package/dist/monolith/cli/storage.js +154 -65
  64. package/dist/monolith/cli/storage.js.map +1 -1
  65. package/dist/monolith/domain/joy/RitualService.js +44 -46
  66. package/dist/monolith/domain/joy/RitualService.js.map +1 -1
  67. package/dist/monolith/domain/marie/MarieCortex.js +148 -0
  68. package/dist/monolith/domain/marie/MarieCortex.js.map +1 -0
  69. package/dist/monolith/domain/marie/PersonalityRenderer.js +97 -0
  70. package/dist/monolith/domain/marie/PersonalityRenderer.js.map +1 -0
  71. package/dist/monolith/infrastructure/Configuration.js +68 -0
  72. package/dist/monolith/infrastructure/Configuration.js.map +1 -0
  73. package/dist/monolith/infrastructure/CoreInfrastructure.js +204 -0
  74. package/dist/monolith/infrastructure/CoreInfrastructure.js.map +1 -0
  75. package/dist/monolith/infrastructure/ai/agents/MarieAscendant.js +3 -3
  76. package/dist/monolith/infrastructure/ai/agents/MarieAscendant.js.map +1 -1
  77. package/dist/monolith/infrastructure/ai/context/ContextArchiveService.js +51 -57
  78. package/dist/monolith/infrastructure/ai/context/ContextArchiveService.js.map +1 -1
  79. package/dist/monolith/infrastructure/ai/context/ContextManager.js +142 -98
  80. package/dist/monolith/infrastructure/ai/context/ContextManager.js.map +1 -1
  81. package/dist/monolith/infrastructure/ai/core/MarieEngine.js +104 -556
  82. package/dist/monolith/infrastructure/ai/core/MarieEngine.js.map +1 -1
  83. package/dist/monolith/infrastructure/ai/core/MarieEventDispatcher.js +1 -37
  84. package/dist/monolith/infrastructure/ai/core/MarieEventDispatcher.js.map +1 -1
  85. package/dist/monolith/infrastructure/ai/core/MarieLockManager.js +30 -5
  86. package/dist/monolith/infrastructure/ai/core/MarieLockManager.js.map +1 -1
  87. package/dist/monolith/infrastructure/ai/core/MarieProgressTracker.js +176 -196
  88. package/dist/monolith/infrastructure/ai/core/MarieProgressTracker.js.map +1 -1
  89. package/dist/monolith/infrastructure/ai/core/MariePulseService.js +41 -7
  90. package/dist/monolith/infrastructure/ai/core/MariePulseService.js.map +1 -1
  91. package/dist/monolith/infrastructure/ai/core/MarieSanitizer.js +303 -63
  92. package/dist/monolith/infrastructure/ai/core/MarieSanitizer.js.map +1 -1
  93. package/dist/monolith/infrastructure/ai/core/MarieSemaphore.js +47 -4
  94. package/dist/monolith/infrastructure/ai/core/MarieSemaphore.js.map +1 -1
  95. package/dist/monolith/infrastructure/ai/core/MarieSession.js +95 -15
  96. package/dist/monolith/infrastructure/ai/core/MarieSession.js.map +1 -1
  97. package/dist/monolith/infrastructure/ai/core/MarieStabilityMonitor.js +21 -0
  98. package/dist/monolith/infrastructure/ai/core/MarieStabilityMonitor.js.map +1 -1
  99. package/dist/monolith/infrastructure/ai/core/MarieToolMender.js +12 -0
  100. package/dist/monolith/infrastructure/ai/core/MarieToolMender.js.map +1 -1
  101. package/dist/monolith/infrastructure/ai/core/MarieToolProcessor.js +339 -481
  102. package/dist/monolith/infrastructure/ai/core/MarieToolProcessor.js.map +1 -1
  103. package/dist/monolith/infrastructure/ai/core/MarieVitality.js +238 -0
  104. package/dist/monolith/infrastructure/ai/core/MarieVitality.js.map +1 -0
  105. package/dist/monolith/infrastructure/ai/core/ReasoningBudget.js +23 -12
  106. package/dist/monolith/infrastructure/ai/core/ReasoningBudget.js.map +1 -1
  107. package/dist/monolith/infrastructure/ai/core/SessionLogService.js +9 -2
  108. package/dist/monolith/infrastructure/ai/core/SessionLogService.js.map +1 -1
  109. package/dist/monolith/infrastructure/ai/providers/AIProvider.js +402 -1
  110. package/dist/monolith/infrastructure/ai/providers/AIProvider.js.map +1 -1
  111. package/dist/monolith/infrastructure/ai/providers/DreamBeesProvider.js +114 -0
  112. package/dist/monolith/infrastructure/ai/providers/DreamBeesProvider.js.map +1 -0
  113. package/dist/monolith/infrastructure/ai/providers/OpenRouterProvider.js +426 -370
  114. package/dist/monolith/infrastructure/ai/providers/OpenRouterProvider.js.map +1 -1
  115. package/dist/monolith/infrastructure/ai/providers/OpenRouterStreamParser.js +235 -241
  116. package/dist/monolith/infrastructure/ai/providers/OpenRouterStreamParser.js.map +1 -1
  117. package/dist/monolith/infrastructure/ai/workerAi.js +185 -0
  118. package/dist/monolith/infrastructure/ai/workerAi.js.map +1 -0
  119. package/dist/monolith/infrastructure/config/ConfigService.js +216 -359
  120. package/dist/monolith/infrastructure/config/ConfigService.js.map +1 -1
  121. package/dist/monolith/infrastructure/joy/CognitiveRituals.js +8 -0
  122. package/dist/monolith/infrastructure/joy/CognitiveRituals.js.map +1 -0
  123. package/dist/monolith/infrastructure/joy/JoyTools.js +23 -43
  124. package/dist/monolith/infrastructure/joy/JoyTools.js.map +1 -1
  125. package/dist/monolith/infrastructure/persistence/MarieMindAutonomics.js +4 -0
  126. package/dist/monolith/infrastructure/persistence/MarieMindAutonomics.js.map +1 -0
  127. package/dist/monolith/infrastructure/persistence/MarieMindEngine.js +11 -0
  128. package/dist/monolith/infrastructure/persistence/MarieMindEngine.js.map +1 -0
  129. package/dist/monolith/infrastructure/persistence/NoormmeAutonomics.js +135 -0
  130. package/dist/monolith/infrastructure/persistence/NoormmeAutonomics.js.map +1 -0
  131. package/dist/monolith/infrastructure/persistence/NoormmeEngine.js +523 -0
  132. package/dist/monolith/infrastructure/persistence/NoormmeEngine.js.map +1 -0
  133. package/dist/monolith/infrastructure/persistence/NoormmeSchema.js +179 -0
  134. package/dist/monolith/infrastructure/persistence/NoormmeSchema.js.map +1 -0
  135. package/dist/monolith/infrastructure/persistence/NoormmeSeeder.js +94 -0
  136. package/dist/monolith/infrastructure/persistence/NoormmeSeeder.js.map +1 -0
  137. package/dist/monolith/infrastructure/persistence/NoormmeTools.js +371 -0
  138. package/dist/monolith/infrastructure/persistence/NoormmeTools.js.map +1 -0
  139. package/dist/monolith/infrastructure/services/MarieMemoryStore.js +133 -134
  140. package/dist/monolith/infrastructure/services/MarieMemoryStore.js.map +1 -1
  141. package/dist/monolith/infrastructure/tools/MarieToolDefinitions.js +6 -1578
  142. package/dist/monolith/infrastructure/tools/MarieToolDefinitions.js.map +1 -1
  143. package/dist/monolith/infrastructure/tools/PureStreamParser.js +68 -80
  144. package/dist/monolith/infrastructure/tools/PureStreamParser.js.map +1 -1
  145. package/dist/monolith/infrastructure/tools/SharedToolDefinitions.js +12 -11
  146. package/dist/monolith/infrastructure/tools/SharedToolDefinitions.js.map +1 -1
  147. package/dist/monolith/infrastructure/tools/SovereignTools.js +326 -0
  148. package/dist/monolith/infrastructure/tools/SovereignTools.js.map +1 -0
  149. package/dist/monolith/infrastructure/tools/ToolRegistry.js +45 -26
  150. package/dist/monolith/infrastructure/tools/ToolRegistry.js.map +1 -1
  151. package/dist/monolith/infrastructure/tools/definitions/AnalysisTools.js +232 -0
  152. package/dist/monolith/infrastructure/tools/definitions/AnalysisTools.js.map +1 -0
  153. package/dist/monolith/infrastructure/tools/definitions/AutomationTools.js +274 -0
  154. package/dist/monolith/infrastructure/tools/definitions/AutomationTools.js.map +1 -0
  155. package/dist/monolith/infrastructure/tools/definitions/ContextTools.js +71 -0
  156. package/dist/monolith/infrastructure/tools/definitions/ContextTools.js.map +1 -0
  157. package/dist/monolith/infrastructure/tools/definitions/CoreTools.js +37 -0
  158. package/dist/monolith/infrastructure/tools/definitions/CoreTools.js.map +1 -0
  159. package/dist/monolith/infrastructure/tools/definitions/DiagnosticTools.js +154 -0
  160. package/dist/monolith/infrastructure/tools/definitions/DiagnosticTools.js.map +1 -0
  161. package/dist/monolith/infrastructure/tools/definitions/NavigationTools.js +197 -0
  162. package/dist/monolith/infrastructure/tools/definitions/NavigationTools.js.map +1 -0
  163. package/dist/monolith/infrastructure/tools/definitions/PlanningTools.js +300 -0
  164. package/dist/monolith/infrastructure/tools/definitions/PlanningTools.js.map +1 -0
  165. package/dist/monolith/plumbing/Plumbing.js +238 -0
  166. package/dist/monolith/plumbing/Plumbing.js.map +1 -0
  167. package/dist/monolith/plumbing/PlumbingAnalysis.js +109 -0
  168. package/dist/monolith/plumbing/PlumbingAnalysis.js.map +1 -0
  169. package/dist/monolith/plumbing/PlumbingSystem.js +169 -0
  170. package/dist/monolith/plumbing/PlumbingSystem.js.map +1 -0
  171. package/dist/monolith/plumbing/analysis/ComplexityService.js +30 -34
  172. package/dist/monolith/plumbing/analysis/ComplexityService.js.map +1 -1
  173. package/dist/monolith/plumbing/analysis/DependencyService.js +55 -44
  174. package/dist/monolith/plumbing/analysis/DependencyService.js.map +1 -1
  175. package/dist/monolith/plumbing/analysis/DiscoveryService.js +40 -42
  176. package/dist/monolith/plumbing/analysis/DiscoveryService.js.map +1 -1
  177. package/dist/monolith/plumbing/analysis/JoyMapService.js +52 -56
  178. package/dist/monolith/plumbing/analysis/JoyMapService.js.map +1 -1
  179. package/dist/monolith/plumbing/analysis/LintService.js +118 -118
  180. package/dist/monolith/plumbing/analysis/LintService.js.map +1 -1
  181. package/dist/monolith/plumbing/analysis/MarieSentinelService.js +278 -269
  182. package/dist/monolith/plumbing/analysis/MarieSentinelService.js.map +1 -1
  183. package/dist/monolith/plumbing/analysis/QualityGuardrailService.js +116 -114
  184. package/dist/monolith/plumbing/analysis/QualityGuardrailService.js.map +1 -1
  185. package/dist/monolith/plumbing/analysis/SurgicalMender.js +57 -59
  186. package/dist/monolith/plumbing/analysis/SurgicalMender.js.map +1 -1
  187. package/dist/monolith/plumbing/analysis/TestService.js +89 -89
  188. package/dist/monolith/plumbing/analysis/TestService.js.map +1 -1
  189. package/dist/monolith/plumbing/filesystem/FileService.js +123 -195
  190. package/dist/monolith/plumbing/filesystem/FileService.js.map +1 -1
  191. package/dist/monolith/plumbing/filesystem/PathResolver.js +7 -8
  192. package/dist/monolith/plumbing/filesystem/PathResolver.js.map +1 -1
  193. package/dist/monolith/plumbing/git/GitService.js +4 -4
  194. package/dist/monolith/plumbing/git/GitService.js.map +1 -1
  195. package/dist/monolith/plumbing/lsp/SymbolService.js +5 -34
  196. package/dist/monolith/plumbing/lsp/SymbolService.js.map +1 -1
  197. package/dist/monolith/plumbing/terminal/ProcessRegistry.js +20 -22
  198. package/dist/monolith/plumbing/terminal/ProcessRegistry.js.map +1 -1
  199. package/dist/monolith/plumbing/terminal/TerminalService.js +127 -136
  200. package/dist/monolith/plumbing/terminal/TerminalService.js.map +1 -1
  201. package/dist/monolith/plumbing/utils/EnvironmentUtils.js +3 -23
  202. package/dist/monolith/plumbing/utils/EnvironmentUtils.js.map +1 -1
  203. package/dist/monolith/plumbing/utils/JsonUtils.js +252 -311
  204. package/dist/monolith/plumbing/utils/JsonUtils.js.map +1 -1
  205. package/dist/monolith/plumbing/utils/MutexUtils.js.map +1 -1
  206. package/dist/monolith/plumbing/utils/PlumbingCore.js +549 -0
  207. package/dist/monolith/plumbing/utils/PlumbingCore.js.map +1 -0
  208. package/dist/monolith/plumbing/utils/PrefixTree.js +61 -114
  209. package/dist/monolith/plumbing/utils/PrefixTree.js.map +1 -1
  210. package/dist/monolith/plumbing/utils/StreamTagDetector.js +89 -127
  211. package/dist/monolith/plumbing/utils/StreamTagDetector.js.map +1 -1
  212. package/dist/monolith/plumbing/utils/StringUtils.js +87 -89
  213. package/dist/monolith/plumbing/utils/StringUtils.js.map +1 -1
  214. package/dist/monolith/runtime/MarieRuntime.js +76 -417
  215. package/dist/monolith/runtime/MarieRuntime.js.map +1 -1
  216. package/dist/monolith/runtime/RuntimeAdapterBase.js +1 -1
  217. package/dist/monolith/runtime/RuntimeAdapterBase.js.map +1 -1
  218. package/dist/monolith/runtime/providerFactory.js +1 -7
  219. package/dist/monolith/runtime/providerFactory.js.map +1 -1
  220. package/dist/monolith/services/HealthService.js +29 -32
  221. package/dist/monolith/services/HealthService.js.map +1 -1
  222. package/dist/monolith/services/JoyAutomationService.js +58 -95
  223. package/dist/monolith/services/JoyAutomationService.js.map +1 -1
  224. package/dist/monolith/services/MarieAutomationService.js +59 -0
  225. package/dist/monolith/services/MarieAutomationService.js.map +1 -0
  226. package/dist/monolith/services/MarieGhostService.js +46 -161
  227. package/dist/monolith/services/MarieGhostService.js.map +1 -1
  228. package/dist/monolith/services/MarieServices.js +102 -0
  229. package/dist/monolith/services/MarieServices.js.map +1 -0
  230. package/dist/monolith/services/MarieTypes.js +2 -0
  231. package/dist/monolith/services/MarieTypes.js.map +1 -0
  232. package/dist/monolith/services/UpdateService.js +47 -49
  233. package/dist/monolith/services/UpdateService.js.map +1 -1
  234. package/dist/prompts.js +11 -5
  235. package/dist/prompts.js.map +1 -1
  236. package/dist/test_prefix_tree.js +9 -9
  237. package/dist/test_prefix_tree.js.map +1 -1
  238. package/package.json +18 -88
  239. package/run_test.js +5 -0
  240. package/.marie_visual_verify_1771225696548/progress_bar_check.txt +0 -1
  241. package/dist/extension.cjs +0 -635
  242. package/dist/extension.js +0 -473
  243. package/dist/extension.js.map +0 -1
  244. package/dist/monolith/adapters/VscodeMarieAdapter.js +0 -81
  245. package/dist/monolith/adapters/VscodeMarieAdapter.js.map +0 -1
  246. package/dist/monolith/domain/joy/JoyTools.js +0 -535
  247. package/dist/monolith/domain/joy/JoyTools.js.map +0 -1
  248. package/dist/monolith/infrastructure/ai/agents/MarieYOLO.js +0 -207
  249. package/dist/monolith/infrastructure/ai/agents/MarieYOLO.js.map +0 -1
  250. package/dist/monolith/infrastructure/ai/core/GhostPort.js +0 -2
  251. package/dist/monolith/infrastructure/ai/core/GhostPort.js.map +0 -1
  252. package/dist/monolith/infrastructure/ai/core/MarieYOLOTypes.js +0 -2
  253. package/dist/monolith/infrastructure/ai/core/MarieYOLOTypes.js.map +0 -1
  254. package/dist/monolith/infrastructure/ai/core/VscodeFileSystemPort.js +0 -33
  255. package/dist/monolith/infrastructure/ai/core/VscodeFileSystemPort.js.map +0 -1
  256. package/dist/monolith/infrastructure/ai/providers/AnthropicProvider.js +0 -148
  257. package/dist/monolith/infrastructure/ai/providers/AnthropicProvider.js.map +0 -1
  258. package/dist/monolith/infrastructure/ai/providers/CerebrasProvider.js +0 -208
  259. package/dist/monolith/infrastructure/ai/providers/CerebrasProvider.js.map +0 -1
  260. package/dist/monolith/plumbing/ui/DecorationService.js +0 -54
  261. package/dist/monolith/plumbing/ui/DecorationService.js.map +0 -1
  262. package/dist/monolith/services/JoyLogService.js +0 -48
  263. package/dist/monolith/services/JoyLogService.js.map +0 -1
  264. package/dist/monolith/services/JoyService.js +0 -209
  265. package/dist/monolith/services/JoyService.js.map +0 -1
  266. package/dist/monolith/services/MarieSCMProvider.js +0 -41
  267. package/dist/monolith/services/MarieSCMProvider.js.map +0 -1
  268. package/dist/test_agent_stream_control_plane.js +0 -170
  269. package/dist/test_agent_stream_control_plane.js.map +0 -1
  270. package/dist/test_strategy_integration.js +0 -114
  271. package/dist/test_strategy_integration.js.map +0 -1
  272. package/dist/test_streaming_fragility.js +0 -191
  273. package/dist/test_streaming_fragility.js.map +0 -1
  274. package/dist/webview-ui/App.js +0 -16
  275. package/dist/webview-ui/App.js.map +0 -1
  276. package/dist/webview-ui/Providers.js +0 -6
  277. package/dist/webview-ui/Providers.js.map +0 -1
  278. package/dist/webview-ui/components/ApprovalPanel.js +0 -8
  279. package/dist/webview-ui/components/ApprovalPanel.js.map +0 -1
  280. package/dist/webview-ui/components/ChatPanel.js +0 -19
  281. package/dist/webview-ui/components/ChatPanel.js.map +0 -1
  282. package/dist/webview-ui/components/Composer.js +0 -19
  283. package/dist/webview-ui/components/Composer.js.map +0 -1
  284. package/dist/webview-ui/components/HeaderBar.js +0 -5
  285. package/dist/webview-ui/components/HeaderBar.js.map +0 -1
  286. package/dist/webview-ui/components/SessionList.js +0 -14
  287. package/dist/webview-ui/components/SessionList.js.map +0 -1
  288. package/dist/webview-ui/context/WebviewStateContext.js +0 -146
  289. package/dist/webview-ui/context/WebviewStateContext.js.map +0 -1
  290. package/dist/webview-ui/main.css +0 -1
  291. package/dist/webview-ui/main.js +0 -108
  292. package/dist/webview-ui/main.js.map +0 -1
  293. package/dist/webview-ui/types.js +0 -2
  294. package/dist/webview-ui/types.js.map +0 -1
  295. package/dist/webview-ui/vscode.js +0 -4
  296. package/dist/webview-ui/vscode.js.map +0 -1
  297. package/lint_output.txt +0 -705
  298. package/lint_output_v2.txt +0 -711
  299. package/marie-coder-0.1.16.vsix +0 -0
@@ -1,587 +1,135 @@
1
- import path from "path";
2
- import { MarieSession } from "./MarieSession.js";
3
- import { MarieEventDispatcher } from "./MarieEventDispatcher.js";
4
- import { MarieToolProcessor } from "./MarieToolProcessor.js";
5
- import { MarieAscendant } from "../agents/MarieAscendant.js";
6
- import { MarieLockManager } from "./MarieLockManager.js";
7
- import { MarieToolMender } from "./MarieToolMender.js";
8
- import { MariePulseService } from "./MariePulseService.js";
9
- import { MarieStabilityMonitor } from "./MarieStabilityMonitor.js";
10
- import { ReasoningBudget } from "./ReasoningBudget.js";
11
- import { SessionLogService } from "./SessionLogService.js";
12
- import { MarieSemaphore } from "./MarieSemaphore.js";
13
- export function getPromptProfileForDepth(depth) {
14
- return depth > 0 ? "continuation" : "full";
15
- }
16
- /**
17
- * Entry point for the AI Engine. YOLO Supremacy Edition.
18
- */
1
+ import { getTool, getRegisteredTools } from "../../tools/SovereignTools.js";
2
+ import { getModel, getMaxRecursiveDepth, } from "../../Configuration.js";
3
+ import { manageContext } from "../../CoreInfrastructure.js";
4
+ import { SYSTEM_CONTINUATION_PROMPT, SYSTEM_PROMPT } from "../../../../prompts.js";
5
+ import { safeStringify, safeSpread } from "../../../plumbing/utils/PlumbingCore.js";
19
6
  export class MarieEngine {
20
7
  provider;
21
8
  toolRegistry;
22
9
  approvalRequester;
23
10
  providerFactory;
24
- fs;
25
- ghostPort;
26
- static CONTENT_BUFFER_MAX_BYTES = 1024 * 1024;
27
- static GLOBAL_CONCURRENCY_LIMIT = 5;
28
- static globalSemaphore = new MarieSemaphore(MarieEngine.GLOBAL_CONCURRENCY_LIMIT);
29
- ascendant;
30
11
  state;
31
- lockManager;
32
- toolMender;
33
- pulseService;
34
- reasoningBudget;
35
- toolCallCounter = 0;
36
- contentBuffer = "";
37
- lastContentEmit = 0;
12
+ pulse;
38
13
  activeTurn = null;
39
14
  disposed = false;
40
- logService;
41
- constructor(provider, toolRegistry, approvalRequester, providerFactory, fs, ghostPort) {
15
+ heartbeatTimer = null;
16
+ watchdogTimer = null;
17
+ iterations = [];
18
+ static toolsInFlight = new Map();
19
+ logPath;
20
+ logQueue = [];
21
+ isWritingLog = false;
22
+ constructor(provider, toolRegistry, approvalRequester = async () => true, providerFactory) {
42
23
  this.provider = provider;
43
24
  this.toolRegistry = toolRegistry;
44
25
  this.approvalRequester = approvalRequester;
45
26
  this.providerFactory = providerFactory;
46
- this.fs = fs;
47
- this.ghostPort = ghostPort;
48
- this.ascendant = new MarieAscendant(this.provider);
49
- this.state = this.initializeState();
50
- this.lockManager = new MarieLockManager();
51
- this.toolMender = new MarieToolMender(this.toolRegistry);
52
- this.reasoningBudget = new ReasoningBudget();
53
- }
54
- initializeState() {
55
- return {
56
- errorHotspots: {},
57
- totalErrorCount: 0,
58
- spiritPressure: 50,
59
- recentFiles: [],
60
- toolHistory: [],
61
- techniqueExecutions: [],
62
- victoryStreak: 0,
63
- shakyResponseDensity: 0,
64
- writtenFiles: [],
65
- actionDiffs: {},
66
- wiringAlerts: [],
67
- mood: "STABLE",
68
- isSpiritBurstActive: false,
69
- isAwakened: false,
70
- karmaBond: undefined,
71
- panicCoolDown: 0,
72
- environment: this.fs?.type === "vscode" ? "vscode" : "cli",
73
- lastFailedFile: undefined,
74
- };
27
+ this.state = { totalErrorCount: 0, confidenceLevel: 80, recentFiles: [], executionHistory: [] };
75
28
  }
76
- async chatLoop(messages, tracker, saveHistory, signal, consecutiveErrorCount = 0, depth = 0, accumulatedContent = "") {
77
- if (this.disposed) {
78
- throw new Error("MarieEngine has been disposed.");
79
- }
80
- console.log(`[MarieEngine] chatLoop started at depth ${depth}. Accumulated content length: ${accumulatedContent.length}`);
81
- // TURN COLLISION GUARD (Instance): Wait for any existing turn in this instance to finish
82
- if (this.activeTurn) {
83
- console.warn("[MarieEngine] INSTANCE RE-ENTRY DETECTED. Waiting for previous turn to finalize...");
84
- await this.activeTurn;
85
- }
86
- // GLOBAL SEMAPHORE: Acquire slot before proceeding
87
- await MarieEngine.globalSemaphore.acquire();
88
- let resolveTurn = () => { };
89
- this.activeTurn = new Promise((resolve) => {
90
- resolveTurn = resolve;
91
- });
92
- try {
93
- const result = await this._executeChatLoop(messages, tracker, saveHistory, signal, consecutiveErrorCount, depth, accumulatedContent);
94
- console.log(`[MarieEngine] chatLoop finished at depth ${depth}. Final content length: ${result.length}`);
95
- return result;
96
- }
97
- finally {
98
- MarieEngine.globalSemaphore.release();
99
- resolveTurn();
100
- this.activeTurn = null;
101
- }
102
- }
103
- async _executeChatLoop(messages, tracker, saveHistory, signal, consecutiveErrorCount = 0, depth = 0, accumulatedContent = "") {
104
- if (signal?.aborted) {
105
- throw new Error("Execution aborted by user.");
106
- }
107
- const pulse = this.ensurePulseService(tracker);
108
- // Initialize incremental logging
109
- const originatingSessionId = tracker.getRun().originatingSessionId || "default";
110
- if (!this.logService) {
111
- this.logService = new SessionLogService(originatingSessionId);
112
- }
113
- const logService = this.logService;
114
- logService.setProgressCallback((totalBytes, eventCount) => {
115
- tracker.emitEvent({
116
- type: "session_persistence_update",
117
- runId: tracker.getRun().runId,
118
- sessionId: originatingSessionId,
119
- totalBytes,
120
- elapsedMs: tracker.elapsedMs(),
121
- });
122
- });
123
- // Override tracker emit to persist every event
124
- const originalEmit = tracker.emitEvent.bind(tracker);
125
- tracker.emitEvent = (event) => {
126
- void logService.appendEvent(event);
127
- originalEmit(event);
128
- };
129
- if (depth > 20) {
130
- // Graceful Stability Limit Reached
131
- const msg = "⚠️ Stability Alert: Maximum reasoning depth (20) reached. Returning current accumulation to prevent infinite loop.";
132
- console.warn(msg);
133
- // Return currently accumulated content so the user sees *something*
134
- return accumulatedContent + "\n\n" + msg;
135
- }
136
- tracker.resetReasoningBudget();
137
- this.lockManager = new MarieLockManager(tracker);
138
- const dispatcher = new MarieEventDispatcher(tracker, this.ghostPort);
139
- MarieStabilityMonitor.start();
140
- if (tracker.getRun().steps === 0 && !tracker.getRun().isResuming) {
141
- tracker.emitEvent({
142
- type: "reasoning",
143
- runId: tracker.getRun().runId,
144
- text: "🔥 Ascension protocol initiated. Hero's conviction rising.",
145
- elapsedMs: tracker.elapsedMs(),
146
- });
147
- }
148
- // SPIRIT BURST & AWAKENING DETECTION
149
- const wasBurstActive = this.state.isSpiritBurstActive;
150
- const wasAwakened = this.state.isAwakened;
151
- this.state.isSpiritBurstActive = this.state.spiritPressure > 85;
152
- this.state.isAwakened = this.state.spiritPressure > 95;
153
- if (this.state.isAwakened && !wasAwakened) {
154
- tracker.emitEvent({
155
- type: "reasoning",
156
- runId: tracker.getRun().runId,
157
- text: "✨ AWAKENED! Ultra Instinct achieved. Full codebase sovereignty established.",
158
- elapsedMs: tracker.elapsedMs(),
159
- });
160
- }
161
- else if (this.state.isSpiritBurstActive && !wasBurstActive) {
162
- tracker.emitEvent({
163
- type: "reasoning",
164
- runId: tracker.getRun().runId,
165
- text: "💥 SPIRIT BURST! Conviction is absolute. Auto-approval mandate expanded.",
166
- elapsedMs: tracker.elapsedMs(),
167
- });
168
- }
169
- // Decay spirit pressure if stale
170
- if (Date.now() -
171
- (this.state.techniqueExecutions.slice(-1)[0]?.timestamp || 0) >
172
- 300000) {
173
- this.state.spiritPressure = Math.max(30, this.state.spiritPressure - 10);
174
- }
175
- const processor = new MarieToolProcessor(this.toolRegistry, tracker, async (name, input) => {
176
- // YOLO AUTO-APPROVAL: Tiered risk assessment
177
- if (this.shouldAutoApprove(name, input)) {
178
- tracker.emitEvent({
179
- type: "checkpoint",
180
- runId: tracker.getRun().runId,
181
- status: "approved",
182
- toolName: name,
183
- summary: {
184
- what: "Ascension Auto-Approved",
185
- why: "Heroic Conviction",
186
- impact: "Maximum Speed",
187
- },
188
- elapsedMs: tracker.elapsedMs(),
189
- });
190
- return true;
191
- }
192
- return this.approvalRequester(name, input);
193
- }, this.state, this.fs);
194
- let turnContent = "";
195
- const toolBuffer = new Map();
196
- const parsedInputCache = new Map();
197
- const toolResultBlocks = [];
198
- let turnFailureCount = 0;
199
- let totalToolCount = 0;
200
- let lastTokenTime = Date.now();
201
- const MAX_TOOLS_PER_TURN = 30;
202
- const executeTool = async (toolCall) => {
203
- const tool = this.toolRegistry.getTool(toolCall.name);
204
- if (!tool) {
205
- const repairResult = await this.toolMender.performFuzzyRepair(toolCall, "Tool not found", tracker, processor, this.state, signal);
206
- if (repairResult) {
207
- this.toolCallCounter++;
208
- return {
209
- type: "tool_result",
210
- tool_use_id: toolCall.id,
211
- content: repairResult,
212
- };
213
- }
214
- this.updateShakyResponse();
215
- return {
216
- type: "tool_result",
217
- tool_use_id: toolCall.id,
218
- content: `Error: Tool "${toolCall.name}" not found.`,
219
- };
220
- }
221
- const startTime = Date.now();
222
- pulse.startHeartbeat();
223
- try {
224
- // Determine if we need to transition objectives
225
- if (tracker.getRun().activeObjectiveId === "understand_request") {
226
- tracker.setObjectiveStatus("understand_request", "completed");
227
- tracker.setObjectiveStatus("execute_plan", "in_progress");
228
- tracker.getRun().activeObjectiveId = "execute_plan";
229
- tracker.emitProgressUpdate(`Executing technique: ${toolCall.name}`);
230
- }
231
- let toolResult = await processor.process(toolCall, signal);
232
- // Buffer Hard-Cap
233
- if (typeof toolResult === "string" && toolResult.length > 1024 * 1024) {
234
- toolResult =
235
- toolResult.substring(0, 1024 * 1024) + "\n\n🚨 Truncated at 1MB.";
236
- }
237
- const durationMs = Date.now() - startTime;
238
- const targetFile = toolCall.input?.path ||
239
- toolCall.input?.targetFile ||
240
- toolCall.input?.file;
241
- if (typeof toolResult === "string" && toolResult.startsWith("Error")) {
242
- this.handleFailure(tracker, toolCall.name, toolResult, targetFile);
243
- turnFailureCount++;
244
- }
245
- else {
246
- this.handleSuccess(tracker, toolCall.name, durationMs, targetFile, signal);
247
- }
248
- this.toolCallCounter++;
249
- return {
250
- type: "tool_result",
251
- tool_use_id: toolCall.id,
252
- content: toolResult,
253
- };
254
- }
255
- finally {
256
- pulse.stopHeartbeat();
257
- }
258
- };
259
- const promptProfile = getPromptProfileForDepth(depth);
260
- const session = new MarieSession(this.provider, this.toolRegistry, saveHistory, messages, tracker, this.providerFactory, promptProfile);
261
- const toolExecutions = [];
29
+ async chatLoop(messages, run, callbacks, saveHistory, signal) {
30
+ if (this.disposed)
31
+ throw new Error("Engine disposed.");
32
+ this.pulse = { pendingContent: "", pendingToolDeltas: new Map(), throttleTimer: null, toolThrottleTimer: null, run, callbacks };
33
+ let depth = 0;
34
+ let accumulatedContent = "";
35
+ const maxDepth = getMaxRecursiveDepth();
262
36
  try {
263
- const stream = session.executeLoop(messages, signal);
264
- for await (const event of stream) {
265
- const now = Date.now();
266
- lastTokenTime = now;
267
- pulse.startHeartbeat();
268
- // RESTORE EVENT ROUTING: Dispatch all stream events
269
- if (process.env.MARIE_DEBUG) {
270
- console.log(`[Engine Debug] AI Event: ${event.type}`, event.type === "content_delta"
271
- ? `(${event.text.length} chars)`
272
- : "");
273
- }
274
- dispatcher.dispatch(event);
275
- if (event.type === "content_delta") {
276
- turnContent += event.text;
277
- this.contentBuffer += event.text;
278
- if (this.contentBuffer.length >= MarieEngine.CONTENT_BUFFER_MAX_BYTES)
279
- break;
280
- }
281
- else if (event.type === "tool_call_delta") {
282
- let tb = toolBuffer.get(event.index);
283
- if (!tb) {
284
- tb = { id: event.id, name: event.name, inputString: "" };
285
- toolBuffer.set(event.index, tb);
286
- }
287
- else {
288
- // UPDATE: Ensure name and id are captured even if they arrive in later deltas
289
- if (event.id && !tb.id)
290
- tb.id = event.id;
291
- if (event.name && !tb.name)
292
- tb.name = event.name;
293
- }
294
- if (event.argumentsDelta)
295
- tb.inputString += event.argumentsDelta;
296
- if (tb.name && this.isLikelyCompleteJson(tb.inputString)) {
297
- const input = this.tryParseToolInput(tb.inputString, tb.name, parsedInputCache);
298
- if (!input)
299
- continue;
300
- toolBuffer.delete(event.index);
301
- totalToolCount++;
302
- if (totalToolCount > MAX_TOOLS_PER_TURN)
303
- break;
304
- const target = input.path || input.targetFile || input.file || "GLOBAL";
305
- const isWrite = [
306
- "write_to_file",
307
- "replace_file_content",
308
- "multi_replace_file_content",
309
- "run_command",
310
- "delete_file",
311
- ].includes(tb.name);
312
- // Execute concurrently
313
- const executionPromise = (async () => {
314
- await this.lockManager.acquireLock(target, isWrite, signal, tracker.getRun().runId);
315
- const promise = executeTool({
316
- id: tb.id,
317
- name: tb.name,
318
- input,
319
- });
320
- this.lockManager.registerExecution(target, isWrite, promise, tracker.getRun().runId);
321
- return await promise;
322
- })();
323
- toolExecutions.push(executionPromise);
324
- }
325
- }
326
- else if (event.type === "usage") {
327
- tracker.getRun().usage = event.usage;
37
+ while (depth <= maxDepth) {
38
+ await this.align(messages);
39
+ const prompt = depth > 0 ? SYSTEM_CONTINUATION_PROMPT : SYSTEM_PROMPT;
40
+ const tools = this.getEffectiveTools();
41
+ const managedMessages = await manageContext(messages, this.provider, this.state);
42
+ let turnContent = "";
43
+ const toolExecutions = [];
44
+ const buffer = new Map();
45
+ await this.provider.createMessageStream({
46
+ model: getModel(),
47
+ messages: managedMessages,
48
+ system: prompt,
49
+ tools,
50
+ }, (event) => {
51
+ this.dispatchPulse(event);
52
+ if (event.type === "content_delta")
53
+ turnContent += event.text;
54
+ else if (event.type === "tool_call_delta")
55
+ this.onToolDelta(event, buffer, toolExecutions, signal);
56
+ else if (event.type === "usage")
57
+ this.onUsage(event);
58
+ }, signal);
59
+ this.flushPulse();
60
+ const results = await Promise.all(toolExecutions);
61
+ accumulatedContent += turnContent;
62
+ if (results.length > 0) {
63
+ messages.push({ role: "user", content: results });
64
+ depth++;
328
65
  }
66
+ else
67
+ break;
329
68
  }
69
+ return accumulatedContent;
330
70
  }
331
71
  finally {
332
- pulse.cleanup();
72
+ this.cleanupPulse();
333
73
  }
334
- // POST-LOOP FLUSH: Handle any tools that arrived at the very end but missed the stream evaluation
335
- for (const [index, tb] of toolBuffer.entries()) {
336
- if (tb.name) {
337
- const input = this.tryParseToolInput(tb.inputString, tb.name, parsedInputCache);
338
- if (input) {
339
- totalToolCount++;
340
- const target = input.path || input.targetFile || input.file || "GLOBAL";
341
- const isWrite = [
342
- "write_to_file",
343
- "replace_file_content",
344
- "multi_replace_file_content",
345
- "run_command",
346
- "delete_file",
347
- ].includes(tb.name);
348
- const executionPromise = (async () => {
349
- await this.lockManager.acquireLock(target, isWrite, signal, tracker.getRun().runId);
350
- const promise = executeTool({ id: tb.id, name: tb.name, input });
351
- this.lockManager.registerExecution(target, isWrite, promise, tracker.getRun().runId);
352
- return await promise;
353
- })();
354
- toolExecutions.push(executionPromise);
355
- }
356
- }
357
- }
358
- toolBuffer.clear();
359
- const currentAccumulatedContent = accumulatedContent + turnContent;
360
- console.log(`[MarieEngine] Depth ${depth}: Turn content length: ${turnContent.length}. New accumulated length: ${currentAccumulatedContent.length}`);
361
- if (this.contentBuffer.length > 0) {
362
- this.contentBuffer = "";
363
- }
364
- // Await all concurrent tool executions
365
- const results = await Promise.all(toolExecutions);
366
- toolResultBlocks.push(...results);
367
- await this.lockManager.waitForAll();
368
- if (signal?.aborted) {
369
- throw new Error("Execution aborted by user after tool execution.");
370
- }
371
- // Final tool processing if results were returned
372
- if (totalToolCount > 0) {
373
- messages.push({ role: "user", content: toolResultBlocks });
374
- // ASCENSION EVALUATION: Local decree (NO API CALL)
375
- const decree = await this.ascendant.evaluate(messages, this.state);
376
- this.state.lastDecree = decree;
377
- // Visual feedback only — no state mutations from decree
378
- tracker.emitEvent({
379
- type: "reasoning",
380
- runId: tracker.getRun().runId,
381
- text: `⚡ Decree: ${decree.strategy} @ ${decree.confidence.toFixed(2)} — ${decree.reason}`,
382
- elapsedMs: tracker.elapsedMs(),
383
- });
384
- if (decree.heroicVow) {
385
- tracker.emitEvent({
386
- type: "reasoning",
387
- runId: tracker.getRun().runId,
388
- text: `🗡️ VOW: "${decree.heroicVow}"`,
389
- elapsedMs: tracker.elapsedMs(),
390
- });
391
- }
392
- saveHistory(tracker.getRun()).catch((e) => console.error("History Save Error:", e));
393
- return await this._executeChatLoop(messages, tracker, saveHistory, signal, turnFailureCount > 0 ? consecutiveErrorCount + 1 : 0, depth + 1, currentAccumulatedContent);
394
- }
395
- // End of turn logic
396
- tracker.setObjectiveStatus("execute_plan", "completed");
397
- tracker.setObjectiveStatus("deliver_result", "completed");
398
- tracker.emitEvent({
399
- type: "reasoning",
400
- runId: tracker.getRun().runId,
401
- text: "✨ Convergence achieved. The pattern sparks joy.",
402
- elapsedMs: tracker.elapsedMs(),
403
- });
404
- dispatcher.clear();
405
- return currentAccumulatedContent;
406
74
  }
407
- handleSuccess(tracker, toolName, durationMs, filePath, signal) {
408
- this.state.victoryStreak++;
409
- this.state.totalErrorCount = 0;
410
- this.state.spiritPressure = Math.min(100, this.state.spiritPressure + 10);
411
- this.state.techniqueExecutions.push({
412
- name: toolName,
413
- durationMs,
414
- success: true,
415
- timestamp: Date.now(),
416
- filePath,
417
- });
418
- this.state.toolHistory.push(toolName);
419
- if (this.state.victoryStreak % 3 === 0) {
420
- tracker.emitEvent({
421
- type: "reasoning",
422
- runId: tracker.getRun().runId,
423
- text: `✨ Technique Mastery! ${toolName} executed perfectly. Victory Streak: ${this.state.victoryStreak}.`,
424
- elapsedMs: tracker.elapsedMs(),
425
- });
426
- }
427
- if (filePath && !this.state.recentFiles.includes(filePath)) {
428
- this.state.recentFiles.push(filePath);
429
- if (this.state.recentFiles.length > 10)
430
- this.state.recentFiles.shift();
431
- // ZENITH AUTONOMY: Proactive Context Anchoring
432
- this.proactiveContextAnchoring(filePath, tracker, signal);
75
+ dispatchPulse(event) {
76
+ if (!this.pulse)
77
+ return;
78
+ switch (event.type) {
79
+ case "content_delta":
80
+ this.pulse.pendingContent += event.text;
81
+ break;
82
+ case "tool_call_delta": break;
433
83
  }
434
84
  }
435
- handleFailure(tracker, toolName, error, filePath) {
436
- this.state.victoryStreak = 0;
437
- this.state.spiritPressure = Math.max(0, this.state.spiritPressure - 20);
438
- this.state.techniqueExecutions.push({
439
- name: toolName,
440
- durationMs: 0,
441
- success: false,
442
- timestamp: Date.now(),
443
- filePath,
444
- });
445
- const hotspotCount = (this.state.errorHotspots[filePath || "system"] || 0) + 1;
446
- if (filePath) {
447
- this.state.errorHotspots[filePath] = hotspotCount;
448
- this.state.totalErrorCount++;
449
- this.state.lastFailedFile = filePath;
450
- }
451
- tracker.emitEvent({
452
- type: "reasoning",
453
- runId: tracker.getRun().runId,
454
- text: `⚠️ Technique Falter! ${toolName} failed in ${filePath || "system"}. Resistance: ${hotspotCount}x. Regrouping...`,
455
- elapsedMs: tracker.elapsedMs(),
456
- });
85
+ flushPulse() {
86
+ if (!this.pulse || !this.pulse.pendingContent)
87
+ return;
88
+ this.pulse.callbacks?.onStream?.(this.pulse.pendingContent, this.pulse.run.runId);
89
+ this.pulse.pendingContent = "";
457
90
  }
458
- updateShakyResponse() {
459
- this.state.shakyResponseDensity = Math.min(1, this.state.shakyResponseDensity + 0.2);
460
- }
461
- shouldAutoApprove(toolName, input) {
462
- const safeTools = [
463
- "read_file",
464
- "view_file",
465
- "list_dir",
466
- "grep_search",
467
- "search_web",
468
- "get_file_diagnostics",
469
- ];
470
- if (safeTools.includes(toolName))
471
- return true;
472
- // SPIRIT PRESSURE & KARMA NEUTERED:
473
- // We no longer auto-approve based on pressure/streak to prevent "crashes" or unintended loops.
474
- // The visual feedback remains, but the functional override is disabled.
475
- return false;
476
- }
477
- tryParseToolInput(rawInput, toolName, cache) {
478
- try {
479
- return JSON.parse(rawInput);
480
- }
481
- catch (e) {
482
- const repaired = this.toolMender.repairJsonString(rawInput);
91
+ cleanupPulse() { this.pulse = undefined; }
92
+ onToolDelta(event, buffer, executions, signal) {
93
+ let tb = buffer.get(event.index) || { id: event.id, name: event.name, inputString: "" };
94
+ if (event.id)
95
+ tb.id = event.id;
96
+ if (event.name)
97
+ tb.name = event.name;
98
+ if (event.argumentsDelta)
99
+ tb.inputString += event.argumentsDelta;
100
+ buffer.set(event.index, tb);
101
+ if (tb.name && this.isJsonComplete(tb.inputString)) {
483
102
  try {
484
- return JSON.parse(repaired);
485
- }
486
- catch (e2) {
487
- console.warn(`[MarieEngine] JSON Parse Failed for ${toolName}: ${e instanceof Error ? e.message : String(e)}`);
488
- return null;
103
+ const input = JSON.parse(tb.inputString);
104
+ buffer.delete(event.index);
105
+ executions.push(this.runTool(tb.id, tb.name, input, signal));
489
106
  }
107
+ catch { }
490
108
  }
491
109
  }
492
- isLikelyCompleteJson(input) {
493
- const text = input.trim();
494
- if (!text || (!text.startsWith("{") && !text.startsWith("[")))
495
- return false;
496
- let stack = 0;
497
- let inString = false;
498
- for (let i = 0; i < text.length; i++) {
499
- if (text[i] === '"' && text[i - 1] !== "\\")
500
- inString = !inString;
501
- if (!inString) {
502
- if (text[i] === "{" || text[i] === "[")
503
- stack++;
504
- if (text[i] === "}" || text[i] === "]")
505
- stack--;
506
- }
507
- }
508
- return stack === 0 && text.length >= 2;
509
- }
510
- suggestSelfHealing(tracker, messages) {
511
- // SPIRIT PRESSURE & KARMA NEUTERED:
512
- // We calculate the values for UI visuals but DO NOT inject mandatory recovery protocols.
513
- // This prevents the "crash" loop the user described.
514
- const pressure = this.state.spiritPressure;
515
- const hotspots = Object.entries(this.state.errorHotspots).filter(([_, count]) => count >= 2);
516
- if (pressure < 40 || hotspots.length > 0) {
517
- const hotspotFiles = hotspots.map(([f]) => path.basename(f)).join(", ");
518
- const reason = pressure < 40
519
- ? "Low spirit pressure (instability detected)"
520
- : `Repeated failures in: ${hotspotFiles}`;
521
- // Log only - do not force the user/agent into a recovery loop
522
- console.log(`[MarieEngine] Suggestion: ${reason}. (Auto-recovery disabled for stability)`);
523
- }
524
- }
525
- dispose() {
526
- this.disposed = true;
527
- this.pulseService?.cleanup();
528
- this.pulseService = undefined;
529
- this.contentBuffer = "";
530
- }
531
- ensurePulseService(tracker) {
532
- if (!this.pulseService)
533
- this.pulseService = new MariePulseService(tracker);
534
- return this.pulseService;
535
- }
536
- calibrateStrategicTrajectory(decree, tracker) {
537
- const run = tracker.getRun();
538
- if (decree.strategy === "RESEARCH" ||
539
- (decree.urgency === "HIGH" && decree.confidence > 2.0)) {
540
- const oldPasses = run.totalPasses || 3;
541
- if (oldPasses < 10) {
542
- run.totalPasses = oldPasses + 1;
543
- tracker.emitEvent({
544
- type: "reasoning",
545
- runId: run.runId,
546
- text: `🌌 ZENITH: Autonomously expanded roadmap to ${run.totalPasses} passes. Focus sharpened: ${decree.reason}`,
547
- elapsedMs: tracker.elapsedMs(),
548
- });
549
- }
550
- }
110
+ async runTool(id, name, input, signal) {
111
+ const start = Date.now();
112
+ const tool = this.getTool(name);
113
+ if (!tool)
114
+ return { type: "tool_result", tool_use_id: id, content: `Error: Tool ${name} not found.` };
115
+ this.pulse?.callbacks?.onEvent?.({ type: "tool", runId: this.pulse.run.runId, id, phase: "start", name, input: safeSpread(input), elapsedMs: Date.now() - this.pulse.run.startedAt });
116
+ const result = await tool.execute(input);
117
+ const final = typeof result === "string" ? result : safeStringify(result);
118
+ this.pulse?.callbacks?.onEvent?.({ type: "tool", runId: this.pulse.run.runId, id, phase: "complete", name, message: final.substring(0, 50), elapsedMs: Date.now() - this.pulse.run.startedAt });
119
+ return { type: "tool_result", tool_use_id: id, content: final };
551
120
  }
552
- async proactiveContextAnchoring(filePath, tracker, signal) {
553
- // Only anchor critical files
554
- const isCritical = /Domain|Config|Service|Interface|types/i.test(filePath);
555
- if (isCritical) {
556
- try {
557
- if (signal?.aborted)
558
- return;
559
- const { ContextArchiveService } = await import("../../../infrastructure/ai/context/ContextArchiveService.js");
560
- const { readFile } = await import("../../../plumbing/filesystem/FileService.js");
561
- const content = await readFile(filePath, undefined, undefined, signal);
562
- if (signal?.aborted)
563
- return;
564
- await ContextArchiveService.getInstance().anchor({
565
- id: `proactive_${filePath.split("/").pop()}`,
566
- label: `Strategic: ${filePath.split("/").pop()}`,
567
- content: content.substring(0, 2000), // Cap at 2k chars
568
- type: "file_ref",
569
- });
570
- if (signal?.aborted)
571
- return;
572
- tracker.emitEvent({
573
- type: "reasoning",
574
- runId: tracker.getRun().runId,
575
- text: `⚓ ZENITH: Proactively anchored \`${filePath.split("/").pop()}\` to strategic memory.`,
576
- elapsedMs: tracker.elapsedMs(),
577
- });
578
- }
579
- catch (e) {
580
- if (!signal?.aborted) {
581
- console.warn("[Zenith] Failed proactive anchoring", e);
582
- }
583
- }
584
- }
121
+ async align(messages) { }
122
+ onUsage(e) { if (this.pulse)
123
+ this.pulse.run.usage = e.usage; }
124
+ getEffectiveTools() { return this.toolRegistry ? this.toolRegistry.getRegisteredTools() : getRegisteredTools(); }
125
+ isJsonComplete(s) { try {
126
+ JSON.parse(s);
127
+ return true;
585
128
  }
129
+ catch {
130
+ return false;
131
+ } }
132
+ getTool(name) { return this.toolRegistry ? this.toolRegistry.get(name) : getTool(name); }
133
+ dispose() { this.disposed = true; }
586
134
  }
587
135
  //# sourceMappingURL=MarieEngine.js.map