octocode-cli 1.2.5 → 1.2.7
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/LICENSE +21 -63
- package/README.md +86 -109
- package/out/octocode-cli.js +7027 -7014
- package/package.json +8 -6
- package/skills/README.md +97 -120
- package/skills/octocode-code-engineer/.claude/settings.local.json +18 -0
- package/skills/octocode-code-engineer/.octocode/rfc/RFC-code-engineer-weakness-fixes.md +255 -0
- package/skills/octocode-code-engineer/.plan/VALIDATED_PLAN.md +223 -0
- package/skills/octocode-code-engineer/README.md +178 -0
- package/skills/octocode-code-engineer/SKILL.md +418 -0
- package/skills/octocode-code-engineer/coverage/architecture.ts.html +7828 -0
- package/skills/octocode-code-engineer/coverage/ast-helpers.ts.html +211 -0
- package/skills/octocode-code-engineer/coverage/ast-search.ts.html +1795 -0
- package/skills/octocode-code-engineer/coverage/base.css +224 -0
- package/skills/octocode-code-engineer/coverage/block-navigation.js +87 -0
- package/skills/octocode-code-engineer/coverage/cache.ts.html +376 -0
- package/skills/octocode-code-engineer/coverage/cli.ts.html +982 -0
- package/skills/octocode-code-engineer/coverage/clover.xml +3217 -0
- package/skills/octocode-code-engineer/coverage/collect-effects.ts.html +664 -0
- package/skills/octocode-code-engineer/coverage/collect-input-sources.ts.html +577 -0
- package/skills/octocode-code-engineer/coverage/collect-performance.ts.html +331 -0
- package/skills/octocode-code-engineer/coverage/collect-prototype-pollution.ts.html +421 -0
- package/skills/octocode-code-engineer/coverage/collect-security.ts.html +604 -0
- package/skills/octocode-code-engineer/coverage/collect-test-profile.ts.html +589 -0
- package/skills/octocode-code-engineer/coverage/coverage-final.json +30 -0
- package/skills/octocode-code-engineer/coverage/dependencies.ts.html +997 -0
- package/skills/octocode-code-engineer/coverage/dependency-summary.ts.html +688 -0
- package/skills/octocode-code-engineer/coverage/discovery.ts.html +322 -0
- package/skills/octocode-code-engineer/coverage/favicon.png +0 -0
- package/skills/octocode-code-engineer/coverage/graph-analytics.ts.html +1510 -0
- package/skills/octocode-code-engineer/coverage/index.html +536 -0
- package/skills/octocode-code-engineer/coverage/index.ts.html +826 -0
- package/skills/octocode-code-engineer/coverage/metrics.ts.html +553 -0
- package/skills/octocode-code-engineer/coverage/pipeline.ts.html +2044 -0
- package/skills/octocode-code-engineer/coverage/prettify.css +1 -0
- package/skills/octocode-code-engineer/coverage/prettify.js +2 -0
- package/skills/octocode-code-engineer/coverage/report-analysis.ts.html +1570 -0
- package/skills/octocode-code-engineer/coverage/report-writer.ts.html +1102 -0
- package/skills/octocode-code-engineer/coverage/security-detectors.ts.html +1747 -0
- package/skills/octocode-code-engineer/coverage/semantic-detectors.ts.html +2152 -0
- package/skills/octocode-code-engineer/coverage/semantic.ts.html +1897 -0
- package/skills/octocode-code-engineer/coverage/sort-arrow-sprite.png +0 -0
- package/skills/octocode-code-engineer/coverage/sorter.js +210 -0
- package/skills/octocode-code-engineer/coverage/summary-md.ts.html +1222 -0
- package/skills/octocode-code-engineer/coverage/test-quality-detectors.ts.html +1039 -0
- package/skills/octocode-code-engineer/coverage/tree-sitter-analyzer.ts.html +955 -0
- package/skills/octocode-code-engineer/coverage/ts-analyzer.ts.html +1213 -0
- package/skills/octocode-code-engineer/coverage/types.ts.html +2473 -0
- package/skills/octocode-code-engineer/coverage/utils.ts.html +820 -0
- package/skills/octocode-code-engineer/eslint.config.mjs +54 -0
- package/skills/octocode-code-engineer/minify-scripts.mjs +32 -0
- package/skills/octocode-code-engineer/package.json +54 -0
- package/skills/octocode-code-engineer/references/agent-ast-reading-rfc.md +95 -0
- package/skills/octocode-code-engineer/references/architecture-techniques.md +121 -0
- package/skills/octocode-code-engineer/references/ast-search.md +210 -0
- package/skills/octocode-code-engineer/references/ast-tree-search.md +151 -0
- package/skills/octocode-code-engineer/references/cli-reference.md +167 -0
- package/skills/octocode-code-engineer/references/concepts.md +107 -0
- package/skills/octocode-code-engineer/references/finding-categories.md +128 -0
- package/skills/octocode-code-engineer/references/improvement-roadmap.md +304 -0
- package/skills/octocode-code-engineer/references/output-files.md +144 -0
- package/skills/octocode-code-engineer/references/playbooks.md +204 -0
- package/skills/octocode-code-engineer/references/present-results.md +136 -0
- package/skills/octocode-code-engineer/references/tool-workflows.md +566 -0
- package/skills/octocode-code-engineer/references/validate-investigate.md +225 -0
- package/skills/octocode-code-engineer/scripts/analysis/dependencies.js +1 -0
- package/skills/octocode-code-engineer/scripts/analysis/dependency-summary.js +1 -0
- package/skills/octocode-code-engineer/scripts/analysis/discovery.js +1 -0
- package/skills/octocode-code-engineer/scripts/analysis/graph-analytics.js +1 -0
- package/skills/octocode-code-engineer/scripts/analysis/semantic.js +1 -0
- package/skills/octocode-code-engineer/scripts/ast/helpers.js +1 -0
- package/skills/octocode-code-engineer/scripts/ast/metrics.js +1 -0
- package/skills/octocode-code-engineer/scripts/ast/search.js +2 -0
- package/skills/octocode-code-engineer/scripts/ast/tree-search.js +2 -0
- package/skills/octocode-code-engineer/scripts/ast/tree-sitter.js +1 -0
- package/skills/octocode-code-engineer/scripts/ast/ts-analyzer.js +1 -0
- package/skills/octocode-code-engineer/scripts/collectors/chains.js +1 -0
- package/skills/octocode-code-engineer/scripts/collectors/effects.js +1 -0
- package/skills/octocode-code-engineer/scripts/collectors/input-sources.js +1 -0
- package/skills/octocode-code-engineer/scripts/collectors/performance.js +1 -0
- package/skills/octocode-code-engineer/scripts/collectors/prototype-pollution.js +1 -0
- package/skills/octocode-code-engineer/scripts/collectors/security.js +1 -0
- package/skills/octocode-code-engineer/scripts/collectors/test-profile.js +1 -0
- package/skills/octocode-code-engineer/scripts/common/is-direct-run.js +1 -0
- package/skills/octocode-code-engineer/scripts/common/utils.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/code-quality.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/cohesion.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/coupling.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/cycle.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/dead-code.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/import-style.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/index.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/security.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/semantic.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/shared.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/test-quality.js +1 -0
- package/skills/octocode-code-engineer/scripts/index.js +1 -0
- package/skills/octocode-code-engineer/scripts/pipeline/cache.js +1 -0
- package/skills/octocode-code-engineer/scripts/pipeline/cli.js +1 -0
- package/skills/octocode-code-engineer/scripts/pipeline/main.js +2 -0
- package/skills/octocode-code-engineer/scripts/reporting/analysis.js +1 -0
- package/skills/octocode-code-engineer/scripts/reporting/summary-md.js +1 -0
- package/skills/octocode-code-engineer/scripts/reporting/writer.js +1 -0
- package/skills/octocode-code-engineer/scripts/types/constants.js +1 -0
- package/skills/octocode-code-engineer/scripts/types/index.js +1 -0
- package/skills/octocode-code-engineer/scripts/types/interfaces.js +1 -0
- package/skills/octocode-code-engineer/src/analysis/dependencies.test.ts +545 -0
- package/skills/octocode-code-engineer/src/analysis/dependencies.ts +406 -0
- package/skills/octocode-code-engineer/src/analysis/dependency-summary.test.ts +566 -0
- package/skills/octocode-code-engineer/src/analysis/dependency-summary.ts +257 -0
- package/skills/octocode-code-engineer/src/analysis/discovery.test.ts +420 -0
- package/skills/octocode-code-engineer/src/analysis/discovery.ts +87 -0
- package/skills/octocode-code-engineer/src/analysis/graph-analytics.test.ts +449 -0
- package/skills/octocode-code-engineer/src/analysis/graph-analytics.ts +534 -0
- package/skills/octocode-code-engineer/src/analysis/semantic.test.ts +1533 -0
- package/skills/octocode-code-engineer/src/analysis/semantic.ts +830 -0
- package/skills/octocode-code-engineer/src/ast/helpers.test.ts +185 -0
- package/skills/octocode-code-engineer/src/ast/helpers.ts +62 -0
- package/skills/octocode-code-engineer/src/ast/metrics.test.ts +304 -0
- package/skills/octocode-code-engineer/src/ast/metrics.ts +204 -0
- package/skills/octocode-code-engineer/src/ast/search.test.ts +647 -0
- package/skills/octocode-code-engineer/src/ast/search.ts +648 -0
- package/skills/octocode-code-engineer/src/ast/tree-search.test.ts +199 -0
- package/skills/octocode-code-engineer/src/ast/tree-search.ts +392 -0
- package/skills/octocode-code-engineer/src/ast/tree-sitter.test.ts +407 -0
- package/skills/octocode-code-engineer/src/ast/tree-sitter.ts +402 -0
- package/skills/octocode-code-engineer/src/ast/ts-analyzer.test.ts +1864 -0
- package/skills/octocode-code-engineer/src/ast/ts-analyzer.ts +509 -0
- package/skills/octocode-code-engineer/src/collectors/chains.ts +74 -0
- package/skills/octocode-code-engineer/src/collectors/effects.test.ts +490 -0
- package/skills/octocode-code-engineer/src/collectors/effects.ts +332 -0
- package/skills/octocode-code-engineer/src/collectors/input-sources.test.ts +144 -0
- package/skills/octocode-code-engineer/src/collectors/input-sources.ts +196 -0
- package/skills/octocode-code-engineer/src/collectors/performance.test.ts +82 -0
- package/skills/octocode-code-engineer/src/collectors/performance.ts +141 -0
- package/skills/octocode-code-engineer/src/collectors/prototype-pollution.test.ts +55 -0
- package/skills/octocode-code-engineer/src/collectors/prototype-pollution.ts +162 -0
- package/skills/octocode-code-engineer/src/collectors/security.test.ts +124 -0
- package/skills/octocode-code-engineer/src/collectors/security.ts +309 -0
- package/skills/octocode-code-engineer/src/collectors/test-profile.test.ts +97 -0
- package/skills/octocode-code-engineer/src/collectors/test-profile.ts +269 -0
- package/skills/octocode-code-engineer/src/common/is-direct-run.test.ts +32 -0
- package/skills/octocode-code-engineer/src/common/is-direct-run.ts +13 -0
- package/skills/octocode-code-engineer/src/common/utils.test.ts +463 -0
- package/skills/octocode-code-engineer/src/common/utils.ts +304 -0
- package/skills/octocode-code-engineer/src/detectors/code-quality.ts +966 -0
- package/skills/octocode-code-engineer/src/detectors/cohesion.ts +539 -0
- package/skills/octocode-code-engineer/src/detectors/coupling.ts +323 -0
- package/skills/octocode-code-engineer/src/detectors/cycle.ts +349 -0
- package/skills/octocode-code-engineer/src/detectors/dead-code.ts +320 -0
- package/skills/octocode-code-engineer/src/detectors/import-style.ts +376 -0
- package/skills/octocode-code-engineer/src/detectors/index.test.ts +3061 -0
- package/skills/octocode-code-engineer/src/detectors/index.ts +88 -0
- package/skills/octocode-code-engineer/src/detectors/security.test.ts +882 -0
- package/skills/octocode-code-engineer/src/detectors/security.ts +821 -0
- package/skills/octocode-code-engineer/src/detectors/semantic.ts +758 -0
- package/skills/octocode-code-engineer/src/detectors/shared.ts +49 -0
- package/skills/octocode-code-engineer/src/detectors/test-quality.test.ts +388 -0
- package/skills/octocode-code-engineer/src/detectors/test-quality.ts +367 -0
- package/skills/octocode-code-engineer/src/index.test.ts +4425 -0
- package/skills/octocode-code-engineer/src/index.ts +403 -0
- package/skills/octocode-code-engineer/src/pipeline/cache.test.ts +199 -0
- package/skills/octocode-code-engineer/src/pipeline/cache.ts +130 -0
- package/skills/octocode-code-engineer/src/pipeline/cli.test.ts +493 -0
- package/skills/octocode-code-engineer/src/pipeline/cli.ts +344 -0
- package/skills/octocode-code-engineer/src/pipeline/main.test.ts +174 -0
- package/skills/octocode-code-engineer/src/pipeline/main.ts +1074 -0
- package/skills/octocode-code-engineer/src/pipeline.test.ts +84 -0
- package/skills/octocode-code-engineer/src/reporting/analysis.test.ts +782 -0
- package/skills/octocode-code-engineer/src/reporting/analysis.ts +688 -0
- package/skills/octocode-code-engineer/src/reporting/output-contract.test.ts +463 -0
- package/skills/octocode-code-engineer/src/reporting/summary-md.test.ts +421 -0
- package/skills/octocode-code-engineer/src/reporting/summary-md.ts +714 -0
- package/skills/octocode-code-engineer/src/reporting/writer.ts +430 -0
- package/skills/octocode-code-engineer/src/sanity.test.ts +47 -0
- package/skills/octocode-code-engineer/src/types/constants.ts +248 -0
- package/skills/octocode-code-engineer/src/types/index.ts +80 -0
- package/skills/octocode-code-engineer/src/types/interfaces.ts +682 -0
- package/skills/octocode-code-engineer/tsconfig.json +17 -0
- package/skills/octocode-code-engineer/vitest.config.ts +8 -0
- package/skills/octocode-documentation-writer/README.md +113 -0
- package/skills/octocode-documentation-writer/SKILL.md +886 -0
- package/skills/octocode-documentation-writer/references/agent-discovery-analysis.md +453 -0
- package/skills/octocode-documentation-writer/references/agent-documentation-writer.md +255 -0
- package/skills/octocode-documentation-writer/references/agent-engineer-questions.md +247 -0
- package/skills/octocode-documentation-writer/references/agent-orchestrator.md +370 -0
- package/skills/octocode-documentation-writer/references/agent-qa-validator.md +227 -0
- package/skills/octocode-documentation-writer/references/agent-researcher.md +250 -0
- package/skills/octocode-documentation-writer/schemas/analysis-schema.json +886 -0
- package/skills/octocode-documentation-writer/schemas/discovery-tasks.json +96 -0
- package/skills/octocode-documentation-writer/schemas/documentation-structure.json +373 -0
- package/skills/octocode-documentation-writer/schemas/partial-discovery-schema.json +102 -0
- package/skills/octocode-documentation-writer/schemas/partial-research-schema.json +98 -0
- package/skills/octocode-documentation-writer/schemas/qa-results-schema.json +113 -0
- package/skills/octocode-documentation-writer/schemas/questions-schema.json +228 -0
- package/skills/octocode-documentation-writer/schemas/research-schema.json +104 -0
- package/skills/octocode-documentation-writer/schemas/state-schema.json +222 -0
- package/skills/octocode-documentation-writer/schemas/work-assignments-schema.json +74 -0
- package/skills/octocode-plan/SKILL.md +122 -116
- package/skills/octocode-prompt-optimizer/SKILL.md +617 -0
- package/skills/octocode-pull-request-reviewer/README.md +249 -0
- package/skills/octocode-pull-request-reviewer/SKILL.md +479 -0
- package/skills/octocode-pull-request-reviewer/references/dependency-check.md +74 -0
- package/skills/octocode-pull-request-reviewer/references/domain-reviewers.md +24 -0
- package/skills/octocode-pull-request-reviewer/references/execution-lifecycle.md +441 -0
- package/skills/octocode-pull-request-reviewer/references/flow-analysis-protocol.md +64 -0
- package/skills/octocode-pull-request-reviewer/references/output-template.md +174 -0
- package/skills/octocode-pull-request-reviewer/references/parallel-agent-protocol.md +182 -0
- package/skills/octocode-pull-request-reviewer/references/review-guidelines.md +26 -0
- package/skills/octocode-pull-request-reviewer/references/verification-checklist.md +40 -0
- package/skills/octocode-research/.claude/settings.local.json +46 -0
- package/skills/octocode-research/.octocode/plan/code-review-fixes/plan.md +312 -0
- package/skills/octocode-research/.octocode/plan/code-review-fixes/research.md +212 -0
- package/skills/octocode-research/.octocode/plans/NODE_SERVER_START_PLAN.md +755 -0
- package/skills/octocode-research/.octocode/research/code-review/research.md +371 -0
- package/skills/octocode-research/.octocode/review/IMPROVEMENTS.md +391 -0
- package/skills/octocode-research/.octocode/review/REVIEW_PLAN.md +289 -0
- package/skills/octocode-research/.octocode/review/REVIEW_REPORT.md +356 -0
- package/skills/octocode-research/AGENTS.md +349 -0
- package/skills/octocode-research/README.md +494 -0
- package/skills/octocode-research/SKILL.md +652 -274
- package/skills/octocode-research/docs/API_REFERENCE.md +562 -0
- package/skills/octocode-research/docs/ARCHITECTURE.md +554 -0
- package/skills/octocode-research/docs/FLOWS.md +577 -0
- package/skills/octocode-research/docs/OVERVIEW.md +564 -0
- package/skills/octocode-research/docs/SERVER_FLOWS.md +631 -0
- package/skills/octocode-research/ecosystem.config.cjs +88 -0
- package/skills/octocode-research/eslint.config.mjs +27 -0
- package/skills/octocode-research/package.json +84 -0
- package/skills/octocode-research/references/GUARDRAILS.md +40 -0
- package/skills/octocode-research/references/PARALLEL_AGENT_PROTOCOL.md +178 -0
- package/skills/octocode-research/references/roast-prompt.md +149 -0
- package/skills/octocode-research/scripts/server-init.d.ts +2 -0
- package/skills/octocode-research/scripts/server-init.js +2 -0
- package/skills/octocode-research/scripts/server.d.ts +8 -0
- package/skills/octocode-research/scripts/server.js +445 -0
- package/skills/octocode-research/src/__tests__/integration/circuitBreaker.test.ts +205 -0
- package/skills/octocode-research/src/__tests__/integration/routes.test.ts +374 -0
- package/skills/octocode-research/src/__tests__/unit/circuitBreaker.test.ts +245 -0
- package/skills/octocode-research/src/__tests__/unit/errorHandler.test.ts +183 -0
- package/skills/octocode-research/src/__tests__/unit/httpPreprocess.test.ts +157 -0
- package/skills/octocode-research/src/__tests__/unit/logger.test.ts +143 -0
- package/skills/octocode-research/src/__tests__/unit/queryParser.test.ts +130 -0
- package/skills/octocode-research/src/__tests__/unit/responseBuilder.test.ts +469 -0
- package/skills/octocode-research/src/__tests__/unit/retry.test.ts +205 -0
- package/skills/octocode-research/src/index.ts +186 -0
- package/skills/octocode-research/src/mcpCache.ts +49 -0
- package/skills/octocode-research/src/middleware/errorHandler.ts +65 -0
- package/skills/octocode-research/src/middleware/logger.ts +61 -0
- package/skills/octocode-research/src/middleware/queryParser.ts +115 -0
- package/skills/octocode-research/src/middleware/readiness.ts +17 -0
- package/skills/octocode-research/src/routes/github.ts +197 -0
- package/skills/octocode-research/src/routes/local.ts +175 -0
- package/skills/octocode-research/src/routes/lsp.ts +177 -0
- package/skills/octocode-research/src/routes/package.ts +127 -0
- package/skills/octocode-research/src/routes/prompts.ts +138 -0
- package/skills/octocode-research/src/routes/tools.ts +677 -0
- package/skills/octocode-research/src/server-init.ts +363 -0
- package/skills/octocode-research/src/server.ts +285 -0
- package/skills/octocode-research/src/types/errorGuards.ts +151 -0
- package/skills/octocode-research/src/types/express.d.ts +76 -0
- package/skills/octocode-research/src/types/guards.ts +98 -0
- package/skills/octocode-research/src/types/mcp.ts +119 -0
- package/skills/octocode-research/src/types/responses.ts +199 -0
- package/skills/octocode-research/src/types/toolTypes.ts +33 -0
- package/skills/octocode-research/src/utils/asyncTimeout.ts +116 -0
- package/skills/octocode-research/src/utils/circuitBreaker.ts +492 -0
- package/skills/octocode-research/src/utils/colors.ts +53 -0
- package/skills/octocode-research/src/utils/errorQueue.ts +71 -0
- package/skills/octocode-research/src/utils/logEmoji.ts +103 -0
- package/skills/octocode-research/src/utils/logger.ts +413 -0
- package/skills/octocode-research/src/utils/resilience.ts +169 -0
- package/skills/octocode-research/src/utils/responseBuilder.ts +495 -0
- package/skills/octocode-research/src/utils/responseFactory.ts +100 -0
- package/skills/octocode-research/src/utils/responseParser.ts +272 -0
- package/skills/octocode-research/src/utils/retry.ts +280 -0
- package/skills/octocode-research/src/utils/routeFactory.ts +117 -0
- package/skills/octocode-research/src/utils/url.ts +20 -0
- package/skills/octocode-research/src/validation/httpPreprocess.ts +155 -0
- package/skills/octocode-research/src/validation/index.ts +2 -0
- package/skills/octocode-research/src/validation/schemas.ts +578 -0
- package/skills/octocode-research/src/validation/toolCallSchema.ts +132 -0
- package/skills/octocode-research/tsconfig.json +21 -0
- package/skills/octocode-research/tsdown.config.ts +42 -0
- package/skills/octocode-research/vitest.config.ts +20 -0
- package/skills/octocode-researcher/SKILL.md +461 -0
- package/skills/octocode-researcher/references/fallbacks.md +120 -0
- package/skills/{octocode-local-search → octocode-researcher}/references/tool-reference.md +132 -49
- package/skills/{octocode-local-search → octocode-researcher}/references/workflow-patterns.md +204 -4
- package/skills/octocode-rfc-generator/SKILL.md +223 -0
- package/skills/octocode-rfc-generator/references/rfc-template.md +193 -0
- package/skills/octocode-roast/SKILL.md +63 -21
- package/skills/octocode-implement/SKILL.md +0 -293
- package/skills/octocode-implement/references/execution-phases.md +0 -317
- package/skills/octocode-implement/references/tool-reference.md +0 -403
- package/skills/octocode-implement/references/workflow-patterns.md +0 -385
- package/skills/octocode-local-search/SKILL.md +0 -449
- package/skills/octocode-pr-review/SKILL.md +0 -391
- package/skills/octocode-pr-review/references/domain-reviewers.md +0 -105
- package/skills/octocode-pr-review/references/execution-lifecycle.md +0 -116
- package/skills/octocode-pr-review/references/research-flows.md +0 -75
- package/skills/octocode-research/references/tool-reference.md +0 -304
- package/skills/octocode-research/references/workflow-patterns.md +0 -325
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
buildTreeSitterTree,
|
|
5
|
+
hashString,
|
|
6
|
+
increment,
|
|
7
|
+
makeTreeSitterFingerprint,
|
|
8
|
+
} from '../common/utils.js';
|
|
9
|
+
import {
|
|
10
|
+
TS_TREE_SITTER_CONTROL_TYPES,
|
|
11
|
+
TS_TREE_SITTER_FUNCTION_TYPES,
|
|
12
|
+
} from '../types/index.js';
|
|
13
|
+
|
|
14
|
+
import type {
|
|
15
|
+
AnalysisOptions,
|
|
16
|
+
FlowEntry,
|
|
17
|
+
FlowMaps,
|
|
18
|
+
FunctionEntry,
|
|
19
|
+
Location,
|
|
20
|
+
NodeBudget,
|
|
21
|
+
SyntaxNode,
|
|
22
|
+
TreeSitterFileEntry,
|
|
23
|
+
TreeSitterMetrics,
|
|
24
|
+
TreeSitterRuntime,
|
|
25
|
+
} from '../types/index.js';
|
|
26
|
+
import type Parser from 'tree-sitter';
|
|
27
|
+
|
|
28
|
+
let treeSitterRuntime: TreeSitterRuntime | null = null;
|
|
29
|
+
|
|
30
|
+
export function getTreeSitterRuntime(): TreeSitterRuntime | null {
|
|
31
|
+
return treeSitterRuntime;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function hasLogicalOperator(node: SyntaxNode): boolean {
|
|
35
|
+
for (const child of node.children) {
|
|
36
|
+
if (!child.isNamed && (child.type === '&&' || child.type === '||'))
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function collectTreeSitterMetrics(
|
|
43
|
+
node: SyntaxNode,
|
|
44
|
+
_sourceText: string
|
|
45
|
+
): TreeSitterMetrics {
|
|
46
|
+
const metrics: TreeSitterMetrics = {
|
|
47
|
+
complexity: 1,
|
|
48
|
+
maxBranchDepth: 0,
|
|
49
|
+
maxLoopDepth: 0,
|
|
50
|
+
returns: 0,
|
|
51
|
+
awaits: 0,
|
|
52
|
+
calls: 0,
|
|
53
|
+
loops: 0,
|
|
54
|
+
statements: 0,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const visit = (
|
|
58
|
+
n: SyntaxNode,
|
|
59
|
+
branchDepth: number,
|
|
60
|
+
loopDepth: number
|
|
61
|
+
): void => {
|
|
62
|
+
metrics.statements += 1;
|
|
63
|
+
|
|
64
|
+
if (
|
|
65
|
+
[
|
|
66
|
+
'if_statement',
|
|
67
|
+
'while_statement',
|
|
68
|
+
'do_statement',
|
|
69
|
+
'for_statement',
|
|
70
|
+
'for_in_statement',
|
|
71
|
+
'for_of_statement',
|
|
72
|
+
'for_await_statement',
|
|
73
|
+
'switch_statement',
|
|
74
|
+
'catch_clause',
|
|
75
|
+
].includes(n.type)
|
|
76
|
+
) {
|
|
77
|
+
metrics.complexity += 1;
|
|
78
|
+
branchDepth += 1;
|
|
79
|
+
metrics.maxBranchDepth = Math.max(metrics.maxBranchDepth, branchDepth);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (n.type === 'conditional_expression') {
|
|
83
|
+
metrics.complexity += 1;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (n.type === 'binary_expression' && hasLogicalOperator(n)) {
|
|
87
|
+
metrics.complexity += 1;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (n.type === 'return_statement' || n.type === 'throw_statement') {
|
|
91
|
+
metrics.returns += 1;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (n.type === 'await_expression') {
|
|
95
|
+
metrics.awaits += 1;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (n.type === 'call_expression') {
|
|
99
|
+
metrics.calls += 1;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (
|
|
103
|
+
[
|
|
104
|
+
'for_statement',
|
|
105
|
+
'for_in_statement',
|
|
106
|
+
'for_of_statement',
|
|
107
|
+
'for_await_statement',
|
|
108
|
+
'while_statement',
|
|
109
|
+
'do_statement',
|
|
110
|
+
].includes(n.type)
|
|
111
|
+
) {
|
|
112
|
+
const nextLoopDepth = loopDepth + 1;
|
|
113
|
+
metrics.loops += 1;
|
|
114
|
+
metrics.maxLoopDepth = Math.max(metrics.maxLoopDepth, nextLoopDepth);
|
|
115
|
+
for (const child of n.children) {
|
|
116
|
+
visit(child, branchDepth, nextLoopDepth);
|
|
117
|
+
}
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
for (const child of n.children) {
|
|
122
|
+
visit(child, branchDepth, loopDepth);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
visit(node, 0, 0);
|
|
127
|
+
return metrics;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function inferTreeSitterFunctionName(node: SyntaxNode, _text: string): string {
|
|
131
|
+
const identifier = node.namedChildren.find(child =>
|
|
132
|
+
['identifier', 'property_identifier', 'type_identifier'].includes(
|
|
133
|
+
child.type
|
|
134
|
+
)
|
|
135
|
+
);
|
|
136
|
+
if (identifier) return identifier.text;
|
|
137
|
+
|
|
138
|
+
let parent = node.parent;
|
|
139
|
+
while (parent) {
|
|
140
|
+
if (parent.type === 'variable_declarator') {
|
|
141
|
+
const id = parent.namedChildren.find(child =>
|
|
142
|
+
[
|
|
143
|
+
'identifier',
|
|
144
|
+
'property_identifier',
|
|
145
|
+
'array_pattern',
|
|
146
|
+
'object_pattern',
|
|
147
|
+
'shorthand_property_identifier_pattern',
|
|
148
|
+
].includes(child.type)
|
|
149
|
+
);
|
|
150
|
+
if (id && id.type === 'identifier') {
|
|
151
|
+
return id.text;
|
|
152
|
+
}
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (parent.type === 'pair') {
|
|
157
|
+
const key = parent.namedChildren.find(child =>
|
|
158
|
+
[
|
|
159
|
+
'identifier',
|
|
160
|
+
'string',
|
|
161
|
+
'shorthand_property_identifier_pattern',
|
|
162
|
+
'property_identifier',
|
|
163
|
+
].includes(child.type)
|
|
164
|
+
);
|
|
165
|
+
if (key) return key.text;
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (
|
|
170
|
+
[
|
|
171
|
+
'assignment_expression',
|
|
172
|
+
'method_definition',
|
|
173
|
+
'property_signature',
|
|
174
|
+
'public_field_definition',
|
|
175
|
+
].includes(parent.type)
|
|
176
|
+
) {
|
|
177
|
+
const key = parent.namedChildren.find(child =>
|
|
178
|
+
[
|
|
179
|
+
'identifier',
|
|
180
|
+
'property_identifier',
|
|
181
|
+
'string',
|
|
182
|
+
'private_property_identifier',
|
|
183
|
+
].includes(child.type)
|
|
184
|
+
);
|
|
185
|
+
if (key) return key.text;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (parent.type === 'statement_block' || parent.type === 'program') break;
|
|
189
|
+
parent = parent.parent;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return '<anonymous>';
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function countTreeSitterStatements(node: SyntaxNode): number {
|
|
196
|
+
const body = node.namedChildren.find(
|
|
197
|
+
child => child.type === 'statement_block'
|
|
198
|
+
);
|
|
199
|
+
if (!body) return 1;
|
|
200
|
+
return body.namedChildren.length;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function countControlFlowBodyStatements(node: SyntaxNode): number {
|
|
204
|
+
const body = node.namedChildren.find(
|
|
205
|
+
child => child.type === 'statement_block' || child.type === 'switch_body'
|
|
206
|
+
);
|
|
207
|
+
if (body) return body.namedChildren.length;
|
|
208
|
+
return node.namedChildren.length;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function makeLocationFromTree(
|
|
212
|
+
node: SyntaxNode,
|
|
213
|
+
repoRoot: string,
|
|
214
|
+
filePath: string
|
|
215
|
+
): Location {
|
|
216
|
+
return {
|
|
217
|
+
file: path.relative(repoRoot, filePath),
|
|
218
|
+
lineStart: node.startPosition.row + 1,
|
|
219
|
+
lineEnd: node.endPosition.row + 1,
|
|
220
|
+
columnStart: node.startPosition.column + 1,
|
|
221
|
+
columnEnd: node.endPosition.column + 1,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export function analyzeTreeSitterFile(
|
|
226
|
+
filePath: string,
|
|
227
|
+
sourceText: string,
|
|
228
|
+
options: AnalysisOptions,
|
|
229
|
+
packageName: string,
|
|
230
|
+
maps: FlowMaps | null
|
|
231
|
+
): TreeSitterFileEntry | null {
|
|
232
|
+
if (!treeSitterRuntime?.available) return null;
|
|
233
|
+
|
|
234
|
+
const ext = path.extname(filePath);
|
|
235
|
+
const parser =
|
|
236
|
+
ext === '.tsx' || ext === '.jsx'
|
|
237
|
+
? treeSitterRuntime.parserTsx
|
|
238
|
+
: treeSitterRuntime.parserTs;
|
|
239
|
+
if (!parser) return null;
|
|
240
|
+
|
|
241
|
+
const tree = parser.parse(sourceText);
|
|
242
|
+
const fileRelative = path.relative(options.root, filePath);
|
|
243
|
+
const fileEntry: TreeSitterFileEntry = {
|
|
244
|
+
parseEngine: 'tree-sitter',
|
|
245
|
+
nodeCount: 0,
|
|
246
|
+
functions: [],
|
|
247
|
+
flows: [],
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
if (options.emitTree) {
|
|
251
|
+
const nodeBudget: NodeBudget = { size: 8000 };
|
|
252
|
+
const snapshot = buildTreeSitterTree(
|
|
253
|
+
tree.rootNode,
|
|
254
|
+
sourceText,
|
|
255
|
+
options.treeDepth,
|
|
256
|
+
nodeBudget
|
|
257
|
+
);
|
|
258
|
+
if (snapshot) {
|
|
259
|
+
fileEntry.tree = snapshot;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const visit = (node: SyntaxNode): void => {
|
|
264
|
+
fileEntry.nodeCount += 1;
|
|
265
|
+
|
|
266
|
+
if (TS_TREE_SITTER_FUNCTION_TYPES.has(node.type)) {
|
|
267
|
+
const loc = makeLocationFromTree(node, options.root, filePath);
|
|
268
|
+
const metrics = collectTreeSitterMetrics(node, sourceText);
|
|
269
|
+
const statementCount = countTreeSitterStatements(node);
|
|
270
|
+
const name = inferTreeSitterFunctionName(node, sourceText);
|
|
271
|
+
const params = node.childForFieldName('parameters');
|
|
272
|
+
const paramCount = params ? params.namedChildren.length : 0;
|
|
273
|
+
|
|
274
|
+
const entry: FunctionEntry = {
|
|
275
|
+
kind: node.type,
|
|
276
|
+
name,
|
|
277
|
+
nameHint: name,
|
|
278
|
+
file: fileRelative,
|
|
279
|
+
lineStart: loc.lineStart,
|
|
280
|
+
lineEnd: loc.lineEnd,
|
|
281
|
+
columnStart: loc.columnStart,
|
|
282
|
+
columnEnd: loc.columnEnd,
|
|
283
|
+
statementCount,
|
|
284
|
+
lengthLines: loc.lineEnd - loc.lineStart + 1,
|
|
285
|
+
params: paramCount,
|
|
286
|
+
complexity: metrics.complexity,
|
|
287
|
+
maxBranchDepth: metrics.maxBranchDepth,
|
|
288
|
+
maxLoopDepth: metrics.maxLoopDepth,
|
|
289
|
+
returns: metrics.returns,
|
|
290
|
+
awaits: metrics.awaits,
|
|
291
|
+
calls: metrics.calls,
|
|
292
|
+
loops: metrics.loops,
|
|
293
|
+
cognitiveComplexity: 0,
|
|
294
|
+
source: 'tree-sitter',
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
fileEntry.functions.push(entry);
|
|
298
|
+
|
|
299
|
+
if (maps && statementCount >= options.minFunctionStatements) {
|
|
300
|
+
const body = node.namedChildren.find(
|
|
301
|
+
child => child.type === 'statement_block'
|
|
302
|
+
);
|
|
303
|
+
const bodyHash = body
|
|
304
|
+
? makeTreeSitterFingerprint(body)
|
|
305
|
+
: hashString(fileRelative);
|
|
306
|
+
increment(maps.flowMap, `${bodyHash}|${node.type}`, {
|
|
307
|
+
...entry,
|
|
308
|
+
hash: bodyHash,
|
|
309
|
+
metrics,
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (TS_TREE_SITTER_CONTROL_TYPES.has(node.type)) {
|
|
315
|
+
const loc = makeLocationFromTree(node, options.root, filePath);
|
|
316
|
+
const statementCount = countControlFlowBodyStatements(node);
|
|
317
|
+
const flowEntry: FlowEntry = {
|
|
318
|
+
kind: node.type,
|
|
319
|
+
file: fileRelative,
|
|
320
|
+
lineStart: loc.lineStart,
|
|
321
|
+
lineEnd: loc.lineEnd,
|
|
322
|
+
columnStart: loc.columnStart,
|
|
323
|
+
columnEnd: loc.columnEnd,
|
|
324
|
+
statementCount,
|
|
325
|
+
};
|
|
326
|
+
fileEntry.flows.push(flowEntry);
|
|
327
|
+
|
|
328
|
+
if (maps && statementCount >= options.minFlowStatements) {
|
|
329
|
+
const flowHash = makeTreeSitterFingerprint(node);
|
|
330
|
+
increment(maps.controlMap, `${flowHash}|${node.type}`, {
|
|
331
|
+
...flowEntry,
|
|
332
|
+
hash: flowHash,
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
for (const child of node.children) {
|
|
338
|
+
visit(child);
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
visit(tree.rootNode);
|
|
343
|
+
return fileEntry;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
export async function resolveTreeSitter(): Promise<TreeSitterRuntime> {
|
|
347
|
+
if (treeSitterRuntime !== null) return treeSitterRuntime;
|
|
348
|
+
|
|
349
|
+
try {
|
|
350
|
+
const parserMod = await import('tree-sitter');
|
|
351
|
+
const typescriptMod: Record<string, unknown> =
|
|
352
|
+
await import('tree-sitter-typescript');
|
|
353
|
+
|
|
354
|
+
const ParserClass = parserMod.default || parserMod;
|
|
355
|
+
|
|
356
|
+
const tsLang =
|
|
357
|
+
(typescriptMod as Record<string, unknown>).typescript ||
|
|
358
|
+
(
|
|
359
|
+
(typescriptMod as Record<string, unknown>).default as Record<
|
|
360
|
+
string,
|
|
361
|
+
unknown
|
|
362
|
+
>
|
|
363
|
+
)?.typescript;
|
|
364
|
+
const tsxLang =
|
|
365
|
+
(typescriptMod as Record<string, unknown>).tsx ||
|
|
366
|
+
(
|
|
367
|
+
(typescriptMod as Record<string, unknown>).default as Record<
|
|
368
|
+
string,
|
|
369
|
+
unknown
|
|
370
|
+
>
|
|
371
|
+
)?.tsx;
|
|
372
|
+
|
|
373
|
+
if (!ParserClass || !tsLang) {
|
|
374
|
+
throw new Error(
|
|
375
|
+
'Tree-sitter or tree-sitter-typescript did not expose expected exports'
|
|
376
|
+
);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
const parserTs = new (ParserClass as new () => Parser)();
|
|
380
|
+
parserTs.setLanguage(tsLang as Parameters<Parser['setLanguage']>[0]);
|
|
381
|
+
|
|
382
|
+
const parserTsx = new (ParserClass as new () => Parser)();
|
|
383
|
+
parserTsx.setLanguage(
|
|
384
|
+
(tsxLang || tsLang) as Parameters<Parser['setLanguage']>[0]
|
|
385
|
+
);
|
|
386
|
+
|
|
387
|
+
treeSitterRuntime = {
|
|
388
|
+
available: true,
|
|
389
|
+
parserTs,
|
|
390
|
+
parserTsx,
|
|
391
|
+
};
|
|
392
|
+
return treeSitterRuntime;
|
|
393
|
+
} catch (error: unknown) {
|
|
394
|
+
treeSitterRuntime = {
|
|
395
|
+
available: false,
|
|
396
|
+
parserTs: null,
|
|
397
|
+
parserTsx: null,
|
|
398
|
+
error: String((error as Error)?.message || error),
|
|
399
|
+
};
|
|
400
|
+
return treeSitterRuntime;
|
|
401
|
+
}
|
|
402
|
+
}
|