@log0u7/opencode-mesh 0.20.0 → 0.22.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.
package/dist/tui.tsx CHANGED
@@ -2,39 +2,25 @@
2
2
 
3
3
  import { Plugin } from "@opencode/plugin/tui";
4
4
  import type { JSX } from "@opentui/solid";
5
- import { For, Show, createSignal } from "solid-js";
5
+ import { For, createSignal } from "solid-js";
6
6
 
7
7
  type Context = Plugin.Context;
8
8
  type Theme = Context["theme"];
9
9
 
10
- import { MeshRpc, formatMeshSidebar, type MeshSnapshot } from "./rpc.js";
10
+ import {
11
+ MeshRpc,
12
+ formatMeshSidebarCollapsed,
13
+ formatMeshSidebarExpanded,
14
+ type MeshSnapshot,
15
+ type SidebarSegment,
16
+ type SidebarTone,
17
+ } from "./rpc.js";
11
18
  import { createSidebarState, type SidebarRpc } from "./sidebar-state.js";
12
19
 
13
20
  const REFRESH_MS = 15_000;
14
21
  /** quota-style event refresh: debounced immediate refresh after activity. */
15
22
  const EVENT_DEBOUNCE_MS = 150;
16
23
 
17
- function themedBody(theme: Theme, lines: () => string[] | null, unread: number): JSX.Element {
18
- return (
19
- <Show when={lines()} keyed>
20
- {(current) => (
21
- <box gap={0}>
22
- <For each={current}>
23
- {(line, index) => (
24
- <text
25
- fg={index() === 0 && unread > 0 ? theme.text.base : theme.text.muted}
26
- wrapMode="none"
27
- >
28
- {line}
29
- </text>
30
- )}
31
- </For>
32
- </box>
33
- )}
34
- </Show>
35
- );
36
- }
37
-
38
24
  function dialogBody(theme: Theme, snapshot: MeshSnapshot): JSX.Element {
39
25
  const self = snapshot.hostname.length > 0 ? snapshot.hostname : snapshot.node_id;
40
26
  const peers = snapshot.peers.map((p) => (p.hostname.length > 0 ? p.hostname : p.node_id));
@@ -52,6 +38,58 @@ function dialogBody(theme: Theme, snapshot: MeshSnapshot): JSX.Element {
52
38
  );
53
39
  }
54
40
 
