create-ai-memory 0.15.4 → 0.16.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/shell/ai-mem.zsh CHANGED
@@ -1,8 +1,8 @@
1
1
  # === AI CLI + Obsidian memory ===
2
2
  # Portable, agent-agnostic session memory. Source this from ~/.zshrc after
3
3
  # exporting AI_MEM_ROOT to point at your vault. Zsh-only (uses print -r, ${(s)},
4
- # and associative arrays). Add a new agent by defining __ai_adapter_<name> in adapters.zsh and
5
- # listing it in AI_MEM_AGENTS; a matching <name>-start function is generated.
4
+ # and associative arrays). Add a new harness by defining __ai_adapter_<name> in adapters.zsh and
5
+ # listing it in AI_MEM_HARNESSES; a matching <name>-start function is generated.
6
6
  #
7
7
  # Private helpers are named __ai_* with TWO leading underscores, deliberately.
8
8
  # Claude Code snapshots the interactive shell and replays that snapshot for
@@ -47,6 +47,18 @@ if [[ -d "$AI_MEM_ROOT" ]]; then
47
47
  AI_MEM_ROOT="$(cd "$AI_MEM_ROOT" && pwd -P)"
48
48
  fi
49
49
  export AI_MEM_ROOT
50
+ # Paths derived from AI_MEM_ROOT. Every function that reads them calls this
51
+ # first rather than trusting the exports made at source time: a shell can carry
52
+ # the functions without the exports (Claude Code's Bash tool replays a snapshot
53
+ # of functions, and only inherited variables survive), and then AI_MEM_SESSION_DIR
54
+ # is empty -- ai-mem-sleep reported "no session logs at -- nothing to do".
55
+ # Only empty ones are filled, so a caller that points one of them elsewhere keeps it.
56
+ __ai_mem_paths() {
57
+ export AI_MEM_GLOBAL="${AI_MEM_GLOBAL:-$AI_MEM_ROOT/_Global_Profile.md}"
58
+ export AI_MEM_STANDARDS="${AI_MEM_STANDARDS:-$AI_MEM_ROOT/_Standards.md}"
59
+ export AI_MEM_PROJECT_DIR="${AI_MEM_PROJECT_DIR:-$AI_MEM_ROOT/_projects}"
60
+ export AI_MEM_SESSION_DIR="${AI_MEM_SESSION_DIR:-$AI_MEM_ROOT/_session_logs}"
61
+ }
50
62
  export AI_MEM_GLOBAL="$AI_MEM_ROOT/_Global_Profile.md"
51
63
  export AI_MEM_STANDARDS="$AI_MEM_ROOT/_Standards.md"
52
64
  export AI_MEM_PROJECT_DIR="$AI_MEM_ROOT/_projects"
@@ -299,6 +311,7 @@ __ai_mem_resolve_project() {
299
311
  }
300
312
 
