Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(merge): reconcile release/2.5 batch integration
AkitaOnRailse408340fb943
diff --git a/crates/ai-memory-cli/src/commands/render_shared.rs b/crates/ai-memory-cli/src/commands/render_shared.rsindex 11221bb4..05a4d9ef 100644--- a/crates/ai-memory-cli/src/commands/render_shared.rs+++ b/crates/ai-memory-cli/src/commands/render_shared.rs@@ -300,7 +300,7 @@ function captureShellArguments(word: string): string[] { const out = word.starts// variables, command substitution, and `cd` state are not followed. A tool's// own `workdir` replaces the event cwd for relative arguments.function captureMatchCommand(command: string | string[], config: CaptureConfig, workdir?: string): boolean | undefined { const budget = { work: 0 }; const home = homedir(); const base = workdir === undefined ? config.base : /^(?:\/|\\\\|[A-Za-z]:[\\/])/.test(workdir) ? workdir : config.base && captureJoin(config.base, workdir); for (const word of captureShellWordList(command)) for (const argument of captureShellArguments(word)) { const expanded = argument.startsWith("~/") ? captureJoin(home, argument.slice(2)) : argument; if ([...expanded].length > CAPTURE_MAX_PATH_CHARS) continue; const absolute = /^(?:\/|\\\\|[A-Za-z]:[\\/])/.test(expanded); if (!absolute && !base) continue; const candidate = captureNormalize(absolute ? expanded : captureJoin(base, expanded)); if (!candidate) continue; const glob = /[*?]/.test(candidate.path); for (const pattern of config.patterns) { if (candidate.windows !== pattern.windows) continue; const under = captureStartsWith(candidate.path, pattern.prefix, pattern.windows); if (!under && !glob) continue; if (under) { const directory = pattern.directory ? captureGlob(pattern.directory, candidate.path, pattern.windows, budget) : false; if (directory !== false) return directory; const match = captureGlob(pattern.path, candidate.path, pattern.windows, budget); if (match !== false) return match; } if (glob) { const reaches = captureGlobReaches(candidate.path, pattern.prefix, pattern.windows, budget); if (reaches !== false) return reaches; } } } return false; }-function captureTool(payload: Record<string, unknown>): { family: CaptureProtocol["tool_family"]; paths?: string[]; extraction: CaptureProtocol["extraction_state"]; callID?: string; command?: string | string[]; shell?: boolean; workdir?: string } { const name = typeof payload.tool === "string" ? payload.tool.toLowerCase() : ""; const args = payload.args as Record<string, unknown> | undefined; const call = ["tool_use_id","toolUseId","tool_call_id","toolCallId","call_id","callId","callID"].map((k) => payload[k]).find((v): v is string => typeof v === "string" && /^[A-Za-z0-9_.-]{1,128}$/.test(v)); if (["search","grep","glob","find","list","ls","list_files","read_dir","list_dir","grep_search","search_files","find_by_name"].includes(name)) return { family: "search-list", extraction: "not-applicable", callID: call }; if (["bash","shell","shell_command","exec","execute","run_command","web_search","search_web","manage_task","manage_subagents","terminal","execute_bash","execute_cmd"].includes(name)) return { family: "non-file", extraction: "extracted", callID: call, command: captureShellCommand(args), shell: !["web_search","search_web","manage_task","manage_subagents"].includes(name), workdir: typeof args?.workdir === "string" && args.workdir.trim() ? args.workdir : undefined }; if (!["read","write","edit","apply_patch","notebookedit","notebook_edit","create_file","delete_file","rename_file","move_file","multi_edit","multiedit","replace","replace_all"].includes(name)) return { family: "unknown", extraction: "extracted", callID: call }; const direct = (o: any): string[] | undefined => { if (!o || typeof o !== "object") return undefined; const r: string[] = []; for (const k of ["file_path","filePath","path","absolute_path","AbsolutePath","notebook_path","TargetFile"]) if (k in o) { if (typeof o[k] !== "string") return undefined; r.push(o[k]); } if ("paths" in o) { if (!Array.isArray(o.paths) || o.paths.some((x: unknown) => typeof x !== "string")) return undefined; r.push(...o.paths); } return r.length && r.length <= CAPTURE_MAX_CANDIDATES ? r : undefined; }; let paths = direct(args); if (["multi_edit","multiedit","replace_all"].includes(name)) { const entries = args?.edits ?? args?.replacements; if (!Array.isArray(entries) || !entries.length || entries.length > CAPTURE_MAX_CANDIDATES) paths = undefined; else { paths = paths ?? []; for (const entry of entries) { const more = direct(entry); if (!more || paths.length + more.length > CAPTURE_MAX_CANDIDATES) { paths = undefined; break; } paths.push(...more); } } } if (!paths || paths.some((p) => !p.trim() || [...p].length > CAPTURE_MAX_PATH_CHARS)) return { family: "file", extraction: "missing-or-malformed", callID: call }; return { family: "file", paths, extraction: "extracted", callID: call }; }+function captureTool(payload: Record<string, unknown>): { family: CaptureProtocol["tool_family"]; paths?: string[]; extraction: CaptureProtocol["extraction_state"]; callID?: string; command?: string | string[]; shell?: boolean; workdir?: string } { const name = typeof payload.tool === "string" ? payload.tool.toLowerCase() : ""; const args = payload.args as Record<string, unknown> | undefined; const call = ["tool_use_id","toolUseId","tool_call_id","toolCallId","call_id","callId","callID"].map((k) => payload[k]).find((v): v is string => typeof v === "string" && /^[A-Za-z0-9_.-]{1,128}$/.test(v)); if (["search","grep","glob","find","list","ls","list_files","read_dir","list_dir","grep_search","search_files","find_by_name"].includes(name)) return { family: "search-list", extraction: "not-applicable", callID: call }; if (["bash","shell","shell_command","exec","execute","run_command","web_search","search_web","manage_task","manage_subagents","terminal","execute_bash","execute_cmd"].includes(name)) return { family: "non-file", extraction: "extracted", callID: call, command: captureShellCommand(args), shell: name !== "web_search", workdir: typeof args?.workdir === "string" && args.workdir.trim() ? args.workdir : undefined }; if (!["read","write","edit","apply_patch","notebookedit","notebook_edit","create_file","delete_file","rename_file","move_file","multi_edit","multiedit","replace","replace_all"].includes(name)) return { family: "unknown", extraction: "extracted", callID: call }; const direct = (o: any): string[] | undefined => { if (!o || typeof o !== "object") return undefined; const r: string[] = []; for (const k of ["file_path","filePath","path","absolute_path","AbsolutePath","notebook_path","TargetFile"]) if (k in o) { if (typeof o[k] !== "string") return undefined; r.push(o[k]); } if ("paths" in o) { if (!Array.isArray(o.paths) || o.paths.some((x: unknown) => typeof x !== "string")) return undefined; r.push(...o.paths); } return r.length && r.length <= CAPTURE_MAX_CANDIDATES ? r : undefined; }; let paths = direct(args); if (["multi_edit","multiedit","replace_all"].includes(name)) { const entries = args?.edits ?? args?.replacements; if (!Array.isArray(entries) || !entries.length || entries.length > CAPTURE_MAX_CANDIDATES) paths = undefined; else { paths = paths ?? []; for (const entry of entries) { const more = direct(entry); if (!more || paths.length + more.length > CAPTURE_MAX_CANDIDATES) { paths = undefined; break; } paths.push(...more); } } } if (!paths || paths.some((p) => !p.trim() || [...p].length > CAPTURE_MAX_PATH_CHARS)) return { family: "file", extraction: "missing-or-malformed", callID: call }; return { family: "file", paths, extraction: "extracted", callID: call }; }// An external lifecycle owner (`AI_MEMORY_CAPTURE_OWNER`, any value that is// non-empty after trimming) takes over capture for this process: the gate runs// before the capture-policy marker scan, so no disposition work, no marker readdiff --git a/crates/ai-memory-core/src/ids.rs b/crates/ai-memory-core/src/ids.rsindex f6deab53..4c1ae4e8 100644--- a/crates/ai-memory-core/src/ids.rs+++ b/crates/ai-memory-core/src/ids.rs@@ -82,9 +82,12 @@ id_newtype!(pub ProjectId, "Project identifier (middle of the 3-tuple).");id_newtype!(pub SessionId, "Identifier for a single agent run.");impl SessionId {- /// The stored id for a harness's own session id: the id itself when it is- /// a UUID, otherwise a deterministic v5 UUID of it, so hook POSTs and later- /// lookups by native id share one key.+ /// Resolve a harness-native session id to the `SessionId` the store keys+ /// on: a UUID native id is used as-is (canonicalized); any other string+ /// (Codex, OpenCode, ...) is hashed to a deterministic UUID v5, so hook+ /// POSTs and later lookups by native id share one key. The hook router and+ /// any offline tool that matches transcripts by native id (e.g.+ /// `ai-memory repair-backfill-timestamps`) must agree on this one rule.#[must_use]pub fn from_native(raw: &str) -> Self {Self::from_str(raw)@@ -104,20 +107,6 @@ id_newtype!(pub AutoImproveRunId, "Identifier for one auto-improvement review ruid_newtype!(pub AutoImproveProposalId, "Identifier for one staged auto-improvement proposal.");id_newtype!(pub PageFeedbackId, "Identifier for one page-feedback signal (`memory_feedback`).");-impl SessionId {- /// Resolve a harness-native session id to the `SessionId` the store keys- /// on: a UUID native id is used as-is (canonicalized); any other string- /// (Codex, OpenCode, ...) is hashed to a deterministic UUID v5. The hook- /// router and any offline tool that matches transcripts by native id- /// (e.g. `ai-memory repair-backfill-timestamps`) must agree on this one- /// rule to end up with the same key.- #[must_use]- pub fn from_native(raw: &str) -> Self {- raw.parse::<Self>()- .unwrap_or_else(|_| Self(Uuid::new_v5(&Uuid::NAMESPACE_OID, raw.as_bytes())))- }-}-/// Relative path of a page within the wiki tree.////// Always uses `/` as the separator (POSIX-style), normalised on construction.diff --git a/crates/ai-memory-mcp/tests/suite/admin_repair_session_times.rs b/crates/ai-memory-mcp/tests/suite/admin_repair_session_times.rsindex d7e19623..9db96f23 100644--- a/crates/ai-memory-mcp/tests/suite/admin_repair_session_times.rs+++ b/crates/ai-memory-mcp/tests/suite/admin_repair_session_times.rs@@ -43,6 +43,8 @@ async fn make_state(tmp: &TempDir) -> (AdminState, Store) {active_project: ai_memory_core::ActiveProject::new(),scope_invalidator: None,trusted_proxy_identity: false,+ contradiction_band_min: ai_memory_consolidate::DEFAULT_CONTRADICTION_SIM_LOW,+ contradiction_band_max: ai_memory_consolidate::DEFAULT_CONTRADICTION_SIM_HIGH,db_path,};(state, store)diff --git a/crates/ai-memory-web/src/mount.rs b/crates/ai-memory-web/src/mount.rsindex 805ef1fd..8f4a4ab7 100644--- a/crates/ai-memory-web/src/mount.rs+++ b/crates/ai-memory-web/src/mount.rs@@ -1156,6 +1156,7 @@ mod tests {web_slug: "/web",base_href: &base_href,base_path: "",+ trusted_proxy_identity: false,},).unwrap();