Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(hooks): keep Windows hook transport textual
AkitaOnRailsc181749aca77
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex ef15cc57..86471a4a 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -36,6 +36,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0Code's `--yolo`, and kimi joins the automatic bare-run harness pool.### Fixed+- Windows PowerShell fallback hooks now force text input/output and silence+ non-interactive progress records. This prevents nested PowerShell runners+ such as Antigravity CLI from reporting serialized `CLIXML` progress on every+ hook while preserving the hook's JSON stdout. Existing script-fallback+ installs should rerun `install-hooks --agent <agent> --apply` after upgrading+ ([#224]).- Kimi Code handoffs are now delivered through the `UserPromptSubmit` hookinstead of `SessionStart`. Kimi Code fires `SessionStart` but discards thehook's stdout/result (verified against kimi-code v0.28.1,diff --git a/crates/ai-memory-cli/src/commands/render_shared.rs b/crates/ai-memory-cli/src/commands/render_shared.rsindex b5c8aa09..6ae648e7 100644--- a/crates/ai-memory-cli/src/commands/render_shared.rs+++ b/crates/ai-memory-cli/src/commands/render_shared.rs@@ -1024,7 +1024,13 @@ fn hook_command(format!("{prefix}{}", shell_quote(&script.to_string_lossy()))}HookCommandPlatform::Windows => {- let mut setup = format!("$env:AI_MEMORY_HOOK_URL={}", powershell_quote(server_url));+ // Hook runners launch this child with redirected streams. Force+ // text transport and suppress non-interactive progress so Windows+ // PowerShell does not serialize progress records as CLIXML.+ let mut setup = format!(+ "$ProgressPreference='SilentlyContinue'; $env:AI_MEMORY_HOOK_URL={}",+ powershell_quote(server_url)+ );if let Some(t) = auth_token {setup.push_str(&format!("; $env:AI_MEMORY_AUTH_TOKEN={}",@@ -1040,7 +1046,7 @@ fn hook_command(let program = format!("{setup}; & {}", powershell_quote(&script.to_string_lossy()));let encoded = powershell_encoded_command(&program);format!(- "powershell.exe -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -EncodedCommand {encoded}"+ "powershell.exe -NoLogo -NoProfile -NonInteractive -InputFormat Text -OutputFormat Text -ExecutionPolicy Bypass -EncodedCommand {encoded}")}HookCommandPlatform::WindowsBash => {@@ -2144,7 +2150,7 @@ check(activeKeep.disposition === "keep" && activeKeep.protocol?.version === 1 &&.and_then(|s| s.as_str()).unwrap();assert!(cmd.starts_with(- "powershell.exe -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -EncodedCommand "+ "powershell.exe -NoLogo -NoProfile -NonInteractive -InputFormat Text -OutputFormat Text -ExecutionPolicy Bypass -EncodedCommand "));assert!(!cmd.contains("$env:"),@@ -2155,6 +2161,7 @@ check(activeKeep.disposition === "keep" && activeKeep.protocol?.version === 1 &&"outer command must not expose values to its caller: {cmd}");let program = decode_powershell_encoded_command(cmd);+ assert!(program.starts_with("$ProgressPreference='SilentlyContinue';"));assert!(program.contains("$env:AI_MEMORY_HOOK_URL='http://localhost:49374'"));assert!(program.contains("$env:AI_MEMORY_AUTH_TOKEN='tok''en'"));assert!(@@ -2189,6 +2196,10 @@ check(activeKeep.disposition === "keep" && activeKeep.protocol?.version === 1 &&command.contains(" -EncodedCommand "),"{pointer}: {command}");+ assert!(+ command.contains(" -InputFormat Text -OutputFormat Text "),+ "{pointer}: nested PowerShell transport must stay textual: {command}"+ );assert!(!command.contains("$env:")&& !command.contains("localhost:49374")@@ -2197,6 +2208,10 @@ check(activeKeep.disposition === "keep" && activeKeep.protocol?.version === 1 &&);let program = decode_powershell_encoded_command(command);+ assert!(+ program.starts_with("$ProgressPreference='SilentlyContinue';"),+ "{pointer}: {program}"+ );assert!(program.contains("$env:AI_MEMORY_HOOK_URL='http://localhost:49374'"),"{pointer}: {program}"@@ -2222,6 +2237,7 @@ check(activeKeep.disposition === "keep" && activeKeep.protocol?.version === 1 &&&script,r#"if ($env:AI_MEMORY_HOOK_URL -ne "http://localhost:49374") { exit 9 }if ($env:AI_MEMORY_AUTH_TOKEN -ne "tok'en") { exit 10 }+Write-Progress -Activity "hook progress" -Status "must stay silent"$payload = [Console]::In.ReadToEnd()[Console]::Out.Write($payload)"#,@@ -2259,6 +2275,11 @@ $payload = [Console]::In.ReadToEnd()"nested PowerShell failed: {}",String::from_utf8_lossy(&output.stderr));+ assert!(+ output.stderr.is_empty(),+ "non-interactive hook wrote stderr: {}",+ String::from_utf8_lossy(&output.stderr)+ );assert_eq!(output.stdout, br#"{"hook":"ok"}"#);}diff --git a/docs/mcp-install.md b/docs/mcp-install.mdindex 2434cebb..d8e118b4 100644--- a/docs/mcp-install.md+++ b/docs/mcp-install.md@@ -414,7 +414,9 @@ The rendered hooks config looks like:- Hook scripts are staged under `~/.local/share/ai-memory/hooks/antigravity-cli/`.- Native Windows Docker-wrapper installs render hook entries as`powershell.exe ... -EncodedCommand <payload>` so Antigravity's outer command- runner cannot expand the inner `$env:` setup. Rerun+ runner cannot expand the inner `$env:` setup. The child also forces text+ input/output and disables progress so PowerShell does not serialize progress+ records as `CLIXML` hook stderr. Rerun`install-hooks --agent antigravity-cli --apply` after upgrading to refreshexisting entries.- The `PreInvocation` event fires before each model call (not just at@@ -424,6 +426,9 @@ The rendered hooks config looks like:- Antigravity CLI does not expose a true session-end hook. `Stop` recordsa stop observation only; call `memory_handoff_begin` before quitting whenyou need the next agent to receive a handoff.+- The built-in `/web` route displays compiled wiki pages, not raw session or+ observation rows. To verify hook capture, compare the `sessions` and+ `observations` counts from `ai-memory status` before and after a prompt.- Source: <https://antigravity.google/docs/hooks>---diff --git a/docs/windows.md b/docs/windows.mdindex 02ba9d1d..a3466dae 100644--- a/docs/windows.md+++ b/docs/windows.md@@ -111,8 +111,10 @@ the CLI to render hook commands for the native Windows agent:use native single command strings matching their hook schema. The wrapperrenders those `.ps1` fallback commands with PowerShell `-EncodedCommand` so ahook runner cannot expand their `$env:` setup before the inner PowerShell- process receives it. PowerShell/Git Bash script bundles are compatibility- fallbacks and do not enforce capture-policy v1.+ process receives it. Those commands force text input/output and suppress+ progress records so nested PowerShell runners do not emit `CLIXML` hook+ stderr. PowerShell/Git Bash script bundles are compatibility fallbacks and do+ not enforce capture-policy v1.After upgrading the wrapper/image, rerun `install-hooks --agent <agent> --apply`for each native Windows agent so existing hook entries receive the current@@ -345,7 +347,8 @@ For WSL2:2. Confirm generated hook commands reference `.sh` files under WSL paths.3. Launch the agent from WSL2.4. Call `memory_status` from the agent.-5. Send a prompt, then run `ai-memory status` or `ai-memory recent`.+5. Record `ai-memory status`, send a prompt, then confirm its `sessions` or+ `observations` count increased.For native Windows:@@ -358,7 +361,10 @@ For native Windows:generated `.ps1` hooks under your Windows home directory.3. Launch the native Windows agent.4. Call `memory_status` from the agent.-5. Send a prompt, then run `ai-memory status` or `ai-memory recent`.+5. Record `ai-memory status`, send a prompt, then confirm its `sessions` or+ `observations` count increased.Report which mode you tested, which agent and version you used, andwhether the hook command executed or failed with a path/shell error.+The built-in `/web` browser lists compiled wiki pages; zero pages there does+not mean the raw hook observations were missed.