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.
Files changed (97) hide show
  1. package/README.md +1 -0
  2. package/ai-tasks.json +14 -0
  3. package/dist/build.json +1 -1
  4. package/dist/src/cli/commands.d.ts +7 -0
  5. package/dist/src/cli/commands.js +441 -31
  6. package/dist/src/cli/format.js +3 -2
  7. package/dist/src/cli/json-schemas.js +157 -47
  8. package/dist/src/cli/main.js +38 -7
  9. package/dist/src/core/accounts.d.ts +6 -1
  10. package/dist/src/core/accounts.js +16 -3
  11. package/dist/src/core/ask.d.ts +2 -1
  12. package/dist/src/core/ask.js +12 -4
  13. package/dist/src/core/claude-settings-file.d.ts +57 -0
  14. package/dist/src/core/claude-settings-file.js +104 -2
  15. package/dist/src/core/config.d.ts +34 -16
  16. package/dist/src/core/config.js +58 -5
  17. package/dist/src/core/create.js +4 -1
  18. package/dist/src/core/desktop-app.js +5 -1
  19. package/dist/src/core/handoff-overview.d.ts +4 -1
  20. package/dist/src/core/handoff-overview.js +3 -2
  21. package/dist/src/core/handoff-rules.d.ts +34 -0
  22. package/dist/src/core/handoff-rules.js +115 -0
  23. package/dist/src/core/handoff-select.js +45 -28
  24. package/dist/src/core/handoff-status.d.ts +37 -7
  25. package/dist/src/core/handoff-status.js +95 -19
  26. package/dist/src/core/handoff.d.ts +4 -1
  27. package/dist/src/core/handoff.js +8 -5
  28. package/dist/src/core/inbound.d.ts +11 -3
  29. package/dist/src/core/inbound.js +26 -74
  30. package/dist/src/core/launch.js +6 -4
  31. package/dist/src/core/quota-levels.d.ts +13 -2
  32. package/dist/src/core/quota-levels.js +21 -3
  33. package/dist/src/core/remote-control.d.ts +10 -12
  34. package/dist/src/core/remote-control.js +29 -86
  35. package/dist/src/core/themes.d.ts +107 -0
  36. package/dist/src/core/themes.js +463 -0
  37. package/dist/src/core/tuning-apply.js +12 -20
  38. package/dist/src/families/agy/index.d.ts +8 -0
  39. package/dist/src/families/agy/index.js +53 -0
  40. package/dist/src/families/agy/quota.d.ts +9 -0
  41. package/dist/src/families/agy/quota.js +110 -0
  42. package/dist/src/families/index.js +7 -0
  43. package/dist/src/families/logos.d.ts +10 -0
  44. package/dist/src/families/logos.js +12 -1
  45. package/dist/src/menubar/script.js +26 -3
  46. package/dist/src/menubar/snapshot.d.ts +33 -6
  47. package/dist/src/menubar/snapshot.js +138 -43
  48. package/dist/src/menubar/strings.d.ts +18 -2
  49. package/dist/src/menubar/strings.js +18 -2
  50. package/dist/src/panel/handler.d.ts +4 -1
  51. package/dist/src/panel/handler.js +206 -46
  52. package/dist/src/panel/i18n.d.ts +106 -7
  53. package/dist/src/panel/i18n.js +260 -62
  54. package/dist/src/panel/page-logic.d.ts +67 -20
  55. package/dist/src/panel/page-logic.js +74 -7
  56. package/dist/src/panel/page-script.js +522 -124
  57. package/dist/src/panel/page-styles.d.ts +2 -0
  58. package/dist/src/panel/page-styles.js +157 -34
  59. package/dist/src/panel/page.js +3 -3
  60. package/dist/src/panel/theme.d.ts +6 -1
  61. package/dist/src/panel/theme.js +4 -0
  62. package/dist/src/panel/themes.d.ts +14 -0
  63. package/dist/src/panel/themes.js +162 -0
  64. package/dist/src/plugins/check.js +27 -13
  65. package/dist/src/plugins/loader.d.ts +11 -0
  66. package/dist/src/plugins/loader.js +47 -1
  67. package/dist/src/runtime.d.ts +9 -2
  68. package/dist/src/runtime.js +12 -5
  69. package/dist/src/types.d.ts +35 -5
  70. package/package.json +2 -2
  71. package/schemas/config.json +45 -2
  72. package/schemas/families.json +13 -5
  73. package/schemas/handoff-disable.json +22 -0
  74. package/schemas/handoff-enable.json +22 -0
  75. package/schemas/handoff-rules.json +302 -0
  76. package/schemas/handoff-status.json +26 -0
  77. package/schemas/hide.json +157 -0
  78. package/schemas/list.json +15 -0
  79. package/schemas/menubar-snapshot.json +309 -2
  80. package/schemas/order.json +26 -1
  81. package/schemas/pin.json +17 -0
  82. package/schemas/theme-check.json +140 -0
  83. package/schemas/theme-export.json +86 -0
  84. package/schemas/theme-import.json +92 -0
  85. package/schemas/theme-preview.json +86 -0
  86. package/schemas/theme-remove.json +87 -0
  87. package/schemas/theme-use.json +88 -0
  88. package/schemas/theme.json +137 -0
  89. package/schemas/unhide.json +157 -0
  90. package/schemas/unpin.json +17 -0
  91. package/skills/sideby/SKILL.md +5 -2
  92. package/skills/sideby/references/accounts.md +1 -0
  93. package/skills/sideby/references/ai-tasks.md +1 -1
  94. package/skills/sideby/references/handoff.md +7 -3
  95. package/skills/sideby/references/panel.md +9 -0
  96. package/skills/sideby/references/quota.md +3 -1
  97. package/skills/sideby/references/themes.md +47 -0
