topside-arch 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +213 -2
  3. package/contrib/aur/PKGBUILD +35 -0
  4. package/contrib/aur/topside-arch.install +25 -0
  5. package/contrib/icons/hicolor/scalable/apps/topside.svg +28 -0
  6. package/contrib/systemd/topside.service +10 -0
  7. package/contrib/themes/sakura.json +31 -0
  8. package/dist/adapters/claude/attach.js +92 -0
  9. package/dist/adapters/claude/hook-event.js +173 -0
  10. package/dist/adapters/claude/one-shot.js +30 -0
  11. package/dist/adapters/claude/settings.js +78 -0
  12. package/dist/adapters/claude/usage.js +76 -0
  13. package/dist/adapters/codex/codex.js +73 -0
  14. package/dist/adapters/codex/patch.js +39 -0
  15. package/dist/adapters/codex/usage.js +77 -0
  16. package/dist/adapters/pi/extension.js +271 -0
  17. package/dist/adapters/pi/risk-gate.js +256 -0
  18. package/dist/cli/commands.js +563 -0
  19. package/dist/cli/hook-log.js +32 -0
  20. package/dist/cli/main.js +100 -0
  21. package/dist/daemon/preview.js +70 -0
  22. package/dist/daemon/processes.js +105 -0
  23. package/dist/daemon/server.js +437 -0
  24. package/dist/daemon/session-state.js +173 -0
  25. package/dist/daemon/store.js +176 -0
  26. package/dist/dms/setup.js +126 -0
  27. package/dist/hosts/hosts.js +39 -0
  28. package/dist/jump/jump.js +199 -0
  29. package/dist/pill/config.js +92 -0
  30. package/dist/pill/launch.js +38 -0
  31. package/dist/sekaipop/setup.js +210 -0
  32. package/dist/shared/ancestry.js +27 -0
  33. package/dist/shared/client.js +29 -0
  34. package/dist/shared/package.js +25 -0
  35. package/dist/shared/paths.js +69 -0
  36. package/dist/shared/protocol.js +35 -0
  37. package/dist/shared/qml-lib.js +32 -0
  38. package/dist/shared/result.js +6 -0
  39. package/dist/shared/terminal.js +42 -0
  40. package/dist/themes/themes.js +84 -0
  41. package/package.json +49 -4
  42. package/shell/core/AgentIcon.qml +24 -0
  43. package/shell/core/AppLogo.qml +48 -0
  44. package/shell/core/ApprovalRow.qml +197 -0
  45. package/shell/core/BoardDetail.qml +296 -0
  46. package/shell/core/BoardList.qml +433 -0
  47. package/shell/core/BoardNotice.qml +187 -0
  48. package/shell/core/CardButton.qml +55 -0
  49. package/shell/core/CardHeader.qml +46 -0
  50. package/shell/core/ChalkBoard.qml +99 -0
  51. package/shell/core/CompletionCard.qml +106 -0
  52. package/shell/core/FlapText.qml +95 -0
  53. package/shell/core/KeyCap.qml +72 -0
  54. package/shell/core/Mascot.qml +13 -0
  55. package/shell/core/MascotBadge.qml +40 -0
  56. package/shell/core/MascotEffect.qml +40 -0
  57. package/shell/core/Paper.qml +54 -0
  58. package/shell/core/PixelGrid.qml +40 -0
  59. package/shell/core/QuestionRow.qml +161 -0
  60. package/shell/core/SessionRow.qml +220 -0
  61. package/shell/core/Stamp.qml +62 -0
  62. package/shell/core/StatusDots.qml +33 -0
  63. package/shell/core/Surface.qml +32 -0
  64. package/shell/core/Tag.qml +22 -0
  65. package/shell/core/TerminalIcon.qml +34 -0
  66. package/shell/core/Theme.qml +100 -0
  67. package/shell/core/TicketDetail.qml +588 -0
  68. package/shell/core/TicketList.qml +639 -0
  69. package/shell/core/TicketNotice.qml +198 -0
  70. package/shell/core/TopsideClient.qml +198 -0
  71. package/shell/core/UsageLine.qml +106 -0
  72. package/shell/core/agents.js +79 -0
  73. package/shell/core/board.js +138 -0
  74. package/shell/core/hiding.js +29 -0
  75. package/shell/core/pixels.js +542 -0
  76. package/shell/core/qmldir +30 -0
  77. package/shell/core/sounds.js +31 -0
  78. package/shell/core/themes.js +195 -0
  79. package/shell/core/ticket.js +131 -0
  80. package/shell/dms-plugin/TopsideSettings.qml +696 -0
  81. package/shell/dms-plugin/TopsideWidget.qml +572 -0
  82. package/shell/dms-plugin/plugin.json +14 -0
  83. package/shell/pill.qml +279 -0
  84. package/shell/sekaipop-plugin/Bar.qml +151 -0
  85. package/shell/sekaipop-plugin/Card.qml +291 -0
  86. package/shell/sekaipop-plugin/Floating.qml +83 -0
  87. package/shell/sekaipop-plugin/ListWindow.qml +156 -0
  88. package/shell/sekaipop-plugin/Popup.qml +70 -0
  89. package/shell/sekaipop-plugin/Service.qml +414 -0
  90. package/shell/sekaipop-plugin/ShellLook.qml +43 -0
  91. package/shell/sekaipop-plugin/StyledCard.qml +179 -0
  92. package/shell/sekaipop-plugin/plugin.json +109 -0
