feat(tui): add clear-context plan implementation#17499
Merged
fcoury-oai merged 8 commits intomainfrom Apr 17, 2026
Merged
Conversation
Add a second Plan Mode approval option that starts a fresh cleared thread and submits the approved plan as the initial implementation prompt. Keep the existing same-context implementation option first and unchanged while reusing the established clear-session flow for the new path.
Document the fresh-context Plan Mode handoff so reviewers can see that only the approved plan is carried into the new thread. Call out the initial-message timing contract that prevents replayed history from racing with the implementation prompt.
Require the same Default-mode availability for the fresh-context implementation path as the existing same-thread implementation action. This keeps the Plan Mode approval popup from offering a coding handoff when the new thread would fall back to another visible mode.
Add the required `plan_markdown` argument comment in the Plan Mode regression test so the argument-comment lint can pass. This keeps the Default-mode availability coverage unchanged while satisfying the repo's literal argument convention.
Remove the explicit lifetime from the clear-context plan helper so Clippy accepts the TUI target under the Bazel lint configuration. The helper still returns the approved plan borrowed from the cached plan markdown; this only lets Rust infer the same relationship.
Extract the Plan Mode implementation popup construction into a focused `chatwidget` submodule so the large widget file stays on orchestration. The refactor preserves the existing popup behavior while keeping the clear-context handoff prompt and disabled-state checks close together.
aibrahim-oai
approved these changes
Apr 17, 2026
Frame the fresh-context implementation prompt as a prior agent plan handoff so the model sees the plan as task intent.
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
TL;DR
Yes, implement this planaction unchanged./clearthread-start path and submits the approved plan as the fresh thread's first prompt.Problem
Plan Mode already asks whether to implement an approved plan, but the only affirmative path continues in the same thread. That is useful when the planning conversation itself is still valuable, but it does not support the workflow where exploratory planning context is discarded and implementation starts from the final approved plan as the only model-visible handoff.
Mental model
There are now two implementation choices after a proposed plan. The existing choice,
Yes, implement this plan, is unchanged: it switches to Default mode and submitsImplement the plan.in the current thread. The new choice,Yes, clear context and implement, treats the proposed plan as a handoff artifact. It clears the UI/session context through the same thread-start source used by/clear, then submits an initial prompt containing the approved plan after the fresh thread is configured.The important distinction is that the new path is not compaction. The model receives a deliberate implementation prompt built from the approved plan markdown, not a summary of the previous planning transcript. Both implementation choices require the Default collaboration preset to be available, so the popup does not offer a coding handoff when the fresh thread would fall back to another mode.
Non-goals
This change does not alter
/clear,/compact, or the existing same-context Plan Mode implementation option. It does not add protocol surface area or app-server schema changes. It also does not carry the previous transcript path or a generated planning summary into the new model context.Tradeoffs
The fresh-context option relies on the approved plan being sufficiently complete. That matches the Plan Mode contract, but it means vague plans will produce weaker implementation starts than a compacted transcript would. The upside is that rejected ideas, exploratory dead ends, and planning corrections do not leak into the implementation turn.
The current implementation stores the latest proposed plan in
ChatWidgetrather than deriving it from history cells at selection time. This keeps the popup action simple and deterministic, but it makes the cache lifecycle important: it must be reset when a new task starts so an old plan cannot be submitted later.Architecture
The TUI stores the most recent completed proposed-plan markdown when a plan item completes. The Plan Mode approval popup uses that cache to enable the fresh-context option and to build a first-turn prompt that instructs the model to implement the approved plan in a fresh context.
Selecting the new option emits a TUI-internal
ClearUiAndSubmitUserMessageevent.Apphandles that event by reusing the existing clear flow: clear terminal state, reset app UI state, start a new app-server thread withThreadStartSource::Clear, and attach a replacementChatWidgetwith an initial user message. The existing initial-message suppression inenqueue_primary_thread_sessionensures the prompt is submitted only after the new session is configured and any startup replay is rendered.Observability
The previous thread remains resumable through the existing clear-session summary hint. There is no new telemetry or protocol event for this path, so debugging should start at the TUI event boundary: confirm the popup emitted
ClearUiAndSubmitUserMessage, confirm the app-server thread start usedThreadStartSource::Clear, then confirm the fresh widget submitted the initial user message afterSessionConfigured.Tests
The Plan Mode popup snapshots cover the new option and preserve the original option as the first/default action. Unit coverage verifies the original same-context option still emits
SubmitUserMessageWithMode, the new option emitsClearUiAndSubmitUserMessagewith the approved plan embedded verbatim, and the clear-context option is disabled when Default mode is unavailable or no approved plan exists. The broadercodex-tuitest package passes with the updated fresh-thread initial-message plumbing.