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.
Files changed (95) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +217 -2
  3. package/contrib/aur/.SRCINFO +20 -0
  4. package/contrib/aur/PKGBUILD +35 -0
  5. package/contrib/aur/topside-arch.install +28 -0
  6. package/contrib/icons/hicolor/scalable/apps/topside.svg +28 -0
  7. package/contrib/systemd/topside.service +10 -0
  8. package/contrib/themes/sakura.json +31 -0
  9. package/dist/adapters/claude/attach.js +92 -0
  10. package/dist/adapters/claude/hook-event.js +173 -0
  11. package/dist/adapters/claude/one-shot.js +30 -0
  12. package/dist/adapters/claude/settings.js +78 -0
  13. package/dist/adapters/claude/usage.js +76 -0
  14. package/dist/adapters/codex/codex.js +73 -0
  15. package/dist/adapters/codex/patch.js +39 -0
  16. package/dist/adapters/codex/usage.js +77 -0
  17. package/dist/adapters/pi/extension.js +271 -0
  18. package/dist/adapters/pi/risk-gate.js +256 -0
  19. package/dist/cli/commands.js +615 -0
  20. package/dist/cli/hook-log.js +32 -0
  21. package/dist/cli/main.js +100 -0
  22. package/dist/daemon/preview.js +70 -0
  23. package/dist/daemon/processes.js +105 -0
  24. package/dist/daemon/server.js +437 -0
  25. package/dist/daemon/session-state.js +179 -0
  26. package/dist/daemon/store.js +176 -0
  27. package/dist/dms/setup.js +137 -0
  28. package/dist/hosts/hosts.js +39 -0
  29. package/dist/jump/jump.js +199 -0
  30. package/dist/pill/config.js +92 -0
  31. package/dist/pill/launch.js +38 -0
  32. package/dist/sekaipop/setup.js +267 -0
  33. package/dist/service/unit.js +77 -0
  34. package/dist/shared/ancestry.js +27 -0
  35. package/dist/shared/client.js +29 -0
  36. package/dist/shared/package.js +25 -0
  37. package/dist/shared/paths.js +69 -0
  38. package/dist/shared/protocol.js +35 -0
  39. package/dist/shared/qml-lib.js +33 -0
  40. package/dist/shared/result.js +6 -0
  41. package/dist/shared/terminal.js +42 -0
  42. package/dist/themes/themes.js +84 -0
  43. package/package.json +49 -4
  44. package/shell/core/AgentIcon.qml +24 -0
  45. package/shell/core/AppLogo.qml +48 -0
  46. package/shell/core/ApprovalRow.qml +197 -0
  47. package/shell/core/BoardDetail.qml +336 -0
  48. package/shell/core/BoardList.qml +419 -0
  49. package/shell/core/BoardNotice.qml +189 -0
  50. package/shell/core/CardButton.qml +55 -0
  51. package/shell/core/CardHeader.qml +46 -0
  52. package/shell/core/ChalkBoard.qml +99 -0
  53. package/shell/core/CompletionCard.qml +106 -0
  54. package/shell/core/FlapText.qml +110 -0
  55. package/shell/core/KeyCap.qml +72 -0
  56. package/shell/core/Mascot.qml +13 -0
  57. package/shell/core/MascotBadge.qml +40 -0
  58. package/shell/core/MascotEffect.qml +40 -0
  59. package/shell/core/Paper.qml +54 -0
  60. package/shell/core/PixelGrid.qml +40 -0
  61. package/shell/core/QuestionRow.qml +161 -0
  62. package/shell/core/SessionRow.qml +257 -0
  63. package/shell/core/Stamp.qml +62 -0
  64. package/shell/core/StatusDots.qml +33 -0
  65. package/shell/core/Surface.qml +32 -0
  66. package/shell/core/Tag.qml +22 -0
  67. package/shell/core/TerminalIcon.qml +34 -0
  68. package/shell/core/Theme.qml +100 -0
  69. package/shell/core/TicketDetail.qml +657 -0
  70. package/shell/core/TicketList.qml +717 -0
  71. package/shell/core/TicketNotice.qml +198 -0
  72. package/shell/core/TopsideClient.qml +201 -0
  73. package/shell/core/UsageLine.qml +106 -0
  74. package/shell/core/agents.js +79 -0
  75. package/shell/core/board.js +132 -0
  76. package/shell/core/hiding.js +68 -0
  77. package/shell/core/pixels.js +542 -0
  78. package/shell/core/qmldir +30 -0
  79. package/shell/core/sounds.js +31 -0
  80. package/shell/core/themes.js +195 -0
  81. package/shell/core/ticket.js +170 -0
  82. package/shell/dms-plugin/TopsideSettings.qml +696 -0
  83. package/shell/dms-plugin/TopsideWidget.qml +554 -0
  84. package/shell/dms-plugin/plugin.json +14 -0
  85. package/shell/pill.qml +279 -0
  86. package/shell/sekaipop-plugin/Bar.qml +150 -0
  87. package/shell/sekaipop-plugin/Card.qml +296 -0
  88. package/shell/sekaipop-plugin/Floating.qml +74 -0
  89. package/shell/sekaipop-plugin/ListWindow.qml +156 -0
  90. package/shell/sekaipop-plugin/Popup.qml +70 -0
  91. package/shell/sekaipop-plugin/Service.qml +418 -0
  92. package/shell/sekaipop-plugin/ShellLook.qml +43 -0
  93. package/shell/sekaipop-plugin/StyledCard.qml +194 -0
  94. package/shell/sekaipop-plugin/place.js +28 -0
  95. package/shell/sekaipop-plugin/plugin.json +109 -0
