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,54 @@
|
|
|
1
|
+
import eslint from '@eslint/js';
|
|
2
|
+
import tseslint from 'typescript-eslint';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
import { dirname } from 'path';
|
|
5
|
+
import importPlugin from 'eslint-plugin-import';
|
|
6
|
+
|
|
7
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
|
|
9
|
+
export default tseslint.config(
|
|
10
|
+
eslint.configs.recommended,
|
|
11
|
+
...tseslint.configs.recommended,
|
|
12
|
+
{
|
|
13
|
+
files: ['src/**/*.ts'],
|
|
14
|
+
plugins: {
|
|
15
|
+
import: importPlugin,
|
|
16
|
+
},
|
|
17
|
+
languageOptions: {
|
|
18
|
+
parserOptions: {
|
|
19
|
+
project: null,
|
|
20
|
+
tsconfigRootDir: __dirname,
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
rules: {
|
|
24
|
+
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
|
|
25
|
+
'@typescript-eslint/no-explicit-any': 'error',
|
|
26
|
+
'import/first': 'error',
|
|
27
|
+
'import/newline-after-import': 'error',
|
|
28
|
+
'import/order': [
|
|
29
|
+
'error',
|
|
30
|
+
{
|
|
31
|
+
groups: ['builtin', 'external', 'internal', ['parent', 'sibling', 'index'], 'type'],
|
|
32
|
+
'newlines-between': 'always',
|
|
33
|
+
alphabetize: {
|
|
34
|
+
order: 'asc',
|
|
35
|
+
caseInsensitive: true,
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
'sort-imports': ['error', { ignoreDeclarationSort: true }],
|
|
40
|
+
'@typescript-eslint/no-use-before-define': [
|
|
41
|
+
'error',
|
|
42
|
+
{
|
|
43
|
+
functions: false,
|
|
44
|
+
classes: true,
|
|
45
|
+
variables: true,
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
'no-empty': 'error',
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
ignores: ['dist/**', 'node_modules/**', 'scripts/**'],
|
|
53
|
+
}
|
|
54
|
+
);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { minify } from 'terser';
|
|
6
|
+
|
|
7
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
const scriptsDir = path.join(__dirname, 'scripts');
|
|
9
|
+
|
|
10
|
+
function collectJsFiles(dir) {
|
|
11
|
+
const results = [];
|
|
12
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
13
|
+
const full = path.join(dir, entry.name);
|
|
14
|
+
if (entry.isDirectory()) {
|
|
15
|
+
results.push(...collectJsFiles(full));
|
|
16
|
+
} else if (entry.isFile() && entry.name.endsWith('.js')) {
|
|
17
|
+
results.push(full);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return results;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const files = collectJsFiles(scriptsDir);
|
|
24
|
+
|
|
25
|
+
for (const filePath of files) {
|
|
26
|
+
let code = fs.readFileSync(filePath, 'utf8');
|
|
27
|
+
const shebang = code.startsWith('#!') ? code.slice(0, code.indexOf('\n') + 1) : '';
|
|
28
|
+
if (shebang) code = code.slice(shebang.length);
|
|
29
|
+
const result = await minify(code, { compress: true, mangle: true, format: { ecma: 2020 } });
|
|
30
|
+
if (result.error) throw result.error;
|
|
31
|
+
fs.writeFileSync(filePath, shebang + (result.code ?? ''), 'utf8');
|
|
32
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "octocode-local-code-quality",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "AST-based code quality analysis with duplicate detection, complexity metrics, and dependency graph intelligence",
|
|
7
|
+
"author": "Guy Bary <bgauryy@octocodeai.com>",
|
|
8
|
+
"homepage": "https://octocode.ai",
|
|
9
|
+
"repository": "bgauryy/octocode-mcp.git",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"keywords": [
|
|
12
|
+
"agent-skill",
|
|
13
|
+
"ast-analysis",
|
|
14
|
+
"code-quality",
|
|
15
|
+
"tree-sitter",
|
|
16
|
+
"dependency-graph",
|
|
17
|
+
"octocode"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc && node minify-scripts.mjs",
|
|
21
|
+
"build:watch": "tsc --watch",
|
|
22
|
+
"test": "vitest run",
|
|
23
|
+
"test:watch": "vitest",
|
|
24
|
+
"lint": "eslint src",
|
|
25
|
+
"lint:fix": "eslint src --fix",
|
|
26
|
+
"analyze": "node scripts/index.js",
|
|
27
|
+
"analyze:json": "node scripts/index.js --json --out .octocode/scan/scan.json",
|
|
28
|
+
"analyze:full": "node scripts/index.js --include-tests --findings-limit 500 --deep-link-topn 30 --out .octocode/scan/scan.json",
|
|
29
|
+
"analyze:graph": "node scripts/index.js --graph --out .octocode/scan/scan.json",
|
|
30
|
+
"search": "node scripts/ast/search.js",
|
|
31
|
+
"search:json": "node scripts/ast/search.js --json",
|
|
32
|
+
"search:presets": "node scripts/ast/search.js --list-presets",
|
|
33
|
+
"search:trees": "node scripts/ast/tree-search.js",
|
|
34
|
+
"search:trees:json": "node scripts/ast/tree-search.js --json"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@ast-grep/napi": "^0.42.0",
|
|
38
|
+
"tree-sitter": "^0.25.0",
|
|
39
|
+
"tree-sitter-typescript": "^0.23.2",
|
|
40
|
+
"typescript": "^5.9.3"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@eslint/js": "^9.27.0",
|
|
44
|
+
"@types/node": "^20.0.0",
|
|
45
|
+
"eslint": "^9.27.0",
|
|
46
|
+
"eslint-plugin-import": "^2.32.0",
|
|
47
|
+
"terser": "^5.46.1",
|
|
48
|
+
"typescript-eslint": "^8.32.0",
|
|
49
|
+
"vitest": "^4.1.0"
|
|
50
|
+
},
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": ">=18.0.0"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# RFC: Agent-Safe AST Artifact Reading
|
|
2
|
+
|
|
3
|
+
> **Status: Implemented.** This RFC documents the design decisions behind `ast/tree-search.js`. For usage, see [ast-tree-search.md](./ast-tree-search.md). This file is architectural context only — not an actionable guide.
|
|
4
|
+
|
|
5
|
+
## Summary
|
|
6
|
+
|
|
7
|
+
This RFC standardizes how agents inspect generated AST artifacts in `octocode-local-code-quality`.
|
|
8
|
+
|
|
9
|
+
The recommendation is to keep a dedicated `ast-tree-search` CLI for `ast-trees.txt`, make the TypeScript source authoritative, generate the runtime JS from that source, and have generated `summary.md` guidance point to the exact scan artifact being discussed.
|
|
10
|
+
|
|
11
|
+
## Motivation
|
|
12
|
+
|
|
13
|
+
The current AST artifact workflow had four failures:
|
|
14
|
+
|
|
15
|
+
1. latest-scan ambiguity: commands that target `.octocode/scan` can silently read a different scan than the `summary.md` the agent is reviewing
|
|
16
|
+
2. conflicting working-directory assumptions: some generated commands only work inside a scan directory while others assume repo-root or skill-root execution
|
|
17
|
+
3. source/runtime drift: AST guidance and runtime behavior diverged because `scripts/` and `src/` were not acting like one source-of-truth pipeline
|
|
18
|
+
4. agent-noisy output: artifact search could dump hundreds of hits with no built-in narrowing, which makes triage harder and increases false conclusions
|
|
19
|
+
|
|
20
|
+
Agents need artifact inspection that is pinned, bounded, and clearly separate from source-level AST search.
|
|
21
|
+
|
|
22
|
+
## Alternatives Considered
|
|
23
|
+
|
|
24
|
+
### 1. Keep `grep` or `rg` only
|
|
25
|
+
|
|
26
|
+
Pros:
|
|
27
|
+
|
|
28
|
+
- zero new code
|
|
29
|
+
- flexible for power users
|
|
30
|
+
|
|
31
|
+
Cons:
|
|
32
|
+
|
|
33
|
+
- easy to run against the wrong artifact
|
|
34
|
+
- no default bounding or structured metadata
|
|
35
|
+
- weak affordances for agents that need predictable output
|
|
36
|
+
|
|
37
|
+
### 2. Teach `ast-search` to ingest generated output files
|
|
38
|
+
|
|
39
|
+
Pros:
|
|
40
|
+
|
|
41
|
+
- one CLI surface
|
|
42
|
+
- reuses an existing command name
|
|
43
|
+
|
|
44
|
+
Cons:
|
|
45
|
+
|
|
46
|
+
- mixes two different problem spaces: generated artifact triage and source-level AST matching
|
|
47
|
+
- increases confusion about what is being validated
|
|
48
|
+
- encourages agents to treat artifact search as if it were source proof
|
|
49
|
+
|
|
50
|
+
### 3. Keep a dedicated AST artifact CLI with TypeScript source-of-truth
|
|
51
|
+
|
|
52
|
+
Pros:
|
|
53
|
+
|
|
54
|
+
- clean separation between artifact navigation and source search
|
|
55
|
+
- output can be optimized for agent triage
|
|
56
|
+
- easy to pin generated guidance to the current scan
|
|
57
|
+
|
|
58
|
+
Cons:
|
|
59
|
+
|
|
60
|
+
- one additional CLI surface to document and test
|
|
61
|
+
- more summary-generation logic
|
|
62
|
+
- build sync must be maintained so `scripts/` does not drift from `src`
|
|
63
|
+
|
|
64
|
+
## Recommendation
|
|
65
|
+
|
|
66
|
+
Adopt alternative 3.
|
|
67
|
+
|
|
68
|
+
- `ast-tree-search` remains a dedicated CLI for generated `ast-trees.txt`
|
|
69
|
+
- `ast-search` remains the source-level structural search tool
|
|
70
|
+
- the TypeScript source under `src/` becomes the implementation source of truth
|
|
71
|
+
- generated `summary.md` points to the exact `ast-trees.txt` file for the current scan
|
|
72
|
+
- artifact search output is bounded and filterable by default
|
|
73
|
+
|
|
74
|
+
## Design Notes
|
|
75
|
+
|
|
76
|
+
- default `--limit` is `50`; `0` means unlimited output
|
|
77
|
+
- `--file` and `--section` support scan-specific narrowing
|
|
78
|
+
- output always includes the selected `ast-trees.txt` file
|
|
79
|
+
- JSON output includes parsed `file` metadata for each match
|
|
80
|
+
- raw `rg` remains documented only as a fallback for indentation/text checks
|
|
81
|
+
|
|
82
|
+
## Drawbacks
|
|
83
|
+
|
|
84
|
+
- more implementation and testing surface
|
|
85
|
+
- generated docs and runtime help must stay aligned
|
|
86
|
+
- users now need to understand when to use artifact search versus source search
|
|
87
|
+
|
|
88
|
+
## Implementation Plan
|
|
89
|
+
|
|
90
|
+
1. Add `src/ast-tree-search.ts` and tests.
|
|
91
|
+
2. Regenerate runtime `scripts/` from TypeScript source.
|
|
92
|
+
3. Update `summary.md` generation to print pinned commands for the current scan.
|
|
93
|
+
4. Add package aliases and reference docs for the new CLI.
|
|
94
|
+
5. Update skill docs so the artifact-search flow is consistent everywhere.
|
|
95
|
+
6. Validate with package tests and a real scoped scan.
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# Architecture Techniques
|
|
2
|
+
|
|
3
|
+
Use this reference when the scan output is directionally useful but not yet strong enough to justify a confident architecture claim.
|
|
4
|
+
|
|
5
|
+
> For how to validate architecture findings with tools, see [validate & investigate](./validate-investigate.md) and the Architecture Playbooks in [playbooks.md](./playbooks.md). For metric definitions (instability, SDP, cyclomatic density), see [concepts.md](./concepts.md).
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Graph Techniques
|
|
10
|
+
|
|
11
|
+
### SCC Condensation
|
|
12
|
+
|
|
13
|
+
Collapse raw file cycles into strongly connected clusters before reasoning about architecture. This is better than treating every cycle edge as a separate problem.
|
|
14
|
+
|
|
15
|
+
Use when:
|
|
16
|
+
|
|
17
|
+
- many `dependency-cycle` findings point at overlapping files
|
|
18
|
+
- the same hotspot appears in multiple cycle paths
|
|
19
|
+
- the graph feels "sticky" but a single edge fix is unclear
|
|
20
|
+
|
|
21
|
+
Interpretation:
|
|
22
|
+
|
|
23
|
+
- a large SCC usually means a subsystem boundary is missing
|
|
24
|
+
- hub files inside an SCC are better refactor starting points than random cycle members
|
|
25
|
+
|
|
26
|
+
### Package / Folder Graph
|
|
27
|
+
|
|
28
|
+
Aggregate file edges into package or folder edges to see subsystem behavior.
|
|
29
|
+
|
|
30
|
+
Use when:
|
|
31
|
+
|
|
32
|
+
- file-level cycles hide the real architectural issue
|
|
33
|
+
- the repo has many cross-package imports
|
|
34
|
+
- the user asks about bounded contexts or team ownership
|
|
35
|
+
|
|
36
|
+
Interpretation:
|
|
37
|
+
|
|
38
|
+
- high cross-package chatter means packages are acting like one subsystem
|
|
39
|
+
- one package importing many internals of another usually means boundary erosion
|
|
40
|
+
|
|
41
|
+
### Broker / Articulation Analysis
|
|
42
|
+
|
|
43
|
+
Look for modules that many dependency paths flow through.
|
|
44
|
+
|
|
45
|
+
Use when:
|
|
46
|
+
|
|
47
|
+
- `hotFiles[]` is dominated by one or two files
|
|
48
|
+
- changes in one file ripple unexpectedly broadly
|
|
49
|
+
- the architecture feels centralized without an obvious god module
|
|
50
|
+
|
|
51
|
+
Interpretation:
|
|
52
|
+
|
|
53
|
+
- articulation points are brittle bridges between subsystems
|
|
54
|
+
- high-scoring chokepoints are priority refactor targets even if they have few direct findings
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## AST And Semantic Techniques
|
|
59
|
+
|
|
60
|
+
### Relational AST Rules
|
|
61
|
+
|
|
62
|
+
Use structure-aware rules instead of single-node patterns.
|
|
63
|
+
|
|
64
|
+
Good targets:
|
|
65
|
+
|
|
66
|
+
- boundary leaks
|
|
67
|
+
- import-time orchestration
|
|
68
|
+
- controller -> repository shortcuts
|
|
69
|
+
- modules mixing transport, persistence, and domain logic
|
|
70
|
+
|
|
71
|
+
Ask:
|
|
72
|
+
|
|
73
|
+
- is the suspicious node `inside` the wrong context?
|
|
74
|
+
- does the module `have` multiple unrelated responsibilities?
|
|
75
|
+
- do bad patterns `follow` or `precede` each other in a repeated shape?
|
|
76
|
+
|
|
77
|
+
### Symbol-Level Usage Graphs
|
|
78
|
+
|
|
79
|
+
Reason below the file level by tracking which exports are consumed together.
|
|
80
|
+
|
|
81
|
+
Use when:
|
|
82
|
+
|
|
83
|
+
- `low-cohesion` is flagged
|
|
84
|
+
- `feature-envy` looks real but the file is still widely used
|
|
85
|
+
- a barrel or utility file may hide unrelated APIs
|
|
86
|
+
|
|
87
|
+
Interpretation:
|
|
88
|
+
|
|
89
|
+
- disjoint consumer groups usually mean the file exports multiple concepts
|
|
90
|
+
- one symbol cluster dominating imports can mean the logic belongs closer to that target
|
|
91
|
+
|
|
92
|
+
### CFG / Dataflow Checks
|
|
93
|
+
|
|
94
|
+
Use lightweight flow reasoning to avoid flat heuristic claims.
|
|
95
|
+
|
|
96
|
+
Best questions:
|
|
97
|
+
|
|
98
|
+
- does validation dominate sink usage?
|
|
99
|
+
- does cleanup happen on all exits?
|
|
100
|
+
- is initialization happening only on some paths?
|
|
101
|
+
- does import-time work trigger hidden side effects?
|
|
102
|
+
|
|
103
|
+
Interpretation:
|
|
104
|
+
|
|
105
|
+
- if the path is not explainable, lower confidence
|
|
106
|
+
- if validation or cleanup is path-dependent, prefer a hybrid conclusion over a local one
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## How To Decide
|
|
111
|
+
|
|
112
|
+
- Use the **graph lens** first for cycles, chokepoints, package chatter, and startup risk.
|
|
113
|
+
- Use the **AST lens** first for low cohesion, feature envy, repeated orchestration, and side effects.
|
|
114
|
+
- Use the **hybrid lens** when graph and AST evidence point to the same file or boundary.
|
|
115
|
+
- If graph and AST signals conflict, say so explicitly and validate before concluding.
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## Validation
|
|
120
|
+
|
|
121
|
+
These techniques are investigation tools, not proof. Validate statements about live code with Octocode local tools before presenting as fact. See the Principles section in [SKILL.md](../SKILL.md).
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
# AST Search Reference
|
|
2
|
+
|
|
3
|
+
Structural code search powered by [`@ast-grep/napi`](https://ast-grep.github.io/). Finds code by AST shape, not text — `console.log(x)` matches regardless of whitespace or formatting.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
node <SKILL_DIR>/scripts/ast/search.js [options]
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Search Modes
|
|
12
|
+
|
|
13
|
+
Pick one per invocation.
|
|
14
|
+
|
|
15
|
+
### Pattern (`-p`, `--pattern`)
|
|
16
|
+
|
|
17
|
+
Write the code shape. Replace variable parts with `$X` (one node) or `$$$X` (zero or more).
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
-p 'console.log($$$ARGS)' # all console.log
|
|
21
|
+
-p 'console.$METHOD($$$ARGS)' # any console method
|
|
22
|
+
-p 'if ($COND) { return $VAL }' # early returns
|
|
23
|
+
-p 'import { $$$NAMES } from $MOD' # named imports (any module)
|
|
24
|
+
-p 'export const $NAME = $VAL' # exported constants
|
|
25
|
+
-p 'process.env.$VAR' # env access
|
|
26
|
+
-p 'throw new Error($$$MSG)' # error throws
|
|
27
|
+
-p 'function $NAME($$$P) { $$$B }' # function declarations
|
|
28
|
+
-p 'const $NAME = ($$$P) => $BODY' # arrow assignments
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Meta-variables captured in JSON output under `metaVariables`:
|
|
32
|
+
|
|
33
|
+
```json
|
|
34
|
+
{ "$METHOD": "log", "$$$ARGS": "\"hello\", 42" }
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
> **Quote sensitivity**: `'fs'` won't match `"fs"`. Use `$MOD` wildcard to match any quote style.
|
|
38
|
+
|
|
39
|
+
### Kind (`-k`, `--kind`)
|
|
40
|
+
|
|
41
|
+
Match all nodes of an AST kind.
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
-k function_declaration -k arrow_function -k class_declaration
|
|
45
|
+
-k interface_declaration -k type_alias_declaration -k import_statement
|
|
46
|
+
-k try_statement -k switch_statement -k for_in_statement
|
|
47
|
+
-k await_expression -k template_string -k object_pattern
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
> TS-only kinds (`predefined_type`, `interface_declaration`) are silently skipped on `.js` files.
|
|
51
|
+
|
|
52
|
+
### Preset (`--preset`)
|
|
53
|
+
|
|
54
|
+
16 built-in rules for common patterns. List with `--list-presets`.
|
|
55
|
+
|
|
56
|
+
| Preset | Finds |
|
|
57
|
+
|--------|-------|
|
|
58
|
+
| `empty-catch` | `catch (e) {}` — silently swallowed errors |
|
|
59
|
+
| `console-log` | `console.log(...)` left in production |
|
|
60
|
+
| `console-any` | Any `console.*()` call |
|
|
61
|
+
| `debugger` | `debugger;` statements |
|
|
62
|
+
| `todo-fixme` | TODO/FIXME/HACK/XXX/BUG comments |
|
|
63
|
+
| `any-type` | `: any` annotations (TS only) |
|
|
64
|
+
| `type-assertion` | `x as Type` assertions |
|
|
65
|
+
| `non-null-assertion` | `x!` non-null assertions |
|
|
66
|
+
| `fat-arrow-body` | `() => { return x }` — could be expression |
|
|
67
|
+
| `nested-ternary` | `a ? (b ? 1 : 2) : 3` |
|
|
68
|
+
| `throw-string` | `throw "oops"` — should be Error |
|
|
69
|
+
| `switch-no-default` | `switch` without `default` |
|
|
70
|
+
| `class-declaration` | All class declarations |
|
|
71
|
+
| `async-function` | `async function` declarations |
|
|
72
|
+
| `export-default` | `export default` statements |
|
|
73
|
+
| `import-star` | `import * as X` namespace imports |
|
|
74
|
+
|
|
75
|
+
### Rule (`--rule`)
|
|
76
|
+
|
|
77
|
+
Raw ast-grep rule JSON. Use for negation, regex, or nested structural queries.
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
# Negation: if without else
|
|
81
|
+
--rule '{"rule":{"kind":"if_statement","not":{"has":{"kind":"else_clause"}}}}'
|
|
82
|
+
|
|
83
|
+
# Regex on text: secrets in strings
|
|
84
|
+
--rule '{"rule":{"kind":"string","regex":"password|secret|token|api.?key"}}'
|
|
85
|
+
|
|
86
|
+
# Nested: try with finally
|
|
87
|
+
--rule '{"rule":{"kind":"try_statement","has":{"kind":"finally_clause","stopBy":"end"}}}'
|
|
88
|
+
|
|
89
|
+
# Long param lists
|
|
90
|
+
--rule '{"rule":{"kind":"formal_parameters","regex":"(,.*){5,}"}}'
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
**Rule operators:**
|
|
94
|
+
|
|
95
|
+
| Operator | Purpose | Example |
|
|
96
|
+
|----------|---------|---------|
|
|
97
|
+
| `kind` | Match node kind | `{"kind":"catch_clause"}` |
|
|
98
|
+
| `pattern` | Match code shape | `{"pattern":"console.log($$$A)"}` |
|
|
99
|
+
| `regex` | Match node text | `{"regex":"TODO\|FIXME"}` |
|
|
100
|
+
| `has` | Child matches rule | `{"has":{"kind":"finally_clause"}}` |
|
|
101
|
+
| `not` | Negate | `{"not":{"has":{"kind":"else_clause"}}}` |
|
|
102
|
+
| `all` | AND | `{"all":[{"kind":"X"},{"regex":"Y"}]}` |
|
|
103
|
+
| `any` | OR | `{"any":[{"kind":"X"},{"kind":"Y"}]}` |
|
|
104
|
+
| `stopBy: "end"` | Search descendants (not just direct children) | `{"has":{"kind":"X","stopBy":"end"}}` |
|
|
105
|
+
| `field` | Match by grammar field | `{"has":{"field":"default"}}` |
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## CLI Reference
|
|
110
|
+
|
|
111
|
+
```
|
|
112
|
+
node scripts/ast/search.js [options]
|
|
113
|
+
|
|
114
|
+
Search (pick one):
|
|
115
|
+
-p, --pattern <code> Code shape with $X/$$$X wildcards
|
|
116
|
+
-k, --kind <name> AST node kind
|
|
117
|
+
--preset <name> Built-in rule (see --list-presets)
|
|
118
|
+
--rule <json> Raw ast-grep rule JSON
|
|
119
|
+
|
|
120
|
+
Options:
|
|
121
|
+
--root <path> Search directory (default: cwd)
|
|
122
|
+
--json JSON output (use for programmatic consumption)
|
|
123
|
+
--limit N Max matches (default: 500)
|
|
124
|
+
--include-tests Include *.test.*, *.spec.*, __tests__/
|
|
125
|
+
-C, --context N Context lines around matches (text mode only)
|
|
126
|
+
--list-presets List presets and exit
|
|
127
|
+
-h, --help Show help
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
| Flag | Default | Notes |
|
|
131
|
+
|------|---------|-------|
|
|
132
|
+
| `--root` | cwd | Relative or absolute |
|
|
133
|
+
| `--json` | off | Outputs `AstSearchResult` — always use for agent consumption |
|
|
134
|
+
| `--limit` | 500 | Global cap across all files |
|
|
135
|
+
| `--include-tests` | off | Test files excluded by default |
|
|
136
|
+
| `--context` | 0 | Shows source lines around matches with `>` marker |
|
|
137
|
+
|
|
138
|
+
**Scanned**: `.ts`, `.tsx`, `.js`, `.jsx`, `.mjs`, `.cjs` (excludes `.d.ts`)
|
|
139
|
+
|
|
140
|
+
**Skipped dirs**: `.git`, `.next`, `.yarn`, `.cache`, `.octocode`, `node_modules`, `dist`, `coverage`, `out`
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## Output
|
|
145
|
+
|
|
146
|
+
### Text (default)
|
|
147
|
+
|
|
148
|
+
```
|
|
149
|
+
🔍 preset:empty-catch — Empty catch blocks that silently swallow errors
|
|
150
|
+
3 matches across 2 files
|
|
151
|
+
|
|
152
|
+
── packages/core/src/parser.ts ──
|
|
153
|
+
L42:4 [catch_clause] catch (e) { }
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Text with `--context 2`
|
|
157
|
+
|
|
158
|
+
```
|
|
159
|
+
── src/index.ts ──
|
|
160
|
+
896 | for (const [key, file] of Object.entries(outputFiles)) {
|
|
161
|
+
897 | let size = '—';
|
|
162
|
+
> 898 | try { size = formatFileSize(fs.statSync(path.join(dir, file)).size); } catch {}
|
|
163
|
+
899 | lines.push(...);
|
|
164
|
+
900 | }
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### JSON (`--json`)
|
|
168
|
+
|
|
169
|
+
```json
|
|
170
|
+
{
|
|
171
|
+
"query": "preset:empty-catch — ...",
|
|
172
|
+
"queryType": "preset",
|
|
173
|
+
"totalMatches": 3,
|
|
174
|
+
"totalFiles": 2,
|
|
175
|
+
"matches": [{
|
|
176
|
+
"file": "packages/core/src/parser.ts",
|
|
177
|
+
"kind": "catch_clause",
|
|
178
|
+
"text": "catch (e) { }",
|
|
179
|
+
"lineStart": 42, "lineEnd": 42,
|
|
180
|
+
"columnStart": 4, "columnEnd": 18,
|
|
181
|
+
"metaVariables": {}
|
|
182
|
+
}]
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
## Agent Guide
|
|
189
|
+
|
|
190
|
+
### Decision Tree
|
|
191
|
+
|
|
192
|
+
```
|
|
193
|
+
"Find all X() calls" → -p 'X($$$ARGS)'
|
|
194
|
+
"Find all X nodes" → -k X_kind_name
|
|
195
|
+
"Known code smell" → --preset name
|
|
196
|
+
"Negation / regex / nesting" → --rule '{...}'
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Rules for Agents
|
|
200
|
+
|
|
201
|
+
1. **Always `--json`** for programmatic use. Parse `totalMatches`, iterate `matches[]`.
|
|
202
|
+
2. **Start narrow**: `--limit 10 --root <specific-dir>` before broad search.
|
|
203
|
+
3. **Chain with scan**: `index.js` flags `unsafe-any` → `--preset any-type --root <pkg>`.
|
|
204
|
+
4. **Use `$MOD`** for imports — avoids quote mismatch.
|
|
205
|
+
5. **`--rule` for negation** — patterns can't express "X without Y".
|
|
206
|
+
6. **`stopBy: "end"`** required for recursive `has` (descendant search, not just children).
|
|
207
|
+
7. **Grammar-safe**: TS-only kinds silently skipped on JS files.
|
|
208
|
+
8. **`--include-tests`** for `describe`, `it`, `expect` patterns.
|
|
209
|
+
9. **Meta-variables** appear in JSON — extract captured `$NAME`, `$MOD`, `$$$ARGS`.
|
|
210
|
+
10. **`-C N`** for context — shows N lines before/after matches in text mode.
|