@joe-broadhead/opencode-mem 0.7.0 → 0.8.0

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.
@@ -0,0 +1,226 @@
1
+ <!doctype html>
2
+ <html lang="en-GB">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>Commitments</title>
6
+ <style>
7
+ :root {
8
+ color: var(--jelly-text, CanvasText);
9
+ background: var(--jelly-surface, Canvas);
10
+ font: 14px/1.4 var(--jelly-font, system-ui, sans-serif);
11
+ }
12
+ * { box-sizing: border-box; }
13
+ body { margin: 0; padding: 2px; }
14
+ p { margin: 0; }
15
+ .muted { color: var(--jelly-muted, GrayText); font-size: 12px; }
16
+ .state { font-weight: 600; display: flex; align-items: center; gap: 6px; }
17
+ .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--jelly-accent, Highlight); flex: none; }
18
+ .dot.off { background: transparent; border: 1.5px solid var(--jelly-muted, GrayText); }
19
+ .dot.danger { background: var(--jelly-danger, CanvasText); }
20
+ ul { list-style: none; margin: 4px 0 0; padding: 0; }
21
+ li { display: flex; gap: 8px; align-items: flex-start; padding: 6px 0; border-top: 1px solid var(--jelly-border, GrayText); }
22
+ li:first-child { border-top: 0; }
23
+ .grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }
24
+ .when { font-size: 12px; color: var(--jelly-muted, GrayText); }
25
+ .when.overdue { color: var(--jelly-danger, CanvasText); font-weight: 600; }
26
+ .button {
27
+ font: inherit; font-size: 12px; color: var(--jelly-text, CanvasText); background: var(--jelly-raised, Canvas);
28
+ border: 1px solid var(--jelly-border, GrayText); border-radius: var(--jelly-radius, 8px); padding: 2px 8px; cursor: pointer; white-space: nowrap;
29
+ }
30
+ .button:focus-visible { outline: 2px solid var(--jelly-accent, Highlight); outline-offset: 2px; }
31
+ .more { margin-top: 6px; }
32
+ </style>
33
+ </head>
34
+ <body>
35
+ <main id="card" aria-live="polite"><p class="muted">Loading…</p></main>
36
+ <script>
37
+ // jelly-view.js: a client of Jelly's view bridge. Paste it into the page's own <script>:
38
+ // a sealed page loads no script by URL and is given no global. Call jellyView() as the
39
+ // script starts; it resolves with the client when the app says hello.
40
+ function jellyView() {
41
+ return new Promise((resolve) => {
42
+ addEventListener("message", function hello(event) {
43
+ const said = event.data;
44
+ if (event.source !== parent || said?.v !== 1 || said.kind !== "hello" || !event.ports[0])
45
+ return;
46
+ removeEventListener("message", hello);
47
+ const port = event.ports[0];
48
+ const listeners = new Set();
49
+ const latest = new Map();
50
+ const queue = [];
51
+ let sequence = 0;
52
+ let current;
53
+ const theme = (tokens) => {
54
+ const style = document.documentElement.style;
55
+ for (const [name, value] of Object.entries(tokens))
56
+ if (name === "scheme") style.colorScheme = value;
57
+ else style.setProperty(`--jelly-${name}`, value);
58
+ };
59
+ // The app answers one request at a time, so requests go in turn.
60
+ const next = () => {
61
+ if (current !== undefined || queue.length === 0) return;
62
+ current = queue.shift();
63
+ current.timer = setTimeout(
64
+ () => settle({ ok: false, error: "No answer from the app" }),
65
+ 15000,
66
+ );
67
+ port.postMessage(current.message);
68
+ };
69
+ const settle = (answer) => {
70
+ const done = current;
71
+ current = undefined;
72
+ clearTimeout(done.timer);
73
+ if (answer.ok) done.resolve(answer.value);
74
+ else done.reject(new Error(answer.error));
75
+ next();
76
+ };
77
+ port.onmessage = ({ data }) => {
78
+ if (data?.v !== 1) return;
79
+ if (typeof data.kind !== "string") {
80
+ if (current !== undefined && data.re === current.message.id) settle(data);
81
+ return;
82
+ }
83
+ // A call waiting for the person is answered by `until`, not in 15 s.
84
+ if (data.kind === "rpc.waiting" && data.re === current?.message.id) {
85
+ clearTimeout(current.timer);
86
+ current.timer = setTimeout(
87
+ () => settle({ ok: false, error: "No answer from the app" }),
88
+ Math.max(0, Date.parse(data.until) - Date.now()) + 15000,
89
+ );
90
+ }
91
+ if (data.kind === "theme.changed") theme(data.theme);
92
+ // A wait is news only while it lasts, so a later listener is not told of it.
93
+ if (data.kind !== "rpc.waiting") latest.set(data.kind, data);
94
+ for (const listener of listeners) listener(data);
95
+ };
96
+ port.start();
97
+ theme(said.theme);
98
+ const request = (op, fields = {}) =>
99
+ new Promise((resolve, reject) => {
100
+ queue.push({ resolve, reject, message: { ...fields, v: 1, id: String(++sequence), op } });
101
+ next();
102
+ });
103
+ resolve({
104
+ hello: said,
105
+ // A listener first hears the latest push of each kind that came before it.
106
+ on(listener) {
107
+ for (const push of latest.values()) listener(push);
108
+ listeners.add(listener);
109
+ return () => listeners.delete(listener);
110
+ },
111
+ request,
112
+ data: () => request("data.get"),
113
+ state: () => request("state.get"),
114
+ setState: (revision, data) => request("state.set", { revision, data }),
115
+ call: (method, input = {}) => request("rpc.call", { method, input }),
116
+ openAgent: (prefill) => request("open-agent", prefill === undefined ? {} : { prefill }),
117
+ resize: (height) =>
118
+ request("resize", { height: Math.min(1200, Math.max(1, Math.ceil(height))) }),
119
+ decline: () => request("decline"),
120
+ });
121
+ });
122
+ });
123
+ }
124
+ </script>
125
+ <script>
126
+ // Memory's Commitments card: what you promised, what your agent promised, and
127
+ // what you're waiting on, overdue first. Nothing is fetched; the list comes
128
+ // from the plugin over the bridge. Marking one done starts a message for the
129
+ // person to send: the agent closes it with mem_commitments, as Forget works.
130
+ const card = document.getElementById("card");
131
+ const SHOWN = 8;
132
+ let view = null;
133
+
134
+ function el(tag, className, text) {
135
+ const node = document.createElement(tag);
136
+ if (className) node.className = className;
137
+ if (text !== undefined) node.textContent = text;
138
+ return node;
139
+ }
140
+ function state(words, dot) {
141
+ const line = el("p", "state");
142
+ const mark = el("span", `dot ${dot}`);
143
+ mark.setAttribute("aria-hidden", "true");
144
+ line.append(mark, words);
145
+ return line;
146
+ }
147
+ function fit() {
148
+ // The body's own height: the document is at least as tall as the frame, so it never shrinks.
149
+ if (view) view.resize(document.body.getBoundingClientRect().height).catch(() => undefined);
150
+ }
151
+ function show(...nodes) {
152
+ card.replaceChildren(...nodes);
153
+ card.removeAttribute("aria-busy");
154
+ fit();
155
+ }
156
+ // Who will do it, in words.
157
+ function ownerWords(owner) {
158
+ if (owner === "user") return "You";
159
+ if (owner === "agent") return "Your agent";
160
+ return `Waiting on ${owner}`;
161
+ }
162
+ // When it is due, in words: overdue is said, never shown by colour alone.
163
+ function dueWords(item) {
164
+ if (item.overdue) return `Overdue since ${item.when}`;
165
+ if (item.dueToday) return `Due today${item.when.includes(":") ? `, ${item.when.split(" ").pop()}` : ""}`;
166
+ if (item.when) return item.when;
167
+ return item.trigger ? `${item.trigger.charAt(0).toUpperCase()}${item.trigger.slice(1)}` : "No date";
168
+ }
169
+ function row(item, status) {
170
+ const line = el("li");
171
+ const words = el("div", "grow");
172
+ words.append(el("div", "", item.what), el("div", item.overdue ? "when overdue" : "when", `${dueWords(item)} · ${ownerWords(item.owner)}`));
173
+ const done = el("button", "button", "Mark done…");
174
+ done.type = "button";
175
+ done.setAttribute("aria-label", `Mark done: ${item.what.slice(0, 60)}`);
176
+ done.addEventListener("click", async () => {
177
+ try {
178
+ await view.openAgent(`Mark '${item.what.replace(/\s+/g, " ").trim()}' as done (${item.id}).`);
179
+ status.textContent = "Your message is ready. Send it, and the agent marks this as done.";
180
+ } catch (error) {
181
+ status.textContent = `Couldn't start the message: ${error.message}`;
182
+ }
183
+ fit();
184
+ });
185
+ line.append(words, done);
186
+ return line;
187
+ }
188
+
189
+ async function draw() {
190
+ card.setAttribute("aria-busy", "true");
191
+ let answer;
192
+ try {
193
+ answer = await view.call("commitments.list", { state: "open" });
194
+ } catch (error) {
195
+ const retry = el("button", "button", "Try again");
196
+ retry.type = "button";
197
+ retry.addEventListener("click", draw);
198
+ return show(state("Couldn't read your commitments", "danger"), el("p", "muted", error.message), retry);
199
+ }
200
+ if (answer.items.length === 0) {
201
+ return show(el("p", "muted", "Nothing due. When you ask your agent to remind you of something, it shows here."));
202
+ }
203
+ const overdue = answer.items.filter((item) => item.overdue).length;
204
+ const status = el("p", "muted");
205
+ status.setAttribute("role", "status");
206
+ const list = el("ul");
207
+ list.append(...answer.items.slice(0, SHOWN).map((item) => row(item, status)));
208
+ const head = overdue > 0
209
+ ? state(`${overdue} overdue, ${answer.items.length} open`, "danger")
210
+ : state(`${answer.items.length} open · today is ${answer.today}`, "");
211
+ const nodes = [head, list, status];
212
+ const rest = answer.items.length - SHOWN + (answer.more ? 1 : 0);
213
+ if (rest > 0) nodes.push(el("p", "muted more", `${answer.more ? "More than " : ""}${rest} more in Settings → Plugins → Memory → Commitments.`));
214
+ show(...nodes);
215
+ }
216
+
217
+ jellyView().then((client) => {
218
+ view = client;
219
+ view.on((push) => {
220
+ if (push.kind === "rpc.waiting") show(state("Waiting for you", "off"), el("p", "muted", "Allow this in Jelly to see your commitments."));
221
+ });
222
+ draw();
223
+ });
224
+ </script>
225
+ </body>
226
+ </html>
package/views/home.html CHANGED
@@ -17,6 +17,7 @@
17
17
  .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--jelly-accent, Highlight); flex: none; }
