sideby 0.24.0 → 0.26.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 (45) hide show
  1. package/README.md +3 -1
  2. package/ai-tasks.json +17 -0
  3. package/dist/build.json +1 -1
  4. package/dist/src/cli/commands.d.ts +14 -0
  5. package/dist/src/cli/commands.js +120 -12
  6. package/dist/src/cli/json-schemas.js +47 -0
  7. package/dist/src/cli/main.js +41 -6
  8. package/dist/src/core/ask.d.ts +10 -6
  9. package/dist/src/core/ask.js +52 -9
  10. package/dist/src/core/config.d.ts +16 -0
  11. package/dist/src/core/config.js +16 -0
  12. package/dist/src/core/egress.d.ts +103 -0
  13. package/dist/src/core/egress.js +333 -0
  14. package/dist/src/core/handoff-run.d.ts +4 -2
  15. package/dist/src/core/handoff-run.js +18 -11
  16. package/dist/src/core/launch.d.ts +5 -1
  17. package/dist/src/core/launch.js +5 -0
  18. package/dist/src/core/network.d.ts +131 -0
  19. package/dist/src/core/network.js +317 -0
  20. package/dist/src/families/agy/index.js +4 -1
  21. package/dist/src/families/claude/index.js +4 -1
  22. package/dist/src/families/codex/index.js +8 -1
  23. package/dist/src/families/grok/index.js +4 -1
  24. package/dist/src/families/pi/index.js +4 -1
  25. package/dist/src/network/hook.d.ts +15 -0
  26. package/dist/src/network/hook.js +69 -0
  27. package/dist/src/panel/handler.d.ts +3 -0
  28. package/dist/src/panel/handler.js +33 -1
  29. package/dist/src/panel/i18n.d.ts +51 -0
  30. package/dist/src/panel/i18n.js +102 -0
  31. package/dist/src/panel/page-logic.d.ts +23 -1
  32. package/dist/src/panel/page-logic.js +33 -0
  33. package/dist/src/panel/page-script.js +130 -2
  34. package/dist/src/panel/page-styles.js +11 -3
  35. package/dist/src/runtime.d.ts +18 -1
  36. package/dist/src/runtime.js +78 -7
  37. package/dist/src/types.d.ts +7 -0
  38. package/package.json +2 -2
  39. package/schemas/config.json +20 -0
  40. package/schemas/network-set.json +129 -0
  41. package/schemas/network.json +199 -0
  42. package/schemas/try.json +4 -0
  43. package/skills/sideby/SKILL.md +3 -2
  44. package/skills/sideby/references/ai-tasks.md +2 -1
  45. package/skills/sideby/references/network.md +37 -0
