topside-arch 0.1.1 → 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
@@ -27,15 +27,21 @@ Topside comes from npm. npm doesn't install system packages or services, so thos
27
27
 
28
28
  ```bash
29
29
  sudo pacman -S nodejs npm quickshell # Node >= 26
30
- sudo npm install -g topside-arch
31
- mkdir -p ~/.config/systemd/user
32
- cp "$(npm root -g)/topside-arch/contrib/systemd/topside.service" ~/.config/systemd/user/
33
- systemctl --user enable --now topside # the daemon, now and at login
30
+ sudo npm install -g topside-arch # or without sudo, if npm's prefix is in your home
31
+ topside login on # writes the daemon's unit, starts it now and at login
34
32
  topside hooks install # Claude Code; Usage below covers Codex, pi, omp
35
33
  topside setup # the SekaiPop or DMS bar entry; else `topside pill`
36
34
  ```
37
35
 
38
- The unit runs `/usr/bin/topside daemon`. If `topside` lives somewhere else (`which topside`), fix `ExecStart` in the copied file. To upgrade, run `sudo npm install -g topside-arch` again, then `systemctl --user restart topside` and `topside setup`. To remove it: `topside hooks uninstall` first, then `systemctl --user disable --now topside`, delete the unit, and `sudo npm uninstall -g topside-arch`.
36
+ `topside login on` writes `~/.config/systemd/user/topside.service` running the same `node` and script you just ran, wherever npm put them (`/usr` with `sudo`, your home without it or with nvm), so systemd never looks for a `/usr/bin/topside` that isn't there. Before 0.1.2 the steps copied a unit that did, which fails with `203/EXEC` after an install without `sudo`; `topside setup` rewrites that unit too and restarts the daemon. To upgrade, run `sudo npm install -g topside-arch` again, then `topside setup`: it refreshes the bar's files and restarts what still runs the old ones (SekaiPop or DMS, and the daemon). Add `--no-restart` to do that yourself later; it prints the commands. To remove it, take out what Topside put into your agents first, while the `topside` command still exists:
37
+
38
+ ```bash
39
+ topside usage uninstall # Claude Code's status line, back as it was
40
+ topside hooks uninstall # Claude Code's hooks
41
+ topside hooks uninstall codex # and pi, omp: only the ones you installed
42
+ systemctl --user disable --now topside && rm ~/.config/systemd/user/topside.service
43
+ sudo npm uninstall -g topside-arch
44
+ ```
39
45
 
40
46
  The AUR package (`yay -S topside-arch`) waits for the AUR to take new accounts again; its `PKGBUILD` is ready in `contrib/aur/`.
41
47
 
@@ -48,11 +54,9 @@ Topside used to be called Vibe Island on Arch, with the command `via`. The first
48
54
  ```bash
49
55
  systemctl --user disable --now via && rm ~/.config/systemd/user/via.service # stop the old daemon first
50
56
  npm uninstall -g vibe-island-on-arch && npm install -g topside-arch
51
- cp "$(npm root -g)/topside-arch/contrib/systemd/topside.service" ~/.config/systemd/user/
52
- systemctl --user daemon-reload && systemctl --user enable --now topside
57
+ topside login on # the new daemon's unit, now and at login
53
58
  topside hooks install # swaps the old via entries for Topside's
54
- topside setup # swaps the via widget for Topside's
55
- systemctl --user restart dms
59
+ topside setup # swaps the via widget for Topside's and restarts DMS
56
60
  ```
57
61
 
58
62
  Then add "Topside" to the bar in DMS Settings → Bar → Widgets, where "via" sat. The widget's settings start from their defaults.
@@ -60,7 +64,7 @@ Then add "Topside" to the bar in DMS Settings → Bar → Widgets, where "via" s
60
64
  ## Usage
61
65
 
62
66
  ```bash
63
- systemctl --user enable --now topside # start the daemon now and at login
67
+ topside login on # start the daemon now and at login
64
68
  topside hooks install # add Topside's hooks to ~/.claude/settings.json
65
69
  ```
66
70
 
@@ -97,9 +101,9 @@ On DankMaterialShell, put Topside on the bar:
97
101
  topside setup # installs the plugin into ~/.config/dms/plugins/topside and enables it
