@joe-broadhead/opencode-mem 0.9.12 → 0.11.2

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.
Files changed (144) hide show
  1. package/CHANGELOG.md +1934 -2
  2. package/README.md +29 -17
  3. package/SECURITY.md +3 -1
  4. package/docs/agent-instructions.md +17 -0
  5. package/docs/agent-protocol.md +8 -8
  6. package/docs/permissions.md +22 -4
  7. package/package.json +7923 -217
  8. package/shared/page-paths.js +44 -0
  9. package/skills/mem.pages/SKILL.md +8 -1
  10. package/skills/mem.usage/SKILL.md +15 -15
  11. package/src/action-grant-keys.js +159 -0
  12. package/src/action-grant.js +439 -0
  13. package/src/actions.js +1690 -0
  14. package/src/backend/records.js +25 -2
  15. package/src/backend/v3.js +76 -22
  16. package/src/call-shapes.js +17 -16
  17. package/src/collector-lock.js +533 -62
  18. package/src/collector-service.js +153 -26
  19. package/src/collector.js +627 -33
  20. package/src/config.js +79 -6
  21. package/src/connect.js +106 -8
  22. package/src/credentials.js +123 -25
  23. package/src/events.js +174 -3
  24. package/src/forget-turn.js +141 -0
  25. package/src/host-refusal.js +78 -0
  26. package/src/index.js +209 -22
  27. package/src/jobs/host.js +557 -0
  28. package/src/ops/codes.js +110 -0
  29. package/src/ops/copy-lineage.js +42 -0
  30. package/src/ops/index.js +28 -0
  31. package/src/ops/space-ops.js +1936 -0
  32. package/src/outlinks.js +103 -0
  33. package/src/p2-reservation.js +151 -0
  34. package/src/permissions.js +30 -0
  35. package/src/plugins/descriptor.js +62 -0
  36. package/src/plugins/discovery.js +318 -0
  37. package/src/plugins/grants.js +178 -0
  38. package/src/plugins/locate.js +319 -0
  39. package/src/plugins/manifest.js +1162 -0
  40. package/src/plugins/source-contract/index.js +34 -0
  41. package/src/plugins/source-contract/policy.js +102 -0
  42. package/src/plugins/source-contract/vendor/PROVENANCE.json +17 -0
  43. package/src/plugins/source-contract/vendor/RELEASE-SHA256SUMS +3 -0
  44. package/src/plugins/source-contract/vendor/RELEASE.json +17 -0
  45. package/src/plugins/source-contract/vendor/SHA256SUMS +41 -0
  46. package/src/plugins/source-contract/vendor/THIRD-PARTY-NOTICES.md +35 -0
  47. package/src/plugins/source-contract/vendor/broker-client.js +93 -0
  48. package/src/plugins/source-contract/vendor/chunks/chunk-3M5PAKSS.js +84 -0
  49. package/src/plugins/source-contract/vendor/chunks/chunk-4ERCA4TK.js +185 -0
  50. package/src/plugins/source-contract/vendor/chunks/chunk-6HDIB2SA.js +183 -0
  51. package/src/plugins/source-contract/vendor/chunks/chunk-ELPJD3ND.js +10 -0
  52. package/src/plugins/source-contract/vendor/chunks/chunk-HLVAKAYG.js +10 -0
  53. package/src/plugins/source-contract/vendor/chunks/chunk-I2RXJJJM.js +81 -0
  54. package/src/plugins/source-contract/vendor/chunks/chunk-KWEWSZ4V.js +505 -0
  55. package/src/plugins/source-contract/vendor/chunks/chunk-KYWBTAF4.js +182 -0
  56. package/src/plugins/source-contract/vendor/chunks/chunk-Q3RQA5J2.js +249 -0
  57. package/src/plugins/source-contract/vendor/chunks/chunk-RRUAIQ4I.js +156 -0
  58. package/src/plugins/source-contract/vendor/chunks/chunk-RYNKNCPP.js +165 -0
  59. package/src/plugins/source-contract/vendor/chunks/chunk-W5SHR7DQ.js +9477 -0
  60. package/src/plugins/source-contract/vendor/chunks/chunk-ZUKF7P6U.js +653 -0
  61. package/src/plugins/source-contract/vendor/cursor.js +26 -0
  62. package/src/plugins/source-contract/vendor/descriptor.js +34 -0
  63. package/src/plugins/source-contract/vendor/events.js +257 -0
  64. package/src/plugins/source-contract/vendor/index.js +10 -0
  65. package/src/plugins/source-contract/vendor/params.js +22 -0
  66. package/src/plugins/source-contract/vendor/permission.js +28 -0
  67. package/src/plugins/source-contract/vendor/pick.js +22 -0
  68. package/src/plugins/source-contract/vendor/read.js +29 -0
  69. package/src/plugins/source-contract/vendor/registry.js +23 -0
  70. package/src/plugins/source-contract/vendor/schema.js +17 -0
  71. package/src/plugins/source-contract/vendor/schemas/output.agenda.json +96 -0
  72. package/src/plugins/source-contract/vendor/schemas/output.countdown.json +28 -0
  73. package/src/plugins/source-contract/vendor/schemas/output.image.json +28 -0
  74. package/src/plugins/source-contract/vendor/schemas/output.inbox.json +84 -0
  75. package/src/plugins/source-contract/vendor/schemas/output.links.json +46 -0
  76. package/src/plugins/source-contract/vendor/schemas/output.list.json +57 -0
  77. package/src/plugins/source-contract/vendor/schemas/output.metric.json +61 -0
  78. package/src/plugins/source-contract/vendor/schemas/output.note.json +14 -0
  79. package/src/plugins/source-contract/vendor/schemas/output.progress.json +50 -0
  80. package/src/plugins/source-contract/vendor/schemas/output.record.json +38 -0
  81. package/src/plugins/source-contract/vendor/schemas/output.table.json +61 -0
  82. package/src/plugins/source-contract/vendor/schemas/output.thread.json +62 -0
  83. package/src/plugins/source-contract/vendor/schemas/sources.json +819 -0
  84. package/src/plugins/source-contract/vendor/schemas.js +19 -0
  85. package/src/plugins/source-contract/vendor/tools-rpc.js +42 -0
  86. package/src/plugins/verify.js +56 -0
  87. package/src/protocol.js +21 -5
  88. package/src/recall.js +104 -5
  89. package/src/records.js +61 -2
  90. package/src/requests.js +216 -0
  91. package/src/runtime.js +89 -7
  92. package/src/setup-time.js +68 -0
  93. package/src/skills.js +230 -8
  94. package/src/source-ids.js +25 -0
  95. package/src/sources/declaration.js +365 -0
  96. package/src/sources/reads.js +772 -0
  97. package/src/sources/rpc.js +151 -0
  98. package/src/sources.js +409 -90
  99. package/src/spaces.js +283 -11
  100. package/src/spool.js +61 -4
  101. package/src/stated.js +10 -5
  102. package/src/storable.js +139 -0
  103. package/src/tools/commitments.js +47 -5
  104. package/src/tools/held-write.js +36 -13
  105. package/src/tools/index.js +27 -0
  106. package/src/tools/ingest.js +27 -2
  107. package/src/tools/memory.js +52 -14
  108. package/src/tools/page.js +95 -9
  109. package/src/tools/recall.js +208 -4
  110. package/src/tools/records-kit.js +2 -1
  111. package/src/tools/share.js +42 -3
  112. package/src/tools/shared.js +44 -4
  113. package/src/tools/space-lifecycle.js +278 -0
  114. package/src/tools/spaces.js +373 -29
  115. package/src/tools/status.js +9 -2
  116. package/src/tools/wiki.js +34 -4
  117. package/src/util.js +110 -6
  118. package/src/vendor/source-contract/README.md +24 -0
  119. package/src/vendor/source-contract/THIRD-PARTY-NOTICES.md +35 -0
  120. package/src/vendor/source-contract/VENDOR.json +81 -0
  121. package/src/vendor/source-contract/chunks/chunk-3M5PAKSS.js +84 -0
  122. package/src/vendor/source-contract/chunks/chunk-6HDIB2SA.js +183 -0
  123. package/src/vendor/source-contract/chunks/chunk-HLVAKAYG.js +10 -0
  124. package/src/vendor/source-contract/chunks/chunk-I2RXJJJM.js +81 -0
  125. package/src/vendor/source-contract/chunks/chunk-KWEWSZ4V.js +505 -0
  126. package/src/vendor/source-contract/chunks/chunk-W5SHR7DQ.js +9477 -0
  127. package/src/vendor/source-contract/chunks/chunk-ZUKF7P6U.js +653 -0
  128. package/src/vendor/source-contract/cursor.js +26 -0
  129. package/src/vendor/source-contract/events.js +257 -0
  130. package/src/vendor/source-contract/registry.js +23 -0
  131. package/src/vendor/source-contract/tools-rpc.js +42 -0
  132. package/src/views/access-reads.js +256 -0
  133. package/src/views/communities.js +77 -0
  134. package/src/views/contracts.js +1183 -36
  135. package/src/views/inbox-bytes.js +103 -0
  136. package/src/views/overdue.js +1 -1
  137. package/src/views/profile.js +31 -0
  138. package/src/views/receipt.js +81 -0
  139. package/src/views/records-reads.js +869 -37
  140. package/src/views/rpc.js +159 -11
  141. package/src/views/shape.js +8 -5
  142. package/views/memory.html +16 -3
  143. package/views/pages.html +2 -2
  144. package/views/remembered.html +130 -0
