Skip to content

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

Rust

test(hooks): align RFC 3986 shell expectations

AkitaOnRailsa0d82d3e1ce6
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7a763c42..6b178f30 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -84,13 +84,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
(everything outside `A-Za-z0-9-_.~`) in both the native helper and the
POSIX `hooks/_lib.sh`, and the shell cwd extractor unescapes JSON `\\` /
`\/`. Previously a Windows cwd like `C:\dev\myproject` went into the query
- string with raw backslashes — confirmed to break the shell-script hook
- fallback outside Git Bash, and the suspected cause of the native
- session-start hook returning `{}` on Windows while the pending handoff
- stayed unconsumed. The session-start hook also now prints a stderr
- warning when the handoff fetch fails (server unreachable, bad URL)
+ string with raw backslashes, which broke the shell-script fallback outside
+ Git Bash. The reporter confirmed that native Windows handoff delivery was
+ already correct for well-formed JSON; their original failure came from a
+ PowerShell pipe adding a UTF-8 BOM. The session-start hook now also prints a
+ stderr warning when the handoff fetch fails (server unreachable, bad URL)
instead of being indistinguishable from "no pending handoff" — exit code
- stays 0, hooks never break the agent ([#188]).
+ stays 0, hooks never break the agent. Malformed-payload/BOM diagnostics are
+ tracked separately in [#197] ([#188]).
- `install-mcp --server-url` now appends the `/mcp` path when given a base
URL (the same value `install-hooks --server-url` takes), instead of
rendering a client config that points at the server root and 404s. The
diff --git a/tests/hooks/test_lib.sh b/tests/hooks/test_lib.sh
index d98d0aaf..789ed09d 100755
--- a/tests/hooks/test_lib.sh
+++ b/tests/hooks/test_lib.sh
@@ -62,6 +62,9 @@ PAYLOAD_NESTED='{"session_id":"x","cwd":"/home/u/root","tool_input":{"cwd":"/tmp
assert_eq "extract cwd prefers first match" "/home/u/root" "$(ai_memory_extract_cwd "$PAYLOAD_NESTED")"
PAYLOAD_AGY='{"conversationId":"x","workspacePaths":["/home/u/agy","/tmp/other"]}'
assert_eq "extract cwd from antigravity workspacePaths" "/home/u/agy" "$(ai_memory_extract_cwd "$PAYLOAD_AGY")"
+PAYLOAD_WINDOWS='{"session_id":"x","cwd":"C:\\dev\\myproject"}'
+assert_eq "extract cwd unescapes Windows JSON path" 'C:\dev\myproject' \
+ "$(ai_memory_extract_cwd "$PAYLOAD_WINDOWS")"
# --- json_string -------------------------------------------------------
JSON_INPUT='quoted "thing" \ path
@@ -71,14 +74,14 @@ assert_eq "json_string escapes text" '"quoted \"thing\" \\ path\nnext line"' \
# --- marker_qs --------------------------------------------------------
QS=$(ai_memory_marker_qs "$TMP/a/b/c")
-assert_eq "marker_qs single key" "&cwd=$TMP/a/b/c&workspace=deep" "$QS"
+assert_eq "marker_qs single key" "&cwd=$(ai_memory_url_encode "$TMP/a/b/c")&workspace=deep" "$QS"
printf 'workspace = "ws1"\nproject = "p1"\nproject_strategy = "repo-root"\n' >"$TMP/a/b/.ai-memory.toml"
QS2=$(ai_memory_marker_qs "$TMP/a/b/c")
-assert_eq "closer marker wins" "&cwd=$TMP/a/b/c&workspace=ws1&project=p1&project_strategy=repo-root" "$QS2"
+assert_eq "closer marker wins" "&cwd=$(ai_memory_url_encode "$TMP/a/b/c")&workspace=ws1&project=p1&project_strategy=repo-root" "$QS2"
QS3=$(ai_memory_marker_qs "$TMP/nonexistent")
-assert_eq "no marker -> cwd only" "&cwd=$TMP/nonexistent" "$QS3"
+assert_eq "no marker -> cwd only" "&cwd=$(ai_memory_url_encode "$TMP/nonexistent")" "$QS3"
# --- repo-root strategy: host-side resolution -------------------------
# Outside any git repo the helper stays silent (caller keeps basename(cwd)).
@@ -99,7 +102,7 @@ if command -v git >/dev/null 2>&1; then
printf 'workspace = "oss"\nproject_strategy = "repo-root"\n' >"$REPO/.ai-memory.toml"
QSR=$(ai_memory_marker_qs "$REPO/crates/cli")
assert_eq "repo-root: subdir resolves to repo basename" \
- "&cwd=$REPO/crates/cli&workspace=oss&project=acme-api&project_strategy=repo-root" \
+ "&cwd=$(ai_memory_url_encode "$REPO/crates/cli")&workspace=oss&project=acme-api&project_strategy=repo-root" \
"$QSR"
rm -f "$REPO/.ai-memory.toml"
@@ -107,14 +110,14 @@ if command -v git >/dev/null 2>&1; then
export AI_MEMORY_PROJECT_STRATEGY
QSE=$(ai_memory_marker_qs "$REPO/crates/cli")
assert_eq "repo-root env: no marker resolves to repo basename" \
- "&cwd=$REPO/crates/cli&project=acme-api&project_strategy=repo-root" \
+ "&cwd=$(ai_memory_url_encode "$REPO/crates/cli")&project=acme-api&project_strategy=repo-root" \
"$QSE"
printf 'workspace = "oss"\nproject = "pinned"\nproject_strategy = "basename"\n' \
>"$REPO/.ai-memory.toml"
QSO=$(ai_memory_marker_qs "$REPO/crates/cli")
assert_eq "marker project strategy overrides env default" \
- "&cwd=$REPO/crates/cli&workspace=oss&project=pinned&project_strategy=basename" \
+ "&cwd=$(ai_memory_url_encode "$REPO/crates/cli")&workspace=oss&project=pinned&project_strategy=basename" \
"$QSO"
unset AI_MEMORY_PROJECT_STRATEGY
@@ -131,7 +134,7 @@ if command -v git >/dev/null 2>&1; then
if git -C "$REPO" worktree add -q "$WT" >/dev/null 2>&1; then
QSW=$(ai_memory_marker_qs "$WT")
assert_eq "repo-root: out-of-tree worktree collapses to main repo" \
- "&cwd=$WT&workspace=oss&project=acme-api&project_strategy=repo-root" \
+ "&cwd=$(ai_memory_url_encode "$WT")&workspace=oss&project=acme-api&project_strategy=repo-root" \
"$QSW"
fi
@@ -140,7 +143,7 @@ if command -v git >/dev/null 2>&1; then
>"$REPO/.ai-memory.toml"
QSP=$(ai_memory_marker_qs "$REPO/crates/cli")
assert_eq "explicit project pin beats repo-root" \
- "&cwd=$REPO/crates/cli&workspace=oss&project=pinned&project_strategy=repo-root" \
+ "&cwd=$(ai_memory_url_encode "$REPO/crates/cli")&workspace=oss&project=pinned&project_strategy=repo-root" \
"$QSP"
PSH=""
@@ -167,6 +170,9 @@ assert_eq "url_encode passes safe slug" "movvia" "$(ai_memory_url_encode "movv
assert_eq "url_encode escapes ampersand" "a%26b" "$(ai_memory_url_encode "a&b")"
assert_eq "url_encode escapes equals" "a%3Db" "$(ai_memory_url_encode "a=b")"
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')"
# --- summary ----------------------------------------------------------
printf '\n%d passed, %d failed\n' "$PASS" "$FAIL"