98
102
  ```
99
103
 
100
- Then open DMS Settings → Bar → Widgets and add "Topside" to the left, center or right zone. The bar shows the newest session's mascot (its agent's logo in pixels, in the status color) and one dot per session; with no session it shows Topside's sign, three glowing status dots side by side. The popout and the bar marks use Topside's own themes: pick one, with Light, Dark or System, and the text size under ⚙. ⏻ next to it quits Topside (stops the daemon); the popout then offers to start it again; click it for the list. A permission request comes as a card with Deny, Always, Allow and Auto mode: Always takes Claude Code's own suggestion (it says which, like accepting edits for the rest of the session), Auto mode lets Claude Code decide later tool calls itself. A request to edit or write a file shows the change as a short diff first. When Claude asks you a multiple-choice question, it shows up on the island as well as in the terminal. Click an option on either one and the other closes. The popout opens by itself when Claude Code asks for permission. When a session finishes while its terminal is out of sight, the popout opens for 5 seconds on your prompt and Claude's last reply; rest the pointer on it to keep it open. It opens on the monitor you're working on. The ⚙ in the popout opens Topside's settings in DMS, laid out like the Mac's: General (start at login, how many sessions the bar and the list show, 5 by default, the rest behind "+ N more"), Notifications (whether cards open by themselves, a reminder for a request nobody answered after 2 minutes, and sounds, off by default, picked from your desktop's sound theme), Hidden sessions (folders and prompts you hid from a row's ⊘ and ≈ buttons, each with a ✕ to bring them back), Integrations (switches for the Claude Code hooks and plan usage, so you don't need the commands below; if Claude Code still runs another copy of Topside or the old via, a Use this copy button fixes it), Appearance, and About (the version, who made it, and where this copy runs from). Its "Arrange on the bar" row takes you to DMS's Bar → Widgets page, where you drag Topside to another zone or spot. A running session shows your last prompt and what it is doing right now ("Editing auth.ts"), with chips for the agent and terminal and how long it has run. A session that finished its turn turns green and says "Done · click to jump" until you jump to it or send it a prompt. Click a session to jump to its terminal. Point at a row for ⊘, which hides every session in its folder, and ≈, which hides sessions started with a prompt like it; Undo shows for 6 seconds. Runs of `claude -p` never show up. Background sessions (`claude --bg`, `/bg`) stay off the island while nobody watches them; Claude handles them. Run `claude attach <id>` in a terminal and that session shows up, and clicking it jumps to that terminal. Run `topside setup` again after upgrading Topside to refresh the plugin files, then restart DMS (`systemctl --user restart dms`) so it drops the old ones.
104
+ Then open DMS Settings → Bar → Widgets and add "Topside" to the left, center or right zone. The bar shows the newest session's mascot (its agent's logo in pixels, in the status color) and one dot per session; with no session it shows Topside's sign, three glowing status dots side by side. The popout and the bar marks use Topside's own themes: pick one, with Light, Dark or System, and the text size under ⚙. ⏻ next to it quits Topside (stops the daemon), and the speaker on its left turns sounds on and off; the popout then offers to start it again; click it for the list. A permission request comes as a card with Deny, Always, Allow and Auto mode: Always takes Claude Code's own suggestion (it says which, like accepting edits for the rest of the session), Auto mode lets Claude Code decide later tool calls itself. A request to edit or write a file shows the change as a short diff first. When Claude asks you a multiple-choice question, it shows up on the island as well as in the terminal. Click an option on either one and the other closes. The popout opens by itself when Claude Code asks for permission. When a session finishes while its terminal is out of sight, the popout opens for 5 seconds on your prompt and Claude's last reply; rest the pointer on it to keep it open. It opens on the monitor you're working on. The ⚙ in the popout opens Topside's settings in DMS, laid out like the Mac's: General (start at login, how many sessions the bar and the list show, 5 by default, the rest behind "+ N more"), Notifications (whether cards open by themselves, a reminder for a request nobody answered after 2 minutes, and sounds, off by default, picked from your desktop's sound theme), Hidden sessions (folders and prompts you hid from a row's ⊘ and ≈ buttons, each with a ✕ to bring them back), Integrations (switches for the Claude Code hooks and plan usage, so you don't need the commands below; if Claude Code still runs another copy of Topside or the old via, a Use this copy button fixes it), Appearance, and About (the version, who made it, and where this copy runs from). Its "Arrange on the bar" row takes you to DMS's Bar → Widgets page, where you drag Topside to another zone or spot. A running session shows your last prompt and what it is doing right now ("Editing auth.ts"), with chips for the agent and terminal and how long it has run. A session that finished its turn turns green and says "Done · click to jump" until you jump to it or send it a prompt. Click a session to jump to its terminal. Point at a row for ⊘, which hides every session in its folder, and ≈, which hides sessions started with a prompt like it. Either one asks first ("Hide 2 sessions in web-app, and any new one there?"), with the rows it would take tinted red, and only hides when you click Hide; Settings brings them back. Runs of `claude -p` never show up. Background sessions (`claude --bg`, `/bg`) stay off the island while nobody watches them; Claude handles them. Run `claude attach <id>` in a terminal and that session shows up, and clicking it jumps to that terminal. Run `topside setup` again after upgrading Topside: it refreshes the plugin files and restarts DMS so it drops the old ones.
101
105
 
102
- On SekaiPop, the same `topside setup` puts Topside in its bar instead (both, when both run). It copies the plugin into `~/.config/sekaipop/plugins/topside` and switches its entry on; Edit Desktop's BAR tab moves it. A plugin already in that folder that setup didn't write is moved to `~/.local/state/topside/` first, never deleted. Settings you picked on the DMS widget (sounds, reminders, theme, hidden sessions) come along unless you already set them on SekaiPop. The entry and its card work like the DMS widget: the mascot and dots, cards that open by themselves for a request or a finished turn, sounds, reminders, ⊘ and ≈ with Undo, and the ⌃Y ⌃N ⌃A ⌃1…⌃9 ⌃J keys on the card you open with a click. A card that opens by itself sits in Topside's own window by the entry and takes no keys, so you keep typing; ✕ closes it, and it goes once you've answered. Its settings live in SekaiPop's Settings > Desktop > Plugins > Topside (⚙ on the card goes there), and picking a sound there plays it: sessions shown, the notification switches and sounds, the hidden folders and prompts one per line, style, look, theme, mode and text size. Style picks how things arrive. Board, the default, lowers a split-flap departure board with the session, its agent and a status word (WAITING, QUESTION, SECURITY, DELAYED, ARRIVED), the change and keys under it; a click on the entry dims the screen and lowers the departures board in Topside's own window, 880 wide with an agent column, waiting sessions first; a click on a row spotlights it and answers it or shows Jump, with hiding as a quiet link, and Esc or a click outside puts it away. The notification board is wide too, most of a 1080p screen's width, with the board's usual flaps; a long diff scrolls under it while the board and the keys stay put. Ticket prints each request out of a little receipt printer on the bar as an order ticket, and you answer with rubber stamps (ALLOW, DENY, RUN IT) that slam onto the paper before it tears off; a finished turn prints ORDER UP!, and a click on the entry dims the screen and shows the kitchen rail in Topside's own window, a ticket per session under a shift report of your plan. A long ticket keeps its head and stamps in place and scrolls the middle. Classic is Topside's cards. The look starts on Match SekaiPop: the card takes the shell's surfaces, outline, corners, hard shadow, font and light or dark mode, and the theme you pick only colors the statuses. Pick Topside to get Topside's own look back. The hook and usage switches of the DMS page aren't there; use the commands below. After `topside setup` replaces files, SekaiPop keeps the old ones until Settings > General > Reload shell.
106
+ On SekaiPop, the same `topside setup` puts Topside in its bar instead (both, when both run). It copies the plugin into `~/.config/sekaipop/plugins/topside` and switches its entry on; Edit Desktop's BAR tab moves it. A plugin already in that folder that setup didn't write is moved to `~/.local/state/topside/` first, never deleted. Settings you picked on the DMS widget (sounds, reminders, theme, hidden sessions) come along unless you already set them on SekaiPop. The entry and its card work like the DMS widget: the mascot and dots, cards that open by themselves for a request or a finished turn, sounds, reminders, ⊘ and ≈ that ask before they hide, and the ⌃Y ⌃N ⌃A ⌃1…⌃9 ⌃J keys on the card you open with a click. A card that opens by itself sits in Topside's own window by the entry and takes no keys, so you keep typing; ✕ closes it, and it goes once you've answered. Its settings live in SekaiPop's Settings > Desktop > Plugins > Topside (⚙ on the card, the board and the rail goes there; the speaker beside it turns sounds on and off), and picking a sound there plays it: sessions shown, the notification switches and sounds, the hidden folders and prompts one per line, style, look, theme, mode and text size. Style picks how things arrive. Board, the default, lowers a split-flap departure board with the session, its agent and a status word (WAITING, QUESTION, SECURITY, DELAYED, ARRIVED), the change and keys under it; a click on the entry dims the screen and lowers the departures board in Topside's own window, 880 wide with an agent column, newest first and nothing picked, its flaps riffling as it comes down; a click on a row spotlights it and answers it or shows Jump, with hiding as a quiet link, and Esc or a click outside puts it away. The notification board is wide too, most of a 1080p screen's width, with the board's usual flaps; a long diff scrolls under it while the board and the keys stay put. Kitchen prints each request out of a little receipt printer on the bar as an order ticket, and you answer with rubber stamps (ALLOW, DENY, RUN IT) that slam onto the paper before it tears off; a finished turn prints ORDER UP!, and a click on the entry dims the screen and shows the kitchen rail in Topside's own window, a ticket per session under a shift report of your plan, newest first with every waiting one on the first rail; ⌃Y and ⌃N press the ticket's stamp when it shows the request. A long ticket keeps its head and stamps in place and scrolls the middle. Classic is Topside's cards. The look starts on Match SekaiPop: the card takes the shell's surfaces, outline, corners, hard shadow, font and light or dark mode, and the theme you pick only colors the statuses. Pick Topside to get Topside's own look back. The hook and usage switches of the DMS page aren't there; use the commands below. After `topside setup` replaces files it restarts SekaiPop with SekaiPop's own `restart-shell.sh`, since the shell keeps the old ones until a new process starts. It won't from outside your Wayland session (over SSH, say); then use Settings > General > Reload shell.
103
107
 
104
108
  Without DMS or SekaiPop, start the pill:
105
109
 
@@ -0,0 +1,20 @@
1
+ pkgbase = topside-arch
2
+ pkgdesc = Watch your coding agents (Claude Code, Codex, pi, omp) from your Quickshell bar: answer their requests, jump to their terminal
3
+ pkgver = 0.1.1
4
+ pkgrel = 1
5
+ url = https://topside.ducban.com/arch/
6
+ install = topside-arch.install
7
+ arch = any
8
+ license = MIT
9
+ makedepends = npm
10
+ depends = nodejs>=26
11
+ depends = quickshell
12
+ optdepends = hyprland: jump to a session's terminal
13
+ optdepends = libcanberra: sounds for requests and finished turns
14
+ optdepends = wezterm: pick the tab when jumping
15
+ optdepends = tmux: pick the window and pane when jumping
16
+ noextract = topside-arch-0.1.1.tgz
17
+ source = https://registry.npmjs.org/topside-arch/-/topside-arch-0.1.1.tgz
18
+ sha256sums = 075f129aa5b1284acc095edee1d4d31730701e006333fdbcebaef7b149998252
19
+
20
+ pkgname = topside-arch
@@ -2,7 +2,7 @@
2
2
  # Built from the npm tarball. scripts/aur.sh fills pkgver and sha256sums
3
3
  # after a release; don't edit those two by hand.
4
4
  pkgname=topside-arch
5
- pkgver=0.1.0
5
+ pkgver=0.1.1
6
6
  pkgrel=1
7
7
  pkgdesc="Watch your coding agents (Claude Code, Codex, pi, omp) from your Quickshell bar: answer their requests, jump to their terminal"
8
8
  arch=('any')
@@ -19,10 +19,10 @@ optdepends=(
19
19
  install=topside-arch.install
20
20
  source=("https://registry.npmjs.org/$pkgname/-/$pkgname-$pkgver.tgz")
21
21
  noextract=("$pkgname-$pkgver.tgz")
22
- sha256sums=('SKIP')
22
+ sha256sums=('075f129aa5b1284acc095edee1d4d31730701e006333fdbcebaef7b149998252')
23
23
 
24
24
  package() {
25
- npm install -g --no-fund --no-audit --prefix "$pkgdir/usr" "$srcdir/$pkgname-$pkgver.tgz"
25
+ npm install -g --no-fund --no-audit --cache "$srcdir/npm-cache" --prefix "$pkgdir/usr" "$srcdir/$pkgname-$pkgver.tgz"
26
26
 
27
27
  # npm leaves some folders writable by everyone and files owned by the builder.
28
28
  find "$pkgdir/usr" -type d -exec chmod 755 {} +
@@ -10,16 +10,19 @@ EOF
10
10
  post_upgrade() {
11
11
  cat <<'EOF'
12
12
  ==> Topside upgraded. As your own user:
13
- systemctl --user restart topside
14
- topside setup # refreshes the bar's files; then reload the shell
13
+ topside setup # refreshes the bar's files, restarts the shell and the daemon
15
14
  EOF
16
15
  }
17
16
 
18
17
  pre_remove() {
19
18
  cat <<'EOF'
20
- ==> Removing Topside. Its hooks stay in your agents' settings and now point
21
- at a command that's gone. Take out the entries tagged # topside-managed
22
- in ~/.claude/settings.json (and ~/.codex/hooks.json), or reinstall and
23
- run `topside hooks uninstall` first. Your data stays in ~/.local/state/topside.
19
+ ==> Removing Topside. What it put into your agents stays and now points at a
20
+ command that's gone. Before removing, as yourself, run:
21
+ topside usage uninstall; topside hooks uninstall
22
+ topside hooks uninstall codex (and pi, omp: the ones you installed)
23
+ Already gone? Remove by hand: entries tagged # topside-managed in
24
+ ~/.claude/settings.json (hooks, and a statusLine running `topside statusline`),
25
+ ~/.codex/hooks.json, ~/.pi/agent/extensions/topside.ts and
26
+ ~/.omp/agent/extensions/topside.ts. Your data stays in ~/.local/state/topside.
24
27
  EOF
25
28
  }
@@ -1,5 +1,5 @@
1
1
  import { spawnSync } from "node:child_process";
2
- import { copyFileSync, existsSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { copyFileSync, existsSync, readFileSync, statSync, writeFileSync } from "node:fs";
3
3
  import { dirname } from "node:path";
4
4
  import { isDeepStrictEqual } from "node:util";
5
5
  import { env, pid, stdin } from "node:process";
@@ -13,6 +13,7 @@ import { agentHome, extensionAgents, extensionPath, extensionSource, extensionSt
13
13
  import { clearUntrusted, codexHookTimeouts, formatCodexDecision, fromCodex, isCodexOneShot, isUntrusted, setUntrusted, untrustedFlagPath } from "../adapters/codex/codex.js";
14
14
  import { parseStatusLineUsage, usageState, withoutUsageBridge, withUsageBridge } from "../adapters/claude/usage.js";
15
15
  import { startDaemon } from "../daemon/server.js";
16
+ import { daemonIsStale, packageUnitPath, refreshUnit, serviceState, userUnitPath, writeUnit } from "../service/unit.js";
16
17
  import { openStore } from "../daemon/store.js";
17
18
  import { hiddenFoldersOfShells, setupShells, syncThemesOfShells } from "../hosts/hosts.js";
18
19
  import { isInFront, jump, realHost as realJumpHost } from "../jump/jump.js";
@@ -362,16 +363,40 @@ export function integrationsCommand(action, version) {
362
363
  }
363
364
  return done(out.join("") || "Nothing installed to adopt.\n");
364
365
  }
365
- // `topside login on|off`: start the daemon at login, or not. Doesn't start or stop it now.
366
+ function systemctl(...args) {
367
+ const result = spawnSync("systemctl", ["--user", ...args], { encoding: "utf8" });
368
+ if (result.error)
369
+ return err(`cannot run systemctl: ${result.error.message}`);
370
+ if (result.status !== 0)
371
+ return err(result.stderr.trim() || `systemctl exited with ${result.status}`);
372
+ return ok(result.stdout);
373
+ }
374
+ // `topside login on|off`. On writes the daemon's unit first (src/service/unit.ts)
375
+ // unless the AUR package brought one, then enables and starts it. Off only
376
+ // disables it; the daemon runs until you stop it or log out.
366
377
  export function loginCommand(action) {
367
378
  if (action !== "on" && action !== "off")
368
379
  return failed("Usage: topside login on|off");
369
- const result = spawnSync("systemctl", ["--user", action === "on" ? "enable" : "disable", "topside"], { encoding: "utf8" });
370
- if (result.error)
371
- return failed(`cannot run systemctl: ${result.error.message}`);
372
- if (result.status !== 0)
373
- return failed(result.stderr.trim() || `systemctl exited with ${result.status}`);
374
- return done(action === "on" ? "Topside starts at login.\n" : "Topside no longer starts at login.\n");
380
+ if (action === "off") {
381
+ const off = systemctl("disable", "topside");
382
+ return off.ok ? done("Topside no longer starts at login.\n") : failed(off.error);
383
+ }
384
+ let out = "";
385
+ const path = userUnitPath();
386
+ if (!existsSync(packageUnitPath) || existsSync(path)) {
387
+ const command = topsideCommand();
388
+ const wrote = writeUnit(path, command);
389
+ if (!wrote.ok)
390
+ return failed(wrote.error);
391
+ if (wrote.value === "written") {
392
+ const reload = systemctl("daemon-reload");
393
+ if (!reload.ok)
394
+ return failed(reload.error);
395
+ out += `Wrote ${path}: it runs ${command.join(" ")} daemon.\n`;
396
+ }
397
+ }
398
+ const on = systemctl("enable", "--now", "topside");
399
+ return on.ok ? done(`${out}Topside runs now and starts at login.\n`) : failed(on.error);
375
400
  }
376
401
  function rewriteSettings(change, said, path = claudeSettingsPath()) {
377
402
  const current = readSettings(path);
@@ -518,9 +543,36 @@ export function themeCommand(args) {
518
543
  }
519
544
  // Joins every running shell's bar (src/hosts/hosts.ts); with none, setup
520
545
  // points at the standalone pill.
521
- export async function setupCommand() {
522
- const result = await setupShells();
523
- return result.ok ? done(result.value) : failed(result.error);
546
+ // Also points the daemon's unit at this copy, so an upgrade, a new prefix or
547
+ // the old unit that ran /usr/bin/topside heals here.
548
+ // `topside setup [--no-restart]`: every running shell, then the daemon's
549
+ // unit. Whatever still runs old files is restarted (the shells by their
550
+ // hosts; the daemon here) unless --no-restart, which says what to run instead.
551
+ export async function setupCommand(args = []) {
552
+ const restart = !args.includes("--no-restart");
553
+ const result = await setupShells(undefined, { restart });
554
+ if (!result.ok)
555
+ return failed(result.error);
556
+ const path = userUnitPath();
557
+ const command = topsideCommand();
558
+ const unit = refreshUnit(path, command);
559
+ if (!unit.ok)
560
+ return done(`${result.value}Couldn't update the daemon's unit: ${unit.error}\n`);
561
+ const written = unit.value === "written";
562
+ let said = result.value;
563
+ if (written) {
564
+ const reload = systemctl("daemon-reload");
565
+ said += `Pointed ${path} at this copy${reload.ok ? "" : ` (daemon-reload failed: ${reload.error})`}.\n`;
566
+ }
567
+ const show = systemctl("show", "topside", "-p", "ActiveState,ExecMainStartTimestamp", "--timestamp=unix");
568
+ // When this copy's script was written: an upgrade in place rewrites it.
569
+ const builtAt = Math.floor((statSync(command[command.length - 1] ?? "", { throwIfNoEntry: false })?.mtimeMs ?? 0) / 1000);
570
+ if (!daemonIsStale(serviceState(show.ok ? show.value : ""), builtAt, written))
571
+ return done(said);
572
+ if (!restart)
573
+ return done(`${said}The daemon runs older code: systemctl --user restart topside\n`);
574
+ const restarted = systemctl("restart", "topside");
575
+ return done(`${said}${restarted.ok ? "Restarted the daemon on this copy.\n" : `Couldn't restart the daemon (${restarted.error}): systemctl --user restart topside\n`}`);
524
576
  }
525
577
  // Accepts the full session id or any unique prefix, like the ids `topside status` prints.
526
578
  export function findSession(sessions, id) {
package/dist/cli/main.js CHANGED
@@ -12,7 +12,7 @@ Commands:
12
12
  deny <id> Deny a pending tool call
13
13
  jump <id> Focus the terminal a session runs in (Hyprland)
14
14
  front <id> Say "yes" if that terminal has the focus, else "no"
15
- setup Install the bar entry for SekaiPop and/or DMS, whichever runs
15
+ setup [--no-restart] Install the bar entry for SekaiPop and/or DMS, whichever runs; restart what still runs old files
16
16
  pill Start the standalone pill (Quickshell)
17
17
  pill position [<where>] Show or set where the pill sits, e.g. bottom-right
18
18
  pill theme [<name>] Show or set the pill's theme, e.g. tokyoNight or one of yours
@@ -31,7 +31,7 @@ Commands:
31
31
  usage uninstall Give Claude Code its own status line back
32
32
  integrations Show what's installed, as JSON (the DMS settings page reads it)
33
33
  integrations adopt Point installed hooks and the usage bridge at this copy
34
- login on|off Start the daemon at login, or not
34
+ login on|off Write the daemon's unit and start it, now and at login; or not at login
35
35
  gate [on|off] Ask before risky pi and omp shell commands (off by default)
36
36
  hook <agent> Hook entry point: claude, codex, or pi/omp (via the extension)
37
37
  statusline Status line entry point, called by Claude Code
@@ -60,7 +60,7 @@ export async function run(args, version) {
60
60
  case "front":
61
61
  return frontCommand(arg);
62
62
  case "setup":
63
- return setupCommand();
63
+ return setupCommand(args.slice(1));
64
64
  case "pill":
65
65
  return pillCommand(args.slice(1));
66
66
  case "theme":
@@ -118,6 +118,10 @@ function rawField(toolInput, key) {
118
118
  return typeof value === "string" ? value : "";
119
119
  }
120
120
  const baseName = (path) => path.split("/").filter(Boolean).at(-1) ?? path;
121
+ // `A=1 B='x y' ` in front of a command, as the risk gate's `isAssignment` reads
122
+ // one. A value ends at a space or, like `lex` there, at `;`, `&` or `|`; a
123
+ // line of nothing but settings strips whole and shows as written.
124
+ const leadingAssignments = /^(?:[\p{L}\p{N}_]+=(?:'[^']*'|"[^"]*"|\\.|[^\s;&|'"\\])*(?:\s+|$))+/u;
121
125
  // A short present-tense line for the island: "Editing auth.ts".
122
126
  export function describeTool(toolName, toolInput) {
123
127
  const file = baseName(field(toolInput, "file_path") || field(toolInput, "notebook_path"));
@@ -132,7 +136,9 @@ export function describeTool(toolName, toolInput) {
132
136
  return file ? `Reading ${file}` : "Reading";
133
137
  case "Bash": {
134
138
  // A heredoc body is noise on one line: keep what runs, not what it reads.
135
- const command = field(toolInput, "command").split("<<")[0]?.trim() ?? "";
139
+ // Leading `VAR=value` settings aren't what runs either.
140
+ const written = field(toolInput, "command").split("<<")[0]?.trim() ?? "";
141
+ const command = written.replace(leadingAssignments, "") || written;
136
142
  return command ? `Running ${command}` : "Running a command";
137
143
  }
138
144
  case "Grep":
package/dist/dms/setup.js CHANGED
@@ -23,6 +23,12 @@ export const realHost = {
23
23
  },
24
24
  disablePlugin: (id) => void spawnSync("dms", ["ipc", "call", "plugins", "disable", id], { stdio: "ignore" }),
25
25
  wait: (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
26
+ restart: () => {
27
+ const run = spawnSync("systemctl", ["--user", "restart", "dms"], { encoding: "utf8" });
28
+ if (run.error)
29
+ return `can't run systemctl: ${run.error.message}`;
30
+ return run.status === 0 ? "" : run.stderr.trim() || `systemctl exited with ${run.status}`;
31
+ },
26
32
  };
