create-ai-memory 0.16.0 → 0.16.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 +5 -0
- package/bin/ai-mem-mcp.js +29 -5
- package/package.json +1 -1
- package/shell/adapters.zsh +3 -1
- package/shell/ai-mem.zsh +93 -24
package/README.md
CHANGED
|
@@ -817,6 +817,11 @@ a standing brief (read context first, search before solving, write back after)
|
|
|
817
817
|
-- without it a model has no reason to suspect a memory exists. Tool
|
|
818
818
|
descriptions stay terse because schemas are re-sent every turn.
|
|
819
819
|
|
|
820
|
+
A GUI session log is created by the first write, not by a read. Each MCP
|
|
821
|
+
server keeps one log path for its lifetime; `add_note` (or an agent that
|
|
822
|
+
writes the session outcome) creates the file there. A conversation that only
|
|
823
|
+
reads context leaves no empty note in the vault.
|
|
824
|
+
|
|
820
825
|
**Do not register this for a terminal agent.** Claude Code, Codex, Gemini and
|
|
821
826
|
opencode have a shell and should call `ai-mem-search` directly.
|
|
822
827
|
|
package/bin/ai-mem-mcp.js
CHANGED
|
@@ -43,6 +43,22 @@ const VERSION = (() => {
|
|
|
43
43
|
}
|
|
44
44
|
})();
|
|
45
45
|
|
|
46
|
+
/**
|
|
47
|
+
* The global session log this server writes to, pinned for its lifetime.
|
|
48
|
+
*
|
|
49
|
+
* Every zsh call is a fresh process, so the path the module picks on
|
|
50
|
+
* `initialize` would be lost by the next call. Pinning it keeps one server
|
|
51
|
+
* on one log. The file itself is created by the first write, so a
|
|
52
|
+
* conversation that only reads leaves no empty note in the vault.
|
|
53
|
+
*/
|
|
54
|
+
let sessionLog = '';
|
|
55
|
+
|
|
56
|
+
/** Remember the "Active session log" path from an ai-context result. */
|
|
57
|
+
function pinSessionLog(text) {
|
|
58
|
+
const m = /^- Active session log: (.+?\.md)(?: -- |$)/m.exec(text || '');
|
|
59
|
+
if (m) sessionLog = m[1];
|
|
60
|
+
}
|
|
61
|
+
|
|
46
62
|
/**
|
|
47
63
|
* Run a zsh snippet with the module sourced, and return its output.
|
|
48
64
|
*
|
|
@@ -65,6 +81,9 @@ function zsh(snippet) {
|
|
|
65
81
|
AI_MEM_FORCE_PROJECT: GUI_PROJECT,
|
|
66
82
|
AI_MEM_GLOBALIZE_ROOT: GUI_ROOT,
|
|
67
83
|
AI_MEM_GLOBAL_SESSION: '1',
|
|
84
|
+
// Always set, so a project log exported by a parent *-start shell is
|
|
85
|
+
// never mistaken for this GUI session.
|
|
86
|
+
AI_MEM_ACTIVE_SESSION_LOG: sessionLog,
|
|
68
87
|
},
|
|
69
88
|
maxBuffer: 8 * 1024 * 1024,
|
|
70
89
|
});
|
|
@@ -220,8 +239,12 @@ function callTool(name, args = {}) {
|
|
|
220
239
|
switch (name) {
|
|
221
240
|
case 'search_memory':
|
|
222
241
|
return zsh(`ai-mem-search ${q(args.term)} ${args.project ? q(args.project) : ''}`);
|
|
223
|
-
case 'get_context':
|
|
224
|
-
|
|
242
|
+
case 'get_context': {
|
|
243
|
+
const project = args.project || GUI_PROJECT;
|
|
244
|
+
const result = zsh(`ai-context ${q(project)}`);
|
|
245
|
+
if (result.ok && project === GUI_PROJECT) pinSessionLog(result.text);
|
|
246
|
+
return result;
|
|
247
|
+
}
|
|
225
248
|
// ai-note and ai-lesson both push the vault themselves, so a GUI write is
|
|
226
249
|
// committed and backed up exactly like a terminal one -- no separate step
|
|
227
250
|
// for the model to forget.
|
|
@@ -267,9 +290,10 @@ function handle(req) {
|
|
|
267
290
|
if (id === undefined) return;
|
|
268
291
|
|
|
269
292
|
if (method === 'initialize') {
|
|
270
|
-
// Initialize is the GUI equivalent of a CLI launcher:
|
|
271
|
-
// session log even if the model never
|
|
272
|
-
|
|
293
|
+
// Initialize is the GUI equivalent of a CLI launcher: load the context and
|
|
294
|
+
// pin this server's global session log even if the model never calls a
|
|
295
|
+
// tool first. The log file is created by the first write, not here.
|
|
296
|
+
pinSessionLog(zsh(`ai-context ${q(GUI_PROJECT)}`).text);
|
|
273
297
|
return send({
|
|
274
298
|
jsonrpc: '2.0',
|
|
275
299
|
id,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-ai-memory",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.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/adapters.zsh
CHANGED
|
@@ -204,8 +204,10 @@ __ai_adapter_omp() {
|
|
|
204
204
|
export PATH="$ai_mem_bin:$PATH"
|
|
205
205
|
system_prompt+=$'\nUse the executable ai-mem-search for vault searches. Do not glob or read session-log files directly when answering memory questions; use ai-mem-search so project scope, archived-log filtering, ranking, and output limits remain correct.'
|
|
206
206
|
fi
|
|
207
|
+
# Research uses two sources: the ai-internet-search CLI for the authoritative
|
|
208
|
+
# core and the harness's built-in web search for breadth.
|
|
207
209
|
if command -v ai-internet-search >/dev/null 2>&1; then
|
|
208
|
-
system_prompt+=$'\
|
|
210
|
+
system_prompt+=$'\nFor explicit web research and current or uncertain external facts, use two sources every time: run ai-internet-search for the authoritative core, and run the built-in web search for breadth. Tell the user which facts came from each source.'
|
|
209
211
|
fi
|
|
210
212
|
if [[ -n "$mode_block" ]]; then
|
|
211
213
|
system_prompt+=$'\n\nActive local skill instructions:\n'
|
package/shell/ai-mem.zsh
CHANGED
|
@@ -356,7 +356,7 @@ __ai_mem_latest_session_log() {
|
|
|
356
356
|
latest="$(awk '
|
|
357
357
|
FNR == 1 { fm = ($0 == "---"); if (fm) next }
|
|
358
358
|
fm { if ($0 == "---") fm = 0; next }
|
|
359
|
-
/^[[:space:]]*$/ || $0 == "# Session Outcome" || /^\* \*\*[^*]+:\*\*[[:space:]]*\[.*\]$/ { next }
|
|
359
|
+
/^[[:space:]]*$/ || $0 == "# Session Outcome" || $0 == "# Global Session Notes" || /^\* \*\*[^*]+:\*\*[[:space:]]*\[.*\]$/ { next }
|
|
360
360
|
{ print FILENAME; exit }
|
|
361
361
|
' "${(@f)logs}" 2>/dev/null)" || true
|
|
362
362
|
[[ -n "$latest" ]] || latest="${logs%%$'\n'*}"
|
|
@@ -472,30 +472,38 @@ __ai_mem_prepare_session() {
|
|
|
472
472
|
"$AI_MEM_PROJECT_DIR/_project_template.md" > "$project_note"
|
|
473
473
|
fi
|
|
474
474
|
|
|
475
|
-
# A blank note with this second's timestamp belongs to a separate session.
|
|
476
|
-
# Wait for the next timestamp instead of overwriting its previous-session
|
|
477
|
-
# link. A note with Live Notes is the active GUI/CLI session and must be
|
|
478
|
-
# reused.
|
|
479
|
-
if [[ -f "$session_note" ]] && ! grep -q '^### Live Notes' "$session_note" 2>/dev/null; then
|
|
480
|
-
while [[ -f "$session_note" ]]; do
|
|
481
|
-
sleep 1
|
|
482
|
-
session_stamp="$(date +%Y-%m-%d_%H-%M-%S)"
|
|
483
|
-
session_note="$project_session_dir/${project_name}-${session_stamp}.md"
|
|
484
|
-
done
|
|
485
|
-
fi
|
|
486
|
-
|
|
487
475
|
local prev_link=""
|
|
488
476
|
if [[ -n "$previous_session_note" ]]; then
|
|
489
477
|
prev_link="[[${previous_session_note:t:r}]]"
|
|
490
478
|
fi
|
|
491
479
|
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
480
|
+
if (( global_session )); then
|
|
481
|
+
# GUI clients start the MCP server (initialize reads context) and then
|
|
482
|
+
# call get_context before almost every answer. Writing a skeleton on
|
|
483
|
+
# each read left ~290 empty notes in a week, chained into a strand of
|
|
484
|
+
# junk in the graph. So a global log is only a PATH here: the MCP
|
|
485
|
+
# server pins it in AI_MEM_ACTIVE_SESSION_LOG for its lifetime, and
|
|
486
|
+
# the file is created by the first write (ai-note, or an agent that
|
|
487
|
+
# writes the session outcome). A read-only conversation leaves nothing.
|
|
488
|
+
local active="${AI_MEM_ACTIVE_SESSION_LOG:-}"
|
|
489
|
+
if [[ "$active" == "$project_session_dir/${project_name}-$(date +%Y-%m-%d)_"*.md ]]; then
|
|
490
|
+
session_note="$active"
|
|
491
|
+
fi
|
|
492
|
+
else
|
|
493
|
+
# A blank note with this second's timestamp belongs to a separate
|
|
494
|
+
# session. Wait for the next timestamp instead of overwriting its
|
|
495
|
+
# previous-session link. A note with Live Notes is the active CLI
|
|
496
|
+
# session and must be reused.
|
|
497
|
+
if [[ -f "$session_note" ]] && ! grep -q '^### Live Notes' "$session_note" 2>/dev/null; then
|
|
498
|
+
while [[ -f "$session_note" ]]; do
|
|
499
|
+
sleep 1
|
|
500
|
+
session_stamp="$(date +%Y-%m-%d_%H-%M-%S)"
|
|
501
|
+
session_note="$project_session_dir/${project_name}-${session_stamp}.md"
|
|
502
|
+
done
|
|
503
|
+
fi
|
|
504
|
+
# Context reads can follow a write in the same second. Reusing an
|
|
505
|
+
# existing timestamped note preserves Live Notes and any other append.
|
|
506
|
+
if [[ ! -f "$session_note" ]]; then
|
|
499
507
|
SESSION_DATE="$(date +%Y-%m-%d)" PROJECT_NAME="$project_name" PREV_LINK="$prev_link" perl -0pe 's/\{\{date\}\}/$ENV{SESSION_DATE}/g; s/\{\{project_name\}\}/$ENV{PROJECT_NAME}/g; s/\{\{previous_session_link\}\}/$ENV{PREV_LINK}/g' \
|
|
500
508
|
"$AI_MEM_SESSION_DIR/_session_template.md" > "$session_note"
|
|
501
509
|
fi
|
|
@@ -511,10 +519,38 @@ __ai_mem_prepare_session() {
|
|
|
511
519
|
# Pull one "* **Label:** value" bullet out of a session log's fixed
|
|
512
520
|
# "# Session Outcome" section. Reads the log directly — no separate file is
|
|
513
521
|
# ever written, so there is nothing extra sitting in the vault.
|
|
522
|
+
#
|
|
523
|
+
# Indented lines under the bullet belong to it and are joined with "; ".
|
|
524
|
+
# Agents often write a field as a bare label with nested bullets; reading
|
|
525
|
+
# only the label line returned "", the digest showed "—", and the next agent
|
|
526
|
+
# was told there were no decisions when the log held a list of them (140 of
|
|
527
|
+
# 407 logs on a real vault). Blank lines inside the list are skipped; the
|
|
528
|
+
# first non-blank, non-indented line (next bullet or heading) ends the field.
|
|
514
529
|
__ai_mem_session_field() {
|
|
515
530
|
local file="$1" label="$2" value
|
|
516
531
|
[[ -f "$file" ]] || return 0
|
|
517
|
-
value="$(
|
|
532
|
+
value="$(awk -v prefix="* **${label}:**" '
|
|
533
|
+
!found {
|
|
534
|
+
if (index($0, prefix) == 1) {
|
|
535
|
+
found = 1
|
|
536
|
+
v = substr($0, length(prefix) + 1)
|
|
537
|
+
sub(/^[[:space:]]+/, "", v)
|
|
538
|
+
}
|
|
539
|
+
next
|
|
540
|
+
}
|
|
541
|
+
/^[[:space:]]*$/ { next }
|
|
542
|
+
/^[[:space:]]/ {
|
|
543
|
+
item = $0
|
|
544
|
+
sub(/^[[:space:]]+([-*+][[:space:]]+)?/, "", item)
|
|
545
|
+
# An item that already ends a sentence needs no extra "; ".
|
|
546
|
+
if (v == "") v = item
|
|
547
|
+
else if (v ~ /[.;:!?]$/) v = v " " item
|
|
548
|
+
else v = v "; " item
|
|
549
|
+
next
|
|
550
|
+
}
|
|
551
|
+
{ exit }
|
|
552
|
+
END { if (found) print v }
|
|
553
|
+
' "$file")"
|
|
518
554
|
# An untouched template still has its literal [bracket] placeholder — that
|
|
519
555
|
# is not real content, so treat it the same as an empty field.
|
|
520
556
|
[[ "$value" == \[*\] ]] && return 0
|
|
@@ -743,6 +779,13 @@ __ai_mem_context_prompt() {
|
|
|
743
779
|
fi
|
|
744
780
|
local project_label="$project_note"
|
|
745
781
|
[[ -n "$project_label" ]] || project_label="none (GUI/MCP global memory; no repository context)"
|
|
782
|
+
# A global (GUI/MCP) log is created on the first write, so its path may
|
|
783
|
+
# not exist yet. Say so; an agent that tries to read it would otherwise
|
|
784
|
+
# take "not found" for an error.
|
|
785
|
+
local session_state=""
|
|
786
|
+
if [[ -n "$session_note" && ! -e "$session_note" ]]; then
|
|
787
|
+
session_state=" -- not created yet; the first ai-note or session-log write creates it at this path"
|
|
788
|
+
fi
|
|
746
789
|
# Hard "no"s go first: models follow early instructions most reliably,
|
|
747
790
|
# and the note cap truncates from the end. The index sits with the other
|
|
748
791
|
# pointers. Each block carries its own trailing newline so an absent
|
|
@@ -763,7 +806,7 @@ $(__ai_mem_note_contents "$AI_MEM_STANDARDS")
|
|
|
763
806
|
|
|
764
807
|
${about_index}- Project context: $project_label$project_state
|
|
765
808
|
$previous_session_block
|
|
766
|
-
- Active session log: $session_note
|
|
809
|
+
- Active session log: $session_note$session_state
|
|
767
810
|
$(__ai_mem_lesson_index)
|
|
768
811
|
|
|
769
812
|
Use the Obsidian vault as the persistent memory layer.
|
|
@@ -1045,6 +1088,19 @@ __ai_mem_current_project() {
|
|
|
1045
1088
|
__ai_mem_resolve_project
|
|
1046
1089
|
}
|
|
1047
1090
|
|
|
1091
|
+
# Create a global (GUI/MCP) session log at $1 if it does not exist yet. Global
|
|
1092
|
+
# logs are created lazily, on the first write, so a read-only conversation
|
|
1093
|
+
# leaves no empty note behind. `previous:` links the newest log with content.
|
|
1094
|
+
__ai_mem_create_global_log() {
|
|
1095
|
+
local session_note="$1" project_name="$2" previous prev_link=""
|
|
1096
|
+
[[ -f "$session_note" ]] && return 0
|
|
1097
|
+
__ai_mem_guard "$session_note" || return 1
|
|
1098
|
+
previous="$(__ai_mem_latest_session_log "$project_name")" || return 1
|
|
1099
|
+
[[ -n "$previous" ]] && prev_link="[[${previous:t:r}]]"
|
|
1100
|
+
mkdir -p "${session_note:h}"
|
|
1101
|
+
print -rl -- "---" "type: ai-global-session" "date: $(date +%Y-%m-%d)" "previous: \"$prev_link\"" "---" "" "# Global Session Notes" > "$session_note"
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1048
1104
|
__ai_mem_today_session_log() {
|
|
1049
1105
|
__ai_mem_paths
|
|
1050
1106
|
local project_name="${1:-}"
|
|
@@ -1059,10 +1115,18 @@ __ai_mem_today_session_log() {
|
|
|
1059
1115
|
local project_session_dir
|
|
1060
1116
|
project_session_dir="$(__ai_mem_project_session_dir "$project_name")"
|
|
1061
1117
|
|
|
1062
|
-
|
|
1118
|
+
local global_session=0
|
|
1119
|
+
[[ "${AI_MEM_GLOBAL_SESSION:-}" == "1" ]] && global_session=1
|
|
1120
|
+
|
|
1121
|
+
# A global session's path is pinned by the MCP server before the file
|
|
1122
|
+
# exists; the first write creates it there.
|
|
1123
|
+
if [[ -n "${AI_MEM_ACTIVE_SESSION_LOG:-}" ]] && { (( global_session )) || [[ -f "$AI_MEM_ACTIVE_SESSION_LOG" ]]; }; then
|
|
1063
1124
|
case "$AI_MEM_ACTIVE_SESSION_LOG" in
|
|
1064
1125
|
"$AI_MEM_ROOT"|"$AI_MEM_ROOT"/*)
|
|
1065
|
-
if [[ "$AI_MEM_ACTIVE_SESSION_LOG" == "$project_session_dir/${project_name}-${today}_"
|
|
1126
|
+
if [[ "$AI_MEM_ACTIVE_SESSION_LOG" == "$project_session_dir/${project_name}-${today}_"*.md ]]; then
|
|
1127
|
+
if (( global_session )); then
|
|
1128
|
+
__ai_mem_create_global_log "$AI_MEM_ACTIVE_SESSION_LOG" "$project_name" || return 1
|
|
1129
|
+
fi
|
|
1066
1130
|
print -r -- "$AI_MEM_ACTIVE_SESSION_LOG"
|
|
1067
1131
|
return 0
|
|
1068
1132
|
fi
|
|
@@ -1083,6 +1147,11 @@ __ai_mem_today_session_log() {
|
|
|
1083
1147
|
|
|
1084
1148
|
local session_note="$project_session_dir/${project_name}-${today}_$(date +%H-%M-%S).md"
|
|
1085
1149
|
__ai_mem_guard "$session_note" || return 1
|
|
1150
|
+
if (( global_session )); then
|
|
1151
|
+
__ai_mem_create_global_log "$session_note" "$project_name" || return 1
|
|
1152
|
+
print -r -- "$session_note"
|
|
1153
|
+
return 0
|
|
1154
|
+
fi
|
|
1086
1155
|
mkdir -p "$project_session_dir"
|
|
1087
1156
|
SESSION_DATE="$today" PROJECT_NAME="$project_name" perl -0pe 's/\{\{date\}\}/$ENV{SESSION_DATE}/g; s/\{\{project_name\}\}/$ENV{PROJECT_NAME}/g' \
|
|
1088
1157
|
"$AI_MEM_SESSION_DIR/_session_template.md" > "$session_note"
|