Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions crates/db/src/models/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,28 @@ impl Workspace {
})
}

/// Find workspace by path, also trying the parent directory.
/// Used by VSCode extension which may open a repo subfolder (single-repo case)
/// rather than the workspace root directory (multi-repo case).
pub async fn resolve_container_ref_by_prefix(
pool: &SqlitePool,
path: &str,
) -> Result<ContainerInfo, sqlx::Error> {
// First try exact match
if let Ok(info) = Self::resolve_container_ref(pool, path).await {
return Ok(info);
}

if let Some(parent) = std::path::Path::new(path).parent()
&& let Some(parent_str) = parent.to_str()
&& let Ok(info) = Self::resolve_container_ref(pool, parent_str).await
{
return Ok(info);
}

Err(sqlx::Error::RowNotFound)
}

pub async fn set_archived(
pool: &SqlitePool,
workspace_id: Uuid,
Expand Down
31 changes: 30 additions & 1 deletion crates/server/src/routes/containers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use db::models::workspace::{Workspace, WorkspaceContext};
use deployment::Deployment;
use serde::{Deserialize, Serialize};
use utils::response::ApiResponse;
use uuid::Uuid;

use crate::{DeploymentImpl, error::ApiError};

Expand All @@ -17,6 +18,29 @@ pub struct ContainerQuery {
pub container_ref: String,
}

#[derive(Debug, Serialize)]
pub struct ContainerInfo {
pub project_id: Uuid,
pub task_id: Uuid,
pub attempt_id: Uuid,
}

pub async fn get_container_info(
Query(query): Query<ContainerQuery>,
State(deployment): State<DeploymentImpl>,
) -> Result<ResponseJson<ApiResponse<ContainerInfo>>, ApiError> {
let info =
Workspace::resolve_container_ref_by_prefix(&deployment.db().pool, &query.container_ref)
.await
.map_err(ApiError::Database)?;

Ok(ResponseJson(ApiResponse::success(ContainerInfo {
project_id: info.project_id,
task_id: info.task_id,
attempt_id: info.workspace_id,
})))
}

pub async fn get_context(
State(deployment): State<DeploymentImpl>,
Query(payload): Query<ContainerQuery>,
Expand All @@ -40,5 +64,10 @@ pub async fn get_context(
}

pub fn router(_deployment: &DeploymentImpl) -> Router<DeploymentImpl> {
Router::new().route("/containers/attempt-context", get(get_context))
Router::new()
// NOTE: /containers/info is required by the VSCode extension (vibe-kanban-vscode)
// to auto-detect workspaces. It maps workspace_id to attempt_id for compatibility.
// Do not remove this endpoint without updating the extension.
.route("/containers/info", get(get_container_info))
.route("/containers/attempt-context", get(get_context))
}