@joe-broadhead/opencode-mem 0.9.5 → 0.9.14

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 (63) hide show
  1. package/CHANGELOG.md +1408 -0
  2. package/README.md +120 -41
  3. package/docs/agent-instructions.md +17 -0
  4. package/docs/agent-protocol.md +28 -27
  5. package/docs/permissions.md +150 -0
  6. package/package.json +386 -17
  7. package/skills/mem.pages/SKILL.md +40 -16
  8. package/skills/mem.sharing/SKILL.md +39 -6
  9. package/skills/mem.sources/SKILL.md +41 -10
  10. package/skills/mem.usage/SKILL.md +37 -16
  11. package/src/backend/records.js +8 -0
  12. package/src/backend/v3.js +15 -10
  13. package/src/call-shapes.js +18 -25
  14. package/src/capture-pause.js +136 -0
  15. package/src/capture.js +7 -5
  16. package/src/collector-service.js +212 -35
  17. package/src/collector.js +187 -47
  18. package/src/commands.js +37 -0
  19. package/src/compaction.js +4 -2
  20. package/src/config.js +151 -1
  21. package/src/curation.js +6 -10
  22. package/src/events.js +144 -36
  23. package/src/forget-purge.js +377 -0
  24. package/src/forgotten.js +152 -0
  25. package/src/hooks.js +9 -4
  26. package/src/index.js +5 -3
  27. package/src/permissions.js +116 -38
  28. package/src/protocol.js +32 -11
  29. package/src/recall.js +13 -1
  30. package/src/records.js +4 -1
  31. package/src/runtime.js +202 -15
  32. package/src/shapes.js +63 -0
  33. package/src/sources.js +205 -12
  34. package/src/spaces.js +58 -1
  35. package/src/spool.js +442 -64
  36. package/src/stated.js +334 -0
  37. package/src/storable.js +477 -0
  38. package/src/tools/aliases.js +36 -147
  39. package/src/tools/commitments.js +79 -13
  40. package/src/tools/held-write.js +5 -1
  41. package/src/tools/index.js +25 -43
  42. package/src/tools/ingest.js +33 -128
  43. package/src/tools/memory.js +525 -911
  44. package/src/tools/page-sections.js +147 -0
  45. package/src/tools/page.js +314 -82
  46. package/src/tools/recall-browse.js +173 -0
  47. package/src/tools/recall.js +36 -8
  48. package/src/tools/records-kit.js +2 -1
  49. package/src/tools/share.js +494 -131
  50. package/src/tools/shared.js +97 -19
  51. package/src/tools/spaces.js +194 -101
  52. package/src/tools/status.js +31 -3
  53. package/src/tools/wiki.js +5 -13
  54. package/src/util.js +10 -59
  55. package/src/views/contracts.js +258 -20
  56. package/src/views/overdue.js +1 -1
  57. package/src/views/profile.js +2 -3
  58. package/src/views/receipt.js +81 -0
  59. package/src/views/records-reads.js +545 -25
  60. package/src/views/rpc.js +41 -3
  61. package/views/memory.html +16 -3
  62. package/views/remembered.html +130 -0
  63. package/src/erase.js +0 -36
@@ -1,73 +1,39 @@
1
- import { DEFAULT_ACCOUNT, isAccountName, isSourceName } from "../collector.js"
2
1
  import { describeResult } from "../collector-service.js"
3
- import { errorMessage, isPlainObject, oneLine } from "../util.js"
4
- import { RECORDS_MISSING, recordsFailure, recordsOf } from "./share.js"
5
- import { unboundOwner } from "../backend/records.js"
6
2
 
7
- /** Events in one ingest call (contract §2.4). */
8
- export const MAX_INGEST_EVENTS = 500
3
+ /**
4
+ * 0.9.7 (security review of audit tools #4): `mem_ingest` and `mem_cursor` are
5
+ * retired and always refuse, in every session. Their gate used to check only
6
+ * the session id's format, which is computable (a sha256 of source and
7
+ * account), and the collector's own sessions allowed both. Nothing legitimate
8
+ * calls them: the in-plugin collector reads the cursor and ingests through the
9
+ * records client directly (src/collector-service.js), and Jelly's routine calls
10
+ * `mem_collect`. They stay registered only because Jelly declares both tools
11
+ * (`package.json` `jelly.tools`); a call gets this answer.
12
+ */
13
+ export const RETIRED = (tool) => `${tool} is retired and internal: it does nothing in any session. Memory collects on its own, and mem_collect collects now when the person asks.`
9
14
 
