From 1f3c2af25a5142f0ee7204defddecec2e7c6d5da Mon Sep 17 00:00:00 2001 From: Johnny Amancio Date: Mon, 1 Jun 2026 13:22:03 +0200 Subject: [PATCH 1/2] fix: correct architect use of plan exit to save the plan file correctly --- .../opencode/src/kilocode/session/prompt.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/opencode/src/kilocode/session/prompt.ts b/packages/opencode/src/kilocode/session/prompt.ts index 7da8a541d76..08fa206ff13 100644 --- a/packages/opencode/src/kilocode/session/prompt.ts +++ b/packages/opencode/src/kilocode/session/prompt.ts @@ -16,6 +16,7 @@ import { Permission } from "@/permission" import { environmentDetails, type EditorContext } from "@/kilocode/editor-context" import { Identifier } from "@/id/id" import { Filesystem } from "@/util/filesystem" +import { InstanceState } from "@/effect/instance-state" import PROMPT_PLAN from "@/session/prompt/plan.txt" import CODE_SWITCH from "@/session/prompt/code-switch.txt" @@ -48,7 +49,8 @@ export namespace KiloSessionPrompt { abort: AbortSignal }): Promise<"continue" | "break"> { if (!shouldAskPlanFollowup({ messages: input.messages, abort: input.abort })) return "break" - const action = await PlanFollowup.ask({ + const ask = InstanceState.bind(PlanFollowup.ask) + const action = await ask({ sessionID: input.sessionID, messages: input.messages, abort: input.abort, @@ -227,23 +229,29 @@ export namespace KiloSessionPrompt { * Ensures the plan file directory exists and tells the agent where to write. */ export async function insertPlanReminders(input: { - agent: { name: string } + agent: { name: string; options?: Record } session: Session.Info userMessage: MessageV2.WithParts }) { - if (input.agent.name !== "plan") return - const plan = Session.plan(input.session, Instance.current) + if (input.agent.name !== "plan" && input.agent.options?.id !== "architect") return + // keep bind(): inside Effect.promise the project context is lost, so Instance.current throws without it + const plan = InstanceState.bind(() => Session.plan(input.session, Instance.current))() const exists = await Filesystem.exists(plan) if (!exists) await ensurePlanDir(path.dirname(plan)) const info = exists ? `A plan file already exists at ${plan}. You can read it and make incremental edits using the edit tool.` : `No plan file exists yet. You should create your plan at ${plan} using the write tool.` + const planFile = `## Plan File\n${info}\nThis is the ONLY file you are allowed to write to or edit.` + const text = + input.agent.name === "plan" + ? `${PROMPT_PLAN}\n\n${planFile}` + : `\n${planFile} Before writing this file or calling plan_exit, ask the user to choose exactly one of: "Finalize and save the plan" or "Continue refining". If the user chooses to finalize, write the complete plan to this exact file, then call plan_exit with no arguments.\n` input.userMessage.parts.push({ id: PartID.ascending(), messageID: input.userMessage.info.id, sessionID: input.userMessage.info.sessionID, type: "text", - text: PROMPT_PLAN + `\n\n## Plan File\n${info}\nThis is the ONLY file you are allowed to write to or edit.`, + text, synthetic: true, }) } From 4d27232faf7eabdcdc407030eb5d07d522b24849 Mon Sep 17 00:00:00 2001 From: Johnny Amancio Date: Tue, 2 Jun 2026 14:24:48 +0200 Subject: [PATCH 2/2] fix: relax rule for file creation to allow other files under user request --- packages/opencode/src/kilocode/session/prompt.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/opencode/src/kilocode/session/prompt.ts b/packages/opencode/src/kilocode/session/prompt.ts index 08fa206ff13..c151a8f7f45 100644 --- a/packages/opencode/src/kilocode/session/prompt.ts +++ b/packages/opencode/src/kilocode/session/prompt.ts @@ -241,11 +241,15 @@ export namespace KiloSessionPrompt { const info = exists ? `A plan file already exists at ${plan}. You can read it and make incremental edits using the edit tool.` : `No plan file exists yet. You should create your plan at ${plan} using the write tool.` - const planFile = `## Plan File\n${info}\nThis is the ONLY file you are allowed to write to or edit.` + const limit = + input.agent.name === "plan" + ? "This is the ONLY file you are allowed to write to or edit." + : "Use this as the main plan file to write or edit. Do not write or edit other files unless the user explicitly asks and your permissions allow it." + const planFile = `## Plan File\n${info}\n${limit}` const text = input.agent.name === "plan" ? `${PROMPT_PLAN}\n\n${planFile}` - : `\n${planFile} Before writing this file or calling plan_exit, ask the user to choose exactly one of: "Finalize and save the plan" or "Continue refining". If the user chooses to finalize, write the complete plan to this exact file, then call plan_exit with no arguments.\n` + : `\n${planFile} Before writing this file or calling plan_exit, ask the user to choose exactly one of: "Finalize and save the plan" or "Continue refining". If the user chooses to finalize, write the main plan to this exact file, then call plan_exit with no arguments. If the user explicitly asks for additional plan files and your permissions allow it, you may create them and reference them from the main plan.\n` input.userMessage.parts.push({ id: PartID.ascending(), messageID: input.userMessage.info.id,