Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(wrapper): preserve stdin across every output mode
AkitaOnRails0055407e6563
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 8db204f5..115feb00 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -45,15 +45,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0ambiguous. Unpackaged installs keep resolving to the plain path.(#250)-### Fixed- The Docker wrappers (`bin/ai-memory`, `bin/ai-memory.ps1`) kept stdinattached only on a real terminal, so every piped or redirectedinvocation reached the container with a closed stdin. `ai-memorywrite-page --body -` therefore stored a page with frontmatter and anempty body while still reporting a successful write, and the sameapplied to any other stdin reader (hooks fed by a pipe). The wrappers- now pass `-i` whenever stdin is not a terminal, and keep `-t` for real- terminals only (#243).+ now always pass `-i`, while `-t` is added only when stdin and stdout are+ both terminals. `AI_MEMORY_NO_TTY=1` disables only TTY allocation and+ no longer disconnects stdin. (#243)## [1.18.0] - 2026-07-23diff --git a/bin/ai-memory b/bin/ai-memoryindex fa90ad17..4deecc26 100755--- a/bin/ai-memory+++ b/bin/ai-memory@@ -302,15 +302,12 @@ esacmaybe_warn_outdated || true-# `-t` only makes sense on a real terminal, but `-i` must be passed whenever-# stdin is a pipe/redirect too: subcommands that read stdin (`write-page-# --body -`, `hook`) otherwise see an immediately-closed stdin inside the-# container and silently persist an empty body.-TTY_ARGS=()+# Keep stdin attached in every mode. This covers pipes and redirects, plus the+# easy-to-miss terminal-stdin/redirected-stdout case. `AI_MEMORY_NO_TTY`+# suppresses only the pseudo-terminal allocation.+TTY_ARGS=(-i)if [ -z "${AI_MEMORY_NO_TTY:-}" ] && [ -t 0 ] && [ -t 1 ]; then- TTY_ARGS=(-it)-elif [ ! -t 0 ]; then- TTY_ARGS=(-i)+ TTY_ARGS+=(-t)fi# The CLI runs INSIDE the container but renders hook config for the HOST, whichdiff --git a/bin/ai-memory.ps1 b/bin/ai-memory.ps1index 840f07bc..3dc5f83f 100644--- a/bin/ai-memory.ps1+++ b/bin/ai-memory.ps1@@ -44,14 +44,11 @@ $HomePath = (Resolve-Path -LiteralPath $HOME).Path$WorkPath = (Get-Location).Path$HookHostRoot = ($HomePath -replace '\\', '/') + "/.local/share/ai-memory/hooks"-$DockerArgs = @("run", "--rm")-# `-t` needs a real console, but `-i` must also be passed when stdin is-# redirected: `write-page --body -` (and other stdin readers) would otherwise-# see empty stdin inside the container and silently persist an empty body.+$DockerArgs = @("run", "--rm", "-i")+# Keep stdin attached in every mode. `AI_MEMORY_NO_TTY` suppresses only the+# pseudo-terminal allocation.if (-not $env:AI_MEMORY_NO_TTY -and -not [Console]::IsInputRedirected -and -not [Console]::IsOutputRedirected) {- $DockerArgs += "-it"-} elseif ([Console]::IsInputRedirected) {- $DockerArgs += "-i"+ $DockerArgs += "-t"}$DockerArgs += @(diff --git a/crates/ai-memory-cli/tests/packaging.rs b/crates/ai-memory-cli/tests/packaging.rsindex 19b6d8ca..d0f94359 100644--- a/crates/ai-memory-cli/tests/packaging.rs+++ b/crates/ai-memory-cli/tests/packaging.rs@@ -285,6 +285,37 @@ fn wrapper_keeps_stdin_attached_when_it_is_a_pipe() {);}+#[test]+fn docker_wrappers_keep_stdin_attached_independently_of_tty_allocation() {+ let posix = read_repo("bin/ai-memory");+ assert!(+ posix.contains("TTY_ARGS=(-i)"),+ "POSIX wrapper must attach stdin before inspecting terminal state"+ );+ assert!(+ posix.contains("TTY_ARGS+=(-t)"),+ "POSIX wrapper must add TTY allocation separately"+ );+ assert!(+ !posix.contains("TTY_ARGS=(-it)"),+ "combined flags can drop stdin when only stdout is redirected"+ );++ let powershell = read_repo("bin/ai-memory.ps1");+ assert!(+ powershell.contains("$DockerArgs = @(\"run\", \"--rm\", \"-i\")"),+ "PowerShell wrapper must attach stdin before inspecting console state"+ );+ assert!(+ powershell.contains("$DockerArgs += \"-t\""),+ "PowerShell wrapper must add TTY allocation separately"+ );+ assert!(+ !powershell.contains("$DockerArgs += \"-it\""),+ "PowerShell must not couple stdin attachment to TTY allocation"+ );+}+#[cfg(unix)]#[test]fn managed_run_wrapper_uses_host_binary_path_and_remote_server_without_docker() {