package/src/views/rpc.js CHANGED
@@ -1,24 +1,41 @@
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
4
  import {
5
5
  COMMITMENTS_MAX,
6
+ INBOX_ITEM_MEETING,
7
+ INBOX_ITEM_SESSION,
6
8
  LIST_MAX,
7
9
  PAGE_TEXT_CHARS,
8
10
  SPEAKER_FIELD,
11
+ SPACE_GRANT_ONLY,
12
+ SPOOL_TIME_CHARS,
9
13
  VIEW_ERROR,
10
14
  VIEW_METHODS,
11
15
  } from "./contracts.js"
12
16
  import { createRecordsReads, recordsFailureWords } from "./records-reads.js"
17
+ import { fitInboxRead } from "./inbox-bytes.js"
13
18
  import { oneLinePlain, overdueInboxItems } from "./overdue.js"
14
19
  import { createProfileReads } from "./profile.js"
20
+ import { createAccessReads } from "./access-reads.js"
15
21
  import { SPACE_KINDS, ViewRefusal, clip, clipText, idOf, refuse, spaceOf } from "./shape.js"
16
22
  import { createHeldInboxDecision } from "./inbox-decision.js"
23
+ import { createActionHandlers, createActionReads, createPluginVerifier } from "../actions.js"
24
+ import { createSpaceOperations } from "../ops/index.js"
25
+ import { createToolkit } from "../tools/shared.js"
17
26
 
