@joe-broadhead/opencode-mem 0.9.12 → 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/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.methods["review.list"]({}), overdueNotices()])
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 [{ key: `proposal:${item.id}`, category: "request", label: "Proposal", name: "Memory", line: title || "A proposal is waiting for review", at: item.created }]
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-Q8fg8cAZZmRD62VpizjSMkhTSUfbnStU+/9BjGxdfVg='; style-src 'unsafe-inline'; base-uri 'none'; form-action 'none'">
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>