@joe-broadhead/opencode-mem 0.9.2 → 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.
- package/CHANGELOG.md +1605 -0
- package/README.md +135 -43
- package/docs/agent-protocol.md +29 -28
- package/docs/permissions.md +148 -0
- package/package.json +277 -16
- package/skills/mem.pages/SKILL.md +35 -16
- package/skills/mem.sharing/SKILL.md +39 -6
- package/skills/mem.sources/SKILL.md +41 -10
- package/skills/mem.usage/SKILL.md +47 -16
- package/src/backend/records.js +413 -50
- package/src/backend/v3.js +15 -10
- package/src/call-shapes.js +18 -25
- package/src/capture-pause.js +136 -0
- package/src/capture.js +7 -4
- package/src/collector-service.js +212 -35
- package/src/collector.js +186 -47
- package/src/commands.js +37 -0
- package/src/compaction.js +4 -2
- package/src/config.js +162 -1
- package/src/connect.js +353 -0
- package/src/copies.js +28 -3
- package/src/credentials.js +35 -7
- package/src/curation.js +33 -14
- package/src/events.js +144 -36
- package/src/forget-purge.js +377 -0
- package/src/forgotten.js +356 -0
- package/src/hooks.js +9 -4
- package/src/index.js +25 -6
- package/src/permissions.js +116 -38
- package/src/protocol.js +21 -11
- package/src/records.js +4 -1
- package/src/runtime.js +207 -16
- package/src/shapes.js +63 -0
- package/src/sources.js +183 -12
- package/src/spaces.js +58 -1
- package/src/spool.js +442 -64
- package/src/stated.js +334 -0
- package/src/storable.js +477 -0
- package/src/tools/aliases.js +36 -147
- package/src/tools/commitments.js +69 -12
- package/src/tools/held-write.js +9 -1
- package/src/tools/index.js +29 -44
- package/src/tools/ingest.js +33 -128
- package/src/tools/memory.js +594 -901
- package/src/tools/page-sections.js +147 -0
- package/src/tools/page.js +314 -82
- package/src/tools/recall-browse.js +173 -0
- package/src/tools/recall.js +79 -19
- package/src/tools/share.js +494 -131
- package/src/tools/shared.js +97 -19
- package/src/tools/spaces.js +215 -104
- package/src/tools/status.js +31 -3
- package/src/tools/wiki.js +5 -13
- package/src/util.js +10 -20
- package/src/views/contracts.js +137 -6
- package/src/views/overdue.js +125 -0
- package/src/views/profile.js +154 -0
- package/src/views/records-reads.js +132 -33
- package/src/views/rpc.js +63 -12
- package/src/views/shape.js +49 -0
- package/views/commitments.html +31 -4
- package/views/home.html +22 -3
- package/views/memory.html +126 -24
- package/src/erase.js +0 -36
package/src/tools/aliases.js
CHANGED
|
@@ -1,164 +1,53 @@
|
|
|
1
|
-
import { recordsOf } from "./share.js"
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
|
-
* The
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
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
|
-
*
|
|
17
|
-
*
|
|
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
|
|
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"
|
|
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
|
|
31
|
-
const
|
|
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
|
-
*
|
|
40
|
-
*
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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
|
}
|
package/src/tools/commitments.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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: "
|
|
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: "
|
|
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:
|
|
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
|
-
|
|
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:
|
|
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:
|
|
144
|
+
description: "update: open, done or cancelled; list: open (default), done, cancelled or all",
|
|
101
145
|
},
|
|
102
|
-
project: { type: "string", description:
|
|
103
|
-
link: { type: "string", description: "
|
|
104
|
-
due_before: { type: "string", description: "list
|
|
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
|
},
|
package/src/tools/held-write.js
CHANGED
|
@@ -2,12 +2,20 @@ import { createHash } from "node:crypto"
|
|
|
2
2
|
import { asVerifiedView } from "../credentials.js"
|
|
3
3
|
import { oneLine, redactSecrets } from "../util.js"
|
|
4
4
|
import { callRecords, RECORD_ID } from "./records-kit.js"
|
|
5
|
+
import { writeCallRoot } from "../backend/records.js"
|
|
5
6
|
|
|
6
7
|
const hash = (value) => createHash("sha256").update(value).digest("hex")
|
|
7
8
|
const SPACE = /^[A-Za-z0-9_.-]{1,128}$/
|
|
8
9
|
|
|
9
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* The held proposal's key: from the tool call's root (`withWriteCall`), so a
|
|
12
|
+
* call sent again after a restart holds the same proposal, and two identical
|
|
13
|
+
* calls in one message, or one Code Mode script, hold two.
|
|
14
|
+
*/
|
|
10
15
|
function writeKey(context, space) {
|
|
16
|
+
const root = writeCallRoot()
|
|
17
|
+
if (root) return `hw_${hash(JSON.stringify([space, root]))}`
|
|
18
|
+
// Outside a tool call (a direct caller): the call's own ids, as before.
|
|
11
19
|
if (![context?.sessionID, context?.messageID, context?.id].every((value) => typeof value === "string" && value)) throw new Error("held write needs a stable session, message and tool call id")
|
|
12
20
|
return `hw_${hash(JSON.stringify([space, context.sessionID, context.messageID, context.id]))}`
|
|
13
21
|
}
|
package/src/tools/index.js
CHANGED
|
@@ -1,31 +1,20 @@
|
|
|
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
|
+
import { withWriteCall } from "../backend/records.js"
|
|
3
4
|
import { createCollectorService } from "../collector-service.js"
|
|
4
5
|
import { createToolkit } from "./shared.js"
|
|
5
6
|
import { registerWiki } from "./wiki.js"
|
|
6
7
|
import { registerShare } from "./share.js"
|
|
7
8
|
import { registerSpaces } from "./spaces.js"
|
|
8
9
|
import { registerCollect, registerCollectCommand, registerIngest } from "./ingest.js"
|
|
9
|
-
import {
|
|
10
|
+
import { registerAliases } from "./aliases.js"
|
|
10
11
|
|
|
11
|
-
//
|
|
12
|
-
// recall, remember, revise, page and commitments (contract §4.1). Until lane
|
|
13
|
-
// PLUG-A lands, today's registrations stand in. The integrator replaces the
|
|
14
|
-
// three import lines and CORE_TOOLS below, and nothing else, with imports of
|
|
15
|
-
// registerRecall, registerRemember, registerRevise, registerPage and
|
|
16
|
-
// registerCommitments (from the modules PLUG-A chose) and
|
|
17
|
-
//
|
|
18
|
-
// CORE_TOOLS = Object.freeze([registerRecall, registerRemember, registerRevise, registerPage, registerCommitments])
|
|
19
|
-
//
|
|
20
|
-
// A core registration that still adds
|
|
21
|
-
// forget, promote, status, grants or members is captured as the alias's
|
|
22
|
-
// legacy path, never registered twice (LEGACY_TOOLS).
|
|
12
|
+
// The records-backed core tools (contract §4.1).
|
|
23
13
|
import { registerRecall } from "./recall.js"
|
|
24
14
|
import { registerRemember, registerRevise } from "./memory.js"
|
|
25
15
|
import { registerPage } from "./page.js"
|
|
26
16
|
import { registerCommitments } from "./commitments.js"
|
|
27
17
|
export const CORE_TOOLS = Object.freeze([registerRecall, registerRemember, registerRevise, registerPage, registerCommitments])
|
|
28
|
-
// ── end of the lane PLUG-A block ────────────────────────────────────────────
|
|
29
18
|
|
|
30
19
|
/**
|
|
31
20
|
* Register the `mem_*` tool family and the `/mem-collect` command.
|
|
@@ -76,36 +65,32 @@ export async function registerTools(ctx, runtime, { core = CORE_TOOLS } = {}) {
|
|
|
76
65
|
|
|
77
66
|
/**
|
|
78
67
|
* Register every tool on `editor`: the core tools, the documents tool, share,
|
|
79
|
-
* spaces, the collector's ingest and cursor, then the
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
* @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`.
|
|
83
71
|
*/
|
|
84
72
|
export function buildToolset(editor, toolkit, core = CORE_TOOLS) {
|
|
85
|
-
const
|
|
86
|
-
const legacy = new Map()
|
|
87
|
-
const capturing = new Proxy(editor, {
|
|
73
|
+
const recording = new Proxy(editor, {
|
|
88
74
|
get(target, key, receiver) {
|
|
89
75
|
if (key !== "add") return Reflect.get(target, key, receiver)
|
|
90
76
|
return (definition) => {
|
|
91
|
-
|
|
92
|
-
legacy.set(definition.name, definition)
|
|
93
|
-
return
|
|
94
|
-
}
|
|
95
|
-
const adjusted = definition?.name === "wiki" ? { ...definition, description: `${WIKI_DOCUMENTS_NOTE} ${definition.description}` } : definition
|
|
96
|
-
registered.set(adjusted.name, adjusted)
|
|
97
|
-
target.add(adjusted)
|
|
77
|
+
target.add(definition?.name === "wiki" ? { ...definition, description: `${WIKI_DOCUMENTS_NOTE} ${definition.description}` } : definition)
|
|
98
78
|
}
|
|
99
79
|
},
|
|
100
80
|
})
|
|
101
|
-
for (const register of core) register(
|
|
102
|
-
registerWiki(
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
registerIngest(
|
|
106
|
-
registerCollect(
|
|
107
|
-
registerAliases(
|
|
108
|
-
|
|
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 ?? "")))
|
|
109
94
|
}
|
|
110
95
|
|
|
111
96
|
/**
|
|
@@ -121,16 +106,16 @@ function gateEditor(editor, runtime) {
|
|
|
121
106
|
...definition,
|
|
122
107
|
options: { ...definition.options, ...(PINNED_TOOLS.includes(definition.name) ? { pinned: true } : {}) },
|
|
123
108
|
execute: (input, context) => {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
(definition.name === "promote" && !input?.revoke)
|
|
129
|
-
)
|
|
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)
|
|
130
113
|
const run = async () => {
|
|
131
114
|
const reason = (runtime.availability ? await runtime.availability() : runtime.unavailable?.()) ?? ""
|
|
132
115
|
if (reason) return { content: reason }
|
|
133
|
-
|
|
116
|
+
// One tool call is one logical call: its records writes derive
|
|
117
|
+
// their idempotency keys from its ids (docs/design/records-idempotency.md).
|
|
118
|
+
return withWriteCall(context, definition.name, input, () => definition.execute(input, context))
|
|
134
119
|
}
|
|
135
120
|
return held ? asVerifiedSession(context?.sessionID, run) : asSession(context?.sessionID, run)
|
|
136
121
|
},
|