@joe-broadhead/opencode-mem 0.9.14 → 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 (139) hide show
  1. package/CHANGELOG.md +1805 -0
  2. package/README.md +14 -7
  3. package/SECURITY.md +3 -1
  4. package/docs/agent-instructions.md +1 -1
  5. package/docs/agent-protocol.md +7 -7
  6. package/docs/permissions.md +16 -0
  7. package/package.json +7688 -339
  8. package/shared/page-paths.js +44 -0
  9. package/skills/mem.pages/SKILL.md +3 -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 +623 -30
  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 +11 -6
  88. package/src/recall.js +92 -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 +389 -92
  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 +37 -4
  104. package/src/tools/held-write.js +31 -12
  105. package/src/tools/index.js +27 -0
  106. package/src/tools/ingest.js +27 -2
  107. package/src/tools/memory.js +30 -7
  108. package/src/tools/page.js +95 -9
  109. package/src/tools/recall.js +208 -4
  110. package/src/tools/share.js +42 -3
  111. package/src/tools/shared.js +44 -4
  112. package/src/tools/space-lifecycle.js +278 -0
  113. package/src/tools/spaces.js +373 -29
  114. package/src/tools/status.js +9 -2
  115. package/src/tools/wiki.js +34 -4
  116. package/src/util.js +110 -6
  117. package/src/vendor/source-contract/README.md +24 -0
  118. package/src/vendor/source-contract/THIRD-PARTY-NOTICES.md +35 -0
  119. package/src/vendor/source-contract/VENDOR.json +81 -0
  120. package/src/vendor/source-contract/chunks/chunk-3M5PAKSS.js +84 -0
  121. package/src/vendor/source-contract/chunks/chunk-6HDIB2SA.js +183 -0
  122. package/src/vendor/source-contract/chunks/chunk-HLVAKAYG.js +10 -0
  123. package/src/vendor/source-contract/chunks/chunk-I2RXJJJM.js +81 -0
  124. package/src/vendor/source-contract/chunks/chunk-KWEWSZ4V.js +505 -0
  125. package/src/vendor/source-contract/chunks/chunk-W5SHR7DQ.js +9477 -0
  126. package/src/vendor/source-contract/chunks/chunk-ZUKF7P6U.js +653 -0
  127. package/src/vendor/source-contract/cursor.js +26 -0
  128. package/src/vendor/source-contract/events.js +257 -0
  129. package/src/vendor/source-contract/registry.js +23 -0
  130. package/src/vendor/source-contract/tools-rpc.js +42 -0
  131. package/src/views/access-reads.js +256 -0
  132. package/src/views/communities.js +77 -0
  133. package/src/views/contracts.js +930 -21
  134. package/src/views/inbox-bytes.js +103 -0
  135. package/src/views/profile.js +31 -0
  136. package/src/views/records-reads.js +355 -38
  137. package/src/views/rpc.js +118 -8
  138. package/src/views/shape.js +8 -5
  139. package/views/pages.html +2 -2
package/src/views/rpc.js CHANGED
@@ -1,26 +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,
6
7
  INBOX_ITEM_SESSION,
7
8
  LIST_MAX,
8
9
  PAGE_TEXT_CHARS,
9
10
  SPEAKER_FIELD,
11
+ SPACE_GRANT_ONLY,
10
12
  SPOOL_TIME_CHARS,
11
13
  VIEW_ERROR,
12
14
  VIEW_METHODS,
13
15
  } from "./contracts.js"
14
16
  import { createRecordsReads, recordsFailureWords } from "./records-reads.js"
17
+ import { fitInboxRead } from "./inbox-bytes.js"
15
18
  import { oneLinePlain, overdueInboxItems } from "./overdue.js"
16
19
  import { createProfileReads } from "./profile.js"
20
+ import { createAccessReads } from "./access-reads.js"
17
21
  import { SPACE_KINDS, ViewRefusal, clip, clipText, idOf, refuse, spaceOf } from "./shape.js"
18
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"
19
26
 
20
27
  // Jelly has no Inbox action route, signed-grant verifier, or ask bridge yet (#33).
21
28
  // Never enable in production until all three are available and independently verified.
22
29
  export const INBOX_ACTION_RPC_ENABLED = false
23
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
+
24
39
  /**
25
40
  * The RPC behind Memory's views in Jelly (`views/*.html`).
26
41
  *
@@ -83,7 +98,7 @@ const CREDENTIALS = Object.freeze({
83
98
  * agents?: () => Promise<string[]>,
84
99
  * }} input
85
100
  */
