Skip to content

feat(tui): add plan mode#12

Merged
remarkablemark merged 12 commits into
masterfrom
feat/plan
May 6, 2026
Merged

feat(tui): add plan mode#12
remarkablemark merged 12 commits into
masterfrom
feat/plan

Conversation

@remarkablemark
Copy link
Copy Markdown
Member

What is the motivation for this pull request?

This PR adds a dedicated plan mode to the TUI so the assistant can research with read-only tools, produce an executable checklist plan, and require an explicit mode selection before executing that plan.

What is the current behavior?

The chat flow does not have a planning phase. Tool use happens in the normal chat loop, and there is no separate approval step for moving from planning into execution.

What is the new behavior?

The TUI now supports a plan mode with a separate read-only research pass, checklist plan generation, and a PlanApproval prompt that lets the user continue planning, switch to safe execution, or switch to automatic execution. The chat logic also blocks destructive tool calls during planning, preserves clearer blocked-action messaging, and includes expanded tests that bring coverage to 100%.

Checklist:

Add a third mode option that cycles Safe → Auto → Plan → Safe. In Plan mode, the AI generates a structured plan that must be approved before any tool execution.

Changes:

1. **Constants** - Add `PLAN` mode and system prompt variant for plan generation
2. **Footer.tsx** - Update to show "Plan" mode (purple/magenta color), handle 3-state cycle with Shift+Tab
3. **App.tsx** - Replace `autoExecute` boolean with `mode` state ('safe' | 'auto' | 'plan'), pass `mode` to Chat and Footer
4. **Chat.tsx** - When in Plan mode:
   - On user message, AI can use read-only tools (read_file, list_dir, grep_search, view_range) to research
   - Once research is done, AI generates a plan as markdown checklist (e.g., `- [ ] write_file("src/utils.ts") - Add new function`)
   - Show plan approval UI with 3 choices: "Auto", "Safe", "Cancel"
   - If Auto: execute all write tools in the plan automatically, updating checkboxes as each completes
   - If Safe: execute write tools one-by-one with individual approval prompts
   - If Cancel: abort, stay in Plan mode without executing write tools
5. **New PlanApproval component** - UI showing the generated plan with 3 action options (Auto/Safe/Cancel buttons). Escape key triggers Cancel.
6. **Tests** - Update existing tests, add new tests for plan mode

Files to Modify:

- `src/constants/mode.ts` - Add PLAN mode constant
- `src/constants/prompt.ts` - Plan generation prompt
- `src/components/Footer.tsx` - 3-state mode cycling, show current mode name
- `src/components/App.tsx` - Replace autoExecute with mode state
- `src/components/Chat.tsx` - Accept mode prop, handle plan generation and approval flow
- `src/components/PlanApproval.tsx` - New component
- `src/components/index.ts` - Export new component
- `src/utils/tools.ts` - Categorize tools as read-only vs write
`Chat` now only sets `pendingPlan` when the generated text contains a
checklist step for:

- write_file
- edit_file
- run_shell
Bug: Agent thinks it performed the tool call even though it was blocked

Fix: Changed `Chat` so when `executeTool()` returns `Tool not allowed: ...`,
the follow-up system message now says the tool was blocked, the action was
`NOT performed`, and the assistant must not claim success. That gives the
next model turn explicit state instead of a generic “tool result” shape
that can be misread as completion.
Reminder layer: `PLAN_GENERATION_INSTRUCTION` now explicitly says:
respond with a plan checklist only, do not execute tools, and do not
claim any action was performed.

Enforcement layer: Plan mode now intercepts any non-read-only tool
call before execution and feeds back a system correction telling the
model to continue with read-only research and then display the unchecked
checklist only.
So it stays in the same directive/status style throughout.

The main change was replacing `Error: ...` with `Blocked because ...`,
which fits the no-period policy lines better.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
src/components/App.tsx 100.00% <100.00%> (ø)
src/components/Chat/Chat.tsx 100.00% <100.00%> (ø)
src/components/Chat/Input.tsx 100.00% <100.00%> (ø)
src/components/Chat/constants.ts 100.00% <100.00%> (ø)
src/components/Chat/plan.ts 100.00% <100.00%> (ø)
src/components/Footer.tsx 100.00% <100.00%> (ø)
src/components/PlanApproval.tsx 100.00% <100.00%> (ø)
src/constants/mode.ts 100.00% <100.00%> (ø)
src/constants/prompt.ts 100.00% <100.00%> (ø)
src/utils/agents.ts 100.00% <100.00%> (ø)
... and 1 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@remarkablemark remarkablemark self-assigned this May 6, 2026
@remarkablemark remarkablemark added the enhancement New feature or request label May 6, 2026
@remarkablemark remarkablemark merged commit 0ab2e9e into master May 6, 2026
15 checks passed
@remarkablemark remarkablemark deleted the feat/plan branch May 6, 2026 02:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant