sideby 0.22.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.
Files changed (52) hide show
  1. package/ai-tasks.json +14 -0
  2. package/dist/build.json +1 -1
  3. package/dist/src/cli/commands.d.ts +7 -0
  4. package/dist/src/cli/commands.js +326 -21
  5. package/dist/src/cli/json-schemas.js +76 -1
  6. package/dist/src/cli/main.js +32 -4
  7. package/dist/src/core/ask.js +6 -1
  8. package/dist/src/core/config.d.ts +5 -1
  9. package/dist/src/core/config.js +18 -3
  10. package/dist/src/core/quota-levels.d.ts +7 -2
  11. package/dist/src/core/quota-levels.js +13 -3
  12. package/dist/src/core/themes.d.ts +107 -0
  13. package/dist/src/core/themes.js +463 -0
  14. package/dist/src/menubar/snapshot.d.ts +10 -0
  15. package/dist/src/menubar/snapshot.js +14 -6
  16. package/dist/src/menubar/strings.d.ts +6 -0
  17. package/dist/src/menubar/strings.js +6 -0
  18. package/dist/src/panel/handler.d.ts +2 -0
  19. package/dist/src/panel/handler.js +125 -1
  20. package/dist/src/panel/i18n.d.ts +49 -0
  21. package/dist/src/panel/i18n.js +104 -6
  22. package/dist/src/panel/page-logic.d.ts +20 -1
  23. package/dist/src/panel/page-logic.js +41 -0
  24. package/dist/src/panel/page-script.js +264 -35
  25. package/dist/src/panel/page-styles.d.ts +2 -0
  26. package/dist/src/panel/page-styles.js +57 -31
  27. package/dist/src/panel/theme.d.ts +6 -1
  28. package/dist/src/panel/theme.js +4 -0
  29. package/dist/src/panel/themes.d.ts +14 -0
  30. package/dist/src/panel/themes.js +162 -0
  31. package/dist/src/runtime.d.ts +4 -0
  32. package/package.json +1 -1
  33. package/schemas/config.json +29 -1
  34. package/schemas/families.json +5 -0
  35. package/schemas/hide.json +157 -0
  36. package/schemas/list.json +10 -0
  37. package/schemas/order.json +26 -1
  38. package/schemas/pin.json +17 -0
  39. package/schemas/theme-check.json +140 -0
  40. package/schemas/theme-export.json +86 -0
  41. package/schemas/theme-import.json +92 -0
  42. package/schemas/theme-preview.json +86 -0
  43. package/schemas/theme-remove.json +87 -0
  44. package/schemas/theme-use.json +88 -0
  45. package/schemas/theme.json +137 -0
  46. package/schemas/unhide.json +157 -0
  47. package/schemas/unpin.json +17 -0
  48. package/skills/sideby/SKILL.md +3 -1
  49. package/skills/sideby/references/ai-tasks.md +1 -1
  50. package/skills/sideby/references/panel.md +9 -0
  51. package/skills/sideby/references/quota.md +1 -1
  52. package/skills/sideby/references/themes.md +47 -0
package/ai-tasks.json CHANGED
@@ -70,6 +70,20 @@
70
70
  { "en": "sideby doesn't recognize my terminal", "zh": "我用的终端没被认出来" }
71
71
  ]
72
72
  },
