opencodekit 0.15.21 → 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.
Files changed (144) hide show
  1. package/dist/index.js +5 -7
  2. package/dist/template/.opencode/AGENTS.md +85 -23
  3. package/dist/template/.opencode/agent/build.md +88 -7
  4. package/dist/template/.opencode/agent/explore.md +1 -1
  5. package/dist/template/.opencode/agent/general.md +54 -4
  6. package/dist/template/.opencode/agent/looker.md +1 -1
  7. package/dist/template/.opencode/agent/painter.md +1 -1
  8. package/dist/template/.opencode/agent/plan.md +52 -0
  9. package/dist/template/.opencode/agent/review.md +1 -1
  10. package/dist/template/.opencode/agent/scout.md +3 -3
  11. package/dist/template/.opencode/agent/vision.md +1 -1
  12. package/dist/template/.opencode/command/create.md +231 -91
  13. package/dist/template/.opencode/command/design.md +40 -7
  14. package/dist/template/.opencode/command/handoff.md +22 -0
  15. package/dist/template/.opencode/command/init.md +49 -78
  16. package/dist/template/.opencode/command/plan.md +36 -16
  17. package/dist/template/.opencode/command/pr.md +15 -0
  18. package/dist/template/.opencode/command/research.md +3 -0
  19. package/dist/template/.opencode/command/resume.md +8 -18
  20. package/dist/template/.opencode/command/review-codebase.md +30 -0
  21. package/dist/template/.opencode/command/ship.md +199 -0
  22. package/dist/template/.opencode/command/start.md +316 -28
  23. package/dist/template/.opencode/command/status.md +24 -1
  24. package/dist/template/.opencode/command/ui-review.md +36 -7
  25. package/dist/template/.opencode/command/verify.md +307 -0
  26. package/dist/template/.opencode/memory/_templates/prd.md +29 -0
  27. package/dist/template/.opencode/memory/_templates/proposal.md +38 -0
  28. package/dist/template/.opencode/memory/_templates/spec.md +66 -0
  29. package/dist/template/.opencode/memory/_templates/tasks.md +198 -0
  30. package/dist/template/.opencode/memory/_templates/tech-stack.md +50 -0
  31. package/dist/template/.opencode/memory/project/tech-stack.md +53 -0
  32. package/dist/template/.opencode/memory/research/ccpm-analysis.md +334 -0
  33. package/dist/template/.opencode/memory/research/openspec-analysis.md +226 -0
  34. package/dist/template/.opencode/memory.db +0 -0
  35. package/dist/template/.opencode/memory.db-shm +0 -0
  36. package/dist/template/.opencode/memory.db-wal +0 -0
  37. package/dist/template/.opencode/opencode.json +18 -4
  38. package/dist/template/.opencode/package.json +1 -0
  39. package/dist/template/.opencode/plans/1770006237537-mighty-otter.md +418 -0
  40. package/dist/template/.opencode/plans/1770006913647-glowing-forest.md +170 -0
  41. package/dist/template/.opencode/plans/1770013678126-witty-planet.md +278 -0
  42. package/dist/template/.opencode/plugin/lib/memory-db.ts +828 -0
  43. package/dist/template/.opencode/plugin/memory.ts +38 -1
  44. package/dist/template/.opencode/skill/index-knowledge/SKILL.md +76 -31
  45. package/dist/template/.opencode/skill/memory-system/SKILL.md +110 -55
  46. package/dist/template/.opencode/skill/tool-priority/SKILL.md +2 -2
  47. package/dist/template/.opencode/tool/memory-get.ts +143 -0
  48. package/dist/template/.opencode/tool/memory-maintain.ts +167 -0
  49. package/dist/template/.opencode/tool/memory-migrate.ts +319 -0
  50. package/dist/template/.opencode/tool/memory-read.ts +17 -46
  51. package/dist/template/.opencode/tool/memory-search.ts +131 -28
  52. package/dist/template/.opencode/tool/memory-timeline.ts +105 -0
  53. package/dist/template/.opencode/tool/memory-update.ts +21 -26
  54. package/dist/template/.opencode/tool/observation.ts +112 -100
  55. package/dist/template/.opencode/tsconfig.json +19 -19
  56. package/package.json +1 -1
  57. package/dist/template/.opencode/command/accessibility-check.md +0 -331
  58. package/dist/template/.opencode/command/agent-browser.md +0 -21
  59. package/dist/template/.opencode/command/analyze-mockup.md +0 -423
  60. package/dist/template/.opencode/command/analyze-project.md +0 -295
  61. package/dist/template/.opencode/command/brainstorm.md +0 -373
  62. package/dist/template/.opencode/command/cloudflare.md +0 -70
  63. package/dist/template/.opencode/command/commit.md +0 -245
  64. package/dist/template/.opencode/command/complete-next-task.md +0 -77
  65. package/dist/template/.opencode/command/design-audit.md +0 -480
  66. package/dist/template/.opencode/command/edit-image.md +0 -242
  67. package/dist/template/.opencode/command/finish.md +0 -255
  68. package/dist/template/.opencode/command/fix-ci.md +0 -109
  69. package/dist/template/.opencode/command/fix-types.md +0 -104
  70. package/dist/template/.opencode/command/fix-ui.md +0 -117
  71. package/dist/template/.opencode/command/fix.md +0 -168
  72. package/dist/template/.opencode/command/frontend-design.md +0 -21
  73. package/dist/template/.opencode/command/generate-diagram.md +0 -349
  74. package/dist/template/.opencode/command/generate-icon.md +0 -283
  75. package/dist/template/.opencode/command/generate-image.md +0 -246
  76. package/dist/template/.opencode/command/generate-pattern.md +0 -247
  77. package/dist/template/.opencode/command/generate-storyboard.md +0 -250
  78. package/dist/template/.opencode/command/implement.md +0 -609
  79. package/dist/template/.opencode/command/import-plan.md +0 -406
  80. package/dist/template/.opencode/command/index-knowledge.md +0 -25
  81. package/dist/template/.opencode/command/integration-test.md +0 -424
  82. package/dist/template/.opencode/command/issue.md +0 -102
  83. package/dist/template/.opencode/command/new-feature.md +0 -651
  84. package/dist/template/.opencode/command/opensrc.md +0 -58
  85. package/dist/template/.opencode/command/quick-build.md +0 -238
  86. package/dist/template/.opencode/command/ralph.md +0 -41
  87. package/dist/template/.opencode/command/research-and-implement.md +0 -148
  88. package/dist/template/.opencode/command/research-ui.md +0 -466
  89. package/dist/template/.opencode/command/restore-image.md +0 -424
  90. package/dist/template/.opencode/command/revert-feature.md +0 -386
  91. package/dist/template/.opencode/command/skill-create.md +0 -517
  92. package/dist/template/.opencode/command/skill-optimize.md +0 -556
  93. package/dist/template/.opencode/command/summarize.md +0 -412
  94. package/dist/template/.opencode/command/triage.md +0 -398
  95. package/dist/template/.opencode/memory/_templates/README.md +0 -35
  96. package/dist/template/.opencode/memory/_templates/observation.md +0 -39
  97. package/dist/template/.opencode/memory/_templates/project/architecture.md +0 -60
  98. package/dist/template/.opencode/memory/_templates/project/commands.md +0 -72
  99. package/dist/template/.opencode/memory/_templates/project/conventions.md +0 -68
  100. package/dist/template/.opencode/memory/_templates/project/gotchas.md +0 -41
  101. package/dist/template/.opencode/memory/_templates/prompt-engineering.md +0 -333
  102. package/dist/template/.opencode/memory/observations/2026-01-22-decision-agents-md-prompt-engineering-improvement.md +0 -29
  103. package/dist/template/.opencode/memory/observations/2026-01-25-decision-agent-roles-build-orchestrates-general-e.md +0 -14
  104. package/dist/template/.opencode/memory/observations/2026-01-25-decision-simplified-swarm-helper-tool-to-fix-type.md +0 -20
  105. package/dist/template/.opencode/memory/observations/2026-01-25-decision-use-beads-as-swarm-board-source-of-truth.md +0 -14
  106. package/dist/template/.opencode/memory/observations/2026-01-25-learning-user-wants-real-swarm-coordination-guida.md +0 -15
  107. package/dist/template/.opencode/memory/observations/2026-01-28-decision-created-deep-research-skill-for-thorough.md +0 -29
  108. package/dist/template/.opencode/memory/observations/2026-01-28-decision-gh-grep-mcp-wrapper-vs-native-grep-searc.md +0 -21
  109. package/dist/template/.opencode/memory/observations/2026-01-28-decision-oracle-tool-optimal-usage-patterns.md +0 -32
  110. package/dist/template/.opencode/memory/observations/2026-01-28-learning-ampcode-deep-mode-research-integration-w.md +0 -42
  111. package/dist/template/.opencode/memory/observations/2026-01-28-pattern-research-delegation-pattern-explore-for-.md +0 -32
  112. package/dist/template/.opencode/memory/observations/2026-01-29-decision-copilot-auth-plugin-rate-limit-handling.md +0 -27
  113. package/dist/template/.opencode/memory/observations/2026-01-29-decision-spec-driven-approach-for-opencodekit.md +0 -21
  114. package/dist/template/.opencode/memory/observations/2026-01-29-learning-karpathy-llm-coding-insights-dec-2025.md +0 -44
  115. package/dist/template/.opencode/memory/observations/2026-01-30-decision-github-copilot-claude-routing-keep-disab.md +0 -32
  116. package/dist/template/.opencode/memory/observations/2026-01-30-discovery-context-management-research-critical-gap.md +0 -14
  117. package/dist/template/.opencode/memory/observations/2026-01-30-discovery-kimi-k2-5-agent-swarm-architecture-patte.md +0 -45
  118. package/dist/template/.opencode/memory/observations/2026-01-30-pattern-swarm-tools-architecture.md +0 -28
  119. package/dist/template/.opencode/memory/observations/2026-01-31-decision-copilot-auth-plugin-updated-with-baseurl.md +0 -63
  120. package/dist/template/.opencode/memory/observations/2026-01-31-decision-created-dedicated-worker-agent-for-swarm.md +0 -20
  121. package/dist/template/.opencode/memory/observations/2026-01-31-decision-rollback-to-v1-1-47-for-copilot-claude-r.md +0 -21
  122. package/dist/template/.opencode/memory/observations/2026-01-31-decision-simplified-swarm-to-task-tool-pattern.md +0 -44
  123. package/dist/template/.opencode/memory/observations/2026-01-31-decision-swarm-architecture-task-tool-over-tmux.md +0 -33
  124. package/dist/template/.opencode/memory/observations/2026-01-31-decision-worker-skills-defined-for-swarm-delegati.md +0 -30
  125. package/dist/template/.opencode/memory/observations/2026-01-31-learning-gpt-reasoning-config-for-github-copilot.md +0 -51
  126. package/dist/template/.opencode/memory/observations/2026-01-31-learning-opencode-copilot-auth-comparison-finding.md +0 -61
  127. package/dist/template/.opencode/memory/observations/2026-01-31-learning-opencode-copilot-reasoning-architecture-.md +0 -66
  128. package/dist/template/.opencode/memory/observations/2026-01-31-learning-opencode-custom-tools-api.md +0 -48
  129. package/dist/template/.opencode/memory/observations/2026-01-31-learning-opencode-v1-1-48-skills-as-slash-command.md +0 -21
  130. package/dist/template/.opencode/memory/observations/2026-01-31-learning-swarm-system-simplified-removed-mailbox-.md +0 -30
  131. package/dist/template/.opencode/memory/observations/2026-01-31-learning-v1-1-48-native-copilot-reasoning-via-pr-.md +0 -45
  132. package/dist/template/.opencode/memory/observations/2026-01-31-warning-cannot-add-custom-config-to-opencode-jso.md +0 -18
  133. package/dist/template/.opencode/memory/observations/2026-01-31-warning-copilot-claude-v1-endpoint-returns-404-c.md +0 -48
  134. package/dist/template/.opencode/memory/observations/2026-01-31-warning-opencode-v1-1-48-claude-thinking-block-s.md +0 -51
  135. package/dist/template/.opencode/memory/project/architecture.md +0 -60
  136. package/dist/template/.opencode/memory/project/commands.md +0 -72
  137. package/dist/template/.opencode/memory/project/conventions.md +0 -68
  138. package/dist/template/.opencode/memory/project/gotchas.md +0 -41
  139. package/dist/template/.opencode/skill/notebooklm/SKILL.md +0 -272
  140. package/dist/template/.opencode/skill/notebooklm/references/setup.md +0 -353
  141. package/dist/template/.opencode/tool/notebooklm.ts +0 -488
  142. package/dist/template/.opencode/tool/oracle.ts +0 -240
  143. /package/dist/template/.opencode/memory/{user.example.md → _templates/user.md} +0 -0
  144. /package/dist/template/.opencode/memory/{user.md → project/user.md} +0 -0
