Skip to content

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

Rust

fix(hooks): url-encode bytes >= 0x80 on bash 3.2 (#877)

mchlcs96f26511a161
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 815328ed..f7ee53f8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -159,6 +159,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
event: their `git` lookups set `windowsHide`. The repo-root project lookup
behind those spawns is memoized per cwd instead of running two synchronous
`git` processes on every event. (#863)
+- Shell hooks on macOS no longer corrupt non-ASCII characters in the query
+ string. `/bin/sh` there is bash 3.2, which sign-extends bytes >= 0x80, so
+ `ai_memory_url_encode` sent `é` as `%FFFFFFFFFFFFFFC3%FFFFFFFFFFFFFFA9`
+ instead of `%C3%A9`. An accented cwd reached the server as a different
+ path, and Cursor events and the session-start handoff lookup both use the
+ query `cwd`. (#877)
## [2.4.0] - 2026-09-21
diff --git a/hooks/_lib.sh b/hooks/_lib.sh
index 5b2492d3..a3a8e14a 100644
--- a/hooks/_lib.sh
+++ b/hooks/_lib.sh
@@ -254,7 +254,12 @@ ai_memory_url_encode() {
s="$rest"
case $c in
[A-Za-z0-9._~-]) out="$out$c" ;;
- *) out="$out$(printf '%%%02X' "'$c")" ;;
+ *)
+ # bash 3.2 (macOS /bin/sh) sign-extends bytes >= 0x80, so
+ # `printf '%X' "'$c"` printed FFFFFFFFFFFFFFC3 for 0xC3.
+ b=$(printf '%d' "'$c")
+ [ "$b" -lt 0 ] && b=$((b + 256))
+ out="$out$(printf '%%%02X' "$b")" ;;
esac
done
printf '%s' "$out"
diff --git a/tests/hooks/test_lib.sh b/tests/hooks/test_lib.sh
index 40b4562b..b36fd117 100755
--- a/tests/hooks/test_lib.sh
+++ b/tests/hooks/test_lib.sh
@@ -352,6 +352,10 @@ assert_eq "url_encode escapes plus" "a%2Bb" "$(ai_memory_url_encode "a+b"
assert_eq "url_encode escapes Windows cwd" "C%3A%5Cdev%5Cmyproject" \
"$(ai_memory_url_encode 'C:\dev\myproject')"
assert_eq "url_encode encodes UTF-8 per byte" "r%C3%A9po" "$(ai_memory_url_encode 'répo')"
+# macOS /bin/sh is bash 3.2, which sign-extends bytes >= 0x80 in `printf "'c"`.
+assert_eq "url_encode encodes an accented macOS path" \
+ "%2FUsers%2Fme%2F%C3%81rea%20de%20Trabalho" \
+ "$(ai_memory_url_encode '/Users/me/Área de Trabalho')"
# --- offline spool ----------------------------------------------------
# The spool dir follows the data dir, which the harness pins inside $TMP.