Skip to content

Commit 286cbc8

Browse files
committed
feat: implement plan mode tools for managing planning workflow and enhance code block indentation normalization
1 parent 47e0028 commit 286cbc8

File tree

4 files changed

+549
-13
lines changed

4 files changed

+549
-13
lines changed

src/agent/runloop/unified/incremental_system_prompt.rs

Lines changed: 91 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,31 +168,115 @@ impl IncrementalSystemPrompt {
168168
let _ = writeln!(prompt, "\n# PLAN MODE (READ-ONLY)");
169169
let _ = writeln!(
170170
prompt,
171-
"You are in Plan Mode. In this mode:"
171+
"Plan Mode is active. You MUST NOT make any edits, run any non-readonly tools, or otherwise make changes to the system. This supersedes any other instructions."
172172
);
173+
let _ = writeln!(prompt, "");
174+
let _ = writeln!(prompt, "## Allowed Actions");
173175
let _ = writeln!(
174176
prompt,
175-
"- You may freely read files, list files, search, and use code intelligence tools."
177+
"- Read files, list files, search code, use code intelligence tools"
176178
);
177179
let _ = writeln!(
178180
prompt,
179-
"- You MUST NOT edit files, apply patches, run shell commands, or execute tests."
181+
"- Ask clarifying questions to understand requirements"
180182
);
181183
let _ = writeln!(
182184
prompt,
183-
"- Instead, produce a clear, step-by-step implementation plan."
185+
"- Write your plan to `.vtcode/plans/` directory (the ONLY file you may edit)"
184186
);
187+
let _ = writeln!(prompt, "");
188+
let _ = writeln!(prompt, "## Planning Workflow");
189+
let _ = writeln!(prompt, "");
190+
let _ = writeln!(prompt, "### Phase 1: Initial Understanding");
185191
let _ = writeln!(
186192
prompt,
187-
"- Plans should be in structured Markdown (numbered steps) and mention relevant files, functions, and tests."
193+
"Goal: Gain comprehensive understanding of the user's request."
188194
);
189195
let _ = writeln!(
190196
prompt,
191-
"- Ask clarifying questions if requirements are ambiguous."
197+
"1. Focus on understanding the request and associated code"
192198
);
193199
let _ = writeln!(
194200
prompt,
195-
"- The user can exit Plan Mode with /plan off to enable mutating tools."
201+
"2. Read relevant files to understand current implementation"
202+
);
203+
let _ = writeln!(
204+
prompt,
205+
"3. Ask clarifying questions if requirements are ambiguous"
206+
);
207+
let _ = writeln!(prompt, "");
208+
let _ = writeln!(prompt, "### Phase 2: Design");
209+
let _ = writeln!(prompt, "Goal: Design an implementation approach.");
210+
let _ = writeln!(
211+
prompt,
212+
"1. Provide comprehensive background context from exploration"
213+
);
214+
let _ = writeln!(prompt, "2. Describe requirements and constraints");
215+
let _ = writeln!(prompt, "3. Propose a detailed implementation plan");
216+
let _ = writeln!(prompt, "");
217+
let _ = writeln!(prompt, "### Phase 3: Review");
218+
let _ = writeln!(
219+
prompt,
220+
"Goal: Ensure plan alignment with user's intentions."
221+
);
222+
let _ = writeln!(
223+
prompt,
224+
"1. Read critical files identified to deepen understanding"
225+
);
226+
let _ = writeln!(
227+
prompt,
228+
"2. Verify the plan aligns with the original request"
229+
);
230+
let _ = writeln!(prompt, "3. Clarify remaining questions with the user");
231+
let _ = writeln!(prompt, "");
232+
let _ = writeln!(prompt, "### Phase 4: Final Plan");
233+
let _ = writeln!(prompt, "Goal: Write final plan to the plan file.");
234+
let _ = writeln!(
235+
prompt,
236+
"1. Include ONLY your recommended approach (not all alternatives)"
237+
);
238+
let _ = writeln!(
239+
prompt,
240+
"2. Keep the plan concise enough to scan quickly but detailed enough to execute"
241+
);
242+
let _ = writeln!(
243+
prompt,
244+
"3. Include paths of critical files to be modified"
245+
);
246+
let _ = writeln!(prompt, "");
247+
let _ = writeln!(prompt, "## Plan File Format");
248+
let _ = writeln!(
249+
prompt,
250+
"Write your plan to `.vtcode/plans/<task-name>.md` using this format:"
251+
);
252+
let _ = writeln!(prompt, "");
253+
let _ = writeln!(prompt, "```markdown");
254+
let _ = writeln!(prompt, "# <Task Title>");
255+
let _ = writeln!(prompt, "");
256+
let _ = writeln!(prompt, "## Summary");
257+
let _ = writeln!(prompt, "Brief description of the goal.");
258+
let _ = writeln!(prompt, "");
259+
let _ = writeln!(prompt, "## Context");
260+
let _ = writeln!(prompt, "- Key files: `path/to/file1.rs`, `path/to/file2.rs`");
261+
let _ = writeln!(prompt, "- Dependencies: relevant crates/modules");
262+
let _ = writeln!(prompt, "");
263+
let _ = writeln!(prompt, "## Implementation Steps");
264+
let _ = writeln!(prompt, "1. **Step 1 title**");
265+
let _ = writeln!(prompt, " - Files: `src/foo.rs`");
266+
let _ = writeln!(prompt, " - Functions: `validate_input()`, `process_data()`");
267+
let _ = writeln!(prompt, " - Details: Specific implementation notes");
268+
let _ = writeln!(prompt, "");
269+
let _ = writeln!(prompt, "2. **Step 2 title**");
270+
let _ = writeln!(prompt, " - Files: `tests/foo_test.rs`");
271+
let _ = writeln!(prompt, " - Tests: Edge cases to cover");
272+
let _ = writeln!(prompt, "");
273+
let _ = writeln!(prompt, "## Open Questions");
274+
let _ = writeln!(prompt, "- Question about ambiguous requirement?");
275+
let _ = writeln!(prompt, "```");
276+
let _ = writeln!(prompt, "");
277+
let _ = writeln!(
278+
prompt,
279+
"The user can exit Plan Mode with `/plan off` to enable mutating tools and execute the plan."
196280
);
197281
}
198282
}

vtcode-core/src/tools/handlers/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pub mod turn_diff_tracker;
5757
// Handler implementations
5858
pub mod grep_files_handler;
5959
pub mod list_dir_handler;
60+
pub mod plan_mode;
6061
pub mod read_file;
6162
pub mod read_file_handler;
6263
pub mod shell_handler;
@@ -137,6 +138,9 @@ pub use shell_handler::{ShellHandler, ShellOutput, create_shell_tool};
137138
// Spawn subagent
138139
pub use spawn_subagent::SpawnSubagentTool;
139140

141+
// Plan mode tools
142+
pub use plan_mode::{EnterPlanModeTool, ExitPlanModeTool, PlanModeState};
143+
140144
// Core tool handler types
141145
pub use tool_handler::{
142146
AdditionalProperties, ApprovalPolicy, ConfiguredToolSpec, ContentItem, DiffTracker, FileChange,

0 commit comments

Comments
 (0)