From fcc561ebb75a6f5752bb12c8fd28cd7af7388373 Mon Sep 17 00:00:00 2001 From: Dax Raad Date: Wed, 14 Jan 2026 08:21:17 -0500 Subject: [PATCH] fix plan mode when not in git worktree --- packages/opencode/src/agent/agent.ts | 6 ++++++ packages/opencode/src/session/index.ts | 6 +++++- packages/opencode/src/session/prompt.ts | 4 +++- packages/opencode/src/session/prompt/build-switch.txt | 2 -- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/opencode/src/agent/agent.ts b/packages/opencode/src/agent/agent.ts index 6847d29ab..52896136e 100644 --- a/packages/opencode/src/agent/agent.ts +++ b/packages/opencode/src/agent/agent.ts @@ -13,6 +13,8 @@ import PROMPT_SUMMARY from "./prompt/summary.txt" import PROMPT_TITLE from "./prompt/title.txt" import { PermissionNext } from "@/permission/next" import { mergeDeep, pipe, sortBy, values } from "remeda" +import { Global } from "@/global" +import path from "path" export namespace Agent { export const Info = z @@ -88,9 +90,13 @@ export namespace Agent { PermissionNext.fromConfig({ question: "allow", plan_exit: "allow", + external_directory: { + [path.join(Global.Path.data, "plans", "*")]: "allow", + }, edit: { "*": "deny", ".opencode/plans/*.md": "allow", + [path.relative(Instance.worktree, path.join(Global.Path.data, "plans/*.md"))]: "allow", }, }), user, diff --git a/packages/opencode/src/session/index.ts b/packages/opencode/src/session/index.ts index 2bb9fc5f8..c70b74f0f 100644 --- a/packages/opencode/src/session/index.ts +++ b/packages/opencode/src/session/index.ts @@ -22,6 +22,7 @@ import { Snapshot } from "@/snapshot" import type { Provider } from "@/provider/provider" import { PermissionNext } from "@/permission/next" import path from "path" +import { Global } from "@/global" export namespace Session { const log = Log.create({ service: "session" }) @@ -233,7 +234,10 @@ export namespace Session { } export function plan(input: { slug: string; time: { created: number } }) { - return path.join(Instance.worktree, ".opencode", "plans", [input.time.created, input.slug].join("-") + ".md") + const base = Instance.project.vcs + ? path.join(Instance.worktree, ".opencode", "plans") + : path.join(Global.Path.data, "plans") + return path.join(base, [input.time.created, input.slug].join("-") + ".md") } export const get = fn(Identifier.schema("session"), async (id) => { diff --git a/packages/opencode/src/session/prompt.ts b/packages/opencode/src/session/prompt.ts index 5036d3a69..345b1c49e 100644 --- a/packages/opencode/src/session/prompt.ts +++ b/packages/opencode/src/session/prompt.ts @@ -1229,11 +1229,13 @@ export namespace SessionPrompt { messageID: userMessage.info.id, sessionID: userMessage.info.sessionID, type: "text", - text: BUILD_SWITCH.replace("{{plan}}", plan), + text: + BUILD_SWITCH + "\n\n" + `A plan file exists at ${plan}. You should execute on the plan defined within it`, synthetic: true, }) userMessage.parts.push(part) } + return input.messages } // Entering plan mode diff --git a/packages/opencode/src/session/prompt/build-switch.txt b/packages/opencode/src/session/prompt/build-switch.txt index 40b39b95b..3737b74d8 100644 --- a/packages/opencode/src/session/prompt/build-switch.txt +++ b/packages/opencode/src/session/prompt/build-switch.txt @@ -2,6 +2,4 @@ Your operational mode has changed from plan to build. You are no longer in read-only mode. You are permitted to make file changes, run shell commands, and utilize your arsenal of tools as needed. - -A plan file exists at {{plan}}. You should read this file and execute on the plan defined within it.