create-ai-memory 0.18.0 → 0.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -124,6 +124,10 @@ function titleOf(text, path, fm, h1Counts) {
124
124
  }
125
125
 
126
126
  const LINK_RE = /\[\[([^\]|#]+)/g;
127
+ // Code is not prose: a shell test such as [[ -n $X ]] inside `inline code` or
128
+ // a fenced block looks like a wikilink. Same rule as ai-mem-lint, including a
129
+ // fence that never closes, which runs to the end of the note (as in Obsidian).
130
+ const CODE_RE = /^[ \t]*(```|~~~)[^\n]*(?:\n[\s\S]*?^[ \t]*\1[^\n]*$|[\s\S]*$(?![\s\S]))|`[^`\n]*`/gm;
127
131
 
128
132
  /**
129
133
  * Build the graph.
@@ -171,7 +175,9 @@ function buildGraph() {
171
175
  return 0;
172
176
  }
173
177
  })(),
174
- links: [...text.matchAll(LINK_RE)].map((m) => m[1].trim()),
178
+ links: [...text.replace(CODE_RE, '').matchAll(LINK_RE)]
179
+ .map((m) => m[1].trim())
180
+ .filter((l) => !l.includes('{{')),
175
181
  };
176
182
  nodes.push(node);
177
183
  // First writer wins: a duplicate basename is ambiguous in Obsidian too.
@@ -187,7 +193,8 @@ function buildGraph() {
187
193
  // mark which notes carry a broken link without inventing targets for them.
188
194
  const danglingSeen = new Set();
189
195
  for (const link of n.links) {
190
- const target = byBasename.get(link);
196
+ // A folder path ([[_idea/x]], [[../dir/x]]) resolves by its last segment.
197
+ const target = byBasename.get(link) || byBasename.get(link.split('/').pop());
191
198
  if (!target) {
192
199
  if (link && link !== basename(n.id, '.md')) danglingSeen.add(link);
193
200
  continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-ai-memory",
3
- "version": "0.18.0",
3
+ "version": "0.18.1",
4
4
  "description": "Persistent, harness-agnostic session memory for AI coding CLIs (Claude Code, Codex, Gemini, Cursor, opencode, omp). One Markdown vault, any harness.",
5
5
  "bin": {
6
6
  "create-ai-memory": "bin/create-ai-memory.js",
package/shell/ai-mem.zsh CHANGED
@@ -1098,6 +1098,8 @@ __ai_mem_current_project() {
1098
1098
  # Create a global (GUI/MCP) session log at $1 if it does not exist yet. Global
1099
1099
  # logs are created lazily, on the first write, so a read-only conversation
1100
1100
  # leaves no empty note behind. `previous:` links the newest log with content.
1101
+ # `project:` links the project note, as in a terminal session log: without it
1102
+ # ai-mem-lint reports the log as orphaned and the graph shows it unconnected.
1101
1103
  __ai_mem_create_global_log() {
1102
1104
  local session_note="$1" project_name="$2" previous prev_link=""
1103
1105
  [[ -f "$session_note" ]] && return 0
@@ -1105,7 +1107,8 @@ __ai_mem_create_global_log() {
1105
1107
  previous="$(__ai_mem_latest_session_log "$project_name")" || return 1
1106
1108
  [[ -n "$previous" ]] && prev_link="[[${previous:t:r}]]"
1107
1109
  mkdir -p "${session_note:h}"
1108
- print -rl -- "---" "type: ai-global-session" "date: $(date +%Y-%m-%d)" "previous: \"$prev_link\"" "---" "" "# Global Session Notes" > "$session_note"
1110
+ print -rl -- "---" "type: ai-global-session" "date: $(date +%Y-%m-%d)" "project: \"[[$project_name]]\"" \
1111
+ "previous: \"$prev_link\"" "---" "" "# Global Session Notes" > "$session_note"
1109
1112
  }
1110
1113
 
1111
1114
  __ai_mem_today_session_log() {
@@ -1388,7 +1391,9 @@ ai-mem-lint() {
1388
1391
  __ai_mem_paths
1389
1392
  local fix=0
1390
1393
  [[ "${1:-}" == "--fix" ]] && fix=1
1391
- local issues=0 f label target
1394
+ # Declared once here: re-declaring a set local (`local pname` inside a
1395
+ # loop or a later block) makes zsh print "pname=value" to stdout.
1396
+ local issues=0 f label target pname otmp
1392
1397
  # Open Knowledge Format names exactly one required frontmatter field:
1393
1398
  # `type`. Every note the vault ships already declares one except session
1394
1399
  # logs, which predate the field -- so a vault that has been in use carries
@@ -1413,7 +1418,11 @@ ai-mem-lint() {
1413
1418
  # ai-mem-sleep moves older logs into the project's _archive/, and
1414
1419
  # Obsidian resolves a link by basename anywhere in the vault. A
1415
1420
  # link to an archived log still opens, so it is not dangling.
1416
- if [[ ! -f "${f:h}/${target}.md" && ! -f "${f:h}/_archive/${target}.md" ]]; then
1421
+ # A project renamed mid-history links its first log to a log in
1422
+ # the old project's folder; Obsidian resolves that by basename,
1423
+ # so look vault-wide before calling it dangling (rare, so cheap).
1424
+ if [[ ! -f "${f:h}/${target}.md" && ! -f "${f:h}/_archive/${target}.md" \
1425
+ && -z "$(find "$AI_MEM_SESSION_DIR" -name "${target}.md" -print -quit 2>/dev/null)" ]]; then
1417
1426
  print -r -- "dangling previous link: $f -> [[${target}]] (not found)"
1418
1427
  (( issues++ ))
1419
1428
  fi
@@ -1422,7 +1431,7 @@ ai-mem-lint() {
1422
1431
 
1423
1432
  while IFS= read -r -d '' f; do
1424
1433
  [[ "${f:t}" == "_project_template.md" ]] && continue
1425
- local pname="${f:t:r}"
1434
+ pname="${f:t:r}"
1426
1435
  if ! grep -rq -- "\[\[${pname}\]\]" "$AI_MEM_SESSION_DIR" 2>/dev/null; then
1427
1436
  print -r -- "unreferenced project note (no session log links to it): $f"
1428
1437
  (( issues++ ))
@@ -1464,7 +1473,6 @@ ai-mem-lint() {
1464
1473
  done < <(find "$AI_MEM_SESSION_DIR" -maxdepth 2 -name "*.md" -print0 2>/dev/null)
1465
1474
 
1466
1475
  if (( $#orphan_files && fix )); then
1467
- local pname otmp
1468
1476
  for f in $orphan_files; do
1469
1477
  __ai_mem_guard "$f" >/dev/null || continue
1470
1478
  pname="$(grep -m1 '^project: ' "$f" | sed 's/^project: *//; s/^"//; s/"$//')"
@@ -1503,29 +1511,46 @@ ai-mem-lint() {
1503
1511
  # a dead edge in the graph. Detection only: the dead link is surfaced, never
1504
1512
  # auto-removed, because the intended target is unknowable and a note's own
1505
1513
  # prose is the author's to edit. Wikilinks resolve by basename (the same way
1506
- # ai-mem-serve draws them), so the node set is every note's basename.
1514
+ # ai-mem-serve draws them), so the node set is every note's basename. A
1515
+ # folder path ([[_idea/x]], [[../dir/x]]) resolves by its last segment.
1507
1516
  #
1508
- # One grep over the vault, never a grep per file -- a per-file scan is the
1509
- # 25s antipattern ai-mem-search documents. Scope is the vault root derived
1510
- # from AI_MEM_SESSION_DIR (its parent), the same subtree the rest of this
1511
- # linter walks, so a caller that redirects the session dir redirects this too.
1517
+ # Not links, so never reported (28 of 280 findings on a real vault were
1518
+ # these): text inside `inline code` or a fenced code block, where a shell
1519
+ # test such as [[ -n $X ]] looks like a wikilink, and {{placeholder}}
1520
+ # targets in the note templates.
1521
+ #
1522
+ # One awk pass over the vault, never a process per file -- a per-file scan
1523
+ # is the 25s antipattern ai-mem-search documents. Scope is the vault root
1524
+ # derived from AI_MEM_SESSION_DIR (its parent), the same subtree the rest
1525
+ # of this linter walks, so a caller that redirects the session dir
1526
+ # redirects this too.
1512
1527
  local vault="${AI_MEM_SESSION_DIR:h}"
1513
- typeset -A _known
1514
- local nf
1515
- for nf in ${(f)"$(find "$vault" -name '*.md' -not -path '*/.git/*' 2>/dev/null)"}; do
1516
- _known[${nf:t:r}]=1
1517
- done
1528
+ local known_file
1529
+ known_file="$(mktemp)"
1530
+ find "$vault" -name '*.md' -not -path '*/.git/*' 2>/dev/null \
1531
+ | awk '{ sub(/.*\//, ""); sub(/\.md$/, ""); print }' > "$known_file"
1518
1532
  local -a dangling
1519
- local line src tgt
1520
- for line in ${(f)"$(grep -rHoE --include='*.md' --exclude-dir=.git -- '\[\[[^]]+\]\]' "$vault" 2>/dev/null)"}; do
1521
- src="${line%%:\[\[*}" # path, before the ':[[' grep separator
1522
- tgt="${line##*:\[\[}"; tgt="${tgt%\]\]}" # inside the brackets
1523
- tgt="${tgt%%\|*}"; tgt="${tgt%%#*}" # drop |alias and #heading
1524
- tgt="${tgt## }"; tgt="${tgt%% }"
1525
- [[ -z "$tgt" ]] && continue
1526
- [[ -n "${_known[$tgt]-}" ]] && continue
1527
- dangling+=( "${src:t} -> [[${tgt}]]" )
1528
- done
1533
+ dangling=( ${(f)"$(find "$vault" -name '*.md' -not -path '*/.git/*' -exec awk -v kf="$known_file" '
1534
+ FILENAME == kf { known[$0] = 1; next }
1535
+ FNR == 1 { fence = 0; src = FILENAME; sub(/.*\//, "", src) }
1536
+ /^[ \t]*(```|~~~)/ { fence = !fence; next }
1537
+ fence { next }
1538
+ {
1539
+ line = $0
1540
+ gsub(/`[^`]*`/, "", line)
1541
+ while (match(line, /\[\[[^\]]+\]\]/)) {
1542
+ t = substr(line, RSTART + 2, RLENGTH - 4)
1543
+ line = substr(line, RSTART + RLENGTH)
1544
+ sub(/\|.*/, "", t); sub(/#.*/, "", t)
1545
+ sub(/^ +/, "", t); sub(/ +$/, "", t)
1546
+ if (t == "" || index(t, "{{")) continue
1547
+ b = t; sub(/.*\//, "", b)
1548
+ if ((t in known) || (b in known)) continue
1549
+ print src " -> [[" t "]]"
1550
+ }
1551
+ }' "$known_file" {} + 2>/dev/null)"} )
1552
+ rm -f "$known_file"
1553
+ local line
1529
1554
  if (( $#dangling )); then
1530
1555
  print -r -- "$#dangling dangling wikilink(s) -- a [[link]] that resolves to no note:"
1531
1556
  for line in $dangling; do print -r -- " $line"; done