distill-mcp 0.6.0-beta
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/bin/cli.js +133 -0
- package/dist/analytics/session-tracker.d.ts +74 -0
- package/dist/analytics/session-tracker.d.ts.map +1 -0
- package/dist/analytics/session-tracker.js +123 -0
- package/dist/ast/benchmark.test.d.ts +7 -0
- package/dist/ast/benchmark.test.d.ts.map +1 -0
- package/dist/ast/benchmark.test.js +175 -0
- package/dist/ast/go/index.d.ts +9 -0
- package/dist/ast/go/index.d.ts.map +1 -0
- package/dist/ast/go/index.js +8 -0
- package/dist/ast/go/parser.d.ts +31 -0
- package/dist/ast/go/parser.d.ts.map +1 -0
- package/dist/ast/go/parser.js +428 -0
- package/dist/ast/go/parser.test.d.ts +5 -0
- package/dist/ast/go/parser.test.d.ts.map +1 -0
- package/dist/ast/go/parser.test.js +241 -0
- package/dist/ast/go/queries.d.ts +51 -0
- package/dist/ast/go/queries.d.ts.map +1 -0
- package/dist/ast/go/queries.js +114 -0
- package/dist/ast/go/utils.d.ts +66 -0
- package/dist/ast/go/utils.d.ts.map +1 -0
- package/dist/ast/go/utils.js +140 -0
- package/dist/ast/index.d.ts +39 -0
- package/dist/ast/index.d.ts.map +1 -0
- package/dist/ast/index.js +245 -0
- package/dist/ast/php/index.d.ts +9 -0
- package/dist/ast/php/index.d.ts.map +1 -0
- package/dist/ast/php/index.js +8 -0
- package/dist/ast/php/parser.d.ts +31 -0
- package/dist/ast/php/parser.d.ts.map +1 -0
- package/dist/ast/php/parser.js +388 -0
- package/dist/ast/php/parser.test.d.ts +5 -0
- package/dist/ast/php/parser.test.d.ts.map +1 -0
- package/dist/ast/php/parser.test.js +328 -0
- package/dist/ast/php/queries.d.ts +61 -0
- package/dist/ast/php/queries.d.ts.map +1 -0
- package/dist/ast/php/queries.js +117 -0
- package/dist/ast/php/utils.d.ts +83 -0
- package/dist/ast/php/utils.d.ts.map +1 -0
- package/dist/ast/php/utils.js +246 -0
- package/dist/ast/python/index.d.ts +9 -0
- package/dist/ast/python/index.d.ts.map +1 -0
- package/dist/ast/python/index.js +8 -0
- package/dist/ast/python/parser.d.ts +32 -0
- package/dist/ast/python/parser.d.ts.map +1 -0
- package/dist/ast/python/parser.js +422 -0
- package/dist/ast/python/parser.test.d.ts +5 -0
- package/dist/ast/python/parser.test.d.ts.map +1 -0
- package/dist/ast/python/parser.test.js +186 -0
- package/dist/ast/python/queries.d.ts +73 -0
- package/dist/ast/python/queries.d.ts.map +1 -0
- package/dist/ast/python/queries.js +137 -0
- package/dist/ast/python/utils.d.ts +63 -0
- package/dist/ast/python/utils.d.ts.map +1 -0
- package/dist/ast/python/utils.js +159 -0
- package/dist/ast/quick-scan.d.ts +40 -0
- package/dist/ast/quick-scan.d.ts.map +1 -0
- package/dist/ast/quick-scan.js +287 -0
- package/dist/ast/rust/index.d.ts +9 -0
- package/dist/ast/rust/index.d.ts.map +1 -0
- package/dist/ast/rust/index.js +8 -0
- package/dist/ast/rust/parser.d.ts +31 -0
- package/dist/ast/rust/parser.d.ts.map +1 -0
- package/dist/ast/rust/parser.js +416 -0
- package/dist/ast/rust/parser.test.d.ts +5 -0
- package/dist/ast/rust/parser.test.d.ts.map +1 -0
- package/dist/ast/rust/parser.test.js +329 -0
- package/dist/ast/rust/queries.d.ts +66 -0
- package/dist/ast/rust/queries.d.ts.map +1 -0
- package/dist/ast/rust/queries.js +132 -0
- package/dist/ast/rust/utils.d.ts +91 -0
- package/dist/ast/rust/utils.d.ts.map +1 -0
- package/dist/ast/rust/utils.js +254 -0
- package/dist/ast/swift/index.d.ts +10 -0
- package/dist/ast/swift/index.d.ts.map +1 -0
- package/dist/ast/swift/index.js +8 -0
- package/dist/ast/swift/parser.d.ts +31 -0
- package/dist/ast/swift/parser.d.ts.map +1 -0
- package/dist/ast/swift/parser.js +554 -0
- package/dist/ast/swift/parser.test.d.ts +5 -0
- package/dist/ast/swift/parser.test.d.ts.map +1 -0
- package/dist/ast/swift/parser.test.js +398 -0
- package/dist/ast/swift/queries.d.ts +71 -0
- package/dist/ast/swift/queries.d.ts.map +1 -0
- package/dist/ast/swift/queries.js +137 -0
- package/dist/ast/swift/utils.d.ts +94 -0
- package/dist/ast/swift/utils.d.ts.map +1 -0
- package/dist/ast/swift/utils.js +411 -0
- package/dist/ast/types.d.ts +96 -0
- package/dist/ast/types.d.ts.map +1 -0
- package/dist/ast/types.js +21 -0
- package/dist/ast/typescript.d.ts +24 -0
- package/dist/ast/typescript.d.ts.map +1 -0
- package/dist/ast/typescript.js +357 -0
- package/dist/cache/file-hash.d.ts +33 -0
- package/dist/cache/file-hash.d.ts.map +1 -0
- package/dist/cache/file-hash.js +59 -0
- package/dist/cache/index.d.ts +9 -0
- package/dist/cache/index.d.ts.map +1 -0
- package/dist/cache/index.js +8 -0
- package/dist/cache/smart-cache.d.ts +68 -0
- package/dist/cache/smart-cache.d.ts.map +1 -0
- package/dist/cache/smart-cache.js +266 -0
- package/dist/cache/types.d.ts +102 -0
- package/dist/cache/types.d.ts.map +1 -0
- package/dist/cache/types.js +6 -0
- package/dist/cli/analyze.d.ts +43 -0
- package/dist/cli/analyze.d.ts.map +1 -0
- package/dist/cli/analyze.js +250 -0
- package/dist/cli/doctor.d.ts +2 -0
- package/dist/cli/doctor.d.ts.map +1 -0
- package/dist/cli/doctor.js +127 -0
- package/dist/cli/hooks.d.ts +14 -0
- package/dist/cli/hooks.d.ts.map +1 -0
- package/dist/cli/hooks.js +229 -0
- package/dist/cli/index.d.ts +5 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +4 -0
- package/dist/cli/setup.d.ts +10 -0
- package/dist/cli/setup.d.ts.map +1 -0
- package/dist/cli/setup.js +117 -0
- package/dist/cli/utils.d.ts +30 -0
- package/dist/cli/utils.d.ts.map +1 -0
- package/dist/cli/utils.js +116 -0
- package/dist/compressors/config.d.ts +9 -0
- package/dist/compressors/config.d.ts.map +1 -0
- package/dist/compressors/config.js +183 -0
- package/dist/compressors/conversation.d.ts +109 -0
- package/dist/compressors/conversation.d.ts.map +1 -0
- package/dist/compressors/conversation.js +404 -0
- package/dist/compressors/diff.d.ts +35 -0
- package/dist/compressors/diff.d.ts.map +1 -0
- package/dist/compressors/diff.js +389 -0
- package/dist/compressors/generic.d.ts +9 -0
- package/dist/compressors/generic.d.ts.map +1 -0
- package/dist/compressors/generic.js +188 -0
- package/dist/compressors/index.d.ts +31 -0
- package/dist/compressors/index.d.ts.map +1 -0
- package/dist/compressors/index.js +82 -0
- package/dist/compressors/logs.d.ts +9 -0
- package/dist/compressors/logs.d.ts.map +1 -0
- package/dist/compressors/logs.js +245 -0
- package/dist/compressors/multifile.d.ts +106 -0
- package/dist/compressors/multifile.d.ts.map +1 -0
- package/dist/compressors/multifile.js +498 -0
- package/dist/compressors/semantic.d.ts +33 -0
- package/dist/compressors/semantic.d.ts.map +1 -0
- package/dist/compressors/semantic.js +233 -0
- package/dist/compressors/stacktrace.d.ts +9 -0
- package/dist/compressors/stacktrace.d.ts.map +1 -0
- package/dist/compressors/stacktrace.js +259 -0
- package/dist/compressors/types.d.ts +146 -0
- package/dist/compressors/types.d.ts.map +1 -0
- package/dist/compressors/types.js +6 -0
- package/dist/config/output-config.d.ts +56 -0
- package/dist/config/output-config.d.ts.map +1 -0
- package/dist/config/output-config.js +78 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/middleware/chain.d.ts +49 -0
- package/dist/middleware/chain.d.ts.map +1 -0
- package/dist/middleware/chain.js +126 -0
- package/dist/middleware/index.d.ts +4 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/index.js +3 -0
- package/dist/middleware/logging.d.ts +8 -0
- package/dist/middleware/logging.d.ts.map +1 -0
- package/dist/middleware/logging.js +71 -0
- package/dist/middleware/types.d.ts +58 -0
- package/dist/middleware/types.d.ts.map +1 -0
- package/dist/middleware/types.js +7 -0
- package/dist/parsers/eslint.d.ts +8 -0
- package/dist/parsers/eslint.d.ts.map +1 -0
- package/dist/parsers/eslint.js +132 -0
- package/dist/parsers/generic.d.ts +8 -0
- package/dist/parsers/generic.d.ts.map +1 -0
- package/dist/parsers/generic.js +234 -0
- package/dist/parsers/index.d.ts +34 -0
- package/dist/parsers/index.d.ts.map +1 -0
- package/dist/parsers/index.js +216 -0
- package/dist/parsers/types.d.ts +84 -0
- package/dist/parsers/types.d.ts.map +1 -0
- package/dist/parsers/types.js +6 -0
- package/dist/parsers/typescript.d.ts +8 -0
- package/dist/parsers/typescript.d.ts.map +1 -0
- package/dist/parsers/typescript.js +107 -0
- package/dist/pipelines/definitions.d.ts +50 -0
- package/dist/pipelines/definitions.d.ts.map +1 -0
- package/dist/pipelines/definitions.js +206 -0
- package/dist/sandbox/executor.d.ts +12 -0
- package/dist/sandbox/executor.d.ts.map +1 -0
- package/dist/sandbox/executor.js +191 -0
- package/dist/sandbox/index.d.ts +11 -0
- package/dist/sandbox/index.d.ts.map +1 -0
- package/dist/sandbox/index.js +9 -0
- package/dist/sandbox/sandbox.test.d.ts +7 -0
- package/dist/sandbox/sandbox.test.d.ts.map +1 -0
- package/dist/sandbox/sandbox.test.js +202 -0
- package/dist/sandbox/sdk/analyze.d.ts +36 -0
- package/dist/sandbox/sdk/analyze.d.ts.map +1 -0
- package/dist/sandbox/sdk/analyze.js +413 -0
- package/dist/sandbox/sdk/analyze.test.d.ts +7 -0
- package/dist/sandbox/sdk/analyze.test.d.ts.map +1 -0
- package/dist/sandbox/sdk/analyze.test.js +191 -0
- package/dist/sandbox/sdk/code.d.ts +20 -0
- package/dist/sandbox/sdk/code.d.ts.map +1 -0
- package/dist/sandbox/sdk/code.js +104 -0
- package/dist/sandbox/sdk/compress.d.ts +23 -0
- package/dist/sandbox/sdk/compress.d.ts.map +1 -0
- package/dist/sandbox/sdk/compress.js +107 -0
- package/dist/sandbox/sdk/conversation.d.ts +148 -0
- package/dist/sandbox/sdk/conversation.d.ts.map +1 -0
- package/dist/sandbox/sdk/conversation.js +177 -0
- package/dist/sandbox/sdk/files.d.ts +29 -0
- package/dist/sandbox/sdk/files.d.ts.map +1 -0
- package/dist/sandbox/sdk/files.js +41 -0
- package/dist/sandbox/sdk/git.d.ts +37 -0
- package/dist/sandbox/sdk/git.d.ts.map +1 -0
- package/dist/sandbox/sdk/git.js +313 -0
- package/dist/sandbox/sdk/git.test.d.ts +8 -0
- package/dist/sandbox/sdk/git.test.d.ts.map +1 -0
- package/dist/sandbox/sdk/git.test.js +160 -0
- package/dist/sandbox/sdk/index.d.ts +16 -0
- package/dist/sandbox/sdk/index.d.ts.map +1 -0
- package/dist/sandbox/sdk/index.js +15 -0
- package/dist/sandbox/sdk/multifile.d.ts +63 -0
- package/dist/sandbox/sdk/multifile.d.ts.map +1 -0
- package/dist/sandbox/sdk/multifile.js +130 -0
- package/dist/sandbox/sdk/pipeline.d.ts +16 -0
- package/dist/sandbox/sdk/pipeline.d.ts.map +1 -0
- package/dist/sandbox/sdk/pipeline.js +454 -0
- package/dist/sandbox/sdk/pipeline.test.d.ts +7 -0
- package/dist/sandbox/sdk/pipeline.test.d.ts.map +1 -0
- package/dist/sandbox/sdk/pipeline.test.js +197 -0
- package/dist/sandbox/sdk/search.d.ts +36 -0
- package/dist/sandbox/sdk/search.d.ts.map +1 -0
- package/dist/sandbox/sdk/search.js +338 -0
- package/dist/sandbox/sdk/search.test.d.ts +7 -0
- package/dist/sandbox/sdk/search.test.d.ts.map +1 -0
- package/dist/sandbox/sdk/search.test.js +183 -0
- package/dist/sandbox/sdk/utils.d.ts +18 -0
- package/dist/sandbox/sdk/utils.d.ts.map +1 -0
- package/dist/sandbox/sdk/utils.js +24 -0
- package/dist/sandbox/security/code-analyzer.d.ts +15 -0
- package/dist/sandbox/security/code-analyzer.d.ts.map +1 -0
- package/dist/sandbox/security/code-analyzer.js +87 -0
- package/dist/sandbox/security/index.d.ts +6 -0
- package/dist/sandbox/security/index.d.ts.map +1 -0
- package/dist/sandbox/security/index.js +5 -0
- package/dist/sandbox/security/path-validator.d.ts +23 -0
- package/dist/sandbox/security/path-validator.d.ts.map +1 -0
- package/dist/sandbox/security/path-validator.js +113 -0
- package/dist/sandbox/types.d.ts +577 -0
- package/dist/sandbox/types.d.ts.map +1 -0
- package/dist/sandbox/types.js +14 -0
- package/dist/server.d.ts +36 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +133 -0
- package/dist/summarizers/build-logs.d.ts +11 -0
- package/dist/summarizers/build-logs.d.ts.map +1 -0
- package/dist/summarizers/build-logs.js +234 -0
- package/dist/summarizers/generic.d.ts +11 -0
- package/dist/summarizers/generic.d.ts.map +1 -0
- package/dist/summarizers/generic.js +93 -0
- package/dist/summarizers/index.d.ts +20 -0
- package/dist/summarizers/index.d.ts.map +1 -0
- package/dist/summarizers/index.js +43 -0
- package/dist/summarizers/server-logs.d.ts +11 -0
- package/dist/summarizers/server-logs.d.ts.map +1 -0
- package/dist/summarizers/server-logs.js +215 -0
- package/dist/summarizers/test-logs.d.ts +11 -0
- package/dist/summarizers/test-logs.d.ts.map +1 -0
- package/dist/summarizers/test-logs.js +258 -0
- package/dist/summarizers/types.d.ts +146 -0
- package/dist/summarizers/types.d.ts.map +1 -0
- package/dist/summarizers/types.js +21 -0
- package/dist/tools/analyze-build-output.d.ts +30 -0
- package/dist/tools/analyze-build-output.d.ts.map +1 -0
- package/dist/tools/analyze-build-output.js +45 -0
- package/dist/tools/analyze-context.d.ts +23 -0
- package/dist/tools/analyze-context.d.ts.map +1 -0
- package/dist/tools/analyze-context.js +78 -0
- package/dist/tools/auto-optimize.d.ts +9 -0
- package/dist/tools/auto-optimize.d.ts.map +1 -0
- package/dist/tools/auto-optimize.js +191 -0
- package/dist/tools/code-execute.d.ts +9 -0
- package/dist/tools/code-execute.d.ts.map +1 -0
- package/dist/tools/code-execute.js +84 -0
- package/dist/tools/code-skeleton.d.ts +33 -0
- package/dist/tools/code-skeleton.d.ts.map +1 -0
- package/dist/tools/code-skeleton.js +206 -0
- package/dist/tools/compress-context.d.ts +33 -0
- package/dist/tools/compress-context.d.ts.map +1 -0
- package/dist/tools/compress-context.js +64 -0
- package/dist/tools/context-budget.d.ts +43 -0
- package/dist/tools/context-budget.d.ts.map +1 -0
- package/dist/tools/context-budget.js +260 -0
- package/dist/tools/context-budget.test.d.ts +5 -0
- package/dist/tools/context-budget.test.d.ts.map +1 -0
- package/dist/tools/context-budget.test.js +219 -0
- package/dist/tools/conversation-compress.d.ts +46 -0
- package/dist/tools/conversation-compress.d.ts.map +1 -0
- package/dist/tools/conversation-compress.js +78 -0
- package/dist/tools/conversation-memory.d.ts +75 -0
- package/dist/tools/conversation-memory.d.ts.map +1 -0
- package/dist/tools/conversation-memory.js +289 -0
- package/dist/tools/deduplicate-errors.d.ts +30 -0
- package/dist/tools/deduplicate-errors.d.ts.map +1 -0
- package/dist/tools/deduplicate-errors.js +72 -0
- package/dist/tools/detect-retry-loop.d.ts +40 -0
- package/dist/tools/detect-retry-loop.d.ts.map +1 -0
- package/dist/tools/detect-retry-loop.js +212 -0
- package/dist/tools/diff-compress.d.ts +40 -0
- package/dist/tools/diff-compress.d.ts.map +1 -0
- package/dist/tools/diff-compress.js +94 -0
- package/dist/tools/discover-tools.d.ts +11 -0
- package/dist/tools/discover-tools.d.ts.map +1 -0
- package/dist/tools/discover-tools.js +163 -0
- package/dist/tools/dynamic-loader.d.ts +131 -0
- package/dist/tools/dynamic-loader.d.ts.map +1 -0
- package/dist/tools/dynamic-loader.js +378 -0
- package/dist/tools/dynamic-loader.test.d.ts +10 -0
- package/dist/tools/dynamic-loader.test.d.ts.map +1 -0
- package/dist/tools/dynamic-loader.test.js +164 -0
- package/dist/tools/lazy-mcp.d.ts +31 -0
- package/dist/tools/lazy-mcp.d.ts.map +1 -0
- package/dist/tools/lazy-mcp.js +151 -0
- package/dist/tools/lazy-mcp.test.d.ts +10 -0
- package/dist/tools/lazy-mcp.test.d.ts.map +1 -0
- package/dist/tools/lazy-mcp.test.js +172 -0
- package/dist/tools/multifile-compress.d.ts +36 -0
- package/dist/tools/multifile-compress.d.ts.map +1 -0
- package/dist/tools/multifile-compress.js +223 -0
- package/dist/tools/optimization-tips.d.ts +18 -0
- package/dist/tools/optimization-tips.d.ts.map +1 -0
- package/dist/tools/optimization-tips.js +133 -0
- package/dist/tools/registry.d.ts +70 -0
- package/dist/tools/registry.d.ts.map +1 -0
- package/dist/tools/registry.js +169 -0
- package/dist/tools/semantic-compress.d.ts +39 -0
- package/dist/tools/semantic-compress.d.ts.map +1 -0
- package/dist/tools/semantic-compress.js +113 -0
- package/dist/tools/semantic-compress.test.d.ts +5 -0
- package/dist/tools/semantic-compress.test.d.ts.map +1 -0
- package/dist/tools/semantic-compress.test.js +182 -0
- package/dist/tools/session-stats.d.ts +34 -0
- package/dist/tools/session-stats.d.ts.map +1 -0
- package/dist/tools/session-stats.js +194 -0
- package/dist/tools/set-output-config.d.ts +38 -0
- package/dist/tools/set-output-config.d.ts.map +1 -0
- package/dist/tools/set-output-config.js +122 -0
- package/dist/tools/smart-cache-tool.d.ts +38 -0
- package/dist/tools/smart-cache-tool.d.ts.map +1 -0
- package/dist/tools/smart-cache-tool.js +224 -0
- package/dist/tools/smart-file-read.d.ts +52 -0
- package/dist/tools/smart-file-read.d.ts.map +1 -0
- package/dist/tools/smart-file-read.js +481 -0
- package/dist/tools/smart-pipeline.d.ts +40 -0
- package/dist/tools/smart-pipeline.d.ts.map +1 -0
- package/dist/tools/smart-pipeline.js +295 -0
- package/dist/tools/summarize-logs.d.ts +36 -0
- package/dist/tools/summarize-logs.d.ts.map +1 -0
- package/dist/tools/summarize-logs.js +184 -0
- package/dist/tools/token-budget.test.d.ts +11 -0
- package/dist/tools/token-budget.test.d.ts.map +1 -0
- package/dist/tools/token-budget.test.js +275 -0
- package/dist/utils/bm25.d.ts +86 -0
- package/dist/utils/bm25.d.ts.map +1 -0
- package/dist/utils/bm25.js +153 -0
- package/dist/utils/bm25.test.d.ts +5 -0
- package/dist/utils/bm25.test.d.ts.map +1 -0
- package/dist/utils/bm25.test.js +156 -0
- package/dist/utils/command-normalizer.d.ts +39 -0
- package/dist/utils/command-normalizer.d.ts.map +1 -0
- package/dist/utils/command-normalizer.js +90 -0
- package/dist/utils/content-detector.d.ts +27 -0
- package/dist/utils/content-detector.d.ts.map +1 -0
- package/dist/utils/content-detector.js +127 -0
- package/dist/utils/embeddings.d.ts +54 -0
- package/dist/utils/embeddings.d.ts.map +1 -0
- package/dist/utils/embeddings.js +97 -0
- package/dist/utils/embeddings.test.d.ts +8 -0
- package/dist/utils/embeddings.test.d.ts.map +1 -0
- package/dist/utils/embeddings.test.js +96 -0
- package/dist/utils/error-normalizer.d.ts +39 -0
- package/dist/utils/error-normalizer.d.ts.map +1 -0
- package/dist/utils/error-normalizer.js +233 -0
- package/dist/utils/hybrid-search.d.ts +79 -0
- package/dist/utils/hybrid-search.d.ts.map +1 -0
- package/dist/utils/hybrid-search.js +146 -0
- package/dist/utils/hybrid-search.test.d.ts +5 -0
- package/dist/utils/hybrid-search.test.d.ts.map +1 -0
- package/dist/utils/hybrid-search.test.js +172 -0
- package/dist/utils/index.d.ts +13 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +12 -0
- package/dist/utils/language-detector.d.ts +27 -0
- package/dist/utils/language-detector.d.ts.map +1 -0
- package/dist/utils/language-detector.js +94 -0
- package/dist/utils/log-parser.d.ts +46 -0
- package/dist/utils/log-parser.d.ts.map +1 -0
- package/dist/utils/log-parser.js +287 -0
- package/dist/utils/output-estimator.d.ts +54 -0
- package/dist/utils/output-estimator.d.ts.map +1 -0
- package/dist/utils/output-estimator.js +119 -0
- package/dist/utils/output-estimator.test.d.ts +5 -0
- package/dist/utils/output-estimator.test.d.ts.map +1 -0
- package/dist/utils/output-estimator.test.js +115 -0
- package/dist/utils/output-similarity.d.ts +48 -0
- package/dist/utils/output-similarity.d.ts.map +1 -0
- package/dist/utils/output-similarity.js +140 -0
- package/dist/utils/project-detector.d.ts +16 -0
- package/dist/utils/project-detector.d.ts.map +1 -0
- package/dist/utils/project-detector.js +119 -0
- package/dist/utils/segment-scorer.d.ts +99 -0
- package/dist/utils/segment-scorer.d.ts.map +1 -0
- package/dist/utils/segment-scorer.js +148 -0
- package/dist/utils/signature-grouper.d.ts +58 -0
- package/dist/utils/signature-grouper.d.ts.map +1 -0
- package/dist/utils/signature-grouper.js +185 -0
- package/dist/utils/tfidf.d.ts +45 -0
- package/dist/utils/tfidf.d.ts.map +1 -0
- package/dist/utils/tfidf.js +204 -0
- package/dist/utils/tfidf.test.d.ts +5 -0
- package/dist/utils/tfidf.test.d.ts.map +1 -0
- package/dist/utils/tfidf.test.js +115 -0
- package/dist/utils/token-counter.d.ts +35 -0
- package/dist/utils/token-counter.d.ts.map +1 -0
- package/dist/utils/token-counter.js +83 -0
- package/dist/utils/toon-serializer.d.ts +120 -0
- package/dist/utils/toon-serializer.d.ts.map +1 -0
- package/dist/utils/toon-serializer.js +472 -0
- package/dist/utils/toon-serializer.test.d.ts +7 -0
- package/dist/utils/toon-serializer.test.d.ts.map +1 -0
- package/dist/utils/toon-serializer.test.js +290 -0
- package/package.json +63 -0
- package/scripts/install.ps1 +133 -0
- package/scripts/install.sh +183 -0
- package/scripts/pre-commit-hook.sh +86 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export const optimizationTipsSchema = {
|
|
3
|
+
type: "object",
|
|
4
|
+
properties: {
|
|
5
|
+
focus: { type: "string", enum: ["general", "prompts", "context", "cost", "performance"] },
|
|
6
|
+
},
|
|
7
|
+
required: [],
|
|
8
|
+
};
|
|
9
|
+
const inputSchema = z.object({
|
|
10
|
+
focus: z
|
|
11
|
+
.enum(["general", "prompts", "context", "cost", "performance"])
|
|
12
|
+
.optional()
|
|
13
|
+
.default("general"),
|
|
14
|
+
});
|
|
15
|
+
const TIPS = {
|
|
16
|
+
general: `## Context Engineering Best Practices
|
|
17
|
+
|
|
18
|
+
### 1. Structure Your Context
|
|
19
|
+
- Place long documents at the **top** of your prompt
|
|
20
|
+
- Put instructions and queries **after** the context
|
|
21
|
+
- Use clear section delimiters (XML tags, markdown headers)
|
|
22
|
+
|
|
23
|
+
### 2. Be Specific
|
|
24
|
+
- Tell the model exactly what format you want
|
|
25
|
+
- Provide examples of desired output (few-shot prompting)
|
|
26
|
+
- Avoid ambiguous instructions
|
|
27
|
+
|
|
28
|
+
### 3. Optimize Token Usage
|
|
29
|
+
- Remove redundant information between messages
|
|
30
|
+
- Summarize conversation history for long sessions
|
|
31
|
+
- Use system prompts for reusable instructions
|
|
32
|
+
|
|
33
|
+
### 4. Monitor and Iterate
|
|
34
|
+
- Track token usage per request
|
|
35
|
+
- A/B test different prompt structures
|
|
36
|
+
- Measure output quality vs token cost`,
|
|
37
|
+
prompts: `## Prompt Optimization Tips
|
|
38
|
+
|
|
39
|
+
### System Prompts
|
|
40
|
+
- Keep system prompts concise but complete
|
|
41
|
+
- Extract role definitions to system prompt (saves input tokens)
|
|
42
|
+
- Avoid repeating instructions in every user message
|
|
43
|
+
|
|
44
|
+
### User Messages
|
|
45
|
+
- Front-load the most important information
|
|
46
|
+
- Use structured formats (JSON, XML) for complex inputs
|
|
47
|
+
- Reference previous context instead of repeating it
|
|
48
|
+
|
|
49
|
+
### Few-Shot Examples
|
|
50
|
+
- 2-3 examples usually suffice
|
|
51
|
+
- Choose diverse, representative examples
|
|
52
|
+
- Format examples exactly like expected output
|
|
53
|
+
|
|
54
|
+
### Prompt Templates
|
|
55
|
+
- Create reusable templates for common tasks
|
|
56
|
+
- Use placeholders for variable content
|
|
57
|
+
- Test templates with edge cases`,
|
|
58
|
+
context: `## Context Management Tips
|
|
59
|
+
|
|
60
|
+
### Long Conversations
|
|
61
|
+
- Summarize every 5-10 messages
|
|
62
|
+
- Keep only relevant message history
|
|
63
|
+
- Use a "memory" system prompt for key facts
|
|
64
|
+
|
|
65
|
+
### RAG (Retrieval-Augmented Generation)
|
|
66
|
+
- Retrieve only the most relevant chunks
|
|
67
|
+
- Limit context to 3-5 relevant documents
|
|
68
|
+
- Order by relevance, most relevant first
|
|
69
|
+
|
|
70
|
+
### Code Context
|
|
71
|
+
- Include only relevant files/functions
|
|
72
|
+
- Use file paths as references instead of full content
|
|
73
|
+
- Summarize unchanged files
|
|
74
|
+
|
|
75
|
+
### Multi-Agent Patterns
|
|
76
|
+
- Split context across specialized agents
|
|
77
|
+
- Each agent handles specific sub-tasks
|
|
78
|
+
- Reduces per-agent context size`,
|
|
79
|
+
cost: `## Cost Optimization Tips
|
|
80
|
+
|
|
81
|
+
### Model Selection
|
|
82
|
+
- Use Haiku for simple tasks (5x cheaper than Sonnet)
|
|
83
|
+
- Reserve Opus for complex reasoning
|
|
84
|
+
- Route based on task complexity
|
|
85
|
+
|
|
86
|
+
### Caching
|
|
87
|
+
- Cache common prompts and responses
|
|
88
|
+
- Use prompt caching for repeated prefixes
|
|
89
|
+
- Anthropic prompt caching: 90% discount on cached tokens
|
|
90
|
+
|
|
91
|
+
### Batch Processing
|
|
92
|
+
- Use Batch API for non-urgent requests (50% discount)
|
|
93
|
+
- Group similar requests together
|
|
94
|
+
- Process during off-peak hours
|
|
95
|
+
|
|
96
|
+
### Output Optimization
|
|
97
|
+
- Set max_tokens appropriately
|
|
98
|
+
- Request concise responses when possible
|
|
99
|
+
- Output tokens cost 5x more than input`,
|
|
100
|
+
performance: `## Performance Optimization Tips
|
|
101
|
+
|
|
102
|
+
### Latency Reduction
|
|
103
|
+
- Use streaming for better perceived performance
|
|
104
|
+
- Pre-compute and cache common responses
|
|
105
|
+
- Minimize round-trips with comprehensive prompts
|
|
106
|
+
|
|
107
|
+
### Throughput
|
|
108
|
+
- Use async/parallel requests when possible
|
|
109
|
+
- Implement request queuing for rate limits
|
|
110
|
+
- Monitor and respect API limits
|
|
111
|
+
|
|
112
|
+
### Reliability
|
|
113
|
+
- Implement exponential backoff for retries
|
|
114
|
+
- Handle streaming errors gracefully
|
|
115
|
+
- Cache responses for idempotent requests
|
|
116
|
+
|
|
117
|
+
### Context Window
|
|
118
|
+
- Stay under 50% of max context for best performance
|
|
119
|
+
- Performance degrades significantly above 80%
|
|
120
|
+
- Consider chunking for very long documents`,
|
|
121
|
+
};
|
|
122
|
+
export async function optimizationTips(args, _config) {
|
|
123
|
+
const { focus } = inputSchema.parse(args);
|
|
124
|
+
const tips = TIPS[focus];
|
|
125
|
+
const result = `${tips}
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
*Tips from CtxOpt - Context Engineering Optimizer*
|
|
129
|
+
*Learn more at https://ctxopt.dev*`;
|
|
130
|
+
return {
|
|
131
|
+
content: [{ type: "text", text: result }],
|
|
132
|
+
};
|
|
133
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tools Registry
|
|
3
|
+
*
|
|
4
|
+
* Central registry for all MCP tools with unified execution.
|
|
5
|
+
*/
|
|
6
|
+
import type { ToolResult } from "../middleware/types.js";
|
|
7
|
+
import type { MiddlewareChain } from "../middleware/chain.js";
|
|
8
|
+
export interface ToolDefinition {
|
|
9
|
+
name: string;
|
|
10
|
+
description: string;
|
|
11
|
+
inputSchema: Record<string, unknown>;
|
|
12
|
+
execute: (args: unknown) => Promise<ToolExecuteResult>;
|
|
13
|
+
}
|
|
14
|
+
export interface ToolExecuteResult {
|
|
15
|
+
content: Array<{
|
|
16
|
+
type: "text";
|
|
17
|
+
text: string;
|
|
18
|
+
}>;
|
|
19
|
+
isError?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export declare class ToolRegistry {
|
|
22
|
+
private tools;
|
|
23
|
+
private middlewareChain;
|
|
24
|
+
private changeCallbacks;
|
|
25
|
+
/**
|
|
26
|
+
* Set the middleware chain to use for tool execution
|
|
27
|
+
*/
|
|
28
|
+
setMiddlewareChain(chain: MiddlewareChain): void;
|
|
29
|
+
/**
|
|
30
|
+
* Register callback for tool list changes
|
|
31
|
+
*/
|
|
32
|
+
onToolsChanged(callback: () => void): void;
|
|
33
|
+
/**
|
|
34
|
+
* Emit tool list change notification
|
|
35
|
+
*/
|
|
36
|
+
private emitChange;
|
|
37
|
+
/**
|
|
38
|
+
* Register a tool
|
|
39
|
+
*/
|
|
40
|
+
register(tool: ToolDefinition): this;
|
|
41
|
+
/**
|
|
42
|
+
* Unregister a tool
|
|
43
|
+
*/
|
|
44
|
+
unregister(name: string): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Get a tool by name
|
|
47
|
+
*/
|
|
48
|
+
get(name: string): ToolDefinition | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* List all registered tools
|
|
51
|
+
*/
|
|
52
|
+
list(): ToolDefinition[];
|
|
53
|
+
/**
|
|
54
|
+
* Get tool definitions for MCP ListTools response
|
|
55
|
+
*/
|
|
56
|
+
getToolDefinitions(): Array<{
|
|
57
|
+
name: string;
|
|
58
|
+
description: string;
|
|
59
|
+
inputSchema: Record<string, unknown>;
|
|
60
|
+
}>;
|
|
61
|
+
/**
|
|
62
|
+
* Execute a tool with middleware chain
|
|
63
|
+
*/
|
|
64
|
+
execute(name: string, args: unknown): Promise<ToolResult>;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Create a new tool registry instance
|
|
68
|
+
*/
|
|
69
|
+
export declare function createToolRegistry(): ToolRegistry;
|
|
70
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/tools/registry.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAe,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAG9D,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,OAAO,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAC;CACxD;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/C,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,KAAK,CAA0C;IACvD,OAAO,CAAC,eAAe,CAAgC;IACvD,OAAO,CAAC,eAAe,CAAyB;IAEhD;;OAEG;IACH,kBAAkB,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI;IAIhD;;OAEG;IACH,cAAc,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI;IAI1C;;OAEG;IACH,OAAO,CAAC,UAAU;IAUlB;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI;IAMpC;;OAEG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAQjC;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;IAI7C;;OAEG;IACH,IAAI,IAAI,cAAc,EAAE;IAIxB;;OAEG;IACH,kBAAkB,IAAI,KAAK,CAAC;QAC1B,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,MAAM,CAAC;QACpB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACtC,CAAC;IAQF;;OAEG;IACG,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC;CA6FhE;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,YAAY,CAEjD"}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tools Registry
|
|
3
|
+
*
|
|
4
|
+
* Central registry for all MCP tools with unified execution.
|
|
5
|
+
*/
|
|
6
|
+
import { countTokens } from "../utils/token-counter.js";
|
|
7
|
+
export class ToolRegistry {
|
|
8
|
+
tools = new Map();
|
|
9
|
+
middlewareChain = null;
|
|
10
|
+
changeCallbacks = [];
|
|
11
|
+
/**
|
|
12
|
+
* Set the middleware chain to use for tool execution
|
|
13
|
+
*/
|
|
14
|
+
setMiddlewareChain(chain) {
|
|
15
|
+
this.middlewareChain = chain;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Register callback for tool list changes
|
|
19
|
+
*/
|
|
20
|
+
onToolsChanged(callback) {
|
|
21
|
+
this.changeCallbacks.push(callback);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Emit tool list change notification
|
|
25
|
+
*/
|
|
26
|
+
emitChange() {
|
|
27
|
+
for (const cb of this.changeCallbacks) {
|
|
28
|
+
try {
|
|
29
|
+
cb();
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
// Ignore callback errors
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Register a tool
|
|
38
|
+
*/
|
|
39
|
+
register(tool) {
|
|
40
|
+
this.tools.set(tool.name, tool);
|
|
41
|
+
this.emitChange();
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Unregister a tool
|
|
46
|
+
*/
|
|
47
|
+
unregister(name) {
|
|
48
|
+
const result = this.tools.delete(name);
|
|
49
|
+
if (result) {
|
|
50
|
+
this.emitChange();
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Get a tool by name
|
|
56
|
+
*/
|
|
57
|
+
get(name) {
|
|
58
|
+
return this.tools.get(name);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* List all registered tools
|
|
62
|
+
*/
|
|
63
|
+
list() {
|
|
64
|
+
return Array.from(this.tools.values());
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Get tool definitions for MCP ListTools response
|
|
68
|
+
*/
|
|
69
|
+
getToolDefinitions() {
|
|
70
|
+
return this.list().map((tool) => ({
|
|
71
|
+
name: tool.name,
|
|
72
|
+
description: tool.description,
|
|
73
|
+
inputSchema: tool.inputSchema,
|
|
74
|
+
}));
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Execute a tool with middleware chain
|
|
78
|
+
*/
|
|
79
|
+
async execute(name, args) {
|
|
80
|
+
const tool = this.tools.get(name);
|
|
81
|
+
if (!tool) {
|
|
82
|
+
return {
|
|
83
|
+
content: [{ type: "text", text: `Unknown tool: ${name}` }],
|
|
84
|
+
isError: true,
|
|
85
|
+
tokensIn: 0,
|
|
86
|
+
tokensOut: 0,
|
|
87
|
+
tokensSaved: 0,
|
|
88
|
+
wasFiltered: false,
|
|
89
|
+
metadata: {},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
// Count input tokens using centralized counter
|
|
93
|
+
const inputText = JSON.stringify(args);
|
|
94
|
+
const tokensIn = countTokens(inputText);
|
|
95
|
+
// Create tool context with error tracking
|
|
96
|
+
const ctx = {
|
|
97
|
+
toolName: name,
|
|
98
|
+
arguments: args,
|
|
99
|
+
startTime: Date.now(),
|
|
100
|
+
metadata: {},
|
|
101
|
+
middlewareErrors: [],
|
|
102
|
+
};
|
|
103
|
+
try {
|
|
104
|
+
// Execute beforeTool middlewares
|
|
105
|
+
let currentCtx = ctx;
|
|
106
|
+
if (this.middlewareChain) {
|
|
107
|
+
currentCtx = await this.middlewareChain.executeBefore(ctx);
|
|
108
|
+
if (currentCtx === null) {
|
|
109
|
+
// Middleware skipped execution
|
|
110
|
+
return {
|
|
111
|
+
content: [{ type: "text", text: "Tool execution skipped by middleware" }],
|
|
112
|
+
isError: false,
|
|
113
|
+
tokensIn,
|
|
114
|
+
tokensOut: 0,
|
|
115
|
+
tokensSaved: 0,
|
|
116
|
+
wasFiltered: true,
|
|
117
|
+
metadata: { skippedBy: "middleware" },
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// Execute tool
|
|
122
|
+
const executeResult = await tool.execute(currentCtx.arguments);
|
|
123
|
+
// Count output tokens using centralized counter
|
|
124
|
+
const outputText = executeResult.content.map((c) => c.text).join("\n");
|
|
125
|
+
const tokensOut = countTokens(outputText);
|
|
126
|
+
// Create result
|
|
127
|
+
let result = {
|
|
128
|
+
content: executeResult.content,
|
|
129
|
+
isError: executeResult.isError ?? false,
|
|
130
|
+
tokensIn,
|
|
131
|
+
tokensOut,
|
|
132
|
+
tokensSaved: 0,
|
|
133
|
+
wasFiltered: false,
|
|
134
|
+
metadata: {},
|
|
135
|
+
};
|
|
136
|
+
// Execute afterTool middlewares
|
|
137
|
+
if (this.middlewareChain) {
|
|
138
|
+
result = await this.middlewareChain.executeAfter(currentCtx, result);
|
|
139
|
+
}
|
|
140
|
+
return result;
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
144
|
+
// Try to handle error with middleware
|
|
145
|
+
if (this.middlewareChain) {
|
|
146
|
+
const handledResult = await this.middlewareChain.executeOnError(ctx, err);
|
|
147
|
+
if (handledResult) {
|
|
148
|
+
return handledResult;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
// Return error result
|
|
152
|
+
return {
|
|
153
|
+
content: [{ type: "text", text: `Error executing ${name}: ${err.message}` }],
|
|
154
|
+
isError: true,
|
|
155
|
+
tokensIn,
|
|
156
|
+
tokensOut: 0,
|
|
157
|
+
tokensSaved: 0,
|
|
158
|
+
wasFiltered: false,
|
|
159
|
+
metadata: { error: err.message },
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Create a new tool registry instance
|
|
166
|
+
*/
|
|
167
|
+
export function createToolRegistry() {
|
|
168
|
+
return new ToolRegistry();
|
|
169
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Semantic Compress Tool
|
|
3
|
+
*
|
|
4
|
+
* Intelligently compress content by extracting the most important segments
|
|
5
|
+
* using TF-IDF scoring, position weighting, and keyword detection.
|
|
6
|
+
*
|
|
7
|
+
* Phase 2: Rule-based implementation (no ML models)
|
|
8
|
+
*/
|
|
9
|
+
import type { ToolDefinition } from "./registry.js";
|
|
10
|
+
/**
|
|
11
|
+
* JSON Schema for MCP tool registration
|
|
12
|
+
*/
|
|
13
|
+
export declare const semanticCompressSchema: {
|
|
14
|
+
type: "object";
|
|
15
|
+
properties: {
|
|
16
|
+
content: {
|
|
17
|
+
type: string;
|
|
18
|
+
};
|
|
19
|
+
targetRatio: {
|
|
20
|
+
type: string;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
required: string[];
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Execute semantic compression
|
|
27
|
+
*/
|
|
28
|
+
export declare function executeSemanticCompress(args: unknown): Promise<{
|
|
29
|
+
content: Array<{
|
|
30
|
+
type: "text";
|
|
31
|
+
text: string;
|
|
32
|
+
}>;
|
|
33
|
+
isError?: boolean;
|
|
34
|
+
}>;
|
|
35
|
+
/**
|
|
36
|
+
* Tool definition for MCP registration
|
|
37
|
+
*/
|
|
38
|
+
export declare const semanticCompressTool: ToolDefinition;
|
|
39
|
+
//# sourceMappingURL=semantic-compress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"semantic-compress.d.ts","sourceRoot":"","sources":["../../src/tools/semantic-compress.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAMpD;;GAEG;AAEH,eAAO,MAAM,sBAAsB;;;;;;;;;;;CAOlC,CAAC;AAmCF;;GAEG;AACH,wBAAsB,uBAAuB,CAC3C,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC;IAAE,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC,CAgEhF;AAED;;GAEG;AACH,eAAO,MAAM,oBAAoB,EAAE,cAKlC,CAAC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Semantic Compress Tool
|
|
3
|
+
*
|
|
4
|
+
* Intelligently compress content by extracting the most important segments
|
|
5
|
+
* using TF-IDF scoring, position weighting, and keyword detection.
|
|
6
|
+
*
|
|
7
|
+
* Phase 2: Rule-based implementation (no ML models)
|
|
8
|
+
*/
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
import { semanticCompressor, } from "../compressors/semantic.js";
|
|
11
|
+
/**
|
|
12
|
+
* JSON Schema for MCP tool registration
|
|
13
|
+
*/
|
|
14
|
+
// Minimal schema - model has only one value, preservePatterns rarely used
|
|
15
|
+
export const semanticCompressSchema = {
|
|
16
|
+
type: "object",
|
|
17
|
+
properties: {
|
|
18
|
+
content: { type: "string" },
|
|
19
|
+
targetRatio: { type: "number" },
|
|
20
|
+
},
|
|
21
|
+
required: ["content"],
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Zod schema for runtime input validation
|
|
25
|
+
*/
|
|
26
|
+
const inputSchema = z.object({
|
|
27
|
+
content: z.string().min(1, "Content is required"),
|
|
28
|
+
targetRatio: z.number().min(0.1).max(0.9).optional().default(0.5),
|
|
29
|
+
preservePatterns: z.array(z.string()).optional(),
|
|
30
|
+
model: z.enum(["fast"]).optional().default("fast"),
|
|
31
|
+
});
|
|
32
|
+
/**
|
|
33
|
+
* Format the compression result - minimal header to save tokens
|
|
34
|
+
*/
|
|
35
|
+
function formatOutput(result, _technique) {
|
|
36
|
+
const savingsPercent = result.originalTokens > 0
|
|
37
|
+
? Math.round((result.savings / result.originalTokens) * 100)
|
|
38
|
+
: 0;
|
|
39
|
+
const header = `[semantic] ${result.originalTokens}→${result.compressedTokens} tokens (-${savingsPercent}%)`;
|
|
40
|
+
return `${header}\n${result.compressed}`;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Execute semantic compression
|
|
44
|
+
*/
|
|
45
|
+
export async function executeSemanticCompress(args) {
|
|
46
|
+
// Validate input
|
|
47
|
+
const parseResult = inputSchema.safeParse(args);
|
|
48
|
+
if (!parseResult.success) {
|
|
49
|
+
return {
|
|
50
|
+
content: [
|
|
51
|
+
{
|
|
52
|
+
type: "text",
|
|
53
|
+
text: `Invalid input: ${parseResult.error.errors.map((e) => e.message).join(", ")}`,
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
isError: true,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
const input = parseResult.data;
|
|
60
|
+
// Convert preserve patterns to RegExp
|
|
61
|
+
let preservePatterns;
|
|
62
|
+
if (input.preservePatterns) {
|
|
63
|
+
try {
|
|
64
|
+
preservePatterns = input.preservePatterns.map((p) => new RegExp(p, "i"));
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
const error = e;
|
|
68
|
+
return {
|
|
69
|
+
content: [
|
|
70
|
+
{
|
|
71
|
+
type: "text",
|
|
72
|
+
text: `Invalid regex pattern: ${error.message}`,
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
isError: true,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// Run semantic compression
|
|
80
|
+
const result = semanticCompressor.compress(input.content, {
|
|
81
|
+
targetRatio: input.targetRatio,
|
|
82
|
+
preservePatterns,
|
|
83
|
+
detail: "normal",
|
|
84
|
+
});
|
|
85
|
+
// Build output
|
|
86
|
+
const output = {
|
|
87
|
+
compressed: result.compressed,
|
|
88
|
+
originalTokens: result.stats.originalTokens,
|
|
89
|
+
compressedTokens: result.stats.compressedTokens,
|
|
90
|
+
savings: result.stats.originalTokens - result.stats.compressedTokens,
|
|
91
|
+
preservedSegments: result.preservedSegments ?? [],
|
|
92
|
+
};
|
|
93
|
+
// Update session state with tokens saved
|
|
94
|
+
if (output.savings > 0) {
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
content: [
|
|
98
|
+
{
|
|
99
|
+
type: "text",
|
|
100
|
+
text: formatOutput(output, result.stats.technique),
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Tool definition for MCP registration
|
|
107
|
+
*/
|
|
108
|
+
export const semanticCompressTool = {
|
|
109
|
+
name: "semantic_compress",
|
|
110
|
+
description: "TF-IDF compression. Keeps important segments by relevance scoring.",
|
|
111
|
+
inputSchema: semanticCompressSchema,
|
|
112
|
+
execute: executeSemanticCompress,
|
|
113
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"semantic-compress.test.d.ts","sourceRoot":"","sources":["../../src/tools/semantic-compress.test.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|