Files
orca/src/shared/agent-session-runtime-capabilities.ts
T
Brennan Benson 0d94c0ba8f Native chat: queue messages sent while the agent works (on by default, Settings toggle, Cmd/Ctrl+Enter to send one now) (#36588)
* Advertise mid-turn queueing as queued-messages.v2

Released clients read the v1 name with an unfinished queue UI; they never
see v2 and keep sending immediately.

(cherry picked from commit f39382e090)

* Let each desktop send choose queue or steer while the agent works

The follow-up choice is now a Queue / Steer setting saved under
nativeChatFollowUpBehavior, Steer by default; the old
nativeChatQueueFollowUps switch, which every install saved as true
while queueing was dark, is retired on load. Every reader goes through
native-chat-follow-up-behavior.

While the agent works, Enter follows the setting and Cmd/Ctrl+Enter
sends the draft the other way; the alternate flips the setting before
the queue's own rules (a waiting command still queues, prompts no one
here can answer still send now) and never applies while Stopping.
Cmd/Ctrl+Shift+Enter steers the head card only and leaves the draft.
An idle agent's card reads Send, and the card menu no longer offers
"Turn off queueing".

(cherry picked from commit 55b48694e7)

* Hold Send on the phone to queue or steer a message mid-turn

While the agent works on a host that queues, holding Send opens a
Queue / Steer sheet; a choice other than the host's setting sends the
alternate, resolved against the chat as it is when it lands, by the
desktop's rule. Release and dismiss send nothing. The phone reads the
host's new follow-up setting (absent reads as Steer), and an idle
agent's card reads Send.

(cherry picked from commit db87cf51ea)

* Read the follow-up default from one place on desktop and phone

(cherry picked from commit 8e1438bfb6)

* Keep phone follow-up choices aligned with live host state

(cherry picked from commit dc9215be3d)

* Update stream and wire fixtures for live follow-up preferences

(cherry picked from commit e4d038cf0b)

* Document minimal runtime test fixture assertions

(cherry picked from commit 254f751ef3)

* Keep mobile preference tests in the mobile compiler project

(cherry picked from commit ae2aa8910e)

* feat(native-chat): queue follow-ups by default with a toggle

(cherry picked from commit 70969d6a43)

* test(mobile): assert shared preference renders on real changes

(cherry picked from commit 3f50de9b2a)

* Remove obsolete follow-up option translations

(cherry picked from commit b87b360cf3)

* Describe Cmd/Ctrl+Enter relative to the Queue follow-ups switch

The Settings description said Cmd/Ctrl+Enter sends into the running
turn, which is wrong while the switch is off. Describe it as doing the
opposite for one message, in every language.

* Show what a mid-turn phone Send does, and offer the other way only when it differs

While the agent works, the phone's Send button now shows Queue or Steer.
Holding it lists that action first with a check and the other second,
each with a one-line description, and appears only when both choices
would actually lead to different sends. A waiting command or prompts
nobody here can answer make a hold behave like a tap.

* Steer the head card once while its shortcut is held

Holding Cmd/Ctrl+Shift+Enter auto-repeats the key, which steered each
card that became the head in turn. Ignore the repeats.

* Show beside Stop what Enter does while the agent works

While a turn runs and the draft has something to send, a send control
now sits beside Stop. Its icon and label say whether Enter queues the
message or steers it into the running turn, and its tooltip names Enter
and, when it would send differently, Cmd/Ctrl+Enter. Clicking it sends
as Enter does. Stop keeps its place and nothing changes while Stopping,
with an empty draft, or before the host says it queues.

The phone and desktop now read what a send does from one shared helper
over the send's own resolver.

* Test the send keys and Queue follow-ups search against real wiring

One desktop test drives Enter and Cmd+Enter through the real composer,
transport and session to the outgoing send and checks its delivery with
queueing on and off. Settings search is checked against the capability
list this build's host advertises.

