@nandoblanco/opencode-local-memory 1.1.1 → 1.3.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/CHANGELOG.md ADDED
@@ -0,0 +1,35 @@
1
+ # Changelog
2
+
3
+ ## 1.3.0 (2026-11-17)
4
+
5
+ - Removed the trailing keyboard shortcut badge (`Ctrl+Shift+M`) from the left sidebar `vertical-tabs-memories` button and added `whitespace-nowrap` so sidebar button labels do not wrap (`gui.tsx`).
6
+ - Kept the `<local-memory-plugin>` system block constant per session in the `context` hook to preserve prompt cache hits across turns.
7
+ - Added `maintainMemory()` (`npx @nandoblanco/opencode-local-memory maintain` / `clean`, `--prune-imported`) and automatic 24-hour background maintenance via `.last-maintain` to deduplicate topic facts and prune auto-compaction stub files.
8
+ - Required an explicit compaction summary (`>= 40` chars) before writing compaction checkpoints and capped auto-recalled `session:` entries at 2 per turn.
9
+
10
+ ## 1.2.0 (2026-11-12)
11
+
12
+ - Added OpenCode Desktop Memory Manager (`gui.tsx`, `gui.css`, `dist/gui-experimental.cjs`, and `MemoryRpc` in `rpc.js`) with a persistent side panel (`Ctrl+Shift+M` to open/focus, `Ctrl+Alt+M` to toggle), fallback dialog when no session is active, query and project filters, inline fact creation/editing, core pinning (`core: true`), entry deletion, rule/session import, and index resync.
13
+ - Added interactive fact creation, editing, core pin/unpin, and deletion confirmation inside the `/memory` TUI modal (`tui.ts`).
14
+ - Pinned patched `glob` and `minimatch` versions in development dependency overrides (`package.json`).
15
+
16
+ ## 1.1.1 (2026-10-28)
17
+
18
+ - Refined the `/memory` OpenTUI modal layout (`tui.ts`) with a bordered filter bar and split-pane preview cards.
19
+
20
+ ## 1.1.0 (2026-10-27)
21
+
22
+ - Added zero-token rule and history importer (`importRulesAndSessions` in `index.js`, `/memory-import`, `Ctrl+B` in `/memory`, and `npx @nandoblanco/opencode-local-memory import`) to import `AGENTS.md` / `CLAUDE.md` rules into `topics/*.md` and compacted session summaries from `opencode.db` into `sessions/*.md`.
23
+ - Added `memory_delete` agent tool, `/memory-delete` slash command, and `supersedes` replacement pruning on `memory_store`.
24
+ - Added `project` scoping (`global` vs. project-specific memories with umbrella-root detection) and `core: true` pinned invariants injected on every turn.
25
+ - Upgraded hybrid search (`searchMemories`) to combine 384-dimensional `Xenova/all-MiniLM-L6-v2` cosine similarity with field-weighted Okapi BM25 scoring.
26
+
27
+ ## 1.0.1 (2026-10-26)
28
+
29
+ - Scoped npm package as `@nandoblanco/opencode-local-memory` with public `publishConfig` and normalized `bin` and `repository` fields.
30
+ - Hardened tag and entry ID sanitization, ONNX runtime lifecycle cleanup, concurrent `syncVectors` serialization, and comment-preserving JSONC config installation (`installPlugin`).
31
+
32
+ ## 1.0.0 (2026-10-25)
33
+
34
+ - Initial release of `opencode-local-memory` for OpenCode.
35
+ - Added local markdown memory storage (`topics/*.md` and `sessions/*.md`), CPU vector indexing (`vectors.json` via `@huggingface/transformers`), automatic per-turn recall (`context` hook), session compaction checkpoints (`compaction` hook), agent tools (`memory_search`, `memory_store`, `memory_checkpoint`), and the zero-token `/memory` TUI browser (`tui.ts`).
package/README.md CHANGED
@@ -1,9 +1,15 @@
1
1
  # opencode-local-memory
2
2
 
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.
3
+ **Local-first, automatic persistent memory plugin for OpenCode**: recalls relevant facts and session summaries on every turn, stores decisions and preferences as local markdown with CPU embeddings, checkpoints session compactions, and provides a zero-token Memory Manager in the TUI and OpenCode Desktop.
4
4
 
5
5
  ![opencode-local-memory TUI preview](./assets/screenshot.png)
6
6
 
