@joe-broadhead/opencode-mem 0.8.1 → 0.8.2

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 CHANGED
@@ -3,6 +3,71 @@
3
3
  The format follows Keep a Changelog 1.1.0: one `## [x.y.z] - date` section per
4
4
  release.
5
5
 
6
+ ## [0.8.2] - 2026-11-06
7
+
8
+ A Jelly token per chat, and no fallback for a speaker with no linked account
9
+ (coordinator's decision D30; Jelly's resource-token contract v1.3 §6 and §7).
10
+ Not published yet: it is published from its own `v0.8.2` tag by
11
+ `.github/workflows/release.yml`.
12
+
13
+ ### Changed
14
+
15
+ - **A token per session.** Inside Jelly the plugin asks
16
+ `token("memory", { session })` with the OpenCode session of the work, so on a
17
+ Jelly host with members each person speaking to a shared agent is remembered
18
+ as themselves. A captured turn, a tool call (`context.sessionID`), a command,
19
+ the pinned block, the compaction checkpoint and the replay of a spooled entry
20
+ each use their own session's token (`asSession` in `src/credentials.js`).
21
+ Tokens are cached per session until 60 s before they expire, with one ask in
22
+ flight per session, and a `401` re-asks once for that session only. The cache
23
+ holds at most 64 sessions (least recently used first out) and drops a session
24
+ when OpenCode deletes it; `session.deleted` is read also with
25
+ `capture: false`. Work that belongs to no session (the skill mirror,
26
+ Memory's views, start-up) asks `token("memory")` as before.
27
+ - **Asked again at each user turn.** A second person can speak in a session
28
+ someone else started, so each new user message (the `prompt` hook, which is
29
+ now registered also with `bootstrap: false`, and the admission event) drops
30
+ the session's token and refusal hold; the turn's first memory call asks
31
+ again. A turn superseded by a newer message is still captured with its own
32
+ token. A turn with no user message (a wake, a routine) keeps the cached
33
+ token. A spooled entry records the account its token named
34
+ (`credentialSubject`) and waits while its session's token names someone
35
+ else.
36
+ - **No fallback for an unlinked speaker.** When Jelly refuses a session with
37
+ `not_enrolled` and the detail `not_signed_in` (the person speaking has not
38
+ linked a Jelly account on this host), that session uses no credential: not
39
+ the pasted key, which belongs to whoever pasted it, and not another session's
40
+ token. Its turns are neither captured nor spooled, the context hook adds
41
+ nothing, and every tool and command answers "Memory isn't available in this
42
+ chat because the person speaking hasn't linked their Jelly account on this
43
+ host." The refusal is held 30 s per session; other sessions are unaffected. A
44
+ request that meets it mid-flight fails with `MEMORY_NOT_LINKED`. Other
45
+ refusals behave as in 0.8.1, `access_denied` included.
46
+ - **The spool keeps an entry's identity.** Each entry records
47
+ `credentialSession`, the session it was written in, and is replayed as that
48
+ session whichever session's flush sends it, so one person's turn is never
49
+ sent with another's token. An entry whose session's speaker is unlinked is
50
+ deleted, and the log names the file, never the content. Entries from 0.8.1
51
+ replay as their turn's session, or with no session. `flushSpool` reports
52
+ `dropped` when it deleted one.
53
+ - **Unchanged:** stock OpenCode (the `token` option, `MEMORY_TOKEN`, then the
54
+ pasted key); an accessor that ignores `session`; and Jelly 0.3.2, whose
55
+ accessor refuses `{ session }` as `invalid_target` with the detail
56
+ `invalid_cnf_jwk`: the plugin then asks as before, one token for the engine.
57
+ An accessor that throws on the option is handled as any other throw.
58
+ - The accepted risk is restated: a session that falls back writes as the
59
+ pasted key's user whoever speaks in it; an unlinked speaker never does, as
60
+ long as Jelly passes the refusal's `detail` through
61
+ ([README](README.md#running-inside-jelly)).
62
+
63
+ ### Added
64
+
65
+ - `test/session-tokens.test.js`: two sessions with two speakers, the unlinked
66
+ speaker, the hold per session, the bound and the deletion, the spool, a 401
67
+ per session, stock OpenCode, both shapes of a Jelly 0.3.2 accessor, and a
68
+ new speaker in the same session (A then B, an unlinked B after A, A after an
69
+ unlinked B at once, a superseded turn, the spool waiting for its speaker).
70
+
6
71
  ## [0.8.1] - 2026-11-06
7
72
 
8
73
  Memory follows Jelly's plugin authors' standard, and forgetting asks first. Not
package/README.md CHANGED
@@ -175,23 +175,41 @@ plugin, which then uses the pasted key.
175
175
  2. Jelly's identity accessor, `globalThis[Symbol.for("jelly.identity")]`, when
176
176
  its `resources()` lists `memory`: the host is signed in to a Jelly account
177
177
  whose Jelly ID offers `memory`, and the agent was given this plugin. The
178
- plugin asks `token("memory")` for a ten-minute token, keeps it in memory
178
+ plugin asks for a ten-minute token **per chat** (below), keeps it in memory
179
179
  until 60 s before it expires, and asks again once when the gateway answers
180
180
  `401`;
181
181
  3. the **Memory key** setting: the key pasted from Memory's `/account`
182
182
  page, read with
183
183
  `globalThis[Symbol.for("jelly.plugin-secrets")].get("@joe-broadhead/opencode-mem", "token")`.
184
184
 
185
+ **A token per chat (0.8.2).** On a Jelly host with members, several people
186
+ can talk to one agent, and a Jelly token names one person. So the plugin asks
187
+ `token("memory", { session })` with the OpenCode session of the work: a
188
+ captured turn, a tool call, the pinned block, and the replay of a spooled entry
189
+ each use the token of the session they belong to, which names the person
190
+ speaking there. A second person can speak in a chat someone else started, so
191
+ the token is asked for again at each new user message, and the previous turn
192
+ is still captured with its own speaker's token; a spooled turn is replayed only
193
+ while the chat's token names the person who spoke it. A turn with no user
194
+ message (a wake, a routine) keeps the cached token. Tokens are kept per session, for at most 64 sessions (the least
195
+ recently used goes first), and a session's is dropped when the session is
196
+ deleted. Work that belongs to no chat (the skill mirror, Memory's views) asks
197
+ `token("memory")` as before, which Jelly answers with the agent owner's token
198
+ while the agent is private. A Jelly older than members (0.3.2) refuses the
199
+ `session` option; the plugin then asks as before, one token for the agent,
200
+ which on such a host is its owner's.
201
+
185
202
  **When Jelly refuses the token.** `token("memory")` rejects with a code. Jelly's
186
203
  host maps Jelly ID's `400` to `invalid_target`, `401` to `not_enrolled`, `403`
187
204
  to `access_denied`, and everything else, a `503` included, to `unavailable`, so
188
205
  the plugin cannot tell an outage from Jelly ID turning memory off. The host
189
- holds each refusal for 30 s, and so does the plugin: Jelly is not asked again
190
- until the 30 s pass.
206
+ holds each refusal for 30 s, and so does the plugin, per chat: Jelly is not
207
+ asked again for that chat until the 30 s pass.
191
208
 
192
209
  | Code | What the request does |
193
210
  |---|---|
194
- | `invalid_target`, `not_enrolled`, `unavailable` | Uses the pasted key, when one is saved. With no key, it fails with "this agent's Jelly sign-in can't be used for memory: … (`<code>`), and no memory key is saved in the plugin's settings"; a finished turn is spooled for later |
211
+ | `not_enrolled` with the detail `not_signed_in` | The person speaking in this chat has not linked a Jelly account on this host. Memory is off for this chat only: no credential is used, not the pasted key and not another chat's token; nothing is captured or spooled; each tool and command answers "Memory isn't available in this chat because the person speaking hasn't linked their Jelly account on this host." Other chats are not affected |
212
+ | `invalid_target`, `not_enrolled` (no such detail), `unavailable` | Uses the pasted key, when one is saved. With no key, it fails with "this agent's Jelly sign-in can't be used for memory: … (`<code>`), and no memory key is saved in the plugin's settings"; a finished turn is spooled for later |
195
213
  | `access_denied` | Fails: "the Jelly account is disabled or marked for deletion (access_denied); a saved memory key is not used in its place". No fallback |
196
214
 
197
215
  Why no fallback on `access_denied`: Jelly says the account behind this agent is
@@ -205,10 +223,15 @@ Jelly token or not at all, and a refused pasted key is not retried.
205
223
  asked again within 30 s)`, and the log has one warning per refusal (its code,
206
224
  never a token).
207
225
 
208
- **Accepted risk.** If a person's Jelly sign-in and pasted key belong to two
209
- different memory users, a request that falls back writes as the key's user,
210
- into that user's memory, until Jelly answers again. Paste a key from the same
211
- account you sign in to Jelly with.
226
+ **Accepted risk.** The pasted key belongs to whoever pasted it. A chat whose
227
+ token Jelly refuses with a code that falls back (`invalid_target`,
228
+ `unavailable`, or `not_enrolled` without `not_signed_in`) writes as the key's
229
+ memory user, into that user's memory, whoever is speaking in it, until Jelly
230
+ answers again. Paste a key from the same account you sign in to Jelly with, and
231
+ on an agent shared with others prefer no key at all. A speaker Jelly reports as
232
+ unlinked (`not_signed_in`) is never written as the key's user. This relies on
233
+ Jelly passing the refusal's `detail` to the plugin: a Jelly whose accessor drops
234
+ it makes that refusal a plain `not_enrolled`, which falls back.
212
235
 
213
236
  **Gateway origin:** the **Memory address** setting (`controlURL`), else the
214
237
  `url` of the identity accessor's `memory` resource, during a fallback too.
package/SECURITY.md CHANGED
@@ -54,7 +54,7 @@ This is the summary.
54
54
  | Credential | Lives in | Purpose |
55
55
  |---|---|---|
56
56
  | Better Auth API key | Client | Authenticates one user to the gateway; expires after `AUTH_KEY_TTL_DAYS` (90); revocable on `/account` or with `deploy/auth/scripts/revoke-user-keys.mjs` |
57
- | Jelly ID resource token | Client (a Jelly host, in memory only) | Authenticates the host's owner to the gateway for ten minutes; verified with the issuer's Ed25519 keys, audience-bound; at the gateway a refused one never falls back to another credential kind ([docs/design/adr-personal-containers.md](docs/design/adr-personal-containers.md)). The plugin's own fallback to a pasted key is a separate request with that key ([README](README.md#running-inside-jelly)) |
57
+ | Jelly ID resource token | Client (a Jelly host, in memory only) | Authenticates one person to the gateway for ten minutes: the host's owner, or (Jelly 0.3.3 members) the person speaking in the OpenCode session the plugin asked for, a token per session; verified with the issuer's Ed25519 keys, audience-bound; at the gateway a refused one never falls back to another credential kind ([docs/design/adr-personal-containers.md](docs/design/adr-personal-containers.md)). The plugin's own fallback to a pasted key is a separate request with that key, never made for a speaker Jelly reports as unlinked (`not_signed_in`) ([README](README.md#running-inside-jelly)) |
58
58
  | `CONTROL_TOKEN` | Gateway | Authenticates the gateway to control; must equal `CONTROL_SERVICE_TOKEN` |
59
59
  | `CONTROL_SERVICE_TOKEN` | Control service | Verifies the gateway's `x-control-user` assertion; never grants admin |
60
60
  | `CONTROL_ADMIN_TOKEN` | Operator/infrastructure, the exporter, the `cell-health` job | Cell and placement administration; separate from the service token |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joe-broadhead/opencode-mem",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "type": "module",
5
5
  "description": "Durable private and shared-space memory for OpenCode agents",
6
6
  "license": "MIT",
package/src/commands.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { asSession } from "./credentials.js"
1
2
  import { describeBootstrap, describeSpool, errorMessage, oneLine } from "./util.js"
2
3
 
3
4
  /**
@@ -71,11 +72,13 @@ export async function registerCommands(ctx, runtime) {
71
72
  add: (definition) =>
72
73
  target.add({
73
74
  ...definition,
74
- execute: async (input = {}) => {
75
- const reason = runtime.unavailable?.() ?? ""
76
- if (reason) return reply(input?.sessionID, reason)
77
- return definition.execute(input)
78
- },
75
+ // As the command's session: its token, and its speaker's sentence.
76
+ execute: (input = {}) =>
77
+ asSession(input?.sessionID, async () => {
78
+ const reason = (runtime.availability ? await runtime.availability() : runtime.unavailable?.()) ?? ""
79
+ if (reason) return reply(input?.sessionID, reason)
80
+ return definition.execute(input)
81
+ }),
79
82
  }),
80
83
  }
81
84
  editor.add({