sideby 0.42.2 → 0.44.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 (66) hide show
  1. package/ai-tasks.json +10 -0
  2. package/dist/build.json +1 -1
  3. package/dist/src/cli/commands.js +54 -13
  4. package/dist/src/cli/json-schemas.js +65 -1
  5. package/dist/src/cli/main.js +11 -4
  6. package/dist/src/core/ask.d.ts +8 -14
  7. package/dist/src/core/ask.js +66 -30
  8. package/dist/src/core/egress.d.ts +5 -0
  9. package/dist/src/core/egress.js +32 -2
  10. package/dist/src/core/file-memo.d.ts +2 -0
  11. package/dist/src/core/file-memo.js +20 -0
  12. package/dist/src/core/handoff-run.js +41 -8
  13. package/dist/src/core/handoff-select.d.ts +5 -0
  14. package/dist/src/core/handoff-select.js +1 -1
  15. package/dist/src/core/handoff.d.ts +78 -1
  16. package/dist/src/core/handoff.js +100 -9
  17. package/dist/src/core/history-index.d.ts +4 -0
  18. package/dist/src/core/history-index.js +1 -1
  19. package/dist/src/core/live-sessions.d.ts +5 -0
  20. package/dist/src/core/live-sessions.js +12 -1
  21. package/dist/src/core/memo-store.js +32 -8
  22. package/dist/src/core/network.d.ts +37 -0
  23. package/dist/src/core/network.js +65 -1
  24. package/dist/src/core/pick-commands.d.ts +7 -1
  25. package/dist/src/core/pick-commands.js +15 -3
  26. package/dist/src/core/pick-records.d.ts +26 -0
  27. package/dist/src/core/pick-records.js +81 -0
  28. package/dist/src/families/agy/history.d.ts +2 -0
  29. package/dist/src/families/agy/history.js +118 -0
  30. package/dist/src/families/agy/index.js +5 -0
  31. package/dist/src/families/agy/quota.d.ts +5 -1
  32. package/dist/src/families/agy/quota.js +111 -10
  33. package/dist/src/families/history.js +2 -1
  34. package/dist/src/families/quota-watch.d.ts +12 -0
  35. package/dist/src/families/quota-watch.js +24 -0
  36. package/dist/src/network/hook.js +4 -4
  37. package/dist/src/network/page-script.d.ts +40 -0
  38. package/dist/src/network/page-script.js +270 -0
  39. package/dist/src/network/page.d.ts +11 -0
  40. package/dist/src/network/page.js +189 -0
  41. package/dist/src/network/panel.d.ts +5 -0
  42. package/dist/src/network/panel.js +7 -0
  43. package/dist/src/panel/changes.d.ts +57 -0
  44. package/dist/src/panel/changes.js +178 -0
  45. package/dist/src/panel/handler.d.ts +59 -1
  46. package/dist/src/panel/handler.js +374 -99
  47. package/dist/src/panel/i18n.d.ts +49 -0
  48. package/dist/src/panel/i18n.js +100 -2
  49. package/dist/src/panel/page-logic.d.ts +37 -3
  50. package/dist/src/panel/page-logic.js +106 -12
  51. package/dist/src/panel/page-script.js +194 -27
  52. package/dist/src/panel/page-styles.js +18 -8
  53. package/dist/src/panel/page.js +3 -1
  54. package/dist/src/runtime.d.ts +55 -5
  55. package/dist/src/runtime.js +105 -12
  56. package/dist/src/types.d.ts +3 -2
  57. package/package.json +1 -1
  58. package/schemas/network-diagnose.json +196 -0
  59. package/schemas/next.json +67 -2
  60. package/skills/sideby/SKILL.md +3 -2
  61. package/skills/sideby/references/accounts.md +1 -1
  62. package/skills/sideby/references/ai-tasks.md +1 -1
  63. package/skills/sideby/references/handoff.md +6 -2
  64. package/skills/sideby/references/network.md +6 -1
  65. package/skills/sideby/references/quota.md +1 -1
  66. package/skills/sideby/references/sessions.md +1 -1
@@ -8,12 +8,12 @@ import { type DesktopDeps } from './core/desktop-app.ts';
8
8
  import { type DoctorReport } from './core/doctor.ts';
9
9
  import type { TraceFetcher } from './core/egress.ts';
10
10
  import { UserError } from './core/errors.ts';
11
- import { type HandoffPlan } from './core/handoff.ts';
11
+ import { type HandoffCandidate, type HandoffPlan, type PickRecord } from './core/handoff.ts';
12
12
  import { type HandoffDecision, type UsedAccount } from './core/handoff-select.ts';
13
13
  import { type DoctorHistory } from './core/last-doctor.ts';
14
14
  import { type HostLaunch, type PreparedLaunch } from './core/launch.ts';