7
+ ## OpenCode Desktop Support
8
+
9
+ **Now available in OpenCode Desktop as well as the TUI.** The persistent Memory side panel lets you search stored memories, add and edit facts, pin or unpin core memories, delete entries, import history, and resync the index without a model turn. Press `Ctrl+Shift+M` to open or focus the panel, or `Ctrl+Alt+M` to toggle it. When no session is active, the manager opens in a fallback dialog.
10
+
11
+ One global OpenCode V2 plugin entry loads the server, TUI, and Desktop integration together. Both interfaces use the same local memory files and index; see [Installation](#installation) for setup.
12
+
7
13
  ## Background
8
14
 
9
15
  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.
@@ -11,7 +17,7 @@ This plugin started as a folder of markdown files and CLI scripts wired together
11
17
  `opencode-local-memory` packages that workflow into a self-contained OpenCode plugin:
12
18
 
13
19
  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.
20
+ 2. **Local CPU embeddings (`vectors.json`)**: Uses `@huggingface/transformers` (`Xenova/all-MiniLM-L6-v2`) inside the OpenCode process to embed and search entries on CPU without external servers or API keys.
15
21
  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
22
  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
23
 
@@ -27,6 +33,8 @@ This plugin started as a folder of markdown files and CLI scripts wired together
27
33
  | Interactive `/memory` TUI modal | Wide (`80%` default, configurable via `dialogWidth`) split-pane browser with colored filter pills (`^t` type, `^g` topic, `^r` mode, `^b` import, `^l` resync), instant 0ms lexical filtering refined by local vector similarity, and full session markdown preview |
28
34
  | Zero-token history & rule import (`/memory-import`) | Imports existing `AGENTS.md` / `CLAUDE.md` rules into `topics/*.md` and compacted session summaries from `opencode.db` into `sessions/*.md` idempotently via `/memory-import`, `^b` inside `/memory`, or `npx @nandoblanco/opencode-local-memory import` |
29
35
  | 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` |
36
+ | Interactive fact management | Add and edit topic facts, pin or unpin core entries, and confirm deletion inside the TUI Manager; session checkpoint editing is read-only |
37
+ | OpenCode Desktop Manager | Persistent Memory side panel, query and project filters, fact editor, pin/unpin, delete, import, and resync through `MemoryRpc`; opens a fallback dialog when no session is active |
30
38
 
31
39
  ## Installation
32
40
 
@@ -54,7 +62,7 @@ opencode plugin add github:nandoblanco/opencode-local-memory
54
62
 
55
63
  ### Option 2: Manual Configuration
56
64
 
57
- Add `@nandoblanco/opencode-local-memory` to `~/.config/opencode/opencode.jsonc` and `~/.config/opencode/cli.json`:
65
+ Add `@nandoblanco/opencode-local-memory` to the global `~/.config/opencode/opencode.jsonc`. OpenCode V2 loads its server, TUI, and Desktop parts from this single entry. The installer also writes `cli.json` for its TUI setup; a separate manual entry there is not required:
58
66
 
59
67
  ```jsonc
60
68
  {
@@ -74,7 +82,7 @@ Add `@nandoblanco/opencode-local-memory` to `~/.config/opencode/opencode.jsonc`
74
82
 
75
83
  ### From a Local Directory
76
84
 
77
- 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`):
85
+ For development, use Node.js 26.4 or newer to meet the OpenTUI dependency's declared minimum. Clone this repository, run `npm ci` and `npm run build:gui`, then run `node ./index.js install` or reference the package directory in the global `opencode.jsonc`. The root `overrides` pin patched `glob` and `minimatch` versions for this repository's development dependencies; they do not alter the OpenCode host application's dependencies:
78
86
 
79
87
  ```json
80
88
  {
@@ -113,6 +121,12 @@ Once enabled, the plugin manages memory automatically during normal coding sessi
113
121
  }
114
122
  ```
115
123
 
124
+ ### OpenCode Desktop
125
+
126
+ Run `/memory [query]` or press `Ctrl+Shift+M` (`Cmd+Shift+M` on macOS) to open and focus the persistent Memory side panel. `Ctrl+Alt+M` (`Cmd+Option+M`) toggles the panel. Without an active session, these commands open a dialog instead. Titlebar and vertical-tab shortcuts also open the Manager.
127
+
128
+ The Desktop commands `/memory-add`, `/memory-delete`, and `/memory-import` call the server RPC methods without a model turn. `/memory-add` without pipe-separated arguments opens the fact editor. Desktop shortcuts are separate from the TUI keybindings below.
129
+
116
130
  ## TUI Query Syntax (`/memory`)
117
131
 
118
132
  Type filters inline in the search bar or toggle them with clickable filter pills and keyboard shortcuts.
@@ -131,14 +145,18 @@ Type filters inline in the search bar or toggle them with clickable filter pills
131
145
  | Key | Action |
132
146
  | :--- | :--- |
133
147
  | `Enter` | Copy the selected memory entry (`[id] (file): fact`) to the clipboard and close the popup |
134
- | `Up` / `Down` or `Ctrl+K` / `Ctrl+N` | Move selection up or down (`j`/`k` also work when the Results List pane is focused) |
135
- | `PageUp` / `PageDown` or `Ctrl+U` / `Ctrl+D` | Jump 6 items up/down (or scroll the right Preview pane by 8 lines when focused) |
148
+ | `Up` / `Down` or `Ctrl+K` / `Ctrl+J` | Move selection up or down (`j`/`k` also work when the Results List pane is focused) |
149
+ | `PageUp` / `PageDown` or `Ctrl+U` / `Ctrl+F` | Jump 6 items up/down (or scroll the right Preview pane by 8 lines when focused) |
136
150
  | `Tab` / `Shift+Tab` | Switch focus between Search Input, Results List, and Preview Pane |
137
151
  | `Ctrl+T` | Cycle entry type filter pill (`all` -> `topics` -> `sessions`) |
138
152
  | `Ctrl+G` | Cycle topic file filter pill (`all` -> `decisions` -> `preferences` -> `environment` -> ...) |
139
153
  | `Ctrl+R` | Cycle search mode pill (`hybrid` -> `keyword` -> `regex`) |
140
154
  | `Ctrl+B` | Import existing `AGENTS.md` / `CLAUDE.md` rules and compacted `opencode.db` sessions |
141
155
  | `Ctrl+L` | Force resync markdown files (`topics/*.md` + `sessions/*.md`) into `vectors.json` |
156
+ | `Ctrl+N` / `Ctrl+E` | Add a fact / edit the selected topic fact |
157
+ | `Ctrl+P` | Pin or unpin the selected topic fact as core |
158
+ | `Ctrl+D` | Request deletion; press again or press `Enter` to confirm |
159
+ | `Ctrl+S` / `Enter` *(in editor)* | Save the fact; `Tab` cycles fields and `Space` toggles the core field |
142
160
  | `Esc` | Close popup |
143
161
 
144
162
  ## How It Works (Architecture & Internals)
@@ -192,14 +210,14 @@ Checkpoint numbers (`-01`, `-02`, ...) auto-increment per `YYYY-MM-DD_<slug>` pr
192
210
  `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:
193
211
 
194
212
  ```js
195
- const mod = await import("@xenova/transformers");
196
- const embed = await mod.pipeline("feature-extraction", "Xenova/all-MiniLM-L6-v2");
213
+ const mod = await import("@huggingface/transformers");
214
+ const embed = await mod.pipeline("feature-extraction", "Xenova/all-MiniLM-L6-v2", { device: "cpu", dtype: "q8" });
197
215
  const out = await embed(text, { pooling: "mean", normalize: true });
198
216
  const vec = Array.from(out.data); // -> [0.021, -0.084, 0.112, ... 384 numbers]
199
217
  ```
200
218
 
201
219
  - **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.
202
- - **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.
220
+ - **Model installation and local cache**: `@huggingface/transformers` is a regular npm dependency in `package.json` that runs ONNX models on CPU without Python or an external inference server. The pipeline explicitly selects `device: "cpu"` and `dtype: "q8"`, retaining the same model and 384-dimensional vector format. On first use it downloads and caches the quantized model and tokenizer from Hugging Face. Later runs reuse the local cache. Upgrading from `@xenova/transformers` can require a new model download because the library cache location changes; existing `vectors.json` files are preserved.
203
221
  - **Incremental vector sync (`syncVectors`)**: Parses all `topics/*.md` blocks and `sessions/*.md` summaries (with per-file `mtimeMs` caching in `parsedFileCache`) and compares each entry's `id`, `fact`, `tags`, `project`, and `core` against `vectors.json`. Unchanged entries reuse their cached 384-dimensional vectors and serialized JSON lines; only new or modified entries run through the embedding pipeline.
204
222
  - **Scoring formula (`searchMemory` & `computeLexicalScore`)**:
205
223
  - `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.
@@ -224,6 +242,8 @@ const vec = Array.from(out.data); // -> [0.021, -0.084, 0.112, ... 384 numbers]
224
242
 
225
243
  ### 7. Agent Tools Registered by the Server Plugin
226
244
 
245
+ Desktop uses the separately exported `MemoryRpc` contract in `rpc.js` / `rpc.d.ts`. Server setup registers `query`, `store`, `remove`, `sync`, `importMemory`, and `getSessionMarkdown`; these are RPC methods, not additional LLM tools. `readSessionMarkdown()` restricts previews to paths beneath the memory root that start with `sessions/`. The GUI source (`gui.tsx`, `gui.css`) builds to `dist/gui-experimental.cjs` with `npm run build:gui`.
246
+
227
247
  | Tool Name | Required Inputs | Optional Inputs | Behavior |
228
248
  | :--- | :--- | :--- | :--- |
229
249
  | `memory_store` | `topic`, `tags`, `fact` | `id`, `supersedes`, `project` (default `global`), `core` (`boolean`) | Creates `topics/<topic>.md` if missing, registers it in `memory.md`, updates in place when `id` exists (or assigns the next `<prefix>-<nnn>` ID), prunes `supersedes` IDs, and updates `vectors.json`. |
@@ -242,7 +262,8 @@ Local embedding, TUI browsing, and direct `/memory-add`, `/memory-delete`, and `
242
262
  | History & rule import (`/memory-import`, `Ctrl+B`) | **0 tokens** | Parses `AGENTS.md` / `CLAUDE.md` rules and reads compacted `opencode.db` sessions directly via SQLite and local embeddings |
243
263
  | 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` |
244
264
  | Standalone CLI (`npx @nandoblanco/opencode-local-memory ...`) | **0 tokens** | Runs directly in Node.js outside the model turn |
245
- | Per-turn auto-recall (`context` hook) & agent tools | **~250-450 system/schema tokens** | Injects compact instructions plus pinned `core` memories and top matching facts (`score >= 0.38`, max `topK = 6`) into `event.system` and registers `memory_store`, `memory_delete`, `memory_search`, and `memory_checkpoint` |
265
+ | Desktop Manager and RPC operations | **0 tokens** | Queries and updates local memory through `MemoryRpc` without a model turn |
266
+ | Per-turn auto-recall (`context` hook) & agent tools | **Variable system/schema and recalled-content tokens** | Injects instructions, pinned `core` memories, and matching facts (`score >= 0.38`, max `topK = 6`); cost grows with their content and the selected model's tokenizer |
246
267
 
247
268
  ## Directory Structure
248
269
 
@@ -294,6 +315,9 @@ npx @nandoblanco/opencode-local-memory store decisions "arch, api" "Use REST end
294
315
 
295
316
  # Delete one or more entries by ID (or comma-separated IDs)
296
317
  npx @nandoblanco/opencode-local-memory delete dec-002
318
+
319
+ # Deduplicate topic facts, prune auto-compaction stub files, and resync vectors.json
320
+ npx @nandoblanco/opencode-local-memory maintain [--dir /path/to/memory] [--prune-imported]
297
321
  ```
298
322
 
299
323
  ## Configuration Options
@@ -0,0 +1 @@
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});let e=require("solid-js/web"),t=require("@opencode/plugin/gui"),n=require("solid-js");var r=`.olm-root{box-sizing:border-box;width:100%;color:var(--v2-text-text-base);font-family:var(--v2-font-family-sans,-apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif);flex-direction:column;display:flex}.olm-root--modal{height:min(66vh,520px);max-height:100%;overflow:hidden}.olm-root--panel{height:100%;min-height:420px}.olm-header{border-bottom:1px solid var(--v2-border-border-muted);flex-direction:column;flex-shrink:0;gap:8px;padding-bottom:12px;display:flex}.olm-root--panel .olm-header{padding:12px 12px 10px}.olm-toolbar{align-items:center;gap:8px;width:100%;display:flex}.olm-root--panel .olm-toolbar{flex-direction:column;align-items:stretch}.olm-search-field{flex:1;min-width:0;display:flex}.olm-search-field>[data-component=text-input-v2]{width:100%;max-width:none}.olm-toolbar-controls{flex-shrink:0;align-items:center;gap:6px;display:flex}.olm-root--panel .olm-toolbar-controls{flex-wrap:wrap;width:100%}.olm-segmented{background:var(--v2-background-bg-base);border:1px solid var(--v2-border-border-muted);border-radius:6px;align-items:center;padding:2px;display:inline-flex}.olm-segment{appearance:none;color:var(--v2-text-text-muted);cursor:pointer;white-space:nowrap;background:0 0;border:none;border-radius:4px;padding:3px 9px;font-family:inherit;font-size:12px;font-weight:500;line-height:16px;transition:background-color .12s,color .12s}.olm-segment:hover{color:var(--v2-text-text-base)}.olm-segment:focus-visible{box-shadow:0 0 0 2px var(--v2-border-border-focus);outline:none}.olm-segment--active{background:var(--v2-background-bg-layer-02);color:var(--v2-text-text-base);box-shadow:var(--v2-elevation-button-neutral,0 1px 2px #00000014)}.olm-active-filters{flex-wrap:wrap;justify-content:space-between;align-items:center;gap:8px;display:flex}.olm-chip-group{flex-wrap:wrap;align-items:center;gap:6px;display:flex}.olm-chip{appearance:none;border:1px solid var(--v2-border-border-muted);background:var(--v2-background-bg-layer-02);height:22px;color:var(--v2-text-text-base);cursor:pointer;border-radius:5px;align-items:center;gap:4px;padding:0 8px;font-family:inherit;font-size:11px;font-weight:500;display:inline-flex}.olm-chip:hover{background:var(--v2-overlay-simple-overlay-hover);border-color:var(--v2-border-border-strong)}.olm-chip:focus-visible{box-shadow:0 0 0 2px var(--v2-border-border-focus);outline:none}.olm-chip-key{color:var(--v2-text-text-muted)}.olm-meta-summary{color:var(--v2-text-text-muted);font-variant-numeric:tabular-nums;margin-left:auto;font-size:11px}.olm-split{flex:1;grid-template-columns:minmax(250px,42%) minmax(0,1fr);min-height:0;display:grid;overflow:hidden}.olm-root--panel .olm-split{grid-template-rows:minmax(170px,44%) minmax(0,1fr);grid-template-columns:1fr}.olm-column{flex-direction:column;min-height:0;display:flex;overflow:hidden}.olm-column--list{border-right:1px solid var(--v2-border-border-muted)}.olm-root--panel .olm-column--list{border-right:none;border-bottom:1px solid var(--v2-border-border-muted)}.olm-scroll{flex:1;min-height:0;overflow:hidden auto}.olm-list{flex-direction:column;gap:2px;padding:6px 8px 6px 0;display:flex}.olm-root--panel .olm-list{padding:6px 8px}.olm-row{appearance:none;text-align:left;cursor:pointer;width:100%;color:var(--v2-text-text-base);background:0 0;border:none;border-radius:6px;flex-direction:column;gap:4px;padding:8px 10px;transition:background-color .1s;display:flex}.olm-row:hover{background:var(--v2-overlay-simple-overlay-hover)}.olm-row:focus-visible{box-shadow:inset 0 0 0 2px var(--v2-border-border-focus);outline:none}.olm-row--selected,.olm-row--selected:hover{background:var(--v2-overlay-simple-overlay-pressed)}.olm-row-top{justify-content:space-between;align-items:center;gap:8px;min-width:0;display:flex}.olm-row-id-wrap{align-items:center;gap:6px;min-width:0;display:inline-flex}.olm-row-pin{color:var(--v2-state-fg-warning,#f59e0b);flex-shrink:0;font-size:12px;line-height:1}.olm-row-id{color:var(--v2-text-text-base);text-overflow:ellipsis;white-space:nowrap;font-size:12px;font-weight:600;line-height:16px;overflow:hidden}.olm-row-meta{flex-shrink:0;align-items:center;gap:6px;display:inline-flex}.olm-badge{background:var(--v2-background-bg-layer-02);border:1px solid var(--v2-border-border-muted);height:18px;color:var(--v2-text-text-muted);white-space:nowrap;border-radius:4px;align-items:center;padding:0 6px;font-size:10px;font-weight:500;display:inline-flex}.olm-badge--core{color:var(--v2-state-fg-warning,#f59e0b);border-color:var(--v2-border-border-strong)}.olm-row-score{color:var(--v2-text-text-faint);font-variant-numeric:tabular-nums;font-size:11px}.olm-row-fact{color:var(--v2-text-text-muted);-webkit-line-clamp:2;word-break:break-word;-webkit-box-orient:vertical;font-size:12px;line-height:16px;display:-webkit-box;overflow:hidden}.olm-detail-bar{border-bottom:1px solid var(--v2-border-border-muted);flex-shrink:0;justify-content:space-between;align-items:flex-start;gap:12px;padding:10px 0 10px 16px;display:flex}.olm-root--panel .olm-detail-bar{flex-wrap:wrap;padding:10px 12px}.olm-detail-heading{flex:1;min-width:0}.olm-detail-title{color:var(--v2-text-text-base);align-items:center;gap:6px;margin:0;font-size:13px;font-weight:600;line-height:18px;display:flex}.olm-detail-subtitle{color:var(--v2-text-text-muted);flex-wrap:wrap;align-items:center;gap:6px;margin-top:3px;font-size:11px;display:flex}.olm-detail-actions{flex-wrap:wrap;flex-shrink:0;align-items:center;gap:6px;display:flex}.olm-detail-body{flex-direction:column;gap:12px;padding:12px 0 12px 16px;display:flex}.olm-root--panel .olm-detail-body{padding:10px 12px}.olm-field-grid{grid-template-columns:repeat(auto-fit,minmax(120px,1fr));gap:8px;display:grid}.olm-field-card{background:var(--v2-background-bg-base);border:1px solid var(--v2-border-border-muted);border-radius:6px;flex-direction:column;gap:2px;padding:8px 10px;display:flex}.olm-field-label{text-transform:uppercase;letter-spacing:.04em;color:var(--v2-text-text-faint);font-size:10px;font-weight:600}.olm-field-value{color:var(--v2-text-text-base);word-break:break-word;font-size:12px}.olm-fact-box{background:var(--v2-background-bg-base);border:1px solid var(--v2-border-border-muted);color:var(--v2-text-text-base);white-space:pre-wrap;word-break:break-word;border-radius:8px;padding:12px 14px;font-size:13px;line-height:20px}.olm-tags-list{flex-wrap:wrap;align-items:center;gap:6px;display:flex}.olm-tag{background:var(--v2-background-bg-layer-02);border:1px solid var(--v2-border-border-muted);height:20px;color:var(--v2-text-text-muted);border-radius:4px;align-items:center;padding:0 7px;font-size:11px;display:inline-flex}.olm-form{flex-direction:column;gap:12px;padding:12px 0 12px 16px;display:flex}.olm-root--panel .olm-form{padding:10px 12px}.olm-form-row{grid-template-columns:1fr 1fr;gap:10px;display:grid}.olm-form-group{flex-direction:column;gap:4px;display:flex}.olm-form-label{color:var(--v2-text-text-muted);font-size:11px;font-weight:600}.olm-input,.olm-textarea{box-sizing:border-box;border:1px solid var(--v2-border-border-muted);background:var(--v2-background-bg-base);width:100%;color:var(--v2-text-text-base);border-radius:6px;padding:7px 10px;font-family:inherit;font-size:12px;transition:border-color .12s,box-shadow .12s}.olm-input:focus-visible,.olm-textarea:focus-visible{border-color:var(--v2-border-border-focus);box-shadow:0 0 0 2px var(--v2-border-border-focus);outline:none}.olm-textarea{resize:vertical;min-height:110px;line-height:18px}.olm-topic-suggestions{flex-wrap:wrap;align-items:center;gap:5px;margin-top:2px;display:flex}.olm-topic-pill{appearance:none;border:1px solid var(--v2-border-border-muted);background:var(--v2-background-bg-layer-02);color:var(--v2-text-text-muted);cursor:pointer;border-radius:4px;padding:2px 7px;font-family:inherit;font-size:11px}.olm-topic-pill:hover{color:var(--v2-text-text-base);border-color:var(--v2-border-border-strong)}.olm-topic-pill--active{background:var(--v2-overlay-simple-overlay-pressed);color:var(--v2-text-text-base);border-color:var(--v2-border-border-strong)}.olm-empty{text-align:center;color:var(--v2-text-text-muted);box-sizing:border-box;flex-direction:column;justify-content:center;align-items:center;gap:8px;height:100%;padding:32px 20px;display:flex}.olm-empty-title{color:var(--v2-text-text-base);font-size:13px;font-weight:500}.olm-empty-desc{color:var(--v2-text-text-muted);max-width:280px;font-size:12px}.olm-mark{color:inherit;background:#f59e0b38;border-radius:3px;padding:0 2px;font-weight:600}.olm-dialog-footer{justify-content:space-between;align-items:center;gap:12px;width:100%;display:flex}.olm-shortcuts{flex-wrap:wrap;align-items:center;gap:14px;display:flex}.olm-shortcut-item{color:var(--v2-text-text-muted);align-items:center;gap:5px;font-size:11px;display:inline-flex}[data-slot=titlebar-update]:has(button[aria-label*=Memory\\ Manager]){width:fit-content}[data-slot=titlebar-update]:has(button[aria-label*=Memory\\ Manager]) button{gap:4px;padding-inline:8px 6px}[data-slot=titlebar-update]:has(button[aria-label*=Memory\\ Manager]) [data-slot=titlebar-update-label]{opacity:1;margin-inline:0;transform:translate(0)}.olm-titlebar-quick-btn{appearance:none;color:var(--v2-icon-icon-muted,var(--v2-text-text-muted));cursor:pointer;-webkit-app-region:no-drag;background:0 0;border:none;border-radius:6px;flex-shrink:0;justify-content:center;align-items:center;width:36px;height:28px;transition:background-color .12s,color .12s;display:inline-flex}.olm-titlebar-quick-btn:hover{background:var(--v2-overlay-simple-overlay-hover);color:var(--v2-icon-icon-base,var(--v2-text-text-base))}.olm-titlebar-quick-btn:focus-visible{outline:2px solid var(--v2-border-border-focus);outline-offset:-2px}@media (width<=720px){.olm-split{grid-template-rows:minmax(170px,44%) minmax(0,1fr);grid-template-columns:1fr}.olm-column--list{border-right:none;border-bottom:1px solid var(--v2-border-border-muted)}.olm-form-row{grid-template-columns:1fr}}`,i=`https://json-schema.org/draft/2020-12/schema`,a={id:`opencode-local-memory`,methods:{query:{input:{$schema:i,type:`object`,properties:{query:{type:`string`},typeFilter:{type:`string`,enum:[`all`,`core`,`topics`,`sessions`]},topicFilter:{type:`string`},mode:{type:`string`,enum:[`hybrid`,`keyword`,`regex`]},projectFilter:{type:`string`},coreOnly:{type:`boolean`},limit:{type:`number`}},additionalProperties:!1},output:{$schema:i,type:`object`,properties:{rootDir:{type:`string`},totalEntries:{type:`number`},coreCount:{type:`number`},topicsCount:{type:`number`},sessionsCount:{type:`number`},topics:{type:`array`,items:{type:`string`}},projects:{type:`array`,items:{type:`string`}},hits:{type:`array`,items:{type:`object`,properties:{score:{type:`number`},semanticScore:{type:`number`},entry:{type:`object`,properties:{id:{type:`string`},date:{type:`string`},file:{type:`string`},tags:{type:`string`},fact:{type:`string`},project:{type:`string`},core:{type:`boolean`}},required:[`id`,`date`,`file`,`tags`,`fact`],additionalProperties:!1}},required:[`score`,`semanticScore`,`entry`],additionalProperties:!1}}},required:[`rootDir`,`totalEntries`,`coreCount`,`topicsCount`,`sessionsCount`,`topics`,`projects`,`hits`],additionalProperties:!1}},store:{input:{$schema:i,type:`object`,properties:{id:{type:`string`},topic:{type:`string`},tags:{type:`string`},fact:{type:`string`},project:{type:`string`},core:{type:`boolean`},supersedes:{type:`string`}},required:[`topic`,`tags`,`fact`],additionalProperties:!1},output:{$schema:i,type:`object`,properties:{entry:{type:`object`,properties:{id:{type:`string`},date:{type:`string`},file:{type:`string`},tags:{type:`string`},fact:{type:`string`},project:{type:`string`},core:{type:`boolean`},updated:{type:`boolean`},superseded:{type:`array`,items:{type:`string`}}},required:[`id`,`date`,`file`,`tags`,`fact`,`project`,`core`,`updated`,`superseded`],additionalProperties:!1}},required:[`entry`],additionalProperties:!1}},remove:{input:{$schema:i,type:`object`,properties:{id:{type:`string`}},required:[`id`],additionalProperties:!1},output:{$schema:i,type:`object`,properties:{deleted:{type:`array`,items:{type:`object`,properties:{id:{type:`string`},file:{type:`string`}},required:[`id`,`file`],additionalProperties:!1}},notFound:{type:`array`,items:{type:`string`}},total:{type:`number`}},required:[`deleted`,`notFound`,`total`],additionalProperties:!1}},sync:{input:{$schema:i,type:`object`,properties:{},additionalProperties:!1},output:{$schema:i,type:`object`,properties:{total:{type:`number`},embedded:{type:`number`},reused:{type:`number`},vecFile:{type:`string`}},required:[`total`,`embedded`,`reused`,`vecFile`],additionalProperties:!1}},importMemory:{input:{$schema:i,type:`object`,properties:{limit:{type:`number`}},additionalProperties:!1},output:{$schema:i,type:`object`,properties:{importedFactsCount:{type:`number`},skippedFacts:{type:`number`},importedSessionsCount:{type:`number`},skippedSessions:{type:`number`},total:{type:`number`}},required:[`importedFactsCount`,`skippedFacts`,`importedSessionsCount`,`skippedSessions`,`total`],additionalProperties:!1}},getSessionMarkdown:{input:{$schema:i,type:`object`,properties:{file:{type:`string`}},required:[`file`],additionalProperties:!1},output:{$schema:i,type:`object`,properties:{file:{type:`string`},markdown:{type:`string`}},required:[`file`,`markdown`],additionalProperties:!1}}},events:{}},o=(0,e.template)(`<button type=button class=olm-chip title="Reset search mode to Hybrid"><span class=olm-chip-key>Mode:</span><span>`),s=(0,e.template)(`<button type=button class=olm-chip title="Clear topic filter"><span class=olm-chip-key>Topic:</span><span>`),c=(0,e.template)(`<div class=olm-active-filters><div class=olm-chip-group></div><span class=olm-meta-summary> of <!> memories (<!> core)`),l=(0,e.template)(`<div class=olm-list role=listbox aria-label="Memory entries">`),u=(0,e.template)(`<div><div class=olm-header><div class=olm-toolbar><div class=olm-search-field></div><div class=olm-toolbar-controls><div class=olm-segmented role=group aria-label="Memory type filter"></div></div></div></div><div class=olm-split><div class="olm-column olm-column--list"><div class=olm-scroll></div></div><div class="olm-column olm-column--detail">`),d=(0,e.template)(`<button type=button>`),f=(0,e.template)(`<span style=font-size:11px;color:var(--v2-state-fg-danger)>`),ee=(0,e.template)(`<div class=olm-empty><div class=olm-empty-title></div><div class=olm-empty-desc>Try switching to All types, clearing topic filters, or click Add Memory to store a new fact.`),te=(0,e.template)(`<span class=olm-row-pin title="Pinned Core Memory">★`),ne=(0,e.template)(`<span class="olm-badge olm-badge--core">core`),re=(0,e.template)(`<span class=olm-row-score>`),ie=(0,e.template)(`<button type=button role=option><div class=olm-row-top><span class=olm-row-id-wrap><span class=olm-row-id></span></span><span class=olm-row-meta><span class=olm-badge></span></span></div><div class=olm-row-fact>`),p=(0,e.template)(`<mark class=olm-mark>`),m=(0,e.template)(`<span>`),ae=(0,e.template)(`<div class=olm-detail-bar><div class=olm-detail-heading><h3 class=olm-detail-title></h3><div class=olm-detail-subtitle><span>Saves to topics/<!>.md and updates semantic vectors immediately</span></div></div><div class=olm-detail-actions>`),oe=(0,e.template)(`<div class=olm-topic-suggestions>`),se=(0,e.template)(`<div class=olm-scroll><div class=olm-form><div class=olm-form-row><div class=olm-form-group><label class=olm-form-label>Topic Slug</label><input type=text class=olm-input placeholder="e.g. preferences, decisions, environment"></div><div class=olm-form-group><label class=olm-form-label>Project Scope</label><input type=text class=olm-input placeholder="global or project slug (e.g. git/opencode-plugins)"></div></div><div class=olm-form-group><label class=olm-form-label>Tags (comma-separated keywords)</label><input type=text class=olm-input placeholder="e.g. opencode, desktop, gui, preferences"></div><div class=olm-form-group></div><div class=olm-form-group><label class=olm-form-label>Memory Fact</label><textarea class=olm-textarea placeholder="Write a concise, authoritative statement of the rule, decision, preference, or environment fact..."autofocus>`),ce=(0,e.template)(`<div class=olm-empty><div class=olm-empty-title>Select a memory to inspect or manage</div><div class=olm-empty-desc>View full details, pin/unpin core memories, edit topic facts in-place, or delete outdated entries.`),le=(0,e.template)(`<span>·`),ue=(0,e.template)(`<span>Updated `),de=(0,e.template)(`<div class=olm-detail-bar><div class=olm-detail-heading><h3 class=olm-detail-title><span></span></h3><div class=olm-detail-subtitle><span></span></div></div><div class=olm-detail-actions>`),fe=(0,e.template)(`<div class=olm-tags-list>`),pe=(0,e.template)(`<div class=olm-fact-box>`),me=(0,e.template)(`<div class=olm-scroll><div class=olm-detail-body><div class=olm-field-grid><div class=olm-field-card><span class=olm-field-label>Type</span><span class=olm-field-value></span></div><div class=olm-field-card><span class=olm-field-label>Topic</span><span class=olm-field-value></span></div><div class=olm-field-card><span class=olm-field-label>Project Scope</span><span class=olm-field-value></span></div><div class=olm-field-card><span class=olm-field-label>Core Status</span><span class=olm-field-value>`),he=(0,e.template)(`<span class=olm-tag>#`),ge={all:`All`,core:`Core`,topics:`Topics`,sessions:`Sessions`},_e={hybrid:`Hybrid (Semantic + BM25)`,keyword:`Keyword`,regex:`Regex`},ve=[`all`,`core`,`topics`,`sessions`],h=[`hybrid`,`keyword`,`regex`];function g(e,t){return e[(e.indexOf(t)+1)%e.length]??e[0]}function _(e){return String(e.file||``).startsWith(`sessions/`)||String(e.id||``).startsWith(`session:`)}function v(e){let t=String(e.file||``);return t.startsWith(`topics/`)&&t.endsWith(`.md`)?t.slice(7,-3):_(e)?`session`:`general`}function ye(e){return String(e.tags||``).split(`,`).map(e=>e.trim()).filter(Boolean)}function be(e,t){let n=String(t||``).replace(/\b(?:type|topic|mode|project|in|core|is|re):[^\s]+/gi,` `).trim().split(/\s+/).filter(e=>e.length>=2);if(!e||n.length===0)return[{text:e,match:!1}];let r=n.map(e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)),i;try{i=RegExp(`(${r.join(`|`)})`,`gi`)}catch{return[{text:e,match:!1}]}let a=[],o=0;for(let t of e.matchAll(i)){let n=t.index??0,r=t[0]??``;r&&(n>o&&a.push({text:e.slice(o,n),match:!1}),a.push({text:r,match:!0}),o=n+r.length)}return o<e.length&&a.push({text:e.slice(o),match:!1}),a.length>0?a:[{text:e,match:!1}]}function y(e){let t=e.sessions.current();if(t?.server?.client)return t.server.client.rpc(a);let n=e.servers?.list?.()??[];return((n.map(t=>e.servers.get(t)).find(e=>e?.builtin)??n.map(t=>e.servers.get(t)).find(e=>e?.local)??n.map(t=>e.servers.get(t)).find(e=>e!==void 0))?.client??e.client).rpc(a)}function b(t){let r=t.ctx.ui,[i,a]=(0,n.createSignal)(t.initialQuery??``),[b,S]=(0,n.createSignal)(`all`),[C,w]=(0,n.createSignal)(`all`),[T,E]=(0,n.createSignal)(`hybrid`),[Se,D]=(0,n.createSignal)(0),[O,k]=(0,n.createSignal)(!0),[A,j]=(0,n.createSignal)(!1),[M,N]=(0,n.createSignal)(void 0),[P,Ce]=(0,n.createSignal)(void 0),[F,I]=(0,n.createSignal)(``),[we,L]=(0,n.createSignal)(``),[R,z]=(0,n.createSignal)(t.initialEditorMode??`none`),[B,Te]=(0,n.createSignal)(``),[V,H]=(0,n.createSignal)(`preferences`),[Ee,U]=(0,n.createSignal)(``),[De,W]=(0,n.createSignal)(`global`),[Oe,G]=(0,n.createSignal)(!1),[ke,K]=(0,n.createSignal)(t.initialDraftFact??``);(0,n.createEffect)(()=>{let e=x();e&&a(e)}),(0,n.createEffect)(()=>{let e=xe();e&&(z(e.mode),K(e.draftFact))});let q=0,J,Y=(0,n.createMemo)(()=>P()?.hits??[]),X=(0,n.createMemo)(()=>P()?.topics??[]),Z=(0,n.createMemo)(()=>{let e=Y();return e[Math.max(0,Math.min(Se(),Math.max(0,e.length-1)))]});async function Q(e){let n=++q;k(!0),N(void 0);try{let r=await y(t.ctx).query({query:i(),typeFilter:b(),topicFilter:C(),mode:T(),limit:80});if(n!==q)return;if(Ce(r),e){let t=r.hits.findIndex(t=>t.entry.id===e);D(t>=0?t:0)}else D(e=>Math.max(0,Math.min(e,Math.max(0,r.hits.length-1))))}catch(e){if(n!==q)return;N(e instanceof Error?e.message:String(e))}finally{n===q&&k(!1)}}function Ae(){J&&clearTimeout(J),J=setTimeout(()=>{Q()},65)}(0,n.createEffect)(()=>{i(),b(),C(),T(),Ae()}),(0,n.createEffect)(()=>{let e=Z();if(L(``),!e||!_(e.entry)){I(``);return}let r=!1;(async()=>{try{let n=await y(t.ctx).getSessionMarkdown({file:e.entry.file});r||I(n.markdown||e.entry.fact)}catch{r||I(e.entry.fact)}})(),(0,n.onCleanup)(()=>{r=!0})}),(0,n.onCleanup)(()=>{J&&clearTimeout(J)});function je(){let e=C()===`all`?X()[0]||`preferences`:C();z(`add`),Te(``),H(e),U(``),W(`global`),G(b()===`core`),K(``),L(``)}function Me(e){let n=e??Z();!n||_(n.entry)?t.ctx.toast.show({title:`Only topic facts can be edited in-place`,variant:`error`}):(Te(n.entry.id),H(v(n.entry)),U(n.entry.tags||``),W(n.entry.project||`global`),G(!!n.entry.core),K(n.entry.fact||``),L(``),z(`edit`))}async function $(){let e=V().trim(),n=ke().trim();if(!e)t.ctx.toast.show({title:`Topic slug is required`,variant:`error`});else if(!n)t.ctx.toast.show({title:`Memory fact cannot be empty`,variant:`error`});else{j(!0);try{let r=await y(t.ctx).store({id:R()===`edit`&&B()?B():void 0,topic:e,tags:Ee().trim()||e,fact:n,project:De().trim()||`global`,core:Oe()});z(`none`),t.ctx.toast.show({title:`${r.entry.updated?`Updated`:`Stored`} [${r.entry.id}] (${r.entry.file})`,variant:`success`}),await Q(r.entry.id)}catch(e){t.ctx.toast.show({title:e instanceof Error?e.message:`Failed to save memory`,variant:`error`})}finally{j(!1)}}}async function Ne(e){let n=e??Z();if(!n||_(n.entry))return;let r=!n.entry.core;j(!0);try{let e=await y(t.ctx).store({id:n.entry.id,topic:v(n.entry),tags:n.entry.tags||v(n.entry),fact:n.entry.fact,project:n.entry.project||`global`,core:r});t.ctx.toast.show({title:`${r?`Pinned`:`Unpinned`} [${e.entry.id}]`,variant:`success`}),await Q(e.entry.id)}catch(e){t.ctx.toast.show({title:e instanceof Error?e.message:`Failed to update core pin`,variant:`error`})}finally{j(!1)}}async function Pe(e){let n=e??Z();if(n){if(we()!==n.entry.id)L(n.entry.id);else{j(!0);try{let e=await y(t.ctx).remove({id:n.entry.id});L(``),e.deleted.length>0?(t.ctx.toast.show({title:`Deleted ${e.deleted.map(e=>e.id).join(`, `)}`,variant:`success`}),await Q()):t.ctx.toast.show({title:`Not found: ${n.entry.id}`,variant:`error`})}catch(e){t.ctx.toast.show({title:e instanceof Error?e.message:`Delete failed`,variant:`error`})}finally{j(!1)}}}}async function Fe(){j(!0);try{let e=await y(t.ctx).sync({});t.ctx.toast.show({title:`Synced ${e.total} memories (${e.embedded} newly embedded)`,variant:`success`}),await Q(Z()?.entry.id)}catch(e){t.ctx.toast.show({title:e instanceof Error?e.message:`Sync failed`,variant:`error`})}finally{j(!1)}}async function Ie(){j(!0);try{let e=await y(t.ctx).importMemory({limit:30});t.ctx.toast.show({title:`Imported ${e.importedFactsCount} rules, ${e.importedSessionsCount} sessions (${e.total} total)`,variant:`success`}),await Q(Z()?.entry.id)}catch(e){t.ctx.toast.show({title:e instanceof Error?e.message:`Import failed`,variant:`error`})}finally{j(!1)}}async function Le(e){let n=e??Z();if(!n)return;let r=`[${n.entry.id}] (${n.entry.file}): ${n.entry.fact}`;try{await t.ctx.system.copy(r),t.ctx.toast.show({title:`Copied [${n.entry.id}]`,variant:`success`})}catch{}}function Re(e){if(R()!==`none`){if(e.key===`Escape`){e.preventDefault(),z(`none`);return}if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`s`){e.preventDefault(),$();return}}else{if(e.ctrlKey||e.metaKey){let t=e.key.toLowerCase();if(t===`t`){e.preventDefault(),S(e=>g(ve,e)),D(0);return}if(t===`g`){e.preventDefault();let t=[`all`,...X()];w(e=>g(t,e)),D(0);return}if(t===`r`){e.preventDefault(),E(e=>g(h,e)),D(0);return}if(t===`n`){e.preventDefault(),je();return}if(t===`e`){e.preventDefault(),Me();return}if(t===`p`){e.preventDefault(),Ne();return}if(t===`d`){e.preventDefault(),Pe();return}if(t===`l`){e.preventDefault(),Fe();return}}if(e.key===`ArrowDown`){e.preventDefault();let t=Math.max(0,Y().length-1);D(e=>Math.min(t,e+1))}else e.key===`ArrowUp`&&(e.preventDefault(),D(e=>Math.max(0,e-1)))}}let ze=(0,n.createMemo)(()=>{let e=[{label:`All topics`,icon:C()===`all`?`check-small`:void 0,onSelect:()=>{w(`all`),D(0)}},...X().map(e=>({label:e,icon:C()===e?`check-small`:void 0,onSelect:()=>{w(e),D(0)}}))];return[{type:`group`,label:`Search Mode`,items:[`hybrid`,`keyword`,`regex`].map(e=>({label:_e[e],icon:T()===e?`check-small`:void 0,onSelect:()=>{E(e),D(0)}}))},{type:`separator`},{type:`group`,label:`Topic Filter`,items:e},{type:`separator`},{label:`Import rules & sessions`,icon:`download`,onSelect:()=>{Ie()}},{label:`Reset filters`,icon:`refresh`,disabled:b()===`all`&&C()===`all`&&T()===`hybrid`,onSelect:()=>{S(`all`),w(`all`),E(`hybrid`),D(0)}}]}),Be=(0,n.createMemo)(()=>C()!==`all`||T()!==`hybrid`||!!M());return(()=>{var h=u(),g=h.firstChild,y=g.firstChild.firstChild,x=y.nextSibling,xe=x.firstChild,k=g.nextSibling.firstChild,j=k.firstChild,N=k.nextSibling;return h.$$keydown=Re,(0,e.insert)(y,(0,e.createComponent)(r.TextInput,{get value(){return i()},onInput:e=>{a(e),D(0)},label:`Search memories`,placeholder:`Search facts & session checkpoints, or filter with topic:preferences type:core...`,type:`search`,size:`large`,get invalid(){return!!M()},get autofocus(){return R()===`none`}})),(0,e.insert)(xe,(0,e.createComponent)(n.For,{each:ve,children:t=>(()=>{var n=d();return n.$$click=()=>{S(t),D(0)},(0,e.insert)(n,()=>ge[t]),(0,e.effect)(()=>(0,e.className)(n,`olm-segment ${b()===t?`olm-segment--active`:``}`)),n})()})),(0,e.insert)(x,(0,e.createComponent)(r.Menu,{label:`Filters`,icon:`sliders`,trigger:`button`,placement:`bottom-end`,get items(){return ze()}}),null),(0,e.insert)(x,(0,e.createComponent)(n.Show,{get when(){return O()||A()},get children(){return(0,e.createComponent)(r.Loader,{size:`small`})}}),null),(0,e.insert)(x,(0,e.createComponent)(r.Tooltip,{value:`Resync vector index`,keys:[`Ctrl`,`L`],get children(){return(0,e.createComponent)(r.IconButton,{icon:`refresh`,label:`Resync vector index`,variant:`ghost`,size:`normal`,get busy(){return A()},onClick:()=>void Fe()})}}),null),(0,e.insert)(x,(0,e.createComponent)(r.Button,{variant:`contrast`,size:`small`,icon:`plus-small`,onClick:()=>je(),children:`Add Memory`}),null),(0,e.insert)(g,(0,e.createComponent)(n.Show,{get when(){return Be()||P()},get children(){var t=c(),i=t.firstChild,a=i.nextSibling,l=a.firstChild,u=l.nextSibling,d=u.nextSibling.nextSibling;return d.nextSibling,(0,e.insert)(i,(0,e.createComponent)(n.Show,{get when(){return T()!==`hybrid`},get children(){var t=o(),n=t.firstChild.nextSibling;return t.$$click=()=>E(`hybrid`),(0,e.insert)(n,()=>_e[T()]),(0,e.insert)(t,(0,e.createComponent)(r.Icon,{name:`close-small`,size:`small`}),null),t}}),null),(0,e.insert)(i,(0,e.createComponent)(n.Show,{get when(){return C()!==`all`},get children(){var t=s(),n=t.firstChild.nextSibling;return t.$$click=()=>w(`all`),(0,e.insert)(n,C),(0,e.insert)(t,(0,e.createComponent)(r.Icon,{name:`close-small`,size:`small`}),null),t}}),null),(0,e.insert)(i,(0,e.createComponent)(n.Show,{get when(){return M()},children:t=>(()=>{var n=f();return(0,e.insert)(n,t),n})()}),null),(0,e.insert)(a,()=>Y().length,l),(0,e.insert)(a,()=>P()?.totalEntries??0,u),(0,e.insert)(a,()=>P()?.coreCount??0,d),t}}),null),(0,e.insert)(j,(0,e.createComponent)(n.Show,{get when(){return Y().length>0},get fallback(){return(()=>{var t=ee(),n=t.firstChild;return(0,e.insert)(t,(0,e.createComponent)(r.Icon,{name:`magnifying-glass`,size:`large`}),n),(0,e.insert)(n,()=>O()?`Loading persistent memories...`:`No matching memories`),t})()},get children(){var t=l();return(0,e.insert)(t,(0,e.createComponent)(n.For,{get each(){return Y()},children:(t,r)=>{let a=()=>r()===Se()&&R()===`none`;return(()=>{var o=ie(),s=o.firstChild,c=s.firstChild,l=c.firstChild,u=c.nextSibling,d=u.firstChild,f=s.nextSibling;return o.$$click=()=>{z(`none`),D(r())},(0,e.insert)(c,(0,e.createComponent)(n.Show,{get when(){return t.entry.core},get children(){return te()}}),l),(0,e.insert)(l,()=>t.entry.id),(0,e.insert)(u,(0,e.createComponent)(n.Show,{get when(){return t.entry.core},get children(){return ne()}}),d),(0,e.insert)(d,()=>v(t.entry)),(0,e.insert)(u,(0,e.createComponent)(n.Show,{get when(){return(0,e.memo)(()=>i().trim().length>0)()&&t.score>0},get children(){var n=re();return(0,e.insert)(n,()=>t.score.toFixed(2)),n}}),null),(0,e.insert)(f,(0,e.createComponent)(n.For,{get each(){return be(t.entry.fact,i())},children:t=>(0,e.createComponent)(n.Show,{get when(){return t.match},get fallback(){return(()=>{var n=m();return(0,e.insert)(n,()=>t.text),n})()},get children(){var n=p();return(0,e.insert)(n,()=>t.text),n}})})),(0,e.effect)(t=>{var n=a(),r=`olm-row ${a()?`olm-row--selected`:``}`;return n!==t.e&&(0,e.setAttribute)(o,`aria-selected`,t.e=n),r!==t.t&&(0,e.className)(o,t.t=r),t},{e:void 0,t:void 0}),o})()}})),t}})),(0,e.insert)(N,(0,e.createComponent)(n.Show,{get when(){return R()===`none`},get fallback(){return[(()=>{var t=ae(),n=t.firstChild,i=n.firstChild,a=i.nextSibling.firstChild,o=a.firstChild.nextSibling;o.nextSibling;var s=n.nextSibling;return(0,e.insert)(i,(()=>{var t=(0,e.memo)(()=>R()===`add`);return()=>t()?`Add New Memory Fact`:`Edit Memory [${B()}]`})()),(0,e.insert)(a,()=>V()||`preferences`,o),(0,e.insert)(s,(0,e.createComponent)(r.Button,{variant:`ghost`,size:`small`,onClick:()=>z(`none`),children:`Cancel`}),null),(0,e.insert)(s,(0,e.createComponent)(r.Button,{variant:`contrast`,size:`small`,icon:`check-small`,get busy(){return A()},onClick:()=>void $(),get children(){return R()===`add`?`Save Memory`:`Save Changes`}}),null),t})(),(()=>{var t=se(),i=t.firstChild.firstChild,a=i.firstChild,o=a.firstChild.nextSibling,s=a.nextSibling.firstChild.nextSibling,c=i.nextSibling,l=c.firstChild.nextSibling,u=c.nextSibling,f=u.nextSibling.firstChild.nextSibling;return o.$$input=e=>H(e.currentTarget.value),(0,e.insert)(a,(0,e.createComponent)(n.Show,{get when(){return X().length>0},get children(){var t=oe();return(0,e.insert)(t,(0,e.createComponent)(n.For,{get each(){return X().slice(0,8)},children:t=>(()=>{var n=d();return n.$$click=()=>H(t),(0,e.insert)(n,t),(0,e.effect)(()=>(0,e.className)(n,`olm-topic-pill ${V()===t?`olm-topic-pill--active`:``}`)),n})()})),t}}),null),s.$$input=e=>W(e.currentTarget.value),l.$$input=e=>U(e.currentTarget.value),(0,e.insert)(u,(0,e.createComponent)(r.Switch,{get checked(){return Oe()},onChange:e=>G(e),label:`Pin as Core Memory`,description:`Core memories are always injected on every turn regardless of prompt query.`})),f.$$input=e=>K(e.currentTarget.value),(0,e.effect)(()=>o.value=V()),(0,e.effect)(()=>s.value=De()),(0,e.effect)(()=>l.value=Ee()),(0,e.effect)(()=>f.value=ke()),t})()]},get children(){return(0,e.createComponent)(n.Show,{get when(){return Z()},get fallback(){return(()=>{var t=ce(),n=t.firstChild;return(0,e.insert)(t,(0,e.createComponent)(r.Icon,{name:`bubble-5`,size:`large`}),n),t})()},children:t=>[(()=>{var i=de(),a=i.firstChild,o=a.firstChild,s=o.firstChild,c=o.nextSibling,l=c.firstChild,u=a.nextSibling;return(0,e.insert)(o,(0,e.createComponent)(n.Show,{get when(){return t().entry.core},get children(){return te()}}),s),(0,e.insert)(s,()=>t().entry.id),(0,e.insert)(l,()=>t().entry.file),(0,e.insert)(c,(0,e.createComponent)(n.Show,{get when(){return t().entry.date},get children(){return[le(),(()=>{var n=ue();return n.firstChild,(0,e.insert)(n,()=>t().entry.date,null),n})()]}}),null),(0,e.insert)(u,(0,e.createComponent)(n.Show,{get when(){return!_(t().entry)},get children(){return[(0,e.createComponent)(r.Button,{variant:`neutral`,size:`small`,get busy(){return A()},onClick:()=>void Ne(t()),get children(){return t().entry.core?`Unpin Core`:`Pin Core`}}),(0,e.createComponent)(r.Button,{variant:`neutral`,size:`small`,icon:`edit`,onClick:()=>Me(t()),children:`Edit`})]}}),null),(0,e.insert)(u,(0,e.createComponent)(r.Tooltip,{value:`Copy memory entry`,get children(){return(0,e.createComponent)(r.IconButton,{icon:`copy`,label:`Copy memory entry`,variant:`ghost`,size:`small`,onClick:()=>void Le(t())})}}),null),(0,e.insert)(u,(0,e.createComponent)(r.Button,{variant:`danger`,size:`small`,icon:`trash`,get busy(){return A()},onClick:()=>void Pe(t()),get children(){return we()===t().entry.id?`Confirm Delete`:`Delete`}}),null),i})(),(()=>{var a=me(),o=a.firstChild,s=o.firstChild.firstChild,c=s.firstChild.nextSibling,l=s.nextSibling,u=l.firstChild.nextSibling,d=l.nextSibling,f=d.firstChild.nextSibling,ee=d.nextSibling.firstChild.nextSibling;return(0,e.insert)(c,()=>_(t().entry)?`Session Checkpoint`:`Topic Fact`),(0,e.insert)(u,()=>v(t().entry)),(0,e.insert)(f,()=>t().entry.project||`global`),(0,e.insert)(ee,()=>t().entry.core?`★ Pinned (Always recalled)`:`Contextual recall`),(0,e.insert)(o,(0,e.createComponent)(n.Show,{get when(){return ye(t().entry).length>0},get children(){var r=fe();return(0,e.insert)(r,(0,e.createComponent)(n.For,{get each(){return ye(t().entry)},children:t=>(()=>{var n=he();return n.firstChild,(0,e.insert)(n,t,null),n})()})),r}}),null),(0,e.insert)(o,(0,e.createComponent)(n.Show,{get when(){return(0,e.memo)(()=>!!_(t().entry))()&&F()},get fallback(){return(()=>{var r=pe();return(0,e.insert)(r,(0,e.createComponent)(n.For,{get each(){return be(t().entry.fact,i())},children:t=>(0,e.createComponent)(n.Show,{get when(){return t.match},get fallback(){return(()=>{var n=m();return(0,e.insert)(n,()=>t.text),n})()},get children(){var n=p();return(0,e.insert)(n,()=>t.text),n}})})),r})()},get children(){var t=pe();return(0,e.insert)(t,(0,e.createComponent)(r.Markdown,{get text(){return F()}})),t}}),null),a})()]})}})),(0,e.effect)(()=>(0,e.className)(h,`olm-root olm-root--${t.variant}`)),h})()}var[x,S]=(0,n.createSignal)(``),[xe,C]=(0,n.createSignal)(null),w;function T(t,r=``,i=`none`,a=``){r&&S(r),(i!==`none`||a)&&C({mode:i,draftFact:a});let o=t.sessions.current();if(o){w?.close();try{t.layout.open(`${t.id}:memory`,o)}catch{}}else{if(w)return;let o=t.ui;w=t.dialogs.open(s=>((0,n.onCleanup)(()=>{w=void 0}),(0,e.createComponent)(o.Dialog,{title:`Memory Manager`,size:`x-large`,get children(){return(0,e.createComponent)(b,{ctx:t,variant:`modal`,initialQuery:r,initialEditorMode:i,initialDraftFact:a,get onClose(){return s.close}})}})))}}var E=t.Plugin.define({i18n:{en:{"memory.command.title":`Memory Manager...`,"memory.command.description":`Search, add, edit, pin, and delete persistent local memories`,"memory.panel":`Memory`,"memory.panel.toggle":`Toggle Memory Panel`}},setup(i){i.add(t.Style,r),i.add(t.Command,()=>({id:`memory`,title:i.t(`memory.command.title`),description:i.t(`memory.command.description`),keywords:`memory facts recall core topics sessions vectors embeddings`,group:`Session`,section:`session`,bind:`mod+shift+m`,slash:{name:`memory`,arguments:!0},featured:!0,run(e){T(i,e??``)}})),i.add(t.Command,()=>({id:`memory-add`,title:`Add Memory Fact...`,description:`Add a new persistent memory fact (<topic> | <tags> | <fact> or interactive form)`,keywords:`memory store add fact rule preference`,group:`Session`,section:`session`,slash:{name:`memory-add`,arguments:!0},run(e){let t=(e??``).trim();if(t.includes(`|`)){let e=t.split(`|`).map(e=>e.trim()).filter(Boolean);if(e.length>=3){let t=e[0],n=e[1],r=e.slice(2).join(` | `);y(i).store({topic:t,tags:n,fact:r}).then(e=>{i.toast.show({title:`Stored [${e.entry.id}] in ${e.entry.file}`,variant:`success`})}).catch(e=>{i.toast.show({title:e instanceof Error?e.message:`Failed to store memory`,variant:`error`})});return}}T(i,``,`add`,t)}})),i.add(t.Command,()=>({id:`memory-delete`,title:`Delete Memory Entry...`,description:`Delete a persistent memory entry by ID`,keywords:`memory delete remove prune`,group:`Session`,section:`session`,slash:{name:`memory-delete`,arguments:!0},run(e){let t=(e??``).trim();t?y(i).remove({id:t}).then(e=>{e.deleted.length>0?i.toast.show({title:`Deleted ${e.deleted.map(e=>e.id).join(`, `)}`,variant:`success`}):i.toast.show({title:`Not found: ${t}`,variant:`error`})}).catch(e=>{i.toast.show({title:e instanceof Error?e.message:`Delete failed`,variant:`error`})}):T(i,``)}})),i.add(t.Command,()=>({id:`memory-import`,title:`Import Existing Memories`,description:`Import rules from AGENTS.md/CLAUDE.md and compacted sessions from opencode.db`,keywords:`memory import rules sessions bootstrap`,group:`Session`,section:`session`,slash:{name:`memory-import`,arguments:!0},run(e){let t=Number.parseInt((e??``).trim(),10),n=Number.isFinite(t)&&t>0?t:30;y(i).importMemory({limit:n}).then(e=>{i.toast.show({title:`Imported ${e.importedFactsCount} rules, ${e.importedSessionsCount} sessions (${e.total} total)`,variant:`success`})}).catch(e=>{i.toast.show({title:e instanceof Error?e.message:`Import failed`,variant:`error`})})}}));let a=`${i.id}:memory`,o={id:`memory`,get title(){return i.t(`memory.panel`)},closable:`compact`};if(i.add(t.Command,()=>({id:`memory-panel`,title:i.t(`memory.panel.toggle`),description:`Toggle the persistent Memory Manager side panel`,keywords:`memory panel sidebar facts core`,group:`Session`,section:`session`,bind:`mod+alt+m`,run(){let e=i.sessions.current();e?i.layout.toggle(a,e):T(i,``)}})),i.add(t.MenuItem,()=>{let e=i.sessions.current();return{menu:`session.panel`,id:`memory`,title:i.t(`memory.panel`),description:i.t(`memory.command.description`),icon:`outline-brain`,keybind:`${i.id}.memory-panel`,opened:!!e&&i.layout.state(a,e)!==`closed`,run(){let e=i.sessions.current();e?i.layout.toggle(a,e):T(i,``)}}}),typeof document<`u`){let e=()=>{let e=document.querySelector(`header[data-slot="titlebar-v2"] button[aria-label*="Search"]`);if(e&&e.parentElement){let t=e.parentElement;if(!t.querySelector(`[data-action="titlebar-memories"]`)){let e=document.createElement(`button`);e.type=`button`,e.setAttribute(`data-action`,`titlebar-memories`),e.setAttribute(`aria-label`,`Memory Manager (Ctrl+Shift+M)`),e.setAttribute(`title`,`Memory Manager (Ctrl+Shift+M)`),e.className=`olm-titlebar-quick-btn`,e.innerHTML=`<svg data-slot="icon-svg" width="16" height="16" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><use href="#opencode-v2-icon-outline-brain"></use></svg>`,e.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),T(i,``)}),t.appendChild(e)}}let t=document.querySelector(`button[data-action="vertical-tabs-search"]`);if(t&&t.parentElement&&!t.parentElement.querySelector(`[data-action="vertical-tabs-memories"]`)){let e=document.createElement(`button`);e.type=`button`,e.setAttribute(`data-titlebar-tab-action`,``),e.setAttribute(`data-action`,`vertical-tabs-memories`),e.setAttribute(`aria-label`,`Memories (Ctrl+Shift+M)`),e.className=`group flex h-7 w-full shrink-0 items-center gap-1.5 rounded-[6px] ps-1.5 pe-2 text-[13px] leading-4 text-v2-text-text-faint hover:text-v2-text-text-base`,e.innerHTML=`<svg data-slot="icon-svg" width="16" height="16" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg" class="shrink-0" aria-hidden="true"><use href="#opencode-v2-icon-outline-brain"></use></svg><span class="min-w-0 truncate whitespace-nowrap">Memories</span>`,e.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),T(i,``)}),t.insertAdjacentElement(`afterend`,e)}};e();let t=new MutationObserver(()=>{e()});document.body&&t.observe(document.body,{childList:!0,subtree:!0}),(0,n.onCleanup)(()=>{t.disconnect(),document.querySelectorAll(`[data-action="titlebar-memories"], [data-action="vertical-tabs-memories"]`).forEach(e=>e.remove())})}i.add(t.Panel,{id:`memory`,region:`side`,list:e=>e.open.includes(`memory`)?[o]:[],render:()=>(0,e.createComponent)(b,{ctx:i,variant:`panel`})})}});(0,e.delegateEvents)([`keydown`,`click`,`input`]),exports.default=E;