feat: enhance Plan mode with 5-phase workflow, hard enforcement, and user approval#61
Merged
yishuiliunian merged 3 commits intomainfrom Apr 2, 2026
Merged
Conversation
…user approval (#60) Align Plan mode with Claude Code's plan-approve-execute pattern: - PlanFile: session-scoped plan file with slug collision retry, path matching for relative/absolute paths, and read with NotFound vs IO error distinction - PlanModeState: atomic snapshot of pre-plan mode/permission/tool-filter, restored on ExitPlanMode via take() — prevents inconsistent partial state - EnterPlanMode: user consent, sub-agent guard, mkdir rollback on failure - ExitPlanMode: validates mode + plan file, reads plan, requests approval via Frontend trait, injects approved plan into tool_result context - Hard enforcement: dual-layer tool filtering (LLM-side via llm_params + runtime-side via tools_check), Write/Edit path-restricted to plan file - System-reminder: wraps non-intercepted tool results with plan mode rules - Fragment: 5-phase workflow (Explore→Design→Review→Write→Approve) - mode.system_prompt_suffix() returns empty for Plan to avoid conflict with Fragment instructions - 26 new tests across 3 files covering PlanFile, Enter/Exit interception, tool filtering, and system-reminder wrapping
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Changes
New files:
crates/loopal-runtime/src/plan_file.rs— PlanFile struct, slug generation, path matching, tool filter, remindercrates/loopal-runtime/src/agent_loop/tools_plan.rs— EnterPlanMode/ExitPlanMode interception, state managementModified:
agent_loop/mod.rs— PlanModeState struct, AgentConfig.plan_state fieldagent_loop/tools.rs— system-reminder wrapping for plan mode tool resultsagent_loop/tools_check.rs— hard enforcement: plan_tool_filter + Write/Edit path restrictionagent_loop/llm_params.rs— LLM-side tool filtering in plan modeagent_loop/runner.rs— PlanFile instance on AgentLoopRunnerfrontend/traits.rs— PlanApproval enum, request_plan_approval() trait methodmode.rs— Plan suffix returns empty (Fragment handles instructions)plan-5phase.md— Full 5-phase workflow with correct AskUser tool nameTests:
tests/suite/plan_file_test.rs— 12 unit tests for PlanFiletests/agent_loop/plan_mode_test.rs— 6 integration tests for Enter/Exittests/agent_loop/plan_mode_filter_test.rs— 3 integration tests for tool filteringTest plan
bazel test //crates/loopal-runtime:loopal-runtime_test— 26 plan tests passbazel build //...— full build passes