rucan 0.1.0 → 0.1.2

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/README.md CHANGED
@@ -14,7 +14,7 @@ pnpm build
14
14
  pnpm dev
15
15
  ```
16
16
 
17
- Use Ctrl+G to open the menu. P pins, D detaches, H selects a host, E opens the file explorer, and Q opens exit options. Arrow keys, digits and sidebar clicks switch workspaces. T opens optional tmux actions, and S browses scrollback. The first launch creates a sample at `~/.config/rucan/config.yaml` or under an absolute `XDG_CONFIG_HOME`. Local and remote configuration examples follow.
17
+ Type `exit` at the shell prompt to close the current shell. To open Rucan's exit screen, press Ctrl+G and then Q, or enter `/exit` in the menu. Press Enter on the exit screen to keep sessions running. Ctrl+G and F12 open the workspace menu. On Mac keyboards with media keys, press Fn+F12 to send F12. P pins a session, D closes the UI and keeps sessions running, H selects a host, and E opens the file explorer. Arrow keys, digits and sidebar clicks switch workspaces. T opens optional tmux actions, and S browses scrollback. The first launch creates a sample at `~/.config/rucan/config.yaml` or under an absolute `XDG_CONFIG_HOME`. Local and remote configuration examples follow.
18
18
 
19
19
  ```yaml
20
20
  version: 1
@@ -28,6 +28,10 @@ workspaces:
28
28
  persistence: persistent
29
29
  ```
30
30
 
31
+ The numbered workspace list contains running sessions. When the selected session exits, Rucan opens the next running session. If the list is empty, use Ctrl+G, then N to open a new workspace.
32
+
33
+ Inside a managed shell, run `rucan` to see session commands. Use `npx rucan@latest` if you run Rucan through npm without a global installation.
34
+
31
35
  `pnpm dev config` validates the configuration and prints its path. The npm package installs the `rucan` command. After the first release:
32
36
 
33
37
  ```sh
Binary file
Binary file
Binary file
Binary file
@@ -1,9 +1,9 @@
1
1
  {
2
- "version": "0.1.0",
2
+ "version": "0.1.2",
3
3
  "platforms": {
4
- "linux-x64": "c47e4a55e4babdfcdd496fcf054b2b1f4f4d7e3869ea38d293eb9adb49b6f78d",
5
- "linux-arm64": "edb01cccef91b5289293291380f0af5c23bd3b8dcc25b423acb552d8f292ac01",
6
- "darwin-x64": "b71cbf1ff134b9860baaa942ecd83abeeaff42cb6396a299a62e2b3f4aa517f6",
7
- "darwin-arm64": "0fcde845a719877e548f59453a36122b4113d83517e789476884b50ecc6fa376"
4
+ "linux-x64": "0369001ea14d9f604251eb1701871fadf8915a3f4b603eba1231a9d8cbc92e34",
5
+ "linux-arm64": "3bd5ae6113d92d91f9a13e17becea75949a394772ab75d54d24a778d24d4f718",
6
+ "darwin-x64": "39cb080a250b7bcc03af523825b9f2ca9762650453f1ff999a4300e34c5744c2",
7
+ "darwin-arm64": "95eaee56515ae4119b45a372ebd912ac3a4a0cd80fd7f3cc56a248bb560b5e21"
8
8
  }
9
9
  }
package/dist/main.js CHANGED
@@ -15,6 +15,10 @@ async function main(args) {
15
15
  console.log(`rucan ${version}`);
16
16
  return;
17
17
  }
