@towles/tool 0.0.111 → 0.0.112

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@towles/tool",
3
- "version": "0.0.111",
3
+ "version": "0.0.112",
4
4
  "description": "One off quality of life scripts that I use on a daily basis.",
5
5
  "homepage": "https://github.com/ChrisTowles/towles-tool#readme",
6
6
  "bugs": {
@@ -110,6 +110,16 @@ function App() {
110
110
  const [modal, setModal] = createSignal<"none" | "confirm-kill" | "help">("none");
111
111
  const [killTarget, setKillTarget] = createSignal<string | null>(null);
112
112
 
113
+ // --- Transient toast (footer) ---
114
+ type ToastTone = "error" | "info" | "success";
115
+ const [toast, setToast] = createSignal<{ message: string; tone: ToastTone } | null>(null);
116
+ let toastTimer: ReturnType<typeof setTimeout> | null = null;
117
+ function showToast(message: string, tone: ToastTone = "info") {
118
+ setToast({ message, tone });
119
+ if (toastTimer) clearTimeout(toastTimer);
120
+ toastTimer = setTimeout(() => setToast(null), 4000);
121
+ }
122
+
113
123
  const [clientTty, setClientTty] = createSignal(getClientTty(muxCtx));
114
124
  let ws: WebSocket | null = null;
115
125
  let startupFocusSynced = false;
@@ -119,8 +129,14 @@ function App() {
119
129
 
120
130
  const focusedData = createMemo(() => sessions.find((s) => s.name === focusedSession()) ?? null);
121
131
 
122
- function send(cmd: ClientCommand) {
123
- if (connected() && ws) ws.send(JSON.stringify(cmd));
132
+ function send(cmd: ClientCommand, successMsg?: string): boolean {
133
+ if (connected() && ws) {
134
+ ws.send(JSON.stringify(cmd));
135
+ if (successMsg) showToast(successMsg, "success");
136
+ return true;
137
+ }
138
+ showToast("not connected to agentboard server", "error");
139
+ return false;
124
140
  }
125
141
 
126
142
  function switchToSession(name: string) {
@@ -180,13 +196,16 @@ function App() {
180
196
  "/tmp/agentboard-tui-agent-click.log",
181
197
  `[${new Date().toISOString()}] keyboard focus-agent-pane session=${data.name} agent=${agent.agent} threadId=${agent.threadId} threadName=${agent.threadName}\n`,
182
198
  );
183
- send({
184
- type: "focus-agent-pane",
185
- session: data.name,
186
- agent: agent.agent,
187
- threadId: agent.threadId,
188
- threadName: agent.threadName,
189
- });
199
+ send(
200
+ {
201
+ type: "focus-agent-pane",
202
+ session: data.name,
203
+ agent: agent.agent,
204
+ threadId: agent.threadId,
205
+ threadName: agent.threadName,
206
+ },
207
+ `focusing ${agent.agent}`,
208
+ );
190
209
  }
191
210
 
192
211
  function dismissFocusedAgent() {
@@ -194,17 +213,13 @@ function App() {
194
213
  const agents = data?.agents ?? [];
195
214
  const agent = agents[focusedAgentIdx()];
196
215
  if (!agent || !data) return;
197
- send({
198
- type: "dismiss-agent",
199
- session: data.name,
200
- agent: agent.agent,
201
- threadId: agent.threadId,
202
- });
203
- // Adjust index if we dismissed the last item
216
+ send(
217
+ { type: "dismiss-agent", session: data.name, agent: agent.agent, threadId: agent.threadId },
218
+ `dismissed ${agent.agent}`,
219
+ );
204
220
  if (focusedAgentIdx() >= agents.length - 1 && agents.length > 1) {
205
221
  setFocusedAgentIdx(agents.length - 2);
206
222
  }
207
- // If no agents left, go back to sessions
208
223
  if (agents.length <= 1) setPanelFocus("sessions");
209
224
  }
210
225
 
@@ -213,13 +228,16 @@ function App() {
213
228
  const agents = data?.agents ?? [];
214
229
  const agent = agents[focusedAgentIdx()];
215
230
  if (!agent || !data) return;
216
- send({
217
- type: "kill-agent-pane",
218
- session: data.name,
219
- agent: agent.agent,
220
- threadId: agent.threadId,
221
- threadName: agent.threadName,
222
- });
231
+ send(
232
+ {
233
+ type: "kill-agent-pane",
234
+ session: data.name,
235
+ agent: agent.agent,
236
+ threadId: agent.threadId,
237
+ threadName: agent.threadName,
238
+ },
239
+ `killed ${agent.agent} pane`,
240
+ );
223
241
  }
224
242
 
225
243
  function beginDetailResize(event: MouseEvent) {
@@ -311,11 +329,27 @@ function App() {
311
329
  const data = focusedData();
312
330
  if (!data?.dir) return;
313
331
  const editor = preferredEditor();
314
- Bun.spawn([editor, data.dir], {
315
- stdout: "ignore",
316
- stderr: "ignore",
317
- stdin: "ignore",
318
- });
332
+ try {
333
+ const proc = Bun.spawn([editor, data.dir], {
334
+ stdout: "ignore",
335
+ stderr: "ignore",
336
+ stdin: "ignore",
337
+ });
338
+ showToast(`opening ${data.dir} in ${editor}`, "success");
339
+ void proc.exited.then((code) => {
340
+ if (code !== 0) {
341
+ logResizeDebug("openInEditor failed", { editor, dir: data.dir, code });
342
+ showToast(`failed to open editor "${editor}" (exit ${code})`, "error");
343
+ }
344
+ });
345
+ } catch (err) {
346
+ logResizeDebug("openInEditor spawn threw", {
347
+ editor,
348
+ dir: data.dir,
349
+ error: String(err),
350
+ });
351
+ showToast(`failed to spawn editor "${editor}": ${String(err)}`, "error");
352
+ }
319
353
  }
320
354
 
321
355
  onMount(() => {
@@ -340,6 +374,7 @@ function App() {
340
374
  const refocusTimeout = setTimeout(doStartupRefocus, 2000);
341
375
 
342
376
  onCleanup(() => {
377
+ if (toastTimer) clearTimeout(toastTimer);
343
378
  clearTimeout(refocusTimeout);
344
379
  renderer.removeListener("capabilities", doStartupRefocus);
345
380
  });
@@ -460,7 +495,7 @@ function App() {
460
495
  if (currentModal === "confirm-kill") {
461
496
  if (key.name === "y") {
462
497
  const target = killTarget();
463
- if (target) send({ type: "kill-session", name: target });
498
+ if (target) send({ type: "kill-session", name: target }, `killed ${target}`);
464
499
  setKillTarget(null);
465
500
  setModal("none");
466
501
  } else {
@@ -541,20 +576,11 @@ function App() {
541
576
  break;
542
577
  }
543
578
  case "r":
544
- send({ type: "refresh" });
579
+ send({ type: "refresh" }, "refreshing sessions");
545
580
  break;
546
- case "u":
547
- send({ type: "show-all-sessions" });
581
+ case "d":
582
+ if (panelFocus() === "agents") dismissFocusedAgent();
548
583
  break;
549
- case "d": {
550
- if (panelFocus() === "agents") {
551
- dismissFocusedAgent();
552
- } else {
553
- const focused = focusedSession();
554
- if (focused) send({ type: "hide-session", name: focused });
555
- }
556
- break;
557
- }
558
584
  case "x": {
559
585
  if (panelFocus() === "agents") {
560
586
  killFocusedAgentPane();
@@ -682,6 +708,20 @@ function App() {
682
708
  <box height={1}>
683
709
  <text style={{ fg: P().surface2 }}>{DIVIDER}</text>
684
710
  </box>
711
+ <Show when={toast()}>
712
+ {(t) => (
713
+ <box height={1}>
714
+ <text
715
+ style={{
716
+ fg:
717
+ t().tone === "error" ? P().red : t().tone === "success" ? P().green : P().blue,
718
+ }}
719
+ >
720
+ {t().message}
721
+ </text>
722
+ </box>
723
+ )}
724
+ </Show>
685
725
  <Show
686
726
  when={panelFocus() === "sessions"}
687
727
  fallback={
@@ -700,11 +740,10 @@ function App() {
700
740
  palette={P}
701
741
  hints={[
702
742
  ["⇥", "cycle"],
703
- ["⏎", "go"],
704
- ["→", "select"],
743
+ ["⏎", "switch"],
744
+ ["→", "agents"],
705
745
  ["n", "new"],
706
746
  ["e", "edit"],
707
- ["d", "hide"],
708
747
  ["x", "kill"],
709
748
  ["r", "refresh"],
710
749
  ["q", "quit"],
@@ -768,11 +807,9 @@ const HELP_KEYS: [string, string][] = [
768
807
  ["Tab", "Cycle sessions"],
769
808
  ["n", "New session"],
770
809
  ["e", "Open in editor"],
771
- ["d", "Hide session"],
772
810
  ["x", "Kill session"],
773
811
  ["r", "Refresh"],
774
- ["u", "Show all sessions"],
775
- ["→/l", "Select panel"],
812
+ ["→/l", "Agents panel"],
776
813
  ["←/h/Esc", "Back to sessions"],
777
814
  ["Alt+↑↓", "Reorder sessions"],
778
815
  ["q", "Quit"],
@@ -248,13 +248,8 @@ export function startServer(
248
248
  return a.name.localeCompare(b.name);
249
249
  });
250
250
 
251
- const currentSession = getCurrentSession();
252
-
253
251
  // Sync custom ordering with current session list
254
252
  sessionOrder.sync(allMuxSessions.map((s) => s.name));
255
- if (currentSession) {
256
- sessionOrder.show(currentSession);
257
- }
258
253
 
259
254
  // Apply custom ordering
260
255
  const orderedNames = sessionOrder.apply(allMuxSessions.map((s) => s.name));
@@ -1366,14 +1361,6 @@ export function startServer(
1366
1361
  mux.createSession();
1367
1362
  broadcastState();
1368
1363
  break;
1369
- case "hide-session":
1370
- sessionOrder.hide(cmd.name);
1371
- broadcastState();
1372
- break;
1373
- case "show-all-sessions":
1374
- sessionOrder.showAll();
1375
- broadcastState();
1376
- break;
1377
1364
  case "kill-session": {
1378
1365
  const p = sessionProviders.get(cmd.name) ?? mux;
1379
1366
  p.killSession(cmd.name);
@@ -3,7 +3,6 @@ import { dirname } from "node:path";
3
3
 
4
4
  interface PersistedSessionOrder {
5
5
  order?: unknown;
6
- hidden?: unknown;
7
6
  }
8
7
 
9
8
  /**
@@ -16,7 +15,6 @@ interface PersistedSessionOrder {
16
15
  */
17
16
  export class SessionOrder {
18
17
  private order: string[] = [];
19
- private hidden = new Set<string>();
20
18
  private readonly persistPath: string | null;
21
19
 
22
20
  constructor(persistPath?: string) {
@@ -33,11 +31,6 @@ export class SessionOrder {
33
31
  if (Array.isArray(persisted.order)) {
34
32
  this.order = persisted.order.filter((n): n is string => typeof n === "string");
35
33
  }
36
- if (Array.isArray(persisted.hidden)) {
37
- this.hidden = new Set(
38
- persisted.hidden.filter((n): n is string => typeof n === "string"),
39
- );
40
- }
41
34
  }
42
35
  }
43
36
  } catch {
@@ -51,7 +44,6 @@ export class SessionOrder {
51
44
  const nameSet = new Set(names);
52
45
  // Remove sessions that no longer exist
53
46
  this.order = this.order.filter((n) => nameSet.has(n));
54
- this.hidden = new Set([...this.hidden].filter((n) => nameSet.has(n)));
55
47
  // Add new sessions in sorted position
56
48
  const newNames = names
57
49
  .filter((n) => !this.order.includes(n))
@@ -78,48 +70,21 @@ export class SessionOrder {
78
70
  this.save();
79
71
  }
80
72
 
81
- /** Hide a session from the panel without touching the underlying mux session. */
82
- hide(name: string): void {
83
- if (!this.order.includes(name) || this.hidden.has(name)) return;
84
- this.hidden.add(name);
85
- this.save();
86
- }
87
-
88
- /** Make a previously hidden session visible again. */
89
- show(name: string): void {
90
- if (!this.hidden.delete(name)) return;
91
- if (!this.order.includes(name)) {
92
- this.order.push(name);
93
- }
94
- this.save();
95
- }
96
-
97
- /** Restore all hidden sessions back into the panel. */
98
- showAll(): void {
99
- if (this.hidden.size === 0) return;
100
- this.hidden.clear();
101
- this.save();
102
- }
103
-
104
73
  /** Apply the custom order to a list of session names. Returns sorted names. */
105
74
  apply(names: string[]): string[] {
106
75
  const posMap = new Map(this.order.map((n, i) => [n, i]));
107
- return names
108
- .filter((n) => !this.hidden.has(n))
109
- .sort((a, b) => {
110
- const pa = posMap.get(a) ?? Infinity;
111
- const pb = posMap.get(b) ?? Infinity;
112
- return pa - pb;
113
- });
76
+ return [...names].sort((a, b) => {
77
+ const pa = posMap.get(a) ?? Infinity;
78
+ const pb = posMap.get(b) ?? Infinity;
79
+ return pa - pb;
80
+ });
114
81
  }
115
82
 
116
83
  private save(): void {
117
84
  if (!this.persistPath) return;
118
85
  try {
119
86
  mkdirSync(dirname(this.persistPath), { recursive: true });
120
- const serialized =
121
- this.hidden.size === 0 ? this.order : { order: this.order, hidden: [...this.hidden] };
122
- writeFileSync(this.persistPath, JSON.stringify(serialized) + "\n");
87
+ writeFileSync(this.persistPath, JSON.stringify(this.order) + "\n");
123
88
  } catch {
124
89
  // Best-effort — don't crash if write fails
125
90
  }
@@ -111,8 +111,6 @@ export type ClientCommand =
111
111
  | { type: "switch-session"; name: string; clientTty?: string }
112
112
  | { type: "switch-index"; index: number }
113
113
  | { type: "new-session" }
114
- | { type: "hide-session"; name: string }
115
- | { type: "show-all-sessions" }
116
114
  | { type: "kill-session"; name: string }
117
115
  | { type: "reorder-session"; name: string; delta: -1 | 1 }
118
116
  | { type: "refresh" }