Compare commits

...

1 Commits

Author SHA1 Message Date
Dylan Hurd
e332154dd4 git repo once 2025-08-06 06:24:57 -07:00
2 changed files with 18 additions and 13 deletions

View File

@@ -52,6 +52,7 @@ use crate::exec::SandboxType;
use crate::exec::StdoutStream; use crate::exec::StdoutStream;
use crate::exec::process_exec_tool_call; use crate::exec::process_exec_tool_call;
use crate::exec_env::create_env; use crate::exec_env::create_env;
use crate::git_info::GitInfo;
use crate::git_info::collect_git_info; use crate::git_info::collect_git_info;
use crate::mcp_connection_manager::McpConnectionManager; use crate::mcp_connection_manager::McpConnectionManager;
use crate::mcp_tool_call::handle_mcp_tool_call; use crate::mcp_tool_call::handle_mcp_tool_call;
@@ -213,6 +214,7 @@ pub(crate) struct Session {
/// the model as well as sandbox policies are resolved against this path /// the model as well as sandbox policies are resolved against this path
/// instead of `std::env::current_dir()`. /// instead of `std::env::current_dir()`.
pub(crate) cwd: PathBuf, pub(crate) cwd: PathBuf,
git_info: Option<GitInfo>,
base_instructions: Option<String>, base_instructions: Option<String>,
user_instructions: Option<String>, user_instructions: Option<String>,
pub(crate) approval_policy: AskForApproval, pub(crate) approval_policy: AskForApproval,
@@ -725,11 +727,12 @@ async fn submission_loop(
} }
return; return;
} }
let git_info = collect_git_info(&cwd).await;
// Optionally resume an existing rollout. // Optionally resume an existing rollout.
let mut restored_items: Option<Vec<ResponseItem>> = None; let mut restored_items: Option<Vec<ResponseItem>> = None;
let rollout_recorder: Option<RolloutRecorder> = let rollout_recorder: Option<RolloutRecorder> =
if let Some(path) = resume_path.as_ref() { if let Some(path) = resume_path.as_ref() {
match RolloutRecorder::resume(path, cwd.clone()).await { match RolloutRecorder::resume(path, git_info.clone()).await {
Ok((rec, saved)) => { Ok((rec, saved)) => {
session_id = saved.session_id; session_id = saved.session_id;
if !saved.items.is_empty() { if !saved.items.is_empty() {
@@ -749,8 +752,13 @@ async fn submission_loop(
let rollout_recorder = match rollout_recorder { let rollout_recorder = match rollout_recorder {
Some(rec) => Some(rec), Some(rec) => Some(rec),
None => { None => {
match RolloutRecorder::new(&config, session_id, user_instructions.clone()) match RolloutRecorder::new(
.await &config,
session_id,
user_instructions.clone(),
git_info.clone(),
)
.await
{ {
Ok(r) => Some(r), Ok(r) => Some(r),
Err(e) => { Err(e) => {
@@ -829,6 +837,7 @@ async fn submission_loop(
sandbox_policy, sandbox_policy,
shell_environment_policy: config.shell_environment_policy.clone(), shell_environment_policy: config.shell_environment_policy.clone(),
cwd, cwd,
git_info,
writable_roots, writable_roots,
mcp_connection_manager, mcp_connection_manager,
notify, notify,
@@ -1228,7 +1237,7 @@ async fn run_turn(
base_instructions_override: sess.base_instructions.clone(), base_instructions_override: sess.base_instructions.clone(),
environment_context: Some(EnvironmentContext { environment_context: Some(EnvironmentContext {
cwd: sess.cwd.clone(), cwd: sess.cwd.clone(),
git_info: collect_git_info(&sess.cwd).await, git_info: sess.git_info.clone(),
approval_policy: sess.approval_policy, approval_policy: sess.approval_policy,
sandbox_policy: sess.sandbox_policy.clone(), sandbox_policy: sess.sandbox_policy.clone(),
}), }),

View File

@@ -21,7 +21,6 @@ use uuid::Uuid;
use crate::config::Config; use crate::config::Config;
use crate::git_info::GitInfo; use crate::git_info::GitInfo;
use crate::git_info::collect_git_info;
use crate::models::ResponseItem; use crate::models::ResponseItem;
const SESSIONS_SUBDIR: &str = "sessions"; const SESSIONS_SUBDIR: &str = "sessions";
@@ -82,6 +81,7 @@ impl RolloutRecorder {
config: &Config, config: &Config,
uuid: Uuid, uuid: Uuid,
instructions: Option<String>, instructions: Option<String>,
git_info: Option<GitInfo>,
) -> std::io::Result<Self> { ) -> std::io::Result<Self> {
let LogFileInfo { let LogFileInfo {
file, file,
@@ -96,9 +96,6 @@ impl RolloutRecorder {
.format(timestamp_format) .format(timestamp_format)
.map_err(|e| IoError::other(format!("failed to format timestamp: {e}")))?; .map_err(|e| IoError::other(format!("failed to format timestamp: {e}")))?;
// Clone the cwd for the spawned task to collect git info asynchronously
let cwd = config.cwd.clone();
// A reasonably-sized bounded channel. If the buffer fills up the send // A reasonably-sized bounded channel. If the buffer fills up the send
// future will yield, which is fine we only need to ensure we do not // future will yield, which is fine we only need to ensure we do not
// perform *blocking* I/O on the caller's thread. // perform *blocking* I/O on the caller's thread.
@@ -115,7 +112,7 @@ impl RolloutRecorder {
id: session_id, id: session_id,
instructions, instructions,
}), }),
cwd, git_info,
)); ));
Ok(Self { tx }) Ok(Self { tx })
@@ -157,7 +154,7 @@ impl RolloutRecorder {
pub async fn resume( pub async fn resume(
path: &Path, path: &Path,
cwd: std::path::PathBuf, git_info: Option<GitInfo>,
) -> std::io::Result<(Self, SavedSession)> { ) -> std::io::Result<(Self, SavedSession)> {
info!("Resuming rollout from {path:?}"); info!("Resuming rollout from {path:?}");
let text = tokio::fs::read_to_string(path).await?; let text = tokio::fs::read_to_string(path).await?;
@@ -220,7 +217,7 @@ impl RolloutRecorder {
tokio::fs::File::from_std(file), tokio::fs::File::from_std(file),
rx, rx,
None, None,
cwd, git_info,
)); ));
info!("Resumed rollout successfully from {path:?}"); info!("Resumed rollout successfully from {path:?}");
Ok((Self { tx }, saved)) Ok((Self { tx }, saved))
@@ -291,13 +288,12 @@ async fn rollout_writer(
file: tokio::fs::File, file: tokio::fs::File,
mut rx: mpsc::Receiver<RolloutCmd>, mut rx: mpsc::Receiver<RolloutCmd>,
mut meta: Option<SessionMeta>, mut meta: Option<SessionMeta>,
cwd: std::path::PathBuf, git_info: Option<GitInfo>,
) -> std::io::Result<()> { ) -> std::io::Result<()> {
let mut writer = JsonlWriter { file }; let mut writer = JsonlWriter { file };
// If we have a meta, collect git info asynchronously and write meta first // If we have a meta, collect git info asynchronously and write meta first
if let Some(session_meta) = meta.take() { if let Some(session_meta) = meta.take() {
let git_info = collect_git_info(&cwd).await;
let session_meta_with_git = SessionMetaWithGit { let session_meta_with_git = SessionMetaWithGit {
meta: session_meta, meta: session_meta,
git: git_info, git: git_info,