Skip to main content

wisp/
command.rs

1use crate::attachment::{AttachmentOutcome, PromptAttachment};
2use crate::conversation::ConversationId;
3use crate::file_index::FileEntry;
4use crate::git_review::{ClientState, DiffReviewEvent, ServerMessage};
5use crate::request::RequestId;
6use crate::session::workspace_status::WorkspaceStatus;
7use crate::settings::UiSettings;
8use crate::theme::{Theme, ThemeApplicationError};
9use acp_utils::notifications::{
10    PromptSearchParams, PromptSearchResponse, SessionPreviewResponse, WorkspaceListResponse, WorkspaceMoveResponse,
11    WorkspaceMoveTarget,
12};
13use agent_client_protocol::schema::v2::{
14    ContentBlock, ListSessionsResponse, LoginAuthResponse, NewSessionResponse, PromptResponse, ResumeSessionResponse,
15    SessionConfigOptionValue, SessionId, SetSessionConfigOptionResponse,
16};
17use std::path::PathBuf;
18use std::sync::Arc;
19
20#[derive(Debug, Clone)]
21pub enum Command {
22    Agent(AgentCommand),
23    GitReview(GitReviewCommand),
24    Filesystem(FilesystemCommand),
25    Terminal(TerminalCommand),
26}
27
28#[derive(Debug, Clone)]
29pub enum AgentCommand {
30    Prompt {
31        session_id: SessionId,
32        text: String,
33        content: Option<Vec<ContentBlock>>,
34    },
35    Cancel {
36        session_id: SessionId,
37    },
38    SetConfigOption {
39        conversation_id: ConversationId,
40        session_id: SessionId,
41        config_id: String,
42        value: SessionConfigOptionValue,
43    },
44    AuthenticateMcpServer {
45        session_id: SessionId,
46        server_name: String,
47    },
48    Authenticate {
49        method_id: String,
50    },
51    ListSessions,
52    ResumeSession {
53        session_id: SessionId,
54        cwd: PathBuf,
55    },
56    NewSession {
57        cwd: PathBuf,
58    },
59    SearchPrompts(PromptSearchParams),
60    SessionPreview {
61        session_id: String,
62    },
63    ListWorkspaces {
64        session_id: String,
65    },
66    MoveWorkspace {
67        session_id: String,
68        target: WorkspaceMoveTarget,
69    },
70    FetchWorkspaceStatus {
71        session_id: String,
72        cwd: PathBuf,
73    },
74}
75
76#[derive(Debug, Clone)]
77pub enum GitReviewCommand {
78    /// Starts a review client for the session, opening the agent-side server.
79    Open { session_id: String },
80    /// Applies one user action the review screen captured.
81    Event(DiffReviewEvent),
82    /// Feeds one agent-side live-protocol message into the review client.
83    Forward(ServerMessage),
84    /// Stops the review and tears down the agent-side server.
85    Close,
86}
87
88#[derive(Debug, Clone)]
89pub enum FilesystemCommand {
90    IndexFiles { request_id: RequestId, root: PathBuf },
91    PrepareSubmission { attachments: Vec<PromptAttachment> },
92    ListThemes,
93    ListReviewThemes,
94    ApplyTheme { settings: Box<UiSettings> },
95}
96
97#[derive(Debug, Clone)]
98pub enum TerminalCommand {
99    RingBell,
100}
101
102pub enum CommandResult {
103    Prompt(Result<PromptResponse, String>),
104    Cancel(Result<(), String>),
105    AuthenticateMcp(Result<(), String>),
106    ConfigOptionsUpdated { conversation_id: ConversationId, result: Result<SetSessionConfigOptionResponse, String> },
107    AuthenticationCompleted { method_id: String, result: Result<LoginAuthResponse, String> },
108    NewSession(Result<NewSessionResponse, String>),
109    ResumeSession { session_id: SessionId, result: Result<ResumeSessionResponse, String> },
110    SessionsListed(Result<ListSessionsResponse, String>),
111    PromptSearchResults { query: String, result: Result<PromptSearchResponse, String> },
112    SessionPreviewLoaded { session_id: String, result: Result<SessionPreviewResponse, String> },
113    WorkspacesListed(Result<WorkspaceListResponse, String>),
114    WorkspaceMoved(Result<WorkspaceMoveResponse, String>),
115    FilesIndexed { request_id: RequestId, files: Vec<FileEntry> },
116    GitReview(Arc<ClientState>),
117    GitReviewAction(Result<(), String>),
118    SubmissionPrepared(AttachmentOutcome),
119    ThemesListed(Vec<String>),
120    ReviewThemesListed(Vec<clankerdiff_ratatui::ThemeChoice>),
121    ThemeApplied(Result<(Box<UiSettings>, Theme), ThemeApplicationError>),
122    WorkspaceResolved { cwd: PathBuf, status: WorkspaceStatus },
123    BackgroundFailed(String),
124    TerminalFailed(String),
125}