sideby 0.19.1 → 0.20.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/README.md +7 -4
- package/ai-tasks.json +28 -0
- package/dist/build.json +1 -1
- package/dist/src/cli/commands.d.ts +22 -1
- package/dist/src/cli/commands.js +815 -21
- package/dist/src/cli/format.d.ts +4 -0
- package/dist/src/cli/format.js +42 -4
- package/dist/src/cli/json-schemas.js +334 -4
- package/dist/src/cli/main.js +159 -13
- package/dist/src/core/accounts.d.ts +6 -0
- package/dist/src/core/accounts.js +12 -0
- package/dist/src/core/autostart.d.ts +11 -0
- package/dist/src/core/autostart.js +32 -5
- package/dist/src/core/browser-profiles.d.ts +23 -2
- package/dist/src/core/browser-profiles.js +148 -37
- package/dist/src/core/claude-settings-file.d.ts +18 -0
- package/dist/src/core/claude-settings-file.js +52 -3
- package/dist/src/core/config.d.ts +5 -0
- package/dist/src/core/config.js +12 -1
- package/dist/src/core/edit-settings.d.ts +7 -0
- package/dist/src/core/edit-settings.js +10 -5
- package/dist/src/core/history-group.d.ts +28 -0
- package/dist/src/core/history-group.js +47 -0
- package/dist/src/core/history-index.d.ts +145 -0
- package/dist/src/core/history-index.js +447 -0
- package/dist/src/core/history-project.d.ts +13 -0
- package/dist/src/core/history-project.js +87 -0
- package/dist/src/core/history.d.ts +210 -0
- package/dist/src/core/history.js +952 -0
- package/dist/src/core/inbound.d.ts +62 -0
- package/dist/src/core/inbound.js +215 -0
- package/dist/src/core/launch.d.ts +9 -1
- package/dist/src/core/launch.js +58 -24
- package/dist/src/core/live-sessions-copy.d.ts +5 -0
- package/dist/src/core/live-sessions-copy.js +46 -0
- package/dist/src/core/live-sessions-procs.d.ts +89 -0
- package/dist/src/core/live-sessions-procs.js +296 -0
- package/dist/src/core/live-sessions-title.d.ts +28 -0
- package/dist/src/core/live-sessions-title.js +80 -0
- package/dist/src/core/live-sessions.d.ts +68 -0
- package/dist/src/core/live-sessions.js +163 -0
- package/dist/src/core/login-check.d.ts +15 -0
- package/dist/src/core/login-check.js +32 -0
- package/dist/src/core/messages.d.ts +83 -0
- package/dist/src/core/messages.js +433 -0
- package/dist/src/core/project-categories.d.ts +14 -0
- package/dist/src/core/project-categories.js +48 -0
- package/dist/src/core/quota-fetch.d.ts +3 -3
- package/dist/src/core/quota-fetch.js +5 -5
- package/dist/src/core/quota-levels.d.ts +5 -0
- package/dist/src/core/quota-levels.js +5 -0
- package/dist/src/core/remote-control.d.ts +2 -0
- package/dist/src/core/remote-control.js +34 -59
- package/dist/src/core/run-link.d.ts +76 -0
- package/dist/src/core/run-link.js +245 -0
- package/dist/src/core/same-login.d.ts +4 -3
- package/dist/src/core/same-login.js +10 -7
- package/dist/src/core/session-select.d.ts +31 -0
- package/dist/src/core/session-select.js +44 -0
- package/dist/src/families/browser.d.ts +7 -18
- package/dist/src/families/browser.js +19 -8
- package/dist/src/families/claude/deliver.d.ts +2 -0
- package/dist/src/families/claude/deliver.js +43 -0
- package/dist/src/families/claude/history.d.ts +2 -0
- package/dist/src/families/claude/history.js +192 -0
- package/dist/src/families/claude/live-sessions.d.ts +13 -0
- package/dist/src/families/claude/live-sessions.js +117 -0
- package/dist/src/families/claude/messaging.d.ts +69 -0
- package/dist/src/families/claude/messaging.js +165 -0
- package/dist/src/families/claude/mod.d.ts +26 -0
- package/dist/src/families/claude/mod.js +105 -0
- package/dist/src/families/claude/session-files.d.ts +21 -0
- package/dist/src/families/claude/session-files.js +54 -0
- package/dist/src/families/codex/deliver.d.ts +5 -0
- package/dist/src/families/codex/deliver.js +76 -0
- package/dist/src/families/codex/history.d.ts +7 -0
- package/dist/src/families/codex/history.js +174 -0
- package/dist/src/families/codex/index.js +2 -0
- package/dist/src/families/codex/live-sessions.d.ts +12 -0
- package/dist/src/families/codex/live-sessions.js +193 -0
- package/dist/src/families/codex/quota.d.ts +3 -0
- package/dist/src/families/codex/quota.js +123 -0
- package/dist/src/families/codex/rate-limits.js +2 -0
- package/dist/src/families/codex/rollout.js +1 -1
- package/dist/src/families/grok/browser.d.ts +3 -0
- package/dist/src/families/grok/browser.js +5 -0
- package/dist/src/families/grok/history.d.ts +2 -0
- package/dist/src/families/grok/history.js +157 -0
- package/dist/src/families/grok/live-sessions.d.ts +4 -0
- package/dist/src/families/grok/live-sessions.js +80 -0
- package/dist/src/families/grok/login-key.d.ts +14 -0
- package/dist/src/families/grok/login-key.js +37 -0
- package/dist/src/families/history.d.ts +20 -0
- package/dist/src/families/history.js +81 -0
- package/dist/src/families/live-sessions.d.ts +26 -0
- package/dist/src/families/live-sessions.js +9 -0
- package/dist/src/families/login-keys.js +5 -1
- package/dist/src/families/messaging.d.ts +27 -0
- package/dist/src/families/messaging.js +6 -0
- package/dist/src/families/pi/history.d.ts +2 -0
- package/dist/src/families/pi/history.js +124 -0
- package/dist/src/families/pi/live-sessions.d.ts +2 -0
- package/dist/src/families/pi/live-sessions.js +70 -0
- package/dist/src/families/shared/history-text.d.ts +65 -0
- package/dist/src/families/shared/history-text.js +261 -0
- package/dist/src/menubar/hotkey.d.ts +86 -0
- package/dist/src/menubar/hotkey.js +159 -0
- package/dist/src/menubar/script.d.ts +2 -0
- package/dist/src/menubar/script.js +118 -22
- package/dist/src/menubar/snapshot.d.ts +8 -4
- package/dist/src/menubar/snapshot.js +45 -13
- package/dist/src/menubar/strings.d.ts +24 -6
- package/dist/src/menubar/strings.js +24 -6
- package/dist/src/panel/handler.d.ts +69 -0
- package/dist/src/panel/handler.js +686 -15
- package/dist/src/panel/i18n.d.ts +304 -3
- package/dist/src/panel/i18n.js +620 -18
- package/dist/src/panel/orca.d.ts +48 -0
- package/dist/src/panel/orca.js +153 -0
- package/dist/src/panel/page-logic.d.ts +255 -13
- package/dist/src/panel/page-logic.js +483 -1
- package/dist/src/panel/page-script.js +2260 -204
- package/dist/src/panel/page-styles.js +404 -32
- package/dist/src/panel/page.js +1 -0
- package/dist/src/plugins/check.js +16 -4
- package/dist/src/plugins/loader.d.ts +8 -1
- package/dist/src/plugins/loader.js +72 -7
- package/dist/src/runtime.d.ts +5 -0
- package/dist/src/runtime.js +27 -5
- package/dist/src/types.d.ts +116 -1
- package/dist/testing/index.d.ts +5 -0
- package/dist/testing/index.js +5 -0
- package/mods/claude/.claude-plugin/plugin.json +7 -0
- package/mods/claude/hooks/hooks.json +1 -0
- package/mods/claude/hooks/register.js +261 -0
- package/package.json +5 -2
- package/schemas/autostart.json +74 -1
- package/schemas/browser-set.json +110 -0
- package/schemas/browser.json +22 -2
- package/schemas/config.json +26 -1
- package/schemas/history-index.json +209 -0
- package/schemas/history-projects.json +133 -0
- package/schemas/history-show.json +275 -0
- package/schemas/history.json +410 -0
- package/schemas/menubar-hotkey.json +139 -0
- package/schemas/menubar-snapshot.json +36 -2
- package/schemas/menubar.json +74 -1
- package/schemas/messages-inbound.json +258 -0
- package/schemas/messages.json +164 -0
- package/schemas/send.json +165 -0
- package/schemas/sessions-copy.json +113 -0
- package/schemas/sessions-open-run.json +97 -0
- package/schemas/sessions.json +237 -0
- package/skills/sideby/SKILL.md +10 -5
- package/skills/sideby/references/accounts.md +11 -0
- package/skills/sideby/references/ai-tasks.md +17 -1
- package/skills/sideby/references/panel.md +6 -4
- package/skills/sideby/references/quota.md +2 -2
- package/skills/sideby/references/sessions.md +79 -0
|
@@ -313,6 +313,40 @@ export function mergeDaily(lists) {
|
|
|
313
313
|
.sort()
|
|
314
314
|
.map((date) => ({ date, totalTokens: sums[date] || 0 }));
|
|
315
315
|
}
|
|
316
|
+
/**
|
|
317
|
+
* One usage for the directories of a Same Login (spec §3.21): their token counts and days added up, their newest
|
|
318
|
+
* use. Directories without readable usage are left out; with none readable it is the first one's usage as it is.
|
|
319
|
+
*/
|
|
320
|
+
export function mergeUsage(usages) {
|
|
321
|
+
const ok = usages.filter((u) => Boolean(u && u.status === 'ok'));
|
|
322
|
+
if (ok.length < 2)
|
|
323
|
+
return ok[0] || usages[0];
|
|
324
|
+
const sum = (k) => ok.reduce((n, u) => n + (Number(u[k]) || 0), 0);
|
|
325
|
+
const at = (u) => {
|
|
326
|
+
const v = Date.parse(u.lastActivityAt || '');
|
|
327
|
+
return Number.isFinite(v) ? v : -1;
|
|
328
|
+
};
|
|
329
|
+
const newest = ok.reduce((x, y) => (at(y) > at(x) ? y : x));
|
|
330
|
+
const days = {};
|
|
331
|
+
for (const u of ok)
|
|
332
|
+
for (const d of u.daily || [])
|
|
333
|
+
if (d && typeof d.date === 'string')
|
|
334
|
+
days[d.date] = (days[d.date] || 0) + (Number(d.totalTokens) || 0);
|
|
335
|
+
return {
|
|
336
|
+
...ok[0],
|
|
337
|
+
status: 'ok',
|
|
338
|
+
sessions: sum('sessions'),
|
|
339
|
+
totalTokens: sum('totalTokens'),
|
|
340
|
+
inputTokens: sum('inputTokens'),
|
|
341
|
+
outputTokens: sum('outputTokens'),
|
|
342
|
+
cacheReadTokens: sum('cacheReadTokens'),
|
|
343
|
+
cacheWriteTokens: sum('cacheWriteTokens'),
|
|
344
|
+
daily: Object.keys(days)
|
|
345
|
+
.sort()
|
|
346
|
+
.map((date) => ({ date, totalTokens: days[date] || 0 })),
|
|
347
|
+
lastActivityAt: newest.lastActivityAt,
|
|
348
|
+
};
|
|
349
|
+
}
|
|
316
350
|
/** The soonest Quota reset still ahead of `now`, with the window label and Account. */
|
|
317
351
|
export function nextReset(accounts, now) {
|
|
318
352
|
let best = null;
|
|
@@ -546,6 +580,178 @@ export function updatedAge(ms) {
|
|
|
546
580
|
return { key: 'time.hAgo', n: h };
|
|
547
581
|
return { key: 'time.dAgo', n: Math.floor(h / 24) };
|
|
548
582
|
}
|
|
583
|
+
/**
|
|
584
|
+
* The Sessions page order: a Session that needs the user first, then the most recent activity (`updatedAt`, else
|
|
585
|
+
* `startedAt`), then the label, so two answers with the same Sessions keep the same order.
|
|
586
|
+
*/
|
|
587
|
+
export function sortSessions(list) {
|
|
588
|
+
const at = (s) => {
|
|
589
|
+
const ts = Date.parse(s.updatedAt || s.startedAt || '');
|
|
590
|
+
return Number.isFinite(ts) ? ts : 0;
|
|
591
|
+
};
|
|
592
|
+
const label = (s) => s.label || s.sessionId;
|
|
593
|
+
return list
|
|
594
|
+
.slice()
|
|
595
|
+
.sort((a, b) => (a.status === 'needs-you' ? 0 : 1) - (b.status === 'needs-you' ? 0 : 1) ||
|
|
596
|
+
at(b) - at(a) ||
|
|
597
|
+
(label(a) < label(b) ? -1 : label(a) > label(b) ? 1 : 0));
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* The order a refresh shows: Sessions already on screen keep their places (`shown`, their ids in screen order), so a
|
|
601
|
+
* Session that just answered does not jump past another. A Session that needs the user still goes first, and one not
|
|
602
|
+
* shown before comes ahead of the shown ones, in `sortSessions` order.
|
|
603
|
+
*/
|
|
604
|
+
export function steadyOrder(shown, list) {
|
|
605
|
+
const sorted = sortSessions(list);
|
|
606
|
+
if (!shown.length)
|
|
607
|
+
return sorted;
|
|
608
|
+
const pos = new Map(shown.map((id, i) => [id, i]));
|
|
609
|
+
const needs = (s) => (s.status === 'needs-you' ? 0 : 1);
|
|
610
|
+
const rank = sorted.map((s, i) => ({
|
|
611
|
+
s,
|
|
612
|
+
seen: pos.has(s.sessionId) ? 1 : 0,
|
|
613
|
+
at: pos.get(s.sessionId) ?? i,
|
|
614
|
+
}));
|
|
615
|
+
rank.sort((a, b) => needs(a.s) - needs(b.s) || a.seen - b.seen || a.at - b.at);
|
|
616
|
+
return rank.map((x) => x.s);
|
|
617
|
+
}
|
|
618
|
+
/** How long ago a Session was last active, as a message key and count; null when it has no time at all. */
|
|
619
|
+
export function sessionAge(s, now) {
|
|
620
|
+
const ts = Date.parse(s.updatedAt || s.startedAt || '');
|
|
621
|
+
return Number.isFinite(ts) ? updatedAge(Math.max(0, now - ts)) : null;
|
|
622
|
+
}
|
|
623
|
+
/**
|
|
624
|
+
* The three parts of a Session Label as the row shows them: the Account's short name (bold), the Host's title (the
|
|
625
|
+
* working directory's name when the Host gave none) and the first 8 characters of the id (monospace).
|
|
626
|
+
*/
|
|
627
|
+
export function sessionLabelParts(s) {
|
|
628
|
+
const dir = (s.cwd || '').replace(/\/+$/, '').split('/').pop() || '';
|
|
629
|
+
return {
|
|
630
|
+
account: s.accountLabel || s.account,
|
|
631
|
+
title: (s.title || '').trim() || dir,
|
|
632
|
+
id: s.sessionId.slice(0, 8),
|
|
633
|
+
};
|
|
634
|
+
}
|
|
635
|
+
/**
|
|
636
|
+
* What the "Send to it" dialog shows after a send: `done` (the Host took it; `hint` is any note, shown as a yellow
|
|
637
|
+
* hint), `approve` (it took it, but the target shows it only once the user approves it there; `reason` says how, ADR-0045),
|
|
638
|
+
* `paste` (the user pastes `pasteText`; `reason` says why, `jump` offers the
|
|
639
|
+
* target's Orca tab) or `stored` (kept as a file only; `pasteText` for reference). `key` is the headline's message key.
|
|
640
|
+
*/
|
|
641
|
+
export function sendResultView(m, orca) {
|
|
642
|
+
const pasteText = m.pasteText || '';
|
|
643
|
+
const note = (m.note || '').trim();
|
|
644
|
+
if (m.status === 'delivered' && m.needsApproval)
|
|
645
|
+
return { kind: 'approve', key: 'send.approve', pasteText, reason: note, hint: '', jump: false };
|
|
646
|
+
if (m.status === 'delivered' || m.status === 'read')
|
|
647
|
+
return {
|
|
648
|
+
kind: 'done',
|
|
649
|
+
key: m.status === 'read' ? 'send.read' : 'send.done',
|
|
650
|
+
pasteText,
|
|
651
|
+
reason: '',
|
|
652
|
+
hint: note,
|
|
653
|
+
jump: false,
|
|
654
|
+
};
|
|
655
|
+
if (m.status === 'paste-needed')
|
|
656
|
+
return {
|
|
657
|
+
kind: 'paste',
|
|
658
|
+
key: 'send.paste',
|
|
659
|
+
pasteText,
|
|
660
|
+
reason: note,
|
|
661
|
+
hint: '',
|
|
662
|
+
jump: Boolean(orca && pasteText),
|
|
663
|
+
};
|
|
664
|
+
return { kind: 'stored', key: 'send.stored', pasteText, reason: note, hint: '', jump: false };
|
|
665
|
+
}
|
|
666
|
+
/** The chip a Sessions row shows for the latest Message to it, or null when there is none worth showing. */
|
|
667
|
+
export function messageChip(status, needsApproval) {
|
|
668
|
+
// Taken by the Host, but shown only once the user approves it in the target's terminal (ADR-0045).
|
|
669
|
+
if (status === 'delivered' && needsApproval)
|
|
670
|
+
return { key: 'send.chip.approve', tone: 'warn' };
|
|
671
|
+
if (status === 'delivered')
|
|
672
|
+
return { key: 'send.chip.delivered', tone: 'accent' };
|
|
673
|
+
if (status === 'read')
|
|
674
|
+
return { key: 'send.chip.read', tone: 'ok' };
|
|
675
|
+
if (status === 'paste-needed')
|
|
676
|
+
return { key: 'send.chip.paste', tone: 'warn' };
|
|
677
|
+
return null;
|
|
678
|
+
}
|
|
679
|
+
/** A Session Label without its short id: `cc002 · knip cleanup · 61230c3d` → `cc002 · knip cleanup`. */
|
|
680
|
+
export function shortSessionLabel(label) {
|
|
681
|
+
const parts = (label || '').split(' · ').filter(Boolean);
|
|
682
|
+
if (parts.length > 1 && /^[0-9a-f]{8}$/i.test(parts[parts.length - 1]))
|
|
683
|
+
parts.pop();
|
|
684
|
+
return parts.join(' · ');
|
|
685
|
+
}
|
|
686
|
+
/**
|
|
687
|
+
* What changed between two readings of the latest Messages, for the Panel's notices (spec §3.32): `new` (a Message
|
|
688
|
+
* reached a Session), `approve` (it reached one that shows it only once the user approves it, ADR-0045), `read` (its
|
|
689
|
+
* Session read it) or `paste` (it waits for the user to paste it). The first reading (`before` null) only sets the
|
|
690
|
+
* baseline, so opening the Panel announces nothing that was already there.
|
|
691
|
+
*/
|
|
692
|
+
export function messageNews(before, after) {
|
|
693
|
+
if (!before)
|
|
694
|
+
return [];
|
|
695
|
+
const out = [];
|
|
696
|
+
for (const [sessionId, m] of Object.entries(after)) {
|
|
697
|
+
// A kept Message that is not delivered yet says nothing; it is announced once it arrives or needs a paste.
|
|
698
|
+
if (m.status === 'stored')
|
|
699
|
+
continue;
|
|
700
|
+
const was = before[sessionId];
|
|
701
|
+
const same = was && was.id === m.id;
|
|
702
|
+
if (same && was.status === m.status)
|
|
703
|
+
continue;
|
|
704
|
+
const fresh = !same || was.status === 'stored';
|
|
705
|
+
const kind = m.status === 'paste-needed'
|
|
706
|
+
? 'paste'
|
|
707
|
+
: fresh
|
|
708
|
+
? m.status === 'delivered' && m.needsApproval
|
|
709
|
+
? 'approve'
|
|
710
|
+
: 'new'
|
|
711
|
+
: m.status === 'read'
|
|
712
|
+
? 'read'
|
|
713
|
+
: null;
|
|
714
|
+
if (kind)
|
|
715
|
+
out.push({ kind, sessionId, id: m.id, to: shortSessionLabel(m.to), from: shortSessionLabel(m.from) });
|
|
716
|
+
}
|
|
717
|
+
return out;
|
|
718
|
+
}
|
|
719
|
+
/**
|
|
720
|
+
* Whether "Send to it" must wait: any screenshot that failed (refused, or its upload broke) stops the send, so a
|
|
721
|
+
* message never goes without a picture the user added. `names` lists them for the note; null lets it go.
|
|
722
|
+
*/
|
|
723
|
+
export function sendBlock(files) {
|
|
724
|
+
const failed = files.filter((f) => f.status === 'error').map((f) => f.name);
|
|
725
|
+
return failed.length ? { key: 'send.blocked', names: failed.join(', ') } : null;
|
|
726
|
+
}
|
|
727
|
+
/**
|
|
728
|
+
* Why "Send to it" refuses a file before uploading it, as a message key, or null when it may go: images only (PNG,
|
|
729
|
+
* JPEG, GIF, WebP), at most 20 MB each, at most 5. `kept` is how many the dialog already holds. The server checks all
|
|
730
|
+
* three again; this only says it sooner.
|
|
731
|
+
*/
|
|
732
|
+
export function sendFileProblem(file, kept) {
|
|
733
|
+
if (kept >= 5)
|
|
734
|
+
return 'send.max';
|
|
735
|
+
if (!['image/png', 'image/jpeg', 'image/gif', 'image/webp'].includes(file.type || ''))
|
|
736
|
+
return 'send.notImage';
|
|
737
|
+
if (file.size > 20 * 1024 * 1024)
|
|
738
|
+
return 'send.tooBig';
|
|
739
|
+
return null;
|
|
740
|
+
}
|
|
741
|
+
/**
|
|
742
|
+
* A working directory short enough for one row: whole when it fits in `max` characters, else its root (`~` or the
|
|
743
|
+
* first folder) and its last two folders around an ellipsis, else only the end. Empty when there is none.
|
|
744
|
+
*/
|
|
745
|
+
export function shortCwd(cwd, max = 44) {
|
|
746
|
+
if (!cwd)
|
|
747
|
+
return '';
|
|
748
|
+
if (cwd.length <= max)
|
|
749
|
+
return cwd;
|
|
750
|
+
const parts = cwd.split('/');
|
|
751
|
+
const head = parts[0] === '' ? `/${parts[1] || ''}` : parts[0];
|
|
752
|
+
const short = `${head}/…/${parts.slice(-2).join('/')}`;
|
|
753
|
+
return short.length <= max && parts.length > 4 ? short : `…${cwd.slice(-(max - 1))}`;
|
|
754
|
+
}
|
|
549
755
|
/**
|
|
550
756
|
* The Panel's language: a host `lang` of `en` or `zh` wins; `auto` uses the viewer's saved choice, then the browser
|
|
551
757
|
* language (`zh*` gives Chinese, anything else English).
|
|
@@ -691,6 +897,8 @@ export const AI_TASK_KINDS = [
|
|
|
691
897
|
'plugin',
|
|
692
898
|
'terminal',
|
|
693
899
|
'handoff',
|
|
900
|
+
'menubar',
|
|
901
|
+
'hotkey',
|
|
694
902
|
];
|
|
695
903
|
/**
|
|
696
904
|
* The message keys of the AI dialog for `task` (spec §3.28 "每个入口的提示"): its title, the text box placeholder and
|
|
@@ -791,6 +999,10 @@ export function taskPrompt(input, strip) {
|
|
|
791
999
|
plugin: '帮我写一个 sideby 插件或 hook。',
|
|
792
1000
|
terminal: '帮我让 sideby 能在我用的终端里打开 AI 任务:写一条自定义终端命令。',
|
|
793
1001
|
handoff: '帮我调好 sideby 的自动接力:根据我的账号推荐什么时候接力(阈值)和接力的顺序。',
|
|
1002
|
+
menubar: 'sideby 的状态栏额度图标在 macOS 顶栏里看不到,请帮我找出原因并让它显示出来。',
|
|
1003
|
+
hotkey: '帮我给 sideby 的状态栏菜单挑一个单手按着顺手、又没被别的程序占用的快捷键,并替我设好。',
|
|
1004
|
+
pHotkey: '先运行 `sideby menubar hotkey --json` 看现在用的组合。再查本机已经被占的组合:`defaults read com.apple.symbolichotkeys AppleSymbolicHotKeys` 里 enabled 为 1 的系统快捷键,以及 `/Applications` 里装了哪些常用全局快捷键的 App(Raycast、Alfred、ChatGPT、Claude 等),按它们的默认快捷键判断;不要打开它们的配置文件(里面可能有密钥),拿不准就问我。问我习惯用哪只手、平时常按哪些快捷键,然后推荐 2 到 3 个按起来顺手、又没被占的组合(两个键最顺手,比如 ⌥X;必须带 ⌥、⌘ 或 ⌃),说清每个会占掉什么(比如 ⌥X 不能再打出 ≈)。我选定后运行 `sideby menubar hotkey <组合>`,几秒内生效,不用重启;再请我按一下,确认能打开菜单。按了没反应,说明别的 App 先占了,换下一个。不要改系统或别的 App 的快捷键设置。',
|
|
1005
|
+
pMenubar: '先运行 `sideby menubar --json`。`state` 为 `off`:它被关掉了(常见于菜单里的「从状态栏隐藏…」),给我看 `sideby menubar on` 的预览,我同意后加 `--yes`。`state` 为 `on` 但 `loaded` 为 `false`:macOS 没在运行它,`sideby menubar on --yes` 只是重新启动,不改文件。`loaded` 为 `true`:它在运行但被挡住了,依次查:状态栏是否太满或被刘海挡住(按住 ⌘ 拖动图标);有没有 Ice、Bartender、Hidden Bar 这类菜单栏整理工具把它收起来了(查 `/Applications`,告诉我去它的设置里把 sideby(显示为 osascript)挪出来);macOS 26 及以上要在「系统设置 › 菜单栏」里允许 osascript(`sideby menubar --json` 里的快捷键 `hotkey.label` 可以在任何地方打开菜单,用来确认它在运行)。不要结束或重启任何不是 sideby 的进程。',
|
|
794
1006
|
cHandoff: '自动接力现在的设置(来自 `sideby handoff status --json`):',
|
|
795
1007
|
pHandoff: '先运行 `sideby handoff status --json` 和 `sideby quota --json`,看清每个账号的额度来源和用量。只用 `sideby handoff enable …` 或 `sideby config set handoff.<键> <值>` 改设置;先不加 `--yes` 给我看预览,我同意后再加 `--yes`。没有额度数据的账号排在顺序后面,并告诉我怎么让它显示额度。',
|
|
796
1008
|
cAccount: '账号:',
|
|
@@ -830,6 +1042,10 @@ export function taskPrompt(input, strip) {
|
|
|
830
1042
|
plugin: 'Help me write a sideby plugin or hook.',
|
|
831
1043
|
terminal: 'Help sideby open AI Tasks in the terminal I use: write a custom terminal command.',
|
|
832
1044
|
handoff: "Help me tune sideby's Auto Handoff: from my accounts, recommend when to hand over (the threshold) and in what order.",
|
|
1045
|
+
menubar: "I can't see sideby's quota icon in the macOS menu bar. Find out why and make it show.",
|
|
1046
|
+
hotkey: "Pick a shortcut for sideby's menu bar menu that is easy to press with one hand and that nothing else uses, and set it for me.",
|
|
1047
|
+
pHotkey: 'Run `sideby menubar hotkey --json` first to see the current shortcut. Then find the combinations already taken on this Mac: the system shortcuts with enabled 1 in `defaults read com.apple.symbolichotkeys AppleSymbolicHotKeys`, and the apps in /Applications that usually hold a global shortcut (Raycast, Alfred, ChatGPT, Claude and the like), judged by their default shortcuts; do not open their config files (they may hold keys), and ask me when unsure. Ask which hand I use and which shortcuts I press often, then recommend 2 or 3 combinations that are easy to press and free (two keys are easiest, such as ⌥X; each needs ⌥, ⌘ or ⌃), and say what each takes away (⌥X no longer types ≈). Once I pick one, run `sideby menubar hotkey <keys>`: it works within seconds, with no restart; then ask me to press it and check the menu opens. If nothing happens another app took it first, so try the next. Never change the shortcuts of macOS or another app.',
|
|
1048
|
+
pMenubar: 'Run `sideby menubar --json` first. `state` is `off`: it was turned off (often with "Hide from Menu Bar…" in its menu); show me the preview of `sideby menubar on`, and add `--yes` after I agree. `state` is `on` with `loaded: false`: macOS is not running it; `sideby menubar on --yes` only starts it again and changes no file. `loaded: true`: it runs but is hidden; check in turn whether the menu bar is too full or the notch covers it (hold ⌘ and drag icons), whether a menu bar organizer such as Ice, Bartender or Hidden Bar tucked it away (look in /Applications, and tell me where in its settings to move sideby, shown as osascript, out), and, on macOS 26 and later, whether osascript is allowed under System Settings › Menu Bar. The shortcut in `hotkey.label` opens the menu from anywhere, which shows it is running. Never end or restart a process that is not sideby\'s.',
|
|
833
1049
|
cHandoff: 'Auto Handoff now (from `sideby handoff status --json`):',
|
|
834
1050
|
pHandoff: 'Run `sideby handoff status --json` and `sideby quota --json` first to see where each account gets its quota and how much is used. Change settings only with `sideby handoff enable …` or `sideby config set handoff.<key> <value>`; show me the preview without `--yes` first, and add `--yes` only after I agree. Put accounts without quota data last in the order, and tell me how to make them show it.',
|
|
835
1051
|
cAccount: 'Account: ',
|
|
@@ -979,6 +1195,31 @@ export function panelMigration(config, local) {
|
|
|
979
1195
|
* The line under the start-at-login switch (spec §3.29) as a message key, whether it is on, whether the switch can
|
|
980
1196
|
* be moved, and the action beside it: `fix` turns it on again so it starts this sideby. Read-only: no switch, no action.
|
|
981
1197
|
*/
|
|
1198
|
+
/**
|
|
1199
|
+
* A key press in the Panel's shortcut recorder as config `menubar.hotkey` writes it (`ctrl+opt+s`), or null while only
|
|
1200
|
+
* modifiers are held or the key is not a letter or digit. Reads `code`, not `key`: on a Mac ⌥S types "ß".
|
|
1201
|
+
*/
|
|
1202
|
+
export function hotkeyFromKey(e) {
|
|
1203
|
+
const m = /^(?:Key([A-Z])|Digit([0-9]))$/.exec(e.code);
|
|
1204
|
+
if (!m)
|
|
1205
|
+
return null;
|
|
1206
|
+
const mods = [e.ctrlKey && 'ctrl', e.altKey && 'opt', e.shiftKey && 'shift', e.metaKey && 'cmd'].filter(Boolean);
|
|
1207
|
+
if (!mods.length)
|
|
1208
|
+
return null;
|
|
1209
|
+
return [...mods, (m[1] || m[2]).toLowerCase()].join('+');
|
|
1210
|
+
}
|
|
1211
|
+
/**
|
|
1212
|
+
* Whether a key press in the shortcut recorder is only a modifier being held (`wait`: the letter is still to come) or
|
|
1213
|
+
* a key the menu bar shortcut cannot use (`unsupported`: an arrow, F-key, Space and the like), so the recorder can say
|
|
1214
|
+
* so at once instead of looking stuck. A letter or digit is neither (see `hotkeyFromKey`).
|
|
1215
|
+
*/
|
|
1216
|
+
export function hotkeyPressKind(code) {
|
|
1217
|
+
if (/^(?:Key[A-Z]|Digit[0-9])$/.test(code))
|
|
1218
|
+
return 'key';
|
|
1219
|
+
if (/^(?:Meta|Control|Alt|Shift|OS|CapsLock|Fn)/.test(code) || code === '')
|
|
1220
|
+
return 'wait';
|
|
1221
|
+
return 'unsupported';
|
|
1222
|
+
}
|
|
982
1223
|
export function autostartNote(s, readOnly) {
|
|
983
1224
|
if (!s)
|
|
984
1225
|
return { key: 'as.checking', on: false, toggle: false, action: null };
|
|
@@ -987,7 +1228,14 @@ export function autostartNote(s, readOnly) {
|
|
|
987
1228
|
if (s.state === 'foreign')
|
|
988
1229
|
return { key: 'as.foreign', on: false, toggle: false, action: null };
|
|
989
1230
|
const on = s.state === 'on' || s.state === 'stale';
|
|
990
|
-
|
|
1231
|
+
// Not running comes after stale (that fix starts it too) and before another copy (the icon is what is missing).
|
|
1232
|
+
const fix = s.state === 'stale'
|
|
1233
|
+
? 'as.stale'
|
|
1234
|
+
: on && s.loaded === false
|
|
1235
|
+
? 'as.notRunning'
|
|
1236
|
+
: on && !s.current
|
|
1237
|
+
? 'as.other'
|
|
1238
|
+
: null;
|
|
991
1239
|
return { key: fix || 'as.hint', on, toggle: !readOnly, action: fix && !readOnly ? 'fix' : null };
|
|
992
1240
|
}
|
|
993
1241
|
/**
|
|
@@ -1078,3 +1326,237 @@ export function widthFollower(shown, tierOf, apply, settleMs, timers) {
|
|
|
1078
1326
|
timer = timers.set(settle, settleMs);
|
|
1079
1327
|
};
|
|
1080
1328
|
}
|
|
1329
|
+
// ---------- Session History (spec §3.33) ----------
|
|
1330
|
+
/** When a History row was last active: "x min ago" within a week, then its date (key `time.on`). */
|
|
1331
|
+
/**
|
|
1332
|
+
* Whether the end of a list is close enough to load its next page: within `margin` px of the bottom of what can be
|
|
1333
|
+
* seen, which is the viewport where the list's box grows with its rows (the page scrolls, not the box).
|
|
1334
|
+
*/
|
|
1335
|
+
export function tailInView(tailTop, boxBottom, viewHeight, margin = 200) {
|
|
1336
|
+
return tailTop < Math.min(boxBottom, viewHeight) + margin;
|
|
1337
|
+
}
|
|
1338
|
+
export function historyWhen(iso, now) {
|
|
1339
|
+
const ts = Date.parse(iso || '');
|
|
1340
|
+
if (!Number.isFinite(ts))
|
|
1341
|
+
return null;
|
|
1342
|
+
const ms = Math.max(0, now - ts);
|
|
1343
|
+
if (ms < 7 * 86_400_000)
|
|
1344
|
+
return updatedAge(ms);
|
|
1345
|
+
const d = new Date(ts);
|
|
1346
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
1347
|
+
return { key: 'time.on', date: d.getFullYear() + '-' + pad(d.getMonth() + 1) + '-' + pad(d.getDate()) };
|
|
1348
|
+
}
|
|
1349
|
+
/** `text` cut into the parts that match one of `words` (any case) and the parts between, for highlighting. */
|
|
1350
|
+
export function highlightParts(text, words) {
|
|
1351
|
+
const low = text.toLowerCase();
|
|
1352
|
+
const marks = [];
|
|
1353
|
+
for (const w of words) {
|
|
1354
|
+
const lw = w.toLowerCase();
|
|
1355
|
+
if (!lw)
|
|
1356
|
+
continue;
|
|
1357
|
+
for (let at = low.indexOf(lw); at >= 0; at = low.indexOf(lw, at + lw.length))
|
|
1358
|
+
marks.push([at, at + lw.length]);
|
|
1359
|
+
}
|
|
1360
|
+
marks.sort((a, b) => a[0] - b[0] || b[1] - a[1]);
|
|
1361
|
+
const out = [];
|
|
1362
|
+
let pos = 0;
|
|
1363
|
+
for (const [from, to] of marks) {
|
|
1364
|
+
if (to <= pos)
|
|
1365
|
+
continue;
|
|
1366
|
+
const start = Math.max(from, pos);
|
|
1367
|
+
if (start > pos)
|
|
1368
|
+
out.push({ text: text.slice(pos, start), hit: false });
|
|
1369
|
+
out.push({ text: text.slice(start, to), hit: true });
|
|
1370
|
+
pos = to;
|
|
1371
|
+
}
|
|
1372
|
+
if (pos < text.length)
|
|
1373
|
+
out.push({ text: text.slice(pos), hit: false });
|
|
1374
|
+
return out;
|
|
1375
|
+
}
|
|
1376
|
+
/**
|
|
1377
|
+
* What an empty History list says, and which way out it offers: a wider time range, searching tool output too.
|
|
1378
|
+
* Null while there are rows.
|
|
1379
|
+
*/
|
|
1380
|
+
export function historyEmpty(v) {
|
|
1381
|
+
if (v.total > 0)
|
|
1382
|
+
return null;
|
|
1383
|
+
const searching = v.q.trim() !== '';
|
|
1384
|
+
const widen = v.since !== 'all';
|
|
1385
|
+
if (v.state === 'building')
|
|
1386
|
+
return { key: 'hist.emptyBuilding', widen: false, tools: false };
|
|
1387
|
+
if (v.unreadable)
|
|
1388
|
+
return { key: 'hist.emptyUnreadable', widen: false, tools: false };
|
|
1389
|
+
if (v.accounts === 0)
|
|
1390
|
+
return { key: 'hist.emptyNoAccounts', widen: false, tools: false, accounts: true };
|
|
1391
|
+
if (v.stored === 0 && !searching)
|
|
1392
|
+
return { key: 'hist.emptyNone', widen: false, tools: false };
|
|
1393
|
+
if (searching && v.project)
|
|
1394
|
+
return { key: 'hist.emptyMatchProject', widen, tools: !v.tools, everywhere: true };
|
|
1395
|
+
if (searching)
|
|
1396
|
+
return { key: 'hist.emptyMatch', widen, tools: !v.tools };
|
|
1397
|
+
if (v.project)
|
|
1398
|
+
return { key: 'hist.emptyProject', widen, tools: false };
|
|
1399
|
+
return { key: widen ? 'hist.emptySince' : 'hist.emptyNone', widen, tools: false };
|
|
1400
|
+
}
|
|
1401
|
+
/** A Session's messages for reading, with each run of tool calls folded into one line naming the tools. */
|
|
1402
|
+
export function foldToolCalls(messages) {
|
|
1403
|
+
const out = [];
|
|
1404
|
+
for (const m of messages) {
|
|
1405
|
+
const last = out[out.length - 1];
|
|
1406
|
+
if (m.role !== 'tool')
|
|
1407
|
+
out.push(m);
|
|
1408
|
+
else if (last && last.role === 'tools')
|
|
1409
|
+
last.tools.push(m.tool || m.text);
|
|
1410
|
+
else
|
|
1411
|
+
out.push(m.at
|
|
1412
|
+
? { role: 'tools', tools: [m.tool || m.text], n: m.n, at: m.at }
|
|
1413
|
+
: { role: 'tools', tools: [m.tool || m.text], n: m.n });
|
|
1414
|
+
}
|
|
1415
|
+
return out;
|
|
1416
|
+
}
|
|
1417
|
+
/**
|
|
1418
|
+
* Splits a message into Markdown blocks: headings, fenced code, quotes, lists, GitHub tables, rules and paragraphs.
|
|
1419
|
+
* An unclosed fence (a message cut short) runs to the end. Anything else is a paragraph, line breaks kept.
|
|
1420
|
+
*/
|
|
1421
|
+
export function mdBlocks(text) {
|
|
1422
|
+
const lines = text.replace(/\r\n?/g, '\n').split('\n');
|
|
1423
|
+
const out = [];
|
|
1424
|
+
const cells = (line) => {
|
|
1425
|
+
let s = line.trim();
|
|
1426
|
+
if (s.startsWith('|'))
|
|
1427
|
+
s = s.slice(1);
|
|
1428
|
+
if (s.endsWith('|') && !s.endsWith('\\|'))
|
|
1429
|
+
s = s.slice(0, -1);
|
|
1430
|
+
return s.split(/(?<!\\)\|/).map((c) => c.trim().replace(/\\\|/g, '|'));
|
|
1431
|
+
};
|
|
1432
|
+
const isRule = (line) => /^\s*\|?\s*:?-+:?\s*(\|\s*:?-+:?\s*)*\|?\s*$/.test(line) && line.includes('-');
|
|
1433
|
+
const listItem = (line) => /^\s{0,3}([-*+]|\d{1,9}[.)])\s+(.*)$/.exec(line);
|
|
1434
|
+
let para = [];
|
|
1435
|
+
const flush = () => {
|
|
1436
|
+
if (para.length)
|
|
1437
|
+
out.push({ type: 'p', text: para.join('\n') });
|
|
1438
|
+
para = [];
|
|
1439
|
+
};
|
|
1440
|
+
let i = 0;
|
|
1441
|
+
while (i < lines.length) {
|
|
1442
|
+
const line = lines[i];
|
|
1443
|
+
const fence = /^\s{0,3}(`{3,}|~{3,})\s*([\w+-]*)/.exec(line);
|
|
1444
|
+
if (fence) {
|
|
1445
|
+
flush();
|
|
1446
|
+
const body = [];
|
|
1447
|
+
i++;
|
|
1448
|
+
while (i < lines.length && !lines[i].trim().startsWith(fence[1]))
|
|
1449
|
+
body.push(lines[i++]);
|
|
1450
|
+
i++;
|
|
1451
|
+
out.push({ type: 'code', lang: fence[2] || '', text: body.join('\n') });
|
|
1452
|
+
continue;
|
|
1453
|
+
}
|
|
1454
|
+
if (!line.trim()) {
|
|
1455
|
+
flush();
|
|
1456
|
+
i++;
|
|
1457
|
+
continue;
|
|
1458
|
+
}
|
|
1459
|
+
const head = /^\s{0,3}(#{1,6})\s+(.*?)\s*#*\s*$/.exec(line);
|
|
1460
|
+
if (head) {
|
|
1461
|
+
flush();
|
|
1462
|
+
out.push({ type: 'h', level: head[1].length, text: head[2] });
|
|
1463
|
+
i++;
|
|
1464
|
+
continue;
|
|
1465
|
+
}
|
|
1466
|
+
if (/^\s{0,3}([-*_])(\s*\1){2,}\s*$/.test(line)) {
|
|
1467
|
+
flush();
|
|
1468
|
+
out.push({ type: 'hr' });
|
|
1469
|
+
i++;
|
|
1470
|
+
continue;
|
|
1471
|
+
}
|
|
1472
|
+
if (line.includes('|') && i + 1 < lines.length && isRule(lines[i + 1])) {
|
|
1473
|
+
const headCells = cells(line);
|
|
1474
|
+
const align = cells(lines[i + 1]).map((c) => c.startsWith(':') && c.endsWith(':')
|
|
1475
|
+
? 'center'
|
|
1476
|
+
: c.endsWith(':')
|
|
1477
|
+
? 'right'
|
|
1478
|
+
: c.startsWith(':')
|
|
1479
|
+
? 'left'
|
|
1480
|
+
: '');
|
|
1481
|
+
if (align.length === headCells.length) {
|
|
1482
|
+
flush();
|
|
1483
|
+
const rows = [];
|
|
1484
|
+
i += 2;
|
|
1485
|
+
while (i < lines.length && lines[i].includes('|') && lines[i].trim()) {
|
|
1486
|
+
const r = cells(lines[i++]);
|
|
1487
|
+
rows.push(headCells.map((_, k) => r[k] ?? ''));
|
|
1488
|
+
}
|
|
1489
|
+
out.push({ type: 'table', head: headCells, align, rows });
|
|
1490
|
+
continue;
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
if (/^\s{0,3}>/.test(line)) {
|
|
1494
|
+
flush();
|
|
1495
|
+
const body = [];
|
|
1496
|
+
while (i < lines.length && /^\s{0,3}>/.test(lines[i]))
|
|
1497
|
+
body.push(lines[i++].replace(/^\s{0,3}>\s?/, ''));
|
|
1498
|
+
out.push({ type: 'quote', text: body.join('\n') });
|
|
1499
|
+
continue;
|
|
1500
|
+
}
|
|
1501
|
+
const item = listItem(line);
|
|
1502
|
+
// A list may start right under a paragraph line; a numbered one only from 1, as in CommonMark.
|
|
1503
|
+
if (item && (!para.length || !/\d/.test(item[1]) || /^1\D/.test(item[1]))) {
|
|
1504
|
+
flush();
|
|
1505
|
+
const ordered = /\d/.test(item[1]);
|
|
1506
|
+
const items = [];
|
|
1507
|
+
while (i < lines.length) {
|
|
1508
|
+
const m = listItem(lines[i]);
|
|
1509
|
+
if (m && /\d/.test(m[1]) === ordered)
|
|
1510
|
+
items.push(m[2]);
|
|
1511
|
+
else if (items.length && lines[i].trim() && /^\s{2,}/.test(lines[i]))
|
|
1512
|
+
items[items.length - 1] += '\n' + lines[i].trim();
|
|
1513
|
+
else
|
|
1514
|
+
break;
|
|
1515
|
+
i++;
|
|
1516
|
+
}
|
|
1517
|
+
out.push({ type: 'list', ordered, items });
|
|
1518
|
+
continue;
|
|
1519
|
+
}
|
|
1520
|
+
para.push(line);
|
|
1521
|
+
i++;
|
|
1522
|
+
}
|
|
1523
|
+
flush();
|
|
1524
|
+
return out;
|
|
1525
|
+
}
|
|
1526
|
+
/** Inline Markdown in one block: `code`, **bold**, *italic*, and [links](https://…) with a web address only. */
|
|
1527
|
+
export function mdInline(text) {
|
|
1528
|
+
const out = [];
|
|
1529
|
+
const re = /(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)|\*\*([^*\n]+?)\*\*|__([^_\n]+?)__|\*([^*\s][^*\n]*?)\*|\[([^\]\n]+)\]\((https?:\/\/[^\s)]+)\)/g;
|
|
1530
|
+
let last = 0;
|
|
1531
|
+
for (const m of text.matchAll(re)) {
|
|
1532
|
+
if (m.index > last)
|
|
1533
|
+
out.push({ t: 'text', text: text.slice(last, m.index) });
|
|
1534
|
+
if (m[1])
|
|
1535
|
+
out.push({ t: 'code', text: m[2].trim() || m[2] });
|
|
1536
|
+
else if (m[3] || m[4])
|
|
1537
|
+
out.push({ t: 'b', text: (m[3] || m[4]) });
|
|
1538
|
+
else if (m[5])
|
|
1539
|
+
out.push({ t: 'i', text: m[5] });
|
|
1540
|
+
else
|
|
1541
|
+
out.push({ t: 'a', text: m[6], href: m[7] });
|
|
1542
|
+
last = m.index + m[0].length;
|
|
1543
|
+
}
|
|
1544
|
+
if (last < text.length)
|
|
1545
|
+
out.push({ t: 'text', text: text.slice(last) });
|
|
1546
|
+
return out;
|
|
1547
|
+
}
|
|
1548
|
+
/** The History filters saved before a reload, each dropped back to its default when it is missing or malformed. */
|
|
1549
|
+
export function histFilters(raw) {
|
|
1550
|
+
const o = raw && typeof raw === 'object' ? raw : {};
|
|
1551
|
+
const str = (v) => (typeof v === 'string' && v.length <= 1000 ? v : '');
|
|
1552
|
+
const since = str(o.since);
|
|
1553
|
+
return {
|
|
1554
|
+
q: str(o.q),
|
|
1555
|
+
since: ['today', '7d', '30d', 'all'].includes(since) ? since : '30d',
|
|
1556
|
+
family: str(o.family),
|
|
1557
|
+
account: str(o.account),
|
|
1558
|
+
project: str(o.project),
|
|
1559
|
+
category: str(o.category),
|
|
1560
|
+
scripts: o.scripts === true,
|
|
1561
|
+
};
|
|
1562
|
+
}
|