@log0u7/opencode-mesh 0.33.6 → 0.34.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.
package/dist/tui.tsx CHANGED
@@ -9,8 +9,11 @@ type Theme = Context["theme"];
9
9
 
10
10
  import {
11
11
  MeshRpc,
12
+ formatMeshPoolsDialog,
13
+ formatMeshPeersDialog,
12
14
  formatMeshSidebarCollapsed,
13
15
  formatMeshSidebarExpanded,
16
+ formatMeshStatusDialog,
14
17
  type MeshSnapshot,
15
18
  type SidebarSegment,
16
19
  type SidebarTone,
@@ -21,23 +24,32 @@ const REFRESH_MS = 15_000;
21
24
  /** quota-style event refresh: debounced immediate refresh after activity. */
22
25
  const EVENT_DEBOUNCE_MS = 150;
23
26
 
24
- function dialogBody(theme: Theme, snapshot: MeshSnapshot): JSX.Element {
25
- const self = snapshot.hostname.length > 0 ? snapshot.hostname : snapshot.node_id;
26
- const peers = snapshot.peers.map((p) => (p.hostname.length > 0 ? p.hostname : p.node_id));
27
+ /** One tone-colored segment row per line (the dialog twin of sidebarBody). */
28
+ function segmentDialog(theme: Theme, lines: SidebarSegment[][]): JSX.Element {
27
29
  return (
28
- <box gap={1} paddingLeft={2} paddingRight={2} paddingBottom={1}>
29
- <text fg={theme.text.base}>
30
- <b>Mesh — coordination</b>
31
- </text>
32
- <text fg={theme.text.muted}>Node: {self}</text>
33
- <text fg={theme.text.muted}>
34
- Paired peers: {peers.length === 0 ? "none" : peers.join(", ")}
35
- </text>
36
- <text fg={theme.text.muted}>Active locks: {snapshot.active_locks}</text>
30
+ <box gap={0} paddingLeft={2} paddingRight={2} paddingBottom={1}>
31
+ <For each={lines}>
32
+ {(line) => (
33
+ <box flexDirection="row" gap={0}>
34
+ <For each={line}>
35
+ {(seg) => (
36
+ <text fg={toneFg(theme, seg.tone)} wrapMode="none">
37
+ {seg.tone === "entity" ? <b>{seg.text}</b> : seg.text}
38
+ </text>
39
+ )}
40
+ </For>
41
+ </box>
42
+ )}
43
+ </For>
37
44
  </box>
38
45
  );
39
46
  }
40
47
 
48
+ /** A small focused dialog: one bold section title, then segment lines. */
49
+ function sectionDialog(theme: Theme, title: string, lines: SidebarSegment[][]): JSX.Element {
50
+ return segmentDialog(theme, [[{ text: title, tone: "entity" }], ...lines]);
51
+ }
52
+
41
53
  /** The theme's attention color for the alert glyph: warning or error when the
42
54
  * theme exposes one, plain text otherwise. */
43
55
  function alertFg(theme: Theme): string {
@@ -191,28 +203,146 @@ export default Plugin.define({
191
203
  });
192
204
 
193
205
  // Keymap layers are disposed with the plugin; no manual disposer here.
206
+ const MESH_USAGE = "usage: /mesh [status|pools|peers|board <pool>|inbox [agent]|toggle]";
207
+ const toast = (message: string, variant: "info" | "warning" = "info") =>
208
+ context.ui.toast.show({ title: "Mesh", message, variant });
209
+ const unreachable = () => toast("Server unreachable");
210
+ const show = (body: () => JSX.Element) => {
211
+ context.ui.dialog.show(body);
212
+ context.ui.dialog.set({ size: "medium" });
213
+ };
214
+ const statusDialog = (snap: MeshSnapshot): JSX.Element =>
215
+ segmentDialog(theme, [
216
+ [{ text: "Mesh · coordination", tone: "entity" }],
217
+ ...formatMeshStatusDialog(snap, { width: 40 }),
218
+ ]);
219
+ const dispatch = async (input: string | undefined) => {
220
+ const words = (input ?? "").trim().split(/\s+/).filter(Boolean);
221
+ const [cmd, arg] = words;
222
+ switch (cmd ?? "") {
223
+ case "":
224
+ case "status": {
225
+ await refresh(currentSession);
226
+ const snap = snapshot();
227
+ if (!snap) {
228
+ unreachable();
229
+ return;
230
+ }
231
+ show(() => statusDialog(snap));
232
+ return;
233
+ }
234
+ case "pools": {
235
+ let snap = snapshot();
236
+ if (!snap) {
237
+ await refresh(currentSession);
238
+ snap = snapshot();
239
+ }
240
+ if (!snap) {
241
+ unreachable();
242
+ return;
243
+ }
244
+ show(() => sectionDialog(theme, "Mesh · pools", formatMeshPoolsDialog(snap)));
245
+ return;
246
+ }
247
+ case "peers": {
248
+ let snap = snapshot();
249
+ if (!snap) {
250
+ await refresh(currentSession);
251
+ snap = snapshot();
252
+ }
253
+ if (!snap) {
254
+ unreachable();
255
+ return;
256
+ }
257
+ show(() => sectionDialog(theme, "Mesh · peers", formatMeshPeersDialog(snap)));
258
+ return;
259
+ }
260
+ case "board": {
261
+ if (!arg) {
262
+ toast("usage: /mesh board <pool>", "warning");
263
+ return;
264
+ }
265
+ try {
266
+ const result = (await mesh.board({ pool: arg })) as {
267
+ rows: Array<{ box: string; line: string }>;
268
+ };
269
+ show(() =>
270
+ sectionDialog(
271
+ theme,
272
+ `Mesh · board ${arg}`,
273
+ result.rows.length === 0
274
+ ? [[{ text: "(empty board)", tone: "value" }]]
275
+ : result.rows.map((row) => [
276
+ { text: `${row.box} `, tone: "qualifier" },
277
+ { text: row.line, tone: "value" },
278
+ ]),
279
+ ),
280
+ );
281
+ } catch {
282
+ unreachable();
283
+ }
284
+ return;
285
+ }
286
+ case "inbox": {
287
+ try {
288
+ const result = (await mesh.inbox(arg ? { box: arg } : {})) as {
289
+ rows: Array<{ box: string; from_box: string | null; subject: string; age_s: number }>;
290
+ total: number;
291
+ };
292
+ show(() =>
293
+ sectionDialog(
294
+ theme,
295
+ `Mesh · inbox${arg ? ` ${arg}` : ""}`,
296
+ result.rows.length === 0
297
+ ? [[{ text: "inbox clear", tone: "value" }]]
298
+ : ([
299
+ ...result.rows.map((row): SidebarSegment[] => [
300
+ { text: "● ", tone: "alert" },
301
+ { text: row.subject.slice(0, 40), tone: "qualifier" },
302
+ { text: ` ${row.from_box ?? "?"} ${row.box}`, tone: "value" },
303
+ {
304
+ text: ` ${row.age_s < 90 ? `${row.age_s}s` : `${Math.round(row.age_s / 60)}m`} ago`,
305
+ tone: "value",
306
+ },
307
+ ]),
308
+ ...(result.total > result.rows.length
309
+ ? ([
310
+ [
311
+ {
312
+ text: `+${result.total - result.rows.length} more unread`,
313
+ tone: "value",
314
+ },
315
+ ],
316
+ ] as SidebarSegment[][])
317
+ : []),
318
+ ] as SidebarSegment[][]),
319
+ ),
320
+ );
321
+ } catch {
322
+ unreachable();
323
+ }
324
+ return;
325
+ }
326
+ case "toggle":
327
+ toggleCollapsed();
328
+ return;
329
+ default:
330
+ toast(MESH_USAGE, "warning");
331
+ }
332
+ };
194
333
  context.keymap.layer(() => ({
195
334
  mode: "global",
196
335
  commands: [
197
336
  {
198
337
  id: "mesh.status",
199
- title: "Mesh status",
338
+ title: "Mesh",
339
+ description:
340
+ "Mesh /mesh shows the status. Subcommands: pools, peers, board <pool>, inbox [agent], toggle",
200
341
  group: "Mesh",
201
- slash: { name: "mesh" },
342
+ slash: { name: "mesh", arguments: true },
202
343
  palette: true,
203
- run: async () => {
204
- await refresh(currentSession);
205
- const current = snapshot();
206
- if (!current) {
207
- context.ui.toast.show({
208
- title: "Mesh",
209
- message: "Server unreachable",
210
- variant: "info",
211
- });
212
- return;
213
- }
214
- context.ui.dialog.show(() => dialogBody(theme, current));
215
- context.ui.dialog.set({ size: "medium" });
344
+ run: async (input?: string) => {
345
+ await dispatch(input);
216
346
  },
217
347
  },
218
348
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@log0u7/opencode-mesh",
3
- "version": "0.33.6",
3
+ "version": "0.34.1",
4
4
  "description": "Multi-session coordination for OpenCode: session coordination on one machine and a peer pool across LAN or Tailscale, with pairing, mailbox, and worktree locks.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",