feat: add plan mode for aish#102
Merged
F16shen merged 4 commits intoAI-Shell-Team:mainfrom Apr 14, 2026
Merged
Conversation
Contributor
|
Thanks for the pull request. A maintainer will review it when available. Please keep the PR focused, explain the why in the description, and make sure local checks pass before requesting review. Contribution guide: https://github.com/AI-Shell-Team/aish/blob/main/CONTRIBUTING.md |
Contributor
|
This pull request description looks incomplete. Please update the missing sections below before review. Missing items:
|
5fd6f16 to
604999b
Compare
604999b to
b0bbf90
Compare
Introduce a full plan mode subsystem that lets users ask the AI to produce and revise a structured implementation plan before executing side-effecting work. ## Plan mode core Add a dedicated plan package with: - PlanPhase: NORMAL / PLANNING - PlanApprovalStatus: DRAFT / AWAITING_USER / CHANGES_REQUESTED / APPROVED - PlanModeState serialization, revision tracking, approved snapshot handling, and artifact hash verification - automatic plan artifact creation plus approved snapshot drift detection This makes planning a first-class runtime state instead of an ad-hoc shell toggle. ## Approval workflow Add an exit_plan_mode tool path for the model to signal that a plan is ready for review. When invoked, the shell: - reads the bound plan artifact and builds an approval request - shows a full-screen approval modal with summary, artifact path, and preview - supports approve, request changes, and cancel outcomes - persists approved plan context and detects later edits as plan drift Approved plans now carry a verified snapshot so execution can rely on a stable reviewed plan. ## Planning restrictions Restrict tool access during planning: - visible tools limited to read/search, ask_user, memory, plan writes, and exit_plan_mode - side-effect tools remain blocked - memory mutations are disallowed - only writes to the bound plan artifact are permitted automatically This keeps planning read-heavy and prevents execution from starting before approval. ## Shell and UI integration Integrate plan mode into the interactive shell: - /plan enters planning mode and shows status when already planning - bound plan artifact writes use a dedicated planning label in the shell UI - approval and feedback messages are surfaced through localized prompt UI - prompt/editor/theme surfaces were updated to display plan state cleanly Add a persistent approval modal with plan summary, artifact metadata, and markdown preview support. ## Post-approval execution refinements Refine the interaction flow after the initial plan-mode implementation: - reserve approval for the model-driven exit_plan_mode tool path only - make F2 and /plan exit direct shell-level mode toggles instead of routing through approval - make /plan start show current planning status when already in plan mode - fix Escape cancel in the approval modal so the terminal redraw does not appear stuck - automatically continue into implementation after approval by queueing a follow-up AI turn with the approved plan as execution context This aligns shell mode switching with user expectations while keeping plan approval tied to the reviewed model workflow. ## LLM session integration Add plan-aware LLM session behavior: - inject structured planning reminders while in planning mode - filter visible tools by plan phase - persist plan state through the session store on state transitions - inject approved-plan or changes-requested context back into later model turns ## Search tool refactor Split search functionality into focused tools: - GlobTool for glob-based file matching with common VCS/cache exclusions - GrepTool for recursive text search with safe truncation and result caps This replaces the earlier monolithic search implementation with smaller, clearer tool boundaries. ## Internationalization Externalize user-visible plan mode strings into i18n resources, including: - approval titles, prompts, option labels, hints, and status messages - plan tool text and workflow reminder strings - both en-US and zh-CN coverage ## Tests and maintenance Add focused regression coverage for: - plan state transitions and restrictions - approval request and adapter behavior - shell runtime plan toggling and approval handling - approval modal keyboard behavior - post-approval automatic continuation Also clean up minor lint issues and tighten revision normalization so make lint and make test both pass.
b0bbf90 to
9b5a027
Compare
Remove the new plan-mode emoji labels from en-US and zh-CN strings, add missing trailing newlines to the new plan module files, and align the newly added plan-mode tests with the repository timeout convention. This commit is intentionally limited to low-cost review follow-ups only. It does not change plan approval behavior, followup execution flow, or session plan-state semantics. Validation run: /home/lixin/workspace/aishell/aish/.venv/bin/python -m pytest tests/test_plan_mode.py tests/shell/runtime/test_shell_pty_core.py tests/shell/ui/test_shell_prompt_io.py tests/terminal/interaction/test_plan_approval.py
Move plan approval ownership into ExitPlanModeTool and remove the shell-owned followup bridge so approved plans continue through the normal tool/session lifecycle. Add EnterPlanModeTool, expose it from LLMSession, and allow re-entering planning when approved-plan drift is detected. Simplify AI question handling back to a single request/response path and update shell/runtime regressions for the new approval flow. Validation: python -m pytest tests/test_plan_mode.py tests/shell/runtime/test_shell_pty_core.py tests/terminal/interaction/test_plan_approval.py (64 passed)
Remove an unused intermediate assignment in ExitPlanModeTool and drop unused imports from the PTY shell runtime test module. Validation: make lint
jexShain
approved these changes
Apr 14, 2026
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
This PR introduces a first-class plan mode workflow for aish, including plan
state persistence, plan approval, planning-specific tool restrictions, and a
reviewed-plan execution handoff.
It also includes follow-up interaction fixes from manual testing so shell-level
mode switching behaves predictably and approved plans automatically continue
into implementation.
Plan Mode
Core state machine
Add a dedicated plan subsystem under src/aish/plan/ with:
and SHA-256 integrity verification
This turns planning into an explicit runtime lifecycle instead of a loose shell
state.
Approval workflow
Add an exit_plan_mode tool path that the model uses when the plan is ready for
review.
The shell then:
Approved plans are snapshotted and verified so implementation can rely on the
reviewed version of the plan.
Tool restrictions while planning
During planning, visible tools are narrowed to planning-safe operations:
Side-effecting execution tools remain blocked, and only writes to the active
plan artifact are auto-approved.
Shell and UI Integration
Integrate plan mode into the shell runtime and prompt UI:
Post-Approval Flow Refinements
Based on manual validation after the first implementation, this PR also refines
how mode switching and plan approval interact:
through approval
stuck
follow-up AI turn using the approved plan as execution context
This keeps approval tied to plan review while making shell controls behave more
predictably.
LLM Session Integration
Update the LLM session to be plan-aware:
Search Tool Refactor
Split the earlier search implementation into focused tools:
Internationalization
Externalize user-visible plan mode strings into en-US and zh-CN resources,
covering approval UI, plan tool text, status messages, and workflow reminders.
Tests
Added and updated regression coverage for:
Validation