@nandoblanco/opencode-local-memory 0.0.0-stage → 1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Fernando Blanco
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,308 @@
1
- # Temporary Holding Version
1
+ # opencode-local-memory
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ **Local-first, automatic persistent memory plugin for OpenCode**: recalls relevant facts and session summaries automatically on every turn, stores new decisions and preferences as plain local markdown with local CPU embeddings, checkpoints session compactions automatically, and includes a zero-token `/memory` TUI popup.
4
+
5
+ ![opencode-local-memory TUI preview](./assets/screenshot.png)
6
+
7
+ ## Background
8
+
9
+ This plugin started as a folder of markdown files and CLI scripts wired together through instructions in `AGENTS.md`. That setup worked on one machine, but every new environment needed the same prompt rules, and searching memory from the chat meant spending model tokens on a script call.
10
+
11
+ `opencode-local-memory` packages that workflow into a self-contained OpenCode plugin:
12
+
13
+ 1. **Human-readable markdown is the source of truth**: Atomic facts live in `topics/*.md` and session summaries live in `sessions/*.md`. You can read, edit, or back them up like any ordinary text files.
14
+ 2. **Local CPU embeddings (`vectors.json`)**: Uses `@xenova/transformers` (`Xenova/all-MiniLM-L6-v2`) inside the OpenCode process to embed and search entries on CPU without external servers or API keys.
15
+ 3. **Self-contained lifecycle hooks**: The plugin's `context` hook recalls relevant memories for each prompt and injects the storage and recall rules directly into `<local-memory-plugin>`, so you do not need custom `AGENTS.md` instructions.
16
+ 4. **Zero-token TUI search & store**: Browse, filter, and add memories directly inside OpenCode via `/memory` and `/memory-add` without making an LLM request.
17
+
18
+ ## Features
19
+
20
+ | Feature | Details |
21
+ | :--- | :--- |
22
+ | Local-first, zero-token TUI & CPU embeddings | Runs 384-dimensional `Xenova/all-MiniLM-L6-v2` embeddings locally on CPU and provides a zero-token `/memory` TUI browser with no cloud API keys or external servers |
23
+ | Human-readable markdown source of truth | Stores atomic facts in `topics/*.md` and session checkpoints in `sessions/*.md` so every memory stays plain, editable markdown |
24
+ | Automatic per-turn recall (`context` hook) | Before each model call, runs hybrid semantic + lexical search (`vectors.json`) against the user's prompt and injects the top matching facts and session checkpoints into `event.system` |
25
+ | Atomic fact storage (`memory_store` & `/memory-add`) | Appends formatted blocks to `topics/<topic>.md`, auto-increments sequential IDs (`<prefix>-<nnn>`), registers new topic files in `memory.md`, and updates `vectors.json` in a single atomic call |
26
+ | Automatic session checkpoints (`compaction` hook) | Captures distilled session summaries (`sessions/YYYY-MM-DD_<slug>-<NN>.md`) automatically on session compaction or via `memory_checkpoint` and indexes them into `vectors.json` |
27
+ | Interactive `/memory` TUI modal | Wide (`80%` default, configurable via `dialogWidth`) split-pane browser with colored filter pills (`^t` type, `^g` topic, `^r` mode, `^l` resync), instant 0ms lexical filtering refined by local vector similarity, and full session markdown preview |
28
+ | Automatic first-run bootstrap | On a blank install, automatically creates `~/.config/opencode/memory` (or `$XDG_CONFIG_HOME/opencode/memory`) with `memory.md`, starter `topics/{preferences,decisions,environment,agent-behavior}.md`, and `sessions/README.md` |
29
+
30
+ ## Installation
31
+
32
+ ### Option 1: One-Command Install (Recommended)
33
+
34
+ Run the built-in installer to automatically register the server and TUI plugins in `~/.config/opencode/opencode.jsonc` and `~/.config/opencode/cli.json` (preserving existing comments and settings), create `~/.config/opencode/memory`, and pre-warm the local embedding model:
35
+
36
+ ```sh
37
+ npx @nandoblanco/opencode-local-memory install
38
+ ```
39
+
40
+ Or specify a custom memory folder:
41
+
42
+ ```sh
43
+ npx @nandoblanco/opencode-local-memory install --dir ~/my-memory
44
+ ```
45
+
46
+ You can also install directly with OpenCode's native plugin CLI (because `package.json` exports both `.` and `./tui`, OpenCode loads both the server plugin and TUI popup automatically):
47
+
48
+ ```sh
49
+ opencode plugin add @nandoblanco/opencode-local-memory
50
+ # or directly from GitHub:
51
+ opencode plugin add github:nandoblanco/opencode-local-memory
52
+ ```
53
+
54
+ ### Option 2: Manual Configuration
55
+
56
+ Add `@nandoblanco/opencode-local-memory` to `~/.config/opencode/opencode.jsonc` and `~/.config/opencode/cli.json`:
57
+
58
+ ```jsonc
59
+ {
60
+ "plugins": [
61
+ {
62
+ "package": "@nandoblanco/opencode-local-memory",
63
+ "options": {
64
+ "directory": "~/.config/opencode/memory",
65
+ "minScore": 0.38,
66
+ "topK": 6,
67
+ "dialogWidth": "80%"
68
+ }
69
+ }
70
+ ]
71
+ }
72
+ ```
73
+
74
+ ### From a Local Directory
75
+
76
+ Clone this repository, run `npm install`, and run `node ./index.js install` (or reference `"file:///path/to/opencode-local-memory"` in `opencode.jsonc` and `cli.json`):
77
+
78
+ ```json
79
+ {
80
+ "plugins": ["file:///path/to/opencode-local-memory"]
81
+ }
82
+ ```
83
+
84
+ ## Usage
85
+
86
+ ### Automatic Agent Memory (Server Tools & Hooks)
87
+
88
+ Once enabled, the plugin manages memory automatically during normal coding sessions:
89
+
90
+ - **Automatic Storage (`memory_store`)**: When you state a preference or coding convention, make an architectural decision, uncover a non-obvious environment fact, or correct the agent, the model calls `memory_store` before finishing its turn.
91
+ - **Automatic Recall (`context` hook + `memory_search`)**: The `context` hook injects relevant memories before each turn. For broader lookups, the model calls `memory_search` (`hybrid`, `semantic`, or `grep`).
92
+ - **Automatic Checkpoints (`compaction` hook + `memory_checkpoint`)**: The plugin writes numbered session summaries to `sessions/YYYY-MM-DD_<slug>-<NN>.md` and indexes them into `vectors.json`.
93
+
94
+ ### Zero-Token TUI Commands
95
+
96
+ 1. **Interactive `/memory` popup**: Run `/memory` (or `/memory <query>`) or press `Ctrl+P` and select `Search local memory (0 tokens)...`.
97
+ 2. **Direct zero-token storage (`/memory-add`)**: Run `/memory-add <topic> | <tags> | <fact>` to append a fact and embed it into `vectors.json` immediately without invoking the AI:
98
+ ```text
99
+ /memory-add preferences | css, layout | Always verify layout changes with Playwright before reporting completion.
100
+ ```
101
+ 3. **Custom keybind**: Bind `local.memory.search` in `~/.config/opencode/cli.json`:
102
+ ```json
103
+ {
104
+ "keybinds": {
105
+ "local.memory.search": "ctrl+m"
106
+ }
107
+ }
108
+ ```
109
+
110
+ ## TUI Query Syntax (`/memory`)
111
+
112
+ Type filters inline in the search bar or toggle them with clickable filter pills and keyboard shortcuts.
113
+
114
+ | Syntax | Description | Example |
115
+ | :--- | :--- | :--- |
116
+ | `term1 term2` | Hybrid semantic (`Xenova/all-MiniLM-L6-v2`) + lexical search | `winnipeg velocity cards` |
117
+ | `/pattern/i` or `re:pattern` | Regular expression match across ID, tags, fact, and file path | `/dec-01[0-9]/i` |
118
+ | `type:topics` / `type:sessions` / `type:all` | Filter to atomic topic facts (`topics/*.md`) or session checkpoints (`sessions/*.md`) (`type:facts`, `in:topics`, `in:sessions` also work) | `type:sessions plugin` |
119
+ | `topic:<slug>` | Filter to a specific topic file (`topics/<slug>.md`) | `topic:decisions self-contained` |
120
+
121
+ ## Keyboard Shortcuts (`/memory`)
122
+
123
+ | Key | Action |
124
+ | :--- | :--- |
125
+ | `Enter` | Copy the selected memory entry (`[id] (file): fact`) to the clipboard and close the popup |
126
+ | `Up` / `Down` or `Ctrl+K` / `Ctrl+N` | Move selection up or down (`j`/`k` also work when the Results List pane is focused) |
127
+ | `PageUp` / `PageDown` or `Ctrl+U` / `Ctrl+D` | Jump 6 items up/down (or scroll the right Preview pane by 8 lines when focused) |
128
+ | `Tab` / `Shift+Tab` | Switch focus between Search Input, Results List, and Preview Pane |
129
+ | `Ctrl+T` | Cycle entry type filter pill (`all` -> `topics` -> `sessions`) |
130
+ | `Ctrl+G` | Cycle topic file filter pill (`all` -> `decisions` -> `preferences` -> `environment` -> ...) |
131
+ | `Ctrl+R` | Cycle search mode pill (`hybrid` -> `keyword` -> `regex`) |
132
+ | `Ctrl+L` | Force resync markdown files (`topics/*.md` + `sessions/*.md`) into `vectors.json` |
133
+ | `Esc` | Close popup |
134
+
135
+ ## How It Works (Architecture & Internals)
136
+
137
+ ### 1. Memory Directory Resolution & First-Run Bootstrap (`resolveMemoryDir` & `ensureMemoryLayout`)
138
+
139
+ When the plugin initializes, `resolveMemoryDir()` selects the active memory directory in this order:
140
+
141
+ 1. Explicit `directory` option in `opencode.jsonc` / `cli.json` (supports `~` expansion)
142
+ 2. `OPENCODE_MEMORY_DIR` environment variable
143
+ 3. Parent directory of `index.js` if both `memory.md` and `topics/` already exist there
144
+ 4. `$XDG_CONFIG_HOME/opencode/memory` or `~/.config/opencode/memory` (default)
145
+
146
+ On startup and before any write or sync operation, `ensureMemoryLayout(rootDir)` checks the target directory. If `memory.md`, `topics/`, or `sessions/` are missing, it creates the directory tree, writes `memory.md` and `sessions/README.md`, and initializes four starter topic files (`preferences.md`, `decisions.md`, `environment.md`, `agent-behavior.md`). No pre-existing files are overwritten.
147
+
148
+ ### 2. Per-Turn System Prompt Injection (`context` Hook)
149
+
150
+ Before each model turn, the server plugin's `ctx.session.hook("context")` handler inspects the conversation and appends a `<local-memory-plugin>` block to `event.system`:
151
+
152
+ 1. **Dynamic topic discovery**: Scans `topics/*.md` via `getTopicSlugs()` and lists every available topic slug, instructing the model that passing any new slug to `memory_store` will create a new topic file automatically.
153
+ 2. **Automatic storage triggers**: Instructs the model to call `memory_store` in the same turn whenever:
154
+ - The user states a preference, convention, or workflow rule
155
+ - An architectural, workflow, or design decision is made
156
+ - A non-obvious environment, path, port, or tooling fact is discovered
157
+ - A recurring pattern emerges
158
+ - The user corrects the model or repeats an instruction
159
+ 3. **Global vs. project scope rules**: Directs cross-project facts to `memory_store` (`topics/*.md`) and repository-specific conventions or asset IDs to the project's `AGENTS.md`.
160
+ 4. **Per-prompt auto-recall**: Extracts the latest user message (`extractLastUserText`), runs a hybrid semantic + lexical search against `vectors.json` when the prompt is at least 5 characters long, filters hits with `score >= minScore` (default `0.38`, top `topK = 6`), and injects matching facts directly into `<local-memory-plugin>`.
161
+
162
+ ### 3. How Topic Files & IDs Are Created (`memory_store` & `storeMemoryFact`)
163
+
164
+ When a storage trigger fires (or when you run `/memory-add` or `npx @nandoblanco/opencode-local-memory store`), `storeMemoryFact(rootDir, input)` executes an atomic write-and-embed pipeline:
165
+
166
+ 1. **Choosing an existing vs. new topic**: The model checks the injected `Available topics` list. If the fact matches an existing category (`preferences`, `decisions`, `environment`, `agent-behavior`), it passes that slug. If the fact belongs to a new domain (for example, `tools`, `sql`, or `frontend-css-patterns`), it passes a new kebab-case slug.
167
+ 2. **Automatic topic file creation**: Normalizes the slug via `.toLowerCase().replace(/[^a-z0-9-_]/g, "-")`. If `topics/<slug>.md` does not exist yet, the plugin creates it with a `# <Slug>` heading and appends `- \`topics/<slug>.md\` - <slug> entries` to `memory.md`.
168
+ 3. **Sequential ID generation (`nextTopicId`)**: Scans existing `- id: <prefix>-<nnn>` blocks in `topics/<slug>.md`, preserves the file's prefix convention (for example, `dec-016` increments to `dec-017`, while a new `tools.md` file starts at `tools-001`), and formats the new YAML-style entry block with today's `YYYY-MM-DD` date.
169
+ 4. **Immediate vector indexing**: Embeds `fact + " " + tags` into a 384-dimensional vector and updates `vectors.json` and the in-memory cache immediately so the fact is searchable on the very next turn.
170
+
171
+ ### 4. Session Checkpoints (`memory_checkpoint` & `compaction` Hook)
172
+
173
+ `storeSessionCheckpoint(rootDir, input)` writes session summaries to `sessions/YYYY-MM-DD_<slug>-<NN>.md` in two ways:
174
+
175
+ 1. **Model-initiated (`memory_checkpoint` tool)**: At the end of significant work sessions, the model passes a `slug`, `title`, and structured markdown `summary` (`What was built/fixed/decided`, `Key decisions`, `Problems solved`, `Outcome`).
176
+ 2. **Automatic compaction (`compaction` hook)**: When OpenCode compacts a conversation (`ctx.session.hook("compaction")`), the plugin derives a 4-word slug from the last active user prompt, writes a numbered checkpoint file, records `.session-state`, and calls `syncVectors()` so the session summary is indexed into `vectors.json`.
177
+
178
+ Checkpoint numbers (`-01`, `-02`, ...) auto-increment per `YYYY-MM-DD_<slug>` prefix so multiple checkpoints on the same day never collide.
179
+
180
+ ### 5. Local Embedding Model, Hybrid Search & Caching (`syncVectors` & `searchMemory`)
181
+
182
+ `opencode-local-memory` uses `Xenova/all-MiniLM-L6-v2`, a 23 MB sentence-embedding model that converts any sentence into a 384-number vector representing its meaning:
183
+
184
+ ```js
185
+ const mod = await import("@xenova/transformers");
186
+ const embed = await mod.pipeline("feature-extraction", "Xenova/all-MiniLM-L6-v2");
187
+ const out = await embed(text, { pooling: "mean", normalize: true });
188
+ const vec = Array.from(out.data); // -> [0.021, -0.084, 0.112, ... 384 numbers]
189
+ ```
190
+
191
+ - **Semantic vs. keyword matching**: Exact keyword search (`grep`) only matches shared characters. If you store *"Always run backup.ps1 before editing"* and later ask *"how do we undo changes?"*, keyword search returns nothing because no words overlap. The embedding model places both sentences near each other in 384-dimensional space, so their dot product (`dot(queryVec, entry.vector)`) scores high even with zero shared words.
192
+ - **Model installation and local cache**: `@xenova/transformers` is a regular npm dependency in `package.json` that runs ONNX models on CPU inside Node.js or Bun (no Python or external server). On first run, `pipeline("feature-extraction", "Xenova/all-MiniLM-L6-v2")` downloads `onnx/model_quantized.onnx` (~23 MB) and `tokenizer.json` from Hugging Face into `node_modules/@xenova/transformers/.cache/Xenova/all-MiniLM-L6-v2/`. Every subsequent run loads the quantized model from local disk in milliseconds, offline.
193
+ - **Incremental vector sync (`syncVectors`)**: Parses all `topics/*.md` blocks and `sessions/*.md` summaries and compares each entry's `id`, `fact`, and `tags` against `vectors.json`. Unchanged entries reuse their cached 384-dimensional vectors; only new or modified entries run through the embedding pipeline.
194
+ - **Scoring formula (`searchMemory`)**:
195
+ - `semanticScore`: Dot product (cosine similarity on L2-normalized vectors) between the 384-number query vector and each stored entry vector (`0.0` to `1.0`), computed in plain JavaScript in under 2 milliseconds.
196
+ - `lexicalScore`: `+0.35` if the full lowercase query is an exact substring of the entry haystack (`id + tags + fact + file`), or `(matchedWords / queryWords) * 0.25` for partial token matches (tokens >= 2 characters).
197
+ - Final score: `semanticScore + lexicalScore` in `hybrid` mode (default), `semanticScore` in `semantic` mode, or `lexicalScore` in `grep` mode.
198
+ - **In-memory & cross-process caching**:
199
+ - `loadCachedVectors()` caches parsed entries in memory and validates `vectors.json` via `fs.statSync(vecFile).mtimeMs` and resolved path (`cachedRootDir`), automatically reloading if another process or CLI command updates `vectors.json`.
200
+ - `queryVecCache` keeps an in-memory 128-entry FIFO cache of normalized query embeddings to avoid re-embedding repeated prompts.
201
+ - `lastContextKey` caches the generated `<local-memory-plugin>` system block per `(userText, cachedVersion)` pair so duplicate hook invocations within the same turn do zero extra work.
202
+
203
+ ### 6. Interactive OpenTUI `/memory` Modal Architecture (`tui.ts`)
204
+
205
+ 1. **Wide modal layout (`applyDialogWidth` & `dialog.set`)**:
206
+ - Calls `context.ui.dialog.show(...)` followed by `context.ui.dialog.set({ size: "xlarge", centered: true })` so the dialog opens wide without being reset to default width.
207
+ - Inside `onMount` and `ref`, `applyDialogWidth()` walks upward from `rootRef` to the outer `absolute`-positioned dialog container and sets `width: "80%"` (or your configured `dialogWidth`), `maxWidth: "80%"`, and `minWidth: 76`.
208
+ 2. **Two-phase 0ms lexical + async hybrid search (`runSearch`)**:
209
+ - On every keystroke, `filterEntriesSync()` runs synchronously in 0ms against the in-memory `vectors.json` entries so the results list updates immediately with zero input lag.
210
+ - When `mode` is `"hybrid"` and the query is at least 2 characters long, `runSearch()` then awaits `searchMemory(rootDir, q, "hybrid", 50)` (guarded by a monotonic `searchSeq` counter to discard stale async results) and refines the list with semantic vector similarity scores (`score >= 0.22`).
211
+ 3. **Split-pane layout & full session markdown preview**:
212
+ - Renders interactive `Pill` components beneath the search bar for `type:<filter>` (`^t`), `topic:<slug>` (`^g`), and `mode:<mode>` (`^r`).
213
+ - Splits the main body into a 44%-width left results list (entry ID, hybrid score, source file, and 1-line summary) and a 56%-width right preview pane (metadata card, search-term highlighted fact text, and full markdown file content via `readFullSessionMarkdown()` whenever a `sessions/*.md` checkpoint is selected).
214
+
215
+ ### 7. Agent Tools Registered by the Server Plugin
216
+
217
+ | Tool Name | Required Inputs | Optional Inputs | Behavior |
218
+ | :--- | :--- | :--- | :--- |
219
+ | `memory_store` | `topic`, `tags`, `fact` | `id` | Creates `topics/<topic>.md` if missing, registers it in `memory.md`, assigns the next `<prefix>-<nnn>` ID, appends the entry block, and updates `vectors.json`. |
220
+ | `memory_search` | `query` | `mode` (`hybrid`, `semantic`, `grep`), `topN` (default `8`) | Searches all topic facts and session checkpoints and returns ranked entries with scores, IDs, dates, file paths, tags, and facts. |
221
+ | `memory_checkpoint` | `slug`, `title`, `summary` | `project` (default `global`), `contextPct` | Writes `sessions/YYYY-MM-DD_<slug>-<NN>.md`, updates `.session-state`, and indexes the checkpoint into `vectors.json`. |
222
+
223
+ ### 8. Token Usage Breakdown
224
+
225
+ Local embedding, TUI browsing, and direct `/memory-add` storage use zero LLM tokens:
226
+
227
+ | Operation | Token Cost | Why |
228
+ | :--- | :--- | :--- |
229
+ | Interactive `/memory` TUI modal (`Ctrl+M`) | **0 tokens** | Reads `vectors.json` and `sessions/*.md` directly from disk and runs `Xenova/all-MiniLM-L6-v2` locally on CPU without an LLM request |
230
+ | Direct TUI fact storage (`/memory-add`) | **0 tokens** | Parses `<topic> \| <tags> \| <fact>`, appends to `topics/<topic>.md`, and updates `vectors.json` locally in Node.js |
231
+ | Automatic compaction checkpoint (`compaction` hook) | **0 extra turn tokens** | Captures the existing compaction summary event and indexes it locally into `sessions/*.md` and `vectors.json` |
232
+ | Standalone CLI (`npx @nandoblanco/opencode-local-memory ...`) | **0 tokens** | Runs directly in Node.js outside the model turn |
233
+ | Per-turn auto-recall (`context` hook) & agent tools | **~250-450 system/schema tokens** | Injects compact instructions plus top matching facts (`score >= 0.38`, max `topK = 6`) into `event.system` and registers `memory_store`, `memory_search`, and `memory_checkpoint` |
234
+
235
+ ## Directory Structure
236
+
237
+ ```text
238
+ ~/.config/opencode/memory/
239
+ ├── memory.md # Global index of topic files
240
+ ├── vectors.json # Local 384-dim embeddings cache (auto-maintained)
241
+ ├── topics/
242
+ │ ├── preferences.md # User coding style and workflow rules
243
+ │ ├── decisions.md # Architectural and cross-project decisions
244
+ │ ├── environment.md # Machine, OS, paths, and tooling facts
245
+ │ └── agent-behavior.md # Corrections and operational protocols
246
+ └── sessions/
247
+ ├── README.md
248
+ └── YYYY-MM-DD_slug-01.md # Distilled session checkpoints
249
+ ```
250
+
251
+ Each entry in `topics/<topic>.md` uses a clean, human-editable block format:
252
+
253
+ ```yaml
254
+ - id: dec-016
255
+ date: 2026-10-25
256
+ tags: [opencode, plugin, local-memory, self-contained]
257
+ fact: All persistent memory rules are injected directly by opencode-local-memory's context hook.
258
+ ```
259
+
260
+ ## CLI Commands
261
+
262
+ ```sh
263
+ # One-command setup: updates opencode.jsonc + cli.json, scaffolds memory/, and warms vectors.json
264
+ npx @nandoblanco/opencode-local-memory install [--dir /path/to/memory]
265
+
266
+ # Incrementally sync topics/*.md and sessions/*.md into vectors.json
267
+ npx @nandoblanco/opencode-local-memory sync
268
+
269
+ # Hybrid, semantic, or exact keyword search
270
+ npx @nandoblanco/opencode-local-memory search "query" [hybrid|semantic|grep] [topN]
271
+
272
+ # Exact keyword grep
273
+ npx @nandoblanco/opencode-local-memory recall "exact keyword"
274
+
275
+ # Store a new fact from the command line
276
+ npx @nandoblanco/opencode-local-memory store decisions "arch, api" "Use REST endpoints for batch exports."
277
+ ```
278
+
279
+ ## Configuration Options
280
+
281
+ Options can be passed in `~/.config/opencode/opencode.jsonc` and `~/.config/opencode/cli.json` or via environment variables:
282
+
283
+ ```jsonc
284
+ {
285
+ "plugins": [
286
+ {
287
+ "package": "@nandoblanco/opencode-local-memory",
288
+ "options": {
289
+ "directory": "~/.config/opencode/memory",
290
+ "minScore": 0.38,
291
+ "topK": 6,
292
+ "dialogWidth": "80%"
293
+ }
294
+ }
295
+ ]
296
+ }
297
+ ```
298
+
299
+ | Option | Env Variable | Default | Description |
300
+ | :--- | :--- | :--- | :--- |
301
+ | `directory` | `OPENCODE_MEMORY_DIR` | `~/.config/opencode/memory` | Path to the persistent memory directory (`memory.md`, `topics/`, `sessions/`, `vectors.json`) |
302
+ | `minScore` | *(none)* | `0.38` | Minimum hybrid similarity score (`0.0`-`1.0`) for per-prompt auto-recall injection |
303
+ | `topK` | *(none)* | `6` | Maximum auto-recalled facts injected per turn |
304
+ | `dialogWidth` | `OPENCODE_MEMORY_DIALOG_WIDTH` | `"80%"` | Width of the centered `/memory` TUI modal (`"80%"` or column count like `120`; also respects `OPENCODE_DIALOG_WIDTH`) |
305
+
306
+ ## License
307
+
308
+ MIT
Binary file