Files
orca/src/main/runtime/rpc/methods/terminal-quick-command-rpc-schema.ts
T
Brennan Benson 5fcf777617 feat(mobile): Quick Commands (terminal + agent-prompt presets) (#9298)
* feat(mobile): add Quick Commands (terminal + agent-prompt presets)

Brings the desktop Terminal Quick Commands feature to mobile: saved
agent-prompt or terminal-command presets that launch a new terminal tab.

Entry point sits in the session tab strip next to the "+" new-terminal
button (with a divider) — quick commands spawn a tab, so they live with
tab creation, mirroring desktop's tab-bar split button.

- Launcher button + Quick Commands bottom sheet (search, This project /
  Global groups, run/edit/delete rows, add row).
- Add/Edit sheet mirroring desktop TerminalQuickCommandDialog: Label,
  Action toggle (Terminal Command | Agent Prompt), Agent select, Prompt /
  Command Text, Advanced (Append Enter, Scope Global/Project), validation
  and save-failure feedback.
- Launch reuses handleCreateTerminal (extended with enter + toast copy):
  agent prompts launch the agent then deliver the prompt; terminal
  commands run the (Enter-appended) command text.
- Expose terminalQuickCommands over the remote/mobile RPC surface
  (getClientSettings/updateClientSettings allowlists, RuntimeStore type,
  and the strict SettingsUpdate zod schema).
- Mirror the agent-prompt support predicate mobile-side (stdin-after-start
  agents are unsupported) with a parity test guarding drift from desktop.
- Mock server: sample quick commands + settings.update handler for QA.

* fix(mobile): harden quick command execution

* fix(mobile): harden quick command persistence and launch

* test(mobile): preserve unexpected quick command errors

* fix(mobile): harden quick command launch performance

* fix(runtime): reject malformed quick command updates

* refactor(mobile): reuse shared quick-command logic instead of mirroring

The mobile quick-commands mirror was built on a false premise — that
runtime-importing src/shared/terminal-quick-commands breaks the RN bundle
/ Vitest. It doesn't: tui-agent-config → orca-cli-command-name is a pure
leaf with no module-load Node APIs (verified via probe + bundle-graph).

- Mobile now reuses the canonical desktop helpers (action/agent/scope/
  matchesRepo/support/flatten) directly from src/shared; only genuinely
  mobile-specific pieces (agent-branded labels, native row truncation,
  the launch plan) stay local.
- Multiline runnable terminal commands now flatten via the shared
  flattenTerminalQuickCommand (";"-join) — unity with desktop, so a
  command saved on one runs identically on the other.
- Drop the MOBILE_TUI_AGENT_PROMPT_COMMAND_UNSUPPORTED mirror + its parity
  test; use the shared supportsTerminalAgentQuickCommand predicate.
- Export the shared MAX_QUICK_COMMAND_* length caps for reuse.

* fix(mobile): protect quick command data boundaries

* fix(mobile): enforce quick command limits

* fix(mobile): make quick command updates atomic

* fix(mobile): keep quick command filters recoverable

* fix(mobile): use filled play icon for quick commands

* Revert "fix(mobile): use filled play icon for quick commands"

This reverts commit 169bf053b060deabda489b92a8bba56c4a0a1ad6.

* fix(mobile): gate quick commands on host capability
2026-07-19 23:42:31 -07:00

74 lines
2.3 KiB
TypeScript

import { z } from 'zod'
import type { TerminalQuickCommand } from '../../../../shared/types'
import {
MAX_QUICK_COMMAND_AGENT_PROMPT_LENGTH,
MAX_QUICK_COMMAND_ID_LENGTH,
MAX_QUICK_COMMAND_LABEL_LENGTH,
MAX_QUICK_COMMAND_REPO_ID_LENGTH,
MAX_QUICK_COMMAND_TERMINAL_TEXT_LENGTH,
normalizeTerminalQuickCommands,
supportsTerminalAgentQuickCommand
} from '../../../../shared/terminal-quick-commands'
const TerminalQuickCommandScopeUpdate = z.discriminatedUnion('type', [
z.object({ type: z.literal('global') }).strict(),
z
.object({
type: z.literal('repo'),
repoId: z.string().max(MAX_QUICK_COMMAND_REPO_ID_LENGTH)
})
.strict()
])
const TerminalQuickCommandUpdateItem = z.union([
z
.object({
id: z.string().max(MAX_QUICK_COMMAND_ID_LENGTH),
label: z.string().max(MAX_QUICK_COMMAND_LABEL_LENGTH),
action: z.literal('terminal-command').optional(),
command: z.string().max(MAX_QUICK_COMMAND_TERMINAL_TEXT_LENGTH),
appendEnter: z.boolean(),
scope: TerminalQuickCommandScopeUpdate.optional()
})
.strict(),
z
.object({
id: z.string().max(MAX_QUICK_COMMAND_ID_LENGTH),
label: z.string().max(MAX_QUICK_COMMAND_LABEL_LENGTH),
action: z.literal('agent-prompt'),
agent: z.custom(supportsTerminalAgentQuickCommand, {
message: 'Agent does not support prompt commands'
}),
prompt: z.string().max(MAX_QUICK_COMMAND_AGENT_PROMPT_LENGTH),
scope: TerminalQuickCommandScopeUpdate.optional()
})
.strict()
])
export const TerminalQuickCommandsUpdate = z
.object({
// Why: a single host-side mutation preserves unrelated desktop/mobile edits
// and avoids retransmitting the full ~240 KB list for every small change.
mutation: z.union([
z
.object({
type: z.literal('upsert'),
command: TerminalQuickCommandUpdateItem.transform(
(value) => normalizeTerminalQuickCommands([value])[0]
).pipe(
z.custom<TerminalQuickCommand>((value) => value !== undefined, {
message: 'Quick command cannot be normalized'
})
)
})
.strict(),
z
.object({
type: z.literal('delete'),
id: z.string().min(1).max(MAX_QUICK_COMMAND_ID_LENGTH)
})
.strict()
])
})
.strict()