18
18
  .dot.off { background: transparent; border: 1.5px solid var(--jelly-muted, GrayText); }
19
19
  .dot.danger { background: var(--jelly-danger, CanvasText); }
20
+ .notice { font-size: 12px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--jelly-border, GrayText); }
20
21
  .figure { font-size: 26px; font-weight: 600; line-height: 1.15; margin: 6px 0 2px; }
21
22
  .button {
22
23
  font: inherit; font-size: 12px; color: var(--jelly-text, CanvasText); background: var(--jelly-raised, Canvas);
@@ -169,6 +170,18 @@ async function draw() {
169
170
  el("p", "muted", `${counts.memories === 1 ? "memory" : "memories"} kept, from ${count(counts.conversations, "conversation", "conversations")}`),
170
171
  ];
171
172
  if (overview.health !== "ok") lines.push(el("p", "muted", "Memory can't be reached just now."));
173
+ // The notice: memory is on for every Jelly user, so the tile says plainly what
174
+ // it saves and where to turn it off. A view cannot open Settings, so it names
175
+ // the place.
176
+ lines.push(
177
+ el(
178
+ "p",
179
+ "notice",
180
+ overview.capture
181
+ ? "Memory saves your finished conversations to your private memory. You can turn this off in Settings → Plugins → Memory."
182
+ : "Memory isn't saving conversations. Turn it on in Settings → Plugins → Memory.",
183
+ ),
184
+ );
172
185
  show(...lines);
173
186
  }
