universal-ast-mapper 1.28.0 → 2.0.1
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/BLUEPRINT.md +230 -230
- package/CHANGELOG.md +475 -338
- package/README.md +1127 -878
- package/dist/ai-refactor.js +185 -0
- package/dist/ai-testgen.js +105 -0
- package/dist/arch-rules.js +82 -0
- package/dist/cli.js +1029 -20
- package/dist/covmerge.js +176 -0
- package/dist/dashboard.js +259 -0
- package/dist/diagram.js +264 -0
- package/dist/docgen.js +156 -0
- package/dist/embeddings.js +136 -0
- package/dist/explain.js +123 -0
- package/dist/fix.js +92 -0
- package/dist/history.js +36 -0
- package/dist/html.js +602 -270
- package/dist/incremental.js +122 -0
- package/dist/index.js +537 -0
- package/dist/indexstore.js +105 -0
- package/dist/lsp.js +238 -0
- package/dist/patch.js +199 -0
- package/dist/plugins.js +88 -0
- package/dist/report.js +285 -76
- package/dist/security.js +178 -0
- package/dist/serve.js +185 -0
- package/dist/similar.js +98 -0
- package/dist/smells.js +285 -0
- package/dist/testgen.js +280 -0
- package/dist/webapp.js +341 -0
- package/package.json +49 -47
- package/scripts/install-skill.mjs +187 -187
package/package.json
CHANGED
|
@@ -1,47 +1,49 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "universal-ast-mapper",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "MCP server that maps source files into a normalized code skeleton (JSON + HTML) using tree-sitter.",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "dist/index.js",
|
|
7
|
-
"bin": {
|
|
8
|
-
"universal-ast-mapper": "dist/index.js",
|
|
9
|
-
"ast-map": "dist/cli.js"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "universal-ast-mapper",
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"description": "MCP server that maps source files into a normalized code skeleton (JSON + HTML) using tree-sitter.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"universal-ast-mapper": "dist/index.js",
|
|
9
|
+
"ast-map": "dist/cli.js",
|
|
10
|
+
"ast-map-lsp": "dist/lsp.js"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist",
|
|
14
|
+
"scripts",
|
|
15
|
+
"README.md",
|
|
16
|
+
"CHANGELOG.md",
|
|
17
|
+
"BLUEPRINT.md"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"prepare": "npm run build",
|
|
21
|
+
"build": "tsc",
|
|
22
|
+
"start": "node dist/index.js",
|
|
23
|
+
"smoke": "node test/smoke.mjs",
|
|
24
|
+
"test": "node test/smoke.mjs && node test/analysis.mjs && node test/cache-smoke.mjs && node test/check-smoke.mjs && node test/roots-smoke.mjs && node test/tsalias-smoke.mjs",
|
|
25
|
+
"postinstall": "node scripts/install-skill.mjs"
|
|
26
|
+
},
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=18"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"mcp",
|
|
32
|
+
"ast",
|
|
33
|
+
"tree-sitter",
|
|
34
|
+
"code-map",
|
|
35
|
+
"skeleton"
|
|
36
|
+
],
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
40
|
+
"commander": "^14.0.3",
|
|
41
|
+
"tree-sitter-wasms": "0.1.13",
|
|
42
|
+
"web-tree-sitter": "0.21.0",
|
|
43
|
+
"zod": "^3.23.8"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/node": "^20.11.0",
|
|
47
|
+
"typescript": "^5.4.0"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -1,187 +1,187 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Postinstall: copies the /ast-map Claude Code skill to ~/.claude/skills/ast-map/
|
|
4
|
-
* so it appears in the / command palette automatically after install.
|
|
5
|
-
* Skips silently if Claude Code is not installed or if running in CI.
|
|
6
|
-
*/
|
|
7
|
-
import fs from "node:fs";
|
|
8
|
-
import path from "node:path";
|
|
9
|
-
import os from "node:os";
|
|
10
|
-
|
|
11
|
-
// ─── Skip in CI / non-interactive environments ────────────────────────────────
|
|
12
|
-
if (
|
|
13
|
-
process.env.CI ||
|
|
14
|
-
process.env.CONTINUOUS_INTEGRATION ||
|
|
15
|
-
process.env.npm_config_ci ||
|
|
16
|
-
process.env.GITHUB_ACTIONS ||
|
|
17
|
-
process.env.GITLAB_CI
|
|
18
|
-
) {
|
|
19
|
-
process.exit(0);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// ─── Skill content ────────────────────────────────────────────────────────────
|
|
23
|
-
|
|
24
|
-
const SKILL_MD = `---
|
|
25
|
-
name: ast-map
|
|
26
|
-
description: "AST-based code analysis using universal-ast-mapper. Use to understand codebase structure, find dead code, detect circular deps, check blast radius, validate architecture. Works on TypeScript, JavaScript, Python, Go."
|
|
27
|
-
trigger: /ast-map
|
|
28
|
-
---
|
|
29
|
-
|
|
30
|
-
# /ast-map
|
|
31
|
-
|
|
32
|
-
Run AST-based code analysis on the current project using universal-ast-mapper (tree-sitter).
|
|
33
|
-
|
|
34
|
-
## Usage
|
|
35
|
-
|
|
36
|
-
\`\`\`
|
|
37
|
-
/ast-map # architecture overview: dead code + cycles + top symbols
|
|
38
|
-
/ast-map dead [dir] # find unused exports
|
|
39
|
-
/ast-map cycles [dir] # detect circular import chains
|
|
40
|
-
/ast-map validate [path] # architecture + structural violations
|
|
41
|
-
/ast-map skeleton <file> # show a file's symbols and imports
|
|
42
|
-
/ast-map top [dir] # top N most-imported symbols (God Nodes)
|
|
43
|
-
/ast-map impact <file> <symbol> # blast radius of changing a symbol
|
|
44
|
-
/ast-map calls <file> <fn> # call graph for a function
|
|
45
|
-
/ast-map search <name> [dir] # find a symbol across all files
|
|
46
|
-
/ast-map deps <file> # what this file imports / what imports it
|
|
47
|
-
\`\`\`
|
|
48
|
-
|
|
49
|
-
If no path is given, use \`.\` (current working directory). Do not ask the user for a path.
|
|
50
|
-
|
|
51
|
-
---
|
|
52
|
-
|
|
53
|
-
## What You Must Do When Invoked
|
|
54
|
-
|
|
55
|
-
### Step 1 — Determine mode
|
|
56
|
-
|
|
57
|
-
Parse the arguments after \`/ast-map\`:
|
|
58
|
-
|
|
59
|
-
| Command | Action |
|
|
60
|
-
|---------|--------|
|
|
61
|
-
| _(no args)_ | Run full overview: dead + cycles + validate |
|
|
62
|
-
| \`dead [dir]\` | Find dead exports |
|
|
63
|
-
| \`cycles [dir]\` | Find circular deps |
|
|
64
|
-
| \`validate [path]\` | Architecture + structural check |
|
|
65
|
-
| \`skeleton <file>\` | File skeleton |
|
|
66
|
-
| \`top [dir]\` | Top imported symbols |
|
|
67
|
-
| \`impact <file> <symbol>\` | Change impact |
|
|
68
|
-
| \`calls <file> <fn>\` | Call graph |
|
|
69
|
-
| \`search <name> [dir]\` | Symbol search |
|
|
70
|
-
| \`deps <file>\` | File dependencies |
|
|
71
|
-
|
|
72
|
-
### Step 2 — Choose execution method
|
|
73
|
-
|
|
74
|
-
**Prefer MCP tools** (faster, no subprocess). If \`mcp__ast-mapper__*\` tools are available in the current session, use them. Otherwise fall back to CLI.
|
|
75
|
-
|
|
76
|
-
**MCP tool → CLI command mapping:**
|
|
77
|
-
|
|
78
|
-
| Command | MCP Tool | CLI fallback |
|
|
79
|
-
|---------|----------|-------------|
|
|
80
|
-
| dead | \`find_dead_code\` | \`ast-map dead <dir>\` |
|
|
81
|
-
| cycles | \`find_circular_deps\` | \`ast-map cycles <dir>\` |
|
|
82
|
-
| validate | \`validate_architecture\` | \`ast-map validate <path>\` |
|
|
83
|
-
| skeleton | \`get_skeleton_json\` | \`ast-map skeleton <file>\` |
|
|
84
|
-
| top | \`get_top_symbols\` | \`ast-map top <dir>\` |
|
|
85
|
-
| impact | \`get_change_impact\` | \`ast-map impact <file> <symbol>\` |
|
|
86
|
-
| calls | \`get_call_graph\` | \`ast-map calls <file> <fn>\` |
|
|
87
|
-
| search | \`search_symbol\` | \`ast-map search <name> <dir>\` |
|
|
88
|
-
| deps | \`get_file_deps\` | \`ast-map deps <file>\` |
|
|
89
|
-
|
|
90
|
-
### Step 3 — Full overview (no args)
|
|
91
|
-
|
|
92
|
-
If no command was given, run a 3-part overview and present a unified report:
|
|
93
|
-
|
|
94
|
-
1. **Dead code** — find high-confidence unused exports
|
|
95
|
-
2. **Circular deps** — detect import cycles
|
|
96
|
-
3. **Top symbols** — list the 5 most-imported symbols
|
|
97
|
-
|
|
98
|
-
Then summarise:
|
|
99
|
-
\`\`\`
|
|
100
|
-
AST-MCP Overview — [directory]
|
|
101
|
-
Scanned: N files
|
|
102
|
-
|
|
103
|
-
Dead Code (high confidence): X symbols
|
|
104
|
-
[list, grouped by file]
|
|
105
|
-
|
|
106
|
-
Circular Dependencies: Y cycles
|
|
107
|
-
[list each cycle as A → B → C → A]
|
|
108
|
-
|
|
109
|
-
God Nodes (top 5 most imported):
|
|
110
|
-
1. symbolName (file) — imported by N files
|
|
111
|
-
...
|
|
112
|
-
|
|
113
|
-
Recommendation: [1-2 sentences on what to look at first]
|
|
114
|
-
\`\`\`
|
|
115
|
-
|
|
116
|
-
### Step 4 — Present results clearly
|
|
117
|
-
|
|
118
|
-
- **Dead code**: group by file, show symbol name + kind. Note if 0 ("No dead exports found ✓")
|
|
119
|
-
- **Cycles**: show each cycle as \`A.ts → B.ts → C.ts → A.ts\`. Note length.
|
|
120
|
-
- **validate**: group by severity (errors first, then warnings). Show file + rule + message.
|
|
121
|
-
- **skeleton**: show symbols as a tree with line ranges.
|
|
122
|
-
- **impact**: show direct and transitive file lists + totalFiles count.
|
|
123
|
-
- **calls**: show call list with line numbers + whether external.
|
|
124
|
-
- **search**: show file + symbol + kind + line range.
|
|
125
|
-
|
|
126
|
-
Always end with a relevant follow-up offer:
|
|
127
|
-
- Found dead code? → "Want me to verify each one with \`impact\` before deleting?"
|
|
128
|
-
- Found cycles? → "Want me to show which import to break to resolve the shortest cycle?"
|
|
129
|
-
- Found God Nodes? → "Want me to check the blast radius of the top one?"
|
|
130
|
-
|
|
131
|
-
---
|
|
132
|
-
|
|
133
|
-
## Examples
|
|
134
|
-
|
|
135
|
-
### /ast-map
|
|
136
|
-
Runs dead + cycles + top on the current directory — a 30-second architecture health check.
|
|
137
|
-
|
|
138
|
-
### /ast-map dead src/
|
|
139
|
-
Finds all exported symbols in \`src/\` that are never imported by any other file.
|
|
140
|
-
|
|
141
|
-
### /ast-map validate src/ --max-lines 300
|
|
142
|
-
Checks for boundary violations, API routes missing try/catch, files over 300 lines.
|
|
143
|
-
|
|
144
|
-
### /ast-map impact src/lib/auth.ts validateSession
|
|
145
|
-
Shows every file that directly or transitively depends on \`validateSession\`.
|
|
146
|
-
`;
|
|
147
|
-
|
|
148
|
-
// ─── CLAUDE.md entry ──────────────────────────────────────────────────────────
|
|
149
|
-
|
|
150
|
-
const CLAUDE_MD_ENTRY = `
|
|
151
|
-
# ast-map
|
|
152
|
-
- **ast-map** (\`~/.claude/skills/ast-map/SKILL.md\`) - AST-based code analysis: dead code, circular deps, blast radius, architecture validation, symbol search. Trigger: \`/ast-map\`
|
|
153
|
-
When the user types \`/ast-map\`, invoke the Skill tool with \`skill: "ast-map"\` before doing anything else.
|
|
154
|
-
`;
|
|
155
|
-
|
|
156
|
-
// ─── Install ──────────────────────────────────────────────────────────────────
|
|
157
|
-
|
|
158
|
-
function main() {
|
|
159
|
-
const claudeDir = path.join(os.homedir(), ".claude");
|
|
160
|
-
|
|
161
|
-
// Only install if Claude Code config directory exists
|
|
162
|
-
if (!fs.existsSync(claudeDir)) return;
|
|
163
|
-
|
|
164
|
-
try {
|
|
165
|
-
// 1. Write SKILL.md
|
|
166
|
-
const skillDir = path.join(claudeDir, "skills", "ast-map");
|
|
167
|
-
fs.mkdirSync(skillDir, { recursive: true });
|
|
168
|
-
fs.writeFileSync(path.join(skillDir, "SKILL.md"), SKILL_MD, "utf8");
|
|
169
|
-
|
|
170
|
-
// 2. Update CLAUDE.md — idempotent (skip if entry already present)
|
|
171
|
-
const claudeMdPath = path.join(claudeDir, "CLAUDE.md");
|
|
172
|
-
const existing = fs.existsSync(claudeMdPath)
|
|
173
|
-
? fs.readFileSync(claudeMdPath, "utf8")
|
|
174
|
-
: "";
|
|
175
|
-
|
|
176
|
-
if (!existing.includes('skill: "ast-map"')) {
|
|
177
|
-
fs.writeFileSync(claudeMdPath, existing.trimEnd() + "\n" + CLAUDE_MD_ENTRY, "utf8");
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
console.log("✓ /ast-map skill installed to Claude Code (~/.claude/skills/ast-map/)");
|
|
181
|
-
console.log(' Type /ast-map in any Claude Code session to run code analysis.');
|
|
182
|
-
} catch {
|
|
183
|
-
// Non-fatal — skill install is best-effort, don't break npm install
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
main();
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Postinstall: copies the /ast-map Claude Code skill to ~/.claude/skills/ast-map/
|
|
4
|
+
* so it appears in the / command palette automatically after install.
|
|
5
|
+
* Skips silently if Claude Code is not installed or if running in CI.
|
|
6
|
+
*/
|
|
7
|
+
import fs from "node:fs";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
import os from "node:os";
|
|
10
|
+
|
|
11
|
+
// ─── Skip in CI / non-interactive environments ────────────────────────────────
|
|
12
|
+
if (
|
|
13
|
+
process.env.CI ||
|
|
14
|
+
process.env.CONTINUOUS_INTEGRATION ||
|
|
15
|
+
process.env.npm_config_ci ||
|
|
16
|
+
process.env.GITHUB_ACTIONS ||
|
|
17
|
+
process.env.GITLAB_CI
|
|
18
|
+
) {
|
|
19
|
+
process.exit(0);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// ─── Skill content ────────────────────────────────────────────────────────────
|
|
23
|
+
|
|
24
|
+
const SKILL_MD = `---
|
|
25
|
+
name: ast-map
|
|
26
|
+
description: "AST-based code analysis using universal-ast-mapper. Use to understand codebase structure, find dead code, detect circular deps, check blast radius, validate architecture. Works on TypeScript, JavaScript, Python, Go."
|
|
27
|
+
trigger: /ast-map
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
# /ast-map
|
|
31
|
+
|
|
32
|
+
Run AST-based code analysis on the current project using universal-ast-mapper (tree-sitter).
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
\`\`\`
|
|
37
|
+
/ast-map # architecture overview: dead code + cycles + top symbols
|
|
38
|
+
/ast-map dead [dir] # find unused exports
|
|
39
|
+
/ast-map cycles [dir] # detect circular import chains
|
|
40
|
+
/ast-map validate [path] # architecture + structural violations
|
|
41
|
+
/ast-map skeleton <file> # show a file's symbols and imports
|
|
42
|
+
/ast-map top [dir] # top N most-imported symbols (God Nodes)
|
|
43
|
+
/ast-map impact <file> <symbol> # blast radius of changing a symbol
|
|
44
|
+
/ast-map calls <file> <fn> # call graph for a function
|
|
45
|
+
/ast-map search <name> [dir] # find a symbol across all files
|
|
46
|
+
/ast-map deps <file> # what this file imports / what imports it
|
|
47
|
+
\`\`\`
|
|
48
|
+
|
|
49
|
+
If no path is given, use \`.\` (current working directory). Do not ask the user for a path.
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## What You Must Do When Invoked
|
|
54
|
+
|
|
55
|
+
### Step 1 — Determine mode
|
|
56
|
+
|
|
57
|
+
Parse the arguments after \`/ast-map\`:
|
|
58
|
+
|
|
59
|
+
| Command | Action |
|
|
60
|
+
|---------|--------|
|
|
61
|
+
| _(no args)_ | Run full overview: dead + cycles + validate |
|
|
62
|
+
| \`dead [dir]\` | Find dead exports |
|
|
63
|
+
| \`cycles [dir]\` | Find circular deps |
|
|
64
|
+
| \`validate [path]\` | Architecture + structural check |
|
|
65
|
+
| \`skeleton <file>\` | File skeleton |
|
|
66
|
+
| \`top [dir]\` | Top imported symbols |
|
|
67
|
+
| \`impact <file> <symbol>\` | Change impact |
|
|
68
|
+
| \`calls <file> <fn>\` | Call graph |
|
|
69
|
+
| \`search <name> [dir]\` | Symbol search |
|
|
70
|
+
| \`deps <file>\` | File dependencies |
|
|
71
|
+
|
|
72
|
+
### Step 2 — Choose execution method
|
|
73
|
+
|
|
74
|
+
**Prefer MCP tools** (faster, no subprocess). If \`mcp__ast-mapper__*\` tools are available in the current session, use them. Otherwise fall back to CLI.
|
|
75
|
+
|
|
76
|
+
**MCP tool → CLI command mapping:**
|
|
77
|
+
|
|
78
|
+
| Command | MCP Tool | CLI fallback |
|
|
79
|
+
|---------|----------|-------------|
|
|
80
|
+
| dead | \`find_dead_code\` | \`ast-map dead <dir>\` |
|
|
81
|
+
| cycles | \`find_circular_deps\` | \`ast-map cycles <dir>\` |
|
|
82
|
+
| validate | \`validate_architecture\` | \`ast-map validate <path>\` |
|
|
83
|
+
| skeleton | \`get_skeleton_json\` | \`ast-map skeleton <file>\` |
|
|
84
|
+
| top | \`get_top_symbols\` | \`ast-map top <dir>\` |
|
|
85
|
+
| impact | \`get_change_impact\` | \`ast-map impact <file> <symbol>\` |
|
|
86
|
+
| calls | \`get_call_graph\` | \`ast-map calls <file> <fn>\` |
|
|
87
|
+
| search | \`search_symbol\` | \`ast-map search <name> <dir>\` |
|
|
88
|
+
| deps | \`get_file_deps\` | \`ast-map deps <file>\` |
|
|
89
|
+
|
|
90
|
+
### Step 3 — Full overview (no args)
|
|
91
|
+
|
|
92
|
+
If no command was given, run a 3-part overview and present a unified report:
|
|
93
|
+
|
|
94
|
+
1. **Dead code** — find high-confidence unused exports
|
|
95
|
+
2. **Circular deps** — detect import cycles
|
|
96
|
+
3. **Top symbols** — list the 5 most-imported symbols
|
|
97
|
+
|
|
98
|
+
Then summarise:
|
|
99
|
+
\`\`\`
|
|
100
|
+
AST-MCP Overview — [directory]
|
|
101
|
+
Scanned: N files
|
|
102
|
+
|
|
103
|
+
Dead Code (high confidence): X symbols
|
|
104
|
+
[list, grouped by file]
|
|
105
|
+
|
|
106
|
+
Circular Dependencies: Y cycles
|
|
107
|
+
[list each cycle as A → B → C → A]
|
|
108
|
+
|
|
109
|
+
God Nodes (top 5 most imported):
|
|
110
|
+
1. symbolName (file) — imported by N files
|
|
111
|
+
...
|
|
112
|
+
|
|
113
|
+
Recommendation: [1-2 sentences on what to look at first]
|
|
114
|
+
\`\`\`
|
|
115
|
+
|
|
116
|
+
### Step 4 — Present results clearly
|
|
117
|
+
|
|
118
|
+
- **Dead code**: group by file, show symbol name + kind. Note if 0 ("No dead exports found ✓")
|
|
119
|
+
- **Cycles**: show each cycle as \`A.ts → B.ts → C.ts → A.ts\`. Note length.
|
|
120
|
+
- **validate**: group by severity (errors first, then warnings). Show file + rule + message.
|
|
121
|
+
- **skeleton**: show symbols as a tree with line ranges.
|
|
122
|
+
- **impact**: show direct and transitive file lists + totalFiles count.
|
|
123
|
+
- **calls**: show call list with line numbers + whether external.
|
|
124
|
+
- **search**: show file + symbol + kind + line range.
|
|
125
|
+
|
|
126
|
+
Always end with a relevant follow-up offer:
|
|
127
|
+
- Found dead code? → "Want me to verify each one with \`impact\` before deleting?"
|
|
128
|
+
- Found cycles? → "Want me to show which import to break to resolve the shortest cycle?"
|
|
129
|
+
- Found God Nodes? → "Want me to check the blast radius of the top one?"
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## Examples
|
|
134
|
+
|
|
135
|
+
### /ast-map
|
|
136
|
+
Runs dead + cycles + top on the current directory — a 30-second architecture health check.
|
|
137
|
+
|
|
138
|
+
### /ast-map dead src/
|
|
139
|
+
Finds all exported symbols in \`src/\` that are never imported by any other file.
|
|
140
|
+
|
|
141
|
+
### /ast-map validate src/ --max-lines 300
|
|
142
|
+
Checks for boundary violations, API routes missing try/catch, files over 300 lines.
|
|
143
|
+
|
|
144
|
+
### /ast-map impact src/lib/auth.ts validateSession
|
|
145
|
+
Shows every file that directly or transitively depends on \`validateSession\`.
|
|
146
|
+
`;
|
|
147
|
+
|
|
148
|
+
// ─── CLAUDE.md entry ──────────────────────────────────────────────────────────
|
|
149
|
+
|
|
150
|
+
const CLAUDE_MD_ENTRY = `
|
|
151
|
+
# ast-map
|
|
152
|
+
- **ast-map** (\`~/.claude/skills/ast-map/SKILL.md\`) - AST-based code analysis: dead code, circular deps, blast radius, architecture validation, symbol search. Trigger: \`/ast-map\`
|
|
153
|
+
When the user types \`/ast-map\`, invoke the Skill tool with \`skill: "ast-map"\` before doing anything else.
|
|
154
|
+
`;
|
|
155
|
+
|
|
156
|
+
// ─── Install ──────────────────────────────────────────────────────────────────
|
|
157
|
+
|
|
158
|
+
function main() {
|
|
159
|
+
const claudeDir = path.join(os.homedir(), ".claude");
|
|
160
|
+
|
|
161
|
+
// Only install if Claude Code config directory exists
|
|
162
|
+
if (!fs.existsSync(claudeDir)) return;
|
|
163
|
+
|
|
164
|
+
try {
|
|
165
|
+
// 1. Write SKILL.md
|
|
166
|
+
const skillDir = path.join(claudeDir, "skills", "ast-map");
|
|
167
|
+
fs.mkdirSync(skillDir, { recursive: true });
|
|
168
|
+
fs.writeFileSync(path.join(skillDir, "SKILL.md"), SKILL_MD, "utf8");
|
|
169
|
+
|
|
170
|
+
// 2. Update CLAUDE.md — idempotent (skip if entry already present)
|
|
171
|
+
const claudeMdPath = path.join(claudeDir, "CLAUDE.md");
|
|
172
|
+
const existing = fs.existsSync(claudeMdPath)
|
|
173
|
+
? fs.readFileSync(claudeMdPath, "utf8")
|
|
174
|
+
: "";
|
|
175
|
+
|
|
176
|
+
if (!existing.includes('skill: "ast-map"')) {
|
|
177
|
+
fs.writeFileSync(claudeMdPath, existing.trimEnd() + "\n" + CLAUDE_MD_ENTRY, "utf8");
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
console.log("✓ /ast-map skill installed to Claude Code (~/.claude/skills/ast-map/)");
|
|
181
|
+
console.log(' Type /ast-map in any Claude Code session to run code analysis.');
|
|
182
|
+
} catch {
|
|
183
|
+
// Non-fatal — skill install is best-effort, don't break npm install
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
main();
|