@joe-broadhead/opencode-mem 0.9.2 → 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.
Files changed (64) hide show
  1. package/CHANGELOG.md +1605 -0
  2. package/README.md +135 -43
  3. package/docs/agent-protocol.md +29 -28
  4. package/docs/permissions.md +148 -0
  5. package/package.json +277 -16
  6. package/skills/mem.pages/SKILL.md +35 -16
  7. package/skills/mem.sharing/SKILL.md +39 -6
  8. package/skills/mem.sources/SKILL.md +41 -10
  9. package/skills/mem.usage/SKILL.md +47 -16
  10. package/src/backend/records.js +413 -50
  11. package/src/backend/v3.js +15 -10
  12. package/src/call-shapes.js +18 -25
  13. package/src/capture-pause.js +136 -0
  14. package/src/capture.js +7 -4
  15. package/src/collector-service.js +212 -35
  16. package/src/collector.js +186 -47
  17. package/src/commands.js +37 -0
  18. package/src/compaction.js +4 -2
  19. package/src/config.js +162 -1
  20. package/src/connect.js +353 -0
  21. package/src/copies.js +28 -3
  22. package/src/credentials.js +35 -7
  23. package/src/curation.js +33 -14
  24. package/src/events.js +144 -36
  25. package/src/forget-purge.js +377 -0
  26. package/src/forgotten.js +356 -0
  27. package/src/hooks.js +9 -4
  28. package/src/index.js +25 -6
  29. package/src/permissions.js +116 -38
  30. package/src/protocol.js +21 -11
  31. package/src/records.js +4 -1
  32. package/src/runtime.js +207 -16
  33. package/src/shapes.js +63 -0
  34. package/src/sources.js +183 -12
  35. package/src/spaces.js +58 -1
  36. package/src/spool.js +442 -64
  37. package/src/stated.js +334 -0
  38. package/src/storable.js +477 -0
  39. package/src/tools/aliases.js +36 -147
  40. package/src/tools/commitments.js +69 -12
  41. package/src/tools/held-write.js +9 -1
  42. package/src/tools/index.js +29 -44
  43. package/src/tools/ingest.js +33 -128
  44. package/src/tools/memory.js +594 -901
  45. package/src/tools/page-sections.js +147 -0
  46. package/src/tools/page.js +314 -82
  47. package/src/tools/recall-browse.js +173 -0
  48. package/src/tools/recall.js +79 -19
  49. package/src/tools/share.js +494 -131
  50. package/src/tools/shared.js +97 -19
  51. package/src/tools/spaces.js +215 -104
  52. package/src/tools/status.js +31 -3
  53. package/src/tools/wiki.js +5 -13
  54. package/src/util.js +10 -20
  55. package/src/views/contracts.js +137 -6
  56. package/src/views/overdue.js +125 -0
  57. package/src/views/profile.js +154 -0
  58. package/src/views/records-reads.js +132 -33
  59. package/src/views/rpc.js +63 -12
  60. package/src/views/shape.js +49 -0
  61. package/views/commitments.html +31 -4
  62. package/views/home.html +22 -3
  63. package/views/memory.html +126 -24
  64. package/src/erase.js +0 -36
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-vdgtd30kecxDG0rZOVmS1EnxzondTzzjjlXVGbR3enU='; 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-Q8fg8cAZZmRD62VpizjSMkhTSUfbnStU+/9BjGxdfVg='; style-src 'unsafe-inline'; base-uri 'none'; form-action 'none'">
6
6
  <title>Your memory</title>
7
7
  <style>
