Task attempt 55cc3eff-6099-484a-b9c1-899d2a3528ce - Final changes

This commit is contained in:
Louis Knight-Webb
2025-06-20 19:25:18 +01:00
parent 5a9583b6b9
commit 99ab67cb65
5 changed files with 173 additions and 37 deletions

View File

@@ -20,60 +20,66 @@ fn main() {
r#"// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
// Auto-generated from Rust backend types using ts-rs
export {}
{}
export {}
{}
export {}
{}
export {}
{}
export {}
{}
export {}
{}
export {}
{}
export {}
{}
export {}
{}
export {}
{}
export {}
{}
export {}
{}
export {}
{}
export {}
{}
export {}
{}
export {}
{}
export {}
{}
export {}
{}
export {}
{}
export {}
{}
export {}
{}
export {}
{}
export {}
{}
export {}
{}
export {}
{}
export {}"#,
{}
{}
{}"#,
vibe_kanban::models::ApiResponse::<()>::decl(),
vibe_kanban::models::config::Config::decl(),
vibe_kanban::models::config::ThemeMode::decl(),
vibe_kanban::models::config::EditorConfig::decl(),
vibe_kanban::models::config::EditorType::decl(),
vibe_kanban::executor::ExecutorConfig::decl(),
vibe_kanban::models::project::CreateProject::decl(),
vibe_kanban::models::project::Project::decl(),

View File

@@ -10,6 +10,7 @@ pub struct Config {
pub executor: ExecutorConfig,
pub disclaimer_acknowledged: bool,
pub sound_alerts: bool,
pub editor: EditorConfig,
}
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
@@ -21,6 +22,25 @@ pub enum ThemeMode {
System,
}
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
#[ts(export)]
pub struct EditorConfig {
pub editor_type: EditorType,
pub custom_command: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
#[ts(export)]
#[serde(rename_all = "lowercase")]
pub enum EditorType {
VSCode,
Cursor,
Windsurf,
IntelliJ,
Zed,
Custom,
}
impl Default for Config {
fn default() -> Self {
Self {
@@ -28,6 +48,35 @@ impl Default for Config {
executor: ExecutorConfig::Claude,
disclaimer_acknowledged: false,
sound_alerts: true,
editor: EditorConfig::default(),
}
}
}
impl Default for EditorConfig {
fn default() -> Self {
Self {
editor_type: EditorType::VSCode,
custom_command: None,
}
}
}
impl EditorConfig {
pub fn get_command(&self) -> Vec<String> {
match &self.editor_type {
EditorType::VSCode => vec!["code".to_string()],
EditorType::Cursor => vec!["cursor".to_string()],
EditorType::Windsurf => vec!["windsurf".to_string()],
EditorType::IntelliJ => vec!["idea".to_string()],
EditorType::Zed => vec!["zed".to_string()],
EditorType::Custom => {
if let Some(custom) = &self.custom_command {
custom.split_whitespace().map(|s| s.to_string()).collect()
} else {
vec!["code".to_string()] // fallback to VSCode
}
}
}
}
}

View File

@@ -6,6 +6,7 @@ use axum::{
Json, Router,
};
use sqlx::SqlitePool;
use std::sync::{Arc, Mutex};
use uuid::Uuid;
use crate::models::{
@@ -452,6 +453,7 @@ pub async fn merge_task_attempt(
pub async fn open_task_attempt_in_editor(
Path((project_id, task_id, attempt_id)): Path<(Uuid, Uuid, Uuid)>,
Extension(pool): Extension<SqlitePool>,
Extension(config): Extension<Arc<Mutex<crate::models::config::Config>>>,
) -> Result<ResponseJson<ApiResponse<()>>, StatusCode> {
// Verify task attempt exists and belongs to the correct task
match TaskAttempt::exists_for_task(&pool, attempt_id, task_id, project_id).await {
@@ -473,29 +475,44 @@ pub async fn open_task_attempt_in_editor(
}
};
// Open VSCode in the worktree directory
match std::process::Command::new("code")
.arg(&attempt.worktree_path)
.spawn()
{
// Get editor command from config
let editor_command = {
let config_guard = config.lock().unwrap();
config_guard.editor.get_command()
};
// Open editor in the worktree directory
let mut cmd = std::process::Command::new(&editor_command[0]);
for arg in &editor_command[1..] {
cmd.arg(arg);
}
cmd.arg(&attempt.worktree_path);
match cmd.spawn() {
Ok(_) => {
tracing::info!(
"Opened VSCode for task attempt {} at path: {}",
"Opened editor ({}) for task attempt {} at path: {}",
editor_command.join(" "),
attempt_id,
attempt.worktree_path
);
Ok(ResponseJson(ApiResponse {
success: true,
data: None,
message: Some("VSCode opened successfully".to_string()),
message: Some("Editor opened successfully".to_string()),
}))
}
Err(e) => {
tracing::error!("Failed to open VSCode for attempt {}: {}", attempt_id, e);
tracing::error!(
"Failed to open editor ({}) for attempt {}: {}",
editor_command.join(" "),
attempt_id,
e
);
Ok(ResponseJson(ApiResponse {
success: false,
data: None,
message: Some(format!("Failed to open VSCode: {}", e)),
message: Some(format!("Failed to open editor: {}", e)),
}))
}
}