@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,391 @@
|
|
|
1
|
+
import { Message } from "../../src/clients/types";
|
|
2
|
+
import { TokenCompressor } from "../../src/processors/TokenCompressor";
|
|
3
|
+
import { ToolsService } from "../../src/services";
|
|
4
|
+
|
|
5
|
+
describe("TokenCompressor", () => {
|
|
6
|
+
let tokenCompressor: TokenCompressor;
|
|
7
|
+
let mockToolsService: jest.Mocked<ToolsService>;
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
mockToolsService = {
|
|
11
|
+
addTool: jest.fn(),
|
|
12
|
+
addFunctions: jest.fn(),
|
|
13
|
+
getTool: jest.fn(),
|
|
14
|
+
} as any;
|
|
15
|
+
|
|
16
|
+
tokenCompressor = new TokenCompressor(mockToolsService);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
afterEach(() => {
|
|
20
|
+
tokenCompressor.clearStorage();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe("constructor", () => {
|
|
24
|
+
it("should register expandTokens tool with ToolsService", () => {
|
|
25
|
+
expect(mockToolsService.getTool).toHaveBeenCalledWith("expandTokens");
|
|
26
|
+
expect(mockToolsService.addTool).toHaveBeenCalled();
|
|
27
|
+
expect(mockToolsService.addFunctions).toHaveBeenCalled();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("should not register tool if already exists", () => {
|
|
31
|
+
mockToolsService.getTool.mockReturnValue({ type: "function", function: { name: "expandTokens" } } as any);
|
|
32
|
+
const newCompressor = new TokenCompressor(mockToolsService);
|
|
33
|
+
|
|
34
|
+
// Should only be called once from the first instance
|
|
35
|
+
expect(mockToolsService.addTool).toHaveBeenCalledTimes(1);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("should work without ToolsService", () => {
|
|
39
|
+
expect(() => new TokenCompressor()).not.toThrow();
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe("compressContent", () => {
|
|
44
|
+
it("should return original content if below threshold", () => {
|
|
45
|
+
const shortContent = "This is short content";
|
|
46
|
+
const result = tokenCompressor.compressContent(shortContent);
|
|
47
|
+
expect(result).toBe(shortContent);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("should compress long strings using chunking", () => {
|
|
51
|
+
const longContent = "x".repeat(40000); // Well above threshold (40k chars = 10k tokens > 8k maxTokens)
|
|
52
|
+
const result = tokenCompressor.compressContent(longContent);
|
|
53
|
+
|
|
54
|
+
expect(result).toContain("[COMPRESSED_STRING");
|
|
55
|
+
expect(result).toContain("Key:");
|
|
56
|
+
expect(result).toContain("expandTokens");
|
|
57
|
+
expect(result).toContain("Preview:");
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("should compress JSON objects by properties", () => {
|
|
61
|
+
const largeJson = {
|
|
62
|
+
data: "x".repeat(40000), // 40k chars = 10k tokens, above threshold
|
|
63
|
+
metadata: { id: 1, name: "test" }
|
|
64
|
+
};
|
|
65
|
+
const content = JSON.stringify(largeJson);
|
|
66
|
+
const result = tokenCompressor.compressContent(content);
|
|
67
|
+
|
|
68
|
+
// Should be parsed and compressed as JSON
|
|
69
|
+
const parsed = JSON.parse(result);
|
|
70
|
+
expect(typeof parsed.data).toBe("string");
|
|
71
|
+
expect(parsed.data).toContain("[COMPRESSED_JSON_PROPERTY");
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("should handle mixed JSON compression strategies", () => {
|
|
75
|
+
const complexJson = {
|
|
76
|
+
smallProp: "small",
|
|
77
|
+
largeProp: "x".repeat(40000), // 40k chars = 10k tokens, above threshold
|
|
78
|
+
array: new Array(2000).fill({ item: "data".repeat(50) }) // Larger array to trigger compression
|
|
79
|
+
};
|
|
80
|
+
const content = JSON.stringify(complexJson);
|
|
81
|
+
const result = tokenCompressor.compressContent(content);
|
|
82
|
+
|
|
83
|
+
const parsed = JSON.parse(result);
|
|
84
|
+
expect(parsed.smallProp).toBe("small"); // Should remain unchanged
|
|
85
|
+
expect(parsed.largeProp).toContain("[COMPRESSED_JSON_PROPERTY"); // Should be compressed
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe("compressStringInChunks", () => {
|
|
90
|
+
it("should return original string if below limit", () => {
|
|
91
|
+
const content = "short string";
|
|
92
|
+
const result = tokenCompressor.compressStringInChunks(content);
|
|
93
|
+
expect(result).toBe(content);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("should create chunked compression for large strings", () => {
|
|
97
|
+
const content = "x".repeat(20000);
|
|
98
|
+
const result = tokenCompressor.compressStringInChunks(content);
|
|
99
|
+
|
|
100
|
+
expect(result).toContain("[COMPRESSED_STRING");
|
|
101
|
+
expect(result).toContain("chunks");
|
|
102
|
+
expect(result).toContain("Key:");
|
|
103
|
+
|
|
104
|
+
// Should have stored chunks in storage
|
|
105
|
+
expect(tokenCompressor.getStorageSize()).toBeGreaterThan(0);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("should create chain of NEXT_CHUNK_KEY references", () => {
|
|
109
|
+
const content = "a".repeat(20000);
|
|
110
|
+
tokenCompressor.compressStringInChunks(content);
|
|
111
|
+
|
|
112
|
+
const keys = tokenCompressor.getStorageKeys();
|
|
113
|
+
expect(keys.length).toBeGreaterThan(1);
|
|
114
|
+
|
|
115
|
+
// Check that chunks are linked
|
|
116
|
+
const firstChunk = tokenCompressor.retrieveString(keys[0]);
|
|
117
|
+
expect(firstChunk).toContain("NEXT_CHUNK_KEY");
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
describe("compressJsonProperties", () => {
|
|
122
|
+
it("should compress large array elements", () => {
|
|
123
|
+
// Create array that will definitely create chunks > 4000 chars (50 elements × 200 chars = 10k+ chars per potential chunk)
|
|
124
|
+
const largeArray = new Array(15).fill("x".repeat(2200));
|
|
125
|
+
const result = tokenCompressor.compressJsonProperties(largeArray);
|
|
126
|
+
|
|
127
|
+
// Should contain compression markers
|
|
128
|
+
expect(JSON.stringify(result)).toContain("[COMPRESSED_JSON_ARRAY_CHUNK");
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("should compress nested JSON objects", () => {
|
|
132
|
+
const nestedObj = {
|
|
133
|
+
level1: {
|
|
134
|
+
level2: {
|
|
135
|
+
data: "x".repeat(40000) // 40k chars = ~10k tokens, above 8k threshold
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const result = tokenCompressor.compressJsonProperties(nestedObj);
|
|
141
|
+
expect(JSON.stringify(result)).toContain("[COMPRESSED_JSON");
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("should handle arrays with mixed content sizes", () => {
|
|
145
|
+
const mixedArray = [
|
|
146
|
+
"small",
|
|
147
|
+
"x".repeat(5000), // Large item
|
|
148
|
+
{ data: "y".repeat(5000) }, // Large object
|
|
149
|
+
"another small item"
|
|
150
|
+
];
|
|
151
|
+
|
|
152
|
+
const result = tokenCompressor.compressJsonProperties(mixedArray);
|
|
153
|
+
expect(Array.isArray(result)).toBe(true);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("should preserve small objects unchanged", () => {
|
|
157
|
+
const smallObj = { id: 1, name: "test", active: true };
|
|
158
|
+
const result = tokenCompressor.compressJsonProperties(smallObj);
|
|
159
|
+
expect(result).toEqual(smallObj);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
describe("compressMessage", () => {
|
|
164
|
+
it("should compress string content in messages", async () => {
|
|
165
|
+
const message: Message = {
|
|
166
|
+
role: "user",
|
|
167
|
+
content: "x".repeat(20000)
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
await tokenCompressor.compressMessage(message);
|
|
171
|
+
|
|
172
|
+
expect(message.content).toContain("[COMPRESSED_STRING");
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it("should compress text in multimodal content", async () => {
|
|
176
|
+
const message: Message = {
|
|
177
|
+
role: "user",
|
|
178
|
+
content: [
|
|
179
|
+
{ type: "text", text: "x".repeat(20000) },
|
|
180
|
+
{ type: "image_url", image_url: { url: "http://example.com/img.jpg" } }
|
|
181
|
+
]
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
await tokenCompressor.compressMessage(message);
|
|
185
|
+
|
|
186
|
+
const textContent = message.content[0] as { type: string; text: string };
|
|
187
|
+
expect(textContent.text).toContain("[COMPRESSED_STRING");
|
|
188
|
+
|
|
189
|
+
// Non-text content should remain unchanged
|
|
190
|
+
const imageContent = message.content[1] as { type: string; image_url: { url: string } };
|
|
191
|
+
expect(imageContent.image_url.url).toBe("http://example.com/img.jpg");
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("should handle messages with no content", async () => {
|
|
195
|
+
const message: Message = { role: "user" } as any;
|
|
196
|
+
await expect(tokenCompressor.compressMessage(message)).resolves.not.toThrow();
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
describe("createProcessor", () => {
|
|
201
|
+
it("should create processor that compresses all messages", async () => {
|
|
202
|
+
const processor = tokenCompressor.createProcessor();
|
|
203
|
+
const messages: Message[] = [
|
|
204
|
+
{ role: "user", content: "x".repeat(20000) },
|
|
205
|
+
{ role: "assistant", content: "short response" }
|
|
206
|
+
];
|
|
207
|
+
|
|
208
|
+
await processor([], messages);
|
|
209
|
+
|
|
210
|
+
expect(messages[0].content).toContain("[COMPRESSED_STRING");
|
|
211
|
+
expect(messages[1].content).toBe("short response"); // Should remain short
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it("should create processor with filter function", async () => {
|
|
215
|
+
const processor = tokenCompressor.createProcessor(
|
|
216
|
+
(msg) => msg.role === "user"
|
|
217
|
+
);
|
|
218
|
+
const messages: Message[] = [
|
|
219
|
+
{ role: "user", content: "x".repeat(20000) },
|
|
220
|
+
{ role: "assistant", content: "x".repeat(20000) }
|
|
221
|
+
];
|
|
222
|
+
|
|
223
|
+
await processor([], messages);
|
|
224
|
+
|
|
225
|
+
expect(messages[0].content).toContain("[COMPRESSED_STRING");
|
|
226
|
+
expect(messages[1].content).not.toContain("[COMPRESSED_STRING");
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
describe("storage operations", () => {
|
|
231
|
+
it("should store and retrieve strings", () => {
|
|
232
|
+
const key = "test_key";
|
|
233
|
+
const value = "test_value";
|
|
234
|
+
|
|
235
|
+
tokenCompressor.storeString(key, value);
|
|
236
|
+
const retrieved = tokenCompressor.retrieveString(key);
|
|
237
|
+
|
|
238
|
+
expect(retrieved).toBe(value);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it("should return null for non-existent keys", () => {
|
|
242
|
+
const result = tokenCompressor.retrieveString("non_existent");
|
|
243
|
+
expect(result).toBeNull();
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it("should clear all storage", () => {
|
|
247
|
+
tokenCompressor.storeString("key1", "value1");
|
|
248
|
+
tokenCompressor.storeString("key2", "value2");
|
|
249
|
+
|
|
250
|
+
expect(tokenCompressor.getStorageSize()).toBe(2);
|
|
251
|
+
|
|
252
|
+
tokenCompressor.clearStorage();
|
|
253
|
+
expect(tokenCompressor.getStorageSize()).toBe(0);
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
it("should return storage keys", () => {
|
|
257
|
+
tokenCompressor.storeString("key1", "value1");
|
|
258
|
+
tokenCompressor.storeString("key2", "value2");
|
|
259
|
+
|
|
260
|
+
const keys = tokenCompressor.getStorageKeys();
|
|
261
|
+
expect(keys).toContain("key1");
|
|
262
|
+
expect(keys).toContain("key2");
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
describe("configuration", () => {
|
|
267
|
+
it("should allow setting compression threshold", () => {
|
|
268
|
+
tokenCompressor.setCompressionThreshold(1000);
|
|
269
|
+
|
|
270
|
+
const content = "x".repeat(5000); // Above new threshold (5000 chars = 1250 tokens > 1000)
|
|
271
|
+
const result = tokenCompressor.compressContent(content);
|
|
272
|
+
|
|
273
|
+
expect(result).toContain("[COMPRESSED_STRING");
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
it("should adjust character limit with threshold", () => {
|
|
277
|
+
const originalThreshold = 4000;
|
|
278
|
+
const newThreshold = 2000;
|
|
279
|
+
|
|
280
|
+
tokenCompressor.setCompressionThreshold(newThreshold);
|
|
281
|
+
|
|
282
|
+
// Should compress at lower threshold
|
|
283
|
+
const content = "x".repeat(9000); // Above new threshold (9000 chars = 2250 tokens > 2000)
|
|
284
|
+
const result = tokenCompressor.compressContent(content);
|
|
285
|
+
|
|
286
|
+
expect(result).toContain("[COMPRESSED_STRING");
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
describe("tool function integration", () => {
|
|
291
|
+
it("should register expandTokens function correctly", () => {
|
|
292
|
+
const toolsServiceCalls = mockToolsService.addFunctions.mock.calls;
|
|
293
|
+
expect(toolsServiceCalls.length).toBe(1);
|
|
294
|
+
|
|
295
|
+
const functions = toolsServiceCalls[0][0];
|
|
296
|
+
expect(functions.expandTokens).toBeDefined();
|
|
297
|
+
expect(typeof functions.expandTokens).toBe("function");
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
it("should return stored data when expandTokens is called", () => {
|
|
301
|
+
const key = "test_key";
|
|
302
|
+
const value = "test_value";
|
|
303
|
+
tokenCompressor.storeString(key, value);
|
|
304
|
+
|
|
305
|
+
const toolsServiceCalls = mockToolsService.addFunctions.mock.calls;
|
|
306
|
+
const functions = toolsServiceCalls[0][0];
|
|
307
|
+
const result = functions.expandTokens(key);
|
|
308
|
+
|
|
309
|
+
expect(result).toBe(value);
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
it("should return error message for non-existent keys", () => {
|
|
313
|
+
const toolsServiceCalls = mockToolsService.addFunctions.mock.calls;
|
|
314
|
+
const functions = toolsServiceCalls[0][0];
|
|
315
|
+
const result = functions.expandTokens("non_existent");
|
|
316
|
+
|
|
317
|
+
expect(result).toContain("Error: No data found for key");
|
|
318
|
+
expect(result).toContain("Available keys:");
|
|
319
|
+
});
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
describe("edge cases", () => {
|
|
323
|
+
it("should handle empty strings", () => {
|
|
324
|
+
const result = tokenCompressor.compressContent("");
|
|
325
|
+
expect(result).toBe("");
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
it("should handle malformed JSON gracefully", () => {
|
|
329
|
+
const malformedJson = '{"incomplete": "json"'; // Missing closing brace
|
|
330
|
+
const result = tokenCompressor.compressContent(malformedJson);
|
|
331
|
+
|
|
332
|
+
// Should treat as string, not JSON
|
|
333
|
+
if (result.length > malformedJson.length) {
|
|
334
|
+
expect(result).toContain("[COMPRESSED_STRING");
|
|
335
|
+
} else {
|
|
336
|
+
expect(result).toBe(malformedJson);
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
it("should handle very large objects without stack overflow", () => {
|
|
341
|
+
const deepObject = { level: 0 } as any;
|
|
342
|
+
let current = deepObject;
|
|
343
|
+
|
|
344
|
+
// Create deeply nested object
|
|
345
|
+
for (let i = 1; i < 100; i++) {
|
|
346
|
+
current.next = { level: i, data: "x".repeat(100) };
|
|
347
|
+
current = current.next;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
expect(() => {
|
|
351
|
+
tokenCompressor.compressJsonProperties(deepObject);
|
|
352
|
+
}).not.toThrow();
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
it("should handle circular references in JSON", () => {
|
|
356
|
+
const obj: any = { name: "test" };
|
|
357
|
+
obj.self = obj; // Create circular reference
|
|
358
|
+
|
|
359
|
+
expect(() => {
|
|
360
|
+
JSON.stringify(obj); // This should throw
|
|
361
|
+
}).toThrow();
|
|
362
|
+
|
|
363
|
+
// Our compressor should handle this gracefully by not receiving circular JSON
|
|
364
|
+
const safeObj = { name: "test", data: "x".repeat(10000) };
|
|
365
|
+
expect(() => {
|
|
366
|
+
tokenCompressor.compressJsonProperties(safeObj);
|
|
367
|
+
}).not.toThrow();
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
describe("performance characteristics", () => {
|
|
372
|
+
it("should handle large arrays efficiently", () => {
|
|
373
|
+
const largeArray = new Array(1000).fill("x".repeat(100));
|
|
374
|
+
const startTime = Date.now();
|
|
375
|
+
|
|
376
|
+
tokenCompressor.compressJsonProperties(largeArray);
|
|
377
|
+
|
|
378
|
+
const duration = Date.now() - startTime;
|
|
379
|
+
expect(duration).toBeLessThan(5000); // Should complete within 5 seconds
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
it("should not compress already small content multiple times", () => {
|
|
383
|
+
const content = "small content";
|
|
384
|
+
const result1 = tokenCompressor.compressContent(content);
|
|
385
|
+
const result2 = tokenCompressor.compressContent(result1);
|
|
386
|
+
|
|
387
|
+
expect(result1).toBe(content);
|
|
388
|
+
expect(result2).toBe(content);
|
|
389
|
+
});
|
|
390
|
+
});
|
|
391
|
+
});
|