174
187
 
package/views/memory.html CHANGED
@@ -37,6 +37,7 @@
37
37
  .grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }
38
38
  .meta { font-size: 12px; color: var(--jelly-muted, GrayText); }
39
39
  .badge { font-size: 12px; border: 1px solid var(--jelly-border, GrayText); border-radius: 999px; padding: 0 8px; white-space: nowrap; }
40
+ .badge.overdue { border-color: var(--jelly-danger, CanvasText); font-weight: 600; }
40
41
  .note { border: 1px solid var(--jelly-border, GrayText); border-radius: var(--jelly-radius, 8px); padding: 10px 12px; margin: 8px 0; }
41
42
  .page { white-space: pre-wrap; overflow-wrap: anywhere; border: 1px solid var(--jelly-border, GrayText); border-radius: var(--jelly-radius, 8px); padding: 10px 12px; margin-top: 8px; }
42
43
  .actions { display: flex; gap: 8px; margin-top: 10px; align-items: center; flex-wrap: wrap; }
@@ -47,6 +48,7 @@
47
48
  <body>
48
49
  <div class="tabs" role="tablist" aria-label="Memory">
49
50
  <button class="tab" role="tab" id="tab-overview" aria-controls="panel" aria-selected="true" data-tab="overview">Overview</button>
