opencode-codebase-index 0.3.0 → 0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-codebase-index",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Semantic codebase indexing and search for OpenCode - find code by meaning, not just keywords",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -38,6 +38,7 @@
38
38
  "dev": "tsup --watch",
39
39
  "test": "vitest",
40
40
  "test:run": "vitest run",
41
+ "test:coverage": "vitest run --coverage",
41
42
  "lint": "eslint src/",
42
43
  "typecheck": "tsc --noEmit",
43
44
  "prepublishOnly": "npm run build"
@@ -70,6 +71,7 @@
70
71
  "@napi-rs/cli": "^3.5.1",
71
72
  "@opencode-ai/plugin": "^1.1.21",
72
73
  "@types/node": "^25.0.8",
74
+ "@vitest/coverage-v8": "^4.0.17",
73
75
  "eslint": "^9.0.0",
74
76
  "tsup": "^8.1.0",
75
77
  "typescript": "^5.5.0",
package/skill/SKILL.md CHANGED
@@ -1,191 +1,66 @@
1
- # Codebase Search Skill
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
- Semantic search for finding code by meaning, not just keywords.
6
+ # Codebase Search Skill
4
7
 
5
- ## When to Use Semantic Search vs Grep
8
+ ## When to Use What
6
9
 
7
- | Scenario | Use | Why |
8
- |----------|-----|-----|
9
- | Don't know function/class names | `codebase_search` | Natural language code |
10
- | Concept discovery ("what handles auth?") | `codebase_search` | Finds related code by meaning |
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
- **Best for:**
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
- **Parameters:**
33
- - `query` (required): Natural language description
34
- - `limit` (optional): Maximum results (default: 10)
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
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
39
24
 
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.
25
+ ## Tools
54
26
 
55
- ### `index_health_check`
56
- Remove stale entries from deleted files and orphaned embeddings.
57
-
58
- ## Search Filters
59
-
60
- ### Filter by Chunk Type (`chunkType`)
61
-
62
- Narrow results to specific code constructs:
63
-
64
- | Value | Finds |
65
- |-------|-------|
66
- | `function` | Functions, arrow functions |
67
- | `class` | Class definitions |
68
- | `method` | Class methods |
69
- | `interface` | TypeScript interfaces |
70
- | `type` | Type aliases |
71
- | `enum` | Enumerations |
72
- | `struct` | Rust/Go structs |
73
- | `impl` | Rust impl blocks |
74
- | `trait` | Rust traits |
75
- | `module` | Module definitions |
76
-
77
- **Examples:**
78
- ```
79
- codebase_search(query="validation logic", chunkType="function")
80
- codebase_search(query="data models", chunkType="interface")
81
- codebase_search(query="user entity", chunkType="class")
82
- ```
83
-
84
- ### Filter by Directory (`directory`)
85
-
86
- Scope search to specific paths:
27
+ ### `codebase_peek`
28
+ Find WHERE code is. Returns metadata only (file, line, name, type).
87
29
 
88
30
  ```
89
- codebase_search(query="API routes", directory="src/api")
90
- codebase_search(query="test helpers", directory="tests")
91
- codebase_search(query="database queries", directory="src/db")
31
+ codebase_peek(query="validation logic", chunkType="function", directory="src/utils")
92
32
  ```
93
33
 
94
- ### Filter by File Type (`fileType`)
95
-
96
- Limit to specific languages:
34
+ ### `codebase_search`
35
+ Find code with full content. Use when you need to see implementation.
97
36
 
98
37
  ```
99
- codebase_search(query="config parsing", fileType="ts")
100
- codebase_search(query="build scripts", fileType="py")
101
- codebase_search(query="data structures", fileType="rs")
38
+ codebase_search(query="error handling middleware", fileType="ts", contextLines=2)
102
39
  ```
103
40
 
104
- ### Combining Filters
105
-
106
- 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.
107
43
 
108
44
  ```
109
- codebase_search(
110
- query="validation",
111
- chunkType="function",
112
- directory="src/utils",
113
- fileType="ts"
114
- )
45
+ find_similar(code="function validate(input) { return input.length > 0; }", excludeFile="src/current.ts")
115
46
  ```
116
47
 
117
- ## Hybrid Weight Tuning
118
-
119
- The `hybridWeight` config option (0.0-1.0) balances semantic vs keyword search:
120
-
121
- | Value | Behavior | Best For |
122
- |-------|----------|----------|
123
- | `0.0` | Pure semantic | Conceptual queries, unfamiliar code |
124
- | `0.5` | Balanced (default) | General use |
125
- | `1.0` | Pure keyword (BM25) | When you know specific terms |
126
-
127
- Configure in `.opencode/codebase-index.json`:
128
- ```json
129
- {
130
- "search": {
131
- "hybridWeight": 0.3
132
- }
133
- }
134
- ```
48
+ ### `index_codebase`
49
+ Create/update index. Required before first search. Incremental (~50ms when unchanged).
135
50
 
136
- **When to adjust:**
137
- - Lower (0.2-0.4): Exploratory queries, finding related code
138
- - Higher (0.6-0.8): When query contains specific identifiers
51
+ ### `index_status`
52
+ Check if indexed and ready.
139
53
 
140
- ## Query Writing Tips
54
+ ## Query Tips
141
55
 
142
56
  **Describe behavior, not syntax:**
143
- ```
144
- Good: "function that hashes passwords securely"
145
- Bad: "hashPassword" (use grep for exact names)
146
-
147
- Good: "middleware that checks JWT tokens"
148
- Bad: "jwt" (too vague, use grep for keyword)
149
-
150
- Good: "error handling for unauthorized requests"
151
- Bad: "401" (literal keyword, use grep)
152
- ```
153
-
154
- ## Workflow Examples
155
-
156
- ### Exploring unfamiliar codebase
157
- ```
158
- 1. index_status → check if indexed
159
- 2. index_codebase → if needed
160
- 3. codebase_search("how does authentication work") → get overview
161
- 4. codebase_search("session management") → drill into specifics
162
- 5. grep "SessionStore" → once you know the class name
163
- ```
164
-
165
- ### Finding all functions in a module
166
- ```
167
- 1. codebase_search(query="utility helpers", directory="src/utils", chunkType="function")
168
- 2. Review results to understand available utilities
169
- 3. grep specific function name for all usages
170
- ```
171
-
172
- ### Finding implementation for a feature
173
- ```
174
- 1. codebase_search("image upload and processing") → find relevant files
175
- 2. Read top results to understand structure
176
- 3. grep "uploadImage" → find exact function
177
- 4. LSP goto_definition → navigate to implementation
178
- ```
57
+ - Good: `"function that hashes passwords securely"`
58
+ - Bad: `"hashPassword"` (use grep for exact names)
179
59
 
180
- ### Debugging unknown code path
181
- ```
182
- 1. codebase_search("error handling for payment failures") → find error handlers
183
- 2. codebase_search("retry logic for API calls") → find retry mechanisms
184
- 3. grep "PaymentError" → find specific error class
185
- ```
60
+ ## Filters
186
61
 
187
- ### Finding TypeScript interfaces
188
- ```
189
- 1. codebase_search(query="user data", chunkType="interface") find User interfaces
190
- 2. codebase_search(query="API response", chunkType="type") → find response types
191
- ```
62
+ | Filter | Example |
63
+ |--------|---------|
64
+ | `chunkType` | `function`, `class`, `interface`, `type`, `method` |
65
+ | `directory` | `"src/api"`, `"tests"` |
66
+ | `fileType` | `"ts"`, `"py"`, `"rs"` |