2025-12-24 17:11:18 +09:00
# TOOLS KNOWLEDGE BASE
## OVERVIEW
2026-01-17 19:16:49 +09:00
Core toolset implementing LSP, structural search, and system orchestration. Extends OpenCode with high-performance C++ bindings and multi-agent delegation.
2025-12-24 17:11:18 +09:00
## STRUCTURE
```
tools/
2026-01-17 19:16:49 +09:00
├── [tool-name]/
│ ├── index.ts # Tool factory entry
│ ├── tools.ts # Business logic & implementation
│ ├── types.ts # Zod schemas & TS types
│ └── constants.ts # Tool-specific fixed values
├── lsp/ # 11 tools via JSON-RPC client (596 lines client.ts)
├── ast-grep/ # Structural search (NAPI bindings)
├── delegate-task/ # Category-based agent routing (770 lines tools.ts)
├── session-manager/ # OpenCode session history (9 files)
└── interactive-bash/ # Tmux session management (5 files)
2025-12-24 17:11:18 +09:00
```
## TOOL CATEGORIES
2026-01-17 19:16:49 +09:00
| Category | Purpose | Key Implementations |
|----------|---------|---------------------|
| **LSP ** | Semantic code intelligence | `lsp_goto_definition` , `lsp_find_references` , `lsp_rename` |
| **Search ** | Fast discovery & matching | `glob` , `grep` , `ast_grep_search` , `ast_grep_replace` |
| **System ** | CLI & Environment | `bash` , `interactive_bash` (tmux), `look_at` (vision) |
| **Session ** | History & Context | `session_read` , `session_search` , `session_select` |
| **Agent ** | Task Orchestration | `delegate_task` , `call_omo_agent` |
2025-12-24 17:11:18 +09:00
2026-01-17 19:16:49 +09:00
## HOW TO ADD
1. **Directory ** : Create `src/tools/[name]/` with standard files.
2. **Factory ** : Use `tool()` from `@opencode-ai/plugin/tool` .
3. **Parameters ** : Define strict Zod schemas in `types.ts` .
4. **Registration ** : Export from `src/tools/index.ts` and add to `builtinTools` .
2025-12-24 17:11:18 +09:00
## LSP SPECIFICS
2026-01-17 19:16:49 +09:00
- **Client**: `lsp/client.ts` manages stdio lifecycle and JSON-RPC.
- **Capabilities**: Supports definition, references, symbols, diagnostics, and workspace-wide rename.
- **Protocol**: Maps standard LSP methods to tool-compatible responses.
2025-12-24 17:11:18 +09:00
## AST-GREP SPECIFICS
2026-01-17 19:16:49 +09:00
- **Engine**: Uses `@ast-grep/napi` for 25+ language support.
- **Patterns**: Supports meta-variables (`$VAR` ) and multi-node matching (`$$$` ).
- **Performance**: Structural matching executed in Rust/C++ layer.
2026-01-13 21:00:00 +09:00
## ANTI-PATTERNS
2026-01-17 19:16:49 +09:00
- **Sequential Calls**: Don't call `bash` in loops; use `&&` or delegation.
- **Raw File Ops**: Never use `mkdir/touch` inside tool logic.
- **Heavy Sync**: Keep `PreToolUse` light; heavy computation belongs in `tools.ts` .
- **Sleep**: Never use `sleep N` ; use polling loops or tool-specific wait flags.