@@ -4,12 +4,30 @@
4
4
  */
5
5
  export const QUOTA_FAIL_PERCENT = 85;
6
6
  export const QUOTA_WARN_PERCENT = 60;
7
+ /**
8
+ * Takeover Limit (spec §3.17 "接力规则"): an Account more used than this does not take over a Handoff, so the next
9
+ * Account starts with room to work. It sits this many points below the Handoff Threshold and moves with it.
10
+ */
11
+ export const TAKEOVER_GAP = 10;
12
+ export function takeoverLimit(threshold) {
13
+ return Math.max(1, threshold - TAKEOVER_GAP);
14
+ }
7
15
  /** Days of Usage every Family reports. */
8
16
  export const USAGE_DAYS = 7;
9
- /** Shared by the Panel and menu bar. Self-contained so the Panel can inline it without other module state. */
10
- export function quotaIsStale(quota, now) {
17
+ /**
18
+ * Shared by the Panel and menu bar. Self-contained so the Panel can inline it without other module state.
19
+ * A reading over an hour old is still current when `lastUseAt`, the newest use of its login on this computer, came at
20
+ * most 10 minutes after it (a session's last records land after its last status line): nothing here has used the
21
+ * Quota since (spec §3.31). Use on the web or another computer cannot be seen; the hover text says so.
22
+ */
23
+ export function quotaIsStale(quota, now, lastUseAt) {
11
24
  const at = Date.parse(quota.observedAt);
12
- return Boolean(quota.fetchError) || !Number.isFinite(at) || now - at > 3600_000 || at - now > 60_000;
25
+ if (quota.fetchError || !Number.isFinite(at) || at - now > 60_000)
26
+ return true;
27
+ if (now - at <= 3600_000)
28
+ return false;
29
+ const used = lastUseAt ? Date.parse(lastUseAt) : Number.NaN;
30
+ return !(Number.isFinite(used) && used - at <= 600_000);
13
31
  }
14
32
  export function quotaLevel(usedPercent) {
15
33
  if (usedPercent >= QUOTA_FAIL_PERCENT)
@@ -1,4 +1,5 @@
1
1
  import type { Account, ReadContext } from '../types.ts';
2
+ import { type SettingsProblem } from './claude-settings-file.ts';
2
3
  export declare const RC_KEY = "remoteControlAtStartup";
3
4
  /**
4
5
  * `on`: every session connects by itself; `default`: no key, so the organization's or Claude Code's default decides
@@ -11,19 +12,13 @@ export interface RemoteControlGroup {
11
12
  /** Refs of the Accounts whose `settings.json` is `file`, in discovery order. */
12
13
  accounts: string[];
13
14
  state: RemoteControlState;
15
+ /** For `blocked` and `missing`: why, as a code the Panel words in its language. */
16
+ why?: SettingsProblem;
14
17
  /** For `blocked` and `missing`: why, and what to do. */
15
18
  reason?: string;
16
19
  /** sideby set it here and can put the earlier value back. */
17
20
  undo: boolean;
18
21
  }
19
- export interface RemoteControlUndoRecord {
20
- file: string;
21
- /** The value before sideby wrote, or null when the key was not there. */
22
- previous: boolean | null;
23
- /** The value sideby wrote; records from before `on` existed lack it and mean `false`. */
24
- wrote?: boolean;
25
- at: string;
26
- }
27
22
  export interface RemoteControlChange {
28
23
  ok: boolean;
29
24
  /** One line per group that was meant to change. */
@@ -37,10 +32,13 @@ export interface RemoteControlChange {
37
32
  }
38
33
  /** Every Claude Account's setting, grouped by the file it lives in. Writes nothing. */
39
34
  export declare function remoteControlGroups(accounts: readonly Account[], ctx: ReadContext): Promise<RemoteControlGroup[]>;
40
- /** The groups `off` would change: those that are on, or follow a default that may be on. */
41
- export declare function groupsToTurnOff(groups: readonly RemoteControlGroup[]): RemoteControlGroup[];
42
- /** The groups `on` would change: those that are off, or follow a default that may be off. */
43
- export declare function groupsToTurnOn(groups: readonly RemoteControlGroup[]): RemoteControlGroup[];
35
+ /**
36
+ * The groups `on` or `off` would change: those that do not hold that side yet, a default counting as either. Self-
37
+ * contained, so the Panel page runs this same function (page-script.ts).
38
+ */
39
+ export declare function remoteControlTodo<G extends {
40
+ state: string;
41
+ }>(groups: readonly G[], to: 'on' | 'off'): G[];
44
42
  /** What `on`, `off` or `undo` says when no file needs it: always `ok: false`, so the CLI exits 1. */
45
43
  export declare function remoteControlNothingToDo(action: 'on' | 'off' | 'undo', groups: readonly RemoteControlGroup[]): RemoteControlChange;
46
44
  /**
@@ -1,60 +1,40 @@
1
- // Remote Control at startup (spec §3.22, ADR-0017): reads and writes one key, `remoteControlAtStartup`, of each
2
- // Claude Account's `settings.json`. Accounts that share a file (a link to the Main Account's) form one group and one
3
- // write. Nothing but that key is ever read out of the file into an output, an error or the undo record; writes go
4
- // through `writeIfUnchanged`, keep every other key, and never create, replace or retarget a link.
5
- import { rm } from 'node:fs/promises';
6
- import { keyRecordPath, readKeyRecord, readObject, settingsFileGroups, writeKeyRecord, writeSettingsKey, } from './claude-settings-file.js';
1
+ import { readSettingsGroups, settingsKey } from './claude-settings-file.js';
7
2
  export const RC_KEY = 'remoteControlAtStartup';
8
- const NO_SETTINGS = 'this account has no settings.json; run `sideby doctor --fix` so it shares the main one, then try again';
3
+ // Records from before `on` existed lack `wrote` and mean `false`.
4
+ const rc = settingsKey(RC_KEY, 'remote-control', { legacyWrote: false });
9
5
  function stateOf(v) {
10
6
  return v === true ? 'on' : v === false ? 'off' : 'default';
11
7
  }
12
- const RECORDS = 'remote-control';
13
- const recordPath = (ctx, file) => keyRecordPath(ctx.stateDir, RECORDS, file);
14
- async function readRecord(ctx, file) {
15
- const r = await readKeyRecord(ctx.stateDir, RECORDS, file);
16
- return r && (r.previous === null || typeof r.previous === 'boolean')
17
- ? r
18
- : null;
19
- }
20
8
  /** Every Claude Account's setting, grouped by the file it lives in. Writes nothing. */
21
9
  export async function remoteControlGroups(accounts, ctx) {
22
10
  const out = [];
23
- for (const { file, accounts: refs, where } of await settingsFileGroups(accounts)) {
24
- const group = { file, accounts: refs, state: 'missing', undo: false };
25
- out.push(group);
26
- if (where.broken) {
27
- group.state = 'blocked';
28
- group.reason =
29
- 'settings.json is a link to a file that does not exist; run `sideby doctor` to see how to fix it';
30
- }
31
- else if (!where.exists) {
32
- group.reason = NO_SETTINGS;
33
- }
34
- else {
35
- const read = await readObject(where.file);
36
- if ('error' in read) {
37
- group.state = 'blocked';
38
- group.reason = `settings.json cannot be changed safely: ${read.error}. Fix or move the file, then try again`;
39
- }
40
- else {
41
- group.state = stateOf(read.obj[RC_KEY]);
42
- const record = await readRecord(ctx, where.file);
43
- group.undo = record !== null && read.obj[RC_KEY] === (record.wrote ?? false);
44
- }
45
- }
11
+ for (const g of await readSettingsGroups(accounts)) {
12
+ if ('why' in g)
13
+ out.push({
14
+ file: g.file,
15
+ accounts: g.accounts,
16
+ state: g.why === 'no-settings' ? 'missing' : 'blocked',
17
+ why: g.why,
18
+ reason: g.reason,
19
+ undo: false,
20
+ });
21
+ else
22
+ out.push({
23
+ file: g.file,
24
+ accounts: g.accounts,
25
+ state: stateOf(g.obj[RC_KEY]),
26
+ undo: await rc.undoable(ctx.stateDir, g.file, g.obj),
27
+ });
46
28
  }
47
29
  return out;
48
30
  }
49
- /** The groups `off` would change: those that are on, or follow a default that may be on. */
50
- export function groupsToTurnOff(groups) {
51
- return groups.filter((g) => g.state === 'on' || g.state === 'default');
52
- }
53
- /** The groups `on` would change: those that are off, or follow a default that may be off. */
54
- export function groupsToTurnOn(groups) {
55
- return groups.filter((g) => g.state === 'off' || g.state === 'default');
31
+ /**
32
+ * The groups `on` or `off` would change: those that do not hold that side yet, a default counting as either. Self-
33
+ * contained, so the Panel page runs this same function (page-script.ts).
34
+ */
35
+ export function remoteControlTodo(groups, to) {
36
+ return groups.filter((g) => g.state === 'default' || g.state === (to === 'on' ? 'off' : 'on'));
56
37
  }
57
- const writeKey = writeSettingsKey;
58
38
  /** What `on`, `off` or `undo` says when no file needs it: always `ok: false`, so the CLI exits 1. */
59
39
  export function remoteControlNothingToDo(action, groups) {
60
40
  if (action === 'undo')
@@ -78,30 +58,10 @@ export function remoteControlNothingToDo(action, groups) {
78
58
  */
79
59
  export async function setRemoteControl(accounts, ctx, to) {
80
60
  const groups = await remoteControlGroups(accounts, ctx);
81
- const todo = to ? groupsToTurnOn(groups) : groupsToTurnOff(groups);
61
+ const todo = remoteControlTodo(groups, to ? 'on' : 'off');
82
62
  if (todo.length === 0)
83
63
  return remoteControlNothingToDo(to ? 'on' : 'off', groups);
84
- const results = [];
85
- for (const g of todo) {
86
- let previous = null;
87
- const failed = await writeKey(g.file, (obj) => {
88
- previous = typeof obj[RC_KEY] === 'boolean' ? obj[RC_KEY] : null;
89
- obj[RC_KEY] = to;
90
- return obj;
91
- }, (obj) => (obj[RC_KEY] === to ? `It was turned ${to ? 'on' : 'off'} meanwhile; nothing changed.` : null));
92
- if (failed) {
93
- results.push({ file: g.file, accounts: g.accounts, ok: false, message: failed });
94
- continue;
95
- }
96
- const record = {
97
- file: g.file,
98
- previous,
99
- wrote: to,
100
- at: new Date().toISOString(),
101
- };
102
- await writeKeyRecord(ctx.stateDir, RECORDS, g.file, record);
103
- results.push({ file: g.file, accounts: g.accounts, ok: true, message: to ? 'Turned on.' : 'Turned off.' });
104
- }
64
+ const results = await rc.set(ctx.stateDir, todo, to, (v) => (v === to ? `It was turned ${to ? 'on' : 'off'} meanwhile; nothing changed.` : null), to ? 'Turned on.' : 'Turned off.');
105
65
  const ok = results.every((r) => r.ok);
106
66
  return {
107
67
  ok,
@@ -126,24 +86,7 @@ export async function undoRemoteControlOff(accounts, ctx) {
126
86
  const todo = groupsToUndo(await remoteControlGroups(accounts, ctx));
127
87
  if (todo.length === 0)
128
88
  return remoteControlNothingToDo('undo', []);
129
- const results = [];
130
- for (const g of todo) {
131
- const record = await readRecord(ctx, g.file);
132
- if (!record)
133
- continue;
134
- const failed = await writeKey(g.file, (obj) => {
135
- if (record.previous === null)
136
- delete obj[RC_KEY];
137
- else
138
- obj[RC_KEY] = record.previous;
139
- return obj;
140
- }, (obj) => obj[RC_KEY] === (record.wrote ?? false)
141
- ? null
142
- : 'The setting was changed after sideby set it, so it was left alone.');
143
- if (!failed)
144
- await rm(recordPath(ctx, g.file), { force: true });
145
- results.push({ file: g.file, accounts: g.accounts, ok: !failed, message: failed ?? 'Put back.' });
146
- }
89
+ const results = await rc.undo(ctx.stateDir, todo);
147
90
  const ok = results.length > 0 && results.every((r) => r.ok);
148
91
  return {
149
92
  ok,
@@ -0,0 +1,107 @@
1
+ import { type PanelThemeTokens } from '../panel/theme.ts';
2
+ import type { Paths } from './paths.ts';
3
+ export declare const THEME_ID_RE: RegExp;
4
+ export interface ThemeFile {
5
+ schemaVersion: 1;
6
+ name: string;
7
+ base?: string;
8
+ accent?: string;
9
+ light?: PanelThemeTokens;
10
+ dark?: PanelThemeTokens;
11
+ }
12
+ export interface ThemeEntry {
13
+ id: string;
14
+ name: string;
15
+ source: 'builtin' | 'file';
16
+ path?: string;
17
+ /** Page, card, accent tint, main button, dark page; for the Theme's card in Settings. */
18
+ swatches: string[];
19
+ /** Why this Theme cannot be used; empty when it can. */
20
+ problems: string[];
21
+ /** Keys that were ignored. */
22
+ warnings: string[];
23
+ }
24
+ export interface ResolvedColors {
25
+ id: string;
26
+ light: PanelThemeTokens;
27
+ dark: PanelThemeTokens;
28
+ /** How many colors were moved to pass the contrast check. */
29
+ adjusted: number;
30
+ /** Set when the chosen Theme could not be used and Sky stands in. */
31
+ fallback?: string;
32
+ }
33
+ export declare const themesDir: (paths: Paths) => string;
34
+ /**
35
+ * The name `sideby theme use` takes for "no Theme chosen": the Panel then shows the Default Theme on its own and,
36
+ * inside a Portal, the Portal's colors. It names no Theme File.
37
+ */
38
+ export declare const NO_THEME = "default";
39
+ /** Checks parsed JSON as a Theme File. Problems make it unusable; warnings are keys that were ignored. */
40
+ export declare function checkThemeData(data: unknown): {
41
+ theme?: ThemeFile;
42
+ problems: string[];
43
+ warnings: string[];
44
+ };
45
+ /** Reads one Theme File: a regular file of at most 64 KB, never followed through a link. */
46
+ export declare function readThemeFile(path: string): Promise<{
47
+ theme?: ThemeFile;
48
+ problems: string[];
49
+ warnings: string[];
50
+ }>;
51
+ export declare function listThemes(paths: Paths): Promise<ThemeEntry[]>;
52
+ /** A Theme File's colors before the contrast check: base, then accent roles, then the file's own tokens. */
53
+ export declare function themeColors(theme: ThemeFile): {
54
+ light: PanelThemeTokens;
55
+ dark: PanelThemeTokens;
56
+ };
57
+ /** The colors for a Theme id (Built-in or file), with failing pairs moved until they pass. Unknown or broken: Sky. */
58
+ export declare function resolveColors(paths: Paths, id: string | undefined): Promise<ResolvedColors>;
59
+ /** A 12-step scale around one color: step 9 is the color, the others follow the template's lightness. */
60
+ export declare function accentScale(hex: string, dark: boolean): string[];
61
+ /** The accent roles of a Theme generated from one color; neutrals and warning colors stay the base Theme's. */
62
+ export declare function accentTokens(hex: string): {
63
+ light: PanelThemeTokens;
64
+ dark: PanelThemeTokens;
65
+ };
66
+ export interface ContrastPair {
67
+ mode: 'light' | 'dark';
68
+ fg: keyof PanelThemeTokens;
69
+ bg: keyof PanelThemeTokens;
70
+ ratio?: number;
71
+ min: number;
72
+ ok: boolean;
73
+ /** A value for `fg` that passes; only when it fails. */
74
+ suggest?: string;
75
+ }
76
+ export declare function contrastPairs(c: {
77
+ light: PanelThemeTokens;
78
+ dark: PanelThemeTokens;
79
+ }): ContrastPair[];
80
+ /** Sets `panel.colorTheme`, keeping what it was so `undo` can put it back. */
81
+ export declare function useTheme(paths: Paths, id: string): Promise<{
82
+ before: string;
83
+ after: string;
84
+ changed: boolean;
85
+ }>;
86
+ /** Puts back the Theme from before the last `use`, only while config still holds what that `use` wrote. */
87
+ export declare function undoTheme(paths: Paths): Promise<{
88
+ before: string;
89
+ after: string;
90
+ }>;
91
+ /** Writes a checked Theme File into the themes folder. */
92
+ export declare function saveThemeFile(paths: Paths, id: string, theme: ThemeFile): Promise<string>;
93
+ export declare function removeThemeFile(paths: Paths, id: string): Promise<{
94
+ path: string;
95
+ wasActive: boolean;
96
+ }>;
97
+ /** 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. */
98
+ export declare function exportTheme(paths: Paths, id: string): Promise<ThemeFile>;
99
+ /** Keeps a Theme for one look at the Panel without choosing it (`sideby theme preview`). */
100
+ export declare function setPreview(paths: Paths, theme: ThemeFile): Promise<void>;
101
+ /** The previewed Theme's colors, if one was set in the last ten minutes. */
102
+ export declare function previewColors(paths: Paths): Promise<ResolvedColors | undefined>;
103
+ export declare function toOklch(hex: string): [number, number, number];
104
+ /** OKLCH to #rrggbb, lowering chroma until the color fits sRGB. */
105
+ export declare function fromOklch(L: number, C: number, H: number): string;
106
+ /** WCAG 2 contrast ratio of two #rrggbb colors. */
107
+ export declare function contrast(a: string, b: string): number;