@dinasor/mnemo-cli 0.0.3 → 0.0.6

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/memory_mac.sh CHANGED
@@ -11,7 +11,7 @@
11
11
  # sh ./memory_mac.sh --enable-vector --vector-provider gemini
12
12
  #
13
13
  # This creates:
14
- # .cursor/memory/*, .cursor/rules/*, scripts/memory/*, .githooks/pre-commit
14
+ # .cursor/memory/*, .cursor/rules/*, .cursor/skills/*, scripts/memory/*, .githooks/pre-commit
15
15
  # (and optional .githooks/post-commit when --enable-vector is used)
16
16
 
17
17
  set -eu
@@ -126,6 +126,17 @@ write_file() {
126
126
  printf '%s\n' "WROTE: $path"
127
127
  }
128
128
 
129
+ install_template_file() {
130
+ # install_template_file <template_path> <dest_path>
131
+ template_path="$1"
132
+ dest_path="$2"
133
+ if [ ! -f "$template_path" ]; then
134
+ printf '%s\n' "WARNING: Template not found: $template_path"
135
+ return 0
136
+ fi
137
+ write_file "$dest_path" < "$template_path"
138
+ }
139
+
129
140
  sync_dir_one_way() {
130
141
  src="$1"
131
142
  dst="$2"
@@ -599,6 +610,14 @@ This project uses Mnemo for structured AI memory. All memory lives in `.cursor/m
599
610
  - Clear active-context.md when task is merged
600
611
  EOF
601
612
 
613
+ # -------------------------
614
+ # Cursor project skills
615
+ # -------------------------
616
+
617
+ _skills_tpl_dir="$_INSTALLER_DIR/scripts/memory/installer/templates/skills/mnemo-codebase-optimizer"
618
+ install_template_file "$_skills_tpl_dir/SKILL.md" "$CURSOR_DIR/skills/mnemo-codebase-optimizer/SKILL.md"
619
+ install_template_file "$_skills_tpl_dir/reference.md" "$CURSOR_DIR/skills/mnemo-codebase-optimizer/reference.md"
620
+
602
621
  write_file "$MEM_SCRIPTS_DIR/customization.md" <<'EOF'
603
622
  # Mnemo Memory Customization Prompt (paste into an AI)
604
623
 
@@ -1843,6 +1862,17 @@ def _resolve_memory_root() -> Path:
1843
1862
  return script_repo / ".mnemo" / "memory"
1844
1863
 
1845
1864
 
1865
+ def _resolve_repo_root(memory_root: Path) -> Path:
1866
+ root = memory_root.resolve()
1867
+ if root.name == "memory" and root.parent.name in {".mnemo", ".cursor"}:
1868
+ return root.parent.parent
1869
+ cwd = Path.cwd().resolve()
1870
+ for candidate in (cwd, *cwd.parents):
1871
+ if candidate.joinpath(".mnemo", "memory").exists() or candidate.joinpath(".cursor", "memory").exists():
1872
+ return candidate
1873
+ return cwd
1874
+
1875
+
1846
1876
  def _parse_env_line(raw_line: str):
1847
1877
  line = raw_line.strip()
1848
1878
  if not line or line.startswith("#"):
@@ -1863,10 +1893,26 @@ def _parse_env_line(raw_line: str):
1863
1893
  return key, value
1864
1894
 
1865
1895
 
1866
- def _load_project_env() -> None:
1867
- if os.getenv("GEMINI_API_KEY"):
1868
- return
1869
- env_path = Path(".env")
1896
+ def _is_missing_env_value(value):
1897
+ if value is None:
1898
+ return True
1899
+ stripped = str(value).strip()
1900
+ if not stripped:
1901
+ return True
1902
+ if stripped.startswith("${env:") and stripped.endswith("}"):
1903
+ return True
1904
+ return False
1905
+
1906
+
1907
+ def _get_env_value(name: str) -> str:
1908
+ value = os.getenv(name)
1909
+ if _is_missing_env_value(value):
1910
+ return ""
1911
+ return str(value).strip()
1912
+
1913
+
1914
+ def _load_project_env(repo_root: Path) -> None:
1915
+ env_path = repo_root / ".env"
1870
1916
  if not env_path.exists():
1871
1917
  return
1872
1918
  try:
@@ -1875,16 +1921,28 @@ def _load_project_env() -> None:
1875
1921
  if not parsed:
1876
1922
  continue
1877
1923
  key, value = parsed
1878
- os.environ.setdefault(key, value)
1924
+ key = key.lstrip("\ufeff")
1925
+ if _is_missing_env_value(os.getenv(key)):
1926
+ os.environ[key] = value
1879
1927
  except OSError:
1880
1928
  pass
1881
1929
 
1882
1930
 
1931
+ def _resolve_provider() -> str:
1932
+ configured = os.getenv("MNEMO_PROVIDER", "").strip().lower()
1933
+ if configured.startswith("${env:") and configured.endswith("}"):
1934
+ configured = ""
1935
+ if configured in {"openai", "gemini"}:
1936
+ return configured
1937
+ return "gemini" if _get_env_value("GEMINI_API_KEY") else "openai"
1938
+
1939
+
1883
1940
  MEM_ROOT = _resolve_memory_root()
1941
+ REPO_ROOT = _resolve_repo_root(MEM_ROOT)
1884
1942
  _DB_OVERRIDE = os.getenv("MNEMO_DB_PATH", "").strip()
1885
1943
  DB_PATH = Path(_DB_OVERRIDE).expanduser().resolve() if _DB_OVERRIDE else (MEM_ROOT / "mnemo_vector.sqlite")
1886
- _load_project_env()
1887
- PROVIDER = os.getenv("MNEMO_PROVIDER", "gemini" if os.getenv("GEMINI_API_KEY") else "openai").lower()
1944
+ _load_project_env(REPO_ROOT)
1945
+ PROVIDER = _resolve_provider()
1888
1946
 
1889
1947
  SKIP_NAMES = {
1890
1948
  "README.md",
@@ -1911,14 +1969,14 @@ def _get_embed_client():
1911
1969
  return _EMBED_CLIENT
1912
1970
 
1913
1971
  if PROVIDER == "gemini":
1914
- key = os.getenv("GEMINI_API_KEY")
1972
+ key = _get_env_value("GEMINI_API_KEY")
1915
1973
  if not key:
1916
1974
  raise RuntimeError("GEMINI_API_KEY is not set")
1917
1975
  from google import genai
1918
1976
  _EMBED_CLIENT = genai.Client(api_key=key)
1919
1977
  return _EMBED_CLIENT
1920
1978
 
1921
- key = os.getenv("OPENAI_API_KEY")
1979
+ key = _get_env_value("OPENAI_API_KEY")
1922
1980
  if not key:
1923
1981
  raise RuntimeError("OPENAI_API_KEY is not set")
1924
1982
  from openai import OpenAI
@@ -2388,6 +2446,7 @@ GI_END="# <<< Mnemo (generated) >>>"
2388
2446
  ignore_lines=".mnemo/
2389
2447
  .cursor/memory/
2390
2448
  .cursor/rules/
2449
+ .cursor/skills/
2391
2450
  .cursor/mcp.json
2392
2451
  .agent/rules/
2393
2452
  scripts/memory/
@@ -2461,6 +2520,7 @@ fi
2461
2520
  echo ""
2462
2521
  echo "Setup complete. (Mnemo v$MNEMO_VERSION)"
2463
2522
  echo "Next:"
2523
+ echo " skill: .cursor/skills/mnemo-codebase-optimizer/SKILL.md"
2464
2524
  echo " sh ./scripts/memory/rebuild-memory-index.sh"
2465
2525
  echo " sh ./scripts/memory/lint-memory.sh"
2466
2526
  if [ "$ENABLE_VECTOR" = "1" ] && [ "$DRY_RUN" != "1" ]; then
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dinasor/mnemo-cli",
3
- "version": "0.0.3",
3
+ "version": "0.0.6",
4
4
  "description": "Mnemo installer CLI for the current project folder.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -1,68 +1,69 @@
1
- <#
2
- gitignore_setup.ps1 - Managed .gitignore block for Mnemo generated artifacts.
3
- Dot-sourced by bootstrap.ps1.
4
- #>
5
-
6
- function Update-MnemoGitignore {
7
- param(
8
- [Parameter(Mandatory=$true)][hashtable]$Ctx,
9
- [switch]$EnableVector
10
- )
11
-
12
- $giPath = Join-Path $Ctx.RepoRoot ".gitignore"
13
- $giBeginMarker = "# >>> Mnemo (generated) - do not edit this block manually <<<"
14
- $giEndMarker = "# <<< Mnemo (generated) >>>"
15
-
16
- # User-facing default: ignore the full Mnemo generated footprint so target repos stay clean by default.
17
- $ignoreLines = @(
18
- ".mnemo/",
19
- ".cursor/memory/",
20
- ".cursor/rules/",
21
- ".cursor/mcp.json",
22
- ".agent/rules/",
23
- "scripts/memory/",
24
- ".githooks/"
25
- )
26
-
27
- $giLineEndings = "CRLF"
28
- $giContent = ""
29
- if (Test-Path $giPath) {
30
- $giContent = Get-Content -Raw -Encoding UTF8 -ErrorAction SilentlyContinue $giPath
31
- if ($null -eq $giContent) { $giContent = "" }
32
- if ($giContent.Length -gt 0 -and [int]$giContent[0] -eq 0xFEFF) { $giContent = $giContent.Substring(1) }
33
- $giLineEndings = if ($giContent -match "`r`n") { "CRLF" } else { "LF" }
34
- }
35
-
36
- $newBlock = $giBeginMarker + "`n" + ($ignoreLines -join "`n") + "`n" + $giEndMarker
37
-
38
- if ($script:DryRun) {
39
- Write-Host "[DRY RUN] WOULD UPDATE: $giPath (managed Mnemo block)" -ForegroundColor DarkCyan
40
- return
41
- }
42
-
43
- $beginEsc = [regex]::Escape($giBeginMarker)
44
- $endEsc = [regex]::Escape($giEndMarker)
45
- $blockPattern = "(?s)$beginEsc.*?$endEsc"
46
-
47
- if ($giContent -match $blockPattern) {
48
- $newContent = [regex]::Replace($giContent, $blockPattern, $newBlock.Replace('$', '$$'))
49
- $existingNorm = $giContent -replace "`r?`n", "`n"
50
- $newNorm = $newContent -replace "`r?`n", "`n"
51
- if ($newNorm -ne $existingNorm) {
52
- $enc = New-Object System.Text.UTF8Encoding($false)
53
- $normalized = if ($giLineEndings -eq "CRLF") { $newContent -replace "`r?`n", "`r`n" } else { $newContent -replace "`r?`n", "`n" }
54
- [System.IO.File]::WriteAllText($giPath, $normalized, $enc)
55
- Write-Host "WROTE: $giPath (updated Mnemo managed block)" -ForegroundColor Green
56
- } else {
57
- Write-Host "SKIP (exists): $giPath (Mnemo managed block unchanged)" -ForegroundColor DarkYellow
58
- }
59
- } else {
60
- $trimmed = $giContent.TrimEnd("`r", "`n")
61
- $sep = if ($trimmed.Length -gt 0) { "`n`n" } else { "" }
62
- $newContent = $trimmed + $sep + $newBlock + "`n"
63
- $enc = New-Object System.Text.UTF8Encoding($false)
64
- $normalized = if ($giLineEndings -eq "CRLF") { $newContent -replace "`r?`n", "`r`n" } else { $newContent -replace "`r?`n", "`n" }
65
- [System.IO.File]::WriteAllText($giPath, $normalized, $enc)
66
- Write-Host "WROTE: $giPath (added Mnemo managed block)" -ForegroundColor Green
67
- }
68
- }
1
+ <#
2
+ gitignore_setup.ps1 - Managed .gitignore block for Mnemo generated artifacts.
3
+ Dot-sourced by bootstrap.ps1.
4
+ #>
5
+
6
+ function Update-MnemoGitignore {
7
+ param(
8
+ [Parameter(Mandatory=$true)][hashtable]$Ctx,
9
+ [switch]$EnableVector
10
+ )
11
+
12
+ $giPath = Join-Path $Ctx.RepoRoot ".gitignore"
13
+ $giBeginMarker = "# >>> Mnemo (generated) - do not edit this block manually <<<"
14
+ $giEndMarker = "# <<< Mnemo (generated) >>>"
15
+
16
+ # User-facing default: ignore the full Mnemo generated footprint so target repos stay clean by default.
17
+ $ignoreLines = @(
18
+ ".mnemo/",
19
+ ".cursor/memory/",
20
+ ".cursor/rules/",
21
+ ".cursor/skills/",
22
+ ".cursor/mcp.json",
23
+ ".agent/rules/",
24
+ "scripts/memory/",
25
+ ".githooks/"
26
+ )
27
+
28
+ $giLineEndings = "CRLF"
29
+ $giContent = ""
30
+ if (Test-Path $giPath) {
31
+ $giContent = Get-Content -Raw -Encoding UTF8 -ErrorAction SilentlyContinue $giPath
32
+ if ($null -eq $giContent) { $giContent = "" }
33
+ if ($giContent.Length -gt 0 -and [int]$giContent[0] -eq 0xFEFF) { $giContent = $giContent.Substring(1) }
34
+ $giLineEndings = if ($giContent -match "`r`n") { "CRLF" } else { "LF" }
35
+ }
36
+
37
+ $newBlock = $giBeginMarker + "`n" + ($ignoreLines -join "`n") + "`n" + $giEndMarker
38
+
39
+ if ($script:DryRun) {
40
+ Write-Host "[DRY RUN] WOULD UPDATE: $giPath (managed Mnemo block)" -ForegroundColor DarkCyan
41
+ return
42
+ }
43
+
44
+ $beginEsc = [regex]::Escape($giBeginMarker)
45
+ $endEsc = [regex]::Escape($giEndMarker)
46
+ $blockPattern = "(?s)$beginEsc.*?$endEsc"
47
+
48
+ if ($giContent -match $blockPattern) {
49
+ $newContent = [regex]::Replace($giContent, $blockPattern, $newBlock.Replace('$', '$$'))
50
+ $existingNorm = $giContent -replace "`r?`n", "`n"
51
+ $newNorm = $newContent -replace "`r?`n", "`n"
52
+ if ($newNorm -ne $existingNorm) {
53
+ $enc = New-Object System.Text.UTF8Encoding($false)
54
+ $normalized = if ($giLineEndings -eq "CRLF") { $newContent -replace "`r?`n", "`r`n" } else { $newContent -replace "`r?`n", "`n" }
55
+ [System.IO.File]::WriteAllText($giPath, $normalized, $enc)
56
+ Write-Host "WROTE: $giPath (updated Mnemo managed block)" -ForegroundColor Green
57
+ } else {
58
+ Write-Host "SKIP (exists): $giPath (Mnemo managed block unchanged)" -ForegroundColor DarkYellow
59
+ }
60
+ } else {
61
+ $trimmed = $giContent.TrimEnd("`r", "`n")
62
+ $sep = if ($trimmed.Length -gt 0) { "`n`n" } else { "" }
63
+ $newContent = $trimmed + $sep + $newBlock + "`n"
64
+ $enc = New-Object System.Text.UTF8Encoding($false)
65
+ $normalized = if ($giLineEndings -eq "CRLF") { $newContent -replace "`r?`n", "`r`n" } else { $newContent -replace "`r?`n", "`n" }
66
+ [System.IO.File]::WriteAllText($giPath, $normalized, $enc)
67
+ Write-Host "WROTE: $giPath (added Mnemo managed block)" -ForegroundColor Green
68
+ }
69
+ }
@@ -436,6 +436,16 @@ function Install-MemoryScripts {
436
436
  -ForceWrite:$Force
437
437
  }