@@ -19,6 +19,12 @@
19
19
  import fsPromises from "node:fs/promises";
20
20
  import path from "node:path";
21
21
  import type { Plugin } from "@opencode-ai/plugin";
22
+ import {
23
+ checkFTS5Available,
24
+ checkpointWAL,
25
+ getDatabaseSizes,
26
+ optimizeFTS5,
27
+ } from "./lib/memory-db.js";
22
28
 
23
29
  // ============================================================================
24
30
  // Configuration
@@ -491,8 +497,39 @@ export const MemoryPlugin: Plugin = async ({ client, $: _$ }) => {
491
497
  }
492
498
  },
493
499
 
494
- // Hook: session.idle - Session completed
500
+ // Hook: session.idle - Session completed + FTS5 optimization
495
501
  "session.idle": async () => {
502
+ // ===== FTS5 Optimization =====
503
+ // Run FTS5 optimize at session end to keep search fast
504
+ try {
505
+ if (checkFTS5Available()) {
506
+ optimizeFTS5();
507
+ await log("FTS5 index optimized");
508
+ }
509
+ } catch (err) {
510
+ const errMsg = err instanceof Error ? err.message : String(err);
511
+ await log(`FTS5 optimization failed: ${errMsg}`, "warn");
512
+ }
513
+
514
+ // ===== WAL Checkpoint (if WAL > 1MB) =====
515
+ // Checkpoint WAL to main DB when it gets too large
516
+ try {
517
+ const sizes = getDatabaseSizes();
518
+ if (sizes.wal > 1024 * 1024) {
519
+ // WAL > 1MB
520
+ const result = checkpointWAL();
521
+ if (result.checkpointed) {
522
+ await log(
523
+ `WAL checkpointed (was ${Math.round(sizes.wal / 1024)}KB)`,
524
+ );
525
+ }
526
+ }
527
+ } catch (err) {
528
+ const errMsg = err instanceof Error ? err.message : String(err);
529
+ await log(`WAL checkpoint failed: ${errMsg}`, "warn");
530
+ }
531
+
532
+ // ===== Session Summary Prompt =====
496
533
  if (config.sessionSummaryEnabled === false) return;
497
534
 
498
535
  await log("Session idle - prompting memory summary");
@@ -10,11 +10,23 @@ Generate hierarchical AGENTS.md files. Root + complexity-scored subdirectories.
10
10
  ## Usage
11
11
 
12
12
  ```
13
- --create-new # Read existing → remove all → regenerate from scratch
14
- --max-depth=2 # Limit directory depth (default: 5)
13
+ /index-knowledge # Update mode (default)
14
+ /index-knowledge --create-new # Delete all regenerate from scratch
15
+ /index-knowledge --max-depth=2 # Limit directory depth (default: 5)
15
16
  ```
16
17
 
17
- Default: Update mode (modify existing + create new where warranted)
18
+ ## Load Skills
19
+
20
+ ```typescript
21
+ skill({ name: "memory-system" }); // Search for existing patterns
22
+ skill({ name: "deep-research" }); // For thorough LSP exploration
23
+ ```
24
+
25
+ ## Check Memory First
26
+
27
+ ```typescript
28
+ memory_search({ query: "AGENTS.md conventions patterns", limit: 3 });
29
+ ```
18
30
 
19
31
  ---
20
32
 
@@ -30,13 +42,13 @@ Default: Update mode (modify existing + create new where warranted)
30
42
  <critical>
31
43
  **TodoWrite ALL phases. Mark in_progress → completed in real-time.**
32
44
 
33
- ```
34
- TodoWrite([
45
+ ```typescript
46
+ todowrite({ todos: [
35
47
  { id: "discovery", content: "Fire explore agents + LSP codemap + read existing", status: "pending", priority: "high" },
36
48
  { id: "scoring", content: "Score directories, determine locations", status: "pending", priority: "high" },
37
49
  { id: "generate", content: "Generate AGENTS.md files (root + subdirs)", status: "pending", priority: "high" },
38
50
  { id: "review", content: "Deduplicate, validate, trim", status: "pending", priority: "medium" }
39
- ])
51
+ ]});
40
52
  ```
41
53
  </critical>
42
54
 
@@ -93,14 +105,14 @@ Task(
93
105
  <dynamic-agents>
94
106
  **DYNAMIC AGENT SPAWNING**: After bash analysis, spawn ADDITIONAL explore agents based on project scale:
95
107
 
96
- | Factor | Threshold | Additional Agents |
97
- |--------|-----------|-------------------|
98
- | **Total files** | >100 | +1 per 100 files |
99
- | **Total lines** | >10k | +1 per 10k lines |
100
- | **Directory depth** | ≥4 | +2 for deep exploration |
108
+ | Factor | Threshold | Additional Agents |
109
+ | ---------------------------- | --------- | -------------------------- |
110
+ | **Total files** | >100 | +1 per 100 files |
111
+ | **Total lines** | >10k | +1 per 10k lines |
112
+ | **Directory depth** | ≥4 | +2 for deep exploration |
101
113
  | **Large files (>500 lines)** | >10 files | +1 for complexity hotspots |
102
- | **Monorepo** | detected | +1 per package/workspace |
103
- | **Multiple languages** | >1 | +1 per language |
114
+ | **Monorepo** | detected | +1 per package/workspace |
115
+ | **Multiple languages** | >1 | +1 per language |
104
116
 
105
117
  ```bash
