@mathew-cf/opencode-memory 0.2.0
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/LICENSE +201 -0
- package/README.md +126 -0
- package/dist/config.d.ts +47 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/constants.d.ts +31 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/hooks/guard.d.ts +78 -0
- package/dist/hooks/guard.d.ts.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13555 -0
- package/dist/lib/db.d.ts +32 -0
- package/dist/lib/db.d.ts.map +1 -0
- package/dist/lib/frontmatter.d.ts +49 -0
- package/dist/lib/frontmatter.d.ts.map +1 -0
- package/dist/lib/paths.d.ts +48 -0
- package/dist/lib/paths.d.ts.map +1 -0
- package/dist/lib/rag.d.ts +79 -0
- package/dist/lib/rag.d.ts.map +1 -0
- package/dist/lib/ripgrep.d.ts +32 -0
- package/dist/lib/ripgrep.d.ts.map +1 -0
- package/dist/lib/search-terms.d.ts +61 -0
- package/dist/lib/search-terms.d.ts.map +1 -0
- package/dist/tools/memory.d.ts +84 -0
- package/dist/tools/memory.d.ts.map +1 -0
- package/dist/tools/session.d.ts +103 -0
- package/dist/tools/session.d.ts.map +1 -0
- package/package.json +47 -0
- package/skills/opencode-memory/SKILL.md +295 -0
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: opencode-memory
|
|
3
|
+
description: Proactive memory usage — search ~/opencode-memory/ before starting work and save reusable discoveries when done. Load this skill at the start of ANY non-trivial task, whenever working in an unfamiliar repo, using an unfamiliar tool or API, debugging, or encountering a system you don't know. Past sessions frequently leave pointers that save 5–30 minutes of rediscovery. If in doubt, load it — the overhead is minimal.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# OpenCode Memory
|
|
7
|
+
|
|
8
|
+
Memory is OpenCode's **engine of self-improvement**. Every session that uses it well leaves the system more capable for the next one. It's a living index — not a mirror of data that APIs return live, but a map of _where to look_ and _what to watch out for_.
|
|
9
|
+
|
|
10
|
+
The goal isn't to save everything — it's to save what took >1 minute to figure out and that a future session would otherwise have to rediscover from scratch.
|
|
11
|
+
|
|
12
|
+
## Tools
|
|
13
|
+
|
|
14
|
+
| Tool | Purpose |
|
|
15
|
+
| --------------------------------- | --------------------------------------- |
|
|
16
|
+
| `memory_search(query, category?)` | Hybrid keyword + semantic search |
|
|
17
|
+
| `memory_list(category?)` | Browse categories or list files |
|
|
18
|
+
| `memory_save()` | Commit + re-index after writing/editing |
|
|
19
|
+
| `memory_access(path)` | Mark a file as read & useful (bumps ranking) |
|
|
20
|
+
| `memory_setup()` | Check `rag` install status, print guidance |
|
|
21
|
+
|
|
22
|
+
Read search results with the Read tool on `~/opencode-memory/{path}`.
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## The Session Loop
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
START → memory_search("what I'm working on")
|
|
30
|
+
Read relevant files; follow Related: pointers
|
|
31
|
+
Verify mutable facts via live sources (not memory)
|
|
32
|
+
|
|
33
|
+
DURING → Save discoveries immediately when they happen
|
|
34
|
+
(context is richest right after the discovery — don't defer)
|
|
35
|
+
|
|
36
|
+
END → Run the Retrospective (see below)
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The END step is the one sessions most often skip — and the one that compounds value over time.
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## When to Search
|
|
44
|
+
|
|
45
|
+
- **Starting on any repo** — search its name for structure, build commands, gotchas
|
|
46
|
+
- **Using an unfamiliar tool or API** — a past session may have documented usage
|
|
47
|
+
- **Debugging** — a previous session may have solved the same root cause
|
|
48
|
+
- **People/team lookups** — check `people/` category, then verify live
|
|
49
|
+
- **Before saving** — search first to update existing files rather than duplicate
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## When to Save (and When Not To)
|
|
54
|
+
|
|
55
|
+
The right question isn't "could I save this?" but "would a future session waste time without this?"
|
|
56
|
+
|
|
57
|
+
**Save:**
|
|
58
|
+
|
|
59
|
+
- Gotchas and non-obvious workarounds
|
|
60
|
+
- Repo structure: where things live, build/test/deploy incantations
|
|
61
|
+
- Tool quirks and undocumented behavior
|
|
62
|
+
- Debugging root causes that weren't obvious from the error message
|
|
63
|
+
- Pointers: "use X tool for Y task; watch out for Z"
|
|
64
|
+
|
|
65
|
+
**Don't save:**
|
|
66
|
+
|
|
67
|
+
- Data that a live API returns fresh every time (query it fresh)
|
|
68
|
+
- Copies of wiki pages or API docs
|
|
69
|
+
- Task-specific context that won't generalize
|
|
70
|
+
- Anything discoverable in <1 minute from first principles
|
|
71
|
+
|
|
72
|
+
### Quality filter — ask before writing
|
|
73
|
+
|
|
74
|
+
1. Would a future session rediscover this within 1 minute from scratch? → skip
|
|
75
|
+
2. Is this specific enough to act on? Vague notes don't get read
|
|
76
|
+
3. Is there an existing memory to update rather than a new file to create?
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## Durable knowledge vs change-log (IMPORTANT)
|
|
81
|
+
|
|
82
|
+
Memory is not a work journal. The test: **will this still be useful 6 months from now?**
|
|
83
|
+
|
|
84
|
+
| Durable (save) | Change-log / ephemeral (don't save to memory) |
|
|
85
|
+
| -------------------------------------------------------------------- | ------------------------------------------------------------- |
|
|
86
|
+
| How a system works, data flow, architecture | "PR #349 is in review, reviewers X/Y/Z assigned" |
|
|
87
|
+
| Why a decision was made, design rationale | "RFC status: in discussion, ends YYYY-MM-DD" |
|
|
88
|
+
| Where code lives, build/test commands | "Current state (updated today): ticket switches X to Y" |
|
|
89
|
+
| Non-obvious gotchas, workarounds, quirks | "What's done / what's needed / what's blocked this week" |
|
|
90
|
+
| Conventions ("file names use author-slug", "errors extend AppError") | Sprint-level task lists and follow-up checklists |
|
|
91
|
+
| Version/constraint requirements ("bun ^1.3.11 required") | Version-at-time-of-writing ("we're on v1.4.6 as of today") |
|
|
92
|
+
|
|
93
|
+
**Where ephemeral status belongs:** ticket tracker files, PR descriptions, session notes — NOT `~/opencode-memory/`.
|
|
94
|
+
|
|
95
|
+
### The change-log smell-test
|
|
96
|
+
|
|
97
|
+
If the file reads like a sprint update, status report, or "here's where we are on this ticket," it's change-log. Rewrite it so the **durable lesson** stays and the timestamped state is removed.
|
|
98
|
+
|
|
99
|
+
**Change-log entry (bad):**
|
|
100
|
+
|
|
101
|
+
> As of YYYY-MM-DD, PR #349 is open with reviewers X, Y, Z. RFC is in discussion status ending YYYY-MM-DD. Next step: get council approval, then create domain page.
|
|
102
|
+
|
|
103
|
+
**Same knowledge as durable memory (good):**
|
|
104
|
+
|
|
105
|
+
> RFC naming convention: during `discussion` status use `author-slug.md`; the RFC number is auto-assigned at approval. After approval, create `docs/<domain>.md` with if/then decision statements. New domains require Owner + Council approval per RFC-002.
|
|
106
|
+
|
|
107
|
+
One could be searched for years from now and still work. The other is stale in 5 days.
|
|
108
|
+
|
|
109
|
+
### Breadth is still fine
|
|
110
|
+
|
|
111
|
+
Don't let this discourage writing memory. A short file pointing at "here's the repo, here's where the tests live, here's one gotcha I hit" is valuable even if it's not deep. **Breadth + durability** beats deep-but-ephemeral. The goal is to remove change-log noise, not to raise the bar for saving useful knowledge.
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## Retrospective (End of Session)
|
|
116
|
+
|
|
117
|
+
At the end of any non-trivial session, spend 1–2 minutes on this:
|
|
118
|
+
|
|
119
|
+
1. **What did I discover?** Anything that took >1 min to figure out → save it
|
|
120
|
+
2. **What memories did I use?** Were they accurate? Update stale ones
|
|
121
|
+
3. **What should have been in memory but wasn't?** Save it now
|
|
122
|
+
4. **Did the memory system fail me?** → log it in `notes/memory-system.md` (see below)
|
|
123
|
+
|
|
124
|
+
This only takes a couple of minutes and the value compounds across sessions.
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## Verify Mutable Facts Against Live Sources
|
|
129
|
+
|
|
130
|
+
Memory goes stale. Re-query for anything that changes:
|
|
131
|
+
|
|
132
|
+
| Fact Type | Primary Source |
|
|
133
|
+
| ------------------------------- | ---------------------------------- |
|
|
134
|
+
| Service ownership, team info | Your service catalog or wiki |
|
|
135
|
+
| People, managers, org structure | Your directory / org chart |
|
|
136
|
+
| Ticket status, assignments | Your issue tracker |
|
|
137
|
+
| Pipeline status, CI/CD | Your CI provider's API |
|
|
138
|
+
| Error tracking | Your error tracking tool |
|
|
139
|
+
|
|
140
|
+
**Trust without re-querying**: repo structure, code patterns, gotchas/workarounds, tool quirks — these are stable across sessions.
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## Self-Improvement Loop
|
|
145
|
+
|
|
146
|
+
This is where memory becomes truly self-improving. The memory skill itself can get better based on what sessions learn about it.
|
|
147
|
+
|
|
148
|
+
When the system isn't working well — a memory was wrong, a search returned noise, something important wasn't saved when it should have been — add a note to `notes/memory-system.md`:
|
|
149
|
+
|
|
150
|
+
```markdown
|
|
151
|
+
## What's working
|
|
152
|
+
|
|
153
|
+
- Memories in `repos/` with specific gotchas → high reuse rate
|
|
154
|
+
|
|
155
|
+
## What's not working
|
|
156
|
+
|
|
157
|
+
- Searches for [topic] return noise → consider subcategories or better tags
|
|
158
|
+
- [Pattern] kept being rediscovered → should have been saved in [category] with tags [X]
|
|
159
|
+
|
|
160
|
+
## Patterns observed
|
|
161
|
+
|
|
162
|
+
- Sessions that save immediately after discovery > sessions that defer to end
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
**Escalation signal**: if you find yourself writing the same kind of memory repeatedly, or if a whole category of memories is never useful, that's a signal to propose updates to this SKILL.md. The skill should evolve based on what's actually useful in this environment — that's the point.
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## Repo Notes — Path Convention
|
|
170
|
+
|
|
171
|
+
When saving notes about a repository, mirror the repo's location on the filesystem:
|
|
172
|
+
|
|
173
|
+
```
|
|
174
|
+
~/opencode-memory/repos/{host}/{org}/{repo}.md
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Examples:
|
|
178
|
+
|
|
179
|
+
- `repos/github.com/user/project.md`
|
|
180
|
+
- `repos/gitlab.com/my-group/my-project.md`
|
|
181
|
+
- `repos/bitbucket.org/team/library.md`
|
|
182
|
+
|
|
183
|
+
That way a future session can find the file by searching on any fragment of the repo URL.
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
## Frontmatter (required — include provenance)
|
|
188
|
+
|
|
189
|
+
```yaml
|
|
190
|
+
---
|
|
191
|
+
title: Human-readable title
|
|
192
|
+
tags: [tag1, tag2]
|
|
193
|
+
summary: One-line summary
|
|
194
|
+
created: YYYY-MM-DD
|
|
195
|
+
updated: YYYY-MM-DD
|
|
196
|
+
importance: high | medium | low
|
|
197
|
+
source: URL or description of primary source
|
|
198
|
+
source_date: YYYY-MM-DD # when primary source was last consulted
|
|
199
|
+
related: [category/file.md]
|
|
200
|
+
---
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
`source` and `source_date` tell future sessions where to verify and how stale this might be.
|
|
204
|
+
|
|
205
|
+
Categories: `preferences` · `repos` · `technical` · `people` · `workflows` · `snippets` · `notes`
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
## Good Memory vs. Bad Memory
|
|
210
|
+
|
|
211
|
+
**Good** — pointer + actionable gotcha (still useful in a year):
|
|
212
|
+
|
|
213
|
+
```markdown
|
|
214
|
+
---
|
|
215
|
+
title: api-core uses custom error hierarchy
|
|
216
|
+
tags: [api-core, error-handling]
|
|
217
|
+
summary: All errors must extend AppError; throwing plain Error bypasses formatting
|
|
218
|
+
source: Code inspection of src/errors/ in api-core
|
|
219
|
+
source_date: 2025-06-15
|
|
220
|
+
importance: high
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
All errors in `src/errors/` must extend `AppError`. Throwing plain `Error` bypasses
|
|
224
|
+
error formatting → raw 500s. Gotcha: `AuthError` must include `realm` field or auth
|
|
225
|
+
middleware silently ignores it.
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
**Bad — data dump:**
|
|
229
|
+
|
|
230
|
+
```markdown
|
|
231
|
+
# Software Catalog
|
|
232
|
+
|
|
233
|
+
[200 lines copied from an API response]
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
Fix: "Use the catalog API. Gotcha: entity refs use `group:teams/` prefix for groups, not `group:default/`."
|
|
237
|
+
|
|
238
|
+
**Bad — change-log / status report:**
|
|
239
|
+
|
|
240
|
+
```markdown
|
|
241
|
+
## What's Done
|
|
242
|
+
|
|
243
|
+
- ✅ PR #349 open with reviewers X, Y, Z
|
|
244
|
+
- ✅ RFC in discussion status
|
|
245
|
+
|
|
246
|
+
## What's Needed
|
|
247
|
+
|
|
248
|
+
1. Get RFC approved (blocked on council)
|
|
249
|
+
2. Create domain page after approval
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
Fix: extract the durable convention and put sprint tracking in a ticket file.
|
|
253
|
+
|
|
254
|
+
**Bad — timestamped "current state" inside an architecture doc:**
|
|
255
|
+
|
|
256
|
+
```markdown
|
|
257
|
+
### Module Foo
|
|
258
|
+
|
|
259
|
+
**Target:** Route via new membership check.
|
|
260
|
+
**Current state (updated YYYY-MM-DD):** ticket-123 switches foo... PR #... in flight.
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
Fix: document the target architecture as if it's already the design. If you must note migration state, keep it one line: "Migration tracked in ticket-123." The architecture doc should not rot when the migration merges.
|
|
264
|
+
|
|
265
|
+
---
|
|
266
|
+
|
|
267
|
+
## Search Tips
|
|
268
|
+
|
|
269
|
+
- Be specific: `memory_search("retry jitter config")` not `memory_search("retry")`
|
|
270
|
+
- Multi-term = OR with ranking: `"oauth scopes"` surfaces files with both terms first
|
|
271
|
+
- Filter by category: `memory_search("api-core", category="repos")`
|
|
272
|
+
- Follow `Related:` pointers in results — connected knowledge is often more useful than the direct hit
|
|
273
|
+
- Set `importance: high` for frequently referenced knowledge; it affects ranking
|
|
274
|
+
|
|
275
|
+
---
|
|
276
|
+
|
|
277
|
+
## Installation — Search Backends
|
|
278
|
+
|
|
279
|
+
Both search backends ship as npm dependencies with prebuilt binaries:
|
|
280
|
+
|
|
281
|
+
| Backend | Package | Provides the `<bin>` |
|
|
282
|
+
| ---------------------- | ----------------------- | -------------------- |
|
|
283
|
+
| **Keyword (ripgrep)** | `@vscode/ripgrep` | `rg` |
|
|
284
|
+
| **Semantic (rag-cli)** | `@mathew-cf/rag-cli` | `rag` |
|
|
285
|
+
|
|
286
|
+
No manual install is needed — `npm install` (or whatever installs this plugin) pulls in both and resolves them via `require.resolve` at runtime. Nothing depends on `$PATH`.
|
|
287
|
+
|
|
288
|
+
After install, run once to pre-cache the embedding model (optional but makes the first semantic search instant):
|
|
289
|
+
|
|
290
|
+
```bash
|
|
291
|
+
memory_setup # reports which backends are resolvable
|
|
292
|
+
rag download # downloads the MiniLM-L6 weights (~90MB)
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
If a backend fails to install (unsupported platform, etc.), the tools degrade gracefully — `memory_search` still returns whatever the available backend can find. Call `memory_setup` any time to see install guidance for the missing piece.
|