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,178 @@
|
|
|
1
|
+
// The Panel's change feed (spec §3.45, ADR-0084): while a page asks, watch the files Quota lands in and count their
|
|
2
|
+
// changes, so the page reads the state within about a second instead of at its next 20-second round. Events only bump
|
|
3
|
+
// a counter: no watched file is ever read here.
|
|
4
|
+
import { statSync, watch } from 'node:fs';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
/** How long after the first event a change counts: an atomic write (temporary file, then rename) counts once. */
|
|
7
|
+
export const GATHER_MS = 300;
|
|
8
|
+
/** How long a request with nothing new is held. */
|
|
9
|
+
export const HOLD_MS = 25_000;
|
|
10
|
+
/** Watchers close this long after the last request: the page asks again at once, so only a gone page is this quiet. */
|
|
11
|
+
export const IDLE_MS = 40_000;
|
|
12
|
+
/** How often the folders are listed again while a page asks (a new Account, a folder made since). */
|
|
13
|
+
const RESCAN_MS = 60_000;
|
|
14
|
+
/** With several sessions open the status line rewrites its cache on every reply; each change rereads every Account. */
|
|
15
|
+
const QUOTA_GAP_MS = 5000;
|
|
16
|
+
/** sideby's own churn under `<state>/quota`: ask locks, the folder `claude -p /usage` runs in, Limit Reset records. */
|
|
17
|
+
const OWN = new Set(['asking', 'claude-run', 'limit-reset']);
|
|
18
|
+
/** `<state>/quota`: the status line cache and the kept answers of each Host's own CLI. */
|
|
19
|
+
export function stateQuotaDir(stateDir) {
|
|
20
|
+
return {
|
|
21
|
+
dir: join(stateDir, 'quota'),
|
|
22
|
+
recursive: true,
|
|
23
|
+
match: {
|
|
24
|
+
test: (name) => {
|
|
25
|
+
const parts = name.split(/[\\/]/);
|
|
26
|
+
const base = parts[parts.length - 1] ?? '';
|
|
27
|
+
return base.endsWith('.json') && !base.startsWith('.') && !OWN.has(parts[0] ?? '');
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
gapMs: QUOTA_GAP_MS,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const realTimers = {
|
|
34
|
+
now: () => Date.now(),
|
|
35
|
+
set: (fn, ms) => setTimeout(fn, ms).unref(),
|
|
36
|
+
clear: (t) => clearTimeout(t),
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Turns events into counted changes: one `GATHER_MS` after the first event, and never sooner than `gapMs` (the
|
|
40
|
+
* event's folder) after the last one. Events meanwhile join that change; one whose folder allows an earlier time
|
|
41
|
+
* brings it forward.
|
|
42
|
+
*/
|
|
43
|
+
export function changeClock(fire, timers = realTimers) {
|
|
44
|
+
let last = Number.NEGATIVE_INFINITY;
|
|
45
|
+
let due = null;
|
|
46
|
+
let timer;
|
|
47
|
+
return {
|
|
48
|
+
poke(gapMs) {
|
|
49
|
+
const at = timers.now();
|
|
50
|
+
const want = Math.max(at + GATHER_MS, last + gapMs);
|
|
51
|
+
if (due !== null && due <= want)
|
|
52
|
+
return;
|
|
53
|
+
if (due !== null)
|
|
54
|
+
timers.clear(timer);
|
|
55
|
+
due = want;
|
|
56
|
+
timer = timers.set(() => {
|
|
57
|
+
due = null;
|
|
58
|
+
last = timers.now();
|
|
59
|
+
fire();
|
|
60
|
+
}, want - at);
|
|
61
|
+
},
|
|
62
|
+
stop() {
|
|
63
|
+
if (due !== null)
|
|
64
|
+
timers.clear(timer);
|
|
65
|
+
due = null;
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
const isDir = (p) => {
|
|
70
|
+
try {
|
|
71
|
+
return statSync(p).isDirectory();
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* The feed of one Panel. `dirs` lists what to watch; `onChange` runs once per counted change, before held requests
|
|
79
|
+
* are answered.
|
|
80
|
+
*/
|
|
81
|
+
export function createChangeFeed(opts) {
|
|
82
|
+
let seq = 0;
|
|
83
|
+
const waiters = new Set();
|
|
84
|
+
const watchers = new Map();
|
|
85
|
+
let lastAsk = 0;
|
|
86
|
+
let lastScan = 0;
|
|
87
|
+
let scanning = null;
|
|
88
|
+
let idle;
|
|
89
|
+
const clock = changeClock(() => {
|
|
90
|
+
seq++;
|
|
91
|
+
opts.onChange?.();
|
|
92
|
+
for (const done of [...waiters])
|
|
93
|
+
done();
|
|
94
|
+
});
|
|
95
|
+
function closeAll() {
|
|
96
|
+
for (const w of watchers.values())
|
|
97
|
+
w.close();
|
|
98
|
+
watchers.clear();
|
|
99
|
+
clock.stop();
|
|
100
|
+
lastScan = 0;
|
|
101
|
+
if (idle)
|
|
102
|
+
clearInterval(idle);
|
|
103
|
+
idle = undefined;
|
|
104
|
+
}
|
|
105
|
+
async function scan() {
|
|
106
|
+
lastScan = Date.now();
|
|
107
|
+
const dirs = await opts.dirs().catch(() => []);
|
|
108
|
+
const want = new Map(dirs.map((d) => [`${d.recursive ? 'r' : 'f'}\0${d.dir}`, d]));
|
|
109
|
+
for (const [key, w] of watchers)
|
|
110
|
+
if (!want.has(key)) {
|
|
111
|
+
w.close();
|
|
112
|
+
watchers.delete(key);
|
|
113
|
+
}
|
|
114
|
+
for (const [key, d] of want) {
|
|
115
|
+
if (watchers.has(key) || !isDir(d.dir))
|
|
116
|
+
continue;
|
|
117
|
+
// A platform without recursive watching, or a folder that cannot be watched, is left out: the page polls.
|
|
118
|
+
try {
|
|
119
|
+
const w = watch(d.dir, { recursive: d.recursive, persistent: false }, (_event, name) => {
|
|
120
|
+
if (name === null || d.match.test(String(name)))
|
|
121
|
+
clock.poke(d.gapMs);
|
|
122
|
+
});
|
|
123
|
+
// Unhandled, a watcher's error would end the process (a Portal's worker with it).
|
|
124
|
+
w.on('error', () => {
|
|
125
|
+
w.close();
|
|
126
|
+
if (watchers.get(key) === w)
|
|
127
|
+
watchers.delete(key);
|
|
128
|
+
});
|
|
129
|
+
watchers.set(key, w);
|
|
130
|
+
}
|
|
131
|
+
catch { }
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
async function ensure() {
|
|
135
|
+
if (!idle) {
|
|
136
|
+
idle = setInterval(() => {
|
|
137
|
+
if (!waiters.size && Date.now() - lastAsk > IDLE_MS)
|
|
138
|
+
closeAll();
|
|
139
|
+
}, 10_000).unref();
|
|
140
|
+
}
|
|
141
|
+
if (!scanning && (!lastScan || Date.now() - lastScan > RESCAN_MS))
|
|
142
|
+
scanning = scan().finally(() => {
|
|
143
|
+
scanning = null;
|
|
144
|
+
});
|
|
145
|
+
if (scanning)
|
|
146
|
+
await scanning;
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
/**
|
|
150
|
+
* The answer for a page that last saw `since` (null: none yet). Held up to `HOLD_MS` while nothing changed, or
|
|
151
|
+
* until `gone` settles (the request closed).
|
|
152
|
+
*/
|
|
153
|
+
async wait(since, gone) {
|
|
154
|
+
lastAsk = Date.now();
|
|
155
|
+
await ensure();
|
|
156
|
+
const now = () => ({
|
|
157
|
+
seq,
|
|
158
|
+
changed: since !== null && since !== seq,
|
|
159
|
+
watching: watchers.size > 0,
|
|
160
|
+
});
|
|
161
|
+
if (since === null || since !== seq || !watchers.size)
|
|
162
|
+
return now();
|
|
163
|
+
return new Promise((resolve) => {
|
|
164
|
+
const done = () => {
|
|
165
|
+
clearTimeout(timer);
|
|
166
|
+
waiters.delete(done);
|
|
167
|
+
lastAsk = Date.now();
|
|
168
|
+
resolve(now());
|
|
169
|
+
};
|
|
170
|
+
const timer = setTimeout(done, HOLD_MS).unref();
|
|
171
|
+
waiters.add(done);
|
|
172
|
+
void gone.then(done, done);
|
|
173
|
+
});
|
|
174
|
+
},
|
|
175
|
+
/** For tests: closes every watcher now. */
|
|
176
|
+
close: closeAll,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
@@ -4,6 +4,7 @@ import { type AppProfileStatus } from '../core/app-profiles.ts';
|
|
|
4
4
|
import { type AutostartContext, type AutostartStatus } from '../core/autostart.ts';
|
|
5
5
|
import { type BrowserReport } from '../core/browser-profiles.ts';
|
|
6
6
|
import { type DisplayConfig, type EditorChoice, type HandoffSettings, type PanelConfig } from '../core/config.ts';
|
|
7
|
+
import { type HandoffPlan, type PickRecord } from '../core/handoff.ts';
|
|
7
8
|
import { type InboundGroup } from '../core/inbound.ts';
|
|
8
9
|
import { type LiveSession, type LiveSessionsResult, sessionCopyText } from '../core/live-sessions.ts';
|
|
9
10
|
import { listMessages, type MessageReceipt, sendMessage } from '../core/messages.ts';
|
|
@@ -77,6 +78,11 @@ export interface PanelHandlerOptions {
|
|
|
77
78
|
* does not export it); it may change without notice.
|
|
78
79
|
*/
|
|
79
80
|
export declare const LIVE_SESSIONS_SOURCE: unique symbol;
|
|
81
|
+
/**
|
|
82
|
+
* Internal: a property under this key of the handler options serves only the Network view (`src/network/panel.ts`).
|
|
83
|
+
* Not part of the Portal contract (`src/index.ts` does not export it); it may change without notice.
|
|
84
|
+
*/
|
|
85
|
+
export declare const PANEL_VIEW: unique symbol;
|
|
80
86
|
export interface LiveSessionsSource {
|
|
81
87
|
list?: (rt: Runtime) => Promise<LiveSessionsResult>;
|
|
82
88
|
copyText?: typeof sessionCopyText;
|
|
@@ -146,6 +152,10 @@ export type PanelAccount = (AccountStatus | (Account & Partial<AccountStatus>))
|
|
|
146
152
|
modelInfo?: Omit<AccountModel, 'ref' | 'family'>;
|
|
147
153
|
/** Its reads take longer than the state waits (`readBudget`); they go on, and a later state carries them. */
|
|
148
154
|
pending?: true;
|
|
155
|
+
/** Its usage is still being read (the rest is current); a later state carries it. */
|
|
156
|
+
usagePending?: true;
|
|
157
|
+
/** The last complete state, shown while a new read of the Account takes longer than the state waits. */
|
|
158
|
+
refreshing?: true;
|
|
149
159
|
};
|
|
150
160
|
export type { DoctorHistory };
|
|
151
161
|
/** Counts of failing and warning Findings per checked Account, from the Doctor history. */
|
|
@@ -270,6 +280,18 @@ export interface PanelState {
|
|
|
270
280
|
* at least two subscription Accounts, some Quota data and a pick; API Accounts are left out as in the CLI default.
|
|
271
281
|
*/
|
|
272
282
|
handoff?: Record<string, string>;
|
|
283
|
+
/** Family → the Live Sessions of the login of its `handoff` pick, Pick Records included, when any (ADR-0083). */
|
|
284
|
+
handoffRunning?: Record<string, number>;
|
|
285
|
+
/**
|
|
286
|
+
* Family → why its `handoff` pick goes first: `expiring` or `room` under its limits (ADR-0083), `tight` past every
|
|
287
|
+
* limit (a Last Resort), `unknown` when it has no Quota data and the accounts with data are full.
|
|
288
|
+
*/
|
|
289
|
+
handoffReason?: Record<string, 'expiring' | 'room' | 'tight' | 'unknown'>;
|
|
290
|
+
/**
|
|
291
|
+
* Family → the "Best to use now" card's pick (spec §3.45): the same plan as `handoff`, also for a Family with one
|
|
292
|
+
* login, and when the running sessions are not known in time (ranked as if none ran).
|
|
293
|
+
*/
|
|
294
|
+
pickNow?: Record<string, PickNow>;
|
|
273
295
|
/** Auto Handoff settings (spec §3.17) and the Families that can start one; readiness comes from /api/handoff/status. */
|
|
274
296
|
autoHandoff: {
|
|
275
297
|
settings: HandoffSettings;
|
|
@@ -390,8 +412,44 @@ export declare function autostartView(s: AutostartStatus, home: string): {
|
|
|
390
412
|
missing?: string[] | undefined;
|
|
391
413
|
loaded?: boolean | undefined;
|
|
392
414
|
};
|
|
415
|
+
/** One Family's "Best to use now" (spec §3.45). */
|
|
416
|
+
export interface PickNow {
|
|
417
|
+
/** The Account `sideby next` would pick; null when none can be started now. */
|
|
418
|
+
pick: string | null;
|
|
419
|
+
/** Whether any Account of the Family has Quota data; without any there is no pick. */
|
|
420
|
+
hasQuota: boolean;
|
|
421
|
+
/** Why the pick goes first, as `handoffReason`. */
|
|
422
|
+
reason?: 'expiring' | 'room' | 'tight' | 'unknown';
|
|
423
|
+
/** The Live Sessions of the pick's login, Pick Records included, when any. */
|
|
424
|
+
running?: number;
|
|
425
|
+
/** Why there is no pick: no Quota data, every signed-in Account has a window used up, or none is signed in. */
|
|
426
|
+
why?: 'no-quota' | 'used-up' | 'signed-out';
|
|
427
|
+
/** With `used-up`: the Account that comes back first. */
|
|
428
|
+
earliestReset?: {
|
|
429
|
+
ref: string;
|
|
430
|
+
at: string;
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
/** The Live Sessions and Pick Records a pick counts (ADR-0083). */
|
|
434
|
+
export interface PickLoad {
|
|
435
|
+
live: ReadonlyMap<string, number>;
|
|
436
|
+
picks: readonly PickRecord[];
|
|
437
|
+
}
|
|
393
438
|
/** The `handoff` map of the Panel state, from the statuses and Quota already read for the page. */
|
|
394
|
-
export declare function handoffByFamily(rt: Runtime, accounts: readonly PanelAccount[], now: Date): Record<string, string>;
|
|
439
|
+
export declare function handoffByFamily(rt: Runtime, accounts: readonly PanelAccount[], now: Date, load?: PickLoad): Record<string, string>;
|
|
440
|
+
/** The plan behind each pick of `handoffByFamily`, spread by Room per Session when `load` is given (ADR-0083). */
|
|
441
|
+
export declare function handoffPlans(rt: Runtime, accounts: readonly PanelAccount[], now: Date, load?: PickLoad): Record<string, HandoffPlan>;
|
|
442
|
+
/**
|
|
443
|
+
* `sideby next`'s plan for every Family with a Quota source and a signed-in or unknown Subscription Account read
|
|
444
|
+
* already, with how many logins it has: the Next pick takes those with two or more, the "Best to use now" card
|
|
445
|
+
* (spec §3.45) every one.
|
|
446
|
+
*/
|
|
447
|
+
export declare function familyPlans(rt: Runtime, accounts: readonly PanelAccount[], now: Date, load?: PickLoad): Record<string, {
|
|
448
|
+
plan: HandoffPlan;
|
|
449
|
+
logins: number;
|
|
450
|
+
}>;
|
|
451
|
+
/** The "Best to use now" card's entry of a Family's plan (spec §3.45). */
|
|
452
|
+
export declare function pickNowOf(plan: HandoffPlan): PickNow;
|
|
395
453
|
export type RemoteControlView = Omit<RemoteControlGroup, 'file'> & {
|
|
396
454
|
file: string;
|
|
397
455
|
};
|