18
27
  // Jelly has no Inbox action route, signed-grant verifier, or ask bridge yet (#33).
19
28
  // Never enable in production until all three are available and independently verified.
20
29
  export const INBOX_ACTION_RPC_ENABLED = false
21
30
 
31
+ /**
32
+ * The reads' own `personalScopes`, reachable from the RPC registration so an
33
+ * action that reaches the memory core (A12's erase) reads the same scopes the
34
+ * profile read did. It is not a view method: it is reached by this symbol, never
35
+ * named in the declaration.
36
+ */
37
+ export const VIEW_SCOPES = Symbol.for("mem.views.scopes")
38
+
22
39
  /**
23
40
  * The RPC behind Memory's views in Jelly (`views/*.html`).
24
41
  *
@@ -81,7 +98,7 @@ const CREDENTIALS = Object.freeze({
81
98
  * agents?: () => Promise<string[]>,
82
99
  * }} input
83
100
  */
84
- export function createViewReads({ runtime, agents = async () => [] }) {
101
+ export function createViewReads({ runtime, agents = async () => [], operations = null, inboxItemMeeting = INBOX_ITEM_MEETING }) {
85
102
  const { config, backend, credentials } = runtime
86
103
 
87
104
  /** The agent names a view reads under; [] lets control choose. */
@@ -158,6 +175,7 @@ export function createViewReads({ runtime, agents = async () => [] }) {
158
175
 
159
176
  const recordsReads = createRecordsReads({ runtime, personalScopes, available, describe: viewFailureWords })
160
177
  const profileReads = createProfileReads({ runtime, personalScopes, available, describe: viewFailureWords })
178
+ const accessReads = createAccessReads({ runtime, personalScopes, available })
161
179
 
162
180
  /**
163
181
  * The overview of a memory that can't be used now. `state` tells a page which
@@ -167,8 +185,38 @@ export function createViewReads({ runtime, agents = async () => [] }) {
167
185
  */
168
186
  function notConnected(reason, base, status = 0) {
169
187
  const held = credentialState()
170
- const state = overviewState({ ...held, address: base.address, status })
171
- return { connected: false, reason: clip(reason, 400), state, ...held, ...base }
188
+ // The switch's own two states are things to set, not an outage: "on with no
189
+ // address" and an address paused until the switch is on are `unconfigured`,
190
+ // and their reason names the field (R2-S1).
191
+ const note = config?.ownServiceNote ?? ""
192
+ const state = note === "incomplete" || note === "paused" ? "unconfigured" : overviewState({ ...held, address: base.address, status })
193
+ // The switch's own states have no address to show: the one `base` carries is
194
+ // the local simulator's default, and naming it would read as a real service.
195
+ const { address: _simulator, ...withoutAddress } = base
196
+ const shown = note ? withoutAddress : base
197
+ // `capture: false` while memory cannot be used: nothing is captured, and a
198
+ // sheet that reads this field must not say "Capture is on" (jelly #72).
199
+ return {
200
+ connected: false,
201
+ reason: clip(reason, 400),
202
+ state,
203
+ tile: note === "paused" ? TILE_SENTENCES.paused : TILE_SENTENCES[state],
204
+ ...held,
205
+ ...shown,
206
+ capture: false,
207
+ }
208
+ }
209
+
210
+ /**
211
+ * `memory.setup` (jelly #80, D226): the numbers this engine start's setup
212
+ * recorded, and nothing else — no sign-in, no request, no space, so the host
213
+ * can read it as soon as the engine is up. A copy, so a caller cannot change
214
+ * what the next read answers.
215
+ */
216
+ function setup() {
217
+ const record = runtime.setupTime
218
+ if (!record) refuse("Memory has no setup record for this start.")
219
+ return { ms: record.ms, phases: record.phases.map((phase) => ({ name: phase.name, ms: phase.ms })), at: record.at }
172
220
  }
173
221
 
174
222
  async function overview() {
@@ -179,6 +227,12 @@ export function createViewReads({ runtime, agents = async () => [] }) {
179
227
  extraction: "unknown",
180
228
  ...(address ? { address: clip(address, 300) } : {}),
181
229
  }
230
+ // The switch's own states first: "on with no address" and an address paused
231
+ // until the switch is on are things to set, not an outage to retry (R2-S1).
232
+ const ownServiceNote = config?.ownServiceNote ?? ""
233
+ if (ownServiceNote) {
234
+ return notConnected(unavailableReason({ source: "", controlURL: "", memoryResourceOffered: true, ownServiceNote }), base)
235
+ }
182
236
  const reason = await unavailableNow()
183
237
  if (reason) return notConnected(reason, base)
184
238
  let scopes
@@ -226,11 +280,42 @@ export function createViewReads({ runtime, agents = async () => [] }) {
226
280
  extraction: ["healthy", "failing", "unknown"].includes(extraction?.state) ? extraction.state : "unknown",
227
281
  ...(extraction?.state === "failing" && typeof extraction.failing_since === "string" && /^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d{3}Z$/.test(extraction.failing_since) ? { failing_since: extraction.failing_since } : {}),
228
282
  ...(kept.records ? { records: kept.records } : {}),
283
+ ...spoolQueue(),
229
284
  space: spaceOf(scopes[0]?.context),
230
285
  counts,
231
286
  }
232
287
  }
233
288
 
289
+ /**
290
+ * The engine's capture queue, as `mem_status` tells the agent (#58 F6): what
291
+ * still waits to be sent, and when the oldest of those was queued. It is this
292
+ * machine's queue whatever space the person reads, so a host several people
293
+ * share shows their queue together; a build that keeps no queue says nothing.
294
+ */
295
+ function spoolQueue() {
296
+ let stats
297
+ try {
298
+ stats = runtime.spoolStats?.()
299
+ } catch (error) {
300
+ runtime.log?.debug?.("view overview: the capture queue was not read", { error: error?.message })
301
+ return {}
302
+ }
303
+ if (!stats || typeof stats !== "object") return {}
304
+ const depth = Math.max(0, Math.floor(Number(stats.pending) || 0))
305
+ return {
306
+ spool: {
307
+ depth,
308
+ ...(depth > 0 && typeof stats.oldest === "string" && stats.oldest.trim() ? { oldest: clip(stats.oldest.trim(), SPOOL_TIME_CHARS) } : {}),
309
+ },
310
+ }
311
+ }
312
+
313
+ /** A non-negative whole count, or undefined when the answer has none (jelly #55). */
314
+ const countOf = (value) => {
315
+ const number = Number(value)
316
+ return Number.isInteger(number) && number >= 0 ? number : undefined
317
+ }
318
+
234
319
  async function spacesList() {
235
320
  await available()
236
321
  if (!runtime.control) return { spaces: [{ ...spaceOf(null), role: "owner" }] }
@@ -243,7 +328,10 @@ export function createViewReads({ runtime, agents = async () => [] }) {
243
328
  id: idOf(space.space_id),
244
329
  name: clip(space.name || space.space_id, 200),
245
330
  kind: SPACE_KINDS.has(space.kind) ? space.kind : "unknown",
331
+ grantOnly: SPACE_GRANT_ONLY,
246
332
  role: clip(space.role ?? "", 40),
333
+ ...(countOf(space.members) === undefined ? {} : { members: countOf(space.members) }),
334
+ ...(countOf(space.wikis) === undefined ? {} : { wikis: countOf(space.wikis) }),
247
335
  })),
248
336
  }
249
337
  }
