sideby 0.19.0 → 0.19.1

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 CHANGED
@@ -1 +1 @@
1
- {"id":"20261019T134334-23c436"}
1
+ {"id":"20261019T145027-572ca5"}
@@ -5,6 +5,11 @@ export function fileSignature(st) {
5
5
  export const persistedMemos = new Map();
6
6
  export class FileMemo {
7
7
  #scopes = new Map();
8
+ /**
9
+ * Parses running now, by scope and path: a second reader of the same file version (two passes at once, such as an
10
+ * Account's own identity and the Same Login check) waits for that parse instead of starting another.
11
+ */
12
+ #running = new Map();
8
13
  /** Counters for tests and timing. */
9
14
  stats = { hits: 0, misses: 0 };
10
15
  /** True when a pass changed what is remembered since the last `dump`. */
@@ -29,11 +34,28 @@ export class FileMemo {
29
34
  seen.set(path, hit);
30
35
  return hit.value;
31
36
  }
37
+ const key = `${scope}\0${path}`;
38
+ const running = this.#running.get(key);
39
+ if (running && running.sig === sig) {
40
+ this.stats.hits++;
41
+ const value = await running.value;
42
+ if (!keep || keep(value))
43
+ seen.set(path, { sig, value });
44
+ return value;
45
+ }
32
46
  this.stats.misses++;
33
- const value = await parse();
34
- if (!keep || keep(value))
35
- seen.set(path, { sig, value });
36
- return value;
47
+ const started = parse();
48
+ this.#running.set(key, { sig, value: started });
49
+ try {
50
+ const value = await started;
51
+ if (!keep || keep(value))
52
+ seen.set(path, { sig, value });
53
+ return value;
54
+ }
55
+ finally {
56
+ if (this.#running.get(key)?.value === started)
57
+ this.#running.delete(key);
58
+ }
37
59
  },
38
60
  done: () => {
39
61
  if (!before || before.size !== seen.size || [...seen].some(([k, v]) => before.get(k) !== v))
@@ -512,42 +512,42 @@ const en = {
512
512
  'ask.otherTool': 'Other tool…',
513
513
  'ask.otherToolSub': 'Not in this list',
514
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.',
515
+ 'pk.title': 'Start the account with the most quota left',
516
+ 'pk.intro': 'Set one short command per tool. Typing it starts the account with the most quota left. If no account has quota data yet, it starts your main account and tells you.',
517
+ 'pk.none': 'Add a second account for a tool first. With only one account, there is nothing to choose between.',
518
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',
519
+ 'pk.exists': 'starts the {host} account with the most quota left.',
520
+ 'pk.start': 'Start account with most quota:',
521
+ 'pk.startTip': 'Type {name} in a terminal to start the {host} account with the most quota left',
522
522
  'pk.remove': 'Remove',
523
523
  'pk.removed': 'Removed {name}.',
524
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.',
525
+ 'pk.hint': 'Type this in a terminal to start the {host} account with the most quota left.',
526
+ 'pk.shadows': '{name} is already a command on this computer ({path}). If you add it, typing {name} in your terminal will start {host} instead.',
527
527
  'pk.add': 'Add',
528
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.',
529
+ 'pk.added': 'Added {name}. Open a new terminal window to use it.',
530
+ 'pk.newShell': 'Changes take effect in new terminal windows.',
531
531
  'pk.offerShort': 'Add {name}',
532
- 'pk.offerMore': ': start the one with most room',
532
+ 'pk.offerMore': ': start the account with the most quota left',
533
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.',
534
+ 'pk.addedSetup': 'Added {name}. Turn on terminal setup above so new terminals can use it.',
535
+ 'pk.renamedSetup': 'Renamed {old} to {name}. Turn on terminal setup above so new terminals can use it.',
536
+ 'ss.title': 'New terminals can’t use your short commands yet.',
537
537
  'ss.body': 'sideby can add this line to the end of {rc}:',
538
- 'ss.add': 'Add the line',
538
+ 'ss.add': 'Add to {rc}',
539
539
  'ss.adding': 'Adding…',
540
- 'ss.added': 'Added to {rc}. Short commands work in a new terminal window.',
540
+ 'ss.added': 'Added to {rc}. Open a new terminal window to use your short commands.',
541
541
  'ss.undo': 'Undo',
542
- 'ss.removed': 'Took sideby’s line out of {rc}.',
542
+ 'ss.removed': 'Removed sideby’s line from {rc}.',
543
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',
544
+ 'pk.renamed': 'Renamed {old} to {name}. Open a new terminal window to use it.',
545
+ 'pk.fileFailed': 'Saved your setting, but couldn’t update the terminal command file: {msg}',
546
+ 'pk.why.othersFull': 'no quota data yet, and the other accounts are full',
547
+ 'pk.offerNoName': 'Add short command: start the account with the most quota left',
548
+ 'pk.namePh': 'e.g. cc',
549
+ 'pk.started': 'Opened {ref} in {terminal} ({why}).',
550
+ 'pk.why.room': '{n}% used, most quota left',
551
551
  'pk.why.noData': 'no quota data yet',
552
552
  'login.opened': 'Opened {terminal}: sign in to {ref} there.',
553
553
  'login.failed': 'Could not open a terminal. Copied: paste it into your terminal and press Return.',
@@ -1408,7 +1408,7 @@ const zh = {
1408
1408
  'ai.examples': '可以这样说(点一下复制):',
1409
1409
  'ai.copy': '复制',
1410
1410
  'ai.ask.quota': '我哪个 Claude 账号剩余额度最多?',
1411
- 'ai.ask.pick': '加个 cc:每次自动启动额度最多的 Claude 账号。',
1411
+ 'ai.ask.pick': '加个 cc:每次自动启动剩余额度最多的 Claude 账号。',
1412
1412
  'ai.ask.new': '再加一个 Claude 账号,短命令叫 cc009。',
1413
1413
  'ai.ask.pin': '把 claude:work 置顶。',
1414
1414
  'ai.ask.fix': '检查一下我的账号,把该共享的修好。',
@@ -1506,42 +1506,42 @@ const zh = {
1506
1506
  'ask.otherTool': '其他工具……',
1507
1507
  'ask.otherToolSub': '列表里没有',
1508
1508
  'ask.plugin': '让 AI 写插件',
1509
- 'pk.title': '自动选最空的账号',
1510
- 'pk.intro': '每个工具一个短命令,每次启动额度剩得最多的账号。还没有任何额度数据时,启动主账号,并告诉你原因。',
1511
- 'pk.none': '先给某个工具再加一个账号:只有一个账号时没得挑。',
1509
+ 'pk.title': '自动启动剩余额度最多的账号',
1510
+ 'pk.intro': '给每个工具设一个短命令,每次自动启动剩余额度最多的账号。如果暂时没有额度数据,就启动主账号并提醒你。',
1511
+ 'pk.none': '请先给任意工具再加一个账号。只有一个账号时不用挑。',
1512
1512
  'pk.noneYet': '未设置',
1513
- 'pk.exists': '启动额度最多的 {host} 账号。',
1514
- 'pk.start': '启动最空的账号',
1515
- 'pk.startTip': '在终端输入 {name}:启动额度剩得最多的 {host} 账号',
1513
+ 'pk.exists': '启动剩余额度最多的 {host} 账号。',
1514
+ 'pk.start': '启动剩余额度最多的账号:',
1515
+ 'pk.startTip': '在终端输入 {name},启动剩余额度最多的 {host} 账号',
1516
1516
  'pk.remove': '删除',
1517
1517
  'pk.removed': '已删除 {name}。',
1518
1518
  'pk.nameLabel': '{host} 的短命令',
1519
- 'pk.hint': '在终端输入它,就会启动额度最多的 {host} 账号。',
1520
- 'pk.shadows': '这台电脑上已经有 {name} 命令({path})。加上后,在终端输入 {name} 会启动 {host},不再运行原来的命令。',
1519
+ 'pk.hint': '在终端输入这个命令,就会启动剩余额度最多的 {host} 账号。',
1520
+ 'pk.shadows': '电脑上已经有 {name} 命令({path})。添加后,在终端输入 {name} 会改为启动 {host}。',
1521
1521
  'pk.add': '添加',
1522
1522
  'pk.addAnyway': '仍然添加',
1523
1523
  'pk.added': '已添加 {name},新开一个终端窗口就能用。',
1524
- 'pk.newShell': '新加的短命令要在新开的终端窗口里才能用。',
1524
+ 'pk.newShell': '新设的短命令在新开的终端窗口里生效。',
1525
1525
  'pk.offerShort': '添加 {name}',
1526
- 'pk.offerMore': ':自动选最空的账号',
1526
+ 'pk.offerMore': ':自动启动剩余额度最多的账号',
1527
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},新开一个终端窗口就能用短命令。',
1528
+ 'pk.addedSetup': '已添加 {name}。点击上方按钮写入终端配置,新开的终端就能直接用。',
1529
+ 'pk.renamedSetup': '已将 {old} 改名为 {name}。点击上方按钮写入终端配置,新开的终端就能直接用。',
1530
+ 'ss.title': '新开的终端还用不了短命令。',
1531
+ 'ss.body': 'sideby 可以把下面这行加到 {rc} 末尾:',
1532
+ 'ss.add': '写入 {rc}',
1533
+ 'ss.adding': '正在写入…',
1534
+ 'ss.added': '已写入 {rc},新开一个终端窗口就能用短命令。',
1535
1535
  'ss.undo': '撤销',
1536
- 'ss.removed': '已从 {rc} 删掉 sideby 加的那一行。',
1536
+ 'ss.removed': '已从 {rc} 移除了那行配置。',
1537
1537
  'pk.save': '保存',
1538
- 'pk.renamed': '已把 {old} 改名为 {name},新开一个终端窗口就能用。',
1539
- 'pk.fileFailed': '配置已保存,但 shell-init 文件没能重写:{msg}',
1540
- 'pk.why.othersFull': '它还没有额度数据,有数据的账号都满了',
1541
- 'pk.offerNoName': '添加短命令:自动选最空的账号',
1538
+ 'pk.renamed': '已把 {old} 改为 {name},新开一个终端窗口就能用。',
1539
+ 'pk.fileFailed': '设置已保存,但没能更新终端命令文件:{msg}',
1540
+ 'pk.why.othersFull': '它还没有额度数据,其他有数据的账号都用完了',
1541
+ 'pk.offerNoName': '添加短命令:自动启动剩余额度最多的账号',
1542
1542
  'pk.namePh': '例如 cc',
1543
- 'pk.started': '已在 {terminal} 打开 {ref}({why})。',
1544
- 'pk.why.room': '已用 {n}%,余量最多',
1543
+ 'pk.started': '已在 {terminal} 启动 {ref}({why})。',
1544
+ 'pk.why.room': '已用 {n}%,剩余额度最多',
1545
1545
  'pk.why.noData': '还没有额度数据',
1546
1546
  'login.opened': '已打开 {terminal},请在那里登录 {ref}。',
1547
1547
  'login.failed': '终端没打开,命令已复制:粘贴到你的终端,按回车。',
@@ -4492,7 +4492,7 @@ const MAIN = String.raw `
4492
4492
  body.push(h('div', { class: 'pk-row' }, head,
4493
4493
  h('p', { class: 'small' }, h('code', { class: 'mono' }, name), ' ', t('pk.exists', { host: info.title })),
4494
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')),
4495
+ h('button', { class: 'btn btn-sm', type: 'button', disabled: pk.busy, onclick: () => startPick(name) }, icon('terminal'), pickStartLabel(), h('code', { class: 'mono' }, name)),
4496
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
4497
  BOOT.readOnly ? null : h('button', { class: 'btn btn-sm btn-ghost', type: 'button', disabled: pk.busy, onclick: () => pickRemove(name) }, t('pk.remove')))))
4498
4498
  continue
@@ -4531,13 +4531,15 @@ const MAIN = String.raw `
4531
4531
  return h('div', { class: 'note note-warn ss-note', role: 'status' },
4532
4532
  h('div', { class: 'note-line' }, h('b', null, t('ss.title')), ' ', t('ss.body', { rc: ss.rc })),
4533
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')))
4534
+ h('button', { class: 'btn btn-sm btn-primary', type: 'button', disabled: ssBusy, onclick: () => shellSetup(false) }, ssBusy ? t('ss.adding') : t('ss.add', { rc: ss.rc })))
4535
4535
  }
4536
+ // The label ends in a colon and the command name follows: a space after an English colon, none after a Chinese one.
4537
+ function pickStartLabel() { const l = t('pk.start'); return /[::]$/.test(l) && lang !== 'zh' ? l + ' ' : l }
4536
4538
  // In a tool's group head: the button that starts the account with the most room, or the offer to add one.
4537
4539
  function pickHead(fam) {
4538
4540
  const name = pickOf(fam)
4539
4541
  // 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))
4542
+ 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' }, pickStartLabel()), h('code', { class: 'mono' }, name))
4541
4543
  const offer = (S.state.pickOffers || {})[fam]
4542
4544
  if (!offer || BOOT.readOnly) return null
4543
4545
  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'))
@@ -2,16 +2,32 @@
2
2
  // a common hand-rolled convention (for example, start a local gateway an API Account needs).
3
3
  // It is local code with the user's permissions, so it gets the same ownership checks as Plugins.
4
4
  import { spawn } from 'node:child_process';
5
- import { access, constants } from 'node:fs/promises';
5
+ import { access, constants, mkdtemp, open, rm } from 'node:fs/promises';
6
+ import { tmpdir } from 'node:os';
6
7
  import { join } from 'node:path';
7
8
  import { lstatOrNull } from '../core/fs-safe.js';
8
9
  import { checkTrusted } from './loader.js';
9
10
  export const SCRIPT_NAME = 'sideby-before-launch';
10
11
  export const SCRIPT_TIMEOUT_MS = 25_000;
11
12
  const TAIL_LINES = 20;
13
+ /** How much of the end of stderr is read back for the error. */
14
+ const STDERR_TAIL_BYTES = 16_384;
12
15
  function tail(text) {
13
16
  return text.trimEnd().split('\n').slice(-TAIL_LINES).join('\n');
14
17
  }
18
+ async function readTail(file) {
19
+ const fh = await open(file, 'r');
20
+ try {
21
+ const { size } = await fh.stat();
22
+ const length = Math.min(size, STDERR_TAIL_BYTES);
23
+ const buf = Buffer.alloc(length);
24
+ await fh.read(buf, 0, length, size - length);
25
+ return buf.toString();
26
+ }
27
+ finally {
28
+ await fh.close();
29
+ }
30
+ }
15
31
  export const accountScript = {
16
32
  name: 'account-script',
17
33
  register(api) {
@@ -31,32 +47,50 @@ export const accountScript = {
31
47
  catch {
32
48
  throw api.abort(`${script} is not executable; run \`chmod u+x "${script}"\``);
33
49
  }
34
- const { code, stderr, timedOut } = await new Promise((resolve) => {
35
- const child = spawn(script, [], {
36
- cwd: ctx.account.dir,
37
- env: ctx.env,
38
- stdio: ['ignore', 'ignore', 'pipe'],
39
- });
40
- let err = '';
41
- child.stderr.on('data', (d) => {
42
- err = (err + d.toString()).slice(-16_384);
43
- });
44
- const timer = setTimeout(() => {
45
- child.kill('SIGKILL');
46
- child.stderr.destroy();
47
- resolve({ code: null, stderr: err, timedOut: true });
48
- }, SCRIPT_TIMEOUT_MS);
49
- child.on('error', (e) => {
50
- clearTimeout(timer);
51
- resolve({ code: 1, stderr: e.message, timedOut: false });
52
- });
53
- child.on('exit', (c) => {
54
- clearTimeout(timer);
55
- // A background process the script started (a gateway, say) inherits stderr; stop reading it.
56
- child.stderr.destroy();
57
- resolve({ code: c, stderr: err, timedOut: false });
58
- });
59
- });
50
+ // stderr goes to a private temp file rather than a pipe: once the script has exited, everything it wrote is
51
+ // in the file, so its last lines are read back without racing the event loop, and a background process the
52
+ // script started (a gateway, say) that inherits stderr cannot hold the launch open.
53
+ // Do not go back to a pipe plus a drain timer: on a loaded runner the timer can fire before the pipe is read and
54
+ // drop the tail. The file is the contract; the saturated-event-loop test guards it.
55
+ const tmp = await mkdtemp(join(tmpdir(), 'sideby-before-launch-'));
56
+ let code;
57
+ let timedOut;
58
+ let stderr = '';
59
+ try {
60
+ const file = join(tmp, 'stderr');
61
+ const out = await open(file, 'w', 0o600);
62
+ try {
63
+ ;
64
+ ({ code, timedOut } = await new Promise((resolve) => {
65
+ const child = spawn(script, [], {
66
+ cwd: ctx.account.dir,
67
+ env: ctx.env,
68
+ stdio: ['ignore', 'ignore', out.fd],
69
+ });
70
+ const timer = setTimeout(() => {
71
+ child.kill('SIGKILL');
72
+ resolve({ code: null, timedOut: true });
73
+ }, SCRIPT_TIMEOUT_MS);
74
+ child.on('error', (e) => {
75
+ clearTimeout(timer);
76
+ stderr = e.message;
77
+ resolve({ code: 1, timedOut: false });
78
+ });
79
+ child.on('exit', (c) => {
80
+ clearTimeout(timer);
81
+ resolve({ code: c, timedOut: false });
82
+ });
83
+ }));
84
+ }
85
+ finally {
86
+ await out.close();
87
+ }
88
+ if (!stderr)
89
+ stderr = await readTail(file);
90
+ }
91
+ finally {
92
+ await rm(tmp, { recursive: true, force: true });
93
+ }
60
94
  if (timedOut)
61
95
  throw api.abort(`${SCRIPT_NAME} did not finish within ${SCRIPT_TIMEOUT_MS / 1000}s`);
62
96
  if (code !== 0)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sideby",
3
- "version": "0.19.0",
3
+ "version": "0.19.1",
4
4
  "description": "Run work, personal and API-key accounts at the same time, without their configs drifting apart.",
5
5
  "license": "MIT",
6
6
  "author": "Adonis0123 (https://github.com/Adonis0123)",
@@ -2,7 +2,7 @@
2
2
  name: sideby
3
3
  description: Use when the user runs, or wants to run, several AI coding accounts (Claude Code, Codex, Grok Build, pi) side by side. Covers installing sideby and setting up a new account ("install sideby", "set up another Claude account", "add cc008", "配置一个 cc00x", "再加一个 Codex 账号"), explaining what accounts share and what stays separate ("what do my accounts share?", "这些账号共享了什么"), showing which account a session is ("show [cc001] in the status line", "加上账号标识"), seeing accounts, quota and usage, moving on when one hits its 5-hour or weekly limit, moving the current task to another account ("用 cc008 继续", "交回 cc008"), adding a short command (alias) or a pick command that starts whichever account has the most quota ("加个 cc"), adding an API account from a vendor's docs ("加一个 DeepSeek API 账号"), supporting a new tool, and repairing drifted account directories (skills, hooks, rules or settings not shared, wrong symlinks, credential file permissions). Drives the `sideby` CLI with `--json`; the agent does every step except browser sign-in, filling in secrets and starting interactive sessions, which it hands to the user as one command (inside an Auto Handoff session, `sideby handoff ready --to` moves the task itself).
4
4
  metadata:
5
- version: "0.19.0"
5
+ version: "0.19.1"
6
6
  requires:
7
7
  bins: [sideby, node]
8
8
  cliHelp: sideby --help