sideby 0.42.1 → 0.43.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 (58) hide show
  1. package/ai-tasks.json +10 -0
  2. package/dist/build.json +1 -1
  3. package/dist/src/cli/commands.js +63 -13
  4. package/dist/src/cli/json-schemas.js +58 -1
  5. package/dist/src/cli/main.js +11 -4
  6. package/dist/src/core/ask.d.ts +8 -14
  7. package/dist/src/core/ask.js +66 -30
  8. package/dist/src/core/egress.d.ts +5 -0
  9. package/dist/src/core/egress.js +32 -2
  10. package/dist/src/core/handoff-run.js +41 -8
  11. package/dist/src/core/handoff-select.d.ts +5 -0
  12. package/dist/src/core/handoff-select.js +1 -1
  13. package/dist/src/core/handoff.d.ts +69 -1
  14. package/dist/src/core/handoff.js +90 -9
  15. package/dist/src/core/history-index.d.ts +4 -0
  16. package/dist/src/core/history-index.js +1 -1
  17. package/dist/src/core/live-sessions.d.ts +5 -0
  18. package/dist/src/core/live-sessions.js +12 -1
  19. package/dist/src/core/network.d.ts +37 -0
  20. package/dist/src/core/network.js +65 -1
  21. package/dist/src/core/pick-commands.d.ts +7 -1
  22. package/dist/src/core/pick-commands.js +15 -3
  23. package/dist/src/core/pick-records.d.ts +26 -0
  24. package/dist/src/core/pick-records.js +81 -0
  25. package/dist/src/families/agy/history.d.ts +2 -0
  26. package/dist/src/families/agy/history.js +118 -0
  27. package/dist/src/families/agy/index.js +5 -0
  28. package/dist/src/families/agy/quota.d.ts +5 -1
  29. package/dist/src/families/agy/quota.js +111 -10
  30. package/dist/src/families/history.js +2 -1
  31. package/dist/src/network/hook.js +4 -4
  32. package/dist/src/network/page-script.d.ts +40 -0
  33. package/dist/src/network/page-script.js +270 -0
  34. package/dist/src/network/page.d.ts +11 -0
  35. package/dist/src/network/page.js +189 -0
  36. package/dist/src/network/panel.d.ts +5 -0
  37. package/dist/src/network/panel.js +7 -0
  38. package/dist/src/panel/handler.d.ts +21 -1
  39. package/dist/src/panel/handler.js +174 -37
  40. package/dist/src/panel/i18n.d.ts +26 -0
  41. package/dist/src/panel/i18n.js +54 -2
  42. package/dist/src/panel/page-logic.d.ts +26 -3
  43. package/dist/src/panel/page-logic.js +95 -12
  44. package/dist/src/panel/page-script.js +86 -17
  45. package/dist/src/panel/page-styles.js +1 -0
  46. package/dist/src/runtime.d.ts +58 -5
  47. package/dist/src/runtime.js +121 -13
  48. package/dist/src/types.d.ts +3 -2
  49. package/package.json +1 -1
  50. package/schemas/network-diagnose.json +196 -0
  51. package/schemas/next.json +42 -2
  52. package/skills/sideby/SKILL.md +3 -2
  53. package/skills/sideby/references/accounts.md +1 -1
  54. package/skills/sideby/references/ai-tasks.md +1 -1
  55. package/skills/sideby/references/handoff.md +4 -2
  56. package/skills/sideby/references/network.md +6 -1
  57. package/skills/sideby/references/quota.md +1 -1
  58. package/skills/sideby/references/sessions.md +1 -1
