create-ai-memory 0.9.0 → 0.10.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
@@ -277,6 +277,7 @@ optional. Set `AI_MEM_ROOT` in `~/.zshrc` first if you do not want the default
277
277
  | `ai-lesson <topic-slug> <problem> <solution>` | Append a dated Problem/Solution entry to a cross-project `_lessons/<topic-slug>.md` -- decisions, mistakes, solutions worth recalling outside the current project |
278
278
  | `ai-mem-lint` | Check the vault's links: orphaned session logs, dangling `previous` links, unreferenced project notes |
279
279
  | `ai-mem-search <term> [project]` | Grep across the vault (or one project's logs) for a term, with `file:line:excerpt` |
280
+ | `ai-mem-vault-backup` | Commit and push the vault if it's git-backed. `ai-note`/`ai-lesson` already call this; use it directly after editing a session log or project note by hand |
280
281
 
281
282
  Project is auto-resolved from the current git repo; pass a name to override.
282
283
 
@@ -13,4 +13,12 @@ log="${AI_MEM_ACTIVE_SESSION_LOG:-}"
13
13
  sha="$(git rev-parse HEAD 2>/dev/null || true)"
14
14
  [ -n "$sha" ] || exit 0
15
15
 
16
- printf '%s\n' "$sha" > "${log%.md}.startsha"
16
+ # The log directory can disappear under a running shell -- a project rename
17
+ # moves it, and AI_MEM_ACTIVE_SESSION_LOG still points at the old path.
18
+ # Without this guard the redirect fails, `set -e` aborts, and Claude Code
19
+ # prints the hook's error -- including these absolute paths -- into the first
20
+ # frame of every session. A SessionStart hook must fail open: it is
21
+ # bookkeeping, not a gate.
22
+ [ -d "$(dirname "$log")" ] || exit 0
23
+
24
+ printf '%s\n' "$sha" > "${log%.md}.startsha" 2>/dev/null || exit 0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-ai-memory",
3
- "version": "0.9.0",
3
+ "version": "0.10.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
@@ -33,6 +33,53 @@ _ai_mem_guard() {
33
33
  esac
34
34
  }
35
35
 
36
+ # Best-effort git commit+push for the vault itself (not the project repo being
37
+ # worked on) -- shared by ai-note/ai-lesson (so a note is durable the moment
38
+ # it's written, not just at session Stop, which can silently never fire) and
39
+ # the Stop hook's own copy (hooks/claude/session-summary.sh runs standalone,
40
+ # outside this sourced shell, so it can't call this function directly).
41
+ # No-ops silently if AI_MEM_ROOT isn't its own git repo; never fails the
42
+ # caller on a push error (no network, no remote configured, etc).
43
+ _ai_mem_vault_backup() {
44
+ local vault_git_root
45
+ vault_git_root="$(git -C "${AI_MEM_ROOT:-}" rev-parse --show-toplevel 2>/dev/null || true)"
46
+ [[ -n "$vault_git_root" ]] || return 0
47
+
48
+ local lock_dir="$vault_git_root/.git/aimem-backup.lock"
49
+ if [[ -d "$lock_dir" ]]; then
50
+ local lock_age=$(( $(date +%s) - $(stat -c %Y "$lock_dir" 2>/dev/null || stat -f %m "$lock_dir" 2>/dev/null || echo 0) ))
51
+ (( lock_age > 60 )) && rmdir "$lock_dir" 2>/dev/null
52
+ fi
53
+
54
+ if mkdir "$lock_dir" 2>/dev/null; then
55
+ git -C "$vault_git_root" add -A 2>/dev/null
56
+ if ! git -C "$vault_git_root" diff --cached --quiet 2>/dev/null; then
57
+ git -C "$vault_git_root" commit -q -m "vault backup: $(date '+%Y-%m-%d %H:%M:%S')" 2>/dev/null
58
+ git -C "$vault_git_root" push -q 2>/dev/null
59
+ fi
60
+ rmdir "$lock_dir" 2>/dev/null
61
+ fi
62
+ return 0
63
+ return 0
64
+ }
65
+
66
+ # Public entry point for anything that writes to the vault outside
67
+ # ai-note/ai-lesson -- e.g. the update-session-log skill, which edits the
68
+ # Session Outcome section directly and has no other reason to know this
69
+ # function exists.
70
+ ai-mem-vault-backup() {
71
+ local before after
72
+ before="$(git -C "${AI_MEM_ROOT:-}" rev-parse HEAD 2>/dev/null || true)"
73
+ _ai_mem_vault_backup
74
+ after="$(git -C "${AI_MEM_ROOT:-}" rev-parse HEAD 2>/dev/null || true)"
75
+ if [[ -z "$before" && -z "$after" ]]; then
76
+ echo "ai-mem-vault-backup: vault isn't git-backed, nothing to do"
77
+ elif [[ "$before" != "$after" ]]; then
78
+ echo "ai-mem-vault-backup: pushed"
79
+ else
80
+ echo "ai-mem-vault-backup: nothing to commit"
81
+ fi
82
+ }
36
83
  # Read a vault note only when it exists inside the memory root.
37
84
  _ai_mem_note_contents() {
38
85
  local path="${1:-}"
@@ -547,7 +594,7 @@ ai-note() {
547
594
  fi
548
595
 
549
596
  printf '\n- %s %s\n' "$timestamp" "$note_text" >> "$session_note"
550
- printf 'Appended to %s\n' "$session_note"
597
+ _ai_mem_vault_backup
551
598
  printf 'Appended to %s\n' "$session_note"
552
599
  }
553
600
 
@@ -584,7 +631,8 @@ ai-lesson() {
584
631
  mkdir -p "$AI_MEM_ROOT/_lessons"
585
632
  local lesson_template="$AI_MEM_ROOT/_lessons/_lesson_template.md"
586
633
  if [[ -f "$lesson_template" ]]; then
587
- TOPIC="$slug" perl -0pe 's/\{\{topic\}\}/$ENV{TOPIC}/g' "$lesson_template" > "$lesson_file"
634
+ TOPIC="$slug" perl -0pe 's/\{\{topic\}\}/$ENV{TOPIC}/g' "$lesson_template" \
635
+ | awk '/^# /{print; exit} {print}' > "$lesson_file"
588
636
  else
589
637
  printf -- '---\ntype: ai-lesson\ntopic: %s\n---\n\n# %s\n' "$slug" "$slug" > "$lesson_file"
590
638
  fi
@@ -592,6 +640,7 @@ ai-lesson() {
592
640
 
593
641
  printf -- '\n## %s [[%s]]\n\n### Problem\n%s\n\n### Solution\n%s\n' \
594
642
  "$timestamp" "$project_name" "$problem" "$solution" >> "$lesson_file"
643
+ _ai_mem_vault_backup
595
644
  printf 'Appended to %s\n' "$lesson_file"
596
645
  }
597
646
  # Lints the vault's links: session logs missing a project wikilink, previous
@@ -4,3 +4,11 @@ topic: "{{topic}}"
4
4
  ---
5
5
 
6
6
  # {{topic}}
7
+
8
+ ## [Date] [Project]
9
+
10
+ ### Problem
11
+ [What went wrong]
12
+
13
+ ### Solution
14
+ [What fixed it]