51
+ <button class="tab" role="tab" id="tab-commitments" aria-controls="panel" aria-selected="false" tabindex="-1" data-tab="commitments">Commitments</button>
50
52
  <button class="tab" role="tab" id="tab-spaces" aria-controls="panel" aria-selected="false" tabindex="-1" data-tab="spaces">Spaces</button>
51
53
  <button class="tab" role="tab" id="tab-wiki" aria-controls="panel" aria-selected="false" tabindex="-1" data-tab="wiki">Wiki</button>
52
54
  <button class="tab" role="tab" id="tab-recent" aria-controls="panel" aria-selected="false" tabindex="-1" data-tab="recent">Recent</button>
@@ -240,10 +242,28 @@ function captureRows(overview) {
240
242
  ];
241
243
  if (saved !== null && saved !== overview.capture)
242
244
  rows.push(`Saved as ${saved ? "on" : "off"}; this takes effect when the agent next starts.`);
243
- rows.push("Change it with Remember conversations, in this plugin's settings.");
244
245
  return rows.map((row, index) => el("div", index === 0 ? {} : { class: "meta" }, row));
245
246
  }
246
247
 
248
+ /**
249
+ * The notice at the top of the Overview: what is saved, what "private" means,
250
+ * and where the switch is. A view cannot open a setting, so it names it.
251
+ */
252
+ function captureNotice(overview) {
253
+ const where = "Remember conversations, in this plugin's settings (Settings → Plugins → Memory)";
254
+ if (!overview.capture)
255
+ return el("div", { class: "note", role: "note" },
256
+ el("p", {}, el("strong", {}, "Memory isn't saving your conversations.")),
257
+ p("Your agents still recall what memory holds, and remember what you ask them to."),
258
+ p(`To save your finished conversations to your private memory, turn on ${where}.`, "muted"),
259
+ );
260
+ return el("div", { class: "note", role: "note" },
261
+ el("p", {}, el("strong", {}, "Memory saves your finished conversations to your private memory.")),
262
+ p("Private means only you, and your agents working for you, can read it. Nothing goes to a shared space unless you choose to share it, and Jelly asks you first."),
263
+ p(`To stop, turn off ${where}.`, "muted"),
264
+ );
265
+ }
266
+
247
267
  async function overviewTab() {
248
268
  loading();
249
269
  let overview;
@@ -257,6 +277,7 @@ async function overviewTab() {
257
277
  const signedIn = [SIGNED_IN[overview.credential] ?? SIGNED_IN.none];
258
278
  if (overview.refused) signedIn.push(`${REFUSED[overview.refused] ?? "Jelly couldn't sign you in"}, so the saved key is used.`);
259
279
  show(
280
+ captureNotice(overview),
260
281
  p("Memory keeps your decisions, preferences and notes, so your agents can use them in later conversations."),
261
282
  el("dl", {},
262
283
  el("dt", {}, "Status"),
@@ -438,9 +459,83 @@ async function recentTab(offset = 0, list = null) {
438
459
  fit();
439
460
  }
440
461
 
462
+ /* --------------------------------------------------------------- commitments */
463
+
464
+ // Words for who will do it: never colour alone, and never the stored "user".
465
+ function ownerWords(owner) {
466
+ if (owner === "user") return "You";
467
+ if (owner === "agent") return "Your agent";
468
+ return `Waiting on ${owner}`;
469
+ }
470
+ // When it is due, in words: overdue is said, not only shown.
471
+ function dueWords(item) {
472
+ if (item.state !== "open") return item.closed ? `${item.state === "done" ? "Done" : "Cancelled"} ${item.closed}` : item.state === "done" ? "Done" : "Cancelled";
473
+ if (item.overdue) return `Overdue since ${item.when}`;
474
+ if (item.dueToday) return `Due today${item.when.includes(":") ? `, ${item.when.split(" ").pop()}` : ""}`;
475
+ if (item.when) return item.when;
476
+ return item.trigger ? `${item.trigger.charAt(0).toUpperCase()}${item.trigger.slice(1)}` : "No date";
477
+ }
478
+ // The message the person sends: the agent closes it with mem_commitments.
479
+ function doneMessage(item) {
480
+ return `Mark '${item.what.replace(/\s+/g, " ").trim()}' as done (${item.id}).`;
481
+ }
482
+ function commitmentRow(item, status) {
483
+ const meta = [ownerWords(item.owner), item.project ? `Project ${item.project}` : ""].filter(Boolean).join(" · ");
484
+ const row = el("li", {},
485
+ el("div", { class: "grow" },
486
+ el("div", {}, item.what),
487
+ el("div", { class: "meta" }, meta),
488
+ ),
489
+ el("span", { class: item.overdue ? "badge overdue" : "badge" }, dueWords(item)),
490
+ );
491
+ if (item.state === "open") {
492
+ const done = button("Mark done…", async () => {
493
+ try {
494
+ await view.openAgent(doneMessage(item));
495
+ status.textContent = "Your message is ready. Send it, and the agent marks this as done.";
496
+ } catch (error) {
497
+ status.textContent = `Couldn't start the message: ${error.message}`;
498
+ }
499
+ fit();
500
+ });
501
+ done.setAttribute("aria-label", `Mark done: ${item.what.slice(0, 60)}`);
502
+ row.append(done);
503
+ }
504
+ return row;
505
+ }
506
+
507
+ async function commitmentsTab() {
508
+ loading();
509
+ let openList, closed;
510
+ try {
511
+ [openList, closed] = await Promise.all([call("commitments.list", { state: "open" }), call("commitments.list", { state: "closed" })]);
512
+ } catch (error) {
513
+ return failed(error, () => open("commitments"));
514
+ }
515
+ const status = el("p", { class: "muted", role: "status" });
516
+ const parts = [
517
+ p(`Things you or your agent promised, and what you're waiting on from others. Today is ${openList.today}. Mark done starts a message for you to send.`),
518
+ status,
519
+ ];
520
+ if (openList.items.length === 0) {
521
+ parts.push(p("Nothing due. When you ask your agent to remind you of something, it shows here.", "muted"));
522
+ } else {
523
+ parts.push(el("ul", { class: "rows" }, openList.items.map((item) => commitmentRow(item, status))));
524
+ if (openList.more) parts.push(p("Only the first 100 are shown. Ask your agent for the rest.", "muted"));
525
+ }
526
+ if (closed.items.length > 0) {
527
+ parts.push(
528
+ el("h2", { class: "spaced" }, "Done recently"),
529
+ el("ul", { class: "rows" }, closed.items.slice(0, 20).map((item) => commitmentRow(item, status))),
530
+ p("Closed commitments are kept for 90 days.", "muted"),
531
+ );
532
+ }
533
+ show(...parts);
534
+ }
535
+
441
536
  /* ---------------------------------------------------------------------- tabs */
442
537
 
443
- const SCREENS = { overview: overviewTab, spaces: spacesTab, wiki: wikiTab, recent: () => recentTab() };
538
+ const SCREENS = { overview: overviewTab, commitments: commitmentsTab, spaces: spacesTab, wiki: wikiTab, recent: () => recentTab() };
444
539
 
445
540
  function open(name) {
446
541
  shown = name;