Skip to content

Commit 3c371de

Browse files
committed
fix(plan): show plan content as markdown in exit prompt, guard empty plan
Read the plan file content and append it as a markdown preview in the plan_exit question. Also guard against empty plan files — return an error telling the agent to write the plan first.
1 parent aca39a6 commit 3c371de

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

packages/opencode/src/tool/plan.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,24 @@ export const PlanExitTool = Tool.define("plan_exit", {
2121
parameters: z.object({}),
2222
async execute(_params, ctx) {
2323
const session = await Session.get(ctx.sessionID)
24-
const plan = path.relative(Instance.worktree, Session.plan(session))
24+
const abs = Session.plan(session)
25+
const plan = path.relative(Instance.worktree, abs)
26+
const content = await Bun.file(abs)
27+
.text()
28+
.catch(() => "")
29+
if (!content.trim()) {
30+
return {
31+
title: "Plan file is empty",
32+
output: `The plan file at ${plan} is empty or does not exist. You must write your plan to this file before calling plan_exit. Use the write tool to create the plan file first.`,
33+
metadata: {},
34+
}
35+
}
36+
const preview = `\n\n---\n\n${content}`
2537
const answers = await Question.ask({
2638
sessionID: ctx.sessionID,
2739
questions: [
2840
{
29-
question: `Plan at ${plan} is complete. Would you like to switch to the build agent and start implementing?`,
41+
question: `Plan at \`${plan}\` is complete. Would you like to switch to the build agent and start implementing?${preview}`,
3042
header: "Build Agent",
3143
custom: false,
3244
options: [

0 commit comments

Comments
 (0)