@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
@@ -0,0 +1,151 @@
1
+ /**
2
+ * Memory as a source provider: the tools RPC that serves `package.json#sources`
3
+ * (contract version 1; app#2346 §2.3).
4
+ *
5
+ * The transport is the shared package's `registerToolsRpc`, so a call arrives at
6
+ * `POST /api/rpc/mem.tools/<method>` and is resolved against the calling
7
+ * session's own rules **before** it runs: the source's action (`mem.names_list`)
8
+ * and, through each method's resource resolver, its operation
9
+ * (`mem.read` on `<account>:records.list`). A read that is not granted does not
10
+ * run, and the answer names the rule to add.
11
+ *
12
+ * Nothing here is an agent tool: these methods add no text to a model step. They
13
+ * exist for another project to read, under a grant.
14
+ */
15
+ import { asVerifiedSession } from "../credentials.js"
16
+ import { isCoded } from "../errors.js"
17
+ import { registerToolsRpc } from "../vendor/source-contract/tools-rpc.js"
18
+ import { PROBE_ACTION, RPC_PLUGIN, SOURCE_READS } from "./declaration.js"
19
+ import { PLUGIN, createSourceReads, sourceItemOf, sourceNameOf } from "./reads.js"
20
+
21
+ /** The RPC id a host calls: `<plugin id>.tools`. The declaration names the same id (`sources.rpc`). */
22
+ export const TOOLS_RPC_ID = `${RPC_PLUGIN}.tools`
23
+
24
+ /** What an `events_list` page and a snapshot answer are, as the RPC contract declares them. */
25
+ const OBJECT = Object.freeze({ type: "object" })
26
+
27
+ /** The type of each param a source declares, as its method's input schema shows it. */
28
+ const PARAM_TYPES = Object.freeze({
29
+ session: { type: "string" },
30
+ turn: { type: "string" },
31
+ space: { type: "string" },
32
+ target: { type: "string" },
33
+ meeting: { type: "string" },
34
+ q: { type: "string" },
35
+ max: { type: "integer" },
36
+ limit: { type: "integer" },
37
+ })
38
+
39
+ /** One sentence for each method, in the console and `describe`. */
40
+ const DESCRIPTIONS = Object.freeze({
41
+ "mem.turn-receipts": "what Memory saved because of one turn",
42
+ "mem.names": "the people and names Memory knows",
43
+ "mem.members": "who is in one space",
44
+ "mem.grants": "who a space, wiki, folder or page is shared with",
45
+ "mem.spaces-to-join": "the shared spaces you may ask to join",
46
+ "mem.meeting-records": "what one meeting produced",
47
+ "mem.suggestions": "a turn's record worth sharing with a space",
48
+ "mem.pages-search": "page titles that match a query",
49
+ })
50
+
51
+ /** The next step for each code the transport itself can answer with. */
52
+ const NEXT_STEPS = Object.freeze({
53
+ SESSION_UNKNOWN: "Call it in a session that exists in this location, such as the one the host opened for the read.",
54
+ SESSION_AGENT_REQUIRED: "Call it in a session whose agent exists in this location.",
55
+ PERMISSION_DENIED: "Add an allow rule for the source's action and its operation to the session's agent, or use a session whose agent allows them.",
56
+ CANCELLED: "Call it again while the session is open.",
57
+ })
58
+
59
+ /** The tool a source's read names, as the plugin's declared tools list shows it. */
60
+ export function sourceTools() {
61
+ return [
62
+ ...SOURCE_READS.map((read) => ({ id: read.tool, readOnly: true })),
63
+ { id: "probe", readOnly: true },
64
+ ]
65
+ }
66
+
67
+ /** The input schema of one source's method: its fixed `source`, the account, and its own params. */
68
+ function inputSchema(item, extra = {}) {
69
+ const params = Object.keys(item.params ?? {})
70
+ return {
71
+ type: "object",
72
+ additionalProperties: false,
73
+ properties: {
74
+ source: { type: "string", maxLength: 64 },
75
+ account: { type: "string", maxLength: 320 },
76
+ ...extra,
77
+ ...Object.fromEntries(params.filter((name) => name in PARAM_TYPES).map((name) => [name, PARAM_TYPES[name]])),
78
+ },
79
+ }
80
+ }
81
+
82
+ /** The resource a call acts on (`<account>:<operation>`), or null when its input names none. */
83
+ function resourceOf(input, item) {
84
+ const account = typeof input?.account === "string" ? input.account.trim() : ""
85
+ const operation = item.permission?.operations?.find((name) => name !== "probe") ?? ""
86
+ return account && operation ? `${account}:${operation}` : null
87
+ }
88
+
89
+ /**
90
+ * A coded failure as the transport's `failed` answer: `{ code, what, next }`.
91
+ * Memory's errors are already in the family's form (`CODE: … Next step: …`).
92
+ */
93
+ export function pluginErrorOf(error) {
94
+ const message = String(error?.message ?? "")
95
+ if (!isCoded(message)) return undefined
96
+ const match = /^([A-Z][A-Z0-9_]*): (.*?) Next step: (.+)$/su.exec(message)
97
+ if (!match) return undefined
98
+ return { code: match[1], what: match[2], next: match[3] }
99
+ }
100
+
101
+ /**
102
+ * Register Memory's tools RPC.
103
+ *
104
+ * @param {any} ctx the plugin context
105
+ * @param {any} runtime the plugin runtime
106
+ * @returns {Promise<{ dispose: () => Promise<void> } | null>}
107
+ */
108
+ export async function registerSourceRpc(ctx, runtime) {
109
+ if (typeof ctx?.rpc?.register !== "function") return null
110
+ const reads = createSourceReads({ runtime })
111
+ const methods = [
112
+ ...SOURCE_READS.map((read) => {
113
+ const item = sourceItemOf(read.source)
114
+ const run = reads[read.tool]
115
+ return {
116
+ kind: "plugin",
117
+ class: "read",
118
+ name: read.tool,
119
+ action: read.action,
120
+ description: DESCRIPTIONS[item.id] ?? item.id,
121
+ input: inputSchema(item, item.kind === "events" ? { cursor: { type: "string" }, since: { type: "string" }, limit: { type: "integer" }, scope: OBJECT } : {}),
122
+ output: OBJECT,
123
+ // A read asserts its operation where the host resolves the rule, before dispatch.
124
+ resource: (input) => resourceOf(input, item),
125
+ run: async (input, call) => {
126
+ if (input?.source !== undefined && input.source !== sourceNameOf(item) && input.source !== item.id) {
127
+ throw new Error(`UNAVAILABLE: ${read.tool} reads ${item.id}, not ${String(input.source)}. Next step: call the method its descriptor names.`)
128
+ }
129
+ // Verified: the session's own Jelly token, minted for the person speaking
130
+ // in it. A pasted key cannot stand in for the caller.
131
+ return asVerifiedSession(call.sessionID, () => run(input ?? {}, call))
132
+ },
133
+ }
134
+ }),
135
+ {
136
+ kind: "plugin",
137
+ class: "read",
138
+ name: "probe",
139
+ action: PROBE_ACTION,
140
+ description: "the account Memory is signed in as, and the owner; it reads no content",
141
+ input: { type: "object", additionalProperties: false, properties: { source: { type: "string", maxLength: 64 }, account: { type: "string", maxLength: 320 } } },
142
+ output: OBJECT,
143
+ run: async (input, call) => asVerifiedSession(call.sessionID, () => reads.probe(input ?? {}, call)),
144
+ },
145
+ ]
146
+ const dispose = await registerToolsRpc(ctx, {
147
+ plugin: { id: RPC_PLUGIN, nextSteps: NEXT_STEPS, pluginError: pluginErrorOf },
148
+ methods,
149
+ })
150
+ return { dispose: async () => dispose() }
151
+ }