@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.
Files changed (143) hide show
  1. package/CHANGELOG.md +1856 -0
  2. package/README.md +15 -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 +8921 -1070
  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 +88 -7
  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 +74 -23
  104. package/src/tools/held-write.js +46 -19
  105. package/src/tools/index.js +28 -0
  106. package/src/tools/ingest.js +38 -2
  107. package/src/tools/memory.js +56 -25
  108. package/src/tools/page.js +212 -95
  109. package/src/tools/recall.js +218 -4
  110. package/src/tools/share.js +42 -3
  111. package/src/tools/shared.js +84 -6
  112. package/src/tools/space-lifecycle.js +278 -0
  113. package/src/tools/spaces.js +381 -30
  114. package/src/tools/status.js +9 -2
  115. package/src/tools/wiki.js +231 -116
  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 +1082 -23
  134. package/src/views/inbox-bytes.js +103 -0
  135. package/src/views/profile.js +31 -0
  136. package/src/views/receipt.js +26 -1
  137. package/src/views/records-reads.js +520 -41
  138. package/src/views/rpc.js +153 -25
  139. package/src/views/shape.js +8 -5
  140. package/src/views/write-state.js +89 -0
  141. package/src/wiki-ingest.js +215 -0
  142. package/src/wiki-state.js +228 -0
  143. package/views/pages.html +2 -2
@@ -0,0 +1,103 @@
1
+ import { INBOX_READ_BYTES_MAX } from "./contracts.js"
2
+ import { clip, jsonBytes, refuse } from "./shape.js"
3
+
4
+ /**
5
+ * One Inbox read, held under the host's byte cap.
6
+ *
7
+ * Jelly sizes a plugin RPC answer at 65,536 bytes (`VIEW_DATA_MAX_BYTES`) and
8
+ * refuses a larger one silently, keeping the person's last Inbox
9
+ * (`backend/host/src/plugin-views/rpc.ts:247`).
10
+ *
11
+ * **A guard, not a fix.** Today's read peaks at 28–33 KB and nothing is
12
+ * trimmed. The cap is for the day an Inbox item carries its meeting
13
+ * (`INBOX_ITEM_MEETING`): with those fields on, a full Inbox of proposals whose
14
+ * moments are quoted in CJK comes to about 75–80 KB, and this trims it to about
15
+ * 61 KB.
16
+ *
17
+ * What is given up, from the last item backwards:
18
+ *
19
+ * 1. **`evidence` entries**;
20
+ * 2. then **`meeting`**;
21
+ * 3. then the **words**, `line` and `name`, cut on a character boundary and
22
+ * ending in "…".
23
+ *
24
+ * Stages 1 and 2 are spent across every item before the next begins, so no item
25
+ * is made unreadable while another still carries what it could give up. The
26
+ * words are not: the last item is shortened as far as it needs before the one
27
+ * above is touched at all.
28
+ *
29
+ * **Never an item and never a `key`.** The host replaces its whole copy with
30
+ * each answer, so an item left out is one that vanishes from the person's Inbox
31
+ * while it is still true. When even the trimmed answer cannot be carried, the
32
+ * read refuses as an unreadable part does today, and the host keeps what it
33
+ * had.
34
+ */
35
+
36
+ /** What goes before the words, in the order it goes. */
37
+ const OPTIONAL = ["evidence", "meeting"]
38
+
39
+ /** The words a too-large answer refuses with: the read fails whole, as an unreadable part does. */
40
+ export const INBOX_TOO_LARGE = "The Inbox is too large to read in one answer, so it has not been read."
41
+
42
+ /**
43
+ * `answer` (its `items`) held under `limit` UTF-8 bytes of JSON, trimmed as
44
+ * this module's header describes, or a refusal when even that cannot fit.
45
+ *
46
+ * @template {{ items: Array<object> }} Answer
47
+ * @param {Answer} answer
48
+ * @param {number} [limit]
49
+ * @returns {Answer}
50
+ */
51
+ export function fitInboxRead(answer, limit = INBOX_READ_BYTES_MAX) {
52
+ if (jsonBytes(answer) <= limit) return answer
53
+ const items = answer.items.map((item) => ({ ...item }))
54
+ const fitted = { ...answer, items }
55
+ const over = () => jsonBytes(fitted) > limit
56
+
57
+ for (const field of OPTIONAL) {
58
+ for (let at = items.length - 1; at >= 0 && over(); at -= 1) {
59
+ if (field === "evidence") {
60
+ // One entry at a time, so an answer a single moment over the cap keeps the rest.
61
+ while (over() && Array.isArray(items[at].evidence) && items[at].evidence.length > 0)
62
+ items[at].evidence = items[at].evidence.slice(0, -1)
63
+ } else if (items[at].meeting !== undefined) {
64
+ delete items[at].meeting
65
+ }
66
+ }
67
+ }
68
+
69
+ for (let at = items.length - 1; at >= 0 && over(); at -= 1) {
70
+ for (const field of ["line", "name"]) {
71
+ const text = items[at][field]
72
+ if (typeof text === "string" && text !== "") items[at][field] = shorten(fitted, items[at], field, text, limit)
73
+ }
74
+ }
75
+
76
+ if (over()) refuse(INBOX_TOO_LARGE)
77
+ return fitted
78
+ }
79
+
80
+ /**
81
+ * `text` shortened to the longest prefix, ending in "…", that keeps `answer`
82
+ * under `limit`; `"…"`, the shortest the words can be, when no prefix does.
83
+ *
84
+ * The search starts at one character: `clip(text, 1)` is `"…"` for any text,
85
+ * and `clip(text, 0)` is not shorter than it (`oneLine` cuts at `max - 1`, a
86
+ * negative index at zero).
87
+ */
88
+ function shorten(answer, item, field, text, limit) {
89
+ let shortest = null
90
+ let low = 1
91
+ let high = text.length
92
+ while (low <= high) {
93
+ const at = (low + high) >> 1
94
+ item[field] = clip(text, at)
95
+ if (jsonBytes(answer) <= limit) {
96
+ shortest = item[field]
97
+ low = at + 1
98
+ } else {
99
+ high = at - 1
100
+ }
101
+ }
102
+ return shortest ?? "…"
103
+ }
@@ -9,6 +9,37 @@ import {
9
9
  } from "./contracts.js"
