sideby 0.17.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 +11 -1
- package/ai-tasks.json +90 -0
- package/dist/build.json +1 -1
- package/dist/src/cli/commands.d.ts +9 -1
- package/dist/src/cli/commands.js +507 -26
- package/dist/src/cli/json-schemas.js +196 -19
- package/dist/src/cli/main.js +79 -13
- package/dist/src/core/after-install.d.ts +54 -0
- package/dist/src/core/after-install.js +78 -0
- package/dist/src/core/ask.d.ts +87 -1
- package/dist/src/core/ask.js +122 -7
- package/dist/src/core/autostart.d.ts +38 -8
- package/dist/src/core/autostart.js +85 -39
- package/dist/src/core/brand-mark.d.ts +49 -11
- package/dist/src/core/brand-mark.js +116 -38
- package/dist/src/core/browser-profiles.js +7 -32
- package/dist/src/core/config.d.ts +19 -0
- package/dist/src/core/config.js +75 -2
- package/dist/src/core/desktop-app.d.ts +1 -1
- package/dist/src/core/desktop-app.js +2 -2
- package/dist/src/core/edit-settings.d.ts +24 -0
- package/dist/src/core/edit-settings.js +97 -0
- package/dist/src/core/handoff-brief.d.ts +4 -2
- package/dist/src/core/handoff-brief.js +6 -1
- package/dist/src/core/handoff-chain.d.ts +24 -0
- package/dist/src/core/handoff-chain.js +2 -0
- package/dist/src/core/handoff-run.d.ts +4 -3
- package/dist/src/core/handoff-run.js +14 -9
- package/dist/src/core/launch.d.ts +2 -0
- package/dist/src/core/launch.js +14 -10
- package/dist/src/core/local-build.d.ts +12 -5
- package/dist/src/core/local-build.js +49 -31
- package/dist/src/core/lock.d.ts +30 -0
- package/dist/src/core/lock.js +143 -0
- package/dist/src/core/pick-commands.d.ts +42 -0
- package/dist/src/core/pick-commands.js +44 -0
- package/dist/src/core/quota-levels.d.ts +6 -1
- package/dist/src/core/quota-levels.js +16 -5
- 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/task-spec.d.ts +95 -0
- package/dist/src/core/task-spec.js +209 -0
- package/dist/src/core/terminal.d.ts +21 -4
- package/dist/src/core/terminal.js +155 -10
- package/dist/src/core/update.d.ts +27 -16
- package/dist/src/core/update.js +69 -95
- package/dist/src/core/windows-dirs.d.ts +19 -0
- package/dist/src/core/windows-dirs.js +39 -0
- package/dist/src/desktop/icon.js +12 -15
- package/dist/src/families/claude/ai-task.d.ts +8 -0
- package/dist/src/families/claude/ai-task.js +38 -0
- package/dist/src/families/claude/handoff-hook.js +4 -4
- package/dist/src/families/claude/index.js +3 -0
- package/dist/src/families/codex/handoff-hook.js +4 -4
- package/dist/src/families/codex/index.js +9 -0
- package/dist/src/families/grok/handoff-hook.js +4 -4
- package/dist/src/families/grok/index.js +1 -0
- package/dist/src/families/pi/index.js +1 -0
- package/dist/src/handoff/hook.js +51 -30
- package/dist/src/handoff/levels.d.ts +24 -0
- package/dist/src/handoff/levels.js +70 -0
- package/dist/src/handoff/messages.d.ts +6 -3
- package/dist/src/handoff/messages.js +20 -7
- package/dist/src/handoff/reader.d.ts +6 -3
- package/dist/src/menubar/agent.d.ts +3 -0
- package/dist/src/menubar/agent.js +21 -0
- package/dist/src/menubar/script.d.ts +8 -0
- package/dist/src/menubar/script.js +457 -0
- package/dist/src/menubar/snapshot.d.ts +115 -0
- package/dist/src/menubar/snapshot.js +255 -0
- package/dist/src/menubar/strings.d.ts +87 -0
- package/dist/src/menubar/strings.js +88 -0
- package/dist/src/panel/background.js +12 -19
- package/dist/src/panel/handler.d.ts +30 -0
- package/dist/src/panel/handler.js +148 -80
- package/dist/src/panel/i18n.d.ts +72 -0
- package/dist/src/panel/i18n.js +144 -0
- package/dist/src/panel/page-logic.d.ts +105 -0
- package/dist/src/panel/page-logic.js +170 -15
- package/dist/src/panel/page-script.js +419 -111
- package/dist/src/panel/page-styles.js +45 -13
- package/dist/src/panel/page.d.ts +7 -0
- package/dist/src/panel/page.js +11 -1
- package/dist/src/runtime.d.ts +44 -2
- package/dist/src/runtime.js +107 -6
- package/dist/src/types.d.ts +14 -0
- package/package.json +4 -3
- package/schemas/alias-list.json +119 -0
- package/schemas/alias.json +27 -1
- package/schemas/ask-choices.json +168 -0
- package/schemas/ask-print.json +87 -0
- package/schemas/config.json +28 -1
- package/schemas/edit.json +119 -0
- package/schemas/error.json +4 -0
- package/schemas/families.json +4 -0
- package/schemas/list.json +4 -0
- package/schemas/local.json +1 -1
- package/schemas/menubar-snapshot.json +646 -0
- package/schemas/menubar-start.json +112 -0
- package/schemas/menubar.json +165 -0
- package/schemas/new.json +19 -0
- package/schemas/shell-init-setup.json +124 -0
- package/skills/sideby/SKILL.md +11 -4
- package/skills/sideby/references/accounts.md +10 -0
- package/skills/sideby/references/ai-tasks.md +10 -0
- package/skills/sideby/references/handoff.md +3 -1
- package/skills/sideby/references/panel.md +6 -0
- package/skills/sideby/references/setup.md +1 -1
- package/skills/sideby/references/update.md +1 -1
package/dist/src/cli/commands.js
CHANGED
|
@@ -3,8 +3,9 @@ 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
|
+
import { editSettings } from '../core/edit-settings.js';
|
|
8
9
|
import { UserError } from '../core/errors.js';
|
|
9
10
|
import { requestHandoff } from '../core/handoff-chain.js';
|
|
10
11
|
import { handoffOverview } from '../core/handoff-overview.js';
|
|
@@ -33,17 +34,15 @@ async function whileRunning(rt, fn) {
|
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
36
|
/** Runs the Account with Auto Handoff when it applies (spec §3.17), else the Host as usual. */
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
/** `opts.aiTask`: an AI Task's Host, started without permission bypasses (ADR-0031); `sideby run` leaves it out. */
|
|
38
|
+
async function runAccount(rt, ref, args, io, opts = {}) {
|
|
39
|
+
return whileRunning(rt, () => runAccountNow(rt, ref, args, io, opts));
|
|
38
40
|
}
|
|
39
|
-
async function runAccountNow(rt, ref, args, io) {
|
|
40
|
-
const handed = await runWithHandoff(rt, ref, args, {
|
|
41
|
-
err: (l) => io.err(c.dim(l)),
|
|
42
|
-
stdin: io.stdin ?? process.stdin,
|
|
43
|
-
});
|
|
41
|
+
async function runAccountNow(rt, ref, args, io, opts) {
|
|
42
|
+
const handed = await runWithHandoff(rt, ref, args, { err: (l) => io.err(c.dim(l)), stdin: io.stdin ?? process.stdin }, opts);
|
|
44
43
|
if (handed !== null)
|
|
45
44
|
return handed;
|
|
46
|
-
const prepared = await rt.prepareLaunch(ref, args, 'run');
|
|
45
|
+
const prepared = await rt.prepareLaunch(ref, args, 'run', opts);
|
|
47
46
|
if (prepared.notice)
|
|
48
47
|
io.err(c.cyan(prepared.notice));
|
|
49
48
|
const code = await runHost(prepared);
|
|
@@ -336,8 +335,13 @@ export async function cmdNew(a, io) {
|
|
|
336
335
|
api: a.flags.has('api'),
|
|
337
336
|
...(alias !== undefined ? { alias } : {}),
|
|
338
337
|
});
|
|
338
|
+
const pickOffer = await pickOfferAfterNew(rt, res.account);
|
|
339
339
|
if (a.flags.has('json')) {
|
|
340
|
-
json(io,
|
|
340
|
+
json(io, {
|
|
341
|
+
...res,
|
|
342
|
+
...(suggestion ? { suggestion } : {}),
|
|
343
|
+
...(pickOffer ? { pickCommandOffer: pickOffer } : {}),
|
|
344
|
+
});
|
|
341
345
|
return res.ok ? 0 : 1;
|
|
342
346
|
}
|
|
343
347
|
if (suggestion?.aliasProblem)
|
|
@@ -365,8 +369,29 @@ export async function cmdNew(a, io) {
|
|
|
365
369
|
io.out('\nNext:');
|
|
366
370
|
for (const n of res.nextSteps)
|
|
367
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.`));
|
|
368
374
|
return res.ok ? 0 : 1;
|
|
369
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
|
+
}
|
|
370
395
|
function printShellInitWrites(io, files, home) {
|
|
371
396
|
for (const f of files) {
|
|
372
397
|
const path = f.path.startsWith('/') ? tildify(f.path, home) : f.path;
|
|
@@ -383,6 +408,8 @@ export async function cmdRun(a, io, command) {
|
|
|
383
408
|
if (command === 'login' && (extra.length || a.rest.length))
|
|
384
409
|
throw new UsageError('login takes no extra arguments');
|
|
385
410
|
const rt = await createRuntime();
|
|
411
|
+
if (command === 'run' && rt.pickCommandFamily(ref) !== undefined)
|
|
412
|
+
return runPick(rt, ref, [...extra, ...a.rest], io);
|
|
386
413
|
if (command === 'run')
|
|
387
414
|
return runAccount(rt, ref, [...extra, ...a.rest], io);
|
|
388
415
|
const prepared = await rt.prepareLaunch(ref, [...extra, ...a.rest], command);
|
|
@@ -390,6 +417,24 @@ export async function cmdRun(a, io, command) {
|
|
|
390
417
|
io.err(c.cyan(prepared.notice));
|
|
391
418
|
return whileRunning(rt, () => runHost(prepared));
|
|
392
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
|
+
}
|
|
393
438
|
/**
|
|
394
439
|
* `sideby resume <family>`: what the Host-named shell function calls (spec §3.15). Starts the Account that holds the
|
|
395
440
|
* session the arguments resume by id, a new session where a never-saved one started (ADR-0009), or the Host unchanged.
|
|
@@ -1167,6 +1212,8 @@ export async function cmdPlugins(a, io) {
|
|
|
1167
1212
|
return rt.pluginErrors.length ? 1 : 0;
|
|
1168
1213
|
}
|
|
1169
1214
|
export async function cmdShellInit(a, io) {
|
|
1215
|
+
if (a.positionals[0] === 'setup')
|
|
1216
|
+
return cmdShellSetup(a, io);
|
|
1170
1217
|
const shell = a.positionals[0];
|
|
1171
1218
|
const write = a.flags.has('write');
|
|
1172
1219
|
const usage = 'usage: sideby shell-init zsh|bash | sideby shell-init [zsh|bash] --write';
|
|
@@ -1188,6 +1235,51 @@ export async function cmdShellInit(a, io) {
|
|
|
1188
1235
|
printShellInitWrites(io, files, rt.paths.home);
|
|
1189
1236
|
return files.every((f) => f.ok) ? 0 : 1;
|
|
1190
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
|
+
}
|
|
1191
1283
|
/** Absolute path of this CLI's entry (`main.ts` from source, `main.js` from dist), for detached processes. */
|
|
1192
1284
|
function cliEntry() {
|
|
1193
1285
|
const ext = import.meta.url.endsWith('.ts') ? 'ts' : 'js';
|
|
@@ -1257,13 +1349,73 @@ export async function cmdUi(a, io) {
|
|
|
1257
1349
|
});
|
|
1258
1350
|
return 0;
|
|
1259
1351
|
}
|
|
1352
|
+
/**
|
|
1353
|
+
* `sideby update --skill [--yes] [--json]` (spec §3.23): only the installed sideby skill, toward this version. It
|
|
1354
|
+
* never installs the CLI, also when a newer one exists (it says that update is separate), and asks no registry. The
|
|
1355
|
+
* new code runs it after an install, so a registry that moved meanwhile never installs a version nobody confirmed.
|
|
1356
|
+
*/
|
|
1357
|
+
async function cmdUpdateSkill(a, io) {
|
|
1358
|
+
if (a.positionals.length || a.rest.length)
|
|
1359
|
+
throw new UsageError('usage: sideby update --skill [--yes] [--json]');
|
|
1360
|
+
const u = await import('../core/update.js');
|
|
1361
|
+
const { SKILL_INSTALL } = await import('../core/skill-check.js');
|
|
1362
|
+
const paths = resolvePaths(process.env);
|
|
1363
|
+
const asJson = a.flags.has('json');
|
|
1364
|
+
const plan = await u.planSkillUpdate(paths, process.env);
|
|
1365
|
+
const shown = u.shownPlan(plan);
|
|
1366
|
+
const sk = plan.skill;
|
|
1367
|
+
// The skills tool fetches the newest skill, so a newer CLI should follow; that stays the user's own step.
|
|
1368
|
+
const cliLine = () => {
|
|
1369
|
+
if (plan.available)
|
|
1370
|
+
io.out(c.cyan(`sideby ${plan.latest} is available; updating sideby itself is separate: \`sideby update\`.`));
|
|
1371
|
+
};
|
|
1372
|
+
if (!sk?.outdated || !sk.canRun) {
|
|
1373
|
+
if (asJson)
|
|
1374
|
+
json(io, { ...shown, updated: false });
|
|
1375
|
+
else {
|
|
1376
|
+
if (!sk)
|
|
1377
|
+
io.out(`No sideby skill is installed. To install it: ${SKILL_INSTALL}`);
|
|
1378
|
+
else if (!sk.outdated)
|
|
1379
|
+
io.out(`${c.green('✓')} The sideby skill is already for sideby ${plan.current}.`);
|
|
1380
|
+
else
|
|
1381
|
+
io.out(c.yellow(`The sideby skill is not updated by sideby: ${sk.reason}.\n ${sk.command}`));
|
|
1382
|
+
cliLine();
|
|
1383
|
+
}
|
|
1384
|
+
return 0;
|
|
1385
|
+
}
|
|
1386
|
+
if (!a.flags.has('yes')) {
|
|
1387
|
+
if (asJson)
|
|
1388
|
+
json(io, { ...shown, updated: false });
|
|
1389
|
+
else {
|
|
1390
|
+
const from = sk.installed.map((v) => v ?? 'no version').join(', ');
|
|
1391
|
+
io.out(`Updating the sideby skill (for ${from}) to sideby ${plan.current} runs:\n ${sk.command}`);
|
|
1392
|
+
cliLine();
|
|
1393
|
+
io.out(c.cyan('\nRun it with `sideby update --skill --yes`.'));
|
|
1394
|
+
}
|
|
1395
|
+
return 10;
|
|
1396
|
+
}
|
|
1397
|
+
if (!asJson)
|
|
1398
|
+
io.out(c.dim(`$ ${sk.command}`));
|
|
1399
|
+
const r = await u.applySkillOnly(paths, sk, process.env, asJson ? undefined : (t) => process.stderr.write(t));
|
|
1400
|
+
if (asJson)
|
|
1401
|
+
json(io, { ...shown, updated: false, skillUpdated: r?.ok ?? false, message: r?.message ?? '' });
|
|
1402
|
+
else {
|
|
1403
|
+
if (r?.ok)
|
|
1404
|
+
io.out(`${c.green('✓')} ${r.message}; agents load it in their next session.`);
|
|
1405
|
+
else
|
|
1406
|
+
io.err(c.red(`✗ ${r?.message}`));
|
|
1407
|
+
cliLine();
|
|
1408
|
+
}
|
|
1409
|
+
return r?.ok ? 0 : 1;
|
|
1410
|
+
}
|
|
1260
1411
|
/**
|
|
1261
1412
|
* `sideby update [--yes] [--json]` (spec §3.23): asks the registry now, shows what an Update runs, and runs it with
|
|
1262
|
-
* `--yes` (exit 10 before). An install sideby cannot update gets the command to run and exit 1.
|
|
1413
|
+
* `--yes` (exit 10 before). An install sideby cannot update gets the command to run and exit 1. `--skill` updates the
|
|
1414
|
+
* skill alone (cmdUpdateSkill).
|
|
1263
1415
|
*/
|
|
1264
1416
|
export async function cmdUpdate(a, io) {
|
|
1265
1417
|
if (a.positionals.length)
|
|
1266
|
-
throw new UsageError('usage: sideby update [--yes] [--json]');
|
|
1418
|
+
throw new UsageError('usage: sideby update [--skill] [--yes] [--json]');
|
|
1267
1419
|
if (a.flags.has('auto')) {
|
|
1268
1420
|
if (a.rest.length)
|
|
1269
1421
|
throw new UsageError('usage: sideby update --auto on|off [--json]');
|
|
@@ -1276,6 +1428,8 @@ export async function cmdUpdate(a, io) {
|
|
|
1276
1428
|
io.out(`Auto Update ${auto ? 'on' : 'off'}${r.changed ? '.' : ' (unchanged).'}`);
|
|
1277
1429
|
return 0;
|
|
1278
1430
|
}
|
|
1431
|
+
if (a.flags.has('skill'))
|
|
1432
|
+
return cmdUpdateSkill(a, io);
|
|
1279
1433
|
const u = await import('../core/update.js');
|
|
1280
1434
|
const { SKILL_INSTALL } = await import('../core/skill-check.js');
|
|
1281
1435
|
const { backgroundPanelPort } = await import('../panel/background.js');
|
|
@@ -1566,6 +1720,28 @@ export async function cmdDesktop(a, io) {
|
|
|
1566
1720
|
io.err(c.cyan(n));
|
|
1567
1721
|
return 0;
|
|
1568
1722
|
}
|
|
1723
|
+
/** `sideby edit <account> [--path]`: the Account's Host settings file in the user's editor (spec §3.30, ADR-0033). */
|
|
1724
|
+
export async function cmdEdit(a, io) {
|
|
1725
|
+
const [ref, ...extra] = a.positionals;
|
|
1726
|
+
if (!ref || extra.length || a.rest.length)
|
|
1727
|
+
throw new UsageError('usage: sideby edit <account> [--path]');
|
|
1728
|
+
const rt = await createRuntime();
|
|
1729
|
+
const r = await editSettings(rt, ref, { open: !a.flags.has('path') });
|
|
1730
|
+
if (a.flags.has('json')) {
|
|
1731
|
+
json(io, r);
|
|
1732
|
+
return 0;
|
|
1733
|
+
}
|
|
1734
|
+
const home = rt.paths.home;
|
|
1735
|
+
if (!r.opened)
|
|
1736
|
+
io.out(r.target ?? r.path);
|
|
1737
|
+
else
|
|
1738
|
+
io.out(`${c.green('✓')} opened ${c.bold(r.ref)}'s ${r.file} with your default program`);
|
|
1739
|
+
if (r.opened || r.target)
|
|
1740
|
+
io.out(c.dim(` ${tildify(r.target ?? r.path, home)}${r.target ? ` (linked from ${tildify(r.path, home)})` : ''}`));
|
|
1741
|
+
if (r.sharedWith.length)
|
|
1742
|
+
io.out(c.dim(` shared: a change also applies to ${r.sharedWith.join(', ')}`));
|
|
1743
|
+
return 0;
|
|
1744
|
+
}
|
|
1569
1745
|
/** `sideby browser [--enable|--disable] [--yes]` and `sideby browser open <account> [--profile <p>]` (spec §3.24). */
|
|
1570
1746
|
export async function cmdBrowser(a, io) {
|
|
1571
1747
|
const [sub, ref, ...extra] = a.positionals;
|
|
@@ -1645,28 +1821,79 @@ export async function cmdBrowser(a, io) {
|
|
|
1645
1821
|
}
|
|
1646
1822
|
export async function cmdAlias(a, io) {
|
|
1647
1823
|
const [sub, alias, target, ...more] = a.positionals;
|
|
1648
|
-
const usage = 'usage: sideby alias add <short-command> <account> [-- host args] | sideby alias rm <short-command>';
|
|
1649
|
-
const
|
|
1650
|
-
|
|
1651
|
-
|
|
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)
|
|
1652
1832
|
throw new UsageError(usage);
|
|
1653
1833
|
const rt = await createRuntime();
|
|
1654
|
-
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);
|
|
1655
1839
|
if (a.flags.has('json')) {
|
|
1656
1840
|
json(io, res);
|
|
1657
|
-
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;
|
|
1658
1850
|
}
|
|
1659
|
-
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';
|
|
1660
1857
|
const said = {
|
|
1661
|
-
added: `${c.green('✓')}
|
|
1662
|
-
exists: `${c.green('✓')}
|
|
1663
|
-
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}`,
|
|
1664
1861
|
absent: `${c.dim('·')} no short command ${res.alias} in the config; nothing to remove`,
|
|
1665
1862
|
};
|
|
1666
1863
|
io.out(said[res.status]);
|
|
1667
1864
|
printShellInitWrites(io, res.shellInitFiles ?? [], rt.paths.home);
|
|
1668
1865
|
return res.ok ? 0 : 1;
|
|
1669
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
|
+
}
|
|
1670
1897
|
/** `sideby families [family]`: each Family's layout, sign-in and Shared Items, from its FamilyDef (spec §3.16). */
|
|
1671
1898
|
export async function cmdFamilies(a, io) {
|
|
1672
1899
|
const [only, ...extra] = a.positionals;
|
|
@@ -1702,7 +1929,7 @@ export async function cmdFamilies(a, io) {
|
|
|
1702
1929
|
}
|
|
1703
1930
|
/** AI Task CLI; the terminal receives only an opaque task id. */
|
|
1704
1931
|
export async function cmdAsk(a, io, runtime) {
|
|
1705
|
-
const { previewAttachments, promptForTask, readTask, startAiTask, taskEnv, taskHostArgs, taskStateDir } = await import('../core/ask.js');
|
|
1932
|
+
const { movedCwdError, previewAttachments, promptForTask, readTask, realCwdInHome, startAiTask, taskEnv, taskHostArgs, taskStateDir, } = await import('../core/ask.js');
|
|
1706
1933
|
const run = a.flags.get('run');
|
|
1707
1934
|
if (typeof run === 'string') {
|
|
1708
1935
|
const stateDir = a.flags.get('state-dir');
|
|
@@ -1722,9 +1949,29 @@ export async function cmdAsk(a, io, runtime) {
|
|
|
1722
1949
|
: (runtime ?? (await createRuntime()));
|
|
1723
1950
|
const cwd = process.cwd();
|
|
1724
1951
|
try {
|
|
1725
|
-
|
|
1952
|
+
try {
|
|
1953
|
+
process.chdir(task.cwd);
|
|
1954
|
+
}
|
|
1955
|
+
catch (err) {
|
|
1956
|
+
if (task.cwdInHome)
|
|
1957
|
+
throw movedCwdError('does not exist');
|
|
1958
|
+
throw err;
|
|
1959
|
+
}
|
|
1960
|
+
// A Portal's folder is checked where the process now is, so a link swapped in after the task was written is
|
|
1961
|
+
// caught, and the folder cannot change between the check and the Host start.
|
|
1962
|
+
if (task.cwdInHome) {
|
|
1963
|
+
const now = await realCwdInHome(process.cwd(), task.home ?? rt.paths.home);
|
|
1964
|
+
if ('why' in now)
|
|
1965
|
+
throw movedCwdError(now.why);
|
|
1966
|
+
if (now.real !== task.cwd)
|
|
1967
|
+
throw movedCwdError('points somewhere else');
|
|
1968
|
+
}
|
|
1726
1969
|
if (task.kind === 'prompt')
|
|
1727
|
-
return await runAccount(rt, task.account, await taskHostArgs(rt, task), io);
|
|
1970
|
+
return await runAccount(rt, task.account, await taskHostArgs(rt, task), io, { aiTask: true });
|
|
1971
|
+
if (task.kind === 'run')
|
|
1972
|
+
return rt.pickCommandFamily(task.account) !== undefined
|
|
1973
|
+
? await runPick(rt, task.account, [], io)
|
|
1974
|
+
: await runAccount(rt, task.account, [], io);
|
|
1728
1975
|
const prepared = await rt.prepareLaunch(task.account, [], 'login');
|
|
1729
1976
|
if (prepared.notice)
|
|
1730
1977
|
io.err(prepared.notice);
|
|
@@ -1734,6 +1981,8 @@ export async function cmdAsk(a, io, runtime) {
|
|
|
1734
1981
|
process.chdir(cwd);
|
|
1735
1982
|
}
|
|
1736
1983
|
}
|
|
1984
|
+
if (a.flags.has('spec') || a.flags.has('choices'))
|
|
1985
|
+
return cmdAskSpec(a, io, runtime);
|
|
1737
1986
|
const rt = runtime ?? (await createRuntime());
|
|
1738
1987
|
const task = String(a.flags.get('task') ?? 'free');
|
|
1739
1988
|
if (!AI_TASK_KINDS.includes(task))
|
|
@@ -1760,13 +2009,85 @@ export async function cmdAsk(a, io, runtime) {
|
|
|
1760
2009
|
if (a.flags.has('json'))
|
|
1761
2010
|
json(io, result);
|
|
1762
2011
|
else if (result.command)
|
|
1763
|
-
io.out(result.opened ?
|
|
2012
|
+
io.out(result.opened ? await openedLine(rt, result) : result.command);
|
|
1764
2013
|
else
|
|
1765
2014
|
io.out(result.prompt ?? preview.prompt);
|
|
1766
2015
|
if (!result.opened)
|
|
1767
2016
|
io.err(result.detail);
|
|
1768
2017
|
return result.opened ? 0 : 1;
|
|
1769
2018
|
}
|
|
2019
|
+
/** What `sideby ask` prints once the terminal opened; a Family with `aiTaskArgs` adds that its checks stay on. */
|
|
2020
|
+
async function openedLine(rt, result) {
|
|
2021
|
+
const line = `Opened ${result.terminal} for ${result.account}.`;
|
|
2022
|
+
const family = result.account
|
|
2023
|
+
? await rt.resolve(result.account).then((a) => rt.families.get(a.family), () => undefined)
|
|
2024
|
+
: undefined;
|
|
2025
|
+
return family?.aiTaskArgs
|
|
2026
|
+
? `${line} Its permission checks stay on, so risky actions are checked first.`
|
|
2027
|
+
: line;
|
|
2028
|
+
}
|
|
2029
|
+
/**
|
|
2030
|
+
* `sideby ask --spec - [--print]` and `sideby ask --choices` (ADR-0030): the AI Tasks a Portal starts. The Task Spec
|
|
2031
|
+
* comes on stdin, never through a shell. A refused spec exits 1 with its `code` (and `reason`, as the Portal reads
|
|
2032
|
+
* it), or 2 for a spec version this sideby does not know.
|
|
2033
|
+
*/
|
|
2034
|
+
async function cmdAskSpec(a, io, runtime) {
|
|
2035
|
+
const { previewTaskSpec, parseTaskSpec, readSpecText, SpecError, startTaskSpec, taskChoices } = await import('../core/task-spec.js');
|
|
2036
|
+
const choices = a.flags.has('choices');
|
|
2037
|
+
const allowed = choices ? ['choices', 'json'] : ['spec', 'print', 'json'];
|
|
2038
|
+
if (a.positionals.length ||
|
|
2039
|
+
a.rest.length ||
|
|
2040
|
+
a.attach?.length ||
|
|
2041
|
+
[...a.flags.keys()].some((f) => !allowed.includes(f)))
|
|
2042
|
+
throw new UsageError('Use `sideby ask --spec - [--print] --json` or `sideby ask --choices --json` on their own.');
|
|
2043
|
+
const rt = runtime ?? (await createRuntime());
|
|
2044
|
+
if (choices) {
|
|
2045
|
+
const result = await taskChoices(rt);
|
|
2046
|
+
if (a.flags.has('json'))
|
|
2047
|
+
json(io, result);
|
|
2048
|
+
else {
|
|
2049
|
+
io.out(result.account ? `Account: ${result.account}` : `No account: ${result.detail}`);
|
|
2050
|
+
io.out(`Terminal: ${result.terminal}`);
|
|
2051
|
+
}
|
|
2052
|
+
return 0;
|
|
2053
|
+
}
|
|
2054
|
+
if (a.flags.get('spec') !== '-')
|
|
2055
|
+
throw new UsageError('Pass the Task Spec on stdin: sideby ask --spec - --json');
|
|
2056
|
+
const stdin = io.stdin ?? process.stdin;
|
|
2057
|
+
if (stdin.isTTY)
|
|
2058
|
+
throw new UsageError('Pipe the Task Spec into stdin: sideby ask --spec - --json < spec.json');
|
|
2059
|
+
try {
|
|
2060
|
+
const spec = parseTaskSpec(await readSpecText(stdin));
|
|
2061
|
+
if (a.flags.has('print')) {
|
|
2062
|
+
const preview = await previewTaskSpec(rt, spec);
|
|
2063
|
+
if (a.flags.has('json'))
|
|
2064
|
+
json(io, preview);
|
|
2065
|
+
else
|
|
2066
|
+
io.out(preview.prompt);
|
|
2067
|
+
return 0;
|
|
2068
|
+
}
|
|
2069
|
+
const result = await startTaskSpec(rt, spec);
|
|
2070
|
+
if (a.flags.has('json'))
|
|
2071
|
+
json(io, result);
|
|
2072
|
+
else if (result.command)
|
|
2073
|
+
io.out(result.opened ? await openedLine(rt, result) : result.command);
|
|
2074
|
+
else
|
|
2075
|
+
io.out(result.prompt ?? '');
|
|
2076
|
+
if (!result.opened)
|
|
2077
|
+
io.err(result.detail);
|
|
2078
|
+
return result.opened ? 0 : 1;
|
|
2079
|
+
}
|
|
2080
|
+
catch (err) {
|
|
2081
|
+
// A folder that changed between the check and the task file is refused like a bad one.
|
|
2082
|
+
if (!(err instanceof SpecError) && !(err instanceof UserError && err.code === 'bad-cwd'))
|
|
2083
|
+
throw err;
|
|
2084
|
+
if (a.flags.has('json'))
|
|
2085
|
+
json(io, { schemaVersion: 1, error: err.message, code: err.code, reason: err.code });
|
|
2086
|
+
else
|
|
2087
|
+
io.err(`sideby: ${err.message}`);
|
|
2088
|
+
return err.code === 'spec-version' ? 2 : 1;
|
|
2089
|
+
}
|
|
2090
|
+
}
|
|
1770
2091
|
export async function cmdTerminal(a, io) {
|
|
1771
2092
|
const { terminals, setCustomTerminal, setPreferredTerminal } = await import('../core/ask.js');
|
|
1772
2093
|
const rt = await createRuntime();
|
|
@@ -2004,6 +2325,166 @@ export async function cmdAutostart(a, io) {
|
|
|
2004
2325
|
}
|
|
2005
2326
|
return 0;
|
|
2006
2327
|
}
|
|
2328
|
+
/** What the Menu Bar Item lists (spec §3.31): each Family's accounts in Display Order, with its Handoff ranking. */
|
|
2329
|
+
async function menubarFamilies(rt) {
|
|
2330
|
+
const accounts = displayOrdered(await rt.accounts(), rt);
|
|
2331
|
+
const ids = [...new Set(accounts.map((x) => x.family))];
|
|
2332
|
+
return Promise.all(ids.map(async (id) => {
|
|
2333
|
+
const f = rt.families.get(id);
|
|
2334
|
+
const plan = f.readQuota || f.fetchQuota ? await rt.handoff(id).catch(() => null) : null;
|
|
2335
|
+
const list = await Promise.all(accounts
|
|
2336
|
+
.filter((x) => x.family === id)
|
|
2337
|
+
.map(async (x) => ({
|
|
2338
|
+
ref: x.ref,
|
|
2339
|
+
name: x.name,
|
|
2340
|
+
kind: x.kind,
|
|
2341
|
+
login: x.kind === 'api' ? 'not-needed' : (await rt.status(x)).login,
|
|
2342
|
+
quota: await rt.quota(x),
|
|
2343
|
+
sameLogin: await rt.sameLogin(x),
|
|
2344
|
+
})));
|
|
2345
|
+
return { id, title: f.title, logo: f.logo ?? null, plan, accounts: list };
|
|
2346
|
+
}));
|
|
2347
|
+
}
|
|
2348
|
+
/**
|
|
2349
|
+
* `sideby menubar [on|off] [--yes]`, `menubar snapshot` and `menubar start <account>` (spec §3.31, ADR-0034): quota in
|
|
2350
|
+
* the macOS menu bar.
|
|
2351
|
+
*/
|
|
2352
|
+
export async function cmdMenubar(a, io) {
|
|
2353
|
+
const [action, extra] = a.positionals;
|
|
2354
|
+
const wantJson = a.flags.has('json');
|
|
2355
|
+
if (action === 'snapshot') {
|
|
2356
|
+
if (extra !== undefined)
|
|
2357
|
+
throw new UsageError('usage: sideby menubar snapshot [--lang en|zh] [--json]');
|
|
2358
|
+
const { menubarHotkey, menubarLang, menubarSnapshot } = await import('../menubar/snapshot.js');
|
|
2359
|
+
const rt = await createRuntime();
|
|
2360
|
+
const lang = menubarLang(rt.config.panel?.language, a.flags.get('lang') ?? rt.env.LANG);
|
|
2361
|
+
const snap = menubarSnapshot(await menubarFamilies(rt), rt.readContext().now, lang, menubarHotkey(rt.config.menubar?.hotkey));
|
|
2362
|
+
if (wantJson)
|
|
2363
|
+
json(io, snap);
|
|
2364
|
+
else {
|
|
2365
|
+
io.out(snap.title ? `${snap.title} ${c.dim(snap.tooltip)}` : snap.tooltip);
|
|
2366
|
+
const line = (r, indent) => io.out(`${indent}${r.label}${r.recommended ? ` (${snap.labels.recommended})` : ''} ${c.dim(r.detail)}`);
|
|
2367
|
+
for (const s of snap.sections) {
|
|
2368
|
+
io.out(c.bold(s.title));
|
|
2369
|
+
for (const r of s.rows)
|
|
2370
|
+
line(r, ' ');
|
|
2371
|
+
if (s.more) {
|
|
2372
|
+
io.out(` ${s.more.title}`);
|
|
2373
|
+
for (const r of s.more.rows)
|
|
2374
|
+
line(r, ' ');
|
|
2375
|
+
}
|
|
2376
|
+
}
|
|
2377
|
+
}
|
|
2378
|
+
return 0;
|
|
2379
|
+
}
|
|
2380
|
+
if (action === 'start') {
|
|
2381
|
+
if (!extra || a.positionals.length > 2)
|
|
2382
|
+
throw new UsageError('usage: sideby menubar start <account> [--json]');
|
|
2383
|
+
const { openRunInTerminal } = await import('../core/ask.js');
|
|
2384
|
+
const rt = await createRuntime();
|
|
2385
|
+
const r = await openRunInTerminal(rt, extra);
|
|
2386
|
+
if (wantJson)
|
|
2387
|
+
json(io, r);
|
|
2388
|
+
else
|
|
2389
|
+
io.out(r.opened ? `Opened ${r.terminal} for ${r.account}.` : r.command);
|
|
2390
|
+
if (!r.opened)
|
|
2391
|
+
io.err(r.detail);
|
|
2392
|
+
return r.opened ? 0 : 1;
|
|
2393
|
+
}
|
|
2394
|
+
const { applyAutostart, autostartStatus, planAutostart, refreshAutostart } = await import('../core/autostart.js');
|
|
2395
|
+
const { MENUBAR_AGENT } = await import('../menubar/agent.js');
|
|
2396
|
+
if (extra !== undefined || (action !== undefined && action !== 'on' && action !== 'off'))
|
|
2397
|
+
throw new UsageError('usage: sideby menubar [on|off] [--yes] [--json]');
|
|
2398
|
+
if (a.flags.has('yes') && !action)
|
|
2399
|
+
throw new UsageError('--yes needs a change: sideby menubar on|off --yes');
|
|
2400
|
+
const home = resolvePaths().home;
|
|
2401
|
+
const ctx = { home };
|
|
2402
|
+
if (a.flags.has('refresh')) {
|
|
2403
|
+
// After an update or a local build switch: point an existing agent at this sideby; never create one.
|
|
2404
|
+
const r = await refreshAutostart(ctx, MENUBAR_AGENT);
|
|
2405
|
+
const status = await autostartStatus(ctx, MENUBAR_AGENT);
|
|
2406
|
+
if (wantJson)
|
|
2407
|
+
json(io, {
|
|
2408
|
+
...status,
|
|
2409
|
+
path: tilde(status.path, home),
|
|
2410
|
+
changed: r.rewritten,
|
|
2411
|
+
...(r.note ? { note: r.note } : {}),
|
|
2412
|
+
});
|
|
2413
|
+
else
|
|
2414
|
+
io.out(r.rewritten ? 'The menu bar item now runs this sideby.' : (r.note ?? 'Nothing to change.'));
|
|
2415
|
+
return 0;
|
|
2416
|
+
}
|
|
2417
|
+
if (!action) {
|
|
2418
|
+
const s = await autostartStatus(ctx, MENUBAR_AGENT);
|
|
2419
|
+
if (wantJson)
|
|
2420
|
+
json(io, { ...s, path: tilde(s.path, home) });
|
|
2421
|
+
else if (!s.supported)
|
|
2422
|
+
io.out('The menu bar item is only available on macOS for now.');
|
|
2423
|
+
else if (s.state === 'off')
|
|
2424
|
+
io.out('Menu bar item: off. Run `sideby menubar on` to show quota in the menu bar.');
|
|
2425
|
+
else if (s.state === 'foreign')
|
|
2426
|
+
io.out(`${tilde(s.path, home)} is not sideby's, so sideby leaves it alone; remove or rename it yourself if it is not needed.`);
|
|
2427
|
+
else if (s.state === 'stale')
|
|
2428
|
+
io.out('Menu bar item: points to a sideby or Node that is no longer there. Run `sideby menubar on` to fix it.');
|
|
2429
|
+
else {
|
|
2430
|
+
io.out('Menu bar item: on.');
|
|
2431
|
+
if (!s.current)
|
|
2432
|
+
io.out(c.dim('It runs another sideby than this one; `sideby menubar on` points it here.'));
|
|
2433
|
+
io.out(c.dim('Turn it off: sideby menubar off'));
|
|
2434
|
+
}
|
|
2435
|
+
return 0;
|
|
2436
|
+
}
|
|
2437
|
+
const plan = await planAutostart(ctx, action, MENUBAR_AGENT);
|
|
2438
|
+
if (plan.blocked)
|
|
2439
|
+
throw new UserError(plan.blocked.code === 'unsupported'
|
|
2440
|
+
? 'The menu bar item is only available on macOS for now.'
|
|
2441
|
+
: plan.blocked.message, { code: plan.blocked.code });
|
|
2442
|
+
const shown = {
|
|
2443
|
+
...plan.status,
|
|
2444
|
+
path: tilde(plan.path, home),
|
|
2445
|
+
action,
|
|
2446
|
+
changed: plan.changed,
|
|
2447
|
+
applied: false,
|
|
2448
|
+
...(plan.content ? { content: plan.content } : {}),
|
|
2449
|
+
...(plan.programArguments ? { programArguments: plan.programArguments } : {}),
|
|
2450
|
+
commands: plan.commands,
|
|
2451
|
+
};
|
|
2452
|
+
if (!plan.changed) {
|
|
2453
|
+
if (wantJson)
|
|
2454
|
+
json(io, shown);
|
|
2455
|
+
else
|
|
2456
|
+
io.out(action === 'on' ? 'Already on.' : 'Already off.');
|
|
2457
|
+
return 0;
|
|
2458
|
+
}
|
|
2459
|
+
const path = tilde(plan.path, home);
|
|
2460
|
+
if (!a.flags.has('yes')) {
|
|
2461
|
+
// The file holds the whole menu bar script, so only its path is printed; `--json` carries the content.
|
|
2462
|
+
if (wantJson)
|
|
2463
|
+
json(io, shown);
|
|
2464
|
+
else
|
|
2465
|
+
io.out(action === 'on'
|
|
2466
|
+
? `This adds a login item at ${path} that shows your quota in the menu bar and starts at login. Run \`sideby menubar on --yes\` to turn it on.`
|
|
2467
|
+
: `This removes ${path} and hides the menu bar item. Run \`sideby menubar off --yes\` to turn it off.`);
|
|
2468
|
+
return 10;
|
|
2469
|
+
}
|
|
2470
|
+
const r = await applyAutostart(ctx, plan, MENUBAR_AGENT);
|
|
2471
|
+
if (wantJson)
|
|
2472
|
+
json(io, {
|
|
2473
|
+
...shown,
|
|
2474
|
+
state: r.state,
|
|
2475
|
+
applied: true,
|
|
2476
|
+
loaded: r.loaded,
|
|
2477
|
+
...(r.note ? { note: r.note } : {}),
|
|
2478
|
+
});
|
|
2479
|
+
else {
|
|
2480
|
+
io.out(action === 'on'
|
|
2481
|
+
? 'The menu bar item is on and in your menu bar now. To turn it off later, run `sideby menubar off`.'
|
|
2482
|
+
: 'The menu bar item is off. Run `sideby menubar on` to turn it on again.');
|
|
2483
|
+
if (r.note)
|
|
2484
|
+
io.out(c.dim(r.note));
|
|
2485
|
+
}
|
|
2486
|
+
return 0;
|
|
2487
|
+
}
|
|
2007
2488
|
/** The `accounts.<ref>.args` check of `sideby config set`: only the model and effort arguments, as `sideby model`. */
|
|
2008
2489
|
function modelArgsProblem(rt) {
|
|
2009
2490
|
return (ref, args) => {
|