Analyze CLI (tools/analyze)
AST-based deep analysis CLI (@booking/tools-analyze) that scans source files with @ast-grep/napi and reports structural findings across 5 domains.
Overview
The analyze tool performs in-process AST analysis to detect structural code issues. Each finding maps to a review workflow, enabling automated quality gates in CI pipelines and pre-PR checks.
Tech Stack
| Layer | Technology | Version |
|---|---|---|
| Runtime | Bun | >= 1.3.14 |
| Language | TypeScript | ^7.0.2 |
| AST Engine | @ast-grep/napi | ^0.44.1 |
| Architecture | Clean Architecture | — |
| Bundling | bunup | ^0.16.32 |
| Linting | Biome | ^2.5.6 |
| Type Checking | tsc | ^7.0.2 |
| Testing | Vitest | ^4.1.10 |
Analysis Domains
| Domain | Rules | Review Workflow |
|---|---|---|
| Structure | no-default-export, no-barrel-in-deep | /review-architecture |
| Complexity | deep-nesting, long-function-body | /review-refactor |
| Patterns | no-console-log, no-any, no-ts-ignore, no-todo | /review-code-quality |
| Dependencies | no-cross-domain-import | /review-architecture |
| Dead Code | unused-private-function | /check-unused-files |
Architecture
tools/analyze/src/
├── index.ts # Library entry point
├── domain/ # Pure analyzer definitions + types
│ └── analyzers/ # Analyzer rules (5 domains)
├── application/ # Report builder, scorer
├── adapters/ # @ast-grep/napi wrapper, file discovery
└── presentation/ # CLI entry, args, format, helpKey Scripts
bash
# Run analysis (table output, default)
moon run tools-analyze:analyze
# JSON output for automation
moon run tools-analyze:analyze-json
# Markdown output
moon run tools-analyze:analyze-markdown
# Build
moon run tools-analyze:build
# Quality
moon run tools-analyze:lint
moon run tools-analyze:typecheck
moon run tools-analyze:verifyCLI Usage
bash
# Table format (default)
bun run analyze
# JSON format
bun run analyze:json
# Markdown format
bun run analyze:markdown
# Filter by domain and severity
bun run analyze -- --domain Complexity --severity High
# Write to file
bun run analyze -- --format json -o analysis.jsonCLI Options
| Option | Description |
|---|---|
--format <json|table|markdown> | Output format (default: table) |
--output <path>, -o | Write report to file instead of stdout |
--domain <name> | Filter by analyzer domain |
--severity <Critical|High|Medium|Low> | Filter by severity |
--verbose, -v | Show full evidence snippets |
--help, -h | Show help |
Related
- Health CLI — File-based health analysis (complementary)
- Architecture Overview — Clean Architecture layers
- Code Review — Review workflows