create-ai-memory 0.7.1 → 0.8.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.
package/README.md CHANGED
@@ -274,6 +274,7 @@ optional. Set `AI_MEM_ROOT` in `~/.zshrc` first if you do not want the default
274
274
  | `ai-start [project]` | Prepare the session (project note and fresh log) without launching an agent |
275
275
  | `ai-context [project]` | Print the vault context block for the current repo, and arm the git commit guard |
276
276
  | `ai-note <text>` | Append a timestamped note to today's session log while you work |
277
+ | `ai-lesson <topic-slug> <text>` | Append a timestamped note to a cross-project `_lessons/<topic-slug>.md` -- decisions, mistakes, solutions worth recalling outside the current project |
277
278
  | `ai-mem-lint` | Check the vault's links: orphaned session logs, dangling `previous` links, unreferenced project notes |
278
279
  | `ai-mem-search <term> [project]` | Grep across the vault (or one project's logs) for a term, with `file:line:excerpt` |
279
280
 
@@ -357,6 +358,9 @@ $AI_MEM_ROOT/
357
358
  _session_template.md scaffold for new session logs
358
359
  <repo>/
359
360
  <repo>-<timestamp>.md one file per session
361
+ _lessons/
362
+ _lesson_template.md scaffold for new lesson topics
363
+ <topic-slug>.md cross-project decisions/mistakes, filed by ai-lesson
360
364
  ```
361
365
 
362
366
  Notes are created from templates on first use and never overwritten. Edit
@@ -389,9 +393,17 @@ Launchers are not hardcoded. Each agent is one small adapter, and the
389
393
  The files live in `hooks/claude/`. Record repo `HEAD` at session start, then on
390
394
  exit write an auto block to the log with the branch, commits made this session, and
391
395
  uncommitted changes, so the next session has real carryover instead of an empty
392
- template. Merge `settings.snippet.json` into `~/.claude/settings.json`, replacing
393
- `<AI_MEM_HOME>` with an absolute path. Both hooks no-op for plain `claude` runs;
394
- they gate on `$AI_MEM_ACTIVE_SESSION_LOG`.
396
+ template. A third hook fires right before Claude Code auto-compacts: the first
397
+ attempt each session it blocks compaction once and tells the agent to run
398
+ `ai-note` before its working context gets thrown away, then gets out of the
399
+ way for every later attempt (one-shot, via a marker file next to the log) so
400
+ the session can never get stuck refusing to compact. It only guards
401
+ auto-compact, not a deliberate `/compact`. Merge `settings.snippet.json` into
402
+ `~/.claude/settings.json`, replacing `<AI_MEM_HOME>` with an absolute path.
403
+ All three hooks no-op for plain `claude` runs; they gate on
404
+ `$AI_MEM_ACTIVE_SESSION_LOG`. This is Claude-Code-specific -- other agents
405
+ (Codex, Gemini, etc.) have no equivalent pre-compaction hook, so jotting
406
+ things down with `ai-note`/`codex-note` as you go still matters there.
395
407
 
396
408
  ### Git commit guard
397
409
  The files live in `hooks/git/`:
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env bash
2
+ # Claude Code PreCompact hook for the AI-memory vault.
3
+ #
4
+ # Auto-compact erases whatever the agent hasn't written down yet. This hook
5
+ # blocks the FIRST auto-compact attempt per session (exit 2 + stderr, which
6
+ # Claude Code surfaces to the agent) to nudge it into running `ai-note` before
7
+ # its working context is thrown away. A marker file makes it one-shot: every
8
+ # later compact attempt this session exits 0 immediately, so the session can
9
+ # never get stuck refusing to compact.
10
+ #
11
+ # No-ops unless the session was launched via claude-start (which exports
12
+ # AI_MEM_ACTIVE_SESSION_LOG). Wire this with matcher "auto" only -- a manual
13
+ # /compact is a deliberate user action, not the silent-erasure case this
14
+ # guards against.
15
+ set -euo pipefail
16
+
17
+ log="${AI_MEM_ACTIVE_SESSION_LOG:-}"
18
+ [ -n "$log" ] || exit 0
19
+ [ -f "$log" ] || exit 0
20
+
21
+ marker="${log%.md}.precompact-nudged"
22
+ [ -f "$marker" ] && exit 0
23
+
24
+ touch "$marker"
25
+ echo "Auto-compact is about to run and will erase anything not written down. Run ai-note \"<what matters from this session so far>\" now, then continue." >&2
26
+ exit 2
@@ -1,5 +1,5 @@
1
1
  {
2
- "_comment": "Merge into ~/.claude/settings.json. Replace <AI_MEM_HOME> with the absolute path to your ai-mem checkout (Claude Code does not expand env vars in hook commands). Both hooks no-op unless the session was launched via claude-start.",
2
+ "_comment": "Merge into ~/.claude/settings.json. Replace <AI_MEM_HOME> with the absolute path to your ai-mem checkout (Claude Code does not expand env vars in hook commands). All hooks no-op unless the session was launched via claude-start.",
3
3
  "hooks": {
4
4
  "SessionStart": [
5
5
  {
@@ -14,6 +14,14 @@
14
14
  { "type": "command", "command": "<AI_MEM_HOME>/hooks/claude/session-summary.sh" }
15
15
  ]
16
16
  }
17
+ ],
18
+ "PreCompact": [
19
+ {
20
+ "matcher": "auto",
21
+ "hooks": [
22
+ { "type": "command", "command": "<AI_MEM_HOME>/hooks/claude/pre-compact.sh" }
23
+ ]
24
+ }
17
25
  ]
18
26
  }
19
27
  }
package/install.sh CHANGED
@@ -78,7 +78,7 @@ ask AI_MEM_AGENTS "Which agents should get <agent>-start launchers?" "$AI_MEM_AG
78
78
  # --- scaffold the vault ------------------------------------------------------
79
79
  echo
80
80
  echo " scaffolding vault at: $AI_MEM_ROOT"
81
- mkdir -p "$AI_MEM_ROOT/_projects" "$AI_MEM_ROOT/_session_logs"
81
+ mkdir -p "$AI_MEM_ROOT/_projects" "$AI_MEM_ROOT/_session_logs" "$AI_MEM_ROOT/_lessons"
82
82
 
83
83
  copy_if_absent() { # never overwrite the user's real notes on a re-run
84
84
  local src="$1" dst="$2"
@@ -88,6 +88,7 @@ copy_if_absent "$HERE/vault-template/_Global_Profile.md" "$AI_ME
88
88
  copy_if_absent "$HERE/vault-template/_Standards.md" "$AI_MEM_ROOT/_Standards.md"
89
89
  copy_if_absent "$HERE/vault-template/_projects/_project_template.md" "$AI_MEM_ROOT/_projects/_project_template.md"
90
90
  copy_if_absent "$HERE/vault-template/_session_logs/_session_template.md" "$AI_MEM_ROOT/_session_logs/_session_template.md"
91
+ copy_if_absent "$HERE/vault-template/_lessons/_lesson_template.md" "$AI_MEM_ROOT/_lessons/_lesson_template.md"
91
92
 
92
93
  # --- assemble the ~/.zshrc lines ---------------------------------------------
93
94
  LINES="export AI_MEM_ROOT=\"$AI_MEM_ROOT\""
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-ai-memory",
3
- "version": "0.7.1",
3
+ "version": "0.8.1",
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
@@ -135,10 +135,11 @@ _ai_mem_latest_session_log() {
135
135
  # plugin-manager install (source only, no install.sh) still gets a working vault.
136
136
  _ai_mem_ensure_vault() {
137
137
  [[ -d "$AI_MEM_TEMPLATE_SRC" ]] || return 0
138
- mkdir -p "$AI_MEM_PROJECT_DIR" "$AI_MEM_SESSION_DIR"
138
+ mkdir -p "$AI_MEM_PROJECT_DIR" "$AI_MEM_SESSION_DIR" "$AI_MEM_ROOT/_lessons"
139
139
  local rel
140
140
  for rel in _Global_Profile.md _Standards.md \
141
- _projects/_project_template.md _session_logs/_session_template.md; do
141
+ _projects/_project_template.md _session_logs/_session_template.md \
142
+ _lessons/_lesson_template.md; do
142
143
  local src="$AI_MEM_TEMPLATE_SRC/$rel" dst="$AI_MEM_ROOT/$rel"
143
144
  if [[ -f "$src" && ! -f "$dst" ]]; then
144
145
  _ai_mem_guard "$dst" || return 1
@@ -261,6 +262,7 @@ Use the Obsidian vault as the persistent memory layer.
261
262
  Treat the global profile and standards note as the shared baseline for every run.
262
263
  Keep durable preferences and project facts in the vault, and keep the active session log updated with decisions, blockers, and next steps.
263
264
  For anything not covered above -- a decision from further back, a different project, a health check on the vault's links -- run \`ai-mem-search <term> [project]\` or \`ai-mem-lint\` yourself; both are plain shell commands already on PATH.
265
+ When you hit a mistake, decision, or solution worth remembering across projects (not just this one), run \`ai-lesson <topic-slug> <text>\` -- e.g. \`ai-lesson rate-limiting "used a token bucket, fixed window kept losing bursts"\`. It appends to a cross-project note at _lessons/<topic-slug>.md; ai-mem-search already covers it.
264
266
  EOF
265
267
  }
266
268
 
@@ -549,6 +551,54 @@ ai-note() {
549
551
  printf 'Appended to %s\n' "$session_note"
550
552
  }
551
553
 
554
+ codex-lesson() {
555
+ ai-lesson "$@"
556
+ }
557
+
558
+ # Cross-project memory: a mistake, decision, or reusable solution, filed under
559
+ # a topic instead of a single project's session log. One flat file per topic
560
+ # (ADR/postmortem shape, not a full wiki) so ai-mem-search already covers it
561
+ # for free -- no new search path, no taxonomy to maintain.
562
+ ai-lesson() {
563
+ local topic="${1:-}"
564
+ if [[ -z "$topic" ]]; then
565
+ echo "Usage: ai-lesson <topic-slug> <text>"
566
+ return 1
567
+ fi
568
+ shift
569
+ local text="${*:-}"
570
+ if [[ -z "$text" ]]; then
571
+ echo "Usage: ai-lesson <topic-slug> <text>"
572
+ return 1
573
+ fi
574
+
575
+ local slug
576
+ slug="$(print -r -- "$topic" | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z0-9]+/-/g; s/^-+|-+$//g')"
577
+ if [[ -z "$slug" ]]; then
578
+ echo "ai-lesson: topic slug must contain at least one letter or digit"
579
+ return 1
580
+ fi
581
+
582
+ local project_name lesson_file timestamp
583
+ project_name="$(_ai_mem_current_project)" || return 1
584
+ lesson_file="$AI_MEM_ROOT/_lessons/${slug}.md"
585
+ timestamp="$(date '+%Y-%m-%d %H:%M')"
586
+
587
+ _ai_mem_guard "$lesson_file" || return 1
588
+
589
+ if [[ ! -f "$lesson_file" ]]; then
590
+ mkdir -p "$AI_MEM_ROOT/_lessons"
591
+ local lesson_template="$AI_MEM_ROOT/_lessons/_lesson_template.md"
592
+ if [[ -f "$lesson_template" ]]; then
593
+ TOPIC="$slug" perl -0pe 's/\{\{topic\}\}/$ENV{TOPIC}/g' "$lesson_template" > "$lesson_file"
594
+ else
595
+ printf -- '---\ntype: ai-lesson\ntopic: %s\n---\n\n# %s\n' "$slug" "$slug" > "$lesson_file"
596
+ fi
597
+ fi
598
+
599
+ printf -- '\n- %s [%s] %s\n' "$timestamp" "$project_name" "$text" >> "$lesson_file"
600
+ printf 'Appended to %s\n' "$lesson_file"
601
+ }
552
602
  # Lints the vault's links: session logs missing a project wikilink, previous
553
603
  # links pointing at a note that no longer exists, and project notes nothing
554
604
  # links back to. Pure grep/find -- no new dependency, catches exactly the
@@ -615,7 +665,7 @@ ai-mem-search() {
615
665
  fi
616
666
 
617
667
  local raw
618
- raw="$(grep -rn --exclude-dir=.git --exclude='_session_template.md' --exclude='_project_template.md' -- "$term" "$search_root" 2>/dev/null)"
668
+ raw="$(grep -rn --exclude-dir=.git --exclude='_session_template.md' --exclude='_project_template.md' --exclude='_lesson_template.md' -- "$term" "$search_root" 2>/dev/null)"
619
669
 
620
670
  if [[ -z "$raw" ]]; then
621
671
  print -r -- "no matches for '$term' in $search_root"
@@ -0,0 +1,6 @@
1
+ ---
2
+ type: ai-lesson
3
+ topic: {{topic}}
4
+ ---
5
+
6
+ # {{topic}}