11export * as AgentPlugin from "./agent"
22
3- import path from "path"
43import { define } from "@opencode-ai/plugin/effect/plugin"
54import { Effect } from "effect"
65import { Agent } from "../agent"
7- import { Global } from "@opencode-ai/util/global"
8- import { Location } from "../location"
96import { Permission } from "../permission"
107
11- // Combined output files written by the Shell service, e.g. `<data>/shell/<projectID>/<shellID>.out`.
12- // Whitelisted so agents can read a command's full captured output without an external-directory prompt.
13- const SHELL_OUTPUT_GLOB = path.join(Global.Path.data, "shell", "*", "*")
14-
158const PROMPT_EXPLORE = `You are a file search specialist. You excel at thoroughly navigating and exploring codebases.
169
1710Your strengths:
@@ -100,57 +93,21 @@ Rules:
10093export const Plugin = define({
10194 id: "opencode.agent",
10295 effect: Effect.fn(function* (ctx) {
103- const location = yield* Location.Service
104- const worktree = location.directory
105- const whitelistedDirs = [SHELL_OUTPUT_GLOB, path.join(Global.Path.tmp, "*")]
106- const readonlyExternalDirectory: Permission.Ruleset = [
107- { action: "external_directory", resource: "*", effect: "ask" },
108- ...whitelistedDirs.map(
109- (resource): Permission.Rule => ({ action: "external_directory", resource, effect: "allow" }),
110- ),
111- ]
112- const defaults: Permission.Ruleset = [
113- { action: "*", resource: "*", effect: "allow" },
114- ...readonlyExternalDirectory,
115- { action: "question", resource: "*", effect: "deny" },
116- { action: "plan_enter", resource: "*", effect: "deny" },
117- { action: "plan_exit", resource: "*", effect: "deny" },
118- { action: "read", resource: "*", effect: "allow" },
119- { action: "read", resource: "*.env", effect: "ask" },
120- { action: "read", resource: "*.env.*", effect: "ask" },
121- { action: "read", resource: "*.env.example", effect: "allow" },
122- ]
123-
12496 yield* ctx.agent.transform((draft) => {
12597 draft.update(Agent.defaultID, (item) => {
12698 item.name = Agent.Name.make("Build")
12799 item.description = "The default agent. Executes tools based on configured permissions."
128100 item.mode = "primary"
129- item.permissions.push(
130- ...Permission.merge(defaults, [
131- { action: "question", resource: "*", effect: "allow" },
132- { action: "plan_enter", resource: "*", effect: "allow" },
133- ]),
134- )
101+ item.permissions.push({ action: "question", resource: "*", effect: "allow" })
135102 })
136103
137104 draft.update(Agent.ID.make("plan"), (item) => {
138105 item.name = Agent.Name.make("Plan")
139106 item.description = "Plan mode. Disallows all edit tools."
140107 item.mode = "primary"
141108 item.permissions.push(
142- ...Permission.merge(defaults, [
143- { action: "question", resource: "*", effect: "allow" },
144- { action: "plan_exit", resource: "*", effect: "allow" },
145- { action: "external_directory", resource: path.join(Global.Path.data, "plans", "*"), effect: "allow" },
146- { action: "edit", resource: "*", effect: "deny" },
147- { action: "edit", resource: path.join(".opencode", "plans", "*.md"), effect: "allow" },
148- {
149- action: "edit",
150- resource: path.relative(worktree, path.join(Global.Path.data, "plans", "*.md")),
151- effect: "allow",
152- },
153- ]),
109+ { action: "question", resource: "*", effect: "allow" },
110+ { action: "edit", resource: "*", effect: "deny" },
154111 )
155112 })
156113
@@ -159,28 +116,36 @@ export const Plugin = define({
159116 item.description =
160117 "General-purpose agent for researching complex questions and executing multi-step tasks. Use this agent to execute multiple units of work in parallel."
161118 item.mode = "subagent"
162- item.permissions.push(...Permission.merge(defaults, [{ action: "subagent", resource: "*", effect: "deny" }]))
119+ item.permissions.push(
120+ { action: "question", resource: "*", effect: "deny" },
121+ { action: "subagent", resource: "*", effect: "deny" },
122+ )
163123 })
164124
165125 draft.update(Agent.ID.make("explore"), (item) => {
126+ const externalDirectories = item.permissions.filter(
127+ (rule) => rule.action === "external_directory" && rule.effect === "allow",
128+ )
166129 item.name = Agent.Name.make("Explore")
167130 item.description =
168131 '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.'
169132 item.system = PROMPT_EXPLORE
170133 item.mode = "subagent"
171134 item.permissions.push(
172135 ...Permission.merge(
173- defaults,
174136 [
175137 { action: "*", resource: "*", effect: "deny" },
176138 { action: "grep", resource: "*", effect: "allow" },
177139 { action: "glob", resource: "*", effect: "allow" },
178140 { action: "webfetch", resource: "*", effect: "allow" },
179141 { action: "websearch", resource: "*", effect: "allow" },
180142 { action: "read", resource: "*", effect: "allow" },
143+ { action: "read", resource: "*.env", effect: "ask" },
144+ { action: "read", resource: "*.env.*", effect: "ask" },
145+ { action: "read", resource: "*.env.example", effect: "allow" },
181146 { action: "subagent", resource: "*", effect: "deny" },
182147 ],
183- readonlyExternalDirectory ,
148+ [{ action: "external_directory", resource: "*", effect: "ask" }, ...externalDirectories] ,
184149 ),
185150 )
186151 })
@@ -190,23 +155,23 @@ export const Plugin = define({
190155 item.mode = "primary"
191156 item.hidden = true
192157 item.system = PROMPT_COMPACTION
193- item.permissions.push(...Permission.merge(defaults, [ { action: "*", resource: "*", effect: "deny" }]) )
158+ item.permissions.push({ action: "*", resource: "*", effect: "deny" })
194159 })
195160
196161 draft.update(Agent.ID.make("title"), (item) => {
197162 item.name = Agent.Name.make("Title")
198163 item.mode = "primary"
199164 item.hidden = true
200165 item.system = PROMPT_TITLE
201- item.permissions.push(...Permission.merge(defaults, [ { action: "*", resource: "*", effect: "deny" }]) )
166+ item.permissions.push({ action: "*", resource: "*", effect: "deny" })
202167 })
203168
204169 draft.update(Agent.ID.make("summary"), (item) => {
205170 item.name = Agent.Name.make("Summary")
206171 item.mode = "primary"
207172 item.hidden = true
208173 item.system = PROMPT_SUMMARY
209- item.permissions.push(...Permission.merge(defaults, [ { action: "*", resource: "*", effect: "deny" }]) )
174+ item.permissions.push({ action: "*", resource: "*", effect: "deny" })
210175 })
211176 })
212177 }),
0 commit comments