8
8
  :root {
@@ -16,7 +16,8 @@
16
16
  p { margin: 0 0 8px; }
17
17
  .muted { color: var(--jelly-muted, GrayText); }
18
18
  .danger { color: var(--jelly-danger, CanvasText); }
19
- .tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--jelly-border, GrayText); margin-bottom: 12px; }
19
+ /* Six tabs are wider than a phone: the row wraps, and the border runs under the last line. */
20
+ .tabs { display: flex; flex-wrap: wrap; gap: 2px 4px; border-bottom: 1px solid var(--jelly-border, GrayText); margin-bottom: 12px; }
20
21
  .tab {
21
22
  font: inherit; color: var(--jelly-muted, GrayText); background: none; border: 0;
22
23
  border-bottom: 2px solid transparent; padding: 6px 10px; margin-bottom: -1px; cursor: pointer;
@@ -29,9 +30,9 @@
29
30
  }
30
31
  .button.primary { background: var(--jelly-accent, Highlight); color: var(--jelly-on-accent, HighlightText); border-color: transparent; }
31
32
  .link { font: inherit; color: var(--jelly-accent, LinkText); background: none; border: 0; padding: 0; cursor: pointer; text-align: left; }
32
- dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 12px 0 0; }
33
+ dl { display: grid; grid-template-columns: fit-content(45%) minmax(0, 1fr); gap: 6px 16px; margin: 12px 0 0; }
33
34
  dt { color: var(--jelly-muted, GrayText); }
34
- dd { margin: 0; }
35
+ dd { margin: 0; overflow-wrap: anywhere; }
35
36
  ul.rows { list-style: none; margin: 0; padding: 0; }
36
37
  ul.rows > li { border-top: 1px solid var(--jelly-border, GrayText); padding: 10px 0; display: flex; gap: 12px; align-items: flex-start; }
37
38
  ul.rows > li:first-child { border-top: 0; }
@@ -53,6 +54,7 @@
53
54
  <button class="tab" role="tab" id="tab-spaces" aria-controls="panel" aria-selected="false" tabindex="-1" data-tab="spaces">Spaces</button>
54
55
  <button class="tab" role="tab" id="tab-wiki" aria-controls="panel" aria-selected="false" tabindex="-1" data-tab="wiki">Wiki</button>
55
56
  <button class="tab" role="tab" id="tab-recent" aria-controls="panel" aria-selected="false" tabindex="-1" data-tab="recent">Recent</button>
57
+ <button class="tab" role="tab" id="tab-profile" aria-controls="panel" aria-selected="false" tabindex="-1" data-tab="profile">About you</button>
56
58
  </div>
57
59
  <main id="panel" role="tabpanel" aria-labelledby="tab-overview" aria-live="polite"></main>
58
60
  <script>
@@ -145,6 +147,33 @@ function jellyView() {
145
147
  }
146
148
  </script>
147
149
  <script>
150
+ // done-message.js: the message "Mark done" drafts, for Memory's Commitments views. Paste it into
151
+ // the page's own <script>, as jelly-view.js is. The person reads and sends this text, so it holds
152
+ // no record id: "Mark 'Send the Q4 numbers' as done." The agent finds the commitment by its
153
+ // words (mem_commitments list). Only when another open commitment reads the same (spacing and
154
+ // case aside) does it add what tells them apart, in this order: the due date, the owner, the
155
+ // trigger. Only when two still match exactly does it fall back to the id.
156
+ function doneMessage(item, others) {
157
+ const words = (value) => String(value ?? "").replace(/\s+/g, " ").trim();
158
+ const fold = (value) => words(value).toLowerCase();
159
+ const said = words(item.what);
160
+ const same = (others || []).filter((other) => other !== item && other.id !== item.id && other.state === "open" && fold(other.what) === fold(item.what));
161
+ const draft = (detail) => `Mark '${said}'${detail ? ` (${detail})` : ""} as done.`;
162
+ if (same.length === 0) return draft("");
163
+ const owner = (value) => (value === "user" ? "yours" : value === "agent" ? "your agent's" : `waiting on ${words(value)}`);
164
+ const kinds = [
165
+ [(one) => words(one.when), (one) => `due ${words(one.when)}`],
166
+ [(one) => fold(one.owner), (one) => owner(one.owner)],
167
+ [(one) => fold(one.trigger), (one) => `when ${words(one.trigger)}`],
168
+ ];
169
+ for (const [read, say] of kinds) {
170
+ const mine = read(item);
171
+ if (mine && same.every((other) => read(other) !== mine)) return draft(say(item));
172
+ }
173
+ return `Mark '${said}' as done (${item.id}).`;
174
+ }
175
+ </script>
176
+ <script>
148
177
  // Memory's Settings section. Everything shown comes over the bridge; nothing is
