Skip to content

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

Rust

fix(cli): accept any captured agent in finalize-session --agent (#623)

AkitaOnRailsca2e68e6e955
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1568d260..602c1ff4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Fixed
+- `finalize-session --agent hermes` (and `claude-desktop`, `crush`, `other`)
+ is accepted again (#623). These agents are captured and stored, but
+ `finalize-session` reused the install-oriented agent enum — which is
+ deliberately limited to agents with a first-party installer — so it rejected
+ them at parse time and their sessions could never be closed, summarised, or
+ consolidated. `finalize-session` is agent-agnostic, so `--agent` now accepts
+ any agent the store recognises (a genuine typo is still rejected);
+ `install-hooks`/`setup-agent` stay limited. A drift guard keeps the two sets
+ from diverging again.
- generated TypeScript integrations (`--agent open-code`, `omp`, `pi`,
`openclaw`) authenticate again under `install-hooks --apply`. Since #552
the bearer is deliberately omitted from the rendered file and persisted to
diff --git a/crates/ai-memory-cli/src/cli.rs b/crates/ai-memory-cli/src/cli.rs
index 77d16862..e846da28 100644
--- a/crates/ai-memory-cli/src/cli.rs
+++ b/crates/ai-memory-cli/src/cli.rs
@@ -1501,14 +1501,39 @@ impl AgentChoice {
}
}
+/// Parse a `finalize-session --agent` value into an [`ai_memory_core::AgentKind`].
+///
+/// Unlike the install-oriented `AgentChoice` value-enum, this accepts every
+/// agent the store's CHECK constraint permits, because finalize-session is
+/// agent-agnostic and must be able to close a session for any captured harness
+/// (#623). A genuine typo — which `from_wire` would silently map to `Other` —
+/// is rejected so the operator gets a clear error instead of a mis-scoped
+/// finalize.
+fn parse_finalizable_agent(s: &str) -> Result<ai_memory_core::AgentKind, String> {
+ use ai_memory_core::AgentKind;
+ let kind = AgentKind::from_wire(s);
+ if matches!(kind, AgentKind::Other) && !s.eq_ignore_ascii_case("other") {
+ let known = AgentKind::ALL
+ .iter()
+ .map(|k| k.as_str())
+ .collect::<Vec<_>>()
+ .join(", ");
+ return Err(format!("unknown agent '{s}'; expected one of: {known}"));
+ }
+ Ok(kind)
+}
+
/// Arguments for `finalize-session`.
#[derive(Debug, Args)]
pub struct FinalizeSessionArgs {
- /// Agent kind to finalize. Defaults to Codex for backward compatibility;
- /// Codex, Antigravity CLI, Pool, and ZCode have no reliable true
- /// SessionEnd hook.
- #[arg(long, value_enum, default_value_t = AgentChoice::Codex)]
- pub agent: AgentChoice,
+ /// Agent kind to finalize. Accepts any agent the store recognises — unlike
+ /// `install-hooks`/`setup-agent`, which are limited to agents with a
+ /// first-party installer. finalize-session is agent-agnostic (it just posts
+ /// a synthetic session-end and summarises), so refusing a captured harness
+ /// like `hermes` here only stranded its sessions unclosable (#623).
+ /// Defaults to Codex for backward compatibility.
+ #[arg(long, default_value = "codex", value_parser = parse_finalizable_agent)]
+ pub agent: ai_memory_core::AgentKind,
/// Workspace name. Defaults to the nearest `.ai-memory.toml` marker's
/// `workspace`, else `default`.
#[arg(long)]
@@ -2292,6 +2317,39 @@ mod tests {
);
}
+ #[test]
+ fn finalize_session_accepts_hermes_and_every_captured_agent() {
+ // #623: hermes is accepted for capture/storage but the install-oriented
+ // AgentChoice enum lacked it, so finalize-session refused it and hermes
+ // sessions could never be closed. finalize is agent-agnostic; it must
+ // accept every AgentKind the store recognises.
+ let parsed = Cli::try_parse_from(["ai-memory", "finalize-session", "--agent", "hermes"])
+ .expect("hermes must be a valid finalize agent");
+ let Command::FinalizeSession(args) = parsed.command else {
+ panic!("expected finalize-session command");
+ };
+ assert_eq!(args.agent, ai_memory_core::AgentKind::Hermes);
+
+ // Drift guard: every AgentKind must be finalizable, so the CLI accept
+ // set can never again fall behind the store's CHECK set (the exact
+ // drift that caused #623). `other` is included via its explicit spelling.
+ for kind in ai_memory_core::AgentKind::ALL {
+ let parsed =
+ Cli::try_parse_from(["ai-memory", "finalize-session", "--agent", kind.as_str()])
+ .unwrap_or_else(|e| panic!("agent {} must finalize: {e}", kind.as_str()));
+ let Command::FinalizeSession(args) = parsed.command else {
+ panic!("expected finalize-session command");
+ };
+ assert_eq!(args.agent, kind, "wire round-trip for {}", kind.as_str());
+ }
+
+ // A genuine typo is rejected rather than silently mapped to Other.
+ assert!(
+ Cli::try_parse_from(["ai-memory", "finalize-session", "--agent", "hermez"]).is_err(),
+ "an unknown agent must be rejected, not silently accepted as Other"
+ );
+ }
+
#[test]
fn architecture_lists_every_visible_cli_subcommand() {
let architecture = include_str!("../../../docs/ARCHITECTURE.md");
@@ -2833,7 +2891,7 @@ mod tests {
let Command::FinalizeSession(args) = cli.command else {
panic!("expected finalize-session for pool");
};
- assert_eq!(args.agent, AgentChoice::Pool);
+ assert_eq!(args.agent, ai_memory_core::AgentKind::Pool);
}
#[test]
@@ -2861,7 +2919,7 @@ mod tests {
let Command::FinalizeSession(args) = cli.command else {
panic!("expected finalize-session for zcode");
};
- assert_eq!(args.agent, AgentChoice::Zcode);
+ assert_eq!(args.agent, ai_memory_core::AgentKind::Zcode);
}
#[test]
diff --git a/crates/ai-memory-cli/src/commands/finalize_session.rs b/crates/ai-memory-cli/src/commands/finalize_session.rs
index e02361ba..4b41ac4e 100644
--- a/crates/ai-memory-cli/src/commands/finalize_session.rs
+++ b/crates/ai-memory-cli/src/commands/finalize_session.rs
@@ -52,7 +52,7 @@ struct FinalizeSessionReport {
/// Returns an error if the configured server cannot list the scope's open
/// sessions or rejects a synthetic `session-end` hook.
pub async fn run(config: &Config, args: FinalizeSessionArgs) -> Result<()> {
- let agent = args.agent.kind();
+ let agent = args.agent;
let (workspace, project) =
super::resolve_scope(config, args.workspace.as_deref(), args.project.as_deref())?;
let endpoint = ServerEndpoint::from_config_resolving_auth(config).await;