@joe-broadhead/opencode-mem 0.9.5 → 0.9.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1281 -0
- package/README.md +105 -31
- package/docs/agent-protocol.md +28 -27
- package/docs/permissions.md +148 -0
- package/package.json +24 -12
- package/skills/mem.pages/SKILL.md +35 -16
- package/skills/mem.sharing/SKILL.md +39 -6
- package/skills/mem.sources/SKILL.md +41 -10
- package/skills/mem.usage/SKILL.md +37 -16
- package/src/backend/records.js +8 -0
- package/src/backend/v3.js +15 -10
- package/src/call-shapes.js +18 -25
- package/src/capture-pause.js +136 -0
- package/src/capture.js +7 -5
- package/src/collector-service.js +212 -35
- package/src/collector.js +186 -47
- package/src/commands.js +37 -0
- package/src/compaction.js +4 -2
- package/src/config.js +151 -1
- package/src/curation.js +6 -10
- package/src/events.js +144 -36
- package/src/forget-purge.js +377 -0
- package/src/forgotten.js +152 -0
- package/src/hooks.js +9 -4
- package/src/index.js +5 -3
- package/src/permissions.js +116 -38
- package/src/protocol.js +21 -11
- package/src/records.js +4 -1
- package/src/runtime.js +202 -15
- package/src/shapes.js +63 -0
- package/src/sources.js +183 -12
- package/src/spaces.js +58 -1
- package/src/spool.js +442 -64
- package/src/stated.js +334 -0
- package/src/storable.js +477 -0
- package/src/tools/aliases.js +36 -147
- package/src/tools/commitments.js +69 -12
- package/src/tools/index.js +25 -43
- package/src/tools/ingest.js +33 -128
- package/src/tools/memory.js +503 -904
- package/src/tools/page-sections.js +147 -0
- package/src/tools/page.js +314 -82
- package/src/tools/recall-browse.js +173 -0
- package/src/tools/recall.js +36 -8
- package/src/tools/share.js +494 -131
- package/src/tools/shared.js +97 -19
- package/src/tools/spaces.js +194 -101
- package/src/tools/status.js +31 -3
- package/src/tools/wiki.js +5 -13
- package/src/util.js +10 -59
- package/src/views/profile.js +2 -3
- package/src/views/records-reads.js +6 -1
- package/src/erase.js +0 -36
package/src/tools/ingest.js
CHANGED
|
@@ -1,73 +1,39 @@
|
|
|
1
|
-
import { DEFAULT_ACCOUNT, isAccountName, isSourceName } from "../collector.js"
|
|
2
1
|
import { describeResult } from "../collector-service.js"
|
|
3
|
-
import { errorMessage, isPlainObject, oneLine } from "../util.js"
|
|
4
|
-
import { RECORDS_MISSING, recordsFailure, recordsOf } from "./share.js"
|
|
5
|
-
import { unboundOwner } from "../backend/records.js"
|
|
6
2
|
|
|
7
|
-
/**
|
|
8
|
-
|
|
3
|
+
/**
|
|
4
|
+
* 0.9.7 (security review of audit tools #4): `mem_ingest` and `mem_cursor` are
|
|
5
|
+
* retired and always refuse, in every session. Their gate used to check only
|
|
6
|
+
* the session id's format, which is computable (a sha256 of source and
|
|
7
|
+
* account), and the collector's own sessions allowed both. Nothing legitimate
|
|
8
|
+
* calls them: the in-plugin collector reads the cursor and ingests through the
|
|
9
|
+
* records client directly (src/collector-service.js), and Jelly's routine calls
|
|
10
|
+
* `mem_collect`. They stay registered only because Jelly declares both tools
|
|
11
|
+
* (`package.json` `jelly.tools`); a call gets this answer.
|
|
12
|
+
*/
|
|
13
|
+
export const RETIRED = (tool) => `${tool} is retired and internal: it does nothing in any session. Memory collects on its own, and mem_collect collects now when the person asks.`
|
|
9
14
|
|
|
10
15
|
/**
|
|
11
|
-
* `mem_ingest` and `mem_cursor`:
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* them, and their descriptions say so.
|
|
15
|
-
*
|
|
16
|
-
* Both work in the caller's personal space, where raw events stay private
|
|
17
|
-
* (memory-funnel-v1.md §10). Each answers structured `output` (so the check's
|
|
18
|
-
* code reads `c.cursor` and `saved.cursor_saved`) and a one-line `content`.
|
|
19
|
-
*
|
|
20
|
-
* A refused ingest (409 `source_unbound`: the binding is missing, or the
|
|
21
|
-
* signed-in account changed) is not an error to the check: it answers
|
|
22
|
-
* `cursor_saved: false` with the owner the records service reported, and the
|
|
23
|
-
* collector remembers that owner so `mem_spaces` can show it when the person
|
|
24
|
-
* binds the source.
|
|
16
|
+
* `mem_ingest` and `mem_cursor`: retired stubs (above). Each answers its old
|
|
17
|
+
* structured output shape, so a stale host schedule's check reads a refusal
|
|
18
|
+
* (`cursor_saved: false`, `enabled: false`) and stops.
|
|
25
19
|
*
|
|
26
20
|
* @param {any} editor
|
|
27
|
-
* @param {ReturnType<import("./shared.js").createToolkit>}
|
|
21
|
+
* @param {ReturnType<import("./shared.js").createToolkit>} _toolkit
|
|
28
22
|
*/
|
|
29
|
-
export function registerIngest(editor,
|
|
30
|
-
const { text, log } = toolkit
|
|
31
|
-
|
|
32
|
-
/** The personal space the events belong to, as a records call's `where`. */
|
|
33
|
-
async function personalWhere(context) {
|
|
34
|
-
if (!toolkit.control) return { where: { sessionID: context?.sessionID } }
|
|
35
|
-
const resolved = await toolkit.resolvePrivateSpace({}, context)
|
|
36
|
-
if (resolved.invalid) return { error: resolved.invalid }
|
|
37
|
-
if (resolved.error) return { error: resolved.error }
|
|
38
|
-
return { where: { space: resolved.context.space_id } }
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function bindingOf(input) {
|
|
42
|
-
const source = String(input?.source ?? "").trim()
|
|
43
|
-
const account = String(input?.account ?? "").trim() || DEFAULT_ACCOUNT
|
|
44
|
-
if (!isSourceName(source)) return { error: `source "${oneLine(source || "(none)", 60)}" is not a source name` }
|
|
45
|
-
if (!isAccountName(account)) return { error: `account "${oneLine(account, 60)}" is not an account name` }
|
|
46
|
-
return { source, account }
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const refuse = (reason, extra = {}) => ({ output: { accepted: 0, duplicates: 0, refused: 0, cursor_saved: false, error: reason, ...extra }, content: reason })
|
|
50
|
-
|
|
23
|
+
export function registerIngest(editor, _toolkit) {
|
|
51
24
|
editor.add({
|
|
52
25
|
name: "ingest",
|
|
53
|
-
description:
|
|
54
|
-
"For the memory collector only (the memory-collect schedule and /mem-collect); agents never call it. Sends one page of a source's events to the person's private event log, with the source's new cursor. The records service keeps events only from the account the person bound, for 30 days, never as memories.",
|
|
26
|
+
description: "Retired and internal; agents never call it, and it always refuses. Memory collects on its own, and mem_collect collects now when the person asks.",
|
|
55
27
|
input: {
|
|
56
28
|
type: "object",
|
|
57
29
|
properties: {
|
|
58
|
-
source: { type: "string", description: "
|
|
59
|
-
account: { type: "string", description:
|
|
60
|
-
owner: {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
properties: { id: { type: "string" }, label: { type: "string" } },
|
|
64
|
-
required: ["id"],
|
|
65
|
-
},
|
|
66
|
-
events: { type: "array", items: { type: "object" }, description: `events_list's events, oldest first, at most ${MAX_INGEST_EVENTS}` },
|
|
67
|
-
cursor: { type: "string", description: "events_list's cursor after these events" },
|
|
30
|
+
source: { type: "string", description: "Ignored" },
|
|
31
|
+
account: { type: "string", description: "Ignored" },
|
|
32
|
+
owner: { type: "object", description: "Ignored", properties: { id: { type: "string" }, label: { type: "string" } } },
|
|
33
|
+
events: { type: "array", items: { type: "object" }, description: "Ignored" },
|
|
34
|
+
cursor: { type: "string", description: "Ignored" },
|
|
68
35
|
},
|
|
69
|
-
|
|
70
|
-
additionalProperties: false,
|
|
36
|
+
additionalProperties: true,
|
|
71
37
|
},
|
|
72
38
|
output: {
|
|
73
39
|
type: "object",
|
|
@@ -77,67 +43,26 @@ export function registerIngest(editor, toolkit) {
|
|
|
77
43
|
refused: { type: "integer" },
|
|
78
44
|
cursor_saved: { type: "boolean" },
|
|
79
45
|
error: { type: "string" },
|
|
80
|
-
owner: { type: "object" },
|
|
81
46
|
},
|
|
82
47
|
required: ["accepted", "duplicates", "refused", "cursor_saved"],
|
|
83
48
|
},
|
|
84
49
|
options: { namespace: "mem" },
|
|
85
|
-
execute: async (
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
const binding = bindingOf(input)
|
|
89
|
-
if (binding.error) return refuse(`not ingested: ${binding.error}`)
|
|
90
|
-
if (!isPlainObject(input?.owner) || !String(input.owner.id ?? "").trim()) return refuse("not ingested: owner.id is required (events_list's owner)")
|
|
91
|
-
if (!Array.isArray(input?.events)) return refuse("not ingested: events must be an array")
|
|
92
|
-
if (input.events.length > MAX_INGEST_EVENTS) return refuse(`not ingested: at most ${MAX_INGEST_EVENTS} events per call`)
|
|
93
|
-
if (typeof input?.cursor !== "string" || !input.cursor) return refuse("not ingested: cursor is required (events_list's cursor)")
|
|
94
|
-
const target = await personalWhere(context)
|
|
95
|
-
if (target.error) return refuse(`not ingested: ${target.error}`)
|
|
96
|
-
const owner = { id: oneLine(input.owner.id, 300), label: oneLine(input.owner.label ?? input.owner.id, 300) }
|
|
97
|
-
try {
|
|
98
|
-
const answer = await records.call(
|
|
99
|
-
"events.ingest",
|
|
100
|
-
{ source: binding.source, account: binding.account, owner, events: input.events, cursor: input.cursor },
|
|
101
|
-
target.where,
|
|
102
|
-
)
|
|
103
|
-
const output = {
|
|
104
|
-
accepted: Number(answer?.accepted) || 0,
|
|
105
|
-
duplicates: Number(answer?.duplicates) || 0,
|
|
106
|
-
refused: Number(answer?.refused) || 0,
|
|
107
|
-
cursor_saved: answer?.cursor_saved === true,
|
|
108
|
-
}
|
|
109
|
-
return {
|
|
110
|
-
output,
|
|
111
|
-
content: `${binding.source}:${binding.account}: ${output.accepted} accepted, ${output.duplicates} duplicate(s), ${output.refused} refused; cursor ${output.cursor_saved ? "saved" : "not saved"}.`,
|
|
112
|
-
}
|
|
113
|
-
} catch (error) {
|
|
114
|
-
const code = String(error?.code ?? error?.error?.code ?? "")
|
|
115
|
-
if (code === "source_unbound") {
|
|
116
|
-
const reported = unboundOwner(error) ?? owner
|
|
117
|
-
toolkit.collector?.noteOwner(binding.source, binding.account, reported)
|
|
118
|
-
return refuse(
|
|
119
|
-
`not ingested: ${binding.source}:${binding.account} is not bound to the account signed in (${oneLine(reported?.label ?? reported?.id ?? "unknown", 120)}). The person confirms it with mem_spaces ("action": "sources", "bind").`,
|
|
120
|
-
{ owner: { id: oneLine(reported?.id ?? "", 300), label: oneLine(reported?.label ?? reported?.id ?? "", 300) } },
|
|
121
|
-
)
|
|
122
|
-
}
|
|
123
|
-
log.warn("ingest failed", { source: binding.source, error: errorMessage(error) })
|
|
124
|
-
return refuse(`${error?.outcomeUnknown ? "ingest outcome unknown" : "not ingested"}: ${recordsFailure(error)}`)
|
|
125
|
-
}
|
|
50
|
+
execute: async () => {
|
|
51
|
+
const reason = RETIRED("mem_ingest")
|
|
52
|
+
return { output: { accepted: 0, duplicates: 0, refused: 0, cursor_saved: false, error: reason }, content: reason }
|
|
126
53
|
},
|
|
127
54
|
})
|
|
128
55
|
|
|
129
56
|
editor.add({
|
|
130
57
|
name: "cursor",
|
|
131
|
-
description:
|
|
132
|
-
"For the memory collector only (the memory-collect schedule and /mem-collect); agents never call it. Reads where collection from one source stopped, and whether the person enabled and confirmed that source.",
|
|
58
|
+
description: "Retired and internal; agents never call it, and it always refuses. Memory collects on its own, and mem_collect collects now when the person asks.",
|
|
133
59
|
input: {
|
|
134
60
|
type: "object",
|
|
135
61
|
properties: {
|
|
136
|
-
source: { type: "string", description: "
|
|
137
|
-
account: { type: "string", description:
|
|
62
|
+
source: { type: "string", description: "Ignored" },
|
|
63
|
+
account: { type: "string", description: "Ignored" },
|
|
138
64
|
},
|
|
139
|
-
|
|
140
|
-
additionalProperties: false,
|
|
65
|
+
additionalProperties: true,
|
|
141
66
|
},
|
|
142
67
|
output: {
|
|
143
68
|
type: "object",
|
|
@@ -151,29 +76,9 @@ export function registerIngest(editor, toolkit) {
|
|
|
151
76
|
required: ["enabled", "status"],
|
|
152
77
|
},
|
|
153
78
|
options: { namespace: "mem" },
|
|
154
|
-
execute: async (
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
if (!records) return closed(RECORDS_MISSING)
|
|
158
|
-
const binding = bindingOf(input)
|
|
159
|
-
if (binding.error) return closed(`no cursor: ${binding.error}`)
|
|
160
|
-
const target = await personalWhere(context)
|
|
161
|
-
if (target.error) return closed(`no cursor: ${target.error}`)
|
|
162
|
-
try {
|
|
163
|
-
const answer = await records.call("events.cursor", { source: binding.source, account: binding.account }, target.where)
|
|
164
|
-
const output = {
|
|
165
|
-
cursor: typeof answer?.cursor === "string" ? answer.cursor : "",
|
|
166
|
-
cursor_at: typeof answer?.cursor_at === "string" ? answer.cursor_at : "",
|
|
167
|
-
enabled: answer?.enabled === true || answer?.enabled === 1,
|
|
168
|
-
status: typeof answer?.status === "string" ? answer.status : "unknown",
|
|
169
|
-
}
|
|
170
|
-
return {
|
|
171
|
-
output,
|
|
172
|
-
content: `${binding.source}:${binding.account}: ${output.status}, ${output.enabled ? "enabled" : "disabled"}, cursor ${output.cursor ? `at ${oneLine(output.cursor_at || "an earlier run", 40)}` : "not set"}.`,
|
|
173
|
-
}
|
|
174
|
-
} catch (error) {
|
|
175
|
-
return closed(`no cursor: ${recordsFailure(error)}`)
|
|
176
|
-
}
|
|
79
|
+
execute: async () => {
|
|
80
|
+
const reason = `no cursor: ${RETIRED("mem_cursor")}`
|
|
81
|
+
return { output: { cursor: "", enabled: false, status: "unavailable", error: reason }, content: reason }
|
|
177
82
|
},
|
|
178
83
|
})
|
|
179
84
|
}
|