10
10
  import { clip, clipText, fitList, mapLimit, spaceOf } from "./shape.js"
11
11
 
12
+ /**
13
+ * The erase the person's About-you page offers: a text operation, not a model
14
+ * call. Every line that holds the phrase (case-insensitive, at least
15
+ * `MIN_ERASE_CHARS` long) is removed from the persona and from each scenario,
16
+ * and nothing else. It does not touch the turns and atoms the text was distilled
17
+ * from, so a later consolidation can write it back: the preview says so. These
18
+ * are the same rules the console's Profile page erases by
19
+ * (`deploy/auth/console/profile-area.mjs`).
20
+ */
21
+ export const MIN_ERASE_CHARS = 4
22
+
23
+ const folded = (text) => String(text ?? "").toLowerCase()
24
+
25
+ /** True when the text holds the phrase, case-insensitively. */
26
+ export function containsPhrase(text, phrase) {
27
+ const needle = folded(phrase).trim()
28
+ return needle.length > 0 && folded(text).includes(needle)
29
+ }
30
+
31
+ /** The lines of `content` that hold the phrase, in order. */
32
+ export function matchingLines(content, phrase) {
33
+ return String(content ?? "").split("\n").filter((line) => containsPhrase(line, phrase))
34
+ }
35
+
36
+ /** `content` without the lines that hold the phrase, and how many went. */
37
+ export function eraseLines(content, phrase) {
38
+ const lines = String(content ?? "").split("\n")
39
+ const kept = lines.filter((line) => !containsPhrase(line, phrase))
40
+ return { content: kept.join("\n"), removed: lines.length - kept.length }
41
+ }
42
+
12
43
  /** Said in `notes` when more is held than the answer shows. */
