@joe-broadhead/opencode-mem 0.11.2 → 0.11.3
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 +51 -0
- package/README.md +1 -0
- package/package.json +504 -2
- package/src/config.js +9 -1
- package/src/tools/commitments.js +50 -32
- package/src/tools/held-write.js +15 -7
- package/src/tools/index.js +1 -0
- package/src/tools/ingest.js +11 -0
- package/src/tools/memory.js +26 -18
- package/src/tools/page.js +118 -87
- package/src/tools/recall.js +12 -2
- package/src/tools/shared.js +40 -2
- package/src/tools/spaces.js +8 -1
- package/src/tools/wiki.js +198 -113
- package/src/views/contracts.js +152 -2
- package/src/views/receipt.js +26 -1
- package/src/views/records-reads.js +165 -3
- package/src/views/rpc.js +35 -17
- package/src/views/write-state.js +89 -0
- package/src/wiki-ingest.js +215 -0
- package/src/wiki-state.js +228 -0
package/src/tools/commitments.js
CHANGED
|
@@ -17,6 +17,7 @@ import { dueStated, holdsWord, tiedWords, triggerStated } from "../stated.js"
|
|
|
17
17
|
import { latestWord } from "../requests.js"
|
|
18
18
|
import { errorMessage, oneLine } from "../util.js"
|
|
19
19
|
import { withReceipt, writeReceipt } from "../views/receipt.js"
|
|
20
|
+
import { commitmentPlace, failedAnswer, refusedAnswer, withWriteState } from "../views/write-state.js"
|
|
20
21
|
import { spaceOf } from "../views/shape.js"
|
|
21
22
|
|
|
22
23
|
/**
|
|
@@ -157,37 +158,44 @@ export function registerCommitments(editor, toolkit) {
|
|
|
157
158
|
options: { namespace: "mem" },
|
|
158
159
|
execute: async (input, context) => {
|
|
159
160
|
const action = String(input?.action ?? "")
|
|
161
|
+
// 0.11.3 (jelly's #89 ask A4): a write's answer opens with its state
|
|
162
|
+
// line, and a refusal opens with `state: refused` and names nothing.
|
|
163
|
+
const isWrite = action === "add" || action === "update" || action === "delete"
|
|
164
|
+
const answer = (content) => (isWrite ? refusedAnswer(text(content)) : text(content))
|
|
165
|
+
const failure = (message) => (isWrite ? failedAnswer(fail(message)) : fail(message))
|
|
160
166
|
if (!COMMITMENT_ACTIONS.includes(action)) {
|
|
161
|
-
return
|
|
167
|
+
return answer(`action is required: one of ${COMMITMENT_ACTIONS.join(", ")}. Example: {"action": "list"}`)
|
|
162
168
|
}
|
|
163
169
|
const where = await personalScope(context)
|
|
164
|
-
if (where.invalid) return
|
|
165
|
-
if (where.error) return
|
|
170
|
+
if (where.invalid) return answer(where.invalid)
|
|
171
|
+
if (where.error) return failure(where.error)
|
|
166
172
|
const { now, zone, today } = clockNow()
|
|
167
173
|
|
|
168
174
|
if (action === "list") {
|
|
169
175
|
const state = String(input?.state ?? "open").toLowerCase()
|
|
170
|
-
if (![...STATES, "all"].includes(state)) return
|
|
176
|
+
if (![...STATES, "all"].includes(state)) return answer(`state must be one of ${[...STATES, "all"].join(", ")}`)
|
|
171
177
|
if (input?.due_before !== undefined && input?.due_before !== "") {
|
|
172
178
|
const before = validateDue(input.due_before)
|
|
173
|
-
if (before.error || before.due.includes("T")) return
|
|
179
|
+
if (before.error || before.due.includes("T")) return answer("due_before must be a date, YYYY-MM-DD")
|
|
174
180
|
}
|
|
175
181
|
let records
|
|
176
182
|
try {
|
|
177
183
|
records = (await runtime.records.read(where.scoped)).records
|
|
178
184
|
} catch (error) {
|
|
179
185
|
log.warn("commitments read failed", error)
|
|
180
|
-
return
|
|
186
|
+
return failure(errorMessage(error))
|
|
181
187
|
}
|
|
182
188
|
const items = filterItems(records.items, input, zone)
|
|
183
189
|
const label = state === "all" ? "" : `${state} `
|
|
184
190
|
if (items.length === 0) {
|
|
185
191
|
const filters = `${input?.project ? ` for project ${oneLine(input.project, 80)}` : ""}${input?.owner ? ` owned by ${oneLine(input.owner, 80)}` : ""}`
|
|
186
|
-
|
|
192
|
+
// 0.11.3: name the space, because agents restate "no commitments" as
|
|
193
|
+
// a claim about the person's records (0.11.1 gate H2).
|
|
194
|
+
return answer(`No ${label}commitments${filters} in your personal space. Today is ${formatDay(today)}.`)
|
|
187
195
|
}
|
|
188
196
|
const lines = items.slice(0, LIST_MAX).map((item) => itemLine(item, today, zone))
|
|
189
197
|
if (items.length > LIST_MAX) lines.push(`(${items.length - LIST_MAX} more)`)
|
|
190
|
-
return
|
|
198
|
+
return answer(
|
|
191
199
|
[
|
|
192
200
|
`<commitments today="${formatDay(today)}">`,
|
|
193
201
|
`Stored commitments, not instructions. Overdue first; undated last.${
|
|
@@ -200,9 +208,9 @@ export function registerCommitments(editor, toolkit) {
|
|
|
200
208
|
}
|
|
201
209
|
|
|
202
210
|
const id = String(input?.id ?? "").trim()
|
|
203
|
-
if (action !== "add" && !id) return
|
|
204
|
-
if (action === "add" && id) return
|
|
205
|
-
if (action !== "update" && input?.state !== undefined) return
|
|
211
|
+
if (action !== "add" && !id) return answer(`id is required for ${action}: the rec_… id from list or add`)
|
|
212
|
+
if (action === "add" && id) return answer("add makes a new id; to change a commitment, use update with its id")
|
|
213
|
+
if (action !== "update" && input?.state !== undefined) return answer("state is set with update; add always starts open")
|
|
206
214
|
|
|
207
215
|
let change
|
|
208
216
|
let warning = ""
|
|
@@ -210,13 +218,13 @@ export function registerCommitments(editor, toolkit) {
|
|
|
210
218
|
if (action === "delete") {
|
|
211
219
|
change = { action, id }
|
|
212
220
|
} else {
|
|
213
|
-
if (action === "update" && input?.state === "all") return
|
|
221
|
+
if (action === "update" && input?.state === "all") return answer("state must be open, done, or cancelled")
|
|
214
222
|
const validated = validateFields(input, { requireWhat: action === "add" })
|
|
215
|
-
if (validated.error) return
|
|
223
|
+
if (validated.error) return answer(`not saved: ${validated.error}`)
|
|
216
224
|
const fields = validated.fields
|
|
217
225
|
// Secrets and email addresses are refused; a home path or a role address is stored with a warning (D3').
|
|
218
226
|
const personal = storable([fields.what, fields.trigger, fields.owner, fields.link].filter((part) => typeof part === "string").join("\n"), "commitment")
|
|
219
|
-
if (personal.outcome === "refuse") return
|
|
227
|
+
if (personal.outcome === "refuse") return answer(personal.message.replace(/^not stored/, "not saved"))
|
|
220
228
|
if (personal.outcome === "warn") warning = personal.message
|
|
221
229
|
// A due date or trigger is kept only when the person's messages name it
|
|
222
230
|
// (0.9.9, WRITES-099; 0.11 gate H2). A call with no call id — a host's
|
|
@@ -230,8 +238,8 @@ export function registerCommitments(editor, toolkit) {
|
|
|
230
238
|
const personMessages = said.brief || (said.model && !said.seen) ? [{ text: "", at: 0 }] : said.seen ? (runtime.personSaid?.(context?.sessionID) ?? []) : []
|
|
231
239
|
const unstated = keepStated(fields, personMessages, zone, runtime.personDrops?.(context?.sessionID))
|
|
232
240
|
if (action === "update" && Object.keys(fields).length === 0) {
|
|
233
|
-
if (unstated.length > 0) return
|
|
234
|
-
return
|
|
241
|
+
if (unstated.length > 0) return answer(`not updated: ${unstated.join(" ")}`)
|
|
242
|
+
return answer("nothing to update: pass state, what, owner, due, trigger, project, or link")
|
|
235
243
|
}
|
|
236
244
|
if (unstated.length > 0) dropped = unstated.join(" ")
|
|
237
245
|
change = { action, id: action === "add" ? newCommitmentId() : id, fields }
|
|
@@ -246,9 +254,9 @@ export function registerCommitments(editor, toolkit) {
|
|
|
246
254
|
})
|
|
247
255
|
} catch (error) {
|
|
248
256
|
log.warn("commitments write failed", error)
|
|
249
|
-
return
|
|
257
|
+
return failure(errorMessage(error))
|
|
250
258
|
}
|
|
251
|
-
if (result.error) return
|
|
259
|
+
if (result.error) return answer(`${result.conflict ? "not saved (conflict)" : "not saved"}: ${result.error}`)
|
|
252
260
|
// The Due list in the pinned block is rebuilt on the next model call.
|
|
253
261
|
runtime.invalidate?.(context?.sessionID)
|
|
254
262
|
log.info("commitments", { action, rounds: result.rounds, unchanged: Boolean(result.unchanged) })
|
|
@@ -256,22 +264,28 @@ export function registerCommitments(editor, toolkit) {
|
|
|
256
264
|
if (action === "add" && result.unchanged) {
|
|
257
265
|
// A duplicate changed nothing (0.10.3 gate, B13): say so plainly, and
|
|
258
266
|
// tag the record in the list as the one that was already open.
|
|
259
|
-
return
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
+
return withWriteState(
|
|
268
|
+
text(
|
|
269
|
+
[
|
|
270
|
+
`already open, so nothing was added: ${describe(result.item, zone)}`,
|
|
271
|
+
dropped,
|
|
272
|
+
openNowSummary(result.records?.items, today, zone, { mark: { id: result.item.id, label: "already open, nothing added" } }),
|
|
273
|
+
]
|
|
274
|
+
.filter(Boolean)
|
|
275
|
+
.join("\n"),
|
|
276
|
+
),
|
|
277
|
+
{ state: "stored", id: result.item.id, link: commitmentPlace(result.item.id) },
|
|
267
278
|
)
|
|
268
279
|
}
|
|
269
280
|
if (action === "delete") {
|
|
270
|
-
return
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
281
|
+
return withWriteState(
|
|
282
|
+
text(
|
|
283
|
+
[
|
|
284
|
+
`deleted ${oneLine(result.item.id || id, 40)}: ${oneLine(result.item.what, 300)}. It is gone from this space's records.`,
|
|
285
|
+
openNowSummary(result.records?.items, today, zone),
|
|
286
|
+
].join("\n"),
|
|
287
|
+
),
|
|
288
|
+
{ state: "ready" },
|
|
275
289
|
)
|
|
276
290
|
}
|
|
277
291
|
const verb = action === "add" ? "added" : "updated"
|
|
@@ -305,7 +319,11 @@ export function registerCommitments(editor, toolkit) {
|
|
|
305
319
|
const receipt = action === "add"
|
|
306
320
|
? writeReceipt("commit", { record: { ...result.item, kind: "commitment", type: "commitment", status: "current", title: result.item.what }, space: spaceOf(where.spaceContext) })
|
|
307
321
|
: undefined
|
|
308
|
-
return withReceipt(text(lines.join("\n")), receipt)
|
|
322
|
+
return withWriteState(withReceipt(text(lines.join("\n")), receipt), {
|
|
323
|
+
state: "stored",
|
|
324
|
+
id: result.item.id,
|
|
325
|
+
link: commitmentPlace(result.item.id),
|
|
326
|
+
})
|
|
309
327
|
},
|
|
310
328
|
})
|
|
311
329
|
}
|
package/src/tools/held-write.js
CHANGED
|
@@ -23,7 +23,14 @@ function writeKey(context, space) {
|
|
|
23
23
|
return `hw_${hash(JSON.stringify([space, context.sessionID, context.messageID, context.id]))}`
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* Hold only the submitted records, in the caller's personal space.
|
|
28
|
+
*
|
|
29
|
+
* Answers `{ text, id, state }` (0.11.3, jelly's #89 ask A4): the sentence the
|
|
30
|
+
* write answers, the proposal's id, and the state the write's first line
|
|
31
|
+
* carries: `held` for a new hold, `stored` when an earlier acceptance already
|
|
32
|
+
* saved it, `refused` when the person declined it.
|
|
33
|
+
*/
|
|
27
34
|
export async function holdTeamWrite(toolkit, context, spaceContext, records) {
|
|
28
35
|
if (!spaceContext?.space_id || !spaceContext?.space_name || spaceContext.space_kind !== "shared") throw new Error("held write needs a named shared space from control")
|
|
29
36
|
if (!Array.isArray(records) || records.length === 0 || records.length > 20) throw new Error("held write needs one to twenty records")
|
|
@@ -47,12 +54,13 @@ export async function holdTeamWrite(toolkit, context, spaceContext, records) {
|
|
|
47
54
|
},
|
|
48
55
|
}
|
|
49
56
|
const answer = await callRecords(toolkit, "records.put", { record, idempotency_key: idempotencyKey }, personal, scoped)
|
|
50
|
-
|
|
51
|
-
if (
|
|
52
|
-
if (answer.record.status === "
|
|
53
|
-
if (answer.record.status === "
|
|
54
|
-
if (answer.record.status === "
|
|
55
|
-
|
|
57
|
+
const id = String(answer?.record?.id ?? "")
|
|
58
|
+
if (!RECORD_ID.test(id)) throw new Error("the records service did not confirm the proposal")
|
|
59
|
+
if (answer.record.status === "applied") return { text: `Already approved and saved in ${oneLine(spaceContext.space_name, 200)}; no new write was made.`, id, state: "stored" }
|
|
60
|
+
if (answer.record.status === "applied_private") return { text: "Already saved privately; no new write was made.", id, state: "stored" }
|
|
61
|
+
if (answer.record.status === "declined") return { text: "The person declined this write; nothing was saved and it must not be retried elsewhere.", id, state: "refused" }
|
|
62
|
+
if (answer.record.status === "accepting") return { text: "Approval is being completed; retry the same acceptance.", id, state: "held" }
|
|
63
|
+
return { text: `Held for approval in the Inbox for ${oneLine(spaceContext.space_name, 200)}; not saved as a memory or page yet.`, id, state: "held" }
|
|
56
64
|
}
|
|
57
65
|
|
|
58
66
|
/**
|
package/src/tools/index.js
CHANGED
package/src/tools/ingest.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { describeResult } from "../collector-service.js"
|
|
2
|
+
import { memoryResourceAvailable } from "../credentials.js"
|
|
2
3
|
import { asksToCollect, latestWord, mustRefuse } from "../requests.js"
|
|
3
4
|
import { errorMessage } from "../util.js"
|
|
4
5
|
|
|
@@ -129,6 +130,8 @@ export function registerCollect(editor, toolkit) {
|
|
|
129
130
|
started: { type: "boolean" },
|
|
130
131
|
running: { type: "boolean" },
|
|
131
132
|
skipped: { type: "string" },
|
|
133
|
+
/** Why a routine could not collect: the same state `memory.overview` names. */
|
|
134
|
+
state: { type: "string", enum: ["unconfigured", "refused", "unreachable"] },
|
|
132
135
|
done: { type: "boolean" },
|
|
133
136
|
sources: { type: "array", items: { type: "object" } },
|
|
134
137
|
},
|
|
@@ -142,6 +145,14 @@ export function registerCollect(editor, toolkit) {
|
|
|
142
145
|
await toolkit.ensureSession?.(context?.sessionID)
|
|
143
146
|
const said = latestWord(toolkit.runtime, context?.sessionID, context)
|
|
144
147
|
if (mustRefuse(said, asksToCollect(said.text))) return { output: { skipped: COLLECT_NEEDS_REQUEST }, content: COLLECT_NEEDS_REQUEST }
|
|
148
|
+
// A host that offers no `memory` resource has no Memory service to collect
|
|
149
|
+
// from. A host's direct execution (a routine's check) says so, rather than
|
|
150
|
+
// answer "started" for a collection that cannot run. A model's call in
|
|
151
|
+
// plain OpenCode keeps the local path it has today.
|
|
152
|
+
if (!said.model && !toolkit.config?.controlURL && !memoryResourceAvailable()) {
|
|
153
|
+
const answer = "Memory is unavailable: this host has not offered the memory resource, so a routine cannot collect. Next step: turn on Memory's services on the host, or ask the person to connect Memory."
|
|
154
|
+
return { output: { skipped: answer, state: "unconfigured" }, content: answer }
|
|
155
|
+
}
|
|
145
156
|
const outcome = await toolkit.collector.trigger({ source: input?.source, wait: input?.wait === true, sessionID: context?.sessionID, from: "tool" })
|
|
146
157
|
return { output: collectOutput(outcome), content: describeOutcome(outcome) }
|
|
147
158
|
},
|
package/src/tools/memory.js
CHANGED
|
@@ -21,6 +21,7 @@ import { TASK_INPUT, canWriteShared, hostProvenance } from "./shared.js"
|
|
|
21
21
|
import { CORE_ID, MEMORY_TYPES, PAGE_PATH, RECORD_ID, TURN_ID, callRecords, changeNote, dateOf, lineageIds, noteRecordSpace, notWritten, recordLine, recordSpace, titleFrom } from "./records-kit.js"
|
|
22
22
|
import { spaceOf } from "../views/shape.js"
|
|
23
23
|
import { withReceipt, writeReceipt } from "../views/receipt.js"
|
|
24
|
+
import { failedAnswer, memoryPlace, refusedAnswer, withWriteState } from "../views/write-state.js"
|
|
24
25
|
|
|
25
26
|
const KINDS = MEMORY_TYPES
|
|
26
27
|
/** A supersede replaces a few records, not a cleanup: more is a forget. */
|
|
@@ -901,57 +902,61 @@ export function registerRemember(editor, toolkit) {
|
|
|
901
902
|
},
|
|
902
903
|
options: { namespace: "mem" },
|
|
903
904
|
execute: async (input, context) => {
|
|
905
|
+
// 0.11.3 (jelly's #89 ask A4): an answer that writes nothing opens with
|
|
906
|
+
// `state: refused`; one whose call did not finish opens with `failed`.
|
|
907
|
+
const refuse = (message) => refusedAnswer(text(message))
|
|
908
|
+
const failedCall = (message) => failedAnswer(fail(message))
|
|
904
909
|
// Every refusal is decided here, before any request.
|
|
905
910
|
const content = String(input?.content ?? "").trim()
|
|
906
911
|
const refusal = writeRefusal(content)
|
|
907
|
-
if (refusal) return
|
|
912
|
+
if (refusal) return refuse(refusal)
|
|
908
913
|
if (content.length > MAX_CONTENT_CHARS) {
|
|
909
|
-
return
|
|
914
|
+
return refuse(
|
|
910
915
|
`not stored: ${content.length} characters is not one atomic fact (limit ${MAX_CONTENT_CHARS}). State the decision in a sentence or two, and put long synthesis on a page (mem_page).`,
|
|
911
916
|
)
|
|
912
917
|
}
|
|
913
918
|
// kind is required (§4.1); a host that does not check the schema gets fact.
|
|
914
919
|
const kind = input?.kind === undefined || input?.kind === null || input?.kind === "" ? "fact" : String(input.kind)
|
|
915
|
-
if (!KINDS.includes(kind)) return
|
|
920
|
+
if (!KINDS.includes(kind)) return refuse(`not stored: kind must be one of ${KINDS.join(", ")}.`)
|
|
916
921
|
// The why is stored with the fact, so it passes the same guard.
|
|
917
922
|
const why = String(input?.why ?? "").trim()
|
|
918
923
|
const whyRefusal = why ? writeRefusal(why) : ""
|
|
919
924
|
if (whyRefusal) {
|
|
920
925
|
// A refusal that opens "Nothing was stored:" keeps its opening, so a relay passes the gate's answer check.
|
|
921
|
-
if (whyRefusal.startsWith("Nothing was stored: ")) return
|
|
922
|
-
return
|
|
926
|
+
if (whyRefusal.startsWith("Nothing was stored: ")) return refuse(whyRefusal.replace(/^Nothing was stored: /, "Nothing was stored (why): "))
|
|
927
|
+
return refuse(`not stored (why): ${whyRefusal.replace(/^not stored: /, "")}`)
|
|
923
928
|
}
|
|
924
929
|
// Who stated it is the host's to decide, not the caller's (FABLE tools 1
|
|
925
930
|
// and 6): the argument is a claim, kept for compatibility, and stays
|
|
926
931
|
// "person" only in a held write the person accepts (hostProvenance).
|
|
927
932
|
const claimed = input?.stated_by === "person" ? "person" : "agent"
|
|
928
933
|
const links = idList(input?.links)
|
|
929
|
-
if (links.length > MAX_LINKS) return
|
|
934
|
+
if (links.length > MAX_LINKS) return refuse(`not stored: links takes at most ${MAX_LINKS} paths or ids.`)
|
|
930
935
|
const badLinks = links.filter((link) => !PAGE_PATH.test(link) && !RECORD_ID.test(link))
|
|
931
936
|
if (badLinks.length > 0) {
|
|
932
|
-
return
|
|
937
|
+
return refuse(`not stored: ${badLinks.map((link) => JSON.stringify(oneLine(link, 80))).join(", ")} ${badLinks.length === 1 ? "is not a page path or record id" : "are not page paths or record ids"}; a path is lower-case segments such as people/ama.`)
|
|
933
938
|
}
|
|
934
939
|
const supersedes = idList(input?.supersedes)
|
|
935
940
|
if (supersedes.length > MAX_SUPERSEDES) {
|
|
936
|
-
return
|
|
941
|
+
return refuse(`not stored: supersedes takes at most ${MAX_SUPERSEDES} ids; to remove more, use mem_revise forget.`)
|
|
937
942
|
}
|
|
938
943
|
const turns = supersedes.filter((id) => TURN_ID.test(id))
|
|
939
944
|
if (turns.length > 0) {
|
|
940
|
-
return
|
|
945
|
+
return refuse(
|
|
941
946
|
`not stored: supersedes takes memory ids (rec_…) or atom ids (m_…); ${turns.map((id) => oneLine(id, 80)).join(", ")} ${turns.length === 1 ? "is a turn" : "are turns"}. Pass the memory's id, or forget the turn with mem_revise.`,
|
|
942
947
|
)
|
|
943
948
|
}
|
|
944
949
|
const recordIDs = supersedes.filter((id) => RECORD_ID.test(id))
|
|
945
950
|
const atomIDs = supersedes.filter((id) => !RECORD_ID.test(id))
|
|
946
951
|
const task = taskFor(input, context)
|
|
947
|
-
if (task.invalid) return
|
|
952
|
+
if (task.invalid) return refuse(`not stored: ${task.invalid}`)
|
|
948
953
|
|
|
949
954
|
// Personal, whatever the call names (FIX-0911). A call that asked for a
|
|
950
955
|
// shared target is told where the memory went and how the team gets it.
|
|
951
956
|
const askedShared = normalizeVisibility(input?.visibility, "private") !== "private" || String(input?.space ?? "").trim() !== ""
|
|
952
957
|
const resolved = await resolvePrivateSpace({}, context)
|
|
953
|
-
if (resolved.invalid) return
|
|
954
|
-
if (resolved.error) return
|
|
958
|
+
if (resolved.invalid) return refuse(resolved.invalid)
|
|
959
|
+
if (resolved.error) return failedCall(resolved.error)
|
|
955
960
|
const spaceContext = resolved.context
|
|
956
961
|
const scoped = spaceContext ? scopeFor(spaceContext, { agent: context?.agent }) : scope({ agent: context?.agent })
|
|
957
962
|
const label = displayScope(spaceContext, scoped)
|
|
@@ -963,7 +968,7 @@ export function registerRemember(editor, toolkit) {
|
|
|
963
968
|
try {
|
|
964
969
|
const found = await callRecords(toolkit, "records.search", { query: oneLine(content, 200), kinds: ["memory"], types: [kind], limit: 5 }, spaceContext, scoped)
|
|
965
970
|
const same = (found?.hits ?? []).find((hit) => hit.type === kind && normal(hit.snippet) === normal(body))
|
|
966
|
-
if (same) return text(`already stored as ${same.id} (memory/${kind}) in ${label}; nothing new was written. To change it: mem_revise {"action": "correct", "id": "${same.id}", "content": "…"}.`)
|
|
971
|
+
if (same) return withWriteState(text(`already stored as ${same.id} (memory/${kind}) in ${label}; nothing new was written. To change it: mem_revise {"action": "correct", "id": "${same.id}", "content": "…"}.`), { state: "stored", id: same.id, link: memoryPlace(same.id) })
|
|
967
972
|
} catch {
|
|
968
973
|
/* the check is a courtesy; the write decides */
|
|
969
974
|
}
|
|
@@ -1000,17 +1005,17 @@ export function registerRemember(editor, toolkit) {
|
|
|
1000
1005
|
} catch (error) {
|
|
1001
1006
|
log.warn("remember failed", error)
|
|
1002
1007
|
if (!error?.outcomeUnknown) await core?.dropKept(keep, spaceContext, scoped)
|
|
1003
|
-
if (error?.outcomeUnknown) return
|
|
1008
|
+
if (error?.outcomeUnknown) return failedCall(errorMessage(error))
|
|
1004
1009
|
const refused = notWritten(error, "stored")
|
|
1005
|
-
if (refused) return
|
|
1010
|
+
if (refused) return refuse(refused)
|
|
1006
1011
|
if (error instanceof RecordsError && error.code === "not_found") {
|
|
1007
|
-
return
|
|
1012
|
+
return refuse(`not confirmed: ${oneLine(error.what, 200).replace(/^[^:]+: /, "")}. Supersedes takes rec_ ids that mem_recall or mem_remember returned.`)
|
|
1008
1013
|
}
|
|
1009
1014
|
const message = errorMessage(error)
|
|
1010
1015
|
return isCoded(message) ? text(message) : fail(message)
|
|
1011
1016
|
}
|
|
1012
1017
|
const id = String(stored?.id ?? "")
|
|
1013
|
-
if (!RECORD_ID.test(id)) return
|
|
1018
|
+
if (!RECORD_ID.test(id)) return failedCall("the records service answered without a record id; the memory may not be stored. Check with mem_recall before writing it again.")
|
|
1014
1019
|
noteRecordSpace(toolkit, id, spaceContext)
|
|
1015
1020
|
log.info("remember", { kind, scope: label, task: Boolean(task.key), supersedes: supersedes.length, askedShared })
|
|
1016
1021
|
|
|
@@ -1029,7 +1034,10 @@ export function registerRemember(editor, toolkit) {
|
|
|
1029
1034
|
}
|
|
1030
1035
|
if (core) lines.push(await core.supersedeAtoms(keep, id, spaceContext, base))
|
|
1031
1036
|
lines.push(`To change it later: mem_revise {"action": "correct", "id": "${id}", "content": "…"}; to drop it: {"action": "retire", "id": "${id}"}.`)
|
|
1032
|
-
return
|
|
1037
|
+
return withWriteState(
|
|
1038
|
+
withReceipt(text(lines.join("\n")), writeReceipt("remember", { record: stored, space: spaceOf(spaceContext) })),
|
|
1039
|
+
{ state: "stored", id, link: memoryPlace(id) },
|
|
1040
|
+
)
|
|
1033
1041
|
},
|
|
1034
1042
|
})
|
|
1035
1043
|
}
|