@joe-broadhead/opencode-mem 0.9.14 → 0.11.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 +1856 -0
- package/README.md +15 -7
- package/SECURITY.md +3 -1
- package/docs/agent-instructions.md +1 -1
- package/docs/agent-protocol.md +7 -7
- package/docs/permissions.md +16 -0
- package/package.json +8921 -1070
- package/shared/page-paths.js +44 -0
- package/skills/mem.pages/SKILL.md +3 -1
- package/skills/mem.usage/SKILL.md +15 -15
- package/src/action-grant-keys.js +159 -0
- package/src/action-grant.js +439 -0
- package/src/actions.js +1690 -0
- package/src/backend/records.js +25 -2
- package/src/backend/v3.js +76 -22
- package/src/call-shapes.js +17 -16
- package/src/collector-lock.js +533 -62
- package/src/collector-service.js +153 -26
- package/src/collector.js +623 -30
- package/src/config.js +88 -7
- package/src/connect.js +106 -8
- package/src/credentials.js +123 -25
- package/src/events.js +174 -3
- package/src/forget-turn.js +141 -0
- package/src/host-refusal.js +78 -0
- package/src/index.js +209 -22
- package/src/jobs/host.js +557 -0
- package/src/ops/codes.js +110 -0
- package/src/ops/copy-lineage.js +42 -0
- package/src/ops/index.js +28 -0
- package/src/ops/space-ops.js +1936 -0
- package/src/outlinks.js +103 -0
- package/src/p2-reservation.js +151 -0
- package/src/permissions.js +30 -0
- package/src/plugins/descriptor.js +62 -0
- package/src/plugins/discovery.js +318 -0
- package/src/plugins/grants.js +178 -0
- package/src/plugins/locate.js +319 -0
- package/src/plugins/manifest.js +1162 -0
- package/src/plugins/source-contract/index.js +34 -0
- package/src/plugins/source-contract/policy.js +102 -0
- package/src/plugins/source-contract/vendor/PROVENANCE.json +17 -0
- package/src/plugins/source-contract/vendor/RELEASE-SHA256SUMS +3 -0
- package/src/plugins/source-contract/vendor/RELEASE.json +17 -0
- package/src/plugins/source-contract/vendor/SHA256SUMS +41 -0
- package/src/plugins/source-contract/vendor/THIRD-PARTY-NOTICES.md +35 -0
- package/src/plugins/source-contract/vendor/broker-client.js +93 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-3M5PAKSS.js +84 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-4ERCA4TK.js +185 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-6HDIB2SA.js +183 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-ELPJD3ND.js +10 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-HLVAKAYG.js +10 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-I2RXJJJM.js +81 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-KWEWSZ4V.js +505 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-KYWBTAF4.js +182 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-Q3RQA5J2.js +249 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-RRUAIQ4I.js +156 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-RYNKNCPP.js +165 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-W5SHR7DQ.js +9477 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-ZUKF7P6U.js +653 -0
- package/src/plugins/source-contract/vendor/cursor.js +26 -0
- package/src/plugins/source-contract/vendor/descriptor.js +34 -0
- package/src/plugins/source-contract/vendor/events.js +257 -0
- package/src/plugins/source-contract/vendor/index.js +10 -0
- package/src/plugins/source-contract/vendor/params.js +22 -0
- package/src/plugins/source-contract/vendor/permission.js +28 -0
- package/src/plugins/source-contract/vendor/pick.js +22 -0
- package/src/plugins/source-contract/vendor/read.js +29 -0
- package/src/plugins/source-contract/vendor/registry.js +23 -0
- package/src/plugins/source-contract/vendor/schema.js +17 -0
- package/src/plugins/source-contract/vendor/schemas/output.agenda.json +96 -0
- package/src/plugins/source-contract/vendor/schemas/output.countdown.json +28 -0
- package/src/plugins/source-contract/vendor/schemas/output.image.json +28 -0
- package/src/plugins/source-contract/vendor/schemas/output.inbox.json +84 -0
- package/src/plugins/source-contract/vendor/schemas/output.links.json +46 -0
- package/src/plugins/source-contract/vendor/schemas/output.list.json +57 -0
- package/src/plugins/source-contract/vendor/schemas/output.metric.json +61 -0
- package/src/plugins/source-contract/vendor/schemas/output.note.json +14 -0
- package/src/plugins/source-contract/vendor/schemas/output.progress.json +50 -0
- package/src/plugins/source-contract/vendor/schemas/output.record.json +38 -0
- package/src/plugins/source-contract/vendor/schemas/output.table.json +61 -0
- package/src/plugins/source-contract/vendor/schemas/output.thread.json +62 -0
- package/src/plugins/source-contract/vendor/schemas/sources.json +819 -0
- package/src/plugins/source-contract/vendor/schemas.js +19 -0
- package/src/plugins/source-contract/vendor/tools-rpc.js +42 -0
- package/src/plugins/verify.js +56 -0
- package/src/protocol.js +11 -6
- package/src/recall.js +92 -5
- package/src/records.js +61 -2
- package/src/requests.js +216 -0
- package/src/runtime.js +89 -7
- package/src/setup-time.js +68 -0
- package/src/skills.js +230 -8
- package/src/source-ids.js +25 -0
- package/src/sources/declaration.js +365 -0
- package/src/sources/reads.js +772 -0
- package/src/sources/rpc.js +151 -0
- package/src/sources.js +389 -92
- package/src/spaces.js +283 -11
- package/src/spool.js +61 -4
- package/src/stated.js +10 -5
- package/src/storable.js +139 -0
- package/src/tools/commitments.js +74 -23
- package/src/tools/held-write.js +46 -19
- package/src/tools/index.js +28 -0
- package/src/tools/ingest.js +38 -2
- package/src/tools/memory.js +56 -25
- package/src/tools/page.js +212 -95
- package/src/tools/recall.js +218 -4
- package/src/tools/share.js +42 -3
- package/src/tools/shared.js +84 -6
- package/src/tools/space-lifecycle.js +278 -0
- package/src/tools/spaces.js +381 -30
- package/src/tools/status.js +9 -2
- package/src/tools/wiki.js +231 -116
- package/src/util.js +110 -6
- package/src/vendor/source-contract/README.md +24 -0
- package/src/vendor/source-contract/THIRD-PARTY-NOTICES.md +35 -0
- package/src/vendor/source-contract/VENDOR.json +81 -0
- package/src/vendor/source-contract/chunks/chunk-3M5PAKSS.js +84 -0
- package/src/vendor/source-contract/chunks/chunk-6HDIB2SA.js +183 -0
- package/src/vendor/source-contract/chunks/chunk-HLVAKAYG.js +10 -0
- package/src/vendor/source-contract/chunks/chunk-I2RXJJJM.js +81 -0
- package/src/vendor/source-contract/chunks/chunk-KWEWSZ4V.js +505 -0
- package/src/vendor/source-contract/chunks/chunk-W5SHR7DQ.js +9477 -0
- package/src/vendor/source-contract/chunks/chunk-ZUKF7P6U.js +653 -0
- package/src/vendor/source-contract/cursor.js +26 -0
- package/src/vendor/source-contract/events.js +257 -0
- package/src/vendor/source-contract/registry.js +23 -0
- package/src/vendor/source-contract/tools-rpc.js +42 -0
- package/src/views/access-reads.js +256 -0
- package/src/views/communities.js +77 -0
- package/src/views/contracts.js +1082 -23
- package/src/views/inbox-bytes.js +103 -0
- package/src/views/profile.js +31 -0
- package/src/views/receipt.js +26 -1
- package/src/views/records-reads.js +520 -41
- package/src/views/rpc.js +153 -25
- package/src/views/shape.js +8 -5
- package/src/views/write-state.js +89 -0
- package/src/wiki-ingest.js +215 -0
- package/src/wiki-state.js +228 -0
- package/views/pages.html +2 -2
package/src/views/rpc.js
CHANGED
|
@@ -1,26 +1,42 @@
|
|
|
1
|
-
import { UNLINKED_SENTENCE, asView, inView, isUnlinked, originOf, PACKAGE_NAME, SOURCES } from "../credentials.js"
|
|
1
|
+
import { UNLINKED_SENTENCE, asView, inView, isUnlinked, originOf, PACKAGE_NAME, SOURCES, unavailableReason } from "../credentials.js"
|
|
2
2
|
import { dayIn, dueDay, filterItems, formatDay, formatDue } from "../records.js"
|
|
3
3
|
import { isRecordsWikiName } from "../tools/knowledge.js"
|
|
4
|
+
import { wikiCache, wikiErrorOf, wikiStateOf } from "../wiki-state.js"
|
|
4
5
|
import {
|
|
5
6
|
COMMITMENTS_MAX,
|
|
7
|
+
INBOX_ITEM_MEETING,
|
|
6
8
|
INBOX_ITEM_SESSION,
|
|
7
9
|
LIST_MAX,
|
|
8
10
|
PAGE_TEXT_CHARS,
|
|
9
11
|
SPEAKER_FIELD,
|
|
12
|
+
SPACE_GRANT_ONLY,
|
|
10
13
|
SPOOL_TIME_CHARS,
|
|
11
14
|
VIEW_ERROR,
|
|
12
15
|
VIEW_METHODS,
|
|
13
16
|
} from "./contracts.js"
|
|
14
17
|
import { createRecordsReads, recordsFailureWords } from "./records-reads.js"
|
|
18
|
+
import { fitInboxRead } from "./inbox-bytes.js"
|
|
15
19
|
import { oneLinePlain, overdueInboxItems } from "./overdue.js"
|
|
16
20
|
import { createProfileReads } from "./profile.js"
|
|
21
|
+
import { createAccessReads } from "./access-reads.js"
|
|
17
22
|
import { SPACE_KINDS, ViewRefusal, clip, clipText, idOf, refuse, spaceOf } from "./shape.js"
|
|
18
23
|
import { createHeldInboxDecision } from "./inbox-decision.js"
|
|
24
|
+
import { createActionHandlers, createActionReads, createPluginVerifier } from "../actions.js"
|
|
25
|
+
import { createSpaceOperations } from "../ops/index.js"
|
|
26
|
+
import { createToolkit } from "../tools/shared.js"
|
|
19
27
|
|
|
20
28
|
// Jelly has no Inbox action route, signed-grant verifier, or ask bridge yet (#33).
|
|
21
29
|
// Never enable in production until all three are available and independently verified.
|
|
22
30
|
export const INBOX_ACTION_RPC_ENABLED = false
|
|
23
31
|
|
|
32
|
+
/**
|
|
33
|
+
* The reads' own `personalScopes`, reachable from the RPC registration so an
|
|
34
|
+
* action that reaches the memory core (A12's erase) reads the same scopes the
|
|
35
|
+
* profile read did. It is not a view method: it is reached by this symbol, never
|
|
36
|
+
* named in the declaration.
|
|
37
|
+
*/
|
|
38
|
+
export const VIEW_SCOPES = Symbol.for("mem.views.scopes")
|
|
39
|
+
|
|
24
40
|
/**
|
|
25
41
|
* The RPC behind Memory's views in Jelly (`views/*.html`).
|
|
26
42
|
*
|
|
@@ -83,7 +99,7 @@ const CREDENTIALS = Object.freeze({
|
|
|
83
99
|
* agents?: () => Promise<string[]>,
|
|
84
100
|
* }} input
|
|
85
101
|
*/
|
|
86
|
-
export function createViewReads({ runtime, agents = async () => [] }) {
|
|
102
|
+
export function createViewReads({ runtime, agents = async () => [], operations = null, inboxItemMeeting = INBOX_ITEM_MEETING }) {
|
|
87
103
|
const { config, backend, credentials } = runtime
|
|
88
104
|
|
|
89
105
|
/** The agent names a view reads under; [] lets control choose. */
|
|
@@ -160,6 +176,7 @@ export function createViewReads({ runtime, agents = async () => [] }) {
|
|
|
160
176
|
|
|
161
177
|
const recordsReads = createRecordsReads({ runtime, personalScopes, available, describe: viewFailureWords })
|
|
162
178
|
const profileReads = createProfileReads({ runtime, personalScopes, available, describe: viewFailureWords })
|
|
179
|
+
const accessReads = createAccessReads({ runtime, personalScopes, available })
|
|
163
180
|
|
|
164
181
|
/**
|
|
165
182
|
* The overview of a memory that can't be used now. `state` tells a page which
|
|
@@ -169,8 +186,38 @@ export function createViewReads({ runtime, agents = async () => [] }) {
|
|
|
169
186
|
*/
|
|
170
187
|
function notConnected(reason, base, status = 0) {
|
|
171
188
|
const held = credentialState()
|
|
172
|
-
|
|
173
|
-
|
|
189
|
+
// The switch's own two states are things to set, not an outage: "on with no
|
|
190
|
+
// address" and an address paused until the switch is on are `unconfigured`,
|
|
191
|
+
// and their reason names the field (R2-S1).
|
|
192
|
+
const note = config?.ownServiceNote ?? ""
|
|
193
|
+
const state = note === "incomplete" || note === "paused" ? "unconfigured" : overviewState({ ...held, address: base.address, status })
|
|
194
|
+
// The switch's own states have no address to show: the one `base` carries is
|
|
195
|
+
// the local simulator's default, and naming it would read as a real service.
|
|
196
|
+
const { address: _simulator, ...withoutAddress } = base
|
|
197
|
+
const shown = note ? withoutAddress : base
|
|
198
|
+
// `capture: false` while memory cannot be used: nothing is captured, and a
|
|
199
|
+
// sheet that reads this field must not say "Capture is on" (jelly #72).
|
|
200
|
+
return {
|
|
201
|
+
connected: false,
|
|
202
|
+
reason: clip(reason, 400),
|
|
203
|
+
state,
|
|
204
|
+
tile: note === "paused" ? TILE_SENTENCES.paused : TILE_SENTENCES[state],
|
|
205
|
+
...held,
|
|
206
|
+
...shown,
|
|
207
|
+
capture: false,
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* `memory.setup` (jelly #80, D226): the numbers this engine start's setup
|
|
213
|
+
* recorded, and nothing else — no sign-in, no request, no space, so the host
|
|
214
|
+
* can read it as soon as the engine is up. A copy, so a caller cannot change
|
|
215
|
+
* what the next read answers.
|
|
216
|
+
*/
|
|
217
|
+
function setup() {
|
|
218
|
+
const record = runtime.setupTime
|
|
219
|
+
if (!record) refuse("Memory has no setup record for this start.")
|
|
220
|
+
return { ms: record.ms, phases: record.phases.map((phase) => ({ name: phase.name, ms: phase.ms })), at: record.at }
|
|
174
221
|
}
|
|
175
222
|
|
|
176
223
|
async function overview() {
|
|
@@ -181,6 +228,12 @@ export function createViewReads({ runtime, agents = async () => [] }) {
|
|
|
181
228
|
extraction: "unknown",
|
|
182
229
|
...(address ? { address: clip(address, 300) } : {}),
|
|
183
230
|
}
|
|
231
|
+
// The switch's own states first: "on with no address" and an address paused
|
|
232
|
+
// until the switch is on are things to set, not an outage to retry (R2-S1).
|
|
233
|
+
const ownServiceNote = config?.ownServiceNote ?? ""
|
|
234
|
+
if (ownServiceNote) {
|
|
235
|
+
return notConnected(unavailableReason({ source: "", controlURL: "", memoryResourceOffered: true, ownServiceNote }), base)
|
|
236
|
+
}
|
|
184
237
|
const reason = await unavailableNow()
|
|
185
238
|
if (reason) return notConnected(reason, base)
|
|
186
239
|
let scopes
|
|
@@ -258,6 +311,12 @@ export function createViewReads({ runtime, agents = async () => [] }) {
|
|
|
258
311
|
}
|
|
259
312
|
}
|
|
260
313
|
|
|
314
|
+
/** A non-negative whole count, or undefined when the answer has none (jelly #55). */
|
|
315
|
+
const countOf = (value) => {
|
|
316
|
+
const number = Number(value)
|
|
317
|
+
return Number.isInteger(number) && number >= 0 ? number : undefined
|
|
318
|
+
}
|
|
319
|
+
|
|
261
320
|
async function spacesList() {
|
|
262
321
|
await available()
|
|
263
322
|
if (!runtime.control) return { spaces: [{ ...spaceOf(null), role: "owner" }] }
|
|
@@ -270,7 +329,10 @@ export function createViewReads({ runtime, agents = async () => [] }) {
|
|
|
270
329
|
id: idOf(space.space_id),
|
|
271
330
|
name: clip(space.name || space.space_id, 200),
|
|
272
331
|
kind: SPACE_KINDS.has(space.kind) ? space.kind : "unknown",
|
|
332
|
+
grantOnly: SPACE_GRANT_ONLY,
|
|
273
333
|
role: clip(space.role ?? "", 40),
|
|
334
|
+
...(countOf(space.members) === undefined ? {} : { members: countOf(space.members) }),
|
|
335
|
+
...(countOf(space.wikis) === undefined ? {} : { wikis: countOf(space.wikis) }),
|
|
274
336
|
})),
|
|
275
337
|
}
|
|
276
338
|
}
|
|
@@ -281,6 +343,9 @@ export function createViewReads({ runtime, agents = async () => [] }) {
|
|
|
281
343
|
return first.context ? runtime.sharedScope({ context: first.context }) : runtime.sharedScope()
|
|
282
344
|
}
|
|
283
345
|
|
|
346
|
+
/** The last ready page set of each wiki, across an ingest (jelly #89 A2). */
|
|
347
|
+
const pageCache = wikiCache({ stateDir: config.stateDir, log: runtime.log })
|
|
348
|
+
|
|
284
349
|
async function wikiList() {
|
|
285
350
|
await available()
|
|
286
351
|
const scope = await knowledgeScope()
|
|
@@ -290,42 +355,55 @@ export function createViewReads({ runtime, agents = async () => [] }) {
|
|
|
290
355
|
// The records wiki is commitments' store, shown by commitments.list.
|
|
291
356
|
.filter((item) => idOf(item?.wiki_id) && !isRecordsWikiName(item?.name))
|
|
292
357
|
.slice(0, LIST_MAX)
|
|
293
|
-
.map((item) =>
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
358
|
+
.map((item) => {
|
|
359
|
+
// The state a host can show (jelly #89 A1): ready, processing, or
|
|
360
|
+
// failed with the reason, at most 400 characters.
|
|
361
|
+
const error = wikiErrorOf(item, pageCache.error(item.wiki_id))
|
|
362
|
+
return {
|
|
363
|
+
id: idOf(item.wiki_id),
|
|
364
|
+
name: clip(item.name || item.wiki_id, 200),
|
|
365
|
+
pages: Math.max(0, Math.floor(Number(item.page_count) || 0)),
|
|
366
|
+
status: wikiStateOf(item),
|
|
367
|
+
...(error ? { error } : {}),
|
|
368
|
+
}
|
|
369
|
+
}),
|
|
298
370
|
}
|
|
299
371
|
}
|
|
300
372
|
|
|
301
|
-
/** A wiki the caller can list, or a refusal: a view names only what it was shown. */
|
|
373
|
+
/** A wiki the caller can list, and its hub item, or a refusal: a view names only what it was shown. */
|
|
302
374
|
async function visibleWiki(scope, value) {
|
|
303
375
|
const wiki = idOf(value)
|
|
304
376
|
if (!wiki) refuse("That is not a wiki id.")
|
|
305
377
|
const data = await backend.listWiki({ scope })
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
}
|
|
309
|
-
return wiki
|
|
378
|
+
const item = (data?.items ?? []).find((entry) => entry?.wiki_id === wiki && !isRecordsWikiName(entry?.name))
|
|
379
|
+
if (!item) refuse("That wiki isn't in your memory.")
|
|
380
|
+
return { wiki, item }
|
|
310
381
|
}
|
|
311
382
|
|
|
312
383
|
async function wikiPages(input) {
|
|
313
384
|
await available()
|
|
314
385
|
const scope = await knowledgeScope()
|
|
315
|
-
const wiki = await visibleWiki(scope, input?.wiki)
|
|
386
|
+
const { wiki, item } = await visibleWiki(scope, input?.wiki)
|
|
387
|
+
const state = wikiStateOf(item)
|
|
316
388
|
const data = await backend.listWikiPages({ scope, wikiID: wiki })
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
389
|
+
const listed = (data?.items ?? [])
|
|
390
|
+
.map((entry) => ({ ref: idOf(entry?.path ?? entry?.id), title: clip(entry?.title || entry?.path || entry?.id, 200) }))
|
|
391
|
+
.filter((page) => page.ref)
|
|
392
|
+
.slice(0, LIST_MAX)
|
|
393
|
+
if (state === "ready" && listed.length > 0) pageCache.rememberPages(wiki, listed)
|
|
394
|
+
// The hub lists no pages while a wiki ingests; the last ready set is
|
|
395
|
+
// listed instead, marked stale, so the person's pages never vanish (A2).
|
|
396
|
+
if (listed.length === 0 && state !== "ready") {
|
|
397
|
+
const stale = pageCache.pages(wiki)
|
|
398
|
+
if (stale.length > 0) return { pages: stale, stale: true }
|
|
322
399
|
}
|
|
400
|
+
return { pages: listed }
|
|
323
401
|
}
|
|
324
402
|
|
|
325
403
|
async function wikiRead(input) {
|
|
326
404
|
await available()
|
|
327
405
|
const scope = await knowledgeScope()
|
|
328
|
-
const wiki = await visibleWiki(scope, input?.wiki)
|
|
406
|
+
const { wiki } = await visibleWiki(scope, input?.wiki)
|
|
329
407
|
const ref = idOf(input?.ref)
|
|
330
408
|
if (!ref) refuse("That is not a page.")
|
|
331
409
|
const data = await backend.readWikiPage({ scope, wikiID: wiki, refs: [ref] })
|
|
@@ -364,6 +442,7 @@ export function createViewReads({ runtime, agents = async () => [] }) {
|
|
|
364
442
|
owner: clip(item.owner || "user", 80),
|
|
365
443
|
state: ["open", "done", "cancelled"].includes(item.state) ? item.state : "open",
|
|
366
444
|
when: clip(item.due ? formatDue(item.due, zone) : "", 40),
|
|
445
|
+
...(day ? { due: clip(day, 40) } : {}),
|
|
367
446
|
overdue: item.state === "open" && Boolean(day) && day < today,
|
|
368
447
|
dueToday: item.state === "open" && day === today,
|
|
369
448
|
...(item.trigger ? { trigger: clip(item.trigger, 200) } : {}),
|
|
@@ -385,7 +464,11 @@ export function createViewReads({ runtime, agents = async () => [] }) {
|
|
|
385
464
|
* OpenCode keeps its Due list (`mem_commitments`, the pinned block). The host
|
|
386
465
|
* replaces its whole copy with each answer, so a part that cannot be read
|
|
387
466
|
* fails the whole read (the host then keeps what it had) rather than answer a
|
|
388
|
-
* list that would drop items still true.
|
|
467
|
+
* list that would drop items still true. For the same reason one answer is
|
|
468
|
+
* held under `INBOX_READ_BYTES_MAX` bytes — a guard for the day an item
|
|
469
|
+
* carries its meeting, since today's read peaks at 28–33 KB — by giving up
|
|
470
|
+
* `evidence`, then `meeting`, then the words, from the last item backwards:
|
|
471
|
+
* never an item and never a key (`fitInboxRead`, `src/views/inbox-bytes.js`).
|
|
389
472
|
*/
|
|
390
473
|
async function inboxList() {
|
|
391
474
|
await available()
|
|
@@ -402,12 +485,18 @@ export function createViewReads({ runtime, agents = async () => [] }) {
|
|
|
402
485
|
line: title || "A proposal is waiting for review",
|
|
403
486
|
at: item.created,
|
|
404
487
|
...(kind ? { kind } : {}),
|
|
488
|
+
// The meeting a proposal was drawn from, and the moments it cites, as
|
|
489
|
+
// `review.list` carries them (#62): the proposal's own fields, read from
|
|
490
|
+
// the same space. Held back until Jelly's strict Inbox item takes them
|
|
491
|
+
// (INBOX_ITEM_MEETING, src/views/contracts.js).
|
|
492
|
+
...(inboxItemMeeting && item.meeting ? { meeting: item.meeting } : {}),
|
|
493
|
+
...(inboxItemMeeting && item.evidence?.length ? { evidence: item.evidence } : {}),
|
|
405
494
|
// The session is stored and read already; Jelly's strict Inbox reader has
|
|
406
495
|
// no such field yet, so it goes on the wire only when `INBOX_ITEM_SESSION`.
|
|
407
496
|
...(INBOX_ITEM_SESSION && session ? { session } : {}),
|
|
408
497
|
}]
|
|
409
498
|
})
|
|
410
|
-
return { items: [...proposals, ...overdue] }
|
|
499
|
+
return fitInboxRead({ items: [...proposals, ...overdue] })
|
|
411
500
|
}
|
|
412
501
|
|
|
413
502
|
/** One item for each of the person's overdue commitments: the same rule `commitments.list` marks `overdue`. */
|
|
@@ -420,6 +509,7 @@ export function createViewReads({ runtime, agents = async () => [] }) {
|
|
|
420
509
|
return {
|
|
421
510
|
"commitments.list": commitmentsList,
|
|
422
511
|
"inbox.list": inboxList,
|
|
512
|
+
"memory.setup": setup,
|
|
423
513
|
"memory.overview": overview,
|
|
424
514
|
"spaces.list": spacesList,
|
|
425
515
|
"wiki.list": wikiList,
|
|
@@ -427,6 +517,9 @@ export function createViewReads({ runtime, agents = async () => [] }) {
|
|
|
427
517
|
"wiki.read": wikiRead,
|
|
428
518
|
...recordsReads.methods,
|
|
429
519
|
...profileReads,
|
|
520
|
+
...accessReads,
|
|
521
|
+
...createActionReads({ runtime, personalScopes, operations }),
|
|
522
|
+
[VIEW_SCOPES]: personalScopes,
|
|
430
523
|
}
|
|
431
524
|
}
|
|
432
525
|
|
|
@@ -440,6 +533,21 @@ function viewWords(reason) {
|
|
|
440
533
|
return reason === UNLINKED_SENTENCE && inView() ? VIEW_UNLINKED_SENTENCE : reason
|
|
441
534
|
}
|
|
442
535
|
|
|
536
|
+
/**
|
|
537
|
+
* One fixed sentence per overview state (jelly #73): one full sentence, at most
|
|
538
|
+
* 60 characters, so a phone tile holds it whole, and its next step names
|
|
539
|
+
* something the person can see on Memory's card — whatever credential it was
|
|
540
|
+
* (a key, a Jelly sign-in or OpenCode's), the card is where it is fixed.
|
|
541
|
+
* `reason` stays free text for the reading pane; a tile draws `tile`.
|
|
542
|
+
*/
|
|
543
|
+
export const TILE_SENTENCES = Object.freeze({
|
|
544
|
+
unconfigured: "Open Memory's card and connect to start using it.",
|
|
545
|
+
refused: "Open Memory's card and connect again; it was refused.",
|
|
546
|
+
unreachable: "Try again in a moment; Memory cannot be reached.",
|
|
547
|
+
// Not a state `overviewState` returns: a saved address waiting for the switch.
|
|
548
|
+
paused: "Turn on \"Use my own Memory service\" in Memory's settings.",
|
|
549
|
+
})
|
|
550
|
+
|
|
443
551
|
/**
|
|
444
552
|
* Why `memory.overview` is `connected: false`, as the page tells it: "unconfigured"
|
|
445
553
|
* (no credential, no address, or no linked Jelly account), "refused" (a credential
|
|
@@ -528,9 +636,15 @@ export function splitSpeaker(input) {
|
|
|
528
636
|
* @param {any} ctx
|
|
529
637
|
* @param {any} runtime
|
|
530
638
|
*/
|
|
531
|
-
export async function registerViewRpc(ctx, runtime, { enableInboxActions = INBOX_ACTION_RPC_ENABLED, verifyInboxAction } = {}) {
|
|
639
|
+
export async function registerViewRpc(ctx, runtime, { enableInboxActions = INBOX_ACTION_RPC_ENABLED, verifyInboxAction, inboxItemMeeting = INBOX_ITEM_MEETING } = {}) {
|
|
532
640
|
if (typeof ctx?.rpc?.register !== "function") return null
|
|
533
|
-
|
|
641
|
+
// The space and sharing operations an action runs (`src/ops`), built on the
|
|
642
|
+
// same toolkit the tools use: the control plane, the person's records client,
|
|
643
|
+
// and the space the gateway resolves. A build with no control plane still
|
|
644
|
+
// builds them; each operation then refuses with SCOPE_MISSING.
|
|
645
|
+
const operations = createSpaceOperations(createToolkit(ctx, runtime))
|
|
646
|
+
const reads = createViewReads({ runtime, agents: engineAgents(ctx), operations, inboxItemMeeting })
|
|
647
|
+
const personalScopes = reads[VIEW_SCOPES] ?? (async () => [])
|
|
534
648
|
const methods = {}
|
|
535
649
|
const handlers = {}
|
|
536
650
|
for (const method of VIEW_METHODS) {
|
|
@@ -549,6 +663,20 @@ export async function registerViewRpc(ctx, runtime, { enableInboxActions = INBOX
|
|
|
549
663
|
return typeof speaker === "string" ? asView(speaker, read) : read()
|
|
550
664
|
}
|
|
551
665
|
}
|
|
666
|
+
// The actions a person's own page may change, under a host-signed grant
|
|
667
|
+
// (src/actions.js): registered as `act.<name>`, which Jelly's own fence
|
|
668
|
+
// refuses to anything but the host's call for a person. Dark until
|
|
669
|
+
// `config.actions`; an agent never holds one.
|
|
670
|
+
const actions = createActionHandlers({
|
|
671
|
+
config: runtime.config,
|
|
672
|
+
runtime,
|
|
673
|
+
verifier: createPluginVerifier({ keyFile: runtime.config.actionKeysFile || null, maxAgeHours: runtime.config.actionKeysMaxAgeHours ?? 24, log: runtime.log }),
|
|
674
|
+
personalScopes,
|
|
675
|
+
operations,
|
|
676
|
+
log: runtime.log,
|
|
677
|
+
})
|
|
678
|
+
Object.assign(methods, actions.methods)
|
|
679
|
+
Object.assign(handlers, actions.handlers)
|
|
552
680
|
if (enableInboxActions) {
|
|
553
681
|
if (typeof verifyInboxAction !== "function") throw new Error("Inbox actions require a grant verifier and ask bridge")
|
|
554
682
|
const decide = createHeldInboxDecision(runtime)
|
package/src/views/shape.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { oneLine } from "../util.js"
|
|
2
|
-
import { ID_PATTERN } from "./contracts.js"
|
|
2
|
+
import { ID_PATTERN, SPACE_GRANT_ONLY } from "./contracts.js"
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Small helpers every view read shares: refusals in the plugin's own words,
|
|
@@ -49,11 +49,12 @@ export const SPACE_KINDS = new Set(["personal", "shared"])
|
|
|
49
49
|
|
|
50
50
|
/** The space an answer names, from a control context; local direct mode has one. */
|
|
51
51
|
export function spaceOf(context) {
|
|
52
|
-
if (!context) return { id: "local", name: "Local memory", kind: "personal" }
|
|
52
|
+
if (!context) return { id: "local", name: "Local memory", kind: "personal", grantOnly: SPACE_GRANT_ONLY }
|
|
53
53
|
return {
|
|
54
54
|
id: idOf(context.space_id) || "unknown",
|
|
55
55
|
name: clip(context.space_name || context.space_id || "Your memory", 200),
|
|
56
56
|
kind: SPACE_KINDS.has(context.space_kind) ? context.space_kind : "unknown",
|
|
57
|
+
grantOnly: SPACE_GRANT_ONLY,
|
|
57
58
|
}
|
|
58
59
|
}
|
|
59
60
|
|
|
@@ -65,13 +66,15 @@ export const ANSWER_BYTES = 56_000
|
|
|
65
66
|
|
|
66
67
|
/**
|
|
67
68
|
* Keep adding `items` to `answer[key]` while the whole answer stays under the
|
|
68
|
-
* byte cap; whether any were left out.
|
|
69
|
+
* byte cap; whether any were left out. `limit` is the cap, defaulted to
|
|
70
|
+
* `ANSWER_BYTES`: a read that adds fields to the answer after its list passes a
|
|
71
|
+
* smaller one, so what the host reads is inside it too.
|
|
69
72
|
*/
|
|
70
|
-
export function fitList(answer, key, items) {
|
|
73
|
+
export function fitList(answer, key, items, limit = ANSWER_BYTES) {
|
|
71
74
|
let fitted = false
|
|
72
75
|
for (const item of items) {
|
|
73
76
|
answer[key].push(item)
|
|
74
|
-
if (jsonBytes(answer) >
|
|
77
|
+
if (jsonBytes(answer) > limit) {
|
|
75
78
|
answer[key].pop()
|
|
76
79
|
fitted = true
|
|
77
80
|
break
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The first line of every write's answer (0.11.3, jelly's #89 ask A4): the
|
|
3
|
+
* state a host and an agent can quote, the written item's id, and its place,
|
|
4
|
+
* as `state: stored · id: rec_… · link: page:projects/harbour`. The prose the
|
|
5
|
+
* answer carried before follows on the next line, unchanged, so nothing a host
|
|
6
|
+
* or a test parsed in 0.11.2 changes.
|
|
7
|
+
*
|
|
8
|
+
* `state` is the state of the item after the call, never of the call:
|
|
9
|
+
* - `stored`: the item is saved in its store and readable now;
|
|
10
|
+
* - `held`: nothing is saved; it waits for the person in the Inbox, and `id`
|
|
11
|
+
* names the proposal;
|
|
12
|
+
* - `processing`: the item is saved, and an ingest it started is making search
|
|
13
|
+
* and the pages derived from it current;
|
|
14
|
+
* - `queued`: nothing is saved yet; the wiki is ingesting an earlier write, and
|
|
15
|
+
* this write is written when that ingest finishes;
|
|
16
|
+
* - `ready`: the change is complete and there is no item to open (a delete);
|
|
17
|
+
* - `failed`: the call did not finish cleanly; the prose says whether the item
|
|
18
|
+
* was saved and what failed;
|
|
19
|
+
* - `refused`: nothing was written. A refusal names no id and no place.
|
|
20
|
+
*
|
|
21
|
+
* `link` is the item's place, one of `memory:<id>`, `commitment:<id>`,
|
|
22
|
+
* `page:<path>` or `wiki:<wiki id>/<filename>` (a wiki document has no id of
|
|
23
|
+
* its own, so its place is also its id). The format is documented once, in
|
|
24
|
+
* docs/write-states.md.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/** The seven states a write answers, in the order the doc lists them. */
|
|
28
|
+
export const WRITE_STATES = Object.freeze(["stored", "held", "processing", "queued", "ready", "failed", "refused"])
|
|
29
|
+
|
|
30
|
+
/** What a host splits the first line on. */
|
|
31
|
+
export const WRITE_STATE_SEPARATOR = " · "
|
|
32
|
+
|
|
33
|
+
/** The longest id and place a first line carries, so one field cannot flood an answer. */
|
|
34
|
+
export const WRITE_STATE_ID_CHARS = 240
|
|
35
|
+
export const WRITE_STATE_LINK_CHARS = 300
|
|
36
|
+
|
|
37
|
+
const one = (value, max) =>
|
|
38
|
+
String(value ?? "")
|
|
39
|
+
.replace(/[\u0000-\u001f\u007f]/g, " ")
|
|
40
|
+
.replace(/\s+/g, " ")
|
|
41
|
+
.trim()
|
|
42
|
+
.slice(0, max)
|
|
43
|
+
|
|
44
|
+
/** A memory's place: its record id. */
|
|
45
|
+
export const memoryPlace = (id) => `memory:${one(id, WRITE_STATE_ID_CHARS)}`
|
|
46
|
+
|
|
47
|
+
/** A commitment's place: its record id (`cmt_…` while it is filed under the wiki). */
|
|
48
|
+
export const commitmentPlace = (id) => `commitment:${one(id, WRITE_STATE_ID_CHARS)}`
|
|
49
|
+
|
|
50
|
+
/** A page's place: its path. */
|
|
51
|
+
export const pagePlace = (path) => `page:${one(path, WRITE_STATE_ID_CHARS)}`
|
|
52
|
+
|
|
53
|
+
/** A wiki document's place: its wiki and its source file. */
|
|
54
|
+
export const wikiPlace = (wikiID, filename) => `wiki:${one(wikiID, 80)}/${one(filename, 160)}`
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The first line, without a newline: `state: refused`, or
|
|
58
|
+
* `state: held · id: rec_… · link: page:projects/harbour`. `id` and `link`
|
|
59
|
+
* come together, and a refusal carries neither.
|
|
60
|
+
*
|
|
61
|
+
* @param {{ state: string, id?: string, link?: string }} write
|
|
62
|
+
* @returns {string}
|
|
63
|
+
*/
|
|
64
|
+
export function writeStateLine({ state, id, link } = {}) {
|
|
65
|
+
if (!WRITE_STATES.includes(state)) throw new Error(`a write answers one of ${WRITE_STATES.join(", ")}; got ${JSON.stringify(state)}`)
|
|
66
|
+
const parts = [`state: ${state}`]
|
|
67
|
+
if (state !== "refused" && id) {
|
|
68
|
+
parts.push(`id: ${one(id, WRITE_STATE_ID_CHARS)}`)
|
|
69
|
+
if (link) parts.push(`link: ${one(link, WRITE_STATE_LINK_CHARS)}`)
|
|
70
|
+
}
|
|
71
|
+
return parts.join(WRITE_STATE_SEPARATOR)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* A tool result with the write's first line above its prose, or the result
|
|
76
|
+
* exactly as it is when the call wrote nothing and names nothing.
|
|
77
|
+
*
|
|
78
|
+
* @param {{ content: string }} result
|
|
79
|
+
* @param {{ state: string, id?: string, link?: string }} write
|
|
80
|
+
*/
|
|
81
|
+
export function withWriteState(result, write) {
|
|
82
|
+
return { ...result, content: `${writeStateLine(write)}\n${result?.content ?? ""}` }
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** A result that wrote nothing. */
|
|
86
|
+
export const refusedAnswer = (result) => withWriteState(result, { state: "refused" })
|
|
87
|
+
|
|
88
|
+
/** A result whose call did not finish cleanly. */
|
|
89
|
+
export const failedAnswer = (result) => withWriteState(result, { state: "failed" })
|