86
- export function createViewReads({ runtime, agents = async () => [] }) {
101
+ export function createViewReads({ runtime, agents = async () => [], operations = null, inboxItemMeeting = INBOX_ITEM_MEETING }) {
87
102
  const { config, backend, credentials } = runtime
88
103
 
89
104
  /** The agent names a view reads under; [] lets control choose. */
@@ -160,6 +175,7 @@ export function createViewReads({ runtime, agents = async () => [] }) {
160
175
 
161
176
  const recordsReads = createRecordsReads({ runtime, personalScopes, available, describe: viewFailureWords })
162
177
  const profileReads = createProfileReads({ runtime, personalScopes, available, describe: viewFailureWords })
178
+ const accessReads = createAccessReads({ runtime, personalScopes, available })
163
179
 
164
180
  /**
165
181
  * The overview of a memory that can't be used now. `state` tells a page which
@@ -169,8 +185,38 @@ export function createViewReads({ runtime, agents = async () => [] }) {
169
185
  */
170
186
  function notConnected(reason, base, status = 0) {
171
187
  const held = credentialState()
172
- const state = overviewState({ ...held, address: base.address, status })
173
- 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 }
174
220
  }
175
221
 
176
222
  async function overview() {
@@ -181,6 +227,12 @@ export function createViewReads({ runtime, agents = async () => [] }) {
181
227
  extraction: "unknown",
182
228
  ...(address ? { address: clip(address, 300) } : {}),
183
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
+ }
184
236
  const reason = await unavailableNow()
185
237
  if (reason) return notConnected(reason, base)
186
238
  let scopes
@@ -258,6 +310,12 @@ export function createViewReads({ runtime, agents = async () => [] }) {
258
310
  }
259
311
  }
260
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
+
261
319
  async function spacesList() {
262
320
  await available()
263
321
  if (!runtime.control) return { spaces: [{ ...spaceOf(null), role: "owner" }] }
@@ -270,7 +328,10 @@ export function createViewReads({ runtime, agents = async () => [] }) {
270
328
  id: idOf(space.space_id),
271
329
  name: clip(space.name || space.space_id, 200),
272
330
  kind: SPACE_KINDS.has(space.kind) ? space.kind : "unknown",
331
+ grantOnly: SPACE_GRANT_ONLY,
273
332
  role: clip(space.role ?? "", 40),
333
+ ...(countOf(space.members) === undefined ? {} : { members: countOf(space.members) }),
334
+ ...(countOf(space.wikis) === undefined ? {} : { wikis: countOf(space.wikis) }),
274
335
  })),
275
336
  }
276
337
  }
@@ -385,7 +446,11 @@ export function createViewReads({ runtime, agents = async () => [] }) {
385
446
  * OpenCode keeps its Due list (`mem_commitments`, the pinned block). The host
386
447
  * replaces its whole copy with each answer, so a part that cannot be read
387
448
  * fails the whole read (the host then keeps what it had) rather than answer a
388
- * 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`).
389
454
  */
390
455
  async function inboxList() {
391
456
  await available()
@@ -402,12 +467,18 @@ export function createViewReads({ runtime, agents = async () => [] }) {
402
467
  line: title || "A proposal is waiting for review",
403
468
  at: item.created,
404
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 } : {}),
405
476
  // The session is stored and read already; Jelly's strict Inbox reader has
406
477
  // no such field yet, so it goes on the wire only when `INBOX_ITEM_SESSION`.
407
478
  ...(INBOX_ITEM_SESSION && session ? { session } : {}),
408
479
  }]
409
480
  })
410
- return { items: [...proposals, ...overdue] }
481
+ return fitInboxRead({ items: [...proposals, ...overdue] })
411
482
  }
412
483
 
413
484
  /** One item for each of the person's overdue commitments: the same rule `commitments.list` marks `overdue`. */
@@ -420,6 +491,7 @@ export function createViewReads({ runtime, agents = async () => [] }) {
420
491
  return {
421
492
  "commitments.list": commitmentsList,
422
493
  "inbox.list": inboxList,
494
+ "memory.setup": setup,
423
495
  "memory.overview": overview,
424
496
  "spaces.list": spacesList,
425
497
  "wiki.list": wikiList,
@@ -427,6 +499,9 @@ export function createViewReads({ runtime, agents = async () => [] }) {
427
499
  "wiki.read": wikiRead,
428
500
  ...recordsReads.methods,
429
501
  ...profileReads,
502
+ ...accessReads,
503
+ ...createActionReads({ runtime, personalScopes, operations }),
504
+ [VIEW_SCOPES]: personalScopes,
430
505
  }
431
506
  }
432
507
 
@@ -440,6 +515,21 @@ function viewWords(reason) {
440
515
  return reason === UNLINKED_SENTENCE && inView() ? VIEW_UNLINKED_SENTENCE : reason
441
516
  }
442
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
+
443
533
  /**
444
534
  * Why `memory.overview` is `connected: false`, as the page tells it: "unconfigured"
445
535
  * (no credential, no address, or no linked Jelly account), "refused" (a credential
@@ -528,9 +618,15 @@ export function splitSpeaker(input) {
528
618
  * @param {any} ctx
529
619
  * @param {any} runtime
530
620
  */
531
- 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 } = {}) {
532
622
  if (typeof ctx?.rpc?.register !== "function") return null
533
- 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 () => [])
534
630
  const methods = {}
535
631
  const handlers = {}
536
632
  for (const method of VIEW_METHODS) {
@@ -549,6 +645,20 @@ export async function registerViewRpc(ctx, runtime, { enableInboxActions = INBOX
549
645
  return typeof speaker === "string" ? asView(speaker, read) : read()
550
646
  }
551
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)
552
662
  if (enableInboxActions) {
553
663
  if (typeof verifyInboxAction !== "function") throw new Error("Inbox actions require a grant verifier and ask bridge")
554
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/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);