@joe-broadhead/opencode-mem 0.9.5 → 0.9.12

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 (53) hide show
  1. package/CHANGELOG.md +1281 -0
  2. package/README.md +105 -31
  3. package/docs/agent-protocol.md +28 -27
  4. package/docs/permissions.md +148 -0
  5. package/package.json +24 -12
  6. package/skills/mem.pages/SKILL.md +35 -16
  7. package/skills/mem.sharing/SKILL.md +39 -6
  8. package/skills/mem.sources/SKILL.md +41 -10
  9. package/skills/mem.usage/SKILL.md +37 -16
  10. package/src/backend/records.js +8 -0
  11. package/src/backend/v3.js +15 -10
  12. package/src/call-shapes.js +18 -25
  13. package/src/capture-pause.js +136 -0
  14. package/src/capture.js +7 -5
  15. package/src/collector-service.js +212 -35
  16. package/src/collector.js +186 -47
  17. package/src/commands.js +37 -0
  18. package/src/compaction.js +4 -2
  19. package/src/config.js +151 -1
  20. package/src/curation.js +6 -10
  21. package/src/events.js +144 -36
  22. package/src/forget-purge.js +377 -0
  23. package/src/forgotten.js +152 -0
  24. package/src/hooks.js +9 -4
  25. package/src/index.js +5 -3
  26. package/src/permissions.js +116 -38
  27. package/src/protocol.js +21 -11
  28. package/src/records.js +4 -1
  29. package/src/runtime.js +202 -15
  30. package/src/shapes.js +63 -0
  31. package/src/sources.js +183 -12
  32. package/src/spaces.js +58 -1
  33. package/src/spool.js +442 -64
  34. package/src/stated.js +334 -0
  35. package/src/storable.js +477 -0
  36. package/src/tools/aliases.js +36 -147
  37. package/src/tools/commitments.js +69 -12
  38. package/src/tools/index.js +25 -43
  39. package/src/tools/ingest.js +33 -128
  40. package/src/tools/memory.js +503 -904
  41. package/src/tools/page-sections.js +147 -0
  42. package/src/tools/page.js +314 -82
  43. package/src/tools/recall-browse.js +173 -0
  44. package/src/tools/recall.js +36 -8
  45. package/src/tools/share.js +494 -131
  46. package/src/tools/shared.js +97 -19
  47. package/src/tools/spaces.js +194 -101
  48. package/src/tools/status.js +31 -3
  49. package/src/tools/wiki.js +5 -13
  50. package/src/util.js +10 -59
  51. package/src/views/profile.js +2 -3
  52. package/src/views/records-reads.js +6 -1
  53. package/src/erase.js +0 -36
@@ -1,164 +1,53 @@
1
- import { recordsOf } from "./share.js"
2
-
3
1
  /**
4
- * The old tool names, kept for one release (0.9.x; removed in 0.10), each
5
- * described as "Deprecated: use X" (docs/design/memory-v1-contracts.md §4.1):
6
- *
7
- * - `forget` → `mem_revise` with "action": "forget". Ids from before 0.9
8
- * (`m_…`, `msg-…`) and `match` keep today's behaviour exactly, through the
9
- * legacy registration when the core tools still provide one;
10
- * - `promote` → `mem_share` copy (and revoke). A 0.8 share (a `res_…` wiki
11
- * share) is still revoked as before; with no records client, a copy falls
12
- * back to the 0.8 wiki share, and says so;
13
- * - `status` → `mem_spaces` health; `grants` → `mem_spaces` access;
14
- * `members` → `mem_spaces` members.
2
+ * The 0.8 tool names, kept registered until 0.10 (docs/design/memory-v1-contracts.md
3
+ * §4.1) as one-line "renamed" shims. Since 0.9.8 a shim runs nothing: it
4
+ * answers where the tool went, so a 0.9.x prompt or script that still calls
5
+ * the old name gets a pointer instead of "unknown tool", and the replacement
6
+ * asks and checks as it always does.
15
7
  *
16
- * A core registration that still adds one of these names is captured, not
17
- * added (src/tools/index.js), so each name is registered once, here.
8
+ * Why shims rather than working aliases: a working alias kept about 600 lines
9
+ * of pre-0.9 forget and promote alive, needed its own approval gate and
10
+ * `jelly.asks` entry, and cost a full schema on every step in direct-tool
11
+ * mode. A shim's schema is empty and its description is one sentence, and it
12
+ * can change nothing, so it needs no gate and no ask.
18
13
  */
