@joe-broadhead/opencode-mem 0.6.2 → 0.7.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.
@@ -0,0 +1,197 @@
1
+ <!doctype html>
2
+ <html lang="en-GB">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>Memory</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
+ .notice { font-size: 12px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--jelly-border, GrayText); }
21
+ .figure { font-size: 26px; font-weight: 600; line-height: 1.15; margin: 6px 0 2px; }
22
+ .button {
23
+ font: inherit; font-size: 12px; color: var(--jelly-text, CanvasText); background: var(--jelly-raised, Canvas);
24
+ border: 1px solid var(--jelly-border, GrayText); border-radius: var(--jelly-radius, 8px); padding: 2px 8px; margin-top: 8px; cursor: pointer;
25
+ }
26
+ .button:focus-visible { outline: 2px solid var(--jelly-accent, Highlight); outline-offset: 2px; }
27
+ </style>
28
+ </head>
29
+ <body>
30
+ <main id="tile" aria-live="polite"><p class="muted">Loading…</p></main>
31
+ <script>
32
+ // jelly-view.js: a client of Jelly's view bridge. Paste it into the page's own <script>:
33
+ // a sealed page loads no script by URL and is given no global. Call jellyView() as the
34
+ // script starts; it resolves with the client when the app says hello.
35
+ function jellyView() {
36
+ return new Promise((resolve) => {
37
+ addEventListener("message", function hello(event) {
38
+ const said = event.data;
39
+ if (event.source !== parent || said?.v !== 1 || said.kind !== "hello" || !event.ports[0])
40
+ return;
41
+ removeEventListener("message", hello);
42
+ const port = event.ports[0];
43
+ const listeners = new Set();
44
+ const latest = new Map();
45
+ const queue = [];
46
+ let sequence = 0;
47
+ let current;
48
+ const theme = (tokens) => {
49
+ const style = document.documentElement.style;
50
+ for (const [name, value] of Object.entries(tokens))
51
+ if (name === "scheme") style.colorScheme = value;
52
+ else style.setProperty(`--jelly-${name}`, value);
53
+ };
54
+ // The app answers one request at a time, so requests go in turn.
55
+ const next = () => {
56
+ if (current !== undefined || queue.length === 0) return;
57
+ current = queue.shift();
58
+ current.timer = setTimeout(
59
+ () => settle({ ok: false, error: "No answer from the app" }),
60
+ 15000,
61
+ );
62
+ port.postMessage(current.message);
63
+ };
64
+ const settle = (answer) => {
65
+ const done = current;
66
+ current = undefined;
67
+ clearTimeout(done.timer);
68
+ if (answer.ok) done.resolve(answer.value);
69
+ else done.reject(new Error(answer.error));
70
+ next();
71
+ };
72
+ port.onmessage = ({ data }) => {
73
+ if (data?.v !== 1) return;
74
+ if (typeof data.kind !== "string") {
75
+ if (current !== undefined && data.re === current.message.id) settle(data);
76
+ return;
77
+ }
78
+ // A call waiting for the person is answered by `until`, not in 15 s.
79
+ if (data.kind === "rpc.waiting" && data.re === current?.message.id) {
80
+ clearTimeout(current.timer);
81
+ current.timer = setTimeout(
82
+ () => settle({ ok: false, error: "No answer from the app" }),
83
+ Math.max(0, Date.parse(data.until) - Date.now()) + 15000,
84
+ );
85
+ }
86
+ if (data.kind === "theme.changed") theme(data.theme);
87
+ // A wait is news only while it lasts, so a later listener is not told of it.
88
+ if (data.kind !== "rpc.waiting") latest.set(data.kind, data);
89
+ for (const listener of listeners) listener(data);
90
+ };
91
+ port.start();
92
+ theme(said.theme);
93
+ const request = (op, fields = {}) =>
94
+ new Promise((resolve, reject) => {
95
+ queue.push({ resolve, reject, message: { ...fields, v: 1, id: String(++sequence), op } });
96
+ next();
97
+ });
98
+ resolve({
99
+ hello: said,
100
+ // A listener first hears the latest push of each kind that came before it.
101
+ on(listener) {
102
+ for (const push of latest.values()) listener(push);
103
+ listeners.add(listener);
104
+ return () => listeners.delete(listener);
105
+ },
106
+ request,
107
+ data: () => request("data.get"),
108
+ state: () => request("state.get"),
109
+ setState: (revision, data) => request("state.set", { revision, data }),
110
+ call: (method, input = {}) => request("rpc.call", { method, input }),
111
+ openAgent: (prefill) => request("open-agent", prefill === undefined ? {} : { prefill }),
112
+ resize: (height) =>
113
+ request("resize", { height: Math.min(1200, Math.max(1, Math.ceil(height))) }),
114
+ decline: () => request("decline"),
115
+ });
116
+ });
117
+ });
118
+ }
119
+ </script>
120
+ <script>
121
+ // Memory's Home tile: whether memory is on, and how much it holds. Nothing is
122
+ // fetched; the numbers come from the plugin over the bridge.
123
+ const tile = document.getElementById("tile");
124
+ let view = null;
125
+
126
+ function el(tag, className, text) {
127
+ const node = document.createElement(tag);
128
+ if (className) node.className = className;
129
+ if (text !== undefined) node.textContent = text;
130
+ return node;
131
+ }
132
+ function state(words, dot) {
133
+ const line = el("p", "state");
134
+ const mark = el("span", `dot ${dot}`);
135
+ mark.setAttribute("aria-hidden", "true");
136
+ line.append(mark, words);
137
+ return line;
138
+ }
139
+ function fit() {
140
+ // The body's own height: the document is at least as tall as the frame, so it never shrinks.
141
+ if (view) view.resize(document.body.getBoundingClientRect().height).catch(() => undefined);
142
+ }
143
+ function show(...nodes) {
144
+ tile.replaceChildren(...nodes);
145
+ tile.removeAttribute("aria-busy");
146
+ fit();
147
+ }
148
+ const count = (value, one, many) => `${value.toLocaleString("en-GB")} ${value === 1 ? one : many}`;
149
+
150
+ async function draw() {
151
+ tile.setAttribute("aria-busy", "true");
152
+ let overview;
153
+ try {
154
+ overview = await view.call("memory.overview");
155
+ } catch (error) {
156
+ const retry = el("button", "button", "Try again");
157
+ retry.type = "button";
158
+ retry.addEventListener("click", draw);
159
+ return show(state("Couldn't read memory", "danger"), el("p", "muted", error.message), retry);
160
+ }
161
+ if (!overview.connected)
162
+ return show(
163
+ state("Not connected", "off"),
164
+ el("p", "muted", "Open Settings, then Plugins, then Memory, to connect it."),
165
+ );
166
+ const counts = overview.counts ?? { memories: 0, conversations: 0 };
167
+ const lines = [
168
+ state(overview.capture ? "Remembering" : "Not saving conversations", overview.capture ? "" : "off"),
169
+ el("p", "figure", counts.memories.toLocaleString("en-GB")),
170
+ el("p", "muted", `${counts.memories === 1 ? "memory" : "memories"} kept, from ${count(counts.conversations, "conversation", "conversations")}`),
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
+ );
185
+ show(...lines);
186
+ }
187
+
188
+ jellyView().then((client) => {
189
+ view = client;
190
+ view.on((push) => {
191
+ if (push.kind === "rpc.waiting") show(state("Waiting for you", "off"), el("p", "muted", "Allow this in Jelly to see your memory."));
192
+ });
193
+ draw();
194
+ });
195
+ </script>
196
+ </body>
197
+ </html>