Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(cli): avoid working-tree scans before the resume picker
Paulo Vitor Martins1e6754ce1601
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex e148247b..9f73590d 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0provider. (#1026)### Fixed+- Fixed `resume` and `workstreams` running `git status` on every linked checkout+ before listing anything: listing now reads only the checkout's stable+ fingerprints, so a large working tree or a slow filesystem-monitor hook no+ longer blocks the picker before its first frame. (#1039)- Fixed the generated OpenCode 2 plugin ending every tracked session whenOpenCode unloads it on idle-location eviction. Unload is not shutdown: thehost and its sessions stay alive, so each eviction froze a live sessiondiff --git a/crates/ai-memory-cli/src/commands/workstreams.rs b/crates/ai-memory-cli/src/commands/workstreams.rsindex c0c3f01b..bcd8f00b 100644--- a/crates/ai-memory-cli/src/commands/workstreams.rs+++ b/crates/ai-memory-cli/src/commands/workstreams.rs@@ -4,7 +4,7 @@ use std::fmt::Write as _;use std::path::Path;use ai_memory_core::{ListManagedWorkstreamsRequest, ManagedWorkstreamSummary};-use ai_memory_workstream::inspect_repository;+use ai_memory_workstream::inspect_repository_fingerprints;use anyhow::{Context as _, Result};use crate::cli::WorkstreamsArgs;@@ -45,8 +45,8 @@ pub(super) async fn list_for_checkout(checkout: &Path,limit: usize,) -> Result<Vec<ManagedWorkstreamSummary>> {- let repository =- inspect_repository(checkout).context("inspecting managed workstream checkout")?;+ let repository = inspect_repository_fingerprints(checkout)+ .context("inspecting managed workstream checkout")?;post_json(endpoint,"/workstream/recent",diff --git a/crates/ai-memory-workstream/src/lib.rs b/crates/ai-memory-workstream/src/lib.rsindex a2c395a3..1efb1373 100644--- a/crates/ai-memory-workstream/src/lib.rs+++ b/crates/ai-memory-workstream/src/lib.rs@@ -20,7 +20,9 @@ pub use jail::{inside_ai_jail_here, jail_checklist, jail_toggle, marked_choices, parse_jail_toggles,usable_ai_jail, usable_ai_jail_here,};-pub use repository::{RepositoryIdentity, inspect_repository};+pub use repository::{+ RepositoryFingerprints, RepositoryIdentity, inspect_repository, inspect_repository_fingerprints,+};pub use transcript::{AmbiguousNativeSession, ExportedTranscript, NativeSessionCandidate,claude_attached_background_session, claude_live_background_attach_id,diff --git a/crates/ai-memory-workstream/src/repository.rs b/crates/ai-memory-workstream/src/repository.rsindex 73646994..cd4d55d3 100644--- a/crates/ai-memory-workstream/src/repository.rs+++ b/crates/ai-memory-workstream/src/repository.rs@@ -27,9 +27,49 @@ pub struct RepositoryIdentity {pub linked_worktree: bool,}+/// Stable checkout keys, without scanning files or collecting a checkpoint.+#[derive(Debug, Clone, PartialEq, Eq)]+pub struct RepositoryFingerprints {+ /// Repository identity hash shared by linked worktrees.+ pub repo_fingerprint: String,+ /// Worktree-specific identity hash.+ pub worktree_fingerprint: String,+}++struct RepositoryMetadata {+ cwd: PathBuf,+ fingerprints: RepositoryFingerprints,+ linked_worktree: bool,+}+/// Inspect the current checkout without committing, stashing, resetting, or/// otherwise changing it.pub fn inspect_repository(cwd: &Path) -> Result<RepositoryIdentity> {+ let metadata = inspect_metadata(cwd)?;+ Ok(RepositoryIdentity {+ checkpoint: checkpoint(&metadata.cwd),+ origin_push_url: git(&metadata.cwd, &["remote", "get-url", "--push", "origin"])+ .as_deref()+ .and_then(|urls| urls.lines().next())+ .map(str::trim)+ .filter(|url| !url.is_empty())+ .map(str::to_owned),+ cwd: metadata.cwd,+ repo_fingerprint: metadata.fingerprints.repo_fingerprint,+ worktree_fingerprint: metadata.fingerprints.worktree_fingerprint,+ linked_worktree: metadata.linked_worktree,+ })+}++/// Inspect only the stable keys needed to list checkout-local workstreams.+///+/// Listing must not run `git status`: a large working tree or an unavailable+/// filesystem-monitor hook can otherwise block the picker before its first frame.+pub fn inspect_repository_fingerprints(cwd: &Path) -> Result<RepositoryFingerprints> {+ Ok(inspect_metadata(cwd)?.fingerprints)+}++fn inspect_metadata(cwd: &Path) -> Result<RepositoryMetadata> {let canonical = cwd.canonicalize().with_context(|| format!("canonicalizing managed run cwd {}", cwd.display()))?;@@ -55,17 +95,12 @@ pub fn inspect_repository(cwd: &Path) -> Result<RepositoryIdentity> {(_, Some(root)) => format!("{}\nroot\n{root}", sha256(&repo_seed)),_ => format!("{}\ncwd\n{}", sha256(&repo_seed), canonical.display()),};- Ok(RepositoryIdentity {- cwd: canonical.clone(),- repo_fingerprint: sha256(&repo_seed),- worktree_fingerprint: sha256(&worktree_seed),- checkpoint: checkpoint(&canonical),- origin_push_url: git(&canonical, &["remote", "get-url", "--push", "origin"])- .as_deref()- .and_then(|urls| urls.lines().next())- .map(str::trim)- .filter(|url| !url.is_empty())- .map(str::to_owned),+ Ok(RepositoryMetadata {+ cwd: canonical,+ fingerprints: RepositoryFingerprints {+ repo_fingerprint: sha256(&repo_seed),+ worktree_fingerprint: sha256(&worktree_seed),+ },linked_worktree: matches!((&git_dir, &common_dir),(Some(git_dir), Some(common)) if git_dir != common@@ -163,6 +198,9 @@ mod tests {assert_eq!(first.repo_fingerprint.len(), 64);assert_eq!(first.origin_push_url, None);assert!(!first.linked_worktree);+ let lightweight = inspect_repository_fingerprints(temp.path()).unwrap();+ assert_eq!(lightweight.repo_fingerprint, first.repo_fingerprint);+ assert_eq!(lightweight.worktree_fingerprint, first.worktree_fingerprint);}fn git_fixture(cwd: &Path, args: &[&str]) {@@ -226,6 +264,13 @@ mod tests {let worktree = inspect_repository(&linked).unwrap();assert!(worktree.linked_worktree);assert_eq!(worktree.origin_push_url, primary.origin_push_url);+ for (path, full) in [(&main, &primary), (&linked, &worktree)] {+ let lightweight = inspect_repository_fingerprints(path).unwrap();+ assert_eq!(lightweight.repo_fingerprint, full.repo_fingerprint);+ assert_eq!(lightweight.worktree_fingerprint, full.worktree_fingerprint);+ }+ assert_eq!(primary.repo_fingerprint, worktree.repo_fingerprint);+ assert_ne!(primary.worktree_fingerprint, worktree.worktree_fingerprint);}/// The push URL counts, not the fetch URL. The `.invalid` host keeps a