sideby 0.44.0 → 0.45.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/dist/build.json +1 -1
  2. package/dist/src/cli/commands.d.ts +4 -0
  3. package/dist/src/cli/commands.js +9 -8
  4. package/dist/src/cli/json-schemas.js +51 -0
  5. package/dist/src/core/cli-commands.js +0 -10
  6. package/dist/src/core/egress.d.ts +1 -7
  7. package/dist/src/core/egress.js +7 -36
  8. package/dist/src/core/history.d.ts +1 -1
  9. package/dist/src/core/history.js +2 -2
  10. package/dist/src/core/network.d.ts +5 -35
  11. package/dist/src/core/network.js +18 -54
  12. package/dist/src/core/themes.js +0 -7
  13. package/dist/src/core/update.d.ts +1 -1
  14. package/dist/src/core/update.js +4 -12
  15. package/dist/src/families/claude/quota-fetch.js +2 -2
  16. package/dist/src/families/claude/tuning.d.ts +0 -1
  17. package/dist/src/families/claude/tuning.js +1 -1
  18. package/dist/src/network/hook.js +1 -1
  19. package/dist/src/network/page.d.ts +1 -1
  20. package/dist/src/network/page.js +15 -181
  21. package/dist/src/panel/handler.js +57 -25
  22. package/dist/src/panel/page-logic.d.ts +11 -29
  23. package/dist/src/panel/page-logic.js +11 -33
  24. package/dist/src/panel/page-script.js +5 -34
  25. package/dist/src/panel/page-styles.js +9 -18
  26. package/dist/src/quota/claude-statusline.js +1 -1
  27. package/dist/src/runtime.d.ts +2 -1
  28. package/dist/src/runtime.js +9 -6
  29. package/dist/src/types.d.ts +2 -2
  30. package/dist/src/unattended/hook.js +0 -1
  31. package/dist/testing/index.js +1 -1
  32. package/package.json +2 -1
  33. package/schemas/network-diagnose.json +239 -0
  34. package/skills/sideby/SKILL.md +1 -1
  35. package/skills/sideby/references/network.md +5 -3
  36. package/dist/src/network/page-script.d.ts +0 -40
  37. package/dist/src/network/page-script.js +0 -270
@@ -5,6 +5,8 @@
5
5
  "required": [
6
6
  "schemaVersion",
7
7
  "checkedAt",
8
+ "system",
9
+ "localProxyCandidates",
8
10
  "targets"
9
11
  ],
10
12
  "properties": {
@@ -16,6 +18,243 @@
16
18
  "type": "string",
17
19
  "description": "When this offline diagnosis ran (ISO), not the Guard cache time."
18
20
  },
