@deepseekdev/coder 1.0.74

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 (711) hide show
  1. package/LICENSE +21 -0
  2. package/agents/agi-code.rules.json +159 -0
  3. package/agents/general.rules.json +181 -0
  4. package/dist/bin/cliMode.d.ts +8 -0
  5. package/dist/bin/cliMode.d.ts.map +1 -0
  6. package/dist/bin/cliMode.js +20 -0
  7. package/dist/bin/cliMode.js.map +1 -0
  8. package/dist/bin/deepseek.d.ts +3 -0
  9. package/dist/bin/deepseek.d.ts.map +1 -0
  10. package/dist/bin/deepseek.js +137 -0
  11. package/dist/bin/deepseek.js.map +1 -0
  12. package/dist/bin/erosolar.d.ts +7 -0
  13. package/dist/bin/erosolar.d.ts.map +1 -0
  14. package/dist/bin/erosolar.js +7 -0
  15. package/dist/bin/erosolar.js.map +1 -0
  16. package/dist/bin/lean.d.ts +9 -0
  17. package/dist/bin/lean.d.ts.map +1 -0
  18. package/dist/bin/lean.js +333 -0
  19. package/dist/bin/lean.js.map +1 -0
  20. package/dist/bin/selfTest.d.ts +14 -0
  21. package/dist/bin/selfTest.d.ts.map +1 -0
  22. package/dist/bin/selfTest.js +298 -0
  23. package/dist/bin/selfTest.js.map +1 -0
  24. package/dist/capabilities/baseCapability.d.ts +72 -0
  25. package/dist/capabilities/baseCapability.d.ts.map +1 -0
  26. package/dist/capabilities/baseCapability.js +183 -0
  27. package/dist/capabilities/baseCapability.js.map +1 -0
  28. package/dist/capabilities/bashCapability.d.ts +13 -0
  29. package/dist/capabilities/bashCapability.d.ts.map +1 -0
  30. package/dist/capabilities/bashCapability.js +24 -0
  31. package/dist/capabilities/bashCapability.js.map +1 -0
  32. package/dist/capabilities/editCapability.d.ts +17 -0
  33. package/dist/capabilities/editCapability.d.ts.map +1 -0
  34. package/dist/capabilities/editCapability.js +27 -0
  35. package/dist/capabilities/editCapability.js.map +1 -0
  36. package/dist/capabilities/enhancedGitCapability.d.ts +7 -0
  37. package/dist/capabilities/enhancedGitCapability.d.ts.map +1 -0
  38. package/dist/capabilities/enhancedGitCapability.js +220 -0
  39. package/dist/capabilities/enhancedGitCapability.js.map +1 -0
  40. package/dist/capabilities/filesystemCapability.d.ts +13 -0
  41. package/dist/capabilities/filesystemCapability.d.ts.map +1 -0
  42. package/dist/capabilities/filesystemCapability.js +24 -0
  43. package/dist/capabilities/filesystemCapability.js.map +1 -0
  44. package/dist/capabilities/gitHistoryCapability.d.ts +6 -0
  45. package/dist/capabilities/gitHistoryCapability.d.ts.map +1 -0
  46. package/dist/capabilities/gitHistoryCapability.js +160 -0
  47. package/dist/capabilities/gitHistoryCapability.js.map +1 -0
  48. package/dist/capabilities/hitlCapability.d.ts +18 -0
  49. package/dist/capabilities/hitlCapability.d.ts.map +1 -0
  50. package/dist/capabilities/hitlCapability.js +29 -0
  51. package/dist/capabilities/hitlCapability.js.map +1 -0
  52. package/dist/capabilities/index.d.ts +11 -0
  53. package/dist/capabilities/index.d.ts.map +1 -0
  54. package/dist/capabilities/index.js +13 -0
  55. package/dist/capabilities/index.js.map +1 -0
  56. package/dist/capabilities/searchCapability.d.ts +19 -0
  57. package/dist/capabilities/searchCapability.d.ts.map +1 -0
  58. package/dist/capabilities/searchCapability.js +29 -0
  59. package/dist/capabilities/searchCapability.js.map +1 -0
  60. package/dist/capabilities/toolManifest.d.ts +3 -0
  61. package/dist/capabilities/toolManifest.d.ts.map +1 -0
  62. package/dist/capabilities/toolManifest.js +163 -0
  63. package/dist/capabilities/toolManifest.js.map +1 -0
  64. package/dist/capabilities/toolRegistry.d.ts +25 -0
  65. package/dist/capabilities/toolRegistry.d.ts.map +1 -0
  66. package/dist/capabilities/toolRegistry.js +150 -0
  67. package/dist/capabilities/toolRegistry.js.map +1 -0
  68. package/dist/capabilities/unifiedCodingCapability.d.ts +48 -0
  69. package/dist/capabilities/unifiedCodingCapability.d.ts.map +1 -0
  70. package/dist/capabilities/unifiedCodingCapability.js +631 -0
  71. package/dist/capabilities/unifiedCodingCapability.js.map +1 -0
  72. package/dist/capabilities/webCapability.d.ts +23 -0
  73. package/dist/capabilities/webCapability.d.ts.map +1 -0
  74. package/dist/capabilities/webCapability.js +33 -0
  75. package/dist/capabilities/webCapability.js.map +1 -0
  76. package/dist/config.d.ts +25 -0
  77. package/dist/config.d.ts.map +1 -0
  78. package/dist/config.js +155 -0
  79. package/dist/config.js.map +1 -0
  80. package/dist/contracts/agent-profiles.schema.json +43 -0
  81. package/dist/contracts/agent-schemas.json +480 -0
  82. package/dist/contracts/models.schema.json +9 -0
  83. package/dist/contracts/module-schema.json +430 -0
  84. package/dist/contracts/schemas/agent-profile.schema.json +157 -0
  85. package/dist/contracts/schemas/agent-rules.schema.json +238 -0
  86. package/dist/contracts/schemas/agent-schemas.schema.json +528 -0
  87. package/dist/contracts/schemas/agent.schema.json +90 -0
  88. package/dist/contracts/schemas/tool-selection.schema.json +174 -0
  89. package/dist/contracts/tools.schema.json +82 -0
  90. package/dist/contracts/unified-schema.json +757 -0
  91. package/dist/contracts/v1/agent.d.ts +187 -0
  92. package/dist/contracts/v1/agent.d.ts.map +1 -0
  93. package/dist/contracts/v1/agent.js +8 -0
  94. package/dist/contracts/v1/agent.js.map +1 -0
  95. package/dist/contracts/v1/agentProfileManifest.d.ts +60 -0
  96. package/dist/contracts/v1/agentProfileManifest.d.ts.map +1 -0
  97. package/dist/contracts/v1/agentProfileManifest.js +9 -0
  98. package/dist/contracts/v1/agentProfileManifest.js.map +1 -0
  99. package/dist/contracts/v1/agentRules.d.ts +60 -0
  100. package/dist/contracts/v1/agentRules.d.ts.map +1 -0
  101. package/dist/contracts/v1/agentRules.js +10 -0
  102. package/dist/contracts/v1/agentRules.js.map +1 -0
  103. package/dist/contracts/v1/provider.d.ts +149 -0
  104. package/dist/contracts/v1/provider.d.ts.map +1 -0
  105. package/dist/contracts/v1/provider.js +7 -0
  106. package/dist/contracts/v1/provider.js.map +1 -0
  107. package/dist/contracts/v1/tool.d.ts +136 -0
  108. package/dist/contracts/v1/tool.d.ts.map +1 -0
  109. package/dist/contracts/v1/tool.js +7 -0
  110. package/dist/contracts/v1/tool.js.map +1 -0
  111. package/dist/contracts/v1/toolAccess.d.ts +43 -0
  112. package/dist/contracts/v1/toolAccess.d.ts.map +1 -0
  113. package/dist/contracts/v1/toolAccess.js +9 -0
  114. package/dist/contracts/v1/toolAccess.js.map +1 -0
  115. package/dist/core/agent.d.ts +320 -0
  116. package/dist/core/agent.d.ts.map +1 -0
  117. package/dist/core/agent.js +1627 -0
  118. package/dist/core/agent.js.map +1 -0
  119. package/dist/core/agentProfileManifest.d.ts +3 -0
  120. package/dist/core/agentProfileManifest.d.ts.map +1 -0
  121. package/dist/core/agentProfileManifest.js +188 -0
  122. package/dist/core/agentProfileManifest.js.map +1 -0
  123. package/dist/core/agentProfiles.d.ts +22 -0
  124. package/dist/core/agentProfiles.d.ts.map +1 -0
  125. package/dist/core/agentProfiles.js +35 -0
  126. package/dist/core/agentProfiles.js.map +1 -0
  127. package/dist/core/agentRulebook.d.ts +11 -0
  128. package/dist/core/agentRulebook.d.ts.map +1 -0
  129. package/dist/core/agentRulebook.js +136 -0
  130. package/dist/core/agentRulebook.js.map +1 -0
  131. package/dist/core/agentSchemaLoader.d.ts +131 -0
  132. package/dist/core/agentSchemaLoader.d.ts.map +1 -0
  133. package/dist/core/agentSchemaLoader.js +235 -0
  134. package/dist/core/agentSchemaLoader.js.map +1 -0
  135. package/dist/core/agiCore.d.ts +312 -0
  136. package/dist/core/agiCore.d.ts.map +1 -0
  137. package/dist/core/agiCore.js +1585 -0
  138. package/dist/core/agiCore.js.map +1 -0
  139. package/dist/core/aiErrorFixer.d.ts +57 -0
  140. package/dist/core/aiErrorFixer.d.ts.map +1 -0
  141. package/dist/core/aiErrorFixer.js +214 -0
  142. package/dist/core/aiErrorFixer.js.map +1 -0
  143. package/dist/core/bashCommandGuidance.d.ts +16 -0
  144. package/dist/core/bashCommandGuidance.d.ts.map +1 -0
  145. package/dist/core/bashCommandGuidance.js +40 -0
  146. package/dist/core/bashCommandGuidance.js.map +1 -0
  147. package/dist/core/constants.d.ts +31 -0
  148. package/dist/core/constants.d.ts.map +1 -0
  149. package/dist/core/constants.js +62 -0
  150. package/dist/core/constants.js.map +1 -0
  151. package/dist/core/contextManager.d.ts +271 -0
  152. package/dist/core/contextManager.d.ts.map +1 -0
  153. package/dist/core/contextManager.js +1073 -0
  154. package/dist/core/contextManager.js.map +1 -0
  155. package/dist/core/contextWindow.d.ts +42 -0
  156. package/dist/core/contextWindow.d.ts.map +1 -0
  157. package/dist/core/contextWindow.js +123 -0
  158. package/dist/core/contextWindow.js.map +1 -0
  159. package/dist/core/customCommands.d.ts +19 -0
  160. package/dist/core/customCommands.d.ts.map +1 -0
  161. package/dist/core/customCommands.js +85 -0
  162. package/dist/core/customCommands.js.map +1 -0
  163. package/dist/core/deepBugAnalyzer.d.ts +25 -0
  164. package/dist/core/deepBugAnalyzer.d.ts.map +1 -0
  165. package/dist/core/deepBugAnalyzer.js +44 -0
  166. package/dist/core/deepBugAnalyzer.js.map +1 -0
  167. package/dist/core/dynamicGuardrails.d.ts +207 -0
  168. package/dist/core/dynamicGuardrails.d.ts.map +1 -0
  169. package/dist/core/dynamicGuardrails.js +455 -0
  170. package/dist/core/dynamicGuardrails.js.map +1 -0
  171. package/dist/core/embeddingProviders.d.ts +80 -0
  172. package/dist/core/embeddingProviders.d.ts.map +1 -0
  173. package/dist/core/embeddingProviders.js +241 -0
  174. package/dist/core/embeddingProviders.js.map +1 -0
  175. package/dist/core/episodicMemory.d.ts +259 -0
  176. package/dist/core/episodicMemory.d.ts.map +1 -0
  177. package/dist/core/episodicMemory.js +834 -0
  178. package/dist/core/episodicMemory.js.map +1 -0
  179. package/dist/core/errors/apiKeyErrors.d.ts +11 -0
  180. package/dist/core/errors/apiKeyErrors.d.ts.map +1 -0
  181. package/dist/core/errors/apiKeyErrors.js +159 -0
  182. package/dist/core/errors/apiKeyErrors.js.map +1 -0
  183. package/dist/core/errors/errorTypes.d.ts +111 -0
  184. package/dist/core/errors/errorTypes.d.ts.map +1 -0
  185. package/dist/core/errors/errorTypes.js +345 -0
  186. package/dist/core/errors/errorTypes.js.map +1 -0
  187. package/dist/core/errors/index.d.ts +50 -0
  188. package/dist/core/errors/index.d.ts.map +1 -0
  189. package/dist/core/errors/index.js +156 -0
  190. package/dist/core/errors/index.js.map +1 -0
  191. package/dist/core/errors/networkErrors.d.ts +14 -0
  192. package/dist/core/errors/networkErrors.d.ts.map +1 -0
  193. package/dist/core/errors/networkErrors.js +53 -0
  194. package/dist/core/errors/networkErrors.js.map +1 -0
  195. package/dist/core/errors/safetyValidator.d.ts +109 -0
  196. package/dist/core/errors/safetyValidator.d.ts.map +1 -0
  197. package/dist/core/errors/safetyValidator.js +271 -0
  198. package/dist/core/errors/safetyValidator.js.map +1 -0
  199. package/dist/core/errors.d.ts +4 -0
  200. package/dist/core/errors.d.ts.map +1 -0
  201. package/dist/core/errors.js +33 -0
  202. package/dist/core/errors.js.map +1 -0
  203. package/dist/core/finalResponseFormatter.d.ts +10 -0
  204. package/dist/core/finalResponseFormatter.d.ts.map +1 -0
  205. package/dist/core/finalResponseFormatter.js +14 -0
  206. package/dist/core/finalResponseFormatter.js.map +1 -0
  207. package/dist/core/flowProtection.d.ts +154 -0
  208. package/dist/core/flowProtection.d.ts.map +1 -0
  209. package/dist/core/flowProtection.js +439 -0
  210. package/dist/core/flowProtection.js.map +1 -0
  211. package/dist/core/gitWorktreeManager.d.ts +126 -0
  212. package/dist/core/gitWorktreeManager.d.ts.map +1 -0
  213. package/dist/core/gitWorktreeManager.js +403 -0
  214. package/dist/core/gitWorktreeManager.js.map +1 -0
  215. package/dist/core/global-macbook-access.d.ts +59 -0
  216. package/dist/core/global-macbook-access.d.ts.map +1 -0
  217. package/dist/core/global-macbook-access.js +101 -0
  218. package/dist/core/global-macbook-access.js.map +1 -0
  219. package/dist/core/guardrails.d.ts +146 -0
  220. package/dist/core/guardrails.d.ts.map +1 -0
  221. package/dist/core/guardrails.js +361 -0
  222. package/dist/core/guardrails.js.map +1 -0
  223. package/dist/core/hallucinationGuard.d.ts +57 -0
  224. package/dist/core/hallucinationGuard.d.ts.map +1 -0
  225. package/dist/core/hallucinationGuard.js +237 -0
  226. package/dist/core/hallucinationGuard.js.map +1 -0
  227. package/dist/core/hitl.d.ts +109 -0
  228. package/dist/core/hitl.d.ts.map +1 -0
  229. package/dist/core/hitl.js +371 -0
  230. package/dist/core/hitl.js.map +1 -0
  231. package/dist/core/hooks.d.ts +113 -0
  232. package/dist/core/hooks.d.ts.map +1 -0
  233. package/dist/core/hooks.js +364 -0
  234. package/dist/core/hooks.js.map +1 -0
  235. package/dist/core/hotReload.d.ts +154 -0
  236. package/dist/core/hotReload.d.ts.map +1 -0
  237. package/dist/core/hotReload.js +451 -0
  238. package/dist/core/hotReload.js.map +1 -0
  239. package/dist/core/hypothesisEngine.d.ts +27 -0
  240. package/dist/core/hypothesisEngine.d.ts.map +1 -0
  241. package/dist/core/hypothesisEngine.js +58 -0
  242. package/dist/core/hypothesisEngine.js.map +1 -0
  243. package/dist/core/index.d.ts +18 -0
  244. package/dist/core/index.d.ts.map +1 -0
  245. package/dist/core/index.js +40 -0
  246. package/dist/core/index.js.map +1 -0
  247. package/dist/core/initialExplorer.d.ts +53 -0
  248. package/dist/core/initialExplorer.d.ts.map +1 -0
  249. package/dist/core/initialExplorer.js +423 -0
  250. package/dist/core/initialExplorer.js.map +1 -0
  251. package/dist/core/inputProtection.d.ts +122 -0
  252. package/dist/core/inputProtection.d.ts.map +1 -0
  253. package/dist/core/inputProtection.js +422 -0
  254. package/dist/core/inputProtection.js.map +1 -0
  255. package/dist/core/liveGCPVerification.d.ts +41 -0
  256. package/dist/core/liveGCPVerification.d.ts.map +1 -0
  257. package/dist/core/liveGCPVerification.js +745 -0
  258. package/dist/core/liveGCPVerification.js.map +1 -0
  259. package/dist/core/modelDiscovery.d.ts +105 -0
  260. package/dist/core/modelDiscovery.d.ts.map +1 -0
  261. package/dist/core/modelDiscovery.js +768 -0
  262. package/dist/core/modelDiscovery.js.map +1 -0
  263. package/dist/core/multilinePasteHandler.d.ts +35 -0
  264. package/dist/core/multilinePasteHandler.d.ts.map +1 -0
  265. package/dist/core/multilinePasteHandler.js +81 -0
  266. package/dist/core/multilinePasteHandler.js.map +1 -0
  267. package/dist/core/parallelExecutor.d.ts +215 -0
  268. package/dist/core/parallelExecutor.d.ts.map +1 -0
  269. package/dist/core/parallelExecutor.js +584 -0
  270. package/dist/core/parallelExecutor.js.map +1 -0
  271. package/dist/core/preferences.d.ts +71 -0
  272. package/dist/core/preferences.d.ts.map +1 -0
  273. package/dist/core/preferences.js +341 -0
  274. package/dist/core/preferences.js.map +1 -0
  275. package/dist/core/productTestHarness.d.ts +46 -0
  276. package/dist/core/productTestHarness.d.ts.map +1 -0
  277. package/dist/core/productTestHarness.js +128 -0
  278. package/dist/core/productTestHarness.js.map +1 -0
  279. package/dist/core/providerKeys.d.ts +20 -0
  280. package/dist/core/providerKeys.d.ts.map +1 -0
  281. package/dist/core/providerKeys.js +40 -0
  282. package/dist/core/providerKeys.js.map +1 -0
  283. package/dist/core/resultVerification.d.ts +47 -0
  284. package/dist/core/resultVerification.d.ts.map +1 -0
  285. package/dist/core/resultVerification.js +126 -0
  286. package/dist/core/resultVerification.js.map +1 -0
  287. package/dist/core/revenueEnvValidator.d.ts +30 -0
  288. package/dist/core/revenueEnvValidator.d.ts.map +1 -0
  289. package/dist/core/revenueEnvValidator.js +244 -0
  290. package/dist/core/revenueEnvValidator.js.map +1 -0
  291. package/dist/core/schemaValidator.d.ts +49 -0
  292. package/dist/core/schemaValidator.d.ts.map +1 -0
  293. package/dist/core/schemaValidator.js +234 -0
  294. package/dist/core/schemaValidator.js.map +1 -0
  295. package/dist/core/secretStore.d.ts +48 -0
  296. package/dist/core/secretStore.d.ts.map +1 -0
  297. package/dist/core/secretStore.js +295 -0
  298. package/dist/core/secretStore.js.map +1 -0
  299. package/dist/core/selfUpgrade.d.ts +79 -0
  300. package/dist/core/selfUpgrade.d.ts.map +1 -0
  301. package/dist/core/selfUpgrade.js +92 -0
  302. package/dist/core/selfUpgrade.js.map +1 -0
  303. package/dist/core/sessionStorage.d.ts +10 -0
  304. package/dist/core/sessionStorage.d.ts.map +1 -0
  305. package/dist/core/sessionStorage.js +46 -0
  306. package/dist/core/sessionStorage.js.map +1 -0
  307. package/dist/core/sessionStore.d.ts +35 -0
  308. package/dist/core/sessionStore.d.ts.map +1 -0
  309. package/dist/core/sessionStore.js +191 -0
  310. package/dist/core/sessionStore.js.map +1 -0
  311. package/dist/core/shutdown.d.ts +34 -0
  312. package/dist/core/shutdown.d.ts.map +1 -0
  313. package/dist/core/shutdown.js +173 -0
  314. package/dist/core/shutdown.js.map +1 -0
  315. package/dist/core/sudoPasswordManager.d.ts +52 -0
  316. package/dist/core/sudoPasswordManager.d.ts.map +1 -0
  317. package/dist/core/sudoPasswordManager.js +115 -0
  318. package/dist/core/sudoPasswordManager.js.map +1 -0
  319. package/dist/core/taskCompletionDetector.d.ts +112 -0
  320. package/dist/core/taskCompletionDetector.d.ts.map +1 -0
  321. package/dist/core/taskCompletionDetector.js +469 -0
  322. package/dist/core/taskCompletionDetector.js.map +1 -0
  323. package/dist/core/testFailureMonitor.d.ts +67 -0
  324. package/dist/core/testFailureMonitor.d.ts.map +1 -0
  325. package/dist/core/testFailureMonitor.js +262 -0
  326. package/dist/core/testFailureMonitor.js.map +1 -0
  327. package/dist/core/toolPreconditions.d.ts +34 -0
  328. package/dist/core/toolPreconditions.d.ts.map +1 -0
  329. package/dist/core/toolPreconditions.js +242 -0
  330. package/dist/core/toolPreconditions.js.map +1 -0
  331. package/dist/core/toolRuntime.d.ts +185 -0
  332. package/dist/core/toolRuntime.d.ts.map +1 -0
  333. package/dist/core/toolRuntime.js +412 -0
  334. package/dist/core/toolRuntime.js.map +1 -0
  335. package/dist/core/types/utilityTypes.d.ts +183 -0
  336. package/dist/core/types/utilityTypes.d.ts.map +1 -0
  337. package/dist/core/types/utilityTypes.js +273 -0
  338. package/dist/core/types/utilityTypes.js.map +1 -0
  339. package/dist/core/types.d.ts +334 -0
  340. package/dist/core/types.d.ts.map +1 -0
  341. package/dist/core/types.js +76 -0
  342. package/dist/core/types.js.map +1 -0
  343. package/dist/core/unifiedOrchestrator.d.ts +47 -0
  344. package/dist/core/unifiedOrchestrator.d.ts.map +1 -0
  345. package/dist/core/unifiedOrchestrator.js +103 -0
  346. package/dist/core/unifiedOrchestrator.js.map +1 -0
  347. package/dist/core/unrestricted-mode.d.ts +42 -0
  348. package/dist/core/unrestricted-mode.d.ts.map +1 -0
  349. package/dist/core/unrestricted-mode.js +88 -0
  350. package/dist/core/unrestricted-mode.js.map +1 -0
  351. package/dist/core/updateChecker.d.ts +148 -0
  352. package/dist/core/updateChecker.d.ts.map +1 -0
  353. package/dist/core/updateChecker.js +593 -0
  354. package/dist/core/updateChecker.js.map +1 -0
  355. package/dist/headless/interactiveShell.d.ts +22 -0
  356. package/dist/headless/interactiveShell.d.ts.map +1 -0
  357. package/dist/headless/interactiveShell.js +4045 -0
  358. package/dist/headless/interactiveShell.js.map +1 -0
  359. package/dist/headless/quickMode.d.ts +26 -0
  360. package/dist/headless/quickMode.d.ts.map +1 -0
  361. package/dist/headless/quickMode.js +236 -0
  362. package/dist/headless/quickMode.js.map +1 -0
  363. package/dist/leanAgent.d.ts +73 -0
  364. package/dist/leanAgent.d.ts.map +1 -0
  365. package/dist/leanAgent.js +175 -0
  366. package/dist/leanAgent.js.map +1 -0
  367. package/dist/orchestration/index.d.ts +14 -0
  368. package/dist/orchestration/index.d.ts.map +1 -0
  369. package/dist/orchestration/index.js +12 -0
  370. package/dist/orchestration/index.js.map +1 -0
  371. package/dist/plugins/index.d.ts +49 -0
  372. package/dist/plugins/index.d.ts.map +1 -0
  373. package/dist/plugins/index.js +104 -0
  374. package/dist/plugins/index.js.map +1 -0
  375. package/dist/plugins/providers/anthropic/index.d.ts +9 -0
  376. package/dist/plugins/providers/anthropic/index.d.ts.map +1 -0
  377. package/dist/plugins/providers/anthropic/index.js +48 -0
  378. package/dist/plugins/providers/anthropic/index.js.map +1 -0
  379. package/dist/plugins/providers/deepseek/index.d.ts +11 -0
  380. package/dist/plugins/providers/deepseek/index.d.ts.map +1 -0
  381. package/dist/plugins/providers/deepseek/index.js +54 -0
  382. package/dist/plugins/providers/deepseek/index.js.map +1 -0
  383. package/dist/plugins/providers/index.d.ts +2 -0
  384. package/dist/plugins/providers/index.d.ts.map +1 -0
  385. package/dist/plugins/providers/index.js +17 -0
  386. package/dist/plugins/providers/index.js.map +1 -0
  387. package/dist/plugins/providers/openai/index.d.ts +10 -0
  388. package/dist/plugins/providers/openai/index.d.ts.map +1 -0
  389. package/dist/plugins/providers/openai/index.js +47 -0
  390. package/dist/plugins/providers/openai/index.js.map +1 -0
  391. package/dist/plugins/providers/xai/index.d.ts +10 -0
  392. package/dist/plugins/providers/xai/index.d.ts.map +1 -0
  393. package/dist/plugins/providers/xai/index.js +47 -0
  394. package/dist/plugins/providers/xai/index.js.map +1 -0
  395. package/dist/plugins/tools/agentSpawning/agentSpawningPlugin.d.ts +10 -0
  396. package/dist/plugins/tools/agentSpawning/agentSpawningPlugin.d.ts.map +1 -0
  397. package/dist/plugins/tools/agentSpawning/agentSpawningPlugin.js +110 -0
  398. package/dist/plugins/tools/agentSpawning/agentSpawningPlugin.js.map +1 -0
  399. package/dist/plugins/tools/bash/localBashPlugin.d.ts +3 -0
  400. package/dist/plugins/tools/bash/localBashPlugin.d.ts.map +1 -0
  401. package/dist/plugins/tools/bash/localBashPlugin.js +14 -0
  402. package/dist/plugins/tools/bash/localBashPlugin.js.map +1 -0
  403. package/dist/plugins/tools/edit/editPlugin.d.ts +9 -0
  404. package/dist/plugins/tools/edit/editPlugin.d.ts.map +1 -0
  405. package/dist/plugins/tools/edit/editPlugin.js +15 -0
  406. package/dist/plugins/tools/edit/editPlugin.js.map +1 -0
  407. package/dist/plugins/tools/enhancedGit/enhancedGitPlugin.d.ts +3 -0
  408. package/dist/plugins/tools/enhancedGit/enhancedGitPlugin.d.ts.map +1 -0
  409. package/dist/plugins/tools/enhancedGit/enhancedGitPlugin.js +9 -0
  410. package/dist/plugins/tools/enhancedGit/enhancedGitPlugin.js.map +1 -0
  411. package/dist/plugins/tools/filesystem/localFilesystemPlugin.d.ts +3 -0
  412. package/dist/plugins/tools/filesystem/localFilesystemPlugin.d.ts.map +1 -0
  413. package/dist/plugins/tools/filesystem/localFilesystemPlugin.js +14 -0
  414. package/dist/plugins/tools/filesystem/localFilesystemPlugin.js.map +1 -0
  415. package/dist/plugins/tools/gitHistory/gitHistoryPlugin.d.ts +3 -0
  416. package/dist/plugins/tools/gitHistory/gitHistoryPlugin.d.ts.map +1 -0
  417. package/dist/plugins/tools/gitHistory/gitHistoryPlugin.js +9 -0
  418. package/dist/plugins/tools/gitHistory/gitHistoryPlugin.js.map +1 -0
  419. package/dist/plugins/tools/index.d.ts +3 -0
  420. package/dist/plugins/tools/index.d.ts.map +1 -0
  421. package/dist/plugins/tools/index.js +3 -0
  422. package/dist/plugins/tools/index.js.map +1 -0
  423. package/dist/plugins/tools/integrity/integrityPlugin.d.ts +3 -0
  424. package/dist/plugins/tools/integrity/integrityPlugin.d.ts.map +1 -0
  425. package/dist/plugins/tools/integrity/integrityPlugin.js +31 -0
  426. package/dist/plugins/tools/integrity/integrityPlugin.js.map +1 -0
  427. package/dist/plugins/tools/mcp/mcpPlugin.d.ts +3 -0
  428. package/dist/plugins/tools/mcp/mcpPlugin.d.ts.map +1 -0
  429. package/dist/plugins/tools/mcp/mcpPlugin.js +27 -0
  430. package/dist/plugins/tools/mcp/mcpPlugin.js.map +1 -0
  431. package/dist/plugins/tools/nodeDefaults.d.ts +13 -0
  432. package/dist/plugins/tools/nodeDefaults.d.ts.map +1 -0
  433. package/dist/plugins/tools/nodeDefaults.js +31 -0
  434. package/dist/plugins/tools/nodeDefaults.js.map +1 -0
  435. package/dist/plugins/tools/orchestration/orchestrationPlugin.d.ts +3 -0
  436. package/dist/plugins/tools/orchestration/orchestrationPlugin.d.ts.map +1 -0
  437. package/dist/plugins/tools/orchestration/orchestrationPlugin.js +340 -0
  438. package/dist/plugins/tools/orchestration/orchestrationPlugin.js.map +1 -0
  439. package/dist/plugins/tools/registry.d.ts +22 -0
  440. package/dist/plugins/tools/registry.d.ts.map +1 -0
  441. package/dist/plugins/tools/registry.js +58 -0
  442. package/dist/plugins/tools/registry.js.map +1 -0
  443. package/dist/plugins/tools/search/localSearchPlugin.d.ts +3 -0
  444. package/dist/plugins/tools/search/localSearchPlugin.d.ts.map +1 -0
  445. package/dist/plugins/tools/search/localSearchPlugin.js +14 -0
  446. package/dist/plugins/tools/search/localSearchPlugin.js.map +1 -0
  447. package/dist/plugins/tools/skills/skillPlugin.d.ts +3 -0
  448. package/dist/plugins/tools/skills/skillPlugin.d.ts.map +1 -0
  449. package/dist/plugins/tools/skills/skillPlugin.js +27 -0
  450. package/dist/plugins/tools/skills/skillPlugin.js.map +1 -0
  451. package/dist/providers/baseProvider.d.ts +148 -0
  452. package/dist/providers/baseProvider.d.ts.map +1 -0
  453. package/dist/providers/baseProvider.js +284 -0
  454. package/dist/providers/baseProvider.js.map +1 -0
  455. package/dist/providers/openaiChatCompletionsProvider.d.ts +64 -0
  456. package/dist/providers/openaiChatCompletionsProvider.d.ts.map +1 -0
  457. package/dist/providers/openaiChatCompletionsProvider.js +1003 -0
  458. package/dist/providers/openaiChatCompletionsProvider.js.map +1 -0
  459. package/dist/providers/providerFactory.d.ts +22 -0
  460. package/dist/providers/providerFactory.d.ts.map +1 -0
  461. package/dist/providers/providerFactory.js +25 -0
  462. package/dist/providers/providerFactory.js.map +1 -0
  463. package/dist/providers/resilientProvider.d.ts +103 -0
  464. package/dist/providers/resilientProvider.d.ts.map +1 -0
  465. package/dist/providers/resilientProvider.js +462 -0
  466. package/dist/providers/resilientProvider.js.map +1 -0
  467. package/dist/runtime/agentController.d.ts +114 -0
  468. package/dist/runtime/agentController.d.ts.map +1 -0
  469. package/dist/runtime/agentController.js +707 -0
  470. package/dist/runtime/agentController.js.map +1 -0
  471. package/dist/runtime/agentHost.d.ts +61 -0
  472. package/dist/runtime/agentHost.d.ts.map +1 -0
  473. package/dist/runtime/agentHost.js +157 -0
  474. package/dist/runtime/agentHost.js.map +1 -0
  475. package/dist/runtime/agentSession.d.ts +45 -0
  476. package/dist/runtime/agentSession.d.ts.map +1 -0
  477. package/dist/runtime/agentSession.js +210 -0
  478. package/dist/runtime/agentSession.js.map +1 -0
  479. package/dist/runtime/agentWorkerPool.d.ts +167 -0
  480. package/dist/runtime/agentWorkerPool.d.ts.map +1 -0
  481. package/dist/runtime/agentWorkerPool.js +435 -0
  482. package/dist/runtime/agentWorkerPool.js.map +1 -0
  483. package/dist/runtime/node.d.ts +7 -0
  484. package/dist/runtime/node.d.ts.map +1 -0
  485. package/dist/runtime/node.js +25 -0
  486. package/dist/runtime/node.js.map +1 -0
  487. package/dist/runtime/universal.d.ts +18 -0
  488. package/dist/runtime/universal.d.ts.map +1 -0
  489. package/dist/runtime/universal.js +21 -0
  490. package/dist/runtime/universal.js.map +1 -0
  491. package/dist/shell/autoExecutor.d.ts +70 -0
  492. package/dist/shell/autoExecutor.d.ts.map +1 -0
  493. package/dist/shell/autoExecutor.js +320 -0
  494. package/dist/shell/autoExecutor.js.map +1 -0
  495. package/dist/shell/commandRegistry.d.ts +122 -0
  496. package/dist/shell/commandRegistry.d.ts.map +1 -0
  497. package/dist/shell/commandRegistry.js +398 -0
  498. package/dist/shell/commandRegistry.js.map +1 -0
  499. package/dist/shell/composableMessage.d.ts +178 -0
  500. package/dist/shell/composableMessage.d.ts.map +1 -0
  501. package/dist/shell/composableMessage.js +384 -0
  502. package/dist/shell/composableMessage.js.map +1 -0
  503. package/dist/shell/liveStatus.d.ts +27 -0
  504. package/dist/shell/liveStatus.d.ts.map +1 -0
  505. package/dist/shell/liveStatus.js +53 -0
  506. package/dist/shell/liveStatus.js.map +1 -0
  507. package/dist/shell/systemPrompt.d.ts +12 -0
  508. package/dist/shell/systemPrompt.d.ts.map +1 -0
  509. package/dist/shell/systemPrompt.js +16 -0
  510. package/dist/shell/systemPrompt.js.map +1 -0
  511. package/dist/shell/vimMode.d.ts +66 -0
  512. package/dist/shell/vimMode.d.ts.map +1 -0
  513. package/dist/shell/vimMode.js +435 -0
  514. package/dist/shell/vimMode.js.map +1 -0
  515. package/dist/tools/bashTools.d.ts +7 -0
  516. package/dist/tools/bashTools.d.ts.map +1 -0
  517. package/dist/tools/bashTools.js +773 -0
  518. package/dist/tools/bashTools.js.map +1 -0
  519. package/dist/tools/diffUtils.d.ts +43 -0
  520. package/dist/tools/diffUtils.d.ts.map +1 -0
  521. package/dist/tools/diffUtils.js +607 -0
  522. package/dist/tools/diffUtils.js.map +1 -0
  523. package/dist/tools/editTools.d.ts +29 -0
  524. package/dist/tools/editTools.d.ts.map +1 -0
  525. package/dist/tools/editTools.js +673 -0
  526. package/dist/tools/editTools.js.map +1 -0
  527. package/dist/tools/emailTools.d.ts +140 -0
  528. package/dist/tools/emailTools.d.ts.map +1 -0
  529. package/dist/tools/emailTools.js +793 -0
  530. package/dist/tools/emailTools.js.map +1 -0
  531. package/dist/tools/fileChangeTracker.d.ts +47 -0
  532. package/dist/tools/fileChangeTracker.d.ts.map +1 -0
  533. package/dist/tools/fileChangeTracker.js +154 -0
  534. package/dist/tools/fileChangeTracker.js.map +1 -0
  535. package/dist/tools/fileReadTracker.d.ts +69 -0
  536. package/dist/tools/fileReadTracker.d.ts.map +1 -0
  537. package/dist/tools/fileReadTracker.js +213 -0
  538. package/dist/tools/fileReadTracker.js.map +1 -0
  539. package/dist/tools/fileTools.d.ts +3 -0
  540. package/dist/tools/fileTools.d.ts.map +1 -0
  541. package/dist/tools/fileTools.js +333 -0
  542. package/dist/tools/fileTools.js.map +1 -0
  543. package/dist/tools/grepTools.d.ts +3 -0
  544. package/dist/tools/grepTools.d.ts.map +1 -0
  545. package/dist/tools/grepTools.js +128 -0
  546. package/dist/tools/grepTools.js.map +1 -0
  547. package/dist/tools/hitlTools.d.ts +7 -0
  548. package/dist/tools/hitlTools.d.ts.map +1 -0
  549. package/dist/tools/hitlTools.js +189 -0
  550. package/dist/tools/hitlTools.js.map +1 -0
  551. package/dist/tools/humanOpsTools.d.ts +3 -0
  552. package/dist/tools/humanOpsTools.d.ts.map +1 -0
  553. package/dist/tools/humanOpsTools.js +86 -0
  554. package/dist/tools/humanOpsTools.js.map +1 -0
  555. package/dist/tools/localExplore.d.ts +38 -0
  556. package/dist/tools/localExplore.d.ts.map +1 -0
  557. package/dist/tools/localExplore.js +30 -0
  558. package/dist/tools/localExplore.js.map +1 -0
  559. package/dist/tools/metaTools.d.ts +3 -0
  560. package/dist/tools/metaTools.d.ts.map +1 -0
  561. package/dist/tools/metaTools.js +148 -0
  562. package/dist/tools/metaTools.js.map +1 -0
  563. package/dist/tools/planningTools.d.ts +81 -0
  564. package/dist/tools/planningTools.d.ts.map +1 -0
  565. package/dist/tools/planningTools.js +370 -0
  566. package/dist/tools/planningTools.js.map +1 -0
  567. package/dist/tools/searchTools.d.ts +12 -0
  568. package/dist/tools/searchTools.d.ts.map +1 -0
  569. package/dist/tools/searchTools.js +363 -0
  570. package/dist/tools/searchTools.js.map +1 -0
  571. package/dist/tools/telemetryTools.d.ts +10 -0
  572. package/dist/tools/telemetryTools.d.ts.map +1 -0
  573. package/dist/tools/telemetryTools.js +9 -0
  574. package/dist/tools/telemetryTools.js.map +1 -0
  575. package/dist/tools/unifiedOps.d.ts +3 -0
  576. package/dist/tools/unifiedOps.d.ts.map +1 -0
  577. package/dist/tools/unifiedOps.js +57 -0
  578. package/dist/tools/unifiedOps.js.map +1 -0
  579. package/dist/tools/webTools.d.ts +26 -0
  580. package/dist/tools/webTools.d.ts.map +1 -0
  581. package/dist/tools/webTools.js +227 -0
  582. package/dist/tools/webTools.js.map +1 -0
  583. package/dist/ui/PromptController.d.ts +193 -0
  584. package/dist/ui/PromptController.d.ts.map +1 -0
  585. package/dist/ui/PromptController.js +394 -0
  586. package/dist/ui/PromptController.js.map +1 -0
  587. package/dist/ui/UnifiedUIRenderer.d.ts +843 -0
  588. package/dist/ui/UnifiedUIRenderer.d.ts.map +1 -0
  589. package/dist/ui/UnifiedUIRenderer.js +5711 -0
  590. package/dist/ui/UnifiedUIRenderer.js.map +1 -0
  591. package/dist/ui/animatedStatus.d.ts +140 -0
  592. package/dist/ui/animatedStatus.d.ts.map +1 -0
  593. package/dist/ui/animatedStatus.js +480 -0
  594. package/dist/ui/animatedStatus.js.map +1 -0
  595. package/dist/ui/animation/AnimationScheduler.d.ts +197 -0
  596. package/dist/ui/animation/AnimationScheduler.d.ts.map +1 -0
  597. package/dist/ui/animation/AnimationScheduler.js +440 -0
  598. package/dist/ui/animation/AnimationScheduler.js.map +1 -0
  599. package/dist/ui/codeHighlighter.d.ts +6 -0
  600. package/dist/ui/codeHighlighter.d.ts.map +1 -0
  601. package/dist/ui/codeHighlighter.js +855 -0
  602. package/dist/ui/codeHighlighter.js.map +1 -0
  603. package/dist/ui/designSystem.d.ts +26 -0
  604. package/dist/ui/designSystem.d.ts.map +1 -0
  605. package/dist/ui/designSystem.js +114 -0
  606. package/dist/ui/designSystem.js.map +1 -0
  607. package/dist/ui/errorFormatter.d.ts +64 -0
  608. package/dist/ui/errorFormatter.d.ts.map +1 -0
  609. package/dist/ui/errorFormatter.js +316 -0
  610. package/dist/ui/errorFormatter.js.map +1 -0
  611. package/dist/ui/globalWriteLock.d.ts +63 -0
  612. package/dist/ui/globalWriteLock.d.ts.map +1 -0
  613. package/dist/ui/globalWriteLock.js +173 -0
  614. package/dist/ui/globalWriteLock.js.map +1 -0
  615. package/dist/ui/index.d.ts +32 -0
  616. package/dist/ui/index.d.ts.map +1 -0
  617. package/dist/ui/index.js +54 -0
  618. package/dist/ui/index.js.map +1 -0
  619. package/dist/ui/interrupts/InterruptManager.d.ts +157 -0
  620. package/dist/ui/interrupts/InterruptManager.d.ts.map +1 -0
  621. package/dist/ui/interrupts/InterruptManager.js +501 -0
  622. package/dist/ui/interrupts/InterruptManager.js.map +1 -0
  623. package/dist/ui/layout.d.ts +27 -0
  624. package/dist/ui/layout.d.ts.map +1 -0
  625. package/dist/ui/layout.js +184 -0
  626. package/dist/ui/layout.js.map +1 -0
  627. package/dist/ui/outputMode.d.ts +44 -0
  628. package/dist/ui/outputMode.d.ts.map +1 -0
  629. package/dist/ui/outputMode.js +123 -0
  630. package/dist/ui/outputMode.js.map +1 -0
  631. package/dist/ui/overlay/OverlayManager.d.ts +105 -0
  632. package/dist/ui/overlay/OverlayManager.d.ts.map +1 -0
  633. package/dist/ui/overlay/OverlayManager.js +304 -0
  634. package/dist/ui/overlay/OverlayManager.js.map +1 -0
  635. package/dist/ui/premiumComponents.d.ts +54 -0
  636. package/dist/ui/premiumComponents.d.ts.map +1 -0
  637. package/dist/ui/premiumComponents.js +241 -0
  638. package/dist/ui/premiumComponents.js.map +1 -0
  639. package/dist/ui/richText.d.ts +13 -0
  640. package/dist/ui/richText.d.ts.map +1 -0
  641. package/dist/ui/richText.js +444 -0
  642. package/dist/ui/richText.js.map +1 -0
  643. package/dist/ui/telemetry/ResponseTracker.d.ts +22 -0
  644. package/dist/ui/telemetry/ResponseTracker.d.ts.map +1 -0
  645. package/dist/ui/telemetry/ResponseTracker.js +60 -0
  646. package/dist/ui/telemetry/ResponseTracker.js.map +1 -0
  647. package/dist/ui/telemetry/UITelemetry.d.ts +181 -0
  648. package/dist/ui/telemetry/UITelemetry.d.ts.map +1 -0
  649. package/dist/ui/telemetry/UITelemetry.js +446 -0
  650. package/dist/ui/telemetry/UITelemetry.js.map +1 -0
  651. package/dist/ui/textHighlighter.d.ts +83 -0
  652. package/dist/ui/textHighlighter.d.ts.map +1 -0
  653. package/dist/ui/textHighlighter.js +267 -0
  654. package/dist/ui/textHighlighter.js.map +1 -0
  655. package/dist/ui/theme.d.ts +364 -0
  656. package/dist/ui/theme.d.ts.map +1 -0
  657. package/dist/ui/theme.js +471 -0
  658. package/dist/ui/theme.js.map +1 -0
  659. package/dist/ui/toolDisplay.d.ts +221 -0
  660. package/dist/ui/toolDisplay.d.ts.map +1 -0
  661. package/dist/ui/toolDisplay.js +1654 -0
  662. package/dist/ui/toolDisplay.js.map +1 -0
  663. package/dist/ui/uiConstants.d.ts +288 -0
  664. package/dist/ui/uiConstants.d.ts.map +1 -0
  665. package/dist/ui/uiConstants.js +472 -0
  666. package/dist/ui/uiConstants.js.map +1 -0
  667. package/dist/utils/askUserPrompt.d.ts +21 -0
  668. package/dist/utils/askUserPrompt.d.ts.map +1 -0
  669. package/dist/utils/askUserPrompt.js +87 -0
  670. package/dist/utils/askUserPrompt.js.map +1 -0
  671. package/dist/utils/asyncUtils.d.ts +95 -0
  672. package/dist/utils/asyncUtils.d.ts.map +1 -0
  673. package/dist/utils/asyncUtils.js +286 -0
  674. package/dist/utils/asyncUtils.js.map +1 -0
  675. package/dist/utils/debugLogger.d.ts +6 -0
  676. package/dist/utils/debugLogger.d.ts.map +1 -0
  677. package/dist/utils/debugLogger.js +39 -0
  678. package/dist/utils/debugLogger.js.map +1 -0
  679. package/dist/utils/errorUtils.d.ts +12 -0
  680. package/dist/utils/errorUtils.d.ts.map +1 -0
  681. package/dist/utils/errorUtils.js +83 -0
  682. package/dist/utils/errorUtils.js.map +1 -0
  683. package/dist/utils/frontmatter.d.ts +10 -0
  684. package/dist/utils/frontmatter.d.ts.map +1 -0
  685. package/dist/utils/frontmatter.js +78 -0
  686. package/dist/utils/frontmatter.js.map +1 -0
  687. package/dist/utils/packageInfo.d.ts +14 -0
  688. package/dist/utils/packageInfo.d.ts.map +1 -0
  689. package/dist/utils/packageInfo.js +45 -0
  690. package/dist/utils/packageInfo.js.map +1 -0
  691. package/dist/utils/planFormatter.d.ts +34 -0
  692. package/dist/utils/planFormatter.d.ts.map +1 -0
  693. package/dist/utils/planFormatter.js +141 -0
  694. package/dist/utils/planFormatter.js.map +1 -0
  695. package/dist/utils/securityUtils.d.ts +132 -0
  696. package/dist/utils/securityUtils.d.ts.map +1 -0
  697. package/dist/utils/securityUtils.js +324 -0
  698. package/dist/utils/securityUtils.js.map +1 -0
  699. package/dist/utils/statusReporter.d.ts +6 -0
  700. package/dist/utils/statusReporter.d.ts.map +1 -0
  701. package/dist/utils/statusReporter.js +26 -0
  702. package/dist/utils/statusReporter.js.map +1 -0
  703. package/dist/workspace.d.ts +8 -0
  704. package/dist/workspace.d.ts.map +1 -0
  705. package/dist/workspace.js +135 -0
  706. package/dist/workspace.js.map +1 -0
  707. package/dist/workspace.validator.d.ts +49 -0
  708. package/dist/workspace.validator.d.ts.map +1 -0
  709. package/dist/workspace.validator.js +215 -0
  710. package/dist/workspace.validator.js.map +1 -0
  711. package/package.json +121 -0
