Repository navigation
Description
Problem
mecatl has plan mode (enforced at three layers: catalog filter, governance.planModeDecision, prompt suffix), a smooth operator-driven mode switch (Alt+M / SetMode RPC / session/set_mode), and the opusplan model swap (plan slot → reasoning model, same session, history preserved). What it lacks is the Claude Code "present plan → iterate → approve → execute" loop:
- No structured "plan ready" signal — the plan is just ordinary assistant text; the operator can't tell "model is thinking" from "model has finished the plan."
- No plan-specific approval gate. The only approval modal is the per-tool-call permission ask (allow-once/allow-always/deny), which fires mid-dispatch, not on a finished plan.
- "Approve" = manually hit
Alt+M. No "approve this plan" affordance, no structured mark that a plan was accepted at a point, no iteration-vs-approve distinction.
The operator explicitly does not want a model-called ExitPlanMode tool (the Claude Code mechanism). The transition stays operator-driven; the question is the seam that makes an operator-driven transition feel like present→iterate→approve→execute.
Proposed design (UX + seam, synthesized from a UX-expert + architect review)
Core mechanism: reuse the guardrail approve-once pattern (ADR 0062)
The guardrail PreToolUse block→ask path already does exactly "surface an out-of-band decision as an ordinary permission ask": blockOutcome returns {Block, AskApproval}, agent.preHook→askHookApproval surfaces it as a PauseForApproval→EvPermissionAsk→Approve, and session.PendingAsk.HookOriginated (serialized) makes the resume path skip preHook re-run. Plan approval reuses this spine verbatim, with a PlanOriginated provenance bit instead of HookOriginated.
Model signal: a read-only PresentPlan tool (NOT ExitPlanMode)
The model signals "plan ready" by calling a read-only PresentPlan tool. This is not the rejected ExitPlanMode:
- It does not flip the mode — the operator drives the flip via
Approve. - It is
ReadOnly()==true, so it passes the plan-mode catalog filter (Catalog.Available(ModePlan)) and the governance plan gate (planModeDecisiononly deniesmutatingTools+ non-read-only Bash). - It gives the structured "plan ready" signal the UX needs — the operator can distinguish "model is still planning" from "model has committed a plan for review."
The tool is a signaling vehicle (like SubmitResult for structured subagent output); its Execute is vestigial — the dispatcher synthesizes both the allow-result and the deny-result. Registered in the plan-mode catalog only (not callable in default/acceptEdits).
State: reuse StateAwaiting + a serialized PlanOriginated bit
No new session state. StateAwaiting + PendingAsk.PlanOriginated (serialized, cross-process load-bearing — exactly like HookOriginated). The entire surfaceAsk spine (register → PauseForApproval → EvPermissionAsk → await → ResumeWith → EvApproval) is reused unchanged.
Note: the existing doc-comment on PendingAsk already says a third provenance is the point to extract a serialized AskOrigin enum. This is that trigger — optionally collapse HookOriginated + PlanOriginated into an enum; a third bool is the minimum-diff alternative.
Approve → mode flip lands at the run terminal boundary, NOT mid-turn
The mid-turn-switch invariant (SetMode rejects from StateRunning/StateAwaiting) is preserved. The verdict resolves the ask; the flip is a consequence that fires when the run reaches a terminal state where SetMode is legal.
Flow (allow path):
- Model in
ModePlancallsPresentPlan(plan text). - Dispatcher type-asserts
tool.PlanPresenter→surfacePlanAsk(sibling ofaskHookApproval): buildsPendingAsk{PlanOriginated:true, Tool:"PresentPlan", Args:planText, Call:c.ID}, calls sharedsurfaceAsk. PauseForApproval→StateAwaiting→EvPermissionAsk. Run parks.- Operator
ApproveRun(askID, verdict). Same-process channel path orresumeFromAwaiting— both unchanged. ResumeApproval→driveFromAwaiting→resolvePendingCall. Theask.PlanOriginatedbranch (mirrors theask.HookOriginatedbranch): Allow → synthesize the PresentPlan result ("Plan approved by operator. Proceeding in mode."), set a run-scopedplanApprovedTargeton*Run. Deny → synthesize a deny result; the runLoop continues (model can revise).runLoop: after dispatch, ifplanApprovedTarget != "", terminate withStopPlanApproved(a string passthrough, mirrorsStopNoProgress/StopBudget— no proto enum, notask generate). Do NOT loop back to the model.- At
terminate(StopPlanApproved→completed): callsess.SetMode(target)— legal fromcompleted. Persist. - Next run: continuation prompt →
StartRunContent→engineAndWorkspaceForCASE 1 (builtForMode=plan ≠ default) rebuilds the engine through the factory → execute model. The plan-slot model swap is the existing CASE 1 mechanism, unchanged.
Verdict → target-mode mapping (reuses the verdict taxonomy meaningfully):
VerdictAllowOnce→ModeDefault("approve; run with normal per-tool asks")VerdictAllowAlways→ModeAcceptEdits("approve; trust its execution, auto-accept edits")VerdictDeny→ no flip; continue inModePlan(iterate)
This gives the operator a single Approve affordance with a natural strength dial, no new verdict enum.
Operator-facing UX (on top of the mechanism)
TUI (plan mode, idle/parked on plan-ask): a footer bar (not a full modal) naming both models:
PLAN MODE · planning on opus · approving will execute on glm-5.2
[A]pprove & run [E]dit-mode approve [type] iterate [Alt+M] cycle mode
A → inline one-line confirm: Approve plan → switch to default mode and run on glm-5.2? [Enter] confirm [Esc] cancel
E → same with accept-edits.
gRPC / HTTP: the primary path composes two existing RPCs (SetMode is NOT used mid-run — the flip is internal to the Approve resume). Recommended convenience: one new ApprovePlan RPC that is atomic (prevents the half-executed SetMode-without-proceed footgun for headless callers):
ApprovePlanRequest { session_id; target_mode: default|acceptEdits; note: string }
→ returns the new Run (streamed like StartRunContent)
HTTP: POST /v1/sessions/{id}:approvePlan. ACP does not get a new method — it composes session/set_mode+session/prompt (documented).
Iterate ("change X"): Deny the plan ask (synthesized "plan not approved" result) → model continues in plan mode → operator sends a new prompt. Or just send a new prompt without denying (the parked ask is abandoned via Interrupt). No new "reject" verb — iterate-with-negation is just a prompt.
Harness-injected proceed message: "Plan approved by operator. Proceed with execution." (+ optional note) — recorded as the user turn that drives execution, same class as the no-progress/background-completion harness notes (event-silent ordinary recorded history).
Honest failure / edge paths
- Headless, no human: plan-mode
EvResult+ no operator = a session awaiting input, not a degradation. Opt-in operator-tierplan_mode_auto_approveflag firesApprovePlanon plan-modeStopEndTurn. Do not wire an LLM auto-reviewer by default (higher stakes than a bash ask). Document loudly: no human reviewed this plan. - Partial approve: not a wire field — iterate with scope. Documented limit (there's no structured plan artifact to subset).
- Approve pressed mid-run:
ApprovePlanreturnsFAILED_PRECONDITION; TUI disables the key and shows the defer line (existing pattern).
Package touches (minimal set)
| Package | Change | Invariant preserved |
|---|---|---|
engine/session |
PendingAsk.PlanOriginated (serialized, or extract AskOrigin enum per the existing comment); StopPlanApproved stop-reason string. |
Domain-only; no adapter/proto import. |
engine/tool |
PresentPlan ToolSpec (read-only); optional PlanPresenter interface (or ToolSpec.PresentsPlan). |
Domain-only; passes plan-mode catalog filter. |
engine/agent |
surfacePlanAsk (sibling of askHookApproval); runLoop terminate-on-planApprovedTarget; resolvePendingCall PlanOriginated resume branch; run-scoped planApprovedTarget on *Run. |
Application; imports only domain+port; reuses surfaceAsk spine unchanged. |
internal/app |
Register PresentPlan in plan-mode catalog; optional Service auto-continue on StopPlanApproved. |
Composition; the ONLY layer touching adapters+agent. engineAndWorkspaceFor CASE 1 unchanged. |
engine/governance |
NO change. planModeDecision already passes read-only tools. |
No new classifier. |
engine/port |
NO change. Ask machinery reused. | No API widening. |
contracts/proto |
NO change (client discriminates on ask.Tool; stop-reason is a string passthrough). Optionally one Added bool. |
No enum, no task generate. |
internal/adapter/server |
NO change to ApproveRun/resumeFromAwaiting/SetMode/engineAndWorkspaceFor — all reused. Optional ApprovePlan convenience RPC + auto-continue hook. |
Existing seams carry it. |
Four layers touched (session, tool, agent, app); governance/port/proto untouched. This is the same surface the guardrail approve-once feature touched (minus the governance hook-outcome and the WaiverHolder — plan approval is one-shot, AllowOnce/AllowAlways map to the target mode, no in-memory waiver).
Tests (mirror the guardrail approve-once test names)
Engine/agent:
TestPresentPlanSurfacesPlanOriginatedAsk(mirrorsTestPreBlockSetsAskApproval)TestPlanApprovalAllowOnceFlipsModeAndTerminatesTestPlanApprovalAllowAlwaysFlipsToAcceptEditsTestPlanApprovalDenyContinuesInPlanModeTestResumePlanApprovalAfterRestartExecutesAndFlips(mirrorsTestApproveAfterRestartE2E+ the guardrail restart test — pins the serializedPlanOriginatedmarker as cross-process load-bearing)TestPlanApprovalDoesNotFlipMidTurn(pins theSetMode-never-from-Running/Awaiting invariant)TestPlanApprovalRebuildsEngineViaFactory(after flip, nextStartRunContenttriggersengineAndWorkspaceForCASE 1)
Session:
TestPendingAskPlanOriginatedRoundTrips/TestPendingAskPlanOriginatedOmitemptyWhenFalse(mirror theHookOriginatedpair)
Composition/server:
TestSetModeRejectedWhileAwaitingPlanApproval(the flip must come throughApprove, not a racingSetMode)TestApprovePlanAfterRestartE2E(two-Buildoffline, plan-ask parked in svc1,Approvein svc2 → flip → continuation run on the execute model)TestPresentPlanFilteredToPlanModeCatalog
ADR
New ADR 0063 (plan-approval seam), referencing ADR 0062 (guardrail approve-once) as the pattern precedent and ADR 0030 (Layer 3 mode→model factory) for the engine rebuild. Supersedes nothing. Living docs to update: docs/architecture.md (plan-mode section) + docs/design/IMPLEMENTATION-NOTES.md (a "Plan approval" subsection beside the guardrails sections).
Open questions to confirm before implementation
PresentPlantool vs. operator-decides. The UX review initially leaned toward "derived plan-ready state (mode==plan && idle && last turn had text), no new tool." The architect review argued for thePresentPlantool because it gives a structured "plan ready" signal the derived state cannot (the operator can't otherwise distinguish "model is thinking out loud" from "model has committed a plan"). I recommend thePresentPlantool — it solves the UX problem with a read-only tool that is not the rejectedExitPlanMode. Confirm.AskOriginenum vs. third bool. ThePendingAskdoc-comment already budgeted for extracting an enum at the third provenance. Cleaner long-term vs. minimum diff. Confirm preference.ApprovePlanconvenience RPC vs. two-step (Approve+StartRunContent). The two-step works today with zero engine change; the convenience RPC prevents the half-executed footgun for headless callers. Confirm whether to ship the RPC in v1 or defer.- Service auto-continue on
StopPlanApproved. Client-driven continuation (observeStopPlanApproved→ send a continuation prompt) is the honest headless default; auto-continue is an opt-in composition flag. Confirm default-off.
Related
- ADR 0062 (guardrail approve-once — the pattern precedent)
- ADR 0030 Layer 3 (mode→model factory — the engine rebuild path)
- ADR 0007 (twelve-patterns audit, pattern 6 explore-plan-act — currently "Gap: None, driven by client"; this issue adds the structured approval surface)
docs/harnesses/08-design-considerations.mdgauntlet ACP: accept client-provided streaming-HTTP MCP servers #7 (plan mode is a hook-enforced toolset)
Activity
JAORMX commentedon Jul 21, 2026
Implemented in #293. The full pipeline ran to completion: architect plan → 6 implementation waves → independent 6-agent review panel (Spec/Standards/Security: zero findings) + QA test-adequacy review → iteration fixing the cross-confirmed findings → green across build, both-module tests, lint,
api:check,docs:check, and the offline demo.All four open questions resolved as recommended:
PresentPlantool (not ExitPlanMode), serializedAskOriginenum (per thesession.go:230-231contract),ApprovePlanconvenience RPC shipped in v1, and auto-continue default-off (client-driven, with the opt-in operator-tierplan_mode_auto_approveflag for headless). ADR 0069 records the decision.fix(plan): make the plan-approval gate discoverable to the model (#206)
feat(plan): show the full plan in the approval modal, scrollable (#206)
fix(plan): iterate pauses for operator feedback instead of free-runni…
fix(plan): word-wrap the plan in the approval modal (#206)
docs(adr): codify the model-visible affordance gate (ADR 0070)
fix(plan): full-screen scrollable plan review, no collapse (#206)
fix(plan): interactive approve actually continues to execution (#206)
feat(plan): operator-driven plan-approval gate (issue #206) (#293)
docs(engine): drop orphaned conflict marker in CHANGELOG (#296)
fix(plan): mechanical follow-ups from the PR-293 post-merge review (#297