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
|
@@ -4,7 +4,7 @@ import { realpath } from 'node:fs/promises';
|
|
|
4
4
|
import { aliasesByAccount, startArgsOf } from '../core/accounts.js';
|
|
5
5
|
import { advisorPlan, advisorScope, checkAdvisorAccount, isAdvisorChoice, } from '../core/advisor.js';
|
|
6
6
|
import { listAppProfiles, openAppProfile, removeAppProfile, } from '../core/app-profiles.js';
|
|
7
|
-
import { openLoginInTerminal, openRunInTerminal, pickTaskAccount, previewAttachments, promptForTask, setCustomTerminal, setPreferredTerminal, startAiTask, taskContext, terminals, tryAccount, } from '../core/ask.js';
|
|
7
|
+
import { newTaskId, openLoginInTerminal, openPromptTask, openRunInTerminal, pickTaskAccount, previewAttachments, promptForTask, setCustomTerminal, setPreferredTerminal, startAiTask, taskContext, terminals, tryAccount, } from '../core/ask.js';
|
|
8
8
|
import { ATTACHMENT_LIMITS, MAX_ATTACHMENTS, MAX_UPLOAD_BYTES, removeStaged, stagedAttachments, stageUpload, } from '../core/attachments.js';
|
|
9
9
|
import { applyAutostart, autostartStatus, PANEL_AGENT, planAutostart, } from '../core/autostart.js';
|
|
10
10
|
import { FAVICON_SVG, ICON_SVG } from '../core/brand-mark.js';
|
|
@@ -13,7 +13,7 @@ import { aiTaskPermissions, aliasArgs, aliasRefs, EDITORS, editConfigPanel, edit
|
|
|
13
13
|
import { openDesktopApp, withDesktopApps } from '../core/desktop-app.js';
|
|
14
14
|
import { editSettings, isEditor } from '../core/edit-settings.js';
|
|
15
15
|
import { UserError } from '../core/errors.js';
|
|
16
|
-
import { planHandoff } from '../core/handoff.js';
|
|
16
|
+
import { blocked, planHandoff } from '../core/handoff.js';
|
|
17
17
|
import { applyHandoffEnable, planHandoffEnable } from '../core/handoff-enable.js';
|
|
18
18
|
import { handoffOverview } from '../core/handoff-overview.js';
|
|
19
19
|
import { apiUndecided, handoffRulesView } from '../core/handoff-rules.js';
|
|
@@ -35,7 +35,7 @@ import { openRunBoard, withRuns } from '../core/run-link.js';
|
|
|
35
35
|
import { SECRET_VAR_NAME, secretVarFor, setSecret } from '../core/secret-file.js';
|
|
36
36
|
import { readHandoffChains, withHandoffs } from '../core/session-handoffs.js';
|
|
37
37
|
import { SKILL_INSTALL } from '../core/skill-check.js';
|
|
38
|
-
import {
|
|
38
|
+
import { TERMINALS } from '../core/terminal.js';
|
|
39
39
|
import { checkThemeData, listThemes, NO_THEME, previewColors, removeThemeFile, resolveColors, saveThemeFile, undoTheme, useTheme, } from '../core/themes.js';
|
|
40
40
|
import { MIN_CALLS } from '../core/tuning.js';
|
|
41
41
|
import { onUntil, setAnswerWait, setUnattendedSchedule, turnUnattendedOff, turnUnattendedOn, unattendedStatus, } from '../core/unattended.js';
|
|
@@ -45,14 +45,16 @@ import { listPendingDecisions, markPendingDone, reopenPendingDecisions } from '.
|
|
|
45
45
|
import { readUnattendedConfig } from '../core/unattended-state.js';
|
|
46
46
|
import * as update from '../core/update.js';
|
|
47
47
|
import { buildId, localBuild, packageVersion } from '../core/version.js';
|
|
48
|
+
import { quotaWatchDirs } from '../families/quota-watch.js';
|
|
48
49
|
import { HOOK_FAMILIES } from '../handoff/hook.js';
|
|
49
50
|
import { MENUBAR_AGENT } from '../menubar/agent.js';
|
|
50
51
|
import { hotkeyView, iconView, openMenuBarSettings, readMenubarState, setMenubarHotkey, } from '../menubar/hotkey.js';
|
|
51
52
|
import { MENUBAR_SCRIPT } from '../menubar/script.js';
|
|
52
53
|
import { renderNetworkPage } from '../network/page.js';
|
|
54
|
+
import { createChangeFeed, stateQuotaDir } from './changes.js';
|
|
53
55
|
import { orcaTabs, switchOrcaTab, systemOrca } from './orca.js';
|
|
54
56
|
import { renderPage } from './page.js';
|
|
55
|
-
import { AI_TASK_KINDS } from './page-logic.js';
|
|
57
|
+
import { AI_TASK_KINDS, networkDiagnoseTaskFacts } from './page-logic.js';
|
|
56
58
|
import { tokenStyles } from './page-styles.js';
|
|
57
59
|
import { resolveTheme } from './theme.js';
|
|
58
60
|
import { BUILTIN_THEMES, DEFAULT_THEME_ID } from './themes.js';
|
|
@@ -273,14 +275,32 @@ export function handoffByFamily(rt, accounts, now, load) {
|
|
|
273
275
|
}
|
|
274
276
|
/** The plan behind each pick of `handoffByFamily`, spread by Room per Session when `load` is given (ADR-0083). */
|
|
275
277
|
export function handoffPlans(rt, accounts, now, load) {
|
|
278
|
+
return nextPicks(familyPlans(rt, accounts, now, load));
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* The plans that make a Next pick: a pick from Quota data, among two logins or more. Logins, not directories: a Same
|
|
282
|
+
* Login group (spec §3.21) is one Quota, so it alone is no alternative.
|
|
283
|
+
*/
|
|
284
|
+
function nextPicks(all) {
|
|
285
|
+
const out = {};
|
|
286
|
+
for (const [id, { plan, logins }] of Object.entries(all))
|
|
287
|
+
if (logins >= 2 && plan.pick && plan.hasQuota)
|
|
288
|
+
out[id] = plan;
|
|
289
|
+
return out;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* `sideby next`'s plan for every Family with a Quota source and a signed-in or unknown Subscription Account read
|
|
293
|
+
* already, with how many logins it has: the Next pick takes those with two or more, the "Best to use now" card
|
|
294
|
+
* (spec §3.45) every one.
|
|
295
|
+
*/
|
|
296
|
+
export function familyPlans(rt, accounts, now, load) {
|
|
276
297
|
const out = {};
|
|
277
298
|
for (const [id, f] of rt.families) {
|
|
278
299
|
// An Account still being read has no Quota yet; it is neither a pick nor an alternative until it has.
|
|
279
300
|
const list = accounts.filter((a) => a.family === id && !a.pending);
|
|
280
|
-
// Count logins, not directories: a Same Login group (spec §3.21) is one Quota, so it alone is no alternative.
|
|
281
301
|
const subs = list.filter((a) => a.kind === 'subscription');
|
|
282
302
|
const logins = subs.filter((a, i) => !subs.slice(0, i).some((b) => a.sameLogin?.includes(b.ref))).length;
|
|
283
|
-
if ((!f.readQuota && !f.fetchQuota) || logins <
|
|
303
|
+
if ((!f.readQuota && !f.fetchQuota) || logins < 1)
|
|
284
304
|
continue;
|
|
285
305
|
const plan = planHandoff(id, list.map((a) => ({
|
|
286
306
|
ref: a.ref,
|
|
@@ -300,11 +320,35 @@ export function handoffPlans(rt, accounts, now, load) {
|
|
|
300
320
|
// Counted over every Account, also one still being read, so a Same Login partner's sessions count.
|
|
301
321
|
...(load ? { picks: load.picks, live: load.live } : {}),
|
|
302
322
|
});
|
|
303
|
-
|
|
304
|
-
out[id] = plan;
|
|
323
|
+
out[id] = { plan, logins };
|
|
305
324
|
}
|
|
306
325
|
return out;
|
|
307
326
|
}
|
|
327
|
+
/** The "Best to use now" card's entry of a Family's plan (spec §3.45). */
|
|
328
|
+
export function pickNowOf(plan) {
|
|
329
|
+
const chosen = plan.accounts.find((e) => e.ref === plan.pick);
|
|
330
|
+
if (plan.pick && plan.hasQuota) {
|
|
331
|
+
const reason = plan.reason ?? (plan.tight ? 'tight' : chosen?.state === 'unknown' ? 'unknown' : undefined);
|
|
332
|
+
return {
|
|
333
|
+
pick: plan.pick,
|
|
334
|
+
hasQuota: true,
|
|
335
|
+
...(reason ? { reason } : {}),
|
|
336
|
+
...(chosen?.liveSessions ? { running: chosen.liveSessions } : {}),
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
// No Subscription Account that can start (signed out, or its sign-in expired): signing in comes first.
|
|
340
|
+
const subs = plan.accounts.filter((e) => e.kind === 'subscription');
|
|
341
|
+
if (!subs.some((e) => e.state !== 'logged-out' && !blocked(e)))
|
|
342
|
+
return { pick: null, hasQuota: plan.hasQuota, why: 'signed-out' };
|
|
343
|
+
if (!plan.hasQuota)
|
|
344
|
+
return { pick: null, hasQuota: false, why: 'no-quota' };
|
|
345
|
+
return {
|
|
346
|
+
pick: null,
|
|
347
|
+
hasQuota: true,
|
|
348
|
+
why: 'used-up',
|
|
349
|
+
...(plan.earliestReset ? { earliestReset: plan.earliestReset } : {}),
|
|
350
|
+
};
|
|
351
|
+
}
|
|
308
352
|
class HttpError extends Error {
|
|
309
353
|
status;
|
|
310
354
|
/** Machine-readable reason the page acts on, such as `bad-token`. */
|
|
@@ -471,52 +515,62 @@ function optBool(body, key) {
|
|
|
471
515
|
throw new HttpError(400, `"${key}" must be true or false`);
|
|
472
516
|
return v;
|
|
473
517
|
}
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
const
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
const
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
518
|
+
function settle(p) {
|
|
519
|
+
return p.then((value) => ({ value }), (err) => ({ error: err.message }));
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* Starts the reads of one Account. `full` is its whole state. Usage parses session logs and can take far longer than
|
|
523
|
+
* the rest on a cold start, so `quick()` gives the state without it (`usagePending`) once the rest is in, or null
|
|
524
|
+
* while it is not.
|
|
525
|
+
*/
|
|
526
|
+
function accountState(rt, account, families) {
|
|
527
|
+
const status = settle(rt.status(account));
|
|
528
|
+
// The kept answer of a Quota check shows now; a stale one is asked again behind it (spec §3.26).
|
|
529
|
+
const quota = settle(rt.quota(account, { fetch: 'background' }));
|
|
530
|
+
const usage = settle(rt.usage(account));
|
|
531
|
+
let restIn = false;
|
|
532
|
+
void Promise.all([status, quota]).then(() => {
|
|
533
|
+
restIn = true;
|
|
534
|
+
});
|
|
535
|
+
const build = async (u) => {
|
|
536
|
+
const [s, q] = await Promise.all([status, quota]);
|
|
537
|
+
const errors = [s.error, q.error, u?.error].filter((e) => e !== undefined);
|
|
538
|
+
const fam = families.find((f) => f.id === account.family);
|
|
539
|
+
const base = s.value ?? {
|
|
540
|
+
...account,
|
|
541
|
+
familyTitle: fam?.title ?? account.family,
|
|
542
|
+
hostInstalled: fam?.installed ?? false,
|
|
543
|
+
login: 'unknown',
|
|
544
|
+
};
|
|
545
|
+
errors.push(...(s.value?.problems ?? []));
|
|
546
|
+
let modelInfo;
|
|
547
|
+
if (rt.families.get(account.family)?.modelChoice) {
|
|
548
|
+
const used = u?.value;
|
|
549
|
+
// Given even when empty: without it `accountModel` would wait for the usage itself.
|
|
550
|
+
const last = used?.status === 'ok'
|
|
551
|
+
? {
|
|
552
|
+
...(used.lastModel ? { model: used.lastModel } : {}),
|
|
553
|
+
...(used.lastEffort ? { effort: used.lastEffort } : {}),
|
|
554
|
+
}
|
|
555
|
+
: {};
|
|
556
|
+
try {
|
|
557
|
+
const { ref: _r, family: _f, ...rest } = await accountModel(rt, account, last);
|
|
558
|
+
modelInfo = rest;
|
|
559
|
+
}
|
|
560
|
+
catch (err) {
|
|
561
|
+
errors.push(err.message);
|
|
505
562
|
}
|
|
506
|
-
: {};
|
|
507
|
-
const info = await guard(accountModel(rt, account, last));
|
|
508
|
-
if (info) {
|
|
509
|
-
const { ref: _r, family: _f, ...rest } = info;
|
|
510
|
-
modelInfo = rest;
|
|
511
563
|
}
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
564
|
+
return {
|
|
565
|
+
...base,
|
|
566
|
+
...(modelInfo ? { modelInfo } : {}),
|
|
567
|
+
...(q.value ? { quota: q.value } : {}),
|
|
568
|
+
...(u?.value ? { usage: u.value } : {}),
|
|
569
|
+
...(u ? {} : { usagePending: true }),
|
|
570
|
+
...(errors.length ? { error: errors.join('; ') } : {}),
|
|
571
|
+
};
|
|
519
572
|
};
|
|
573
|
+
return { full: usage.then(build), quick: () => (restIn ? build(undefined) : null) };
|
|
520
574
|
}
|
|
521
575
|
/** The model an advisor request asks for, and the Account it is limited to (a ref), checked. */
|
|
522
576
|
async function advisorBody(rt, body) {
|
|
@@ -544,10 +598,32 @@ function advisorView(st, home) {
|
|
|
544
598
|
* answer. Mutable for tests only.
|
|
545
599
|
*/
|
|
546
600
|
export const readBudget = { ms: 2000, hungMs: 60_000 };
|
|
601
|
+
/** How long a state waits, once `readBudget` is over, for an Account's state without its usage. */
|
|
602
|
+
const QUICK_MS = 500;
|
|
547
603
|
/** An answer kept longer than this is not used: the next state reads the Account again. */
|
|
548
604
|
const KEPT_MS = 30_000;
|
|
549
|
-
/**
|
|
550
|
-
|
|
605
|
+
/** Forgets every read and every last state: after a change, nothing read before it is shown. */
|
|
606
|
+
function clearReadings(r) {
|
|
607
|
+
r.going.clear();
|
|
608
|
+
r.last.clear();
|
|
609
|
+
}
|
|
610
|
+
/** A read that began longer ago than this goes on after a file change: a cold first read can take a minute. */
|
|
611
|
+
const REREAD_MS = 5000;
|
|
612
|
+
/**
|
|
613
|
+
* After a file Quota lands in changed (spec §3.45): the next state reads again instead of using a read from before
|
|
614
|
+
* the change. The last states stay, for slow rows meanwhile.
|
|
615
|
+
*/
|
|
616
|
+
function dropEarlyReadings(r, now) {
|
|
617
|
+
for (const [ref, reading] of r.going)
|
|
618
|
+
if (reading.done || now - reading.started < REREAD_MS)
|
|
619
|
+
r.going.delete(ref);
|
|
620
|
+
}
|
|
621
|
+
/**
|
|
622
|
+
* The Account's state within `readBudget`. While its reads go on: its last complete state (`refreshing`), or else
|
|
623
|
+
* the state without its usage once the rest is in (`usagePending`), or else a pending placeholder.
|
|
624
|
+
*/
|
|
625
|
+
async function timedAccountState(rt, account, families, readings) {
|
|
626
|
+
const mine = readings.going;
|
|
551
627
|
const fam = families.find((f) => f.id === account.family);
|
|
552
628
|
const placeholder = async (extra) => {
|
|
553
629
|
// Its Same Login is known without the slow reads, so its rows stay grouped meanwhile.
|
|
@@ -561,21 +637,53 @@ async function timedAccountState(rt, account, families, mine) {
|
|
|
561
637
|
...extra,
|
|
562
638
|
};
|
|
563
639
|
};
|
|
640
|
+
const last = () => {
|
|
641
|
+
const st = readings.last.get(account.ref);
|
|
642
|
+
return st ? { ...st, refreshing: true } : null;
|
|
643
|
+
};
|
|
644
|
+
// The state without usage still asks the model reader, which a plugin may make slow: it gets a short wait only.
|
|
645
|
+
const partial = async (r) => {
|
|
646
|
+
const quick = r.quick();
|
|
647
|
+
if (!quick)
|
|
648
|
+
return null;
|
|
649
|
+
let timer;
|
|
650
|
+
const late = new Promise((done) => {
|
|
651
|
+
timer = setTimeout(() => done(null), QUICK_MS);
|
|
652
|
+
});
|
|
653
|
+
try {
|
|
654
|
+
return await Promise.race([quick.catch(() => null), late]);
|
|
655
|
+
}
|
|
656
|
+
finally {
|
|
657
|
+
clearTimeout(timer);
|
|
658
|
+
}
|
|
659
|
+
};
|
|
564
660
|
let r = mine.get(account.ref);
|
|
565
661
|
if (r?.done && Date.now() - r.done.at > KEPT_MS)
|
|
566
662
|
r = undefined;
|
|
567
|
-
// A read still going after `readBudget.hungMs` has hung (a plugin reader, a Host that never answers).
|
|
663
|
+
// A read still going after `readBudget.hungMs` has hung (a plugin reader, a Host that never answers). A first read
|
|
664
|
+
// on a cold start can parse usage for longer than that: while the rest is in, it goes on.
|
|
568
665
|
if (r && !r.done && Date.now() - r.started > readBudget.hungMs) {
|
|
569
|
-
|
|
666
|
+
const early = last() ? null : await partial(r);
|
|
667
|
+
if (early)
|
|
668
|
+
return early;
|
|
669
|
+
// Dropped, so the next state starts a new read; this one shows the last state, or says what happened instead
|
|
670
|
+
// of spinning on.
|
|
570
671
|
mine.delete(account.ref);
|
|
672
|
+
const shown = last();
|
|
673
|
+
if (shown)
|
|
674
|
+
return shown;
|
|
571
675
|
return placeholder({
|
|
572
676
|
error: `reading this account took longer than ${Math.round(readBudget.hungMs / 1000)} s; refresh to try again`,
|
|
573
677
|
});
|
|
574
678
|
}
|
|
575
679
|
if (!r) {
|
|
576
|
-
const
|
|
680
|
+
const read = accountState(rt, account, families);
|
|
681
|
+
const fresh = { promise: read.full, quick: read.quick, started: Date.now() };
|
|
577
682
|
fresh.promise.then((state) => {
|
|
578
683
|
fresh.done = { state, at: Date.now() };
|
|
684
|
+
// Not a read a change has since dropped: its state is from before the change.
|
|
685
|
+
if (mine.get(account.ref) === fresh)
|
|
686
|
+
readings.last.set(account.ref, state);
|
|
579
687
|
}, () => undefined);
|
|
580
688
|
mine.set(account.ref, fresh);
|
|
581
689
|
r = fresh;
|
|
@@ -603,7 +711,7 @@ async function timedAccountState(rt, account, families, mine) {
|
|
|
603
711
|
mine.delete(account.ref);
|
|
604
712
|
return state;
|
|
605
713
|
}
|
|
606
|
-
return placeholder({ pending: true });
|
|
714
|
+
return last() ?? (await partial(reading)) ?? placeholder({ pending: true });
|
|
607
715
|
}
|
|
608
716
|
async function buildState(rt, opts) {
|
|
609
717
|
// Read alongside the Accounts, so waiting for it adds little.
|
|
@@ -623,9 +731,10 @@ async function buildState(rt, opts) {
|
|
|
623
731
|
? await rt.networkStatus().catch(() => undefined)
|
|
624
732
|
: undefined;
|
|
625
733
|
// Reads of Accounts that are gone are dropped.
|
|
626
|
-
for (const
|
|
627
|
-
|
|
628
|
-
|
|
734
|
+
for (const map of [opts.readings.going, opts.readings.last])
|
|
735
|
+
for (const ref of map.keys())
|
|
736
|
+
if (!accounts.some((a) => a.ref === ref))
|
|
737
|
+
map.delete(ref);
|
|
629
738
|
const aliases = aliasesByAccount(aliasRefs(rt.config.aliases), accounts);
|
|
630
739
|
// Asks in flight before the reads start: one that ends while they run may have left a row with the older numbers.
|
|
631
740
|
const askingOf = () => accounts.filter((a) => quotaAsking(rt.paths.stateDir, a.family, a.name)).map((a) => a.ref);
|
|
@@ -660,9 +769,14 @@ async function buildState(rt, opts) {
|
|
|
660
769
|
const ref = key.slice(0, key.indexOf('\0'));
|
|
661
770
|
live.set(ref, (live.get(ref) ?? 0) + 1);
|
|
662
771
|
}
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
772
|
+
// Unknown running sessions leave the Next pick out; the card ranks as if none ran, so it never reads "nothing".
|
|
773
|
+
const load = keys ? { live, picks: await readPickRecords(rt.paths.stateDir, ctx.now) } : undefined;
|
|
774
|
+
const every = familyPlans(rt, list, ctx.now, load);
|
|
775
|
+
const plans = keys ? nextPicks(every) : {};
|
|
776
|
+
// A tool whose quota has only per-model windows (Antigravity CLI) never ranks by quota, so it gets no card.
|
|
777
|
+
const pickNow = Object.fromEntries(Object.entries(every)
|
|
778
|
+
.filter(([f, { plan }]) => plan.hasQuota || !list.some((a) => a.family === f && a.quota?.status === 'ok'))
|
|
779
|
+
.map(([f, { plan }]) => [f, pickNowOf(plan)]));
|
|
666
780
|
const handoff = Object.fromEntries(Object.entries(plans).map(([f, p]) => [f, p.pick]));
|
|
667
781
|
const handoffRunning = Object.fromEntries(Object.entries(plans).flatMap(([f, p]) => {
|
|
668
782
|
const n = p.accounts.find((e) => e.ref === p.pick)?.liveSessions ?? 0;
|
|
@@ -722,6 +836,7 @@ async function buildState(rt, opts) {
|
|
|
722
836
|
...(Object.keys(handoff).length ? { handoff } : {}),
|
|
723
837
|
...(Object.keys(handoffRunning).length ? { handoffRunning } : {}),
|
|
724
838
|
...(Object.keys(handoffReason).length ? { handoffReason } : {}),
|
|
839
|
+
...(Object.keys(pickNow).length ? { pickNow } : {}),
|
|
725
840
|
...(remoteControl.length ? { remoteControl: rcView(remoteControl, ctx.home) } : {}),
|
|
726
841
|
...(advisor.groups.length ? { advisor: advisorView(advisor, ctx.home) } : {}),
|
|
727
842
|
...(appProfiles.length
|
|
@@ -1110,8 +1225,38 @@ export function createPanelHandler(opts) {
|
|
|
1110
1225
|
const openBridge = resolveBridge('open', opts.open);
|
|
1111
1226
|
const token = randomBytes(32).toString('base64url');
|
|
1112
1227
|
const serial = writeQueue();
|
|
1113
|
-
const readings = new Map();
|
|
1228
|
+
const readings = { going: new Map(), last: new Map() };
|
|
1114
1229
|
const getRuntime = typeof opts.runtime === 'function' ? opts.runtime : async () => opts.runtime;
|
|
1230
|
+
// Recent facts this server actually returned, keyed by their complete redacted serialization. Client-supplied
|
|
1231
|
+
// diagnosis text is only a lookup key: arbitrary instructions never become a fixed AI Task prompt.
|
|
1232
|
+
const networkFacts = new Map();
|
|
1233
|
+
const rememberNetworkFacts = (diagnosis) => {
|
|
1234
|
+
const facts = networkDiagnoseTaskFacts(diagnosis);
|
|
1235
|
+
const key = JSON.stringify(facts);
|
|
1236
|
+
networkFacts.delete(key);
|
|
1237
|
+
networkFacts.set(key, facts);
|
|
1238
|
+
while (networkFacts.size > 8)
|
|
1239
|
+
networkFacts.delete(networkFacts.keys().next().value);
|
|
1240
|
+
return diagnosis;
|
|
1241
|
+
};
|
|
1242
|
+
const actualAskPrompt = async (rt, input) => {
|
|
1243
|
+
if (view === 'network') {
|
|
1244
|
+
const supplied = input.context?.networkDiagnose;
|
|
1245
|
+
const facts = supplied && networkFacts.get(JSON.stringify(supplied));
|
|
1246
|
+
if (!facts)
|
|
1247
|
+
throw new HttpError(400, 'Run the Network diagnosis again and use its current redacted facts; nothing was opened.', 'network-facts-mismatch');
|
|
1248
|
+
input = { ...input, context: { ...input.context, networkDiagnose: facts } };
|
|
1249
|
+
}
|
|
1250
|
+
return promptForTask(rt, input, await previewAttachments(rt, input));
|
|
1251
|
+
};
|
|
1252
|
+
// Quota files watched while a page asks (spec §3.45, ADR-0084).
|
|
1253
|
+
const changes = createChangeFeed({
|
|
1254
|
+
dirs: async () => {
|
|
1255
|
+
const rt = await getRuntime();
|
|
1256
|
+
return [stateQuotaDir(rt.paths.stateDir), ...quotaWatchDirs(await rt.accounts())];
|
|
1257
|
+
},
|
|
1258
|
+
onChange: () => dropEarlyReadings(readings, Date.now()),
|
|
1259
|
+
});
|
|
1115
1260
|
const sessionsSource = opts[LIVE_SESSIONS_SOURCE];
|
|
1116
1261
|
const liveSessions = sessionsSource?.list ?? listLiveSessions;
|
|
1117
1262
|
// A change from this page can end a stretch of Unattended Mode: the plugins hear of it now, as after the CLI. The
|
|
@@ -1127,13 +1272,13 @@ export function createPanelHandler(opts) {
|
|
|
1127
1272
|
// Session History loads node:sqlite only when the page first asks for it.
|
|
1128
1273
|
let historyMod;
|
|
1129
1274
|
const history = () => (historyMod ??= import('../core/history.js'));
|
|
1130
|
-
// Which Sessions run now, for the "running" mark of History rows: read at most every 5 s, given 3 s.
|
|
1131
1275
|
const LIVE_FIRST_MS = 300;
|
|
1132
1276
|
// How long the page state waits for the first list of running sessions before it leaves the Next pick out.
|
|
1133
1277
|
const LIVE_STATE_MS = 3_000;
|
|
1134
1278
|
let liveMark;
|
|
1135
|
-
// Which
|
|
1136
|
-
// one while a fresh one is read, and waits
|
|
1279
|
+
// Which Sessions run now, for the "running" mark of History rows: read at most every 5 s, given 3 s. A search
|
|
1280
|
+
// never waits for that list once one is known: it answers with the last one while a fresh one is read, and waits
|
|
1281
|
+
// at most LIVE_FIRST_MS for the very first.
|
|
1137
1282
|
const liveRead = (rt) => {
|
|
1138
1283
|
if (!liveMark || Date.now() - liveMark.at > 5_000) {
|
|
1139
1284
|
const ids = (sessionsSource?.list ? sessionsSource.list(rt) : listLiveSessions(rt, { deadlineMs: 3_000 }))
|
|
@@ -1247,13 +1392,18 @@ export function createPanelHandler(opts) {
|
|
|
1247
1392
|
};
|
|
1248
1393
|
},
|
|
1249
1394
|
});
|
|
1250
|
-
const checkNetworkAsk = (body) => {
|
|
1395
|
+
const checkNetworkAsk = (body, confirmed = false) => {
|
|
1251
1396
|
if (view !== 'network')
|
|
1252
1397
|
return;
|
|
1253
1398
|
if (body.task !== 'network-diagnose')
|
|
1254
1399
|
throw new HttpError(400, 'the Network Panel only runs its fixed diagnosis task');
|
|
1255
|
-
|
|
1256
|
-
|
|
1400
|
+
const allowed = ['task', 'lang', 'context', ...(confirmed ? ['confirmedPrompt'] : [])];
|
|
1401
|
+
if (Object.keys(body).some((k) => !allowed.includes(k)))
|
|
1402
|
+
throw new HttpError(400, confirmed
|
|
1403
|
+
? 'the fixed network diagnosis accepts only task, lang, diagnostic context and confirmedPrompt'
|
|
1404
|
+
: 'the fixed network diagnosis accepts only task, lang and diagnostic context');
|
|
1405
|
+
if (confirmed && (typeof body.confirmedPrompt !== 'string' || !body.confirmedPrompt.trim()))
|
|
1406
|
+
throw new HttpError(400, 'Preview again and send the exact prompt as confirmedPrompt; nothing was opened.', 'network-prompt-required');
|
|
1257
1407
|
const context = body.context;
|
|
1258
1408
|
if (!context || typeof context !== 'object' || Array.isArray(context))
|
|
1259
1409
|
throw new HttpError(400, 'the fixed network diagnosis requires its diagnostic context');
|
|
@@ -1263,8 +1413,7 @@ export function createPanelHandler(opts) {
|
|
|
1263
1413
|
throw new HttpError(400, 'the fixed network diagnosis requires networkDiagnose facts');
|
|
1264
1414
|
};
|
|
1265
1415
|
const routes = {
|
|
1266
|
-
// AI Tasks (spec §3.28, ADR-0027).
|
|
1267
|
-
// the copy fallback and the read-only Panel.
|
|
1416
|
+
// AI Tasks (spec §3.28, ADR-0027).
|
|
1268
1417
|
// Frees a staged upload the person removed from the dialog, so it stops counting toward the staging limit.
|
|
1269
1418
|
'/api/ask/attach/remove': {
|
|
1270
1419
|
async run(body) {
|
|
@@ -1275,6 +1424,8 @@ export function createPanelHandler(opts) {
|
|
|
1275
1424
|
return { removed: await removeStaged(rt.paths, ids) };
|
|
1276
1425
|
},
|
|
1277
1426
|
},
|
|
1427
|
+
// The prompt and the account it would use, read only: for the confirm area, the copy fallback and the read-only
|
|
1428
|
+
// Panel.
|
|
1278
1429
|
'/api/ask/prompt': {
|
|
1279
1430
|
writes: () => false,
|
|
1280
1431
|
queued: false,
|
|
@@ -1282,7 +1433,7 @@ export function createPanelHandler(opts) {
|
|
|
1282
1433
|
checkNetworkAsk(body);
|
|
1283
1434
|
const input = askInput(body);
|
|
1284
1435
|
const rt = await getRuntime();
|
|
1285
|
-
const { prompt, removedSecrets } =
|
|
1436
|
+
const { prompt, removedSecrets } = await actualAskPrompt(rt, input);
|
|
1286
1437
|
const pick = await pickTaskAccount(rt, input);
|
|
1287
1438
|
return {
|
|
1288
1439
|
prompt,
|
|
@@ -1299,16 +1450,19 @@ export function createPanelHandler(opts) {
|
|
|
1299
1450
|
// Writes the task file and opens the terminal. An account the person picked, API ones too, is kept as `ask.account`.
|
|
1300
1451
|
'/api/ask': {
|
|
1301
1452
|
async run(body) {
|
|
1302
|
-
checkNetworkAsk(body);
|
|
1453
|
+
checkNetworkAsk(body, true);
|
|
1303
1454
|
const input = askInput(body);
|
|
1304
1455
|
const rt = await getRuntime();
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1456
|
+
if (view === 'network') {
|
|
1457
|
+
const actual = await actualAskPrompt(rt, input);
|
|
1458
|
+
if (actual.prompt !== body.confirmedPrompt)
|
|
1459
|
+
throw new HttpError(400, 'The network diagnosis prompt changed. Preview again and confirm the exact new prompt; nothing was opened.', 'network-prompt-mismatch');
|
|
1460
|
+
// Write the exact server-generated prompt that was compared above; do not generate it again after an await.
|
|
1461
|
+
const result = opened(await openPromptTask(rt, { ...input, terminal: 'orca', remember: false }, { taskId: newTaskId(), ...actual, attachments: [] }));
|
|
1462
|
+
const { account: _account, ...withoutAccount } = result;
|
|
1463
|
+
return withoutAccount;
|
|
1464
|
+
}
|
|
1465
|
+
return opened(await startAiTask(rt, { ...input, remember: Boolean(input.account || input.terminal) }));
|
|
1312
1466
|
},
|
|
1313
1467
|
},
|
|
1314
1468
|
// Runs `sideby login <ref>` in the person's terminal; no AI is involved (spec §3.28 "登录").
|
|
@@ -1455,20 +1609,25 @@ export function createPanelHandler(opts) {
|
|
|
1455
1609
|
},
|
|
1456
1610
|
// Pick Commands (spec §3.13, ADR-0035): start the Account with the most room in the Preferred Terminal, add one
|
|
1457
1611
|
// (a name that hides a command on PATH comes back as `confirm` until the page sends confirm: true), remove one.
|
|
1612
|
+
// `family` instead of `name`: the "Best to use now" card (spec §3.45), the Family's Pick Command when it has one,
|
|
1613
|
+
// else the same rules without one.
|
|
1458
1614
|
'/api/pick/start': {
|
|
1459
1615
|
async run(body) {
|
|
1460
|
-
const
|
|
1461
|
-
if (!name)
|
|
1462
|
-
throw new HttpError(400, '"name" is required');
|
|
1616
|
+
const fam = optString(body, 'family');
|
|
1463
1617
|
const rt = await getRuntime();
|
|
1618
|
+
const name = optString(body, 'name') ??
|
|
1619
|
+
(fam ? Object.entries(rt.config.pickCommands ?? {}).find(([, f]) => f === fam)?.[0] : undefined);
|
|
1620
|
+
if (!name && !fam)
|
|
1621
|
+
throw new HttpError(400, '"name" or "family" is required');
|
|
1464
1622
|
// This start counts for the next pick, so its record is written now (ADR-0083).
|
|
1465
1623
|
let rec;
|
|
1466
|
-
const
|
|
1624
|
+
const po = {
|
|
1467
1625
|
record: true,
|
|
1468
1626
|
recorded: (r) => {
|
|
1469
1627
|
rec = r;
|
|
1470
1628
|
},
|
|
1471
|
-
}
|
|
1629
|
+
};
|
|
1630
|
+
const { family, choice } = name ? await rt.pickChoice(name, po) : await rt.familyPick(fam, po);
|
|
1472
1631
|
if (choice.ref === null)
|
|
1473
1632
|
throw new UserError(choice.earliestReset
|
|
1474
1633
|
? `Every signed-in ${family} account has used up its quota; ${choice.earliestReset.ref} is back first.`
|
|
@@ -1484,7 +1643,7 @@ export function createPanelHandler(opts) {
|
|
|
1484
1643
|
await rt.cancelPick(rec);
|
|
1485
1644
|
return {
|
|
1486
1645
|
...r,
|
|
1487
|
-
name,
|
|
1646
|
+
...(name ? { name } : {}),
|
|
1488
1647
|
family,
|
|
1489
1648
|
picked: choice.ref,
|
|
1490
1649
|
reason: choice.reason,
|
|
@@ -1929,10 +2088,6 @@ export function createPanelHandler(opts) {
|
|
|
1929
2088
|
return { switched: true };
|
|
1930
2089
|
},
|
|
1931
2090
|
},
|
|
1932
|
-
// "Send to it" (spec §3.32 step 2): text and the screenshots staged through SEND_ATTACH_ROUTE go to one Live
|
|
1933
|
-
// Session through sendMessage, which keeps the Message as a file before any delivery. The page sends only the
|
|
1934
|
-
// Session id. It writes files, so a read-only Panel refuses it (writes defaults to true); it runs beside the
|
|
1935
|
-
// write queue because a delivery may wait on the Host.
|
|
1936
2091
|
// Opens the Run Board of a Session (spec §3.32 step 2b, ADR-0041). The page sends only the Session id: the board
|
|
1937
2092
|
// file is found again here, from the Session Index, and checked again. It starts a program, so a read-only Panel
|
|
1938
2093
|
// refuses it (writes defaults to true).
|
|
@@ -1947,6 +2102,10 @@ export function createPanelHandler(opts) {
|
|
|
1947
2102
|
return { opened: true, board: tildify(r.board, rt.paths.home) };
|
|
1948
2103
|
},
|
|
1949
2104
|
},
|
|
2105
|
+
// "Send to it" (spec §3.32 step 2): text and the screenshots staged through SEND_ATTACH_ROUTE go to one Live
|
|
2106
|
+
// Session through sendMessage, which keeps the Message as a file before any delivery. The page sends only the
|
|
2107
|
+
// Session id. It writes files, so a read-only Panel refuses it (writes defaults to true); it runs beside the
|
|
2108
|
+
// write queue because a delivery may wait on the Host.
|
|
1950
2109
|
'/api/sessions/send': {
|
|
1951
2110
|
queued: false,
|
|
1952
2111
|
async run(body) {
|
|
@@ -2248,7 +2407,8 @@ export function createPanelHandler(opts) {
|
|
|
2248
2407
|
'/api/network/diagnose': {
|
|
2249
2408
|
writes: () => false,
|
|
2250
2409
|
async run() {
|
|
2251
|
-
|
|
2410
|
+
const diagnosis = await (await getRuntime()).networkDiagnose();
|
|
2411
|
+
return view === 'network' ? rememberNetworkFacts(diagnosis) : diagnosis;
|
|
2252
2412
|
},
|
|
2253
2413
|
},
|
|
2254
2414
|
// Network Guard's switch and countries (spec §3.35): config `network`, shown first like every config change.
|
|
@@ -2781,6 +2941,16 @@ export function createPanelHandler(opts) {
|
|
|
2781
2941
|
send(res, 200, await loginItemView(rt, sub === '/api/menubar' ? MENUBAR_AGENT : PANEL_AGENT));
|
|
2782
2942
|
return true;
|
|
2783
2943
|
}
|
|
2944
|
+
// Held until a Quota file changes or 25 s pass (spec §3.45, ADR-0084).
|
|
2945
|
+
if (sub === '/api/changes') {
|
|
2946
|
+
const raw = new URL(req.url ?? '/', 'http://x').searchParams.get('since');
|
|
2947
|
+
const since = method === 'GET' && raw !== null && /^\d{1,15}$/.test(raw) ? Number(raw) : null;
|
|
2948
|
+
const gone = new Promise((done) => res.once('close', done));
|
|
2949
|
+
const answer = await changes.wait(since, gone);
|
|
2950
|
+
if (!res.destroyed)
|
|
2951
|
+
send(res, 200, answer);
|
|
2952
|
+
return true;
|
|
2953
|
+
}
|
|
2784
2954
|
if (sub === '/api/state') {
|
|
2785
2955
|
send(res, 200, await buildState(await getRuntime(), {
|
|
2786
2956
|
version,
|
|
@@ -2831,7 +3001,7 @@ export function createPanelHandler(opts) {
|
|
|
2831
3001
|
const result = await (route.queued === false ? route.run(body) : serial(() => route.run(body)));
|
|
2832
3002
|
// A change may concern an Account whose read began before it: the next state reads again.
|
|
2833
3003
|
if (route.writes?.(body) ?? true)
|
|
2834
|
-
readings
|
|
3004
|
+
clearReadings(readings);
|
|
2835
3005
|
send(res, 200, result);
|
|
2836
3006
|
return true;
|
|
2837
3007
|
}
|
package/dist/src/panel/i18n.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ declare const en: {
|
|
|
6
6
|
'top.loading': string;
|
|
7
7
|
'top.refreshing': string;
|
|
8
8
|
'top.updated': string;
|
|
9
|
+
'top.updatedLive': string;
|
|
10
|
+
'top.updatedTitleLive': string;
|
|
9
11
|
'top.updatedTitle': string;
|
|
10
12
|
'top.stale': string;
|
|
11
13
|
'foot.text': string;
|
|
@@ -153,6 +155,27 @@ declare const en: {
|
|
|
153
155
|
'stat.sessions.other': string;
|
|
154
156
|
'stat.nextReset': string;
|
|
155
157
|
'stat.noQuota': string;
|
|
158
|
+
'stat.pickNow': string;
|
|
159
|
+
'stat.pickNowIn': string;
|
|
160
|
+
'stat.pickLeft': string;
|
|
161
|
+
'stat.pickReset': string;
|
|
162
|
+
'stat.pickTight': string;
|
|
163
|
+
'stat.pickNoData': string;
|
|
164
|
+
'stat.pickStart': string;
|
|
165
|
+
'stat.pickStartTip': string;
|
|
166
|
+
'stat.pickCopy': string;
|
|
167
|
+
'stat.pickCopyTip': string;
|
|
168
|
+
'stat.pickOnly': string;
|
|
169
|
+
'stat.pickOthers': string;
|
|
170
|
+
'stat.pickUsedUp': string;
|
|
171
|
+
'stat.pickBack': string;
|
|
172
|
+
'stat.pickWait': string;
|
|
173
|
+
'stat.pickNoQuota': string;
|
|
174
|
+
'stat.pickNoQuotaTip': string;
|
|
175
|
+
'stat.pickSignIn': string;
|
|
176
|
+
'stat.pickNoSource': string;
|
|
177
|
+
'stat.pickNoSourceOne': string;
|
|
178
|
+
'stat.pickReading': string;
|
|
156
179
|
'need.error.one': string;
|
|
157
180
|
'need.error.other': string;
|
|
158
181
|
'need.health-fail.one': string;
|