sideby 0.32.2 → 0.34.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.
Files changed (60) hide show
  1. package/assets/brand/sai-painted-1024.png +0 -0
  2. package/assets/brand/sai-painted-128.png +0 -0
  3. package/assets/brand/sai-painted-256.png +0 -0
  4. package/assets/brand/sai-painted-64.png +0 -0
  5. package/dist/build.json +1 -1
  6. package/dist/src/cli/commands.js +76 -18
  7. package/dist/src/cli/format.js +3 -1
  8. package/dist/src/cli/json-schemas.js +34 -6
  9. package/dist/src/cli/main.js +12 -5
  10. package/dist/src/core/brand-mark.d.ts +18 -115
  11. package/dist/src/core/brand-mark.js +43 -174
  12. package/dist/src/core/live-sessions.d.ts +4 -0
  13. package/dist/src/core/live-sessions.js +17 -3
  14. package/dist/src/core/messages.d.ts +26 -5
  15. package/dist/src/core/messages.js +73 -16
  16. package/dist/src/core/quota-fetch.js +9 -2
  17. package/dist/src/core/session-status.d.ts +55 -0
  18. package/dist/src/core/session-status.js +59 -0
  19. package/dist/src/core/unattended-retry.d.ts +39 -0
  20. package/dist/src/core/unattended-retry.js +107 -0
  21. package/dist/src/core/unattended.d.ts +2 -2
  22. package/dist/src/core/unattended.js +10 -2
  23. package/dist/src/desktop/icon.d.ts +13 -1
  24. package/dist/src/desktop/icon.js +153 -285
  25. package/dist/src/families/claude/deliver.js +14 -2
  26. package/dist/src/families/claude/messaging.d.ts +14 -1
  27. package/dist/src/families/claude/messaging.js +24 -4
  28. package/dist/src/families/codex/deliver.d.ts +10 -1
  29. package/dist/src/families/codex/deliver.js +24 -2
  30. package/dist/src/families/messaging.d.ts +12 -1
  31. package/dist/src/handoff/messages.js +1 -1
  32. package/dist/src/menubar/script.d.ts +5 -0
  33. package/dist/src/menubar/script.js +111 -25
  34. package/dist/src/menubar/snapshot.d.ts +25 -5
  35. package/dist/src/menubar/snapshot.js +114 -26
  36. package/dist/src/menubar/strings.d.ts +22 -6
  37. package/dist/src/menubar/strings.js +22 -6
  38. package/dist/src/panel/handler.d.ts +2 -2
  39. package/dist/src/panel/handler.js +8 -2
  40. package/dist/src/panel/i18n.d.ts +11 -0
  41. package/dist/src/panel/i18n.js +35 -13
  42. package/dist/src/panel/page-logic.d.ts +41 -4
  43. package/dist/src/panel/page-logic.js +145 -10
  44. package/dist/src/panel/page-script.js +50 -11
  45. package/dist/src/panel/page-styles.js +5 -5
  46. package/dist/src/panel/page.js +2 -2
  47. package/dist/src/panel/theme.d.ts +4 -1
  48. package/dist/src/runtime.d.ts +3 -1
  49. package/dist/src/runtime.js +1 -1
  50. package/dist/src/unattended/hook.d.ts +4 -0
  51. package/dist/src/unattended/hook.js +86 -2
  52. package/package.json +2 -1
  53. package/schemas/menubar-snapshot.json +102 -2
  54. package/schemas/messages.json +6 -2
  55. package/schemas/send.json +6 -2
  56. package/schemas/sessions.json +22 -1
  57. package/skills/sideby/SKILL.md +1 -1
  58. package/skills/sideby/references/panel.md +1 -1
  59. package/skills/sideby/references/sessions.md +7 -4
  60. package/skills/sideby/references/unattended.md +4 -2
