@joe-broadhead/opencode-mem 0.13.0 → 0.13.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/CHANGELOG.md CHANGED
@@ -3,6 +3,77 @@
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.13.1] - 2026-11-18
7
+
8
+ ### Added
9
+
10
+ - **The console can turn on a source an installed plugin declares.** The plugin consent path had never run end to
11
+ end: the console had no button that made a first plugin request or a first consent, and it listed no plugin request.
12
+ - **Turn on…** asks the person's collector to report which account the source is signed in to, and the declaration
13
+ it read from the plugin's installed package. Nothing is read before that, and nothing is stored.
14
+ - **Confirm <owner>…** shows the declaration the person consents to before they consent: the plugin and its
15
+ package, the source, the reported account and the owner, whether it reads privately, the cost, and the scope with
16
+ its description and the options the collector offered. The consent is sent with exactly the reported owner and
17
+ digest. When the declaration changed after the collector reported it, the page asks the collector again instead
18
+ of confirming a declaration nobody can see, and a consent that reaches records with a declaration that moved is
19
+ answered in records' own words.
20
+ - **A request in progress says where it stands:** waiting for the collector, an account to confirm, or why the
21
+ collector could not read it, in one line with its code, and when it tries again.
22
+ - **A binding made before its plugin declared** (for example `github.activity`, `granola.meetings` or
23
+ `linear.activity`) says "Not collecting: needs your confirmation", with Turn on…. The consent takes that row over,
24
+ so nothing needs unbinding first. When the reported account differs from the old row, as `linear.activity` does
25
+ with `default`, the old row is offered Remove and says that it holds no events.
26
+ - **The Plugins section says what is true now:** a source can be turned on, and nothing is collected until the
27
+ person confirms the declaration that their collector reported.
28
+ - **An account that contains `/`** (Linear reports `<workspace id>/<email>`) is shown as it is and posted in the
29
+ body; no path is built from it, and the id the page keeps in Activity is encoded.
30
+ - **The dialog lists every option the consent carries**, in a list that scrolls when it is long, and the consent
31
+ sends exactly those options: nothing is consented that the person did not see, and nothing shown is left out.
32
+ - **An account or an owner label that holds a Unicode format character** (a right-to-left override, a zero-width
33
+ space) shows it as a visible escape such as `\u202E`, so one row never reorders or disguises another.
34
+ - **Cancel clears a plugin request in any state**, after a preview that names the source and the requested account
35
+ (`plugins.cancel`). Thirty-two stuck requests would otherwise block every new one, and the console had no way to
36
+ clear one; the page says that a failed request stops counting against the limit and is removed after 7 days, and
37
+ that one left unconfirmed is removed after 30.
38
+
39
+ A request reaches "needs your confirmation" on the collector's next run: every 30 minutes while OpenCode runs, or
40
+ when the person asks.
41
+
42
+ ### Fixed
43
+
44
+ - **A plugin source can be turned on again.** The plugin consent path had never run end to end in any release: no
45
+ collector called `plugins.probe`, so a `plugins.request` row stayed `requested` for ever, and `plugins.consent`
46
+ refuses a request that was never reported. Nothing was collected from `github.activity`, `granola.meetings` or
47
+ `linear.activity`, and the console had nothing to confirm.
48
+ - The collector answers the person's plugin requests: each run reads `plugins.list` and probes the requests that are
49
+ due, through the contract's own `probe` in the binding's own session, and reports with
50
+ `plugins.probe {plugin_id, source, account, owner, reported_account, digest}`. A failure is reported with no owner
51
+ and the source's own words, and the store's back-off counts it (`failures`, `retry_at`). A request for a source no
52
+ installed plugin declares is reported, never thrown.
53
+ - `mem_spaces sources bind` asks with `plugins.request`, naming the plugin, when an installed plugin declares the
54
+ source; a previous contract's name keeps `sources.request`. Its answer names Memory's console, Sources, and the
55
+ next step there.
56
+ - `sources.request` and `sources.bind` **refuse, never reroute,** a source an installed plugin declares: 409
57
+ `plugin_consent_required`, with the next step "Turn it on in Memory's console, Sources". A rerouted call would
58
+ record a consent the person was never shown, with no `private`, cost or scope. Existing `sources` rows are left
59
+ alone.
60
+ - **No content is read from a declared source without a consent.** With no consent on, the collector read the page and
61
+ ingest refused it, on every run: content was read that nobody consented to, and the binding failed for ever. It now
62
+ reads nothing, makes no session, reports `needsConsent` with the person's next step, and is never turned failing. A
63
+ binding made under a previous contract's name is read as before.
64
+ - **A binding is reported paused only when the store paused it.** `plugins.pause` answers `{ paused: 0 }` without a
65
+ consent, and the collector reported `paused` anyway: Linear's binding looked stopped while it stayed enabled and
66
+ failed on every run. The store's own count decides, and a pause that made none keeps the real failure.
67
+ - **The contract's account is accepted, a `/` included.** Memory's grammar was narrower than the contract's
68
+ `ACCOUNT_PATTERN`, so `linear.activity`'s own account - `<workspace uuid>/<user email>` - was dropped: the collector
69
+ omitted `reported_account`, records kept the `default` the person asked with, and every Linear page was refused with
70
+ `ACCOUNT_MISMATCH`. The four copies now hold the contract's grammar within Memory's cap of 128. Where an account is a
71
+ name - a plugin's MCP server, `plaud-{account}` - the narrow rule stays, and an account with a slash keeps the plain
72
+ namespace.
73
+ - A raw-byte check in `records/test` no longer reads a random value as a leak: a fingerprint key that ended `84` beside
74
+ a date starting `2026` made `842026`, which matched `8420` (CI run 44280387202). The values that are random by design
75
+ are removed before the match, and nothing else is.
76
+
6
77
  ## [0.13.0] - 2026-11-18
7
78
 
