sideby 0.32.1 → 0.33.0
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/assets/brand/sai-painted-1024.png +0 -0
- package/assets/brand/sai-painted-128.png +0 -0
- package/assets/brand/sai-painted-256.png +0 -0
- package/assets/brand/sai-painted-64.png +0 -0
- package/dist/build.json +1 -1
- package/dist/src/cli/commands.js +57 -14
- package/dist/src/cli/format.js +3 -1
- package/dist/src/cli/json-schemas.js +30 -5
- package/dist/src/cli/main.js +9 -4
- package/dist/src/core/brand-mark.d.ts +18 -115
- package/dist/src/core/brand-mark.js +43 -174
- package/dist/src/core/messages.d.ts +17 -5
- package/dist/src/core/messages.js +38 -15
- package/dist/src/core/quota-fetch.js +9 -2
- package/dist/src/desktop/icon.d.ts +13 -1
- package/dist/src/desktop/icon.js +153 -285
- package/dist/src/families/claude/deliver.js +9 -1
- package/dist/src/families/claude/messaging.d.ts +7 -1
- package/dist/src/families/claude/messaging.js +10 -2
- package/dist/src/families/codex/deliver.d.ts +10 -1
- package/dist/src/families/codex/deliver.js +24 -2
- package/dist/src/families/messaging.d.ts +6 -1
- package/dist/src/menubar/script.d.ts +5 -0
- package/dist/src/menubar/script.js +111 -25
- package/dist/src/menubar/snapshot.d.ts +29 -8
- package/dist/src/menubar/snapshot.js +132 -31
- package/dist/src/menubar/strings.d.ts +22 -6
- package/dist/src/menubar/strings.js +22 -6
- package/dist/src/panel/handler.d.ts +2 -2
- package/dist/src/panel/handler.js +8 -2
- package/dist/src/panel/i18n.d.ts +5 -0
- package/dist/src/panel/i18n.js +14 -4
- package/dist/src/panel/page-logic.d.ts +25 -4
- package/dist/src/panel/page-logic.js +122 -10
- package/dist/src/panel/page-script.js +39 -8
- package/dist/src/panel/page-styles.js +5 -5
- package/dist/src/panel/page.js +2 -2
- package/dist/src/panel/theme.d.ts +4 -1
- package/dist/src/runtime.d.ts +3 -1
- package/dist/src/runtime.js +1 -1
- package/package.json +2 -1
- package/schemas/menubar-snapshot.json +102 -2
- package/schemas/messages.json +6 -2
- package/schemas/send.json +6 -2
- package/skills/sideby/SKILL.md +1 -1
- package/skills/sideby/references/panel.md +1 -1
- package/skills/sideby/references/sessions.md +6 -3
package/dist/src/desktop/icon.js
CHANGED
|
@@ -1,309 +1,178 @@
|
|
|
1
|
-
// The sideby
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
import { buddyShapes, MARK, MARK_COLORS, MARK_VIEWBOX, markSvgBody, } from '../core/brand-mark.js';
|
|
1
|
+
// The sideby app icon without dependencies: the painted mark of core/brand-mark.ts (ADR-0064) on a light rounded
|
|
2
|
+
// tile, composited in pure Node and encoded as PNG, SVG or ICNS. The painting is decoded from its PNG, scaled with an
|
|
3
|
+
// exact area average (each output pixel is the mean of the source area it covers, in premultiplied alpha) and laid
|
|
4
|
+
// over the antialiased tile, as the Panel header lays it over its 40 px tile.
|
|
5
|
+
import { deflateSync, inflateSync } from 'node:zlib';
|
|
6
|
+
import { MARK_INSET, MARK_SIZES, MARK_TILE, markDataUri, markPng } from '../core/brand-mark.js';
|
|
8
7
|
/** Text stored in every generated file, so `sideby app uninstall` deletes only what it wrote. */
|
|
9
8
|
export const APP_MARKER = 'sideby-app-install';
|
|
10
|
-
// The Panel's logo tile (page-styles.ts: .logo 40×40, radius 10)
|
|
11
|
-
const TILE = { size: 40, radius: 10
|
|
9
|
+
// The Panel's logo tile (page-styles.ts: .logo 40×40, radius 10).
|
|
10
|
+
const TILE = { size: 40, radius: 10 };
|
|
12
11
|
// The tile sits on the macOS icon grid: 824 of 1024 units, centred.
|
|
13
12
|
const GRID = { canvas: 1024, tile: 824 };
|
|
14
|
-
|
|
15
|
-
const SUB_ROWS = 16;
|
|
16
|
-
const rgb = (hex) => [1, 3, 5].map((i) => Number.parseInt(hex.slice(i, i + 2), 16));
|
|
13
|
+
const TILE_RGB = [1, 3, 5].map((i) => Number.parseInt(MARK_TILE.slice(i, i + 2), 16));
|
|
17
14
|
function tileRect(size) {
|
|
18
15
|
const w = (size * GRID.tile) / GRID.canvas;
|
|
19
16
|
const off = (size - w) / 2;
|
|
20
17
|
return { x: off, y: off, w, h: w, r: (TILE.radius * w) / TILE.size };
|
|
21
18
|
}
|
|
22
|
-
/**
|
|
23
|
-
function
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
return {
|
|
28
|
-
k,
|
|
29
|
-
map: (gx, gy) => [
|
|
30
|
-
tile.x + (b.x + b.scale * gx - MARK_VIEWBOX.x) * u,
|
|
31
|
-
tile.y + (b.y + b.scale * gy - MARK_VIEWBOX.y) * u,
|
|
32
|
-
],
|
|
33
|
-
};
|
|
19
|
+
/** Where the painting goes on a `size` canvas: inset from the tile's edge as in the Panel header. */
|
|
20
|
+
export function markRect(size) {
|
|
21
|
+
const t = tileRect(size);
|
|
22
|
+
const inset = t.w * MARK_INSET;
|
|
23
|
+
return { x: t.x + inset, y: t.y + inset, w: t.w - 2 * inset };
|
|
34
24
|
}
|
|
35
|
-
/**
|
|
36
|
-
function
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
let
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
gx = x;
|
|
48
|
-
gy = y;
|
|
49
|
-
cur.pts.push(map(x, y));
|
|
50
|
-
};
|
|
51
|
-
const curve = (ctrl, end) => {
|
|
52
|
-
const all = [map(gx, gy), ...ctrl.map(([x, y]) => map(x, y)), map(end[0], end[1])];
|
|
53
|
-
let len = 0;
|
|
54
|
-
for (let j = 1; j < all.length; j++)
|
|
55
|
-
len += Math.hypot(all[j][0] - all[j - 1][0], all[j][1] - all[j - 1][1]);
|
|
56
|
-
const n = Math.max(4, Math.ceil(len / 2));
|
|
57
|
-
for (let s = 1; s <= n; s++) {
|
|
58
|
-
const t = s / n;
|
|
59
|
-
// De Casteljau on the pixel control points.
|
|
60
|
-
let p = all.map((q) => [q[0], q[1]]);
|
|
61
|
-
while (p.length > 1)
|
|
62
|
-
p = p.slice(1).map((q, j) => [p[j][0] + (q[0] - p[j][0]) * t, p[j][1] + (q[1] - p[j][1]) * t]);
|
|
63
|
-
cur.pts.push([p[0][0], p[0][1]]);
|
|
64
|
-
}
|
|
65
|
-
gx = end[0];
|
|
66
|
-
gy = end[1];
|
|
67
|
-
};
|
|
68
|
-
let cmd = '';
|
|
69
|
-
while (i < tokens.length) {
|
|
70
|
-
if (!isNum())
|
|
71
|
-
cmd = tokens[i++].toUpperCase();
|
|
72
|
-
switch (cmd) {
|
|
73
|
-
case 'M':
|
|
74
|
-
gx = num();
|
|
75
|
-
gy = num();
|
|
76
|
-
start = [gx, gy];
|
|
77
|
-
cur = { pts: [map(gx, gy)], closed: false };
|
|
78
|
-
polys.push(cur);
|
|
79
|
-
cmd = 'L'; // further pairs after M are lines
|
|
80
|
-
break;
|
|
81
|
-
case 'L':
|
|
82
|
-
lineTo(num(), num());
|
|
83
|
-
break;
|
|
84
|
-
case 'H':
|
|
85
|
-
lineTo(num(), gy);
|
|
86
|
-
break;
|
|
87
|
-
case 'Q': {
|
|
88
|
-
const c = [num(), num()];
|
|
89
|
-
curve([c], [num(), num()]);
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
case 'C': {
|
|
93
|
-
const c1 = [num(), num()];
|
|
94
|
-
const c2 = [num(), num()];
|
|
95
|
-
curve([c1, c2], [num(), num()]);
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
case 'Z':
|
|
99
|
-
cur.closed = true;
|
|
100
|
-
gx = start[0];
|
|
101
|
-
gy = start[1];
|
|
102
|
-
break;
|
|
103
|
-
default:
|
|
104
|
-
throw new Error(`icon: unsupported path command ${cmd}`);
|
|
25
|
+
/** Coverage (0..1) of the tile's rounded rectangle at each pixel, from its signed distance. */
|
|
26
|
+
function tileCoverage(size) {
|
|
27
|
+
const s = tileRect(size);
|
|
28
|
+
const a = new Float32Array(size * size);
|
|
29
|
+
const hx = s.w / 2;
|
|
30
|
+
const hy = s.h / 2;
|
|
31
|
+
for (let py = 0; py < size; py++)
|
|
32
|
+
for (let px = 0; px < size; px++) {
|
|
33
|
+
const qx = Math.abs(px + 0.5 - (s.x + hx)) - (hx - s.r);
|
|
34
|
+
const qy = Math.abs(py + 0.5 - (s.y + hy)) - (hy - s.r);
|
|
35
|
+
const d = Math.hypot(Math.max(qx, 0), Math.max(qy, 0)) + Math.min(Math.max(qx, qy), 0) - s.r;
|
|
36
|
+
a[py * size + px] = Math.min(1, Math.max(0, 0.5 - d));
|
|
105
37
|
}
|
|
106
|
-
|
|
107
|
-
return polys;
|
|
38
|
+
return a;
|
|
108
39
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const p = pts[j];
|
|
130
|
-
const q = pts[(j + 1) % pts.length];
|
|
131
|
-
if (p[1] !== q[1])
|
|
132
|
-
edges.push([p[0], p[1], q[0], q[1]]);
|
|
133
|
-
x0 = Math.min(x0, p[0]);
|
|
134
|
-
y0 = Math.min(y0, p[1]);
|
|
135
|
-
x1 = Math.max(x1, p[0]);
|
|
136
|
-
y1 = Math.max(y1, p[1]);
|
|
40
|
+
/** Decodes an 8-bit, non-interlaced RGB or RGBA PNG to straight-alpha RGBA pixels. */
|
|
41
|
+
export function decodePng(png) {
|
|
42
|
+
if (png.readUInt32BE(0) !== 0x89504e47)
|
|
43
|
+
throw new Error('icon: not a PNG');
|
|
44
|
+
let off = 8;
|
|
45
|
+
let width = 0;
|
|
46
|
+
let height = 0;
|
|
47
|
+
let channels = 0;
|
|
48
|
+
const idat = [];
|
|
49
|
+
while (off < png.length) {
|
|
50
|
+
const len = png.readUInt32BE(off);
|
|
51
|
+
const type = png.toString('latin1', off + 4, off + 8);
|
|
52
|
+
const data = png.subarray(off + 8, off + 8 + len);
|
|
53
|
+
if (type === 'IHDR') {
|
|
54
|
+
width = data.readUInt32BE(0);
|
|
55
|
+
height = data.readUInt32BE(4);
|
|
56
|
+
const [depth, color, , , interlace] = data.subarray(8, 13);
|
|
57
|
+
channels = color === 6 ? 4 : color === 2 ? 3 : 0;
|
|
58
|
+
if (depth !== 8 || !channels || interlace !== 0)
|
|
59
|
+
throw new Error('icon: unsupported PNG format');
|
|
137
60
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
61
|
+
if (type === 'IDAT')
|
|
62
|
+
idat.push(data);
|
|
63
|
+
off += 12 + len;
|
|
64
|
+
}
|
|
65
|
+
const raw = inflateSync(Buffer.concat(idat));
|
|
66
|
+
const stride = width * channels;
|
|
67
|
+
const cur = new Uint8Array(stride);
|
|
68
|
+
let prev = new Uint8Array(stride);
|
|
69
|
+
const rgba = new Uint8Array(width * height * 4);
|
|
70
|
+
for (let y = 0; y < height; y++) {
|
|
71
|
+
const base = y * (stride + 1);
|
|
72
|
+
const filter = raw[base];
|
|
73
|
+
for (let i = 0; i < stride; i++) {
|
|
74
|
+
const x = raw[base + 1 + i];
|
|
75
|
+
const a = i >= channels ? cur[i - channels] : 0;
|
|
76
|
+
const b = prev[i];
|
|
77
|
+
const c = i >= channels ? prev[i - channels] : 0;
|
|
78
|
+
let v = x;
|
|
79
|
+
if (filter === 1)
|
|
80
|
+
v = x + a;
|
|
81
|
+
else if (filter === 2)
|
|
82
|
+
v = x + b;
|
|
83
|
+
else if (filter === 3)
|
|
84
|
+
v = x + ((a + b) >> 1);
|
|
85
|
+
else if (filter === 4) {
|
|
86
|
+
const p = a + b - c;
|
|
87
|
+
const pa = Math.abs(p - a);
|
|
88
|
+
const pb = Math.abs(p - b);
|
|
89
|
+
const pc = Math.abs(p - c);
|
|
90
|
+
v = x + (pa <= pb && pa <= pc ? a : pb <= pc ? b : c);
|
|
166
91
|
}
|
|
92
|
+
cur[i] = v & 0xff;
|
|
167
93
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
let x0 = Infinity;
|
|
175
|
-
let y0 = Infinity;
|
|
176
|
-
let x1 = -Infinity;
|
|
177
|
-
let y1 = -Infinity;
|
|
178
|
-
for (const { pts, closed } of polys) {
|
|
179
|
-
const n = closed ? pts.length : pts.length - 1;
|
|
180
|
-
for (let j = 0; j < Math.max(n, 1); j++) {
|
|
181
|
-
const p = pts[j];
|
|
182
|
-
const q = pts[(j + 1) % pts.length] ?? p;
|
|
183
|
-
segs.push([p[0], p[1], q[0], q[1]]);
|
|
184
|
-
x0 = Math.min(x0, p[0], q[0]);
|
|
185
|
-
y0 = Math.min(y0, p[1], q[1]);
|
|
186
|
-
x1 = Math.max(x1, p[0], q[0]);
|
|
187
|
-
y1 = Math.max(y1, p[1], q[1]);
|
|
94
|
+
for (let x = 0; x < width; x++) {
|
|
95
|
+
const o = (y * width + x) * 4;
|
|
96
|
+
rgba[o] = cur[x * channels];
|
|
97
|
+
rgba[o + 1] = cur[x * channels + 1];
|
|
98
|
+
rgba[o + 2] = cur[x * channels + 2];
|
|
99
|
+
rgba[o + 3] = channels === 4 ? cur[x * channels + 3] : 255;
|
|
188
100
|
}
|
|
101
|
+
prev = Uint8Array.from(cur);
|
|
189
102
|
}
|
|
190
|
-
|
|
191
|
-
if (!m)
|
|
192
|
-
return null;
|
|
193
|
-
const dist = new Float32Array(m.w * m.h).fill(Infinity);
|
|
194
|
-
for (const [ax, ay, bx, by] of segs) {
|
|
195
|
-
const dx = bx - ax;
|
|
196
|
-
const dy = by - ay;
|
|
197
|
-
const len2 = dx * dx + dy * dy;
|
|
198
|
-
const sx0 = Math.max(m.x0, Math.floor(Math.min(ax, bx) - r - 1));
|
|
199
|
-
const sx1 = Math.min(m.x0 + m.w, Math.ceil(Math.max(ax, bx) + r + 1));
|
|
200
|
-
const sy0 = Math.max(m.y0, Math.floor(Math.min(ay, by) - r - 1));
|
|
201
|
-
const sy1 = Math.min(m.y0 + m.h, Math.ceil(Math.max(ay, by) + r + 1));
|
|
202
|
-
for (let py = sy0; py < sy1; py++)
|
|
203
|
-
for (let px = sx0; px < sx1; px++) {
|
|
204
|
-
const cx = px + 0.5 - ax;
|
|
205
|
-
const cy = py + 0.5 - ay;
|
|
206
|
-
const t = len2 === 0 ? 0 : Math.min(1, Math.max(0, (cx * dx + cy * dy) / len2));
|
|
207
|
-
const d = Math.hypot(cx - t * dx, cy - t * dy);
|
|
208
|
-
const i = (py - m.y0) * m.w + px - m.x0;
|
|
209
|
-
if (d < dist[i])
|
|
210
|
-
dist[i] = d;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
for (let i = 0; i < dist.length; i++)
|
|
214
|
-
m.a[i] = Math.min(1, Math.max(0, r + 0.5 - dist[i]));
|
|
215
|
-
return m;
|
|
216
|
-
}
|
|
217
|
-
/** Filled ellipse with an approximate signed distance (exact on the axes, good near the edge). */
|
|
218
|
-
function ellipseMask(size, cx, cy, rx, ry) {
|
|
219
|
-
const m = box(size, cx - rx - 1, cy - ry - 1, cx + rx + 1, cy + ry + 1);
|
|
220
|
-
if (!m)
|
|
221
|
-
return null;
|
|
222
|
-
for (let py = 0; py < m.h; py++)
|
|
223
|
-
for (let px = 0; px < m.w; px++) {
|
|
224
|
-
const x = m.x0 + px + 0.5 - cx;
|
|
225
|
-
const y = m.y0 + py + 0.5 - cy;
|
|
226
|
-
const k0 = Math.hypot(x / rx, y / ry);
|
|
227
|
-
const k1 = Math.hypot(x / (rx * rx), y / (ry * ry));
|
|
228
|
-
const d = k1 === 0 ? -Math.min(rx, ry) : (k0 * (k0 - 1)) / k1;
|
|
229
|
-
m.a[py * m.w + px] = Math.min(1, Math.max(0, 0.5 - d));
|
|
230
|
-
}
|
|
231
|
-
return m;
|
|
103
|
+
return { width, height, rgba };
|
|
232
104
|
}
|
|
233
|
-
/**
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
const
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
const
|
|
245
|
-
|
|
105
|
+
/**
|
|
106
|
+
* For each of `n` output pixels, the source pixels it covers and how much of each, when a `src`-pixel line is laid
|
|
107
|
+
* from `from` to `from + span` on the output line.
|
|
108
|
+
*/
|
|
109
|
+
function areaWeights(n, src, from, span) {
|
|
110
|
+
const k = src / span;
|
|
111
|
+
return Array.from({ length: n }, (_, i) => {
|
|
112
|
+
const s0 = Math.max(0, (i - from) * k);
|
|
113
|
+
const s1 = Math.min(src, (i + 1 - from) * k);
|
|
114
|
+
const out = [];
|
|
115
|
+
for (let j = Math.floor(s0); j < s1; j++) {
|
|
116
|
+
const w = Math.min(j + 1, s1) - Math.max(j, s0);
|
|
117
|
+
if (w > 0)
|
|
118
|
+
out.push({ j, w: w / k });
|
|
246
119
|
}
|
|
247
|
-
|
|
120
|
+
return out;
|
|
121
|
+
});
|
|
248
122
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
const
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
layers.push({ mask: fillMask(size, polys), color: rgb(s.fill) });
|
|
258
|
-
if (s.stroke !== 'none')
|
|
259
|
-
layers.push({ mask: strokeMask(size, polys, (s.width ?? MARK.placedLine) * k), color: rgb(s.stroke) });
|
|
260
|
-
};
|
|
261
|
-
paths.forEach(shape);
|
|
262
|
-
for (const e of dots) {
|
|
263
|
-
const [cx, cy] = map(e.cx, e.cy);
|
|
264
|
-
layers.push({
|
|
265
|
-
mask: ellipseMask(size, cx, cy, e.rx * k, e.ry * k),
|
|
266
|
-
color: rgb(e.fill === 'ink' ? MARK_COLORS.ink : MARK_COLORS.light),
|
|
267
|
-
});
|
|
123
|
+
const decoded = new Map();
|
|
124
|
+
/** The smallest painting at least as large as `px`, decoded once. */
|
|
125
|
+
function painting(px) {
|
|
126
|
+
const size = MARK_SIZES.find((s) => s >= px) ?? MARK_SIZES[MARK_SIZES.length - 1];
|
|
127
|
+
let d = decoded.get(size);
|
|
128
|
+
if (!d) {
|
|
129
|
+
d = decodePng(markPng(size));
|
|
130
|
+
decoded.set(size, d);
|
|
268
131
|
}
|
|
269
|
-
|
|
270
|
-
return layers;
|
|
132
|
+
return d;
|
|
271
133
|
}
|
|
272
134
|
/** RGBA pixels (straight alpha) of the icon at `size`×`size`. */
|
|
273
135
|
export function renderIcon(size) {
|
|
274
|
-
const
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
for (let x = 0; x < m.w; x++) {
|
|
287
|
-
const la = Math.min(1, m.a[y * m.w + x]);
|
|
288
|
-
if (la <= 0)
|
|
289
|
-
continue;
|
|
290
|
-
const i = ((m.y0 + y) * size + m.x0 + x) * 4;
|
|
291
|
-
acc[i] = cr * la + acc[i] * (1 - la);
|
|
292
|
-
acc[i + 1] = cg * la + acc[i + 1] * (1 - la);
|
|
293
|
-
acc[i + 2] = cb * la + acc[i + 2] * (1 - la);
|
|
294
|
-
acc[i + 3] = la + acc[i + 3] * (1 - la);
|
|
295
|
-
}
|
|
136
|
+
const r = markRect(size);
|
|
137
|
+
const src = painting(r.w);
|
|
138
|
+
// Premultiplied source, then an area average across, then down.
|
|
139
|
+
const sw = src.width;
|
|
140
|
+
const sh = src.height;
|
|
141
|
+
const pre = new Float32Array(sw * sh * 4);
|
|
142
|
+
for (let i = 0; i < sw * sh; i++) {
|
|
143
|
+
const a = src.rgba[i * 4 + 3] / 255;
|
|
144
|
+
pre[i * 4] = (src.rgba[i * 4] / 255) * a;
|
|
145
|
+
pre[i * 4 + 1] = (src.rgba[i * 4 + 1] / 255) * a;
|
|
146
|
+
pre[i * 4 + 2] = (src.rgba[i * 4 + 2] / 255) * a;
|
|
147
|
+
pre[i * 4 + 3] = a;
|
|
296
148
|
}
|
|
149
|
+
const wx = areaWeights(size, sw, r.x, r.w);
|
|
150
|
+
const wy = areaWeights(size, sh, r.y, r.w);
|
|
151
|
+
const across = new Float32Array(size * sh * 4);
|
|
152
|
+
for (let y = 0; y < sh; y++)
|
|
153
|
+
for (let x = 0; x < size; x++)
|
|
154
|
+
for (const { j, w } of wx[x])
|
|
155
|
+
for (let c = 0; c < 4; c++)
|
|
156
|
+
across[(y * size + x) * 4 + c] += pre[(y * sw + j) * 4 + c] * w;
|
|
157
|
+
const tile = tileCoverage(size);
|
|
297
158
|
const px = new Uint8Array(size * size * 4);
|
|
298
|
-
for (let
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
159
|
+
for (let y = 0; y < size; y++)
|
|
160
|
+
for (let x = 0; x < size; x++) {
|
|
161
|
+
const m = [0, 0, 0, 0];
|
|
162
|
+
for (const { j, w } of wy[y])
|
|
163
|
+
for (let c = 0; c < 4; c++)
|
|
164
|
+
m[c] += across[(j * size + x) * 4 + c] * w;
|
|
165
|
+
// The painting over the tile, both premultiplied.
|
|
166
|
+
const ta = tile[y * size + x];
|
|
167
|
+
const ma = Math.min(1, m[3]);
|
|
168
|
+
const a = ma + ta * (1 - ma);
|
|
169
|
+
if (a <= 0)
|
|
170
|
+
continue;
|
|
171
|
+
const o = (y * size + x) * 4;
|
|
172
|
+
for (let c = 0; c < 3; c++)
|
|
173
|
+
px[o + c] = Math.min(255, Math.round(((m[c] + (TILE_RGB[c] / 255) * ta * (1 - ma)) / a) * 255));
|
|
174
|
+
px[o + 3] = Math.min(255, Math.round(a * 255));
|
|
175
|
+
}
|
|
307
176
|
return px;
|
|
308
177
|
}
|
|
309
178
|
const CRC_TABLE = (() => {
|
|
@@ -386,16 +255,15 @@ export function encodeIcns(pngs) {
|
|
|
386
255
|
head.writeUInt32BE(body.length + 8, 4);
|
|
387
256
|
return Buffer.concat([head, body]);
|
|
388
257
|
}
|
|
389
|
-
/** The same
|
|
258
|
+
/** The same icon as an SVG (1024-unit canvas), for Linux icon themes: the tile, and the painting as a `data:` image. */
|
|
390
259
|
export function iconSvg() {
|
|
391
260
|
const tile = tileRect(GRID.canvas);
|
|
392
|
-
const
|
|
393
|
-
const V = MARK_VIEWBOX;
|
|
261
|
+
const r = markRect(GRID.canvas);
|
|
394
262
|
return [
|
|
395
263
|
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${GRID.canvas} ${GRID.canvas}" width="${GRID.canvas}" height="${GRID.canvas}">`,
|
|
396
264
|
` <!-- ${APP_MARKER} -->`,
|
|
397
|
-
` <rect x="${tile.x}" y="${tile.y}" width="${tile.w}" height="${tile.h}" rx="${tile.r}" fill="${
|
|
398
|
-
` <
|
|
265
|
+
` <rect x="${tile.x}" y="${tile.y}" width="${tile.w}" height="${tile.h}" rx="${tile.r}" fill="${MARK_TILE}"/>`,
|
|
266
|
+
` <image x="${r.x}" y="${r.y}" width="${r.w}" height="${r.w}" href="${markDataUri(1024)}"/>`,
|
|
399
267
|
'</svg>',
|
|
400
268
|
'',
|
|
401
269
|
].join('\n');
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// back as a paste with the reason; nothing here reads a key file or a token.
|
|
4
4
|
import { inboundGroups } from '../../core/inbound.js';
|
|
5
5
|
import { hostArgs } from '../../core/live-sessions-procs.js';
|
|
6
|
-
import { checkSocket, claudeSocketOf, DELIVER_TIMEOUT_MS, messageLine, sessionBypass, socketChanged, socketRoots, writeToSocket, } from './messaging.js';
|
|
6
|
+
import { checkSocket, claudeSocketOf, DELIVER_TIMEOUT_MS, messageLine, sessionBypass, socketChanged, socketRoots, UnconfirmedWrite, writeToSocket, } from './messaging.js';
|
|
7
7
|
export async function deliverClaude(req) {
|
|
8
8
|
const { rt, to, acct, pid, procs, deps } = req;
|
|
9
9
|
const paste = (note) => ({ status: 'paste-needed', note });
|
|
@@ -27,6 +27,14 @@ export async function deliverClaude(req) {
|
|
|
27
27
|
await (deps.write ?? writeToSocket)(sock.path, messageLine(req.text), deps.timeoutMs ?? DELIVER_TIMEOUT_MS, () => socketChanged(sock.path, checked.identity));
|
|
28
28
|
}
|
|
29
29
|
catch (err) {
|
|
30
|
+
if (err instanceof UnconfirmedWrite) {
|
|
31
|
+
// Written, but never confirmed: a paste on top of it could reach the session twice.
|
|
32
|
+
const ended = await req.ended();
|
|
33
|
+
return {
|
|
34
|
+
status: 'unknown',
|
|
35
|
+
note: `sideby wrote it to ${to.label} but could not confirm it arrived (${err.message}).${ended ? ' The session has ended since.' : ''} It may still show up; check the session before you send it again`,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
30
38
|
return paste(`sideby could not reach ${to.label} (${err.message}); paste the line into its tab`);
|
|
31
39
|
}
|
|
32
40
|
if (inbound === 'accept')
|
|
@@ -54,10 +54,16 @@ export declare function socketProblem(path: string, o: {
|
|
|
54
54
|
export declare function socketChanged(path: string, id: SocketIdentity): Promise<string | null>;
|
|
55
55
|
/** The one line Claude Code reads from its socket as a user message. */
|
|
56
56
|
export declare const messageLine: (text: string) => string;
|
|
57
|
+
/**
|
|
58
|
+
* The line was handed to the socket and its end sent, but the flush was never confirmed (a timeout or an error after
|
|
59
|
+
* that point): the session may have read it, so the outcome is unknown (ADR-0065), unlike a failure before writing.
|
|
60
|
+
*/
|
|
61
|
+
export declare class UnconfirmedWrite extends Error {
|
|
62
|
+
}
|
|
57
63
|
/**
|
|
58
64
|
* Connects to `path`, runs `verify` (a reason rejects before anything is written), writes `line`, and closes the
|
|
59
65
|
* connection as soon as the line is flushed, also when the peer keeps its end open. Rejects on a refused connection
|
|
60
|
-
* or after `timeoutMs
|
|
66
|
+
* or after `timeoutMs`; with `UnconfirmedWrite` once the line was written and the flush did not come.
|
|
61
67
|
*/
|
|
62
68
|
export declare function writeToSocket(path: string, line: string, timeoutMs?: number, verify?: () => Promise<string | null>): Promise<void>;
|
|
63
69
|
/** Whether Host arguments start Claude Code in bypass permission mode. */
|
|
@@ -105,14 +105,21 @@ export async function socketChanged(path, id) {
|
|
|
105
105
|
}
|
|
106
106
|
/** The one line Claude Code reads from its socket as a user message. */
|
|
107
107
|
export const messageLine = (text) => `${JSON.stringify({ type: 'user', message: { role: 'user', content: text } })}\n`;
|
|
108
|
+
/**
|
|
109
|
+
* The line was handed to the socket and its end sent, but the flush was never confirmed (a timeout or an error after
|
|
110
|
+
* that point): the session may have read it, so the outcome is unknown (ADR-0065), unlike a failure before writing.
|
|
111
|
+
*/
|
|
112
|
+
export class UnconfirmedWrite extends Error {
|
|
113
|
+
}
|
|
108
114
|
/**
|
|
109
115
|
* Connects to `path`, runs `verify` (a reason rejects before anything is written), writes `line`, and closes the
|
|
110
116
|
* connection as soon as the line is flushed, also when the peer keeps its end open. Rejects on a refused connection
|
|
111
|
-
* or after `timeoutMs
|
|
117
|
+
* or after `timeoutMs`; with `UnconfirmedWrite` once the line was written and the flush did not come.
|
|
112
118
|
*/
|
|
113
119
|
export function writeToSocket(path, line, timeoutMs = DELIVER_TIMEOUT_MS, verify) {
|
|
114
120
|
return new Promise((resolve, reject) => {
|
|
115
121
|
let done = false;
|
|
122
|
+
let written = false;
|
|
116
123
|
const sock = createConnection({ path });
|
|
117
124
|
const finish = (err) => {
|
|
118
125
|
if (done)
|
|
@@ -121,7 +128,7 @@ export function writeToSocket(path, line, timeoutMs = DELIVER_TIMEOUT_MS, verify
|
|
|
121
128
|
clearTimeout(timer);
|
|
122
129
|
sock.destroy();
|
|
123
130
|
if (err)
|
|
124
|
-
reject(err);
|
|
131
|
+
reject(written ? new UnconfirmedWrite(err.message) : err);
|
|
125
132
|
else
|
|
126
133
|
resolve();
|
|
127
134
|
};
|
|
@@ -132,6 +139,7 @@ export function writeToSocket(path, line, timeoutMs = DELIVER_TIMEOUT_MS, verify
|
|
|
132
139
|
return finish(new Error(changed));
|
|
133
140
|
if (done)
|
|
134
141
|
return;
|
|
142
|
+
written = true;
|
|
135
143
|
sock.end(line, () => finish(null));
|
|
136
144
|
});
|
|
137
145
|
sock.once('error', (err) => finish(new Error(err.code === 'ECONNREFUSED' ? 'it refused the connection' : (err.code ?? err.message))));
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import type { Delivery, DeliveryRequest } from '../messaging.ts';
|
|
2
2
|
export declare const QUEUE_TIMEOUT_MS = 20000;
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* `codex queue` started but did not finish in time: it may already have queued the line, so the outcome is unknown
|
|
5
|
+
* (ADR-0065), unlike a start failure or a non-zero exit, which mean it did not.
|
|
6
|
+
*/
|
|
7
|
+
export declare class CodexQueueTimeout extends Error {
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Runs `codex <args>` and resolves to its exit code; its output is ignored, as it may hold account details. Rejects
|
|
11
|
+
* with `CodexQueueTimeout` when the process started and did not end within `timeoutMs`, else with a plain Error.
|
|
12
|
+
*/
|
|
4
13
|
export declare function runCodex(args: readonly string[], env: NodeJS.ProcessEnv, timeoutMs: number): Promise<number>;
|
|
5
14
|
export declare function deliverCodex(req: DeliveryRequest): Promise<Delivery>;
|
|
@@ -8,10 +8,23 @@ import { accountEnv } from '../../core/launch.js';
|
|
|
8
8
|
export const QUEUE_TIMEOUT_MS = 20_000;
|
|
9
9
|
/** How long the queue process gets to end after SIGTERM before it is sent SIGKILL. */
|
|
10
10
|
const KILL_GRACE_MS = 2_000;
|
|
11
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* `codex queue` started but did not finish in time: it may already have queued the line, so the outcome is unknown
|
|
13
|
+
* (ADR-0065), unlike a start failure or a non-zero exit, which mean it did not.
|
|
14
|
+
*/
|
|
15
|
+
export class CodexQueueTimeout extends Error {
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Runs `codex <args>` and resolves to its exit code; its output is ignored, as it may hold account details. Rejects
|
|
19
|
+
* with `CodexQueueTimeout` when the process started and did not end within `timeoutMs`, else with a plain Error.
|
|
20
|
+
*/
|
|
12
21
|
export function runCodex(args, env, timeoutMs) {
|
|
13
22
|
return new Promise((resolve, reject) => {
|
|
14
23
|
const child = spawn('codex', args, { cwd: tmpdir(), env, stdio: 'ignore' });
|
|
24
|
+
let started = false;
|
|
25
|
+
child.once('spawn', () => {
|
|
26
|
+
started = true;
|
|
27
|
+
});
|
|
15
28
|
const timer = setTimeout(() => {
|
|
16
29
|
// Only this short-lived queue process is ended (by its own pid), never a Codex session.
|
|
17
30
|
child.kill('SIGTERM');
|
|
@@ -23,7 +36,8 @@ export function runCodex(args, env, timeoutMs) {
|
|
|
23
36
|
}
|
|
24
37
|
catch { }
|
|
25
38
|
}, KILL_GRACE_MS).unref();
|
|
26
|
-
|
|
39
|
+
const why = 'Codex did not answer in time';
|
|
40
|
+
reject(started ? new CodexQueueTimeout(why) : new Error(why));
|
|
27
41
|
}, timeoutMs);
|
|
28
42
|
child.once('error', (err) => {
|
|
29
43
|
clearTimeout(timer);
|
|
@@ -59,6 +73,14 @@ export async function deliverCodex(req) {
|
|
|
59
73
|
code = await (deps.runCodex ?? runCodex)(args, accountEnv(family, acct, rt.env), deps.timeoutMs ?? QUEUE_TIMEOUT_MS);
|
|
60
74
|
}
|
|
61
75
|
catch (err) {
|
|
76
|
+
if (err instanceof CodexQueueTimeout) {
|
|
77
|
+
// It may have queued the line already; a paste on top of it could reach the session twice.
|
|
78
|
+
const ended = await req.ended();
|
|
79
|
+
return {
|
|
80
|
+
status: 'unknown',
|
|
81
|
+
note: `sideby could not confirm that ${to.label} got it: \`codex queue\` did not finish within ${(deps.timeoutMs ?? QUEUE_TIMEOUT_MS) / 1000} s.${ended ? ' The session has ended since.' : ''} It may still show up; check the session before you send it again`,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
62
84
|
return {
|
|
63
85
|
status: 'paste-needed',
|
|
64
86
|
note: `sideby could not send it to ${to.label} (${err.message}); paste the line into its terminal tab`,
|