Compare commits

...

4 Commits

Author SHA1 Message Date
Aiden Cline 71f7b354d6 fix(core): tighten plan switch reminder copy
Rewrite enter and leave synthetics to state the read-only constraint
and its removal without extra workflow instructions.
2026-08-11 10:52:52 -05:00
Aiden Cline 0652e32ae1 feat(core): inject plan mode reminders on agent switch
Subscribe to session.agent.selected and admit a synthetic system reminder
when entering or leaving Plan, without waking the session.
2026-08-11 10:52:52 -05:00
Aiden Cline e0a9d43f8c fix(core): tighten plan plugin copy
Use a user-facing Plan description and a per-tool read-only failure message.
2026-08-11 10:52:52 -05:00
Aiden Cline 4ee4966d05 feat(core): extract plan agent into a plugin
Move Plan out of opencode.agent into opencode.plan. Keep edit/write/patch
advertised and reject those calls from execute.before when Plan is selected.
2026-08-11 10:52:52 -05:00
4 changed files with 57 additions and 11 deletions
-10
View File
@@ -101,16 +101,6 @@ export const Plugin = define({
item.permissions.push({ action: "question", resource: "*", effect: "allow" })
})
draft.update(Agent.ID.make("plan"), (item) => {
item.name = Agent.Name.make("Plan")
item.description = "Plan mode. Disallows all edit tools."
item.mode = "primary"
item.permissions.push(
{ action: "question", resource: "*", effect: "allow" },
{ action: "edit", resource: "*", effect: "deny" },
)
})
draft.update(Agent.ID.make("general"), (item) => {
item.name = Agent.Name.make("General")
item.description =
+2
View File
@@ -60,6 +60,7 @@ import { WellKnown } from "../wellknown"
import { WriteTool } from "../tool/plugin/write"
import { AgentPlugin } from "./agent"
import { CommandPlugin } from "./command"
import { PlanPlugin } from "./plan"
import { ModelsDevPlugin } from "./models-dev"
import { ProviderPlugins } from "./provider"
import { WebSearchPlugins } from "./websearch"
@@ -192,6 +193,7 @@ export type InternalPlugin = Plugin<Requirements | Scope.Scope>
const pre = [
WellKnownPlugin.Plugin,
AgentPlugin.Plugin,
PlanPlugin.Plugin,
CommandPlugin.Plugin,
SkillPlugin.Plugin,
...SystemPromptPlugin.Plugins,
+55
View File
@@ -0,0 +1,55 @@
export * as PlanPlugin from "./plan"
import { ToolFailure } from "@opencode-ai/ai"
import { define } from "@opencode-ai/plugin/effect/plugin"
import { Effect, Stream } from "effect"
import { Agent } from "../agent"
const plan = Agent.ID.make("plan")
const enter = `<system-reminder>
You are in Plan mode. This is a READ-ONLY environment. You are not allowed to edit files, and you may not ask a subagent to edit them either.
</system-reminder>`
const leave = `<system-reminder>
You are no longer in Plan mode. The previous read-only restrictions no longer apply. You may edit files again.
</system-reminder>`
export const Plugin = define({
id: "opencode.plan",
effect: Effect.fn(function* (ctx) {
yield* ctx.agent.transform((draft) => {
draft.update(plan, (item) => {
item.name = Agent.Name.make("Plan")
item.description = "Read-only agent for exploring the codebase and planning work before implementation."
item.mode = "primary"
item.permissions.push({ action: "question", resource: "*", effect: "allow" })
})
})
yield* ctx.tool.hook("execute.before", (event) => {
if (event.agent !== plan) return Effect.void
if (event.tool !== "edit" && event.tool !== "write" && event.tool !== "patch") return Effect.void
return new ToolFailure({
message: `Cannot use ${event.tool} in Plan mode. You are in a read-only mode and must not modify files.`,
})
})
yield* ctx.event.subscribe().pipe(
Stream.filter((event) => event.type === "session.agent.selected"),
Stream.runForEach((event) => {
if (event.data.agent === event.data.previous) return Effect.void
const text = event.data.agent === plan ? enter : event.data.previous === plan ? leave : undefined
if (!text) return Effect.void
return ctx.session
.synthetic({
sessionID: event.data.sessionID,
text,
resume: false,
})
.pipe(Effect.catch(() => Effect.void))
}),
Effect.forkScoped({ startImmediately: true }),
)
}),
})
-1
View File
@@ -165,7 +165,6 @@ describe("Agent", () => {
"compaction",
"explore",
"general",
"plan",
"summary",
"title",
])