73
+ {
74
+ "id": "theme",
75
+ "native": true,
76
+ "title": { "en": "Let AI pick your colors", "zh": "让 AI 帮我配色" },
77
+ "placeholder": {
78
+ "en": "What feel do you want? A website or a color works too.",
79
+ "zh": "想要什么感觉?给个网址或颜色也行。"
80
+ },
81
+ "examples": [
82
+ { "en": "Quiet and gray, like Notion", "zh": "素净的灰色,像 Notion" },
83
+ { "en": "Green, like my company site", "zh": "绿色,和我们公司官网一样" },
84
+ { "en": "Warmer, easier on the eyes at night", "zh": "暖一点,晚上看着不累" }
85
+ ]
86
+ },
73
87
  {
74
88
  "id": "handoff",
75
89
  "native": true,
package/dist/build.json CHANGED
@@ -1 +1 @@
1
- {"id":"20261021T094830-069f4a"}
1
+ {"id":"20261022T091443-e858af"}
@@ -29,6 +29,11 @@ export declare function serializeDoctor(r: DoctorReport): {
29
29
  fixes: import("../core/doctor.ts").FixOutcome[];
30
30
  };
31
31
  export declare function cmdPin(a: ParsedArgs, io: Io, pin: boolean): Promise<number>;
32
+ /**
33
+ * `sideby hide|unhide <family|account>` (spec §3.25): takes a Family, or an Account with the other directories of its
34
+ * Same Login, out of the lists or puts it back. Display only.
35
+ */
36
+ export declare function cmdHide(a: ParsedArgs, io: Io, hide: boolean): Promise<number>;
32
37
  export declare function cmdOrder(a: ParsedArgs, io: Io): Promise<number>;
33
38
  export declare function cmdList(a: ParsedArgs, io: Io): Promise<number>;
34
39
  export interface NewSuggestion {
@@ -132,3 +137,5 @@ export declare function cmdSend(a: SendArgs, io: Io): Promise<number>;
132
137
  * `sideby messages inbound [accept|undo] [--yes]`: whether Claude sessions show them at once.
133
138
  */
134
139
  export declare function cmdMessages(a: ParsedArgs, io: Io, runtime?: Runtime): Promise<number>;
140
+ /** `sideby theme` (spec §3.34): list, use, undo, check, preview, import, export and remove Themes. */
141
+ export declare function cmdTheme(a: ParsedArgs, io: Io): Promise<number>;
@@ -1,3 +1,5 @@
1
+ import { stat, writeFile } from 'node:fs/promises';
2
+ import { basename, join, resolve } from 'node:path';
1
3
  import { StringDecoder } from 'node:string_decoder';
2
4
  import { fileURLToPath } from 'node:url';
3
5
  import { aliasesByAccount } from '../core/accounts.js';
@@ -20,7 +22,7 @@ import { USAGE_DAYS } from '../core/quota-levels.js';
20
22
  import { groupsToUndo, remoteControlNothingToDo, remoteControlTodo, } from '../core/remote-control.js';
21
23
  import { SHELLS } from '../core/shell-init.js';
22
24
  import { MODEL_NAME } from '../families/shared/model-args.js';
23
- import { AI_TASK_KINDS, inDisplayOrder, pinnedIn, suggestAlias, suggestName, withPinned, } from '../panel/page-logic.js';
25
+ import { AI_TASK_KINDS, hiddenIn, inDisplayOrder, pinnedIn, suggestAlias, suggestName, withPinned, } from '../panel/page-logic.js';
24
26
  import { createRuntime, UnknownFamilyError } from '../runtime.js';
25
27
  import { UsageError } from './args.js';
26
28
  import { c, clock, compactNumber, quotaText, table, truncate, tuningLines, usageText } from './format.js';
@@ -107,6 +109,8 @@ function cleanDisplay(rt, groups) {
107
109
  families: d.families?.filter((id) => groups.has(id)),
108
110
  accounts: clean(d.accounts),
109
111
  pinned: clean(d.pinned),
112
+ hiddenFamilies: d.hiddenFamilies?.filter((id) => groups.has(id)),
113
+ hidden: clean(d.hidden),
110
114
  };
111
115
  }
112
116
  export async function cmdPin(a, io, pin) {
@@ -148,6 +152,60 @@ export async function cmdPin(a, io, pin) {
148
152
  io.out(`${account.ref}: ${message}`);
149
153
  return 0;
150
154
  }
155
+ /**
156
+ * `sideby hide|unhide <family|account>` (spec §3.25): takes a Family, or an Account with the other directories of its
157
+ * Same Login, out of the lists or puts it back. Display only.
158
+ */
159
+ export async function cmdHide(a, io, hide) {
160
+ if (a.positionals.length !== 1 || a.rest.length)
161
+ throw new UsageError('usage: sideby hide|unhide <family|account|short command> [--json]');
162
+ const rt = await createRuntime();
163
+ const target = a.positionals[0];
164
+ const accounts = await rt.accounts();
165
+ const d = cleanDisplay(rt, await orderGroups(rt, accounts));
166
+ let kind;
167
+ let ref;
168
+ let already;
169
+ if (rt.families.has(target)) {
170
+ kind = 'family';
171
+ ref = target;
172
+ const list = d.hiddenFamilies ?? [];
173
+ already = list.includes(target);
174
+ d.hiddenFamilies = hide ? (already ? list : [...list, target]) : list.filter((id) => id !== target);
175
+ }
176
+ else {
177
+ kind = 'account';
178
+ const account = await rt.resolve(target);
179
+ ref = account.ref;
180
+ const peers = new Set([account.ref, ...(await rt.sameLogin(account))]);
181
+ const names = accounts.filter((x) => peers.has(x.ref)).map((x) => x.name);
182
+ const list = d.hidden?.[account.family] ?? [];
183
+ already = names.some((name) => list.includes(name));
184
+ d.hidden = {
185
+ ...d.hidden,
186
+ [account.family]: hide
187
+ ? [...list, ...names.filter((name) => !list.includes(name))]
188
+ : list.filter((name) => !names.includes(name)),
189
+ };
190
+ if (!hide && !already && d.hiddenFamilies?.includes(account.family))
191
+ throw new UserError(`All of ${account.family} is hidden, not just ${account.ref}; run sideby unhide ${account.family} to show the family again.`);
192
+ }
193
+ const before = JSON.stringify(rt.displayOrder());
194
+ const display = await rt.setDisplayOrder(d);
195
+ const changed = before !== JSON.stringify(display);
196
+ const message = hide
197
+ ? already
198
+ ? 'Already hidden.'
199
+ : `Hidden from the Panel, the menu bar and sideby list; it can still be started. sideby unhide ${ref} shows it again.`
200
+ : already
201
+ ? 'Shown again.'
202
+ : 'Not hidden; nothing to change.';
203
+ if (a.flags.has('json'))
204
+ json(io, { target: ref, kind, hidden: hide, changed, message, display });
205
+ else
206
+ io.out(`${ref}: ${message}`);
207
+ return 0;
208
+ }
151
209
  export async function cmdOrder(a, io) {
152
210
  const reset = a.flags.has('reset');
153
211
  const families = a.flags.has('families');
@@ -162,7 +220,7 @@ export async function cmdOrder(a, io) {
162
220
  const groups = await orderGroups(rt, accounts);
163
221
  let d = cleanDisplay(rt, groups);
164
222
  if (reset)
165
- d = { pinned: d.pinned };
223
+ d = { pinned: d.pinned, hiddenFamilies: d.hiddenFamilies, hidden: d.hidden };
166
224
  else {
167
225
  const [id, ...names] = a.positionals;
168
226
  const requested = families ? a.positionals : names;
@@ -187,6 +245,7 @@ export async function cmdOrder(a, io) {
187
245
  const groups = await orderGroups(rt, accounts);
188
246
  const rows = inDisplayOrder([...groups.keys()], (id) => id, display.families).map((family) => ({
189
247
  family,
248
+ hidden: display.hiddenFamilies?.includes(family) ?? false,
190
249
  accounts: rt.families.has(family)
191
250
  ? ordered
192
251
  .filter((x) => x.family === family)
@@ -194,18 +253,20 @@ export async function cmdOrder(a, io) {
194
253
  name: x.name,
195
254
  ref: x.ref,
196
255
  pinned: display.pinned?.[family]?.includes(x.name) ?? false,
256
+ hidden: hiddenIn(x, display),
197
257
  }))
198
258
  : inDisplayOrder(groups.get(family) ?? [], (n) => n, display.accounts?.[family]).map((name) => ({
199
259
  name,
200
260
  ref: `${family}:${name}`,
201
261
  pinned: false,
262
+ hidden: hiddenIn({ family, name }, display),
202
263
  })),
203
264
  }));
204
265
  if (a.flags.has('json'))
205
266
  json(io, { display, families: rows });
206
267
  else
207
268
  for (const row of rows)
208
- io.out(`${row.family}: ${row.accounts.map((x) => `${x.name}${x.pinned ? ' (pinned)' : ''}`).join(', ') || '(no accounts)'}`);
269
+ io.out(`${row.family}${row.hidden ? ' (hidden)' : ''}: ${row.accounts.map((x) => `${x.name}${x.pinned ? ' (pinned)' : ''}${x.hidden && !row.hidden ? ' (hidden)' : ''}`).join(', ') || '(no accounts)'}`);
209
270
  return 0;
210
271
  }
211
272
  function onOff(value, usage) {
@@ -217,7 +278,11 @@ export async function cmdList(a, io) {
217
278
  const rt = await createRuntime();
218
279
  const accounts = displayOrdered(await rt.accounts(), rt);
219
280
  const [statuses, appProfiles] = await Promise.all([
220
- withDesktopApps(rt, accounts, Promise.all(accounts.map((x) => rt.status(x)))).then((list) => list.map((s) => pinnedIn(s, rt.displayOrder().pinned?.[s.family] ?? []) ? { ...s, pinned: true } : s)),
281
+ withDesktopApps(rt, accounts, Promise.all(accounts.map((x) => rt.status(x)))).then((list) => list.map((s) => {
282
+ const d = rt.displayOrder();
283
+ const marked = pinnedIn(s, d.pinned?.[s.family] ?? []) ? { ...s, pinned: true } : s;
284
+ return hiddenIn(s, d) ? { ...marked, hidden: true } : marked;
285
+ })),
221
286
  // Desktop app windows in the Display Order too (spec §3.25), the main window first by default.
222
287
  listAppProfiles(rt).then((list) => {
223
288
  const d = rt.displayOrder();
@@ -228,13 +293,22 @@ export async function cmdList(a, io) {
228
293
  }),
229
294
  ]);
230
295
  const hasDesktop = statuses.some((s) => s.desktopApp);
231
- const families = inDisplayOrder(await rt.familyInfo(), (f) => f.id, rt.displayOrder().families);
296
+ const families = inDisplayOrder(await rt.familyInfo(), (f) => f.id, rt.displayOrder().families).map((f) => rt.displayOrder().hiddenFamilies?.includes(f.id) ? { ...f, hidden: true } : f);
232
297
  if (a.flags.has('json')) {
233
298
  json(io, { families, accounts: statuses, appProfiles, pluginErrors: [...rt.pluginErrors] });
234
299
  return 0;
235
300
  }
236
301
  const home = rt.paths.home;
237
- if (statuses.length === 0) {
302
+ // Hidden Accounts (spec §3.25) stay out of the text unless --all asks for them; --json above has them all.
303
+ const all = a.flags.has('all');
304
+ const shown = all ? statuses : statuses.filter((s) => !s.hidden);
305
+ const hiddenCount = statuses.length - shown.length;
306
+ const hiddenLine = c.dim(`\n${hiddenCount} hidden; sideby list --all shows them, sideby unhide <family|account> puts one back.`);
307
+ if (statuses.length && !shown.length) {
308
+ io.out(`All ${statuses.length} accounts are hidden.`);
309
+ io.out(hiddenLine);
310
+ }
311
+ else if (statuses.length === 0) {
238
312
  io.out('No accounts found yet.');
239
313
  const installed = families.filter((f) => f.installed);
240
314
  if (installed.length === 0)
@@ -246,8 +320,8 @@ export async function cmdList(a, io) {
246
320
  // `= main`: the other Accounts of its Same Login, which share its Quota (spec §3.21).
247
321
  const brokenOf = (id) => families.find((f) => f.id === id)?.brokenBin;
248
322
  const sameMark = (refs) => refs?.length ? ` ${c.dim(`= ${refs.map((r) => r.slice(r.indexOf(':') + 1)).join(', ')}`)}` : '';
249
- const rows = statuses.map((s) => [
250
- `${c.bold(s.ref)}${sameMark(s.sameLogin)}`,
323
+ const rows = shown.map((s) => [
324
+ `${c.bold(s.ref)}${sameMark(s.sameLogin)}${s.hidden ? ` ${c.dim('(hidden)')}` : ''}`,
251
325
  s.isMain ? 'main' : s.kind === 'api' ? c.cyan('api') : 'sub',
252
326
  s.login === 'logged-in'
253
327
  ? c.green('✓')
@@ -265,12 +339,14 @@ export async function cmdList(a, io) {
265
339
  ]);
266
340
  io.out(table(rows, ['ACCOUNT', 'TYPE', 'LOGIN', 'EMAIL', 'MODEL', 'DIR', ...(hasDesktop ? ['DESKTOP'] : [])]));
267
341
  // One line per Host that cannot run, with what to do: the rows only say which accounts it affects.
268
- for (const f of families.filter((x) => !x.installed && statuses.some((s) => s.family === x.id)))
342
+ for (const f of families.filter((x) => !x.installed && shown.some((s) => s.family === x.id)))
269
343
  io.out(c.yellow(f.brokenBin
270
344
  ? `\n${f.title}'s install is broken (${tildify(f.brokenBin, home)} cannot run, often after an interrupted upgrade); reinstall it: ${installHint(f)}`
271
345
  : `\n${f.title} is not installed; install it: ${installHint(f)}`));
272
- if (statuses.some((s) => s.sameLogin?.length))
346
+ if (shown.some((s) => s.sameLogin?.length))
273
347
  io.out(c.dim('\n= <account>: signed in as the same login as that account, so they share one quota.'));
348
+ if (hiddenCount)
349
+ io.out(hiddenLine);
274
350
  io.out(c.dim('\nsideby run <account> · sideby new <family> <name> · sideby quota · sideby ui'));
275
351
  }
276
352
  // App Profiles (ADR-0019): windows of an app that signs in apart from the Accounts above. Not on the first screen
@@ -293,7 +369,7 @@ export async function cmdList(a, io) {
293
369
  const id = list[0]?.ref.slice(0, list[0].ref.indexOf(':'));
294
370
  io.out(c.dim(`sideby desktop ${id}:<name> opens one (a new name makes a new window)`));
295
371
  }
296
- for (const s of statuses)
372
+ for (const s of shown)
297
373
  for (const p of s.problems ?? [])
298
374
  io.err(c.yellow(`${s.ref}: ${p}`));
299
375
  for (const e of rt.pluginErrors)
@@ -2473,24 +2549,57 @@ export async function cmdAutostart(a, io) {
2473
2549
  }
2474
2550
  return 0;
2475
2551
  }
2552
+ /** The newest session activity among these Accounts, from their Usage; undefined when none can be read. */
2553
+ async function lastLocalUse(rt, list) {
2554
+ const times = await Promise.all(list.map(async (x) => {
2555
+ const u = await rt.usage(x).catch(() => null);
2556
+ return u?.status === 'ok' && u.lastActivityAt ? Date.parse(u.lastActivityAt) : Number.NaN;
2557
+ }));
2558
+ const newest = Math.max(...times.filter(Number.isFinite));
2559
+ return Number.isFinite(newest) ? new Date(newest).toISOString() : undefined;
2560
+ }
2476
2561
  /** What the Menu Bar Item lists (spec §3.31): each Family's accounts in Display Order, with its Handoff ranking. */
2477
2562
  async function menubarFamilies(rt) {
2478
- const accounts = displayOrdered(await rt.accounts(), rt);
2563
+ // Hidden Families and Accounts (spec §3.25) stay out of the menu and its percent; a Same Login is hidden whole.
2564
+ const display = rt.displayOrder();
2565
+ const every = displayOrdered(await rt.accounts(), rt);
2566
+ const accounts = [];
2567
+ for (const x of every)
2568
+ if (!hiddenIn({ ...x, sameLogin: await rt.sameLogin(x) }, display))
2569
+ accounts.push(x);
2479
2570
  const ids = [...new Set(accounts.map((x) => x.family))];
2480
2571
  return Promise.all(ids.map(async (id) => {
2481
2572
  const f = rt.families.get(id);
2482
2573
  const plan = f.readQuota || f.fetchQuota ? await rt.handoff(id).catch(() => null) : null;
2574
+ const now = rt.readContext().now.getTime();
2483
2575
  const list = await Promise.all(accounts
2484
2576
  .filter((x) => x.family === id)
2485
- .map(async (x) => ({
2486
- ref: x.ref,
2487
- name: x.name,
2488
- kind: x.kind,
2489
- login: x.kind === 'api' ? 'not-needed' : (await rt.status(x)).login,
2490
- quota: await rt.quota(x),
2491
- sameLogin: await rt.sameLogin(x),
2492
- })));
2493
- return { id, title: f.title, logo: f.logo ?? null, plan, accounts: list };
2577
+ .map(async (x) => {
2578
+ const quota = await rt.quota(x);
2579
+ const sameLogin = await rt.sameLogin(x);
2580
+ // Usage is read only for a reading over an hour old, to tell whether this computer used the login since.
2581
+ const old = quota.status === 'ok' && now - Date.parse(quota.observedAt) > 3600_000;
2582
+ const lastUseAt = old
2583
+ ? await lastLocalUse(rt, [x, ...accounts.filter((p) => sameLogin.includes(p.ref))])
2584
+ : undefined;
2585
+ return {
2586
+ ref: x.ref,
2587
+ name: x.name,
2588
+ kind: x.kind,
2589
+ login: x.kind === 'api' ? 'not-needed' : (await rt.status(x)).login,
2590
+ quota,
2591
+ sameLogin,
2592
+ ...(lastUseAt ? { lastUseAt } : {}),
2593
+ };
2594
+ }));
2595
+ return {
2596
+ id,
2597
+ title: f.title,
2598
+ logo: f.logo ?? null,
2599
+ refreshable: Boolean(f.fetchQuota),
2600
+ plan,
2601
+ accounts: list,
2602
+ };
2494
2603
  }));
2495
2604
  }
2496
2605
  /**
@@ -3483,3 +3592,199 @@ async function messagesInbound(a, args, io, runtime) {
3483
3592
  }
3484
3593
  return r.ok ? 0 : 1;
3485
3594
  }
3595
+ /** `sideby theme` (spec §3.34): list, use, undo, check, preview, import, export and remove Themes. */
3596
+ export async function cmdTheme(a, io) {
3597
+ const t = await import('../core/themes.js');
3598
+ const { loadConfig } = await import('../core/config.js');
3599
+ const [sub = 'list', target, ...more] = a.positionals;
3600
+ const wantJson = a.flags.has('json');
3601
+ const paths = resolvePaths();
3602
+ const usage = 'usage: sideby theme [list] | use <name> | use --undo | check <name|file> | preview <name|file> | import <file> [--id <name>] [--yes] | export <name> [--out <file>] | remove <name> [--yes] [--json]';
3603
+ if (more.length)
3604
+ throw new UsageError(usage);
3605
+ const active = async () => (await loadConfig(paths.configFile).catch(() => ({}))).panel
3606
+ ?.colorTheme ?? 'sky';
3607
+ // A name, or a path to a Theme File not yet in the themes folder.
3608
+ const load = async (ref) => {
3609
+ if (t.THEME_ID_RE.test(ref) && !ref.endsWith('.json'))
3610
+ return { id: ref, theme: await t.exportTheme(paths, ref) };
3611
+ const r = await t.readThemeFile(resolve(ref));
3612
+ if (!r.theme)
3613
+ throw new UserError(`${ref} ${r.problems.join('; ')}`);
3614
+ for (const w of r.warnings)
3615
+ io.err(c.yellow(`! ${w}`));
3616
+ return { id: basename(ref, '.json'), theme: r.theme };
3617
+ };
3618
+ if (sub === 'list') {
3619
+ if (target)
3620
+ throw new UsageError(usage);
3621
+ const now = await active();
3622
+ const themes = (await t.listThemes(paths)).map((e) => ({
3623
+ id: e.id,
3624
+ name: e.name,
3625
+ source: e.source,
3626
+ ...(e.path ? { path: tilde(e.path, paths.home) } : {}),
3627
+ active: e.id === now,
3628
+ problems: e.problems,
3629
+ warnings: e.warnings,
3630
+ }));
3631
+ if (wantJson)
3632
+ json(io, { folder: tilde(t.themesDir(paths), paths.home), themes });
3633
+ else {
3634
+ for (const e of themes) {
3635
+ const mark = e.active ? c.green('●') : ' ';
3636
+ io.out(`${mark} ${e.id.padEnd(14)} ${e.name}${e.source === 'builtin' ? c.dim(' (built in)') : ''}`);
3637
+ for (const p of e.problems)
3638
+ io.out(c.red(` ✗ ${p}${e.path ? ` (${e.path})` : ''}`));
3639
+ for (const w of e.warnings)
3640
+ io.out(c.yellow(` ! ${w}`));
3641
+ }
3642
+ io.out(c.dim(`Switch: sideby theme use <name>. Your Theme Files go in ${tilde(t.themesDir(paths), paths.home)}.`));
3643
+ }
3644
+ return 0;
3645
+ }
3646
+ if (sub === 'use') {
3647
+ const undo = a.flags.has('undo');
3648
+ if (undo === Boolean(target))
3649
+ throw new UsageError('usage: sideby theme use <name> | sideby theme use --undo | sideby theme use default [--json]');
3650
+ let r;
3651
+ try {
3652
+ r = undo ? await t.undoTheme(paths) : await t.useTheme(paths, target);
3653
+ }
3654
+ catch (e) {
3655
+ throw new UserError(e.message);
3656
+ }
3657
+ if (wantJson)
3658
+ json(io, { before: r.before, after: r.after, changed: r.changed ?? true });
3659
+ else
3660
+ io.out(r.changed === false
3661
+ ? `Already using ${r.after}.`
3662
+ : `${c.green('✓')} Theme ${r.before} → ${r.after}. The Panel shows it on its next refresh${undo ? '.' : '; undo with `sideby theme use --undo`.'}`);
3663
+ return 0;
3664
+ }
3665
+ if (sub === 'check') {
3666
+ if (!target)
3667
+ throw new UsageError(usage);
3668
+ const { id, theme } = await load(target);
3669
+ const pairs = t.contrastPairs(t.themeColors(theme));
3670
+ const failing = pairs.filter((p) => !p.ok);
3671
+ if (wantJson)
3672
+ json(io, { id, ok: failing.length === 0, pairs, warnings: [] });
3673
+ else {
3674
+ for (const p of pairs)
3675
+ if (p.ratio !== undefined)
3676
+ io.out(`${p.ok ? c.green('✓') : c.red('✗')} ${p.mode.padEnd(5)} ${`${p.fg} on ${p.bg}`.padEnd(24)} ${p.ratio.toFixed(2)}:1 (needs ${p.min})${p.suggest ? c.dim(` try ${p.fg}: ${p.suggest}`) : ''}`);
3677
+ io.out(failing.length
3678
+ ? c.yellow(`${failing.length} pair(s) too faint. The Panel moves them to the value shown; set those values in the file to choose them yourself.`)
3679
+ : `${c.green('✓')} Every pair is readable in light and dark.`);
3680
+ }
3681
+ return failing.length ? 1 : 0;
3682
+ }
3683
+ if (sub === 'preview') {
3684
+ if (!target)
3685
+ throw new UsageError(usage);
3686
+ const { theme } = await load(target);
3687
+ await t.setPreview(paths, theme);
3688
+ const { backgroundPanelPort, findRunningPanel } = await import('../panel/background.js');
3689
+ const port = await backgroundPanelPort(paths);
3690
+ const url = port ? await findRunningPanel(paths, port) : undefined;
3691
+ if (!url) {
3692
+ if (wantJson)
3693
+ json(io, {
3694
+ opened: false,
3695
+ hint: 'start the Panel with `sideby ui --background`, then run this again',
3696
+ });
3697
+ else
3698
+ io.err(c.yellow('The Panel is not running. Start it with `sideby ui --background`, then run this again.'));
3699
+ return 1;
3700
+ }
3701
+ const { openBrowser } = await import('../panel/server.js');
3702
+ const opened = await openBrowser(`${url}?theme=preview`);
3703
+ if (wantJson)
3704
+ json(io, { opened, url: `${url}?theme=preview` });
3705
+ else
3706
+ io.out(`Showing ${theme.name} for this one look (${url}?theme=preview); your Theme stays the same. Keep it with \`sideby theme import\` and \`sideby theme use\`.`);
3707
+ return 0;
3708
+ }
3709
+ if (sub === 'import') {
3710
+ if (!target)
3711
+ throw new UsageError(usage);
3712
+ const { id: fromName, theme } = await load(target);
3713
+ const idFlag = a.flags.get('id');
3714
+ const id = typeof idFlag === 'string' ? idFlag : fromName;
3715
+ const dest = join(t.themesDir(paths), `${id}.json`);
3716
+ const exists = await stat(dest).then(() => true, () => false);
3717
+ if (exists && !a.flags.has('yes')) {
3718
+ if (wantJson)
3719
+ json(io, { id, path: tilde(dest, paths.home), replaced: false, exists: true });
3720
+ else
3721
+ io.out(`${tilde(dest, paths.home)} already exists. Replace it with \`sideby theme import ${target} --yes\`.`);
3722
+ return 10;
3723
+ }
3724
+ let path;
3725
+ try {
3726
+ path = await t.saveThemeFile(paths, id, theme);
3727
+ }
3728
+ catch (e) {
3729
+ throw new UserError(e.message);
3730
+ }
3731
+ if (wantJson)
3732
+ json(io, { id, path: tilde(path, paths.home), replaced: exists });
3733
+ else
3734
+ io.out(`${c.green('✓')} Saved ${theme.name} as ${id}. Use it with \`sideby theme use ${id}\`.`);
3735
+ return 0;
3736
+ }
3737
+ if (sub === 'export') {
3738
+ if (!target)
3739
+ throw new UsageError(usage);
3740
+ let theme;
3741
+ try {
3742
+ theme = await t.exportTheme(paths, target);
3743
+ }
3744
+ catch (e) {
3745
+ throw new UserError(e.message);
3746
+ }
3747
+ const text = `${JSON.stringify(theme, null, 2)}\n`;
3748
+ const out = a.flags.get('out');
3749
+ if (typeof out === 'string') {
3750
+ await writeFile(resolve(out), text, { flag: 'wx' }).catch((e) => {
3751
+ throw new UserError(e.code === 'EEXIST'
3752
+ ? `${out} already exists; pick another file`
3753
+ : `cannot write ${out} (${e.code})`);
3754
+ });
3755
+ if (wantJson)
3756
+ json(io, { id: target, out });
3757
+ else
3758
+ io.out(`${c.green('✓')} Wrote ${out}. Edit it, then \`sideby theme check ${out}\` and \`sideby theme import ${out}\`.`);
3759
+ }
3760
+ else if (wantJson)
3761
+ json(io, { id: target, theme });
3762
+ else
3763
+ io.out(text.trimEnd());
3764
+ return 0;
3765
+ }
3766
+ if (sub === 'remove') {
3767
+ if (!target)
3768
+ throw new UsageError(usage);
3769
+ if (!a.flags.has('yes')) {
3770
+ if (wantJson)
3771
+ json(io, { id: target, removed: false });
3772
+ else
3773
+ io.out(`This deletes the Theme File ${target}. Run \`sideby theme remove ${target} --yes\` to do it.`);
3774
+ return 10;
3775
+ }
3776
+ let r;
3777
+ try {
3778
+ r = await t.removeThemeFile(paths, target);
3779
+ }
3780
+ catch (e) {
3781
+ throw new UserError(e.message);
3782
+ }
3783
+ if (wantJson)
3784
+ json(io, { id: target, removed: true, wasActive: r.wasActive });
3785
+ else
3786
+ io.out(`${c.green('✓')} Removed ${tilde(r.path, paths.home)}${r.wasActive ? '; the Panel is back on Sky' : ''}.`);
3787
+ return 0;
3788
+ }
3789
+ throw new UsageError(usage);
3790
+ }
@@ -88,6 +88,9 @@ const AccountStatus = Type.Intersect([
88
88
  pinned: Type.Optional(Type.Literal(true, {
89
89
  description: 'Pinned to the top of its family in the Panel and `sideby list` (spec §3.25). Display only; absent when not pinned.',
90
90
  })),
91
+ hidden: Type.Optional(Type.Literal(true, {
92
+ description: 'Hidden from the Panel, the menu bar and the text of `sideby list` (spec §3.25). Display only; set by `sideby list`, absent when shown.',
93
+ })),
91
94
  problems: Type.Optional(Type.Array(Str)),
92
95
  desktopApp: Type.Optional(Type.Object({ app: Str, installed: Type.Boolean(), running: Type.Boolean() }, {
93
96
  description: "The family's desktop app for this account (macOS, subscription accounts of claude and codex): whether it is installed and whether this account's own window runs now. Open it with `sideby desktop <account>`.",
@@ -110,6 +113,9 @@ const FamilyInfo = Type.Object({
110
113
  mainOnly: Type.Optional(Type.Literal(true, {
111
114
  description: 'The Host keeps one sign-in per computer, so sideby knows only its Main Account and refuses to create others (ADR-0047).',
112
115
  })),
116
+ hidden: Type.Optional(Type.Literal(true, {
117
+ description: 'Hidden from the Panel, the menu bar and the text of `sideby list` (spec §3.25). Display only; set by `sideby list`, absent when shown.',
118
+ })),
113
119
  });
114
120
  const ShareModeSchema = Type.Union(['link', 'copy', 'link-or-copy', 'link-or-local', 'local', 'local-if-api', 'info', 'json-key'].map((m) => Type.Literal(m)));
115
121
  const FamilyDetail = Type.Intersect([
@@ -310,6 +316,8 @@ const Display = Type.Object({
310
316
  families: Type.Optional(Type.Array(Str)),
311
317
  accounts: Type.Optional(Type.Record(Str, Type.Array(Str))),
312
318
  pinned: Type.Optional(Type.Record(Str, Type.Array(Str))),
319
+ hiddenFamilies: Type.Optional(Type.Array(Str)),
320
+ hidden: Type.Optional(Type.Record(Str, Type.Array(Str))),
313
321
  });
314
322
  const PinResult = Type.Object({
315
323
  schemaVersion: Version,
@@ -319,6 +327,15 @@ const PinResult = Type.Object({
319
327
  message: Str,
320
328
  display: Display,
321
329
  });
330
+ const HideResult = Type.Object({
331
+ schemaVersion: Version,
332
+ target: Type.String({ description: 'The Family id or account ref that was hidden or shown again.' }),
333
+ kind: Type.Union([Type.Literal('family'), Type.Literal('account')]),
334
+ hidden: Type.Boolean(),
335
+ changed: Type.Boolean(),
336
+ message: Str,
337
+ display: Display,
338
+ });
322
339
  const Skipped = Type.Optional(Type.Array(Type.Object({ ref: Str, reason: Str })));
323
340
  const HandoffSettingsOut = HandoffSettingsSchema;
324
341
  const Takeover = Type.Array(Type.Object({
@@ -490,9 +507,12 @@ export const OUTPUT_SCHEMAS = {
490
507
  display: Display,
491
508
  families: Type.Array(Type.Object({
492
509
  family: Str,
493
- accounts: Type.Array(Type.Object({ name: Str, ref: Str, pinned: Type.Boolean() })),
510
+ hidden: Type.Boolean(),
511
+ accounts: Type.Array(Type.Object({ name: Str, ref: Str, pinned: Type.Boolean(), hidden: Type.Boolean() })),
494
512
  })),
495
513
  }),
514
+ hide: HideResult,
515
+ unhide: HideResult,
496
516
  'quota-check': Type.Object({
497
517
  schemaVersion: Version,
498
518
  family: Str,
@@ -1383,6 +1403,61 @@ export const OUTPUT_SCHEMAS = {
1383
1403
  meaning: Type.Optional(Str),
1384
1404
  takes: Type.Optional(Str),
1385
1405
  }),
1406
+ // `sideby theme` (spec §3.34, ADR-0050).
1407
+ theme: Type.Object({
1408
+ schemaVersion: Version,
1409
+ folder: Type.String({ description: 'Where Theme Files go, with ~ for the home folder.' }),
1410
+ themes: Type.Array(Type.Object({
1411
+ id: Type.String({ description: 'The name to pass to `sideby theme use`.' }),
1412
+ name: Str,
1413
+ source: Type.Union([Type.Literal('builtin'), Type.Literal('file')]),
1414
+ path: Type.Optional(Str),
1415
+ active: Type.Boolean(),
1416
+ problems: Type.Array(Str, { description: 'Why the Theme cannot be used; empty when it can.' }),
1417
+ warnings: Type.Array(Str, { description: 'Keys of the file that were ignored.' }),
1418
+ })),
1419
+ }),
1420
+ 'theme-use': Type.Object({ schemaVersion: Version, before: Str, after: Str, changed: Type.Boolean() }),
1421
+ 'theme-check': Type.Object({
1422
+ schemaVersion: Version,
1423
+ id: Str,
1424
+ ok: Type.Boolean({ description: 'Every pair passes; the command exits 1 otherwise.' }),
1425
+ pairs: Type.Array(Type.Object({
1426
+ mode: Type.Union([Type.Literal('light'), Type.Literal('dark')]),
1427
+ fg: Str,
1428
+ bg: Str,
1429
+ ratio: Type.Optional(Type.Number({ description: 'WCAG 2 contrast; missing when a value is not #rrggbb.' })),
1430
+ min: Type.Number(),
1431
+ ok: Type.Boolean(),
1432
+ suggest: Type.Optional(Type.String({ description: 'A value for fg that passes.' })),
1433
+ })),
1434
+ warnings: Type.Array(Str),
1435
+ }),
1436
+ 'theme-preview': Type.Object({
1437
+ schemaVersion: Version,
1438
+ opened: Type.Boolean(),
1439
+ url: Type.Optional(Str),
1440
+ hint: Type.Optional(Str),
1441
+ }),
1442
+ 'theme-import': Type.Object({
1443
+ schemaVersion: Version,
1444
+ id: Str,
1445
+ path: Str,
1446
+ replaced: Type.Boolean(),
1447
+ exists: Type.Optional(Type.Boolean({ description: 'A Theme File of that name exists; rerun with --yes to replace it.' })),
1448
+ }),
1449
+ 'theme-export': Type.Object({
1450
+ schemaVersion: Version,
1451
+ id: Str,
1452
+ out: Type.Optional(Str),
1453
+ theme: Type.Optional(Type.Unknown({ description: 'The Theme File, when no --out was given.' })),
1454
+ }),
1455
+ 'theme-remove': Type.Object({
1456
+ schemaVersion: Version,
1457
+ id: Str,
1458
+ removed: Type.Boolean(),
1459
+ wasActive: Type.Optional(Type.Boolean()),
1460
+ }),
1386
1461
  'config-set': Type.Object({
1387
1462
  schemaVersion: Version,
1388
1463
  action: Type.Union([Type.Literal('set'), Type.Literal('unset')]),