@dinasor/mnemo-cli 0.0.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/CHANGELOG.md +46 -0
- package/LICENSE +21 -0
- package/README.md +263 -0
- package/VERSION +1 -0
- package/bin/mnemo.js +139 -0
- package/memory.ps1 +178 -0
- package/memory_mac.sh +2447 -0
- package/package.json +36 -0
- package/scripts/memory/installer/bootstrap.ps1 +21 -0
- package/scripts/memory/installer/core/bridge.ps1 +285 -0
- package/scripts/memory/installer/core/io.ps1 +110 -0
- package/scripts/memory/installer/core/paths.ps1 +83 -0
- package/scripts/memory/installer/features/gitignore_setup.ps1 +80 -0
- package/scripts/memory/installer/features/hooks_setup.ps1 +157 -0
- package/scripts/memory/installer/features/mcp_setup.ps1 +87 -0
- package/scripts/memory/installer/features/memory_scaffold.ps1 +541 -0
- package/scripts/memory/installer/features/vector_setup.ps1 +103 -0
- package/scripts/memory/installer/templates/add-journal-entry.ps1 +122 -0
- package/scripts/memory/installer/templates/add-lesson.ps1 +151 -0
- package/scripts/memory/installer/templates/autonomy/__init__.py +6 -0
- package/scripts/memory/installer/templates/autonomy/context_safety.py +181 -0
- package/scripts/memory/installer/templates/autonomy/entity_resolver.py +215 -0
- package/scripts/memory/installer/templates/autonomy/ingest_pipeline.py +252 -0
- package/scripts/memory/installer/templates/autonomy/lifecycle_engine.py +254 -0
- package/scripts/memory/installer/templates/autonomy/policies.yaml +59 -0
- package/scripts/memory/installer/templates/autonomy/reranker.py +220 -0
- package/scripts/memory/installer/templates/autonomy/retrieval_router.py +148 -0
- package/scripts/memory/installer/templates/autonomy/runner.py +272 -0
- package/scripts/memory/installer/templates/autonomy/schema.py +150 -0
- package/scripts/memory/installer/templates/autonomy/vault_policy.py +205 -0
- package/scripts/memory/installer/templates/build-memory-sqlite.py +111 -0
- package/scripts/memory/installer/templates/clear-active.ps1 +55 -0
- package/scripts/memory/installer/templates/customization.md +84 -0
- package/scripts/memory/installer/templates/lint-memory.ps1 +217 -0
- package/scripts/memory/installer/templates/mnemo_vector.py +556 -0
- package/scripts/memory/installer/templates/query-memory-sqlite.py +95 -0
- package/scripts/memory/installer/templates/query-memory.ps1 +122 -0
- package/scripts/memory/installer/templates/rebuild-memory-index.ps1 +293 -0
|
@@ -0,0 +1,541 @@
|
|
|
1
|
+
<#
|
|
2
|
+
memory_scaffold.ps1 - Installs memory content files and multi-agent bridges.
|
|
3
|
+
Dot-sourced by bootstrap.ps1. Depends on io.ps1 functions.
|
|
4
|
+
#>
|
|
5
|
+
|
|
6
|
+
function Install-MemoryScaffold {
|
|
7
|
+
param(
|
|
8
|
+
[Parameter(Mandatory=$true)][hashtable]$Ctx,
|
|
9
|
+
[Parameter(Mandatory=$true)][string]$ProjectName,
|
|
10
|
+
[Parameter(Mandatory=$true)][string]$MnemoVersion,
|
|
11
|
+
[switch]$Force
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
$month = (Get-Date -Format "yyyy-MM")
|
|
15
|
+
$today = (Get-Date -Format "yyyy-MM-dd")
|
|
16
|
+
|
|
17
|
+
$indexMd = @"
|
|
18
|
+
# Memory Index
|
|
19
|
+
|
|
20
|
+
Entry point for repo memory.
|
|
21
|
+
|
|
22
|
+
## Read order (token-safe)
|
|
23
|
+
|
|
24
|
+
ALWAYS READ (in order):
|
|
25
|
+
1) ``hot-rules.md`` (tiny invariants, <20 lines)
|
|
26
|
+
2) ``active-context.md`` (this session only)
|
|
27
|
+
3) ``memo.md`` (long-term current truth + ownership)
|
|
28
|
+
|
|
29
|
+
SEARCH FIRST, THEN OPEN ONLY WHAT MATCHES:
|
|
30
|
+
4) ``lessons/index.md`` -> find lesson ID(s)
|
|
31
|
+
5) ``lessons/L-XXX-*.md`` -> open only specific lesson(s)
|
|
32
|
+
6) ``digests/YYYY-MM.digest.md`` -> before raw journal
|
|
33
|
+
7) ``journal/YYYY-MM.md`` -> only for archaeology
|
|
34
|
+
|
|
35
|
+
## Files
|
|
36
|
+
|
|
37
|
+
- Hot rules: ``hot-rules.md``
|
|
38
|
+
- Active context: ``active-context.md``
|
|
39
|
+
- Memo: ``memo.md``
|
|
40
|
+
- Lessons: ``lessons/``
|
|
41
|
+
- Lesson index (generated): ``lessons/index.md`` + ``lessons-index.json``
|
|
42
|
+
- Journal monthly: ``journal/YYYY-MM.md``
|
|
43
|
+
- Journal index (generated): ``journal-index.md`` + ``journal-index.json``
|
|
44
|
+
- Digests (generated): ``digests/YYYY-MM.digest.md``
|
|
45
|
+
- Tag vocabulary: ``tag-vocabulary.md``
|
|
46
|
+
- Regression checklist: ``regression-checklist.md``
|
|
47
|
+
- ADRs: ``adr/``
|
|
48
|
+
|
|
49
|
+
## Maintenance commands
|
|
50
|
+
|
|
51
|
+
Helper scripts:
|
|
52
|
+
- Add lesson: ``scripts/memory/add-lesson.ps1 -Title "..." -Tags "..." -Rule "..."``
|
|
53
|
+
- Add journal: ``scripts/memory/add-journal-entry.ps1 -Tags "..." -Title "..."``
|
|
54
|
+
- Rebuild indexes: ``scripts/memory/rebuild-memory-index.ps1``
|
|
55
|
+
- Lint: ``scripts/memory/lint-memory.ps1``
|
|
56
|
+
- Query (grep): ``scripts/memory/query-memory.ps1 -Query "..."``
|
|
57
|
+
- Query (SQLite): ``scripts/memory/query-memory.ps1 -Query "..." -UseSqlite``
|
|
58
|
+
- Clear session: ``scripts/memory/clear-active.ps1``
|
|
59
|
+
"@
|
|
60
|
+
|
|
61
|
+
$hotRules = @"
|
|
62
|
+
# Hot Rules (MUST READ)
|
|
63
|
+
|
|
64
|
+
Keep this file under ~20 lines. If it grows, move content into memo or lessons.
|
|
65
|
+
|
|
66
|
+
## Authority Order (highest to lowest)
|
|
67
|
+
1) Lessons override EVERYTHING (including active-context)
|
|
68
|
+
2) active-context.md overrides memo/journal (but NOT lessons)
|
|
69
|
+
3) memo.md is long-term project truth
|
|
70
|
+
4) journal is history
|
|
71
|
+
|
|
72
|
+
## Retrieval Rules
|
|
73
|
+
5) Do NOT scan raw journals. Use indexes/digests first.
|
|
74
|
+
6) Reuse existing patterns. Check memo.md ownership before creating new systems.
|
|
75
|
+
7) When done: clear active-context.md, add journal entry if significant.
|
|
76
|
+
"@
|
|
77
|
+
|
|
78
|
+
$activeContext = @"
|
|
79
|
+
# Active Context (Session Scratchpad)
|
|
80
|
+
|
|
81
|
+
Priority: this overrides older journal history *for this session only*.
|
|
82
|
+
|
|
83
|
+
CLEAR this file when the task is done:
|
|
84
|
+
- Run ``scripts/memory/clear-active.ps1``
|
|
85
|
+
|
|
86
|
+
## Current Goal
|
|
87
|
+
-
|
|
88
|
+
|
|
89
|
+
## Files in Focus
|
|
90
|
+
-
|
|
91
|
+
|
|
92
|
+
## Findings / Decisions
|
|
93
|
+
-
|
|
94
|
+
|
|
95
|
+
## Temporary Constraints
|
|
96
|
+
-
|
|
97
|
+
|
|
98
|
+
## Blockers
|
|
99
|
+
-
|
|
100
|
+
"@
|
|
101
|
+
|
|
102
|
+
$memo = @"
|
|
103
|
+
# Project Memo - $ProjectName
|
|
104
|
+
|
|
105
|
+
Last updated: $today
|
|
106
|
+
|
|
107
|
+
## Ownership map (fill early)
|
|
108
|
+
|
|
109
|
+
- UI / Frontend owner: <path/module>
|
|
110
|
+
- Backend / Server owner: <path/module>
|
|
111
|
+
- Data parsing / protocol owner: <path/module>
|
|
112
|
+
- Build/CI owner: <path/module>
|
|
113
|
+
|
|
114
|
+
## Current truth (high-signal)
|
|
115
|
+
|
|
116
|
+
- <invariants that must stay true>
|
|
117
|
+
- <important defaults/toggles>
|
|
118
|
+
- <timing/lifecycle rules>
|
|
119
|
+
- <anything that prevents regressions>
|
|
120
|
+
|
|
121
|
+
## Open questions / TODO
|
|
122
|
+
- <unknowns / risks>
|
|
123
|
+
"@
|
|
124
|
+
|
|
125
|
+
$journalMonth = @"
|
|
126
|
+
# Development Journal - $ProjectName ($month)
|
|
127
|
+
|
|
128
|
+
## $today
|
|
129
|
+
|
|
130
|
+
- [Process] Initialized memory system (Mnemo v$MnemoVersion)
|
|
131
|
+
- Why: token-safe AI memory + indexed retrieval + portable hooks
|
|
132
|
+
- Key files:
|
|
133
|
+
- ``.cursor/memory/*``
|
|
134
|
+
- ``.cursor/rules/00-memory-system.mdc``
|
|
135
|
+
- ``scripts/memory/*``
|
|
136
|
+
"@
|
|
137
|
+
|
|
138
|
+
$memoryRule = @"
|
|
139
|
+
---
|
|
140
|
+
description: Memory System v$MnemoVersion - Authority + Atomic Retrieval + Token Safety
|
|
141
|
+
globs:
|
|
142
|
+
- "**/*"
|
|
143
|
+
alwaysApply: true
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
# Memory System (MANDATORY)
|
|
147
|
+
|
|
148
|
+
## Authority Order (highest to lowest)
|
|
149
|
+
1) Lessons override EVERYTHING (including active-context)
|
|
150
|
+
2) ``active-context.md`` overrides memo/journal (but NOT lessons)
|
|
151
|
+
3) ``memo.md`` is long-term project truth
|
|
152
|
+
4) Journal is history
|
|
153
|
+
5) Existing codebase
|
|
154
|
+
6) New suggestions (lowest priority)
|
|
155
|
+
|
|
156
|
+
## Token-Safe Retrieval
|
|
157
|
+
|
|
158
|
+
ALWAYS READ (in order):
|
|
159
|
+
1. ``.cursor/memory/hot-rules.md`` (tiny, <20 lines)
|
|
160
|
+
2. ``.cursor/memory/active-context.md`` (current session state)
|
|
161
|
+
3. ``.cursor/memory/memo.md`` (project truth + ownership)
|
|
162
|
+
|
|
163
|
+
SEARCH FIRST, THEN FETCH:
|
|
164
|
+
4. ``.cursor/memory/lessons/index.md`` -> find relevant lesson ID
|
|
165
|
+
5. ``.cursor/memory/lessons/L-XXX-title.md`` -> load ONLY the specific file
|
|
166
|
+
6. ``.cursor/memory/digests/YYYY-MM.digest.md`` -> before raw journal
|
|
167
|
+
7. ``.cursor/memory/journal/YYYY-MM.md`` -> only for archaeology
|
|
168
|
+
|
|
169
|
+
## After Any Feature/Fix
|
|
170
|
+
|
|
171
|
+
1. Update ``active-context.md`` during work (scratchpad)
|
|
172
|
+
2. Add journal entry to ``journal/YYYY-MM.md`` when done
|
|
173
|
+
3. Create ``lessons/L-XXX-title.md`` if you discovered a pitfall
|
|
174
|
+
4. Update ``memo.md`` if project truth changed
|
|
175
|
+
5. Clear ``active-context.md`` when task is merged
|
|
176
|
+
|
|
177
|
+
## Helper Scripts
|
|
178
|
+
|
|
179
|
+
- Add lesson: ``scripts/memory/add-lesson.ps1 -Title "..." -Tags "..." -Rule "..."``
|
|
180
|
+
- Add journal: ``scripts/memory/add-journal-entry.ps1 -Tags "..." -Title "..."``
|
|
181
|
+
- Rebuild: ``scripts/memory/rebuild-memory-index.ps1``
|
|
182
|
+
- Lint: ``scripts/memory/lint-memory.ps1``
|
|
183
|
+
- Query: ``scripts/memory/query-memory.ps1 -Query "..." [-UseSqlite]``
|
|
184
|
+
- Clear: ``scripts/memory/clear-active.ps1``
|
|
185
|
+
|
|
186
|
+
## AI Behavior
|
|
187
|
+
|
|
188
|
+
- When user says "I'm done" or "merge this" -> remind to clear active-context
|
|
189
|
+
- When you discover a bug pattern -> suggest creating a lesson
|
|
190
|
+
- When unsure about architecture -> check lessons/index.md first
|
|
191
|
+
- Don't create parallel systems -> check memo.md ownership map
|
|
192
|
+
"@
|
|
193
|
+
|
|
194
|
+
$claudeMd = @"
|
|
195
|
+
# Project Memory (Mnemo)
|
|
196
|
+
|
|
197
|
+
This project uses [Mnemo](https://github.com/DiNaSoR/Mnemo) for structured AI memory.
|
|
198
|
+
Memory lives in ``.cursor/memory/`` as the single source of truth.
|
|
199
|
+
|
|
200
|
+
## Read Order (ALWAYS)
|
|
201
|
+
1. ``.cursor/memory/hot-rules.md`` - tiny invariants (<20 lines)
|
|
202
|
+
2. ``.cursor/memory/active-context.md`` - current session state
|
|
203
|
+
3. ``.cursor/memory/memo.md`` - long-term project truth + ownership
|
|
204
|
+
|
|
205
|
+
## Search First, Then Fetch
|
|
206
|
+
- ``.cursor/memory/lessons/index.md`` -> find lesson ID -> open only that lesson file
|
|
207
|
+
- ``.cursor/memory/digests/YYYY-MM.digest.md`` -> before raw journal archaeology
|
|
208
|
+
- ``.cursor/memory/journal/YYYY-MM.md`` -> only for deep history
|
|
209
|
+
|
|
210
|
+
## After Any Feature/Fix
|
|
211
|
+
1. Update ``active-context.md`` during work
|
|
212
|
+
2. Add journal entry when done
|
|
213
|
+
3. Create lesson if you discovered a pitfall
|
|
214
|
+
4. Update ``memo.md`` if project truth changed
|
|
215
|
+
5. Clear ``active-context.md`` when task is merged
|
|
216
|
+
"@
|
|
217
|
+
|
|
218
|
+
$static = @{
|
|
219
|
+
(Join-Path $Ctx.MemoryDir "index.md") = $indexMd
|
|
220
|
+
(Join-Path $Ctx.MemoryDir "hot-rules.md") = $hotRules
|
|
221
|
+
(Join-Path $Ctx.MemoryDir "active-context.md") = $activeContext
|
|
222
|
+
(Join-Path $Ctx.MemoryDir "memo.md") = $memo
|
|
223
|
+
(Join-Path $Ctx.JournalDir "$month.md") = $journalMonth
|
|
224
|
+
(Join-Path $Ctx.RulesDir "00-memory-system.mdc") = $memoryRule
|
|
225
|
+
(Join-Path $Ctx.RepoRoot "CLAUDE.md") = $claudeMd
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
foreach ($kv in $static.GetEnumerator()) {
|
|
229
|
+
Write-MnemoFile -Path $kv.Key -Content $kv.Value -ForceWrite:$Force
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
# Static content files (small enough to keep inline)
|
|
233
|
+
Write-MnemoFile (Join-Path $Ctx.LessonsDir "README.md") @"
|
|
234
|
+
# Lessons (Atomic)
|
|
235
|
+
|
|
236
|
+
Each lesson is a separate file with strict YAML frontmatter.
|
|
237
|
+
|
|
238
|
+
Naming: ``L-001-short-title.md``
|
|
239
|
+
|
|
240
|
+
Create: ``scripts/memory/add-lesson.ps1 -Title "..." -Tags "..." -Rule "..."``
|
|
241
|
+
"@ -ForceWrite:$Force
|
|
242
|
+
|
|
243
|
+
Write-MnemoFile (Join-Path $Ctx.LessonsDir "index.md") @"
|
|
244
|
+
# Lessons Index (generated)
|
|
245
|
+
|
|
246
|
+
Generated by ``scripts/memory/rebuild-memory-index.ps1``.
|
|
247
|
+
|
|
248
|
+
Format: ID | [Tags] | AppliesTo | Rule | File
|
|
249
|
+
|
|
250
|
+
(No lessons yet.)
|
|
251
|
+
"@ -ForceWrite:$Force
|
|
252
|
+
|
|
253
|
+
Write-MnemoFile (Join-Path $Ctx.JournalDir "README.md") @"
|
|
254
|
+
# Journal
|
|
255
|
+
|
|
256
|
+
Monthly file: ``YYYY-MM.md``
|
|
257
|
+
|
|
258
|
+
Rules:
|
|
259
|
+
- Each date appears ONCE per file: ``## YYYY-MM-DD``
|
|
260
|
+
- Put multiple entries under that header as bullets.
|
|
261
|
+
- Keep it high-signal: what changed, why, key files.
|
|
262
|
+
|
|
263
|
+
Add entries via: ``scripts/memory/add-journal-entry.ps1 -Tags "UI,Fix" -Title "..."``
|
|
264
|
+
"@ -ForceWrite:$Force
|
|
265
|
+
|
|
266
|
+
Write-MnemoFile (Join-Path $Ctx.DigestsDir "README.md") @"
|
|
267
|
+
# Digests
|
|
268
|
+
|
|
269
|
+
Generated summaries of journal months.
|
|
270
|
+
AI should read digests before raw journal.
|
|
271
|
+
|
|
272
|
+
Generated by: ``scripts/memory/rebuild-memory-index.ps1``
|
|
273
|
+
"@ -ForceWrite:$Force
|
|
274
|
+
|
|
275
|
+
Write-MnemoFile (Join-Path $Ctx.AdrDir "README.md") @"
|
|
276
|
+
# ADRs
|
|
277
|
+
|
|
278
|
+
Architecture Decision Records: why we did it this way.
|
|
279
|
+
|
|
280
|
+
Naming: ``ADR-001-short-title.md``
|
|
281
|
+
Format: Context / Decision / Consequences
|
|
282
|
+
"@ -ForceWrite:$Force
|
|
283
|
+
|
|
284
|
+
Write-MnemoFile (Join-Path $Ctx.MemoryDir "tag-vocabulary.md") @"
|
|
285
|
+
# Tag Vocabulary (fixed set)
|
|
286
|
+
|
|
287
|
+
Use a small vocabulary so retrieval stays reliable.
|
|
288
|
+
Linter validates tags against this list.
|
|
289
|
+
|
|
290
|
+
- [UI] - UI behavior, rendering, interaction
|
|
291
|
+
- [Layout] - layout groups, anchors, sizing, rects
|
|
292
|
+
- [Input] - mouse/keyboard/controller input rules
|
|
293
|
+
- [Data] - parsing, payloads, formats, state sync
|
|
294
|
+
- [Server] - server-side logic and lifecycle
|
|
295
|
+
- [Init] - initialization / load order / startup
|
|
296
|
+
- [Build] - compilation, MSBuild, project files
|
|
297
|
+
- [CI] - automation, pipelines
|
|
298
|
+
- [Release] - packaging, artifacts, uploads
|
|
299
|
+
- [Compat] - IL2CPP, runtime constraints, environment quirks
|
|
300
|
+
- [Integration] - optional plugins, reflection bridges, external systems
|
|
301
|
+
- [Docs] - documentation and changelog work
|
|
302
|
+
- [Architecture] - module boundaries, refactors, ownership
|
|
303
|
+
- [DX] - developer experience, tooling, maintainability
|
|
304
|
+
- [Reliability] - crash prevention, guardrails, self-healing
|
|
305
|
+
- [Process] - workflow, memory system, tooling changes
|
|
306
|
+
|
|
307
|
+
# Common "type" tags
|
|
308
|
+
- [Fix] - bug fixes, regressions, patches
|
|
309
|
+
- [Feature] - new behavior/capability
|
|
310
|
+
- [Refactor] - restructuring without behavior changes
|
|
311
|
+
"@ -ForceWrite:$Force
|
|
312
|
+
|
|
313
|
+
Write-MnemoFile (Join-Path $Ctx.MemoryDir "regression-checklist.md") @"
|
|
314
|
+
# Regression Checklist
|
|
315
|
+
|
|
316
|
+
Run only what is relevant.
|
|
317
|
+
|
|
318
|
+
## Build
|
|
319
|
+
- [ ] Build solution / affected projects
|
|
320
|
+
- [ ] No new warnings (or documented)
|
|
321
|
+
|
|
322
|
+
## Runtime (if applicable)
|
|
323
|
+
- [ ] Core UI renders
|
|
324
|
+
- [ ] Core interactions work
|
|
325
|
+
- [ ] No obvious errors/log spam
|
|
326
|
+
|
|
327
|
+
## Data (if applicable)
|
|
328
|
+
- [ ] Parsing works on known payloads
|
|
329
|
+
- [ ] State updates do not regress
|
|
330
|
+
|
|
331
|
+
## Docs (if applicable)
|
|
332
|
+
- [ ] Journal updated
|
|
333
|
+
- [ ] Memo updated (if truth changed)
|
|
334
|
+
- [ ] Lesson added (if pitfall discovered)
|
|
335
|
+
"@ -ForceWrite:$Force
|
|
336
|
+
|
|
337
|
+
# Template files
|
|
338
|
+
Write-MnemoFile (Join-Path $Ctx.TemplatesDir "lesson.template.md") @"
|
|
339
|
+
---
|
|
340
|
+
id: L-XXX
|
|
341
|
+
title: Short descriptive title
|
|
342
|
+
status: Active
|
|
343
|
+
tags: [UI, Reliability]
|
|
344
|
+
introduced: YYYY-MM-DD
|
|
345
|
+
applies_to:
|
|
346
|
+
- path/or/glob/**
|
|
347
|
+
triggers:
|
|
348
|
+
- error keyword
|
|
349
|
+
rule: One sentence. Imperative. Testable.
|
|
350
|
+
supersedes: ""
|
|
351
|
+
---
|
|
352
|
+
|
|
353
|
+
# L-XXX - Short descriptive title
|
|
354
|
+
|
|
355
|
+
## Symptom
|
|
356
|
+
What broke / what was observed.
|
|
357
|
+
|
|
358
|
+
## Root cause
|
|
359
|
+
The real reason.
|
|
360
|
+
|
|
361
|
+
## Wrong approach (DO NOT REPEAT)
|
|
362
|
+
- What not to do
|
|
363
|
+
|
|
364
|
+
## Correct approach
|
|
365
|
+
- What to do instead
|
|
366
|
+
|
|
367
|
+
## References
|
|
368
|
+
- Files: ``path/to/file``
|
|
369
|
+
- Journal: ``journal/YYYY-MM.md#YYYY-MM-DD``
|
|
370
|
+
"@ -ForceWrite:$Force
|
|
371
|
+
|
|
372
|
+
Write-MnemoFile (Join-Path $Ctx.TemplatesDir "journal-entry.template.md") @"
|
|
373
|
+
# Journal Entry Template (paste under an existing date header)
|
|
374
|
+
|
|
375
|
+
- [Area][Type] Title
|
|
376
|
+
- Why: ...
|
|
377
|
+
- Key files:
|
|
378
|
+
- ``path/to/file``
|
|
379
|
+
- Notes: <optional>
|
|
380
|
+
- Verification: Build PASS/FAIL/NOT RUN; Runtime PASS/FAIL/NOT RUN
|
|
381
|
+
- Related: Lesson L-XXX; ADR ADR-XXX
|
|
382
|
+
"@ -ForceWrite:$Force
|
|
383
|
+
|
|
384
|
+
Write-MnemoFile (Join-Path $Ctx.TemplatesDir "adr.template.md") @"
|
|
385
|
+
# ADR-XXX - Title
|
|
386
|
+
|
|
387
|
+
Date: YYYY-MM-DD
|
|
388
|
+
Status: Proposed | Accepted | Deprecated
|
|
389
|
+
|
|
390
|
+
## Context
|
|
391
|
+
What problem are we solving?
|
|
392
|
+
|
|
393
|
+
## Decision
|
|
394
|
+
What did we choose?
|
|
395
|
+
|
|
396
|
+
## Consequences
|
|
397
|
+
Tradeoffs, risks, follow-ups.
|
|
398
|
+
"@ -ForceWrite:$Force
|
|
399
|
+
|
|
400
|
+
# Multi-agent bridges
|
|
401
|
+
$geminiRule = @"
|
|
402
|
+
---
|
|
403
|
+
description: Mnemo memory system - structured AI memory in .cursor/memory/
|
|
404
|
+
alwaysApply: true
|
|
405
|
+
---
|
|
406
|
+
|
|
407
|
+
# Memory System (Mnemo)
|
|
408
|
+
|
|
409
|
+
This project uses Mnemo for structured AI memory. All memory lives in ``.cursor/memory/``.
|
|
410
|
+
|
|
411
|
+
## Read Order (ALWAYS)
|
|
412
|
+
1. ``.cursor/memory/hot-rules.md`` - tiny invariants (read first)
|
|
413
|
+
2. ``.cursor/memory/active-context.md`` - current session state
|
|
414
|
+
3. ``.cursor/memory/memo.md`` - project truth + ownership
|
|
415
|
+
|
|
416
|
+
## Authority Order
|
|
417
|
+
1. Lessons override everything
|
|
418
|
+
2. active-context overrides memo/journal (but NOT lessons)
|
|
419
|
+
3. memo.md is long-term truth
|
|
420
|
+
4. Journal is history
|
|
421
|
+
|
|
422
|
+
## After Any Task
|
|
423
|
+
- Update active-context.md during work
|
|
424
|
+
- Add journal entry when done
|
|
425
|
+
- Create lesson if you discovered a pitfall
|
|
426
|
+
- Clear active-context.md when task is merged
|
|
427
|
+
"@
|
|
428
|
+
|
|
429
|
+
$agentsMd = @"
|
|
430
|
+
# Memory System (Mnemo)
|
|
431
|
+
|
|
432
|
+
This project uses Mnemo for structured AI memory.
|
|
433
|
+
Memory location: ``.cursor/memory/``
|
|
434
|
+
|
|
435
|
+
## Retrieval Order
|
|
436
|
+
1. Read ``.cursor/memory/hot-rules.md`` first (tiny, <20 lines)
|
|
437
|
+
2. Read ``.cursor/memory/active-context.md`` for current session
|
|
438
|
+
3. Read ``.cursor/memory/memo.md`` for project truth + ownership
|
|
439
|
+
4. Search ``.cursor/memory/lessons/index.md`` before creating new patterns
|
|
440
|
+
5. Check ``.cursor/memory/digests/`` before raw journal archaeology
|
|
441
|
+
|
|
442
|
+
## Authority Order (highest to lowest)
|
|
443
|
+
1. Lessons override EVERYTHING
|
|
444
|
+
2. active-context.md overrides memo/journal (but NOT lessons)
|
|
445
|
+
3. memo.md is long-term project truth
|
|
446
|
+
4. Journal is history
|
|
447
|
+
5. Existing codebase
|
|
448
|
+
6. New suggestions (lowest priority)
|
|
449
|
+
|
|
450
|
+
## After Any Feature/Fix
|
|
451
|
+
- Update active-context.md during work (scratchpad)
|
|
452
|
+
- Add journal entry to journal/YYYY-MM.md when done
|
|
453
|
+
- Create lessons/L-XXX-title.md if you discovered a pitfall
|
|
454
|
+
- Update memo.md if project truth changed
|
|
455
|
+
- Clear active-context.md when task is merged
|
|
456
|
+
"@
|
|
457
|
+
|
|
458
|
+
Write-MnemoFile (Join-Path $Ctx.MnemoRulesAgentDir "memory-system.md") $geminiRule -ForceWrite:$Force
|
|
459
|
+
Write-MnemoFile (Join-Path $Ctx.RepoRoot "AGENTS.md") $agentsMd -ForceWrite:$Force
|
|
460
|
+
|
|
461
|
+
Write-Host "`nMemory scaffold installed." -ForegroundColor Cyan
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
function Install-MemoryScripts {
|
|
465
|
+
param(
|
|
466
|
+
[Parameter(Mandatory=$true)][hashtable]$Ctx,
|
|
467
|
+
[Parameter(Mandatory=$true)][string]$InstallerRoot,
|
|
468
|
+
[switch]$Force,
|
|
469
|
+
[switch]$EnableVector,
|
|
470
|
+
[string]$VectorProvider = "openai"
|
|
471
|
+
)
|
|
472
|
+
|
|
473
|
+
$scripts = @(
|
|
474
|
+
@{ Name = "rebuild-memory-index.ps1"; LineEndings = "CRLF" },
|
|
475
|
+
@{ Name = "lint-memory.ps1"; LineEndings = "CRLF" },
|
|
476
|
+
@{ Name = "query-memory.ps1"; LineEndings = "CRLF" },
|
|
477
|
+
@{ Name = "build-memory-sqlite.py"; LineEndings = "LF" },
|
|
478
|
+
@{ Name = "query-memory-sqlite.py"; LineEndings = "LF" },
|
|
479
|
+
@{ Name = "clear-active.ps1"; LineEndings = "CRLF" },
|
|
480
|
+
@{ Name = "add-lesson.ps1"; LineEndings = "CRLF" },
|
|
481
|
+
@{ Name = "add-journal-entry.ps1"; LineEndings = "CRLF" },
|
|
482
|
+
@{ Name = "customization.md"; LineEndings = "CRLF" }
|
|
483
|
+
)
|
|
484
|
+
|
|
485
|
+
foreach ($s in $scripts) {
|
|
486
|
+
Install-TemplateFile `
|
|
487
|
+
-TemplateName $s.Name `
|
|
488
|
+
-DestPath (Join-Path $Ctx.MemScripts $s.Name) `
|
|
489
|
+
-InstallerRoot $InstallerRoot `
|
|
490
|
+
-LineEndings $s.LineEndings `
|
|
491
|
+
-ForceWrite:$Force
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
if ($EnableVector) {
|
|
495
|
+
Install-TemplateFile `
|
|
496
|
+
-TemplateName "mnemo_vector.py" `
|
|
497
|
+
-DestPath (Join-Path $Ctx.MemScripts "mnemo_vector.py") `
|
|
498
|
+
-InstallerRoot $InstallerRoot `
|
|
499
|
+
-LineEndings "LF" `
|
|
500
|
+
-ForceWrite:$Force
|
|
501
|
+
|
|
502
|
+
# Install autonomy modules
|
|
503
|
+
Install-AutonomyModules -Ctx $Ctx -InstallerRoot $InstallerRoot -Force:$Force
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
function Install-AutonomyModules {
|
|
508
|
+
param(
|
|
509
|
+
[Parameter(Mandatory=$true)][hashtable]$Ctx,
|
|
510
|
+
[Parameter(Mandatory=$true)][string]$InstallerRoot,
|
|
511
|
+
[switch]$Force
|
|
512
|
+
)
|
|
513
|
+
|
|
514
|
+
$autonomyTemplates = @("__init__.py", "schema.py", "runner.py", "ingest_pipeline.py",
|
|
515
|
+
"lifecycle_engine.py", "entity_resolver.py", "retrieval_router.py",
|
|
516
|
+
"reranker.py", "context_safety.py", "vault_policy.py")
|
|
517
|
+
$policyTemplates = @("policies.yaml")
|
|
518
|
+
|
|
519
|
+
foreach ($f in $autonomyTemplates) {
|
|
520
|
+
$src = Join-Path $InstallerRoot "scripts\memory\installer\templates\autonomy\$f"
|
|
521
|
+
if (Test-Path $src) {
|
|
522
|
+
Install-TemplateFile `
|
|
523
|
+
-TemplateName "autonomy\$f" `
|
|
524
|
+
-DestPath (Join-Path $Ctx.AutonomyDir $f) `
|
|
525
|
+
-InstallerRoot $InstallerRoot `
|
|
526
|
+
-LineEndings "LF" `
|
|
527
|
+
-ForceWrite:$Force
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
foreach ($f in $policyTemplates) {
|
|
531
|
+
$src = Join-Path $InstallerRoot "scripts\memory\installer\templates\autonomy\$f"
|
|
532
|
+
if (Test-Path $src) {
|
|
533
|
+
Install-TemplateFile `
|
|
534
|
+
-TemplateName "autonomy\$f" `
|
|
535
|
+
-DestPath (Join-Path $Ctx.AutonomyDir $f) `
|
|
536
|
+
-InstallerRoot $InstallerRoot `
|
|
537
|
+
-LineEndings "LF" `
|
|
538
|
+
-ForceWrite:$Force
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
<#
|
|
2
|
+
vector_setup.ps1 - Vector engine installation and dependency management.
|
|
3
|
+
Dot-sourced by bootstrap.ps1.
|
|
4
|
+
#>
|
|
5
|
+
|
|
6
|
+
function Resolve-VectorPython {
|
|
7
|
+
$candidates = @(
|
|
8
|
+
@{ Kind = "python"; Args = @() },
|
|
9
|
+
@{ Kind = "py"; Args = @("-3") },
|
|
10
|
+
@{ Kind = "py"; Args = @() },
|
|
11
|
+
@{ Kind = "python3"; Args = @() }
|
|
12
|
+
)
|
|
13
|
+
foreach ($c in $candidates) {
|
|
14
|
+
$cmd = Get-Command $c.Kind -ErrorAction SilentlyContinue
|
|
15
|
+
if ($null -eq $cmd) { continue }
|
|
16
|
+
try {
|
|
17
|
+
$ver = & $cmd.Source @($c.Args) -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')" 2>$null
|
|
18
|
+
if ($LASTEXITCODE -eq 0 -and [version]$ver -ge [version]"3.10") {
|
|
19
|
+
return @{ Path = $cmd.Source; Args = @($c.Args) }
|
|
20
|
+
}
|
|
21
|
+
} catch {}
|
|
22
|
+
}
|
|
23
|
+
return $null
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function Install-VectorEngine {
|
|
27
|
+
param(
|
|
28
|
+
[Parameter(Mandatory=$true)][hashtable]$Ctx,
|
|
29
|
+
[Parameter(Mandatory=$true)][string]$InstallerRoot,
|
|
30
|
+
[switch]$Force,
|
|
31
|
+
[string]$VectorProvider = "openai"
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
Write-Host "Vector mode enabled (provider: $VectorProvider)" -ForegroundColor Cyan
|
|
35
|
+
|
|
36
|
+
if ($script:DryRun) {
|
|
37
|
+
Write-Host "[DRY RUN] Skipping vector dependency install and MCP wiring." -ForegroundColor DarkCyan
|
|
38
|
+
return $null
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
$vectorPython = Resolve-VectorPython
|
|
42
|
+
if ($null -eq $vectorPython) {
|
|
43
|
+
throw "Vector mode requires Python 3.10+ (python/py launcher not found or version too old)."
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
$deps = @("openai", "sqlite-vec", "mcp[cli]>=1.2.0,<2.0")
|
|
47
|
+
if ($VectorProvider -eq "gemini") { $deps += "google-genai" }
|
|
48
|
+
$requiredModules = @("openai", "sqlite_vec", "mcp")
|
|
49
|
+
if ($VectorProvider -eq "gemini") { $requiredModules += "google.genai" }
|
|
50
|
+
|
|
51
|
+
$moduleListPy = ($requiredModules | ForEach-Object { "'$_'" }) -join ", "
|
|
52
|
+
$depCheck = "import importlib.util, sys; mods=[$moduleListPy]; missing=[m for m in mods if importlib.util.find_spec(m) is None]; print(','.join(missing)); sys.exit(0 if not missing else 1)"
|
|
53
|
+
|
|
54
|
+
$depsSatisfied = $false
|
|
55
|
+
if (-not $Force) {
|
|
56
|
+
& $vectorPython.Path @($vectorPython.Args) -c $depCheck 2>$null | Out-Null
|
|
57
|
+
$depsSatisfied = ($LASTEXITCODE -eq 0)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if ($depsSatisfied) {
|
|
61
|
+
Write-Host "SKIP (deps installed): vector dependency install" -ForegroundColor DarkYellow
|
|
62
|
+
} else {
|
|
63
|
+
Write-Host "Installing vector dependencies..." -ForegroundColor Cyan
|
|
64
|
+
& $vectorPython.Path @($vectorPython.Args) -m pip install --quiet @deps
|
|
65
|
+
if ($LASTEXITCODE -ne 0) {
|
|
66
|
+
throw "Failed to install vector dependencies. Try: python -m pip install $($deps -join ' ')"
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
# Add vector cursor rule
|
|
71
|
+
$vectorRule = @"
|
|
72
|
+
---
|
|
73
|
+
description: Mnemo vector semantic retrieval layer (optional)
|
|
74
|
+
globs:
|
|
75
|
+
- "**/*"
|
|
76
|
+
alwaysApply: true
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
# Vector Memory Layer (Optional)
|
|
80
|
+
|
|
81
|
+
This rule supplements ``00-memory-system.mdc`` and does not replace governance.
|
|
82
|
+
|
|
83
|
+
## Use vector tools when:
|
|
84
|
+
- You do not know the exact keyword for prior context.
|
|
85
|
+
- Keyword/FTS search did not find relevant history.
|
|
86
|
+
|
|
87
|
+
## MCP tools
|
|
88
|
+
- ``vector_search`` - semantic retrieval with authority-aware reranking.
|
|
89
|
+
- ``vector_sync`` - incremental indexing.
|
|
90
|
+
- ``vector_forget`` - remove stale entries.
|
|
91
|
+
- ``vector_health`` - DB/API health check.
|
|
92
|
+
- ``memory_status`` - JSON summary for autonomous monitoring.
|
|
93
|
+
|
|
94
|
+
## Fallback
|
|
95
|
+
If vector search is unavailable, keep using:
|
|
96
|
+
- ``scripts/memory/query-memory.ps1 -Query "..."``
|
|
97
|
+
- ``scripts/memory/query-memory.ps1 -Query "..." -UseSqlite``
|
|
98
|
+
"@
|
|
99
|
+
|
|
100
|
+
Write-MnemoFile (Join-Path $Ctx.RulesDir "01-vector-search.mdc") $vectorRule -ForceWrite:$Force
|
|
101
|
+
|
|
102
|
+
return $vectorPython
|
|
103
|
+
}
|