sideby 0.21.0 → 0.23.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/README.md +1 -0
- package/ai-tasks.json +14 -0
- package/dist/build.json +1 -1
- package/dist/src/cli/commands.d.ts +7 -0
- package/dist/src/cli/commands.js +441 -31
- package/dist/src/cli/format.js +3 -2
- package/dist/src/cli/json-schemas.js +157 -47
- package/dist/src/cli/main.js +38 -7
- package/dist/src/core/accounts.d.ts +6 -1
- package/dist/src/core/accounts.js +16 -3
- package/dist/src/core/ask.d.ts +2 -1
- package/dist/src/core/ask.js +12 -4
- package/dist/src/core/claude-settings-file.d.ts +57 -0
- package/dist/src/core/claude-settings-file.js +104 -2
- package/dist/src/core/config.d.ts +34 -16
- package/dist/src/core/config.js +58 -5
- package/dist/src/core/create.js +4 -1
- package/dist/src/core/desktop-app.js +5 -1
- package/dist/src/core/handoff-overview.d.ts +4 -1
- package/dist/src/core/handoff-overview.js +3 -2
- package/dist/src/core/handoff-rules.d.ts +34 -0
- package/dist/src/core/handoff-rules.js +115 -0
- package/dist/src/core/handoff-select.js +45 -28
- package/dist/src/core/handoff-status.d.ts +37 -7
- package/dist/src/core/handoff-status.js +95 -19
- package/dist/src/core/handoff.d.ts +4 -1
- package/dist/src/core/handoff.js +8 -5
- package/dist/src/core/inbound.d.ts +11 -3
- package/dist/src/core/inbound.js +26 -74
- package/dist/src/core/launch.js +6 -4
- package/dist/src/core/quota-levels.d.ts +13 -2
- package/dist/src/core/quota-levels.js +21 -3
- package/dist/src/core/remote-control.d.ts +10 -12
- package/dist/src/core/remote-control.js +29 -86
- package/dist/src/core/themes.d.ts +107 -0
- package/dist/src/core/themes.js +463 -0
- package/dist/src/core/tuning-apply.js +12 -20
- package/dist/src/families/agy/index.d.ts +8 -0
- package/dist/src/families/agy/index.js +53 -0
- package/dist/src/families/agy/quota.d.ts +9 -0
- package/dist/src/families/agy/quota.js +110 -0
- package/dist/src/families/index.js +7 -0
- package/dist/src/families/logos.d.ts +10 -0
- package/dist/src/families/logos.js +12 -1
- package/dist/src/menubar/script.js +26 -3
- package/dist/src/menubar/snapshot.d.ts +33 -6
- package/dist/src/menubar/snapshot.js +138 -43
- package/dist/src/menubar/strings.d.ts +18 -2
- package/dist/src/menubar/strings.js +18 -2
- package/dist/src/panel/handler.d.ts +4 -1
- package/dist/src/panel/handler.js +206 -46
- package/dist/src/panel/i18n.d.ts +106 -7
- package/dist/src/panel/i18n.js +260 -62
- package/dist/src/panel/page-logic.d.ts +67 -20
- package/dist/src/panel/page-logic.js +74 -7
- package/dist/src/panel/page-script.js +522 -124
- package/dist/src/panel/page-styles.d.ts +2 -0
- package/dist/src/panel/page-styles.js +157 -34
- package/dist/src/panel/page.js +3 -3
- package/dist/src/panel/theme.d.ts +6 -1
- package/dist/src/panel/theme.js +4 -0
- package/dist/src/panel/themes.d.ts +14 -0
- package/dist/src/panel/themes.js +162 -0
- package/dist/src/plugins/check.js +27 -13
- package/dist/src/plugins/loader.d.ts +11 -0
- package/dist/src/plugins/loader.js +47 -1
- package/dist/src/runtime.d.ts +9 -2
- package/dist/src/runtime.js +12 -5
- package/dist/src/types.d.ts +35 -5
- package/package.json +2 -2
- package/schemas/config.json +45 -2
- package/schemas/families.json +13 -5
- package/schemas/handoff-disable.json +22 -0
- package/schemas/handoff-enable.json +22 -0
- package/schemas/handoff-rules.json +302 -0
- package/schemas/handoff-status.json +26 -0
- package/schemas/hide.json +157 -0
- package/schemas/list.json +15 -0
- package/schemas/menubar-snapshot.json +309 -2
- package/schemas/order.json +26 -1
- package/schemas/pin.json +17 -0
- package/schemas/theme-check.json +140 -0
- package/schemas/theme-export.json +86 -0
- package/schemas/theme-import.json +92 -0
- package/schemas/theme-preview.json +86 -0
- package/schemas/theme-remove.json +87 -0
- package/schemas/theme-use.json +88 -0
- package/schemas/theme.json +137 -0
- package/schemas/unhide.json +157 -0
- package/schemas/unpin.json +17 -0
- package/skills/sideby/SKILL.md +5 -2
- package/skills/sideby/references/accounts.md +1 -0
- package/skills/sideby/references/ai-tasks.md +1 -1
- package/skills/sideby/references/handoff.md +7 -3
- package/skills/sideby/references/panel.md +9 -0
- package/skills/sideby/references/quota.md +3 -1
- package/skills/sideby/references/themes.md +47 -0
|
@@ -0,0 +1,463 @@
|
|
|
1
|
+
// Themes (spec §3.34, ADR-0050): the two Built-in Themes plus the user's Theme Files in <config>/themes/<id>.json.
|
|
2
|
+
// A Theme File is data only: a base Built-in Theme, an optional accent that regenerates the accent roles, and token
|
|
3
|
+
// overrides checked like a Portal Theme's. This module lists, checks, resolves and switches them; it never runs code.
|
|
4
|
+
import { lstat, mkdir, readdir, readFile, rm } from 'node:fs/promises';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { THEME_TOKENS, themeValueProblem } from '../panel/theme.js';
|
|
7
|
+
import { BUILTIN_THEMES, DEFAULT_THEME_ID } from '../panel/themes.js';
|
|
8
|
+
import { editConfigPanel, loadConfig } from './config.js';
|
|
9
|
+
import { writeFileAtomic } from './fs-safe.js';
|
|
10
|
+
export const THEME_ID_RE = /^[a-z0-9][a-z0-9-]{0,39}$/;
|
|
11
|
+
const MAX_FILE = 64 * 1024;
|
|
12
|
+
const HEX_RE = /^#[0-9a-fA-F]{6}$/;
|
|
13
|
+
export const themesDir = (paths) => join(paths.configDir, 'themes');
|
|
14
|
+
const undoFile = (paths) => join(paths.stateDir, 'theme-undo.json');
|
|
15
|
+
const previewFile = (paths) => join(paths.stateDir, 'theme-preview.json');
|
|
16
|
+
const builtin = (id) => BUILTIN_THEMES.find((t) => t.id === id);
|
|
17
|
+
/**
|
|
18
|
+
* The name `sideby theme use` takes for "no Theme chosen": the Panel then shows the Default Theme on its own and,
|
|
19
|
+
* inside a Portal, the Portal's colors. It names no Theme File.
|
|
20
|
+
*/
|
|
21
|
+
export const NO_THEME = 'default';
|
|
22
|
+
const reserved = (id) => Boolean(builtin(id)) || id === NO_THEME;
|
|
23
|
+
const DEFAULT = builtin(DEFAULT_THEME_ID);
|
|
24
|
+
// ---- Reading and checking a Theme File
|
|
25
|
+
/** Checks parsed JSON as a Theme File. Problems make it unusable; warnings are keys that were ignored. */
|
|
26
|
+
export function checkThemeData(data) {
|
|
27
|
+
const problems = [];
|
|
28
|
+
const warnings = [];
|
|
29
|
+
if (typeof data !== 'object' || data === null || Array.isArray(data))
|
|
30
|
+
return { problems: ['must be a JSON object, like {"schemaVersion": 1, "name": "My theme"}'], warnings };
|
|
31
|
+
const d = data;
|
|
32
|
+
if (d.schemaVersion !== 1)
|
|
33
|
+
problems.push('schemaVersion must be 1');
|
|
34
|
+
if (typeof d.name !== 'string' || !d.name.trim() || d.name.length > 60)
|
|
35
|
+
problems.push('name must be a short text (1 to 60 characters)');
|
|
36
|
+
if (d.base !== undefined && (typeof d.base !== 'string' || !builtin(d.base)))
|
|
37
|
+
problems.push(`base must be one of ${BUILTIN_THEMES.map((t) => t.id).join(', ')}`);
|
|
38
|
+
if (d.accent !== undefined && (typeof d.accent !== 'string' || !HEX_RE.test(d.accent)))
|
|
39
|
+
problems.push('accent must be a color like #3f8fc4');
|
|
40
|
+
const tokens = { light: {}, dark: {} };
|
|
41
|
+
for (const mode of ['light', 'dark']) {
|
|
42
|
+
const v = d[mode];
|
|
43
|
+
if (v === undefined)
|
|
44
|
+
continue;
|
|
45
|
+
if (typeof v !== 'object' || v === null || Array.isArray(v)) {
|
|
46
|
+
problems.push(`${mode} must be an object of tokens`);
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
for (const [k, value] of Object.entries(v)) {
|
|
50
|
+
if (!Object.hasOwn(THEME_TOKENS, k)) {
|
|
51
|
+
warnings.push(`${mode}.${k} is not a token sideby knows; it was ignored`);
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
const problem = themeValueProblem(value);
|
|
55
|
+
if (problem)
|
|
56
|
+
problems.push(`${mode}.${k} ${problem}`);
|
|
57
|
+
else
|
|
58
|
+
tokens[mode][k] = value.trim();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
for (const k of Object.keys(d))
|
|
62
|
+
if (!['$schema', 'schemaVersion', 'name', 'base', 'accent', 'light', 'dark'].includes(k))
|
|
63
|
+
warnings.push(`${k} is not a Theme File key; it was ignored`);
|
|
64
|
+
if (problems.length)
|
|
65
|
+
return { problems, warnings };
|
|
66
|
+
return {
|
|
67
|
+
theme: {
|
|
68
|
+
schemaVersion: 1,
|
|
69
|
+
name: d.name.trim(),
|
|
70
|
+
...(d.base ? { base: d.base } : {}),
|
|
71
|
+
...(d.accent ? { accent: d.accent.toLowerCase() } : {}),
|
|
72
|
+
light: tokens.light,
|
|
73
|
+
dark: tokens.dark,
|
|
74
|
+
},
|
|
75
|
+
problems,
|
|
76
|
+
warnings,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/** Reads one Theme File: a regular file of at most 64 KB, never followed through a link. */
|
|
80
|
+
export async function readThemeFile(path) {
|
|
81
|
+
try {
|
|
82
|
+
const st = await lstat(path);
|
|
83
|
+
if (!st.isFile())
|
|
84
|
+
return { problems: ['is not a regular file (links are not followed)'], warnings: [] };
|
|
85
|
+
if (st.size > MAX_FILE)
|
|
86
|
+
return { problems: ['is over 64 KB'], warnings: [] };
|
|
87
|
+
const text = await readFile(path, 'utf8');
|
|
88
|
+
let data;
|
|
89
|
+
try {
|
|
90
|
+
data = JSON.parse(text);
|
|
91
|
+
}
|
|
92
|
+
catch (e) {
|
|
93
|
+
return {
|
|
94
|
+
problems: [`is not valid JSON (${e.message}); fix it or run \`sideby theme check\``],
|
|
95
|
+
warnings: [],
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
return checkThemeData(data);
|
|
99
|
+
}
|
|
100
|
+
catch (e) {
|
|
101
|
+
return { problems: [`cannot be read (${e.code ?? 'error'})`], warnings: [] };
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// ---- Listing
|
|
105
|
+
export async function listThemes(paths) {
|
|
106
|
+
const out = BUILTIN_THEMES.map((t) => ({
|
|
107
|
+
id: t.id,
|
|
108
|
+
name: t.name.en,
|
|
109
|
+
source: 'builtin',
|
|
110
|
+
swatches: [...t.swatches],
|
|
111
|
+
problems: [],
|
|
112
|
+
warnings: [],
|
|
113
|
+
}));
|
|
114
|
+
let names = [];
|
|
115
|
+
try {
|
|
116
|
+
names = (await readdir(themesDir(paths))).filter((n) => n.endsWith('.json')).sort();
|
|
117
|
+
}
|
|
118
|
+
catch { }
|
|
119
|
+
for (const n of names) {
|
|
120
|
+
const id = n.slice(0, -5);
|
|
121
|
+
const path = join(themesDir(paths), n);
|
|
122
|
+
if (!THEME_ID_RE.test(id) || reserved(id)) {
|
|
123
|
+
out.push({
|
|
124
|
+
id,
|
|
125
|
+
name: id,
|
|
126
|
+
source: 'file',
|
|
127
|
+
path,
|
|
128
|
+
swatches: [],
|
|
129
|
+
warnings: [],
|
|
130
|
+
problems: [
|
|
131
|
+
builtin(id)
|
|
132
|
+
? `uses the name of a Built-in Theme; rename the file`
|
|
133
|
+
: 'file name must be lowercase letters, digits and hyphens (up to 40), then .json',
|
|
134
|
+
],
|
|
135
|
+
});
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
const r = await readThemeFile(path);
|
|
139
|
+
const colors = r.theme ? themeColors(r.theme) : undefined;
|
|
140
|
+
out.push({
|
|
141
|
+
id,
|
|
142
|
+
name: r.theme?.name ?? id,
|
|
143
|
+
source: 'file',
|
|
144
|
+
path,
|
|
145
|
+
swatches: colors ? swatchesOf(colors.light, colors.dark) : [],
|
|
146
|
+
problems: r.problems,
|
|
147
|
+
warnings: r.warnings,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
return out;
|
|
151
|
+
}
|
|
152
|
+
const swatchesOf = (l, d) => [l.bg, l.accentSoft, l.primary, d.bg].filter((c) => typeof c === 'string');
|
|
153
|
+
// ---- Resolving a Theme to tokens
|
|
154
|
+
/** A Theme File's colors before the contrast check: base, then accent roles, then the file's own tokens. */
|
|
155
|
+
export function themeColors(theme) {
|
|
156
|
+
const base = builtin(theme.base ?? DEFAULT_THEME_ID);
|
|
157
|
+
const accent = theme.accent ? accentTokens(theme.accent) : { light: {}, dark: {} };
|
|
158
|
+
return {
|
|
159
|
+
light: { ...base.light, ...accent.light, ...theme.light },
|
|
160
|
+
dark: { ...base.dark, ...accent.dark, ...theme.dark },
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
/** The colors for a Theme id (Built-in or file), with failing pairs moved until they pass. Unknown or broken: Sky. */
|
|
164
|
+
export async function resolveColors(paths, id) {
|
|
165
|
+
const want = id === undefined || id === NO_THEME ? DEFAULT_THEME_ID : id;
|
|
166
|
+
const b = builtin(want);
|
|
167
|
+
if (b)
|
|
168
|
+
return { id: want, light: { ...b.light }, dark: { ...b.dark }, adjusted: 0 };
|
|
169
|
+
if (!THEME_ID_RE.test(want))
|
|
170
|
+
return { ...defaults(), fallback: `${want} is not a Theme name; using ${DEFAULT.name.en}` };
|
|
171
|
+
const r = await readThemeFile(join(themesDir(paths), `${want}.json`));
|
|
172
|
+
if (!r.theme)
|
|
173
|
+
return {
|
|
174
|
+
...defaults(),
|
|
175
|
+
fallback: `Theme ${want} cannot be used (${r.problems[0]}); using ${DEFAULT.name.en}`,
|
|
176
|
+
};
|
|
177
|
+
return adjust(want, themeColors(r.theme));
|
|
178
|
+
}
|
|
179
|
+
function defaults() {
|
|
180
|
+
return { id: DEFAULT_THEME_ID, light: { ...DEFAULT.light }, dark: { ...DEFAULT.dark }, adjusted: 0 };
|
|
181
|
+
}
|
|
182
|
+
function adjust(id, c) {
|
|
183
|
+
const light = { ...c.light };
|
|
184
|
+
const dark = { ...c.dark };
|
|
185
|
+
let adjusted = 0;
|
|
186
|
+
for (const p of contrastPairs({ light, dark }))
|
|
187
|
+
if (!p.ok && p.suggest) {
|
|
188
|
+
;
|
|
189
|
+
(p.mode === 'light' ? light : dark)[p.fg] = p.suggest;
|
|
190
|
+
adjusted++;
|
|
191
|
+
}
|
|
192
|
+
return { id, light, dark, adjusted };
|
|
193
|
+
}
|
|
194
|
+
// ---- Accent roles from one color
|
|
195
|
+
// Lightness and chroma of the maintainer's leaf scales, step 1 to 12; step 9 becomes the accent itself.
|
|
196
|
+
const SCALE_LIGHT = [
|
|
197
|
+
[0.988, 0.014],
|
|
198
|
+
[0.973, 0.029],
|
|
199
|
+
[0.948, 0.055],
|
|
200
|
+
[0.923, 0.08],
|
|
201
|
+
[0.894, 0.101],
|
|
202
|
+
[0.857, 0.118],
|
|
203
|
+
[0.809, 0.14],
|
|
204
|
+
[0.746, 0.161],
|
|
205
|
+
[0.735, 0.18],
|
|
206
|
+
[0.69, 0.178],
|
|
207
|
+
[0.5, 0.126],
|
|
208
|
+
[0.305, 0.072],
|
|
209
|
+
];
|
|
210
|
+
const SCALE_DARK = [
|
|
211
|
+
[0.18, 0.015],
|
|
212
|
+
[0.207, 0.026],
|
|
213
|
+
[0.25, 0.045],
|
|
214
|
+
[0.289, 0.06],
|
|
215
|
+
[0.33, 0.074],
|
|
216
|
+
[0.378, 0.09],
|
|
217
|
+
[0.44, 0.11],
|
|
218
|
+
[0.521, 0.136],
|
|
219
|
+
[0.735, 0.18],
|
|
220
|
+
[0.776, 0.172],
|
|
221
|
+
[0.841, 0.14],
|
|
222
|
+
[0.94, 0.061],
|
|
223
|
+
];
|
|
224
|
+
/** A 12-step scale around one color: step 9 is the color, the others follow the template's lightness. */
|
|
225
|
+
export function accentScale(hex, dark) {
|
|
226
|
+
const [sL, sC, sH] = toOklch(hex);
|
|
227
|
+
const k = sC / 0.18;
|
|
228
|
+
return (dark ? SCALE_DARK : SCALE_LIGHT).map(([L, C], i) => i === 8
|
|
229
|
+
? hex.toLowerCase()
|
|
230
|
+
: i === 9
|
|
231
|
+
? fromOklch(dark ? sL + 0.04 : sL - 0.045, sC, sH)
|
|
232
|
+
: fromOklch(i === 10 && !dark ? Math.min(L, sL - 0.12) : L, Math.min(C * k, C * 1.3), sH));
|
|
233
|
+
}
|
|
234
|
+
/** The accent roles of a Theme generated from one color; neutrals and warning colors stay the base Theme's. */
|
|
235
|
+
export function accentTokens(hex) {
|
|
236
|
+
const a = accentScale(hex, false);
|
|
237
|
+
const d = accentScale(hex, true);
|
|
238
|
+
// Main button: the accent if white text reaches 3.2:1 on it, else the accent darkened until it does.
|
|
239
|
+
const [L, C, H] = toOklch(hex);
|
|
240
|
+
let l = L;
|
|
241
|
+
let p = hex.toLowerCase();
|
|
242
|
+
while (contrast(p, '#ffffff') < 3.2 && l > 0.3) {
|
|
243
|
+
l -= 0.005;
|
|
244
|
+
p = fromOklch(l, C, H);
|
|
245
|
+
}
|
|
246
|
+
const pHover = fromOklch(toOklch(p)[0] - 0.045, C, H);
|
|
247
|
+
const button = {
|
|
248
|
+
primary: p,
|
|
249
|
+
primaryHover: pHover,
|
|
250
|
+
primaryActive: pHover,
|
|
251
|
+
primaryBorder: p,
|
|
252
|
+
primaryHoverBorder: pHover,
|
|
253
|
+
onPrimary: '#ffffff',
|
|
254
|
+
};
|
|
255
|
+
return {
|
|
256
|
+
light: {
|
|
257
|
+
...button,
|
|
258
|
+
accent: a[10],
|
|
259
|
+
accentSoft: a[2],
|
|
260
|
+
focus: a[10],
|
|
261
|
+
buttonHoverBorder: a[5],
|
|
262
|
+
buttonHoverText: a[10],
|
|
263
|
+
checkColor: a[8],
|
|
264
|
+
ok: a[11],
|
|
265
|
+
okSoft: a[2],
|
|
266
|
+
okBar: a[8],
|
|
267
|
+
},
|
|
268
|
+
dark: {
|
|
269
|
+
...button,
|
|
270
|
+
accent: d[10],
|
|
271
|
+
accentSoft: d[2],
|
|
272
|
+
focus: d[10],
|
|
273
|
+
buttonHoverBorder: d[5],
|
|
274
|
+
buttonHoverText: d[10],
|
|
275
|
+
checkColor: d[8],
|
|
276
|
+
ok: d[10],
|
|
277
|
+
okSoft: d[2],
|
|
278
|
+
okBar: d[8],
|
|
279
|
+
},
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
// Text pairs need 4.5:1; the main button (bold text, ADR-0050) and the focus outline need 3:1.
|
|
283
|
+
const PAIRS = [
|
|
284
|
+
['text', 'bg', 4.5],
|
|
285
|
+
['text', 'surface', 4.5],
|
|
286
|
+
['muted', 'bg', 4.5],
|
|
287
|
+
['muted', 'surface', 4.5],
|
|
288
|
+
['accent', 'bg', 4.5],
|
|
289
|
+
['accent', 'surface', 4.5],
|
|
290
|
+
['ok', 'okSoft', 4.5],
|
|
291
|
+
['warn', 'warnSoft', 4.5],
|
|
292
|
+
['fail', 'failSoft', 4.5],
|
|
293
|
+
['fail', 'surface', 4.5],
|
|
294
|
+
['onPrimary', 'primary', 3],
|
|
295
|
+
['focus', 'surface', 3],
|
|
296
|
+
];
|
|
297
|
+
export function contrastPairs(c) {
|
|
298
|
+
const out = [];
|
|
299
|
+
for (const mode of ['light', 'dark'])
|
|
300
|
+
for (const [fg, bg, min] of PAIRS) {
|
|
301
|
+
const a = c[mode][fg];
|
|
302
|
+
const b = c[mode][bg];
|
|
303
|
+
if (!a || !b || !HEX_RE.test(a) || !HEX_RE.test(b)) {
|
|
304
|
+
out.push({ mode, fg, bg, min, ok: true });
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
const ratio = Math.round(contrast(a, b) * 100) / 100;
|
|
308
|
+
const ok = ratio >= min;
|
|
309
|
+
out.push({ mode, fg, bg, ratio, min, ok, ...(ok ? {} : { suggest: passing(a, b, min) }) });
|
|
310
|
+
}
|
|
311
|
+
return out;
|
|
312
|
+
}
|
|
313
|
+
/** Moves `fg` along OKLCH lightness, away from `bg`, until it reaches `min`. */
|
|
314
|
+
function passing(fg, bg, min) {
|
|
315
|
+
const [L, C, H] = toOklch(fg);
|
|
316
|
+
const darker = toOklch(bg)[0] > 0.6;
|
|
317
|
+
for (let l = L; l >= 0 && l <= 1; l += darker ? -0.01 : 0.01) {
|
|
318
|
+
const c = fromOklch(l, C, H);
|
|
319
|
+
if (contrast(c, bg) >= min)
|
|
320
|
+
return c;
|
|
321
|
+
}
|
|
322
|
+
return darker ? '#000000' : '#ffffff';
|
|
323
|
+
}
|
|
324
|
+
// ---- Switching
|
|
325
|
+
/** Sets `panel.colorTheme`, keeping what it was so `undo` can put it back. */
|
|
326
|
+
export async function useTheme(paths, id) {
|
|
327
|
+
if (id !== NO_THEME) {
|
|
328
|
+
const entry = (await listThemes(paths)).find((t) => t.id === id);
|
|
329
|
+
if (!entry)
|
|
330
|
+
throw new Error(`no Theme named ${id}; run \`sideby theme list\` to see the names`);
|
|
331
|
+
if (entry.problems.length)
|
|
332
|
+
throw new Error(`Theme ${id} cannot be used: ${entry.problems[0]}; fix ${entry.path}`);
|
|
333
|
+
}
|
|
334
|
+
// A Theme picked by name is kept even when it is the Default Theme: inside a Portal it wins over the Portal's colors.
|
|
335
|
+
const before = (await loadConfig(paths.configFile)).panel?.colorTheme ?? NO_THEME;
|
|
336
|
+
const r = await editConfigPanel(paths.configFile, { colorTheme: id === NO_THEME ? null : id });
|
|
337
|
+
if (r.changed) {
|
|
338
|
+
await mkdir(paths.stateDir, { recursive: true });
|
|
339
|
+
await writeFileAtomic(undoFile(paths), `${JSON.stringify({ before, after: id })}\n`);
|
|
340
|
+
}
|
|
341
|
+
return { before, after: id, changed: r.changed };
|
|
342
|
+
}
|
|
343
|
+
/** Puts back the Theme from before the last `use`, only while config still holds what that `use` wrote. */
|
|
344
|
+
export async function undoTheme(paths) {
|
|
345
|
+
let rec;
|
|
346
|
+
try {
|
|
347
|
+
rec = JSON.parse(await readFile(undoFile(paths), 'utf8'));
|
|
348
|
+
}
|
|
349
|
+
catch {
|
|
350
|
+
throw new Error('nothing to undo: no Theme was switched with sideby yet');
|
|
351
|
+
}
|
|
352
|
+
const now = (await loadConfig(paths.configFile)).panel?.colorTheme ?? NO_THEME;
|
|
353
|
+
if (typeof rec.before !== 'string' || rec.after !== now)
|
|
354
|
+
throw new Error(`the Theme was changed since (now ${now}); pick one with \`sideby theme use <name>\``);
|
|
355
|
+
await editConfigPanel(paths.configFile, { colorTheme: rec.before === NO_THEME ? null : rec.before });
|
|
356
|
+
await rm(undoFile(paths), { force: true });
|
|
357
|
+
return { before: now, after: rec.before };
|
|
358
|
+
}
|
|
359
|
+
// ---- Files
|
|
360
|
+
/** Writes a checked Theme File into the themes folder. */
|
|
361
|
+
export async function saveThemeFile(paths, id, theme) {
|
|
362
|
+
if (!THEME_ID_RE.test(id) || reserved(id))
|
|
363
|
+
throw new Error(`${id} cannot be a Theme name: use lowercase letters, digits and hyphens, not ${[...BUILTIN_THEMES.map((t) => t.id), NO_THEME].join(', ')}`);
|
|
364
|
+
await mkdir(themesDir(paths), { recursive: true });
|
|
365
|
+
const path = join(themesDir(paths), `${id}.json`);
|
|
366
|
+
await writeFileAtomic(path, `${JSON.stringify(theme, null, 2)}\n`);
|
|
367
|
+
return path;
|
|
368
|
+
}
|
|
369
|
+
export async function removeThemeFile(paths, id) {
|
|
370
|
+
if (!THEME_ID_RE.test(id) || reserved(id))
|
|
371
|
+
throw new Error(`${id} is not a Theme File; Built-in Themes cannot be removed`);
|
|
372
|
+
const path = join(themesDir(paths), `${id}.json`);
|
|
373
|
+
const st = await lstat(path).catch(() => undefined);
|
|
374
|
+
if (!st)
|
|
375
|
+
throw new Error(`no Theme File ${path}`);
|
|
376
|
+
const wasActive = (await loadConfig(paths.configFile)).panel?.colorTheme === id;
|
|
377
|
+
if (wasActive)
|
|
378
|
+
await editConfigPanel(paths.configFile, { colorTheme: null });
|
|
379
|
+
await rm(path);
|
|
380
|
+
return { path, wasActive };
|
|
381
|
+
}
|
|
382
|
+
/** A full Theme File for an id: a Built-in Theme gets every token, so it can be the start of the user's own. */
|
|
383
|
+
export async function exportTheme(paths, id) {
|
|
384
|
+
const b = builtin(id);
|
|
385
|
+
if (b)
|
|
386
|
+
return {
|
|
387
|
+
schemaVersion: 1,
|
|
388
|
+
name: `My ${b.name.en}`,
|
|
389
|
+
base: b.id,
|
|
390
|
+
light: { ...b.light },
|
|
391
|
+
dark: { ...b.dark },
|
|
392
|
+
};
|
|
393
|
+
const r = await readThemeFile(join(themesDir(paths), `${id}.json`));
|
|
394
|
+
if (!r.theme)
|
|
395
|
+
throw new Error(`Theme ${id} cannot be exported: ${r.problems[0] ?? 'not found'}`);
|
|
396
|
+
return r.theme;
|
|
397
|
+
}
|
|
398
|
+
/** Keeps a Theme for one look at the Panel without choosing it (`sideby theme preview`). */
|
|
399
|
+
export async function setPreview(paths, theme) {
|
|
400
|
+
await mkdir(paths.stateDir, { recursive: true });
|
|
401
|
+
await writeFileAtomic(previewFile(paths), `${JSON.stringify({ at: Date.now(), theme })}\n`);
|
|
402
|
+
}
|
|
403
|
+
/** The previewed Theme's colors, if one was set in the last ten minutes. */
|
|
404
|
+
export async function previewColors(paths) {
|
|
405
|
+
try {
|
|
406
|
+
const rec = JSON.parse(await readFile(previewFile(paths), 'utf8'));
|
|
407
|
+
if (typeof rec.at !== 'number' || Date.now() - rec.at > 10 * 60_000)
|
|
408
|
+
return undefined;
|
|
409
|
+
const r = checkThemeData(rec.theme);
|
|
410
|
+
return r.theme ? adjust('preview', themeColors(r.theme)) : undefined;
|
|
411
|
+
}
|
|
412
|
+
catch {
|
|
413
|
+
return undefined;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
// ---- OKLCH and WCAG contrast
|
|
417
|
+
const lin = (c) => (c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4);
|
|
418
|
+
const unlin = (c) => (c <= 0.0031308 ? 12.92 * c : 1.055 * c ** (1 / 2.4) - 0.055);
|
|
419
|
+
const rgb = (hex) => [1, 3, 5].map((i) => Number.parseInt(hex.slice(i, i + 2), 16) / 255);
|
|
420
|
+
export function toOklch(hex) {
|
|
421
|
+
const [r, g, b] = rgb(hex).map(lin);
|
|
422
|
+
const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
|
|
423
|
+
const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
|
|
424
|
+
const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
|
|
425
|
+
const L = 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s;
|
|
426
|
+
const A = 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s;
|
|
427
|
+
const B = 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s;
|
|
428
|
+
return [L, Math.hypot(A, B), ((Math.atan2(B, A) * 180) / Math.PI + 360) % 360];
|
|
429
|
+
}
|
|
430
|
+
function oklchRgb(L, C, H) {
|
|
431
|
+
const a = C * Math.cos((H * Math.PI) / 180);
|
|
432
|
+
const b = C * Math.sin((H * Math.PI) / 180);
|
|
433
|
+
const l = (L + 0.3963377774 * a + 0.2158037573 * b) ** 3;
|
|
434
|
+
const m = (L - 0.1055613458 * a - 0.0638541728 * b) ** 3;
|
|
435
|
+
const s = (L - 0.0894841775 * a - 1.291485548 * b) ** 3;
|
|
436
|
+
return [
|
|
437
|
+
4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,
|
|
438
|
+
-1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,
|
|
439
|
+
-0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s,
|
|
440
|
+
];
|
|
441
|
+
}
|
|
442
|
+
/** OKLCH to #rrggbb, lowering chroma until the color fits sRGB. */
|
|
443
|
+
export function fromOklch(L, C, H) {
|
|
444
|
+
const l = Math.min(1, Math.max(0, L));
|
|
445
|
+
let c = C;
|
|
446
|
+
while (c > 0 && !oklchRgb(l, c, H).every((v) => v >= -1e-4 && v <= 1 + 1e-4))
|
|
447
|
+
c -= 0.003;
|
|
448
|
+
return `#${oklchRgb(l, Math.max(c, 0), H)
|
|
449
|
+
.map((v) => Math.round(unlin(Math.min(1, Math.max(0, v))) * 255)
|
|
450
|
+
.toString(16)
|
|
451
|
+
.padStart(2, '0'))
|
|
452
|
+
.join('')}`;
|
|
453
|
+
}
|
|
454
|
+
const luminance = (hex) => {
|
|
455
|
+
const [r, g, b] = rgb(hex).map(lin);
|
|
456
|
+
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
457
|
+
};
|
|
458
|
+
/** WCAG 2 contrast ratio of two #rrggbb colors. */
|
|
459
|
+
export function contrast(a, b) {
|
|
460
|
+
const x = luminance(a);
|
|
461
|
+
const y = luminance(b);
|
|
462
|
+
return (Math.max(x, y) + 0.05) / (Math.min(x, y) + 0.05);
|
|
463
|
+
}
|
|
@@ -3,11 +3,10 @@
|
|
|
3
3
|
// error or the undo record, and the write goes through `writeIfUnchanged`. A symlinked `settings.json` (settings
|
|
4
4
|
// shared with the Main Account) is written at the real file it points to, and the plan names every Account that
|
|
5
5
|
// shares it; a link is never created, replaced or retargeted.
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { isObj, locate, readObject, render } from './claude-settings-file.js';
|
|
6
|
+
import { rm, stat } from 'node:fs/promises';
|
|
7
|
+
import { isObj, keyRecordPath, locate, readKeyRecord, readObject, render, writeKeyRecord, } from './claude-settings-file.js';
|
|
9
8
|
import { UserError } from './errors.js';
|
|
10
|
-
import { fileHash, sha256,
|
|
9
|
+
import { fileHash, sha256, writeIfUnchanged } from './fs-safe.js';
|
|
11
10
|
import { MAX_COMPACT_WINDOW, MIN_COMPACT_WINDOW } from './tuning.js';
|
|
12
11
|
export const TUNE_KEY = 'autoCompactWindow';
|
|
13
12
|
export const MIN_WINDOW = MIN_COMPACT_WINDOW;
|
|
@@ -31,21 +30,15 @@ function overridesOf(obj) {
|
|
|
31
30
|
}
|
|
32
31
|
return out;
|
|
33
32
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
33
|
+
const RECORDS = 'tune';
|
|
34
|
+
const recordPath = (ctx, file) => keyRecordPath(ctx.stateDir, RECORDS, file);
|
|
37
35
|
async function readRecord(ctx, file) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
catch {
|
|
46
|
-
// no record
|
|
47
|
-
}
|
|
48
|
-
return null;
|
|
36
|
+
const r = await readKeyRecord(ctx.stateDir, RECORDS, file);
|
|
37
|
+
return r &&
|
|
38
|
+
(r.applied === null || typeof r.applied === 'number') &&
|
|
39
|
+
(r.previous === null || typeof r.previous === 'number')
|
|
40
|
+
? r
|
|
41
|
+
: null;
|
|
49
42
|
}
|
|
50
43
|
/** What applying `value` to the Account would do. Writes nothing. */
|
|
51
44
|
export async function planTuneApply(account, value, accounts) {
|
|
@@ -136,8 +129,7 @@ export async function applyTune(account, value, accounts, ctx) {
|
|
|
136
129
|
created: chained ? earlier.created : plan.creates,
|
|
137
130
|
at: new Date().toISOString(),
|
|
138
131
|
};
|
|
139
|
-
await
|
|
140
|
-
await writeFileAtomic(recordPath(ctx, plan.file), `${JSON.stringify(record, null, 2)}\n`, 0o600);
|
|
132
|
+
await writeKeyRecord(ctx.stateDir, RECORDS, plan.file, record);
|
|
141
133
|
return {
|
|
142
134
|
ok: true,
|
|
143
135
|
plan,
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { FamilyDef, Plugin } from '../../types.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Antigravity CLI, a Main-only Family (ADR-0047): agy keeps its data under `$HOME/.gemini/antigravity-cli` and its
|
|
4
|
+
* Google sign-in in one fixed system keychain entry, with no variable that moves either (tried with agy 1.4.4 on
|
|
5
|
+
* 2026-10-21), so sideby knows only its Main Account.
|
|
6
|
+
*/
|
|
7
|
+
export declare const agyFamily: FamilyDef;
|
|
8
|
+
export declare const agyPlugin: Plugin;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { BUILTIN_LOGOS } from '../logos.js';
|
|
2
|
+
import { agyQuotaFetch } from './quota.js';
|
|
3
|
+
/** Lets agy run without asking before each tool call; an AI Task must keep those checks (ADR-0031). */
|
|
4
|
+
const SKIP_PERMISSIONS = '--dangerously-skip-permissions';
|
|
5
|
+
/**
|
|
6
|
+
* Antigravity CLI, a Main-only Family (ADR-0047): agy keeps its data under `$HOME/.gemini/antigravity-cli` and its
|
|
7
|
+
* Google sign-in in one fixed system keychain entry, with no variable that moves either (tried with agy 1.4.4 on
|
|
8
|
+
* 2026-10-21), so sideby knows only its Main Account.
|
|
9
|
+
*/
|
|
10
|
+
export const agyFamily = {
|
|
11
|
+
id: 'agy',
|
|
12
|
+
title: 'Antigravity CLI',
|
|
13
|
+
logo: BUILTIN_LOGOS.agy,
|
|
14
|
+
bin: 'agy',
|
|
15
|
+
installUrl: 'https://antigravity.google/docs/getting-started?tab=cli',
|
|
16
|
+
installCommand: 'curl -fsSL https://antigravity.google/cli/install.sh | bash',
|
|
17
|
+
mainOnly: true,
|
|
18
|
+
layout: { main: '.gemini/antigravity-cli' },
|
|
19
|
+
// Variables that would sign agy in with a key or route it elsewhere instead of the Google sign-in. Kept:
|
|
20
|
+
// GOOGLE_CLOUD_PROJECT (other tools use it too) and AGY_ACCOUNT (picks a connected sandbox account, not the login).
|
|
21
|
+
hijackVars: [
|
|
22
|
+
'GEMINI_API_KEY',
|
|
23
|
+
'GOOGLE_API_KEY',
|
|
24
|
+
'AGY_ADC_AUTH',
|
|
25
|
+
'GOOGLE_GENAI_USE_VERTEXAI',
|
|
26
|
+
'GOOGLE_GENAI_USE_ENTERPRISE',
|
|
27
|
+
'ANTIGRAVITY_PROJECT_ID',
|
|
28
|
+
],
|
|
29
|
+
apiVars: [],
|
|
30
|
+
// `-p` is one non-interactive prompt (agy 1.4.4 --help, 2026-10-21).
|
|
31
|
+
probe: { args: ['-p', 'Reply with OK'] },
|
|
32
|
+
// agy reads a prompt only from -p, -i or stdin: "unexpected argument" otherwise (agy 1.4.4, 2026-10-21).
|
|
33
|
+
promptArg: '--prompt-interactive',
|
|
34
|
+
aiTaskArgs: (args) => args.includes(SKIP_PERMISSIONS) ? args.filter((a) => a !== SKIP_PERMISSIONS) : [...args],
|
|
35
|
+
sharedItems: [],
|
|
36
|
+
settingsFile: 'settings.json',
|
|
37
|
+
login: {
|
|
38
|
+
args: null,
|
|
39
|
+
hint: 'Start agy and sign in with your Google account in the browser; agy keeps one sign-in per computer',
|
|
40
|
+
},
|
|
41
|
+
// The sign-in lives in the system keychain, which sideby never reads: the state is unknown. A quota check that
|
|
42
|
+
// fails for want of a sign-in says so in the Quota column.
|
|
43
|
+
async loginState() {
|
|
44
|
+
return 'unknown';
|
|
45
|
+
},
|
|
46
|
+
fetchQuota: agyQuotaFetch,
|
|
47
|
+
};
|
|
48
|
+
export const agyPlugin = {
|
|
49
|
+
name: 'agy',
|
|
50
|
+
register(api) {
|
|
51
|
+
api.family(agyFamily);
|
|
52
|
+
},
|
|
53
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Account, QuotaFetch, QuotaFetchContext, QuotaResult } from '../../types.ts';
|
|
2
|
+
export declare const AGY_QUOTA_ARGS: readonly ['-p', '/usage', '--output-format', 'json'];
|
|
3
|
+
/**
|
|
4
|
+
* The Quota in agy's JSON answer: one window per bucket, named after its model group, since each limit covers only
|
|
5
|
+
* that group's models. Only group names, windows, percentages and reset times are kept.
|
|
6
|
+
*/
|
|
7
|
+
export declare function agyQuota(answer: unknown, observedAt: string): QuotaResult | null;
|
|
8
|
+
export declare function fetchAgyQuota(account: Account, ctx: QuotaFetchContext): Promise<QuotaResult>;
|
|
9
|
+
export declare const agyQuotaFetch: QuotaFetch;
|