@joe-broadhead/opencode-mem 0.9.14 → 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.
Files changed (143) hide show
  1. package/CHANGELOG.md +1856 -0
  2. package/README.md +15 -7
  3. package/SECURITY.md +3 -1
  4. package/docs/agent-instructions.md +1 -1
  5. package/docs/agent-protocol.md +7 -7
  6. package/docs/permissions.md +16 -0
  7. package/package.json +8921 -1070
  8. package/shared/page-paths.js +44 -0
  9. package/skills/mem.pages/SKILL.md +3 -1
  10. package/skills/mem.usage/SKILL.md +15 -15
  11. package/src/action-grant-keys.js +159 -0
  12. package/src/action-grant.js +439 -0
  13. package/src/actions.js +1690 -0
  14. package/src/backend/records.js +25 -2
  15. package/src/backend/v3.js +76 -22
  16. package/src/call-shapes.js +17 -16
  17. package/src/collector-lock.js +533 -62
  18. package/src/collector-service.js +153 -26
  19. package/src/collector.js +623 -30
  20. package/src/config.js +88 -7
  21. package/src/connect.js +106 -8
  22. package/src/credentials.js +123 -25
  23. package/src/events.js +174 -3
  24. package/src/forget-turn.js +141 -0
  25. package/src/host-refusal.js +78 -0
  26. package/src/index.js +209 -22
  27. package/src/jobs/host.js +557 -0
  28. package/src/ops/codes.js +110 -0
  29. package/src/ops/copy-lineage.js +42 -0
  30. package/src/ops/index.js +28 -0
  31. package/src/ops/space-ops.js +1936 -0
  32. package/src/outlinks.js +103 -0
  33. package/src/p2-reservation.js +151 -0
  34. package/src/permissions.js +30 -0
  35. package/src/plugins/descriptor.js +62 -0
  36. package/src/plugins/discovery.js +318 -0
  37. package/src/plugins/grants.js +178 -0
  38. package/src/plugins/locate.js +319 -0
  39. package/src/plugins/manifest.js +1162 -0
  40. package/src/plugins/source-contract/index.js +34 -0
  41. package/src/plugins/source-contract/policy.js +102 -0
  42. package/src/plugins/source-contract/vendor/PROVENANCE.json +17 -0
  43. package/src/plugins/source-contract/vendor/RELEASE-SHA256SUMS +3 -0
  44. package/src/plugins/source-contract/vendor/RELEASE.json +17 -0
  45. package/src/plugins/source-contract/vendor/SHA256SUMS +41 -0
  46. package/src/plugins/source-contract/vendor/THIRD-PARTY-NOTICES.md +35 -0
  47. package/src/plugins/source-contract/vendor/broker-client.js +93 -0
  48. package/src/plugins/source-contract/vendor/chunks/chunk-3M5PAKSS.js +84 -0
  49. package/src/plugins/source-contract/vendor/chunks/chunk-4ERCA4TK.js +185 -0
  50. package/src/plugins/source-contract/vendor/chunks/chunk-6HDIB2SA.js +183 -0
  51. package/src/plugins/source-contract/vendor/chunks/chunk-ELPJD3ND.js +10 -0
  52. package/src/plugins/source-contract/vendor/chunks/chunk-HLVAKAYG.js +10 -0
  53. package/src/plugins/source-contract/vendor/chunks/chunk-I2RXJJJM.js +81 -0
  54. package/src/plugins/source-contract/vendor/chunks/chunk-KWEWSZ4V.js +505 -0
  55. package/src/plugins/source-contract/vendor/chunks/chunk-KYWBTAF4.js +182 -0
  56. package/src/plugins/source-contract/vendor/chunks/chunk-Q3RQA5J2.js +249 -0
  57. package/src/plugins/source-contract/vendor/chunks/chunk-RRUAIQ4I.js +156 -0
  58. package/src/plugins/source-contract/vendor/chunks/chunk-RYNKNCPP.js +165 -0
  59. package/src/plugins/source-contract/vendor/chunks/chunk-W5SHR7DQ.js +9477 -0
  60. package/src/plugins/source-contract/vendor/chunks/chunk-ZUKF7P6U.js +653 -0
  61. package/src/plugins/source-contract/vendor/cursor.js +26 -0
  62. package/src/plugins/source-contract/vendor/descriptor.js +34 -0
  63. package/src/plugins/source-contract/vendor/events.js +257 -0
  64. package/src/plugins/source-contract/vendor/index.js +10 -0
  65. package/src/plugins/source-contract/vendor/params.js +22 -0
  66. package/src/plugins/source-contract/vendor/permission.js +28 -0
  67. package/src/plugins/source-contract/vendor/pick.js +22 -0
  68. package/src/plugins/source-contract/vendor/read.js +29 -0
  69. package/src/plugins/source-contract/vendor/registry.js +23 -0
  70. package/src/plugins/source-contract/vendor/schema.js +17 -0
  71. package/src/plugins/source-contract/vendor/schemas/output.agenda.json +96 -0
  72. package/src/plugins/source-contract/vendor/schemas/output.countdown.json +28 -0
  73. package/src/plugins/source-contract/vendor/schemas/output.image.json +28 -0
  74. package/src/plugins/source-contract/vendor/schemas/output.inbox.json +84 -0
  75. package/src/plugins/source-contract/vendor/schemas/output.links.json +46 -0
  76. package/src/plugins/source-contract/vendor/schemas/output.list.json +57 -0
  77. package/src/plugins/source-contract/vendor/schemas/output.metric.json +61 -0
  78. package/src/plugins/source-contract/vendor/schemas/output.note.json +14 -0
  79. package/src/plugins/source-contract/vendor/schemas/output.progress.json +50 -0
  80. package/src/plugins/source-contract/vendor/schemas/output.record.json +38 -0
  81. package/src/plugins/source-contract/vendor/schemas/output.table.json +61 -0
  82. package/src/plugins/source-contract/vendor/schemas/output.thread.json +62 -0
  83. package/src/plugins/source-contract/vendor/schemas/sources.json +819 -0
  84. package/src/plugins/source-contract/vendor/schemas.js +19 -0
  85. package/src/plugins/source-contract/vendor/tools-rpc.js +42 -0
  86. package/src/plugins/verify.js +56 -0
  87. package/src/protocol.js +11 -6
  88. package/src/recall.js +92 -5
  89. package/src/records.js +61 -2
  90. package/src/requests.js +216 -0
  91. package/src/runtime.js +89 -7
  92. package/src/setup-time.js +68 -0
  93. package/src/skills.js +230 -8
  94. package/src/source-ids.js +25 -0
  95. package/src/sources/declaration.js +365 -0
  96. package/src/sources/reads.js +772 -0
  97. package/src/sources/rpc.js +151 -0
  98. package/src/sources.js +389 -92
  99. package/src/spaces.js +283 -11
  100. package/src/spool.js +61 -4
  101. package/src/stated.js +10 -5
  102. package/src/storable.js +139 -0
  103. package/src/tools/commitments.js +74 -23
  104. package/src/tools/held-write.js +46 -19
  105. package/src/tools/index.js +28 -0
  106. package/src/tools/ingest.js +38 -2
  107. package/src/tools/memory.js +56 -25
  108. package/src/tools/page.js +212 -95
  109. package/src/tools/recall.js +218 -4
  110. package/src/tools/share.js +42 -3
  111. package/src/tools/shared.js +84 -6
  112. package/src/tools/space-lifecycle.js +278 -0
  113. package/src/tools/spaces.js +381 -30
  114. package/src/tools/status.js +9 -2
  115. package/src/tools/wiki.js +231 -116
  116. package/src/util.js +110 -6
  117. package/src/vendor/source-contract/README.md +24 -0
  118. package/src/vendor/source-contract/THIRD-PARTY-NOTICES.md +35 -0
  119. package/src/vendor/source-contract/VENDOR.json +81 -0
  120. package/src/vendor/source-contract/chunks/chunk-3M5PAKSS.js +84 -0
  121. package/src/vendor/source-contract/chunks/chunk-6HDIB2SA.js +183 -0
  122. package/src/vendor/source-contract/chunks/chunk-HLVAKAYG.js +10 -0
  123. package/src/vendor/source-contract/chunks/chunk-I2RXJJJM.js +81 -0
  124. package/src/vendor/source-contract/chunks/chunk-KWEWSZ4V.js +505 -0
  125. package/src/vendor/source-contract/chunks/chunk-W5SHR7DQ.js +9477 -0
  126. package/src/vendor/source-contract/chunks/chunk-ZUKF7P6U.js +653 -0
  127. package/src/vendor/source-contract/cursor.js +26 -0
  128. package/src/vendor/source-contract/events.js +257 -0
  129. package/src/vendor/source-contract/registry.js +23 -0
  130. package/src/vendor/source-contract/tools-rpc.js +42 -0
  131. package/src/views/access-reads.js +256 -0
  132. package/src/views/communities.js +77 -0
  133. package/src/views/contracts.js +1082 -23
  134. package/src/views/inbox-bytes.js +103 -0
  135. package/src/views/profile.js +31 -0
  136. package/src/views/receipt.js +26 -1
  137. package/src/views/records-reads.js +520 -41
  138. package/src/views/rpc.js +153 -25
  139. package/src/views/shape.js +8 -5
  140. package/src/views/write-state.js +89 -0
  141. package/src/wiki-ingest.js +215 -0
  142. package/src/wiki-state.js +228 -0
  143. package/views/pages.html +2 -2
