sideby 0.18.0 → 0.19.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.
Files changed (40) hide show
  1. package/README.md +8 -0
  2. package/dist/build.json +1 -1
  3. package/dist/src/cli/commands.js +159 -13
  4. package/dist/src/cli/json-schemas.js +39 -1
  5. package/dist/src/cli/main.js +23 -6
  6. package/dist/src/core/ask.d.ts +14 -0
  7. package/dist/src/core/ask.js +16 -1
  8. package/dist/src/core/browser-profiles.js +7 -32
  9. package/dist/src/core/config.d.ts +14 -0
  10. package/dist/src/core/config.js +64 -1
  11. package/dist/src/core/pick-commands.d.ts +42 -0
  12. package/dist/src/core/pick-commands.js +44 -0
  13. package/dist/src/core/shell-init.js +3 -1
  14. package/dist/src/core/shell-setup.d.ts +40 -0
  15. package/dist/src/core/shell-setup.js +54 -0
  16. package/dist/src/core/skill-check.d.ts +2 -0
  17. package/dist/src/core/skill-check.js +2 -0
  18. package/dist/src/core/terminal.d.ts +21 -4
  19. package/dist/src/core/terminal.js +149 -9
  20. package/dist/src/core/update.js +2 -2
  21. package/dist/src/core/windows-dirs.d.ts +19 -0
  22. package/dist/src/core/windows-dirs.js +39 -0
  23. package/dist/src/panel/handler.d.ts +18 -0
  24. package/dist/src/panel/handler.js +69 -1
  25. package/dist/src/panel/i18n.d.ts +39 -0
  26. package/dist/src/panel/i18n.js +78 -0
  27. package/dist/src/panel/page-script.js +182 -3
  28. package/dist/src/panel/page-styles.js +3 -0
  29. package/dist/src/panel/page.js +6 -1
  30. package/dist/src/runtime.d.ts +35 -1
  31. package/dist/src/runtime.js +96 -3
  32. package/package.json +2 -2
  33. package/schemas/alias-list.json +119 -0
  34. package/schemas/alias.json +27 -1
  35. package/schemas/config.json +11 -0
  36. package/schemas/new.json +19 -0
  37. package/schemas/shell-init-setup.json +124 -0
  38. package/skills/sideby/SKILL.md +6 -3
  39. package/skills/sideby/references/accounts.md +10 -0
  40. package/skills/sideby/references/setup.md +1 -1
