@tyvm/knowhow 0.0.47 → 0.0.49
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/benchmarks/results/27b0a06/2025-09-27/xai/xai-grok-code-fast-1.json +2909 -0
- package/benchmarks/results/4057aed/2025-08-14/anthropic/anthropic-claude-sonnet-4-20250514.json +1671 -0
- package/jest.config.js +2 -2
- package/package.json +8 -3
- package/src/agents/base/base.ts +39 -25
- package/src/agents/patcher/patcher.ts +26 -5
- package/src/agents/tools/agentCall.ts +4 -2
- package/src/agents/tools/aiClient.ts +3 -11
- package/src/agents/tools/ast/astAppendNode.ts +90 -0
- package/src/agents/tools/ast/astDeleteNode.ts +88 -0
- package/src/agents/tools/ast/astEditNode.ts +95 -0
- package/src/agents/tools/ast/astGetPathForLine.ts +73 -0
- package/src/agents/tools/ast/astListPaths.ts +66 -0
- package/src/agents/tools/ast/index.ts +7 -0
- package/src/agents/tools/callPlugin.ts +8 -2
- package/src/agents/tools/embeddingSearch.ts +2 -1
- package/src/agents/tools/execCommand.ts +239 -94
- package/src/agents/tools/fileSearch.ts +15 -17
- package/src/agents/tools/index.ts +1 -0
- package/src/agents/tools/language/definitions.ts +10 -2
- package/src/agents/tools/language/index.ts +3 -2
- package/src/agents/tools/lintFile.ts +4 -2
- package/src/agents/tools/list.ts +203 -62
- package/src/agents/tools/patch.ts +48 -14
- package/src/agents/tools/readBlocks.ts +34 -0
- package/src/agents/tools/readFile.ts +23 -0
- package/src/agents/tools/stringReplace.ts +33 -9
- package/src/agents/tools/writeFile.ts +55 -0
- package/src/agents/tools/ycmd/server.ts +14 -4
- package/src/chat/CliChatService.ts +6 -1
- package/src/chat/modules/AgentModule.ts +129 -67
- package/src/chat/modules/AskModule.ts +0 -1
- package/src/chat/modules/SetupModule.ts +4 -4
- package/src/chat/modules/SystemModule.ts +28 -5
- package/src/chat/types.ts +2 -0
- package/src/chat-old.ts +2 -2
- package/src/clients/anthropic.ts +22 -1
- package/src/clients/openai.ts +1 -1
- package/src/clients/xai.ts +15 -5
- package/src/config.ts +17 -5
- package/src/dataset/diffs/generate.ts +2 -2
- package/src/dataset/diffs/jsonl.ts +0 -1
- package/src/embeddings.ts +8 -8
- package/src/index.ts +11 -5
- package/src/plugins/GitPlugin.ts +530 -0
- package/src/plugins/LinterPlugin.ts +89 -0
- package/src/plugins/PluginBase.ts +4 -2
- package/src/plugins/asana.ts +4 -2
- package/src/plugins/downloader/plugin.ts +5 -2
- package/src/plugins/embedding.ts +24 -4
- package/src/plugins/figma.ts +7 -3
- package/src/plugins/github.ts +4 -2
- package/src/plugins/jira.ts +4 -2
- package/src/plugins/language.ts +134 -27
- package/src/plugins/linear.ts +4 -2
- package/src/plugins/notion.ts +4 -2
- package/src/plugins/plugins.ts +27 -16
- package/src/plugins/tree-sitter/editor.ts +369 -0
- package/src/plugins/tree-sitter/lang-packs/index.ts +23 -0
- package/src/plugins/tree-sitter/lang-packs/java.ts +59 -0
- package/src/plugins/tree-sitter/lang-packs/javascript.ts +57 -0
- package/src/plugins/tree-sitter/lang-packs/python.ts +45 -0
- package/src/plugins/tree-sitter/lang-packs/types.ts +79 -0
- package/src/plugins/tree-sitter/lang-packs/typescript.ts +49 -0
- package/src/plugins/tree-sitter/parser.ts +444 -0
- package/src/plugins/tree-sitter/simple-paths.ts +467 -0
- package/src/plugins/types.ts +11 -0
- package/src/plugins/url.ts +5 -3
- package/src/plugins/vim.ts +8 -5
- package/src/processors/CustomVariables.ts +60 -70
- package/src/processors/TokenCompressor.ts +15 -14
- package/src/processors/ToolResponseCache.ts +20 -14
- package/src/services/EmbeddingService.ts +18 -9
- package/src/services/EventService.ts +80 -0
- package/src/services/Mcp.ts +5 -0
- package/src/services/S3.ts +4 -3
- package/src/services/Tools.ts +125 -53
- package/src/services/index.ts +16 -11
- package/src/services/types.ts +3 -3
- package/src/types.ts +7 -2
- package/src/worker.ts +14 -1
- package/test-comprehensive.ts +31 -0
- package/tests/clients/AIClient.test.ts +490 -0
- package/tests/manual/agent-events/run-test.ts +203 -0
- package/tests/{integration → manual/file-edits}/figma.test.ts +1 -1
- package/tests/{integration → manual/file-edits}/fileblocks/readwrite.test.ts +7 -3
- package/tests/{integration → manual/file-edits}/patching.test.ts +11 -8
- package/tests/plugins/language/languagePlugin-content-triggers.test.ts +332 -0
- package/tests/plugins/language/languagePlugin-integration.test.ts +456 -0
- package/tests/plugins/language/languagePlugin.test.ts +363 -0
- package/tests/processors/Base64ImageDetector.test.ts +403 -0
- package/tests/processors/CustomVariables.test.ts +485 -0
- package/tests/processors/HarmonyToolProcessor.test.ts +490 -0
- package/tests/processors/TokenCompressor.test.ts +390 -0
- package/tests/processors/ToolResponseCache.test.ts +736 -0
- package/tests/services/Tools.test.ts +1339 -0
- package/tests/test.spec.ts +162 -117
- package/tests/tree-sitter/editor.test.ts +113 -0
- package/tests/tree-sitter/invalid.test.ts +299 -0
- package/tests/tree-sitter/paths/common-edits.test.ts +564 -0
- package/tests/tree-sitter/paths/debug-exact-position.test.ts +44 -0
- package/tests/tree-sitter/paths/debug-line-indexing.test.ts +49 -0
- package/tests/tree-sitter/paths/debug-paths.test.ts +90 -0
- package/tests/tree-sitter/paths/paths.test.ts +170 -0
- package/tests/tree-sitter/paths/simple-paths.test.ts +367 -0
- package/tests/tree-sitter/sample-after.ts +48 -0
- package/tests/tree-sitter/sample-before.ts +25 -0
- package/tests/tree-sitter/test-files/completely-broken.ts +7 -0
- package/tests/tree-sitter/test-files/duplicate-braces.ts +39 -0
- package/tests/tree-sitter/test-files/invalid-nesting.ts +39 -0
- package/tests/tree-sitter/test-files/malformed-signature.ts +39 -0
- package/tests/tree-sitter/test-files/mismatched-parens.ts +39 -0
- package/tests/tree-sitter/test-files/missing-semicolon.ts +39 -0
- package/tests/tree-sitter/test-files/partially-broken.ts +20 -0
- package/tests/tree-sitter/test-files/specific-errors.ts +14 -0
- package/tests/tree-sitter/test-files/unclosed-string.ts +39 -0
- package/tests/tree-sitter/tree-sitter.test.ts +251 -0
- package/ts_build/package.json +8 -3
- package/ts_build/src/agents/base/base.d.ts +7 -2
- package/ts_build/src/agents/base/base.js +27 -21
- package/ts_build/src/agents/base/base.js.map +1 -1
- package/ts_build/src/agents/patcher/patcher.js +26 -5
- package/ts_build/src/agents/patcher/patcher.js.map +1 -1
- package/ts_build/src/agents/tools/agentCall.js +2 -1
- package/ts_build/src/agents/tools/agentCall.js.map +1 -1
- package/ts_build/src/agents/tools/aiClient.d.ts +7 -8
- package/ts_build/src/agents/tools/aiClient.js.map +1 -1
- package/ts_build/src/agents/tools/ast/astAppendNode.d.ts +1 -0
- package/ts_build/src/agents/tools/ast/astAppendNode.js +96 -0
- package/ts_build/src/agents/tools/ast/astAppendNode.js.map +1 -0
- package/ts_build/src/agents/tools/ast/astDeleteNode.d.ts +1 -0
- package/ts_build/src/agents/tools/ast/astDeleteNode.js +94 -0
- package/ts_build/src/agents/tools/ast/astDeleteNode.js.map +1 -0
- package/ts_build/src/agents/tools/ast/astEditNode.d.ts +1 -0
- package/ts_build/src/agents/tools/ast/astEditNode.js +96 -0
- package/ts_build/src/agents/tools/ast/astEditNode.js.map +1 -0
- package/ts_build/src/agents/tools/ast/astGetPathForLine.d.ts +1 -0
- package/ts_build/src/agents/tools/ast/astGetPathForLine.js +78 -0
- package/ts_build/src/agents/tools/ast/astGetPathForLine.js.map +1 -0
- package/ts_build/src/agents/tools/ast/astListPaths.d.ts +1 -0
- package/ts_build/src/agents/tools/ast/astListPaths.js +78 -0
- package/ts_build/src/agents/tools/ast/astListPaths.js.map +1 -0
- package/ts_build/src/agents/tools/ast/index.d.ts +5 -0
- package/ts_build/src/agents/tools/ast/index.js +14 -0
- package/ts_build/src/agents/tools/ast/index.js.map +1 -0
- package/ts_build/src/agents/tools/astAppendNode.d.ts +1 -0
- package/ts_build/src/agents/tools/astAppendNode.js +98 -0
- package/ts_build/src/agents/tools/astAppendNode.js.map +1 -0
- package/ts_build/src/agents/tools/astDeleteNode.d.ts +1 -0
- package/ts_build/src/agents/tools/astDeleteNode.js +95 -0
- package/ts_build/src/agents/tools/astDeleteNode.js.map +1 -0
- package/ts_build/src/agents/tools/astEditNode.d.ts +1 -0
- package/ts_build/src/agents/tools/astEditNode.js +98 -0
- package/ts_build/src/agents/tools/astEditNode.js.map +1 -0
- package/ts_build/src/agents/tools/astGetPathForLine.d.ts +1 -0
- package/ts_build/src/agents/tools/astGetPathForLine.js +89 -0
- package/ts_build/src/agents/tools/astGetPathForLine.js.map +1 -0
- package/ts_build/src/agents/tools/astListPaths.d.ts +1 -0
- package/ts_build/src/agents/tools/astListPaths.js +82 -0
- package/ts_build/src/agents/tools/astListPaths.js.map +1 -0
- package/ts_build/src/agents/tools/callPlugin.js +4 -2
- package/ts_build/src/agents/tools/callPlugin.js.map +1 -1
- package/ts_build/src/agents/tools/embeddingSearch.js +3 -2
- package/ts_build/src/agents/tools/embeddingSearch.js.map +1 -1
- package/ts_build/src/agents/tools/execCommand.d.ts +2 -2
- package/ts_build/src/agents/tools/execCommand.js +201 -67
- package/ts_build/src/agents/tools/execCommand.js.map +1 -1
- package/ts_build/src/agents/tools/fileSearch.d.ts +1 -1
- package/ts_build/src/agents/tools/fileSearch.js +11 -15
- package/ts_build/src/agents/tools/fileSearch.js.map +1 -1
- package/ts_build/src/agents/tools/github/index.d.ts +1 -1
- package/ts_build/src/agents/tools/index.d.ts +1 -0
- package/ts_build/src/agents/tools/index.js +1 -0
- package/ts_build/src/agents/tools/index.js.map +1 -1
- package/ts_build/src/agents/tools/language/definitions.js +11 -2
- package/ts_build/src/agents/tools/language/definitions.js.map +1 -1
- package/ts_build/src/agents/tools/language/index.js +4 -3
- package/ts_build/src/agents/tools/language/index.js.map +1 -1
- package/ts_build/src/agents/tools/lintFile.js +4 -2
- package/ts_build/src/agents/tools/lintFile.js.map +1 -1
- package/ts_build/src/agents/tools/list.js +185 -49
- package/ts_build/src/agents/tools/list.js.map +1 -1
- package/ts_build/src/agents/tools/patch.js +33 -10
- package/ts_build/src/agents/tools/patch.js.map +1 -1
- package/ts_build/src/agents/tools/readBlocks.js +23 -0
- package/ts_build/src/agents/tools/readBlocks.js.map +1 -1
- package/ts_build/src/agents/tools/readFile.js +14 -0
- package/ts_build/src/agents/tools/readFile.js.map +1 -1
- package/ts_build/src/agents/tools/stringReplace.js +19 -2
- package/ts_build/src/agents/tools/stringReplace.js.map +1 -1
- package/ts_build/src/agents/tools/writeFile.js +40 -0
- package/ts_build/src/agents/tools/writeFile.js.map +1 -1
- package/ts_build/src/agents/tools/ycmd/server.js +5 -0
- package/ts_build/src/agents/tools/ycmd/server.js.map +1 -1
- package/ts_build/src/chat/CliChatService.d.ts +1 -0
- package/ts_build/src/chat/CliChatService.js +6 -2
- package/ts_build/src/chat/CliChatService.js.map +1 -1
- package/ts_build/src/chat/modules/AgentModule.d.ts +5 -1
- package/ts_build/src/chat/modules/AgentModule.js +62 -32
- package/ts_build/src/chat/modules/AgentModule.js.map +1 -1
- package/ts_build/src/chat/modules/AskModule.js.map +1 -1
- package/ts_build/src/chat/modules/SetupModule.js +4 -3
- package/ts_build/src/chat/modules/SetupModule.js.map +1 -1
- package/ts_build/src/chat/modules/SystemModule.js +19 -4
- package/ts_build/src/chat/modules/SystemModule.js.map +1 -1
- package/ts_build/src/chat/modules/index.d.ts +5 -0
- package/ts_build/src/chat/modules/index.js +14 -0
- package/ts_build/src/chat/modules/index.js.map +1 -0
- package/ts_build/src/chat/types.d.ts +2 -0
- package/ts_build/src/chat-old.js +3 -3
- package/ts_build/src/chat-old.js.map +1 -1
- package/ts_build/src/clients/anthropic.d.ts +1 -0
- package/ts_build/src/clients/anthropic.js +22 -1
- package/ts_build/src/clients/anthropic.js.map +1 -1
- package/ts_build/src/clients/openai.js +1 -1
- package/ts_build/src/clients/openai.js.map +1 -1
- package/ts_build/src/clients/xai.d.ts +7 -0
- package/ts_build/src/clients/xai.js +13 -4
- package/ts_build/src/clients/xai.js.map +1 -1
- package/ts_build/src/config.js +14 -3
- package/ts_build/src/config.js.map +1 -1
- package/ts_build/src/dataset/diffs/generate.js +2 -2
- package/ts_build/src/dataset/diffs/generate.js.map +1 -1
- package/ts_build/src/dataset/diffs/jsonl.js.map +1 -1
- package/ts_build/src/embeddings.js +9 -13
- package/ts_build/src/embeddings.js.map +1 -1
- package/ts_build/src/index.js +10 -10
- package/ts_build/src/index.js.map +1 -1
- package/ts_build/src/plugins/GitPlugin.d.ts +39 -0
- package/ts_build/src/plugins/GitPlugin.js +439 -0
- package/ts_build/src/plugins/GitPlugin.js.map +1 -0
- package/ts_build/src/plugins/LinterPlugin.d.ts +15 -0
- package/ts_build/src/plugins/LinterPlugin.js +65 -0
- package/ts_build/src/plugins/LinterPlugin.js.map +1 -0
- package/ts_build/src/plugins/PluginBase.d.ts +4 -3
- package/ts_build/src/plugins/PluginBase.js +3 -3
- package/ts_build/src/plugins/PluginBase.js.map +1 -1
- package/ts_build/src/plugins/asana.d.ts +3 -1
- package/ts_build/src/plugins/asana.js +3 -2
- package/ts_build/src/plugins/asana.js.map +1 -1
- package/ts_build/src/plugins/downloader/plugin.d.ts +3 -1
- package/ts_build/src/plugins/downloader/plugin.js +3 -2
- package/ts_build/src/plugins/downloader/plugin.js.map +1 -1
- package/ts_build/src/plugins/embedding.d.ts +5 -1
- package/ts_build/src/plugins/embedding.js +15 -3
- package/ts_build/src/plugins/embedding.js.map +1 -1
- package/ts_build/src/plugins/figma.d.ts +3 -1
- package/ts_build/src/plugins/figma.js +28 -4
- package/ts_build/src/plugins/figma.js.map +1 -1
- package/ts_build/src/plugins/github.d.ts +3 -1
- package/ts_build/src/plugins/github.js +3 -2
- package/ts_build/src/plugins/github.js.map +1 -1
- package/ts_build/src/plugins/jira.d.ts +3 -1
- package/ts_build/src/plugins/jira.js +3 -2
- package/ts_build/src/plugins/jira.js.map +1 -1
- package/ts_build/src/plugins/language.d.ts +7 -4
- package/ts_build/src/plugins/language.js +85 -20
- package/ts_build/src/plugins/language.js.map +1 -1
- package/ts_build/src/plugins/linear.d.ts +3 -1
- package/ts_build/src/plugins/linear.js +3 -2
- package/ts_build/src/plugins/linear.js.map +1 -1
- package/ts_build/src/plugins/notion.d.ts +3 -1
- package/ts_build/src/plugins/notion.js +3 -2
- package/ts_build/src/plugins/notion.js.map +1 -1
- package/ts_build/src/plugins/plugins.d.ts +4 -3
- package/ts_build/src/plugins/plugins.js +24 -14
- package/ts_build/src/plugins/plugins.js.map +1 -1
- package/ts_build/src/plugins/tree-sitter/editor.d.ts +34 -0
- package/ts_build/src/plugins/tree-sitter/editor.js +218 -0
- package/ts_build/src/plugins/tree-sitter/editor.js.map +1 -0
- package/ts_build/src/plugins/tree-sitter/human-readable-paths-new.d.ts +29 -0
- package/ts_build/src/plugins/tree-sitter/human-readable-paths-new.js +538 -0
- package/ts_build/src/plugins/tree-sitter/human-readable-paths-new.js.map +1 -0
- package/ts_build/src/plugins/tree-sitter/human-readable-paths.d.ts +22 -0
- package/ts_build/src/plugins/tree-sitter/human-readable-paths.js +332 -0
- package/ts_build/src/plugins/tree-sitter/human-readable-paths.js.map +1 -0
- package/ts_build/src/plugins/tree-sitter/lang-packs/index.d.ts +8 -0
- package/ts_build/src/plugins/tree-sitter/lang-packs/index.js +26 -0
- package/ts_build/src/plugins/tree-sitter/lang-packs/index.js.map +1 -0
- package/ts_build/src/plugins/tree-sitter/lang-packs/java.d.ts +2 -0
- package/ts_build/src/plugins/tree-sitter/lang-packs/java.js +61 -0
- package/ts_build/src/plugins/tree-sitter/lang-packs/java.js.map +1 -0
- package/ts_build/src/plugins/tree-sitter/lang-packs/javascript.d.ts +2 -0
- package/ts_build/src/plugins/tree-sitter/lang-packs/javascript.js +59 -0
- package/ts_build/src/plugins/tree-sitter/lang-packs/javascript.js.map +1 -0
- package/ts_build/src/plugins/tree-sitter/lang-packs/python.d.ts +2 -0
- package/ts_build/src/plugins/tree-sitter/lang-packs/python.js +47 -0
- package/ts_build/src/plugins/tree-sitter/lang-packs/python.js.map +1 -0
- package/ts_build/src/plugins/tree-sitter/lang-packs/types.d.ts +43 -0
- package/ts_build/src/plugins/tree-sitter/lang-packs/types.js +3 -0
- package/ts_build/src/plugins/tree-sitter/lang-packs/types.js.map +1 -0
- package/ts_build/src/plugins/tree-sitter/lang-packs/typescript.d.ts +2 -0
- package/ts_build/src/plugins/tree-sitter/lang-packs/typescript.js +50 -0
- package/ts_build/src/plugins/tree-sitter/lang-packs/typescript.js.map +1 -0
- package/ts_build/src/plugins/tree-sitter/parser.d.ts +75 -0
- package/ts_build/src/plugins/tree-sitter/parser.js +306 -0
- package/ts_build/src/plugins/tree-sitter/parser.js.map +1 -0
- package/ts_build/src/plugins/tree-sitter/simple-paths.d.ts +22 -0
- package/ts_build/src/plugins/tree-sitter/simple-paths.js +332 -0
- package/ts_build/src/plugins/tree-sitter/simple-paths.js.map +1 -0
- package/ts_build/src/plugins/types.d.ts +10 -0
- package/ts_build/src/plugins/url.d.ts +3 -2
- package/ts_build/src/plugins/url.js +3 -2
- package/ts_build/src/plugins/url.js.map +1 -1
- package/ts_build/src/plugins/vim.d.ts +4 -2
- package/ts_build/src/plugins/vim.js +6 -8
- package/ts_build/src/plugins/vim.js.map +1 -1
- package/ts_build/src/processors/CustomVariables.js +45 -47
- package/ts_build/src/processors/CustomVariables.js.map +1 -1
- package/ts_build/src/processors/TokenCompressor.js +10 -13
- package/ts_build/src/processors/TokenCompressor.js.map +1 -1
- package/ts_build/src/processors/ToolResponseCache.d.ts +2 -2
- package/ts_build/src/processors/ToolResponseCache.js +18 -10
- package/ts_build/src/processors/ToolResponseCache.js.map +1 -1
- package/ts_build/src/services/EmbeddingService.d.ts +10 -1
- package/ts_build/src/services/EmbeddingService.js +12 -12
- package/ts_build/src/services/EmbeddingService.js.map +1 -1
- package/ts_build/src/services/EventService.d.ts +7 -0
- package/ts_build/src/services/EventService.js +49 -0
- package/ts_build/src/services/EventService.js.map +1 -1
- package/ts_build/src/services/Mcp.js +8 -0
- package/ts_build/src/services/Mcp.js.map +1 -1
- package/ts_build/src/services/S3.js +4 -3
- package/ts_build/src/services/S3.js.map +1 -1
- package/ts_build/src/services/Tools.d.ts +1 -0
- package/ts_build/src/services/Tools.js +97 -35
- package/ts_build/src/services/Tools.js.map +1 -1
- package/ts_build/src/services/index.d.ts +4 -5
- package/ts_build/src/services/index.js +14 -9
- package/ts_build/src/services/index.js.map +1 -1
- package/ts_build/src/services/types.js +3 -3
- package/ts_build/src/services/types.js.map +1 -1
- package/ts_build/src/types.d.ts +7 -1
- package/ts_build/src/types.js +4 -0
- package/ts_build/src/types.js.map +1 -1
- package/ts_build/src/worker.js +12 -1
- package/ts_build/src/worker.js.map +1 -1
- package/ts_build/tests/clients/AIClient.test.d.ts +1 -0
- package/ts_build/tests/clients/AIClient.test.js +377 -0
- package/ts_build/tests/clients/AIClient.test.js.map +1 -0
- package/ts_build/tests/languagePlugin.test.js +217 -11
- package/ts_build/tests/languagePlugin.test.js.map +1 -1
- package/ts_build/tests/manual/agent-events/event-handler-reliability.test.d.ts +1 -0
- package/ts_build/tests/manual/agent-events/event-handler-reliability.test.js +315 -0
- package/ts_build/tests/manual/agent-events/event-handler-reliability.test.js.map +1 -0
- package/ts_build/tests/manual/agent-events/run-test.d.ts +2 -0
- package/ts_build/tests/manual/agent-events/run-test.js +148 -0
- package/ts_build/tests/manual/agent-events/run-test.js.map +1 -0
- package/ts_build/tests/manual/file-edits/figma.test.d.ts +1 -0
- package/ts_build/tests/manual/file-edits/figma.test.js +47 -0
- package/ts_build/tests/manual/file-edits/figma.test.js.map +1 -0
- package/ts_build/tests/manual/file-edits/fileblocks/readwrite.test.d.ts +1 -0
- package/ts_build/tests/manual/file-edits/fileblocks/readwrite.test.js +100 -0
- package/ts_build/tests/manual/file-edits/fileblocks/readwrite.test.js.map +1 -0
- package/ts_build/tests/manual/file-edits/patching.test.d.ts +1 -0
- package/ts_build/tests/manual/file-edits/patching.test.js +119 -0
- package/ts_build/tests/manual/file-edits/patching.test.js.map +1 -0
- package/ts_build/tests/plugins/language/languagePlugin-content-triggers.test.d.ts +1 -0
- package/ts_build/tests/plugins/language/languagePlugin-content-triggers.test.js +277 -0
- package/ts_build/tests/plugins/language/languagePlugin-content-triggers.test.js.map +1 -0
- package/ts_build/tests/plugins/language/languagePlugin-integration.test.d.ts +1 -0
- package/ts_build/tests/plugins/language/languagePlugin-integration.test.js +331 -0
- package/ts_build/tests/plugins/language/languagePlugin-integration.test.js.map +1 -0
- package/ts_build/tests/plugins/language/languagePlugin.test.d.ts +1 -0
- package/ts_build/tests/plugins/language/languagePlugin.test.js +286 -0
- package/ts_build/tests/plugins/language/languagePlugin.test.js.map +1 -0
- package/ts_build/tests/processors/Base64ImageDetector.test.d.ts +1 -0
- package/ts_build/tests/processors/Base64ImageDetector.test.js +351 -0
- package/ts_build/tests/processors/Base64ImageDetector.test.js.map +1 -0
- package/ts_build/tests/processors/CustomVariables.test.d.ts +1 -0
- package/ts_build/tests/processors/CustomVariables.test.js +354 -0
- package/ts_build/tests/processors/CustomVariables.test.js.map +1 -0
- package/ts_build/tests/processors/HarmonyToolProcessor.test.d.ts +1 -0
- package/ts_build/tests/processors/HarmonyToolProcessor.test.js +382 -0
- package/ts_build/tests/processors/HarmonyToolProcessor.test.js.map +1 -0
- package/ts_build/tests/processors/TokenCompressor.test.d.ts +1 -0
- package/ts_build/tests/processors/TokenCompressor.test.js +299 -0
- package/ts_build/tests/processors/TokenCompressor.test.js.map +1 -0
- package/ts_build/tests/processors/ToolResponseCache.test.d.ts +1 -0
- package/ts_build/tests/processors/ToolResponseCache.test.js +550 -0
- package/ts_build/tests/processors/ToolResponseCache.test.js.map +1 -0
- package/ts_build/tests/services/Plugins/plugin-event-integration.test.d.ts +1 -0
- package/ts_build/tests/services/Plugins/plugin-event-integration.test.js +232 -0
- package/ts_build/tests/services/Plugins/plugin-event-integration.test.js.map +1 -0
- package/ts_build/tests/services/Tools.test.d.ts +1 -0
- package/ts_build/tests/services/Tools.test.js +1059 -0
- package/ts_build/tests/services/Tools.test.js.map +1 -0
- package/ts_build/tests/test.spec.js +110 -68
- package/ts_build/tests/test.spec.js.map +1 -1
- package/ts_build/tests/tree-sitter/editor.test.d.ts +1 -0
- package/ts_build/tests/tree-sitter/editor.test.js +85 -0
- package/ts_build/tests/tree-sitter/editor.test.js.map +1 -0
- package/ts_build/tests/tree-sitter/invalid.test.d.ts +1 -0
- package/ts_build/tests/tree-sitter/invalid.test.js +198 -0
- package/ts_build/tests/tree-sitter/invalid.test.js.map +1 -0
- package/ts_build/tests/tree-sitter/paths/common-edits.test.d.ts +1 -0
- package/ts_build/tests/tree-sitter/paths/common-edits.test.js +347 -0
- package/ts_build/tests/tree-sitter/paths/common-edits.test.js.map +1 -0
- package/ts_build/tests/tree-sitter/paths/debug-exact-position.test.d.ts +1 -0
- package/ts_build/tests/tree-sitter/paths/debug-exact-position.test.js +35 -0
- package/ts_build/tests/tree-sitter/paths/debug-exact-position.test.js.map +1 -0
- package/ts_build/tests/tree-sitter/paths/debug-line-indexing.test.d.ts +1 -0
- package/ts_build/tests/tree-sitter/paths/debug-line-indexing.test.js +38 -0
- package/ts_build/tests/tree-sitter/paths/debug-line-indexing.test.js.map +1 -0
- package/ts_build/tests/tree-sitter/paths/debug-paths.test.d.ts +1 -0
- package/ts_build/tests/tree-sitter/paths/debug-paths.test.js +74 -0
- package/ts_build/tests/tree-sitter/paths/debug-paths.test.js.map +1 -0
- package/ts_build/tests/tree-sitter/paths/human-readable-paths.test.d.ts +1 -0
- package/ts_build/tests/tree-sitter/paths/human-readable-paths.test.js +302 -0
- package/ts_build/tests/tree-sitter/paths/human-readable-paths.test.js.map +1 -0
- package/ts_build/tests/tree-sitter/paths/paths.test.d.ts +1 -0
- package/ts_build/tests/tree-sitter/paths/paths.test.js +116 -0
- package/ts_build/tests/tree-sitter/paths/paths.test.js.map +1 -0
- package/ts_build/tests/tree-sitter/paths/simple-paths.test.d.ts +1 -0
- package/ts_build/tests/tree-sitter/paths/simple-paths.test.js +302 -0
- package/ts_build/tests/tree-sitter/paths/simple-paths.test.js.map +1 -0
- package/ts_build/tests/tree-sitter/sample-after.d.ts +11 -0
- package/ts_build/tests/tree-sitter/sample-after.js +44 -0
- package/ts_build/tests/tree-sitter/sample-after.js.map +1 -0
- package/ts_build/tests/tree-sitter/sample-before.d.ts +9 -0
- package/ts_build/tests/tree-sitter/sample-before.js +28 -0
- package/ts_build/tests/tree-sitter/sample-before.js.map +1 -0
- package/ts_build/tests/tree-sitter/test-files/completely-broken.d.ts +2 -0
- package/ts_build/tests/tree-sitter/test-files/completely-broken.js +17 -0
- package/ts_build/tests/tree-sitter/test-files/completely-broken.js.map +1 -0
- package/ts_build/tests/tree-sitter/test-files/duplicate-braces.d.ts +8 -0
- package/ts_build/tests/tree-sitter/test-files/duplicate-braces.js +38 -0
- package/ts_build/tests/tree-sitter/test-files/duplicate-braces.js.map +1 -0
- package/ts_build/tests/tree-sitter/test-files/invalid-nesting.d.ts +8 -0
- package/ts_build/tests/tree-sitter/test-files/invalid-nesting.js +38 -0
- package/ts_build/tests/tree-sitter/test-files/invalid-nesting.js.map +1 -0
- package/ts_build/tests/tree-sitter/test-files/malformed-signature.d.ts +8 -0
- package/ts_build/tests/tree-sitter/test-files/malformed-signature.js +38 -0
- package/ts_build/tests/tree-sitter/test-files/malformed-signature.js.map +1 -0
- package/ts_build/tests/tree-sitter/test-files/mismatched-parens.d.ts +10 -0
- package/ts_build/tests/tree-sitter/test-files/mismatched-parens.js +38 -0
- package/ts_build/tests/tree-sitter/test-files/mismatched-parens.js.map +1 -0
- package/ts_build/tests/tree-sitter/test-files/missing-semicolon.d.ts +8 -0
- package/ts_build/tests/tree-sitter/test-files/missing-semicolon.js +38 -0
- package/ts_build/tests/tree-sitter/test-files/missing-semicolon.js.map +1 -0
- package/ts_build/tests/tree-sitter/test-files/partially-broken.d.ts +6 -0
- package/ts_build/tests/tree-sitter/test-files/partially-broken.js +20 -0
- package/ts_build/tests/tree-sitter/test-files/partially-broken.js.map +1 -0
- package/ts_build/tests/tree-sitter/test-files/specific-errors.d.ts +7 -0
- package/ts_build/tests/tree-sitter/test-files/specific-errors.js +14 -0
- package/ts_build/tests/tree-sitter/test-files/specific-errors.js.map +1 -0
- package/ts_build/tests/tree-sitter/test-files/unclosed-string.d.ts +8 -0
- package/ts_build/tests/tree-sitter/test-files/unclosed-string.js +38 -0
- package/ts_build/tests/tree-sitter/test-files/unclosed-string.js.map +1 -0
- package/ts_build/tests/tree-sitter/tree-sitter.test.d.ts +1 -0
- package/ts_build/tests/tree-sitter/tree-sitter.test.js +185 -0
- package/ts_build/tests/tree-sitter/tree-sitter.test.js.map +1 -0
- package/tsconfig.json +2 -1
- package/tests/languagePlugin.test.ts +0 -74
- /package/src/chat/modules/{index.js → index.ts} +0 -0
- /package/tests/{integration → manual/file-edits}/patching/input.txt +0 -0
- /package/tests/{integration → manual/file-edits}/patching/output.txt +0 -0
- /package/tests/{integration → manual/file-edits}/patching/patch.txt +0 -0
- /package/tests/{integration → manual/file-edits}/patching/unseen.txt +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as fs from "fs";
|
|
2
|
+
import { services, ToolsService } from "../../services";
|
|
2
3
|
|
|
3
4
|
// Tool to write the full contents of a file
|
|
4
5
|
export function writeFile(filePath: string, content: string): string {
|
|
@@ -16,12 +17,39 @@ export async function writeFileChunk(
|
|
|
16
17
|
isContinuing: boolean,
|
|
17
18
|
isDone: boolean
|
|
18
19
|
) {
|
|
20
|
+
// Get context from bound ToolsService
|
|
21
|
+
const toolService = (
|
|
22
|
+
this instanceof ToolsService ? this : services().Tools
|
|
23
|
+
) as ToolsService;
|
|
24
|
+
const context = toolService.getContext();
|
|
25
|
+
|
|
19
26
|
if (!filePath || content === undefined) {
|
|
20
27
|
throw new Error(
|
|
21
28
|
"File path and content are both required. Make sure you write small chunks of content, otherwise you may hit output limits."
|
|
22
29
|
);
|
|
23
30
|
}
|
|
24
31
|
|
|
32
|
+
// Read original content for event emission
|
|
33
|
+
let originalContent = "";
|
|
34
|
+
try {
|
|
35
|
+
if (fs.existsSync(filePath)) {
|
|
36
|
+
originalContent = fs.readFileSync(filePath, "utf8");
|
|
37
|
+
}
|
|
38
|
+
} catch (error) {
|
|
39
|
+
// If we can't read the original file, continue with empty string
|
|
40
|
+
originalContent = "";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Emit pre-edit blocking event
|
|
44
|
+
if (context.Events) {
|
|
45
|
+
await context.Events.emitBlocking("file:pre-edit", {
|
|
46
|
+
filePath,
|
|
47
|
+
operation: isContinuing ? "append" : "write",
|
|
48
|
+
content,
|
|
49
|
+
originalContent,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
25
53
|
if (!isContinuing) {
|
|
26
54
|
fs.writeFileSync(filePath, content);
|
|
27
55
|
}
|
|
@@ -42,6 +70,33 @@ export async function writeFileChunk(
|
|
|
42
70
|
|
|
43
71
|
if (isDone) {
|
|
44
72
|
message = " File write complete. Use readFile to verify";
|
|
73
|
+
|
|
74
|
+
// Emit post-edit blocking event to get event results
|
|
75
|
+
let eventResults: any[] = [];
|
|
76
|
+
if (context.Events) {
|
|
77
|
+
// Read updated content for event emission
|
|
78
|
+
const updatedContent = fs.readFileSync(filePath, "utf8");
|
|
79
|
+
|
|
80
|
+
eventResults = await context.Events.emitBlocking("file:post-edit", {
|
|
81
|
+
filePath,
|
|
82
|
+
operation: "write",
|
|
83
|
+
content,
|
|
84
|
+
originalContent,
|
|
85
|
+
updatedContent,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Format event results
|
|
90
|
+
let eventResultsText = "";
|
|
91
|
+
if (eventResults && eventResults.length > 0) {
|
|
92
|
+
if (eventResults.length > 0) {
|
|
93
|
+
eventResultsText =
|
|
94
|
+
"\n\nAdditional Information:\n" +
|
|
95
|
+
JSON.stringify(eventResults, null, 2);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
message += eventResultsText;
|
|
45
100
|
}
|
|
46
101
|
|
|
47
102
|
return message;
|
|
@@ -364,11 +364,13 @@ export class YcmdServer {
|
|
|
364
364
|
*/
|
|
365
365
|
private async waitForServerStart(): Promise<YcmdServerInfo> {
|
|
366
366
|
return new Promise((resolve, reject) => {
|
|
367
|
+
let timedOut = false;
|
|
367
368
|
const timeout = setTimeout(() => {
|
|
368
369
|
console.log(
|
|
369
370
|
"ycmd server startup timeout - server failed to start within 30 seconds"
|
|
370
371
|
);
|
|
371
372
|
reject(new Error("ycmd server failed to start within timeout"));
|
|
373
|
+
timedOut = true;
|
|
372
374
|
}, 30000);
|
|
373
375
|
|
|
374
376
|
const host = "127.0.0.1";
|
|
@@ -378,6 +380,10 @@ export class YcmdServer {
|
|
|
378
380
|
// Check for server readiness
|
|
379
381
|
const checkReady = async () => {
|
|
380
382
|
try {
|
|
383
|
+
if (timedOut) {
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
|
|
381
387
|
const port = getPort();
|
|
382
388
|
console.log(`Checking ycmd server health on port ${port}`);
|
|
383
389
|
|
|
@@ -450,18 +456,22 @@ export class YcmdServer {
|
|
|
450
456
|
private setupExitHandler(): void {
|
|
451
457
|
// Handle normal process exit
|
|
452
458
|
process.on("exit", () => this.forceCleanup());
|
|
453
|
-
|
|
459
|
+
|
|
454
460
|
// Handle Ctrl+C (SIGINT)
|
|
455
461
|
process.on("SIGINT", () => {
|
|
456
|
-
console.log(
|
|
462
|
+
console.log(
|
|
463
|
+
"\nReceived SIGINT (Ctrl+C), shutting down ycmd server gracefully..."
|
|
464
|
+
);
|
|
457
465
|
this.gracefulShutdown().finally(() => {
|
|
458
466
|
process.exit(0);
|
|
459
467
|
});
|
|
460
468
|
});
|
|
461
|
-
|
|
469
|
+
|
|
462
470
|
// Handle SIGTERM (termination signal)
|
|
463
471
|
process.on("SIGTERM", () => {
|
|
464
|
-
console.log(
|
|
472
|
+
console.log(
|
|
473
|
+
"\nReceived SIGTERM, shutting down ycmd server gracefully..."
|
|
474
|
+
);
|
|
465
475
|
this.gracefulShutdown().finally(() => {
|
|
466
476
|
process.exit(0);
|
|
467
477
|
});
|
|
@@ -17,7 +17,7 @@ import { recordAudio, voiceToText } from "../microphone";
|
|
|
17
17
|
import editor from "@inquirer/editor";
|
|
18
18
|
import fs from "fs";
|
|
19
19
|
import path from "path";
|
|
20
|
-
import {
|
|
20
|
+
import { services } from "../services";
|
|
21
21
|
|
|
22
22
|
export class CliChatService implements ChatService {
|
|
23
23
|
private context: ChatContext;
|
|
@@ -44,6 +44,10 @@ export class CliChatService implements ChatService {
|
|
|
44
44
|
this.loadInputHistory();
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
getModuleByName(name: string) {
|
|
48
|
+
return this.modules.find((module) => module.name === "agent");
|
|
49
|
+
}
|
|
50
|
+
|
|
47
51
|
/**
|
|
48
52
|
* Load input history from disk for scrollback functionality
|
|
49
53
|
*/
|
|
@@ -239,6 +243,7 @@ export class CliChatService implements ChatService {
|
|
|
239
243
|
plugins: string[] = [],
|
|
240
244
|
chatHistory: ChatInteraction[] = []
|
|
241
245
|
) {
|
|
246
|
+
const { Plugins } = services();
|
|
242
247
|
const pluginText = await Plugins.callMany(plugins, input);
|
|
243
248
|
const historyMessage = `<PreviousChats>
|
|
244
249
|
This information is provided as historical context and is likely not related to the current task:
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
} from "../../processors/index";
|
|
21
21
|
import { TaskInfo, ChatSession } from "../types";
|
|
22
22
|
import { agents } from "../../agents";
|
|
23
|
+
import { ToolCallEvent } from "src/agents/base/base";
|
|
23
24
|
|
|
24
25
|
export class AgentModule extends BaseChatModule {
|
|
25
26
|
name = "agent";
|
|
@@ -535,9 +536,9 @@ ${reason}
|
|
|
535
536
|
messageId: session.knowhowMessageId,
|
|
536
537
|
existingKnowhowTaskId: session.knowhowTaskId,
|
|
537
538
|
chatHistory: [],
|
|
538
|
-
run:
|
|
539
|
+
run: false, // Don't run yet, we need to set up event listeners first
|
|
539
540
|
});
|
|
540
|
-
await this.attachedAgentChatLoop(taskId, agent);
|
|
541
|
+
await this.attachedAgentChatLoop(taskId, agent, resumePrompt);
|
|
541
542
|
} catch (error) {
|
|
542
543
|
console.error(
|
|
543
544
|
`Failed to resume session ${sessionId}:`,
|
|
@@ -549,11 +550,26 @@ ${reason}
|
|
|
549
550
|
async handleInput(input: string, context: ChatContext): Promise<boolean> {
|
|
550
551
|
// If in agent mode, start agent with the input as initial task (like original chat.ts)
|
|
551
552
|
if (context.agentMode && context.selectedAgent) {
|
|
552
|
-
|
|
553
|
+
// Create initial interaction for the chatHistory
|
|
554
|
+
const initialInteraction: ChatInteraction = {
|
|
555
|
+
input,
|
|
556
|
+
output: "", // Will be filled after agent completion
|
|
557
|
+
summaries: [],
|
|
558
|
+
lastThread: [],
|
|
559
|
+
};
|
|
560
|
+
|
|
561
|
+
const { result, finalOutput } = await this.startAgent(
|
|
553
562
|
context.selectedAgent,
|
|
554
563
|
input,
|
|
555
564
|
context.chatHistory || []
|
|
556
565
|
);
|
|
566
|
+
|
|
567
|
+
// Update the chatHistory with the completed interaction
|
|
568
|
+
if (result && finalOutput) {
|
|
569
|
+
initialInteraction.output = finalOutput;
|
|
570
|
+
context.chatHistory.push(initialInteraction);
|
|
571
|
+
}
|
|
572
|
+
|
|
557
573
|
return result;
|
|
558
574
|
}
|
|
559
575
|
return false;
|
|
@@ -593,6 +609,17 @@ ${reason}
|
|
|
593
609
|
let knowhowTaskId: string | undefined;
|
|
594
610
|
|
|
595
611
|
try {
|
|
612
|
+
// Get context for plugins
|
|
613
|
+
const context = this.chatService?.getContext();
|
|
614
|
+
const plugins = context?.plugins || [];
|
|
615
|
+
|
|
616
|
+
// Format the prompt with plugins and chat history
|
|
617
|
+
const formattedPrompt = await this.chatService.formatChatInput(
|
|
618
|
+
input,
|
|
619
|
+
plugins,
|
|
620
|
+
chatHistory
|
|
621
|
+
);
|
|
622
|
+
|
|
596
623
|
// Create task info object
|
|
597
624
|
let taskInfo: TaskInfo = {
|
|
598
625
|
taskId,
|
|
@@ -601,6 +628,7 @@ ${reason}
|
|
|
601
628
|
agentName,
|
|
602
629
|
agent,
|
|
603
630
|
initialInput: input,
|
|
631
|
+
formattedPrompt,
|
|
604
632
|
status: "running",
|
|
605
633
|
startTime: Date.now(),
|
|
606
634
|
totalCost: 0,
|
|
@@ -637,25 +665,28 @@ ${reason}
|
|
|
637
665
|
}
|
|
638
666
|
|
|
639
667
|
// Set up session update listener
|
|
640
|
-
agent.agentEvents.on(
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
668
|
+
agent.agentEvents.on(
|
|
669
|
+
agent.eventTypes.threadUpdate,
|
|
670
|
+
async (threadState) => {
|
|
671
|
+
// Update task cost from agent's current total cost
|
|
672
|
+
taskInfo.totalCost = agent.getTotalCostUsd();
|
|
673
|
+
this.updateSession(taskId, threadState);
|
|
674
|
+
|
|
675
|
+
// Update Knowhow chat task if created
|
|
676
|
+
if (knowhowTaskId && options.messageId && baseUrl) {
|
|
677
|
+
await client
|
|
678
|
+
.updateChatTask(knowhowTaskId, {
|
|
679
|
+
threads: agent.getThreads(),
|
|
680
|
+
totalCostUsd: agent.getTotalCostUsd(),
|
|
681
|
+
inProgress: true,
|
|
682
|
+
})
|
|
683
|
+
.catch((error) => {
|
|
684
|
+
console.error(`❌ Failed to update Knowhow chat task:`, error);
|
|
685
|
+
});
|
|
686
|
+
console.log(`✅ Updated Knowhow chat task: ${knowhowTaskId}`);
|
|
687
|
+
}
|
|
657
688
|
}
|
|
658
|
-
|
|
689
|
+
);
|
|
659
690
|
|
|
660
691
|
console.log(
|
|
661
692
|
Marked.parse(`**Starting ${agent.name} with task ID: ${taskId}...**`)
|
|
@@ -663,7 +694,7 @@ ${reason}
|
|
|
663
694
|
console.log(Marked.parse(`**Task:** ${input}`));
|
|
664
695
|
|
|
665
696
|
// Initialize new task
|
|
666
|
-
await agent.newTask();
|
|
697
|
+
await agent.newTask(taskId);
|
|
667
698
|
|
|
668
699
|
if (options.model) {
|
|
669
700
|
console.log("Setting model:", options.model);
|
|
@@ -673,17 +704,6 @@ ${reason}
|
|
|
673
704
|
]);
|
|
674
705
|
}
|
|
675
706
|
|
|
676
|
-
// Get context for plugins
|
|
677
|
-
const context = this.chatService?.getContext();
|
|
678
|
-
const plugins = context?.plugins || [];
|
|
679
|
-
|
|
680
|
-
// Format the prompt with plugins and chat history
|
|
681
|
-
const formattedPrompt = await this.chatService.formatChatInput(
|
|
682
|
-
input,
|
|
683
|
-
plugins,
|
|
684
|
-
chatHistory
|
|
685
|
-
);
|
|
686
|
-
|
|
687
707
|
// Set up message processors like in original startAgent
|
|
688
708
|
|
|
689
709
|
agent.messageProcessor.setProcessors("pre_call", [
|
|
@@ -700,15 +720,33 @@ ${reason}
|
|
|
700
720
|
]);
|
|
701
721
|
|
|
702
722
|
// Set up event listeners
|
|
723
|
+
if (!agent.agentEvents.listenerCount(agent.eventTypes.toolCall)) {
|
|
724
|
+
agent.agentEvents.on(
|
|
725
|
+
agent.eventTypes.toolCall,
|
|
726
|
+
(responseMsg: ToolCallEvent) => {
|
|
727
|
+
console.time(JSON.stringify(responseMsg.toolCall.function.name));
|
|
728
|
+
console.log(
|
|
729
|
+
` 🔨 Tool: ${responseMsg.toolCall.function.name}\n Args: ${responseMsg.toolCall.function.arguments}\n`
|
|
730
|
+
);
|
|
731
|
+
}
|
|
732
|
+
);
|
|
733
|
+
}
|
|
703
734
|
if (!agent.agentEvents.listenerCount(agent.eventTypes.toolUsed)) {
|
|
704
|
-
agent.agentEvents.on(
|
|
705
|
-
|
|
706
|
-
|
|
735
|
+
agent.agentEvents.on(
|
|
736
|
+
agent.eventTypes.toolUsed,
|
|
737
|
+
(responseMsg: ToolCallEvent) => {
|
|
738
|
+
console.timeEnd(JSON.stringify(responseMsg.toolCall.function.name));
|
|
739
|
+
console.log(
|
|
740
|
+
` 🔨 Tool Response:
|
|
741
|
+
${JSON.stringify(responseMsg.functionResp, null, 2)}`
|
|
742
|
+
);
|
|
743
|
+
}
|
|
744
|
+
);
|
|
707
745
|
}
|
|
708
746
|
|
|
709
747
|
const taskCompleted = new Promise<string>((resolve) => {
|
|
710
748
|
agent.agentEvents.once(agent.eventTypes.done, async (doneMsg) => {
|
|
711
|
-
console.log("Agent has
|
|
749
|
+
console.log("Agent has completed the task.");
|
|
712
750
|
done = true;
|
|
713
751
|
output = doneMsg || "No response from the AI";
|
|
714
752
|
// Update task info
|
|
@@ -767,7 +805,13 @@ ${reason}
|
|
|
767
805
|
agent.call(formattedPrompt);
|
|
768
806
|
}
|
|
769
807
|
|
|
770
|
-
return {
|
|
808
|
+
return {
|
|
809
|
+
agent,
|
|
810
|
+
taskId,
|
|
811
|
+
formattedPrompt,
|
|
812
|
+
initialInput: input,
|
|
813
|
+
taskCompleted,
|
|
814
|
+
};
|
|
771
815
|
} catch (error) {
|
|
772
816
|
console.error("Agent setup failed:", error);
|
|
773
817
|
this.taskRegistry.delete(taskId);
|
|
@@ -809,11 +853,11 @@ ${reason}
|
|
|
809
853
|
.replace(/[^\w\s]/g, "")
|
|
810
854
|
.split(/\s+/)
|
|
811
855
|
.filter((word) => word.length > 2)
|
|
812
|
-
.slice(0,
|
|
856
|
+
.slice(0, 9);
|
|
813
857
|
|
|
814
858
|
const wordPart = words.join("-") || "task";
|
|
815
|
-
const
|
|
816
|
-
return `${
|
|
859
|
+
const epochSeconds = Math.floor(Date.now() / 1000);
|
|
860
|
+
return `${epochSeconds}-${wordPart}`;
|
|
817
861
|
}
|
|
818
862
|
|
|
819
863
|
/**
|
|
@@ -887,47 +931,67 @@ ${reason}
|
|
|
887
931
|
selectedAgent: BaseAgent,
|
|
888
932
|
initialInput: string,
|
|
889
933
|
chatHistory: ChatInteraction[] = []
|
|
890
|
-
): Promise<boolean> {
|
|
934
|
+
): Promise<{ result: boolean; finalOutput?: string }> {
|
|
891
935
|
try {
|
|
892
|
-
const { agent, taskId } = await this.setupAgent({
|
|
936
|
+
const { agent, taskId, formattedPrompt } = await this.setupAgent({
|
|
893
937
|
agentName: selectedAgent.name,
|
|
894
938
|
input: initialInput,
|
|
895
939
|
chatHistory,
|
|
896
|
-
run:
|
|
940
|
+
run: false, // Don't run yet, we need to set up event listeners first
|
|
897
941
|
});
|
|
898
|
-
|
|
942
|
+
const result = await this.attachedAgentChatLoop(
|
|
943
|
+
taskId,
|
|
944
|
+
agent,
|
|
945
|
+
formattedPrompt
|
|
946
|
+
);
|
|
947
|
+
return result;
|
|
899
948
|
} catch (error) {
|
|
900
949
|
console.error("Error starting agent:", error);
|
|
901
|
-
return false;
|
|
950
|
+
return { result: false, finalOutput: "Error starting agent" };
|
|
902
951
|
}
|
|
903
952
|
}
|
|
904
953
|
|
|
905
|
-
async attachedAgentChatLoop(
|
|
954
|
+
async attachedAgentChatLoop(
|
|
955
|
+
taskId: string,
|
|
956
|
+
agent: BaseAgent,
|
|
957
|
+
initialInput?: string
|
|
958
|
+
): Promise<{ result: boolean; finalOutput?: string }> {
|
|
906
959
|
try {
|
|
907
960
|
let done = false;
|
|
908
961
|
let output = "Done";
|
|
962
|
+
let agentFinalOutput: string | undefined;
|
|
909
963
|
|
|
910
964
|
// Define available commands
|
|
911
|
-
const commands = ["pause", "unpause", "kill", "detach"];
|
|
965
|
+
const commands = ["/pause", "/unpause", "/kill", "/detach", "/done"];
|
|
912
966
|
const history: string[] = [];
|
|
913
967
|
|
|
914
|
-
|
|
915
|
-
(await this.chatService?.getInput(
|
|
916
|
-
`Enter command or message for ${agent.name}: `,
|
|
917
|
-
commands
|
|
918
|
-
)) || "";
|
|
919
|
-
|
|
920
|
-
history.push(input);
|
|
921
|
-
|
|
968
|
+
// Set up the event listener BEFORE starting the agent to avoid race condition
|
|
922
969
|
let finished = false;
|
|
923
970
|
const donePromise = new Promise<string>((resolve) => {
|
|
924
971
|
agent.agentEvents.once(agent.eventTypes.done, (doneMsg) => {
|
|
925
|
-
|
|
972
|
+
// Capture the agent's final output
|
|
973
|
+
agentFinalOutput = doneMsg || "No response from the AI";
|
|
926
974
|
finished = true;
|
|
927
975
|
resolve("done");
|
|
928
976
|
});
|
|
929
977
|
});
|
|
930
978
|
|
|
979
|
+
// Now start the agent if we have an initial input (this means we're starting, not just attaching)
|
|
980
|
+
if (initialInput) {
|
|
981
|
+
const taskInfo = this.taskRegistry.get(taskId);
|
|
982
|
+
agent.call(
|
|
983
|
+
taskInfo?.formattedPrompt || taskInfo?.initialInput || initialInput
|
|
984
|
+
);
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
let input =
|
|
988
|
+
(await this.chatService?.getInput(
|
|
989
|
+
`Enter command or message for ${agent.name}: `,
|
|
990
|
+
commands
|
|
991
|
+
)) || "";
|
|
992
|
+
|
|
993
|
+
history.push(input);
|
|
994
|
+
|
|
931
995
|
while (!done) {
|
|
932
996
|
switch (input) {
|
|
933
997
|
case "":
|
|
@@ -936,26 +1000,26 @@ ${reason}
|
|
|
936
1000
|
done = true;
|
|
937
1001
|
}
|
|
938
1002
|
break;
|
|
939
|
-
case "done":
|
|
1003
|
+
case "/done":
|
|
940
1004
|
output = "Exited agent interaction.";
|
|
941
1005
|
done = true;
|
|
942
1006
|
break;
|
|
943
|
-
case "pause":
|
|
1007
|
+
case "/pause":
|
|
944
1008
|
await agent.pause();
|
|
945
1009
|
console.log("Agent paused.");
|
|
946
1010
|
break;
|
|
947
|
-
case "unpause":
|
|
1011
|
+
case "/unpause":
|
|
948
1012
|
await agent.unpause();
|
|
949
1013
|
console.log("Agent unpaused.");
|
|
950
1014
|
break;
|
|
951
|
-
case "kill":
|
|
1015
|
+
case "/kill":
|
|
952
1016
|
await agent.kill();
|
|
953
1017
|
console.log("Agent terminated.");
|
|
954
1018
|
done = true;
|
|
955
1019
|
break;
|
|
956
|
-
case "detach":
|
|
1020
|
+
case "/detach":
|
|
957
1021
|
console.log("Detached from agent");
|
|
958
|
-
return true;
|
|
1022
|
+
return { result: true, finalOutput: agentFinalOutput };
|
|
959
1023
|
default:
|
|
960
1024
|
agent.addPendingUserMessage({
|
|
961
1025
|
role: "user",
|
|
@@ -981,12 +1045,10 @@ ${reason}
|
|
|
981
1045
|
finalTaskInfo.endTime = Date.now();
|
|
982
1046
|
}
|
|
983
1047
|
}
|
|
984
|
-
|
|
985
|
-
return true;
|
|
1048
|
+
return { result: true, finalOutput: agentFinalOutput };
|
|
986
1049
|
} catch (error) {
|
|
987
1050
|
console.error("Agent execution failed:", error);
|
|
988
|
-
|
|
989
|
-
return false;
|
|
1051
|
+
return { result: false, finalOutput: "Error during agent execution" };
|
|
990
1052
|
}
|
|
991
1053
|
}
|
|
992
1054
|
}
|
|
@@ -7,7 +7,6 @@ import { ChatCommand, ChatMode, ChatContext } from "../types";
|
|
|
7
7
|
import { ChatInteraction } from "../../types";
|
|
8
8
|
import { Models } from "../../ai";
|
|
9
9
|
import { services } from "../../services/index";
|
|
10
|
-
import { Plugins } from "../../plugins/plugins";
|
|
11
10
|
import { Marked } from "../../utils/index";
|
|
12
11
|
|
|
13
12
|
export class AskModule extends BaseChatModule {
|
|
@@ -167,13 +167,13 @@ export class SetupModule extends BaseChatModule {
|
|
|
167
167
|
) {
|
|
168
168
|
// Launch Setup agent to guide user through configuration
|
|
169
169
|
if (this.agentModule) {
|
|
170
|
+
const initialInput = "Help me set up my Knowhow configuration with the missing features and optimize my setup.";
|
|
170
171
|
const { taskId, agent } = await this.agentModule.setupAgent({
|
|
171
172
|
agentName: "Setup",
|
|
172
|
-
run:
|
|
173
|
-
input:
|
|
174
|
-
"Help me set up my Knowhow configuration with the missing features and optimize my setup.",
|
|
173
|
+
run: false,
|
|
174
|
+
input: initialInput,
|
|
175
175
|
});
|
|
176
|
-
await this.agentModule.attachedAgentChatLoop(taskId, agent);
|
|
176
|
+
await this.agentModule.attachedAgentChatLoop(taskId, agent, initialInput);
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
} else {
|
|
@@ -3,6 +3,7 @@ import { CliChatService } from "../CliChatService";
|
|
|
3
3
|
import { ChatCommand, ChatMode, ChatContext } from "../types";
|
|
4
4
|
import { ask } from "../../utils";
|
|
5
5
|
import { services } from "../../services";
|
|
6
|
+
import { Models } from "../../types";
|
|
6
7
|
|
|
7
8
|
export class SystemModule extends BaseChatModule {
|
|
8
9
|
name = "system";
|
|
@@ -56,8 +57,18 @@ export class SystemModule extends BaseChatModule {
|
|
|
56
57
|
currentModel: selectedModel,
|
|
57
58
|
currentProvider,
|
|
58
59
|
});
|
|
59
|
-
|
|
60
60
|
console.log(`Model set to: ${selectedModel}`);
|
|
61
|
+
|
|
62
|
+
// Update currently active agent if any
|
|
63
|
+
if (context?.selectedAgent) {
|
|
64
|
+
console.log(
|
|
65
|
+
`Updating active agent ${context.currentAgent} model to: ${selectedModel}`
|
|
66
|
+
);
|
|
67
|
+
context?.selectedAgent?.updatePreferences({
|
|
68
|
+
model: selectedModel,
|
|
69
|
+
provider: currentProvider as any,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
61
72
|
}
|
|
62
73
|
|
|
63
74
|
async handleProviderCommand(args: string[]): Promise<void> {
|
|
@@ -77,10 +88,10 @@ export class SystemModule extends BaseChatModule {
|
|
|
77
88
|
|
|
78
89
|
// Get default model for new provider
|
|
79
90
|
const ChatModelDefaults = {
|
|
80
|
-
openai:
|
|
81
|
-
anthropic:
|
|
82
|
-
google:
|
|
83
|
-
xai:
|
|
91
|
+
openai: Models.openai.GPT_5,
|
|
92
|
+
anthropic: Models.anthropic.Sonnet4,
|
|
93
|
+
google: Models.google.Gemini_25_Flash_Preview,
|
|
94
|
+
xai: Models.xai.GrokCodeFast,
|
|
84
95
|
};
|
|
85
96
|
|
|
86
97
|
const newModel =
|
|
@@ -95,6 +106,18 @@ export class SystemModule extends BaseChatModule {
|
|
|
95
106
|
console.log(
|
|
96
107
|
`Provider set to: ${selectedProvider}, Model set to: ${newModel}`
|
|
97
108
|
);
|
|
109
|
+
|
|
110
|
+
// Update currently active agent if any
|
|
111
|
+
if (context?.selectedAgent) {
|
|
112
|
+
console.log(
|
|
113
|
+
`Updating active agent ${context.currentAgent} provider to: ${selectedProvider} and model to: ${newModel}`
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
context?.selectedAgent?.updatePreferences({
|
|
117
|
+
model: newModel,
|
|
118
|
+
provider: selectedProvider as any,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
98
121
|
}
|
|
99
122
|
|
|
100
123
|
async handleDebugCommand(args: string[]): Promise<void> {
|
package/src/chat/types.ts
CHANGED
|
@@ -14,6 +14,7 @@ export interface ChatContext {
|
|
|
14
14
|
currentModel?: string;
|
|
15
15
|
currentProvider?: string;
|
|
16
16
|
inputMethod?: InputMethod;
|
|
17
|
+
selectedAgent?: BaseAgent;
|
|
17
18
|
[key: string]: any;
|
|
18
19
|
}
|
|
19
20
|
|
|
@@ -68,6 +69,7 @@ export interface TaskInfo {
|
|
|
68
69
|
agentName: string;
|
|
69
70
|
agent: BaseAgent;
|
|
70
71
|
initialInput: string;
|
|
72
|
+
formattedPrompt: string;
|
|
71
73
|
status: "running" | "paused" | "completed" | "failed";
|
|
72
74
|
startTime: number;
|
|
73
75
|
endTime?: number;
|
package/src/chat-old.ts
CHANGED
|
@@ -10,9 +10,8 @@ import {
|
|
|
10
10
|
} from "./types";
|
|
11
11
|
import { Marked } from "./utils";
|
|
12
12
|
import { ask } from "./utils";
|
|
13
|
-
import {
|
|
13
|
+
import { services } from "./services";
|
|
14
14
|
import { queryEmbedding, getConfiguredEmbeddingMap } from "./embeddings";
|
|
15
|
-
import { services } from "./services/";
|
|
16
15
|
import { FlagsService } from "./services/flags";
|
|
17
16
|
import { IAgent } from "./agents/interface";
|
|
18
17
|
import { Message } from "./clients";
|
|
@@ -165,6 +164,7 @@ export async function formatChatInput(
|
|
|
165
164
|
plugins: string[] = [],
|
|
166
165
|
chatHistory: ChatInteraction[] = []
|
|
167
166
|
) {
|
|
167
|
+
const { Plugins } = services();
|
|
168
168
|
const pluginText = await Plugins.callMany(plugins, input);
|
|
169
169
|
const historyMessage = `<PreviousChats>
|
|
170
170
|
This information is provided as historical context and is likely not related to the current task:
|
package/src/clients/anthropic.ts
CHANGED
|
@@ -151,6 +151,15 @@ export class GenericAnthropicClient implements GenericClient {
|
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
+
tryParse(str: string): any {
|
|
155
|
+
try {
|
|
156
|
+
return JSON.parse(str);
|
|
157
|
+
} catch (e) {
|
|
158
|
+
console.error("Invalid JSON from tool call", str);
|
|
159
|
+
return {};
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
154
163
|
transformMessages(messages: Message[]): MessageParam[] {
|
|
155
164
|
const toolCalls = messages.flatMap((msg) => msg.tool_calls || []);
|
|
156
165
|
const claudeMessages: MessageParam[] = messages
|
|
@@ -173,7 +182,7 @@ export class GenericAnthropicClient implements GenericClient {
|
|
|
173
182
|
type: "tool_use",
|
|
174
183
|
id: msg.tool_call_id,
|
|
175
184
|
name: toolCall.function.name,
|
|
176
|
-
input:
|
|
185
|
+
input: this.tryParse(toolCall.function.arguments),
|
|
177
186
|
},
|
|
178
187
|
],
|
|
179
188
|
});
|
|
@@ -332,6 +341,18 @@ export class GenericAnthropicClient implements GenericClient {
|
|
|
332
341
|
cache_hit: 0.3,
|
|
333
342
|
output: 15.0,
|
|
334
343
|
},
|
|
344
|
+
[Models.anthropic.Sonnet4_5]: {
|
|
345
|
+
input: 3.0,
|
|
346
|
+
cache_write: 3.75,
|
|
347
|
+
cache_hit: 0.3,
|
|
348
|
+
output: 15.0,
|
|
349
|
+
},
|
|
350
|
+
[Models.anthropic.Haiku4_5]: {
|
|
351
|
+
input: 1,
|
|
352
|
+
cache_write: 1.25,
|
|
353
|
+
cache_hit: 0.1,
|
|
354
|
+
output: 5,
|
|
355
|
+
},
|
|
335
356
|
[Models.anthropic.Sonnet3_7]: {
|
|
336
357
|
input: 3.0,
|
|
337
358
|
cache_write: 3.75,
|
package/src/clients/openai.ts
CHANGED
|
@@ -29,7 +29,7 @@ export class GenericOpenAiClient implements GenericClient {
|
|
|
29
29
|
this.apiKey = apiKey;
|
|
30
30
|
this.client = new OpenAI({
|
|
31
31
|
apiKey,
|
|
32
|
-
...(config
|
|
32
|
+
...(config?.openaiBaseUrl && { baseURL: config.openaiBaseUrl }),
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
|