vibe-kanban-cli 0.1.4

Interactive CLI for Vibe Kanban
Documentation
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
//! HTTP client for the Vibe Kanban API.

use anyhow::{Context, Result, anyhow};
use reqwest::Client;
use uuid::Uuid;

use crate::types::*;

/// Client for interacting with the Vibe Kanban server API.
#[derive(Clone)]
pub struct VibeKanbanClient {
    client: Client,
    base_url: String,
}

impl VibeKanbanClient {
    /// Create a new API client.
    pub fn new(base_url: &str) -> Result<Self> {
        let client = Client::builder()
            .build()
            .context("Failed to create HTTP client")?;

        Ok(Self {
            client,
            base_url: base_url.trim_end_matches('/').to_string(),
        })
    }

    /// Build the full URL for an API endpoint.
    fn url(&self, path: &str) -> String {
        format!("{}/api{}", self.base_url, path)
    }

    /// Extract data from an API response or return an error.
    fn extract_data<T>(response: ApiResponse<T>) -> Result<T> {
        if response.success {
            response.data.ok_or_else(|| anyhow!("Response success but no data"))
        } else {
            Err(anyhow!(
                "API error: {}",
                response.message.unwrap_or_else(|| "Unknown error".to_string())
            ))
        }
    }

    // =========================================================================
    // Projects
    // =========================================================================

    /// List all projects.
    pub async fn list_projects(&self) -> Result<Vec<Project>> {
        let response = self
            .client
            .get(self.url("/projects"))
            .send()
            .await
            .context("Failed to fetch projects")?
            .json::<ApiResponse<Vec<Project>>>()
            .await
            .context("Failed to parse projects response")?;

        Self::extract_data(response)
    }

    /// Get a project by ID.
    pub async fn get_project(&self, project_id: Uuid) -> Result<Project> {
        let response = self
            .client
            .get(self.url(&format!("/projects/{}", project_id)))
            .send()
            .await
            .context("Failed to fetch project")?
            .json::<ApiResponse<Project>>()
            .await
            .context("Failed to parse project response")?;

        Self::extract_data(response)
    }

    /// Create a new project.
    pub async fn create_project(&self, payload: &CreateProject) -> Result<Project> {
        let response = self
            .client
            .post(self.url("/projects"))
            .json(payload)
            .send()
            .await
            .context("Failed to create project")?
            .json::<ApiResponse<Project>>()
            .await
            .context("Failed to parse create project response")?;

        Self::extract_data(response)
    }

    /// Get repositories for a project.
    pub async fn get_project_repositories(&self, project_id: Uuid) -> Result<Vec<Repo>> {
        let response = self
            .client
            .get(self.url(&format!("/projects/{}/repositories", project_id)))
            .send()
            .await
            .context("Failed to fetch repositories")?
            .json::<ApiResponse<Vec<Repo>>>()
            .await
            .context("Failed to parse repositories response")?;

        Self::extract_data(response)
    }

    // =========================================================================
    // Tasks
    // =========================================================================

    /// List tasks for a project.
    pub async fn list_tasks(&self, project_id: Uuid) -> Result<Vec<TaskWithAttemptStatus>> {
        let response = self
            .client
            .get(self.url("/tasks"))
            .query(&[("project_id", project_id.to_string())])
            .send()
            .await
            .context("Failed to fetch tasks")?
            .json::<ApiResponse<Vec<TaskWithAttemptStatus>>>()
            .await
            .context("Failed to parse tasks response")?;

        Self::extract_data(response)
    }

    /// Get a task by ID.
    pub async fn get_task(&self, task_id: Uuid) -> Result<Task> {
        let response = self
            .client
            .get(self.url(&format!("/tasks/{}", task_id)))
            .send()
            .await
            .context("Failed to fetch task")?
            .json::<ApiResponse<Task>>()
            .await
            .context("Failed to parse task response")?;

        Self::extract_data(response)
    }

    /// Create a new task.
    pub async fn create_task(&self, payload: &CreateTask) -> Result<Task> {
        let response = self
            .client
            .post(self.url("/tasks"))
            .json(payload)
            .send()
            .await
            .context("Failed to create task")?
            .json::<ApiResponse<Task>>()
            .await
            .context("Failed to parse create task response")?;

        Self::extract_data(response)
    }