19
14
  export const LEGACY_TOOLS = Object.freeze(["forget", "promote", "status", "grants", "members"])
20
15
 
21
- /** What each alias became, for descriptions and the teaching. */
16
+ /** What each old name became. */
22
17
  export const REPLACED_BY = Object.freeze({
23
18
  forget: 'mem_revise with "action": "forget"',
24
- promote: 'mem_share with "action": "copy" (and "revoke")',
19
+ promote: 'mem_share with "action": "copy"',
25
20
  status: 'mem_spaces with "action": "health"',
26
21
  grants: 'mem_spaces with "action": "access"',
27
22
  members: 'mem_spaces with "action": "members"',
28
23
  })
29
24
 
30
- /** A records-service id (contract §2.3): `rec_` and a 26-character Crockford ULID. */
31
- const RECORD_ID = /^rec_[0-9A-HJKMNP-TV-Z]{26}$/
32
- const SPACES = Object.freeze({ health: "health", access: "access", members: "members" })
33
- const FORGET = "forget"
34
-
35
- /** An alias's whole description (contract §4.1): "Deprecated: use X" and nothing more. */
36
- export const deprecated = (name) => `Deprecated: use ${REPLACED_BY[name]}.`
25
+ /** A shim's whole description. */
26
+ export const renamed = (name) => `Renamed: use ${REPLACED_BY[name]}.`
37
27
 
38
28
  /**
39
- * @param {any} editor the gated editor
40
- * @param {ReturnType<import("./shared.js").createToolkit>} toolkit
41
- * @param {{
42
- * registered: Map<string, any>,
43
- * legacy: Map<string, any>,
44
- * share: ReturnType<import("./share.js").createShareActions>,
45
- * spaces: ReturnType<import("./spaces.js").createSpacesActions>,
46
- * }} parts
29
+ * What a shim answers beyond the replacement. A 0.8 share (a `res_…` id) was
30
+ * a wiki, not a copy record, so mem_share revoke cannot delete it.
47
31
  */
