1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
//! A2A Protocol CLI commands
//!
//! Provides command-line interface for:
//! - Serving VT Code as an A2A agent
//! - Discovering remote A2A agents
//! - Sending tasks to other agents
//! - Managing A2A agent connections
use clap::{Parser, Subcommand};
/// A2A Protocol commands
#[derive(Debug, Subcommand, Clone)]
pub enum A2aCommands {
/// Serve VT Code as an A2A agent (requires a2a-server feature)
///
/// Starts an HTTP server exposing A2A endpoints:
/// - /.well-known/agent-card.json - Agent discovery
/// - /a2a - JSON-RPC endpoint for task management
/// - /a2a/stream - Server-Sent Events streaming
///
/// Examples:
/// vtcode a2a serve --port 8080
/// vtcode a2a serve --host 0.0.0.0 --port 8080
Serve {
/// Host to bind the server to
#[arg(long, default_value = "127.0.0.1")]
host: String,
/// Port to listen on
#[arg(short, long, default_value_t = 8080)]
port: u16,
/// Base URL for the agent (used in agent card)
#[arg(long)]
base_url: Option<String>,
/// Enable push notifications via webhooks
#[arg(long)]
enable_push: bool,
},
/// Discover and display information about a remote A2A agent
///
/// Fetches and displays the agent card from the remote agent,
/// showing capabilities, skills, and supported features.
///
/// Examples:
/// vtcode a2a discover <https://agent.example.com>
/// vtcode a2a discover <https://localhost:8080>
Discover {
/// URL of the remote A2A agent
agent_url: String,
},
/// Send a task to a remote A2A agent
///
/// Sends a message to a remote agent and returns the task result.
/// The agent will process the request and return structured results.
///
/// Examples:
/// vtcode a2a send-task <https://agent.example.com> "Help me refactor this code"
/// vtcode a2a send-task <https://localhost:8080> "Explain this error message"
SendTask {
/// URL of the remote A2A agent
agent_url: String,
/// The task/message to send to the agent
message: String,
/// Wait for task completion and stream progress
#[arg(long)]
stream: bool,
/// Optional context ID for conversation tracking
#[arg(long)]
context_id: Option<String>,
},
/// List active tasks in a running A2A agent
///
/// Queries a remote A2A agent for its current and recent tasks.
///
/// Examples:
/// vtcode a2a list-tasks <https://agent.example.com>
/// vtcode a2a list-tasks <https://localhost:8080> --context-id my-conversation
ListTasks {
/// URL of the remote A2A agent
agent_url: String,
/// Filter by context ID
#[arg(long)]
context_id: Option<String>,
/// Maximum number of tasks to return
#[arg(long, default_value_t = 50)]
limit: u32,
},
/// Get details about a specific task
///
/// Retrieves the current status, artifacts, and history of a task.
///
/// Examples:
/// vtcode a2a get-task <https://agent.example.com> task-123
/// vtcode a2a get-task <https://localhost:8080> task-456
GetTask {
/// URL of the remote A2A agent
agent_url: String,
/// Task ID to retrieve
task_id: String,
},
/// Cancel a running task
///
/// Requests cancellation of a task that is currently being processed.
///
/// Examples:
/// vtcode a2a cancel-task <https://agent.example.com> task-123
CancelTask {
/// URL of the remote A2A agent
agent_url: String,
/// Task ID to cancel
task_id: String,
},
}
/// A2A CLI configuration options
#[derive(Debug, Parser)]
pub struct A2aServeConfig {
/// Host to bind the server to
#[arg(long, default_value = "127.0.0.1")]
pub host: String,
/// Port to listen on
#[arg(short, long, default_value_t = 8080)]
pub port: u16,
/// Base URL for the agent (used in agent card)
#[arg(long)]
pub base_url: Option<String>,
/// Enable push notifications via webhooks
#[arg(long)]
pub enable_push: bool,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_cli_serve_command() {
let cmd = A2aCommands::Serve {
host: "127.0.0.1".to_string(),
port: 8080,
base_url: Some("http://localhost:8080".to_string()),
enable_push: false,
};
match cmd {
A2aCommands::Serve { port, .. } => assert_eq!(port, 8080),
_ => panic!("Wrong command type"),
}
}
#[test]
fn test_cli_discover_command() {
let cmd = A2aCommands::Discover {
agent_url: "https://example.com".to_string(),
};
match cmd {
A2aCommands::Discover { agent_url } => {
assert_eq!(agent_url, "https://example.com")
}
_ => panic!("Wrong command type"),
}
}
}