@autodev/codebase 0.0.7 → 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.
package/README.md CHANGED
@@ -1,17 +1,20 @@
1
1
  # @autodev/codebase
2
2
 
3
- <div align="center">
3
+ <p align="center">
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/@autodev/codebase)](https://www.npmjs.com/package/@autodev/codebase)
6
6
  [![GitHub stars](https://img.shields.io/github/stars/anrgct/autodev-codebase)](https://github.com/anrgct/autodev-codebase)
7
7
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
8
8
 
9
- </div>
9
+ </p>
10
+
11
+ A vector embedding-based code semantic search tool with MCP server and multi-model integration. Can be used as a pure CLI tool. Supports Ollama for fully local embedding and reranking, enabling complete offline operation and privacy protection for your code repository.
10
12
 
11
13
  ```sh
14
+ # Semantic code search - Find code by meaning, not just keywords
12
15
  ╭─ ~/workspace/autodev-codebase
13
- ╰─❯ codebase --demo --search="user manage"
14
- Found 3 results in 2 files for: "user manage"
16
+ ╰─❯ codebase search "user manage" --demo
17
+ Found 20 results in 5 files for: "user manage"
15
18
 
16
19
  ==================================================
17
20
  File: "hello.js"
@@ -31,36 +34,44 @@ class UserManager {
31
34
  return this.users;
32
35
  }
33
36
  }
37
+ ……
34
38
 
35
- ==================================================
36
- File: "README.md" | 2 snippets
37
- ==================================================
38
- < md_h1 Demo Project > md_h2 Usage > md_h3 JavaScript Functions > (L16-20)
39
- ### JavaScript Functions
40
-
41
- - greetUser(name) - Greets a user by name
42
- - UserManager - Class for managing user data
43
-
44
- ─────
45
- < md_h1 Demo Project > md_h2 Search Examples > (L27-38)
46
- ## Search Examples
47
-
48
- Try searching for:
49
- - "greet user"
50
- - "process data"
51
- - "user management"
52
- - "batch processing"
53
- - "YOLO model"
54
- - "computer vision"
55
- - "object detection"
56
- - "model training"
39
+ # Call graph analysis - Trace function call relationships and execution paths
40
+ ╭─ ~/workspace/autodev-codebase
41
+ ╰─❯ codebase call --demo --query="app,addUser"
42
+ Connections between app, addUser:
43
+
44
+ Found 2 matching node(s):
45
+ - demo/app:L1-29
46
+ - demo/hello.UserManager.addUser:L12-15
57
47
 
48
+ Direct connections:
49
+ - demo/app:L1-29 → demo/hello.UserManager.addUser:L12-15
50
+
51
+ Chains found:
52
+ - demo/app:L1-29 → demo/hello.UserManager.addUser:L12-15
53
+
54
+ # Code outline with AI summaries - Understand code structure at a glance
55
+ ╭─ ~/workspace/autodev-codebase
56
+ ╰─❯ codebase outline 'hello.js' --demo --summarize
57
+ # hello.js (23 lines)
58
+ └─ Defines a greeting function that logs a personalized hello message and returns a welcome string. Implements a UserManager class managing an array of users with methods to add users and retrieve the current user list. Exports both components for external use.
59
+
60
+ 2--5 | function greetUser
61
+ └─ Implements user greeting logic by logging a personalized hello message and returning a welcome message
62
+
63
+ 7--20 | class UserManager
64
+ └─ Manages user data with methods to add users to a list and retrieve all stored users
65
+
66
+ 12--15 | method addUser
67
+ └─ Adds a user to the users array and logs a confirmation message with the user's name.
58
68
  ```
59
- A vector embedding-based code semantic search tool with MCP server and multi-model integration. Can be used as a pure CLI tool. Supports Ollama for fully local embedding and reranking, enabling complete offline operation and privacy protection for your code repository.
69
+
60
70
 
61
71
  ## 🚀 Features
62
72
 
63
73
  - **🔍 Semantic Code Search**: Vector-based search using advanced embedding models
74
+ - **🔗 Call Graph Analysis**: Trace function call relationships and execution paths
64
75
  - **🌐 MCP Server**: HTTP-based MCP server with SSE and stdio adapters
65
76
  - **💻 Pure CLI Tool**: Standalone command-line interface without GUI dependencies
66
77
  - **⚙️ Layered Configuration**: CLI, project, and global config management
@@ -71,6 +82,7 @@ A vector embedding-based code semantic search tool with MCP server and multi-mod
71
82
  - **📊 Real-time Watching**: Automatic index updates
72
83
  - **⚡ Batch Processing**: Efficient parallel processing
73
84
  - **📝 Code Outline Extraction**: Generate structured code outlines with AI summaries
85
+ - **💨 Dependency Analysis Cache**: Intelligent caching for 10-50x faster re-analysis
74
86
 
75
87
  ## 📦 Installation
76
88
 
@@ -89,7 +101,7 @@ docker run -d -p 6333:6333 -p 6334:6334 --name qdrant qdrant/qdrant
89
101
  ### 3. Install
90
102
  ```bash
91
103
  npm install -g @autodev/codebase
92
- codebase --set-config embedderProvider=ollama,embedderModelId=nomic-embed-text
104
+ codebase config --set embedderProvider=ollama,embedderModelId=nomic-embed-text
93
105
  ```
94
106
 
95
107
  ## 🛠️ Quick Start
@@ -99,108 +111,125 @@ codebase --set-config embedderProvider=ollama,embedderModelId=nomic-embed-text
99
111
  # Creates a demo directory in current working directory for testing
100
112
 
101
113
  # Index & search
102
- codebase --demo --index
103
- codebase --demo --search="user greet"
114
+ codebase index --demo
115
+ codebase search "user greet" --demo
116
+
117
+ # Call graph analysis
118
+ codebase call --demo --query="app,addUser"
104
119
 
105
120
  # MCP server
106
- codebase --demo --serve
121
+ codebase index --serve --demo
107
122
  ```
108
123
 
109
124
  ## 📋 Commands
110
125
 
111
- ### 📝 AI-Powered Code Outlines
126
+ ### 📝 Code Outlines
127
+ ```bash
128
+ # Extract code structure (functions, classes, methods)
129
+ codebase outline "src/**/*.ts"
112
130
 
113
- Generate intelligent code summaries with one command:
131
+ # Generate code structure with AI summaries
132
+ codebase outline "src/**/*.ts" --summarize
114
133
 
115
- ```bash
116
- codebase --outline "src/**/*.ts" --summarize
117
- ```
134
+ # View only file-level summaries
135
+ codebase outline "src/**/*.ts" --summarize --title
118
136
 
119
- **Output Example:**
137
+ # Clear summary cache
138
+ codebase outline --clear-summarize-cache
120
139
  ```
121
- # src/cli.ts (1902 lines)
122
- └─ Implements a simplified CLI for @autodev/codebase using Node.js native parseArgs.
123
- Manages codebase indexing, searching, and MCP server operations.
124
140
 
125
- 27--35 | function initGlobalLogger
126
- └─ Initializes a global logger instance with specified log level and timestamps.
141
+ ### 🔗 Call Graph Analysis
142
+ ```bash
143
+ # Analyze function call relationships
144
+ codebase call --query="functionA,functionB"
127
145
 
128
- 45--54 | interface SearchResult
129
- └─ Defines the structure for search result payloads, including file path, code chunk,
130
- and relevance score.
146
+ # Analyze specific directory
147
+ codebase call src/commands
131
148
 
132
- ... (full outline with AI summaries)
133
- ```
149
+ # Export analysis results
150
+ codebase call --output=graph.json
134
151
 
135
- **Benefits:**
136
- - 🧠 **Understand code fast** - Get function-level summaries without reading every line
137
- - 💾 **Smart caching** - Only summarizes changed code blocks
138
- - 🌐 **Multi-language** - English/Chinese summaries supported
139
- - ⚡ **Batch processing** - Efficiently handles large codebases
152
+ # Open interactive graph viewer
153
+ codebase call --open
140
154
 
141
- **Quick Setup:**
142
- ```bash
143
- # Configure Ollama (recommended for free, local AI)
144
- codebase --set-config summarizerProvider=ollama,summarizerOllamaModelId=qwen3-vl:4b-instruct
155
+ # Set analysis depth
156
+ codebase call --query="main" --depth=3
145
157
 
146
- # Or use DeepSeek (cost-effective API)
147
- codebase --set-config summarizerProvider=openai-compatible,summarizerOpenAiCompatibleBaseUrl=https://api.deepseek.com/v1,summarizerOpenAiCompatibleModelId=deepseek-chat,summarizerOpenAiCompatibleApiKey=sk-your-key
158
+ # Specify workspace path
159
+ codebase call --path=/my/project
148
160
  ```
149
161
 
150
-
151
- ### Indexing & Search
162
+ **Query Patterns:**
163
+ - **Exact match**: `--query="functionName"` or `--query="ClassName.methodName"`
164
+ - **Wildcards**: `*` (any characters), `?` (single character)
165
+ - Examples: `--query="get*"`, `--query="*User*"`, `--query="*.*.get*"`
166
+ - **Single pattern**: `--query="main"` - Shows dependency tree (what it calls, who calls it)
167
+ - Use `--depth` to control tree depth (default: 10)
168
+ - **Multiple patterns**: `--query="main,helper"` - Analyzes connections between functions
169
+ - Connection search depth is fixed at 10 (--depth is ignored)
170
+
171
+ **Supported Languages:**
172
+ - **TypeScript/JavaScript** (.ts, .tsx, .js, .jsx)
173
+ - **Python** (.py)
174
+ - **Java** (.java)
175
+ - **C/C++** (.c, .h, .cpp, .cc, .cxx, .hpp, .hxx, .c++)
176
+ - **C#** (.cs)
177
+ - **Rust** (.rs)
178
+ - **Go** (.go)
179
+
180
+ ### 🔍 Indexing & Search
152
181
  ```bash
153
182
  # Index the codebase
154
- codebase --index --path=/my/project --force
183
+ codebase index --path=/my/project --force
155
184
 
156
185
  # Search with filters
157
- codebase --search="error handling" --path-filters="src/**/*.ts"
186
+ codebase search "error handling" --path-filters="src/**/*.ts"
158
187
 
159
188
  # Search with custom limit and minimum score
160
- codebase --search="authentication" --limit=20 --min-score=0.7
161
- codebase --search="API" -l 30 -S 0.5
189
+ codebase search "authentication" --limit=20 --min-score=0.7
190
+ codebase search "API" -l 30 -S 0.5
162
191
 
163
192
  # Search in JSON format
164
- codebase --search="authentication" --json
193
+ codebase search "authentication" --json
165
194
 
166
195
  # Clear index data
167
- codebase --clear --path=/my/project
196
+ codebase index --clear-cache --path=/my/project
168
197
  ```
169
198
 
170
- ### MCP Server
199
+ ### 🌐 MCP Server
171
200
  ```bash
172
201
  # HTTP mode (recommended)
173
- codebase --serve --port=3001 --path=/my/project
202
+ codebase index --serve --port=3001 --path=/my/project
174
203
 
175
204
  # Stdio adapter
176
- codebase --stdio-adapter --server-url=http://localhost:3001/mcp
205
+ codebase stdio --server-url=http://localhost:3001/mcp
177
206
  ```
178
207
 
179
- ### Configuration
208
+ ### ⚙️ Configuration
180
209
  ```bash
181
210
  # View config
182
- codebase --get-config
183
- codebase --get-config embedderProvider --json
211
+ codebase config --get
212
+ codebase config --get embedderProvider --json
184
213
 
185
214
  # Set config
186
- codebase --set-config embedderProvider=ollama,embedderModelId=nomic-embed-text
187
- codebase --set-config --global qdrantUrl=http://localhost:6333
215
+ codebase config --set embedderProvider=ollama,embedderModelId=nomic-embed-text
216
+ codebase config --set --global qdrantUrl=http://localhost:6333
188
217
  ```
189
218
 
190
- ### Advanced Features
219
+ ### 🚀 Advanced Features
191
220
 
192
221
  #### 🔍 LLM-Powered Search Reranking
193
222
  Enable LLM reranking to dramatically improve search relevance:
194
223
 
195
224
  ```bash
196
225
  # Enable reranking with Ollama (recommended)
197
- codebase --set-config rerankerEnabled=true,rerankerProvider=ollama,rerankerOllamaModelId=qwen3-vl:4b-instruct
226
+ codebase config --set rerankerEnabled=true,rerankerProvider=ollama,rerankerOllamaModelId=qwen3-vl:4b-instruct
198
227
 
199
228
  # Or use OpenAI-compatible providers
200
- codebase --set-config rerankerEnabled=true,rerankerProvider=openai-compatible,rerankerOpenAiCompatibleModelId=deepseek-chat
229
+ codebase config --set rerankerEnabled=true,rerankerProvider=openai-compatible,rerankerOpenAiCompatibleModelId=deepseek-chat
201
230
 
202
231
  # Search with automatic reranking
203
- codebase --search="user authentication" # Results are automatically reranked by LLM
232
+ codebase search "user authentication" # Results are automatically reranked by LLM
204
233
  ```
205
234
 
206
235
  **Benefits:**
@@ -212,36 +241,24 @@ codebase --search="user authentication" # Results are automatically reranked by
212
241
  #### Path Filtering & Export
213
242
  ```bash
214
243
  # Path filtering with brace expansion and exclusions
215
- codebase --search="API" --path-filters="src/**/*.ts,lib/**/*.js"
216
- codebase --search="utils" --path-filters="{src,test}/**/*.ts"
244
+ codebase search "API" --path-filters="src/**/*.ts,lib/**/*.js"
245
+ codebase search "utils" --path-filters="{src,test}/**/*.ts"
217
246
 
218
247
  # Export results in JSON format for scripts
219
- codebase --search="auth" --json
248
+ codebase search "auth" --json
220
249
  ```
221
250
 
222
- #### 📝 AI-Powered Code Outlines
223
- Generate intelligent code summaries and outlines:
251
+ #### Path Filtering & Export
224
252
 
225
253
  ```bash
226
- # Extract code structure
227
- codebase --outline src/index.ts
228
-
229
- # With AI summaries (recommended)
230
- codebase --outline "src/**/*.ts" --summarize
231
-
232
- # Preview before processing
233
- codebase --outline "src/**/*.ts" --dry-run
254
+ # Path filtering with brace expansion and exclusions
255
+ codebase search "API" --path-filters="src/**/*.ts,lib/**/*.js"
256
+ codebase search "utils" --path-filters="{src,test}/**/*.ts"
234
257
 
235
- # Clear cache and regenerate
236
- codebase --outline src/index.ts --summarize --clear-summarize-cache
258
+ # Export results in JSON format for scripts
259
+ codebase search "auth" --json
237
260
  ```
238
261
 
239
- **Key Benefits:**
240
- - 🎯 **Function-level summaries**: Understand code purpose at a glance
241
- - 💾 **Smart caching**: Avoid redundant LLM calls
242
- - 🌐 **Multi-language**: English / Chinese support
243
- - ⚡ **Batch processing**: Efficiently handle large codebases
244
-
245
262
  ## ⚙️ Configuration
246
263
 
247
264
  ### Config Layers (Priority Order)
@@ -250,7 +267,7 @@ codebase --outline src/index.ts --summarize --clear-summarize-cache
250
267
  3. **Global Config** - `~/.autodev-cache/autodev-config.json`
251
268
  4. **Built-in Defaults** - Fallback values
252
269
 
253
- **Note:** CLI arguments provide runtime override for paths, logging, and operational behavior. For persistent configuration (embedderProvider, API keys, search parameters), use `--set-config` to save to config files.
270
+ **Note:** CLI arguments provide runtime override for paths, logging, and operational behavior. For persistent configuration (embedderProvider, API keys, search parameters), use `config --set` to save to config files.
254
271
 
255
272
  ### Common Config Examples
256
273
 
@@ -295,36 +312,42 @@ codebase --outline src/index.ts --summarize --clear-summarize-cache
295
312
  | **Summarizer** | `summarizerProvider`, `summarizerLanguage`, `summarizerBatchSize` | AI summary generation |
296
313
 
297
314
  **Key CLI Arguments:**
298
- - `--serve` / `--index` / `--search` - Core operations
299
- - `--outline <pattern>` - Extract code outlines (supports glob patterns)
315
+ - `index` - Index the codebase
316
+ - `search <query>` - Search the codebase (required positional argument)
317
+ - `outline <pattern>` - Extract code outlines (supports glob patterns)
318
+ - `call` - Analyze function call relationships and dependency graphs
319
+ - `stdio` - Start stdio adapter for MCP
320
+ - `config` - Manage configuration (use with --get or --set)
321
+ - `--serve` - Start MCP HTTP server (use with `index` command)
300
322
  - `--summarize` - Generate AI summaries for code outlines
301
323
  - `--dry-run` - Preview operations before execution
302
324
  - `--title` - Show only file-level summaries
303
325
  - `--clear-summarize-cache` - Clear all summary caches
304
- - `--get-config` / `--set-config` - Configuration management
305
326
  - `--path`, `--demo`, `--force` - Common options
306
327
  - `--limit` / `-l <number>` - Maximum number of search results (default: from config, max 50)
307
328
  - `--min-score` / `-S <number>` - Minimum similarity score for search results (0-1, default: from config)
329
+ - `--query <patterns>` - Query patterns for call graph analysis (comma-separated)
330
+ - `--output <file>` - Export analysis results to JSON file
331
+ - `--open` - Open interactive graph viewer
332
+ - `--depth <number>` - Set analysis depth for call graphs
308
333
  - `--help` - Show all available options
309
334
 
310
- For complete CLI reference, see [CONFIG.md](CONFIG.md).
311
-
312
335
  **Configuration Commands:**
313
336
  ```bash
314
337
  # View config
315
- codebase --get-config
316
- codebase --get-config --json
338
+ codebase config --get
339
+ codebase config --get --json
317
340
 
318
341
  # Set config (saves to file)
319
- codebase --set-config embedderProvider=ollama,embedderModelId=nomic-embed-text
320
- codebase --set-config --global embedderProvider=openai,embedderOpenAiApiKey=sk-xxx
342
+ codebase config --set embedderProvider=ollama,embedderModelId=nomic-embed-text
343
+ codebase config --set --global embedderProvider=openai,embedderOpenAiApiKey=sk-xxx
321
344
 
322
345
  # Use custom config file
323
- codebase --config=/path/to/config.json --get-config
324
- codebase --config=/path/to/config.json --set-config embedderProvider=ollama
346
+ codebase --config=/path/to/config.json config --get
347
+ codebase --config=/path/to/config.json config --set embedderProvider=ollama
325
348
 
326
349
  # Runtime override (paths, logging, etc.)
327
- codebase --index --path=/my/project --log-level=info --force
350
+ codebase index --path=/my/project --log-level=info --force
328
351
  ```
329
352
 
330
353
  For complete configuration reference, see [CONFIG.md](CONFIG.md).
@@ -333,7 +356,7 @@ For complete configuration reference, see [CONFIG.md](CONFIG.md).
333
356
 
334
357
  ### HTTP Streamable Mode (Recommended)
335
358
  ```bash
336
- codebase --serve --port=3001
359
+ codebase index --serve --port=3001
337
360
  ```
338
361
 
339
362
  **IDE Config:**
@@ -350,10 +373,10 @@ codebase --serve --port=3001
350
373
  ### Stdio Adapter
351
374
  ```bash
352
375
  # First start the MCP server in one terminal
353
- codebase --serve --port=3001
376
+ codebase index --serve --port=3001
354
377
 
355
378
  # Then connect via stdio adapter in another terminal (for IDEs that require stdio)
356
- codebase --stdio-adapter --server-url=http://localhost:3001/mcp
379
+ codebase stdio --server-url=http://localhost:3001/mcp
357
380
  ```
358
381
 
359
382
  **IDE Config:**
@@ -362,7 +385,7 @@ codebase --stdio-adapter --server-url=http://localhost:3001/mcp
362
385
  "mcpServers": {
363
386
  "codebase": {
364
387
  "command": "codebase",
365
- "args": ["stdio-adapter", "--server-url=http://localhost:3001/mcp"]
388
+ "args": ["stdio", "--server-url=http://localhost:3001/mcp"]
366
389
  }
367
390
  }
368
391
  }