106
118
  # Measure project scale first
@@ -111,6 +123,7 @@ max_depth=$(find . -type d -not -path '*/node_modules/*' -not -path '*/.git/*' |
111
123
  ```
112
124
 
113
125
  Example spawning (all in ONE message for parallel execution):
126
+
114
127
  ```
115
128
  // 500 files, 50k lines, depth 6, 15 large files → spawn additional agents
116
129
  Task(
@@ -132,6 +145,7 @@ Task(
132
145
  )
133
146
  // ... more based on calculation
134
147
  ```
148
+
135
149
  </dynamic-agents>
136
150
 
137
151
  ### Main Session: Concurrent Analysis
@@ -139,6 +153,7 @@ Task(
139
153
  **While Task agents execute**, main session does:
140
154
 
141
155
  #### 1. Bash Structural Analysis
156
+
142
157
  ```bash
143
158
  # Directory depth + file counts
144
159
  find . -type d -not -path '*/\.*' -not -path '*/node_modules/*' -not -path '*/venv/*' -not -path '*/dist/*' -not -path '*/build/*' | awk -F/ '{print NF-1}' | sort -n | uniq -c
@@ -154,6 +169,7 @@ find . -type f \( -name "AGENTS.md" -o -name "CLAUDE.md" \) -not -path '*/node_m
154
169
  ```
155
170
 
156
171
  #### 2. Read Existing AGENTS.md
172
+
157
173
  ```
158
174
  For each existing file found:
159
175
  Read(filePath=file)
@@ -164,6 +180,7 @@ For each existing file found:
164
180
  If `--create-new`: Read all existing first (preserve context) → then delete all → regenerate.
165
181
 
166
182
  #### 3. LSP Codemap (if available)
183
+
167
184
  ```
168
185
  lsp_servers() # Check availability
169
186
 
@@ -192,27 +209,28 @@ lsp_find_references(filePath="...", line=X, character=Y)
192
209
 
193
210
  ### Scoring Matrix
194
211
 
195
- | Factor | Weight | High Threshold | Source |
196
- |--------|--------|----------------|--------|
197
- | File count | 3x | >20 | bash |
198
- | Subdir count | 2x | >5 | bash |
199
- | Code ratio | 2x | >70% | bash |
200
- | Unique patterns | 1x | Has own config | explore |
201
- | Module boundary | 2x | Has index.ts/__init__.py | bash |
202
- | Symbol density | 2x | >30 symbols | LSP |
203
- | Export count | 2x | >10 exports | LSP |
204
- | Reference centrality | 3x | >20 refs | LSP |
212
+ | Factor | Weight | High Threshold | Source |
213
+ | -------------------- | ------ | ------------------------ | ------- |
214
+ | File count | 3x | >20 | bash |
215
+ | Subdir count | 2x | >5 | bash |
216
+ | Code ratio | 2x | >70% | bash |
217
+ | Unique patterns | 1x | Has own config | explore |
218
+ | Module boundary | 2x | Has index.ts/**init**.py | bash |
219
+ | Symbol density | 2x | >30 symbols | LSP |
220
+ | Export count | 2x | >10 exports | LSP |
221
+ | Reference centrality | 3x | >20 refs | LSP |
205
222
 
206
223
  ### Decision Rules
207
224
 
208
- | Score | Action |
209
- |-------|--------|
210
- | **Root (.)** | ALWAYS create |
211
- | **>15** | Create AGENTS.md |
212
- | **8-15** | Create if distinct domain |
213
- | **<8** | Skip (parent covers) |
225
+ | Score | Action |
226
+ | ------------ | ------------------------- |
227
+ | **Root (.)** | ALWAYS create |
228
+ | **>15** | Create AGENTS.md |
229
+ | **8-15** | Create if distinct domain |
230
+ | **<8** | Skip (parent covers) |
214
231
 
215
232
  ### Output
233
+
216
234
  ```
217
235
  AGENTS_LOCATIONS = [
218
236
  { path: ".", type: "root" },
@@ -239,39 +257,48 @@ AGENTS_LOCATIONS = [
239
257
  **Branch:** {BRANCH}
240
258
 
241
259
  ## OVERVIEW
260
+
242
261
  {1-2 sentences: what + core stack}
243
262
 
244
263
  ## STRUCTURE
264
+
245
265
  \`\`\`
246
266
  {root}/
247
- ├── {dir}/ # {non-obvious purpose only}
267
+ ├── {dir}/ # {non-obvious purpose only}
248
268
  └── {entry}
249
269
  \`\`\`
250
270
 
251
271
  ## WHERE TO LOOK
272
+
252
273
  | Task | Location | Notes |
253
- |------|----------|-------|
274
+ | ---- | -------- | ----- |
254
275
 
255
276
  ## CODE MAP
277
+
256
278
  {From LSP - skip if unavailable or project <10 files}
257
279
 
258
280
  | Symbol | Type | Location | Refs | Role |
259
281
 
260
282
  ## CONVENTIONS
283
+
261
284
  {ONLY deviations from standard}
262
285
 
263
286
  ## ANTI-PATTERNS (THIS PROJECT)
287
+
264
288
  {Explicitly forbidden here}
265
289
 
266
290
  ## UNIQUE STYLES
291
+
267
292
  {Project-specific}
268
293
 
269
294
  ## COMMANDS
295
+
270
296
  \`\`\`bash
271
297
  {dev/test/build}
272
298
  \`\`\`
273
299
 
274
300
  ## NOTES
301
+
275
302
  {Gotchas}
276
303
  ```
277
304
 
@@ -316,6 +343,7 @@ Task(
316
343
  **Mark "review" as in_progress.**
317
344
 
318
345
  For each generated file:
346
+
319
347
  - Remove generic advice
320
348
  - Remove parent duplicates
321
349
  - Trim to size limits
@@ -356,3 +384,20 @@ Hierarchy:
356
384
  - **Redundancy**: Child never repeats parent
357
385
  - **Generic content**: Remove anything that applies to ALL projects
358
386
  - **Verbose style**: Telegraphic or die
387
+ - **Skipping memory**: ALWAYS search memory for existing patterns before starting
388
+
389
+ ---
390
+
391
+ ## Record Findings
392
+
393
+ After completion, save significant discoveries:
394
+
395
+ ```typescript
396
+ observation({
397
+ type: "pattern",
398
+ title: "AGENTS.md patterns for [project]",
399
+ narrative: "[Key conventions, anti-patterns, structure decisions]",
400
+ concepts: "AGENTS.md, documentation, codebase, knowledge",
401
+ confidence: "high",
402
+ });
403
+ ```
@@ -5,90 +5,94 @@ description: Use when persisting learnings, loading previous context, or searchi
5
5
 
6
6
  # Memory System
7
7
 
8
- Persistent context that survives across sessions.
8
+ Persistent context that survives across sessions. Uses **SQLite + FTS5** as single source of truth.
9
9
 
10
- ## Directory Structure
10
+ ## Architecture
11
11
 
12
12
  ```
13
- .opencode/memory/
14
- _templates/ # Task templates (prd, observation, session-summary)
15
- handoffs/ # Phase transitions
16
- research/ # Research findings
17
- observations/ # Structured observations
18
- project/ # Persistent project knowledge
19
- commands.md # Build, test, lint, deploy commands
20
- conventions.md # Code patterns, commit style, PR process
21
- gotchas.md # Footguns, edge cases, "don't forget this"
22
- architecture.md # Key modules, directory structure
23
- user.md # Identity, preferences, communication style
13
+ SQLite Database: .opencode/memory/memory.sqlite
14
+ ├── observations table (FTS5 indexed)
15
+ ├── handoffs/ subdirectory
16
+ ├── research/ subdirectory
17
+ └── project/ subdirectory (commands, conventions, gotchas, architecture)
24
18
  ```
25
19
 
26
- ## Standard Memory Blocks
20
+ **Key principle:** All writes go to SQLite. No dual-write pattern. No markdown fallbacks.
27
21
 
28
- | File | Purpose | Update When |
29
- | ------------------------- | ------------------------ | --------------------------- |
30
- | `project/commands.md` | Build/test/lint commands | Discovering new command |
31
- | `project/conventions.md` | Code patterns, style | Learning team pattern |
32
- | `project/gotchas.md` | Footguns, warnings | Hitting unexpected behavior |
33
- | `project/architecture.md` | Key modules, structure | Mapping new area |
34
- | `user.md` | Preferences, workflow | Learning user preference |
22
+ ## Memory Tools
35
23
 
36
- ## Explicit Memory Updates
24
+ ### memory-search (Start Here)
37
25
 
38
- Don't rely on implicit learning. Explicitly persist:
26
+ Fast FTS5 full-text search. Returns **compact index** (50-100 tokens per result) for progressive disclosure.
39
27
 
40
- - Non-obvious project behavior → `project/gotchas.md`
41
- - User preferences discovered → `user.md`
42
- - New build/test commands `project/commands.md`
43
- - Code patterns to follow → `project/conventions.md`
28
+ ```typescript
29
+ memory_search({ query: "authentication" });
30
+ memory_search({ query: "bugfix", type: "observations", limit: 5 });
31
+ memory_search({ query: "session", type: "handoffs" });
32
+ memory_search({ query: "patterns", type: "all" }); // Search everything
33
+ ```
44
34
 
45
- ## Memory Tools
35
+ **Search modes:**
36
+
37
+ - `observations` (default): Search SQLite with FTS5 ranking
38
+ - `handoffs`, `research`, `templates`: Search specific directories
39
+ - `beads`: Search .beads/artifacts
40
+ - `all`: Search everything
46
41
 
47
- ### memory-read
42
+ ### memory-get (Progressive Disclosure)
48
43
 
49
- Load previous context or templates:
44
+ Fetch full observation details after identifying relevant IDs from search:
50
45
 
51
46
  ```typescript
52
- memory - read({ file: "project/commands" }); // Load commands
53
- memory - read({ file: "_templates/prd" }); // Load PRD template
54
- memory - read({ file: "handoffs/bd-abc123" }); // Load specific handoff
47
+ memory_get({ ids: "42" }); // Single observation
48
+ memory_get({ ids: "1,5,10" }); // Multiple observations
55
49
  ```
56
50
 
57
- ### memory-update
51
+ ### memory-timeline (Chronological Context)
58
52
 
59
- Save learnings or handoffs:
53
+ See what happened before/after a specific observation:
60
54
 
61
55
  ```typescript
62
- memory -
63
- update({
64
- file: "project/gotchas",
65
- content: "### New Gotcha\n\nDescription...",
66
- mode: "append", // or "replace"
67
- });
56
+ memory_timeline({ anchor_id: 42, depth_before: 5, depth_after: 5 });
68
57
  ```
69
58
 
70
- ### memory-search
59
+ ### memory-read (Files)
71
60
 
72
- Find past decisions, research, or handoffs:
61
+ Load project files, handoffs, or templates:
73
62
 
74
63
  ```typescript
75
- memory - search({ query: "authentication" });
76
- memory - search({ query: "bugfix", type: "observations" });
77
- memory - search({ query: "session", type: "handoffs" });
64
+ memory_read({ file: "project/commands" });
65
+ memory_read({ file: "handoffs/2024-01-20-phase-1" });
66
+ memory_read({ file: "research/auth-patterns" });
67
+ ```
68
+
69
+ ### memory-update (Files)
70
+
71
+ Save to project files or handoffs:
72
+
73
+ ```typescript
74
+ memory_update({
75
+ file: "project/gotchas",
76
+ content: "### New Gotcha\n\nDescription...",
77
+ mode: "append", // or "replace"
78
+ });
78
79
  ```
79
80
 
80
81
  ## Observations
81
82
 
82
- Record important findings with structured metadata:
83
+ Record structured findings to SQLite with FTS5 indexing:
83
84
 
84
85
  ```typescript
85
86
  observation({
86
87
  type: "decision", // decision, bugfix, feature, pattern, discovery, learning, warning
87
88
  title: "Use JWT auth",
88
- content: "Decided to use JWT because...",
89
- concepts: "auth, security",
90
- files: "src/auth.ts",
91
- bead_id: "bd-abc123",
89
+ narrative: "Decided to use JWT because it's stateless and scales well...",
90
+ facts: "stateless, scalable, industry standard", // Key facts (comma-separated)
91
+ concepts: "auth, jwt, security", // Keywords for search
92
+ confidence: "high", // high, medium, low
93
+ files_read: "src/auth.ts, src/middleware.ts", // Files consulted
94
+ files_modified: "src/auth.ts", // Files changed
95
+ bead_id: "bd-abc123", // Link to task (optional)
92
96
  });
93
97
  ```
94
98
 
@@ -99,9 +103,60 @@ observation({
99
103
  - Patterns worth reusing
100
104
  - Gotchas and warnings for future
101
105
 
106
+ ## Standard Project Files
107
+
108
+ | File | Purpose | Update When |
109
+ | ------------------------- | ------------------------ | --------------------------- |
110
+ | `project/commands.md` | Build/test/lint commands | Discovering new command |
111
+ | `project/conventions.md` | Code patterns, style | Learning team pattern |
112
+ | `project/gotchas.md` | Footguns, warnings | Hitting unexpected behavior |
113
+ | `project/architecture.md` | Key modules, structure | Mapping new area |
114
+
115
+ ## Progressive Disclosure Pattern
116
+
117
+ Memory search returns **compact results** to avoid context bloat. Follow this pattern:
118
+
119
+ ```typescript
120
+ // 1. Search for relevant context
121
+ memory_search({ query: "auth patterns" });
122
+
123
+ // 2. Identify relevant observation IDs from compact index
124
+ // 3. Fetch full details only for what you need
125
+ memory_get({ ids: "42,45" });
126
+
127
+ // 4. See chronological context if needed
128
+ memory_timeline({ anchor_id: 42 });
129
+ ```
130
+
102
131
  ## Best Practices
103
132
 
104
- 1. **Read before work** - Check relevant memory files at session start
105
- 2. **Update during work** - Don't wait until end; persist incrementally
106
- 3. **Be specific** - Include file paths, function names, concrete examples
107
- 4. **Keep it actionable** - Future agents should know what to do with the info
133
+ 1. **Search before work** - Run `memory_search` at session start
134
+ 2. **Progressive disclosure** - Use search get timeline pattern
135
+ 3. **Record decisions** - Create observations for non-obvious choices
136
+ 4. **Be specific** - Include file paths, function names, concrete examples
137
+ 5. **Keep it actionable** - Future agents should know what to do with the info
138
+
139
+ ## Maintenance
140
+
141
+ For long-term storage health:
142
+
143
+ ```typescript
144
+ // Check current status
145
+ memory_maintain({ operation: "status" });
146
+
147
+ // Full maintenance (archive >90 days, checkpoint WAL, vacuum)
148
+ memory_maintain({ operation: "full" });
149
+
150
+ // Preview what would be archived
151
+ memory_maintain({ operation: "archive", older_than_days: 60, dry_run: true });
152
+ ```
153
+
154
+ **Automatic maintenance** runs at session end:
155
+
156
+ - FTS5 index optimization
157
+ - WAL checkpoint (if WAL > 1MB)
158
+
159
+ **Manual maintenance** (run monthly or when storage grows):
160
+
161
+ - `archive`: Move old observations to archive table
162
+ - `vacuum`: Defragment and reclaim space
@@ -120,7 +120,7 @@ Task({
120
120
  | **codesearch** | Real implementation patterns | GitHub code examples |
121
121
  | **grepsearch** | Cross-repo patterns | grep.app search |
122
122
  | **webfetch** | Specific URL content | User-provided links |
123
- | **oracle** | Second opinion | Validate approach |
123
+ | **review (Task)** | Second opinion | Validate approach |
124
124
 
125
125
  ## Workflow Pattern
126
126
 
@@ -251,7 +251,7 @@ RESEARCH:
251
251
  context7_resolve_library_id({ libraryName: "..." })
252
252
  context7_query_docs({ libraryId: "...", topic: "..." })
253
253
  websearch({ query: "..." })
254
- oracle({ question: "..." })
254
+ Task({ subagent_type: "review", description: "Second opinion", prompt: "Review the approach." })
255
255
 
256
256
  MEMORY:
257
257
  memory_search({ query: "..." }) → Find past learnings
@@ -0,0 +1,143 @@
1
+ import { tool } from "@opencode-ai/plugin";
2
+ import {
3
+ type ObservationRow,
4
+ getObservationsByIds,
5
+ } from "../plugin/lib/memory-db";
6
+
7
+ const TYPE_ICONS: Record<string, string> = {
8
+ decision: "🎯",
9
+ bugfix: "🐛",
10
+ feature: "✨",
11
+ pattern: "🔄",
12
+ discovery: "💡",
13
+ learning: "📚",
14
+ warning: "⚠️",
15
+ };
16
+
17
+ const CONFIDENCE_ICONS: Record<string, string> = {
18
+ high: "🟢",
19
+ medium: "🟡",
20
+ low: "🔴",
21
+ };
22
+
23
+ function parseJsonArray(jsonStr: string | null): string[] {
24
+ if (!jsonStr) return [];
25
+ try {
26
+ return JSON.parse(jsonStr);
27
+ } catch {
28
+ return [];
29
+ }
30
+ }
31
+
32
+ function formatFullObservation(obs: ObservationRow): string {
33
+ const icon = TYPE_ICONS[obs.type] || "📝";
34
+ const confIcon = CONFIDENCE_ICONS[obs.confidence] || "🟢";
35
+ const date = obs.created_at.split("T")[0];
36
+
37
+ let output = `# ${icon} #${obs.id}: ${obs.title}\n\n`;
38
+
39
+ // Metadata
40
+ output += `**Type**: ${obs.type} | **Confidence**: ${confIcon} ${obs.confidence} | **Created**: ${date}\n\n`;
41
+
42
+ if (obs.subtitle) {
43
+ output += `*${obs.subtitle}*\n\n`;
44
+ }
45
+
46
+ // Concepts
47
+ const concepts = parseJsonArray(obs.concepts);
48
+ if (concepts.length > 0) {
49
+ output += `**Concepts**: ${concepts.join(", ")}\n\n`;
50
+ }
51
+
52
+ // Files
53
+ const filesRead = parseJsonArray(obs.files_read);
54
+ const filesModified = parseJsonArray(obs.files_modified);
55
+ if (filesRead.length > 0) {
56
+ output += `**Files Read**: ${filesRead.join(", ")}\n`;
57
+ }
58
+ if (filesModified.length > 0) {
59
+ output += `**Files Modified**: ${filesModified.join(", ")}\n`;
60
+ }
61
+ if (filesRead.length > 0 || filesModified.length > 0) {
62
+ output += "\n";
63
+ }
64
+
65
+ // Facts
66
+ const facts = parseJsonArray(obs.facts);
67
+ if (facts.length > 0) {
68
+ output += "## Key Facts\n\n";
69
+ for (const fact of facts) {
70
+ output += `- ${fact}\n`;
71
+ }
72
+ output += "\n";
73
+ }
74
+
75
+ // Narrative
76
+ if (obs.narrative) {
77
+ output += "## Content\n\n";
78
+ output += obs.narrative;
79
+ output += "\n\n";
80
+ }
81
+
82
+ // Relationships
83
+ if (obs.bead_id) {
84
+ output += `**Linked Bead**: ${obs.bead_id}\n`;
85
+ }
86
+ if (obs.supersedes) {
87
+ output += `**Supersedes**: #${obs.supersedes}\n`;
88
+ }
89
+ if (obs.superseded_by) {
90
+ output += `⚠️ **Superseded by**: #${obs.superseded_by}\n`;
91
+ }
92
+ if (obs.valid_until) {
93
+ output += `**Valid until**: ${obs.valid_until}\n`;
94
+ }
95
+ if (obs.markdown_file) {
96
+ output += `**Source file**: ${obs.markdown_file}\n`;
97
+ }
98
+
99
+ return output;
100
+ }
101
+
102
+ export default tool({
103
+ description: `Get full observation details by ID.
104
+
105
+ Purpose:
106
+ - Progressive disclosure: fetch full details after identifying relevant observations via search
107
+ - Get complete narrative, facts, and metadata
108
+ - Supports multiple IDs for batch retrieval
109
+
110
+ Example:
111
+ memory-get({ ids: "42" }) // Single observation
112
+ memory-get({ ids: "1,5,10" }) // Multiple observations`,
113
+ args: {
114
+ ids: tool.schema
115
+ .string()
116
+ .describe("Comma-separated observation IDs to retrieve"),
117
+ },
118
+ execute: async (args: { ids: string }) => {
119
+ const ids = args.ids
120
+ .split(",")
121
+ .map((id) => Number.parseInt(id.trim(), 10))
122
+ .filter((id) => !Number.isNaN(id));
123
+
124
+ if (ids.length === 0) {
125
+ return "No valid observation IDs provided.";
126
+ }
127
+
128
+ const observations = getObservationsByIds(ids);
129
+
130
+ if (observations.length === 0) {
131
+ return `No observations found for IDs: ${args.ids}`;
132
+ }
133
+
134
+ let output = `# Retrieved ${observations.length} Observation(s)\n\n`;
135
+
136
+ for (const obs of observations) {
137
+ output += formatFullObservation(obs);
138
+ output += "\n---\n\n";
139
+ }
140
+
141
+ return output;
142
+ },
143
+ });