301
313
  __ai_mem_project_session_dir() {
314
+ __ai_mem_paths
302
315
  local project_name="${1:-}"
303
316
  if [[ -z "$project_name" ]]; then
304
317
  project_name="$(__ai_mem_resolve_project)"
@@ -314,44 +327,10 @@ __ai_mem_project_session_dir() {
314
327
  print -r -- "$AI_MEM_SESSION_DIR/$project_name"
315
328
  }
316
329
 
317
- __ai_mem_graphify_repo_root() {
318
- local git_root=""
319
- git_root="$(git rev-parse --show-toplevel 2>/dev/null)" || true
320
- if [[ -n "$git_root" ]]; then
321
- print -r -- "$git_root"
322
- else
323
- print -r -- "$PWD"
324
- fi
325
- }
326
-
327
- __ai_mem_graphify_context() {
328
- local repo_root="$(__ai_mem_graphify_repo_root)"
329
- local graph_root="$repo_root/graphify-out"
330
- local graph_json="$graph_root/graph.json"
331
- local graph_report="$graph_root/GRAPH_REPORT.md"
332
- local graph_wiki="$graph_root/wiki/index.md"
333
-
334
- if [[ ! -f "$graph_json" ]]; then
335
- return 0
336
- fi
337
-
338
- export AI_GRAPHIFY_ROOT="$graph_root"
339
- export AI_GRAPHIFY_GRAPH_JSON="$graph_json"
340
-
341
- printf '%s\n' \
342
- "Graphify context:" \
343
- "- Knowledge graph available at: $graph_root" \
344
- "- Use graphify query/path/explain before raw grep for codebase or architecture questions." \
345
- "- Read the graph report for broad overviews: $graph_report"
346
-
347
- if [[ -f "$graph_wiki" ]]; then
348
- printf '%s\n' "- Use the wiki index for broad navigation: $graph_wiki"
349
- fi
350
- }
351
-
352
330
  # Returns the newest saved session log for the current project.
353
331
  # The active run gets a fresh log, so this only feeds carryover context.
354
332
  __ai_mem_latest_session_log() {
333
+ __ai_mem_paths
355
334
  local project_name="${1:-}"
356
335
  if [[ -z "$project_name" ]]; then
357
336
  project_name="$(__ai_mem_resolve_project)"
@@ -377,7 +356,7 @@ __ai_mem_latest_session_log() {
377
356
  latest="$(awk '
378
357
  FNR == 1 { fm = ($0 == "---"); if (fm) next }
379
358
  fm { if ($0 == "---") fm = 0; next }
380
- /^[[:space:]]*$/ || $0 == "# Session Outcome" || /^\* \*\*[^*]+:\*\*[[:space:]]*\[.*\]$/ { next }
359
+ /^[[:space:]]*$/ || $0 == "# Session Outcome" || $0 == "# Global Session Notes" || /^\* \*\*[^*]+:\*\*[[:space:]]*\[.*\]$/ { next }
381
360
  { print FILENAME; exit }
382
361
  ' "${(@f)logs}" 2>/dev/null)" || true
383
362
  [[ -n "$latest" ]] || latest="${logs%%$'\n'*}"
@@ -391,6 +370,7 @@ __ai_mem_latest_session_log() {
391
370
  # Idempotent and additive: it never overwrites a file the user already has, so a
392
371
  # plugin-manager install (source only, no install.sh) still gets a working vault.
393
372
  __ai_mem_ensure_vault() {
373
+ __ai_mem_paths
394
374
  [[ -d "$AI_MEM_TEMPLATE_SRC" ]] || return 0
395
375
  mkdir -p "$AI_MEM_PROJECT_DIR" "$AI_MEM_SESSION_DIR" "$AI_MEM_ROOT/_lessons"
396
376
  local rel
@@ -404,6 +384,15 @@ __ai_mem_ensure_vault() {
404
384
  fi
405
385
  done
406
386
 
387
+ # _about_me/ is seeded as a whole, only when the folder does not exist.
388
+ # Seeding per file would bring back a note the user deleted on purpose,
389
+ # at every launch.
390
+ local about_src="$AI_MEM_TEMPLATE_SRC/_about_me" about_dst="$AI_MEM_ROOT/_about_me"
391
+ if [[ -d "$about_src" && ! -e "$about_dst" ]]; then
392
+ __ai_mem_guard "$about_dst" || return 1
393
+ cp -R "$about_src" "$about_dst"
394
+ fi
395
+
407
396
  # Seeding only fills in a MISSING file, which is right -- these are the
408
397
  # user's notes and templates, and an upgrade must not overwrite edits they
409
398
  # made. But that leaves an existing vault on whatever templates it had
@@ -446,6 +435,7 @@ __ai_mem_ensure_vault() {
446
435
  }
447
436
 
448
437
  __ai_mem_prepare_session() {
438
+ __ai_mem_paths
449
439
  local project_name="${1:-}"
450
440
  if [[ -z "$project_name" ]]; then
451
441
  project_name="$(__ai_mem_resolve_project)"
@@ -453,7 +443,16 @@ __ai_mem_prepare_session() {
453
443
 
454
444
  __ai_mem_ensure_vault || return 1
455
445
 
456
- local project_note="$AI_MEM_PROJECT_DIR/${project_name}.md"
446
+ # GUI/MCP memory has no repository project. Keep its session records
447
+ # lightweight instead of copying repository-oriented templates.
448
+ local global_session=0
449
+ [[ "${AI_MEM_GLOBAL_SESSION:-}" == "1" ]] && global_session=1
450
+
451
+ local project_note=""
452
+ if (( ! global_session )); then
453
+ project_note="$AI_MEM_PROJECT_DIR/${project_name}.md"
454
+ fi
455
+
457
456
  local project_session_dir
458
457
  project_session_dir="$(__ai_mem_project_session_dir "$project_name")"
459
458
  local previous_session_note=""
@@ -461,38 +460,53 @@ __ai_mem_prepare_session() {
461
460
  local session_stamp="$(date +%Y-%m-%d_%H-%M-%S)"
462
461
  local session_note="$project_session_dir/${project_name}-${session_stamp}.md"
463
462
 
464
- __ai_mem_guard "$project_note" || return 1
463
+ if (( ! global_session )); then
464
+ __ai_mem_guard "$project_note" || return 1
465
+ fi
465
466
  __ai_mem_guard "$session_note" || return 1
466
467
 
467
468
  mkdir -p "$AI_MEM_PROJECT_DIR" "$AI_MEM_SESSION_DIR" "$project_session_dir"
468
469
 
469
- if [[ ! -f "$project_note" ]]; then
470
+ if (( ! global_session )) && [[ ! -f "$project_note" ]]; then
470
471
  PROJECT_NAME="$project_name" perl -0pe 's/\[Insert Project Name\]/$ENV{PROJECT_NAME}/g' \
471
472
  "$AI_MEM_PROJECT_DIR/_project_template.md" > "$project_note"
472
473
  fi
473
474
 
474
- # A blank note with this second's timestamp belongs to a separate session.
475
- # Wait for the next timestamp instead of overwriting its previous-session
476
- # link. A note with Live Notes is the active GUI/CLI session and must be
477
- # reused.
478
- if [[ -f "$session_note" ]] && ! grep -q '^### Live Notes' "$session_note" 2>/dev/null; then
479
- while [[ -f "$session_note" ]]; do
480
- sleep 1
481
- session_stamp="$(date +%Y-%m-%d_%H-%M-%S)"
482
- session_note="$project_session_dir/${project_name}-${session_stamp}.md"
483
- done
484
- fi
485
-
486
475
  local prev_link=""
487
476
  if [[ -n "$previous_session_note" ]]; then
488
477
  prev_link="[[${previous_session_note:t:r}]]"
489
478
  fi
490
479
 
491
- # Context reads can follow a GUI write in the same second. Reusing an
492
- # existing timestamped note preserves Live Notes and any other append.
493
- if [[ ! -f "$session_note" ]]; then
494
- 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' \
495
- "$AI_MEM_SESSION_DIR/_session_template.md" > "$session_note"
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
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' \
508
+ "$AI_MEM_SESSION_DIR/_session_template.md" > "$session_note"
509
+ fi
496
510
  fi
497
511
 
498
512
  export AI_MEM_ACTIVE_PROJECT="$project_name"
@@ -563,7 +577,136 @@ __ai_mem_lesson_index() {
563
577
  return 0
564
578
  }
565
579
 
580
+ # The human side of the profile: who the user is, what they want, and what
581
+ # they refuse. It lives in _about_me/ as several small notes rather than one
582
+ # file, because one file grows until the note cap truncates it -- which is
583
+ # exactly what happens to a long _Global_Profile.md.
584
+ #
585
+ # Each note says in frontmatter how it reaches the agent:
586
+ # inject: always -> body inlined at the TOP of the prompt. For hard
587
+ # "no"s: a rule the agent must open a file to see is
588
+ # a rule it will often never see.
589
+ # anything else -> one index line naming the file and `read_when:`,
590
+ # the trigger that tells the agent WHEN to open it.
591
+ # A bare link with no trigger is routinely ignored.
592
+ # An `always` note is capped separately and tightly (AI_MEM_ABOUT_ME_MAX_CHARS),
593
+ # so growth there shows up as a truncation notice instead of silent bloat.
594
+ #
595
+ # A note that is still only template scaffolding (headings, blockquotes,
596
+ # [bracketed] placeholder bullets) is skipped: pointing the agent at a blank
597
+ # template reads as context and carries none. Blockquotes and placeholder
598
+ # bullets are also dropped from an injected body -- they are notes to the
599
+ # user, and every character there is paid for in every session. Notes whose
600
+ # name starts with `_` are skipped, matching every other folder's templates.
601
+ #
602
+ # Usage: __ai_mem_about_me always|index
603
+ __ai_mem_about_me() {
604
+ local mode="${1:-}" dir="$AI_MEM_ROOT/_about_me"
605
+ [[ -d "$dir" ]] || return 0
606
+
607
+ local -a notes
608
+ notes=("$dir"/*.md(N.on))
609
+ (( $#notes )) || return 0
610
+
611
+ local f fm inject read_when body cap="${AI_MEM_ABOUT_ME_MAX_CHARS:-1500}"
612
+ local -a index_lines
613
+ for f in $notes; do
614
+ [[ "${f:t}" == _* ]] && continue
615
+ __ai_mem_guard "$f" || return 1
616
+
617
+ # Frontmatter only when line 1 opens it, so prose can never pose as
618
+ # a declaration (same rule as mirror_of).
619
+ fm=""
620
+ [[ "$(head -1 "$f")" == "---" ]] && fm="$(sed -n '2,/^---$/p' "$f")"
621
+ # Values may be YAML-quoted; sed strips the key, surrounding space,
622
+ # and one pair of quotes.
623
+ inject="$(print -r -- "$fm" | sed -n "s/^inject:[[:space:]]*[\"']\{0,1\}\([^\"']*\)[\"']\{0,1\}[[:space:]]*\$/\1/p" | head -1)"
624
+ read_when="$(print -r -- "$fm" | sed -n "s/^read_when:[[:space:]]*[\"']\{0,1\}\([^\"']*\)[\"']\{0,1\}[[:space:]]*\$/\1/p" | head -1)"
625
+
626
+ # Body without frontmatter, blockquotes, or placeholder bullets; empty
627
+ # when nothing but scaffolding is left.
628
+ body="$(awk '
629
+ NR == 1 && $0 == "---" { fm = 1; next }
630
+ fm { if ($0 == "---") fm = 0; next }
631
+ /^>/ || /^[*-][[:space:]]+\[[^]]*\][[:space:]]*$/ { next }
632
+ /^[[:space:]]*$/ { if (n && lines[n] != "") lines[++n] = ""; next }
633
+ { lines[++n] = $0 }
634
+ !/^#/ { filled = 1 }
635
+ END { if (filled) for (i = 1; i <= n; i++) print lines[i] }
636
+ ' "$f")"
637
+ [[ -n "${body//[[:space:]]/}" ]] || continue
638
+
639
+ if [[ "$inject" == always ]]; then
640
+ [[ "$mode" == always ]] || continue
641
+ print -r -- "- About me -- ${f:t} (always in force):"
642
+ AI_MEM_NOTE_MAX_CHARS="$cap" __ai_mem_cap_note "$body" "$f"
643
+ print
644
+ else
645
+ [[ "$mode" == index ]] || continue
646
+ index_lines+=(" * ${f:t}: ${read_when:-read when relevant to the task} -- $f")
647
+ fi
648
+ done
649
+
650
+ if [[ "$mode" == index ]] && (( $#index_lines )); then
651
+ print -r -- "- About me -- more notes, NOT included here. Read a file with \`cat\` when its trigger applies:"
652
+ print -rl -- $index_lines
653
+ fi
654
+ return 0
655
+ }
656
+
657
+ # Tell the HUMAN, once per vault, that _about_me/ is still blank. It goes to
658
+ # stderr and never into the prompt: an agent told "this is empty" at every
659
+ # launch would nag the user about it in every session. The marker lives in
660
+ # the vault, so each vault (and each test fixture) is hinted independently.
661
+ __ai_mem_about_me_hint() {
662
+ local dir="$AI_MEM_ROOT/_about_me"
663
+ local marker="$dir/.about-me-hinted"
664
+ [[ -d "$dir" && ! -e "$marker" ]] || return 0
665
+ [[ -z "$(__ai_mem_about_me index 2>/dev/null)" ]] || return 0
666
+ print -r -- "ai-memory: _about_me/ has only placeholders. Run 'ai-about-me' to fill it by interview. (Shown once.)" >&2
667
+ __ai_mem_guard "$marker" && : > "$marker"
668
+ return 0
669
+ }
670
+
671
+ # Fill _about_me/ by interview, or review it against the vault's evidence.
672
+ #
673
+ # ai-about-me [harness] interview: one question at a time
674
+ # ai-about-me --review [harness] propose rules from lessons and session logs
675
+ #
676
+ # The agent is started like <harness>-start, with the protocol from
677
+ # about-me-interview.md or about-me-review.md as the session's task. The
678
+ # protocols are written for the agent: ask before writing, draft for approval,
679
+ # never add a rule the user did not state. A self-edited profile stops being
680
+ # the user's own view of themselves.
681
+ ai-about-me() {
682
+ __ai_mem_paths
683
+ local mode=interview
684
+ case "${1:-}" in
685
+ --review) mode=review; shift ;;
686
+ -h|--help)
687
+ print -r -- "usage: ai-about-me [--review] [harness]"
688
+ print -r -- " Interview: the agent asks one question at a time and fills _about_me/ after you approve each draft."
689
+ print -r -- " --review: the agent proposes rules from your lessons and session logs; you accept or reject each one."
690
+ return 0 ;;
691
+ -*) print -r -- "ai-about-me: unknown option '$1' (see ai-about-me --help)" >&2; return 1 ;;
692
+ esac
693
+
694
+ local protocol="$AI_MEM_HOME/about-me-$mode.md"
695
+ if [[ ! -f "$protocol" ]]; then
696
+ print -r -- "ai-about-me: protocol file not found: $protocol" >&2
697
+ return 1
698
+ fi
699
+ local launcher="${1:-${${(z)AI_MEM_HARNESSES}[1]}}"
700
+ (( $# )) && shift
701
+
702
+ __ai_mem_ensure_vault || return 1
703
+ local task
704
+ task="$(<"$protocol")"$'\n\n'"The notes are in: $AI_MEM_ROOT/_about_me/"
705
+ AI_MEM_SESSION_TASK="$task" __ai_session_start "$launcher" "$@"
706
+ }
707
+
566
708
  __ai_mem_context_prompt() {
709
+ __ai_mem_paths
567
710
  local project_note="${1:-}"
568
711
  local previous_session_note="${2:-}"
569
712
  local session_note="${3:-}"
@@ -606,24 +749,42 @@ __ai_mem_context_prompt() {
606
749
  if [[ -f "$project_note" ]] && grep -q '\[What problem this repository solves\]' "$project_note" 2>/dev/null; then
607
750
  project_state=" -- NOT YET FILLED IN: it is still the blank template, so it holds no context. Read the repo (README, package manifest, AGENTS.md/CLAUDE.md, recent git log) and fill it in early in this session; every future session on this repo starts from it."
608
751
  fi
752
+ local project_label="$project_note"
753
+ [[ -n "$project_label" ]] || project_label="none (GUI/MCP global memory; no repository context)"
754
+ # A global (GUI/MCP) log is created on the first write, so its path may
755
+ # not exist yet. Say so; an agent that tries to read it would otherwise
756
+ # take "not found" for an error.
757
+ local session_state=""
758
+ if [[ -n "$session_note" && ! -e "$session_note" ]]; then
759
+ session_state=" -- not created yet; the first ai-note or session-log write creates it at this path"
760
+ fi
761
+ # Hard "no"s go first: models follow early instructions most reliably,
762
+ # and the note cap truncates from the end. The index sits with the other
763
+ # pointers. Each block carries its own trailing newline so an absent
764
+ # _about_me/ leaves the prompt byte-identical to before.
765
+ local about_always about_index
766
+ about_always="$(__ai_mem_about_me always)" || return 1
767
+ about_index="$(__ai_mem_about_me index)" || return 1
768
+ [[ -n "$about_always" ]] && about_always+=$'\n\n'
769
+ [[ -n "$about_index" ]] && about_index+=$'\n'
609
770
 
610
771
  cat <<EOF
611
772
  Read these notes before doing anything else:
612
- - Global profile:
773
+ ${about_always}- Global profile:
613
774
  $(__ai_mem_note_contents "$AI_MEM_GLOBAL")
614
775
 
615
776
  - Standards:
616
777
  $(__ai_mem_note_contents "$AI_MEM_STANDARDS")
617
778
 
618
- - Project context: $project_note$project_state
779
+ ${about_index}- Project context: $project_label$project_state
619
780
  $previous_session_block
620
- - Active session log: $session_note
781
+ - Active session log: $session_note$session_state
621
782
  $(__ai_mem_lesson_index)
622
783
 
623
784
  Use the Obsidian vault as the persistent memory layer.
624
785
  Treat the global profile and standards note as the shared baseline for every run.
625
786
  Keep durable preferences and project facts in the vault, and keep the active session log updated with decisions, blockers, and next steps.
626
- 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 zsh functions from the sourced module, so \`command -v\` finds them but \`which\` under bash will not. 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.
787
+ 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.
627
788
  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.
628
789
  Search ONE distinctive word, not a sentence. Matching is literal substring, so a whole error line ('command not found: sed') finds nothing while 'command not found' finds it, and a bare tool name ('sed', 'git') returns hundreds of irrelevant lines. Pick the most unusual word in the symptom and try two or three of them separately.
629
790
  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.
@@ -633,6 +794,7 @@ EOF
633
794
 
634
795
  # Mark the current shell as having loaded AI vault context for the active repo.
635
796
  __ai_mem_mark_commit_ready() {
797
+ __ai_mem_paths
636
798
  local project_name="${1:-}"
637
799
  local source="${2:-ai-context}"
638
800
  local ready_dir="$AI_MEM_SESSION_DIR/.context-ready"
@@ -681,6 +843,7 @@ __ai_mem_export_active() {
681
843
  }
682
844
 
683
845
  ai-start() {
846
+ __ai_mem_paths
684
847
  local project_name="${1:-}"
685
848
  shift || true
686
849
 
@@ -746,6 +909,19 @@ __ai_yesno() {
746
909
  typeset -gA AI_MEM_SKILLS
747
910
  typeset -ga AI_MEM_SKILL_ORDER
748
911
 
912
+ # When OMP is the preferred harness, preserve the requested *-start provider.
913
+ # Override these maps before sourcing this file when a provider uses a custom
914
+ # OMP name or model. An unmapped launcher falls back to its own name.
915
+ typeset -gA AI_MEM_OMP_PROVIDERS
916
+ typeset -gA AI_MEM_OMP_MODELS
917
+ [[ -n "${AI_MEM_OMP_PROVIDERS[codex]:-}" ]] || AI_MEM_OMP_PROVIDERS[codex]=openai-codex
918
+ [[ -n "${AI_MEM_OMP_PROVIDERS[claude]:-}" ]] || AI_MEM_OMP_PROVIDERS[claude]=anthropic
919
+ [[ -n "${AI_MEM_OMP_PROVIDERS[gemini]:-}" ]] || AI_MEM_OMP_PROVIDERS[gemini]=google
920
+ [[ -n "${AI_MEM_OMP_PROVIDERS[agy]:-}" ]] || AI_MEM_OMP_PROVIDERS[agy]=google
921
+ [[ -n "${AI_MEM_OMP_PROVIDERS[opencode]:-}" ]] || AI_MEM_OMP_PROVIDERS[opencode]=opencode
922
+ [[ -n "${AI_MEM_OMP_PROVIDERS[cursor]:-}" ]] || AI_MEM_OMP_PROVIDERS[cursor]=cursor
923
+ [[ -n "${AI_MEM_OMP_MODELS[claude]:-}" ]] || AI_MEM_OMP_MODELS[claude]=claude-sonnet-4-5
924
+
749
925
  # Ask which optional skills to enable. Each is independent; answer y/n per skill.
750
926
  # Echoes a pipe-joined list of chosen keys; empty means a plain session.
751
927
  __ai_session_modes_pick() {
@@ -770,11 +946,20 @@ __ai_session_modes_instructions() {
770
946
 
771
947
  # Start an AI client with the shared memory block and the chosen session mode.
772
948
  __ai_session_start() {
773
- local launcher="${1:-}"
949
+ local requested_launcher="${1:-}"
950
+ local launcher="${AI_MEM_PREFERRED_HARNESS:-$requested_launcher}"
774
951
  if (( $# > 0 )); then
775
952
  shift
776
953
  fi
777
954
 
955
+ if [[ -n "${AI_MEM_PREFERRED_HARNESS:-}" && "$requested_launcher" != "$launcher" ]]; then
956
+ echo "ai-memory: $requested_launcher-start is using preferred harness $launcher" >&2
957
+ fi
958
+ # Keep the user's requested launcher visible to a preferred harness. This
959
+ # lets one OMP harness route codex-start and claude-start to different
960
+ # providers instead of silently using OMP's default provider for both.
961
+ export AI_MEM_REQUESTED_LAUNCHER="$requested_launcher"
962
+
778
963
  # Warn (never block) if this shell is running a stale copy. Everything
779
964
  # below would otherwise succeed quietly using the old behaviour, and the
780
965
  # only symptom is a fix that appears not to have worked.
@@ -791,7 +976,7 @@ __ai_session_start() {
791
976
  # session log is created. Cursor is exempt: its adapter falls back to opening
792
977
  # the app when the `cursor` CLI is absent.
793
978
  if [[ "$launcher" != cursor ]] && ! command -v "$launcher" >/dev/null 2>&1; then
794
- echo "ai-memory: '$launcher' CLI not found on PATH. Install it, or drop it from AI_MEM_AGENTS." >&2
979
+ echo "ai-memory: '$launcher' CLI not found on PATH. Install it, or remove it from AI_MEM_HARNESSES." >&2
795
980
  return 1
796
981
  fi
797
982
 
@@ -803,7 +988,12 @@ __ai_session_start() {
803
988
  __ai_mem_export_active "$active_project" "$previous_session_note" "$session_note"
804
989
 
805
990
  local session_modes mode_block
806
- session_modes="$(__ai_session_modes_pick)" || return 1
991
+ if [[ -n "${AI_MEM_MANUAL_SKILLS:-}" ]]; then
992
+ # One-off opt-in for skills that should not appear in the startup picker.
993
+ session_modes="$AI_MEM_MANUAL_SKILLS"
994
+ else
995
+ session_modes="$(__ai_session_modes_pick)" || return 1
996
+ fi
807
997
  mode_block="$(__ai_session_modes_instructions "$session_modes")"
808
998
 
809
999
  # AI_SESSION_MODES carries the chosen skill keys; AI_SESSION_STYLE_LABEL
@@ -814,14 +1004,10 @@ __ai_session_start() {
814
1004
  local memory_prompt
815
1005
  memory_prompt="$(__ai_mem_context_prompt "$project_note" "$previous_session_note" "$session_note")"
816
1006
 
817
- local graphify_context=""
818
- graphify_context="$(__ai_mem_graphify_context)" || return 1
819
- if [[ -n "$graphify_context" ]]; then
820
- memory_prompt+=$'\n\n'
821
- memory_prompt+="$graphify_context"
822
- fi
823
-
824
- if [[ -n "$mode_block" ]]; then
1007
+ # OMP receives the selected skill files through its system-prompt channel;
1008
+ # do not duplicate the short picker blocks in its opening user message,
1009
+ # where OMP can mistake names such as "caveman skill" for skill:// refs.
1010
+ if [[ -n "$mode_block" && "$launcher" != omp ]]; then
825
1011
  memory_prompt+=$'\n\n'
826
1012
  memory_prompt+="$mode_block"
827
1013
  fi
@@ -829,6 +1015,15 @@ __ai_session_start() {
829
1015
  memory_prompt+=$'\n\n'
830
1016
  memory_prompt+="$session_prompt"
831
1017
  fi
1018
+ # A task for the whole session (e.g. the ai-about-me interview). It rides
1019
+ # in the opening message only: adapters also forward "$@" as CLI args,
1020
+ # so passing it as an argument would send it twice to some harnesses.
1021
+ if [[ -n "${AI_MEM_SESSION_TASK:-}" ]]; then
1022
+ memory_prompt+=$'\n\n'
1023
+ memory_prompt+="$AI_MEM_SESSION_TASK"
1024
+ else
1025
+ __ai_mem_about_me_hint
1026
+ fi
832
1027
 
833
1028
  __ai_mem_mark_commit_ready "$active_project" "$launcher-start" || return 1
834
1029
 
@@ -842,12 +1037,14 @@ __ai_session_start() {
842
1037
  "__ai_adapter_$launcher" "$memory_prompt" "$mode_block" "$@"
843
1038
  }
844
1039
 
845
- # Load the agent adapters, then generate a <name>-start launcher for every
846
- # registered agent that has a matching adapter. Users extend by appending to
847
- # AI_MEM_AGENTS (space-separated) and defining __ai_adapter_<name>.
1040
+ # Load the harness adapters, then generate a <name>-start launcher for every
1041
+ # registered harness that has a matching adapter. AI_MEM_HARNESSES is preferred;
1042
+ # AI_MEM_AGENTS remains a compatibility alias for existing installs.
848
1043
  source "$AI_MEM_HOME/adapters.zsh"
849
- : "${AI_MEM_AGENTS:=claude codex agy gemini cursor opencode}"
850
- for _ai_agent in ${(z)AI_MEM_AGENTS}; do
1044
+ : "${AI_MEM_HARNESSES:=${AI_MEM_AGENTS:-claude codex agy gemini cursor opencode omp}}"
1045
+ export AI_MEM_HARNESSES
1046
+ export AI_MEM_AGENTS="$AI_MEM_HARNESSES"
1047
+ for _ai_agent in ${(z)AI_MEM_HARNESSES}; do
851
1048
  if typeset -f "__ai_adapter_$_ai_agent" >/dev/null; then
852
1049
  # A same-named alias (e.g. from another plugin) makes zsh refuse to
853
1050
  # `eval` a function definition of that name at all -- "defining
@@ -863,7 +1060,21 @@ __ai_mem_current_project() {
863
1060
  __ai_mem_resolve_project
864
1061
  }
865
1062
 
1063
+ # Create a global (GUI/MCP) session log at $1 if it does not exist yet. Global
1064
+ # logs are created lazily, on the first write, so a read-only conversation
1065
+ # leaves no empty note behind. `previous:` links the newest log with content.
1066
+ __ai_mem_create_global_log() {
1067
+ local session_note="$1" project_name="$2" previous prev_link=""
1068
+ [[ -f "$session_note" ]] && return 0
1069
+ __ai_mem_guard "$session_note" || return 1
1070
+ previous="$(__ai_mem_latest_session_log "$project_name")" || return 1
1071
+ [[ -n "$previous" ]] && prev_link="[[${previous:t:r}]]"
1072
+ mkdir -p "${session_note:h}"
1073
+ print -rl -- "---" "type: ai-global-session" "date: $(date +%Y-%m-%d)" "previous: \"$prev_link\"" "---" "" "# Global Session Notes" > "$session_note"
1074
+ }
1075
+
866
1076
  __ai_mem_today_session_log() {
1077
+ __ai_mem_paths
867
1078
  local project_name="${1:-}"
868
1079
  if [[ -z "$project_name" ]]; then
869
1080
  project_name="$(__ai_mem_resolve_project)"
@@ -876,10 +1087,18 @@ __ai_mem_today_session_log() {
876
1087
  local project_session_dir
877
1088
  project_session_dir="$(__ai_mem_project_session_dir "$project_name")"
878
1089
 
879
- if [[ -n "${AI_MEM_ACTIVE_SESSION_LOG:-}" && -f "$AI_MEM_ACTIVE_SESSION_LOG" ]]; then
1090
+ local global_session=0
1091
+ [[ "${AI_MEM_GLOBAL_SESSION:-}" == "1" ]] && global_session=1
1092
+
1093
+ # A global session's path is pinned by the MCP server before the file
1094
+ # exists; the first write creates it there.
1095
+ if [[ -n "${AI_MEM_ACTIVE_SESSION_LOG:-}" ]] && { (( global_session )) || [[ -f "$AI_MEM_ACTIVE_SESSION_LOG" ]]; }; then
880
1096
  case "$AI_MEM_ACTIVE_SESSION_LOG" in
881
1097
  "$AI_MEM_ROOT"|"$AI_MEM_ROOT"/*)
882
- if [[ "$AI_MEM_ACTIVE_SESSION_LOG" == "$project_session_dir/${project_name}-${today}_"* ]]; then
1098
+ if [[ "$AI_MEM_ACTIVE_SESSION_LOG" == "$project_session_dir/${project_name}-${today}_"*.md ]]; then
1099
+ if (( global_session )); then
1100
+ __ai_mem_create_global_log "$AI_MEM_ACTIVE_SESSION_LOG" "$project_name" || return 1
1101
+ fi
883
1102
  print -r -- "$AI_MEM_ACTIVE_SESSION_LOG"
884
1103
  return 0
885
1104
  fi
@@ -900,6 +1119,11 @@ __ai_mem_today_session_log() {
900
1119
 
901
1120
  local session_note="$project_session_dir/${project_name}-${today}_$(date +%H-%M-%S).md"
902
1121
  __ai_mem_guard "$session_note" || return 1
1122
+ if (( global_session )); then
1123
+ __ai_mem_create_global_log "$session_note" "$project_name" || return 1
1124
+ print -r -- "$session_note"
1125
+ return 0
1126
+ fi
903
1127
  mkdir -p "$project_session_dir"
904
1128
  SESSION_DATE="$today" PROJECT_NAME="$project_name" perl -0pe 's/\{\{date\}\}/$ENV{SESSION_DATE}/g; s/\{\{project_name\}\}/$ENV{PROJECT_NAME}/g' \
905
1129
  "$AI_MEM_SESSION_DIR/_session_template.md" > "$session_note"
@@ -1126,6 +1350,7 @@ ai-mem-ingest() {
1126
1350
  # "isolated dots in Graph View" class of problem before you have to notice it
1127
1351
  # by eye.
1128
1352
  ai-mem-lint() {
1353
+ __ai_mem_paths
1129
1354
  local fix=0
1130
1355
  [[ "${1:-}" == "--fix" ]] && fix=1
1131
1356
  local issues=0 f label target found
@@ -1291,6 +1516,7 @@ ai-mem-lint() {
1291
1516
  # AI_MEM_SLEEP_DAYS archive logs older than this many days (default 90)
1292
1517
  # AI_MEM_SLEEP_CONSOLIDATE flag a project with this many hot logs (default 8)
1293
1518
  ai-mem-sleep() {
1519
+ __ai_mem_paths
1294
1520
  local apply=0
1295
1521
  [[ "${1:-}" == "--apply" ]] && apply=1
1296
1522
 
@@ -1489,6 +1715,7 @@ ai-mem-sleep-schedule() {
1489
1715
  # because a flag only helps if whoever's calling this remembers it exists,
1490
1716
  # and the whole point is not depending on that.
1491
1717
  ai-mem-search() {
1718
+ __ai_mem_paths
1492
1719
  local term="${1:-}"
1493
1720
  local project="${2:-}"
1494
1721
  if [[ -z "$term" ]]; then
@@ -0,0 +1,15 @@
1
+ ---
2
+ type: ai-about-me
3
+ inject: index
4
+ read_when: before you explain something or decide how much detail to give
5
+ ---
6
+
7
+ # Expertise
8
+
9
+ > Write this note yourself. An agent may propose a change, but it must not
10
+ > edit this note without your approval. ai-mem does not inject this note. It
11
+ > puts one index line in the prompt: the file name and `read_when`. Replace
12
+ > the [bracketed] bullets. A note that has only placeholders is not listed.
13
+
14
+ * [Strong in: ... -- skip the basics here]
15
+ * [Learning: ... -- explain these]
@@ -0,0 +1,15 @@
1
+ ---
2
+ type: ai-about-me
3
+ inject: index
4
+ read_when: before you take a shortcut on design, on architecture, or on a skill I want to learn
5
+ ---
6
+
7
+ # Interests
8
+
9
+ > Write this note yourself. An agent may propose a change, but it must not
10
+ > edit this note without your approval. ai-mem does not inject this note. It
11
+ > puts one index line in the prompt: the file name and `read_when`. Replace
12
+ > the [bracketed] bullets. A note that has only placeholders is not listed.
13
+
14
+ * [A long-term goal that outranks a quick shortcut, e.g. "I keep architecture decisions: show the tradeoff, do not decide for me"]
15
+ * [A skill you want to keep practising yourself instead of handing it to the agent]
@@ -0,0 +1,15 @@
1
+ ---
2
+ type: ai-about-me
3
+ inject: index
4
+ read_when: when it is not clear if I want you to act now or to explore options first
5
+ ---
6
+
7
+ # Modes
8
+
9
+ > Write this note yourself. An agent may propose a change, but it must not
10
+ > edit this note without your approval. ai-mem does not inject this note. It
11
+ > puts one index line in the prompt: the file name and `read_when`. Replace
12
+ > the [bracketed] bullets. A note that has only placeholders is not listed.
13
+
14
+ * [Acceleration: the words you use when you know the next step and want it done fast]
15
+ * [Exploration: the words you use when you are unsure and want options with evidence]