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