Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(backfill): hide Windows git probes
AkitaOnRailsb4bd68a946c8
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 8176204f..13c255bb 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -13,6 +13,9 @@ version in [`docs/changelog/`](docs/changelog/):### Fixed+- Automatic backfill no longer flashes a console window for each Git probe on+ Windows. Git children inherit `CREATE_NO_WINDOW`, and a run resolves each+ harness's session directory only once (#1727).- The OpenCode version probe now waits up to 10 seconds instead of 2, allowingcold-start executable scanning and loaded hosts without treating a workinginstallation as hung (#1718).diff --git a/crates/ai-memory-cli/src/commands/backfill.rs b/crates/ai-memory-cli/src/commands/backfill.rsindex b8c696f9..d2909a79 100644--- a/crates/ai-memory-cli/src/commands/backfill.rs+++ b/crates/ai-memory-cli/src/commands/backfill.rs@@ -433,13 +433,24 @@ async fn run_in(config: &Config, args: crate::cli::BackfillArgs, cwd: PathBuf) -// Import each selected session, oldest-first so the imported history reads// chronologically, until the total-events circuit breaker trips.+ let mut session_dirs: Vec<(ManagedHarness, Option<PathBuf>)> = Vec::new();for session in selected.into_iter().rev() {if report.imported_events >= MAX_EVENTS_TOTAL {report.skipped_for_cap += 1;continue;}- match import_one(- &endpoint, &workspace, &project, &home, &cwd, &capture, &session,+ let session_dir = cached_session_dir(&mut session_dirs, session.harness, || {+ import_session_dir(&home, &cwd, session.harness)+ });+ match import_one_with_session_dir(+ &endpoint,+ &workspace,+ &project,+ &home,+ &cwd,+ &capture,+ &session,+ session_dir.as_deref(),).await{@@ -715,6 +726,7 @@ fn acknowledged_items(ack: &HookBatchAck, items: &[&HookItem]) -> Result<Vec<usi/// every event, so retroactive text crosses the same trust boundary as live/// capture, and `capture` drops or strips tool events the checkout's/// `[capture] ignore_paths` excludes before anything is posted.+#[cfg(test)]async fn import_one(endpoint: &ServerEndpoint,workspace: &str,@@ -724,11 +736,51 @@ async fn import_one(capture: &TranscriptCapture,session: &SessionRef,) -> Result<usize> {+ let session_dir = import_session_dir(home, cwd, session.harness);+ import_one_with_session_dir(+ endpoint,+ workspace,+ project,+ home,+ cwd,+ capture,+ session,+ session_dir.as_deref(),+ )+ .await+}++fn import_session_dir(home: &Path, cwd: &Path, harness: ManagedHarness) -> Option<PathBuf> {let roots = LaunchRoots { home, cwd };- let session_dir =- build_launch_plan_with_env(session.harness, None, Vec::new(), None, &[], Some(roots))- .ok()- .and_then(|plan| plan.session_dir);+ build_launch_plan_with_env(harness, None, Vec::new(), None, &[], Some(roots))+ .ok()+ .and_then(|plan| plan.session_dir)+}++fn cached_session_dir(+ cache: &mut Vec<(ManagedHarness, Option<PathBuf>)>,+ harness: ManagedHarness,+ resolve: impl FnOnce() -> Option<PathBuf>,+) -> Option<PathBuf> {+ if let Some((_, session_dir)) = cache.iter().find(|(cached, _)| *cached == harness) {+ return session_dir.clone();+ }+ let session_dir = resolve();+ cache.push((harness, session_dir.clone()));+ session_dir+}++#[allow(clippy::too_many_arguments)]+async fn import_one_with_session_dir(+ endpoint: &ServerEndpoint,+ workspace: &str,+ project: &str,+ home: &Path,+ cwd: &Path,+ capture: &TranscriptCapture,+ session: &SessionRef,+ session_dir: Option<&Path>,+) -> Result<usize> {import_exact_session(endpoint,workspace,@@ -737,7 +789,7 @@ async fn import_one(cwd,session.harness,&session.native_session_id,- session_dir.as_deref(),+ session_dir,None,capture,)@@ -1385,6 +1437,24 @@ mod tests {);}+ #[test]+ fn session_directory_resolution_is_cached_per_harness() {+ let mut cache = Vec::new();+ let mut calls = 0;+ let first = cached_session_dir(&mut cache, ManagedHarness::Crush, || {+ calls += 1;+ Some(PathBuf::from("crush-data"))+ });+ let second = cached_session_dir(&mut cache, ManagedHarness::Crush, || {+ calls += 1;+ Some(PathBuf::from("wrong"))+ });++ assert_eq!(first, Some(PathBuf::from("crush-data")));+ assert_eq!(second, first);+ assert_eq!(calls, 1);+ }+#[test]fn member_sessions_path_encodes_each_name_as_one_segment() {assert_eq!(diff --git a/crates/ai-memory-consolidate/src/bootstrap.rs b/crates/ai-memory-consolidate/src/bootstrap.rsindex 9875fa54..9b2be9c1 100644--- a/crates/ai-memory-consolidate/src/bootstrap.rs+++ b/crates/ai-memory-consolidate/src/bootstrap.rs@@ -866,7 +866,7 @@ pub fn discover_main_repo_root(start: &Path) -> Result<PathBuf, BootstrapError>#[cfg(windows)]fn discover_main_repo_root_fallback(start: &Path) -> Result<PathBuf, BootstrapError> {- let is_bare = std::process::Command::new("git")+ let is_bare = git_command().arg("-C").arg(start).args(["rev-parse", "--is-bare-repository"])@@ -877,7 +877,7 @@ fn discover_main_repo_root_fallback(start: &Path) -> Result<PathBuf, BootstrapEr}let is_bare = String::from_utf8_lossy(&is_bare.stdout).trim() == "true";- let output = std::process::Command::new("git")+ let output = git_command().arg("-C").arg(start).args(["rev-parse", "--path-format=absolute", "--git-common-dir"])@@ -1039,7 +1039,7 @@ fn collect_git_commits_fallback(path = %repo_path.display(),"git2 failed to open repository; falling back to git CLI");- let output = std::process::Command::new("git")+ let output = git_command().arg("-C").arg(repo_path).args([@@ -1096,6 +1096,15 @@ fn collect_git_commits_fallback(Ok(out)}+#[cfg(windows)]+fn git_command() -> std::process::Command {+ use std::os::windows::process::CommandExt as _;++ let mut command = std::process::Command::new("git");+ command.creation_flags(0x0800_0000); // CREATE_NO_WINDOW+ command+}+#[cfg(not(windows))]fn collect_git_commits_fallback(_repo_path: &Path,diff --git a/crates/ai-memory-workstream/src/repository.rs b/crates/ai-memory-workstream/src/repository.rsindex cd4d55d3..19834dad 100644--- a/crates/ai-memory-workstream/src/repository.rs+++ b/crates/ai-memory-workstream/src/repository.rs@@ -145,15 +145,22 @@ fn git(cwd: &Path, args: &[&str]) -> Option<String> {}fn git_bytes(cwd: &Path, args: &[&str]) -> Option<Vec<u8>> {- let output = Command::new("git")- .arg("-C")- .arg(cwd)- .args(args)- .output()- .ok()?;+ let mut command = Command::new("git");+ hide_console(&mut command);+ let output = command.arg("-C").arg(cwd).args(args).output().ok()?;output.status.success().then_some(output.stdout)}+#[cfg(windows)]+fn hide_console(command: &mut Command) {+ use std::os::windows::process::CommandExt as _;++ command.creation_flags(0x0800_0000); // CREATE_NO_WINDOW+}++#[cfg(not(windows))]+fn hide_console(_command: &mut Command) {}+fn parse_status_paths(status: &[u8]) -> Vec<String> {let mut entries = status.split(|byte| *byte == 0).peekable();let mut paths = Vec::new();diff --git a/docs/design-boot-backfill.md b/docs/design-boot-backfill.mdindex bb2ac707..f9ddcdf2 100644--- a/docs/design-boot-backfill.md+++ b/docs/design-boot-backfill.md@@ -229,6 +229,9 @@ Retroactive text is exactly as untrusted as live hook text, since it is old modecontacting the server.- **Emptiness + lease** prevent a backfill from overwriting or racing an establishedproject's real history.+- **Detached Windows execution stays hidden.** Git CLI fallbacks and repository+ probes use `CREATE_NO_WINDOW`, and one backfill caches the session directory per+ harness instead of repeating the same checkout probe for every selected session.- **Multi-user posture.** On a shared server, default-on retro-import of a long localhistory is more sensitive than on a single-user box. Backfill attributes to the bootingoperator, imports only into an *empty* project scope, and is opt-outable per project via