Skip to content

Commit 987a81b

Browse files
committed
feat: register slash commands via config hook
- Add config hook to programmatically register /search, /find, /index commands - Commands now auto-register when plugin loads (no manual copy needed) - Update README with simplified local development instructions
1 parent 5ca9b44 commit 987a81b

File tree

2 files changed

+47
-18
lines changed

2 files changed

+47
-18
lines changed

README.md

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,7 @@ Maintenance tool to remove stale entries from deleted files.
155155

156156
## 🎮 Slash Commands
157157

158-
For easier access, you can add slash commands to your project.
159-
160-
Copy the commands:
161-
```bash
162-
cp -r node_modules/opencode-codebase-index/commands/* .opencode/command/
163-
```
158+
The plugin automatically registers these slash commands:
164159

165160
| Command | Description |
166161
| ------- | ----------- |
@@ -238,19 +233,16 @@ Be aware of these characteristics:
238233
npm run build
239234
```
240235

241-
2. **Deploy to OpenCode Cache**:
242-
```bash
243-
# Deploy script
244-
rm -rf ~/.cache/opencode/node_modules/opencode-codebase-index
245-
mkdir -p ~/.cache/opencode/node_modules/opencode-codebase-index
246-
cp -R dist native commands skill package.json ~/.cache/opencode/node_modules/opencode-codebase-index/
247-
```
248-
249-
3. **Register in Test Project**:
250-
```bash
251-
mkdir -p .opencode/plugin
252-
echo 'export { default } from "$HOME/.cache/opencode/node_modules/opencode-codebase-index/dist/index.js"' > .opencode/plugin/codebase-index.ts
236+
2. **Register in Test Project** (use `file://` URL in `opencode.json`):
237+
```json
238+
{
239+
"plugin": [
240+
"file:///path/to/opencode-codebase-index"
241+
]
242+
}
253243
```
244+
245+
This loads directly from your source directory, so changes take effect after rebuilding.
254246

255247
## 🤝 Contributing
256248

src/index.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,43 @@ const plugin: Plugin = async ({ directory }) => {
5252
index_status,
5353
index_health_check,
5454
},
55+
56+
async config(cfg) {
57+
cfg.command = cfg.command ?? {};
58+
59+
cfg.command["search"] = {
60+
description: "Search codebase by meaning using semantic search",
61+
template: `Use the \`codebase_search\` tool to find code related to: $ARGUMENTS
62+
63+
If the index doesn't exist yet, run \`index_codebase\` first.
64+
65+
Return the most relevant results with file paths and line numbers.`,
66+
};
67+
68+
cfg.command["find"] = {
69+
description: "Find code using hybrid approach (semantic + grep)",
70+
template: `Find code related to: $ARGUMENTS
71+
72+
Strategy:
73+
1. First use \`codebase_search\` to find semantically related code
74+
2. From the results, identify specific function/class names
75+
3. Use grep to find all occurrences of those identifiers
76+
4. Combine findings into a comprehensive answer
77+
78+
If the semantic index doesn't exist, run \`index_codebase\` first.`,
79+
};
80+
81+
cfg.command["index"] = {
82+
description: "Index the codebase for semantic search",
83+
template: `Run the \`index_codebase\` tool to create or update the semantic search index.
84+
85+
Show progress and final statistics including:
86+
- Number of files processed
87+
- Number of chunks indexed
88+
- Tokens used
89+
- Duration`,
90+
};
91+
},
5592
};
5693
};
5794

0 commit comments

Comments
 (0)