octocode-cli 1.2.6 → 1.2.8
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 +85 -142
- package/out/octocode-cli.js +7063 -6934
- 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,151 @@
|
|
|
1
|
+
# AST Tree Search
|
|
2
|
+
|
|
3
|
+
Use `ast/tree-search.js` to inspect the generated `ast-trees.txt` artifact from one specific scan.
|
|
4
|
+
|
|
5
|
+
This is the canonical way to read AST snapshot output for agents because it keeps the search pinned to the current scan and bounds noisy output by default.
|
|
6
|
+
|
|
7
|
+
## When to Use It
|
|
8
|
+
|
|
9
|
+
- use it after reading `summary.md` when you want fast structure-first triage
|
|
10
|
+
- use it before `ast/search.js` when you are still deciding which file deserves deeper source-level inspection
|
|
11
|
+
- use it to narrow by node kind, file, or section without accidentally reading a different scan
|
|
12
|
+
|
|
13
|
+
Do not use it as proof of live-code behavior. After artifact triage, validate important claims with Octocode local and LSP tools, or with `ast/search.js` for structural confirmation.
|
|
14
|
+
|
|
15
|
+
## What `ast-trees.txt` Looks Like
|
|
16
|
+
|
|
17
|
+
Each file gets a `## package — path` header. Nodes are `Kind[startLine:endLine]`, nesting = indentation. Truncated subtrees end with `...`.
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
## my-package — src/services/storage.ts
|
|
21
|
+
SourceFile[1:152]
|
|
22
|
+
ImportDeclaration[1:3]
|
|
23
|
+
FunctionDeclaration[10:45]
|
|
24
|
+
Block[11:44]
|
|
25
|
+
IfStatement[12:20] ...
|
|
26
|
+
ReturnStatement[43]
|
|
27
|
+
ExportDeclaration[50:52]
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
This tells you: `storage.ts` has a function spanning lines 10-45 with a conditional inside it. Use this to decide which files and functions deserve source-level inspection.
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
node <SKILL_DIR>/scripts/ast/tree-search.js [options]
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Core options:
|
|
39
|
+
|
|
40
|
+
- `--input, -i <path>`: `ast-trees.txt`, a timestamped scan directory, or the scan root
|
|
41
|
+
- `--kind, -k <kind>`: match node kinds such as `function_declaration` or `ClassDeclaration`
|
|
42
|
+
- `--pattern, -p <regex>`: regex against AST tree lines
|
|
43
|
+
- `--file <regex>`: filter to section file paths that match the regex
|
|
44
|
+
- `--section <regex>`: filter to section headers that match the regex
|
|
45
|
+
- `--limit <n>`: default `50`; use `0` for all matches
|
|
46
|
+
- `--context, -C <n>`: include surrounding lines
|
|
47
|
+
- `--json`: machine-readable output
|
|
48
|
+
- `--ignore-case`: case-insensitive matching
|
|
49
|
+
|
|
50
|
+
## Input Resolution
|
|
51
|
+
|
|
52
|
+
The `-i` flag accepts three kinds of input, resolved automatically:
|
|
53
|
+
|
|
54
|
+
| Input | What happens | Selection mode |
|
|
55
|
+
|-------|-------------|----------------|
|
|
56
|
+
| Path to `ast-trees.txt` file | Uses that file directly | `direct-file` |
|
|
57
|
+
| Path to a scan directory (e.g., `.octocode/scan/2026-03-19T00-01-19-468Z`) | Looks for `ast-trees.txt` inside it | `scan-dir` |
|
|
58
|
+
| Path to scan root (e.g., `.octocode/scan`) | Finds the latest timestamped directory with an `ast-trees.txt` | `latest-scan` |
|
|
59
|
+
|
|
60
|
+
Default when `-i` is omitted: `.octocode/scan` (resolves to latest scan automatically).
|
|
61
|
+
|
|
62
|
+
## Recommended Flow
|
|
63
|
+
|
|
64
|
+
1. Start from `<CURRENT_SCAN>/ast-trees.txt` or just pass `-i .octocode/scan` for the latest.
|
|
65
|
+
2. Run a bounded query with `--limit 25` or smaller.
|
|
66
|
+
3. Narrow with `--file` or `--section` once you know the suspicious area.
|
|
67
|
+
4. Switch to `ast/search.js` when you need source-level structural matching.
|
|
68
|
+
5. Validate final claims with Octocode local and LSP tools.
|
|
69
|
+
|
|
70
|
+
## Examples
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
# Find all function declarations (latest scan)
|
|
74
|
+
node <SKILL_DIR>/scripts/ast/tree-search.js -i .octocode/scan -k function_declaration --limit 25
|
|
75
|
+
|
|
76
|
+
# Find classes in a specific file
|
|
77
|
+
node <SKILL_DIR>/scripts/ast/tree-search.js -i <CURRENT_SCAN>/ast-trees.txt --file 'src/report' -k class_declaration --limit 10
|
|
78
|
+
|
|
79
|
+
# Find control flow nodes
|
|
80
|
+
node <SKILL_DIR>/scripts/ast/tree-search.js -i <CURRENT_SCAN>/ast-trees.txt -p 'IfStatement|SwitchStatement|ForStatement|WhileStatement' --limit 25
|
|
81
|
+
|
|
82
|
+
# JSON output for programmatic use
|
|
83
|
+
node <SKILL_DIR>/scripts/ast/tree-search.js -i <CURRENT_SCAN>/ast-trees.txt --section 'src/services' -k function_declaration --json
|
|
84
|
+
|
|
85
|
+
# With context lines to see surrounding tree structure
|
|
86
|
+
node <SKILL_DIR>/scripts/ast/tree-search.js -i .octocode/scan -k function_declaration -C 2 --limit 10
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Output
|
|
90
|
+
|
|
91
|
+
### Text (default)
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
AST tree search: kind=function_declaration
|
|
95
|
+
Requested input: /path/to/.octocode/scan
|
|
96
|
+
Selected AST file: /path/to/.octocode/scan/2026-03-19T00-01-19-468Z/ast-trees.txt (latest-scan)
|
|
97
|
+
Matches: 42 total, showing 10 (limit 10)
|
|
98
|
+
Matched files: 5
|
|
99
|
+
|
|
100
|
+
-- my-package — src/services/storage.ts --
|
|
101
|
+
L14 (src/services/storage.ts) FunctionDeclaration[10:45]
|
|
102
|
+
L68 (src/services/storage.ts) FunctionDeclaration[50:80]
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Text with `--context 2`
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
-- my-package — src/services/storage.ts --
|
|
109
|
+
12 | ImportDeclaration[1:3]
|
|
110
|
+
13 | ExportDeclaration[5:8]
|
|
111
|
+
> 14 | FunctionDeclaration[10:45]
|
|
112
|
+
15 | ExportKeyword[10]
|
|
113
|
+
16 | Identifier[10]
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### JSON (`--json`)
|
|
117
|
+
|
|
118
|
+
```json
|
|
119
|
+
{
|
|
120
|
+
"requestedInput": "/path/to/.octocode/scan",
|
|
121
|
+
"inputFile": "/path/to/.octocode/scan/2026-03-19T.../ast-trees.txt",
|
|
122
|
+
"selectionMode": "latest-scan",
|
|
123
|
+
"query": "kind=function_declaration",
|
|
124
|
+
"limit": 25,
|
|
125
|
+
"totalMatches": 42,
|
|
126
|
+
"returnedMatches": 25,
|
|
127
|
+
"truncated": true,
|
|
128
|
+
"uniqueFiles": 5,
|
|
129
|
+
"matches": [{
|
|
130
|
+
"section": "my-package — src/services/storage.ts",
|
|
131
|
+
"file": "src/services/storage.ts",
|
|
132
|
+
"lineNumber": 14,
|
|
133
|
+
"line": " FunctionDeclaration[10:45]",
|
|
134
|
+
"context": [{ "lineNumber": 14, "line": " FunctionDeclaration[10:45]" }]
|
|
135
|
+
}]
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Use `totalMatches` vs `returnedMatches` to know if results are truncated. Use `selectionMode` to confirm which scan was selected.
|
|
140
|
+
|
|
141
|
+
## Difference from `ast/search.js`
|
|
142
|
+
|
|
143
|
+
| | `ast/tree-search.js` | `ast/search.js` |
|
|
144
|
+
|---|---|---|
|
|
145
|
+
| **Searches** | Generated `ast-trees.txt` artifact | Actual source files on disk |
|
|
146
|
+
| **Powered by** | Regex / kind matching on text | `@ast-grep/napi` structural matching |
|
|
147
|
+
| **Input** | `-i <scan-path>` | `--root <source-dir>` |
|
|
148
|
+
| **Best for** | Quick triage — find where to look | Proof — confirm a code pattern exists |
|
|
149
|
+
| **Proves behavior** | No — artifact only | Partial — structural shape, not runtime |
|
|
150
|
+
|
|
151
|
+
Use `ast/tree-search.js` to decide where to look. Use `ast/search.js` to prove a source-level structural pattern exists.
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# CLI Reference
|
|
2
|
+
|
|
3
|
+
```bash
|
|
4
|
+
node <SKILL_DIR>/scripts/index.js [flags]
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
Output goes to `.octocode/scan/<timestamp>/` by default. Results are cached — subsequent runs skip unchanged files (~4x faster).
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## CLI Presets
|
|
12
|
+
|
|
13
|
+
| Situation | Flags |
|
|
14
|
+
|---|---|
|
|
15
|
+
| Default scan | _(none)_ |
|
|
16
|
+
| Analyze different repo | `--root /path/to/other/repo` |
|
|
17
|
+
| Legacy single-file output | `--out path/to/report.json` |
|
|
18
|
+
| Scope to one package | `--scope=packages/my-package` |
|
|
19
|
+
| Scope to a directory | `--scope=packages/my-package/src/tools` |
|
|
20
|
+
| Scope to a single file | `--scope=packages/my-package/src/session.ts` |
|
|
21
|
+
| Scope to a function | `--scope=packages/my-package/src/session.ts:initSession` |
|
|
22
|
+
| Scope to multiple areas | `--scope=packages/foo/src/tools,packages/bar/src/ui` |
|
|
23
|
+
| Architecture only | `--features=architecture` |
|
|
24
|
+
| Code quality only | `--features=code-quality` |
|
|
25
|
+
| Dead code only | `--features=dead-code` |
|
|
26
|
+
| Security only | `--features=security` |
|
|
27
|
+
| Test quality only | `--features=test-quality --include-tests` |
|
|
28
|
+
| Single category | `--features=cognitive-complexity` |
|
|
29
|
+
| Mix pillars + categories | `--features=dead-code,dependency-cycle` |
|
|
30
|
+
| Everything except X | `--exclude=architecture` |
|
|
31
|
+
| Exclude specific categories | `--exclude=dead-export,magic-number` |
|
|
32
|
+
| Cap findings (diverse) | `--findings-limit 500` |
|
|
33
|
+
| Cap findings (pure severity) | `--findings-limit 500 --no-diversify` |
|
|
34
|
+
| Include tests | `--include-tests` |
|
|
35
|
+
| Architecture graph | `--graph` |
|
|
36
|
+
| Advanced graph overlays | `--graph --graph-advanced` |
|
|
37
|
+
| Flow enrichment | `--flow` |
|
|
38
|
+
| Suppress AST tree output | `--no-tree` |
|
|
39
|
+
| Strict complexity | `--critical-complexity-threshold 20 --cognitive-complexity-threshold 10` |
|
|
40
|
+
| Strict type safety | `--any-threshold 0` |
|
|
41
|
+
| Strict maintainability | `--maintainability-index-threshold 30 --halstead-effort-threshold 200000` |
|
|
42
|
+
| Layer enforcement | `--layer-order ui,service,repository` |
|
|
43
|
+
| Sensitive flow dups | `--flow-dup-threshold 2 --min-flow-statements 4` |
|
|
44
|
+
| Diverse top recs | `--max-recs-per-category 1` |
|
|
45
|
+
| Enable semantic analysis | `--semantic` |
|
|
46
|
+
| Semantic + scope combo | `--semantic --scope=packages/my-package` |
|
|
47
|
+
| Only semantic categories | `--semantic --features=unused-parameter,shotgun-surgery` |
|
|
48
|
+
| Deep hierarchy threshold | `--semantic --type-hierarchy-threshold 6` |
|
|
49
|
+
| Detect near-clones | `--similarity-threshold 0.8` |
|
|
50
|
+
| Strict security | `--secret-entropy-threshold 4.0 --secret-min-length 16` |
|
|
51
|
+
| Strict test quality | `--mock-threshold 5 --include-tests --features=test-quality` |
|
|
52
|
+
| Force full re-parse | `--no-cache` |
|
|
53
|
+
| Clear cache | `--clear-cache` |
|
|
54
|
+
| JSON to stdout | `--json` |
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Flag Details
|
|
59
|
+
|
|
60
|
+
`--scope` focuses on specific paths (comma-separated, relative to root). Use `file:symbol` syntax to drill into a specific function or exported variable — only findings whose line range overlaps with that symbol are returned. The full dependency graph is still built so architecture findings involving scoped files are reported. Combinable with `--features`/`--exclude`.
|
|
61
|
+
|
|
62
|
+
`--features` and `--exclude` are mutually exclusive. Both accept pillar names (`architecture`, `code-quality`, `dead-code`, `security`, `test-quality`) and individual category names, comma-separated.
|
|
63
|
+
|
|
64
|
+
`--semantic` enables TypeChecker + LanguageService analysis (additional categories). Off by default since it adds ~3-5s. Semantic categories require `--semantic` to appear in results.
|
|
65
|
+
|
|
66
|
+
`--out` changes the output destination. If the path ends with `.json`, writes a single monolithic file (legacy mode). Otherwise, writes to the given directory instead of the default timestamped directory.
|
|
67
|
+
|
|
68
|
+
`--parser` selects the parse engine: `auto` (default — uses tree-sitter with TS fallback), `typescript` (TS compiler only), or `tree-sitter` (tree-sitter only).
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## All Flags Reference
|
|
73
|
+
|
|
74
|
+
### Core
|
|
75
|
+
|
|
76
|
+
| Flag | Default | Description |
|
|
77
|
+
|------|---------|-------------|
|
|
78
|
+
| `--root <path>` | cwd | Analyze a different repo root |
|
|
79
|
+
| `--out <path>` | `.octocode/scan/<ts>/` | Output path. Ends in `.json` → single-file legacy mode |
|
|
80
|
+
| `--json` | off | Print report JSON to stdout |
|
|
81
|
+
| `--include-tests` | off | Include `*.test.*` and `*.spec.*` files |
|
|
82
|
+
| `--scope=X,Y,Z` | _(all files)_ | Limit to specific paths/files/functions (comma-separated) |
|
|
83
|
+
| `--features=X,Y,Z` | _(all)_ | Run only selected pillars/categories |
|
|
84
|
+
| `--exclude=X,Y,Z` | _(none)_ | Exclude specific pillars/categories (mutually exclusive with `--features`) |
|
|
85
|
+
| `--findings-limit N` | no limit | Cap total findings in report |
|
|
86
|
+
| `--graph` | off | Emit Mermaid dependency graph (`graph.md`) |
|
|
87
|
+
| `--graph-advanced` | off | Enable SCC clusters, chokepoints, package graph hotspots, and advanced architecture findings |
|
|
88
|
+
| `--flow` | off | Enable lightweight flow enrichment such as `cfgFlags`, `flowTrace`, and richer evidence metadata |
|
|
89
|
+
| `--emit-tree` | **on** | Force include AST tree blocks in output |
|
|
90
|
+
| `--no-tree` | — | Suppress AST tree output (`ast-trees.txt`) |
|
|
91
|
+
| `--parser <engine>` | `auto` | Parse engine: `auto`, `typescript`, `tree-sitter` |
|
|
92
|
+
| `--semantic` | off | Enable semantic analysis (TypeChecker + LanguageService) |
|
|
93
|
+
| `--no-diversify` | off | Disable category-aware diversification when truncating. By default `--findings-limit` interleaves categories so the capped list is diverse. Use this for pure severity ordering. |
|
|
94
|
+
| `--no-cache` | off | Disable incremental cache; re-parse all files |
|
|
95
|
+
| `--clear-cache` | — | Delete the analysis cache and exit (no scan) |
|
|
96
|
+
| `--all` | off | Enable all features: `--include-tests --semantic` |
|
|
97
|
+
| `--help`, `-h` | — | Show help message |
|
|
98
|
+
|
|
99
|
+
### Thresholds — Architecture
|
|
100
|
+
|
|
101
|
+
| Flag | Default | Controls |
|
|
102
|
+
|------|---------|----------|
|
|
103
|
+
| `--coupling-threshold N` | 15 | Ca+Ce threshold for `high-coupling` |
|
|
104
|
+
| `--fan-in-threshold N` | 20 | Fan-in threshold for `god-module-coupling` |
|
|
105
|
+
| `--fan-out-threshold N` | 15 | Fan-out threshold for `god-module-coupling` |
|
|
106
|
+
| `--layer-order <layers>` | _(none)_ | Comma-separated layer names for violation detection |
|
|
107
|
+
| `--deep-link-topn N` | 12 | Max critical dependency paths to report |
|
|
108
|
+
|
|
109
|
+
### Thresholds — Code Quality
|
|
110
|
+
|
|
111
|
+
| Flag | Default | Controls |
|
|
112
|
+
|------|---------|----------|
|
|
113
|
+
| `--critical-complexity-threshold N` | 30 | Complexity for HIGH findings + critical path weighting |
|
|
114
|
+
| `--cognitive-complexity-threshold N` | 15 | Cognitive complexity threshold |
|
|
115
|
+
| `--cyclomatic-density-threshold N` | 0.5 | CC/LOC ratio threshold |
|
|
116
|
+
| `--halstead-effort-threshold N` | 500000 | Halstead effort threshold |
|
|
117
|
+
| `--maintainability-index-threshold N` | 20 | MI below this triggers a finding (0-100 scale) |
|
|
118
|
+
| `--parameter-threshold N` | 5 | Max function parameters before flagging |
|
|
119
|
+
| `--any-threshold N` | 5 | Max `any` type usages per file |
|
|
120
|
+
| `--magic-number-threshold N` | 3 | Max magic number occurrences per file |
|
|
121
|
+
| `--god-module-statements N` | 500 | Statement threshold for `god-module` |
|
|
122
|
+
| `--god-module-exports N` | 20 | Export threshold for `god-module` |
|
|
123
|
+
| `--god-function-statements N` | 100 | Statement threshold for `god-function` |
|
|
124
|
+
| `--min-function-statements N` | 6 | Min function body statements for duplicate matching |
|
|
125
|
+
| `--min-flow-statements N` | 6 | Min control-flow statements for duplicate matching |
|
|
126
|
+
| `--flow-dup-threshold N` | 3 | Min occurrences for a repeated flow to become a finding |
|
|
127
|
+
| `--similarity-threshold N` | 0.85 | Jaccard similarity threshold for near-clone detection |
|
|
128
|
+
| `--max-recs-per-category N` | 2 | Max findings per category in top recommendations |
|
|
129
|
+
|
|
130
|
+
### Thresholds — Semantic (require `--semantic`)
|
|
131
|
+
|
|
132
|
+
| Flag | Default | Controls |
|
|
133
|
+
|------|---------|----------|
|
|
134
|
+
| `--type-hierarchy-threshold N` | 4 | Max inheritance depth before flagging |
|
|
135
|
+
| `--override-chain-threshold N` | 3 | Max method override depth before flagging |
|
|
136
|
+
|
|
137
|
+
### Thresholds — Security
|
|
138
|
+
|
|
139
|
+
| Flag | Default | Controls |
|
|
140
|
+
|------|---------|----------|
|
|
141
|
+
| `--secret-entropy-threshold N` | 4.5 | Shannon entropy threshold for high-entropy string detection |
|
|
142
|
+
| `--secret-min-length N` | 20 | Min string length for entropy-based secret detection |
|
|
143
|
+
|
|
144
|
+
### Thresholds — Test Quality
|
|
145
|
+
|
|
146
|
+
| Flag | Default | Controls |
|
|
147
|
+
|------|---------|----------|
|
|
148
|
+
| `--mock-threshold N` | 10 | Max mock/spy calls per test file before flagging |
|
|
149
|
+
|
|
150
|
+
### Output Tuning
|
|
151
|
+
|
|
152
|
+
| Flag | Default | Controls |
|
|
153
|
+
|------|---------|----------|
|
|
154
|
+
| `--tree-depth N` | 4 | AST tree depth when tree snapshots are emitted |
|
|
155
|
+
| `--barrel-symbol-threshold N` | 30 | Re-export count threshold for `barrel-explosion` |
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## Drill-Down Workflow
|
|
160
|
+
|
|
161
|
+
```
|
|
162
|
+
1. Full scan → identify hotspots from summary.md
|
|
163
|
+
2. --scope=critical/area → deep-dive into the worst package/directory
|
|
164
|
+
3. --scope=file.ts → investigate a single file's findings
|
|
165
|
+
4. --scope=file.ts:functionName → drill into a specific function or variable
|
|
166
|
+
5. Fix → re-scan with scope → verify finding count drops
|
|
167
|
+
```
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# Concepts — Metric Definitions
|
|
2
|
+
|
|
3
|
+
## Instability (SDP)
|
|
4
|
+
|
|
5
|
+
**Formula**: `I = Ce / (Ca + Ce)` where Ca = inbound (afferent) coupling, Ce = outbound (efferent) coupling.
|
|
6
|
+
|
|
7
|
+
**Range**: 0 (maximally stable) to 1 (maximally unstable).
|
|
8
|
+
|
|
9
|
+
**Threshold**: An SDP violation fires when a stable module (I < 0.5) depends on a more unstable module with delta > 0.15. Delta > 0.3 = high severity.
|
|
10
|
+
|
|
11
|
+
**Interpretation**: I=0 means everything depends on this module and it depends on nothing — changing it breaks many consumers. I=1 means it depends on many modules but nothing depends on it — safe to change. Violations mean a hard-to-change module depends on an easy-to-change one, creating fragility.
|
|
12
|
+
|
|
13
|
+
**Example**: Module A (I=0.2, 8 importers, 2 imports) depends on module B (I=0.8, 1 importer, 4 imports). Delta=0.6. Fix: extract an interface in A that B implements.
|
|
14
|
+
|
|
15
|
+
## Cognitive Complexity
|
|
16
|
+
|
|
17
|
+
**Formula**: Each `if`/`for`/`while`/`switch`/`catch`/`&&`/`||` adds +1. Each nesting level adds +1 more per construct inside it.
|
|
18
|
+
|
|
19
|
+
**Default threshold**: 15. Above 15 = flagged.
|
|
20
|
+
|
|
21
|
+
**Interpretation**: Unlike cyclomatic complexity, cognitive complexity penalizes deeply nested code much more heavily. A flat chain of 10 `if` statements scores 10, but 5 nested `if` blocks score 5+4+3+2+1=15.
|
|
22
|
+
|
|
23
|
+
**Example**: A function with cognitive complexity 42 has deeply nested branches. Target: refactor to <15 by extracting guard clauses, breaking into helper functions, or using early returns.
|
|
24
|
+
|
|
25
|
+
## Halstead Metrics
|
|
26
|
+
|
|
27
|
+
**Formula**: Volume = Length × log₂(Vocabulary). Effort = Volume × Difficulty. Difficulty = (distinctOperators/2) × (totalOperands/distinctOperands).
|
|
28
|
+
|
|
29
|
+
**Default threshold**: Effort > 500,000 triggers a finding.
|
|
30
|
+
|
|
31
|
+
**Interpretation**: Effort estimates the mental effort to understand or recreate the code. Volume measures information content. EstimatedBugs = Volume / 3000 gives a rough bug prediction.
|
|
32
|
+
|
|
33
|
+
**Example**: A 200-line function with effort 1,200,000 is ~2.4× the threshold — it likely needs decomposition into 3-4 smaller functions each under 500K effort.
|
|
34
|
+
|
|
35
|
+
## Maintainability Index
|
|
36
|
+
|
|
37
|
+
**Formula**: `MI = 171 - 5.2×ln(Volume) - 0.23×CC - 16.2×ln(LOC)`, rescaled to 0-100.
|
|
38
|
+
|
|
39
|
+
**Default threshold**: MI < 20 triggers a finding.
|
|
40
|
+
|
|
41
|
+
**Interpretation**: >65 = highly maintainable. 40-65 = moderate. 20-40 = difficult. <20 = very difficult to maintain. The index combines volume, complexity, and size into one number.
|
|
42
|
+
|
|
43
|
+
**Example**: MI=12 on a 300-line function means it's in the danger zone. Splitting it into 4 focused helpers of ~75 lines each would likely push each above MI=40.
|
|
44
|
+
|
|
45
|
+
## Abstractness (A)
|
|
46
|
+
|
|
47
|
+
**Formula**: `A = abstractExports / totalExports` — share of exports that are types/interfaces.
|
|
48
|
+
|
|
49
|
+
**Range**: 0 (fully concrete) to 1 (fully abstract).
|
|
50
|
+
|
|
51
|
+
**Interpretation**: Combined with Instability to compute Distance from Main Sequence.
|
|
52
|
+
|
|
53
|
+
**Example**: A module with 10 exports, 3 of which are types → A = 0.3.
|
|
54
|
+
|
|
55
|
+
## Distance from Main Sequence (D)
|
|
56
|
+
|
|
57
|
+
**Formula**: `D = |A + I - 1|` where A = Abstractness, I = Instability.
|
|
58
|
+
|
|
59
|
+
**Default thresholds**: D > 0.7 (and module has minimum coupling) triggers a finding. Severity high if D > 0.8.
|
|
60
|
+
|
|
61
|
+
**Interpretation**: D = 0 means the module sits on the "main sequence" (balanced abstraction vs. stability). High D means the module is either in the **Zone of Pain** (concrete + stable = hard to change) or **Zone of Uselessness** (abstract + unstable = unused abstractions).
|
|
62
|
+
|
|
63
|
+
**Example**: Module with I=0.1, A=0.1 → D = |0.1 + 0.1 - 1| = 0.8 (Zone of Pain). Fix: add abstractions or reduce inbound coupling.
|
|
64
|
+
|
|
65
|
+
## Hot-File Risk Score
|
|
66
|
+
|
|
67
|
+
**Formula**: `risk = fanIn * 3 + complexity + fanOut + (onCriticalPath ? 100 : 0) + (inCycle ? 50 : 0)`
|
|
68
|
+
|
|
69
|
+
**Interpretation**: Ranks files by danger-to-change. High fan-in means many consumers break. High complexity means the file itself is fragile. Critical path and cycle membership amplify risk.
|
|
70
|
+
|
|
71
|
+
**Example**: `types/index.ts` with fanIn=54, complexity=1 → risk = 54*3 + 1 + 2 + 100 = 265. The highest risk files are the most important to keep stable and well-tested.
|
|
72
|
+
|
|
73
|
+
## Low Cohesion (LCOM)
|
|
74
|
+
|
|
75
|
+
**Method**: For each file, compare the set of imports used by each export. If exports share few common dependencies, the file has low cohesion — its exports serve unrelated purposes.
|
|
76
|
+
|
|
77
|
+
**Default thresholds**: minExports ≥ 3, internal dependencies from 3+ distinct groups.
|
|
78
|
+
|
|
79
|
+
**Interpretation**: A file with low cohesion is doing multiple jobs and should be split. LCOM > 1 suggests the module boundary is wrong.
|
|
80
|
+
|
|
81
|
+
**Example**: `utils.ts` exports `parseDate()`, `formatCurrency()`, and `validateEmail()` — each uses different imports and serves a different domain. Split into `date-utils.ts`, `currency-utils.ts`, `validation-utils.ts`.
|
|
82
|
+
|
|
83
|
+
## Cyclomatic Density
|
|
84
|
+
|
|
85
|
+
**Formula**: `CC / LOC` (cyclomatic complexity divided by lines of code).
|
|
86
|
+
|
|
87
|
+
**Note**: Not used as a standalone finding category. Cyclomatic complexity is folded into the `function-optimization` detector and the Maintainability Index calculation.
|
|
88
|
+
|
|
89
|
+
**Interpretation**: Density > 0.5 means on average every other line is a branch point. The code is almost entirely control flow with minimal straight-line logic.
|
|
90
|
+
|
|
91
|
+
**Example**: A function with CC=30 and LOC=45 has density 0.67 — nearly pure branching logic. Consider extracting branch groups into named helpers or using lookup tables.
|
|
92
|
+
|
|
93
|
+
## Reachability
|
|
94
|
+
|
|
95
|
+
**Method**: BFS from entrypoints (`index`, `main`, `app`, `server`, `cli`, `public`, `*.config.*`). Files not reached are flagged as `unreachable-module`.
|
|
96
|
+
|
|
97
|
+
**Interpretation**: Stricter than orphan-module detection (which only checks for zero inbound imports). A file may have importers but still be unreachable from any entrypoint if its entire import subtree is disconnected.
|
|
98
|
+
|
|
99
|
+
**Example**: `utils/legacy-helper.ts` has 2 importers, but both importers are also unreachable from any entrypoint — the entire cluster is dead code.
|
|
100
|
+
|
|
101
|
+
## Package Boundaries
|
|
102
|
+
|
|
103
|
+
**Rule**: `packages/A/` should import from `packages/B/src/index.ts` (public API), never `packages/B/src/internal/bar.ts`.
|
|
104
|
+
|
|
105
|
+
**Interpretation**: Crossing into another package's internal modules creates tight coupling that bypasses the package's public contract. Changes to internals can break consumers silently.
|
|
106
|
+
|
|
107
|
+
**Example**: `packages/cli/src/run.ts` imports `packages/core/src/internal/parser.ts` instead of using the public `packages/core/src/index.ts` re-export. Fix: add the needed symbol to core's public API or restructure the dependency.
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# Finding Categories
|
|
2
|
+
|
|
3
|
+
All categories detected by the scan, grouped by pillar. Categories marked `--semantic` require the `--semantic` flag.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Architecture Risk
|
|
8
|
+
|
|
9
|
+
| Category | Severity | Detects | Requires |
|
|
10
|
+
|----------|----------|---------|----------|
|
|
11
|
+
| `dependency-cycle` | high | Circular import chains | — |
|
|
12
|
+
| `dependency-critical-path` | high — critical | High-weight transitive dependency chains | — |
|
|
13
|
+
| `dependency-test-only` | medium | Production modules imported only from tests | — |
|
|
14
|
+
| `architecture-sdp-violation` | medium — high | Stable module depends on unstable module (I = Ce/(Ca+Ce)) | — |
|
|
15
|
+
| `high-coupling` | medium — high | Excessive Ca + Ce connections | — |
|
|
16
|
+
| `god-module-coupling` | medium — high | High fan-in (bottleneck) or fan-out (sprawl) | — |
|
|
17
|
+
| `mega-folder` | medium | Directory with excessive file count | — |
|
|
18
|
+
| `orphan-module` | medium | Zero inbound AND zero outbound dependencies | — |
|
|
19
|
+
| `unreachable-module` | high | Not reachable from any entrypoint via BFS | — |
|
|
20
|
+
| `layer-violation` | high | Import backwards in configured layer order | — |
|
|
21
|
+
| `low-cohesion` | medium — high | Exports serve unrelated purposes (LCOM > 1) | — |
|
|
22
|
+
| `distance-from-main-sequence` | medium — high | Module far from A + I = 1 (Zone of Pain / Uselessness) | — |
|
|
23
|
+
| `feature-envy` | medium — high | Module imports 60%+ symbols from single external module | — |
|
|
24
|
+
| `untested-critical-code` | high — critical | Hot/critical-path file with zero test imports | — |
|
|
25
|
+
| `cycle-cluster` | medium — high | Strongly connected file cluster large enough to behave like one tangled subsystem | — |
|
|
26
|
+
| `broker-module` | medium — high | Module concentrates graph pressure across fan-in, fan-out, articulation, or critical-path signals | — |
|
|
27
|
+
| `bridge-module` | medium — high | Structural articulation point or bridge between subsystems | — |
|
|
28
|
+
| `package-boundary-chatter` | medium — high | Excessive cross-package dependency edges between two package groups | — |
|
|
29
|
+
| `startup-risk-hub` | medium — high | Import-time side effects on a high fan-in structural hub | — |
|
|
30
|
+
| `over-abstraction` | medium | Interface/abstract class with exactly 1 implementor | `--semantic` |
|
|
31
|
+
| `concrete-dependency` | medium | Import resolves to concrete class (DIP violation) | `--semantic` |
|
|
32
|
+
| `circular-type-dependency` | high | Type A references Type B, B references A (type-level cycle) | `--semantic` |
|
|
33
|
+
| `shotgun-surgery` | medium — high | Export referenced from 8+ unique files (change amplification risk) | `--semantic` |
|
|
34
|
+
| `import-side-effect-risk` | low — critical | Module executes risky work at import time (sync I/O, exec, eval, timers, listeners); scored by AST evidence + architecture context (fan-in, critical path, cycle, entry role) | — |
|
|
35
|
+
| `namespace-import` | medium | Namespace import (`import * as X`) pulling in entire module surface | — |
|
|
36
|
+
| `commonjs-in-esm` | medium | CommonJS `require()` in an ESM-style codebase | — |
|
|
37
|
+
| `export-star-leak` | medium — high | `export * from` re-exports leaking internal symbols | — |
|
|
38
|
+
| `mixed-module-format` | medium | File mixes CommonJS and ESM syntax | — |
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## Code Quality
|
|
43
|
+
|
|
44
|
+
| Category | Severity | Detects | Requires |
|
|
45
|
+
|----------|----------|---------|----------|
|
|
46
|
+
| `duplicate-function-body` | low — high | Identical function implementations across files | — |
|
|
47
|
+
| `duplicate-flow-structure` | medium — high | Repeated control-flow patterns | — |
|
|
48
|
+
| `similar-function-body` | medium — high | Near-clone functions (Type-2: renamed vars, different literals) | — |
|
|
49
|
+
| `function-optimization` | medium — high | High complexity, deep nesting, oversized functions | — |
|
|
50
|
+
| `cognitive-complexity` | medium — high | Nesting-aware complexity score | — |
|
|
51
|
+
| `god-module` | high | Files with excessive statements or exports | — |
|
|
52
|
+
| `god-function` | high | Functions with excessive statements | — |
|
|
53
|
+
| `halstead-effort` | medium — high | Halstead effort > threshold or estimated bugs > 2.0 | — |
|
|
54
|
+
| `low-maintainability` | high — critical | Maintainability Index below threshold | — |
|
|
55
|
+
| `excessive-parameters` | medium — high | Function exceeds parameter threshold | — |
|
|
56
|
+
| `unsafe-any` | medium — high | Excessive `any` types | — |
|
|
57
|
+
| `empty-catch` | medium | Empty catch block | — |
|
|
58
|
+
| `switch-no-default` | low | Switch missing default case | — |
|
|
59
|
+
| `type-assertion-escape` | medium — high | `as any`, `as unknown as T`, non-null `!` assertions | — |
|
|
60
|
+
| `missing-error-boundary` | low — high | Async function with await(s) but no try-catch or `.catch()` handler; severity tiers: 1 await = low, 2-3 = medium, 4+ = high | — |
|
|
61
|
+
| `promise-misuse` | medium | `async` function that never uses `await` | — |
|
|
62
|
+
| `await-in-loop` | high | await inside loop body — sequential async (N+1 latency) | — |
|
|
63
|
+
| `sync-io` | medium | Synchronous I/O calls (readFileSync, execSync, etc.) | — |
|
|
64
|
+
| `uncleared-timer` | medium | setInterval without clearInterval in scope | — |
|
|
65
|
+
| `listener-leak-risk` | medium | Event listeners added without corresponding removal | — |
|
|
66
|
+
| `unbounded-collection` | low | Collection growth inside nested loops without size guard | — |
|
|
67
|
+
| `unused-parameter` | medium | Function parameter never referenced in body (semantic) | `--semantic` |
|
|
68
|
+
| `deep-override-chain` | medium — high | Method overridden beyond depth threshold in class hierarchy | `--semantic` |
|
|
69
|
+
| `interface-compliance` | medium — high | Class `implements I` with missing or any-cast members | `--semantic` |
|
|
70
|
+
| `narrowable-type` | low | Parameter declared broad but all callers pass narrow type | `--semantic` |
|
|
71
|
+
| `message-chain` | medium — high | Property-access chains of depth ≥ 4 (`a.b.c.d`) violating the Law of Demeter. Medium at depth 4–5; high at depth ≥ 6. Deep chains tightly couple the caller to intermediate object structure | — |
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## Dead Code & Hygiene
|
|
76
|
+
|
|
77
|
+
| Category | Severity | Detects | Requires |
|
|
78
|
+
|----------|----------|---------|----------|
|
|
79
|
+
| `dead-export` | medium — high | Exported symbol with no usage (import matching) | — |
|
|
80
|
+
| `dead-re-export` | medium | Barrel re-export with no consumers | — |
|
|
81
|
+
| `re-export-duplication` | medium | Same symbol re-exported from multiple paths | — |
|
|
82
|
+
| `re-export-shadowed` | high | Local export and re-export name collision | — |
|
|
83
|
+
| `unused-npm-dependency` | low — medium | package.json dep not imported anywhere | — |
|
|
84
|
+
| `package-boundary-violation` | medium — high | Cross-package import bypassing public API | — |
|
|
85
|
+
| `barrel-explosion` | medium — high | Barrel with excessive re-exports or chain depth | — |
|
|
86
|
+
| `redundant-re-export` | low — medium | *(planned)* Barrel re-export with 0 consumers through the barrel path; includes `export *` where <50% of symbols are consumed | — |
|
|
87
|
+
| `redundant-comment` | low | *(planned)* Comment that restates what the code already says (narrating patterns: `// Import`, `// Define`, `// Return`, `// Set`, `// Get`, `// Handle`, `// Create`, etc.) | — |
|
|
88
|
+
| `unused-import` | low | Imported symbol never semantically used (TypeChecker confirmed) | `--semantic` |
|
|
89
|
+
| `orphan-implementation` | medium | Exported class with no external references and no interface | `--semantic` |
|
|
90
|
+
| `move-to-caller` | low | Exported symbol consumed by exactly 1 file (candidate for inlining) | `--semantic` |
|
|
91
|
+
| `semantic-dead-export` | high | Exported symbol with zero semantic references (TypeChecker confirmed, stricter than `dead-export`) | `--semantic` |
|
|
92
|
+
| `dead-file` | medium | File with no inbound or outbound dependencies — likely stale | — |
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## Security
|
|
97
|
+
|
|
98
|
+
| Category | Severity | Detects | Requires |
|
|
99
|
+
|----------|----------|---------|----------|
|
|
100
|
+
| `hardcoded-secret` | high | String literals matching secret patterns (password, API key, token) or high-entropy strings | — |
|
|
101
|
+
| `eval-usage` | critical | `eval()`, `new Function()`, string-based `setTimeout`/`setInterval` | — |
|
|
102
|
+
| `unsafe-html` | high | `innerHTML`, `outerHTML`, `dangerouslySetInnerHTML`, `document.write` | — |
|
|
103
|
+
| `sql-injection-risk` | high | Template literal with SQL keywords and interpolated expressions | — |
|
|
104
|
+
| `unsafe-regex` | medium | Regex with nested quantifiers (catastrophic backtracking / ReDoS) | — |
|
|
105
|
+
| `prototype-pollution-risk` | medium — high | `Object.assign()` without `__proto__` guard, deep merge/extend utilities, computed-property bracket writes (`obj[key] = val`) | — |
|
|
106
|
+
| `unvalidated-input-sink` | high | Function receives external input (param name heuristic) and uses a dangerous sink (eval, innerHTML, SQL, exec, fs write) without validation evidence | — |
|
|
107
|
+
| `input-passthrough-risk` | low — medium | Function receives external input and passes it to other functions without validation; severity by param confidence (high-confidence params like `req`, `body` = medium; medium-confidence like `input`, `event` = low; low-confidence like `data`, `args` = filtered out). Trace downstream with `lspCallHierarchy` | — |
|
|
108
|
+
| `path-traversal-risk` | medium — high | Function receives external input that flows into `fs.readFile`, `path.resolve`, or `path.join` without validation (normalize → prefix check → realpath). High severity when no validation; medium when partial validation detected | — |
|
|
109
|
+
| `command-injection-risk` | high — critical | Function receives external input that flows into `exec`/`execSync` (critical) or `spawn` with potential `shell:true` (high). exec with string interpolation enables arbitrary OS command execution | — |
|
|
110
|
+
| `debug-log-leakage` | medium — high | `debugger` statements (high) or `console.debug`/`console.trace` calls (medium) in non-test production files. Information disclosure risk — exposes internal state and execution paths | — |
|
|
111
|
+
| `sensitive-data-logging` | high | `console.*` calls whose argument text matches a sensitive-data pattern: password, token, secret, credential, API key, session, SSN, credit card. Logs write secrets to stdout, log aggregators, and persistent storage | — |
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## Test Quality
|
|
116
|
+
|
|
117
|
+
Requires `--include-tests` (or auto-enabled when `--features=test-quality`).
|
|
118
|
+
|
|
119
|
+
| Category | Severity | Detects | Requires |
|
|
120
|
+
|----------|----------|---------|----------|
|
|
121
|
+
| `low-assertion-density` | medium | Average < 1 assertion per test block | `--include-tests` |
|
|
122
|
+
| `test-no-assertion` | high | `it()`/`test()` block with zero assertions | `--include-tests` |
|
|
123
|
+
| `excessive-mocking` | medium | Mock/spy calls exceeding threshold per test file | `--include-tests` |
|
|
124
|
+
| `shared-mutable-state` | medium | `let`/`var` at describe scope — mutation across tests | `--include-tests` |
|
|
125
|
+
| `missing-test-cleanup` | medium | `beforeAll`/`beforeEach` without corresponding `afterAll`/`afterEach` | `--include-tests` |
|
|
126
|
+
| `focused-test` | medium | `.only`, `.skip`, or `.todo` committed in a test file | `--include-tests` |
|
|
127
|
+
| `fake-timer-no-restore` | medium | Fake timers enabled without restoring real timers | `--include-tests` |
|
|
128
|
+
| `missing-mock-restoration` | medium | Spies/stubs created without restore or restoreAll cleanup | `--include-tests` |
|