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.
- package/dist/build.json +1 -1
- package/dist/src/cli/commands.d.ts +4 -0
- package/dist/src/cli/commands.js +9 -8
- package/dist/src/cli/json-schemas.js +58 -0
- package/dist/src/core/cli-commands.js +0 -10
- package/dist/src/core/egress.d.ts +1 -7
- package/dist/src/core/egress.js +7 -36
- package/dist/src/core/file-memo.d.ts +2 -0
- package/dist/src/core/file-memo.js +20 -0
- package/dist/src/core/handoff.d.ts +9 -0
- package/dist/src/core/handoff.js +10 -0
- package/dist/src/core/history.d.ts +1 -1
- package/dist/src/core/history.js +2 -2
- package/dist/src/core/memo-store.js +32 -8
- package/dist/src/core/network.d.ts +5 -35
- package/dist/src/core/network.js +18 -54
- package/dist/src/core/themes.js +0 -7
- package/dist/src/core/update.d.ts +1 -1
- package/dist/src/core/update.js +4 -12
- package/dist/src/families/claude/quota-fetch.js +2 -2
- package/dist/src/families/claude/tuning.d.ts +0 -1
- package/dist/src/families/claude/tuning.js +1 -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 +1 -1
- package/dist/src/network/page.d.ts +1 -1
- package/dist/src/network/page.js +15 -181
- package/dist/src/panel/changes.d.ts +57 -0
- package/dist/src/panel/changes.js +178 -0
- package/dist/src/panel/handler.d.ts +38 -0
- package/dist/src/panel/handler.js +263 -93
- package/dist/src/panel/i18n.d.ts +23 -0
- package/dist/src/panel/i18n.js +46 -0
- package/dist/src/panel/page-logic.d.ts +22 -29
- package/dist/src/panel/page-logic.js +22 -33
- package/dist/src/panel/page-script.js +114 -45
- package/dist/src/panel/page-styles.js +26 -26
- package/dist/src/panel/page.js +3 -1
- package/dist/src/quota/claude-statusline.js +1 -1
- package/dist/src/runtime.d.ts +13 -1
- package/dist/src/runtime.js +14 -8
- package/dist/src/types.d.ts +2 -2
- package/dist/src/unattended/hook.js +0 -1
- package/dist/testing/index.js +1 -1
- package/package.json +2 -1
- package/schemas/network-diagnose.json +239 -0
- package/schemas/next.json +25 -0
- package/skills/sideby/SKILL.md +2 -2
- package/skills/sideby/references/handoff.md +2 -0
- package/skills/sideby/references/network.md +5 -3
- package/dist/src/network/page-script.d.ts +0 -40
- package/dist/src/network/page-script.js +0 -270
package/dist/src/core/network.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
// Network Guard (spec §3.35, ADR-0053): which address each Account's Egress is checked at, the check before a
|
|
2
2
|
// Launch, and the hooks that keep checking inside a session sideby starts. The check itself is core/egress.ts.
|
|
3
3
|
import { mkdir, readFile } from 'node:fs/promises';
|
|
4
|
-
import { createConnection } from 'node:net';
|
|
5
4
|
import { join } from 'node:path';
|
|
6
|
-
import {
|
|
5
|
+
import { diagnoseNetwork, } from 'network-portal';
|
|
6
|
+
import { blockMessage, cacheKey, judge, NETWORK_ENV, prefersChinese, readEntry, refresh, routeLabel, verdict, } from './egress.js';
|
|
7
7
|
import { UserError } from './errors.js';
|
|
8
8
|
import { writeFileAtomic } from './fs-safe.js';
|
|
9
9
|
import { sessionHookArgs, sidebyHookCommand, withClaudeHooks } from './session-hooks.js';
|
|
10
10
|
import { inCi } from './update.js';
|
|
11
|
+
export { probeListener, readNetworkSystem, } from 'network-portal';
|
|
11
12
|
/** Families Network Guard covers in v1. */
|
|
12
13
|
export const GUARDED_FAMILIES = ['claude', 'codex'];
|
|
13
14
|
export const TRACE = {
|
|
@@ -266,67 +267,30 @@ export async function networkOverview(opts) {
|
|
|
266
267
|
accounts,
|
|
267
268
|
};
|
|
268
269
|
}
|
|
269
|
-
/**
|
|
270
|
-
export const probeListener = (host, port, timeoutMs) => new Promise((resolve) => {
|
|
271
|
-
const socket = createConnection({ host, port });
|
|
272
|
-
let done = false;
|
|
273
|
-
const finish = (reachable, error) => {
|
|
274
|
-
if (done)
|
|
275
|
-
return;
|
|
276
|
-
done = true;
|
|
277
|
-
socket.destroy();
|
|
278
|
-
resolve({ reachable, ...(error ? { error } : {}) });
|
|
279
|
-
};
|
|
280
|
-
socket.setTimeout(timeoutMs);
|
|
281
|
-
socket.once('connect', () => finish(true));
|
|
282
|
-
socket.once('timeout', () => finish(false, 'timeout'));
|
|
283
|
-
socket.once('error', (e) => finish(false, e.code || 'failed'));
|
|
284
|
-
});
|
|
285
|
-
/**
|
|
286
|
-
* Offline, read-only diagnosis: cached Guard state plus the route visible to this sideby process and a local TCP probe.
|
|
287
|
-
* Unlike `networkOverview({check:true})`, it never calls a trace fetcher, resolves a remote proxy, or writes a cache entry.
|
|
288
|
-
*/
|
|
270
|
+
/** The package owns generic probes; sideby supplies only its accounts and cached Guard state. */
|
|
289
271
|
export async function networkDiagnose(opts) {
|
|
290
272
|
const overview = await networkOverview({ ...opts, check: false });
|
|
291
|
-
const
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
const proxy = routeLabel(target.url, opts.env);
|
|
295
|
-
let guardSupport = raw ? 'invalid' : 'direct';
|
|
296
|
-
let listener = null;
|
|
297
|
-
if (raw && proxy !== 'invalid') {
|
|
298
|
-
// `proxy` is already redacted; parse this rather than the raw environment value at the output boundary.
|
|
299
|
-
const parsed = new URL(proxy.includes('://') ? proxy : `http://${proxy}`);
|
|
300
|
-
guardSupport = parsed.protocol === 'http:' ? 'http-connect' : 'unsupported';
|
|
301
|
-
// Offline diagnosis never resolves or connects to a remote proxy. URL keeps IPv6 brackets in `hostname`;
|
|
302
|
-
// `createConnection` needs the bare address. Only HTTP has a defined default port for this check.
|
|
303
|
-
const host = parsed.hostname.startsWith('[') ? parsed.hostname.slice(1, -1) : parsed.hostname;
|
|
304
|
-
const local = host === 'localhost' || host === '::1' || /^127(?:\.\d{1,3}){3}$/.test(host);
|
|
305
|
-
const port = parsed.port ? Number(parsed.port) : parsed.protocol === 'http:' ? 80 : null;
|
|
306
|
-
if (local && port !== null)
|
|
307
|
-
listener = {
|
|
308
|
-
host,
|
|
309
|
-
port,
|
|
310
|
-
...(await (opts.probe ?? probeListener)(host, port, 1000).catch(() => ({
|
|
311
|
-
reachable: false,
|
|
312
|
-
error: 'failed',
|
|
313
|
-
}))),
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
|
-
targets.push({
|
|
273
|
+
const diagnosis = await diagnoseNetwork({
|
|
274
|
+
env: opts.env,
|
|
275
|
+
targets: overview.targets.map((target) => ({
|
|
317
276
|
url: target.url,
|
|
318
|
-
proxy,
|
|
319
|
-
guardSupport,
|
|
320
|
-
listener,
|
|
321
277
|
guard: {
|
|
322
278
|
status: target.status,
|
|
323
279
|
...(target.loc ? { loc: target.loc } : {}),
|
|
324
280
|
...(target.checkedAt ? { checkedAt: target.checkedAt } : {}),
|
|
325
281
|
...(target.error ? { error: target.error } : {}),
|
|
326
282
|
},
|
|
327
|
-
})
|
|
328
|
-
|
|
329
|
-
|
|
283
|
+
})),
|
|
284
|
+
...(opts.now ? { now: opts.now } : {}),
|
|
285
|
+
...(opts.probe ? { probe: opts.probe } : {}),
|
|
286
|
+
...(opts.system ? { system: opts.system } : {}),
|
|
287
|
+
});
|
|
288
|
+
// The generic package exposes origins only; sideby v1 keeps the exact Guard trace URLs its CLI callers correlate.
|
|
289
|
+
const traceUrls = new Map(overview.targets.map((target) => [new URL(target.url).origin, target.url]));
|
|
290
|
+
return {
|
|
291
|
+
...diagnosis,
|
|
292
|
+
targets: diagnosis.targets.map((target) => ({ ...target, url: traceUrls.get(target.url) ?? target.url })),
|
|
293
|
+
};
|
|
330
294
|
}
|
|
331
295
|
/** Country codes as config keeps them: upper case, two letters, each once, in the order given. */
|
|
332
296
|
export function normalizeAllow(codes) {
|
package/dist/src/core/themes.js
CHANGED
|
@@ -22,7 +22,6 @@ const builtin = (id) => BUILTIN_THEMES.find((t) => t.id === (Object.hasOwn(RENAM
|
|
|
22
22
|
export const NO_THEME = 'default';
|
|
23
23
|
const reserved = (id) => Boolean(builtin(id)) || id === NO_THEME;
|
|
24
24
|
const DEFAULT = builtin(DEFAULT_THEME_ID);
|
|
25
|
-
// ---- Reading and checking a Theme File
|
|
26
25
|
/** Checks parsed JSON as a Theme File. Problems make it unusable; warnings are keys that were ignored. */
|
|
27
26
|
export function checkThemeData(data) {
|
|
28
27
|
const problems = [];
|
|
@@ -102,7 +101,6 @@ export async function readThemeFile(path) {
|
|
|
102
101
|
return { problems: [`cannot be read (${e.code ?? 'error'})`], warnings: [] };
|
|
103
102
|
}
|
|
104
103
|
}
|
|
105
|
-
// ---- Listing
|
|
106
104
|
export async function listThemes(paths) {
|
|
107
105
|
const out = BUILTIN_THEMES.map((t) => ({
|
|
108
106
|
id: t.id,
|
|
@@ -151,7 +149,6 @@ export async function listThemes(paths) {
|
|
|
151
149
|
return out;
|
|
152
150
|
}
|
|
153
151
|
const swatchesOf = (l, d) => [l.bg, l.accentSoft, l.primary, d.bg].filter((c) => typeof c === 'string');
|
|
154
|
-
// ---- Resolving a Theme to tokens
|
|
155
152
|
/** A Theme File's colors before the contrast check: base, then accent roles, then the file's own tokens. */
|
|
156
153
|
export function themeColors(theme) {
|
|
157
154
|
const base = builtin(theme.base ?? DEFAULT_THEME_ID);
|
|
@@ -192,7 +189,6 @@ function adjust(id, c) {
|
|
|
192
189
|
}
|
|
193
190
|
return { id, light, dark, adjusted };
|
|
194
191
|
}
|
|
195
|
-
// ---- Accent roles from one color
|
|
196
192
|
// Lightness and chroma of the maintainer's leaf scales, step 1 to 12; step 9 becomes the accent itself.
|
|
197
193
|
const SCALE_LIGHT = [
|
|
198
194
|
[0.988, 0.014],
|
|
@@ -324,7 +320,6 @@ function passing(fg, bg, min) {
|
|
|
324
320
|
}
|
|
325
321
|
return darker ? '#000000' : '#ffffff';
|
|
326
322
|
}
|
|
327
|
-
// ---- Switching
|
|
328
323
|
/** Sets `panel.colorTheme`, keeping what it was so `undo` can put it back. */
|
|
329
324
|
export async function useTheme(paths, id) {
|
|
330
325
|
id = builtin(id)?.id ?? id;
|
|
@@ -360,7 +355,6 @@ export async function undoTheme(paths) {
|
|
|
360
355
|
await rm(undoFile(paths), { force: true });
|
|
361
356
|
return { before: now, after: rec.before };
|
|
362
357
|
}
|
|
363
|
-
// ---- Files
|
|
364
358
|
/** Writes a checked Theme File into the themes folder. */
|
|
365
359
|
export async function saveThemeFile(paths, id, theme) {
|
|
366
360
|
if (!THEME_ID_RE.test(id) || reserved(id))
|
|
@@ -417,7 +411,6 @@ export async function previewColors(paths) {
|
|
|
417
411
|
return undefined;
|
|
418
412
|
}
|
|
419
413
|
}
|
|
420
|
-
// ---- OKLCH and WCAG contrast
|
|
421
414
|
const lin = (c) => (c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4);
|
|
422
415
|
const unlin = (c) => (c <= 0.0031308 ? 12.92 * c : 1.055 * c ** (1 / 2.4) - 0.055);
|
|
423
416
|
const rgb = (hex) => [1, 3, 5].map((i) => Number.parseInt(hex.slice(i, i + 2), 16) / 255);
|
|
@@ -69,12 +69,12 @@ export interface InstallMethod {
|
|
|
69
69
|
/** npm only: the prefix whose `lib/node_modules` holds sideby. */
|
|
70
70
|
prefix?: string;
|
|
71
71
|
}
|
|
72
|
-
/** Swapped in tests through `bindUpdateDeps`; the real machine otherwise. */
|
|
73
72
|
/**
|
|
74
73
|
* Whether `sideby autostart --refresh --json` rewrote the login item: it exits 0 also when nothing changed or the
|
|
75
74
|
* rewrite was refused, so only its `changed: true` counts.
|
|
76
75
|
*/
|
|
77
76
|
export declare function autostartRefreshed(code: number | null, stdout: string): boolean;
|
|
77
|
+
/** Swapped in tests through `bindUpdateDeps`; the real machine otherwise. */
|
|
78
78
|
export interface UpdateDeps {
|
|
79
79
|
fetch: typeof fetch;
|
|
80
80
|
now: () => Date;
|
package/dist/src/core/update.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
// Update Check, Update Notice, Install Method, Update and Auto Update (spec §3.23, ADR-0021). The Update Check is
|
|
2
|
-
//
|
|
1
|
+
// Update Check, Update Notice, Install Method, Update and Auto Update (spec §3.23, ADR-0021). The Update Check is one
|
|
2
|
+
// of the two network requests sideby makes on its own (the other is Network Guard, ADR-0053): one GET for the
|
|
3
|
+
// `latest` dist-tag, carrying nothing about the user.
|
|
3
4
|
// Everything it learns goes to one state file shared by the CLI and every Panel.
|
|
4
5
|
import { spawn } from 'node:child_process';
|
|
5
6
|
import { access, constants, mkdir, readdir, readFile, realpath, rm } from 'node:fs/promises';
|
|
@@ -22,7 +23,6 @@ export const RETRY_INTERVAL_MS = 60 * 60 * 1000;
|
|
|
22
23
|
export const AUTO_RETRY_MS = 24 * 60 * 60 * 1000;
|
|
23
24
|
const FETCH_TIMEOUT_MS = 5000;
|
|
24
25
|
export const RELEASE_NOTES = (v) => `${REPO_URL}/releases/tag/v${v}`;
|
|
25
|
-
/** Swapped in tests through `bindUpdateDeps`; the real machine otherwise. */
|
|
26
26
|
/**
|
|
27
27
|
* Whether `sideby autostart --refresh --json` rewrote the login item: it exits 0 also when nothing changed or the
|
|
28
28
|
* rewrite was refused, so only its `changed: true` counts.
|
|
@@ -180,7 +180,6 @@ export const runProgram = (file, args, opts) => deps().exec(file, args, opts);
|
|
|
180
180
|
export const updateMachine = () => deps();
|
|
181
181
|
/** The lock every install shares (`update-install.lock`), so a Local Build switch never races an Update. */
|
|
182
182
|
export const takeInstallLock = (paths) => takeLock(paths, 'update-install.lock').catch(() => null);
|
|
183
|
-
// ---- versions
|
|
184
183
|
/** `latest` is newer than `current`. */
|
|
185
184
|
export const isNewer = (latest, current) => latest !== undefined && compareVersions(latest, current) === 1;
|
|
186
185
|
/**
|
|
@@ -192,7 +191,6 @@ export function sameLine(from, to) {
|
|
|
192
191
|
const b = parseVersion(to)?.core;
|
|
193
192
|
return Boolean(a && b && a[0] === b[0]);
|
|
194
193
|
}
|
|
195
|
-
// ---- switches
|
|
196
194
|
const set = (v) => v !== undefined && v !== '' && v !== '0' && v.toLowerCase() !== 'false';
|
|
197
195
|
// `inCi` lives in core/egress.ts, a leaf module `network-hook` may import.
|
|
198
196
|
export { inCi };
|
|
@@ -215,7 +213,6 @@ export function checksOffWhy(env, config, local = localBuild() !== null) {
|
|
|
215
213
|
export function checksOff(env, config, local = localBuild() !== null) {
|
|
216
214
|
return checksOffWhy(env, config, local)?.text ?? null;
|
|
217
215
|
}
|
|
218
|
-
// ---- registry
|
|
219
216
|
/** The registry checks and installs use: `SIDEBY_UPDATE_REGISTRY` (http or https only), else npm's. */
|
|
220
217
|
function registryOf(env) {
|
|
221
218
|
const base = (env.SIDEBY_UPDATE_REGISTRY || DEFAULT_REGISTRY).replace(/\/+$/, '');
|
|
@@ -235,7 +232,6 @@ function shownRegistry(base) {
|
|
|
235
232
|
return 'the registry in SIDEBY_UPDATE_REGISTRY';
|
|
236
233
|
}
|
|
237
234
|
}
|
|
238
|
-
// ---- cache
|
|
239
235
|
const cacheFile = (p) => join(p.stateDir, 'update.json');
|
|
240
236
|
const str = (v) => typeof v === 'string';
|
|
241
237
|
export async function readUpdateCache(paths) {
|
|
@@ -316,7 +312,6 @@ export function autoPending(cache, current, config, now) {
|
|
|
316
312
|
return true;
|
|
317
313
|
return !a.ok && !(age(a.at, now) < AUTO_RETRY_MS);
|
|
318
314
|
}
|
|
319
|
-
// ---- the check
|
|
320
315
|
/** Asks the registry for the `latest` dist-tag. Throws with a message that names the registry and what to do. */
|
|
321
316
|
export async function fetchLatest(env) {
|
|
322
317
|
const base = registryOf(env);
|
|
@@ -355,7 +350,7 @@ export async function refreshUpdateCheck(paths, env) {
|
|
|
355
350
|
const LOCK_MAX_MS = 60 * 60 * 1000;
|
|
356
351
|
/** A lock file another process has just created and not yet written to. */
|
|
357
352
|
const LOCK_WRITE_GRACE_MS = 60 * 1000;
|
|
358
|
-
/** How often a holder touches its lock
|
|
353
|
+
/** How often a holder touches its lock; one nobody touched for `LOCK_STALE_MS` is free. */
|
|
359
354
|
const LOCK_BEAT_MS = 15 * 1000;
|
|
360
355
|
const LOCK_STALE_MS = 2 * 60 * 1000;
|
|
361
356
|
/**
|
|
@@ -378,7 +373,6 @@ async function takeLock(paths, name) {
|
|
|
378
373
|
writeGraceMs: LOCK_WRITE_GRACE_MS,
|
|
379
374
|
}).catch(() => null);
|
|
380
375
|
}
|
|
381
|
-
// ---- the notice
|
|
382
376
|
/**
|
|
383
377
|
* The Update Notice line the CLI may print now, or null. Once per new version per day; `current` is the running
|
|
384
378
|
* version.
|
|
@@ -504,7 +498,6 @@ export function afterCommandPlan(cache, current, config, env, now, skill = null)
|
|
|
504
498
|
skillAutoPending(cache, current, config, skill, now),
|
|
505
499
|
};
|
|
506
500
|
}
|
|
507
|
-
// ---- Install Method
|
|
508
501
|
/** Where the running copy comes from (spec §3.23 table); reads only paths. */
|
|
509
502
|
export async function installMethod(env) {
|
|
510
503
|
const d = deps();
|
|
@@ -600,7 +593,6 @@ export function updateCommand(method, version, env = {}) {
|
|
|
600
593
|
return { text: 'pnpm local --off' };
|
|
601
594
|
}
|
|
602
595
|
}
|
|
603
|
-
// ---- running sessions
|
|
604
596
|
const runningDir = (p) => join(p.stateDir, 'running');
|
|
605
597
|
/**
|
|
606
598
|
* Records that this process runs a Host (`run`, `login`, `next`, `resume`) so an Auto Update waits for it; returns the
|
|
@@ -161,11 +161,11 @@ export function claudeUsageAnswer(answer, account, now) {
|
|
|
161
161
|
const windows = local ? usageQuota(text, now) : null;
|
|
162
162
|
if (windows)
|
|
163
163
|
return { status: 'ok', windows, observedAt: new Date(now).toISOString(), source: QUOTA_FETCH_SOURCE };
|
|
164
|
-
// Only an answer with a known expiry phrase is an Expired Login (ADR-0071, Q10); a `/login` hint, "Not logged in" or
|
|
165
|
-
// an API key problem alone is not.
|
|
166
164
|
// A model turn is never read for sign-in words: its text may merely quote them (it is not a local /usage either).
|
|
167
165
|
if (typeof a.num_turns === 'number' && a.num_turns > 0)
|
|
168
166
|
return failed('this Claude Code version cannot report quota through /usage; update Claude Code, then refresh');
|
|
167
|
+
// Only an answer with a known expiry phrase is an Expired Login (ADR-0071, Q10); a `/login` hint, "Not logged in" or
|
|
168
|
+
// an API key problem alone is not.
|
|
169
169
|
// Only Claude Code's own error result counts as an expiry.
|
|
170
170
|
if (a.is_error === true && saysLoginExpired(text) && !/invalid api key/i.test(text))
|
|
171
171
|
return {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { FileMemo } from '../../core/file-memo.ts';
|
|
2
2
|
import type { Account, ReadContext, TuningResult } from '../../types.ts';
|
|
3
|
-
/** Context window of a model, from the table or the records: a context that grew past 200K is a 1M window. */
|
|
4
3
|
export declare const isKnownClaudeModel: (id: string) => boolean;
|
|
5
4
|
/** `[key, ts, session, model, ctx, out, write5m, write1h]` */
|
|
6
5
|
type TurnRow = [string, number, string, string, number, number, number, number];
|
|
@@ -11,8 +11,8 @@ import { getOrCreate, IDLE_OBSERVED_MS, tuningResult, } from '../../core/tuning.
|
|
|
11
11
|
import { listJsonl } from './usage.js';
|
|
12
12
|
const DAY_MS = 86_400_000;
|
|
13
13
|
const SETTINGS_MAX_BYTES = 1_000_000;
|
|
14
|
-
/** Context window of a model, from the table or the records: a context that grew past 200K is a 1M window. */
|
|
15
14
|
export const isKnownClaudeModel = (id) => id.startsWith('claude-');
|
|
15
|
+
/** Context window of a model, from the table or the records: a context that grew past 200K is a 1M window. */
|
|
16
16
|
const windowOf = (maxCtx) => (maxCtx > 200_000 ? 1_000_000 : 200_000);
|
|
17
17
|
/**
|
|
18
18
|
* Models with a native 1M window, which compact at about 967K when nothing is set: the Fable models, Sonnet 5 and
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Account } from '../types.ts';
|
|
2
|
+
export interface QuotaWatchDir {
|
|
3
|
+
dir: string;
|
|
4
|
+
/** Whether files sit in subfolders (`sessions/2026/11/23/…`). */
|
|
5
|
+
recursive: boolean;
|
|
6
|
+
/** The changed name (relative to `dir`, any separator) that counts. */
|
|
7
|
+
match: RegExp;
|
|
8
|
+
/** At most one change every this many ms: a running session appends to these files all the time. */
|
|
9
|
+
gapMs: number;
|
|
10
|
+
}
|
|
11
|
+
/** The folders to watch for `accounts`. */
|
|
12
|
+
export declare function quotaWatchDirs(accounts: readonly Account[]): QuotaWatchDir[];
|
|
@@ -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
|
@@ -86,7 +86,7 @@ async function hostMadePrompt(input) {
|
|
|
86
86
|
const decisionName = (id) => sha256(id).slice(0, 32);
|
|
87
87
|
/**
|
|
88
88
|
* Keeps the decision for a prompt the Host made (`ok` or `blocked`, nothing of the prompt) where `Held` finds it, and
|
|
89
|
-
* removes decisions nobody read. A failure changes nothing: `Held` then
|
|
89
|
+
* removes decisions nobody read. A failure changes nothing: `Held` then finds no decision and hands nothing over.
|
|
90
90
|
*/
|
|
91
91
|
async function keepDecision(dir, id, decision, now) {
|
|
92
92
|
try {
|
|
@@ -7,5 +7,5 @@ export interface NetworkPageOptions {
|
|
|
7
7
|
theme?: ResolvedTheme;
|
|
8
8
|
lang?: 'auto' | 'en' | 'zh';
|
|
9
9
|
}
|
|
10
|
-
/** The
|
|
10
|
+
/** The generic page owns diagnosis and interaction; sideby owns only its theme, icon, token header and footer. */
|
|
11
11
|
export declare function renderNetworkPage(opts: NetworkPageOptions): string;
|
package/dist/src/network/page.js
CHANGED
|
@@ -1,189 +1,23 @@
|
|
|
1
|
-
//
|
|
2
|
-
import {
|
|
3
|
-
import { FAVICON_VERSION
|
|
1
|
+
// sideby chrome around the reusable Network document. Runtime data still comes only from the Panel's own routes.
|
|
2
|
+
import { renderNetworkPage as renderPortalNetworkPage } from 'network-portal';
|
|
3
|
+
import { FAVICON_VERSION } from '../panel/page.js';
|
|
4
4
|
import { pageStyles } from '../panel/page-styles.js';
|
|
5
5
|
import { resolveTheme } from '../panel/theme.js';
|
|
6
|
-
|
|
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. */
|
|
6
|
+
/** The generic page owns diagnosis and interaction; sideby owns only its theme, icon, token header and footer. */
|
|
136
7
|
export function renderNetworkPage(opts) {
|
|
137
|
-
const nonce = opts.nonce
|
|
138
|
-
? ` nonce="${opts.nonce.replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<')}"`
|
|
139
|
-
: '';
|
|
140
8
|
const theme = opts.theme ?? resolveTheme(undefined);
|
|
141
|
-
|
|
142
|
-
const
|
|
143
|
-
|
|
9
|
+
// A Portal serves this page under /panel/; only the Host root favicon carries the current surface's Network icon.
|
|
10
|
+
const favicon = `/favicon.svg?v=${FAVICON_VERSION}`;
|
|
11
|
+
return renderPortalNetworkPage({
|
|
144
12
|
basePath: opts.basePath,
|
|
145
13
|
token: opts.token,
|
|
146
|
-
|
|
147
|
-
|
|
14
|
+
...(opts.nonce ? { nonce: opts.nonce } : {}),
|
|
15
|
+
...(opts.version ? { version: opts.version } : {}),
|
|
16
|
+
...(opts.lang ? { lang: opts.lang } : {}),
|
|
17
|
+
hostStyles: pageStyles(theme),
|
|
18
|
+
favicon,
|
|
19
|
+
tokenHeader: 'x-sideby-token',
|
|
20
|
+
footer: 'sideby',
|
|
21
|
+
chrome: { title: 'Network', header: theme.header },
|
|
148
22
|
});
|
|
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
23
|
}
|
|
@@ -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 {};
|