@joe-broadhead/opencode-mem 0.12.2 → 0.12.4
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 +63 -0
- package/README.md +1 -1
- package/package.json +1 -1
- package/skills/mem.sources/SKILL.md +1 -1
- package/src/collector-service.js +99 -17
- package/src/collector.js +120 -21
- package/src/plugins/discovery.js +3 -2
- package/src/plugins/list.js +18 -0
- package/src/plugins/locate.js +15 -4
- package/src/plugins/verify.js +6 -4
- package/src/sources.js +87 -5
- package/src/tools/spaces.js +54 -18
- package/src/util.js +28 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,69 @@
|
|
|
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.12.4] - 2026-11-18
|
|
7
|
+
|
|
8
|
+
### Fixed
|
|
9
|
+
|
|
10
|
+
- X is collected once a day. Its reads are billed, so the owner's cadence policy now outranks both the
|
|
11
|
+
registry's own cadence and a plugin's declared `cadence.providerMinMinutes`, for a legacy binding
|
|
12
|
+
and a declared source alike.
|
|
13
|
+
- A failed collection no longer uses up its binding's cadence: a binding that fails is due again after
|
|
14
|
+
the shorter of its cadence and an hour. A successful binding keeps its cadence. Live at 22:37Z on
|
|
15
|
+
2026-11-17, X failed and the next timer run skipped it as not due, which a daily cadence would have
|
|
16
|
+
stretched to a day.
|
|
17
|
+
- Memory reads the plugin list OpenCode actually answers: `ctx.plugin.list()` gives
|
|
18
|
+
`{ location, data: [...] }` on 2.2.6, not an array. Discovery and re-verification read only an array,
|
|
19
|
+
so they saw no plugin, published no declaration, and every bind fell back to the previous contract.
|
|
20
|
+
An answer that is neither shape is read as no list, with a warning.
|
|
21
|
+
- A configuration reload that leaves two instances in one process no longer leaves the surviving one
|
|
22
|
+
without the collector lease until its next 30-minute tick: an instance that is not the holder takes
|
|
23
|
+
a lease that is free at its next heartbeat, and collects what is due, so a reload does not read a
|
|
24
|
+
billed source whose cadence is not up.
|
|
25
|
+
- A run whose collector service was asked to stop writes no source status and reports nothing, so an
|
|
26
|
+
instance being disposed cannot mark every binding failing with its own missing plugin RPCs. An
|
|
27
|
+
`RPC is unavailable` answer is transient: the binding keeps its last good state, and the run says
|
|
28
|
+
retry next run.
|
|
29
|
+
- A collection's failure reads as one line of text with its code (`Why: AUTH_REQUIRED: the Slack
|
|
30
|
+
plugin is not signed in`), never `Why: [object Object]`. The placeholder came from a failure that
|
|
31
|
+
arrived as an object and met `String()`: at the records service, which stored it, and at the
|
|
32
|
+
console, which rendered it. Both now read a failure for its `code` and `message`, and the
|
|
33
|
+
collector reports its own failures with the code the contract's table named.
|
|
34
|
+
- A collector on another machine no longer marks a binding failing. Every report names the machine
|
|
35
|
+
that made it, and a binding's failing state stands only when the collector that last succeeded
|
|
36
|
+
for it is the one that failed; another machine's failure is kept beside the binding, named and
|
|
37
|
+
timed, and said on Sources without calling it failing. A pause from that machine is not applied
|
|
38
|
+
either. A machine started from a snapshot with the person's Memory sign-in and none of the
|
|
39
|
+
source's can no longer stop the machine that reads the source.
|
|
40
|
+
- A source whose account names the machine that reads it (`history`) is never read or reported by
|
|
41
|
+
a collector on another machine, so a guest cannot turn it failing.
|
|
42
|
+
|
|
43
|
+
### Deploy
|
|
44
|
+
|
|
45
|
+
The records service needs a deploy before these reports are read as here: `sources.collected` and
|
|
46
|
+
`plugins.pause` take a `host`, and `source_collections` gains `host`, `elsewhere_host`,
|
|
47
|
+
`elsewhere_at` and `elsewhere_error`. Additive, with no migration: an older service ignores the
|
|
48
|
+
fields, and an older collector sends none, which keeps the previous rule.
|
|
49
|
+
|
|
50
|
+
## [0.12.3] - 2026-11-17
|
|
51
|
+
|
|
52
|
+
### Fixed
|
|
53
|
+
|
|
54
|
+
- Memory reads the sources an installed plugin declares on plain OpenCode. OpenCode 2.2.6 reports a
|
|
55
|
+
git plugin with no commit, and the locator refused every such install, so no declaration was read
|
|
56
|
+
and every bind took the previous contract's path. Without a commit, the store's copies for the
|
|
57
|
+
target must agree on one declaration, or none is read.
|
|
58
|
+
- A bind request's name resolves to the source its plugin declares (`granola` is
|
|
59
|
+
`granola.meetings`), and the account is learned through the contract's `probe`. A namespace with
|
|
60
|
+
several sources, such as `gws`, names them instead of choosing one. The bind answer says which
|
|
61
|
+
source a name was asked as.
|
|
62
|
+
- A declared source's page always names its account, `"default"` included, so a resumed cursor is
|
|
63
|
+
accepted. Wispr Flow refused its second page without it.
|
|
64
|
+
|
|
65
|
+
### Deploy
|
|
66
|
+
|
|
67
|
+
No server change and no migration: the plugin alone changes.
|
|
68
|
+
|
|
6
69
|
## [0.12.2] - 2026-11-17
|
|
7
70
|
|
|
8
71
|
### Changed
|
package/README.md
CHANGED
|
@@ -590,7 +590,7 @@ machine collects every 30 minutes (`collect`, `collectEveryMinutes`,
|
|
|
590
590
|
console as the next step), outside the person's own personal space, and for
|
|
591
591
|
any account their own collector did not report.
|
|
592
592
|
- **Cadence and setup.** Each source has its own cadence in the registry (X,
|
|
593
|
-
which is billed,
|
|
593
|
+
which is billed, once a day). A bind passes on the source's own setup
|
|
594
594
|
step: Slack needs its `events.channels` option, and X should have
|
|
595
595
|
`"events": {"maxCalls": 2}` (and `ownsXApp` only if the account owns the app).
|
|
596
596
|
- **Without routines, collection only buffers.** The records service's
|
package/package.json
CHANGED
|
@@ -57,7 +57,7 @@ await tools.mem.spaces({ action: "sources", unbind: { source: "gmail", account:
|
|
|
57
57
|
|
|
58
58
|
Collection runs with no model: every 30 minutes while OpenCode runs (one process
|
|
59
59
|
per machine), and on Jelly a declared routine also wakes it. A billed source
|
|
60
|
-
runs less often (X
|
|
60
|
+
runs less often (X, which is billed, once a day). `spaces` `health` shows the last run,
|
|
61
61
|
each source's counts and errors, and whether **routines** run, with the model.
|
|
62
62
|
|
|
63
63
|
**Collection without routines only buffers.** When health says `routines: off`,
|
package/src/collector-service.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import fs from "node:fs"
|
|
2
|
+
import os from "node:os"
|
|
2
3
|
import path from "node:path"
|
|
3
4
|
import { DEFAULT_ACCOUNT, cadenceMs, collectSessionId, collectSessionRules, collectableSources, createCollector, hostBrokerTransport, hostSourceLister, hostSourceProber, rulesHash } from "./collector.js"
|
|
4
5
|
import { createLease } from "./collector-lock.js"
|
|
5
6
|
import { knownSources, sourceEntry } from "./sources.js"
|
|
6
|
-
import { errorMessage, isPlainObject, oneLine } from "./util.js"
|
|
7
|
+
import { errorMessage, failureText, isPlainObject, oneLine } from "./util.js"
|
|
7
8
|
import { recordsOf } from "./tools/share.js"
|
|
8
9
|
import { unboundOwner } from "./backend/records.js"
|
|
9
10
|
|
|
@@ -18,7 +19,9 @@ export const CATCH_UP_RUNS = 10
|
|
|
18
19
|
export const STARTUP_JITTER_MS = Object.freeze([10_000, 60_000])
|
|
19
20
|
/** A source is due this long before its cadence is up, so a 30-minute timer does not skip a 30-minute source by a few seconds. */
|
|
20
21
|
export const DUE_SLACK_MS = 60_000
|
|
21
|
-
/**
|
|
22
|
+
/** A binding whose last attempt failed is due again after the shorter of its cadence and this (0.12.4). */
|
|
23
|
+
export const RETRY_MS = 60 * 60_000
|
|
24
|
+
/** Triggers a person started: they collect every bound source, whatever its cadence. A take-over is not one: it is a startup run, and collects what is due. */
|
|
22
25
|
const ASKED = new Set(["tool", "command", "request"])
|
|
23
26
|
|
|
24
27
|
const REAL_CLOCK = Object.freeze({
|
|
@@ -46,7 +49,8 @@ const REAL_CLOCK = Object.freeze({
|
|
|
46
49
|
* request (`mem_collect`, `/mem-collect`). `collect: false` (or
|
|
47
50
|
* `MEMORY_COLLECT=0`) turns the timer off; a request still runs. A timer
|
|
48
51
|
* run collects a source only when its own cadence is up (the registry's
|
|
49
|
-
* `everyMinutes`: X
|
|
52
|
+
* `everyMinutes`: X, which is billed, once a day); a request collects every
|
|
53
|
+
* source.
|
|
50
54
|
* - **Bind requests:** each run first answers the person's bind requests
|
|
51
55
|
* (`sources.list` `requests`): only for those sources, it reads the
|
|
52
56
|
* signed-in account and reports it (`sources.report`) for the person to
|
|
@@ -71,7 +75,7 @@ const REAL_CLOCK = Object.freeze({
|
|
|
71
75
|
* lease?: ReturnType<typeof createLease>,
|
|
72
76
|
* }} input
|
|
73
77
|
*/
|
|
74
|
-
export function createCollectorService({ ctx, runtime, toolkit, clock = REAL_CLOCK, random = Math.random, waitMs = COLLECT_WAIT_MS, lease }) {
|
|
78
|
+
export function createCollectorService({ ctx, runtime, toolkit, clock = REAL_CLOCK, random = Math.random, waitMs = COLLECT_WAIT_MS, lease, host = os.hostname() }) {
|
|
75
79
|
const config = runtime.config
|
|
76
80
|
const log = runtime.log
|
|
77
81
|
const stateDir = config.stateDir
|
|
@@ -186,7 +190,7 @@ export function createCollectorService({ ctx, runtime, toolkit, clock = REAL_CLO
|
|
|
186
190
|
const account = binding.account || DEFAULT_ACCOUNT
|
|
187
191
|
const id = collectSessionId({ source: binding.source, account })
|
|
188
192
|
try {
|
|
189
|
-
await ensureSession({ id, title: `Memory collection: ${binding.source}`, permissions: collectSessionRules({ source: binding.source, account }), extra: { source: binding.source } })
|
|
193
|
+
await ensureSession({ id, title: `Memory collection: ${binding.read ?? binding.source}`, permissions: collectSessionRules({ source: binding.source, account, read: binding.read ?? null }), extra: { source: binding.source } })
|
|
190
194
|
} catch (error) {
|
|
191
195
|
throw new Error(`the collector's session for ${binding.source}:${account} could not be made (${oneLine(errorMessage(error), 200)}); nothing was read`)
|
|
192
196
|
}
|
|
@@ -246,6 +250,7 @@ export function createCollectorService({ ctx, runtime, toolkit, clock = REAL_CLO
|
|
|
246
250
|
const brokerState = { timedOut: false, embedded: new Set() }
|
|
247
251
|
const collector = createCollector({
|
|
248
252
|
scheduler: null,
|
|
253
|
+
host,
|
|
249
254
|
lister: hostSourceLister(ctx, { broker: hostBrokerTransport(ctx, { state: brokerState }), brokerState }),
|
|
250
255
|
prober: hostSourceProber(ctx),
|
|
251
256
|
log,
|
|
@@ -263,6 +268,8 @@ export function createCollectorService({ ctx, runtime, toolkit, clock = REAL_CLO
|
|
|
263
268
|
|
|
264
269
|
/** A run's refusal once the lease is another process's: it must not read, write or report as a holder. */
|
|
265
270
|
const LOST = "another OpenCode process holds the collector lease now; this run stopped before writing more"
|
|
271
|
+
/** A run's refusal once the service was asked to stop: a reload disposed this instance, so its run writes nothing more. */
|
|
272
|
+
const STOPPING = "this collector service was asked to stop; the run stopped before writing more"
|
|
266
273
|
|
|
267
274
|
function writeStatus(status) {
|
|
268
275
|
try {
|
|
@@ -326,7 +333,7 @@ export function createCollectorService({ ctx, runtime, toolkit, clock = REAL_CLO
|
|
|
326
333
|
* Start one collection unless one is running here, memory is unavailable, or
|
|
327
334
|
* another process holds the lease. Returns at once.
|
|
328
335
|
*
|
|
329
|
-
* @param {"startup" | "timer" | "catch-up" | "request" | "tool" | "command"} trigger
|
|
336
|
+
* @param {"startup" | "timer" | "catch-up" | "takeover" | "request" | "tool" | "command"} trigger
|
|
330
337
|
* @returns {Promise<{ started: true } | { running: true, since: string } | { skipped: string }>}
|
|
331
338
|
*/
|
|
332
339
|
async function begin(trigger, { only, sessionID } = {}) {
|
|
@@ -382,6 +389,7 @@ export function createCollectorService({ ctx, runtime, toolkit, clock = REAL_CLO
|
|
|
382
389
|
* taker) never writes as a holder — not even the run's first status line.
|
|
383
390
|
*/
|
|
384
391
|
function guard() {
|
|
392
|
+
if (stopped) throw new Error(STOPPING)
|
|
385
393
|
if (stillHolder()) return
|
|
386
394
|
throw new Error(LOST)
|
|
387
395
|
}
|
|
@@ -424,6 +432,7 @@ export function createCollectorService({ ctx, runtime, toolkit, clock = REAL_CLO
|
|
|
424
432
|
const rpc = (binding) => {
|
|
425
433
|
// Read nothing as a holder that has lost the lease (a machine that woke
|
|
426
434
|
// after another process took over): the binding is reported, not read.
|
|
435
|
+
if (stopped) throw new Error(STOPPING)
|
|
427
436
|
if (!stillHolder()) throw new Error(LOST)
|
|
428
437
|
return rpcSession(null, binding)
|
|
429
438
|
}
|
|
@@ -449,7 +458,15 @@ export function createCollectorService({ ctx, runtime, toolkit, clock = REAL_CLO
|
|
|
449
458
|
// The reason is the source's own failure text and the store keeps it for
|
|
450
459
|
// every process and the console to read: redacted here, where it is
|
|
451
460
|
// stored, not only where it is shown (0.10.4's gate; review F1).
|
|
452
|
-
|
|
461
|
+
// `host` says which machine asked: a pause from one that is not the
|
|
462
|
+
// binding's collector is not applied (0.12.3), as its collection report
|
|
463
|
+
// does not turn the binding failing.
|
|
464
|
+
pause: (binding, reason, code) => {
|
|
465
|
+
// A run whose service was asked to stop pauses nothing: the instance is
|
|
466
|
+
// being disposed, and the store is not told what its dead RPCs said.
|
|
467
|
+
if (stopped) return Promise.resolve()
|
|
468
|
+
return call("plugins.pause", { source: binding.source, account: binding.account, reason: oneLine(errorMessage(reason), 200), code, host }, where)
|
|
469
|
+
},
|
|
453
470
|
ingest: async (input) => {
|
|
454
471
|
// And write nothing as one: the page never lands, and the run leaves the
|
|
455
472
|
// status to the holder that has the lease.
|
|
@@ -476,12 +493,22 @@ export function createCollectorService({ ctx, runtime, toolkit, clock = REAL_CLO
|
|
|
476
493
|
* report never fails the collection.
|
|
477
494
|
*/
|
|
478
495
|
async function reportCollections(call, where, results) {
|
|
496
|
+
// A service asked to stop reports nothing: its run is the instance being
|
|
497
|
+
// disposed, and its plugin RPCs are already gone (0.12.4, live at 22:19Z on
|
|
498
|
+
// 2026-11-17), so every binding would be reported failing for the host's
|
|
499
|
+
// state rather than its own.
|
|
500
|
+
if (stopped) return
|
|
479
501
|
for (const result of results) {
|
|
480
|
-
if (
|
|
502
|
+
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
|
|
481
505
|
// `more` travels with the report (review S5): the console's Sources row says
|
|
482
506
|
// "catching up" from records, so it must know the run left pages behind.
|
|
483
|
-
|
|
484
|
-
|
|
507
|
+
// `host` is this machine: the records service shows a binding's failing
|
|
508
|
+
// state only for the collector that last succeeded for it, so a machine
|
|
509
|
+
// with no sign-in to the source cannot turn it failing (0.12.3).
|
|
510
|
+
const body = { source: result.source, account: result.account ?? "default", ok: !result.error, accepted: Number.isInteger(result.accepted) ? result.accepted : undefined, more: result.more === true, host }
|
|
511
|
+
if (result.error) body.error = reasonText(result, 300)
|
|
485
512
|
try {
|
|
486
513
|
await call("sources.collected", body, where)
|
|
487
514
|
} catch (error) {
|
|
@@ -492,9 +519,14 @@ export function createCollectorService({ ctx, runtime, toolkit, clock = REAL_CLO
|
|
|
492
519
|
|
|
493
520
|
function finish(trigger, started, results, error, none = false, { probes = [], collected } = {}) {
|
|
494
521
|
const ended = clock.now()
|
|
495
|
-
//
|
|
522
|
+
// The point each binding's cadence counts from, kept across runs and
|
|
523
|
+
// processes in collector.json. A success counts from the run's start; a
|
|
524
|
+
// failed attempt counts from earlier, so the binding is due again after the
|
|
525
|
+
// shorter of its cadence and an hour (0.12.4). A failure must not use up a
|
|
526
|
+
// billed source's day: live at 22:37Z on 2026-11-17, X failed, and the
|
|
527
|
+
// 22:49Z run skipped it as not due.
|
|
496
528
|
const at = { ...(collected ?? (isPlainObject(readStatus()?.collected) ? readStatus().collected : {})) }
|
|
497
|
-
for (const result of results) if (!result.notDue) at[keyOf(result)] = new Date(started).toISOString()
|
|
529
|
+
for (const result of results) if (!result.notDue && !result.otherHost) at[keyOf(result)] = new Date(cadencePoint(result, started)).toISOString()
|
|
498
530
|
last = {
|
|
499
531
|
state: error ? "failed" : "done",
|
|
500
532
|
trigger,
|
|
@@ -508,9 +540,12 @@ export function createCollectorService({ ctx, runtime, toolkit, clock = REAL_CLO
|
|
|
508
540
|
collected: at,
|
|
509
541
|
}
|
|
510
542
|
// A run writes no status as a holder unless the lock still proves it is
|
|
511
|
-
// one: the check is made now, not only when the run first noticed.
|
|
512
|
-
|
|
513
|
-
|
|
543
|
+
// one: the check is made now, not only when the run first noticed. A
|
|
544
|
+
// service asked to stop writes none either: its run is the instance being
|
|
545
|
+
// disposed, and its state is not the machine's (0.12.4).
|
|
546
|
+
if (!stopped && !leaseLost) stillHolder()
|
|
547
|
+
if (stopped) log?.info?.("collection run stopped with the service; it wrote no status", { trigger })
|
|
548
|
+
else if (leaseLost) log?.info?.("collection run stopped: the lease is another process's", { trigger })
|
|
514
549
|
else writeStatus(last)
|
|
515
550
|
const behind = results.some((result) => result.more && !result.error)
|
|
516
551
|
if (behind && catchUps < CATCH_UP_RUNS && !stopped) {
|
|
@@ -541,11 +576,27 @@ export function createCollectorService({ ctx, runtime, toolkit, clock = REAL_CLO
|
|
|
541
576
|
/* already taken */
|
|
542
577
|
}
|
|
543
578
|
}
|
|
579
|
+
// The holder may have gone without its lease going stale: a configuration
|
|
580
|
+
// reload disposes one of two instances and its stop() releases the lease,
|
|
581
|
+
// and the survivor that skipped its startup run must not wait for its next
|
|
582
|
+
// interval tick (0.12.4, live at 22:19Z on 2026-11-17). Take a lease that
|
|
583
|
+
// is free now and collect once; the one-holder rule is the same acquire.
|
|
584
|
+
if (!leader && !active && !stopped && freeLease()) safely("takeover")
|
|
544
585
|
} catch (error) {
|
|
545
586
|
log?.warn?.("collector heartbeat failed", { error: errorMessage(error) })
|
|
546
587
|
}
|
|
547
588
|
}
|
|
548
589
|
|
|
590
|
+
/** True when no process holds the lease, or the one it names stopped beating: the next beat may take it. */
|
|
591
|
+
function freeLease() {
|
|
592
|
+
try {
|
|
593
|
+
const current = lock.holder()
|
|
594
|
+
return !current || lock.isStale(current)
|
|
595
|
+
} catch {
|
|
596
|
+
return false
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
|
|
549
600
|
/** Start the timers. Returns at once; the first run comes after a short random wait. */
|
|
550
601
|
function start() {
|
|
551
602
|
if (!config.collect) {
|
|
@@ -697,6 +748,31 @@ function keyOf(row) {
|
|
|
697
748
|
return `${row?.source ?? ""}\u0000${row?.account || DEFAULT_ACCOUNT}`
|
|
698
749
|
}
|
|
699
750
|
|
|
751
|
+
/**
|
|
752
|
+
* The point a binding's cadence counts from after a run: the run's start, or
|
|
753
|
+
* for a failed attempt earlier by the part of the cadence beyond an hour, so the
|
|
754
|
+
* binding is due again after the shorter of its cadence and an hour. A billed
|
|
755
|
+
* source that fails is retried no more often than that, and a transient failure
|
|
756
|
+
* costs at most that (0.12.4).
|
|
757
|
+
*/
|
|
758
|
+
function cadencePoint(result, started) {
|
|
759
|
+
if (!result.error) return started
|
|
760
|
+
const cadence = cadenceMs(result.source)
|
|
761
|
+
return started - (cadence - Math.min(cadence, RETRY_MS))
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
/**
|
|
765
|
+
* A result's reason as one line: `CODE: message` when the run kept the
|
|
766
|
+
* contract's code (`AUTH_REQUIRED` is a sign-in), else the message alone. A
|
|
767
|
+
* failure that arrived as an object reads as its own words; `String(object)`,
|
|
768
|
+
* which is `[object Object]`, is never what a person sees (0.12.3).
|
|
769
|
+
*/
|
|
770
|
+
function reasonText(result, max = 300) {
|
|
771
|
+
const raw = result?.error
|
|
772
|
+
if (typeof raw === "string") return failureText({ code: result?.code, message: raw }, max)
|
|
773
|
+
return failureText(raw ?? result?.reason, max)
|
|
774
|
+
}
|
|
775
|
+
|
|
700
776
|
/**
|
|
701
777
|
* What the status file keeps of one result. The file is read by every process
|
|
702
778
|
* and by the console, and it holds text a source or a plugin wrote — a
|
|
@@ -706,7 +782,7 @@ function keyOf(row) {
|
|
|
706
782
|
*/
|
|
707
783
|
export function storedResult(result) {
|
|
708
784
|
const kept = { ...result }
|
|
709
|
-
if (kept.error) kept.error =
|
|
785
|
+
if (kept.error) kept.error = reasonText(kept, 300)
|
|
710
786
|
if (kept.refused_reason) kept.refused_reason = oneLine(errorMessage(kept.refused_reason), 200)
|
|
711
787
|
if (kept.setup) kept.setup = oneLine(errorMessage(kept.setup), 400)
|
|
712
788
|
if (kept.held) kept.held = oneLine(errorMessage(kept.held), 100)
|
|
@@ -729,6 +805,12 @@ export function describeProbe(probe) {
|
|
|
729
805
|
/** One source's line: its counts, what it refused, and why it stopped. */
|
|
730
806
|
export function describeResult(result) {
|
|
731
807
|
if (result.notDue) return `${oneLine(result.source ?? "?", 40)}:${oneLine(result.account ?? "?", 80)}: not due (collected every ${Number(result.everyMinutes) || 30} minutes)`
|
|
808
|
+
// Another machine's host-bound binding (0.12.3): said, and not a failure.
|
|
809
|
+
if (result.otherHost) return `${oneLine(result.source ?? "?", 40)}:${oneLine(result.account ?? "?", 80)}: only ${oneLine(result.otherHost, 80)} collects it, so this machine leaves it alone`
|
|
810
|
+
// The plugin's RPC is not registered yet, or no longer (a reload): the host's
|
|
811
|
+
// state, not the binding's failure, so it is not called stopped and it keeps
|
|
812
|
+
// the state it had (0.12.4).
|
|
813
|
+
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`
|
|
732
814
|
const counts = `${Number(result.accepted) || 0} new, ${Number(result.duplicates) || 0} already had, ${Number(result.refused) || 0} refused, ${Number(result.pages) || 0} page(s)`
|
|
733
815
|
// A refused event is a real loss — the contract's cursor moves past it — so
|
|
734
816
|
// the line names the newest one and why, not only how many (DESIGN §2.3.1).
|
|
@@ -741,5 +823,5 @@ export function describeResult(result) {
|
|
|
741
823
|
// object, and the 0.10.3 gate (A15) caught an answer repeating the placeholder.
|
|
742
824
|
// The refusal trace is build/0.11’s (fix/source-kinds): a refused event is a
|
|
743
825
|
// real loss, so the line names the newest one and why.
|
|
744
|
-
return `${name}: ${result.error ? `stopped (${
|
|
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)}` : ""}`
|
|
745
827
|
}
|
package/src/collector.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { errorMessage, isPlainObject, oneLine } from "./util.js"
|
|
2
2
|
import { createHash } from "node:crypto"
|
|
3
3
|
import { isSourceName } from "./source-ids.js"
|
|
4
|
-
import { ACCOUNT_NAME, DEFAULT_EVERY_MINUTES, contractRefusal, rpcDefinition, sourceAllowRules, sourceEntry } from "./sources.js"
|
|
4
|
+
import { ACCOUNT_NAME, DEFAULT_EVERY_MINUTES, contractRefusal, hostBoundSource, resolveDeclaredSource, rpcDefinition, sourceAllowRules, sourceEntry } from "./sources.js"
|
|
5
5
|
import { acceptAnswer, probe, read } from "./plugins/source-contract/vendor/read.js"
|
|
6
6
|
import { isBrokerAnswer, sourceReader } from "./plugins/source-contract/vendor/broker-client.js"
|
|
7
7
|
import { probeResultProblems } from "./plugins/source-contract/vendor/events.js"
|
|
@@ -79,9 +79,16 @@ const freezeRules = (rules) => Object.freeze(rules.map((rule) => Object.freeze({
|
|
|
79
79
|
* of its EVENT_READS on the binding's own account, and for github the four
|
|
80
80
|
* `github_api` GETs its events_list makes. There is no session for every
|
|
81
81
|
* source at once (0.9.7).
|
|
82
|
+
*
|
|
83
|
+
* `read` is the declared source a request's name stands for (0.12.3): a request
|
|
84
|
+
* recorded under `granola` is probed through `granola.meetings`, and the session
|
|
85
|
+
* it runs in allows exactly what that declaration asserts — its probe action
|
|
86
|
+
* included (`sourceAllowRules`). Without it the binding's own name decides, as
|
|
87
|
+
* before.
|
|
82
88
|
*/
|
|
83
|
-
export function collectSessionRules({ source, account }) {
|
|
84
|
-
const
|
|
89
|
+
export function collectSessionRules({ source, account, read = null }) {
|
|
90
|
+
const named = read ? sourceEntry(read) : null
|
|
91
|
+
const entry = named?.contract === "sources" ? named : sourceEntry(source)
|
|
85
92
|
return freezeRules([...BASE_RULES, ...(entry ? sourceAllowRules(entry, account || DEFAULT_ACCOUNT) : [])])
|
|
86
93
|
}
|
|
87
94
|
|
|
@@ -158,14 +165,63 @@ export function collectableSources(sources, { only } = {}) {
|
|
|
158
165
|
return [...seen.values()].sort((a, b) => bindingKey(a).localeCompare(bindingKey(b)))
|
|
159
166
|
}
|
|
160
167
|
|
|
168
|
+
/**
|
|
169
|
+
* The machine a host-bound binding belongs to, when it is not this one, or
|
|
170
|
+
* null. A host-bound source's account names the machine whose own files it
|
|
171
|
+
* reads (src/sources.js `hostBoundSource`): another machine's collector never
|
|
172
|
+
* reads it, and never reports on it, so it cannot turn the binding failing
|
|
173
|
+
* (0.12.3). Hostnames are case-insensitive.
|
|
174
|
+
*
|
|
175
|
+
* @param {{ source?: string, account?: string }} binding
|
|
176
|
+
* @param {string | null | undefined} host this collector's machine
|
|
177
|
+
* @returns {string | null} the machine the binding names
|
|
178
|
+
*/
|
|
179
|
+
export function foreignHostSource(binding, host) {
|
|
180
|
+
if (!hostBoundSource(binding?.source)) return null
|
|
181
|
+
const named = String(binding?.account ?? "").trim()
|
|
182
|
+
const here = String(host ?? "").trim()
|
|
183
|
+
if (!named || !here || named.toLowerCase() === here.toLowerCase()) return null
|
|
184
|
+
return named
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** The host's tools RPC has no plugin registered under that id right now: the plugin is starting, reloading or unloaded. */
|
|
188
|
+
function rpcUnavailable(error) {
|
|
189
|
+
return error?.type === "rpc.unavailable" || /^RPC is unavailable\b/.test(String(error?.message ?? ""))
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Mark a result whose failure is the host's RPC, not the binding's: it keeps
|
|
194
|
+
* its last good state in the store (nothing is reported for it), and the run
|
|
195
|
+
* says when it reads again (0.12.4, live at 22:19Z on 2026-11-17: a plugin
|
|
196
|
+
* being reloaded answered `RPC is unavailable`, and five bindings were reported
|
|
197
|
+
* failing).
|
|
198
|
+
*/
|
|
199
|
+
function transient(result, error, failure) {
|
|
200
|
+
if (!rpcUnavailable(error)) return false
|
|
201
|
+
result.transient = true
|
|
202
|
+
result.retry = "next run"
|
|
203
|
+
result.error = failure.message
|
|
204
|
+
result.code = undefined
|
|
205
|
+
result.action = undefined
|
|
206
|
+
return true
|
|
207
|
+
}
|
|
208
|
+
|
|
161
209
|
/** The input every `events_list` call to a binding sends: the page, its account, and the registry's input. */
|
|
162
210
|
/**
|
|
163
211
|
* The account an events_list call names: a named binding's, and for a source
|
|
164
212
|
* whose reads are scoped by account (`namesAccount`, gws) "default" too, so
|
|
165
213
|
* the plugin reads exactly the account the session's rules allow.
|
|
214
|
+
*
|
|
215
|
+
* **A declared source always names it, "default" included** (0.12.3): the
|
|
216
|
+
* contract binds a cursor to the account it was issued for, and a resumed read
|
|
217
|
+
* that names none is refused (`INPUT_INVALID`) — live on 2026-11-17, wisprflow
|
|
218
|
+
* v0.0.4, binding `wisprflow:default`: the first page read, and the second
|
|
219
|
+
* stopped for the missing account. A plugin that declares no source keeps the
|
|
220
|
+
* previous contract's rule.
|
|
166
221
|
*/
|
|
167
|
-
function accountInput(entry, account) {
|
|
222
|
+
function accountInput(entry, account, declared = null) {
|
|
168
223
|
const named = account || DEFAULT_ACCOUNT
|
|
224
|
+
if (declared?.contract === "sources" || entry?.contract === "sources") return { account: named }
|
|
169
225
|
return named !== DEFAULT_ACCOUNT || entry?.namesAccount ? { account: named } : {}
|
|
170
226
|
}
|
|
171
227
|
|
|
@@ -174,6 +230,10 @@ function accountInput(entry, account) {
|
|
|
174
230
|
* scope the person confirmed**. A scoped source that is not told its scope reads
|
|
175
231
|
* its plugin's whole option, and its page is then refused as out of scope.
|
|
176
232
|
*
|
|
233
|
+
* The account is decided by the declared source a binding's name stands for,
|
|
234
|
+
* when its package declares one: a binding made before that keeps collecting,
|
|
235
|
+
* and its resumed page names the account its cursor was issued for.
|
|
236
|
+
*
|
|
177
237
|
* @param {{ source: string, account?: string }} binding
|
|
178
238
|
* @param {string | undefined} cursor
|
|
179
239
|
* @param {Record<string, string[]>} [scope] the consented scope (`events.cursor` returns it)
|
|
@@ -183,7 +243,7 @@ export function listInput(binding, cursor, scope) {
|
|
|
183
243
|
return {
|
|
184
244
|
...(cursor ? { cursor } : {}),
|
|
185
245
|
limit: PAGE_LIMIT,
|
|
186
|
-
...accountInput(entry, binding.account),
|
|
246
|
+
...accountInput(entry, binding.account, resolveDeclaredSource(binding.source).entry),
|
|
187
247
|
...(entry?.input ?? {}),
|
|
188
248
|
...(isPlainObject(scope) && Object.keys(scope).length ? { scope } : {}),
|
|
189
249
|
}
|
|
@@ -792,7 +852,7 @@ function noteRefusal(result, refusal) {
|
|
|
792
852
|
*
|
|
793
853
|
* @param {{ scheduler?: { list(): Promise<any[]>, create(input: any): Promise<any>, remove(id: string): Promise<void> } | null, lister?: ReturnType<typeof hostSourceLister>, prober?: ReturnType<typeof hostSourceProber>, log?: any }} [input]
|
|
794
854
|
*/
|
|
795
|
-
export function createCollector({ scheduler = null, lister = null, prober = null, log } = {}) {
|
|
855
|
+
export function createCollector({ scheduler = null, lister = null, prober = null, log, host = null } = {}) {
|
|
796
856
|
const reported = new Map()
|
|
797
857
|
|
|
798
858
|
function noteOwner(source, account, owner) {
|
|
@@ -860,6 +920,13 @@ export function createCollector({ scheduler = null, lister = null, prober = null
|
|
|
860
920
|
// One broker deadline per tick (N7b): a broker that timed out this run does not cost each later binding.
|
|
861
921
|
lister?.resetBrokerTick?.()
|
|
862
922
|
for (const binding of collectableSources(sources, { only })) {
|
|
923
|
+
// Another machine's host-bound binding: not read, not reported, and so
|
|
924
|
+
// never turned failing here (0.12.3). The row says whose it is.
|
|
925
|
+
const elsewhere = foreignHostSource(binding, host)
|
|
926
|
+
if (elsewhere) {
|
|
927
|
+
results.push({ ...binding, pages: 0, accepted: 0, duplicates: 0, refused: 0, more: false, otherHost: elsewhere, done: true })
|
|
928
|
+
continue
|
|
929
|
+
}
|
|
863
930
|
if (!due(binding)) {
|
|
864
931
|
results.push({ ...binding, pages: 0, accepted: 0, duplicates: 0, refused: 0, more: false, notDue: true, everyMinutes: cadenceMs(binding.source) / 60_000, done: true })
|
|
865
932
|
continue
|
|
@@ -985,6 +1052,10 @@ export function createCollector({ scheduler = null, lister = null, prober = null
|
|
|
985
1052
|
// §8.3.4: a code is a pause, a hold or a reset. A reset reads once more
|
|
986
1053
|
// from the window; a pause pauses the binding through its callback.
|
|
987
1054
|
const failure = failureFromError(error)
|
|
1055
|
+
// A plugin whose RPC is not registered yet (or no longer) is the
|
|
1056
|
+
// host's state: the binding keeps the state it had, and this run
|
|
1057
|
+
// retries next run rather than failing the binding (0.12.4).
|
|
1058
|
+
if (transient(result, error, failure)) break
|
|
988
1059
|
// A PERMISSION_DENIED is decided by fact, never by its message: the broker's refusal is a changed
|
|
989
1060
|
// declaration only when the digest installed now differs from the one the person confirmed. Equal
|
|
990
1061
|
// digests mean the access itself was refused (a withdrawn grant, or the provider), which re-consenting
|
|
@@ -1040,6 +1111,9 @@ export function createCollector({ scheduler = null, lister = null, prober = null
|
|
|
1040
1111
|
result.error = failure.message
|
|
1041
1112
|
result.code = failure.code
|
|
1042
1113
|
result.action = failureAction(failure.code).action
|
|
1114
|
+
// The same transient read outside the page loop (a session, a cursor):
|
|
1115
|
+
// the binding keeps its state, and the run retries next run (0.12.4).
|
|
1116
|
+
transient(result, error, failure)
|
|
1043
1117
|
} finally {
|
|
1044
1118
|
result.done = true
|
|
1045
1119
|
}
|
|
@@ -1048,11 +1122,21 @@ export function createCollector({ scheduler = null, lister = null, prober = null
|
|
|
1048
1122
|
}
|
|
1049
1123
|
|
|
1050
1124
|
/**
|
|
1051
|
-
* Answer the person's bind requests: for each requested source only,
|
|
1052
|
-
*
|
|
1053
|
-
*
|
|
1054
|
-
*
|
|
1055
|
-
*
|
|
1125
|
+
* Answer the person's bind requests: for each requested source only, learn
|
|
1126
|
+
* the signed-in account and report it, or the source's own reason it could
|
|
1127
|
+
* not, with `report`. Nothing is bound here: the person confirms the reported
|
|
1128
|
+
* account.
|
|
1129
|
+
*
|
|
1130
|
+
* **How the account is learned (0.12.3).** A name the installed plugin
|
|
1131
|
+
* declares a source for is learned through the contract's `probe` (D11), in
|
|
1132
|
+
* the binding's session, whatever name the request carries: 0.12.2 recorded
|
|
1133
|
+
* the nine registry names (`granola`, `github`, …) and then probed them
|
|
1134
|
+
* through the previous contract's owner-only `events_list`, which granola and
|
|
1135
|
+
* linear refuse without an account and github refuses as too large. The
|
|
1136
|
+
* owner-only `events_list` now serves only a plugin that declares nothing.
|
|
1137
|
+
* A request recorded under a name that has since been declared is reported
|
|
1138
|
+
* under its own name — the store keys it that way — with a note naming the
|
|
1139
|
+
* declared source that binds instead.
|
|
1056
1140
|
*
|
|
1057
1141
|
* @param {{ requests: unknown, only?: string, sessionID?: string, report: (input: object) => Promise<unknown>, probes?: object[] }} input
|
|
1058
1142
|
*/
|
|
@@ -1061,11 +1145,20 @@ export function createCollector({ scheduler = null, lister = null, prober = null
|
|
|
1061
1145
|
const probe = { ...asked, reported: false }
|
|
1062
1146
|
probes.push(probe)
|
|
1063
1147
|
const entry = sourceEntry(asked.source)
|
|
1148
|
+
// The declared source this name stands for, when the declaration names one:
|
|
1149
|
+
// one declared source is probed under its own id, and a name with several
|
|
1150
|
+
// is not guessed between them.
|
|
1151
|
+
const resolved = resolveDeclaredSource(asked.source)
|
|
1152
|
+
const reading = resolved.entry?.contract === "sources" ? resolved.entry : entry
|
|
1153
|
+
const renamed = reading.contract === "sources" && reading.source !== asked.source ? reading.source : null
|
|
1064
1154
|
// The binding's own session first: when it cannot be made, nothing is read and
|
|
1065
1155
|
// nothing is reported (it is not the source's failure, so no back-off either).
|
|
1066
1156
|
let session
|
|
1067
1157
|
try {
|
|
1068
|
-
|
|
1158
|
+
// The declared source a retired name stands for decides the session's rules too: the probe runs in
|
|
1159
|
+
// the binding's own session, and that session must allow the probe action the declaration asserts.
|
|
1160
|
+
const binding = renamed ? { ...asked, read: reading.source } : asked
|
|
1161
|
+
session = typeof sessionID === "function" ? await sessionID(binding) : sessionID
|
|
1069
1162
|
} catch (error) {
|
|
1070
1163
|
probe.error = oneLine(errorMessage(error), 300)
|
|
1071
1164
|
continue
|
|
@@ -1073,28 +1166,34 @@ export function createCollector({ scheduler = null, lister = null, prober = null
|
|
|
1073
1166
|
let body
|
|
1074
1167
|
try {
|
|
1075
1168
|
// A declared source has the contract's `probe` (D11); the owner-only
|
|
1076
|
-
// `events_list({ limit: 0 })` page is the previous contract's
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1169
|
+
// `events_list({ limit: 0 })` page is the previous contract's, and only
|
|
1170
|
+
// for a plugin that declares no source.
|
|
1171
|
+
const answer = reading.contract === "sources"
|
|
1172
|
+
? await (prober ? prober(reading.source, { account: asked.account }, session) : Promise.reject(new Error("this host gives plugins no tools RPC, so a source cannot be probed")))
|
|
1173
|
+
: 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")))
|
|
1174
|
+
// A name the declaration has replaced says which source binds instead:
|
|
1175
|
+
// the store refuses a retired name, so the person needs the one to use.
|
|
1176
|
+
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
|
|
1080
1177
|
if (answer?.owner?.id) {
|
|
1081
1178
|
const owner = { id: oneLine(answer.owner.id, 300), label: oneLine(answer.owner.label ?? answer.owner.email ?? answer.owner.id, 300) }
|
|
1179
|
+
const setup = answer.setup || reading.setupOptions || null
|
|
1082
1180
|
body = {
|
|
1083
1181
|
source: asked.source,
|
|
1084
1182
|
account: asked.account,
|
|
1085
1183
|
owner,
|
|
1086
1184
|
reported_account: answer.account,
|
|
1087
1185
|
// The installed declaration's digest, read from disk: a re-consent records the digest the installed
|
|
1088
|
-
// package has now, so jelly never refuses a read made under the old one.
|
|
1089
|
-
|
|
1186
|
+
// package has now, so jelly never refuses a read made under the old one. Only for the declared id
|
|
1187
|
+
// itself: a consent recorded under a retired name never reads that declaration.
|
|
1188
|
+
...(renamed === null && reading.descriptorHash ? { digest: reading.descriptorHash } : {}),
|
|
1090
1189
|
// The note is the source's or the plugin's own sentence: it is
|
|
1091
|
-
// reported to the store (`
|
|
1190
|
+
// reported to the store (`source_requests.note`) and shown from it,
|
|
1092
1191
|
// so it is redacted here, where it is written (review F1/F2).
|
|
1093
|
-
...(
|
|
1192
|
+
...(replaced || setup ? { note: oneLine(errorMessage([replaced, setup].filter(Boolean).join(" ")), 400) } : {}),
|
|
1094
1193
|
}
|
|
1095
1194
|
probe.owner = owner
|
|
1096
1195
|
} else {
|
|
1097
|
-
body = { source: asked.source, account: asked.account, note: oneLine(errorMessage(answer?.setup || `${
|
|
1196
|
+
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) }
|
|
1098
1197
|
}
|
|
1099
1198
|
} catch (error) {
|
|
1100
1199
|
body = { source: asked.source, account: asked.account, note: oneLine(errorMessage(error), 400) }
|
package/src/plugins/discovery.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Discovery of plugin-declared Memory (DESIGN-PLUGIN-MEMORY §2.3), read-only:
|
|
3
3
|
*
|
|
4
|
-
* 1. **List** `ctx.plugin.list()
|
|
4
|
+
* 1. **List** `ctx.plugin.list()` (an array, or the host's `{ location, data }`): active `package` and `local` plugins, not
|
|
5
5
|
* `builtin`, `sdk` or Memory itself.
|
|
6
6
|
* 2. **Find** each one's installed package (src/plugins/locate.js).
|
|
7
7
|
* 3. **Read** `name`, `version` and `memory` from that `package.json`. No
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
* or the protocol.
|
|
28
28
|
*/
|
|
29
29
|
import { LAYOUT_CHANGED, cacheRoot, locate } from "./locate.js"
|
|
30
|
+
import { pluginList } from "./list.js"
|
|
30
31
|
import { canonicalJSON, validateManifest } from "./manifest.js"
|
|
31
32
|
import { CONTRACT_LABELS, readDeclared } from "./descriptor.js"
|
|
32
33
|
import { setDeclaredSources, setInstalledVersions, sourceEntriesOf } from "../sources.js"
|
|
@@ -245,7 +246,7 @@ export function createPluginDiscovery({ ctx, runtime, toolkit, clock = REAL_CLOC
|
|
|
245
246
|
if (resolved.invalid || resolved.error) throw new Error(resolved.invalid || resolved.error)
|
|
246
247
|
where = { space: resolved.context.space_id }
|
|
247
248
|
}
|
|
248
|
-
const result = await discover({ plugins: await ctx.plugin.list(), root: await root(), readRpc: reader, clock })
|
|
249
|
+
const result = await discover({ plugins: pluginList(await ctx.plugin.list(), log), root: await root(), readRpc: reader, clock })
|
|
249
250
|
// A full report: every plugin this machine has; the records service marks the ones it no longer names as missing.
|
|
250
251
|
await records.call("plugins.report", { layout: result.layout, full: true, plugins: result.plugins }, where)
|
|
251
252
|
// The declarations the collector reads under are published **only after**
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What `ctx.plugin.list()` answers, as its list of plugins.
|
|
3
|
+
*
|
|
4
|
+
* OpenCode 2.2.6 answers `{ location, data: [...] }`, not an array (live on the
|
|
5
|
+
* owner's machine at 19:10Z on 2026-11-17: 116 entries), while `/api/plugin`
|
|
6
|
+
* answers a bare array. Both are read here, and anything else is no list at
|
|
7
|
+
* all: a warning in the log, never a throw, and never a plugin.
|
|
8
|
+
*
|
|
9
|
+
* @param {unknown} answer what the host answered
|
|
10
|
+
* @param {{ warn?: (message: string, detail?: object) => void } | null} [log]
|
|
11
|
+
* @returns {any[]} the plugins the answer names, or none
|
|
12
|
+
*/
|
|
13
|
+
export function pluginList(answer, log = null) {
|
|
14
|
+
if (Array.isArray(answer)) return answer
|
|
15
|
+
if (answer !== null && typeof answer === "object" && Array.isArray(answer.data)) return answer.data
|
|
16
|
+
log?.warn?.("plugin list is not a list", { shape: answer === null ? "null" : typeof answer })
|
|
17
|
+
return []
|
|
18
|
+
}
|
package/src/plugins/locate.js
CHANGED
|
@@ -216,7 +216,14 @@ export function parseRegistryTarget(target) {
|
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
function locateGit(target, version, root) {
|
|
219
|
-
|
|
219
|
+
// OpenCode 2.2.6 reports a package plugin's source as `{ type: "package",
|
|
220
|
+
// target }` and **no `version`** (`@opencode/core` `pluginSource`). Refusing
|
|
221
|
+
// then made every family plugin `unverified` and the scan `LAYOUT_CHANGED`,
|
|
222
|
+
// so no declaration was ever read on plain OpenCode (live, 2026-11-17).
|
|
223
|
+
// Without a commit the store's copies for this target are the candidates, and
|
|
224
|
+
// `choose` keeps the one declaration they agree on; with one, only the copy
|
|
225
|
+
// the host names is read.
|
|
226
|
+
const commit = typeof version === "string" && /^[0-9a-f]{7,64}$/.test(version) ? version : null
|
|
220
227
|
const suffix = `-${createHash("sha256").update(target).digest("hex").slice(0, 12)}`
|
|
221
228
|
let dirs
|
|
222
229
|
try {
|
|
@@ -245,12 +252,16 @@ function locateGit(target, version, root) {
|
|
|
245
252
|
const dependency = Object.entries(manifest.value.dependencies).find(([, spec]) => spec === target)?.[0]
|
|
246
253
|
if (!dependency) continue
|
|
247
254
|
const locked = lock.value.packages[`node_modules/${dependency}`]
|
|
248
|
-
if (typeof locked?.resolved !== "string"
|
|
255
|
+
if (typeof locked?.resolved !== "string") continue
|
|
256
|
+
if (commit !== null && !locked.resolved.endsWith(`#${commit}`)) continue
|
|
249
257
|
found.push({ ...packageIn(stamp, dependency, root), dependency })
|
|
250
258
|
}
|
|
251
259
|
}
|
|
252
|
-
//
|
|
253
|
-
//
|
|
260
|
+
// A stamp whose declaration differs from another stamp's is refused by
|
|
261
|
+
// `choose` ("differ"): the digest is what the person consents to, so the copy
|
|
262
|
+
// is never guessed between them. The store holds the target at another commit
|
|
263
|
+
// than the host names: the install is older or newer than `/api/plugin` says,
|
|
264
|
+
// and it is never read as that version's.
|
|
254
265
|
if (found.length === 0 && dirs.length > 0) return { ok: false, cause: "stale", reason: NOT_AT_COMMIT }
|
|
255
266
|
return choose(found, () => ({ kind: "git" }))
|
|
256
267
|
}
|
package/src/plugins/verify.js
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
* Memory's credential can report a plugin. So before a binding collects, the
|
|
5
5
|
* collector itself:
|
|
6
6
|
*
|
|
7
|
-
* 1. finds the plugin in OpenCode's own list (`ctx.plugin.list()`
|
|
7
|
+
* 1. finds the plugin in OpenCode's own list (`ctx.plugin.list()`: `{ location, data }` on
|
|
8
|
+
* 2.2.6, a bare array from `/api/plugin`), active,
|
|
8
9
|
* with no failed twin of the same id;
|
|
9
10
|
* 2. checks the pin: the same source kind and target or path, and the same
|
|
10
11
|
* package name, as the person confirmed;
|
|
@@ -20,6 +21,7 @@
|
|
|
20
21
|
* collector accept what is really on disk, intersected with the consent.
|
|
21
22
|
*/
|
|
22
23
|
import { LAYOUT_CHANGED, locate } from "./locate.js"
|
|
24
|
+
import { pluginList } from "./list.js"
|
|
23
25
|
import { validateManifest } from "./manifest.js"
|
|
24
26
|
import { effectiveSource } from "./grants.js"
|
|
25
27
|
|
|
@@ -27,12 +29,12 @@ const stop = (kind, reason) => ({ ok: false, stop: kind, reason })
|
|
|
27
29
|
|
|
28
30
|
/**
|
|
29
31
|
* @param {{ plugin_id: string, source: string, package: string, pin: { kind: string, ref: string }, digest: string, live_digest?: string | null, snapshot: { source: any }, state: string }} consent
|
|
30
|
-
* @param {{ plugins: any[], root: string }} where OpenCode's plugin list and the cache root
|
|
32
|
+
* @param {{ plugins: any[] | { data: any[] }, root: string, log?: { warn?: (message: string, detail?: object) => void } | null }} where OpenCode's plugin list (either shape) and the cache root
|
|
31
33
|
* @returns {Promise<{ ok: true, effective: ReturnType<typeof effectiveSource>, live: any, digest: string } | { ok: false, stop: string, reason: string }>}
|
|
32
34
|
*/
|
|
33
|
-
export async function verifyConsent(consent, { plugins, root }) {
|
|
35
|
+
export async function verifyConsent(consent, { plugins, root, log = null }) {
|
|
34
36
|
if (consent.state !== "on") return stop("stopped", consent.reason ?? `the binding is ${consent.state}`)
|
|
35
|
-
const all =
|
|
37
|
+
const all = pluginList(plugins, log)
|
|
36
38
|
const info = all.find((entry) => entry?.id === consent.plugin_id && entry?.state?.status === "active")
|
|
37
39
|
if (!info) return stop("missing", `${consent.plugin_id} is not running in this OpenCode`)
|
|
38
40
|
if (all.some((entry) => entry?.id === consent.plugin_id && entry?.state?.status === "failed" && /^Duplicate plugin ID\b/.test(String(entry.state.error ?? "")))) {
|
package/src/sources.js
CHANGED
|
@@ -31,9 +31,41 @@ import { maxBytesOf } from "./plugins/source-contract/vendor/descriptor.js"
|
|
|
31
31
|
/** A binding's account name: no wildcard (`*`, `?`), separator (`:`, `/`) or space, and never empty. */
|
|
32
32
|
export const ACCOUNT_NAME = /^[A-Za-z0-9][A-Za-z0-9_.@+-]{0,127}$/
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* The sources whose **account names the machine that reads them**: the
|
|
36
|
+
* sessions a history source indexes live in this machine's own files, so a
|
|
37
|
+
* binding of one is that machine's binding, and no other machine can read it
|
|
38
|
+
* (0.12.3). A collector on another machine leaves such a binding alone: it is
|
|
39
|
+
* not read, not reported, and so never turned failing.
|
|
40
|
+
*
|
|
41
|
+
* It is named here, beside the catalog, because the account is the only place
|
|
42
|
+
* a machine is named: the contract has no field for it. A declared
|
|
43
|
+
* `history.sessions` is the same source under its contract id.
|
|
44
|
+
*/
|
|
45
|
+
const HOST_BOUND = new Set(["history", "history.sessions"])
|
|
46
|
+
|
|
47
|
+
/** True when only the machine its account names may collect this source (0.12.3). */
|
|
48
|
+
export function hostBoundSource(source) {
|
|
49
|
+
return HOST_BOUND.has(String(source ?? ""))
|
|
50
|
+
}
|
|
51
|
+
|
|
34
52
|
/** The timer's default cadence per source, in minutes. */
|
|
35
53
|
export const DEFAULT_EVERY_MINUTES = 30
|
|
36
54
|
|
|
55
|
+
/**
|
|
56
|
+
* The owner's cadence policy, by namespace (0.12.4): **X's reads are billed**, so
|
|
57
|
+
* a binding of one of its sources is read once a day, whatever the plugin's own
|
|
58
|
+
* declaration or cadence says. A plugin's `cadence.providerMinMinutes` is the
|
|
59
|
+
* floor the provider imposes, never the person's choice, so it cannot shorten
|
|
60
|
+
* this; it can only lengthen it.
|
|
61
|
+
*/
|
|
62
|
+
const OWNER_CADENCE_MINUTES = Object.freeze({ x: 1440 })
|
|
63
|
+
|
|
64
|
+
/** The shortest cadence the owner allows this namespace, in minutes, or 0 where they set none. */
|
|
65
|
+
function ownerCadence(namespace) {
|
|
66
|
+
return OWNER_CADENCE_MINUTES[String(namespace ?? "")] ?? 0
|
|
67
|
+
}
|
|
68
|
+
|
|
37
69
|
function freezePermission(permission) {
|
|
38
70
|
return Object.freeze({
|
|
39
71
|
...permission,
|
|
@@ -89,7 +121,7 @@ export const PREVIOUS_CONTRACT_SOURCES = Object.freeze(
|
|
|
89
121
|
namespace: "x",
|
|
90
122
|
package: "@joe-broadhead/opencode-x",
|
|
91
123
|
minVersion: "0.0.4",
|
|
92
|
-
|
|
124
|
+
// Once a day: its reads are billed, and the owner's cadence policy is below (`ownerCadence`).
|
|
93
125
|
permission: { actions: ["x_get_users_me", "x_get_users_mentions", "x_get_users_bookmarks", "x_get_users_timeline"] },
|
|
94
126
|
setupOptions:
|
|
95
127
|
'X reads are billed. Set the x plugin\'s options "events": {"feeds": ["mentions", "bookmarks"], "maxCalls": 2}, and "ownsXApp": true only if the signed-in account owns the developer app (it lowers the price X charges); then restart OpenCode.',
|
|
@@ -145,7 +177,6 @@ export const PREVIOUS_CONTRACT_SOURCES = Object.freeze(
|
|
|
145
177
|
tool: "events_list",
|
|
146
178
|
input: {},
|
|
147
179
|
minVersion: null,
|
|
148
|
-
everyMinutes: DEFAULT_EVERY_MINUTES,
|
|
149
180
|
ownerProbe: "limit1",
|
|
150
181
|
setupOptions: null,
|
|
151
182
|
namesAccount: false,
|
|
@@ -153,6 +184,9 @@ export const PREVIOUS_CONTRACT_SOURCES = Object.freeze(
|
|
|
153
184
|
contractLabel: "events_list (previous)",
|
|
154
185
|
kind: "events",
|
|
155
186
|
...entry,
|
|
187
|
+
// The owner's cadence outranks the registry's own: X is read once a day
|
|
188
|
+
// because its reads are billed (0.12.4).
|
|
189
|
+
everyMinutes: Math.max(DEFAULT_EVERY_MINUTES, Number(entry.everyMinutes) || 0, ownerCadence(entry.namespace)),
|
|
156
190
|
input: Object.freeze({ ...(entry.input ?? {}) }),
|
|
157
191
|
permission: freezePermission({
|
|
158
192
|
events: `${entry.namespace}_events_list`,
|
|
@@ -307,6 +341,50 @@ export function sourceEntry(source) {
|
|
|
307
341
|
return declared.get(name) ?? BY_SOURCE.get(name) ?? null
|
|
308
342
|
}
|
|
309
343
|
|
|
344
|
+
/**
|
|
345
|
+
* Every declared source one name stands for (0.12.3): its id, the name its page
|
|
346
|
+
* carries (`input.source`, which is the previous contract's name for the same
|
|
347
|
+
* feed), its namespace, or its id's last part. The nine family plugins kept
|
|
348
|
+
* their registry names — `granola`, `gmail`, `slack` — as the page names their
|
|
349
|
+
* declarations send, so a bind request names one of them and the declared
|
|
350
|
+
* source is what it means.
|
|
351
|
+
*
|
|
352
|
+
* @param {string} source
|
|
353
|
+
* @returns {object[]} the declared entries, in binding order; empty when nothing declares for the name
|
|
354
|
+
*/
|
|
355
|
+
export function declaredForName(source) {
|
|
356
|
+
const wanted = String(source ?? "")
|
|
357
|
+
if (wanted === "") return []
|
|
358
|
+
const exact = declared.get(wanted)
|
|
359
|
+
if (exact) return [exact]
|
|
360
|
+
const byPage = [...declared.values()].filter((entry) => entry.pageSource === wanted)
|
|
361
|
+
if (byPage.length > 0) return byPage
|
|
362
|
+
return [...declared.values()].filter((entry) => entry.namespace === wanted || entry.source.endsWith(`.${wanted}`))
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* What a bind request's name means under the installed declarations: the one
|
|
367
|
+
* declared source it stands for, or the several it could be.
|
|
368
|
+
*
|
|
369
|
+
* A name that is one declared source's id, page name or namespace is that
|
|
370
|
+
* source. **Several** declared sources under one name (a namespace such as
|
|
371
|
+
* `gws`, whose `gws.gmail` and `gws.calendar` are different feeds) resolve to
|
|
372
|
+
* none of them: the bind must name the one it means, because reading the wrong
|
|
373
|
+
* feed is not a choice Memory makes for the person. An events source wins over a
|
|
374
|
+
* snapshot source of the same name, and a snapshot alone is returned so the
|
|
375
|
+
* caller can say why this release does not bind it (G1).
|
|
376
|
+
*
|
|
377
|
+
* @param {string} source
|
|
378
|
+
* @returns {{ entry: object | null, options: string[] }} `options`: the ids to name instead, when several
|
|
379
|
+
*/
|
|
380
|
+
export function resolveDeclaredSource(source) {
|
|
381
|
+
const matches = declaredForName(source)
|
|
382
|
+
const events = matches.filter((entry) => entry.kind === "events")
|
|
383
|
+
const candidates = events.length > 0 ? events : matches
|
|
384
|
+
if (candidates.length === 1) return { entry: candidates[0], options: [] }
|
|
385
|
+
return { entry: null, options: candidates.map((entry) => entry.source) }
|
|
386
|
+
}
|
|
387
|
+
|
|
310
388
|
/** True when a package declares a source under the contract, so its legacy alias is retired (audit 1.3). */
|
|
311
389
|
export function legacyRetired(source) {
|
|
312
390
|
const entry = BY_SOURCE.get(String(source ?? ""))
|
|
@@ -388,13 +466,14 @@ function declaredEntry(plugin, item) {
|
|
|
388
466
|
const named = item.accounts?.named === true
|
|
389
467
|
const stated = Number(item.cadence?.providerMinMinutes)
|
|
390
468
|
const floor = Number.isInteger(stated) && stated >= 1 ? stated : null
|
|
469
|
+
const namespace = String(item.id).split(".")[0]
|
|
391
470
|
return Object.freeze({
|
|
392
471
|
source: item.id,
|
|
393
472
|
pluginId: plugin.id,
|
|
394
473
|
package: plugin.package,
|
|
395
474
|
version: plugin.version ?? null,
|
|
396
475
|
rpc: `${plugin.id}.tools`,
|
|
397
|
-
namespace
|
|
476
|
+
namespace,
|
|
398
477
|
tool: item.tool,
|
|
399
478
|
kind: item.kind,
|
|
400
479
|
reads: item.reads ?? null,
|
|
@@ -406,7 +485,9 @@ function declaredEntry(plugin, item) {
|
|
|
406
485
|
// rules and the plugin's account always agree.
|
|
407
486
|
namesAccount: named,
|
|
408
487
|
ownerProbe: "probe",
|
|
409
|
-
|
|
488
|
+
// A declared X source is read once a day too: the plugin's own cadence can
|
|
489
|
+
// only lengthen the owner's policy, never shorten it (0.12.4).
|
|
490
|
+
everyMinutes: Math.max(DEFAULT_EVERY_MINUTES, floor ?? 0, ownerCadence(namespace)),
|
|
410
491
|
minVersion: null,
|
|
411
492
|
setupOptions: null,
|
|
412
493
|
contract: "sources",
|
|
@@ -451,7 +532,8 @@ function memoryEntries(plugin) {
|
|
|
451
532
|
pageSource: pageSourceOf({ id: source.id, input: source.input }),
|
|
452
533
|
namesAccount: source.accounts === "multi",
|
|
453
534
|
ownerProbe: "limit0",
|
|
454
|
-
|
|
535
|
+
// The owner's cadence applies to a previous-contract declaration too, by the source id's namespace.
|
|
536
|
+
everyMinutes: Math.max(DEFAULT_EVERY_MINUTES, Number(source.cadence?.everyMinutes) || 0, ownerCadence(String(source.id).split(".")[0])),
|
|
455
537
|
minVersion: null,
|
|
456
538
|
setupOptions: null,
|
|
457
539
|
contract: "memory",
|
package/src/tools/spaces.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { contextScopeLabel } from "../scope.js"
|
|
2
2
|
import { DEFAULT_ACCOUNT, isAccountName, isSourceName } from "../collector.js"
|
|
3
|
-
import { bindableSource, installedVersionOf, kindProblem, knownSources, releaseNote, sourceEntry } from "../sources.js"
|
|
3
|
+
import { bindableSource, installedVersionOf, kindProblem, knownSources, releaseNote, resolveDeclaredSource, sourceEntry } from "../sources.js"
|
|
4
4
|
import { createProfileReads, profileText } from "../views/profile.js"
|
|
5
5
|
import { asksToDecline, latestWord, mustRefuse, namesProposal } from "../requests.js"
|
|
6
6
|
import { errorMessage, isPlainObject, oneLine } from "../util.js"
|
|
@@ -348,22 +348,38 @@ export function createSpacesActions(toolkit) {
|
|
|
348
348
|
}
|
|
349
349
|
}
|
|
350
350
|
|
|
351
|
-
/**
|
|
351
|
+
/**
|
|
352
|
+
* A bind or unbind's source and account; `known` requires a source in the
|
|
353
|
+
* registry (src/sources.js).
|
|
354
|
+
*
|
|
355
|
+
* A name is resolved to the declared source it stands for (0.12.3): its id,
|
|
356
|
+
* the name its page carries (`gmail`, `granola`, `slack`), or its namespace.
|
|
357
|
+
* One declared source is bound under its own id, and the answer says so; a
|
|
358
|
+
* namespace with several (`gws`) names them instead, because which feed to
|
|
359
|
+
* read is the person's choice, not Memory's. Nothing that declares keeps the
|
|
360
|
+
* previous contract's name, so every request, report, binding and listing is
|
|
361
|
+
* keyed by the declared id.
|
|
362
|
+
*/
|
|
352
363
|
function bindingOf(value, { known = false } = {}) {
|
|
353
364
|
const source = String(value?.source ?? "").trim()
|
|
354
365
|
const asked = String(value?.account ?? "").trim()
|
|
355
366
|
const account = asked || DEFAULT_ACCOUNT
|
|
356
367
|
if (!isSourceName(source)) return { error: `"${oneLine(source || "(none)", 60)}" is not a source name: one of ${knownSources().join(", ")}.` }
|
|
357
|
-
|
|
368
|
+
const resolved = resolveDeclaredSource(source)
|
|
369
|
+
if (resolved.options.length > 1) {
|
|
370
|
+
return { error: `"${oneLine(source, 60)}" names ${resolved.options.length} sources this release binds separately: ${resolved.options.join(", ")}. Bind the one you mean.` }
|
|
371
|
+
}
|
|
372
|
+
const bound = resolved.entry?.source ?? source
|
|
373
|
+
if (known && !bindableSource(bound)) {
|
|
358
374
|
// Said plainly, and each for its own reason: a kind this release does not
|
|
359
375
|
// read (G1), or an installed release too old to serve it (G3). A name
|
|
360
376
|
// Memory does not know at all keeps the list.
|
|
361
|
-
const kind = kindProblem(
|
|
377
|
+
const kind = kindProblem(bound)
|
|
362
378
|
if (kind) return { error: `${kind.message} ${kind.next}` }
|
|
363
|
-
return { error: `"${oneLine(
|
|
379
|
+
return { error: `"${oneLine(bound, 60)}" is not a source Memory knows: one of ${knownSources().join(", ")}.` }
|
|
364
380
|
}
|
|
365
381
|
if (!isAccountName(account)) return { error: `"${oneLine(account, 60)}" is not an account name.` }
|
|
366
|
-
return { source, account, asked: Boolean(asked) }
|
|
382
|
+
return { source: bound, account, asked: Boolean(asked), from: bound === source ? null : source }
|
|
367
383
|
}
|
|
368
384
|
|
|
369
385
|
const describeBinding = (row, behind = null) => {
|
|
@@ -459,10 +475,24 @@ export function createSpacesActions(toolkit) {
|
|
|
459
475
|
* server's refusal, with the server's next step.
|
|
460
476
|
*/
|
|
461
477
|
async function bindSource(value, space, rows, requests) {
|
|
478
|
+
// A name the previous contract knows is checked against the installs before it
|
|
479
|
+
// is asked for (0.12.3): a package that declares its source now is bound under
|
|
480
|
+
// the declared id, and the scan is the one discovery already makes — read-only,
|
|
481
|
+
// and coalesced with any scan under way. A declared id needs no scan.
|
|
482
|
+
const named = String(value?.source ?? "").trim()
|
|
483
|
+
if (typeof toolkit.plugins?.scan === "function" && sourceEntry(named)?.contract === "events_list" && resolveDeclaredSource(named).entry === null) {
|
|
484
|
+
try {
|
|
485
|
+
await toolkit.plugins.scan("bind")
|
|
486
|
+
} catch (error) {
|
|
487
|
+
log.warn("plugin discovery failed before a bind", { error: errorMessage(error) })
|
|
488
|
+
}
|
|
489
|
+
}
|
|
462
490
|
const asked = bindingOf(value, { known: true })
|
|
463
491
|
if (asked.error) return `not bound: ${asked.error}`
|
|
464
492
|
const name = `${asked.source}${asked.asked ? `:${asked.account}` : ""}`
|
|
465
|
-
|
|
493
|
+
// The declared source this release binds, and — when the person asked by the
|
|
494
|
+
// previous contract's name — the name they used (0.12.3).
|
|
495
|
+
const label = `${asked.source}${asked.from ? ` (asked as ${oneLine(asked.from, 60)})` : ""}`
|
|
466
496
|
const link = consoleAt("sources")
|
|
467
497
|
const matches = (row, ...accounts) => row.source === asked.source && (!asked.asked || accounts.some((account) => (account || DEFAULT_ACCOUNT) === asked.account))
|
|
468
498
|
const bound = rows.find((row) => matches(row, row.account) && row.status === "confirmed" && (row.enabled === true || row.enabled === 1))
|
|
@@ -521,36 +551,42 @@ export function createSpacesActions(toolkit) {
|
|
|
521
551
|
if (input?.unbind) {
|
|
522
552
|
const binding = bindingOf(input.unbind)
|
|
523
553
|
if (binding.error) return text(`not unbound: ${binding.error}`)
|
|
524
|
-
|
|
525
|
-
|
|
554
|
+
// A binding made before its package declared keeps the name it was made
|
|
555
|
+
// under: ending it by that name ends that row, never a declared source of
|
|
556
|
+
// the same account (0.12.3).
|
|
557
|
+
const askedName = String(input?.unbind?.source ?? "").trim()
|
|
558
|
+
const held = [...rows, ...requests].some((entry) => entry.source === askedName && (entry.account || DEFAULT_ACCOUNT) === binding.account)
|
|
559
|
+
const target = binding.from && held ? { ...binding, source: askedName } : binding
|
|
560
|
+
const row = rows.find((entry) => entry.source === target.source && (entry.account || DEFAULT_ACCOUNT) === target.account)
|
|
561
|
+
const request = requests.find((entry) => entry.source === target.source && (entry.account || DEFAULT_ACCOUNT) === target.account)
|
|
526
562
|
if (!row && request) {
|
|
527
563
|
if (space.shared) return text(personalOnly("cancelled"))
|
|
528
564
|
// Only a bind request: nothing was collected, so cancelling it deletes nothing.
|
|
529
565
|
try {
|
|
530
|
-
await records().call("sources.cancel", { source:
|
|
566
|
+
await records().call("sources.cancel", { source: target.source, account: binding.account }, space.where)
|
|
531
567
|
} catch (error) {
|
|
532
568
|
return fail(`not cancelled: ${recordsFailure(error)}`)
|
|
533
569
|
}
|
|
534
570
|
// No session keeps this binding's allow rules once nobody asks for it.
|
|
535
|
-
await toolkit.collector?.forgetSession?.({ source:
|
|
536
|
-
return text(`cancelled the bind request for ${
|
|
571
|
+
await toolkit.collector?.forgetSession?.({ source: target.source, account: binding.account })
|
|
572
|
+
return text(`cancelled the bind request for ${target.source}:${binding.account} in ${space.label}; nothing had been collected from it.`)
|
|
537
573
|
}
|
|
538
|
-
if (!row) return text(`not unbound: ${
|
|
574
|
+
if (!row) return text(`not unbound: ${target.source}:${binding.account} is not a source in ${space.label}.`)
|
|
539
575
|
if (input?.confirm !== true) {
|
|
540
576
|
return text(
|
|
541
|
-
`preview, nothing changed: unbinding ${
|
|
577
|
+
`preview, nothing changed: unbinding ${target.source}:${binding.account} (${oneLine(row.owner_label || row.owner_id || "owner unknown", 120)}) stops its collection and deletes every event collected from it in ${space.label}. Journal pages and memories already made from them stay. Call again with "confirm": true to unbind.`,
|
|
542
578
|
)
|
|
543
579
|
}
|
|
544
|
-
const denied = await gateUnbind(
|
|
580
|
+
const denied = await gateUnbind(target, `stops collecting ${target.source}:${binding.account} and deletes every event collected from it in ${oneLine(space.context?.space_name || space.spaceId || "this space", 120)}; pages and memories already made from them stay.`)
|
|
545
581
|
if (denied) return text(`not unbound (approval): ${denied}`)
|
|
546
582
|
let answer
|
|
547
583
|
try {
|
|
548
|
-
answer = await records().call("sources.unbind", { source:
|
|
584
|
+
answer = await records().call("sources.unbind", { source: target.source, account: binding.account }, space.where)
|
|
549
585
|
} catch (error) {
|
|
550
586
|
log.warn("sources unbind failed", error)
|
|
551
587
|
return fail(`${error?.outcomeUnknown ? "unbind outcome unknown" : "not unbound"}: ${recordsFailure(error)}`)
|
|
552
588
|
}
|
|
553
|
-
await toolkit.collector?.forgetSession?.({ source:
|
|
589
|
+
await toolkit.collector?.forgetSession?.({ source: target.source, account: binding.account })
|
|
554
590
|
let after = rows.filter((entry) => entry !== row)
|
|
555
591
|
try {
|
|
556
592
|
after = await listSources(space.where)
|
|
@@ -559,7 +595,7 @@ export function createSpacesActions(toolkit) {
|
|
|
559
595
|
}
|
|
560
596
|
const sync = await syncCollector(after)
|
|
561
597
|
return text(
|
|
562
|
-
`unbound ${
|
|
598
|
+
`unbound ${target.source}:${binding.account} in ${space.label}: collection stopped and ${Number(answer?.deleted_events) || 0} event(s) were deleted.${sync ? ` ${sync}` : ""}`,
|
|
563
599
|
)
|
|
564
600
|
}
|
|
565
601
|
|
package/src/util.js
CHANGED
|
@@ -174,6 +174,34 @@ export function errorMessage(error) {
|
|
|
174
174
|
return NO_ERROR_MESSAGE
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
+
/** A message that already names a code (`AUTH_REQUIRED: …`): a second one would be noise. */
|
|
178
|
+
const CODED_PREFIX = /^[A-Z][A-Z0-9_]+: /
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* A failure as one line of text a person reads: `CODE: what happened`, or the
|
|
182
|
+
* message alone when it names no code (or only the contract's own
|
|
183
|
+
* `UNAVAILABLE`, which says the read failed and no more). The code is kept
|
|
184
|
+
* because a provider's refusal is diagnosed by it (`AUTH_REQUIRED` is a
|
|
185
|
+
* sign-in, `RATE_LIMITED` is a wait), and the message alone has lost it by the
|
|
186
|
+
* time it is stored.
|
|
187
|
+
*
|
|
188
|
+
* It is built from `errorMessage`, so a failure that arrives as a plain object
|
|
189
|
+
* reads as its own words: never `String(object)`, which is `[object Object]`.
|
|
190
|
+
* A message that already names the code (`AUTH_REQUIRED: …`, which is how a
|
|
191
|
+
* coded error is written) is not prefixed twice.
|
|
192
|
+
*
|
|
193
|
+
* @param {unknown} error
|
|
194
|
+
* @param {number} [max]
|
|
195
|
+
*/
|
|
196
|
+
export function failureText(error, max = 300) {
|
|
197
|
+
const text = oneLine(errorMessage(error), max)
|
|
198
|
+
const code = oneLine(codeOf(error), 60)
|
|
199
|
+
// `UNAVAILABLE` is the contract's word for "the read failed, retry": a
|
|
200
|
+
// failure that names nothing more specific reads as its own sentence.
|
|
201
|
+
if (!code || code === "UNAVAILABLE" || text === code || CODED_PREFIX.test(text)) return text
|
|
202
|
+
return oneLine(`${code}: ${text}`, max)
|
|
203
|
+
}
|
|
204
|
+
|
|
177
205
|
/** The withheld phrase, naming the code so a failure is still diagnosable. */
|
|
178
206
|
function withheld(code) {
|
|
179
207
|
return code ? `${ERROR_WITHHELD} (code ${oneLine(code, 60)})` : ERROR_WITHHELD
|