@@ -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. */
@@ -233,7 +234,7 @@ export function createCoreForget(toolkit) {
233
234
  if (notRemoved.length > 0) lines.push(`Kept the text of ${notRemoved.join(", ")}, but the atom was not removed from the core, so recall may still show it.`)
234
235
  if (keep.left.length > 0) {
235
236
  const list = keep.left.map((id) => oneLine(id, 80)).join(", ")
236
- lines.push(`Not replaced: ${list}. ${keep.left.length === 1 ? "Its" : "Their"} text could not be kept as history, so ${keep.left.length === 1 ? "it stays" : "they stay"} and recall may still show ${keep.left.length === 1 ? "it" : "them"}. Removing ${keep.left.length === 1 ? "it" : "them"} is a forget: ask the person first.`)
237
+ lines.push(`Not replaced: ${list}. ${keep.left.length === 1 ? "Its" : "Their"} text could not be kept as history, so ${keep.left.length === 1 ? "it stays" : "they stay"} and recall may still show ${keep.left.length === 1 ? "it" : "them"}. Removing ${keep.left.length === 1 ? "it" : "them"} is a forget: only on the person's request, never as a tidy-up.`)
237
238
  }
238
239
  lines.push("Captured turns that mention the old value stay as history.")
239
240
  return lines.join(" ")
@@ -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 text(refusal)
912
+ if (refusal) return refuse(refusal)
908
913
  if (content.length > MAX_CONTENT_CHARS) {
909
- return text(
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 text(`not stored: kind must be one of ${KINDS.join(", ")}.`)
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 text(whyRefusal.replace(/^Nothing was stored: /, "Nothing was stored (why): "))
922
- return text(`not stored (why): ${whyRefusal.replace(/^not stored: /, "")}`)
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 text(`not stored: links takes at most ${MAX_LINKS} paths or ids.`)
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 text(`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.`)
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 text(`not stored: supersedes takes at most ${MAX_SUPERSEDES} ids; to remove more, use mem_revise forget.`)
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 text(
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 text(`not stored: ${task.invalid}`)
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 text(resolved.invalid)
954
- if (resolved.error) return fail(resolved.error)
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 fail(errorMessage(error))
1008
+ if (error?.outcomeUnknown) return failedCall(errorMessage(error))
1004
1009
  const refused = notWritten(error, "stored")
1005
- if (refused) return text(refused)
1010
+ if (refused) return refuse(refused)
1006
1011
  if (error instanceof RecordsError && error.code === "not_found") {
1007
- return text(`not confirmed: ${oneLine(error.what, 200).replace(/^[^:]+: /, "")}. Supersedes takes rec_ ids that mem_recall or mem_remember returned.`)
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 fail("the records service answered without a record id; the memory may not be stored. Check with mem_recall before writing it again.")
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 withReceipt(text(lines.join("\n")), writeReceipt("remember", { record: stored, space: spaceOf(spaceContext) }))
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
  }
@@ -1049,7 +1057,7 @@ export function registerRemember(editor, toolkit) {
1049
1057
  * @param {ReturnType<import("./shared.js").createToolkit>} toolkit
1050
1058
  */
1051
1059
  export function registerRevise(editor, toolkit) {
1052
- const { text, fail, log, scope, scopeFor, resolveReadSpace, assertTeamWrite, gateWrite, displayScope, taskFor, forgetLocations } = toolkit
1060
+ const { text, fail, log, runtime, scope, scopeFor, resolveReadSpace, assertTeamWrite, gateWrite, displayScope, taskFor, forgetLocations } = toolkit
1053
1061
  /**
1054
1062
  * The space a revise acts in: where this process last saw the id (recall,
1055
1063
  * remember, page), else the session's (personal, or a bound shared one).
@@ -1086,7 +1094,7 @@ export function registerRevise(editor, toolkit) {
1086
1094
  editor.add({
1087
1095
  name: "revise",
1088
1096
  description:
1089
- "Change memories by their ids (rec_… from mem_remember or mem_recall). Call it when the person says a memory changed or is wrong, or you find it so. correct writes a successor; confirm, retire, restore and history manage its lifecycle. To clean up many, list them with mem_recall's filter, retire them (restore undoes it), and forget only what the person asks to forget. forget deletes the record and its history and checks a bounded subset for copies; it cannot establish complete erasure. When the person asked you to forget it, the request is their consent. When you propose a deletion yourself (including a whole turn), ask the person first, and obtain separate consent before deleting it. Shared revisions follow the host permission policy, which may prompt or allow silently. Never put status, instructions, email addresses or local paths in content.",
1097
+ "Change memories by their ids (rec_… from mem_remember or mem_recall). Call it when the person says a memory changed or is wrong, or you find it so. correct writes a successor; confirm, retire, restore and history manage its lifecycle. To clean up many, list them with mem_recall's filter, retire them (restore undoes it), and forget only what the person asks to forget. forget deletes the record and its history and checks a bounded subset for copies; it cannot establish complete erasure. When the person asked you to forget it, the request is their consent. When you propose a deletion yourself (including a whole turn), report it, never tidy it up, and delete only on their request. Shared revisions follow the host permission policy, which may prompt or allow silently. Never put status, instructions, email addresses or local paths in content.",
1090
1098
  input: {
1091
1099
  type: "object",
1092
1100
  properties: {
@@ -1228,7 +1236,7 @@ export function registerRevise(editor, toolkit) {
1228
1236
  const scan = await createCoreForget(toolkit).scanCopies({ texts: [factOf(old)], spaceContext, base })
1229
1237
  const atoms = scan.copies.filter((row) => row.layer === "l1")
1230
1238
  correctionWarning = atoms.length
1231
- ? `Possible stale/conflicting atoms remain and may appear in recall (heuristic candidates, not verified lineage): ${atoms.map((row) => `${oneLine(row.id, 80)}: ${JSON.stringify(oneLine(row.content, 300))}`).join("; ")}. Leave them unless the person asks: removing one is a forget, so ask first.`
1239
+ ? `Possible stale/conflicting atoms remain and may appear in recall (heuristic candidates, not verified lineage): ${atoms.map((row) => `${oneLine(row.id, 80)}: ${JSON.stringify(oneLine(row.content, 300))}`).join("; ")}. Leave them unless the person asks: removing one is a forget, so only on their request, never as a tidy-up.`
1232
1240
  : "Old atoms and turns may still appear in recall; provenance and the bounded scan cannot rule out stale conflicts."
1233
1241
  if (scan.windows.some((window) => !window.listing.complete)) correctionWarning += " The core scan was incomplete."
1234
1242
  } catch (error) {
@@ -1305,7 +1313,7 @@ export function registerRevise(editor, toolkit) {
1305
1313
  function outcomeLines(results, done, undone = "not changed") {
1306
1314
  return results.map((item) => item.ok
1307
1315
  ? `- ${oneLine(item.id, 40)}: ${done}`
1308
- : `- ${oneLine(item.id, 40)}: ${undone} (${oneLine(item.error?.code ?? "error", 40)}): ${oneLine(item.error?.message ?? "", 200)}`)
1316
+ : `- ${oneLine(item.id, 40)}: ${undone} (${oneLine(item.error?.code ?? "error", 40)}): ${oneLine(errorMessage(item.error), 200)}`)
1309
1317
  }
1310
1318
 
1311
1319
  /**
@@ -1457,13 +1465,15 @@ export function registerRevise(editor, toolkit) {
1457
1465
  }
1458
1466
 
1459
1467
  let gone = []
1468
+ // A delete whose outcome the service did not report: the text may be gone,
1469
+ // so for capture the forget counts as done (fail closed).
1470
+ let deleteUnknown = false
1460
1471
  // Records the service refused to delete: still there by its answer, so the
1461
1472
  // read back does not report them as copies left behind.
1462
1473
  const refusedIDs = new Set()
1463
1474
  let refusedBlock = ""
1464
1475
  if (records.length > 0) {
1465
1476
  let data
1466
- let deleteUnknown = false
1467
1477
  const recordList = records.map((record) => record.id)
1468
1478
  try {
1469
1479
  // A batch forget authorises each id on its own (0.9.7); an older
@@ -1562,7 +1572,7 @@ export function registerRevise(editor, toolkit) {
1562
1572
  }
1563
1573
  // Forget, end to end on this machine: turns waiting in the spool or in
1564
1574
  // quarantine that hold the text are deleted, and later captures of this
1565
- // session (the asking turn, the next checkpoint) are masked.
1575
+ // session (the next checkpoint) are masked.
1566
1576
  for (const record of records) {
1567
1577
  if (!gone.includes(record.id)) continue
1568
1578
  purgeTexts.push(String(record.title ?? ""), factOf(record), String(record.body ?? "").replace(/^\s*why\s*:\s*/gim, ""))
@@ -1576,6 +1586,27 @@ export function registerRevise(editor, toolkit) {
1576
1586
  log.warn("forget purge failed", errorMessage(error))
1577
1587
  }
1578
1588
  }
1589
+ // The turn that asked restates the text: the person's request quotes it,
1590
+ // the answer often does, and this result can too. Masking misses a
1591
+ // paraphrase, so the turn it ran in (a subagent's runs in its parent's) is
1592
+ // not kept at all, and the exchange's captures are removed
1593
+ // (src/forget-turn.js). A delete the service did not confirm counts as
1594
+ // done here: the text may already be gone. A declined forget, or one that
1595
+ // deleted nothing, marks no turn.
1596
+ const removal = gone.length > 0 || coreGone > 0 || deleteUnknown ? await runtime?.noteForgetTurn?.(context?.sessionID) : null
1597
+ // The one instruction about the answer, whenever the text may be gone.
1598
+ if (gone.length > 0 || coreGone > 0 || deleteUnknown) parts.push("Do not repeat what was forgotten in your answer.")
1599
+ // Whether any turn was dropped, so the sentence says what happened rather
1600
+ // than what was expected (a background subagent's forget drops none).
1601
+ if (removal?.marked > 0) parts.push("This turn isn't kept where the text was restated.")
1602
+ // A copy of the turn that could not be confirmed erased: the person can
1603
+ // still ask for that turn to be removed, and only they can decide.
1604
+ if (removal?.failed > 0) parts.push("A copy of this turn could not be confirmed erased; tell the person you can remove that turn if they ask, and do it only with their consent.")
1605
+ // A turn the person steered away from, or that the host evicted, may hold
1606
+ // the text and is already kept: it is never deleted for them. The person
1607
+ // decides, through the consent path a retained turn always needs.
1608
+ const partial = context?.sessionID ? runtime?.partialTurnOf?.(context.sessionID) : null
1609
+ if (partial) parts.push("An earlier turn of this exchange may hold the text. Offer to remove it if the person wants; a kept turn is removed only with their consent.")
1579
1610
  log.info("revise forget", { records: gone.length, core: coreIDs.length, copies: copyIDs.length })
1580
1611
  parts.push("Coverage is incomplete: other agents (including a fifth or unknown agent), rows beyond 300 per layer/agent, older record versions, other users and spaces, L2/L3, wiki, backups and derived copies were not comprehensively searched. Searches use at most 20 record and 25 core hits per query and can miss paraphrases. The persona and scenarios (L2/L3) are not changed by an id forget; the person erases a phrase there on the Profile page of Memory's console.")
1581
1612
  return [parts.join(" "), refusedBlock, report].filter(Boolean).join("\n")