返回 CodeWhale
types.rs
根目录 / crates / tui / src / tui / app / types.rs
1 //! Plain data types shared across the TUI: modes, effort/collapse/display
2 //! enums, the public `TuiOptions` construction bag, queued-message records,
3 //! and the action enums drained by the event loop.
4 //!
5 //! Everything here is pure data (plus parsing/labeling helpers that need no
6 //! `App` state). The TUI-owned items are re-exported from `app.rs` so existing
7 //! `crate::tui::app::X` paths are unchanged; types owned by another crate
8 //! (such as [`AppMode`]) are named at their own crate path instead.
9
10 use super::*;
11
12 use codewhale_config::AppMode;
13
14 /// What an interactive setting selection actually did.
15 ///
16 /// The three cases are genuinely different to the user, and the boolean this
17 /// replaced conflated the last two: a refused selection and an accepted one
18 /// that only wrote the startup default both returned `false`, so every caller
19 /// reported "already in that mode" and showed no receipt for the write.
20 ///
21 /// Only [`Self::Changed`] means live session state moved — that is the case
22 /// that must still emit an `AppAction` so the engine is resynchronized.
23 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
24 pub enum SettingSelection {
25 /// Live state moved, and the startup default was persisted.
26 Changed,
27 /// Live state already matched, and the startup default was persisted. This
28 /// is the normal shape after a session restore, where the live value and
29 /// the startup default legitimately disagree.
30 PersistedSame,
31 /// Refused by the turn lock or the Work receipt store.
32 Refused,
33 }
34
35 #[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
36 pub struct DialStep {
37 pub mode_changed: bool,
38 pub posture_changed: bool,
39 }
40
41 impl DialStep {
42 #[must_use]
43 pub fn changed(self) -> bool {
44 self.mode_changed || self.posture_changed
45 }
46 }
47
48 impl SettingSelection {
49 /// Whether live state moved — i.e. whether the engine needs resyncing.
50 #[must_use]
51 pub fn changed_live_state(self) -> bool {
52 matches!(self, Self::Changed)
53 }
54
55 /// Whether the selection was accepted at all (either case that persisted).
56 #[must_use]
57 #[cfg(test)]
58 pub fn accepted(self) -> bool {
59 !matches!(self, Self::Refused)
60 }
61 }
62
63 /// Localized, TUI-only presentation of [`AppMode`]. Kept out of
64 /// codewhale-config so the mode type does not depend on the locale packs.
65 pub trait AppModeUi {
66 /// Localized short name for the mode picker (user-facing surface only).
67 fn display_name_localized(self, locale: Locale) -> Cow<'static, str>;
68 /// Localized one-line hint for the mode picker (user-facing surface only).
69 fn picker_hint_localized(self, locale: Locale) -> Cow<'static, str>;
70 }
71
72 impl AppModeUi for AppMode {
73 /// Localized short name for the mode picker (user-facing surface only).
74 fn display_name_localized(self, locale: Locale) -> Cow<'static, str> {
75 tr(
76 locale,
77 match self {
78 AppMode::Agent => MessageId::AppModeAgent,
79 AppMode::Plan => MessageId::AppModePlan,
80 },
81 )
82 }
83
84 /// Localized one-line hint for the mode picker (user-facing surface only).
85 fn picker_hint_localized(self, locale: Locale) -> Cow<'static, str> {
86 tr(
87 locale,
88 match self {
89 AppMode::Agent => MessageId::AppModeAgentHint,
90 AppMode::Plan => MessageId::AppModePlanHint,
91 },
92 )
93 }
94 }
95
96 /// Exact provider/model route whose prompt can be inspected or replayed.
97 ///
98 /// Auto-model sessions keep `model == "auto"` as the user's selection, so
99 /// cache operations must carry the last concrete route separately. The base
100 /// URL is absent after restoring an older session because saved Auto receipts
101 /// intentionally do not persist raw endpoints.
102 #[derive(Debug, Clone, PartialEq, Eq)]
103 pub(crate) struct CacheReplayTarget {
104 pub(crate) provider: ProviderKind,
105 pub(crate) provider_identity: String,
106 /// Additive exact provider id used by persisted-route resolution.
107 /// `None` is meaningful for the legacy root-level `custom` route.
108 pub(crate) provider_id: Option<String>,
109 pub(crate) model: String,
110 pub(crate) base_url: Option<String>,
111 }
112
113 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
114 pub enum ComposerDensity {
115 Compact,
116 Comfortable,
117 Spacious,
118 }
119
120 impl ComposerDensity {
121 #[must_use]
122 pub fn from_setting(value: &str) -> Self {
123 match value.trim().to_ascii_lowercase().as_str() {
124 "compact" | "tight" => Self::Compact,
125 "spacious" | "loose" => Self::Spacious,
126 _ => Self::Comfortable,
127 }
128 }
129 }
130
131 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
132 pub enum TranscriptSpacing {
133 Compact,
134 Spacious,
135 }
136
137 impl TranscriptSpacing {
138 #[must_use]
139 pub fn from_setting(value: &str) -> Self {
140 match value.trim().to_ascii_lowercase().as_str() {
141 "compact" | "tight" => Self::Compact,
142 _ => Self::Spacious,
143 }
144 }
145 }
146
147 /// Controls how dense tool-call runs are collapsed in the transcript.
148 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
149 pub enum ToolCollapseMode {
150 /// Collapse qualifying tool runs by default.
151 ///
152 /// Collapsed success cells keep the tool-name + arg/command summary as the
153 /// single intent line (#3256 decision): that is already the model-visible
154 /// call summary, so a second "intent" source is not required.
155 Compact,
156 /// Never collapse tool runs automatically.
157 Expanded,
158 /// Collapse only when calm mode is active.
159 Calm,
160 }
161
162 impl ToolCollapseMode {
163 #[must_use]
164 pub fn from_setting(value: &str) -> Self {
165 match value.trim().to_ascii_lowercase().as_str() {
166 "expanded" | "off" | "none" => Self::Expanded,
167 "calm" | "calm-mode" | "calm_only" | "calm-only" => Self::Calm,
168 // `collapsed`/`collapse` are issue #3256's preferred names for the
169 // default; treat them like the canonical `compact`.
170 _ => Self::Compact,
171 }
172 }
173
174 #[must_use]
175 pub fn as_setting(self) -> &'static str {
176 match self {
177 Self::Compact => "compact",
178 Self::Expanded => "expanded",
179 Self::Calm => "calm",
180 }
181 }
182
183 #[must_use]
184 pub fn is_active(self, calm_mode: bool) -> bool {
185 match self {
186 Self::Compact => true,
187 Self::Expanded => false,
188 Self::Calm => calm_mode,
189 }
190 }
191 }
192
193 /// Configuration required to bootstrap the TUI.
194 #[derive(Clone)]
195 #[allow(clippy::struct_excessive_bools)]
196 pub struct TuiOptions {
197 pub model: String,
198 pub workspace: PathBuf,
199 pub config_path: Option<PathBuf>,
200 pub config_profile: Option<String>,
201 pub allow_shell: bool,
202 pub use_mouse_capture: bool,
203 /// Enable terminal bracketed-paste mode (OSC `?2004h` / `?2004l`). Defaults
204 /// on; settable via `bracketed_paste = false` in `settings.toml` for the
205 /// rare terminal that mishandles it.
206 pub use_bracketed_paste: bool,
207 /// Maximum number of concurrent sub-agents.
208 pub max_subagents: usize,
209 pub skills_dir: PathBuf,
210 pub memory_path: PathBuf,
211 pub mcp_config_path: PathBuf,
212 pub use_memory: bool,
213 /// Start in agent mode (defaults to agent; --yolo starts in YOLO)
214 pub start_in_agent_mode: bool,
215 /// Skip onboarding screens
216 pub skip_onboarding: bool,
217 /// Auto-approve tool executions (yolo mode)
218 pub yolo: bool,
219 /// Resume a previous session by ID
220 pub resume_session_id: Option<String>,
221 /// Startup input: a prompt to submit, or remote control to begin.
222 pub initial_input: Option<InitialInput>,
223 /// One-line receipt to show once at startup.
224 ///
225 /// Auto-resume uses this to say what it did — reattached, or fell back to
226 /// a fresh transcript because the candidate was missing, unreadable, or
227 /// recorded against a different workspace (#2934). Silence is the correct
228 /// value when nothing happened worth reporting.
229 pub startup_notice: Option<String>,
230 }
231
232 #[derive(Debug, Clone, PartialEq, Eq)]
233 pub enum InitialInput {
234 /// Pre-populate the composer, submit it once startup is ready, then keep
235 /// the interactive session open for follow-up messages (#2370).
236 Submit(String),
237 /// Begin account-owned web remote control after the TUI is initialized.
238 RemoteControl,
239 }
240
241 // === Sub-state structs for App field organization (#377) ===
242
243 /// Vim modal editing mode for the composer input area.
244 ///
245 /// Enabled via `[composer] mode = "vim"` in `settings.toml`. When the
246 /// composer vim mode is active the user starts in `Normal` mode and presses
247 /// `i`, `a`, or `o` to enter `Insert` mode. `Esc` from `Insert` returns to
248 /// `Normal`. Standard vim motions (`h`/`j`/`k`/`l`, `w`/`b`, `0`/`$`, `x`,
249 /// `dd`) work in `Normal` mode.
250 #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
251 pub enum VimMode {
252 /// Normal / command mode — motions and operators, no text insertion.
253 #[default]
254 Normal,
255 /// Insert mode — characters are appended at the cursor as typed.
256 Insert,
257 }
258
259 impl VimMode {}
260
261 /// Message queued while the engine is busy.
262 #[derive(Debug, Clone, PartialEq, Eq)]
263 pub struct QueuedMessage {
264 pub display: String,
265 pub skill_instruction: Option<String>,
266 pub skill_provenance: Option<codewhale_skills::SkillProvenance>,
267 pub extension_command: Option<(
268 codewhale_engine::extension_host::command::ExtensionCommandRef,
269 String,
270 )>,
271 pub approved_plan: Option<String>,
272 pub owner_input: bool,
273 /// True once this turn has been painted into `history` as `HistoryCell::User`.
274 /// Queue/offline submit echoes before the model runs; Immediate prepare skips
275 /// a second paint when this is set so drained queued turns do not double.
276 pub history_echoed: bool,
277 }
278
279 /// The message the current turn was dispatched with, and the transcript cell
280 /// that shows it. When the engine reports the turn was never sent (a key
281 /// rejected before any model output), this is what goes back in the composer,
282 /// skill included, and the bubble that comes out of the transcript (#6566).
283 #[derive(Debug, Clone)]
284 pub struct UnansweredSubmission {
285 pub message: QueuedMessage,
286 pub history_cell: usize,
287 }
288
289 /// A steer handed to the engine that the engine has not yet recorded.
290 ///
291 /// Live-only, and deliberately not in `api_messages`: `EngineHandle::steer`
292 /// succeeding means the channel took the text, not that a turn accepted it.
293 /// The engine commits a steer at a step boundary and drops one whose turn has
294 /// already moved on, so painting a settled transcript cell at send time
295 /// produced a cell that could sit above the work it followed, or survive
296 /// forever for a steer the model never saw (#6190). It becomes a real cell
297 /// when the engine's own record shows it, and a "could not send" receipt when
298 /// the turn ends without it.
299 #[derive(Debug, Clone)]
300 pub struct InflightSteer {
301 /// The composed message, carried so acceptance can paint the same cell
302 /// (including the queue-time echo it may already own).
303 pub message: QueuedMessage,
304 /// Exactly what was handed to `EngineHandle::steer`. The engine records
305 /// this as the first text block of the accepted user message, which is
306 /// what acceptance matches on.
307 pub content: String,
308 /// `api_messages.len()` when the steer was sent — the lower bound for the
309 /// acceptance search, so an identical earlier message cannot claim it.
310 pub sent_after_index: usize,
311 /// Held until acceptance knows the message index to anchor them to.
312 pub references: Vec<codewhale_core::ContextReference>,
313 }
314
315 /// How a freshly-typed user input should be sent.
316 ///
317 /// Picked by [`App::decide_composer_submit`] when the user submits a
318 /// non-empty composer.
319 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
320 pub enum SubmitDisposition {
321 /// Engine idle and online: send immediately.
322 Immediate,
323 /// Park on `queued_messages` (offline, or engine busy — #382).
324 Queue,
325 /// Amend the active turn immediately (#382).
326 Steer,
327 }
328
329 /// Enter-shaped gestures understood by the composer state machine.
330 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
331 pub enum ComposerSubmitChord {
332 Enter,
333 CtrlEnter,
334 }
335
336 /// The complete result of resolving a submit gesture against composer state.
337 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
338 pub enum ComposerSubmitAction {
339 Submit(SubmitDisposition),
340 /// Send the oldest queued message now: into the active turn while one
341 /// runs, otherwise as a new turn.
342 SendQueuedNow,
343 Noop,
344 }
345
346 /// Detailed tool payload attached to a history cell.
347 #[derive(Debug, Clone)]
348 pub struct ToolDetailRecord {
349 pub tool_id: String,
350 pub tool_name: String,
351 pub input: Value,
352 pub output: Option<String>,
353 }
354
355 /// Lightweight task view for sidebar rendering.
356 #[derive(Debug, Clone, PartialEq, Eq)]
357 pub struct TaskPanelEntry {
358 pub id: String,
359 pub status: String,
360 pub prompt_summary: String,
361 pub duration_ms: Option<u64>,
362 pub kind: TaskPanelEntryKind,
363 pub stale: bool,
364 pub elapsed_since_output_ms: Option<u64>,
365 pub owner_agent_id: Option<String>,
366 pub owner_agent_name: Option<String>,
367 /// #2889: structured current activity for the Work panel.
368 pub current_tool: Option<String>,
369 pub role: Option<String>,
370 pub files_touched: u32,
371 /// A finished shell's exit code. `None` while running, and for durable
372 /// tasks.
373 pub exit_code: Option<i64>,
374 }
375
376 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
377 pub enum TaskPanelEntryKind {
378 Background,
379 Shell,
380 }
381
382 impl QueuedMessage {
383 pub fn new(display: String, skill_instruction: Option<String>) -> Self {
384 Self {
385 display,
386 skill_instruction,
387 skill_provenance: None,
388 extension_command: None,
389 approved_plan: None,
390 owner_input: true,
391 history_echoed: false,
392 }
393 }
394
395 #[must_use]
396 pub fn with_approved_plan(mut self, approved_plan: Option<String>) -> Self {
397 self.approved_plan = approved_plan;
398 if self.approved_plan.is_some() {
399 self.owner_input = false;
400 }
401 self
402 }
403
404 #[must_use]
405 pub fn without_owner_input(mut self) -> Self {
406 self.owner_input = false;
407 self
408 }
409
410 #[must_use]
411 pub fn with_skill_provenance(
412 mut self,
413 provenance: Option<codewhale_skills::SkillProvenance>,
414 ) -> Self {
415 self.skill_provenance = provenance;
416 self
417 }
418
419 #[must_use]
420 pub(crate) fn is_workflow_draft(&self) -> bool {
421 self.skill_instruction
422 .as_deref()
423 .is_some_and(|instruction| {
424 instruction.starts_with(
425 codewhale_command_contract::workflow::WORKFLOW_DRAFT_INSTRUCTION_PREFIX,
426 )
427 })
428 }
429
430 #[cfg(test)]
431 pub fn content(&self) -> String {
432 if let Some(skill_instruction) = self.skill_instruction.as_ref() {
433 format!(
434 "{skill_instruction}\n\n---\n\nUser request: {}",
435 self.display
436 )
437 } else {
438 self.display.clone()
439 }
440 }
441 }
442
443 // === Actions ===
444
445 /// A typed goal-control request accepted by the TUI and delivered to the
446 /// engine mailbox. Keeping this separate from transcript text lets the host
447 /// persist, retry, and reconcile controls without impersonating the user.
448 #[derive(Debug, Clone, PartialEq, Eq)]
449 pub(crate) enum GoalControlIntent {
450 SetStatus {
451 status: codewhale_engine::tools::goal::GoalStatus,
452 clear: bool,
453 },
454 SetObjective {
455 objective: String,
456 token_budget: Option<u32>,
457 },
458 }
459
460 /// One accepted goal control waiting for its authoritative GoalUpdated
461 /// receipt. `dispatched` distinguishes mailbox backpressure from an operation
462 /// already ordered in the engine channel; both remain pending until receipt.
463 #[derive(Debug, Clone, PartialEq, Eq)]
464 pub(crate) struct PendingGoalControl {
465 pub goal_id: Option<String>,
466 pub intent: GoalControlIntent,
467 pub dispatched: bool,
468 }
469
470 /// Actions emitted by the UI event loop.
471 #[derive(Debug, Clone, PartialEq)]
472 pub enum AppAction {
473 OpenUndoSelector,
474 UndoLatestRequest {
475 force: bool,
476 },
477 SetWorkspaceTrust {
478 trusted: bool,
479 save: bool,
480 },
481 Quit,
482 LoadSession(PathBuf),
483 RemoteControl(codewhale_app_server::remote_control::RemoteControlAction),
484 NewSession {
485 sync: codewhale_command_contract::facets::SessionSyncPayload,
486 force: bool,
487 draft: Option<String>,
488 },
489 SyncSession {
490 session_id: Option<String>,
491 messages: Vec<Message>,
492 system_prompt: Option<SystemPrompt>,
493 model: String,
494 workspace: PathBuf,
495 mode: AppMode,
496 agent_preset: Option<String>,
497 },
498 SetConversationMode {
499 id: String,
500 },
501 OpenConfigView,
502 /// Open this workspace's `.codewhale/hooks.toml` in `$EDITOR`, creating
503 /// it from a commented template first when it does not exist yet.
504 EditProjectHooks,
505 /// Open the native git worktree manager.
506 OpenWorktreeManager,
507 OpenAgentBoard,
508 OpenPlanArtifact {
509 arg: Option<String>,
510 },
511 /// Open the `/model` two-pane picker (Pro/Flash + Off/High/Max).
512 OpenModelPicker,
513 /// Open the `/provider` picker modal — DeepSeek / NVIDIA NIM / OpenRouter
514 /// / Novita with inline API-key prompt for un-configured providers (#52).
515 OpenProviderPicker,
516 /// Open the `/provider` picker in setup/catalog mode, optionally focused on
517 /// a built-in provider that needs credentials before first use.
518 OpenProviderSetup {
519 provider: Option<codewhale_config::ProviderId>,
520 },
521 /// Open the named, keyless DS4 local-runtime preset for review and save.
522 OpenDs4Setup,
523 /// Run the xAI/Grok device-code flow with the TUI temporarily suspended.
524 StartXaiDeviceLogin,
525 OpenModelConnectionSetup,
526 StartAccountConnect,
527 StartAccountLogin,
528 StartAccountLogout,
529 /// Run native ChatGPT PKCE sign-in with the TUI temporarily suspended.
530 StartChatgptPkceLogin,
531 StartChatgptRevoke,
532 /// Run OrcaRouter OAuth 2.0 + PKCE sign-in (loopback redirect) with the TUI
533 /// temporarily suspended. Produces a durable `sk-orca-...` key in the
534 /// ordinary `orcarouter` credential slot — the same slot the API-key path
535 /// writes — so nothing downstream knows which adapter was used.
536 StartPluginLogin {
537 provider: String,
538 },
539 StartPluginLogout {
540 provider: String,
541 },
542 StartOrcarouterPkceLogin,
543 /// Clear the saved OrcaRouter credential.
544 StartOrcarouterRevoke,
545 /// Open the `/mode` picker modal for Act / Plan / Operate.
546 OpenModePicker,
547 /// Refresh the engine prompt after the UI operating mode changes.
548 ModeChanged(AppMode),
549 /// Synchronize a saved top-level approval policy into the live Config,
550 /// then refresh the engine prompt from the App's updated permission mode.
551 ApprovalPolicyPersisted {
552 policy: Option<String>,
553 },
554 /// Reload the active user permission rules after `/permissions` safely
555 /// removes one from the sibling `permissions.toml`.
556 PermissionRulesChanged,
557 ApproveAutoReviewRetry {
558 target: String,
559 },
560 /// Rebuild the engine's Skill/MCP catalogue from the App's newly replaced
561 /// immutable plugin snapshot after trust, enable, revoke, or reload.
562 PluginRegistryChanged,
563 /// Open the `/statusline` multi-select picker for footer items.
564 OpenStatusPicker,
565 /// Open the `/feedback` picker for GitHub issue/security destinations.
566 OpenFeedbackPicker,
567 /// Read/review a scoped immutable issue draft without parking the UI.
568 ReviewIssueReport {
569 id: String,
570 change: Option<String>,
571 },
572 /// Open the `/theme` picker modal with live preview of every preset.
573 OpenThemePicker,
574 /// Open the `/skills manage` manager — audit inventory + owned mutations.
575 OpenSkillsManager,
576 /// Open the `/workflows` run dashboard — live and retained workflow runs.
577 OpenWorkflowsManager,
578 /// Open the unified, read-only extensions inventory on a specific tab.
579 OpenExtensions {
580 tab: crate::tui::views::extensions::ExtensionsTab,
581 },
582 OpenFleetMissions,
583 OpenFleetList,
584 /// Open the `/fleet` roster — the saved-party view of the agent team.
585 OpenFleetRoster,
586 /// Open the selected v2 Fleet editor, or legacy profile setup when no
587 /// named Fleet is selected.
588 OpenFleetSetup,
589 /// `/fleet add`: validate the provider against the live config, write
590 /// the member rows, and mark the engine roster stale.
591 FleetAddModel {
592 provider: String,
593 model: String,
594 roles: Vec<String>,
595 },
596 /// `/fleet remove`: drop every member row pinning the route and mark the
597 /// engine roster stale.
598 FleetRemoveModel {
599 provider: String,
600 model: String,
601 },
602 /// Open the `/hotbar` setup wizard.
603 OpenHotbarSetup,
604 /// Open the constitution-first `/setup` wizard shell.
605 OpenSetupWizard,
606 /// Open the constitution-first `/setup` wizard at a specific step.
607 OpenSetupWizardAt {
608 step: codewhale_config::SetupStep,
609 },
610 /// Record that the bundled/default constitution should be used.
611 UseBundledConstitution,
612 OpenConstitutionManager {
613 review: bool,
614 },
615 /// Open the exact effective base-prompt preview for the next turn (#3928).
616 ///
617 /// Handled where the session config lives, so the preview is built by the
618 /// same function the dispatch path uses. Human-only: it issues no provider
619 /// request and expands no tool catalog.
620 PreviewEffectiveBasePrompt,
621 /// Disable the Hotbar: persist `hotbar = []` and clear the live slots.
622 DisableHotbar,
623 /// Restore the default recommended Hotbar slots: remove the `hotbar` key so
624 /// the resolver falls back to the built-in defaults.
625 RestoreHotbarDefaults,
626 /// Open an external URL in the system browser.
627 OpenExternalUrl {
628 url: String,
629 label: String,
630 },
631 /// Run an extension command in the extension host (`/name input`). The UI
632 /// event loop awaits it, then shows its text and/or submits its prompt
633 /// as the user's next message.
634 RunExtensionCommand {
635 command: codewhale_engine::extension_host::command::ExtensionCommandRef,
636 name: String,
637 input: String,
638 },
639 /// Send a message to the AI (normal chat mode).
640 SendMessage(String),
641 /// Same-session rollback. A retry is admitted only after the Engine
642 /// acknowledges this history and its persisted snapshot is durable.
643 ConversationUndo {
644 sync: codewhale_command_contract::facets::SessionSyncPayload,
645 restored_files: usize,
646 retry_input: Option<String>,
647 /// `retry_input` is the text of a pending `/edit`, already taken from
648 /// the composer. If the rollback is refused it must go back there, with
649 /// edit mode re-armed, or the user's revision is lost.
650 edit_replacement: bool,
651 },
652 /// Send a built-in Workflow planning turn with separate user-visible text
653 /// and bounded runtime guidance. Draft instructions carry a typed marker
654 /// that makes the dispatch path expose no tools for that turn.
655 WorkflowInstruction {
656 display: String,
657 instruction: String,
658 },
659 /// Cancel a running sub-agent through the engine manager.
660 CancelSubAgent {
661 agent_id: String,
662 },
663 /// Update the runtime goal status (`/goal pause|resume|clear|…`) without
664 /// dispatching a model turn. The UI layer translates this into
665 /// `Op::SetGoalStatus`.
666 SetGoalStatus {
667 status: codewhale_engine::tools::goal::GoalStatus,
668 clear: bool,
669 },
670 /// Set or replace the goal objective (`/goal <objective>`). The engine
671 /// owns the goal and starts the first goal turn itself as runtime
672 /// steering; the objective is never sent as a raw user message.
673 SetGoalObjective {
674 objective: String,
675 token_budget: Option<u32>,
676 },
677 ListSubAgents,
678 AgentProfiles {
679 arguments: String,
680 },
681 /// Ask the engine to describe the exact next outbound request
682 /// (`/preview-request`, #1004). The engine is the authority: only it can
683 /// rebuild the current tool catalog, MCP state, gates, and resolved route.
684 PreviewOutboundRequest {
685 /// Render the manifest as JSON instead of the human-readable table.
686 json: bool,
687 /// Render the exact base prompt only. Never includes runtime/system layers.
688 base_prompt_only: bool,
689 /// Optional text used only to resolve `auto` reasoning/routing. Never
690 /// added to the conversation and never sent to a provider.
691 hypothetical_prompt: Option<String>,
692 },
693 /// Show bounded read-only text without copying it into transcript history.
694 OpenTextPager {
695 title: String,
696 content: String,
697 },
698 /// Show a unified diff in a pager with the transcript's diff rendering,
699 /// without copying it into transcript history (`/diff`).
700 OpenDiffPager {
701 title: String,
702 diff: String,
703 },
704 /// Review a host-generated command; the pager carries its exact token
705 /// through explicit confirmation and the normal command dispatcher.
706 OpenCommandReview {
707 title: String,
708 content: String,
709 command: String,
710 },
711 /// Router setup (`/router`, `/model router`, #6525): open the view, test a
712 /// preset with one routing call, or save one to `[auto.router]`.
713 RouterSetup {
714 request: crate::tui::views::router_setup::RouterRequest,
715 },
716 /// Live remaining-credit lookup for prepaid providers (`/balance`).
717 FetchBalance,
718 FetchModels,
719 /// Force a Models.dev live-catalog refresh into ProviderLake (#4187).
720 RefreshModelsDevCatalog,
721 CacheWarmup,
722 /// Switch the active LLM backend (DeepSeek vs NVIDIA NIM) without
723 /// restarting the process. The runtime rebuilds its API client from
724 /// the updated config. `model` overrides the post-switch model
725 /// (already normalized but not yet provider-prefixed).
726 SwitchProvider {
727 provider: codewhale_config::ProviderId,
728 model: Option<String>,
729 },
730 /// Switch provider+model through the same apply path as a `/model` route
731 /// row. Used by Hotbar route slots so dispatch does not hand-mutate config.
732 SwitchModelRoute {
733 identity: codewhale_runtime::config::ProviderIdentity,
734 model: String,
735 },
736 UpdateCompaction(CompactionConfig),
737 UpdateStreamChunkTimeout(u64),
738 UpdateSubagentRuntimeConfig {
739 enabled: bool,
740 max_subagents: usize,
741 launch_concurrency: usize,
742 max_spawn_depth: u32,
743 api_timeout_secs: u64,
744 heartbeat_timeout_secs: u64,
745 },
746 /// Apply `/config search.provider` to the live Config and engine.
747 UpdateSearchProvider {
748 provider: codewhale_runtime::config::SearchProvider,
749 },
750 /// Apply `/config prompt_suggestion` to the live Config.
751 UpdatePromptSuggestion {
752 enabled: bool,
753 },
754 SetAutoReviewReviewerModel {
755 reviewer_model: Option<String>,
756 },
757 /// Apply one `/config notifications` scalar to the live Config.
758 UpdateNotification {
759 update: codewhale_config::notifications::NotificationConfigUpdate,
760 },
761 /// Enable or disable the background advisor watcher for this session (#3982).
762 SetAdvisorEnabled {
763 enabled: bool,
764 },
765 /// Open the live transcript overlay through a terminal-safe command path.
766 OpenLiveTranscript,
767 /// Open the whole-turn inspector (Ctrl+Alt+O, /turn inspect).
768 OpenTurnInspector,
769 OpenContextInspector,
770 SetActiveModelContextWindow {
771 tokens: Option<u32>,
772 },
773 CompactContext {
774 /// Optional user focus from `/compact <focus>`, forwarded into the
775 /// successor-brief summary prompt.
776 focus: Option<String>,
777 },
778 PurgeContext,
779 TaskAdd {
780 prompt: String,
781 },
782 TaskList,
783 TaskShow {
784 id: String,
785 },
786 TaskCancel {
787 id: String,
788 },
789 Automation(AutomationAction),
790 ShellJob(ShellJobAction),
791 Mcp(McpUiAction),
792 /// Switch to a different config profile without restarting.
793 SwitchProfile {
794 /// Profile name to load.
795 profile: String,
796 },
797 /// Switch the workspace used by tools, hooks, tasks, and session metadata.
798 SwitchWorkspace {
799 workspace: PathBuf,
800 },
801 /// Record from the microphone and route the transcription into the
802 /// composer (or auto-send it). Emitted by `/voice` and the voice hotbar
803 /// action; handled in the UI event loop where the live `Config` supplies
804 /// provider credentials.
805 VoiceCapture,
806 /// Upload an already-rendered, redacted session page as a secret gist.
807 /// Emitted only by `/share confirm`.
808 ShareSession {
809 html: String,
810 },
811 }
812
813 #[derive(Debug, Clone, PartialEq, Eq)]
814 pub enum AutomationAction {
815 /// Open the automations room, optionally focused on one id.
816 Open {
817 focus: Option<String>,
818 },
819 List,
820 Show(String),
821 Pause(String),
822 Resume(String),
823 Adopt(String),
824 Delete {
825 id: String,
826 confirmation: Option<String>,
827 },
828 Run(String),
829 }
830
831 #[derive(Debug, Clone, PartialEq, Eq)]
832 pub enum ShellJobAction {
833 List,
834 Show {
835 id: String,
836 },
837 SendStdin {
838 id: String,
839 input: String,
840 close: bool,
841 },
842 Cancel {
843 id: String,
844 },
845 CancelAll,
846 }
847
848 #[derive(Debug, Clone, PartialEq, Eq)]
849 pub enum McpUiAction {
850 Show,
851 Init {
852 force: bool,
853 },
854 AddStdio {
855 name: String,
856 command: String,
857 args: Vec<String>,
858 },
859 AddHttp {
860 name: String,
861 url: String,
862 transport: Option<String>,
863 },
864 Enable {
865 name: String,
866 },
867 Disable {
868 name: String,
869 },
870 Remove {
871 name: String,
872 },
873 Login {
874 name: String,
875 scopes: Vec<String>,
876 },
877 Logout {
878 name: String,
879 },
880 /// Retry one failed/timed-out server through the engine-owned live pool.
881 Retry {
882 name: String,
883 },
884 /// List consent-gated external MCP import candidates with provenance.
885 ImportList,
886 /// Approve importing one discovered external server into user mcp.json.
887 ImportApprove {
888 name: String,
889 },
890 /// Decline an external candidate (durable until source content changes).
891 ImportDecline {
892 name: String,
893 },
894 ProjectReview,
895 ProjectApprove {
896 digest: String,
897 },
898 ProjectRevoke,
899 Validate,
900 /// Report this server's last observed state without starting a new pool.
901 Diagnose {
902 name: String,
903 },
904 Reload,
905 }
906
906 lines RUST