xonecas.io
64875
Mc

mini-coder / commit a867716

fix: plan mode changes

xonecas2026-02-20 a867716c11dca753f7cb0bae1d93b32eeaf86448 parent 54eea50

4 files changed

TODO.md+1−1
@@ -21,7 +21,7 @@ Besides undoing the conversation turn, it should restore some snapshot, using gi
2121 # Plan mode changes
2222
2323 - Allow read tools + mcp
24-- When plan mode is on, add a `<system-message>PLAN MODE ACTIVE -- READ ONLY</system-message>` suffix to the user messages.
24+- When plan mode is on, add a `<system-message>PLAN MODE ACTIVE: Help the user gather context for the plan -- READ ONLY</system-message>` suffix to the user messages.
2525
2626 ---
2727
src/agent/agent.ts+11−4
@@ -33,7 +33,7 @@ import {
3333 resumeSession,
3434 touchActiveSession,
3535 } from "../session/manager.ts";
36-import { buildToolSet } from "./tools.ts";
36+import { buildReadOnlyToolSet, buildToolSet } from "./tools.ts";
3737
3838 // ─── Git branch detection ─────────────────────────────────────────────────────
3939
@@ -240,6 +240,7 @@ export async function runAgent(opts: AgentOptions): Promise<void> {
240240
241241 // ── MCP: load persisted servers and connect them ───────────────────────────
242242 const tools: ToolDef[] = buildToolSet({ cwd, depth: 0, runSubagent });
243+ const mcpTools: ToolDef[] = [];
243244
244245 async function connectAndAddMcp(name: string): Promise<void> {
245246 const rows = listMcpServers();
@@ -255,6 +256,7 @@ export async function runAgent(opts: AgentOptions): Promise<void> {
255256 };
256257 const client = await connectMcpServer(cfg);
257258 tools.push(...client.tools);
259+ mcpTools.push(...client.tools);
258260 }
259261
260262 // Connect all persisted MCP servers at startup
@@ -396,8 +398,13 @@ export async function runAgent(opts: AgentOptions): Promise<void> {
396398 session.messages.push(userMsg);
397399 saveMessages(session.id, [userMsg], thisTurn);
398400
399- // Also push into coreHistory as a raw ModelMessage
400- coreHistory.push({ role: "user", content: resolvedText });
401+ // Also push into coreHistory as a raw ModelMessage.
402+ // In plan mode, append the system-message suffix so the model knows it
403+ // should only read/explore — not execute write operations.
404+ const coreContent = planMode
405+ ? `${resolvedText}\n\n<system-message>PLAN MODE ACTIVE: Help the user gather context for the plan -- READ ONLY</system-message>`
406+ : resolvedText;
407+ coreHistory.push({ role: "user", content: coreContent });
401408
402409 const llm = resolveModel(currentModel);
403410 const systemPrompt = buildSystemPrompt(cwd);
@@ -411,7 +418,7 @@ export async function runAgent(opts: AgentOptions): Promise<void> {
411418 const events = runTurn({
412419 model: llm,
413420 messages: coreHistory,
414- tools: planMode ? [] : tools,
421+ tools: planMode ? [...buildReadOnlyToolSet({ cwd }), ...mcpTools] : tools,
415422 systemPrompt,
416423 signal: abortController.signal,
417424 });
src/agent/tools.ts+8−0
@@ -88,3 +88,11 @@ export function buildToolSet(opts: {
8888 }) as ToolDef,
8989 ];
9090 }
91+
92+export function buildReadOnlyToolSet(opts: { cwd: string }): ToolDef[] {
93+ return [
94+ withCwdDefault(globTool as ToolDef, opts.cwd),
95+ withCwdDefault(grepTool as ToolDef, opts.cwd),
96+ withCwdDefault(readTool as ToolDef, opts.cwd),
97+ ];
98+}
src/cli/commands.ts+4−4
@@ -114,7 +114,7 @@ function handlePlan(ctx: CommandContext): void {
114114 ctx.setPlanMode(!ctx.planMode);
115115 if (ctx.planMode) {
116116 writeln(
117- `${PREFIX.info} ${c.yellow("plan mode")} ${c.dim("— agent will describe without running tools")}`,
117+ `${PREFIX.info} ${c.yellow("plan mode")} ${c.dim("— read-only tools + MCP, no writes or shell")}`,
118118 );
119119 } else {
120120 writeln(`${PREFIX.info} ${c.dim("plan mode off")}`);
@@ -264,8 +264,8 @@ type unsafety, resource leaks, race conditions, or security issues.
264264 dead code, missing or misleading comments — only after the above are addressed.
265265
266266 Instructions:
267-- First use \`shell\` to run \`git diff HEAD~1\` (or \`git diff --cached\` if there are staged changes) \
268-to see what changed. Also run \`git log --oneline -5\` for context.
267+- First use \`shell\` to use git diff commands to check for unstaged changes, if not focused \
268+on something else default to reviewing the git diff.
269269 - Use \`glob\`, \`grep\`, and \`read\` as needed to understand the full context of changed files.
270270 - Structure your output with a section per concern level above. \
271271 Use "✔ nothing to flag" for levels with no issues.
@@ -307,7 +307,7 @@ function handleHelp(): void {
307307 const cmds: [string, string][] = [
308308 ["/model [id]", "list or switch models (fetches live list)"],
309309 ["/undo", "remove the last turn from conversation history"],
310- ["/plan", "toggle plan mode (no tool execution)"],
310+ ["/plan", "toggle plan mode (read-only tools + MCP)"],
311311 ["/review [focus]", "run a structured code review on recent changes"],
312312 ["/mcp list", "list MCP servers"],
313313 ["/mcp add <n> <t> [u]", "add an MCP server"],