21
+ "system": {
22
+ "type": "object",
23
+ "required": [
24
+ "warp",
25
+ "proxy",
26
+ "dns",
27
+ "route"
28
+ ],
29
+ "properties": {
30
+ "warp": {
31
+ "type": "object",
32
+ "required": [
33
+ "status",
34
+ "state"
35
+ ],
36
+ "properties": {
37
+ "status": {
38
+ "anyOf": [
39
+ {
40
+ "type": "string",
41
+ "const": "available"
42
+ },
43
+ {
44
+ "type": "string",
45
+ "const": "unavailable"
46
+ },
47
+ {
48
+ "type": "string",
49
+ "const": "error"
50
+ }
51
+ ]
52
+ },
53
+ "state": {
54
+ "anyOf": [
55
+ {
56
+ "type": "string",
57
+ "const": "connected"
58
+ },
59
+ {
60
+ "type": "string",
61
+ "const": "disconnected"
62
+ },
63
+ {
64
+ "type": "string",
65
+ "const": "unknown"
66
+ }
67
+ ]
68
+ },
69
+ "networkHealthy": {
70
+ "type": "boolean"
71
+ },
72
+ "error": {
73
+ "type": "string"
74
+ }
75
+ }
76
+ },
77
+ "proxy": {
78
+ "type": "object",
79
+ "required": [
80
+ "status",
81
+ "pacEnabled",
82
+ "autoDiscoveryEnabled",
83
+ "protocols"
84
+ ],
85
+ "properties": {
86
+ "status": {
87
+ "anyOf": [
88
+ {
89
+ "type": "string",
90
+ "const": "available"
91
+ },
92
+ {
93
+ "type": "string",
94
+ "const": "unavailable"
95
+ },
96
+ {
97
+ "type": "string",
98
+ "const": "error"
99
+ }
100
+ ]
101
+ },
102
+ "pacEnabled": {
103
+ "type": "boolean"
104
+ },
105
+ "autoDiscoveryEnabled": {
106
+ "type": "boolean"
107
+ },
108
+ "protocols": {
109
+ "type": "array",
110
+ "items": {
111
+ "type": "object",
112
+ "required": [
113
+ "protocol",
114
+ "enabled"
115
+ ],
116
+ "properties": {
117
+ "protocol": {
118
+ "anyOf": [
119
+ {
120
+ "type": "string",
121
+ "const": "http"
122
+ },
123
+ {
124
+ "type": "string",
125
+ "const": "https"
126
+ },
127
+ {
128
+ "type": "string",
129
+ "const": "socks"
130
+ }
131
+ ]
132
+ },
133
+ "enabled": {
134
+ "type": "boolean"
135
+ },
136
+ "host": {
137
+ "type": "string",
138
+ "description": "Loopback only; every other host is redacted."
139
+ },
140
+ "port": {
141
+ "type": "integer"
142
+ }
143
+ }
144
+ }
145
+ },
146
+ "exceptionCount": {
147
+ "type": "integer"
148
+ },
149
+ "error": {
150
+ "type": "string"
151
+ }
152
+ }
153
+ },
154
+ "dns": {
155
+ "type": "object",
156
+ "required": [
157
+ "status",
158
+ "nameservers"
159
+ ],
160
+ "properties": {
161
+ "status": {
162
+ "anyOf": [
163
+ {
164
+ "type": "string",
165
+ "const": "available"
166
+ },
167
+ {
168
+ "type": "string",
169
+ "const": "unavailable"
170
+ },
171
+ {
172
+ "type": "string",
173
+ "const": "error"
174
+ }
175
+ ]
176
+ },
177
+ "nameservers": {
178
+ "type": "array",
179
+ "items": {
180
+ "type": "string"
181
+ }
182
+ },
183
+ "error": {
184
+ "type": "string"
185
+ }
186
+ }
187
+ },
188
+ "route": {
189
+ "type": "object",
190
+ "required": [
191
+ "status"
192
+ ],
193
+ "properties": {
194
+ "status": {
195
+ "anyOf": [
196
+ {
197
+ "type": "string",
198
+ "const": "available"
199
+ },
200
+ {
201
+ "type": "string",
202
+ "const": "unavailable"
203
+ },
204
+ {
205
+ "type": "string",
206
+ "const": "error"
207
+ }
208
+ ]
209
+ },
210
+ "interface": {
211
+ "type": "string"
212
+ },
213
+ "gateway": {
214
+ "type": "string"
215
+ },
216
+ "error": {
217
+ "type": "string"
218
+ }
219
+ }
220
+ }
221
+ }
222
+ },
223
+ "localProxyCandidates": {
224
+ "type": "array",
225
+ "items": {
226
+ "type": "object",
227
+ "required": [
228
+ "label",
229
+ "protocol",
230
+ "host",
231
+ "port",
232
+ "reachable"
233
+ ],
234
+ "properties": {
235
+ "label": {
236
+ "type": "string",
237
+ "description": "The common configuration for this port, not an identified process."
238
+ },
239
+ "protocol": {
240
+ "type": "string"
241
+ },
242
+ "host": {
243
+ "type": "string"
244
+ },
245
+ "port": {
246
+ "type": "integer"
247
+ },
248
+ "reachable": {
249
+ "type": "boolean",
250
+ "description": "TCP connect only; not proof of upstream connectivity."
251
+ },
252
+ "error": {
253
+ "type": "string"
254
+ }
255
+ }
256
+ }
257
+ },
19
258
  "targets": {
20
259
  "type": "array",
21
260
  "items": {
@@ -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.44.0"
5
+ version: "0.45.0"
6
6
  requires:
7
7
  bins: [sideby, node]
8
8
  cliHelp: sideby --help
@@ -2,17 +2,19 @@
2
2
 
3
3
  Network Guard (spec §3.35, ADR-0053) checks the country a Host's requests leave from (its Egress): before sideby starts a Claude or Codex account, and before each prompt and tool call in a session sideby started. When the country is not one the user allows, or cannot be told, it stops and says what to do; inside a session it first asks again for up to about 30 seconds. It guards against a proxy that stopped or a node in the wrong country. It does not make use from a region the vendor does not support allowed; say so if the user seems to expect that, and never help hide where they are (time zone, fingerprints).
4
4
 
5
+ The reusable proxy, offline diagnosis, system probes, Network page/controller and fixed diagnostic facts live in https://github.com/Adonis0123/network-portal. sideby supplies Guard targets and cached status, and keeps its account model, Guard cache, fail-closed trace and hooks, Runtime, CLI, JSON schemas and Panel security/theme integration. The package does not read accounts, sideby config or the Guard cache.
6
+
5
7
  ## See where requests leave from
6
8
 
7
9
  ```sh
8
10
  sideby network --json # the setting and the newest result per address, from the cache (no request)
9
11
  sideby network check --json # ask every address now
10
- sideby network diagnose --json # offline route/listener/cache diagnosis (no trace)
12
+ sideby network diagnose --json # offline system/route/listener/cache diagnosis (no trace)
11
13
  ```
12
14
 
13
15
  Each `targets[]` row is one address sideby asks (`api.anthropic.com` for Claude, `chatgpt.com` for Codex) with `status` (`ok`, `blocked`, `unknown`, `not-checked`), `loc` (the country) and the `accounts` checked there. `accounts[].skip` says why an account is not checked: `api` (API accounts are never checked) or `third-party` (an endpoint set to a third party).
14
16
 
15
- `network diagnose` is read-only and sends no `/cdn-cgi/trace`. It reports the current process's selected proxy reduced to scheme, hostname and port (`direct` when none), a loopback TCP listener result, and the cached Guard state with its own `checkedAt`. It never resolves or connects to a remote proxy, and does not invent a port for a non-HTTP proxy that omitted one. Credentials, paths, queries and fragments are never returned or cached; the command also skips generic update and Unattended-ended notification side effects. This covers direct, HTTP and SOCKS settings from Clash, v2rayN or another proxy app without identifying or controlling the app. A reachable TCP listener does not prove HTTP CONNECT, SOCKS or upstream connectivity. `guardSupport: "unsupported"` means the current Guard cannot use that scheme: it supports HTTP CONNECT only. Tell the user to configure an HTTP proxy (v2rayN commonly exposes one separately from SOCKS) or direct connection; do not add a proxy protocol stack or switch the exit. Run `network check` only when the user wants a fresh online country result.
17
+ `network diagnose` is read-only and sends no `/cdn-cgi/trace`. In addition to the selected redacted process proxy, loopback listener and cached Guard state, its `system` facts report WARP state and Network health, macOS HTTP/HTTPS/SOCKS, PAC and automatic proxy discovery (`autoDiscoveryEnabled`) switches, the first default resolver's nameservers, and the default route. WARP Connected does not mean all traffic uses WARP. Non-loopback system proxy hosts are `redacted`; PAC URLs, exception names and DNS search domains are omitted. When a valid proxy dictionary provides no known Enable keys, including an empty `<dict>`/`<dictionary>` or one containing only other configuration keys, every known switch is off; provided switches are reported at their parsed values. Empty stdout or malformed output degrades that item to `invalid-output`, as do empty DNS and route results, instead of claiming everything is off or unconfigured. `localProxyCandidates` probes the common Clash/v2rayN ports 7897, 7890 and 10808: these labels do not identify a process, and TCP reachability does not prove the proxy protocol or upstream connectivity. Commands are fixed, offline, bounded and individually degraded; remote proxies are never resolved or connected, and no port is invented for a non-HTTP proxy that omitted one. Credentials, paths, queries and fragments are never returned or cached; the command also skips generic update and Unattended-ended notification side effects. `guardSupport: "unsupported"` means the current Guard cannot use that scheme: it supports HTTP CONNECT only. Tell the user to configure an HTTP proxy (v2rayN commonly exposes one separately from SOCKS) or direct connection; do not add a proxy protocol stack or switch the exit. Run `network check` only when the user wants a fresh online country result.
16
18
 
17
19
  ## Turn it on
18
20
 
@@ -35,7 +37,7 @@ Tell the user, once:
35
37
 
36
38
  The Panel's **Let AI help** (in the Network check dialog and on the wrong-network banner) starts the `network` AI Task (`sideby ask --task network`). Its prompt carries the switch, the allowed countries and the newest result per address (countries only, never an address). Follow it: run `sideby network check --json`, ask which countries, preview, then `--yes` after they agree.
37
39
 
38
- **Diagnose connection** in the same dialog is manual and offline. **Let AI diagnose** starts the separate fixed `network-diagnose` task with only current errors, the redacted route, listener results and Guard check times; `sideby ask --task network-diagnose` gathers the same facts itself. That task excludes generic account, health, quota, version and attachment context, removes URL userinfo before preview or task-file writing, and is read-only: explain the facts and next step, never install a skill, change network settings, configuration, code or files, switch the exit, or automatically run an online check. Do not mix it with the `network` settings task.
40
+ **Diagnose connection** in the same dialog is manual and offline. **Let AI diagnose** starts the separate fixed `network-diagnose` task with only current errors, safe system facts, local proxy candidates, the redacted route, listener results and Guard check times. On the standalone Network page and its routes, the task accepts only facts returned by this server's `/api/network/diagnose`, rejects client-added or replaced facts, and writes the exact server-generated confirmed prompt without generating it again. The Accounts dialog and `sideby ask --task network-diagnose` keep their original entry behavior: the CLI gathers the same facts itself, and neither uses the standalone page's server-side facts snapshot or `confirmedPrompt` contract. The task excludes generic account, health, quota, version and attachment context, removes URL userinfo before preview or task-file writing, and is read-only: explain the facts and next step, never install a skill, change network settings, configuration, code or files, switch the exit, or automatically run an online check. Do not mix it with the `network` settings task.
39
41
 
40
42
  ## When something was blocked
41
43
 
@@ -1,40 +0,0 @@
1
- import type { NetworkDiagnosis } from '../core/network.ts';
2
- import { networkDiagnoseTaskFacts } from '../panel/page-logic.ts';
3
- type Api = (path: string, body: Record<string, unknown>) => Promise<unknown>;
4
- type AskResult = {
5
- opened: boolean;
6
- command?: string | null;
7
- reason?: string;
8
- detail?: string;
9
- };
10
- type AskState = {
11
- body: Record<string, unknown>;
12
- prompt: string;
13
- loading: boolean;
14
- busy: boolean;
15
- promptChanged: boolean;
16
- error: string | null;
17
- result: AskResult | null;
18
- };
19
- /** One controller per document; a null Ask is a closed dialog and invalidates every pending continuation. */
20
- export declare function networkPageController(opts: {
21
- api: Api;
22
- facts?: typeof networkDiagnoseTaskFacts;
23
- version: string;
24
- lang: string;
25
- onChange?: () => void;
26
- }): {
27
- state: {
28
- diagnosis: NetworkDiagnosis | null;
29
- loading: boolean;
30
- error: string | null;
31
- ask: AskState | null;
32
- };
33
- start(): Promise<void>;
34
- diagnose(): Promise<void>;
35
- openAsk(): Promise<void>;
36
- closeAsk(): void;
37
- confirmAsk(): Promise<void>;
38
- };
39
- export declare const NETWORK_PAGE_SCRIPT: string;
40
- export {};
@@ -1,270 +0,0 @@
1
- import { networkDiagnoseTaskFacts } from '../panel/page-logic.js';
2
- /** One controller per document; a null Ask is a closed dialog and invalidates every pending continuation. */
3
- export function networkPageController(opts) {
4
- const facts = opts.facts ?? networkDiagnoseTaskFacts;
5
- const state = { diagnosis: null, loading: false, error: null, ask: null };
6
- let diagnosisRun = null;
7
- const changed = () => opts.onChange?.();
8
- const message = (err) => err?.message || String(err);
9
- return {
10
- state,
11
- async start() {
12
- return this.diagnose();
13
- },
14
- async diagnose() {
15
- if (diagnosisRun)
16
- return;
17
- const mine = {};
18
- diagnosisRun = mine;
19
- state.loading = true;
20
- state.error = null;
21
- changed();
22
- try {
23
- const result = (await opts.api('/api/network/diagnose', {}));
24
- if (diagnosisRun !== mine)
25
- return;
26
- state.diagnosis = result;
27
- }
28
- catch (err) {
29
- if (diagnosisRun !== mine)
30
- return;
31
- state.error = message(err);
32
- }
33
- finally {
34
- if (diagnosisRun === mine) {
35
- diagnosisRun = null;
36
- state.loading = false;
37
- changed();
38
- }
39
- }
40
- },
41
- async openAsk() {
42
- if (!state.diagnosis || state.ask)
43
- return;
44
- const ask = {
45
- body: {
46
- task: 'network-diagnose',
47
- lang: opts.lang,
48
- context: { networkDiagnose: facts(state.diagnosis), version: opts.version },
49
- },
50
- prompt: '',
51
- loading: true,
52
- busy: false,
53
- promptChanged: false,
54
- error: null,
55
- result: null,
56
- };
57
- state.ask = ask;
58
- changed();
59
- try {
60
- const preview = (await opts.api('/api/ask/prompt', ask.body));
61
- if (state.ask !== ask)
62
- return;
63
- ask.prompt = preview.prompt;
64
- ask.loading = false;
65
- changed();
66
- }
67
- catch (err) {
68
- if (state.ask !== ask)
69
- return;
70
- ask.error = message(err);
71
- ask.loading = false;
72
- changed();
73
- }
74
- },
75
- closeAsk() {
76
- state.ask = null;
77
- changed();
78
- },
79
- async confirmAsk() {
80
- const ask = state.ask;
81
- if (!ask || ask.loading || ask.busy || ask.result)
82
- return;
83
- ask.busy = true;
84
- ask.error = null;
85
- changed();
86
- try {
87
- // The body is identical to the preview's. A new preview always wins over this confirmation.
88
- const check = (await opts.api('/api/ask/prompt', ask.body));
89
- if (state.ask !== ask)
90
- return;
91
- if (check.prompt !== ask.prompt) {
92
- ask.prompt = check.prompt;
93
- ask.promptChanged = true;
94
- ask.busy = false;
95
- changed();
96
- return;
97
- }
98
- ask.promptChanged = false;
99
- const result = (await opts.api('/api/ask', ask.body));
100
- if (state.ask !== ask)
101
- return;
102
- ask.result = result;
103
- ask.busy = false;
104
- changed();
105
- }
106
- catch (err) {
107
- if (state.ask !== ask)
108
- return;
109
- ask.error = message(err);
110
- ask.busy = false;
111
- changed();
112
- }
113
- },
114
- };
115
- }
116
- export const NETWORK_PAGE_SCRIPT = `
117
- const createNetworkController = ${networkPageController.toString()};
118
- const factsForTask = ${networkDiagnoseTaskFacts.toString()};
119
- const $ = (id) => document.getElementById(id);
120
- function h(tag, attrs, ...children) {
121
- const el = document.createElement(tag);
122
- for (const [key, value] of Object.entries(attrs || {})) {
123
- if (value === null || value === undefined || value === false) continue;
124
- if (key.startsWith('on')) el.addEventListener(key.slice(2), value);
125
- else if (key === 'class') el.className = value;
126
- else if (key === 'text') el.textContent = value;
127
- else el.setAttribute(key, value === true ? '' : String(value));
128
- }
129
- for (const child of children.flat()) {
130
- if (child === null || child === undefined || child === false) continue;
131
- el.append(child && typeof child === 'object' ? child : document.createTextNode(String(child)));
132
- }
133
- return el;
134
- }
135
- let lang = BOOT.lang === 'auto' ? (navigator.language.toLowerCase().startsWith('zh') ? 'zh' : 'en') : BOOT.lang;
136
- const t = (key, vars = {}) => {
137
- let value = (MESSAGES[lang] && MESSAGES[lang][key]) || MESSAGES.en[key] || key;
138
- for (const [name, replacement] of Object.entries(vars)) value = value.split('{' + name + '}').join(String(replacement));
139
- return value;
140
- };
141
- let token = BOOT.token;
142
- async function api(path, body) {
143
- const send = async () => {
144
- const response = await fetch(BOOT.basePath + path, {
145
- method: 'POST',
146
- headers: { 'content-type': 'application/json', 'x-sideby-token': token },
147
- body: JSON.stringify(body),
148
- });
149
- const data = await response.json().catch(() => ({}));
150
- if (!response.ok) {
151
- const error = new Error(data.error || t('requestFailed', { status: response.status }));
152
- error.code = data.code;
153
- throw error;
154
- }
155
- return data;
156
- };
157
- try { return await send(); } catch (error) {
158
- if (error.code !== 'bad-token') throw error;
159
- const response = await fetch(BOOT.basePath + '/api/session');
160
- if (!response.ok) throw error;
161
- token = (await response.json()).token;
162
- return send();
163
- }
164
- }
165
- const dialog = $('ask-dialog');
166
- const controller = createNetworkController({
167
- api,
168
- facts: factsForTask,
169
- version: BOOT.version,
170
- get lang() { return lang; },
171
- onChange: render,
172
- });
173
- function clear(el) { while (el.firstChild) el.removeChild(el.firstChild); }
174
- function routeLabel(target) {
175
- return h('p', { class: 'net-route' }, h('span', { class: 'muted' }, t('route') + ': '), h('code', { text: target.proxy }));
176
- }
177
- function targetCard(target) {
178
- const listener = target.listener;
179
- const support = target.guardSupport;
180
- const guardBits = [t('guard.' + target.guard.status)];
181
- if (target.guard.loc) guardBits.push(target.guard.loc);
182
- guardBits.push(target.guard.checkedAt ? t('guardChecked', { when: target.guard.checkedAt }) : t('guardNever'));
183
- if (target.guard.error) guardBits.push(target.guard.error);
184
- return h('article', { class: 'panel net-target' },
185
- h('div', { class: 'net-target-head' }, h('h3', { text: target.url }), h('span', { class: 'chip', text: t('support.' + support) })),
186
- routeLabel(target),
187
- h('p', { class: listener && listener.reachable ? 'net-ok' : 'small muted', text: listener
188
- ? t(listener.reachable ? 'listenerUp' : 'listenerDown', { host: listener.host, port: listener.port, error: listener.error || t('failed') })
189
- : support === 'direct' ? t('direct') : t('noListener') }),
190
- h('p', { class: 'small muted', text: guardBits.join(' · ') }),
191
- support === 'unsupported' ? h('p', { class: 'note note-warn', text: t('unsupported') }) : null,
192
- support === 'invalid' ? h('p', { class: 'note note-warn', text: t('invalid') }) : null);
193
- }
194
- function renderMain() {
195
- document.documentElement.lang = lang === 'zh' ? 'zh-CN' : 'en';
196
- document.title = t('title');
197
- $('title').textContent = t('title');
198
- $('tagline').textContent = t('tagline');
199
- $('intro').textContent = t('intro');
200
- $('scope').textContent = t('scope');
201
- $('not-covered').textContent = t('notCovered');
202
- $('tcp-limit').textContent = t('tcpLimit');
203
- $('diagnose').textContent = controller.state.loading ? t('diagnosing') : controller.state.diagnosis ? t('diagnoseAgain') : t('diagnose');
204
- $('diagnose').disabled = controller.state.loading;
205
- $('diagnose').setAttribute('aria-busy', controller.state.loading ? 'true' : 'false');
206
- $('language').textContent = lang === 'zh' ? 'English' : '中文';
207
- $('language').hidden = BOOT.lang !== 'auto';
208
- const status = $('status');
209
- clear(status);
210
- if (controller.state.loading) status.append(h('p', { class: 'note', role: 'status', text: t('loading') }));
211
- else if (controller.state.error) status.append(h('p', { class: 'note note-fail', role: 'alert', text: t('diagnoseFailed', { message: controller.state.error }) }));
212
- else if (controller.state.diagnosis) status.append(h('p', { class: 'small muted', role: 'status', text: t('checkedAt', { when: controller.state.diagnosis.checkedAt }) }));
213
- const list = $('targets');
214
- const diagnosis = controller.state.diagnosis;
215
- list.setAttribute('aria-busy', controller.state.loading && !diagnosis ? 'true' : 'false');
216
- clear(list);
217
- if (controller.state.loading && !diagnosis) {
218
- list.append(h('div', { class: 'panel net-placeholder', 'aria-busy': 'true' }, h('span', { class: 'sk sk-line w70' }), h('span', { class: 'sk sk-line w50' })));
219
- } else if (diagnosis && !diagnosis.targets.length) {
220
- list.append(h('p', { class: 'panel net-empty', text: t('empty') }));
221
- } else if (diagnosis) {
222
- for (const target of diagnosis.targets) list.append(targetCard(target));
223
- }
224
- $('ask-open').hidden = !diagnosis;
225
- $('ask-open').textContent = t('ask');
226
- }
227
- function renderAsk() {
228
- const ask = controller.state.ask;
229
- if (!ask) {
230
- if (dialog.open) dialog.close();
231
- return;
232
- }
233
- if (!dialog.open) dialog.showModal();
234
- const body = $('ask-body');
235
- clear(body);
236
- $('ask-title').textContent = t('ask');
237
- body.append(h('p', { class: 'small muted', text: t('fixedOnly') }));
238
- if (ask.loading) body.append(h('p', { class: 'note', role: 'status', text: t('promptLoading') }));
239
- else {
240
- body.append(h('span', { class: 'small muted', text: t('actualPrompt') }));
241
- if (ask.promptChanged) body.append(h('p', { class: 'note note-warn', role: 'status', text: t('promptChanged') }));
242
- body.append(h('pre', { class: 'net-prompt', text: ask.prompt }));
243
- }
244
- if (ask.error) body.append(h('p', { class: 'note note-fail', role: 'alert', text: ask.error }));
245
- if (ask.result) {
246
- body.append(h('p', { class: ask.result.opened ? 'note note-ok' : 'note note-warn', role: 'status', text: ask.result.opened ? t('opened') : t('copyFallback') }));
247
- if (ask.result.command) {
248
- body.append(h('pre', { class: 'net-prompt', text: ask.result.command }));
249
- body.append(h('button', { class: 'btn', type: 'button', onclick: async () => {
250
- try { await navigator.clipboard.writeText(ask.result.command); } catch { $('command').value = ask.result.command; $('command').select(); }
251
- }, text: t('copy') }));
252
- body.append(h('textarea', { id: 'command', class: 'net-command', readonly: true, 'aria-label': t('command'), text: ask.result.command }));
253
- }
254
- }
255
- $('ask-confirm').hidden = Boolean(ask.result);
256
- $('ask-confirm').disabled = ask.loading || ask.busy || !ask.prompt;
257
- $('ask-confirm').textContent = ask.busy ? t('checkingPrompt') : t('confirm');
258
- $('ask-cancel').textContent = ask.result ? t('close') : t('cancel');
259
- }
260
- function render() { renderMain(); renderAsk(); }
261
- $('diagnose').addEventListener('click', () => controller.diagnose());
262
- $('ask-open').addEventListener('click', () => controller.openAsk());
263
- $('ask-confirm').addEventListener('click', () => controller.confirmAsk());
264
- $('ask-cancel').addEventListener('click', () => controller.closeAsk());
265
- dialog.addEventListener('close', () => { if (controller.state.ask) controller.closeAsk(); });
266
- dialog.addEventListener('cancel', () => controller.closeAsk());
267
- $('language').addEventListener('click', () => { lang = lang === 'zh' ? 'en' : 'zh'; render(); });
268
- render();
269
- void controller.start();
270
- `;