sideby 0.42.2 → 0.44.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.
- package/ai-tasks.json +10 -0
- package/dist/build.json +1 -1
- package/dist/src/cli/commands.js +54 -13
- package/dist/src/cli/json-schemas.js +65 -1
- package/dist/src/cli/main.js +11 -4
- package/dist/src/core/ask.d.ts +8 -14
- package/dist/src/core/ask.js +66 -30
- package/dist/src/core/egress.d.ts +5 -0
- package/dist/src/core/egress.js +32 -2
- package/dist/src/core/file-memo.d.ts +2 -0
- package/dist/src/core/file-memo.js +20 -0
- package/dist/src/core/handoff-run.js +41 -8
- package/dist/src/core/handoff-select.d.ts +5 -0
- package/dist/src/core/handoff-select.js +1 -1
- package/dist/src/core/handoff.d.ts +78 -1
- package/dist/src/core/handoff.js +100 -9
- package/dist/src/core/history-index.d.ts +4 -0
- package/dist/src/core/history-index.js +1 -1
- package/dist/src/core/live-sessions.d.ts +5 -0
- package/dist/src/core/live-sessions.js +12 -1
- package/dist/src/core/memo-store.js +32 -8
- package/dist/src/core/network.d.ts +37 -0
- package/dist/src/core/network.js +65 -1
- package/dist/src/core/pick-commands.d.ts +7 -1
- package/dist/src/core/pick-commands.js +15 -3
- package/dist/src/core/pick-records.d.ts +26 -0
- package/dist/src/core/pick-records.js +81 -0
- package/dist/src/families/agy/history.d.ts +2 -0
- package/dist/src/families/agy/history.js +118 -0
- package/dist/src/families/agy/index.js +5 -0
- package/dist/src/families/agy/quota.d.ts +5 -1
- package/dist/src/families/agy/quota.js +111 -10
- package/dist/src/families/history.js +2 -1
- package/dist/src/families/quota-watch.d.ts +12 -0
- package/dist/src/families/quota-watch.js +24 -0
- package/dist/src/network/hook.js +4 -4
- package/dist/src/network/page-script.d.ts +40 -0
- package/dist/src/network/page-script.js +270 -0
- package/dist/src/network/page.d.ts +11 -0
- package/dist/src/network/page.js +189 -0
- package/dist/src/network/panel.d.ts +5 -0
- package/dist/src/network/panel.js +7 -0
- package/dist/src/panel/changes.d.ts +57 -0
- package/dist/src/panel/changes.js +178 -0
- package/dist/src/panel/handler.d.ts +59 -1
- package/dist/src/panel/handler.js +374 -99
- package/dist/src/panel/i18n.d.ts +49 -0
- package/dist/src/panel/i18n.js +100 -2
- package/dist/src/panel/page-logic.d.ts +37 -3
- package/dist/src/panel/page-logic.js +106 -12
- package/dist/src/panel/page-script.js +194 -27
- package/dist/src/panel/page-styles.js +18 -8
- package/dist/src/panel/page.js +3 -1
- package/dist/src/runtime.d.ts +55 -5
- package/dist/src/runtime.js +105 -12
- package/dist/src/types.d.ts +3 -2
- package/package.json +1 -1
- package/schemas/network-diagnose.json +196 -0
- package/schemas/next.json +67 -2
- package/skills/sideby/SKILL.md +3 -2
- package/skills/sideby/references/accounts.md +1 -1
- package/skills/sideby/references/ai-tasks.md +1 -1
- package/skills/sideby/references/handoff.md +6 -2
- package/skills/sideby/references/network.md +6 -1
- package/skills/sideby/references/quota.md +1 -1
- package/skills/sideby/references/sessions.md +1 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Folders of built-in Families whose files change an Account's Quota or usage, for the Panel's change feed (spec
|
|
2
|
+
// §3.45, ADR-0084). Internal on purpose: not part of the public FamilyDef. Only file names are matched; nothing here
|
|
3
|
+
// is ever read.
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
const SESSION_GAP_MS = 5000;
|
|
6
|
+
const DIRS = {
|
|
7
|
+
// Quota (until a kept answer exists, `localFallbackOnly`) and usage from `token_count` events.
|
|
8
|
+
codex: (a) => [
|
|
9
|
+
{
|
|
10
|
+
dir: join(a.dir, 'sessions'),
|
|
11
|
+
recursive: true,
|
|
12
|
+
match: /(^|[\\/])rollout-[^\\/]*\.jsonl$/,
|
|
13
|
+
gapMs: SESSION_GAP_MS,
|
|
14
|
+
},
|
|
15
|
+
],
|
|
16
|
+
// The Quota Grok logs after each turn (ADR-0025).
|
|
17
|
+
grok: (a) => [
|
|
18
|
+
{ dir: join(a.dir, 'logs'), recursive: false, match: /^unified\.jsonl$/, gapMs: SESSION_GAP_MS },
|
|
19
|
+
],
|
|
20
|
+
};
|
|
21
|
+
/** The folders to watch for `accounts`. */
|
|
22
|
+
export function quotaWatchDirs(accounts) {
|
|
23
|
+
return accounts.flatMap((a) => (Object.hasOwn(DIRS, a.family) ? DIRS[a.family](a) : []));
|
|
24
|
+
}
|
package/dist/src/network/hook.js
CHANGED
|
@@ -9,7 +9,7 @@ import { spawn } from 'node:child_process';
|
|
|
9
9
|
import { lstat, readdir, unlink } from 'node:fs/promises';
|
|
10
10
|
import { join } from 'node:path';
|
|
11
11
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
12
|
-
import { blockMessage, inCi, judge, NETWORK_ENV, prefersChinese, readNetworkConfig, refresh, verdict, } from '../core/egress.js';
|
|
12
|
+
import { blockMessage, inCi, judge, NETWORK_ENV, prefersChinese, readNetworkConfig, refresh, routeLabel, verdict, } from '../core/egress.js';
|
|
13
13
|
import { ownedFolder, readSmallFile, sha256, writeFileAtomic } from '../core/fs-safe.js';
|
|
14
14
|
import { resolvePaths } from '../core/paths.js';
|
|
15
15
|
import { HELD_CLOSE, HELD_OPEN, hookWakeUp, hostMade } from '../core/prompt-origin.js';
|
|
@@ -249,14 +249,14 @@ export async function runNetworkHook(argv, env, err, deps = {}) {
|
|
|
249
249
|
return 0;
|
|
250
250
|
}
|
|
251
251
|
await decided('blocked');
|
|
252
|
-
err.write(`${blockMessage(v, allow, { ref: env.SIDEBY_LABEL || env.SIDEBY_ACCOUNT, at: moment, zh: prefersChinese(env) })}\n`);
|
|
252
|
+
err.write(`${blockMessage(v, allow, { ref: env.SIDEBY_LABEL || env.SIDEBY_ACCOUNT, at: moment, zh: prefersChinese(env), proxy: routeLabel(url, env) })}\n`);
|
|
253
253
|
return 2;
|
|
254
254
|
}
|
|
255
255
|
catch {
|
|
256
256
|
await decided('blocked');
|
|
257
257
|
err.write(`${prefersChinese(env)
|
|
258
|
-
?
|
|
259
|
-
:
|
|
258
|
+
? `已拦截:sideby 的网络检查出错,没能确认网络出口。本次检查使用${routeLabel(url, env) === 'direct' ? '直连(direct)' : `代理 \`${routeLabel(url, env)}\``}。重新发送试试;旧会话可能要重开才能继承新的代理环境;一直出错就运行 \`sideby network diagnose\`。`
|
|
259
|
+
: `Blocked: sideby's network check failed and could not tell this network's exit. This check used ${routeLabel(url, env) === 'direct' ? 'a direct connection (direct)' : `proxy \`${routeLabel(url, env)}\``}. Try again; an older session may need restarting to inherit a changed proxy environment; if it keeps failing, run \`sideby network diagnose\`.`}\n`);
|
|
260
260
|
return 2;
|
|
261
261
|
}
|
|
262
262
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
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 {};
|
|
@@ -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, '&').replace(/"/g, '"').replace(/</g, '<')}"`
|
|
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';
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export interface WatchDir {
|
|
2
|
+
dir: string;
|
|
3
|
+
recursive: boolean;
|
|
4
|
+
/** The changed name (relative to `dir`) that counts. An event without a name always counts. */
|
|
5
|
+
match: {
|
|
6
|
+
test(name: string): boolean;
|
|
7
|
+
};
|
|
8
|
+
/** At most one change every this many ms from this folder. */
|
|
9
|
+
gapMs: number;
|
|
10
|
+
}
|
|
11
|
+
/** What `GET /api/changes` answers. */
|
|
12
|
+
export interface ChangeAnswer {
|
|
13
|
+
seq: number;
|
|
14
|
+
/** The count differs from the `since` the page sent. */
|
|
15
|
+
changed: boolean;
|
|
16
|
+
/** Some folder is watched; false means the page keeps to its poll. */
|
|
17
|
+
watching: boolean;
|
|
18
|
+
}
|
|
19
|
+
/** How long after the first event a change counts: an atomic write (temporary file, then rename) counts once. */
|
|
20
|
+
export declare const GATHER_MS = 300;
|
|
21
|
+
/** How long a request with nothing new is held. */
|
|
22
|
+
export declare const HOLD_MS = 25000;
|
|
23
|
+
/** Watchers close this long after the last request: the page asks again at once, so only a gone page is this quiet. */
|
|
24
|
+
export declare const IDLE_MS = 40000;
|
|
25
|
+
/** `<state>/quota`: the status line cache and the kept answers of each Host's own CLI. */
|
|
26
|
+
export declare function stateQuotaDir(stateDir: string): WatchDir;
|
|
27
|
+
interface Timers {
|
|
28
|
+
now(): number;
|
|
29
|
+
set(fn: () => void, ms: number): unknown;
|
|
30
|
+
clear(t: unknown): void;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Turns events into counted changes: one `GATHER_MS` after the first event, and never sooner than `gapMs` (the
|
|
34
|
+
* event's folder) after the last one. Events meanwhile join that change; one whose folder allows an earlier time
|
|
35
|
+
* brings it forward.
|
|
36
|
+
*/
|
|
37
|
+
export declare function changeClock(fire: () => void, timers?: Timers): {
|
|
38
|
+
poke(gapMs: number): void;
|
|
39
|
+
stop(): void;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* The feed of one Panel. `dirs` lists what to watch; `onChange` runs once per counted change, before held requests
|
|
43
|
+
* are answered.
|
|
44
|
+
*/
|
|
45
|
+
export declare function createChangeFeed(opts: {
|
|
46
|
+
dirs: () => Promise<WatchDir[]>;
|
|
47
|
+
onChange?: () => void;
|
|
48
|
+
}): {
|
|
49
|
+
/**
|
|
50
|
+
* The answer for a page that last saw `since` (null: none yet). Held up to `HOLD_MS` while nothing changed, or
|
|
51
|
+
* until `gone` settles (the request closed).
|
|
52
|
+
*/
|
|
53
|
+
wait(since: number | null, gone: Promise<unknown>): Promise<ChangeAnswer>;
|
|
54
|
+
/** For tests: closes every watcher now. */
|
|
55
|
+
close: () => void;
|
|
56
|
+
};
|
|
57
|
+
export {};
|