@@ -0,0 +1,39 @@
1
+ // Windows' own folders as WSL sees them (spec §3.24, §3.28): one `cmd.exe` call names the current Windows user's
2
+ // `%LOCALAPPDATA%` and the Program Files folders, so sideby never guesses between the users under `C:\Users`.
3
+ import { join } from 'node:path';
4
+ /** A Windows drive path (`C:\Windows`) as WSL mounts it (`/mnt/c/Windows`); undefined for anything else. */
5
+ export function toUnix(win, mount) {
6
+ const m = /^([A-Za-z]):\\(.*)$/.exec(win.trim());
7
+ if (!m)
8
+ return undefined;
9
+ return join(mount, m[1].toLowerCase(), ...m[2].split('\\').filter(Boolean));
10
+ }
11
+ const memo = new Map();
12
+ /**
13
+ * The current Windows user's folders, from one `cmd.exe` call, remembered for the process; null when cmd.exe does not
14
+ * answer (WSL interop off, or no C: drive), for the caller to fall back without guessing between users.
15
+ */
16
+ export async function askWindowsDirs(exec, mount) {
17
+ const hit = memo.get(mount);
18
+ if (hit)
19
+ return hit;
20
+ const r = await exec(join(mount, 'c', 'Windows', 'System32', 'cmd.exe'), [
21
+ '/d',
22
+ '/c',
23
+ 'echo %LOCALAPPDATA%^|%ProgramFiles%^|%ProgramFiles(x86)%',
24
+ ]).catch(() => null);
25
+ const parts = r?.code === 0 ? r.stdout.trim().split('|') : [];
26
+ const dir = (win) => {
27
+ const unix = win ? toUnix(win, mount) : undefined;
28
+ return win && unix ? { win: win.trim(), unix } : undefined;
29
+ };
30
+ const local = dir(parts[0]);
31
+ if (!local)
32
+ return null;
33
+ const found = {
34
+ localAppData: local,
35
+ programs: [dir(parts[1]), dir(parts[2])].filter((d) => d !== undefined),
36
+ };
37
+ memo.set(mount, found);
38
+ return found;
39
+ }
@@ -149,6 +149,24 @@ export interface PanelState {
149
149
  history?: DoctorHistory;
150
150
  /** The config `aliases` as alias → Account ref (arguments left out), so the page can tell which names are taken. */
151
151
  configAliases?: Record<string, string>;
152
+ /** The config `pickCommands`, name → Family (spec §3.13, ADR-0035). */
153
+ pickCommands?: Record<string, string>;
154
+ /**
155
+ * Family → the Pick Command the page offers to add: a Family with two or more Subscription Accounts and none yet,
156
+ * with the command on PATH the name would hide; `name: null` when no default name is free (the user types one).
157
+ */
158
+ pickOffers?: Record<string, {
159
+ name: string | null;
160
+ shadows?: string;
161
+ }>;
162
+ /** Whether new terminals load the short commands (`sideby shell-init setup`, ADR-0036), and the rc file it would edit. */
163
+ shellSetup: {
164
+ shell: 'zsh' | 'bash';
165
+ rc: string;
166
+ loaded: boolean;
167
+ added: boolean;
168
+ block: string;
169
+ };
152
170
  /**
153
171
  * Family → the Account `sideby next <family>` would pick (spec §3.13). Only Families with a Quota source,
154
172
  * at least two subscription Accounts, some Quota data and a pick; API Accounts are left out as in the CLI default.
@@ -2,7 +2,7 @@
2
2
  import { randomBytes, timingSafeEqual } from 'node:crypto';
3
3
  import { aliasesByAccount } from '../core/accounts.js';
4
4
  import { listAppProfiles, openAppProfile, removeAppProfile, } from '../core/app-profiles.js';
5
- import { openLoginInTerminal, pickTaskAccount, previewAttachments, promptForTask, setCustomTerminal, setPreferredTerminal, startAiTask, taskContext, terminals, tryAccount, } from '../core/ask.js';
5
+ import { openLoginInTerminal, openPickInTerminal, pickTaskAccount, previewAttachments, promptForTask, setCustomTerminal, setPreferredTerminal, startAiTask, taskContext, terminals, tryAccount, } from '../core/ask.js';
6
6
  import { MAX_ATTACHMENTS, MAX_UPLOAD_BYTES, removeStaged, stageUpload } from '../core/attachments.js';
7
7
  import { applyAutostart, autostartStatus, PANEL_AGENT, planAutostart, } from '../core/autostart.js';
8
8
  import { FAVICON_SVG, ICON_SVG } from '../core/brand-mark.js';
@@ -382,6 +382,14 @@ async function buildState(rt, opts) {
382
382
  };
383
383
  });
384
384
  const handoff = handoffByFamily(rt, list, ctx.now);
385
+ const pickOffers = {};
386
+ for (const f of families) {
387
+ const offer = await rt.pickSuggestion(f.id, accounts).catch(() => null);
388
+ if (offer && !offer.exists)
389
+ pickOffers[f.id] = { name: offer.name, ...(offer.shadows ? { shadows: offer.shadows } : {}) };
390
+ }
391
+ const { setupBlock, shellSetupStatus, userShell } = await import('../core/shell-setup.js');
392
+ const shellSt = await shellSetupStatus(userShell(rt.env), ctx.home, rt.env, rt.config.shellInitFile);
385
393
  const browser = await browserReport(rt, accounts).catch(() => undefined);
386
394
  const showBrowser = browser && (browser.families.matched.length || browser.families.openOnly.length);
387
395
  return {
@@ -401,6 +409,9 @@ async function buildState(rt, opts) {
401
409
  quotaSetups,
402
410
  ...(history ? { history } : {}),
403
411
  ...(rt.config.aliases ? { configAliases: aliasRefs(rt.config.aliases) } : {}),
412
+ ...(rt.config.pickCommands ? { pickCommands: { ...rt.config.pickCommands } } : {}),
413
+ ...(Object.keys(pickOffers).length ? { pickOffers } : {}),
414
+ shellSetup: { ...shellSt, rc: tildify(shellSt.rc, ctx.home), block: setupBlock(shellSt.shell) },
404
415
  ...(Object.keys(handoff).length ? { handoff } : {}),
405
416
  ...(remoteControl.length ? { remoteControl: rcView(remoteControl, ctx.home) } : {}),
406
417
  ...(appProfiles.length
@@ -741,6 +752,63 @@ export function createPanelHandler(opts) {
741
752
  return rt.createAccount(family, name, { api, ...(alias ? { alias } : {}) });
742
753
  },
743
754
  },
755
+ // Pick Commands (spec §3.13, ADR-0035): start the Account with the most room in the Preferred Terminal, add one
756
+ // (a name that hides a command on PATH comes back as `confirm` until the page sends confirm: true), remove one.
757
+ '/api/pick/start': {
758
+ async run(body) {
759
+ const name = optString(body, 'name');
760
+ if (!name)
761
+ throw new HttpError(400, '"name" is required');
762
+ const rt = await getRuntime();
763
+ const { family, choice } = await rt.pickChoice(name);
764
+ if (choice.ref === null)
765
+ throw new UserError(choice.earliestReset
766
+ ? `Every ${family} account is at its limit; ${choice.earliestReset.ref} is back first.`
767
+ : `No ${family} account can be used now; sign one in first.`, { code: 'none-usable' });
768
+ // The terminal runs the Pick Command itself, so it picks again as it starts and prints which and why.
769
+ const r = opened(await openPickInTerminal(rt, name));
770
+ return {
771
+ ...r,
772
+ name,
773
+ family,
774
+ picked: choice.ref,
775
+ reason: choice.reason,
776
+ ...('pressure' in choice ? { pressure: choice.pressure } : {}),
777
+ };
778
+ },
779
+ },
780
+ '/api/pick/add': {
781
+ async run(body) {
782
+ const name = optString(body, 'name')?.trim();
783
+ const family = optString(body, 'family');
784
+ if (!name || !family)
785
+ throw new HttpError(400, 'enter a name and pick a family');
786
+ const rt = await getRuntime();
787
+ return rt.addPickCommand(name, family, { yes: optBool(body, 'confirm') });
788
+ },
789
+ },
790
+ '/api/pick/remove': {
791
+ async run(body) {
792
+ const name = optString(body, 'name');
793
+ if (!name)
794
+ throw new HttpError(400, '"name" is required');
795
+ const rt = await getRuntime();
796
+ if (rt.pickCommandFamily(name) === undefined)
797
+ throw new HttpError(400, `no pick command "${name}"`);
798
+ return rt.removeAlias(name);
799
+ },
800
+ },
801
+ // `sideby shell-init setup` (ADR-0036): the page has shown the line and the file; undo takes out only that line.
802
+ '/api/shell-init/setup': {
803
+ async run(body) {
804
+ const rt = await getRuntime();
805
+ const { applyShellSetup, userShell } = await import('../core/shell-setup.js');
806
+ const r = await applyShellSetup(userShell(rt.env), rt.paths.home, rt.env, rt.config.shellInitFile, {
807
+ undo: optBool(body, 'undo'),
808
+ });
809
+ return { status: r.status, shell: r.shell, rc: tildify(r.rc, rt.paths.home) };
810
+ },
811
+ },
744
812
  '/api/quota/setup': {
745
813
  writes: (body) => body.confirm === true,
746
814
  async run(body) {
@@ -2,6 +2,7 @@ export type PanelLang = 'en' | 'zh';
2
2
  declare const en: {
3
3
  'top.tagline': string;
4
4
  'top.refresh': string;
5
+ 'top.repo': string;
5
6
  'top.loading': string;
6
7
  'top.refreshing': string;
7
8
  'top.updated': string;
@@ -411,6 +412,7 @@ declare const en: {
411
412
  'ai.examples': string;
412
413
  'ai.copy': string;
413
414
  'ai.ask.quota': string;
415
+ 'ai.ask.pick': string;
414
416
  'ai.ask.new': string;
415
417
  'ai.ask.pin': string;
416
418
  'ai.ask.fix': string;
@@ -508,6 +510,43 @@ declare const en: {
508
510
  'ask.otherTool': string;
509
511
  'ask.otherToolSub': string;
510
512
  'ask.plugin': string;
513
+ 'pk.title': string;
514
+ 'pk.intro': string;
515
+ 'pk.none': string;
516
+ 'pk.noneYet': string;
517
+ 'pk.exists': string;
518
+ 'pk.start': string;
519
+ 'pk.startTip': string;
520
+ 'pk.remove': string;
521
+ 'pk.removed': string;
522
+ 'pk.nameLabel': string;
523
+ 'pk.hint': string;
524
+ 'pk.shadows': string;
525
+ 'pk.add': string;
526
+ 'pk.addAnyway': string;
527
+ 'pk.added': string;
528
+ 'pk.newShell': string;
529
+ 'pk.offerShort': string;
530
+ 'pk.offerMore': string;
531
+ 'pk.rename': string;
532
+ 'pk.addedSetup': string;
533
+ 'pk.renamedSetup': string;
534
+ 'ss.title': string;
535
+ 'ss.body': string;
536
+ 'ss.add': string;
537
+ 'ss.adding': string;
538
+ 'ss.added': string;
539
+ 'ss.undo': string;
540
+ 'ss.removed': string;
541
+ 'pk.save': string;
542
+ 'pk.renamed': string;
543
+ 'pk.fileFailed': string;
544
+ 'pk.why.othersFull': string;
545
+ 'pk.offerNoName': string;
546
+ 'pk.namePh': string;
547
+ 'pk.started': string;
548
+ 'pk.why.room': string;
549
+ 'pk.why.noData': string;
511
550
  'login.opened': string;
512
551
  'login.failed': string;
513
552
  'login.automation': string;
@@ -4,6 +4,7 @@
4
4
  const en = {
5
5
  'top.tagline': 'Every AI coding account, side by side.',
6
6
  'top.refresh': 'Refresh',
7
+ 'top.repo': 'sideby on GitHub',
7
8
  'top.loading': 'Loading…',
8
9
  'top.refreshing': 'Refreshing…',
9
10
  'top.updated': 'Read {ago} · refreshes every {s} s',
@@ -413,6 +414,7 @@ const en = {
413
414
  'ai.examples': 'Things you can say (click to copy):',
414
415
  'ai.copy': 'Copy',
415
416
  'ai.ask.quota': 'Which of my Claude accounts has the most quota left?',
417
+ 'ai.ask.pick': 'Add cc: start whichever Claude account has the most quota left.',
416
418
  'ai.ask.new': 'Add another Claude account with the short command cc009.',
417
419
  'ai.ask.pin': 'Pin claude:work to the top.',
418
420
  'ai.ask.fix': 'Check my accounts and fix what they should share.',
@@ -510,6 +512,43 @@ const en = {
510
512
  'ask.otherTool': 'Other tool…',
511
513
  'ask.otherToolSub': 'Not in this list',
512
514
  'ask.plugin': 'Let AI write a plugin',
515
+ 'pk.title': 'Start the one with most room',
516
+ 'pk.intro': 'A short command per tool that starts, each time, the account with the most quota left. When no account has quota data yet, it starts the main account and says so.',
517
+ 'pk.none': 'Add a second account of a tool first: with one account there is nothing to pick.',
518
+ 'pk.noneYet': 'Not set',
519
+ 'pk.exists': 'starts the {host} account with the most room.',
520
+ 'pk.start': 'Start the one with most room',
521
+ 'pk.startTip': '{name} in a terminal: starts the {host} account with the most quota left',
522
+ 'pk.remove': 'Remove',
523
+ 'pk.removed': 'Removed {name}.',
524
+ 'pk.nameLabel': 'Short command for {host}',
525
+ 'pk.hint': 'Type it in a terminal to start the {host} account with the most room.',
526
+ 'pk.shadows': '{name} is already a command on this computer ({path}). In your shell, typing {name} would start {host} instead.',
527
+ 'pk.add': 'Add',
528
+ 'pk.addAnyway': 'Add anyway',
529
+ 'pk.added': 'Added {name}. It works in a new terminal window.',
530
+ 'pk.newShell': 'New short commands work in a new terminal window.',
531
+ 'pk.offerShort': 'Add {name}',
532
+ 'pk.offerMore': ': start the one with most room',
533
+ 'pk.rename': 'Rename',
534
+ 'pk.addedSetup': 'Added {name}. One more step: let new terminals load it (above).',
535
+ 'pk.renamedSetup': 'Renamed {old} to {name}. One more step: let new terminals load it (above).',
536
+ 'ss.title': 'New terminals do not load your short commands yet.',
537
+ 'ss.body': 'sideby can add this line to the end of {rc}:',
538
+ 'ss.add': 'Add the line',
539
+ 'ss.adding': 'Adding…',
540
+ 'ss.added': 'Added to {rc}. Short commands work in a new terminal window.',
541
+ 'ss.undo': 'Undo',
542
+ 'ss.removed': 'Took sideby’s line out of {rc}.',
543
+ 'pk.save': 'Save',
544
+ 'pk.renamed': 'Renamed {old} to {name}. It works in a new terminal window.',
545
+ 'pk.fileFailed': 'Saved in the config, but a shell-init file was not rewritten: {msg}',
546
+ 'pk.why.othersFull': 'no quota data for it yet; the accounts with data are full',
547
+ 'pk.offerNoName': 'Add a short command: start the one with most room',
548
+ 'pk.namePh': 'for example cc',
549
+ 'pk.started': 'Opened {terminal} with {ref} ({why}).',
550
+ 'pk.why.room': '{n}% used, the most room',
551
+ 'pk.why.noData': 'no quota data yet',
513
552
  'login.opened': 'Opened {terminal}: sign in to {ref} there.',
514
553
  'login.failed': 'Could not open a terminal. Copied: paste it into your terminal and press Return.',
515
554
  'login.automation': 'Copied. To let sideby open {terminal}, turn it on in System Settings → Privacy & Security → Automation.',
@@ -959,6 +998,7 @@ const en = {
959
998
  const zh = {
960
999
  'top.tagline': '所有 AI 编程账号,并排运行。',
961
1000
  'top.refresh': '刷新',
1001
+ 'top.repo': 'sideby 的 GitHub 仓库',
962
1002
  'top.loading': '加载中…',
963
1003
  'top.refreshing': '刷新中…',
964
1004
  'top.updated': '{ago}读取 · 每 {s} 秒自动刷新',
@@ -1368,6 +1408,7 @@ const zh = {
1368
1408
  'ai.examples': '可以这样说(点一下复制):',
1369
1409
  'ai.copy': '复制',
1370
1410
  'ai.ask.quota': '我哪个 Claude 账号剩余额度最多?',
1411
+ 'ai.ask.pick': '加个 cc:每次自动启动额度最多的 Claude 账号。',
1371
1412
  'ai.ask.new': '再加一个 Claude 账号,短命令叫 cc009。',
1372
1413
  'ai.ask.pin': '把 claude:work 置顶。',
1373
1414
  'ai.ask.fix': '检查一下我的账号,把该共享的修好。',
@@ -1465,6 +1506,43 @@ const zh = {
1465
1506
  'ask.otherTool': '其他工具……',
1466
1507
  'ask.otherToolSub': '列表里没有',
1467
1508
  'ask.plugin': '让 AI 写插件',
1509
+ 'pk.title': '自动选最空的账号',
1510
+ 'pk.intro': '每个工具一个短命令,每次启动额度剩得最多的账号。还没有任何额度数据时,启动主账号,并告诉你原因。',
1511
+ 'pk.none': '先给某个工具再加一个账号:只有一个账号时没得挑。',
1512
+ 'pk.noneYet': '未设置',
1513
+ 'pk.exists': '启动额度最多的 {host} 账号。',
1514
+ 'pk.start': '启动最空的账号',
1515
+ 'pk.startTip': '在终端输入 {name}:启动额度剩得最多的 {host} 账号',
1516
+ 'pk.remove': '删除',
1517
+ 'pk.removed': '已删除 {name}。',
1518
+ 'pk.nameLabel': '{host} 的短命令',
1519
+ 'pk.hint': '在终端输入它,就会启动额度最多的 {host} 账号。',
1520
+ 'pk.shadows': '这台电脑上已经有 {name} 命令({path})。加上后,在终端输入 {name} 会启动 {host},不再运行原来的命令。',
1521
+ 'pk.add': '添加',
1522
+ 'pk.addAnyway': '仍然添加',
1523
+ 'pk.added': '已添加 {name},新开一个终端窗口就能用。',
1524
+ 'pk.newShell': '新加的短命令要在新开的终端窗口里才能用。',
1525
+ 'pk.offerShort': '添加 {name}',
1526
+ 'pk.offerMore': ':自动选最空的账号',
1527
+ 'pk.rename': '改名',
1528
+ 'pk.addedSetup': '已添加 {name}。还差一步:让新终端能用它(见上方)。',
1529
+ 'pk.renamedSetup': '已把 {old} 改名为 {name}。还差一步:让新终端能用它(见上方)。',
1530
+ 'ss.title': '新开的终端还用不了你的短命令。',
1531
+ 'ss.body': 'sideby 可以把下面这一行加到 {rc} 末尾:',
1532
+ 'ss.add': '加上这一行',
1533
+ 'ss.adding': '正在添加…',
1534
+ 'ss.added': '已加到 {rc},新开一个终端窗口就能用短命令。',
1535
+ 'ss.undo': '撤销',
1536
+ 'ss.removed': '已从 {rc} 删掉 sideby 加的那一行。',
1537
+ 'pk.save': '保存',
1538
+ 'pk.renamed': '已把 {old} 改名为 {name},新开一个终端窗口就能用。',
1539
+ 'pk.fileFailed': '配置已保存,但 shell-init 文件没能重写:{msg}',
1540
+ 'pk.why.othersFull': '它还没有额度数据,有数据的账号都满了',
1541
+ 'pk.offerNoName': '添加短命令:自动选最空的账号',
1542
+ 'pk.namePh': '例如 cc',
1543
+ 'pk.started': '已在 {terminal} 打开 {ref}({why})。',
1544
+ 'pk.why.room': '已用 {n}%,余量最多',
1545
+ 'pk.why.noData': '还没有额度数据',
1468
1546
  'login.opened': '已打开 {terminal},请在那里登录 {ref}。',
1469
1547
  'login.failed': '终端没打开,命令已复制:粘贴到你的终端,按回车。',
1470
1548
  'login.automation': '命令已复制。要让 sideby 打开 {terminal},请在「系统设置 → 隐私与安全性 → 自动化」里打开它。',
@@ -907,6 +907,9 @@ const MAIN = String.raw `
907
907
  for (const el of document.querySelectorAll('[data-i18n]')) el.textContent = t(el.getAttribute('data-i18n'))
908
908
  $('refresh').setAttribute('aria-label', t('top.refresh'))
909
909
  $('ask-ai').setAttribute('aria-label', t('ask.button'))
910
+ const repo = $('repo')
911
+ for (const k of ['aria-label', 'title']) repo.setAttribute(k, t('top.repo'))
912
+ if (/^https:\/\/github\.com\//.test(BOOT.repoUrl || '')) { repo.href = BOOT.repoUrl; repo.hidden = false }
910
913
  renderSettingsButton()
911
914
  }
912
915
  function applyTheme() {
@@ -1832,7 +1835,8 @@ const MAIN = String.raw `
1832
1835
  h('span', { class: 'muted small' }, t('quota.turnOnFamilyNote', { host: info.title })),
1833
1836
  h('button', { class: 'btn btn-sm', type: 'button', title: setup.summary, 'aria-label': t('quota.turnOnFamilyLabel', { host: info.title }), onclick: () => openSetup(fam) }, t('quota.turnOnFamily')))
1834
1837
  : null,
1835
- off && setup && setup.plan.status === 'blocked' ? h('span', { class: 'muted small label-tip' }, t('quota.blocked'), tipRaw(t('quota.blocked'), setup.plan.message)) : null))
1838
+ off && setup && setup.plan.status === 'blocked' ? h('span', { class: 'muted small label-tip' }, t('quota.blocked'), tipRaw(t('quota.blocked'), setup.plan.message)) : null,
1839
+ ui.arrange ? null : pickHead(fam)))
1836
1840
  const body = collapsedNow ? null : cards
1837
1841
  ? h('div', { class: 'grid', id: bodyId, 'data-key': 'cards', 'data-patch': '' }, list.map((a) => card(a, now, cols)))
1838
1842
  : h('div', { class: 'rows', id: bodyId, role: 'list', 'data-key': ui.arrange ? 'rows-arrange' : 'rows', 'data-patch': '' }, loginClusters(list).map((x) => Array.isArray(x) ? loginRow(x, now, cols) : row(x, now, cols)))
@@ -2867,6 +2871,7 @@ const MAIN = String.raw `
2867
2871
  r.hookErrors.map((e) => h('span', { class: 'small' }, 'plugin ' + e.plugin + ': ' + e.message))) : null,
2868
2872
  r.account.dir ? h('p', { class: 'small' }, h('span', { class: 'muted' }, t('nf.dir') + ' '), h('code', null, r.account.dir)) : null,
2869
2873
  r.alias && r.alias.added ? h('div', { class: 'small created-alias' }, h('span', { class: 'muted' }, t('nf.alias') + ' '), codeCopy(r.alias.name), h('span', { class: 'muted' }, ' ' + t('nf.aliasNewShell'))) : null,
2874
+ r.alias && r.alias.added ? shellSetupNote() : null,
2870
2875
  r.alias && !r.alias.added ? h('div', { class: 'note note-warn' }, h('b', null, t('nf.aliasNotAdded')), ' ', h('span', { class: 'small' }, r.alias.message || '')) : null,
2871
2876
  (r.shellInitFiles || []).map((f) => f.ok
2872
2877
  ? h('p', { class: 'muted small' }, t(f.action === 'unchanged' ? 'nf.shellFileSame' : 'nf.shellFileUpdated', { file: f.path }))
@@ -3595,6 +3600,10 @@ const MAIN = String.raw `
3595
3600
  h('button', { class: 'seg-btn', type: 'button', 'aria-pressed': String(v === c.on), onclick: () => { if (v !== c.on) { leave(false); setCheck(c.family, v) } } }, text)))))
3596
3601
  }
3597
3602
  }
3603
+ if (pickFamilies().length) {
3604
+ const names = Object.keys(S.state.pickCommands || {})
3605
+ acct.push(link(t('pk.title'), names.length ? names.join(', ') : t('pk.noneYet'), names.length ? 'chip-ok' : '', () => openPick(null), true))
3606
+ }
3598
3607
  if (secs.includes('rc')) {
3599
3608
  const sum = rcSummary()
3600
3609
  acct.push(link(t('rc.button'), t('rc.state.' + sum), sum === 'on' ? 'chip-warn' : sum === 'off' ? 'chip-ok' : '', openRc, true))
@@ -3791,6 +3800,7 @@ const MAIN = String.raw `
3791
3800
  else if (dlg.kind === 'key' && ky && ky.step !== 'enter') renderKey()
3792
3801
  else if (dlg.kind === 'terminal' && tm) renderTerminals()
3793
3802
  else if (dlg.kind === 'autostart') renderAutostart()
3803
+ else if (dlg.kind === 'pick' && pk) renderPick()
3794
3804
  }
3795
3805
  function setTheme(v) {
3796
3806
  if (CFG) { cfgPanel.theme = v; saveCfg({ theme: v }) } else { prefs.theme = v; savePrefs() }
@@ -3803,7 +3813,7 @@ const MAIN = String.raw `
3803
3813
  return Boolean(u && u.skillUpdate && u.skillUpdate.installed && u.skillUpdate.installed.length)
3804
3814
  }
3805
3815
  // Example phrases: a click puts one in the Let AI do it box (spec §3.28).
3806
- const AI_ASKS = ['ai.ask.quota', 'ai.ask.new', 'ai.ask.api', 'ai.ask.pin', 'ai.ask.fix', 'ai.ask.handoff', 'ai.ask.menubar', 'ai.ask.rc', 'ai.ask.tool']
3816
+ const AI_ASKS = ['ai.ask.quota', 'ai.ask.pick', 'ai.ask.new', 'ai.ask.api', 'ai.ask.pin', 'ai.ask.fix', 'ai.ask.handoff', 'ai.ask.menubar', 'ai.ask.rc', 'ai.ask.tool']
3807
3817
  function openRc() {
3808
3818
  if (!S.state || !rcSummary()) return
3809
3819
  rc.target = null
@@ -3843,7 +3853,7 @@ const MAIN = String.raw `
3843
3853
  // One dialog for every "let AI do it" entry: what to do, then the account and the terminal it will use, then one
3844
3854
  // button. When nothing can run it, or the panel is read-only, it copies the prompt instead.
3845
3855
  let ak = null
3846
- const TERM_NAMES = { terminal: 'Terminal', iterm2: 'iTerm2', ghostty: 'Ghostty', orca: 'Orca', wezterm: 'WezTerm', kitty: 'kitty', alacritty: 'Alacritty', custom: 'Custom' }
3856
+ const TERM_NAMES = { terminal: 'Terminal', iterm2: 'iTerm2', ghostty: 'Ghostty', orca: 'Orca', wezterm: 'WezTerm', kitty: 'kitty', alacritty: 'Alacritty', 'windows-terminal': 'Windows Terminal', custom: 'Custom' }
3847
3857
  function termName(id) {
3848
3858
  const list = ak && ak.terms ? ak.terms.terminals : []
3849
3859
  const f = list.find((x) => x.id === id)
@@ -4364,6 +4374,175 @@ const MAIN = String.raw `
4364
4374
  setKids(dlg.el, dialogFrame(t('term.title'), null, body, [h('button', { class: 'btn', type: 'button', onclick: () => dlg.el.close() }, t('btn.close'))]))
4365
4375
  }
4366
4376
 
4377
+ // ---------- pick commands (spec §3.13, ADR-0035) ----------
4378
+ // A short command per tool that starts, each time, the account with the most quota left. The dialog lists every
4379
+ // tool that has one or could have one; adding shows what the name would hide in the shell before it writes.
4380
+ let pk = null
4381
+ function pickOf(fam) { const e = Object.entries(S.state.pickCommands || {}).find(([, f]) => f === fam); return e ? e[0] : null }
4382
+ function pickFamilies() { return S.state.families.map((f) => f.id).filter((id) => pickOf(id) || (S.state.pickOffers || {})[id]) }
4383
+ function openPick(fam) {
4384
+ closeMenu()
4385
+ pk = { focus: fam || null, busy: false, drafts: {}, confirm: {}, renaming: {}, error: null }
4386
+ showDialog('pick')
4387
+ renderPick()
4388
+ const input = fam && document.getElementById('pk-name-' + fam)
4389
+ if (input) input.focus()
4390
+ }
4391
+ async function startPick(name) {
4392
+ if (BOOT.readOnly) { copyText(name, name); return }
4393
+ try {
4394
+ const r = await api('/api/pick/start', { name })
4395
+ const why = r.reason === 'most-room' ? t('pk.why.room', { n: String(r.pressure) }) : t(r.reason === 'others-full' ? 'pk.why.othersFull' : 'pk.why.noData')
4396
+ if (r.opened) { toast(t('pk.started', { terminal: TERM_NAMES[r.terminal] || r.terminal, ref: r.picked, why })); return }
4397
+ await copyText(name, name)
4398
+ toast(r.automation ? t('login.automation', { terminal: TERM_NAMES[r.terminal] || r.terminal }) : t('login.failed'), { kind: 'info' })
4399
+ } catch (e) { toast(e.message, { kind: 'fail' }) }
4400
+ }
4401
+ // The dialog is the preview: a name that hides nothing is added at once; one that hides a command on PATH shows
4402
+ // that first and needs a second click. A rename adds the new name, then removes the old one.
4403
+ async function pickAdd(fam, name, shown, replaces) {
4404
+ pk.busy = true
4405
+ pk.error = null
4406
+ renderPick()
4407
+ try {
4408
+ let r = await api('/api/pick/add', { name, family: fam, confirm: Boolean(shown) })
4409
+ if (r.status === 'confirm' && !r.shadows) r = await api('/api/pick/add', { name, family: fam, confirm: true })
4410
+ if (r.status === 'confirm') pk.confirm[fam] = { name, shadows: r.shadows }
4411
+ else {
4412
+ const old = replaces && replaces !== name ? await api('/api/pick/remove', { name: replaces }) : null
4413
+ delete pk.renaming[fam]
4414
+ delete pk.drafts[fam]
4415
+ const later = S.state.shellSetup && !S.state.shellSetup.loaded
4416
+ pickToast([r, old], t((old ? 'pk.renamed' : 'pk.added') + (later ? 'Setup' : ''), { name, old: replaces }))
4417
+ await load({ silent: true })
4418
+ }
4419
+ } catch (e) { pk.error = e }
4420
+ if (!pk) return
4421
+ pk.busy = false
4422
+ if (dlg.kind === 'pick') renderPick()
4423
+ }
4424
+ async function pickRemove(name) {
4425
+ pk.busy = true
4426
+ pk.error = null
4427
+ renderPick()
4428
+ try {
4429
+ pickToast([await api('/api/pick/remove', { name })], t('pk.removed', { name }))
4430
+ await load({ silent: true })
4431
+ } catch (e) { pk.error = e }
4432
+ if (!pk) return
4433
+ pk.busy = false
4434
+ if (dlg.kind === 'pick') renderPick()
4435
+ }
4436
+ // The config is written first; a shell-init file sideby could not rewrite is said, not hidden behind "added".
4437
+ function pickToast(results, done) {
4438
+ const failed = results.filter(Boolean).flatMap((r) => (r.shellInitFiles || []).filter((f) => !f.ok).map((f) => f.message))
4439
+ if (failed.length) toast(t('pk.fileFailed', { msg: failed.join('; ') }), { kind: 'fail', duration: 12000 })
4440
+ else toast(done)
4441
+ }
4442
+ // A name field with what it would hide and its button; typing updates them in place, so the caret stays put.
4443
+ function nameEditor(fam, info, initial, replaces) {
4444
+ const id = 'pk-name-' + fam
4445
+ const input = h('input', { id, type: 'text', class: 'mono', autocomplete: 'off', autocapitalize: 'none', spellcheck: 'false', maxlength: '64', placeholder: t('pk.namePh'), disabled: pk.busy, 'aria-describedby': id + '-hint' })
4446
+ input.value = pk.drafts[fam] !== undefined ? pk.drafts[fam] : initial || ''
4447
+ const offer = (S.state.pickOffers || {})[fam]
4448
+ const note = h('p', { class: 'note' })
4449
+ const go = h('button', { class: 'btn btn-sm btn-primary', type: 'button' })
4450
+ const shadowsOf = (n) => {
4451
+ const asked = pk.confirm[fam]
4452
+ return asked && asked.name === n ? asked.shadows : offer && n && n === offer.name ? offer.shadows : null
4453
+ }
4454
+ const sync = () => {
4455
+ const n = input.value.trim()
4456
+ const shadows = shadowsOf(n)
4457
+ note.hidden = !shadows
4458
+ note.textContent = shadows ? t('pk.shadows', { name: n, path: shadows, host: info.title }) : ''
4459
+ go.textContent = t(shadows ? 'pk.addAnyway' : replaces ? 'pk.save' : 'pk.add')
4460
+ go.disabled = pk.busy || !n || n === replaces
4461
+ }
4462
+ const add = () => { const n = input.value.trim(); if (n && n !== replaces) pickAdd(fam, n, shadowsOf(n), replaces) }
4463
+ input.addEventListener('input', () => { pk.drafts[fam] = input.value; sync() })
4464
+ input.addEventListener('keydown', (e) => { if (e.key === 'Enter') { e.preventDefault(); add() } })
4465
+ go.addEventListener('click', add)
4466
+ sync()
4467
+ return [
4468
+ h('label', { class: 'field', for: id }, h('span', null, t('pk.nameLabel', { host: info.title })), input),
4469
+ h('p', { class: 'field-hint', id: id + '-hint' }, t('pk.hint', { host: info.title })),
4470
+ note,
4471
+ h('div', { class: 'actions' }, go,
4472
+ replaces ? h('button', { class: 'btn btn-sm btn-ghost', type: 'button', disabled: pk.busy, onclick: () => { delete pk.renaming[fam]; delete pk.drafts[fam]; renderPick() } }, t('btn.cancel')) : null),
4473
+ ]
4474
+ }
4475
+ function renderPick() {
4476
+ if (!pk) return
4477
+ const body = [h('p', { class: 'muted small' }, t('pk.intro'))]
4478
+ const fams = pickFamilies()
4479
+ // Once a pick command exists, the line that makes terminals load it is the next step: first, not below the fold.
4480
+ const setupFirst = Object.keys(S.state.pickCommands || {}).length ? shellSetupNote() : null
4481
+ if (setupFirst) body.push(setupFirst)
4482
+ if (!fams.length) body.push(h('p', { class: 'note' }, t('pk.none')))
4483
+ for (const fam of fams) {
4484
+ const info = family(fam)
4485
+ const name = pickOf(fam)
4486
+ const head = h('div', { class: 'title-logo' }, badge(fam, 'sm'), h('b', null, info.title))
4487
+ if (name && pk.renaming[fam] && !BOOT.readOnly) {
4488
+ body.push(h('div', { class: 'pk-row' }, head, nameEditor(fam, info, name, name)))
4489
+ continue
4490
+ }
4491
+ if (name) {
4492
+ body.push(h('div', { class: 'pk-row' }, head,
4493
+ h('p', { class: 'small' }, h('code', { class: 'mono' }, name), ' ', t('pk.exists', { host: info.title })),
4494
+ h('div', { class: 'actions' },
4495
+ h('button', { class: 'btn btn-sm', type: 'button', disabled: pk.busy, onclick: () => startPick(name) }, icon('terminal'), t('pk.start')),
4496
+ BOOT.readOnly ? null : h('button', { class: 'btn btn-sm btn-ghost', type: 'button', disabled: pk.busy, onclick: () => { pk.renaming[fam] = true; renderPick(); const el = document.getElementById('pk-name-' + fam); if (el) el.focus() } }, t('pk.rename')),
4497
+ BOOT.readOnly ? null : h('button', { class: 'btn btn-sm btn-ghost', type: 'button', disabled: pk.busy, onclick: () => pickRemove(name) }, t('pk.remove')))))
4498
+ continue
4499
+ }
4500
+ if (BOOT.readOnly) continue
4501
+ body.push(h('div', { class: 'pk-row' }, head, nameEditor(fam, info, S.state.pickOffers[fam].name, null)))
4502
+ }
4503
+ if (fams.length && !setupFirst) body.push(shellSetupNote() || h('p', { class: 'muted small' }, t('pk.newShell')))
4504
+ if (pk.error) body.push(errorNote(pk.error, null))
4505
+ setKids(dlg.el, dialogFrame(t('pk.title'), null, body, [h('button', { class: 'btn', type: 'button', onclick: () => dlg.el.close() }, t('btn.close'))]))
4506
+ }
4507
+ // New terminals load short commands only through one line in the shell's rc file (ADR-0036). Where a short command
4508
+ // is added and that line is missing, say so and offer to add it: the line and the file shown are the preview.
4509
+ let ssBusy = false
4510
+ async function shellSetup(undo) {
4511
+ if (ssBusy) return
4512
+ ssBusy = true
4513
+ renderShellSetupHosts()
4514
+ try {
4515
+ const r = await api('/api/shell-init/setup', undo ? { undo: true } : {})
4516
+ if (r.status === 'added') toast(t('ss.added', { rc: r.rc }), { action: { label: t('ss.undo'), run: () => shellSetup(true) } })
4517
+ else if (r.status === 'removed') toast(t('ss.removed', { rc: r.rc }))
4518
+ await load({ silent: true })
4519
+ } catch (e) { toast(e.message, { kind: 'fail' }) }
4520
+ ssBusy = false
4521
+ renderShellSetupHosts()
4522
+ }
4523
+ function renderShellSetupHosts() {
4524
+ if (dlg.kind === 'pick' && pk) renderPick()
4525
+ else if (dlg.kind === 'create' && nf && nf.result) renderCreate()
4526
+ }
4527
+ function shellSetupNote() {
4528
+ const ss = S.state.shellSetup
4529
+ if (!ss || ss.loaded || BOOT.readOnly) return null
4530
+ const line = ss.block.split('\n').find((l) => l.startsWith('eval '))
4531
+ return h('div', { class: 'note note-warn ss-note', role: 'status' },
4532
+ h('div', { class: 'note-line' }, h('b', null, t('ss.title')), ' ', t('ss.body', { rc: ss.rc })),
4533
+ h('code', { class: 'mono note-line' }, line),
4534
+ h('button', { class: 'btn btn-sm btn-primary', type: 'button', disabled: ssBusy, onclick: () => shellSetup(false) }, ssBusy ? t('ss.adding') : t('ss.add')))
4535
+ }
4536
+ // In a tool's group head: the button that starts the account with the most room, or the offer to add one.
4537
+ function pickHead(fam) {
4538
+ const name = pickOf(fam)
4539
+ // On a narrow screen only the icon and the name stay; the words are in the hover text and the label.
4540
+ if (name) return h('button', { class: 'btn btn-sm', type: 'button', title: t('pk.startTip', { name, host: family(fam).title }), 'aria-label': t('pk.startTip', { name, host: family(fam).title }), onclick: () => startPick(name) }, icon('terminal'), h('span', { class: 'hide-sm' }, t('pk.start') + ' '), h('code', { class: 'mono' }, name))
4541
+ const offer = (S.state.pickOffers || {})[fam]
4542
+ if (!offer || BOOT.readOnly) return null
4543
+ return h('button', { class: 'link-btn small', type: 'button', onclick: () => openPick(fam) }, offer.name ? [t('pk.offerShort', { name: offer.name }), h('span', { class: 'hide-sm' }, t('pk.offerMore'))] : t('pk.offerNoName'))
4544
+ }
4545
+
4367
4546
  // ---------- banners ----------
4368
4547
  // Offered once on macOS (spec §3.31), when quota shows and the menu bar item is off; "No thanks" is for good.
4369
4548
  function menubarHint() {
@@ -139,6 +139,8 @@ code, .mono { font-family: var(--mono); font-size: 0.92em; }
139
139
  .pages { margin: 0 0 14px; }
140
140
  .row-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
141
141
  .tune-confirm { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--border); padding-top: 10px; }
142
+ .pk-row { display: flex; flex-direction: column; gap: 6px; padding: 12px 0; border-top: 1px solid var(--border); }
143
+ .pk-row p { margin: 0; }
142
144
  .tune-confirm ul { margin: 0; padding-left: 18px; }
143
145
  .tune-undo { margin: 0; }
144
146
  .tune-details { margin-top: 4px; }
@@ -446,6 +448,7 @@ a.btn:hover { text-decoration: none; }
446
448
  .icon-btn:disabled { color: var(--faint); cursor: not-allowed; }
447
449
  .top-actions .icon-btn { width: var(--ctl-h); height: var(--ctl-h); border-color: var(--border-strong); background: var(--surface); }
448
450
  .top-actions .icon-btn:hover { background: var(--hover); }
451
+ .repo-link svg { width: 17px; height: 17px; fill: currentColor; }
449
452
  .btn:focus-visible, .icon-btn:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible, .stat-btn:focus-visible { outline: var(--focus-outline); outline-offset: 2px; box-shadow: var(--focus-ring); }
450
453
  .btn:focus-visible { border-color: var(--focus); }
451
454
  .note a, .banner a { color: inherit; text-decoration: underline; text-underline-offset: 2px; font-weight: var(--strong-weight); }
@@ -5,12 +5,14 @@ import { createHash } from 'node:crypto';
5
5
  import { FAVICON_SVG, MARK_SVG } from '../core/brand-mark.js';
6
6
  import { ALIAS_NAME, RESERVED_ALIASES } from '../core/config.js';
7
7
  import { QUOTA_FAIL_PERCENT, QUOTA_WARN_PERCENT, USAGE_DAYS } from '../core/quota-levels.js';
8
- import { SKILL_INSTALL } from '../core/skill-check.js';
8
+ import { REPO_URL, SKILL_INSTALL } from '../core/skill-check.js';
9
9
  import { MESSAGES } from './i18n.js';
10
10
  import { widthTier } from './page-logic.js';
11
11
  import { PAGE_SCRIPT } from './page-script.js';
12
12
  import { pageStyles } from './page-styles.js';
13
13
  import { resolveTheme } from './theme.js';
14
+ /** GitHub's mark, from Simple Icons (CC0 1.0, https://simpleicons.org); a trademark of GitHub that only names the site. */
15
+ const GITHUB_MARK = 'M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12';
14
16
  /** Browsers keep a favicon past `no-cache`; a link that changes with the mark makes them fetch the new one. */
15
17
  export const FAVICON_VERSION = createHash('sha256').update(FAVICON_SVG).digest('hex').slice(0, 10);
16
18
  export { pageStyles };
@@ -55,6 +57,8 @@ export function renderPage(opts) {
55
57
  reservedAliases: [...RESERVED_ALIASES],
56
58
  // The command that installs the sideby Agent Skill, which the Panel offers so an AI assistant can do the same.
57
59
  skillInstall: SKILL_INSTALL,
60
+ // sideby's repository for the header link, set by the script: the page itself names no outside address.
61
+ repoUrl: REPO_URL,
58
62
  });
