- Wire Codex plan mode through turn start, including collaboration settings - Track and answer pending `requestUserInput` prompts instead of auto-empty responses - Persist/project thread `interactionMode` (schema, migration, queries) and update tests/contracts
17 KiB
Plan Mode Deep Dive
Goal
Implement plan mode without fighting the architecture that already exists in this repo.
The current app is:
- provider-adapter driven on the server
- orchestration snapshot driven on the client
- already equipped with some plan-adjacent runtime events
- not yet equipped with first-class plan-mode state in the orchestration read model
This document updates the implementation plan to match that reality.
Current Repo Baseline
1. Shared contracts already have some plan primitives
packages/contracts/src/providerRuntime.ts already includes:
turn.plan.updatedcontent.deltawithstreamKind: "plan_text"user-input.requesteduser-input.resolved
Important constraint:
- these are runtime-event primitives only
- there is no first-class provider capability schema
- there is no first-class plan operating mode field
- there is no dedicated final-plan artifact schema
2. Existing runtimeMode is not plan mode
RuntimeMode in packages/contracts/src/orchestration.ts and packages/contracts/src/provider.ts means execution policy:
approval-requiredfull-access
Plan mode must not overload that field.
If we need provider operating mode, it needs a separate concept and separate naming, for example:
interactionModeplanningModeproviderOperatingMode
Anything is acceptable as long as it is not reused from the existing access-policy runtimeMode.
3. Server flow is already canonical-event-first
The current server pipeline is:
- Provider adapters emit
ProviderRuntimeEvents. ProviderServicemultiplexes adapter streams and maintains provider session bindings.ProviderRuntimeIngestiontranslates runtime events into orchestration commands and thread activities.ProjectionPipelinepersists read-model tables.ProjectionSnapshotQueryrebuilds the orchestration snapshot returned byorchestration.getSnapshot.wsServerexposes generic orchestration snapshot, command dispatch, diff, and replay methods.
This matters because plan mode should fit into the same pipeline, not bypass it with a parallel websocket protocol.
Important detail:
wsServerbroadcasts orchestration domain events, not raw provider runtime events- if the web should see plan state live, that state must first become orchestration events and/or projections
4. The current read model has nowhere to put plan mode
OrchestrationThread currently contains:
messagesactivitiescheckpointssessionlatestTurn- thread metadata like title, model, branch, worktree
It does not contain:
- current structured plan snapshot
- accumulated plan-text stream
- pending structured user-input prompt
- resolved structured answers
- provider interactive capabilities
- provider plan/default operating mode
- final approved plan artifact
Today the only flexible place plan data can survive into the web snapshot is activities[].payload.
5. The web app is snapshot-driven, not event-reduced
The client flow today is:
EventRouterlistens toorchestration.domainEvent.- On domain events, it re-fetches
orchestration.getSnapshot. - Zustand stores the latest normalized snapshot.
session-logic.tsderives UI state like pending approvals and work log from thread activities.ChatViewrenders the thread from snapshot state plus those derived selectors.
Important implication:
- plan mode should be added to the orchestration snapshot and/or activity derivation path
- it should not depend on a separate client-side event reducer
6. Current implementation status by provider
Codex
Currently implemented:
turn/plan/updatedmaps toturn.plan.updateditem/plan/deltamaps tocontent.deltawithstreamKind: "plan_text"
Current gap:
item/tool/requestUserInputis currently classified asrequest.openedwith request typetool_user_input- it is not yet upgraded into
user-input.requested - there is no structured answer submission path yet
Claude Code
Currently implemented:
- session/config metadata surfaces through
session.configured - assistant/reasoning text flows through normal runtime content events
- approval requests already bridge into
request.opened/request.resolved
Current gap:
- no current canonical plan-mode mapping
- no current
AskUserQuestionmapping - no current
ExitPlanModemapping
Cursor
Currently implemented:
available_commands_updatemaps tosession.configured- thought/message chunks map to
content.delta - permission requests bridge into approval request events
Current gap:
- no current plan-mode mapping
- no current structured prompt mapping
- no current todo/plan projection
Design Constraints
Keep the current transport model
Plan mode should continue to flow through:
ProviderRuntimeEvent- orchestration commands/events
- projection tables
orchestration.getSnapshotorchestration.domainEvent
Do not introduce provider-specific websocket channels unless the current architecture proves insufficient.
Keep the client snapshot-driven
The client already assumes that server state is re-synced from snapshots. Plan mode should respect that.
That means:
- server-side persistence matters more than clever client buffering
- reconnect behavior should come from projection state, not ad hoc React state
session-logic.tsandChatVieware the main frontend extension seams
Keep approvals separate from structured user input
The current system has a full approval pipeline:
- runtime
request.opened/request.resolved - orchestration
thread.approval.respond - provider
respondToRequest(...)
Plan-mode structured prompts are different and should not be forced into the approval model unless a provider genuinely models them as approval requests.
Preserve raw provider payloads
When adding plan-mode mappings:
- keep
rawon internal canonical runtime events - keep
providerRefson internal canonical runtime events - avoid throwing away native payload shape too early inside adapter/server processing
This does not mean provider-specific payloads should leak into the orchestration read model, websocket API, or web UI.
The boundary should stay:
- adapter/server internals may retain native payloads for correlation, debugging, and future parser improvements
- shared orchestration state and client-visible contracts should expose only canonical plan-mode data
That matters most for Claude and Cursor, where some mappings will be adapter-derived and may need native context during implementation and debugging.
Updated Shared Work Plan
1. Tighten shared contract naming before wiring features
The first step is not to invent a new architecture. It is to formalize the concepts that are currently missing from contracts.
Add a plan operating mode concept
Add a new shared contract for provider plan/default mode.
Requirements:
- do not reuse
RuntimeMode - keep it orthogonal to access policy
- make it available in the server->web read model, not only in raw runtime payloads
Preferred shape:
type ProviderInteractionMode = "default" | "plan";
Add typed provider interactive capabilities
Current session.configured.payload.config is just Record<string, unknown>. That is too weak for capability-driven UI.
Add a typed capability surface in packages/contracts that both server and web can import directly.
Preferred shape:
- exported constant/object keyed by
ProviderKind - exported type derived from that object
- usable by adapters, orchestration code, and frontend rendering logic without duplicating provider capability tables
Minimum fields:
interface ProviderInteractiveCapabilities {
supportsPlanMode: boolean;
supportsStructuredPlanUpdates: boolean;
supportsPlanTextStreaming: boolean;
supportsStructuredUserInput: boolean;
supportsFreeformUserInput: boolean;
supportsPlanAcceptance: boolean;
}
Preferred usage:
- static provider capabilities live in shared contracts
- adapters may still emit dynamic runtime metadata when a capability is session-specific or probe-dependent
- the orchestration snapshot should expose the active provider and any dynamic overrides, not duplicate the full static capability catalog per thread
Add a dedicated structured-answer command path
Current shared commands only support approvals:
thread.approval.respond- provider
respondToRequest(...)
Plan mode needs a distinct path for structured prompt answers.
Preferred additions:
- orchestration command such as
thread.user-input.respond - provider service method such as
respondToUserInput(...) - adapter hook per provider for native answer serialization
Do not overload approval decisions like accept / decline for structured question answers.
2. Extend the orchestration read model
The current read model is the main missing piece.
Plan mode needs first-class projection state so reconnect and refresh behave like the rest of the app.
Add first-class thread plan state
Preferred thread-level additions:
interactionModecurrentPlanpendingUserInputresolvedUserInputs- optional
finalPlanArtifact
The exact nesting can vary, but it should be snapshot-friendly and not require replaying arbitrary activity payloads in the client.
interactiveCapabilities should not be modeled as thread-owned state if they are static per provider.
Preferred split:
- static capabilities: shared contract export keyed by provider
- dynamic per-thread/per-session state: only fields that can actually vary at runtime, such as current interaction mode or active pending prompt
Keep activities as secondary audit trail
thread.activities should still receive plan/user-input activity summaries for timeline/debugging, but it should not be the only source of truth for active plan state.
Projection changes
This likely means:
- new projection repository/table(s) for plan state and prompt state
ProjectionPipelineupdatesProjectionSnapshotQueryreturning the new fields- projection tests for persistence and replay
3. Update runtime ingestion to populate that state
ProviderRuntimeIngestion already knows how to:
- turn assistant text into messages
- turn approval events into activities
- turn
turn.plan.updatedinto an activity
It should be extended to also translate plan/user-input runtime events into read-model state.
Implementation direction:
turn.plan.updatedupdates projected plan snapshotcontent.delta(plan_text)appends to projected plan-text buffer when relevantuser-input.requestedopens a projected pending promptuser-input.resolvedcloses/resolves that prompt- providers that only expose raw/native blobs can still emit synthesized canonical runtime events first, then rely on the shared ingestion path
4. Integrate plan mode into the existing web seams
The web architecture already has the right places.
Store and types
Update:
apps/web/src/types.tsapps/web/src/store.ts
The store should stay thin and snapshot-oriented. It should sync whatever new read-model fields the server exposes.
Derived UI state
Update:
apps/web/src/session-logic.ts
This is the natural place for:
derivePlanState(...)derivePendingUserInput(...)- any fallback derivation from activities during an incremental migration
Rendering
Primary UI seam:
apps/web/src/components/ChatView.tsx
Current UI already has:
- top-of-thread alert stacks for pending approvals
- work-log rendering derived from activities
- timeline rows for messages and work state
That suggests two viable rendering patterns:
- active plan/prompt panel above the timeline
- resolved plan/prompt entries rendered in timeline/history
The route structure does not need to change. Plan mode should remain thread-local state inside the existing chat route.
Provider Implementation Plan
Provider 1: Codex
Codex is closest to the target shape and should be the first end-to-end implementation.
Current status
Already present:
- native structured plan update mapping
- native plan-text stream mapping
Missing:
- native structured prompt mapping for
item/tool/requestUserInput - structured answer submission path
- removal of the current empty-answer auto-ack path in
codexAppServerManager - projection and UI support for the already-emitted plan events
Required work
- Upgrade
item/tool/requestUserInputfrom request-only handling to canonicaluser-input.requested. - Preserve
request.openedas transport/debug metadata when useful. - Add adapter-side answer submission for the corresponding pending request/tool context.
- Emit
user-input.resolvedwhen the answer is submitted or confirmed resolved. - Project the result into the orchestration snapshot.
Codex-specific note
The runtime event schemas already match Codex reasonably well, so this provider should define the canonical end-to-end behavior first.
Provider 2: Claude Code
Claude likely needs tool-aware adaptation rather than pure transport mapping.
Current status
Already present:
- generic session/runtime stream integration
- approval bridging
Missing:
- plan/default operating mode mapping
AskUserQuestion->user-input.requestedExitPlanMode-> final-plan or plan-state handoff
Required work
- Detect plan/default operating mode from Claude-native metadata without touching access-policy
runtimeMode. - Map
AskUserQuestiontool payloads into canonicaluser-input.requested. - Add provider-specific answer serialization for the return path.
- Detect
ExitPlanModeand decide whether it becomes:- a final-plan artifact
- a synthetic structured plan snapshot
- or both
- Avoid over-synthesizing incremental structured plan steps unless Claude gives us enough structure to do it safely.
Provider 3: Cursor
Cursor should start from the same canonical server pipeline, but with a more conservative adapter.
Current status
Already present:
- session/update stream handling
- reasoning/assistant text mapping
- approval bridging
Missing:
- plan/default operating mode mapping
- structured prompt mapping
- structured plan/todo mapping
Required work
- Detect and publish Cursor operating mode separately from access-policy runtime mode.
- Map documented extension methods such as
cursor/ask_questionandcursor/update_todosonly when payloads are confirmed. - Fall back to plan-mode indicator plus normal assistant/reasoning text if structured Cursor plan events are absent.
- Preserve raw ACP payloads so the adapter can improve without changing higher layers.
Frontend Rendering Plan
The frontend should remain capability-driven, but using real repo seams.
Active state
Render from projected snapshot fields:
- current plan/default operating mode
- provider capabilities
- current structured plan
- current plan-text stream
- pending structured prompt
History state
Render from:
- normal messages
- resolved prompt answers
- plan-related activity/history rows
- optional final-plan artifact
Placement
Recommended initial placement:
- Active pending prompt and active plan panel above the timeline, near the current approvals stack.
- Resolved prompt/plan history in the timeline.
This fits the existing ChatView layout with the least architectural churn.
Test Plan
Contracts
Add coverage for:
- new interaction-mode schema
- new capability schema
- new structured-answer command schema
- any read-model additions for active plan/prompt state
Retain existing coverage for:
turn.plan.updatedcontent.delta(plan_text)user-input.requesteduser-input.resolved
Server
Add or extend tests for:
- provider adapter plan/prompt mapping
ProviderRuntimeIngestionplan/prompt projection behaviorProjectionPipelinepersistence and replayProjectionSnapshotQueryreturning active plan state- provider answer submission path
Web
Add or extend tests for:
syncServerReadModelwith new plan fieldssession-logic.tsderivation of active plan/prompt stateChatViewrendering of:- active plan panel
- pending structured prompt
- resolved prompt history
- plan-text fallback
Recommended Execution Order
- Add shared contract types for interaction mode, capabilities, and structured-answer submission.
- Extend orchestration read-model contracts and projection storage for active plan/prompt state.
- Wire
ProviderRuntimeIngestioninto those projections. - Finish Codex end-to-end first, since it already emits most of the canonical runtime pieces.
- Add frontend snapshot sync, derivation, and rendering in
types.ts,store.ts,session-logic.ts, andChatView.tsx. - Add Claude adapter mapping.
- Add Cursor adapter mapping and fallback behavior.
Short version
The repo is already close in one specific sense: the runtime event vocabulary for plans and structured prompts exists.
The real missing architecture is:
- a separate plan/default operating mode concept
- typed provider capabilities
- a first-class structured-answer command path
- read-model projection for active plan/prompt state
- web rendering sourced from that snapshot state
That is the shape the implementation should follow.