create-ai-memory 0.9.1 → 0.11.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 +2 -1
- package/hooks/claude/session-start.sh +9 -1
- package/package.json +1 -1
- package/shell/ai-mem.zsh +85 -4
package/README.md
CHANGED
|
@@ -276,7 +276,8 @@ optional. Set `AI_MEM_ROOT` in `~/.zshrc` first if you do not want the default
|
|
|
276
276
|
| `ai-note <text>` | Append a timestamped note to today's session log while you work |
|
|
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
|
-
| `ai-mem-search <term> [project]` | Grep across the vault (or one project's logs) for a term, with `file:line:excerpt` |
|
|
279
|
+
| `ai-mem-search <term> [project] [--hops]` | Grep across the vault (or one project's logs) for a term, with `file:line:excerpt`. With `--hops`, also resolves any `[[wikilink]]` on a matched line to its project note and shows a short excerpt -- one hop out along the graph, not just the literal text match |
|
|
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
|
-
|
|
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.
|
|
3
|
+
"version": "0.11.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
|
-
|
|
597
|
+
_ai_mem_vault_backup
|
|
551
598
|
printf 'Appended to %s\n' "$session_note"
|
|
552
599
|
}
|
|
553
600
|
|
|
@@ -593,6 +640,7 @@ ai-lesson() {
|
|
|
593
640
|
|
|
594
641
|
printf -- '\n## %s [[%s]]\n\n### Problem\n%s\n\n### Solution\n%s\n' \
|
|
595
642
|
"$timestamp" "$project_name" "$problem" "$solution" >> "$lesson_file"
|
|
643
|
+
_ai_mem_vault_backup
|
|
596
644
|
printf 'Appended to %s\n' "$lesson_file"
|
|
597
645
|
}
|
|
598
646
|
# Lints the vault's links: session logs missing a project wikilink, previous
|
|
@@ -644,10 +692,20 @@ ai-mem-lint() {
|
|
|
644
692
|
# vault scale (a personal notes collection, not a codebase) there is no real
|
|
645
693
|
# performance reason to reach for anything faster.
|
|
646
694
|
ai-mem-search() {
|
|
647
|
-
local
|
|
648
|
-
local
|
|
695
|
+
local hops=0
|
|
696
|
+
local -a rest
|
|
697
|
+
local a
|
|
698
|
+
for a in "$@"; do
|
|
699
|
+
if [[ "$a" == "--hops" ]]; then
|
|
700
|
+
hops=1
|
|
701
|
+
else
|
|
702
|
+
rest+=("$a")
|
|
703
|
+
fi
|
|
704
|
+
done
|
|
705
|
+
local term="${rest[1]:-}"
|
|
706
|
+
local project="${rest[2]:-}"
|
|
649
707
|
if [[ -z "$term" ]]; then
|
|
650
|
-
echo "Usage: ai-mem-search <term> [project]"
|
|
708
|
+
echo "Usage: ai-mem-search <term> [project] [--hops]"
|
|
651
709
|
return 1
|
|
652
710
|
fi
|
|
653
711
|
|
|
@@ -681,4 +739,27 @@ ai-mem-search() {
|
|
|
681
739
|
print -r -- "$sorted"
|
|
682
740
|
print -r -- "--"
|
|
683
741
|
print -r -- "$(print -r -- "$raw" | wc -l | tr -d ' ') match(es) for '$term'"
|
|
742
|
+
|
|
743
|
+
(( hops )) || return 0
|
|
744
|
+
|
|
745
|
+
# One hop out: resolve [[wikilinks]] found on matched lines to their
|
|
746
|
+
# target note (currently: project notes only -- the confirmed use case
|
|
747
|
+
# is a _lessons entry linking the project(s) it hit) and show a short
|
|
748
|
+
# excerpt, so a match doesn't leave you to manually chase the link
|
|
749
|
+
# yourself.
|
|
750
|
+
local links link target excerpt
|
|
751
|
+
links="$(print -r -- "$raw" | grep -oE '\[\[[^]]+\]\]' | sed -E 's/^\[\[|\]\]$//g' | sort -u)"
|
|
752
|
+
[[ -n "$links" ]] || return 0
|
|
753
|
+
|
|
754
|
+
print -r -- "--"
|
|
755
|
+
print -r -- "one hop out:"
|
|
756
|
+
while IFS= read -r link; do
|
|
757
|
+
[[ -n "$link" ]] || continue
|
|
758
|
+
target="$AI_MEM_PROJECT_DIR/${link}.md"
|
|
759
|
+
[[ -f "$target" ]] || continue
|
|
760
|
+
excerpt="$(grep -m1 -A1 '^\* \*\*Purpose:\*\*' "$target" 2>/dev/null | tail -1)"
|
|
761
|
+
[[ -n "$excerpt" ]] || excerpt="$(sed -n '/^---$/,/^---$/!p' "$target" | grep -m1 -v '^$')"
|
|
762
|
+
print -r -- " [[$link]] -> $target"
|
|
763
|
+
[[ -n "$excerpt" ]] && print -r -- " $excerpt"
|
|
764
|
+
done <<< "$links"
|
|
684
765
|
}
|