@joe-broadhead/opencode-mem 0.12.2 → 0.12.3
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 +19 -0
- package/package.json +1 -1
- package/src/collector-service.js +1 -1
- package/src/collector.js +64 -20
- package/src/plugins/locate.js +15 -4
- package/src/sources.js +44 -0
- package/src/tools/spaces.js +54 -18
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,25 @@
|
|
|
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.3] - 2026-11-17
|
|
7
|
+
|
|
8
|
+
### Fixed
|
|
9
|
+
|
|
10
|
+
- Memory reads the sources an installed plugin declares on plain OpenCode. OpenCode 2.2.6 reports a
|
|
11
|
+
git plugin with no commit, and the locator refused every such install, so no declaration was read
|
|
12
|
+
and every bind took the previous contract's path. Without a commit, the store's copies for the
|
|
13
|
+
target must agree on one declaration, or none is read.
|
|
14
|
+
- A bind request's name resolves to the source its plugin declares (`granola` is
|
|
15
|
+
`granola.meetings`), and the account is learned through the contract's `probe`. A namespace with
|
|
16
|
+
several sources, such as `gws`, names them instead of choosing one. The bind answer says which
|
|
17
|
+
source a name was asked as.
|
|
18
|
+
- A declared source's page always names its account, `"default"` included, so a resumed cursor is
|
|
19
|
+
accepted. Wispr Flow refused its second page without it.
|
|
20
|
+
|
|
21
|
+
### Deploy
|
|
22
|
+
|
|
23
|
+
No server change and no migration: the plugin alone changes.
|
|
24
|
+
|
|
6
25
|
## [0.12.2] - 2026-11-17
|
|
7
26
|
|
|
8
27
|
### Changed
|
package/package.json
CHANGED
package/src/collector-service.js
CHANGED
|
@@ -186,7 +186,7 @@ export function createCollectorService({ ctx, runtime, toolkit, clock = REAL_CLO
|
|
|
186
186
|
const account = binding.account || DEFAULT_ACCOUNT
|
|
187
187
|
const id = collectSessionId({ source: binding.source, account })
|
|
188
188
|
try {
|
|
189
|
-
await ensureSession({ id, title: `Memory collection: ${binding.source}`, permissions: collectSessionRules({ source: binding.source, account }), extra: { source: binding.source } })
|
|
189
|
+
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
190
|
} catch (error) {
|
|
191
191
|
throw new Error(`the collector's session for ${binding.source}:${account} could not be made (${oneLine(errorMessage(error), 200)}); nothing was read`)
|
|
192
192
|
}
|
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, 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
|
|
|
@@ -163,9 +170,17 @@ export function collectableSources(sources, { only } = {}) {
|
|
|
163
170
|
* The account an events_list call names: a named binding's, and for a source
|
|
164
171
|
* whose reads are scoped by account (`namesAccount`, gws) "default" too, so
|
|
165
172
|
* the plugin reads exactly the account the session's rules allow.
|
|
173
|
+
*
|
|
174
|
+
* **A declared source always names it, "default" included** (0.12.3): the
|
|
175
|
+
* contract binds a cursor to the account it was issued for, and a resumed read
|
|
176
|
+
* that names none is refused (`INPUT_INVALID`) — live on 2026-11-17, wisprflow
|
|
177
|
+
* v0.0.4, binding `wisprflow:default`: the first page read, and the second
|
|
178
|
+
* stopped for the missing account. A plugin that declares no source keeps the
|
|
179
|
+
* previous contract's rule.
|
|
166
180
|
*/
|
|
167
|
-
function accountInput(entry, account) {
|
|
181
|
+
function accountInput(entry, account, declared = null) {
|
|
168
182
|
const named = account || DEFAULT_ACCOUNT
|
|
183
|
+
if (declared?.contract === "sources" || entry?.contract === "sources") return { account: named }
|
|
169
184
|
return named !== DEFAULT_ACCOUNT || entry?.namesAccount ? { account: named } : {}
|
|
170
185
|
}
|
|
171
186
|
|
|
@@ -174,6 +189,10 @@ function accountInput(entry, account) {
|
|
|
174
189
|
* scope the person confirmed**. A scoped source that is not told its scope reads
|
|
175
190
|
* its plugin's whole option, and its page is then refused as out of scope.
|
|
176
191
|
*
|
|
192
|
+
* The account is decided by the declared source a binding's name stands for,
|
|
193
|
+
* when its package declares one: a binding made before that keeps collecting,
|
|
194
|
+
* and its resumed page names the account its cursor was issued for.
|
|
195
|
+
*
|
|
177
196
|
* @param {{ source: string, account?: string }} binding
|
|
178
197
|
* @param {string | undefined} cursor
|
|
179
198
|
* @param {Record<string, string[]>} [scope] the consented scope (`events.cursor` returns it)
|
|
@@ -183,7 +202,7 @@ export function listInput(binding, cursor, scope) {
|
|
|
183
202
|
return {
|
|
184
203
|
...(cursor ? { cursor } : {}),
|
|
185
204
|
limit: PAGE_LIMIT,
|
|
186
|
-
...accountInput(entry, binding.account),
|
|
205
|
+
...accountInput(entry, binding.account, resolveDeclaredSource(binding.source).entry),
|
|
187
206
|
...(entry?.input ?? {}),
|
|
188
207
|
...(isPlainObject(scope) && Object.keys(scope).length ? { scope } : {}),
|
|
189
208
|
}
|
|
@@ -1048,11 +1067,21 @@ export function createCollector({ scheduler = null, lister = null, prober = null
|
|
|
1048
1067
|
}
|
|
1049
1068
|
|
|
1050
1069
|
/**
|
|
1051
|
-
* Answer the person's bind requests: for each requested source only,
|
|
1052
|
-
*
|
|
1053
|
-
*
|
|
1054
|
-
*
|
|
1055
|
-
*
|
|
1070
|
+
* Answer the person's bind requests: for each requested source only, learn
|
|
1071
|
+
* the signed-in account and report it, or the source's own reason it could
|
|
1072
|
+
* not, with `report`. Nothing is bound here: the person confirms the reported
|
|
1073
|
+
* account.
|
|
1074
|
+
*
|
|
1075
|
+
* **How the account is learned (0.12.3).** A name the installed plugin
|
|
1076
|
+
* declares a source for is learned through the contract's `probe` (D11), in
|
|
1077
|
+
* the binding's session, whatever name the request carries: 0.12.2 recorded
|
|
1078
|
+
* the nine registry names (`granola`, `github`, …) and then probed them
|
|
1079
|
+
* through the previous contract's owner-only `events_list`, which granola and
|
|
1080
|
+
* linear refuse without an account and github refuses as too large. The
|
|
1081
|
+
* owner-only `events_list` now serves only a plugin that declares nothing.
|
|
1082
|
+
* A request recorded under a name that has since been declared is reported
|
|
1083
|
+
* under its own name — the store keys it that way — with a note naming the
|
|
1084
|
+
* declared source that binds instead.
|
|
1056
1085
|
*
|
|
1057
1086
|
* @param {{ requests: unknown, only?: string, sessionID?: string, report: (input: object) => Promise<unknown>, probes?: object[] }} input
|
|
1058
1087
|
*/
|
|
@@ -1061,11 +1090,20 @@ export function createCollector({ scheduler = null, lister = null, prober = null
|
|
|
1061
1090
|
const probe = { ...asked, reported: false }
|
|
1062
1091
|
probes.push(probe)
|
|
1063
1092
|
const entry = sourceEntry(asked.source)
|
|
1093
|
+
// The declared source this name stands for, when the declaration names one:
|
|
1094
|
+
// one declared source is probed under its own id, and a name with several
|
|
1095
|
+
// is not guessed between them.
|
|
1096
|
+
const resolved = resolveDeclaredSource(asked.source)
|
|
1097
|
+
const reading = resolved.entry?.contract === "sources" ? resolved.entry : entry
|
|
1098
|
+
const renamed = reading.contract === "sources" && reading.source !== asked.source ? reading.source : null
|
|
1064
1099
|
// The binding's own session first: when it cannot be made, nothing is read and
|
|
1065
1100
|
// nothing is reported (it is not the source's failure, so no back-off either).
|
|
1066
1101
|
let session
|
|
1067
1102
|
try {
|
|
1068
|
-
|
|
1103
|
+
// The declared source a retired name stands for decides the session's rules too: the probe runs in
|
|
1104
|
+
// the binding's own session, and that session must allow the probe action the declaration asserts.
|
|
1105
|
+
const binding = renamed ? { ...asked, read: reading.source } : asked
|
|
1106
|
+
session = typeof sessionID === "function" ? await sessionID(binding) : sessionID
|
|
1069
1107
|
} catch (error) {
|
|
1070
1108
|
probe.error = oneLine(errorMessage(error), 300)
|
|
1071
1109
|
continue
|
|
@@ -1073,28 +1111,34 @@ export function createCollector({ scheduler = null, lister = null, prober = null
|
|
|
1073
1111
|
let body
|
|
1074
1112
|
try {
|
|
1075
1113
|
// 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
|
-
|
|
1114
|
+
// `events_list({ limit: 0 })` page is the previous contract's, and only
|
|
1115
|
+
// for a plugin that declares no source.
|
|
1116
|
+
const answer = reading.contract === "sources"
|
|
1117
|
+
? 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")))
|
|
1118
|
+
: 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")))
|
|
1119
|
+
// A name the declaration has replaced says which source binds instead:
|
|
1120
|
+
// the store refuses a retired name, so the person needs the one to use.
|
|
1121
|
+
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
1122
|
if (answer?.owner?.id) {
|
|
1081
1123
|
const owner = { id: oneLine(answer.owner.id, 300), label: oneLine(answer.owner.label ?? answer.owner.email ?? answer.owner.id, 300) }
|
|
1124
|
+
const setup = answer.setup || reading.setupOptions || null
|
|
1082
1125
|
body = {
|
|
1083
1126
|
source: asked.source,
|
|
1084
1127
|
account: asked.account,
|
|
1085
1128
|
owner,
|
|
1086
1129
|
reported_account: answer.account,
|
|
1087
1130
|
// 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
|
-
|
|
1131
|
+
// package has now, so jelly never refuses a read made under the old one. Only for the declared id
|
|
1132
|
+
// itself: a consent recorded under a retired name never reads that declaration.
|
|
1133
|
+
...(renamed === null && reading.descriptorHash ? { digest: reading.descriptorHash } : {}),
|
|
1090
1134
|
// The note is the source's or the plugin's own sentence: it is
|
|
1091
|
-
// reported to the store (`
|
|
1135
|
+
// reported to the store (`source_requests.note`) and shown from it,
|
|
1092
1136
|
// so it is redacted here, where it is written (review F1/F2).
|
|
1093
|
-
...(
|
|
1137
|
+
...(replaced || setup ? { note: oneLine(errorMessage([replaced, setup].filter(Boolean).join(" ")), 400) } : {}),
|
|
1094
1138
|
}
|
|
1095
1139
|
probe.owner = owner
|
|
1096
1140
|
} else {
|
|
1097
|
-
body = { source: asked.source, account: asked.account, note: oneLine(errorMessage(answer?.setup || `${
|
|
1141
|
+
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
1142
|
}
|
|
1099
1143
|
} catch (error) {
|
|
1100
1144
|
body = { source: asked.source, account: asked.account, note: oneLine(errorMessage(error), 400) }
|
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/sources.js
CHANGED
|
@@ -307,6 +307,50 @@ export function sourceEntry(source) {
|
|
|
307
307
|
return declared.get(name) ?? BY_SOURCE.get(name) ?? null
|
|
308
308
|
}
|
|
309
309
|
|
|
310
|
+
/**
|
|
311
|
+
* Every declared source one name stands for (0.12.3): its id, the name its page
|
|
312
|
+
* carries (`input.source`, which is the previous contract's name for the same
|
|
313
|
+
* feed), its namespace, or its id's last part. The nine family plugins kept
|
|
314
|
+
* their registry names — `granola`, `gmail`, `slack` — as the page names their
|
|
315
|
+
* declarations send, so a bind request names one of them and the declared
|
|
316
|
+
* source is what it means.
|
|
317
|
+
*
|
|
318
|
+
* @param {string} source
|
|
319
|
+
* @returns {object[]} the declared entries, in binding order; empty when nothing declares for the name
|
|
320
|
+
*/
|
|
321
|
+
export function declaredForName(source) {
|
|
322
|
+
const wanted = String(source ?? "")
|
|
323
|
+
if (wanted === "") return []
|
|
324
|
+
const exact = declared.get(wanted)
|
|
325
|
+
if (exact) return [exact]
|
|
326
|
+
const byPage = [...declared.values()].filter((entry) => entry.pageSource === wanted)
|
|
327
|
+
if (byPage.length > 0) return byPage
|
|
328
|
+
return [...declared.values()].filter((entry) => entry.namespace === wanted || entry.source.endsWith(`.${wanted}`))
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* What a bind request's name means under the installed declarations: the one
|
|
333
|
+
* declared source it stands for, or the several it could be.
|
|
334
|
+
*
|
|
335
|
+
* A name that is one declared source's id, page name or namespace is that
|
|
336
|
+
* source. **Several** declared sources under one name (a namespace such as
|
|
337
|
+
* `gws`, whose `gws.gmail` and `gws.calendar` are different feeds) resolve to
|
|
338
|
+
* none of them: the bind must name the one it means, because reading the wrong
|
|
339
|
+
* feed is not a choice Memory makes for the person. An events source wins over a
|
|
340
|
+
* snapshot source of the same name, and a snapshot alone is returned so the
|
|
341
|
+
* caller can say why this release does not bind it (G1).
|
|
342
|
+
*
|
|
343
|
+
* @param {string} source
|
|
344
|
+
* @returns {{ entry: object | null, options: string[] }} `options`: the ids to name instead, when several
|
|
345
|
+
*/
|
|
346
|
+
export function resolveDeclaredSource(source) {
|
|
347
|
+
const matches = declaredForName(source)
|
|
348
|
+
const events = matches.filter((entry) => entry.kind === "events")
|
|
349
|
+
const candidates = events.length > 0 ? events : matches
|
|
350
|
+
if (candidates.length === 1) return { entry: candidates[0], options: [] }
|
|
351
|
+
return { entry: null, options: candidates.map((entry) => entry.source) }
|
|
352
|
+
}
|
|
353
|
+
|
|
310
354
|
/** True when a package declares a source under the contract, so its legacy alias is retired (audit 1.3). */
|
|
311
355
|
export function legacyRetired(source) {
|
|
312
356
|
const entry = BY_SOURCE.get(String(source ?? ""))
|
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
|
|