    /// Update a task.
    pub async fn update_task(&self, task_id: Uuid, payload: &UpdateTask) -> Result<Task> {
        let response = self
            .client
            .put(self.url(&format!("/tasks/{}", task_id)))
            .json(payload)
            .send()
            .await
            .context("Failed to update task")?
            .json::<ApiResponse<Task>>()
            .await
            .context("Failed to parse update task response")?;

        Self::extract_data(response)
    }

    /// Delete a task.
    pub async fn delete_task(&self, task_id: Uuid) -> Result<()> {
        let response = self
            .client
            .delete(self.url(&format!("/tasks/{}", task_id)))
            .send()
            .await
            .context("Failed to delete task")?
            .json::<ApiResponse<()>>()
            .await
            .context("Failed to parse delete task response")?;

        Self::extract_data(response)
    }

    /// Create a task and start it immediately.
    pub async fn create_and_start_task(
        &self,
        payload: &CreateAndStartTaskRequest,
    ) -> Result<TaskWithAttemptStatus> {
        let response = self
            .client
            .post(self.url("/tasks/create-and-start"))
            .json(payload)
            .send()
            .await
            .context("Failed to create and start task")?
            .json::<ApiResponse<TaskWithAttemptStatus>>()
            .await
            .context("Failed to parse create and start task response")?;

        Self::extract_data(response)
    }

    // =========================================================================
    // Workspaces (Task Attempts)
    // =========================================================================

    /// List workspaces (task attempts).
    pub async fn list_workspaces(&self, task_id: Option<Uuid>) -> Result<Vec<Workspace>> {
        let mut request = self.client.get(self.url("/task-attempts"));

        if let Some(task_id) = task_id {
            request = request.query(&[("task_id", task_id.to_string())]);
        }

        let response = request
            .send()
            .await
            .context("Failed to fetch workspaces")?
            .json::<ApiResponse<Vec<Workspace>>>()
            .await
            .context("Failed to parse workspaces response")?;

        Self::extract_data(response)
    }

    /// Get a workspace by ID.
    pub async fn get_workspace(&self, workspace_id: Uuid) -> Result<Workspace> {
        let response = self
            .client
            .get(self.url(&format!("/task-attempts/{}", workspace_id)))
            .send()
            .await
            .context("Failed to fetch workspace")?
            .json::<ApiResponse<Workspace>>()
            .await
            .context("Failed to parse workspace response")?;

        Self::extract_data(response)
    }

    /// Create a task attempt (workspace).
    pub async fn create_task_attempt(&self, payload: &CreateTaskAttemptBody) -> Result<Workspace> {
        let response = self
            .client
            .post(self.url("/task-attempts"))
            .json(payload)
            .send()
            .await
            .context("Failed to create task attempt")?
            .json::<ApiResponse<Workspace>>()
            .await
            .context("Failed to parse create task attempt response")?;

        Self::extract_data(response)
    }

    /// Get branch status for a workspace.
    pub async fn get_branch_status(&self, workspace_id: Uuid) -> Result<Vec<RepoBranchStatus>> {
        let response = self
            .client
            .get(self.url(&format!("/task-attempts/{}/branch-status", workspace_id)))
            .send()
            .await
            .context("Failed to fetch branch status")?
            .json::<ApiResponse<Vec<RepoBranchStatus>>>()
            .await
            .context("Failed to parse branch status response")?;

        Self::extract_data(response)
    }

    /// Get repositories for a workspace.
    pub async fn get_workspace_repos(&self, workspace_id: Uuid) -> Result<Vec<RepoWithTargetBranch>> {
        let response = self
            .client
            .get(self.url(&format!("/task-attempts/{}/repos", workspace_id)))
            .send()
            .await
            .context("Failed to fetch workspace repos")?
            .json::<ApiResponse<Vec<RepoWithTargetBranch>>>()
            .await
            .context("Failed to parse workspace repos response")?;

        Self::extract_data(response)
    }

    /// Stop a workspace execution.
    pub async fn stop_workspace(&self, workspace_id: Uuid) -> Result<()> {
        let response = self
            .client
            .post(self.url(&format!("/task-attempts/{}/stop", workspace_id)))
            .send()
            .await
            .context("Failed to stop workspace")?
            .json::<ApiResponse<()>>()
            .await
            .context("Failed to parse stop workspace response")?;

        Self::extract_data(response)
    }

