sideby 0.20.0 → 0.22.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 (73) hide show
  1. package/README.md +1 -0
  2. package/dist/build.json +1 -1
  3. package/dist/src/cli/commands.js +115 -10
  4. package/dist/src/cli/format.js +3 -2
  5. package/dist/src/cli/json-schemas.js +81 -46
  6. package/dist/src/cli/main.js +6 -3
  7. package/dist/src/core/accounts.d.ts +6 -1
  8. package/dist/src/core/accounts.js +16 -3
  9. package/dist/src/core/ask.d.ts +2 -1
  10. package/dist/src/core/ask.js +6 -3
  11. package/dist/src/core/claude-settings-file.d.ts +57 -0
  12. package/dist/src/core/claude-settings-file.js +104 -2
  13. package/dist/src/core/config.d.ts +29 -15
  14. package/dist/src/core/config.js +40 -2
  15. package/dist/src/core/create.js +4 -1
  16. package/dist/src/core/desktop-app.js +5 -1
  17. package/dist/src/core/handoff-overview.d.ts +4 -1
  18. package/dist/src/core/handoff-overview.js +3 -2
  19. package/dist/src/core/handoff-rules.d.ts +34 -0
  20. package/dist/src/core/handoff-rules.js +115 -0
  21. package/dist/src/core/handoff-select.js +45 -28
  22. package/dist/src/core/handoff-status.d.ts +37 -7
  23. package/dist/src/core/handoff-status.js +95 -19
  24. package/dist/src/core/handoff.d.ts +4 -1
  25. package/dist/src/core/handoff.js +8 -5
  26. package/dist/src/core/inbound.d.ts +11 -3
  27. package/dist/src/core/inbound.js +26 -74
  28. package/dist/src/core/launch.js +6 -4
  29. package/dist/src/core/quota-levels.d.ts +6 -0
  30. package/dist/src/core/quota-levels.js +8 -0
  31. package/dist/src/core/remote-control.d.ts +10 -12
  32. package/dist/src/core/remote-control.js +29 -86
  33. package/dist/src/core/tuning-apply.js +12 -20
  34. package/dist/src/families/agy/index.d.ts +8 -0
  35. package/dist/src/families/agy/index.js +53 -0
  36. package/dist/src/families/agy/quota.d.ts +9 -0
  37. package/dist/src/families/agy/quota.js +110 -0
  38. package/dist/src/families/index.js +7 -0
  39. package/dist/src/families/logos.d.ts +10 -0
  40. package/dist/src/families/logos.js +12 -1
  41. package/dist/src/menubar/script.js +26 -3
  42. package/dist/src/menubar/snapshot.d.ts +23 -6
  43. package/dist/src/menubar/snapshot.js +126 -39
  44. package/dist/src/menubar/strings.d.ts +12 -2
  45. package/dist/src/menubar/strings.js +12 -2
  46. package/dist/src/panel/handler.d.ts +2 -1
  47. package/dist/src/panel/handler.js +81 -45
  48. package/dist/src/panel/i18n.d.ts +58 -7
  49. package/dist/src/panel/i18n.js +158 -56
  50. package/dist/src/panel/page-logic.d.ts +52 -19
  51. package/dist/src/panel/page-logic.js +47 -7
  52. package/dist/src/panel/page-script.js +333 -115
  53. package/dist/src/panel/page-styles.js +112 -21
  54. package/dist/src/panel/page.js +3 -3
  55. package/dist/src/plugins/check.js +27 -13
  56. package/dist/src/plugins/loader.d.ts +11 -0
  57. package/dist/src/plugins/loader.js +47 -1
  58. package/dist/src/runtime.d.ts +5 -2
  59. package/dist/src/runtime.js +12 -5
  60. package/dist/src/types.d.ts +35 -5
  61. package/package.json +2 -2
  62. package/schemas/config.json +16 -1
  63. package/schemas/families.json +8 -5
  64. package/schemas/handoff-disable.json +22 -0
  65. package/schemas/handoff-enable.json +22 -0
  66. package/schemas/handoff-rules.json +302 -0
  67. package/schemas/handoff-status.json +26 -0
  68. package/schemas/list.json +5 -0
  69. package/schemas/menubar-snapshot.json +309 -2
  70. package/skills/sideby/SKILL.md +3 -2
  71. package/skills/sideby/references/accounts.md +1 -0
  72. package/skills/sideby/references/handoff.md +7 -3
  73. package/skills/sideby/references/quota.md +2 -0
