Skip to content

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

Rust

feat(agents): recognise GrizzyBot as a first-class agent

Edward Griswold7f952171c596
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a7c02988..ee104e59 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+### Added
+- Added `grizzybot` as a recognised agent (wire value `grizzybot`, alias
+ `grizzy-bot`), so GrizzyBot's lifecycle events are attributed to it instead
+ of `other` and its tool calls are captured as closed-schema tool families,
+ like other Claude Code-shaped agents. Adds migration V72 to extend the
+ `sessions.agent_kind` CHECK constraint.
+
### Changed
- Documented FutureInfra as an endpoint for the existing `openai-compat`
provider. (#1026)
diff --git a/crates/ai-memory-core/src/ids.rs b/crates/ai-memory-core/src/ids.rs
index 43719951..ff7031bc 100644
--- a/crates/ai-memory-core/src/ids.rs
+++ b/crates/ai-memory-core/src/ids.rs
@@ -280,6 +280,8 @@ pub enum AgentKind {
Pool,
/// ZCode (z.ai) coding agent.
Zcode,
+ /// GrizzyBot, a native macOS agent app that posts its own lifecycle events.
+ Grizzybot,
/// Anything else (manual capture, future agents).
Other,
}
@@ -290,7 +292,7 @@ impl AgentKind {
/// CHECK constraint accepts every kind (the Zero integration shipped
/// with the enum variant but without the V26 migration and only a
/// live test caught it). Extend together with the enum.
- pub const ALL: [Self; 21] = [
+ pub const ALL: [Self; 22] = [
Self::ClaudeCode,
Self::Codex,
Self::OpenCode,
@@ -311,6 +313,7 @@ impl AgentKind {
Self::Hermes,
Self::Pool,
Self::Zcode,
+ Self::Grizzybot,
Self::Other,
];
@@ -338,6 +341,7 @@ impl AgentKind {
Self::Hermes => "hermes",
Self::Pool => "pool",
Self::Zcode => "zcode",
+ Self::Grizzybot => "grizzybot",
Self::Other => "other",
}
}
@@ -368,6 +372,7 @@ impl AgentKind {
"hermes" | "hermes-agent" => Self::Hermes,
"pool" | "poolside" => Self::Pool,
"zcode" | "zai" => Self::Zcode,
+ "grizzybot" | "grizzy-bot" => Self::Grizzybot,
_ => Self::Other,
}
}
@@ -619,6 +624,22 @@ mod tests {
assert!(!AgentKind::Pool.user_prompt_injects_handoff());
}
+ #[test]
+ fn agent_kind_grizzybot_round_trips() {
+ assert_eq!(AgentKind::Grizzybot.as_str(), "grizzybot");
+ assert_eq!(AgentKind::from_wire("grizzybot"), AgentKind::Grizzybot);
+ assert_eq!(AgentKind::from_wire("grizzy-bot"), AgentKind::Grizzybot);
+ assert_eq!(
+ serde_json::to_string(&AgentKind::Grizzybot).unwrap(),
+ "\"grizzybot\""
+ );
+ assert_eq!(
+ serde_json::from_str::<AgentKind>("\"grizzybot\"").unwrap(),
+ AgentKind::Grizzybot
+ );
+ assert_eq!(AgentKind::from_wire("grizzybot-2"), AgentKind::Other);
+ }
+
#[test]
fn agent_kind_zcode_round_trips_and_injects_session_start_handoff() {
assert_eq!(AgentKind::Zcode.as_str(), "zcode");
diff --git a/crates/ai-memory-hooks/src/capture_policy.rs b/crates/ai-memory-hooks/src/capture_policy.rs
index 851585f2..4d95dce7 100644
--- a/crates/ai-memory-hooks/src/capture_policy.rs
+++ b/crates/ai-memory-hooks/src/capture_policy.rs
@@ -175,6 +175,7 @@ pub(crate) fn tool_observation_metadata(
| AgentKind::CommandCode
| AgentKind::Codex
| AgentKind::Grok
+ | AgentKind::Grizzybot
| AgentKind::Zcode => (
object.get("tool_name")?.as_str()?,
object.get("tool_use_id").and_then(Value::as_str),
@@ -225,6 +226,7 @@ pub(crate) fn tool_observation_metadata(
| AgentKind::KiroCli
| AgentKind::Pool
| AgentKind::Zcode
+ | AgentKind::Grizzybot
) {
"tool_input"
} else {
@@ -719,7 +721,9 @@ fn extract(agent: AgentKind, raw: &Value) -> Extracted<'_> {
| AgentKind::KiroCli
| AgentKind::Pool
// ZCode mirrors Claude Code's snake_case `tool_name`/`tool_input`
- // aliases on every tool event (live-captured, #512).
+ // aliases on every tool event (live-captured, #512). GrizzyBot posts
+ // the same Claude Code-shaped payload from its agent loop.
+ | AgentKind::Grizzybot
| AgentKind::Zcode => object
.get("tool_name")
.and_then(Value::as_str)
@@ -1735,6 +1739,23 @@ mod tests {
assert_eq!(unknown.protocol().tool_family(), ToolFamily::Unknown);
}
+ #[test]
+ fn grizzybot_tool_shape_is_closed_and_unknown_agents_stay_unsupported() {
+ let raw = json!({
+ "hook_event_name": "PostToolUse",
+ "tool_name": "web_search",
+ "tool_input": {"query": "swift"},
+ "session_id": "gb-session",
+ "cwd": "/bot/home"
+ });
+ let metadata = tool_observation_metadata(AgentKind::Grizzybot, &raw, true).unwrap();
+ assert_eq!(metadata.tool_family, ToolFamily::NonFile);
+ // A PreToolUse without an input is not a proven shape.
+ let no_input = json!({"tool_name": "read_file"});
+ assert!(tool_observation_metadata(AgentKind::Grizzybot, &no_input, true).is_none());
+ assert!(tool_observation_metadata(AgentKind::Grizzybot, &no_input, false).is_some());
+ }
+
#[test]
fn zcode_post_tool_use_failure_error_maps_to_error_outcome() {
// Live-captured PostToolUseFailure payload (run 10, real model, #512):
diff --git a/crates/ai-memory-hooks/src/payload.rs b/crates/ai-memory-hooks/src/payload.rs
index 02d6a9c6..7a7e73e0 100644
--- a/crates/ai-memory-hooks/src/payload.rs
+++ b/crates/ai-memory-hooks/src/payload.rs
@@ -725,6 +725,7 @@ const fn closed_tool_agent(agent: AgentKind) -> bool {
| AgentKind::Hermes
| AgentKind::Pool
| AgentKind::Zcode
+ | AgentKind::Grizzybot
)
}
@@ -2092,6 +2093,30 @@ mod tests {
assert_eq!(env.title_hint.as_deref(), Some("tool non-file"));
}
+ #[test]
+ fn grizzybot_tool_title_is_a_closed_family() {
+ let raw = serde_json::json!({
+ "hook_event_name": "PostToolUse",
+ "tool_name": "write_file",
+ "tool_input": {"path": "notes.md", "content": "untrusted"},
+ "tool_response": "ok",
+ "session_id": "gb-session",
+ "cwd": "/bot/home"
+ });
+ let env = HookEnvelope::from_query_and_body(
+ HookQuery {
+ event: "post-tool-use".into(),
+ agent: Some("grizzybot".into()),
+ ..Default::default()
+ },
+ raw,
+ );
+ assert_eq!(env.agent, AgentKind::Grizzybot);
+ assert_eq!(env.title_hint.as_deref(), Some("tool file"));
+ assert_eq!(env.session_id.as_deref(), Some("gb-session"));
+ assert_eq!(env.cwd.as_deref(), Some("/bot/home"));
+ }
+
/// Body is well-formed JSON but the expected `session_id` /
/// `cwd` keys are missing — extraction returns None per key.
#[test]
diff --git a/crates/ai-memory-store/migrations/V72__sessions_grizzybot_agent_kind.sql b/crates/ai-memory-store/migrations/V72__sessions_grizzybot_agent_kind.sql
new file mode 100644
index 00000000..39a34250
--- /dev/null
+++ b/crates/ai-memory-store/migrations/V72__sessions_grizzybot_agent_kind.sql
@@ -0,0 +1,73 @@
+-- Expand sessions.agent_kind CHECK for GrizzyBot (native macOS agent app).
+--
+-- Keep the complete V51 schema, indexes, and scope-pairing triggers while
+-- adding the `grizzybot` wire value.
+
+PRAGMA foreign_keys = OFF;
+
+DROP TRIGGER IF EXISTS auto_improve_scheduler_claims_session_pairing_ai;
+DROP TRIGGER IF EXISTS session_consolidation_jobs_session_pairing_ai;
+
+CREATE TABLE sessions_new (
+ id BLOB PRIMARY KEY NOT NULL,
+ workspace_id BLOB NOT NULL REFERENCES workspaces(id) ON DELETE CASCADE,
+ project_id BLOB NOT NULL REFERENCES projects(id) ON DELETE CASCADE,
+ agent_kind TEXT NOT NULL CHECK (agent_kind IN ('claude-code','codex','open-code','cursor','gemini-cli','claude-desktop','openclaw','antigravity-cli','omp','pi','crush','grok','zero','devin','kimi-code','kiro-cli','command-code','hermes','pool','zcode','grizzybot','other')),
+ cwd TEXT,
+ started_at INTEGER NOT NULL,
+ ended_at INTEGER,
+ summary_page_id BLOB REFERENCES pages(id) ON DELETE SET NULL,
+ ended_observation_count INTEGER NOT NULL DEFAULT 0 CHECK (ended_observation_count >= 0),
+ actor_user TEXT
+);
+
+INSERT INTO sessions_new (
+ id, workspace_id, project_id, agent_kind, cwd, started_at, ended_at,
+ summary_page_id, ended_observation_count, actor_user
+)
+SELECT
+ id, workspace_id, project_id, agent_kind, cwd, started_at, ended_at,
+ summary_page_id, ended_observation_count, actor_user
+FROM sessions;
+
+DROP TABLE sessions;
+
+ALTER TABLE sessions_new RENAME TO sessions;
+
+CREATE INDEX idx_sessions_recent ON sessions(workspace_id, project_id, started_at DESC);
+CREATE INDEX idx_sessions_project ON sessions(project_id);
+CREATE INDEX idx_sessions_started_at ON sessions(started_at DESC);
+CREATE INDEX idx_sessions_scope_ended
+ ON sessions(workspace_id, project_id, ended_at ASC)
+ WHERE ended_at IS NOT NULL;
+CREATE INDEX idx_sessions_open_owner
+ ON sessions(workspace_id, project_id, agent_kind, actor_user)
+ WHERE ended_at IS NULL;
+
+CREATE TRIGGER sessions_ws_proj_pairing_ai
+BEFORE INSERT ON sessions
+FOR EACH ROW
+WHEN NEW.workspace_id IS NOT (SELECT workspace_id FROM projects WHERE id = NEW.project_id)
+BEGIN
+ SELECT RAISE(ABORT, 'sessions.workspace_id does not match the project''s workspace');
+END;
+
+CREATE TRIGGER auto_improve_scheduler_claims_session_pairing_ai
+BEFORE INSERT ON auto_improve_scheduler_claims
+FOR EACH ROW
+WHEN NEW.workspace_id IS NOT (SELECT workspace_id FROM sessions WHERE id = NEW.session_id)
+ OR NEW.project_id IS NOT (SELECT project_id FROM sessions WHERE id = NEW.session_id)
+BEGIN
+ SELECT RAISE(ABORT, 'auto_improve_scheduler_claims scope does not match the session scope');
+END;
+
+CREATE TRIGGER session_consolidation_jobs_session_pairing_ai
+BEFORE INSERT ON session_consolidation_jobs
+FOR EACH ROW
+WHEN NEW.workspace_id IS NOT (SELECT workspace_id FROM sessions WHERE id = NEW.session_id)
+ OR NEW.project_id IS NOT (SELECT project_id FROM sessions WHERE id = NEW.session_id)
+BEGIN
+ SELECT RAISE(ABORT, 'session_consolidation_jobs scope does not match the session scope');
+END;
+
+PRAGMA foreign_keys = ON;
diff --git a/crates/ai-memory-store/src/api_credentials.rs b/crates/ai-memory-store/src/api_credentials.rs
index ac3e16af..dfc953c3 100644
--- a/crates/ai-memory-store/src/api_credentials.rs
+++ b/crates/ai-memory-store/src/api_credentials.rs
@@ -411,7 +411,7 @@ mod tests {
|row| row.get(0),
)
.unwrap();
- assert_eq!(version, 71, "update the pin when adding a migration");
+ assert_eq!(version, 72, "update the pin when adding a migration");
let cols: i64 = conn
.query_row(
"SELECT COUNT(*) FROM pragma_table_info('users') WHERE name = 'token_hash'",
diff --git a/crates/ai-memory-store/src/migrations.rs b/crates/ai-memory-store/src/migrations.rs
index d6c3b2cb..e8bc53af 100644
--- a/crates/ai-memory-store/src/migrations.rs
+++ b/crates/ai-memory-store/src/migrations.rs
@@ -897,6 +897,74 @@ mod tests {
}
}
+ #[test]
+ fn v71_to_v72_preserves_session_state_and_accepts_grizzybot() {
+ let mut conn = Connection::open_in_memory().unwrap();
+ run_to(&mut conn, 71).unwrap();
+ conn.pragma_update(None, "foreign_keys", "ON").unwrap();
+ let workspace_id = crate::ops::get_or_create_workspace(&mut conn, "default").unwrap();
+ let project_id =
+ crate::ops::get_or_create_project(&mut conn, &workspace_id, "project", None).unwrap();
+ let existing = SessionId::new();
+ conn.execute(
+ "INSERT INTO sessions \
+ (id, workspace_id, project_id, agent_kind, cwd, started_at, ended_at, \
+ ended_observation_count, actor_user) \
+ VALUES (?1, ?2, ?3, 'zcode', '/repo', 1, 2, 7, 'user:alice')",
+ params![
+ existing.as_bytes(),
+ workspace_id.as_bytes(),
+ project_id.as_bytes(),
+ ],
+ )
+ .unwrap();
+
+ conn.pragma_update(None, "foreign_keys", "OFF").unwrap();
+ run(&mut conn).unwrap();
+ conn.pragma_update(None, "foreign_keys", "ON").unwrap();
+
+ let preserved: (String, String, i64, Option<String>) = conn
+ .query_row(
+ "SELECT agent_kind, cwd, ended_observation_count, actor_user \
+ FROM sessions WHERE id = ?1",
+ params![existing.as_bytes()],
+ |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?, row.get(3)?)),
+ )
+ .unwrap();
+ assert_eq!(
+ preserved,
+ ("zcode".into(), "/repo".into(), 7, Some("user:alice".into()))
+ );
+
+ crate::ops::begin_session(
+ &mut conn,
+ &NewSession {
+ occurred_at: None,
+ id: SessionId::new(),
+ workspace_id,
+ project_id,
+ agent_kind: AgentKind::Grizzybot,
+ cwd: Some("/repo".into()),
+ actor_user: Some("user:alice".into()),
+ },
+ )
+ .unwrap();
+
+ for name in [
+ "idx_sessions_open_owner",
+ "sessions_ws_proj_pairing_ai",
+ "auto_improve_scheduler_claims_session_pairing_ai",
+ "session_consolidation_jobs_session_pairing_ai",
+ ] {
+ let kind = if name.starts_with("idx_") {
+ "index"
+ } else {
+ "trigger"
+ };
+ assert_eq!(schema_object_count(&conn, kind, name), 1, "missing {name}");
+ }
+ }
+
/// V62 was reshaped in place (#776) from an in-migration backfill to
/// DDL-only + a boot-path backfill, changing its checksum. A store that
/// applied the ORIGINAL V62 recorded the old checksum; `run` must still