@@ -358,18 +446,39 @@ export function createViewReads({ runtime, agents = async () => [] }) {
358
446
  * OpenCode keeps its Due list (`mem_commitments`, the pinned block). The host
359
447
  * replaces its whole copy with each answer, so a part that cannot be read
360
448
  * fails the whole read (the host then keeps what it had) rather than answer a
361
- * list that would drop items still true.
449
+ * list that would drop items still true. For the same reason one answer is
450
+ * held under `INBOX_READ_BYTES_MAX` bytes — a guard for the day an item
451
+ * carries its meeting, since today's read peaks at 28–33 KB — by giving up
452
+ * `evidence`, then `meeting`, then the words, from the last item backwards:
453
+ * never an item and never a key (`fitInboxRead`, `src/views/inbox-bytes.js`).
362
454
  */
363
455
  async function inboxList() {
364
456
  await available()
365
- const [review, overdue] = await Promise.all([recordsReads.methods["review.list"]({}), overdueNotices()])
366
- const proposals = review.items.flatMap((item) => {
457
+ const [review, overdue] = await Promise.all([recordsReads.reviewWith({}), overdueNotices()])
458
+ const proposals = review.items.flatMap(({ item, kind, session }) => {
367
459
  if (!/^rec_[0-9A-Za-z]{1,64}$/.test(item.id)) return []
368
460
  if (!inboxTime(item.created)) return []
369
461
  const title = oneLinePlain(item.title, 120)
370
- return [{ key: `proposal:${item.id}`, category: "request", label: "Proposal", name: "Memory", line: title || "A proposal is waiting for review", at: item.created }]
462
+ return [{
463
+ key: `proposal:${item.id}`,
464
+ category: "request",
465
+ label: "Proposal",
466
+ name: "Memory",
467
+ line: title || "A proposal is waiting for review",
468
+ at: item.created,
469
+ ...(kind ? { kind } : {}),
470
+ // The meeting a proposal was drawn from, and the moments it cites, as
471
+ // `review.list` carries them (#62): the proposal's own fields, read from
472
+ // the same space. Held back until Jelly's strict Inbox item takes them
473
+ // (INBOX_ITEM_MEETING, src/views/contracts.js).
474
+ ...(inboxItemMeeting && item.meeting ? { meeting: item.meeting } : {}),
475
+ ...(inboxItemMeeting && item.evidence?.length ? { evidence: item.evidence } : {}),
476
+ // The session is stored and read already; Jelly's strict Inbox reader has
477
+ // no such field yet, so it goes on the wire only when `INBOX_ITEM_SESSION`.
478
+ ...(INBOX_ITEM_SESSION && session ? { session } : {}),
479
+ }]
371
480
  })
372
- return { items: [...proposals, ...overdue] }
481
+ return fitInboxRead({ items: [...proposals, ...overdue] })
373
482
  }
374
483
 
375
484
  /** One item for each of the person's overdue commitments: the same rule `commitments.list` marks `overdue`. */
@@ -382,6 +491,7 @@ export function createViewReads({ runtime, agents = async () => [] }) {
382
491
  return {
383
492
  "commitments.list": commitmentsList,
384
493
  "inbox.list": inboxList,
494
+ "memory.setup": setup,
385
495
  "memory.overview": overview,
386
496
  "spaces.list": spacesList,
387
497
  "wiki.list": wikiList,
@@ -389,6 +499,9 @@ export function createViewReads({ runtime, agents = async () => [] }) {
389
499
  "wiki.read": wikiRead,
390
500
  ...recordsReads.methods,
391
501
  ...profileReads,
502
+ ...accessReads,
503
+ ...createActionReads({ runtime, personalScopes, operations }),
504
+ [VIEW_SCOPES]: personalScopes,
392
505
  }
393
506
  }
394
507
 
@@ -402,6 +515,21 @@ function viewWords(reason) {
402
515
  return reason === UNLINKED_SENTENCE && inView() ? VIEW_UNLINKED_SENTENCE : reason
403
516
  }
404
517
 
518
+ /**
519
+ * One fixed sentence per overview state (jelly #73): one full sentence, at most
520
+ * 60 characters, so a phone tile holds it whole, and its next step names
521
+ * something the person can see on Memory's card — whatever credential it was
522
+ * (a key, a Jelly sign-in or OpenCode's), the card is where it is fixed.
523
+ * `reason` stays free text for the reading pane; a tile draws `tile`.
524
+ */
525
+ export const TILE_SENTENCES = Object.freeze({
526
+ unconfigured: "Open Memory's card and connect to start using it.",
527
+ refused: "Open Memory's card and connect again; it was refused.",
528
+ unreachable: "Try again in a moment; Memory cannot be reached.",
529
+ // Not a state `overviewState` returns: a saved address waiting for the switch.
530
+ paused: "Turn on \"Use my own Memory service\" in Memory's settings.",
531
+ })
532
+
405
533
  /**
406
534
  * Why `memory.overview` is `connected: false`, as the page tells it: "unconfigured"
407
535
  * (no credential, no address, or no linked Jelly account), "refused" (a credential
@@ -490,9 +618,15 @@ export function splitSpeaker(input) {
490
618
  * @param {any} ctx
491
619
  * @param {any} runtime
492
620
  */
493
- export async function registerViewRpc(ctx, runtime, { enableInboxActions = INBOX_ACTION_RPC_ENABLED, verifyInboxAction } = {}) {
621
+ export async function registerViewRpc(ctx, runtime, { enableInboxActions = INBOX_ACTION_RPC_ENABLED, verifyInboxAction, inboxItemMeeting = INBOX_ITEM_MEETING } = {}) {
494
622
  if (typeof ctx?.rpc?.register !== "function") return null
495
- const reads = createViewReads({ runtime, agents: engineAgents(ctx) })
623
+ // The space and sharing operations an action runs (`src/ops`), built on the
624
+ // same toolkit the tools use: the control plane, the person's records client,
625
+ // and the space the gateway resolves. A build with no control plane still
626
+ // builds them; each operation then refuses with SCOPE_MISSING.
627
+ const operations = createSpaceOperations(createToolkit(ctx, runtime))
628
+ const reads = createViewReads({ runtime, agents: engineAgents(ctx), operations, inboxItemMeeting })
629
+ const personalScopes = reads[VIEW_SCOPES] ?? (async () => [])
496
630
  const methods = {}
497
631
  const handlers = {}
498
632
  for (const method of VIEW_METHODS) {
@@ -511,6 +645,20 @@ export async function registerViewRpc(ctx, runtime, { enableInboxActions = INBOX
511
645
  return typeof speaker === "string" ? asView(speaker, read) : read()
512
646
  }
513
647
  }
648
+ // The actions a person's own page may change, under a host-signed grant
649
+ // (src/actions.js): registered as `act.<name>`, which Jelly's own fence
650
+ // refuses to anything but the host's call for a person. Dark until
651
+ // `config.actions`; an agent never holds one.
652
+ const actions = createActionHandlers({
653
+ config: runtime.config,
654
+ runtime,
655
+ verifier: createPluginVerifier({ keyFile: runtime.config.actionKeysFile || null, maxAgeHours: runtime.config.actionKeysMaxAgeHours ?? 24, log: runtime.log }),
656
+ personalScopes,
657
+ operations,
658
+ log: runtime.log,
659
+ })
660
+ Object.assign(methods, actions.methods)
661
+ Object.assign(handlers, actions.handlers)
514
662
  if (enableInboxActions) {
515
663
  if (typeof verifyInboxAction !== "function") throw new Error("Inbox actions require a grant verifier and ask bridge")
516
664
  const decide = createHeldInboxDecision(runtime)
@@ -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) > ANSWER_BYTES) {
77
+ if (jsonBytes(answer) > limit) {
75
78
  answer[key].pop()
76
79
  fitted = true
77
80
  break
package/views/memory.html CHANGED
@@ -2,7 +2,7 @@
2
2
  <html lang="en-GB">
3
3
  <head>
4
4
  <meta charset="utf-8">
5
- <meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'sha256-5dtPKkjegOPG8bawdSzGBjixnIaSCLYcZOUAwbRWFAc=' 'sha256-EAE0IDrikWE0chPIVODVlKBvBg1sDxCO9UEtFartZJY=' 'sha256-Q8fg8cAZZmRD62VpizjSMkhTSUfbnStU+/9BjGxdfVg='; style-src 'unsafe-inline'; base-uri 'none'; form-action 'none'">
5
+ <meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'sha256-5dtPKkjegOPG8bawdSzGBjixnIaSCLYcZOUAwbRWFAc=' 'sha256-EAE0IDrikWE0chPIVODVlKBvBg1sDxCO9UEtFartZJY=' 'sha256-4GpOEHrmhpQeGOnWxWJkhPlG8s/H/7l0oepo4IUqzH8='; style-src 'unsafe-inline'; base-uri 'none'; form-action 'none'">
6
6
  <title>Your memory</title>
7
7
  <style>
8
8
  :root {
@@ -553,8 +553,6 @@ async function profileTab() {
553
553
  answer.incomplete ? el("p", {}, el("strong", {}, "This may be less than Memory holds.")) : null,
554
554
  el("ul", {}, answer.notes.map((note) => el("li", {}, note))))
555
555
  : null;
556
- if (answer.items.length === 0)
557
- return show(p("Memory holds nothing about you yet. It writes this from your conversations, once it has enough of them.", "muted"), notes);
558
556
  const several = new Set(answer.items.map((item) => item.agent)).size > 1;
559
557
  const part = (item) => el("section", { class: "spaced" },
560
558
  el("h2", {}, item.layer === "persona" ? "Your profile" : item.summary || item.path),
@@ -562,10 +560,25 @@ async function profileTab() {
562
560
  el("div", { class: "page" }, item.text),
563
561
  item.clipped ? p("This is long, so only its start is shown.", "muted") : null,
564
562
  );
563
+ // The people and names Memory knows, for a person who wonders what she can
564
+ // refer to: a failed read shows nothing here rather than an empty claim.
565
+ const names = await call("terms.list", { max: 50 }).catch(() => null);
566
+ const namesList = names && names.terms.length > 0
567
+ ? el("section", { class: "spaced" },
568
+ el("h2", {}, "Names Memory knows"),
569
+ el("ul", {}, names.terms.map((term) => el("li", {},
570
+ el("span", {}, term.text),
571
+ el("span", { class: "meta" }, [term.kind, term.space.name].filter(Boolean).join(" · ")),
572
+ ))),
573
+ names.more ? p("Memory knows more names than this page shows.", "muted") : null,
574
+ )
575
+ : null;
565
576
  show(
566
577
  p(answer.label, "muted"),
567
578
  notes,
568
579
  answer.items.map(part),
580
+ answer.items.length === 0 ? p("Memory holds nothing about you yet. It writes this from your conversations, once it has enough of them.", "muted") : null,
581
+ namesList,
569
582
  answer.more ? p("Memory holds more than this page shows.", "muted spaced") : null,
570
583
  p("To erase something, ask an agent to forget it. It shows you what would go first.", "muted spaced"),
571
584
  );
package/views/pages.html CHANGED
@@ -2,7 +2,7 @@
2
2
  <html lang="en-GB">
3
3
  <head>
4
4
  <meta charset="utf-8">
5
- <meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'sha256-5dtPKkjegOPG8bawdSzGBjixnIaSCLYcZOUAwbRWFAc=' 'sha256-/0aqZ5aL9ON4+6IAVSSwbjH6b/AakzUoE2N5RwMn9BM=' 'sha256-kcB3avtu0E7ugdIHrPBh8YQCbQ7N8LUdbAMODHpXxuY='; style-src 'unsafe-inline'; base-uri 'none'; form-action 'none'">
5
+ <meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'sha256-5dtPKkjegOPG8bawdSzGBjixnIaSCLYcZOUAwbRWFAc=' 'sha256-/0aqZ5aL9ON4+6IAVSSwbjH6b/AakzUoE2N5RwMn9BM=' 'sha256-jqMVE0B1Xg8TD+ZhKc6LhMN5HHe1r/kmn3M7tEmufZE='; style-src 'unsafe-inline'; base-uri 'none'; form-action 'none'">
6
6
  <title>Pages</title>
7
7
  <style>
8
8
  :root {
@@ -620,7 +620,7 @@ async function drawPage(read, folder) {
620
620
  if (record.clipped) nodes.push(el("p", "muted", "This page is longer than a view shows: ask your agent to read the rest."));
621
621
  nodes.push(
622
622
  linkList("Links to", record.outlinks, folder, "This page links to nothing."),
623
- linkList(`Linked from${record.backlinksMore ? " (the newest)" : ""}`, record.backlinks, folder, "Nothing links here yet."),
623
+ linkList(`Linked from${record.backlinksMore ? " (the newest)" : ""}`, record.backlinks, folder, record.backlinksPartial ? "Nothing you can see links here." : "Nothing links here yet."),
624
624
  history,
625
625
  );
626
626
  show(...nodes);
@@ -0,0 +1,130 @@
1
+ <!doctype html>
2
+ <html lang="en-GB">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'sha256-5dtPKkjegOPG8bawdSzGBjixnIaSCLYcZOUAwbRWFAc=' 'sha256-CgOSZ+LvHH0rQecGCbWZUjN52v54OBWuJzsy7gzsz44='; style-src 'unsafe-inline'; base-uri 'none'; form-action 'none'">
6
+ <title>Saved to memory</title>
7
+ <style>
8
+ :root { color: var(--jelly-text, CanvasText); background: var(--jelly-surface, Canvas); font: 14px/1.5 var(--jelly-font, system-ui, sans-serif); }
9
+ body { margin: 0; padding: 16px; }
10
+ h1 { font-size: 18px; margin: 0 0 12px; }
11
+ p { margin: 8px 0; }
12
+ .muted { color: var(--jelly-muted, GrayText); }
13
+ </style>
14
+ </head>
15
+ <body>
16
+ <main aria-live="polite"><h1>Saved to memory</h1><div id="receipt" class="muted">Loading…</div><div id="where"></div></main>
17
+ <script>
18
+ // jelly-view.js: a client of Jelly's view bridge. Paste it into the page's own <script>:
19
+ // a sealed page loads no script by URL and is given no global. Call jellyView() as the
20
+ // script starts; it resolves with the client when the app says hello.
21
+ function jellyView() {
22
+ return new Promise((resolve) => {
23
+ addEventListener("message", function hello(event) {
24
+ const said = event.data;
25
+ if (event.source !== parent || said?.v !== 1 || said.kind !== "hello" || !event.ports[0])
26
+ return;
27
+ removeEventListener("message", hello);
28
+ const port = event.ports[0];
29
+ const listeners = new Set();
30
+ const latest = new Map();
31
+ const queue = [];
32
+ let sequence = 0;
33
+ let current;
34
+ const theme = (tokens) => {
35
+ const style = document.documentElement.style;
36
+ for (const [name, value] of Object.entries(tokens))
37
+ if (name === "scheme") style.colorScheme = value;
38
+ else style.setProperty(`--jelly-${name}`, value);
39
+ };
40
+ // The app answers one request at a time, so requests go in turn.
41
+ const next = () => {
42
+ if (current !== undefined || queue.length === 0) return;
43
+ current = queue.shift();
44
+ current.timer = setTimeout(
45
+ () => settle({ ok: false, error: "No answer from the app" }),
46
+ 15000,
47
+ );
48
+ port.postMessage(current.message);
49
+ };
50
+ const settle = (answer) => {
51
+ const done = current;
52
+ current = undefined;
53
+ clearTimeout(done.timer);
54
+ if (answer.ok) done.resolve(answer.value);
55
+ else done.reject(new Error(answer.error));
56
+ next();
57
+ };
58
+ port.onmessage = ({ data }) => {
59
+ if (data?.v !== 1) return;
60
+ if (typeof data.kind !== "string") {
61
+ if (current !== undefined && data.re === current.message.id) settle(data);
62
+ return;
63
+ }
64
+ // A call waiting for the person is answered by `until`, not in 15 s.
65
+ if (data.kind === "rpc.waiting" && data.re === current?.message.id) {
66
+ clearTimeout(current.timer);
67
+ current.timer = setTimeout(
68
+ () => settle({ ok: false, error: "No answer from the app" }),
69
+ Math.max(0, Date.parse(data.until) - Date.now()) + 15000,
70
+ );
71
+ }
72
+ if (data.kind === "theme.changed") theme(data.theme);
73
+ // A wait is news only while it lasts, so a later listener is not told of it.
74
+ if (data.kind !== "rpc.waiting") latest.set(data.kind, data);
75
+ for (const listener of listeners) listener(data);
76
+ };
77
+ port.start();
78
+ theme(said.theme);
79
+ const request = (op, fields = {}) =>
80
+ new Promise((resolve, reject) => {
81
+ queue.push({ resolve, reject, message: { ...fields, v: 1, id: String(++sequence), op } });
82
+ next();
83
+ });
84
+ resolve({
85
+ hello: said,
86
+ // A listener first hears the latest push of each kind that came before it.
87
+ on(listener) {
88
+ for (const push of latest.values()) listener(push);
89
+ listeners.add(listener);
90
+ return () => listeners.delete(listener);
91
+ },
92
+ request,
93
+ data: () => request("data.get"),
94
+ state: () => request("state.get"),
95
+ setState: (revision, data) => request("state.set", { revision, data }),
96
+ call: (method, input = {}) => request("rpc.call", { method, input }),
97
+ openAgent: (prefill) => request("open-agent", prefill === undefined ? {} : { prefill }),
98
+ resize: (height) =>
99
+ request("resize", { height: Math.min(1200, Math.max(1, Math.ceil(height))) }),
100
+ decline: () => request("decline"),
101
+ });
102
+ });
103
+ });
104
+ }
105
+ </script>
106
+ <script>
107
+ jellyView().then(async (view) => {
108
+ const result = await view.data();
109
+ const data = result?.metadata?.memoryReceipt;
110
+ const receipt = document.getElementById("receipt");
111
+ const where = document.getElementById("where");
112
+ const ACTIONS = ["remembered", "corrected", "confirmed", "retired", "restored", "committed"];
113
+ const yes = data && data.v === 1 && typeof data.id === "string" && ACTIONS.includes(data.action);
114
+ if (!yes) {
115
+ receipt.textContent = "Receipt details are not available for this result.";
116
+ return;
117
+ }
118
+ const said = { remembered: "Remembered", corrected: "Corrected", confirmed: "Confirmed", retired: "Retired", restored: "Restored", committed: "Commitment added" }[data.action];
119
+ // Memory's own text is data: it is set as text, never as markup.
120
+ receipt.textContent = typeof data.title === "string" && data.title ? `${said}: ${data.title}` : said;
121
+ receipt.className = "";
122
+ const parts = [data.kind, data.type, data.status].filter((part) => typeof part === "string" && part);
123
+ const space = data.space;
124
+ const at = space && typeof space.name === "string" && space.name ? `in ${space.name}` : "";
125
+ where.textContent = [parts.join(" · "), at].filter(Boolean).join(" ");
126
+ where.className = "muted";
127
+ }).catch(() => { document.getElementById("receipt").textContent = "Receipt details are not available for this result."; });
128
+ </script>
129
+ </body>
130
+ </html>