create-ai-memory 0.2.1 → 0.4.0

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.
package/README.md CHANGED
@@ -16,8 +16,9 @@ npm create ai-memory@latest
16
16
  ```
17
17
 
18
18
  [![npm](https://img.shields.io/npm/v/create-ai-memory?color=cb3837&label=npm)](https://www.npmjs.com/package/create-ai-memory)
19
+ [![ci](https://img.shields.io/github/actions/workflow/status/rambaarde/create-ai-memory/ci.yml?label=ci)](https://github.com/rambaarde/create-ai-memory/actions/workflows/ci.yml)
20
+ [![release](https://img.shields.io/github/actions/workflow/status/rambaarde/create-ai-memory/publish.yml?label=release)](https://github.com/rambaarde/create-ai-memory/actions/workflows/publish.yml)
19
21
  ![zsh](https://img.shields.io/badge/shell-zsh-89e051)
20
- ![tests](https://img.shields.io/badge/tests-44%20passing-brightgreen)
21
22
  ![deps](https://img.shields.io/badge/runtime%20deps-0-blue)
22
23
  ![license](https://img.shields.io/badge/license-MIT-blue)
23
24
  ![PRs](https://img.shields.io/badge/PRs-welcome-orange)
@@ -235,6 +236,7 @@ optional. Set `AI_MEM_ROOT` in `~/.zshrc` first if you do not want the default
235
236
  | `ai-start [project]` | Prepare the session (project note and fresh log) without launching an agent |
236
237
  | `ai-context [project]` | Print the vault context block for the current repo, and arm the git commit guard |
237
238
  | `ai-note <text>` | Append a timestamped note to today's session log while you work |
239
+ | `ai-mem-lint` | Check the vault's links: orphaned session logs, dangling `previous` links, unreferenced project notes |
238
240
 
239
241
  Project is auto-resolved from the current git repo; pass a name to override.
240
242
 
@@ -52,3 +52,18 @@ tmp="$(mktemp)"
52
52
  awk -v m="$marker" 'index($0, m)==1 { exit } { print }' "$log" > "$tmp"
53
53
  printf '%s\n\n%s\n' "$(cat "$tmp")" "$block" > "$log"
54
54
  rm -f "$tmp"
55
+
56
+ # Optional vault backup: if AI_MEM_ROOT (or an ancestor directory) is its own
57
+ # git repo, commit and push whatever changed this session. Entirely separate
58
+ # from the project repo git calls above -- this targets the vault, not the
59
+ # code being worked on. No-ops silently if the vault isn't git-backed; this
60
+ # is best-effort and must never fail the hook or block the session on a push
61
+ # error (no network, no remote configured, etc).
62
+ vault_git_root="$(git -C "${AI_MEM_ROOT:-}" rev-parse --show-toplevel 2>/dev/null || true)"
63
+ if [ -n "$vault_git_root" ]; then
64
+ git -C "$vault_git_root" add -A 2>/dev/null || true
65
+ if ! git -C "$vault_git_root" diff --cached --quiet 2>/dev/null; then
66
+ git -C "$vault_git_root" commit -q -m "vault backup: ${stamp}" 2>/dev/null || true
67
+ git -C "$vault_git_root" push -q 2>/dev/null || true
68
+ fi
69
+ fi
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-ai-memory",
3
- "version": "0.2.1",
3
+ "version": "0.4.0",
4
4
  "description": "Persistent, agent-agnostic session memory for AI coding CLIs (Claude Code, Codex, Gemini, Cursor, opencode). One Markdown vault, any agent.",
5
5
  "bin": {
6
6
  "create-ai-memory": "bin/create-ai-memory.js"
package/shell/ai-mem.zsh CHANGED
@@ -172,7 +172,12 @@ _ai_mem_prepare_session() {
172
172
  "$AI_MEM_PROJECT_DIR/_project_template.md" > "$project_note"
173
173
  fi
174
174
 
175
- SESSION_DATE="$(date +%Y-%m-%d)" PROJECT_NAME="$project_name" perl -0pe 's/\{\{date\}\}/$ENV{SESSION_DATE}/g; s/\{\{project_name\}\}/$ENV{PROJECT_NAME}/g' \
175
+ local prev_link=""
176
+ if [[ -n "$previous_session_note" ]]; then
177
+ prev_link="[[${previous_session_note:t:r}]]"
178
+ fi
179
+
180
+ SESSION_DATE="$(date +%Y-%m-%d)" PROJECT_NAME="$project_name" PREV_LINK="$prev_link" perl -0pe 's/\{\{date\}\}/$ENV{SESSION_DATE}/g; s/\{\{project_name\}\}/$ENV{PROJECT_NAME}/g; s/\{\{previous_session_link\}\}/$ENV{PREV_LINK}/g' \
176
181
  "$AI_MEM_SESSION_DIR/_session_template.md" > "$session_note"
177
182
 
178
183
  export AI_MEM_ACTIVE_PROJECT="$project_name"
@@ -540,4 +545,50 @@ ai-note() {
540
545
 
541
546
  printf '\n- %s %s\n' "$timestamp" "$note_text" >> "$session_note"
542
547
  printf 'Appended to %s\n' "$session_note"
548
+ printf 'Appended to %s\n' "$session_note"
549
+ }
550
+
551
+ # Lints the vault's links: session logs missing a project wikilink, previous
552
+ # links pointing at a note that no longer exists, and project notes nothing
553
+ # links back to. Pure grep/find -- no new dependency, catches exactly the
554
+ # "isolated dots in Graph View" class of problem before you have to notice it
555
+ # by eye.
556
+ ai-mem-lint() {
557
+ local issues=0 f label target found
558
+
559
+ while IFS= read -r -d '' f; do
560
+ [[ "${f:t}" == "_session_template.md" ]] && continue
561
+
562
+ if ! grep -qm1 -E '^project:.*\[\[.*\]\]' "$f" 2>/dev/null; then
563
+ print -r -- "orphaned session log (no project link): $f"
564
+ (( issues++ ))
565
+ fi
566
+
567
+ label="$(grep -m1 '^previous:' "$f" 2>/dev/null)"
568
+ if [[ "$label" == *'[['* ]]; then
569
+ target="${label#*\[\[}"
570
+ target="${target%%\]\]*}"
571
+ found="$(find "${f:h}" -maxdepth 1 -name "${target}.md" -print -quit 2>/dev/null)"
572
+ if [[ -z "$found" ]]; then
573
+ print -r -- "dangling previous link: $f -> [[${target}]] (not found)"
574
+ (( issues++ ))
575
+ fi
576
+ fi
577
+ done < <(find "$AI_MEM_SESSION_DIR" -maxdepth 2 -name "*.md" -print0 2>/dev/null)
578
+
579
+ while IFS= read -r -d '' f; do
580
+ [[ "${f:t}" == "_project_template.md" ]] && continue
581
+ local pname="${f:t:r}"
582
+ if ! grep -rq -- "\[\[${pname}\]\]" "$AI_MEM_SESSION_DIR" 2>/dev/null; then
583
+ print -r -- "unreferenced project note (no session log links to it): $f"
584
+ (( issues++ ))
585
+ fi
586
+ done < <(find "$AI_MEM_PROJECT_DIR" -maxdepth 1 -name "*.md" -print0 2>/dev/null)
587
+
588
+ if (( issues == 0 )); then
589
+ print -r -- "ok: vault links are clean"
590
+ else
591
+ print -r -- "$issues issue(s) found"
592
+ fi
593
+ return $(( issues > 0 ? 1 : 0 ))
543
594
  }
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  date: {{date}}
3
- project: {{project_name}}
3
+ project: "[[{{project_name}}]]"
4
+ previous: "{{previous_session_link}}"
4
5
  repo_root: [Insert Repo Root]
5
6
  ---
6
7