Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(bootstrap): read a rules file once when two names reach it
AkitaOnRails335cd3a15fb3
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 4fa0d999..c8459020 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -21,6 +21,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0trust each other's baselines. The state directory now ignores itself witha `.gitignore` of `*`. A state committed by an earlier export needs one`git rm -r --cached <dest>/.ai-memory-wikisync`. (#1162)+- Fixed `bootstrap` reading a rules file twice when it is reachable under two+ names: on a case-insensitive filesystem `claude.md` opened `CLAUDE.md`+ again, and on any system a `CLAUDE.md` linked to `AGENTS.md` did the same.+ The doubled text inflated the token estimate, could push every source over+ the budget (`no input sources selected`), and repeated the rules in the+ prompt. Only names the directory lists are read now, and identical text is+ read once. (#1168)- Fixed the macOS menu bar companion's **Settings…** item opening theSettings window behind the frontmost app, so clicking it appeared to donothing. The item now activates the app before opening the window, asdiff --git a/crates/ai-memory-consolidate/src/bootstrap.rs b/crates/ai-memory-consolidate/src/bootstrap.rsindex 6e096e19..99e295c0 100644--- a/crates/ai-memory-consolidate/src/bootstrap.rs+++ b/crates/ai-memory-consolidate/src/bootstrap.rs@@ -1227,11 +1227,22 @@ fn collect_rust_module_headers(repo_path: &Path) -> Result<Vec<BootstrapSource>,}fn collect_project_rules(repo_path: &Path) -> Result<Vec<BootstrapSource>, BootstrapError> {- let mut out = Vec::new();+ // A case-insensitive filesystem answers `claude.md` with `CLAUDE.md`, and+ // a symlinked or hard-linked rules file is the same file under another+ // name: only names the directory actually lists are read, and a text+ // already collected is not collected again (#1168).+ let listed: std::collections::HashSet<std::ffi::OsString> = std::fs::read_dir(repo_path)+ .map(|entries| entries.flatten().map(|entry| entry.file_name()).collect())+ .unwrap_or_default();+ let mut out: Vec<BootstrapSource> = Vec::new();for name in ["CLAUDE.md", "AGENTS.md", "AGENT.md", "claude.md"] {+ if !listed.contains(std::ffi::OsStr::new(name)) {+ continue;+ }let p = repo_path.join(name);if p.is_file()&& let Ok(text) = std::fs::read_to_string(&p)+ && !out.iter().any(|source| source.text == text){out.push(BootstrapSource {kind: SourceKind::ProjectRules,@@ -1589,6 +1600,49 @@ fn render_manifest_body(input: ManifestRender<'_>) -> String {#[cfg(test)]mod tests {use super::*;++ fn rules_labels(repo: &Path) -> Vec<String> {+ collect_project_rules(repo)+ .unwrap()+ .into_iter()+ .map(|source| source.label)+ .collect()+ }++ /// #1168: one rules file reachable under two names is read once.+ #[cfg(unix)]+ #[test]+ fn a_rules_file_linked_under_another_name_is_read_once() {+ let tmp = tempfile::tempdir().unwrap();+ std::fs::write(tmp.path().join("AGENTS.md"), "# rules\nuse pnpm\n").unwrap();+ std::os::unix::fs::symlink("AGENTS.md", tmp.path().join("CLAUDE.md")).unwrap();+ std::fs::hard_link(tmp.path().join("AGENTS.md"), tmp.path().join("claude.md")).unwrap();+ assert_eq!(rules_labels(tmp.path()), vec!["rules: CLAUDE.md"]);+ }++ /// Two rules files with different content are both read, even when+ /// their names differ only in case (possible on a case-sensitive+ /// filesystem).+ #[test]+ fn distinct_rules_files_are_all_read() {+ let tmp = tempfile::tempdir().unwrap();+ std::fs::write(tmp.path().join("CLAUDE.md"), "claude rules\n").unwrap();+ std::fs::write(tmp.path().join("AGENTS.md"), "agent rules\n").unwrap();+ assert_eq!(+ rules_labels(tmp.path()),+ vec!["rules: CLAUDE.md", "rules: AGENTS.md"]+ );+ }++ /// A name the directory does not list is not read, which is what a+ /// case-insensitive filesystem would otherwise answer for `claude.md`.+ #[test]+ fn only_listed_names_are_read() {+ let tmp = tempfile::tempdir().unwrap();+ std::fs::write(tmp.path().join("CLAUDE.md"), "claude rules\n").unwrap();+ let labels = rules_labels(tmp.path());+ assert_eq!(labels, vec!["rules: CLAUDE.md"]);+ }use std::fs;use std::sync::atomic::{AtomicUsize, Ordering};use tempfile::TempDir;