8
79
  ### Changed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joe-broadhead/opencode-mem",
3
- "version": "0.13.0",
3
+ "version": "0.13.1",
4
4
  "type": "module",
5
5
  "description": "Durable private and shared-space memory for OpenCode agents",
6
6
  "license": "MIT",
@@ -1,7 +1,7 @@
1
1
  import fs from "node:fs"
2
2
  import os from "node:os"
3
3
  import path from "node:path"
4
- import { DEFAULT_ACCOUNT, cadenceMs, collectSessionId, collectSessionRules, collectableSources, createCollector, hostBrokerTransport, hostSourceLister, hostSourceProber, rulesHash } from "./collector.js"
4
+ import { DEFAULT_ACCOUNT, NEEDS_CONSENT, cadenceMs, collectSessionId, collectSessionRules, collectableSources, createCollector, hostBrokerTransport, hostSourceLister, hostSourceProber, rulesHash } from "./collector.js"
5
5
  import { createLease } from "./collector-lock.js"
6
6
  import { knownSources, sourceEntry } from "./sources.js"
7
7
  import { errorMessage, failureText, isPlainObject, oneLine } from "./util.js"
@@ -424,6 +424,19 @@ export function createCollectorService({ ctx, runtime, toolkit, clock = REAL_CLO
424
424
  }
425
425
  const listed = await call("sources.list", {}, where)
426
426
  const sources = listed?.sources ?? []
427
+ // The person's plugin requests, if this records service has plugins at all.
428
+ // A listing that fails costs this run's plugin requests and nothing else: an
429
+ // unknown method (a service older than its plugin) and a 5xx or a timeout are
430
+ // the same here, because 0.13.0 never called this and the six legacy sources
431
+ // must keep collecting (the 0.13.1 review's M).
432
+ const pluginsListed = async () => {
433
+ try {
434
+ return await call("plugins.list", {}, where)
435
+ } catch (error) {
436
+ log?.warn?.("the plugin listing failed; plugin requests wait for the next run", { error: oneLine(errorMessage(error), 200) })
437
+ return null
438
+ }
439
+ }
427
440
  guard()
428
441
  await collector.sync(sources)
429
442
  guard()
@@ -438,6 +451,16 @@ export function createCollectorService({ ctx, runtime, toolkit, clock = REAL_CLO
438
451
  }
439
452
  const probes = active?.probes ?? []
440
453
  await collector.probeRequests({ requests: listed?.requests, only, now: clock.now(), sessionID: rpc, probes, report: (body) => call("sources.report", body, where) })
454
+ // The person's plugin requests, answered the same way (C3): the contract's
455
+ // `probe` learns the account and `plugins.probe` records it for the person
456
+ // to confirm in the console. A records service older than its plugin has no
457
+ // plugins to ask about, and the run carries on. The same answer names every
458
+ // consent, which is what decides whether a declared source may be read (O2).
459
+ const plugins = await pluginsListed()
460
+ if (plugins) {
461
+ guard()
462
+ await collector.probePluginRequests({ requests: plugins.requests, only, now: clock.now(), sessionID: rpc, probes, report: (body) => call("plugins.probe", body, where) })
463
+ }
441
464
  const behind = new Set((Array.isArray(previous?.sources) ? previous.sources : []).filter((row) => row?.more && !row?.error).map((row) => keyOf(row)))
442
465
  const rows = new Map((Array.isArray(sources) ? sources : []).filter(isPlainObject).map((row) => [keyOf(row), row]))
443
466
  await collector.runOnce({
@@ -445,6 +468,12 @@ export function createCollectorService({ ctx, runtime, toolkit, clock = REAL_CLO
445
468
  only,
446
469
  sessionID: rpc,
447
470
  results,
471
+ // A declared source is read only under a consent that is on (O2). The list
472
+ // is the one `plugins.list` answered; when the listing failed - an older
473
+ // service, a 5xx, a timeout - no consent is known, so the empty list skips
474
+ // every declared source and reads only the legacy aliases (the re-check's
475
+ // M1: `null` gated nothing and read content nobody consented to).
476
+ consents: plugins ? plugins.consents : [],
448
477
  due: (binding) => {
449
478
  if (ASKED.has(trigger) || only) return true
450
479
  const key = keyOf(binding)
@@ -500,8 +529,11 @@ export function createCollectorService({ ctx, runtime, toolkit, clock = REAL_CLO
500
529
  if (stopped) return
501
530
  for (const result of results) {
502
531
  if (stopped) return
503
- // Not due, and another machine's binding, are not this run's reports.
504
- if (result.notDue || result.otherHost || result.transient || typeof result.source !== "string") continue
532
+ // Not due, another machine's binding, and one no consent lets this machine
533
+ // read, are not this run's reports. A needs-consent binding is never turned
534
+ // failing (O2): its state is the absence of a consent, and the console
535
+ // shows that from plugins.list.
536
+ if (result.notDue || result.otherHost || result.needsConsent || result.transient || typeof result.source !== "string") continue
505
537
  // `more` travels with the report (review S5): the console's Sources row says
506
538
  // "catching up" from records, so it must know the run left pages behind.
507
539
  // `host` is this machine: the records service shows a binding's failing
@@ -811,6 +843,9 @@ export function describeResult(result) {
811
843
  // state, not the binding's failure, so it is not called stopped and it keeps
812
844
  // the state it had (0.12.4).
813
845
  if (result.transient) return `${oneLine(result.source ?? "?", 40)}:${oneLine(result.account ?? "?", 80)}: ${oneLine(errorMessage(result.error ?? "the plugin's RPC is not available"), 240)}; retry next run`
846
+ // A declared source with no consent is not a failure and not a silence (O2):
847
+ // the line says the state and the person's next step.
848
+ if (result.needsConsent) return `${oneLine(result.source ?? "?", 40)}:${oneLine(result.account ?? "?", 80)}: needs consent, nothing was read (${oneLine(errorMessage(result.reason ?? NEEDS_CONSENT), 240)})`
814
849
  const counts = `${Number(result.accepted) || 0} new, ${Number(result.duplicates) || 0} already had, ${Number(result.refused) || 0} refused, ${Number(result.pages) || 0} page(s)`
815
850
  // A refused event is a real loss — the contract's cursor moves past it — so
816
851
  // the line names the newest one and why, not only how many (DESIGN §2.3.1).
@@ -823,5 +858,5 @@ export function describeResult(result) {
823
858
  // object, and the 0.10.3 gate (A15) caught an answer repeating the placeholder.
824
859
  // The refusal trace is build/0.11’s (fix/source-kinds): a refused event is a
825
860
  // real loss, so the line names the newest one and why.
826
- return `${name}: ${result.error ? `stopped (${reasonText(result, 240)}); ` : ""}${counts}${refused}${result.more ? "; more waits for the next run" : ""}${result.setup ? `; the source says: ${oneLine(errorMessage(result.setup), 240)}` : ""}`
861
+ return `${name}: ${result.error ? `stopped (${reasonText(result, 240)}); ` : ""}${result.pause_none ? "the store paused nothing, so the binding stays enabled; " : ""}${counts}${refused}${result.more ? "; more waits for the next run" : ""}${result.setup ? `; the source says: ${oneLine(errorMessage(result.setup), 240)}` : ""}`
827
862
  }
package/src/collector.js CHANGED
@@ -50,6 +50,12 @@ export const COLLECT_CRON = "*/30 * * * *"
50
50
  export const PAGES_PER_SOURCE = 5
51
51
  /** Events asked of a source per page (contract §4.4). */
52
52
  export const PAGE_LIMIT = 200
53
+ /**
54
+ * What a binding of a declared source stands at when this machine holds no
55
+ * consent for it: a state, with the person's next step, never a failure.
56
+ */
57
+ export const NEEDS_CONSENT = "no plugin consent is on for this source here: nothing was read. Next step: confirm it in Memory's console, Sources."
58
+
53
59
  /** The account a binding without one uses. */
54
60
  export const DEFAULT_ACCOUNT = "default"
55
61
  /** The prefix of the collector's reserved sessions: each binding's is `ses_mem_collect_<source>_<hash>`. */
@@ -560,6 +566,36 @@ export function requestedSources(requests, { only, now = Date.now() } = {}) {
560
566
  return out
561
567
  }
562
568
 
569
+ /**
570
+ * The plugin requests due a probe (the `requests` of the plugin listing): a `requested`
571
+ * one, and a `failed` or `attention` one whose back-off has passed.
572
+ *
573
+ * A `reported` request waits for the person, never for the collector; one that
574
+ * is waiting out its back-off is not asked again before its `retry_at`; and an
575
+ * `attention` request — three failures — has no retry time of its own, so it
576
+ * waits for the person to ask again, as a legacy one does.
577
+ *
578
+ * @param {unknown} requests
579
+ * @param {{ only?: string, now?: number }} [options]
580
+ * @returns {{ plugin_id: string, source: string, account: string }[]}
581
+ */
582
+ export function requestedPlugins(requests, { only, now = Date.now() } = {}) {
583
+ const out = []
584
+ for (const entry of Array.isArray(requests) ? requests : []) {
585
+ if (!isPlainObject(entry)) continue
586
+ const state = String(entry.state ?? "")
587
+ if (state !== "requested" && state !== "failed" && state !== "attention") continue
588
+ if (state !== "requested" && !(entry.retry_at && Date.parse(entry.retry_at) <= now)) continue
589
+ const source = String(entry.source ?? "")
590
+ const account = String(entry.account ?? "") || DEFAULT_ACCOUNT
591
+ const plugin = String(entry.plugin_id ?? "")
592
+ if (!plugin || !isSourceName(source) || !isAccountName(account)) continue
593
+ if (only && source !== only) continue
594
+ out.push({ plugin_id: plugin, source, account })
595
+ }
596
+ return out
597
+ }
598
+
563
599
  /**
564
600
  * A source's `events_list`, called through the host's tools RPC (`ctx.rpc`)
565
601
  * with the registry's RPC id, in the session `sessionFor()` gives; null when
@@ -1042,9 +1078,14 @@ export function createCollector({ scheduler = null, lister = null, prober = null
1042
1078
  * due?: (binding: { source: string, account: string }) => boolean,
1043
1079
  * }} input
1044
1080
  */
1045
- async function runOnce({ sources, only, cursor, ingest, sessionID, results = [], due = () => true, pause = null }) {
1081
+ async function runOnce({ sources, consents = null, only, cursor, ingest, sessionID, results = [], due = () => true, pause = null }) {
1046
1082
  // One broker deadline per tick (N7b): a broker that timed out this run does not cost each later binding.
1047
1083
  lister?.resetBrokerTick?.()
1084
+ // The consent of one binding, when the run was told what the plugin listing answers; null when it was not.
1085
+ const consentFor = (binding) => {
1086
+ if (!Array.isArray(consents)) return null
1087
+ return consents.find((row) => isPlainObject(row) && row.source === binding.source && (row.account || DEFAULT_ACCOUNT) === (binding.account || DEFAULT_ACCOUNT)) ?? false
1088
+ }
1048
1089
  for (const binding of collectableSources(sources, { only })) {
1049
1090
  // Another machine's host-bound binding: not read, not reported, and so
1050
1091
  // never turned failing here (0.12.3). The row says whose it is. The
@@ -1058,6 +1099,19 @@ export function createCollector({ scheduler = null, lister = null, prober = null
1058
1099
  results.push({ ...binding, pages: 0, accepted: 0, duplicates: 0, refused: 0, more: false, notDue: true, everyMinutes: cadenceMs(binding.source) / 60_000, done: true })
1059
1100
  continue
1060
1101
  }
1102
+ // No content is read from a declared source without a consent that is on
1103
+ // (O2 of the collector-binds audit, 0.13.1): the page would be refused at
1104
+ // ingest (`plugin_consent_required`), and reading it first is content read
1105
+ // with nobody's consent. The binding stands at `needsConsent`, which the
1106
+ // console and `mem_spaces` show as a state with its next step, never as a
1107
+ // failure on every run. A binding made under a previous contract's name is
1108
+ // read as before: its alias is the exemption the coordinator kept.
1109
+ // A consent that exists but is not `on` is the store's own answer (its
1110
+ // status), and the read is stopped there with the state it names.
1111
+ if (sourceEntry(binding.source)?.contract === "sources" && consentFor(binding) === false) {
1112
+ results.push({ ...binding, pages: 0, accepted: 0, duplicates: 0, refused: 0, more: false, needsConsent: true, reason: NEEDS_CONSENT, done: true })
1113
+ continue
1114
+ }
1061
1115
  const result = { ...binding, pages: 0, accepted: 0, duplicates: 0, refused: 0, more: false, done: false }
1062
1116
  results.push(result)
1063
1117
  try {
@@ -1096,8 +1150,12 @@ export function createCollector({ scheduler = null, lister = null, prober = null
1096
1150
  result.error = reason
1097
1151
  if (typeof pause === "function") {
1098
1152
  try {
1099
- await pause(binding, reason, "OWNER_CHANGED")
1100
- result.paused = true
1153
+ // The store's own answer decides (O3): a pause it did not make -
1154
+ // there is no consent to pause - leaves the binding enabled, and
1155
+ // says so, rather than a `paused` that nothing paused.
1156
+ const answer = await pause(binding, reason, "OWNER_CHANGED")
1157
+ if (Number(answer?.paused) > 0) result.paused = true
1158
+ else result.pause_none = true
1101
1159
  } catch (error) {
1102
1160
  result.pause_error = oneLine(errorMessage(error), 200)
1103
1161
  }
@@ -1214,7 +1272,7 @@ export function createCollector({ scheduler = null, lister = null, prober = null
1214
1272
  try {
1215
1273
  // An account that is not the bound one says so in the store: the person confirms the right account.
1216
1274
  const needsAccount = failure.code === "ACCOUNT_MISMATCH"
1217
- await pause(
1275
+ const paused = await pause(
1218
1276
  binding,
1219
1277
  changed
1220
1278
  ? "the source changed its declaration or its grant; confirm it again"
@@ -1225,7 +1283,11 @@ export function createCollector({ scheduler = null, lister = null, prober = null
1225
1283
  : failure.message,
1226
1284
  changed ? "DECLARATION_CHANGED" : accessRefused ? "ACCESS_REFUSED" : failure.code,
1227
1285
  )
1228
- result.paused = true
1286
+ // Only a pause the store made is reported (O3): plugins.pause answers
1287
+ // { paused: 0 } when there is no consent to pause, and the binding
1288
+ // then keeps the real failure instead of a state nothing changed.
1289
+ if (Number(paused?.paused) > 0) result.paused = true
1290
+ else result.pause_none = true
1229
1291
  } catch (error) {
1230
1292
  result.pause_error = oneLine(errorMessage(error), 200)
1231
1293
  }
@@ -1269,102 +1331,44 @@ export function createCollector({ scheduler = null, lister = null, prober = null
1269
1331
  */
1270
1332
  async function probeRequests({ requests, only, now = Date.now(), sessionID, report, probes = [] }) {
1271
1333
  for (const asked of requestedSources(requests, { only, now })) {
1272
- const probe = { ...asked, reported: false }
1334
+ const { probe, body } = await answerFor(asked, sessionID)
1273
1335
  probes.push(probe)
1274
- const entry = sourceEntry(asked.source)
1275
- // The declared source this name stands for, when the declaration names one:
1276
- // one declared source is probed under its own id, and a name with several
1277
- // is not guessed between them.
1278
- const resolved = resolveDeclaredSource(asked.source)
1279
- const reading = resolved.entry?.contract === "sources" ? resolved.entry : entry
1280
- const renamed = reading.contract === "sources" && reading.source !== asked.source ? reading.source : null
1281
- // The binding's own session first: when it cannot be made, nothing is read and
1282
- // nothing is reported (it is not the source's failure, so no back-off either).
1283
- let session
1336
+ // No body: the binding's own session could not be made, which is not the
1337
+ // source's failure, so nothing is reported and nothing backs off.
1338
+ if (!body) continue
1339
+ probe.note = body.note ?? null
1284
1340
  try {
1285
- // The declared source a retired name stands for decides the session's rules too: the probe runs in
1286
- // the binding's own session, and that session must allow the probe action the declaration asserts.
1287
- const binding = renamed ? { ...asked, read: reading.source } : asked
1288
- session = typeof sessionID === "function" ? await sessionID(binding) : sessionID
1341
+ await report(body)
1342
+ probe.reported = true
1289
1343
  } catch (error) {
1290
1344
  probe.error = oneLine(errorMessage(error), 300)
1291
- continue
1292
- }
1293
- let body
1294
- try {
1295
- // A declared source has the contract's `probe` (D11); the owner-only
1296
- // `events_list({ limit: 0 })` page is the previous contract's, and only
1297
- // for a plugin that declares no source.
1298
- // **A declared source's probe is not told an account** (0.12.5): the
1299
- // plugin answers the account it is signed in to. Live at 00:43Z on
1300
- // 2026-11-18, Memory named `default`, and github, granola and linear
1301
- // each answered ACCOUNT_MISMATCH, so none of the three could bind. **A
1302
- // request that names an account is that account** (0.12.6): a
1303
- // multi-account plugin is probed as `work` when the person asked for
1304
- // `work`, and its refusal is the answer, never a quiet rebind. A
1305
- // plugin that still refuses a default request is asked once with the
1306
- // account its own structured answer names, and nothing is adopted from
1307
- // unparsed text.
1308
- const ask = (input) => (prober ? prober(reading.source, input, session) : Promise.reject(new Error("this host gives plugins no tools RPC, so a source cannot be probed")))
1309
- const declaredAnswer = async () => {
1310
- const named = asked.account && asked.account !== DEFAULT_ACCOUNT ? asked.account : null
1311
- if (named) return ask({ account: named })
1312
- try {
1313
- return await ask({})
1314
- } catch (error) {
1315
- const suggested = suggestedAccount(error)
1316
- if (!suggested) throw error
1317
- try {
1318
- return await ask({ account: suggested })
1319
- } catch (retry) {
1320
- // A retry that fails keeps the first refusal's reason too: the two
1321
- // say different things (the account, then why it still failed) and
1322
- // the person needs both (0.12.6, the re-review's L).
1323
- const both = new Error(`${oneLine(errorMessage(retry), 300)} (the first attempt said: ${oneLine(errorMessage(error), 300)})`)
1324
- both.code = retry?.code ?? error?.code
1325
- both.next = retry?.next ?? error?.next
1326
- throw both
1327
- }
1328
- }
1329
- }
1330
- const answer = reading.contract === "sources"
1331
- ? await declaredAnswer()
1332
- : await (lister ? lister(asked.source, probeInput(reading, asked.account), session) : Promise.reject(new Error("this host gives plugins no way to call another plugin's events_list")))
1333
- // A name the declaration has replaced says which source binds instead:
1334
- // the store refuses a retired name, so the person needs the one to use.
1335
- const replaced = renamed ? `${asked.source} is the previous contract's name for ${renamed}, which this release binds instead: bind ${renamed} in Memory's console.` : null
1336
- if (answer?.owner?.id) {
1337
- const owner = { id: oneLine(answer.owner.id, 300), label: oneLine(answer.owner.label ?? answer.owner.email ?? answer.owner.id, 300) }
1338
- const setup = answer.setup || reading.setupOptions || null
1339
- body = {
1340
- source: asked.source,
1341
- account: asked.account,
1342
- owner,
1343
- // The account the probe names is the binding's account: the store
1344
- // confirms it, and a page of a declared source always names it
1345
- // (0.12.3). A name Memory cannot hold is not reported.
1346
- ...(isAccountName(answer.account) ? { reported_account: answer.account } : {}),
1347
- // The installed declaration's digest, read from disk: a re-consent records the digest the installed
1348
- // package has now, so jelly never refuses a read made under the old one. Only for the declared id
1349
- // itself: a consent recorded under a retired name never reads that declaration.
1350
- ...(renamed === null && reading.descriptorHash ? { digest: reading.descriptorHash } : {}),
1351
- // The note is the source's or the plugin's own sentence: it is
1352
- // reported to the store (`source_requests.note`) and shown from it,
1353
- // so it is redacted here, where it is written (review F1/F2).
1354
- ...(replaced || setup ? { note: oneLine(errorMessage([replaced, setup].filter(Boolean).join(" ")), 400) } : {}),
1355
- }
1356
- probe.owner = owner
1357
- } else {
1358
- body = { source: asked.source, account: asked.account, note: oneLine(errorMessage(answer?.setup || `${reading.package}'s ${reading.contract === "sources" ? "probe" : "events_list"} named no signed-in account; sign in to it in its own plugin.`), 400) }
1359
- }
1360
- } catch (error) {
1361
- // A refusal keeps its own words, and a failed retry keeps both reasons:
1362
- // the store holds a note of 500 (0.12.6).
1363
- body = { source: asked.source, account: asked.account, note: oneLine(errorMessage(error), 500) }
1364
1345
  }
1346
+ }
1347
+ return probes
1348
+ }
1349
+
1350
+ /**
1351
+ * Answer the person's plugin requests: a declared source a plugin declares,
1352
+ * asked for with `plugins.request`, is probed the same way (C3, the audit's
1353
+ * O1). Without this no request ever reaches `reported`, and `plugins.consent`
1354
+ * refuses a request that was never reported, so no consent could be made.
1355
+ *
1356
+ * The answer is `plugins.probe` (the plugin id, the source, the account asked
1357
+ * for, the owner the probe found, the account it answered and the installed
1358
+ * declaration's digest). A failure is reported the same way with no owner,
1359
+ * and the store's own back-off counts it (`failures`, `retry_at`): this loop
1360
+ * asks again only when the row is due (`requestedPlugins`).
1361
+ *
1362
+ * @param {{ requests: unknown, only?: string, sessionID?: string, report: (input: object) => Promise<unknown>, probes?: object[] }} input
1363
+ */
1364
+ async function probePluginRequests({ requests, only, now = Date.now(), sessionID, report, probes = [] }) {
1365
+ for (const asked of requestedPlugins(requests, { only, now })) {
1366
+ const { probe, body } = await answerFor(asked, sessionID)
1367
+ probes.push(probe)
1368
+ if (!body) continue
1365
1369
  probe.note = body.note ?? null
1366
1370
  try {
1367
- await report(body)
1371
+ await report({ plugin_id: asked.plugin_id, ...body })
1368
1372
  probe.reported = true
1369
1373
  } catch (error) {
1370
1374
  probe.error = oneLine(errorMessage(error), 300)
@@ -1373,6 +1377,116 @@ export function createCollector({ scheduler = null, lister = null, prober = null
1373
1377
  return probes
1374
1378
  }
1375
1379
 
1380
+ /**
1381
+ * One request's answer: the owner the probe found, the account it names, the
1382
+ * installed declaration's digest and a note. `probe` is what the run shows;
1383
+ * `body` is reported by the caller's own method.
1384
+ *
1385
+ * @returns {Promise<{ probe: object, body: object | null }>} `body` is null when no report may be made.
1386
+ */
1387
+ async function answerFor(asked, sessionID) {
1388
+ const probe = { ...asked, reported: false }
1389
+ const entry = sourceEntry(asked.source)
1390
+ // The declared source this name stands for, when the declaration names one:
1391
+ // one declared source is probed under its own id, and a name with several
1392
+ // is not guessed between them.
1393
+ const resolved = resolveDeclaredSource(asked.source)
1394
+ const reading = resolved.entry?.contract === "sources" ? resolved.entry : entry
1395
+ // A request for a source no plugin on this machine declares cannot be
1396
+ // probed: it is reported as a failure, so the person sees why, and the
1397
+ // request is never left waiting forever.
1398
+ if (!reading) {
1399
+ probe.error = oneLine(`this machine declares no source ${asked.source}`, 300)
1400
+ return { probe, body: { source: asked.source, account: asked.account, note: `${oneLine(asked.source, 60)} is not a source this machine's installed plugins declare, so Memory cannot read which account it is signed in to. Next step: install and verify the plugin that declares it.` } }
1401
+ }
1402
+ const renamed = reading.contract === "sources" && reading.source !== asked.source ? reading.source : null
1403
+ // The binding's own session first: when it cannot be made, nothing is read and
1404
+ // nothing is reported (it is not the source's failure, so no back-off either).
1405
+ let session
1406
+ try {
1407
+ // The declared source a retired name stands for decides the session's rules too: the probe runs in
1408
+ // the binding's own session, and that session must allow the probe action the declaration asserts.
1409
+ const binding = renamed ? { ...asked, read: reading.source } : asked
1410
+ session = typeof sessionID === "function" ? await sessionID(binding) : sessionID
1411
+ } catch (error) {
1412
+ probe.error = oneLine(errorMessage(error), 300)
1413
+ return { probe, body: null }
1414
+ }
1415
+ let body
1416
+ try {
1417
+ // A declared source has the contract's `probe` (D11); the owner-only
1418
+ // `events_list({ limit: 0 })` page is the previous contract's, and only
1419
+ // for a plugin that declares no source.
1420
+ // **A declared source's probe is not told an account** (0.12.5): the
1421
+ // plugin answers the account it is signed in to. Live at 00:43Z on
1422
+ // 2026-11-18, Memory named `default`, and github, granola and linear
1423
+ // each answered ACCOUNT_MISMATCH, so none of the three could bind. **A
1424
+ // request that names an account is that account** (0.12.6): a
1425
+ // multi-account plugin is probed as `work` when the person asked for
1426
+ // `work`, and its refusal is the answer, never a quiet rebind. A
1427
+ // plugin that still refuses a default request is asked once with the
1428
+ // account its own structured answer names, and nothing is adopted from
1429
+ // unparsed text.
1430
+ const ask = (input) => (prober ? prober(reading.source, input, session) : Promise.reject(new Error("this host gives plugins no tools RPC, so a source cannot be probed")))
1431
+ const declaredAnswer = async () => {
1432
+ const named = asked.account && asked.account !== DEFAULT_ACCOUNT ? asked.account : null
1433
+ if (named) return ask({ account: named })
1434
+ try {
1435
+ return await ask({})
1436
+ } catch (error) {
1437
+ const suggested = suggestedAccount(error)
1438
+ if (!suggested) throw error
1439
+ try {
1440
+ return await ask({ account: suggested })
1441
+ } catch (retry) {
1442
+ // A retry that fails keeps the first refusal's reason too: the two
1443
+ // say different things (the account, then why it still failed) and
1444
+ // the person needs both (0.12.6, the re-review's L).
1445
+ const both = new Error(`${oneLine(errorMessage(retry), 300)} (the first attempt said: ${oneLine(errorMessage(error), 300)})`)
1446
+ both.code = retry?.code ?? error?.code
1447
+ both.next = retry?.next ?? error?.next
1448
+ throw both
1449
+ }
1450
+ }
1451
+ }
1452
+ const answer = reading.contract === "sources"
1453
+ ? await declaredAnswer()
1454
+ : await (lister ? lister(asked.source, probeInput(reading, asked.account), session) : Promise.reject(new Error("this host gives plugins no way to call another plugin's events_list")))
1455
+ // A name the declaration has replaced says which source binds instead:
1456
+ // the store refuses a retired name, so the person needs the one to use.
1457
+ const replaced = renamed ? `${asked.source} is the previous contract's name for ${renamed}, which this release binds instead: bind ${renamed} in Memory's console.` : null
1458
+ if (answer?.owner?.id) {
1459
+ const owner = { id: oneLine(answer.owner.id, 300), label: oneLine(answer.owner.label ?? answer.owner.email ?? answer.owner.id, 300) }
1460
+ const setup = answer.setup || reading.setupOptions || null
1461
+ body = {
1462
+ source: asked.source,
1463
+ account: asked.account,
1464
+ owner,
1465
+ // The account the probe names is the binding's account: the store
1466
+ // confirms it, and a page of a declared source always names it
1467
+ // (0.12.3). A name Memory cannot hold is not reported.
1468
+ ...(isAccountName(answer.account) ? { reported_account: answer.account } : {}),
1469
+ // The installed declaration's digest, read from disk: a re-consent records the digest the installed
1470
+ // package has now, so jelly never refuses a read made under the old one. Only for the declared id
1471
+ // itself: a consent recorded under a retired name never reads that declaration.
1472
+ ...(renamed === null && reading.descriptorHash ? { digest: reading.descriptorHash } : {}),
1473
+ // The note is the source's or the plugin's own sentence: it is
1474
+ // reported to the store (`source_requests.note`) and shown from it,
1475
+ // so it is redacted here, where it is written (review F1/F2).
1476
+ ...(replaced || setup ? { note: oneLine(errorMessage([replaced, setup].filter(Boolean).join(" ")), 400) } : {}),
1477
+ }
1478
+ probe.owner = owner
1479
+ } else {
1480
+ body = { source: asked.source, account: asked.account, note: oneLine(errorMessage(answer?.setup || `${reading.package}'s ${reading.contract === "sources" ? "probe" : "events_list"} named no signed-in account; sign in to it in its own plugin.`), 400) }
1481
+ }
1482
+ } catch (error) {
1483
+ // A refusal keeps its own words, and a failed retry keeps both reasons:
1484
+ // the store holds a note of 500 (0.12.6).
1485
+ body = { source: asked.source, account: asked.account, note: oneLine(errorMessage(error), 500) }
1486
+ }
1487
+ return { probe, body }
1488
+ }
1489
+
1376
1490
  return {
1377
1491
  get scheduled() {
1378
1492
  return Boolean(scheduler)
@@ -1383,5 +1497,6 @@ export function createCollector({ scheduler = null, lister = null, prober = null
1383
1497
  sync,
1384
1498
  runOnce,
1385
1499
  probeRequests,
1500
+ probePluginRequests,
1386
1501
  }
1387
1502
  }
@@ -24,8 +24,8 @@ export const BASE_RULES = Object.freeze([
24
24
  Object.freeze({ action: "*", resource: "*", effect: "deny" }),
25
25
  Object.freeze({ action: "execute", resource: "*", effect: "allow" }),
26
26
  ])
27
- /** A binding's account name: no wildcard, separator or space, never empty. */
28
- export const ACCOUNT_NAME = /^[A-Za-z0-9][A-Za-z0-9_.@+-]{0,127}$/
27
+ /** A binding's account: the contract's `ACCOUNT_PATTERN` within Memory's cap of 128 (src/sources.js), a `/` included. */
28
+ export const ACCOUNT_NAME = /^[^\s*?:\u0000-\u001f\u007f]{1,128}$/
29
29
  export const PAGE_LIMIT = 200
30
30
  export const PAGES_PER_RUN = 5
31
31
  export const BILLED_PAGES_PER_RUN = 2
@@ -1082,9 +1082,14 @@ export function templateById(manifest, id) {
1082
1082
  return templatesOf(manifest).find((template) => template?.id === id) ?? null
1083
1083
  }
1084
1084
 
1085
- /** An account name a grant's resource may bind to. A wildcard, separator or empty is never one. */
1085
+ /**
1086
+ * An account a grant's resource may bind to: the contract's `ACCOUNT_PATTERN`
1087
+ * within Memory's cap of 128 (src/sources.js holds the same grammar). A
1088
+ * wildcard, the separator `:` or empty is never one; a `/` is, because
1089
+ * `linear.activity` answers `<workspace uuid>/<user email>`.
1090
+ */
1086
1091
  export function accountName(value) {
1087
- if (typeof value !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._@%+-]{0,127}$/.test(value)) throw new TypeError("an account must be a plain account name")
1092
+ if (typeof value !== "string" || !/^[^\s*?:\u0000-\u001f\u007f]{1,128}$/.test(value)) throw new TypeError("an account must be a plain account name")
1088
1093
  return value
1089
1094
  }
1090
1095
 
package/src/sources.js CHANGED
@@ -28,8 +28,24 @@ import { decodeBoundCursor, encodeBoundCursor, canonicalScope } from "./plugins/
28
28
  import { probeRules, sessionRules } from "./plugins/source-contract/vendor/permission.js"
29
29
  import { maxBytesOf } from "./plugins/source-contract/vendor/descriptor.js"
30
30
 
31
- /** A binding's account name: no wildcard (`*`, `?`), separator (`:`, `/`) or space, and never empty. */
32
- export const ACCOUNT_NAME = /^[A-Za-z0-9][A-Za-z0-9_.@+-]{0,127}$/
31
+ /**
32
+ * A binding's account: the contract's `ACCOUNT_PATTERN`
33
+ * (`/^[^\s*?:\u0000-\u001f\u007f]{1,320}$/`) with Memory's own cap of 128.
34
+ *
35
+ * It refuses what could widen a permission rule or split a key — a wildcard
36
+ * (`*`, `?`), the separator `:` (a resource is `<account>:<operation>`) and
37
+ * control characters — and accepts everything else the contract allows,
38
+ * a `/` included: `linear.activity` answers `<workspace uuid>/<user email>`,
39
+ * and refusing it dropped the account and keyed every linear binding
40
+ * "default" (0.13.1, the collector-binds audit's §1d).
41
+ */
42
+ export const ACCOUNT_NAME = /^[^\s*?:\u0000-\u001f\u007f]{1,128}$/
43
+ /**
44
+ * An account as part of an action or server name (`plaud-{account}`): the
45
+ * narrower grammar, because a `/` is no part of a name. An account outside it
46
+ * keeps the plain namespace, which is narrower and never wider.
47
+ */
48
+ export const ACCOUNT_SERVER = /^[A-Za-z0-9][A-Za-z0-9_.@+-]{0,127}$/
33
49
 
34
50
  /**
35
51
  * The sources whose **account names the machine that reads them**: the
@@ -601,7 +617,7 @@ export function sourceAllowRules(entry, account = null) {
601
617
  for (const resource of permission.apiReads?.resources ?? []) {
602
618
  if (typeof resource !== "string" || /[?*]/.test(resource)) throw new TypeError(`sourceAllowRules: apiReads resource "${String(resource).slice(0, 60)}" is not an exact resource`)
603
619
  }
604
- const server = named && permission.accountServer ? permission.accountServer.replace("{account}", named) : null
620
+ const server = named && permission.accountServer ? accountServerOf(permission.accountServer, named) : null
605
621
  const inner = (action) => (server && action.startsWith(`${entry.namespace}_`) ? `${server}${action.slice(entry.namespace.length)}` : action)
606
622
  return [
607
623
  allow(permission.events),
@@ -611,6 +627,22 @@ export function sourceAllowRules(entry, account = null) {
611
627
  ]
612
628
  }
613
629
 
630
+ /**
631
+ * The server an account's tools live on (`plaud-{account}`, the contract's
632
+ * `accounts.server`), or a refusal.
633
+ *
634
+ * An account is a **name** here, so the narrow grammar is the one that holds: a
635
+ * `/` is no part of a plugin's MCP server name. Mapping such an account to the
636
+ * plain namespace would build rules for a read it can never make and look
637
+ * allowed, which is what 0.13.1 did (the review's L3). It is refused instead,
638
+ * and the refusal says why, so the binding fails with a sentence rather than
639
+ * reading under the wrong server.
640
+ */
641
+ function accountServerOf(template, account) {
642
+ if (!ACCOUNT_SERVER.test(account)) throw new TypeError(`"${String(account).slice(0, 60)}" is not a server account name: it cannot name ${template.replace("{account}", "...")}`)
643
+ return template.replace("{account}", account)
644
+ }
645
+
614
646
  /** The source contract version a previous-contract plugin's `events_list` must keep. */
615
647
  export const SOURCE_CONTRACT = "the memory source contract v1 (events_list answers source and account)"
616
648
 
@@ -418,9 +418,23 @@ export function createSpacesActions(toolkit) {
418
418
  /** Bindings and the person's open bind requests (a request made in the console, or here). */
419
419
  async function listAll(where) {
420
420
  const answer = await records().call("sources.list", {}, where)
421
+ const requests = Array.isArray(answer?.requests) ? answer.requests.filter(isPlainObject) : []
422
+ // A declared source's request belongs to its plugin (C2): `plugins.list`
423
+ // holds it, and it is listed with the rest, marked, so neither the person
424
+ // nor their agent is told nothing is waiting. The list is best effort: a
425
+ // records service older than its plugin answers an unknown method, and any
426
+ // other failure costs the requests, never the bindings that were already
427
+ // read.
428
+ let pluginRequests = []
429
+ try {
430
+ const plugins = await records().call("plugins.list", {}, where)
431
+ pluginRequests = (Array.isArray(plugins?.requests) ? plugins.requests : []).filter(isPlainObject)
432
+ } catch (error) {
433
+ log.debug("plugins.list failed beside sources.list", { error: errorMessage(error) })
434
+ }
421
435
  return {
422
436
  sources: Array.isArray(answer?.sources) ? answer.sources.filter(isPlainObject) : [],
423
- requests: Array.isArray(answer?.requests) ? answer.requests.filter(isPlainObject) : [],
437
+ requests: [...requests, ...pluginRequests],
424
438
  }
425
439
  }
426
440
 
@@ -506,13 +520,24 @@ export function createSpacesActions(toolkit) {
506
520
  const why = open.state === "attention" || open.state === "failed" ? ` The collector could not read the account yet${open.note ? ` (${oneLine(errorMessage(open.note), 240)})` : ""}.` : ""
507
521
  return `not bound here: a bind request for ${name} is open; the person's collector reports the signed-in account on its next run.${why} ${confirm}`
508
522
  }
523
+ const declared = resolveDeclaredSource(asked.source).entry
509
524
  try {
510
- await records().call("sources.request", { source: asked.source, account: asked.account }, space.where)
525
+ // A declared source is asked for through its own plugin's consent path
526
+ // (C2, the collector-binds audit's C2): `plugins.request` names the plugin
527
+ // and the source, and the store keeps the declaration, its scope and its
528
+ // cost with the request, so the person confirms what they were shown. A
529
+ // previous contract's name has no declaration to consent to, and keeps
530
+ // `sources.request`.
531
+ if (declared?.contract === "sources") await records().call("plugins.request", { plugin_id: declared.pluginId, source: asked.source, account: asked.account }, space.where)
532
+ else await records().call("sources.request", { source: asked.source, account: asked.account }, space.where)
511
533
  } catch (error) {
512
534
  log.warn("sources request failed", error)
513
535
  return `not asked: ${recordsFailure(error)}`
514
536
  }
515
537
  log.info("sources request", { source: asked.source })
538
+ if (declared?.contract === "sources") {
539
+ return `not bound here: asked ${label}'s plugin to read one thing, the account it is signed in to. On its next run (every 30 minutes while OpenCode is open, or now with mem_collect when the person asks), the person's collector reads only that account and reports it with the declaration's scope and cost. Confirming it is the person's own act, in a browser: open Memory's console, Sources (${link}), and choose Confirm for ${label}. Nothing is collected until they do; no agent and no key can confirm it.`
540
+ }
516
541
  return `not bound here: asked. On its next run (every 30 minutes while OpenCode is open, or now with mem_collect when the person asks), the person's collector reads only which account ${label} is signed in to. ${confirm}`
517
542
  }
518
543
 
@@ -561,6 +586,18 @@ export function createSpacesActions(toolkit) {
561
586
  const request = requests.find((entry) => entry.source === target.source && (entry.account || DEFAULT_ACCOUNT) === target.account)
562
587
  if (!row && request) {
563
588
  if (space.shared) return text(personalOnly("cancelled"))
589
+ // A declared source's request is its plugin's, and it is cancelled with
590
+ // the plugin's own method (the re-check's M2). Nothing was collected, so
591
+ // nothing is deleted.
592
+ if (request.plugin_id) {
593
+ try {
594
+ await records().call("plugins.cancel", { plugin_id: request.plugin_id, source: target.source, account: binding.account }, space.where)
595
+ } catch (error) {
596
+ return fail(`not cancelled: ${recordsFailure(error)}`)
597
+ }
598
+ await toolkit.collector?.forgetSession?.({ source: target.source, account: binding.account })
599
+ return text(`cancelled the plugin request for ${target.source}:${binding.account} in ${space.label}; nothing had been collected from it.`)
600
+ }
564
601
  // Only a bind request: nothing was collected, so cancelling it deletes nothing.
565
602
  try {
566
603
  await records().call("sources.cancel", { source: target.source, account: binding.account }, space.where)