438
438
 
439
+ $cursorSkillTemplates = @("SKILL.md", "reference.md")
440
+ foreach ($f in $cursorSkillTemplates) {
441
+ Install-TemplateFile `
442
+ -TemplateName "skills\mnemo-codebase-optimizer\$f" `
443
+ -DestPath (Join-Path $Ctx.CursorDir "skills\mnemo-codebase-optimizer\$f") `
444
+ -InstallerRoot $InstallerRoot `
445
+ -LineEndings "LF" `
446
+ -ForceWrite:$Force
447
+ }
448
+
439
449
  if ($EnableVector) {
440
450
  Install-TemplateFile `
441
451
  -TemplateName "mnemo_vector.py" `
@@ -77,10 +77,26 @@ def _parse_env_line(raw_line: str) -> tuple[str, str] | None:
77
77
  return key, value
78
78
 
79
79
 
80
+ def _is_missing_env_value(value: str | None) -> bool:
81
+ if value is None:
82
+ return True
83
+ stripped = value.strip()
84
+ if not stripped:
85
+ return True
86
+ # Cursor MCP placeholders can arrive as literal strings in some launches.
87
+ if stripped.startswith("${env:") and stripped.endswith("}"):
88
+ return True
89
+ return False
90
+
91
+
92
+ def _get_env_value(name: str) -> str:
93
+ value = os.getenv(name)
94
+ if _is_missing_env_value(value):
95
+ return ""
96
+ return value.strip()
97
+
98
+
80
99
  def _load_project_env(repo_root: Path) -> None:
81
- # Keep shell-provided values authoritative; only fill missing vars from .env.
82
- if os.getenv("GEMINI_API_KEY"):
83
- return
84
100
  env_path = repo_root / ".env"
85
101
  if not env_path.exists():
86
102
  return
@@ -90,17 +106,28 @@ def _load_project_env(repo_root: Path) -> None:
90
106
  if not parsed:
91
107
  continue
92
108
  key, value = parsed
93
- os.environ.setdefault(key, value)
109
+ key = key.lstrip("\ufeff")
110
+ if _is_missing_env_value(os.getenv(key)):
111
+ os.environ[key] = value
94
112
  except OSError:
95
113
  pass
96
114
 
97
115
 
116
+ def _resolve_provider() -> str:
117
+ configured = os.getenv("MNEMO_PROVIDER", "").strip().lower()
118
+ if configured.startswith("${env:") and configured.endswith("}"):
119
+ configured = ""
120
+ if configured in {"openai", "gemini"}:
121
+ return configured
122
+ return "gemini" if _get_env_value("GEMINI_API_KEY") else "openai"
123
+
124
+
98
125
  MEM_ROOT = _resolve_memory_root()
99
126
  REPO_ROOT = _resolve_repo_root(MEM_ROOT)
100
127
  _load_project_env(REPO_ROOT)
101
128
  _DB_OVERRIDE = os.getenv("MNEMO_DB_PATH", "").strip()
102
129
  DB_PATH = Path(_DB_OVERRIDE).expanduser().resolve() if _DB_OVERRIDE else (MEM_ROOT / "mnemo_vector.sqlite")
103
- PROVIDER = os.getenv("MNEMO_PROVIDER", "gemini" if os.getenv("GEMINI_API_KEY") else "openai").lower()
130
+ PROVIDER = _resolve_provider()
104
131
 
105
132
  SKIP_NAMES = {
106
133
  "README.md", "index.md", "lessons-index.json",
@@ -158,14 +185,14 @@ def _get_embed_client():
158
185
  return _EMBED_CLIENT
159
186
 
160
187
  if PROVIDER == "gemini":
161
- key = os.getenv("GEMINI_API_KEY")
188
+ key = _get_env_value("GEMINI_API_KEY")
162
189
  if not key:
163
190
  raise RuntimeError("GEMINI_API_KEY is not set")
164
191
  from google import genai
165
192
  _EMBED_CLIENT = genai.Client(api_key=key)
166
193
  return _EMBED_CLIENT
167
194
 
168
- key = os.getenv("OPENAI_API_KEY")
195
+ key = _get_env_value("OPENAI_API_KEY")
169
196
  if not key:
170
197
  raise RuntimeError("OPENAI_API_KEY is not set")
171
198
  from openai import OpenAI
@@ -0,0 +1,137 @@
1
+ ---
2
+ name: mnemo-codebase-optimizer
3
+ description: Builds high-signal Mnemo memory quickly for any codebase by mapping architecture, ownership, workflows, risks, and commands, then writing optimized memo/hot-rules/active-context/lessons/journal entries and validating retrieval quality. Use when users ask to bootstrap Mnemo memory, optimize project context, or fill memory in a new or existing repository.
4
+ ---
5
+
6
+ # Mnemo Codebase Optimizer
7
+
8
+ ## Purpose
9
+
10
+ Use this skill to rapidly produce a detailed, reliable Mnemo knowledge base for any project.
11
+ The goal is high retrieval quality with low token waste.
12
+
13
+ ## Quick Start
14
+
15
+ Use this checklist and keep one step `in_progress` at a time:
16
+
17
+ ```text
18
+ Memory Seeding Progress
19
+ - [ ] 1) Confirm Mnemo install + paths
20
+ - [ ] 2) Map codebase architecture and ownership
21
+ - [ ] 3) Extract runbook commands and dev workflows
22
+ - [ ] 4) Write/update core memory files
23
+ - [ ] 5) Add initial lessons and journal summary
24
+ - [ ] 6) Rebuild + lint + (optional) vector sync
25
+ - [ ] 7) Validate retrieval quality and refine
26
+ ```
27
+
28
+ ## 1) Confirm Mnemo Install
29
+
30
+ Verify these paths exist:
31
+ - `.mnemo/memory/`
32
+ - `.mnemo/rules/`
33
+ - `scripts/memory/`
34
+
35
+ If missing, run installer first and stop this skill until setup succeeds.
36
+
37
+ ## 2) Map Architecture Fast
38
+
39
+ Collect only high-value context:
40
+ - product purpose and core user flows
41
+ - entrypoints and runtime boundaries (frontend/backend/workers/CLI)
42
+ - module ownership and key responsibilities
43
+ - data model sources and contracts
44
+ - integration surfaces (APIs, queues, webhooks, external services)
45
+ - quality/security constraints and release workflow
46
+
47
+ Avoid copying large code blocks into memory files. Summarize and reference paths.
48
+
49
+ ## 3) Capture Operational Workflow
50
+
51
+ Record:
52
+ - install/build/test/lint commands
53
+ - local run commands for each app/service
54
+ - deployment/release commands and prerequisites
55
+ - debugging commands and common failure signatures
56
+
57
+ Prefer explicit command examples over vague prose.
58
+
59
+ ## 4) Write Core Memory Files
60
+
61
+ Update these files in priority order:
62
+
63
+ 1. `.mnemo/memory/hot-rules.md`
64
+ - 10-20 lines max
65
+ - only hard invariants and "never do" rules
66
+ 2. `.mnemo/memory/memo.md`
67
+ - architecture map, ownership, critical paths, runbook
68
+ 3. `.mnemo/memory/active-context.md`
69
+ - current migration task + open risks + next actions
70
+
71
+ Use short sections and bullets. Keep each bullet atomic and testable.
72
+
73
+ ## 5) Seed Lessons + Journal
74
+
75
+ Create 3-8 starter lessons from known pitfalls:
76
+ - naming conventions
77
+ - data migration gotchas
78
+ - environment/setup traps
79
+ - release regressions and prevention checks
80
+
81
+ Add one monthly journal entry summarizing:
82
+ - what memory was seeded
83
+ - why those sections matter
84
+ - what remains unknown
85
+
86
+ ## 6) Rebuild and Validate
87
+
88
+ Run:
89
+ - `scripts/memory/rebuild-memory-index.ps1` (or shell equivalent)
90
+ - `scripts/memory/lint-memory.ps1` (or shell equivalent)
91
+
92
+ If vector mode is enabled:
93
+ - run `vector_sync`
94
+ - run `vector_health`
95
+
96
+ ## 7) Retrieval Quality Gate
97
+
98
+ Ask 5-10 realistic queries and verify results:
99
+ - architecture query (module boundaries)
100
+ - workflow query (how to run/test/release)
101
+ - ownership query (who owns what)
102
+ - pitfall query (common mistakes)
103
+ - troubleshooting query (known failure/fix)
104
+
105
+ If retrieval misses:
106
+ - tighten memo headings
107
+ - split overloaded bullets
108
+ - add a lesson instead of bloating memo
109
+ - prune low-signal historical text
110
+
111
+ ## Memory Quality Rules
112
+
113
+ - Keep `hot-rules.md` tiny and immutable-focused.
114
+ - Keep `memo.md` as current truth, not raw history.
115
+ - Put historical detail in journal, not memo.
116
+ - Prefer lessons for reusable error-prevention patterns.
117
+ - Use stable terminology for search consistency.
118
+ - Every important claim should map to concrete file paths or commands.
119
+
120
+ ## Output Contract
121
+
122
+ When done, return:
123
+
124
+ 1. **Coverage summary**
125
+ - what domains are now represented in memory
126
+ 2. **Files changed**
127
+ - list of memory files updated/created
128
+ 3. **Quality checks**
129
+ - rebuild/lint/vector status
130
+ 4. **Top retrieval queries**
131
+ - sample queries and expected hit files
132
+ 5. **Remaining unknowns**
133
+ - explicit gaps to fill in next pass
134
+
135
+ ## Additional Resources
136
+
137
+ - Detailed templates: [reference.md](reference.md)
@@ -0,0 +1,138 @@
1
+ # Mnemo Codebase Optimizer Reference
2
+
3
+ ## Memo Template (Detailed)
4
+
5
+ Use this structure for `.mnemo/memory/memo.md`:
6
+
7
+ ```markdown
8
+ # Project Memo - <project>
9
+
10
+ ## Mission
11
+ - One-paragraph purpose and primary user outcomes.
12
+
13
+ ## System Shape
14
+ - Runtime components:
15
+ - `<component>`: `<responsibility>`
16
+ - Boundaries:
17
+ - `<boundary>` -> `<dependency>`
18
+
19
+ ## Ownership Map
20
+ - `<module/path>` -> `<team/owner>`
21
+ - `<module/path>` -> `<team/owner>`
22
+
23
+ ## Critical Flows
24
+ - Flow A:
25
+ - Trigger:
26
+ - Core path:
27
+ - Side effects:
28
+ - Failure modes:
29
+ - Flow B:
30
+ - Trigger:
31
+ - Core path:
32
+ - Side effects:
33
+ - Failure modes:
34
+
35
+ ## Data Contracts
36
+ - `<type/schema/file>`: purpose + key fields + constraints
37
+ - `<type/schema/file>`: purpose + key fields + constraints
38
+
39
+ ## Commands Runbook
40
+ - Install: `<command>`
41
+ - Dev run: `<command>`
42
+ - Tests: `<command>`
43
+ - Lint/format: `<command>`
44
+ - Build/release: `<command>`
45
+
46
+ ## Constraints and Guardrails
47
+ - Non-negotiables:
48
+ - `<rule>`
49
+ - `<rule>`
50
+ - Security/compliance:
51
+ - `<constraint>`
52
+
53
+ ## Known Risks
54
+ - `<risk>` -> detection -> mitigation
55
+ - `<risk>` -> detection -> mitigation
56
+ ```
57
+
58
+ ## Hot Rules Template
59
+
60
+ Use this structure for `.mnemo/memory/hot-rules.md` (10-20 lines):
61
+
62
+ ```markdown
63
+ # Hot Rules
64
+
65
+ - Never bypass `<critical check>`.
66
+ - Do not edit `<generated path>` manually.
67
+ - Keep `<artifact>` synchronized with `<source>`.
68
+ - Before release: run `<required command list>`.
69
+ - If `<failure condition>`, stop and verify `<source of truth>`.
70
+ ```
71
+
72
+ ## Active Context Template
73
+
74
+ Use this structure for `.mnemo/memory/active-context.md`:
75
+
76
+ ```markdown
77
+ # Active Context
78
+
79
+ ## Current Task
80
+ - Goal:
81
+ - Scope:
82
+ - Out of scope:
83
+
84
+ ## Working Notes
85
+ - Current status:
86
+ - Decisions made:
87
+ - Risks and blockers:
88
+
89
+ ## Next Actions
90
+ 1. `<action>`
91
+ 2. `<action>`
92
+ 3. `<action>`
93
+ ```
94
+
95
+ ## Starter Lesson Template
96
+
97
+ Use this for each `L-XXX-*.md`:
98
+
99
+ ```markdown
100
+ ---
101
+ id: L-XXX
102
+ title: "<short pitfall title>"
103
+ tags: ["pitfall", "regression", "<domain>"]
104
+ applies_to: ["<path/glob>"]
105
+ rule: "<single actionable rule>"
106
+ ---
107
+
108
+ ## Context
109
+ When this appears and why it happens.
110
+
111
+ ## Failure Pattern
112
+ Observable signs and likely root causes.
113
+
114
+ ## Corrective Action
115
+ Exact steps to fix safely.
116
+
117
+ ## Prevention Check
118
+ How to detect it before merge/release.
119
+ ```
120
+
121
+ ## Retrieval Validation Query Set
122
+
123
+ Run and confirm each query returns high-signal files:
124
+
125
+ 1. "What are the core runtime boundaries?"
126
+ 2. "Which files define the main data contracts?"
127
+ 3. "How do I run full tests and lint before release?"
128
+ 4. "What regressions happened before and how do we prevent them?"
129
+ 5. "Who owns `<critical module>` and what are the rules?"
130
+ 6. "What are the top production risks in this repo?"
131
+
132
+ ## Optimization Heuristics
133
+
134
+ - Prefer one clear heading over long paragraphs.
135
+ - Replace duplicate bullets with one canonical bullet.
136
+ - If a memo section grows too long, split into lessons.
137
+ - Keep journaling chronological; keep memo conceptual.
138
+ - Remove stale TODOs from memo; keep only current truth.