41
+ /** The theme's attention color for the alert glyph: warning or error when the
42
+ * theme exposes one, plain text otherwise. */
43
+ function alertFg(theme: Theme): string {
44
+ const palette = theme as {
45
+ warning?: { base?: string };
46
+ error?: { base?: string };
47
+ text: { base: string };
48
+ };
49
+ return palette.warning?.base ?? palette.error?.base ?? theme.text.base;
50
+ }
51
+
52
+ /** Quota tone tiers to theme colors: entity and qualifier render in text,
53
+ * values in muted, the alert glyph in the attention color. */
54
+ function toneFg(theme: Theme, tone: SidebarTone): string {
55
+ if (tone === "value") {
56
+ return theme.text.muted;
57
+ }
58
+ if (tone === "alert") {
59
+ return alertFg(theme);
60
+ }
61
+ return theme.text.base;
62
+ }
63
+
64
+ /** One row of tone-colored segments; entity tones render bold. wrapMode="none"
65
+ * everywhere: long lines clip instead of wrapping. */
66
+ function segmentRow(theme: Theme, line: SidebarSegment[], onClick?: () => void): JSX.Element {
67
+ return (
68
+ <box flexDirection="row" gap={0}>
69
+ {line.map((seg) => (
70
+ <text
71
+ fg={toneFg(theme, seg.tone)}
72
+ wrapMode="none"
73
+ {...(onClick ? { onMouseDown: onClick } : {})}
74
+ >
75
+ {seg.tone === "entity" ? <b>{seg.text}</b> : seg.text}
76
+ </text>
77
+ ))}
78
+ </box>
79
+ );
80
+ }
81
+
82
+ /** The expanded v4 body: clickable bold header row, then one segment row per
83
+ * formatter line so each tone tier gets its own color. */
84
+ function sidebarBody(theme: Theme, lines: SidebarSegment[][], onToggle: () => void): JSX.Element {
85
+ return (
86
+ <box gap={0}>
87
+ {segmentRow(theme, lines[0] ?? [], onToggle)}
88
+ <For each={lines.slice(1)}>{(line) => segmentRow(theme, line)}</For>
89
+ </box>
90
+ );
91
+ }
92
+
55
93
  export default Plugin.define({
56
94
  id: "@log0u7/opencode-mesh.tui",
57
95
  setup(context: Context) {
@@ -66,11 +104,10 @@ export default Plugin.define({
66
104
  const meshRpc = context.client.rpc(MeshRpc) as unknown as SidebarRpc;
67
105
  const [store, mutate] = createSidebarState(context.storage, meshRpc);
68
106
  const [snapshot, setSnapshot] = createSignal<MeshSnapshot | null>(null);
69
- const [lines, setLines] = createSignal<string[] | null>(null);
70
107
 
71
108
  // Live sidebar: poll the server-side snapshot over RPC. On a v1 host (no
72
- // RPC) or while the server is unreachable, the slot stays hidden. The
73
- // sessionID arrives with the slot input (see register below).
109
+ // RPC) or while the server is unreachable, the slot falls back to the bare
110
+ // toggle line. The sessionID arrives with the slot input (see register).
74
111
  const mesh = context.client.rpc(MeshRpc);
75
112
  // Snapshots per session: switching tabs must show THAT session's state
76
113
  // instantly (a single "latest" cache made the panel stale on tab switch).
@@ -83,12 +120,9 @@ export default Plugin.define({
83
120
  snapBySession.set(sid, snap);
84
121
  if (currentSession === sid) {
85
122
  setSnapshot(snap);
86
- // The body renders only when expanded: keep the expanded shape ready
87
- // so toggling shows it without waiting for the next refresh.
88
- setLines(formatMeshSidebar(snap, false));
89
123
  }
90
124
  } catch {
91
- if (currentSession === sid) setLines(null);
125
+ if (currentSession === sid) setSnapshot(null);
92
126
  }
93
127
  };
94
128
  const timer = setInterval(() => void refresh(currentSession), REFRESH_MS);
@@ -111,6 +145,14 @@ export default Plugin.define({
111
145
  }
112
146
  })();
113
147
 
148
+ const toggleCollapsed = () => {
149
+ // Formatting is pure: flipping the store re-renders the sidebar from the
150
+ // snapshot already in hand, no refetch needed.
151
+ void mutate((draft) => {
152
+ draft.collapsed = !draft.collapsed;
153
+ });
154
+ };
155
+
114
156
  const unregister = context.ui.slot({
115
157
  append: "sidebar.content",
116
158
  render: (input) => {
@@ -122,36 +164,26 @@ export default Plugin.define({
122
164
  void refresh(currentSession);
123
165
  schedule();
124
166
  }
125
- const unread = (snapshot()?.hats ?? []).reduce((s, h) => s + h.unread, 0);
126
167
  const snap = snapshot();
127
- // Collapsed: two lines — toggle + unread marker, then the counts
128
- // (formatMeshSidebar returns both). No snapshot: the bare toggle line.
129
- const collapsedLines = snap ? formatMeshSidebar(snap, true) : null;
130
- return (
131
- <box gap={0}>
168
+ // No snapshot (v1 host, unreachable server): the bare toggle line.
169
+ if (!snap) {
170
+ return (
132
171
  <box flexDirection="row">
133
- <text
134
- fg={theme.text.base}
135
- onMouseDown={() => {
136
- void mutate((draft) => {
137
- draft.collapsed = !draft.collapsed;
138
- }).then(() => void refresh(currentSession));
139
- }}
140
- >
172
+ <text fg={theme.text.base} wrapMode="none" onMouseDown={toggleCollapsed}>
141
173
  <b>{store.collapsed ? "▶ Mesh" : "▼ Mesh"}</b>
142
174
  </text>
143
- <Show when={store.collapsed && unread > 0}>
144
- <text fg={theme.text.base}>{` ● ${unread} unread`}</text>
145
- </Show>
146
175
  </box>
147
- <Show when={store.collapsed ? collapsedLines : null} keyed>
148
- {(collapsed) => <text fg={theme.text.muted}>{collapsed[1]}</text>}
149
- </Show>
150
- <Show when={!store.collapsed}>
151
- <box gap={0}>{themedBody(theme, lines, unread)}</box>
152
- </Show>
153
- </box>
154
- );
176
+ );
177
+ }
178
+ // Formatting is pure: both shapes derive from the snapshot in hand.
179
+ if (store.collapsed) {
180
+ return (
181
+ <box flexDirection="row">
182
+ {segmentRow(theme, formatMeshSidebarCollapsed(snap), toggleCollapsed)}
183
+ </box>
184
+ );
185
+ }
186
+ return sidebarBody(theme, formatMeshSidebarExpanded(snap), toggleCollapsed);
155
187
  },
156
188
  });
157
189
 
@@ -185,10 +217,7 @@ export default Plugin.define({
185
217
  title: "Toggle mesh sidebar",
186
218
  group: "Mesh",
187
219
  run: async () => {
188
- await mutate((draft) => {
189
- draft.collapsed = !draft.collapsed;
190
- });
191
- void refresh(currentSession);
220
+ toggleCollapsed();
192
221
  },
193
222
  },
194
223
  ],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@log0u7/opencode-mesh",
3
- "version": "0.20.0",
3
+ "version": "0.22.0",
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",