@joe-broadhead/opencode-mem 0.9.12 → 0.11.2
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 +1934 -2
- package/README.md +29 -17
- package/SECURITY.md +3 -1
- package/docs/agent-instructions.md +17 -0
- package/docs/agent-protocol.md +8 -8
- package/docs/permissions.md +22 -4
- package/package.json +7923 -217
- package/shared/page-paths.js +44 -0
- package/skills/mem.pages/SKILL.md +8 -1
- package/skills/mem.usage/SKILL.md +15 -15
- package/src/action-grant-keys.js +159 -0
- package/src/action-grant.js +439 -0
- package/src/actions.js +1690 -0
- package/src/backend/records.js +25 -2
- package/src/backend/v3.js +76 -22
- package/src/call-shapes.js +17 -16
- package/src/collector-lock.js +533 -62
- package/src/collector-service.js +153 -26
- package/src/collector.js +627 -33
- package/src/config.js +79 -6
- package/src/connect.js +106 -8
- package/src/credentials.js +123 -25
- package/src/events.js +174 -3
- package/src/forget-turn.js +141 -0
- package/src/host-refusal.js +78 -0
- package/src/index.js +209 -22
- package/src/jobs/host.js +557 -0
- package/src/ops/codes.js +110 -0
- package/src/ops/copy-lineage.js +42 -0
- package/src/ops/index.js +28 -0
- package/src/ops/space-ops.js +1936 -0
- package/src/outlinks.js +103 -0
- package/src/p2-reservation.js +151 -0
- package/src/permissions.js +30 -0
- package/src/plugins/descriptor.js +62 -0
- package/src/plugins/discovery.js +318 -0
- package/src/plugins/grants.js +178 -0
- package/src/plugins/locate.js +319 -0
- package/src/plugins/manifest.js +1162 -0
- package/src/plugins/source-contract/index.js +34 -0
- package/src/plugins/source-contract/policy.js +102 -0
- package/src/plugins/source-contract/vendor/PROVENANCE.json +17 -0
- package/src/plugins/source-contract/vendor/RELEASE-SHA256SUMS +3 -0
- package/src/plugins/source-contract/vendor/RELEASE.json +17 -0
- package/src/plugins/source-contract/vendor/SHA256SUMS +41 -0
- package/src/plugins/source-contract/vendor/THIRD-PARTY-NOTICES.md +35 -0
- package/src/plugins/source-contract/vendor/broker-client.js +93 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-3M5PAKSS.js +84 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-4ERCA4TK.js +185 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-6HDIB2SA.js +183 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-ELPJD3ND.js +10 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-HLVAKAYG.js +10 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-I2RXJJJM.js +81 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-KWEWSZ4V.js +505 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-KYWBTAF4.js +182 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-Q3RQA5J2.js +249 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-RRUAIQ4I.js +156 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-RYNKNCPP.js +165 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-W5SHR7DQ.js +9477 -0
- package/src/plugins/source-contract/vendor/chunks/chunk-ZUKF7P6U.js +653 -0
- package/src/plugins/source-contract/vendor/cursor.js +26 -0
- package/src/plugins/source-contract/vendor/descriptor.js +34 -0
- package/src/plugins/source-contract/vendor/events.js +257 -0
- package/src/plugins/source-contract/vendor/index.js +10 -0
- package/src/plugins/source-contract/vendor/params.js +22 -0
- package/src/plugins/source-contract/vendor/permission.js +28 -0
- package/src/plugins/source-contract/vendor/pick.js +22 -0
- package/src/plugins/source-contract/vendor/read.js +29 -0
- package/src/plugins/source-contract/vendor/registry.js +23 -0
- package/src/plugins/source-contract/vendor/schema.js +17 -0
- package/src/plugins/source-contract/vendor/schemas/output.agenda.json +96 -0
- package/src/plugins/source-contract/vendor/schemas/output.countdown.json +28 -0
- package/src/plugins/source-contract/vendor/schemas/output.image.json +28 -0
- package/src/plugins/source-contract/vendor/schemas/output.inbox.json +84 -0
- package/src/plugins/source-contract/vendor/schemas/output.links.json +46 -0
- package/src/plugins/source-contract/vendor/schemas/output.list.json +57 -0
- package/src/plugins/source-contract/vendor/schemas/output.metric.json +61 -0
- package/src/plugins/source-contract/vendor/schemas/output.note.json +14 -0
- package/src/plugins/source-contract/vendor/schemas/output.progress.json +50 -0
- package/src/plugins/source-contract/vendor/schemas/output.record.json +38 -0
- package/src/plugins/source-contract/vendor/schemas/output.table.json +61 -0
- package/src/plugins/source-contract/vendor/schemas/output.thread.json +62 -0
- package/src/plugins/source-contract/vendor/schemas/sources.json +819 -0
- package/src/plugins/source-contract/vendor/schemas.js +19 -0
- package/src/plugins/source-contract/vendor/tools-rpc.js +42 -0
- package/src/plugins/verify.js +56 -0
- package/src/protocol.js +21 -5
- package/src/recall.js +104 -5
- package/src/records.js +61 -2
- package/src/requests.js +216 -0
- package/src/runtime.js +89 -7
- package/src/setup-time.js +68 -0
- package/src/skills.js +230 -8
- package/src/source-ids.js +25 -0
- package/src/sources/declaration.js +365 -0
- package/src/sources/reads.js +772 -0
- package/src/sources/rpc.js +151 -0
- package/src/sources.js +409 -90
- package/src/spaces.js +283 -11
- package/src/spool.js +61 -4
- package/src/stated.js +10 -5
- package/src/storable.js +139 -0
- package/src/tools/commitments.js +47 -5
- package/src/tools/held-write.js +36 -13
- package/src/tools/index.js +27 -0
- package/src/tools/ingest.js +27 -2
- package/src/tools/memory.js +52 -14
- package/src/tools/page.js +95 -9
- package/src/tools/recall.js +208 -4
- package/src/tools/records-kit.js +2 -1
- package/src/tools/share.js +42 -3
- package/src/tools/shared.js +44 -4
- package/src/tools/space-lifecycle.js +278 -0
- package/src/tools/spaces.js +373 -29
- package/src/tools/status.js +9 -2
- package/src/tools/wiki.js +34 -4
- package/src/util.js +110 -6
- package/src/vendor/source-contract/README.md +24 -0
- package/src/vendor/source-contract/THIRD-PARTY-NOTICES.md +35 -0
- package/src/vendor/source-contract/VENDOR.json +81 -0
- package/src/vendor/source-contract/chunks/chunk-3M5PAKSS.js +84 -0
- package/src/vendor/source-contract/chunks/chunk-6HDIB2SA.js +183 -0
- package/src/vendor/source-contract/chunks/chunk-HLVAKAYG.js +10 -0
- package/src/vendor/source-contract/chunks/chunk-I2RXJJJM.js +81 -0
- package/src/vendor/source-contract/chunks/chunk-KWEWSZ4V.js +505 -0
- package/src/vendor/source-contract/chunks/chunk-W5SHR7DQ.js +9477 -0
- package/src/vendor/source-contract/chunks/chunk-ZUKF7P6U.js +653 -0
- package/src/vendor/source-contract/cursor.js +26 -0
- package/src/vendor/source-contract/events.js +257 -0
- package/src/vendor/source-contract/registry.js +23 -0
- package/src/vendor/source-contract/tools-rpc.js +42 -0
- package/src/views/access-reads.js +256 -0
- package/src/views/communities.js +77 -0
- package/src/views/contracts.js +1183 -36
- package/src/views/inbox-bytes.js +103 -0
- package/src/views/overdue.js +1 -1
- package/src/views/profile.js +31 -0
- package/src/views/receipt.js +81 -0
- package/src/views/records-reads.js +869 -37
- package/src/views/rpc.js +159 -11
- package/src/views/shape.js +8 -5
- package/views/memory.html +16 -3
- package/views/pages.html +2 -2
- package/views/remembered.html +130 -0
package/src/storable.js
CHANGED
|
@@ -124,6 +124,145 @@ export function redactLocalPaths(value) {
|
|
|
124
124
|
return text
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
+
// ---------------------------------------------------------------------------
|
|
128
|
+
// Error text: what a failure may say. The plugin (src/util.js) and the records
|
|
129
|
+
// service (records/src/collector text, jobs.checkpoint) both redact a source's
|
|
130
|
+
// own words with this, so a secret never reaches an answer, a log or a store.
|
|
131
|
+
// It lives here, beside `redactSecrets`, because both sides carry this file.
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* `scheme://userinfo@host`: a URL's userinfo is a credential, and Memory's own
|
|
135
|
+
* patterns (storable.js) do not cover it.
|
|
136
|
+
*/
|
|
137
|
+
const URL_USERINFO = /\b([a-z][a-z0-9+.-]*:\/\/)[^\s/?#@]*@/gi
|
|
138
|
+
/** A whole URL: scheme, authority and path kept; the query string and fragment dropped. */
|
|
139
|
+
const ERROR_URL = /\b([a-z][a-z0-9+.-]*:\/\/)([^\s/?#]*)([^\s?#]*)(?:[?#][^\s]*)?/gi
|
|
140
|
+
/** A `Cookie:` or `Set-Cookie:` header: header name kept, value dropped. */
|
|
141
|
+
const ERROR_COOKIE = /\b((?:set-)?cookie\s*:\s*)[^\r\n]+/gi
|
|
142
|
+
/** A JWT: the shape Memory's own detector knows, masked whole rather than by part. */
|
|
143
|
+
const ERROR_JWT = /\beyJ[A-Za-z0-9_-]{8,}\.eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/g
|
|
144
|
+
/** A PEM private key block, whole. */
|
|
145
|
+
const ERROR_PEM = /-----BEGIN (?:[A-Z0-9]+ )*PRIVATE KEY(?: BLOCK)?-----[\s\S]*?(?:-----END (?:[A-Z0-9]+ )*PRIVATE KEY(?: BLOCK)?-----|$)/g
|
|
146
|
+
/**
|
|
147
|
+
* The backstop's candidate: one run of 24 or more word characters (letters,
|
|
148
|
+
* digits, `_`, `-`, `+`, `/`, `=`) — the alphabet base64 secrets use, so an
|
|
149
|
+
* AWS secret key with `/` and `+` stays one run. Paths and URLs are reduced
|
|
150
|
+
* before this runs, so the `/` here is a secret's, not a directory's.
|
|
151
|
+
*/
|
|
152
|
+
const ERROR_LONG_TOKEN = /(?<![A-Za-z0-9_+/=-])[A-Za-z0-9_+/=-]{24,}(?![A-Za-z0-9_+/=-])/g
|
|
153
|
+
/** Characters of error text shown at most: enough for a cause, never a dump. */
|
|
154
|
+
export const ERROR_TEXT_MAX = 400
|
|
155
|
+
|
|
156
|
+
/** What an error says when showing its own text would risk a secret. */
|
|
157
|
+
export const ERROR_WITHHELD = "an error (details withheld: they may contain a secret)"
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* A hex run of 32 or more characters: an SHA-256 digest or a hex-encoded key,
|
|
161
|
+
* never something an error needs in full (owner decision, review F2 fourth
|
|
162
|
+
* pass). Shorter hex — a 7 to 12 character commit hash or an id — stays
|
|
163
|
+
* readable.
|
|
164
|
+
*/
|
|
165
|
+
const ERROR_HEX = /(?<![0-9A-Za-z])[0-9a-fA-F]{32,}(?![0-9A-Za-z])/g
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* When a run of characters is a secret rather than a name (review F2, third
|
|
169
|
+
* pass). Length alone cut hostnames and paths, so the rule is randomness:
|
|
170
|
+
*
|
|
171
|
+
* - **at least 24 characters** — a secret is long, and below that the entropy
|
|
172
|
+
* of a short random string is too close to prose's to judge;
|
|
173
|
+
* - **mixed classes**: at least one lowercase, one uppercase and one digit, and
|
|
174
|
+
* **at least 20% lowercase**. Base64 secrets are lowercase-dominant or
|
|
175
|
+
* balanced; a record id (`rec_` + a ULID of uppercase and digits) is 13%
|
|
176
|
+
* lowercase, a hex hash and a UUID carry no uppercase at all, so each of
|
|
177
|
+
* those stays readable;
|
|
178
|
+
* - **Shannon entropy at a length-aware cutoff: `min(4.5, log2(len) - 0.7)`
|
|
179
|
+
* bits per character** (the reviewer's rule, fourth pass). A string's
|
|
180
|
+
* entropy is capped at `log2(len)`, so a flat 4.5 missed 4% of 24-character
|
|
181
|
+
* tokens, 30% at 28 and 70% at 32; the length-aware line misses at most 5%
|
|
182
|
+
* and flags no new benign text. Measured: English words, file paths and
|
|
183
|
+
* sentences sit at 3.3–4.0 (a path with a digit, 3.9), a ULID-based record
|
|
184
|
+
* id at 4.3; random base62/base64 tokens sit at 4.2 (24 characters) to 5.0
|
|
185
|
+
* (32) and AWS secret keys at 4.7.
|
|
186
|
+
*
|
|
187
|
+
* Names can never cover every credential format; this rule covers the shapes
|
|
188
|
+
* no name knows. Memory's own detector and patterns still run first, so a
|
|
189
|
+
* named secret is caught even if this misses it.
|
|
190
|
+
*/
|
|
191
|
+
const MIXED_MIN_ENTROPY = 4.5
|
|
192
|
+
function randomToken(run) {
|
|
193
|
+
const value = String(run ?? "")
|
|
194
|
+
if (value.length < 24) return false
|
|
195
|
+
// A short string cannot reach 4.5 bits per character: the ceiling is log2(len).
|
|
196
|
+
const cutoff = Math.min(MIXED_MIN_ENTROPY, Math.log2(value.length) - 0.7)
|
|
197
|
+
const lower = (value.match(/[a-z]/g) ?? []).length
|
|
198
|
+
const upper = (value.match(/[A-Z]/g) ?? []).length
|
|
199
|
+
if (lower === 0 || upper === 0 || !/\d/.test(value)) return false
|
|
200
|
+
if (lower / value.length < 0.2) return false
|
|
201
|
+
return entropyOf(value) >= cutoff
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** A URL's path, kept segment by segment: a part masked only when it alone is a secret by `randomToken`. */
|
|
205
|
+
function maskPath(path) {
|
|
206
|
+
if (!path) return path
|
|
207
|
+
const segments = path.split("/")
|
|
208
|
+
// A secret may hold `/` itself (an AWS secret key), so the path's characters
|
|
209
|
+
// are judged together first; only then is each segment judged alone.
|
|
210
|
+
const joined = segments.join("")
|
|
211
|
+
if (randomToken(joined)) return "/[redacted]"
|
|
212
|
+
return segments.map((segment) => (randomToken(segment) ? "[redacted]" : segment)).join("/")
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** Shannon entropy, in bits per character. */
|
|
216
|
+
function entropyOf(text) {
|
|
217
|
+
const counts = new Map()
|
|
218
|
+
for (const char of text) counts.set(char, (counts.get(char) ?? 0) + 1)
|
|
219
|
+
let bits = 0
|
|
220
|
+
for (const count of counts.values()) {
|
|
221
|
+
const p = count / text.length
|
|
222
|
+
bits -= p * Math.log2(p)
|
|
223
|
+
}
|
|
224
|
+
return bits
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/** A URL's authority with any userinfo masked, so `user:pass@host` keeps only the host. */
|
|
228
|
+
function maskAuthority(authority) {
|
|
229
|
+
const at = authority.lastIndexOf("@")
|
|
230
|
+
return at < 0 ? authority : `[redacted]@${authority.slice(at + 1)}`
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Text from a failure, safe to show in a tool answer or a console report
|
|
235
|
+
* (0.10.3 gate A15; review F2). A plugin source's thrown value is third-party
|
|
236
|
+
* data, so this is a sanitiser, not a formatter:
|
|
237
|
+
*
|
|
238
|
+
* 1. a PEM private key block becomes `[redacted-private-key]`, and a hex run
|
|
239
|
+
* of 32+ characters becomes `[redacted]` (a digest is no help in an error);
|
|
240
|
+
* 2. every URL keeps its scheme, host and path — userinfo is masked and the
|
|
241
|
+
* query string and fragment are dropped, which covers a signed URL's
|
|
242
|
+
* signature and any `..._token=`, `key=` or `code=` parameter;
|
|
243
|
+
* 3. a `Cookie:` or `Set-Cookie:` header's value becomes `[redacted]`;
|
|
244
|
+
* 4. Memory's own secret patterns run (`redactSecrets`, src/storable.js);
|
|
245
|
+
* 5. the backstop: a run of 24+ word characters that mixes letters and digits
|
|
246
|
+
* at random-token entropy becomes `[redacted]` — names cover only the
|
|
247
|
+
* formats someone thought of, and this is the rule for the rest.
|
|
248
|
+
*
|
|
249
|
+
* The result is capped at `ERROR_TEXT_MAX`. `errorMessage` then asks Memory's
|
|
250
|
+
* own store detector (`secretKinds`) whether anything is still secret, and
|
|
251
|
+
* withholds the whole message when it is.
|
|
252
|
+
*/
|
|
253
|
+
export function redactErrorText(value) {
|
|
254
|
+
let text = String(value ?? "")
|
|
255
|
+
.replace(ERROR_PEM, "[redacted-private-key]")
|
|
256
|
+
.replace(ERROR_HEX, "[redacted]")
|
|
257
|
+
.replace(ERROR_URL, (_match, scheme, authority, path) => `${scheme}${maskAuthority(authority)}${maskPath(path)}`)
|
|
258
|
+
text = text.replace(ERROR_COOKIE, "$1[redacted]").replace(ERROR_JWT, "[redacted-jwt]")
|
|
259
|
+
// Memory's patterns before the backstop: a JWT's three dot-separated parts
|
|
260
|
+
// must match whole, which the backstop's runs would break apart.
|
|
261
|
+
text = redactSecrets(text).replace(URL_USERINFO, "$1[redacted]@")
|
|
262
|
+
text = text.replace(ERROR_LONG_TOKEN, (run) => (randomToken(run) ? "[redacted]" : run))
|
|
263
|
+
return text.length > ERROR_TEXT_MAX ? `${text.slice(0, ERROR_TEXT_MAX - 1)}…` : text
|
|
264
|
+
}
|
|
265
|
+
|
|
127
266
|
// ---------------------------------------------------------------------------
|
|
128
267
|
// Detection for storage.
|
|
129
268
|
|
package/src/tools/commitments.js
CHANGED
|
@@ -8,12 +8,16 @@ import {
|
|
|
8
8
|
formatDue,
|
|
9
9
|
itemLine,
|
|
10
10
|
newCommitmentId,
|
|
11
|
+
openNowSummary,
|
|
11
12
|
similarOpen,
|
|
12
13
|
validateDue,
|
|
13
14
|
validateFields,
|
|
14
15
|
} from "../records.js"
|
|
15
16
|
import { dueStated, holdsWord, tiedWords, triggerStated } from "../stated.js"
|
|
17
|
+
import { latestWord } from "../requests.js"
|
|
16
18
|
import { errorMessage, oneLine } from "../util.js"
|
|
19
|
+
import { withReceipt, writeReceipt } from "../views/receipt.js"
|
|
20
|
+
import { spaceOf } from "../views/shape.js"
|
|
17
21
|
|
|
18
22
|
/**
|
|
19
23
|
* Drop a due date or a trigger the person did not state (0.9.9, WRITES-099):
|
|
@@ -215,8 +219,16 @@ export function registerCommitments(editor, toolkit) {
|
|
|
215
219
|
if (personal.outcome === "refuse") return text(personal.message.replace(/^not stored/, "not saved"))
|
|
216
220
|
if (personal.outcome === "warn") warning = personal.message
|
|
217
221
|
// A due date or trigger is kept only when the person's messages name it
|
|
218
|
-
// (0.9.9, WRITES-099)
|
|
219
|
-
|
|
222
|
+
// (0.9.9, WRITES-099; 0.11 gate H2). A call with no call id — a host's
|
|
223
|
+
// press in a fresh session — is checked exactly as 0.11.0 checked it:
|
|
224
|
+
// with a person message noted the field must be theirs; with none noted
|
|
225
|
+
// it is kept. A model's call with no noted prompt fails closed, and so
|
|
226
|
+
// does a session the host cannot place (an agent's brief). The words are
|
|
227
|
+
// the request guards' source (src/requests.js).
|
|
228
|
+
await toolkit.ensureSession?.(context?.sessionID)
|
|
229
|
+
const said = latestWord(runtime, context?.sessionID, context)
|
|
230
|
+
const personMessages = said.brief || (said.model && !said.seen) ? [{ text: "", at: 0 }] : said.seen ? (runtime.personSaid?.(context?.sessionID) ?? []) : []
|
|
231
|
+
const unstated = keepStated(fields, personMessages, zone, runtime.personDrops?.(context?.sessionID))
|
|
220
232
|
if (action === "update" && Object.keys(fields).length === 0) {
|
|
221
233
|
if (unstated.length > 0) return text(`not updated: ${unstated.join(" ")}`)
|
|
222
234
|
return text("nothing to update: pass state, what, owner, due, trigger, project, or link")
|
|
@@ -242,12 +254,35 @@ export function registerCommitments(editor, toolkit) {
|
|
|
242
254
|
log.info("commitments", { action, rounds: result.rounds, unchanged: Boolean(result.unchanged) })
|
|
243
255
|
|
|
244
256
|
if (action === "add" && result.unchanged) {
|
|
245
|
-
|
|
257
|
+
// A duplicate changed nothing (0.10.3 gate, B13): say so plainly, and
|
|
258
|
+
// tag the record in the list as the one that was already open.
|
|
259
|
+
return text(
|
|
260
|
+
[
|
|
261
|
+
`already open, so nothing was added: ${describe(result.item, zone)}`,
|
|
262
|
+
dropped,
|
|
263
|
+
openNowSummary(result.records?.items, today, zone, { mark: { id: result.item.id, label: "already open, nothing added" } }),
|
|
264
|
+
]
|
|
265
|
+
.filter(Boolean)
|
|
266
|
+
.join("\n"),
|
|
267
|
+
)
|
|
268
|
+
}
|
|
269
|
+
if (action === "delete") {
|
|
270
|
+
return text(
|
|
271
|
+
[
|
|
272
|
+
`deleted ${oneLine(result.item.id || id, 40)}: ${oneLine(result.item.what, 300)}. It is gone from this space's records.`,
|
|
273
|
+
openNowSummary(result.records?.items, today, zone),
|
|
274
|
+
].join("\n"),
|
|
275
|
+
)
|
|
246
276
|
}
|
|
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.`)
|
|
248
277
|
const verb = action === "add" ? "added" : "updated"
|
|
249
278
|
const lines = [`${verb} ${describe(result.item, zone)}`]
|
|
250
279
|
if (dropped) lines.push(dropped)
|
|
280
|
+
// What is open now, from the same scope `list` reads (0.10.0 gate, H2).
|
|
281
|
+
// A new record is tagged as new (0.10.3 gate, B1 and B13): the list
|
|
282
|
+
// otherwise reads like a record that was already there.
|
|
283
|
+
lines.push(
|
|
284
|
+
openNowSummary(result.records?.items, today, zone, action === "add" ? { mark: { id: result.item.id, label: "just added" } } : {}),
|
|
285
|
+
)
|
|
251
286
|
if (action === "add") {
|
|
252
287
|
const similar = similarOpen(result.records?.items, result.item.what, result.item.id)
|
|
253
288
|
if (similar.length > 0) {
|
|
@@ -263,7 +298,14 @@ export function registerCommitments(editor, toolkit) {
|
|
|
263
298
|
}
|
|
264
299
|
if (warning) lines.push(warning)
|
|
265
300
|
if (result.item.state !== "open") lines.push(`Closed items are kept ${CLOSED_RETENTION_DAYS} days, then dropped.`)
|
|
266
|
-
|
|
301
|
+
// Only a new commitment answers a receipt: an update changes a record the
|
|
302
|
+
// turn did not save, and a list or a delete saves nothing. A commitment
|
|
303
|
+
// record's kind and type are fixed by the contract and its open/closed
|
|
304
|
+
// state lives in `fields.state`, so `status` is the record's own.
|
|
305
|
+
const receipt = action === "add"
|
|
306
|
+
? writeReceipt("commit", { record: { ...result.item, kind: "commitment", type: "commitment", status: "current", title: result.item.what }, space: spaceOf(where.spaceContext) })
|
|
307
|
+
: undefined
|
|
308
|
+
return withReceipt(text(lines.join("\n")), receipt)
|
|
267
309
|
},
|
|
268
310
|
})
|
|
269
311
|
}
|
package/src/tools/held-write.js
CHANGED
|
@@ -4,6 +4,9 @@ import { oneLine, redactSecrets } from "../util.js"
|
|
|
4
4
|
import { callRecords, RECORD_ID } from "./records-kit.js"
|
|
5
5
|
import { writeCallRoot } from "../backend/records.js"
|
|
6
6
|
|
|
7
|
+
/** The title a held write is stored under, which the preview replaces with its own words. */
|
|
8
|
+
export const HELD_WRITE_TITLE = "Team write awaiting approval"
|
|
9
|
+
|
|
7
10
|
const hash = (value) => createHash("sha256").update(value).digest("hex")
|
|
8
11
|
const SPACE = /^[A-Za-z0-9_.-]{1,128}$/
|
|
9
12
|
|
|
@@ -35,9 +38,13 @@ export async function holdTeamWrite(toolkit, context, spaceContext, records) {
|
|
|
35
38
|
const content = String(records[0]?.body ?? "")
|
|
36
39
|
const preview = oneLine(redactSecrets(content), 400)
|
|
37
40
|
const record = {
|
|
38
|
-
kind: "proposal", type: "team_write", title:
|
|
41
|
+
kind: "proposal", type: "team_write", title: HELD_WRITE_TITLE, body: JSON.stringify({ records }),
|
|
39
42
|
fields: { space_id: spaceContext.space_id, space_name: oneLine(spaceContext.space_name, 200), preview, key: idempotencyKey },
|
|
40
|
-
source:
|
|
43
|
+
source: {
|
|
44
|
+
...(context?.sessionID ? { session: String(context.sessionID) } : {}),
|
|
45
|
+
// The turn that made it (#58 F4), so a review row says which message waits.
|
|
46
|
+
...(context?.messageID ? { turn: String(context.messageID) } : {}),
|
|
47
|
+
},
|
|
41
48
|
}
|
|
42
49
|
const answer = await callRecords(toolkit, "records.put", { record, idempotency_key: idempotencyKey }, personal, scoped)
|
|
43
50
|
if (!RECORD_ID.test(String(answer?.record?.id ?? ""))) throw new Error("the records service did not confirm the proposal")
|
|
@@ -71,20 +78,36 @@ export async function decideProposal({ key, decision, caller }) {
|
|
|
71
78
|
if (proposal.author?.user !== personal.user_id) throw new Error("only the proposal's author can decide")
|
|
72
79
|
let shared
|
|
73
80
|
if (decision === "accept" && ["proposed", "accepting"].includes(proposal.status)) {
|
|
74
|
-
shared = await runtime
|
|
75
|
-
if (shared?.space_id !== proposal.fields.space_id || shared?.space_kind !== "shared" || shared?.user_id !== personal.user_id || !["editor", "admin", "owner"].includes(String(shared.role ?? "").toLowerCase())) throw new Error("the author no longer has write access to the target shared space")
|
|
81
|
+
shared = await sharedFor(runtime, personal, proposal)
|
|
76
82
|
}
|
|
77
|
-
|
|
83
|
+
const answer = await runtime.recordsClient.call("review.decide", { id, decision, base_version: proposal.version }, options)
|
|
78
84
|
const held = answer?.proposal
|
|
79
85
|
if (decision !== "accept" || held?.status !== "accepting") return answer
|
|
80
86
|
if (!shared) throw new Error("the shared space was not verified")
|
|
81
|
-
|
|
82
|
-
const stats = await runtime.recordsClient.call("space.stats", {}, target)
|
|
83
|
-
if (stats?.held_receipts !== true) throw new Error("the shared records service cannot verify held acceptance")
|
|
84
|
-
const records = JSON.parse(held.body).records
|
|
85
|
-
const written = await runtime.recordsClient.call("records.put", { held_batch: { key: held.fields.accept_key, records } }, target)
|
|
86
|
-
if (typeof written?.receipt !== "string") throw new Error("the shared write was not confirmed; retry acceptance")
|
|
87
|
-
answer = await runtime.recordsClient.call("review.decide", { id, decision: "accept", base_version: held.version, receipt: written.receipt }, options)
|
|
88
|
-
return answer
|
|
87
|
+
return completeHeldWrite({ runtime, space, id, held, shared })
|
|
89
88
|
})
|
|
90
89
|
}
|
|
90
|
+
|
|
91
|
+
/** The shared space a held write is meant for, if this author may still write it. */
|
|
92
|
+
async function sharedFor(runtime, personal, proposal) {
|
|
93
|
+
const shared = await runtime.resolveContext({ space: proposal.fields.space_id })
|
|
94
|
+
if (shared?.space_id !== proposal.fields.space_id || shared?.space_kind !== "shared" || shared?.user_id !== personal.user_id || !["editor", "admin", "owner"].includes(String(shared.role ?? "").toLowerCase())) throw new Error("the author no longer has write access to the target shared space")
|
|
95
|
+
return shared
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The second half of an accept, and the one copy of it: the author's editor
|
|
100
|
+
* right is re-checked, the held batch is written to the shared cell with its
|
|
101
|
+
* signed receipt, and the proposal is completed to `applied`. The act path
|
|
102
|
+
* (inbox.decide, review.decide) reaches the same `accepting` state records
|
|
103
|
+
* answers, and calls this with the proposal as it read it back.
|
|
104
|
+
*/
|
|
105
|
+
export async function completeHeldWrite({ runtime, space, id, held, shared }) {
|
|
106
|
+
const target = { space: shared.space_id }
|
|
107
|
+
const stats = await runtime.recordsClient.call("space.stats", {}, target)
|
|
108
|
+
if (stats?.held_receipts !== true) throw new Error("the shared records service cannot verify held acceptance")
|
|
109
|
+
const records = JSON.parse(held.body).records
|
|
110
|
+
const written = await runtime.recordsClient.call("records.put", { held_batch: { key: held.fields.accept_key, records } }, target)
|
|
111
|
+
if (typeof written?.receipt !== "string") throw new Error("the shared write was not confirmed; retry acceptance")
|
|
112
|
+
return runtime.recordsClient.call("review.decide", { id, decision: "accept", base_version: held.version, receipt: written.receipt }, { space })
|
|
113
|
+
}
|
package/src/tools/index.js
CHANGED
|
@@ -2,6 +2,8 @@ import { MEM_NAMESPACE_DESCRIPTION, PINNED_TOOLS, WIKI_DOCUMENTS_NOTE, WRITE_ACT
|
|
|
2
2
|
import { asSession, asVerifiedSession } from "../credentials.js"
|
|
3
3
|
import { withWriteCall } from "../backend/records.js"
|
|
4
4
|
import { createCollectorService } from "../collector-service.js"
|
|
5
|
+
import { createPluginDiscovery } from "../plugins/discovery.js"
|
|
6
|
+
import { createJobHost } from "../jobs/host.js"
|
|
5
7
|
import { createToolkit } from "./shared.js"
|
|
6
8
|
import { registerWiki } from "./wiki.js"
|
|
7
9
|
import { registerShare } from "./share.js"
|
|
@@ -37,6 +39,17 @@ export async function registerTools(ctx, runtime, { core = CORE_TOOLS } = {}) {
|
|
|
37
39
|
if (!runtime.config.tools) return null
|
|
38
40
|
const toolkit = createToolkit(ctx, runtime)
|
|
39
41
|
toolkit.collector = createCollectorService({ ctx, runtime, toolkit })
|
|
42
|
+
// Plugin declarations (DESIGN-PLUGIN-MEMORY S1): read-only discovery and a
|
|
43
|
+
// report to the records service. It changes nothing the collector does.
|
|
44
|
+
toolkit.plugins = createPluginDiscovery({ ctx, runtime, toolkit })
|
|
45
|
+
runtime.onPluginsChanged = (type) => toolkit.plugins.changed(type)
|
|
46
|
+
// Memory Jobs' host (DESIGN-MEMORY-JOBS §3.2): the extract stage, in this
|
|
47
|
+
// process, beside the connector plugins and their sign-ins. It starts below
|
|
48
|
+
// with the collector's timer, behind the same switch: `collect: false` is a
|
|
49
|
+
// host that claims nothing.
|
|
50
|
+
toolkit.jobHost = createJobHost({ ctx, runtime, toolkit })
|
|
51
|
+
// Health and the tests read it here, as they read the collector.
|
|
52
|
+
runtime.jobHost = toolkit.jobHost
|
|
40
53
|
const tools = await ctx.tool.transform((editor) => {
|
|
41
54
|
editor.namespace({ name: "mem", description: MEM_NAMESPACE_DESCRIPTION })
|
|
42
55
|
buildToolset(gateEditor(editor, runtime), toolkit, core)
|
|
@@ -54,8 +67,22 @@ export async function registerTools(ctx, runtime, { core = CORE_TOOLS } = {}) {
|
|
|
54
67
|
} catch (error) {
|
|
55
68
|
runtime.log?.warn?.("the collector could not start", error)
|
|
56
69
|
}
|
|
70
|
+
try {
|
|
71
|
+
toolkit.plugins.start()
|
|
72
|
+
} catch (error) {
|
|
73
|
+
runtime.log?.warn?.("plugin discovery could not start", error)
|
|
74
|
+
}
|
|
75
|
+
// The job host's heartbeat is behind the collector's own switch: one switch
|
|
76
|
+
// turns off everything Memory does in the background in this process.
|
|
77
|
+
try {
|
|
78
|
+
if (runtime.config.collect) toolkit.jobHost.start()
|
|
79
|
+
} catch (error) {
|
|
80
|
+
runtime.log?.warn?.("the job host could not start", error)
|
|
81
|
+
}
|
|
57
82
|
return {
|
|
58
83
|
dispose: async () => {
|
|
84
|
+
await toolkit.jobHost.stop()
|
|
85
|
+
await toolkit.plugins.stop()
|
|
59
86
|
await toolkit.collector.stop()
|
|
60
87
|
await tools?.dispose?.()
|
|
61
88
|
await command?.dispose?.()
|
package/src/tools/ingest.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { describeResult } from "../collector-service.js"
|
|
2
|
+
import { asksToCollect, latestWord, mustRefuse } from "../requests.js"
|
|
3
|
+
import { errorMessage } from "../util.js"
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* 0.9.7 (security review of audit tools #4): `mem_ingest` and `mem_cursor` are
|
|
@@ -83,6 +85,13 @@ export function registerIngest(editor, _toolkit) {
|
|
|
83
85
|
})
|
|
84
86
|
}
|
|
85
87
|
|
|
88
|
+
/**
|
|
89
|
+
* The answer a collect gets when the person's own latest message did not ask
|
|
90
|
+
* for one. The words are the ones a person uses to ask; the agent repeats
|
|
91
|
+
* them, so nothing happens this turn (0.10.6 gate, life-inject-chain-email #4).
|
|
92
|
+
*/
|
|
93
|
+
const COLLECT_NEEDS_REQUEST = "Collecting needs your request. Offer it: say 'collect my mail now' and I will pull the latest from your sources."
|
|
94
|
+
|
|
86
95
|
/**
|
|
87
96
|
* `mem_collect`: collect now. For routines (Jelly's `collect` routine calls
|
|
88
97
|
* `await tools.mem.collect({})` and then returns false) and the person's
|
|
@@ -91,6 +100,13 @@ export function registerIngest(editor, _toolkit) {
|
|
|
91
100
|
* as the timer (src/collector-service.js), and its counts appear in
|
|
92
101
|
* `mem_spaces` health; `wait: true` waits up to 25 seconds and reports them.
|
|
93
102
|
*
|
|
103
|
+
* 0.10.6 gate H3: the description said "only for routines and the person's
|
|
104
|
+
* explicit request" and an agent collected from Gmail while answering a
|
|
105
|
+
* question about an email. The check is here, in code: with a person message
|
|
106
|
+
* in the session, the latest one must ask (src/requests.js). A routine turn
|
|
107
|
+
* has none, so the routine path is unchanged, and so is a host that runs no
|
|
108
|
+
* prompt hook.
|
|
109
|
+
*
|
|
94
110
|
* @param {any} editor
|
|
95
111
|
* @param {ReturnType<import("./shared.js").createToolkit>} toolkit
|
|
96
112
|
*/
|
|
@@ -119,6 +135,13 @@ export function registerCollect(editor, toolkit) {
|
|
|
119
135
|
},
|
|
120
136
|
options: { namespace: "mem" },
|
|
121
137
|
execute: async (input, context) => {
|
|
138
|
+
// The guard, not the description: a model's call runs only when the
|
|
139
|
+
// person's latest message asks, and an agent's brief never counts. A
|
|
140
|
+
// host's direct execution (a routine's check) carries no call id, so it
|
|
141
|
+
// is not a model call and collects as before.
|
|
142
|
+
await toolkit.ensureSession?.(context?.sessionID)
|
|
143
|
+
const said = latestWord(toolkit.runtime, context?.sessionID, context)
|
|
144
|
+
if (mustRefuse(said, asksToCollect(said.text))) return { output: { skipped: COLLECT_NEEDS_REQUEST }, content: COLLECT_NEEDS_REQUEST }
|
|
122
145
|
const outcome = await toolkit.collector.trigger({ source: input?.source, wait: input?.wait === true, sessionID: context?.sessionID, from: "tool" })
|
|
123
146
|
return { output: collectOutput(outcome), content: describeOutcome(outcome) }
|
|
124
147
|
},
|
|
@@ -133,7 +156,7 @@ function collectOutput(outcome) {
|
|
|
133
156
|
if (outcome.skipped) output.skipped = outcome.skipped
|
|
134
157
|
if ("done" in outcome) output.done = Boolean(outcome.done)
|
|
135
158
|
const sources = outcome.run?.sources ?? outcome.progress
|
|
136
|
-
if (Array.isArray(sources)) output.sources = sources.map(({ source, account, pages, accepted, duplicates, refused, more, error }) => ({ source, account, pages, accepted, duplicates, refused, more, ...(error ? { error } : {}) }))
|
|
159
|
+
if (Array.isArray(sources)) output.sources = sources.map(({ source, account, pages, accepted, duplicates, refused, more, error }) => ({ source, account, pages, accepted, duplicates, refused, more, ...(error ? { error: errorMessage(error) } : {}) }))
|
|
137
160
|
return output
|
|
138
161
|
}
|
|
139
162
|
|
|
@@ -148,7 +171,7 @@ export function describeOutcome(outcome) {
|
|
|
148
171
|
}
|
|
149
172
|
const run = outcome.run
|
|
150
173
|
if (!run) return `${head}; it finished.`
|
|
151
|
-
if (run.error) return `${head}; it failed: ${run.error}`
|
|
174
|
+
if (run.error) return `${head}; it failed: ${errorMessage(run.error)}`
|
|
152
175
|
if (run.none || !run.sources?.length) return `${head}; nothing to collect: no source is enabled and confirmed. Bind one with mem_spaces ("action": "sources") when the person asks.`
|
|
153
176
|
return ["Memory collection:", ...run.sources.map((result) => `- ${describeResult(result)}`)].join("\n")
|
|
154
177
|
}
|
|
@@ -174,6 +197,8 @@ export async function registerCollectCommand(ctx, runtime, toolkit, { asSession
|
|
|
174
197
|
description: "Collect now from the sources you bound to Memory (mail, chat, meetings), without a model turn",
|
|
175
198
|
execute: ({ sessionID }) =>
|
|
176
199
|
asSession(sessionID, async () => {
|
|
200
|
+
// /mem-collect also re-reads the installed plugins' declarations (read-only).
|
|
201
|
+
void toolkit.plugins?.scan?.("command")
|
|
177
202
|
const outcome = await toolkit.collector.trigger({ wait: true, sessionID, from: "command" })
|
|
178
203
|
await reply(sessionID, describeOutcome(outcome))
|
|
179
204
|
}),
|
package/src/tools/memory.js
CHANGED
|
@@ -19,6 +19,8 @@ import { RecordsError, isRecordsUnavailable } from "../backend/records.js"
|
|
|
19
19
|
import { FORGOTTEN_ID, createForgottenMatcher } from "../forgotten.js"
|
|
20
20
|
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
|
+
import { spaceOf } from "../views/shape.js"
|
|
23
|
+
import { withReceipt, writeReceipt } from "../views/receipt.js"
|
|
22
24
|
|
|
23
25
|
const KINDS = MEMORY_TYPES
|
|
24
26
|
/** A supersede replaces a few records, not a cleanup: more is a forget. */
|
|
@@ -231,7 +233,7 @@ export function createCoreForget(toolkit) {
|
|
|
231
233
|
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.`)
|
|
232
234
|
if (keep.left.length > 0) {
|
|
233
235
|
const list = keep.left.map((id) => oneLine(id, 80)).join(", ")
|
|
234
|
-
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:
|
|
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: only on the person's request, never as a tidy-up.`)
|
|
235
237
|
}
|
|
236
238
|
lines.push("Captured turns that mention the old value stay as history.")
|
|
237
239
|
return lines.join(" ")
|
|
@@ -1027,7 +1029,7 @@ export function registerRemember(editor, toolkit) {
|
|
|
1027
1029
|
}
|
|
1028
1030
|
if (core) lines.push(await core.supersedeAtoms(keep, id, spaceContext, base))
|
|
1029
1031
|
lines.push(`To change it later: mem_revise {"action": "correct", "id": "${id}", "content": "…"}; to drop it: {"action": "retire", "id": "${id}"}.`)
|
|
1030
|
-
return text(lines.join("\n"))
|
|
1032
|
+
return withReceipt(text(lines.join("\n")), writeReceipt("remember", { record: stored, space: spaceOf(spaceContext) }))
|
|
1031
1033
|
},
|
|
1032
1034
|
})
|
|
1033
1035
|
}
|
|
@@ -1047,7 +1049,7 @@ export function registerRemember(editor, toolkit) {
|
|
|
1047
1049
|
* @param {ReturnType<import("./shared.js").createToolkit>} toolkit
|
|
1048
1050
|
*/
|
|
1049
1051
|
export function registerRevise(editor, toolkit) {
|
|
1050
|
-
const { text, fail, log, scope, scopeFor, resolveReadSpace, assertTeamWrite, gateWrite, displayScope, taskFor, forgetLocations } = toolkit
|
|
1052
|
+
const { text, fail, log, runtime, scope, scopeFor, resolveReadSpace, assertTeamWrite, gateWrite, displayScope, taskFor, forgetLocations } = toolkit
|
|
1051
1053
|
/**
|
|
1052
1054
|
* The space a revise acts in: where this process last saw the id (recall,
|
|
1053
1055
|
* remember, page), else the session's (personal, or a bound shared one).
|
|
@@ -1084,7 +1086,7 @@ export function registerRevise(editor, toolkit) {
|
|
|
1084
1086
|
editor.add({
|
|
1085
1087
|
name: "revise",
|
|
1086
1088
|
description:
|
|
1087
|
-
"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),
|
|
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), 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.",
|
|
1088
1090
|
input: {
|
|
1089
1091
|
type: "object",
|
|
1090
1092
|
properties: {
|
|
@@ -1209,7 +1211,10 @@ export function registerRevise(editor, toolkit) {
|
|
|
1209
1211
|
throw error
|
|
1210
1212
|
}
|
|
1211
1213
|
const removed = await core.supersedeAtoms(keep, stored?.id, spaceContext, base)
|
|
1212
|
-
return
|
|
1214
|
+
return withReceipt(
|
|
1215
|
+
text(`corrected atom ${oneLine(id, 80)} as ${stored?.id} (memory/${kind}) in ${label}; mem_recall finds it now.\n${removed}`),
|
|
1216
|
+
writeReceipt("correct", { record: stored, space: spaceOf(spaceContext) }),
|
|
1217
|
+
)
|
|
1213
1218
|
}
|
|
1214
1219
|
|
|
1215
1220
|
// The old record and extracted atoms have no durable cross-store link.
|
|
@@ -1223,7 +1228,7 @@ export function registerRevise(editor, toolkit) {
|
|
|
1223
1228
|
const scan = await createCoreForget(toolkit).scanCopies({ texts: [factOf(old)], spaceContext, base })
|
|
1224
1229
|
const atoms = scan.copies.filter((row) => row.layer === "l1")
|
|
1225
1230
|
correctionWarning = atoms.length
|
|
1226
|
-
? `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
|
|
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 only on their request, never as a tidy-up.`
|
|
1227
1232
|
: "Old atoms and turns may still appear in recall; provenance and the bounded scan cannot rule out stale conflicts."
|
|
1228
1233
|
if (scan.windows.some((window) => !window.listing.complete)) correctionWarning += " The core scan was incomplete."
|
|
1229
1234
|
} catch (error) {
|
|
@@ -1234,14 +1239,20 @@ export function registerRevise(editor, toolkit) {
|
|
|
1234
1239
|
const data = await callRecords(toolkit, "records.revise", body, spaceContext, scoped)
|
|
1235
1240
|
const record = data?.record ?? {}
|
|
1236
1241
|
log.info("revise", { revise: verb, scope: label })
|
|
1242
|
+
// The receipt names the record the call changed (a correction writes a
|
|
1243
|
+
// new one); a record with no id answers the text alone.
|
|
1244
|
+
const receipt = writeReceipt(verb, { record, space: spaceOf(spaceContext) })
|
|
1237
1245
|
if (verb === "correct") {
|
|
1238
|
-
return
|
|
1239
|
-
|
|
1246
|
+
return withReceipt(
|
|
1247
|
+
text(
|
|
1248
|
+
`corrected ${id} → ${record.id} in ${label}: ${record.id} is current; ${id} is kept, marked superseded (mem_recall shows it only with status "all"; mem_revise history shows both).\n${recordLine(record)}\n${correctionWarning}`,
|
|
1249
|
+
),
|
|
1250
|
+
receipt,
|
|
1240
1251
|
)
|
|
1241
1252
|
}
|
|
1242
|
-
if (verb === "confirm") return text(`confirmed ${id} (version ${record.version ?? "?"}, ${record.status ?? "current"}) in ${label}: checked today.`)
|
|
1243
|
-
if (verb === "retire") return text(`retired ${id} in ${label}: mem_recall no longer shows it (status "all" does). To bring it back: mem_revise {"action": "restore", "id": "${id}"}.`)
|
|
1244
|
-
return text(`restored ${id} in ${label}: it is ${record.status ?? "current"} again and mem_recall shows it.`)
|
|
1253
|
+
if (verb === "confirm") return withReceipt(text(`confirmed ${id} (version ${record.version ?? "?"}, ${record.status ?? "current"}) in ${label}: checked today.`), receipt)
|
|
1254
|
+
if (verb === "retire") return withReceipt(text(`retired ${id} in ${label}: mem_recall no longer shows it (status "all" does). To bring it back: mem_revise {"action": "restore", "id": "${id}"}.`), receipt)
|
|
1255
|
+
return withReceipt(text(`restored ${id} in ${label}: it is ${record.status ?? "current"} again and mem_recall shows it.`), receipt)
|
|
1245
1256
|
} catch (error) {
|
|
1246
1257
|
log.warn("revise failed", error)
|
|
1247
1258
|
const refused = notWritten(error, verb === "correct" ? "corrected" : "changed")
|
|
@@ -1294,7 +1305,7 @@ export function registerRevise(editor, toolkit) {
|
|
|
1294
1305
|
function outcomeLines(results, done, undone = "not changed") {
|
|
1295
1306
|
return results.map((item) => item.ok
|
|
1296
1307
|
? `- ${oneLine(item.id, 40)}: ${done}`
|
|
1297
|
-
: `- ${oneLine(item.id, 40)}: ${undone} (${oneLine(item.error?.code ?? "error", 40)}): ${oneLine(item.error
|
|
1308
|
+
: `- ${oneLine(item.id, 40)}: ${undone} (${oneLine(item.error?.code ?? "error", 40)}): ${oneLine(errorMessage(item.error), 200)}`)
|
|
1298
1309
|
}
|
|
1299
1310
|
|
|
1300
1311
|
/**
|
|
@@ -1393,6 +1404,10 @@ export function registerRevise(editor, toolkit) {
|
|
|
1393
1404
|
space: spaceContext?.space_id ?? "local",
|
|
1394
1405
|
visibility: spaceContext?.space_kind === "shared" ? "team" : "private",
|
|
1395
1406
|
ids: ids.length,
|
|
1407
|
+
// #55: the ask names the space, as every other team-write ask does, so
|
|
1408
|
+
// an approval can read "... to Platform" rather than an id.
|
|
1409
|
+
...(spaceContext?.space_id ? { space_id: spaceContext.space_id } : {}),
|
|
1410
|
+
...(spaceContext?.space_name ? { space_name: oneLine(spaceContext.space_name, 200) } : {}),
|
|
1396
1411
|
...(copyIDs.length > 0 ? { copies: copyIDs.length } : {}),
|
|
1397
1412
|
...askItems("forget", entries),
|
|
1398
1413
|
...(kept !== null ? { fingerprints_left: Math.max(0, FINGERPRINT_CAP - kept) } : {}),
|
|
@@ -1442,13 +1457,15 @@ export function registerRevise(editor, toolkit) {
|
|
|
1442
1457
|
}
|
|
1443
1458
|
|
|
1444
1459
|
let gone = []
|
|
1460
|
+
// A delete whose outcome the service did not report: the text may be gone,
|
|
1461
|
+
// so for capture the forget counts as done (fail closed).
|
|
1462
|
+
let deleteUnknown = false
|
|
1445
1463
|
// Records the service refused to delete: still there by its answer, so the
|
|
1446
1464
|
// read back does not report them as copies left behind.
|
|
1447
1465
|
const refusedIDs = new Set()
|
|
1448
1466
|
let refusedBlock = ""
|
|
1449
1467
|
if (records.length > 0) {
|
|
1450
1468
|
let data
|
|
1451
|
-
let deleteUnknown = false
|
|
1452
1469
|
const recordList = records.map((record) => record.id)
|
|
1453
1470
|
try {
|
|
1454
1471
|
// A batch forget authorises each id on its own (0.9.7); an older
|
|
@@ -1547,7 +1564,7 @@ export function registerRevise(editor, toolkit) {
|
|
|
1547
1564
|
}
|
|
1548
1565
|
// Forget, end to end on this machine: turns waiting in the spool or in
|
|
1549
1566
|
// quarantine that hold the text are deleted, and later captures of this
|
|
1550
|
-
// session (the
|
|
1567
|
+
// session (the next checkpoint) are masked.
|
|
1551
1568
|
for (const record of records) {
|
|
1552
1569
|
if (!gone.includes(record.id)) continue
|
|
1553
1570
|
purgeTexts.push(String(record.title ?? ""), factOf(record), String(record.body ?? "").replace(/^\s*why\s*:\s*/gim, ""))
|
|
@@ -1561,6 +1578,27 @@ export function registerRevise(editor, toolkit) {
|
|
|
1561
1578
|
log.warn("forget purge failed", errorMessage(error))
|
|
1562
1579
|
}
|
|
1563
1580
|
}
|
|
1581
|
+
// The turn that asked restates the text: the person's request quotes it,
|
|
1582
|
+
// the answer often does, and this result can too. Masking misses a
|
|
1583
|
+
// paraphrase, so the turn it ran in (a subagent's runs in its parent's) is
|
|
1584
|
+
// not kept at all, and the exchange's captures are removed
|
|
1585
|
+
// (src/forget-turn.js). A delete the service did not confirm counts as
|
|
1586
|
+
// done here: the text may already be gone. A declined forget, or one that
|
|
1587
|
+
// deleted nothing, marks no turn.
|
|
1588
|
+
const removal = gone.length > 0 || coreGone > 0 || deleteUnknown ? await runtime?.noteForgetTurn?.(context?.sessionID) : null
|
|
1589
|
+
// The one instruction about the answer, whenever the text may be gone.
|
|
1590
|
+
if (gone.length > 0 || coreGone > 0 || deleteUnknown) parts.push("Do not repeat what was forgotten in your answer.")
|
|
1591
|
+
// Whether any turn was dropped, so the sentence says what happened rather
|
|
1592
|
+
// than what was expected (a background subagent's forget drops none).
|
|
1593
|
+
if (removal?.marked > 0) parts.push("This turn isn't kept where the text was restated.")
|
|
1594
|
+
// A copy of the turn that could not be confirmed erased: the person can
|
|
1595
|
+
// still ask for that turn to be removed, and only they can decide.
|
|
1596
|
+
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.")
|
|
1597
|
+
// A turn the person steered away from, or that the host evicted, may hold
|
|
1598
|
+
// the text and is already kept: it is never deleted for them. The person
|
|
1599
|
+
// decides, through the consent path a retained turn always needs.
|
|
1600
|
+
const partial = context?.sessionID ? runtime?.partialTurnOf?.(context.sessionID) : null
|
|
1601
|
+
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.")
|
|
1564
1602
|
log.info("revise forget", { records: gone.length, core: coreIDs.length, copies: copyIDs.length })
|
|
1565
1603
|
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.")
|
|
1566
1604
|
return [parts.join(" "), refusedBlock, report].filter(Boolean).join("\n")
|