create-ai-memory 0.18.2 → 0.19.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
@@ -317,6 +317,7 @@ optional. Set `AI_MEM_ROOT` in `~/.zshrc` first if you do not want the default
317
317
  | `ai-about-me [--review] [harness]` | Fill `_about_me/` by interview. The agent asks one question at a time, asks about real past events before hypotheticals, asks "why does that matter?" to find the reason behind each rule, and writes a note only after you approve its draft. `--review` proposes rules found in 2 or more of your lessons and session logs; you accept, change or reject each one. The harness defaults to the first in `AI_MEM_HARNESSES`. When `_about_me/` holds only placeholders, the next launch tells you once, on stderr, never the agent |
318
318
  | `ai-mem-ingest --source-id <id> --title <t> --date <ISO> [...]` | File a distilled external artifact -- a meeting, a recorded call, a video, a voice note -- as one note in `_transcripts/`. Writes the summary, decisions, action items, attendee `[[wikilinks]]` and a link to the source; it never embeds the raw transcript body, because a full transcript is bulk the agent pays for and rarely needs. Re-ingesting the same `--source-id` updates that one note instead of filing a second copy. `ai-mem-search` covers `_transcripts/` with no extra path |
319
319
  | `ai-mem-lint [--fix]` | Check the vault's links: orphaned session logs, dangling `previous` links (a link to a log in the project's `_archive/` resolves, as it does in Obsidian), unreferenced project notes, and notes missing the `type:` field. Links to notes not written yet (`[[Name]]` with no `Name.md`) are **not** errors -- Obsidian creates the note when the link is clicked -- so they get one ranked line instead: `most linked: [[checkout-api]] 17, ...`. A target many notes link to is a missing note worth writing. `[[...]]` in code and `{{placeholders}}` are ignored. `--fix` backfills `type:` into session logs written before the field existed |