* Move the composer's send-hold check into its own helper

The pane had grown past the file length limit after the main merge.

* Disable the mid-turn Queue/Steer button whenever Send would be disabled

While an image is still loading, another device holds the input, or a send is blocked for a stated reason, the button beside Stop is now disabled and says why, the same way the idle Send button does. Before, it stayed clickable and a click did nothing.

* Hide the mid-turn Queue/Steer button in goal mode

In goal mode Enter sets the goal, so a button promising to queue or steer the message was wrong. It is now hidden there, as it already is while editing a queued message.

* Fix the Russian queue hint to say the message runs after this turn

It read as queueing until the end of this turn.

* Stub window.api without a type assertion in the Queue follow-ups settings search test

* Pass sendHeld to the composer field in tests and drop an unknown setting from the German Queue test

* Let Cmd-click (Ctrl-click elsewhere) on the mid-turn Queue/Steer button send the other way, like Cmd/Ctrl+Enter

The button shows the other action while the modifier is held, and its tooltip names the click. Only when the other way would send differently; otherwise a modified click is a plain send.

* Merge the duplicate composer-types import and give the composer's round buttons a Button size instead of restyling them

The focused code-quality check rejects importing one module twice, and the design-system check rejects rounded-full on a <Button>, which the new Queue/Steer button copied from Send. Both composer buttons now use a round icon size on the Button primitive and render as before.

* Share one window key listener across every chat's Queue/Steer button, and count Cmd/Ctrl as held only from its own key press

Each mounted chat with a mid-turn draft used to add its own window key listeners, so every keystroke did work per chat, hidden tabs included. One shared listener set now serves them all and wakes a button only when the held state really changes.

Other keys can now only clear the held state, so a dictation paste that leaves the Cmd flag on later key events no longer flips the button with Cmd up. Also tests the Ctrl-click on Windows and Linux.

* Remove the desktop Queue/Steer button shown beside Stop while the agent works

While the agent works, the desktop composer goes back to its usual
controls: Stop, with Enter and the send shortcuts doing what they did.
Enter still follows the queue setting, Cmd/Ctrl+Enter still sends one
message the other way, and Cmd/Ctrl+Shift+Enter still steers the first
queued card.

This also removes what only that button used: its Cmd/Ctrl-click
alternate, the shared Cmd/Ctrl key listener, the extra round Button
size, the send-preview value the desktop session passed to the
composer, and the button's text in every language. The phone is
unchanged.

* Put the composer's send-hold checks back inline in the pane

The separate send-hold helper only existed because the removed mid-turn
Queue/Steer button pushed the pane over the file-length limit. Without the
button the pane fits again, so it goes back to main's inline code.
2026-10-31 02:01:32 -07:00

141 lines
10 KiB
TypeScript

