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/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nguyen Duc Ban
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,214 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Topside for Linux (`topside`)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Topside for Linux, Arch first, and the sibling of Topside on the Mac. A small island on your screen shows what your Claude Code sessions are doing, lets you approve their tool calls, and jumps you to the right terminal.
|
|
4
|
+
|
|
5
|
+
Formerly Vibe Island on Arch (`via`); see [Upgrading from via](#upgrading-from-via). The package is `topside-arch` because it has only been tried on Arch.
|
|
6
|
+
|
|
7
|
+
> Early days: the daemon, the Claude Code hooks, the standalone pill, the DMS bar widget, the SekaiPop bar entry and jump-to-terminal work. See [docs/PRD.md](./docs/PRD.md).
|
|
8
|
+
|
|
9
|
+
## How it fits together
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
Claude Code hooks ──► Topside daemon (Node, systemd --user, SQLite)
|
|
13
|
+
│ JSON over a Unix socket
|
|
14
|
+
│ (topside status / approve / deny also work)
|
|
15
|
+
┌───────────────────┼───────────────────┐
|
|
16
|
+
SekaiPop running? DMS running? neither
|
|
17
|
+
▼ ▼ ▼
|
|
18
|
+
SekaiPop bar entry DMS bar widget Quickshell pill
|
|
19
|
+
(Edit Desktop moves) (any bar zone) (3x3 position grid)
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Each shell is a **host**: a thin layer over the same shared QML. [docs/notes/hosts.md](./docs/notes/hosts.md) compares them and lists what adding another shell takes.
|
|
23
|
+
|
|
24
|
+
## Install
|
|
25
|
+
|
|
26
|
+
Topside comes from npm. npm doesn't install system packages or services, so those are a few lines by hand:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
sudo pacman -S nodejs npm quickshell # Node >= 26
|
|
30
|
+
sudo npm install -g topside-arch
|
|
31
|
+
mkdir -p ~/.config/systemd/user
|
|
32
|
+
cp "$(npm root -g)/topside-arch/contrib/systemd/topside.service" ~/.config/systemd/user/
|
|
33
|
+
systemctl --user enable --now topside # the daemon, now and at login
|
|
34
|
+
topside hooks install # Claude Code; Usage below covers Codex, pi, omp
|
|
35
|
+
topside setup # the SekaiPop or DMS bar entry; else `topside pill`
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
The unit runs `/usr/bin/topside daemon`. If `topside` lives somewhere else (`which topside`), fix `ExecStart` in the copied file. To upgrade, run `sudo npm install -g topside-arch` again, then `systemctl --user restart topside` and `topside setup`. To remove it: `topside hooks uninstall` first, then `systemctl --user disable --now topside`, delete the unit, and `sudo npm uninstall -g topside-arch`.
|
|
39
|
+
|
|
40
|
+
The AUR package (`yay -S topside-arch`) waits for the AUR to take new accounts again; its `PKGBUILD` is ready in `contrib/aur/`.
|
|
41
|
+
|
|
42
|
+
What changed in each version: [docs/releases/](./docs/releases/). The page for people is https://topside.ducban.com/arch/.
|
|
43
|
+
|
|
44
|
+
## Upgrading from via
|
|
45
|
+
|
|
46
|
+
Topside used to be called Vibe Island on Arch, with the command `via`. The first `topside` command you run moves the database and the pill's config over from the old `via` folders. `via` still works as an alias for now. Then, once:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
systemctl --user disable --now via && rm ~/.config/systemd/user/via.service # stop the old daemon first
|
|
50
|
+
npm uninstall -g vibe-island-on-arch && npm install -g topside-arch
|
|
51
|
+
cp "$(npm root -g)/topside-arch/contrib/systemd/topside.service" ~/.config/systemd/user/
|
|
52
|
+
systemctl --user daemon-reload && systemctl --user enable --now topside
|
|
53
|
+
topside hooks install # swaps the old via entries for Topside's
|
|
54
|
+
topside setup # swaps the via widget for Topside's
|
|
55
|
+
systemctl --user restart dms
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Then add "Topside" to the bar in DMS Settings → Bar → Widgets, where "via" sat. The widget's settings start from their defaults.
|
|
59
|
+
|
|
60
|
+
## Usage
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
systemctl --user enable --now topside # start the daemon now and at login
|
|
64
|
+
topside hooks install # add Topside's hooks to ~/.claude/settings.json
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
`topside hooks install` only adds its own entries (tagged `# topside-managed`; it also replaces entries an older install tagged `# via-managed`), keeps every other hook, and writes a backup next to the file first. Running it twice changes nothing. `topside hooks uninstall` takes them out again.
|
|
68
|
+
|
|
69
|
+
Codex works too:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
topside hooks install codex # add Topside's hooks to ~/.codex/hooks.json
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Then run `/hooks` in Codex once and trust Topside's hooks. Codex skips a hook nobody trusted, and a reinstall from another path needs trusting again. Until then Topside still lists Codex sessions it finds running, marked "Not tracked: run /hooks in Codex", and the settings page says so too. Codex's plan usage comes along with its hooks: Topside reads it from Codex's session file, no extra install. Codex requests get Allow and Deny only, because Codex refuses the richer answers. `codex exec` and `codex review` runs don't get a row.
|
|
76
|
+
|
|
77
|
+
pi and omp have no hooks, so Topside writes a small extension into their extensions folder instead:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
topside hooks install pi # ~/.pi/agent/extensions/topside.ts
|
|
81
|
+
topside hooks install omp # ~/.omp/agent/extensions/topside.ts
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
New sessions report right away. A pi session that was already open picks it up with `/reload`; omp only loads extensions when it starts, so restart it. Until then Topside lists them as "Not tracked yet". They run tools without asking. To get an Allow/Deny card before the few commands that are hard to undo (`rm -rf`, `sudo`, `git push --force`, `git reset --hard`, `curl … | sh`), turn on "Ask before risky commands" in Settings or run `topside gate on`. Nobody answering within 25 seconds counts as Deny; with Topside stopped, commands just run. The header shows what the session has cost (`$0.42 · 182k tokens`) instead of plan usage. `topside hooks uninstall pi` removes the file, and Topside never touches a file there that it didn't write.
|
|
85
|
+
|
|
86
|
+
To see your plan usage (`5h 39% 3h41m │ 7d 61% 4d5h`) in the popout's header:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
topside usage install # routes Claude Code's status line through Topside
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Claude Code only tells its status line about rate limits, so Topside wraps yours: it passes the numbers on, then runs your status line on the same input and prints what it prints. Your command rides along base64-encoded and `topside usage uninstall` puts it back byte for byte. With no status line before, nothing is printed. The percent is green below 50, orange from 50, red from 80. If another tool rewrites `statusLine` later, run `topside usage install` again.
|
|
93
|
+
|
|
94
|
+
On DankMaterialShell, put Topside on the bar:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
topside setup # installs the plugin into ~/.config/dms/plugins/topside and enables it
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Then open DMS Settings → Bar → Widgets and add "Topside" to the left, center or right zone. The bar shows the newest session's mascot (its agent's logo in pixels, in the status color) and one dot per session; with no session it shows Topside's sign, three glowing status dots side by side. The popout and the bar marks use Topside's own themes: pick one, with Light, Dark or System, and the text size under ⚙. ⏻ next to it quits Topside (stops the daemon); the popout then offers to start it again; click it for the list. A permission request comes as a card with Deny, Always, Allow and Auto mode: Always takes Claude Code's own suggestion (it says which, like accepting edits for the rest of the session), Auto mode lets Claude Code decide later tool calls itself. A request to edit or write a file shows the change as a short diff first. When Claude asks you a multiple-choice question, it shows up on the island as well as in the terminal. Click an option on either one and the other closes. The popout opens by itself when Claude Code asks for permission. When a session finishes while its terminal is out of sight, the popout opens for 5 seconds on your prompt and Claude's last reply; rest the pointer on it to keep it open. It opens on the monitor you're working on. The ⚙ in the popout opens Topside's settings in DMS, laid out like the Mac's: General (start at login, how many sessions the bar and the list show, 5 by default, the rest behind "+ N more"), Notifications (whether cards open by themselves, a reminder for a request nobody answered after 2 minutes, and sounds, off by default, picked from your desktop's sound theme), Hidden sessions (folders and prompts you hid from a row's ⊘ and ≈ buttons, each with a ✕ to bring them back), Integrations (switches for the Claude Code hooks and plan usage, so you don't need the commands below; if Claude Code still runs another copy of Topside or the old via, a Use this copy button fixes it), Appearance, and About (the version, who made it, and where this copy runs from). Its "Arrange on the bar" row takes you to DMS's Bar → Widgets page, where you drag Topside to another zone or spot. A running session shows your last prompt and what it is doing right now ("Editing auth.ts"), with chips for the agent and terminal and how long it has run. A session that finished its turn turns green and says "Done · click to jump" until you jump to it or send it a prompt. Click a session to jump to its terminal. Point at a row for ⊘, which hides every session in its folder, and ≈, which hides sessions started with a prompt like it; Undo shows for 6 seconds. Runs of `claude -p` never show up. Background sessions (`claude --bg`, `/bg`) stay off the island while nobody watches them; Claude handles them. Run `claude attach <id>` in a terminal and that session shows up, and clicking it jumps to that terminal. Run `topside setup` again after upgrading Topside to refresh the plugin files, then restart DMS (`systemctl --user restart dms`) so it drops the old ones.
|
|
101
|
+
|
|
102
|
+
On SekaiPop, the same `topside setup` puts Topside in its bar instead (both, when both run). It copies the plugin into `~/.config/sekaipop/plugins/topside` and switches its entry on; Edit Desktop's BAR tab moves it. A plugin already in that folder that setup didn't write is moved to `~/.local/state/topside/` first, never deleted. Settings you picked on the DMS widget (sounds, reminders, theme, hidden sessions) come along unless you already set them on SekaiPop. The entry and its card work like the DMS widget: the mascot and dots, cards that open by themselves for a request or a finished turn, sounds, reminders, ⊘ and ≈ with Undo, and the ⌃Y ⌃N ⌃A ⌃1…⌃9 ⌃J keys on the card you open with a click. A card that opens by itself sits in Topside's own window by the entry and takes no keys, so you keep typing; ✕ closes it, and it goes once you've answered. Its settings live in SekaiPop's Settings > Desktop > Plugins > Topside (⚙ on the card goes there), and picking a sound there plays it: sessions shown, the notification switches and sounds, the hidden folders and prompts one per line, style, look, theme, mode and text size. Style picks how things arrive. Board, the default, lowers a split-flap departure board with the session, its agent and a status word (WAITING, QUESTION, SECURITY, DELAYED, ARRIVED), the change and keys under it; a click on the entry dims the screen and lowers the departures board in Topside's own window, 880 wide with an agent column, waiting sessions first; a click on a row spotlights it and answers it or shows Jump, with hiding as a quiet link, and Esc or a click outside puts it away. The notification board is wide too, most of a 1080p screen's width, with the board's usual flaps; a long diff scrolls under it while the board and the keys stay put. Ticket prints each request out of a little receipt printer on the bar as an order ticket, and you answer with rubber stamps (ALLOW, DENY, RUN IT) that slam onto the paper before it tears off; a finished turn prints ORDER UP!, and a click on the entry dims the screen and shows the kitchen rail in Topside's own window, a ticket per session under a shift report of your plan. A long ticket keeps its head and stamps in place and scrolls the middle. Classic is Topside's cards. The look starts on Match SekaiPop: the card takes the shell's surfaces, outline, corners, hard shadow, font and light or dark mode, and the theme you pick only colors the statuses. Pick Topside to get Topside's own look back. The hook and usage switches of the DMS page aren't there; use the commands below. After `topside setup` replaces files, SekaiPop keeps the old ones until Settings > General > Reload shell.
|
|
103
|
+
|
|
104
|
+
Without DMS or SekaiPop, start the pill:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
topside pill # Quickshell pill, top-center by default
|
|
108
|
+
topside pill position bottom-right # move it; the running pill follows the file
|
|
109
|
+
topside pill theme tokyoNight # one of Topside's nine themes, or one of yours
|
|
110
|
+
topside pill mode system # light, dark, or follow the desktop
|
|
111
|
+
topside pill text-size 12 # 10 to 14
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
The pill lists every live session with its state, opens by itself when Claude Code asks for permission, and has Allow and Deny buttons right there. Click a session to jump to its terminal. To get it at login on Hyprland, add `exec-once = topside pill` to `hyprland.conf`. Position is stored in `~/.config/topside/config.json`. The nine positions are `top`, `middle` or `bottom` crossed with `left`, `center` or `right`.
|
|
115
|
+
|
|
116
|
+
### Icon
|
|
117
|
+
|
|
118
|
+
`contrib/icons/hicolor/scalable/apps/topside.svg` is Topside's icon: three status dots on black. To give a launcher entry or a package the icon:
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
install -Dm644 contrib/icons/hicolor/scalable/apps/topside.svg ~/.local/share/icons/hicolor/scalable/apps/topside.svg
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Your own themes
|
|
125
|
+
|
|
126
|
+
A theme is a JSON file in `~/.config/topside/themes/`. Its file name is its id. [`contrib/themes/sakura.json`](./contrib/themes/sakura.json) is a whole one to copy:
|
|
127
|
+
|
|
128
|
+
```json
|
|
129
|
+
{
|
|
130
|
+
"name": "Sakura",
|
|
131
|
+
"dark": { "background": "#2a1f2d", "surface": "#3d2c40", "text": "#ffe4ef", "muted": "#a58ca8",
|
|
132
|
+
"working": "#7ec8e3", "waiting": "#ffb86b", "done": "#9be38f", "reminder": "#ff6b8a", "idle": "#c9a0dc" },
|
|
133
|
+
"light": { "...": "the same nine; leave it out and the dark side is used" },
|
|
134
|
+
"shape": { "cardRadius": 14, "lineWidth": 2, "shadowOffset": 3 }
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
`dark` needs all nine colors, written as `#rrggbb`. `shape` is optional. It takes `font` and `monoFont` (a font's name), and `cardRadius`, `buttonRadius`, `chipRadius`, `rowRadius`, `panelRadius`, `lineWidth` and `shadowOffset` (whole numbers). The file only holds data, nothing that runs.
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
topside theme list # the nine built-in themes and yours, ✓ fine, ! partly used, ✗ unusable
|
|
142
|
+
topside theme check sakura # what's wrong, line by line; exits 1 if anything is
|
|
143
|
+
topside theme sync # refresh SekaiPop's Theme list now (it does this itself)
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Pick yours where you pick any theme: `topside pill theme sakura`, the ‹ › picker on the DMS settings page, or SekaiPop's Theme list. SekaiPop's list catches up by itself a moment after you add, rename or remove a file (`topside theme sync` does it by hand). Saving a file you're using shows at once. A file Topside can't draw falls back to Topside Black. A wrong shape value is just left out.
|
|
147
|
+
|
|
148
|
+
The same things work from a terminal:
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
topside status # live sessions, plus tool calls waiting for you
|
|
152
|
+
topside approve <id> # let the tool call run
|
|
153
|
+
topside deny <id> # block it
|
|
154
|
+
topside jump <id> # focus the session's terminal; any unique prefix of the id works
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Jump needs Hyprland. It switches to the workspace, focuses the window and brings the right tab forward in WezTerm, Orca and tmux (when a terminal has the tmux session attached). Other terminals get the window focused but not the tab. A session started before this version has no terminal recorded until its next prompt.
|
|
158
|
+
|
|
159
|
+
The normal prompt still shows in Claude Code's terminal while Topside waits. Whichever side answers first wins. If the daemon isn't running, the hooks exit right away and Claude Code behaves as if Topside weren't there.
|
|
160
|
+
|
|
161
|
+
## Development
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
npm install
|
|
165
|
+
npm run typecheck # tsc --noEmit
|
|
166
|
+
npm test # node --test on src/**/*.test.ts
|
|
167
|
+
npm run lint # eslint src/
|
|
168
|
+
npm run build # tsc → dist/
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Node runs the `.ts` sources directly (type stripping), so tests don't need a build step.
|
|
172
|
+
|
|
173
|
+
To see what an agent really sends, start it with `TOPSIDE_HOOK_LOG` pointing at a file:
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
TOPSIDE_HOOK_LOG=~/topside-hooks.ndjson claude
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Every hook call appends one line, `{"agent": "claude", "payload": {...}}`. The file is created readable by you only, since payloads include your prompts. Nothing leaves the machine.
|
|
180
|
+
|
|
181
|
+
The logotype, the agent logos, the mascot effects and the nine themes come from Topside on the Mac as one data file, `assets/shared/pixels.json`. Don't edit it, or `shell/core/pixels.js` written from it. When the Mac's copy changes, take it again:
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
node scripts/pixels.ts # from ../vim/assets/shared/pixels.json
|
|
185
|
+
node scripts/pixels.ts path/to/pixels.json
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
`src/shared/pixels.test.ts` fails on a bad copy.
|
|
189
|
+
|
|
190
|
+
## Release
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
npm run release:patch # or release:minor / release:major
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
`scripts/release.sh` checks, builds, bumps the version, pushes tags and publishes to npm. Then it runs `scripts/aur.sh`, which sets `pkgver` and `sha256sums` in `contrib/aur/PKGBUILD` from the published tarball, writes `.SRCINFO`, and commits both. Pushing to the AUR is by hand:
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
scripts/aur.sh --try # before a release: build the package from `npm pack`
|
|
200
|
+
scripts/aur.sh --copy ~/aur/topside-arch # after one: copy the files into your AUR clone
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
Write the release note in `docs/releases/<version>.md` before releasing.
|
|
204
|
+
|
|
205
|
+
## Documentation
|
|
206
|
+
|
|
207
|
+
- [CLAUDE.md](./CLAUDE.md) — development guide
|
|
208
|
+
- [docs/PRD.md](./docs/PRD.md) — product requirements
|
|
209
|
+
- [docs/USER-STORIES.md](./docs/USER-STORIES.md) — user stories and acceptance criteria
|
|
210
|
+
- [docs/notes/hosts.md](./docs/notes/hosts.md) — the shells Topside runs in, what each can do, and how to add one
|
|
211
|
+
|
|
212
|
+
## License
|
|
213
|
+
|
|
214
|
+
MIT, see [LICENSE](./LICENSE). Agent names and marks (Claude Code, Codex, pi, omp) belong to their owners.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Maintainer: Nguyen Duc Ban
|
|
2
|
+
# Built from the npm tarball. scripts/aur.sh fills pkgver and sha256sums
|
|
3
|
+
# after a release; don't edit those two by hand.
|
|
4
|
+
pkgname=topside-arch
|
|
5
|
+
pkgver=0.1.0
|
|
6
|
+
pkgrel=1
|
|
7
|
+
pkgdesc="Watch your coding agents (Claude Code, Codex, pi, omp) from your Quickshell bar: answer their requests, jump to their terminal"
|
|
8
|
+
arch=('any')
|
|
9
|
+
url="https://topside.ducban.com/arch/"
|
|
10
|
+
license=('MIT')
|
|
11
|
+
depends=('nodejs>=26' 'quickshell')
|
|
12
|
+
makedepends=('npm')
|
|
13
|
+
optdepends=(
|
|
14
|
+
'hyprland: jump to a session'"'"'s terminal'
|
|
15
|
+
'libcanberra: sounds for requests and finished turns'
|
|
16
|
+
'wezterm: pick the tab when jumping'
|
|
17
|
+
'tmux: pick the window and pane when jumping'
|
|
18
|
+
)
|
|
19
|
+
install=topside-arch.install
|
|
20
|
+
source=("https://registry.npmjs.org/$pkgname/-/$pkgname-$pkgver.tgz")
|
|
21
|
+
noextract=("$pkgname-$pkgver.tgz")
|
|
22
|
+
sha256sums=('SKIP')
|
|
23
|
+
|
|
24
|
+
package() {
|
|
25
|
+
npm install -g --no-fund --no-audit --prefix "$pkgdir/usr" "$srcdir/$pkgname-$pkgver.tgz"
|
|
26
|
+
|
|
27
|
+
# npm leaves some folders writable by everyone and files owned by the builder.
|
|
28
|
+
find "$pkgdir/usr" -type d -exec chmod 755 {} +
|
|
29
|
+
chown -R root:root "$pkgdir"
|
|
30
|
+
|
|
31
|
+
local mod="$pkgdir/usr/lib/node_modules/$pkgname"
|
|
32
|
+
install -Dm644 "$mod/contrib/systemd/topside.service" "$pkgdir/usr/lib/systemd/user/topside.service"
|
|
33
|
+
install -Dm644 "$mod/contrib/icons/hicolor/scalable/apps/topside.svg" "$pkgdir/usr/share/icons/hicolor/scalable/apps/topside.svg"
|
|
34
|
+
install -Dm644 "$mod/LICENSE" "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
|
|
35
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
post_install() {
|
|
2
|
+
cat <<'EOF'
|
|
3
|
+
==> Topside is installed. As your own user, not root:
|
|
4
|
+
systemctl --user enable --now topside # the daemon, now and at login
|
|
5
|
+
topside hooks install # Claude Code's hooks (codex, pi, omp: add the name)
|
|
6
|
+
topside setup # SekaiPop or DMS bar entry; else run `topside pill`
|
|
7
|
+
EOF
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
post_upgrade() {
|
|
11
|
+
cat <<'EOF'
|
|
12
|
+
==> Topside upgraded. As your own user:
|
|
13
|
+
systemctl --user restart topside
|
|
14
|
+
topside setup # refreshes the bar's files; then reload the shell
|
|
15
|
+
EOF
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
pre_remove() {
|
|
19
|
+
cat <<'EOF'
|
|
20
|
+
==> Removing Topside. Its hooks stay in your agents' settings and now point
|
|
21
|
+
at a command that's gone. Take out the entries tagged # topside-managed
|
|
22
|
+
in ~/.claude/settings.json (and ~/.codex/hooks.json), or reinstall and
|
|
23
|
+
run `topside hooks uninstall` first. Your data stays in ~/.local/state/topside.
|
|
24
|
+
EOF
|
|
25
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="256" height="256" viewBox="0 0 256 256">
|
|
2
|
+
<!-- Topside's sign: the three status dots (working, waiting, done) side by
|
|
3
|
+
side with a soft glow, on Topside Black. Drawn for Linux, after the Mac
|
|
4
|
+
app's icon but without its notch. Glows are radial gradients, not
|
|
5
|
+
filters, so every icon theme renderer draws them. -->
|
|
6
|
+
<defs>
|
|
7
|
+
<radialGradient id="glow-working">
|
|
8
|
+
<stop offset="0.35" stop-color="#4d85ff" stop-opacity="0.55"/>
|
|
9
|
+
<stop offset="1" stop-color="#4d85ff" stop-opacity="0"/>
|
|
10
|
+
</radialGradient>
|
|
11
|
+
<radialGradient id="glow-waiting">
|
|
12
|
+
<stop offset="0.35" stop-color="#ff8c29" stop-opacity="0.55"/>
|
|
13
|
+
<stop offset="1" stop-color="#ff8c29" stop-opacity="0"/>
|
|
14
|
+
</radialGradient>
|
|
15
|
+
<radialGradient id="glow-done">
|
|
16
|
+
<stop offset="0.35" stop-color="#40d96b" stop-opacity="0.55"/>
|
|
17
|
+
<stop offset="1" stop-color="#40d96b" stop-opacity="0"/>
|
|
18
|
+
</radialGradient>
|
|
19
|
+
</defs>
|
|
20
|
+
<rect x="8" y="8" width="240" height="240" rx="56" fill="#000000"/>
|
|
21
|
+
<rect x="8.5" y="8.5" width="239" height="239" rx="55.5" fill="none" stroke="#2a2a2a" stroke-width="1"/>
|
|
22
|
+
<circle cx="68" cy="128" r="46" fill="url(#glow-working)"/>
|
|
23
|
+
<circle cx="128" cy="128" r="46" fill="url(#glow-waiting)"/>
|
|
24
|
+
<circle cx="188" cy="128" r="46" fill="url(#glow-done)"/>
|
|
25
|
+
<circle cx="68" cy="128" r="20" fill="#4d85ff"/>
|
|
26
|
+
<circle cx="128" cy="128" r="20" fill="#ff8c29"/>
|
|
27
|
+
<circle cx="188" cy="128" r="20" fill="#40d96b"/>
|
|
28
|
+
</svg>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Sakura",
|
|
3
|
+
"dark": {
|
|
4
|
+
"background": "#2a1f2d",
|
|
5
|
+
"surface": "#3d2c40",
|
|
6
|
+
"text": "#ffe4ef",
|
|
7
|
+
"muted": "#a58ca8",
|
|
8
|
+
"working": "#7ec8e3",
|
|
9
|
+
"waiting": "#ffb86b",
|
|
10
|
+
"done": "#9be38f",
|
|
11
|
+
"reminder": "#ff6b8a",
|
|
12
|
+
"idle": "#c9a0dc"
|
|
13
|
+
},
|
|
14
|
+
"light": {
|
|
15
|
+
"background": "#fff5f8",
|
|
16
|
+
"surface": "#f6e1ea",
|
|
17
|
+
"text": "#3a2533",
|
|
18
|
+
"muted": "#9a7d8c",
|
|
19
|
+
"working": "#2f7fb0",
|
|
20
|
+
"waiting": "#c46a12",
|
|
21
|
+
"done": "#3f8f3a",
|
|
22
|
+
"reminder": "#d6335a",
|
|
23
|
+
"idle": "#8a5aa8"
|
|
24
|
+
},
|
|
25
|
+
"shape": {
|
|
26
|
+
"cardRadius": 14,
|
|
27
|
+
"buttonRadius": 12,
|
|
28
|
+
"lineWidth": 2,
|
|
29
|
+
"shadowOffset": 3
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { readdirSync, readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
// The record of the first process in the hook's ancestry that has one.
|
|
4
|
+
export function findSessionRecord(pids, read) {
|
|
5
|
+
for (const pid of pids) {
|
|
6
|
+
const raw = read(pid);
|
|
7
|
+
if (raw === null)
|
|
8
|
+
continue;
|
|
9
|
+
try {
|
|
10
|
+
const value = JSON.parse(raw);
|
|
11
|
+
const field = (key) => (typeof value[key] === "string" ? value[key] : "");
|
|
12
|
+
return { pid, sessionId: field("sessionId"), jobId: field("jobId"), name: field("name") };
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
// `claude attach <target>`: argv0 is a claude binary, then "attach", then the target.
|
|
21
|
+
export function attachTarget(argv) {
|
|
22
|
+
const [program, command, target] = argv;
|
|
23
|
+
if (!program || command !== "attach" || !target)
|
|
24
|
+
return null;
|
|
25
|
+
return program.split("/").at(-1) === "claude" ? target : null;
|
|
26
|
+
}
|
|
27
|
+
// The target can be a prefix of the session ID, a prefix of the job ID, or the name.
|
|
28
|
+
export function attaches(target, sessionId, record) {
|
|
29
|
+
if (sessionId.startsWith(target))
|
|
30
|
+
return true;
|
|
31
|
+
if (record === null)
|
|
32
|
+
return false;
|
|
33
|
+
return (record.jobId !== "" && record.jobId.startsWith(target)) || (record.name !== "" && record.name === target);
|
|
34
|
+
}
|
|
35
|
+
export function findAttachClient(clients, sessionId, record) {
|
|
36
|
+
return clients.find((client) => attaches(client.target, sessionId, record)) ?? null;
|
|
37
|
+
}
|
|
38
|
+
// Every `claude attach` process that sits on a terminal.
|
|
39
|
+
export function listAttachClients(proc = "/proc") {
|
|
40
|
+
const clients = [];
|
|
41
|
+
let entries;
|
|
42
|
+
try {
|
|
43
|
+
entries = readdirSync(proc);
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return clients;
|
|
47
|
+
}
|
|
48
|
+
for (const entry of entries) {
|
|
49
|
+
if (!/^\d+$/.test(entry))
|
|
50
|
+
continue;
|
|
51
|
+
const target = attachTarget(readProc(proc, entry, "cmdline").split("\0"));
|
|
52
|
+
if (target !== null && hasTerminal(readProc(proc, entry, "stat")))
|
|
53
|
+
clients.push({ pid: Number(entry), target });
|
|
54
|
+
}
|
|
55
|
+
return clients;
|
|
56
|
+
}
|
|
57
|
+
export function readSessionRecord(configDir) {
|
|
58
|
+
return (pid) => {
|
|
59
|
+
try {
|
|
60
|
+
return readFileSync(join(configDir, "sessions", `${pid}.json`), "utf8");
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export function readEnviron(pid, proc = "/proc") {
|
|
68
|
+
const environ = {};
|
|
69
|
+
for (const pair of readProc(proc, String(pid), "environ").split("\0")) {
|
|
70
|
+
const at = pair.indexOf("=");
|
|
71
|
+
if (at > 0)
|
|
72
|
+
environ[pair.slice(0, at)] = pair.slice(at + 1);
|
|
73
|
+
}
|
|
74
|
+
return environ;
|
|
75
|
+
}
|
|
76
|
+
// tty_nr, the 7th field of /proc/<pid>/stat, is 0 without a controlling terminal.
|
|
77
|
+
// The comm field can contain spaces and parens, so count after the last ")".
|
|
78
|
+
export function hasTerminal(stat) {
|
|
79
|
+
if (stat === "")
|
|
80
|
+
return false;
|
|
81
|
+
const fields = stat.slice(stat.lastIndexOf(")") + 2).split(" ");
|
|
82
|
+
const tty = Number(fields[4]);
|
|
83
|
+
return Number.isInteger(tty) && tty !== 0;
|
|
84
|
+
}
|
|
85
|
+
function readProc(proc, pid, file) {
|
|
86
|
+
try {
|
|
87
|
+
return readFileSync(join(proc, pid, file), "utf8");
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return "";
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { err, ok } from "../../shared/result.js";
|
|
2
|
+
function isRecord(value) {
|
|
3
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4
|
+
}
|
|
5
|
+
function str(input, key) {
|
|
6
|
+
const value = input[key];
|
|
7
|
+
return typeof value === "string" ? value : "";
|
|
8
|
+
}
|
|
9
|
+
// Background sessions run under Claude's own daemon with no terminal of their
|
|
10
|
+
// own. Topside leaves them to Claude: no row, no approvals. One started with
|
|
11
|
+
// claude --bg has CLAUDE_CODE_SESSION_KIND=bg; one moved there with /bg only
|
|
12
|
+
// has CLAUDE_JOB_DIR. Foreground sessions have neither (Claude Code 2.1.323).
|
|
13
|
+
export function isBackgroundSession(env) {
|
|
14
|
+
return env.CLAUDE_CODE_SESSION_KIND === "bg" || Boolean(env.CLAUDE_JOB_DIR);
|
|
15
|
+
}
|
|
16
|
+
// Maps one Claude Code hook stdin payload to an agent-neutral event.
|
|
17
|
+
// Returns ok(null) for hook events Topside doesn't track. Codex's payloads
|
|
18
|
+
// have the same fields (docs/notes/codex-hooks.md), so they come through
|
|
19
|
+
// here too, tagged with their own agent.
|
|
20
|
+
export function parseHookInput(raw, origin, agent = "claude") {
|
|
21
|
+
let input;
|
|
22
|
+
try {
|
|
23
|
+
input = JSON.parse(raw);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return err("hook input is not JSON");
|
|
27
|
+
}
|
|
28
|
+
if (!isRecord(input))
|
|
29
|
+
return err("hook input is not an object");
|
|
30
|
+
const sessionId = str(input, "session_id");
|
|
31
|
+
if (sessionId === "")
|
|
32
|
+
return err("hook input has no session_id");
|
|
33
|
+
const base = { agent, sessionId, cwd: str(input, "cwd"), ...origin };
|
|
34
|
+
switch (str(input, "hook_event_name")) {
|
|
35
|
+
case "SessionStart":
|
|
36
|
+
return ok({ ...base, type: "session-start", name: str(input, "session_title") });
|
|
37
|
+
case "SessionEnd":
|
|
38
|
+
return ok({ ...base, type: "session-end" });
|
|
39
|
+
case "UserPromptSubmit":
|
|
40
|
+
return ok({ ...base, type: "prompt", text: str(input, "prompt"), name: str(input, "session_title") });
|
|
41
|
+
case "PreToolUse":
|
|
42
|
+
return ok({
|
|
43
|
+
...base,
|
|
44
|
+
type: "tool-start",
|
|
45
|
+
toolUseId: str(input, "tool_use_id"),
|
|
46
|
+
toolName: str(input, "tool_name"),
|
|
47
|
+
toolInput: input.tool_input,
|
|
48
|
+
});
|
|
49
|
+
case "PostToolUse":
|
|
50
|
+
return ok({
|
|
51
|
+
...base,
|
|
52
|
+
type: "tool-end",
|
|
53
|
+
toolUseId: str(input, "tool_use_id"),
|
|
54
|
+
toolName: str(input, "tool_name"),
|
|
55
|
+
});
|
|
56
|
+
case "PermissionRequest":
|
|
57
|
+
return ok({
|
|
58
|
+
...base,
|
|
59
|
+
type: "approval-request",
|
|
60
|
+
toolName: str(input, "tool_name"),
|
|
61
|
+
toolInput: input.tool_input,
|
|
62
|
+
always: describeSuggestions(input.permission_suggestions),
|
|
63
|
+
inFront: false, // filled in by the hook command, like turn-end's
|
|
64
|
+
});
|
|
65
|
+
case "Notification":
|
|
66
|
+
return ok({ ...base, type: "attention", reason: attentionReason(str(input, "notification_type")), message: str(input, "message") });
|
|
67
|
+
case "Stop":
|
|
68
|
+
// inFront is filled in by the hook command, which can ask the compositor.
|
|
69
|
+
return ok({ ...base, type: "turn-end", message: str(input, "last_assistant_message"), inFront: false, ...spendOf(input) });
|
|
70
|
+
default:
|
|
71
|
+
return ok(null);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// topside_spend, which the pi and omp extension adds to Stop. The model it
|
|
75
|
+
// names isn't shown, so it isn't read.
|
|
76
|
+
function spendOf(input) {
|
|
77
|
+
const fields = input.topside_spend;
|
|
78
|
+
if (!isRecord(fields))
|
|
79
|
+
return {};
|
|
80
|
+
const cost = typeof fields.cost === "number" && fields.cost > 0 ? fields.cost : 0;
|
|
81
|
+
const tokens = typeof fields.tokens === "number" && fields.tokens > 0 ? Math.round(fields.tokens) : 0;
|
|
82
|
+
return cost > 0 || tokens > 0 ? { spend: { cost, tokens } } : {};
|
|
83
|
+
}
|
|
84
|
+
function attentionReason(notificationType) {
|
|
85
|
+
if (notificationType === "permission_prompt")
|
|
86
|
+
return "permission";
|
|
87
|
+
if (notificationType === "idle_prompt")
|
|
88
|
+
return "idle";
|
|
89
|
+
return "other";
|
|
90
|
+
}
|
|
91
|
+
// The permission_suggestions of a PermissionRequest payload, or null.
|
|
92
|
+
// Always Allow sends them back unchanged as updatedPermissions.
|
|
93
|
+
export function permissionSuggestions(raw) {
|
|
94
|
+
try {
|
|
95
|
+
const input = JSON.parse(raw);
|
|
96
|
+
return isRecord(input) ? (input.permission_suggestions ?? null) : null;
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// What Always Allow will do with these suggestions, in a few words; "" when
|
|
103
|
+
// there's nothing to apply, so the card hides the button. Measured shapes are
|
|
104
|
+
// in docs/notes/claude-hooks.md.
|
|
105
|
+
export function describeSuggestions(suggestions) {
|
|
106
|
+
if (!Array.isArray(suggestions) || suggestions.length === 0)
|
|
107
|
+
return "";
|
|
108
|
+
const parts = suggestions.map(describeSuggestion).filter((part) => part !== "");
|
|
109
|
+
return parts.length === 0 ? "Apply Claude Code's suggestion" : parts.join("; ");
|
|
110
|
+
}
|
|
111
|
+
// One entry in words; "" for entries that ride along unlabeled, such as addDirectories.
|
|
112
|
+
function describeSuggestion(entry) {
|
|
113
|
+
if (!isRecord(entry))
|
|
114
|
+
return "";
|
|
115
|
+
switch (str(entry, "type")) {
|
|
116
|
+
case "setMode": {
|
|
117
|
+
const mode = str(entry, "mode");
|
|
118
|
+
if (mode === "")
|
|
119
|
+
return "";
|
|
120
|
+
return mode === "acceptEdits" ? "Accept edits for the rest of this session" : `Switch this session to ${mode} mode`;
|
|
121
|
+
}
|
|
122
|
+
case "addRules": {
|
|
123
|
+
const rules = Array.isArray(entry.rules) ? entry.rules.filter(isRecord) : [];
|
|
124
|
+
const names = rules
|
|
125
|
+
.filter((rule) => str(rule, "toolName") !== "")
|
|
126
|
+
.map((rule) => (str(rule, "ruleContent") === "" ? str(rule, "toolName") : `${str(rule, "toolName")}(${str(rule, "ruleContent")})`));
|
|
127
|
+
if (names.length === 0)
|
|
128
|
+
return "";
|
|
129
|
+
const place = str(entry, "destination") === "session" ? "this session" : "this project";
|
|
130
|
+
return `Always allow ${names.join(", ")} in ${place}`;
|
|
131
|
+
}
|
|
132
|
+
default:
|
|
133
|
+
return "";
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// stdout for a PermissionRequest hook. Empty string leaves the terminal prompt in charge.
|
|
137
|
+
// Bypass isn't offered: setMode bypassPermissions does nothing in a session
|
|
138
|
+
// that wasn't started with it, while setMode auto does take effect.
|
|
139
|
+
export function formatDecision(decision, suggestions = null) {
|
|
140
|
+
if (decision === "none")
|
|
141
|
+
return "";
|
|
142
|
+
const body = decision === "deny"
|
|
143
|
+
? { behavior: "deny", message: "Denied from Topside" }
|
|
144
|
+
: decision === "always" && Array.isArray(suggestions) && suggestions.length > 0
|
|
145
|
+
? { behavior: "allow", updatedPermissions: suggestions }
|
|
146
|
+
: decision === "auto"
|
|
147
|
+
? { behavior: "allow", updatedPermissions: [{ type: "setMode", mode: "auto", destination: "session" }] }
|
|
148
|
+
: { behavior: "allow" };
|
|
149
|
+
return `${JSON.stringify({ hookSpecificOutput: { hookEventName: "PermissionRequest", decision: body } })}\n`;
|
|
150
|
+
}
|
|
151
|
+
// AskUserQuestion's tool_input.questions, read tolerantly. Empty when the
|
|
152
|
+
// input doesn't look like a question we can show.
|
|
153
|
+
export function parseQuestions(toolInput) {
|
|
154
|
+
if (!isRecord(toolInput) || !Array.isArray(toolInput.questions))
|
|
155
|
+
return [];
|
|
156
|
+
const questions = [];
|
|
157
|
+
for (const item of toolInput.questions) {
|
|
158
|
+
if (!isRecord(item) || !Array.isArray(item.options))
|
|
159
|
+
return [];
|
|
160
|
+
const options = item.options.filter(isRecord).map((o) => ({ label: str(o, "label"), description: str(o, "description") }));
|
|
161
|
+
if (str(item, "question") === "" || options.length === 0 || options.some((o) => o.label === ""))
|
|
162
|
+
return [];
|
|
163
|
+
questions.push({ question: str(item, "question"), header: str(item, "header"), options, multiSelect: item.multiSelect === true });
|
|
164
|
+
}
|
|
165
|
+
return questions;
|
|
166
|
+
}
|
|
167
|
+
// stdout for a PermissionRequest hook that answers AskUserQuestion: allow, plus
|
|
168
|
+
// the original questions with the answers (updatedInput replaces the whole input).
|
|
169
|
+
export function formatAnswers(toolInput, answers) {
|
|
170
|
+
const questions = isRecord(toolInput) ? toolInput.questions : [];
|
|
171
|
+
const decision = { behavior: "allow", updatedInput: { questions, answers } };
|
|
172
|
+
return `${JSON.stringify({ hookSpecificOutput: { hookEventName: "PermissionRequest", decision } })}\n`;
|
|
173
|
+
}
|