Files
codex/codex-rs/tui/src/app_server_session/cloud_project.rs
T
Benjamin Carlsson 7de8a0afc0 Start cloud threads with the local GitHub project (#60007)
## What changed

Pass the local project's GitHub origin to cloud prewarming so new cloud threads can provision a repository checkout. Preserve the attached local project when switching backends and resolve its origin for each thread start.

Normalize supported GitHub origins to credential-free HTTPS URLs and select a repository-specific cloud working directory. Unsupported origins retain the blank environment behavior. Keep project metadata outside the app-server wire protocol, and fix HTTP Git URL parsing so query strings and fragments cannot be mistaken for authority text.

## Testing

Add coverage for project routing, origin normalization and rejection, managed environment encoding, local project retention, and Git URL credential stripping.

GitOrigin-RevId: 5859769965faf060461ccc1cbb3fd48f8e2f2155
2026-11-06 23:00:38 +00:00

49 lines
1.7 KiB
Rust

//! Resolves a host project into credential-free GitHub checkout metadata.
//! Local paths never become cloud executor cwd values or public wire fields.
use codex_app_server_client::ProjectEnvironment;
use std::path::Path;
pub(super) async fn from_local_cwd(cwd: &Path) -> Option<ProjectEnvironment> {
let origin = codex_git_utils::get_git_origin_url(cwd).await?;
github_project(origin.as_str())
}
fn github_project(origin: &str) -> Option<ProjectEnvironment> {
// A relative local path such as github.com/org/repo is not a network origin.
if !origin.contains("://")
&& !origin.split_once(':').is_some_and(|(host, _)| {
host.rsplit('@')
.next()
.is_some_and(|host| host.eq_ignore_ascii_case("github.com"))
})
{
return None;
}
let mut canonical = codex_git_utils::canonicalize_git_remote_url(origin)?;
canonical.make_ascii_lowercase();
let (host, path) = canonical.split_once('/')?;
if !(host == "github.com" || (origin.starts_with("ssh://") && host == "ssh.github.com:443")) {
return None;
}
let (owner, repository) = path.split_once('/')?;
if ![owner, repository].iter().all(|part| {
!part.is_empty()
&& !matches!(*part, "." | "..")
&& part.chars().all(|character| {
character.is_ascii_alphanumeric() || matches!(character, '-' | '_' | '.')
})
}) {
return None;
}
Some(ProjectEnvironment {
name: repository.to_owned(),
cwd: Some(format!("/workspace/{owner}/{repository}")),
origin_urls: vec![format!("https://github.com/{owner}/{repository}")],
})
}
#[cfg(test)]
#[path = "cloud_project_tests.rs"]
mod tests;