import { AGENT_SESSION_ATTENTION_RUNTIME_CAPABILITIES } from './agent-session-attention-capabilities'
import { AGENT_SESSION_BACKGROUND_TASK_CHILD_VIEWS_CAPABILITY } from './agent-session-background-task-child-views-capability'
import { AGENT_SESSION_CONTINUE_INTERRUPTED_RUNTIME_CAPABILITY } from './agent-session-continue-interrupted-capability'
import { AGENT_SESSION_CREATE_RUNTIME_CAPABILITIES } from './agent-session-create-capabilities'
import { AGENT_SESSION_CURRENT_REQUESTS_CLIENT_CAPABILITY } from './agent-session-current-requests-capability'
import { AGENT_SESSION_PERMISSION_MODES_RUNTIME_CAPABILITY } from './agent-session-permission-modes-capability'
import { AGENT_SESSION_RESUME_RUNTIME_CAPABILITIES } from './agent-session-resume-runtime-capabilities'
import { AGENT_SESSION_STOP_RUNTIME_CAPABILITIES } from './agent-session-stop-capabilities'
import { AGENT_SESSION_WORKSPACE_SLEEP_MARK_RUNTIME_CAPABILITY } from './agent-session/agent-session-workspace-sleep'
import { STRUCTURED_AGENT_SESSION_SURFACE_RUNTIME_CAPABILITIES } from './structured-agent-session-surface-capabilities'
export const AGENT_SESSION_BOUNDARY_RUNTIME_CAPABILITY =
'agent-session.session-boundary.v1' as const
export const AGENT_SESSION_HOST_AUTHORITY_RUNTIME_CAPABILITY =
'agent-session.host-authority.v1' as const
// Older launch schemas reject unknown fields; advertise before clients send keyboard support.
export const AGENT_SESSION_KEYBOARD_RUNTIME_CAPABILITY = 'agent-session.keyboard.v1' as const
export const AGENT_SESSION_OMP_RESUME_PATH_RUNTIME_CAPABILITY =
'agent-session.omp-resume-path.v1' as const
// Gate journal/lifecycle/destructive tab mutations by client capability. Mobile may receive metadata-only placeholders for these non-PTY sessions.
export const STRUCTURED_AGENT_SESSION_RUNTIME_CAPABILITY = 'agent-session.structured.v1' as const
// Older hosts advertised structured.v1 while gating on their setting. This capability gives clients per-launch mode choice; legacy clients use createSupport, which retains the host setting.
export const STRUCTURED_AGENT_SESSION_CLIENT_LAUNCH_MODE_CAPABILITY =
'agent-session.structured.client-launch-mode.v1' as const
// Capable clients understand durable pending replies and skip bounded host settlement observation; older clients render uncertainty.
export const AGENT_SESSION_PENDING_SEND_RESULT_RUNTIME_CAPABILITY =
'agent-session.pending-send-result.v1' as const
// Early acceptance requires clients to display later rejection. Hold legacy replies until handover/rejection; remove only after supported desktop/mobile clients render rejected messages in place.
export const AGENT_SESSION_ACCEPTED_SEND_RUNTIME_CAPABILITY =
'agent-session.accepted-send.v1' as const
// Capable hosts answer resend IDs from the record before other refusals; only returned answers
// prove anything, never throws (even refusals). operation_unknown + outcomeUnknown/resultLost
// means retry the same ID; rewindUnconfirmed means settled with no write. operation_expired needs
// transcript inspection; operation_conflict/messageIdReused/sessionNotAttached prove no outcome.
// Other refusals prove no recorded/in-flight message, but resending that ID could still run it:
// after returning text to the user, never resend the old ID. Older hosts provide none of these guarantees.
export const AGENT_SESSION_SEND_ANSWERS_PROOF_RUNTIME_CAPABILITY =
'agent-session.send-answers-proof.v1' as const
// Older hosts reject delivery; older clients cannot render queued replies. Gate queue-if-active,
// its setting and chords, but never kept-draft lists/actions. v2, not v1: released clients that
// read v1 (desktop 1.4.219+, native phone builds) carry an unfinished queue UI, so they never see
// this and keep sending immediately. The Codex steer paths it hands cards to are pinned in
// codex-structured-turn-steer.test.ts.
// Hand-offs link via submission.queuedMessageId, never equal draft/submission IDs. queuePause
// holds every card until queuedMessagesResume or a later turn starts. nextQueuedMessageId names
// the next eligible card; null/missing means none. Per-card holds: send_failed conversion or kept.
export const AGENT_SESSION_QUEUED_MESSAGES_RUNTIME_CAPABILITY =
'agent-session.queued-messages.v2' as const
// Advertise in-place update/edit holds separately from mid-turn queueing: kept/mail cards remain editable while queueing is off. Never fall back to copy/delete.
export const AGENT_SESSION_QUEUED_MESSAGE_EDIT_RUNTIME_CAPABILITY =
'agent-session.queued-message-edit.v1' as const
// Strict update params accept skills only when advertised; omission keeps legacy editing.
export const AGENT_SESSION_QUEUED_MESSAGE_SKILLS_EDIT_RUNTIME_CAPABILITY =
'agent-session.queued-message-skills-edit.v1' as const
export const AGENT_SESSION_QUEUED_MESSAGE_REORDER_RUNTIME_CAPABILITY =
'agent-session.queued-message-reorder.v1' as const
// Strict update params accept images only when advertised; otherwise Save edits text alone.
export const AGENT_SESSION_QUEUED_MESSAGE_IMAGE_EDIT_RUNTIME_CAPABILITY =
'agent-session.queued-message-image-edit.v1' as const
// Publish image cards only to capable readers that preserve images on edit; older copy/delete editing would lose them.
export const AGENT_SESSION_QUEUED_IMAGE_CARDS_CLIENT_CAPABILITY =
'agent-session.queued-image-cards.v1' as const
// Strict conversationCommand rejects unknown delivery. Offer queued /compact only with this and queued-messages.v2; its card is the sole waiting surface.
export const AGENT_SESSION_QUEUED_COMMANDS_RUNTIME_CAPABILITY =
'agent-session.queued-commands.v1' as const
// Gate Claude journal/lifecycle independently of Codex for paired clients.
export const CLAUDE_STRUCTURED_AGENT_SESSION_RUNTIME_CAPABILITY =
'agent-session.structured.claude.v1' as const
// Probe additive conversationOutline before calling; older hosts keep loaded-message rails instead of method_not_found.
export const AGENT_SESSION_CONVERSATION_OUTLINE_RUNTIME_CAPABILITY =
'agent-session.conversation-outline.v1' as const
export const AGENT_SESSION_CONTINUATION_CONTEXT_RUNTIME_CAPABILITY =
'agent-session.continuation-context.v1' as const
// Probe additive item reads before offering full output; older hosts retain only heads.
export const AGENT_SESSION_ITEM_DETAIL_RUNTIME_CAPABILITY = 'agent-session.item-detail.v1' as const
// The RPC is registered unconditionally; per-session rewind support is a separate check.
export const AGENT_SESSION_REWIND_RUNTIME_CAPABILITY = 'agent-session.rewind.v1' as const
// Why: the rewind UI relies on the next send settling an in-doubt rewind, even with the agent up.
export const AGENT_SESSION_REWIND_RECOVERY_CAPABILITY = 'agent-session.rewind-recovery.v1' as const
// Readers must understand a monitoring roster with no available stop control.
// Downgrade turn items to legacy status rows for incapable clients; remove only after every supported release understands turn items.
export const AGENT_SESSION_TURN_ITEM_CAPABILITY = 'agent-session.turn-item.v1' as const
/** The client retires acknowledged echoes even when a catch-up snapshot skips their rows. */
export const AGENT_SESSION_SNAPSHOT_CATCH_UP_CLIENT_CAPABILITY =
'agent-session.snapshot-catch-up.v1' as const
export const AGENT_SESSION_BACKGROUND_TASK_STOP_CAPABILITY =
'agent-session.background-task-stop.v1' as const
// Question-answer params are strict: older hosts need packed optionId instead of structured answers.
export const AGENT_SESSION_QUESTION_ANSWERS_RUNTIME_CAPABILITY =
'agent-session.question-answers.v1' as const
// Paired attachments belong on the server; refuse unsupported servers instead of passing local machine paths.
export const AGENT_SESSION_ATTACHMENTS_RUNTIME_CAPABILITY = 'agent-session.attachments.v1' as const
// Why: hosts before this advertise attachments.v1 but refuse the upload methods from a phone.
export const AGENT_SESSION_PHONE_ATTACHMENTS_RUNTIME_CAPABILITY =
'agent-session.attachments.phone.v1' as const
// Readers must explicitly honor stoppable:false on live child rows. The Stop capability alone predates this field and cannot prove safe rendering.
export const AGENT_SESSION_BACKGROUND_TASK_ROW_STOP_CAPABILITY =
'agent-session.background-task-row-stop.v1' as const
export const AGENT_SESSION_RUNTIME_CAPABILITIES = [
...AGENT_SESSION_STOP_RUNTIME_CAPABILITIES,
...AGENT_SESSION_CREATE_RUNTIME_CAPABILITIES,
AGENT_SESSION_BOUNDARY_RUNTIME_CAPABILITY,
AGENT_SESSION_HOST_AUTHORITY_RUNTIME_CAPABILITY,
AGENT_SESSION_OMP_RESUME_PATH_RUNTIME_CAPABILITY,
AGENT_SESSION_KEYBOARD_RUNTIME_CAPABILITY,
STRUCTURED_AGENT_SESSION_RUNTIME_CAPABILITY,
AGENT_SESSION_CURRENT_REQUESTS_CLIENT_CAPABILITY,
STRUCTURED_AGENT_SESSION_CLIENT_LAUNCH_MODE_CAPABILITY,
AGENT_SESSION_PENDING_SEND_RESULT_RUNTIME_CAPABILITY,
// The host side: it accepts a send before any agent has it, and a Stop with no writer before a
// turn starts, so a client may gate on either.
AGENT_SESSION_ACCEPTED_SEND_RUNTIME_CAPABILITY,
AGENT_SESSION_SEND_ANSWERS_PROOF_RUNTIME_CAPABILITY,
AGENT_SESSION_QUEUED_MESSAGES_RUNTIME_CAPABILITY,
AGENT_SESSION_QUEUED_COMMANDS_RUNTIME_CAPABILITY,
AGENT_SESSION_QUEUED_MESSAGE_EDIT_RUNTIME_CAPABILITY,
AGENT_SESSION_QUEUED_MESSAGE_REORDER_RUNTIME_CAPABILITY,
AGENT_SESSION_QUEUED_MESSAGE_IMAGE_EDIT_RUNTIME_CAPABILITY,
AGENT_SESSION_QUEUED_MESSAGE_SKILLS_EDIT_RUNTIME_CAPABILITY,
AGENT_SESSION_CONTINUE_INTERRUPTED_RUNTIME_CAPABILITY,
AGENT_SESSION_PERMISSION_MODES_RUNTIME_CAPABILITY,
...STRUCTURED_AGENT_SESSION_SURFACE_RUNTIME_CAPABILITIES,
...AGENT_SESSION_ATTENTION_RUNTIME_CAPABILITIES,
AGENT_SESSION_WORKSPACE_SLEEP_MARK_RUNTIME_CAPABILITY,
AGENT_SESSION_REWIND_RUNTIME_CAPABILITY,
AGENT_SESSION_REWIND_RECOVERY_CAPABILITY,
AGENT_SESSION_CONVERSATION_OUTLINE_RUNTIME_CAPABILITY,
AGENT_SESSION_CONTINUATION_CONTEXT_RUNTIME_CAPABILITY,
AGENT_SESSION_ITEM_DETAIL_RUNTIME_CAPABILITY,
AGENT_SESSION_BACKGROUND_TASK_STOP_CAPABILITY,
AGENT_SESSION_QUESTION_ANSWERS_RUNTIME_CAPABILITY,
AGENT_SESSION_ATTACHMENTS_RUNTIME_CAPABILITY,
AGENT_SESSION_PHONE_ATTACHMENTS_RUNTIME_CAPABILITY,
AGENT_SESSION_TURN_ITEM_CAPABILITY,
AGENT_SESSION_BACKGROUND_TASK_ROW_STOP_CAPABILITY,
AGENT_SESSION_BACKGROUND_TASK_CHILD_VIEWS_CAPABILITY,
...AGENT_SESSION_RESUME_RUNTIME_CAPABILITIES
] as const