320
+ | `ai-mem-recall` | Does the memory get used? Every whole-vault `ai-mem-search` appends the lessons it showed (time, project, slug, query) to `.ai-mem/recall.tsv` in the vault. `ai-mem-recall` reads that log and the dated entries in `_lessons/`: how many lessons searches showed, and for each **repeat** entry (the same problem came back) whether a search showed that lesson in the 24 hours before. A repeat no search showed is a **recall miss**: the answer was in the vault and the agent never saw it. The log holds your search queries and is backed up with the vault |
320
321
  | `ai-mem-search <term> [project]` | Case-insensitive literal search across the vault (or one project's logs). Lessons rank first, and within them by *reinforcement* -- a lesson recalled more often (more dated entries) ranks above a once-seen one -- then by date; archived logs (see `ai-mem-sleep`) are skipped. Paths print relative to a root stated once in the header. Output is capped (`AI_MEM_SEARCH_LIMIT`, default 25) with an explicit `N hidden` notice, because the usual caller is an agent with a finite context window. Also resolves any `[[wikilink]]` on a matched line to its project note -- one hop out along the graph, always on, not a flag to remember |
321
322
  | `ai-mem-sleep [--apply]` | The vault's "bedtime" pass: archive stale session logs, flag consolidation candidates, and lint, in one run. Session logs older than `AI_MEM_SLEEP_DAYS` (default 90) move out of the hot search path -- always keeping the newest `AI_MEM_SLEEP_KEEP` (default 5) filled logs per project -- while `_lessons/` are never touched, because durable failure->fix knowledge is exactly what must survive. An **unfilled** log -- the template with nothing written, plus at most an Auto Session Log that saw no commits and a clean tree -- is archived once it is dated before yesterday, and never takes a KEEP slot: most sessions close without a note, and counting them pushed every real log out of the hot set. Dry-run by default; `--apply` moves logs into each project's `_archive/` (reversible via git) and backs up |
322
323
  | `ai-mem-sleep-schedule [--install\|--uninstall] [--at HH:MM]` | Run the bedtime pass on its own, nightly (default 03:00). macOS installs a launchd agent; other platforms a crontab entry. The scheduled job sets `AI_MEM_ROOT` and sources the module first, since a cron/launchd shell does not read `~/.zshrc`. On macOS, a vault in `~/Documents`, `~/Desktop`, `~/Downloads` or iCloud Drive gets a warning: macOS can deny a launchd job read access there, and the pass then does nothing. Check the job log after its first run. Dry-run by default -- prints exactly what it would install; `--install` schedules it, `--uninstall` removes it |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-ai-memory",
3
- "version": "0.18.2",
3
+ "version": "0.19.0",
4
4
  "description": "Persistent, harness-agnostic session memory for AI coding CLIs (Claude Code, Codex, Gemini, Cursor, opencode, omp). One Markdown vault, any harness.",
5
5
  "bin": {
6
6
  "create-ai-memory": "bin/create-ai-memory.js",
package/shell/ai-mem.zsh CHANGED
@@ -1877,8 +1877,9 @@ ai-mem-search() {
1877
1877
  local raw
1878
1878
  # --exclude-dir=_archive: session logs that ai-mem-sleep has retired are out
1879
1879
  # of the hot search path (their durable content lives on in a lesson). They
1880
- # stay in git and on disk, just not in a default search.
1881
- raw="$(grep -rniF --exclude-dir=.git --exclude-dir=_archive --exclude='_session_template.md' --exclude='_project_template.md' --exclude='_lesson_template.md' -- "$term" "$search_root" 2>/dev/null)"
1880
+ # stay in git and on disk, just not in a default search. .ai-mem holds the
1881
+ # recall log (see __ai_mem_log_recall), whose queries must not match.
1882
+ raw="$(grep -rniF --exclude-dir=.git --exclude-dir=_archive --exclude-dir=.ai-mem --exclude='_session_template.md' --exclude='_project_template.md' --exclude='_lesson_template.md' -- "$term" "$search_root" 2>/dev/null)"
1882
1883
 
1883
1884
  # Exact phrase first, then each word. A multi-word term used to be one
1884
1885
  # literal phrase, so word order decided whether anything came back:
@@ -1895,7 +1896,7 @@ ai-mem-search() {
1895
1896
  local -a patterns
1896
1897
  local w
1897
1898
  for w in $words; do patterns+=(-e "$w"); done
1898
- raw="$(grep -rniF --exclude-dir=.git --exclude-dir=_archive --exclude='_session_template.md' --exclude='_project_template.md' --exclude='_lesson_template.md' "${patterns[@]}" "$search_root" 2>/dev/null)"
1899
+ raw="$(grep -rniF --exclude-dir=.git --exclude-dir=_archive --exclude-dir=.ai-mem --exclude='_session_template.md' --exclude='_project_template.md' --exclude='_lesson_template.md' "${patterns[@]}" "$search_root" 2>/dev/null)"
1899
1900
  else
1900
1901
  words=()
1901
1902
  fi
@@ -2023,6 +2024,7 @@ ai-mem-search() {
2023
2024
  print -r -- "$shown" \
2024
2025
  | sed "s|^${search_root}/||" \
2025
2026
  | awk '{ if (length($0) > 200) print substr($0, 1, 200) " [...]"; else print }'
2027
+ [[ -z "$project" ]] && __ai_mem_log_recall "$term" "$shown"
2026
2028
 
2027
2029
  local shown_n
2028
2030
  shown_n="$(print -r -- "$shown" | wc -l | tr -d ' ')"
@@ -2135,3 +2137,88 @@ __ai_mem_search_rank_words() {
2135
2137
  }
2136
2138
  }' <(print -r -- "$strengths") <(print -r -- "$raw") | sort -r | cut -d'|' -f7-
2137
2139
  }
2140
+
2141
+ # Append one line per lesson that a whole-vault search SHOWED to the caller
2142
+ # (not every match: a hidden hit was not recalled). ai-mem-recall reads this to
2143
+ # answer the question the vault could not answer before: when a problem came
2144
+ # back, had the agent found the lesson for it? Columns, tab-separated:
2145
+ # local time (YYYY-MM-DD HH:MM), epoch seconds, active project, slug, query.
2146
+ # Best-effort: a write failure never fails the search. The file lives in
2147
+ # .ai-mem/, which search, lint and the graph viewer all skip.
2148
+ # Args: <query> <shown result lines, absolute paths>.
2149
+ __ai_mem_log_recall() {
2150
+ local query="$1" shown="$2" slugs
2151
+ slugs="$(print -r -- "$shown" | awk -v pre="$AI_MEM_ROOT/_lessons/" '
2152
+ index($0, pre) == 1 { s = substr($0, length(pre) + 1); sub(/\.md:[0-9]+:.*/, "", s)
2153
+ if (s !~ /\// && !(s in seen)) { seen[s] = 1; print s } }')"
2154
+ [[ -n "$slugs" ]] || return 0
2155
+ zmodload zsh/datetime 2>/dev/null
2156
+ local dir="$AI_MEM_ROOT/.ai-mem" now epoch slug
2157
+ now="$(strftime '%Y-%m-%d %H:%M' "$EPOCHSECONDS")"; epoch="$EPOCHSECONDS"
2158
+ query="${${query//$'\t'/ }//$'\n'/ }"
2159
+ mkdir -p "$dir" 2>/dev/null || return 0
2160
+ for slug in ${(f)slugs}; do
2161
+ print -r -- "$now"$'\t'"$epoch"$'\t'"${AI_MEM_ACTIVE_PROJECT:-}"$'\t'"$slug"$'\t'"$query"
2162
+ done >> "$dir/recall.tsv" 2>/dev/null
2163
+ return 0
2164
+ }
2165
+
2166
+ # ai-mem-recall: does the memory get used? Reads the recall log written by
2167
+ # ai-mem-search and the dated entries in _lessons/, from the first logged
2168
+ # search onward, and reports:
2169
+ # - how many lessons searches surfaced, of how many exist;
2170
+ # - each REPEAT entry (a second or later entry in an existing lesson, i.e.
2171
+ # the same problem came back): was that lesson shown by a search in the
2172
+ # 24 hours before the entry was written? "found" means the memory did its
2173
+ # job of surfacing the answer. "not found" means the answer was in the
2174
+ # vault but the agent never saw it -- a recall miss, the number to drive
2175
+ # down. Whether a found lesson then helped cannot be read from files.
2176
+ # ponytail: a fixed 24h window stands in for "the same session"; a session
2177
+ # id in both the log and the lesson entry is the upgrade if the window misleads.
2178
+ ai-mem-recall() {
2179
+ __ai_mem_paths
2180
+ zmodload zsh/datetime 2>/dev/null
2181
+ local log="$AI_MEM_ROOT/.ai-mem/recall.tsv"
2182
+ if [[ ! -s "$log" ]]; then
2183
+ print -r -- "ai-mem-recall: no searches logged yet. ai-mem-search records each lesson it shows; run this again after some sessions."
2184
+ return 0
2185
+ fi
2186
+ local start
2187
+ start="$(head -1 "$log" | cut -f1)"
2188
+ # Dated entries since logging began: <slug> <entry index> <YYYY-MM-DD HH:MM>.
2189
+ local -a rows
2190
+ rows=( ${(f)"$(find "$AI_MEM_ROOT/_lessons" -maxdepth 1 -name '*.md' ! -name '_lesson_template.md' -exec awk -v start="$start" '
2191
+ FNR == 1 { n = 0; s = FILENAME; sub(/.*\//, "", s); sub(/\.md$/, "", s) }
2192
+ /^## [0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-9][0-9]:[0-9][0-9]/ {
2193
+ n++; t = substr($0, 4, 16); if (t >= start) print s "\t" n "\t" t; next }
2194
+ /^## [0-9]/ { n++ }
2195
+ ' {} + 2>/dev/null)"} )
2196
+ local row t
2197
+ local entries=""
2198
+ for row in $rows; do
2199
+ t="${row##*$'\t'}"
2200
+ entries+="$row"$'\t'"$(strftime -r '%Y-%m-%d %H:%M' "$t" 2>/dev/null || print 0)"$'\n'
2201
+ done
2202
+ local total
2203
+ total="$(find "$AI_MEM_ROOT/_lessons" -maxdepth 1 -name '*.md' ! -name '_lesson_template.md' | wc -l | tr -d ' ')"
2204
+ awk -F'\t' -v total="$total" -v start="$start" '
2205
+ FNR == NR { if ($4 != "") { surfaced[$4] = 1; at[$4, ++k[$4]] = $2; searches[$2 "\t" $5] = 1 } next }
2206
+ $1 == "" { next }
2207
+ $2 == 1 { new++; next }
2208
+ {
2209
+ rep++; hit = 0
2210
+ # +60: entry times are whole minutes, so a search in the same
2211
+ # minute can carry a later epoch than the entry heading.
2212
+ for (i = 1; i <= k[$1]; i++) if (at[$1, i] <= $4 + 60 && at[$1, i] >= $4 - 86400) { hit = 1; break }
2213
+ if (hit) found++; else { missed++; miss = miss "\n " $1 " (" $3 ")" }
2214
+ }
2215
+ END {
2216
+ ns = 0; for (s in searches) ns++
2217
+ nl = 0; for (s in surfaced) nl++
2218
+ print "recall since " start " (first logged search)"
2219
+ print " searches that showed a lesson: " ns "; lessons shown: " nl " of " total
2220
+ print " lesson entries written since: " new + rep " (" new + 0 " new lesson(s), " rep + 0 " repeat(s) of an existing lesson)"
2221
+ if (rep) print " repeats found by a search in the 24h before: " found + 0 " of " rep "; not found (recall misses): " missed + 0
2222
+ if (missed) print "recall misses -- the lesson existed but no search showed it:" miss
2223
+ }' "$log" <(print -rn -- "$entries")
2224
+ }