create-ai-memory 0.18.0 → 0.18.2
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 +3 -3
- package/bin/ai-mem-serve.js +9 -2
- package/package.json +1 -1
- package/shell/ai-mem.zsh +81 -34
package/README.md
CHANGED
|
@@ -95,7 +95,7 @@ sequenceDiagram
|
|
|
95
95
|
Note over Vault: nothing overwritten -- a fresh file every session
|
|
96
96
|
Note over Sleep: overnight, unattended -- installed by ai-mem-sleep-schedule
|
|
97
97
|
Sleep->>Vault: archive unfilled logs after a day, logs older than 90d (newest 5 filled kept)
|
|
98
|
-
Sleep->>Vault: lint links,
|
|
98
|
+
Sleep->>Vault: lint links, rank links to unwritten notes, flag consolidation candidates
|
|
99
99
|
Sleep->>Backup: commit + push the archive move, if the vault is git-backed
|
|
100
100
|
Note over Vault,Sleep: _lessons/ are never archived and never pruned
|
|
101
101
|
You->>Shell: claude-start (next time)
|
|
@@ -316,7 +316,7 @@ optional. Set `AI_MEM_ROOT` in `~/.zshrc` first if you do not want the default
|
|
|
316
316
|
| `ai-lesson <topic-slug> <problem> <solution>` | Append a dated Problem/Solution entry to a cross-project `_lessons/<topic-slug>.md` -- decisions, mistakes, solutions worth recalling outside the current project |
|
|
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
|
-
| `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, notes missing the `type:` field
|
|
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
320
|
| `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
321
|
| `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
322
|
| `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 |
|
|
@@ -554,7 +554,7 @@ away what was hard to learn.
|
|
|
554
554
|
| **Strengthen** | A lesson recalled again ranks higher, not just newer -- long-term potentiation for the vault. | `ai-mem-search` ranking |
|
|
555
555
|
| **Consolidate** | Many session logs about one thing distil into a single durable lesson. | `ai-lesson` |
|
|
556
556
|
| **Decay** | Old session logs move out of the hot search path into `_archive/`, still on disk and in git. Unfilled logs go after a day. | `ai-mem-sleep` |
|
|
557
|
-
| **Prune (detect)** |
|
|
557
|
+
| **Prune (detect)** | Links to notes not written yet are ranked by how many notes link to them, never auto-removed. | `ai-mem-lint` |
|
|
558
558
|
| **Schedule** | Run the whole pass nightly on its own. | `ai-mem-sleep-schedule` |
|
|
559
559
|
|
|
560
560
|
**One rule is inviolable: a lesson is never pruned.** The failure-to-fix records
|
package/bin/ai-mem-serve.js
CHANGED
|
@@ -124,6 +124,10 @@ function titleOf(text, path, fm, h1Counts) {
|
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
const LINK_RE = /\[\[([^\]|#]+)/g;
|
|
127
|
+
// Code is not prose: a shell test such as [[ -n $X ]] inside `inline code` or
|
|
128
|
+
// a fenced block looks like a wikilink. Same rule as ai-mem-lint, including a
|
|
129
|
+
// fence that never closes, which runs to the end of the note (as in Obsidian).
|
|
130
|
+
const CODE_RE = /^[ \t]*(```|~~~)[^\n]*(?:\n[\s\S]*?^[ \t]*\1[^\n]*$|[\s\S]*$(?![\s\S]))|`[^`\n]*`/gm;
|
|
127
131
|
|
|
128
132
|
/**
|
|
129
133
|
* Build the graph.
|
|
@@ -171,7 +175,9 @@ function buildGraph() {
|
|
|
171
175
|
return 0;
|
|
172
176
|
}
|
|
173
177
|
})(),
|
|
174
|
-
links: [...text.
|
|
178
|
+
links: [...text.replace(CODE_RE, '').matchAll(LINK_RE)]
|
|
179
|
+
.map((m) => m[1].trim())
|
|
180
|
+
.filter((l) => !l.includes('{{')),
|
|
175
181
|
};
|
|
176
182
|
nodes.push(node);
|
|
177
183
|
// First writer wins: a duplicate basename is ambiguous in Obsidian too.
|
|
@@ -187,7 +193,8 @@ function buildGraph() {
|
|
|
187
193
|
// mark which notes carry a broken link without inventing targets for them.
|
|
188
194
|
const danglingSeen = new Set();
|
|
189
195
|
for (const link of n.links) {
|
|
190
|
-
|
|
196
|
+
// A folder path ([[_idea/x]], [[../dir/x]]) resolves by its last segment.
|
|
197
|
+
const target = byBasename.get(link) || byBasename.get(link.split('/').pop());
|
|
191
198
|
if (!target) {
|
|
192
199
|
if (link && link !== basename(n.id, '.md')) danglingSeen.add(link);
|
|
193
200
|
continue;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-ai-memory",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.2",
|
|
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
|
@@ -1098,6 +1098,8 @@ __ai_mem_current_project() {
|
|
|
1098
1098
|
# Create a global (GUI/MCP) session log at $1 if it does not exist yet. Global
|
|
1099
1099
|
# logs are created lazily, on the first write, so a read-only conversation
|
|
1100
1100
|
# leaves no empty note behind. `previous:` links the newest log with content.
|
|
1101
|
+
# `project:` links the project note, as in a terminal session log: without it
|
|
1102
|
+
# ai-mem-lint reports the log as orphaned and the graph shows it unconnected.
|
|
1101
1103
|
__ai_mem_create_global_log() {
|
|
1102
1104
|
local session_note="$1" project_name="$2" previous prev_link=""
|
|
1103
1105
|
[[ -f "$session_note" ]] && return 0
|
|
@@ -1105,7 +1107,8 @@ __ai_mem_create_global_log() {
|
|
|
1105
1107
|
previous="$(__ai_mem_latest_session_log "$project_name")" || return 1
|
|
1106
1108
|
[[ -n "$previous" ]] && prev_link="[[${previous:t:r}]]"
|
|
1107
1109
|
mkdir -p "${session_note:h}"
|
|
1108
|
-
print -rl -- "---" "type: ai-global-session" "date: $(date +%Y-%m-%d)" "
|
|
1110
|
+
print -rl -- "---" "type: ai-global-session" "date: $(date +%Y-%m-%d)" "project: \"[[$project_name]]\"" \
|
|
1111
|
+
"previous: \"$prev_link\"" "---" "" "# Global Session Notes" > "$session_note"
|
|
1109
1112
|
}
|
|
1110
1113
|
|
|
1111
1114
|
__ai_mem_today_session_log() {
|
|
@@ -1216,6 +1219,22 @@ ai-lesson() {
|
|
|
1216
1219
|
|
|
1217
1220
|
local project_name lesson_file timestamp
|
|
1218
1221
|
project_name="$(__ai_mem_current_project)" || return 1
|
|
1222
|
+
# Run from inside the vault, the project resolves to the vault's own repo
|
|
1223
|
+
# or folder name: on a real vault 36 lesson entries were tagged with the
|
|
1224
|
+
# vault repo's name, a project that does not exist. Inside the vault, use
|
|
1225
|
+
# the active session's project, or refuse rather than guess.
|
|
1226
|
+
if [[ -z "${AI_MEM_FORCE_PROJECT:-}" ]]; then
|
|
1227
|
+
local here_root vault_root
|
|
1228
|
+
here_root="$(git rev-parse --show-toplevel 2>/dev/null)"
|
|
1229
|
+
vault_root="$(git -C "$AI_MEM_ROOT" rev-parse --show-toplevel 2>/dev/null)"
|
|
1230
|
+
if [[ "${PWD:A}/" == "${AI_MEM_ROOT:A}/"* || ( -n "$here_root" && "$here_root" == "$vault_root" ) ]]; then
|
|
1231
|
+
if [[ -z "${AI_MEM_ACTIVE_PROJECT:-}" ]]; then
|
|
1232
|
+
echo "ai-lesson: run from inside the memory vault, so the project is unknown. Run it from the project's repo, or set AI_MEM_ACTIVE_PROJECT=<project>." >&2
|
|
1233
|
+
return 1
|
|
1234
|
+
fi
|
|
1235
|
+
project_name="$AI_MEM_ACTIVE_PROJECT"
|
|
1236
|
+
fi
|
|
1237
|
+
fi
|
|
1219
1238
|
lesson_file="$AI_MEM_ROOT/_lessons/${slug}.md"
|
|
1220
1239
|
timestamp="$(date '+%Y-%m-%d %H:%M')"
|
|
1221
1240
|
|
|
@@ -1388,7 +1407,9 @@ ai-mem-lint() {
|
|
|
1388
1407
|
__ai_mem_paths
|
|
1389
1408
|
local fix=0
|
|
1390
1409
|
[[ "${1:-}" == "--fix" ]] && fix=1
|
|
1391
|
-
local
|
|
1410
|
+
# Declared once here: re-declaring a set local (`local pname` inside a
|
|
1411
|
+
# loop or a later block) makes zsh print "pname=value" to stdout.
|
|
1412
|
+
local issues=0 f label target pname otmp
|
|
1392
1413
|
# Open Knowledge Format names exactly one required frontmatter field:
|
|
1393
1414
|
# `type`. Every note the vault ships already declares one except session
|
|
1394
1415
|
# logs, which predate the field -- so a vault that has been in use carries
|
|
@@ -1413,7 +1434,11 @@ ai-mem-lint() {
|
|
|
1413
1434
|
# ai-mem-sleep moves older logs into the project's _archive/, and
|
|
1414
1435
|
# Obsidian resolves a link by basename anywhere in the vault. A
|
|
1415
1436
|
# link to an archived log still opens, so it is not dangling.
|
|
1416
|
-
|
|
1437
|
+
# A project renamed mid-history links its first log to a log in
|
|
1438
|
+
# the old project's folder; Obsidian resolves that by basename,
|
|
1439
|
+
# so look vault-wide before calling it dangling (rare, so cheap).
|
|
1440
|
+
if [[ ! -f "${f:h}/${target}.md" && ! -f "${f:h}/_archive/${target}.md" \
|
|
1441
|
+
&& -z "$(find "$AI_MEM_SESSION_DIR" -name "${target}.md" -print -quit 2>/dev/null)" ]]; then
|
|
1417
1442
|
print -r -- "dangling previous link: $f -> [[${target}]] (not found)"
|
|
1418
1443
|
(( issues++ ))
|
|
1419
1444
|
fi
|
|
@@ -1422,7 +1447,7 @@ ai-mem-lint() {
|
|
|
1422
1447
|
|
|
1423
1448
|
while IFS= read -r -d '' f; do
|
|
1424
1449
|
[[ "${f:t}" == "_project_template.md" ]] && continue
|
|
1425
|
-
|
|
1450
|
+
pname="${f:t:r}"
|
|
1426
1451
|
if ! grep -rq -- "\[\[${pname}\]\]" "$AI_MEM_SESSION_DIR" 2>/dev/null; then
|
|
1427
1452
|
print -r -- "unreferenced project note (no session log links to it): $f"
|
|
1428
1453
|
(( issues++ ))
|
|
@@ -1464,7 +1489,6 @@ ai-mem-lint() {
|
|
|
1464
1489
|
done < <(find "$AI_MEM_SESSION_DIR" -maxdepth 2 -name "*.md" -print0 2>/dev/null)
|
|
1465
1490
|
|
|
1466
1491
|
if (( $#orphan_files && fix )); then
|
|
1467
|
-
local pname otmp
|
|
1468
1492
|
for f in $orphan_files; do
|
|
1469
1493
|
__ai_mem_guard "$f" >/dev/null || continue
|
|
1470
1494
|
pname="$(grep -m1 '^project: ' "$f" | sed 's/^project: *//; s/^"//; s/"$//')"
|
|
@@ -1499,37 +1523,60 @@ ai-mem-lint() {
|
|
|
1499
1523
|
fi
|
|
1500
1524
|
|
|
1501
1525
|
|
|
1502
|
-
#
|
|
1503
|
-
#
|
|
1504
|
-
#
|
|
1505
|
-
#
|
|
1506
|
-
#
|
|
1526
|
+
# Links to notes not written yet: a [[target]] with no note of that name.
|
|
1527
|
+
# Obsidian treats these as intentional -- clicking one creates the note --
|
|
1528
|
+
# so they are reported as a ranked summary, NOT counted as issues. A target
|
|
1529
|
+
# linked from many notes is a missing hub worth writing; a target linked
|
|
1530
|
+
# once is a breadcrumb. On a real vault 206 of 220 lint issues were these
|
|
1531
|
+
# (people in meeting transcripts, projects without a note), and listing
|
|
1532
|
+
# each one as an error buried the 14 that were real. Wikilinks resolve by
|
|
1533
|
+
# basename (the same way ai-mem-serve draws them); a folder path
|
|
1534
|
+
# ([[_idea/x]], [[../dir/x]]) resolves by its last segment.
|
|
1535
|
+
#
|
|
1536
|
+
# Not links, so never counted: text inside `inline code` or a fenced code
|
|
1537
|
+
# block, where a shell test such as [[ -n $X ]] looks like a wikilink, and
|
|
1538
|
+
# {{placeholder}} targets in the note templates.
|
|
1507
1539
|
#
|
|
1508
|
-
# One
|
|
1509
|
-
# 25s antipattern ai-mem-search documents. Scope is the vault root
|
|
1510
|
-
# from AI_MEM_SESSION_DIR (its parent), the same subtree the rest
|
|
1511
|
-
# linter walks, so a caller that redirects the session dir
|
|
1540
|
+
# One awk pass over the vault, never a process per file -- a per-file scan
|
|
1541
|
+
# is the 25s antipattern ai-mem-search documents. Scope is the vault root
|
|
1542
|
+
# derived from AI_MEM_SESSION_DIR (its parent), the same subtree the rest
|
|
1543
|
+
# of this linter walks, so a caller that redirects the session dir
|
|
1544
|
+
# redirects this too.
|
|
1512
1545
|
local vault="${AI_MEM_SESSION_DIR:h}"
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1546
|
+
local known_file
|
|
1547
|
+
known_file="$(mktemp)"
|
|
1548
|
+
find "$vault" -name '*.md' -not -path '*/.git/*' 2>/dev/null \
|
|
1549
|
+
| awk '{ sub(/.*\//, ""); sub(/\.md$/, ""); print }' > "$known_file"
|
|
1550
|
+
local unwritten
|
|
1551
|
+
unwritten="$(find "$vault" -name '*.md' -not -path '*/.git/*' -exec awk -v kf="$known_file" '
|
|
1552
|
+
FILENAME == kf { known[$0] = 1; next }
|
|
1553
|
+
FNR == 1 { fence = 0 }
|
|
1554
|
+
/^[ \t]*(```|~~~)/ { fence = !fence; next }
|
|
1555
|
+
fence { next }
|
|
1556
|
+
{
|
|
1557
|
+
line = $0
|
|
1558
|
+
gsub(/`[^`]*`/, "", line)
|
|
1559
|
+
while (match(line, /\[\[[^\]]+\]\]/)) {
|
|
1560
|
+
t = substr(line, RSTART + 2, RLENGTH - 4)
|
|
1561
|
+
line = substr(line, RSTART + RLENGTH)
|
|
1562
|
+
sub(/\|.*/, "", t); sub(/#.*/, "", t)
|
|
1563
|
+
sub(/^ +/, "", t); sub(/ +$/, "", t)
|
|
1564
|
+
if (t == "" || index(t, "{{")) continue
|
|
1565
|
+
b = t; sub(/.*\//, "", b)
|
|
1566
|
+
if ((t in known) || (b in known)) continue
|
|
1567
|
+
print t
|
|
1568
|
+
}
|
|
1569
|
+
}' "$known_file" {} + 2>/dev/null)"
|
|
1570
|
+
rm -f "$known_file"
|
|
1571
|
+
if [[ -n "$unwritten" ]]; then
|
|
1572
|
+
# Most-linked first, ties by name; the top 10 only, with the total.
|
|
1573
|
+
local n_links n_targets top
|
|
1574
|
+
n_links="$(print -r -- "$unwritten" | wc -l | tr -d ' ')"
|
|
1575
|
+
n_targets="$(print -r -- "$unwritten" | sort -u | wc -l | tr -d ' ')"
|
|
1576
|
+
top="$(print -r -- "$unwritten" | sort | uniq -c | sort -k1,1nr -k2 | head -10 \
|
|
1577
|
+
| awk '{ c = $1; sub(/^ *[0-9]+ /, ""); printf "%s[[%s]] %s", (NR > 1 ? ", " : ""), $0, c }')"
|
|
1578
|
+
print -r -- "note: $n_links link(s) to $n_targets note(s) not written yet. Not errors -- Obsidian creates a note when its link is clicked. Write the most-linked first; find where one is used with: ai-mem-search '[[name]]'"
|
|
1579
|
+
print -r -- " most linked: $top"
|
|
1533
1580
|
fi
|
|
1534
1581
|
if (( issues == 0 )); then
|
|
1535
1582
|
print -r -- "ok: vault links are clean"
|