10
15
  /**
11
- * `mem_ingest` and `mem_cursor`: the collector's two calls
12
- * (docs/design/memory-v1-contracts.md §4.1, §4.4). The `memory-collect`
13
- * schedule's Code Mode check and `/mem-collect` use them; agents never call
14
- * them, and their descriptions say so.
15
- *
16
- * Both work in the caller's personal space, where raw events stay private
17
- * (memory-funnel-v1.md §10). Each answers structured `output` (so the check's
18
- * code reads `c.cursor` and `saved.cursor_saved`) and a one-line `content`.
19
- *
20
- * A refused ingest (409 `source_unbound`: the binding is missing, or the
21
- * signed-in account changed) is not an error to the check: it answers
22
- * `cursor_saved: false` with the owner the records service reported, and the
23
- * collector remembers that owner so `mem_spaces` can show it when the person
24
- * binds the source.
16
+ * `mem_ingest` and `mem_cursor`: retired stubs (above). Each answers its old
17
+ * structured output shape, so a stale host schedule's check reads a refusal
18
+ * (`cursor_saved: false`, `enabled: false`) and stops.
25
19
  *
26
20
  * @param {any} editor
27
- * @param {ReturnType<import("./shared.js").createToolkit>} toolkit
21
+ * @param {ReturnType<import("./shared.js").createToolkit>} _toolkit
28
22
  */
