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