15
15
  import { type LimitResetPlan, type LimitResetResult } from './core/limit-reset.ts';
16
- import { type NetworkOverview } from './core/network.ts';
16
+ import { type ListenerProbe, type NetworkDiagnosis, type NetworkOverview } from './core/network.ts';
17
17
  import { type Paths } from './core/paths.ts';
18
18
  import { type PickChoice } from './core/pick-commands.ts';
19
19
  import { type ProgressView } from './core/progress.ts';
@@ -267,12 +267,29 @@ export interface Runtime {
267
267
  }): Promise<AliasEditResult>;
268
268
  /** The Family a Pick Command picks in, or undefined when `name` is not one. */
269
269
  pickCommandFamily(name: string): string | undefined;
270
- /** The Account the Pick Command `name` starts now, or why it starts nothing (ADR-0035). */
271
- pickChoice(name: string): Promise<{
270
+ /**
271
+ * The Account the Pick Command `name` starts now, or why it starts nothing (ADR-0035). With `record` the caller
272
+ * starts it, so a Pick Record is written for it (ADR-0083) and given to `recorded`; without, it is a preview.
273
+ */
274
+ pickChoice(name: string, opts?: {
275
+ record?: boolean;
276
+ recorded?: (rec: PickRecord) => void;
277
+ }): Promise<{
272
278
  name: string;
273
279
  family: string;
274
280
  choice: PickChoice;
275
281
  }>;
282
+ /**
283
+ * The Account a start in `family` makes now, by the rules of a Pick Command of that Family (`pickChoice`), whether
284
+ * or not it has one: the Panel's "Best to use now" card (spec §3.45). `record` as in `pickChoice`.
285
+ */
286
+ familyPick(family: string, opts?: {
287
+ record?: boolean;
288
+ recorded?: (rec: PickRecord) => void;
289
+ }): Promise<{
290
+ family: string;
291
+ choice: PickChoice;
292
+ }>;
276
293
  /**
277
294
  * The Pick Command to offer for a Family: the existing one, else a free name following its Aliases (or cc, cx, gk),
278
295
  * with the command on PATH it would hide, or `name: null` when no such name is free (the user types one); null when
@@ -305,6 +322,8 @@ export interface Runtime {
305
322
  networkStatus(opts?: {
306
323
  check?: boolean;
307
324
  }): Promise<NetworkOverview>;
325
+ /** Offline route, TCP listener and cached Guard diagnosis; never sends a trace. */
326
+ networkDiagnose(): Promise<NetworkDiagnosis>;
308
327
  /**
309
328
  * Unattended Mode (spec §3.37): whether it is on and why, until when, the Schedule, the open Pending Decisions and
310
329
  * which Families' sessions it covers. Read fresh on every call.
@@ -515,10 +534,15 @@ export interface Runtime {
515
534
  * falls back to the least used Account under 100% (`tight`). Throws a UserError with code `no-quota-source`
516
535
  * when the Family cannot tell, `no-accounts` when it has none. `fetch` is as for `quota`; `never` reads only the kept
517
536
  * answers (the menu bar's cache-only snapshot, spec §3.31).
537
+ * `picks` counts Live Sessions and Pick Records into the ranking (ADR-0083): `read` for a preview; a function for a
538
+ * start, naming the Account the caller will start (or null), for which a Pick Record is written under the pick lock.
518
539
  */
519
540
  handoff(familyId: string, opts?: {
520
541
  includeApi?: boolean;
521
542
  fetch?: QuotaFetchMode;
543
+ picks?: 'read' | ((plan: HandoffPlan) => string | null);
544
+ /** Gets the Pick Record written, the token `cancelPick` takes back when the start does not happen. */
545
+ recorded?: (rec: PickRecord) => void;
522
546
  }): Promise<HandoffPlan>;
523
547
  /** The config `handoff` settings with every default filled in (spec §3.17). */
524
548
  handoffSettings(): HandoffSettings;
@@ -527,13 +551,31 @@ export interface Runtime {
527
551
  * candidate; `used` lists the chain's Accounts so far, as refs or as its hops (an Account whose hop recorded a window
528
552
  * that has reset since may be picked again, ADR-0060). `ahead` decides early what happens once the origin's fullest
529
553
  * window reaches the threshold, as plan.json and the Panel need. `to` names the only candidate (`handoff ready --to`);
530
- * `manual` (`handoff ready`) never waits for a reset.
554
+ * `manual` (`handoff ready`) never waits for a reset. `picks` counts Live Sessions and Pick Records into the ranking
555
+ * (ADR-0083); `record` also writes a Pick Record for a pick, as the real handoff that starts it does, and gives it to
556
+ * `recorded`.
531
557
  */
532
558
  handoffDecision(origin: Account, used: readonly UsedAccount[], opts?: {
533
559
  ahead?: boolean;
534
560
  to?: string;
535
561
  manual?: boolean;
562
+ picks?: 'read' | 'record';
563
+ recorded?: (rec: PickRecord) => void;
536
564
  }): Promise<HandoffDecision>;
565
+ /**
566
+ * One pick spread by Room per Session (ADR-0083): counts the Live Sessions of every Account and reads the Pick
567
+ * Records, and gives both to `rank`, which says which candidates it ranked. With `record`, `started` names the
568
+ * Account the caller will start and its Pick Record (its login's load now) is written, all under one lock; records
569
+ * that arrived or expired are dropped then. Never from a hook entry.
570
+ */
571
+ pickLoad<T>(record: boolean, rank: (live: ReadonlyMap<string, number>, picks: readonly PickRecord[]) => {
572
+ result: T;
573
+ candidates: readonly HandoffCandidate[];
574
+ }, started: (result: T) => string | null,
575
+ /** Gets the record written, if any: the token for `cancelPick`. */
576
+ recorded?: (rec: PickRecord) => void): Promise<T>;
577
+ /** Takes back exactly this Pick Record, when the start it was written for did not happen after all. */
578
+ cancelPick(rec: PickRecord): Promise<void>;
537
579
  readContext(): ReadContext;
538
580
  }
