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/build.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"id":"
|
|
1
|
+
{"id":"20261124T055449-607979"}
|
|
@@ -202,4 +202,8 @@ export declare function cmdTrust(a: ParsedArgs, io: Io): Promise<number>;
|
|
|
202
202
|
export declare function cmdMemory(a: ParsedArgs, io: Io): Promise<number>;
|
|
203
203
|
/** `sideby unattended …` (spec §3.37, ADR-0058): status, on and off, the Schedule, Pending Decisions and `defer`. */
|
|
204
204
|
export declare function cmdUnattended(a: ParsedArgs, io: Io): Promise<number>;
|
|
205
|
+
/**
|
|
206
|
+
* `sideby commands <words>` (spec §3.36, ADR-0054): the Search Catalog the Panel's Command Palette searches, read-only.
|
|
207
|
+
* Titles and places are in English, as every other command prints; the words may be English or Chinese.
|
|
208
|
+
*/
|
|
205
209
|
export declare function cmdCommands(a: ParsedArgs, io: Io): number;
|
package/dist/src/cli/commands.js
CHANGED
|
@@ -44,8 +44,10 @@ async function whileRunning(rt, fn) {
|
|
|
44
44
|
await done().catch(() => { });
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
/**
|
|
48
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Runs the Account with Auto Handoff when it applies (spec §3.17), else the Host as usual. `opts.aiTask`: an AI Task's
|
|
49
|
+
* Host, started without permission bypasses (ADR-0031); `sideby run` leaves it out.
|
|
50
|
+
*/
|
|
49
51
|
async function runAccount(rt, ref, args, io, opts = {}) {
|
|
50
52
|
return whileRunning(rt, () => runAccountNow(rt, ref, args, io, opts));
|
|
51
53
|
}
|
|
@@ -132,7 +134,6 @@ function displayOrdered(accounts, rt) {
|
|
|
132
134
|
const ids = inDisplayOrder([...new Set(accounts.map((x) => x.family))], (id) => id, d.families);
|
|
133
135
|
return ids.flatMap((id) => withPinned(inDisplayOrder(accounts.filter((x) => x.family === id), (x) => x.name, d.accounts?.[id]), d.pinned?.[id]));
|
|
134
136
|
}
|
|
135
|
-
/** Drop deleted accounts and unloaded Families only when saving a display change. */
|
|
136
137
|
/**
|
|
137
138
|
* Groups the Display Order may name (spec §3.25): every Family, and every desktop app with windows of its own (Grok
|
|
138
139
|
* Bot, `grok-bot`), each with the names it holds.
|
|
@@ -147,6 +148,7 @@ async function orderGroups(rt, accounts) {
|
|
|
147
148
|
}
|
|
148
149
|
return out;
|
|
149
150
|
}
|
|
151
|
+
/** Drop deleted accounts and unloaded Families only when saving a display change. */
|
|
150
152
|
function cleanDisplay(rt, groups) {
|
|
151
153
|
const d = rt.displayOrder();
|
|
152
154
|
const clean = (lists) => Object.fromEntries(Object.entries(lists ?? {})
|
|
@@ -4098,7 +4100,6 @@ export async function cmdHistory(a, io) {
|
|
|
4098
4100
|
io.out(c.dim('Read one, and get the command that continues it in its folder: sideby history show <id>'));
|
|
4099
4101
|
return 0;
|
|
4100
4102
|
}
|
|
4101
|
-
/** The most Sessions one `sideby history` page lists. */
|
|
4102
4103
|
const HISTORY_PAGE_MAX = 500;
|
|
4103
4104
|
/** What to try when a search lists nothing, by what the search was narrowed by. */
|
|
4104
4105
|
function historyEmptyHint(r, q, tools, hasAccounts) {
|
|
@@ -5496,10 +5497,6 @@ export async function cmdUnattended(a, io) {
|
|
|
5496
5497
|
}
|
|
5497
5498
|
throw new UsageError('usage: sideby unattended [status|on|off|schedule|wait|pending|defer]; run `sideby unattended --help`');
|
|
5498
5499
|
}
|
|
5499
|
-
/**
|
|
5500
|
-
* `sideby commands <words>` (spec §3.36, ADR-0054): the Search Catalog the Panel's Command Palette searches, read-only.
|
|
5501
|
-
* Titles and places are in English, as every other command prints; the words may be English or Chinese.
|
|
5502
|
-
*/
|
|
5503
5500
|
/** One command of the Command List as `sideby commands --json` gives it (spec §3.38). */
|
|
5504
5501
|
function commandOut(cmd) {
|
|
5505
5502
|
const place = cmd.feature ? SEARCH_CATALOG.find((e) => e.id === cmd.feature) : undefined;
|
|
@@ -5544,6 +5541,10 @@ function listCommands(a, io) {
|
|
|
5544
5541
|
io.out(out.join('\n'));
|
|
5545
5542
|
return 0;
|
|
5546
5543
|
}
|
|
5544
|
+
/**
|
|
5545
|
+
* `sideby commands <words>` (spec §3.36, ADR-0054): the Search Catalog the Panel's Command Palette searches, read-only.
|
|
5546
|
+
* Titles and places are in English, as every other command prints; the words may be English or Chinese.
|
|
5547
|
+
*/
|
|
5547
5548
|
export function cmdCommands(a, io) {
|
|
5548
5549
|
const query = a.positionals.join(' ').trim();
|
|
5549
5550
|
if (!query)
|
|
@@ -8,6 +8,11 @@ const ReasonCode = Type.Union(['local-build', 'npx', 'volta', 'not-writable', 'p
|
|
|
8
8
|
const Level = Type.Union([Type.Literal('ok'), Type.Literal('warn'), Type.Literal('fail')]);
|
|
9
9
|
const Kind = Type.Union([Type.Literal('subscription'), Type.Literal('api')]);
|
|
10
10
|
const Version = Type.Literal(1);
|
|
11
|
+
const NetworkProbeStatus = Type.Union([
|
|
12
|
+
Type.Literal('available'),
|
|
13
|
+
Type.Literal('unavailable'),
|
|
14
|
+
Type.Literal('error'),
|
|
15
|
+
]);
|
|
11
16
|
/** One Pending Decision of Unattended Mode (spec §3.37). */
|
|
12
17
|
const PendingDecision = Type.Object({
|
|
13
18
|
id: Str,
|
|
@@ -902,6 +907,13 @@ export const OUTPUT_SCHEMAS = {
|
|
|
902
907
|
usedPercent: Type.Number({ description: 'Rounded.' }),
|
|
903
908
|
limit: Type.Number({ description: "This window's Takeover Limit in percent." }),
|
|
904
909
|
}, { description: 'The window closest to its own Takeover Limit; absent when none is open.' })),
|
|
910
|
+
windows: Type.Optional(Type.Array(Type.Object({
|
|
911
|
+
label: Type.String({ description: 'Such as `5h` or `7d`.' }),
|
|
912
|
+
usedPercent: Type.Number({ description: 'Rounded; what is left is 100 minus it.' }),
|
|
913
|
+
resetsAt: Str,
|
|
914
|
+
}), {
|
|
915
|
+
description: 'Every counted window (no model name) that has not reset yet, so a caller can show what the pick has left; absent when none is open.',
|
|
916
|
+
})),
|
|
905
917
|
resetsAt: Type.Optional(Type.String({
|
|
906
918
|
description: 'For full: when it is usable again. With a window used up, when those windows reset; otherwise when every window is under its Takeover Limit again.',
|
|
907
919
|
})),
|
|
@@ -1491,6 +1503,52 @@ export const OUTPUT_SCHEMAS = {
|
|
|
1491
1503
|
checkedAt: Type.String({
|
|
1492
1504
|
description: 'When this offline diagnosis ran (ISO), not the Guard cache time.',
|
|
1493
1505
|
}),
|
|
1506
|
+
system: Type.Object({
|
|
1507
|
+
warp: Type.Object({
|
|
1508
|
+
status: NetworkProbeStatus,
|
|
1509
|
+
state: Type.Union([
|
|
1510
|
+
Type.Literal('connected'),
|
|
1511
|
+
Type.Literal('disconnected'),
|
|
1512
|
+
Type.Literal('unknown'),
|
|
1513
|
+
]),
|
|
1514
|
+
networkHealthy: Type.Optional(Type.Boolean()),
|
|
1515
|
+
error: Type.Optional(Str),
|
|
1516
|
+
}),
|
|
1517
|
+
proxy: Type.Object({
|
|
1518
|
+
status: NetworkProbeStatus,
|
|
1519
|
+
pacEnabled: Type.Boolean(),
|
|
1520
|
+
autoDiscoveryEnabled: Type.Boolean(),
|
|
1521
|
+
protocols: Type.Array(Type.Object({
|
|
1522
|
+
protocol: Type.Union([Type.Literal('http'), Type.Literal('https'), Type.Literal('socks')]),
|
|
1523
|
+
enabled: Type.Boolean(),
|
|
1524
|
+
host: Type.Optional(Type.String({ description: 'Loopback only; every other host is redacted.' })),
|
|
1525
|
+
port: Type.Optional(Type.Integer()),
|
|
1526
|
+
})),
|
|
1527
|
+
exceptionCount: Type.Optional(Type.Integer()),
|
|
1528
|
+
error: Type.Optional(Str),
|
|
1529
|
+
}),
|
|
1530
|
+
dns: Type.Object({
|
|
1531
|
+
status: NetworkProbeStatus,
|
|
1532
|
+
nameservers: Type.Array(Str),
|
|
1533
|
+
error: Type.Optional(Str),
|
|
1534
|
+
}),
|
|
1535
|
+
route: Type.Object({
|
|
1536
|
+
status: NetworkProbeStatus,
|
|
1537
|
+
interface: Type.Optional(Str),
|
|
1538
|
+
gateway: Type.Optional(Str),
|
|
1539
|
+
error: Type.Optional(Str),
|
|
1540
|
+
}),
|
|
1541
|
+
}),
|
|
1542
|
+
localProxyCandidates: Type.Array(Type.Object({
|
|
1543
|
+
label: Type.String({
|
|
1544
|
+
description: 'The common configuration for this port, not an identified process.',
|
|
1545
|
+
}),
|
|
1546
|
+
protocol: Str,
|
|
1547
|
+
host: Str,
|
|
1548
|
+
port: Type.Integer(),
|
|
1549
|
+
reachable: Type.Boolean({ description: 'TCP connect only; not proof of upstream connectivity.' }),
|
|
1550
|
+
error: Type.Optional(Str),
|
|
1551
|
+
})),
|
|
1494
1552
|
targets: Type.Array(Type.Object({
|
|
1495
1553
|
url: Type.String({
|
|
1496
1554
|
description: 'The Guard trace address whose cached result is shown; it is not requested.',
|
|
@@ -17,7 +17,6 @@ export const COMMAND_GROUPS = [
|
|
|
17
17
|
{ id: 'help', title: { en: 'Help, AI and plugins', zh: '帮助、AI 与插件' } },
|
|
18
18
|
];
|
|
19
19
|
export const CLI_COMMANDS = [
|
|
20
|
-
// ---------- Accounts ----------
|
|
21
20
|
{
|
|
22
21
|
id: 'list',
|
|
23
22
|
group: 'accounts',
|
|
@@ -203,7 +202,6 @@ export const CLI_COMMANDS = [
|
|
|
203
202
|
zh: '恢复默认顺序,保留置顶和隐藏',
|
|
204
203
|
},
|
|
205
204
|
},
|
|
206
|
-
// ---------- Start and open ----------
|
|
207
205
|
{
|
|
208
206
|
id: 'run',
|
|
209
207
|
group: 'start',
|
|
@@ -280,7 +278,6 @@ export const CLI_COMMANDS = [
|
|
|
280
278
|
zh: '自己指定 Chrome 用户,或让 sideby 重新找',
|
|
281
279
|
},
|
|
282
280
|
},
|
|
283
|
-
// ---------- Short commands ----------
|
|
284
281
|
{
|
|
285
282
|
id: 'alias.add',
|
|
286
283
|
group: 'shortcuts',
|
|
@@ -342,7 +339,6 @@ export const CLI_COMMANDS = [
|
|
|
342
339
|
summary: { en: 'Make new terminals load your short commands', zh: '让新开的终端自动加载短命令' },
|
|
343
340
|
example: 'sideby shell-init setup',
|
|
344
341
|
},
|
|
345
|
-
// ---------- Quota and usage ----------
|
|
346
342
|
{
|
|
347
343
|
id: 'quota',
|
|
348
344
|
group: 'quota',
|
|
@@ -400,7 +396,6 @@ export const CLI_COMMANDS = [
|
|
|
400
396
|
example: 'sideby tune claude',
|
|
401
397
|
feature: 'page.tuning',
|
|
402
398
|
},
|
|
403
|
-
// ---------- Auto Handoff ----------
|
|
404
399
|
{
|
|
405
400
|
id: 'handoff.status',
|
|
406
401
|
group: 'handoff',
|
|
@@ -460,7 +455,6 @@ export const CLI_COMMANDS = [
|
|
|
460
455
|
help: 'remove it',
|
|
461
456
|
summary: { en: "Remove Grok's handoff hook file", zh: '删掉 Grok 的接力 hook 文件' },
|
|
462
457
|
},
|
|
463
|
-
// ---------- Sessions and messages ----------
|
|
464
458
|
{
|
|
465
459
|
id: 'sessions',
|
|
466
460
|
group: 'sessions',
|
|
@@ -556,7 +550,6 @@ export const CLI_COMMANDS = [
|
|
|
556
550
|
example: 'sideby progress on --every 10',
|
|
557
551
|
feature: 'setting.progress',
|
|
558
552
|
},
|
|
559
|
-
// ---------- Health and safety ----------
|
|
560
553
|
{
|
|
561
554
|
id: 'doctor',
|
|
562
555
|
group: 'health',
|
|
@@ -615,7 +608,6 @@ export const CLI_COMMANDS = [
|
|
|
615
608
|
example: 'sideby unattended wait 30',
|
|
616
609
|
feature: 'action.unattended-wait',
|
|
617
610
|
},
|
|
618
|
-
// ---------- Panel and app ----------
|
|
619
611
|
{
|
|
620
612
|
id: 'ui',
|
|
621
613
|
group: 'panel',
|
|
@@ -705,7 +697,6 @@ export const CLI_COMMANDS = [
|
|
|
705
697
|
help: 'your own Themes (JSON, colors only)',
|
|
706
698
|
summary: { en: 'Import, export or remove your own themes', zh: '导入、导出或删除自己的主题' },
|
|
707
699
|
},
|
|
708
|
-
// ---------- Settings and updates ----------
|
|
709
700
|
{
|
|
710
701
|
id: 'config.get',
|
|
711
702
|
group: 'settings',
|
|
@@ -782,7 +773,6 @@ export const CLI_COMMANDS = [
|
|
|
782
773
|
zh: '给 sideby 开发者:在本地构建和 npm 包之间切换',
|
|
783
774
|
},
|
|
784
775
|
},
|
|
785
|
-
// ---------- Help, AI and plugins ----------
|
|
786
776
|
{
|
|
787
777
|
id: 'commands',
|
|
788
778
|
group: 'help',
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { networkInterfaces } from 'node:os';
|
|
2
|
+
export { proxyFor, redactedProxy, routeLabel } from 'network-portal/proxy';
|
|
2
3
|
/** Variables a launched Host reads for its proxy; the check uses the same ones, so it takes the same route. */
|
|
3
4
|
export declare const PROXY_VARS: readonly ['HTTPS_PROXY', 'https_proxy', 'HTTP_PROXY', 'http_proxy', 'ALL_PROXY', 'all_proxy', 'NO_PROXY', 'no_proxy'];
|
|
4
5
|
/** What `network-hook` reads from the session's environment; set by sideby at Launch. */
|
|
@@ -68,12 +69,6 @@ export interface Verdict {
|
|
|
68
69
|
type Env = Record<string, string | undefined>;
|
|
69
70
|
export type TraceFetcher = (url: string, env: Env, timeoutMs: number) => Promise<string>;
|
|
70
71
|
export type Sleep = (ms: number) => Promise<unknown>;
|
|
71
|
-
/** The proxy a request to `url` goes through under `env`, or null for a direct connection. */
|
|
72
|
-
export declare function proxyFor(url: string, env: Env): string | null;
|
|
73
|
-
/** The selected route safe to show: scheme, hostname and port only, or `direct`; never credentials or a path. */
|
|
74
|
-
export declare function redactedProxy(proxy: string | null): string;
|
|
75
|
-
/** The route `url` selects under `env`, safe for an error, diagnostic result or AI fact. */
|
|
76
|
-
export declare const routeLabel: (url: string, env: Env) => string;
|
|
77
72
|
/** The key a cached result is kept under: the URL and the proxy settings, never their values in clear. */
|
|
78
73
|
export declare function cacheKey(url: string, env: Env): string;
|
|
79
74
|
/** A hash of the machine's own network addresses; it changes with Wi-Fi, a VPN or a TUN device. */
|
|
@@ -140,4 +135,3 @@ export declare function blockMessage(v: Pick<Verdict, 'status' | 'entry' | 'atte
|
|
|
140
135
|
zh: boolean;
|
|
141
136
|
proxy?: string;
|
|
142
137
|
}): string;
|
|
143
|
-
export {};
|
package/dist/src/core/egress.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// The Egress check behind Network Guard (spec §3.35, ADR-0053). A leaf module: `network-hook` runs it on every prompt
|
|
2
|
-
// and tool call, so it imports only Node built-ins and core/fs-safe.ts.
|
|
3
|
-
// `/cdn-cgi/trace` through the Host's proxy settings, keeps the country and a hash of the
|
|
2
|
+
// and tool call, so it imports only Node built-ins, network-portal/proxy (zero runtime dependencies) and core/fs-safe.ts.
|
|
3
|
+
// It asks the vendor's own `/cdn-cgi/trace` through the Host's proxy settings, keeps the country and a hash of the
|
|
4
|
+
// address, and decides.
|
|
4
5
|
import { createHash } from 'node:crypto';
|
|
5
6
|
import { mkdir, readFile } from 'node:fs/promises';
|
|
6
7
|
import { request as httpRequest } from 'node:http';
|
|
@@ -9,7 +10,9 @@ import { networkInterfaces } from 'node:os';
|
|
|
9
10
|
import { join } from 'node:path';
|
|
10
11
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
11
12
|
import { connect as tlsConnect } from 'node:tls';
|
|
13
|
+
import { proxyFor } from 'network-portal/proxy';
|
|
12
14
|
import { writeFileAtomic } from './fs-safe.js';
|
|
15
|
+
export { proxyFor, redactedProxy, routeLabel } from 'network-portal/proxy';
|
|
13
16
|
/** Variables a launched Host reads for its proxy; the check uses the same ones, so it takes the same route. */
|
|
14
17
|
export const PROXY_VARS = [
|
|
15
18
|
'HTTPS_PROXY',
|
|
@@ -74,42 +77,10 @@ export const FRESH_MS = 60_000;
|
|
|
74
77
|
/** Up to this age a tool call goes on while a detached process refreshes the result. */
|
|
75
78
|
export const STALE_MS = 5 * 60_000;
|
|
76
79
|
const sha = (s) => createHash('sha256').update(s).digest('hex');
|
|
77
|
-
/** The proxy a request to `url` goes through under `env`, or null for a direct connection. */
|
|
78
|
-
export function proxyFor(url, env) {
|
|
79
|
-
const host = new URL(url).hostname.toLowerCase();
|
|
80
|
-
const no = env.NO_PROXY ?? env.no_proxy ?? '';
|
|
81
|
-
for (const raw of no.split(',')) {
|
|
82
|
-
const p = raw.trim().toLowerCase().replace(/:\d+$/, '');
|
|
83
|
-
if (!p)
|
|
84
|
-
continue;
|
|
85
|
-
if (p === '*')
|
|
86
|
-
return null;
|
|
87
|
-
const bare = p.replace(/^\*?\./, '');
|
|
88
|
-
if (host === bare || host.endsWith(`.${bare}`))
|
|
89
|
-
return null;
|
|
90
|
-
}
|
|
91
|
-
const v = env.HTTPS_PROXY || env.https_proxy || env.ALL_PROXY || env.all_proxy;
|
|
92
|
-
return v ? v.trim() : null;
|
|
93
|
-
}
|
|
94
|
-
/** The selected route safe to show: scheme, hostname and port only, or `direct`; never credentials or a path. */
|
|
95
|
-
export function redactedProxy(proxy) {
|
|
96
|
-
if (!proxy)
|
|
97
|
-
return 'direct';
|
|
98
|
-
try {
|
|
99
|
-
const p = new URL(proxy.includes('://') ? proxy : `http://${proxy}`);
|
|
100
|
-
if (!p.hostname)
|
|
101
|
-
return 'invalid';
|
|
102
|
-
return `${p.protocol}//${p.host}`;
|
|
103
|
-
}
|
|
104
|
-
catch {
|
|
105
|
-
return 'invalid';
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
/** The route `url` selects under `env`, safe for an error, diagnostic result or AI fact. */
|
|
109
|
-
export const routeLabel = (url, env) => redactedProxy(proxyFor(url, env));
|
|
110
80
|
/** The key a cached result is kept under: the URL and the proxy settings, never their values in clear. */
|
|
111
81
|
export function cacheKey(url, env) {
|
|
112
|
-
|
|
82
|
+
// Version the routing algorithm: an older direct result must not authorize a route the new rules send through a proxy.
|
|
83
|
+
return sha(JSON.stringify(['proxy-selection-v2', url, ...PROXY_VARS.map((k) => env[k] ?? '')])).slice(0, 32);
|
|
113
84
|
}
|
|
114
85
|
/** A hash of the machine's own network addresses; it changes with Wi-Fi, a VPN or a TUN device. */
|
|
115
86
|
export function netPrint(read = networkInterfaces) {
|
|
@@ -36,6 +36,8 @@ export declare class FileMemo<T> {
|
|
|
36
36
|
pass(scope: string): MemoPass<T>;
|
|
37
37
|
/** What is remembered, for the cache file; clears `dirty`. */
|
|
38
38
|
dump(): MemoDump;
|
|
39
|
+
/** The scopes a pass ended in since the last call, for merging into the cache file; clears `dirty`. */
|
|
40
|
+
takeFresh(): MemoDump;
|
|
39
41
|
/**
|
|
40
42
|
* Takes remembered parses from the cache file for scopes this process has not read yet. The values are trusted
|
|
41
43
|
* to have the shape `persist.version` stands for; a stale one never matches, because its signature differs.
|
|
@@ -14,6 +14,12 @@ export class FileMemo {
|
|
|
14
14
|
stats = { hits: 0, misses: 0 };
|
|
15
15
|
/** True when a pass changed what is remembered since the last `dump`. */
|
|
16
16
|
dirty = false;
|
|
17
|
+
/**
|
|
18
|
+
* Scopes a pass ended in since the last `takeFresh`. Only these are this process's own news: the others hold what
|
|
19
|
+
* the cache file had when this process started, which another sideby process sharing the state directory may since
|
|
20
|
+
* have replaced with newer parses.
|
|
21
|
+
*/
|
|
22
|
+
#fresh = new Set();
|
|
17
23
|
persist;
|
|
18
24
|
constructor(persist) {
|
|
19
25
|
if (!persist)
|
|
@@ -61,6 +67,7 @@ export class FileMemo {
|
|
|
61
67
|
if (!before || before.size !== seen.size || [...seen].some(([k, v]) => before.get(k) !== v))
|
|
62
68
|
this.dirty = true;
|
|
63
69
|
this.#scopes.set(scope, seen);
|
|
70
|
+
this.#fresh.add(scope);
|
|
64
71
|
},
|
|
65
72
|
};
|
|
66
73
|
}
|
|
@@ -72,6 +79,18 @@ export class FileMemo {
|
|
|
72
79
|
out[scope] = Object.fromEntries([...files].map(([path, e]) => [path, [e.sig, e.value]]));
|
|
73
80
|
return out;
|
|
74
81
|
}
|
|
82
|
+
/** The scopes a pass ended in since the last call, for merging into the cache file; clears `dirty`. */
|
|
83
|
+
takeFresh() {
|
|
84
|
+
this.dirty = false;
|
|
85
|
+
const out = {};
|
|
86
|
+
for (const scope of this.#fresh) {
|
|
87
|
+
const files = this.#scopes.get(scope);
|
|
88
|
+
if (files)
|
|
89
|
+
out[scope] = Object.fromEntries([...files].map(([path, e]) => [path, [e.sig, e.value]]));
|
|
90
|
+
}
|
|
91
|
+
this.#fresh.clear();
|
|
92
|
+
return out;
|
|
93
|
+
}
|
|
75
94
|
/**
|
|
76
95
|
* Takes remembered parses from the cache file for scopes this process has not read yet. The values are trusted
|
|
77
96
|
* to have the shape `persist.version` stands for; a stale one never matches, because its signature differs.
|
|
@@ -93,6 +112,7 @@ export class FileMemo {
|
|
|
93
112
|
}
|
|
94
113
|
clear() {
|
|
95
114
|
this.#scopes.clear();
|
|
115
|
+
this.#fresh.clear();
|
|
96
116
|
this.dirty = false;
|
|
97
117
|
this.stats.hits = 0;
|
|
98
118
|
this.stats.misses = 0;
|
|
@@ -58,6 +58,15 @@ export interface HandoffEntry {
|
|
|
58
58
|
usedPercent: number;
|
|
59
59
|
limit: number;
|
|
60
60
|
};
|
|
61
|
+
/**
|
|
62
|
+
* Every counted window (no model `name`) that has not reset, so a caller can show what the pick has left (spec
|
|
63
|
+
* §3.45); absent when none is open.
|
|
64
|
+
*/
|
|
65
|
+
windows?: {
|
|
66
|
+
label: string;
|
|
67
|
+
usedPercent: number;
|
|
68
|
+
resetsAt: string;
|
|
69
|
+
}[];
|
|
61
70
|
/**
|
|
62
71
|
* For `full`: when the last window at or over its own Takeover Limit resets, so the Account is usable again. In a
|
|
63
72
|
* plan for a start the user asks for (`lastResort`), an Account with a window used up is usable again once those
|
package/dist/src/core/handoff.js
CHANGED
|
@@ -32,6 +32,7 @@ export const blocked = (e) => Boolean(e.sameLoginAs || e.skip);
|
|
|
32
32
|
function entry(c, now, limits, lastResort, liveSessions) {
|
|
33
33
|
const pressure = quotaPressure(c.quota, now);
|
|
34
34
|
const use = limitUse(c.quota, now, limits);
|
|
35
|
+
const open = openWindows(c.quota, now);
|
|
35
36
|
const base = {
|
|
36
37
|
ref: c.ref,
|
|
37
38
|
kind: c.kind,
|
|
@@ -47,6 +48,15 @@ function entry(c, now, limits, lastResort, liveSessions) {
|
|
|
47
48
|
},
|
|
48
49
|
}
|
|
49
50
|
: {}),
|
|
51
|
+
...(open?.length
|
|
52
|
+
? {
|
|
53
|
+
windows: open.map((w) => ({
|
|
54
|
+
label: w.label,
|
|
55
|
+
usedPercent: Math.round(w.usedPercent),
|
|
56
|
+
resetsAt: w.resetsAt,
|
|
57
|
+
})),
|
|
58
|
+
}
|
|
59
|
+
: {}),
|
|
50
60
|
...(c.quota.status === 'ok' ? { observedAt: c.quota.observedAt } : {}),
|
|
51
61
|
...(c.quota.status === 'ok' && c.quota.from ? { quotaFrom: c.quota.from } : {}),
|
|
52
62
|
};
|
|
@@ -137,7 +137,7 @@ export declare const recency: (ageMs: number) => number;
|
|
|
137
137
|
/** The words of a search; `"two words"` in double quotes is one phrase, matched as written. */
|
|
138
138
|
export declare const splitWords: (q: string | undefined) => string[];
|
|
139
139
|
/**
|
|
140
|
-
* Sessions matching `q`, best first (relevance times a recency boost that
|
|
140
|
+
* Sessions matching `q`, best first (relevance times a recency boost that is half at 30 days), or newest first
|
|
141
141
|
* without words. Answers from what is built; `wait` waits for the current sync first (the CLI's first run).
|
|
142
142
|
* `live` names Sessions running now, as `<account>\0<sessionId>`.
|
|
143
143
|
*/
|
package/dist/src/core/history.js
CHANGED
|
@@ -251,9 +251,9 @@ export async function syncHistory(rt, opts = {}) {
|
|
|
251
251
|
if (s.retired)
|
|
252
252
|
return;
|
|
253
253
|
let input;
|
|
254
|
-
// A Session id goes into a resume command the user may run, so only plain ids are kept.
|
|
255
254
|
if (parsed)
|
|
256
255
|
parsed.parent ??= file.parent;
|
|
256
|
+
// A Session id goes into a resume command the user may run, so only plain ids are kept.
|
|
257
257
|
if (parsed && SAFE_ID.test(parsed.sessionId) && (!parsed.parent || SAFE_ID.test(parsed.parent))) {
|
|
258
258
|
const p = await projects.resolve(parsed.cwd, parsed.gitRoot);
|
|
259
259
|
input = {
|
|
@@ -600,7 +600,7 @@ function toSession(rt, r, labels, names, extra) {
|
|
|
600
600
|
/** The words of a search; `"two words"` in double quotes is one phrase, matched as written. */
|
|
601
601
|
export const splitWords = (q) => [...(q ?? '').matchAll(/"([^"]*)"?|(\S+)/g)].map((m) => (m[1] ?? m[2] ?? '').trim()).filter(Boolean);
|
|
602
602
|
/**
|
|
603
|
-
* Sessions matching `q`, best first (relevance times a recency boost that
|
|
603
|
+
* Sessions matching `q`, best first (relevance times a recency boost that is half at 30 days), or newest first
|
|
604
604
|
* without words. Answers from what is built; `wait` waits for the current sync first (the CLI's first run).
|
|
605
605
|
* `live` names Sessions running now, as `<account>\0<sessionId>`.
|
|
606
606
|
*/
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
// Keeps the persisted FileMemos (core/file-memo.ts) in `<stateDir>/cache/file-memo.json`, so a new process does not
|
|
1
|
+
// Keeps the persisted FileMemos (core/file-memo.ts) in `<stateDir>/cache/file-memo-2.json`, so a new process does not
|
|
2
2
|
// parse every session log again: the Panel worker starts cold after each restart, reinstall or language switch,
|
|
3
3
|
// and parsing the logs of a busy HOME takes seconds, while reading this file back takes milliseconds.
|
|
4
4
|
//
|
|
5
|
+
// Several sideby processes share a state directory (a Panel worker, a background Panel, launchers that wait for hours).
|
|
6
|
+
// Each one writes only the scopes it read itself since its last write, into what the file holds at that moment, so a
|
|
7
|
+
// process that loaded the file long ago never puts its old parses back over newer ones. An older sideby that is still
|
|
8
|
+
// running writes the whole of `cache/file-memo.json`; this file has another name, so it cannot undo these merges.
|
|
9
|
+
//
|
|
5
10
|
// The file holds token counts, session ids and log paths, never a credential; it is written atomically with mode
|
|
6
11
|
// 600. Anything unexpected in it (another format, a parse error, a memo version that changed) is ignored and the
|
|
7
12
|
// logs are parsed again, which gives the same results.
|
|
@@ -15,7 +20,7 @@ export const SAVE_INTERVAL_MS = 60_000;
|
|
|
15
20
|
/** A write waits this long after the last read, so one Panel refresh over every Account is written as a whole. */
|
|
16
21
|
export const SAVE_DELAY_MS = 2_000;
|
|
17
22
|
export function memoCachePath(stateDir) {
|
|
18
|
-
return join(stateDir, 'cache', 'file-memo.json');
|
|
23
|
+
return join(stateDir, 'cache', 'file-memo-2.json');
|
|
19
24
|
}
|
|
20
25
|
const stores = new Map();
|
|
21
26
|
/** One store per state directory and process. */
|
|
@@ -28,13 +33,23 @@ export function memoStore(stateDir, now = Date.now, delayMs = SAVE_DELAY_MS) {
|
|
|
28
33
|
let writing;
|
|
29
34
|
let lastWrite = Number.NEGATIVE_INFINITY;
|
|
30
35
|
let timer;
|
|
31
|
-
|
|
36
|
+
/** The cache file's memos, or null when it is missing or not one this sideby can read. */
|
|
37
|
+
const readCache = async () => {
|
|
32
38
|
try {
|
|
33
39
|
const data = JSON.parse(await readFile(file, 'utf8'));
|
|
34
|
-
|
|
40
|
+
return data?.format === FORMAT && data.memos && typeof data.memos === 'object' ? data.memos : null;
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const load = async () => {
|
|
47
|
+
try {
|
|
48
|
+
const memos = await readCache();
|
|
49
|
+
if (!memos)
|
|
35
50
|
return;
|
|
36
51
|
for (const [name, memo] of persistedMemos) {
|
|
37
|
-
const saved =
|
|
52
|
+
const saved = memos[name];
|
|
38
53
|
if (saved && saved.version === memo.persist?.version && saved.data && typeof saved.data === 'object')
|
|
39
54
|
memo.restore(saved.data);
|
|
40
55
|
}
|
|
@@ -47,9 +62,18 @@ export function memoStore(stateDir, now = Date.now, delayMs = SAVE_DELAY_MS) {
|
|
|
47
62
|
if (![...persistedMemos.values()].some((m) => m.dirty))
|
|
48
63
|
return;
|
|
49
64
|
lastWrite = now();
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
65
|
+
// Taken before the file is read again, so a pass that ends meanwhile counts toward the next write.
|
|
66
|
+
const fresh = [...persistedMemos].map(([name, memo]) => [name, memo, memo.takeFresh()]);
|
|
67
|
+
// Memos this process does not know (another sideby's) are kept as they are.
|
|
68
|
+
const out = { format: FORMAT, memos: { ...(await readCache()) } };
|
|
69
|
+
for (const [name, memo, scopes] of fresh) {
|
|
70
|
+
const version = memo.persist?.version ?? 0;
|
|
71
|
+
const saved = out.memos[name];
|
|
72
|
+
// A memo of another version is dropped whole, as `load` would.
|
|
73
|
+
const data = saved?.version === version && saved.data && typeof saved.data === 'object' ? { ...saved.data } : {};
|
|
74
|
+
Object.assign(data, scopes);
|
|
75
|
+
out.memos[name] = { version, data };
|
|
76
|
+
}
|
|
53
77
|
try {
|
|
54
78
|
await mkdir(join(stateDir, 'cache'), { recursive: true, mode: 0o700 });
|
|
55
79
|
await writeFileAtomic(file, JSON.stringify(out));
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { type ListenerProbe, type NetworkDiagnosis, type NetworkSystemDeps } from 'network-portal';
|
|
1
2
|
import type { Account, Env } from '../types.ts';
|
|
2
3
|
import type { Config } from './config.ts';
|
|
3
4
|
import { type EgressStatus, type TraceFetcher, type Verdict } from './egress.ts';
|
|
4
5
|
import { type SessionHookPart } from './session-hooks.ts';
|
|
6
|
+
export { type ListenerProbe, type NetworkCommandRunner, type NetworkDiagnoseTarget, type NetworkDiagnosis, type NetworkGuardFact, type NetworkGuardStatus, type NetworkLocalProxyCandidate, type NetworkProbeStatus, type NetworkProxyProtocol, type NetworkSystemDeps, type NetworkSystemInfo, probeListener, readNetworkSystem, } from 'network-portal';
|
|
5
7
|
/** Families Network Guard covers in v1. */
|
|
6
8
|
export declare const GUARDED_FAMILIES: readonly ['claude', 'codex'];
|
|
7
9
|
export declare const TRACE: {
|
|
@@ -84,7 +86,7 @@ export declare function withClaudeNetworkHooks(hookArgs: readonly string[], stat
|
|
|
84
86
|
export declare function withoutArgs(args: readonly string[], drop: readonly string[]): string[];
|
|
85
87
|
/**
|
|
86
88
|
* Where one Account is checked, or why not: an API Account (`api`), or an endpoint set to a third party.
|
|
87
|
-
* `at-launch` is
|
|
89
|
+
* `at-launch` is never given (API Accounts are not checked, ADR-0079); it stays in the type for `--json` readers.
|
|
88
90
|
*/
|
|
89
91
|
export interface NetworkAccountRow {
|
|
90
92
|
ref: string;
|
|
@@ -125,42 +127,10 @@ export declare function networkOverview(opts: {
|
|
|
125
127
|
accounts: NetworkAccountRow[];
|
|
126
128
|
}>;
|
|
127
129
|
export type NetworkOverview = Awaited<ReturnType<typeof networkOverview>>;
|
|
128
|
-
|
|
129
|
-
reachable: boolean;
|
|
130
|
-
error?: string;
|
|
131
|
-
}>;
|
|
132
|
-
/** A local TCP connection attempt; its result says nothing about the proxy protocol or upstream connectivity. */
|
|
133
|
-
export declare const probeListener: ListenerProbe;
|
|
134
|
-
export interface NetworkDiagnosis {
|
|
135
|
-
/** When this offline diagnosis was made (ISO), not when the cached Guard entries were checked. */
|
|
136
|
-
checkedAt: string;
|
|
137
|
-
targets: {
|
|
138
|
-
url: string;
|
|
139
|
-
/** The current process's selected proxy with credentials/path removed, or `direct`. */
|
|
140
|
-
proxy: string;
|
|
141
|
-
/** Whether Network Guard can use this route: HTTP CONNECT only; direct needs no proxy protocol. */
|
|
142
|
-
guardSupport: 'direct' | 'http-connect' | 'unsupported' | 'invalid';
|
|
143
|
-
/** Null for direct, a remote proxy, an unreadable address, or a non-HTTP proxy without an explicit port. */
|
|
144
|
-
listener: null | {
|
|
145
|
-
host: string;
|
|
146
|
-
port: number;
|
|
147
|
-
reachable: boolean;
|
|
148
|
-
error?: string;
|
|
149
|
-
};
|
|
150
|
-
guard: {
|
|
151
|
-
status: NetworkTargetStatus['status'];
|
|
152
|
-
loc?: string;
|
|
153
|
-
checkedAt?: string;
|
|
154
|
-
error?: string;
|
|
155
|
-
};
|
|
156
|
-
}[];
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Offline, read-only diagnosis: cached Guard state plus the route visible to this sideby process and a local TCP probe.
|
|
160
|
-
* Unlike `networkOverview({check:true})`, it never calls a trace fetcher, resolves a remote proxy, or writes a cache entry.
|
|
161
|
-
*/
|
|
130
|
+
/** The package owns generic probes; sideby supplies only its accounts and cached Guard state. */
|
|
162
131
|
export declare function networkDiagnose(opts: Parameters<typeof networkOverview>[0] & {
|
|
163
132
|
probe?: ListenerProbe;
|
|
133
|
+
system?: NetworkSystemDeps;
|
|
164
134
|
}): Promise<NetworkDiagnosis>;
|
|
165
135
|
export interface NetworkChange {
|
|
166
136
|
guard?: boolean;
|