sideby 0.43.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 (52) 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 +58 -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/file-memo.d.ts +2 -0
  9. package/dist/src/core/file-memo.js +20 -0
  10. package/dist/src/core/handoff.d.ts +9 -0
  11. package/dist/src/core/handoff.js +10 -0
  12. package/dist/src/core/history.d.ts +1 -1
  13. package/dist/src/core/history.js +2 -2
  14. package/dist/src/core/memo-store.js +32 -8
  15. package/dist/src/core/network.d.ts +5 -35
  16. package/dist/src/core/network.js +18 -54
  17. package/dist/src/core/themes.js +0 -7
  18. package/dist/src/core/update.d.ts +1 -1
  19. package/dist/src/core/update.js +4 -12
  20. package/dist/src/families/claude/quota-fetch.js +2 -2
  21. package/dist/src/families/claude/tuning.d.ts +0 -1
  22. package/dist/src/families/claude/tuning.js +1 -1
  23. package/dist/src/families/quota-watch.d.ts +12 -0
  24. package/dist/src/families/quota-watch.js +24 -0
  25. package/dist/src/network/hook.js +1 -1
  26. package/dist/src/network/page.d.ts +1 -1
  27. package/dist/src/network/page.js +15 -181
  28. package/dist/src/panel/changes.d.ts +57 -0
  29. package/dist/src/panel/changes.js +178 -0
  30. package/dist/src/panel/handler.d.ts +38 -0
  31. package/dist/src/panel/handler.js +263 -93
  32. package/dist/src/panel/i18n.d.ts +23 -0
  33. package/dist/src/panel/i18n.js +46 -0
  34. package/dist/src/panel/page-logic.d.ts +22 -29
  35. package/dist/src/panel/page-logic.js +22 -33
  36. package/dist/src/panel/page-script.js +114 -45
  37. package/dist/src/panel/page-styles.js +26 -26
  38. package/dist/src/panel/page.js +3 -1
  39. package/dist/src/quota/claude-statusline.js +1 -1
  40. package/dist/src/runtime.d.ts +13 -1
  41. package/dist/src/runtime.js +14 -8
  42. package/dist/src/types.d.ts +2 -2
  43. package/dist/src/unattended/hook.js +0 -1
  44. package/dist/testing/index.js +1 -1
  45. package/package.json +2 -1
  46. package/schemas/network-diagnose.json +239 -0
  47. package/schemas/next.json +25 -0
  48. package/skills/sideby/SKILL.md +2 -2
  49. package/skills/sideby/references/handoff.md +2 -0
  50. package/skills/sideby/references/network.md +5 -3
  51. package/dist/src/network/page-script.d.ts +0 -40
  52. package/dist/src/network/page-script.js +0 -270
@@ -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.43.0"
5
+ version: "0.45.0"
6
6
  requires:
7
7
  bins: [sideby, node]
8
8
  cliHelp: sideby --help
@@ -63,7 +63,7 @@ Account refs are `<family>:<name>`; a bare `<name>` works only when it is unique
63
63
  | Turn Auto Update on or off | `sideby update --auto on|off --json` | `references/update.md` |
64
64
  | Switch between a local build of sideby and the release ("切换到正式版", "切回 dev 版本") | `sideby local --json`, `sideby local on|off --json` (exits 10 first) | `references/update.md` |
65
65
  | Repair drift or permissions | `sideby doctor [ref] --json`, then `--fix` after they agree | `references/diagnose.md` |
66
- | Keep working because an account hit its limit | `sideby next <family> --json` | `references/handoff.md` |
66
+ | Keep working because an account hit its limit, or which account to use now ("现在该用哪个账号") | `sideby next <family> --json` | `references/handoff.md` |
67
67
  | Turn on Auto Handoff ("自动接力", "自动交接", "hand over when quota runs low"), see what it still needs, hand this session over now, or pick an account with room for a subtask | `sideby handoff status --json`, `sideby handoff enable --json` (exit 10 first), `sideby handoff ready`, `sideby next <family> --json` | `references/handoff.md` |
68
68
  | Explain or change the handoff rules ("接力规则", "什么时候换号", "让 Codex 接 Claude", "别用 API 账号接力") | `sideby handoff rules --json`, `sideby config set handoff.<key> <value>` or `sideby handoff enable --other-ai/--api --json` (exit 10 first) | `references/handoff.md` |
69
69
  | Sign an account in again or switch it to another login ("换个账号登录", "两个目录登录的是同一个号", "sign claude:work in with another account") | `sideby list --json` (`identity`, `sameLogin`), then give the user `sideby login <ref>` | `references/accounts.md` |
@@ -21,6 +21,8 @@ Use this when the user says an account hit its 5-hour or weekly limit ("usage li
21
21
 
22
22
  The two limits differ because one full 5-hour window costs only about a fifth of a week: a week at 87% is still `ready` and yellow, not red. When the user asks why such an account was picked, say that.
23
23
 
24
+ Each entry's `windows` lists every counted window not reset yet (`label`, `usedPercent`, `resetsAt`): say what is left in each, such as "claude:002 has 72% of its 5-hour window and 40% of its week left". The Panel's top line, **Best to use now**, shows the same pick and numbers for one tool and starts it on a click; point a user who is not in a terminal there.
25
+
24
26
  Each entry's `observedAt` says when its quota was recorded (`quotaFrom` when it was read from another account of the same login). An entry with `sameLoginAs` is signed in as the same login as the account you run in: it shares that quota and is never picked. If `hasQuota` is `false`, no account has quota data: the pick is only a guess, so say so and suggest turning quota on (see the routing table in SKILL.md) or letting the user choose.
25
27
  3. Give the user the command to run in their own terminal: `sideby next <family>` (starts the pick) or `sideby run <pick>`. Host arguments go after `--`. Do not run it yourself.
26
28
  4. Offer a handoff note: the new session starts empty, because each account keeps its own sessions. Write a short note the user can paste into it: the goal, what is done, what is in progress, the files involved, and the next step.
@@ -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
- `;