Skip to content

feat: add plan mode for aish#102

Merged
F16shen merged 4 commits intoAI-Shell-Team:mainfrom
F16shen:plan-ui-persistent-application
Apr 14, 2026
Merged

feat: add plan mode for aish#102
F16shen merged 4 commits intoAI-Shell-Team:mainfrom
F16shen:plan-ui-persistent-application

Conversation

@F16shen
Copy link
Copy Markdown
Collaborator

@F16shen F16shen commented Apr 14, 2026

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:

  • PlanPhase: NORMAL / PLANNING
  • PlanApprovalStatus: DRAFT / AWAITING_USER / CHANGES_REQUESTED / APPROVED
  • PlanModeState serialization, revision tracking, approved snapshot handling,
    and SHA-256 integrity verification
  • automatic plan artifact creation and approved snapshot drift detection

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:

  • reads the bound plan artifact automatically
  • builds an approval request with summary, artifact path, and preview content
  • presents a full-screen approval modal
  • supports approve, request changes, and cancel outcomes
  • persists approved plan context and detects later plan drift

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:

  • read/search tools
  • ask_user
  • memory search/list
  • writes to the bound plan artifact
  • exit_plan_mode

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:

  • /plan enters planning mode and shows status when already planning
  • plan artifact writes are surfaced with a dedicated planning label
  • approval interactions are localized and rendered in a full-screen modal
  • prompt/editor/theme surfaces were updated to reflect plan mode cleanly

Post-Approval Flow Refinements

Based on manual validation after the first implementation, this PR also refines
how mode switching and plan approval interact:

  • reserve approval for the model-driven exit_plan_mode workflow only
  • make F2 and /plan exit direct shell-level mode toggles instead of routing
    through approval
  • make /plan start show planning status when already in plan mode
  • fix Escape cancel in the approval modal so the terminal redraw does not look
    stuck
  • automatically continue into implementation after approval by queueing a
    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:

  • inject structured planning reminders while in planning mode
  • filter visible tools by plan phase
  • persist plan state through the session store on every transition
  • inject approved-plan or changes-requested context into later model turns

Search Tool Refactor

Split the earlier search implementation into focused tools:

  • GlobTool for glob-based matching with VCS/cache exclusions
  • GrepTool for recursive text search with truncation and match caps

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:

  • plan state transitions and restrictions
  • approval request building and response adaptation
  • shell runtime plan toggling and approval handling
  • approval modal keyboard behavior
  • automatic continuation after approval

Validation

  • make lint
  • make test

@github-actions
Copy link
Copy Markdown
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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 14, 2026

This pull request description looks incomplete. Please update the missing sections below before review.

Missing items:

  • User-visible Changes
  • Compatibility
  • Testing
  • Change Type
  • Scope

@F16shen F16shen requested a review from jexShain April 14, 2026 02:26
@F16shen F16shen force-pushed the plan-ui-persistent-application branch from 5fd6f16 to 604999b Compare April 14, 2026 02:33
@F16shen F16shen changed the title Refine plan mode exits and auto-continue approved plans feat: add plan mode for aish Apr 14, 2026
@F16shen F16shen force-pushed the plan-ui-persistent-application branch from 604999b to b0bbf90 Compare April 14, 2026 02:34
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.
@F16shen F16shen force-pushed the plan-ui-persistent-application branch from b0bbf90 to 9b5a027 Compare April 14, 2026 02:45
F16shen added 3 commits April 14, 2026 14:51
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
@F16shen F16shen merged commit 411396b into AI-Shell-Team:main Apr 14, 2026
9 checks passed
@F16shen F16shen deleted the plan-ui-persistent-application branch April 14, 2026 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants