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
package/dist/src/core/handoff.js
CHANGED
|
@@ -17,7 +17,9 @@ function lastReset(quota, now, level) {
|
|
|
17
17
|
return last;
|
|
18
18
|
}
|
|
19
19
|
/** A full Subscription Account a Last Resort may start: no window used up (pressure under 100). */
|
|
20
|
-
const lastResortOk = (e) => e.state === 'full' && !e
|
|
20
|
+
const lastResortOk = (e) => e.state === 'full' && !blocked(e) && e.pressure !== null && e.pressure < 100;
|
|
21
|
+
/** An entry that can never be picked whatever its state: the current Account's Same Login, or an Expired Login. */
|
|
22
|
+
export const blocked = (e) => Boolean(e.sameLoginAs || e.skip);
|
|
21
23
|
function entry(c, now, limits, lastResort) {
|
|
22
24
|
const pressure = quotaPressure(c.quota, now);
|
|
23
25
|
const use = limitUse(c.quota, now, limits);
|
|
@@ -42,6 +44,14 @@ function entry(c, now, limits, lastResort) {
|
|
|
42
44
|
return { ...base, state: 'api' };
|
|
43
45
|
if (c.login === 'logged-out')
|
|
44
46
|
return { ...base, state: 'logged-out' };
|
|
47
|
+
return withSkip(c, stateOfQuota(c, base, pressure, now, limits, lastResort));
|
|
48
|
+
}
|
|
49
|
+
function withSkip(c, e) {
|
|
50
|
+
return c.loginProblem?.kind === 'expired'
|
|
51
|
+
? { ...e, skip: { reason: 'login-expired', command: `sideby login ${c.ref}` } }
|
|
52
|
+
: e;
|
|
53
|
+
}
|
|
54
|
+
function stateOfQuota(c, base, pressure, now, limits, lastResort) {
|
|
45
55
|
if (pressure === null)
|
|
46
56
|
return { ...base, state: 'unknown' };
|
|
47
57
|
// Full once any window reaches its own Takeover Limit: 85 for a Short Window, 95 for a Long one by default.
|
|
@@ -79,13 +89,14 @@ opts = {}) {
|
|
|
79
89
|
return current?.sameLogin?.includes(c.ref) ? { ...e, sameLoginAs: current.ref } : e;
|
|
80
90
|
})
|
|
81
91
|
.sort((a, b) =>
|
|
82
|
-
// A Same Login partner of the current Account can never be picked, so it goes with the
|
|
83
|
-
|
|
92
|
+
// A Same Login partner of the current Account or an Expired Login can never be picked, so it goes with the
|
|
93
|
+
// others that cannot.
|
|
94
|
+
Number(blocked(a)) - Number(blocked(b)) ||
|
|
84
95
|
rank(a) - rank(b) ||
|
|
85
96
|
(a.state === 'ready' || rank(a) === 1.5 ? a.limitUse - b.limitUse : 0) ||
|
|
86
97
|
(a.state === 'full' ? resetTime(a) - resetTime(b) || 0 : 0) ||
|
|
87
98
|
tie(a, b));
|
|
88
|
-
const usable = (e) => !e
|
|
99
|
+
const usable = (e) => !blocked(e) &&
|
|
89
100
|
(e.state === 'ready' ||
|
|
90
101
|
e.state === 'unknown' ||
|
|
91
102
|
(opts.lastResort && lastResortOk(e)) ||
|
|
@@ -97,7 +108,7 @@ opts = {}) {
|
|
|
97
108
|
if (picked?.state === 'full')
|
|
98
109
|
plan.tight = { limit: limits.short, longLimit: limits.long };
|
|
99
110
|
if (pick === null) {
|
|
100
|
-
const first = accounts.find((e) => e.state === 'full' && e.resetsAt);
|
|
111
|
+
const first = accounts.find((e) => e.state === 'full' && e.resetsAt && !e.skip);
|
|
101
112
|
if (first?.resetsAt)
|
|
102
113
|
plan.earliestReset = { ref: first.ref, at: first.resetsAt };
|
|
103
114
|
}
|
|
@@ -52,6 +52,8 @@ export interface Match {
|
|
|
52
52
|
id: number;
|
|
53
53
|
/** Higher is better; 1 for a match that has no FTS rank (short words only). */
|
|
54
54
|
relevance: number;
|
|
55
|
+
/** The title of the Session the match stands for (the parent's, for a match in a subagent Session). */
|
|
56
|
+
title: string;
|
|
55
57
|
}
|
|
56
58
|
export declare class HistoryIndex {
|
|
57
59
|
#private;
|
|
@@ -98,6 +100,8 @@ export declare class HistoryIndex {
|
|
|
98
100
|
* shorter ones are matched with LIKE. Subagent Sessions count for their parent (filters then apply to the parent).
|
|
99
101
|
*/
|
|
100
102
|
match(words: string[], f: Filters): Match[];
|
|
103
|
+
/** The newest subagent Session of `parent` whose own text matches every word: where a snippet comes from then. */
|
|
104
|
+
childMatch(parent: Pick<SessionRow, 'account' | 'sessionId'>, words: string[]): number | undefined;
|
|
101
105
|
/** Top-level Sessions matching the filters, newest first. */
|
|
102
106
|
recent(f: Filters, limit: number, offset: number): {
|
|
103
107
|
rows: SessionRow[];
|
|
@@ -7,7 +7,7 @@ import { dirname } from 'node:path';
|
|
|
7
7
|
import { cutText } from '../families/shared/history-text.js';
|
|
8
8
|
import { UserError } from './errors.js';
|
|
9
9
|
/** Bumped whenever the tables or what a reader stores changes; an older database is dropped and rebuilt. */
|
|
10
|
-
const SCHEMA =
|
|
10
|
+
const SCHEMA = 4;
|
|
11
11
|
let sqlite;
|
|
12
12
|
/** `node:sqlite` without its experimental warning (ADR-0042); undefined when this Node has none. */
|
|
13
13
|
function loadSqlite() {
|
|
@@ -329,14 +329,9 @@ export class HistoryIndex {
|
|
|
329
329
|
parts.push(`${col('script')} = 0`);
|
|
330
330
|
return { sql: parts.length ? parts.join(' AND ') : '1', args };
|
|
331
331
|
}
|
|
332
|
-
/**
|
|
333
|
-
|
|
334
|
-
* or more go through the trigram index and are ranked by bm25 (title and place before prompts before replies);
|
|
335
|
-
* shorter ones are matched with LIKE. Subagent Sessions count for their parent (filters then apply to the parent).
|
|
336
|
-
*/
|
|
337
|
-
match(words, f) {
|
|
332
|
+
/** The conditions on `text` that make a row match every word, and the expression that ranks it. */
|
|
333
|
+
#textConds(words) {
|
|
338
334
|
const longs = words.filter(long);
|
|
339
|
-
const shorts = words.filter((w) => !long(w));
|
|
340
335
|
const args = [];
|
|
341
336
|
const conds = [];
|
|
342
337
|
let rank = '1.0';
|
|
@@ -345,24 +340,58 @@ export class HistoryIndex {
|
|
|
345
340
|
args.push(longs.map(phrase).join(' '));
|
|
346
341
|
rank = '-bm25(text, 6.0, 4.0, 2.0, 1.0)';
|
|
347
342
|
}
|
|
348
|
-
for (const w of
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
343
|
+
for (const w of words.filter((x) => !long(x))) {
|
|
344
|
+
// LIKE ignores case for ASCII letters only, so a word without one matches the same rows through instr(),
|
|
345
|
+
// which reads the text about twice as fast.
|
|
346
|
+
if (/[a-z]/i.test(w)) {
|
|
347
|
+
conds.push("(text.title LIKE ? ESCAPE '\\' OR text.place LIKE ? ESCAPE '\\' OR text.prompts LIKE ? ESCAPE '\\' OR text.replies LIKE ? ESCAPE '\\')");
|
|
348
|
+
const l = like(w);
|
|
349
|
+
args.push(l, l, l, l);
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
conds.push('(instr(text.title, ?) OR instr(text.place, ?) OR instr(text.prompts, ?) OR instr(text.replies, ?))');
|
|
353
|
+
args.push(w, w, w, w);
|
|
354
|
+
}
|
|
352
355
|
}
|
|
356
|
+
return { conds, args, rank };
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Sessions that match every word (in title, place, prompts or replies) and the filters. Words of three characters
|
|
360
|
+
* or more go through the trigram index and are ranked by bm25 (title and place before prompts before replies);
|
|
361
|
+
* shorter ones are matched with LIKE. Subagent Sessions count for their parent (filters then apply to the parent).
|
|
362
|
+
*/
|
|
363
|
+
match(words, f) {
|
|
364
|
+
const { conds, args, rank } = this.#textConds(words);
|
|
353
365
|
// Lift a matching subagent Session to its parent, and apply the filters to whichever row stands for it.
|
|
354
366
|
const where = this.#where(f, (n) => `coalesce(p.${n}, s.${n})`);
|
|
355
|
-
|
|
356
|
-
|
|
367
|
+
const lift = `LEFT JOIN sessions p ON s.parent != '' AND p.account = s.account AND p.session_id = s.parent AND p.parent = ''`;
|
|
368
|
+
// With short words only there is no index to ask, and LIKE reads every row's text: read only the rows the
|
|
369
|
+
// filters keep.
|
|
370
|
+
const scoped = conds.length > 0 && !words.some(long) && where.sql !== '1';
|
|
371
|
+
const scope = scoped ? `text.rowid IN (SELECT s.id FROM sessions s ${lift} WHERE ${where.sql}) AND ` : '';
|
|
372
|
+
return this.#q(`WITH hits(id, rel) AS MATERIALIZED (SELECT text.rowid, ${rank} FROM text WHERE ${scope}${conds.join(' AND ') || '1'})
|
|
373
|
+
SELECT coalesce(p.id, s.id) AS id, max(h.rel) AS relevance, coalesce(p.title, s.title) AS title
|
|
357
374
|
FROM hits h JOIN sessions s ON s.id = h.id
|
|
358
|
-
|
|
375
|
+
${lift}
|
|
359
376
|
WHERE ${where.sql} GROUP BY 1`)
|
|
360
|
-
.all(...args, ...where.args)
|
|
377
|
+
.all(...(scoped ? where.args : []), ...args, ...where.args)
|
|
361
378
|
.map((r) => {
|
|
362
379
|
const m = r;
|
|
363
|
-
return { id: m.id, relevance: Math.max(m.relevance, 1e-6) };
|
|
380
|
+
return { id: m.id, relevance: Math.max(m.relevance, 1e-6), title: m.title };
|
|
364
381
|
});
|
|
365
382
|
}
|
|
383
|
+
/** The newest subagent Session of `parent` whose own text matches every word: where a snippet comes from then. */
|
|
384
|
+
childMatch(parent, words) {
|
|
385
|
+
const { conds, args } = this.#textConds(words);
|
|
386
|
+
if (!conds.length)
|
|
387
|
+
return undefined;
|
|
388
|
+
const r = this.#q(
|
|
389
|
+
// CROSS JOIN keeps this order: the few subagent Sessions first, then the text of each.
|
|
390
|
+
`SELECT c.id FROM sessions c CROSS JOIN text
|
|
391
|
+
WHERE c.parent = ? AND c.account = ? AND c.parent != '' AND text.rowid = c.id AND ${conds.join(' AND ')}
|
|
392
|
+
ORDER BY c.updated_at DESC LIMIT 1`).get(parent.sessionId, parent.account, ...args);
|
|
393
|
+
return r?.id;
|
|
394
|
+
}
|
|
366
395
|
/** Top-level Sessions matching the filters, newest first. */
|
|
367
396
|
recent(f, limit, offset) {
|
|
368
397
|
const w = this.#where(f);
|
|
@@ -43,7 +43,8 @@ export class ProjectResolver {
|
|
|
43
43
|
if (!cwd || !isAbsolute(cwd))
|
|
44
44
|
return { path: hostRoot ?? cwd ?? '', gone: false };
|
|
45
45
|
if ((await kind(cwd)) !== 'dir') {
|
|
46
|
-
|
|
46
|
+
// resolve() drops a trailing separator (Grok records `<repo>/`), so it groups with the live folder's Project.
|
|
47
|
+
const root = resolve(hostRoot && isAbsolute(hostRoot) ? hostRoot : cwd);
|
|
47
48
|
const main = (await kind(join(root, '.git'))) === 'file' ? await worktreeMain(join(root, '.git')) : undefined;
|
|
48
49
|
return { path: main ?? root, gone: true };
|
|
49
50
|
}
|
|
@@ -75,10 +76,22 @@ export function projectNames(paths) {
|
|
|
75
76
|
}
|
|
76
77
|
const parts = list.map((p) => p.split(/[\\/]+/).filter(Boolean));
|
|
77
78
|
const tail = (seg, n) => seg.slice(-n).join('/');
|
|
79
|
+
// How many of these Projects end with each tail of `n` folders, counted once per `n`.
|
|
80
|
+
const tails = new Map();
|
|
81
|
+
const shared = (seg, n) => {
|
|
82
|
+
let count = tails.get(n);
|
|
83
|
+
if (!count) {
|
|
84
|
+
count = new Map();
|
|
85
|
+
for (const o of parts)
|
|
86
|
+
count.set(tail(o, n), (count.get(tail(o, n)) ?? 0) + 1);
|
|
87
|
+
tails.set(n, count);
|
|
88
|
+
}
|
|
89
|
+
return count.get(tail(seg, n)) > 1;
|
|
90
|
+
};
|
|
78
91
|
for (const [i, p] of list.entries()) {
|
|
79
92
|
const seg = parts[i];
|
|
80
93
|
let n = 2;
|
|
81
|
-
while (n < seg.length &&
|
|
94
|
+
while (n < seg.length && shared(seg, n))
|
|
82
95
|
n++;
|
|
83
96
|
out.set(p, tail(seg, n));
|
|
84
97
|
}
|
|
@@ -124,8 +124,18 @@ export declare const historyBuilt: (rt: Runtime) => boolean;
|
|
|
124
124
|
* `/a/app` beside `/x/a/app`).
|
|
125
125
|
*/
|
|
126
126
|
export declare function projectsNamed(names: ReadonlyMap<string, string>, p: string): string[];
|
|
127
|
-
/**
|
|
127
|
+
/**
|
|
128
|
+
* A snippet of `text`, about 40 characters each side of what was searched: the first place where the most of
|
|
129
|
+
* `words` stand within 80 characters of each other, so two words show together when the text has them together.
|
|
130
|
+
*/
|
|
128
131
|
export declare function snippetOf(text: string, words: string[]): string | undefined;
|
|
132
|
+
/**
|
|
133
|
+
* How much a match in the title lifts a Session: the whole query in the title most, then every word, then a share
|
|
134
|
+
* of the words. A title is what people remember a Session by, and bm25 over trigrams hardly tells it from a mention.
|
|
135
|
+
*/
|
|
136
|
+
export declare function titleBoost(title: string, words: string[], query: string): number;
|
|
137
|
+
/** The share of a search score a Session keeps at its age: half at 30 days, a third at 60, never nothing. */
|
|
138
|
+
export declare const recency: (ageMs: number) => number;
|
|
129
139
|
/** The words of a search; `"two words"` in double quotes is one phrase, matched as written. */
|
|
130
140
|
export declare const splitWords: (q: string | undefined) => string[];
|
|
131
141
|
/**
|
package/dist/src/core/history.js
CHANGED
|
@@ -12,7 +12,8 @@ import { HistoryIndex, } from './history-index.js';
|
|
|
12
12
|
import { ProjectResolver, projectNames } from './history-project.js';
|
|
13
13
|
import { accountLabels, hostResumeArgs, liveKey, referenceText } from './live-sessions.js';
|
|
14
14
|
const DAY = 86_400_000;
|
|
15
|
-
|
|
15
|
+
/** How old a Session is when its age has halved its search score; older ones go on falling, more slowly. */
|
|
16
|
+
const RECENCY = 30 * DAY;
|
|
16
17
|
const SYNC_EVERY_MS = 5_000;
|
|
17
18
|
const PARSE_AT_ONCE = 4;
|
|
18
19
|
const STATES = new Map();
|
|
@@ -475,29 +476,69 @@ export function projectsNamed(names, p) {
|
|
|
475
476
|
}
|
|
476
477
|
const SAFE = /^[\w@%+=:,./-]+$/;
|
|
477
478
|
const shq = (v) => (SAFE.test(v) ? v : `'${v.replaceAll("'", "'\\''")}'`);
|
|
478
|
-
|
|
479
|
+
const SNIPPET_SPAN = 80;
|
|
480
|
+
/** Occurrences looked at per word: enough to find a place where the words meet, bounded for a long text. */
|
|
481
|
+
const SNIPPET_SEEK = 40;
|
|
482
|
+
/**
|
|
483
|
+
* A snippet of `text`, about 40 characters each side of what was searched: the first place where the most of
|
|
484
|
+
* `words` stand within 80 characters of each other, so two words show together when the text has them together.
|
|
485
|
+
*/
|
|
479
486
|
export function snippetOf(text, words) {
|
|
480
487
|
if (!text || !words.length)
|
|
481
488
|
return undefined;
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
489
|
+
// Matched in the text itself: lowercasing can change its length and move every position after it.
|
|
490
|
+
const found = words.map((w) => {
|
|
491
|
+
const re = new RegExp(w.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'giu');
|
|
492
|
+
const at = [];
|
|
493
|
+
// One word needs only its first place.
|
|
494
|
+
const seek = words.length > 1 ? SNIPPET_SEEK : 1;
|
|
495
|
+
for (let m = re.exec(text); m && at.length < seek; m = re.exec(text)) {
|
|
496
|
+
at.push({ index: m.index, end: m.index + m[0].length });
|
|
497
|
+
if (!m[0].length)
|
|
498
|
+
re.lastIndex++;
|
|
490
499
|
}
|
|
500
|
+
return at;
|
|
501
|
+
});
|
|
502
|
+
let best;
|
|
503
|
+
for (const start of found.flat().sort((x, y) => x.index - y.index)) {
|
|
504
|
+
let n = 0;
|
|
505
|
+
let end = start.end;
|
|
506
|
+
for (const at of found) {
|
|
507
|
+
const near = at.find((o) => o.index >= start.index && o.end <= start.index + SNIPPET_SPAN);
|
|
508
|
+
if (!near)
|
|
509
|
+
continue;
|
|
510
|
+
n++;
|
|
511
|
+
end = Math.max(end, near.end);
|
|
512
|
+
}
|
|
513
|
+
if (!best || n > best.words)
|
|
514
|
+
best = { at: start.index, end, words: n };
|
|
515
|
+
if (n === words.length)
|
|
516
|
+
break;
|
|
491
517
|
}
|
|
492
|
-
if (
|
|
518
|
+
if (!best)
|
|
493
519
|
return undefined;
|
|
494
|
-
let start = Math.max(0, at - 40);
|
|
520
|
+
let start = Math.max(0, best.at - 40);
|
|
495
521
|
if (start > 0 && /[\uDC00-\uDFFF]/.test(text[start]))
|
|
496
522
|
start--;
|
|
497
|
-
const end = start + cutText(text.slice(start),
|
|
523
|
+
const end = start + cutText(text.slice(start), best.end - start + 40).length;
|
|
498
524
|
const body = text.slice(start, end).replace(/\s+/g, ' ').trim();
|
|
499
525
|
return `${start > 0 ? '…' : ''}${body}${end < text.length ? '…' : ''}`;
|
|
500
526
|
}
|
|
527
|
+
/**
|
|
528
|
+
* How much a match in the title lifts a Session: the whole query in the title most, then every word, then a share
|
|
529
|
+
* of the words. A title is what people remember a Session by, and bm25 over trigrams hardly tells it from a mention.
|
|
530
|
+
*/
|
|
531
|
+
export function titleBoost(title, words, query) {
|
|
532
|
+
const t = title.toLowerCase();
|
|
533
|
+
const n = words.filter((w) => t.includes(w.toLowerCase())).length;
|
|
534
|
+
if (!n)
|
|
535
|
+
return 1;
|
|
536
|
+
if (t.includes(query.trim().toLowerCase()))
|
|
537
|
+
return 8;
|
|
538
|
+
return n === words.length ? 5 : 1 + (2 * n) / words.length;
|
|
539
|
+
}
|
|
540
|
+
/** The share of a search score a Session keeps at its age: half at 30 days, a third at 60, never nothing. */
|
|
541
|
+
export const recency = (ageMs) => 1 / (1 + Math.max(0, ageMs) / RECENCY);
|
|
501
542
|
const NAMES = new WeakMap();
|
|
502
543
|
/** Project names, worked out again only after the index changed. */
|
|
503
544
|
function namesOf(idx) {
|
|
@@ -614,7 +655,11 @@ async function search(rt, s, q, opts) {
|
|
|
614
655
|
const outline = idx.outlineOf(hits.map((h) => h.id));
|
|
615
656
|
items = hits.flatMap((h) => {
|
|
616
657
|
const o = outline.get(h.id);
|
|
617
|
-
|
|
658
|
+
if (!o)
|
|
659
|
+
return [];
|
|
660
|
+
return [
|
|
661
|
+
{ ...o, score: h.relevance * titleBoost(h.title, words, q.q ?? '') * recency(now - o.updatedAt) },
|
|
662
|
+
];
|
|
618
663
|
});
|
|
619
664
|
}
|
|
620
665
|
else
|
|
@@ -663,8 +708,17 @@ async function search(rt, s, q, opts) {
|
|
|
663
708
|
const sessions = rows.map((r) => {
|
|
664
709
|
let snippet;
|
|
665
710
|
if (words.length && idx.keepText) {
|
|
666
|
-
const
|
|
667
|
-
|
|
711
|
+
const of = (id) => {
|
|
712
|
+
const t = idx.text(id);
|
|
713
|
+
return snippetOf(t.prompts, words) ?? snippetOf(t.replies, words);
|
|
714
|
+
};
|
|
715
|
+
snippet = of(r.id);
|
|
716
|
+
// Matched by a subagent Session only: show what that one said, so the row says why it is listed.
|
|
717
|
+
if (!snippet) {
|
|
718
|
+
const child = idx.childMatch(r, words);
|
|
719
|
+
if (child !== undefined)
|
|
720
|
+
snippet = of(child);
|
|
721
|
+
}
|
|
668
722
|
}
|
|
669
723
|
const out = toSession(rt, r, labels, names, {
|
|
670
724
|
children: children.get(r.id) ?? 0,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// When a sign-in that sideby started last finished (exit 0) for an Account (ADR-0071): one small file per Account in
|
|
2
|
+
// sideby's state directory, holding only that time. It never says the login works; it lets the Panel say "Sign-in
|
|
3
|
+
// finished, waiting for confirmation" until a successful turn or Quota answer clears the Expired Login.
|
|
4
|
+
import { mkdir, readFile } from 'node:fs/promises';
|
|
5
|
+
import { dirname, join } from 'node:path';
|
|
6
|
+
import { writeFileAtomic } from './fs-safe.js';
|
|
7
|
+
export function loginMarkFile(stateDir, family, name) {
|
|
8
|
+
return join(stateDir, 'login', family, `${name}.json`);
|
|
9
|
+
}
|
|
10
|
+
export async function readLoginMark(file) {
|
|
11
|
+
try {
|
|
12
|
+
const v = JSON.parse(await readFile(file, 'utf8'))?.signedInAt;
|
|
13
|
+
return typeof v === 'string' && Number.isFinite(Date.parse(v)) ? v : undefined;
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export async function writeLoginMark(file, at) {
|
|
20
|
+
await mkdir(dirname(file), { recursive: true, mode: 0o700 });
|
|
21
|
+
await writeFileAtomic(file, `${JSON.stringify({ signedInAt: at.toISOString() })}\n`, 0o600);
|
|
22
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type HandoffPlan } from './handoff.ts';
|
|
2
2
|
/** The name offered for a built-in Family when its Aliases follow no pattern; pi gets none (`pi` is the Host). */
|
|
3
3
|
export declare const DEFAULT_PICK_NAMES: Readonly<Record<string, string>>;
|
|
4
4
|
/**
|
|
@@ -36,7 +36,9 @@ export type PickChoice =
|
|
|
36
36
|
| {
|
|
37
37
|
ref: string;
|
|
38
38
|
reason: 'others-full';
|
|
39
|
-
}
|
|
39
|
+
}
|
|
40
|
+
/** `signIn`: the Accounts to sign in, signed out or with an Expired Login (ADR-0071). */
|
|
41
|
+
| {
|
|
40
42
|
ref: null;
|
|
41
43
|
reason: 'none-usable';
|
|
42
44
|
earliestReset?: {
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// Pick Commands (spec §3.13, ADR-0035): a short command bound to a Family that starts the Account a Handoff would
|
|
2
|
+
// pick, or the Main Account when no Account of the Family has Quota data.
|
|
3
|
+
import { blocked } from './handoff.js';
|
|
1
4
|
/** The name offered for a built-in Family when its Aliases follow no pattern; pi gets none (`pi` is the Host). */
|
|
2
5
|
export const DEFAULT_PICK_NAMES = { claude: 'cc', codex: 'cx', grok: 'gk' };
|
|
3
6
|
/**
|
|
@@ -16,7 +19,7 @@ export function suggestPickName(family, bin, familyAliases) {
|
|
|
16
19
|
* Account with the lowest Limit Use and no window used up (`tight`). Nothing usable (every window used up, signed out or API): nothing starts.
|
|
17
20
|
*/
|
|
18
21
|
export function choosePick(plan, mainRef) {
|
|
19
|
-
const startable = (ref) => plan.accounts.some((e) => e.ref === ref && !e
|
|
22
|
+
const startable = (ref) => plan.accounts.some((e) => e.ref === ref && !blocked(e) && (e.state === 'ready' || e.state === 'unknown'));
|
|
20
23
|
if (!plan.hasQuota && mainRef && startable(mainRef))
|
|
21
24
|
return { ref: mainRef, reason: 'no-quota-data' };
|
|
22
25
|
if (plan.pick && plan.accounts.some((e) => e.ref === plan.pick && e.state !== 'api')) {
|
|
@@ -42,7 +45,9 @@ export function choosePick(plan, mainRef) {
|
|
|
42
45
|
ref: null,
|
|
43
46
|
reason: 'none-usable',
|
|
44
47
|
...(plan.earliestReset ? { earliestReset: plan.earliestReset } : {}),
|
|
45
|
-
signIn: plan.accounts
|
|
48
|
+
signIn: plan.accounts
|
|
49
|
+
.filter((e) => e.state === 'logged-out' || e.skip?.reason === 'login-expired')
|
|
50
|
+
.map((e) => e.ref),
|
|
46
51
|
};
|
|
47
52
|
}
|
|
48
53
|
/** The line a Pick Command prints before it starts the Host. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Account, Env, QuotaFetch, QuotaResult, ReadContext } from '../types.ts';
|
|
1
|
+
import type { Account, Env, LoginEvents, LoginProblem, QuotaFetch, QuotaResult, ReadContext } from '../types.ts';
|
|
2
2
|
import { type QuotaStoreEntry } from './quota-store.ts';
|
|
3
3
|
/**
|
|
4
4
|
* `wait`: ask when the kept answer is old, and wait for it (the CLI). `background`: ask when old, but show the kept
|
|
@@ -15,6 +15,12 @@ export declare function quotaCheckOff(family: string, config: {
|
|
|
15
15
|
}, env: Env): string | null;
|
|
16
16
|
/** The kept answer for `account`, after asking again when `mode` and its age say so. */
|
|
17
17
|
export declare function fetchedQuota(fq: QuotaFetch, account: Account, ctx: ReadContext, hostEnv: Env, mode: QuotaFetchMode): Promise<QuotaStoreEntry | null>;
|
|
18
|
+
/**
|
|
19
|
+
* The Expired Login of a signed-in Subscription Account (ADR-0071), from what its Host wrote (`events`) and the kept
|
|
20
|
+
* Quota answer: expired when the newest sign that the login expired is newer than every sign that it works (a
|
|
21
|
+
* successful turn, a good Quota answer). `signedInAt` is when a sign-in sideby started last finished.
|
|
22
|
+
*/
|
|
23
|
+
export declare function loginProblemOf(ref: string, events: LoginEvents | undefined, kept: QuotaStoreEntry | null, signedInAt?: string): LoginProblem | undefined;
|
|
18
24
|
/**
|
|
19
25
|
* What sideby shows from a Family that fetches Quota: the newer reading, or the kept answer when local events can
|
|
20
26
|
* replay old snapshots (`localFallbackOnly`); else why there is none (`off` is why fetching is off, or null).
|
|
@@ -42,11 +42,20 @@ async function runFetch(fq, account, ctx, hostEnv, file) {
|
|
|
42
42
|
if (answer?.status === 'unavailable')
|
|
43
43
|
error = answer.detail ?? answer.reason;
|
|
44
44
|
const quota = answer?.status === 'ok' ? keptQuota(answer) : kept?.quota;
|
|
45
|
+
const attemptedAt = new Date().toISOString();
|
|
46
|
+
// An answer that asks for a new sign-in marks the login expired; a good answer clears it; any other failure keeps
|
|
47
|
+
// what was known (ADR-0071).
|
|
48
|
+
const loginExpiredAt = answer?.status === 'unavailable' && answer.loginExpired === true
|
|
49
|
+
? attemptedAt
|
|
50
|
+
: answer?.status === 'ok'
|
|
51
|
+
? undefined
|
|
52
|
+
: kept?.loginExpiredAt;
|
|
45
53
|
const entry = {
|
|
46
54
|
version: 1,
|
|
47
|
-
attemptedAt
|
|
55
|
+
attemptedAt,
|
|
48
56
|
...(quota ? { quota } : {}),
|
|
49
57
|
...(error ? { error } : {}),
|
|
58
|
+
...(loginExpiredAt ? { loginExpiredAt } : {}),
|
|
50
59
|
};
|
|
51
60
|
await writeQuotaStore(file, entry).catch(() => { });
|
|
52
61
|
return entry;
|
|
@@ -75,6 +84,34 @@ export async function fetchedQuota(fq, account, ctx, hostEnv, mode) {
|
|
|
75
84
|
return kept;
|
|
76
85
|
return Promise.race([run, sleep(FIRST_WAIT_MS)]).then((e) => e ?? kept);
|
|
77
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* The Expired Login of a signed-in Subscription Account (ADR-0071), from what its Host wrote (`events`) and the kept
|
|
89
|
+
* Quota answer: expired when the newest sign that the login expired is newer than every sign that it works (a
|
|
90
|
+
* successful turn, a good Quota answer). `signedInAt` is when a sign-in sideby started last finished.
|
|
91
|
+
*/
|
|
92
|
+
export function loginProblemOf(ref, events, kept, signedInAt) {
|
|
93
|
+
const t = (s) => (s ? Date.parse(s) : Number.NaN);
|
|
94
|
+
const newest = (...xs) => {
|
|
95
|
+
let best;
|
|
96
|
+
for (const x of xs)
|
|
97
|
+
if (Number.isFinite(t(x)) && (!best || t(x) > t(best)))
|
|
98
|
+
best = x;
|
|
99
|
+
return best;
|
|
100
|
+
};
|
|
101
|
+
const expired = newest(events?.expiredAt, kept?.loginExpiredAt);
|
|
102
|
+
if (!expired)
|
|
103
|
+
return undefined;
|
|
104
|
+
const working = newest(events?.workingAt, kept?.quota?.observedAt);
|
|
105
|
+
if (working && t(working) >= t(expired))
|
|
106
|
+
return undefined;
|
|
107
|
+
const since = new Date(t(expired)).toISOString();
|
|
108
|
+
return {
|
|
109
|
+
kind: 'expired',
|
|
110
|
+
since,
|
|
111
|
+
message: `sign-in expired; run \`sideby login ${ref}\` to sign in again`,
|
|
112
|
+
...(signedInAt && t(signedInAt) > t(expired) ? { signedInAt } : {}),
|
|
113
|
+
};
|
|
114
|
+
}
|
|
78
115
|
/**
|
|
79
116
|
* What sideby shows from a Family that fetches Quota: the newer reading, or the kept answer when local events can
|
|
80
117
|
* replay old snapshots (`localFallbackOnly`); else why there is none (`off` is why fetching is off, or null).
|
|
@@ -10,6 +10,11 @@ export interface QuotaStoreEntry {
|
|
|
10
10
|
quota?: FetchedQuota;
|
|
11
11
|
/** Why the latest fetch failed, when it did. */
|
|
12
12
|
error?: string;
|
|
13
|
+
/**
|
|
14
|
+
* When a fetch answered that the login expired (ADR-0071). Kept through later generic failures, dropped by the next
|
|
15
|
+
* good answer.
|
|
16
|
+
*/
|
|
17
|
+
loginExpiredAt?: string;
|
|
13
18
|
}
|
|
14
19
|
export declare function quotaStoreFile(stateDir: string, family: string, name: string): string;
|
|
15
20
|
/** Only the fields a Quota reading may carry, so a plugin's extra fields never reach the file. */
|
|
@@ -54,6 +54,9 @@ export async function readQuotaStore(file) {
|
|
|
54
54
|
attemptedAt: e.attemptedAt,
|
|
55
55
|
...(quota ? { quota } : {}),
|
|
56
56
|
...(typeof e.error === 'string' ? { error: e.error } : {}),
|
|
57
|
+
...(typeof e.loginExpiredAt === 'string' && Number.isFinite(Date.parse(e.loginExpiredAt))
|
|
58
|
+
? { loginExpiredAt: e.loginExpiredAt }
|
|
59
|
+
: {}),
|
|
57
60
|
};
|
|
58
61
|
}
|
|
59
62
|
export async function writeQuotaStore(file, entry) {
|
|
@@ -132,6 +132,15 @@ const ENTRIES = [
|
|
|
132
132
|
target: { settings: 'general', find: 'terminal' },
|
|
133
133
|
cliCommand: 'sideby terminal',
|
|
134
134
|
},
|
|
135
|
+
{
|
|
136
|
+
id: 'setting.editor',
|
|
137
|
+
kind: 'setting',
|
|
138
|
+
title: { en: 'Open settings files in', zh: '设置文件用什么打开' },
|
|
139
|
+
synonyms: ['editor', 'cursor', 'vscode', 'vs code', 'zed', 'windsurf', 'settings.json', '编辑器'],
|
|
140
|
+
panel: at(SET, GENERAL),
|
|
141
|
+
target: { settings: 'general', find: 'editor' },
|
|
142
|
+
cliCommand: 'sideby config set editor cursor',
|
|
143
|
+
},
|
|
135
144
|
{
|
|
136
145
|
id: 'setting.menubar',
|
|
137
146
|
kind: 'setting',
|
|
@@ -9,6 +9,7 @@ import { dirWrittenAt, groupedEntryWrittenAt, resumeFlagSession, withoutResumeFl
|
|
|
9
9
|
import { claudeAiTaskArgs } from './ai-task.js';
|
|
10
10
|
import { claudeHandoff } from './handoff.js';
|
|
11
11
|
import { CLAUDE_LAYOUT } from './layout.js';
|
|
12
|
+
import { readClaudeLoginEvents } from './login-events.js';
|
|
12
13
|
import { claudeModelChoice } from './model.js';
|
|
13
14
|
import { readClaudeQuota } from './quota.js';
|
|
14
15
|
import { claudeQuotaFetch } from './quota-fetch.js';
|
|
@@ -124,6 +125,8 @@ export const claudeFamily = {
|
|
|
124
125
|
hint: 'Opens the browser to sign this account in to Claude (`claude auth login`).',
|
|
125
126
|
},
|
|
126
127
|
loginState,
|
|
128
|
+
// An Expired Login (ADR-0071): the transcripts' own records, never a token or `expiresAt`.
|
|
129
|
+
readLoginEvents: readClaudeLoginEvents,
|
|
127
130
|
model,
|
|
128
131
|
modelChoice: claudeModelChoice,
|
|
129
132
|
identity: claudeIdentity,
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { FileMemo } from '../../core/file-memo.ts';
|
|
2
|
+
import type { Account, LoginEvents } from '../../types.ts';
|
|
3
|
+
/** How many of the newest main transcripts are read. */
|
|
4
|
+
export declare const LOGIN_SCAN_SESSIONS = 20;
|
|
5
|
+
/**
|
|
6
|
+
* Phrases Claude Code is known to use for an expired login, compared in lower case with every run of spaces and
|
|
7
|
+
* punctuation as one space. A `/login` hint or "Invalid API key" alone is not one: that is a different problem.
|
|
8
|
+
*/
|
|
9
|
+
export declare const EXPIRY_PHRASES: readonly ['login reached its time limit'];
|
|
10
|
+
/** Whether a Host message says the login expired, by the phrases above. */
|
|
11
|
+
export declare function saysLoginExpired(text: string): boolean;
|
|
12
|
+
interface Times {
|
|
13
|
+
expiredAt?: number;
|
|
14
|
+
workingAt?: number;
|
|
15
|
+
}
|
|
16
|
+
/** The newest expiry record and the newest normal assistant turn in the tail of one transcript. */
|
|
17
|
+
export declare function transcriptLoginTimes(file: string): Promise<Times>;
|
|
18
|
+
export declare const LISTING_MS = 60000;
|
|
19
|
+
/** Forgets every kept listing (for tests). */
|
|
20
|
+
export declare function clearLoginListings(): void;
|
|
21
|
+
export declare const claudeLoginMemo: FileMemo<Times>;
|
|
22
|
+
/** `FamilyDef.readLoginEvents` for Claude Code. An API Account is never checked. */
|
|
23
|
+
export declare function readClaudeLoginEvents(account: Account): Promise<LoginEvents>;
|
|
24
|
+
export {};
|