codebase-analyzer-mcp 1.0.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.
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "jkcorrea-plugins",
3
+ "owner": {
4
+ "name": "jkcorrea",
5
+ "url": "https://github.com/jkcorrea"
6
+ },
7
+ "metadata": {
8
+ "description": "AI-powered development tools by jkcorrea",
9
+ "version": "1.0.0"
10
+ },
11
+ "plugins": [
12
+ {
13
+ "name": "codebase-analyzer",
14
+ "description": "Multi-layer codebase analysis with Gemini AI. 4 agents, 5 commands, 3 skills for architecture analysis, pattern detection, and dataflow tracing.",
15
+ "version": "1.0.0",
16
+ "author": {
17
+ "name": "jkcorrea",
18
+ "url": "https://github.com/jkcorrea"
19
+ },
20
+ "homepage": "https://github.com/jkcorrea/codebase-analyzer-mcp",
21
+ "tags": [
22
+ "codebase-analysis",
23
+ "architecture",
24
+ "patterns",
25
+ "gemini",
26
+ "mcp"
27
+ ],
28
+ "source": "."
29
+ }
30
+ ]
31
+ }
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "codebase-analyzer",
3
+ "version": "1.0.0",
4
+ "description": "Multi-layer codebase analysis with Gemini AI. 4 agents, 5 commands, 3 skills for architecture analysis, pattern detection, and dataflow tracing.",
5
+ "author": {
6
+ "name": "jkcorrea",
7
+ "url": "https://github.com/jkcorrea"
8
+ },
9
+ "homepage": "https://github.com/jkcorrea/codebase-analyzer-mcp",
10
+ "license": "MIT",
11
+ "keywords": [
12
+ "codebase-analysis",
13
+ "architecture",
14
+ "patterns",
15
+ "gemini",
16
+ "mcp",
17
+ "progressive-disclosure",
18
+ "tree-sitter"
19
+ ],
20
+ "mcpServers": {
21
+ "codebase-analyzer": {
22
+ "command": "node",
23
+ "args": [
24
+ "dist/mcp/server.js"
25
+ ],
26
+ "cwd": "."
27
+ }
28
+ }
29
+ }
package/AGENTS.md ADDED
@@ -0,0 +1,112 @@
1
+ # Agent Instructions
2
+
3
+ This repository is both an MCP server and a Claude plugin for multi-layer codebase analysis.
4
+
5
+ ## Working Agreement
6
+
7
+ - **Branching:** Feature branches for non-trivial changes
8
+ - **Safety:** No destructive git commands, no deleting user data
9
+ - **Testing:** Run `pnpm build` after changes - TypeScript errors break everything
10
+ - **Architecture:** Respect layer separation (surface → structural → semantic)
11
+ - **Counts:** When adding agents/commands/skills, update plugin.json description
12
+
13
+ ## Repository Structure
14
+
15
+ ```
16
+ codebase-analyzer-mcp/
17
+ ├── .claude-plugin/
18
+ │ └── plugin.json # Plugin metadata
19
+ ├── agents/
20
+ │ ├── analysis/ # Analysis agents
21
+ │ └── research/ # Research agents
22
+ ├── commands/ # Slash commands
23
+ ├── skills/ # Context-loaded skills
24
+ ├── src/
25
+ │ ├── mcp/ # MCP server + tools
26
+ │ ├── cli/ # CLI interface
27
+ │ └── core/ # Analysis engine
28
+ │ └── layers/ # Surface, structural, semantic
29
+ └── docs/ # Documentation
30
+ ```
31
+
32
+ ## Key Decisions
33
+
34
+ | Decision | Rationale |
35
+ |----------|-----------|
36
+ | Gemini for semantic | Keep Claude context clean |
37
+ | Tree-sitter for parsing | Fast AST without LLM |
38
+ | Progressive disclosure | Minimize initial context cost |
39
+ | Plugin + MCP | Both distribution paths |
40
+
41
+ ## Layer Responsibilities
42
+
43
+ **Surface Layer** (`src/core/layers/surface.ts`)
44
+ - File enumeration, language detection
45
+ - Entry points, module identification
46
+ - NO LLM calls
47
+
48
+ **Structural Layer** (`src/core/layers/structural.ts`)
49
+ - Tree-sitter parsing
50
+ - Symbol extraction
51
+ - Import/export mapping
52
+ - NO LLM calls
53
+
54
+ **Semantic Layer** (`src/core/layers/semantic.ts`)
55
+ - Gemini API calls
56
+ - Architecture detection
57
+ - Pattern recognition
58
+ - EXPENSIVE - opt-in only
59
+
60
+ ## Code Patterns
61
+
62
+ **Partial failures:** Capture in `warnings[]` or `partialFailures[]`, don't throw
63
+
64
+ **Token budget:** Check before expensive operations, warn if exceeded
65
+
66
+ **Logging:** Use `logger` from `src/core/logger.ts`
67
+
68
+ ## Plugin Component Guidelines
69
+
70
+ ### Agents
71
+
72
+ - Place in `agents/[category]/` by purpose
73
+ - YAML frontmatter: `name`, `description` with examples
74
+ - Description explains when to use the agent
75
+ - Use haiku model for efficiency
76
+
77
+ ### Commands
78
+
79
+ - Place in `commands/`
80
+ - Set `user-invocable: true`
81
+ - Document usage, options, examples
82
+ - Show workflow and implementation
83
+
84
+ ### Skills
85
+
86
+ - Directory in `skills/[name]/`
87
+ - SKILL.md is entry point (<500 lines)
88
+ - references/ for detailed docs
89
+ - Description in third person
90
+
91
+ ## Updating Plugin Counts
92
+
93
+ After adding/removing components:
94
+
95
+ ```bash
96
+ # Count components
97
+ ls agents/**/*.md | wc -l # agents
98
+ ls commands/*.md | wc -l # commands
99
+ ls -d skills/*/ | wc -l # skills
100
+
101
+ # Update description in .claude-plugin/plugin.json
102
+ ```
103
+
104
+ Format: `"X agents, Y commands, Z skills"`
105
+
106
+ ## Testing Checklist
107
+
108
+ - [ ] `pnpm build` succeeds
109
+ - [ ] `pnpm cba capabilities` returns JSON
110
+ - [ ] `pnpm cba analyze . -d surface -q` works
111
+ - [ ] New agent/command/skill follows patterns
112
+ - [ ] plugin.json counts match actual files
package/CLAUDE.md ADDED
@@ -0,0 +1,150 @@
1
+ # Codebase Analyzer MCP
2
+
3
+ Multi-layer codebase analysis with Gemini AI. Both an MCP server and a Claude plugin.
4
+
5
+ ## Philosophy
6
+
7
+ **Progressive Disclosure**: Start cheap (surface), reveal more on demand. Don't analyze everything upfront.
8
+
9
+ **Budget Awareness**: Track tokens. Surface is free, structural is cheap, semantic is expensive.
10
+
11
+ **Graceful Degradation**: Partial failures don't break analysis. Capture warnings, continue.
12
+
13
+ **Agent-First Design**: Output structured for AI agents - expandable sections, cost estimates, next steps.
14
+
15
+ ## Quick Start
16
+
17
+ ```bash
18
+ pnpm install && pnpm build
19
+ ```
20
+
21
+ ## Plugin Components
22
+
23
+ | Component | Count | Purpose |
24
+ |-----------|-------|---------|
25
+ | Agents | 4 | Specialized analysis tasks |
26
+ | Commands | 5 | User-invocable actions |
27
+ | Skills | 3 | Context-loaded guidance |
28
+ | MCP Server | 1 | Tool interface for Claude |
29
+
30
+ ### Agents
31
+
32
+ | Agent | Purpose |
33
+ |-------|---------|
34
+ | `architecture-analyzer` | Full codebase architecture analysis |
35
+ | `pattern-detective` | Design/anti-pattern detection |
36
+ | `dataflow-tracer` | Data flow tracing through systems |
37
+ | `codebase-explorer` | Quick exploration and Q&A |
38
+
39
+ ### Commands
40
+
41
+ | Command | Usage |
42
+ |---------|-------|
43
+ | `/analyze` | Analyze a codebase |
44
+ | `/patterns` | Find design patterns |
45
+ | `/trace` | Trace data flow |
46
+ | `/explore` | Quick exploration |
47
+ | `/compare` | Compare repositories |
48
+
49
+ ### Skills
50
+
51
+ | Skill | Purpose |
52
+ |-------|---------|
53
+ | `codebase-analysis` | How to use the MCP tools |
54
+ | `add-mcp-tool` | Guide for adding new tools |
55
+ | `debugging-analysis` | Troubleshooting analysis issues |
56
+
57
+ ## Architecture
58
+
59
+ See [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) for system design.
60
+
61
+ ## Key Paths
62
+
63
+ | Path | Purpose |
64
+ |------|---------|
65
+ | `.claude-plugin/plugin.json` | Plugin metadata |
66
+ | `agents/` | Agent definitions |
67
+ | `commands/` | Slash commands |
68
+ | `skills/` | Context-loaded skills |
69
+ | `src/mcp/server.ts` | MCP server entry |
70
+ | `src/mcp/tools/` | MCP tool definitions |
71
+ | `src/cli/index.ts` | CLI interface |
72
+ | `src/core/orchestrator.ts` | Analysis coordination |
73
+ | `src/core/layers/` | Analysis layers |
74
+
75
+ ## MCP Tools
76
+
77
+ | Tool | Purpose | Cost |
78
+ |------|---------|------|
79
+ | `analyze_repo` | Full analysis with expandable sections | Varies |
80
+ | `expand_section` | Drill into specific sections | Low |
81
+ | `find_patterns` | Pattern detection | Medium |
82
+ | `trace_dataflow` | Data flow tracing | Medium |
83
+ | `get_analysis_capabilities` | List capabilities | None |
84
+
85
+ ## Analysis Depth
86
+
87
+ | Depth | What It Does | LLM Cost |
88
+ |-------|--------------|----------|
89
+ | `surface` | File enumeration, languages, entry points | ~0 |
90
+ | `standard` | + structural analysis with Tree-sitter | Low |
91
+ | `deep` | + semantic analysis with Gemini | High |
92
+
93
+ ## Adding Components
94
+
95
+ ### Adding a New MCP Tool
96
+
97
+ 1. Create `src/mcp/tools/your-tool.ts` (schema + execute)
98
+ 2. Export from `src/mcp/tools/index.ts`
99
+ 3. Register in `src/mcp/server.ts`
100
+ 4. Add CLI command in `src/cli/index.ts` (optional)
101
+ 5. `pnpm build`
102
+
103
+ ### Adding an Agent
104
+
105
+ 1. Create `agents/[category]/your-agent.md`
106
+ 2. Use YAML frontmatter: name, description
107
+ 3. Include examples in description
108
+ 4. Update plugin.json description count
109
+
110
+ ### Adding a Command
111
+
112
+ 1. Create `commands/your-command.md`
113
+ 2. Set `user-invocable: true` in frontmatter
114
+ 3. Document usage, examples, workflow
115
+ 4. Update plugin.json description count
116
+
117
+ ### Adding a Skill
118
+
119
+ 1. Create `skills/your-skill/SKILL.md`
120
+ 2. Add references/ for detailed docs
121
+ 3. Keep SKILL.md under 500 lines
122
+ 4. Update plugin.json description count
123
+
124
+ ## Environment
125
+
126
+ ```bash
127
+ GEMINI_API_KEY=... # Required for semantic analysis
128
+ ```
129
+
130
+ ## Key Learnings
131
+
132
+ _This section captures learnings as we work on this repository._
133
+
134
+ ### 2026-01-28: Source name extraction for GitHub URLs
135
+
136
+ When analyzing GitHub repos, temp clone directory name (cba-XXXXX) was shown instead of repo name. Fixed by extracting owner/repo from GitHub URLs before resolving to local path and passing `sourceName` through analysis chain.
137
+
138
+ **Pattern:** Preserve user-facing identifiers separately from internal paths.
139
+
140
+ ### 2026-01-28: Property name consistency between types and usage
141
+
142
+ Multiple bugs from accessing wrong property names (l.name vs l.language, totalFiles vs fileCount).
143
+
144
+ **Pattern:** When adding new types, grep for all usages of old patterns and update together.
145
+
146
+ ### 2026-01-28: Plugin architecture for agentic development
147
+
148
+ Adopted compound-engineering patterns: agents for specialized tasks, commands for user actions, skills for context-loaded guidance. Makes the repo self-documenting for Claude.
149
+
150
+ **Pattern:** Structure repos as plugins even for MCP servers - the documentation patterns apply.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 jkcorrea
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,252 @@
1
+ # Codebase Analyzer MCP
2
+
3
+ [![Claude Plugin](https://img.shields.io/badge/Claude-Plugin-blueviolet)](https://github.com/jkcorrea/codebase-analyzer-mcp)
4
+ [![npm](https://img.shields.io/npm/v/codebase-analyzer-mcp)](https://www.npmjs.com/package/codebase-analyzer-mcp)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+
7
+ Multi-layer codebase analysis with Gemini AI. Both an MCP server for Claude and a standalone CLI.
8
+
9
+ **Features:**
10
+ - Progressive disclosure - start cheap, drill down as needed
11
+ - Tree-sitter structural analysis (no LLM cost)
12
+ - Gemini semantic analysis (opt-in)
13
+ - Pattern detection, dataflow tracing
14
+ - Agent-optimized output
15
+ - **Standalone binary - no Node/Bun required**
16
+
17
+ ## Installation
18
+
19
+ ### Standalone Binary (Recommended)
20
+
21
+ Download the binary for your platform from [Releases](https://github.com/jkcorrea/codebase-analyzer-mcp/releases):
22
+
23
+ ```bash
24
+ # macOS (Apple Silicon)
25
+ curl -L https://github.com/jkcorrea/codebase-analyzer-mcp/releases/latest/download/cba-macos-arm64 -o cba
26
+ chmod +x cba
27
+ sudo mv cba /usr/local/bin/
28
+
29
+ # macOS (Intel)
30
+ curl -L https://github.com/jkcorrea/codebase-analyzer-mcp/releases/latest/download/cba-macos-x64 -o cba
31
+ chmod +x cba
32
+ sudo mv cba /usr/local/bin/
33
+
34
+ # Linux (x64)
35
+ curl -L https://github.com/jkcorrea/codebase-analyzer-mcp/releases/latest/download/cba-linux-x64 -o cba
36
+ chmod +x cba
37
+ sudo mv cba /usr/local/bin/
38
+
39
+ # Linux (ARM64)
40
+ curl -L https://github.com/jkcorrea/codebase-analyzer-mcp/releases/latest/download/cba-linux-arm64 -o cba
41
+ chmod +x cba
42
+ sudo mv cba /usr/local/bin/
43
+ ```
44
+
45
+ ### npm
46
+
47
+ ```bash
48
+ npm install -g codebase-analyzer-mcp
49
+ ```
50
+
51
+ ### From Source (with Bun)
52
+
53
+ ```bash
54
+ git clone https://github.com/jkcorrea/codebase-analyzer-mcp.git
55
+ cd codebase-analyzer-mcp
56
+ bun install && bun run build
57
+ ```
58
+
59
+ ## Configuration
60
+
61
+ Set your Gemini API key (required for semantic analysis):
62
+
63
+ ```bash
64
+ export GEMINI_API_KEY=your_api_key_here
65
+ ```
66
+
67
+ Get a key at https://aistudio.google.com/apikey
68
+
69
+ ## CLI Usage
70
+
71
+ ```bash
72
+ # Quick overview (surface depth - fast, free)
73
+ cba analyze . -d surface
74
+
75
+ # Standard analysis (includes structural)
76
+ cba analyze .
77
+
78
+ # Deep analysis with semantics (uses Gemini)
79
+ cba analyze . -d deep -s
80
+
81
+ # Analyze GitHub repo
82
+ cba analyze https://github.com/user/repo
83
+
84
+ # Focus on specific areas
85
+ cba analyze . --focus src/api
86
+
87
+ # Pattern detection
88
+ cba patterns .
89
+ cba patterns . --types singleton,factory,repository
90
+
91
+ # Data flow tracing
92
+ cba dataflow . "user login"
93
+ cba dataflow . "payment" --to database
94
+
95
+ # Show capabilities
96
+ cba capabilities
97
+ ```
98
+
99
+ ### Analysis Depths
100
+
101
+ | Depth | Speed | LLM Cost | Includes |
102
+ |-------|-------|----------|----------|
103
+ | `surface` | Fast | ~0 | Files, languages, entry points, modules |
104
+ | `standard` | Medium | Low | + symbols, imports, complexity metrics |
105
+ | `deep` | Slow | High | + semantic analysis, architecture insights |
106
+
107
+ ## MCP Server Usage
108
+
109
+ Add to Claude Code settings (`~/.claude/settings.json`):
110
+
111
+ ### Using standalone binary (recommended)
112
+
113
+ ```json
114
+ {
115
+ "mcpServers": {
116
+ "codebase-analyzer": {
117
+ "command": "cba",
118
+ "args": ["--mcp"],
119
+ "env": {
120
+ "GEMINI_API_KEY": "your_api_key"
121
+ }
122
+ }
123
+ }
124
+ }
125
+ ```
126
+
127
+ ### Using npx (no install)
128
+
129
+ ```json
130
+ {
131
+ "mcpServers": {
132
+ "codebase-analyzer": {
133
+ "command": "npx",
134
+ "args": ["-y", "codebase-analyzer-mcp", "--mcp"],
135
+ "env": {
136
+ "GEMINI_API_KEY": "your_api_key"
137
+ }
138
+ }
139
+ }
140
+ }
141
+ ```
142
+
143
+ ### Using global npm install
144
+
145
+ ```bash
146
+ npm install -g codebase-analyzer-mcp
147
+ ```
148
+
149
+ ```json
150
+ {
151
+ "mcpServers": {
152
+ "codebase-analyzer": {
153
+ "command": "cba",
154
+ "args": ["--mcp"],
155
+ "env": {
156
+ "GEMINI_API_KEY": "your_api_key"
157
+ }
158
+ }
159
+ }
160
+ }
161
+ ```
162
+
163
+ ### MCP Tools
164
+
165
+ | Tool | Description |
166
+ |------|-------------|
167
+ | `analyze_repo` | Full analysis with progressive disclosure |
168
+ | `expand_section` | Drill into specific sections |
169
+ | `find_patterns` | Detect design/architecture patterns |
170
+ | `trace_dataflow` | Trace data flow through the system |
171
+ | `get_analysis_capabilities` | List available options |
172
+
173
+ ## Output Structure
174
+
175
+ ```json
176
+ {
177
+ "analysisId": "analysis_xxx",
178
+ "repositoryMap": {
179
+ "name": "repo-name",
180
+ "languages": [...],
181
+ "fileCount": 42,
182
+ "entryPoints": [...]
183
+ },
184
+ "summary": {
185
+ "architectureType": "serverless",
186
+ "primaryPatterns": ["repository", "factory"],
187
+ "complexity": "medium"
188
+ },
189
+ "sections": [
190
+ {
191
+ "id": "module_src_api",
192
+ "title": "API Module",
193
+ "summary": "...",
194
+ "canExpand": true,
195
+ "expansionCost": { "detail": 500, "full": 2000 }
196
+ }
197
+ ],
198
+ "forAgent": {
199
+ "quickSummary": "...",
200
+ "keyInsights": [...],
201
+ "suggestedNextSteps": [...]
202
+ }
203
+ }
204
+ ```
205
+
206
+ ## Claude Plugin
207
+
208
+ This package also works as a Claude Code plugin with agents, commands, and skills.
209
+
210
+ ### Install as Plugin
211
+
212
+ ```bash
213
+ # Direct install
214
+ claude /plugin install https://github.com/jkcorrea/codebase-analyzer-mcp
215
+
216
+ # Or add as marketplace first (if you want to browse/manage multiple plugins)
217
+ claude /plugin marketplace add https://github.com/jkcorrea/codebase-analyzer-mcp
218
+ claude /plugin install codebase-analyzer
219
+ ```
220
+
221
+ ### Plugin Commands
222
+
223
+ | Command | Description |
224
+ |---------|-------------|
225
+ | `/analyze` | Analyze a codebase |
226
+ | `/patterns` | Find design patterns |
227
+ | `/trace` | Trace data flow |
228
+ | `/explore` | Quick exploration |
229
+ | `/compare` | Compare repositories |
230
+
231
+ ### Plugin Agents
232
+
233
+ | Agent | Purpose |
234
+ |-------|---------|
235
+ | `architecture-analyzer` | Full architecture analysis |
236
+ | `pattern-detective` | Pattern detection |
237
+ | `dataflow-tracer` | Data flow tracing |
238
+ | `codebase-explorer` | Quick exploration |
239
+
240
+ ## Development
241
+
242
+ ```bash
243
+ bun install
244
+ bun run dev # Watch mode
245
+ bun run build # Build TS + binary
246
+ bun run build:bin:all # Build all platform binaries
247
+ bun run cba ... # Run CLI
248
+ ```
249
+
250
+ ## License
251
+
252
+ MIT