opencode-codebase-index 0.3.2 → 0.4.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/README.md +17 -2
- package/dist/index.cjs +202 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +202 -10
- package/dist/index.js.map +1 -1
- package/native/codebase-index-native.win32-x64-msvc.node +0 -0
- package/package.json +1 -1
- package/skill/SKILL.md +39 -179
|
Binary file
|
package/package.json
CHANGED
package/skill/SKILL.md
CHANGED
|
@@ -1,206 +1,66 @@
|
|
|
1
|
-
|
|
1
|
+
---
|
|
2
|
+
name: codebase-search
|
|
3
|
+
description: Semantic code search by meaning. Use codebase_peek to find WHERE code is (saves tokens), codebase_search to see actual code. For exact identifiers, use grep instead.
|
|
4
|
+
---
|
|
2
5
|
|
|
3
|
-
|
|
6
|
+
# Codebase Search Skill
|
|
4
7
|
|
|
5
|
-
## When to Use
|
|
8
|
+
## When to Use What
|
|
6
9
|
|
|
7
|
-
| Scenario |
|
|
8
|
-
|
|
9
|
-
|
|
|
10
|
-
|
|
|
10
|
+
| Scenario | Tool | Why |
|
|
11
|
+
|----------|------|-----|
|
|
12
|
+
| Just need file locations | `codebase_peek` | Metadata only, saves ~90% tokens |
|
|
13
|
+
| Need to see actual code | `codebase_search` | Returns full code content |
|
|
14
|
+
| Find duplicates/patterns | `find_similar` | Given code snippet → similar code |
|
|
15
|
+
| Don't know function/class names | `codebase_peek` or `codebase_search` | Natural language → code |
|
|
11
16
|
| Know exact identifier names | `grep` | Faster, more precise |
|
|
12
17
|
| Need ALL occurrences | `grep` | Semantic returns top N only |
|
|
13
|
-
| Unfamiliar codebase exploration | `codebase_search` | Broader conceptual matches |
|
|
14
|
-
|
|
15
|
-
## Hybrid Strategy (Recommended)
|
|
16
|
-
|
|
17
|
-
1. **Discover with semantic**: `codebase_search("authentication flow")` → get candidate files
|
|
18
|
-
2. **Drill down with grep**: `grep "validateToken"` in those files for exact matches
|
|
19
|
-
3. **Use LSP**: For definitions and references once you have the identifier
|
|
20
|
-
|
|
21
|
-
## Available Tools
|
|
22
|
-
|
|
23
|
-
### `codebase_search`
|
|
24
|
-
Find code by describing what it does in natural language.
|
|
25
18
|
|
|
26
|
-
|
|
27
|
-
- "find the user authentication logic"
|
|
28
|
-
- "code that handles database connections"
|
|
29
|
-
- "error handling middleware for HTTP requests"
|
|
30
|
-
- "where is the payment processing"
|
|
19
|
+
## Recommended Workflow
|
|
31
20
|
|
|
32
|
-
**
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
- `chunkType` (optional): Filter by code type
|
|
36
|
-
- `directory` (optional): Filter by directory path
|
|
37
|
-
- `fileType` (optional): Filter by file extension
|
|
38
|
-
- `contextLines` (optional): Extra lines before/after each match
|
|
39
|
-
|
|
40
|
-
**Returns:** Focused list of 5-10 most relevant files/chunks with scores.
|
|
41
|
-
|
|
42
|
-
### `index_codebase`
|
|
43
|
-
Create or update the semantic index. Required before first search.
|
|
44
|
-
|
|
45
|
-
**Parameters:**
|
|
46
|
-
- `force` (optional): Reindex from scratch (default: false)
|
|
47
|
-
- `estimateOnly` (optional): Show cost estimate without indexing
|
|
48
|
-
- `verbose` (optional): Show skipped files and parse failures
|
|
49
|
-
|
|
50
|
-
**Note:** Incremental indexing is fast (~50ms) when files haven't changed.
|
|
51
|
-
|
|
52
|
-
### `index_status`
|
|
53
|
-
Check if the codebase is indexed and ready for search.
|
|
21
|
+
1. **Locate with peek**: `codebase_peek("authentication flow")` → get file locations
|
|
22
|
+
2. **Read what matters**: `Read` the specific files you need
|
|
23
|
+
3. **Drill down with grep**: `grep "validateToken"` for exact matches
|
|
54
24
|
|
|
55
|
-
|
|
56
|
-
Remove stale entries from deleted files and orphaned embeddings.
|
|
25
|
+
## Tools
|
|
57
26
|
|
|
58
|
-
### `
|
|
59
|
-
|
|
60
|
-
Requires `debug.enabled` and `debug.metrics` to be `true` in config.
|
|
27
|
+
### `codebase_peek`
|
|
28
|
+
Find WHERE code is. Returns metadata only (file, line, name, type).
|
|
61
29
|
|
|
62
|
-
**Shows:** Files indexed, chunks created, cache hit rate, search timing breakdown, GC stats, embedding API call stats.
|
|
63
|
-
|
|
64
|
-
### `index_logs`
|
|
65
|
-
Get recent debug logs with optional filtering.
|
|
66
|
-
Requires `debug.enabled` to be `true` in config.
|
|
67
|
-
|
|
68
|
-
**Parameters:**
|
|
69
|
-
- `limit` (optional): Maximum log entries (default: 20)
|
|
70
|
-
- `category` (optional): Filter by `search`, `embedding`, `cache`, `gc`, `branch`, `general`
|
|
71
|
-
- `level` (optional): Filter by `error`, `warn`, `info`, `debug`
|
|
72
|
-
|
|
73
|
-
## Search Filters
|
|
74
|
-
|
|
75
|
-
### Filter by Chunk Type (`chunkType`)
|
|
76
|
-
|
|
77
|
-
Narrow results to specific code constructs:
|
|
78
|
-
|
|
79
|
-
| Value | Finds |
|
|
80
|
-
|-------|-------|
|
|
81
|
-
| `function` | Functions, arrow functions |
|
|
82
|
-
| `class` | Class definitions |
|
|
83
|
-
| `method` | Class methods |
|
|
84
|
-
| `interface` | TypeScript interfaces |
|
|
85
|
-
| `type` | Type aliases |
|
|
86
|
-
| `enum` | Enumerations |
|
|
87
|
-
| `struct` | Rust/Go structs |
|
|
88
|
-
| `impl` | Rust impl blocks |
|
|
89
|
-
| `trait` | Rust traits |
|
|
90
|
-
| `module` | Module definitions |
|
|
91
|
-
|
|
92
|
-
**Examples:**
|
|
93
30
|
```
|
|
94
|
-
|
|
95
|
-
codebase_search(query="data models", chunkType="interface")
|
|
96
|
-
codebase_search(query="user entity", chunkType="class")
|
|
31
|
+
codebase_peek(query="validation logic", chunkType="function", directory="src/utils")
|
|
97
32
|
```
|
|
98
33
|
|
|
99
|
-
###
|
|
100
|
-
|
|
101
|
-
Scope search to specific paths:
|
|
102
|
-
|
|
103
|
-
```
|
|
104
|
-
codebase_search(query="API routes", directory="src/api")
|
|
105
|
-
codebase_search(query="test helpers", directory="tests")
|
|
106
|
-
codebase_search(query="database queries", directory="src/db")
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
### Filter by File Type (`fileType`)
|
|
110
|
-
|
|
111
|
-
Limit to specific languages:
|
|
34
|
+
### `codebase_search`
|
|
35
|
+
Find code with full content. Use when you need to see implementation.
|
|
112
36
|
|
|
113
37
|
```
|
|
114
|
-
codebase_search(query="
|
|
115
|
-
codebase_search(query="build scripts", fileType="py")
|
|
116
|
-
codebase_search(query="data structures", fileType="rs")
|
|
38
|
+
codebase_search(query="error handling middleware", fileType="ts", contextLines=2)
|
|
117
39
|
```
|
|
118
40
|
|
|
119
|
-
###
|
|
120
|
-
|
|
121
|
-
Filters can be combined for precise results:
|
|
41
|
+
### `find_similar`
|
|
42
|
+
Find code similar to a given snippet. Use for duplicate detection, pattern discovery, refactoring.
|
|
122
43
|
|
|
123
44
|
```
|
|
124
|
-
|
|
125
|
-
query="validation",
|
|
126
|
-
chunkType="function",
|
|
127
|
-
directory="src/utils",
|
|
128
|
-
fileType="ts"
|
|
129
|
-
)
|
|
45
|
+
find_similar(code="function validate(input) { return input.length > 0; }", excludeFile="src/current.ts")
|
|
130
46
|
```
|
|
131
47
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
The `hybridWeight` config option (0.0-1.0) balances semantic vs keyword search:
|
|
135
|
-
|
|
136
|
-
| Value | Behavior | Best For |
|
|
137
|
-
|-------|----------|----------|
|
|
138
|
-
| `0.0` | Pure semantic | Conceptual queries, unfamiliar code |
|
|
139
|
-
| `0.5` | Balanced (default) | General use |
|
|
140
|
-
| `1.0` | Pure keyword (BM25) | When you know specific terms |
|
|
141
|
-
|
|
142
|
-
Configure in `.opencode/codebase-index.json`:
|
|
143
|
-
```json
|
|
144
|
-
{
|
|
145
|
-
"search": {
|
|
146
|
-
"hybridWeight": 0.3
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
```
|
|
48
|
+
### `index_codebase`
|
|
49
|
+
Create/update index. Required before first search. Incremental (~50ms when unchanged).
|
|
150
50
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
- Higher (0.6-0.8): When query contains specific identifiers
|
|
51
|
+
### `index_status`
|
|
52
|
+
Check if indexed and ready.
|
|
154
53
|
|
|
155
|
-
## Query
|
|
54
|
+
## Query Tips
|
|
156
55
|
|
|
157
56
|
**Describe behavior, not syntax:**
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
Bad: "hashPassword" (use grep for exact names)
|
|
161
|
-
|
|
162
|
-
Good: "middleware that checks JWT tokens"
|
|
163
|
-
Bad: "jwt" (too vague, use grep for keyword)
|
|
164
|
-
|
|
165
|
-
Good: "error handling for unauthorized requests"
|
|
166
|
-
Bad: "401" (literal keyword, use grep)
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
## Workflow Examples
|
|
57
|
+
- Good: `"function that hashes passwords securely"`
|
|
58
|
+
- Bad: `"hashPassword"` (use grep for exact names)
|
|
170
59
|
|
|
171
|
-
|
|
172
|
-
```
|
|
173
|
-
1. index_status → check if indexed
|
|
174
|
-
2. index_codebase → if needed
|
|
175
|
-
3. codebase_search("how does authentication work") → get overview
|
|
176
|
-
4. codebase_search("session management") → drill into specifics
|
|
177
|
-
5. grep "SessionStore" → once you know the class name
|
|
178
|
-
```
|
|
60
|
+
## Filters
|
|
179
61
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
### Finding implementation for a feature
|
|
188
|
-
```
|
|
189
|
-
1. codebase_search("image upload and processing") → find relevant files
|
|
190
|
-
2. Read top results to understand structure
|
|
191
|
-
3. grep "uploadImage" → find exact function
|
|
192
|
-
4. LSP goto_definition → navigate to implementation
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
### Debugging unknown code path
|
|
196
|
-
```
|
|
197
|
-
1. codebase_search("error handling for payment failures") → find error handlers
|
|
198
|
-
2. codebase_search("retry logic for API calls") → find retry mechanisms
|
|
199
|
-
3. grep "PaymentError" → find specific error class
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
### Finding TypeScript interfaces
|
|
203
|
-
```
|
|
204
|
-
1. codebase_search(query="user data", chunkType="interface") → find User interfaces
|
|
205
|
-
2. codebase_search(query="API response", chunkType="type") → find response types
|
|
206
|
-
```
|
|
62
|
+
| Filter | Example |
|
|
63
|
+
|--------|---------|
|
|
64
|
+
| `chunkType` | `function`, `class`, `interface`, `type`, `method` |
|
|
65
|
+
| `directory` | `"src/api"`, `"tests"` |
|
|
66
|
+
| `fileType` | `"ts"`, `"py"`, `"rs"` |
|