@@ -0,0 +1,270 @@
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
+ `;
@@ -0,0 +1,11 @@
1
+ import { type ResolvedTheme } from '../panel/theme.ts';
2
+ export interface NetworkPageOptions {
3
+ basePath: string;
4
+ token: string;
5
+ nonce?: string;
6
+ version?: string;
7
+ theme?: ResolvedTheme;
8
+ lang?: 'auto' | 'en' | 'zh';
9
+ }
10
+ /** The network view never embeds account state; the browser obtains only its token and fixed UI metadata. */
11
+ export declare function renderNetworkPage(opts: NetworkPageOptions): string;
@@ -0,0 +1,189 @@
1
+ // Self-contained Network Panel document, using the existing Panel tokens and Content Security Policy.
2
+ import { MARK_IMG } from '../core/brand-mark.js';
3
+ import { FAVICON_VERSION, jsonForScript } from '../panel/page.js';
4
+ import { pageStyles } from '../panel/page-styles.js';
5
+ import { resolveTheme } from '../panel/theme.js';
6
+ import { NETWORK_PAGE_SCRIPT } from './page-script.js';
7
+ const MESSAGES = {
8
+ en: {
9
+ title: 'Network connection',
10
+ tagline: 'Routes and local listeners visible to this Panel.',
11
+ intro: 'See the selected direct or redacted proxy route, its loopback TCP listener, and the cached Network Guard result for each target.',
12
+ scope: 'These facts come from this Panel process environment. Older sessions keep their own environment; run the sideby CLI in that terminal to diagnose them.',
13
+ notCovered: 'This Panel does not read or change WARP, DNS, macOS system proxy, or any other network setting.',
14
+ diagnose: 'Diagnose connection',
15
+ diagnoseAgain: 'Diagnose again',
16
+ diagnosing: 'Diagnosing…',
17
+ loading: 'Running an offline diagnosis. No online trace is sent; a slow local TCP probe may take a moment.',
18
+ diagnoseFailed: 'Diagnosis failed: {message}',
19
+ checkedAt: 'Offline diagnosis at {when}. Cached Guard results have their own timestamps below.',
20
+ empty: 'No guarded targets were found. Add or sign in to an account before diagnosing its route.',
21
+ route: 'Selected route',
22
+ direct: 'Direct connection; there is no proxy listener to test.',
23
+ noListener: 'No loopback TCP probe: the proxy is remote, invalid, or has no explicit port for this protocol.',
24
+ listenerUp: 'Loopback TCP listener reachable at {host}:{port}.',
25
+ listenerDown: 'Loopback TCP listener not reachable at {host}:{port} ({error}).',
26
+ failed: 'failed',
27
+ tcpLimit: 'A reachable TCP listener does not prove that HTTP CONNECT, SOCKS, TLS, or upstream connectivity works.',
28
+ 'support.direct': 'Direct',
29
+ 'support.http-connect': 'HTTP CONNECT',
30
+ 'support.unsupported': 'Unsupported proxy',
31
+ 'support.invalid': 'Invalid proxy',
32
+ unsupported: 'Network Guard does not support this SOCKS or non-HTTP proxy route. Use HTTP CONNECT or direct before an online Guard check.',
33
+ invalid: 'The proxy address is invalid. Correct the environment and start a new session.',
34
+ 'guard.ok': 'Cached Guard: allowed',
35
+ 'guard.blocked': 'Cached Guard: blocked',
36
+ 'guard.unknown': 'Cached Guard: unknown',
37
+ 'guard.not-checked': 'Cached Guard: not checked',
38
+ guardChecked: 'Guard checked {when}',
39
+ guardNever: 'Guard has no cached check',
40
+ ask: 'Let AI diagnose',
41
+ fixedOnly: 'This fixed task contains only the current diagnostic facts above. No free text, attachments, account details, or other context is included.',
42
+ actualPrompt: 'Exact prompt to send',
43
+ promptLoading: 'Preparing the actual prompt…',
44
+ promptChanged: 'The prompt changed. Review the new prompt and confirm again; nothing was opened.',
45
+ confirm: 'Open in Orca',
46
+ checkingPrompt: 'Checking prompt again…',
47
+ cancel: 'Cancel',
48
+ close: 'Close',
49
+ opened: 'Orca was asked to open the diagnosis.',
50
+ copyFallback: 'Orca could not be opened. Copy this command and run it in a terminal.',
51
+ copy: 'Copy command',
52
+ command: 'AI diagnosis command',
53
+ requestFailed: 'Request failed ({status})',
54
+ },
55
+ zh: {
56
+ title: '网络连接',
57
+ tagline: '查看此 Panel 能读取的路由和本地 listener。',
58
+ intro: '逐个 target 查看直连或脱敏代理路由、loopback TCP listener,以及缓存的 Network Guard 结果。',
59
+ scope: '这些信息来自当前 Panel 进程的环境。旧会话保留自己的环境;请在对应终端运行 sideby CLI 诊断。',
60
+ notCovered: '此 Panel 不读取或修改 WARP、DNS、macOS 系统代理及任何其他网络设置。',
61
+ diagnose: '诊断连接',
62
+ diagnoseAgain: '重新诊断',
63
+ diagnosing: '正在诊断…',
64
+ loading: '正在离线诊断,不会发送在线 trace。本地 TCP 探测较慢时需要稍等。',
65
+ diagnoseFailed: '诊断失败:{message}',
66
+ checkedAt: '离线诊断时间:{when}。缓存的 Guard 结果在下方单独标注时间。',
67
+ empty: '没有找到受 Guard 管理的 target。请先添加或登录账号,再诊断它的路由。',
68
+ route: '本次选择的路由',
69
+ direct: '直连,没有代理 listener 要测试。',
70
+ noListener: '未探测 loopback TCP:代理在远程、地址无效,或该协议没有明确端口。',
71
+ listenerUp: 'loopback TCP listener 可连接:{host}:{port}。',
72
+ listenerDown: 'loopback TCP listener 连不上:{host}:{port}({error})。',
73
+ failed: '失败',
74
+ tcpLimit: 'TCP 能连接不代表 HTTP CONNECT、SOCKS、TLS 或上游网络可用。',
75
+ 'support.direct': '直连',
76
+ 'support.http-connect': 'HTTP CONNECT',
77
+ 'support.unsupported': '不支持的代理',
78
+ 'support.invalid': '代理地址无效',
79
+ unsupported: 'Network Guard 不支持此 SOCKS 或非 HTTP 代理路由。在线 Guard 检查前,请改用 HTTP CONNECT 或直连。',
80
+ invalid: '代理地址无效。请修正环境变量,再新开会话。',
81
+ 'guard.ok': '缓存 Guard:允许',
82
+ 'guard.blocked': '缓存 Guard:阻止',
83
+ 'guard.unknown': '缓存 Guard:未知',
84
+ 'guard.not-checked': '缓存 Guard:未检查',
85
+ guardChecked: 'Guard 检查于 {when}',
86
+ guardNever: 'Guard 没有缓存检查',
87
+ ask: '让 AI 诊断',
88
+ fixedOnly: '固定任务只包含上方当前诊断 facts,不含自由文本、附件、账号详情或其他 context。',
89
+ actualPrompt: '将发送的完整提示词',
90
+ promptLoading: '正在生成实际提示词…',
91
+ promptChanged: '提示词有变化。请查看新提示词后再次确认;这次没有打开终端。',
92
+ confirm: '在 Orca 中打开',
93
+ checkingPrompt: '正在再次核对提示词…',
94
+ cancel: '取消',
95
+ close: '关闭',
96
+ opened: '已请求 Orca 打开诊断任务。',
97
+ copyFallback: '无法打开 Orca。请复制此命令到终端运行。',
98
+ copy: '复制命令',
99
+ command: 'AI 诊断命令',
100
+ requestFailed: '请求失败({status})',
101
+ },
102
+ };
103
+ const CSS = `
104
+ .network-main { min-width: 0; }
105
+ .network-hero { margin-bottom: 20px; }
106
+ .network-hero h2 { font-size: var(--title-size); font-weight: var(--title-weight); margin-bottom: 8px; }
107
+ .network-hero p { max-width: 760px; color: var(--muted); overflow-wrap: anywhere; }
108
+ .network-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 12px; }
109
+ .network-notes { display: grid; gap: 8px; margin: 16px 0 20px; }
110
+ .network-notes p { overflow-wrap: anywhere; }
111
+ #targets { display: grid; gap: 12px; min-width: 0; }
112
+ .net-target { min-width: 0; display: grid; gap: 10px; overflow: hidden; }
113
+ .net-target-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; min-width: 0; }
114
+ .net-target h3 { min-width: 0; font-size: var(--heading-size); overflow-wrap: anywhere; }
115
+ .net-target .chip { flex: none; max-width: 100%; white-space: normal; text-align: center; }
116
+ .net-route { min-width: 0; overflow-wrap: anywhere; }
117
+ .net-route code { overflow-wrap: anywhere; }
118
+ .net-ok { color: var(--ok); }
119
+ .net-target .note { display: block; overflow-wrap: anywhere; }
120
+ .net-placeholder { min-height: 120px; }
121
+ .net-empty { color: var(--muted); }
122
+ .net-prompt { white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; max-width: 100%; max-height: 320px; overflow: auto; margin: 0; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-2); font: 12px/1.55 var(--mono); }
123
+ .net-command { width: 100%; min-height: 64px; resize: vertical; background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); border-radius: var(--radius-md); font: 12px var(--mono); }
124
+ @media (max-width: 520px) {
125
+ :root { --gutter: 16px; }
126
+ .network-top .top-in { padding-top: 20px; }
127
+ .network-top .tagline { font-size: var(--small); }
128
+ .net-target { padding: 16px; }
129
+ .net-target-head { flex-direction: column; gap: 8px; }
130
+ .network-actions .btn { flex: 1 1 auto; white-space: normal; min-height: var(--ctl-h); height: auto; padding-top: 8px; padding-bottom: 8px; }
131
+ .dlg-head, .dlg-body { padding-left: 16px; padding-right: 16px; }
132
+ .dlg-foot { padding-left: 16px; padding-right: 16px; flex-wrap: wrap; }
133
+ }
134
+ `;
135
+ /** The network view never embeds account state; the browser obtains only its token and fixed UI metadata. */
136
+ export function renderNetworkPage(opts) {
137
+ const nonce = opts.nonce
138
+ ? ` nonce="${opts.nonce.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/</g, '&lt;')}"`
139
+ : '';
140
+ const theme = opts.theme ?? resolveTheme(undefined);
141
+ const scheme = theme.colorScheme === 'auto' ? 'light dark' : theme.colorScheme;
142
+ const lang = opts.lang ?? 'auto';
143
+ const boot = jsonForScript({
144
+ basePath: opts.basePath,
145
+ token: opts.token,
146
+ version: opts.version ?? '',
147
+ lang,
148
+ });
149
+ return `<!doctype html>
150
+ <html lang="${lang === 'zh' ? 'zh-CN' : 'en'}">
151
+ <head>
152
+ <meta charset="utf-8">
153
+ <meta name="viewport" content="width=device-width, initial-scale=1">
154
+ <meta name="color-scheme" content="${scheme}">
155
+ <meta name="referrer" content="no-referrer">
156
+ <title>Network connection</title>
157
+ <link rel="icon" type="image/svg+xml" href="${opts.basePath}/favicon.svg?v=${FAVICON_VERSION}">
158
+ <style${nonce}>${pageStyles(theme)}${CSS}</style>
159
+ </head>
160
+ <body${theme.header === 'bar' ? ' class="header-bar"' : ''}>
161
+ <header class="top network-top">
162
+ <div class="top-in">
163
+ <div class="brand"><span class="logo" aria-hidden="true">${MARK_IMG}</span><div><h1>sideby</h1><p id="tagline" class="tagline">Routes and local listeners visible to this Panel.</p></div></div>
164
+ <div class="top-actions"><button id="language" class="btn" type="button"${lang === 'auto' ? '' : ' hidden'}>中文</button></div>
165
+ </div>
166
+ </header>
167
+ <main class="wrap network-main">
168
+ <section class="network-hero" aria-labelledby="title">
169
+ <h2 id="title">Network connection</h2>
170
+ <p id="intro">See the selected direct or redacted proxy route, its loopback TCP listener, and the cached Network Guard result for each target.</p>
171
+ <div class="network-actions"><button id="diagnose" class="btn btn-primary" type="button" aria-busy="true">Diagnosing…</button><button id="ask-open" class="btn" type="button" aria-haspopup="dialog" hidden>Let AI diagnose</button></div>
172
+ <div id="status"><p class="note" role="status">Running an offline diagnosis. No online trace is sent.</p></div>
173
+ </section>
174
+ <section class="network-notes" aria-label="Scope"><p id="scope" class="note"></p><p id="not-covered" class="small muted"></p></section>
175
+ <div id="targets" aria-live="polite" aria-busy="true"><div class="panel net-placeholder"><span class="sk sk-line w70"></span><span class="sk sk-line w50"></span></div></div>
176
+ <p id="tcp-limit" class="small muted network-notes"></p>
177
+ <footer class="foot muted small">sideby</footer>
178
+ </main>
179
+ <dialog id="ask-dialog" class="dialog dialog-wide" aria-labelledby="ask-title">
180
+ <div class="dlg-head"><h2 id="ask-title">Let AI diagnose</h2></div>
181
+ <div id="ask-body" class="dlg-body"></div>
182
+ <div class="dlg-foot"><button id="ask-cancel" class="btn" type="button">Cancel</button><button id="ask-confirm" class="btn btn-primary" type="button" disabled>Open in Orca</button></div>
183
+ </dialog>
184
+ <script type="application/json" id="sideby-boot"${nonce}>${boot}</script>
185
+ <script type="application/json" id="network-i18n"${nonce}>${jsonForScript(MESSAGES)}</script>
186
+ <script${nonce}>const BOOT = JSON.parse(document.getElementById('sideby-boot').textContent); const MESSAGES = JSON.parse(document.getElementById('network-i18n').textContent);${NETWORK_PAGE_SCRIPT}</script>
187
+ </body>
188
+ </html>`;
189
+ }
@@ -0,0 +1,5 @@
1
+ import { type PanelHandlerOptions } from '../panel/handler.ts';
2
+ export type NetworkPanelHandlerOptions = PanelHandlerOptions;
3
+ export declare function createPanelHandler(options: NetworkPanelHandlerOptions): import("../panel/handler.ts").PanelHandler;
4
+ export { createRuntime } from '../runtime.ts';
5
+ export { renderNetworkPage } from './page.ts';
@@ -0,0 +1,7 @@
1
+ // Portal `kind: "panel"` entry for the independent Network view. It reuses the Panel's HTTP security and Runtime.
2
+ import { createPanelHandler as createBasePanelHandler, PANEL_VIEW, } from '../panel/handler.js';
3
+ export function createPanelHandler(options) {
4
+ return createBasePanelHandler({ ...options, [PANEL_VIEW]: 'network' });
5
+ }
6
+ export { createRuntime } from '../runtime.js';
7
+ export { renderNetworkPage } from './page.js';
@@ -4,6 +4,7 @@ import { type AppProfileStatus } from '../core/app-profiles.ts';
4
4
  import { type AutostartContext, type AutostartStatus } from '../core/autostart.ts';
5
5
  import { type BrowserReport } from '../core/browser-profiles.ts';
6
6
  import { type DisplayConfig, type EditorChoice, type HandoffSettings, type PanelConfig } from '../core/config.ts';
7
+ import { type HandoffPlan, type PickRecord } from '../core/handoff.ts';
7
8
  import { type InboundGroup } from '../core/inbound.ts';
8
9
  import { type LiveSession, type LiveSessionsResult, sessionCopyText } from '../core/live-sessions.ts';
9
10
  import { listMessages, type MessageReceipt, sendMessage } from '../core/messages.ts';
@@ -77,6 +78,11 @@ export interface PanelHandlerOptions {
77
78
  * does not export it); it may change without notice.
78
79
  */
79
80
  export declare const LIVE_SESSIONS_SOURCE: unique symbol;
81
+ /**
82
+ * Internal: a property under this key of the handler options serves only the Network view (`src/network/panel.ts`).
83
+ * Not part of the Portal contract (`src/index.ts` does not export it); it may change without notice.
84
+ */
85
+ export declare const PANEL_VIEW: unique symbol;
80
86
  export interface LiveSessionsSource {
81
87
  list?: (rt: Runtime) => Promise<LiveSessionsResult>;
82
88
  copyText?: typeof sessionCopyText;
@@ -270,6 +276,13 @@ export interface PanelState {
270
276
  * at least two subscription Accounts, some Quota data and a pick; API Accounts are left out as in the CLI default.
271
277
  */
272
278
  handoff?: Record<string, string>;
279
+ /** Family → the Live Sessions of the login of its `handoff` pick, Pick Records included, when any (ADR-0083). */
280
+ handoffRunning?: Record<string, number>;
281
+ /**
282
+ * Family → why its `handoff` pick goes first: `expiring` or `room` under its limits (ADR-0083), `tight` past every
283
+ * limit (a Last Resort), `unknown` when it has no Quota data and the accounts with data are full.
284
+ */
285
+ handoffReason?: Record<string, 'expiring' | 'room' | 'tight' | 'unknown'>;
273
286
  /** Auto Handoff settings (spec §3.17) and the Families that can start one; readiness comes from /api/handoff/status. */
274
287
  autoHandoff: {
275
288
  settings: HandoffSettings;
@@ -390,8 +403,15 @@ export declare function autostartView(s: AutostartStatus, home: string): {
390
403
  missing?: string[] | undefined;
391
404
  loaded?: boolean | undefined;
392
405
  };
406
+ /** The Live Sessions and Pick Records a pick counts (ADR-0083). */
407
+ export interface PickLoad {
408
+ live: ReadonlyMap<string, number>;
409
+ picks: readonly PickRecord[];
410
+ }
393
411
  /** The `handoff` map of the Panel state, from the statuses and Quota already read for the page. */
394
- export declare function handoffByFamily(rt: Runtime, accounts: readonly PanelAccount[], now: Date): Record<string, string>;
412
+ export declare function handoffByFamily(rt: Runtime, accounts: readonly PanelAccount[], now: Date, load?: PickLoad): Record<string, string>;
413
+ /** The plan behind each pick of `handoffByFamily`, spread by Room per Session when `load` is given (ADR-0083). */
414
+ export declare function handoffPlans(rt: Runtime, accounts: readonly PanelAccount[], now: Date, load?: PickLoad): Record<string, HandoffPlan>;
395
415
  export type RemoteControlView = Omit<RemoteControlGroup, 'file'> & {
396
416
  file: string;
397
417
  };