13
44
  const LEFT_OUT = "Some of what Memory holds about you is not shown here, to keep this short."
14
45
 
@@ -11,6 +11,12 @@ import { idOf, SPACE_KINDS } from "./shape.js"
11
11
  * metadata for the person who made the write, never a second copy of what the
12
12
  * store holds. A call that stored or changed one record answers a receipt; a
13
13
  * call that changed several, or that refused before writing, answers none.
14
+ *
15
+ * 0.11.3 (jelly's #89 ask A4): it carries the write's `state` and its item's
16
+ * `link`, the same two fields the answer's first line carries
17
+ * (`src/views/write-state.js`, docs/write-states.md), so a host draws the
18
+ * receipt card from one place. A receipt is answered only when the call saved
19
+ * or changed one record, so its state is always `stored`.
14
20
  */
15
21
 
16
22
  /** The writes that answer a receipt, in the view's own words. */
@@ -34,6 +40,17 @@ export function writeReceipt(verb, { record, space } = {}) {
34
40
 
35
41
  /** Characters of a receipt's title. */
36
42
  export const RECEIPT_TITLE_CHARS = 200
43
+ /** Characters of a receipt's text: enough for the card, not the whole page. */
44
+ export const RECEIPT_TEXT_CHARS = 2000
45
+
46
+ /** A receipt's place: the item kind the record's own kind names, and its address. */
47
+ function placeOf(record) {
48
+ const id = line(record?.id, 240)
49
+ const kind = line(record?.kind, 20)
50
+ if (kind === "page") return `page:${line(record?.path, 240) || id}`
51
+ if (kind === "commitment") return `commitment:${id}`
52
+ return `memory:${id}`
53
+ }
37
54
 
38
55
  /** One line, at most `max` characters, with no control character left in it. */
39
56
  const line = (value, max) =>
@@ -48,12 +65,16 @@ const line = (value, max) =>
48
65
  * report as saved (no record id, or an action the view does not know).
49
66
  *
50
67
  * @param {{ action?: string, record?: any, space?: { id?: string, name?: string, kind?: string } }} input
51
- * @returns {{ v: 1, action: string, id: string, kind: string, type: string, status: string, space: { id: string, name: string, kind: string }, title: string } | undefined}
68
+ * @returns {{ v: 1, action: string, id: string, kind: string, type: string, status: string, state: string, link: string, space: { id: string, name: string, kind: string }, title: string } | undefined}
52
69
  */
53
70
  export function receiptView({ action, record, space } = {}) {
54
71
  if (!RECEIPT_ACTIONS.includes(action)) return undefined
55
72
  const id = idOf(record?.id)
56
73
  if (!id) return undefined
74
+ const fullText = typeof record?.body === "string" && record.body.trim()
75
+ ? record.body
76
+ : typeof record?.fields?.what === "string" ? record.fields.what : typeof record?.what === "string" ? record.what : ""
77
+ const text = fullText.replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/g, " ").slice(0, RECEIPT_TEXT_CHARS)
57
78
  return {
58
79
  v: 1,
59
80
  action,
@@ -61,12 +82,16 @@ export function receiptView({ action, record, space } = {}) {
61
82
  kind: line(record?.kind, 20),
62
83
  type: line(record?.type, 40),
63
84
  status: line(record?.status, 20),
85
+ // A receipt is a saved record: the same state and place a first line names.
86
+ state: "stored",
87
+ link: placeOf(record),
64
88
  space: {
65
89
  id: idOf(space?.id) || "unknown",
66
90
  name: line(space?.name, 200),
67
91
  kind: SPACE_KINDS.has(space?.kind) ? space.kind : "unknown",
68
92
  },
69
93
  title: line(record?.title, RECEIPT_TITLE_CHARS),
94
+ ...(text ? { text, textMore: fullText.length > RECEIPT_TEXT_CHARS } : {}),
70
95
  }
71
96
  }
72
97