@tyvm/knowhow 0.0.46 → 0.0.48
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 +30 -24
- 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 +107 -64
- 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/types.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 +6 -4
- 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 +19 -7
- package/src/processors/TokenCompressor.ts +13 -13
- package/src/processors/ToolResponseCache.ts +15 -6
- 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 +430 -0
- package/tests/processors/HarmonyToolProcessor.test.ts +490 -0
- package/tests/processors/TokenCompressor.test.ts +391 -0
- package/tests/processors/ToolResponseCache.test.ts +688 -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 +2 -2
- package/ts_build/src/agents/base/base.js +24 -20
- 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 +53 -31
- 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/types.d.ts +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 +7 -9
- 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 +12 -3
- package/ts_build/src/processors/CustomVariables.js.map +1 -1
- package/ts_build/src/processors/TokenCompressor.js +8 -11
- 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 +12 -2
- 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 +351 -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 +300 -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 +539 -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:
|
|
@@ -535,9 +535,9 @@ ${reason}
|
|
|
535
535
|
messageId: session.knowhowMessageId,
|
|
536
536
|
existingKnowhowTaskId: session.knowhowTaskId,
|
|
537
537
|
chatHistory: [],
|
|
538
|
-
run:
|
|
538
|
+
run: false, // Don't run yet, we need to set up event listeners first
|
|
539
539
|
});
|
|
540
|
-
await this.attachedAgentChatLoop(taskId, agent);
|
|
540
|
+
await this.attachedAgentChatLoop(taskId, agent, resumePrompt);
|
|
541
541
|
} catch (error) {
|
|
542
542
|
console.error(
|
|
543
543
|
`Failed to resume session ${sessionId}:`,
|
|
@@ -549,11 +549,26 @@ ${reason}
|
|
|
549
549
|
async handleInput(input: string, context: ChatContext): Promise<boolean> {
|
|
550
550
|
// If in agent mode, start agent with the input as initial task (like original chat.ts)
|
|
551
551
|
if (context.agentMode && context.selectedAgent) {
|
|
552
|
-
|
|
552
|
+
// Create initial interaction for the chatHistory
|
|
553
|
+
const initialInteraction: ChatInteraction = {
|
|
554
|
+
input,
|
|
555
|
+
output: "", // Will be filled after agent completion
|
|
556
|
+
summaries: [],
|
|
557
|
+
lastThread: [],
|
|
558
|
+
};
|
|
559
|
+
|
|
560
|
+
const { result, finalOutput } = await this.startAgent(
|
|
553
561
|
context.selectedAgent,
|
|
554
562
|
input,
|
|
555
563
|
context.chatHistory || []
|
|
556
564
|
);
|
|
565
|
+
|
|
566
|
+
// Update the chatHistory with the completed interaction
|
|
567
|
+
if (result && finalOutput) {
|
|
568
|
+
initialInteraction.output = finalOutput;
|
|
569
|
+
context.chatHistory.push(initialInteraction);
|
|
570
|
+
}
|
|
571
|
+
|
|
557
572
|
return result;
|
|
558
573
|
}
|
|
559
574
|
return false;
|
|
@@ -593,6 +608,17 @@ ${reason}
|
|
|
593
608
|
let knowhowTaskId: string | undefined;
|
|
594
609
|
|
|
595
610
|
try {
|
|
611
|
+
// Get context for plugins
|
|
612
|
+
const context = this.chatService?.getContext();
|
|
613
|
+
const plugins = context?.plugins || [];
|
|
614
|
+
|
|
615
|
+
// Format the prompt with plugins and chat history
|
|
616
|
+
const formattedPrompt = await this.chatService.formatChatInput(
|
|
617
|
+
input,
|
|
618
|
+
plugins,
|
|
619
|
+
chatHistory
|
|
620
|
+
);
|
|
621
|
+
|
|
596
622
|
// Create task info object
|
|
597
623
|
let taskInfo: TaskInfo = {
|
|
598
624
|
taskId,
|
|
@@ -601,6 +627,7 @@ ${reason}
|
|
|
601
627
|
agentName,
|
|
602
628
|
agent,
|
|
603
629
|
initialInput: input,
|
|
630
|
+
formattedPrompt,
|
|
604
631
|
status: "running",
|
|
605
632
|
startTime: Date.now(),
|
|
606
633
|
totalCost: 0,
|
|
@@ -637,25 +664,28 @@ ${reason}
|
|
|
637
664
|
}
|
|
638
665
|
|
|
639
666
|
// 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
|
-
|
|
667
|
+
agent.agentEvents.on(
|
|
668
|
+
agent.eventTypes.threadUpdate,
|
|
669
|
+
async (threadState) => {
|
|
670
|
+
// Update task cost from agent's current total cost
|
|
671
|
+
taskInfo.totalCost = agent.getTotalCostUsd();
|
|
672
|
+
this.updateSession(taskId, threadState);
|
|
673
|
+
|
|
674
|
+
// Update Knowhow chat task if created
|
|
675
|
+
if (knowhowTaskId && options.messageId && baseUrl) {
|
|
676
|
+
await client
|
|
677
|
+
.updateChatTask(knowhowTaskId, {
|
|
678
|
+
threads: agent.getThreads(),
|
|
679
|
+
totalCostUsd: agent.getTotalCostUsd(),
|
|
680
|
+
inProgress: true,
|
|
681
|
+
})
|
|
682
|
+
.catch((error) => {
|
|
683
|
+
console.error(`❌ Failed to update Knowhow chat task:`, error);
|
|
684
|
+
});
|
|
685
|
+
console.log(`✅ Updated Knowhow chat task: ${knowhowTaskId}`);
|
|
686
|
+
}
|
|
657
687
|
}
|
|
658
|
-
|
|
688
|
+
);
|
|
659
689
|
|
|
660
690
|
console.log(
|
|
661
691
|
Marked.parse(`**Starting ${agent.name} with task ID: ${taskId}...**`)
|
|
@@ -663,7 +693,7 @@ ${reason}
|
|
|
663
693
|
console.log(Marked.parse(`**Task:** ${input}`));
|
|
664
694
|
|
|
665
695
|
// Initialize new task
|
|
666
|
-
await agent.newTask();
|
|
696
|
+
await agent.newTask(taskId);
|
|
667
697
|
|
|
668
698
|
if (options.model) {
|
|
669
699
|
console.log("Setting model:", options.model);
|
|
@@ -673,17 +703,6 @@ ${reason}
|
|
|
673
703
|
]);
|
|
674
704
|
}
|
|
675
705
|
|
|
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
706
|
// Set up message processors like in original startAgent
|
|
688
707
|
|
|
689
708
|
agent.messageProcessor.setProcessors("pre_call", [
|
|
@@ -708,7 +727,7 @@ ${reason}
|
|
|
708
727
|
|
|
709
728
|
const taskCompleted = new Promise<string>((resolve) => {
|
|
710
729
|
agent.agentEvents.once(agent.eventTypes.done, async (doneMsg) => {
|
|
711
|
-
console.log("Agent has
|
|
730
|
+
console.log("Agent has completed the task.");
|
|
712
731
|
done = true;
|
|
713
732
|
output = doneMsg || "No response from the AI";
|
|
714
733
|
// Update task info
|
|
@@ -767,7 +786,13 @@ ${reason}
|
|
|
767
786
|
agent.call(formattedPrompt);
|
|
768
787
|
}
|
|
769
788
|
|
|
770
|
-
return {
|
|
789
|
+
return {
|
|
790
|
+
agent,
|
|
791
|
+
taskId,
|
|
792
|
+
formattedPrompt,
|
|
793
|
+
initialInput: input,
|
|
794
|
+
taskCompleted,
|
|
795
|
+
};
|
|
771
796
|
} catch (error) {
|
|
772
797
|
console.error("Agent setup failed:", error);
|
|
773
798
|
this.taskRegistry.delete(taskId);
|
|
@@ -809,11 +834,11 @@ ${reason}
|
|
|
809
834
|
.replace(/[^\w\s]/g, "")
|
|
810
835
|
.split(/\s+/)
|
|
811
836
|
.filter((word) => word.length > 2)
|
|
812
|
-
.slice(0,
|
|
837
|
+
.slice(0, 9);
|
|
813
838
|
|
|
814
839
|
const wordPart = words.join("-") || "task";
|
|
815
|
-
const
|
|
816
|
-
return `${
|
|
840
|
+
const epochSeconds = Math.floor(Date.now() / 1000);
|
|
841
|
+
return `${epochSeconds}-${wordPart}`;
|
|
817
842
|
}
|
|
818
843
|
|
|
819
844
|
/**
|
|
@@ -887,47 +912,67 @@ ${reason}
|
|
|
887
912
|
selectedAgent: BaseAgent,
|
|
888
913
|
initialInput: string,
|
|
889
914
|
chatHistory: ChatInteraction[] = []
|
|
890
|
-
): Promise<boolean> {
|
|
915
|
+
): Promise<{ result: boolean; finalOutput?: string }> {
|
|
891
916
|
try {
|
|
892
|
-
const { agent, taskId } = await this.setupAgent({
|
|
917
|
+
const { agent, taskId, formattedPrompt } = await this.setupAgent({
|
|
893
918
|
agentName: selectedAgent.name,
|
|
894
919
|
input: initialInput,
|
|
895
920
|
chatHistory,
|
|
896
|
-
run:
|
|
921
|
+
run: false, // Don't run yet, we need to set up event listeners first
|
|
897
922
|
});
|
|
898
|
-
|
|
923
|
+
const result = await this.attachedAgentChatLoop(
|
|
924
|
+
taskId,
|
|
925
|
+
agent,
|
|
926
|
+
formattedPrompt
|
|
927
|
+
);
|
|
928
|
+
return result;
|
|
899
929
|
} catch (error) {
|
|
900
930
|
console.error("Error starting agent:", error);
|
|
901
|
-
return false;
|
|
931
|
+
return { result: false, finalOutput: "Error starting agent" };
|
|
902
932
|
}
|
|
903
933
|
}
|
|
904
934
|
|
|
905
|
-
async attachedAgentChatLoop(
|
|
935
|
+
async attachedAgentChatLoop(
|
|
936
|
+
taskId: string,
|
|
937
|
+
agent: BaseAgent,
|
|
938
|
+
initialInput?: string
|
|
939
|
+
): Promise<{ result: boolean; finalOutput?: string }> {
|
|
906
940
|
try {
|
|
907
941
|
let done = false;
|
|
908
942
|
let output = "Done";
|
|
943
|
+
let agentFinalOutput: string | undefined;
|
|
909
944
|
|
|
910
945
|
// Define available commands
|
|
911
|
-
const commands = ["pause", "unpause", "kill", "detach"];
|
|
946
|
+
const commands = ["/pause", "/unpause", "/kill", "/detach", "/done"];
|
|
912
947
|
const history: string[] = [];
|
|
913
948
|
|
|
914
|
-
|
|
915
|
-
(await this.chatService?.getInput(
|
|
916
|
-
`Enter command or message for ${agent.name}: `,
|
|
917
|
-
commands
|
|
918
|
-
)) || "";
|
|
919
|
-
|
|
920
|
-
history.push(input);
|
|
921
|
-
|
|
949
|
+
// Set up the event listener BEFORE starting the agent to avoid race condition
|
|
922
950
|
let finished = false;
|
|
923
951
|
const donePromise = new Promise<string>((resolve) => {
|
|
924
952
|
agent.agentEvents.once(agent.eventTypes.done, (doneMsg) => {
|
|
925
|
-
|
|
953
|
+
// Capture the agent's final output
|
|
954
|
+
agentFinalOutput = doneMsg || "No response from the AI";
|
|
926
955
|
finished = true;
|
|
927
956
|
resolve("done");
|
|
928
957
|
});
|
|
929
958
|
});
|
|
930
959
|
|
|
960
|
+
// Now start the agent if we have an initial input (this means we're starting, not just attaching)
|
|
961
|
+
if (initialInput) {
|
|
962
|
+
const taskInfo = this.taskRegistry.get(taskId);
|
|
963
|
+
agent.call(
|
|
964
|
+
taskInfo?.formattedPrompt || taskInfo?.initialInput || initialInput
|
|
965
|
+
);
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
let input =
|
|
969
|
+
(await this.chatService?.getInput(
|
|
970
|
+
`Enter command or message for ${agent.name}: `,
|
|
971
|
+
commands
|
|
972
|
+
)) || "";
|
|
973
|
+
|
|
974
|
+
history.push(input);
|
|
975
|
+
|
|
931
976
|
while (!done) {
|
|
932
977
|
switch (input) {
|
|
933
978
|
case "":
|
|
@@ -936,26 +981,26 @@ ${reason}
|
|
|
936
981
|
done = true;
|
|
937
982
|
}
|
|
938
983
|
break;
|
|
939
|
-
case "done":
|
|
984
|
+
case "/done":
|
|
940
985
|
output = "Exited agent interaction.";
|
|
941
986
|
done = true;
|
|
942
987
|
break;
|
|
943
|
-
case "pause":
|
|
988
|
+
case "/pause":
|
|
944
989
|
await agent.pause();
|
|
945
990
|
console.log("Agent paused.");
|
|
946
991
|
break;
|
|
947
|
-
case "unpause":
|
|
992
|
+
case "/unpause":
|
|
948
993
|
await agent.unpause();
|
|
949
994
|
console.log("Agent unpaused.");
|
|
950
995
|
break;
|
|
951
|
-
case "kill":
|
|
996
|
+
case "/kill":
|
|
952
997
|
await agent.kill();
|
|
953
998
|
console.log("Agent terminated.");
|
|
954
999
|
done = true;
|
|
955
1000
|
break;
|
|
956
|
-
case "detach":
|
|
1001
|
+
case "/detach":
|
|
957
1002
|
console.log("Detached from agent");
|
|
958
|
-
return true;
|
|
1003
|
+
return { result: true, finalOutput: agentFinalOutput };
|
|
959
1004
|
default:
|
|
960
1005
|
agent.addPendingUserMessage({
|
|
961
1006
|
role: "user",
|
|
@@ -981,12 +1026,10 @@ ${reason}
|
|
|
981
1026
|
finalTaskInfo.endTime = Date.now();
|
|
982
1027
|
}
|
|
983
1028
|
}
|
|
984
|
-
|
|
985
|
-
return true;
|
|
1029
|
+
return { result: true, finalOutput: agentFinalOutput };
|
|
986
1030
|
} catch (error) {
|
|
987
1031
|
console.error("Agent execution failed:", error);
|
|
988
|
-
|
|
989
|
-
return false;
|
|
1032
|
+
return { result: false, finalOutput: "Error during agent execution" };
|
|
990
1033
|
}
|
|
991
1034
|
}
|
|
992
1035
|
}
|
|
@@ -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
|
|
package/src/clients/types.ts
CHANGED