Skip to content

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

Rust

Merge PR #1312: feat(hooks): register CodeBuddy Code as a first-party agent (#1299)

AkitaOnRails09447d155110
diff --cc CHANGELOG.md
index 3aa4bb3a,59b3e9a2..dccffdac
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@@ -12,114 -12,21 +12,130 @@@ version in [`docs/changelog/`](docs/cha
## [Unreleased]
### Added
+- Added opt-in session inspection and owned-session purging for signed-in
+ browser users, enabled at runtime with `serve --enable-session-management`
+ (`AI_MEMORY_ENABLE_SESSION_MANAGEMENT`). A user can purge only a session they
+ own in a project they may write; an Admin can purge any. Requested in #1231.
+ (#1267)
+- Added opt-in self-service `aim_` API keys for signed-in browser users,
+ enabled at runtime with `serve --enable-self-service-keys`
+ (`AI_MEMORY_ENABLE_SELF_SERVICE_KEYS`). Labels must be 1 to 128 characters
+ and a user may hold at most 20 active keys. A self-issued key survives a
+ password reset or account disable and must be revoked separately. Requested
+ in #1231. (#1268)
+- Added `ai-memory search --global`, which searches the wiki pages of every
+ project from the terminal instead of only the current one. Each hit shows
+ its `workspace/project` in the text output and carries `workspace` and
+ `project` fields in `--json`. The flag cannot be combined with
+ `--workspace` or `--project`, and a search without it still resolves its
+ scope from the current directory. The server side is `GET /admin/search`
+ with no `workspace`/`project`: its hits now include `workspace` and
+ `project` next to the fields they already had, and the route stays
+ root-only on a multi-user server. Global search covers wiki pages only;
+ raw observations and a search limited to one workspace are not part of
+ this change. (#1253)
+- Added kind and tier filters to the web search. The search page in `/web`
+ has "Kind" and "Tier" selects, and `/web/search` accepts `kind` and `tier`
+ for both a project search and a cross-project one. Every retrieval stream
+ applies the filter in its own query, so other kinds cannot crowd out a rare
+ one, a filtered search asks the streams for no more candidates than an
+ unfiltered one, and the reranker scores only pages the filter keeps. Kind
+ and tier both ignore case, a nonstandard kind is flagged on an empty
+ result, and "Search all projects" keeps the filters. An unknown `tier` is
+ a 400. (#1248)
+- Added `ai-memory setup --plan`, which prints the plan and changes nothing,
+ and `--plan --json`, which prints it as a JSON document with a `format`
+ version for a script or front end to render. The plan now says what each
+ detected agent was found by (its session store, its MCP config, or Muse's
+ directory), numbers the agents, and lists the other agents `--agent`
+ accepts. At the prompt you can type the numbers of the agents to wire
+ instead of `y`; a number outside the plan changes nothing. (#1270)
+- Added a native Windows path to the two-command install. `install.ps1`,
+ published with each release next to its own `.sha256`, checks the release
+ zip against that checksum, refuses archive entries that are absolute or
+ hold `..`, unpacks it under `%LOCALAPPDATA%\Programs\ai-memory` and adds
+ that directory to the user `PATH` (`AI_MEMORY_NO_MODIFY_PATH=1` skips it),
+ with no administrator rights. `ai-memory setup` now has a service step on
+ Windows: it writes an `ai-memory` value under the per-user `Run` key that
+ starts a hidden `ai-memory service-host` at logon, and starts it right away.
+ The value is written and read through the registry API, not by running
+ `reg.exe`: an unsigned binary running `reg.exe add` on the `Run` key is a
+ common persistence signal, and Bitdefender's behavioral engine quarantined
+ `ai-memory.exe` for it (#1280). Its paths are written plainly, without the
+ `\\?\` prefix a canonical path carries.
+ The host runs the server with no console window and restarts it after a
+ failure, giving up after five failures within ten seconds of starting.
+ `ai-memory uninstall --apply` stops the host and removes the value when it
+ still has the shape `setup` writes and names this install's data dir, so an
+ uninstall against another data dir (a second install, a test's temporary
+ one) leaves the entry alone. (#1271, #1280)
+- Added `ai-memory setup --web`, which shows the setup plan as a page in
+ your browser and applies the agents you tick there by running `ai-memory
+ setup --yes --agent ...` and streaming its output to the page. The page is
+ served on `127.0.0.1` behind a one-time address printed in the terminal
+ (opened in the browser unless `--no-open` or there is no desktop), refuses
+ requests with another `Host`, without the address's secret, or, for a
+ change, without the page's own `Origin` and CSRF token, and holds no token.
+ It stops on Finish, after 15 minutes without a request, or on Ctrl-C. (#1272)
+- Added a desktop installer preview, `companions/ai-memory-desktop`: a Tauri
+ app that uses an existing `ai-memory` install or copies its bundled one into
+ the same per-user location as `install.sh` and `install.ps1`, then shows the
+ `ai-memory setup --web` page in its own window. CI builds unsigned Linux,
+ macOS and Windows installers on manual dispatch; they are not attached to
+ releases until the project signs them. `setup --web` gained a hidden
+ `--stop-on-stdin-eof` flag so the page stops when the app does. (#1273)
+- A prompt that starts with `reload context` (for example `reload context
+ after last compaction, then …`) now puts the stretch of the session that
+ its last compaction dropped back in front of the agent: the prompts typed
+ between the latest two compactions, verbatim; the last captured reply (with
+ the assistant-capture opt-in); and the project's open handoffs, listed
+ without claiming them. The new read-only `GET /recap` route builds it from
+ captured observations. Claude Code and Codex receive it with that prompt
+ through `UserPromptSubmit` `additionalContext`, OpenCode V1/V2 through the
+ plugin's system/context hook, and Grok Build on the next `PostToolUse`.
+ Serving the recap writes nothing, so a reload never consumes a baton (#1230).
+ - Added first-party CodeBuddy Code (Tencent) support. `codebuddy` is an
+ `AgentKind` (migration V81), so hook events are attributed to it and a
+ Claude Code-shaped tool payload (`tool_name`, `tool_input`, `tool_response`)
+ is stored as a closed tool observation instead of an empty `other` capture.
+ `install-hooks --agent codebuddy` (alias `code-buddy`) merges native
+ `ai-memory hook --event … --agent codebuddy` commands for seven events
+ (`SessionStart`, `UserPromptSubmit`, `PreToolUse`, `PostToolUse`,
+ `PreCompact`, `Stop`, `SessionEnd`) into the `hooks` key of
+ `~/.codebuddy/settings.json`, keeps sibling settings and your own hooks,
+ and changes nothing on a re-run. There is no script bundle. The
+ `SessionStart` hook delivers the pending handoff through
+ `hookSpecificOutput.additionalContext`. `setup` wires CodeBuddy when
+ `~/.codebuddy` exists, `setup-agent --agent codebuddy` prints the hook
+ block, and `uninstall` removes the entries. Transcript backfill and
- headless `codebuddy -p` session close are not part of this change. (#1299)
++ headless `codebuddy -p` session close are not part of this change.
++ Requested in #1299. (#1312)
+
+### Changed
+- `ai-memory setup` now ends by naming the agents to restart and the question
+ to ask one of them, "What do you remember about this project?", instead of
+ a generic restart line. `install.sh` names the link's full path in its
+ `next:` line when `~/.local/bin` is not on `PATH`, so the suggested command
+ no longer fails with "command not found". The AUR install and upgrade
+ messages, and the README Fedora, Arch and macOS app steps, point to
+ `ai-memory setup` instead of the manual `init`, `systemctl` and
+ `install-*` commands. (#1270)
+- Changed how the opt-in session-start brief (`[briefing]
+ inject_on_session_start`) spends `max_chars`. Every pinned, `_rules/` and
+ `_slots/` page now gets a short excerpt first, taken from its frontmatter
+ `abstract:` or `summary:`, or else from the prose it opens with (read on
+ into its first list items). The budget left deepens pages to a longer
+ excerpt and then the whole body: pinned and `_slots/` pages first, then
+ pages a few bytes short of whole, then the cheapest bodies. Before, the
+ brief printed whole bodies in order, so one long `_rules/` page was cut with
+ a `[truncated by ...]` note and every page after it became an "omitted"
+ path. Bodies are no longer cut: a body that does not fit whole shows its
+ excerpt. Four or more unpinned excerpts from one folder share a heading,
+ and the omitted list and the closing note point at `memory_read_page`.
+ Small wikis whose pages fit still get every body whole. A project with many
+ standing pages now sees all of them, fewer in full: pin a page, or give it
+ an `abstract:`, to control what it shows. The change adds no marker key
+ and no migration. (#1264)
### Fixed
- Fixed the thin-client commands ignoring a custom `bind`, which could write
diff --cc crates/ai-memory-cli/src/commands/setup.rs
index 9d79240b,3fdd3fc7..48974591
--- a/crates/ai-memory-cli/src/commands/setup.rs
+++ b/crates/ai-memory-cli/src/commands/setup.rs
@@@ -220,18 -160,15 +220,21 @@@ pub async fn run(config: &Config, args
&|harness| doctor::relocated_session_dir_with(harness, &env),
&|client| install_mcp::mcp_config_path_with(client, &env).ok(),
);
- if muse_detected(&home, &env) {
- found.push(AgentChoice::Muse);
+ if let Some(dir) = muse_detected(&home, &env) {
+ found.push((AgentChoice::Muse, Found::ConfigDir(dir)));
}
+ if codebuddy_detected(&home) {
+ found.push(AgentChoice::CodeBuddy);
+ }
found
+ .into_iter()
+ .map(|(agent, found)| (agent, Some(found)))
+ .collect()
} else {
dedup(args.agents.iter().copied())
+ .into_iter()
+ .map(|agent| (agent, None))
+ .collect()
};
let service = if args.no_service {
ServicePlan::Skip("skipped (--no-service)".to_owned())
@@@ -388,14 -270,17 +391,21 @@@ fn muse_detected(home: &Path, env: &dy
})
.join("muse")
};
- xdg("XDG_CONFIG_HOME", &[".config"]).is_dir()
- || xdg("XDG_DATA_HOME", &[".local", "share"]).is_dir()
+ [
+ xdg("XDG_CONFIG_HOME", &[".config"]),
+ xdg("XDG_DATA_HOME", &[".local", "share"]),
+ ]
+ .into_iter()
+ .find(|dir| dir.is_dir())
}
+ /// Whether CodeBuddy Code has been used on this machine: `~/.codebuddy`
+ /// exists. CodeBuddy has no native-session adapter, so setup finds it by
+ /// that directory rather than by [`detect_agents`].
+ fn codebuddy_detected(home: &Path) -> bool {
+ home.join(".codebuddy").is_dir()
+ }
+
/// The binary path the service unit runs. A package manager's versioned
/// location (a Homebrew `Cellar/<formula>/<version>` or a `/nix/store` path)
/// disappears on the next upgrade or `brew cleanup` / garbage collection, so a
@@@ -1029,17 -744,24 +1039,30 @@@ mod tests
std::fs::create_dir_all(xdg.path().join("muse")).unwrap();
let xdg_path = xdg.path().as_os_str().to_owned();
let env = move |name: &str| (name == "XDG_CONFIG_HOME").then(|| xdg_path.clone());
- assert!(muse_detected(home.path(), &env));
+ assert_eq!(
+ muse_detected(home.path(), &env),
+ Some(xdg.path().join("muse"))
+ );
assert_eq!(skills_for(AgentChoice::Muse), InstallSkillsAgent::Agents);
- assert_eq!(AgentPlan::new(AgentChoice::Muse).mcp, Some(McpClient::Muse));
+ assert_eq!(
+ AgentPlan::new(AgentChoice::Muse, None).mcp,
+ Some(McpClient::Muse)
+ );
}
+ #[test]
+ fn codebuddy_is_detected_only_when_its_home_directory_exists() {
+ let home = tempfile::tempdir().unwrap();
+ assert!(!codebuddy_detected(home.path()));
+ std::fs::create_dir_all(home.path().join(".codebuddy")).unwrap();
+ assert!(codebuddy_detected(home.path()));
+ assert_eq!(
+ skills_for(AgentChoice::CodeBuddy),
+ InstallSkillsAgent::Agents
+ );
+ assert_eq!(AgentPlan::new(AgentChoice::CodeBuddy).mcp, None);
+ }
+
/// A versioned Homebrew binary is recorded through the `opt/<formula>`
/// link that survives `brew upgrade` and `brew cleanup`, falling back to
/// the `<prefix>/bin` link; a link to some other binary never wins.