sideby 0.25.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 (37) hide show
  1. package/README.md +1 -0
  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 +113 -7
  6. package/dist/src/cli/json-schemas.js +46 -0
  7. package/dist/src/cli/main.js +38 -3
  8. package/dist/src/core/ask.js +5 -0
  9. package/dist/src/core/config.d.ts +16 -0
  10. package/dist/src/core/config.js +16 -0
  11. package/dist/src/core/egress.d.ts +103 -0
  12. package/dist/src/core/egress.js +333 -0
  13. package/dist/src/core/handoff-run.d.ts +4 -2
  14. package/dist/src/core/handoff-run.js +18 -11
  15. package/dist/src/core/launch.d.ts +5 -1
  16. package/dist/src/core/launch.js +5 -0
  17. package/dist/src/core/network.d.ts +131 -0
  18. package/dist/src/core/network.js +317 -0
  19. package/dist/src/network/hook.d.ts +15 -0
  20. package/dist/src/network/hook.js +69 -0
  21. package/dist/src/panel/handler.d.ts +3 -0
  22. package/dist/src/panel/handler.js +32 -0
  23. package/dist/src/panel/i18n.d.ts +51 -0
  24. package/dist/src/panel/i18n.js +102 -0
  25. package/dist/src/panel/page-logic.d.ts +23 -1
  26. package/dist/src/panel/page-logic.js +33 -0
  27. package/dist/src/panel/page-script.js +130 -2
  28. package/dist/src/panel/page-styles.js +11 -3
  29. package/dist/src/runtime.d.ts +18 -1
  30. package/dist/src/runtime.js +78 -7
  31. package/package.json +2 -2
  32. package/schemas/config.json +20 -0
  33. package/schemas/network-set.json +129 -0
  34. package/schemas/network.json +199 -0
  35. package/skills/sideby/SKILL.md +2 -1
  36. package/skills/sideby/references/ai-tasks.md +1 -1
  37. package/skills/sideby/references/network.md +37 -0
package/README.md CHANGED
@@ -91,6 +91,7 @@ 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
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) |
96
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) |
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":"20261026T102043-565ca8"}
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();
@@ -3791,3 +3810,90 @@ export async function cmdTheme(a, io) {
3791
3810
  }
3792
3811
  throw new UsageError(usage);
3793
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({
@@ -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,7 +152,7 @@ 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
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.',
@@ -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]
@@ -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':
@@ -278,6 +278,11 @@ export function taskContext(c, fail) {
278
278
  throw fail('"context.handoff" must be a list');
279
279
  out.handoff = v.map((x) => str(x, 'each of "context.handoff"'));
280
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
+ }
281
286
  else if (k === 'findings') {
282
287
  if (!Array.isArray(v) || v.length > 100)
283
288
  throw fail('"context.findings" must be a list');
@@ -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
@@ -200,6 +200,15 @@ export const ConfigSchema = Type.Object({
200
200
  description: "Keep a local History Index of every Session's title, Project, typed prompts and model replies (never tool output) in sideby's state folder, so Session History opens and searches at once. On by default; false stops it and deletes the index.",
201
201
  })),
202
202
  }, { additionalProperties: false, description: 'Session History (spec §3.33, ADR-0042).' })),
203
+ network: Type.Optional(Type.Object({
204
+ guard: Type.Optional(Type.Boolean({
205
+ description: "Network Guard: before a Launch and before each prompt and tool call in a session sideby starts, check the country Claude Code's and Codex's requests leave from, and stop when it is not in `allow` or cannot be told. Asks the vendor's own `/cdn-cgi/trace` through the Host's proxy settings, with no credential. Off by default.",
206
+ })),
207
+ allow: Type.Optional(Type.Array(Type.String({ pattern: '^[A-Z]{2}$' }), {
208
+ uniqueItems: true,
209
+ description: 'Countries (ISO 3166-1 alpha-2, such as `US` or `JP`) a Host may send requests from. Network Guard cannot be turned on while it is empty.',
210
+ })),
211
+ }, { additionalProperties: false, description: 'Network Guard (spec §3.35, ADR-0053).' })),
203
212
  browser: Type.Optional(Type.Object({
204
213
  signIns: Type.Optional(Type.Boolean({
205
214
  description: "Look in Google Chrome's local data for which browser user signed in to each Account's website (key names only, never cookies or passwords; nothing leaves this computer). Off by default.",
@@ -411,6 +420,13 @@ export function editConfigHandoff(file, edit, opts = {}) {
411
420
  export function editConfigUpdate(file, edit, opts = {}) {
412
421
  return editConfigKey(file, 'update', 'change the setting', (current) => edit(current ?? {}), opts);
413
422
  }
423
+ /**
424
+ * `sideby network on|off|allow` and the Panel's network check (spec §3.35): changes the config `network` key with
425
+ * `edit` (see `editConfigKey` for how the file is written). With `dryRun`, shows the change without writing.
426
+ */
427
+ export function editConfigNetwork(file, edit, opts = {}) {
428
+ return editConfigKey(file, 'network', 'change the setting', (current) => edit(current ?? {}), opts);
429
+ }
414
430
  /**
415
431
  * `sideby browser --enable|--disable` and the Panel's switch (spec §3.24): changes the config `browser` key with
416
432
  * `edit` (see `editConfigKey` for how the file is written). With `dryRun`, shows the change without writing.
@@ -0,0 +1,103 @@
1
+ import { networkInterfaces } from 'node:os';
2
+ /** Variables a launched Host reads for its proxy; the check uses the same ones, so it takes the same route. */
3
+ export declare const PROXY_VARS: readonly ['HTTPS_PROXY', 'https_proxy', 'HTTP_PROXY', 'http_proxy', 'ALL_PROXY', 'all_proxy', 'NO_PROXY', 'no_proxy'];
4
+ /** What `network-hook` reads from the session's environment; set by sideby at Launch. */
5
+ export declare const NETWORK_ENV: {
6
+ readonly url: 'SIDEBY_NETWORK_URL';
7
+ readonly allow: 'SIDEBY_NETWORK_ALLOW';
8
+ readonly dir: 'SIDEBY_NETWORK_DIR';
9
+ };
10
+ export declare const TIMEOUT_MS = 3000;
11
+ /** A result this young is used as it is. */
12
+ export declare const FRESH_MS = 60000;
13
+ /** Up to this age a tool call goes on while a detached process refreshes the result. */
14
+ export declare const STALE_MS: number;
15
+ export type EgressStatus = 'ok' | 'blocked' | 'unknown';
16
+ /** When a check happens: before a Launch, before a prompt, or before a tool call (spec §3.35 table). */
17
+ export type CheckMoment = 'launch' | 'prompt' | 'tool';
18
+ export interface EgressEntry {
19
+ url: string;
20
+ /** ISO time of the request. */
21
+ checkedAt: string;
22
+ /** Country code from `loc=`, absent when the check could not tell. */
23
+ loc?: string;
24
+ /** SHA-256 of the address; the address itself is never kept. */
25
+ ipHash?: string;
26
+ /** When a check last saw another address than the one before. */
27
+ ipChangedAt?: string;
28
+ /** Why the check could not tell, in plain words. */
29
+ error?: string;
30
+ /** Hash of the machine's network addresses at the time of the check. */
31
+ netPrint: string;
32
+ }
33
+ export interface Verdict {
34
+ status: EgressStatus;
35
+ entry: EgressEntry;
36
+ /** True when this call asked the network (not the cache). */
37
+ fresh: boolean;
38
+ /** True when this call saw the address change. */
39
+ ipChanged: boolean;
40
+ }
41
+ type Env = Record<string, string | undefined>;
42
+ export type TraceFetcher = (url: string, env: Env, timeoutMs: number) => Promise<string>;
43
+ /** The proxy a request to `url` goes through under `env`, or null for a direct connection. */
44
+ export declare function proxyFor(url: string, env: Env): string | null;
45
+ /** The key a cached result is kept under: the URL and the proxy settings, never their values in clear. */
46
+ export declare function cacheKey(url: string, env: Env): string;
47
+ /** A hash of the machine's own network addresses; it changes with Wi-Fi, a VPN or a TUN device. */
48
+ export declare function netPrint(read?: typeof networkInterfaces): string;
49
+ export declare function parseTrace(text: string): {
50
+ ip?: string;
51
+ loc?: string;
52
+ };
53
+ /** One GET of `url`, directly or through an `http://` proxy (CONNECT), as the Host would send it. */
54
+ export declare const fetchTrace: TraceFetcher;
55
+ export declare function readEntry(dir: string, key: string): Promise<EgressEntry | null>;
56
+ /** Whether `loc` passes `allow`; without a country the check could not tell. */
57
+ export declare function judge(entry: EgressEntry, allow: readonly string[]): EgressStatus;
58
+ /**
59
+ * What to do with a cached result at `moment` (spec §3.35): use it, use it and refresh in the background
60
+ * (tool calls only), or check now.
61
+ */
62
+ export declare function plan(entry: EgressEntry | null, allow: readonly string[], moment: CheckMoment, now: number, print: string): 'use' | 'refresh' | 'check';
63
+ /** Asks the network once and keeps the answer (spec §3.35); never throws. */
64
+ export declare function refresh(opts: {
65
+ url: string;
66
+ env: Env;
67
+ dir: string;
68
+ now?: () => Date;
69
+ fetcher?: TraceFetcher;
70
+ print?: string;
71
+ }): Promise<{
72
+ entry: EgressEntry;
73
+ ipChanged: boolean;
74
+ }>;
75
+ /**
76
+ * The verdict at `moment`: from the cache when it is young enough, else from one request. `background` starts a
77
+ * detached refresh for the tool-call middle tier; without it that tier checks now.
78
+ */
79
+ export declare function verdict(opts: {
80
+ url: string;
81
+ env: Env;
82
+ allow: readonly string[];
83
+ dir: string;
84
+ moment: CheckMoment;
85
+ now?: () => Date;
86
+ fetcher?: TraceFetcher;
87
+ print?: string;
88
+ background?: () => void;
89
+ }): Promise<Verdict>;
90
+ /** "香港(HK)" or "HK": a country for a sentence. */
91
+ export declare function countryLabel(code: string, zh: boolean): string;
92
+ /** Whether messages for a hook or a terminal should be Chinese: the user's locale says so. */
93
+ export declare function prefersChinese(env: Env): boolean;
94
+ /**
95
+ * What the user reads when Network Guard stops something (spec §3.35): what happened, why, what to do.
96
+ * `at`: `prompt`/`tool` inside a session, `launch` before one.
97
+ */
98
+ export declare function blockMessage(v: Pick<Verdict, 'status' | 'entry'>, allow: readonly string[], opts: {
99
+ ref?: string;
100
+ at: CheckMoment;
101
+ zh: boolean;
102
+ }): string;
103
+ export {};