149
178
  // fetched. Text from memory is set as text, never parsed as markup.
150
179
  const panel = document.getElementById("panel");
@@ -206,13 +235,21 @@ const plural = (count, one, many) => `${count.toLocaleString("en-GB")} ${count =
206
235
  /* ------------------------------------------------------------- not connected */
207
236
 
208
237
  function notConnected(overview) {
238
+ // Set up and not answering: nothing to change in settings, so a retry and the reason.
239
+ if (overview.state === "unreachable")
240
+ return el("div", { class: "note", role: "status" },
241
+ el("h2", {}, "Memory can't be reached just now"),
242
+ p(String(overview.reason || "").replace(/^\s*memory\s+can['\u2019]t\s+be\s+reached\s+just\s+now\s*[.:!]?\s*/i, "") || "Try again in a moment."),
243
+ p("Nothing needs changing in this plugin's settings.", "muted"),
244
+ el("div", { class: "actions" }, button("Try again", () => open("overview"))),
245
+ );
209
246
  const steps = [];
210
247
  if (overview.credential === "none")
211
248
  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.");
212
249
  if (!overview.address) steps.push("If you use your own memory service, put its address in Memory address, in this plugin's settings.");
213
250
  if (steps.length === 0) steps.push("Check Memory address and Memory key in this plugin's settings, then try again.");
214
251
  return el("div", { class: "note", role: "status" },
215
- el("h2", {}, "Memory isn't connected"),
252
+ el("h2", {}, overview.state === "refused" ? (overview.credential === "jelly" ? "Memory refused this sign-in" : "Memory refused the key") : "Memory isn't connected"),
216
253
  p(overview.reason || "Memory can't be used from this agent yet."),
217
254
  el("p", { class: "muted" }, "What to do:"),
218
255
  el("ul", {}, steps.map((step) => el("li", {}, step))),
@@ -416,7 +453,24 @@ function forgetMessage(memory) {
416
453
  return `Forget this memory: “${start}” (${memory.id}).`;
417
454
  }
418
455
 
419
- function recentRow(memory, status) {
456
+ // Whether a row is the person's own: only their own memories start a Forget message.
457
+ // A shared space's memory is managed in that space, and one held for review is
458
+ // settled in Review, so neither offers it.
459
+ function recentRow(memory, status, own, named) {
460
+ const proposed = memory.status === "proposed";
461
+ const meta = [
462
+ memory.type.replaceAll("_", " "),
463
+ named ? memory.space.name : "",
464
+ memory.status === "contested" ? "Contested" : "",
465
+ memory.stated_by === "external" ? "From someone else" : "",
466
+ date(memory.at),
467
+ ].filter(Boolean);
468
+ const body = el("div", { class: "grow" },
469
+ el("div", {}, memory.text),
470
+ el("div", { class: "meta" }, meta.join(" · ")),
471
+ proposed ? el("div", { class: "meta" }, "Waiting for your review, not saved as a memory yet. Decide it in Review.") : null,
472
+ );
473
+ if (proposed || !own) return el("li", {}, body, proposed ? el("span", { class: "badge" }, "Waiting for review") : null);
420
474
  const forget = button("Forget…", async () => {
421
475
  try {
422
476
  await view.openAgent(forgetMessage(memory));
@@ -427,12 +481,15 @@ function recentRow(memory, status) {
427
481
  fit();
428
482
  });
429
483
  forget.setAttribute("aria-label", `Forget: ${memory.text.slice(0, 60)}`);
430
- return el("li", {},
431
- el("div", { class: "grow" },
432
- el("div", {}, memory.text),
433
- el("div", { class: "meta" }, [memory.type.replaceAll("_", " "), date(memory.at)].filter(Boolean).join(" · ")),
434
- ),
435
- forget,
484
+ return el("li", {}, body, forget);
485
+ }
486
+
487
+ /** What the list could not read, in words: a space is never left out without saying so. */
488
+ function recentIncomplete(answer) {
489
+ if (answer.incomplete.length === 0) return null;
490
+ return el("div", { class: "note", role: "status" },
491
+ el("p", {}, el("strong", {}, "Some memories are missing from this list.")),
492
+ el("ul", {}, answer.incomplete.map((space) => el("li", {}, `${space.name}: ${space.reason}`))),
436
493
  );
437
494
  }
438
495
 
@@ -447,15 +504,28 @@ async function recentTab(offset = 0, list = null) {
447
504
  return fit();
448
505
  }
449
506
  const status = el("p", { class: "muted", role: "status" });
507
+ // The space is named on each row when the list covers more than the person's own.
508
+ const named = answer.spaces.length > 1 || answer.items.some((memory) => memory.space.id !== answer.space.id);
450
509
  if (list === null) {
451
510
  if (answer.items.length === 0)
452
- return show(p("Nothing remembered yet. Memories show here as your agents save them.", "muted"));
511
+ return show(
512
+ p("Nothing remembered yet. Memories show here as your agents save them.", "muted"),
513
+ recentIncomplete(answer),
514
+ );
453
515
  list = el("ul", { class: "rows" });
454
- show(p("Your newest memories, newest first. Forget starts a message for you to send."), status, list);
516
+ show(
517
+ p(named
518
+ ? "Your newest memories, and those in your shared spaces, newest first. Forget starts a message for you to send, for your own memories."
519
+ : "Your newest memories, newest first. Forget starts a message for you to send."),
520
+ recentIncomplete(answer),
521
+ status,
522
+ list,
523
+ );
455
524
  } else {
456
525
  panel.querySelector(".more")?.remove();
457
526
  }
458
- list.append(...answer.items.map((memory) => recentRow(memory, panel.querySelector("[role=status]") ?? status)));
527
+ const own = (memory) => memory.space.id === answer.space.id;
528
+ list.append(...answer.items.map((memory) => recentRow(memory, panel.querySelector("[role=status]") ?? status, own(memory), named)));
459
529
  if (answer.more) {
460
530
  const more = el("div", { class: "actions more" }, button("Show more", () => recentTab(offset + 50, list)));
461
531
  list.after(more);
@@ -465,6 +535,42 @@ async function recentTab(offset = 0, list = null) {
465
535
  fit();
466
536
  }
467
537
 
538
+ /* ----------------------------------------------------------------- about you */
539
+
540
+ // What Memory holds about the person: the persona and the scenarios under it.
541
+ // The text is Memory's own, written from conversations, so it is shown as text
542
+ // and labelled as data; erasing is asked of an agent, which previews it first.
543
+ async function profileTab() {
544
+ loading();
545
+ let answer;
546
+ try {
547
+ answer = await call("profile.read", {});
548
+ } catch (error) {
549
+ return failed(error, () => open("profile"));
550
+ }
551
+ const notes = answer.notes.length > 0
552
+ ? el("div", { class: "note", role: "status" },
553
+ answer.incomplete ? el("p", {}, el("strong", {}, "This may be less than Memory holds.")) : null,
554
+ el("ul", {}, answer.notes.map((note) => el("li", {}, note))))
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
+ const several = new Set(answer.items.map((item) => item.agent)).size > 1;
559
+ const part = (item) => el("section", { class: "spaced" },
560
+ el("h2", {}, item.layer === "persona" ? "Your profile" : item.summary || item.path),
561
+ el("div", { class: "meta" }, [item.layer === "persona" ? "" : item.path, several ? `Agent ${item.agent}` : "", date(item.updated)].filter(Boolean).join(" · ")),
562
+ el("div", { class: "page" }, item.text),
563
+ item.clipped ? p("This is long, so only its start is shown.", "muted") : null,
564
+ );
565
+ show(
566
+ p(answer.label, "muted"),
567
+ notes,
568
+ answer.items.map(part),
569
+ answer.more ? p("Memory holds more than this page shows.", "muted spaced") : null,
570
+ p("To erase something, ask an agent to forget it. It shows you what would go first.", "muted spaced"),
571
+ );
572
+ }
573
+
468
574
  /* --------------------------------------------------------------- commitments */
469
575
 
470
576
  // Words for who will do it: never colour alone, and never the stored "user".
@@ -481,11 +587,7 @@ function dueWords(item) {
481
587
  if (item.when) return item.when;
482
588
  return item.trigger ? `${item.trigger.charAt(0).toUpperCase()}${item.trigger.slice(1)}` : "No date";
483
589
  }
484
- // The message the person sends: the agent closes it with mem_commitments.
485
- function doneMessage(item) {
486
- return `Mark '${item.what.replace(/\s+/g, " ").trim()}' as done (${item.id}).`;
487
- }
488
- function commitmentRow(item, status) {
590
+ function commitmentRow(item, status, all) {
489
591
  const meta = [ownerWords(item.owner), item.project ? `Project ${item.project}` : ""].filter(Boolean).join(" · ");
490
592
  const row = el("li", {},
491
593
  el("div", { class: "grow" },
@@ -497,7 +599,7 @@ function commitmentRow(item, status) {
497
599
  if (item.state === "open") {
498
600
  const done = button("Mark done…", async () => {
499
601
  try {
500
- await view.openAgent(doneMessage(item));
602
+ await view.openAgent(doneMessage(item, all));
501
603
  status.textContent = "Your message is ready. Send it, and the agent marks this as done.";
502
604
  } catch (error) {
503
605
  status.textContent = `Couldn't start the message: ${error.message}`;