@@ -0,0 +1,1585 @@
1
+ /**
2
+ * AGI Core - Unified Autonomous General Intelligence for Software Engineering
3
+ *
4
+ * This is the central intelligence module that provides:
5
+ * 1. Unified prompt understanding and routing
6
+ * 2. Real task decomposition and planning
7
+ * 3. Persistent learning and memory
8
+ * 4. Autonomous execution with verification
9
+ *
10
+ * NO SIMULATIONS - All operations execute real tools
11
+ */
12
+ import * as fs from 'fs';
13
+ import * as path from 'path';
14
+ import { EventEmitter } from 'events';
15
+ import { getEpisodicMemory } from './episodicMemory.js';
16
+ import { getSelfUpgrade, SelfUpgrade } from './selfUpgrade.js';
17
+ import { getHotReload } from './hotReload.js';
18
+ // ============================================================================
19
+ // AGI CORE CLASS
20
+ // ============================================================================
21
+ export class AGICore extends EventEmitter {
22
+ context;
23
+ memoryPath;
24
+ episodicMemory;
25
+ currentEpisodeId = null;
26
+ selfUpgrade;
27
+ hotReload;
28
+ upgradeCheckPromise = null;
29
+ constructor(workingDir) {
30
+ super();
31
+ const dir = workingDir || process.cwd();
32
+ this.memoryPath = path.join(dir, '.agi', 'agi-memory.json');
33
+ this.context = {
34
+ workingDir: dir,
35
+ sessionId: `agi-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
36
+ startTime: Date.now(),
37
+ memory: this.loadMemory(),
38
+ };
39
+ // Initialize episodic memory system
40
+ this.episodicMemory = getEpisodicMemory();
41
+ // Initialize self-upgrade system
42
+ this.selfUpgrade = getSelfUpgrade({
43
+ workingDir: dir,
44
+ autoRestart: true,
45
+ logger: (msg) => this.emit('upgrade:log', msg),
46
+ });
47
+ // Initialize hot-reload system
48
+ this.hotReload = getHotReload({
49
+ workingDir: dir,
50
+ autoCheck: true,
51
+ checkInterval: 5 * 60 * 1000, // Check every 5 minutes
52
+ logger: (msg) => this.emit('hotReload:log', msg),
53
+ });
54
+ // Forward upgrade events
55
+ this.selfUpgrade.on('upgrade', (event) => this.emit('upgrade', event));
56
+ this.hotReload.on('hotReload', (event) => this.emit('hotReload', event));
57
+ // Check for upgrade on initialization (non-blocking)
58
+ this.upgradeCheckPromise = this.checkForUpgradeOnStart();
59
+ // Analyze project on initialization
60
+ this.analyzeProject();
61
+ }
62
+ /**
63
+ * Non-blocking upgrade check on startup
64
+ */
65
+ async checkForUpgradeOnStart() {
66
+ try {
67
+ const versionInfo = await this.selfUpgrade.checkForUpdates();
68
+ if (versionInfo.updateAvailable) {
69
+ this.emit('upgrade:available', {
70
+ current: versionInfo.current,
71
+ latest: versionInfo.latest,
72
+ });
73
+ }
74
+ }
75
+ catch {
76
+ // Non-blocking, ignore errors
77
+ }
78
+ }
79
+ // ==========================================================================
80
+ // MEMORY MANAGEMENT - Real Persistent Learning
81
+ // ==========================================================================
82
+ loadMemory() {
83
+ try {
84
+ if (fs.existsSync(this.memoryPath)) {
85
+ const data = fs.readFileSync(this.memoryPath, 'utf-8');
86
+ return JSON.parse(data);
87
+ }
88
+ }
89
+ catch {
90
+ // Start fresh if memory is corrupted
91
+ }
92
+ return this.createEmptyMemory();
93
+ }
94
+ createEmptyMemory() {
95
+ return {
96
+ patterns: [],
97
+ recentOps: [],
98
+ projectKnowledge: {
99
+ type: 'unknown',
100
+ buildSystem: null,
101
+ testCommand: null,
102
+ lintCommand: null,
103
+ entryPoints: [],
104
+ dependencies: {},
105
+ lastAnalyzed: 0,
106
+ },
107
+ };
108
+ }
109
+ saveMemory() {
110
+ try {
111
+ const dir = path.dirname(this.memoryPath);
112
+ if (!fs.existsSync(dir)) {
113
+ fs.mkdirSync(dir, { recursive: true });
114
+ }
115
+ fs.writeFileSync(this.memoryPath, JSON.stringify(this.context.memory, null, 2));
116
+ }
117
+ catch (error) {
118
+ this.emit('warning', `Failed to save memory: ${error}`);
119
+ }
120
+ }
121
+ /**
122
+ * Learn from a successful operation
123
+ */
124
+ learnFromSuccess(prompt, approach, tools) {
125
+ const existingPattern = this.context.memory.patterns.find(p => this.normalizePrompt(p.trigger) === this.normalizePrompt(prompt));
126
+ if (existingPattern) {
127
+ existingPattern.successCount++;
128
+ existingPattern.lastUsed = Date.now();
129
+ existingPattern.successfulApproach = approach;
130
+ existingPattern.tools = tools;
131
+ }
132
+ else {
133
+ this.context.memory.patterns.push({
134
+ id: `pattern-${Date.now()}`,
135
+ trigger: prompt,
136
+ successfulApproach: approach,
137
+ tools,
138
+ successCount: 1,
139
+ lastUsed: Date.now(),
140
+ });
141
+ }
142
+ // Keep only most useful patterns (limit to 100)
143
+ this.context.memory.patterns = this.context.memory.patterns
144
+ .sort((a, b) => (b.successCount * 0.7 + (b.lastUsed - a.lastUsed) / 86400000 * 0.3) -
145
+ (a.successCount * 0.7 + (a.lastUsed - b.lastUsed) / 86400000 * 0.3))
146
+ .slice(0, 100);
147
+ this.saveMemory();
148
+ }
149
+ /**
150
+ * Record an operation for context
151
+ */
152
+ recordOperation(op) {
153
+ this.context.memory.recentOps.unshift(op);
154
+ // Keep last 50 operations
155
+ this.context.memory.recentOps = this.context.memory.recentOps.slice(0, 50);
156
+ this.saveMemory();
157
+ }
158
+ /**
159
+ * Get learned approach for similar prompts
160
+ */
161
+ getLearnedApproach(prompt) {
162
+ const normalized = this.normalizePrompt(prompt);
163
+ return this.context.memory.patterns.find(p => this.normalizePrompt(p.trigger) === normalized ||
164
+ this.promptSimilarity(p.trigger, prompt) > 0.7) || null;
165
+ }
166
+ normalizePrompt(prompt) {
167
+ return prompt.toLowerCase().trim().replace(/[^\w\s]/g, '');
168
+ }
169
+ promptSimilarity(a, b) {
170
+ const wordsA = new Set(this.normalizePrompt(a).split(/\s+/));
171
+ const wordsB = new Set(this.normalizePrompt(b).split(/\s+/));
172
+ const intersection = new Set([...wordsA].filter(x => wordsB.has(x)));
173
+ const union = new Set([...wordsA, ...wordsB]);
174
+ return intersection.size / union.size;
175
+ }
176
+ // ==========================================================================
177
+ // PROJECT ANALYSIS - Understand the Codebase
178
+ // ==========================================================================
179
+ analyzeProject() {
180
+ const knowledge = this.context.memory.projectKnowledge;
181
+ const dir = this.context.workingDir;
182
+ // Check for package.json (Node.js)
183
+ const packageJsonPath = path.join(dir, 'package.json');
184
+ if (fs.existsSync(packageJsonPath)) {
185
+ try {
186
+ const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
187
+ knowledge.type = 'node';
188
+ knowledge.dependencies = { ...pkg.dependencies, ...pkg.devDependencies };
189
+ if (pkg.scripts) {
190
+ knowledge.testCommand = pkg.scripts.test ? 'npm test' : null;
191
+ knowledge.lintCommand = pkg.scripts.lint ? 'npm run lint' : null;
192
+ knowledge.buildSystem = pkg.scripts.build ? 'npm run build' : null;
193
+ }
194
+ if (pkg.main) {
195
+ knowledge.entryPoints.push(pkg.main);
196
+ }
197
+ }
198
+ catch {
199
+ // Ignore parse errors
200
+ }
201
+ }
202
+ // Check for pyproject.toml or setup.py (Python)
203
+ if (fs.existsSync(path.join(dir, 'pyproject.toml')) ||
204
+ fs.existsSync(path.join(dir, 'setup.py'))) {
205
+ knowledge.type = 'python';
206
+ knowledge.testCommand = 'pytest';
207
+ knowledge.lintCommand = 'ruff check .';
208
+ }
209
+ // Check for Cargo.toml (Rust)
210
+ if (fs.existsSync(path.join(dir, 'Cargo.toml'))) {
211
+ knowledge.type = 'rust';
212
+ knowledge.testCommand = 'cargo test';
213
+ knowledge.lintCommand = 'cargo clippy';
214
+ knowledge.buildSystem = 'cargo build';
215
+ }
216
+ // Check for go.mod (Go)
217
+ if (fs.existsSync(path.join(dir, 'go.mod'))) {
218
+ knowledge.type = 'go';
219
+ knowledge.testCommand = 'go test ./...';
220
+ knowledge.lintCommand = 'golangci-lint run';
221
+ knowledge.buildSystem = 'go build';
222
+ }
223
+ knowledge.lastAnalyzed = Date.now();
224
+ this.saveMemory();
225
+ }
226
+ // ==========================================================================
227
+ // PROMPT UNDERSTANDING - Parse and Interpret User Requests
228
+ // ==========================================================================
229
+ /**
230
+ * Analyze a user prompt and produce a comprehensive execution plan
231
+ */
232
+ analyzePrompt(prompt) {
233
+ const lower = prompt.toLowerCase().trim();
234
+ // Check for learned patterns first
235
+ const learned = this.getLearnedApproach(prompt);
236
+ if (learned && learned.successCount >= 2) {
237
+ return this.createFromLearnedPattern(prompt, learned);
238
+ }
239
+ // Determine intent
240
+ const intent = this.determineIntent(lower);
241
+ const category = this.determineCategory(intent);
242
+ // Generate tasks based on intent
243
+ const tasks = this.generateTasks(prompt, intent);
244
+ // Check for ambiguity
245
+ const clarificationNeeded = this.checkAmbiguity(prompt, intent);
246
+ // Extract scope targets from the prompt
247
+ const identifiedScope = this.extractScope(prompt);
248
+ // Generate interpretation risks
249
+ const interpretationRisks = this.identifyInterpretationRisks(prompt, intent);
250
+ // Generate intent restatement for confirmation
251
+ const intentRestatement = this.generateIntentRestatement(prompt, intent, identifiedScope);
252
+ // Calculate confidence based on multiple factors
253
+ const confidence = this.calculateConfidence(prompt, intent, clarificationNeeded, identifiedScope, interpretationRisks);
254
+ return {
255
+ originalPrompt: prompt,
256
+ interpretation: this.generateInterpretation(prompt, intent),
257
+ intent,
258
+ category,
259
+ confidence,
260
+ tasks,
261
+ clarificationNeeded,
262
+ intentRestatement,
263
+ identifiedScope,
264
+ interpretationRisks,
265
+ };
266
+ }
267
+ /**
268
+ * Extract specific scope/targets from the prompt
269
+ */
270
+ extractScope(prompt) {
271
+ const scope = [];
272
+ const lower = prompt.toLowerCase();
273
+ // File paths and extensions
274
+ const filePatterns = prompt.match(/\b[\w\-./]+\.(ts|js|tsx|jsx|py|json|md|css|scss|html|yml|yaml|toml|sh)\b/gi);
275
+ if (filePatterns) {
276
+ scope.push(...filePatterns.map(f => `file: ${f}`));
277
+ }
278
+ // Function/method names (camelCase or snake_case after action verbs)
279
+ const funcPatterns = prompt.match(/\b(function|method|fn|def|func)\s+(\w+)/gi);
280
+ if (funcPatterns) {
281
+ scope.push(...funcPatterns.map(f => `function: ${f.split(/\s+/)[1]}`));
282
+ }
283
+ // Component names (PascalCase)
284
+ const componentPatterns = prompt.match(/\b[A-Z][a-zA-Z]+(?:Component|Provider|Context|Hook|Service|Controller|Manager)\b/g);
285
+ if (componentPatterns) {
286
+ scope.push(...componentPatterns.map(c => `component: ${c}`));
287
+ }
288
+ // Directory paths
289
+ const dirPatterns = prompt.match(/\b(?:in|from|to|at)\s+([\w\-./]+\/)/gi);
290
+ if (dirPatterns) {
291
+ scope.push(...dirPatterns.map(d => `directory: ${d.split(/\s+/).pop()}`));
292
+ }
293
+ // Module/package names
294
+ const modulePatterns = lower.match(/\b(module|package|library)\s+(\w+)/gi);
295
+ if (modulePatterns) {
296
+ scope.push(...modulePatterns.map(m => m));
297
+ }
298
+ // Class names
299
+ const classPatterns = prompt.match(/\bclass\s+(\w+)/gi);
300
+ if (classPatterns) {
301
+ scope.push(...classPatterns.map(c => c));
302
+ }
303
+ return [...new Set(scope)]; // Deduplicate
304
+ }
305
+ /**
306
+ * Identify potential risks in interpreting the prompt
307
+ */
308
+ identifyInterpretationRisks(prompt, intent) {
309
+ const risks = [];
310
+ const lower = prompt.toLowerCase();
311
+ // Risk: Implicit scope could lead to over-reaching changes
312
+ if (intent === 'refactor' && !/\b(only|just|specific|single)\b/i.test(lower)) {
313
+ risks.push('Refactoring scope unclear - could affect more files than intended');
314
+ }
315
+ // Risk: Destructive operations
316
+ if (/\b(delete|remove|drop|clear|wipe|reset)\b/i.test(lower)) {
317
+ risks.push('Destructive operation - verify exact targets before proceeding');
318
+ }
319
+ // Risk: Vague improvement could lead to unwanted changes
320
+ if (/\b(improve|better|enhance|optimize)\b/i.test(lower) && !/\b(performance|speed|memory|readability|security)\b/i.test(lower)) {
321
+ risks.push('Improvement criteria not specified - may not match user expectations');
322
+ }
323
+ // Risk: "Fix" without error context
324
+ if (intent === 'fix_bugs' && !/\b(error|bug|issue|crash|fail|broken|exception|undefined|null)\b/i.test(lower)) {
325
+ risks.push('No specific error mentioned - may need to identify the actual problem first');
326
+ }
327
+ // Risk: Multi-step request might have implicit ordering
328
+ const actions = lower.match(/\b(and|then|after|before|also|plus)\b/gi) || [];
329
+ if (actions.length >= 2) {
330
+ risks.push('Multi-step request - verify intended order of operations');
331
+ }
332
+ // Risk: Ambiguous "this" or "it" references
333
+ if (/^(fix|change|update|modify)\s+(this|it|that)\b/i.test(lower)) {
334
+ risks.push('Ambiguous reference - confirm what "this/it" refers to');
335
+ }
336
+ // Risk: No test/validation mentioned for code changes
337
+ if (['add_feature', 'refactor', 'fix_bugs'].includes(intent) && !/\b(test|verify|check|validate)\b/i.test(lower)) {
338
+ risks.push('No validation criteria specified - will run standard checks after changes');
339
+ }
340
+ return risks.slice(0, 3); // Limit to top 3 risks
341
+ }
342
+ /**
343
+ * Generate a clear restatement of the user's intent for confirmation
344
+ */
345
+ generateIntentRestatement(prompt, intent, scope) {
346
+ const intentDescriptions = {
347
+ 'fix_bugs': 'fix bugs/errors',
348
+ 'add_feature': 'add new functionality',
349
+ 'refactor': 'refactor/reorganize code',
350
+ 'test': 'create or run tests',
351
+ 'document': 'create/update documentation',
352
+ 'deploy': 'deploy the application',
353
+ 'analyze': 'analyze/review code',
354
+ 'explain': 'explain how something works',
355
+ 'optimize': 'improve performance',
356
+ 'security_audit': 'review security',
357
+ 'setup': 'set up/configure',
358
+ 'migrate': 'migrate/upgrade',
359
+ 'research': 'research/investigate',
360
+ 'data_analysis': 'analyze data',
361
+ 'scientific_computing': 'build scientific computing tools',
362
+ 'legal_research': 'legal research/analysis',
363
+ 'business_analysis': 'business analysis',
364
+ 'financial_analysis': 'financial analysis',
365
+ 'automate': 'create automation',
366
+ 'monitor': 'set up monitoring',
367
+ 'generic_task': 'complete the requested task',
368
+ };
369
+ const intentDesc = intentDescriptions[intent] || 'complete the requested task';
370
+ const scopeDesc = scope.length > 0
371
+ ? ` targeting: ${scope.slice(0, 3).join(', ')}${scope.length > 3 ? '...' : ''}`
372
+ : '';
373
+ // Extract key action words from the prompt for more specific restatement
374
+ const actionMatch = prompt.match(/^(\w+)\s+(.{10,50})/i);
375
+ const specificAction = actionMatch ? actionMatch[0].substring(0, 60) : prompt.substring(0, 60);
376
+ return `I understand you want me to ${intentDesc}${scopeDesc}. Specifically: "${specificAction}${prompt.length > 60 ? '...' : ''}"`;
377
+ }
378
+ /**
379
+ * Calculate confidence score based on multiple factors
380
+ */
381
+ calculateConfidence(prompt, intent, clarificationNeeded, identifiedScope, interpretationRisks) {
382
+ let confidence = 0.9; // Start with high confidence
383
+ // Reduce confidence for each clarification needed
384
+ confidence -= clarificationNeeded.length * 0.15;
385
+ // Reduce confidence for each interpretation risk
386
+ confidence -= interpretationRisks.length * 0.1;
387
+ // Increase confidence if specific scope is identified
388
+ if (identifiedScope.length > 0) {
389
+ confidence += Math.min(identifiedScope.length * 0.05, 0.1);
390
+ }
391
+ // Reduce confidence for very short prompts (likely ambiguous)
392
+ const wordCount = prompt.split(/\s+/).length;
393
+ if (wordCount < 5) {
394
+ confidence -= 0.2;
395
+ }
396
+ // Reduce confidence for generic intent
397
+ if (intent === 'generic_task') {
398
+ confidence -= 0.15;
399
+ }
400
+ // Reduce confidence for vague language
401
+ if (/\b(maybe|possibly|perhaps|kind of|sort of|somehow)\b/i.test(prompt)) {
402
+ confidence -= 0.1;
403
+ }
404
+ // Clamp to valid range
405
+ return Math.max(0.3, Math.min(0.95, confidence));
406
+ }
407
+ determineIntent(lower) {
408
+ // Order matters! More specific patterns first.
409
+ // =========================================================================
410
+ // NON-SWE DOMAINS (check first for domain-specific keywords)
411
+ // =========================================================================
412
+ // Legal/Litigation (sue, lawsuit, court, legal action)
413
+ if (/\bsue\b|lawsuit|litigation|legal\s+action|\bcourt\b|attorney|lawyer|complaint|motion|brief/i.test(lower)) {
414
+ return 'legal_research';
415
+ }
416
+ // Financial/Accounting (accounting, bookkeeping, tax, financial)
417
+ if (/accounting|bookkeeping|financ|tax\b|ledger|balance\s*sheet|invoice|payroll|budget|forecast/i.test(lower)) {
418
+ return 'financial_analysis';
419
+ }
420
+ // Scientific Research (cure, research, experiment, hypothesis, study)
421
+ if (/\bcure\b|research|experiment|hypothesis|scientific|laboratory|clinical|biomedical|genome|molecular/i.test(lower)) {
422
+ return 'research';
423
+ }
424
+ // Data Analysis/Science (data analysis, ML, statistics, visualization)
425
+ if (/data\s+(?:analysis|science|engineer)|statistic|machine\s+learning|\bml\b|\bai\b|neural|dataset/i.test(lower)) {
426
+ return 'data_analysis';
427
+ }
428
+ // Engineering/Science (engineering, physics, chemistry, simulation)
429
+ if (/engineer(?:ing)?|physic|chemist|simulat|cad\b|finite\s+element|signal\s+process/i.test(lower)) {
430
+ return 'scientific_computing';
431
+ }
432
+ // Business Analysis (business, strategy, market, competitor)
433
+ if (/business|strateg|\bmarket\b|competitor|swot|business\s+plan/i.test(lower)) {
434
+ return 'business_analysis';
435
+ }
436
+ // Automation/Operations (automate, workflow, schedule, cron)
437
+ // Note: "pipeline" without "CI" or "CD" context - those go to setup
438
+ if (/\bautomat|\bworkflow|\bschedule|\bcron\b|batch\s+process/i.test(lower)) {
439
+ return 'automate';
440
+ }
441
+ // Data pipeline (ETL, data pipeline) - separate from CI/CD
442
+ if (/(?:data|etl)\s+pipeline/i.test(lower)) {
443
+ return 'automate';
444
+ }
445
+ // Monitoring (monitor, alert, dashboard, metrics, observability)
446
+ if (/\bmonitor|alert|dashboard|metric|observab|logging|trace/i.test(lower)) {
447
+ return 'monitor';
448
+ }
449
+ // =========================================================================
450
+ // SOFTWARE ENGINEERING DOMAINS
451
+ // =========================================================================
452
+ // Security audit (check before general 'audit')
453
+ if (/security|vulnerab|pentest|secure/i.test(lower)) {
454
+ return 'security_audit';
455
+ }
456
+ // Optimization (check before 'improve' which could be refactor)
457
+ if (/optim|faster|performance|speed\s*up|slow/i.test(lower)) {
458
+ return 'optimize';
459
+ }
460
+ // Explanation (check before 'document' - "explain" is for understanding, not writing docs)
461
+ if (/\bwhat\b|\bhow\b.*work|\bwhy\b|\bexplain\b|\bunderstand/i.test(lower)) {
462
+ return 'explain';
463
+ }
464
+ // Bug fixing
465
+ if (/fix|bug|error|issue|broken|crash|fail/i.test(lower)) {
466
+ return 'fix_bugs';
467
+ }
468
+ // Setup/Configuration (check before 'add' - configure is setup, not adding)
469
+ if (/setup|install|configure|init/i.test(lower)) {
470
+ return 'setup';
471
+ }
472
+ // Feature addition
473
+ if (/add|create|implement|build|new|feature/i.test(lower)) {
474
+ return 'add_feature';
475
+ }
476
+ // Refactoring (check 'improve' here after optimization is handled)
477
+ if (/refactor|clean|improve|reorganize|restructure/i.test(lower)) {
478
+ return 'refactor';
479
+ }
480
+ // Testing
481
+ if (/test|spec|coverage|verify/i.test(lower)) {
482
+ return 'test';
483
+ }
484
+ // Documentation
485
+ if (/document|readme|comment|doc\b/i.test(lower)) {
486
+ return 'document';
487
+ }
488
+ // Deployment
489
+ if (/deploy|release|publish|ship/i.test(lower)) {
490
+ return 'deploy';
491
+ }
492
+ // Analysis (general analysis, after security)
493
+ if (/analyze|review|audit|check|inspect/i.test(lower)) {
494
+ return 'analyze';
495
+ }
496
+ // Migration
497
+ if (/migrate|upgrade|update|version/i.test(lower)) {
498
+ return 'migrate';
499
+ }
500
+ return 'generic_task';
501
+ }
502
+ determineCategory(intent) {
503
+ const mapping = {
504
+ // Software Engineering
505
+ 'fix_bugs': 'code_modification',
506
+ 'add_feature': 'code_modification',
507
+ 'refactor': 'code_modification',
508
+ 'test': 'testing',
509
+ 'document': 'documentation',
510
+ 'deploy': 'infrastructure',
511
+ 'analyze': 'code_analysis',
512
+ 'explain': 'research',
513
+ 'optimize': 'code_modification',
514
+ 'security_audit': 'code_analysis',
515
+ 'setup': 'infrastructure',
516
+ 'migrate': 'code_modification',
517
+ // Research & Science
518
+ 'research': 'scientific',
519
+ 'data_analysis': 'scientific',
520
+ 'scientific_computing': 'scientific',
521
+ // Business & Legal
522
+ 'legal_research': 'legal',
523
+ 'business_analysis': 'business',
524
+ 'financial_analysis': 'financial',
525
+ // Automation & Operations
526
+ 'automate': 'automation',
527
+ 'monitor': 'operations',
528
+ // Generic
529
+ 'generic_task': 'general_coding',
530
+ };
531
+ return mapping[intent];
532
+ }
533
+ generateInterpretation(prompt, intent) {
534
+ const interpretations = {
535
+ // Software Engineering
536
+ 'fix_bugs': `Identify and fix bugs/errors in the codebase based on: "${prompt}"`,
537
+ 'add_feature': `Implement new functionality: "${prompt}"`,
538
+ 'refactor': `Improve code structure and quality: "${prompt}"`,
539
+ 'test': `Create or run tests: "${prompt}"`,
540
+ 'document': `Create or update documentation: "${prompt}"`,
541
+ 'deploy': `Prepare and execute deployment: "${prompt}"`,
542
+ 'analyze': `Analyze and review: "${prompt}"`,
543
+ 'explain': `Explain and clarify: "${prompt}"`,
544
+ 'optimize': `Improve performance: "${prompt}"`,
545
+ 'security_audit': `Security review and hardening: "${prompt}"`,
546
+ 'setup': `Set up and configure: "${prompt}"`,
547
+ 'migrate': `Migrate or upgrade: "${prompt}"`,
548
+ // Research & Science
549
+ 'research': `Build research tools and analysis pipeline for: "${prompt}"`,
550
+ 'data_analysis': `Create data analysis pipeline and visualizations for: "${prompt}"`,
551
+ 'scientific_computing': `Build scientific computing tools for: "${prompt}"`,
552
+ // Business & Legal
553
+ 'legal_research': `Legal research and document automation for: "${prompt}"`,
554
+ 'business_analysis': `Business analysis and strategy tools for: "${prompt}"`,
555
+ 'financial_analysis': `Financial analysis and reporting tools for: "${prompt}"`,
556
+ // Automation & Operations
557
+ 'automate': `Build automation workflow for: "${prompt}"`,
558
+ 'monitor': `Create monitoring and alerting system for: "${prompt}"`,
559
+ // Generic
560
+ 'generic_task': `Execute task: "${prompt}"`,
561
+ };
562
+ return interpretations[intent];
563
+ }
564
+ generateTasks(prompt, intent) {
565
+ const tasks = [];
566
+ const knowledge = this.context.memory.projectKnowledge;
567
+ switch (intent) {
568
+ case 'fix_bugs':
569
+ // First: analyze the codebase
570
+ tasks.push({
571
+ id: 'analyze-errors',
572
+ description: 'Run type checker and linter to identify issues',
573
+ category: 'execution',
574
+ tools: ['Bash'],
575
+ dependencies: [],
576
+ status: 'pending',
577
+ });
578
+ if (knowledge.testCommand) {
579
+ tasks.push({
580
+ id: 'run-tests',
581
+ description: 'Run test suite to find failing tests',
582
+ category: 'execution',
583
+ tools: ['Bash'],
584
+ dependencies: [],
585
+ status: 'pending',
586
+ });
587
+ }
588
+ tasks.push({
589
+ id: 'search-issues',
590
+ description: 'Search for TODO/FIXME comments and known issues',
591
+ category: 'search',
592
+ tools: ['Grep'],
593
+ dependencies: [],
594
+ status: 'pending',
595
+ });
596
+ tasks.push({
597
+ id: 'analyze-findings',
598
+ description: 'Analyze all findings and prioritize fixes',
599
+ category: 'analysis',
600
+ tools: ['Read'],
601
+ dependencies: ['analyze-errors', 'search-issues'],
602
+ status: 'pending',
603
+ });
604
+ tasks.push({
605
+ id: 'fix-issues',
606
+ description: 'Apply fixes to identified issues',
607
+ category: 'modification',
608
+ tools: ['Edit'],
609
+ dependencies: ['analyze-findings'],
610
+ status: 'pending',
611
+ });
612
+ tasks.push({
613
+ id: 'verify-fixes',
614
+ description: 'Verify fixes by re-running checks',
615
+ category: 'verification',
616
+ tools: ['Bash'],
617
+ dependencies: ['fix-issues'],
618
+ status: 'pending',
619
+ });
620
+ break;
621
+ case 'add_feature':
622
+ tasks.push({
623
+ id: 'understand-codebase',
624
+ description: 'Analyze existing code structure',
625
+ category: 'analysis',
626
+ tools: ['Glob', 'Read'],
627
+ dependencies: [],
628
+ status: 'pending',
629
+ });
630
+ tasks.push({
631
+ id: 'plan-implementation',
632
+ description: 'Plan the implementation approach',
633
+ category: 'analysis',
634
+ tools: ['Read'],
635
+ dependencies: ['understand-codebase'],
636
+ status: 'pending',
637
+ });
638
+ tasks.push({
639
+ id: 'implement-feature',
640
+ description: 'Write the feature code',
641
+ category: 'modification',
642
+ tools: ['Edit', 'Write'],
643
+ dependencies: ['plan-implementation'],
644
+ status: 'pending',
645
+ });
646
+ tasks.push({
647
+ id: 'add-tests',
648
+ description: 'Add tests for the new feature',
649
+ category: 'modification',
650
+ tools: ['Edit', 'Write'],
651
+ dependencies: ['implement-feature'],
652
+ status: 'pending',
653
+ });
654
+ tasks.push({
655
+ id: 'verify-feature',
656
+ description: 'Run tests and verify feature works',
657
+ category: 'verification',
658
+ tools: ['Bash'],
659
+ dependencies: ['add-tests'],
660
+ status: 'pending',
661
+ });
662
+ break;
663
+ case 'analyze':
664
+ case 'explain':
665
+ tasks.push({
666
+ id: 'explore-structure',
667
+ description: 'Explore project structure',
668
+ category: 'search',
669
+ tools: ['Glob', 'Bash'],
670
+ dependencies: [],
671
+ status: 'pending',
672
+ });
673
+ tasks.push({
674
+ id: 'read-key-files',
675
+ description: 'Read and understand key files',
676
+ category: 'analysis',
677
+ tools: ['Read'],
678
+ dependencies: ['explore-structure'],
679
+ status: 'pending',
680
+ });
681
+ tasks.push({
682
+ id: 'summarize-findings',
683
+ description: 'Summarize and explain findings',
684
+ category: 'communication',
685
+ tools: [],
686
+ dependencies: ['read-key-files'],
687
+ status: 'pending',
688
+ });
689
+ break;
690
+ case 'test':
691
+ if (knowledge.testCommand) {
692
+ tasks.push({
693
+ id: 'run-existing-tests',
694
+ description: 'Run existing test suite',
695
+ category: 'execution',
696
+ tools: ['Bash'],
697
+ dependencies: [],
698
+ status: 'pending',
699
+ });
700
+ }
701
+ tasks.push({
702
+ id: 'analyze-coverage',
703
+ description: 'Analyze test coverage',
704
+ category: 'analysis',
705
+ tools: ['Bash', 'Read'],
706
+ dependencies: [],
707
+ status: 'pending',
708
+ });
709
+ tasks.push({
710
+ id: 'identify-gaps',
711
+ description: 'Identify testing gaps',
712
+ category: 'analysis',
713
+ tools: ['Grep', 'Read'],
714
+ dependencies: ['analyze-coverage'],
715
+ status: 'pending',
716
+ });
717
+ tasks.push({
718
+ id: 'write-tests',
719
+ description: 'Write new tests for uncovered code',
720
+ category: 'modification',
721
+ tools: ['Edit', 'Write'],
722
+ dependencies: ['identify-gaps'],
723
+ status: 'pending',
724
+ });
725
+ break;
726
+ case 'security_audit':
727
+ tasks.push({
728
+ id: 'dependency-audit',
729
+ description: 'Audit dependencies for known vulnerabilities',
730
+ category: 'execution',
731
+ tools: ['Bash'],
732
+ dependencies: [],
733
+ status: 'pending',
734
+ });
735
+ tasks.push({
736
+ id: 'code-patterns',
737
+ description: 'Search for insecure code patterns',
738
+ category: 'search',
739
+ tools: ['Grep'],
740
+ dependencies: [],
741
+ status: 'pending',
742
+ });
743
+ tasks.push({
744
+ id: 'analyze-security',
745
+ description: 'Analyze security findings',
746
+ category: 'analysis',
747
+ tools: ['Read'],
748
+ dependencies: ['dependency-audit', 'code-patterns'],
749
+ status: 'pending',
750
+ });
751
+ tasks.push({
752
+ id: 'report-findings',
753
+ description: 'Report security findings with recommendations',
754
+ category: 'communication',
755
+ tools: [],
756
+ dependencies: ['analyze-security'],
757
+ status: 'pending',
758
+ });
759
+ break;
760
+ // =====================================================================
761
+ // NON-SWE DOMAIN TASKS
762
+ // =====================================================================
763
+ case 'research':
764
+ // Scientific/Medical Research (e.g., "cure cancer")
765
+ tasks.push({
766
+ id: 'define-scope',
767
+ description: 'Define research scope and objectives',
768
+ category: 'analysis',
769
+ tools: ['Read'],
770
+ dependencies: [],
771
+ status: 'pending',
772
+ });
773
+ tasks.push({
774
+ id: 'gather-data',
775
+ description: 'Gather relevant data and research materials',
776
+ category: 'research',
777
+ tools: ['Bash', 'Read'],
778
+ dependencies: ['define-scope'],
779
+ status: 'pending',
780
+ });
781
+ tasks.push({
782
+ id: 'build-pipeline',
783
+ description: 'Build data processing and analysis pipeline',
784
+ category: 'generation',
785
+ tools: ['Edit', 'Write', 'Bash'],
786
+ dependencies: ['gather-data'],
787
+ status: 'pending',
788
+ });
789
+ tasks.push({
790
+ id: 'implement-analysis',
791
+ description: 'Implement analysis algorithms and models',
792
+ category: 'generation',
793
+ tools: ['Edit', 'Write'],
794
+ dependencies: ['build-pipeline'],
795
+ status: 'pending',
796
+ });
797
+ tasks.push({
798
+ id: 'generate-report',
799
+ description: 'Generate analysis report with findings',
800
+ category: 'communication',
801
+ tools: ['Edit', 'Write'],
802
+ dependencies: ['implement-analysis'],
803
+ status: 'pending',
804
+ });
805
+ break;
806
+ case 'data_analysis':
807
+ tasks.push({
808
+ id: 'explore-data',
809
+ description: 'Explore and understand the data',
810
+ category: 'analysis',
811
+ tools: ['Read', 'Bash'],
812
+ dependencies: [],
813
+ status: 'pending',
814
+ });
815
+ tasks.push({
816
+ id: 'clean-data',
817
+ description: 'Clean and preprocess data',
818
+ category: 'execution',
819
+ tools: ['Bash', 'Edit'],
820
+ dependencies: ['explore-data'],
821
+ status: 'pending',
822
+ });
823
+ tasks.push({
824
+ id: 'analyze-patterns',
825
+ description: 'Analyze patterns and statistics',
826
+ category: 'computation',
827
+ tools: ['Bash', 'Edit'],
828
+ dependencies: ['clean-data'],
829
+ status: 'pending',
830
+ });
831
+ tasks.push({
832
+ id: 'create-visualizations',
833
+ description: 'Create visualizations and charts',
834
+ category: 'generation',
835
+ tools: ['Edit', 'Bash'],
836
+ dependencies: ['analyze-patterns'],
837
+ status: 'pending',
838
+ });
839
+ tasks.push({
840
+ id: 'summarize-insights',
841
+ description: 'Summarize insights and recommendations',
842
+ category: 'communication',
843
+ tools: ['Edit'],
844
+ dependencies: ['create-visualizations'],
845
+ status: 'pending',
846
+ });
847
+ break;
848
+ case 'scientific_computing':
849
+ tasks.push({
850
+ id: 'define-problem',
851
+ description: 'Define the scientific problem and requirements',
852
+ category: 'analysis',
853
+ tools: ['Read'],
854
+ dependencies: [],
855
+ status: 'pending',
856
+ });
857
+ tasks.push({
858
+ id: 'design-algorithm',
859
+ description: 'Design computational algorithm',
860
+ category: 'analysis',
861
+ tools: ['Read', 'Edit'],
862
+ dependencies: ['define-problem'],
863
+ status: 'pending',
864
+ });
865
+ tasks.push({
866
+ id: 'implement-computation',
867
+ description: 'Implement computational solution',
868
+ category: 'generation',
869
+ tools: ['Edit', 'Write'],
870
+ dependencies: ['design-algorithm'],
871
+ status: 'pending',
872
+ });
873
+ tasks.push({
874
+ id: 'validate-results',
875
+ description: 'Validate and verify results',
876
+ category: 'verification',
877
+ tools: ['Bash', 'Read'],
878
+ dependencies: ['implement-computation'],
879
+ status: 'pending',
880
+ });
881
+ break;
882
+ case 'legal_research':
883
+ // Legal/Litigation (e.g., "sue google in fed court")
884
+ tasks.push({
885
+ id: 'identify-claims',
886
+ description: 'Identify legal claims and causes of action',
887
+ category: 'research',
888
+ tools: ['Read'],
889
+ dependencies: [],
890
+ status: 'pending',
891
+ });
892
+ tasks.push({
893
+ id: 'research-law',
894
+ description: 'Research applicable laws and precedents',
895
+ category: 'research',
896
+ tools: ['Read', 'Bash'],
897
+ dependencies: ['identify-claims'],
898
+ status: 'pending',
899
+ });
900
+ tasks.push({
901
+ id: 'gather-evidence',
902
+ description: 'Gather and organize evidence',
903
+ category: 'search',
904
+ tools: ['Glob', 'Grep', 'Read'],
905
+ dependencies: [],
906
+ status: 'pending',
907
+ });
908
+ tasks.push({
909
+ id: 'draft-documents',
910
+ description: 'Draft legal documents (complaint, motion, brief)',
911
+ category: 'generation',
912
+ tools: ['Edit', 'Write'],
913
+ dependencies: ['research-law', 'gather-evidence'],
914
+ status: 'pending',
915
+ });
916
+ tasks.push({
917
+ id: 'prepare-filing',
918
+ description: 'Prepare filing package and procedures',
919
+ category: 'generation',
920
+ tools: ['Edit', 'Write'],
921
+ dependencies: ['draft-documents'],
922
+ status: 'pending',
923
+ });
924
+ break;
925
+ case 'business_analysis':
926
+ tasks.push({
927
+ id: 'gather-business-data',
928
+ description: 'Gather business data and market information',
929
+ category: 'research',
930
+ tools: ['Read', 'Bash'],
931
+ dependencies: [],
932
+ status: 'pending',
933
+ });
934
+ tasks.push({
935
+ id: 'analyze-market',
936
+ description: 'Analyze market and competitive landscape',
937
+ category: 'analysis',
938
+ tools: ['Read', 'Edit'],
939
+ dependencies: ['gather-business-data'],
940
+ status: 'pending',
941
+ });
942
+ tasks.push({
943
+ id: 'build-models',
944
+ description: 'Build financial/business models',
945
+ category: 'computation',
946
+ tools: ['Edit', 'Write'],
947
+ dependencies: ['analyze-market'],
948
+ status: 'pending',
949
+ });
950
+ tasks.push({
951
+ id: 'generate-strategy',
952
+ description: 'Generate strategy recommendations',
953
+ category: 'communication',
954
+ tools: ['Edit'],
955
+ dependencies: ['build-models'],
956
+ status: 'pending',
957
+ });
958
+ break;
959
+ case 'financial_analysis':
960
+ // Accounting/Finance (e.g., "do accounting")
961
+ tasks.push({
962
+ id: 'gather-financial-data',
963
+ description: 'Gather financial data and records',
964
+ category: 'search',
965
+ tools: ['Glob', 'Read'],
966
+ dependencies: [],
967
+ status: 'pending',
968
+ });
969
+ tasks.push({
970
+ id: 'organize-transactions',
971
+ description: 'Organize and categorize transactions',
972
+ category: 'analysis',
973
+ tools: ['Read', 'Edit'],
974
+ dependencies: ['gather-financial-data'],
975
+ status: 'pending',
976
+ });
977
+ tasks.push({
978
+ id: 'calculate-financials',
979
+ description: 'Calculate financial metrics and statements',
980
+ category: 'computation',
981
+ tools: ['Edit', 'Bash'],
982
+ dependencies: ['organize-transactions'],
983
+ status: 'pending',
984
+ });
985
+ tasks.push({
986
+ id: 'generate-reports',
987
+ description: 'Generate financial reports',
988
+ category: 'generation',
989
+ tools: ['Edit', 'Write'],
990
+ dependencies: ['calculate-financials'],
991
+ status: 'pending',
992
+ });
993
+ tasks.push({
994
+ id: 'prepare-tax',
995
+ description: 'Prepare tax calculations and filings',
996
+ category: 'generation',
997
+ tools: ['Edit', 'Write'],
998
+ dependencies: ['calculate-financials'],
999
+ status: 'pending',
1000
+ });
1001
+ break;
1002
+ case 'automate':
1003
+ tasks.push({
1004
+ id: 'analyze-workflow',
1005
+ description: 'Analyze current workflow and processes',
1006
+ category: 'analysis',
1007
+ tools: ['Read', 'Glob'],
1008
+ dependencies: [],
1009
+ status: 'pending',
1010
+ });
1011
+ tasks.push({
1012
+ id: 'design-automation',
1013
+ description: 'Design automation solution',
1014
+ category: 'analysis',
1015
+ tools: ['Read'],
1016
+ dependencies: ['analyze-workflow'],
1017
+ status: 'pending',
1018
+ });
1019
+ tasks.push({
1020
+ id: 'implement-automation',
1021
+ description: 'Implement automation scripts',
1022
+ category: 'generation',
1023
+ tools: ['Edit', 'Write', 'Bash'],
1024
+ dependencies: ['design-automation'],
1025
+ status: 'pending',
1026
+ });
1027
+ tasks.push({
1028
+ id: 'test-automation',
1029
+ description: 'Test automation workflow',
1030
+ category: 'verification',
1031
+ tools: ['Bash'],
1032
+ dependencies: ['implement-automation'],
1033
+ status: 'pending',
1034
+ });
1035
+ break;
1036
+ case 'monitor':
1037
+ tasks.push({
1038
+ id: 'identify-metrics',
1039
+ description: 'Identify key metrics to monitor',
1040
+ category: 'analysis',
1041
+ tools: ['Read'],
1042
+ dependencies: [],
1043
+ status: 'pending',
1044
+ });
1045
+ tasks.push({
1046
+ id: 'setup-collection',
1047
+ description: 'Set up metric collection',
1048
+ category: 'execution',
1049
+ tools: ['Edit', 'Bash'],
1050
+ dependencies: ['identify-metrics'],
1051
+ status: 'pending',
1052
+ });
1053
+ tasks.push({
1054
+ id: 'create-dashboard',
1055
+ description: 'Create monitoring dashboard',
1056
+ category: 'generation',
1057
+ tools: ['Edit', 'Write'],
1058
+ dependencies: ['setup-collection'],
1059
+ status: 'pending',
1060
+ });
1061
+ tasks.push({
1062
+ id: 'configure-alerts',
1063
+ description: 'Configure alerting rules',
1064
+ category: 'generation',
1065
+ tools: ['Edit', 'Write'],
1066
+ dependencies: ['create-dashboard'],
1067
+ status: 'pending',
1068
+ });
1069
+ break;
1070
+ default:
1071
+ // Generic task decomposition
1072
+ tasks.push({
1073
+ id: 'understand-request',
1074
+ description: 'Understand the request and context',
1075
+ category: 'analysis',
1076
+ tools: ['Glob', 'Read'],
1077
+ dependencies: [],
1078
+ status: 'pending',
1079
+ });
1080
+ tasks.push({
1081
+ id: 'execute-task',
1082
+ description: 'Execute the requested task',
1083
+ category: 'execution',
1084
+ tools: ['Bash', 'Edit'],
1085
+ dependencies: ['understand-request'],
1086
+ status: 'pending',
1087
+ });
1088
+ tasks.push({
1089
+ id: 'verify-completion',
1090
+ description: 'Verify task completion',
1091
+ category: 'verification',
1092
+ tools: ['Bash', 'Read'],
1093
+ dependencies: ['execute-task'],
1094
+ status: 'pending',
1095
+ });
1096
+ break;
1097
+ }
1098
+ return tasks;
1099
+ }
1100
+ checkAmbiguity(prompt, intent) {
1101
+ const questions = [];
1102
+ const lower = prompt.toLowerCase();
1103
+ const words = lower.split(/\s+/);
1104
+ // ==========================================================================
1105
+ // SCOPE AMBIGUITY
1106
+ // ==========================================================================
1107
+ // Vague scope keywords
1108
+ if (/\b(all|everything|entire|whole|every)\b/i.test(lower)) {
1109
+ questions.push('The request has broad scope. Should I focus on specific areas first?');
1110
+ }
1111
+ // Missing target for action-oriented intents
1112
+ if (['fix_bugs', 'refactor', 'optimize', 'test'].includes(intent)) {
1113
+ if (!/\b(specific|file|function|module|class|component|in\s+\w+\.\w+)\b/i.test(lower)) {
1114
+ questions.push('Are there specific files or modules to focus on?');
1115
+ }
1116
+ }
1117
+ // ==========================================================================
1118
+ // VAGUE LANGUAGE DETECTION
1119
+ // ==========================================================================
1120
+ // Vague improvement requests without criteria
1121
+ if (/\b(better|improve|enhance|upgrade|optimize)\b/i.test(lower)) {
1122
+ if (!/\b(faster|smaller|cleaner|readable|maintainable|secure|performance|memory|speed)\b/i.test(lower)) {
1123
+ questions.push('What specific improvement criteria? (e.g., performance, readability, security)');
1124
+ }
1125
+ }
1126
+ // Vague "make it work" requests
1127
+ if (/\bmake\s+(it|this|that)\s+(work|run|function)\b/i.test(lower)) {
1128
+ questions.push('What specific behavior is currently broken or not working as expected?');
1129
+ }
1130
+ // ==========================================================================
1131
+ // PRONOUN/REFERENCE AMBIGUITY
1132
+ // ==========================================================================
1133
+ // Ambiguous pronouns without clear antecedent (only if prompt is short)
1134
+ if (words.length < 15) {
1135
+ // Short prompts with pronouns are more likely to be ambiguous
1136
+ if (/^(fix|update|change|modify|remove|delete|add)\s+(it|this|that|them)\b/i.test(lower)) {
1137
+ questions.push('What specifically does "' + (lower.match(/\b(it|this|that|them)\b/i)?.[0] || 'it') + '" refer to?');
1138
+ }
1139
+ }
1140
+ // ==========================================================================
1141
+ // MULTI-INTENT DETECTION
1142
+ // ==========================================================================
1143
+ // Multiple action verbs suggesting compound requests
1144
+ const actionVerbs = lower.match(/\b(fix|add|create|update|remove|change|implement|refactor|test|deploy)\b/gi) || [];
1145
+ if (actionVerbs.length >= 3) {
1146
+ questions.push('This request has multiple actions. Should I handle them sequentially or prioritize one?');
1147
+ }
1148
+ // "And also" / "as well as" / "plus" - compound requests
1149
+ if (/\b(and also|as well as|plus|in addition|additionally|also\s+\w+)\b/i.test(lower)) {
1150
+ if (actionVerbs.length >= 2) {
1151
+ questions.push('Should I complete all parts of this request together, or one at a time?');
1152
+ }
1153
+ }
1154
+ // ==========================================================================
1155
+ // DESTRUCTIVE OPERATION WARNINGS
1156
+ // ==========================================================================
1157
+ // Potentially destructive operations need explicit confirmation
1158
+ if (/\b(delete|remove|drop|clear|wipe|reset|destroy|purge)\b/i.test(lower)) {
1159
+ if (!/\b(only|just|specific|single|one)\b/i.test(lower)) {
1160
+ questions.push('This involves deletion. Please confirm the exact scope to prevent data loss.');
1161
+ }
1162
+ }
1163
+ // ==========================================================================
1164
+ // MISSING CONTEXT DETECTION
1165
+ // ==========================================================================
1166
+ // New feature without location
1167
+ if (intent === 'add_feature' && !/\b(in|to|for|at)\s+\w+/i.test(lower)) {
1168
+ questions.push('Where should this new feature be added? (which file/component/module)');
1169
+ }
1170
+ // Unclear priority
1171
+ if (/\b(important|priority|critical|urgent)\b/i.test(lower) && !/\b(high|low|medium|first|last)\b/i.test(lower)) {
1172
+ questions.push('What priority level should I focus on?');
1173
+ }
1174
+ // ==========================================================================
1175
+ // CONFLICTING INSTRUCTIONS
1176
+ // ==========================================================================
1177
+ // Contradictory terms
1178
+ if (/\b(simple|minimal)\b/i.test(lower) && /\b(comprehensive|complete|full|thorough)\b/i.test(lower)) {
1179
+ questions.push('The request mentions both simplicity and comprehensiveness - which should I prioritize?');
1180
+ }
1181
+ // Quick vs thorough
1182
+ if (/\b(quick|fast|rapid)\b/i.test(lower) && /\b(thorough|careful|comprehensive)\b/i.test(lower)) {
1183
+ questions.push('Should I prioritize speed or thoroughness?');
1184
+ }
1185
+ // ==========================================================================
1186
+ // IMPLICIT ASSUMPTIONS
1187
+ // ==========================================================================
1188
+ // "Like X" or "similar to Y" without X/Y being in codebase
1189
+ if (/\b(like|similar to|same as|based on)\s+(\w+)/i.test(lower)) {
1190
+ const match = lower.match(/\b(like|similar to|same as|based on)\s+(\w+)/i);
1191
+ if (match) {
1192
+ const reference = match[2];
1193
+ // Only flag if reference seems like it could be ambiguous
1194
+ if (!/\b(react|vue|angular|node|express|django|flask|rails)\b/i.test(reference)) {
1195
+ questions.push(`What exactly should I use as the reference for "${reference}"?`);
1196
+ }
1197
+ }
1198
+ }
1199
+ // Limit to most relevant questions (max 2)
1200
+ return questions.slice(0, 2);
1201
+ }
1202
+ createFromLearnedPattern(prompt, pattern) {
1203
+ const identifiedScope = this.extractScope(prompt);
1204
+ return {
1205
+ originalPrompt: prompt,
1206
+ interpretation: `Using learned approach: ${pattern.successfulApproach}`,
1207
+ intent: 'generic_task',
1208
+ category: 'automation',
1209
+ confidence: 0.95,
1210
+ tasks: pattern.tools.map((tool, i) => ({
1211
+ id: `learned-${i}`,
1212
+ description: `Execute ${tool} based on learned pattern`,
1213
+ category: 'execution',
1214
+ tools: [tool],
1215
+ dependencies: i > 0 ? [`learned-${i - 1}`] : [],
1216
+ status: 'pending',
1217
+ })),
1218
+ clarificationNeeded: [],
1219
+ intentRestatement: `Using previously learned pattern: "${pattern.successfulApproach}" to handle this similar request.`,
1220
+ identifiedScope,
1221
+ interpretationRisks: [],
1222
+ };
1223
+ }
1224
+ // ==========================================================================
1225
+ // EXECUTION - Run Tasks with Real Tools
1226
+ // ==========================================================================
1227
+ /**
1228
+ * Generate tool calls for a given analysis
1229
+ * Returns explicit tool call specifications ready for execution
1230
+ */
1231
+ generateToolCalls(analysis) {
1232
+ const calls = [];
1233
+ const knowledge = this.context.memory.projectKnowledge;
1234
+ for (const task of analysis.tasks) {
1235
+ switch (task.category) {
1236
+ case 'execution':
1237
+ if (task.tools.includes('Bash')) {
1238
+ // Generate appropriate commands based on task
1239
+ if (task.id.includes('lint') || task.id.includes('errors')) {
1240
+ if (knowledge.lintCommand) {
1241
+ calls.push({
1242
+ tool: 'Bash',
1243
+ args: { command: knowledge.lintCommand + ' 2>&1 || true', description: task.description },
1244
+ description: task.description,
1245
+ taskId: task.id,
1246
+ });
1247
+ }
1248
+ if (knowledge.type === 'node') {
1249
+ calls.push({
1250
+ tool: 'Bash',
1251
+ args: { command: 'npx tsc --noEmit 2>&1 || true', description: 'Type check' },
1252
+ description: 'Run TypeScript type checker',
1253
+ taskId: task.id,
1254
+ });
1255
+ }
1256
+ }
1257
+ if (task.id.includes('test')) {
1258
+ if (knowledge.testCommand) {
1259
+ calls.push({
1260
+ tool: 'Bash',
1261
+ args: { command: knowledge.testCommand + ' 2>&1 || true', description: task.description },
1262
+ description: task.description,
1263
+ taskId: task.id,
1264
+ });
1265
+ }
1266
+ }
1267
+ if (task.id.includes('dependency') || task.id.includes('audit')) {
1268
+ if (knowledge.type === 'node') {
1269
+ calls.push({
1270
+ tool: 'Bash',
1271
+ args: { command: 'npm audit 2>&1 || true', description: 'Security audit' },
1272
+ description: 'Audit npm dependencies for vulnerabilities',
1273
+ taskId: task.id,
1274
+ });
1275
+ }
1276
+ }
1277
+ }
1278
+ break;
1279
+ case 'search':
1280
+ if (task.tools.includes('Grep')) {
1281
+ if (task.id.includes('issues') || task.id.includes('todo')) {
1282
+ calls.push({
1283
+ tool: 'Grep',
1284
+ args: { pattern: 'TODO|FIXME|BUG|HACK|XXX', output_mode: 'content' },
1285
+ description: 'Find TODO/FIXME comments',
1286
+ taskId: task.id,
1287
+ });
1288
+ }
1289
+ if (task.id.includes('security') || task.id.includes('patterns')) {
1290
+ calls.push({
1291
+ tool: 'Grep',
1292
+ args: { pattern: 'eval\\(|exec\\(|innerHTML|dangerouslySetInnerHTML', output_mode: 'content' },
1293
+ description: 'Find potentially unsafe patterns',
1294
+ taskId: task.id,
1295
+ });
1296
+ }
1297
+ }
1298
+ if (task.tools.includes('Glob')) {
1299
+ calls.push({
1300
+ tool: 'Glob',
1301
+ args: { pattern: 'src/**/*.{ts,js,tsx,jsx}' },
1302
+ description: 'Find source files',
1303
+ taskId: task.id,
1304
+ });
1305
+ }
1306
+ break;
1307
+ case 'analysis':
1308
+ // Analysis typically involves reading files
1309
+ if (task.tools.includes('Read')) {
1310
+ calls.push({
1311
+ tool: 'Read',
1312
+ args: { file_path: 'package.json' },
1313
+ description: 'Read project configuration',
1314
+ taskId: task.id,
1315
+ });
1316
+ }
1317
+ break;
1318
+ }
1319
+ }
1320
+ return calls;
1321
+ }
1322
+ // ==========================================================================
1323
+ // PUBLIC API
1324
+ // ==========================================================================
1325
+ /**
1326
+ * Get the current AGI context
1327
+ */
1328
+ getContext() {
1329
+ return this.context;
1330
+ }
1331
+ /**
1332
+ * Get project knowledge
1333
+ */
1334
+ getProjectKnowledge() {
1335
+ return this.context.memory.projectKnowledge;
1336
+ }
1337
+ /**
1338
+ * Get recent operations
1339
+ */
1340
+ getRecentOperations(limit = 10) {
1341
+ return this.context.memory.recentOps.slice(0, limit);
1342
+ }
1343
+ /**
1344
+ * Get learned patterns
1345
+ */
1346
+ getLearnedPatterns() {
1347
+ return this.context.memory.patterns;
1348
+ }
1349
+ /**
1350
+ * Force project re-analysis
1351
+ */
1352
+ refreshProjectKnowledge() {
1353
+ this.analyzeProject();
1354
+ return this.context.memory.projectKnowledge;
1355
+ }
1356
+ // ==========================================================================
1357
+ // EPISODIC MEMORY - Cross-session learning with semantic search
1358
+ // ==========================================================================
1359
+ /**
1360
+ * Start tracking a new episode (task/conversation unit)
1361
+ */
1362
+ startEpisode(intent) {
1363
+ this.currentEpisodeId = this.episodicMemory.startEpisode(intent, this.context.sessionId);
1364
+ this.emit('episode:start', { id: this.currentEpisodeId, intent });
1365
+ return this.currentEpisodeId;
1366
+ }
1367
+ /**
1368
+ * Record tool usage within the current episode
1369
+ */
1370
+ recordEpisodeToolUse(toolName) {
1371
+ if (this.currentEpisodeId) {
1372
+ this.episodicMemory.recordToolUse(toolName);
1373
+ }
1374
+ }
1375
+ /**
1376
+ * Record file modification within the current episode
1377
+ */
1378
+ recordEpisodeFileModification(filePath) {
1379
+ if (this.currentEpisodeId) {
1380
+ this.episodicMemory.recordFileModification(filePath);
1381
+ }
1382
+ }
1383
+ /**
1384
+ * End the current episode and save to memory
1385
+ */
1386
+ async endEpisode(success, summary) {
1387
+ if (!this.currentEpisodeId)
1388
+ return null;
1389
+ const episode = await this.episodicMemory.endEpisode(success, summary);
1390
+ this.emit('episode:end', { episode, success });
1391
+ this.currentEpisodeId = null;
1392
+ return episode;
1393
+ }
1394
+ /**
1395
+ * Abort the current episode without saving
1396
+ */
1397
+ abortEpisode() {
1398
+ if (this.currentEpisodeId) {
1399
+ this.episodicMemory.abortEpisode();
1400
+ this.emit('episode:abort', { id: this.currentEpisodeId });
1401
+ this.currentEpisodeId = null;
1402
+ }
1403
+ }
1404
+ /**
1405
+ * Search episodic memory for similar past work
1406
+ */
1407
+ async searchMemory(query, options) {
1408
+ return this.episodicMemory.search({
1409
+ query,
1410
+ limit: options?.limit ?? 5,
1411
+ successOnly: options?.successOnly,
1412
+ since: options?.since,
1413
+ });
1414
+ }
1415
+ /**
1416
+ * Get learned approach from episodic memory
1417
+ */
1418
+ async getEpisodicApproach(intent) {
1419
+ const learned = await this.episodicMemory.getApproach(intent);
1420
+ if (!learned)
1421
+ return null;
1422
+ return {
1423
+ approach: learned.approach,
1424
+ tools: learned.tools,
1425
+ successRate: learned.successRate,
1426
+ };
1427
+ }
1428
+ /**
1429
+ * Get recent episodes for context
1430
+ */
1431
+ getRecentEpisodes(limit = 5) {
1432
+ return this.episodicMemory.getRecentEpisodes(limit, this.context.sessionId);
1433
+ }
1434
+ /**
1435
+ * Get episodic memory statistics
1436
+ */
1437
+ getEpisodicMemoryStats() {
1438
+ return this.episodicMemory.getStats();
1439
+ }
1440
+ /**
1441
+ * Get the episodic memory instance for direct access
1442
+ */
1443
+ getEpisodicMemory() {
1444
+ return this.episodicMemory;
1445
+ }
1446
+ /**
1447
+ * Check if there's an active episode
1448
+ */
1449
+ hasActiveEpisode() {
1450
+ return this.currentEpisodeId !== null;
1451
+ }
1452
+ /**
1453
+ * Get current episode ID
1454
+ */
1455
+ getCurrentEpisodeId() {
1456
+ return this.currentEpisodeId;
1457
+ }
1458
+ // ==========================================================================
1459
+ // SELF-UPGRADE SYSTEM - Automatic updates and hot-reload
1460
+ // ==========================================================================
1461
+ /**
1462
+ * Check for available updates
1463
+ */
1464
+ async checkForUpdates() {
1465
+ const info = await this.selfUpgrade.checkForUpdates();
1466
+ return {
1467
+ available: info.updateAvailable,
1468
+ current: info.current,
1469
+ latest: info.latest,
1470
+ };
1471
+ }
1472
+ /**
1473
+ * Perform self-upgrade to latest version
1474
+ * Saves session state and restarts CLI automatically
1475
+ */
1476
+ async performSelfUpgrade(options = {}) {
1477
+ // Save current session state if requested
1478
+ if (options.preserveSession !== false) {
1479
+ const sessionState = {
1480
+ workingDir: this.context.workingDir,
1481
+ fromVersion: (await this.selfUpgrade.checkForUpdates()).current,
1482
+ timestamp: Date.now(),
1483
+ pendingTasks: this.context.memory.recentOps.slice(0, 5).map(op => op.prompt),
1484
+ contextSummary: `Session ${this.context.sessionId}, ${this.context.memory.recentOps.length} recent operations`,
1485
+ rlContext: this.currentEpisodeId ? {
1486
+ iteration: 1,
1487
+ variant: 'primary',
1488
+ objective: 'Continue from episode ' + this.currentEpisodeId,
1489
+ currentScore: 0,
1490
+ filesModified: [],
1491
+ } : undefined,
1492
+ };
1493
+ this.selfUpgrade.saveSessionState(sessionState);
1494
+ }
1495
+ // Perform upgrade
1496
+ const result = await this.selfUpgrade.npmInstallFresh(options.version);
1497
+ return {
1498
+ success: result.success,
1499
+ fromVersion: result.fromVersion,
1500
+ toVersion: result.toVersion,
1501
+ error: result.error,
1502
+ };
1503
+ }
1504
+ /**
1505
+ * Perform self-upgrade with build and test verification
1506
+ */
1507
+ async performVerifiedUpgrade(options = {}) {
1508
+ const result = await this.selfUpgrade.upgradeWithFullVerification(options.version, options.buildCommand || this.context.memory.projectKnowledge.buildSystem || 'npm run build', options.testCommand || this.context.memory.projectKnowledge.testCommand || 'npm test');
1509
+ return {
1510
+ success: result.success,
1511
+ buildSuccess: result.buildSuccess,
1512
+ testsPassed: result.testState.passed,
1513
+ testsFailed: result.testState.failed,
1514
+ fromVersion: result.fromVersion,
1515
+ toVersion: result.toVersion,
1516
+ };
1517
+ }
1518
+ /**
1519
+ * Trigger hot-reload if update is available
1520
+ */
1521
+ async triggerHotReload(options = {}) {
1522
+ // Include RL context if applicable
1523
+ const rlContext = this.currentEpisodeId ? {
1524
+ iteration: 1,
1525
+ variant: 'primary',
1526
+ objective: 'Hot-reload continuation',
1527
+ currentScore: 0,
1528
+ filesModified: options.activeEdits || [],
1529
+ } : undefined;
1530
+ return this.hotReload.performHotReload({
1531
+ preserveState: options.preserveState,
1532
+ rlContext,
1533
+ activeEdits: options.activeEdits,
1534
+ });
1535
+ }
1536
+ /**
1537
+ * Resume from previous upgrade session
1538
+ */
1539
+ resumeFromUpgrade() {
1540
+ const state = this.selfUpgrade.loadSessionState();
1541
+ if (state) {
1542
+ this.selfUpgrade.clearSessionState();
1543
+ this.emit('upgrade:resumed', state);
1544
+ }
1545
+ return state;
1546
+ }
1547
+ /**
1548
+ * Get the self-upgrade instance for direct access
1549
+ */
1550
+ getSelfUpgrade() {
1551
+ return this.selfUpgrade;
1552
+ }
1553
+ /**
1554
+ * Get the hot-reload instance for direct access
1555
+ */
1556
+ getHotReload() {
1557
+ return this.hotReload;
1558
+ }
1559
+ /**
1560
+ * Check if this session was started after an upgrade
1561
+ */
1562
+ wasUpgraded() {
1563
+ return SelfUpgrade.wasUpgraded();
1564
+ }
1565
+ /**
1566
+ * Get version we upgraded from (if applicable)
1567
+ */
1568
+ getUpgradeFromVersion() {
1569
+ return SelfUpgrade.getUpgradeFromVersion();
1570
+ }
1571
+ }
1572
+ // ============================================================================
1573
+ // SINGLETON EXPORT
1574
+ // ============================================================================
1575
+ let agiInstance = null;
1576
+ export function getAGI(workingDir) {
1577
+ if (!agiInstance || (workingDir && workingDir !== agiInstance.getContext().workingDir)) {
1578
+ agiInstance = new AGICore(workingDir);
1579
+ }
1580
+ return agiInstance;
1581
+ }
1582
+ export function resetAGI() {
1583
+ agiInstance = null;
1584
+ }
1585
+ //# sourceMappingURL=agiCore.js.map