@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.
- package/README.md +78 -7
- package/bin/codemie-claude-acp.js +21 -0
- package/bin/codemie-opencode.js +11 -0
- package/bin/codemie.js +13 -0
- package/dist/agents/codemie-code/agent.d.ts +38 -4
- package/dist/agents/codemie-code/agent.d.ts.map +1 -1
- package/dist/agents/codemie-code/agent.js +333 -178
- package/dist/agents/codemie-code/agent.js.map +1 -1
- package/dist/agents/codemie-code/index.d.ts +2 -1
- package/dist/agents/codemie-code/index.d.ts.map +1 -1
- package/dist/agents/codemie-code/index.js +36 -7
- package/dist/agents/codemie-code/index.js.map +1 -1
- package/dist/agents/codemie-code/prompts.d.ts +12 -5
- package/dist/agents/codemie-code/prompts.d.ts.map +1 -1
- package/dist/agents/codemie-code/prompts.js +53 -6
- package/dist/agents/codemie-code/prompts.js.map +1 -1
- package/dist/agents/codemie-code/toolMetadata.d.ts.map +1 -1
- package/dist/agents/codemie-code/toolMetadata.js +9 -8
- package/dist/agents/codemie-code/toolMetadata.js.map +1 -1
- package/dist/agents/codemie-code/tools/assistant-invocation.d.ts +47 -0
- package/dist/agents/codemie-code/tools/assistant-invocation.d.ts.map +1 -0
- package/dist/agents/codemie-code/tools/assistant-invocation.js +129 -0
- package/dist/agents/codemie-code/tools/assistant-invocation.js.map +1 -0
- package/dist/agents/codemie-code/tools/index.d.ts +70 -4
- package/dist/agents/codemie-code/tools/index.d.ts.map +1 -1
- package/dist/agents/codemie-code/tools/index.js +57 -44
- package/dist/agents/codemie-code/tools/index.js.map +1 -1
- package/dist/agents/codemie-code/tools/planning.d.ts +6 -5
- package/dist/agents/codemie-code/tools/planning.d.ts.map +1 -1
- package/dist/agents/codemie-code/tools/planning.js +12 -10
- package/dist/agents/codemie-code/tools/planning.js.map +1 -1
- package/dist/agents/codemie-code/types.d.ts +27 -3
- package/dist/agents/codemie-code/types.d.ts.map +1 -1
- package/dist/agents/codemie-code/types.js +24 -0
- package/dist/agents/codemie-code/types.js.map +1 -1
- package/dist/agents/codemie-code/ui/autocomplete.d.ts +98 -0
- package/dist/agents/codemie-code/ui/autocomplete.d.ts.map +1 -0
- package/dist/agents/codemie-code/ui/autocomplete.js +145 -0
- package/dist/agents/codemie-code/ui/autocomplete.js.map +1 -0
- package/dist/agents/codemie-code/ui/keyHandlers.d.ts +112 -0
- package/dist/agents/codemie-code/ui/keyHandlers.d.ts.map +1 -0
- package/dist/agents/codemie-code/ui/keyHandlers.js +415 -0
- package/dist/agents/codemie-code/ui/keyHandlers.js.map +1 -0
- package/dist/agents/codemie-code/ui/mentions.d.ts +86 -0
- package/dist/agents/codemie-code/ui/mentions.d.ts.map +1 -0
- package/dist/agents/codemie-code/ui/mentions.js +122 -0
- package/dist/agents/codemie-code/ui/mentions.js.map +1 -0
- package/dist/agents/codemie-code/ui/terminalCodes.d.ts +38 -0
- package/dist/agents/codemie-code/ui/terminalCodes.d.ts.map +1 -0
- package/dist/agents/codemie-code/ui/terminalCodes.js +42 -0
- package/dist/agents/codemie-code/ui/terminalCodes.js.map +1 -0
- package/dist/agents/codemie-code/ui/todoPanel.d.ts.map +1 -1
- package/dist/agents/codemie-code/ui/todoPanel.js +3 -4
- package/dist/agents/codemie-code/ui/todoPanel.js.map +1 -1
- package/dist/agents/codemie-code/ui.d.ts +8 -7
- package/dist/agents/codemie-code/ui.d.ts.map +1 -1
- package/dist/agents/codemie-code/ui.js +87 -145
- package/dist/agents/codemie-code/ui.js.map +1 -1
- package/dist/agents/core/AgentCLI.d.ts +5 -0
- package/dist/agents/core/AgentCLI.d.ts.map +1 -1
- package/dist/agents/core/AgentCLI.js +25 -1
- package/dist/agents/core/AgentCLI.js.map +1 -1
- package/dist/agents/core/BaseAgentAdapter.d.ts.map +1 -1
- package/dist/agents/core/BaseAgentAdapter.js +90 -27
- package/dist/agents/core/BaseAgentAdapter.js.map +1 -1
- package/dist/agents/core/extension/BaseExtensionInstaller.d.ts +7 -1
- package/dist/agents/core/extension/BaseExtensionInstaller.d.ts.map +1 -1
- package/dist/agents/core/extension/BaseExtensionInstaller.js +58 -15
- package/dist/agents/core/extension/BaseExtensionInstaller.js.map +1 -1
- package/dist/agents/core/session/BaseSessionAdapter.d.ts +25 -0
- package/dist/agents/core/session/BaseSessionAdapter.d.ts.map +1 -1
- package/dist/agents/core/session/discovery-types.d.ts +53 -0
- package/dist/agents/core/session/discovery-types.d.ts.map +1 -0
- package/dist/agents/core/session/discovery-types.js +8 -0
- package/dist/agents/core/session/discovery-types.js.map +1 -0
- package/dist/agents/core/types.d.ts +62 -0
- package/dist/agents/core/types.d.ts.map +1 -1
- package/dist/agents/plugins/claude/claude-acp.plugin.d.ts +27 -0
- package/dist/agents/plugins/claude/claude-acp.plugin.d.ts.map +1 -0
- package/dist/agents/plugins/claude/claude-acp.plugin.js +63 -0
- package/dist/agents/plugins/claude/claude-acp.plugin.js.map +1 -0
- package/dist/agents/plugins/claude/claude-message-types.d.ts +1 -0
- package/dist/agents/plugins/claude/claude-message-types.d.ts.map +1 -1
- package/dist/agents/plugins/claude/claude.plugin.d.ts +44 -1
- package/dist/agents/plugins/claude/claude.plugin.d.ts.map +1 -1
- package/dist/agents/plugins/claude/claude.plugin.js +263 -12
- package/dist/agents/plugins/claude/claude.plugin.js.map +1 -1
- package/dist/agents/plugins/claude/claude.session.d.ts.map +1 -1
- package/dist/agents/plugins/claude/claude.session.js +14 -7
- package/dist/agents/plugins/claude/claude.session.js.map +1 -1
- package/dist/agents/plugins/claude/plugin/.claude-plugin/plugin.json +1 -1
- package/dist/agents/plugins/claude/plugin/README.md +40 -2
- package/dist/agents/plugins/claude/plugin/claude-templates/README.md +5 -5
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/CLAUDE.md.template +177 -436
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/agents/code-review-agent-template.md.template +49 -82
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/agents/refactor-cleaner-agent.md.template +337 -0
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/agents/solution-architect-agent.md.template +129 -419
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/agents/unit-tester-agent.md.template +146 -693
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/api/api-patterns.md.template +110 -138
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/architecture/architecture.md.template +197 -0
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/data/database-patterns.md.template +171 -91
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/development/development-practices.md.template +219 -131
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/security/security-practices.md.template +223 -98
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/standards/code-quality.md.template +131 -95
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/testing/testing-patterns.md.template +247 -75
- package/dist/agents/plugins/claude/plugin/commands/README.md +133 -0
- package/dist/agents/plugins/claude/plugin/commands/codemie-init.md +336 -544
- package/dist/agents/plugins/claude/plugin/commands/codemie-subagents.md +233 -504
- package/dist/agents/plugins/claude/plugin/commands/memory-add.md +311 -30
- package/dist/agents/plugins/claude/plugin/commands/memory-refresh.md +218 -39
- package/dist/agents/plugins/claude/session/processors/claude.conversations-processor.d.ts.map +1 -1
- package/dist/agents/plugins/claude/session/processors/claude.conversations-processor.js +43 -8
- package/dist/agents/plugins/claude/session/processors/claude.conversations-processor.js.map +1 -1
- package/dist/agents/plugins/claude/session/processors/claude.metrics-processor.d.ts.map +1 -1
- package/dist/agents/plugins/claude/session/processors/claude.metrics-processor.js +68 -40
- package/dist/agents/plugins/claude/session/processors/claude.metrics-processor.js.map +1 -1
- package/dist/agents/plugins/gemini/gemini.plugin.d.ts.map +1 -1
- package/dist/agents/plugins/gemini/gemini.plugin.js +0 -3
- package/dist/agents/plugins/gemini/gemini.plugin.js.map +1 -1
- package/dist/agents/plugins/opencode/index.d.ts +8 -0
- package/dist/agents/plugins/opencode/index.d.ts.map +1 -0
- package/dist/agents/plugins/opencode/index.js +12 -0
- package/dist/agents/plugins/opencode/index.js.map +1 -0
- package/dist/agents/plugins/opencode/opencode-message-types.d.ts +207 -0
- package/dist/agents/plugins/opencode/opencode-message-types.d.ts.map +1 -0
- package/dist/agents/plugins/opencode/opencode-message-types.js +59 -0
- package/dist/agents/plugins/opencode/opencode-message-types.js.map +1 -0
- package/dist/agents/plugins/opencode/opencode-model-configs.d.ts +65 -0
- package/dist/agents/plugins/opencode/opencode-model-configs.d.ts.map +1 -0
- package/dist/agents/plugins/opencode/opencode-model-configs.js +184 -0
- package/dist/agents/plugins/opencode/opencode-model-configs.js.map +1 -0
- package/dist/agents/plugins/opencode/opencode.paths.d.ts +62 -0
- package/dist/agents/plugins/opencode/opencode.paths.d.ts.map +1 -0
- package/dist/agents/plugins/opencode/opencode.paths.js +148 -0
- package/dist/agents/plugins/opencode/opencode.paths.js.map +1 -0
- package/dist/agents/plugins/opencode/opencode.plugin.d.ts +35 -0
- package/dist/agents/plugins/opencode/opencode.plugin.d.ts.map +1 -0
- package/dist/agents/plugins/opencode/opencode.plugin.js +338 -0
- package/dist/agents/plugins/opencode/opencode.plugin.js.map +1 -0
- package/dist/agents/plugins/opencode/opencode.session.d.ts +77 -0
- package/dist/agents/plugins/opencode/opencode.session.d.ts.map +1 -0
- package/dist/agents/plugins/opencode/opencode.session.js +424 -0
- package/dist/agents/plugins/opencode/opencode.session.js.map +1 -0
- package/dist/agents/plugins/opencode/opencode.storage-utils.d.ts +25 -0
- package/dist/agents/plugins/opencode/opencode.storage-utils.d.ts.map +1 -0
- package/dist/agents/plugins/opencode/opencode.storage-utils.js +96 -0
- package/dist/agents/plugins/opencode/opencode.storage-utils.js.map +1 -0
- package/dist/agents/plugins/opencode/session/processors/opencode.conversations-processor.d.ts +30 -0
- package/dist/agents/plugins/opencode/session/processors/opencode.conversations-processor.d.ts.map +1 -0
- package/dist/agents/plugins/opencode/session/processors/opencode.conversations-processor.js +116 -0
- package/dist/agents/plugins/opencode/session/processors/opencode.conversations-processor.js.map +1 -0
- package/dist/agents/plugins/opencode/session/processors/opencode.metrics-processor.d.ts +102 -0
- package/dist/agents/plugins/opencode/session/processors/opencode.metrics-processor.d.ts.map +1 -0
- package/dist/agents/plugins/opencode/session/processors/opencode.metrics-processor.js +584 -0
- package/dist/agents/plugins/opencode/session/processors/opencode.metrics-processor.js.map +1 -0
- package/dist/agents/registry.d.ts +1 -1
- package/dist/agents/registry.d.ts.map +1 -1
- package/dist/agents/registry.js +5 -1
- package/dist/agents/registry.js.map +1 -1
- package/dist/cli/commands/assistants/chat.d.ts +11 -0
- package/dist/cli/commands/assistants/chat.d.ts.map +1 -0
- package/dist/cli/commands/assistants/chat.js +201 -0
- package/dist/cli/commands/assistants/chat.js.map +1 -0
- package/dist/cli/commands/assistants/constants.d.ts +81 -0
- package/dist/cli/commands/assistants/constants.d.ts.map +1 -0
- package/dist/cli/commands/assistants/constants.js +75 -0
- package/dist/cli/commands/assistants/constants.js.map +1 -0
- package/dist/cli/commands/assistants/generators/claude-agent-generator.d.ts +26 -0
- package/dist/cli/commands/assistants/generators/claude-agent-generator.d.ts.map +1 -0
- package/dist/cli/commands/assistants/generators/claude-agent-generator.js +115 -0
- package/dist/cli/commands/assistants/generators/claude-agent-generator.js.map +1 -0
- package/dist/cli/commands/assistants/index.d.ts +11 -0
- package/dist/cli/commands/assistants/index.d.ts.map +1 -0
- package/dist/cli/commands/assistants/index.js +28 -0
- package/dist/cli/commands/assistants/index.js.map +1 -0
- package/dist/cli/commands/assistants/list.d.ts +11 -0
- package/dist/cli/commands/assistants/list.d.ts.map +1 -0
- package/dist/cli/commands/assistants/list.js +323 -0
- package/dist/cli/commands/assistants/list.js.map +1 -0
- package/dist/cli/commands/doctor/checks/AgentsCheck.d.ts +5 -0
- package/dist/cli/commands/doctor/checks/AgentsCheck.d.ts.map +1 -1
- package/dist/cli/commands/doctor/checks/AgentsCheck.js +29 -0
- package/dist/cli/commands/doctor/checks/AgentsCheck.js.map +1 -1
- package/dist/cli/commands/install.d.ts.map +1 -1
- package/dist/cli/commands/install.js +104 -13
- package/dist/cli/commands/install.js.map +1 -1
- package/dist/cli/commands/opencode-metrics.d.ts +13 -0
- package/dist/cli/commands/opencode-metrics.d.ts.map +1 -0
- package/dist/cli/commands/opencode-metrics.js +200 -0
- package/dist/cli/commands/opencode-metrics.js.map +1 -0
- package/dist/cli/commands/self-update.d.ts +3 -0
- package/dist/cli/commands/self-update.d.ts.map +1 -0
- package/dist/cli/commands/self-update.js +55 -0
- package/dist/cli/commands/self-update.js.map +1 -0
- package/dist/cli/commands/setup.d.ts.map +1 -1
- package/dist/cli/commands/setup.js +113 -0
- package/dist/cli/commands/setup.js.map +1 -1
- package/dist/cli/commands/skill.d.ts +6 -0
- package/dist/cli/commands/skill.d.ts.map +1 -0
- package/dist/cli/commands/skill.js +196 -0
- package/dist/cli/commands/skill.js.map +1 -0
- package/dist/cli/commands/update.d.ts.map +1 -1
- package/dist/cli/commands/update.js +34 -6
- package/dist/cli/commands/update.js.map +1 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +12 -4
- package/dist/cli/index.js.map +1 -1
- package/dist/env/types.d.ts +13 -0
- package/dist/env/types.d.ts.map +1 -1
- package/dist/env/types.js +1 -1
- package/dist/env/types.js.map +1 -1
- package/dist/migrations/003-remove-hooks-node.migration.d.ts +22 -0
- package/dist/migrations/003-remove-hooks-node.migration.d.ts.map +1 -0
- package/dist/migrations/003-remove-hooks-node.migration.js +103 -0
- package/dist/migrations/003-remove-hooks-node.migration.js.map +1 -0
- package/dist/migrations/index.d.ts +1 -0
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/migrations/index.js +1 -1
- package/dist/migrations/index.js.map +1 -1
- package/dist/providers/plugins/sso/sso.http-client.js +2 -2
- package/dist/providers/plugins/sso/sso.http-client.js.map +1 -1
- package/dist/providers/plugins/sso/sso.setup-steps.d.ts.map +1 -1
- package/dist/providers/plugins/sso/sso.setup-steps.js +14 -10
- package/dist/providers/plugins/sso/sso.setup-steps.js.map +1 -1
- package/dist/skills/core/SkillDiscovery.d.ts +83 -0
- package/dist/skills/core/SkillDiscovery.d.ts.map +1 -0
- package/dist/skills/core/SkillDiscovery.js +237 -0
- package/dist/skills/core/SkillDiscovery.js.map +1 -0
- package/dist/skills/core/SkillManager.d.ts +86 -0
- package/dist/skills/core/SkillManager.d.ts.map +1 -0
- package/dist/skills/core/SkillManager.js +155 -0
- package/dist/skills/core/SkillManager.js.map +1 -0
- package/dist/skills/core/types.d.ts +120 -0
- package/dist/skills/core/types.d.ts.map +1 -0
- package/dist/skills/core/types.js +20 -0
- package/dist/skills/core/types.js.map +1 -0
- package/dist/skills/index.d.ts +12 -0
- package/dist/skills/index.d.ts.map +1 -0
- package/dist/skills/index.js +12 -0
- package/dist/skills/index.js.map +1 -0
- package/dist/skills/utils/content-loader.d.ts +25 -0
- package/dist/skills/utils/content-loader.d.ts.map +1 -0
- package/dist/skills/utils/content-loader.js +161 -0
- package/dist/skills/utils/content-loader.js.map +1 -0
- package/dist/skills/utils/frontmatter.d.ts +60 -0
- package/dist/skills/utils/frontmatter.d.ts.map +1 -0
- package/dist/skills/utils/frontmatter.js +114 -0
- package/dist/skills/utils/frontmatter.js.map +1 -0
- package/dist/skills/utils/pattern-matcher.d.ts +60 -0
- package/dist/skills/utils/pattern-matcher.d.ts.map +1 -0
- package/dist/skills/utils/pattern-matcher.js +97 -0
- package/dist/skills/utils/pattern-matcher.js.map +1 -0
- package/dist/utils/auth.d.ts +22 -0
- package/dist/utils/auth.d.ts.map +1 -0
- package/dist/utils/auth.js +50 -0
- package/dist/utils/auth.js.map +1 -0
- package/dist/utils/cli-updater.d.ts +70 -0
- package/dist/utils/cli-updater.d.ts.map +1 -0
- package/dist/utils/cli-updater.js +339 -0
- package/dist/utils/cli-updater.js.map +1 -0
- package/dist/utils/config.d.ts +6 -1
- package/dist/utils/config.d.ts.map +1 -1
- package/dist/utils/config.js +13 -0
- package/dist/utils/config.js.map +1 -1
- package/dist/utils/installation-detector.d.ts +22 -0
- package/dist/utils/installation-detector.d.ts.map +1 -0
- package/dist/utils/installation-detector.js +49 -0
- package/dist/utils/installation-detector.js.map +1 -0
- package/dist/utils/native-installer.d.ts +49 -0
- package/dist/utils/native-installer.d.ts.map +1 -0
- package/dist/utils/native-installer.js +225 -0
- package/dist/utils/native-installer.js.map +1 -0
- package/dist/utils/processes.js +1 -1
- package/dist/utils/profile.d.ts +2 -0
- package/dist/utils/profile.d.ts.map +1 -1
- package/dist/utils/profile.js +5 -0
- package/dist/utils/profile.js.map +1 -1
- package/dist/utils/sdk-client.d.ts +15 -0
- package/dist/utils/sdk-client.d.ts.map +1 -0
- package/dist/utils/sdk-client.js +92 -0
- package/dist/utils/sdk-client.js.map +1 -0
- package/dist/utils/version-utils.d.ts +50 -0
- package/dist/utils/version-utils.d.ts.map +1 -0
- package/dist/utils/version-utils.js +92 -0
- package/dist/utils/version-utils.js.map +1 -0
- package/package.json +11 -3
- package/scripts/copy-mr-skill-to-global.ts +252 -0
- package/scripts/demo-hooks.sh +125 -0
- package/scripts/test-hooks.sh +196 -0
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/INDEX.md +0 -205
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/TEMPLATE_SIZES.md +0 -74
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/architecture/layered-architecture.md.template +0 -143
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/architecture/project-structure.md.template +0 -127
- 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
|
|
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 =
|
|
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:
|
|
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:
|
|
416
|
+
onEvent({ type: EVENT_TYPES.ERROR, error: 'Stream interrupted by user (Ctrl+C)' });
|
|
323
417
|
};
|
|
324
418
|
process.once('SIGINT', sigintHandler);
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
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
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
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
|
-
//
|
|
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
|
-
|
|
378
|
-
|
|
379
|
-
|
|
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
|
-
|
|
405
|
-
|
|
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
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
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('
|
|
491
|
+
logger.debug('UserPromptSubmit hook provided context');
|
|
429
492
|
}
|
|
430
|
-
|
|
493
|
+
// Prepend context to the message
|
|
494
|
+
message = `${hookResult.additionalContext}\n\n${message}`;
|
|
431
495
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
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(`
|
|
514
|
+
logger.debug(`Injected ${skillsWithInventory.length} skills: ${skillsWithInventory.map((s) => s.skill.metadata.name).join(', ')}`);
|
|
442
515
|
}
|
|
443
516
|
}
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
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
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
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
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
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
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
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:
|
|
572
|
-
onEvent({ type:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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
|
|
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
|