Skip to main content

wisp/
command.rs

1use crate::attachment::{AttachmentOutcome, PromptAttachment};
2use crate::file_index::FileEntry;
3use crate::git_review::{DiffScope, FileStatus, GitDiffEvent};
4use crate::request::RequestId;
5use crate::session::workspace_status::WorkspaceStatus;
6use crate::settings::UiSettings;
7use crate::theme::Theme;
8use acp_utils::notifications::{PromptSearchParams, WorkspaceMoveTarget};
9use agent_client_protocol::schema::v1::{ContentBlock, SessionId};
10use std::path::PathBuf;
11
12#[derive(Debug, Clone)]
13pub enum Command {
14    Agent(AgentCommand),
15    Filesystem(FilesystemCommand),
16    Git(GitCommand),
17    ResolveWorkspace { cwd: PathBuf },
18    Terminal(TerminalCommand),
19}
20
21#[derive(Debug, Clone)]
22pub enum AgentCommand {
23    Prompt { session_id: SessionId, text: String, content: Option<Vec<ContentBlock>> },
24    Cancel { session_id: SessionId },
25    SetConfigOption { session_id: SessionId, config_id: String, value: String },
26    AuthenticateMcpServer { session_id: SessionId, server_name: String },
27    Authenticate { method_id: String },
28    ListSessions,
29    LoadSession { session_id: SessionId, cwd: PathBuf },
30    NewSession { cwd: PathBuf },
31    SearchPrompts(PromptSearchParams),
32    SessionPreview { session_id: String },
33    ListWorkspaces { session_id: String },
34    MoveWorkspace { session_id: String, target: WorkspaceMoveTarget },
35}
36
37impl AgentCommand {
38    pub(crate) fn failure(&self) -> FailedCommand {
39        match self {
40            Self::Prompt { .. } => FailedCommand::Prompt,
41            Self::LoadSession { .. } => FailedCommand::LoadSession,
42            Self::ListWorkspaces { .. } => FailedCommand::ListWorkspaces,
43            Self::MoveWorkspace { .. } => FailedCommand::MoveWorkspace,
44            Self::Cancel { .. } => FailedCommand::Other("cancel"),
45            Self::SetConfigOption { .. } => FailedCommand::Other("set config option"),
46            Self::AuthenticateMcpServer { .. } => FailedCommand::Other("authenticate MCP server"),
47            Self::Authenticate { .. } => FailedCommand::Other("authenticate provider"),
48            Self::ListSessions => FailedCommand::Other("list sessions"),
49            Self::NewSession { .. } => FailedCommand::Other("create new session"),
50            Self::SearchPrompts(_) => FailedCommand::Other("search prompts"),
51            Self::SessionPreview { .. } => FailedCommand::Other("preview session"),
52        }
53    }
54}
55
56#[derive(Debug, Clone, Copy, PartialEq, Eq)]
57pub enum FailedCommand {
58    Prompt,
59    LoadSession,
60    ListWorkspaces,
61    MoveWorkspace,
62    Other(&'static str),
63}
64
65impl FailedCommand {
66    pub fn describe(self) -> &'static str {
67        match self {
68            Self::Prompt => "send prompt",
69            Self::LoadSession => "load session",
70            Self::ListWorkspaces => "list workspaces",
71            Self::MoveWorkspace => "move workspace",
72            Self::Other(name) => name,
73        }
74    }
75}
76
77#[derive(Debug, Clone)]
78pub enum FilesystemCommand {
79    IndexFiles { request_id: RequestId, root: PathBuf },
80    PrepareSubmission { attachments: Vec<PromptAttachment> },
81    ListThemes,
82    ApplyTheme { settings: Box<UiSettings>, value: String },
83}
84
85#[derive(Debug, Clone)]
86pub enum GitCommand {
87    Load { request_id: RequestId, working_dir: PathBuf, repo_root: Option<PathBuf>, scope: DiffScope },
88    StageFiles { request_id: RequestId, repo_root: PathBuf, paths: Vec<String> },
89    UnstageFiles { request_id: RequestId, repo_root: PathBuf, paths: Vec<String> },
90    StageAll { request_id: RequestId, repo_root: PathBuf },
91    UnstageAll { request_id: RequestId, repo_root: PathBuf },
92    Commit { request_id: RequestId, repo_root: PathBuf, message: String },
93    DiscardFile { request_id: RequestId, repo_root: PathBuf, path: String, status: FileStatus },
94    LoadFullFile { request_id: RequestId, repo_root: PathBuf, path: String },
95}
96
97#[derive(Debug, Clone)]
98pub enum TerminalCommand {
99    RingBell,
100}
101
102pub enum CommandResult {
103    PromptSearchFailed { query: String, error: String },
104    FilesIndexed { request_id: RequestId, files: Vec<FileEntry> },
105    GitDiff(GitDiffEvent),
106    SubmissionPrepared(AttachmentOutcome),
107    ThemesListed(Vec<String>),
108    ThemeApplied { settings: Box<UiSettings>, theme: Theme, error: Option<String> },
109    WorkspaceResolved { cwd: PathBuf, status: WorkspaceStatus },
110    Failed { command: FailedCommand, error: String },
111}