sideby 0.35.6 → 0.35.8
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 +9 -1
- package/dist/src/cli/commands.js +59 -16
- package/dist/src/cli/json-schemas.js +20 -0
- package/dist/src/cli/main.js +11 -5
- package/dist/src/core/cli-commands.js +1 -1
- package/dist/src/core/config.d.ts +7 -0
- package/dist/src/core/config.js +9 -0
- package/dist/src/core/doctor.d.ts +5 -1
- package/dist/src/core/doctor.js +16 -0
- package/dist/src/core/edit-settings.d.ts +27 -1
- package/dist/src/core/edit-settings.js +78 -4
- package/dist/src/core/handoff-select.d.ts +3 -1
- package/dist/src/core/handoff-select.js +11 -1
- package/dist/src/core/handoff.d.ts +13 -1
- package/dist/src/core/handoff.js +16 -5
- package/dist/src/core/history-index.d.ts +4 -0
- package/dist/src/core/history-index.js +46 -17
- package/dist/src/core/history-project.js +15 -2
- package/dist/src/core/history.d.ts +11 -1
- package/dist/src/core/history.js +70 -16
- package/dist/src/core/login-mark.d.ts +3 -0
- package/dist/src/core/login-mark.js +22 -0
- package/dist/src/core/pick-commands.d.ts +4 -2
- package/dist/src/core/pick-commands.js +7 -2
- package/dist/src/core/quota-fetch.d.ts +7 -1
- package/dist/src/core/quota-fetch.js +38 -1
- package/dist/src/core/quota-store.d.ts +5 -0
- package/dist/src/core/quota-store.js +3 -0
- package/dist/src/core/search-catalog.js +9 -0
- package/dist/src/families/claude/index.js +3 -0
- package/dist/src/families/claude/login-events.d.ts +24 -0
- package/dist/src/families/claude/login-events.js +163 -0
- package/dist/src/families/claude/quota-fetch.js +14 -0
- package/dist/src/families/grok/bot.d.ts +6 -3
- package/dist/src/families/grok/bot.js +15 -4
- package/dist/src/menubar/snapshot.d.ts +2 -0
- package/dist/src/menubar/snapshot.js +6 -2
- package/dist/src/menubar/strings.d.ts +4 -0
- package/dist/src/menubar/strings.js +4 -0
- package/dist/src/panel/handler.d.ts +14 -1
- package/dist/src/panel/handler.js +48 -14
- 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 +44 -2
- package/dist/src/panel/page-logic.js +43 -3
- package/dist/src/panel/page-script.js +124 -7
- package/dist/src/panel/page-styles.js +8 -0
- package/dist/src/panel/page.d.ts +7 -0
- package/dist/src/panel/page.js +1 -0
- package/dist/src/runtime.d.ts +16 -1
- package/dist/src/runtime.js +51 -2
- package/dist/src/types.d.ts +37 -0
- package/package.json +3 -3
- package/schemas/config.json +11 -0
- package/schemas/edit.json +4 -0
- package/schemas/list.json +24 -0
- package/schemas/next.json +18 -0
- package/skills/sideby/SKILL.md +4 -2
- package/skills/sideby/references/accounts.md +9 -0
- package/skills/sideby/references/diagnose.md +6 -1
- package/skills/sideby/references/panel.md +1 -1
- package/skills/sideby/references/unattended.md +1 -1
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
// When Claude Code last said an Account's login expired, and when it last showed it working (ADR-0071), from the
|
|
2
|
+
// tail of its newest main session transcripts (`<dir>/projects/<project>/<session>.jsonl`). Claude Code writes an
|
|
3
|
+
// expired login as an assistant record with `isApiErrorMessage: true`, `error: "authentication_failed"` and a text
|
|
4
|
+
// such as "Login reached its time limit · Please run /login" (Claude Code 2.1.319, 2026-11-08). Only the two times
|
|
5
|
+
// are kept: never the transcript text, a token, the Keychain or `.credentials.json`.
|
|
6
|
+
import { readdir, stat } from 'node:fs/promises';
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
import { FileMemo } from '../../core/file-memo.js';
|
|
9
|
+
import { tailLinesWith } from './session-files.js';
|
|
10
|
+
/** How many of the newest main transcripts are read. */
|
|
11
|
+
export const LOGIN_SCAN_SESSIONS = 20;
|
|
12
|
+
/**
|
|
13
|
+
* Phrases Claude Code is known to use for an expired login, compared in lower case with every run of spaces and
|
|
14
|
+
* punctuation as one space. A `/login` hint or "Invalid API key" alone is not one: that is a different problem.
|
|
15
|
+
*/
|
|
16
|
+
export const EXPIRY_PHRASES = ['login reached its time limit'];
|
|
17
|
+
const plain = (text) => text
|
|
18
|
+
.toLowerCase()
|
|
19
|
+
.replace(/[^a-z0-9]+/g, ' ')
|
|
20
|
+
.trim();
|
|
21
|
+
/** Whether a Host message says the login expired, by the phrases above. */
|
|
22
|
+
export function saysLoginExpired(text) {
|
|
23
|
+
const t = ` ${plain(text)} `;
|
|
24
|
+
return EXPIRY_PHRASES.some((p) => t.includes(` ${p} `));
|
|
25
|
+
}
|
|
26
|
+
function textOf(message) {
|
|
27
|
+
const content = message?.content;
|
|
28
|
+
if (typeof content === 'string')
|
|
29
|
+
return content;
|
|
30
|
+
if (!Array.isArray(content))
|
|
31
|
+
return '';
|
|
32
|
+
return content
|
|
33
|
+
.map((b) => (b?.type === 'text' ? b.text : ''))
|
|
34
|
+
.filter((t) => typeof t === 'string')
|
|
35
|
+
.join('\n');
|
|
36
|
+
}
|
|
37
|
+
/** The newest expiry record and the newest normal assistant turn in the tail of one transcript. */
|
|
38
|
+
export async function transcriptLoginTimes(file) {
|
|
39
|
+
const out = {};
|
|
40
|
+
for (const line of await tailLinesWith(file, '"assistant"')) {
|
|
41
|
+
let row;
|
|
42
|
+
try {
|
|
43
|
+
row = JSON.parse(line);
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (row?.type !== 'assistant')
|
|
49
|
+
continue;
|
|
50
|
+
// A sub-agent's turn (`isSidechain`) says nothing about the main sign-in, as in history.ts.
|
|
51
|
+
if (row.isSidechain === true)
|
|
52
|
+
continue;
|
|
53
|
+
const at = typeof row.timestamp === 'string' ? Date.parse(row.timestamp) : Number.NaN;
|
|
54
|
+
if (!Number.isFinite(at))
|
|
55
|
+
continue;
|
|
56
|
+
const message = row.message;
|
|
57
|
+
if (row.isApiErrorMessage === true) {
|
|
58
|
+
if (row.error === 'authentication_failed' && saysLoginExpired(textOf(message)))
|
|
59
|
+
out.expiredAt = Math.max(out.expiredAt ?? at, at);
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
// Claude Code's own notices (interrupted, no response) carry the model `<synthetic>`: no model answered them.
|
|
63
|
+
if (message?.model === '<synthetic>' || row.error !== undefined)
|
|
64
|
+
continue;
|
|
65
|
+
out.workingAt = Math.max(out.workingAt ?? at, at);
|
|
66
|
+
}
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Each Account's last full listing: every main transcript with its modification time, and each project folder's own
|
|
71
|
+
* modification time when it was listed. A new or removed transcript changes its folder's time, so the listing is
|
|
72
|
+
* redone then; otherwise it is redone at most every `LISTING_MS`, and only the newest `LOGIN_SCAN_SESSIONS` are stat-ed
|
|
73
|
+
* again. A transcript outside them that grows (an old session resumed) is seen at the next full listing.
|
|
74
|
+
*/
|
|
75
|
+
const listings = new Map();
|
|
76
|
+
export const LISTING_MS = 60_000;
|
|
77
|
+
async function projectFolders(projects) {
|
|
78
|
+
let names;
|
|
79
|
+
try {
|
|
80
|
+
names = await readdir(projects, { withFileTypes: true });
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
const out = new Map();
|
|
86
|
+
for (const p of names) {
|
|
87
|
+
if (!p.isDirectory())
|
|
88
|
+
continue;
|
|
89
|
+
const st = await stat(join(projects, p.name)).catch(() => null);
|
|
90
|
+
if (st)
|
|
91
|
+
out.set(join(projects, p.name), st.mtimeMs);
|
|
92
|
+
}
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
95
|
+
const sameFolders = (a, b) => a.size === b.size && [...a].every(([k, v]) => b.get(k) === v);
|
|
96
|
+
async function statAll(files) {
|
|
97
|
+
const out = [];
|
|
98
|
+
for (const file of files) {
|
|
99
|
+
const st = await stat(file).catch(() => null);
|
|
100
|
+
if (st?.isFile())
|
|
101
|
+
out.push({ file, st });
|
|
102
|
+
}
|
|
103
|
+
return out.sort((a, b) => b.st.mtimeMs - a.st.mtimeMs);
|
|
104
|
+
}
|
|
105
|
+
/** The main transcripts of an Account, newest first, at most `LOGIN_SCAN_SESSIONS`. Subagent transcripts are left out. */
|
|
106
|
+
async function newestTranscripts(dir, now = Date.now()) {
|
|
107
|
+
const projects = join(dir, 'projects');
|
|
108
|
+
const folders = await projectFolders(projects);
|
|
109
|
+
if (!folders) {
|
|
110
|
+
listings.delete(dir);
|
|
111
|
+
return [];
|
|
112
|
+
}
|
|
113
|
+
const kept = listings.get(dir);
|
|
114
|
+
if (kept && now - kept.at < LISTING_MS && now >= kept.at && sameFolders(kept.folders, folders)) {
|
|
115
|
+
const top = await statAll(kept.files.slice(0, LOGIN_SCAN_SESSIONS).map((f) => f.file));
|
|
116
|
+
return top.slice(0, LOGIN_SCAN_SESSIONS);
|
|
117
|
+
}
|
|
118
|
+
const files = [];
|
|
119
|
+
for (const folder of folders.keys()) {
|
|
120
|
+
let entries;
|
|
121
|
+
try {
|
|
122
|
+
entries = await readdir(folder, { withFileTypes: true });
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
for (const e of entries)
|
|
128
|
+
if (e.isFile() && e.name.endsWith('.jsonl'))
|
|
129
|
+
files.push(join(folder, e.name));
|
|
130
|
+
}
|
|
131
|
+
const all = await statAll(files);
|
|
132
|
+
listings.set(dir, { folders, files: all.map((f) => ({ file: f.file, mtimeMs: f.st.mtimeMs })), at: now });
|
|
133
|
+
return all.slice(0, LOGIN_SCAN_SESSIONS);
|
|
134
|
+
}
|
|
135
|
+
/** Forgets every kept listing (for tests). */
|
|
136
|
+
export function clearLoginListings() {
|
|
137
|
+
listings.clear();
|
|
138
|
+
}
|
|
139
|
+
export const claudeLoginMemo = new FileMemo({ name: 'claude-login', version: 1 });
|
|
140
|
+
const iso = (t) => (t === undefined ? undefined : new Date(t).toISOString());
|
|
141
|
+
/** `FamilyDef.readLoginEvents` for Claude Code. An API Account is never checked. */
|
|
142
|
+
export async function readClaudeLoginEvents(account) {
|
|
143
|
+
if (account.kind === 'api')
|
|
144
|
+
return {};
|
|
145
|
+
const pass = claudeLoginMemo.pass(account.dir);
|
|
146
|
+
let expiredAt;
|
|
147
|
+
let workingAt;
|
|
148
|
+
try {
|
|
149
|
+
for (const { file, st } of await newestTranscripts(account.dir)) {
|
|
150
|
+
const t = await pass.get(file, st, () => transcriptLoginTimes(file));
|
|
151
|
+
if (t.expiredAt !== undefined)
|
|
152
|
+
expiredAt = Math.max(expiredAt ?? t.expiredAt, t.expiredAt);
|
|
153
|
+
if (t.workingAt !== undefined)
|
|
154
|
+
workingAt = Math.max(workingAt ?? t.workingAt, t.workingAt);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
finally {
|
|
158
|
+
pass.done();
|
|
159
|
+
}
|
|
160
|
+
const e = iso(expiredAt);
|
|
161
|
+
const w = iso(workingAt);
|
|
162
|
+
return { ...(e ? { expiredAt: e } : {}), ...(w ? { workingAt: w } : {}) };
|
|
163
|
+
}
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import { spawn } from 'node:child_process';
|
|
8
8
|
import { join } from 'node:path';
|
|
9
9
|
import { ownedFolder } from '../../core/fs-safe.js';
|
|
10
|
+
import { saysLoginExpired } from './login-events.js';
|
|
10
11
|
/**
|
|
11
12
|
* Hooks off and no MCP servers: a quota check is no session, so the user's hooks (notifications, loggers) must not
|
|
12
13
|
* run for it and no MCP server needs starting. `/usage` itself needs neither.
|
|
@@ -160,6 +161,19 @@ export function claudeUsageAnswer(answer, account, now) {
|
|
|
160
161
|
const windows = local ? usageQuota(text, now) : null;
|
|
161
162
|
if (windows)
|
|
162
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
|
+
// A model turn is never read for sign-in words: its text may merely quote them (it is not a local /usage either).
|
|
167
|
+
if (typeof a.num_turns === 'number' && a.num_turns > 0)
|
|
168
|
+
return failed('this Claude Code version cannot report quota through /usage; update Claude Code, then refresh');
|
|
169
|
+
// Only Claude Code's own error result counts as an expiry.
|
|
170
|
+
if (a.is_error === true && saysLoginExpired(text) && !/invalid api key/i.test(text))
|
|
171
|
+
return {
|
|
172
|
+
status: 'unavailable',
|
|
173
|
+
reason: 'fetch-failed',
|
|
174
|
+
detail: `Claude Code says the sign-in expired; run \`sideby login ${account.ref}\`, then refresh`,
|
|
175
|
+
loginExpired: true,
|
|
176
|
+
};
|
|
163
177
|
if (/not logged in|please (?:run )?\/login|please log ?in/i.test(text))
|
|
164
178
|
return failed(`Claude Code is not signed in; run \`sideby login ${account.ref}\`, then refresh`);
|
|
165
179
|
if (/using your API key|API usage billing/i.test(text))
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { ProfileAppDef } from '../desktop.ts';
|
|
2
2
|
/**
|
|
3
3
|
* Grok Bot (spec §3.20 "Grok Bot 窗口", ADR-0019). It signs in with a Cursor account, apart from every grok Account,
|
|
4
|
-
* so its windows are App Profiles.
|
|
5
|
-
* (`<dir>/sand-data`) move there.
|
|
6
|
-
*
|
|
4
|
+
* so its windows are App Profiles. SAND_USER_DATA_DIR is the app's isolated mode: userData and its data root
|
|
5
|
+
* (`<dir>/sand-data`) move there. Up to 0.71.x `--user-data-dir` did the same; from 0.79.3 the app sets userData
|
|
6
|
+
* back to its default and ignores the flag, so the new instance loses the single-instance lock to the main window
|
|
7
|
+
* and quits at once. `open --env` sets the variable for the app; the flag stays for older versions and because
|
|
8
|
+
* `instanceOf` finds the window by it. The caller's own SAND_DATA_ROOT and SAND_USER_DATA_DIR are cleared so only
|
|
9
|
+
* this folder counts. All of this is internal to the app and may change.
|
|
7
10
|
*/
|
|
8
11
|
export declare const grokBot: ProfileAppDef;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Grok Bot (spec §3.20 "Grok Bot 窗口", ADR-0019). It signs in with a Cursor account, apart from every grok Account,
|
|
3
|
-
* so its windows are App Profiles.
|
|
4
|
-
* (`<dir>/sand-data`) move there.
|
|
5
|
-
*
|
|
3
|
+
* so its windows are App Profiles. SAND_USER_DATA_DIR is the app's isolated mode: userData and its data root
|
|
4
|
+
* (`<dir>/sand-data`) move there. Up to 0.71.x `--user-data-dir` did the same; from 0.79.3 the app sets userData
|
|
5
|
+
* back to its default and ignores the flag, so the new instance loses the single-instance lock to the main window
|
|
6
|
+
* and quits at once. `open --env` sets the variable for the app; the flag stays for older versions and because
|
|
7
|
+
* `instanceOf` finds the window by it. The caller's own SAND_DATA_ROOT and SAND_USER_DATA_DIR are cleared so only
|
|
8
|
+
* this folder counts. All of this is internal to the app and may change.
|
|
6
9
|
*/
|
|
7
10
|
export const grokBot = {
|
|
8
11
|
id: 'grok-bot',
|
|
@@ -10,7 +13,15 @@ export const grokBot = {
|
|
|
10
13
|
bundleId: 'com.anysphere.sand',
|
|
11
14
|
bundleNames: ['Grok Bot.app'],
|
|
12
15
|
installUrl: 'https://x.ai/bot/',
|
|
13
|
-
openArgs: (app, appData) => [
|
|
16
|
+
openArgs: (app, appData) => [
|
|
17
|
+
'-n',
|
|
18
|
+
'-a',
|
|
19
|
+
app,
|
|
20
|
+
'--env',
|
|
21
|
+
`SAND_USER_DATA_DIR=${appData}`,
|
|
22
|
+
'--args',
|
|
23
|
+
`--user-data-dir=${appData}`,
|
|
24
|
+
],
|
|
14
25
|
clearVars: ['SAND_DATA_ROOT', 'SAND_USER_DATA_DIR'],
|
|
15
26
|
mainUserData: 'Library/Application Support/Grok Bot',
|
|
16
27
|
statusFile: 'desktop-status.json',
|
|
@@ -121,6 +121,8 @@ export interface MenubarFamilyInput {
|
|
|
121
121
|
name: string;
|
|
122
122
|
kind: Account['kind'];
|
|
123
123
|
login: LoginState | 'not-needed';
|
|
124
|
+
/** Its sign-in expired (an Expired Login, ADR-0071): marked in its row, never recommended. */
|
|
125
|
+
loginExpired?: true;
|
|
124
126
|
quota: QuotaResult;
|
|
125
127
|
/** The other refs of its Same Login: the same subscription, so one quota. */
|
|
126
128
|
sameLogin?: readonly string[];
|
|
@@ -233,6 +233,8 @@ function quotaRow(a, plan, now, s, refreshable, lang) {
|
|
|
233
233
|
return noted(s.api);
|
|
234
234
|
if (a.login === 'logged-out')
|
|
235
235
|
return noted(s.signedOut);
|
|
236
|
+
if (a.loginExpired)
|
|
237
|
+
return { ...noted(s.loginExpired), tip: fill(s.loginExpiredTip, { account: a.ref }) };
|
|
236
238
|
const quota = a.quota;
|
|
237
239
|
if (quota.status !== 'ok')
|
|
238
240
|
return noted(s.noData);
|
|
@@ -352,7 +354,9 @@ function section(f, now, s, lang) {
|
|
|
352
354
|
const group = all.filter((y) => y === x || (peers.has(y.a.ref) && !aside(y.a) && !done.has(y.a.ref)));
|
|
353
355
|
for (const y of group)
|
|
354
356
|
done.add(y.a.ref);
|
|
355
|
-
|
|
357
|
+
// The shared Quota stays on show: a directory whose sign-in expired does not lead the row while another works
|
|
358
|
+
// (ADR-0071); it is listed in the submenu with its mark.
|
|
359
|
+
const lead = group.find((y) => !y.a.loginExpired) ?? x;
|
|
356
360
|
const others = group.filter((y) => y !== lead);
|
|
357
361
|
shown.push(others.length
|
|
358
362
|
? {
|
|
@@ -365,7 +369,7 @@ function section(f, now, s, lang) {
|
|
|
365
369
|
}
|
|
366
370
|
: lead);
|
|
367
371
|
for (const y of others) {
|
|
368
|
-
const note = fill(s.sameLoginNote, { name: lead.a.name });
|
|
372
|
+
const note = y.a.loginExpired ? s.loginExpired : fill(s.sameLoginNote, { name: lead.a.name });
|
|
369
373
|
same.push({
|
|
370
374
|
...y,
|
|
371
375
|
r: {
|
|
@@ -19,6 +19,8 @@ export declare const MENUBAR_STRINGS: {
|
|
|
19
19
|
readonly recommended: 'next';
|
|
20
20
|
readonly api: 'API key';
|
|
21
21
|
readonly signedOut: 'signed out';
|
|
22
|
+
readonly loginExpired: '⚠ sign-in expired';
|
|
23
|
+
readonly loginExpiredTip: 'Its sign-in expired: run `sideby login {account}` (or use Sign in again in the Panel)';
|
|
22
24
|
readonly noData: 'no quota yet';
|
|
23
25
|
readonly olderReading: 'older reading';
|
|
24
26
|
readonly observedAt: 'Quota recorded at {time}';
|
|
@@ -86,6 +88,8 @@ export declare const MENUBAR_STRINGS: {
|
|
|
86
88
|
readonly recommended: '首选';
|
|
87
89
|
readonly api: 'API 密钥';
|
|
88
90
|
readonly signedOut: '未登录';
|
|
91
|
+
readonly loginExpired: '⚠ 登录已过期';
|
|
92
|
+
readonly loginExpiredTip: '登录已过期:运行 `sideby login {account}`(或在面板里点“重新登录”)';
|
|
89
93
|
readonly noData: '暂无额度';
|
|
90
94
|
readonly olderReading: '旧数据';
|
|
91
95
|
readonly observedAt: '额度记录时间:{time}';
|
|
@@ -19,6 +19,8 @@ export const MENUBAR_STRINGS = {
|
|
|
19
19
|
recommended: 'next',
|
|
20
20
|
api: 'API key',
|
|
21
21
|
signedOut: 'signed out',
|
|
22
|
+
loginExpired: '⚠ sign-in expired',
|
|
23
|
+
loginExpiredTip: 'Its sign-in expired: run `sideby login {account}` (or use Sign in again in the Panel)',
|
|
22
24
|
noData: 'no quota yet',
|
|
23
25
|
olderReading: 'older reading',
|
|
24
26
|
observedAt: 'Quota recorded at {time}',
|
|
@@ -86,6 +88,8 @@ export const MENUBAR_STRINGS = {
|
|
|
86
88
|
recommended: '首选',
|
|
87
89
|
api: 'API 密钥',
|
|
88
90
|
signedOut: '未登录',
|
|
91
|
+
loginExpired: '⚠ 登录已过期',
|
|
92
|
+
loginExpiredTip: '登录已过期:运行 `sideby login {account}`(或在面板里点“重新登录”)',
|
|
89
93
|
noData: '暂无额度',
|
|
90
94
|
olderReading: '旧数据',
|
|
91
95
|
observedAt: '额度记录时间:{time}',
|
|
@@ -2,7 +2,7 @@ import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
|
2
2
|
import { type AppProfileStatus } from '../core/app-profiles.ts';
|
|
3
3
|
import { type AutostartContext, type AutostartStatus } from '../core/autostart.ts';
|
|
4
4
|
import { type BrowserReport } from '../core/browser-profiles.ts';
|
|
5
|
-
import { type DisplayConfig, type HandoffSettings, type PanelConfig } from '../core/config.ts';
|
|
5
|
+
import { type DisplayConfig, type EditorChoice, type HandoffSettings, type PanelConfig } from '../core/config.ts';
|
|
6
6
|
import { type InboundGroup } from '../core/inbound.ts';
|
|
7
7
|
import { type LiveSession, type LiveSessionsResult, sessionCopyText } from '../core/live-sessions.ts';
|
|
8
8
|
import { listMessages, type MessageReceipt, sendMessage } from '../core/messages.ts';
|
|
@@ -57,6 +57,17 @@ export interface PanelHandlerOptions {
|
|
|
57
57
|
ask?: {
|
|
58
58
|
bridge: 'postMessage';
|
|
59
59
|
};
|
|
60
|
+
/**
|
|
61
|
+
* How the Panel's "Open settings.json" opens the file (spec §3.30, ADR-0033 amendment). `{ bridge: 'postMessage' }`
|
|
62
|
+
* is for a Portal that opens files itself, with an app the user chose there: inside a frame, the item asks the
|
|
63
|
+
* Panel's server only where the file really is and posts `{ type: 'local-tools:open', version: 1, path }` (the
|
|
64
|
+
* absolute path of the real file, never its content) to `window.parent`, with the Panel's own origin as the target
|
|
65
|
+
* origin; the Portal opens it. Without it, or opened on its own, the Panel's server opens the file (config `editor`).
|
|
66
|
+
* Checked when the handler is created: anything else throws a TypeError.
|
|
67
|
+
*/
|
|
68
|
+
open?: {
|
|
69
|
+
bridge: 'postMessage';
|
|
70
|
+
};
|
|
60
71
|
}
|
|
61
72
|
/**
|
|
62
73
|
* Internal, for tests and screenshots: a property under this key of the handler options replaces where the Sessions
|
|
@@ -220,6 +231,8 @@ export interface PanelState {
|
|
|
220
231
|
configAliases?: Record<string, string>;
|
|
221
232
|
/** The config `pickCommands`, name → Family (spec §3.13, ADR-0035). */
|
|
222
233
|
pickCommands?: Record<string, string>;
|
|
234
|
+
/** Config `editor`: what "Open settings.json" opens the file with (spec §3.30); `system` when not set. */
|
|
235
|
+
editor?: EditorChoice;
|
|
223
236
|
/**
|
|
224
237
|
* Family → the Pick Command the page offers to add: a Family with two or more Subscription Accounts and none yet,
|
|
225
238
|
* with the command on PATH the name would hide; `name: null` when no default name is free (the user types one).
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// HTTP handler for the local Panel. Mountable under any basePath; standalone and embedded use the same rules.
|
|
2
2
|
import { randomBytes, timingSafeEqual } from 'node:crypto';
|
|
3
|
+
import { realpath } from 'node:fs/promises';
|
|
3
4
|
import { aliasesByAccount, startArgsOf } from '../core/accounts.js';
|
|
4
5
|
import { listAppProfiles, openAppProfile, removeAppProfile, } from '../core/app-profiles.js';
|
|
5
6
|
import { openLoginInTerminal, openPickInTerminal, pickTaskAccount, previewAttachments, promptForTask, setCustomTerminal, setPreferredTerminal, startAiTask, taskContext, terminals, tryAccount, } from '../core/ask.js';
|
|
@@ -7,9 +8,9 @@ import { ATTACHMENT_LIMITS, MAX_ATTACHMENTS, MAX_UPLOAD_BYTES, removeStaged, sta
|
|
|
7
8
|
import { applyAutostart, autostartStatus, PANEL_AGENT, planAutostart, } from '../core/autostart.js';
|
|
8
9
|
import { FAVICON_SVG, ICON_SVG } from '../core/brand-mark.js';
|
|
9
10
|
import { browserReport, openInBrowser, setBrowserChoice, setBrowserSignIns, } from '../core/browser-profiles.js';
|
|
10
|
-
import { aiTaskPermissions, aliasArgs, aliasRefs, editConfigPanel, editConfigTerminal, editConfigUpdate, loadConfig, } from '../core/config.js';
|
|
11
|
+
import { aiTaskPermissions, aliasArgs, aliasRefs, EDITORS, editConfigPanel, editConfigPath, editConfigTerminal, editConfigUpdate, loadConfig, } from '../core/config.js';
|
|
11
12
|
import { openDesktopApp, withDesktopApps } from '../core/desktop-app.js';
|
|
12
|
-
import { editSettings } from '../core/edit-settings.js';
|
|
13
|
+
import { editSettings, isEditor } from '../core/edit-settings.js';
|
|
13
14
|
import { UserError } from '../core/errors.js';
|
|
14
15
|
import { planHandoff } from '../core/handoff.js';
|
|
15
16
|
import { applyHandoffEnable, planHandoffEnable } from '../core/handoff-enable.js';
|
|
@@ -59,14 +60,15 @@ export const MAX_QUEUED_WRITES = 4;
|
|
|
59
60
|
export const LIVE_SESSIONS_SOURCE = Symbol('sideby.panel.liveSessions');
|
|
60
61
|
/** The longest text "Send to it" takes; the page's text box has the same limit. */
|
|
61
62
|
export const MAX_MESSAGE_TEXT = 8000;
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
/** The `ask` and `open` options: `{ bridge: 'postMessage' }` or left out; anything else is a TypeError. */
|
|
64
|
+
function resolveBridge(name, value) {
|
|
65
|
+
if (value === undefined)
|
|
64
66
|
return undefined;
|
|
65
|
-
if (!
|
|
66
|
-
typeof
|
|
67
|
-
|
|
68
|
-
Object.keys(
|
|
69
|
-
throw new TypeError(
|
|
67
|
+
if (!value ||
|
|
68
|
+
typeof value !== 'object' ||
|
|
69
|
+
value.bridge !== 'postMessage' ||
|
|
70
|
+
Object.keys(value).length !== 1)
|
|
71
|
+
throw new TypeError(`panel ${name} must be { bridge: "postMessage" } or left out`);
|
|
70
72
|
return { bridge: 'postMessage' };
|
|
71
73
|
}
|
|
72
74
|
const PANEL_LANGS = ['auto', 'en', 'zh'];
|
|
@@ -260,6 +262,7 @@ export function handoffByFamily(rt, accounts, now) {
|
|
|
260
262
|
isMain: a.isMain,
|
|
261
263
|
kind: a.kind,
|
|
262
264
|
login: a.login ?? 'unknown',
|
|
265
|
+
...(a.loginProblem ? { loginProblem: a.loginProblem } : {}),
|
|
263
266
|
quota: a.quota ?? { status: 'unavailable', reason: 'unrecognized' },
|
|
264
267
|
})), now,
|
|
265
268
|
// The same plan as `sideby next`: the same Takeover Limits, and past them the least used Account (a Last Resort).
|
|
@@ -630,6 +633,7 @@ async function buildState(rt, opts) {
|
|
|
630
633
|
...(history ? { history } : {}),
|
|
631
634
|
...(rt.config.aliases ? { configAliases: aliasRefs(rt.config.aliases) } : {}),
|
|
632
635
|
...(rt.config.pickCommands ? { pickCommands: { ...rt.config.pickCommands } } : {}),
|
|
636
|
+
editor: isEditor(rt.config.editor) ? rt.config.editor : 'system',
|
|
633
637
|
...(Object.keys(pickOffers).length ? { pickOffers } : {}),
|
|
634
638
|
shellSetup: { ...shellSt, rc: tildify(shellSt.rc, ctx.home), block: setupBlock(shellSt.shell) },
|
|
635
639
|
...(Object.keys(handoff).length ? { handoff } : {}),
|
|
@@ -977,7 +981,8 @@ export function createPanelHandler(opts) {
|
|
|
977
981
|
const theme = resolveTheme(opts.theme);
|
|
978
982
|
const lang = resolveLang(opts.lang);
|
|
979
983
|
const updates = opts.updates !== false;
|
|
980
|
-
const ask =
|
|
984
|
+
const ask = resolveBridge('ask', opts.ask);
|
|
985
|
+
const openBridge = resolveBridge('open', opts.open);
|
|
981
986
|
const token = randomBytes(32).toString('base64url');
|
|
982
987
|
const serial = writeQueue();
|
|
983
988
|
const readings = new Map();
|
|
@@ -1809,17 +1814,45 @@ export function createPanelHandler(opts) {
|
|
|
1809
1814
|
};
|
|
1810
1815
|
},
|
|
1811
1816
|
},
|
|
1812
|
-
// Opens the Account's Host settings file with the system's default program (spec §3.30,
|
|
1813
|
-
// of the file but starts a program, so a read-only Panel refuses it (writes defaults to
|
|
1817
|
+
// Opens the Account's Host settings file with config `editor`, else the system's default program (spec §3.30,
|
|
1818
|
+
// ADR-0033). It reads none of the file but starts a program, so a read-only Panel refuses it (writes defaults to
|
|
1819
|
+
// true). `open: false` (the open bridge) starts nothing and adds `realPath`, the real file's absolute path, for the
|
|
1820
|
+
// Portal to open.
|
|
1814
1821
|
'/api/account/edit-settings': {
|
|
1815
1822
|
async run(body) {
|
|
1816
1823
|
const account = optString(body, 'account');
|
|
1817
1824
|
if (!account)
|
|
1818
1825
|
throw new HttpError(400, '"account" is required');
|
|
1826
|
+
if (body.open !== undefined && typeof body.open !== 'boolean')
|
|
1827
|
+
throw new HttpError(400, '"open" must be true or false');
|
|
1819
1828
|
const rt = await getRuntime();
|
|
1820
|
-
const
|
|
1829
|
+
const open = body.open !== false;
|
|
1830
|
+
const r = await editSettings(rt, account, { open });
|
|
1821
1831
|
const home = rt.paths.home;
|
|
1822
|
-
return {
|
|
1832
|
+
return {
|
|
1833
|
+
...r,
|
|
1834
|
+
path: tildify(r.path, home),
|
|
1835
|
+
...(r.target ? { target: tildify(r.target, home) } : {}),
|
|
1836
|
+
// The file's real path even when the account directory itself is a link (only then is `target` unset).
|
|
1837
|
+
...(open ? {} : { realPath: await realpath(r.path) }),
|
|
1838
|
+
};
|
|
1839
|
+
},
|
|
1840
|
+
},
|
|
1841
|
+
// The editor "Open settings.json" uses: config `editor` (spec §3.30); `system` or null removes the key.
|
|
1842
|
+
'/api/editor': {
|
|
1843
|
+
async run(body) {
|
|
1844
|
+
const editor = body.editor;
|
|
1845
|
+
if (editor !== null && !isEditor(editor))
|
|
1846
|
+
throw new HttpError(400, `"editor" must be one of ${EDITORS.join(', ')} or null`);
|
|
1847
|
+
const rt = await getRuntime();
|
|
1848
|
+
const chosen = editor === null || editor === 'system' ? undefined : editor;
|
|
1849
|
+
const r = await editConfigPath(rt.paths.configFile, 'editor', chosen);
|
|
1850
|
+
// A Panel given one Runtime keeps using it: the next open and /api/state read the new choice from it.
|
|
1851
|
+
if (chosen === undefined)
|
|
1852
|
+
delete rt.config.editor;
|
|
1853
|
+
else
|
|
1854
|
+
rt.config.editor = chosen;
|
|
1855
|
+
return { changed: r.changed, editor: r.after ?? 'system' };
|
|
1823
1856
|
},
|
|
1824
1857
|
},
|
|
1825
1858
|
// Unattended Mode (spec §3.37): the page's status and Pending Decisions. A read-only Panel reads them too.
|
|
@@ -2337,6 +2370,7 @@ export function createPanelHandler(opts) {
|
|
|
2337
2370
|
lang,
|
|
2338
2371
|
updates,
|
|
2339
2372
|
...(ask ? { ask } : {}),
|
|
2373
|
+
...(openBridge ? { open: openBridge } : {}),
|
|
2340
2374
|
...(panel ? { panel } : {}),
|
|
2341
2375
|
}));
|
|
2342
2376
|
return true;
|
package/dist/src/panel/i18n.d.ts
CHANGED
|
@@ -159,6 +159,8 @@ declare const en: {
|
|
|
159
159
|
'need.health-fail.other': string;
|
|
160
160
|
'need.signed-out.one': string;
|
|
161
161
|
'need.signed-out.other': string;
|
|
162
|
+
'need.login-expired.one': string;
|
|
163
|
+
'need.login-expired.other': string;
|
|
162
164
|
'need.not-installed.one': string;
|
|
163
165
|
'need.not-installed.other': string;
|
|
164
166
|
'need.quota-high.one': string;
|
|
@@ -168,6 +170,7 @@ declare const en: {
|
|
|
168
170
|
'why.error': string;
|
|
169
171
|
'why.health-fail': string;
|
|
170
172
|
'why.signed-out': string;
|
|
173
|
+
'why.login-expired': string;
|
|
171
174
|
'why.not-installed': string;
|
|
172
175
|
'why.broken': string;
|
|
173
176
|
'why.quota-high': string;
|
|
@@ -272,6 +275,18 @@ declare const en: {
|
|
|
272
275
|
'acct.api': string;
|
|
273
276
|
'acct.model': string;
|
|
274
277
|
'acct.signedOut': string;
|
|
278
|
+
'acct.expired': string;
|
|
279
|
+
'acct.expiredIn': string;
|
|
280
|
+
'acct.expiredWaiting': string;
|
|
281
|
+
'acct.expiredHint': string;
|
|
282
|
+
'acct.expiredWaitingHint': string;
|
|
283
|
+
'acct.expiredSince': string;
|
|
284
|
+
'acct.signInAgain': string;
|
|
285
|
+
'acct.signInName': string;
|
|
286
|
+
'exp.banner.one': string;
|
|
287
|
+
'exp.banner.other': string;
|
|
288
|
+
'exp.signIn': string;
|
|
289
|
+
'exp.signInRef': string;
|
|
275
290
|
'acct.signInHint': string;
|
|
276
291
|
'acct.signedOutLabel': string;
|
|
277
292
|
'acct.next': string;
|
|
@@ -456,6 +471,7 @@ declare const en: {
|
|
|
456
471
|
'ai.ask.handoffRules': string;
|
|
457
472
|
'ai.ask.rc': string;
|
|
458
473
|
'ai.ask.relogin': string;
|
|
474
|
+
'ai.ask.expired': string;
|
|
459
475
|
'ai.orderHint': string;
|
|
460
476
|
'ai.emptyHint': string;
|
|
461
477
|
'ai.how': string;
|
|
@@ -753,6 +769,8 @@ declare const en: {
|
|
|
753
769
|
'edit.opened': string;
|
|
754
770
|
'edit.shared': string;
|
|
755
771
|
'edit.failed': string;
|
|
772
|
+
'edit.openedWith': string;
|
|
773
|
+
'edit.noPath': string;
|
|
756
774
|
'menu.like': string;
|
|
757
775
|
'menu.tune': string;
|
|
758
776
|
'menu.model': string;
|
|
@@ -1346,6 +1364,11 @@ declare const en: {
|
|
|
1346
1364
|
'set.button': string;
|
|
1347
1365
|
'set.lang': string;
|
|
1348
1366
|
'set.theme': string;
|
|
1367
|
+
'set.editor': string;
|
|
1368
|
+
'set.editor.system': string;
|
|
1369
|
+
'set.editor.hint': string;
|
|
1370
|
+
'set.editor.portal': string;
|
|
1371
|
+
'set.editor.saved': string;
|
|
1349
1372
|
'set.theme.system': string;
|
|
1350
1373
|
'set.theme.light': string;
|
|
1351
1374
|
'set.theme.dark': string;
|