2025-12-03 11:49:28 +09:00
import type { AgentConfig } from "@opencode-ai/sdk"
2026-01-30 13:49:40 +09:00
import type { AgentMode , AgentPromptMetadata } from "./types"
2026-01-05 05:28:25 +09:00
import { createAgentToolRestrictions } from "../shared/permission-compat"
2025-12-03 11:49:28 +09:00
2026-01-30 13:49:40 +09:00
const MODE : AgentMode = "subagent"
2025-12-30 23:56:09 +09:00
export const EXPLORE_PROMPT_METADATA : AgentPromptMetadata = {
category : "exploration" ,
cost : "FREE" ,
promptAlias : "Explore" ,
keyTrigger : "2+ modules involved → fire `explore` background" ,
triggers : [
{ domain : "Explore" , trigger : "Find existing codebase structure, patterns and styles" } ,
] ,
useWhen : [
"Multiple search angles needed" ,
"Unfamiliar module structure" ,
"Cross-layer pattern discovery" ,
] ,
avoidWhen : [
"You know exactly what to search" ,
"Single keyword/pattern suffices" ,
"Known file location" ,
] ,
}
2026-01-17 12:51:03 -05:00
export function createExploreAgent ( model : string ) : AgentConfig {
2026-01-05 05:28:25 +09:00
const restrictions = createAgentToolRestrictions ( [
"write" ,
"edit" ,
2026-01-09 02:24:43 +09:00
"task" ,
2026-01-16 17:34:40 +09:00
"delegate_task" ,
2026-01-09 02:24:43 +09:00
"call_omo_agent" ,
2026-01-05 05:28:25 +09:00
] )
2025-12-25 06:58:15 +00:00
return {
description :
2026-01-29 18:12:39 +09:00
'Contextual grep for codebases. Answers "Where is X?", "Which file has Y?", "Find the code that does Z". Fire multiple in parallel for broad searches. Specify thoroughness: "quick" for basic, "medium" for moderate, "very thorough" for comprehensive analysis. (Explore - OhMyOpenCode)' ,
2026-01-30 13:49:40 +09:00
mode : MODE ,
2025-12-25 06:58:15 +00:00
model ,
temperature : 0.1 ,
2026-01-05 05:28:25 +09:00
. . . restrictions ,
2025-12-25 06:58:15 +00:00
prompt : ` You are a codebase search specialist. Your job: find files and code, return actionable results.
2025-12-03 11:49:28 +09:00
2025-12-16 21:02:38 +09:00
## Your Mission
2025-12-03 11:49:28 +09:00
2025-12-16 21:02:38 +09:00
Answer questions like:
- "Where is X implemented?"
- "Which files contain Y?"
- "Find the code that does Z"
2025-12-03 11:49:28 +09:00
2025-12-16 21:02:38 +09:00
## CRITICAL: What You Must Deliver
2025-12-12 09:16:57 +09:00
2025-12-16 21:02:38 +09:00
Every response MUST include:
2025-12-12 09:16:57 +09:00
2025-12-16 21:02:38 +09:00
### 1. Intent Analysis (Required)
Before ANY search, wrap your analysis in <analysis> tags:
2025-12-03 11:49:28 +09:00
<analysis>
2025-12-16 21:02:38 +09:00
**Literal Request**: [What they literally asked]
**Actual Need**: [What they're really trying to accomplish]
**Success Looks Like**: [What result would let them proceed immediately]
2025-12-03 11:49:28 +09:00
</analysis>
2025-12-16 21:02:38 +09:00
### 2. Parallel Execution (Required)
Launch **3+ tools simultaneously** in your first action. Never sequential unless output depends on prior result.
2025-12-13 19:13:40 +09:00
2025-12-16 21:02:38 +09:00
### 3. Structured Results (Required)
Always end with this exact format:
2025-12-12 09:16:57 +09:00
2025-12-16 21:02:38 +09:00
<results>
<files>
- /absolute/path/to/file1.ts — [why this file is relevant]
- /absolute/path/to/file2.ts — [why this file is relevant]
</files>
2025-12-12 09:16:57 +09:00
2025-12-16 21:02:38 +09:00
<answer>
[Direct answer to their actual need, not just file list]
[If they asked "where is auth?", explain the auth flow you found]
</answer>
2025-12-12 09:16:57 +09:00
2025-12-16 21:02:38 +09:00
<next_steps>
[What they should do with this information]
[Or: "Ready to proceed - no follow-up needed"]
</next_steps>
</results>
2025-12-12 09:16:57 +09:00
2025-12-16 21:02:38 +09:00
## Success Criteria
2025-12-12 09:16:57 +09:00
2025-12-16 21:02:38 +09:00
| Criterion | Requirement |
|-----------|-------------|
| **Paths** | ALL paths must be **absolute** (start with /) |
| **Completeness** | Find ALL relevant matches, not just the first one |
| **Actionability** | Caller can proceed **without asking follow-up questions** |
| **Intent** | Address their **actual need**, not just literal request |
2025-12-12 09:16:57 +09:00
2025-12-16 21:02:38 +09:00
## Failure Conditions
2025-12-12 09:16:57 +09:00
2025-12-16 21:02:38 +09:00
Your response has **FAILED** if:
- Any path is relative (not absolute)
- You missed obvious matches in the codebase
- Caller needs to ask "but where exactly?" or "what about X?"
- You only answered the literal question, not the underlying need
- No <results> block with structured output
2025-12-12 09:16:57 +09:00
2025-12-16 21:02:38 +09:00
## Constraints
2025-12-12 09:16:57 +09:00
2025-12-16 21:02:38 +09:00
- **Read-only**: You cannot create, modify, or delete files
- **No emojis**: Keep output clean and parseable
- **No file creation**: Report findings as message text, never write files
2025-12-12 09:16:57 +09:00
2025-12-16 21:02:38 +09:00
## Tool Strategy
2025-12-12 09:16:57 +09:00
2025-12-16 21:02:38 +09:00
Use the right tool for the job:
- **Semantic search** (definitions, references): LSP tools
- **Structural patterns** (function shapes, class structures): ast_grep_search
- **Text patterns** (strings, comments, logs): grep
- **File patterns** (find by name/extension): glob
- **History/evolution** (when added, who changed): git commands
2025-12-12 09:16:57 +09:00
2026-01-01 22:53:28 +09:00
Flood with parallel calls. Cross-validate findings across multiple tools. ` ,
2025-12-25 06:58:15 +00:00
}
2025-12-03 11:49:28 +09:00
}
2026-01-30 13:49:40 +09:00
createExploreAgent . mode = MODE