18
+ if (args.length === 0 && process.env.RUCAN_SESSION_ID) {
19
+ console.log("Rucan session commands\n\n rucan ls List sessions\n rucan pin Pin this session\n rucan unpin Unpin this session\n rucan --help Show all CLI commands\n\nType exit to close this shell. Open the Rucan menu to close the UI.");
20
+ return;
21
+ }
18
22
  if (args.length === 1 && args[0] === "--help") {
19
23
  console.log("Usage: rucan [attach | remote | tmux | update | doctor | config | ls | status | new | pin | unpin | detach | rename | kill | shutdown | --fixture | --help | --version]\n\nOpen the workspace UI or control a local terminal session.");
20
24
  return;
@@ -1,6 +1,7 @@
1
1
  const pasteStart = Buffer.from("\x1b[200~");
2
2
  const pasteEnd = Buffer.from("\x1b[201~");
3
3
  const mouseStart = Buffer.from("\x1b[<");
4
+ const f12 = Buffer.from("\x1b[24~");
4
5
  function mouseReport(bytes) {
5
6
  const prefix = bytes.subarray(0, mouseStart.length);
6
7
  if (!mouseStart.subarray(0, prefix.length).equals(prefix))
@@ -66,12 +67,22 @@ export class InputRouter {
66
67
  }
67
68
  }
68
69
  else if (!this.#paste) {
69
- const mouse = mouseReport(remainder);
70
- if (mouse === "incomplete")
71
- incomplete = true;
72
- else if (mouse) {
73
- event = { type: "mouse", ...mouse.event };
74
- length = mouse.length;
70
+ const key = remainder.subarray(0, f12.length);
71
+ if (f12.subarray(0, key.length).equals(key)) {
72
+ incomplete = key.length < f12.length;
73
+ if (!incomplete) {
74
+ event = { type: "prefix" };
75
+ length = f12.length;
76
+ }
77
+ }
78
+ else {
79
+ const mouse = mouseReport(remainder);
80
+ if (mouse === "incomplete")
81
+ incomplete = true;
82
+ else if (mouse) {
83
+ event = { type: "mouse", ...mouse.event };
84
+ length = mouse.length;
85
+ }
75
86
  }
76
87
  }
77
88
  }
@@ -6,13 +6,14 @@ import { setTimeout as delay } from "node:timers/promises";
6
6
  import { connectRemoteAgent } from "../agent/ssh.js";
7
7
  import { connectLocalAgent } from "../agent/local.js";
8
8
  import { mountRawInput } from "./raw-input.js";
9
- import { footerFor, menuFor, selectionLines } from "./view.js";
9
+ import { exitLines, footerFor, menuFor, selectionLines, } from "./view.js";
10
10
  import { listTmux, openTmux } from "./tmux.js";
11
11
  import { TerminalWatch } from "./watch.js";
12
+ import { watchWorkspaceList } from "./workspace-refresh.js";
12
13
  import { terminalMouse } from "./mouse.js";
13
14
  import { geometry, Screen } from "./screen.js";
14
15
  import { decodeSnapshot } from "./snapshot.js";
15
- import { createWorkspace, decodeWorkspace, listWorkspaces, workspaceLabels, } from "./workspaces.js";
16
+ import { createWorkspace, decodeWorkspace, listWorkspaces, reconcileWorkspaces, workspaceLabels, } from "./workspaces.js";
16
17
  export async function runInteractive(config, requested, host) {
17
18
  if (!process.stdin.isTTY || !process.stdout.isTTY)
18
19
  throw new Error("The workspace UI requires a terminal.");
@@ -69,6 +70,8 @@ class InteractiveWorkspace {
69
70
  #history;
70
71
  #offset = 0;
71
72
  #name = "";
73
+ #command = "";
74
+ #commandError = false;
72
75
  #tmux = [];
73
76
  #tmuxIndex = 0;
74
77
  #workspaces = [];
@@ -89,13 +92,12 @@ class InteractiveWorkspace {
89
92
  this.#explorer = new Explorer(connect, config.explorer.exclusions, () => this.#draw());
90
93
  }
91
94
  async run(requested) {
92
- this.#workspaces = await listWorkspaces(this.#client);
95
+ this.#workspaces = (await listWorkspaces(this.#client)).filter(({ running }) => running);
93
96
  const target = requested
94
97
  ? this.#workspaces.find(({ id, name }) => id === requested || name === requested)
95
98
  : this.#workspaces.find(({ running }) => running);
96
99
  if (requested && !target)
97
100
  throw new Error(`Unknown session ${requested}`);
98
- await this.#select(target ?? (await this.#new()), false);
99
101
  const onResize = () => {
100
102
  if (this.#resizePending)
101
103
  return;
@@ -103,8 +105,8 @@ class InteractiveWorkspace {
103
105
  this.#enqueue(async () => {
104
106
  this.#resizePending = false;
105
107
  this.#layout = geometry(process.stdout.rows || 24, process.stdout.columns || 80);
106
- await this.#resize();
107
108
  this.#draw();
109
+ await this.#resize();
108
110
  });
109
111
  };
110
112
  const done = new Promise((resolve) => {
@@ -112,7 +114,9 @@ class InteractiveWorkspace {
112
114
  });
113
115
  this.#screen.enter();
114
116
  let unmount;
117
+ let stopRefresh;
115
118
  try {
119
+ await this.#select(target ?? (await this.#new()), false);
116
120
  unmount = mountRawInput(this.#config.terminal.prefix_key, {
117
121
  input: (events) => this.#enqueue(async () => {
118
122
  for (const event of events) {
@@ -125,6 +129,7 @@ class InteractiveWorkspace {
125
129
  stop: () => this.#stop(),
126
130
  });
127
131
  this.#draw();
132
+ stopRefresh = watchWorkspaceList(() => this.#enqueue(() => this.#refreshWorkspaces()));
128
133
  if (this.#config.updates.check_on_startup) {
129
134
  void availableUpdate()
130
135
  .then((target) => {
@@ -138,6 +143,7 @@ class InteractiveWorkspace {
138
143
  await done;
139
144
  }
140
145
  finally {
146
+ stopRefresh?.();
141
147
  this.#stop();
142
148
  this.#client.close();
143
149
  unmount?.();
@@ -183,16 +189,48 @@ class InteractiveWorkspace {
183
189
  this.#controlsInput = controls;
184
190
  this.#status = controls ? "" : "Read-only · input held by another client";
185
191
  this.#snapshot = decodeSnapshot(await this.#client.request({ type: "snapshot", session: workspace.id }));
186
- await this.#resize();
192
+ if (this.#snapshot.state !== "running") {
193
+ await this.#refreshWorkspaces(workspace.id, render);
194
+ return;
195
+ }
187
196
  if (render)
188
197
  this.#draw();
189
198
  this.#watcher.start(workspace.id, this.#snapshot, (snapshot) => {
199
+ if (snapshot.state !== "running") {
200
+ void this.#enqueue(() => this.#refreshWorkspaces(workspace.id));
201
+ return;
202
+ }
190
203
  this.#snapshot = snapshot;
191
204
  this.#draw();
192
205
  }, (error) => {
193
206
  this.#status = error instanceof Error ? error.message : String(error);
194
207
  this.#draw();
195
208
  });
209
+ await this.#resize();
210
+ }
211
+ async #refreshWorkspaces(exitedId, render = true) {
212
+ const running = (await listWorkspaces(this.#client)).filter(({ id, running }) => running && id !== exitedId);
213
+ const selected = this.#selected;
214
+ const previous = this.#workspaces;
215
+ const { workspaces, next } = reconcileWorkspaces(previous, running, selected?.id);
216
+ this.#workspaces = workspaces;
217
+ if (selected ? !workspaces.some(({ id }) => id === selected.id) : next) {
218
+ this.#watcher.stop();
219
+ this.#selected = undefined;
220
+ this.#snapshot = undefined;
221
+ this.#controlsInput = false;
222
+ this.#status = "";
223
+ if (this.#mode === "history")
224
+ this.#mode = "terminal";
225
+ if (next) {
226
+ await this.#select(next, render);
227
+ return;
228
+ }
229
+ }
230
+ if (render &&
231
+ (previous.length !== workspaces.length ||
232
+ workspaces.some((workspace, index) => workspace !== previous[index])))
233
+ this.#draw();
196
234
  }
197
235
  async #recoverControl() {
198
236
  const selected = this.#selected;
@@ -375,8 +413,11 @@ class InteractiveWorkspace {
375
413
  await this.#openTmux(this.#tmux[this.#tmuxIndex]?.id ?? null);
376
414
  }
377
415
  }
416
+ else if (this.#mode === "command") {
417
+ await this.#readCommand(key);
418
+ }
378
419
  else if (this.#mode === "exit") {
379
- if (key === "1")
420
+ if (key === "1" || key === "\r")
380
421
  await this.#exit("keep-all");
381
422
  if (key === "2")
382
423
  await this.#exit("keep-pinned");
@@ -482,15 +523,17 @@ class InteractiveWorkspace {
482
523
  if (key === "\x1b") {
483
524
  this.#mode = "terminal";
484
525
  }
526
+ else if (key.startsWith("/")) {
527
+ this.#command = "";
528
+ this.#commandError = false;
529
+ this.#mode = "command";
530
+ await this.#readCommand(key.slice(1));
531
+ }
485
532
  else if (key === "d") {
486
533
  await this.#exit("keep-all");
487
534
  }
488
- else if (key === "q") {
489
- const policy = this.#config.defaults.on_exit;
490
- if (policy === "ask")
491
- this.#mode = "exit";
492
- else
493
- await this.#exit(policy);
535
+ else if (key === "q" || key === "Q") {
536
+ await this.#requestExit();
494
537
  }
495
538
  else if (key === "r" && this.#selected) {
496
539
  this.#name = "";
@@ -547,6 +590,36 @@ class InteractiveWorkspace {
547
590
  }
548
591
  }
549
592
  }
593
+ async #readCommand(input) {
594
+ if (input === "\x1b") {
595
+ this.#mode = "menu";
596
+ return;
597
+ }
598
+ const [text = "", submitted] = input.split(/(\r|\n)/u, 2);
599
+ if (!/^[a-zA-Z\x7f]*$/u.test(text))
600
+ return;
601
+ for (const character of text.slice(0, 32)) {
602
+ if (character === "\x7f")
603
+ this.#command = this.#command.slice(0, -1);
604
+ else if (this.#command.length < 24)
605
+ this.#command += character;
606
+ }
607
+ if (text)
608
+ this.#commandError = false;
609
+ if (!submitted)
610
+ return;
611
+ if (this.#command.toLowerCase() === "exit")
612
+ await this.#requestExit();
613
+ else
614
+ this.#commandError = true;
615
+ }
616
+ async #requestExit() {
617
+ const policy = this.#config.defaults.on_exit;
618
+ if (policy === "ask")
619
+ this.#mode = "exit";
620
+ else
621
+ await this.#exit(policy);
622
+ }
550
623
  async #exit(policy) {
551
624
  if (policy !== "keep-all") {
552
625
  for (const workspace of await listWorkspaces(this.#client)) {
@@ -566,7 +639,7 @@ class InteractiveWorkspace {
566
639
  const title = selected
567
640
  ? `${selected.name}${selected.persistent ? " ◆" : ""}`
568
641
  : "No session";
569
- const footer = footerFor(this.#mode, this.#config.terminal.prefix_key, this.#name, this.#offset, this.#update);
642
+ const footer = footerFor(this.#mode, this.#config.terminal.prefix_key, this.#name, this.#offset);
570
643
  const explorer = this.#mode === "explorer"
571
644
  ? this.#explorer.layout(this.#layout.rows - 2)
572
645
  : undefined;
@@ -581,9 +654,19 @@ class InteractiveWorkspace {
581
654
  });
582
655
  return;
583
656
  }
657
+ const running = this.#snapshot?.state === "running";
584
658
  this.#screen.draw({
585
659
  layout: this.#layout,
586
- header: `rucan │ ${title} │ ${this.#status || (this.#snapshot?.state === "running" ? (this.#host ? `${this.#host} connected` : "Local agent connected") : "Session exited")}`,
660
+ header: {
661
+ tab: title,
662
+ status: this.#status ||
663
+ (running
664
+ ? this.#host
665
+ ? `${this.#host} connected`
666
+ : "Local agent connected"
667
+ : "No active workspace"),
668
+ healthy: running && !this.#status,
669
+ },
587
670
  footer: this.#update && this.#mode !== "exit"
588
671
  ? `${footer} · U Review v${this.#update}`
589
672
  : footer,
@@ -597,13 +680,28 @@ class InteractiveWorkspace {
597
680
  ? selectionLines("TMUX SESSIONS", this.#tmux.map((entry) => entry.name), this.#tmuxIndex, this.#layout.rows - 2)
598
681
  : undefined) ??
599
682
  explorer?.sidebar ??
600
- workspaceLabels(this.#config, this.#workspaces, selected?.id, this.#mode === "menu" ? menuFor(this.#update) : undefined),
683
+ workspaceLabels(this.#config, this.#workspaces, selected?.id),
601
684
  ...(explorer
602
685
  ? { contentLines: explorer.content }
603
- : this.#mode === "menu" && !this.#snapshot
686
+ : this.#mode === "menu"
604
687
  ? { contentLines: menuFor(this.#update) }
605
- : {}),
606
- snapshot: explorer
688
+ : this.#mode === "exit"
689
+ ? { contentLines: exitLines(this.#host) }
690
+ : this.#mode === "command"
691
+ ? {
692
+ contentLines: [
693
+ `Command /${this.#command}▏`,
694
+ "",
695
+ this.#commandError
696
+ ? "Unknown command. Try /exit."
697
+ : "/exit Quit Rucan",
698
+ ],
699
+ }
700
+ : {}),
701
+ snapshot: explorer ||
702
+ this.#mode === "menu" ||
703
+ this.#mode === "exit" ||
704
+ this.#mode === "command"
607
705
  ? undefined
608
706
  : this.#mode === "history"
609
707
  ? this.#history
@@ -1,5 +1,12 @@
1
1
  import stringWidth from "string-width";
2
+ import { version } from "../release/version.js";
2
3
  const reset = "\x1b[0m";
4
+ const chrome = "\x1b[1;36m";
5
+ const brand = "\x1b[1;30;106m";
6
+ const activeTab = "\x1b[1;97;44m";
7
+ const connected = "\x1b[32m";
8
+ const attention = "\x1b[33m";
9
+ const divider = "\x1b[2m";
3
10
  const hideCursor = "\x1b[?25l";
4
11
  const move = (row, col) => `\x1b[${row};${col}H`;
5
12
  const segmenter = new Intl.Segmenter("en", { granularity: "grapheme" });
@@ -43,10 +50,31 @@ function sgr([flags, fg, bg]) {
43
50
  }
44
51
  return `\x1b[${attributes.join(";")}m`;
45
52
  }
53
+ function renderHeader(header, width) {
54
+ if (typeof header === "string")
55
+ return chrome + fit(header, width) + reset;
56
+ const logo = fit(` rucan v${version} `, width);
57
+ const remaining = width - stringWidth(logo);
58
+ if (remaining < 3)
59
+ return brand + logo + reset;
60
+ const tab = fit(` ${header.tab} `, Math.min(remaining - 1, Math.max(12, Math.floor(width * 0.45))));
61
+ const status = fit(` ● ${header.status}`, remaining - stringWidth(tab) - 1);
62
+ return (brand +
63
+ logo +
64
+ reset +
65
+ " " +
66
+ activeTab +
67
+ tab +
68
+ reset +
69
+ (header.healthy ? connected : attention) +
70
+ status +
71
+ reset);
72
+ }
46
73
  /** Own every write to the outer terminal while the interactive UI is mounted. */
47
74
  export class Screen {
48
75
  #output;
49
76
  #previous = [];
77
+ #paintedLayout;
50
78
  #latest;
51
79
  #blocked = false;
52
80
  #keyModes = "";
@@ -71,17 +99,24 @@ export class Screen {
71
99
  if (!model)
72
100
  return;
73
101
  const { layout, header, footer, sidebarLines, snapshot, showCursor, contentLines, } = model;
74
- const lines = [fit(header, layout.cols)];
102
+ const lines = [renderHeader(header, layout.cols)];
75
103
  for (let row = 0; row < layout.rows - 2; row++) {
76
104
  const sidebar = fit(sidebarLines[row] ?? "", Math.max(0, layout.sidebar - 1));
77
105
  let line = layout.sidebar > 0
78
- ? sidebar +
106
+ ? (row === 0 || sidebar.startsWith("›")
107
+ ? chrome + sidebar + reset
108
+ : sidebar) +
79
109
  " ".repeat(Math.max(0, layout.sidebar - 1 - stringWidth(sidebar))) +
80
- "│"
110
+ divider +
111
+ "│" +
112
+ reset
81
113
  : "";
82
114
  let col = layout.sidebar;
83
- if (contentLines)
84
- line += fit(contentLines[row] ?? "", layout.cols - col);
115
+ if (contentLines && layout.cols - col > 2) {
116
+ const content = fit(contentLines[row] ?? "", layout.cols - col - 2);
117
+ if (content)
118
+ line += " " + (row === 0 ? chrome : reset) + content + reset;
119
+ }
85
120
  for (const [width, text, style] of snapshot?.grid.lines[row] ?? []) {
86
121
  if (col >= layout.cols)
87
122
  break;
@@ -93,8 +128,16 @@ export class Screen {
93
128
  }
94
129
  lines.push(line + reset);
95
130
  }
96
- lines.push(fit(footer, layout.cols));
131
+ lines.push(chrome + fit(footer, layout.cols) + reset);
97
132
  let output = hideCursor;
133
+ if (this.#paintedLayout &&
134
+ (this.#paintedLayout.rows !== layout.rows ||
135
+ this.#paintedLayout.cols !== layout.cols)) {
136
+ // The outer terminal may have reflowed rows since the last frame.
137
+ output += reset + "\x1b[2J";
138
+ this.#previous = [];
139
+ }
140
+ this.#paintedLayout = layout;
98
141
  const last = Math.max(lines.length, this.#previous.length);
99
142
  for (let index = 0; index < last; index++) {
100
143
  const line = lines[index] ?? "";
@@ -1,4 +1,4 @@
1
- export function footerFor(mode, prefix, name, scrollback, update) {
1
+ export function footerFor(mode, prefix, name, scrollback) {
2
2
  switch (mode) {
3
3
  case "create":
4
4
  return "↑↓ Choose workspace · Enter Open · Esc Back";
@@ -14,25 +14,30 @@ export function footerFor(mode, prefix, name, scrollback, update) {
14
14
  return "↑↓ Select · Enter Attach · N Open New Tmux Session · Esc Back";
15
15
  case "explorer":
16
16
  return "↑↓ Select · Enter Expand/Preview · R Refresh · O Editor · Esc Back";
17
+ case "command":
18
+ return "Enter Run command · Esc Back";
17
19
  case "exit":
18
- return "1 Keep all · 2 Keep pinned · 3 Stop managed · 4 Cancel";
20
+ return "Enter Keep all · Esc Back";
19
21
  case "menu":
20
- return "↑↓ / 1–9 Switch · N New · P Pin · H Hosts · D Detach · Q Quit";
22
+ return "Q Quit · Esc Return to terminal · ↑↓ / 1–9 Switch";
21
23
  case "terminal":
22
- return `${prefix} Menu${update ? ` · Update v${update} available` : ""}`;
24
+ return `${prefix} Menu (F12) · Type exit to close the current shell`;
23
25
  }
24
26
  }
25
27
  export function menuFor(update) {
26
28
  return [
27
- "N New",
29
+ "Workspace actions",
30
+ "",
31
+ "/exit or Q Quit Rucan",
32
+ "D Close UI and keep sessions",
33
+ "",
34
+ "N New workspace",
28
35
  "P Pin",
29
36
  "H Hosts",
30
37
  "E Files",
31
38
  "T Tmux",
32
39
  "S History",
33
40
  "R Rename",
34
- "D Detach",
35
- "Q Quit",
36
41
  ...(update ? [`U Update to v${update}`] : []),
37
42
  ];
38
43
  }
@@ -45,3 +50,15 @@ export function selectionLines(title, entries, index, available) {
45
50
  .map((entry, offset) => `${index === start + offset ? "›" : " "} ${entry}`),
46
51
  ];
47
52
  }
53
+ export function exitLines(host) {
54
+ return [
55
+ "Quit Rucan",
56
+ "",
57
+ "Enter / 1 Close UI and keep all sessions",
58
+ "2 Keep pinned sessions only",
59
+ "3 Stop all Rucan-managed sessions",
60
+ "Esc / 4 Go back",
61
+ "",
62
+ `Session options apply to ${host ?? "this computer"}.`,
63
+ ];
64
+ }
@@ -0,0 +1,15 @@
1
+ /** Poll workspace metadata without overlapping requests or watching inactive PTYs. */
2
+ export function watchWorkspaceList(refresh) {
3
+ let stopped = false;
4
+ let timer;
5
+ const schedule = () => {
6
+ if (stopped)
7
+ return;
8
+ timer = setTimeout(() => void refresh().finally(schedule), 2000);
9
+ };
10
+ schedule();
11
+ return () => {
12
+ stopped = true;
13
+ clearTimeout(timer);
14
+ };
15
+ }
@@ -41,6 +41,18 @@ export async function listWorkspaces(client) {
41
41
  .map(decodeWorkspace)
42
42
  .sort((left, right) => left.name.localeCompare(right.name));
43
43
  }
44
+ export function reconcileWorkspaces(previous, running, selectedId) {
45
+ const current = new Map(running.map((workspace) => [workspace.id, workspace]));
46
+ const workspaces = previous.filter(({ id }) => current.has(id));
47
+ for (const { id } of workspaces)
48
+ current.delete(id);
49
+ workspaces.push(...current.values());
50
+ const index = previous.findIndex(({ id }) => id === selectedId);
51
+ return {
52
+ workspaces,
53
+ next: workspaces[Math.min(Math.max(0, index), workspaces.length - 1)],
54
+ };
55
+ }
44
56
  function defaultWorkspace(config, host) {
45
57
  return (config.workspaces.find(({ host: entry, backend }) => entry === host && backend === "native") ?? {
46
58
  name: host ?? "local-shell",
@@ -64,15 +76,14 @@ export async function createWorkspace(client, config, layout, host, requested) {
64
76
  scrollback: config.terminal.scrollback_lines,
65
77
  }));
66
78
  }
67
- export function workspaceLabels(config, sessions, activeId, actions) {
79
+ export function workspaceLabels(config, sessions, activeId) {
68
80
  const labels = [
69
81
  "WORKSPACES",
70
82
  ...sessions.map((workspace, index) => {
71
83
  const selected = workspace.id === activeId ? "›" : " ";
72
84
  const pin = workspace.backend === "tmux" ? "T" : workspace.persistent ? "◆" : "◇";
73
85
  const slot = index < 9 ? String(index + 1) : " ";
74
- const exited = workspace.running ? "" : " ×";
75
- return `${selected}${slot} ${pin} ${workspace.name}${exited}`;
86
+ return `${selected}${slot} ${pin} ${workspace.name}`;
76
87
  }),
77
88
  ];
78
89
  for (const workspace of config.workspaces) {
@@ -81,7 +92,5 @@ export function workspaceLabels(config, sessions, activeId, actions) {
81
92
  else if (workspace.backend === "tmux")
82
93
  labels.push(` ○ ${workspace.name} (tmux)`);
83
94
  }
84
- return actions
85
- ? [...labels, "", ...actions]
86
- : [...labels, "", "EXPLORER", "E in menu to browse"];
95
+ return labels;
87
96
  }
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { Box, Text, useApp, useInput, useWindowSize } from "ink";
3
3
  import { useState } from "react";
4
+ import { version } from "../release/version.js";
4
5
  const fixtureExplorer = ["▾ example-project", " ▸ src", " README.md"];
5
6
  export function WorkspaceView({ config }) {
6
7
  const { exit } = useApp();
@@ -41,7 +42,7 @@ export function WorkspaceView({ config }) {
41
42
  const maxVisible = Math.max(1, rows - 11);
42
43
  const start = Math.max(0, selected - maxVisible + 1);
43
44
  const sidebarWidth = Math.max(16, Math.floor(columns * 0.25));
44
- return (_jsxs(Box, { flexDirection: "column", width: columns, height: rows, children: [_jsxs(Box, { justifyContent: "space-between", paddingX: 1, children: [_jsx(Text, { bold: true, color: "cyan", children: "rucan" }), _jsx(Text, { color: "yellow", children: "Fixture mode \u00B7 agent offline" })] }), _jsxs(Box, { flexGrow: 1, flexShrink: 1, children: [_jsxs(Box, { width: sidebarWidth, flexShrink: 0, flexDirection: "column", children: [_jsxs(Box, { borderStyle: "single", flexDirection: "column", flexGrow: 1, children: [_jsx(Text, { bold: true, children: "WORKSPACES" }), config.workspaces.length === 0 && (_jsx(Text, { dimColor: true, children: "No workspaces" })), config.workspaces
45
+ return (_jsxs(Box, { flexDirection: "column", width: columns, height: rows, children: [_jsxs(Box, { justifyContent: "space-between", paddingX: 1, children: [_jsxs(Text, { bold: true, color: "cyan", children: ["rucan v", version] }), _jsx(Text, { color: "yellow", children: "Fixture mode \u00B7 agent offline" })] }), _jsxs(Box, { flexGrow: 1, flexShrink: 1, children: [_jsxs(Box, { width: sidebarWidth, flexShrink: 0, flexDirection: "column", children: [_jsxs(Box, { borderStyle: "single", flexDirection: "column", flexGrow: 1, children: [_jsx(Text, { bold: true, children: "WORKSPACES" }), config.workspaces.length === 0 && (_jsx(Text, { dimColor: true, children: "No workspaces" })), config.workspaces
45
46
  .slice(start, start + maxVisible)
46
47
  .map((entry, index) => (_jsxs(Text, { wrap: "truncate-end", ...(start + index === selected ? { color: "cyan" } : {}), children: [start + index === selected ? "›" : " ", " ", entry.name, entry.persistence === "persistent" ? " ◆" : ""] }, entry.name)))] }), _jsxs(Box, { borderStyle: "single", flexDirection: "column", children: [_jsx(Text, { bold: true, children: "EXPLORER" }), fixtureExplorer.map((item) => (_jsx(Text, { wrap: "truncate-end", dimColor: true, children: item }, item)))] })] }), _jsxs(Box, { flexGrow: 1, flexShrink: 1, flexBasis: 0, borderStyle: "single", flexDirection: "column", paddingX: 1, children: [_jsx(Text, { bold: true, children: menu ? "MENU" : "TERMINAL" }), menu ? (_jsx(Text, { children: "Esc closes the menu. Q quits." })) : (_jsxs(_Fragment, { children: [workspace && (_jsxs(Text, { wrap: "truncate-end", children: [workspace.host ?? "local", " \u00B7 ", workspace.backend, " \u00B7", " ", workspace.persistence] })), workspace && (_jsxs(Text, { wrap: "truncate-end", color: "green", children: [workspace.cwd, " $ ", workspace.command] })), _jsx(Text, { wrap: "truncate-end", dimColor: true, children: "Fixture preview. No shell is running." })] }))] })] }), _jsxs(Text, { wrap: "truncate-end", dimColor: true, children: [prefix, " Menu \u00B7 \u2191\u2193 / 1\u20139 Switch \u00B7 Q Quit"] })] }));
47
48
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rucan",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=22"