Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions packages/opencode/src/kilocode/session/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -227,23 +229,33 @@ 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<string, unknown> }
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
Comment thread
johnnyeric marked this conversation as resolved.
// 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 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}`
: `<system-reminder>\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</system-reminder>`
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,
})
}
Expand Down
Loading