From 226c44dc770dd0ea42e322af4d0edd6c14ce14db Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 18 Nov 2026 12:45:05 +0100 Subject: 0.11.0: /undo via git checkpoints, /compact, provider presets, leniency, system CA - /undo resets to a git checkpoint taken before each turn - /compact summarises and rewrites the transcript (ADR 0003, the one sanctioned rewrite) - --provider presets for six OpenAI-compatible gateways, local ones lenient by default - --lenient and --system-ca - proxies already honoured via ureq; documented --- src/git.rs | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/git.rs (limited to 'src/git.rs') diff --git a/src/git.rs b/src/git.rs new file mode 100644 index 0000000..78348af --- /dev/null +++ b/src/git.rs @@ -0,0 +1,57 @@ +//! Git helpers for the checkpoint/undo feature. In a separate module so they +//! are unit-testable without driving the whole CLI. + +use std::path::Path; +use std::process::Command; + +/// Runs `git -C `, returning trimmed stdout on success. +pub fn run(dir: &Path, args: &[&str]) -> Option { + Command::new("git") + .arg("-C") + .arg(dir) + .args(args) + .output() + .ok() + .and_then(|output| { + output + .status + .success() + .then(|| String::from_utf8_lossy(&output.stdout).trim().to_string()) + }) +} + +/// True when `dir` is inside a work tree (a `.git` dir or file up the tree). +pub fn in_repo(dir: &Path) -> bool { + let mut current = dir.to_path_buf(); + loop { + if current.join(".git").exists() { + return true; + } + if !current.pop() { + return false; + } + } +} + +/// Snapshots the tree as a commit when it is dirty, and returns HEAD. Returns +/// `None` outside a repository. +pub fn checkpoint(dir: &Path) -> Option { + if !in_repo(dir) { + return None; + } + run(dir, &["add", "-A"]); + let dirty = run(dir, &["status", "--porcelain"]) + .map(|status| !status.is_empty()) + .unwrap_or(false); + if dirty { + run(dir, &["commit", "-m", "agent686: checkpoint"]); + } + run(dir, &["rev-parse", "HEAD"]) +} + +/// Resets to the checkpoint commit and drops untracked files, undoing a turn's +/// changes. +pub fn undo(dir: &Path, sha: &str) { + run(dir, &["reset", "--hard", sha]); + run(dir, &["clean", "-fd"]); +} -- cgit v1.2.3