core: add experimental per-session git worktree mode

Introduce WorktreeHandle to create/reuse/remove linked checkouts under <cwd>/codex/<conversation>; add config flag enable_git_worktree (and trust logic for worktrees); plumb protocol: RemoveWorktree, WorktreeRemoved, SessionConfigured.worktree_path; update exec/TUI integration; docs: experimental config section.

# Conflicts:
#	codex-rs/core/src/codex.rs
#	codex-rs/tui/src/chatwidget.rs
This commit is contained in:
Ahmed Ibrahim
2025-09-29 08:58:37 -07:00
parent 2719fdd12a
commit 103265bac6
18 changed files with 528 additions and 2 deletions
+17
View File
@@ -174,6 +174,9 @@ pub enum Op {
/// Request a code review from the agent.
Review { review_request: ReviewRequest },
/// Remove the git worktree associated with the current session, if any.
RemoveWorktree,
/// Request to shut down codex instance.
Shutdown,
}
@@ -519,6 +522,9 @@ pub enum EventMsg {
/// Exited review mode with an optional final result to apply.
ExitedReviewMode(ExitedReviewModeEvent),
/// Confirmation that a git worktree has been removed.
WorktreeRemoved(WorktreeRemovedEvent),
}
#[derive(Debug, Clone, Deserialize, Serialize, TS)]
@@ -1203,6 +1209,16 @@ pub struct SessionConfiguredEvent {
pub initial_messages: Option<Vec<EventMsg>>,
pub rollout_path: PathBuf,
/// When set, the session is running inside this git worktree checkout.
#[serde(skip_serializing_if = "Option::is_none")]
pub worktree_path: Option<PathBuf>,
}
#[derive(Debug, Clone, Deserialize, Serialize, TS)]
pub struct WorktreeRemovedEvent {
/// Filesystem path that was removed, relative to the host running Codex.
pub path: PathBuf,
}
/// User's decision in response to an ExecApprovalRequest.
@@ -1286,6 +1302,7 @@ mod tests {
history_entry_count: 0,
initial_messages: None,
rollout_path: rollout_file.path().to_path_buf(),
worktree_path: None,
}),
};