@kevinrabun/judges 3.2.0 → 3.4.0
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/README.md +131 -7
- package/dist/ast/index.d.ts +7 -8
- package/dist/ast/index.d.ts.map +1 -1
- package/dist/ast/index.js +16 -18
- package/dist/ast/index.js.map +1 -1
- package/dist/ast/tree-sitter-ast.d.ts.map +1 -1
- package/dist/ast/tree-sitter-ast.js +215 -9
- package/dist/ast/tree-sitter-ast.js.map +1 -1
- package/dist/cli.d.ts +8 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +169 -11
- package/dist/cli.js.map +1 -1
- package/dist/commands/ci-templates.d.ts +10 -0
- package/dist/commands/ci-templates.d.ts.map +1 -0
- package/dist/commands/ci-templates.js +90 -0
- package/dist/commands/ci-templates.js.map +1 -0
- package/dist/commands/fix.d.ts +21 -0
- package/dist/commands/fix.d.ts.map +1 -0
- package/dist/commands/fix.js +189 -0
- package/dist/commands/fix.js.map +1 -0
- package/dist/commands/hook.d.ts +9 -0
- package/dist/commands/hook.d.ts.map +1 -0
- package/dist/commands/hook.js +149 -0
- package/dist/commands/hook.js.map +1 -0
- package/dist/commands/init.d.ts +11 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +266 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/report.d.ts +13 -0
- package/dist/commands/report.d.ts.map +1 -0
- package/dist/commands/report.js +140 -0
- package/dist/commands/report.js.map +1 -0
- package/dist/commands/watch.d.ts +18 -0
- package/dist/commands/watch.d.ts.map +1 -0
- package/dist/commands/watch.js +183 -0
- package/dist/commands/watch.js.map +1 -0
- package/dist/evaluators/code-structure.d.ts +3 -3
- package/dist/evaluators/code-structure.js +3 -3
- package/dist/formatters/html.d.ts +13 -0
- package/dist/formatters/html.d.ts.map +1 -0
- package/dist/formatters/html.js +219 -0
- package/dist/formatters/html.js.map +1 -0
- package/dist/index.js +8 -3
- package/dist/index.js.map +1 -1
- package/dist/language-patterns.d.ts.map +1 -1
- package/dist/language-patterns.js +8 -0
- package/dist/language-patterns.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/grammars/tree-sitter-cpp.wasm +0 -0
- package/grammars/tree-sitter-typescript.wasm +0 -0
- package/package.json +3 -1
- package/server.json +2 -2
- package/dist/ast/typescript-ast.d.ts +0 -7
- package/dist/ast/typescript-ast.d.ts.map +0 -1
- package/dist/ast/typescript-ast.js +0 -236
- package/dist/ast/typescript-ast.js.map +0 -1
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ An MCP (Model Context Protocol) server that provides a panel of **35 specialized
|
|
|
11
11
|
[](https://www.npmjs.com/package/@kevinrabun/judges)
|
|
12
12
|
[](https://www.npmjs.com/package/@kevinrabun/judges)
|
|
13
13
|
[](https://opensource.org/licenses/MIT)
|
|
14
|
-
[](https://github.com/KevinRabun/judges/actions)
|
|
15
15
|
|
|
16
16
|
---
|
|
17
17
|
|
|
@@ -54,10 +54,47 @@ judges eval --judge cybersecurity server.ts
|
|
|
54
54
|
# SARIF output for CI
|
|
55
55
|
judges eval --file app.ts --format sarif > results.sarif
|
|
56
56
|
|
|
57
|
+
# HTML report with severity filters and dark/light theme
|
|
58
|
+
judges eval --file app.ts --format html > report.html
|
|
59
|
+
|
|
60
|
+
# Fail CI on findings (exit code 1)
|
|
61
|
+
judges eval --fail-on-findings src/api.ts
|
|
62
|
+
|
|
63
|
+
# Suppress known findings via baseline
|
|
64
|
+
judges eval --baseline baseline.json src/api.ts
|
|
65
|
+
|
|
66
|
+
# One-line summary for scripts
|
|
67
|
+
judges eval --summary src/api.ts
|
|
68
|
+
|
|
57
69
|
# List all 35 judges
|
|
58
70
|
judges list
|
|
59
71
|
```
|
|
60
72
|
|
|
73
|
+
### Additional CLI Commands
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
# Interactive project setup wizard
|
|
77
|
+
judges init
|
|
78
|
+
|
|
79
|
+
# Preview auto-fix patches (dry run)
|
|
80
|
+
judges fix src/app.ts
|
|
81
|
+
|
|
82
|
+
# Apply patches directly
|
|
83
|
+
judges fix src/app.ts --apply
|
|
84
|
+
|
|
85
|
+
# Watch mode — re-evaluate on file save
|
|
86
|
+
judges watch src/
|
|
87
|
+
|
|
88
|
+
# Project-level report (local directory)
|
|
89
|
+
judges report . --format html --output report.html
|
|
90
|
+
|
|
91
|
+
# Install pre-commit hook
|
|
92
|
+
judges hook install
|
|
93
|
+
|
|
94
|
+
# Uninstall pre-commit hook
|
|
95
|
+
judges hook uninstall
|
|
96
|
+
```
|
|
97
|
+
|
|
61
98
|
### Use in GitHub Actions
|
|
62
99
|
|
|
63
100
|
Add Judges to your CI pipeline with zero configuration:
|
|
@@ -321,6 +358,78 @@ This helps keep Copilot feedback aligned with Judges findings.
|
|
|
321
358
|
|
|
322
359
|
---
|
|
323
360
|
|
|
361
|
+
## CLI Reference
|
|
362
|
+
|
|
363
|
+
All commands support `--help` for usage details.
|
|
364
|
+
|
|
365
|
+
### `judges eval`
|
|
366
|
+
|
|
367
|
+
Evaluate a file with all 35 judges or a single judge.
|
|
368
|
+
|
|
369
|
+
| Flag | Description |
|
|
370
|
+
|------|-------------|
|
|
371
|
+
| `--file <path>` / positional | File to evaluate |
|
|
372
|
+
| `--judge <id>` / `-j <id>` | Single judge mode |
|
|
373
|
+
| `--language <lang>` / `-l <lang>` | Language hint (auto-detected from extension) |
|
|
374
|
+
| `--format <fmt>` / `-f <fmt>` | Output format: `text`, `json`, `sarif`, `markdown`, `html` |
|
|
375
|
+
| `--output <path>` / `-o <path>` | Write output to file |
|
|
376
|
+
| `--fail-on-findings` | Exit with code 1 if verdict is FAIL |
|
|
377
|
+
| `--baseline <path>` / `-b <path>` | JSON baseline file — suppress known findings |
|
|
378
|
+
| `--summary` | Print a single summary line (ideal for scripts) |
|
|
379
|
+
|
|
380
|
+
### `judges init`
|
|
381
|
+
|
|
382
|
+
Interactive wizard that generates project configuration:
|
|
383
|
+
- `.judgesrc.json` — rule customization, disabled judges, severity thresholds
|
|
384
|
+
- `.github/workflows/judges.yml` — GitHub Actions CI workflow
|
|
385
|
+
- `.gitlab-ci.judges.yml` — GitLab CI pipeline (optional)
|
|
386
|
+
- `azure-pipelines.judges.yml` — Azure Pipelines (optional)
|
|
387
|
+
|
|
388
|
+
### `judges fix`
|
|
389
|
+
|
|
390
|
+
Preview or apply auto-fix patches from deterministic findings.
|
|
391
|
+
|
|
392
|
+
| Flag | Description |
|
|
393
|
+
|------|-------------|
|
|
394
|
+
| positional | File to fix |
|
|
395
|
+
| `--apply` | Write patches to disk (default: dry run) |
|
|
396
|
+
| `--judge <id>` | Limit to a single judge's findings |
|
|
397
|
+
|
|
398
|
+
### `judges watch`
|
|
399
|
+
|
|
400
|
+
Continuously re-evaluate files on save.
|
|
401
|
+
|
|
402
|
+
| Flag | Description |
|
|
403
|
+
|------|-------------|
|
|
404
|
+
| positional | File or directory to watch (default: `.`) |
|
|
405
|
+
| `--judge <id>` | Single judge mode |
|
|
406
|
+
| `--fail-on-findings` | Exit non-zero if any evaluation fails |
|
|
407
|
+
|
|
408
|
+
### `judges report`
|
|
409
|
+
|
|
410
|
+
Run a full project-level tribunal on a local directory.
|
|
411
|
+
|
|
412
|
+
| Flag | Description |
|
|
413
|
+
|------|-------------|
|
|
414
|
+
| positional | Directory path (default: `.`) |
|
|
415
|
+
| `--format <fmt>` | Output format: `text`, `json`, `html`, `markdown` |
|
|
416
|
+
| `--output <path>` | Write report to file |
|
|
417
|
+
| `--max-files <n>` | Maximum files to analyze (default: 600) |
|
|
418
|
+
| `--max-file-bytes <n>` | Skip files larger than this (default: 300000) |
|
|
419
|
+
|
|
420
|
+
### `judges hook`
|
|
421
|
+
|
|
422
|
+
Manage a Git pre-commit hook that runs Judges on staged files.
|
|
423
|
+
|
|
424
|
+
```bash
|
|
425
|
+
judges hook install # add pre-commit hook
|
|
426
|
+
judges hook uninstall # remove pre-commit hook
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
Detects Husky (`.husky/pre-commit`) and falls back to `.git/hooks/pre-commit`. Uses marker-based injection so it won't clobber existing hooks.
|
|
430
|
+
|
|
431
|
+
---
|
|
432
|
+
|
|
324
433
|
## The Judge Panel
|
|
325
434
|
|
|
326
435
|
| Judge | Domain | Rule Prefix | What It Evaluates |
|
|
@@ -369,7 +478,7 @@ The tribunal operates in three layers:
|
|
|
369
478
|
|
|
370
479
|
1. **Pattern-Based Analysis** — All tools (`evaluate_code`, `evaluate_code_single_judge`, `evaluate_project`, `evaluate_diff`) perform heuristic analysis using regex pattern matching to catch common anti-patterns. This layer is instant, deterministic, and runs entirely offline with zero external API calls.
|
|
371
480
|
|
|
372
|
-
2. **AST-Based Structural Analysis** — The Code Structure judge (`STRUCT-*` rules) uses real Abstract Syntax Tree parsing to measure cyclomatic complexity, nesting depth, function length, parameter count, dead code, and type safety with precision that regex cannot achieve.
|
|
481
|
+
2. **AST-Based Structural Analysis** — The Code Structure judge (`STRUCT-*` rules) uses real Abstract Syntax Tree parsing to measure cyclomatic complexity, nesting depth, function length, parameter count, dead code, and type safety with precision that regex cannot achieve. All supported languages — **TypeScript, JavaScript, Python, Rust, Go, Java, C#, and C++** — are parsed via **tree-sitter WASM grammars** (real syntax trees compiled to WebAssembly, in-process, zero native dependencies). A scope-tracking structural parser is kept as a fallback when WASM grammars are unavailable. No external AST server required.
|
|
373
482
|
|
|
374
483
|
3. **LLM-Powered Deep Analysis (Prompts)** — The server exposes MCP prompts (e.g., `judge-data-security`, `full-tribunal`) that provide each judge's expert persona as a system prompt. When used by an LLM-based client (Copilot, Claude, Cursor, etc.), the host LLM performs deeper, context-aware probabilistic analysis beyond what static patterns can detect. This is where the `systemPrompt` on each judge comes alive — Judges itself makes no LLM calls, but it provides the expert criteria so your AI assistant can act as 35 specialized reviewers.
|
|
375
484
|
|
|
@@ -379,12 +488,11 @@ The tribunal operates in three layers:
|
|
|
379
488
|
|
|
380
489
|
Judges Panel is a **dual-layer** review system: instant **deterministic tools** (offline, no API keys) for pattern and AST analysis, plus **35 expert-persona MCP prompts** that unlock LLM-powered deep analysis when connected to an AI client. It does not try to be a CVE scanner or a linter. Those capabilities belong in dedicated MCP servers that an AI agent can orchestrate alongside Judges.
|
|
381
490
|
|
|
382
|
-
### Built-in AST Analysis (v2.0.0)
|
|
491
|
+
### Built-in AST Analysis (v2.0.0+)
|
|
383
492
|
|
|
384
493
|
Unlike earlier versions that recommended a separate AST MCP server, Judges Panel now includes **real AST-based structural analysis** out of the box:
|
|
385
494
|
|
|
386
|
-
- **JavaScript
|
|
387
|
-
- **Python, Rust, Go, Java, C#** — Parsed with **tree-sitter WASM grammars** for full syntax-tree analysis (functions, complexity, nesting, dead code, type safety). Falls back to a scope-tracking structural parser when WASM grammars are unavailable
|
|
495
|
+
- **TypeScript, JavaScript, Python, Rust, Go, Java, C#, C++** — All parsed with a **unified tree-sitter WASM engine** for full syntax-tree analysis (functions, complexity, nesting, dead code, type safety). Falls back to a scope-tracking structural parser when WASM grammars are unavailable
|
|
388
496
|
|
|
389
497
|
The Code Structure judge (`STRUCT-*`) uses these parsers to accurately measure:
|
|
390
498
|
|
|
@@ -810,13 +918,22 @@ judges/
|
|
|
810
918
|
│ ├── ast/ # AST analysis engine (built-in, no external deps)
|
|
811
919
|
│ │ ├── index.ts # analyzeStructure() — routes to correct parser
|
|
812
920
|
│ │ ├── types.ts # FunctionInfo, CodeStructure interfaces
|
|
813
|
-
│ │ ├──
|
|
814
|
-
│ │ ├── tree-sitter-ast.ts # Tree-sitter WASM parser (Python/Rust/Go/Java/C#)
|
|
921
|
+
│ │ ├── tree-sitter-ast.ts # Tree-sitter WASM parser (all 8 languages)
|
|
815
922
|
│ │ └── structural-parser.ts # Fallback scope-tracking parser
|
|
816
923
|
│ ├── evaluators/ # Analysis engine for each judge
|
|
817
924
|
│ │ ├── index.ts # evaluateWithJudge(), evaluateWithTribunal(), evaluateProject(), etc.
|
|
818
925
|
│ │ ├── shared.ts # Scoring, verdict logic, markdown formatters
|
|
819
926
|
│ │ └── *.ts # One analyzer per judge (35 files)
|
|
927
|
+
│ ├── formatters/ # Output formatters
|
|
928
|
+
│ │ ├── sarif.ts # SARIF 2.1.0 output
|
|
929
|
+
│ │ └── html.ts # Self-contained HTML report (dark/light theme, filters)
|
|
930
|
+
│ ├── commands/ # CLI subcommands
|
|
931
|
+
│ │ ├── init.ts # Interactive project setup wizard
|
|
932
|
+
│ │ ├── fix.ts # Auto-fix patch preview and application
|
|
933
|
+
│ │ ├── watch.ts # Watch mode — re-evaluate on save
|
|
934
|
+
│ │ ├── report.ts # Project-level local report
|
|
935
|
+
│ │ ├── hook.ts # Pre-commit hook install/uninstall
|
|
936
|
+
│ │ └── ci-templates.ts # GitLab, Azure, Bitbucket CI templates
|
|
820
937
|
│ ├── reports/
|
|
821
938
|
│ │ └── public-repo-report.ts # Public repo clone + full tribunal report generation
|
|
822
939
|
│ └── judges/ # Judge definitions (id, name, domain, system prompt)
|
|
@@ -831,6 +948,8 @@ judges/
|
|
|
831
948
|
├── tests/
|
|
832
949
|
│ └── judges.test.ts # Run: npm test
|
|
833
950
|
├── grammars/ # Tree-sitter WASM grammar files
|
|
951
|
+
│ ├── tree-sitter-typescript.wasm
|
|
952
|
+
│ ├── tree-sitter-cpp.wasm
|
|
834
953
|
│ ├── tree-sitter-python.wasm
|
|
835
954
|
│ ├── tree-sitter-go.wasm
|
|
836
955
|
│ ├── tree-sitter-rust.wasm
|
|
@@ -857,6 +976,11 @@ judges/
|
|
|
857
976
|
| `npm run automation:daily-popular` | Analyze up to 10 rotating popular repos/day and open up to 5 remediation PRs per repo |
|
|
858
977
|
| `npm start` | Start the MCP server |
|
|
859
978
|
| `npm run clean` | Remove `dist/` |
|
|
979
|
+
| `judges init` | Interactive project setup wizard |
|
|
980
|
+
| `judges fix <file>` | Preview auto-fix patches (add `--apply` to write) |
|
|
981
|
+
| `judges watch <dir>` | Watch mode — re-evaluate on file save |
|
|
982
|
+
| `judges report <dir>` | Full tribunal report on a local directory |
|
|
983
|
+
| `judges hook install` | Install a Git pre-commit hook |
|
|
860
984
|
|
|
861
985
|
---
|
|
862
986
|
|
package/dist/ast/index.d.ts
CHANGED
|
@@ -6,22 +6,21 @@ export type { TaintFlow, TaintSourceKind, TaintSinkKind } from "./taint-tracker.
|
|
|
6
6
|
export { analyzeCrossFileTaint } from "./cross-file-taint.js";
|
|
7
7
|
export type { CrossFileTaintFlow } from "./cross-file-taint.js";
|
|
8
8
|
/**
|
|
9
|
-
* Analyse source code structurally.
|
|
10
|
-
* TypeScript
|
|
11
|
-
*
|
|
12
|
-
* lightweight scope-tracking parser.
|
|
9
|
+
* Analyse source code structurally. Uses tree-sitter (real AST via WASM) for
|
|
10
|
+
* TypeScript, JavaScript, Python, Rust, Go, Java, C#, and C++ when available,
|
|
11
|
+
* falling back to the lightweight scope-tracking structural parser.
|
|
13
12
|
*
|
|
14
13
|
* Returns function metrics (complexity, nesting, length, params), dead code
|
|
15
14
|
* locations, deep-nesting locations, and type-safety issues.
|
|
16
15
|
*/
|
|
17
16
|
export declare function analyzeStructure(code: string, language: string): CodeStructure;
|
|
18
17
|
/**
|
|
19
|
-
* Async version of analyzeStructure that uses tree-sitter (real AST) for
|
|
20
|
-
*
|
|
18
|
+
* Async version of analyzeStructure that uses tree-sitter (real AST) for all
|
|
19
|
+
* supported languages when WASM grammars are available.
|
|
21
20
|
* Falls back to the structural parser if tree-sitter is not available.
|
|
22
21
|
*
|
|
23
|
-
* Prefer this over analyzeStructure()
|
|
24
|
-
*
|
|
22
|
+
* Prefer this over analyzeStructure() when async is acceptable — it ensures
|
|
23
|
+
* tree-sitter grammars are fully loaded before analysis.
|
|
25
24
|
*/
|
|
26
25
|
export declare function analyzeStructureAsync(code: string, language: string): Promise<CodeStructure>;
|
|
27
26
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/ast/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ast/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ast/index.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE9D,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,CAAC;AAG5C,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAGpF,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGpF,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,YAAY,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAahE;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,aAAa,CAsC9E;AAED;;;;;;;GAOG;AACH,wBAAsB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAqClG"}
|
package/dist/ast/index.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
2
2
|
// AST Analysis — Unified Entry Point
|
|
3
3
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
4
|
-
// Routes to the
|
|
5
|
-
//
|
|
6
|
-
//
|
|
4
|
+
// Routes to the tree-sitter real-AST parser (WASM) for TypeScript, JavaScript,
|
|
5
|
+
// Python, Rust, Go, Java, C#, and C++ when grammars are available, or the
|
|
6
|
+
// lightweight structural parser as a fallback.
|
|
7
7
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
8
8
|
import { normalizeLanguage } from "../language-patterns.js";
|
|
9
|
-
import { analyzeTypeScript } from "./typescript-ast.js";
|
|
10
9
|
import { analyzeStructurally } from "./structural-parser.js";
|
|
11
10
|
import { isTreeSitterAvailable, isTreeSitterReadySync, analyzeWithTreeSitter, analyzeWithTreeSitterSync, } from "./tree-sitter-ast.js";
|
|
12
11
|
// Re-export tree-sitter availability checks
|
|
@@ -18,16 +17,15 @@ export { analyzeCrossFileTaint } from "./cross-file-taint.js";
|
|
|
18
17
|
// ─── Tree-sitter Warm-up ────────────────────────────────────────────────────
|
|
19
18
|
// Pre-initialize tree-sitter on module load so it's ready when needed.
|
|
20
19
|
// This is fire-and-forget; if it fails, analyzeStructure falls back silently.
|
|
21
|
-
const TREE_SITTER_LANGS = ["python", "rust", "go", "java", "csharp"];
|
|
20
|
+
const TREE_SITTER_LANGS = ["typescript", "javascript", "python", "rust", "go", "java", "csharp", "cpp"];
|
|
22
21
|
const treeSitterReady = new Map();
|
|
23
22
|
for (const lang of TREE_SITTER_LANGS) {
|
|
24
23
|
treeSitterReady.set(lang, isTreeSitterAvailable(lang));
|
|
25
24
|
}
|
|
26
25
|
/**
|
|
27
|
-
* Analyse source code structurally.
|
|
28
|
-
* TypeScript
|
|
29
|
-
*
|
|
30
|
-
* lightweight scope-tracking parser.
|
|
26
|
+
* Analyse source code structurally. Uses tree-sitter (real AST via WASM) for
|
|
27
|
+
* TypeScript, JavaScript, Python, Rust, Go, Java, C#, and C++ when available,
|
|
28
|
+
* falling back to the lightweight scope-tracking structural parser.
|
|
31
29
|
*
|
|
32
30
|
* Returns function metrics (complexity, nesting, length, params), dead code
|
|
33
31
|
* locations, deep-nesting locations, and type-safety issues.
|
|
@@ -35,14 +33,14 @@ for (const lang of TREE_SITTER_LANGS) {
|
|
|
35
33
|
export function analyzeStructure(code, language) {
|
|
36
34
|
const lang = normalizeLanguage(language);
|
|
37
35
|
switch (lang) {
|
|
38
|
-
case "javascript":
|
|
39
36
|
case "typescript":
|
|
40
|
-
|
|
37
|
+
case "javascript":
|
|
41
38
|
case "python":
|
|
42
39
|
case "rust":
|
|
43
40
|
case "go":
|
|
44
41
|
case "java":
|
|
45
42
|
case "csharp":
|
|
43
|
+
case "cpp":
|
|
46
44
|
// Use tree-sitter (real AST) if WASM runtime + grammar already loaded,
|
|
47
45
|
// otherwise fall back to the lightweight structural parser.
|
|
48
46
|
// parser.parse() is synchronous in web-tree-sitter once initialized.
|
|
@@ -71,24 +69,24 @@ export function analyzeStructure(code, language) {
|
|
|
71
69
|
}
|
|
72
70
|
}
|
|
73
71
|
/**
|
|
74
|
-
* Async version of analyzeStructure that uses tree-sitter (real AST) for
|
|
75
|
-
*
|
|
72
|
+
* Async version of analyzeStructure that uses tree-sitter (real AST) for all
|
|
73
|
+
* supported languages when WASM grammars are available.
|
|
76
74
|
* Falls back to the structural parser if tree-sitter is not available.
|
|
77
75
|
*
|
|
78
|
-
* Prefer this over analyzeStructure()
|
|
79
|
-
*
|
|
76
|
+
* Prefer this over analyzeStructure() when async is acceptable — it ensures
|
|
77
|
+
* tree-sitter grammars are fully loaded before analysis.
|
|
80
78
|
*/
|
|
81
79
|
export async function analyzeStructureAsync(code, language) {
|
|
82
80
|
const lang = normalizeLanguage(language);
|
|
83
81
|
switch (lang) {
|
|
84
|
-
case "javascript":
|
|
85
82
|
case "typescript":
|
|
86
|
-
|
|
83
|
+
case "javascript":
|
|
87
84
|
case "python":
|
|
88
85
|
case "rust":
|
|
89
86
|
case "go":
|
|
90
87
|
case "java":
|
|
91
|
-
case "csharp":
|
|
88
|
+
case "csharp":
|
|
89
|
+
case "cpp": {
|
|
92
90
|
// Try tree-sitter first (real AST), fall back to structural parser
|
|
93
91
|
const available = await (treeSitterReady.get(lang) ?? Promise.resolve(false));
|
|
94
92
|
if (available) {
|
package/dist/ast/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ast/index.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,qCAAqC;AACrC,gFAAgF;AAChF
|
|
1
|
+
{"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9E,IAAI,SAAS,EAAE,CAAC;gBACd,IAAI,CAAC;oBACH,OAAO,MAAM,qBAAqB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;gBACjD,CAAC;gBAAC,MAAM,CAAC;oBACP,qDAAqD;gBACvD,CAAC;YACH,CAAC;YACD,OAAO,mBAAmB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACzC,CAAC;QAED;YACE,OAAO;gBACL,QAAQ,EAAE,IAAI;gBACd,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM;gBACnC,SAAS,EAAE,EAAE;gBACb,wBAAwB,EAAE,CAAC;gBAC3B,eAAe,EAAE,CAAC;gBAClB,aAAa,EAAE,EAAE;gBACjB,aAAa,EAAE,EAAE;gBACjB,YAAY,EAAE,EAAE;gBAChB,OAAO,EAAE,EAAE;aACZ,CAAC;IACN,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tree-sitter-ast.d.ts","sourceRoot":"","sources":["../../src/ast/tree-sitter-ast.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tree-sitter-ast.d.ts","sourceRoot":"","sources":["../../src/ast/tree-sitter-ast.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,aAAa,EAAgB,MAAM,YAAY,CAAC;AAqG9D;;;GAGG;AACH,wBAAsB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAK1E;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE3D;AAED;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,aAAa,CAKvF;AAED;;;;;;;GAOG;AACH,wBAAsB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAKlG"}
|