create-ai-memory 0.17.0 → 0.18.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 +9 -7
- package/bin/ai-mem-mcp.js +1 -1
- package/package.json +1 -1
- package/shell/ai-mem.zsh +139 -26
package/README.md
CHANGED
|
@@ -400,11 +400,13 @@ stemming, not fuzzy:
|
|
|
400
400
|
|
|
401
401
|
That last row is the limit: a misspelling finds nothing.
|
|
402
402
|
|
|
403
|
-
**Search
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
403
|
+
**Search a few distinctive words.** The exact phrase is tried first. If it
|
|
404
|
+
has no hits, each word is tried on its own, and notes that hold more of the
|
|
405
|
+
words rank first, so word order does not decide the result: on a real vault
|
|
406
|
+
`migration prisma` found **nothing** as a phrase, and now returns the Prisma
|
|
407
|
+
migration lessons first. Filler words (`the`, `how`, `not`…) are ignored. A
|
|
408
|
+
bare tool name like `sed` alone returns over 2,000 lines, so add a word from
|
|
409
|
+
the symptom.
|
|
408
410
|
|
|
409
411
|
**Token cost is bounded and flat:**
|
|
410
412
|
|
|
@@ -954,8 +956,8 @@ vault's session template predates the current one. Scaffolding only fills in
|
|
|
954
956
|
`ai-mem-lint --fix`.
|
|
955
957
|
|
|
956
958
|
**Search returns nothing for a term you are sure you wrote.**
|
|
957
|
-
|
|
958
|
-
|
|
959
|
+
Words match as literal substrings with no fuzzy matching, so a typo finds
|
|
960
|
+
zero. Use a few distinctive words rather than a whole error line — see
|
|
959
961
|
[what it costs](#what-it-costs-and-what-it-cannot-do).
|
|
960
962
|
|
|
961
963
|
## Why plain files
|
package/bin/ai-mem-mcp.js
CHANGED
|
@@ -165,7 +165,7 @@ const INSTRUCTIONS = [
|
|
|
165
165
|
readVaultNote('_Standards.md'),
|
|
166
166
|
'',
|
|
167
167
|
'get_context returns the loaded profile, standards, project context, and latest session digest. Its successful result is the context gate for this session.',
|
|
168
|
-
'search_memory may contain a prior solution. Search
|
|
168
|
+
'search_memory may contain a prior solution. Search a few distinctive words, not a whole sentence: the exact phrase is tried first, then each word, with notes holding more of them first.',
|
|
169
169
|
'',
|
|
170
170
|
'Write back with add_note for decisions, blockers, and next steps. Use add_lesson only for reusable knowledge that matters in a different project.',
|
|
171
171
|
'If the user asks to see or browse memory, call open_graph.',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-ai-memory",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.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
|
@@ -814,7 +814,7 @@ Treat the global profile and standards note as the shared baseline for every run
|
|
|
814
814
|
Keep durable preferences and project facts in the vault, and keep the active session log updated with decisions, blockers, and next steps.
|
|
815
815
|
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. Search is case-insensitive and matches literally, and its output is capped: if it reports results hidden, narrow with a project argument or a more specific term rather than assuming you have seen everything. Start broad and narrow from there -- a first query that is too specific is the usual way to miss what you were looking for.
|
|
816
816
|
When you hit a blocker -- an error you do not immediately understand, a test failing for an unclear reason, a decision you cannot settle from the code in front of you, or a second failed attempt at the same thing -- search the vault BEFORE guessing again. You have likely been here before, and \`_lessons/\` exists because the answer usually was written down; lessons are ranked above session logs in the results, so a hit under \`_lessons/\` is the recorded fix.
|
|
817
|
-
Search
|
|
817
|
+
Search a few distinctive words, not a whole sentence. The exact phrase is tried first. If it has no hits, each word is tried, and notes that hold more of the words rank first. A bare tool name alone ('sed', 'git') returns hundreds of irrelevant lines, so add a word from the symptom.
|
|
818
818
|
If the user asks to see, open or browse their memory rather than search it, run \`ai-mem-serve\` -- it opens the vault as a graph in their browser, and is safe to run again if it is already up.
|
|
819
819
|
When you hit a mistake, decision, or solution worth remembering across projects (not just this one), run \`ai-lesson <topic-slug> <problem> <solution>\` -- e.g. \`ai-lesson rate-limiting "a fixed-window limiter kept losing bursts of legitimate traffic" "switched to a token bucket, which absorbs bursts correctly"\`. It appends a dated Problem/Solution entry to a cross-project note at _lessons/<topic-slug>.md; ai-mem-search already covers it.
|
|
820
820
|
EOF
|
|
@@ -1833,8 +1833,33 @@ ai-mem-search() {
|
|
|
1833
1833
|
# stay in git and on disk, just not in a default search.
|
|
1834
1834
|
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)"
|
|
1835
1835
|
|
|
1836
|
+
# Exact phrase first, then each word. A multi-word term used to be one
|
|
1837
|
+
# literal phrase, so word order decided whether anything came back:
|
|
1838
|
+
# measured on a real vault, 'prisma migration' found 11 lines and
|
|
1839
|
+
# 'migration prisma' found 0, and 30 three-word queries built from real
|
|
1840
|
+
# lessons found their lesson 0 times out of 30. An agent cannot tell that
|
|
1841
|
+
# empty result from "never written down", so it solves the problem again.
|
|
1842
|
+
# Only a phrase with NO hits is widened, so every query that worked before
|
|
1843
|
+
# returns exactly what it returned before.
|
|
1844
|
+
local -a words
|
|
1836
1845
|
if [[ -z "$raw" ]]; then
|
|
1837
|
-
|
|
1846
|
+
words=(${(f)"$(__ai_mem_search_words "$term")"})
|
|
1847
|
+
if (( $#words >= 2 )); then
|
|
1848
|
+
local -a patterns
|
|
1849
|
+
local w
|
|
1850
|
+
for w in $words; do patterns+=(-e "$w"); done
|
|
1851
|
+
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)"
|
|
1852
|
+
else
|
|
1853
|
+
words=()
|
|
1854
|
+
fi
|
|
1855
|
+
fi
|
|
1856
|
+
|
|
1857
|
+
if [[ -z "$raw" ]]; then
|
|
1858
|
+
if (( $#words )); then
|
|
1859
|
+
print -r -- "no matches for '$term' in $search_root (also tried each word: ${(j:, :)words})"
|
|
1860
|
+
else
|
|
1861
|
+
print -r -- "no matches for '$term' in $search_root"
|
|
1862
|
+
fi
|
|
1838
1863
|
return 1
|
|
1839
1864
|
fi
|
|
1840
1865
|
|
|
@@ -1873,28 +1898,32 @@ ai-mem-search() {
|
|
|
1873
1898
|
[[ -z "$project" ]] && strengths="$(grep -rc '^## [0-9]' "$AI_MEM_ROOT/_lessons" 2>/dev/null)"
|
|
1874
1899
|
|
|
1875
1900
|
local sorted
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1901
|
+
if (( $#words )); then
|
|
1902
|
+
sorted="$(__ai_mem_search_rank_words "$search_root" "${(j: :)words}" "$strengths" "$raw")"
|
|
1903
|
+
else
|
|
1904
|
+
sorted="$(awk -v root="$search_root/" '
|
|
1905
|
+
# First input: <lesson-file-path>:<entry-count>. Build the strength map.
|
|
1906
|
+
FNR == NR {
|
|
1907
|
+
if (match($0, /:[0-9]+$/)) {
|
|
1908
|
+
str[substr($0, 1, RSTART - 1)] = substr($0, RSTART + 1) + 0
|
|
1909
|
+
}
|
|
1910
|
+
next
|
|
1881
1911
|
}
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
}' <(print -r -- "$strengths") <(print -r -- "$raw") | sort -r | cut -d'|' -f4-)"
|
|
1912
|
+
{
|
|
1913
|
+
ts = "0000-00-00_00-00-00"
|
|
1914
|
+
if (match($0, /[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]_[0-9][0-9]-[0-9][0-9]-[0-9][0-9]/))
|
|
1915
|
+
ts = substr($0, RSTART, RLENGTH)
|
|
1916
|
+
rel = $0
|
|
1917
|
+
sub(root, "", rel)
|
|
1918
|
+
is_lesson = (rel ~ /^_lessons\//)
|
|
1919
|
+
rank = is_lesson ? "1" : "0"
|
|
1920
|
+
# The file this match came from, to look up its reinforcement count.
|
|
1921
|
+
path = $0
|
|
1922
|
+
sub(/:[0-9]+:.*$/, "", path)
|
|
1923
|
+
strength = is_lesson ? sprintf("%03d", str[path] + 0) : "000"
|
|
1924
|
+
print rank "|" strength "|" ts "|" $0
|
|
1925
|
+
}' <(print -r -- "$strengths") <(print -r -- "$raw") | sort -r | cut -d'|' -f4-)"
|
|
1926
|
+
fi
|
|
1898
1927
|
|
|
1899
1928
|
# Bound the output. The consumer is normally an agent with a finite
|
|
1900
1929
|
# context window, and an unbounded dump is actively harmful there in a
|
|
@@ -1906,7 +1935,7 @@ ai-mem-search() {
|
|
|
1906
1935
|
# Count goes FIRST -- the reader needs the size of the result set before
|
|
1907
1936
|
# the result set, not after it.
|
|
1908
1937
|
local total limit per_file
|
|
1909
|
-
total="$(print -r -- "$
|
|
1938
|
+
total="$(print -r -- "$sorted" | wc -l | tr -d ' ')"
|
|
1910
1939
|
limit="${AI_MEM_SEARCH_LIMIT:-25}"
|
|
1911
1940
|
per_file="${AI_MEM_SEARCH_PER_FILE:-1}"
|
|
1912
1941
|
|
|
@@ -1932,7 +1961,11 @@ ai-mem-search() {
|
|
|
1932
1961
|
files_shown="$(print -r -- "$spread" | head -n "$limit" | awk '
|
|
1933
1962
|
{ f = $0; sub(/:[0-9]+:.*$/, "", f); seen[f] = 1 } END { print length(seen) }')"
|
|
1934
1963
|
|
|
1935
|
-
|
|
1964
|
+
if (( $#words )); then
|
|
1965
|
+
print -r -- "$total match(es) for any of: ${(j: :)words} (no exact match for '$term'; notes matching more of the words rank first)"
|
|
1966
|
+
else
|
|
1967
|
+
print -r -- "$total match(es) for '$term'"
|
|
1968
|
+
fi
|
|
1936
1969
|
print -r -- "paths below $search_root"
|
|
1937
1970
|
print -r -- "--"
|
|
1938
1971
|
# Strip the repeated vault root (a third to a half of all output bytes on
|
|
@@ -1960,7 +1993,7 @@ ai-mem-search() {
|
|
|
1960
1993
|
# excerpt, so a match doesn't leave you to manually chase the link
|
|
1961
1994
|
# yourself.
|
|
1962
1995
|
local links link target excerpt
|
|
1963
|
-
links="$(print -r -- "$
|
|
1996
|
+
links="$(print -r -- "$sorted" | grep -oE '\[\[[^]]+\]\]' | sed -E 's/^\[\[|\]\]$//g' | sort -u)"
|
|
1964
1997
|
[[ -n "$links" ]] || return 0
|
|
1965
1998
|
|
|
1966
1999
|
print -r -- "--"
|
|
@@ -1975,3 +2008,83 @@ ai-mem-search() {
|
|
|
1975
2008
|
[[ -n "$excerpt" ]] && print -r -- " $excerpt"
|
|
1976
2009
|
done <<< "$links"
|
|
1977
2010
|
}
|
|
2011
|
+
|
|
2012
|
+
# Content words of a search term, lowercased, deduplicated, one per line.
|
|
2013
|
+
# Edge punctuation is stripped ("found:" -> "found") but inner punctuation
|
|
2014
|
+
# stays, so "app.module.ts" and "ai-mem-search" remain single words. Filler
|
|
2015
|
+
# words are dropped: they match nearly every note and would outvote the
|
|
2016
|
+
# words that carry the question.
|
|
2017
|
+
__ai_mem_search_words() {
|
|
2018
|
+
local -a stop out
|
|
2019
|
+
stop=(a an and are as at be but by can do does did for from has have how i
|
|
2020
|
+
if in is it its me my no not of on or our so that the their then there
|
|
2021
|
+
this to was we were what when where which who why will with you your)
|
|
2022
|
+
local w
|
|
2023
|
+
for w in ${=1}; do
|
|
2024
|
+
w="${(L)w}"
|
|
2025
|
+
while [[ -n "$w" && "$w" == [^[:alnum:]]* ]]; do w="${w#?}"; done
|
|
2026
|
+
while [[ -n "$w" && "$w" == *[^[:alnum:]] ]]; do w="${w%?}"; done
|
|
2027
|
+
[[ -n "$w" ]] || continue
|
|
2028
|
+
(( ${stop[(Ie)$w]} )) && continue
|
|
2029
|
+
(( ${out[(Ie)$w]} )) && continue
|
|
2030
|
+
out+=("$w")
|
|
2031
|
+
done
|
|
2032
|
+
print -rl -- $out
|
|
2033
|
+
}
|
|
2034
|
+
|
|
2035
|
+
# Rank grep lines that match ANY of the words, for ai-mem-search's widened
|
|
2036
|
+
# pass. Prints the same <path>:<line>:<text> lines, best first:
|
|
2037
|
+
# 1. how many of the words the note contains (coverage, per note),
|
|
2038
|
+
# 2. lessons above everything else (same tier rule as the phrase search),
|
|
2039
|
+
# 3. the summed rarity (IDF) of the words the note contains, so a note
|
|
2040
|
+
# holding one rare word beats one holding a word every note has,
|
|
2041
|
+
# 4. lesson reinforcement, then recency, then words on the line itself.
|
|
2042
|
+
# Notes matching fewer than half of the words are dropped, unless no note
|
|
2043
|
+
# reaches half, so a long question still returns its best partial match.
|
|
2044
|
+
# Args: <search-root> <space-separated words> <strength lines> <grep lines>.
|
|
2045
|
+
__ai_mem_search_rank_words() {
|
|
2046
|
+
local root="$1" words="$2" strengths="$3" raw="$4"
|
|
2047
|
+
local notes
|
|
2048
|
+
notes="$(find "$root" -name '*.md' -not -path '*/.git/*' -not -path '*/_archive/*' 2>/dev/null | wc -l | tr -d ' ')"
|
|
2049
|
+
awk -v root="$root/" -v words="$words" -v N="$notes" '
|
|
2050
|
+
BEGIN { nw = split(words, W, " ") }
|
|
2051
|
+
FNR == NR {
|
|
2052
|
+
if (match($0, /:[0-9]+$/)) str[substr($0, 1, RSTART - 1)] = substr($0, RSTART + 1) + 0
|
|
2053
|
+
next
|
|
2054
|
+
}
|
|
2055
|
+
{
|
|
2056
|
+
if (!match($0, /:[0-9]+:/)) next
|
|
2057
|
+
path = substr($0, 1, RSTART - 1)
|
|
2058
|
+
text = tolower(substr($0, RSTART + RLENGTH))
|
|
2059
|
+
c = 0
|
|
2060
|
+
for (i = 1; i <= nw; i++) {
|
|
2061
|
+
if (!index(text, W[i])) continue
|
|
2062
|
+
c++
|
|
2063
|
+
if (!((path, i) in has)) { has[path, i] = 1; df[i]++; cov[path]++ }
|
|
2064
|
+
}
|
|
2065
|
+
if (!c) next
|
|
2066
|
+
n++; L[n] = $0; LP[n] = path; LC[n] = c
|
|
2067
|
+
}
|
|
2068
|
+
END {
|
|
2069
|
+
best = 0
|
|
2070
|
+
for (p in cov) if (cov[p] > best) best = cov[p]
|
|
2071
|
+
need = int((nw + 1) / 2)
|
|
2072
|
+
if (need > best) need = best
|
|
2073
|
+
for (i = 1; i <= nw; i++) idf[i] = log(1 + N / (df[i] ? df[i] : 1))
|
|
2074
|
+
for (p in cov) {
|
|
2075
|
+
s = 0
|
|
2076
|
+
for (i = 1; i <= nw; i++) if ((p, i) in has) s += idf[i]
|
|
2077
|
+
score[p] = s
|
|
2078
|
+
}
|
|
2079
|
+
for (k = 1; k <= n; k++) {
|
|
2080
|
+
p = LP[k]
|
|
2081
|
+
if (cov[p] < need) continue
|
|
2082
|
+
rel = p; sub(root, "", rel)
|
|
2083
|
+
lesson = (rel ~ /^_lessons\//) ? 1 : 0
|
|
2084
|
+
ts = "0000-00-00_00-00-00"
|
|
2085
|
+
if (match(p, /[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]_[0-9][0-9]-[0-9][0-9]-[0-9][0-9]/))
|
|
2086
|
+
ts = substr(p, RSTART, RLENGTH)
|
|
2087
|
+
printf "%02d|%d|%09.4f|%03d|%s|%02d|%s\n", cov[p], lesson, score[p], lesson ? str[p] + 0 : 0, ts, LC[k], L[k]
|
|
2088
|
+
}
|
|
2089
|
+
}' <(print -r -- "$strengths") <(print -r -- "$raw") | sort -r | cut -d'|' -f7-
|
|
2090
|
+
}
|