48
- export function registerAliases(editor, toolkit, { registered, legacy, share, spaces }) {
49
- const { text } = toolkit
50
- const listInput = (what) => ({
51
- type: "object",
52
- properties: {
53
- action: { type: "string", enum: ["list"], description: 'Required; the only value is "list". Example: {"action": "list"}' },
54
- space: { type: "string", description: `Space id to ${what} (control plane); defaults to the active space` },
55
- },
56
- required: ["action"],
57
- additionalProperties: false,
58
- })
59
-
60
- // forget → revise forget
61
- const oldForget = legacy.get("forget")
62
- editor.add({
63
- name: "forget",
64
- description: deprecated("forget"),
65
- input: oldForget?.input ?? {
66
- type: "object",
67
- properties: { ids: { type: "array", items: { type: "string" }, description: "Memory ids to forget (rec_…, m_…, msg-…)" } },
68
- required: ["ids"],
69
- additionalProperties: false,
70
- },
71
- options: { namespace: "mem" },
72
- execute: async (input, context) => {
73
- const revise = registered.get("revise")
74
- const ids = Array.isArray(input?.ids) ? [...new Set(input.ids.map((id) => String(id).trim()).filter(Boolean))] : []
75
- const records = ids.filter((id) => RECORD_ID.test(id))
76
- const older = ids.filter((id) => !RECORD_ID.test(id))
77
- const parts = []
78
- if (String(input?.match ?? "").trim() || older.length > 0 || ids.length === 0) {
79
- if (oldForget) {
80
- parts.push((await oldForget.execute(records.length > 0 ? { ...input, ids: older } : input, context))?.content ?? "")
81
- } else if (revise && older.length > 0) {
82
- for (const id of older) parts.push((await revise.execute({ action: FORGET, id }, context))?.content ?? "")
83
- } else {
84
- parts.push(`not forgotten: ${String(input?.match ?? "").trim() ? "match (persona and scenario lines)" : older.join(", ") || "nothing"} needs the old forget, which this build no longer has. Use mem_revise with "action": "forget" and an id.`)
85
- }
86
- }
87
- if (records.length > 0) {
88
- if (!revise) parts.push(`not forgotten: ${records.join(", ")} ${records.length === 1 ? "is a record" : "are records"}; this build has no mem_revise.`)
89
- else for (const id of records) parts.push((await revise.execute({ action: FORGET, id }, context))?.content ?? "")
90
- }
91
- return text(parts.filter(Boolean).join("\n"))
92
- },
93
- })
94
-
95
- // promote → share copy, revoke
96
- const oldPromote = legacy.get("promote")
97
- editor.add({
98
- name: "promote",
99
- description: deprecated("promote"),
100
- input: {
101
- type: "object",
102
- properties: {
103
- ids: { type: "array", items: { type: "string" }, description: 'To copy: private memory ids, with rationale. Example: {"ids": ["rec_..."], "rationale": "The team needs the logging rule", "space": "space-team"}' },
104
- name: { type: "string", description: "Ignored since 0.9 (each copy is its own record); kept so old calls still validate" },
105
- rationale: { type: "string", description: "Why the shared space should see this; required to copy, recorded on each copy" },
106
- space: { type: "string", description: "Shared space id (control plane); defaults to the session's bound shared space; applies to this call only" },
107
- revoke: { type: "string", description: 'To revoke instead: a copy\'s rec_ id, or the res_ id a 0.8 share returned. Example: {"revoke": "rec_...", "space": "space-team"}' },
108
- },
109
- additionalProperties: false,
110
- },
111
- options: { namespace: "mem" },
112
- execute: async (input, context) => {
113
- const revoke = String(input?.revoke ?? "").trim()
114
- if (revoke) {
115
- if (Array.isArray(input?.ids) && input.ids.length > 0) return text("pass ids to copy, or revoke to delete a copy, not both.")
116
- if (RECORD_ID.test(revoke)) return share.revokeCopies({ ids: [revoke], space: input?.space }, context, { legacy: true })
117
- // A 0.8 share: the legacy registration revokes it exactly as before
118
- // (local mode included); without one, the port in share.js does.
119
- if (oldPromote) return oldPromote.execute(input, context)
120
- return share.revokeLegacyShare(input, context)
121
- }
122
- if (!recordsOf(toolkit) && oldPromote) {
123
- if (toolkit.config?.heldTeamWrites) return text("not held: the records service is required for approval. Nothing was shared.")
124
- const answer = (await oldPromote.execute(input, context))?.content ?? ""
125
- return text(`${answer}${answer ? "\n" : ""}(No records service is reachable from this build, so this was a 0.8 wiki share.)`)
126
- }
127
- return share.copy({ ids: input?.ids, rationale: input?.rationale, space: input?.space }, context)
128
- },
129
- })
130
-
131
- editor.add({
132
- name: "status",
133
- description: deprecated("status"),
134
- input: {
135
- type: "object",
136
- properties: { space: { type: "string", description: "Optional; no argument is needed. Space id to report on (control plane); defaults to the active space" } },
137
- additionalProperties: false,
138
- },
139
- options: { namespace: "mem" },
140
- execute: (input, context) => spaces.run({ action: SPACES.health, ...(input?.space ? { space: input.space } : {}) }, context),
141
- })
142
-
143
- editor.add({
144
- name: "grants",
145
- description: deprecated("grants"),
146
- input: listInput("inspect"),
147
- options: { namespace: "mem" },
148
- execute: async (input, context) => {
149
- if (input?.action !== "list") return text('unsupported action: use "action": "list"')
150
- return spaces.run({ action: SPACES.access, ...(input?.space ? { space: input.space } : {}) }, context)
151
- },
152
- })
32
+ const AFTERWORD = Object.freeze({
33
+ promote: " A 0.8 share (a res_ id) is a wiki: delete it with mem_wiki delete and its wiki_id, or in Memory's console.",
34
+ })
153
35
 
154
- editor.add({
155
- name: "members",
156
- description: deprecated("members"),
157
- input: listInput("inspect"),
158
- options: { namespace: "mem" },
159
- execute: async (input, context) => {
160
- if (input?.action !== "list") return text('unsupported action: use "action": "list"')
161
- return spaces.run({ action: SPACES.members, ...(input?.space ? { space: input.space } : {}) }, context)
162
- },
163
- })
36
+ /** What a shim answers; it changes nothing. */
37
+ export const renamedAnswer = (name) => `mem_${name} was renamed in 0.9 and no longer runs: call ${REPLACED_BY[name]}.${AFTERWORD[name] ?? ""} Nothing was done.`
38
+
39
+ /** Accepts any old call shape, so the answer, not a validation error, is what the caller sees. */
40
+ const ANY_INPUT = Object.freeze({ type: "object", properties: {}, additionalProperties: true })
41
+
42
+ /** Register the five shims on `editor`. */
43
+ export function registerAliases(editor, { text }) {
44
+ for (const name of LEGACY_TOOLS) {
45
+ editor.add({
46
+ name,
47
+ description: renamed(name),
48
+ input: ANY_INPUT,
49
+ options: { namespace: "mem" },
50
+ execute: async () => text(renamedAnswer(name)),
51
+ })
52
+ }
164
53
  }
@@ -1,3 +1,4 @@
1
+ import { storable } from "../storable.js"
1
2
  import {
2
3
  CLOSED_RETENTION_DAYS,
3
4
  STATES,
@@ -11,8 +12,51 @@ import {
11
12
  validateDue,
12
13
  validateFields,
13
14
  } from "../records.js"
15
+ import { dueStated, holdsWord, tiedWords, triggerStated } from "../stated.js"
14
16
  import { errorMessage, oneLine } from "../util.js"
15
17
 
18
+ /**
19
+ * Drop a due date or a trigger the person did not state (0.9.9, WRITES-099):
20
+ * the 0.9.8 gate found agents storing a day they worked out from "next week"
21
+ * or from a recalled note. `messages` are the person's recent messages in the
22
+ * session (src/stated.js); with none seen (a host that reports no prompt
23
+ * text) nothing is checked. Clearing a due ("") is always allowed.
24
+ *
25
+ * A date the matcher cannot read from the person's words but that is tied to
26
+ * them (its day number, month or weekday, as in "Black Friday") is dropped
27
+ * once and remembered in `drops`; when the person's next message repeats the
28
+ * tied words (they were asked, and said it again), it is kept, so the ask
29
+ * cannot loop. A date tied to nothing they said is always dropped.
30
+ *
31
+ * @param {Record<string, unknown>} fields the validated fields; changed in place
32
+ * @param {Array<{ text: string, at: number, seq?: number }>} messages
33
+ * @param {string} zone
34
+ * @param {Map<string, { words: string[], seq: number }>} [drops] this session's dropped dates; changed in place
35
+ * @returns {string[]} one sentence per dropped field
36
+ */
37
+ export function keepStated(fields, messages, zone, drops = new Map()) {
38
+ if (!Array.isArray(messages) || messages.length === 0) return []
39
+ const notes = []
40
+ if (typeof fields.due === "string" && fields.due !== "" && !dueStated(fields.due, messages, zone)) {
41
+ const latest = messages.at(-1)
42
+ const before = drops.get(fields.due)
43
+ const repeated = before && Number(latest?.seq) > before.seq && before.words.some((word) => holdsWord(latest.text, word))
44
+ if (repeated) {
45
+ drops.delete(fields.due)
46
+ } else {
47
+ const words = tiedWords(fields.due, messages)
48
+ if (words.length > 0) drops.set(fields.due, { words, seq: Number(latest?.seq) || 0 })
49
+ notes.push(`due ${oneLine(fields.due, 40)} was not kept: the person's messages name no such day. Never work a date out; ask them, then update it.`)
50
+ delete fields.due
51
+ }
52
+ }
53
+ if (typeof fields.trigger === "string" && fields.trigger !== "" && !triggerStated(fields.trigger, messages)) {
54
+ notes.push(`trigger "${oneLine(fields.trigger, 120)}" was not kept: the person's messages do not name it. Ask them, then update it.`)
55
+ delete fields.trigger
56
+ }
57
+ return notes
58
+ }
59
+
16
60
  /** The list answer shows at most this many items; the rest are counted. */
17
61
  const LIST_MAX = 50
18
62
  export const COMMITMENT_ACTIONS = Object.freeze(["list", "add", "update", "delete"])
@@ -69,7 +113,7 @@ export function registerCommitments(editor, toolkit) {
69
113
  editor.add({
70
114
  name: "commitments",
71
115
  description:
72
- "Track things someone will do, with a due date or a trigger. Call it for the person's promises and reminders (\"remind me to send the Q4 numbers on Friday\"), what the agent promised, and what others owe the person (\"Kwame will send the results by Wednesday\"): action \"add\" when it is promised, \"update\" with state \"done\" or \"cancelled\" the moment it is met or dropped, \"list\" for \"what's on my plate\" or \"what am I waiting on\". The ones due soon are already in context (the Due list): list only for more. Resolve relative dates against today first and echo the weekday and date back. Every answer carries the commitment's id (rec_…), which update and delete take. Commitments are private, and writing them never asks. Never store an instruction here (it is refused); team work items belong in the team's tracker when one is connected; preferences, decisions, and facts belong in mem_remember; where a project stands belongs in its page's Status section (mem_page).",
116
+ "Track things someone will do, with a due date or a trigger. Call it for the person's promises and reminders, what the agent promised, and what others owe the person (\"Kwame will send the results by Wednesday\"); cancel with state \"cancelled\"; list for \"what's on my plate\". The Due list is already in context: list only for more. Resolve relative dates against today and echo the weekday and date back. Every answer carries the commitment's id (rec_…). Commitments are private, and writing them never asks. Never store an instruction here; preferences, decisions and facts belong in mem_remember.",
73
117
  input: {
74
118
  type: "object",
75
119
  properties: {
@@ -77,31 +121,31 @@ export function registerCommitments(editor, toolkit) {
77
121
  type: "string",
78
122
  enum: [...COMMITMENT_ACTIONS],
79
123
  description:
80
- 'Required. Read-only: list. Writes: add (needs what), update and delete (need id). Example: {"action": "add", "what": "Send the Q4 numbers to Ama", "owner": "user", "due": "2026-11-06"}',
124
+ "Required. add needs what; update and delete need id. Example: {\"action\": \"add\", \"what\": \"Send the Q4 numbers to Ama\", \"owner\": \"user\", \"due\": \"2026-11-06\"}",
81
125
  },
82
- id: { type: "string", description: "The commitment id (rec_…, or a cmt_… id from before 0.9) for update and delete, from list or add" },
126
+ id: { type: "string", description: "From list or add (rec_…, or an older cmt_…); update and delete need it" },
83
127
  what: {
84
128
  type: "string",
85
- description: "What will be done, in plain words starting with a verb (\"Send the Q4 numbers to Ama\"), at most 300 characters. Required for add",
129
+ description: "Required for add: what will be done, starting with a verb, at most 300 characters",
86
130
  },
87
131
  owner: {
88
132
  type: "string",
89
- description: 'Who will do it: "user" (the person, the default), "agent" (you promised), or a person\'s name (the person is waiting on them). For list, show only this owner',
133
+ description: "\"user\" (default), \"agent\" (you promised), or a person's name (the person waits on them); list: only this owner",
90
134
  },
91
135
  due: {
92
136
  type: "string",
93
137
  description:
94
- 'When: a date, YYYY-MM-DD (by the end of that day), or a date-time with an offset, 2026-11-06T15:00:00+00:00. Resolve "Friday" against today first. "" clears it on update',
138
+ "Only a day the person named: YYYY-MM-DD (by the end of that day) or a date-time with offset; another is dropped; \"\" clears it on update",
95
139
  },
96
- trigger: { type: "string", description: 'An event that makes it due instead of a date, for example "after the deploy is green"; at most 200 characters' },
140
+ trigger: { type: "string", description: "An event the person named that makes it due instead of a date (\"after the deploy is green\"); at most 200 characters" },
97
141
  state: {
98
142
  type: "string",
99
143
  enum: [...STATES, "all"],
100
- description: 'update: open, done, or cancelled. list: open (default), done, cancelled, or all',
144
+ description: "update: open, done or cancelled; list: open (default), done, cancelled or all",
101
145
  },
102
- project: { type: "string", description: 'The project page slug it belongs to, for example "checkout-v3". For list, show only this project' },
103
- link: { type: "string", description: "The tracker item, PR, or thread it belongs to (an id or a URL)" },
104
- due_before: { type: "string", description: "list only: items due before this date (YYYY-MM-DD)" },
146
+ project: { type: "string", description: "Project page slug (\"checkout-v3\"); list: only this project" },
147
+ link: { type: "string", description: "Tracker item, PR or thread (an id or a URL)" },
148
+ due_before: { type: "string", description: "list: due before this date (YYYY-MM-DD)" },
105
149
  },
106
150
  required: ["action"],
107
151
  additionalProperties: false,
@@ -157,6 +201,8 @@ export function registerCommitments(editor, toolkit) {
157
201
  if (action !== "update" && input?.state !== undefined) return text("state is set with update; add always starts open")
158
202
 
159
203
  let change
204
+ let warning = ""
205
+ let dropped = ""
160
206
  if (action === "delete") {
161
207
  change = { action, id }
162
208
  } else {
@@ -164,9 +210,18 @@ export function registerCommitments(editor, toolkit) {
164
210
  const validated = validateFields(input, { requireWhat: action === "add" })
165
211
  if (validated.error) return text(`not saved: ${validated.error}`)
166
212
  const fields = validated.fields
213
+ // Secrets and email addresses are refused; a home path or a role address is stored with a warning (D3').
214
+ const personal = storable([fields.what, fields.trigger, fields.owner, fields.link].filter((part) => typeof part === "string").join("\n"), "commitment")
215
+ if (personal.outcome === "refuse") return text(personal.message.replace(/^not stored/, "not saved"))
216
+ if (personal.outcome === "warn") warning = personal.message
217
+ // A due date or trigger is kept only when the person's messages name it
218
+ // (0.9.9, WRITES-099): one the agent worked out is dropped, and said.
219
+ const unstated = keepStated(fields, runtime.personSaid?.(context?.sessionID) ?? [], zone, runtime.personDrops?.(context?.sessionID))
167
220
  if (action === "update" && Object.keys(fields).length === 0) {
221
+ if (unstated.length > 0) return text(`not updated: ${unstated.join(" ")}`)
168
222
  return text("nothing to update: pass state, what, owner, due, trigger, project, or link")
169
223
  }
224
+ if (unstated.length > 0) dropped = unstated.join(" ")
170
225
  change = { action, id: action === "add" ? newCommitmentId() : id, fields }
171
226
  }
172
227
 
@@ -187,11 +242,12 @@ export function registerCommitments(editor, toolkit) {
187
242
  log.info("commitments", { action, rounds: result.rounds, unchanged: Boolean(result.unchanged) })
188
243
 
189
244
  if (action === "add" && result.unchanged) {
190
- return text(`already open, not added again: ${describe(result.item, zone)}`)
245
+ return text([`already open, not added again: ${describe(result.item, zone)}`, dropped].filter(Boolean).join("\n"))
191
246
  }
192
247
  if (action === "delete") return text(`deleted ${oneLine(result.item.id || id, 40)}: ${oneLine(result.item.what, 300)}. It is gone from this space's records.`)
193
248
  const verb = action === "add" ? "added" : "updated"
194
249
  const lines = [`${verb} ${describe(result.item, zone)}`]
250
+ if (dropped) lines.push(dropped)
195
251
  if (action === "add") {
196
252
  const similar = similarOpen(result.records?.items, result.item.what, result.item.id)
197
253
  if (similar.length > 0) {
@@ -205,6 +261,7 @@ export function registerCommitments(editor, toolkit) {
205
261
  if (!result.item.due && !result.item.trigger) lines.push("It has no due date or trigger, so it appears only in lists, not in the Due list.")
206
262
  lines.push(`When it is met or dropped: mem_commitments {"action": "update", "id": "${result.item.id}", "state": "done"} (or "cancelled").`)
207
263
  }
264
+ if (warning) lines.push(warning)
208
265
  if (result.item.state !== "open") lines.push(`Closed items are kept ${CLOSED_RETENTION_DAYS} days, then dropped.`)
209
266
  return text(lines.join("\n"))
210
267
  },
@@ -1,4 +1,4 @@
1
- import { MEM_NAMESPACE_DESCRIPTION, PINNED_TOOLS, WIKI_DOCUMENTS_NOTE } from "../call-shapes.js"
1
+ import { MEM_NAMESPACE_DESCRIPTION, PINNED_TOOLS, WIKI_DOCUMENTS_NOTE, WRITE_ACTIONS } from "../call-shapes.js"
2
2
  import { asSession, asVerifiedSession } from "../credentials.js"
3
3
  import { withWriteCall } from "../backend/records.js"
4
4
  import { createCollectorService } from "../collector-service.js"
@@ -7,26 +7,14 @@ import { registerWiki } from "./wiki.js"
7
7
  import { registerShare } from "./share.js"
8
8
  import { registerSpaces } from "./spaces.js"
9
9
  import { registerCollect, registerCollectCommand, registerIngest } from "./ingest.js"
10
- import { LEGACY_TOOLS, registerAliases } from "./aliases.js"
10
+ import { registerAliases } from "./aliases.js"
11
11
 
12
- // ── Lane PLUG-A: the records-backed core tools ──────────────────────────────
13
- // recall, remember, revise, page and commitments (contract §4.1). Until lane
14
- // PLUG-A lands, today's registrations stand in. The integrator replaces the
15
- // three import lines and CORE_TOOLS below, and nothing else, with imports of
16
- // registerRecall, registerRemember, registerRevise, registerPage and
17
- // registerCommitments (from the modules PLUG-A chose) and
18
- //
19
- // CORE_TOOLS = Object.freeze([registerRecall, registerRemember, registerRevise, registerPage, registerCommitments])
20
- //
21
- // A core registration that still adds
22
- // forget, promote, status, grants or members is captured as the alias's
23
- // legacy path, never registered twice (LEGACY_TOOLS).
12
+ // The records-backed core tools (contract §4.1).
24
13
  import { registerRecall } from "./recall.js"
25
14
  import { registerRemember, registerRevise } from "./memory.js"
26
15
  import { registerPage } from "./page.js"
27
16
  import { registerCommitments } from "./commitments.js"
28
17
  export const CORE_TOOLS = Object.freeze([registerRecall, registerRemember, registerRevise, registerPage, registerCommitments])
29
- // ── end of the lane PLUG-A block ────────────────────────────────────────────
30
18
 
31
19
  /**
32
20
  * Register the `mem_*` tool family and the `/mem-collect` command.
@@ -77,36 +65,32 @@ export async function registerTools(ctx, runtime, { core = CORE_TOOLS } = {}) {
77
65
 
78
66
  /**
79
67
  * Register every tool on `editor`: the core tools, the documents tool, share,
80
- * spaces, the collector's ingest and cursor, then the deprecated aliases. A
81
- * core registration of a legacy name is kept aside for its alias.
82
- *
83
- * @returns {{ registered: Map<string, any>, legacy: Map<string, any> }}
68
+ * spaces, the collector's ingest and cursor, collect, then the renamed shims.
69
+ * The documents tool's description gains the note that points authored
70
+ * knowledge to `page`.
84
71
  */
85
72
  export function buildToolset(editor, toolkit, core = CORE_TOOLS) {
86
- const registered = new Map()
87
- const legacy = new Map()
88
- const capturing = new Proxy(editor, {
73
+ const recording = new Proxy(editor, {
89
74
  get(target, key, receiver) {
90
75
  if (key !== "add") return Reflect.get(target, key, receiver)
91
76
  return (definition) => {
92
- if (LEGACY_TOOLS.includes(definition?.name)) {
93
- legacy.set(definition.name, definition)
94
- return
95
- }
96
- const adjusted = definition?.name === "wiki" ? { ...definition, description: `${WIKI_DOCUMENTS_NOTE} ${definition.description}` } : definition
97
- registered.set(adjusted.name, adjusted)
98
- target.add(adjusted)
77
+ target.add(definition?.name === "wiki" ? { ...definition, description: `${WIKI_DOCUMENTS_NOTE} ${definition.description}` } : definition)
99
78
  }
100
79
  },
101
80
  })
102
- for (const register of core) register(capturing, toolkit)
103
- registerWiki(capturing, toolkit)
104
- const share = registerShare(capturing, toolkit)
105
- const spaces = registerSpaces(capturing, toolkit)
106
- registerIngest(capturing, toolkit)
107
- registerCollect(capturing, toolkit)
108
- registerAliases(editor, toolkit, { registered, legacy, share, spaces })
109
- return { registered, legacy }
81
+ for (const register of core) register(recording, toolkit)
82
+ registerWiki(recording, toolkit)
83
+ registerShare(recording, toolkit)
84
+ registerSpaces(recording, toolkit)
85
+ registerIngest(recording, toolkit)
86
+ registerCollect(recording, toolkit)
87
+ registerAliases(recording, toolkit)
88
+ }
89
+
90
+ /** True when a call can change memory: remember, or a tool's write action (WRITE_ACTIONS). */
91
+ export function isWriteCall(name, input) {
92
+ if (name === "remember") return true
93
+ return Boolean(WRITE_ACTIONS[name]?.includes(String(input?.action ?? "")))
110
94
  }
111
95
 
112
96
  /**
@@ -122,12 +106,10 @@ function gateEditor(editor, runtime) {
122
106
  ...definition,
123
107
  options: { ...definition.options, ...(PINNED_TOOLS.includes(definition.name) ? { pinned: true } : {}) },
124
108
  execute: (input, context) => {
125
- const held = runtime.config.heldTeamWrites && (
126
- (definition.name === "remember" && String(input?.visibility ?? "").toLowerCase() === "team") ||
127
- (definition.name === "page" && input?.action === "write") ||
128
- (definition.name === "share" && input?.action === "copy") ||
129
- (definition.name === "promote" && !input?.revoke)
130
- )
109
+ // With held team writes, every write runs as the verified speaker,
110
+ // whatever its tool: a shared write is then held or asked by the
111
+ // one gate (toolkit.gateWrite), never by a per-tool list here.
112
+ const held = runtime.config.heldTeamWrites && isWriteCall(definition.name, input)
131
113
  const run = async () => {
132
114
  const reason = (runtime.availability ? await runtime.availability() : runtime.unavailable?.()) ?? ""
133
115
  if (reason) return { content: reason }