Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

fix(handoff): key the unverified-work heuristic on tool family, not title

AkitaOnRails83cdd46ceaf8
diff --git a/.gitignore b/.gitignore
index cfed8d1d..a17aab5b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -36,7 +36,3 @@ evals/runs/
# ai-memory atomic-write backups (apply_atomic in apply_shared.rs)
*.bak-*
-
-# Nix flake build output (nix build / nix run).
-result
-result-*
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 12728932..a2356558 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,14 +19,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
`:homelab` tag and explains that release tags are published by CI only.
### Added
-- Added a `flake.nix` so NixOS and Nix users can build and run ai-memory
- without the Rust toolchain or Docker: `nix build`, `nix run . --
- --version`, or `nix develop` for a dev shell. The build is self-contained
- (SQLite bundled, libgit2 vendored, rustls with webpki-roots — no OpenSSL,
- no system-library hunting). The flake skips the packaging test suite
- because those tests exercise the Docker-wrapper shell script and need
- `docker`/`podman` on PATH; the rest of the workspace tests can be run via
- `nix develop -c cargo test --workspace`. ([#405])
- New `strip_root_combinators` config flag (env `AI_MEMORY_STRIP_ROOT_COMBINATORS`,
or `strip_root_combinators = true` in config.toml) strips root-level
`anyOf`/`oneOf`/`allOf` from MCP tool input schemas on every `tools/list`.
@@ -42,10 +34,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
multi-signal heuristics instead of blindly copying the last user prompt.
Trailing acknowledgments ("ok", "thanks", "好的") are filtered; a
question-mark-terminated final prompt is tagged as an unresolved question;
- an edit/write tool call without a subsequent Stop produces an explicit
- "changes not verified" advisory; and a mid-task exit (Stop without
- SessionEnd) is flagged so the receiver knows the previous session did not
- finish cleanly. (#NNN)
+ file-tool activity without a subsequent Stop produces an advisory to check
+ the working tree; and a mid-task exit (Stop without SessionEnd) is flagged
+ so the receiver knows the previous session did not finish cleanly. (#425)
### Fixed
- `install-hooks --agent pi`, `--agent omp`, and `uninstall` now honor
diff --git a/crates/ai-memory-hooks/src/router.rs b/crates/ai-memory-hooks/src/router.rs
index 9cdb1ff1..7d210186 100644
--- a/crates/ai-memory-hooks/src/router.rs
+++ b/crates/ai-memory-hooks/src/router.rs
@@ -2981,16 +2981,26 @@ fn derive_open_questions(
}
}
- // Heuristic 2: edit/write without a subsequent Stop → unverified changes.
+ // Heuristic 2: file activity with no subsequent Stop → the session ended
+ // abnormally while working in the tree.
+ //
+ // The signal is the tool *family*, not the tool name. A PostToolUse
+ // observation's title is `canonical_tool_name(tool_family)`, which is
+ // only ever "file" / "search-list" / "non-file" / "unknown" — the
+ // reserved protocol deliberately carries no raw tool names. Matching
+ // "edit"/"write"/"patch" against that title can never succeed.
+ //
+ // That same closed schema means read and write are indistinguishable:
+ // `ToolFamily::File` covers both, and `ToolOutcome` is only
+ // success/error/unknown. So this cannot honestly claim changes were
+ // made — only that the session touched files and then ended without a
+ // normal Stop, which is worth telling the receiver either way.
if let Some(tool) = last_tool {
- let title = tool.title.as_str();
- let unverified =
- (title.contains("edit") || title.contains("write") || title.contains("patch"))
- && last_stop.is_none();
- if unverified {
+ let touched_files = tool.title == canonical_tool_name(ToolFamily::File);
+ if touched_files && last_stop.is_none() {
return vec![
- "Changes were made but the session ended before verification".into(),
- "Run tests or lint to confirm the changes are correct".into(),
+ "Session ended without a normal stop while working with files".into(),
+ "Check the working tree for uncommitted or unverified changes".into(),
];
}
}
@@ -11780,18 +11790,62 @@ mod tests {
assert!(q[0].contains("return type"));
}
+ /// The fixture title must come from `canonical_tool_name`, the same
+ /// function the ingest path uses. An earlier version of this test passed
+ /// a literal `"edit"`, which production never emits — so the heuristic
+ /// was dead code while the test stayed green.
#[test]
- fn open_questions_detects_unverified_edit() {
+ fn open_questions_detects_abnormal_exit_after_file_activity() {
let obs = vec![
mk_obs(ObservationKind::UserPrompt, "fix bug", "fix the bug"),
- mk_obs(ObservationKind::PostToolUse, "edit", "edited main.rs"),
+ mk_obs(
+ ObservationKind::PostToolUse,
+ canonical_tool_name(ToolFamily::File),
+ "tool_family: file\noutcome: unknown",
+ ),
// No Stop observation — session ended mid-task.
];
let last = Some("fix the bug".to_string());
let q = derive_open_questions(&obs, &last);
- assert_eq!(q.len(), 2);
- assert!(q[0].contains("ended before verification"));
- assert!(q[1].contains("Run tests"));
+ assert_eq!(q.len(), 2, "got: {q:?}");
+ assert!(q[0].contains("without a normal stop"), "got: {q:?}");
+ assert!(q[1].contains("working tree"), "got: {q:?}");
+ }
+
+ /// Guard against the regression this heuristic already had once: only
+ /// titles the ingest path can actually produce may drive it, so a raw
+ /// tool name must NOT trigger the file branch.
+ #[test]
+ fn open_questions_ignores_raw_tool_names_production_never_emits() {
+ for bogus in ["edit", "write", "patch", "Edit"] {
+ let obs = vec![
+ mk_obs(ObservationKind::UserPrompt, "fix bug", "fix the bug"),
+ mk_obs(ObservationKind::PostToolUse, bogus, "edited main.rs"),
+ ];
+ let q = derive_open_questions(&obs, &Some("fix the bug".to_string()));
+ assert!(
+ q.iter().all(|s| !s.contains("without a normal stop")),
+ "title {bogus:?} is not a canonical tool family and must not \
+ drive the file heuristic; got: {q:?}"
+ );
+ }
+ }
+
+ /// A search/list tool is file-adjacent but not file activity; it must
+ /// fall through to the prompt-based heuristics.
+ #[test]
+ fn open_questions_search_tool_does_not_trigger_file_branch() {
+ let obs = vec![
+ mk_obs(ObservationKind::UserPrompt, "find it", "find the caller"),
+ mk_obs(
+ ObservationKind::PostToolUse,
+ canonical_tool_name(ToolFamily::SearchList),
+ "tool_family: search-list\noutcome: success",
+ ),
+ ];
+ let q = derive_open_questions(&obs, &Some("find the caller".to_string()));
+ assert_eq!(q.len(), 1, "got: {q:?}");
+ assert!(q[0].starts_with("Continue from:"), "got: {q:?}");
}
#[test]
diff --git a/flake.nix b/flake.nix
deleted file mode 100644
index 36cd57bc..00000000
--- a/flake.nix
+++ /dev/null
@@ -1,135 +0,0 @@
-# Nix flake for ai-memory.
-#
-# Provides:
-# nix build # → result/bin/ai-memory (native release binary)
-# nix run . -- --version # smoke-test without installing
-# nix develop # dev shell with Rust 1.95 (pinned)
-#
-# The build is self-contained: SQLite is bundled via rusqlite's `bundled`
-# feature, libgit2 is vendored via git2's `vendored-libgit2` feature, and
-# TLS uses rustls (webpki-roots) — no OpenSSL, no system-library hunting.
-# The only extra step is TAILWIND_SKIP=1 so the web crate's build script
-# uses the vendored static/tailwind.css instead of downloading the
-# Tailwind CLI (which a sandboxed Nix build cannot do).
-#
-# `doCheck = false` skips the packaging test suite. Those tests exercise
-# `bin/ai-memory`, a Docker-wrapper shell script that needs `docker` or
-# `podman` on PATH — they are host-environment tests, not build tests,
-# and are not Nix's responsibility. Run them manually with
-# `nix develop -c cargo test -p ai-memory-cli --test packaging` if your
-# machine has Docker.
-
-{
- description = "Long-term memory for AI coding agents";
-
- inputs = {
- nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
- flake-utils.url = "github:numtide/flake-utils";
- rust-overlay = {
- url = "github:oxalica/rust-overlay";
- inputs.nixpkgs.follows = "nixpkgs";
- };
- };
-
- outputs =
- {
- nixpkgs,
- flake-utils,
- rust-overlay,
- ...
- }:
- flake-utils.lib.eachDefaultSystem (
- system:
- let
- pkgs = import nixpkgs {
- inherit system;
- overlays = [ (import rust-overlay) ];
- };
-
- # Read the same toolchain file the project pins for every other CI
- # path — rust-toolchain.toml says `channel = "1.95"`.
- rust = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
-
- rustPlatform = pkgs.makeRustPlatform {
- rustc = rust;
- cargo = rust;
- };
- in
- {
- packages.default = rustPlatform.buildRustPackage {
- pname = "ai-memory";
- version = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).workspace.package.version;
-
- src = ./.;
- cargoLock.lockFile = ./Cargo.lock;
-
- # No nativeBuildInputs needed — the build is fully self-contained
- # (SQLite bundled, libgit2 vendored, rustls with webpki-roots).
-
- # Skip the Tailwind CLI download in the sandbox. The build script
- # falls back to the vendored static/tailwind.css committed to the
- # repo (see crates/ai-memory-web/build.rs).
- TAILWIND_SKIP = "1";
-
- buildType = "release";
-
- # The packaging test suite (tests/packaging.rs) exercises the
- # Docker-wrapper shell script `bin/ai-memory` and needs
- # docker/podman on PATH — not available in a Nix sandbox. The
- # rest of the workspace test suite (unit tests + integration)
- # does not need them and can be run via `nix develop -c cargo
- # test --workspace` on a machine with Docker.
- doCheck = false;
-
- # Install the bundled hook scripts alongside the binary,
- # mirroring what the AUR PKGBUILD does. Native binary users
- # (`ai-memory serve`, `install-hooks`) look up hooks under
- # the binary's share directory at runtime.
- #
- # `bin/ai-memory` (the Docker-wrapper shell script) is NOT
- # installed — Nix users build the native binary directly and
- # have no need for a Docker wrapper.
- postInstall = ''
- mkdir -p $out/share/ai-memory
- cp -a hooks $out/share/ai-memory/
-
- # Install the default config template so `ai-memory init`
- # has a known-good starting point without a network fetch.
- mkdir -p $out/etc/ai-memory
- cp crates/ai-memory-cli/templates/config.default.toml \
- $out/etc/ai-memory/config.default.toml
- '';
-
- meta = {
- description = "Long-term memory for AI coding agents";
- homepage = "https://github.com/akitaonrails/ai-memory";
- license = pkgs.lib.licenses.mit;
- mainProgram = "ai-memory";
- };
- };
-
- devShells.default = pkgs.mkShell {
- name = "ai-memory-dev";
-
- buildInputs = [
- rust
- pkgs.cargo-watch
- ];
-
- # Same escape hatch for local `cargo build` / `cargo test` —
- # prevents the web crate from trying to download Tailwind.
- TAILWIND_SKIP = "1";
-
- shellHook = ''
- echo ""
- echo "ai-memory dev shell — Rust $(rustc --version)"
- echo ""
- echo " cargo build --workspace # build"
- echo " cargo test --workspace # unit + integration tests"
- echo " cargo test -p ai-memory-cli --test packaging # needs docker"
- echo ""
- '';
- };
- }
- );
-}