Skip to content

feat: Added plan_exit tool via question to switch from Plan to Build. - #55123

Closed
ShogunPanda wants to merge 3 commits into
anomalyco:devfrom
ShogunPanda:plan-to-build
Closed

ShogunPanda wants to merge 3 commits into
anomalyco:devfrom
ShogunPanda:plan-to-build

Conversation

@ShogunPanda

@ShogunPanda ShogunPanda commented Oct 13, 2026 •

Copy link
Copy Markdown

Issue for this PR

Reimplementation of #49218 on v2.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Add an explicit, user-approved Plan-to-Build handoff in V2. Plan can request approval through the existing question UI, then continue implementation in the same session while preserving conversation history and the selected model.

Changes:

  • Register plan_exit in the Plan plugin and update planning reminders to use it instead of ordinary confirmation questions.
  • Switch to Build only on explicit approval; declining keeps Plan active, while dismissal stops execution.
  • Restrict handoffs to top-level Plan sessions with an available, visible primary-capable Build agent.
  • Document the workflow and add regression coverage for approval, rejection, dismissal, and invalid handoffs.

No plan file or public API changes are required. Ordinary question responses do not switch agents.

How did you verify your code works?

Tested manually.

Screenshots / recordings

If this is a UI change, please include a screenshot or recording.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

If you do not follow this template your PR will be automatically rejected.

Assisted-By: OpenAI:GPT-6.1 Sol <openai/gpt-6.1-sol>


Added by the opencode bot (AI-generated).

Fixes #7801

Related: #49879, #43179

Public API: adds the built-in plan_exit tool and plan_exit permission action for the Plan agent (backwards compatible)

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The handoff works as described, but there's one bug to fix. I ran Plan with the simulated model in the TUI: plan_exit shows the approval dialog, Approve switches the session to Build, and the selected model is kept. On the base the tool doesn't exist. Both changed test files pass and packages/core type-checks.

Public API: adds a built-in tool plan_exit and a plan_exit permission action, allowed for the Plan agent. Both are additions and backwards compatible.

The bug: after you approve, the session sends an extra model request once the model has finished answering (see the inline comment). The approve test doesn't check how many requests were made, so it misses this.

Fixes #7801
Related: #49879, #43179

Before

After

Comment thread packages/core/src/plugin/plan.ts Resolved

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The extra model request after approval is gone: I re-ran the TUI flow with the simulated model and Approve now makes exactly two requests. The approve test now checks the request count. Both changed test files pass and packages/core type-checks.

Public API: unchanged since the last review. The PR adds a built-in tool plan_exit and a plan_exit permission action for the Plan agent, both backwards compatible.

One new concern from the fixup: the Build ("leave") reminder is no longer saved for any switch away from Plan, including manual ones. It is now re-inserted near the end of every later Build request. See the inline comment.

Fixes #7801
Related: #49879, #43179

Before

After

Comment thread packages/core/src/plugin/plan.ts Resolved

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both earlier concerns are resolved. Approving plan_exit no longer sends an extra model request: in the TUI with the simulated model, an extra queued response went unused. The Build reminder is now saved once for both plan_exit and manual switches, without starting another step, so later requests reuse the same history instead of re-inserting it. The new runner tests cover both cases. Both changed test files pass and packages/core type-checks.

Public API: adds a built-in tool plan_exit and a plan_exit permission action for the Plan agent. Both are additions and backwards compatible.

No further concerns.

Fixes #7801
Related: #49879, #43179

Before

After

@ShogunPanda
ShogunPanda force-pushed the plan-to-build branch 2 times, most recently from c443407 to 4d271f9 Compare October 21, 2026 14:40

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new commits only rebase this onto the latest dev. plan.ts, the docs and the fixups are unchanged, and the only difference is one moved import in session-runner.test.ts. On the rebased head the handoff still works in the TUI with the simulated model. Approve switches to Build with no extra model turn, and on dev alone the plan_exit call fails. The plan and session-runner tests pass, and the core package type-checks when I run tsgo directly.

Public API: adds a built-in tool plan_exit and a plan_exit permission action for the Plan agent. Both are additions and backwards compatible.

No new concerns.

Before

After

Signed-off-by: Paolo Insogna <[email protected]>
Signed-off-by: Paolo Insogna <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

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.

[FEATURE]: Plan Mode + Question tool can auto switch to Build mode

1 participant