    // =========================================================================
    // Git Operations
    // =========================================================================

    /// Merge changes for a workspace.
    pub async fn merge_workspace(&self, workspace_id: Uuid, repo_id: Uuid) -> Result<()> {
        let payload = MergeTaskAttemptRequest { repo_id };
        let response = self
            .client
            .post(self.url(&format!("/task-attempts/{}/merge", workspace_id)))
            .json(&payload)
            .send()
            .await
            .context("Failed to merge workspace")?
            .json::<ApiResponse<()>>()
            .await
            .context("Failed to parse merge response")?;

        Self::extract_data(response)
    }

    /// Push workspace branch.
    pub async fn push_workspace(&self, workspace_id: Uuid, repo_id: Uuid) -> Result<()> {
        let payload = PushTaskAttemptRequest { repo_id };
        let response = self
            .client
            .post(self.url(&format!("/task-attempts/{}/push", workspace_id)))
            .json(&payload)
            .send()
            .await
            .context("Failed to push workspace")?
            .json::<ApiResponse<()>>()
            .await
            .context("Failed to parse push response")?;

        Self::extract_data(response)
    }

    /// Rebase workspace branch.
    pub async fn rebase_workspace(
        &self,
        workspace_id: Uuid,
        repo_id: Uuid,
        old_base: Option<String>,
        new_base: Option<String>,
    ) -> Result<()> {
        let payload = RebaseTaskAttemptRequest {
            repo_id,
            old_base_branch: old_base,
            new_base_branch: new_base,
        };
        let response = self
            .client
            .post(self.url(&format!("/task-attempts/{}/rebase", workspace_id)))
            .json(&payload)
            .send()
            .await
            .context("Failed to rebase workspace")?
            .json::<ApiResponse<()>>()
            .await
            .context("Failed to parse rebase response")?;

        Self::extract_data(response)
    }

    // =========================================================================
    // Sessions
    // =========================================================================

    /// List sessions for a workspace.
    pub async fn list_sessions(&self, workspace_id: Uuid) -> Result<Vec<Session>> {
        let response = self
            .client
            .get(self.url("/sessions"))
            .query(&[("workspace_id", workspace_id.to_string())])
            .send()
            .await
            .context("Failed to fetch sessions")?
            .json::<ApiResponse<Vec<Session>>>()
            .await
            .context("Failed to parse sessions response")?;

        Self::extract_data(response)
    }

    /// Send a follow-up message to a session.
    pub async fn send_follow_up(
        &self,
        session_id: Uuid,
        payload: &CreateFollowUpAttempt,
    ) -> Result<ExecutionProcess> {
        let response = self
            .client
            .post(self.url(&format!("/sessions/{}/follow-up", session_id)))
            .json(payload)
            .send()
            .await
            .context("Failed to send follow-up")?
            .json::<ApiResponse<ExecutionProcess>>()
            .await
            .context("Failed to parse follow-up response")?;

        Self::extract_data(response)
    }

    // =========================================================================
    // Repositories
    // =========================================================================

    /// List all repositories.
    pub async fn list_repos(&self) -> Result<Vec<Repo>> {
        let response = self
            .client
            .get(self.url("/repos"))
            .send()
            .await
            .context("Failed to fetch repos")?
            .json::<ApiResponse<Vec<Repo>>>()
            .await
            .context("Failed to parse repos response")?;

        Self::extract_data(response)
    }

    /// Get branches for a repository.
    pub async fn get_repo_branches(&self, repo_id: Uuid) -> Result<Vec<GitBranch>> {
        let response = self
            .client
            .get(self.url(&format!("/repos/{}/branches", repo_id)))
            .send()
            .await
            .context("Failed to fetch branches")?
            .json::<ApiResponse<Vec<GitBranch>>>()
            .await
            .context("Failed to parse branches response")?;

        Self::extract_data(response)
    }

    // =========================================================================
    // Health Check
    // =========================================================================

    /// Check if the server is healthy.
    pub async fn health_check(&self) -> Result<bool> {
        let response = self
            .client
            .get(self.url("/health"))
            .send()
            .await
            .context("Failed to reach server")?;

        Ok(response.status().is_success())
    }
}