27
33
  export function dmsPluginsDir() {
28
34
  const config = env.XDG_CONFIG_HOME ?? join(homedir(), ".config");
@@ -66,7 +72,7 @@ async function enableWithRetry(host, attempts = 10, gapMs = 250) {
66
72
  }
67
73
  return last;
68
74
  }
69
- export async function setup(host, pluginsDir = dmsPluginsDir(), cli = topsideCommand()) {
75
+ export async function setup(host, pluginsDir = dmsPluginsDir(), cli = topsideCommand(), restart = false) {
70
76
  if (!host.dmsRunning()) {
71
77
  return ok("DMS isn't running, so there's no bar to join.\nStart the standalone pill instead: topside pill\n");
72
78
  }
@@ -89,16 +95,21 @@ export async function setup(host, pluginsDir = dmsPluginsDir(), cli = topsideCom
89
95
  host.scanPlugins();
90
96
  const enabled = await enableWithRetry(host);
91
97
  // Enabling can fail on an upgrade too, because the cached old files break the
92
- // new widget. The restart fixes both.
98
+ // new widget. The restart fixes both: setup runs it, then enables again.
99
+ const why = renamed || upgrade ? (!restart ? "" : host.restart ? host.restart() : "no way to restart it") : "";
100
+ const restarted = restart && (renamed || upgrade) && why === "";
101
+ if (restarted && !enabled.ok)
102
+ await enableWithRetry(host, 20, 500);
103
+ const restartLine = restarted
104
+ ? "Restarted DMS so it loads the new files.\n"
105
+ : `DMS caches the old files until it restarts${why === "" ? "" : ` (didn't restart it: ${why})`}: systemctl --user restart dms\n`;
93
106
  if (renamed) {
94
107
  return ok(`Replaced the via widget with Topside in ${installed.value}.\n` +
95
- "1. Restart DMS so it drops the old files: systemctl --user restart dms\n" +
96
- '2. Open DMS Settings → Bar → Widgets and add "Topside" where "via" sat.\n');
97
- }
98
- if (upgrade) {
99
- return ok(`Updated the Topside widget in ${installed.value}.\n` +
100
- "DMS caches the old files until it restarts: systemctl --user restart dms\n");
108
+ restartLine +
109
+ 'Open DMS Settings → Bar → Widgets and add "Topside" where "via" sat.\n');
101
110
  }
111
+ if (upgrade)
112
+ return ok(`Updated the Topside widget in ${installed.value}.\n${restartLine}`);
102
113
  if (!enabled.ok) {
103
114
  return ok(`Plugin files are in ${installed.value}, but enabling it failed: ${enabled.error}\n` +
104
115
  "Open DMS Settings → Plugins and switch Topside on by hand.\n");
@@ -121,6 +132,6 @@ export function dmsHiddenFolders(path = join(configDir(), "DankMaterialShell", "
121
132
  export const dmsShell = {
122
133
  name: "DMS",
123
134
  running: () => realHost.dmsRunning(),
124
- setup: () => setup(realHost),
135
+ setup: (options) => setup(realHost, undefined, undefined, options.restart),
125
136
  hiddenFolders: () => dmsHiddenFolders(),
126
137
  };
@@ -4,13 +4,13 @@ import { sekaipopShell } from "../sekaipop/setup.js";
4
4
  export const shellHosts = [sekaipopShell, dmsShell];
5
5
  export const noShellMessage = "Neither SekaiPop nor DMS is running, so there's no bar to join.\nStart the standalone pill instead: topside pill\n";
6
6
  // `topside setup`: installs into every running shell; with none, points at the pill.
7
- export async function setupShells(hosts = shellHosts) {
7
+ export async function setupShells(hosts = shellHosts, options = { restart: true }) {
8
8
  const running = hosts.filter((host) => host.running());
9
9
  if (running.length === 0)
10
10
  return ok(noShellMessage);
11
11
  const parts = [];
12
12
  for (const host of running) {
13
- const result = await host.setup();
13
+ const result = await host.setup(options);
14
14
  if (!result.ok)
15
15
  return err(`${host.name}: ${result.error}`);
16
16
  parts.push(result.value);
@@ -1,6 +1,7 @@
1
1
  import { spawnSync } from "node:child_process";
2
2
  import { existsSync, lstatSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
3
- import { join } from "node:path";
3
+ import { dirname, join } from "node:path";
4
+ import { env } from "node:process";
4
5
  import { fileURLToPath } from "node:url";
5
6
  import { installPlugin, PLUGIN_ID } from "../dms/setup.js";
6
7
  import { configDir, stateDir, topsideCommand } from "../shared/paths.js";
@@ -10,6 +11,49 @@ function ipc(...args) {
10
11
  const run = spawnSync("qs", ["-c", "sekaipop", "ipc", "call", "plugins", ...args], { encoding: "utf8" });
11
12
  return run.error ? "" : run.stdout.trim();
12
13
  }
14
+ // The running shell's folder, from `qs list`'s "Config path: …/shell.qml", or "".
15
+ export function sekaipopConfigDir(listOutput) {
16
+ const path = /^\s*Config path:\s*(.+\/shell\.qml)\s*$/m.exec(listOutput)?.[1] ?? "";
17
+ return path === "" ? "" : dirname(path);
18
+ }
19
+ // What stops setup from restarting SekaiPop, or "" when nothing does. A
20
+ // shell started away from a Wayland session (over SSH, on a TTY) wouldn't
21
+ // come back, so that stays the user's job.
22
+ export function restartBlocker(dir, script, wayland) {
23
+ if (dir === "")
24
+ return "can't tell which folder it runs from";
25
+ if (!script)
26
+ return "it has no scripts/system/restart-shell.sh";
27
+ if (!wayland)
28
+ return "this terminal isn't in your Wayland session";
29
+ return "";
30
+ }
31
+ // SekaiPop's own restart, the one its updates and `sp-reload` run: it stops
32
+ // every copy of the config and starts one again. Only a new process drops
33
+ // the QML it loaded; Quickshell.reload() keeps some of it.
34
+ function restartScript() {
35
+ const dir = sekaipopConfigDir(spawnSync("qs", ["list", "-c", "sekaipop"], { encoding: "utf8" }).stdout ?? "");
36
+ const script = join(dir, "scripts", "system", "restart-shell.sh");
37
+ return { dir, script, found: dir !== "" && existsSync(script) };
38
+ }
39
+ const restartArgs = (dir, script) => ["-f", "sh", script, dir];
40
+ // `setsid -f` forks the script into a session of its own and returns at
41
+ // once, so a failure to start comes back here as an answer, never as an
42
+ // error event after setup has said it's restarting.
43
+ function restartSekaipop() {
44
+ const { dir, script, found } = restartScript();
45
+ const blocker = restartBlocker(dir, found, (env.WAYLAND_DISPLAY ?? "") !== "");
46
+ if (blocker !== "")
47
+ return blocker;
48
+ const run = spawnSync("setsid", restartArgs(dir, script), { stdio: "ignore" });
49
+ if (run.error)
50
+ return `can't run its restart script: ${run.error.message}`;
51
+ return run.status === 0 ? "" : `setsid exited with ${run.status ?? run.signal}`;
52
+ }
53
+ function sekaipopRestartCommand() {
54
+ const { dir, script, found } = restartScript();
55
+ return found ? ["setsid", ...restartArgs(dir, script)].join(" ") : "";
56
+ }
13
57
  export const realSekaipopHost = {
14
58
  // Quickshell's own list of instances of the config, which counts a shell
15
59
  // started as `qs -c sekaipop` and one started from its folder with
@@ -20,6 +64,8 @@ export const realSekaipopHost = {
20
64
  barOn: () => ipc("bar", PLUGIN_ID, "on"),
21
65
  set: (key, value) => void ipc("set", PLUGIN_ID, key, value),
22
66
  now: () => new Date(),
67
+ restart: restartSekaipop,
68
+ restartCommand: sekaipopRestartCommand,
23
69
  };
24
70
  export function sekaipopPluginsDir() {
25
71
  return join(configDir(), "sekaipop", "plugins");
@@ -135,7 +181,7 @@ export function withUserThemes(manifest, themes) {
135
181
  choices.push({ value: t.id, label: t.title });
136
182
  return ok(`${JSON.stringify(data, null, 2)}\n`);
137
183
  }
138
- export function setupSekaipop(host, pluginsDir = sekaipopPluginsDir(), cli = topsideCommand(), backupDir = join(stateDir(), "topside"), settings = { dms: dmsSettings(), sekaipop: sekaipopSettings() }, themes = userThemes().filter((t) => t.usable), themesDir = defaultThemesDir()) {
184
+ export function setupSekaipop(host, pluginsDir = sekaipopPluginsDir(), cli = topsideCommand(), backupDir = join(stateDir(), "topside"), settings = { dms: dmsSettings(), sekaipop: sekaipopSettings() }, themes = userThemes().filter((t) => t.usable), themesDir = defaultThemesDir(), restart = false) {
139
185
  const target = join(pluginsDir, PLUGIN_ID);
140
186
  const upgrade = existsSync(join(target, "cli.json"));
141
187
  const cleared = clearTarget(target, backupDir, host.now());
@@ -167,9 +213,20 @@ export function setupSekaipop(host, pluginsDir = sekaipopPluginsDir(), cli = top
167
213
  ? "It's on the bar; Edit Desktop's BAR tab moves it."
168
214
  : "Turn it on in Settings > Bar > Modules, or: qs -c sekaipop ipc call plugins bar topside on");
169
215
  // A running SekaiPop keeps the QML it loaded, even across its own reload
170
- // on a file change; only rebuilding every window drops it.
171
- if (upgrade || cleared.value !== "")
172
- lines.push("SekaiPop keeps the old files until it rebuilds: Settings > General > Reload shell.");
216
+ // on a file change; only a new process drops it. Setup starts one, last,
217
+ // since it takes the shell (and its ipc) away for a moment.
218
+ if (upgrade || cleared.value !== "") {
219
+ const why = !restart ? "" : host.restart ? host.restart() : "no way to restart it";
220
+ // Asked not to, the command restarts it; a restart that couldn't run
221
+ // (over SSH, say) wouldn't from there either, so that gets the menu.
222
+ const command = restart ? "" : (host.restartCommand?.() ?? "");
223
+ if (restart && why === "")
224
+ lines.push("Restarting SekaiPop so it loads the new files.");
225
+ else if (command !== "")
226
+ lines.push(`SekaiPop keeps the old files until it restarts: ${command}`);
227
+ else
228
+ lines.push(`SekaiPop keeps the old files until it restarts${why === "" ? "" : ` (didn't restart it: ${why})`}: Settings > General > Reload shell.`);
229
+ }
173
230
  lines.push("Its settings are in Settings > Desktop > Plugins > Topside.");
174
231
  return ok(`${lines.join("\n")}\n`);
175
232
  }
@@ -204,7 +261,7 @@ export function syncSekaipopThemes(host, pluginsDir = sekaipopPluginsDir(), them
204
261
  export const sekaipopShell = {
205
262
  name: "SekaiPop",
206
263
  running: () => realSekaipopHost.running(),
207
- setup: () => Promise.resolve(setupSekaipop(realSekaipopHost)),
264
+ setup: (options) => Promise.resolve(setupSekaipop(realSekaipopHost, undefined, undefined, undefined, undefined, undefined, undefined, options.restart)),
208
265
  hiddenFolders: () => sekaipopHiddenFolders(),
209
266
  syncThemes: () => syncSekaipopThemes(realSekaipopHost),
210
267
  };
@@ -0,0 +1,77 @@
1
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { dirname, join } from "node:path";
3
+ import { configDir } from "../shared/paths.js";
4
+ import { err, ok } from "../shared/result.js";
5
+ // The daemon's systemd user unit. npm can't install one, and where npm puts
6
+ // `topside` depends on its prefix: /usr/bin with sudo, the home folder
7
+ // without it or with nvm, whose node isn't on systemd's PATH either. So the
8
+ // CLI writes the unit itself, running the same node and script it runs on.
9
+ const description = "Description=Topside daemon (Topside for Arch Linux)";
10
+ export function userUnitPath() {
11
+ return join(configDir(), "systemd", "user", "topside.service");
12
+ }
13
+ // The AUR package's unit, which the user unit would override.
14
+ export const packageUnitPath = "/usr/lib/systemd/user/topside.service";
15
+ function quoted(word) {
16
+ return /[\s"\\]/.test(word) ? `"${word.replace(/[\\"]/g, "\\$&")}"` : word;
17
+ }
18
+ export function unitText(command) {
19
+ return [
20
+ "[Unit]",
21
+ description,
22
+ "Documentation=https://topside.ducban.com/arch/",
23
+ "",
24
+ "[Service]",
25
+ `ExecStart=${[...command, "daemon"].map(quoted).join(" ")}`,
26
+ "Restart=on-failure",
27
+ "",
28
+ "[Install]",
29
+ "WantedBy=default.target",
30
+ "",
31
+ ].join("\n");
32
+ }
33
+ export function writeUnit(path, command) {
34
+ const text = unitText(command);
35
+ try {
36
+ if (existsSync(path) && readFileSync(path, "utf8") === text)
37
+ return ok("unchanged");
38
+ mkdirSync(dirname(path), { recursive: true });
39
+ writeFileSync(path, text);
40
+ return ok("written");
41
+ }
42
+ catch (error) {
43
+ return err(`can't write ${path}: ${error instanceof Error ? error.message : String(error)}`);
44
+ }
45
+ }
46
+ // For `topside setup` after an upgrade: points a unit Topside wrote (or the
47
+ // copy of contrib/systemd/topside.service the old install steps made) at this
48
+ // copy. A missing unit, or one somebody wrote by hand, is left alone.
49
+ export function refreshUnit(path, command) {
50
+ let current;
51
+ try {
52
+ if (!existsSync(path))
53
+ return ok("absent");
54
+ current = readFileSync(path, "utf8");
55
+ }
56
+ catch (error) {
57
+ return err(`can't read ${path}: ${error instanceof Error ? error.message : String(error)}`);
58
+ }
59
+ if (!current.includes(description))
60
+ return ok("not ours");
61
+ return writeUnit(path, command);
62
+ }
63
+ // What `systemctl --user show topside -p ActiveState,ExecMainStartTimestamp
64
+ // --timestamp=unix` says: whether it runs, and since when (seconds; 0 unknown).
65
+ export function serviceState(show) {
66
+ const active = /^ActiveState=active\s*$/m.test(show);
67
+ const at = /^ExecMainStartTimestamp=@(\d+)/m.exec(show)?.[1];
68
+ return { active, startedAt: at === undefined ? 0 : Number(at) };
69
+ }
70
+ // Whether `topside setup` restarts the daemon: only one that runs, and only
71
+ // when its unit now points elsewhere or it started before this copy's files
72
+ // were written, which is what upgrading in place looks like (npm swaps the
73
+ // files under a daemon that keeps the old code in memory). An unknown start
74
+ // time counts as old.
75
+ export function daemonIsStale(state, builtAt, unitWritten) {
76
+ return state.active && (unitWritten || state.startedAt < builtAt);
77
+ }
@@ -2,7 +2,8 @@ import { readFileSync } from "node:fs";
2
2
  import { dirname, join } from "node:path";
3
3
  import { fileURLToPath } from "node:url";
4
4
  import { runInNewContext } from "node:vm";
5
- // Runs a QML JavaScript library from shell/core in node: plain functions and
5
+ // Runs a QML JavaScript library in node (shell/core's, or a host's own such
6
+ // as shell/sekaipop-plugin/place.js): plain functions and
6
7
  // vars after a `.pragma library` line, with `.import "x.js" as X` lines for
7
8
  // the libraries it uses. Each runs once, in a context of its own, so the CLI
8
9
  // and the tests read the same code the QML draws with.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "topside-arch",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Topside for Arch Linux: watch your coding agents from your Quickshell bar (SekaiPop, DankMaterialShell or a pill), answer their requests, jump to their terminal",
5
5
  "keywords": [
6
6
  "claude-code",