diff --git a/packages/opencode/src/agent/agent.ts b/packages/opencode/src/agent/agent.ts
index 5e806568c7..497c26a17c 100644
--- a/packages/opencode/src/agent/agent.ts
+++ b/packages/opencode/src/agent/agent.ts
@@ -11,7 +11,6 @@ import { ProviderTransform } from "../provider/transform"
import PROMPT_GENERATE from "./generate.txt"
import PROMPT_COMPACTION from "./prompt/compaction.txt"
import PROMPT_EXPLORE from "./prompt/explore.txt"
-import PROMPT_REFERENCE from "./prompt/reference.txt"
import PROMPT_SUMMARY from "./prompt/summary.txt"
import PROMPT_TITLE from "./prompt/title.txt"
import { PermissionNext } from "@/permission/next"
@@ -75,6 +74,17 @@ export namespace Agent {
})
const user = PermissionNext.fromConfig(cfg.permission ?? {})
+ let explorePrompt = PROMPT_EXPLORE
+ if (cfg.references?.length) {
+ const refs = cfg.references.map((r) => Reference.parse(r))
+ const fresh = await Promise.all(refs.map((r) => Reference.ensureFresh(r)))
+ const valid = fresh.filter(Boolean) as Reference.Info[]
+ if (valid.length > 0) {
+ explorePrompt +=
+ "\n\n\n" + valid.map((r) => `- ${r.url} -> ${r.path}`).join("\n") + "\n"
+ }
+ }
+
const result: Record = {
build: {
name: "build",
@@ -145,47 +155,21 @@ export namespace Agent {
read: "allow",
external_directory: {
[Truncate.GLOB]: "allow",
+ [path.join(Global.Path.reference, "*")]: "allow",
},
}),
user,
),
- description: `Fast agent specialized for exploring codebases. Use this when you need to quickly find files by patterns (eg. "src/components/**/*.tsx"), search code for keywords (eg. "API endpoints"), or answer questions about the codebase (eg. "how do API endpoints work?"). When calling this agent, specify the desired thoroughness level: "quick" for basic searches, "medium" for moderate exploration, or "very thorough" for comprehensive analysis across multiple locations and naming conventions.`,
- prompt: PROMPT_EXPLORE,
+ description: `Fast agent specialized for exploring codebases. Use this when you need to quickly find files by patterns (eg. "src/components/**/*.tsx"), search code for keywords (eg. "API endpoints"), or answer questions about the codebase (eg. "how do API endpoints work?"). When calling this agent, specify the desired thoroughness level: "quick" for basic searches, "medium" for moderate exploration, or "very thorough" for comprehensive analysis across multiple locations and naming conventions.${
+ cfg.references?.length
+ ? `\n\nAlways use this to answer questions about the following referenced projects:\n${cfg.references.map((r) => `- ${r}`).join("\n")}`
+ : ""
+ }`,
+ prompt: explorePrompt,
options: {},
mode: "subagent",
native: true,
},
- ...(cfg.references?.length
- ? {
- reference: {
- name: "reference",
- description: `Search across referenced projects configured in opencode.json under "references". Use this to query code in external repositories.\n\nAvailable references:\n${cfg.references.map((r) => `- ${r}`).join("\n")}`,
- permission: PermissionNext.merge(
- defaults,
- PermissionNext.fromConfig({
- "*": "deny",
- grep: "allow",
- glob: "allow",
- list: "allow",
- bash: "allow",
- webfetch: "allow",
- websearch: "allow",
- codesearch: "allow",
- read: "allow",
- lsp: "allow",
- external_directory: {
- [Truncate.GLOB]: "allow",
- [path.join(Global.Path.reference, "*")]: "allow",
- },
- }),
- user,
- ),
- options: {},
- mode: "subagent",
- native: true,
- },
- }
- : {}),
compaction: {
name: "compaction",
mode: "primary",
@@ -283,20 +267,7 @@ export namespace Agent {
})
export async function get(agent: string) {
- const result = await state().then((x) => x[agent])
- if (!result) return result
- if (agent === "reference") {
- const refs = await Reference.list()
- const fresh = await Promise.all(refs.map((r) => Reference.ensureFresh(r)))
- const valid = fresh.filter(Boolean) as Reference.Info[]
- const info =
- valid.length > 0 ? valid.map((r) => `- ${r.url} at ${r.path}`).join("\n") : "No references available."
- return {
- ...result,
- prompt: PROMPT_REFERENCE + "\n\nAvailable references:\n" + info,
- }
- }
- return result
+ return state().then((x) => x[agent])
}
export async function list() {
diff --git a/packages/opencode/src/agent/prompt/explore.txt b/packages/opencode/src/agent/prompt/explore.txt
index 5761077cbd..379786763b 100644
--- a/packages/opencode/src/agent/prompt/explore.txt
+++ b/packages/opencode/src/agent/prompt/explore.txt
@@ -15,4 +15,13 @@ Guidelines:
- For clear communication, avoid using emojis
- Do not create any files, or run bash commands that modify the user's system state in any way
+Referenced projects:
+When configured, you also have access to referenced projects - external codebases that may contain relevant code or patterns. Use these when:
+- The user asks about code not found in the main project
+- You need to understand how a library or dependency works
+- The user mentions an external repository or package
+- Searching for patterns across multiple codebases
+
+Search referenced projects by using their absolute paths (provided in a tag) with Glob, Grep, and Read tools.
+
Complete the user's search request efficiently and report your findings clearly.
diff --git a/packages/opencode/src/agent/prompt/reference.txt b/packages/opencode/src/agent/prompt/reference.txt
deleted file mode 100644
index 95a04b09c8..0000000000
--- a/packages/opencode/src/agent/prompt/reference.txt
+++ /dev/null
@@ -1,18 +0,0 @@
-You are a multi-project code search specialist. You search across referenced projects to answer questions about external codebases.
-
-Your strengths:
-- Rapidly finding files using glob patterns across multiple repositories
-- Searching code and text with powerful regex patterns
-- Reading and analyzing file contents from any referenced project
-
-Guidelines:
-- Search across ALL referenced projects unless the user specifies one
-- Report which project(s) contained relevant findings by mentioning the repository URL
-- Use Glob for broad file pattern matching across all references
-- Use Grep for searching file contents with regex
-- Use Read when you know the specific file path you need to read
-- Return file paths as absolute paths so users can locate findings
-- For clear communication, avoid using emojis
-- Do not create any files, or run bash commands that modify the system state in any way
-
-Complete the user's search request efficiently and report your findings clearly.
\ No newline at end of file