@@ -0,0 +1,210 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import { existsSync, lstatSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { installPlugin, PLUGIN_ID } from "../dms/setup.js";
6
+ import { configDir, stateDir, topsideCommand } from "../shared/paths.js";
7
+ import { err, ok } from "../shared/result.js";
8
+ import { themesDir as defaultThemesDir, userThemes } from "../themes/themes.js";
9
+ function ipc(...args) {
10
+ const run = spawnSync("qs", ["-c", "sekaipop", "ipc", "call", "plugins", ...args], { encoding: "utf8" });
11
+ return run.error ? "" : run.stdout.trim();
12
+ }
13
+ export const realSekaipopHost = {
14
+ // Quickshell's own list of instances of the config, which counts a shell
15
+ // started as `qs -c sekaipop` and one started from its folder with
16
+ // `qs -p` (SekaiPop's restart-shell.sh does that). pgrep on the command
17
+ // line missed the second.
18
+ running: () => (spawnSync("qs", ["list", "-c", "sekaipop"], { encoding: "utf8" }).stdout ?? "").includes("Process ID"),
19
+ reload: () => ipc("reload"),
20
+ barOn: () => ipc("bar", PLUGIN_ID, "on"),
21
+ set: (key, value) => void ipc("set", PLUGIN_ID, key, value),
22
+ now: () => new Date(),
23
+ };
24
+ export function sekaipopPluginsDir() {
25
+ return join(configDir(), "sekaipop", "plugins");
26
+ }
27
+ export function sekaipopPluginSourceDir() {
28
+ return fileURLToPath(new URL("../../shell/sekaipop-plugin/", import.meta.url));
29
+ }
30
+ // Where the shell keeps the plugin's settings (scripts/state/plugin-state.sh).
31
+ export function sekaipopStatePath() {
32
+ return join(stateDir(), "sekaipop", "plugins", `${PLUGIN_ID}.json`);
33
+ }
34
+ // The DMS widget's settings, from DMS's plugin_settings.json ({} when none).
35
+ export function dmsSettings(path = join(configDir(), "DankMaterialShell", "plugin_settings.json")) {
36
+ try {
37
+ const all = JSON.parse(readFileSync(path, "utf8"));
38
+ const mine = all?.topside;
39
+ return typeof mine === "object" && mine !== null ? mine : {};
40
+ }
41
+ catch {
42
+ return {};
43
+ }
44
+ }
45
+ // The SekaiPop entry's own settings so far ({} when none).
46
+ export function sekaipopSettings(path = sekaipopStatePath()) {
47
+ try {
48
+ const state = JSON.parse(readFileSync(path, "utf8"));
49
+ const settings = state?.settings;
50
+ return typeof settings === "object" && settings !== null ? settings : {};
51
+ }
52
+ catch {
53
+ return {};
54
+ }
55
+ }
56
+ // The keys both hosts share, so a move from DMS keeps the user's picks
57
+ // (sounds on, the reminder's wait, the theme...). Lists become lines.
58
+ const sharedKeys = [
59
+ "autoOpen", "maxDots", "reminders", "reminderMinutes", "sounds", "attentionSound", "completionSound",
60
+ "theme", "appearance", "fontSize", "hiddenFolders", "hiddenPrompts",
61
+ ];
62
+ // What to copy from DMS: only keys SekaiPop hasn't got a value for yet, so
63
+ // nothing the user set on SekaiPop is overwritten.
64
+ export function importedSettings(dms, sekaipop) {
65
+ const out = [];
66
+ for (const key of sharedKeys) {
67
+ if (key in sekaipop)
68
+ continue;
69
+ const value = dms[key];
70
+ if (Array.isArray(value)) {
71
+ const lines = value.filter((v) => typeof v === "string");
72
+ if (lines.length > 0)
73
+ out.push([key, lines.join("\n")]);
74
+ }
75
+ else if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
76
+ out.push([key, String(value)]);
77
+ }
78
+ }
79
+ return out;
80
+ }
81
+ // Folders hidden on the SekaiPop entry: its `hiddenFolders` setting, one per line.
82
+ export function sekaipopHiddenFolders(path = sekaipopStatePath()) {
83
+ try {
84
+ const state = JSON.parse(readFileSync(path, "utf8"));
85
+ const text = state?.settings?.hiddenFolders;
86
+ if (typeof text !== "string")
87
+ return [];
88
+ return text.split("\n").map((line) => line.trim()).filter((line) => line !== "");
89
+ }
90
+ catch {
91
+ return [];
92
+ }
93
+ }
94
+ // A folder setup didn't write (no cli.json) is someone's own plugin: it's
95
+ // moved aside into Topside's state folder, never deleted. One setup wrote
96
+ // is replaced; its `core` is dropped first, since an old hand-made one was
97
+ // a link into the repo and copying through it would write there.
98
+ function clearTarget(target, backupDir, now) {
99
+ if (!existsSync(target))
100
+ return ok("");
101
+ try {
102
+ if (!existsSync(join(target, "cli.json"))) {
103
+ mkdirSync(backupDir, { recursive: true });
104
+ const backup = join(backupDir, `sekaipop-plugin-${now.toISOString().replace(/[:.]/g, "-")}`);
105
+ renameSync(target, backup);
106
+ return ok(backup);
107
+ }
108
+ const core = join(target, "core");
109
+ if (existsSync(core) || lstatSync(core, { throwIfNoEntry: false }))
110
+ rmSync(core, { recursive: true, force: true });
111
+ return ok("");
112
+ }
113
+ catch (error) {
114
+ return err(`can't clear ${target}: ${error instanceof Error ? error.message : String(error)}`);
115
+ }
116
+ }
117
+ // SekaiPop's form only offers the choices plugin.json lists, so the copy
118
+ // setup installs lists your usable theme files after the built-in ones.
119
+ export function withUserThemes(manifest, themes) {
120
+ if (themes.length === 0)
121
+ return ok(manifest);
122
+ let data;
123
+ try {
124
+ data = JSON.parse(manifest);
125
+ }
126
+ catch (error) {
127
+ return err(`plugin.json isn't JSON: ${error.message}`);
128
+ }
129
+ const choices = data.settingsInfo?.theme?.choices;
130
+ if (!choices)
131
+ return err("plugin.json has no theme choices");
132
+ const known = new Set(choices.map((c) => c.value));
133
+ for (const t of themes)
134
+ if (!known.has(t.id))
135
+ choices.push({ value: t.id, label: t.title });
136
+ return ok(`${JSON.stringify(data, null, 2)}\n`);
137
+ }
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()) {
139
+ const target = join(pluginsDir, PLUGIN_ID);
140
+ const upgrade = existsSync(join(target, "cli.json"));
141
+ const cleared = clearTarget(target, backupDir, host.now());
142
+ if (!cleared.ok)
143
+ return cleared;
144
+ const installed = installPlugin(pluginsDir, cli, sekaipopPluginSourceDir());
145
+ if (!installed.ok)
146
+ return installed;
147
+ // Service.qml watches it for theme files, so it has to exist.
148
+ mkdirSync(themesDir, { recursive: true });
149
+ const manifestPath = join(installed.value, "plugin.json");
150
+ const manifest = withUserThemes(readFileSync(manifestPath, "utf8"), themes);
151
+ if (!manifest.ok)
152
+ return manifest;
153
+ writeFileSync(manifestPath, manifest.value);
154
+ host.reload();
155
+ const bar = host.barOn();
156
+ const imported = importedSettings(settings.dms, settings.sekaipop);
157
+ for (const [key, value] of imported)
158
+ host.set(key, value);
159
+ const lines = [`${upgrade ? "Updated" : "Installed"} the Topside entry for SekaiPop in ${installed.value}.`];
160
+ if (cleared.value !== "")
161
+ lines.push(`The plugin that was there is in ${cleared.value}.`);
162
+ if (themes.length > 0)
163
+ lines.push(`Your themes are in its Theme list: ${themes.map((t) => t.id).join(", ")}.`);
164
+ if (imported.length > 0)
165
+ lines.push(`Brought over your DMS settings: ${imported.map(([key]) => key).join(", ")}.`);
166
+ lines.push(bar.endsWith("on")
167
+ ? "It's on the bar; Edit Desktop's BAR tab moves it."
168
+ : "Turn it on in Settings > Bar > Modules, or: qs -c sekaipop ipc call plugins bar topside on");
169
+ // 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.");
173
+ lines.push("Its settings are in Settings > Desktop > Plugins > Topside.");
174
+ return ok(`${lines.join("\n")}\n`);
175
+ }
176
+ // SekaiPop as a shell Topside can live in (src/hosts/hosts.ts).
177
+ // Rewrites the installed plugin.json's Theme choices from the shipped one
178
+ // plus the usable theme files, so a file added, renamed or removed shows in
179
+ // SekaiPop's form; then asks a running SekaiPop to read it again. Nothing
180
+ // happens when Topside isn't installed there or the list is the same.
181
+ export function syncSekaipopThemes(host, pluginsDir = sekaipopPluginsDir(), themes = userThemes().filter((t) => t.usable)) {
182
+ const installed = join(pluginsDir, PLUGIN_ID, "plugin.json");
183
+ if (!existsSync(join(pluginsDir, PLUGIN_ID, "cli.json")) || !existsSync(installed))
184
+ return ok("");
185
+ const wanted = withUserThemes(readFileSync(join(sekaipopPluginSourceDir(), "plugin.json"), "utf8"), themes);
186
+ if (!wanted.ok)
187
+ return wanted;
188
+ const current = readFileSync(installed, "utf8");
189
+ const same = (() => {
190
+ try {
191
+ return JSON.stringify(JSON.parse(current)) === JSON.stringify(JSON.parse(wanted.value));
192
+ }
193
+ catch {
194
+ return false;
195
+ }
196
+ })();
197
+ if (same)
198
+ return ok("");
199
+ writeFileSync(installed, wanted.value);
200
+ if (host.running())
201
+ host.reload();
202
+ return ok(`SekaiPop's Theme list now has ${themes.length === 0 ? "only the built-in themes" : `yours too: ${themes.map((t) => t.id).join(", ")}`}.`);
203
+ }
204
+ export const sekaipopShell = {
205
+ name: "SekaiPop",
206
+ running: () => realSekaipopHost.running(),
207
+ setup: () => Promise.resolve(setupSekaipop(realSekaipopHost)),
208
+ hiddenFolders: () => sekaipopHiddenFolders(),
209
+ syncThemes: () => syncSekaipopThemes(realSekaipopHost),
210
+ };
@@ -0,0 +1,27 @@
1
+ import { readFileSync } from "node:fs";
2
+ // Walks /proc from `pid` up to (not including) init. Nearest process first.
3
+ export function ancestry(pid) {
4
+ const chain = [];
5
+ let current = pid;
6
+ while (current > 1 && chain.length < 64) {
7
+ chain.push(current);
8
+ const parent = parentOf(current);
9
+ if (parent === null)
10
+ break;
11
+ current = parent;
12
+ }
13
+ return chain;
14
+ }
15
+ function parentOf(pid) {
16
+ let stat;
17
+ try {
18
+ stat = readFileSync(`/proc/${pid}/stat`, "utf8");
19
+ }
20
+ catch {
21
+ return null;
22
+ }
23
+ // The comm field can contain spaces and parens, so read after the last ")".
24
+ const fields = stat.slice(stat.lastIndexOf(")") + 2).split(" ");
25
+ const ppid = Number(fields[1]);
26
+ return Number.isInteger(ppid) ? ppid : null;
27
+ }
@@ -0,0 +1,29 @@
1
+ import { connect } from "node:net";
2
+ import { createInterface } from "node:readline";
3
+ import { encode, parseServerMessage } from "./protocol.js";
4
+ import { err, ok } from "./result.js";
5
+ export function openConnection(path) {
6
+ return new Promise((resolve) => {
7
+ const socket = connect(path);
8
+ socket.once("connect", () => resolve(ok(socket)));
9
+ socket.once("error", (error) => resolve(err(`cannot reach the Topside daemon at ${path}: ${error.message}`)));
10
+ });
11
+ }
12
+ // Sends one message and resolves with the first reply. `timeoutMs` of 0 waits forever.
13
+ export async function request(path, message, timeoutMs = 2000) {
14
+ const connection = await openConnection(path);
15
+ if (!connection.ok)
16
+ return connection;
17
+ const socket = connection.value;
18
+ return new Promise((resolve) => {
19
+ const done = (result) => {
20
+ clearTimeout(timer);
21
+ socket.destroy();
22
+ resolve(result);
23
+ };
24
+ const timer = timeoutMs > 0 ? setTimeout(() => done(err("the Topside daemon did not answer in time")), timeoutMs) : undefined;
25
+ createInterface({ input: socket }).once("line", (line) => done(parseServerMessage(line)));
26
+ socket.once("close", () => done(err("the Topside daemon closed the connection")));
27
+ socket.write(encode(message));
28
+ });
29
+ }
@@ -0,0 +1,25 @@
1
+ import { readFileSync } from "node:fs";
2
+ const isObject = (value) => typeof value === "object" && value !== null;
3
+ // npm takes `author` as "Name <mail>" or as { name, email, url }.
4
+ export function parsePackage(text) {
5
+ let pkg;
6
+ try {
7
+ pkg = JSON.parse(text);
8
+ }
9
+ catch {
10
+ return { version: "unknown", author: "" };
11
+ }
12
+ if (!isObject(pkg))
13
+ return { version: "unknown", author: "" };
14
+ const version = typeof pkg.version === "string" ? pkg.version : "unknown";
15
+ const author = typeof pkg.author === "string" ? pkg.author : isObject(pkg.author) && typeof pkg.author.name === "string" ? pkg.author.name : "";
16
+ return { version, author };
17
+ }
18
+ export function packageInfo() {
19
+ try {
20
+ return parsePackage(readFileSync(new URL("../../package.json", import.meta.url), "utf8"));
21
+ }
22
+ catch {
23
+ return { version: "unknown", author: "" };
24
+ }
25
+ }
@@ -0,0 +1,69 @@
1
+ import { existsSync, mkdirSync, realpathSync, renameSync } from "node:fs";
2
+ import { homedir, tmpdir, userInfo } from "node:os";
3
+ import { dirname, join } from "node:path";
4
+ import { argv, env, execPath } from "node:process";
5
+ import { err, ok } from "./result.js";
6
+ // How to run this same `topside` again from elsewhere (Claude Code hooks, QML),
7
+ // without relying on PATH: the node binary plus the resolved script.
8
+ export function topsideCommand() {
9
+ return argv[1] ? [execPath, realpathSync(argv[1])] : ["topside"];
10
+ }
11
+ export function socketPath() {
12
+ const explicit = env.TOPSIDE_SOCKET ?? env.VIA_SOCKET;
13
+ if (explicit)
14
+ return explicit;
15
+ const runtime = env.XDG_RUNTIME_DIR ?? join(tmpdir(), `topside-${userInfo().uid}`);
16
+ return join(runtime, "topside", "topside.sock");
17
+ }
18
+ export function dbPath() {
19
+ const explicit = env.TOPSIDE_DB ?? env.VIA_DB;
20
+ if (explicit)
21
+ return explicit;
22
+ return join(stateDir(), "topside", "topside.db");
23
+ }
24
+ export function claudeConfigDir() {
25
+ return env.CLAUDE_CONFIG_DIR ?? join(homedir(), ".claude");
26
+ }
27
+ export function claudeSettingsPath() {
28
+ return join(claudeConfigDir(), "settings.json");
29
+ }
30
+ export function stateDir() {
31
+ return env.XDG_STATE_HOME ?? join(homedir(), ".local", "state");
32
+ }
33
+ export function configDir() {
34
+ return env.XDG_CONFIG_HOME ?? join(homedir(), ".config");
35
+ }
36
+ export function legacyMoves() {
37
+ const db = ["", "-wal", "-shm"].map((suffix) => ({
38
+ from: join(stateDir(), "via", `via.db${suffix}`),
39
+ to: join(stateDir(), "topside", `topside.db${suffix}`),
40
+ }));
41
+ return [db, [{ from: join(configDir(), "via", "config.json"), to: join(configDir(), "topside", "config.json") }]];
42
+ }
43
+ export function moveLegacyFiles(groups) {
44
+ const moved = [];
45
+ for (const group of groups) {
46
+ const [main] = group;
47
+ if (!main || !existsSync(main.from) || existsSync(main.to))
48
+ continue;
49
+ for (const { from, to } of group) {
50
+ if (!existsSync(from))
51
+ continue;
52
+ try {
53
+ mkdirSync(dirname(to), { recursive: true });
54
+ renameSync(from, to);
55
+ moved.push(to);
56
+ }
57
+ catch (error) {
58
+ return err(`can't move ${from} to ${to}: ${error instanceof Error ? error.message : String(error)}`);
59
+ }
60
+ }
61
+ }
62
+ return ok(moved);
63
+ }
64
+ export function codexHome() {
65
+ return env.CODEX_HOME ?? join(homedir(), ".codex");
66
+ }
67
+ export function codexHooksPath() {
68
+ return join(codexHome(), "hooks.json");
69
+ }
@@ -0,0 +1,35 @@
1
+ import { err, ok } from "./result.js";
2
+ export const agentNames = ["claude", "codex", "pi", "omp"];
3
+ export function isAgentName(value) {
4
+ return typeof value === "string" && agentNames.includes(value);
5
+ }
6
+ const clientOps = new Set(["event", "approval", "decide", "seen", "ask", "answer", "usage", "snapshot", "subscribe"]);
7
+ const serverOps = new Set(["ack", "error", "decision", "answers", "snapshot"]);
8
+ export function encode(message) {
9
+ return `${JSON.stringify(message)}\n`;
10
+ }
11
+ function parseOp(line, allowed) {
12
+ let value;
13
+ try {
14
+ value = JSON.parse(line);
15
+ }
16
+ catch {
17
+ return err("invalid JSON");
18
+ }
19
+ if (typeof value !== "object" || value === null || !("op" in value) || typeof value.op !== "string") {
20
+ return err("missing op");
21
+ }
22
+ if (!allowed.has(value.op)) {
23
+ return err(`unknown op: ${value.op}`);
24
+ }
25
+ return ok(value);
26
+ }
27
+ // Shape checks stay shallow: both ends are this codebase, the socket is user-only.
28
+ export function parseClientMessage(line) {
29
+ const parsed = parseOp(line, clientOps);
30
+ return parsed.ok ? ok(parsed.value) : parsed;
31
+ }
32
+ export function parseServerMessage(line) {
33
+ const parsed = parseOp(line, serverOps);
34
+ return parsed.ok ? ok(parsed.value) : parsed;
35
+ }
@@ -0,0 +1,32 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { dirname, join } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { runInNewContext } from "node:vm";
5
+ // Runs a QML JavaScript library from shell/core in node: plain functions and
6
+ // vars after a `.pragma library` line, with `.import "x.js" as X` lines for
7
+ // the libraries it uses. Each runs once, in a context of its own, so the CLI
8
+ // and the tests read the same code the QML draws with.
9
+ const loaded = new Map();
10
+ const importLine = /^\.import\s+"([^"]+\.js)"\s+as\s+(\w+)\s*;?\s*$/;
11
+ export function loadQmlLib(file) {
12
+ const cached = loaded.get(file);
13
+ if (cached)
14
+ return cached;
15
+ const context = {};
16
+ const lines = readFileSync(file, "utf8").split("\n").map((line) => {
17
+ if (line.trim() === ".pragma library")
18
+ return "";
19
+ const found = importLine.exec(line.trim());
20
+ if (!found)
21
+ return line;
22
+ context[found[2] ?? ""] = loadQmlLib(join(dirname(file), found[1] ?? ""));
23
+ return "";
24
+ });
25
+ runInNewContext(lines.join("\n"), context, { filename: file });
26
+ loaded.set(file, context);
27
+ return context;
28
+ }
29
+ // A library in shell/core by its file name.
30
+ export function coreLib(name) {
31
+ return loadQmlLib(fileURLToPath(new URL(`../../shell/core/${name}`, import.meta.url)));
32
+ }
@@ -0,0 +1,6 @@
1
+ export function ok(value) {
2
+ return { ok: true, value };
3
+ }
4
+ export function err(error) {
5
+ return { ok: false, error };
6
+ }
@@ -0,0 +1,42 @@
1
+ export const noTerminal = {
2
+ program: "",
3
+ tmuxSocket: "",
4
+ tmuxPane: "",
5
+ weztermSocket: "",
6
+ weztermPane: "",
7
+ orcaCli: "",
8
+ orcaTerminal: "",
9
+ };
10
+ // A terminal started from another one inherits its variables (a WezTerm
11
+ // launched from Orca carries ORCA_*), so only the fields of the terminal
12
+ // TERM_PROGRAM names are kept. tmux 3.2+ sets TERM_PROGRAM=tmux.
13
+ export function terminalHint(env) {
14
+ const program = env.TERM_PROGRAM ?? "";
15
+ const hint = { ...noTerminal, program };
16
+ if (program === "tmux" && env.TMUX) {
17
+ hint.tmuxSocket = env.TMUX.split(",")[0] ?? "";
18
+ hint.tmuxPane = env.TMUX_PANE ?? "";
19
+ }
20
+ else if (program === "WezTerm") {
21
+ hint.weztermSocket = env.WEZTERM_UNIX_SOCKET ?? "";
22
+ hint.weztermPane = env.WEZTERM_PANE ?? "";
23
+ }
24
+ else if (program === "Orca") {
25
+ hint.orcaCli = env.ORCA_CLI_COMMAND ?? "";
26
+ hint.orcaTerminal = env.ORCA_TERMINAL_HANDLE ?? "";
27
+ }
28
+ return hint;
29
+ }
30
+ // Tolerant read for stored JSON: unknown or missing keys fall back to "".
31
+ export function toTerminalHint(value) {
32
+ if (typeof value !== "object" || value === null)
33
+ return noTerminal;
34
+ const record = value;
35
+ const hint = { ...noTerminal };
36
+ for (const key of Object.keys(noTerminal)) {
37
+ const field = record[key];
38
+ if (typeof field === "string")
39
+ hint[key] = field;
40
+ }
41
+ return hint;
42
+ }
@@ -0,0 +1,84 @@
1
+ import { existsSync, readdirSync, readFileSync } from "node:fs";
2
+ import { basename, extname, join } from "node:path";
3
+ import { env } from "node:process";
4
+ import { configDir } from "../shared/paths.js";
5
+ import { coreLib } from "../shared/qml-lib.js";
6
+ import { err, ok } from "../shared/result.js";
7
+ // shell/core/themes.js, run by coreLib.
8
+ export function themesLib() {
9
+ return coreLib("themes.js");
10
+ }
11
+ export function themesDir() {
12
+ return env.TOPSIDE_THEMES ?? join(configDir(), "topside", "themes");
13
+ }
14
+ // A file's name is the theme's id, which the settings store.
15
+ const idPattern = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
16
+ export function readThemeFile(path) {
17
+ const id = basename(path, extname(path));
18
+ const lib = themesLib();
19
+ let text;
20
+ try {
21
+ text = readFileSync(path, "utf8");
22
+ }
23
+ catch (error) {
24
+ return { id, title: id, source: path, usable: false, problems: [`can't read it: ${error.message}`] };
25
+ }
26
+ const read = lib.read(text);
27
+ const problems = [...read.problems];
28
+ let usable = read.theme !== null;
29
+ if (!idPattern.test(id)) {
30
+ problems.unshift(`the file's name must be letters, digits, - and _ (it is the theme's id)`);
31
+ usable = false;
32
+ }
33
+ if (lib.names.includes(id)) {
34
+ problems.unshift(`"${id}" is a built-in theme's id, and the built-in wins; rename the file`);
35
+ usable = false;
36
+ }
37
+ return { id, title: read.theme?.name || id, source: path, usable, problems };
38
+ }
39
+ export function builtInThemes() {
40
+ const lib = themesLib();
41
+ return lib.names.map((id) => ({ id, title: lib.titles[id] ?? id, source: "built-in", usable: true, problems: [] }));
42
+ }
43
+ export function userThemes(dir = themesDir()) {
44
+ if (!existsSync(dir))
45
+ return [];
46
+ let files;
47
+ try {
48
+ files = readdirSync(dir).filter((f) => f.endsWith(".json"));
49
+ }
50
+ catch {
51
+ return [];
52
+ }
53
+ return files.sort().map((f) => readThemeFile(join(dir, f)));
54
+ }
55
+ export function allThemes(dir = themesDir()) {
56
+ return [...builtInThemes(), ...userThemes(dir)];
57
+ }
58
+ // A theme by id (built-in or a file in the folder), or a file by path.
59
+ export function findTheme(nameOrPath, dir = themesDir()) {
60
+ if (nameOrPath.includes("/") || nameOrPath.endsWith(".json")) {
61
+ return existsSync(nameOrPath) ? ok(readThemeFile(nameOrPath)) : err(`no file at ${nameOrPath}`);
62
+ }
63
+ const found = allThemes(dir).find((t) => t.id === nameOrPath);
64
+ return found ? ok(found) : err(`no theme "${nameOrPath}": not built in, and no ${join(dir, `${nameOrPath}.json`)}`);
65
+ }
66
+ export function formatThemes(entries, dir = themesDir()) {
67
+ const width = Math.max(...entries.map((t) => t.id.length));
68
+ const line = (t) => {
69
+ const mark = !t.usable ? "✗" : t.problems.length > 0 ? "!" : "✓";
70
+ const title = t.title !== t.id ? ` ${t.title}` : "";
71
+ return `${mark} ${t.id.padEnd(width)}${title}${t.source === "built-in" ? "" : " (yours)"}`;
72
+ };
73
+ const yours = entries.filter((t) => t.source !== "built-in");
74
+ const tail = yours.length === 0 ? `\nNo themes of your own yet. Put one in ${dir}/<id>.json; see the README.\n` : yours.some((t) => t.problems.length > 0) ? `\nSee what's wrong with: topside theme check <id>\n` : "";
75
+ return entries.map(line).join("\n") + "\n" + tail;
76
+ }
77
+ export function formatCheck(entry) {
78
+ if (entry.source === "built-in")
79
+ return `${entry.id} is built in and fine.\n`;
80
+ if (entry.problems.length === 0)
81
+ return `${entry.id} (${entry.source}) is fine.\n`;
82
+ const verdict = entry.usable ? "Topside draws it, leaving out what's wrong:" : "Topside can't draw it, so it falls back to Topside Black:";
83
+ return `${entry.id} (${entry.source})\n${verdict}\n${entry.problems.map((p) => ` - ${p}`).join("\n")}\n`;
84
+ }
package/package.json CHANGED
@@ -1,6 +1,51 @@
1
1
  {
2
2
  "name": "topside-arch",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
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
+ "keywords": [
6
+ "claude-code",
7
+ "codex",
8
+ "coding-agents",
9
+ "quickshell",
10
+ "hyprland",
11
+ "arch-linux",
12
+ "dankmaterialshell",
13
+ "sekaipop"
14
+ ],
15
+ "homepage": "https://topside.ducban.com/arch/",
16
+ "bugs": {
17
+ "url": "https://github.com/ducban/topside/issues"
18
+ },
19
+ "license": "MIT",
20
+ "author": "Nguyen Duc Ban",
21
+ "type": "module",
22
+ "bin": {
23
+ "topside": "dist/cli/main.js",
24
+ "via": "dist/cli/main.js"
25
+ },
26
+ "files": [
27
+ "dist",
28
+ "!dist/**/*.test.js",
29
+ "contrib",
30
+ "shell"
31
+ ],
32
+ "engines": {
33
+ "node": ">=26"
34
+ },
35
+ "scripts": {
36
+ "build": "tsc",
37
+ "typecheck": "tsc --noEmit",
38
+ "test": "node --test \"src/**/*.test.ts\"",
39
+ "lint": "eslint src/",
40
+ "release:patch": "bash scripts/release.sh patch",
41
+ "release:minor": "bash scripts/release.sh minor",
42
+ "release:major": "bash scripts/release.sh major"
43
+ },
44
+ "devDependencies": {
45
+ "@eslint/js": "^10.0.1",
46
+ "@types/node": "^26.6.5",
47
+ "eslint": "^10.13.0",
48
+ "typescript": "~6.0.3",
49
+ "typescript-eslint": "^8.72.0"
50
+ }
51
+ }
@@ -0,0 +1,24 @@
1
+ import QtQuick
2
+ import "agents.js" as Agents
3
+
4
+ // An agent's mark on a rounded square of its color. Drawn, not borrowed.
5
+ Rectangle {
6
+ id: icon
7
+ property string agent: "claude"
8
+ property real size: 18
9
+ readonly property var style: Agents.style(agent)
10
+
11
+ width: size
12
+ height: size
13
+ radius: size * 0.24
14
+ color: style.tint
15
+
16
+ Text {
17
+ anchors.centerIn: parent
18
+ text: icon.style.mark
19
+ color: "white"
20
+ font.pixelSize: icon.size * (icon.style.mark.length > 1 ? 0.52 : 0.62)
21
+ font.weight: Font.Black
22
+ font.family: icon.style.mark.length > 1 ? Theme.monoFont : Theme.font
23
+ }
24
+ }