package/README.md CHANGED
@@ -91,8 +91,10 @@ cc-switch's docs describe that switch: it writes the live settings file ([README
91
91
  | See Claude quota (Codex needs no setup) | `sideby quota setup claude --yes` | [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
+ | 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) |
94
95
  | Choose whether Claude sessions connect to claude.ai by themselves (Remote Control), for every account at once | `sideby remote-control off` or `on` (or the panel's Settings) | [Remote Control](docs/guide/usage.md#remote-control) |
95
- | Pin the accounts you use most and put tools and accounts in your own order | `sideby pin claude:work`, `sideby order` (or the panel's Settings) | [Your own order](docs/guide/usage.md#your-own-order) |
96
+ | Pin the accounts you use most, put tools and accounts in your own order, and hide the ones you never use | `sideby pin claude:work`, `sideby order`, `sideby hide grok` (or the panel's Settings) | [Your own order](docs/guide/usage.md#your-own-order) |
97
+ | Give the panel other colors: five built-in Themes, your own color, or one your AI writes | **Settings › Theme** in the panel, or `sideby theme use leaf` | [Themes](docs/guide/panel.md#themes) |
96
98
  | Move on when an account hits its limit | `sideby next claude` | [Handoff](docs/guide/usage.md#when-an-account-hits-its-limit) |
97
99
  | Let a running task move to the next account by itself when quota runs low (off by default; see the risk) | `sideby handoff enable` (or the panel) | [Auto Handoff](docs/guide/usage.md#auto-handoff) |
98
100
  | Short commands such as `ccw` | `sideby alias add ccw claude:work` | [Shell functions](docs/guide/configuration.md#shell-functions) |
package/ai-tasks.json CHANGED
@@ -125,6 +125,23 @@
125
125
  { "en": "Nothing happens when I press it", "zh": "按了没反应" },
126
126
  { "en": "Two keys at most", "zh": "最多两个键" }
127
127
  ]
128
+ },
129
+ {
130
+ "id": "network",
131
+ "native": true,
132
+ "title": { "en": "Let AI help", "zh": "让 AI 帮我" },
133
+ "placeholder": {
134
+ "en": "Where are you, and which proxy nodes do you use? Or paste what was blocked.",
135
+ "zh": "你在哪里、用哪些代理节点?或者贴上被拦下的提示。"
136
+ },
137
+ "examples": [
138
+ {
139
+ "en": "I am in the US; stop everything when the proxy drops",
140
+ "zh": "我在美国,代理一断就全部拦住"
141
+ },
142
+ { "en": "Allow only my Japan and Singapore nodes", "zh": "只允许日本和新加坡节点" },
143
+ { "en": "A message was blocked; help me check the proxy", "zh": "消息被拦了,帮我查查代理" }
144
+ ]
128
145
  }
129
146
  ]
130
147
  }
package/dist/build.json CHANGED
@@ -1 +1 @@
1
- {"id":"20261025T115040-215ace"}
1
+ {"id":"20261027T054352-a40a27"}
@@ -9,6 +9,14 @@ export interface Io {
9
9
  /** The terminal Auto Handoff counts down on (spec §3.17); `process.stdin` when left out. */
10
10
  stdin?: HandoffIo['stdin'];
11
11
  }
12
+ /**
13
+ * Takes sideby's own `--ignore-network` (spec §3.35) out of the arguments `run` and `resume` pass to the Host,
14
+ * anywhere before `--`: no Host has an option of that name.
15
+ */
16
+ export declare function takeIgnoreNetwork(args: readonly string[]): {
17
+ args: string[];
18
+ ignoreNetwork: boolean;
19
+ };
12
20
  export declare function setJsonNotice(n: object | null): void;
13
21
  export declare function serializeDoctor(r: DoctorReport): {
14
22
  status: "issues" | "ok";
@@ -139,3 +147,9 @@ export declare function cmdSend(a: SendArgs, io: Io): Promise<number>;
139
147
  export declare function cmdMessages(a: ParsedArgs, io: Io, runtime?: Runtime): Promise<number>;
140
148
  /** `sideby theme` (spec §3.34): list, use, undo, check, preview, import, export and remove Themes. */
141
149
  export declare function cmdTheme(a: ParsedArgs, io: Io): Promise<number>;
150
+ /**
151
+ * `sideby network`: Network Guard (spec §3.35). Without a subcommand shows the switch, the allowed countries and the
152
+ * newest result per address from the cache; `check` asks each address now; `on`, `off` and `allow` change config
153
+ * `network` after a preview (exit 10 without `--yes`).
154
+ */
155
+ export declare function cmdNetwork(a: ParsedArgs, io: Io): Promise<number>;
@@ -42,6 +42,20 @@ async function whileRunning(rt, fn) {
42
42
  async function runAccount(rt, ref, args, io, opts = {}) {
43
43
  return whileRunning(rt, () => runAccountNow(rt, ref, args, io, opts));
44
44
  }
45
+ /**
46
+ * Takes sideby's own `--ignore-network` (spec §3.35) out of the arguments `run` and `resume` pass to the Host,
47
+ * anywhere before `--`: no Host has an option of that name.
48
+ */
49
+ export function takeIgnoreNetwork(args) {
50
+ const end = args.indexOf('--');
51
+ const head = end === -1 ? args : args.slice(0, end);
52
+ if (!head.includes('--ignore-network'))
53
+ return { args: [...args], ignoreNetwork: false };
54
+ return {
55
+ args: [...head.filter((x) => x !== '--ignore-network'), ...(end === -1 ? [] : args.slice(end))],
56
+ ignoreNetwork: true,
57
+ };
58
+ }
45
59
  async function runAccountNow(rt, ref, args, io, opts) {
46
60
  const handed = await runWithHandoff(rt, ref, args, { err: (l) => io.err(c.dim(l)), stdin: io.stdin ?? process.stdin }, opts);
47
61
  if (handed !== null)
@@ -486,10 +500,12 @@ export async function cmdRun(a, io, command) {
486
500
  if (command === 'login' && (extra.length || a.rest.length))
487
501
  throw new UsageError('login takes no extra arguments');
488
502
  const rt = await createRuntime();
503
+ const { args, ignoreNetwork } = takeIgnoreNetwork([...extra, ...a.rest]);
504
+ const net = ignoreNetwork ? { ignoreNetwork } : {};
489
505
  if (command === 'run' && rt.pickCommandFamily(ref) !== undefined)
490
- return runPick(rt, ref, [...extra, ...a.rest], io);
506
+ return runPick(rt, ref, args, io, net);
491
507
  if (command === 'run')
492
- return runAccount(rt, ref, [...extra, ...a.rest], io);
508
+ return runAccount(rt, ref, args, io, net);
493
509
  return runLogin(rt, ref, io);
494
510
  }
495
511
  /** Who an Account is signed in as, for `runLogin`; identity fields and Same Login peers only, never a credential. */
@@ -527,7 +543,7 @@ async function runLogin(rt, ref, io) {
527
543
  return code;
528
544
  }
529
545
  /** A Pick Command (spec §3.13, ADR-0035): start the Account with the most room, else the Main Account, and say which. */
530
- async function runPick(rt, name, args, io) {
546
+ async function runPick(rt, name, args, io, opts = {}) {
531
547
  const { choice, family } = await rt.pickChoice(name);
532
548
  if (choice.ref === null) {
533
549
  const now = rt.readContext().now;
@@ -542,7 +558,7 @@ async function runPick(rt, name, args, io) {
542
558
  }
543
559
  const { pickLine } = await import('../core/pick-commands.js');
544
560
  io.err(c.dim(`sideby: ${pickLine(name, choice)}`));
545
- return runAccount(rt, choice.ref, args, io);
561
+ return runAccount(rt, choice.ref, args, io, opts);
546
562
  }
547
563
  /**
548
564
  * `sideby resume <family>`: what the Host-named shell function calls (spec §3.15). Starts the Account that holds the
@@ -553,7 +569,10 @@ export async function cmdResume(a, io) {
553
569
  if (!family)
554
570
  throw new UsageError('usage: sideby resume <family> [-- host args]');
555
571
  const rt = await createRuntime();
556
- const route = await rt.resumeLaunch(family, [...extra, ...a.rest]);
572
+ const { args, ignoreNetwork } = takeIgnoreNetwork([...extra, ...a.rest]);
573
+ const route = await rt.resumeLaunch(family, args, ignoreNetwork ? { ignoreNetwork } : {});
574
+ if (route.launch.notice)
575
+ io.err(c.cyan(route.launch.notice));
557
576
  if (route.newSession)
558
577
  io.err(c.dim(`sideby: session ${route.sessionId} was never saved; starting a new session in ${route.account.ref}`));
559
578
  else if (route.account)
@@ -568,7 +587,7 @@ function shellQuote(arg) {
568
587
  export async function cmdNext(a, io) {
569
588
  const [family, ...extra] = a.positionals;
570
589
  if (!family || extra.length)
571
- throw new UsageError('usage: sideby next <family> [--dry-run] [--include-api] [-- host args]');
590
+ throw new UsageError('usage: sideby next <family> [--dry-run] [--include-api] [--ignore-network] [-- host args]');
572
591
  const includeApi = a.flags.has('include-api');
573
592
  const rt = await createRuntime();
574
593
  const plan = await rt.handoff(family, { includeApi });
@@ -634,7 +653,7 @@ export async function cmdNext(a, io) {
634
653
  io.out(c.dim('Tip: ask your old session for a short handoff note and paste it into the new one.'));
635
654
  if (!rt.handoffSettings().auto)
636
655
  io.out(c.dim('Sessions can also hand over by themselves when quota runs low: see `sideby handoff status`.'));
637
- return runAccount(rt, plan.pick, a.rest, io);
656
+ return runAccount(rt, plan.pick, a.rest, io, a.flags.has('ignore-network') ? { ignoreNetwork: true } : {});
638
657
  }
639
658
  export async function cmdDoctor(a, io) {
640
659
  const rt = await createRuntime();
@@ -2429,19 +2448,21 @@ export async function cmdKey(a, io, runtime) {
2429
2448
  export async function cmdTry(a, io) {
2430
2449
  const { tryAccount, tryPreview } = await import('../core/ask.js');
2431
2450
  if (a.positionals.length !== 1 || a.rest.length)
2432
- throw new UsageError('Use sideby try <account> [--yes] [--json].');
2451
+ throw new UsageError('Use sideby try <account> [--model <model>] [--yes] [--json].');
2452
+ const model = a.flags.get('model');
2433
2453
  const rt = await createRuntime();
2434
- const { account, command } = await tryPreview(rt, a.positionals[0]);
2454
+ const ref = a.positionals[0];
2455
+ const { account, command } = await tryPreview(rt, ref, model);
2435
2456
  if (!a.flags.has('yes')) {
2436
2457
  if (a.flags.has('json'))
2437
- json(io, { account: account.ref, command, confirmed: false });
2458
+ json(io, { account: account.ref, ...(model === undefined ? {} : { model }), command, confirmed: false });
2438
2459
  else
2439
2460
  io.out(`This spends a few tokens: ${command.map((v) => JSON.stringify(v)).join(' ')}. Run again with --yes to continue.`);
2440
2461
  return 10;
2441
2462
  }
2442
- const { account: ref, command: _command, ...result } = await tryAccount(rt, account.ref);
2463
+ const { account: done, command: _command, ...result } = await tryAccount(rt, ref, undefined, model);
2443
2464
  if (a.flags.has('json'))
2444
- json(io, { account: ref, confirmed: true, ...result });
2465
+ json(io, { account: done, confirmed: true, ...result });
2445
2466
  else
2446
2467
  io.out(result.ok ? 'OK' : result.output || 'The Host did not reply; check the account and try again.');
2447
2468
  return result.ok ? 0 : 1;
@@ -3789,3 +3810,90 @@ export async function cmdTheme(a, io) {
3789
3810
  }
3790
3811
  throw new UsageError(usage);
3791
3812
  }
3813
+ /**
3814
+ * `sideby network`: Network Guard (spec §3.35). Without a subcommand shows the switch, the allowed countries and the
3815
+ * newest result per address from the cache; `check` asks each address now; `on`, `off` and `allow` change config
3816
+ * `network` after a preview (exit 10 without `--yes`).
3817
+ */
3818
+ export async function cmdNetwork(a, io) {
3819
+ const [sub, ...rest] = a.positionals;
3820
+ const { setNetwork } = await import('../core/network.js');
3821
+ const rt = await createRuntime();
3822
+ const asJson = a.flags.has('json');
3823
+ if (sub === 'on' || sub === 'off' || sub === 'allow') {
3824
+ if (sub !== 'allow' && rest.length)
3825
+ throw new UsageError(`usage: sideby network ${sub} [--yes]`);
3826
+ if (sub === 'allow' && !rest.length)
3827
+ throw new UsageError('usage: sideby network allow <country>... [--yes] (for example: sideby network allow US JP)');
3828
+ const change = sub === 'allow' ? { allow: rest } : { guard: sub === 'on' };
3829
+ const r = await setNetwork(rt.paths.configFile, change, { apply: a.flags.has('yes') });
3830
+ if (asJson)
3831
+ json(io, r);
3832
+ else if (!r.changed)
3833
+ io.out('Nothing to change.');
3834
+ else if (!r.applied) {
3835
+ const show = (v) => `${v.guard ? 'on' : 'off'}, allowed: ${v.allow.join(', ') || 'none'}`;
3836
+ io.out(`Change to ${tildify(r.file, rt.paths.home)}: network ${show(r.before)} → ${show(r.after)}`);
3837
+ if (r.after.guard && !r.before.guard)
3838
+ io.out(c.dim("Claude and Codex accounts started by sideby are then checked before starting and before each prompt and tool call; sideby asks the vendor's own /cdn-cgi/trace through the account's proxy, with no credential."));
3839
+ io.out(c.cyan(`Apply it with \`sideby network ${[sub, ...rest].join(' ')} --yes\`.`));
3840
+ }
3841
+ else
3842
+ io.out(`${c.green('✓')} network check ${r.after.guard ? 'on' : 'off'}, allowed: ${r.after.allow.join(', ') || 'none'}.`);
3843
+ return r.changed && !r.applied ? 10 : 0;
3844
+ }
3845
+ if ((sub !== undefined && sub !== 'check') || rest.length || a.rest.length)
3846
+ throw new UsageError('usage: sideby network [check] | sideby network on|off [--yes] | sideby network allow <country>... [--yes]');
3847
+ const s = await rt.networkStatus(sub === 'check' ? { check: true } : {});
3848
+ if (asJson) {
3849
+ json(io, s);
3850
+ return 0;
3851
+ }
3852
+ const state = s.active
3853
+ ? c.green('on')
3854
+ : s.guard
3855
+ ? c.yellow(s.ci ? 'on, but not in CI' : 'on')
3856
+ : c.dim('off');
3857
+ io.out(`Network check: ${state}${s.allow.length ? `, allowed: ${s.allow.join(', ')}` : ''}`);
3858
+ const now = rt.readContext().now;
3859
+ const mark = {
3860
+ ok: c.green('ok'),
3861
+ blocked: c.red('blocked'),
3862
+ unknown: c.red('cannot tell'),
3863
+ 'not-checked': c.dim('not checked yet'),
3864
+ };
3865
+ if (s.targets.length)
3866
+ io.out(table(s.targets.map((t) => [
3867
+ new URL(t.url).hostname,
3868
+ t.loc ?? '-',
3869
+ s.allow.length || t.status === 'not-checked'
3870
+ ? mark[t.status]
3871
+ : c.dim(t.loc ? 'seen' : 'not checked yet'),
3872
+ c.dim([
3873
+ t.checkedAt ? `checked ${clock(t.checkedAt, now)}` : '',
3874
+ t.error ?? '',
3875
+ t.ipChanged ? 'exit address changed in the last day' : '',
3876
+ t.accounts.join(', '),
3877
+ ]
3878
+ .filter(Boolean)
3879
+ .join(' · ')),
3880
+ ]), ['ADDRESS', 'COUNTRY', 'RESULT', 'NOTE']));
3881
+ const skipped = s.accounts.filter((x) => x.skip);
3882
+ if (skipped.length) {
3883
+ const why = {
3884
+ 'third-party': 'third-party endpoint, not checked',
3885
+ 'at-launch': 'API account, checked when it starts',
3886
+ 'not-covered': 'not covered',
3887
+ };
3888
+ for (const x of skipped)
3889
+ io.out(c.dim(` ${x.ref}: ${why[x.skip]}`));
3890
+ }
3891
+ if (!s.guard)
3892
+ io.out(c.cyan(s.allow.length
3893
+ ? 'Turn it on with `sideby network on --yes`.'
3894
+ : 'Choose the countries your requests may leave from, then turn it on: `sideby network allow US JP --yes` and `sideby network on --yes`.'));
3895
+ else if (sub !== 'check')
3896
+ io.out(c.dim('Check now with `sideby network check`.'));
3897
+ io.out(c.dim('Sessions started without sideby (running `claude` or `codex` directly) are not checked.'));
3898
+ return 0;
3899
+ }
@@ -1092,6 +1092,52 @@ export const OUTPUT_SCHEMAS = {
1092
1092
  description: 'False when only the plan was shown; run again with --yes (exit 10).',
1093
1093
  }),
1094
1094
  }, { title: 'sideby desktop grok-bot:<name> --remove --json' }),
1095
+ network: Type.Object({
1096
+ schemaVersion: Version,
1097
+ guard: Type.Boolean({ description: 'Config `network.guard`: Network Guard is switched on.' }),
1098
+ allow: Type.Array(Str, {
1099
+ description: 'Allowed countries (ISO 3166-1 alpha-2), config `network.allow`.',
1100
+ }),
1101
+ active: Type.Boolean({
1102
+ description: 'It checks Launches now: switched on, a country allowed, and not in CI.',
1103
+ }),
1104
+ ci: Type.Boolean({ description: 'Running in CI, where it makes no request and checks nothing.' }),
1105
+ targets: Type.Array(Type.Object({
1106
+ url: Type.String({ description: 'The `/cdn-cgi/trace` address asked.' }),
1107
+ accounts: Type.Array(Str, { description: 'Refs of the accounts checked at this address.' }),
1108
+ status: Type.Union([
1109
+ Type.Literal('ok'),
1110
+ Type.Literal('blocked'),
1111
+ Type.Literal('unknown'),
1112
+ Type.Literal('not-checked'),
1113
+ ], {
1114
+ description: 'ok: the country is allowed; blocked: it is not; unknown: the last check could not tell (it blocks); not-checked: no result yet.',
1115
+ }),
1116
+ loc: Type.Optional(Type.String({ description: 'The country the vendor sees, from the newest result.' })),
1117
+ checkedAt: Type.Optional(Type.String({ description: 'When the newest result was asked (ISO).' })),
1118
+ error: Type.Optional(Type.String({ description: 'Why the newest check could not tell.' })),
1119
+ ipChanged: Type.Boolean({
1120
+ description: 'The exit address changed in the last day (a notice only).',
1121
+ }),
1122
+ })),
1123
+ accounts: Type.Array(Type.Object({
1124
+ ref: Str,
1125
+ url: Type.Optional(Type.String({ description: 'The address this account is checked at.' })),
1126
+ skip: Type.Optional(Type.Union([Type.Literal('not-covered'), Type.Literal('third-party'), Type.Literal('at-launch')], {
1127
+ description: 'third-party: an API account on another endpoint, not checked; at-launch: an API account, whose address is known only when it starts.',
1128
+ })),
1129
+ })),
1130
+ }, { title: 'sideby network [check] --json' }),
1131
+ 'network-set': Type.Object({
1132
+ schemaVersion: Version,
1133
+ changed: Type.Boolean(),
1134
+ applied: Type.Boolean({
1135
+ description: 'False when only the change was shown; run again with --yes (exit 10).',
1136
+ }),
1137
+ file: Type.String({ description: 'The config file changed.' }),
1138
+ before: Type.Object({ guard: Type.Boolean(), allow: Type.Array(Str) }),
1139
+ after: Type.Object({ guard: Type.Boolean(), allow: Type.Array(Str) }),
1140
+ }, { title: 'sideby network on|off|allow --json' }),
1095
1141
  browser: Type.Object({
1096
1142
  schemaVersion: Version,
1097
1143
  enabled: Type.Boolean({
@@ -1285,6 +1331,7 @@ export const OUTPUT_SCHEMAS = {
1285
1331
  try: Type.Object({
1286
1332
  schemaVersion: Version,
1287
1333
  account: Str,
1334
+ model: Type.Optional(Type.String({ description: 'The model `--model` chose, when given.' })),
1288
1335
  confirmed: Type.Boolean(),
1289
1336
  command: Type.Optional(Type.Array(Str)),
1290
1337
  ok: Type.Optional(Type.Boolean()),
@@ -10,7 +10,7 @@ Usage:
10
10
  sideby ask [<text>] [--print] let your AI handle a sideby task
11
11
  sideby terminal [--set <id>|--custom <t>|--unset] choose your terminal
12
12
  sideby key <account> [--var <NAME>] enter an API key without echo
13
- sideby try <account> [--yes] try the Host with a short paid request
13
+ sideby try <account> [--model <m>] try the Host with a short paid request
14
14
  sideby list accounts (same as \`sideby list\`)
15
15
  sideby list --all also list hidden families and accounts
16
16
  sideby run <account> [-- args] start the host CLI for one account
@@ -42,7 +42,7 @@ Usage:
42
42
  sideby login <account> sign in to an account
43
43
  sideby resume <family> [-- args] run the host; a session resumed by id (claude --resume <id>,
44
44
  codex resume <id>) starts in the account that holds it
45
- sideby next <family> [--dry-run] [--include-api] [-- args]
45
+ sideby next <family> [--dry-run] [--include-api] [--ignore-network] [-- args]
46
46
  recommend the account with the most quota left (claude, codex, grok)
47
47
  and start it; --dry-run only recommends
48
48
  sideby doctor [target] [--fix] [--force]
@@ -96,6 +96,8 @@ Usage:
96
96
  whether Claude sessions show messages from other sessions at once
97
97
  sideby edit <account> [--path] open the account's own settings file (settings.json,
98
98
  config.toml) in your editor
99
+ sideby network [check] stop Claude and Codex when requests would leave from a country
100
+ you did not allow (network on|off|allow <CC>... [--yes])
99
101
  sideby browser [--enable [--yes]] which Chrome browser user signed in to each account's website
100
102
  (read on this computer only; off until you enable it)
101
103
  sideby browser open <account> [--profile <name>]
@@ -150,10 +152,10 @@ Updates: once a day sideby asks the npm registry for its newest version and says
150
152
  Turn it off with NO_UPDATE_NOTIFIER=1 or config "update": { "check": false }; "auto": true installs by itself.`;
151
153
  /** `sideby <command> --help` for the commands agents use to set up and repair accounts (spec §3.16). */
152
154
  const COMMAND_HELP = {
153
- ask: 'sideby ask [<text>] [--task free|fix|quota|account|host|plugin|terminal|handoff|theme|menubar|hotkey] [--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.',
155
+ 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.',
154
156
  terminal: "sideby terminal [--set <id>|--custom '<program> … {cwd} … {cmd}'|--unset] [--json]\nList terminals or save your preference; --custom saves and selects your own launch command.",
155
157
  key: 'sideby key <account> [--var <NAME>] [--json]\nEnter an API key without echo. Run in a terminal or use the Panel key box.',
156
- try: 'sideby try <account> [--yes] [--json]\nSend a short request through the Host. This spends a few tokens. Exit 10 waits for --yes.',
158
+ try: 'sideby try <account> [--model <model>] [--yes] [--json]\nSend a short request through the Host. This spends a few tokens. Exit 10 waits for --yes.\n<account> may be a short command; its arguments apply as in sideby run. --model tries another model once.',
157
159
  plugins: 'sideby plugins [--json]\nsideby plugins new <id> [--json]\nsideby plugins check <id|path> [--json]\nPlugins run as you, with your permissions. Only load plugins you trust.',
158
160
  new: `sideby new <family> <name> [--api] [--alias <short>] [--json]
159
161
  sideby new <family> --next [--api] [--alias <short>] [--json]
@@ -434,6 +436,31 @@ Examples:
434
436
  sideby config unset panel.language --yes
435
437
  Exit: 0 shown, saved or nothing to change; 10 a change was shown and waits for --yes; 1 not a key, a value the key
436
438
  does not take, or the file changed meanwhile; 2 malformed command line.`,
439
+ network: `sideby network [check] [--json]
440
+ sideby network allow <country>... [--yes] [--json]
441
+ sideby network on|off [--yes] [--json]
442
+
443
+ Network check: before sideby starts a Claude or Codex account, and before each prompt and tool call in a session
444
+ it started, check the country the requests leave from. When it is not one you allowed, or cannot be told within 3
445
+ seconds (the proxy is off, the network is down), stop and say what to do. It guards against a proxy that stopped
446
+ or a node in the wrong country; it does not make use from an unsupported region allowed.
447
+
448
+ sideby asks the vendor's own https://api.anthropic.com, chatgpt.com or api.openai.com /cdn-cgi/trace, through the
449
+ account's proxy settings, with no credential, account or identity, and keeps only the country and a hash of the
450
+ address. Results are reused for 60 seconds. Off by default; off in CI. Sessions started without sideby (running
451
+ claude or codex directly) are not checked. API accounts on a third-party endpoint are not checked.
452
+
453
+ network shows the setting and the newest result per address (no request)
454
+ network check asks every address now
455
+ allow sets the allowed countries (two letters, such as US JP); on and off turn it on and off
456
+ To skip it once: sideby run <account> --ignore-network (also sideby next --ignore-network).
457
+
458
+ Examples:
459
+ sideby network allow US JP --yes
460
+ sideby network on --yes
461
+ sideby network check
462
+ Exit: 0 shown or changed; 10 a change was shown and waits for --yes; 1 a country code that is not one, or on with
463
+ no country allowed; 2 malformed command line.`,
437
464
  browser: `sideby browser [--enable|--disable] [--yes] [--json]
438
465
  sideby browser open <account> [--profile <folder|name>] [--json]
439
466
  sideby browser set <account> <folder|name> [--json]
@@ -493,7 +520,7 @@ const COMMANDS = {
493
520
  },
494
521
  terminal: { flags: ['json', 'unset'], valued: ['set', 'custom'] },
495
522
  key: { flags: ['json'], valued: ['var'] },
496
- try: { flags: ['json', 'yes'] },
523
+ try: { flags: ['json', 'yes'], valued: ['model'] },
497
524
  autostart: { flags: ['json', 'yes', 'refresh'] },
498
525
  menubar: { flags: ['json', 'yes', 'refresh'], valued: ['lang', 'hotkey', 'hotkey-label', 'icon'] },
499
526
  config: { flags: ['json', 'yes'] },
@@ -507,7 +534,8 @@ const COMMANDS = {
507
534
  run: { flags: [] },
508
535
  resume: { flags: [] },
509
536
  login: { flags: [] },
510
- next: { flags: ['dry-run', 'include-api', 'json'] },
537
+ next: { flags: ['dry-run', 'include-api', 'json', 'ignore-network'] },
538
+ network: { flags: ['json', 'yes'] },
511
539
  new: { flags: ['api', 'json', 'next'], valued: ['alias'] },
512
540
  alias: { flags: ['json', 'yes'], valued: ['pick'] },
513
541
  doctor: { flags: ['fix', 'force', 'json'] },
@@ -648,6 +676,11 @@ export async function main(argv) {
648
676
  const { runHandoffHook } = await import('../handoff/hook.js');
649
677
  return runHandoffHook(rest, process.env, process.stdin, process.stdout);
650
678
  }
679
+ // Network Guard's hook runs before every prompt and tool call it guards (spec §3.35); same fast path.
680
+ if (first === 'network-hook') {
681
+ const { runNetworkHook } = await import('../network/hook.js');
682
+ return runNetworkHook(rest, process.env, process.stderr);
683
+ }
651
684
  if (nodeTooOld()) {
652
685
  console.error(`sideby needs Node ${MIN_NODE.join('.')} or newer (you have ${process.versions.node}). Upgrade: https://nodejs.org, or with nvm: \`nvm install 22 && nvm alias default 22\`, then \`npm i -g sideby\` again (each Node version has its own global packages).`);
653
686
  return 1;
@@ -796,6 +829,8 @@ async function dispatch(cmd, parsed, io, cmds) {
796
829
  return await cmds.cmdEdit(parsed, io);
797
830
  case 'browser':
798
831
  return await cmds.cmdBrowser(parsed, io);
832
+ case 'network':
833
+ return await cmds.cmdNetwork(parsed, io);
799
834
  case 'shell-init':
800
835
  return await cmds.cmdShellInit(parsed, io);
801
836
  case 'plugins':
@@ -1,6 +1,6 @@
1
1
  import { taskPrompt } from '../panel/page-logic.ts';
2
2
  import type { Runtime } from '../runtime.ts';
3
- import type { Account, Env } from '../types.ts';
3
+ import type { Account, Env, FamilyDef } from '../types.ts';
4
4
  import { type Attachment } from './attachments.ts';
5
5
  import { UserError } from './errors.ts';
6
6
  import { type Paths } from './paths.ts';
@@ -213,12 +213,14 @@ export declare function openPickInTerminal(rt: Runtime, name: string): Promise<{
213
213
  detail?: string | undefined;
214
214
  }>;
215
215
  /**
216
- * What `try` will run for an Account, computed as `sideby run` would (Family defaults, config arguments) but without
217
- * reading its Secret File or running `launch.before` hooks: nothing runs before the user agrees.
216
+ * What `try` will run for an Account, computed as `sideby run` would (Family defaults, config arguments, a short
217
+ * command's arguments) but without reading its Secret File or running `launch.before` hooks: nothing runs before the
218
+ * user agrees. `model` replaces the model those arguments choose.
218
219
  */
219
- export declare function tryPreview(rt: Runtime, ref: string): Promise<{
220
+ export declare function tryPreview(rt: Runtime, ref: string, model?: string): Promise<{
220
221
  account: Account;
221
- family: import("../types.ts").FamilyDef;
222
+ family: FamilyDef;
223
+ probe: string[];
222
224
  command: string[];
223
225
  }>;
224
226
  /**
@@ -226,12 +228,14 @@ export declare function tryPreview(rt: Runtime, ref: string): Promise<{
226
228
  * folder under the task directory that is removed afterwards. The caller has already said it spends a few tokens. The
227
229
  * launch is prepared once here, so `launch.before` hooks run once, and the command returned is what actually ran.
228
230
  * `spawn` replaces the process start (tests); by default the Host runs with stdin ignored and is killed at the timeout.
231
+ * `ref` may be a short command, whose arguments apply as in `sideby run`; `model` replaces the model they choose.
229
232
  */
230
- export declare function tryAccount(rt: Runtime, ref: string, spawn?: ProbeDeps['spawn']): Promise<{
233
+ export declare function tryAccount(rt: Runtime, ref: string, spawn?: ProbeDeps['spawn'], model?: string): Promise<{
231
234
  ok: boolean;
232
235
  exitCode: number | null;
233
236
  output: string;
234
237
  timedOut: boolean;
235
238
  account: string;
239
+ model?: string | undefined;
236
240
  command: string[];
237
241
  }>;
@@ -3,6 +3,7 @@ import { constants } from 'node:fs';
3
3
  import { lstat, mkdtemp, open, readdir, realpath, rm, stat, unlink } from 'node:fs/promises';
4
4
  import { userInfo } from 'node:os';
5
5
  import { dirname, isAbsolute, join, sep } from 'node:path';
6
+ import { MODEL_NAME, takeFlag } from '../families/shared/model-args.js';
6
7
  import { AI_TASK_KINDS, stripSecrets, taskPrompt } from '../panel/page-logic.js';
7
8
  import { checkAttachmentFiles, copyAttachments, MAX_ATTACHMENTS, privateDir, removeOldAttachments, stagedAttachments, takeStaged, } from './attachments.js';
8
9
  import { editConfigAsk, editConfigTerminal } from './config.js';
@@ -277,6 +278,11 @@ export function taskContext(c, fail) {
277
278
  throw fail('"context.handoff" must be a list');
278
279
  out.handoff = v.map((x) => str(x, 'each of "context.handoff"'));
279
280
  }
281
+ else if (k === 'network') {
282
+ if (!Array.isArray(v) || v.length > 100)
283
+ throw fail('"context.network" must be a list');
284
+ out.network = v.map((x) => str(x, 'each of "context.network"'));
285
+ }
280
286
  else if (k === 'findings') {
281
287
  if (!Array.isArray(v) || v.length > 100)
282
288
  throw fail('"context.findings" must be a list');
@@ -454,33 +460,70 @@ export async function openPickInTerminal(rt, name) {
454
460
  throw new UserError(`No short command "${name}" picks an account; add one in the Panel or with \`sideby alias add ${name} --pick <family>\`.`);
455
461
  return openTask(rt, { kind: 'run', account: name, cwd: rt.paths.home });
456
462
  }
463
+ /** The probe arguments for `model`, or the plain probe; refuses a model the Family cannot choose or a malformed name. */
464
+ function probeArgs(family, model) {
465
+ const probe = family.probe;
466
+ if (model === undefined)
467
+ return probe.args;
468
+ if (!probe.model)
469
+ throw new UserError(`${family.title} cannot be tried with another model; leave out --model.`, {
470
+ code: 'no-model-choice',
471
+ });
472
+ if (!MODEL_NAME.test(model))
473
+ throw new UserError('A model name uses letters, digits and ._:/[]- only (at most 100); check the name.', {
474
+ code: 'model-invalid',
475
+ });
476
+ return probe.model.args(model);
477
+ }
457
478
  /**
458
- * What `try` will run for an Account, computed as `sideby run` would (Family defaults, config arguments) but without
459
- * reading its Secret File or running `launch.before` hooks: nothing runs before the user agrees.
479
+ * With `--model`, the model options of the arguments before the probe's (the Account's and the short command's) are
480
+ * taken out, so the Host gets one model. Arguments a hook added around them stay; if the probe's own arguments
481
+ * cannot be found, nothing changes.
460
482
  */
461
- export async function tryPreview(rt, ref) {
483
+ function oneModel(args, probe, family, model) {
484
+ if (model === undefined || !family.probe?.model)
485
+ return args;
486
+ for (let at = args.length - probe.length; at >= 0; at--)
487
+ if (probe.every((v, i) => args[at + i] === v))
488
+ return [...takeFlag(args.slice(0, at), family.probe.model.flags).rest, ...args.slice(at)];
489
+ return args;
490
+ }
491
+ /**
492
+ * What `try` will run for an Account, computed as `sideby run` would (Family defaults, config arguments, a short
493
+ * command's arguments) but without reading its Secret File or running `launch.before` hooks: nothing runs before the
494
+ * user agrees. `model` replaces the model those arguments choose.
495
+ */
496
+ export async function tryPreview(rt, ref, model) {
462
497
  const account = await rt.resolve(ref);
463
498
  const family = rt.families.get(account.family);
464
499
  if (!family?.probe)
465
500
  throw new UserError(`This tool cannot be tried; use \`sideby run ${account.ref}\` instead.`, {
466
501
  code: 'no-probe',
467
502
  });
468
- const { bin, args } = await rt.launchCommand(account.ref, family.probe.args, 'run');
469
- return { account, family, command: [bin, ...args] };
503
+ const probe = probeArgs(family, model);
504
+ const { bin, args } = await rt.launchCommand(ref, probe, 'run');
505
+ return { account, family, probe, command: [bin, ...oneModel(args, probe, family, model)] };
470
506
  }
471
507
  /**
472
508
  * `sideby try` and the Panel (spec §3.28): runs the Family's probe once the way Launch starts the Host, in a temp
473
509
  * folder under the task directory that is removed afterwards. The caller has already said it spends a few tokens. The
474
510
  * launch is prepared once here, so `launch.before` hooks run once, and the command returned is what actually ran.
475
511
  * `spawn` replaces the process start (tests); by default the Host runs with stdin ignored and is killed at the timeout.
512
+ * `ref` may be a short command, whose arguments apply as in `sideby run`; `model` replaces the model they choose.
476
513
  */
477
- export async function tryAccount(rt, ref, spawn = spawnProbe) {
478
- const { account, family } = await tryPreview(rt, ref);
479
- const launch = await rt.prepareLaunch(account.ref, family.probe.args, 'run');
514
+ export async function tryAccount(rt, ref, spawn = spawnProbe, model) {
515
+ const { account, family, probe } = await tryPreview(rt, ref, model);
516
+ const prepared = await rt.prepareLaunch(ref, probe, 'run');
517
+ const launch = { ...prepared, args: oneModel(prepared.args, probe, family, model) };
480
518
  const cwd = await mkdtemp(join(await taskWorkDir(rt.paths), 'probe-'));
481
519
  try {
482
520
  const result = await runProbe(account, { family, baseEnv: rt.env, cwd, launch, spawn });
483
- return { account: account.ref, command: [launch.bin, ...launch.args], ...result };
521
+ return {
522
+ account: account.ref,
523
+ ...(model === undefined ? {} : { model }),
524
+ command: [launch.bin, ...launch.args],
525
+ ...result,
526
+ };
484
527
  }
485
528
  finally {
486
529
  await rm(cwd, { recursive: true, force: true });
@@ -99,6 +99,10 @@ export declare const ConfigSchema: Type.TObject<{
99
99
  history: Type.TOptional<Type.TObject<{
100
100
  index: Type.TOptional<Type.TBoolean>;
101
101
  }>>;
102
+ network: Type.TOptional<Type.TObject<{
103
+ guard: Type.TOptional<Type.TBoolean>;
104
+ allow: Type.TOptional<Type.TArray<Type.TString>>;
105
+ }>>;
102
106
  browser: Type.TOptional<Type.TObject<{
103
107
  signIns: Type.TOptional<Type.TBoolean>;
104
108
  choices: Type.TOptional<Type.TRecord<"^.*$", Type.TString>>;
@@ -148,6 +152,18 @@ export declare function editConfigUpdate(file: string, edit: (current: UpdateCon
148
152
  before: UpdateConfig | undefined;
149
153
  after: UpdateConfig | undefined;
150
154
  }>;
155
+ export type NetworkConfig = NonNullable<Config['network']>;
156
+ /**
157
+ * `sideby network on|off|allow` and the Panel's network check (spec §3.35): changes the config `network` key with
158
+ * `edit` (see `editConfigKey` for how the file is written). With `dryRun`, shows the change without writing.
159
+ */
160
+ export declare function editConfigNetwork(file: string, edit: (current: NetworkConfig) => NetworkConfig, opts?: {
161
+ dryRun?: boolean;
162
+ }): Promise<{
163
+ changed: boolean;
164
+ before: NetworkConfig | undefined;
165
+ after: NetworkConfig | undefined;
166
+ }>;
151
167
  export type BrowserConfig = NonNullable<Config['browser']>;
152
168
  /**
153
169
  * `sideby browser --enable|--disable` and the Panel's switch (spec §3.24): changes the config `browser` key with