@joe-broadhead/opencode-mem 0.9.5 → 0.9.14
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 +1408 -0
- package/README.md +120 -41
- package/docs/agent-instructions.md +17 -0
- package/docs/agent-protocol.md +28 -27
- package/docs/permissions.md +150 -0
- package/package.json +386 -17
- package/skills/mem.pages/SKILL.md +40 -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 +187 -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 +32 -11
- package/src/recall.js +13 -1
- package/src/records.js +4 -1
- package/src/runtime.js +202 -15
- package/src/shapes.js +63 -0
- package/src/sources.js +205 -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 +79 -13
- package/src/tools/held-write.js +5 -1
- package/src/tools/index.js +25 -43
- package/src/tools/ingest.js +33 -128
- package/src/tools/memory.js +525 -911
- 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/records-kit.js +2 -1
- 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/contracts.js +258 -20
- package/src/views/overdue.js +1 -1
- package/src/views/profile.js +2 -3
- package/src/views/receipt.js +81 -0
- package/src/views/records-reads.js +545 -25
- package/src/views/rpc.js +41 -3
- package/views/memory.html +16 -3
- package/views/remembered.html +130 -0
- package/src/erase.js +0 -36
package/src/views/rpc.js
CHANGED
|
@@ -3,9 +3,11 @@ import { dayIn, dueDay, filterItems, formatDay, formatDue } from "../records.js"
|
|
|
3
3
|
import { isRecordsWikiName } from "../tools/knowledge.js"
|
|
4
4
|
import {
|
|
5
5
|
COMMITMENTS_MAX,
|
|
6
|
+
INBOX_ITEM_SESSION,
|
|
6
7
|
LIST_MAX,
|
|
7
8
|
PAGE_TEXT_CHARS,
|
|
8
9
|
SPEAKER_FIELD,
|
|
10
|
+
SPOOL_TIME_CHARS,
|
|
9
11
|
VIEW_ERROR,
|
|
10
12
|
VIEW_METHODS,
|
|
11
13
|
} from "./contracts.js"
|
|
@@ -226,11 +228,36 @@ export function createViewReads({ runtime, agents = async () => [] }) {
|
|
|
226
228
|
extraction: ["healthy", "failing", "unknown"].includes(extraction?.state) ? extraction.state : "unknown",
|
|
227
229
|
...(extraction?.state === "failing" && typeof extraction.failing_since === "string" && /^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d{3}Z$/.test(extraction.failing_since) ? { failing_since: extraction.failing_since } : {}),
|
|
228
230
|
...(kept.records ? { records: kept.records } : {}),
|
|
231
|
+
...spoolQueue(),
|
|
229
232
|
space: spaceOf(scopes[0]?.context),
|
|
230
233
|
counts,
|
|
231
234
|
}
|
|
232
235
|
}
|
|
233
236
|
|
|
237
|
+
/**
|
|
238
|
+
* The engine's capture queue, as `mem_status` tells the agent (#58 F6): what
|
|
239
|
+
* still waits to be sent, and when the oldest of those was queued. It is this
|
|
240
|
+
* machine's queue whatever space the person reads, so a host several people
|
|
241
|
+
* share shows their queue together; a build that keeps no queue says nothing.
|
|
242
|
+
*/
|
|
243
|
+
function spoolQueue() {
|
|
244
|
+
let stats
|
|
245
|
+
try {
|
|
246
|
+
stats = runtime.spoolStats?.()
|
|
247
|
+
} catch (error) {
|
|
248
|
+
runtime.log?.debug?.("view overview: the capture queue was not read", { error: error?.message })
|
|
249
|
+
return {}
|
|
250
|
+
}
|
|
251
|
+
if (!stats || typeof stats !== "object") return {}
|
|
252
|
+
const depth = Math.max(0, Math.floor(Number(stats.pending) || 0))
|
|
253
|
+
return {
|
|
254
|
+
spool: {
|
|
255
|
+
depth,
|
|
256
|
+
...(depth > 0 && typeof stats.oldest === "string" && stats.oldest.trim() ? { oldest: clip(stats.oldest.trim(), SPOOL_TIME_CHARS) } : {}),
|
|
257
|
+
},
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
234
261
|
async function spacesList() {
|
|
235
262
|
await available()
|
|
236
263
|
if (!runtime.control) return { spaces: [{ ...spaceOf(null), role: "owner" }] }
|
|
@@ -362,12 +389,23 @@ export function createViewReads({ runtime, agents = async () => [] }) {
|
|
|
362
389
|
*/
|
|
363
390
|
async function inboxList() {
|
|
364
391
|
await available()
|
|
365
|
-
const [review, overdue] = await Promise.all([recordsReads.
|
|
366
|
-
const proposals = review.items.flatMap((item) => {
|
|
392
|
+
const [review, overdue] = await Promise.all([recordsReads.reviewWith({}), overdueNotices()])
|
|
393
|
+
const proposals = review.items.flatMap(({ item, kind, session }) => {
|
|
367
394
|
if (!/^rec_[0-9A-Za-z]{1,64}$/.test(item.id)) return []
|
|
368
395
|
if (!inboxTime(item.created)) return []
|
|
369
396
|
const title = oneLinePlain(item.title, 120)
|
|
370
|
-
return [{
|
|
397
|
+
return [{
|
|
398
|
+
key: `proposal:${item.id}`,
|
|
399
|
+
category: "request",
|
|
400
|
+
label: "Proposal",
|
|
401
|
+
name: "Memory",
|
|
402
|
+
line: title || "A proposal is waiting for review",
|
|
403
|
+
at: item.created,
|
|
404
|
+
...(kind ? { kind } : {}),
|
|
405
|
+
// The session is stored and read already; Jelly's strict Inbox reader has
|
|
406
|
+
// no such field yet, so it goes on the wire only when `INBOX_ITEM_SESSION`.
|
|
407
|
+
...(INBOX_ITEM_SESSION && session ? { session } : {}),
|
|
408
|
+
}]
|
|
371
409
|
})
|
|
372
410
|
return { items: [...proposals, ...overdue] }
|
|
373
411
|
}
|
package/views/memory.html
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<html lang="en-GB">
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="utf-8">
|
|
5
|
-
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'sha256-5dtPKkjegOPG8bawdSzGBjixnIaSCLYcZOUAwbRWFAc=' 'sha256-EAE0IDrikWE0chPIVODVlKBvBg1sDxCO9UEtFartZJY=' 'sha256-
|
|
5
|
+
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'sha256-5dtPKkjegOPG8bawdSzGBjixnIaSCLYcZOUAwbRWFAc=' 'sha256-EAE0IDrikWE0chPIVODVlKBvBg1sDxCO9UEtFartZJY=' 'sha256-4GpOEHrmhpQeGOnWxWJkhPlG8s/H/7l0oepo4IUqzH8='; style-src 'unsafe-inline'; base-uri 'none'; form-action 'none'">
|
|
6
6
|
<title>Your memory</title>
|
|
7
7
|
<style>
|
|
8
8
|
:root {
|
|
@@ -553,8 +553,6 @@ async function profileTab() {
|
|
|
553
553
|
answer.incomplete ? el("p", {}, el("strong", {}, "This may be less than Memory holds.")) : null,
|
|
554
554
|
el("ul", {}, answer.notes.map((note) => el("li", {}, note))))
|
|
555
555
|
: null;
|
|
556
|
-
if (answer.items.length === 0)
|
|
557
|
-
return show(p("Memory holds nothing about you yet. It writes this from your conversations, once it has enough of them.", "muted"), notes);
|
|
558
556
|
const several = new Set(answer.items.map((item) => item.agent)).size > 1;
|
|
559
557
|
const part = (item) => el("section", { class: "spaced" },
|
|
560
558
|
el("h2", {}, item.layer === "persona" ? "Your profile" : item.summary || item.path),
|
|
@@ -562,10 +560,25 @@ async function profileTab() {
|
|
|
562
560
|
el("div", { class: "page" }, item.text),
|
|
563
561
|
item.clipped ? p("This is long, so only its start is shown.", "muted") : null,
|
|
564
562
|
);
|
|
563
|
+
// The people and names Memory knows, for a person who wonders what she can
|
|
564
|
+
// refer to: a failed read shows nothing here rather than an empty claim.
|
|
565
|
+
const names = await call("terms.list", { max: 50 }).catch(() => null);
|
|
566
|
+
const namesList = names && names.terms.length > 0
|
|
567
|
+
? el("section", { class: "spaced" },
|
|
568
|
+
el("h2", {}, "Names Memory knows"),
|
|
569
|
+
el("ul", {}, names.terms.map((term) => el("li", {},
|
|
570
|
+
el("span", {}, term.text),
|
|
571
|
+
el("span", { class: "meta" }, [term.kind, term.space.name].filter(Boolean).join(" · ")),
|
|
572
|
+
))),
|
|
573
|
+
names.more ? p("Memory knows more names than this page shows.", "muted") : null,
|
|
574
|
+
)
|
|
575
|
+
: null;
|
|
565
576
|
show(
|
|
566
577
|
p(answer.label, "muted"),
|
|
567
578
|
notes,
|
|
568
579
|
answer.items.map(part),
|
|
580
|
+
answer.items.length === 0 ? p("Memory holds nothing about you yet. It writes this from your conversations, once it has enough of them.", "muted") : null,
|
|
581
|
+
namesList,
|
|
569
582
|
answer.more ? p("Memory holds more than this page shows.", "muted spaced") : null,
|
|
570
583
|
p("To erase something, ask an agent to forget it. It shows you what would go first.", "muted spaced"),
|
|
571
584
|
);
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en-GB">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'sha256-5dtPKkjegOPG8bawdSzGBjixnIaSCLYcZOUAwbRWFAc=' 'sha256-CgOSZ+LvHH0rQecGCbWZUjN52v54OBWuJzsy7gzsz44='; style-src 'unsafe-inline'; base-uri 'none'; form-action 'none'">
|
|
6
|
+
<title>Saved to memory</title>
|
|
7
|
+
<style>
|
|
8
|
+
:root { color: var(--jelly-text, CanvasText); background: var(--jelly-surface, Canvas); font: 14px/1.5 var(--jelly-font, system-ui, sans-serif); }
|
|
9
|
+
body { margin: 0; padding: 16px; }
|
|
10
|
+
h1 { font-size: 18px; margin: 0 0 12px; }
|
|
11
|
+
p { margin: 8px 0; }
|
|
12
|
+
.muted { color: var(--jelly-muted, GrayText); }
|
|
13
|
+
</style>
|
|
14
|
+
</head>
|
|
15
|
+
<body>
|
|
16
|
+
<main aria-live="polite"><h1>Saved to memory</h1><div id="receipt" class="muted">Loading…</div><div id="where"></div></main>
|
|
17
|
+
<script>
|
|
18
|
+
// jelly-view.js: a client of Jelly's view bridge. Paste it into the page's own <script>:
|
|
19
|
+
// a sealed page loads no script by URL and is given no global. Call jellyView() as the
|
|
20
|
+
// script starts; it resolves with the client when the app says hello.
|
|
21
|
+
function jellyView() {
|
|
22
|
+
return new Promise((resolve) => {
|
|
23
|
+
addEventListener("message", function hello(event) {
|
|
24
|
+
const said = event.data;
|
|
25
|
+
if (event.source !== parent || said?.v !== 1 || said.kind !== "hello" || !event.ports[0])
|
|
26
|
+
return;
|
|
27
|
+
removeEventListener("message", hello);
|
|
28
|
+
const port = event.ports[0];
|
|
29
|
+
const listeners = new Set();
|
|
30
|
+
const latest = new Map();
|
|
31
|
+
const queue = [];
|
|
32
|
+
let sequence = 0;
|
|
33
|
+
let current;
|
|
34
|
+
const theme = (tokens) => {
|
|
35
|
+
const style = document.documentElement.style;
|
|
36
|
+
for (const [name, value] of Object.entries(tokens))
|
|
37
|
+
if (name === "scheme") style.colorScheme = value;
|
|
38
|
+
else style.setProperty(`--jelly-${name}`, value);
|
|
39
|
+
};
|
|
40
|
+
// The app answers one request at a time, so requests go in turn.
|
|
41
|
+
const next = () => {
|
|
42
|
+
if (current !== undefined || queue.length === 0) return;
|
|
43
|
+
current = queue.shift();
|
|
44
|
+
current.timer = setTimeout(
|
|
45
|
+
() => settle({ ok: false, error: "No answer from the app" }),
|
|
46
|
+
15000,
|
|
47
|
+
);
|
|
48
|
+
port.postMessage(current.message);
|
|
49
|
+
};
|
|
50
|
+
const settle = (answer) => {
|
|
51
|
+
const done = current;
|
|
52
|
+
current = undefined;
|
|
53
|
+
clearTimeout(done.timer);
|
|
54
|
+
if (answer.ok) done.resolve(answer.value);
|
|
55
|
+
else done.reject(new Error(answer.error));
|
|
56
|
+
next();
|
|
57
|
+
};
|
|
58
|
+
port.onmessage = ({ data }) => {
|
|
59
|
+
if (data?.v !== 1) return;
|
|
60
|
+
if (typeof data.kind !== "string") {
|
|
61
|
+
if (current !== undefined && data.re === current.message.id) settle(data);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
// A call waiting for the person is answered by `until`, not in 15 s.
|
|
65
|
+
if (data.kind === "rpc.waiting" && data.re === current?.message.id) {
|
|
66
|
+
clearTimeout(current.timer);
|
|
67
|
+
current.timer = setTimeout(
|
|
68
|
+
() => settle({ ok: false, error: "No answer from the app" }),
|
|
69
|
+
Math.max(0, Date.parse(data.until) - Date.now()) + 15000,
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
if (data.kind === "theme.changed") theme(data.theme);
|
|
73
|
+
// A wait is news only while it lasts, so a later listener is not told of it.
|
|
74
|
+
if (data.kind !== "rpc.waiting") latest.set(data.kind, data);
|
|
75
|
+
for (const listener of listeners) listener(data);
|
|
76
|
+
};
|
|
77
|
+
port.start();
|
|
78
|
+
theme(said.theme);
|
|
79
|
+
const request = (op, fields = {}) =>
|
|
80
|
+
new Promise((resolve, reject) => {
|
|
81
|
+
queue.push({ resolve, reject, message: { ...fields, v: 1, id: String(++sequence), op } });
|
|
82
|
+
next();
|
|
83
|
+
});
|
|
84
|
+
resolve({
|
|
85
|
+
hello: said,
|
|
86
|
+
// A listener first hears the latest push of each kind that came before it.
|
|
87
|
+
on(listener) {
|
|
88
|
+
for (const push of latest.values()) listener(push);
|
|
89
|
+
listeners.add(listener);
|
|
90
|
+
return () => listeners.delete(listener);
|
|
91
|
+
},
|
|
92
|
+
request,
|
|
93
|
+
data: () => request("data.get"),
|
|
94
|
+
state: () => request("state.get"),
|
|
95
|
+
setState: (revision, data) => request("state.set", { revision, data }),
|
|
96
|
+
call: (method, input = {}) => request("rpc.call", { method, input }),
|
|
97
|
+
openAgent: (prefill) => request("open-agent", prefill === undefined ? {} : { prefill }),
|
|
98
|
+
resize: (height) =>
|
|
99
|
+
request("resize", { height: Math.min(1200, Math.max(1, Math.ceil(height))) }),
|
|
100
|
+
decline: () => request("decline"),
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
</script>
|
|
106
|
+
<script>
|
|
107
|
+
jellyView().then(async (view) => {
|
|
108
|
+
const result = await view.data();
|
|
109
|
+
const data = result?.metadata?.memoryReceipt;
|
|
110
|
+
const receipt = document.getElementById("receipt");
|
|
111
|
+
const where = document.getElementById("where");
|
|
112
|
+
const ACTIONS = ["remembered", "corrected", "confirmed", "retired", "restored", "committed"];
|
|
113
|
+
const yes = data && data.v === 1 && typeof data.id === "string" && ACTIONS.includes(data.action);
|
|
114
|
+
if (!yes) {
|
|
115
|
+
receipt.textContent = "Receipt details are not available for this result.";
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const said = { remembered: "Remembered", corrected: "Corrected", confirmed: "Confirmed", retired: "Retired", restored: "Restored", committed: "Commitment added" }[data.action];
|
|
119
|
+
// Memory's own text is data: it is set as text, never as markup.
|
|
120
|
+
receipt.textContent = typeof data.title === "string" && data.title ? `${said}: ${data.title}` : said;
|
|
121
|
+
receipt.className = "";
|
|
122
|
+
const parts = [data.kind, data.type, data.status].filter((part) => typeof part === "string" && part);
|
|
123
|
+
const space = data.space;
|
|
124
|
+
const at = space && typeof space.name === "string" && space.name ? `in ${space.name}` : "";
|
|
125
|
+
where.textContent = [parts.join(" · "), at].filter(Boolean).join(" ");
|
|
126
|
+
where.className = "muted";
|
|
127
|
+
}).catch(() => { document.getElementById("receipt").textContent = "Receipt details are not available for this result."; });
|
|
128
|
+
</script>
|
|
129
|
+
</body>
|
|
130
|
+
</html>
|
package/src/erase.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Deterministic line erase for the L2 scenarios and the L3 persona.
|
|
3
|
-
*
|
|
4
|
-
* Upstream has no delete route for either layer, but both are files the
|
|
5
|
-
* backend lets a caller read and overwrite (`scenario/read`/`scenario/write`,
|
|
6
|
-
* `core/read`/`core/write`). An erase removes every line that contains the
|
|
7
|
-
* phrase, case-insensitively, and nothing else. It is a text operation, not a
|
|
8
|
-
* model call, so the preview is exactly what the write will do.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/** A phrase shorter than this would match unrelated lines. */
|
|
12
|
-
export const MIN_ERASE_CHARS = 4
|
|
13
|
-
|
|
14
|
-
function normalise(text) {
|
|
15
|
-
return String(text ?? "").toLowerCase()
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/** True when the text contains the phrase, case-insensitively. */
|
|
19
|
-
export function containsPhrase(text, phrase) {
|
|
20
|
-
const needle = normalise(phrase).trim()
|
|
21
|
-
return needle.length > 0 && normalise(text).includes(needle)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/** The lines of `content` that contain the phrase. */
|
|
25
|
-
export function matchingLines(content, phrase) {
|
|
26
|
-
return String(content ?? "")
|
|
27
|
-
.split("\n")
|
|
28
|
-
.filter((line) => containsPhrase(line, phrase))
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** `content` without the lines that contain the phrase. */
|
|
32
|
-
export function eraseLines(content, phrase) {
|
|
33
|
-
const lines = String(content ?? "").split("\n")
|
|
34
|
-
const kept = lines.filter((line) => !containsPhrase(line, phrase))
|
|
35
|
-
return { content: kept.join("\n"), removed: lines.length - kept.length }
|
|
36
|
-
}
|