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,413 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK Analyze Functions
|
|
3
|
+
*
|
|
4
|
+
* Static analysis operations for sandbox use.
|
|
5
|
+
* Provides dependency analysis, call graphs, and structure overview.
|
|
6
|
+
*/
|
|
7
|
+
import * as fs from "fs";
|
|
8
|
+
import * as path from "path";
|
|
9
|
+
import { parseFile } from "../../ast/index.js";
|
|
10
|
+
import { detectLanguageFromPath } from "../../utils/language-detector.js";
|
|
11
|
+
import { validatePath } from "../security/path-validator.js";
|
|
12
|
+
const MAX_DEPTH = 5;
|
|
13
|
+
const MAX_STRUCTURE_FILES = 200;
|
|
14
|
+
const MAX_FILE_SIZE = 1024 * 1024; // 1MB
|
|
15
|
+
/**
|
|
16
|
+
* Parse imports from file content
|
|
17
|
+
*/
|
|
18
|
+
function parseImports(content, language) {
|
|
19
|
+
const imports = [];
|
|
20
|
+
if (language === "typescript" || language === "javascript") {
|
|
21
|
+
// ES6 imports: import { x, y } from 'module'
|
|
22
|
+
const esImportRegex = /import\s+(?:(\w+)\s*,?\s*)?(?:\{([^}]+)\})?\s*(?:from\s+)?['"]([^'"]+)['"]/g;
|
|
23
|
+
let match;
|
|
24
|
+
while ((match = esImportRegex.exec(content)) !== null) {
|
|
25
|
+
const defaultImport = match[1];
|
|
26
|
+
const namedImports = match[2];
|
|
27
|
+
const source = match[3] ?? "";
|
|
28
|
+
const names = [];
|
|
29
|
+
let isDefault = false;
|
|
30
|
+
let isNamespace = false;
|
|
31
|
+
if (defaultImport) {
|
|
32
|
+
names.push(defaultImport);
|
|
33
|
+
isDefault = true;
|
|
34
|
+
}
|
|
35
|
+
if (namedImports) {
|
|
36
|
+
const namedList = namedImports.split(",").map((n) => n.trim().split(/\s+as\s+/)[0]?.trim() ?? "");
|
|
37
|
+
names.push(...namedList.filter(Boolean));
|
|
38
|
+
}
|
|
39
|
+
imports.push({ source, names, isDefault, isNamespace });
|
|
40
|
+
}
|
|
41
|
+
// Namespace imports: import * as x from 'module'
|
|
42
|
+
const namespaceRegex = /import\s+\*\s+as\s+(\w+)\s+from\s+['"]([^'"]+)['"]/g;
|
|
43
|
+
while ((match = namespaceRegex.exec(content)) !== null) {
|
|
44
|
+
const name = match[1] ?? "";
|
|
45
|
+
const source = match[2] ?? "";
|
|
46
|
+
imports.push({ source, names: [name], isDefault: false, isNamespace: true });
|
|
47
|
+
}
|
|
48
|
+
// Side-effect imports: import 'module'
|
|
49
|
+
const sideEffectRegex = /import\s+['"]([^'"]+)['"]/g;
|
|
50
|
+
while ((match = sideEffectRegex.exec(content)) !== null) {
|
|
51
|
+
const source = match[1] ?? "";
|
|
52
|
+
if (!imports.some((i) => i.source === source)) {
|
|
53
|
+
imports.push({ source, names: [], isDefault: false, isNamespace: false });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else if (language === "python") {
|
|
58
|
+
// Python imports: from x import y, z
|
|
59
|
+
const fromImportRegex = /from\s+([\w.]+)\s+import\s+([^#\n]+)/g;
|
|
60
|
+
let match;
|
|
61
|
+
while ((match = fromImportRegex.exec(content)) !== null) {
|
|
62
|
+
const source = match[1] ?? "";
|
|
63
|
+
const names = (match[2] ?? "").split(",").map((n) => n.trim().split(/\s+as\s+/)[0]?.trim() ?? "").filter(Boolean);
|
|
64
|
+
imports.push({ source, names, isDefault: false, isNamespace: false });
|
|
65
|
+
}
|
|
66
|
+
// Python imports: import x, y
|
|
67
|
+
const importRegex = /^import\s+([^#\n]+)/gm;
|
|
68
|
+
while ((match = importRegex.exec(content)) !== null) {
|
|
69
|
+
const modules = (match[1] ?? "").split(",").map((m) => m.trim().split(/\s+as\s+/)[0]?.trim() ?? "").filter(Boolean);
|
|
70
|
+
for (const mod of modules) {
|
|
71
|
+
imports.push({ source: mod, names: [mod], isDefault: true, isNamespace: false });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
else if (language === "go") {
|
|
76
|
+
// Go imports
|
|
77
|
+
const importRegex = /import\s+(?:\(\s*([^)]+)\s*\)|"([^"]+)")/g;
|
|
78
|
+
let match;
|
|
79
|
+
while ((match = importRegex.exec(content)) !== null) {
|
|
80
|
+
if (match[1]) {
|
|
81
|
+
// Multi-line import block
|
|
82
|
+
const lines = match[1].split("\n");
|
|
83
|
+
for (const line of lines) {
|
|
84
|
+
const pkgMatch = line.match(/(?:(\w+)\s+)?"([^"]+)"/);
|
|
85
|
+
if (pkgMatch) {
|
|
86
|
+
const alias = pkgMatch[1];
|
|
87
|
+
const source = pkgMatch[2] ?? "";
|
|
88
|
+
const name = alias ?? path.basename(source);
|
|
89
|
+
imports.push({ source, names: [name], isDefault: false, isNamespace: false });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else if (match[2]) {
|
|
94
|
+
// Single import
|
|
95
|
+
const source = match[2];
|
|
96
|
+
imports.push({ source, names: [path.basename(source)], isDefault: false, isNamespace: false });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return imports;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Resolve import path to actual file path
|
|
104
|
+
*/
|
|
105
|
+
function resolveImportPath(importSource, currentFile, workingDir) {
|
|
106
|
+
// Skip external packages
|
|
107
|
+
if (!importSource.startsWith(".") && !importSource.startsWith("/")) {
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
const currentDir = path.dirname(path.join(workingDir, currentFile));
|
|
111
|
+
const extensions = [".ts", ".tsx", ".js", ".jsx", ".py", ".go", ".rs"];
|
|
112
|
+
// Try direct path
|
|
113
|
+
let resolved = path.resolve(currentDir, importSource);
|
|
114
|
+
// Try with extensions
|
|
115
|
+
for (const ext of extensions) {
|
|
116
|
+
const withExt = resolved + ext;
|
|
117
|
+
if (fs.existsSync(withExt)) {
|
|
118
|
+
return path.relative(workingDir, withExt);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// Try index file
|
|
122
|
+
for (const ext of extensions) {
|
|
123
|
+
const indexPath = path.join(resolved, `index${ext}`);
|
|
124
|
+
if (fs.existsSync(indexPath)) {
|
|
125
|
+
return path.relative(workingDir, indexPath);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Extract function calls from function body
|
|
132
|
+
*/
|
|
133
|
+
function extractFunctionCalls(content, functionName) {
|
|
134
|
+
const calls = [];
|
|
135
|
+
// Simple regex to find function calls
|
|
136
|
+
// This is a heuristic - full AST parsing would be more accurate
|
|
137
|
+
const callRegex = /\b([a-zA-Z_]\w*)\s*\(/g;
|
|
138
|
+
let match;
|
|
139
|
+
while ((match = callRegex.exec(content)) !== null) {
|
|
140
|
+
const calledFn = match[1] ?? "";
|
|
141
|
+
// Skip common built-ins and the function itself
|
|
142
|
+
if (calledFn !== functionName &&
|
|
143
|
+
!["if", "for", "while", "switch", "catch", "function", "return", "throw", "new", "typeof", "instanceof"].includes(calledFn)) {
|
|
144
|
+
if (!calls.includes(calledFn)) {
|
|
145
|
+
calls.push(calledFn);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return calls;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Create Analyze API for sandbox
|
|
153
|
+
*/
|
|
154
|
+
export function createAnalyzeAPI(workingDir, callbacks) {
|
|
155
|
+
return {
|
|
156
|
+
/**
|
|
157
|
+
* Analyze file dependencies (imports and exports)
|
|
158
|
+
* @param file - File path to analyze
|
|
159
|
+
*/
|
|
160
|
+
dependencies(file) {
|
|
161
|
+
// Validate file path
|
|
162
|
+
const validation = validatePath(file, workingDir);
|
|
163
|
+
if (!validation.safe) {
|
|
164
|
+
throw new Error(validation.error ?? "Invalid file path");
|
|
165
|
+
}
|
|
166
|
+
const fullPath = path.join(workingDir, file);
|
|
167
|
+
const content = fs.readFileSync(fullPath, "utf-8");
|
|
168
|
+
const language = detectLanguageFromPath(file);
|
|
169
|
+
if (language === "unknown") {
|
|
170
|
+
throw new Error(`Unsupported language for file: ${file}`);
|
|
171
|
+
}
|
|
172
|
+
// Parse the file structure
|
|
173
|
+
const structure = parseFile(content, language);
|
|
174
|
+
// Parse imports
|
|
175
|
+
const imports = parseImports(content, language);
|
|
176
|
+
// Resolve import paths and categorize
|
|
177
|
+
const externalDeps = [];
|
|
178
|
+
const internalDeps = [];
|
|
179
|
+
for (const imp of imports) {
|
|
180
|
+
const resolved = resolveImportPath(imp.source, file, workingDir);
|
|
181
|
+
if (resolved) {
|
|
182
|
+
imp.resolvedPath = resolved;
|
|
183
|
+
if (!internalDeps.includes(resolved)) {
|
|
184
|
+
internalDeps.push(resolved);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
else if (!imp.source.startsWith(".")) {
|
|
188
|
+
if (!externalDeps.includes(imp.source)) {
|
|
189
|
+
externalDeps.push(imp.source);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
// Extract exports
|
|
194
|
+
const exports = [];
|
|
195
|
+
// From AST exports
|
|
196
|
+
for (const exp of structure.exports) {
|
|
197
|
+
exports.push({
|
|
198
|
+
name: exp.name,
|
|
199
|
+
type: exp.type,
|
|
200
|
+
isDefault: exp.name === "default",
|
|
201
|
+
line: exp.startLine,
|
|
202
|
+
signature: exp.signature,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
// Also check functions/classes for exported ones
|
|
206
|
+
for (const fn of structure.functions) {
|
|
207
|
+
if (!exports.some((e) => e.name === fn.name)) {
|
|
208
|
+
// Check if exported in content
|
|
209
|
+
const exportCheck = new RegExp(`export\\s+(?:default\\s+)?(?:async\\s+)?function\\s+${fn.name}\\b`);
|
|
210
|
+
if (exportCheck.test(content)) {
|
|
211
|
+
exports.push({
|
|
212
|
+
name: fn.name,
|
|
213
|
+
type: "function",
|
|
214
|
+
isDefault: content.includes(`export default function ${fn.name}`),
|
|
215
|
+
line: fn.startLine,
|
|
216
|
+
signature: fn.signature,
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
for (const cls of structure.classes) {
|
|
222
|
+
if (!exports.some((e) => e.name === cls.name)) {
|
|
223
|
+
const exportCheck = new RegExp(`export\\s+(?:default\\s+)?class\\s+${cls.name}\\b`);
|
|
224
|
+
if (exportCheck.test(content)) {
|
|
225
|
+
exports.push({
|
|
226
|
+
name: cls.name,
|
|
227
|
+
type: "class",
|
|
228
|
+
isDefault: content.includes(`export default class ${cls.name}`),
|
|
229
|
+
line: cls.startLine,
|
|
230
|
+
signature: cls.signature,
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return {
|
|
236
|
+
file,
|
|
237
|
+
imports,
|
|
238
|
+
exports,
|
|
239
|
+
externalDeps,
|
|
240
|
+
internalDeps,
|
|
241
|
+
};
|
|
242
|
+
},
|
|
243
|
+
/**
|
|
244
|
+
* Build a call graph for a function
|
|
245
|
+
* @param functionName - Function name to analyze
|
|
246
|
+
* @param file - File containing the function
|
|
247
|
+
* @param depth - Maximum depth to traverse (default: 3)
|
|
248
|
+
*/
|
|
249
|
+
callGraph(functionName, file, depth) {
|
|
250
|
+
const maxDepth = Math.min(depth ?? 3, MAX_DEPTH);
|
|
251
|
+
// Validate file path
|
|
252
|
+
const validation = validatePath(file, workingDir);
|
|
253
|
+
if (!validation.safe) {
|
|
254
|
+
throw new Error(validation.error ?? "Invalid file path");
|
|
255
|
+
}
|
|
256
|
+
const fullPath = path.join(workingDir, file);
|
|
257
|
+
const content = fs.readFileSync(fullPath, "utf-8");
|
|
258
|
+
const language = detectLanguageFromPath(file);
|
|
259
|
+
if (language === "unknown") {
|
|
260
|
+
throw new Error(`Unsupported language for file: ${file}`);
|
|
261
|
+
}
|
|
262
|
+
const structure = parseFile(content, language);
|
|
263
|
+
const nodes = [];
|
|
264
|
+
const visited = new Set();
|
|
265
|
+
// Find the root function
|
|
266
|
+
const rootFn = structure.functions.find((f) => f.name === functionName);
|
|
267
|
+
if (!rootFn) {
|
|
268
|
+
throw new Error(`Function '${functionName}' not found in ${file}`);
|
|
269
|
+
}
|
|
270
|
+
// Extract function body (heuristic)
|
|
271
|
+
const lines = content.split("\n");
|
|
272
|
+
const startLine = rootFn.startLine - 1;
|
|
273
|
+
const endLine = rootFn.endLine ?? startLine + 50;
|
|
274
|
+
const fnBody = lines.slice(startLine, endLine).join("\n");
|
|
275
|
+
// Get calls from the function
|
|
276
|
+
const calls = extractFunctionCalls(fnBody, functionName);
|
|
277
|
+
nodes.push({
|
|
278
|
+
name: functionName,
|
|
279
|
+
file,
|
|
280
|
+
line: rootFn.startLine,
|
|
281
|
+
calls,
|
|
282
|
+
calledBy: [],
|
|
283
|
+
});
|
|
284
|
+
visited.add(`${file}:${functionName}`);
|
|
285
|
+
// Build call graph recursively (simplified - same file only)
|
|
286
|
+
function addCalls(fnName, currentDepth) {
|
|
287
|
+
if (currentDepth >= maxDepth)
|
|
288
|
+
return;
|
|
289
|
+
const fn = structure.functions.find((f) => f.name === fnName);
|
|
290
|
+
if (!fn)
|
|
291
|
+
return;
|
|
292
|
+
const key = `${file}:${fnName}`;
|
|
293
|
+
if (visited.has(key))
|
|
294
|
+
return;
|
|
295
|
+
visited.add(key);
|
|
296
|
+
const fnStartLine = fn.startLine - 1;
|
|
297
|
+
const fnEndLine = fn.endLine ?? fnStartLine + 50;
|
|
298
|
+
const body = lines.slice(fnStartLine, fnEndLine).join("\n");
|
|
299
|
+
const fnCalls = extractFunctionCalls(body, fnName);
|
|
300
|
+
nodes.push({
|
|
301
|
+
name: fnName,
|
|
302
|
+
file,
|
|
303
|
+
line: fn.startLine,
|
|
304
|
+
calls: fnCalls,
|
|
305
|
+
calledBy: [],
|
|
306
|
+
});
|
|
307
|
+
for (const call of fnCalls) {
|
|
308
|
+
addCalls(call, currentDepth + 1);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
// Add called functions
|
|
312
|
+
for (const call of calls) {
|
|
313
|
+
addCalls(call, 1);
|
|
314
|
+
}
|
|
315
|
+
// Build calledBy relationships
|
|
316
|
+
for (const node of nodes) {
|
|
317
|
+
for (const call of node.calls) {
|
|
318
|
+
const calledNode = nodes.find((n) => n.name === call);
|
|
319
|
+
if (calledNode && !calledNode.calledBy.includes(node.name)) {
|
|
320
|
+
calledNode.calledBy.push(node.name);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
return {
|
|
325
|
+
root: functionName,
|
|
326
|
+
nodes,
|
|
327
|
+
depth: maxDepth,
|
|
328
|
+
};
|
|
329
|
+
},
|
|
330
|
+
/**
|
|
331
|
+
* Get exports from a file
|
|
332
|
+
* @param file - File path to analyze
|
|
333
|
+
*/
|
|
334
|
+
exports(file) {
|
|
335
|
+
const result = this.dependencies(file);
|
|
336
|
+
return result.exports;
|
|
337
|
+
},
|
|
338
|
+
/**
|
|
339
|
+
* Get directory structure with code analysis
|
|
340
|
+
* @param dir - Directory to analyze (default: working directory root)
|
|
341
|
+
* @param depth - Maximum depth (default: 3)
|
|
342
|
+
*/
|
|
343
|
+
structure(dir, depth) {
|
|
344
|
+
const targetDir = dir ?? ".";
|
|
345
|
+
const maxDepth = Math.min(depth ?? 3, MAX_DEPTH);
|
|
346
|
+
// Validate directory
|
|
347
|
+
const validation = validatePath(targetDir, workingDir);
|
|
348
|
+
if (!validation.safe) {
|
|
349
|
+
throw new Error(validation.error ?? "Invalid directory path");
|
|
350
|
+
}
|
|
351
|
+
const fullPath = path.join(workingDir, targetDir);
|
|
352
|
+
let filesAnalyzed = 0;
|
|
353
|
+
function buildStructure(currentPath, currentDepth, relativePath) {
|
|
354
|
+
const stats = fs.statSync(currentPath);
|
|
355
|
+
const name = path.basename(currentPath);
|
|
356
|
+
if (stats.isFile()) {
|
|
357
|
+
const entry = {
|
|
358
|
+
path: relativePath,
|
|
359
|
+
type: "file",
|
|
360
|
+
name,
|
|
361
|
+
size: stats.size,
|
|
362
|
+
};
|
|
363
|
+
// Analyze code files
|
|
364
|
+
if (filesAnalyzed < MAX_STRUCTURE_FILES && stats.size < MAX_FILE_SIZE) {
|
|
365
|
+
const language = detectLanguageFromPath(currentPath);
|
|
366
|
+
if (language !== "unknown") {
|
|
367
|
+
try {
|
|
368
|
+
const content = fs.readFileSync(currentPath, "utf-8");
|
|
369
|
+
const structure = parseFile(content, language);
|
|
370
|
+
entry.language = language;
|
|
371
|
+
entry.functions = structure.functions.length;
|
|
372
|
+
entry.classes = structure.classes.length;
|
|
373
|
+
entry.exports = structure.exports.length;
|
|
374
|
+
filesAnalyzed++;
|
|
375
|
+
}
|
|
376
|
+
catch {
|
|
377
|
+
// Skip files we can't parse
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
return entry;
|
|
382
|
+
}
|
|
383
|
+
// Directory
|
|
384
|
+
const entry = {
|
|
385
|
+
path: relativePath,
|
|
386
|
+
type: "directory",
|
|
387
|
+
name,
|
|
388
|
+
};
|
|
389
|
+
if (currentDepth < maxDepth) {
|
|
390
|
+
try {
|
|
391
|
+
const entries = fs.readdirSync(currentPath, { withFileTypes: true });
|
|
392
|
+
const children = [];
|
|
393
|
+
for (const e of entries) {
|
|
394
|
+
// Skip hidden and node_modules
|
|
395
|
+
if (e.name.startsWith(".") || e.name === "node_modules") {
|
|
396
|
+
continue;
|
|
397
|
+
}
|
|
398
|
+
const childPath = path.join(currentPath, e.name);
|
|
399
|
+
const childRelative = path.join(relativePath, e.name);
|
|
400
|
+
children.push(buildStructure(childPath, currentDepth + 1, childRelative));
|
|
401
|
+
}
|
|
402
|
+
entry.children = children;
|
|
403
|
+
}
|
|
404
|
+
catch {
|
|
405
|
+
// Skip directories we can't read
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
return entry;
|
|
409
|
+
}
|
|
410
|
+
return buildStructure(fullPath, 0, targetDir);
|
|
411
|
+
},
|
|
412
|
+
};
|
|
413
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analyze.test.d.ts","sourceRoot":"","sources":["../../../src/sandbox/sdk/analyze.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Analyze SDK Tests
|
|
3
|
+
*
|
|
4
|
+
* Tests for ctx.analyze.* functions.
|
|
5
|
+
*/
|
|
6
|
+
import { describe, it, expect, beforeAll } from "vitest";
|
|
7
|
+
import { createAnalyzeAPI } from "./analyze.js";
|
|
8
|
+
import * as fs from "fs";
|
|
9
|
+
import * as path from "path";
|
|
10
|
+
// Get the monorepo root
|
|
11
|
+
function getProjectRoot() {
|
|
12
|
+
let dir = __dirname;
|
|
13
|
+
while (dir !== "/" && !fs.existsSync(path.join(dir, "package.json"))) {
|
|
14
|
+
dir = path.dirname(dir);
|
|
15
|
+
}
|
|
16
|
+
return dir;
|
|
17
|
+
}
|
|
18
|
+
const projectRoot = getProjectRoot();
|
|
19
|
+
// Create mock callbacks
|
|
20
|
+
function createMockCallbacks(workingDir) {
|
|
21
|
+
return {
|
|
22
|
+
readFile(filePath) {
|
|
23
|
+
const fullPath = path.isAbsolute(filePath)
|
|
24
|
+
? filePath
|
|
25
|
+
: path.join(workingDir, filePath);
|
|
26
|
+
return fs.readFileSync(fullPath, "utf-8");
|
|
27
|
+
},
|
|
28
|
+
fileExists(filePath) {
|
|
29
|
+
const fullPath = path.isAbsolute(filePath)
|
|
30
|
+
? filePath
|
|
31
|
+
: path.join(workingDir, filePath);
|
|
32
|
+
try {
|
|
33
|
+
fs.accessSync(fullPath);
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
glob() {
|
|
41
|
+
return [];
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
describe("Analyze SDK", () => {
|
|
46
|
+
let analyze;
|
|
47
|
+
beforeAll(() => {
|
|
48
|
+
const callbacks = createMockCallbacks(projectRoot);
|
|
49
|
+
analyze = createAnalyzeAPI(projectRoot, callbacks);
|
|
50
|
+
});
|
|
51
|
+
describe("dependencies", () => {
|
|
52
|
+
it("should return DependencyResult structure", () => {
|
|
53
|
+
const result = analyze.dependencies("src/sandbox/sdk/analyze.ts");
|
|
54
|
+
expect(result).toBeDefined();
|
|
55
|
+
expect(result.file).toBe("src/sandbox/sdk/analyze.ts");
|
|
56
|
+
expect(Array.isArray(result.imports)).toBe(true);
|
|
57
|
+
expect(Array.isArray(result.exports)).toBe(true);
|
|
58
|
+
expect(Array.isArray(result.externalDeps)).toBe(true);
|
|
59
|
+
expect(Array.isArray(result.internalDeps)).toBe(true);
|
|
60
|
+
});
|
|
61
|
+
it("should detect imports", () => {
|
|
62
|
+
const result = analyze.dependencies("src/sandbox/sdk/analyze.ts");
|
|
63
|
+
expect(result.imports.length).toBeGreaterThan(0);
|
|
64
|
+
const imp = result.imports[0];
|
|
65
|
+
expect(imp.source).toBeDefined();
|
|
66
|
+
expect(Array.isArray(imp.names)).toBe(true);
|
|
67
|
+
expect(typeof imp.isDefault).toBe("boolean");
|
|
68
|
+
expect(typeof imp.isNamespace).toBe("boolean");
|
|
69
|
+
});
|
|
70
|
+
it("should detect exports", () => {
|
|
71
|
+
const result = analyze.dependencies("src/sandbox/sdk/analyze.ts");
|
|
72
|
+
expect(result.exports.length).toBeGreaterThan(0);
|
|
73
|
+
const hasCreateAnalyzeAPI = result.exports.some((e) => e.name === "createAnalyzeAPI");
|
|
74
|
+
expect(hasCreateAnalyzeAPI).toBe(true);
|
|
75
|
+
});
|
|
76
|
+
it("should categorize external vs internal deps", () => {
|
|
77
|
+
const result = analyze.dependencies("src/sandbox/sdk/analyze.ts");
|
|
78
|
+
// Should have some internal deps (relative imports)
|
|
79
|
+
expect(result.internalDeps.length).toBeGreaterThanOrEqual(0);
|
|
80
|
+
// Should recognize node modules as external
|
|
81
|
+
const hasFs = result.externalDeps.includes("fs");
|
|
82
|
+
const hasPath = result.externalDeps.includes("path");
|
|
83
|
+
expect(hasFs || hasPath).toBe(true);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
describe("exports", () => {
|
|
87
|
+
it("should return ExportInfo array", () => {
|
|
88
|
+
const result = analyze.exports("src/sandbox/sdk/analyze.ts");
|
|
89
|
+
expect(Array.isArray(result)).toBe(true);
|
|
90
|
+
});
|
|
91
|
+
it("should include export details", () => {
|
|
92
|
+
const result = analyze.exports("src/sandbox/sdk/analyze.ts");
|
|
93
|
+
if (result.length > 0) {
|
|
94
|
+
const exp = result[0];
|
|
95
|
+
expect(exp.name).toBeDefined();
|
|
96
|
+
expect(exp.type).toBeDefined();
|
|
97
|
+
expect(typeof exp.isDefault).toBe("boolean");
|
|
98
|
+
expect(typeof exp.line).toBe("number");
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
it("should find createAnalyzeAPI export", () => {
|
|
102
|
+
const result = analyze.exports("src/sandbox/sdk/analyze.ts");
|
|
103
|
+
const found = result.find((e) => e.name === "createAnalyzeAPI");
|
|
104
|
+
expect(found).toBeDefined();
|
|
105
|
+
expect(found?.type).toBe("function");
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
describe("callGraph", () => {
|
|
109
|
+
it("should return CallGraphResult structure", () => {
|
|
110
|
+
// Use a simple function that exists in the codebase
|
|
111
|
+
const result = analyze.callGraph("createAnalyzeAPI", "src/sandbox/sdk/analyze.ts");
|
|
112
|
+
expect(result).toBeDefined();
|
|
113
|
+
expect(result.root).toBe("createAnalyzeAPI");
|
|
114
|
+
expect(Array.isArray(result.nodes)).toBe(true);
|
|
115
|
+
expect(typeof result.depth).toBe("number");
|
|
116
|
+
});
|
|
117
|
+
it("should include the root function as a node", () => {
|
|
118
|
+
const result = analyze.callGraph("createAnalyzeAPI", "src/sandbox/sdk/analyze.ts");
|
|
119
|
+
const rootNode = result.nodes.find((n) => n.name === "createAnalyzeAPI");
|
|
120
|
+
expect(rootNode).toBeDefined();
|
|
121
|
+
expect(rootNode?.file).toBe("src/sandbox/sdk/analyze.ts");
|
|
122
|
+
});
|
|
123
|
+
it("should detect function calls", () => {
|
|
124
|
+
const result = analyze.callGraph("createAnalyzeAPI", "src/sandbox/sdk/analyze.ts");
|
|
125
|
+
const rootNode = result.nodes.find((n) => n.name === "createAnalyzeAPI");
|
|
126
|
+
expect(rootNode?.calls).toBeDefined();
|
|
127
|
+
expect(Array.isArray(rootNode?.calls)).toBe(true);
|
|
128
|
+
});
|
|
129
|
+
it("should throw for non-existent function", () => {
|
|
130
|
+
expect(() => analyze.callGraph("nonExistentFunction", "src/sandbox/sdk/analyze.ts")).toThrow("Function 'nonExistentFunction' not found");
|
|
131
|
+
});
|
|
132
|
+
it("should respect depth parameter", () => {
|
|
133
|
+
const shallow = analyze.callGraph("createAnalyzeAPI", "src/sandbox/sdk/analyze.ts", 1);
|
|
134
|
+
const deep = analyze.callGraph("createAnalyzeAPI", "src/sandbox/sdk/analyze.ts", 3);
|
|
135
|
+
expect(shallow.depth).toBe(1);
|
|
136
|
+
expect(deep.depth).toBe(3);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
describe("structure", () => {
|
|
140
|
+
it("should return StructureEntry for root", () => {
|
|
141
|
+
const result = analyze.structure("src/sandbox/sdk");
|
|
142
|
+
expect(result).toBeDefined();
|
|
143
|
+
expect(result.path).toBe("src/sandbox/sdk");
|
|
144
|
+
expect(result.type).toBe("directory");
|
|
145
|
+
expect(result.name).toBe("sdk");
|
|
146
|
+
});
|
|
147
|
+
it("should include children for directories", () => {
|
|
148
|
+
const result = analyze.structure("src/sandbox/sdk", 1);
|
|
149
|
+
expect(result.children).toBeDefined();
|
|
150
|
+
expect(Array.isArray(result.children)).toBe(true);
|
|
151
|
+
expect(result.children.length).toBeGreaterThan(0);
|
|
152
|
+
});
|
|
153
|
+
it("should detect files with code analysis", () => {
|
|
154
|
+
const result = analyze.structure("src/sandbox/sdk", 1);
|
|
155
|
+
const tsFile = result.children?.find((c) => c.type === "file" && c.name.endsWith(".ts") && !c.name.includes(".test."));
|
|
156
|
+
if (tsFile) {
|
|
157
|
+
expect(tsFile.language).toBe("typescript");
|
|
158
|
+
expect(typeof tsFile.functions).toBe("number");
|
|
159
|
+
expect(typeof tsFile.size).toBe("number");
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
it("should include file size", () => {
|
|
163
|
+
const result = analyze.structure("src/sandbox/sdk", 1);
|
|
164
|
+
const file = result.children?.find((c) => c.type === "file");
|
|
165
|
+
if (file) {
|
|
166
|
+
expect(typeof file.size).toBe("number");
|
|
167
|
+
expect(file.size).toBeGreaterThan(0);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
it("should respect depth parameter", () => {
|
|
171
|
+
const shallow = analyze.structure("src", 1);
|
|
172
|
+
const deep = analyze.structure("src", 2);
|
|
173
|
+
// Shallow should have children but not grandchildren
|
|
174
|
+
const shallowChild = shallow.children?.find((c) => c.type === "directory");
|
|
175
|
+
expect(shallowChild?.children).toBeUndefined();
|
|
176
|
+
// Deep should have grandchildren
|
|
177
|
+
const deepChild = deep.children?.find((c) => c.type === "directory");
|
|
178
|
+
if (deepChild?.children) {
|
|
179
|
+
expect(deepChild.children.length).toBeGreaterThanOrEqual(0);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
describe("error handling", () => {
|
|
184
|
+
it("should throw for invalid file path", () => {
|
|
185
|
+
expect(() => analyze.dependencies("../../../etc/passwd")).toThrow();
|
|
186
|
+
});
|
|
187
|
+
it("should throw for non-existent file", () => {
|
|
188
|
+
expect(() => analyze.dependencies("non-existent-file.ts")).toThrow();
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK Code/AST Functions
|
|
3
|
+
*
|
|
4
|
+
* Wraps AST parsing functionality for sandbox use.
|
|
5
|
+
*/
|
|
6
|
+
import type { SupportedLanguage } from "../../ast/types.js";
|
|
7
|
+
import type { FileStructure, ExtractionTarget } from "../types.js";
|
|
8
|
+
/**
|
|
9
|
+
* Parse code content to structure
|
|
10
|
+
*/
|
|
11
|
+
export declare function codeParse(content: string, language: SupportedLanguage): FileStructure;
|
|
12
|
+
/**
|
|
13
|
+
* Extract a specific element from code
|
|
14
|
+
*/
|
|
15
|
+
export declare function codeExtract(content: string, language: SupportedLanguage, target: ExtractionTarget): string | null;
|
|
16
|
+
/**
|
|
17
|
+
* Get code skeleton (signatures only)
|
|
18
|
+
*/
|
|
19
|
+
export declare function codeSkeleton(content: string, language: SupportedLanguage): string;
|
|
20
|
+
//# sourceMappingURL=code.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code.d.ts","sourceRoot":"","sources":["../../../src/sandbox/sdk/code.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,iBAAiB,EAA6B,MAAM,oBAAoB,CAAC;AACvF,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAe,MAAM,aAAa,CAAC;AAgBhF;;GAEG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,iBAAiB,GAAG,aAAa,CAarF;AAED;;GAEG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,iBAAiB,EAC3B,MAAM,EAAE,gBAAgB,GACvB,MAAM,GAAG,IAAI,CAyBf;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,iBAAiB,GAAG,MAAM,CAgDjF"}
|