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.
- package/LICENSE +21 -0
- package/README.md +213 -2
- package/contrib/aur/PKGBUILD +35 -0
- package/contrib/aur/topside-arch.install +25 -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 +563 -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 +173 -0
- package/dist/daemon/store.js +176 -0
- package/dist/dms/setup.js +126 -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 +210 -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 +32 -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 +296 -0
- package/shell/core/BoardList.qml +433 -0
- package/shell/core/BoardNotice.qml +187 -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 +95 -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 +220 -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 +588 -0
- package/shell/core/TicketList.qml +639 -0
- package/shell/core/TicketNotice.qml +198 -0
- package/shell/core/TopsideClient.qml +198 -0
- package/shell/core/UsageLine.qml +106 -0
- package/shell/core/agents.js +79 -0
- package/shell/core/board.js +138 -0
- package/shell/core/hiding.js +29 -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 +131 -0
- package/shell/dms-plugin/TopsideSettings.qml +696 -0
- package/shell/dms-plugin/TopsideWidget.qml +572 -0
- package/shell/dms-plugin/plugin.json +14 -0
- package/shell/pill.qml +279 -0
- package/shell/sekaipop-plugin/Bar.qml +151 -0
- package/shell/sekaipop-plugin/Card.qml +291 -0
- package/shell/sekaipop-plugin/Floating.qml +83 -0
- package/shell/sekaipop-plugin/ListWindow.qml +156 -0
- package/shell/sekaipop-plugin/Popup.qml +70 -0
- package/shell/sekaipop-plugin/Service.qml +414 -0
- package/shell/sekaipop-plugin/ShellLook.qml +43 -0
- package/shell/sekaipop-plugin/StyledCard.qml +179 -0
- package/shell/sekaipop-plugin/plugin.json +109 -0
package/dist/cli/main.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { argv, exit, stderr, stdout } from "node:process";
|
|
3
|
+
import { daemonCommand, decideCommand, hookCommand, jumpCommand, frontCommand, gateCommand, hooksCommand, integrationsCommand, loginCommand, statuslineCommand, usageCommand, pillCommand, themeCommand, setupCommand, statusCommand, } from "./commands.js";
|
|
4
|
+
import { packageInfo } from "../shared/package.js";
|
|
5
|
+
import { legacyMoves, moveLegacyFiles } from "../shared/paths.js";
|
|
6
|
+
const usage = `Usage: topside <command>
|
|
7
|
+
|
|
8
|
+
Commands:
|
|
9
|
+
daemon Run the Topside daemon in the foreground
|
|
10
|
+
status List live sessions and approvals waiting for you
|
|
11
|
+
approve <id> Approve a pending tool call
|
|
12
|
+
deny <id> Deny a pending tool call
|
|
13
|
+
jump <id> Focus the terminal a session runs in (Hyprland)
|
|
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
|
|
16
|
+
pill Start the standalone pill (Quickshell)
|
|
17
|
+
pill position [<where>] Show or set where the pill sits, e.g. bottom-right
|
|
18
|
+
pill theme [<name>] Show or set the pill's theme, e.g. tokyoNight or one of yours
|
|
19
|
+
theme list [--json] List the built-in themes and yours (~/.config/topside/themes)
|
|
20
|
+
theme check [<id>|<file>] Say what's wrong with a theme file of yours
|
|
21
|
+
theme sync Put your theme files in the shells' theme lists (SekaiPop runs it itself)
|
|
22
|
+
pill mode [<mode>] Show or set light, dark or system
|
|
23
|
+
pill text-size [<n>] Show or set the text size, 10 to 14
|
|
24
|
+
hooks install Add Topside's hooks to ~/.claude/settings.json
|
|
25
|
+
hooks uninstall Remove Topside's hooks from ~/.claude/settings.json
|
|
26
|
+
hooks install codex Add them to ~/.codex/hooks.json (then run /hooks in Codex)
|
|
27
|
+
hooks uninstall codex Remove them from ~/.codex/hooks.json
|
|
28
|
+
hooks install pi|omp Write Topside's extension into ~/.pi or ~/.omp
|
|
29
|
+
hooks uninstall pi|omp Remove that extension
|
|
30
|
+
usage install Show plan usage in the island: wraps Claude Code's status line
|
|
31
|
+
usage uninstall Give Claude Code its own status line back
|
|
32
|
+
integrations Show what's installed, as JSON (the DMS settings page reads it)
|
|
33
|
+
integrations adopt Point installed hooks and the usage bridge at this copy
|
|
34
|
+
login on|off Start the daemon at login, or not
|
|
35
|
+
gate [on|off] Ask before risky pi and omp shell commands (off by default)
|
|
36
|
+
hook <agent> Hook entry point: claude, codex, or pi/omp (via the extension)
|
|
37
|
+
statusline Status line entry point, called by Claude Code
|
|
38
|
+
version Print the installed version
|
|
39
|
+
`;
|
|
40
|
+
export async function run(args, version) {
|
|
41
|
+
const [command, arg] = args;
|
|
42
|
+
switch (command) {
|
|
43
|
+
case undefined:
|
|
44
|
+
case "help":
|
|
45
|
+
case "--help":
|
|
46
|
+
return { code: 0, out: usage };
|
|
47
|
+
case "version":
|
|
48
|
+
case "--version":
|
|
49
|
+
return { code: 0, out: `${version}\n` };
|
|
50
|
+
case "daemon":
|
|
51
|
+
return daemonCommand();
|
|
52
|
+
case "status":
|
|
53
|
+
return statusCommand();
|
|
54
|
+
case "approve":
|
|
55
|
+
return decideCommand("allow", arg);
|
|
56
|
+
case "deny":
|
|
57
|
+
return decideCommand("deny", arg);
|
|
58
|
+
case "jump":
|
|
59
|
+
return jumpCommand(arg);
|
|
60
|
+
case "front":
|
|
61
|
+
return frontCommand(arg);
|
|
62
|
+
case "setup":
|
|
63
|
+
return setupCommand();
|
|
64
|
+
case "pill":
|
|
65
|
+
return pillCommand(args.slice(1));
|
|
66
|
+
case "theme":
|
|
67
|
+
return themeCommand(args.slice(1));
|
|
68
|
+
case "hooks":
|
|
69
|
+
return hooksCommand(arg, args[2]);
|
|
70
|
+
case "usage":
|
|
71
|
+
return usageCommand(arg);
|
|
72
|
+
case "integrations":
|
|
73
|
+
return integrationsCommand(arg, version);
|
|
74
|
+
case "gate":
|
|
75
|
+
return gateCommand(arg);
|
|
76
|
+
case "login":
|
|
77
|
+
return loginCommand(arg);
|
|
78
|
+
case "statusline":
|
|
79
|
+
return statuslineCommand(args.slice(1));
|
|
80
|
+
case "hook":
|
|
81
|
+
return hookCommand(arg);
|
|
82
|
+
default:
|
|
83
|
+
return { code: 1, out: `Unknown command: ${command}\n\n${usage}` };
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (import.meta.main) {
|
|
87
|
+
// The hook runs on every tool call and stays quick; everything else first
|
|
88
|
+
// carries over data from before the rename. Kept out of run() so tests
|
|
89
|
+
// never touch the real folders.
|
|
90
|
+
if (argv[2] !== "hook" && argv[2] !== "statusline") {
|
|
91
|
+
const moved = moveLegacyFiles(legacyMoves());
|
|
92
|
+
if (!moved.ok) {
|
|
93
|
+
stderr.write(`${moved.error}\n`);
|
|
94
|
+
exit(1);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const result = await run(argv.slice(2), packageInfo().version);
|
|
98
|
+
(result.code === 0 ? stdout : stderr).write(result.out);
|
|
99
|
+
exit(result.code);
|
|
100
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { patchFiles, patchLines } from "../adapters/codex/patch.js";
|
|
2
|
+
// How much of a change the island shows. The terminal has the full diff.
|
|
3
|
+
export const previewLimit = 12;
|
|
4
|
+
function text(input, key) {
|
|
5
|
+
const value = input[key];
|
|
6
|
+
return typeof value === "string" ? value : "";
|
|
7
|
+
}
|
|
8
|
+
const lines = (value) => (value === "" ? [] : value.replace(/\n$/, "").split("\n"));
|
|
9
|
+
// Shared leading and trailing lines become context; the middle is removed
|
|
10
|
+
// then added. Good enough for the small replacements Edit makes.
|
|
11
|
+
export function diffLines(before, after) {
|
|
12
|
+
const a = lines(before);
|
|
13
|
+
const b = lines(after);
|
|
14
|
+
let start = 0;
|
|
15
|
+
while (start < a.length && start < b.length && a[start] === b[start])
|
|
16
|
+
start++;
|
|
17
|
+
let end = 0;
|
|
18
|
+
while (end < a.length - start && end < b.length - start && a[a.length - 1 - end] === b[b.length - 1 - end])
|
|
19
|
+
end++;
|
|
20
|
+
return [
|
|
21
|
+
...a.slice(0, start).map((t) => ({ kind: "context", text: t })),
|
|
22
|
+
...a.slice(start, a.length - end).map((t) => ({ kind: "remove", text: t })),
|
|
23
|
+
...b.slice(start, b.length - end).map((t) => ({ kind: "add", text: t })),
|
|
24
|
+
...a.slice(a.length - end).map((t) => ({ kind: "context", text: t })),
|
|
25
|
+
];
|
|
26
|
+
}
|
|
27
|
+
// What the tool is about to change, as lines for the approval row. Empty
|
|
28
|
+
// when there's nothing worth more than the one-line summary.
|
|
29
|
+
export function previewTool(toolName, toolInput) {
|
|
30
|
+
if (typeof toolInput !== "object" || toolInput === null)
|
|
31
|
+
return [];
|
|
32
|
+
const input = toolInput;
|
|
33
|
+
let all = [];
|
|
34
|
+
switch (toolName) {
|
|
35
|
+
case "Edit":
|
|
36
|
+
all = diffLines(text(input, "old_string"), text(input, "new_string"));
|
|
37
|
+
break;
|
|
38
|
+
case "MultiEdit": {
|
|
39
|
+
const edits = Array.isArray(input.edits) ? input.edits : [];
|
|
40
|
+
all = edits.flatMap((edit) => diffLines(text(edit, "old_string"), text(edit, "new_string")));
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
case "Write":
|
|
44
|
+
all = lines(text(input, "content")).map((t) => ({ kind: "add", text: t }));
|
|
45
|
+
break;
|
|
46
|
+
case "apply_patch":
|
|
47
|
+
all = patchLines(text(input, "command"));
|
|
48
|
+
break;
|
|
49
|
+
case "Bash": {
|
|
50
|
+
// One-line commands already fit the summary.
|
|
51
|
+
const command = lines(text(input, "command"));
|
|
52
|
+
all = command.length > 1 ? command.map((t) => ({ kind: "context", text: t })) : [];
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (all.length <= previewLimit)
|
|
57
|
+
return all;
|
|
58
|
+
return [...all.slice(0, previewLimit), { kind: "more", text: `${all.length - previewLimit} more lines` }];
|
|
59
|
+
}
|
|
60
|
+
// The file an edit or write changes, as its last two path parts, for the
|
|
61
|
+
// card's diff header. "" when the tool names no file.
|
|
62
|
+
// A Codex patch names its files inside; one file counts, several don't.
|
|
63
|
+
export function previewFile(toolInput, toolName = "") {
|
|
64
|
+
if (typeof toolInput !== "object" || toolInput === null)
|
|
65
|
+
return "";
|
|
66
|
+
const input = toolInput;
|
|
67
|
+
const patched = toolName === "apply_patch" ? patchFiles(text(input, "command")) : [];
|
|
68
|
+
const path = patched.length === 1 ? (patched[0]?.path ?? "") : text(input, "file_path");
|
|
69
|
+
return path.split("/").filter((part) => part !== "").slice(-2).join("/");
|
|
70
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { readdirSync, readFileSync, readlinkSync } from "node:fs";
|
|
2
|
+
import { basename } from "node:path";
|
|
3
|
+
import { findSessionRecord, readEnviron, readSessionRecord } from "../adapters/claude/attach.js";
|
|
4
|
+
import { claudeArgs, readCmdline } from "../adapters/claude/one-shot.js";
|
|
5
|
+
import { isCodexBinary, isCodexOneShot } from "../adapters/codex/codex.js";
|
|
6
|
+
import { isAgentProcess, isExtensionAgent } from "../adapters/pi/extension.js";
|
|
7
|
+
import { ancestry } from "../shared/ancestry.js";
|
|
8
|
+
import { claudeConfigDir } from "../shared/paths.js";
|
|
9
|
+
import { terminalHint } from "../shared/terminal.js";
|
|
10
|
+
// Arguments that mark a Claude Code helper or a one-shot run, never an
|
|
11
|
+
// interactive session (VIA-PARITY §15).
|
|
12
|
+
const helperArgs = new Set(["attach", "daemon", "bg-pty-host", "--bg-pty-host", "--bg-spare", "--chrome-native-host", "mcp", "-p", "--print"]);
|
|
13
|
+
// An interactive Claude Code session on a terminal.
|
|
14
|
+
export function isInteractiveClaude(info) {
|
|
15
|
+
const named = info.exe.includes("/claude/versions/") || basename(info.exe) === "claude" || basename(info.argv[0] ?? "") === "claude";
|
|
16
|
+
return named && info.tty !== 0 && !info.argv.slice(1).some((arg) => helperArgs.has(arg) || arg.startsWith("--print="));
|
|
17
|
+
}
|
|
18
|
+
// An interactive Codex session on a terminal: the native binary (not the npm
|
|
19
|
+
// launcher under a /.bin/ folder), not a one-shot run, and not a helper that
|
|
20
|
+
// a codex process started. `ancestors` are the argv of its ancestors.
|
|
21
|
+
export function isInteractiveCodex(info, ancestors) {
|
|
22
|
+
return (basename(info.exe) === "codex" &&
|
|
23
|
+
!info.exe.includes("/.bin/") &&
|
|
24
|
+
info.tty !== 0 &&
|
|
25
|
+
!isCodexOneShot(info.argv) &&
|
|
26
|
+
!ancestors.some(isCodexBinary));
|
|
27
|
+
}
|
|
28
|
+
// An interactive pi or omp session on a terminal, not a worker that another
|
|
29
|
+
// process of the same agent started. `ancestors` are the argv of its ancestors.
|
|
30
|
+
export function isInteractiveExtensionAgent(agent, info, ancestors) {
|
|
31
|
+
return isAgentProcess(agent, info.argv) && info.tty !== 0 && !ancestors.some((argv) => isAgentProcess(agent, argv));
|
|
32
|
+
}
|
|
33
|
+
// The ID a discovered session goes by: Claude Code's record when it matches
|
|
34
|
+
// the process, else --session-id from its command line, else a placeholder
|
|
35
|
+
// a later hook event replaces.
|
|
36
|
+
export function discoveredId(pid, argv, record) {
|
|
37
|
+
if (record !== null && record.sessionId !== "")
|
|
38
|
+
return record.sessionId;
|
|
39
|
+
const at = argv.indexOf("--session-id");
|
|
40
|
+
const fromArgs = at >= 0 ? (argv[at + 1] ?? "") : (argv.find((arg) => arg.startsWith("--session-id="))?.slice("--session-id=".length) ?? "");
|
|
41
|
+
return fromArgs !== "" ? fromArgs : `pid-${pid}`;
|
|
42
|
+
}
|
|
43
|
+
// The agent's own process in a hook's ancestry (nearest first): the first
|
|
44
|
+
// Claude Code process, which for an attached background session is the
|
|
45
|
+
// `claude attach` client. For Codex, the native codex binary; for pi and
|
|
46
|
+
// omp, their own process (the extension spawns the hook directly). 0 when there's none.
|
|
47
|
+
export function agentPidOf(pids, cmdline, agent = "claude") {
|
|
48
|
+
const isAgent = agent === "codex"
|
|
49
|
+
? (pid) => isCodexBinary(cmdline(pid))
|
|
50
|
+
: isExtensionAgent(agent)
|
|
51
|
+
? (pid) => isAgentProcess(agent, cmdline(pid))
|
|
52
|
+
: (pid) => claudeArgs([cmdline(pid)]) !== null;
|
|
53
|
+
return pids.find(isAgent) ?? 0;
|
|
54
|
+
}
|
|
55
|
+
function readProc(pid, file) {
|
|
56
|
+
try {
|
|
57
|
+
return readFileSync(`/proc/${pid}/${file}`, "utf8");
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return "";
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export const realProcessHost = {
|
|
64
|
+
alive(pid) {
|
|
65
|
+
try {
|
|
66
|
+
process.kill(pid, 0);
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
// EPERM: it exists, it's just someone else's.
|
|
71
|
+
return error.code === "EPERM";
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
cmdline: readCmdline,
|
|
75
|
+
record(pid) {
|
|
76
|
+
const record = findSessionRecord([pid], readSessionRecord(claudeConfigDir()));
|
|
77
|
+
return record !== null && record.pid === pid ? record : null;
|
|
78
|
+
},
|
|
79
|
+
list() {
|
|
80
|
+
try {
|
|
81
|
+
return readdirSync("/proc").filter((name) => /^\d+$/.test(name)).map(Number);
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return [];
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
inspect(pid) {
|
|
88
|
+
const stat = readProc(pid, "stat");
|
|
89
|
+
if (stat === "")
|
|
90
|
+
return null;
|
|
91
|
+
// Fields after the ")" that closes the command name: state, ppid, pgrp, session, tty_nr.
|
|
92
|
+
const tty = Number(stat.slice(stat.lastIndexOf(")") + 2).split(" ")[4] ?? 0);
|
|
93
|
+
let exe = "";
|
|
94
|
+
let cwd = "";
|
|
95
|
+
try {
|
|
96
|
+
exe = readlinkSync(`/proc/${pid}/exe`);
|
|
97
|
+
cwd = readlinkSync(`/proc/${pid}/cwd`);
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
// Someone else's process, or gone: exe stays "".
|
|
101
|
+
}
|
|
102
|
+
return { exe, argv: readCmdline(pid), tty: Number.isFinite(tty) ? tty : 0, cwd, terminal: terminalHint(readEnviron(pid)) };
|
|
103
|
+
},
|
|
104
|
+
ancestry,
|
|
105
|
+
};
|