@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.
- package/CHANGELOG.md +1408 -0
- package/README.md +120 -41
- package/docs/agent-instructions.md +17 -0
- package/docs/agent-protocol.md +28 -27
- package/docs/permissions.md +150 -0
- package/package.json +386 -17
- package/skills/mem.pages/SKILL.md +40 -16
- package/skills/mem.sharing/SKILL.md +39 -6
- package/skills/mem.sources/SKILL.md +41 -10
- package/skills/mem.usage/SKILL.md +37 -16
- package/src/backend/records.js +8 -0
- 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 -5
- package/src/collector-service.js +212 -35
- package/src/collector.js +187 -47
- package/src/commands.js +37 -0
- package/src/compaction.js +4 -2
- package/src/config.js +151 -1
- package/src/curation.js +6 -10
- package/src/events.js +144 -36
- package/src/forget-purge.js +377 -0
- package/src/forgotten.js +152 -0
- package/src/hooks.js +9 -4
- package/src/index.js +5 -3
- package/src/permissions.js +116 -38
- package/src/protocol.js +32 -11
- package/src/recall.js +13 -1
- package/src/records.js +4 -1
- package/src/runtime.js +202 -15
- package/src/shapes.js +63 -0
- package/src/sources.js +205 -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 +79 -13
- package/src/tools/held-write.js +5 -1
- package/src/tools/index.js +25 -43
- package/src/tools/ingest.js +33 -128
- package/src/tools/memory.js +525 -911
- 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 +36 -8
- package/src/tools/records-kit.js +2 -1
- package/src/tools/share.js +494 -131
- package/src/tools/shared.js +97 -19
- package/src/tools/spaces.js +194 -101
- package/src/tools/status.js +31 -3
- package/src/tools/wiki.js +5 -13
- package/src/util.js +10 -59
- package/src/views/contracts.js +258 -20
- package/src/views/overdue.js +1 -1
- package/src/views/profile.js +2 -3
- package/src/views/receipt.js +81 -0
- package/src/views/records-reads.js +545 -25
- package/src/views/rpc.js +41 -3
- package/views/memory.html +16 -3
- package/views/remembered.html +130 -0
- 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,7 +12,52 @@ 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"
|
|
17
|
+
import { withReceipt, writeReceipt } from "../views/receipt.js"
|
|
18
|
+
import { spaceOf } from "../views/shape.js"
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Drop a due date or a trigger the person did not state (0.9.9, WRITES-099):
|
|
22
|
+
* the 0.9.8 gate found agents storing a day they worked out from "next week"
|
|
23
|
+
* or from a recalled note. `messages` are the person's recent messages in the
|
|
24
|
+
* session (src/stated.js); with none seen (a host that reports no prompt
|
|
25
|
+
* text) nothing is checked. Clearing a due ("") is always allowed.
|
|
26
|
+
*
|
|
27
|
+
* A date the matcher cannot read from the person's words but that is tied to
|
|
28
|
+
* them (its day number, month or weekday, as in "Black Friday") is dropped
|
|
29
|
+
* once and remembered in `drops`; when the person's next message repeats the
|
|
30
|
+
* tied words (they were asked, and said it again), it is kept, so the ask
|
|
31
|
+
* cannot loop. A date tied to nothing they said is always dropped.
|
|
32
|
+
*
|
|
33
|
+
* @param {Record<string, unknown>} fields the validated fields; changed in place
|
|
34
|
+
* @param {Array<{ text: string, at: number, seq?: number }>} messages
|
|
35
|
+
* @param {string} zone
|
|
36
|
+
* @param {Map<string, { words: string[], seq: number }>} [drops] this session's dropped dates; changed in place
|
|
37
|
+
* @returns {string[]} one sentence per dropped field
|
|
38
|
+
*/
|
|
39
|
+
export function keepStated(fields, messages, zone, drops = new Map()) {
|
|
40
|
+
if (!Array.isArray(messages) || messages.length === 0) return []
|
|
41
|
+
const notes = []
|
|
42
|
+
if (typeof fields.due === "string" && fields.due !== "" && !dueStated(fields.due, messages, zone)) {
|
|
43
|
+
const latest = messages.at(-1)
|
|
44
|
+
const before = drops.get(fields.due)
|
|
45
|
+
const repeated = before && Number(latest?.seq) > before.seq && before.words.some((word) => holdsWord(latest.text, word))
|
|
46
|
+
if (repeated) {
|
|
47
|
+
drops.delete(fields.due)
|
|
48
|
+
} else {
|
|
49
|
+
const words = tiedWords(fields.due, messages)
|
|
50
|
+
if (words.length > 0) drops.set(fields.due, { words, seq: Number(latest?.seq) || 0 })
|
|
51
|
+
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.`)
|
|
52
|
+
delete fields.due
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (typeof fields.trigger === "string" && fields.trigger !== "" && !triggerStated(fields.trigger, messages)) {
|
|
56
|
+
notes.push(`trigger "${oneLine(fields.trigger, 120)}" was not kept: the person's messages do not name it. Ask them, then update it.`)
|
|
57
|
+
delete fields.trigger
|
|
58
|
+
}
|
|
59
|
+
return notes
|
|
60
|
+
}
|
|
15
61
|
|
|
16
62
|
/** The list answer shows at most this many items; the rest are counted. */
|
|
17
63
|
const LIST_MAX = 50
|
|
@@ -69,7 +115,7 @@ export function registerCommitments(editor, toolkit) {
|
|
|
69
115
|
editor.add({
|
|
70
116
|
name: "commitments",
|
|
71
117
|
description:
|
|
72
|
-
"Track things someone will do, with a due date or a trigger. Call it for the person's promises and reminders
|
|
118
|
+
"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
119
|
input: {
|
|
74
120
|
type: "object",
|
|
75
121
|
properties: {
|
|
@@ -77,31 +123,31 @@ export function registerCommitments(editor, toolkit) {
|
|
|
77
123
|
type: "string",
|
|
78
124
|
enum: [...COMMITMENT_ACTIONS],
|
|
79
125
|
description:
|
|
80
|
-
|
|
126
|
+
"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
127
|
},
|
|
82
|
-
id: { type: "string", description: "
|
|
128
|
+
id: { type: "string", description: "From list or add (rec_…, or an older cmt_…); update and delete need it" },
|
|
83
129
|
what: {
|
|
84
130
|
type: "string",
|
|
85
|
-
description: "
|
|
131
|
+
description: "Required for add: what will be done, starting with a verb, at most 300 characters",
|
|
86
132
|
},
|
|
87
133
|
owner: {
|
|
88
134
|
type: "string",
|
|
89
|
-
description:
|
|
135
|
+
description: "\"user\" (default), \"agent\" (you promised), or a person's name (the person waits on them); list: only this owner",
|
|
90
136
|
},
|
|
91
137
|
due: {
|
|
92
138
|
type: "string",
|
|
93
139
|
description:
|
|
94
|
-
|
|
140
|
+
"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
141
|
},
|
|
96
|
-
trigger: { type: "string", description:
|
|
142
|
+
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
143
|
state: {
|
|
98
144
|
type: "string",
|
|
99
145
|
enum: [...STATES, "all"],
|
|
100
|
-
description:
|
|
146
|
+
description: "update: open, done or cancelled; list: open (default), done, cancelled or all",
|
|
101
147
|
},
|
|
102
|
-
project: { type: "string", description:
|
|
103
|
-
link: { type: "string", description: "
|
|
104
|
-
due_before: { type: "string", description: "list
|
|
148
|
+
project: { type: "string", description: "Project page slug (\"checkout-v3\"); list: only this project" },
|
|
149
|
+
link: { type: "string", description: "Tracker item, PR or thread (an id or a URL)" },
|
|
150
|
+
due_before: { type: "string", description: "list: due before this date (YYYY-MM-DD)" },
|
|
105
151
|
},
|
|
106
152
|
required: ["action"],
|
|
107
153
|
additionalProperties: false,
|
|
@@ -157,6 +203,8 @@ export function registerCommitments(editor, toolkit) {
|
|
|
157
203
|
if (action !== "update" && input?.state !== undefined) return text("state is set with update; add always starts open")
|
|
158
204
|
|
|
159
205
|
let change
|
|
206
|
+
let warning = ""
|
|
207
|
+
let dropped = ""
|
|
160
208
|
if (action === "delete") {
|
|
161
209
|
change = { action, id }
|
|
162
210
|
} else {
|
|
@@ -164,9 +212,18 @@ export function registerCommitments(editor, toolkit) {
|
|
|
164
212
|
const validated = validateFields(input, { requireWhat: action === "add" })
|
|
165
213
|
if (validated.error) return text(`not saved: ${validated.error}`)
|
|
166
214
|
const fields = validated.fields
|
|
215
|
+
// Secrets and email addresses are refused; a home path or a role address is stored with a warning (D3').
|
|
216
|
+
const personal = storable([fields.what, fields.trigger, fields.owner, fields.link].filter((part) => typeof part === "string").join("\n"), "commitment")
|
|
217
|
+
if (personal.outcome === "refuse") return text(personal.message.replace(/^not stored/, "not saved"))
|
|
218
|
+
if (personal.outcome === "warn") warning = personal.message
|
|
219
|
+
// A due date or trigger is kept only when the person's messages name it
|
|
220
|
+
// (0.9.9, WRITES-099): one the agent worked out is dropped, and said.
|
|
221
|
+
const unstated = keepStated(fields, runtime.personSaid?.(context?.sessionID) ?? [], zone, runtime.personDrops?.(context?.sessionID))
|
|
167
222
|
if (action === "update" && Object.keys(fields).length === 0) {
|
|
223
|
+
if (unstated.length > 0) return text(`not updated: ${unstated.join(" ")}`)
|
|
168
224
|
return text("nothing to update: pass state, what, owner, due, trigger, project, or link")
|
|
169
225
|
}
|
|
226
|
+
if (unstated.length > 0) dropped = unstated.join(" ")
|
|
170
227
|
change = { action, id: action === "add" ? newCommitmentId() : id, fields }
|
|
171
228
|
}
|
|
172
229
|
|
|
@@ -187,11 +244,12 @@ export function registerCommitments(editor, toolkit) {
|
|
|
187
244
|
log.info("commitments", { action, rounds: result.rounds, unchanged: Boolean(result.unchanged) })
|
|
188
245
|
|
|
189
246
|
if (action === "add" && result.unchanged) {
|
|
190
|
-
return text(`already open, not added again: ${describe(result.item, zone)}
|
|
247
|
+
return text([`already open, not added again: ${describe(result.item, zone)}`, dropped].filter(Boolean).join("\n"))
|
|
191
248
|
}
|
|
192
249
|
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
250
|
const verb = action === "add" ? "added" : "updated"
|
|
194
251
|
const lines = [`${verb} ${describe(result.item, zone)}`]
|
|
252
|
+
if (dropped) lines.push(dropped)
|
|
195
253
|
if (action === "add") {
|
|
196
254
|
const similar = similarOpen(result.records?.items, result.item.what, result.item.id)
|
|
197
255
|
if (similar.length > 0) {
|
|
@@ -205,8 +263,16 @@ export function registerCommitments(editor, toolkit) {
|
|
|
205
263
|
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
264
|
lines.push(`When it is met or dropped: mem_commitments {"action": "update", "id": "${result.item.id}", "state": "done"} (or "cancelled").`)
|
|
207
265
|
}
|
|
266
|
+
if (warning) lines.push(warning)
|
|
208
267
|
if (result.item.state !== "open") lines.push(`Closed items are kept ${CLOSED_RETENTION_DAYS} days, then dropped.`)
|
|
209
|
-
|
|
268
|
+
// Only a new commitment answers a receipt: an update changes a record the
|
|
269
|
+
// turn did not save, and a list or a delete saves nothing. A commitment
|
|
270
|
+
// record's kind and type are fixed by the contract and its open/closed
|
|
271
|
+
// state lives in `fields.state`, so `status` is the record's own.
|
|
272
|
+
const receipt = action === "add"
|
|
273
|
+
? writeReceipt("commit", { record: { ...result.item, kind: "commitment", type: "commitment", status: "current", title: result.item.what }, space: spaceOf(where.spaceContext) })
|
|
274
|
+
: undefined
|
|
275
|
+
return withReceipt(text(lines.join("\n")), receipt)
|
|
210
276
|
},
|
|
211
277
|
})
|
|
212
278
|
}
|
package/src/tools/held-write.js
CHANGED
|
@@ -37,7 +37,11 @@ export async function holdTeamWrite(toolkit, context, spaceContext, records) {
|
|
|
37
37
|
const record = {
|
|
38
38
|
kind: "proposal", type: "team_write", title: "Team write awaiting approval", body: JSON.stringify({ records }),
|
|
39
39
|
fields: { space_id: spaceContext.space_id, space_name: oneLine(spaceContext.space_name, 200), preview, key: idempotencyKey },
|
|
40
|
-
source:
|
|
40
|
+
source: {
|
|
41
|
+
...(context?.sessionID ? { session: String(context.sessionID) } : {}),
|
|
42
|
+
// The turn that made it (#58 F4), so a review row says which message waits.
|
|
43
|
+
...(context?.messageID ? { turn: String(context.messageID) } : {}),
|
|
44
|
+
},
|
|
41
45
|
}
|
|
42
46
|
const answer = await callRecords(toolkit, "records.put", { record, idempotency_key: idempotencyKey }, personal, scoped)
|
|
43
47
|
if (!RECORD_ID.test(String(answer?.record?.id ?? ""))) throw new Error("the records service did not confirm the proposal")
|
package/src/tools/index.js
CHANGED
|
@@ -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 {
|
|
10
|
+
import { registerAliases } from "./aliases.js"
|
|
11
11
|
|
|
12
|
-
//
|
|
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
|
|
81
|
-
*
|
|
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
|
|
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
|
-
|
|
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(
|
|
103
|
-
registerWiki(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
registerIngest(
|
|
107
|
-
registerCollect(
|
|
108
|
-
registerAliases(
|
|
109
|
-
|
|
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
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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 }
|