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,256 @@
1
+ // pi and omp run tools without asking. With the gate on, Topside asks first
2
+ // for the few shell commands that are hard to take back (VIA-PARITY §22).
3
+ // How long the hook waits for an answer. omp cuts a tool_call handler off
4
+ // after 30 s, so the answer has to come sooner; no answer is a deny.
5
+ export const gateTimeoutMs = 25_000;
6
+ export const gateTimeoutMessage = "Blocked: nobody answered in Topside within 25 seconds";
7
+ const shells = new Set(["sh", "bash", "zsh", "dash", "ksh", "fish"]);
8
+ const downloaders = new Set(["curl", "wget"]);
9
+ // Why `command` is one to ask about first, or null when it can just run.
10
+ // The command is split the way a shell would, so the gate looks inside
11
+ // `sh -c '…'`, `$(…)`, `xargs`, `find -exec` and the like, and a risky word
12
+ // inside a quoted message doesn't count.
13
+ export function riskyCommandReason(command) {
14
+ return riskyIn(command, 0);
15
+ }
16
+ function riskyIn(script, depth) {
17
+ // Scripts inside scripts inside scripts: stop before it gets silly.
18
+ if (depth >= 5)
19
+ return null;
20
+ const lexed = lex(script);
21
+ let previous = "";
22
+ for (const command of lexed.commands) {
23
+ const words = unwrapped(command.words);
24
+ const name = baseName(words[0] ?? "");
25
+ if (command.piped && shells.has(name) && downloaders.has(previous))
26
+ return "runs a downloaded script";
27
+ const reason = riskyWords(words, depth);
28
+ if (reason !== null)
29
+ return reason;
30
+ previous = name;
31
+ }
32
+ for (const inner of lexed.substitutions) {
33
+ const reason = riskyIn(inner, depth + 1);
34
+ if (reason !== null)
35
+ return reason;
36
+ }
37
+ return null;
38
+ }
39
+ function riskyWords(words, depth) {
40
+ if (words.length === 0)
41
+ return null;
42
+ const name = baseName(words[0] ?? "");
43
+ const rest = words.slice(1);
44
+ const short = (letter) => rest.some((word) => word.startsWith("-") && !word.startsWith("--") && word.includes(letter));
45
+ switch (name) {
46
+ case "sudo":
47
+ case "doas":
48
+ return "runs as root";
49
+ case "rm": {
50
+ const recursive = short("r") || short("R") || rest.includes("--recursive");
51
+ return recursive && (short("f") || rest.includes("--force")) ? "deletes files for good" : null;
52
+ }
53
+ case "git":
54
+ if (rest.includes("push") && (short("f") || rest.some((word) => word.startsWith("--force"))))
55
+ return "overwrites the remote branch";
56
+ return rest.includes("reset") && rest.includes("--hard") ? "throws away local changes" : null;
57
+ case "find":
58
+ return findReason(rest, depth);
59
+ case "eval":
60
+ return riskyIn(rest.join(" "), depth + 1);
61
+ default: {
62
+ if (!shells.has(name))
63
+ return null;
64
+ const script = inlineScript(rest);
65
+ return script === null ? null : riskyIn(script, depth + 1);
66
+ }
67
+ }
68
+ }
69
+ // `find … -delete`, or what `-exec` and its kin run on each file.
70
+ function findReason(words, depth) {
71
+ if (words.includes("-delete"))
72
+ return "deletes files for good";
73
+ for (let i = 0; i < words.length; i++) {
74
+ if (!["-exec", "-execdir", "-ok", "-okdir"].includes(words[i] ?? ""))
75
+ continue;
76
+ const run = [];
77
+ for (let j = i + 1; j < words.length && words[j] !== ";" && words[j] !== "+"; j++)
78
+ run.push(words[j] ?? "");
79
+ const reason = riskyWords(unwrapped(run), depth);
80
+ if (reason !== null)
81
+ return reason;
82
+ }
83
+ return null;
84
+ }
85
+ // The script in `sh -c '<script>'` (also `-lc`, `-ec`); null when the shell runs a file.
86
+ function inlineScript(words) {
87
+ for (let i = 0; i < words.length; i++) {
88
+ const word = words[i] ?? "";
89
+ if (!word.startsWith("-"))
90
+ return null;
91
+ if (!word.startsWith("--") && word.includes("c"))
92
+ return words[i + 1] ?? null;
93
+ }
94
+ return null;
95
+ }
96
+ // Commands that run another command: their flags that take a value, and how
97
+ // many words come before the command they run.
98
+ const wrappers = {
99
+ env: { valueFlags: new Set(["-u", "-C", "-P", "-S"]), operands: 0 },
100
+ nohup: { valueFlags: new Set(), operands: 0 },
101
+ command: { valueFlags: new Set(), operands: 0 },
102
+ builtin: { valueFlags: new Set(), operands: 0 },
103
+ exec: { valueFlags: new Set(["-a"]), operands: 0 },
104
+ time: { valueFlags: new Set(), operands: 0 },
105
+ setsid: { valueFlags: new Set(), operands: 0 },
106
+ stdbuf: { valueFlags: new Set(), operands: 0 },
107
+ nice: { valueFlags: new Set(["-n"]), operands: 0 },
108
+ ionice: { valueFlags: new Set(["-c", "-n", "-p"]), operands: 0 },
109
+ timeout: { valueFlags: new Set(["-s", "-k", "--signal", "--kill-after"]), operands: 1 },
110
+ xargs: { valueFlags: new Set(["-I", "-n", "-P", "-L", "-d", "-E", "-s", "-J", "-R"]), operands: 0 },
111
+ };
112
+ const shellKeywords = new Set(["then", "do", "else", "elif", "if", "while", "until", "!", "{"]);
113
+ // `words` without what stands in front of the real command: `VAR=value`
114
+ // settings, shell keywords, and wrappers such as env, nohup, xargs.
115
+ function unwrapped(input) {
116
+ let words = input;
117
+ while (words.length > 0) {
118
+ const first = words[0] ?? "";
119
+ if (isAssignment(first) || shellKeywords.has(first)) {
120
+ words = words.slice(1);
121
+ continue;
122
+ }
123
+ const wrapper = wrappers[baseName(first)];
124
+ if (wrapper === undefined)
125
+ break;
126
+ words = words.slice(1);
127
+ while (words.length > 0 && (words[0] ?? "").startsWith("-"))
128
+ words = words.slice(wrapper.valueFlags.has(words[0] ?? "") ? 2 : 1);
129
+ words = words.slice(wrapper.operands);
130
+ }
131
+ return words;
132
+ }
133
+ function isAssignment(word) {
134
+ const equals = word.indexOf("=");
135
+ return equals > 0 && /^[\p{L}\p{N}_]+$/u.test(word.slice(0, equals));
136
+ }
137
+ function baseName(path) {
138
+ return path.split("/").filter((part) => part !== "").at(-1) ?? path;
139
+ }
140
+ // Splits a script into its simple commands, close enough to how a shell does
141
+ // it for the gate: quotes keep a word together; `;`, `&`, `|`, newlines and
142
+ // parentheses end a command; what `$(…)` or backticks would run is set aside
143
+ // to be read as a script of its own.
144
+ export function lex(script) {
145
+ const commands = [{ words: [], piped: false }];
146
+ const substitutions = [];
147
+ const chars = [...script];
148
+ let word = "";
149
+ let inWord = false;
150
+ let quote = null;
151
+ const current = () => commands[commands.length - 1];
152
+ const endWord = () => {
153
+ if (inWord)
154
+ current().words.push(word);
155
+ word = "";
156
+ inWord = false;
157
+ };
158
+ const endCommand = (piped) => {
159
+ endWord();
160
+ // A second "|" makes it "||": the next command doesn't read this one's output.
161
+ if (current().words.length === 0)
162
+ current().piped = piped && !current().piped;
163
+ else
164
+ commands.push({ words: [], piped });
165
+ };
166
+ // Sets aside the text up to the matching `close`; returns the index after it.
167
+ const substitution = (from, close) => {
168
+ let depth = 1;
169
+ let index = from;
170
+ while (index < chars.length) {
171
+ if (chars[index] === "(" && close === ")")
172
+ depth++;
173
+ if (chars[index] === close)
174
+ depth--;
175
+ if (depth === 0)
176
+ break;
177
+ index++;
178
+ }
179
+ substitutions.push(chars.slice(from, Math.min(index, chars.length)).join(""));
180
+ inWord = true;
181
+ return index + 1;
182
+ };
183
+ let index = 0;
184
+ while (index < chars.length) {
185
+ const char = chars[index] ?? "";
186
+ index++;
187
+ if (quote === "'") {
188
+ if (char === "'")
189
+ quote = null;
190
+ else
191
+ word += char;
192
+ }
193
+ else if (char === "\\" && chars[index] === "\n") {
194
+ // A line continuation: the shell drops both and joins the lines.
195
+ index++;
196
+ }
197
+ else if (char === "\\" && index < chars.length) {
198
+ word += chars[index] ?? "";
199
+ inWord = true;
200
+ index++;
201
+ }
202
+ else if (char === "$" && chars[index] === "(") {
203
+ index = substitution(index + 1, ")");
204
+ }
205
+ else if (char === "`") {
206
+ index = substitution(index, "`");
207
+ }
208
+ else if (quote !== null) {
209
+ if (char === quote)
210
+ quote = null;
211
+ else
212
+ word += char;
213
+ }
214
+ else if (char === "'" || char === '"') {
215
+ quote = char;
216
+ inWord = true;
217
+ }
218
+ else if (char === " " || char === "\t") {
219
+ endWord();
220
+ }
221
+ else if (char === "|") {
222
+ endCommand(true);
223
+ }
224
+ else if (char === ";" || char === "&" || char === "\n" || char === "(" || char === ")") {
225
+ endCommand(false);
226
+ }
227
+ else {
228
+ word += char;
229
+ inWord = true;
230
+ }
231
+ }
232
+ endWord();
233
+ return { commands, substitutions };
234
+ }
235
+ // A folder hides every session in it or below it (shell/core/hiding.js).
236
+ export function inHiddenFolder(cwd, folders) {
237
+ return folders.some((folder) => cwd === folder || cwd.startsWith(`${folder.replace(/\/$/, "")}/`));
238
+ }
239
+ // The command to ask about before this tool call runs, or null when it isn't
240
+ // the gate's business: the gate is off, the session's folder is hidden, the
241
+ // tool has no command, or the command isn't risky.
242
+ export function gatedCommand(toolInput, cwd, on, hiddenFolders) {
243
+ if (!on || inHiddenFolder(cwd, hiddenFolders))
244
+ return null;
245
+ if (typeof toolInput !== "object" || toolInput === null)
246
+ return null;
247
+ const command = toolInput.command;
248
+ if (typeof command !== "string")
249
+ return null;
250
+ return riskyCommandReason(command) === null ? null : command;
251
+ }
252
+ // The hook's answer in Claude Code's decision shape, which the extension reads.
253
+ export function gateDecision(allowed, message) {
254
+ const decision = allowed ? { behavior: "allow" } : { behavior: "deny", message };
255
+ return `${JSON.stringify({ hookSpecificOutput: { hookEventName: "PreToolUse", decision } })}\n`;
256
+ }