topside-arch 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +217 -2
- package/contrib/aur/.SRCINFO +20 -0
- package/contrib/aur/PKGBUILD +35 -0
- package/contrib/aur/topside-arch.install +28 -0
- package/contrib/icons/hicolor/scalable/apps/topside.svg +28 -0
- package/contrib/systemd/topside.service +10 -0
- package/contrib/themes/sakura.json +31 -0
- package/dist/adapters/claude/attach.js +92 -0
- package/dist/adapters/claude/hook-event.js +173 -0
- package/dist/adapters/claude/one-shot.js +30 -0
- package/dist/adapters/claude/settings.js +78 -0
- package/dist/adapters/claude/usage.js +76 -0
- package/dist/adapters/codex/codex.js +73 -0
- package/dist/adapters/codex/patch.js +39 -0
- package/dist/adapters/codex/usage.js +77 -0
- package/dist/adapters/pi/extension.js +271 -0
- package/dist/adapters/pi/risk-gate.js +256 -0
- package/dist/cli/commands.js +615 -0
- package/dist/cli/hook-log.js +32 -0
- package/dist/cli/main.js +100 -0
- package/dist/daemon/preview.js +70 -0
- package/dist/daemon/processes.js +105 -0
- package/dist/daemon/server.js +437 -0
- package/dist/daemon/session-state.js +179 -0
- package/dist/daemon/store.js +176 -0
- package/dist/dms/setup.js +137 -0
- package/dist/hosts/hosts.js +39 -0
- package/dist/jump/jump.js +199 -0
- package/dist/pill/config.js +92 -0
- package/dist/pill/launch.js +38 -0
- package/dist/sekaipop/setup.js +267 -0
- package/dist/service/unit.js +77 -0
- package/dist/shared/ancestry.js +27 -0
- package/dist/shared/client.js +29 -0
- package/dist/shared/package.js +25 -0
- package/dist/shared/paths.js +69 -0
- package/dist/shared/protocol.js +35 -0
- package/dist/shared/qml-lib.js +33 -0
- package/dist/shared/result.js +6 -0
- package/dist/shared/terminal.js +42 -0
- package/dist/themes/themes.js +84 -0
- package/package.json +49 -4
- package/shell/core/AgentIcon.qml +24 -0
- package/shell/core/AppLogo.qml +48 -0
- package/shell/core/ApprovalRow.qml +197 -0
- package/shell/core/BoardDetail.qml +336 -0
- package/shell/core/BoardList.qml +419 -0
- package/shell/core/BoardNotice.qml +189 -0
- package/shell/core/CardButton.qml +55 -0
- package/shell/core/CardHeader.qml +46 -0
- package/shell/core/ChalkBoard.qml +99 -0
- package/shell/core/CompletionCard.qml +106 -0
- package/shell/core/FlapText.qml +110 -0
- package/shell/core/KeyCap.qml +72 -0
- package/shell/core/Mascot.qml +13 -0
- package/shell/core/MascotBadge.qml +40 -0
- package/shell/core/MascotEffect.qml +40 -0
- package/shell/core/Paper.qml +54 -0
- package/shell/core/PixelGrid.qml +40 -0
- package/shell/core/QuestionRow.qml +161 -0
- package/shell/core/SessionRow.qml +257 -0
- package/shell/core/Stamp.qml +62 -0
- package/shell/core/StatusDots.qml +33 -0
- package/shell/core/Surface.qml +32 -0
- package/shell/core/Tag.qml +22 -0
- package/shell/core/TerminalIcon.qml +34 -0
- package/shell/core/Theme.qml +100 -0
- package/shell/core/TicketDetail.qml +657 -0
- package/shell/core/TicketList.qml +717 -0
- package/shell/core/TicketNotice.qml +198 -0
- package/shell/core/TopsideClient.qml +201 -0
- package/shell/core/UsageLine.qml +106 -0
- package/shell/core/agents.js +79 -0
- package/shell/core/board.js +132 -0
- package/shell/core/hiding.js +68 -0
- package/shell/core/pixels.js +542 -0
- package/shell/core/qmldir +30 -0
- package/shell/core/sounds.js +31 -0
- package/shell/core/themes.js +195 -0
- package/shell/core/ticket.js +170 -0
- package/shell/dms-plugin/TopsideSettings.qml +696 -0
- package/shell/dms-plugin/TopsideWidget.qml +554 -0
- package/shell/dms-plugin/plugin.json +14 -0
- package/shell/pill.qml +279 -0
- package/shell/sekaipop-plugin/Bar.qml +150 -0
- package/shell/sekaipop-plugin/Card.qml +296 -0
- package/shell/sekaipop-plugin/Floating.qml +74 -0
- package/shell/sekaipop-plugin/ListWindow.qml +156 -0
- package/shell/sekaipop-plugin/Popup.qml +70 -0
- package/shell/sekaipop-plugin/Service.qml +418 -0
- package/shell/sekaipop-plugin/ShellLook.qml +43 -0
- package/shell/sekaipop-plugin/StyledCard.qml +194 -0
- package/shell/sekaipop-plugin/place.js +28 -0
- package/shell/sekaipop-plugin/plugin.json +109 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { env } from "node:process";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { socketPath, topsideCommand } from "../shared/paths.js";
|
|
6
|
+
import { err, ok } from "../shared/result.js";
|
|
7
|
+
import { configPath, readConfig, writeConfig } from "./config.js";
|
|
8
|
+
// shell/ ships next to dist/ in the package, so derive it from this file.
|
|
9
|
+
// Quickshell confines a config to the root file's directory, so the pill root
|
|
10
|
+
// sits in shell/ itself and imports "core" from there.
|
|
11
|
+
export function pillShellFile() {
|
|
12
|
+
return fileURLToPath(new URL("../../shell/pill.qml", import.meta.url));
|
|
13
|
+
}
|
|
14
|
+
// Runs quickshell with the pill until it exits. The config file is written
|
|
15
|
+
// first so the pill has a file to watch for position changes.
|
|
16
|
+
export async function launchPill() {
|
|
17
|
+
const shellFile = pillShellFile();
|
|
18
|
+
if (!existsSync(shellFile))
|
|
19
|
+
return err(`pill shell not found at ${shellFile}`);
|
|
20
|
+
const config = configPath();
|
|
21
|
+
if (!existsSync(config)) {
|
|
22
|
+
const written = writeConfig(config, readConfig(config));
|
|
23
|
+
if (!written.ok)
|
|
24
|
+
return written;
|
|
25
|
+
}
|
|
26
|
+
return new Promise((resolve) => {
|
|
27
|
+
const child = spawn("quickshell", ["-p", shellFile], {
|
|
28
|
+
stdio: "inherit",
|
|
29
|
+
// TOPSIDE_CLI lets the pill run `topside jump` without `topside` on PATH.
|
|
30
|
+
env: { ...env, TOPSIDE_SOCKET: socketPath(), TOPSIDE_CONFIG: config, TOPSIDE_CLI: JSON.stringify(topsideCommand()) },
|
|
31
|
+
});
|
|
32
|
+
child.once("error", (error) => {
|
|
33
|
+
const reason = "code" in error && error.code === "ENOENT" ? "quickshell is not installed" : error.message;
|
|
34
|
+
resolve(err(`can't start the pill: ${reason}`));
|
|
35
|
+
});
|
|
36
|
+
child.once("exit", (code) => resolve(code === 0 || code === null ? ok(undefined) : err(`quickshell exited with ${code}`)));
|
|
37
|
+
});
|
|
38
|
+
}
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { existsSync, lstatSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { env } from "node:process";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { installPlugin, PLUGIN_ID } from "../dms/setup.js";
|
|
7
|
+
import { configDir, stateDir, topsideCommand } from "../shared/paths.js";
|
|
8
|
+
import { err, ok } from "../shared/result.js";
|
|
9
|
+
import { themesDir as defaultThemesDir, userThemes } from "../themes/themes.js";
|
|
10
|
+
function ipc(...args) {
|
|
11
|
+
const run = spawnSync("qs", ["-c", "sekaipop", "ipc", "call", "plugins", ...args], { encoding: "utf8" });
|
|
12
|
+
return run.error ? "" : run.stdout.trim();
|
|
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
|
+
}
|
|
57
|
+
export const realSekaipopHost = {
|
|
58
|
+
// Quickshell's own list of instances of the config, which counts a shell
|
|
59
|
+
// started as `qs -c sekaipop` and one started from its folder with
|
|
60
|
+
// `qs -p` (SekaiPop's restart-shell.sh does that). pgrep on the command
|
|
61
|
+
// line missed the second.
|
|
62
|
+
running: () => (spawnSync("qs", ["list", "-c", "sekaipop"], { encoding: "utf8" }).stdout ?? "").includes("Process ID"),
|
|
63
|
+
reload: () => ipc("reload"),
|
|
64
|
+
barOn: () => ipc("bar", PLUGIN_ID, "on"),
|
|
65
|
+
set: (key, value) => void ipc("set", PLUGIN_ID, key, value),
|
|
66
|
+
now: () => new Date(),
|
|
67
|
+
restart: restartSekaipop,
|
|
68
|
+
restartCommand: sekaipopRestartCommand,
|
|
69
|
+
};
|
|
70
|
+
export function sekaipopPluginsDir() {
|
|
71
|
+
return join(configDir(), "sekaipop", "plugins");
|
|
72
|
+
}
|
|
73
|
+
export function sekaipopPluginSourceDir() {
|
|
74
|
+
return fileURLToPath(new URL("../../shell/sekaipop-plugin/", import.meta.url));
|
|
75
|
+
}
|
|
76
|
+
// Where the shell keeps the plugin's settings (scripts/state/plugin-state.sh).
|
|
77
|
+
export function sekaipopStatePath() {
|
|
78
|
+
return join(stateDir(), "sekaipop", "plugins", `${PLUGIN_ID}.json`);
|
|
79
|
+
}
|
|
80
|
+
// The DMS widget's settings, from DMS's plugin_settings.json ({} when none).
|
|
81
|
+
export function dmsSettings(path = join(configDir(), "DankMaterialShell", "plugin_settings.json")) {
|
|
82
|
+
try {
|
|
83
|
+
const all = JSON.parse(readFileSync(path, "utf8"));
|
|
84
|
+
const mine = all?.topside;
|
|
85
|
+
return typeof mine === "object" && mine !== null ? mine : {};
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return {};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// The SekaiPop entry's own settings so far ({} when none).
|
|
92
|
+
export function sekaipopSettings(path = sekaipopStatePath()) {
|
|
93
|
+
try {
|
|
94
|
+
const state = JSON.parse(readFileSync(path, "utf8"));
|
|
95
|
+
const settings = state?.settings;
|
|
96
|
+
return typeof settings === "object" && settings !== null ? settings : {};
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
return {};
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// The keys both hosts share, so a move from DMS keeps the user's picks
|
|
103
|
+
// (sounds on, the reminder's wait, the theme...). Lists become lines.
|
|
104
|
+
const sharedKeys = [
|
|
105
|
+
"autoOpen", "maxDots", "reminders", "reminderMinutes", "sounds", "attentionSound", "completionSound",
|
|
106
|
+
"theme", "appearance", "fontSize", "hiddenFolders", "hiddenPrompts",
|
|
107
|
+
];
|
|
108
|
+
// What to copy from DMS: only keys SekaiPop hasn't got a value for yet, so
|
|
109
|
+
// nothing the user set on SekaiPop is overwritten.
|
|
110
|
+
export function importedSettings(dms, sekaipop) {
|
|
111
|
+
const out = [];
|
|
112
|
+
for (const key of sharedKeys) {
|
|
113
|
+
if (key in sekaipop)
|
|
114
|
+
continue;
|
|
115
|
+
const value = dms[key];
|
|
116
|
+
if (Array.isArray(value)) {
|
|
117
|
+
const lines = value.filter((v) => typeof v === "string");
|
|
118
|
+
if (lines.length > 0)
|
|
119
|
+
out.push([key, lines.join("\n")]);
|
|
120
|
+
}
|
|
121
|
+
else if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
122
|
+
out.push([key, String(value)]);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return out;
|
|
126
|
+
}
|
|
127
|
+
// Folders hidden on the SekaiPop entry: its `hiddenFolders` setting, one per line.
|
|
128
|
+
export function sekaipopHiddenFolders(path = sekaipopStatePath()) {
|
|
129
|
+
try {
|
|
130
|
+
const state = JSON.parse(readFileSync(path, "utf8"));
|
|
131
|
+
const text = state?.settings?.hiddenFolders;
|
|
132
|
+
if (typeof text !== "string")
|
|
133
|
+
return [];
|
|
134
|
+
return text.split("\n").map((line) => line.trim()).filter((line) => line !== "");
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
return [];
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// A folder setup didn't write (no cli.json) is someone's own plugin: it's
|
|
141
|
+
// moved aside into Topside's state folder, never deleted. One setup wrote
|
|
142
|
+
// is replaced; its `core` is dropped first, since an old hand-made one was
|
|
143
|
+
// a link into the repo and copying through it would write there.
|
|
144
|
+
function clearTarget(target, backupDir, now) {
|
|
145
|
+
if (!existsSync(target))
|
|
146
|
+
return ok("");
|
|
147
|
+
try {
|
|
148
|
+
if (!existsSync(join(target, "cli.json"))) {
|
|
149
|
+
mkdirSync(backupDir, { recursive: true });
|
|
150
|
+
const backup = join(backupDir, `sekaipop-plugin-${now.toISOString().replace(/[:.]/g, "-")}`);
|
|
151
|
+
renameSync(target, backup);
|
|
152
|
+
return ok(backup);
|
|
153
|
+
}
|
|
154
|
+
const core = join(target, "core");
|
|
155
|
+
if (existsSync(core) || lstatSync(core, { throwIfNoEntry: false }))
|
|
156
|
+
rmSync(core, { recursive: true, force: true });
|
|
157
|
+
return ok("");
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
return err(`can't clear ${target}: ${error instanceof Error ? error.message : String(error)}`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
// SekaiPop's form only offers the choices plugin.json lists, so the copy
|
|
164
|
+
// setup installs lists your usable theme files after the built-in ones.
|
|
165
|
+
export function withUserThemes(manifest, themes) {
|
|
166
|
+
if (themes.length === 0)
|
|
167
|
+
return ok(manifest);
|
|
168
|
+
let data;
|
|
169
|
+
try {
|
|
170
|
+
data = JSON.parse(manifest);
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
return err(`plugin.json isn't JSON: ${error.message}`);
|
|
174
|
+
}
|
|
175
|
+
const choices = data.settingsInfo?.theme?.choices;
|
|
176
|
+
if (!choices)
|
|
177
|
+
return err("plugin.json has no theme choices");
|
|
178
|
+
const known = new Set(choices.map((c) => c.value));
|
|
179
|
+
for (const t of themes)
|
|
180
|
+
if (!known.has(t.id))
|
|
181
|
+
choices.push({ value: t.id, label: t.title });
|
|
182
|
+
return ok(`${JSON.stringify(data, null, 2)}\n`);
|
|
183
|
+
}
|
|
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) {
|
|
185
|
+
const target = join(pluginsDir, PLUGIN_ID);
|
|
186
|
+
const upgrade = existsSync(join(target, "cli.json"));
|
|
187
|
+
const cleared = clearTarget(target, backupDir, host.now());
|
|
188
|
+
if (!cleared.ok)
|
|
189
|
+
return cleared;
|
|
190
|
+
const installed = installPlugin(pluginsDir, cli, sekaipopPluginSourceDir());
|
|
191
|
+
if (!installed.ok)
|
|
192
|
+
return installed;
|
|
193
|
+
// Service.qml watches it for theme files, so it has to exist.
|
|
194
|
+
mkdirSync(themesDir, { recursive: true });
|
|
195
|
+
const manifestPath = join(installed.value, "plugin.json");
|
|
196
|
+
const manifest = withUserThemes(readFileSync(manifestPath, "utf8"), themes);
|
|
197
|
+
if (!manifest.ok)
|
|
198
|
+
return manifest;
|
|
199
|
+
writeFileSync(manifestPath, manifest.value);
|
|
200
|
+
host.reload();
|
|
201
|
+
const bar = host.barOn();
|
|
202
|
+
const imported = importedSettings(settings.dms, settings.sekaipop);
|
|
203
|
+
for (const [key, value] of imported)
|
|
204
|
+
host.set(key, value);
|
|
205
|
+
const lines = [`${upgrade ? "Updated" : "Installed"} the Topside entry for SekaiPop in ${installed.value}.`];
|
|
206
|
+
if (cleared.value !== "")
|
|
207
|
+
lines.push(`The plugin that was there is in ${cleared.value}.`);
|
|
208
|
+
if (themes.length > 0)
|
|
209
|
+
lines.push(`Your themes are in its Theme list: ${themes.map((t) => t.id).join(", ")}.`);
|
|
210
|
+
if (imported.length > 0)
|
|
211
|
+
lines.push(`Brought over your DMS settings: ${imported.map(([key]) => key).join(", ")}.`);
|
|
212
|
+
lines.push(bar.endsWith("on")
|
|
213
|
+
? "It's on the bar; Edit Desktop's BAR tab moves it."
|
|
214
|
+
: "Turn it on in Settings > Bar > Modules, or: qs -c sekaipop ipc call plugins bar topside on");
|
|
215
|
+
// A running SekaiPop keeps the QML it loaded, even across its own reload
|
|
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
|
+
}
|
|
230
|
+
lines.push("Its settings are in Settings > Desktop > Plugins > Topside.");
|
|
231
|
+
return ok(`${lines.join("\n")}\n`);
|
|
232
|
+
}
|
|
233
|
+
// SekaiPop as a shell Topside can live in (src/hosts/hosts.ts).
|
|
234
|
+
// Rewrites the installed plugin.json's Theme choices from the shipped one
|
|
235
|
+
// plus the usable theme files, so a file added, renamed or removed shows in
|
|
236
|
+
// SekaiPop's form; then asks a running SekaiPop to read it again. Nothing
|
|
237
|
+
// happens when Topside isn't installed there or the list is the same.
|
|
238
|
+
export function syncSekaipopThemes(host, pluginsDir = sekaipopPluginsDir(), themes = userThemes().filter((t) => t.usable)) {
|
|
239
|
+
const installed = join(pluginsDir, PLUGIN_ID, "plugin.json");
|
|
240
|
+
if (!existsSync(join(pluginsDir, PLUGIN_ID, "cli.json")) || !existsSync(installed))
|
|
241
|
+
return ok("");
|
|
242
|
+
const wanted = withUserThemes(readFileSync(join(sekaipopPluginSourceDir(), "plugin.json"), "utf8"), themes);
|
|
243
|
+
if (!wanted.ok)
|
|
244
|
+
return wanted;
|
|
245
|
+
const current = readFileSync(installed, "utf8");
|
|
246
|
+
const same = (() => {
|
|
247
|
+
try {
|
|
248
|
+
return JSON.stringify(JSON.parse(current)) === JSON.stringify(JSON.parse(wanted.value));
|
|
249
|
+
}
|
|
250
|
+
catch {
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
})();
|
|
254
|
+
if (same)
|
|
255
|
+
return ok("");
|
|
256
|
+
writeFileSync(installed, wanted.value);
|
|
257
|
+
if (host.running())
|
|
258
|
+
host.reload();
|
|
259
|
+
return ok(`SekaiPop's Theme list now has ${themes.length === 0 ? "only the built-in themes" : `yours too: ${themes.map((t) => t.id).join(", ")}`}.`);
|
|
260
|
+
}
|
|
261
|
+
export const sekaipopShell = {
|
|
262
|
+
name: "SekaiPop",
|
|
263
|
+
running: () => realSekaipopHost.running(),
|
|
264
|
+
setup: (options) => Promise.resolve(setupSekaipop(realSekaipopHost, undefined, undefined, undefined, undefined, undefined, undefined, options.restart)),
|
|
265
|
+
hiddenFolders: () => sekaipopHiddenFolders(),
|
|
266
|
+
syncThemes: () => syncSekaipopThemes(realSekaipopHost),
|
|
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
|
+
}
|
|
@@ -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,33 @@
|
|
|
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 in node (shell/core's, or a host's own such
|
|
6
|
+
// as shell/sekaipop-plugin/place.js): plain functions and
|
|
7
|
+
// vars after a `.pragma library` line, with `.import "x.js" as X` lines for
|
|
8
|
+
// the libraries it uses. Each runs once, in a context of its own, so the CLI
|
|
9
|
+
// and the tests read the same code the QML draws with.
|
|
10
|
+
const loaded = new Map();
|
|
11
|
+
const importLine = /^\.import\s+"([^"]+\.js)"\s+as\s+(\w+)\s*;?\s*$/;
|
|
12
|
+
export function loadQmlLib(file) {
|
|
13
|
+
const cached = loaded.get(file);
|
|
14
|
+
if (cached)
|
|
15
|
+
return cached;
|
|
16
|
+
const context = {};
|
|
17
|
+
const lines = readFileSync(file, "utf8").split("\n").map((line) => {
|
|
18
|
+
if (line.trim() === ".pragma library")
|
|
19
|
+
return "";
|
|
20
|
+
const found = importLine.exec(line.trim());
|
|
21
|
+
if (!found)
|
|
22
|
+
return line;
|
|
23
|
+
context[found[2] ?? ""] = loadQmlLib(join(dirname(file), found[1] ?? ""));
|
|
24
|
+
return "";
|
|
25
|
+
});
|
|
26
|
+
runInNewContext(lines.join("\n"), context, { filename: file });
|
|
27
|
+
loaded.set(file, context);
|
|
28
|
+
return context;
|
|
29
|
+
}
|
|
30
|
+
// A library in shell/core by its file name.
|
|
31
|
+
export function coreLib(name) {
|
|
32
|
+
return loadQmlLib(fileURLToPath(new URL(`../../shell/core/${name}`, import.meta.url)));
|
|
33
|
+
}
|
|
@@ -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
|
+
}
|