@joe-broadhead/opencode-mem 0.8.0 → 0.8.1
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 +1275 -0
- package/README.md +25 -18
- package/package.json +11 -7
- package/skills/{mem-usage → mem.usage}/SKILL.md +4 -1
- package/src/backend/v3.js +20 -5
- package/src/call-shapes.js +1 -0
- package/src/credentials.js +7 -2
- package/src/errors.js +86 -0
- package/src/index.js +9 -0
- package/src/permissions.js +67 -0
- package/src/skills.js +1 -1
- package/src/spaces.js +41 -19
- package/src/tools/commitments.js +2 -1
- package/src/tools/memory.js +35 -4
- package/src/tools/shared.js +3 -1
- package/views/memory.html +2 -2
package/src/tools/memory.js
CHANGED
|
@@ -16,8 +16,17 @@ import {
|
|
|
16
16
|
rememberParts,
|
|
17
17
|
} from "../copies.js"
|
|
18
18
|
import { errorMessage, neutralizeFenceClosers, oneLine, redactSecrets, shortHash } from "../util.js"
|
|
19
|
+
import { isCoded, withNote } from "../errors.js"
|
|
19
20
|
import { TASK_INPUT, canWriteShared } from "./shared.js"
|
|
20
21
|
|
|
22
|
+
/**
|
|
23
|
+
* The permission mem_forget asserts before it deletes: the tool's own engine
|
|
24
|
+
* id, declared `effect: "ask"` in `jelly.tools`. Not an approval action
|
|
25
|
+
* (`jelly.asks`), so it is a name here, not a literal the scan in
|
|
26
|
+
* scripts/approval-actions.mjs would read as one.
|
|
27
|
+
*/
|
|
28
|
+
const FORGET_PERMISSION = "mem_forget"
|
|
29
|
+
|
|
21
30
|
const KINDS = Object.freeze(["fact", "decision", "constraint", "preference", "procedure"])
|
|
22
31
|
/** A supersede replaces a few atoms, not a cleanup: more is a forget. */
|
|
23
32
|
const MAX_SUPERSEDES = 10
|
|
@@ -217,7 +226,12 @@ export function registerMemory(editor, toolkit) {
|
|
|
217
226
|
} catch (error) {
|
|
218
227
|
if (!isTransientFailure(error)) {
|
|
219
228
|
log.warn("remember rejected by the backend", error)
|
|
220
|
-
|
|
229
|
+
const message = errorMessage(error)
|
|
230
|
+
return text(
|
|
231
|
+
isCoded(message)
|
|
232
|
+
? withNote(message, "not stored, and nothing was queued")
|
|
233
|
+
: `not stored: the backend rejected the write (${message}). Nothing was queued.`,
|
|
234
|
+
)
|
|
221
235
|
}
|
|
222
236
|
const spooled = toolkit.runtime.enqueueSpool("conversation", { sessionID, messages, scope: scoped })
|
|
223
237
|
if (spooled) {
|
|
@@ -229,9 +243,7 @@ export function registerMemory(editor, toolkit) {
|
|
|
229
243
|
)
|
|
230
244
|
}
|
|
231
245
|
log.warn("remember failed and could not be spooled", error)
|
|
232
|
-
return fail(
|
|
233
|
-
`${errorMessage(error)}; local spooling is disabled or unavailable, so the memory was not stored.`,
|
|
234
|
-
)
|
|
246
|
+
return fail(withNote(errorMessage(error), "local spooling is disabled or unavailable, so the memory was not stored"))
|
|
235
247
|
}
|
|
236
248
|
},
|
|
237
249
|
})
|
|
@@ -806,6 +818,25 @@ export function registerMemory(editor, toolkit) {
|
|
|
806
818
|
const label = displayScope(spaceContext, scoped)
|
|
807
819
|
|
|
808
820
|
const preview = Boolean(match) && input?.confirm !== true
|
|
821
|
+
// Forget asks (D17): a delete cannot be undone, so the call asserts the
|
|
822
|
+
// tool's own permission before anything is deleted, and the plugin's
|
|
823
|
+
// default rule (src/permissions.js) or Jelly's declared `ask` makes the
|
|
824
|
+
// host ask. A preview deletes nothing and does not ask.
|
|
825
|
+
if (!preview) {
|
|
826
|
+
try {
|
|
827
|
+
await toolkit.assert({
|
|
828
|
+
sessionID: context?.sessionID,
|
|
829
|
+
agent: context?.agent,
|
|
830
|
+
source: { type: "tool", messageID: context?.messageID, id: context?.id },
|
|
831
|
+
action: FORGET_PERMISSION,
|
|
832
|
+
resources: [visibility],
|
|
833
|
+
save: [visibility],
|
|
834
|
+
metadata: { visibility, layer, space: label, ...(ids.length > 0 ? { ids: ids.length } : {}), ...(match ? { erase: true } : {}) },
|
|
835
|
+
})
|
|
836
|
+
} catch (error) {
|
|
837
|
+
return text(`forgetting denied: ${errorMessage(error)}. Nothing was deleted.`)
|
|
838
|
+
}
|
|
839
|
+
}
|
|
809
840
|
const approvalMetadata = { layer, space: spaceContext?.space_id ?? "team", ...(match ? { erase: true } : {}) }
|
|
810
841
|
// An id delete asks once it knows every row it will delete: the named ids
|
|
811
842
|
// and the mem_remember rows that hold only their text. Nothing is
|
package/src/tools/shared.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { contextScopeLabel, scopeLabel, taskKey } from "../scope.js"
|
|
2
2
|
import { errorMessage, oneLine } from "../util.js"
|
|
3
|
+
import { isCoded } from "../errors.js"
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Roles that may write to a shared space. The plugin reads this from the
|
|
@@ -31,7 +32,8 @@ export function createToolkit(ctx, runtime) {
|
|
|
31
32
|
const control = runtime.control
|
|
32
33
|
|
|
33
34
|
const text = (content) => ({ content })
|
|
34
|
-
|
|
35
|
+
// A coded failure (src/errors.js) already says what happened and what to do.
|
|
36
|
+
const fail = (message) => text(isCoded(message) ? message : `memory unavailable: ${message}`)
|
|
35
37
|
|
|
36
38
|
/** Shared-asset scope (skills, wiki). Agent is intentionally absent. */
|
|
37
39
|
function sharedScope(context) {
|
package/views/memory.html
CHANGED
|
@@ -204,7 +204,7 @@ const plural = (count, one, many) => `${count.toLocaleString("en-GB")} ${count =
|
|
|
204
204
|
function notConnected(overview) {
|
|
205
205
|
const steps = [];
|
|
206
206
|
if (overview.credential === "none")
|
|
207
|
-
steps.push("Use Jelly with an account that offers
|
|
207
|
+
steps.push("Use Jelly with an account that offers Memory, or paste the key from Memory's /account page into Memory key, in this plugin's settings.");
|
|
208
208
|
if (!overview.address) steps.push("If you use your own memory service, put its address in Memory address, in this plugin's settings.");
|
|
209
209
|
if (steps.length === 0) steps.push("Check Memory address and Memory key in this plugin's settings, then try again.");
|
|
210
210
|
return el("div", { class: "note", role: "status" },
|
|
@@ -332,7 +332,7 @@ async function spacesTab() {
|
|
|
332
332
|
),
|
|
333
333
|
),
|
|
334
334
|
p(spaces.some((space) => space.kind === "shared")
|
|
335
|
-
? "Who can use a shared space is managed on
|
|
335
|
+
? "Who can use a shared space is managed on Memory's site for now."
|
|
336
336
|
: "Team spaces will show here once your team has one.", "muted"),
|
|
337
337
|
);
|
|
338
338
|
}
|