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.
- package/README.md +8 -0
- package/dist/build.json +1 -1
- package/dist/src/cli/commands.js +159 -13
- package/dist/src/cli/json-schemas.js +39 -1
- package/dist/src/cli/main.js +23 -6
- package/dist/src/core/ask.d.ts +14 -0
- package/dist/src/core/ask.js +16 -1
- package/dist/src/core/browser-profiles.js +7 -32
- package/dist/src/core/config.d.ts +14 -0
- package/dist/src/core/config.js +64 -1
- package/dist/src/core/pick-commands.d.ts +42 -0
- package/dist/src/core/pick-commands.js +44 -0
- package/dist/src/core/shell-init.js +3 -1
- package/dist/src/core/shell-setup.d.ts +40 -0
- package/dist/src/core/shell-setup.js +54 -0
- package/dist/src/core/skill-check.d.ts +2 -0
- package/dist/src/core/skill-check.js +2 -0
- package/dist/src/core/terminal.d.ts +21 -4
- package/dist/src/core/terminal.js +149 -9
- package/dist/src/core/update.js +2 -2
- package/dist/src/core/windows-dirs.d.ts +19 -0
- package/dist/src/core/windows-dirs.js +39 -0
- package/dist/src/panel/handler.d.ts +18 -0
- package/dist/src/panel/handler.js +69 -1
- package/dist/src/panel/i18n.d.ts +39 -0
- package/dist/src/panel/i18n.js +78 -0
- package/dist/src/panel/page-script.js +182 -3
- package/dist/src/panel/page-styles.js +3 -0
- package/dist/src/panel/page.js +6 -1
- package/dist/src/runtime.d.ts +35 -1
- package/dist/src/runtime.js +96 -3
- package/package.json +2 -2
- package/schemas/alias-list.json +119 -0
- package/schemas/alias.json +27 -1
- package/schemas/config.json +11 -0
- package/schemas/new.json +19 -0
- package/schemas/shell-init-setup.json +124 -0
- package/skills/sideby/SKILL.md +6 -3
- package/skills/sideby/references/accounts.md +10 -0
- package/skills/sideby/references/setup.md +1 -1
package/README.md
CHANGED
|
@@ -56,6 +56,14 @@ https://github.com/user-attachments/assets/d1d7e8dd-1df1-4881-ac88-e468c2dd4a1d
|
|
|
56
56
|
<img alt="sideby panel: every account's 5h and 7d quota, 7-day token usage and health in one page" src="https://raw.githubusercontent.com/Adonis0123/sideby/main/docs/assets/panel.png" width="1280">
|
|
57
57
|
</picture>
|
|
58
58
|
|
|
59
|
+
On macOS, the same quota sits in the menu bar (`sideby menubar on`): click or press `⌥⌘S` to open it, and click an account to start it in the terminal.
|
|
60
|
+
|
|
61
|
+
<picture>
|
|
62
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/Adonis0123/sideby/main/docs/assets/menubar-dark.png">
|
|
63
|
+
<source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/Adonis0123/sideby/main/docs/assets/menubar.png">
|
|
64
|
+
<img alt="sideby macOS menu bar dropdown: a status card, each tool with 5-hour and weekly quota bars, reset times, and the suggested account marked" src="https://raw.githubusercontent.com/Adonis0123/sideby/main/docs/assets/menubar.png" width="468">
|
|
65
|
+
</picture>
|
|
66
|
+
|
|
59
67
|
## Why not just an alias?
|
|
60
68
|
|
|
61
69
|
`CLAUDE_CONFIG_DIR` plus a shell alias already starts a second account. It does not keep skills and settings in one place, and it does not show quota for every account. [Does this break a provider's terms?](docs/guide/faq.md#terms)
|
package/dist/build.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"id":"
|
|
1
|
+
{"id":"20261019T134334-23c436"}
|
package/dist/src/cli/commands.js
CHANGED
|
@@ -3,7 +3,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
3
3
|
import { aliasesByAccount } from '../core/accounts.js';
|
|
4
4
|
import { listAppProfiles, openAppProfile, parseProfileRef, removeAppProfile } from '../core/app-profiles.js';
|
|
5
5
|
import { browserReport, openInBrowser, setBrowserSignIns } from '../core/browser-profiles.js';
|
|
6
|
-
import { aliasRefs, editConfigUpdate } from '../core/config.js';
|
|
6
|
+
import { aliasAccount, aliasArgs, aliasRefs, editConfigUpdate } from '../core/config.js';
|
|
7
7
|
import { openDesktopApp, withDesktopApps } from '../core/desktop-app.js';
|
|
8
8
|
import { editSettings } from '../core/edit-settings.js';
|
|
9
9
|
import { UserError } from '../core/errors.js';
|
|
@@ -335,8 +335,13 @@ export async function cmdNew(a, io) {
|
|
|
335
335
|
api: a.flags.has('api'),
|
|
336
336
|
...(alias !== undefined ? { alias } : {}),
|
|
337
337
|
});
|
|
338
|
+
const pickOffer = await pickOfferAfterNew(rt, res.account);
|
|
338
339
|
if (a.flags.has('json')) {
|
|
339
|
-
json(io,
|
|
340
|
+
json(io, {
|
|
341
|
+
...res,
|
|
342
|
+
...(suggestion ? { suggestion } : {}),
|
|
343
|
+
...(pickOffer ? { pickCommandOffer: pickOffer } : {}),
|
|
344
|
+
});
|
|
340
345
|
return res.ok ? 0 : 1;
|
|
341
346
|
}
|
|
342
347
|
if (suggestion?.aliasProblem)
|
|
@@ -364,8 +369,29 @@ export async function cmdNew(a, io) {
|
|
|
364
369
|
io.out('\nNext:');
|
|
365
370
|
for (const n of res.nextSteps)
|
|
366
371
|
io.out(` ${n}`);
|
|
372
|
+
if (pickOffer)
|
|
373
|
+
io.out(c.dim(`\nTip: with two ${res.account.family} accounts, \`${pickOffer.command}\` adds ${pickOffer.name}, which starts the one with the most quota left each time.`));
|
|
367
374
|
return res.ok ? 0 : 1;
|
|
368
375
|
}
|
|
376
|
+
/**
|
|
377
|
+
* The Pick Command `sideby new` offers once, when the new Account is its Family's second Subscription Account and
|
|
378
|
+
* the Family has none yet (spec §3.13).
|
|
379
|
+
*/
|
|
380
|
+
async function pickOfferAfterNew(rt, account) {
|
|
381
|
+
if (account.kind === 'api')
|
|
382
|
+
return null;
|
|
383
|
+
const subs = (await rt.accounts()).filter((x) => x.family === account.family && x.kind !== 'api');
|
|
384
|
+
if (subs.length !== 2)
|
|
385
|
+
return null;
|
|
386
|
+
const offer = await rt.pickSuggestion(account.family);
|
|
387
|
+
if (!offer || offer.exists || offer.name === null)
|
|
388
|
+
return null;
|
|
389
|
+
return {
|
|
390
|
+
name: offer.name,
|
|
391
|
+
command: `sideby alias add ${offer.name} --pick ${account.family}`,
|
|
392
|
+
...(offer.shadows ? { shadows: offer.shadows } : {}),
|
|
393
|
+
};
|
|
394
|
+
}
|
|
369
395
|
function printShellInitWrites(io, files, home) {
|
|
370
396
|
for (const f of files) {
|
|
371
397
|
const path = f.path.startsWith('/') ? tildify(f.path, home) : f.path;
|
|
@@ -382,6 +408,8 @@ export async function cmdRun(a, io, command) {
|
|
|
382
408
|
if (command === 'login' && (extra.length || a.rest.length))
|
|
383
409
|
throw new UsageError('login takes no extra arguments');
|
|
384
410
|
const rt = await createRuntime();
|
|
411
|
+
if (command === 'run' && rt.pickCommandFamily(ref) !== undefined)
|
|
412
|
+
return runPick(rt, ref, [...extra, ...a.rest], io);
|
|
385
413
|
if (command === 'run')
|
|
386
414
|
return runAccount(rt, ref, [...extra, ...a.rest], io);
|
|
387
415
|
const prepared = await rt.prepareLaunch(ref, [...extra, ...a.rest], command);
|
|
@@ -389,6 +417,24 @@ export async function cmdRun(a, io, command) {
|
|
|
389
417
|
io.err(c.cyan(prepared.notice));
|
|
390
418
|
return whileRunning(rt, () => runHost(prepared));
|
|
391
419
|
}
|
|
420
|
+
/** A Pick Command (spec §3.13, ADR-0035): start the Account with the most room, else the Main Account, and say which. */
|
|
421
|
+
async function runPick(rt, name, args, io) {
|
|
422
|
+
const { choice, family } = await rt.pickChoice(name);
|
|
423
|
+
if (choice.ref === null) {
|
|
424
|
+
const now = rt.readContext().now;
|
|
425
|
+
const why = choice.earliestReset
|
|
426
|
+
? `every ${family} account is at its limit; ${choice.earliestReset.ref} is back at ${clock(choice.earliestReset.at, now)}`
|
|
427
|
+
: `no ${family} account can be used now`;
|
|
428
|
+
const signIn = choice.signIn.length
|
|
429
|
+
? `; sign in with \`sideby login ${choice.signIn.join('` or `sideby login ')}\``
|
|
430
|
+
: '';
|
|
431
|
+
io.err(c.yellow(`${name}: ${why}${signIn}, or start one yourself with \`sideby run <account>\`.`));
|
|
432
|
+
return 1;
|
|
433
|
+
}
|
|
434
|
+
const { pickLine } = await import('../core/pick-commands.js');
|
|
435
|
+
io.err(c.dim(`sideby: ${pickLine(name, choice)}`));
|
|
436
|
+
return runAccount(rt, choice.ref, args, io);
|
|
437
|
+
}
|
|
392
438
|
/**
|
|
393
439
|
* `sideby resume <family>`: what the Host-named shell function calls (spec §3.15). Starts the Account that holds the
|
|
394
440
|
* session the arguments resume by id, a new session where a never-saved one started (ADR-0009), or the Host unchanged.
|
|
@@ -1166,6 +1212,8 @@ export async function cmdPlugins(a, io) {
|
|
|
1166
1212
|
return rt.pluginErrors.length ? 1 : 0;
|
|
1167
1213
|
}
|
|
1168
1214
|
export async function cmdShellInit(a, io) {
|
|
1215
|
+
if (a.positionals[0] === 'setup')
|
|
1216
|
+
return cmdShellSetup(a, io);
|
|
1169
1217
|
const shell = a.positionals[0];
|
|
1170
1218
|
const write = a.flags.has('write');
|
|
1171
1219
|
const usage = 'usage: sideby shell-init zsh|bash | sideby shell-init [zsh|bash] --write';
|
|
@@ -1187,6 +1235,51 @@ export async function cmdShellInit(a, io) {
|
|
|
1187
1235
|
printShellInitWrites(io, files, rt.paths.home);
|
|
1188
1236
|
return files.every((f) => f.ok) ? 0 : 1;
|
|
1189
1237
|
}
|
|
1238
|
+
/**
|
|
1239
|
+
* `sideby shell-init setup [zsh|bash] [--yes|--undo]` (spec §3.13, ADR-0036): shows the line it would add to the rc
|
|
1240
|
+
* file and exits 10, adds it with --yes, or takes out exactly what it added with --undo.
|
|
1241
|
+
*/
|
|
1242
|
+
async function cmdShellSetup(a, io) {
|
|
1243
|
+
const [, given, ...extra] = a.positionals;
|
|
1244
|
+
if (extra.length || (given !== undefined && !SHELLS.includes(given)) || a.flags.has('write'))
|
|
1245
|
+
throw new UsageError('usage: sideby shell-init setup [zsh|bash] [--yes|--undo] [--json]');
|
|
1246
|
+
const { applyShellSetup, setupBlock, shellSetupStatus, userShell } = await import('../core/shell-setup.js');
|
|
1247
|
+
const rt = await createRuntime();
|
|
1248
|
+
const shell = given ?? userShell(rt.env);
|
|
1249
|
+
const home = rt.paths.home;
|
|
1250
|
+
const undo = a.flags.has('undo');
|
|
1251
|
+
const st = await shellSetupStatus(shell, home, rt.env, rt.config.shellInitFile);
|
|
1252
|
+
const rc = tildify(st.rc, home);
|
|
1253
|
+
const out = (data, code) => {
|
|
1254
|
+
if (a.flags.has('json'))
|
|
1255
|
+
json(io, { shell, rc, ...data });
|
|
1256
|
+
return code;
|
|
1257
|
+
};
|
|
1258
|
+
if (!undo && st.loaded) {
|
|
1259
|
+
if (!a.flags.has('json'))
|
|
1260
|
+
io.out(`${c.green('✓')} new terminals already load your short commands (${rc})`);
|
|
1261
|
+
return out({ status: 'loaded' }, 0);
|
|
1262
|
+
}
|
|
1263
|
+
if (undo && !st.added) {
|
|
1264
|
+
if (!a.flags.has('json'))
|
|
1265
|
+
io.out(`${c.dim('·')} ${rc} has no line sideby added; nothing to undo`);
|
|
1266
|
+
return out({ status: 'not-added' }, 0);
|
|
1267
|
+
}
|
|
1268
|
+
if (!a.flags.has('yes') && !undo) {
|
|
1269
|
+
if (!a.flags.has('json')) {
|
|
1270
|
+
io.out(`New terminals do not load your short commands yet. sideby would add to the end of ${rc}:\n`);
|
|
1271
|
+
io.out(c.dim(setupBlock(shell).replace(/\n$/, '')));
|
|
1272
|
+
io.out('\nRun again with --yes to add it; `sideby shell-init setup --undo` takes it out again.');
|
|
1273
|
+
}
|
|
1274
|
+
return out({ status: 'confirm', block: setupBlock(shell) }, 10);
|
|
1275
|
+
}
|
|
1276
|
+
const r = await applyShellSetup(shell, home, rt.env, rt.config.shellInitFile, { undo });
|
|
1277
|
+
if (!a.flags.has('json'))
|
|
1278
|
+
io.out(r.status === 'added'
|
|
1279
|
+
? `${c.green('✓')} added the line to ${rc}; it works in a new terminal window`
|
|
1280
|
+
: `${c.green('✓')} took sideby's line out of ${rc}`);
|
|
1281
|
+
return out({ status: r.status }, 0);
|
|
1282
|
+
}
|
|
1190
1283
|
/** Absolute path of this CLI's entry (`main.ts` from source, `main.js` from dist), for detached processes. */
|
|
1191
1284
|
function cliEntry() {
|
|
1192
1285
|
const ext = import.meta.url.endsWith('.ts') ? 'ts' : 'js';
|
|
@@ -1728,28 +1821,79 @@ export async function cmdBrowser(a, io) {
|
|
|
1728
1821
|
}
|
|
1729
1822
|
export async function cmdAlias(a, io) {
|
|
1730
1823
|
const [sub, alias, target, ...more] = a.positionals;
|
|
1731
|
-
const usage = 'usage: sideby alias add <short-command> <account> [-- host args] | sideby alias rm <short-command>';
|
|
1732
|
-
const
|
|
1733
|
-
|
|
1734
|
-
|
|
1824
|
+
const usage = 'usage: sideby alias add <short-command> <account> [-- host args] | sideby alias add <short-command> --pick <family> [--yes] | sideby alias rm <short-command> | sideby alias list';
|
|
1825
|
+
const pick = a.flags.get('pick');
|
|
1826
|
+
if (sub === 'list' && alias === undefined && pick === undefined)
|
|
1827
|
+
return aliasList(a, io);
|
|
1828
|
+
const addPick = sub === 'add' && alias !== undefined && typeof pick === 'string' && target === undefined && !a.rest.length;
|
|
1829
|
+
const add = sub === 'add' && pick === undefined && alias !== undefined && target !== undefined && more.length === 0;
|
|
1830
|
+
const rm = sub === 'rm' && pick === undefined && alias !== undefined && target === undefined && a.rest.length === 0;
|
|
1831
|
+
if (!add && !rm && !addPick)
|
|
1735
1832
|
throw new UsageError(usage);
|
|
1736
1833
|
const rt = await createRuntime();
|
|
1737
|
-
const res =
|
|
1834
|
+
const res = addPick
|
|
1835
|
+
? await rt.addPickCommand(alias, pick, { yes: a.flags.has('yes') })
|
|
1836
|
+
: add
|
|
1837
|
+
? await rt.addAlias(alias, target, a.rest)
|
|
1838
|
+
: await rt.removeAlias(alias);
|
|
1738
1839
|
if (a.flags.has('json')) {
|
|
1739
1840
|
json(io, res);
|
|
1740
|
-
return res.ok ? 0 : 1;
|
|
1841
|
+
return res.status === 'confirm' ? 10 : res.ok ? 0 : 1;
|
|
1842
|
+
}
|
|
1843
|
+
if (res.status === 'confirm') {
|
|
1844
|
+
io.out(`Adds ${c.bold(res.alias)}: typed in a new terminal, it starts the ${res.family} account with the most quota left.`);
|
|
1845
|
+
io.out(c.dim(`Saved in ${tildify(rt.paths.configFile, rt.paths.home)} (pickCommands).`));
|
|
1846
|
+
if (res.shadows)
|
|
1847
|
+
io.out(`${c.yellow('!')} ${res.alias} is already a command (${res.shadows}): in your shell, typing ${res.alias} would start ${res.family} instead.`);
|
|
1848
|
+
io.out(`Run again with --yes to add it${res.shadows ? ' anyway, or pick another name' : ''}.`);
|
|
1849
|
+
return 10;
|
|
1741
1850
|
}
|
|
1742
|
-
const starts = res.
|
|
1851
|
+
const starts = res.kind === 'pick'
|
|
1852
|
+
? ` → the ${res.family} account with the most room`
|
|
1853
|
+
: res.account
|
|
1854
|
+
? ` → ${res.account}${res.args ? ` ${res.args.join(' ')}` : ''}`
|
|
1855
|
+
: '';
|
|
1856
|
+
const what = res.kind === 'pick' ? 'pick command' : 'short command';
|
|
1743
1857
|
const said = {
|
|
1744
|
-
added: `${c.green('✓')}
|
|
1745
|
-
exists: `${c.green('✓')}
|
|
1746
|
-
removed: `${c.green('✓')} removed
|
|
1858
|
+
added: `${c.green('✓')} ${what} ${c.bold(res.alias)}${starts} (in a new shell)`,
|
|
1859
|
+
exists: `${c.green('✓')} ${what} ${c.bold(res.alias)}${starts} was already in the config`,
|
|
1860
|
+
removed: `${c.green('✓')} removed ${what} ${c.bold(res.alias)}${starts}`,
|
|
1747
1861
|
absent: `${c.dim('·')} no short command ${res.alias} in the config; nothing to remove`,
|
|
1748
1862
|
};
|
|
1749
1863
|
io.out(said[res.status]);
|
|
1750
1864
|
printShellInitWrites(io, res.shellInitFiles ?? [], rt.paths.home);
|
|
1751
1865
|
return res.ok ? 0 : 1;
|
|
1752
1866
|
}
|
|
1867
|
+
/** `sideby alias list`: every Alias and Pick Command in the config. */
|
|
1868
|
+
async function aliasList(a, io) {
|
|
1869
|
+
const rt = await createRuntime();
|
|
1870
|
+
const shortCommands = [
|
|
1871
|
+
...Object.entries(rt.config.aliases ?? {}).map(([name, v]) => {
|
|
1872
|
+
const args = aliasArgs(v);
|
|
1873
|
+
return { name, kind: 'account', account: aliasAccount(v), ...(args.length ? { args } : {}) };
|
|
1874
|
+
}),
|
|
1875
|
+
...Object.entries(rt.config.pickCommands ?? {}).map(([name, family]) => ({
|
|
1876
|
+
name,
|
|
1877
|
+
kind: 'pick',
|
|
1878
|
+
family,
|
|
1879
|
+
})),
|
|
1880
|
+
].sort((x, y) => x.name.localeCompare(y.name));
|
|
1881
|
+
if (a.flags.has('json')) {
|
|
1882
|
+
json(io, { shortCommands });
|
|
1883
|
+
return 0;
|
|
1884
|
+
}
|
|
1885
|
+
if (!shortCommands.length) {
|
|
1886
|
+
io.out('No short commands yet. Add one with `sideby alias add cc --pick claude` or `sideby alias add cc008 claude:008`.');
|
|
1887
|
+
return 0;
|
|
1888
|
+
}
|
|
1889
|
+
io.out(table(shortCommands.map((s) => [
|
|
1890
|
+
c.bold(s.name),
|
|
1891
|
+
s.kind === 'pick'
|
|
1892
|
+
? `the ${s.family} account with the most room`
|
|
1893
|
+
: `${s.account}${s.args ? ` ${s.args.join(' ')}` : ''}`,
|
|
1894
|
+
]), ['SHORT', 'STARTS']));
|
|
1895
|
+
return 0;
|
|
1896
|
+
}
|
|
1753
1897
|
/** `sideby families [family]`: each Family's layout, sign-in and Shared Items, from its FamilyDef (spec §3.16). */
|
|
1754
1898
|
export async function cmdFamilies(a, io) {
|
|
1755
1899
|
const [only, ...extra] = a.positionals;
|
|
@@ -1825,7 +1969,9 @@ export async function cmdAsk(a, io, runtime) {
|
|
|
1825
1969
|
if (task.kind === 'prompt')
|
|
1826
1970
|
return await runAccount(rt, task.account, await taskHostArgs(rt, task), io, { aiTask: true });
|
|
1827
1971
|
if (task.kind === 'run')
|
|
1828
|
-
return
|
|
1972
|
+
return rt.pickCommandFamily(task.account) !== undefined
|
|
1973
|
+
? await runPick(rt, task.account, [], io)
|
|
1974
|
+
: await runAccount(rt, task.account, [], io);
|
|
1829
1975
|
const prepared = await rt.prepareLaunch(task.account, [], 'login');
|
|
1830
1976
|
if (prepared.notice)
|
|
1831
1977
|
io.err(prepared.notice);
|
|
@@ -614,6 +614,9 @@ export const OUTPUT_SCHEMAS = {
|
|
|
614
614
|
suggestion: Type.Optional(Type.Object({ name: Str, alias: Type.Optional(Str), aliasProblem: Type.Optional(Str) }, {
|
|
615
615
|
description: 'Only with `--next`: the picked name, the short command that follows the existing pattern, or why that short command was left out.',
|
|
616
616
|
})),
|
|
617
|
+
pickCommandOffer: Type.Optional(Type.Object({ name: Str, command: Str, shadows: Type.Optional(Str) }, {
|
|
618
|
+
description: 'Set once, when this is the Family’s second subscription account and it has no pick command: the command that adds one.',
|
|
619
|
+
})),
|
|
617
620
|
}, { title: 'sideby new --json' }),
|
|
618
621
|
alias: Type.Object({
|
|
619
622
|
schemaVersion: Version,
|
|
@@ -624,11 +627,46 @@ export const OUTPUT_SCHEMAS = {
|
|
|
624
627
|
Type.Literal('exists'),
|
|
625
628
|
Type.Literal('removed'),
|
|
626
629
|
Type.Literal('absent'),
|
|
627
|
-
|
|
630
|
+
Type.Literal('confirm'),
|
|
631
|
+
], {
|
|
632
|
+
description: '`confirm` (exit 10): the pick command would hide a command on PATH, so nothing was written; run again with `--yes`.',
|
|
633
|
+
}),
|
|
634
|
+
kind: Type.Optional(Type.Union([Type.Literal('account'), Type.Literal('pick')], {
|
|
635
|
+
description: '`pick` for a Pick Command (`--pick`), `account` for a short command of one Account.',
|
|
636
|
+
})),
|
|
628
637
|
account: Type.Optional(Str),
|
|
629
638
|
args: Type.Optional(Type.Array(Str, { description: 'Host arguments `sideby run <alias>` adds.' })),
|
|
639
|
+
family: Type.Optional(Type.String({ description: 'The Family a Pick Command picks in.' })),
|
|
640
|
+
shadows: Type.Optional(Type.String({
|
|
641
|
+
description: 'The command on PATH this Pick Command hides in the shell, such as /usr/bin/cc.',
|
|
642
|
+
})),
|
|
630
643
|
shellInitFiles: Type.Optional(ShellInitFiles),
|
|
631
644
|
}, { title: 'sideby alias add|rm --json' }),
|
|
645
|
+
'shell-init-setup': Type.Object({
|
|
646
|
+
schemaVersion: Version,
|
|
647
|
+
shell: Type.Union([Type.Literal('zsh'), Type.Literal('bash')]),
|
|
648
|
+
rc: Type.String({ description: 'The rc file, with ~ for the home folder.' }),
|
|
649
|
+
status: Type.Union([
|
|
650
|
+
Type.Literal('loaded'),
|
|
651
|
+
Type.Literal('confirm'),
|
|
652
|
+
Type.Literal('added'),
|
|
653
|
+
Type.Literal('removed'),
|
|
654
|
+
Type.Literal('not-added'),
|
|
655
|
+
], {
|
|
656
|
+
description: '`loaded`: new terminals already load the short commands. `confirm` (exit 10): nothing written; `block` is what --yes appends. `not-added`: --undo found no line sideby added.',
|
|
657
|
+
}),
|
|
658
|
+
block: Type.Optional(Type.String()),
|
|
659
|
+
}, { title: 'sideby shell-init setup --json' }),
|
|
660
|
+
'alias-list': Type.Object({
|
|
661
|
+
schemaVersion: Version,
|
|
662
|
+
shortCommands: Type.Array(Type.Object({
|
|
663
|
+
name: Str,
|
|
664
|
+
kind: Type.Union([Type.Literal('account'), Type.Literal('pick')]),
|
|
665
|
+
account: Type.Optional(Type.String({ description: 'The Account a short command of kind `account` starts.' })),
|
|
666
|
+
args: Type.Optional(Type.Array(Str)),
|
|
667
|
+
family: Type.Optional(Type.String({ description: 'The Family a Pick Command picks in.' })),
|
|
668
|
+
})),
|
|
669
|
+
}, { title: 'sideby alias list --json' }),
|
|
632
670
|
plugins: Type.Object({
|
|
633
671
|
schemaVersion: Version,
|
|
634
672
|
plugins: Type.Array(Type.Object({
|
package/dist/src/cli/main.js
CHANGED
|
@@ -31,7 +31,11 @@ Usage:
|
|
|
31
31
|
sideby alias add <short> <account> [-- args]
|
|
32
32
|
add a short command, optionally with host arguments
|
|
33
33
|
(sideby alias add pi-kimi pi:main -- --model kimi-coding/k3)
|
|
34
|
+
sideby alias add <short> --pick <family> [--yes]
|
|
35
|
+
add a pick command: each run starts the account with the
|
|
36
|
+
most quota left (sideby alias add cc --pick claude)
|
|
34
37
|
sideby alias rm <short> remove a short command
|
|
38
|
+
sideby alias list list short commands and pick commands
|
|
35
39
|
sideby login <account> sign in to an account
|
|
36
40
|
sideby resume <family> [-- args] run the host; a session resumed by id (claude --resume <id>,
|
|
37
41
|
codex resume <id>) starts in the account that holds it
|
|
@@ -77,6 +81,9 @@ Usage:
|
|
|
77
81
|
sideby shell-init zsh|bash print shell functions, e.g. eval "$(sideby shell-init zsh)"
|
|
78
82
|
sideby shell-init [zsh|bash] --write
|
|
79
83
|
rewrite the config's shellInitFile with them
|
|
84
|
+
sideby shell-init setup [zsh|bash] [--yes|--undo]
|
|
85
|
+
make new terminals load your short commands: adds one line to
|
|
86
|
+
~/.zshrc (or ~/.bashrc), shown first; --undo takes it out
|
|
80
87
|
sideby plugins list loaded plugins and load errors
|
|
81
88
|
sideby plugins new <id> create a local Family Plugin skeleton
|
|
82
89
|
sideby plugins check <id|path> check a plugin and show fixes
|
|
@@ -138,20 +145,28 @@ Writes: the account directory; the config \`aliases\` and every \`shellInitFile\
|
|
|
138
145
|
Next: the user signs in with \`sideby login <account>\` (subscription) or fills in proxy.env (API).
|
|
139
146
|
Exit: 0 done; 1 invalid name or alias, directory exists, or partly failed; 2 malformed command line.`,
|
|
140
147
|
alias: `sideby alias add <short> <account> [-- host args] [--json]
|
|
148
|
+
sideby alias add <short> --pick <family> [--yes] [--json]
|
|
141
149
|
sideby alias rm <short> [--json]
|
|
150
|
+
sideby alias list [--json]
|
|
142
151
|
|
|
143
152
|
A short command starts one account: \`sideby run <short>\`, or just \`<short>\` once your shell loads
|
|
144
153
|
\`sideby shell-init\`. Host arguments after -- are added only when it starts through the short command; it is
|
|
145
154
|
the same account (same sign-in, same sessions), so do not create an account per model.
|
|
146
155
|
|
|
156
|
+
A pick command (--pick) starts, each time, the account of that family with the most quota left, the one
|
|
157
|
+
\`sideby next\` would pick; when no account has quota data yet it starts the main account. It prints which
|
|
158
|
+
account it started. A name that hides a command on PATH (cc is the C compiler on macOS) needs --yes.
|
|
159
|
+
|
|
147
160
|
Examples:
|
|
148
161
|
sideby alias add cc008 claude:008
|
|
149
162
|
sideby alias add pi-kimi pi:main -- --model kimi-coding/k3
|
|
163
|
+
sideby alias add cc --pick claude # says first if cc hides a command (exit 10)
|
|
150
164
|
sideby alias rm cc008
|
|
151
165
|
|
|
152
|
-
Writes: the config \`aliases\` and every \`shellInitFile\`. New shell functions work in a
|
|
153
|
-
eval "$(sideby shell-init zsh)" (put that line in ~/.zshrc once).
|
|
154
|
-
Exit: 0 done (also when it already exists or is absent); 1 invalid, reserved or taken; 2 malformed
|
|
166
|
+
Writes: the config \`aliases\` or \`pickCommands\` and every \`shellInitFile\`. New shell functions work in a
|
|
167
|
+
new shell, or after eval "$(sideby shell-init zsh)" (put that line in ~/.zshrc once).
|
|
168
|
+
Exit: 0 done (also when it already exists or is absent); 1 invalid, reserved or taken; 2 malformed;
|
|
169
|
+
10 a pick command would hide a command on PATH, run again with --yes.`,
|
|
155
170
|
login: `sideby login <account>
|
|
156
171
|
|
|
157
172
|
Run the host's own sign-in for one account: claude auth login, codex login, grok login. For pi it starts pi;
|
|
@@ -338,7 +353,7 @@ const COMMANDS = {
|
|
|
338
353
|
login: { flags: [] },
|
|
339
354
|
next: { flags: ['dry-run', 'include-api', 'json'] },
|
|
340
355
|
new: { flags: ['api', 'json', 'next'], valued: ['alias'] },
|
|
341
|
-
alias: { flags: ['json'] },
|
|
356
|
+
alias: { flags: ['json', 'yes'], valued: ['pick'] },
|
|
342
357
|
doctor: { flags: ['fix', 'force', 'json'] },
|
|
343
358
|
quota: { flags: ['json', 'yes', 'refresh'] },
|
|
344
359
|
tune: { flags: ['json', 'yes'] },
|
|
@@ -353,7 +368,7 @@ const COMMANDS = {
|
|
|
353
368
|
desktop: { flags: ['json', 'remove', 'yes'] },
|
|
354
369
|
edit: { flags: ['json', 'path'] },
|
|
355
370
|
browser: { flags: ['json', 'enable', 'disable', 'yes'], valued: ['profile'] },
|
|
356
|
-
'shell-init': { flags: ['write'] },
|
|
371
|
+
'shell-init': { flags: ['write', 'yes', 'undo', 'json'] },
|
|
357
372
|
plugins: { flags: ['json'] },
|
|
358
373
|
families: { flags: ['json'] },
|
|
359
374
|
update: { flags: ['json', 'yes', 'skill'], valued: ['auto'] },
|
|
@@ -374,7 +389,9 @@ function repeatedValues(args, name) {
|
|
|
374
389
|
}
|
|
375
390
|
/** Commands that never print an Update Notice: their output is read by a shell or an agent, or they are internal. */
|
|
376
391
|
function noticeAllowed(cmd, parsed) {
|
|
377
|
-
if (cmd === 'shell-init'
|
|
392
|
+
if ((cmd === 'shell-init' && parsed.positionals[0] !== 'setup') ||
|
|
393
|
+
cmd === 'update' ||
|
|
394
|
+
cmd === 'update-check')
|
|
378
395
|
return false;
|
|
379
396
|
if (cmd === 'ask' && (parsed.flags.has('print') || parsed.flags.has('run')))
|
|
380
397
|
return false;
|
package/dist/src/core/ask.d.ts
CHANGED
|
@@ -197,6 +197,20 @@ export declare function openRunInTerminal(rt: Runtime, ref: string): Promise<{
|
|
|
197
197
|
reason?: AiTaskReason | undefined;
|
|
198
198
|
detail?: string | undefined;
|
|
199
199
|
}>;
|
|
200
|
+
/**
|
|
201
|
+
* Starts a Pick Command in the Preferred Terminal (spec §3.13): the terminal runs it as `sideby run <name>` does, so it
|
|
202
|
+
* picks the Account when it starts and says which there.
|
|
203
|
+
*/
|
|
204
|
+
export declare function openPickInTerminal(rt: Runtime, name: string): Promise<{
|
|
205
|
+
schemaVersion: 1;
|
|
206
|
+
task: string;
|
|
207
|
+
account: string;
|
|
208
|
+
terminal: string;
|
|
209
|
+
opened: boolean;
|
|
210
|
+
command: string;
|
|
211
|
+
reason?: AiTaskReason | undefined;
|
|
212
|
+
detail?: string | undefined;
|
|
213
|
+
}>;
|
|
200
214
|
/**
|
|
201
215
|
* What `try` will run for an Account, computed as `sideby run` would (Family defaults, config arguments) but without
|
|
202
216
|
* reading its Secret File or running `launch.before` hooks: nothing runs before the user agrees.
|
package/dist/src/core/ask.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { randomBytes } from 'node:crypto';
|
|
2
2
|
import { constants } from 'node:fs';
|
|
3
3
|
import { lstat, mkdtemp, open, readdir, realpath, rm, stat, unlink } from 'node:fs/promises';
|
|
4
|
+
import { userInfo } from 'node:os';
|
|
4
5
|
import { dirname, isAbsolute, join, sep } from 'node:path';
|
|
5
6
|
import { AI_TASK_KINDS, stripSecrets, taskPrompt } from '../panel/page-logic.js';
|
|
6
7
|
import { checkAttachmentFiles, copyAttachments, MAX_ATTACHMENTS, privateDir, removeOldAttachments, stagedAttachments, takeStaged, } from './attachments.js';
|
|
@@ -11,7 +12,7 @@ import { writeFileAtomic } from './fs-safe.js';
|
|
|
11
12
|
import { planHandoff } from './handoff.js';
|
|
12
13
|
import { resolvePaths } from './paths.js';
|
|
13
14
|
import { runProbe, spawnProbe } from './probe.js';
|
|
14
|
-
import { askLauncher, askRunCommand, guessTerminal, installedTerminals, launcherProblem, openTerminal, TERMINALS, validateCustomTemplate, } from './terminal.js';
|
|
15
|
+
import { askLauncher, askRunCommand, guessTerminal, installedTerminals, launcherProblem, openTerminal, TERMINALS, validateCustomTemplate, wslDistro, } from './terminal.js';
|
|
15
16
|
export async function pickTaskAccount(rt, opts = {}) {
|
|
16
17
|
const all = (await rt.accounts()).filter((a) => !opts.family || a.family === opts.family);
|
|
17
18
|
if (opts.account) {
|
|
@@ -210,6 +211,7 @@ export async function terminals(rt) {
|
|
|
210
211
|
env: rt.env,
|
|
211
212
|
platform: deps.platform,
|
|
212
213
|
appDirs,
|
|
214
|
+
...(deps.wslMount ? { wslMount: deps.wslMount, exec: (file, args) => deps.exec(file, args) } : {}),
|
|
213
215
|
});
|
|
214
216
|
if (rt.config.terminal?.custom)
|
|
215
217
|
installed.push({ id: 'custom' });
|
|
@@ -352,6 +354,10 @@ async function openTask(rt, task, terminal, launcher = askLauncher(), taskId = n
|
|
|
352
354
|
custom: rt.config.terminal?.custom,
|
|
353
355
|
installed: choices.installed,
|
|
354
356
|
platform: deps.platform,
|
|
357
|
+
// Both open from WSL into this distribution (Orca picks its worktree from it).
|
|
358
|
+
...(id === 'windows-terminal' || (id === 'orca' && deps.platform === 'linux')
|
|
359
|
+
? { wslDistro: await wslDistro(rt.env, deps.exec), shell: userInfo().shell ?? undefined }
|
|
360
|
+
: {}),
|
|
355
361
|
}, deps.exec));
|
|
356
362
|
return {
|
|
357
363
|
schemaVersion: 1,
|
|
@@ -431,6 +437,15 @@ export async function openRunInTerminal(rt, ref) {
|
|
|
431
437
|
const account = await rt.resolve(ref);
|
|
432
438
|
return openTask(rt, { kind: 'run', account: account.ref, cwd: rt.paths.home });
|
|
433
439
|
}
|
|
440
|
+
/**
|
|
441
|
+
* Starts a Pick Command in the Preferred Terminal (spec §3.13): the terminal runs it as `sideby run <name>` does, so it
|
|
442
|
+
* picks the Account when it starts and says which there.
|
|
443
|
+
*/
|
|
444
|
+
export async function openPickInTerminal(rt, name) {
|
|
445
|
+
if (rt.pickCommandFamily(name) === undefined)
|
|
446
|
+
throw new UserError(`No short command "${name}" picks an account; add one in the Panel or with \`sideby alias add ${name} --pick <family>\`.`);
|
|
447
|
+
return openTask(rt, { kind: 'run', account: name, cwd: rt.paths.home });
|
|
448
|
+
}
|
|
434
449
|
/**
|
|
435
450
|
* What `try` will run for an Account, computed as `sideby run` would (Family defaults, config arguments) but without
|
|
436
451
|
* reading its Secret File or running `launch.before` hooks: nothing runs before the user agrees.
|
|
@@ -13,6 +13,7 @@ import { editConfigBrowser } from './config.js';
|
|
|
13
13
|
import { depsFor, findApp } from './desktop-app.js';
|
|
14
14
|
import { UserError } from './errors.js';
|
|
15
15
|
import { localStorageKeys } from './leveldb-keys.js';
|
|
16
|
+
import { askWindowsDirs } from './windows-dirs.js';
|
|
16
17
|
const OPEN = '/usr/bin/open';
|
|
17
18
|
export const CHROME = {
|
|
18
19
|
title: 'Google Chrome',
|
|
@@ -25,41 +26,15 @@ const MAX_LOCAL_STATE = 16 * 1024 * 1024;
|
|
|
25
26
|
export function chromeUserData(home) {
|
|
26
27
|
return join(home, 'Library', 'Application Support', 'Google', 'Chrome');
|
|
27
28
|
}
|
|
28
|
-
/**
|
|
29
|
-
function toUnix(win, mount) {
|
|
30
|
-
const m = /^([A-Za-z]):\\(.*)$/.exec(win.trim());
|
|
31
|
-
if (!m)
|
|
32
|
-
return undefined;
|
|
33
|
-
return join(mount, m[1].toLowerCase(), ...m[2].split('\\').filter(Boolean));
|
|
34
|
-
}
|
|
35
|
-
const windowsMemo = new Map();
|
|
29
|
+
/** Windows folders sideby needs on WSL, each as a Windows path and as the WSL path it is mounted at. */
|
|
36
30
|
/**
|
|
37
|
-
* `%LOCALAPPDATA%` and the Program Files folders
|
|
38
|
-
*
|
|
31
|
+
* `%LOCALAPPDATA%` and the Program Files folders (core/windows-dirs.ts). When cmd.exe fails, the only Windows user
|
|
32
|
+
* with Chrome data under `<mount>/c/Users`; several are not guessed between.
|
|
39
33
|
*/
|
|
40
34
|
async function windowsDirs(deps, mount, problems) {
|
|
41
|
-
const
|
|
42
|
-
if (
|
|
43
|
-
return
|
|
44
|
-
const r = await deps.exec(join(mount, 'c', 'Windows', 'System32', 'cmd.exe'), [
|
|
45
|
-
'/d',
|
|
46
|
-
'/c',
|
|
47
|
-
'echo %LOCALAPPDATA%^|%ProgramFiles%^|%ProgramFiles(x86)%',
|
|
48
|
-
]);
|
|
49
|
-
const parts = r.code === 0 ? r.stdout.trim().split('|') : [];
|
|
50
|
-
const dir = (win) => {
|
|
51
|
-
const unix = win ? toUnix(win, mount) : undefined;
|
|
52
|
-
return win && unix ? { win: win.trim(), unix } : undefined;
|
|
53
|
-
};
|
|
54
|
-
const local = dir(parts[0]);
|
|
55
|
-
if (local) {
|
|
56
|
-
const found = {
|
|
57
|
-
localAppData: local,
|
|
58
|
-
programs: [dir(parts[1]), dir(parts[2])].filter((d) => d !== undefined),
|
|
59
|
-
};
|
|
60
|
-
windowsMemo.set(mount, found);
|
|
61
|
-
return found;
|
|
62
|
-
}
|
|
35
|
+
const asked = await askWindowsDirs((file, args) => deps.exec(file, args), mount);
|
|
36
|
+
if (asked)
|
|
37
|
+
return asked;
|
|
63
38
|
// cmd.exe did not answer (interop off, or no C: drive): look for the one Windows user that has Chrome.
|
|
64
39
|
const users = join(mount, 'c', 'Users');
|
|
65
40
|
const withChrome = [];
|
|
@@ -53,6 +53,7 @@ export declare const ConfigSchema: Type.TObject<{
|
|
|
53
53
|
account: Type.TString;
|
|
54
54
|
args: Type.TOptional<Type.TArray<Type.TString>>;
|
|
55
55
|
}>]>>>;
|
|
56
|
+
pickCommands: Type.TOptional<Type.TRecord<"^.*$", Type.TString>>;
|
|
56
57
|
ignore: Type.TOptional<Type.TArray<Type.TString>>;
|
|
57
58
|
pluginDirs: Type.TOptional<Type.TArray<Type.TString>>;
|
|
58
59
|
plugins: Type.TOptional<Type.TRecord<"^.*$", Type.TRecord<"^.*$", Type.TUnknown>>>;
|
|
@@ -188,6 +189,19 @@ export declare function removeConfigAlias(file: string, alias: string): Promise<
|
|
|
188
189
|
status: 'removed' | 'absent';
|
|
189
190
|
aliases: Record<string, AliasValue>;
|
|
190
191
|
}>;
|
|
192
|
+
/**
|
|
193
|
+
* Adds `name → family` to the config file's `pickCommands` (see `editConfigKey` for how the file is written). Refuses
|
|
194
|
+
* an invalid name, one that is an Alias, or one that already picks in another Family.
|
|
195
|
+
*/
|
|
196
|
+
export declare function addConfigPickCommand(file: string, name: string, family: string): Promise<{
|
|
197
|
+
status: 'added' | 'exists';
|
|
198
|
+
pickCommands: Record<string, string>;
|
|
199
|
+
}>;
|
|
200
|
+
/** Removes `name` from `pickCommands`; `absent` when it was not there. An emptied key goes away with it. */
|
|
201
|
+
export declare function removeConfigPickCommand(file: string, name: string): Promise<{
|
|
202
|
+
status: 'removed' | 'absent';
|
|
203
|
+
pickCommands: Record<string, string>;
|
|
204
|
+
}>;
|
|
191
205
|
export declare function editConfigTerminal(file: string, patch: {
|
|
192
206
|
preferred?: string;
|
|
193
207
|
custom?: string;
|