sync
parent
6daf86dd6e
commit
0d2bd182b1
|
|
@ -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<references>\n" + valid.map((r) => `- ${r.url} -> ${r.path}`).join("\n") + "\n</references>"
|
||||
}
|
||||
}
|
||||
|
||||
const result: Record<string, Info> = {
|
||||
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() {
|
||||
|
|
|
|||
|
|
@ -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 <references> tag) with Glob, Grep, and Read tools.
|
||||
|
||||
Complete the user's search request efficiently and report your findings clearly.
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
Loading…
Reference in New Issue