create-ai-memory 0.5.0 → 0.7.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
@@ -97,6 +97,44 @@ already have, every launch.
97
97
  One environment variable, `AI_MEM_ROOT`, points at the vault, so the whole system
98
98
  moves between machines by pointing at the same folder.
99
99
 
100
+ ## The full loop
101
+
102
+ Agents read the vault through `ai-mem.zsh` at launch and write to it through a Stop
103
+ hook at close. You read the same files in Obsidian, or through `ai-mem-search` and
104
+ `ai-mem-lint`. Neither side gets a privileged interface — it's the same folder either way.
105
+
106
+ ```mermaid
107
+ sequenceDiagram
108
+ autonumber
109
+ actor You
110
+ participant Shell as claude-start
111
+ participant Agent as Claude Code
112
+ participant Vault as _Ai_Memory
113
+ participant Backup as git backup (optional)
114
+
115
+ You->>Shell: claude-start
116
+ Shell->>Vault: read _Global_Profile.md + _Standards.md
117
+ Vault-->>Shell: full text
118
+ Shell->>Vault: read prior session's Session Outcome
119
+ Vault-->>Shell: Summary / Decisions / Blockers / Next
120
+ Shell->>Vault: create session log (project + previous wikilinks)
121
+ Shell->>Agent: launch, all of it as the first message
122
+ Note over You,Agent: the session's work happens here
123
+ You->>Agent: ai-note "..." (optional, mid-session)
124
+ Agent->>Vault: append to Live Notes
125
+ Note over Agent: session ends -- Stop hook fires
126
+ Agent->>Vault: rewrite Auto Session Log (branch, commits, changes)
127
+ Agent->>Backup: commit + push, if the vault is git-backed
128
+ Note over Vault: nothing overwritten -- a fresh file every session
129
+ You->>Shell: claude-start (next time)
130
+ Shell->>Vault: read prior session again
131
+ Note over Shell,Vault: now includes what just happened
132
+ ```
133
+
134
+ Everything through step 10 touches only files on your machine. Step 11 is the
135
+ only network call in the whole loop, and only exists if you set up a git-backed
136
+ vault yourself; skip that and everything stays local, always.
137
+
100
138
  ## See a full session
101
139
 
102
140
  ```console
@@ -61,9 +61,30 @@ rm -f "$tmp"
61
61
  # error (no network, no remote configured, etc).
62
62
  vault_git_root="$(git -C "${AI_MEM_ROOT:-}" rev-parse --show-toplevel 2>/dev/null || true)"
63
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
64
+ # A same-second Stop from a second terminal is real -- flock isn't
65
+ # portable to every platform this ships on, but `mkdir` is atomic
66
+ # everywhere. A lock older than 60s is almost certainly abandoned by a
67
+ # crashed run, not a genuine concurrent one (this operation normally
68
+ # completes in well under a second), so clear it rather than let one
69
+ # dead process wedge every future backup forever.
70
+ lock_dir="$vault_git_root/.git/aimem-backup.lock"
71
+ if [ -d "$lock_dir" ]; then
72
+ lock_age=$(( $(date +%s) - $(stat -c %Y "$lock_dir" 2>/dev/null || stat -f %m "$lock_dir" 2>/dev/null || echo 0) ))
73
+ if [ "$lock_age" -gt 60 ]; then
74
+ rmdir "$lock_dir" 2>/dev/null || true
75
+ fi
68
76
  fi
77
+
78
+ if mkdir "$lock_dir" 2>/dev/null; then
79
+ trap 'rmdir "$lock_dir" 2>/dev/null || true' EXIT
80
+ git -C "$vault_git_root" add -A 2>/dev/null || true
81
+ if ! git -C "$vault_git_root" diff --cached --quiet 2>/dev/null; then
82
+ git -C "$vault_git_root" commit -q -m "vault backup: ${stamp}" 2>/dev/null || true
83
+ git -C "$vault_git_root" push -q 2>/dev/null || true
84
+ fi
85
+ rmdir "$lock_dir" 2>/dev/null || true
86
+ trap - EXIT
87
+ fi
88
+ # else: another process holds a fresh lock right now -- skip silently,
89
+ # the next Stop event (this session or another) will catch up.
69
90
  fi
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-ai-memory",
3
- "version": "0.5.0",
3
+ "version": "0.7.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
@@ -260,6 +260,7 @@ $previous_session_block
260
260
  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
+ 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.
263
264
  EOF
264
265
  }
265
266
 
@@ -591,7 +592,6 @@ ai-mem-lint() {
591
592
  print -r -- "$issues issue(s) found"
592
593
  fi
593
594
  return $(( issues > 0 ? 1 : 0 ))
594
- return $(( issues > 0 ? 1 : 0 ))
595
595
  }
596
596
 
597
597
  # Full-text search across the vault. Plain grep -- no new dependency, and at
@@ -622,7 +622,17 @@ ai-mem-search() {
622
622
  return 1
623
623
  fi
624
624
 
625
- print -r -- "$raw"
625
+ # Newest-first: for a time-series log the most recent match is usually the
626
+ # relevant one, so a large result set stays usable at a glance even without
627
+ # ranking. Sort key is the YYYY-MM-DD_HH-MM-SS embedded in the filename;
628
+ # lines with no such timestamp (e.g. _Global_Profile.md) sort last.
629
+ local sorted ts
630
+ sorted="$(print -r -- "$raw" | while IFS= read -r line; do
631
+ ts="$(print -r -- "$line" | grep -oE '[0-9]{4}-[0-9]{2}-[0-9]{2}_[0-9]{2}-[0-9]{2}-[0-9]{2}' | head -1)"
632
+ print -r -- "${ts:-0000-00-00_00-00-00}|${line}"
633
+ done | sort -r | cut -d'|' -f2-)"
634
+
635
+ print -r -- "$sorted"
626
636
  print -r -- "--"
627
637
  print -r -- "$(print -r -- "$raw" | wc -l | tr -d ' ') match(es) for '$term'"
628
638
  }