@tyvm/knowhow 0.0.47 → 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/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/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
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import { fileExists } from "../../../utils";
|
|
3
|
+
import { services, ToolsService } from "../../../services";
|
|
4
|
+
import { LanguageAgnosticParser } from "../../../plugins/tree-sitter/parser";
|
|
5
|
+
import { TreeEditor } from "../../../plugins/tree-sitter/editor";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* List all available simple paths in a file using tree-sitter AST parsing
|
|
9
|
+
*/
|
|
10
|
+
export async function astListPaths(filePath: string): Promise<string> {
|
|
11
|
+
// Get context from bound ToolsService
|
|
12
|
+
const toolService = (
|
|
13
|
+
this instanceof ToolsService ? this : services().Tools
|
|
14
|
+
) as ToolsService;
|
|
15
|
+
|
|
16
|
+
const context = toolService.getContext();
|
|
17
|
+
|
|
18
|
+
if (context.Events) {
|
|
19
|
+
await context.Events.emitBlocking("file:pre-read", {
|
|
20
|
+
filePath,
|
|
21
|
+
});
|
|
22
|
+
await context.Events.emitNonBlocking("ast:pre-list-paths", {
|
|
23
|
+
filePath,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const exists = await fileExists(filePath);
|
|
28
|
+
if (!exists) {
|
|
29
|
+
throw new Error(`File not found: ${filePath}`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
const content = fs.readFileSync(filePath, "utf8");
|
|
34
|
+
|
|
35
|
+
if (!LanguageAgnosticParser.supportsFile(filePath)) {
|
|
36
|
+
throw new Error(`Unsupported file type for AST parsing: ${filePath}`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const parser = LanguageAgnosticParser.createParserForFile(filePath);
|
|
40
|
+
const editor = new TreeEditor(parser, content);
|
|
41
|
+
const paths = editor.getAllSimplePaths();
|
|
42
|
+
|
|
43
|
+
// Emit post-action event
|
|
44
|
+
if (context.Events) {
|
|
45
|
+
await context.Events.emitNonBlocking("file:post-read", {
|
|
46
|
+
filePath,
|
|
47
|
+
content,
|
|
48
|
+
});
|
|
49
|
+
await context.Events.emitNonBlocking("ast:post-list-paths", {
|
|
50
|
+
filePath,
|
|
51
|
+
paths,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const result = {
|
|
56
|
+
file: filePath,
|
|
57
|
+
language: parser.getLanguage(),
|
|
58
|
+
totalPaths: paths.length,
|
|
59
|
+
paths: paths.sort(),
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
return JSON.stringify(result, null, 2);
|
|
63
|
+
} catch (error: any) {
|
|
64
|
+
throw new Error(`Failed to parse file ${filePath}: ${error.message}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// AST Tools - Tree-sitter based tools for parsing and modifying code structure
|
|
2
|
+
|
|
3
|
+
export { astEditNode } from "./astEditNode";
|
|
4
|
+
export { astAppendNode } from "./astAppendNode";
|
|
5
|
+
export { astDeleteNode } from "./astDeleteNode";
|
|
6
|
+
export { astListPaths } from "./astListPaths";
|
|
7
|
+
export { astGetPathForLine } from "./astGetPathForLine";
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { services } from "../../services";
|
|
2
|
+
import { ToolsService } from "../../services";
|
|
2
3
|
export async function callPlugin(pluginName: string, userInput: string) {
|
|
3
|
-
|
|
4
|
+
// Get context from bound ToolsService
|
|
5
|
+
const toolService = (
|
|
6
|
+
this instanceof ToolsService ? this : services().Tools
|
|
7
|
+
) as ToolsService;
|
|
8
|
+
|
|
9
|
+
return toolService.getContext().Plugins.call(pluginName, userInput);
|
|
4
10
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Tool to search for files related to the user's goal
|
|
2
|
-
import {
|
|
2
|
+
import { services } from "../../services";
|
|
3
3
|
export async function embeddingSearch(keyword: string): Promise<string> {
|
|
4
|
+
const { Plugins } = services();
|
|
4
5
|
return Plugins.call("embeddings", keyword);
|
|
5
6
|
}
|
|
@@ -1,135 +1,280 @@
|
|
|
1
|
-
import { exec } from "child_process";
|
|
1
|
+
import { exec, spawn, ExecException } from "child_process";
|
|
2
2
|
import { promisify } from "util";
|
|
3
|
+
import * as fs from "fs";
|
|
4
|
+
import * as path from "path";
|
|
5
|
+
import * as os from "os";
|
|
3
6
|
|
|
4
7
|
const execAsync = promisify(exec);
|
|
5
8
|
|
|
6
9
|
export interface ExecCommandOptions {
|
|
7
|
-
timeout?: number; //
|
|
8
|
-
continueInBackground?: boolean; //
|
|
9
|
-
|
|
10
|
+
timeout?: number; // ms; -1 = wait indefinitely
|
|
11
|
+
continueInBackground?: boolean; // allow to keep running on timeout
|
|
12
|
+
maxBuffer?: number; // for exec()
|
|
10
13
|
}
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
const execWithTimeout = async (
|
|
14
|
-
command: string,
|
|
15
|
-
options: ExecCommandOptions = {}
|
|
16
|
-
): Promise<{
|
|
15
|
+
type ExecResult = {
|
|
17
16
|
stdout: string;
|
|
18
17
|
stderr: string;
|
|
19
18
|
timedOut: boolean;
|
|
20
19
|
killed: boolean;
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
pid?: number;
|
|
21
|
+
logPath?: string;
|
|
22
|
+
};
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
24
|
+
const PROCESSES_DIR = path.join(process.cwd(), ".knowhow", "processes");
|
|
25
|
+
fs.mkdirSync(PROCESSES_DIR, { recursive: true });
|
|
26
|
+
|
|
27
|
+
const STARTED_PIDS = new Set<number>();
|
|
28
|
+
setupProcessCleanup();
|
|
29
|
+
|
|
30
|
+
// ---------- utils ----------
|
|
31
|
+
function stripTrailingAmp(cmd: string) {
|
|
32
|
+
const t = cmd.trim();
|
|
33
|
+
return t.endsWith("&") ? t.replace(/&\s*$/, "").trim() : t;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function commandNameFrom(cmd: string) {
|
|
37
|
+
const cleaned = stripTrailingAmp(cmd);
|
|
38
|
+
const first = cleaned.split(/\s+/)[0] || "command";
|
|
39
|
+
return first.replace(/[^\w.-]+/g, "_");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function makeLogPath(cmd: string) {
|
|
43
|
+
const name = commandNameFrom(cmd);
|
|
44
|
+
return path.join(PROCESSES_DIR, `${name}.txt`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function setupProcessCleanup() {
|
|
48
|
+
const killAll = () => {
|
|
49
|
+
for (const pid of STARTED_PIDS) {
|
|
50
|
+
try {
|
|
51
|
+
if (os.platform() === "win32") {
|
|
52
|
+
spawn("taskkill", ["/PID", String(pid), "/T", "/F"], {
|
|
53
|
+
stdio: "ignore",
|
|
54
|
+
detached: true,
|
|
55
|
+
}).unref();
|
|
56
|
+
} else {
|
|
57
|
+
try {
|
|
58
|
+
process.kill(-pid, "SIGTERM");
|
|
59
|
+
} catch {
|
|
60
|
+
try {
|
|
61
|
+
process.kill(pid, "SIGTERM");
|
|
62
|
+
} catch {}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
} catch {}
|
|
36
66
|
}
|
|
37
|
-
}
|
|
67
|
+
};
|
|
68
|
+
process.once("exit", killAll);
|
|
69
|
+
process.once("SIGINT", () => {
|
|
70
|
+
killAll();
|
|
71
|
+
process.exit(130);
|
|
72
|
+
});
|
|
73
|
+
process.once("SIGTERM", () => {
|
|
74
|
+
killAll();
|
|
75
|
+
process.exit(143);
|
|
76
|
+
});
|
|
77
|
+
process.once("uncaughtException", (e) => {
|
|
78
|
+
console.error(e);
|
|
79
|
+
killAll();
|
|
80
|
+
process.exit(1);
|
|
81
|
+
});
|
|
82
|
+
process.once("unhandledRejection", (e: any) => {
|
|
83
|
+
console.error(e);
|
|
84
|
+
killAll();
|
|
85
|
+
process.exit(1);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// ---------- core ----------
|
|
90
|
+
const execWithTimeout = async (
|
|
91
|
+
command: string,
|
|
92
|
+
opts: ExecCommandOptions = {}
|
|
93
|
+
): Promise<ExecResult> => {
|
|
94
|
+
const {
|
|
95
|
+
timeout = 5000,
|
|
96
|
+
continueInBackground = false,
|
|
97
|
+
maxBuffer = 1024 * 1024 * 16,
|
|
98
|
+
} = opts;
|
|
38
99
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
100
|
+
const cleaned = stripTrailingAmp(command);
|
|
101
|
+
const shouldBg = continueInBackground || command.trim().endsWith("&");
|
|
102
|
+
|
|
103
|
+
// Foreground, indefinite wait → stream with spawn
|
|
104
|
+
if (timeout === -1 && !shouldBg) {
|
|
105
|
+
return new Promise<ExecResult>((resolve) => {
|
|
106
|
+
let out = "";
|
|
107
|
+
let err = "";
|
|
108
|
+
const child = spawn(cleaned, { shell: true });
|
|
109
|
+
child.stdout?.on("data", (d) => (out += d.toString()));
|
|
110
|
+
child.stderr?.on("data", (d) => (err += d.toString()));
|
|
111
|
+
child.once("error", (e) =>
|
|
43
112
|
resolve({
|
|
44
|
-
stdout,
|
|
45
|
-
stderr:
|
|
113
|
+
stdout: out,
|
|
114
|
+
stderr: err || String(e),
|
|
46
115
|
timedOut: false,
|
|
47
116
|
killed: false,
|
|
48
|
-
|
|
49
|
-
|
|
117
|
+
pid: child.pid ?? undefined,
|
|
118
|
+
})
|
|
119
|
+
);
|
|
120
|
+
child.once("exit", () =>
|
|
50
121
|
resolve({
|
|
51
|
-
stdout,
|
|
52
|
-
stderr,
|
|
122
|
+
stdout: out,
|
|
123
|
+
stderr: err,
|
|
53
124
|
timedOut: false,
|
|
54
|
-
killed:
|
|
55
|
-
|
|
56
|
-
|
|
125
|
+
killed: false,
|
|
126
|
+
pid: child.pid ?? undefined,
|
|
127
|
+
})
|
|
128
|
+
);
|
|
57
129
|
});
|
|
130
|
+
}
|
|
58
131
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
132
|
+
if (shouldBg) {
|
|
133
|
+
// --- BACKGROUND MODE WITH CHILD-OWNED LOG FD ---
|
|
134
|
+
const logPath = makeLogPath(cleaned);
|
|
135
|
+
|
|
136
|
+
// Open the log file now; we'll pass this FD to the child so it writes directly.
|
|
137
|
+
// Use 'w' to truncate old logs and guarantee our header goes first.
|
|
138
|
+
const fd = fs.openSync(logPath, "w");
|
|
139
|
+
|
|
140
|
+
// Spawn detached; bind stdout/stderr to the same file.
|
|
141
|
+
const child = spawn(cleaned, {
|
|
142
|
+
shell: true,
|
|
143
|
+
detached: true,
|
|
144
|
+
stdio: ["ignore", fd, fd], // child writes directly to file for its entire lifetime
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// Immediately write header (first line includes PID), then close *our* fd.
|
|
148
|
+
// The child keeps its own duplicated handle open.
|
|
149
|
+
const pid = child.pid!;
|
|
150
|
+
const header =
|
|
151
|
+
`PID: ${pid}\n` +
|
|
152
|
+
`CMD: ${cleaned}\n` +
|
|
153
|
+
`START: ${new Date().toISOString()}\n` +
|
|
154
|
+
`---\n`;
|
|
155
|
+
fs.writeSync(fd, header);
|
|
156
|
+
fs.fsyncSync(fd); // flush header before we let go
|
|
157
|
+
try {
|
|
158
|
+
fs.closeSync(fd);
|
|
159
|
+
} catch {}
|
|
160
|
+
|
|
161
|
+
// We only wait 'timeout' ms to return; process keeps running/logging after that.
|
|
162
|
+
return await new Promise<ExecResult>((resolve) => {
|
|
163
|
+
let settled = false;
|
|
164
|
+
|
|
165
|
+
const done = (res: ExecResult) => {
|
|
166
|
+
if (settled) return;
|
|
167
|
+
settled = true;
|
|
168
|
+
resolve({ ...res, pid, logPath });
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
child.once("error", (e) =>
|
|
172
|
+
done({
|
|
70
173
|
stdout: "",
|
|
71
|
-
stderr: `
|
|
72
|
-
timedOut:
|
|
73
|
-
killed:
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
174
|
+
stderr: `Failed to start command: ${String(e)}`,
|
|
175
|
+
timedOut: false,
|
|
176
|
+
killed: false,
|
|
177
|
+
})
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
const tid = setTimeout(() => {
|
|
181
|
+
// fully detach from our side
|
|
182
|
+
try {
|
|
183
|
+
child.unref();
|
|
184
|
+
} catch {}
|
|
185
|
+
STARTED_PIDS.add(pid);
|
|
186
|
+
done({
|
|
78
187
|
stdout: "",
|
|
79
|
-
stderr:
|
|
188
|
+
stderr:
|
|
189
|
+
`Command timed out after ${timeout}ms but continues in background\n` +
|
|
190
|
+
`Logs: ${logPath}\n` +
|
|
191
|
+
`Tip: read first line for PID; kill by PID for cleanup.\n`,
|
|
80
192
|
timedOut: true,
|
|
81
193
|
killed: false,
|
|
82
194
|
});
|
|
83
|
-
}
|
|
84
|
-
}, timeout);
|
|
195
|
+
}, timeout);
|
|
85
196
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
197
|
+
// If it finishes early, report success and avoid “timed out” messaging
|
|
198
|
+
child.once("exit", () => {
|
|
199
|
+
clearTimeout(tid);
|
|
200
|
+
done({
|
|
201
|
+
stdout: "",
|
|
202
|
+
stderr: `Process finished before timeout. Logs: ${logPath}\n`,
|
|
203
|
+
timedOut: false,
|
|
204
|
+
killed: false,
|
|
205
|
+
});
|
|
206
|
+
});
|
|
89
207
|
});
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Foreground with timeout → use exec (buffered) or switch to spawn+manual timer if you prefer
|
|
211
|
+
return new Promise<ExecResult>((resolve) => {
|
|
212
|
+
let out = "";
|
|
213
|
+
let err = "";
|
|
214
|
+
const child = exec(
|
|
215
|
+
cleaned,
|
|
216
|
+
{ timeout, maxBuffer },
|
|
217
|
+
(error: ExecException | null, stdout: string, stderr: string) => {
|
|
218
|
+
out = out || stdout;
|
|
219
|
+
err = err || stderr;
|
|
220
|
+
if (error) {
|
|
221
|
+
resolve({
|
|
222
|
+
stdout: out,
|
|
223
|
+
stderr: err || error.message,
|
|
224
|
+
timedOut: (error as any).killed ?? false,
|
|
225
|
+
killed: !!(error as any).killed,
|
|
226
|
+
pid: (child as any).pid ?? undefined,
|
|
227
|
+
});
|
|
228
|
+
} else {
|
|
229
|
+
resolve({
|
|
230
|
+
stdout: out,
|
|
231
|
+
stderr: err,
|
|
232
|
+
timedOut: false,
|
|
233
|
+
killed: false,
|
|
234
|
+
pid: (child as any).pid ?? undefined,
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
);
|
|
239
|
+
child.stdout?.on("data", (d) => (out += d.toString()));
|
|
240
|
+
child.stderr?.on("data", (d) => (err += d.toString()));
|
|
90
241
|
});
|
|
91
242
|
};
|
|
92
243
|
|
|
93
|
-
//
|
|
244
|
+
// Public tool
|
|
94
245
|
export const execCommand = async (
|
|
95
246
|
command: string,
|
|
96
247
|
timeout?: number,
|
|
97
|
-
continueInBackground?: boolean
|
|
98
|
-
waitForCompletion?: boolean
|
|
248
|
+
continueInBackground?: boolean
|
|
99
249
|
): Promise<string> => {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
continueInBackground,
|
|
106
|
-
waitForCompletion,
|
|
107
|
-
});
|
|
250
|
+
const { stdout, stderr, timedOut, killed, pid, logPath } =
|
|
251
|
+
await execWithTimeout(command, {
|
|
252
|
+
timeout,
|
|
253
|
+
continueInBackground,
|
|
254
|
+
});
|
|
108
255
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
output += stdout;
|
|
256
|
+
let output = "";
|
|
257
|
+
if (stderr) output += stderr + "\n";
|
|
258
|
+
if (stdout) output += stdout;
|
|
113
259
|
|
|
114
|
-
|
|
115
|
-
|
|
260
|
+
const statusMsg = timedOut
|
|
261
|
+
? killed
|
|
116
262
|
? " (killed due to timeout)"
|
|
117
|
-
:
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const fullOutput = output.split("\n");
|
|
263
|
+
: ` (timed out, still running${pid ? `, pid=${pid}` : ""}${
|
|
264
|
+
logPath ? `, logs=${logPath}` : ""
|
|
265
|
+
})`
|
|
266
|
+
: "";
|
|
124
267
|
|
|
268
|
+
const lines = output.split("\n");
|
|
125
269
|
const maxLines = 1000;
|
|
126
|
-
const
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
270
|
+
const maxChars = 40000;
|
|
271
|
+
const trimmed = (lines.length > maxLines ? lines.slice(0, maxLines) : lines)
|
|
272
|
+
.join("\n")
|
|
273
|
+
.slice(0, maxChars);
|
|
274
|
+
const trimmedMsg =
|
|
275
|
+
lines.length > maxLines
|
|
276
|
+
? ` (${lines.length - maxLines} results trimmed)`
|
|
277
|
+
: "";
|
|
133
278
|
|
|
134
|
-
return
|
|
135
|
-
};
|
|
279
|
+
return `$ ${command}${statusMsg}\n${trimmed}${trimmedMsg}`;
|
|
280
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { globSync } from "glob";
|
|
2
2
|
import { getConfiguredEmbeddings } from "../../embeddings";
|
|
3
3
|
import { execCommand } from "./execCommand";
|
|
4
4
|
import { getIgnorePattern } from "../../config";
|
|
@@ -9,25 +9,23 @@ export async function fileSearch(searchTerm) {
|
|
|
9
9
|
const pattern = `./**/*${searchTermLower}*`;
|
|
10
10
|
const ignore = await getIgnorePattern();
|
|
11
11
|
console.log({ pattern, ignore });
|
|
12
|
-
const
|
|
12
|
+
const globFiles = globSync(pattern, {
|
|
13
13
|
ignore,
|
|
14
|
+
nocase: true,
|
|
14
15
|
});
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
);
|
|
17
|
+
const embeddings = await getConfiguredEmbeddings();
|
|
18
|
+
const embeddingFiles = embeddings.filter((embedding) =>
|
|
19
|
+
embedding.id.toLowerCase().includes(searchTermLower)
|
|
20
|
+
);
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
files.push(...ids);
|
|
30
|
-
}
|
|
22
|
+
// ids are filepath.txt-part
|
|
23
|
+
const embeddingIds = embeddingFiles.map((r) => {
|
|
24
|
+
const parts = r.id.split("-");
|
|
25
|
+
return parts.slice(0, -1).join("-");
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const allFiles = toUniqueArray([...globFiles, ...embeddingIds]);
|
|
31
29
|
|
|
32
|
-
return
|
|
30
|
+
return allFiles;
|
|
33
31
|
}
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { services } from "../../../services";
|
|
2
|
+
function getPluginNames(): string {
|
|
3
|
+
try {
|
|
4
|
+
const { Plugins } = services();
|
|
5
|
+
return Plugins.listPlugins().join(", ");
|
|
6
|
+
} catch {
|
|
7
|
+
return "";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
2
10
|
export const definitions = [
|
|
3
11
|
{
|
|
4
12
|
type: "function",
|
|
@@ -22,7 +30,7 @@ export const definitions = [
|
|
|
22
30
|
properties: {
|
|
23
31
|
kind: {
|
|
24
32
|
type: "string",
|
|
25
|
-
description: `The type of datasource, options are "file", "url", "text" or the name of a plugin: ${
|
|
33
|
+
description: `The type of datasource, options are "file", "url", "text" or the name of a plugin: ${getPluginNames()}
|
|
26
34
|
For files you must use the full relative path. For plugins you must use the name of the plugin associated with the data.
|
|
27
35
|
Always use a plugin as the kind, if a plugin name is in the url.
|
|
28
36
|
`,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { services } from "../../../services";
|
|
2
2
|
import { getLanguageConfig, updateLanguageConfig } from "../../../config";
|
|
3
3
|
import { IDatasource } from "../../../types";
|
|
4
4
|
|
|
5
5
|
export async function addLanguageTerm(term: string, sources: IDatasource[]) {
|
|
6
6
|
const language = await getLanguageConfig();
|
|
7
|
-
language[term] = { sources };
|
|
7
|
+
language[term] = { events: [], sources };
|
|
8
8
|
await updateLanguageConfig(language);
|
|
9
9
|
}
|
|
10
10
|
|
|
@@ -14,6 +14,7 @@ export async function getAllLanguageTerms() {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export async function lookupLanguageTerm(term: string) {
|
|
17
|
+
const { Plugins } = services();
|
|
17
18
|
const language = await getLanguageConfig();
|
|
18
19
|
return Plugins.call("language", term);
|
|
19
20
|
}
|
|
@@ -9,8 +9,10 @@ export async function lintFile(filePath: string) {
|
|
|
9
9
|
if (lintCommand.includes("$1")) {
|
|
10
10
|
lintCommand = lintCommand.replace("$1", filePath);
|
|
11
11
|
}
|
|
12
|
-
lintResult = await execCommand(`${lintCommand}`,
|
|
13
|
-
|
|
12
|
+
lintResult = await execCommand(`${lintCommand}`, -1);
|
|
13
|
+
if (lintResult) {
|
|
14
|
+
console.log("Lint Result:", lintResult);
|
|
15
|
+
}
|
|
14
16
|
return lintResult;
|
|
15
17
|
}
|
|
16
18
|
return "";
|