539
581
  export declare class UnknownFamilyError extends UserError {
@@ -565,6 +607,7 @@ export declare function createRuntime(opts?: {
565
607
  network?: {
566
608
  fetcher?: TraceFetcher;
567
609
  print?: string;
610
+ probe?: ListenerProbe;
568
611
  };
569
612
  /**
570
613
  * Internal, for tests: how long a Limit Reset request may take before it counts as unanswered (spec §3.40), so a
@@ -589,4 +632,11 @@ export declare function createRuntime(opts?: {
589
632
  liveRuns?: (account: Account) => Promise<LiveRuns>;
590
633
  trash?: Trash;
591
634
  };
635
+ /**
636
+ * Internal, for tests: the Live Sessions of each Account a pick counts (ADR-0083). Omitted, `listLiveSessions`
637
+ * with `ps`. Not part of the plugin or Portal contract.
638
+ */
639
+ picks?: {
640
+ liveSessions?: () => Promise<ReadonlyMap<string, number>>;
641
+ };
592
642
  }): Promise<Runtime>;
@@ -9,7 +9,7 @@ import { bindDesktopDeps, checkAppData } from './core/desktop-app.js';
9
9
  import { applyFixes, runDoctor } from './core/doctor.js';
10
10
  import { hostSettingsFile } from './core/edit-settings.js';
11
11
  import { UserError } from './core/errors.js';
12
- import { planHandoff } from './core/handoff.js';
12
+ import { activePicks, loginLoad, planHandoff, } from './core/handoff.js';
13
13
  import { handoffFindings, tapState } from './core/handoff-doctor.js';
14
14
  import { selectNext, } from './core/handoff-select.js';
15
15
  import { identityOf } from './core/identity.js';
@@ -19,7 +19,7 @@ import { accountEnv, beforeDashes, brokenOnPath, launchCommand, prepareLaunch, w
19
19
  import { confirmedSpends, isOutcome, LimitResetError, limitResetFile, loginUnchanged, newLimitResetRecord, outcomeMessage, planExpired, pruneLimitResetRecords, readLimitResetRecord, sameAccounts, scanLimitResetRecords, spent, takeLimitResetLock, unreadableRecordsMessage, unresolvedFor, writeLimitResetRecord, } from './core/limit-reset.js';
20
20
  import { loginMarkFile, readLoginMark, writeLoginMark } from './core/login-mark.js';
21
21
  import { memoStore } from './core/memo-store.js';
22
- import { codexNetworkTrustLine, guardLaunch, guardOn, ipChangedLine, networkHookPart, networkOverview, networkSettingsLine, } from './core/network.js';
22
+ import { codexNetworkTrustLine, guardLaunch, guardOn, ipChangedLine, networkDiagnose, networkHookPart, networkOverview, networkSettingsLine, } from './core/network.js';
23
23
  import { resolvePaths } from './core/paths.js';
24
24
  import { choosePick, suggestPickName } from './core/pick-commands.js';
25
25
  import { PROGRESS_FAMILIES, progressHookPart, progressSettingsLine, progressView, setProgress, } from './core/progress.js';
@@ -607,7 +607,9 @@ export async function createRuntime(opts = {}) {
607
607
  const f = families.get(a.family);
608
608
  if (!f?.readLoginEvents || a.kind === 'api')
609
609
  return undefined;
610
- if ((login ?? (await loginOf(a))) !== 'logged-in')
610
+ // `unknown` too: a Host whose sign-in sideby cannot see (agy, ADR-0082) still says when it needs a new one.
611
+ const state = login ?? (await loginOf(a));
612
+ if (state !== 'logged-in' && state !== 'unknown')
611
613
  return undefined;
612
614
  const ctx = readContext();
613
615
  await memos.ready();
@@ -718,6 +720,22 @@ export async function createRuntime(opts = {}) {
718
720
  ...(files.length ? { shellInitFiles: files } : {}),
719
721
  };
720
722
  };
723
+ // The Live Sessions of each Account, for spreading picks (ADR-0083). A listing that fails counts none: the pick
724
+ // still happens, ranked as before.
725
+ const liveSessionCounts = async () => {
726
+ if (opts.picks?.liveSessions)
727
+ return opts.picks.liveSessions();
728
+ try {
729
+ const { listLiveSessions } = await import('./core/live-sessions.js');
730
+ const n = new Map();
731
+ for (const s of (await listLiveSessions(rt, { deadlineMs: 3_000 })).sessions)
732
+ n.set(s.account, (n.get(s.account) ?? 0) + 1);
733
+ return n;
734
+ }
735
+ catch {
736
+ return new Map();
737
+ }
738
+ };
721
739
  const rt = {
722
740
  paths,
723
741
  config,
@@ -1038,19 +1056,44 @@ export async function createRuntime(opts = {}) {
1038
1056
  ? config.pickCommands[name]
1039
1057
  : undefined;
1040
1058
  },
1041
- async pickChoice(name) {
1059
+ async pickChoice(name, po = {}) {
1042
1060
  const family = rt.pickCommandFamily(name);
1043
1061
  if (family === undefined)
1044
1062
  throw new UserError(`no pick command "${name}"; add one with \`sideby alias add ${name} --pick <family>\``);
1063
+ return { name, ...(await rt.familyPick(family, po)) };
1064
+ },
1065
+ async familyPick(family, po = {}) {
1045
1066
  const f = familyOf(family);
1046
1067
  // API Accounts are never picked, also not as the fallback (ADR-0035).
1047
1068
  const subs = (await accounts()).filter((a) => a.family === f.id && a.kind !== 'api');
1048
1069
  if (!subs.length)
1049
1070
  throw new UserError(`no ${f.title} subscription accounts yet; create one with \`sideby new ${f.id} --next\``, { code: 'no-accounts' });
1050
1071
  const main = subs.find((a) => a.isMain)?.ref ?? null;
1051
- if (!f.readQuota && !f.fetchQuota)
1052
- return { name, family, choice: { ref: main ?? subs[0].ref, reason: 'no-quota-data' } };
1053
- return { name, family, choice: choosePick(await rt.handoff(f.id), main) };
1072
+ if (!f.readQuota && !f.fetchQuota) {
1073
+ const ref = main ?? subs[0].ref;
1074
+ // Nothing to rank, but a start still counts for the next pick (ADR-0083).
1075
+ if (po.record) {
1076
+ const groups = await groupsOf(subs);
1077
+ await rt.pickLoad(true, () => ({
1078
+ result: ref,
1079
+ candidates: subs.map((a) => ({
1080
+ ref: a.ref,
1081
+ name: a.name,
1082
+ isMain: a.isMain,
1083
+ kind: a.kind,
1084
+ login: 'unknown',
1085
+ quota: { status: 'unavailable', reason: 'no-source' },
1086
+ ...(groups.get(a.ref) ? { sameLogin: groups.get(a.ref) } : {}),
1087
+ })),
1088
+ }), (r) => r, po.recorded);
1089
+ }
1090
+ return { family, choice: { ref, reason: 'no-quota-data' } };
1091
+ }
1092
+ const plan = await rt.handoff(f.id, {
1093
+ picks: po.record ? (p) => choosePick(p, main).ref : 'read',
1094
+ ...(po.recorded ? { recorded: po.recorded } : {}),
1095
+ });
1096
+ return { family, choice: choosePick(plan, main) };
1054
1097
  },
1055
1098
  async pickSuggestion(familyId, given) {
1056
1099
  const f = families.get(familyId);
@@ -1173,6 +1216,17 @@ export async function createRuntime(opts = {}) {
1173
1216
  now,
1174
1217
  });
1175
1218
  },
1219
+ async networkDiagnose() {
1220
+ return networkDiagnose({
1221
+ accounts: await accounts(),
1222
+ config,
1223
+ stateDir: paths.stateDir,
1224
+ env,
1225
+ envFor: async (a) => accountEnv(familyOf(a.family), a, env),
1226
+ ...(opts.network?.probe ? { probe: opts.network.probe } : {}),
1227
+ now,
1228
+ });
1229
+ },
1176
1230
  async launchCommand(ref, userArgs, command) {
1177
1231
  const inputs = launchInputs(ref, await accounts(), userArgs, command);
1178
1232
  return { account: inputs.account, family: inputs.family, ...launchCommand(inputs) };
@@ -1781,12 +1835,44 @@ export async function createRuntime(opts = {}) {
1781
1835
  // The Takeover Limits follow the user's Handoff Threshold, so `sideby next` and Auto Handoff agree on "full".
1782
1836
  // A start the user asks for may still go past them (a Last Resort, spec §3.13); Auto Handoff never does.
1783
1837
  const limits = takeoverLimits(handoffSettings(config).threshold);
1784
- return planHandoff(f.id, candidates, readContext().now, {
1785
- ...o,
1838
+ const { picks: mode, recorded, ...rest } = o;
1839
+ const plan = (list, picks) => planHandoff(f.id, list, readContext().now, {
1840
+ ...rest,
1786
1841
  limits,
1787
1842
  lastResort: true,
1788
1843
  ...(from ? { from } : {}),
1844
+ ...(picks ? { picks } : {}),
1789
1845
  });
1846
+ if (!mode)
1847
+ return plan(candidates);
1848
+ return rt.pickLoad(typeof mode === 'function', (live, picks) => {
1849
+ const counted = candidates.map((c) => ({ ...c, liveSessions: live.get(c.ref) ?? 0 }));
1850
+ return { result: plan(counted, picks), candidates: counted };
1851
+ }, (p) => (typeof mode === 'function' ? mode(p) : null), recorded);
1852
+ },
1853
+ async pickLoad(record, rank, started, recorded) {
1854
+ const { withPickRecords } = await import('./core/pick-records.js');
1855
+ let seen;
1856
+ return withPickRecords(paths.stateDir, now, record, async (picks) => {
1857
+ const live = await liveSessionCounts();
1858
+ const r = rank(live, picks);
1859
+ seen = { live, candidates: r.candidates };
1860
+ return r.result;
1861
+ }, (result, picks, at) => {
1862
+ const ref = started(result);
1863
+ if (!ref || !seen)
1864
+ return null;
1865
+ // Its login's load at the pick, Pick Records included; records that arrived or expired are dropped.
1866
+ return {
1867
+ ref,
1868
+ liveAtPick: loginLoad(seen.candidates, picks, at, seen.live).get(ref) ?? seen.live.get(ref) ?? 0,
1869
+ keep: activePicks(picks, seen.candidates, at, seen.live),
1870
+ };
1871
+ }, recorded);
1872
+ },
1873
+ async cancelPick(rec) {
1874
+ const { dropPickRecord } = await import('./core/pick-records.js');
1875
+ await dropPickRecord(paths.stateDir, rec).catch(() => { });
1790
1876
  },
1791
1877
  handoffSettings: () => handoffSettings(config),
1792
1878
  async handoffDecision(origin, used, opts = {}) {
@@ -1846,9 +1932,9 @@ export async function createRuntime(opts = {}) {
1846
1932
  catch {
1847
1933
  // cannot tell: do not wait
1848
1934
  }
1849
- return selectNext({
1850
- origin: self,
1851
- candidates,
1935
+ const decide = (list, picks) => selectNext({
1936
+ origin: list.find((c) => c.ref === origin.ref),
1937
+ candidates: list,
1852
1938
  settings: handoffSettings(config),
1853
1939
  aliases: aliasRefs(config.aliases),
1854
1940
  used,
@@ -1856,7 +1942,14 @@ export async function createRuntime(opts = {}) {
1856
1942
  ...(opts.ahead ? { ahead: true } : {}),
1857
1943
  ...(opts.to !== undefined ? { to: opts.to } : {}),
1858
1944
  ...(opts.manual ? { manual: true } : {}),
1945
+ ...(picks ? { picks } : {}),
1859
1946
  });
1947
+ if (!opts.picks)
1948
+ return decide(candidates);
1949
+ return rt.pickLoad(opts.picks === 'record', (live, picks) => {
1950
+ const counted = candidates.map((c) => ({ ...c, liveSessions: live.get(c.ref) ?? 0 }));
1951
+ return { result: decide(counted, picks), candidates: counted };
1952
+ }, (d) => (d.kind === 'pick' ? d.ref : null), opts.recorded);
1860
1953
  },
1861
1954
  readContext,
1862
1955
  };
@@ -271,8 +271,9 @@ export interface FamilyDef {
271
271
  /**
272
272
  * When the Host last said this Account's login expired, and when it last showed it working, from the Host's own
273
273
  * records only (ADR-0071): never a token, the Keychain or an expiry field of a credential file. Called only for a
274
- * signed-in Subscription Account; an error counts as nothing known. Without it the Family's logins never show as
275
- * expired.
274
+ * Subscription Account whose login state is `logged-in` or `unknown`; an error counts as nothing known. Without it
275
+ * the Family's logins never show as expired; a Family with no such records returns `{}`, and then only its
276
+ * `fetchQuota` answers (`loginExpired`) tell.
276
277
  */
277
278
  readLoginEvents?(account: Account, ctx: ReadContext): Promise<LoginEvents>;
278
279
  model?(account: Account): Promise<string | undefined>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sideby",
3
- "version": "0.42.2",
3
+ "version": "0.44.0",
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)",
@@ -0,0 +1,196 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "sideby/network-diagnose.json",
4
+ "type": "object",
5
+ "required": [
6
+ "schemaVersion",
7
+ "checkedAt",
8
+ "targets"
9
+ ],
10
+ "properties": {
11
+ "schemaVersion": {
12
+ "type": "number",
13
+ "const": 1
14
+ },
15
+ "checkedAt": {
16
+ "type": "string",
17
+ "description": "When this offline diagnosis ran (ISO), not the Guard cache time."
18
+ },
19
+ "targets": {
20
+ "type": "array",
21
+ "items": {
22
+ "type": "object",
23
+ "required": [
24
+ "url",
25
+ "proxy",
26
+ "guardSupport",
27
+ "listener",
28
+ "guard"
29
+ ],
30
+ "properties": {
31
+ "url": {
32
+ "type": "string",
33
+ "description": "The Guard trace address whose cached result is shown; it is not requested."
34
+ },
35
+ "proxy": {
36
+ "type": "string",
37
+ "description": "Selected proxy reduced to scheme, hostname and port, or direct/invalid."
38
+ },
39
+ "guardSupport": {
40
+ "anyOf": [
41
+ {
42
+ "type": "string",
43
+ "const": "direct"
44
+ },
45
+ {
46
+ "type": "string",
47
+ "const": "http-connect"
48
+ },
49
+ {
50
+ "type": "string",
51
+ "const": "unsupported"
52
+ },
53
+ {
54
+ "type": "string",
55
+ "const": "invalid"
56
+ }
57
+ ],
58
+ "description": "Guard supports direct and HTTP CONNECT; SOCKS/HTTPS proxies are unsupported."
59
+ },
60
+ "listener": {
61
+ "anyOf": [
62
+ {
63
+ "type": "null"
64
+ },
65
+ {
66
+ "type": "object",
67
+ "required": [
68
+ "host",
69
+ "port",
70
+ "reachable"
71
+ ],
72
+ "properties": {
73
+ "host": {
74
+ "type": "string"
75
+ },
76
+ "port": {
77
+ "type": "integer"
78
+ },
79
+ "reachable": {
80
+ "type": "boolean",
81
+ "description": "TCP connect only; not proof that the proxy protocol works."
82
+ },
83
+ "error": {
84
+ "type": "string"
85
+ }
86
+ }
87
+ }
88
+ ],
89
+ "description": "Local loopback TCP listener only; null for direct, remote or invalid proxies, and non-HTTP proxies without an explicit port."
90
+ },
91
+ "guard": {
92
+ "type": "object",
93
+ "required": [
94
+ "status"
95
+ ],
96
+ "properties": {
97
+ "status": {
98
+ "anyOf": [
99
+ {
100
+ "type": "string",
101
+ "const": "ok"
102
+ },
103
+ {
104
+ "type": "string",
105
+ "const": "blocked"
106
+ },
107
+ {
108
+ "type": "string",
109
+ "const": "unknown"
110
+ },
111
+ {
112
+ "type": "string",
113
+ "const": "not-checked"
114
+ }
115
+ ]
116
+ },
117
+ "loc": {
118
+ "type": "string"
119
+ },
120
+ "checkedAt": {
121
+ "type": "string",
122
+ "description": "When the cached Guard check ran (ISO)."
123
+ },
124
+ "error": {
125
+ "type": "string"
126
+ }
127
+ }
128
+ }
129
+ }
130
+ }
131
+ },
132
+ "_notice": {
133
+ "type": "object",
134
+ "properties": {
135
+ "update": {
136
+ "type": "object",
137
+ "required": [
138
+ "current",
139
+ "latest",
140
+ "command",
141
+ "message"
142
+ ],
143
+ "properties": {
144
+ "current": {
145
+ "type": "string"
146
+ },
147
+ "latest": {
148
+ "type": "string"
149
+ },
150
+ "command": {
151
+ "type": "string",
152
+ "description": "Run it after the user agrees: it shows the plan and exits 10; then --yes."
153
+ },
154
+ "message": {
155
+ "type": "string"
156
+ }
157
+ }
158
+ },
159
+ "skill": {
160
+ "type": "object",
161
+ "required": [
162
+ "installed",
163
+ "current",
164
+ "command",
165
+ "message"
166
+ ],
167
+ "properties": {
168
+ "installed": {
169
+ "anyOf": [
170
+ {
171
+ "type": "string"
172
+ },
173
+ {
174
+ "type": "null"
175
+ }
176
+ ],
177
+ "description": "The skill's version; null when it has none."
178
+ },
179
+ "current": {
180
+ "type": "string"
181
+ },
182
+ "command": {
183
+ "type": "string",
184
+ "description": "`sideby update`, which updates the skill with sideby: run it after the user agrees; it shows the plan and exits 10, then --yes."
185
+ },
186
+ "message": {
187
+ "type": "string"
188
+ }
189
+ }
190
+ }
191
+ },
192
+ "description": "Not the answer to the task: mention it briefly afterwards and offer to update."
193
+ }
194
+ },
195
+ "title": "sideby network diagnose --json"
196
+ }
package/schemas/next.json CHANGED
@@ -41,7 +41,8 @@
41
41
  "kind",
42
42
  "state",
43
43
  "pressure",
44
- "limitUse"
44
+ "limitUse",
45
+ "liveSessions"
45
46
  ],
46
47
  "properties": {
47
48
  "ref": {
@@ -104,7 +105,33 @@
104
105
  "type": "null"
105
106
  }
106
107
  ],
107
- "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."
108
+ "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 the room it leaves per running session, (100 - limitUse) / (liveSessions + 1), highest first; a Last Resort by it, lowest first."
109
+ },
110
+ "liveSessions": {
111
+ "type": "number",
112
+ "description": "The Live Sessions of the account's Same Login group, plus Pick Records: starts sideby made in the last 2 minutes that have not shown up as a Live Session yet (ADR-0083)."
113
+ },
114
+ "expiring": {
115
+ "type": "object",
116
+ "required": [
117
+ "label",
118
+ "usedPercent",
119
+ "resetsAt"
120
+ ],
121
+ "properties": {
122
+ "label": {
123
+ "type": "string",
124
+ "description": "Such as `7d`."
125
+ },
126
+ "usedPercent": {
127
+ "type": "number",
128
+ "description": "Rounded."
129
+ },
130
+ "resetsAt": {
131
+ "type": "string"
132
+ }
133
+ },
134
+ "description": "For ready: its counted weekly (or longer) window that resets within 24 hours; such an account ranks before every other ready one, since that room is lost at the reset (ADR-0083)."
108
135
  },
109
136
  "window": {
110
137
  "type": "object",
@@ -129,6 +156,31 @@
129
156
  },
130
157
  "description": "The window closest to its own Takeover Limit; absent when none is open."
131
158
  },
159
+ "windows": {
160
+ "type": "array",
161
+ "items": {
162
+ "type": "object",
163
+ "required": [
164
+ "label",
165
+ "usedPercent",
166
+ "resetsAt"
167
+ ],
168
+ "properties": {
169
+ "label": {
170
+ "type": "string",
171
+ "description": "Such as `5h` or `7d`."
172
+ },
173
+ "usedPercent": {
174
+ "type": "number",
175
+ "description": "Rounded; what is left is 100 minus it."
176
+ },
177
+ "resetsAt": {
178
+ "type": "string"
179
+ }
180
+ }
181
+ },
182
+ "description": "Every counted window (no model name) that has not reset yet, so a caller can show what the pick has left; absent when none is open."
183
+ },
132
184
  "resetsAt": {
133
185
  "type": "string",
134
186
  "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."
@@ -205,6 +257,19 @@
205
257
  },
206
258
  "description": "Set when nothing can be picked and some accounts are full (every one has a window used up): the first to come back."
207
259
  },
260
+ "reason": {
261
+ "anyOf": [
262
+ {
263
+ "type": "string",
264
+ "const": "expiring"
265
+ },
266
+ {
267
+ "type": "string",
268
+ "const": "room"
269
+ }
270
+ ],
271
+ "description": "Why a ready pick goes first (ADR-0083): expiring, its weekly room resets within 24 hours; room, it has the most room per running session."
272
+ },
208
273
  "_notice": {
209
274
  "type": "object",
210
275
  "properties": {
@@ -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.42.2"
5
+ version: "0.44.0"
6
6
  requires:
7
7
  bins: [sideby, node]
8
8
  cliHelp: sideby --help
@@ -63,7 +63,7 @@ Account refs are `<family>:<name>`; a bare `<name>` works only when it is unique
63
63
  | Turn Auto Update on or off | `sideby update --auto on|off --json` | `references/update.md` |
64
64
  | Switch between a local build of sideby and the release ("切换到正式版", "切回 dev 版本") | `sideby local --json`, `sideby local on|off --json` (exits 10 first) | `references/update.md` |
65
65
  | Repair drift or permissions | `sideby doctor [ref] --json`, then `--fix` after they agree | `references/diagnose.md` |
66
- | Keep working because an account hit its limit | `sideby next <family> --json` | `references/handoff.md` |
66
+ | Keep working because an account hit its limit, or which account to use now ("现在该用哪个账号") | `sideby next <family> --json` | `references/handoff.md` |
67
67
  | Turn on Auto Handoff ("自动接力", "自动交接", "hand over when quota runs low"), see what it still needs, hand this session over now, or pick an account with room for a subtask | `sideby handoff status --json`, `sideby handoff enable --json` (exit 10 first), `sideby handoff ready`, `sideby next <family> --json` | `references/handoff.md` |
68
68
  | Explain or change the handoff rules ("接力规则", "什么时候换号", "让 Codex 接 Claude", "别用 API 账号接力") | `sideby handoff rules --json`, `sideby config set handoff.<key> <value>` or `sideby handoff enable --other-ai/--api --json` (exit 10 first) | `references/handoff.md` |
69
69
  | Sign an account in again or switch it to another login ("换个账号登录", "两个目录登录的是同一个号", "sign claude:work in with another account") | `sideby list --json` (`identity`, `sameLogin`), then give the user `sideby login <ref>` | `references/accounts.md` |
@@ -85,6 +85,7 @@ Account refs are `<family>:<name>`; a bare `<name>` works only when it is unique
85
85
  | A Claude API account's gateway rejects requests after an Advisor change, or why sideby adds `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS` to API accounts ("API 账号网关报错了", "为什么 API 账号多了这个变量") | `sideby advisor --json` (`apiBetasOff`, each group's `apiAccounts`), `sideby config get claude.apiBetasOff --json`; `sideby advisor undo` or `sideby config set claude.apiBetasOff false` after they agree | `references/panel.md` |
86
86
  | Claude asks "Is this a project you created or one you trust?" (Quick safety check, Accessing workspace) in one account although another of the user's Claude accounts already trusts the folder, or a handoff ended at that question ("别的账号已经信任过了还问", "每个账号都要点一次信任", "stop asking me to trust this folder in every account", "接力时卡在信任文件夹") | `sideby trust --json` (setting, and while on, `--dir <folder>` shows each account's trust as booleans), then `sideby trust on --json` (exits 10 with the change; rerun with `--yes` after they agree); `sideby trust undo` (exits 10 first) takes the copies back; `sideby trust off` keeps them | `references/trust.md` |
87
87
  | Stop Claude and Codex when the network is wrong ("网络不对时别让 Claude 用", "代理断了就拦住", "only allow US and Japan", "开网络检查"), see where requests leave from now, or a session says it was blocked | `sideby network --json`, `sideby network check --json`, `sideby network allow <CC>... --json` and `sideby network on --json` (each exits 10 first; rerun with `--yes` after they agree) | `references/network.md` |
88
+ | Diagnose Clash, v2rayN, direct, HTTP or SOCKS proxy connectivity without changing anything ("退出 Clash 就不能用", "v2ray 也看看", "诊断网络") | `sideby network diagnose --json` (offline, read-only; redacted route, TCP listener and cached Guard state), or the fixed read-only `network-diagnose` AI Task | `references/network.md` |
88
89
  | Leave sessions running with nobody there ("挂机", "无人值守", "今晚自己跑完", "设个时间段别问我", "keep going while I sleep"), set a nightly Schedule, or see what was left for the user | `sideby unattended on [--until 08:00] --json` (run it yourself when they say they are leaving), `sideby unattended schedule preset weeknights --json`, `sideby unattended --json`, `sideby unattended pending --json`; inside a session refused a question: `sideby unattended defer "<one sentence>"` | `references/unattended.md` |
89
90
  | What sessions left for the user, by project, and which of it they already dealt with ("哪些待我决定的处理过了", "真正没处理的是哪些", "按项目看待我决定的", "标错了恢复", "which pending decisions did I already answer") | `sideby unattended pending --json` (`state`: `open` nobody touched it since, `replied` the user wrote in that session afterwards, which does not tell whether it was finished; `projects` has each project's counts), `--project <name>` for one project; list each one to the user first, then `sideby unattended pending done <id>` or `done --ids <a>,<b> --json` for the ones they agree to; `sideby unattended pending reopen <id> --json` puts back a wrong mark | `references/unattended.md` |
90
91
  | How long a question waits before the session goes on without an answer ("问题没人回就自动按推荐继续", "问题等我 30 分钟", "别自动继续,一直等我", "how long does a question wait for me") | `sideby unattended wait --json` shows `answerWait`; `sideby unattended wait <1-120> --json` or `sideby unattended wait off --json` sets it. It acts only while Unattended Mode is on, and never answers "yes" | `references/unattended.md` |