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
@@ -10,6 +10,7 @@ export const MENUBAR_STRINGS = {
10
10
  statusOk: 'Plenty of quota',
11
11
  statusOld: 'Quota needs refreshing',
12
12
  detailOld: 'Some readings are old · refresh to check',
13
+ detailOldSession: 'Some readings are old · they update when a session runs in that account',
13
14
  statusLow: '{tool} is running low',
14
15
  detailOk: 'Highest next account: {account} ({p}% used)',
15
16
  detailLow: '{account} is at {p}% · switch tools or wait',
@@ -21,9 +22,16 @@ export const MENUBAR_STRINGS = {
21
22
  noData: 'no quota yet',
22
23
  olderReading: 'older reading',
23
24
  observedAt: 'Quota recorded at {time}',
25
+ observedJustNow: 'Quota read just now',
26
+ observedAgo: 'Quota read {time} ago',
27
+ olderReadingTip: 'These numbers may be old · click Refresh to check again',
28
+ olderReadingSessionTip: 'These numbers may be old · they update when a session runs in this account',
29
+ quietTip: 'Not used on this computer since · use on the web or other computers is not included',
30
+ fetchFailed: 'The last check failed: {error}',
31
+ windowTip: '{label}: {p}% used',
32
+ windowResetsTip: '{label}: {p}% used · resets in {time}',
24
33
  window: '{label} {p}%',
25
34
  resets: 'resets in {time}',
26
- resetsTip: '{label} resets in {time}',
27
35
  moreApi: 'API keys ({n})',
28
36
  moreSignedOut: '{n} signed out',
29
37
  moreMixed: '{n} more',
@@ -60,6 +68,7 @@ export const MENUBAR_STRINGS = {
60
68
  statusOk: '各工具额度充足',
61
69
  statusOld: '额度需要更新',
62
70
  detailOld: '部分额度是旧数据 · 请刷新确认',
71
+ detailOldSession: '部分额度是旧数据 · 在对应账号开一次会话就会更新',
63
72
  statusLow: '{tool} 额度吃紧',
64
73
  detailOk: '首选账号中最高:{account}(已用 {p}%)',
65
74
  detailLow: '首选 {account} 已用 {p}% · 可换工具或等重置',
@@ -71,9 +80,16 @@ export const MENUBAR_STRINGS = {
71
80
  noData: '暂无额度',
72
81
  olderReading: '旧数据',
73
82
  observedAt: '额度记录时间:{time}',
83
+ observedJustNow: '额度刚刚读取',
84
+ observedAgo: '额度读于 {time}前',
85
+ olderReadingTip: '这些数字可能已经过时 · 点“刷新”重新检查',
86
+ olderReadingSessionTip: '这些数字可能已经过时 · 在这个账号开一次会话就会更新',
87
+ quietTip: '之后这台电脑没用过这个账号 · 网页或其他电脑上的用量不在内',
88
+ fetchFailed: '上次检查没成功:{error}',
89
+ windowTip: '{label}:已用 {p}%',
90
+ windowResetsTip: '{label}:已用 {p}% · {time}后重置',
74
91
  window: '{label} {p}%',
75
92
  resets: '{time}后重置',
76
- resetsTip: '{label}额度将在 {time}后重置',
77
93
  moreApi: '{n} 个 API 密钥账号',
78
94
  moreSignedOut: '{n} 个未登录账号',
79
95
  moreMixed: '另外 {n} 个账号',
@@ -7,7 +7,7 @@ import { type InboundGroup } from '../core/inbound.ts';
7
7
  import { type LiveSession, type LiveSessionsResult, sessionCopyText } from '../core/live-sessions.ts';
8
8
  import { listMessages, type MessageReceipt, sendMessage } from '../core/messages.ts';
9
9
  import { type AccountModel } from '../core/model-choice.ts';
10
- import type { RemoteControlGroup } from '../core/remote-control.ts';
10
+ import { type RemoteControlGroup } from '../core/remote-control.ts';
11
11
  import * as update from '../core/update.ts';
12
12
  import type { AccountStatus, DoctorHistory, FamilyInfo, QuotaCheckInfo, Runtime } from '../runtime.ts';
13
13
  import type { Account, FamilyLogo, QuotaResult, QuotaSetupPlan, UsageResult } from '../types.ts';
@@ -149,6 +149,8 @@ export type PanelFamily = FamilyInfo & {
149
149
  tryCommand?: string[];
150
150
  /** AI Tasks start this Host with its permission checks on (`aiTaskArgs`, ADR-0031), so the AI dialog says so. */
151
151
  aiTaskSafe?: true;
152
+ /** "Refresh" can ask the Host for its Quota (`fetchQuota`); without it old numbers wait for a session (spec §3.31). */
153
+ quotaRefresh?: true;
152
154
  };
153
155
  /** What the Panel shows about updates (spec §3.23); absent when the handler was created with `updates: false`. */
154
156
  export interface PanelUpdate {
@@ -235,6 +237,7 @@ export interface PanelState {
235
237
  autoHandoff: {
236
238
  settings: HandoffSettings;
237
239
  starters: string[];
240
+ apiUndecided: boolean;
238
241
  };
239
242
  /** Claude settings files grouped as `sideby remote-control` shows them (spec §3.22); absent without Claude Accounts. */
240
243
  remoteControl?: RemoteControlView[];
@@ -14,16 +14,19 @@ import { UserError } from '../core/errors.js';
14
14
  import { planHandoff } from '../core/handoff.js';
15
15
  import { applyHandoffEnable, planHandoffEnable } from '../core/handoff-enable.js';
16
16
  import { handoffOverview } from '../core/handoff-overview.js';
17
+ import { apiUndecided, handoffRulesView } from '../core/handoff-rules.js';
17
18
  import { configureHandoff, handoffStatus } from '../core/handoff-status.js';
18
- import { acceptInbound, inboundGroups, undoInbound, waitingFiles, } from '../core/inbound.js';
19
+ import { acceptInbound, groupsToAccept, inboundGroups, undoInbound, waitingFiles, } from '../core/inbound.js';
19
20
  import { listLiveSessions, liveKey, referenceText, sessionCopyText, } from '../core/live-sessions.js';
20
21
  import { listMessages, sendMessage } from '../core/messages.js';
21
22
  import { accountModel, setAccountModel } from '../core/model-choice.js';
22
23
  import { tildify } from '../core/paths.js';
24
+ import { remoteControlTodo } from '../core/remote-control.js';
23
25
  import { openRunBoard, withRuns } from '../core/run-link.js';
24
26
  import { SECRET_VAR_NAME, secretVarFor, setSecret } from '../core/secret-file.js';
25
27
  import { SKILL_INSTALL } from '../core/skill-check.js';
26
28
  import { launchArgs, TERMINALS } from '../core/terminal.js';
29
+ import { checkThemeData, listThemes, NO_THEME, previewColors, removeThemeFile, resolveColors, saveThemeFile, undoTheme, useTheme, } from '../core/themes.js';
27
30
  import { MIN_CALLS } from '../core/tuning.js';
28
31
  import * as update from '../core/update.js';
29
32
  import { buildId, localBuild, packageVersion } from '../core/version.js';
@@ -34,7 +37,9 @@ import { MENUBAR_SCRIPT } from '../menubar/script.js';
34
37
  import { orcaTabs, switchOrcaTab, systemOrca } from './orca.js';
35
38
  import { renderPage } from './page.js';
36
39
  import { AI_TASK_KINDS } from './page-logic.js';
40
+ import { tokenStyles } from './page-styles.js';
37
41
  import { resolveTheme } from './theme.js';
42
+ import { BUILTIN_THEMES, DEFAULT_THEME_ID } from './themes.js';
38
43
  export const PANEL_VERSION = packageVersion();
39
44
  export const MAX_BODY_BYTES = 64 * 1024;
40
45
  /** Write requests allowed to wait behind the running one; more get 409. */
@@ -88,6 +93,7 @@ function keyFacts(def) {
88
93
  ...(def.secretFileMeansApi === false ? { keyAlways: true } : {}),
89
94
  ...(def.probe ? { tryCommand: [def.bin, ...def.probe.args] } : {}),
90
95
  ...(def.aiTaskArgs ? { aiTaskSafe: true } : {}),
96
+ ...(def.fetchQuota ? { quotaRefresh: true } : {}),
91
97
  };
92
98
  }
93
99
  let autostartOverride = {};
@@ -613,6 +619,7 @@ async function buildState(rt, opts) {
613
619
  starters: [...rt.families.values()]
614
620
  .filter((f) => f.handoff?.starts.length && HOOK_FAMILIES.includes(f.id))
615
621
  .map((f) => f.id),
622
+ apiUndecided: apiUndecided(rt, accounts.filter((a) => a.kind === 'api').length),
616
623
  },
617
624
  ...(upd ? { update: upd } : {}),
618
625
  ...(showBrowser ? { browser } : {}),
@@ -637,6 +644,8 @@ function displayBody(body) {
637
644
  for (const [k, v] of Object.entries(d)) {
638
645
  if (k === 'families')
639
646
  out.families = names(v, '"families"');
647
+ else if (k === 'hiddenFamilies')
648
+ out.hiddenFamilies = names(v, '"hiddenFamilies"');
640
649
  else if (k === 'accounts') {
641
650
  if (!v || typeof v !== 'object' || Array.isArray(v))
642
651
  throw new HttpError(400, '"accounts" must be an object');
@@ -647,19 +656,47 @@ function displayBody(body) {
647
656
  throw new HttpError(400, '"pinned" must be an object');
648
657
  out.pinned = Object.fromEntries(Object.entries(v).map(([f, list]) => [f, names(list, `"pinned.${f}"`)]));
649
658
  }
659
+ else if (k === 'hidden') {
660
+ if (!v || typeof v !== 'object' || Array.isArray(v))
661
+ throw new HttpError(400, '"hidden" must be an object');
662
+ out.hidden = Object.fromEntries(Object.entries(v).map(([f, list]) => [f, names(list, `"hidden.${f}"`)]));
663
+ }
650
664
  else
651
665
  throw new HttpError(400, `unknown key "${k}"`);
652
666
  }
653
667
  return out;
654
668
  }
655
- /** The `change` of a /api/handoff/configure body, with every field checked; unknown fields are refused. */
669
+ /**
670
+ * The `change` of a /api/handoff/configure body, with every field checked; unknown fields are refused. Null for a
671
+ * single setting removes it, as the `undo` of an earlier answer asks.
672
+ */
673
+ const HANDOFF_SINGLE_KEYS = new Set([
674
+ 'auto',
675
+ 'sameFamily',
676
+ 'otherFamilies',
677
+ 'api',
678
+ 'adaptive',
679
+ 'prepareAt',
680
+ 'threshold',
681
+ 'waitIfResetWithinMinutes',
682
+ 'countdownSeconds',
683
+ ]);
656
684
  function handoffChange(body) {
657
685
  const c = body.change;
658
686
  if (!c || typeof c !== 'object' || Array.isArray(c))
659
687
  throw new HttpError(400, '"change" must be an object');
660
688
  const out = {};
661
689
  for (const [k, v] of Object.entries(c)) {
662
- if (k === 'auto' || k === 'sameFamily') {
690
+ if (v === null && k !== 'familyOrder' && k !== 'crossOrganization' && k !== 'orders') {
691
+ if (!HANDOFF_SINGLE_KEYS.has(k))
692
+ throw new HttpError(400, `unknown setting "${k}"`);
693
+ out[k] = null;
694
+ }
695
+ else if (k === 'auto' ||
696
+ k === 'sameFamily' ||
697
+ k === 'otherFamilies' ||
698
+ k === 'api' ||
699
+ k === 'adaptive') {
663
700
  if (typeof v !== 'boolean')
664
701
  throw new HttpError(400, `"${k}" must be true or false`);
665
702
  out[k] = v;
@@ -672,6 +709,11 @@ function handoffChange(body) {
672
709
  throw new HttpError(400, `"${k}" must be a whole number`);
673
710
  out[k] = v;
674
711
  }
712
+ else if (k === 'familyOrder' || k === 'crossOrganization') {
713
+ if (!Array.isArray(v) || !v.every((n) => typeof n === 'string'))
714
+ throw new HttpError(400, `"${k}" must be a list of names`);
715
+ out[k] = [...v];
716
+ }
675
717
  else if (k === 'orders') {
676
718
  if (!Array.isArray(v) ||
677
719
  !v.every((o) => o &&
@@ -784,6 +826,67 @@ function writeQueue() {
784
826
  });
785
827
  };
786
828
  }
829
+ /** What the Theme dialog shows (spec §3.34); the config is read again, so a switch from the CLI shows at once. */
830
+ async function themesView(rt, portal) {
831
+ const chosen = (await loadConfig(rt.paths.configFile).catch(() => rt.config)).panel?.colorTheme ?? NO_THEME;
832
+ const colors = await resolveColors(rt.paths, chosen);
833
+ const portalColors = portal.light.length + portal.dark.length > 0;
834
+ // Inside a Portal, no Theme chosen means the Portal's colors: a card of their own, in use.
835
+ const pageCard = portalColors
836
+ ? [
837
+ {
838
+ id: NO_THEME,
839
+ name: "This page's colors",
840
+ source: 'portal',
841
+ swatches: portalSwatches(portal),
842
+ problems: [],
843
+ warnings: [],
844
+ },
845
+ ]
846
+ : [];
847
+ const listed = (await listThemes(rt.paths)).map((t) => ({
848
+ id: t.id,
849
+ name: t.name,
850
+ ...(t.source === 'builtin' ? { nameZh: BUILTIN_THEMES.find((b) => b.id === t.id)?.name.zh } : {}),
851
+ source: t.source,
852
+ swatches: t.swatches,
853
+ problems: t.problems,
854
+ warnings: t.warnings,
855
+ }));
856
+ const page = chosen === NO_THEME && portalColors;
857
+ return {
858
+ active: page ? NO_THEME : colors.id,
859
+ chosen,
860
+ adjusted: colors.adjusted,
861
+ ...(colors.fallback ? { fallback: colors.fallback } : {}),
862
+ portalColors,
863
+ // The token CSS the page swaps in.
864
+ css: tokenStyles(page ? portal : layerTheme(colors, portal)),
865
+ themes: [...pageCard, ...listed],
866
+ };
867
+ }
868
+ /** A Portal's own page, card, accent tint, main button and dark page, over the Default Theme's where it leaves one out. */
869
+ function portalSwatches(portal) {
870
+ const value = (decls, name) => decls
871
+ .findLast((d) => d.startsWith(`--${name}:`))
872
+ ?.slice(name.length + 3)
873
+ .trim();
874
+ const sky = BUILTIN_THEMES.find((b) => b.id === DEFAULT_THEME_ID)?.swatches ?? [];
875
+ return [
876
+ value(portal.light, 'bg') ?? sky[0],
877
+ value(portal.light, 'accent-soft') ?? sky[1],
878
+ value(portal.light, 'primary') ?? sky[2],
879
+ value(portal.dark, 'bg') ?? sky[3],
880
+ ].filter((c) => typeof c === 'string');
881
+ }
882
+ /**
883
+ * A Theme the user picked over the Portal's tokens (ADR-0050): its colors win over the Portal's, and what the Theme
884
+ * does not name (font, sizes, header) stays the Portal's.
885
+ */
886
+ function layerTheme(colors, portal) {
887
+ const own = resolveTheme({ light: colors.light, dark: colors.dark });
888
+ return { ...portal, light: [...portal.light, ...own.light], dark: [...portal.dark, ...own.dark] };
889
+ }
787
890
  export function createPanelHandler(opts) {
788
891
  const basePath = normalizeBase(opts.basePath);
789
892
  const allowed = new Set(opts.allowedHosts.map((h) => h.toLowerCase()));
@@ -846,6 +949,31 @@ export function createPanelHandler(opts) {
846
949
  toolScans.delete(id);
847
950
  }
848
951
  };
952
+ /**
953
+ * A change of one key in Claude's settings files that the page showed file by file before the user confirmed
954
+ * (Remote Control, spec §3.22; receiving Messages, ADR-0045). Without `confirm` it writes nothing and names the
955
+ * files; with it, `files` must be exactly the files the page showed, or nothing is written and `changedSince` says
956
+ * so, because a file the user never saw in the preview must not change. Undo passes no `todo`: it only puts back
957
+ * what sideby wrote, and its toast runs before the page has read the new state.
958
+ */
959
+ const previewedChange = (change) => ({
960
+ writes: (body) => body.confirm === true,
961
+ async run(body) {
962
+ const rt = await getRuntime();
963
+ const home = rt.paths.home;
964
+ const files = change.todo ? (await change.todo(rt)).map((g) => tildify(g.file, home)) : undefined;
965
+ if (!optBool(body, 'confirm'))
966
+ return { applied: false, ...(files ? { files } : {}) };
967
+ if (files) {
968
+ const saw = body.files;
969
+ const same = Array.isArray(saw) && saw.length === files.length && files.every((f) => saw.includes(f));
970
+ if (!same)
971
+ return { applied: false, changedSince: true, files };
972
+ }
973
+ const r = await change.apply(rt);
974
+ return { ...r, applied: true, results: r.results.map((x) => ({ ...x, file: tildify(x.file, home) })) };
975
+ },
976
+ });
849
977
  /** The switch of one LaunchAgent sideby writes: the Panel's login item or the Menu Bar Item. */
850
978
  const loginItemRoute = (agent) => ({
851
979
  writes: (body) => body.confirm === true,
@@ -956,6 +1084,41 @@ export function createPanelHandler(opts) {
956
1084
  return tryAccount(await getRuntime(), account);
957
1085
  },
958
1086
  },
1087
+ // Themes (spec §3.34): `use` a Theme, `undo` the last switch, `accent` saves and uses the Theme File custom.json
1088
+ // (the current Built-in Theme with that accent), `remove` deletes a Theme File. Answers what GET /api/themes does.
1089
+ '/api/theme': {
1090
+ async run(body) {
1091
+ const rt = await getRuntime();
1092
+ try {
1093
+ if (typeof body.use === 'string')
1094
+ await useTheme(rt.paths, body.use);
1095
+ else if (body.undo === true)
1096
+ await undoTheme(rt.paths);
1097
+ else if (typeof body.accent === 'string') {
1098
+ const current = (await loadConfig(rt.paths.configFile)).panel?.colorTheme;
1099
+ const base = BUILTIN_THEMES.some((t) => t.id === current) ? current : undefined;
1100
+ const checked = checkThemeData({
1101
+ schemaVersion: 1,
1102
+ name: 'Custom',
1103
+ ...(base ? { base } : {}),
1104
+ accent: body.accent,
1105
+ });
1106
+ if (!checked.theme)
1107
+ throw new Error(checked.problems[0]);
1108
+ await saveThemeFile(rt.paths, 'custom', checked.theme);
1109
+ await useTheme(rt.paths, 'custom');
1110
+ }
1111
+ else if (typeof body.remove === 'string')
1112
+ await removeThemeFile(rt.paths, body.remove);
1113
+ else
1114
+ throw new Error('send "use", "undo", "accent" or "remove"');
1115
+ }
1116
+ catch (err) {
1117
+ throw new HttpError(400, err.message);
1118
+ }
1119
+ return themesView(await getRuntime(), theme);
1120
+ },
1121
+ },
959
1122
  // Preferred Terminal and Custom terminal command (spec §3.28): `id` null or left out goes back to the guess;
960
1123
  // `custom` an empty string removes the template.
961
1124
  '/api/terminal': {
@@ -1139,31 +1302,16 @@ export function createPanelHandler(opts) {
1139
1302
  },
1140
1303
  },
1141
1304
  // Remote Control at startup (spec §3.22, ADR-0017): writes `remoteControlAtStartup` (false for off, true for on)
1142
- // into each Claude settings file that does not hold it yet; the page shows the files first, from the state.
1143
- '/api/remote-control/off': {
1144
- async run() {
1145
- const rt = await getRuntime();
1146
- const r = await rt.remoteControlOff();
1147
- const home = rt.paths.home;
1148
- return { ...r, results: r.results.map((x) => ({ ...x, file: tildify(x.file, home) })) };
1149
- },
1150
- },
1151
- '/api/remote-control/on': {
1152
- async run() {
1153
- const rt = await getRuntime();
1154
- const r = await rt.remoteControlOn();
1155
- const home = rt.paths.home;
1156
- return { ...r, results: r.results.map((x) => ({ ...x, file: tildify(x.file, home) })) };
1157
- },
1158
- },
1159
- '/api/remote-control/undo': {
1160
- async run() {
1161
- const rt = await getRuntime();
1162
- const r = await rt.remoteControlUndo();
1163
- const home = rt.paths.home;
1164
- return { ...r, results: r.results.map((x) => ({ ...x, file: tildify(x.file, home) })) };
1165
- },
1166
- },
1305
+ // into each Claude settings file that does not hold it yet, only the files the page showed (`previewedChange`).
1306
+ '/api/remote-control/off': previewedChange({
1307
+ todo: async (rt) => remoteControlTodo(await rt.remoteControl(), 'off'),
1308
+ apply: (rt) => rt.remoteControlOff(),
1309
+ }),
1310
+ '/api/remote-control/on': previewedChange({
1311
+ todo: async (rt) => remoteControlTodo(await rt.remoteControl(), 'on'),
1312
+ apply: (rt) => rt.remoteControlOn(),
1313
+ }),
1314
+ '/api/remote-control/undo': previewedChange({ apply: (rt) => rt.remoteControlUndo() }),
1167
1315
  // Sessions (spec §3.32, ADR-0039): what every Account is running now, read only, with the texts its copy buttons
1168
1316
  // copy in the Panel's language. Polled every few seconds, so it runs beside the write queue.
1169
1317
  '/api/sessions': {
@@ -1478,22 +1626,13 @@ export function createPanelHandler(opts) {
1478
1626
  };
1479
1627
  },
1480
1628
  },
1481
- '/api/messages/inbound/accept': {
1482
- async run() {
1483
- const rt = await getRuntime();
1484
- const r = await acceptInbound(await rt.accounts(), rt.readContext());
1485
- const home = rt.paths.home;
1486
- return { ...r, results: r.results.map((x) => ({ ...x, file: tildify(x.file, home) })) };
1487
- },
1488
- },
1489
- '/api/messages/inbound/undo': {
1490
- async run() {
1491
- const rt = await getRuntime();
1492
- const r = await undoInbound(await rt.accounts(), rt.readContext());
1493
- const home = rt.paths.home;
1494
- return { ...r, results: r.results.map((x) => ({ ...x, file: tildify(x.file, home) })) };
1495
- },
1496
- },
1629
+ '/api/messages/inbound/accept': previewedChange({
1630
+ todo: async (rt) => groupsToAccept(await inboundGroups(await rt.accounts(), rt.readContext())),
1631
+ apply: async (rt) => acceptInbound(await rt.accounts(), rt.readContext()),
1632
+ }),
1633
+ '/api/messages/inbound/undo': previewedChange({
1634
+ apply: async (rt) => undoInbound(await rt.accounts(), rt.readContext()),
1635
+ }),
1497
1636
  // Auto Handoff (spec §3.17): readiness reads only; configure shows the config change unless `confirm`.
1498
1637
  '/api/handoff/status': {
1499
1638
  writes: () => false,
@@ -1630,7 +1769,11 @@ export function createPanelHandler(opts) {
1630
1769
  '/api/handoff/overview': {
1631
1770
  writes: () => false,
1632
1771
  async run() {
1633
- return handoffOverview(await getRuntime());
1772
+ const rt = await getRuntime();
1773
+ // The Handoff Rules and where work would go now, also while it is off (spec §3.17 "接力规则").
1774
+ const overview = await handoffOverview(rt, { always: true });
1775
+ const { rules, apiUndecided } = await handoffRulesView(rt, overview);
1776
+ return { ...overview, rules, apiUndecided };
1634
1777
  },
1635
1778
  },
1636
1779
  // Turning it on in one step (ADR-0013): without `confirm` only the plan; with it, every step in order.
@@ -1926,6 +2069,18 @@ export function createPanelHandler(opts) {
1926
2069
  const panel = method === 'HEAD'
1927
2070
  ? undefined
1928
2071
  : await getRuntime().then((rt) => rt.config.panel, () => undefined);
2072
+ // The user's Theme under the Portal's colors (spec §3.34): `?theme=preview` shows the Theme `sideby theme
2073
+ // preview` set, for this load only. A Theme that cannot be read leaves the default and Settings says why.
2074
+ const preview = new URL(req.url ?? '/', 'http://x').searchParams.get('theme') === 'preview';
2075
+ const colors = method === 'HEAD'
2076
+ ? undefined
2077
+ : await getRuntime().then(async (rt) => (preview ? await previewColors(rt.paths) : undefined) ??
2078
+ (rt.config.panel?.colorTheme && rt.config.panel.colorTheme !== NO_THEME
2079
+ ? await resolveColors(rt.paths, rt.config.panel.colorTheme)
2080
+ : undefined), () => undefined);
2081
+ // No Theme chosen: the page's own tokens (the Default Theme) under the Portal's. A chosen Theme, even the
2082
+ // Default one, wins over the Portal's colors.
2083
+ const pageTheme = colors ? layerTheme(colors, theme) : theme;
1929
2084
  res.writeHead(200, {
1930
2085
  'content-type': 'text/html; charset=utf-8',
1931
2086
  'cache-control': 'no-store',
@@ -1952,7 +2107,7 @@ export function createPanelHandler(opts) {
1952
2107
  build,
1953
2108
  local,
1954
2109
  readOnly,
1955
- theme,
2110
+ theme: pageTheme,
1956
2111
  lang,
1957
2112
  updates,
1958
2113
  ...(ask ? { ask } : {}),
@@ -1982,6 +2137,11 @@ export function createPanelHandler(opts) {
1982
2137
  send(res, 200, { token });
1983
2138
  return true;
1984
2139
  }
2140
+ // Themes (spec §3.34): every Theme with its swatches and problems, and the one in use.
2141
+ if (sub === '/api/themes') {
2142
+ send(res, 200, await themesView(await getRuntime(), theme));
2143
+ return true;
2144
+ }
1985
2145
  if (sub === '/api/terminals') {
1986
2146
  send(res, 200, await terminalsView(await getRuntime()));
1987
2147
  return true;
@@ -206,6 +206,23 @@ declare const en: {
206
206
  'pin.full': string;
207
207
  'pin.mark': string;
208
208
  'pin.failed': string;
209
+ 'hide.account': string;
210
+ 'hide.family': string;
211
+ 'hide.showAccount': string;
212
+ 'hide.showFamily': string;
213
+ 'hide.hideName': string;
214
+ 'hide.showName': string;
215
+ 'hide.mark': string;
216
+ 'hide.inFamily': string;
217
+ 'hide.done': string;
218
+ 'hide.count.one': string;
219
+ 'hide.count.other': string;
220
+ 'hide.show': string;
221
+ 'hide.collapse': string;
222
+ 'hide.needs': string;
223
+ 'hide.allTitle': string;
224
+ 'hide.allBody': string;
225
+ 'hide.failed': string;
209
226
  'quota.fetchFailed': string;
210
227
  'quota.checkOff': string;
211
228
  'quota.checkOffHint': string;
@@ -280,6 +297,8 @@ declare const en: {
280
297
  'quota.resetNoData': string;
281
298
  'quota.dataFrom': string;
282
299
  'quota.asOf': string;
300
+ 'quota.staleSession': string;
301
+ 'quota.quiet': string;
283
302
  'quota.sharedFrom': string;
284
303
  'login.label': string;
285
304
  'login.also': string;
@@ -425,8 +444,10 @@ declare const en: {
425
444
  'ai.ask.pick': string;
426
445
  'ai.ask.new': string;
427
446
  'ai.ask.pin': string;
447
+ 'ai.ask.hide': string;
428
448
  'ai.ask.fix': string;
429
449
  'ai.ask.handoff': string;
450
+ 'ai.ask.handoffRules': string;
430
451
  'ai.ask.rc': string;
431
452
  'ai.ask.relogin': string;
432
453
  'ai.orderHint': string;
@@ -488,6 +509,7 @@ declare const en: {
488
509
  'ask.task.handoff': string;
489
510
  'ask.task.menubar': string;
490
511
  'ask.task.hotkey': string;
512
+ 'ask.task.theme': string;
491
513
  'ask.task.terminal': string;
492
514
  'ask.keyWarn': string;
493
515
  'ask.keyRemoved': string;
@@ -602,6 +624,34 @@ declare const en: {
602
624
  'key.explain': string;
603
625
  'key.explainText': string;
604
626
  'key.cannotTry': string;
627
+ 'th.title': string;
628
+ 'th.intro': string;
629
+ 'th.loading': string;
630
+ 'th.inUse': string;
631
+ 'th.mine': string;
632
+ 'th.switched': string;
633
+ 'th.custom': string;
634
+ 'th.undo': string;
635
+ 'th.undone': string;
636
+ 'th.page': string;
637
+ 'th.adjusted': string;
638
+ 'th.accent': string;
639
+ 'th.accentUse': string;
640
+ 'th.accentHint': string;
641
+ 'th.ai': string;
642
+ 'th.aiPh': string;
643
+ 'th.aiGo': string;
644
+ 'th.aiHint': string;
645
+ 'th.files': string;
646
+ 'th.remove': string;
647
+ 'th.removeSure': string;
648
+ 'th.removed': string;
649
+ 'ask.title.theme': string;
650
+ 'ask.ph.theme': string;
651
+ 'ask.ex.theme.1': string;
652
+ 'ask.ex.theme.2': string;
653
+ 'ask.ex.theme.3': string;
654
+ 'ai.ask.theme': string;
605
655
  'term.title': string;
606
656
  'term.intro': string;
607
657
  'term.pick': string;
@@ -737,12 +787,11 @@ declare const en: {
737
787
  'md.saved': string;
738
788
  'page.handoff': string;
739
789
  'hp.title': string;
790
+ 'hp.statusOn': string;
791
+ 'hp.statusOff': string;
740
792
  'hp.advanced': string;
741
793
  'hp.loading': string;
742
794
  'hp.intro': string;
743
- 'hp.how1': string;
744
- 'hp.how2': string;
745
- 'hp.how3': string;
746
795
  'hp.noStarters': string;
747
796
  'hp.sameFamily': string;
748
797
  'hp.turnOn': string;
@@ -767,7 +816,6 @@ declare const en: {
767
816
  'hp.goesTo': string;
768
817
  'hp.goesToLimit': string;
769
818
  'hp.waits': string;
770
- 'hp.waitRule': string;
771
819
  'hp.planChanged': string;
772
820
  'hp.none': string;
773
821
  'hp.noneBack': string;
@@ -783,6 +831,49 @@ declare const en: {
783
831
  'hp.sameConfirm': string;
784
832
  'hp.sameOn': string;
785
833
  'hp.sameOff': string;
834
+ 'hp.takeoverIf': string;
835
+ 'hp.rules': string;
836
+ 'hp.rulesNote': string;
837
+ 'hp.rule.whenAdaptive': string;
838
+ 'hp.rule.when': string;
839
+ 'hp.rule.windows': string;
840
+ 'hp.rule.takeover': string;
841
+ 'hp.rule.wait': string;
842
+ 'hp.rule.noWait': string;
843
+ 'hp.rule.sameOn': string;
844
+ 'hp.rule.sameOff': string;
845
+ 'hp.rule.otherOn': string;
846
+ 'hp.rule.otherOff': string;
847
+ 'hp.rule.apiOn': string;
848
+ 'hp.rule.apiOff': string;
849
+ 'hp.rule.org': string;
850
+ 'hp.rule.orgExcept': string;
851
+ 'hp.rule.order': string;
852
+ 'hp.rule.countdown': string;
853
+ 'hp.rule.noCountdown': string;
854
+ 'hp.on': string;
855
+ 'hp.off': string;
856
+ 'hp.edit': string;
857
+ 'hp.adaptive': string;
858
+ 'hp.adaptiveOn': string;
859
+ 'hp.adaptiveOff': string;
860
+ 'hp.otherFamilies': string;
861
+ 'hp.otherOn': string;
862
+ 'hp.otherOff': string;
863
+ 'hp.aiOrderSaved': string;
864
+ 'hp.api': string;
865
+ 'hp.apiOn': string;
866
+ 'hp.apiOff': string;
867
+ 'hp.noApi': string;
868
+ 'hp.apiWarn': string;
869
+ 'hp.apiConfirm': string;
870
+ 'hp.apiAskTitle': string;
871
+ 'hp.apiAskBody': string;
872
+ 'hp.apiKeepOff': string;
873
+ 'hp.apiKeepOn': string;
874
+ 'hp.apiKeptOff': string;
875
+ 'hp.undone': string;
876
+ 'hp.noneAll': string;
786
877
  'page.accounts': string;
787
878
  'page.tuning': string;
788
879
  'page.sessions': string;
@@ -989,8 +1080,6 @@ declare const en: {
989
1080
  'inb.state.default': string;
990
1081
  'inb.state.refuse': string;
991
1082
  'inb.state.cannot': string;
992
- 'inb.change': string;
993
- 'inb.notSet': string;
994
1083
  'inb.confirmNote': string;
995
1084
  'inb.accept': string;
996
1085
  'inb.undo': string;
@@ -1015,6 +1104,8 @@ declare const en: {
1015
1104
  'tune.hostDefaultRange': string;
1016
1105
  'tune.best': string;
1017
1106
  'tune.saved': string;
1107
+ 'tune.savedLabel': string;
1108
+ 'tune.savedValue': string;
1018
1109
  'tune.compactions.one': string;
1019
1110
  'tune.compactions.other': string;
1020
1111
  'tune.noCompactions': string;
@@ -1062,6 +1153,7 @@ declare const en: {
1062
1153
  'nf.accounts.other': string;
1063
1154
  'nf.runOnce': string;
1064
1155
  'nf.notInstalled': string;
1156
+ 'nf.mainOnly': string;
1065
1157
  'nf.broken': string;
1066
1158
  'nf.name': string;
1067
1159
  'nf.namePh': string;
@@ -1133,6 +1225,8 @@ declare const en: {
1133
1225
  'ah.hint': string;
1134
1226
  'ah.setUp': string;
1135
1227
  'ah.dismiss': string;
1228
+ 'ah.crossOrg': string;
1229
+ 'ah.crossOrgHint': string;
1136
1230
  'toast.ahOn': string;
1137
1231
  'toast.ahOff': string;
1138
1232
  'qs.title': string;
@@ -1156,11 +1250,11 @@ declare const en: {
1156
1250
  'rc.hidden': string;
1157
1251
  'rc.readOnly': string;
1158
1252
  'rc.confirmTitle': string;
1159
- 'rc.change': string;
1160
1253
  'rc.notSet': string;
1161
1254
  'rc.usedBy': string;
1162
1255
  'rc.confirmNote': string;
1163
1256
  'rc.confirm': string;
1257
+ 'rc.skipped': string;
1164
1258
  'rc.done': string;
1165
1259
  'rc.failed': string;
1166
1260
  'set.button': string;
@@ -1279,6 +1373,11 @@ declare const en: {
1279
1373
  'rc.state.off': string;
1280
1374
  'rc.state.missing': string;
1281
1375
  'rc.state.blocked': string;
1376
+ 'settings.why.no-settings': string;
1377
+ 'settings.why.broken-link': string;
1378
+ 'settings.why.unsafe': string;
1379
+ 'settings.why.refuse': string;
1380
+ 'settings.why.other': string;
1282
1381
  'rc.dialogTitle': string;
1283
1382
  'rc.explain': string;
1284
1383
  'rc.allOff': string;