@@ -526,13 +628,13 @@ async function commitmentsTab() {
526
628
  if (openList.items.length === 0) {
527
629
  parts.push(p("Nothing due. When you ask your agent to remind you of something, it shows here.", "muted"));
528
630
  } else {
529
- parts.push(el("ul", { class: "rows" }, openList.items.map((item) => commitmentRow(item, status))));
631
+ parts.push(el("ul", { class: "rows" }, openList.items.map((item) => commitmentRow(item, status, openList.items))));
530
632
  if (openList.more) parts.push(p("Only the first 100 are shown. Ask your agent for the rest.", "muted"));
531
633
  }
532
634
  if (closed.items.length > 0) {
533
635
  parts.push(
534
636
  el("h2", { class: "spaced" }, "Done recently"),
535
- el("ul", { class: "rows" }, closed.items.slice(0, 20).map((item) => commitmentRow(item, status))),
637
+ el("ul", { class: "rows" }, closed.items.slice(0, 20).map((item) => commitmentRow(item, status, openList.items))),
536
638
  p("Closed commitments are kept for 90 days.", "muted"),
537
639
  );
538
640
  }
@@ -541,7 +643,7 @@ async function commitmentsTab() {
541
643
 
542
644
  /* ---------------------------------------------------------------------- tabs */
543
645
 
544
- const SCREENS = { overview: overviewTab, commitments: commitmentsTab, spaces: spacesTab, wiki: wikiTab, recent: () => recentTab() };
646
+ const SCREENS = { overview: overviewTab, commitments: commitmentsTab, spaces: spacesTab, wiki: wikiTab, recent: () => recentTab(), profile: profileTab };
545
647
 
546
648
  function open(name) {
547
649
  shown = name;
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
- }