Skip to content

feat: enhance Plan mode with 5-phase workflow, hard enforcement, and user approval#61

Merged
yishuiliunian merged 3 commits intomainfrom
feat/plan-mode-enhancement
Apr 2, 2026
Merged

feat: enhance Plan mode with 5-phase workflow, hard enforcement, and user approval#61
yishuiliunian merged 3 commits intomainfrom
feat/plan-mode-enhancement

Conversation

@yishuiliunian
Copy link
Copy Markdown
Contributor

Summary

  • Align Plan mode with Claude Code's plan→approve→execute pattern
  • Add PlanFile management (slug generation, collision retry, path matching)
  • Add PlanModeState for atomic pre-plan snapshot/restore
  • Add hard tool enforcement (dual-layer: LLM-side + runtime-side)
  • Add 5-phase Fragment workflow (Explore→Design→Review→Write→Approve)
  • Add 26 new tests across 3 files

Changes

New files:

  • crates/loopal-runtime/src/plan_file.rs — PlanFile struct, slug generation, path matching, tool filter, reminder
  • crates/loopal-runtime/src/agent_loop/tools_plan.rs — EnterPlanMode/ExitPlanMode interception, state management

Modified:

  • agent_loop/mod.rs — PlanModeState struct, AgentConfig.plan_state field
  • agent_loop/tools.rs — system-reminder wrapping for plan mode tool results
  • agent_loop/tools_check.rs — hard enforcement: plan_tool_filter + Write/Edit path restriction
  • agent_loop/llm_params.rs — LLM-side tool filtering in plan mode
  • agent_loop/runner.rs — PlanFile instance on AgentLoopRunner
  • frontend/traits.rs — PlanApproval enum, request_plan_approval() trait method
  • mode.rs — Plan suffix returns empty (Fragment handles instructions)
  • plan-5phase.md — Full 5-phase workflow with correct AskUser tool name

Tests:

  • tests/suite/plan_file_test.rs — 12 unit tests for PlanFile
  • tests/agent_loop/plan_mode_test.rs — 6 integration tests for Enter/Exit
  • tests/agent_loop/plan_mode_filter_test.rs — 3 integration tests for tool filtering

Test plan

  • bazel test //crates/loopal-runtime:loopal-runtime_test — 26 plan tests pass
  • bazel build //... — full build passes
  • CI passes

…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
@yishuiliunian yishuiliunian merged commit edfbb3f into main Apr 2, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant