sideby 0.31.2 → 0.32.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 (55) hide show
  1. package/README.md +4 -4
  2. package/dist/build.json +1 -1
  3. package/dist/src/cli/commands.d.ts +0 -4
  4. package/dist/src/cli/commands.js +76 -14
  5. package/dist/src/cli/format.js +3 -2
  6. package/dist/src/cli/json-schemas.js +45 -5
  7. package/dist/src/cli/main.js +19 -159
  8. package/dist/src/core/ask.js +6 -1
  9. package/dist/src/core/cli-commands.d.ts +56 -0
  10. package/dist/src/core/cli-commands.js +842 -0
  11. package/dist/src/core/handoff-chain.d.ts +9 -3
  12. package/dist/src/core/handoff-chain.js +3 -2
  13. package/dist/src/core/handoff-rules.js +5 -5
  14. package/dist/src/core/handoff-run.js +19 -2
  15. package/dist/src/core/handoff-select.d.ts +15 -5
  16. package/dist/src/core/handoff-select.js +34 -22
  17. package/dist/src/core/handoff.d.ts +36 -3
  18. package/dist/src/core/handoff.js +57 -18
  19. package/dist/src/core/pick-commands.d.ts +19 -4
  20. package/dist/src/core/pick-commands.js +19 -5
  21. package/dist/src/core/quota-levels.d.ts +67 -4
  22. package/dist/src/core/quota-levels.js +82 -6
  23. package/dist/src/core/search-catalog.js +20 -0
  24. package/dist/src/families/claude/index.js +3 -0
  25. package/dist/src/families/claude/quota-fetch.d.ts +26 -0
  26. package/dist/src/families/claude/quota-fetch.js +236 -0
  27. package/dist/src/handoff/hook.js +5 -0
  28. package/dist/src/menubar/script.js +8 -3
  29. package/dist/src/menubar/snapshot.d.ts +9 -5
  30. package/dist/src/menubar/snapshot.js +37 -24
  31. package/dist/src/menubar/strings.d.ts +6 -4
  32. package/dist/src/menubar/strings.js +6 -4
  33. package/dist/src/panel/handler.js +7 -3
  34. package/dist/src/panel/i18n.d.ts +15 -0
  35. package/dist/src/panel/i18n.js +36 -6
  36. package/dist/src/panel/page-logic.d.ts +32 -8
  37. package/dist/src/panel/page-logic.js +43 -16
  38. package/dist/src/panel/page-script.js +129 -17
  39. package/dist/src/panel/page-styles.js +18 -0
  40. package/dist/src/panel/page.js +6 -1
  41. package/dist/src/runtime.d.ts +2 -1
  42. package/dist/src/runtime.js +10 -4
  43. package/dist/testing/index.d.ts +5 -0
  44. package/dist/testing/index.js +2 -0
  45. package/package.json +2 -2
  46. package/schemas/commands-list.json +165 -0
  47. package/schemas/menubar-snapshot.json +3 -3
  48. package/schemas/next.json +57 -4
  49. package/skills/sideby/SKILL.md +3 -2
  50. package/skills/sideby/references/accounts.md +1 -1
  51. package/skills/sideby/references/ai-tasks.md +2 -2
  52. package/skills/sideby/references/diagnose.md +1 -1
  53. package/skills/sideby/references/handoff.md +13 -9
  54. package/skills/sideby/references/panel.md +11 -1
  55. package/skills/sideby/references/quota.md +9 -3
package/README.md CHANGED
@@ -25,7 +25,7 @@ npm i -g sideby
25
25
  sideby new claude work # create ~/.claude-work, sharing ~/.claude's skills and hooks
26
26
  sideby login claude:work # sign in once
27
27
  sideby run work # Claude Code on the work account
28
- sideby quota setup claude --yes # Claude quota in the panel; undo: sideby quota teardown claude
28
+ sideby quota setup claude --yes # optional: live Claude quota while a session runs; undo: sideby quota teardown claude
29
29
  sideby ui --background # every account's quota at http://127.0.0.1:17420, still there after you close the terminal
30
30
  ```
31
31
 
@@ -72,7 +72,7 @@ On macOS, the same quota sits in the menu bar (`sideby menubar on`): click or pr
72
72
  |---|---|---|---|---|
73
73
  | `CLAUDE_CONFIG_DIR` and an alias | Yes. Each terminal exports the variable. | Each directory is its own copy. They drift unless you symlink by hand. | That session's status line | One alias per account |
74
74
  | [cc-switch](https://github.com/farion1231/cc-switch) | Enabling a provider writes the host's live config, so open sessions share that switch. | Plugin settings are copied across providers as a separate step. | The active provider, from its quota endpoint | Install the desktop app |
75
- | sideby | Yes. `sideby run` selects the directory for that process and leaves your shell alone. | Linked to the main account. `sideby doctor --fix` repairs copies. Sign-in and sessions stay separate. | Every account, from local files. Claude needs `quota setup`. | `npm i -g sideby`, then `sideby new` and sign in |
75
+ | sideby | Yes. `sideby run` selects the directory for that process and leaves your shell alone. | Linked to the main account. `sideby doctor --fix` repairs copies. Sign-in and sessions stay separate. | Every account, from local files and each tool's own CLI. | `npm i -g sideby`, then `sideby new` and sign in |
76
76
 
77
77
  cc-switch's docs describe that switch: it writes the live settings file ([README](https://github.com/farion1231/cc-switch#readme)). [#1105](https://github.com/farion1231/cc-switch/issues/1105) and [#2908](https://github.com/farion1231/cc-switch/issues/2908) ask for several sessions at once. [#1106](https://github.com/farion1231/cc-switch/issues/1106) is closed; the maintainer says Claude Code's "open terminal" can start one provider without changing the global config.
78
78
 
@@ -88,7 +88,7 @@ cc-switch's docs describe that switch: it writes the live settings file ([README
88
88
  | Have the panel ready in the background whenever you log in | **Settings › Startup** in the panel, or `sideby autostart on` | [Start at login](docs/guide/usage.md#start-at-login) |
89
89
  | Add an API key account (DeepSeek, a gateway, …) | `sideby new claude deepseek --api` | [API accounts](docs/guide/usage.md#api-accounts) |
90
90
  | Find and fix config drift between accounts | `sideby doctor --fix` | [Doctor](docs/guide/usage.md#doctor) |
91
- | See Claude quota (Codex needs no setup) | `sideby quota setup claude --yes` | [Claude quota](docs/guide/usage.md#claude-quota) |
91
+ | See every account's quota (no setup) | `sideby quota` | [Claude quota](docs/guide/usage.md#claude-quota) |
92
92
  | Find the cheapest auto-compact size from your own sessions, and use it in one click | `sideby tune` (or the panel's Context tuning tab) | [Context tuning](docs/guide/usage.md#context-tuning) |
93
93
  | See each account's model and effort, and set them per account | `sideby model <account>` (or click the model in the panel) | [Model and effort](docs/guide/usage.md#model-and-effort) |
94
94
  | Stop Claude and Codex when your requests would leave from a country you did not allow, for example when the proxy stopped | **Settings › Network check** in the panel, or `sideby network on` | [Network check](docs/guide/usage.md#network-check) |
@@ -109,7 +109,7 @@ cc-switch's docs describe that switch: it writes the live settings file ([README
109
109
 
110
110
  | Host | Account directories | Sign-in | Quota | Usage (7 days) |
111
111
  |---|---|---|---|---|
112
- | Claude Code | `~/.claude`, `~/.claude-<name>` | `claude auth login` | ✓ after `quota setup claude` | ✓ |
112
+ | Claude Code | `~/.claude`, `~/.claude-<name>` | `claude auth login` | ✓ | ✓ |
113
113
  | Codex CLI | `~/.codex`, `~/.codex-<name>` | `codex login` | ✓ | ✓ |
114
114
  | Grok Build | `~/.grok`, `~/.grok-<name>` | `grok login` | weekly, asked from the `grok` CLI | no public source |
115
115
  | pi | `~/.pi/agent`, `~/.pi-<name>/agent` | `/login` inside pi | no public source | no public source |
package/dist/build.json CHANGED
@@ -1 +1 @@
1
- {"id":"20261030T054007-cfb0e3"}
1
+ {"id":"20261030T091708-6dfc06"}
@@ -165,8 +165,4 @@ export declare function cmdTheme(a: ParsedArgs, io: Io): Promise<number>;
165
165
  export declare function cmdNetwork(a: ParsedArgs, io: Io): Promise<number>;
166
166
  /** `sideby unattended …` (spec §3.37, ADR-0058): status, on and off, the Schedule, Pending Decisions and `defer`. */
167
167
  export declare function cmdUnattended(a: ParsedArgs, io: Io): Promise<number>;
168
- /**
169
- * `sideby commands <words>` (spec §3.36, ADR-0054): the Search Catalog the Panel's Command Palette searches, read-only.
170
- * Titles and places are in English, as every other command prints; the words may be English or Chinese.
171
- */
172
168
  export declare function cmdCommands(a: ParsedArgs, io: Io): number;
@@ -5,6 +5,7 @@ import { fileURLToPath } from 'node:url';
5
5
  import { aliasesByAccount } from '../core/accounts.js';
6
6
  import { listAppProfiles, openAppProfile, parseProfileRef, removeAppProfile } from '../core/app-profiles.js';
7
7
  import { browserReport, openInBrowser, setBrowserChoice, setBrowserSignIns, } from '../core/browser-profiles.js';
8
+ import { CLI_COMMANDS, COMMAND_GROUPS, commonCommands } from '../core/cli-commands.js';
8
9
  import { aliasAccount, aliasArgs, aliasRefs, editConfigUpdate } from '../core/config.js';
9
10
  import { openDesktopApp, withDesktopApps } from '../core/desktop-app.js';
10
11
  import { editSettings } from '../core/edit-settings.js';
@@ -18,7 +19,7 @@ import { installHint, runHost } from '../core/launch.js';
18
19
  import { loginAfterLine, loginBeforeLine } from '../core/login-check.js';
19
20
  import { accountModel, setAccountModel } from '../core/model-choice.js';
20
21
  import { resolvePaths, tildify } from '../core/paths.js';
21
- import { USAGE_DAYS } from '../core/quota-levels.js';
22
+ import { takeoverLimits, USAGE_DAYS } from '../core/quota-levels.js';
22
23
  import { groupsToUndo, remoteControlNothingToDo, remoteControlTodo, } from '../core/remote-control.js';
23
24
  import { SEARCH_CATALOG, searchCatalog } from '../core/search-catalog.js';
24
25
  import { SHELLS } from '../core/shell-init.js';
@@ -575,7 +576,7 @@ async function runPick(rt, name, args, io, opts = {}) {
575
576
  if (choice.ref === null) {
576
577
  const now = rt.readContext().now;
577
578
  const why = choice.earliestReset
578
- ? `every ${family} account is at its limit; ${choice.earliestReset.ref} is back at ${clock(choice.earliestReset.at, now)}`
579
+ ? `every signed-in ${family} account has used up its quota; ${choice.earliestReset.ref} is back at ${clock(choice.earliestReset.at, now)}`
579
580
  : `no ${family} account can be used now`;
580
581
  const signIn = choice.signIn.length
581
582
  ? `; sign in with \`sideby login ${choice.signIn.join('` or `sideby login ')}\``
@@ -584,7 +585,7 @@ async function runPick(rt, name, args, io, opts = {}) {
584
585
  return 1;
585
586
  }
586
587
  const { pickLine } = await import('../core/pick-commands.js');
587
- io.err(c.dim(`sideby: ${pickLine(name, choice)}`));
588
+ io.err((choice.reason === 'tight' ? c.yellow : c.dim)(`sideby: ${pickLine(name, choice, family)}`));
588
589
  return runAccount(rt, choice.ref, args, io, opts);
589
590
  }
590
591
  /**
@@ -630,31 +631,45 @@ export async function cmdNext(a, io) {
630
631
  return plan.pick && plan.hasQuota ? 0 : 1;
631
632
  }
632
633
  const now = rt.readContext().now;
634
+ const limits = plan.tight
635
+ ? { short: plan.tight.limit, long: plan.tight.longLimit }
636
+ : takeoverLimits(rt.handoffSettings().threshold);
637
+ const low = (e) => e.state === 'full' && e.pressure !== null && e.pressure < 100;
638
+ // The window closest to its own Takeover Limit, which decides the rank: "7d 87% of 95%".
639
+ const closest = (e) => e.window
640
+ ? `${e.window.label} ${e.window.usedPercent}% of ${e.window.limit}%`
641
+ : `${Math.round(e.pressure ?? 0)}%`;
633
642
  const note = (e) => {
634
643
  if (e.sameLoginAs)
635
644
  return `same login as ${e.sameLoginAs}, which shares its quota; skipped`;
636
645
  if (e.state === 'ready')
637
- return `fullest window ${Math.round(e.pressure ?? 0)}%`;
646
+ return `closest to its limit: ${closest(e)}`;
638
647
  if (e.state === 'unknown')
639
648
  return 'no quota data yet';
640
649
  if (e.state === 'api')
641
650
  return includeApi ? 'API account, pay per use' : 'left out; add --include-api to use it';
651
+ if (low(e)) {
652
+ const over = `past its limit: ${closest(e)} (limits ${limits.short}% for 5-hour, ${limits.long}% for weekly windows)`;
653
+ return e.resetsAt ? `${over} until ${clock(e.resetsAt, now)}` : over;
654
+ }
642
655
  if (e.state === 'full')
643
- return e.resetsAt ? `back at ${clock(e.resetsAt, now)}` : 'at its limit';
656
+ return e.resetsAt ? `used up; back at ${clock(e.resetsAt, now)}` : 'used up';
644
657
  return `signed out; sign in with \`sideby login ${e.ref}\``;
645
658
  };
646
659
  const mark = { ready: c.green, unknown: c.yellow, api: c.cyan, full: c.red, 'logged-out': c.dim };
660
+ // A full Account with no window used up still has some quota: `low` in the table, and a Last Resort can start it.
661
+ const stateText = (e) => low(e) ? c.yellow('low') : mark[e.state](e.state === 'logged-out' ? 'signed out' : e.state);
647
662
  io.out(table(plan.accounts.map((e) => [
648
663
  e.ref === plan.pick ? c.green('→') : ' ',
649
664
  c.bold(e.ref),
650
- mark[e.state](e.state === 'logged-out' ? 'signed out' : e.state),
665
+ stateText(e),
651
666
  c.dim(note(e)),
652
667
  ]), ['', 'ACCOUNT', 'STATE', 'NOTE']));
653
668
  if (!plan.pick) {
654
669
  const out = plan.accounts.filter((e) => e.state === 'logged-out').map((e) => `sideby login ${e.ref}`);
655
670
  const apiLeft = !includeApi && plan.accounts.some((e) => e.state === 'api');
656
671
  const why = plan.earliestReset
657
- ? `every ${family} account is at its limit; ${plan.earliestReset.ref} is back at ${clock(plan.earliestReset.at, now)}`
672
+ ? `every signed-in ${family} account has used up its quota; ${plan.earliestReset.ref} is back at ${clock(plan.earliestReset.at, now)}`
658
673
  : `no ${family} account can be used now`;
659
674
  const same = plan.accounts.filter((e) => e.sameLoginAs).map((e) => e.ref);
660
675
  const sameNote = same.length ? `; ${same.join(', ')} share the quota of ${plan.from}` : '';
@@ -674,10 +689,12 @@ export async function cmdNext(a, io) {
674
689
  return 1;
675
690
  }
676
691
  const reason = picked.state === 'ready'
677
- ? `lowest quota pressure, ${Math.round(picked.pressure ?? 0)}%`
678
- : picked.state === 'unknown'
679
- ? 'no account with known room; this one has no quota data yet'
680
- : 'API account, pay per use';
692
+ ? `furthest from its limits, ${closest(picked)}`
693
+ : plan.tight
694
+ ? `every ${family} account is past its limit (${plan.tight.limit}% of a 5-hour window, ${plan.tight.longLimit}% of a weekly one); this one has the most left, ${closest(picked)}`
695
+ : picked.state === 'unknown'
696
+ ? 'no account with known room; this one has no quota data yet'
697
+ : 'API account, pay per use';
681
698
  io.out(`\nNext: ${c.bold(plan.pick)} (${reason}).`);
682
699
  if (a.flags.has('dry-run')) {
683
700
  io.out(`Start it with \`${runCmd}\`.`);
@@ -2411,14 +2428,15 @@ export function readKeyLine(input = process.stdin) {
2411
2428
  throw new UserError('Run `sideby key` in a terminal or use the Panel key box.', { code: 'tty-required' });
2412
2429
  return new Promise((resolve, reject) => {
2413
2430
  const raw = input.isRaw;
2414
- const paused = input.isPaused();
2431
+ // A stdin nobody read yet is not paused but not flowing either; leaving it flowing keeps the process alive.
2432
+ const flowing = input.readableFlowing === true;
2415
2433
  let value = '';
2416
2434
  const finish = (error) => {
2417
2435
  input.off('data', onData);
2418
2436
  input.off('end', onEnd);
2419
2437
  input.off('error', onError);
2420
2438
  input.setRawMode(raw);
2421
- if (paused)
2439
+ if (!flowing)
2422
2440
  input.pause();
2423
2441
  if (error)
2424
2442
  reject(error);
@@ -4241,10 +4259,54 @@ export async function cmdUnattended(a, io) {
4241
4259
  * `sideby commands <words>` (spec §3.36, ADR-0054): the Search Catalog the Panel's Command Palette searches, read-only.
4242
4260
  * Titles and places are in English, as every other command prints; the words may be English or Chinese.
4243
4261
  */
4262
+ /** One command of the Command List as `sideby commands --json` gives it (spec §3.38). */
4263
+ function commandOut(cmd) {
4264
+ const place = cmd.feature ? SEARCH_CATALOG.find((e) => e.id === cmd.feature) : undefined;
4265
+ return {
4266
+ id: cmd.id,
4267
+ usage: cmd.usage,
4268
+ description: cmd.summary.en,
4269
+ example: cmd.example ?? null,
4270
+ featureId: place?.id ?? null,
4271
+ panel: place?.panel.en ?? null,
4272
+ };
4273
+ }
4274
+ /** Rows of `command description`; a command too long for the column gets the description on the next line. */
4275
+ function commandRows(rows) {
4276
+ const col = Math.min(44, Math.max(...rows.map(([u]) => u.length)) + 2);
4277
+ return rows.flatMap(([u, d]) => u.length + 2 <= col ? [` ${u.padEnd(col)}${d}`] : [` ${u}`, ` ${' '.repeat(col)}${d}`]);
4278
+ }
4279
+ /** `sideby commands` with no words: every command by task, the common ones first, each with an example there. */
4280
+ function listCommands(a, io) {
4281
+ const common = commonCommands();
4282
+ if (a.flags.has('json')) {
4283
+ json(io, {
4284
+ common: common.map((cmd) => cmd.id),
4285
+ groups: COMMAND_GROUPS.map((g) => ({
4286
+ id: g.id,
4287
+ title: g.title.en,
4288
+ commands: CLI_COMMANDS.filter((cmd) => cmd.group === g.id).map(commandOut),
4289
+ })).filter((g) => g.commands.length),
4290
+ });
4291
+ return 0;
4292
+ }
4293
+ const out = [
4294
+ c.bold('Common'),
4295
+ ...commandRows(common.map((cmd) => [cmd.example ?? cmd.usage, cmd.summary.en])),
4296
+ ];
4297
+ for (const g of COMMAND_GROUPS) {
4298
+ const cmds = CLI_COMMANDS.filter((cmd) => cmd.group === g.id);
4299
+ if (cmds.length)
4300
+ out.push('', c.bold(g.title.en), ...commandRows(cmds.map((cmd) => [cmd.usage, cmd.summary.en])));
4301
+ }
4302
+ out.push('', c.dim('`sideby <command> --help` explains one; `sideby commands <words>` finds where a feature lives in the Panel. In the Panel: Commands, or press ?.'));
4303
+ io.out(out.join('\n'));
4304
+ return 0;
4305
+ }
4244
4306
  export function cmdCommands(a, io) {
4245
4307
  const query = a.positionals.join(' ').trim();
4246
4308
  if (!query)
4247
- throw new UsageError('usage: sideby commands <words> [--json], for example: sideby commands language');
4309
+ return listCommands(a, io);
4248
4310
  const results = searchCatalog(query, SEARCH_CATALOG).map(({ entry }) => ({
4249
4311
  id: entry.id,
4250
4312
  kind: entry.kind,
@@ -1,4 +1,4 @@
1
- import { quotaLevel } from '../core/quota-levels.js';
1
+ import { windowLevel } from '../core/quota-levels.js';
2
2
  import { MIN_CALLS } from '../core/tuning.js';
3
3
  const useColor = () => !process.env.NO_COLOR && Boolean(process.stdout.isTTY);
4
4
  const paint = (code) => (s) => (useColor() ? `\x1b[${code}m${s}\x1b[0m` : s);
@@ -88,7 +88,8 @@ function windowText(w, now) {
88
88
  if (Date.parse(w.resetsAt) <= now.getTime())
89
89
  return `${label} reset`;
90
90
  const pct = Math.round(w.usedPercent);
91
- const level = quotaLevel(pct);
91
+ // Each window by its own levels: a weekly window warns at 85% and turns red at 95% (spec §3.26).
92
+ const level = windowLevel({ ...w, usedPercent: pct });
92
93
  const color = level === 'fail' ? c.red : level === 'warn' ? c.yellow : c.green;
93
94
  return `${label} ${color(`${pct}%`)} ${c.dim(`→ ${clock(w.resetsAt, now)}`)}`;
94
95
  }
@@ -429,7 +429,7 @@ const MenubarRow = Type.Object({
429
429
  description: "A Host whose every limit covers one model group: a line per group under the account, each with its own bars; the account's `bars` are then null.",
430
430
  }),
431
431
  reset: Type.String({
432
- description: 'Until the fullest window resets, such as `4d 17h`; empty when nothing is used.',
432
+ description: 'Which window resets and how long until it does, such as `7d · in 4d 17h`: the window closest to its own red level (85% for 5 hours, 95% for longer windows). Empty when nothing is used.',
433
433
  }),
434
434
  note: Type.String({
435
435
  description: 'A no-quota explanation, or an old-reading warning beside the bars.',
@@ -691,12 +691,22 @@ export const OUTPUT_SCHEMAS = {
691
691
  Type.Literal('full'),
692
692
  Type.Literal('logged-out'),
693
693
  ], {
694
- description: 'ready and unknown can be picked; api only with --include-api; full and logged-out never.',
694
+ description: 'ready and unknown can be picked; api only with --include-api; logged-out never. full (a window at or past its own Takeover Limit: 5-hour windows the handoff threshold - 10, windows longer than a day the threshold) only as a Last Resort: when no subscription account is ready or unknown, the one with the lowest limitUse and no window used up, and `tight` is set.',
695
695
  }),
696
696
  pressure: Type.Union([Type.Number(), Type.Null()], {
697
697
  description: 'Used percent of the fullest window not reset yet; null without quota.',
698
698
  }),
699
- resetsAt: Type.Optional(Type.String({ description: 'For full: when its last full window resets.' })),
699
+ limitUse: Type.Union([Type.Number(), Type.Null()], {
700
+ description: 'Limit Use: the percent of its own Takeover Limit that the closest window has used (a weekly 87% under 95 is 91.6); null without quota. Ready accounts rank by it, lowest first.',
701
+ }),
702
+ window: Type.Optional(Type.Object({
703
+ label: Type.String({ description: 'Such as `5h` or `7d`.' }),
704
+ usedPercent: Type.Number({ description: 'Rounded.' }),
705
+ limit: Type.Number({ description: "This window's Takeover Limit in percent." }),
706
+ }, { description: 'The window closest to its own Takeover Limit; absent when none is open.' })),
707
+ resetsAt: Type.Optional(Type.String({
708
+ description: 'For full: when it is usable again. With a window used up, when those windows reset; otherwise when every window is under its Takeover Limit again.',
709
+ })),
700
710
  observedAt: Type.Optional(Type.String({ description: "When the account's quota was recorded (its last session)." })),
701
711
  quotaFrom: Type.Optional(Type.String({
702
712
  description: 'The account the quota was read from, when it is another account of the same login.',
@@ -708,8 +718,18 @@ export const OUTPUT_SCHEMAS = {
708
718
  hasQuota: Type.Boolean({
709
719
  description: 'False when no account has quota data: the pick is then a guess, and `sideby next` does not start it (exit 1).',
710
720
  }),
721
+ tight: Type.Optional(Type.Object({
722
+ limit: Type.Number({
723
+ description: 'The Takeover Limit of 5-hour windows in percent (handoff threshold - 10).',
724
+ }),
725
+ longLimit: Type.Number({
726
+ description: 'The Takeover Limit of windows longer than a day in percent (the handoff threshold).',
727
+ }),
728
+ }, {
729
+ description: 'Set when the pick is a Last Resort: every subscription account has a window at or past its Takeover Limit, and the pick is the one with the lowest limitUse and no window used up.',
730
+ })),
711
731
  earliestReset: Type.Optional(Type.Object({ ref: Str, at: Str }, {
712
- description: 'Set when nothing can be picked and some accounts are full: the first to come back.',
732
+ description: 'Set when nothing can be picked and some accounts are full (every one has a window used up): the first to come back.',
713
733
  })),
714
734
  }, { title: 'sideby next --json' }),
715
735
  'quota-setup': Type.Object({ schemaVersion: Version, family: Str, applied: Type.Boolean(), plan: QuotaSetupPlan }, { title: 'sideby quota setup --json' }),
@@ -881,6 +901,26 @@ export const OUTPUT_SCHEMAS = {
881
901
  cliCommand: Type.Union([Str, Type.Null()]),
882
902
  })),
883
903
  }, { title: 'sideby commands --json' }),
904
+ 'commands-list': Type.Object({
905
+ schemaVersion: Version,
906
+ common: Type.Array(Str, { description: 'Ids of the common commands, most common first.' }),
907
+ groups: Type.Array(Type.Object({
908
+ id: Type.String({ description: "A task group such as 'accounts' or 'quota'; an open set." }),
909
+ title: Str,
910
+ commands: Type.Array(Type.Object({
911
+ id: Type.String({ description: "Stable, such as 'run' or 'handoff.enable'." }),
912
+ usage: Type.String({ description: 'The command line as `sideby --help` shows it.' }),
913
+ description: Str,
914
+ example: Type.Union([Str, Type.Null()]),
915
+ featureId: Type.Union([Str, Type.Null()], {
916
+ description: 'The `sideby commands <words>` result id of its place in the Panel, or null.',
917
+ }),
918
+ panel: Type.Union([Str, Type.Null()], {
919
+ description: 'Where it lives in the Panel, such as "Settings → General → Language", or null.',
920
+ }),
921
+ })),
922
+ })),
923
+ }, { title: 'sideby commands --json (no words): the Command List' }),
884
924
  'app-install': Type.Object({
885
925
  schemaVersion: Version,
886
926
  platform: AppPlatform,
@@ -1458,7 +1498,7 @@ export const OUTPUT_SCHEMAS = {
1458
1498
  'menubar-snapshot': Type.Object({
1459
1499
  schemaVersion: Version,
1460
1500
  title: Type.String({
1461
- description: 'The words next to the icon, such as `Codex 62%`, once the tightest tool reaches 60%; empty otherwise.',
1501
+ description: 'The words next to the icon, such as `Codex 62%`, once the tightest tool reaches its warning level (60% of a 5-hour window, 85% of a longer one); empty otherwise.',
1462
1502
  }),
1463
1503
  level: Type.Union(['ok', 'warn', 'fail', 'none'].map((k) => Type.Literal(k))),
1464
1504
  tooltip: Str,
@@ -4,157 +4,11 @@
4
4
  import { realpathSync } from 'node:fs';
5
5
  import { fileURLToPath, pathToFileURL } from 'node:url';
6
6
  const MIN_NODE = [22, 18];
7
- const HELP = `sideby — run every AI coding account side by side
8
-
9
- Usage:
10
- sideby ask [<text>] [--print] let your AI handle a sideby task
11
- sideby terminal [--set <id>|--custom <t>|--unset] choose your terminal
12
- sideby key <account> [--var <NAME>] enter an API key without echo
13
- sideby try <account> [--model <m>] try the Host with a short paid request
14
- sideby list accounts (same as \`sideby list\`)
15
- sideby list --all also list hidden families and accounts
16
- sideby run <account> [-- args] start the host CLI for one account
17
- sideby new <family> <name>|--next [--api] [--alias <short>]
18
- create an account (families: claude, codex, grok, pi);
19
- --next picks the next name and short command (cc008);
20
- --alias also adds a short command such as cc008
21
- sideby pin|unpin <account|short command> [--json]
22
- pin or unpin a Same Login (at most 3 per family)
23
- sideby hide|unhide <family|account> [--json]
24
- hide a family or an account from the Panel, menu bar and list
25
- sideby order [--json] show display order, with pinned and hidden accounts marked
26
- sideby order <family> <name>... set account order within a family
27
- sideby order --families <id>... set family order
28
- sideby order --reset restore default order, keeping pins and hidden ones
29
- sideby quota check <family> on|off turn quota fetching on or off
30
- sideby update --auto on|off set Auto Update without running an update
31
- sideby update --skill [--yes] update only the installed sideby skill to this version
32
- sideby commands <words> find where a page, setting or action lives in the Panel,
33
- and the command that does the same (read-only)
34
- sideby families [family] what each host's accounts share with the main account,
35
- where they live and how they sign in
36
- sideby alias add <short> <account> [-- args]
37
- add a short command, optionally with host arguments
38
- (sideby alias add pi-kimi pi:main -- --model kimi-coding/k3)
39
- sideby alias add <short> --pick <family> [--yes]
40
- add a pick command: each run starts the account with the
41
- most quota left (sideby alias add cc --pick claude)
42
- sideby alias rm <short> remove a short command
43
- sideby alias list list short commands and pick commands
44
- sideby login <account> sign in to an account
45
- sideby resume <family> [-- args] run the host; a session resumed by id (claude --resume <id>,
46
- codex resume <id>) starts in the account that holds it
47
- sideby next <family> [--dry-run] [--include-api] [--ignore-network] [--unattended] [-- args]
48
- recommend the account with the most quota left (claude, codex, grok)
49
- and start it; --dry-run only recommends
50
- sideby doctor [target] [--fix] [--force]
51
- check shared items and permissions; --fix repairs safe issues
52
- sideby quota [account|family] [--refresh]
53
- quota and 7-day token usage; --refresh asks every fetching family again now
54
- sideby quota setup claude [--yes] turn on Claude quota (shows the change first)
55
- sideby quota teardown claude undo it, restoring the original file
56
- sideby tune [account|family] estimate the cheapest auto-compact threshold per model
57
- from your last 7 days of sessions (read-only)
58
- sideby model <account> [<model>|default] [--effort <level>|default] [--yes]
59
- show or set the model and effort sideby starts this account with
60
- sideby remote-control [on|off|undo] [--yes]
61
- whether Claude sessions connect to claude.ai by themselves;
62
- off stops that for every account (shows the change first)
63
- sideby handoff status what Auto Handoff still needs on this machine
64
- sideby handoff rules every rule that decides when it hands over and to whom,
65
- and where each account's work would go now
66
- sideby handoff enable [--yes] turn it on (shows the config change first); --same-family,
67
- --order claude=codex001,cc002, --threshold n, --prepare-at n,
68
- --other-ai [--ai-order codex,grok], --api (billed per use)
69
- sideby handoff disable [--yes] turn it off, keeping the other settings
70
- sideby handoff ready [--brief <f>] inside a session sideby started with Auto Handoff: hand over to
71
- the next account when this turn ends (config \`handoff\`);
72
- --to <account> names it, also one this chain already used
73
- sideby handoff setup grok [--yes] add sideby's hook file so Grok can hand over at its limit
74
- sideby handoff teardown grok remove it
75
- sideby ui [--port n] [--no-open] open the local panel
76
- sideby ui --background same, without a terminal: keeps running after this command exits
77
- sideby ui --stop stop the background panel
78
- sideby desktop <account> open the desktop app (Claude Desktop, the Codex app) as this
79
- account, next to the others (macOS)
80
- sideby desktop grok-bot:<name> open a Grok Bot window, a new one for a new name (macOS)
81
- sideby sessions [<account>|<family>] which session each account runs now, needing you first
82
- sideby sessions copy <account|session-id> [--as reference|id|resume]
83
- copy one for another AI: a reference to its record (default),
84
- its id or its resume command
85
- sideby sessions open-run <account|session-id>
86
- open the run report of the dispatched task that session works for
87
- sideby history [<words>...] find any past session of any account, by project, AI, time
88
- or what was said (--project, --family, --account, --since,
89
- --tools also searches tool output)
90
- sideby history show <id> read one session; history projects lists the projects
91
- sideby history index [--clear] the local search index: how far it is built, or delete it
92
- sideby send <account|session> "<text>" [--image <path>]...
93
- tell another session something (a screenshot too): Claude
94
- sessions get it at once, others through a line you paste
95
- sideby messages [--to <account|session>]
96
- the messages you sent and whether each was delivered or read
97
- sideby messages inbound [accept|undo] [--yes]
98
- whether Claude sessions show messages from other sessions at once
99
- sideby edit <account> [--path] open the account's own settings file (settings.json,
100
- config.toml) in your editor
101
- sideby network [check] stop Claude and Codex when requests would leave from a country
102
- you did not allow (network on|off|allow <CC>... [--yes])
103
- sideby unattended [on|off] nobody is here: sessions sideby starts do not stop to ask; on takes
104
- --for 4h, --until 07:30 or --slot-end (schedule add|remove|preset weeknights,
105
- pending [done <id>|--all], defer "<text>"); run --unattended for one session
106
- sideby browser [--enable [--yes]] which Chrome browser user signed in to each account's website
107
- (read on this computer only; off until you enable it)
108
- sideby browser open <account> [--profile <name>]
109
- open claude.ai, chatgpt.com or grok.com in that browser user
110
- sideby browser set <account> <name> | --auto
111
- choose that browser user yourself, or let sideby find it again
112
- sideby app install [--url <url>] add a sideby app that opens the panel (macOS, Linux)
113
- sideby app uninstall remove that app
114
- sideby shell-init zsh|bash print shell functions, e.g. eval "$(sideby shell-init zsh)"
115
- sideby shell-init [zsh|bash] --write
116
- rewrite the config's shellInitFile with them
117
- sideby shell-init setup [zsh|bash] [--yes|--undo]
118
- make new terminals load your short commands: adds one line to
119
- ~/.zshrc (or ~/.bashrc), shown first; --undo takes it out
120
- sideby plugins list loaded plugins and load errors
121
- sideby plugins new <id> create a local Family Plugin skeleton
122
- sideby plugins check <id|path> check a plugin and show fixes
123
- sideby update [--yes] update sideby to the newest version (shows the command first)
124
- sideby autostart [on|off] [--yes] start the panel in the background at login (macOS, Linux, WSL;
125
- shows the file first)
126
- sideby menubar [on|off] [--yes] show quota in the macOS menu bar; click an account to start it
127
- sideby menubar hotkey [<keys>|off] show or change the shortcut that opens that menu (⌥X)
128
- sideby theme [list] the Panel's Themes; use <name> switches, use --undo goes back, use default clears
129
- sideby theme check|preview <name|file> contrast report, or one look in the Panel without switching
130
- sideby theme import <file> | export <name> | remove <name> your own Themes (JSON, colors only)
131
- sideby config get [<key>] every setting with its value and meaning, or one setting
132
- sideby config set <key> <value> [--yes]
133
- change any setting (sideby config set panel.theme dark)
134
- sideby config unset <key> [--yes] back to the default
135
- sideby local [on|off] [--yes] for sideby developers: switch the global sideby between the
136
- last local build (pnpm local) and the npm package
137
-
138
- Options:
139
- --json machine-readable output (list, new, next, alias, doctor, quota, tune, model, remote-control, handoff,
140
- families, commands, plugins, app, desktop, sessions, history, send, messages, edit, browser, update, local, ask,
141
- terminal, key, try, autostart, menubar, config, network, unattended)
142
- -h, --help show this help; \`sideby <command> --help\` for new, alias, login, doctor, families, commands, desktop, edit, browser,
143
- autostart, menubar, config, sessions, history, send, messages, network, unattended
144
- -v, --version show the version
145
-
146
- An <account> is <family>:<name> (claude:work) or just <name> when it is unique.
147
-
148
- For AI agents:
149
- Add --json and read the result; JSON Schemas ship in the package under schemas/.
150
- Install the skill: npx skills add Adonis0123/sideby -g
151
- Setup steps and the full contract: https://github.com/Adonis0123/sideby/blob/main/llms.txt
152
- Run everything else yourself, but hand the user these as one line each: \`sideby login <account>\`
153
- (browser sign-in), filling in proxy.env, and \`sideby run\` or \`sideby next\` (interactive sessions).
154
- Exit 10 means a change was shown: ask the user, then run it again with --yes.
155
-
156
- Updates: once a day sideby asks the npm registry for its newest version and says so after a command.
157
- Turn it off with NO_UPDATE_NOTIFIER=1 or config "update": { "check": false }; "auto": true installs by itself.`;
7
+ /** `sideby --help`, generated from the Command List (spec §3.38) so it never drifts from the Panel and `sideby commands`. */
8
+ async function generalHelp() {
9
+ const { cliHelp } = await import('../core/cli-commands.js');
10
+ return cliHelp();
11
+ }
158
12
  /** `sideby <command> --help` for the commands agents use to set up and repair accounts (spec §3.16). */
159
13
  const COMMAND_HELP = {
160
14
  ask: 'sideby ask [<text>] [--task free|fix|quota|account|host|plugin|terminal|handoff|theme|menubar|hotkey|network] [--account <ref>] [--terminal <id>] [--attach <file>]... [--print] [--json]\nsideby ask --run <id> [--state-dir <dir>]\nsideby ask --spec - [--print] --json\nsideby ask --choices --json\nOpen a task in your terminal. --spec reads a Task Spec (one JSON object, at most 1 MB) from stdin, as a Portal sends it; --choices lists the accounts and terminals a task can use. --attach adds an image (PNG, JPEG, GIF, WebP; up to 20 MB) or a video (MP4, MOV, WebM; up to 200 MB), at most 5. --print prints only the prompt. If opening fails, paste the command into a terminal.',
@@ -537,17 +391,23 @@ Examples:
537
391
  sideby browser set codex:main "Profile 7"
538
392
  Exit: 0 shown, changed, chosen or opened; 1 not macOS, Chrome not installed, no or several browser users to choose from, or
539
393
  Chrome did not open; 10 --enable/--disable without --yes; 2 malformed command line.`,
540
- commands: `sideby commands <words>... [--json]
394
+ commands: `sideby commands [--json]
395
+ sideby commands <words>... [--json]
396
+
397
+ With no words: every command, grouped by task (Accounts, Start and open, Quota and usage, ...), the common ones first,
398
+ each with one line on what it does and an example. The Panel shows the same list under Commands (or press ?).
541
399
 
542
- Find a feature of sideby by name, in English or Chinese: a page of the Panel, a setting or an action. Each result
543
- says where it lives in the Panel (Settings → General → Language) and the command that does the same, when there is
544
- one. The Panel's Search (Cmd/Ctrl+K) searches the same list. It finds features, not sessions: for those use
545
- \`sideby history <words>\`.
400
+ With words: find a feature of sideby by name, in English or Chinese: a page of the Panel, a setting or an action.
401
+ Each result says where it lives in the Panel (Settings → General → Language) and the command that does the same,
402
+ when there is one. The Panel's Search (Cmd/Ctrl+K) searches the same list. It finds features, not sessions: for those
403
+ use \`sideby history <words>\`.
546
404
 
547
405
  Examples:
406
+ sideby commands
407
+ sideby commands --json
548
408
  sideby commands language
549
409
  sideby commands 深色 --json
550
- Exit: 0, also when nothing matches; 2 no words given or malformed command line.`,
410
+ Exit: 0, also when nothing matches; 2 malformed command line.`,
551
411
  families: `sideby families [family] [--json]
552
412
 
553
413
  For each host (built in or from a plugin): where its accounts live, the variable that selects one, how to sign
@@ -756,7 +616,7 @@ export async function main(argv) {
756
616
  return 0;
757
617
  }
758
618
  if (first === '-h' || first === '--help' || first === 'help') {
759
- console.log((rest[0] !== undefined && first === 'help' && COMMAND_HELP[rest[0]]) || HELP);
619
+ console.log((rest[0] !== undefined && first === 'help' && COMMAND_HELP[rest[0]]) || (await generalHelp()));
760
620
  return 0;
761
621
  }
762
622
  const cmd = first === undefined || first.startsWith('--') ? 'list' : first;
@@ -800,7 +660,7 @@ export async function main(argv) {
800
660
  }
801
661
  }
802
662
  if (parsed.flags.has('help')) {
803
- console.log(COMMAND_HELP[cmd] ?? HELP);
663
+ console.log(COMMAND_HELP[cmd] ?? (await generalHelp()));
804
664
  return 0;
805
665
  }
806
666
  // parseArgs keeps the last value of an option; `ask --attach` may be given several times.
@@ -13,6 +13,7 @@ import { writeFileAtomic } from './fs-safe.js';
13
13
  import { planHandoff } from './handoff.js';
14
14
  import { resolvePaths } from './paths.js';
15
15
  import { runProbe, spawnProbe } from './probe.js';
16
+ import { takeoverLimits } from './quota-levels.js';
16
17
  import { askLauncher, askRunCommand, guessTerminal, installedTerminals, launcherProblem, openTerminal, TERMINALS, validateCustomTemplate, wslDistro, } from './terminal.js';
17
18
  export async function pickTaskAccount(rt, opts = {}) {
18
19
  const all = (await rt.accounts()).filter((a) => !opts.family || a.family === opts.family);
@@ -38,7 +39,11 @@ export async function pickTaskAccount(rt, opts = {}) {
38
39
  }
39
40
  if (!candidates.length)
40
41
  return { reason: 'none-signed-in' };
41
- const plan = planHandoff('', candidates, rt.readContext().now);
42
+ // As `sideby next`: past the Takeover Limits, the Account closest to room with no window used up (a Last Resort, §3.13).
43
+ const plan = planHandoff('', candidates, rt.readContext().now, {
44
+ limits: takeoverLimits(rt.handoffSettings().threshold),
45
+ lastResort: true,
46
+ });
42
47
  const account = all.find((a) => a.ref === plan.pick);
43
48
  return account ? { account } : { reason: 'all-full' };
44
49
  }
@@ -0,0 +1,56 @@
1
+ import { type Words } from './search-catalog.ts';
2
+ export type CommandGroupId = 'accounts' | 'start' | 'shortcuts' | 'quota' | 'handoff' | 'sessions' | 'health' | 'panel' | 'settings' | 'help';
3
+ export interface CommandGroup {
4
+ id: CommandGroupId;
5
+ title: Words;
6
+ }
7
+ export interface CliCommand {
8
+ /** Stable: `sideby commands --json` and the Panel name it. */
9
+ id: string;
10
+ group: CommandGroupId;
11
+ /** The command line as `sideby --help` shows it. */
12
+ usage: string;
13
+ /** What `sideby --help` prints next to it, in English; it may name more options than `summary`. */
14
+ help: string;
15
+ /** One line for the Command List. */
16
+ summary: Words;
17
+ /** A line that runs as it is, with the demo names (`claude:work`, `cc008`). */
18
+ example?: string;
19
+ /** Its place in the "Common" group, 1 first. */
20
+ common?: number;
21
+ /** The Search Catalog id of its place in the Panel, for "Open in Panel". */
22
+ feature?: string;
23
+ }
24
+ /** Task groups, in the order `sideby --help`, `sideby commands` and the Panel show them. */
25
+ export declare const COMMAND_GROUPS: readonly CommandGroup[];
26
+ export declare const CLI_COMMANDS: readonly CliCommand[];
27
+ /** The common commands, in the order the "Common" group shows them. */
28
+ export declare function commonCommands(list?: readonly CliCommand[]): CliCommand[];
29
+ /** The commands `main.ts` dispatches for a usage line: `run`; `pin` and `unpin` for `pin|unpin`; `list` for `sideby`. */
30
+ export declare function commandWords(usage: string): string[];
31
+ /**
32
+ * Commands matching `query`, in catalog order. Every word of the query must appear in the usage, the example, the
33
+ * description in either language or the group's title; an empty query matches everything. Runs in the Panel too.
34
+ */
35
+ export declare function filterCommands<T extends {
36
+ usage: string;
37
+ group: string;
38
+ summary: {
39
+ en: string;
40
+ zh: string;
41
+ };
42
+ example?: string;
43
+ }>(query: string, list: readonly T[], groups: readonly {
44
+ id: string;
45
+ title: {
46
+ en: string;
47
+ zh: string;
48
+ };
49
+ }[]): readonly T[];
50
+ /** `sideby --help`: the commands grouped by task, from the Command List, then the options and the notes. */
51
+ export declare function cliHelp(list?: readonly CliCommand[]): string;
52
+ /** What the Panel embeds: everything but the `--help` text, which only the terminal shows. */
53
+ export declare function commandListForPage(): {
54
+ groups: readonly CommandGroup[];
55
+ commands: Omit<CliCommand, 'help'>[];
56
+ };