59
63
  return `<!doctype html>
60
64
  <html lang="${lang === 'zh' ? 'zh-CN' : 'en'}">
@@ -81,6 +85,7 @@ export function renderPage(opts) {
81
85
  <div class="top-actions">
82
86
  <button id="update" class="btn update-btn" type="button" hidden></button>
83
87
  <button id="ask-ai" class="btn" type="button" aria-haspopup="dialog" aria-label="Let AI do it"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6 9h12a2 2 0 0 1 2 2v6a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-6a2 2 0 0 1 2-2zM12 5v4M9.5 13.5v1M14.5 13.5v1"/></svg><span class="hide-sm" data-i18n="ask.button">Let AI do it</span></button>
88
+ <a id="repo" class="icon-btn repo-link" target="_blank" rel="noopener noreferrer" aria-label="sideby on GitHub" title="sideby on GitHub" hidden><svg viewBox="0 0 24 24" aria-hidden="true"><path d="${GITHUB_MARK}"/></svg></a>
84
89
  <button id="settings" class="btn" type="button" aria-haspopup="dialog" aria-expanded="false"${lang === 'auto' ? '' : ' hidden'}><span data-i18n="set.button">Settings</span></button>
85
90
  <button id="refresh" class="btn" type="button" aria-label="Refresh"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M20 11a8 8 0 1 0-2.3 5.7"/><path d="M20 4v7h-7"/></svg><span class="hide-sm" data-i18n="top.refresh">Refresh</span></button>
86
91
  </div>