Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
bootstrap: resolve repo root via libgit2, drop git-binary dep
AkitaOnRails02c851ebf97d
diff --git a/crates/ai-memory-cli/src/commands/bootstrap.rs b/crates/ai-memory-cli/src/commands/bootstrap.rsindex 8cf1f75b..62e1b0e0 100644--- a/crates/ai-memory-cli/src/commands/bootstrap.rs+++ b/crates/ai-memory-cli/src/commands/bootstrap.rs@@ -11,10 +11,8 @@//! - `AI_MEMORY_SERVER_URL` — base URL of the running server.//! - `AI_MEMORY_AUTH_TOKEN` — bearer token if the server has auth enabled.-use std::path::PathBuf;--use ai_memory_consolidate::{BootstrapOutcome, collect_sources};-use anyhow::{Context, Result, bail};+use ai_memory_consolidate::{BootstrapOutcome, collect_sources, discover_repo_root};+use anyhow::{Context, Result};use tracing::info;use crate::cli::BootstrapArgs;@@ -34,18 +32,14 @@ pub async fn run(_config: &Config, args: BootstrapArgs) -> Result<()> {let ep = ServerEndpoint::from_env();info!(server = %ep.url, auth = ep.auth_token.is_some(), "bootstrap CLI configured");- // ---- repo path — auto-detect if absent -------------------------+ // ---- repo path — auto-detect via libgit2 if absent ------------+ // libgit2 walks up from CWD looking for `.git`, so the slim+ // runtime container doesn't need a `git` binary.let repo_path = match args.repo_path {Some(p) => p,- None => resolve_repo_root().context("auto-detecting --repo-path via git rev-parse")?,+ None => discover_repo_root(std::path::Path::new("."))+ .context("auto-detecting --repo-path (no .git found at or above CWD)")?,};- if !repo_path.join(".git").exists() {- bail!(- "repo path {} is not a git repository (looked for {}/.git)",- repo_path.display(),- repo_path.display()- );- }// ---- collect sources locally ----------------------------------let sources = collect_sources(@@ -167,20 +161,3 @@ fn print_human_report(outcome: &BootstrapOutcome, workspace: &str, project: &strand consolidation will refine the wiki over time.");}--/// `git rev-parse --show-toplevel` — finds the repo root from $PWD.-fn resolve_repo_root() -> Result<PathBuf> {- let output = std::process::Command::new("git")- .args(["rev-parse", "--show-toplevel"])- .output()- .context("running `git rev-parse --show-toplevel`")?;- if !output.status.success() {- bail!(- "git rev-parse failed (cwd is not inside a git repository?). \- stderr: {}",- String::from_utf8_lossy(&output.stderr).trim(),- );- }- let line = String::from_utf8_lossy(&output.stdout).trim().to_string();- Ok(PathBuf::from(line))-}diff --git a/crates/ai-memory-consolidate/src/bootstrap.rs b/crates/ai-memory-consolidate/src/bootstrap.rsindex c6665eb8..caf28b27 100644--- a/crates/ai-memory-consolidate/src/bootstrap.rs+++ b/crates/ai-memory-consolidate/src/bootstrap.rs@@ -459,6 +459,23 @@ pub fn collect_sources(Ok(sources)}+/// Walk up from `start` looking for the nearest `.git` and return+/// the repo root path. Pure libgit2 (no `git` binary required), so+/// the slim runtime container can resolve repo roots too.+///+/// # Errors+/// Returns `BootstrapError::NotARepo` when no repository is found+/// at or above `start`.+pub fn discover_repo_root(start: &Path) -> Result<PathBuf, BootstrapError> {+ let repo = git2::Repository::discover(start)+ .map_err(|_| BootstrapError::NotARepo(start.to_path_buf()))?;+ // `path()` returns the .git dir; the workdir is the parent unless+ // it's a bare repo (which bootstrap doesn't support anyway).+ repo.workdir()+ .map(Path::to_path_buf)+ .ok_or_else(|| BootstrapError::NotARepo(start.to_path_buf()))+}+/// Read commits, format each as a one-paragraph entry. We include/// only commits with a substantive body (more than ~120 chars/// total) — drive-by typo-fix commits aren't worth tokens.diff --git a/crates/ai-memory-consolidate/src/lib.rs b/crates/ai-memory-consolidate/src/lib.rsindex cb79fef0..d9ae4740 100644--- a/crates/ai-memory-consolidate/src/lib.rs+++ b/crates/ai-memory-consolidate/src/lib.rs@@ -16,7 +16,7 @@ pub mod types;pub use bootstrap::{Bootstrap, BootstrapConfig, BootstrapError, BootstrapOutcome, BootstrapSource, SourceCounts,- SourceKind, collect_sources,+ SourceKind, collect_sources, discover_repo_root,};pub use consolidator::{BATCH_SYSTEM_PROMPT, Consolidator, ConsolidatorError, ConsolidatorResult, build_batch_request,