@@ -1,309 +1,178 @@
1
- // The sideby mark drawn without dependencies: the two buddies of core/brand-mark.ts on a light rounded tile,
2
- // rasterised in pure Node and encoded as PNG, SVG or ICNS. Curves are flattened to polylines; fills use the nonzero
3
- // rule with exact horizontal coverage on 16 sub-rows per pixel, outlines are round-capped, round-joined thick
4
- // polylines (distance to a segment), ellipses use an analytic distance. Each shape is computed only inside its own
5
- // bounding box and composited back to front, fill before outline, as an SVG renderer would.
6
- import { deflateSync } from 'node:zlib';
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); MARK_VIEWBOX maps onto the whole tile square.
11
- const TILE = { size: 40, radius: 10, color: [0xe5, 0xf2, 0xfb] };
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
- // Sub-rows per pixel row for fills.
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
- /** Pixels per mark unit and the map from a buddy's 64-unit grid to pixels. */
23
- function placement(size, b) {
24
- const tile = tileRect(size);
25
- const u = tile.w / MARK_VIEWBOX.size;
26
- const k = b.scale * u;
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
- /** Parses absolute M, L, H, Q, C, Z path data and flattens it to pixel polylines. */
36
- function flatten(d, map) {
37
- const tokens = d.match(/[MLHQCZ]|-?\d*\.?\d+(?:e-?\d+)?/gi) ?? [];
38
- const polys = [];
39
- let cur = null;
40
- let gx = 0;
41
- let gy = 0;
42
- let start = [0, 0];
43
- let i = 0;
44
- const num = () => Number(tokens[i++]);
45
- const isNum = () => i < tokens.length && !/^[A-Za-z]$/.test(tokens[i]);
46
- const lineTo = (x, y) => {
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
- function box(size, x0, y0, x1, y1) {
110
- const bx0 = Math.max(0, Math.floor(x0));
111
- const by0 = Math.max(0, Math.floor(y0));
112
- const bx1 = Math.min(size, Math.ceil(x1));
113
- const by1 = Math.min(size, Math.ceil(y1));
114
- if (bx1 <= bx0 || by1 <= by0)
115
- return null;
116
- const w = bx1 - bx0;
117
- const h = by1 - by0;
118
- return { x0: bx0, y0: by0, w, h, a: new Float32Array(w * h) };
119
- }
120
- /** Nonzero fill of the polylines (each closed implicitly), exact in x and sampled on SUB_ROWS rows per pixel. */
121
- function fillMask(size, polys) {
122
- const edges = [];
123
- let x0 = Infinity;
124
- let y0 = Infinity;
125
- let x1 = -Infinity;
126
- let y1 = -Infinity;
127
- for (const { pts } of polys)
128
- for (let j = 0; j < pts.length; j++) {
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
- const m = box(size, x0, y0, x1, y1);
139
- if (!m)
140
- return null;
141
- const hits = [];
142
- for (let row = 0; row < m.h; row++)
143
- for (let s = 0; s < SUB_ROWS; s++) {
144
- const sy = m.y0 + row + (s + 0.5) / SUB_ROWS;
145
- hits.length = 0;
146
- for (const [ax, ay, bx, by] of edges) {
147
- if (sy < Math.min(ay, by) || sy >= Math.max(ay, by))
148
- continue;
149
- hits.push([ax + ((sy - ay) * (bx - ax)) / (by - ay), by > ay ? 1 : -1]);
150
- }
151
- if (hits.length < 2)
152
- continue;
153
- hits.sort((p, q) => p[0] - q[0]);
154
- let wind = 0;
155
- for (let h = 0; h < hits.length - 1; h++) {
156
- wind += hits[h][1];
157
- if (wind === 0)
158
- continue;
159
- const xa = Math.max(hits[h][0], m.x0);
160
- const xb = Math.min(hits[h + 1][0], m.x0 + m.w);
161
- for (let px = Math.floor(xa); px < xb; px++) {
162
- const cover = Math.min(xb, px + 1) - Math.max(xa, px);
163
- if (cover > 0)
164
- m.a[row * m.w + px - m.x0] += cover / SUB_ROWS;
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
- return m;
169
- }
170
- /** Round-capped, round-joined line of width `w` along the polylines: distance to the nearest segment ≤ w/2. */
171
- function strokeMask(size, polys, w) {
172
- const r = w / 2;
173
- const segs = [];
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
- const m = box(size, x0 - r - 1, y0 - r - 1, x1 + r + 1, y1 + r + 1);
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
- /** Signed distance from (px, py) to a rounded rectangle; negative inside. */
234
- function roundedRectMask(size, s) {
235
- const m = box(size, s.x - 1, s.y - 1, s.x + s.w + 1, s.y + s.h + 1);
236
- if (!m)
237
- return null;
238
- const hx = s.w / 2;
239
- const hy = s.h / 2;
240
- for (let py = 0; py < m.h; py++)
241
- for (let px = 0; px < m.w; px++) {
242
- const qx = Math.abs(m.x0 + px + 0.5 - (s.x + hx)) - (hx - s.r);
243
- const qy = Math.abs(m.y0 + py + 0.5 - (s.y + hy)) - (hy - s.r);
244
- const d = Math.hypot(Math.max(qx, 0), Math.max(qy, 0)) + Math.min(Math.max(qx, qy), 0) - s.r;
245
- m.a[py * m.w + px] = Math.min(1, Math.max(0, 0.5 - d));
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
- return m;
120
+ return out;
121
+ });
248
122
  }
249
- /** The shapes of one placed buddy, back to front, each with its colour (core/brand-mark.ts buddyShapes). */
250
- function buddyLayers(size, b) {
251
- const { k, map } = placement(size, b);
252
- const { paths, dots, above } = buddyShapes(b);
253
- const layers = [];
254
- const shape = (s) => {
255
- const polys = flatten(s.d, map);
256
- if (s.fill && s.fill !== 'none')
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
- above.forEach(shape);
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 layers = [
275
- { mask: roundedRectMask(size, tileRect(size)), color: TILE.color },
276
- ...buddyLayers(size, MARK.back),
277
- ...buddyLayers(size, { ...MARK.front, colors: { ...MARK.front.colors, body: MARK_COLORS.blue.body } }),
278
- ];
279
- // Premultiplied "over" compositing, layer by layer inside each mask's box.
280
- const acc = new Float32Array(size * size * 4);
281
- for (const { mask: m, color } of layers) {
282
- if (!m)
283
- continue;
284
- const [cr, cg, cb] = color.map((c) => c / 255);
285
- for (let y = 0; y < m.h; y++)
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 i = 0; i < px.length; i += 4) {
299
- const a = acc[i + 3];
300
- if (a <= 0)
301
- continue;
302
- px[i] = Math.round((acc[i] / a) * 255);
303
- px[i + 1] = Math.round((acc[i + 1] / a) * 255);
304
- px[i + 2] = Math.round((acc[i + 2] / a) * 255);
305
- px[i + 3] = Math.round(a * 255);
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 mark as an SVG (1024-unit canvas), for Linux icon themes. */
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 hex = (c) => `#${c.map((v) => v.toString(16).padStart(2, '0')).join('')}`;
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="${hex(TILE.color)}"/>`,
398
- ` <svg x="${tile.x}" y="${tile.y}" width="${tile.w}" height="${tile.h}" viewBox="${V.x} ${V.y} ${V.size} ${V.size}">${markSvgBody(MARK_COLORS.blue.body)}</svg>`,
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, PassingWriteError, 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,7 +27,19 @@ 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
- return paste(`sideby could not reach ${to.label} (${err.message}); paste the line into its tab`);
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
+ }
38
+ // Nothing was written: a failure that may pass is tried again (core/messages.ts), any other is a paste.
39
+ return {
40
+ ...paste(`sideby could not reach ${to.label} (${err.message}); paste the line into its tab`),
41
+ ...(err instanceof PassingWriteError ? { retry: true } : {}),
42
+ };
31
43
  }
32
44
  if (inbound === 'accept')
33
45
  return { status: 'delivered' };
@@ -54,10 +54,23 @@ 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
+ }
63
+ /**
64
+ * Nothing was written, and the failure may pass: the session refused or dropped the connection, its queue was full,
65
+ * or it did not answer in time. Sending again cannot deliver the line twice, so the delivery is tried again.
66
+ */
67
+ export declare class PassingWriteError extends Error {
68
+ }
57
69
  /**
58
70
  * Connects to `path`, runs `verify` (a reason rejects before anything is written), writes `line`, and closes the
59
71
  * 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`.
72
+ * or after `timeoutMs` (with `PassingWriteError` when nothing was written and it may pass); with `UnconfirmedWrite`
73
+ * once the line was written and the flush did not come.
61
74
  */
62
75
  export declare function writeToSocket(path: string, line: string, timeoutMs?: number, verify?: () => Promise<string | null>): Promise<void>;
63
76
  /** Whether Host arguments start Claude Code in bypass permission mode. */
@@ -105,14 +105,30 @@ 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
+ }
114
+ /**
115
+ * Nothing was written, and the failure may pass: the session refused or dropped the connection, its queue was full,
116
+ * or it did not answer in time. Sending again cannot deliver the line twice, so the delivery is tried again.
117
+ */
118
+ export class PassingWriteError extends Error {
119
+ }
120
+ /** Socket errors before anything is written that a session that is busy for a moment gives. */
121
+ const PASSING_CODES = new Set(['ECONNREFUSED', 'ECONNRESET', 'EAGAIN', 'ETIMEDOUT', 'EPIPE']);
108
122
  /**
109
123
  * Connects to `path`, runs `verify` (a reason rejects before anything is written), writes `line`, and closes the
110
124
  * 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`.
125
+ * or after `timeoutMs` (with `PassingWriteError` when nothing was written and it may pass); with `UnconfirmedWrite`
126
+ * once the line was written and the flush did not come.
112
127
  */
113
128
  export function writeToSocket(path, line, timeoutMs = DELIVER_TIMEOUT_MS, verify) {
114
129
  return new Promise((resolve, reject) => {
115
130
  let done = false;
131
+ let written = false;
116
132
  const sock = createConnection({ path });
117
133
  const finish = (err) => {
118
134
  if (done)
@@ -121,20 +137,24 @@ export function writeToSocket(path, line, timeoutMs = DELIVER_TIMEOUT_MS, verify
121
137
  clearTimeout(timer);
122
138
  sock.destroy();
123
139
  if (err)
124
- reject(err);
140
+ reject(written ? new UnconfirmedWrite(err.message) : err);
125
141
  else
126
142
  resolve();
127
143
  };
128
- const timer = setTimeout(() => finish(new Error(`it did not answer within ${timeoutMs / 1000} s`)), timeoutMs);
144
+ const timer = setTimeout(() => finish(new PassingWriteError(`it did not answer within ${timeoutMs / 1000} s`)), timeoutMs);
129
145
  sock.once('connect', async () => {
130
146
  const changed = verify ? await verify().catch((e) => e.message) : null;
131
147
  if (changed)
132
148
  return finish(new Error(changed));
133
149
  if (done)
134
150
  return;
151
+ written = true;
135
152
  sock.end(line, () => finish(null));
136
153
  });
137
- sock.once('error', (err) => finish(new Error(err.code === 'ECONNREFUSED' ? 'it refused the connection' : (err.code ?? err.message))));
154
+ sock.once('error', (err) => {
155
+ const why = err.code === 'ECONNREFUSED' ? 'it refused the connection' : (err.code ?? err.message);
156
+ finish(err.code && PASSING_CODES.has(err.code) ? new PassingWriteError(why) : new Error(why));
157
+ });
138
158
  });
139
159
  }
140
160
  /** Whether Host arguments start Claude Code in bypass permission mode. */
@@ -1,5 +1,14 @@
1
1
  import type { Delivery, DeliveryRequest } from '../messaging.ts';
2
2
  export declare const QUEUE_TIMEOUT_MS = 20000;
3
- /** Runs `codex <args>` and resolves to its exit code; its output is ignored, as it may hold account details. */
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>;