For agentic workers: REQUIRED SUB-SKILL: Use systematic debugging for any failed runtime verification, and update this plan before changing code if product semantics change.
Goal: Restore v4 /goal parity with z-code-2 for the visible composer command path: draft-first /goal must set or replace the session target through the goal command channel, queued /goal must stay a goal command, and no /goal command may be downgraded into an ordinary model prompt.
Architecture: Keep goal state owned by the agent/session runtime and surfaced through v4 conversation snapshots. UI parses visible slash commands at the send boundary, then routes them through v4/command. Running or compacting sessions keep the existing command barrier for immediate target writes, but enqueue /goal as a command-aware pending item and consume it only through the goal command path.
Tech Stack: React UI in packages/ui/src/v4, protocol schemas in packages/shared/src/zcode-protocol-v4, bootstrap command handlers in apps/zcode-cli/packages/bootstrap/src/zcode-protocol-v4, core queue/runtime contracts in apps/zcode-cli/packages/contracts and apps/zcode-cli/packages/core.
This plan covers /goal, /target, /goal replace, and /goal resume on the v4 chat composer and queue paths.
Out of scope for this pass:
Multiple system messages that are separated by user/assistant messages failure. That is a provider SDK/version issue and should not be mixed into this fix.direct / quick / grill and ExitGoalSetup approval cards). z-code-2 added that later, but current v4 protocol only exposes sendGoalCommand(text) and resumeGoal./goal show, /goal pause, and /goal clear protocol behavior. The old parser recognized these actions, but v4 has no matching command payloads yet.Current v4 source of truth:
docs/conversation-protocol-declaration.md: /goal xxx sets or updates the session goal; running and compacting /goal xxx append to the queue.docs/testing/conversation-session-goal-specific-coverage-matrix.md: G0/G1/G2 define completed replacement, running queue, queue edit/delete/reorder, send-now, and compact interaction expectations.packages/shared/src/zcode-protocol-v4/command.ts: v4 currently has sendGoalCommand({ text, heldQueueDisposition? }) and resumeGoal({}).packages/shared/src/zcode-protocol-v4/snapshot.ts: queue items already have kind: "sendText" | "sendGoalCommand", with a comment saying /goal stores the user original.apps/zcode-cli/packages/bootstrap/src/zcode-protocol-v4/commands/handlers/goal-compact.ts: sendGoalCommand already implements set/replace by reading existing target, but rejects active turns.packages/ui/src/v4/SessionPane.tsx: slash parsing only runs when sessionId exists, so draft-first /goal falls through to createSession(firstInput) + sendText.z-code-2 evidence:
0e3ad860b fix: route visible slash commands: parsed visible /compact, /goal, and /target at submit boundary; draft/no-task slash commands created or resumed a session first, then ran the session control command instead of sending ordinary prompt text.ea2848b5e fix(ui): preserve queued goal semantics: classified queued prompt kind as goal/compact/text and restored /goal prefix when a queued goal was edited to objective-only text.670951d25 fix(ui): wait for session ready before queue drain: delayed queued command drain until the session active lock actually released.588278603 fix(ui): gate queued prompts on goal completion: active/incomplete goal target blocked queued prompt drain until the goal was complete.2382ca8a2 fix(ui): block active goal queued send now: send-now during active goal output acted like stop/pause first; it did not interleave another command into the active goal turn.d1ac21ceb fix: block goal command while task is running: useful bug rationale that /goal writes session_target and must not bypass a running turn. Its old product decision "block while running" has since been superseded by current docs, which require queueing.9eadd7211 and 696139694: full standalone setup/verifier parity. These are future parity references, not Phase 1 requirements.Draft-first /goal is not parsed.
SessionPane.handleSendText only calls handleSlashCommand when sessionId exists. In a new draft, /goal ... becomes first input and is submitted as ordinary sendText.
Current parser is too narrow.
It recognizes /goal <text> but not /target, /goal replace <text>, or /goal resume.
Running /goal has no command-aware queue path.
sendGoalCommand rejects when record.activeAbortController exists. That barrier is correct for immediate target writes, but running/compacting product semantics require enqueueing the command instead of failing or sending ordinary prompt text.
Queue kind is declared but not preserved from core events.
queueItemSchema supports sendGoalCommand, but product-projection.ts hardcodes TurnSteerQueued items to kind: "sendText".
Core pending-input drain currently injects everything as a user prompt.
drainPendingInput calls persistUserPrompt and messageHistory.addUser for the pending input text. A queued /goal must not pass through this path.
sendQueuedNow always replays as prompt text.
The v4 queue handler reads item text, removes the item, waits idle, then calls startPromptTurn. For a goal queue item, this would again become an ordinary user prompt.
Queue editing can lose command syntax.
z-code-2 restored /goal when a queued goal was edited to just the objective. v4 needs the same behavior, preferably using queueItem.kind as authority.
The composer submit boundary must classify visible slash commands before normal send logic:
composer text + attachments
|
v
slash parser
|-- attachments present --------------------------> sendText
|-- not /goal|/target|/compact --------------------> sendText
|-- /goal or /target -----------------------------> goal command route
|-- /goal resume ----------------------------------> resumeGoal route
For supported goal commands:
/goal <objective> sets a target when none exists./goal <objective> replaces the existing target when one exists./goal replace <objective> maps to the same replace-capable sendGoalCommand payload with objective text stripped of replace./target <objective> is an alias for /goal <objective>./goal resume maps to resumeGoal.sendText./goal is consumed as an unsupported/empty goal command with a UI warning; it must not create an ordinary prompt.State and queue order:
idle/completed, queue empty
/goal A
-> sendGoalCommand(A)
-> set or replace session target
-> start goal continuation when mode allows
running or compacting
/goal B
-> enqueue queue item { kind: sendGoalCommand, text: original or canonical /goal B }
-> no target write yet
-> no model request for B yet
active work becomes ready
queue head sendText
-> existing text drain behavior
queue head sendGoalCommand
-> remove queue item
-> sendGoalCommand(objective)
-> target set/replace + goal continuation
held queue (completed + queue>0 + autoDrain=false)
/goal C
-> require heldQueueDisposition choice
-> clearQueueAndSend: clear queue, then sendGoalCommand(C)
-> keepQueueAndSend: preserve existing queue, then sendGoalCommand(C)
The key invariant is:
queue item kind sendGoalCommand
must never flow into persistUserPrompt/startPromptTurn as raw "/goal ..."
Desktop and web remote boundaries:
desktop-continuous client
-> v4/command
-> existing desktop host/runtime
web-remote-replayable client
-> v4/command through shared-host attachment
-> same owner/runtime boundary
-> replayable snapshot restores queue/target state
No relay/main-process goal state is introduced.
packages/ui/src/v4/slashCommands.ts.sendGoalCommand, resumeGoal, compact, or unsupported;objective for goal set/replace;displayText, preserving the user's visible command when possible;baseRevision.sessionId guard in SessionPane.handleSendText.createSession without firstInput;sendGoalCommand or resumeGoal to the new session;sendText with the raw /goal input.heldQueueDisposition into sendGoalCommand when the composer is in choice mode./compact behavior as currently implemented, but do not broaden this plan into compact rendering changes.Recommended durable path:
TurnSteerInput.commandKind?: "sendText" | "sendGoalCommand";PendingTurnInput.commandKind;TurnSteerQueuedPayload.commandKind.sendText for compatibility.sendGoalCommand is received during active work, enqueue through record.app.steerTurn using:
commandKind: "sendGoalCommand";displayText if protocol carries it, otherwise canonical /goal ${objective});inputId and queryId from the command id.product-projection.ts to set queue.items[].kind from the event command kind.displayText to sendGoalCommand payload is accepted, make it optional and keep text as the parsed objective. This preserves exact /target or /goal replace user text without changing existing callers.Compatibility fallback if core contract churn must be minimized:
sendGoalCommand in projection from queued text starting with /goal or /target.Core pending input auto-drain must distinguish text from commands:
sendGoalCommand, drainPendingInput must not call persistUserPrompt or messageHistory.addUser.turn-stop must not loop forever when queue head is a non-text command:
hasPendingInput checks used for auto-drain with a helper such as hasAutoDrainablePendingInput;autoDrain is true;getQueueItemText with a host method that returns { kind, text }, or add a parallel getQueueItem.sendQueuedNow:
sendText, call startPromptTurn;sendGoalCommand, parse objective from text and call the extracted goal-command execution helper.editQueueItem:
sendGoalCommand and edited text no longer starts with /goal or /target, store either the objective-only text plus kind, or canonicalize to /goal ${objective};reorderQueueItem and deleteQueueItem should remain kind-preserving and side-effect-free.Unit tests:
/goal fix login -> sendGoalCommand objective fix login;/target fix login -> same command;/goal replace fix login -> objective fix login;/goal resume -> resumeGoal;/goal -> not a command;/goal consumed as unsupported/empty./goal creates/promotes a session and dispatches sendGoalCommand, not sendText;/goal dispatches sendGoalCommand;heldQueueDisposition.sendGoalCommand and does not write target immediately.TurnSteerQueued with command kind sendGoalCommand produces queue item kind sendGoalCommand;sendQueuedNow on goal item calls goal command path;Runtime verification:
sess_ec648b58-f3f1-476e-8f2e-c76bffd7735e style draft-first /goal:
session_target has the new objective;/goal ... ordinary user_prompt is sent to the model request;/goal next target;kind=sendGoalCommand;Required checks before commit:
pnpm typecheckpnpm lint/goal <objective>, or should it only surface the target card/banner? z-code-2 preserved the visible command shape, but current v4 acceptance can first assert the stronger invariant: it must not become an ordinary model prompt./goal show, /goal pause, and /goal clear be added to v4 command schema now, or left for full standalone parity?direct / quick / grill) be planned as a separate v4 protocol extension after this command-routing fix?