opencode-codex-memory 0.8.0 → 0.8.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/README.md +64 -525
- package/dist/src/claude-import.js +25 -27
- package/dist/src/v2/agents.js +19 -8
- package/dist/src/v2/plugin.js +23 -4
- package/dist/src/v2/search-sandbox.d.ts +4 -0
- package/dist/src/v2/search-sandbox.js +33 -0
- package/dist/src/v2/service.d.ts +2 -0
- package/dist/src/v2/service.js +43 -4
- package/dist/src/v2/shim.d.ts +2 -2
- package/dist/src/v2/shim.js +77 -38
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -9,567 +9,106 @@
|
|
|
9
9
|
</a>
|
|
10
10
|
</p>
|
|
11
11
|
|
|
12
|
-
Persistent memory for [OpenCode](https://opencode.ai)
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
Persistent memory for [OpenCode](https://opencode.ai). Your agent learns from
|
|
13
|
+
past sessions — your conventions, your projects, the decisions you made — and
|
|
14
|
+
brings useful context into new conversations automatically.
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
See the [changelog](./CHANGELOG.md) for release history.
|
|
22
|
-
|
|
23
|
-
**Local-first by design.** Memory is plain markdown files plus a small SQLite
|
|
24
|
-
database on your own machine — no memory service to sign up for, no MCP server,
|
|
25
|
-
no separate process, no sync. Installing it is one line in your `opencode.json`;
|
|
26
|
-
from there everything lives under `~/.local/share/opencode/` by default (or a
|
|
27
|
-
directory you set with `home`), so you can read it, grep it, edit it, or delete
|
|
28
|
-
it like anything else you own. Nothing leaves your machine beyond the model
|
|
29
|
-
calls OpenCode already makes.
|
|
30
|
-
|
|
31
|
-
If you *do* also use the Codex CLI or Claude Code on the same machine: the
|
|
32
|
-
plugin can bring their memories in (and, for Codex, push ours back). Off by
|
|
33
|
-
default — see [Sharing memory with the Codex CLI](#sharing-memory-with-the-codex-cli)
|
|
34
|
-
and [Importing memory from Claude Code](#importing-memory-from-claude-code).
|
|
35
|
-
|
|
36
|
-
## Why
|
|
37
|
-
|
|
38
|
-
By default every OpenCode session starts from zero. You re-explain your build
|
|
39
|
-
commands, your code style, and the quirks of each repo over and over.
|
|
40
|
-
|
|
41
|
-
This plugin closes that loop. It reviews finished sessions in the
|
|
42
|
-
background, keeps what's durable — your preferences, how a repo is built, what
|
|
43
|
-
worked and what didn't — and puts that context back in front of the agent in
|
|
44
|
-
later conversations. You don't manage any of it; OpenCode just gets more useful
|
|
45
|
-
the more you use it.
|
|
46
|
-
|
|
47
|
-
If you want the mental model — learning, remembering, forgetting — see
|
|
48
|
-
[How OpenCode Codex Memory works](./docs/how-ai-memory-works.md).
|
|
16
|
+
**No Codex subscription or OpenAI account required.** This plugin ports the
|
|
17
|
+
memory system from OpenAI's Codex and uses the models you already have in
|
|
18
|
+
OpenCode. Memory is stored locally as Markdown files and a small SQLite
|
|
19
|
+
database. Background learning makes additional calls through your configured
|
|
20
|
+
model providers; there is no separate memory service or MCP server.
|
|
49
21
|
|
|
50
22
|
## Install
|
|
51
23
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
```json
|
|
55
|
-
{
|
|
56
|
-
"plugin": ["opencode-codex-memory@0.8.0"]
|
|
57
|
-
}
|
|
58
|
-
```
|
|
24
|
+
The plugin works with its default settings; no extra memory configuration is needed.
|
|
59
25
|
|
|
60
|
-
|
|
61
|
-
it, so a bare `"opencode-codex-memory"` is not "always latest". Check
|
|
62
|
-
[npm](https://www.npmjs.com/package/opencode-codex-memory) for the current
|
|
63
|
-
version.
|
|
26
|
+
### 1. Add the plugin for your OpenCode version
|
|
64
27
|
|
|
65
|
-
|
|
66
|
-
|
|
28
|
+
Run `opencode --version` if you are unsure which version you use. Add the entry
|
|
29
|
+
to your existing global `~/.config/opencode/opencode.jsonc` or `opencode.json`
|
|
30
|
+
(under `$XDG_CONFIG_HOME/opencode` if set). Keep your other settings and plugins.
|
|
67
31
|
|
|
68
|
-
|
|
69
|
-
[Configuration](#configuration).
|
|
70
|
-
|
|
71
|
-
**OpenCode 2:** the same package works on opencode2 — install it with the
|
|
72
|
-
V2 plugin syntax:
|
|
73
|
-
|
|
74
|
-
```jsonc
|
|
75
|
-
{
|
|
76
|
-
"plugins": [{ "package": "opencode-codex-memory@0.8.0" }],
|
|
77
|
-
}
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
Same pipeline, not the same host APIs — see [docs/opencode2.md](./docs/opencode2.md)
|
|
81
|
-
for the limits (registered service, retained citation markup, no `small_model`).
|
|
82
|
-
On opencode2 you also get a **Memory** section in the session sidebar plus a
|
|
83
|
-
`/memory-status` command, served live from the same state as `memory_inspect`.
|
|
84
|
-
|
|
85
|
-
### Installation hints
|
|
86
|
-
|
|
87
|
-
To bump pins, copy
|
|
88
|
-
[`docs/commands/update-plugins.md`](./docs/commands/update-plugins.md) to
|
|
89
|
-
`~/.config/opencode/command/update-plugins.md` and run `/update-plugins`.
|
|
90
|
-
This command is not part of the plugin package — nothing about it is
|
|
91
|
-
installed with the plugin. It works for every pinned plugin in your config,
|
|
92
|
-
not just this one.
|
|
93
|
-
|
|
94
|
-
## Try it
|
|
95
|
-
|
|
96
|
-
Just use OpenCode normally. Sessions that have been idle for a few hours get
|
|
97
|
-
reviewed in the background and memory starts building up — you don't have to do
|
|
98
|
-
anything. Come back the next day and ask something like *"what do you know about how I
|
|
99
|
-
work?"* or *"what was I doing in this repo?"* and the agent draws on what it
|
|
100
|
-
learned. The more you use it, the more it knows.
|
|
101
|
-
|
|
102
|
-
You can also steer it in plain language, mid-conversation:
|
|
103
|
-
|
|
104
|
-
- *"remember that I deploy this project with `make release`"* → saved as a note.
|
|
105
|
-
- *"what was I working on in this repo last week?"* → time-scoped recall.
|
|
106
|
-
- *"reset my memory"* → wipes it and starts over.
|
|
107
|
-
|
|
108
|
-
Want to prime it before the first session has a chance to be learned? You can
|
|
109
|
-
drop a starter summary in yourself — it's just a file:
|
|
110
|
-
|
|
111
|
-
```bash
|
|
112
|
-
mkdir -p ~/.local/share/opencode/memories
|
|
113
|
-
echo 'I prefer TypeScript strict mode and 2-space indentation.' \
|
|
114
|
-
> ~/.local/share/opencode/memories/memory_summary.md
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
## Where your data lives
|
|
118
|
-
|
|
119
|
-
```
|
|
120
|
-
~/.local/share/opencode/
|
|
121
|
-
├── memory.db # the plugin's own database (OpenCode's data is only accessed via its API)
|
|
122
|
-
└── memories/
|
|
123
|
-
├── memory_summary.md # compact summary injected into the system prompt
|
|
124
|
-
├── MEMORY.md # searchable index of everything learned
|
|
125
|
-
├── rollout_summaries/ # one recap per past session
|
|
126
|
-
├── skills/ # reusable procedures discovered over time
|
|
127
|
-
└── extensions/ad_hoc/notes/ # things you explicitly asked it to remember
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
By default this is OpenCode's own data directory — `$XDG_DATA_HOME/opencode`
|
|
131
|
-
when that's set, otherwise `~/.local/share/opencode` (same resolution on macOS,
|
|
132
|
-
Linux, and Windows). Relocating OpenCode's local dir (for example by setting
|
|
133
|
-
`XDG_DATA_HOME`) therefore moves memory with it. To pin **only** `memory.db`
|
|
134
|
-
and `memories/` somewhere else — a sandbox mount, without the rest of
|
|
135
|
-
OpenCode's database — set `home`. That pin is always enforced; OpenCode's data
|
|
136
|
-
dir and `XDG_DATA_HOME` no longer apply. Precedence:
|
|
137
|
-
[Relocating memory](#relocating-memory-sandbox-mounts). Do not symlink
|
|
138
|
-
`memories/` — the plugin refuses a symlinked memory root.
|
|
139
|
-
|
|
140
|
-
It's all plain files and a local SQLite database. Read them, edit them, delete
|
|
141
|
-
them — it's yours. (The `memories/` folder also holds a few working files and
|
|
142
|
-
an internal `.git/` the plugin uses for change tracking; `memory_reset` wipes
|
|
143
|
-
those too.)
|
|
144
|
-
|
|
145
|
-
### Backup and restore
|
|
146
|
-
|
|
147
|
-
Back up the whole OpenCode data directory while OpenCode is stopped. The
|
|
148
|
-
SQLite database and `memories/` workspace are a pair: restoring only one can
|
|
149
|
-
leave job state, Git baseline, and memory files out of sync. Include hidden
|
|
150
|
-
files, especially `memories/.git/`, and SQLite sidecars such as `memory.db-wal`
|
|
151
|
-
or `memory.db-shm` when present.
|
|
152
|
-
|
|
153
|
-
The default directory is `$XDG_DATA_HOME/opencode` when `XDG_DATA_HOME` is set,
|
|
154
|
-
otherwise `~/.local/share/opencode`. If you set `home` (or
|
|
155
|
-
`OPENCODE_CODEX_MEMORY_HOME`), back up that directory instead — it is the pair
|
|
156
|
-
`memory.db` + `memories/`. Copy it to a dated backup location. To restore, stop
|
|
157
|
-
OpenCode, replace the current home with the backup copy, then start OpenCode
|
|
158
|
-
again. Do not restore while OpenCode is running or copy only `memory.db` or
|
|
159
|
-
only `memories/`.
|
|
160
|
-
|
|
161
|
-
## Privacy & safety
|
|
162
|
-
|
|
163
|
-
- **Local only.** There is no remote storage option to enable, by accident or
|
|
164
|
-
otherwise: Codex keeps memory storage behind a backend interface whose only
|
|
165
|
-
implementation today is the local filesystem, and this port implements that
|
|
166
|
-
path and nothing else. Nothing is sent anywhere except through your existing
|
|
167
|
-
OpenCode provider, using your existing credentials; the plugin holds no keys
|
|
168
|
-
of its own.
|
|
169
|
-
- **Secrets are redacted** (API keys, tokens, private keys, passwords) from
|
|
170
|
-
session transcripts and extracted memories before anything is written or sent
|
|
171
|
-
to a model. Notes you explicitly dictate ("remember that ...") are stored as
|
|
172
|
-
you said them.
|
|
173
|
-
- **The learning agents are sandboxed** — the extraction agent can't touch your
|
|
174
|
-
filesystem (the transcript is handed to it inline; it only emits its structured
|
|
175
|
-
result), and the consolidation agent gets only file tools plus access to the
|
|
176
|
-
memory folder. Shell, network, IDE, and MCP tools are denied for both.
|
|
177
|
-
- **Reset is safe.** `memory_reset` refuses to run if the memory folder is a
|
|
178
|
-
symlink, so it can't be tricked into deleting something else.
|
|
179
|
-
- **Web/MCP sessions:** by default, sessions that used web search, fetch, or MCP
|
|
180
|
-
tools are still eligible for memory (matching Codex). If you'd rather exclude
|
|
181
|
-
them so scraped or external content can't enter your memory, set
|
|
182
|
-
`disable_on_external_context: true`.
|
|
183
|
-
|
|
184
|
-
## Configuration
|
|
185
|
-
|
|
186
|
-
Optional plugin options (all have sensible defaults). Names and defaults match
|
|
187
|
-
Codex's `[memories]` config so the two stay easy to compare:
|
|
188
|
-
|
|
189
|
-
| Option | Default | Meaning |
|
|
190
|
-
|---|---|---|
|
|
191
|
-
| `generate_memories` | `true` | Turn the background learning pipeline on/off |
|
|
192
|
-
| `version` | `"v1"` | Read version for new sessions, and the sole writer when dual-write is off. `"v2"` is summary-only, with recaps in isolated `memories_v2/` and no `MEMORY.md`. |
|
|
193
|
-
| `dual_write` | `false` | Run both learning pipelines independently while reading the selected version. Enables V2 warmup before an explicit cutover. |
|
|
194
|
-
| `use_memories` | `true` | Inject the memory summary into the system prompt |
|
|
195
|
-
| `dedicated_tools` | `true` | Expose the `memory_read`/`memory_search`/`memory_list`/`memory_add_note` tools |
|
|
196
|
-
| `disable_on_external_context` | `false` | Exclude sessions that used web/MCP tools from memory |
|
|
197
|
-
| `extract_model` | OpenCode `small_model`, else see below | Model used for per-session extraction |
|
|
198
|
-
| `consolidation_model` | OpenCode `model`, else see below | Model used for consolidation |
|
|
199
|
-
| `max_raw_memories_for_consolidation` | `256` | How many raw memories feed each consolidation pass |
|
|
200
|
-
| `max_rollout_age_days` | `10` | Ignore sessions older than this for extraction |
|
|
201
|
-
| `min_rollout_idle_hours` | `6` | How long a session must be idle before it's eligible |
|
|
202
|
-
| `max_rollouts_per_startup` | `2` | Max sessions extracted per pass |
|
|
203
|
-
| `max_unused_days` | `30` | Prune memories unused for this long |
|
|
204
|
-
| `codex_interop` | `{ "import": false, "export": false }` | Two-way memory exchange with a local Codex CLI (see below) |
|
|
205
|
-
| `claude_import` | `{ "enabled": false }` | One-way import of Claude Code project memories (see below) |
|
|
206
|
-
| `home` | unset (follows OpenCode data dir) | Pin `memory.db` + `memories/` here. When set, OpenCode's data dir and `XDG_DATA_HOME` are ignored. See [Relocating memory](#relocating-memory-sandbox-mounts) |
|
|
207
|
-
|
|
208
|
-
To set options, turn the plugin entry into a `[name, options]` pair:
|
|
209
|
-
|
|
210
|
-
```json
|
|
211
|
-
{
|
|
212
|
-
"plugin": [
|
|
213
|
-
["opencode-codex-memory@0.8.0", { "disable_on_external_context": true, "min_rollout_idle_hours": 2 }]
|
|
214
|
-
]
|
|
215
|
-
}
|
|
216
|
-
```
|
|
217
|
-
|
|
218
|
-
See the [OpenCode plugin docs](https://opencode.ai/docs/plugins/) for details.
|
|
219
|
-
|
|
220
|
-
Numeric options are clamped to Codex's valid ranges; unknown option keys are
|
|
221
|
-
ignored with a warning. Setting `use_memories: false` also hides the memory
|
|
222
|
-
tools, matching Codex's extension gating.
|
|
223
|
-
|
|
224
|
-
**Verifying your configuration:** the plugin never hard-fails on bad options.
|
|
225
|
-
To check what actually took effect, ask the agent to run `memory_inspect` — it
|
|
226
|
-
echoes the effective options (after parsing and clamping), lists warnings for
|
|
227
|
-
unknown or malformed keys (typos included), and shows the resolved Codex
|
|
228
|
-
interop state. A mistyped option shows up there twice: as a warning, and as
|
|
229
|
-
the default value appearing where you expected your setting.
|
|
230
|
-
|
|
231
|
-
Model selection mirrors Codex's cheap-extraction / capable-consolidation
|
|
232
|
-
split using OpenCode's own concepts: when `extract_model` is unset, the
|
|
233
|
-
`small_model` from your `opencode.json` is used (Codex uses `gpt-5.6-luna`);
|
|
234
|
-
when `consolidation_model` is unset, your main `model` is used (Codex uses
|
|
235
|
-
`gpt-5.6-terra`). If neither is configured, the learning sub-agents fall back to
|
|
236
|
-
their own agent-level `model` (if you defined one), else the provider default.
|
|
237
|
-
(OpenCode's *automatic* small-model pick is internal to OpenCode and not
|
|
238
|
-
exposed to plugins — set `small_model` explicitly to get the cheap extraction
|
|
239
|
-
path.)
|
|
240
|
-
|
|
241
|
-
The full precedence per phase: plugin option (`extract_model` /
|
|
242
|
-
`consolidation_model`) → OpenCode config (`small_model` / `model`) → a `model`
|
|
243
|
-
on your own `memorize-extract`/`memorize` agent definition, if you overrode
|
|
244
|
-
one → the provider's default model. Note that the first two pass the model
|
|
245
|
-
explicitly, so they win over an agent-level `model`.
|
|
246
|
-
|
|
247
|
-
Reasoning effort follows Codex (`low` for extraction, `medium` for
|
|
248
|
-
consolidation) when the model lists that name. Otherwise the plugin picks the
|
|
249
|
-
nearest OpenCode variant on `none < minimal < low < medium < high < xhigh < max`
|
|
250
|
-
(ties go higher). No listed efforts → no pin, host default.
|
|
251
|
-
|
|
252
|
-
> Note: `dedicated_tools` defaults to `true` here (Codex defaults it to `false`).
|
|
253
|
-
> This is the one intentional default difference — the tools are a core part of a
|
|
254
|
-
> standalone memory plugin. Everything else matches Codex's defaults.
|
|
255
|
-
>
|
|
256
|
-
> Turning `dedicated_tools` off keeps background learning, summary injection,
|
|
257
|
-
> and citation tracking working. The injected guidance switches to Codex's
|
|
258
|
-
> file-based mode — the agent reads the memory files with its normal file
|
|
259
|
-
> tools and writes "remember this" notes directly into
|
|
260
|
-
> `extensions/ad_hoc/notes/`. Caveat: the memory folder lives outside your
|
|
261
|
-
> project, so OpenCode raises an `external_directory` permission prompt the
|
|
262
|
-
> first time an agent touches it (allow-always covers later access); agents
|
|
263
|
-
> whose permissions deny that ask cannot use file-based mode. The dedicated
|
|
264
|
-
> tools have no such friction — that's why they are the default. The
|
|
265
|
-
> maintenance tools (`memory_reset`, `memory_inspect`, `memory_mode`) stay
|
|
266
|
-
> available either way.
|
|
267
|
-
|
|
268
|
-
### Migrating from memory V1 to V2
|
|
269
|
-
|
|
270
|
-
Memory versions are independent of OpenCode host versions: both work on
|
|
271
|
-
OpenCode 1.x and 2.x. V1 remains the default. See the
|
|
272
|
-
[conceptual comparison](docs/how-ai-memory-works.md#two-versions-v1-and-v2)
|
|
273
|
-
for the different learning contracts.
|
|
274
|
-
|
|
275
|
-
1. Set these **plugin options** and restart OpenCode's server:
|
|
276
|
-
|
|
277
|
-
```json
|
|
278
|
-
{ "version": "v1", "dual_write": true }
|
|
279
|
-
```
|
|
280
|
-
|
|
281
|
-
V1 continues serving memory. Both pipelines independently extract eligible
|
|
282
|
-
conversations and consolidate into their own workspaces. This adds model
|
|
283
|
-
calls for the second pipeline; it does not copy or convert V1 artifacts.
|
|
284
|
-
|
|
285
|
-
2. Check `memory_inspect`, or `/memory` on OpenCode 2. `v2_ready` becomes true
|
|
286
|
-
when V2 has a valid summary and one successful consolidation has consumed
|
|
287
|
-
at least **20 distinct sessions**. The count is a high-water mark, not a
|
|
288
|
-
lifetime sum, so repeated consolidation of one session cannot make V2 ready.
|
|
289
|
-
`min_consolidated_threads` on inspect (RPC: `minConsolidatedThreads`) can
|
|
290
|
-
override the reporting threshold from 1 to 4096; it does not change config
|
|
291
|
-
or switch versions. Readiness is a warmup signal, not a quality guarantee.
|
|
292
|
-
|
|
293
|
-
3. When ready, set `version: "v2"` and restart the server. New sessions use V2.
|
|
294
|
-
Existing sessions keep the version selected on their first memory use,
|
|
295
|
-
including retrieval tools, explicit notes, and citation accounting across
|
|
296
|
-
server restarts. Start a new session to try the new read path.
|
|
297
|
-
|
|
298
|
-
4. Keep `dual_write: true` while evaluating V2, then set it to `false` when you
|
|
299
|
-
want only V2 learning. To roll back, select `version: "v1"` and start a new
|
|
300
|
-
session. If dual-write was off, V1 will not contain the intervening learning.
|
|
301
|
-
|
|
302
|
-
There is no automatic cutover. An explicit "remember this" note goes to the
|
|
303
|
-
requesting session's selected workspace; the other writer learns from eligible
|
|
304
|
-
conversation history. Disabled/polluted session flags are shared. Session
|
|
305
|
-
deletion removes extracted rows from both stores and queues forgetting;
|
|
306
|
-
`memory_reset` clears both stores and workspaces, preserving session modes and
|
|
307
|
-
read-version stamps. Inactive stores resume queued consolidation when enabled.
|
|
308
|
-
|
|
309
|
-
### Relocating memory (sandbox mounts)
|
|
310
|
-
|
|
311
|
-
First match wins:
|
|
312
|
-
|
|
313
|
-
1. **`home` plugin option** — pinned. Always enforced. OpenCode's data
|
|
314
|
-
directory and `XDG_DATA_HOME` do not apply.
|
|
315
|
-
2. **`OPENCODE_CODEX_MEMORY_HOME`** — same pin, only if `home` is unset.
|
|
316
|
-
3. **OpenCode data dir** (default) — `$XDG_DATA_HOME/opencode` when that env
|
|
317
|
-
is set, otherwise `~/.local/share/opencode`. Memory moves with OpenCode's
|
|
318
|
-
local directory.
|
|
319
|
-
|
|
320
|
-
To mount **only** memory into a sandbox, use (1) or (2) and point at a
|
|
321
|
-
dedicated directory:
|
|
322
|
-
|
|
323
|
-
```json
|
|
324
|
-
{
|
|
325
|
-
"plugin": [
|
|
326
|
-
["opencode-codex-memory@0.8.0", { "home": "/path/to/opencode-memory" }]
|
|
327
|
-
]
|
|
328
|
-
}
|
|
329
|
-
```
|
|
330
|
-
|
|
331
|
-
OpenCode 2:
|
|
32
|
+
**OpenCode 2.x**
|
|
332
33
|
|
|
333
34
|
```jsonc
|
|
334
35
|
{
|
|
36
|
+
"$schema": "https://opencode.ai/config.json",
|
|
335
37
|
"plugins": [
|
|
336
|
-
{ "package": "opencode-codex-memory@0.8.
|
|
38
|
+
{ "package": "opencode-codex-memory@0.8.1" }
|
|
337
39
|
]
|
|
338
40
|
}
|
|
339
41
|
```
|
|
340
42
|
|
|
341
|
-
|
|
342
|
-
make memory follow the cwd, and memory is global. Same layout as the default,
|
|
343
|
-
just elsewhere:
|
|
344
|
-
|
|
345
|
-
```
|
|
346
|
-
/path/to/opencode-memory/
|
|
347
|
-
├── memory.db
|
|
348
|
-
└── memories/
|
|
349
|
-
```
|
|
350
|
-
|
|
351
|
-
Mount that directory into the sandbox at the **same absolute path**.
|
|
352
|
-
|
|
353
|
-
This does not move existing files. Stop OpenCode, copy `memory.db` (and
|
|
354
|
-
`memory.db-wal` / `memory.db-shm` if present) plus `memories/` into the new
|
|
355
|
-
home, then start it again. Do not symlink `memories/` in place of `home` —
|
|
356
|
-
a symlinked memory root is refused. Ask the agent to run `memory_inspect` to
|
|
357
|
-
confirm the resolved path.
|
|
358
|
-
|
|
359
|
-
### Sharing memory with the Codex CLI
|
|
360
|
-
|
|
361
|
-
If you use OpenCode and the Codex CLI on the same machine, turn this on so each
|
|
362
|
-
side can pick up what the other already learned. **Either or both directions.**
|
|
363
|
-
Off by default; no changes to Codex's own config are required.
|
|
364
|
-
|
|
365
|
-
**Enable both directions:**
|
|
366
|
-
|
|
367
|
-
```json
|
|
368
|
-
{
|
|
369
|
-
"plugin": [
|
|
370
|
-
[
|
|
371
|
-
"opencode-codex-memory@0.8.0",
|
|
372
|
-
{ "codex_interop": { "import": true, "export": true } }
|
|
373
|
-
]
|
|
374
|
-
]
|
|
375
|
-
}
|
|
376
|
-
```
|
|
377
|
-
|
|
378
|
-
- **Import:** on each consolidation pass here, durable memory from Codex is
|
|
379
|
-
merged into this plugin's store (tagged so you can tell it came from Codex).
|
|
380
|
-
- **Export:** after a successful consolidation here, this plugin's memory is
|
|
381
|
-
offered to Codex; Codex merges it on *its* next consolidation pass.
|
|
382
|
-
|
|
383
|
-
**Options** (all under `codex_interop`):
|
|
384
|
-
|
|
385
|
-
| Option | Default | Meaning |
|
|
386
|
-
| --- | --- | --- |
|
|
387
|
-
| `import` | `false` | Bring Codex's consolidated memory into OpenCode. |
|
|
388
|
-
| `export` | `false` | Offer this plugin's consolidated memory to Codex. |
|
|
389
|
-
| `codex_home` | `$CODEX_HOME`, else `~/.codex` | Where the Codex CLI keeps its data. Set this if you use a non-default location. |
|
|
390
|
-
|
|
391
|
-
**Notes**
|
|
392
|
-
|
|
393
|
-
- Export only runs once Codex has created its own memory workspace
|
|
394
|
-
(`$CODEX_HOME/memories`). Until then, import/export quietly do nothing for
|
|
395
|
-
the missing side.
|
|
396
|
-
- Codex's own files are never rewritten in place — export only adds a side
|
|
397
|
-
channel Codex already knows how to read.
|
|
398
|
-
- Both sides tag origin (`[from codex]` / `[from opencode]`) and skip the other
|
|
399
|
-
tag on re-import, so the same facts don't bounce back and forth.
|
|
400
|
-
- Safe to combine with `claude_import`. Check status with `memory_inspect`
|
|
401
|
-
(`codex_interop:` section).
|
|
402
|
-
|
|
403
|
-
**Turning it off**
|
|
404
|
-
|
|
405
|
-
Setting `import` / `export` back to `false` (or removing `codex_interop`) only
|
|
406
|
-
stops further sync. Already merged memory stays in this plugin's store, and any
|
|
407
|
-
staging copies stay on disk (harmless while import is off). The last export left
|
|
408
|
-
in Codex stays until Codex consolidates it away or you remove it there.
|
|
409
|
-
|
|
410
|
-
To drop the local staging copies too: turn import off first, then delete
|
|
411
|
-
`extensions/codex_import/` under the plugin memory directory (see
|
|
412
|
-
[Where your data lives](#where-your-data-lives)). Leave import off — if you turn
|
|
413
|
-
it back on, the next pass will recreate them from Codex. After a deletion, the
|
|
414
|
-
next consolidation can treat the missing files as a signal to drop entries that
|
|
415
|
-
only came from that import.
|
|
416
|
-
|
|
417
|
-
### Importing memory from Claude Code
|
|
418
|
-
|
|
419
|
-
If you use Claude Code as well as OpenCode, turn this on so OpenCode can learn
|
|
420
|
-
from the project memories Claude already keeps on your machine. **One-way only**
|
|
421
|
-
(Claude → OpenCode); nothing is written back into Claude. Off by default.
|
|
422
|
-
|
|
423
|
-
**Enable everything Claude has:**
|
|
43
|
+
**OpenCode 1.x** (1.18 or newer)
|
|
424
44
|
|
|
425
45
|
```json
|
|
426
46
|
{
|
|
427
|
-
"
|
|
428
|
-
|
|
429
|
-
]
|
|
47
|
+
"$schema": "https://opencode.ai/config.json",
|
|
48
|
+
"plugin": ["opencode-codex-memory@0.8.1"]
|
|
430
49
|
}
|
|
431
50
|
```
|
|
432
51
|
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
global summary.
|
|
437
|
-
|
|
438
|
-
**Options** (all under `claude_import`):
|
|
52
|
+
Keep a published package version pinned as shown. See
|
|
53
|
+
[Updating the plugin](./docs/troubleshooting.md#updating-the-plugin) when a
|
|
54
|
+
new release is available.
|
|
439
55
|
|
|
440
|
-
|
|
441
|
-
| --- | --- | --- |
|
|
442
|
-
| `enabled` | `false` | Turn the importer on. |
|
|
443
|
-
| `claude_home` | `~/.claude` | Where Claude Code stores its data. Set this if you use a non-default location. |
|
|
444
|
-
| `projects` | all projects | Optional allowlist of Claude project ids to import (see below). |
|
|
56
|
+
### 2. Restart OpenCode and check status
|
|
445
57
|
|
|
446
|
-
|
|
58
|
+
On OpenCode 2, run:
|
|
447
59
|
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
```json
|
|
452
|
-
{
|
|
453
|
-
"plugin": [
|
|
454
|
-
[
|
|
455
|
-
"opencode-codex-memory@0.8.0",
|
|
456
|
-
{
|
|
457
|
-
"claude_import": {
|
|
458
|
-
"enabled": true,
|
|
459
|
-
"projects": ["-Users-you-Desktop-git-my-app"]
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
]
|
|
463
|
-
]
|
|
464
|
-
}
|
|
60
|
+
```sh
|
|
61
|
+
opencode service restart
|
|
465
62
|
```
|
|
466
63
|
|
|
467
|
-
|
|
64
|
+
On OpenCode 1.x, restart OpenCode. If an IDE or another app manages your
|
|
65
|
+
OpenCode server, restart that server too.
|
|
468
66
|
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
67
|
+
Start a conversation and ask **“Check my memory status.”** The agent can run
|
|
68
|
+
`memory_inspect` to show progress and any warnings. In OpenCode 2's terminal
|
|
69
|
+
UI, you can also open the [**`/memory` panel**](./docs/usage.md#memory-panel).
|
|
472
70
|
|
|
473
|
-
|
|
474
|
-
can place on disk.
|
|
475
|
-
- Add or remove ids anytime while import is **on**. Dropping an id (or deleting
|
|
476
|
-
that project's memory in Claude) stops syncing it and removes the staging
|
|
477
|
-
copy on the next pass so consolidation can drop derived entries. Memory
|
|
478
|
-
already merged into the main store is not instantly deleted; the consolidator
|
|
479
|
-
cleans it up when it next runs.
|
|
480
|
-
- Turning `enabled` off (see below) does **not** prune anything.
|
|
481
|
-
|
|
482
|
-
**Turning it off**
|
|
483
|
-
|
|
484
|
-
Setting `enabled` to `false` (or removing `claude_import`) only stops further
|
|
485
|
-
import. Already merged memory stays in this plugin's store, and staging copies
|
|
486
|
-
stay on disk (harmless while import is off).
|
|
487
|
-
|
|
488
|
-
To drop the local staging copies too: turn import off first, then delete
|
|
489
|
-
`extensions/external_agent_import/` under the plugin memory directory (see
|
|
490
|
-
[Where your data lives](#where-your-data-lives)). Leave import off — if you turn
|
|
491
|
-
it back on, the next pass will recreate them from Claude. After a deletion, the
|
|
492
|
-
next consolidation can treat the missing files as a signal to drop entries that
|
|
493
|
-
only came from that import.
|
|
494
|
-
|
|
495
|
-
To stop importing *some* projects without turning the feature off: shrink
|
|
496
|
-
`projects` (or delete that memory in Claude) and let the next pass run. That
|
|
497
|
-
only affects the Claude import channel.
|
|
498
|
-
|
|
499
|
-
**Notes**
|
|
500
|
-
|
|
501
|
-
- Safe to combine with `codex_interop` (Codex sharing uses a separate channel).
|
|
502
|
-
- If you also run another OpenCode plugin that *writes* Claude-style memory,
|
|
503
|
-
pick one writer — two systems updating the same long-term store will fight.
|
|
504
|
-
- Check status anytime with `memory_inspect` (`claude_import:` section).
|
|
505
|
-
|
|
506
|
-
## Why one global memory?
|
|
507
|
-
|
|
508
|
-
There's a single store for everything you do, not one per project — and that's
|
|
509
|
-
the design choice most likely to surprise you, so it's worth explaining where it
|
|
510
|
-
came from.
|
|
511
|
-
|
|
512
|
-
Codex *started* with per-project memory: a separate bucket per directory, plus a
|
|
513
|
-
user-level scope on top. It **deliberately removed that** in early 2026 and
|
|
514
|
-
collapsed everything into one global root — one store, one lock, one
|
|
515
|
-
consolidation pass — for simplicity.
|
|
516
|
-
|
|
517
|
-
Simplicity is easy to underrate here — until you try to draw the boundaries
|
|
518
|
-
yourself. Scoping forces a question that often has no good answer: which project does
|
|
519
|
-
"prefers table-driven tests" belong to? Monorepos, worktrees, and sibling repos
|
|
520
|
-
of the same stack all blur the line, and the most valuable lessons — the ones
|
|
521
|
-
about how *you* work — belong to no project at all. Per-scope stores also each
|
|
522
|
-
consolidate over a thinner slice of evidence than the whole.
|
|
71
|
+
## Try it
|
|
523
72
|
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
conventions follow you into a new repo on day one) while project-specific facts
|
|
529
|
-
stay recognizable as such.
|
|
73
|
+
Use OpenCode normally. By default, a session becomes eligible for learning
|
|
74
|
+
after **6 hours of inactivity**, and consolidation combines learned material
|
|
75
|
+
into memory. The work runs in the background while OpenCode is running;
|
|
76
|
+
an empty memory immediately after installation is normal.
|
|
530
77
|
|
|
531
|
-
|
|
532
|
-
the summary. Codex judged that cheaper than the alternative, and this port
|
|
533
|
-
mirrors that decision rather than layering scoping back on top.
|
|
78
|
+
In a later conversation, try:
|
|
534
79
|
|
|
535
|
-
|
|
80
|
+
- “What do you know about how I work?”
|
|
81
|
+
- “What was I working on in this repo last week?”
|
|
82
|
+
- “Remember that I deploy this project with `make release`.”
|
|
536
83
|
|
|
537
|
-
|
|
538
|
-
|
|
84
|
+
Explicit “remember this” requests save a note immediately; a later
|
|
85
|
+
consolidation integrates it into the summary. You can
|
|
86
|
+
[check progress or pause learning](./docs/usage.md) at any time.
|
|
539
87
|
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
-
|
|
544
|
-
|
|
545
|
-
- effective memory-agent health, including user overrides and required permissions
|
|
546
|
-
- a short eligibility reminder (`min_rollout_idle_hours`, default **6h**)
|
|
88
|
+
Memory is **global across projects**. Project-specific details carry context
|
|
89
|
+
about where they came from, while general preferences can follow you into a
|
|
90
|
+
new repo. Files live under `~/.local/share/opencode/` by default. See
|
|
91
|
+
[Storage and privacy](./docs/storage-and-privacy.md) for the layout, model-call
|
|
92
|
+
privacy, backups, and relocation.
|
|
547
93
|
|
|
548
|
-
|
|
94
|
+
## Start here
|
|
549
95
|
|
|
550
|
-
|
|
|
96
|
+
| I want to… | Read |
|
|
551
97
|
|---|---|
|
|
552
|
-
|
|
|
553
|
-
|
|
|
554
|
-
|
|
|
555
|
-
|
|
|
556
|
-
|
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
[How OpenCode Codex Memory works](./docs/how-ai-memory-works.md). Implementation
|
|
567
|
-
map and workarounds: [`ARCHITECTURE.md`](./ARCHITECTURE.md). Contributor
|
|
568
|
-
guidance lives in [`CONTRIBUTING.md`](./CONTRIBUTING.md) and
|
|
569
|
-
[`AGENTS.md`](./AGENTS.md) — in short: this repo exists to port Codex's memory
|
|
570
|
-
system to OpenCode, and PRs that break that parity will be rejected.
|
|
571
|
-
|
|
572
|
-
CI runs `bun test`, typecheck, build, and the packaging smoke test on every PR.
|
|
98
|
+
| Recall past work, save a note, or pause learning | [Using memory](./docs/usage.md) |
|
|
99
|
+
| Choose or switch memory behavior | [Memory V1 and Memory V2](./docs/memory-versions.md) |
|
|
100
|
+
| Set models, learning frequency, or other options | [Configuration](./docs/configuration.md) |
|
|
101
|
+
| Find, back up, move, or reset my data | [Storage and privacy](./docs/storage-and-privacy.md) |
|
|
102
|
+
| Share with Codex CLI or import Claude Code memories | [Integrations](./docs/integrations.md) |
|
|
103
|
+
| Fix missing memory or check an update | [Troubleshooting](./docs/troubleshooting.md) |
|
|
104
|
+
|
|
105
|
+
## Learn more and contribute
|
|
106
|
+
|
|
107
|
+
- [How memory works](./docs/how-ai-memory-works.md) — the illustrated explanation
|
|
108
|
+
of learning, recall, and forgetting.
|
|
109
|
+
- [Changelog](./CHANGELOG.md) — release history.
|
|
110
|
+
- [Contributing](./CONTRIBUTING.md) — development setup and the Codex parity policy.
|
|
111
|
+
- [Architecture](./ARCHITECTURE.md) — implementation map and host adaptations.
|
|
573
112
|
|
|
574
113
|
## License
|
|
575
114
|
|
|
@@ -73,8 +73,10 @@ function lstatKind(p) {
|
|
|
73
73
|
return "dir";
|
|
74
74
|
return "other";
|
|
75
75
|
}
|
|
76
|
-
catch {
|
|
77
|
-
|
|
76
|
+
catch (err) {
|
|
77
|
+
if (err.code === "ENOENT")
|
|
78
|
+
return "missing";
|
|
79
|
+
throw err;
|
|
78
80
|
}
|
|
79
81
|
}
|
|
80
82
|
/**
|
|
@@ -83,13 +85,7 @@ function lstatKind(p) {
|
|
|
83
85
|
* cwd that canonicalizes to an existing directory wins.
|
|
84
86
|
*/
|
|
85
87
|
export function projectCwdFromSessions(projectRoot) {
|
|
86
|
-
|
|
87
|
-
try {
|
|
88
|
-
entries = fs.readdirSync(projectRoot, { withFileTypes: true });
|
|
89
|
-
}
|
|
90
|
-
catch {
|
|
91
|
-
return null;
|
|
92
|
-
}
|
|
88
|
+
const entries = fs.readdirSync(projectRoot, { withFileTypes: true });
|
|
93
89
|
const sessions = entries
|
|
94
90
|
.filter((e) => e.isFile() && e.name.endsWith(".jsonl"))
|
|
95
91
|
.map((e) => {
|
|
@@ -139,13 +135,9 @@ export function projectCwdFromSessions(projectRoot) {
|
|
|
139
135
|
return null;
|
|
140
136
|
}
|
|
141
137
|
function collectMarkdownFiles(sourceRoot, currentDir, projectKey, projectCwd, out) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
catch {
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
138
|
+
// A partial scan is not a deletion signal. Codex propagates discovery errors
|
|
139
|
+
// before replacing/pruning any imported project.
|
|
140
|
+
const entries = fs.readdirSync(currentDir, { withFileTypes: true });
|
|
149
141
|
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
150
142
|
for (const entry of entries) {
|
|
151
143
|
const full = path.join(currentDir, entry.name);
|
|
@@ -179,13 +171,7 @@ export function discoverExternalMemoryFiles(claudeHome) {
|
|
|
179
171
|
if (lstatKind(projectsRoot) !== "dir")
|
|
180
172
|
return [];
|
|
181
173
|
const files = [];
|
|
182
|
-
|
|
183
|
-
try {
|
|
184
|
-
projectEntries = fs.readdirSync(projectsRoot, { withFileTypes: true });
|
|
185
|
-
}
|
|
186
|
-
catch {
|
|
187
|
-
return [];
|
|
188
|
-
}
|
|
174
|
+
const projectEntries = fs.readdirSync(projectsRoot, { withFileTypes: true });
|
|
189
175
|
projectEntries.sort((a, b) => a.name.localeCompare(b.name));
|
|
190
176
|
for (const entry of projectEntries) {
|
|
191
177
|
if (!entry.isDirectory() || entry.isSymbolicLink())
|
|
@@ -317,6 +303,14 @@ function removeProjectResources(projectKey) {
|
|
|
317
303
|
fs.rmSync(targetRoot, { recursive: true, force: true });
|
|
318
304
|
return true;
|
|
319
305
|
}
|
|
306
|
+
/** Codex project_has_unscoped_target: keep valid scoped imports when cwd is unavailable. */
|
|
307
|
+
function projectHasUnscopedTarget(projectKey) {
|
|
308
|
+
const target = path.join(memoryRoot(), "extensions", EXTENSION_NAME, "resources", projectKey);
|
|
309
|
+
const kind = lstatKind(target);
|
|
310
|
+
if (kind === "missing")
|
|
311
|
+
return false;
|
|
312
|
+
return kind !== "dir" || lstatKind(path.join(target, PROJECT_SCOPE_FILE)) !== "file";
|
|
313
|
+
}
|
|
320
314
|
function replaceProjectResources(projectKey, projectCwd, projectFiles) {
|
|
321
315
|
// Read all sources first so a mid-copy failure never leaves a half-empty dir
|
|
322
316
|
// after we deleted the previous resources (codex replace_project_resources).
|
|
@@ -372,8 +366,13 @@ export function syncClaudeImport(opts) {
|
|
|
372
366
|
if (!opts.enabled)
|
|
373
367
|
return empty;
|
|
374
368
|
const claudeHome = resolveClaudeHome(opts);
|
|
375
|
-
|
|
376
|
-
|
|
369
|
+
try {
|
|
370
|
+
if (lstatKind(claudeHome) !== "dir")
|
|
371
|
+
return empty;
|
|
372
|
+
}
|
|
373
|
+
catch {
|
|
374
|
+
return empty; // Unreachable home is the documented quiet no-op.
|
|
375
|
+
}
|
|
377
376
|
const allFiles = discoverExternalMemoryFiles(claudeHome);
|
|
378
377
|
const byProject = groupByProject(allFiles);
|
|
379
378
|
const sourceKeys = new Set(byProject.keys());
|
|
@@ -417,8 +416,7 @@ export function syncClaudeImport(opts) {
|
|
|
417
416
|
skippedNoCwd.push(projectKey);
|
|
418
417
|
// Unscoped leftovers under this key → remove (codex project_has_unscoped_target).
|
|
419
418
|
try {
|
|
420
|
-
|
|
421
|
-
if (lstatKind(target) !== "missing") {
|
|
419
|
+
if (projectHasUnscopedTarget(projectKey)) {
|
|
422
420
|
if (removeProjectResources(projectKey)) {
|
|
423
421
|
changed = true;
|
|
424
422
|
synchronizedProjects.push(projectKey);
|
package/dist/src/v2/agents.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* hidden definition preserves the health snapshot both agents report into.
|
|
15
15
|
*/
|
|
16
16
|
import path from "path";
|
|
17
|
-
import { memoryRoot } from "../paths.js";
|
|
17
|
+
import { allMemoryRoots, memoryRoot } from "../paths.js";
|
|
18
18
|
import { pluginOptions } from "../options.js";
|
|
19
19
|
import { writeMemoryVersions } from "../memory-version.js";
|
|
20
20
|
import { recordAgentConfig } from "../agent-health.js";
|
|
@@ -35,9 +35,7 @@ export function buildMemorizeAgent() {
|
|
|
35
35
|
// Memories live outside every project: without this grant the wildcard
|
|
36
36
|
// deny blocks consolidation from touching the memory workspace (same
|
|
37
37
|
// role as external_directory in the V1 definition).
|
|
38
|
-
...writeMemoryVersions().flatMap((version) =>
|
|
39
|
-
action, resource: path.join(memoryRoot(version), "*"), effect: "allow",
|
|
40
|
-
}))),
|
|
38
|
+
...writeMemoryVersions().flatMap((version) => workspacePermissions(memoryRoot(version))),
|
|
41
39
|
],
|
|
42
40
|
};
|
|
43
41
|
}
|
|
@@ -45,9 +43,17 @@ export function buildMemorizeAgent() {
|
|
|
45
43
|
export function consolidationPermissions(root) {
|
|
46
44
|
return [
|
|
47
45
|
{ action: "*", resource: "*", effect: "deny" },
|
|
48
|
-
...
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
...workspacePermissions(root),
|
|
47
|
+
];
|
|
48
|
+
}
|
|
49
|
+
function workspacePermissions(root) {
|
|
50
|
+
return [
|
|
51
|
+
...["read", "edit", "external_directory"].flatMap((action) => [root, path.join(root, "*")].map((resource) => ({
|
|
52
|
+
action, resource, effect: "allow",
|
|
53
|
+
}))),
|
|
54
|
+
// These actions check the search pattern, not a path. search-sandbox.ts
|
|
55
|
+
// wraps the built-in executors to enforce this helper's single root.
|
|
56
|
+
...["glob", "grep"].map((action) => ({ action, resource: "*", effect: "allow" })),
|
|
51
57
|
];
|
|
52
58
|
}
|
|
53
59
|
/**
|
|
@@ -77,6 +83,9 @@ export function toV1AgentDefinition(def, agentId) {
|
|
|
77
83
|
continue;
|
|
78
84
|
}
|
|
79
85
|
if (rule.action === "external_directory") {
|
|
86
|
+
// V1 health expects only root/*; its V1 sandbox already includes root.
|
|
87
|
+
if (allMemoryRoots().includes(rule.resource))
|
|
88
|
+
continue;
|
|
80
89
|
const cur = (permission.external_directory ?? {});
|
|
81
90
|
cur[rule.resource] = rule.effect;
|
|
82
91
|
permission.external_directory = cur;
|
|
@@ -181,7 +190,7 @@ function isShippedIncomplete(id, existing, shipped) {
|
|
|
181
190
|
const perms = existing.permissions;
|
|
182
191
|
if (!Array.isArray(perms))
|
|
183
192
|
return true;
|
|
184
|
-
return !perms.some((rule) => rule &&
|
|
193
|
+
return shipped.permissions.some((expected) => !perms.some((rule) => rule?.action === expected.action && rule?.resource === expected.resource && rule?.effect === expected.effect));
|
|
185
194
|
}
|
|
186
195
|
function v2PermissionsToV1Map(permissions) {
|
|
187
196
|
const out = {};
|
|
@@ -195,6 +204,8 @@ function v2PermissionsToV1Map(permissions) {
|
|
|
195
204
|
continue;
|
|
196
205
|
}
|
|
197
206
|
if (rule.action === "external_directory" && typeof rule.resource === "string") {
|
|
207
|
+
if (allMemoryRoots().includes(rule.resource))
|
|
208
|
+
continue;
|
|
198
209
|
const cur = (out.external_directory ?? {});
|
|
199
210
|
cur[rule.resource] = rule.effect;
|
|
200
211
|
out.external_directory = cur;
|
package/dist/src/v2/plugin.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* - agent.transform → memorize sub-agent provisioning (was config hook)
|
|
14
14
|
* - tool.transform → memory tool registration (was returned tool map)
|
|
15
15
|
*
|
|
16
|
-
* Known V2 adaptations (see
|
|
16
|
+
* Known V2 adaptations (see ARCHITECTURE.md): global session reads use the
|
|
17
17
|
* registered public service; finalized citations are accounted from durable
|
|
18
18
|
* text events and stripped from model-bound context; config documents are
|
|
19
19
|
* adapted for the shared model resolver.
|
|
@@ -34,6 +34,7 @@ import { applyPluginOptions, handleSessionDeleted } from "../index.js";
|
|
|
34
34
|
import { setV2Context, buildV1ClientShim, rememberV2Session, } from "./shim.js";
|
|
35
35
|
import { ensureV2Agents } from "./agents.js";
|
|
36
36
|
import { buildV2Tools } from "./tools.js";
|
|
37
|
+
import { guardMemorySearchTools } from "./search-sandbox.js";
|
|
37
38
|
import { MemoryStatusRpc } from "./status-rpc.js";
|
|
38
39
|
import { readMemoryStatus } from "./status.js";
|
|
39
40
|
import { recordInjection, resetInjectionStats } from "./injection.js";
|
|
@@ -77,8 +78,9 @@ function recordV2Citations(sessionId, assistantMessageId, text) {
|
|
|
77
78
|
withSessionMemoryVersion(sessionId, () => getStore().recordUsageOnce(sessionId, assistantMessageId, ids));
|
|
78
79
|
}
|
|
79
80
|
function stripAndReconcileCitations(sessionId, messages) {
|
|
80
|
-
for (const
|
|
81
|
-
|
|
81
|
+
for (const msg of messages ?? []) {
|
|
82
|
+
// Model-bound LLM.Message uses role; persisted/legacy rows use type.
|
|
83
|
+
if ((msg?.role ?? msg?.type) !== "assistant" || !Array.isArray(msg.content))
|
|
82
84
|
continue;
|
|
83
85
|
for (const part of msg.content) {
|
|
84
86
|
if (part?.type !== "text" || typeof part.text !== "string")
|
|
@@ -86,7 +88,10 @@ function stripAndReconcileCitations(sessionId, messages) {
|
|
|
86
88
|
if (!hasCitationMarkup(part.text))
|
|
87
89
|
continue;
|
|
88
90
|
try {
|
|
89
|
-
|
|
91
|
+
// Context fragments may have no durable id. Inventing one would count
|
|
92
|
+
// the same citation again after text.ended (and after compaction).
|
|
93
|
+
if (typeof msg.id === "string")
|
|
94
|
+
recordV2Citations(sessionId, msg.id, part.text);
|
|
90
95
|
}
|
|
91
96
|
catch (e) {
|
|
92
97
|
console.error("[opencode-codex-memory] citation recording failed:", e);
|
|
@@ -256,7 +261,20 @@ export async function setup(ctx) {
|
|
|
256
261
|
return { ok: false };
|
|
257
262
|
}
|
|
258
263
|
}
|
|
264
|
+
const previous = pluginOptions[key];
|
|
259
265
|
pluginOptions[key] = value;
|
|
266
|
+
if (key === "use_memories" && value !== previous) {
|
|
267
|
+
try {
|
|
268
|
+
// Transforms capture options but the host only replays them after an
|
|
269
|
+
// explicit registry invalidation. Affect future tool snapshots now.
|
|
270
|
+
await ctx.tool.reload();
|
|
271
|
+
}
|
|
272
|
+
catch (error) {
|
|
273
|
+
pluginOptions[key] = previous;
|
|
274
|
+
console.error("[opencode-codex-memory] failed to reload V2 memory tools:", error);
|
|
275
|
+
return { ok: false };
|
|
276
|
+
}
|
|
277
|
+
}
|
|
260
278
|
invalidateCache();
|
|
261
279
|
notifyStatusChanged();
|
|
262
280
|
return { ok: true };
|
|
@@ -282,6 +300,7 @@ export async function setup(ctx) {
|
|
|
282
300
|
});
|
|
283
301
|
};
|
|
284
302
|
await ctx.tool.transform((editor) => {
|
|
303
|
+
guardMemorySearchTools(editor, (sessionID) => ctx.session.get({ sessionID }));
|
|
285
304
|
for (const t of buildV2Tools())
|
|
286
305
|
editor.add(t);
|
|
287
306
|
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { allMemoryRoots } from "../paths.js";
|
|
3
|
+
import { safeResolveUnderRoot } from "../path-guard.js";
|
|
4
|
+
import { MEMORIZE_AGENT_ID } from "./agents.js";
|
|
5
|
+
/** Pattern permissions cannot constrain paths. Wrap executors, not fail-open hooks. */
|
|
6
|
+
export function guardMemorySearchTools(editor, getSession) {
|
|
7
|
+
const roots = allMemoryRoots();
|
|
8
|
+
for (const name of ["glob", "grep"]) {
|
|
9
|
+
editor.update(name, (tool) => {
|
|
10
|
+
const execute = tool.execute;
|
|
11
|
+
tool.execute = async (input, context) => {
|
|
12
|
+
if (context.agent !== MEMORIZE_AGENT_ID)
|
|
13
|
+
return execute(input, context);
|
|
14
|
+
const response = await getSession(context.sessionID);
|
|
15
|
+
const session = response?.data ?? response;
|
|
16
|
+
// Helper permissions persist across plugin reloads and select one writer
|
|
17
|
+
// even during dual-write. Never fall back to the active project or version.
|
|
18
|
+
const allowed = roots.filter((root) => session?.permissions?.some((rule) => rule.action === "read" && rule.resource === root && rule.effect === "allow"));
|
|
19
|
+
if (allowed.length !== 1)
|
|
20
|
+
throw new Error("memory search requires one session-scoped memory workspace");
|
|
21
|
+
const root = allowed[0];
|
|
22
|
+
const requested = input.path ?? ".";
|
|
23
|
+
if (typeof requested !== "string")
|
|
24
|
+
throw new Error("invalid memory search path");
|
|
25
|
+
const target = safeResolveUnderRoot(root, path.relative(root, path.resolve(root, requested)));
|
|
26
|
+
if (name === "glob" && (path.isAbsolute(input.pattern) || /(^|[\\/,{])\.\.([\\/},]|$)/.test(input.pattern))) {
|
|
27
|
+
throw new Error("glob pattern escapes memory workspace");
|
|
28
|
+
}
|
|
29
|
+
return execute({ ...input, path: target }, context);
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
package/dist/src/v2/service.d.ts
CHANGED
|
@@ -59,6 +59,8 @@ export declare function setV2ServiceDependenciesForTest(dependencies: V2ServiceD
|
|
|
59
59
|
export declare function invalidateOwnService(): void;
|
|
60
60
|
/** Last discoverOwnService failure, if ownServiceClient returned null. */
|
|
61
61
|
export declare function lastServiceFailure(): string | null;
|
|
62
|
+
/** Invalidate broken endpoints for the next call. Never replay mutations or generation. */
|
|
63
|
+
export declare function serviceRequest<T>(client: V2ServiceClient, request: () => Promise<T>): Promise<T>;
|
|
62
64
|
/** Auth headers for the registered local service. */
|
|
63
65
|
export declare function serviceHeaders(endpoint: V2ServiceEndpoint): Record<string, string> | undefined;
|
|
64
66
|
export declare function parseReadyStatus(body: unknown): V2ServiceStatus | null;
|
package/dist/src/v2/service.js
CHANGED
|
@@ -15,22 +15,57 @@ import { OpenCode } from "@opencode/client";
|
|
|
15
15
|
import { Service } from "@opencode/client/service";
|
|
16
16
|
let testDependencies = null;
|
|
17
17
|
let clientPromise = null;
|
|
18
|
+
let cachedClient = null;
|
|
18
19
|
let lastFailure = null;
|
|
19
20
|
const SERVICE_REQUEST_TIMEOUT_MS = 3_000;
|
|
20
21
|
/** Test seam: replace discovery without changing the production connection path. */
|
|
21
22
|
export function setV2ServiceDependenciesForTest(dependencies) {
|
|
22
23
|
testDependencies = dependencies;
|
|
23
|
-
|
|
24
|
+
invalidateOwnService();
|
|
24
25
|
}
|
|
25
26
|
/** Forget a cached endpoint after a service restart or failed request. */
|
|
26
27
|
export function invalidateOwnService() {
|
|
27
28
|
clientPromise = null;
|
|
29
|
+
cachedClient = null;
|
|
28
30
|
lastFailure = null;
|
|
29
31
|
}
|
|
30
32
|
/** Last discoverOwnService failure, if ownServiceClient returned null. */
|
|
31
33
|
export function lastServiceFailure() {
|
|
32
34
|
return lastFailure;
|
|
33
35
|
}
|
|
36
|
+
function connectionFailed(error) {
|
|
37
|
+
let failed = false;
|
|
38
|
+
const seen = new Set();
|
|
39
|
+
for (let current = error; current && !seen.has(current); current = current.cause ?? current.error) {
|
|
40
|
+
seen.add(current);
|
|
41
|
+
if (current.name === "AbortError")
|
|
42
|
+
return false;
|
|
43
|
+
const status = current.status ?? current.statusCode ?? current.response?.status;
|
|
44
|
+
if (status === 401 || status === 403 || current.reason === "Transport")
|
|
45
|
+
failed = true;
|
|
46
|
+
if (/ECONNREFUSED|ECONNRESET|EPIPE|ENOTFOUND|ETIMEDOUT|fetch failed|unauthori[sz]ed/i.test([current.code, current.type, current._tag, current.name, current.message].join(" ")))
|
|
47
|
+
failed = true;
|
|
48
|
+
}
|
|
49
|
+
return failed;
|
|
50
|
+
}
|
|
51
|
+
/** Invalidate broken endpoints for the next call. Never replay mutations or generation. */
|
|
52
|
+
export async function serviceRequest(client, request) {
|
|
53
|
+
const invalidate = (error) => {
|
|
54
|
+
if (client === cachedClient && connectionFailed(error)) {
|
|
55
|
+
invalidateOwnService();
|
|
56
|
+
lastFailure = error instanceof Error ? error.message : "registered OpenCode service connection failed";
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
try {
|
|
60
|
+
const result = await request();
|
|
61
|
+
invalidate(result?.error);
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
invalidate(error);
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
34
69
|
/** Auth headers for the registered local service. */
|
|
35
70
|
export function serviceHeaders(endpoint) {
|
|
36
71
|
return Service.headers(endpoint);
|
|
@@ -192,17 +227,21 @@ export async function ownServiceClient() {
|
|
|
192
227
|
if (!clientPromise) {
|
|
193
228
|
const request = discoverOwnService()
|
|
194
229
|
.then((found) => {
|
|
195
|
-
|
|
230
|
+
if (clientPromise === request) {
|
|
231
|
+
cachedClient = found?.client ?? null;
|
|
232
|
+
lastFailure = found ? null : "no registered OpenCode 2 service.json";
|
|
233
|
+
}
|
|
196
234
|
return found?.client ?? null;
|
|
197
235
|
})
|
|
198
236
|
.catch((err) => {
|
|
199
|
-
|
|
237
|
+
if (clientPromise === request)
|
|
238
|
+
lastFailure = err instanceof Error ? err.message : String(err);
|
|
200
239
|
console.warn("[opencode-codex-memory] registered OpenCode service unavailable:", err);
|
|
201
240
|
return null;
|
|
202
241
|
});
|
|
203
242
|
clientPromise = request;
|
|
204
243
|
const result = await request;
|
|
205
|
-
if (!result)
|
|
244
|
+
if (!result && clientPromise === request)
|
|
206
245
|
clientPromise = null;
|
|
207
246
|
return result;
|
|
208
247
|
}
|
package/dist/src/v2/shim.d.ts
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* the V1 shutdown/liveness logic keeps working across hosts.
|
|
19
19
|
* - config.get → public service config documents adapted for the V1 resolver;
|
|
20
20
|
* callers fall back to session defaults if the service is unavailable.
|
|
21
|
-
* - provider.list →
|
|
21
|
+
* - provider.list → model.list adapted to the V1 catalog shape for
|
|
22
22
|
* reasoning-variant mapping.
|
|
23
23
|
* - mcp.status → mcp.list adapted to the V1 status map.
|
|
24
24
|
*
|
|
@@ -49,7 +49,7 @@ export declare function adaptV2Messages(msgs: unknown): Array<{
|
|
|
49
49
|
};
|
|
50
50
|
parts?: unknown[];
|
|
51
51
|
}>;
|
|
52
|
-
/** V2 catalog.model.list → V1 provider-list shape
|
|
52
|
+
/** V2 model.list (legacy catalog.model.list) → V1 provider-list shape. */
|
|
53
53
|
export declare function adaptProviderCatalog(v2: unknown): unknown;
|
|
54
54
|
/** V2 mcp.list → V1 mcp.status map shape. */
|
|
55
55
|
export declare function adaptMcpStatus(v2: unknown): unknown;
|
package/dist/src/v2/shim.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { memoryRoot } from "../paths.js";
|
|
2
2
|
import { consolidationPermissions } from "./agents.js";
|
|
3
|
-
import { invalidateOwnService, lastServiceFailure, ownServiceClient } from "./service.js";
|
|
3
|
+
import { invalidateOwnService, lastServiceFailure, ownServiceClient, serviceRequest } from "./service.js";
|
|
4
4
|
let v2ctx = null;
|
|
5
5
|
export function setV2Context(ctx) {
|
|
6
6
|
v2ctx = ctx;
|
|
@@ -33,7 +33,7 @@ async function sessionGoneOnService(client, sessionID) {
|
|
|
33
33
|
if (typeof client.session.get !== "function")
|
|
34
34
|
return false;
|
|
35
35
|
try {
|
|
36
|
-
const info = await client.session.get({ sessionID });
|
|
36
|
+
const info = await serviceRequest(client, () => client.session.get({ sessionID }));
|
|
37
37
|
if (info?.error && isNotFoundError(info.error)) {
|
|
38
38
|
return true;
|
|
39
39
|
}
|
|
@@ -205,7 +205,7 @@ export function adaptV2Messages(msgs) {
|
|
|
205
205
|
}
|
|
206
206
|
return rows;
|
|
207
207
|
}
|
|
208
|
-
/** V2 catalog.model.list → V1 provider-list shape
|
|
208
|
+
/** V2 model.list (legacy catalog.model.list) → V1 provider-list shape. */
|
|
209
209
|
export function adaptProviderCatalog(v2) {
|
|
210
210
|
const items = und(v2);
|
|
211
211
|
const list = Array.isArray(items) ? items : items?.data ?? [];
|
|
@@ -214,7 +214,9 @@ export function adaptProviderCatalog(v2) {
|
|
|
214
214
|
if (!m || typeof m !== "object")
|
|
215
215
|
continue;
|
|
216
216
|
const providerID = m.providerID;
|
|
217
|
-
|
|
217
|
+
// id is the selectable OpenCode alias; modelID can be a different provider
|
|
218
|
+
// wire name. Legacy catalogs exposed only modelID.
|
|
219
|
+
const modelID = m.id ?? m.modelID;
|
|
218
220
|
if (typeof providerID !== "string" || typeof modelID !== "string")
|
|
219
221
|
continue;
|
|
220
222
|
if (!providers.has(providerID))
|
|
@@ -226,7 +228,7 @@ export function adaptProviderCatalog(v2) {
|
|
|
226
228
|
}
|
|
227
229
|
}
|
|
228
230
|
;
|
|
229
|
-
providers.get(providerID)[modelID] = { variants };
|
|
231
|
+
providers.get(providerID)[modelID] = { ...(m.variants !== undefined ? { variants } : {}) };
|
|
230
232
|
}
|
|
231
233
|
return { all: [...providers.entries()].map(([id, models]) => ({ id, models })) };
|
|
232
234
|
}
|
|
@@ -264,6 +266,60 @@ function responseNextCursor(response) {
|
|
|
264
266
|
const next = direct ?? payload?.cursor?.next;
|
|
265
267
|
return typeof next === "string" && next.length > 0 ? next : undefined;
|
|
266
268
|
}
|
|
269
|
+
/** Read durable messages in source order, including terminal errors/idle rows. */
|
|
270
|
+
async function loadV2Messages(sessionID, context, signal) {
|
|
271
|
+
const client = await ownServiceClient();
|
|
272
|
+
if (typeof client?.message?.list === "function") {
|
|
273
|
+
const messages = [];
|
|
274
|
+
const seenCursors = new Set();
|
|
275
|
+
let cursor;
|
|
276
|
+
while (true) {
|
|
277
|
+
const response = await serviceRequest(client, () => client.message.list(cursor ? { sessionID, cursor } : { sessionID, order: "asc" }, signal ? { signal } : undefined));
|
|
278
|
+
const rows = responseRows(response);
|
|
279
|
+
if (!rows)
|
|
280
|
+
throw new Error("registered service returned an invalid message list");
|
|
281
|
+
messages.push(...rows);
|
|
282
|
+
const next = responseNextCursor(response);
|
|
283
|
+
if (!next)
|
|
284
|
+
return messages;
|
|
285
|
+
if (seenCursors.has(next))
|
|
286
|
+
throw new Error("registered service repeated a message cursor");
|
|
287
|
+
seenCursors.add(next);
|
|
288
|
+
cursor = next;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
const raw = await (context ?? ctx()).session.context({ sessionID });
|
|
292
|
+
const rows = responseRows(raw);
|
|
293
|
+
if (!rows)
|
|
294
|
+
throw new Error("session context returned an invalid message list");
|
|
295
|
+
return rows;
|
|
296
|
+
}
|
|
297
|
+
function completedPromptResponse(rows, promptID) {
|
|
298
|
+
const boundary = typeof promptID === "string" ? rows.findIndex((m) => m?.id === promptID && m.type === "user") : -1;
|
|
299
|
+
if (boundary < 0)
|
|
300
|
+
throw new Error("submitted prompt missing from consolidation transcript");
|
|
301
|
+
const turn = rows.slice(boundary + 1);
|
|
302
|
+
const nextUser = turn.findIndex((m) => m?.type === "user");
|
|
303
|
+
const messages = nextUser < 0 ? turn : turn.slice(0, nextUser);
|
|
304
|
+
const assistant = messages.findLast((m) => m?.type === "assistant");
|
|
305
|
+
if (!assistant)
|
|
306
|
+
throw new Error("no assistant reply after consolidation wait");
|
|
307
|
+
if (assistant.error) {
|
|
308
|
+
// V1 runPrompt recognizes info.error, including its quota status code.
|
|
309
|
+
const error = assistant.error;
|
|
310
|
+
return { data: { info: { error: {
|
|
311
|
+
name: error.type ?? error.name,
|
|
312
|
+
data: { message: error.message ?? error.data?.message, statusCode: error.status ?? error.statusCode ?? error.data?.statusCode },
|
|
313
|
+
} }, parts: [] } };
|
|
314
|
+
}
|
|
315
|
+
const idle = messages.findLast((m) => m?.type === "idle");
|
|
316
|
+
if (idle && idle.outcome !== "succeeded")
|
|
317
|
+
throw new Error(`consolidation ${idle.outcome} after session.wait`);
|
|
318
|
+
if (!assistant.time?.completed || !["stop", "length", "content-filter"].includes(assistant.finish)) {
|
|
319
|
+
throw new Error(`consolidation turn incomplete after session.wait (${assistant.finish ?? "no finish"})`);
|
|
320
|
+
}
|
|
321
|
+
return { data: { info: {}, parts: [{ type: "text", text: joinTextParts(assistant.content) }] } };
|
|
322
|
+
}
|
|
267
323
|
function adaptV2SessionRow(row) {
|
|
268
324
|
if (!row || typeof row !== "object")
|
|
269
325
|
return row;
|
|
@@ -303,7 +359,7 @@ async function v2promptWithWait(sessionID, body, signal) {
|
|
|
303
359
|
throw new Error("sub-agent prompt cancelled");
|
|
304
360
|
const publicClient = await ownServiceClient();
|
|
305
361
|
if (typeof publicClient?.generate?.text === "function") {
|
|
306
|
-
const gen = await publicClient.generate.text(payload, signal ? { signal } : undefined);
|
|
362
|
+
const gen = await serviceRequest(publicClient, () => publicClient.generate.text(payload, signal ? { signal } : undefined));
|
|
307
363
|
const outText = typeof gen?.text === "string" ? gen.text : JSON.stringify(gen);
|
|
308
364
|
return { data: { parts: [{ type: "text", text: outText }] } };
|
|
309
365
|
}
|
|
@@ -358,7 +414,9 @@ async function v2promptWithWait(sessionID, body, signal) {
|
|
|
358
414
|
else {
|
|
359
415
|
await waitP;
|
|
360
416
|
}
|
|
361
|
-
|
|
417
|
+
// wait means idle, not successful. Codex requires Completed before phase 2
|
|
418
|
+
// may validate artifacts and reset the last-successful workspace baseline.
|
|
419
|
+
return completedPromptResponse(await loadV2Messages(sessionID, c, signal), und(posted)?.id);
|
|
362
420
|
}
|
|
363
421
|
/** Build the V1-shaped client. Passed to setPluginInput() by V2 setup(). */
|
|
364
422
|
export function buildV1ClientShim() {
|
|
@@ -418,7 +476,7 @@ export function buildV1ClientShim() {
|
|
|
418
476
|
}
|
|
419
477
|
const client = await ownServiceClient();
|
|
420
478
|
if (client && typeof client.session.list === "function") {
|
|
421
|
-
return paginateSessionList((input) => client.session.list(input), limit, cursor, search);
|
|
479
|
+
return paginateSessionList((input) => serviceRequest(client, () => client.session.list(input)), limit, cursor, search);
|
|
422
480
|
}
|
|
423
481
|
if (client)
|
|
424
482
|
throw new Error("registered service does not support session.list");
|
|
@@ -463,30 +521,7 @@ export function buildV1ClientShim() {
|
|
|
463
521
|
try {
|
|
464
522
|
if (isReleasedSubSession(opts.path.id))
|
|
465
523
|
throw Object.assign(new Error("SessionNotFound"), { _tag: "SessionNotFoundError" });
|
|
466
|
-
|
|
467
|
-
if (typeof client?.message?.list === "function") {
|
|
468
|
-
const messages = [];
|
|
469
|
-
const seenCursors = new Set();
|
|
470
|
-
let cursor;
|
|
471
|
-
while (true) {
|
|
472
|
-
const response = await client.message.list(cursor ? { sessionID: opts.path.id, cursor } : { sessionID: opts.path.id, order: "asc" });
|
|
473
|
-
const rows = responseRows(response);
|
|
474
|
-
if (!rows)
|
|
475
|
-
throw new Error("registered service returned an invalid message list");
|
|
476
|
-
messages.push(...rows);
|
|
477
|
-
const next = responseNextCursor(response);
|
|
478
|
-
if (!next || seenCursors.has(next))
|
|
479
|
-
break;
|
|
480
|
-
seenCursors.add(next);
|
|
481
|
-
cursor = next;
|
|
482
|
-
}
|
|
483
|
-
return { data: adaptV2Messages(messages) };
|
|
484
|
-
}
|
|
485
|
-
const raw = await ctx().session.context({
|
|
486
|
-
sessionID: opts.path.id,
|
|
487
|
-
});
|
|
488
|
-
const rows = Array.isArray(raw) ? raw : responseRows(raw) ?? [];
|
|
489
|
-
return { data: adaptV2Messages(rows) };
|
|
524
|
+
return { data: adaptV2Messages(await loadV2Messages(opts.path.id)) };
|
|
490
525
|
}
|
|
491
526
|
catch (e) {
|
|
492
527
|
return { error: e };
|
|
@@ -504,7 +539,7 @@ export function buildV1ClientShim() {
|
|
|
504
539
|
const client = await serviceOrThrow();
|
|
505
540
|
if (typeof client.session.remove !== "function")
|
|
506
541
|
throw new Error("registered service does not support session.remove");
|
|
507
|
-
const result = await client.session.remove({ sessionID: opts.path.id }, opts.signal ? { signal: opts.signal } : undefined);
|
|
542
|
+
const result = await serviceRequest(client, () => client.session.remove({ sessionID: opts.path.id }, opts.signal ? { signal: opts.signal } : undefined));
|
|
508
543
|
if (result?.error)
|
|
509
544
|
throw result.error;
|
|
510
545
|
if (await sessionGoneOnService(client, opts.path.id)) {
|
|
@@ -530,7 +565,7 @@ export function buildV1ClientShim() {
|
|
|
530
565
|
try {
|
|
531
566
|
const client = await ownServiceClient();
|
|
532
567
|
if (client?.session?.get) {
|
|
533
|
-
const info = await client.session.get({ sessionID: opts.path.id });
|
|
568
|
+
const info = await serviceRequest(client, () => client.session.get({ sessionID: opts.path.id }));
|
|
534
569
|
if (info?.error && isNotFoundError(info.error)) {
|
|
535
570
|
markReleased(opts.path.id);
|
|
536
571
|
return {};
|
|
@@ -563,7 +598,7 @@ export function buildV1ClientShim() {
|
|
|
563
598
|
const client = await ownServiceClient();
|
|
564
599
|
if (client?.session?.get) {
|
|
565
600
|
try {
|
|
566
|
-
const info = und(await client.session.get({ sessionID: opts.path.id }));
|
|
601
|
+
const info = und(await serviceRequest(client, () => client.session.get({ sessionID: opts.path.id })));
|
|
567
602
|
return { data: info };
|
|
568
603
|
}
|
|
569
604
|
catch (e) {
|
|
@@ -588,7 +623,7 @@ export function buildV1ClientShim() {
|
|
|
588
623
|
const client = await serviceOrThrow();
|
|
589
624
|
if (typeof client.session.interrupt !== "function")
|
|
590
625
|
throw new Error("registered service does not support session.interrupt");
|
|
591
|
-
const result = await client.session.interrupt({ sessionID: opts.path.id });
|
|
626
|
+
const result = await serviceRequest(client, () => client.session.interrupt({ sessionID: opts.path.id }));
|
|
592
627
|
if (!result?.error)
|
|
593
628
|
return {};
|
|
594
629
|
}
|
|
@@ -608,7 +643,7 @@ export function buildV1ClientShim() {
|
|
|
608
643
|
get: async () => {
|
|
609
644
|
try {
|
|
610
645
|
const client = await serviceOrThrow();
|
|
611
|
-
const response = await client.config?.get({ location: { directory: ctx().location.directory } });
|
|
646
|
+
const response = await serviceRequest(client, async () => client.config?.get({ location: { directory: ctx().location.directory } }));
|
|
612
647
|
const documents = und(response);
|
|
613
648
|
const candidates = Array.isArray(documents) ? documents : documents?.type === "document" ? [documents] : [];
|
|
614
649
|
let info = {};
|
|
@@ -639,7 +674,11 @@ export function buildV1ClientShim() {
|
|
|
639
674
|
const provider = {
|
|
640
675
|
list: async () => {
|
|
641
676
|
try {
|
|
642
|
-
const
|
|
677
|
+
const c = ctx();
|
|
678
|
+
const models = c.model ?? c.catalog?.model;
|
|
679
|
+
if (typeof models?.list !== "function")
|
|
680
|
+
throw new Error("host does not support model.list");
|
|
681
|
+
const res = await models.list();
|
|
643
682
|
return { data: adaptProviderCatalog(res) };
|
|
644
683
|
}
|
|
645
684
|
catch (e) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-codex-memory",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "Persistent memory plugin for opencode — ports codex's two-phase memory system (extraction → consolidation → injection → citation feedback)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/src/index.js",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"live:e2e": "bun scripts/live-e2e.ts",
|
|
50
50
|
"prepack": "npm run build && npm run smoke",
|
|
51
51
|
"test": "bun test",
|
|
52
|
-
"typecheck": "tsc --noEmit"
|
|
52
|
+
"typecheck": "tsc --noEmit -p tsconfig.typecheck.json"
|
|
53
53
|
},
|
|
54
54
|
"keywords": [
|
|
55
55
|
"opencode",
|