29
- export function registerIngest(editor, toolkit) {
30
- const { text, log } = toolkit
31
-
32
- /** The personal space the events belong to, as a records call's `where`. */
33
- async function personalWhere(context) {
34
- if (!toolkit.control) return { where: { sessionID: context?.sessionID } }
35
- const resolved = await toolkit.resolvePrivateSpace({}, context)
36
- if (resolved.invalid) return { error: resolved.invalid }
37
- if (resolved.error) return { error: resolved.error }
38
- return { where: { space: resolved.context.space_id } }
39
- }
40
-
41
- function bindingOf(input) {
42
- const source = String(input?.source ?? "").trim()
43
- const account = String(input?.account ?? "").trim() || DEFAULT_ACCOUNT
44
- if (!isSourceName(source)) return { error: `source "${oneLine(source || "(none)", 60)}" is not a source name` }
45
- if (!isAccountName(account)) return { error: `account "${oneLine(account, 60)}" is not an account name` }
46
- return { source, account }
47
- }
48
-
49
- const refuse = (reason, extra = {}) => ({ output: { accepted: 0, duplicates: 0, refused: 0, cursor_saved: false, error: reason, ...extra }, content: reason })
50
-
23
+ export function registerIngest(editor, _toolkit) {
51
24
  editor.add({
52
25
  name: "ingest",
53
- description:
54
- "For the memory collector only (the memory-collect schedule and /mem-collect); agents never call it. Sends one page of a source's events to the person's private event log, with the source's new cursor. The records service keeps events only from the account the person bound, for 30 days, never as memories.",
26
+ description: "Retired and internal; agents never call it, and it always refuses. Memory collects on its own, and mem_collect collects now when the person asks.",
55
27
  input: {
56
28
  type: "object",
57
29
  properties: {
58
- source: { type: "string", description: "The source's Code Mode namespace, such as gmail" },
59
- account: { type: "string", description: 'The account within the source; default "default"' },
60
- owner: {
61
- type: "object",
62
- description: "The signed-in account events_list reported",
63
- properties: { id: { type: "string" }, label: { type: "string" } },
64
- required: ["id"],
65
- },
66
- events: { type: "array", items: { type: "object" }, description: `events_list's events, oldest first, at most ${MAX_INGEST_EVENTS}` },
67
- cursor: { type: "string", description: "events_list's cursor after these events" },
30
+ source: { type: "string", description: "Ignored" },
31
+ account: { type: "string", description: "Ignored" },
32
+ owner: { type: "object", description: "Ignored", properties: { id: { type: "string" }, label: { type: "string" } } },
33
+ events: { type: "array", items: { type: "object" }, description: "Ignored" },
34
+ cursor: { type: "string", description: "Ignored" },
68
35
  },
69
- required: ["source", "owner", "events", "cursor"],
70
- additionalProperties: false,
36
+ additionalProperties: true,
71
37
  },
72
38
  output: {
73
39
  type: "object",
@@ -77,67 +43,26 @@ export function registerIngest(editor, toolkit) {
77
43
  refused: { type: "integer" },
78
44
  cursor_saved: { type: "boolean" },
79
45
  error: { type: "string" },
80
- owner: { type: "object" },
81
46
  },
82
47
  required: ["accepted", "duplicates", "refused", "cursor_saved"],
83
48
  },
84
49
  options: { namespace: "mem" },
85
- execute: async (input, context) => {
86
- const records = recordsOf(toolkit)
87
- if (!records) return refuse(RECORDS_MISSING)
88
- const binding = bindingOf(input)
89
- if (binding.error) return refuse(`not ingested: ${binding.error}`)
90
- if (!isPlainObject(input?.owner) || !String(input.owner.id ?? "").trim()) return refuse("not ingested: owner.id is required (events_list's owner)")
91
- if (!Array.isArray(input?.events)) return refuse("not ingested: events must be an array")
92
- if (input.events.length > MAX_INGEST_EVENTS) return refuse(`not ingested: at most ${MAX_INGEST_EVENTS} events per call`)
93
- if (typeof input?.cursor !== "string" || !input.cursor) return refuse("not ingested: cursor is required (events_list's cursor)")
94
- const target = await personalWhere(context)
95
- if (target.error) return refuse(`not ingested: ${target.error}`)
96
- const owner = { id: oneLine(input.owner.id, 300), label: oneLine(input.owner.label ?? input.owner.id, 300) }
97
- try {
98
- const answer = await records.call(
99
- "events.ingest",
100
- { source: binding.source, account: binding.account, owner, events: input.events, cursor: input.cursor },
101
- target.where,
102
- )
103
- const output = {
104
- accepted: Number(answer?.accepted) || 0,
105
- duplicates: Number(answer?.duplicates) || 0,
106
- refused: Number(answer?.refused) || 0,
107
- cursor_saved: answer?.cursor_saved === true,
108
- }
109
- return {
110
- output,
111
- content: `${binding.source}:${binding.account}: ${output.accepted} accepted, ${output.duplicates} duplicate(s), ${output.refused} refused; cursor ${output.cursor_saved ? "saved" : "not saved"}.`,
112
- }
113
- } catch (error) {
114
- const code = String(error?.code ?? error?.error?.code ?? "")
115
- if (code === "source_unbound") {
116
- const reported = unboundOwner(error) ?? owner
117
- toolkit.collector?.noteOwner(binding.source, binding.account, reported)
118
- return refuse(
119
- `not ingested: ${binding.source}:${binding.account} is not bound to the account signed in (${oneLine(reported?.label ?? reported?.id ?? "unknown", 120)}). The person confirms it with mem_spaces ("action": "sources", "bind").`,
120
- { owner: { id: oneLine(reported?.id ?? "", 300), label: oneLine(reported?.label ?? reported?.id ?? "", 300) } },
121
- )
122
- }
123
- log.warn("ingest failed", { source: binding.source, error: errorMessage(error) })
124
- return refuse(`${error?.outcomeUnknown ? "ingest outcome unknown" : "not ingested"}: ${recordsFailure(error)}`)
125
- }
50
+ execute: async () => {
51
+ const reason = RETIRED("mem_ingest")
52
+ return { output: { accepted: 0, duplicates: 0, refused: 0, cursor_saved: false, error: reason }, content: reason }
126
53
  },
127
54
  })
128
55
 
129
56
  editor.add({
130
57
  name: "cursor",
131
- description:
132
- "For the memory collector only (the memory-collect schedule and /mem-collect); agents never call it. Reads where collection from one source stopped, and whether the person enabled and confirmed that source.",
58
+ description: "Retired and internal; agents never call it, and it always refuses. Memory collects on its own, and mem_collect collects now when the person asks.",
133
59
  input: {
134
60
  type: "object",
135
61
  properties: {
136
- source: { type: "string", description: "The source's Code Mode namespace, such as gmail" },
137
- account: { type: "string", description: 'The account within the source; default "default"' },
62
+ source: { type: "string", description: "Ignored" },
63
+ account: { type: "string", description: "Ignored" },
138
64
  },
139
- required: ["source"],
140
- additionalProperties: false,
65
+ additionalProperties: true,
141
66
  },
142
67
  output: {
143
68
  type: "object",
@@ -151,29 +76,9 @@ export function registerIngest(editor, toolkit) {
151
76
  required: ["enabled", "status"],
152
77
  },
153
78
  options: { namespace: "mem" },
154
- execute: async (input, context) => {
155
- const closed = (reason) => ({ output: { cursor: "", enabled: false, status: "unavailable", error: reason }, content: reason })
156
- const records = recordsOf(toolkit)
157
- if (!records) return closed(RECORDS_MISSING)
158
- const binding = bindingOf(input)
159
- if (binding.error) return closed(`no cursor: ${binding.error}`)
160
- const target = await personalWhere(context)
161
- if (target.error) return closed(`no cursor: ${target.error}`)
162
- try {
163
- const answer = await records.call("events.cursor", { source: binding.source, account: binding.account }, target.where)
164
- const output = {
165
- cursor: typeof answer?.cursor === "string" ? answer.cursor : "",
166
- cursor_at: typeof answer?.cursor_at === "string" ? answer.cursor_at : "",
167
- enabled: answer?.enabled === true || answer?.enabled === 1,
168
- status: typeof answer?.status === "string" ? answer.status : "unknown",
169
- }
170
- return {
171
- output,
172
- content: `${binding.source}:${binding.account}: ${output.status}, ${output.enabled ? "enabled" : "disabled"}, cursor ${output.cursor ? `at ${oneLine(output.cursor_at || "an earlier run", 40)}` : "not set"}.`,
173
- }
174
- } catch (error) {
175
- return closed(`no cursor: ${recordsFailure(error)}`)
176
- }
79
+ execute: async () => {
80
+ const reason = `no cursor: ${RETIRED("mem_cursor")}`
81
+ return { output: { cursor: "", enabled: false, status: "unavailable", error: reason }, content: reason }
177
82
  },
178
83
  })
179
84
  }