@codemieai/code 0.0.33 → 0.0.35

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 (294) hide show
  1. package/README.md +78 -7
  2. package/bin/codemie-claude-acp.js +21 -0
  3. package/bin/codemie-opencode.js +11 -0
  4. package/bin/codemie.js +13 -0
  5. package/dist/agents/codemie-code/agent.d.ts +38 -4
  6. package/dist/agents/codemie-code/agent.d.ts.map +1 -1
  7. package/dist/agents/codemie-code/agent.js +333 -178
  8. package/dist/agents/codemie-code/agent.js.map +1 -1
  9. package/dist/agents/codemie-code/index.d.ts +2 -1
  10. package/dist/agents/codemie-code/index.d.ts.map +1 -1
  11. package/dist/agents/codemie-code/index.js +36 -7
  12. package/dist/agents/codemie-code/index.js.map +1 -1
  13. package/dist/agents/codemie-code/prompts.d.ts +12 -5
  14. package/dist/agents/codemie-code/prompts.d.ts.map +1 -1
  15. package/dist/agents/codemie-code/prompts.js +53 -6
  16. package/dist/agents/codemie-code/prompts.js.map +1 -1
  17. package/dist/agents/codemie-code/toolMetadata.d.ts.map +1 -1
  18. package/dist/agents/codemie-code/toolMetadata.js +9 -8
  19. package/dist/agents/codemie-code/toolMetadata.js.map +1 -1
  20. package/dist/agents/codemie-code/tools/assistant-invocation.d.ts +47 -0
  21. package/dist/agents/codemie-code/tools/assistant-invocation.d.ts.map +1 -0
  22. package/dist/agents/codemie-code/tools/assistant-invocation.js +129 -0
  23. package/dist/agents/codemie-code/tools/assistant-invocation.js.map +1 -0
  24. package/dist/agents/codemie-code/tools/index.d.ts +70 -4
  25. package/dist/agents/codemie-code/tools/index.d.ts.map +1 -1
  26. package/dist/agents/codemie-code/tools/index.js +57 -44
  27. package/dist/agents/codemie-code/tools/index.js.map +1 -1
  28. package/dist/agents/codemie-code/tools/planning.d.ts +6 -5
  29. package/dist/agents/codemie-code/tools/planning.d.ts.map +1 -1
  30. package/dist/agents/codemie-code/tools/planning.js +12 -10
  31. package/dist/agents/codemie-code/tools/planning.js.map +1 -1
  32. package/dist/agents/codemie-code/types.d.ts +27 -3
  33. package/dist/agents/codemie-code/types.d.ts.map +1 -1
  34. package/dist/agents/codemie-code/types.js +24 -0
  35. package/dist/agents/codemie-code/types.js.map +1 -1
  36. package/dist/agents/codemie-code/ui/autocomplete.d.ts +98 -0
  37. package/dist/agents/codemie-code/ui/autocomplete.d.ts.map +1 -0
  38. package/dist/agents/codemie-code/ui/autocomplete.js +145 -0
  39. package/dist/agents/codemie-code/ui/autocomplete.js.map +1 -0
  40. package/dist/agents/codemie-code/ui/keyHandlers.d.ts +112 -0
  41. package/dist/agents/codemie-code/ui/keyHandlers.d.ts.map +1 -0
  42. package/dist/agents/codemie-code/ui/keyHandlers.js +415 -0
  43. package/dist/agents/codemie-code/ui/keyHandlers.js.map +1 -0
  44. package/dist/agents/codemie-code/ui/mentions.d.ts +86 -0
  45. package/dist/agents/codemie-code/ui/mentions.d.ts.map +1 -0
  46. package/dist/agents/codemie-code/ui/mentions.js +122 -0
  47. package/dist/agents/codemie-code/ui/mentions.js.map +1 -0
  48. package/dist/agents/codemie-code/ui/terminalCodes.d.ts +38 -0
  49. package/dist/agents/codemie-code/ui/terminalCodes.d.ts.map +1 -0
  50. package/dist/agents/codemie-code/ui/terminalCodes.js +42 -0
  51. package/dist/agents/codemie-code/ui/terminalCodes.js.map +1 -0
  52. package/dist/agents/codemie-code/ui/todoPanel.d.ts.map +1 -1
  53. package/dist/agents/codemie-code/ui/todoPanel.js +3 -4
  54. package/dist/agents/codemie-code/ui/todoPanel.js.map +1 -1
  55. package/dist/agents/codemie-code/ui.d.ts +8 -7
  56. package/dist/agents/codemie-code/ui.d.ts.map +1 -1
  57. package/dist/agents/codemie-code/ui.js +87 -145
  58. package/dist/agents/codemie-code/ui.js.map +1 -1
  59. package/dist/agents/core/AgentCLI.d.ts +5 -0
  60. package/dist/agents/core/AgentCLI.d.ts.map +1 -1
  61. package/dist/agents/core/AgentCLI.js +25 -1
  62. package/dist/agents/core/AgentCLI.js.map +1 -1
  63. package/dist/agents/core/BaseAgentAdapter.d.ts.map +1 -1
  64. package/dist/agents/core/BaseAgentAdapter.js +90 -27
  65. package/dist/agents/core/BaseAgentAdapter.js.map +1 -1
  66. package/dist/agents/core/extension/BaseExtensionInstaller.d.ts +7 -1
  67. package/dist/agents/core/extension/BaseExtensionInstaller.d.ts.map +1 -1
  68. package/dist/agents/core/extension/BaseExtensionInstaller.js +58 -15
  69. package/dist/agents/core/extension/BaseExtensionInstaller.js.map +1 -1
  70. package/dist/agents/core/session/BaseSessionAdapter.d.ts +25 -0
  71. package/dist/agents/core/session/BaseSessionAdapter.d.ts.map +1 -1
  72. package/dist/agents/core/session/discovery-types.d.ts +53 -0
  73. package/dist/agents/core/session/discovery-types.d.ts.map +1 -0
  74. package/dist/agents/core/session/discovery-types.js +8 -0
  75. package/dist/agents/core/session/discovery-types.js.map +1 -0
  76. package/dist/agents/core/types.d.ts +62 -0
  77. package/dist/agents/core/types.d.ts.map +1 -1
  78. package/dist/agents/plugins/claude/claude-acp.plugin.d.ts +27 -0
  79. package/dist/agents/plugins/claude/claude-acp.plugin.d.ts.map +1 -0
  80. package/dist/agents/plugins/claude/claude-acp.plugin.js +63 -0
  81. package/dist/agents/plugins/claude/claude-acp.plugin.js.map +1 -0
  82. package/dist/agents/plugins/claude/claude-message-types.d.ts +1 -0
  83. package/dist/agents/plugins/claude/claude-message-types.d.ts.map +1 -1
  84. package/dist/agents/plugins/claude/claude.plugin.d.ts +44 -1
  85. package/dist/agents/plugins/claude/claude.plugin.d.ts.map +1 -1
  86. package/dist/agents/plugins/claude/claude.plugin.js +263 -12
  87. package/dist/agents/plugins/claude/claude.plugin.js.map +1 -1
  88. package/dist/agents/plugins/claude/claude.session.d.ts.map +1 -1
  89. package/dist/agents/plugins/claude/claude.session.js +14 -7
  90. package/dist/agents/plugins/claude/claude.session.js.map +1 -1
  91. package/dist/agents/plugins/claude/plugin/.claude-plugin/plugin.json +1 -1
  92. package/dist/agents/plugins/claude/plugin/README.md +40 -2
  93. package/dist/agents/plugins/claude/plugin/claude-templates/README.md +5 -5
  94. package/dist/agents/plugins/claude/plugin/claude-templates/templates/CLAUDE.md.template +177 -436
  95. package/dist/agents/plugins/claude/plugin/claude-templates/templates/agents/code-review-agent-template.md.template +49 -82
  96. package/dist/agents/plugins/claude/plugin/claude-templates/templates/agents/refactor-cleaner-agent.md.template +337 -0
  97. package/dist/agents/plugins/claude/plugin/claude-templates/templates/agents/solution-architect-agent.md.template +129 -419
  98. package/dist/agents/plugins/claude/plugin/claude-templates/templates/agents/unit-tester-agent.md.template +146 -693
  99. package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/api/api-patterns.md.template +110 -138
  100. package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/architecture/architecture.md.template +197 -0
  101. package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/data/database-patterns.md.template +171 -91
  102. package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/development/development-practices.md.template +219 -131
  103. package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/security/security-practices.md.template +223 -98
  104. package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/standards/code-quality.md.template +131 -95
  105. package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/testing/testing-patterns.md.template +247 -75
  106. package/dist/agents/plugins/claude/plugin/commands/README.md +133 -0
  107. package/dist/agents/plugins/claude/plugin/commands/codemie-init.md +336 -544
  108. package/dist/agents/plugins/claude/plugin/commands/codemie-subagents.md +233 -504
  109. package/dist/agents/plugins/claude/plugin/commands/memory-add.md +311 -30
  110. package/dist/agents/plugins/claude/plugin/commands/memory-refresh.md +218 -39
  111. package/dist/agents/plugins/claude/session/processors/claude.conversations-processor.d.ts.map +1 -1
  112. package/dist/agents/plugins/claude/session/processors/claude.conversations-processor.js +43 -8
  113. package/dist/agents/plugins/claude/session/processors/claude.conversations-processor.js.map +1 -1
  114. package/dist/agents/plugins/claude/session/processors/claude.metrics-processor.d.ts.map +1 -1
  115. package/dist/agents/plugins/claude/session/processors/claude.metrics-processor.js +68 -40
  116. package/dist/agents/plugins/claude/session/processors/claude.metrics-processor.js.map +1 -1
  117. package/dist/agents/plugins/gemini/gemini.plugin.d.ts.map +1 -1
  118. package/dist/agents/plugins/gemini/gemini.plugin.js +0 -3
  119. package/dist/agents/plugins/gemini/gemini.plugin.js.map +1 -1
  120. package/dist/agents/plugins/opencode/index.d.ts +8 -0
  121. package/dist/agents/plugins/opencode/index.d.ts.map +1 -0
  122. package/dist/agents/plugins/opencode/index.js +12 -0
  123. package/dist/agents/plugins/opencode/index.js.map +1 -0
  124. package/dist/agents/plugins/opencode/opencode-message-types.d.ts +207 -0
  125. package/dist/agents/plugins/opencode/opencode-message-types.d.ts.map +1 -0
  126. package/dist/agents/plugins/opencode/opencode-message-types.js +59 -0
  127. package/dist/agents/plugins/opencode/opencode-message-types.js.map +1 -0
  128. package/dist/agents/plugins/opencode/opencode-model-configs.d.ts +65 -0
  129. package/dist/agents/plugins/opencode/opencode-model-configs.d.ts.map +1 -0
  130. package/dist/agents/plugins/opencode/opencode-model-configs.js +184 -0
  131. package/dist/agents/plugins/opencode/opencode-model-configs.js.map +1 -0
  132. package/dist/agents/plugins/opencode/opencode.paths.d.ts +62 -0
  133. package/dist/agents/plugins/opencode/opencode.paths.d.ts.map +1 -0
  134. package/dist/agents/plugins/opencode/opencode.paths.js +148 -0
  135. package/dist/agents/plugins/opencode/opencode.paths.js.map +1 -0
  136. package/dist/agents/plugins/opencode/opencode.plugin.d.ts +35 -0
  137. package/dist/agents/plugins/opencode/opencode.plugin.d.ts.map +1 -0
  138. package/dist/agents/plugins/opencode/opencode.plugin.js +338 -0
  139. package/dist/agents/plugins/opencode/opencode.plugin.js.map +1 -0
  140. package/dist/agents/plugins/opencode/opencode.session.d.ts +77 -0
  141. package/dist/agents/plugins/opencode/opencode.session.d.ts.map +1 -0
  142. package/dist/agents/plugins/opencode/opencode.session.js +424 -0
  143. package/dist/agents/plugins/opencode/opencode.session.js.map +1 -0
  144. package/dist/agents/plugins/opencode/opencode.storage-utils.d.ts +25 -0
  145. package/dist/agents/plugins/opencode/opencode.storage-utils.d.ts.map +1 -0
  146. package/dist/agents/plugins/opencode/opencode.storage-utils.js +96 -0
  147. package/dist/agents/plugins/opencode/opencode.storage-utils.js.map +1 -0
  148. package/dist/agents/plugins/opencode/session/processors/opencode.conversations-processor.d.ts +30 -0
  149. package/dist/agents/plugins/opencode/session/processors/opencode.conversations-processor.d.ts.map +1 -0
  150. package/dist/agents/plugins/opencode/session/processors/opencode.conversations-processor.js +116 -0
  151. package/dist/agents/plugins/opencode/session/processors/opencode.conversations-processor.js.map +1 -0
  152. package/dist/agents/plugins/opencode/session/processors/opencode.metrics-processor.d.ts +102 -0
  153. package/dist/agents/plugins/opencode/session/processors/opencode.metrics-processor.d.ts.map +1 -0
  154. package/dist/agents/plugins/opencode/session/processors/opencode.metrics-processor.js +584 -0
  155. package/dist/agents/plugins/opencode/session/processors/opencode.metrics-processor.js.map +1 -0
  156. package/dist/agents/registry.d.ts +1 -1
  157. package/dist/agents/registry.d.ts.map +1 -1
  158. package/dist/agents/registry.js +5 -1
  159. package/dist/agents/registry.js.map +1 -1
  160. package/dist/cli/commands/assistants/chat.d.ts +11 -0
  161. package/dist/cli/commands/assistants/chat.d.ts.map +1 -0
  162. package/dist/cli/commands/assistants/chat.js +201 -0
  163. package/dist/cli/commands/assistants/chat.js.map +1 -0
  164. package/dist/cli/commands/assistants/constants.d.ts +81 -0
  165. package/dist/cli/commands/assistants/constants.d.ts.map +1 -0
  166. package/dist/cli/commands/assistants/constants.js +75 -0
  167. package/dist/cli/commands/assistants/constants.js.map +1 -0
  168. package/dist/cli/commands/assistants/generators/claude-agent-generator.d.ts +26 -0
  169. package/dist/cli/commands/assistants/generators/claude-agent-generator.d.ts.map +1 -0
  170. package/dist/cli/commands/assistants/generators/claude-agent-generator.js +115 -0
  171. package/dist/cli/commands/assistants/generators/claude-agent-generator.js.map +1 -0
  172. package/dist/cli/commands/assistants/index.d.ts +11 -0
  173. package/dist/cli/commands/assistants/index.d.ts.map +1 -0
  174. package/dist/cli/commands/assistants/index.js +28 -0
  175. package/dist/cli/commands/assistants/index.js.map +1 -0
  176. package/dist/cli/commands/assistants/list.d.ts +11 -0
  177. package/dist/cli/commands/assistants/list.d.ts.map +1 -0
  178. package/dist/cli/commands/assistants/list.js +323 -0
  179. package/dist/cli/commands/assistants/list.js.map +1 -0
  180. package/dist/cli/commands/doctor/checks/AgentsCheck.d.ts +5 -0
  181. package/dist/cli/commands/doctor/checks/AgentsCheck.d.ts.map +1 -1
  182. package/dist/cli/commands/doctor/checks/AgentsCheck.js +29 -0
  183. package/dist/cli/commands/doctor/checks/AgentsCheck.js.map +1 -1
  184. package/dist/cli/commands/install.d.ts.map +1 -1
  185. package/dist/cli/commands/install.js +104 -13
  186. package/dist/cli/commands/install.js.map +1 -1
  187. package/dist/cli/commands/opencode-metrics.d.ts +13 -0
  188. package/dist/cli/commands/opencode-metrics.d.ts.map +1 -0
  189. package/dist/cli/commands/opencode-metrics.js +200 -0
  190. package/dist/cli/commands/opencode-metrics.js.map +1 -0
  191. package/dist/cli/commands/self-update.d.ts +3 -0
  192. package/dist/cli/commands/self-update.d.ts.map +1 -0
  193. package/dist/cli/commands/self-update.js +55 -0
  194. package/dist/cli/commands/self-update.js.map +1 -0
  195. package/dist/cli/commands/setup.d.ts.map +1 -1
  196. package/dist/cli/commands/setup.js +113 -0
  197. package/dist/cli/commands/setup.js.map +1 -1
  198. package/dist/cli/commands/skill.d.ts +6 -0
  199. package/dist/cli/commands/skill.d.ts.map +1 -0
  200. package/dist/cli/commands/skill.js +196 -0
  201. package/dist/cli/commands/skill.js.map +1 -0
  202. package/dist/cli/commands/update.d.ts.map +1 -1
  203. package/dist/cli/commands/update.js +34 -6
  204. package/dist/cli/commands/update.js.map +1 -1
  205. package/dist/cli/index.d.ts.map +1 -1
  206. package/dist/cli/index.js +12 -4
  207. package/dist/cli/index.js.map +1 -1
  208. package/dist/env/types.d.ts +13 -0
  209. package/dist/env/types.d.ts.map +1 -1
  210. package/dist/env/types.js +1 -1
  211. package/dist/env/types.js.map +1 -1
  212. package/dist/migrations/003-remove-hooks-node.migration.d.ts +22 -0
  213. package/dist/migrations/003-remove-hooks-node.migration.d.ts.map +1 -0
  214. package/dist/migrations/003-remove-hooks-node.migration.js +103 -0
  215. package/dist/migrations/003-remove-hooks-node.migration.js.map +1 -0
  216. package/dist/migrations/index.d.ts +1 -0
  217. package/dist/migrations/index.d.ts.map +1 -1
  218. package/dist/migrations/index.js +1 -1
  219. package/dist/migrations/index.js.map +1 -1
  220. package/dist/providers/plugins/sso/sso.http-client.js +2 -2
  221. package/dist/providers/plugins/sso/sso.http-client.js.map +1 -1
  222. package/dist/providers/plugins/sso/sso.setup-steps.d.ts.map +1 -1
  223. package/dist/providers/plugins/sso/sso.setup-steps.js +14 -10
  224. package/dist/providers/plugins/sso/sso.setup-steps.js.map +1 -1
  225. package/dist/skills/core/SkillDiscovery.d.ts +83 -0
  226. package/dist/skills/core/SkillDiscovery.d.ts.map +1 -0
  227. package/dist/skills/core/SkillDiscovery.js +237 -0
  228. package/dist/skills/core/SkillDiscovery.js.map +1 -0
  229. package/dist/skills/core/SkillManager.d.ts +86 -0
  230. package/dist/skills/core/SkillManager.d.ts.map +1 -0
  231. package/dist/skills/core/SkillManager.js +155 -0
  232. package/dist/skills/core/SkillManager.js.map +1 -0
  233. package/dist/skills/core/types.d.ts +120 -0
  234. package/dist/skills/core/types.d.ts.map +1 -0
  235. package/dist/skills/core/types.js +20 -0
  236. package/dist/skills/core/types.js.map +1 -0
  237. package/dist/skills/index.d.ts +12 -0
  238. package/dist/skills/index.d.ts.map +1 -0
  239. package/dist/skills/index.js +12 -0
  240. package/dist/skills/index.js.map +1 -0
  241. package/dist/skills/utils/content-loader.d.ts +25 -0
  242. package/dist/skills/utils/content-loader.d.ts.map +1 -0
  243. package/dist/skills/utils/content-loader.js +161 -0
  244. package/dist/skills/utils/content-loader.js.map +1 -0
  245. package/dist/skills/utils/frontmatter.d.ts +60 -0
  246. package/dist/skills/utils/frontmatter.d.ts.map +1 -0
  247. package/dist/skills/utils/frontmatter.js +114 -0
  248. package/dist/skills/utils/frontmatter.js.map +1 -0
  249. package/dist/skills/utils/pattern-matcher.d.ts +60 -0
  250. package/dist/skills/utils/pattern-matcher.d.ts.map +1 -0
  251. package/dist/skills/utils/pattern-matcher.js +97 -0
  252. package/dist/skills/utils/pattern-matcher.js.map +1 -0
  253. package/dist/utils/auth.d.ts +22 -0
  254. package/dist/utils/auth.d.ts.map +1 -0
  255. package/dist/utils/auth.js +50 -0
  256. package/dist/utils/auth.js.map +1 -0
  257. package/dist/utils/cli-updater.d.ts +70 -0
  258. package/dist/utils/cli-updater.d.ts.map +1 -0
  259. package/dist/utils/cli-updater.js +339 -0
  260. package/dist/utils/cli-updater.js.map +1 -0
  261. package/dist/utils/config.d.ts +6 -1
  262. package/dist/utils/config.d.ts.map +1 -1
  263. package/dist/utils/config.js +13 -0
  264. package/dist/utils/config.js.map +1 -1
  265. package/dist/utils/installation-detector.d.ts +22 -0
  266. package/dist/utils/installation-detector.d.ts.map +1 -0
  267. package/dist/utils/installation-detector.js +49 -0
  268. package/dist/utils/installation-detector.js.map +1 -0
  269. package/dist/utils/native-installer.d.ts +49 -0
  270. package/dist/utils/native-installer.d.ts.map +1 -0
  271. package/dist/utils/native-installer.js +225 -0
  272. package/dist/utils/native-installer.js.map +1 -0
  273. package/dist/utils/processes.js +1 -1
  274. package/dist/utils/profile.d.ts +2 -0
  275. package/dist/utils/profile.d.ts.map +1 -1
  276. package/dist/utils/profile.js +5 -0
  277. package/dist/utils/profile.js.map +1 -1
  278. package/dist/utils/sdk-client.d.ts +15 -0
  279. package/dist/utils/sdk-client.d.ts.map +1 -0
  280. package/dist/utils/sdk-client.js +92 -0
  281. package/dist/utils/sdk-client.js.map +1 -0
  282. package/dist/utils/version-utils.d.ts +50 -0
  283. package/dist/utils/version-utils.d.ts.map +1 -0
  284. package/dist/utils/version-utils.js +92 -0
  285. package/dist/utils/version-utils.js.map +1 -0
  286. package/package.json +11 -3
  287. package/scripts/copy-mr-skill-to-global.ts +252 -0
  288. package/scripts/demo-hooks.sh +125 -0
  289. package/scripts/test-hooks.sh +196 -0
  290. package/dist/agents/plugins/claude/plugin/claude-templates/templates/INDEX.md +0 -205
  291. package/dist/agents/plugins/claude/plugin/claude-templates/templates/TEMPLATE_SIZES.md +0 -74
  292. package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/architecture/layered-architecture.md.template +0 -143
  293. package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/architecture/project-structure.md.template +0 -127
  294. package/dist/agents/plugins/claude/plugin/commands/codemie-pr.md +0 -25
