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,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Search SDK Tests
|
|
3
|
+
*
|
|
4
|
+
* Tests for ctx.search.* functions.
|
|
5
|
+
*/
|
|
6
|
+
import { describe, it, expect, beforeAll } from "vitest";
|
|
7
|
+
import { createSearchAPI } from "./search.js";
|
|
8
|
+
import * as fs from "fs";
|
|
9
|
+
import * as path from "path";
|
|
10
|
+
// Get the monorepo root
|
|
11
|
+
function getProjectRoot() {
|
|
12
|
+
// Navigate up from test file to project root
|
|
13
|
+
let dir = __dirname;
|
|
14
|
+
while (dir !== "/" && !fs.existsSync(path.join(dir, "package.json"))) {
|
|
15
|
+
dir = path.dirname(dir);
|
|
16
|
+
}
|
|
17
|
+
return dir;
|
|
18
|
+
}
|
|
19
|
+
const projectRoot = getProjectRoot();
|
|
20
|
+
// Create mock callbacks
|
|
21
|
+
function createMockCallbacks(workingDir) {
|
|
22
|
+
return {
|
|
23
|
+
readFile(filePath) {
|
|
24
|
+
const fullPath = path.isAbsolute(filePath)
|
|
25
|
+
? filePath
|
|
26
|
+
: path.join(workingDir, filePath);
|
|
27
|
+
return fs.readFileSync(fullPath, "utf-8");
|
|
28
|
+
},
|
|
29
|
+
fileExists(filePath) {
|
|
30
|
+
const fullPath = path.isAbsolute(filePath)
|
|
31
|
+
? filePath
|
|
32
|
+
: path.join(workingDir, filePath);
|
|
33
|
+
try {
|
|
34
|
+
fs.accessSync(fullPath);
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
glob() {
|
|
42
|
+
return [];
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
describe("Search SDK", () => {
|
|
47
|
+
let search;
|
|
48
|
+
beforeAll(() => {
|
|
49
|
+
const callbacks = createMockCallbacks(projectRoot);
|
|
50
|
+
search = createSearchAPI(projectRoot, callbacks);
|
|
51
|
+
});
|
|
52
|
+
describe("grep", () => {
|
|
53
|
+
it("should return GrepResult structure", () => {
|
|
54
|
+
const result = search.grep("function", "**/*.ts");
|
|
55
|
+
expect(result).toBeDefined();
|
|
56
|
+
expect(result.matches).toBeDefined();
|
|
57
|
+
expect(Array.isArray(result.matches)).toBe(true);
|
|
58
|
+
expect(typeof result.totalMatches).toBe("number");
|
|
59
|
+
expect(typeof result.filesSearched).toBe("number");
|
|
60
|
+
});
|
|
61
|
+
it("should find matches in TypeScript files", () => {
|
|
62
|
+
const result = search.grep("export", "**/*.ts");
|
|
63
|
+
expect(result.matches.length).toBeGreaterThan(0);
|
|
64
|
+
const match = result.matches[0];
|
|
65
|
+
expect(match.file).toBeDefined();
|
|
66
|
+
expect(typeof match.line).toBe("number");
|
|
67
|
+
expect(typeof match.column).toBe("number");
|
|
68
|
+
expect(match.content).toBeDefined();
|
|
69
|
+
expect(match.match).toBeDefined();
|
|
70
|
+
});
|
|
71
|
+
it("should support regex patterns", () => {
|
|
72
|
+
const result = search.grep("function\\s+\\w+", "**/*.ts");
|
|
73
|
+
expect(result.matches.length).toBeGreaterThan(0);
|
|
74
|
+
});
|
|
75
|
+
it("should respect file glob filter", () => {
|
|
76
|
+
const tsResult = search.grep("import", "**/*.ts");
|
|
77
|
+
expect(tsResult.filesSearched).toBeGreaterThan(0);
|
|
78
|
+
// Search in non-existent extension should return 0 matches
|
|
79
|
+
const noResult = search.grep("import", "**/*.xyz");
|
|
80
|
+
expect(noResult.matches.length).toBe(0);
|
|
81
|
+
});
|
|
82
|
+
it("should throw for invalid regex", () => {
|
|
83
|
+
expect(() => search.grep("[invalid", "**/*.ts")).toThrow("Invalid regex pattern");
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
describe("symbols", () => {
|
|
87
|
+
it("should return SymbolResult structure", () => {
|
|
88
|
+
const result = search.symbols("create", "**/*.ts");
|
|
89
|
+
expect(result).toBeDefined();
|
|
90
|
+
expect(result.symbols).toBeDefined();
|
|
91
|
+
expect(Array.isArray(result.symbols)).toBe(true);
|
|
92
|
+
expect(typeof result.totalMatches).toBe("number");
|
|
93
|
+
});
|
|
94
|
+
it("should find function symbols", () => {
|
|
95
|
+
const result = search.symbols("createSearchAPI", "**/*.ts");
|
|
96
|
+
if (result.symbols.length > 0) {
|
|
97
|
+
const symbol = result.symbols[0];
|
|
98
|
+
expect(symbol.name).toBeDefined();
|
|
99
|
+
expect(symbol.type).toBeDefined();
|
|
100
|
+
expect(symbol.file).toBeDefined();
|
|
101
|
+
expect(typeof symbol.line).toBe("number");
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
it("should support partial name matching", () => {
|
|
105
|
+
const result = search.symbols("Search", "**/*.ts");
|
|
106
|
+
expect(result.symbols.length).toBeGreaterThan(0);
|
|
107
|
+
// Should find symbols containing "Search" in their name
|
|
108
|
+
const hasMatch = result.symbols.some((s) => s.name.toLowerCase().includes("search"));
|
|
109
|
+
expect(hasMatch).toBe(true);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
describe("files", () => {
|
|
113
|
+
it("should return FileResult structure", () => {
|
|
114
|
+
const result = search.files("**/*.ts");
|
|
115
|
+
expect(result).toBeDefined();
|
|
116
|
+
expect(result.files).toBeDefined();
|
|
117
|
+
expect(Array.isArray(result.files)).toBe(true);
|
|
118
|
+
expect(typeof result.totalMatches).toBe("number");
|
|
119
|
+
});
|
|
120
|
+
it("should find TypeScript files", () => {
|
|
121
|
+
const result = search.files("**/*.ts");
|
|
122
|
+
expect(result.files.length).toBeGreaterThan(0);
|
|
123
|
+
const file = result.files[0];
|
|
124
|
+
expect(file.path).toBeDefined();
|
|
125
|
+
expect(file.name).toBeDefined();
|
|
126
|
+
expect(file.extension).toBe(".ts");
|
|
127
|
+
});
|
|
128
|
+
it("should find specific file patterns", () => {
|
|
129
|
+
const result = search.files("**/search.ts");
|
|
130
|
+
expect(result.files.length).toBeGreaterThan(0);
|
|
131
|
+
const hasSearchFile = result.files.some((f) => f.name === "search.ts");
|
|
132
|
+
expect(hasSearchFile).toBe(true);
|
|
133
|
+
});
|
|
134
|
+
it("should include file size", () => {
|
|
135
|
+
const result = search.files("**/*.ts");
|
|
136
|
+
if (result.files.length > 0) {
|
|
137
|
+
const file = result.files[0];
|
|
138
|
+
expect(typeof file.size).toBe("number");
|
|
139
|
+
expect(file.size).toBeGreaterThan(0);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
describe("references", () => {
|
|
144
|
+
it("should return ReferenceMatch array", () => {
|
|
145
|
+
const result = search.references("createSearchAPI", "**/*.ts");
|
|
146
|
+
expect(Array.isArray(result)).toBe(true);
|
|
147
|
+
});
|
|
148
|
+
it("should find symbol references", () => {
|
|
149
|
+
// Search for a common symbol that should have multiple references
|
|
150
|
+
const result = search.references("HostCallbacks", "**/*.ts");
|
|
151
|
+
if (result.length > 0) {
|
|
152
|
+
const ref = result[0];
|
|
153
|
+
expect(ref.file).toBeDefined();
|
|
154
|
+
expect(typeof ref.line).toBe("number");
|
|
155
|
+
expect(typeof ref.column).toBe("number");
|
|
156
|
+
expect(ref.context).toBeDefined();
|
|
157
|
+
expect(["definition", "usage", "import"]).toContain(ref.type);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
it("should categorize reference types", () => {
|
|
161
|
+
const result = search.references("GrepResult", "**/*.ts");
|
|
162
|
+
// Should have at least one definition or usage
|
|
163
|
+
const hasTypedRef = result.some((r) => r.type === "definition" || r.type === "usage" || r.type === "import");
|
|
164
|
+
if (result.length > 0) {
|
|
165
|
+
expect(hasTypedRef).toBe(true);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
describe("error handling", () => {
|
|
170
|
+
it("should handle empty results gracefully", () => {
|
|
171
|
+
// Use a pattern that won't appear in any file (including this test file)
|
|
172
|
+
// by searching in a directory without test files
|
|
173
|
+
const result = search.grep("xyznonexistentpattern123", "src/ast/**/*.ts");
|
|
174
|
+
expect(result.matches).toEqual([]);
|
|
175
|
+
expect(result.totalMatches).toBe(0);
|
|
176
|
+
});
|
|
177
|
+
it("should handle non-matching glob patterns", () => {
|
|
178
|
+
const result = search.files("**/*.nonexistent");
|
|
179
|
+
expect(result.files).toEqual([]);
|
|
180
|
+
expect(result.totalMatches).toBe(0);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK Utility Functions
|
|
3
|
+
*/
|
|
4
|
+
import type { ContentType } from "../../compressors/types.js";
|
|
5
|
+
import type { SupportedLanguage } from "../../ast/types.js";
|
|
6
|
+
/**
|
|
7
|
+
* Count tokens in text
|
|
8
|
+
*/
|
|
9
|
+
export declare function countTokens(text: string): number;
|
|
10
|
+
/**
|
|
11
|
+
* Detect content type (logs, stacktrace, code, etc.)
|
|
12
|
+
*/
|
|
13
|
+
export declare function detectType(content: string): ContentType;
|
|
14
|
+
/**
|
|
15
|
+
* Detect programming language from file path
|
|
16
|
+
*/
|
|
17
|
+
export declare function detectLanguage(filePath: string): SupportedLanguage;
|
|
18
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/sandbox/sdk/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAE5D;;GAEG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,CAEvD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,iBAAiB,CAElE"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK Utility Functions
|
|
3
|
+
*/
|
|
4
|
+
import { countTokens as count } from "../../utils/token-counter.js";
|
|
5
|
+
import { detectContentType } from "../../utils/content-detector.js";
|
|
6
|
+
import { detectLanguageFromPath } from "../../utils/language-detector.js";
|
|
7
|
+
/**
|
|
8
|
+
* Count tokens in text
|
|
9
|
+
*/
|
|
10
|
+
export function countTokens(text) {
|
|
11
|
+
return count(text);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Detect content type (logs, stacktrace, code, etc.)
|
|
15
|
+
*/
|
|
16
|
+
export function detectType(content) {
|
|
17
|
+
return detectContentType(content);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Detect programming language from file path
|
|
21
|
+
*/
|
|
22
|
+
export function detectLanguage(filePath) {
|
|
23
|
+
return detectLanguageFromPath(filePath);
|
|
24
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Code Analyzer
|
|
3
|
+
*
|
|
4
|
+
* Static analysis of code before execution to block dangerous patterns.
|
|
5
|
+
*/
|
|
6
|
+
import type { CodeAnalysis } from "../types.js";
|
|
7
|
+
/**
|
|
8
|
+
* Analyze code for security issues
|
|
9
|
+
*/
|
|
10
|
+
export declare function analyzeCode(code: string): CodeAnalysis;
|
|
11
|
+
/**
|
|
12
|
+
* Sanitize error messages to remove host paths
|
|
13
|
+
*/
|
|
14
|
+
export declare function sanitizeError(error: Error, workingDir: string): string;
|
|
15
|
+
//# sourceMappingURL=code-analyzer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-analyzer.d.ts","sourceRoot":"","sources":["../../../src/sandbox/security/code-analyzer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAoDhD;;GAEG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAuBtD;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAetE"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Code Analyzer
|
|
3
|
+
*
|
|
4
|
+
* Static analysis of code before execution to block dangerous patterns.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Dangerous patterns that are blocked in sandbox code
|
|
8
|
+
*/
|
|
9
|
+
const BLOCKED_PATTERNS = [
|
|
10
|
+
// Code execution
|
|
11
|
+
{ pattern: /\beval\s*\(/, reason: "eval() is not allowed" },
|
|
12
|
+
{ pattern: /\bFunction\s*\(/, reason: "Function constructor is not allowed" },
|
|
13
|
+
{ pattern: /new\s+Function\s*\(/, reason: "new Function() is not allowed" },
|
|
14
|
+
// Module system
|
|
15
|
+
{ pattern: /\brequire\s*\(/, reason: "require() is not allowed" },
|
|
16
|
+
{ pattern: /\bimport\s*\(/, reason: "dynamic import() is not allowed" },
|
|
17
|
+
{ pattern: /import\.meta/, reason: "import.meta is not allowed" },
|
|
18
|
+
// Node.js globals
|
|
19
|
+
{ pattern: /\bprocess\b/, reason: "process is not allowed" },
|
|
20
|
+
{ pattern: /\bglobal\b/, reason: "global is not allowed" },
|
|
21
|
+
{ pattern: /\bglobalThis\b/, reason: "globalThis is not allowed" },
|
|
22
|
+
{ pattern: /\b__dirname\b/, reason: "__dirname is not allowed" },
|
|
23
|
+
{ pattern: /\b__filename\b/, reason: "__filename is not allowed" },
|
|
24
|
+
{ pattern: /\bBuffer\b/, reason: "Buffer is not allowed" },
|
|
25
|
+
// Prototype pollution
|
|
26
|
+
{ pattern: /__proto__/, reason: "__proto__ is not allowed" },
|
|
27
|
+
{ pattern: /\.constructor\s*\[/, reason: "constructor access is not allowed" },
|
|
28
|
+
{ pattern: /\.prototype\s*\[/, reason: "prototype access is not allowed" },
|
|
29
|
+
// Reflection APIs
|
|
30
|
+
{ pattern: /\bReflect\b/, reason: "Reflect is not allowed" },
|
|
31
|
+
{ pattern: /\bProxy\b/, reason: "Proxy is not allowed" },
|
|
32
|
+
// Unsafe operations
|
|
33
|
+
{ pattern: /\bsetTimeout\s*\(/, reason: "setTimeout is not allowed (use await)" },
|
|
34
|
+
{ pattern: /\bsetInterval\s*\(/, reason: "setInterval is not allowed" },
|
|
35
|
+
{ pattern: /\bsetImmediate\s*\(/, reason: "setImmediate is not allowed" },
|
|
36
|
+
// File system escape attempts
|
|
37
|
+
{ pattern: /file:\/\//, reason: "file:// URLs are not allowed" },
|
|
38
|
+
{ pattern: /\.\.\/\.\.\//, reason: "path traversal is not allowed" },
|
|
39
|
+
];
|
|
40
|
+
/**
|
|
41
|
+
* Warning patterns (not blocked, but flagged)
|
|
42
|
+
*/
|
|
43
|
+
const WARNING_PATTERNS = [
|
|
44
|
+
{ pattern: /while\s*\(\s*true\s*\)/, warning: "infinite loop detected" },
|
|
45
|
+
{ pattern: /for\s*\(\s*;\s*;\s*\)/, warning: "infinite loop detected" },
|
|
46
|
+
{ pattern: /\.repeat\s*\(\s*\d{6,}\s*\)/, warning: "large string repeat" },
|
|
47
|
+
];
|
|
48
|
+
/**
|
|
49
|
+
* Analyze code for security issues
|
|
50
|
+
*/
|
|
51
|
+
export function analyzeCode(code) {
|
|
52
|
+
const blockedPatterns = [];
|
|
53
|
+
const warnings = [];
|
|
54
|
+
// Check blocked patterns
|
|
55
|
+
for (const { pattern, reason } of BLOCKED_PATTERNS) {
|
|
56
|
+
if (pattern.test(code)) {
|
|
57
|
+
blockedPatterns.push(reason);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// Check warning patterns
|
|
61
|
+
for (const { pattern, warning } of WARNING_PATTERNS) {
|
|
62
|
+
if (pattern.test(code)) {
|
|
63
|
+
warnings.push(warning);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
safe: blockedPatterns.length === 0,
|
|
68
|
+
warnings,
|
|
69
|
+
blockedPatterns,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Sanitize error messages to remove host paths
|
|
74
|
+
*/
|
|
75
|
+
export function sanitizeError(error, workingDir) {
|
|
76
|
+
let message = error.message || "Unknown error";
|
|
77
|
+
// Remove absolute paths
|
|
78
|
+
message = message.replace(new RegExp(workingDir, "g"), "<workdir>");
|
|
79
|
+
message = message.replace(/\/home\/[^/]+/g, "<home>");
|
|
80
|
+
message = message.replace(/C:\\Users\\[^\\]+/gi, "<home>");
|
|
81
|
+
// Remove stack traces with host info
|
|
82
|
+
if (error.stack) {
|
|
83
|
+
const firstLine = message.split("\n")[0];
|
|
84
|
+
return firstLine || message;
|
|
85
|
+
}
|
|
86
|
+
return message;
|
|
87
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/sandbox/security/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path Validator
|
|
3
|
+
*
|
|
4
|
+
* Validates file paths for sandbox access.
|
|
5
|
+
* Reuses patterns from smart-file-read.ts for consistency.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Validation result
|
|
9
|
+
*/
|
|
10
|
+
export interface PathValidation {
|
|
11
|
+
safe: boolean;
|
|
12
|
+
error?: string;
|
|
13
|
+
resolvedPath?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Validate a file path for sandbox access
|
|
17
|
+
*/
|
|
18
|
+
export declare function validatePath(filePath: string, workingDir: string): PathValidation;
|
|
19
|
+
/**
|
|
20
|
+
* Validate a glob pattern
|
|
21
|
+
*/
|
|
22
|
+
export declare function validateGlobPattern(pattern: string, workingDir: string): PathValidation;
|
|
23
|
+
//# sourceMappingURL=path-validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-validator.d.ts","sourceRoot":"","sources":["../../../src/sandbox/security/path-validator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAyBH;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,GACjB,cAAc,CAoDhB;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,GACjB,cAAc,CA+BhB"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path Validator
|
|
3
|
+
*
|
|
4
|
+
* Validates file paths for sandbox access.
|
|
5
|
+
* Reuses patterns from smart-file-read.ts for consistency.
|
|
6
|
+
*/
|
|
7
|
+
import * as path from "path";
|
|
8
|
+
import * as fs from "fs";
|
|
9
|
+
/**
|
|
10
|
+
* Blocked file patterns (sensitive files)
|
|
11
|
+
*/
|
|
12
|
+
const BLOCKED_PATTERNS = [
|
|
13
|
+
/\.env($|\.)/i, // Environment files
|
|
14
|
+
/\.pem$/i, // Private keys
|
|
15
|
+
/\.key$/i, // Key files
|
|
16
|
+
/id_rsa/i, // SSH keys
|
|
17
|
+
/id_ed25519/i, // SSH keys
|
|
18
|
+
/credentials/i, // Credentials
|
|
19
|
+
/secrets?\./i, // Secret files
|
|
20
|
+
/\.keystore$/i, // Java keystores
|
|
21
|
+
/\.jks$/i, // Java keystores
|
|
22
|
+
/password/i, // Password files
|
|
23
|
+
/\.htpasswd/i, // Apache passwords
|
|
24
|
+
/\.netrc/i, // Network credentials
|
|
25
|
+
/\.npmrc/i, // NPM credentials
|
|
26
|
+
/\.pypirc/i, // PyPI credentials
|
|
27
|
+
];
|
|
28
|
+
/**
|
|
29
|
+
* Validate a file path for sandbox access
|
|
30
|
+
*/
|
|
31
|
+
export function validatePath(filePath, workingDir) {
|
|
32
|
+
try {
|
|
33
|
+
// Normalize and resolve path
|
|
34
|
+
const normalizedPath = path.normalize(filePath);
|
|
35
|
+
const resolvedPath = path.isAbsolute(normalizedPath)
|
|
36
|
+
? normalizedPath
|
|
37
|
+
: path.resolve(workingDir, normalizedPath);
|
|
38
|
+
// Check if path is within working directory
|
|
39
|
+
const relative = path.relative(workingDir, resolvedPath);
|
|
40
|
+
if (relative.startsWith("..") || path.isAbsolute(relative)) {
|
|
41
|
+
return {
|
|
42
|
+
safe: false,
|
|
43
|
+
error: `Path must be within working directory: ${workingDir}`,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
// Check for symlinks that might escape
|
|
47
|
+
try {
|
|
48
|
+
const realPath = fs.realpathSync(resolvedPath);
|
|
49
|
+
const realRelative = path.relative(workingDir, realPath);
|
|
50
|
+
if (realRelative.startsWith("..") || path.isAbsolute(realRelative)) {
|
|
51
|
+
return {
|
|
52
|
+
safe: false,
|
|
53
|
+
error: "Symlink escapes working directory",
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
// File doesn't exist yet, that's okay for validation
|
|
59
|
+
}
|
|
60
|
+
// Check against blocked patterns
|
|
61
|
+
const fileName = path.basename(resolvedPath);
|
|
62
|
+
for (const pattern of BLOCKED_PATTERNS) {
|
|
63
|
+
if (pattern.test(fileName) || pattern.test(resolvedPath)) {
|
|
64
|
+
return {
|
|
65
|
+
safe: false,
|
|
66
|
+
error: `Access to ${fileName} is blocked for security`,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
safe: true,
|
|
72
|
+
resolvedPath,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
return {
|
|
77
|
+
safe: false,
|
|
78
|
+
error: `Invalid path: ${error instanceof Error ? error.message : "unknown error"}`,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Validate a glob pattern
|
|
84
|
+
*/
|
|
85
|
+
export function validateGlobPattern(pattern, workingDir) {
|
|
86
|
+
// Check for path traversal in pattern
|
|
87
|
+
if (pattern.includes("..")) {
|
|
88
|
+
return {
|
|
89
|
+
safe: false,
|
|
90
|
+
error: "Glob pattern cannot contain path traversal (..)",
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
// Check for absolute paths
|
|
94
|
+
if (path.isAbsolute(pattern)) {
|
|
95
|
+
return {
|
|
96
|
+
safe: false,
|
|
97
|
+
error: "Glob pattern must be relative to working directory",
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
// Check for blocked patterns in glob
|
|
101
|
+
for (const blocked of BLOCKED_PATTERNS) {
|
|
102
|
+
if (blocked.test(pattern)) {
|
|
103
|
+
return {
|
|
104
|
+
safe: false,
|
|
105
|
+
error: `Glob pattern matches blocked file types`,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
safe: true,
|
|
111
|
+
resolvedPath: path.join(workingDir, pattern),
|
|
112
|
+
};
|
|
113
|
+
}
|