-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
659 lines (541 loc) · 25.8 KB
/
install.sh
File metadata and controls
659 lines (541 loc) · 25.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
#!/usr/bin/env sh
set -eu
config_dir="${HOME}/.config/opencode"
force="0"
while [ "$#" -gt 0 ]; do
case "$1" in
--force)
force="1"
;;
--config-dir)
shift
config_dir="$1"
;;
-h|--help)
printf '%s\n' "Usage: sh install.sh [--config-dir DIR] [--force]"
exit 0
;;
*)
printf '%s\n' "Unknown argument: $1" >&2
exit 1
;;
esac
shift
done
write_file() {
relative_path="$1"
destination="$config_dir/$relative_path"
mkdir -p "$(dirname "$destination")"
if [ -f "$destination" ] && [ "$force" != "1" ]; then
printf '%s\n' "Skipped $relative_path"
cat > /dev/null
return 0
fi
if [ -f "$destination" ]; then
status="Updated"
else
status="Created"
fi
cat > "$destination"
printf '%s\n' "$status $relative_path"
}
write_file "agents/memory-curator.md" <<'EOF_AGENTS_MEMORY_CURATOR_MD'
---
description: Curates durable project memory after a feature changes or during a review pass
mode: subagent
permission:
bash:
"*": deny
webfetch: deny
---
You maintain compact, durable project memory under `docs/ai-memory/`.
Your job is to keep active memory aligned with the current truth of the codebase without bloating future prompts.
Workflow:
1. Read `docs/ai-memory/INDEX.md`, `docs/ai-memory/decisions.md`, `docs/ai-memory/troubleshooting.md`, and `docs/ai-memory/features/README.md`.
2. Use the command-provided scope, git summary, changed files, and any explicit approval instructions as the primary source of scope.
3. Identify the memory notes affected by that scope. Start with the target slug when provided, then expand only to related notes that mention changed files, modules, feature names, or exact error strings.
4. Read only the project files and memory notes needed to decide whether each note should be kept, rewritten, trimmed, or proposed for deletion.
5. Apply high-confidence non-destructive updates immediately:
- create missing notes when durable context now exists
- rewrite stale bullets or sections when behavior changed
- trim sections that no longer apply while preserving the useful parts of the note
- update `docs/ai-memory/INDEX.md` so it reflects the active notes
6. Update shared notes only when the information will matter outside a single feature.
7. Never delete a feature note, decision entry, troubleshooting entry, or index entry unless the user explicitly approves that deletion in the current conversation.
8. When deletion candidates exist without approval, stop before deleting them and return a brief `Deletion review` list with stable item IDs, exact file or section targets, reasons, and the recommended action.
9. When the user explicitly approves specific deletions, remove only those approved items and update `docs/ai-memory/INDEX.md` plus any cross-references that point to them.
Decision rules:
- `keep` - the note is still accurate and useful.
- `rewrite` - the note is still useful but some facts changed.
- `trim` - only part of the note is stale.
- `delete` - the note or entry no longer describes current durable knowledge and adds no ongoing value.
Delete only when at least one of these is true:
- the feature or behavior was removed
- the note was absorbed by another canonical note
- the referenced files or modules no longer exist or are no longer relevant
- a shared decision or troubleshooting item no longer applies to the current codebase
- the remaining content is purely historical and Git history is a better home for it
Capture only durable information:
- implemented behavior or constraints
- file paths, modules, or entry points future work must know
- decisions and tradeoffs that future sessions should preserve
- exact error messages, root causes, and fixes when reusable
Avoid:
- raw chat transcripts
- temporary TODOs or abandoned ideas
- verbose diff narration
- temporary commands or tool output
- duplicate notes
- historical archive notes inside the active memory tree
File conventions:
- keep notes concise and searchable
- use short bullet lists
- prefer exact file paths in backticks
- use exact error strings in backticks
- use kebab-case filenames for feature notes
- update existing sections instead of appending near-duplicates
- keep `docs/ai-memory/` focused on the current truth of the repo
Feature note template:
# <Feature Title>
## Summary
- What now exists and why it matters.
## Files
- `path/to/file` - why it matters.
## Decisions
- Durable decision and rationale.
## Errors and fixes
- Symptom: `exact error or signal`
- Root cause: ...
- Fix: ...
## Follow-ups
- Only if a real, durable constraint remains.
Output expectations:
- Briefly list the notes you updated automatically.
- If deletions are pending, emit a `Deletion review` section with numbered items and exact targets.
- When deletions are pending, end with one short reply hint such as `Reply with delete 1` or `keep all`.
- Keep the result concise and explicit about what still needs user approval.
If the prompt does not provide a clean slug, infer one. If the durable intent is still ambiguous after reading the relevant files, ask one short clarifying question.
EOF_AGENTS_MEMORY_CURATOR_MD
write_file "agents/memory-recall.md" <<'EOF_AGENTS_MEMORY_RECALL_MD'
---
description: Recalls relevant durable project memory for a task or feature
mode: subagent
permission:
edit: deny
bash:
"*": deny
webfetch: deny
---
You search `docs/ai-memory/` and return only the durable context relevant to the caller's query.
Treat the active memory tree as the current truth of the repo, not as a historical archive.
Workflow:
1. Start with `docs/ai-memory/INDEX.md`.
2. Use `grep` on the active `docs/ai-memory/**/*.md` files for the query terms, feature names, file paths, modules, tags, and exact error strings.
3. Read only the matching notes.
4. Synthesize the smallest useful answer for the caller.
Output:
- `Matches` - the memory notes that were relevant.
- `Relevant context` - implemented behavior or project knowledge that matters now.
- `Files` - exact file paths when the memory references them.
- `Decisions` - durable constraints or tradeoffs to preserve.
- `Troubleshooting` - exact recurring errors and fixes when relevant.
- `Gaps` - clearly state if the memory does not answer something.
Rules:
- If there are no relevant matches, say so clearly.
- Do not restate full notes when a short synthesis is enough.
- Prefer exact file paths and exact error strings in backticks.
- Do not reconstruct removed memory from Git or old chat context.
- Do not modify any files.
EOF_AGENTS_MEMORY_RECALL_MD
write_file "commands/remember-feature.md" <<'EOF_COMMANDS_REMEMBER_FEATURE_MD'
---
description: Save and refresh durable memory for a finished feature
agent: memory-curator
subtask: true
---
Record durable project memory for the finished feature `$ARGUMENTS`.
Goal:
- Save the smallest useful long-term context for future sessions.
- Keep related memory aligned with the current truth of the codebase.
- Do not capture raw chat history or temporary implementation noise.
Inputs:
- Feature slug or scope: `$ARGUMENTS`
- Git status:
!`git status --short`
- Changed files:
!`git diff --name-only`
!`git diff --cached --name-only`
- Deleted files:
!`git diff --name-only --diff-filter=D`
!`git diff --cached --name-only --diff-filter=D`
- Diff summary:
!`git diff --stat`
!`git diff --cached --stat`
- Recent commits:
!`git log --oneline -5`
Tasks:
1. If `docs/ai-memory/` does not exist, explain that project memory has not been bootstrapped yet and tell the user to run the bootstrap script from this kit before retrying.
2. Read the existing memory files in `docs/ai-memory/`.
3. Use the current diff, changed files, deleted files, and the provided slug to identify related memory notes that may now be stale.
4. Read only the changed source files and affected memory notes needed to understand the durable outcome.
5. Normalize `$ARGUMENTS` to a kebab-case slug, or infer one from the finished work if missing.
6. Create or update `docs/ai-memory/features/<normalized-slug>.md`.
7. Rewrite or trim other affected memory notes when the current change invalidates stale details.
8. Update `docs/ai-memory/INDEX.md` so it lists only the active feature notes.
9. Update `docs/ai-memory/decisions.md` only for cross-feature decisions that still apply.
10. Update `docs/ai-memory/troubleshooting.md` only for reusable debugging knowledge that still applies.
11. Apply high-confidence rewrites and trims automatically.
12. If a note or entry should be removed from active memory, do not delete it yet unless the user explicitly approved that deletion in the current conversation. Instead, return a short `Deletion review` with item IDs, exact targets, and reasons.
13. If the user explicitly approved specific deletions in the current conversation, delete only those approved items and update `docs/ai-memory/INDEX.md` plus any broken references.
14. If there is no meaningful durable information yet, say so instead of inventing memory.
EOF_COMMANDS_REMEMBER_FEATURE_MD
write_file "commands/recall-feature.md" <<'EOF_COMMANDS_RECALL_FEATURE_MD'
---
description: Recall relevant project memory for a feature or topic
agent: memory-recall
subtask: true
---
Recall durable project memory for `$ARGUMENTS`.
Tasks:
1. If `docs/ai-memory/` does not exist, explain that project memory has not been bootstrapped yet and tell the user to run the bootstrap script from this kit.
2. Start from `docs/ai-memory/INDEX.md`.
3. If `$ARGUMENTS` is empty, briefly summarize what project memory exists and what kinds of queries are supported.
4. Treat `docs/ai-memory/` as the active memory tree for the current truth of the repo.
5. Search `docs/ai-memory/**/*.md` for relevant feature names, file paths, modules, tags, decisions, and exact error strings related to `$ARGUMENTS`.
6. Read only the matching notes.
7. Return a concise synthesis with:
- relevant behavior
- important files
- decisions or constraints
- reusable errors and fixes
8. If nothing relevant exists yet, say that clearly.
9. Do not update memory.
EOF_COMMANDS_RECALL_FEATURE_MD
write_file "commands/review-memory.md" <<'EOF_COMMANDS_REVIEW_MEMORY_MD'
---
description: Review and prune stale project memory
agent: memory-curator
subtask: true
---
Review the active project memory for `$ARGUMENTS`.
Goal:
- Find stale memory caused by refactors, removals, or drift.
- Automatically rewrite or trim notes that can be safely refreshed.
- Require a brief user review before deleting active memory.
Inputs:
- Review scope: `$ARGUMENTS`
- Git status:
!`git status --short`
- Changed files:
!`git diff --name-only`
!`git diff --cached --name-only`
- Deleted files:
!`git diff --name-only --diff-filter=D`
!`git diff --cached --name-only --diff-filter=D`
- Diff summary:
!`git diff --stat`
!`git diff --cached --stat`
- Recent commits:
!`git log --oneline -10`
Tasks:
1. If `docs/ai-memory/` does not exist, explain that project memory has not been bootstrapped yet and tell the user to run the bootstrap script from this kit.
2. Treat `$ARGUMENTS` as an optional scope. If it is empty, review the memory touched by recent changes first, then expand only if needed.
3. Read `docs/ai-memory/INDEX.md`, `docs/ai-memory/decisions.md`, `docs/ai-memory/troubleshooting.md`, and only the relevant feature notes.
4. Scan the notes that match the scope, changed files, deleted files, referenced modules, slugs, or likely stale signals.
5. Classify each candidate as `keep`, `rewrite`, `trim`, or `delete`.
6. Apply high-confidence rewrites and trims immediately.
7. Update `docs/ai-memory/INDEX.md` whenever active feature notes change.
8. If delete candidates exist and the user has not explicitly approved them in the current conversation, return a brief `Deletion review` with item IDs, exact targets, reasons, and recommended deletes.
9. If the user explicitly approved specific item IDs or exact targets in the current conversation, delete only those approved items and update `docs/ai-memory/INDEX.md` plus any cross-references.
10. Keep the report concise: automatic updates first, pending deletion review second, gaps last.
EOF_COMMANDS_REVIEW_MEMORY_MD
write_file "opencode-memory-kit/scripts/bootstrap-project.ps1" <<'EOF_OPENCODE_MEMORY_KIT_SCRIPTS_BOOTSTRAP_PROJECT_PS1'
param(
[string]$Target = ".",
[switch]$Force
)
$ErrorActionPreference = "Stop"
function Write-Utf8NoBomFile {
param(
[string]$Path,
[string]$Content
)
$encoding = New-Object System.Text.UTF8Encoding($false)
[System.IO.File]::WriteAllText($Path, $Content, $encoding)
}
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$repoRoot = Split-Path -Parent $scriptDir
$templateRoot = Join-Path $repoRoot "templates\project"
$docsTemplateRoot = Join-Path $templateRoot "docs"
$fullAgentsTemplate = Join-Path $templateRoot "AGENTS.md"
$appendAgentsTemplate = Join-Path $templateRoot "AGENTS.memory.md"
$marker = "opencode-memory-kit:start"
if (-not (Test-Path -Path $Target -PathType Container)) {
throw "Target directory does not exist: $Target"
}
$resolvedTarget = (Resolve-Path $Target).Path
$targetAgents = Join-Path $resolvedTarget "AGENTS.md"
if (Test-Path $targetAgents) {
$current = [System.IO.File]::ReadAllText($targetAgents)
if ($current.Contains($marker)) {
Write-Host "Skipped AGENTS.md (memory workflow already present)"
}
else {
$appendBlock = [System.IO.File]::ReadAllText($appendAgentsTemplate)
$separator = if ($current.EndsWith("`n")) { "`r`n" } else { "`r`n`r`n" }
Write-Utf8NoBomFile -Path $targetAgents -Content ($current + $separator + $appendBlock)
Write-Host "Updated AGENTS.md (appended memory workflow block)"
}
}
else {
Copy-Item $fullAgentsTemplate $targetAgents
Write-Host "Created AGENTS.md"
}
Get-ChildItem -File -Recurse $docsTemplateRoot | ForEach-Object {
$sourcePath = $_.FullName
$relativePath = $sourcePath.Substring($templateRoot.Length + 1)
$destination = Join-Path $resolvedTarget $relativePath
$destinationDir = Split-Path -Parent $destination
if ($destinationDir -and -not (Test-Path $destinationDir)) {
New-Item -ItemType Directory -Force -Path $destinationDir | Out-Null
}
$exists = Test-Path $destination
if ($exists -and -not $Force) {
Write-Host "Skipped $relativePath"
}
else {
Copy-Item $sourcePath $destination -Force
if ($exists) {
Write-Host "Updated $relativePath"
}
else {
Write-Host "Created $relativePath"
}
}
}
Write-Host ""
Write-Host "Project memory workflow is ready in $resolvedTarget"
Write-Host "Next steps:"
Write-Host " 1. Open the project in OpenCode"
Write-Host " 2. Build as usual"
Write-Host " 3. Run /remember-feature <slug> when a feature is accepted"
Write-Host " 4. Run /recall-feature <query> in future sessions"
Write-Host " 5. Run /review-memory [scope] after large refactors or removals"
EOF_OPENCODE_MEMORY_KIT_SCRIPTS_BOOTSTRAP_PROJECT_PS1
write_file "opencode-memory-kit/scripts/bootstrap-project.sh" <<'EOF_OPENCODE_MEMORY_KIT_SCRIPTS_BOOTSTRAP_PROJECT_SH'
#!/usr/bin/env sh
set -eu
target="."
force="0"
while [ "$#" -gt 0 ]; do
case "$1" in
--force)
force="1"
;;
-h|--help)
printf '%s\n' "Usage: sh scripts/bootstrap-project.sh [target-dir] [--force]"
exit 0
;;
*)
target="$1"
;;
esac
shift
done
script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
repo_root=$(dirname "$script_dir")
template_root="$repo_root/templates/project"
docs_template_root="$template_root/docs"
full_agents_template="$template_root/AGENTS.md"
append_agents_template="$template_root/AGENTS.memory.md"
marker="opencode-memory-kit:start"
if [ ! -d "$target" ]; then
printf '%s\n' "Target directory does not exist: $target" >&2
exit 1
fi
target=$(CDPATH= cd -- "$target" && pwd)
target_agents="$target/AGENTS.md"
if [ -f "$target_agents" ]; then
if grep -q "$marker" "$target_agents"; then
printf '%s\n' "Skipped AGENTS.md (memory workflow already present)"
else
printf '\n\n' >> "$target_agents"
cat "$append_agents_template" >> "$target_agents"
printf '%s\n' "Updated AGENTS.md (appended memory workflow block)"
fi
else
cp "$full_agents_template" "$target_agents"
printf '%s\n' "Created AGENTS.md"
fi
find "$docs_template_root" -type f | sort | while IFS= read -r source_path; do
relative_path=${source_path#"$template_root/"}
destination="$target/$relative_path"
destination_dir=$(dirname "$destination")
mkdir -p "$destination_dir"
if [ -f "$destination" ] && [ "$force" != "1" ]; then
printf '%s\n' "Skipped $relative_path"
continue
fi
if [ -f "$destination" ]; then
cp "$source_path" "$destination"
printf '%s\n' "Updated $relative_path"
else
cp "$source_path" "$destination"
printf '%s\n' "Created $relative_path"
fi
done
printf '\n'
printf '%s\n' "Project memory workflow is ready in $target"
printf '%s\n' "Next steps:"
printf '%s\n' " 1. Open the project in OpenCode"
printf '%s\n' " 2. Build as usual"
printf '%s\n' " 3. Run /remember-feature <slug> when a feature is accepted"
printf '%s\n' " 4. Run /recall-feature <query> in future sessions"
printf '%s\n' " 5. Run /review-memory [scope] after large refactors or removals"
EOF_OPENCODE_MEMORY_KIT_SCRIPTS_BOOTSTRAP_PROJECT_SH
write_file "opencode-memory-kit/templates/project/AGENTS.md" <<'EOF_OPENCODE_MEMORY_KIT_TEMPLATES_PROJECT_AGENTS_MD'
# Project Instructions
<!-- opencode-memory-kit:start -->
## Project Memory Workflow
This project uses a durable AI memory layer stored in `docs/ai-memory/`.
### Persistent Memory
- Use `docs/ai-memory/INDEX.md` as the entry point.
- For explicit manual lookup, use `/recall-feature <query>`.
- Memory is intentionally lazy-loaded. Do not read every file in `docs/ai-memory/` by default.
- When a task mentions existing functionality, prior decisions, regressions, previous bugs, or continuing work from a past session:
1. Read `docs/ai-memory/INDEX.md`.
2. Use `grep` on `docs/ai-memory/**/*.md` for relevant feature names, file paths, tags, and error strings.
3. Read only the matching notes.
- Prefer `docs/ai-memory/features/*.md` for feature-specific implementation context.
- Prefer `docs/ai-memory/decisions.md` for durable cross-feature decisions and constraints.
- Prefer `docs/ai-memory/troubleshooting.md` for recurring errors, exact messages, root causes, and fixes.
### Updating Memory
- After a feature is implemented, iterated on, and accepted, persist durable context with `/remember-feature <kebab-case-slug>`.
- After a large refactor, feature removal, or cleanup pass, review stale memory with `/review-memory [scope]`.
- `docs/ai-memory/` should represent the current truth of the repo, not a historical archive.
- `/remember-feature` and `/review-memory` may automatically rewrite or trim stale notes when confidence is high.
- Deletions from the active memory tree require a brief review before removal.
- The memory update should capture only long-lived project knowledge:
- relevant behavior now implemented
- important files or modules touched
- decisions that future work must respect
- reusable debugging knowledge
- Do not store raw conversation logs, temporary speculation, or large diff narration.
### Memory Quality Bar
- Keep notes concise and searchable.
- Include exact file paths and exact error strings when useful.
- Update existing notes in place instead of creating duplicates.
- Remove obsolete sections once they stop being true.
- Use Git history for old context instead of keeping dead notes under `docs/ai-memory/`.
<!-- opencode-memory-kit:end -->
EOF_OPENCODE_MEMORY_KIT_TEMPLATES_PROJECT_AGENTS_MD
write_file "opencode-memory-kit/templates/project/AGENTS.memory.md" <<'EOF_OPENCODE_MEMORY_KIT_TEMPLATES_PROJECT_AGENTS_MEMORY_MD'
<!-- opencode-memory-kit:start -->
## Project Memory Workflow
This project uses a durable AI memory layer stored in `docs/ai-memory/`.
### Persistent Memory
- Use `docs/ai-memory/INDEX.md` as the entry point.
- For explicit manual lookup, use `/recall-feature <query>`.
- Memory is intentionally lazy-loaded. Do not read every file in `docs/ai-memory/` by default.
- When a task mentions existing functionality, prior decisions, regressions, previous bugs, or continuing work from a past session:
1. Read `docs/ai-memory/INDEX.md`.
2. Use `grep` on `docs/ai-memory/**/*.md` for relevant feature names, file paths, tags, and error strings.
3. Read only the matching notes.
- Prefer `docs/ai-memory/features/*.md` for feature-specific implementation context.
- Prefer `docs/ai-memory/decisions.md` for durable cross-feature decisions and constraints.
- Prefer `docs/ai-memory/troubleshooting.md` for recurring errors, exact messages, root causes, and fixes.
### Updating Memory
- After a feature is implemented, iterated on, and accepted, persist durable context with `/remember-feature <kebab-case-slug>`.
- After a large refactor, feature removal, or cleanup pass, review stale memory with `/review-memory [scope]`.
- `docs/ai-memory/` should represent the current truth of the repo, not a historical archive.
- `/remember-feature` and `/review-memory` may automatically rewrite or trim stale notes when confidence is high.
- Deletions from the active memory tree require a brief review before removal.
- The memory update should capture only long-lived project knowledge:
- relevant behavior now implemented
- important files or modules touched
- decisions that future work must respect
- reusable debugging knowledge
- Do not store raw conversation logs, temporary speculation, or large diff narration.
### Memory Quality Bar
- Keep notes concise and searchable.
- Include exact file paths and exact error strings when useful.
- Update existing notes in place instead of creating duplicates.
- Remove obsolete sections once they stop being true.
- Use Git history for old context instead of keeping dead notes under `docs/ai-memory/`.
<!-- opencode-memory-kit:end -->
EOF_OPENCODE_MEMORY_KIT_TEMPLATES_PROJECT_AGENTS_MEMORY_MD
write_file "opencode-memory-kit/templates/project/docs/ai-memory/INDEX.md" <<'EOF_OPENCODE_MEMORY_KIT_TEMPLATES_PROJECT_DOCS_AI_MEMORY_INDEX_MD'
# AI Memory Index
This directory stores compact, durable context for future OpenCode sessions.
It should describe the current truth of the repo. Historical context lives in Git.
## How to use this memory
- Start here when a task depends on prior project work.
- For manual lookup in OpenCode, run `/recall-feature <query>`.
- For cleanup after refactors or removals, run `/review-memory [scope]`.
- Search this directory by feature name, file path, module name, tag, or exact error text.
- Read only the matching notes.
- Rewrite or trim stale notes in place, and review deletions before removing obsolete notes from the active tree.
## Shared notes
- `decisions.md` - cross-feature decisions and constraints
- `troubleshooting.md` - reusable errors, root causes, and fixes
- `features/README.md` - feature-note conventions
## Features
- None recorded yet.
EOF_OPENCODE_MEMORY_KIT_TEMPLATES_PROJECT_DOCS_AI_MEMORY_INDEX_MD
write_file "opencode-memory-kit/templates/project/docs/ai-memory/decisions.md" <<'EOF_OPENCODE_MEMORY_KIT_TEMPLATES_PROJECT_DOCS_AI_MEMORY_DECISIONS_MD'
# Decisions
Cross-feature decisions and constraints that future work should preserve.
## How to add entries
- Add only decisions that affect more than one future task or module.
- Prefer one short subsection per decision.
- Link affected files when possible.
- Rewrite or remove entries when the decision no longer constrains the current codebase.
- Do not keep superseded decisions here just for history; Git already preserves that context.
## Entries
- None recorded yet.
EOF_OPENCODE_MEMORY_KIT_TEMPLATES_PROJECT_DOCS_AI_MEMORY_DECISIONS_MD
write_file "opencode-memory-kit/templates/project/docs/ai-memory/troubleshooting.md" <<'EOF_OPENCODE_MEMORY_KIT_TEMPLATES_PROJECT_DOCS_AI_MEMORY_TROUBLESHOOTING_MD'
# Troubleshooting
Reusable debugging knowledge for this project.
## How to add entries
- Record only issues that are likely to recur.
- Prefer exact symptoms in backticks.
- Include root cause and fix.
- Rewrite or remove entries when the symptom, root cause, or fix no longer matches the current codebase.
- Do not keep solved-once historical notes that no longer help future debugging.
## Entries
- None recorded yet.
EOF_OPENCODE_MEMORY_KIT_TEMPLATES_PROJECT_DOCS_AI_MEMORY_TROUBLESHOOTING_MD
write_file "opencode-memory-kit/templates/project/docs/ai-memory/features/README.md" <<'EOF_OPENCODE_MEMORY_KIT_TEMPLATES_PROJECT_DOCS_AI_MEMORY_FEATURES_README_MD'
# Feature Notes
Create one file per accepted feature using a kebab-case slug.
## When to create a feature note
- The feature changed durable project behavior.
- Future work will benefit from remembering touched files, constraints, or fixes.
## Lifecycle
- Treat each feature note as the canonical record for the current state of that feature.
- Rewrite the note in place when behavior changes.
- Trim sections that became stale while keeping the useful parts.
- Delete the file when the feature is removed, absorbed, or no longer carries durable value.
- Do not archive obsolete feature notes under `docs/ai-memory/`; rely on Git history instead.
- Deletions require a brief review before removal.
## Recommended structure
- `# <Feature Title>`
- `## Summary`
- `## Files`
- `## Decisions`
- `## Errors and fixes`
- `## Follow-ups`
Record durable knowledge only. Avoid raw diff summaries and transient chat context.
EOF_OPENCODE_MEMORY_KIT_TEMPLATES_PROJECT_DOCS_AI_MEMORY_FEATURES_README_MD
bootstrap_path="$config_dir/opencode-memory-kit/scripts/bootstrap-project.sh"
printf '\n'
printf '%s\n' "OpenCode memory kit installed under $config_dir"
printf '%s\n' "Installed into default OpenCode locations:"
printf '%s\n' " - agents/"
printf '%s\n' " - commands/"
printf '%s\n' " - opencode-memory-kit/"
printf '\n'
printf '%s\n' "Commands now available: /remember-feature, /recall-feature, and /review-memory"
printf '%s\n' "Bootstrap a new repo with:"
printf '%s\n' " sh \"$bootstrap_path\" ."