feat(tui): add plan mode#12
Merged
Merged
Conversation
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 Report✅ All modified and coverable lines are covered by tests.
🚀 New features to boost your workflow:
|
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.
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
planmode with a separate read-only research pass, checklist plan generation, and aPlanApprovalprompt 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: