Skip to content

feat: operator-driven plan-approval gate (present plan → iterate → approve → execute), reusing the guardrail approve-once seam #206

Closed

Description

@JAORMX

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 (planModeDecision only denies mutatingTools + 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):

  1. Model in ModePlan calls PresentPlan(plan text).
  2. Dispatcher type-asserts tool.PlanPresenter → surfacePlanAsk (sibling of askHookApproval): builds PendingAsk{PlanOriginated:true, Tool:"PresentPlan", Args:planText, Call:c.ID}, calls shared surfaceAsk.
  3. PauseForApproval → StateAwaiting → EvPermissionAsk. Run parks.
  4. Operator ApproveRun(askID, verdict). Same-process channel path or resumeFromAwaiting — both unchanged.
  5. ResumeApproval → driveFromAwaiting → resolvePendingCall. The ask.PlanOriginated branch (mirrors the ask.HookOriginated branch): Allow → synthesize the PresentPlan result ("Plan approved by operator. Proceeding in mode."), set a run-scoped planApprovedTarget on *Run. Deny → synthesize a deny result; the runLoop continues (model can revise).
  6. runLoop: after dispatch, if planApprovedTarget != "", terminate with StopPlanApproved (a string passthrough, mirrors StopNoProgress/StopBudget — no proto enum, no task generate). Do NOT loop back to the model.
  7. At terminate (StopPlanApproved → completed): call sess.SetMode(target) — legal from completed. Persist.
  8. Next run: continuation prompt → StartRunContent → engineAndWorkspaceFor CASE 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 in ModePlan (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-tier plan_mode_auto_approve flag fires ApprovePlan on plan-mode StopEndTurn. 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: ApprovePlan returns FAILED_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 (mirrors TestPreBlockSetsAskApproval)
  • TestPlanApprovalAllowOnceFlipsModeAndTerminates
  • TestPlanApprovalAllowAlwaysFlipsToAcceptEdits
  • TestPlanApprovalDenyContinuesInPlanMode
  • TestResumePlanApprovalAfterRestartExecutesAndFlips (mirrors TestApproveAfterRestartE2E + the guardrail restart test — pins the serialized PlanOriginated marker as cross-process load-bearing)
  • TestPlanApprovalDoesNotFlipMidTurn (pins the SetMode-never-from-Running/Awaiting invariant)
  • TestPlanApprovalRebuildsEngineViaFactory (after flip, next StartRunContent triggers engineAndWorkspaceFor CASE 1)

Session:

  • TestPendingAskPlanOriginatedRoundTrips / TestPendingAskPlanOriginatedOmitemptyWhenFalse (mirror the HookOriginated pair)

Composition/server:

  • TestSetModeRejectedWhileAwaitingPlanApproval (the flip must come through Approve, not a racing SetMode)
  • TestApprovePlanAfterRestartE2E (two-Build offline, plan-ask parked in svc1, Approve in 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

  1. PresentPlan tool 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 the PresentPlan tool 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 the PresentPlan tool — it solves the UX problem with a read-only tool that is not the rejected ExitPlanMode. Confirm.
  2. AskOrigin enum vs. third bool. The PendingAsk doc-comment already budgeted for extracting an enum at the third provenance. Cleaner long-term vs. minimum diff. Confirm preference.
  3. ApprovePlan convenience 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.
  4. Service auto-continue on StopPlanApproved. Client-driven continuation (observe StopPlanApproved → 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.md gauntlet ACP: accept client-provided streaming-HTTP MCP servers #7 (plan mode is a hook-enforced toolset)

Activity

  1. JAORMX commented on Jul 21, 2026

    @JAORMX
    ContributorAuthor

    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: PresentPlan tool (not ExitPlanMode), serialized AskOrigin enum (per the session.go:230-231 contract), ApprovePlan convenience RPC shipped in v1, and auto-continue default-off (client-driven, with the opt-in operator-tier plan_mode_auto_approve flag for headless). ADR 0069 records the decision.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions