sideby 0.31.1 → 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":"20261030T033929-5e5870"}
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));
@@ -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.1",
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.1"
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