sideby 0.31.0 → 0.31.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/build.json CHANGED
@@ -1 +1 @@
1
- {"id":"20261029T160058-18f53c"}
1
+ {"id":"20261030T054007-cfb0e3"}
@@ -184,8 +184,8 @@ export async function runWithHandoff(rt, ref, userArgs, io, opts = {}) {
184
184
  const chain = newId();
185
185
  const dir = chainDir(rt.paths.stateDir, chain);
186
186
  await ensureChainDir(dir);
187
+ // The chain's hops so far, also what `selectNext` leaves out: each records the window that made it hand over.
187
188
  const hops = { hops: [] };
188
- const used = [];
189
189
  const own = rt.config.aliases?.[ref];
190
190
  let hop = { ref, args: [...aliasArgs(own), ...userArgs] };
191
191
  let n = 1;
@@ -221,7 +221,6 @@ export async function runWithHandoff(rt, ref, userArgs, io, opts = {}) {
221
221
  // Later hops carry no `--` of their own (continueArgs drops it), so the prompt goes after a fresh one.
222
222
  if (hop.prompt)
223
223
  args.push(...h.promptArgs(hop.prompt));
224
- used.push(account.ref);
225
224
  hops.hops.push({ ref: account.ref, startedAt: new Date().toISOString() });
226
225
  await writeJsonFile(join(dir, FILES.chain), hops);
227
226
  if (launch.notice)
@@ -236,7 +235,7 @@ export async function runWithHandoff(rt, ref, userArgs, io, opts = {}) {
236
235
  pending = pending.then(async () => {
237
236
  try {
238
237
  // Read by the hook once the threshold is crossed, so it answers for that moment (spec §3.17 "选号" 1).
239
- const d = await rt.handoffDecision(account, used, { ahead: true });
238
+ const d = await rt.handoffDecision(account, hops.hops, { ahead: true });
240
239
  if (stopped)
241
240
  return;
242
241
  const plan = {
@@ -279,7 +278,7 @@ export async function runWithHandoff(rt, ref, userArgs, io, opts = {}) {
279
278
  outcome = got;
280
279
  break;
281
280
  }
282
- const d = await decide(rt, account, used, got.ready.to, got.ready.trigger === 'manual');
281
+ const d = await decide(rt, account, hops.hops, got.ready.to, got.ready.trigger === 'manual');
283
282
  if (d.kind === 'pick') {
284
283
  outcome = { ...got, decision: d };
285
284
  break;
@@ -301,7 +300,7 @@ export async function runWithHandoff(rt, ref, userArgs, io, opts = {}) {
301
300
  if (kept)
302
301
  io.err(`sideby: ${account.ref} did not hand over: ${explain(kept)}`);
303
302
  else
304
- await noteUnhandedHighQuota(rt, account, used, settings.threshold, io);
303
+ await noteUnhandedHighQuota(rt, account, hops.hops, settings.threshold, io);
305
304
  return outcome.code;
306
305
  }
307
306
  const decision = outcome.decision;
@@ -399,5 +398,5 @@ export async function readyDecision(rt, env, to) {
399
398
  }
400
399
  const account = await rt.resolve(ref);
401
400
  const chain = await readJsonFile(join(dir, FILES.chain));
402
- return decide(rt, account, chain?.hops.map((h) => h.ref) ?? [account.ref], to, true);
401
+ return decide(rt, account, chain?.hops ?? [account.ref], to, true);
403
402
  }
@@ -39,6 +39,22 @@ export type HandoffDecision = {
39
39
  };
40
40
  skipped?: SkippedAccount[];
41
41
  };
42
+ /**
43
+ * An Account this chain already used: its ref, or its hop as `chain.json` keeps it, with the Quota window that made it
44
+ * hand over (`ChainHop.window`).
45
+ */
46
+ export type UsedAccount = string | {
47
+ ref: string;
48
+ window?: {
49
+ resetsAt: string;
50
+ };
51
+ };
52
+ /**
53
+ * The Accounts an automatic handoff leaves out (spec §3.17 "选号" 3): the origin, and every Account the chain used
54
+ * unless its latest hop handed over for a Quota window that has reset by `now` (ADR-0060). A bare ref, or a hop with no
55
+ * window (a manual handoff, an older chain), stays out.
56
+ */
57
+ export declare function stillUsed(origin: string, used: readonly UsedAccount[], now: Date): Set<string>;
42
58
  /** Organizations when both have one, else email domains when both have one, else the same. */
43
59
  export declare function sameOrganization(a?: AccountIdentity, b?: AccountIdentity): boolean;
44
60
  export declare function selectNext(input: {
@@ -47,8 +63,8 @@ export declare function selectNext(input: {
47
63
  settings: HandoffSettings;
48
64
  /** Short command → Account ref, so lists may name either. */
49
65
  aliases: Readonly<Record<string, string>>;
50
- /** Accounts this chain already used, the origin included. */
51
- used: readonly string[];
66
+ /** Accounts this chain already used, the origin included; one whose window has reset since may come back. */
67
+ used: readonly UsedAccount[];
52
68
  now: Date;
53
69
  /** Decide now what happens when the origin's fullest window reaches the threshold (see `waitUntil`). */
54
70
  ahead?: boolean;
@@ -1,5 +1,22 @@
1
1
  import { planHandoff } from './handoff.js';
2
2
  import { takeoverLimit, windowReset } from './quota-levels.js';
3
+ /**
4
+ * The Accounts an automatic handoff leaves out (spec §3.17 "选号" 3): the origin, and every Account the chain used
5
+ * unless its latest hop handed over for a Quota window that has reset by `now` (ADR-0060). A bare ref, or a hop with no
6
+ * window (a manual handoff, an older chain), stays out.
7
+ */
8
+ export function stillUsed(origin, used, now) {
9
+ const back = new Map();
10
+ for (const u of used) {
11
+ if (typeof u === 'string')
12
+ back.set(u, false);
13
+ else
14
+ back.set(u.ref, u.window !== undefined && windowReset(u.window.resetsAt, now));
15
+ }
16
+ const out = new Set([...back].flatMap(([ref, b]) => (b ? [] : [ref])));
17
+ out.add(origin);
18
+ return out;
19
+ }
3
20
  const domain = (email) => email.slice(email.lastIndexOf('@') + 1).toLowerCase();
4
21
  /** Organizations when both have one, else email domains when both have one, else the same. */
5
22
  export function sameOrganization(a, b) {
@@ -60,7 +77,7 @@ export function selectNext(input) {
60
77
  if (until)
61
78
  return { kind: 'wait', until };
62
79
  const allowed = new Set(s.crossOrganization.map(refOf));
63
- const used = new Set([origin.ref, ...input.used]);
80
+ const used = stillUsed(origin.ref, input.used, now);
64
81
  const family = s.families[origin.family];
65
82
  const fullAt = takeoverLimit(s.threshold);
66
83
  const rank = (fam) => planHandoff(fam, input.candidates.filter((c) => c.family === fam), now, { includeApi: true, fullAt }).accounts.map((e) => byRef.get(e.ref));
@@ -5,6 +5,11 @@ export declare const TICK_SECONDS = 5;
5
5
  export declare const STALE_SECONDS: number;
6
6
  /** A snapshot still running after this is ended, so a stuck one cannot stop the refreshes. */
7
7
  export declare const SNAPSHOT_TIMEOUT_SECONDS = 60;
8
+ /**
9
+ * Hours after which an idle item starts itself again. Over many hours the menu took longer and longer to open (1.6 to
10
+ * 2 s after 18 hours on macOS 27, 2026-10-30, against about 0.1 s fresh), with no cause found in the script.
11
+ */
12
+ export declare const RESTART_HOURS = 6;
8
13
  /** The macOS distributed notification that makes a running item read its snapshot again (`nudgeMenubar`). */
9
14
  export declare const MENUBAR_RELOAD = "dev.sideby.menubar.reload";
10
15
  export declare const MENUBAR_SCRIPT: string;
@@ -10,11 +10,17 @@ export const TICK_SECONDS = 5;
10
10
  export const STALE_SECONDS = 15 * 60;
11
11
  /** A snapshot still running after this is ended, so a stuck one cannot stop the refreshes. */
12
12
  export const SNAPSHOT_TIMEOUT_SECONDS = 60;
13
+ /**
14
+ * Hours after which an idle item starts itself again. Over many hours the menu took longer and longer to open (1.6 to
15
+ * 2 s after 18 hours on macOS 27, 2026-10-30, against about 0.1 s fresh), with no cause found in the script.
16
+ */
17
+ export const RESTART_HOURS = 6;
13
18
  /** The macOS distributed notification that makes a running item read its snapshot again (`nudgeMenubar`). */
14
19
  export const MENUBAR_RELOAD = 'dev.sideby.menubar.reload';
15
20
  export const MENUBAR_SCRIPT = String.raw `
16
21
  ObjC.import('Cocoa');
17
22
  ObjC.import('Carbon');
23
+ ObjC.import('stdlib');
18
24
  function run(argv) {
19
25
  var node = argv[0], entry = argv[1];
20
26
  var SNAPSHOT = ${SNAPSHOT_SECONDS}, TICK = ${TICK_SECONDS}, STALE = ${STALE_SECONDS}, TIMEOUT = ${SNAPSHOT_TIMEOUT_SECONDS};
@@ -46,6 +52,9 @@ function run(argv) {
46
52
  var LOADING = zh ? ${JSON.stringify(MENUBAR_STRINGS.zh.loading)} : ${JSON.stringify(MENUBAR_STRINGS.en.loading)};
47
53
  var OPEN_PANEL = zh ? ${JSON.stringify(MENUBAR_STRINGS.zh.openPanel)} : ${JSON.stringify(MENUBAR_STRINGS.en.openPanel)};
48
54
  var now = function () { return Date.now() / 1000; };
55
+ // The clock NSEvent timestamps use.
56
+ var uptime = function () { return Number($.NSProcessInfo.processInfo.systemUptime); };
57
+ var started = now();
49
58
 
50
59
  function sideby(args) {
51
60
  var t = $.NSTask.alloc.init;
@@ -96,7 +105,7 @@ function run(argv) {
96
105
  // RegisterEventHotKey: it needs no permission, unlike watching every key press. macOS hands a press to this app as a
97
106
  // system-defined event of subtype 6 whose data1 is the key's reference. While the menu is open the key is
98
107
  // unregistered, so the press reaches the menu, where a hidden item with the same key closes it.
99
- var hotkeyWant = null, hotkeyRef = 0, hotkeyBound = false, menuOpen = false, closedAt = 0;
108
+ var hotkeyWant = null, hotkeyRef = 0, hotkeyBound = false, menuOpen = false, closedAt = 0, lastUse = 0;
100
109
  // Whether the shortcut could be registered ('ok', 'taken', '' when off), and what the last snapshot was told: the
101
110
  // status with the shortcut it is about, so a report never lands on a shortcut changed since.
102
111
  var hotkeyStatus = '', hotkeyReported = '';
@@ -116,8 +125,8 @@ function run(argv) {
116
125
  function watchKeys() {
117
126
  if (monitor) return;
118
127
  monitor = $.NSEvent.addLocalMonitorForEventsMatchingMaskHandler($.NSEventMaskSystemDefined, function (e) {
119
- // A press queued while the menu was open arrives just after it closes; it meant "close", not "open again".
120
- if (e.subtype === 6 && hotkeyRef && Number(e.data1) === hotkeyRef && !menuOpen && now() - closedAt > 0.5) openMenu();
128
+ // A press made before the menu closed meant "close", not "open again"; any later press opens it at once.
129
+ if (e.subtype === 6 && hotkeyRef && Number(e.data1) === hotkeyRef && !menuOpen && Number(e.timestamp) > closedAt) openMenu();
121
130
  return e;
122
131
  });
123
132
  }
@@ -286,22 +295,27 @@ function run(argv) {
286
295
  var HEAD_X = 15, HEAD_TEXT_X = 34;
287
296
 
288
297
  // A quota window as a small rounded bar: a soft track, filled as far as it is used, coloured by level.
289
- var BAR_W = 44, BAR_H = 5;
298
+ // Drawn once per fill and colour and kept until light or dark mode changes, so a refresh draws none again.
299
+ var BAR_W = 44, BAR_H = 5, bars = {}, barsDark = null;
290
300
  function bar(b, old) {
301
+ var d = dark(), fill = stale() || old ? 'old' : BAR[b.level] || BAR.ok, pct = Math.max(0, Math.min(100, b.percent));
302
+ if (d !== barsDark) { bars = {}; barsDark = d; }
303
+ var key = pct + fill;
304
+ if (bars[key]) return bars[key];
291
305
  var img = $.NSImage.alloc.initWithSize($.NSMakeSize(BAR_W, BAR_H));
292
306
  img.lockFocus;
293
- hex(dark() ? '#1f2c3a' : '#e4edf4').set;
307
+ hex(d ? '#1f2c3a' : '#e4edf4').set;
294
308
  $.NSBezierPath.bezierPathWithRoundedRectXRadiusYRadius($.NSMakeRect(0, 0, BAR_W, BAR_H), BAR_H / 2, BAR_H / 2).fill;
295
- if (b.percent > 0) {
296
- (stale() || old ? $.NSColor.tertiaryLabelColor : hex(BAR[b.level] || BAR.ok)).set;
297
- var w = Math.max(BAR_H, BAR_W * Math.min(100, b.percent) / 100);
309
+ if (pct > 0) {
310
+ (fill === 'old' ? $.NSColor.tertiaryLabelColor : hex(fill)).set;
311
+ var w = Math.max(BAR_H, BAR_W * pct / 100);
298
312
  $.NSBezierPath.bezierPathWithRoundedRectXRadiusYRadius($.NSMakeRect(0, 0, w, BAR_H), BAR_H / 2, BAR_H / 2).fill;
299
313
  }
300
314
  img.unlockFocus;
301
315
  var att = $.NSTextAttachment.alloc.init;
302
316
  att.image = img;
303
317
  att.bounds = $.NSMakeRect(0, 1.5, BAR_W, BAR_H);
304
- return $.NSAttributedString.attributedStringWithAttachment(att);
318
+ return (bars[key] = $.NSAttributedString.attributedStringWithAttachment(att));
305
319
  }
306
320
 
307
321
  // Columns: the name, then per window its bar and percent, then the reset time. One set of tab stops lines them up
@@ -501,13 +515,16 @@ function run(argv) {
501
515
  'menuWillOpen:': { types: ['void', ['id']], implementation: function () { menuOpen = true; try { unregisterHotkey(); } catch (e) {} } },
502
516
  'menuDidClose:': {
503
517
  types: ['void', ['id']],
504
- implementation: function () { menuOpen = false; closedAt = now(); try { registerHotkey(); } catch (e) {} },
518
+ implementation: function () { menuOpen = false; closedAt = uptime(); lastUse = now(); try { registerHotkey(); } catch (e) {} },
505
519
  },
506
520
  'closeMenu:': { types: ['void', ['id']], implementation: function () {} },
507
521
  'tick:': {
508
522
  types: ['void', ['id']],
509
523
  implementation: function () {
510
524
  actions = actions.filter(function (t) { return t.running; });
525
+ // After RESTART_HOURS, while nothing is open, running or just used, it ends with a failure code so launchd
526
+ // starts it again at once (it restarts only after a failed exit): the icon is gone for about a second.
527
+ if (now() - started > ${RESTART_HOURS} * 3600 && !menuOpen && !task && !actions.length && now() - lastUse > 60) $.exit(75);
511
528
  if (task && task.running && now() - lastStart > TIMEOUT) task.terminate;
512
529
  if (task && !task.running) finishSnapshot();
513
530
  lookAtIcon();
@@ -6,7 +6,7 @@ import { type DoctorReport } from './core/doctor.ts';
6
6
  import type { TraceFetcher } from './core/egress.ts';
7
7
  import { UserError } from './core/errors.ts';
8
8
  import { type HandoffPlan } from './core/handoff.ts';
9
- import { type HandoffDecision } from './core/handoff-select.ts';
9
+ import { type HandoffDecision, type UsedAccount } from './core/handoff-select.ts';
10
10
  import { type DoctorHistory } from './core/last-doctor.ts';
11
11
  import { type HostLaunch, type PreparedLaunch } from './core/launch.ts';
12
12
  import { type NetworkOverview } from './core/network.ts';
@@ -367,11 +367,12 @@ export interface Runtime {
367
367
  handoffSettings(): HandoffSettings;
368
368
  /**
369
369
  * Where an Auto Handoff from `origin` would go now (spec §3.17 "选号"): every Account of every Family is a
370
- * candidate; `used` lists the chain's Accounts so far. `ahead` decides early what happens once the origin's fullest
370
+ * candidate; `used` lists the chain's Accounts so far, as refs or as its hops (an Account whose hop recorded a window
371
+ * that has reset since may be picked again, ADR-0060). `ahead` decides early what happens once the origin's fullest
371
372
  * window reaches the threshold, as plan.json and the Panel need. `to` names the only candidate (`handoff ready --to`);
372
373
  * `manual` (`handoff ready`) never waits for a reset.
373
374
  */
374
- handoffDecision(origin: Account, used: readonly string[], opts?: {
375
+ handoffDecision(origin: Account, used: readonly UsedAccount[], opts?: {
375
376
  ahead?: boolean;
376
377
  to?: string;
377
378
  manual?: boolean;
@@ -8,7 +8,7 @@ import { hostSettingsFile } from './core/edit-settings.js';
8
8
  import { UserError } from './core/errors.js';
9
9
  import { planHandoff } from './core/handoff.js';
10
10
  import { handoffFindings, tapState } from './core/handoff-doctor.js';
11
- import { selectNext } from './core/handoff-select.js';
11
+ import { selectNext, } from './core/handoff-select.js';
12
12
  import { identityOf } from './core/identity.js';
13
13
  import { inboundFindings } from './core/inbound.js';
14
14
  import { mergeDoctorHistory, readDoctorHistory, writeDoctorHistory, } from './core/last-doctor.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sideby",
3
- "version": "0.31.0",
3
+ "version": "0.31.2",
4
4
  "description": "Run work, personal and API-key accounts at the same time, without their configs drifting apart.",
5
5
  "license": "MIT",
6
6
  "author": "Adonis0123 (https://github.com/Adonis0123)",
@@ -2,7 +2,7 @@
2
2
  name: sideby
3
3
  description: Use when the user runs, or wants to run, several AI coding accounts (Claude Code, Codex, Grok Build, pi) side by side. Covers installing sideby and setting up a new account ("install sideby", "set up another Claude account", "add cc008", "配置一个 cc00x", "再加一个 Codex 账号"), explaining what accounts share and what stays separate ("what do my accounts share?", "这些账号共享了什么"), showing which account a session is ("show [cc001] in the status line", "加上账号标识"), finding a past session of any account ("找一下我上周改登录页的那个会话"), telling another running session something, in any account ("告诉 cc002 ……", "给跑构建的那个会话发消息"; Claude Code's own SendMessage reaches only sessions of the same account), seeing accounts, quota and usage, moving on when one hits its 5-hour or weekly limit, moving the current task to another account ("用 cc008 继续", "交回 cc008"), adding a short command (alias) or a pick command that starts whichever account has the most quota ("加个 cc"), adding an API account from a vendor's docs ("加一个 DeepSeek API 账号"), supporting a new tool, and repairing drifted account directories (skills, hooks, rules or settings not shared, wrong symlinks, credential file permissions). Drives the `sideby` CLI with `--json`; the agent does every step except browser sign-in, filling in secrets and starting interactive sessions, which it hands to the user as one command (inside an Auto Handoff session, `sideby handoff ready --to` moves the task itself).
4
4
  metadata:
5
- version: "0.31.0"
5
+ version: "0.31.2"
6
6
  requires:
7
7
  bins: [sideby, node]
8
8
  cliHelp: sideby --help
@@ -43,7 +43,7 @@ With config `"handoff": { "auto": true }`, a session sideby started hands its ta
43
43
  - When it says a window is about to run out (the message names it, such as "weekly (7d) quota is at 98%"; each window hands over at its own pace, ADR-0032), finish the current step, update the brief, and end your turn. sideby starts the next account from it.
44
44
  - End the brief with the line `<!-- handoff brief complete -->` once it is complete. Without it sideby asks once more, then adds its own records under what you wrote.
45
45
  - When a user asks why a session handed over "with 95% left": the 5-hour and weekly windows are separate, and the fullest one decides. Run `sideby quota` and read both windows.
46
- - When the user asks to hand over now, update the brief, run `sideby handoff ready` (add `--brief <file>` when the user's own handoff tool wrote one), and end your turn. Tell the user the account it prints, not what `sideby next` says: the chain never goes back to an account it already used. When the user names an account ("go back to cc008"), run `sideby handoff ready --to <account>`; it works for an account this chain already used. When the quota is about to run out and sideby says the session will wait for the reset, the user can move on at once by typing `! sideby handoff ready` in the session (the model cannot answer at the limit); tell them so if they ask why nothing moved.
46
+ - When the user asks to hand over now, update the brief, run `sideby handoff ready` (add `--brief <file>` when the user's own handoff tool wrote one), and end your turn. Tell the user the account it prints, not what `sideby next` says: the chain goes back to an account it already used only once the quota window that account handed over for has reset. When the user names an account ("go back to cc008"), run `sideby handoff ready --to <account>`; it works for an account this chain already used. When the quota is about to run out and sideby says the session will wait for the reset, the user can move on at once by typing `! sideby handoff ready` in the session (the model cannot answer at the limit); tell them so if they ask why nothing moved.
47
47
 
48
48
  ### Turning it on for the user
49
49