From 28c5a4209bab4629f59445a5d228f0919f2a029e Mon Sep 17 00:00:00 2001 From: bchanot Date: Wed, 28 Oct 2026 17:53:48 +0100 Subject: [PATCH] fix(memory): resolve the lib dir before -C so upgrade finds the templates from a relative path --- lib/memory.sh | 4 +++- lib/tests/memory.test.sh | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/memory.sh b/lib/memory.sh index 3fe4058..8940506 100755 --- a/lib/memory.sh +++ b/lib/memory.sh @@ -37,6 +37,8 @@ # of any level, fenced or not. Free text reaches awk through ENVIRON, # never `-v` (which expands backslash escapes). +# absolute before any `-C` cd: a relative $0 no longer resolves after it +_MEM_LIB_DIR="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)" MEM_GREP="${MEM_GREP:-/usr/bin/grep}" _MEM_TABLE='decision decisions BDR learning learnings LRN @@ -677,7 +679,7 @@ _mem_upgrade_front() { # → the file; one lacking a frontmatter gets local t first # the template's (format: 2 is added with the rest) IFS= read -r first < "$1" if [ "$first" != --- ]; then - t="$(dirname "${BASH_SOURCE[0]}")/../templates/memory/${1##*/}" + t="$_MEM_LIB_DIR/../templates/memory/${1##*/}" [ -f "$t" ] || { echo "memory: no template for $1" >&2; return 2; } awk 'NR > 1 && /^---$/ { print; print ""; exit } $0 != "format: 2"' "$t" diff --git a/lib/tests/memory.test.sh b/lib/tests/memory.test.sh index 84727f4..81bd378 100755 --- a/lib/tests/memory.test.sh +++ b/lib/tests/memory.test.sh @@ -477,6 +477,13 @@ dialect nofm '^## BLK-001 — no frontmatter (2026-05-18)$' check T15-nofm-template "$(sed -n 1,3p d15/nofm/blockers.md | tr '\n' '#')" \ '---#format: 2#type: blockers_registry#' check T15-nofm-body "$(grep -c '^# Blockers$' d15/nofm/blockers.md)" 1 +# a relative lib path plus -C from another cwd still finds the templates +mkdir -p d15/relpath/.claude/memory +printf '# Blockers\n\n## BLK-001 | 2026-05-18 | no frontmatter\n%s\n' \ + '- **Statut** : resolved' > d15/relpath/.claude/memory/blockers.md +(cd "$ROOT" && bash lib/memory.sh -C "$FIX/d15/relpath" upgrade >/dev/null 2>&1) +check T15-relpath-rc "$?" 0 +check T15-relpath-format "$(grep -c '^format: 2$' d15/relpath/.claude/memory/blockers.md)" 1 # an em-dash heading stays byte-identical, a dated one included v1blk d15/keep '## BLK-001 — keep — 2026-05-18' 'Status: open' bash "$MEM" upgrade d15/keep >/dev/null 2>&1