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,266 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Smart Cache Implementation
|
|
3
|
+
*
|
|
4
|
+
* LRU cache with TTL and file hash validation.
|
|
5
|
+
* Designed for caching parsed file content but works for any data.
|
|
6
|
+
*/
|
|
7
|
+
import { computeFastFileHash, validateFileHash } from "./file-hash.js";
|
|
8
|
+
/** Default cache configuration */
|
|
9
|
+
const DEFAULT_CONFIG = {
|
|
10
|
+
maxEntries: 100,
|
|
11
|
+
defaultTtlMs: 30 * 60 * 1000, // 30 minutes
|
|
12
|
+
maxMemoryBytes: 50 * 1024 * 1024, // 50MB
|
|
13
|
+
enableFileHashValidation: true,
|
|
14
|
+
cleanupInterval: 50,
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Smart Cache class with LRU eviction, TTL expiration, and file hash validation
|
|
18
|
+
*/
|
|
19
|
+
export class SmartCache {
|
|
20
|
+
cache;
|
|
21
|
+
config;
|
|
22
|
+
stats;
|
|
23
|
+
operationCount;
|
|
24
|
+
constructor(config = {}) {
|
|
25
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
26
|
+
this.cache = new Map();
|
|
27
|
+
this.operationCount = 0;
|
|
28
|
+
this.stats = {
|
|
29
|
+
entries: 0,
|
|
30
|
+
hits: 0,
|
|
31
|
+
misses: 0,
|
|
32
|
+
hitRate: 0,
|
|
33
|
+
tokensSaved: 0,
|
|
34
|
+
memorySizeBytes: 0,
|
|
35
|
+
evictions: 0,
|
|
36
|
+
invalidations: 0,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Get a value from cache with automatic validation
|
|
41
|
+
*/
|
|
42
|
+
async get(key) {
|
|
43
|
+
this.operationCount++;
|
|
44
|
+
this.maybeCleanup();
|
|
45
|
+
const entry = this.cache.get(key);
|
|
46
|
+
if (!entry) {
|
|
47
|
+
this.stats.misses++;
|
|
48
|
+
this.updateHitRate();
|
|
49
|
+
return { hit: false, missReason: "not_found" };
|
|
50
|
+
}
|
|
51
|
+
// Check TTL expiration
|
|
52
|
+
const ttl = entry.ttl ?? this.config.defaultTtlMs;
|
|
53
|
+
const age = Date.now() - entry.createdAt;
|
|
54
|
+
if (age > ttl) {
|
|
55
|
+
this.cache.delete(key);
|
|
56
|
+
this.stats.entries--;
|
|
57
|
+
this.stats.memorySizeBytes -= entry.sizeBytes;
|
|
58
|
+
this.stats.misses++;
|
|
59
|
+
this.updateHitRate();
|
|
60
|
+
return { hit: false, missReason: "expired" };
|
|
61
|
+
}
|
|
62
|
+
// Check file hash validation (if applicable)
|
|
63
|
+
if (this.config.enableFileHashValidation &&
|
|
64
|
+
entry.filePath &&
|
|
65
|
+
entry.fileHash) {
|
|
66
|
+
const isValid = await validateFileHash(entry.filePath, entry.fileHash);
|
|
67
|
+
if (!isValid) {
|
|
68
|
+
this.cache.delete(key);
|
|
69
|
+
this.stats.entries--;
|
|
70
|
+
this.stats.memorySizeBytes -= entry.sizeBytes;
|
|
71
|
+
this.stats.invalidations++;
|
|
72
|
+
this.stats.misses++;
|
|
73
|
+
this.updateHitRate();
|
|
74
|
+
return { hit: false, missReason: "file_changed" };
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// Update last accessed time (for LRU)
|
|
78
|
+
entry.lastAccessedAt = Date.now();
|
|
79
|
+
// Update stats
|
|
80
|
+
this.stats.hits++;
|
|
81
|
+
if (entry.tokenCount) {
|
|
82
|
+
this.stats.tokensSaved += entry.tokenCount;
|
|
83
|
+
}
|
|
84
|
+
this.updateHitRate();
|
|
85
|
+
return { hit: true, value: entry.value };
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Set a value in cache
|
|
89
|
+
*/
|
|
90
|
+
async set(key, value, options = {}) {
|
|
91
|
+
this.operationCount++;
|
|
92
|
+
// Compute size estimate
|
|
93
|
+
const sizeBytes = this.estimateSize(value);
|
|
94
|
+
// Compute file hash if path provided
|
|
95
|
+
let fileHash = options.fileHash;
|
|
96
|
+
if (!fileHash &&
|
|
97
|
+
options.filePath &&
|
|
98
|
+
this.config.enableFileHashValidation) {
|
|
99
|
+
const hashInfo = await computeFastFileHash(options.filePath);
|
|
100
|
+
fileHash = hashInfo?.hash;
|
|
101
|
+
}
|
|
102
|
+
// Check if we need to evict entries
|
|
103
|
+
await this.ensureCapacity(sizeBytes);
|
|
104
|
+
const entry = {
|
|
105
|
+
value,
|
|
106
|
+
createdAt: Date.now(),
|
|
107
|
+
lastAccessedAt: Date.now(),
|
|
108
|
+
ttl: options.ttl,
|
|
109
|
+
fileHash,
|
|
110
|
+
filePath: options.filePath,
|
|
111
|
+
sizeBytes,
|
|
112
|
+
tokenCount: options.tokenCount,
|
|
113
|
+
};
|
|
114
|
+
// Remove old entry stats if exists
|
|
115
|
+
const existing = this.cache.get(key);
|
|
116
|
+
if (existing) {
|
|
117
|
+
this.stats.memorySizeBytes -= existing.sizeBytes;
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
this.stats.entries++;
|
|
121
|
+
}
|
|
122
|
+
this.cache.set(key, entry);
|
|
123
|
+
this.stats.memorySizeBytes += sizeBytes;
|
|
124
|
+
this.maybeCleanup();
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Invalidate a specific cache entry
|
|
128
|
+
*/
|
|
129
|
+
invalidate(key) {
|
|
130
|
+
const entry = this.cache.get(key);
|
|
131
|
+
if (entry) {
|
|
132
|
+
this.cache.delete(key);
|
|
133
|
+
this.stats.entries--;
|
|
134
|
+
this.stats.memorySizeBytes -= entry.sizeBytes;
|
|
135
|
+
this.stats.invalidations++;
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Invalidate all entries for a specific file path
|
|
142
|
+
*/
|
|
143
|
+
invalidateByPath(filePath) {
|
|
144
|
+
let count = 0;
|
|
145
|
+
for (const [key, entry] of this.cache.entries()) {
|
|
146
|
+
if (entry.filePath === filePath) {
|
|
147
|
+
this.cache.delete(key);
|
|
148
|
+
this.stats.entries--;
|
|
149
|
+
this.stats.memorySizeBytes -= entry.sizeBytes;
|
|
150
|
+
this.stats.invalidations++;
|
|
151
|
+
count++;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return count;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Clear all cache entries
|
|
158
|
+
*/
|
|
159
|
+
clear() {
|
|
160
|
+
this.cache.clear();
|
|
161
|
+
this.stats.entries = 0;
|
|
162
|
+
this.stats.memorySizeBytes = 0;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Get cache statistics
|
|
166
|
+
*/
|
|
167
|
+
getStats() {
|
|
168
|
+
return { ...this.stats };
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Get list of cached keys (for debugging/inspection)
|
|
172
|
+
*/
|
|
173
|
+
getKeys() {
|
|
174
|
+
return Array.from(this.cache.keys());
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Check if a key exists (without updating access time)
|
|
178
|
+
*/
|
|
179
|
+
has(key) {
|
|
180
|
+
return this.cache.has(key);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Get the number of entries in cache
|
|
184
|
+
*/
|
|
185
|
+
get size() {
|
|
186
|
+
return this.cache.size;
|
|
187
|
+
}
|
|
188
|
+
// Private methods
|
|
189
|
+
updateHitRate() {
|
|
190
|
+
const total = this.stats.hits + this.stats.misses;
|
|
191
|
+
this.stats.hitRate =
|
|
192
|
+
total > 0 ? Math.round((this.stats.hits / total) * 1000) / 10 : 0;
|
|
193
|
+
}
|
|
194
|
+
estimateSize(value) {
|
|
195
|
+
// Rough estimation based on JSON serialization
|
|
196
|
+
try {
|
|
197
|
+
const json = JSON.stringify(value);
|
|
198
|
+
return json.length * 2; // UTF-16 encoding
|
|
199
|
+
}
|
|
200
|
+
catch {
|
|
201
|
+
return 1024; // Default 1KB for non-serializable
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
async ensureCapacity(newEntrySize) {
|
|
205
|
+
// Check entry count limit
|
|
206
|
+
while (this.cache.size >= this.config.maxEntries) {
|
|
207
|
+
this.evictLRU();
|
|
208
|
+
}
|
|
209
|
+
// Check memory limit
|
|
210
|
+
while (this.stats.memorySizeBytes + newEntrySize > this.config.maxMemoryBytes &&
|
|
211
|
+
this.cache.size > 0) {
|
|
212
|
+
this.evictLRU();
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
evictLRU() {
|
|
216
|
+
let oldestKey = null;
|
|
217
|
+
let oldestTime = Infinity;
|
|
218
|
+
for (const [key, entry] of this.cache.entries()) {
|
|
219
|
+
if (entry.lastAccessedAt < oldestTime) {
|
|
220
|
+
oldestTime = entry.lastAccessedAt;
|
|
221
|
+
oldestKey = key;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
if (oldestKey) {
|
|
225
|
+
const entry = this.cache.get(oldestKey);
|
|
226
|
+
this.cache.delete(oldestKey);
|
|
227
|
+
this.stats.entries--;
|
|
228
|
+
this.stats.memorySizeBytes -= entry.sizeBytes;
|
|
229
|
+
this.stats.evictions++;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
maybeCleanup() {
|
|
233
|
+
if (this.operationCount % this.config.cleanupInterval !== 0) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
this.cleanupExpired();
|
|
237
|
+
}
|
|
238
|
+
cleanupExpired() {
|
|
239
|
+
const now = Date.now();
|
|
240
|
+
for (const [key, entry] of this.cache.entries()) {
|
|
241
|
+
const ttl = entry.ttl ?? this.config.defaultTtlMs;
|
|
242
|
+
if (now - entry.createdAt > ttl) {
|
|
243
|
+
this.cache.delete(key);
|
|
244
|
+
this.stats.entries--;
|
|
245
|
+
this.stats.memorySizeBytes -= entry.sizeBytes;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
// Singleton instance for session-wide caching
|
|
251
|
+
let globalCache = null;
|
|
252
|
+
/**
|
|
253
|
+
* Get the global cache instance (creates one if needed)
|
|
254
|
+
*/
|
|
255
|
+
export function getGlobalCache() {
|
|
256
|
+
if (!globalCache) {
|
|
257
|
+
globalCache = new SmartCache();
|
|
258
|
+
}
|
|
259
|
+
return globalCache;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Reset the global cache (for testing or explicit reset)
|
|
263
|
+
*/
|
|
264
|
+
export function resetGlobalCache() {
|
|
265
|
+
globalCache = null;
|
|
266
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Smart Cache Types
|
|
3
|
+
*
|
|
4
|
+
* Type definitions for the LRU cache with TTL and file hash validation.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* A single cache entry with metadata
|
|
8
|
+
*/
|
|
9
|
+
export interface CacheEntry<T = unknown> {
|
|
10
|
+
/** The cached value */
|
|
11
|
+
value: T;
|
|
12
|
+
/** When this entry was created (timestamp) */
|
|
13
|
+
createdAt: number;
|
|
14
|
+
/** When this entry was last accessed (for LRU eviction) */
|
|
15
|
+
lastAccessedAt: number;
|
|
16
|
+
/** TTL in milliseconds (entry-specific, overrides default) */
|
|
17
|
+
ttl?: number;
|
|
18
|
+
/** File hash for validation (optional, used for file-based caches) */
|
|
19
|
+
fileHash?: string;
|
|
20
|
+
/** Original file path (if applicable) */
|
|
21
|
+
filePath?: string;
|
|
22
|
+
/** Size in bytes (approximate, for memory tracking) */
|
|
23
|
+
sizeBytes: number;
|
|
24
|
+
/** Token count (for stats tracking) */
|
|
25
|
+
tokenCount?: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Cache statistics
|
|
29
|
+
*/
|
|
30
|
+
export interface CacheStats {
|
|
31
|
+
/** Total number of entries */
|
|
32
|
+
entries: number;
|
|
33
|
+
/** Cache hits since session start */
|
|
34
|
+
hits: number;
|
|
35
|
+
/** Cache misses since session start */
|
|
36
|
+
misses: number;
|
|
37
|
+
/** Hit rate percentage (0-100) */
|
|
38
|
+
hitRate: number;
|
|
39
|
+
/** Total tokens saved via cache hits */
|
|
40
|
+
tokensSaved: number;
|
|
41
|
+
/** Approximate memory usage in bytes */
|
|
42
|
+
memorySizeBytes: number;
|
|
43
|
+
/** Number of entries evicted (LRU or TTL) */
|
|
44
|
+
evictions: number;
|
|
45
|
+
/** Number of entries invalidated due to file change */
|
|
46
|
+
invalidations: number;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Cache configuration options
|
|
50
|
+
*/
|
|
51
|
+
export interface CacheConfig {
|
|
52
|
+
/** Maximum number of entries (default: 100) */
|
|
53
|
+
maxEntries: number;
|
|
54
|
+
/** Default TTL in milliseconds (default: 30 minutes) */
|
|
55
|
+
defaultTtlMs: number;
|
|
56
|
+
/** Maximum memory size in bytes (default: 50MB) */
|
|
57
|
+
maxMemoryBytes: number;
|
|
58
|
+
/** Enable file hash validation (default: true) */
|
|
59
|
+
enableFileHashValidation: boolean;
|
|
60
|
+
/** Cleanup interval in operations (default: 50) */
|
|
61
|
+
cleanupInterval: number;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Options for setting a cache entry
|
|
65
|
+
*/
|
|
66
|
+
export interface SmartCacheOptions {
|
|
67
|
+
/** Optional TTL override for this entry */
|
|
68
|
+
ttl?: number;
|
|
69
|
+
/** File path for hash validation */
|
|
70
|
+
filePath?: string;
|
|
71
|
+
/** Pre-computed file hash (if already available) */
|
|
72
|
+
fileHash?: string;
|
|
73
|
+
/** Token count for stats */
|
|
74
|
+
tokenCount?: number;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Cache key type
|
|
78
|
+
*/
|
|
79
|
+
export type CacheKey = string;
|
|
80
|
+
/**
|
|
81
|
+
* Result of a cache get operation
|
|
82
|
+
*/
|
|
83
|
+
export interface CacheGetResult<T> {
|
|
84
|
+
/** Whether the entry was found and valid */
|
|
85
|
+
hit: boolean;
|
|
86
|
+
/** The cached value (undefined if miss) */
|
|
87
|
+
value?: T;
|
|
88
|
+
/** Reason for miss (if applicable) */
|
|
89
|
+
missReason?: "not_found" | "expired" | "file_changed" | "evicted";
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* File hash information
|
|
93
|
+
*/
|
|
94
|
+
export interface FileHashInfo {
|
|
95
|
+
/** The computed hash string */
|
|
96
|
+
hash: string;
|
|
97
|
+
/** File modification time in milliseconds */
|
|
98
|
+
mtime: number;
|
|
99
|
+
/** File size in bytes */
|
|
100
|
+
size: number;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/cache/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,WAAW,UAAU,CAAC,CAAC,GAAG,OAAO;IACrC,uBAAuB;IACvB,KAAK,EAAE,CAAC,CAAC;IAET,8CAA8C;IAC9C,SAAS,EAAE,MAAM,CAAC;IAElB,2DAA2D;IAC3D,cAAc,EAAE,MAAM,CAAC;IAEvB,8DAA8D;IAC9D,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb,sEAAsE;IACtE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,yCAAyC;IACzC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,uDAAuD;IACvD,SAAS,EAAE,MAAM,CAAC;IAElB,uCAAuC;IACvC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,8BAA8B;IAC9B,OAAO,EAAE,MAAM,CAAC;IAEhB,qCAAqC;IACrC,IAAI,EAAE,MAAM,CAAC;IAEb,uCAAuC;IACvC,MAAM,EAAE,MAAM,CAAC;IAEf,kCAAkC;IAClC,OAAO,EAAE,MAAM,CAAC;IAEhB,wCAAwC;IACxC,WAAW,EAAE,MAAM,CAAC;IAEpB,wCAAwC;IACxC,eAAe,EAAE,MAAM,CAAC;IAExB,6CAA6C;IAC7C,SAAS,EAAE,MAAM,CAAC;IAElB,uDAAuD;IACvD,aAAa,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,+CAA+C;IAC/C,UAAU,EAAE,MAAM,CAAC;IAEnB,wDAAwD;IACxD,YAAY,EAAE,MAAM,CAAC;IAErB,mDAAmD;IACnD,cAAc,EAAE,MAAM,CAAC;IAEvB,kDAAkD;IAClD,wBAAwB,EAAE,OAAO,CAAC;IAElC,mDAAmD;IACnD,eAAe,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,2CAA2C;IAC3C,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb,oCAAoC;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,oDAAoD;IACpD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,4BAA4B;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC;AAE9B;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC;IAC/B,4CAA4C;IAC5C,GAAG,EAAE,OAAO,CAAC;IAEb,2CAA2C;IAC3C,KAAK,CAAC,EAAE,CAAC,CAAC;IAEV,sCAAsC;IACtC,UAAU,CAAC,EAAE,WAAW,GAAG,SAAS,GAAG,cAAc,GAAG,SAAS,CAAC;CACnE;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,+BAA+B;IAC/B,IAAI,EAAE,MAAM,CAAC;IAEb,6CAA6C;IAC7C,KAAK,EAAE,MAAM,CAAC;IAEd,yBAAyB;IACzB,IAAI,EAAE,MAAM,CAAC;CACd"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI Analyze Command
|
|
3
|
+
*
|
|
4
|
+
* Analyzes files for token usage and optimization opportunities.
|
|
5
|
+
* Used by both CLI and GitHub Action.
|
|
6
|
+
*/
|
|
7
|
+
export interface AnalyzeOptions {
|
|
8
|
+
patterns: string[];
|
|
9
|
+
threshold: number;
|
|
10
|
+
json: boolean;
|
|
11
|
+
workingDir: string;
|
|
12
|
+
}
|
|
13
|
+
export interface FileAnalysis {
|
|
14
|
+
file: string;
|
|
15
|
+
tokens: number;
|
|
16
|
+
lines: number;
|
|
17
|
+
language: string;
|
|
18
|
+
exceedsThreshold: boolean;
|
|
19
|
+
suggestion?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface AnalyzeReport {
|
|
22
|
+
timestamp: string;
|
|
23
|
+
workingDir: string;
|
|
24
|
+
threshold: number;
|
|
25
|
+
totalFiles: number;
|
|
26
|
+
totalTokens: number;
|
|
27
|
+
filesAboveThreshold: number;
|
|
28
|
+
files: FileAnalysis[];
|
|
29
|
+
recommendations: string[];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Analyze files and generate report
|
|
33
|
+
*/
|
|
34
|
+
export declare function analyzeFiles(options: AnalyzeOptions): Promise<AnalyzeReport>;
|
|
35
|
+
/**
|
|
36
|
+
* Format report as text table
|
|
37
|
+
*/
|
|
38
|
+
export declare function formatReportAsText(report: AnalyzeReport): string;
|
|
39
|
+
/**
|
|
40
|
+
* Run analyze command
|
|
41
|
+
*/
|
|
42
|
+
export declare function runAnalyze(args: string[]): Promise<void>;
|
|
43
|
+
//# sourceMappingURL=analyze.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analyze.d.ts","sourceRoot":"","sources":["../../src/cli/analyze.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,OAAO,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,KAAK,EAAE,YAAY,EAAE,CAAC;IACtB,eAAe,EAAE,MAAM,EAAE,CAAC;CAC3B;AAqHD;;GAEG;AACH,wBAAsB,YAAY,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC,CA0ElF;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,CAkChE;AAED;;GAEG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CA8C9D"}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI Analyze Command
|
|
3
|
+
*
|
|
4
|
+
* Analyzes files for token usage and optimization opportunities.
|
|
5
|
+
* Used by both CLI and GitHub Action.
|
|
6
|
+
*/
|
|
7
|
+
import * as fs from "fs";
|
|
8
|
+
import * as path from "path";
|
|
9
|
+
import { countTokens } from "../utils/token-counter.js";
|
|
10
|
+
const LANGUAGE_MAP = {
|
|
11
|
+
".ts": "typescript",
|
|
12
|
+
".tsx": "typescript",
|
|
13
|
+
".js": "javascript",
|
|
14
|
+
".jsx": "javascript",
|
|
15
|
+
".py": "python",
|
|
16
|
+
".go": "go",
|
|
17
|
+
".rs": "rust",
|
|
18
|
+
".php": "php",
|
|
19
|
+
".swift": "swift",
|
|
20
|
+
".java": "java",
|
|
21
|
+
".c": "c",
|
|
22
|
+
".cpp": "cpp",
|
|
23
|
+
".h": "c",
|
|
24
|
+
".hpp": "cpp",
|
|
25
|
+
".cs": "csharp",
|
|
26
|
+
".rb": "ruby",
|
|
27
|
+
".md": "markdown",
|
|
28
|
+
".json": "json",
|
|
29
|
+
".yaml": "yaml",
|
|
30
|
+
".yml": "yaml",
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Match files against glob patterns (simple implementation)
|
|
34
|
+
*/
|
|
35
|
+
function matchGlob(filepath, pattern) {
|
|
36
|
+
// Handle brace expansion: {a,b,c} -> (a|b|c)
|
|
37
|
+
let regexPattern = pattern.replace(/\{([^}]+)\}/g, (_match, group) => {
|
|
38
|
+
const alternatives = group.split(",").map((s) => s.trim());
|
|
39
|
+
return `(${alternatives.join("|")})`;
|
|
40
|
+
});
|
|
41
|
+
regexPattern = regexPattern
|
|
42
|
+
.replace(/\*\*\//g, "(.*/)?")
|
|
43
|
+
.replace(/\*\*/g, ".*")
|
|
44
|
+
.replace(/\*/g, "[^/]*")
|
|
45
|
+
.replace(/\?/g, ".")
|
|
46
|
+
.replace(/\./g, "\\.");
|
|
47
|
+
const regex = new RegExp(`^${regexPattern}$`);
|
|
48
|
+
return regex.test(filepath);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Walk directory and find matching files
|
|
52
|
+
*/
|
|
53
|
+
function walkDirectory(dir, patterns, maxFiles = 1000) {
|
|
54
|
+
const results = [];
|
|
55
|
+
function walk(currentDir, relativePath = "") {
|
|
56
|
+
if (results.length >= maxFiles)
|
|
57
|
+
return;
|
|
58
|
+
try {
|
|
59
|
+
const entries = fs.readdirSync(currentDir, { withFileTypes: true });
|
|
60
|
+
for (const entry of entries) {
|
|
61
|
+
if (results.length >= maxFiles)
|
|
62
|
+
break;
|
|
63
|
+
const fullPath = path.join(currentDir, entry.name);
|
|
64
|
+
const relPath = path.join(relativePath, entry.name);
|
|
65
|
+
// Skip hidden dirs and node_modules
|
|
66
|
+
if (entry.name.startsWith(".") || entry.name === "node_modules") {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (entry.isDirectory()) {
|
|
70
|
+
walk(fullPath, relPath);
|
|
71
|
+
}
|
|
72
|
+
else if (entry.isFile()) {
|
|
73
|
+
for (const pattern of patterns) {
|
|
74
|
+
if (matchGlob(relPath, pattern)) {
|
|
75
|
+
results.push(relPath);
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
// Skip directories we can't read
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
walk(dir);
|
|
87
|
+
return results;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Get optimization suggestion based on file characteristics
|
|
91
|
+
*/
|
|
92
|
+
function getSuggestion(tokens, language) {
|
|
93
|
+
if (tokens > 5000) {
|
|
94
|
+
if (["typescript", "javascript", "python", "go", "rust"].includes(language)) {
|
|
95
|
+
return "Use smart_file_read to extract specific functions/classes";
|
|
96
|
+
}
|
|
97
|
+
return "Consider using code_skeleton to get signatures only";
|
|
98
|
+
}
|
|
99
|
+
if (tokens > 2000) {
|
|
100
|
+
return "Consider using semantic_compress for this file";
|
|
101
|
+
}
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Detect language from file extension
|
|
106
|
+
*/
|
|
107
|
+
function detectLanguage(filepath) {
|
|
108
|
+
const ext = path.extname(filepath).toLowerCase();
|
|
109
|
+
return LANGUAGE_MAP[ext] || "unknown";
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Analyze files and generate report
|
|
113
|
+
*/
|
|
114
|
+
export async function analyzeFiles(options) {
|
|
115
|
+
const { patterns, threshold, workingDir } = options;
|
|
116
|
+
// Find matching files
|
|
117
|
+
const files = walkDirectory(workingDir, patterns);
|
|
118
|
+
// Analyze each file
|
|
119
|
+
const analyses = [];
|
|
120
|
+
let totalTokens = 0;
|
|
121
|
+
let filesAboveThreshold = 0;
|
|
122
|
+
for (const file of files) {
|
|
123
|
+
try {
|
|
124
|
+
const fullPath = path.join(workingDir, file);
|
|
125
|
+
const content = fs.readFileSync(fullPath, "utf-8");
|
|
126
|
+
const tokens = countTokens(content);
|
|
127
|
+
const lines = content.split("\n").length;
|
|
128
|
+
const language = detectLanguage(file);
|
|
129
|
+
const exceedsThreshold = tokens > threshold;
|
|
130
|
+
if (exceedsThreshold) {
|
|
131
|
+
filesAboveThreshold++;
|
|
132
|
+
}
|
|
133
|
+
totalTokens += tokens;
|
|
134
|
+
analyses.push({
|
|
135
|
+
file,
|
|
136
|
+
tokens,
|
|
137
|
+
lines,
|
|
138
|
+
language,
|
|
139
|
+
exceedsThreshold,
|
|
140
|
+
suggestion: exceedsThreshold ? getSuggestion(tokens, language) : undefined,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
// Skip files we can't read
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
// Sort by tokens descending
|
|
148
|
+
analyses.sort((a, b) => b.tokens - a.tokens);
|
|
149
|
+
// Generate recommendations
|
|
150
|
+
const recommendations = [];
|
|
151
|
+
if (filesAboveThreshold > 0) {
|
|
152
|
+
recommendations.push(`${filesAboveThreshold} file(s) exceed the ${threshold} token threshold`);
|
|
153
|
+
}
|
|
154
|
+
const veryLargeFiles = analyses.filter((a) => a.tokens > 5000);
|
|
155
|
+
if (veryLargeFiles.length > 0) {
|
|
156
|
+
recommendations.push(`${veryLargeFiles.length} file(s) > 5000 tokens - use smart_file_read for targeted extraction`);
|
|
157
|
+
}
|
|
158
|
+
if (totalTokens > 50000) {
|
|
159
|
+
recommendations.push("Large codebase - consider using code_skeleton for overview before detailed reading");
|
|
160
|
+
}
|
|
161
|
+
return {
|
|
162
|
+
timestamp: new Date().toISOString(),
|
|
163
|
+
workingDir,
|
|
164
|
+
threshold,
|
|
165
|
+
totalFiles: files.length,
|
|
166
|
+
totalTokens,
|
|
167
|
+
filesAboveThreshold,
|
|
168
|
+
files: analyses,
|
|
169
|
+
recommendations,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Format report as text table
|
|
174
|
+
*/
|
|
175
|
+
export function formatReportAsText(report) {
|
|
176
|
+
const lines = [];
|
|
177
|
+
lines.push("## Token Analysis Report\n");
|
|
178
|
+
lines.push(`Analyzed: ${report.totalFiles} files`);
|
|
179
|
+
lines.push(`Total tokens: ${report.totalTokens.toLocaleString()}`);
|
|
180
|
+
lines.push(`Above threshold (${report.threshold}): ${report.filesAboveThreshold}\n`);
|
|
181
|
+
if (report.files.length > 0) {
|
|
182
|
+
lines.push("### Files by Token Count\n");
|
|
183
|
+
lines.push("| File | Tokens | Lines | Language |");
|
|
184
|
+
lines.push("|------|--------|-------|----------|");
|
|
185
|
+
// Show top 20 files
|
|
186
|
+
for (const file of report.files.slice(0, 20)) {
|
|
187
|
+
const marker = file.exceedsThreshold ? " ⚠️" : "";
|
|
188
|
+
lines.push(`| ${file.file}${marker} | ${file.tokens.toLocaleString()} | ${file.lines} | ${file.language} |`);
|
|
189
|
+
}
|
|
190
|
+
if (report.files.length > 20) {
|
|
191
|
+
lines.push(`| ... and ${report.files.length - 20} more files | | | |`);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (report.recommendations.length > 0) {
|
|
195
|
+
lines.push("\n### Recommendations\n");
|
|
196
|
+
for (const rec of report.recommendations) {
|
|
197
|
+
lines.push(`- ${rec}`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return lines.join("\n");
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Run analyze command
|
|
204
|
+
*/
|
|
205
|
+
export async function runAnalyze(args) {
|
|
206
|
+
// Parse arguments
|
|
207
|
+
let patterns = ["**/*.{ts,tsx,js,jsx,py,go,rs}"];
|
|
208
|
+
let threshold = 2000;
|
|
209
|
+
let json = false;
|
|
210
|
+
let outputFile = null;
|
|
211
|
+
for (let i = 0; i < args.length; i++) {
|
|
212
|
+
const arg = args[i];
|
|
213
|
+
if (arg === "--patterns" || arg === "-p") {
|
|
214
|
+
const patternArg = args[++i];
|
|
215
|
+
if (patternArg) {
|
|
216
|
+
patterns = patternArg.split(",");
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
else if (arg === "--threshold" || arg === "-t") {
|
|
220
|
+
const thresholdArg = args[++i];
|
|
221
|
+
if (thresholdArg) {
|
|
222
|
+
threshold = parseInt(thresholdArg, 10);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
else if (arg === "--json" || arg === "-j") {
|
|
226
|
+
json = true;
|
|
227
|
+
}
|
|
228
|
+
else if (arg === "--output" || arg === "-o") {
|
|
229
|
+
outputFile = args[++i] || null;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
const report = await analyzeFiles({
|
|
233
|
+
patterns,
|
|
234
|
+
threshold,
|
|
235
|
+
json,
|
|
236
|
+
workingDir: process.cwd(),
|
|
237
|
+
});
|
|
238
|
+
const output = json ? JSON.stringify(report, null, 2) : formatReportAsText(report);
|
|
239
|
+
if (outputFile) {
|
|
240
|
+
fs.writeFileSync(outputFile, output);
|
|
241
|
+
console.log(`Report written to ${outputFile}`);
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
console.log(output);
|
|
245
|
+
}
|
|
246
|
+
// Exit with error code if files exceed threshold
|
|
247
|
+
if (report.filesAboveThreshold > 0 && !json) {
|
|
248
|
+
process.exit(1);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doctor.d.ts","sourceRoot":"","sources":["../../src/cli/doctor.ts"],"names":[],"mappings":"AAgHA,wBAAsB,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CA2C5C"}
|