@@ -0,0 +1,198 @@
1
+ import QtQuick
2
+ import "ticket.js" as Ticket
3
+
4
+ // The Ticket style's notification: a receipt printer's mouth with the
5
+ // ticket feeding out of it line by line. Tickets still waiting behind it sit
6
+ // crooked underneath with a red count. A stamp tears the ticket off upwards;
7
+ // the next one prints. TicketDetail.qml is the paper itself.
8
+ Item {
9
+ id: notice
10
+ required property var client
11
+ // What it prints: the first waiting request (Board.pending()), else the
12
+ // session whose turn just finished.
13
+ property var request: null
14
+ property var finishedSession: null
15
+ property var queue: []
16
+ property bool reminding: false
17
+ property bool shortcuts: false
18
+ property bool closable: false
19
+ // The text size; the ticket's width is the holder's.
20
+ property int size: 12
21
+ // The most it may take; past that, the middle of the ticket scrolls.
22
+ property real maxHeight: 100000
23
+ signal closeRequested()
24
+ signal dismissed()
25
+
26
+ readonly property var session: request ? sessionFor(request.sessionId) : finishedSession
27
+ function sessionFor(id) {
28
+ return client.sessions.find(s => s.id === id) || null;
29
+ }
30
+ function pick(index, label) {
31
+ detail.pick(index, label);
32
+ }
33
+
34
+ // Print again: a new ticket, or the same one brought back by its reminder.
35
+ readonly property string key: (request ? request.item.id : "") + "/" + (session ? session.id : "") + "/" + reminding
36
+ onKeyChanged: reprint()
37
+ Component.onCompleted: reprint()
38
+ function reprint() {
39
+ feed.restart();
40
+ }
41
+
42
+ // A little air between SekaiPop's bar and the printer.
43
+ readonly property int lead: 14
44
+ readonly property int mouth: Math.round(size * 1.7)
45
+ readonly property int inset: Math.round(size * 1.6)
46
+ readonly property int below: queue.length > 0 ? Math.round(size * 1.6) : 0
47
+
48
+ implicitHeight: lead + mouth + detail.implicitHeight + below + 18
49
+
50
+ // Tickets waiting behind this one, crooked.
51
+ Repeater {
52
+ model: Math.min(2, notice.queue.length)
53
+ delegate: Paper {
54
+ required property int index
55
+ x: notice.inset + (index === 0 ? 12 : -12)
56
+ y: notice.lead + notice.mouth + (index === 0 ? 10 : 18)
57
+ width: detail.width
58
+ // As tall as the ticket in front, so they only peek out below it.
59
+ height: detail.implicitHeight
60
+ rotation: index === 0 ? 2.5 : -2.5
61
+ opacity: index === 0 ? 0.95 : 0.85
62
+ }
63
+ }
64
+
65
+ // The paper, fed out of the printer and torn off when stamped.
66
+ Item {
67
+ id: slot
68
+ x: notice.inset - 20
69
+ y: notice.lead + notice.mouth - 2
70
+ width: detail.width + 40
71
+ height: detail.implicitHeight * feed.shown + 40
72
+ clip: true
73
+
74
+ TicketDetail {
75
+ id: detail
76
+ x: 20
77
+ y: -detail.implicitHeight * (0.6 * tear.lift + 1 - feed.shown)
78
+ width: notice.width - 2 * notice.inset
79
+ height: implicitHeight
80
+ client: notice.client
81
+ session: notice.session
82
+ request: notice.request
83
+ finished: notice.request === null
84
+ reminding: notice.reminding
85
+ shortcuts: notice.shortcuts
86
+ closable: notice.closable
87
+ size: notice.size
88
+ maxHeight: notice.maxHeight - notice.lead - notice.mouth - notice.below - 18
89
+ rotation: -5 * tear.lift
90
+ opacity: 1 - tear.lift
91
+ // Torn off: it lifts away; a new ticket starts straight, at once.
92
+ onLeavingChanged: {
93
+ if (leaving) tearAway.restart();
94
+ else {
95
+ tearAway.stop();
96
+ tear.lift = 0;
97
+ }
98
+ }
99
+ onCloseRequested: notice.closeRequested()
100
+ onDismissed: notice.dismissed()
101
+ }
102
+ }
103
+ QtObject {
104
+ id: tear
105
+ property real lift: 0
106
+ }
107
+ NumberAnimation {
108
+ id: tearAway
109
+ target: tear
110
+ property: "lift"
111
+ from: 0
112
+ to: 1
113
+ duration: 400
114
+ easing.type: Easing.InQuad
115
+ }
116
+
117
+ // How much of the ticket has come out: in steps, the way a printer feeds.
118
+ QtObject {
119
+ id: feed
120
+ property real shown: 1
121
+ function restart() {
122
+ shown = 0;
123
+ stepper.restart();
124
+ }
125
+ }
126
+ Timer {
127
+ id: stepper
128
+ interval: 55
129
+ repeat: true
130
+ onTriggered: {
131
+ feed.shown = Math.min(1, feed.shown + 1 / 16);
132
+ if (feed.shown >= 1) stop();
133
+ }
134
+ }
135
+
136
+ // The printer's mouth the paper comes out of.
137
+ Rectangle {
138
+ x: notice.inset - 16
139
+ y: notice.lead
140
+ width: detail.width + 32
141
+ height: notice.mouth
142
+ radius: height / 2
143
+ gradient: Gradient {
144
+ GradientStop { position: 0; color: "#3a3b42" }
145
+ GradientStop { position: 0.55; color: "#141418" }
146
+ GradientStop { position: 1; color: "#050507" }
147
+ }
148
+ border.color: "#000000"
149
+ Rectangle {
150
+ anchors.centerIn: parent
151
+ width: detail.width + 12
152
+ height: 4
153
+ radius: 2
154
+ color: "#000000"
155
+ }
156
+ // The printer's light: amber while something waits, green otherwise.
157
+ Rectangle {
158
+ anchors.verticalCenter: parent.verticalCenter
159
+ x: 12
160
+ width: 8
161
+ height: 8
162
+ radius: 4
163
+ color: notice.request ? "#f5a524" : "#3ecf6e"
164
+ opacity: notice.request && blink.dim ? 0.3 : 1
165
+ }
166
+ }
167
+
168
+ // How many tickets wait in all.
169
+ Rectangle {
170
+ visible: notice.queue.length > 0
171
+ x: notice.inset - width / 2 + 4
172
+ y: notice.lead + notice.mouth + 6
173
+ width: Math.round(notice.size * 2.4)
174
+ height: width
175
+ radius: width / 2
176
+ rotation: 8
177
+ color: Ticket.red
178
+ Text {
179
+ anchors.centerIn: parent
180
+ text: notice.queue.length + 1
181
+ color: "#ffffff"
182
+ font.family: Theme.monoFont
183
+ font.pixelSize: notice.size + 2
184
+ font.weight: Font.Black
185
+ }
186
+ }
187
+
188
+ QtObject {
189
+ id: blink
190
+ property bool dim: false
191
+ }
192
+ Timer {
193
+ interval: 600
194
+ repeat: true
195
+ running: notice.request !== null && notice.visible
196
+ onTriggered: blink.dim = !blink.dim
197
+ }
198
+ }
@@ -0,0 +1,201 @@
1
+ import QtQuick
2
+ import Quickshell
3
+ import Quickshell.Io
4
+ import "hiding.js" as Hiding
5
+
6
+ // Talks to the Topside daemon: one subscribe socket, snapshots pushed on change.
7
+ // Reconnects on its own when the daemon restarts.
8
+ Scope {
9
+ id: client
10
+
11
+ property string socketPath: Quickshell.env("TOPSIDE_SOCKET") || (Quickshell.env("XDG_RUNTIME_DIR") + "/topside/topside.sock")
12
+ property bool connected: sock.connected
13
+ // What the daemon sent, then the same without hidden sessions and their
14
+ // requests. Hosts use the filtered lists.
15
+ property var allSessions: []
16
+ property var allApprovals: []
17
+ property var allQuestions: []
18
+ property var hiddenFolders: []
19
+ property var hiddenPrompts: []
20
+ readonly property var hiddenIds: {
21
+ const ids = {};
22
+ for (const s of allSessions) if (Hiding.isHidden(s, hiddenFolders, hiddenPrompts)) ids[s.id] = true;
23
+ return ids;
24
+ }
25
+ readonly property var sessions: allSessions.filter(s => !hiddenIds[s.id])
26
+ readonly property var approvals: allApprovals.filter(a => !hiddenIds[a.sessionId])
27
+ readonly property var questions: allQuestions.filter(q => !hiddenIds[q.sessionId])
28
+ // Plan usage by agent name, e.g. usage.claude.fiveHour.
29
+ property var usage: ({})
30
+ // Spend per session id, from agents billed by the token (pi, omp).
31
+ property var spend: ({})
32
+ // Command that runs this Topside, e.g. ["/usr/bin/node", ".../main.js"]. The pill
33
+ // gets it from TOPSIDE_CLI; the DMS widget sets it from the plugin's cli.json.
34
+ property var cli: parseCli(Quickshell.env("TOPSIDE_CLI"))
35
+ property string jumpError: ""
36
+ signal jumped()
37
+ // A session's turn just ended while its terminal was out of sight: the
38
+ // host may show a completion card. Never for a session that was already
39
+ // done when the UI connected, nor one whose terminal had the focus.
40
+ signal finished(var session)
41
+ // The daemon's call for a sound: "attention" or "completion". Only on the
42
+ // broadcast after the change, for a session whose terminal was out of sight.
43
+ signal cue(string name)
44
+
45
+ // Ids of sessions done in the last snapshot; null until the first one.
46
+ property var wasDone: null
47
+
48
+ // A request or question that wasn't in the last snapshot. Every snapshot
49
+ // replaces the lists, so their changed signals fire on any broadcast; a
50
+ // host that opened on those would reopen a popout the user just closed.
51
+ signal requested()
52
+ property var wasPending: ({})
53
+
54
+ function noticeRequests() {
55
+ const pending = {};
56
+ let fresh = false;
57
+ for (const r of approvals.concat(questions)) {
58
+ pending[r.id] = true;
59
+ if (!wasPending[r.id]) fresh = true;
60
+ }
61
+ wasPending = pending;
62
+ if (fresh) requested();
63
+ }
64
+
65
+ function notice(sessions) {
66
+ const done = {};
67
+ for (const s of sessions) {
68
+ if (s.status !== "done") continue;
69
+ done[s.id] = true;
70
+ if (wasDone !== null && !wasDone[s.id] && !s.endedInFront) finished(s);
71
+ }
72
+ wasDone = done;
73
+ }
74
+
75
+ function parseCli(text) {
76
+ try {
77
+ const value = JSON.parse(text);
78
+ return Array.isArray(value) && value.length > 0 ? value : ["topside"];
79
+ } catch (e) {
80
+ return ["topside"];
81
+ }
82
+ }
83
+
84
+ // A host whose surface holds the keyboard sets this: jump() then only
85
+ // asks (jumpAsked) and the host lets the keyboard go before it calls
86
+ // jumpNow(). Focusing the terminal while a surface still held the keys
87
+ // lost: the compositor gave the focus back to the window from before once
88
+ // the surface let go.
89
+ property bool askBeforeJump: false
90
+ signal jumpAsked(string sessionId)
91
+
92
+ function jump(sessionId) {
93
+ // A jump still running wins: asking now would close the host's windows
94
+ // for a jump that jumpNow() then drops.
95
+ if (jumper.running) return;
96
+ if (askBeforeJump) {
97
+ jumpAsked(sessionId);
98
+ return;
99
+ }
100
+ jumpNow(sessionId);
101
+ }
102
+ function jumpNow(sessionId) {
103
+ if (jumper.running) return;
104
+ client.jumpError = "";
105
+ jumper.didStart = false;
106
+ jumper.command = client.cli.concat(["jump", sessionId]);
107
+ jumper.running = true;
108
+ }
109
+
110
+ // answers: question text → chosen label(s), as AskUserQuestion expects.
111
+ function answer(questionId, answers) {
112
+ send({ op: "answer", questionId: questionId, answers: answers });
113
+ }
114
+
115
+ function send(message) {
116
+ if (!sock.connected) return;
117
+ sock.write(JSON.stringify(message) + "\n");
118
+ sock.flush();
119
+ }
120
+
121
+ function decide(approvalId, decision) {
122
+ if (!sock.connected) return;
123
+ sock.write(JSON.stringify({ op: "decide", approvalId: approvalId, decision: decision }) + "\n");
124
+ sock.flush();
125
+ }
126
+
127
+ Socket {
128
+ id: sock
129
+ path: client.socketPath
130
+ connected: true
131
+ parser: SplitParser {
132
+ splitMarker: "\n"
133
+ onRead: data => {
134
+ let msg;
135
+ try {
136
+ msg = JSON.parse(data);
137
+ } catch (e) {
138
+ return;
139
+ }
140
+ if (msg.op === "snapshot") {
141
+ client.allSessions = msg.snapshot.sessions.filter(s => s.status !== "ended");
142
+ client.allApprovals = msg.snapshot.approvals;
143
+ client.allQuestions = msg.snapshot.questions || [];
144
+ client.usage = msg.snapshot.usage || {};
145
+ client.spend = msg.snapshot.spend || {};
146
+ client.notice(client.sessions);
147
+ client.noticeRequests();
148
+ if (msg.snapshot.cue && !client.hiddenIds[msg.snapshot.cueSession]) client.cue(msg.snapshot.cue);
149
+ }
150
+ }
151
+ }
152
+ onConnectionStateChanged: {
153
+ if (connected) {
154
+ write('{"op":"subscribe"}\n');
155
+ flush();
156
+ } else {
157
+ client.allSessions = [];
158
+ client.allApprovals = [];
159
+ client.allQuestions = [];
160
+ client.wasDone = null;
161
+ retry.start();
162
+ }
163
+ }
164
+ onError: retry.start()
165
+ }
166
+
167
+ Process {
168
+ id: jumper
169
+ // A command that can't start never emits exited(), only running = false.
170
+ property bool didStart: false
171
+ stderr: StdioCollector { id: jumpStderr }
172
+ onStarted: didStart = true
173
+ onRunningChanged: {
174
+ if (!running && !didStart) {
175
+ client.jumpError = "Can't run " + client.cli[0] + ". Install Topside, or rerun topside setup.";
176
+ clearError.restart();
177
+ }
178
+ }
179
+ onExited: exitCode => {
180
+ if (exitCode === 0) {
181
+ client.jumped();
182
+ } else {
183
+ client.jumpError = jumpStderr.text.trim() || "topside jump failed";
184
+ clearError.restart();
185
+ }
186
+ }
187
+ }
188
+
189
+ Timer {
190
+ id: clearError
191
+ interval: 8000
192
+ onTriggered: client.jumpError = ""
193
+ }
194
+
195
+ Timer {
196
+ id: retry
197
+ interval: 2000
198
+ repeat: false
199
+ onTriggered: sock.connected = true
200
+ }
201
+ }
@@ -0,0 +1,106 @@
1
+ import QtQuick
2
+
3
+ // Plan usage as Topside's header shows it: "5h 39% 3h41m │ 7d 61% 4d5h".
4
+ // The percent is green below 50, orange from 50, red from 80. A window
5
+ // whose reset time has passed is left out, as Claude Code drops it too.
6
+ // With `agent` set, the agent's mark leads, since each agent has its own plan.
7
+ // Agents billed by the token (pi, omp) have no plan windows: with `spend`
8
+ // set, the line reads "$0.42 · 182k tokens" for that session instead.
9
+ Row {
10
+ id: line
11
+ property var usage: null
12
+ property var spend: null
13
+ property string agent: ""
14
+
15
+ readonly property string spendText: {
16
+ if (!spend) return "";
17
+ const parts = [];
18
+ if (spend.cost > 0) parts.push(spend.cost < 0.01 ? "<$0.01" : "$" + spend.cost.toFixed(2));
19
+ if (spend.tokens > 0) {
20
+ const t = spend.tokens;
21
+ parts.push((t >= 1000000 ? (t / 1000000).toFixed(1) + "M" : t >= 1000 ? Math.floor(t / 1000) + "k" : t) + " tokens");
22
+ }
23
+ return parts.join(" · ");
24
+ }
25
+ property real now: Date.now() / 1000
26
+
27
+ readonly property var windows: [
28
+ { label: "5h", window: usage ? usage.fiveHour : undefined },
29
+ { label: "7d", window: usage ? usage.sevenDay : undefined },
30
+ ].filter(w => w.window && w.window.resetsAt > now)
31
+ readonly property bool empty: windows.length === 0 && spendText === ""
32
+
33
+ // Time until reset: "4d5h", "3h41m", "12m", "<1m".
34
+ function remaining(resetsAt) {
35
+ const minutes = Math.floor(Math.max(0, resetsAt - now) / 60);
36
+ if (minutes < 1) return "<1m";
37
+ if (minutes < 60) return minutes + "m";
38
+ const hours = Math.floor(minutes / 60);
39
+ if (hours < 24) return hours + "h" + (minutes % 60) + "m";
40
+ return Math.floor(hours / 24) + "d" + (hours % 24) + "h";
41
+ }
42
+
43
+ function level(percent) {
44
+ return percent >= 80 ? Theme.reminder : percent >= 50 ? Theme.waiting : Theme.done;
45
+ }
46
+
47
+ spacing: 6
48
+
49
+ Timer {
50
+ interval: 30000
51
+ running: !line.empty
52
+ repeat: true
53
+ onTriggered: line.now = Date.now() / 1000
54
+ }
55
+
56
+ AgentIcon {
57
+ visible: line.agent !== ""
58
+ agent: line.agent || "claude"
59
+ size: Theme.content + 3
60
+ anchors.verticalCenter: parent.verticalCenter
61
+ }
62
+
63
+ Text {
64
+ visible: line.spendText !== ""
65
+ text: line.spendText
66
+ color: Theme.fgDim
67
+ font.family: Theme.monoFont
68
+ font.pixelSize: Theme.content
69
+ anchors.verticalCenter: parent.verticalCenter
70
+ }
71
+
72
+ Repeater {
73
+ model: line.spendText !== "" ? [] : line.windows
74
+ delegate: Row {
75
+ required property var modelData
76
+ required property int index
77
+ spacing: 6
78
+ Text {
79
+ visible: parent.index > 0
80
+ text: "│"
81
+ color: Theme.stroke
82
+ font.family: Theme.monoFont
83
+ font.pixelSize: Theme.content
84
+ }
85
+ Text {
86
+ text: parent.modelData.label
87
+ color: Theme.fgFaint
88
+ font.family: Theme.monoFont
89
+ font.pixelSize: Theme.content
90
+ }
91
+ Text {
92
+ text: Math.round(parent.modelData.window.usedPercentage) + "%"
93
+ color: line.level(parent.modelData.window.usedPercentage)
94
+ font.family: Theme.monoFont
95
+ font.pixelSize: Theme.content
96
+ font.weight: Font.Bold
97
+ }
98
+ Text {
99
+ text: line.remaining(parent.modelData.window.resetsAt)
100
+ color: Theme.fgDim
101
+ font.family: Theme.monoFont
102
+ font.pixelSize: Theme.content
103
+ }
104
+ }
105
+ }
106
+ }
@@ -0,0 +1,79 @@
1
+ .pragma library
2
+
3
+ .import "pixels.js" as Pixels
4
+
5
+ // How each agent looks: its name, its mark, its color and its logo as pixels
6
+ // on a 12 by 12 grid, from the shared pixel file (pixels.js, VIA-PARITY
7
+ // section 24). The logos belong to their owners and only say which agent is
8
+ // running.
9
+ var styles = {};
10
+ (function () {
11
+ for (var id in Pixels.data.agents) {
12
+ var agent = Pixels.data.agents[id];
13
+ // Linux fonts draw "*" small and high in the square; "✱" fills it as the
14
+ // Mac's mark does.
15
+ styles[id] = { name: agent.name, mark: agent.mark === "*" ? "✱" : agent.mark, tint: agent.tint.toLowerCase(), mascot: agent.logo };
16
+ }
17
+ })();
18
+
19
+ // An unknown agent borrows Claude's look.
20
+ function style(agent) {
21
+ return styles[agent] || styles.claude;
22
+ }
23
+
24
+ // Topside's logotype: the letters (5 by 7), the dots and their sizes in cells.
25
+ var logotype = Pixels.data.logotype;
26
+ var glyphs = logotype.glyphs;
27
+
28
+ // The effect beside a mascot (VIA-PARITY section 24, "The effect"): which
29
+ // glyph, where in its box (cells from the top left) and how opaque, for a
30
+ // state at `time` seconds. A state without a look of its own ("ended") reads
31
+ // as idle.
32
+ var motion = Pixels.data.motion;
33
+
34
+ // The corner (0 top left, 1 top right, 2 bottom left, 3 bottom right) of
35
+ // trip `n`. The spec multiplies n, as an unsigned 64-bit number, by
36
+ // 2654435761 and keeps bits 13 and 14; those depend only on the low 15 bits
37
+ // of both numbers, so plain numbers do it without BigInt.
38
+ function scatter(n) {
39
+ return ((((n & 0x7fff) * (2654435761 % 32768)) % 32768) >> 13) % 4;
40
+ }
41
+ function corner(n) {
42
+ var c = scatter(n);
43
+ return c === scatter(n - 1) ? (c + 1 + (n % 3)) % 4 : c;
44
+ }
45
+
46
+ function effectFrame(status, time) {
47
+ var look = motion.looks[status] || motion.looks.idle;
48
+ var period = look.period || 0;
49
+ var phase = period > 0 ? (time % period) / period : 0;
50
+ var start = look.start || [0, 0];
51
+ var end = look.end || [0, 0];
52
+ var x = start[0] + (end[0] - start[0]) * phase;
53
+ var y = start[1] + (end[1] - start[1]) * phase;
54
+ var opacity = period > 0 ? Math.min(1, phase / motion.fadeIn, (1 - phase) / motion.fadeOut) : 1;
55
+ if (look.cornerStep) {
56
+ var c = corner(Math.floor(time / period));
57
+ if (c % 2 === 1) x += look.cornerStep;
58
+ if (Math.floor(c / 2) === 1) y += look.cornerStep;
59
+ }
60
+ if (look.blinkEvery && Math.floor(time / look.blinkEvery) % 2 === 1) opacity *= motion.dim;
61
+ var name = look.youngGlyph && phase < look.youngUntil ? look.youngGlyph : look.glyph;
62
+ return { pixels: motion.glyphs[name], x: x, y: y, opacity: opacity };
63
+ }
64
+
65
+ // Terminal names, and their desktop entry where one is usual on Linux.
66
+ var terminals = {
67
+ WezTerm: { name: "WezTerm", desktop: "org.wezfurlong.wezterm" },
68
+ Orca: { name: "Orca", desktop: "orca-ide" },
69
+ ghostty: { name: "Ghostty", desktop: "com.mitchellh.ghostty" },
70
+ kitty: { name: "kitty", desktop: "kitty" },
71
+ Alacritty: { name: "Alacritty", desktop: "Alacritty" },
72
+ foot: { name: "foot", desktop: "foot" },
73
+ vscode: { name: "VS Code", desktop: "code" },
74
+ tmux: { name: "tmux", desktop: "" },
75
+ };
76
+
77
+ function terminal(program) {
78
+ return terminals[program] || { name: program, desktop: "" };
79
+ }