@@ -3,21 +3,27 @@
3
3
  *
4
4
  * Core LangGraph ReAct agent using LangChain v1.0+ with streaming support
5
5
  */
6
+ import { randomUUID } from 'node:crypto';
6
7
  import { createReactAgent } from '@langchain/langgraph/prebuilt';
7
8
  import { ChatOpenAI } from '@langchain/openai';
8
- import { HumanMessage, SystemMessage } from '@langchain/core/messages';
9
+ import { HumanMessage, SystemMessage, AIMessage } from '@langchain/core/messages';
10
+ import { EVENT_TYPES, CodeMieAgentError } from './types.js';
9
11
  import { getSystemPrompt } from './prompts.js';
10
- import { CodeMieAgentError } from './types.js';
11
12
  import { extractToolMetadata } from './toolMetadata.js';
12
13
  import { extractTokenUsageFromStreamChunk, extractTokenUsageFromFinalState } from './tokenUtils.js';
13
14
  import { setGlobalToolEventCallback } from './tools/index.js';
14
15
  import { logger } from '../../utils/logger.js';
15
16
  import { sanitizeCookies, sanitizeAuthToken } from '../../utils/security.js';
16
17
  import { HookExecutor } from '../../hooks/executor.js';
18
+ import { extractSkillPatterns } from '../../skills/utils/pattern-matcher.js';
19
+ import { SkillManager } from '../../skills/core/SkillManager.js';
20
+ import { parseAtMentionCommand } from './ui/mentions.js';
21
+ import { loadRegisteredAssistants } from '../../utils/config.js';
17
22
  export class CodeMieAgent {
18
23
  agent;
19
24
  config;
20
25
  tools;
26
+ skills;
21
27
  conversationHistory = [];
22
28
  toolCallArgs = new Map(); // Store tool args by tool call ID
23
29
  currentExecutionSteps = [];
@@ -39,16 +45,19 @@ export class CodeMieAgent {
39
45
  llmCalls: 0,
40
46
  executionSteps: []
41
47
  };
42
- constructor(config, tools) {
48
+ constructor(config, tools, skills = []) {
43
49
  this.config = config;
44
50
  this.tools = tools;
51
+ this.skills = skills;
52
+ const sessionId = randomUUID();
53
+ logger.setSessionId(sessionId);
45
54
  // Create the appropriate LLM based on provider
46
55
  const llm = this.createLLM();
47
- // Create LangGraph ReAct agent with system prompt
56
+ // Create LangGraph ReAct agent with system prompt (including skills if loaded)
48
57
  this.agent = createReactAgent({
49
58
  llm,
50
59
  tools: this.tools,
51
- messageModifier: getSystemPrompt(config.workingDirectory)
60
+ messageModifier: getSystemPrompt(config.workingDirectory, this.skills)
52
61
  });
53
62
  // Initialize hook executor if hooks are configured
54
63
  if (config.hooks) {
@@ -77,6 +86,27 @@ export class CodeMieAgent {
77
86
  logger.debug(`CodeMie Agent initialized with ${tools.length} tools`);
78
87
  }
79
88
  }
89
+ /**
90
+ * Update tools after initialization (needed for tools that require conversation history)
91
+ */
92
+ async updateTools(tools) {
93
+ this.tools = tools;
94
+ // Load registered assistants for system prompt
95
+ const assistants = await loadRegisteredAssistants();
96
+ // Recreate agent with new tools and assistant-aware prompt
97
+ const llm = this.createLLM();
98
+ this.agent = createReactAgent({
99
+ llm,
100
+ tools: this.tools,
101
+ messageModifier: getSystemPrompt(this.config.workingDirectory, [], assistants)
102
+ });
103
+ if (this.config.debug) {
104
+ logger.debug(`CodeMie Agent tools updated: ${tools.length} tools`);
105
+ if (assistants.length > 0) {
106
+ logger.debug(`Loaded ${assistants.length} assistants for system prompt:`, assistants.map(a => a.slug));
107
+ }
108
+ }
109
+ }
80
110
  /**
81
111
  * Create the appropriate LLM instance based on provider configuration
82
112
  */
@@ -151,7 +181,7 @@ export class CodeMieAgent {
151
181
  model: this.config.model,
152
182
  apiKey: this.config.authToken,
153
183
  configuration: {
154
- baseURL: this.config.baseUrl !== 'bedrock' ? this.config.baseUrl : undefined,
184
+ baseURL: this.config.baseUrl === 'bedrock' ? undefined : this.config.baseUrl,
155
185
  // Add client tracking header to all Bedrock requests
156
186
  fetch: async (input, init) => {
157
187
  const updatedInit = {
@@ -179,7 +209,7 @@ export class CodeMieAgent {
179
209
  baseURL
180
210
  };
181
211
  // Check if we have SSO cookies to inject (following codemie-ide-plugin pattern)
182
- const ssoCookies = global.codemieSSOCookies;
212
+ const ssoCookies = globalThis.codemieSSOCookies;
183
213
  if (this.config.debug) {
184
214
  logger.debug(`SSO Cookies available:`, sanitizeCookies(ssoCookies));
185
215
  logger.debug(`Auth token:`, sanitizeAuthToken(this.config.authToken));
@@ -285,6 +315,70 @@ export class CodeMieAgent {
285
315
  content: content
286
316
  });
287
317
  }
318
+ /**
319
+ * Handle @ mention invocation result by updating history and emitting events
320
+ * @param message - Original user message
321
+ * @param images - Optional images from user
322
+ * @param atMentionResult - Result from preprocessAtMention
323
+ * @param onEvent - Event callback
324
+ */
325
+ handleAtMentionResult(message, images, atMentionResult, onEvent) {
326
+ const userMessage = this.createHumanMessage(message, images);
327
+ this.conversationHistory.push(userMessage);
328
+ const assistantMessage = new AIMessage({
329
+ content: atMentionResult.response || 'No response from assistant'
330
+ });
331
+ this.conversationHistory.push(assistantMessage);
332
+ onEvent({ type: EVENT_TYPES.THINKING_END });
333
+ onEvent({ type: EVENT_TYPES.CONTENT_CHUNK, content: atMentionResult.response });
334
+ onEvent({ type: EVENT_TYPES.COMPLETE });
335
+ }
336
+ /**
337
+ * Preprocess message to detect @ mentions and invoke assistants directly
338
+ * Returns { handled: true, response: string, assistantSlug: string } if @ mention was processed,
339
+ * or { handled: false } if no @ mention found
340
+ */
341
+ async preprocessAtMention(message, onEvent) {
342
+ // Use shared mention pattern from mentions module
343
+ const parsed = parseAtMentionCommand(message);
344
+ if (!parsed) {
345
+ return { handled: false };
346
+ }
347
+ const { assistantSlug, message: assistantMessage } = parsed;
348
+ try {
349
+ // Find the invoke_assistant tool
350
+ const invokeTool = this.tools.find(tool => tool.name === 'invoke_assistant');
351
+ if (!invokeTool) {
352
+ if (this.config.debug) {
353
+ logger.debug('@ mention detected but invoke_assistant tool not available');
354
+ }
355
+ return { handled: false };
356
+ }
357
+ if (this.config.debug) {
358
+ logger.debug(`Preprocessing @ mention: @${assistantSlug} "${assistantMessage.substring(0, 50)}..."`);
359
+ }
360
+ // Emit thinking_start with assistant info
361
+ onEvent({ type: EVENT_TYPES.THINKING_START });
362
+ // Invoke the assistant tool directly
363
+ const response = await invokeTool.invoke({
364
+ assistantSlug,
365
+ message: assistantMessage,
366
+ includeHistory: false // Default to no history for @ mentions (can be made configurable)
367
+ });
368
+ return { handled: true, response: String(response), assistantSlug };
369
+ }
370
+ catch (error) {
371
+ if (this.config.debug) {
372
+ logger.debug('@ mention preprocessing failed:', error);
373
+ }
374
+ // Return error as response but mark as handled
375
+ return {
376
+ handled: true,
377
+ response: `Failed to invoke assistant @${assistantSlug}: ${error instanceof Error ? error.message : String(error)}`,
378
+ assistantSlug
379
+ };
380
+ }
381
+ }
288
382
  /**
289
383
  * Stream a chat interaction with the agent
290
384
  */
@@ -304,7 +398,7 @@ export class CodeMieAgent {
304
398
  // Set up global tool event callback for progress reporting
305
399
  setGlobalToolEventCallback((event) => {
306
400
  onEvent({
307
- type: 'tool_call_progress',
401
+ type: EVENT_TYPES.TOOL_CALL_PROGRESS,
308
402
  toolName: event.toolName,
309
403
  toolProgress: event.progress
310
404
  });
@@ -319,193 +413,220 @@ export class CodeMieAgent {
319
413
  }
320
414
  streamAborted = true;
321
415
  abortController.abort();
322
- onEvent({ type: 'error', error: 'Stream interrupted by user (Ctrl+C)' });
416
+ onEvent({ type: EVENT_TYPES.ERROR, error: 'Stream interrupted by user (Ctrl+C)' });
323
417
  };
324
418
  process.once('SIGINT', sigintHandler);
325
- try {
326
- if (this.config.debug) {
327
- logger.debug(`Processing message: ${message.substring(0, 100)}...`);
328
- }
329
- // Execute SessionStart hooks (only on first message)
330
- if (this.hookExecutor && this.conversationHistory.length === 0) {
331
- try {
332
- const sessionStartResult = await this.hookExecutor.executeSessionStart();
333
- // Handle blocking decision
334
- if (sessionStartResult.decision === 'block') {
335
- const reason = sessionStartResult.reason || 'Session blocked by SessionStart hook';
336
- const context = sessionStartResult.additionalContext;
337
- // Check if we should retry (exit code 2 behavior)
338
- if (context && this.hookLoopCounter < (this.getMaxHookRetries())) {
339
- this.hookLoopCounter++;
340
- logger.warn(`SessionStart hook blocked (attempt ${this.hookLoopCounter}/${this.getMaxHookRetries()})`);
341
- // Build feedback message
342
- const hookFeedback = [reason, context].filter(Boolean).join('\n\n');
343
- // Clear hook cache for retry
344
- this.hookExecutor.clearCache();
345
- // Retry with feedback
346
- return this.chatStream(`[Hook feedback]: ${hookFeedback}`, onEvent, images);
419
+ if (this.config.debug) {
420
+ logger.debug(`Processing message: ${message.substring(0, 100)}...`);
421
+ }
422
+ // Execute SessionStart hooks (only on first message)
423
+ if (this.hookExecutor && this.conversationHistory.length === 0) {
424
+ try {
425
+ const sessionStartResult = await this.hookExecutor.executeSessionStart();
426
+ // Handle blocking decision
427
+ if (sessionStartResult.decision === 'block') {
428
+ const reason = sessionStartResult.reason || 'Session blocked by SessionStart hook';
429
+ const context = sessionStartResult.additionalContext;
430
+ // Check if we should retry (exit code 2 behavior)
431
+ if (context && this.hookLoopCounter < (this.getMaxHookRetries())) {
432
+ this.hookLoopCounter++;
433
+ logger.warn(`SessionStart hook blocked (attempt ${this.hookLoopCounter}/${this.getMaxHookRetries()})`);
434
+ // Build feedback message
435
+ const hookFeedback = [reason, context].filter(Boolean).join('\n\n');
436
+ // Clear hook cache for retry
437
+ this.hookExecutor.clearCache();
438
+ // Retry with feedback
439
+ return this.chatStream(`[Hook feedback]: ${hookFeedback}`, onEvent, images);
440
+ }
441
+ else {
442
+ // Max retries reached or no feedback - block session
443
+ if (this.hookLoopCounter >= this.getMaxHookRetries()) {
444
+ logger.error(`SessionStart hook blocked after ${this.hookLoopCounter} attempts - aborting session`);
445
+ onEvent({
446
+ type: 'error',
447
+ error: `Session blocked after ${this.hookLoopCounter} attempts: ${reason}`
448
+ });
347
449
  }
348
450
  else {
349
- // Max retries reached or no feedback - block session
350
- if (this.hookLoopCounter >= this.getMaxHookRetries()) {
351
- logger.error(`SessionStart hook blocked after ${this.hookLoopCounter} attempts - aborting session`);
352
- onEvent({
353
- type: 'error',
354
- error: `Session blocked after ${this.hookLoopCounter} attempts: ${reason}`
355
- });
356
- }
357
- else {
358
- logger.warn('SessionStart hook blocked session start');
359
- onEvent({
360
- type: 'error',
361
- error: reason
362
- });
363
- }
364
- return; // Exit without starting session
365
- }
366
- }
367
- // Inject hook output as system context
368
- if (sessionStartResult.additionalContext) {
369
- if (this.config.debug) {
370
- logger.debug('SessionStart hook provided context, injecting into conversation');
451
+ logger.warn('SessionStart hook blocked session start');
452
+ onEvent({
453
+ type: 'error',
454
+ error: reason
455
+ });
371
456
  }
372
- // Add SessionStart output as system message before user message
373
- const systemMessage = new SystemMessage(`[SessionStart Hook Output]:\n${sessionStartResult.additionalContext}`);
374
- this.conversationHistory.push(systemMessage);
457
+ return; // Exit without starting session
375
458
  }
376
459
  }
377
- catch (error) {
378
- logger.error(`SessionStart hook failed: ${error}`);
379
- // Continue session start (fail open)
380
- }
381
- }
382
- // Execute UserPromptSubmit hooks
383
- if (this.hookExecutor && message.trim()) {
384
- try {
385
- const hookResult = await this.hookExecutor.executeUserPromptSubmit(message);
386
- // Handle blocking decision
387
- if (hookResult.decision === 'block') {
388
- logger.warn('UserPromptSubmit hook blocked prompt');
389
- onEvent({
390
- type: 'error',
391
- error: hookResult.reason || 'Prompt blocked by hook'
392
- });
393
- return; // Exit without processing
394
- }
395
- // Add context to conversation
396
- if (hookResult.additionalContext) {
397
- if (this.config.debug) {
398
- logger.debug('UserPromptSubmit hook provided context');
399
- }
400
- // Prepend context to the message
401
- message = `${hookResult.additionalContext}\n\n${message}`;
460
+ // Inject hook output as system context
461
+ if (sessionStartResult.additionalContext) {
462
+ if (this.config.debug) {
463
+ logger.debug('SessionStart hook provided context, injecting into conversation');
402
464
  }
403
- }
404
- catch (error) {
405
- logger.error(`UserPromptSubmit hook failed: ${error}`);
406
- // Continue execution
465
+ // Add SessionStart output as system message before user message
466
+ const systemMessage = new SystemMessage(`[SessionStart Hook Output]:\n${sessionStartResult.additionalContext}`);
467
+ this.conversationHistory.push(systemMessage);
407
468
  }
408
469
  }
409
- // Add user message to conversation history (with optional images)
410
- const userMessage = this.createHumanMessage(message, images);
411
- this.conversationHistory.push(userMessage);
412
- // Notify start of thinking
413
- onEvent({ type: 'thinking_start' });
414
- // Start the first LLM call step
415
- currentStep = this.startLLMStep();
416
- // Create the stream with conversation history
417
- const stream = await this.agent.stream({ messages: this.conversationHistory }, {
418
- streamMode: 'updates',
419
- recursionLimit: 50,
420
- signal: abortController.signal // Add abort signal for stream cancellation
421
- });
422
- let hasContent = false;
423
- // Process stream chunks with interruption handling
424
- for await (const chunk of stream) {
425
- // Check if stream was aborted
426
- if (streamAborted || abortController.signal.aborted) {
470
+ catch (error) {
471
+ logger.error(`SessionStart hook failed: ${error}`);
472
+ // Continue session start (fail open)
473
+ }
474
+ }
475
+ // Execute UserPromptSubmit hooks
476
+ if (this.hookExecutor && message.trim()) {
477
+ try {
478
+ const hookResult = await this.hookExecutor.executeUserPromptSubmit(message);
479
+ // Handle blocking decision
480
+ if (hookResult.decision === 'block') {
481
+ logger.warn('UserPromptSubmit hook blocked prompt');
482
+ onEvent({
483
+ type: 'error',
484
+ error: hookResult.reason || 'Prompt blocked by hook'
485
+ });
486
+ return; // Exit without processing
487
+ }
488
+ // Add context to conversation
489
+ if (hookResult.additionalContext) {
427
490
  if (this.config.debug) {
428
- logger.debug('Stream processing aborted');
491
+ logger.debug('UserPromptSubmit hook provided context');
429
492
  }
430
- break;
493
+ // Prepend context to the message
494
+ message = `${hookResult.additionalContext}\n\n${message}`;
431
495
  }
432
- // Try to extract token usage from stream chunk
433
- const tokenUsage = extractTokenUsageFromStreamChunk(chunk, this.config.model, this.config.provider);
434
- if (tokenUsage && currentStep && currentStep.type === 'llm_call') {
435
- // Update current step with token usage
436
- currentStep.tokenUsage = tokenUsage;
437
- this.updateStatsWithTokenUsage(tokenUsage);
438
- // Store token usage to associate with next tool call
439
- this.currentLLMTokenUsage = tokenUsage;
496
+ }
497
+ catch (error) {
498
+ logger.error(`UserPromptSubmit hook failed: ${error}`);
499
+ // Continue execution
500
+ }
501
+ }
502
+ // Detect skill patterns in message
503
+ const patternResult = extractSkillPatterns(message);
504
+ if (patternResult.hasPatterns) {
505
+ try {
506
+ // Load skills with inventory
507
+ const skillsWithInventory = await this.loadDetectedSkills(patternResult.patterns);
508
+ if (skillsWithInventory.length > 0) {
509
+ // Format and inject as system message
510
+ const skillContent = this.formatSkillsForInjection(skillsWithInventory);
511
+ const skillSystemMessage = new SystemMessage(`[Skill Invocation Detected]\n\n${skillContent}`);
512
+ this.conversationHistory.push(skillSystemMessage);
440
513
  if (this.config.debug) {
441
- logger.debug(`Token usage: ${tokenUsage.inputTokens} in, ${tokenUsage.outputTokens} out`);
514
+ logger.debug(`Injected ${skillsWithInventory.length} skills: ${skillsWithInventory.map((s) => s.skill.metadata.name).join(', ')}`);
442
515
  }
443
516
  }
444
- await this.processStreamChunk(chunk, onEvent, (toolStarted) => {
445
- if (toolStarted) {
446
- // Complete current LLM step if it exists
447
- if (currentStep && currentStep.type === 'llm_call') {
448
- this.completeStep(currentStep);
449
- currentStep = null;
450
- }
451
- // Start tool execution step
452
- currentStep = this.startToolStep(toolStarted);
453
- currentToolCall = toolStarted;
454
- this.stats.toolCalls++;
455
- }
456
- else if (currentToolCall && currentStep) {
457
- // Complete tool step
458
- currentStep.toolSuccess = true;
517
+ }
518
+ catch (error) {
519
+ // Non-blocking: Log error but continue
520
+ logger.warn('Failed to load skills for pattern injection:', error);
521
+ }
522
+ }
523
+ // Preprocess @ mentions before normal agent processing
524
+ const atMentionResult = await this.preprocessAtMention(message, onEvent);
525
+ if (atMentionResult.handled) {
526
+ this.handleAtMentionResult(message, images, atMentionResult, onEvent);
527
+ return;
528
+ }
529
+ // Add user message to conversation history (with optional images)
530
+ const userMessage = this.createHumanMessage(message, images);
531
+ this.conversationHistory.push(userMessage);
532
+ // Notify start of thinking
533
+ onEvent({ type: EVENT_TYPES.THINKING_START });
534
+ // Start the first LLM call step
535
+ currentStep = this.startLLMStep();
536
+ // Create the stream with conversation history
537
+ const stream = await this.agent.stream({ messages: this.conversationHistory }, {
538
+ streamMode: 'updates',
539
+ recursionLimit: 50,
540
+ signal: abortController.signal // Add abort signal for stream cancellation
541
+ });
542
+ let hasContent = false;
543
+ // Process stream chunks with interruption handling
544
+ for await (const chunk of stream) {
545
+ // Check if stream was aborted
546
+ if (streamAborted || abortController.signal.aborted) {
547
+ if (this.config.debug) {
548
+ logger.debug('Stream processing aborted');
549
+ }
550
+ break;
551
+ }
552
+ // Try to extract token usage from stream chunk
553
+ const tokenUsage = extractTokenUsageFromStreamChunk(chunk, this.config.model, this.config.provider);
554
+ if (tokenUsage && currentStep?.type === 'llm_call') {
555
+ // Update current step with token usage
556
+ currentStep.tokenUsage = tokenUsage;
557
+ this.updateStatsWithTokenUsage(tokenUsage);
558
+ // Store token usage to associate with next tool call
559
+ this.currentLLMTokenUsage = tokenUsage;
560
+ if (this.config.debug) {
561
+ logger.debug(`Token usage: ${tokenUsage.inputTokens} in, ${tokenUsage.outputTokens} out`);
562
+ }
563
+ }
564
+ await this.processStreamChunk(chunk, onEvent, (toolStarted) => {
565
+ if (toolStarted) {
566
+ // Complete current LLM step if it exists
567
+ if (currentStep?.type === 'llm_call') {
459
568
  this.completeStep(currentStep);
460
569
  currentStep = null;
461
- this.stats.successfulTools++;
462
- currentToolCall = null;
463
- // Start new LLM step for next reasoning cycle (processing tool result)
464
- currentStep = this.startLLMStep();
465
- }
466
- });
467
- // Check if we have content
468
- if (chunk.agent?.messages) {
469
- const lastMessage = chunk.agent.messages.at(-1);
470
- if (lastMessage?.content && !hasContent) {
471
- hasContent = true;
472
570
  }
571
+ // Start tool execution step
572
+ currentStep = this.startToolStep(toolStarted);
573
+ currentToolCall = toolStarted;
574
+ this.stats.toolCalls++;
575
+ }
576
+ else if (currentToolCall && currentStep) {
577
+ // Complete tool step
578
+ currentStep.toolSuccess = true;
579
+ this.completeStep(currentStep);
580
+ currentStep = null;
581
+ this.stats.successfulTools++;
582
+ currentToolCall = null;
583
+ // Start new LLM step for next reasoning cycle (processing tool result)
584
+ currentStep = this.startLLMStep();
585
+ }
586
+ });
587
+ // Check if we have content
588
+ if (chunk.agent?.messages) {
589
+ const lastMessage = chunk.agent.messages.at(-1);
590
+ if (lastMessage?.content && !hasContent) {
591
+ hasContent = true;
473
592
  }
474
593
  }
475
- // Complete any remaining step
476
- if (currentStep) {
477
- this.completeStep(currentStep);
478
- }
479
- // Update conversation history with final messages and try to extract any missed token usage
480
- try {
481
- const finalState = await this.agent.getState();
482
- if (finalState?.messages) {
483
- this.conversationHistory = finalState.messages;
484
- // Try to extract token usage from final state if we missed it during streaming
485
- const finalTokenUsage = extractTokenUsageFromFinalState(finalState, this.config.model, this.config.provider);
486
- if (finalTokenUsage && this.currentExecutionSteps.length > 0) {
487
- // Find the last LLM step that doesn't have token usage
488
- for (let i = this.currentExecutionSteps.length - 1; i >= 0; i--) {
489
- const step = this.currentExecutionSteps[i];
490
- if (step.type === 'llm_call' && !step.tokenUsage) {
491
- step.tokenUsage = finalTokenUsage;
492
- this.updateStatsWithTokenUsage(finalTokenUsage);
493
- break;
494
- }
594
+ }
595
+ // Complete any remaining step
596
+ if (currentStep) {
597
+ this.completeStep(currentStep);
598
+ }
599
+ // Update conversation history with final messages and try to extract any missed token usage
600
+ try {
601
+ const finalState = await this.agent.getState();
602
+ if (finalState?.messages) {
603
+ this.conversationHistory = finalState.messages;
604
+ // Try to extract token usage from final state if we missed it during streaming
605
+ const finalTokenUsage = extractTokenUsageFromFinalState(finalState, this.config.model, this.config.provider);
606
+ if (finalTokenUsage && this.currentExecutionSteps.length > 0) {
607
+ // Find the last LLM step that doesn't have token usage
608
+ for (let i = this.currentExecutionSteps.length - 1; i >= 0; i--) {
609
+ const step = this.currentExecutionSteps[i];
610
+ if (step.type === 'llm_call' && !step.tokenUsage) {
611
+ step.tokenUsage = finalTokenUsage;
612
+ this.updateStatsWithTokenUsage(finalTokenUsage);
613
+ break;
495
614
  }
496
615
  }
497
616
  }
498
617
  }
499
- catch {
500
- // If getState fails, continue without updating history
501
- if (this.config.debug) {
502
- logger.debug('Could not get final state, continuing...');
503
- }
618
+ }
619
+ catch {
620
+ // If getState fails, continue without updating history
621
+ if (this.config.debug) {
622
+ logger.debug('Could not get final state, continuing...');
504
623
  }
505
- // Finalize execution statistics
506
- this.stats.executionTime = Date.now() - startTime;
507
- this.stats.executionSteps = [...this.currentExecutionSteps];
508
- // Execute Stop hooks
624
+ }
625
+ // Finalize execution statistics
626
+ this.stats.executionTime = Date.now() - startTime;
627
+ this.stats.executionSteps = [...this.currentExecutionSteps];
628
+ // Execute Stop hooks
629
+ try {
509
630
  if (this.hookExecutor) {
510
631
  try {
511
632
  const stopHookResult = await this.hookExecutor.executeStop(this.currentExecutionSteps, {
@@ -568,8 +689,8 @@ export class CodeMieAgent {
568
689
  }
569
690
  }
570
691
  // Notify thinking end and completion
571
- onEvent({ type: 'thinking_end' });
572
- onEvent({ type: 'complete' });
692
+ onEvent({ type: EVENT_TYPES.THINKING_END });
693
+ onEvent({ type: EVENT_TYPES.COMPLETE });
573
694
  if (this.config.debug) {
574
695
  logger.debug(`Agent completed in ${this.stats.executionTime}ms`);
575
696
  logger.debug(`Total tokens: ${this.stats.totalTokens} (${this.stats.inputTokens} in, ${this.stats.outputTokens} out)`);
@@ -588,7 +709,7 @@ export class CodeMieAgent {
588
709
  logger.debug('Stream aborted by user');
589
710
  }
590
711
  onEvent({
591
- type: 'error',
712
+ type: EVENT_TYPES.ERROR,
592
713
  error: 'Operation interrupted by user'
593
714
  });
594
715
  return; // Don't throw error for user interruptions
@@ -601,7 +722,7 @@ export class CodeMieAgent {
601
722
  logger.debug(`Model: ${this.config.model}`);
602
723
  }
603
724
  onEvent({
604
- type: 'error',
725
+ type: EVENT_TYPES.ERROR,
605
726
  error: errorMessage
606
727
  });
607
728
  throw new CodeMieAgentError(`Agent execution failed: ${errorMessage}`, 'EXECUTION_ERROR', { originalError: error, stats: this.stats });
@@ -631,7 +752,7 @@ export class CodeMieAgent {
631
752
  // Stream content chunks
632
753
  if (lastMessage?.content && typeof lastMessage.content === 'string') {
633
754
  onEvent({
634
- type: 'content_chunk',
755
+ type: EVENT_TYPES.CONTENT_CHUNK,
635
756
  content: lastMessage.content
636
757
  });
637
758
  }
@@ -672,7 +793,7 @@ export class CodeMieAgent {
672
793
  // Use tool name as key since LangGraph may not preserve IDs consistently
673
794
  this.toolCallArgs.set(toolCall.name, toolCall.args);
674
795
  onEvent({
675
- type: 'tool_call_start',
796
+ type: EVENT_TYPES.TOOL_CALL_START,
676
797
  toolName: toolCall.name,
677
798
  toolArgs: toolCall.args
678
799
  });
@@ -733,7 +854,7 @@ export class CodeMieAgent {
733
854
  }
734
855
  }
735
856
  onEvent({
736
- type: 'tool_call_result',
857
+ type: EVENT_TYPES.TOOL_CALL_RESULT,
737
858
  toolName,
738
859
  result,
739
860
  toolMetadata
@@ -750,7 +871,7 @@ export class CodeMieAgent {
750
871
  }
751
872
  // Don't throw here, just log - let the main stream continue
752
873
  onEvent({
753
- type: 'error',
874
+ type: EVENT_TYPES.ERROR,
754
875
  error: `Stream processing error: ${error instanceof Error ? error.message : String(error)}`
755
876
  });
756
877
  }
@@ -878,7 +999,7 @@ export class CodeMieAgent {
878
999
  }
879
1000
  else {
880
1001
  // Check if the previous step was a tool execution
881
- const prevStep = this.currentExecutionSteps[this.currentExecutionSteps.length - 1];
1002
+ const prevStep = this.currentExecutionSteps.at(-1);
882
1003
  llmContext = (prevStep?.type === 'tool_execution') ? 'processing_tool_result' : 'final_response';
883
1004
  }
884
1005
  const step = {
@@ -942,5 +1063,39 @@ export class CodeMieAgent {
942
1063
  this.stats.estimatedTotalCost += tokenUsage.estimatedCost;
943
1064
  }
944
1065
  }
1066
+ /**
1067
+ * Load detected skills with file inventory
1068
+ *
1069
+ * @param patterns - Detected skill patterns
1070
+ * @returns Skills with inventory and formatted content
1071
+ */
1072
+ async loadDetectedSkills(patterns) {
1073
+ // Extract unique skill names (preserve order)
1074
+ const skillNames = Array.from(new Set(patterns.map((p) => p.name)));
1075
+ // Get skills from manager
1076
+ const manager = SkillManager.getInstance();
1077
+ const skillsWithInventory = await manager.getSkillsByNames(skillNames, {
1078
+ cwd: this.config.workingDirectory,
1079
+ agentName: 'codemie-code',
1080
+ });
1081
+ return skillsWithInventory;
1082
+ }
1083
+ /**
1084
+ * Format skills for prompt injection
1085
+ *
1086
+ * @param skills - Skills with inventory
1087
+ * @returns Formatted content for system message
1088
+ */
1089
+ formatSkillsForInjection(skills) {
1090
+ const parts = [
1091
+ 'The user has invoked the following skills. Follow their guidance for this request.',
1092
+ '',
1093
+ ];
1094
+ for (const { formattedContent } of skills) {
1095
+ parts.push('---', '', formattedContent, '');
1096
+ }
1097
+ parts.push('---', '', 'IMPORTANT: These skills provide specialized knowledge for this task. Prioritize their guidance over general instructions.');
1098
+ return parts.join('\n');
1099
+ }
945
1100
  }
946
1101
  //# sourceMappingURL=agent.js.map