@@ -65,7 +65,11 @@ export function menubarHotkey(value) {
65
65
  }
66
66
  /** `2h 5m`, `3d 4h` or `12m` until `at`; at least one minute. */
67
67
  export function untilText(at, now, s) {
68
- const total = Math.max(1, Math.ceil((Date.parse(at) - now.getTime()) / 60000));
68
+ return durationText(Math.ceil((Date.parse(at) - now.getTime()) / 60000), s);
69
+ }
70
+ /** `2h 5m`, `3d 4h` or `12m` for a number of minutes; at least one minute. */
71
+ function durationText(minutes, s) {
72
+ const total = Math.max(1, minutes);
69
73
  const d = Math.floor(total / 1440);
70
74
  const h = Math.floor((total % 1440) / 60);
71
75
  const m = total % 60;
@@ -75,6 +79,74 @@ export function untilText(at, now, s) {
75
79
  return fill(s.hoursMinutes, { h, m });
76
80
  return fill(s.minutes, { m });
77
81
  }
82
+ /**
83
+ * The model groups of a Quota whose every window covers one group (Antigravity CLI), in the order the Host lists them,
84
+ * as the Panel shows them: each with its own windows, so the menu draws a line per group with its `5h` and `7d` bars.
85
+ * Null when some window covers every model.
86
+ */
87
+ export function quotaGroups(quota) {
88
+ if (quota.status !== 'ok' || !quota.windows.length || quota.windows.some((w) => !w.name))
89
+ return null;
90
+ const groups = new Map();
91
+ for (const { name, ...w } of quota.windows)
92
+ groups.set(name, [...(groups.get(name) ?? []), w]);
93
+ return [...groups].map(([name, windows]) => ({ name, quota: { ...quota, windows } }));
94
+ }
95
+ /** A model group's name over its line, without a trailing "models" so it fits. */
96
+ function groupLabel(name) {
97
+ return name.replace(/\s+models$/i, '') || name;
98
+ }
99
+ /**
100
+ * What a Quota whose windows cover every model draws: two bar columns (the shortest window, then the fullest of the
101
+ * others, so a third window that is used up still shows; a single window fills the second), the time until the fullest
102
+ * resets, and one hover line per window with its use and reset.
103
+ */
104
+ function drawn(quota, now, s) {
105
+ const open = openWindows(quota, now) ?? [];
106
+ const windows = quota.windows
107
+ .filter((w) => !w.name)
108
+ .sort((x, y) => (x.windowMinutes ?? 0) - (y.windowMinutes ?? 0));
109
+ const openOf = (w) => open.find((o) => o.label === w.label);
110
+ const bar = (w) => {
111
+ const percent = Math.round(openOf(w)?.usedPercent ?? 0);
112
+ return { label: w.label, percent, level: quotaLevel(percent) };
113
+ };
114
+ const longer = windows
115
+ .slice(1)
116
+ .map(bar)
117
+ .reduce((best, b) => (!best || b.percent > best.percent ? b : best), null);
118
+ const bars = !windows.length
119
+ ? null
120
+ : longer
121
+ ? [bar(windows[0]), longer]
122
+ : [null, bar(windows[0])];
123
+ const fullest = open.reduce((best, w) => (!best || w.usedPercent > best.usedPercent ? w : best), null);
124
+ const reset = fullest && fullest.usedPercent > 0 ? untilText(fullest.resetsAt, now, s) : '';
125
+ const lines = windows.map((w) => {
126
+ const o = openOf(w);
127
+ const p = bar(w).percent;
128
+ return o && p > 0
129
+ ? fill(s.windowResetsTip, { label: w.label, p, time: untilText(o.resetsAt, now, s) })
130
+ : fill(s.windowTip, { label: w.label, p });
131
+ });
132
+ return {
133
+ bars,
134
+ fullest,
135
+ reset,
136
+ parts: windows.map((w) => fill(s.window, { label: w.label, p: bar(w).percent })),
137
+ lines,
138
+ };
139
+ }
140
+ /** When the numbers were read, in words: "just now", "25 min ago", or the time itself when the date is unknown. */
141
+ function observedText(observedAt, now, s) {
142
+ const at = Date.parse(observedAt);
143
+ if (!Number.isFinite(at))
144
+ return fill(s.observedAt, { time: '?' });
145
+ const minutes = Math.max(0, Math.floor((now.getTime() - at) / 60000));
146
+ if (minutes < 1)
147
+ return s.observedJustNow;
148
+ return fill(s.observedAgo, { time: durationText(minutes, s) });
149
+ }
78
150
  function row(a, plan, now, s) {
79
151
  const recommended = Boolean(plan?.hasQuota && plan.pick === a.ref);
80
152
  const startTip = fill(s.startTip, { account: a.ref });
@@ -84,6 +156,7 @@ function row(a, plan, now, s) {
84
156
  recommended,
85
157
  tip: startTip,
86
158
  bars: null,
159
+ groups: null,
87
160
  reset: '',
88
161
  observedAt: null,
89
162
  stale: false,
@@ -93,56 +166,69 @@ function row(a, plan, now, s) {
93
166
  return noted(s.api);
94
167
  if (a.login === 'logged-out')
95
168
  return noted(s.signedOut);
96
- const open = openWindows(a.quota, now);
97
- if (a.quota.status !== 'ok' || open === null)
169
+ const quota = a.quota;
170
+ if (quota.status !== 'ok')
98
171
  return noted(s.noData);
99
- const observedAt = a.quota.observedAt;
100
- const at = Date.parse(observedAt);
101
- const stale = quotaIsStale(a.quota, now.getTime());
102
- const windows = a.quota.windows
103
- .filter((w) => !w.name)
104
- .sort((x, y) => (x.windowMinutes ?? 0) - (y.windowMinutes ?? 0));
105
- const bar = (w) => {
106
- const percent = Math.round(open.find((o) => o.label === w.label)?.usedPercent ?? 0);
107
- return { label: w.label, percent, level: quotaLevel(percent) };
108
- };
109
- // Two columns: the shortest window, then the fullest of the others, so a third window that is used up still shows.
110
- const longer = windows
111
- .slice(1)
112
- .map(bar)
113
- .reduce((best, b) => (!best || b.percent > best.percent ? b : best), null);
114
- const bars = longer ? [bar(windows[0]), longer] : [null, bar(windows[0])];
115
- const parts = windows.map((w) => fill(s.window, { label: w.label, p: bar(w).percent }));
116
- const fullest = open.reduce((best, w) => (!best || w.usedPercent > best.usedPercent ? w : best), null);
117
- const reset = fullest && fullest.usedPercent > 0 ? untilText(fullest.resetsAt, now, s) : '';
118
- if (reset)
119
- parts.push(fill(s.resets, { time: reset }));
172
+ const stale = quotaIsStale(quota, now.getTime());
173
+ // The head of the hover text: when the numbers were read, and why they may be old.
174
+ const head = [
175
+ observedText(quota.observedAt, now, s),
176
+ ...(stale ? [s.olderReadingTip] : []),
177
+ ...(quota.fetchError ? [fill(s.fetchFailed, { error: quota.fetchError })] : []),
178
+ ];
179
+ const groups = quotaGroups(quota);
180
+ if (groups) {
181
+ // One line per model group under the account, each with its own 5h and 7d bars (spec §3.31).
182
+ const drawnGroups = groups.map((g) => ({ name: g.name, d: drawn(g.quota, now, s) }));
183
+ const fullest = drawnGroups
184
+ .map((g) => g.d.fullest)
185
+ .reduce((best, w) => (w && (!best || w.usedPercent > best.usedPercent) ? w : best), null);
186
+ const groupTip = (g) => [g.name, ...g.d.lines.map((l) => ` ${l}`)];
187
+ return {
188
+ ...base,
189
+ observedAt: quota.observedAt,
190
+ stale,
191
+ detail: [
192
+ ...drawnGroups.map((g) => `${groupLabel(g.name)} ${g.d.parts.join(' ')}`),
193
+ ...(stale ? [s.olderReading] : []),
194
+ ].join(s.sep),
195
+ level: quotaLevel(fullest?.usedPercent ?? 0),
196
+ tip: [...head, '', ...drawnGroups.flatMap(groupTip), '', startTip].join('\n'),
197
+ groups: drawnGroups.map((g) => ({
198
+ label: groupLabel(g.name),
199
+ bars: g.d.bars,
200
+ reset: g.d.reset,
201
+ tip: [...head, '', ...groupTip(g), '', startTip].join('\n'),
202
+ })),
203
+ note: stale ? s.olderReading : '',
204
+ };
205
+ }
206
+ if (openWindows(quota, now) === null)
207
+ return noted(s.noData);
208
+ const d = drawn(quota, now, s);
209
+ const parts = [...d.parts];
210
+ if (d.reset)
211
+ parts.push(fill(s.resets, { time: d.reset }));
120
212
  if (stale)
121
213
  parts.push(s.olderReading);
122
- const tips = open
123
- .filter((w) => w.usedPercent > 0)
124
- .map((w) => fill(s.resetsTip, { label: w.label, time: untilText(w.resetsAt, now, s) }));
125
214
  return {
126
215
  ...base,
127
- observedAt,
216
+ observedAt: quota.observedAt,
128
217
  stale,
129
218
  detail: parts.join(s.sep),
130
- level: quotaLevel(fullest?.usedPercent ?? 0),
131
- tip: [
132
- fill(s.observedAt, { time: Number.isFinite(at) ? observedAt : '?' }),
133
- ...(stale ? [s.olderReading] : []),
134
- ...(a.quota.fetchError ? [a.quota.fetchError] : []),
135
- ...tips,
136
- startTip,
137
- ].join('\n'),
138
- bars,
139
- reset,
219
+ level: quotaLevel(d.fullest?.usedPercent ?? 0),
220
+ tip: [...head, '', ...d.lines, '', startTip].join('\n'),
221
+ bars: d.bars,
222
+ reset: d.reset,
140
223
  note: stale ? s.olderReading : '',
141
224
  };
142
225
  }
143
226
  /** The recommended row first; API key and signed-out rows into `more` while other rows remain to show. */
144
227
  function columns(rows) {
145
- const at = (i) => rows.map((r) => r.bars?.[i]?.label).find((l) => l !== undefined) ?? null;
228
+ const at = (i) => rows
229
+ .flatMap((r) => [r.bars, ...(r.groups ?? []).map((g) => g.bars)])
230
+ .map((bars) => bars?.[i]?.label)
231
+ .find((l) => l !== undefined) ?? null;
146
232
  return [at(0), at(1)];
147
233
  }
148
234
  function section(f, now, s) {
@@ -151,6 +237,7 @@ function section(f, now, s) {
151
237
  path: f.logo.path,
152
238
  ...(f.logo.fillRule ? { fillRule: f.logo.fillRule } : {}),
153
239
  ...(f.logo.color ? { color: f.logo.color } : {}),
240
+ ...(f.logo.gradients?.length ? { gradients: f.logo.gradients } : {}),
154
241
  }
155
242
  : null;
156
243
  const all = f.accounts.map((a) => ({ a, r: row(a, f.plan, now, s) }));
@@ -21,9 +21,14 @@ export declare const MENUBAR_STRINGS: {
21
21
  readonly noData: 'no quota yet';
22
22
  readonly olderReading: 'older reading';
23
23
  readonly observedAt: 'Quota recorded at {time}';
24
+ readonly observedJustNow: 'Quota read just now';
25
+ readonly observedAgo: 'Quota read {time} ago';
26
+ readonly olderReadingTip: 'These numbers may be old · click Refresh to check again';
27
+ readonly fetchFailed: 'The last check failed: {error}';
28
+ readonly windowTip: '{label}: {p}% used';
29
+ readonly windowResetsTip: '{label}: {p}% used · resets in {time}';
24
30
  readonly window: '{label} {p}%';
25
31
  readonly resets: 'resets in {time}';
26
- readonly resetsTip: '{label} resets in {time}';
27
32
  readonly moreApi: 'API keys ({n})';
28
33
  readonly moreSignedOut: '{n} signed out';
29
34
  readonly moreMixed: '{n} more';
@@ -71,9 +76,14 @@ export declare const MENUBAR_STRINGS: {
71
76
  readonly noData: '暂无额度';
72
77
  readonly olderReading: '旧数据';
73
78
  readonly observedAt: '额度记录时间:{time}';
79
+ readonly observedJustNow: '额度刚刚读取';
80
+ readonly observedAgo: '额度读于 {time}前';
81
+ readonly olderReadingTip: '这些数字可能已经过时 · 点“刷新”重新检查';
82
+ readonly fetchFailed: '上次检查没成功:{error}';
83
+ readonly windowTip: '{label}:已用 {p}%';
84
+ readonly windowResetsTip: '{label}:已用 {p}% · {time}后重置';
74
85
  readonly window: '{label} {p}%';
75
86
  readonly resets: '{time}后重置';
76
- readonly resetsTip: '{label}额度将在 {time}后重置';
77
87
  readonly moreApi: '{n} 个 API 密钥账号';
78
88
  readonly moreSignedOut: '{n} 个未登录账号';
79
89
  readonly moreMixed: '另外 {n} 个账号';
@@ -21,9 +21,14 @@ export const MENUBAR_STRINGS = {
21
21
  noData: 'no quota yet',
22
22
  olderReading: 'older reading',
23
23
  observedAt: 'Quota recorded at {time}',
24
+ observedJustNow: 'Quota read just now',
25
+ observedAgo: 'Quota read {time} ago',
26
+ olderReadingTip: 'These numbers may be old · click Refresh to check again',
27
+ fetchFailed: 'The last check failed: {error}',
28
+ windowTip: '{label}: {p}% used',
29
+ windowResetsTip: '{label}: {p}% used · resets in {time}',
24
30
  window: '{label} {p}%',
25
31
  resets: 'resets in {time}',
26
- resetsTip: '{label} resets in {time}',
27
32
  moreApi: 'API keys ({n})',
28
33
  moreSignedOut: '{n} signed out',
29
34
  moreMixed: '{n} more',
@@ -71,9 +76,14 @@ export const MENUBAR_STRINGS = {
71
76
  noData: '暂无额度',
72
77
  olderReading: '旧数据',
73
78
  observedAt: '额度记录时间:{time}',
79
+ observedJustNow: '额度刚刚读取',
80
+ observedAgo: '额度读于 {time}前',
81
+ olderReadingTip: '这些数字可能已经过时 · 点“刷新”重新检查',
82
+ fetchFailed: '上次检查没成功:{error}',
83
+ windowTip: '{label}:已用 {p}%',
84
+ windowResetsTip: '{label}:已用 {p}% · {time}后重置',
74
85
  window: '{label} {p}%',
75
86
  resets: '{time}后重置',
76
- resetsTip: '{label}额度将在 {time}后重置',
77
87
  moreApi: '{n} 个 API 密钥账号',
78
88
  moreSignedOut: '{n} 个未登录账号',
79
89
  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';
@@ -235,6 +235,7 @@ export interface PanelState {
235
235
  autoHandoff: {
236
236
  settings: HandoffSettings;
237
237
  starters: string[];
238
+ apiUndecided: boolean;
238
239
  };
239
240
  /** Claude settings files grouped as `sideby remote-control` shows them (spec §3.22); absent without Claude Accounts. */
240
241
  remoteControl?: RemoteControlView[];
@@ -14,12 +14,14 @@ 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';
@@ -613,6 +615,7 @@ async function buildState(rt, opts) {
613
615
  starters: [...rt.families.values()]
614
616
  .filter((f) => f.handoff?.starts.length && HOOK_FAMILIES.includes(f.id))
615
617
  .map((f) => f.id),
618
+ apiUndecided: apiUndecided(rt, accounts.filter((a) => a.kind === 'api').length),
616
619
  },
617
620
  ...(upd ? { update: upd } : {}),
618
621
  ...(showBrowser ? { browser } : {}),
@@ -652,14 +655,37 @@ function displayBody(body) {
652
655
  }
653
656
  return out;
654
657
  }
655
- /** The `change` of a /api/handoff/configure body, with every field checked; unknown fields are refused. */
658
+ /**
659
+ * The `change` of a /api/handoff/configure body, with every field checked; unknown fields are refused. Null for a
660
+ * single setting removes it, as the `undo` of an earlier answer asks.
661
+ */
662
+ const HANDOFF_SINGLE_KEYS = new Set([
663
+ 'auto',
664
+ 'sameFamily',
665
+ 'otherFamilies',
666
+ 'api',
667
+ 'adaptive',
668
+ 'prepareAt',
669
+ 'threshold',
670
+ 'waitIfResetWithinMinutes',
671
+ 'countdownSeconds',
672
+ ]);
656
673
  function handoffChange(body) {
657
674
  const c = body.change;
658
675
  if (!c || typeof c !== 'object' || Array.isArray(c))
659
676
  throw new HttpError(400, '"change" must be an object');
660
677
  const out = {};
661
678
  for (const [k, v] of Object.entries(c)) {
662
- if (k === 'auto' || k === 'sameFamily') {
679
+ if (v === null && k !== 'familyOrder' && k !== 'crossOrganization' && k !== 'orders') {
680
+ if (!HANDOFF_SINGLE_KEYS.has(k))
681
+ throw new HttpError(400, `unknown setting "${k}"`);
682
+ out[k] = null;
683
+ }
684
+ else if (k === 'auto' ||
685
+ k === 'sameFamily' ||
686
+ k === 'otherFamilies' ||
687
+ k === 'api' ||
688
+ k === 'adaptive') {
663
689
  if (typeof v !== 'boolean')
664
690
  throw new HttpError(400, `"${k}" must be true or false`);
665
691
  out[k] = v;
@@ -672,6 +698,11 @@ function handoffChange(body) {
672
698
  throw new HttpError(400, `"${k}" must be a whole number`);
673
699
  out[k] = v;
674
700
  }
701
+ else if (k === 'familyOrder' || k === 'crossOrganization') {
702
+ if (!Array.isArray(v) || !v.every((n) => typeof n === 'string'))
703
+ throw new HttpError(400, `"${k}" must be a list of names`);
704
+ out[k] = [...v];
705
+ }
675
706
  else if (k === 'orders') {
676
707
  if (!Array.isArray(v) ||
677
708
  !v.every((o) => o &&
@@ -846,6 +877,31 @@ export function createPanelHandler(opts) {
846
877
  toolScans.delete(id);
847
878
  }
848
879
  };
880
+ /**
881
+ * A change of one key in Claude's settings files that the page showed file by file before the user confirmed
882
+ * (Remote Control, spec §3.22; receiving Messages, ADR-0045). Without `confirm` it writes nothing and names the
883
+ * files; with it, `files` must be exactly the files the page showed, or nothing is written and `changedSince` says
884
+ * so, because a file the user never saw in the preview must not change. Undo passes no `todo`: it only puts back
885
+ * what sideby wrote, and its toast runs before the page has read the new state.
886
+ */
887
+ const previewedChange = (change) => ({
888
+ writes: (body) => body.confirm === true,
889
+ async run(body) {
890
+ const rt = await getRuntime();
891
+ const home = rt.paths.home;
892
+ const files = change.todo ? (await change.todo(rt)).map((g) => tildify(g.file, home)) : undefined;
893
+ if (!optBool(body, 'confirm'))
894
+ return { applied: false, ...(files ? { files } : {}) };
895
+ if (files) {
896
+ const saw = body.files;
897
+ const same = Array.isArray(saw) && saw.length === files.length && files.every((f) => saw.includes(f));
898
+ if (!same)
899
+ return { applied: false, changedSince: true, files };
900
+ }
901
+ const r = await change.apply(rt);
902
+ return { ...r, applied: true, results: r.results.map((x) => ({ ...x, file: tildify(x.file, home) })) };
903
+ },
904
+ });
849
905
  /** The switch of one LaunchAgent sideby writes: the Panel's login item or the Menu Bar Item. */
850
906
  const loginItemRoute = (agent) => ({
851
907
  writes: (body) => body.confirm === true,
@@ -1139,31 +1195,16 @@ export function createPanelHandler(opts) {
1139
1195
  },
1140
1196
  },
1141
1197
  // 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
- },
1198
+ // into each Claude settings file that does not hold it yet, only the files the page showed (`previewedChange`).
1199
+ '/api/remote-control/off': previewedChange({
1200
+ todo: async (rt) => remoteControlTodo(await rt.remoteControl(), 'off'),
1201
+ apply: (rt) => rt.remoteControlOff(),
1202
+ }),
1203
+ '/api/remote-control/on': previewedChange({
1204
+ todo: async (rt) => remoteControlTodo(await rt.remoteControl(), 'on'),
1205
+ apply: (rt) => rt.remoteControlOn(),
1206
+ }),
1207
+ '/api/remote-control/undo': previewedChange({ apply: (rt) => rt.remoteControlUndo() }),
1167
1208
  // Sessions (spec §3.32, ADR-0039): what every Account is running now, read only, with the texts its copy buttons
1168
1209
  // copy in the Panel's language. Polled every few seconds, so it runs beside the write queue.
1169
1210
  '/api/sessions': {
@@ -1478,22 +1519,13 @@ export function createPanelHandler(opts) {
1478
1519
  };
1479
1520
  },
1480
1521
  },
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
- },
1522
+ '/api/messages/inbound/accept': previewedChange({
1523
+ todo: async (rt) => groupsToAccept(await inboundGroups(await rt.accounts(), rt.readContext())),
1524
+ apply: async (rt) => acceptInbound(await rt.accounts(), rt.readContext()),
1525
+ }),
1526
+ '/api/messages/inbound/undo': previewedChange({
1527
+ apply: async (rt) => undoInbound(await rt.accounts(), rt.readContext()),
1528
+ }),
1497
1529
  // Auto Handoff (spec §3.17): readiness reads only; configure shows the config change unless `confirm`.
1498
1530
  '/api/handoff/status': {
1499
1531
  writes: () => false,
@@ -1630,7 +1662,11 @@ export function createPanelHandler(opts) {
1630
1662
  '/api/handoff/overview': {
1631
1663
  writes: () => false,
1632
1664
  async run() {
1633
- return handoffOverview(await getRuntime());
1665
+ const rt = await getRuntime();
1666
+ // The Handoff Rules and where work would go now, also while it is off (spec §3.17 "接力规则").
1667
+ const overview = await handoffOverview(rt, { always: true });
1668
+ const { rules, apiUndecided } = await handoffRulesView(rt, overview);
1669
+ return { ...overview, rules, apiUndecided };
1634
1670
  },
1635
1671
  },
1636
1672
  // Turning it on in one step (ADR-0013): without `confirm` only the plan; with it, every step in order.
@@ -427,6 +427,7 @@ declare const en: {
427
427
  'ai.ask.pin': string;
428
428
  'ai.ask.fix': string;
429
429
  'ai.ask.handoff': string;
430
+ 'ai.ask.handoffRules': string;
430
431
  'ai.ask.rc': string;
431
432
  'ai.ask.relogin': string;
432
433
  'ai.orderHint': string;
@@ -737,12 +738,11 @@ declare const en: {
737
738
  'md.saved': string;
738
739
  'page.handoff': string;
739
740
  'hp.title': string;
741
+ 'hp.statusOn': string;
742
+ 'hp.statusOff': string;
740
743
  'hp.advanced': string;
741
744
  'hp.loading': string;
742
745
  'hp.intro': string;
743
- 'hp.how1': string;
744
- 'hp.how2': string;
745
- 'hp.how3': string;
746
746
  'hp.noStarters': string;
747
747
  'hp.sameFamily': string;
748
748
  'hp.turnOn': string;
@@ -767,7 +767,6 @@ declare const en: {
767
767
  'hp.goesTo': string;
768
768
  'hp.goesToLimit': string;
769
769
  'hp.waits': string;
770
- 'hp.waitRule': string;
771
770
  'hp.planChanged': string;
772
771
  'hp.none': string;
773
772
  'hp.noneBack': string;
@@ -783,6 +782,49 @@ declare const en: {
783
782
  'hp.sameConfirm': string;
784
783
  'hp.sameOn': string;
785
784
  'hp.sameOff': string;
785
+ 'hp.takeoverIf': string;
786
+ 'hp.rules': string;
787
+ 'hp.rulesNote': string;
788
+ 'hp.rule.whenAdaptive': string;
789
+ 'hp.rule.when': string;
790
+ 'hp.rule.windows': string;
791
+ 'hp.rule.takeover': string;
792
+ 'hp.rule.wait': string;
793
+ 'hp.rule.noWait': string;
794
+ 'hp.rule.sameOn': string;
795
+ 'hp.rule.sameOff': string;
796
+ 'hp.rule.otherOn': string;
797
+ 'hp.rule.otherOff': string;
798
+ 'hp.rule.apiOn': string;
799
+ 'hp.rule.apiOff': string;
800
+ 'hp.rule.org': string;
801
+ 'hp.rule.orgExcept': string;
802
+ 'hp.rule.order': string;
803
+ 'hp.rule.countdown': string;
804
+ 'hp.rule.noCountdown': string;
805
+ 'hp.on': string;
806
+ 'hp.off': string;
807
+ 'hp.edit': string;
808
+ 'hp.adaptive': string;
809
+ 'hp.adaptiveOn': string;
810
+ 'hp.adaptiveOff': string;
811
+ 'hp.otherFamilies': string;
812
+ 'hp.otherOn': string;
813
+ 'hp.otherOff': string;
814
+ 'hp.aiOrderSaved': string;
815
+ 'hp.api': string;
816
+ 'hp.apiOn': string;
817
+ 'hp.apiOff': string;
818
+ 'hp.noApi': string;
819
+ 'hp.apiWarn': string;
820
+ 'hp.apiConfirm': string;
821
+ 'hp.apiAskTitle': string;
822
+ 'hp.apiAskBody': string;
823
+ 'hp.apiKeepOff': string;
824
+ 'hp.apiKeepOn': string;
825
+ 'hp.apiKeptOff': string;
826
+ 'hp.undone': string;
827
+ 'hp.noneAll': string;
786
828
  'page.accounts': string;
787
829
  'page.tuning': string;
788
830
  'page.sessions': string;
@@ -853,6 +895,7 @@ declare const en: {
853
895
  'hist.unfold': string;
854
896
  'hist.fold': string;
855
897
  'hist.unfoldOne': string;
898
+ 'hist.catMove': string;
856
899
  'hist.day.today': string;
857
900
  'hist.day.yesterday': string;
858
901
  'hist.day.week': string;
@@ -988,8 +1031,6 @@ declare const en: {
988
1031
  'inb.state.default': string;
989
1032
  'inb.state.refuse': string;
990
1033
  'inb.state.cannot': string;
991
- 'inb.change': string;
992
- 'inb.notSet': string;
993
1034
  'inb.confirmNote': string;
994
1035
  'inb.accept': string;
995
1036
  'inb.undo': string;
@@ -1014,6 +1055,8 @@ declare const en: {
1014
1055
  'tune.hostDefaultRange': string;
1015
1056
  'tune.best': string;
1016
1057
  'tune.saved': string;
1058
+ 'tune.savedLabel': string;
1059
+ 'tune.savedValue': string;
1017
1060
  'tune.compactions.one': string;
1018
1061
  'tune.compactions.other': string;
1019
1062
  'tune.noCompactions': string;
@@ -1061,6 +1104,7 @@ declare const en: {
1061
1104
  'nf.accounts.other': string;
1062
1105
  'nf.runOnce': string;
1063
1106
  'nf.notInstalled': string;
1107
+ 'nf.mainOnly': string;
1064
1108
  'nf.broken': string;
1065
1109
  'nf.name': string;
1066
1110
  'nf.namePh': string;
@@ -1132,6 +1176,8 @@ declare const en: {
1132
1176
  'ah.hint': string;
1133
1177
  'ah.setUp': string;
1134
1178
  'ah.dismiss': string;
1179
+ 'ah.crossOrg': string;
1180
+ 'ah.crossOrgHint': string;
1135
1181
  'toast.ahOn': string;
1136
1182
  'toast.ahOff': string;
1137
1183
  'qs.title': string;
@@ -1155,11 +1201,11 @@ declare const en: {
1155
1201
  'rc.hidden': string;
1156
1202
  'rc.readOnly': string;
1157
1203
  'rc.confirmTitle': string;
1158
- 'rc.change': string;
1159
1204
  'rc.notSet': string;
1160
1205
  'rc.usedBy': string;
1161
1206
  'rc.confirmNote': string;
1162
1207
  'rc.confirm': string;
1208
+ 'rc.skipped': string;
1163
1209
  'rc.done': string;
1164
1210
  'rc.failed': string;
1165
1211
  'set.button': string;
@@ -1278,6 +1324,11 @@ declare const en: {
1278
1324
  'rc.state.off': string;
1279
1325
  'rc.state.missing': string;
1280
1326
  'rc.state.blocked': string;
1327
+ 'settings.why.no-settings': string;
1328
+ 'settings.why.broken-link': string;
1329
+ 'settings.why.unsafe': string;
1330
+ 'settings.why.refuse': string;
1331
+ 'settings.why.other': string;
1281
1332
  'rc.dialogTitle': string;
1282
1333
  'rc.explain': string;
1283
1334
  'rc.allOff': string;