@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,90 @@
|
|
|
1
|
+
import { LanguageAgnosticParser } from "../../../src/plugins/tree-sitter/parser";
|
|
2
|
+
import { TreeEditor } from "../../../src/plugins/tree-sitter/editor";
|
|
3
|
+
|
|
4
|
+
describe("Debug Tree Path Consistency", () => {
|
|
5
|
+
it("should analyze parser vs editor tree differences", () => {
|
|
6
|
+
const parser = LanguageAgnosticParser.createTypeScriptParser();
|
|
7
|
+
|
|
8
|
+
const content = `export class Calculator {
|
|
9
|
+
private history: number[] = [];
|
|
10
|
+
|
|
11
|
+
constructor(private precision: number = 2) {}
|
|
12
|
+
|
|
13
|
+
add(a: number, b: number): number {
|
|
14
|
+
const result = a + b;
|
|
15
|
+
this.history.push(result);
|
|
16
|
+
return Math.round(result * Math.pow(10, this.precision)) / Math.pow(10, this.precision);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
multiply(a: number, b: number): number {
|
|
20
|
+
const result = a * b;
|
|
21
|
+
this.history.push(result);
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
getHistory(): number[] {
|
|
26
|
+
return [...this.history];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
clear(): void {
|
|
30
|
+
this.history = [];
|
|
31
|
+
}
|
|
32
|
+
}`;
|
|
33
|
+
|
|
34
|
+
// Create tree first
|
|
35
|
+
const tree = parser.parseString(content);
|
|
36
|
+
|
|
37
|
+
console.log("=== Sample content ===");
|
|
38
|
+
console.log("");
|
|
39
|
+
console.log(content);
|
|
40
|
+
console.log("=== End content ===");
|
|
41
|
+
|
|
42
|
+
console.log("=== Comparing Parser vs Editor Trees ===");
|
|
43
|
+
// Use the same tree instance for both parser and editor
|
|
44
|
+
const editor = TreeEditor.fromTree(parser, tree);
|
|
45
|
+
|
|
46
|
+
console.log(`Parser tree root: ${tree.rootNode.type}, children: ${tree.rootNode.children.length}`);
|
|
47
|
+
console.log(`Parser children types: [${tree.rootNode.children.map(c => c.type).join(', ')}]`);
|
|
48
|
+
|
|
49
|
+
console.log(`Parser instances identical: ${parser === (editor as any).parser}`);
|
|
50
|
+
|
|
51
|
+
console.log(`Editor tree root: ${editor.tree.rootNode.type}, children: ${editor.tree.rootNode.children.length}`);
|
|
52
|
+
console.log(`Editor children types: [${editor.tree.rootNode.children.map(c => c.type).join(', ')}]`);
|
|
53
|
+
|
|
54
|
+
console.log(`Trees identical: ${tree === editor.tree}`);
|
|
55
|
+
console.log("==========================================");
|
|
56
|
+
|
|
57
|
+
// Find all paths for different terms
|
|
58
|
+
const resultPaths = parser.findPathsForLine(tree, "result");
|
|
59
|
+
const historyPaths = parser.findPathsForLine(tree, "history");
|
|
60
|
+
const addPaths = parser.findPathsForLine(tree, "add");
|
|
61
|
+
|
|
62
|
+
console.log("=== All paths containing 'result' ===");
|
|
63
|
+
resultPaths.forEach((pathInfo, i) => {
|
|
64
|
+
console.log(`${i}: ${pathInfo.path} at row ${pathInfo.row}, col ${pathInfo.column}: "${pathInfo.text}"`);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
console.log("\n=== Testing path round-trip ===");
|
|
68
|
+
if (resultPaths.length > 0) {
|
|
69
|
+
const firstPath = resultPaths[0];
|
|
70
|
+
console.log(`Testing path: ${firstPath.path}`);
|
|
71
|
+
|
|
72
|
+
const foundNode = editor.findNodeByPath(firstPath.path);
|
|
73
|
+
if (foundNode) {
|
|
74
|
+
console.log(`✓ Node found! Text: "${foundNode.text}", Type: ${foundNode.type}`);
|
|
75
|
+
console.log(`Position: row ${foundNode.startPosition.row}, col ${foundNode.startPosition.column}`);
|
|
76
|
+
|
|
77
|
+
// Test if we can regenerate the same path
|
|
78
|
+
const regeneratedPath = parser.getNodePath(tree.rootNode, foundNode);
|
|
79
|
+
console.log(`Original path: ${firstPath.path}`);
|
|
80
|
+
console.log(`Regenerated path: ${regeneratedPath}`);
|
|
81
|
+
console.log(`Paths match: ${regeneratedPath === firstPath.path}`);
|
|
82
|
+
} else {
|
|
83
|
+
console.log(`✗ Node NOT found for path: ${firstPath.path}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Verify that path resolution now works
|
|
88
|
+
expect(tree === editor.tree).toBe(true);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LanguageAgnosticParser,
|
|
3
|
+
} from "../../../src/plugins/tree-sitter/parser";
|
|
4
|
+
import { TreeEditor } from "../../../src/plugins/tree-sitter/editor";
|
|
5
|
+
|
|
6
|
+
describe("Tree-sitter Path Functionality", () => {
|
|
7
|
+
let parser: LanguageAgnosticParser;
|
|
8
|
+
let editor: TreeEditor;
|
|
9
|
+
|
|
10
|
+
const sampleCode = `export class Calculator {
|
|
11
|
+
private history: number[] = [];
|
|
12
|
+
private operationCount: number = 0;
|
|
13
|
+
|
|
14
|
+
constructor(private precision: number = 2) {}
|
|
15
|
+
|
|
16
|
+
add(a: number, b: number): number {
|
|
17
|
+
const result = a + b;
|
|
18
|
+
this.history.push(result);
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
multiply(a: number, b: number): number {
|
|
23
|
+
const result = a * b;
|
|
24
|
+
this.history.push(result);
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
getHistory(): number[] {
|
|
29
|
+
return [...this.history];
|
|
30
|
+
}
|
|
31
|
+
}`;
|
|
32
|
+
|
|
33
|
+
beforeEach(() => {
|
|
34
|
+
parser = LanguageAgnosticParser.createTypeScriptParser();
|
|
35
|
+
editor = new TreeEditor(parser, sampleCode);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe("Path Generation and Resolution", () => {
|
|
39
|
+
test("should generate consistent paths with getNodePath and findNodeByPath", () => {
|
|
40
|
+
const tree = editor.getTree();
|
|
41
|
+
|
|
42
|
+
// Find all variable declarations in methods
|
|
43
|
+
const paths = editor.findPathsForLine(tree, "result");
|
|
44
|
+
|
|
45
|
+
expect(paths.length).toBeGreaterThan(0);
|
|
46
|
+
|
|
47
|
+
paths.forEach(pathLocation => {
|
|
48
|
+
console.log(`Found path: ${pathLocation.path} at ${pathLocation.row}:${pathLocation.column}`);
|
|
49
|
+
|
|
50
|
+
// Try to find the node back using the path
|
|
51
|
+
const foundNode = (editor as any).findNodeByPath(pathLocation.path);
|
|
52
|
+
expect(foundNode).not.toBeNull();
|
|
53
|
+
|
|
54
|
+
if (foundNode) {
|
|
55
|
+
// The found node might be a parent of the exact location, so just verify it contains the text
|
|
56
|
+
expect(foundNode.text).toContain(pathLocation.text);
|
|
57
|
+
expect(foundNode.endPosition.column).toBeGreaterThanOrEqual(pathLocation.column + pathLocation.text.length);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("should find paths to variables defined in methods", () => {
|
|
63
|
+
const tree = editor.getTree();
|
|
64
|
+
|
|
65
|
+
// Find paths to 'result' variable declarations
|
|
66
|
+
const resultPaths = editor.findPathsForLine(tree, "result");
|
|
67
|
+
|
|
68
|
+
// Filter to only variable declarations (not references)
|
|
69
|
+
const variableDeclarations = resultPaths.filter(path =>
|
|
70
|
+
path.path.includes("statement_block") && path.text === "result"
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
expect(variableDeclarations.length).toBeGreaterThan(0);
|
|
74
|
+
|
|
75
|
+
variableDeclarations.forEach(path => {
|
|
76
|
+
console.log(`Variable declaration path: ${path.path}`);
|
|
77
|
+
console.log(`Location: line ${path.row + 1}, column ${path.column + 1}`);
|
|
78
|
+
console.log(`Text: "${path.text}"`);
|
|
79
|
+
|
|
80
|
+
// Verify we can find the node back
|
|
81
|
+
const node = (editor as any).findNodeByPath(path.path);
|
|
82
|
+
expect(node).not.toBeNull();
|
|
83
|
+
expect(node?.text).toContain("result");
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test("should find paths to method parameters", () => {
|
|
88
|
+
const tree = editor.getTree();
|
|
89
|
+
|
|
90
|
+
// Find paths to method parameters 'a' and 'b'
|
|
91
|
+
const parameterPaths = [
|
|
92
|
+
...editor.findPathsForLine(tree, "a"),
|
|
93
|
+
...editor.findPathsForLine(tree, "b")
|
|
94
|
+
].filter(path =>
|
|
95
|
+
path.path.includes("formal_parameters") ||
|
|
96
|
+
path.path.includes("required_parameter")
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
expect(parameterPaths.length).toBeGreaterThan(0);
|
|
100
|
+
|
|
101
|
+
parameterPaths.forEach(path => {
|
|
102
|
+
console.log(`Parameter path: ${path.path}`);
|
|
103
|
+
const node = (editor as any).findNodeByPath(path.path);
|
|
104
|
+
expect(node).not.toBeNull();
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test("should find paths to class properties", () => {
|
|
109
|
+
const tree = editor.getTree();
|
|
110
|
+
|
|
111
|
+
// Find paths to class properties
|
|
112
|
+
const propertyPaths = editor.findPathsForLine(tree, "history");
|
|
113
|
+
|
|
114
|
+
const propertyDeclarations = propertyPaths.filter(path =>
|
|
115
|
+
path.path.includes("public_field_definition") && path.path.includes("property_identifier")
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
expect(propertyDeclarations.length).toBeGreaterThan(0);
|
|
119
|
+
|
|
120
|
+
propertyDeclarations.forEach(path => {
|
|
121
|
+
console.log(`Property path: ${path.path}`);
|
|
122
|
+
const node = (editor as any).findNodeByPath(path.path);
|
|
123
|
+
expect(node).not.toBeNull();
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
describe("Path-based Node Updates", () => {
|
|
129
|
+
test("should update node content using paths", () => {
|
|
130
|
+
const tree = editor.getTree();
|
|
131
|
+
|
|
132
|
+
// Find the first result variable declaration
|
|
133
|
+
const resultPaths = editor.findPathsForLine(tree, "result");
|
|
134
|
+
const firstResultPath = resultPaths[0];
|
|
135
|
+
|
|
136
|
+
expect(firstResultPath).toBeDefined();
|
|
137
|
+
|
|
138
|
+
// Update the node at this path
|
|
139
|
+
const updatedEditor = editor.updateNodeByPath(firstResultPath.path, "finalResult");
|
|
140
|
+
const updatedText = updatedEditor.getCurrentText();
|
|
141
|
+
|
|
142
|
+
expect(updatedText).toContain("finalResult");
|
|
143
|
+
expect(updatedText).not.toBe(sampleCode);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test("should handle multi-line node updates", () => {
|
|
147
|
+
const tree = editor.getTree();
|
|
148
|
+
|
|
149
|
+
// Find a method body
|
|
150
|
+
const addMethodPaths = editor.findPathsForLine(tree, "add");
|
|
151
|
+
const methodPath = addMethodPaths.find(path =>
|
|
152
|
+
path.path.includes("method_definition") && path.path.includes("property_identifier") && path.text === "add"
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
expect(methodPath).toBeDefined();
|
|
156
|
+
|
|
157
|
+
// Update the entire method
|
|
158
|
+
const newMethodBody = `add(a: number, b: number): number {
|
|
159
|
+
console.log("Adding numbers");
|
|
160
|
+
return a + b;
|
|
161
|
+
}`;
|
|
162
|
+
|
|
163
|
+
const updatedEditor = editor.updateNodeByPath(methodPath!.path, newMethodBody);
|
|
164
|
+
const updatedText = updatedEditor.getCurrentText();
|
|
165
|
+
|
|
166
|
+
expect(updatedText).toContain("console.log");
|
|
167
|
+
expect(updatedText).toContain("Adding numbers");
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
});
|
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
import { LanguageAgnosticParser } from "../../../src/plugins/tree-sitter/parser";
|
|
2
|
+
import { TreeEditor } from "../../../src/plugins/tree-sitter/editor";
|
|
3
|
+
import { SimplePathResolver } from "../../../src/plugins/tree-sitter/simple-paths";
|
|
4
|
+
|
|
5
|
+
describe("Simple Path Functionality", () => {
|
|
6
|
+
let parser: LanguageAgnosticParser;
|
|
7
|
+
let resolver: SimplePathResolver;
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
parser = LanguageAgnosticParser.createTypeScriptParser();
|
|
11
|
+
resolver = new SimplePathResolver(parser);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const sampleCode = `
|
|
15
|
+
export class Calculator {
|
|
16
|
+
private value: number = 0;
|
|
17
|
+
|
|
18
|
+
constructor(initialValue: number) {
|
|
19
|
+
this.value = initialValue;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
add(x: number): number {
|
|
23
|
+
const result = this.value + x;
|
|
24
|
+
console.log("Adding", result);
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
multiply(x: number, y: number): number {
|
|
29
|
+
const result = x * y;
|
|
30
|
+
console.log("Multiplying", result);
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
`.trim();
|
|
35
|
+
|
|
36
|
+
describe("SimplePathResolver", () => {
|
|
37
|
+
test("should find nodes by class name", () => {
|
|
38
|
+
const tree = parser.parseString(sampleCode);
|
|
39
|
+
const matches = resolver.findBySimplePath(tree, "Calculator");
|
|
40
|
+
|
|
41
|
+
expect(matches.length).toBeGreaterThan(0);
|
|
42
|
+
expect(matches[0].description).toContain("Calculator");
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test("should find nodes by method name", () => {
|
|
46
|
+
const tree = parser.parseString(sampleCode);
|
|
47
|
+
const matches = resolver.findBySimplePath(tree, "add");
|
|
48
|
+
|
|
49
|
+
expect(matches.length).toBeGreaterThan(0);
|
|
50
|
+
expect(matches.some(m => m.description.includes("add"))).toBe(true);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test("should find nodes by class.method pattern", () => {
|
|
54
|
+
const tree = parser.parseString(sampleCode);
|
|
55
|
+
const matches = resolver.findBySimplePath(tree, "Calculator.add");
|
|
56
|
+
|
|
57
|
+
expect(matches.length).toBeGreaterThan(0);
|
|
58
|
+
expect(matches[0].description).toContain("Calculator");
|
|
59
|
+
expect(matches[0].description).toContain("add");
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("should get all available simple paths", () => {
|
|
63
|
+
const tree = parser.parseString(sampleCode);
|
|
64
|
+
const paths = resolver.getAllSimplePaths(tree);
|
|
65
|
+
|
|
66
|
+
expect(paths.length).toBeGreaterThan(0);
|
|
67
|
+
expect(paths.some(p => p.includes("Calculator"))).toBe(true);
|
|
68
|
+
expect(paths.some(p => p.includes("add"))).toBe(true);
|
|
69
|
+
expect(paths.some(p => p.includes("multiply"))).toBe(true);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe("TreeEditor Simple Path Integration", () => {
|
|
74
|
+
test("should update node using simple path", () => {
|
|
75
|
+
const editor = new TreeEditor(parser, sampleCode);
|
|
76
|
+
|
|
77
|
+
// Find a method to update
|
|
78
|
+
const matches = editor.findNodesBySimplePath("add");
|
|
79
|
+
expect(matches.length).toBeGreaterThan(0);
|
|
80
|
+
|
|
81
|
+
// Update the method body
|
|
82
|
+
const updatedEditor = editor.updateNodeBySimplePath("Calculator.add", `add(x: number): number {
|
|
83
|
+
return this.value + x + 1; // Modified
|
|
84
|
+
}`);
|
|
85
|
+
|
|
86
|
+
const newText = updatedEditor.getCurrentText();
|
|
87
|
+
expect(newText).toContain("Modified");
|
|
88
|
+
expect(newText).toContain("x + 1");
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test("should find multiple nodes with same name", () => {
|
|
92
|
+
const editor = new TreeEditor(parser, sampleCode);
|
|
93
|
+
|
|
94
|
+
// Create a sample with duplicate method names to test multiple matches
|
|
95
|
+
const duplicateMethodCode = `
|
|
96
|
+
class A { method() { return 1; } }
|
|
97
|
+
class B { method() { return 2; } }
|
|
98
|
+
`.trim();
|
|
99
|
+
|
|
100
|
+
const duplicateEditor = new TreeEditor(parser, duplicateMethodCode);
|
|
101
|
+
const matches = duplicateEditor.findNodesBySimplePath("method");
|
|
102
|
+
|
|
103
|
+
// Should find multiple 'method' functions
|
|
104
|
+
expect(matches.length).toBeGreaterThan(1);
|
|
105
|
+
expect(matches.some(m => m.description.includes("method in class A"))).toBe(true);
|
|
106
|
+
expect(matches.some(m => m.description.includes("method in class B"))).toBe(true);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test("should get all simple paths from TreeEditor", () => {
|
|
110
|
+
const editor = new TreeEditor(parser, sampleCode);
|
|
111
|
+
const paths = editor.getAllSimplePaths();
|
|
112
|
+
|
|
113
|
+
expect(paths.length).toBeGreaterThan(0);
|
|
114
|
+
expect(paths.some(p => p.includes("Calculator"))).toBe(true);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test("should handle path not found error", () => {
|
|
118
|
+
const editor = new TreeEditor(parser, sampleCode);
|
|
119
|
+
|
|
120
|
+
expect(() => {
|
|
121
|
+
editor.updateNodeBySimplePath("NonExistentClass.nonExistentMethod", "new content");
|
|
122
|
+
}).toThrow(/Node not found at path: NonExistentClass.nonExistentMethod/);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test("should handle multiple matches error", () => {
|
|
126
|
+
const editor = new TreeEditor(parser, sampleCode);
|
|
127
|
+
|
|
128
|
+
// Create a sample with duplicate method names
|
|
129
|
+
const duplicateMethodCode = `
|
|
130
|
+
class A { method() { return 1; } }
|
|
131
|
+
class B { method() { return 2; } }
|
|
132
|
+
`.trim();
|
|
133
|
+
|
|
134
|
+
const duplicateEditor = new TreeEditor(parser, duplicateMethodCode);
|
|
135
|
+
|
|
136
|
+
// Try to update with ambiguous path that matches multiple nodes
|
|
137
|
+
expect(() => {
|
|
138
|
+
duplicateEditor.updateNodeBySimplePath("method", "new content");
|
|
139
|
+
}).toThrow(/Multiple nodes found for path: method.*/);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
describe("Generic Block Support", () => {
|
|
144
|
+
const testFrameworkCode = `
|
|
145
|
+
describe("Authentication", () => {
|
|
146
|
+
beforeEach(() => {
|
|
147
|
+
setup();
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test("should login successfully", () => {
|
|
151
|
+
expect(login()).toBe(true);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it("should logout properly", () => {
|
|
155
|
+
expect(logout()).toBe(true);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
afterEach(() => {
|
|
159
|
+
cleanup();
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
describe("User Management", () => {
|
|
164
|
+
test("should create user", () => {
|
|
165
|
+
expect(createUser()).toBeTruthy();
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
`.trim();
|
|
169
|
+
|
|
170
|
+
test("should find describe blocks by name", () => {
|
|
171
|
+
const tree = parser.parseString(testFrameworkCode);
|
|
172
|
+
const matches = resolver.findBySimplePath(tree, 'describe("Authentication")');
|
|
173
|
+
|
|
174
|
+
expect(matches.length).toBe(1);
|
|
175
|
+
expect(matches[0].description).toContain("describe");
|
|
176
|
+
expect(matches[0].description).toContain("Authentication");
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test("should find test blocks by name", () => {
|
|
180
|
+
const tree = parser.parseString(testFrameworkCode);
|
|
181
|
+
const matches = resolver.findBySimplePath(tree, 'test("should login successfully")');
|
|
182
|
+
|
|
183
|
+
expect(matches.length).toBe(1);
|
|
184
|
+
expect(matches[0].description).toContain("test");
|
|
185
|
+
expect(matches[0].description).toContain("should login successfully");
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
test("should find it blocks by name", () => {
|
|
189
|
+
const tree = parser.parseString(testFrameworkCode);
|
|
190
|
+
const matches = resolver.findBySimplePath(tree, 'it("should logout properly")');
|
|
191
|
+
|
|
192
|
+
expect(matches.length).toBe(1);
|
|
193
|
+
expect(matches[0].description).toContain("it");
|
|
194
|
+
expect(matches[0].description).toContain("should logout properly");
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
test("should find beforeEach blocks", () => {
|
|
198
|
+
const tree = parser.parseString(testFrameworkCode);
|
|
199
|
+
const matches = resolver.findBySimplePath(tree, "beforeEach");
|
|
200
|
+
|
|
201
|
+
expect(matches.length).toBe(1);
|
|
202
|
+
expect(matches[0].description).toContain("beforeEach");
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
test("should find afterEach blocks", () => {
|
|
206
|
+
const tree = parser.parseString(testFrameworkCode);
|
|
207
|
+
const matches = resolver.findBySimplePath(tree, "afterEach");
|
|
208
|
+
|
|
209
|
+
expect(matches.length).toBe(1);
|
|
210
|
+
expect(matches[0].description).toContain("afterEach");
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
test("should handle template string literals", () => {
|
|
214
|
+
const templateStringCode = `
|
|
215
|
+
describe(\`User \${userId} Tests\`, () => {
|
|
216
|
+
test(\`should process \${action}\`, () => {
|
|
217
|
+
// test content
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
`.trim();
|
|
221
|
+
|
|
222
|
+
const tree = parser.parseString(templateStringCode);
|
|
223
|
+
const matches = resolver.findBySimplePath(tree, 'describe(`User ${userId} Tests`)');
|
|
224
|
+
|
|
225
|
+
expect(matches.length).toBe(1);
|
|
226
|
+
expect(matches[0].description).toContain("describe");
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
test("should find multiple describe blocks with different names", () => {
|
|
230
|
+
const tree = parser.parseString(testFrameworkCode);
|
|
231
|
+
const authMatches = resolver.findBySimplePath(tree, 'describe("Authentication")');
|
|
232
|
+
const userMatches = resolver.findBySimplePath(tree, 'describe("User Management")');
|
|
233
|
+
|
|
234
|
+
expect(authMatches.length).toBe(1);
|
|
235
|
+
expect(userMatches.length).toBe(1);
|
|
236
|
+
expect(authMatches[0].description).toContain("Authentication");
|
|
237
|
+
expect(userMatches[0].description).toContain("User Management");
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
test("should include generic blocks in getAllSimplePaths", () => {
|
|
241
|
+
const tree = parser.parseString(testFrameworkCode);
|
|
242
|
+
const paths = resolver.getAllSimplePaths(tree);
|
|
243
|
+
|
|
244
|
+
expect(paths.some(p => p.includes('describe("Authentication")'))).toBe(true);
|
|
245
|
+
expect(paths.some(p => p.includes('test("should login successfully")'))).toBe(true);
|
|
246
|
+
expect(paths.some(p => p.includes('it("should logout properly")'))).toBe(true);
|
|
247
|
+
expect(paths.some(p => p.includes("beforeEach"))).toBe(true);
|
|
248
|
+
expect(paths.some(p => p.includes("afterEach"))).toBe(true);
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
describe("Multi-Language Support", () => {
|
|
253
|
+
describe("JavaScript Support", () => {
|
|
254
|
+
let jsParser: LanguageAgnosticParser;
|
|
255
|
+
let jsResolver: SimplePathResolver;
|
|
256
|
+
|
|
257
|
+
beforeEach(() => {
|
|
258
|
+
jsParser = LanguageAgnosticParser.createJavaScriptParser();
|
|
259
|
+
jsResolver = new SimplePathResolver(jsParser);
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
const jsCode = `
|
|
263
|
+
class Calculator {
|
|
264
|
+
constructor(initialValue = 0) {
|
|
265
|
+
this.value = initialValue;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
add(x) {
|
|
269
|
+
const result = this.value + x;
|
|
270
|
+
console.log(\`Adding: \${result}\`);
|
|
271
|
+
return result;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
multiply(x, y) {
|
|
275
|
+
const result = x * y;
|
|
276
|
+
console.log(\`Multiplying: \${result}\`);
|
|
277
|
+
return result;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
`.trim();
|
|
281
|
+
|
|
282
|
+
test("should find JavaScript classes", () => {
|
|
283
|
+
const tree = jsParser.parseString(jsCode);
|
|
284
|
+
const matches = jsResolver.findBySimplePath(tree, "Calculator");
|
|
285
|
+
|
|
286
|
+
expect(matches.length).toBeGreaterThan(0);
|
|
287
|
+
expect(matches[0].description).toContain("Calculator");
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
test("should find JavaScript methods", () => {
|
|
291
|
+
const tree = jsParser.parseString(jsCode);
|
|
292
|
+
const matches = jsResolver.findBySimplePath(tree, "add");
|
|
293
|
+
|
|
294
|
+
expect(matches.length).toBeGreaterThan(0);
|
|
295
|
+
expect(matches.some(m => m.description.includes("add"))).toBe(true);
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
test("should find JavaScript class.method patterns", () => {
|
|
299
|
+
const tree = jsParser.parseString(jsCode);
|
|
300
|
+
const matches = jsResolver.findBySimplePath(tree, "Calculator.add");
|
|
301
|
+
|
|
302
|
+
expect(matches.length).toBeGreaterThan(0);
|
|
303
|
+
expect(matches[0].description).toContain("Calculator");
|
|
304
|
+
expect(matches[0].description).toContain("add");
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
test("should handle JavaScript with test blocks", () => {
|
|
308
|
+
const jsTestCode = `
|
|
309
|
+
describe("Calculator Tests", () => {
|
|
310
|
+
test("should add numbers", () => {
|
|
311
|
+
const calc = new Calculator();
|
|
312
|
+
expect(calc.add(2)).toBe(2);
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
`.trim();
|
|
316
|
+
|
|
317
|
+
const tree = jsParser.parseString(jsTestCode);
|
|
318
|
+
const matches = jsResolver.findBySimplePath(tree, 'describe("Calculator Tests")');
|
|
319
|
+
|
|
320
|
+
expect(matches.length).toBe(1);
|
|
321
|
+
expect(matches[0].description).toContain("describe");
|
|
322
|
+
expect(matches[0].description).toContain("Calculator Tests");
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
describe("Interface Support (TypeScript)", () => {
|
|
328
|
+
const interfaceCode = `
|
|
329
|
+
interface ICalculator {
|
|
330
|
+
add(x: number): number;
|
|
331
|
+
multiply(x: number, y: number): number;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
interface IUserManager {
|
|
335
|
+
createUser(name: string): User;
|
|
336
|
+
deleteUser(id: number): void;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
class Calculator implements ICalculator {
|
|
340
|
+
add(x: number): number {
|
|
341
|
+
return x;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
multiply(x: number, y: number): number {
|
|
345
|
+
return x * y;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
`.trim();
|
|
349
|
+
|
|
350
|
+
test("should find interfaces", () => {
|
|
351
|
+
const tree = parser.parseString(interfaceCode);
|
|
352
|
+
const matches = resolver.findBySimplePath(tree, "ICalculator");
|
|
353
|
+
|
|
354
|
+
expect(matches.length).toBeGreaterThan(0);
|
|
355
|
+
expect(matches[0].description).toContain("ICalculator");
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
test("should find interface methods", () => {
|
|
359
|
+
const tree = parser.parseString(interfaceCode);
|
|
360
|
+
const matches = resolver.findBySimplePath(tree, "ICalculator.add");
|
|
361
|
+
|
|
362
|
+
expect(matches.length).toBeGreaterThan(0);
|
|
363
|
+
expect(matches[0].description).toContain("ICalculator");
|
|
364
|
+
expect(matches[0].description).toContain("add");
|
|
365
|
+
});
|
|
366
|
+
});
|
|
367
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export class Calculator {
|
|
2
|
+
private history: number[] = [];
|
|
3
|
+
private operationCount: number = 0;
|
|
4
|
+
|
|
5
|
+
constructor(private precision: number = 2) {}
|
|
6
|
+
|
|
7
|
+
add(a: number, b: number): number {
|
|
8
|
+
// Enhanced add method with validation and logging
|
|
9
|
+
if (typeof a !== 'number' || typeof b !== 'number') {
|
|
10
|
+
throw new Error('Both arguments must be numbers');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const result = a + b;
|
|
14
|
+
this.history.push(result);
|
|
15
|
+
this.operationCount++;
|
|
16
|
+
|
|
17
|
+
console.log(`Addition performed: ${a} + ${b} = ${result}`);
|
|
18
|
+
return Math.round(result * Math.pow(10, this.precision)) / Math.pow(10, this.precision);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
multiply(a: number, b: number): number {
|
|
22
|
+
// Enhanced multiply method with validation
|
|
23
|
+
if (typeof a !== 'number' || typeof b !== 'number') {
|
|
24
|
+
throw new Error('Both arguments must be numbers');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const result = a * b;
|
|
28
|
+
this.history.push(result);
|
|
29
|
+
this.operationCount++;
|
|
30
|
+
|
|
31
|
+
console.log(`Multiplication performed: ${a} * ${b} = ${result}`);
|
|
32
|
+
return Math.round(result * Math.pow(10, this.precision)) / Math.pow(10, this.precision);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
getHistory(): number[] {
|
|
36
|
+
return [...this.history];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
getOperationCount(): number {
|
|
40
|
+
return this.operationCount;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
clear(): void {
|
|
44
|
+
this.history = [];
|
|
45
|
+
this.operationCount = 0;
|
|
46
|
+
console.log('Calculator cleared');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export class Calculator {
|
|
2
|
+
private history: number[] = [];
|
|
3
|
+
|
|
4
|
+
constructor(private precision: number = 2) {}
|
|
5
|
+
|
|
6
|
+
add(a: number, b: number): number {
|
|
7
|
+
const result = a + b;
|
|
8
|
+
this.history.push(result);
|
|
9
|
+
return Math.round(result * Math.pow(10, this.precision)) / Math.pow(10, this.precision);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
multiply(a: number, b: number): number {
|
|
13
|
+
const result = a * b;
|
|
14
|
+
this.history.push(result);
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
getHistory(): number[] {
|
|
19
|
+
return [...this.history];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
clear(): void {
|
|
23
|
+
this.history = [];
|
|
24
|
+
}
|
|
25
|
+
}
|