create-ai-memory 0.7.1 → 0.8.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
@@ -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
 
@@ -389,9 +390,17 @@ Launchers are not hardcoded. Each agent is one small adapter, and the
389
390
  The files live in `hooks/claude/`. Record repo `HEAD` at session start, then on
390
391
  exit write an auto block to the log with the branch, commits made this session, and
391
392
  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`.
393
+ template. A third hook fires right before Claude Code auto-compacts: the first
394
+ attempt each session it blocks compaction once and tells the agent to run
395
+ `ai-note` before its working context gets thrown away, then gets out of the
396
+ way for every later attempt (one-shot, via a marker file next to the log) so
397
+ the session can never get stuck refusing to compact. It only guards
398
+ auto-compact, not a deliberate `/compact`. Merge `settings.snippet.json` into
399
+ `~/.claude/settings.json`, replacing `<AI_MEM_HOME>` with an absolute path.
400
+ All three hooks no-op for plain `claude` runs; they gate on
401
+ `$AI_MEM_ACTIVE_SESSION_LOG`. This is Claude-Code-specific -- other agents
402
+ (Codex, Gemini, etc.) have no equivalent pre-compaction hook, so jotting
403
+ things down with `ai-note`/`codex-note` as you go still matters there.
395
404
 
396
405
  ### Git commit guard
397
406
  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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-ai-memory",
3
- "version": "0.7.1",
3
+ "version": "0.8.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
@@ -261,6 +261,7 @@ Use the Obsidian vault as the persistent memory layer.
261
261
  Treat the global profile and standards note as the shared baseline for every run.
262
262
  Keep durable preferences and project facts in the vault, and keep the active session log updated with decisions, blockers, and next steps.
263
263
  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.
264
+ 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
265
  EOF
265
266
  }
266
267
 
@@ -549,6 +550,49 @@ ai-note() {
549
550
  printf 'Appended to %s\n' "$session_note"
550
551
  }
551
552
 
553
+ codex-lesson() {
554
+ ai-lesson "$@"
555
+ }
556
+
557
+ # Cross-project memory: a mistake, decision, or reusable solution, filed under
558
+ # a topic instead of a single project's session log. One flat file per topic
559
+ # (ADR/postmortem shape, not a full wiki) so ai-mem-search already covers it
560
+ # for free -- no new search path, no taxonomy to maintain.
561
+ ai-lesson() {
562
+ local topic="${1:-}"
563
+ if [[ -z "$topic" ]]; then
564
+ echo "Usage: ai-lesson <topic-slug> <text>"
565
+ return 1
566
+ fi
567
+ shift
568
+ local text="${*:-}"
569
+ if [[ -z "$text" ]]; then
570
+ echo "Usage: ai-lesson <topic-slug> <text>"
571
+ return 1
572
+ fi
573
+
574
+ local slug
575
+ slug="$(print -r -- "$topic" | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z0-9]+/-/g; s/^-+|-+$//g')"
576
+ if [[ -z "$slug" ]]; then
577
+ echo "ai-lesson: topic slug must contain at least one letter or digit"
578
+ return 1
579
+ fi
580
+
581
+ local project_name lesson_file timestamp
582
+ project_name="$(_ai_mem_current_project)" || return 1
583
+ lesson_file="$AI_MEM_ROOT/_lessons/${slug}.md"
584
+ timestamp="$(date '+%Y-%m-%d %H:%M')"
585
+
586
+ _ai_mem_guard "$lesson_file" || return 1
587
+
588
+ if [[ ! -f "$lesson_file" ]]; then
589
+ mkdir -p "$AI_MEM_ROOT/_lessons"
590
+ printf -- '---\ntype: ai-lesson\ntopic: %s\n---\n\n# %s\n' "$slug" "$slug" > "$lesson_file"
591
+ fi
592
+
593
+ printf -- '\n- %s [%s] %s\n' "$timestamp" "$project_name" "$text" >> "$lesson_file"
594
+ printf 'Appended to %s\n' "$lesson_file"
595
+ }
552
596
  # Lints the vault's links: session logs missing a project wikilink, previous
553
597
  # links pointing at a note that no longer exists, and project notes nothing
554
598
  # links back to. Pure grep/find -- no new dependency, catches exactly the