sideby 0.21.0 → 0.23.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 +1 -0
- package/ai-tasks.json +14 -0
- package/dist/build.json +1 -1
- package/dist/src/cli/commands.d.ts +7 -0
- package/dist/src/cli/commands.js +441 -31
- package/dist/src/cli/format.js +3 -2
- package/dist/src/cli/json-schemas.js +157 -47
- package/dist/src/cli/main.js +38 -7
- package/dist/src/core/accounts.d.ts +6 -1
- package/dist/src/core/accounts.js +16 -3
- package/dist/src/core/ask.d.ts +2 -1
- package/dist/src/core/ask.js +12 -4
- package/dist/src/core/claude-settings-file.d.ts +57 -0
- package/dist/src/core/claude-settings-file.js +104 -2
- package/dist/src/core/config.d.ts +34 -16
- package/dist/src/core/config.js +58 -5
- package/dist/src/core/create.js +4 -1
- package/dist/src/core/desktop-app.js +5 -1
- package/dist/src/core/handoff-overview.d.ts +4 -1
- package/dist/src/core/handoff-overview.js +3 -2
- package/dist/src/core/handoff-rules.d.ts +34 -0
- package/dist/src/core/handoff-rules.js +115 -0
- package/dist/src/core/handoff-select.js +45 -28
- package/dist/src/core/handoff-status.d.ts +37 -7
- package/dist/src/core/handoff-status.js +95 -19
- package/dist/src/core/handoff.d.ts +4 -1
- package/dist/src/core/handoff.js +8 -5
- package/dist/src/core/inbound.d.ts +11 -3
- package/dist/src/core/inbound.js +26 -74
- package/dist/src/core/launch.js +6 -4
- package/dist/src/core/quota-levels.d.ts +13 -2
- package/dist/src/core/quota-levels.js +21 -3
- package/dist/src/core/remote-control.d.ts +10 -12
- package/dist/src/core/remote-control.js +29 -86
- package/dist/src/core/themes.d.ts +107 -0
- package/dist/src/core/themes.js +463 -0
- package/dist/src/core/tuning-apply.js +12 -20
- package/dist/src/families/agy/index.d.ts +8 -0
- package/dist/src/families/agy/index.js +53 -0
- package/dist/src/families/agy/quota.d.ts +9 -0
- package/dist/src/families/agy/quota.js +110 -0
- package/dist/src/families/index.js +7 -0
- package/dist/src/families/logos.d.ts +10 -0
- package/dist/src/families/logos.js +12 -1
- package/dist/src/menubar/script.js +26 -3
- package/dist/src/menubar/snapshot.d.ts +33 -6
- package/dist/src/menubar/snapshot.js +138 -43
- package/dist/src/menubar/strings.d.ts +18 -2
- package/dist/src/menubar/strings.js +18 -2
- package/dist/src/panel/handler.d.ts +4 -1
- package/dist/src/panel/handler.js +206 -46
- package/dist/src/panel/i18n.d.ts +106 -7
- package/dist/src/panel/i18n.js +260 -62
- package/dist/src/panel/page-logic.d.ts +67 -20
- package/dist/src/panel/page-logic.js +74 -7
- package/dist/src/panel/page-script.js +522 -124
- package/dist/src/panel/page-styles.d.ts +2 -0
- package/dist/src/panel/page-styles.js +157 -34
- package/dist/src/panel/page.js +3 -3
- package/dist/src/panel/theme.d.ts +6 -1
- package/dist/src/panel/theme.js +4 -0
- package/dist/src/panel/themes.d.ts +14 -0
- package/dist/src/panel/themes.js +162 -0
- package/dist/src/plugins/check.js +27 -13
- package/dist/src/plugins/loader.d.ts +11 -0
- package/dist/src/plugins/loader.js +47 -1
- package/dist/src/runtime.d.ts +9 -2
- package/dist/src/runtime.js +12 -5
- package/dist/src/types.d.ts +35 -5
- package/package.json +2 -2
- package/schemas/config.json +45 -2
- package/schemas/families.json +13 -5
- package/schemas/handoff-disable.json +22 -0
- package/schemas/handoff-enable.json +22 -0
- package/schemas/handoff-rules.json +302 -0
- package/schemas/handoff-status.json +26 -0
- package/schemas/hide.json +157 -0
- package/schemas/list.json +15 -0
- package/schemas/menubar-snapshot.json +309 -2
- package/schemas/order.json +26 -1
- package/schemas/pin.json +17 -0
- package/schemas/theme-check.json +140 -0
- package/schemas/theme-export.json +86 -0
- package/schemas/theme-import.json +92 -0
- package/schemas/theme-preview.json +86 -0
- package/schemas/theme-remove.json +87 -0
- package/schemas/theme-use.json +88 -0
- package/schemas/theme.json +137 -0
- package/schemas/unhide.json +157 -0
- package/schemas/unpin.json +17 -0
- package/skills/sideby/SKILL.md +5 -2
- package/skills/sideby/references/accounts.md +1 -0
- package/skills/sideby/references/ai-tasks.md +1 -1
- package/skills/sideby/references/handoff.md +7 -3
- package/skills/sideby/references/panel.md +9 -0
- package/skills/sideby/references/quota.md +3 -1
- package/skills/sideby/references/themes.md +47 -0
package/dist/src/cli/commands.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { stat, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { basename, join, resolve } from 'node:path';
|
|
1
3
|
import { StringDecoder } from 'node:string_decoder';
|
|
2
4
|
import { fileURLToPath } from 'node:url';
|
|
3
5
|
import { aliasesByAccount } from '../core/accounts.js';
|
|
@@ -9,17 +11,18 @@ import { editSettings } from '../core/edit-settings.js';
|
|
|
9
11
|
import { UserError } from '../core/errors.js';
|
|
10
12
|
import { requestHandoff } from '../core/handoff-chain.js';
|
|
11
13
|
import { handoffOverview } from '../core/handoff-overview.js';
|
|
14
|
+
import { handoffRulesView } from '../core/handoff-rules.js';
|
|
12
15
|
import { explain, readyDecision, runWithHandoff } from '../core/handoff-run.js';
|
|
13
|
-
import { configureHandoff, handoffHint, handoffStatus } from '../core/handoff-status.js';
|
|
16
|
+
import { checkHandoffRefs, configureHandoff, handoffHint, handoffRefs, handoffStatus, } from '../core/handoff-status.js';
|
|
14
17
|
import { installHint, runHost } from '../core/launch.js';
|
|
15
18
|
import { loginAfterLine, loginBeforeLine } from '../core/login-check.js';
|
|
16
19
|
import { accountModel, setAccountModel } from '../core/model-choice.js';
|
|
17
20
|
import { resolvePaths, tildify } from '../core/paths.js';
|
|
18
21
|
import { USAGE_DAYS } from '../core/quota-levels.js';
|
|
19
|
-
import {
|
|
22
|
+
import { groupsToUndo, remoteControlNothingToDo, remoteControlTodo, } from '../core/remote-control.js';
|
|
20
23
|
import { SHELLS } from '../core/shell-init.js';
|
|
21
24
|
import { MODEL_NAME } from '../families/shared/model-args.js';
|
|
22
|
-
import { AI_TASK_KINDS, inDisplayOrder, pinnedIn, suggestAlias, suggestName, withPinned, } from '../panel/page-logic.js';
|
|
25
|
+
import { AI_TASK_KINDS, hiddenIn, inDisplayOrder, pinnedIn, suggestAlias, suggestName, withPinned, } from '../panel/page-logic.js';
|
|
23
26
|
import { createRuntime, UnknownFamilyError } from '../runtime.js';
|
|
24
27
|
import { UsageError } from './args.js';
|
|
25
28
|
import { c, clock, compactNumber, quotaText, table, truncate, tuningLines, usageText } from './format.js';
|
|
@@ -106,6 +109,8 @@ function cleanDisplay(rt, groups) {
|
|
|
106
109
|
families: d.families?.filter((id) => groups.has(id)),
|
|
107
110
|
accounts: clean(d.accounts),
|
|
108
111
|
pinned: clean(d.pinned),
|
|
112
|
+
hiddenFamilies: d.hiddenFamilies?.filter((id) => groups.has(id)),
|
|
113
|
+
hidden: clean(d.hidden),
|
|
109
114
|
};
|
|
110
115
|
}
|
|
111
116
|
export async function cmdPin(a, io, pin) {
|
|
@@ -147,6 +152,60 @@ export async function cmdPin(a, io, pin) {
|
|
|
147
152
|
io.out(`${account.ref}: ${message}`);
|
|
148
153
|
return 0;
|
|
149
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* `sideby hide|unhide <family|account>` (spec §3.25): takes a Family, or an Account with the other directories of its
|
|
157
|
+
* Same Login, out of the lists or puts it back. Display only.
|
|
158
|
+
*/
|
|
159
|
+
export async function cmdHide(a, io, hide) {
|
|
160
|
+
if (a.positionals.length !== 1 || a.rest.length)
|
|
161
|
+
throw new UsageError('usage: sideby hide|unhide <family|account|short command> [--json]');
|
|
162
|
+
const rt = await createRuntime();
|
|
163
|
+
const target = a.positionals[0];
|
|
164
|
+
const accounts = await rt.accounts();
|
|
165
|
+
const d = cleanDisplay(rt, await orderGroups(rt, accounts));
|
|
166
|
+
let kind;
|
|
167
|
+
let ref;
|
|
168
|
+
let already;
|
|
169
|
+
if (rt.families.has(target)) {
|
|
170
|
+
kind = 'family';
|
|
171
|
+
ref = target;
|
|
172
|
+
const list = d.hiddenFamilies ?? [];
|
|
173
|
+
already = list.includes(target);
|
|
174
|
+
d.hiddenFamilies = hide ? (already ? list : [...list, target]) : list.filter((id) => id !== target);
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
kind = 'account';
|
|
178
|
+
const account = await rt.resolve(target);
|
|
179
|
+
ref = account.ref;
|
|
180
|
+
const peers = new Set([account.ref, ...(await rt.sameLogin(account))]);
|
|
181
|
+
const names = accounts.filter((x) => peers.has(x.ref)).map((x) => x.name);
|
|
182
|
+
const list = d.hidden?.[account.family] ?? [];
|
|
183
|
+
already = names.some((name) => list.includes(name));
|
|
184
|
+
d.hidden = {
|
|
185
|
+
...d.hidden,
|
|
186
|
+
[account.family]: hide
|
|
187
|
+
? [...list, ...names.filter((name) => !list.includes(name))]
|
|
188
|
+
: list.filter((name) => !names.includes(name)),
|
|
189
|
+
};
|
|
190
|
+
if (!hide && !already && d.hiddenFamilies?.includes(account.family))
|
|
191
|
+
throw new UserError(`All of ${account.family} is hidden, not just ${account.ref}; run sideby unhide ${account.family} to show the family again.`);
|
|
192
|
+
}
|
|
193
|
+
const before = JSON.stringify(rt.displayOrder());
|
|
194
|
+
const display = await rt.setDisplayOrder(d);
|
|
195
|
+
const changed = before !== JSON.stringify(display);
|
|
196
|
+
const message = hide
|
|
197
|
+
? already
|
|
198
|
+
? 'Already hidden.'
|
|
199
|
+
: `Hidden from the Panel, the menu bar and sideby list; it can still be started. sideby unhide ${ref} shows it again.`
|
|
200
|
+
: already
|
|
201
|
+
? 'Shown again.'
|
|
202
|
+
: 'Not hidden; nothing to change.';
|
|
203
|
+
if (a.flags.has('json'))
|
|
204
|
+
json(io, { target: ref, kind, hidden: hide, changed, message, display });
|
|
205
|
+
else
|
|
206
|
+
io.out(`${ref}: ${message}`);
|
|
207
|
+
return 0;
|
|
208
|
+
}
|
|
150
209
|
export async function cmdOrder(a, io) {
|
|
151
210
|
const reset = a.flags.has('reset');
|
|
152
211
|
const families = a.flags.has('families');
|
|
@@ -161,7 +220,7 @@ export async function cmdOrder(a, io) {
|
|
|
161
220
|
const groups = await orderGroups(rt, accounts);
|
|
162
221
|
let d = cleanDisplay(rt, groups);
|
|
163
222
|
if (reset)
|
|
164
|
-
d = { pinned: d.pinned };
|
|
223
|
+
d = { pinned: d.pinned, hiddenFamilies: d.hiddenFamilies, hidden: d.hidden };
|
|
165
224
|
else {
|
|
166
225
|
const [id, ...names] = a.positionals;
|
|
167
226
|
const requested = families ? a.positionals : names;
|
|
@@ -186,6 +245,7 @@ export async function cmdOrder(a, io) {
|
|
|
186
245
|
const groups = await orderGroups(rt, accounts);
|
|
187
246
|
const rows = inDisplayOrder([...groups.keys()], (id) => id, display.families).map((family) => ({
|
|
188
247
|
family,
|
|
248
|
+
hidden: display.hiddenFamilies?.includes(family) ?? false,
|
|
189
249
|
accounts: rt.families.has(family)
|
|
190
250
|
? ordered
|
|
191
251
|
.filter((x) => x.family === family)
|
|
@@ -193,18 +253,20 @@ export async function cmdOrder(a, io) {
|
|
|
193
253
|
name: x.name,
|
|
194
254
|
ref: x.ref,
|
|
195
255
|
pinned: display.pinned?.[family]?.includes(x.name) ?? false,
|
|
256
|
+
hidden: hiddenIn(x, display),
|
|
196
257
|
}))
|
|
197
258
|
: inDisplayOrder(groups.get(family) ?? [], (n) => n, display.accounts?.[family]).map((name) => ({
|
|
198
259
|
name,
|
|
199
260
|
ref: `${family}:${name}`,
|
|
200
261
|
pinned: false,
|
|
262
|
+
hidden: hiddenIn({ family, name }, display),
|
|
201
263
|
})),
|
|
202
264
|
}));
|
|
203
265
|
if (a.flags.has('json'))
|
|
204
266
|
json(io, { display, families: rows });
|
|
205
267
|
else
|
|
206
268
|
for (const row of rows)
|
|
207
|
-
io.out(`${row.family}: ${row.accounts.map((x) => `${x.name}${x.pinned ? ' (pinned)' : ''}`).join(', ') || '(no accounts)'}`);
|
|
269
|
+
io.out(`${row.family}${row.hidden ? ' (hidden)' : ''}: ${row.accounts.map((x) => `${x.name}${x.pinned ? ' (pinned)' : ''}${x.hidden && !row.hidden ? ' (hidden)' : ''}`).join(', ') || '(no accounts)'}`);
|
|
208
270
|
return 0;
|
|
209
271
|
}
|
|
210
272
|
function onOff(value, usage) {
|
|
@@ -216,7 +278,11 @@ export async function cmdList(a, io) {
|
|
|
216
278
|
const rt = await createRuntime();
|
|
217
279
|
const accounts = displayOrdered(await rt.accounts(), rt);
|
|
218
280
|
const [statuses, appProfiles] = await Promise.all([
|
|
219
|
-
withDesktopApps(rt, accounts, Promise.all(accounts.map((x) => rt.status(x)))).then((list) => list.map((s) =>
|
|
281
|
+
withDesktopApps(rt, accounts, Promise.all(accounts.map((x) => rt.status(x)))).then((list) => list.map((s) => {
|
|
282
|
+
const d = rt.displayOrder();
|
|
283
|
+
const marked = pinnedIn(s, d.pinned?.[s.family] ?? []) ? { ...s, pinned: true } : s;
|
|
284
|
+
return hiddenIn(s, d) ? { ...marked, hidden: true } : marked;
|
|
285
|
+
})),
|
|
220
286
|
// Desktop app windows in the Display Order too (spec §3.25), the main window first by default.
|
|
221
287
|
listAppProfiles(rt).then((list) => {
|
|
222
288
|
const d = rt.displayOrder();
|
|
@@ -227,13 +293,22 @@ export async function cmdList(a, io) {
|
|
|
227
293
|
}),
|
|
228
294
|
]);
|
|
229
295
|
const hasDesktop = statuses.some((s) => s.desktopApp);
|
|
230
|
-
const families = inDisplayOrder(await rt.familyInfo(), (f) => f.id, rt.displayOrder().families);
|
|
296
|
+
const families = inDisplayOrder(await rt.familyInfo(), (f) => f.id, rt.displayOrder().families).map((f) => rt.displayOrder().hiddenFamilies?.includes(f.id) ? { ...f, hidden: true } : f);
|
|
231
297
|
if (a.flags.has('json')) {
|
|
232
298
|
json(io, { families, accounts: statuses, appProfiles, pluginErrors: [...rt.pluginErrors] });
|
|
233
299
|
return 0;
|
|
234
300
|
}
|
|
235
301
|
const home = rt.paths.home;
|
|
236
|
-
|
|
302
|
+
// Hidden Accounts (spec §3.25) stay out of the text unless --all asks for them; --json above has them all.
|
|
303
|
+
const all = a.flags.has('all');
|
|
304
|
+
const shown = all ? statuses : statuses.filter((s) => !s.hidden);
|
|
305
|
+
const hiddenCount = statuses.length - shown.length;
|
|
306
|
+
const hiddenLine = c.dim(`\n${hiddenCount} hidden; sideby list --all shows them, sideby unhide <family|account> puts one back.`);
|
|
307
|
+
if (statuses.length && !shown.length) {
|
|
308
|
+
io.out(`All ${statuses.length} accounts are hidden.`);
|
|
309
|
+
io.out(hiddenLine);
|
|
310
|
+
}
|
|
311
|
+
else if (statuses.length === 0) {
|
|
237
312
|
io.out('No accounts found yet.');
|
|
238
313
|
const installed = families.filter((f) => f.installed);
|
|
239
314
|
if (installed.length === 0)
|
|
@@ -245,8 +320,8 @@ export async function cmdList(a, io) {
|
|
|
245
320
|
// `= main`: the other Accounts of its Same Login, which share its Quota (spec §3.21).
|
|
246
321
|
const brokenOf = (id) => families.find((f) => f.id === id)?.brokenBin;
|
|
247
322
|
const sameMark = (refs) => refs?.length ? ` ${c.dim(`= ${refs.map((r) => r.slice(r.indexOf(':') + 1)).join(', ')}`)}` : '';
|
|
248
|
-
const rows =
|
|
249
|
-
`${c.bold(s.ref)}${sameMark(s.sameLogin)}`,
|
|
323
|
+
const rows = shown.map((s) => [
|
|
324
|
+
`${c.bold(s.ref)}${sameMark(s.sameLogin)}${s.hidden ? ` ${c.dim('(hidden)')}` : ''}`,
|
|
250
325
|
s.isMain ? 'main' : s.kind === 'api' ? c.cyan('api') : 'sub',
|
|
251
326
|
s.login === 'logged-in'
|
|
252
327
|
? c.green('✓')
|
|
@@ -264,12 +339,14 @@ export async function cmdList(a, io) {
|
|
|
264
339
|
]);
|
|
265
340
|
io.out(table(rows, ['ACCOUNT', 'TYPE', 'LOGIN', 'EMAIL', 'MODEL', 'DIR', ...(hasDesktop ? ['DESKTOP'] : [])]));
|
|
266
341
|
// One line per Host that cannot run, with what to do: the rows only say which accounts it affects.
|
|
267
|
-
for (const f of families.filter((x) => !x.installed &&
|
|
342
|
+
for (const f of families.filter((x) => !x.installed && shown.some((s) => s.family === x.id)))
|
|
268
343
|
io.out(c.yellow(f.brokenBin
|
|
269
344
|
? `\n${f.title}'s install is broken (${tildify(f.brokenBin, home)} cannot run, often after an interrupted upgrade); reinstall it: ${installHint(f)}`
|
|
270
345
|
: `\n${f.title} is not installed; install it: ${installHint(f)}`));
|
|
271
|
-
if (
|
|
346
|
+
if (shown.some((s) => s.sameLogin?.length))
|
|
272
347
|
io.out(c.dim('\n= <account>: signed in as the same login as that account, so they share one quota.'));
|
|
348
|
+
if (hiddenCount)
|
|
349
|
+
io.out(hiddenLine);
|
|
273
350
|
io.out(c.dim('\nsideby run <account> · sideby new <family> <name> · sideby quota · sideby ui'));
|
|
274
351
|
}
|
|
275
352
|
// App Profiles (ADR-0019): windows of an app that signs in apart from the Accounts above. Not on the first screen
|
|
@@ -292,7 +369,7 @@ export async function cmdList(a, io) {
|
|
|
292
369
|
const id = list[0]?.ref.slice(0, list[0].ref.indexOf(':'));
|
|
293
370
|
io.out(c.dim(`sideby desktop ${id}:<name> opens one (a new name makes a new window)`));
|
|
294
371
|
}
|
|
295
|
-
for (const s of
|
|
372
|
+
for (const s of shown)
|
|
296
373
|
for (const p of s.problems ?? [])
|
|
297
374
|
io.err(c.yellow(`${s.ref}: ${p}`));
|
|
298
375
|
for (const e of rt.pluginErrors)
|
|
@@ -741,15 +818,15 @@ export async function cmdRemoteControl(a, io, runtime) {
|
|
|
741
818
|
for (const g of groups)
|
|
742
819
|
io.out(rcGroupLine(g, home));
|
|
743
820
|
io.out(c.dim(' on: every session connects; default: Claude Code or your organization decides; off: only when you run /remote-control'));
|
|
744
|
-
if (
|
|
821
|
+
if (remoteControlTodo(groups, 'off').length)
|
|
745
822
|
io.out(c.cyan('\nRun `sideby remote-control off` so no session connects by itself (it shows the change first).'));
|
|
746
823
|
return 0;
|
|
747
824
|
}
|
|
748
825
|
const apply = () => action === 'off' ? rt.remoteControlOff() : action === 'on' ? rt.remoteControlOn() : rt.remoteControlUndo();
|
|
749
826
|
const todo = action === 'off'
|
|
750
|
-
?
|
|
827
|
+
? remoteControlTodo(groups, 'off')
|
|
751
828
|
: action === 'on'
|
|
752
|
-
?
|
|
829
|
+
? remoteControlTodo(groups, 'on')
|
|
753
830
|
: groupsToUndo(groups);
|
|
754
831
|
const verb = action === 'off' ? 'turn it off' : action === 'on' ? 'turn it on' : 'undo';
|
|
755
832
|
if (todo.length === 0) {
|
|
@@ -1017,12 +1094,16 @@ async function cmdHandoffStatus(a, io) {
|
|
|
1017
1094
|
const rt = await createRuntime();
|
|
1018
1095
|
const st = await handoffStatus(rt);
|
|
1019
1096
|
if (a.flags.has('json')) {
|
|
1020
|
-
|
|
1097
|
+
const overview = await handoffOverview(rt);
|
|
1098
|
+
json(io, { ...st, apiUndecided: (await handoffRulesView(rt, overview)).apiUndecided, overview });
|
|
1021
1099
|
return 0;
|
|
1022
1100
|
}
|
|
1023
1101
|
io.out(`Auto Handoff: ${st.auto ? c.green('on') : c.yellow('off')} (same family ${st.sameFamily ? 'on' : 'off'}; brief at ${st.prepareAt}%, hand over at ${st.threshold}%)`);
|
|
1024
1102
|
if (st.sideby.problem)
|
|
1025
1103
|
io.out(c.red(`sideby on PATH: ${st.sideby.problem}`));
|
|
1104
|
+
if ((await handoffRulesView(rt)).apiUndecided)
|
|
1105
|
+
io.out(c.yellow(API_UNDECIDED));
|
|
1106
|
+
io.out(c.dim('Every rule in plain words: `sideby handoff rules`.'));
|
|
1026
1107
|
if (st.families.length)
|
|
1027
1108
|
io.out(`\n${table(st.families.map((f) => [
|
|
1028
1109
|
c.bold(f.family),
|
|
@@ -1043,6 +1124,66 @@ async function cmdHandoffStatus(a, io) {
|
|
|
1043
1124
|
}
|
|
1044
1125
|
return 0;
|
|
1045
1126
|
}
|
|
1127
|
+
/** `sideby handoff rules` (spec §3.17 "接力规则"): every rule in effect, in plain words, and how to change each. */
|
|
1128
|
+
async function cmdHandoffRules(a, io) {
|
|
1129
|
+
const rt = await createRuntime();
|
|
1130
|
+
const view = await handoffRulesView(rt);
|
|
1131
|
+
if (a.flags.has('json')) {
|
|
1132
|
+
json(io, view);
|
|
1133
|
+
return 0;
|
|
1134
|
+
}
|
|
1135
|
+
io.out(`Auto Handoff: ${view.auto ? c.green('on') : c.yellow('off')}${view.auto ? '' : c.dim(' (these rules apply once it is on)')}`);
|
|
1136
|
+
if (view.apiUndecided)
|
|
1137
|
+
io.out(c.yellow(`\n${API_UNDECIDED}`));
|
|
1138
|
+
io.out('');
|
|
1139
|
+
for (const [i, r] of view.rules.entries()) {
|
|
1140
|
+
io.out(`${String(i + 1).padStart(2)}. ${r.text}`);
|
|
1141
|
+
const change = ruleCommand(r);
|
|
1142
|
+
if (change)
|
|
1143
|
+
io.out(c.dim(` change: ${change}`));
|
|
1144
|
+
}
|
|
1145
|
+
if (view.takeover.length) {
|
|
1146
|
+
io.out('\nIf a handoff started now:');
|
|
1147
|
+
for (const t of view.takeover)
|
|
1148
|
+
io.out(` ${t.ref} → ${decisionText(t.decision)}`);
|
|
1149
|
+
}
|
|
1150
|
+
return 0;
|
|
1151
|
+
}
|
|
1152
|
+
const API_UNDECIDED = 'API accounts no longer take over by default: they are billed per use. Keep them as the last resort with `sideby config set handoff.api true --yes`, or say no with `sideby config set handoff.api false --yes`.';
|
|
1153
|
+
/** The command that changes a rule, or null for a fixed one. */
|
|
1154
|
+
function ruleCommand(r) {
|
|
1155
|
+
const set = (key, v) => `sideby config set handoff.${key} ${v} --yes`;
|
|
1156
|
+
switch (r.id) {
|
|
1157
|
+
case 'when':
|
|
1158
|
+
return `${set('threshold', '<percent>')}; ${set('prepareAt', '<percent>')}; ${set('adaptive', String(!r.params.adaptive))}`;
|
|
1159
|
+
case 'takeover':
|
|
1160
|
+
return `follows the threshold: ${set('threshold', '<percent>')}`;
|
|
1161
|
+
case 'wait':
|
|
1162
|
+
return set('waitIfResetWithinMinutes', '<minutes>');
|
|
1163
|
+
case 'sameFamily':
|
|
1164
|
+
case 'otherFamilies':
|
|
1165
|
+
case 'api':
|
|
1166
|
+
return (set(r.id, String(!r.params.on)) +
|
|
1167
|
+
(r.id === 'otherFamilies' ? `; ${set('familyOrder', '\'["codex","grok"]\'')}` : ''));
|
|
1168
|
+
case 'organization':
|
|
1169
|
+
return set('crossOrganization', '\'["<account>"]\'');
|
|
1170
|
+
case 'order':
|
|
1171
|
+
return `sideby handoff enable --order ${r.params.family}=<account,account>`;
|
|
1172
|
+
case 'countdown':
|
|
1173
|
+
return set('countdownSeconds', '<seconds>');
|
|
1174
|
+
default:
|
|
1175
|
+
return null;
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
function decisionText(d) {
|
|
1179
|
+
if (d.kind === 'pick')
|
|
1180
|
+
return d.ref;
|
|
1181
|
+
if (d.kind === 'wait')
|
|
1182
|
+
return `waits for the reset at ${new Date(d.until).toLocaleTimeString()}`;
|
|
1183
|
+
return d.earliestReset
|
|
1184
|
+
? `none now (${d.reason}); ${d.earliestReset.ref} is back at ${new Date(d.earliestReset.at).toLocaleTimeString()}`
|
|
1185
|
+
: `none (${d.reason})`;
|
|
1186
|
+
}
|
|
1046
1187
|
function intFlag(a, name) {
|
|
1047
1188
|
const v = a.flags.get(name);
|
|
1048
1189
|
if (v === undefined)
|
|
@@ -1059,6 +1200,16 @@ function switchCommand(sub, change) {
|
|
|
1059
1200
|
parts.push('--same-family');
|
|
1060
1201
|
if (change.sameFamily === false)
|
|
1061
1202
|
parts.push('--no-same-family');
|
|
1203
|
+
if (change.otherFamilies === true)
|
|
1204
|
+
parts.push('--other-ai');
|
|
1205
|
+
if (change.otherFamilies === false)
|
|
1206
|
+
parts.push('--no-other-ai');
|
|
1207
|
+
if (change.familyOrder)
|
|
1208
|
+
parts.push(`--ai-order ${change.familyOrder.join(',')}`);
|
|
1209
|
+
if (change.api === true)
|
|
1210
|
+
parts.push('--api');
|
|
1211
|
+
if (change.api === false)
|
|
1212
|
+
parts.push('--no-api');
|
|
1062
1213
|
for (const o of change.orders ?? [])
|
|
1063
1214
|
parts.push(`--order ${o.family}=${o.order.join(',')}`);
|
|
1064
1215
|
if (change.prepareAt !== undefined)
|
|
@@ -1079,6 +1230,22 @@ async function cmdHandoffSwitch(a, io, sub) {
|
|
|
1079
1230
|
change.sameFamily = true;
|
|
1080
1231
|
if (a.flags.has('no-same-family'))
|
|
1081
1232
|
change.sameFamily = false;
|
|
1233
|
+
if (a.flags.has('other-ai'))
|
|
1234
|
+
change.otherFamilies = true;
|
|
1235
|
+
if (a.flags.has('no-other-ai'))
|
|
1236
|
+
change.otherFamilies = false;
|
|
1237
|
+
if (a.flags.has('api'))
|
|
1238
|
+
change.api = true;
|
|
1239
|
+
if (a.flags.has('no-api'))
|
|
1240
|
+
change.api = false;
|
|
1241
|
+
const aiOrder = a.flags.get('ai-order');
|
|
1242
|
+
if (aiOrder === true)
|
|
1243
|
+
throw new UsageError('--ai-order takes families, for example --ai-order codex,grok');
|
|
1244
|
+
if (typeof aiOrder === 'string')
|
|
1245
|
+
change.familyOrder = aiOrder
|
|
1246
|
+
.split(',')
|
|
1247
|
+
.map((x) => x.trim())
|
|
1248
|
+
.filter(Boolean);
|
|
1082
1249
|
const order = a.flags.get('order');
|
|
1083
1250
|
if (typeof order === 'string') {
|
|
1084
1251
|
const eq = order.indexOf('=');
|
|
@@ -1117,6 +1284,8 @@ async function cmdHandoffSwitch(a, io, sub) {
|
|
|
1117
1284
|
io.out(`Auto Handoff is already ${sub === 'enable' ? 'set that way' : 'off'}; nothing to change.`);
|
|
1118
1285
|
else if (!r.applied) {
|
|
1119
1286
|
io.out(`Change to ${tildify(r.file, rt.paths.home)}:\n\n${r.diff}`);
|
|
1287
|
+
if (sub === 'enable' && r.settings.api)
|
|
1288
|
+
io.out(c.yellow('API accounts are billed per use and sideby does not cap spending; set a limit in the provider’s console.'));
|
|
1120
1289
|
if (sub === 'enable' && r.settings.sameFamily)
|
|
1121
1290
|
io.out(c.yellow('Same-family hand-over moves work between subscriptions of one vendor; vendors may act on that.'));
|
|
1122
1291
|
io.out(c.cyan(`\nApply it with \`${switchCommand(sub, change)} --yes\`.`));
|
|
@@ -1144,10 +1313,12 @@ export async function cmdHandoff(a, io) {
|
|
|
1144
1313
|
}
|
|
1145
1314
|
if (sub === 'status')
|
|
1146
1315
|
return cmdHandoffStatus(a, io);
|
|
1316
|
+
if (sub === 'rules')
|
|
1317
|
+
return cmdHandoffRules(a, io);
|
|
1147
1318
|
if (sub === 'enable' || sub === 'disable')
|
|
1148
1319
|
return cmdHandoffSwitch(a, io, sub);
|
|
1149
1320
|
if (sub !== 'ready')
|
|
1150
|
-
throw new UsageError('usage: sideby handoff status | enable [--same-family] [--order <family>=<acct,…>] [--threshold n] [--prepare-at n] [--yes] | disable [--yes] | ready [--to <account>] [--brief <file>] | setup|teardown <family> [--yes]');
|
|
1321
|
+
throw new UsageError('usage: sideby handoff status | rules | enable [--same-family] [--other-ai] [--ai-order <family,…>] [--api] [--order <family>=<acct,…>] [--threshold n] [--prepare-at n] [--yes] | disable [--yes] | ready [--to <account>] [--brief <file>] | setup|teardown <family> [--yes]');
|
|
1151
1322
|
const flag = a.flags.get('brief');
|
|
1152
1323
|
const brief = typeof flag === 'string' ? flag : undefined;
|
|
1153
1324
|
const toFlag = a.flags.get('to');
|
|
@@ -1962,10 +2133,16 @@ export async function cmdFamilies(a, io) {
|
|
|
1962
2133
|
if (i)
|
|
1963
2134
|
io.out('');
|
|
1964
2135
|
io.out(`${c.bold(f.title)} (${f.id}) ${f.installed ? c.green('installed') : c.yellow(f.brokenBin ? `install broken (${tildify(f.brokenBin, rt.paths.home)} cannot run); reinstall: ${installHint(f)}` : `not installed: ${installHint(f)}`)}`);
|
|
1965
|
-
io.out(
|
|
1966
|
-
|
|
2136
|
+
io.out(f.mainOnly
|
|
2137
|
+
? ` Accounts ~/${f.layout.main} (main only: ${f.title} keeps one sign-in per computer)`
|
|
2138
|
+
: ` Accounts ~/${f.layout.main} (main), ~/${f.layout.account}; selected with ${f.selectVar}`);
|
|
2139
|
+
io.out(` Sign in sideby login ${f.id}:${f.mainOnly ? 'main' : '<name>'} ${c.dim(f.login.args ? `(runs ${[f.bin, ...f.login.args].join(' ')})` : `(${f.login.hint})`)}`);
|
|
1967
2140
|
const yes = (b) => (b ? c.green('yes') : c.dim('no public source'));
|
|
1968
2141
|
io.out(` Quota ${yes(f.quota)}${f.quotaSetup ? c.dim(`, after \`sideby quota setup ${f.id}\``) : ''} Usage ${yes(f.usage)}`);
|
|
2142
|
+
if (!f.shared.length) {
|
|
2143
|
+
io.out(c.dim(' No shared items: everything in the account directory is its own.'));
|
|
2144
|
+
return;
|
|
2145
|
+
}
|
|
1969
2146
|
io.out(' Shared items, and how each account holds them:');
|
|
1970
2147
|
const rows = f.shared.map((s) => [
|
|
1971
2148
|
` ${s.path}${s.key ? `#${s.key}` : ''}`,
|
|
@@ -2372,24 +2549,57 @@ export async function cmdAutostart(a, io) {
|
|
|
2372
2549
|
}
|
|
2373
2550
|
return 0;
|
|
2374
2551
|
}
|
|
2552
|
+
/** The newest session activity among these Accounts, from their Usage; undefined when none can be read. */
|
|
2553
|
+
async function lastLocalUse(rt, list) {
|
|
2554
|
+
const times = await Promise.all(list.map(async (x) => {
|
|
2555
|
+
const u = await rt.usage(x).catch(() => null);
|
|
2556
|
+
return u?.status === 'ok' && u.lastActivityAt ? Date.parse(u.lastActivityAt) : Number.NaN;
|
|
2557
|
+
}));
|
|
2558
|
+
const newest = Math.max(...times.filter(Number.isFinite));
|
|
2559
|
+
return Number.isFinite(newest) ? new Date(newest).toISOString() : undefined;
|
|
2560
|
+
}
|
|
2375
2561
|
/** What the Menu Bar Item lists (spec §3.31): each Family's accounts in Display Order, with its Handoff ranking. */
|
|
2376
2562
|
async function menubarFamilies(rt) {
|
|
2377
|
-
|
|
2563
|
+
// Hidden Families and Accounts (spec §3.25) stay out of the menu and its percent; a Same Login is hidden whole.
|
|
2564
|
+
const display = rt.displayOrder();
|
|
2565
|
+
const every = displayOrdered(await rt.accounts(), rt);
|
|
2566
|
+
const accounts = [];
|
|
2567
|
+
for (const x of every)
|
|
2568
|
+
if (!hiddenIn({ ...x, sameLogin: await rt.sameLogin(x) }, display))
|
|
2569
|
+
accounts.push(x);
|
|
2378
2570
|
const ids = [...new Set(accounts.map((x) => x.family))];
|
|
2379
2571
|
return Promise.all(ids.map(async (id) => {
|
|
2380
2572
|
const f = rt.families.get(id);
|
|
2381
2573
|
const plan = f.readQuota || f.fetchQuota ? await rt.handoff(id).catch(() => null) : null;
|
|
2574
|
+
const now = rt.readContext().now.getTime();
|
|
2382
2575
|
const list = await Promise.all(accounts
|
|
2383
2576
|
.filter((x) => x.family === id)
|
|
2384
|
-
.map(async (x) =>
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2577
|
+
.map(async (x) => {
|
|
2578
|
+
const quota = await rt.quota(x);
|
|
2579
|
+
const sameLogin = await rt.sameLogin(x);
|
|
2580
|
+
// Usage is read only for a reading over an hour old, to tell whether this computer used the login since.
|
|
2581
|
+
const old = quota.status === 'ok' && now - Date.parse(quota.observedAt) > 3600_000;
|
|
2582
|
+
const lastUseAt = old
|
|
2583
|
+
? await lastLocalUse(rt, [x, ...accounts.filter((p) => sameLogin.includes(p.ref))])
|
|
2584
|
+
: undefined;
|
|
2585
|
+
return {
|
|
2586
|
+
ref: x.ref,
|
|
2587
|
+
name: x.name,
|
|
2588
|
+
kind: x.kind,
|
|
2589
|
+
login: x.kind === 'api' ? 'not-needed' : (await rt.status(x)).login,
|
|
2590
|
+
quota,
|
|
2591
|
+
sameLogin,
|
|
2592
|
+
...(lastUseAt ? { lastUseAt } : {}),
|
|
2593
|
+
};
|
|
2594
|
+
}));
|
|
2595
|
+
return {
|
|
2596
|
+
id,
|
|
2597
|
+
title: f.title,
|
|
2598
|
+
logo: f.logo ?? null,
|
|
2599
|
+
refreshable: Boolean(f.fetchQuota),
|
|
2600
|
+
plan,
|
|
2601
|
+
accounts: list,
|
|
2602
|
+
};
|
|
2393
2603
|
}));
|
|
2394
2604
|
}
|
|
2395
2605
|
/**
|
|
@@ -2691,10 +2901,14 @@ export async function cmdConfig(a, io) {
|
|
|
2691
2901
|
? 'usage: sideby config set <key> <value> [--yes] [--json] (quote a value with spaces)'
|
|
2692
2902
|
: 'usage: sideby config unset <key> [--yes] [--json]');
|
|
2693
2903
|
const next = sub === 'set' ? cfg.parseConfigValue(value) : undefined;
|
|
2694
|
-
const
|
|
2904
|
+
const top = key.split('.')[0];
|
|
2905
|
+
const rt = top === 'accounts' || top === 'handoff' ? await createRuntime() : undefined;
|
|
2906
|
+
const argsProblem = rt && top === 'accounts' ? modelArgsProblem(rt) : undefined;
|
|
2907
|
+
const refs = rt && top === 'handoff' ? await handoffRefs(rt) : undefined;
|
|
2695
2908
|
const r = await cfg.editConfigPath(file, key, next, {
|
|
2696
2909
|
dryRun: !yes,
|
|
2697
2910
|
...(argsProblem ? { argsProblem } : {}),
|
|
2911
|
+
...(refs ? { checkHandoff: (before, after) => checkHandoffRefs(refs, before, after) } : {}),
|
|
2698
2912
|
});
|
|
2699
2913
|
const out = {
|
|
2700
2914
|
action: sub,
|
|
@@ -3378,3 +3592,199 @@ async function messagesInbound(a, args, io, runtime) {
|
|
|
3378
3592
|
}
|
|
3379
3593
|
return r.ok ? 0 : 1;
|
|
3380
3594
|
}
|
|
3595
|
+
/** `sideby theme` (spec §3.34): list, use, undo, check, preview, import, export and remove Themes. */
|
|
3596
|
+
export async function cmdTheme(a, io) {
|
|
3597
|
+
const t = await import('../core/themes.js');
|
|
3598
|
+
const { loadConfig } = await import('../core/config.js');
|
|
3599
|
+
const [sub = 'list', target, ...more] = a.positionals;
|
|
3600
|
+
const wantJson = a.flags.has('json');
|
|
3601
|
+
const paths = resolvePaths();
|
|
3602
|
+
const usage = 'usage: sideby theme [list] | use <name> | use --undo | check <name|file> | preview <name|file> | import <file> [--id <name>] [--yes] | export <name> [--out <file>] | remove <name> [--yes] [--json]';
|
|
3603
|
+
if (more.length)
|
|
3604
|
+
throw new UsageError(usage);
|
|
3605
|
+
const active = async () => (await loadConfig(paths.configFile).catch(() => ({}))).panel
|
|
3606
|
+
?.colorTheme ?? 'sky';
|
|
3607
|
+
// A name, or a path to a Theme File not yet in the themes folder.
|
|
3608
|
+
const load = async (ref) => {
|
|
3609
|
+
if (t.THEME_ID_RE.test(ref) && !ref.endsWith('.json'))
|
|
3610
|
+
return { id: ref, theme: await t.exportTheme(paths, ref) };
|
|
3611
|
+
const r = await t.readThemeFile(resolve(ref));
|
|
3612
|
+
if (!r.theme)
|
|
3613
|
+
throw new UserError(`${ref} ${r.problems.join('; ')}`);
|
|
3614
|
+
for (const w of r.warnings)
|
|
3615
|
+
io.err(c.yellow(`! ${w}`));
|
|
3616
|
+
return { id: basename(ref, '.json'), theme: r.theme };
|
|
3617
|
+
};
|
|
3618
|
+
if (sub === 'list') {
|
|
3619
|
+
if (target)
|
|
3620
|
+
throw new UsageError(usage);
|
|
3621
|
+
const now = await active();
|
|
3622
|
+
const themes = (await t.listThemes(paths)).map((e) => ({
|
|
3623
|
+
id: e.id,
|
|
3624
|
+
name: e.name,
|
|
3625
|
+
source: e.source,
|
|
3626
|
+
...(e.path ? { path: tilde(e.path, paths.home) } : {}),
|
|
3627
|
+
active: e.id === now,
|
|
3628
|
+
problems: e.problems,
|
|
3629
|
+
warnings: e.warnings,
|
|
3630
|
+
}));
|
|
3631
|
+
if (wantJson)
|
|
3632
|
+
json(io, { folder: tilde(t.themesDir(paths), paths.home), themes });
|
|
3633
|
+
else {
|
|
3634
|
+
for (const e of themes) {
|
|
3635
|
+
const mark = e.active ? c.green('●') : ' ';
|
|
3636
|
+
io.out(`${mark} ${e.id.padEnd(14)} ${e.name}${e.source === 'builtin' ? c.dim(' (built in)') : ''}`);
|
|
3637
|
+
for (const p of e.problems)
|
|
3638
|
+
io.out(c.red(` ✗ ${p}${e.path ? ` (${e.path})` : ''}`));
|
|
3639
|
+
for (const w of e.warnings)
|
|
3640
|
+
io.out(c.yellow(` ! ${w}`));
|
|
3641
|
+
}
|
|
3642
|
+
io.out(c.dim(`Switch: sideby theme use <name>. Your Theme Files go in ${tilde(t.themesDir(paths), paths.home)}.`));
|
|
3643
|
+
}
|
|
3644
|
+
return 0;
|
|
3645
|
+
}
|
|
3646
|
+
if (sub === 'use') {
|
|
3647
|
+
const undo = a.flags.has('undo');
|
|
3648
|
+
if (undo === Boolean(target))
|
|
3649
|
+
throw new UsageError('usage: sideby theme use <name> | sideby theme use --undo | sideby theme use default [--json]');
|
|
3650
|
+
let r;
|
|
3651
|
+
try {
|
|
3652
|
+
r = undo ? await t.undoTheme(paths) : await t.useTheme(paths, target);
|
|
3653
|
+
}
|
|
3654
|
+
catch (e) {
|
|
3655
|
+
throw new UserError(e.message);
|
|
3656
|
+
}
|
|
3657
|
+
if (wantJson)
|
|
3658
|
+
json(io, { before: r.before, after: r.after, changed: r.changed ?? true });
|
|
3659
|
+
else
|
|
3660
|
+
io.out(r.changed === false
|
|
3661
|
+
? `Already using ${r.after}.`
|
|
3662
|
+
: `${c.green('✓')} Theme ${r.before} → ${r.after}. The Panel shows it on its next refresh${undo ? '.' : '; undo with `sideby theme use --undo`.'}`);
|
|
3663
|
+
return 0;
|
|
3664
|
+
}
|
|
3665
|
+
if (sub === 'check') {
|
|
3666
|
+
if (!target)
|
|
3667
|
+
throw new UsageError(usage);
|
|
3668
|
+
const { id, theme } = await load(target);
|
|
3669
|
+
const pairs = t.contrastPairs(t.themeColors(theme));
|
|
3670
|
+
const failing = pairs.filter((p) => !p.ok);
|
|
3671
|
+
if (wantJson)
|
|
3672
|
+
json(io, { id, ok: failing.length === 0, pairs, warnings: [] });
|
|
3673
|
+
else {
|
|
3674
|
+
for (const p of pairs)
|
|
3675
|
+
if (p.ratio !== undefined)
|
|
3676
|
+
io.out(`${p.ok ? c.green('✓') : c.red('✗')} ${p.mode.padEnd(5)} ${`${p.fg} on ${p.bg}`.padEnd(24)} ${p.ratio.toFixed(2)}:1 (needs ${p.min})${p.suggest ? c.dim(` try ${p.fg}: ${p.suggest}`) : ''}`);
|
|
3677
|
+
io.out(failing.length
|
|
3678
|
+
? c.yellow(`${failing.length} pair(s) too faint. The Panel moves them to the value shown; set those values in the file to choose them yourself.`)
|
|
3679
|
+
: `${c.green('✓')} Every pair is readable in light and dark.`);
|
|
3680
|
+
}
|
|
3681
|
+
return failing.length ? 1 : 0;
|
|
3682
|
+
}
|
|
3683
|
+
if (sub === 'preview') {
|
|
3684
|
+
if (!target)
|
|
3685
|
+
throw new UsageError(usage);
|
|
3686
|
+
const { theme } = await load(target);
|
|
3687
|
+
await t.setPreview(paths, theme);
|
|
3688
|
+
const { backgroundPanelPort, findRunningPanel } = await import('../panel/background.js');
|
|
3689
|
+
const port = await backgroundPanelPort(paths);
|
|
3690
|
+
const url = port ? await findRunningPanel(paths, port) : undefined;
|
|
3691
|
+
if (!url) {
|
|
3692
|
+
if (wantJson)
|
|
3693
|
+
json(io, {
|
|
3694
|
+
opened: false,
|
|
3695
|
+
hint: 'start the Panel with `sideby ui --background`, then run this again',
|
|
3696
|
+
});
|
|
3697
|
+
else
|
|
3698
|
+
io.err(c.yellow('The Panel is not running. Start it with `sideby ui --background`, then run this again.'));
|
|
3699
|
+
return 1;
|
|
3700
|
+
}
|
|
3701
|
+
const { openBrowser } = await import('../panel/server.js');
|
|
3702
|
+
const opened = await openBrowser(`${url}?theme=preview`);
|
|
3703
|
+
if (wantJson)
|
|
3704
|
+
json(io, { opened, url: `${url}?theme=preview` });
|
|
3705
|
+
else
|
|
3706
|
+
io.out(`Showing ${theme.name} for this one look (${url}?theme=preview); your Theme stays the same. Keep it with \`sideby theme import\` and \`sideby theme use\`.`);
|
|
3707
|
+
return 0;
|
|
3708
|
+
}
|
|
3709
|
+
if (sub === 'import') {
|
|
3710
|
+
if (!target)
|
|
3711
|
+
throw new UsageError(usage);
|
|
3712
|
+
const { id: fromName, theme } = await load(target);
|
|
3713
|
+
const idFlag = a.flags.get('id');
|
|
3714
|
+
const id = typeof idFlag === 'string' ? idFlag : fromName;
|
|
3715
|
+
const dest = join(t.themesDir(paths), `${id}.json`);
|
|
3716
|
+
const exists = await stat(dest).then(() => true, () => false);
|
|
3717
|
+
if (exists && !a.flags.has('yes')) {
|
|
3718
|
+
if (wantJson)
|
|
3719
|
+
json(io, { id, path: tilde(dest, paths.home), replaced: false, exists: true });
|
|
3720
|
+
else
|
|
3721
|
+
io.out(`${tilde(dest, paths.home)} already exists. Replace it with \`sideby theme import ${target} --yes\`.`);
|
|
3722
|
+
return 10;
|
|
3723
|
+
}
|
|
3724
|
+
let path;
|
|
3725
|
+
try {
|
|
3726
|
+
path = await t.saveThemeFile(paths, id, theme);
|
|
3727
|
+
}
|
|
3728
|
+
catch (e) {
|
|
3729
|
+
throw new UserError(e.message);
|
|
3730
|
+
}
|
|
3731
|
+
if (wantJson)
|
|
3732
|
+
json(io, { id, path: tilde(path, paths.home), replaced: exists });
|
|
3733
|
+
else
|
|
3734
|
+
io.out(`${c.green('✓')} Saved ${theme.name} as ${id}. Use it with \`sideby theme use ${id}\`.`);
|
|
3735
|
+
return 0;
|
|
3736
|
+
}
|
|
3737
|
+
if (sub === 'export') {
|
|
3738
|
+
if (!target)
|
|
3739
|
+
throw new UsageError(usage);
|
|
3740
|
+
let theme;
|
|
3741
|
+
try {
|
|
3742
|
+
theme = await t.exportTheme(paths, target);
|
|
3743
|
+
}
|
|
3744
|
+
catch (e) {
|
|
3745
|
+
throw new UserError(e.message);
|
|
3746
|
+
}
|
|
3747
|
+
const text = `${JSON.stringify(theme, null, 2)}\n`;
|
|
3748
|
+
const out = a.flags.get('out');
|
|
3749
|
+
if (typeof out === 'string') {
|
|
3750
|
+
await writeFile(resolve(out), text, { flag: 'wx' }).catch((e) => {
|
|
3751
|
+
throw new UserError(e.code === 'EEXIST'
|
|
3752
|
+
? `${out} already exists; pick another file`
|
|
3753
|
+
: `cannot write ${out} (${e.code})`);
|
|
3754
|
+
});
|
|
3755
|
+
if (wantJson)
|
|
3756
|
+
json(io, { id: target, out });
|
|
3757
|
+
else
|
|
3758
|
+
io.out(`${c.green('✓')} Wrote ${out}. Edit it, then \`sideby theme check ${out}\` and \`sideby theme import ${out}\`.`);
|
|
3759
|
+
}
|
|
3760
|
+
else if (wantJson)
|
|
3761
|
+
json(io, { id: target, theme });
|
|
3762
|
+
else
|
|
3763
|
+
io.out(text.trimEnd());
|
|
3764
|
+
return 0;
|
|
3765
|
+
}
|
|
3766
|
+
if (sub === 'remove') {
|
|
3767
|
+
if (!target)
|
|
3768
|
+
throw new UsageError(usage);
|
|
3769
|
+
if (!a.flags.has('yes')) {
|
|
3770
|
+
if (wantJson)
|
|
3771
|
+
json(io, { id: target, removed: false });
|
|
3772
|
+
else
|
|
3773
|
+
io.out(`This deletes the Theme File ${target}. Run \`sideby theme remove ${target} --yes\` to do it.`);
|
|
3774
|
+
return 10;
|
|
3775
|
+
}
|
|
3776
|
+
let r;
|
|
3777
|
+
try {
|
|
3778
|
+
r = await t.removeThemeFile(paths, target);
|
|
3779
|
+
}
|
|
3780
|
+
catch (e) {
|
|
3781
|
+
throw new UserError(e.message);
|
|
3782
|
+
}
|
|
3783
|
+
if (wantJson)
|
|
3784
|
+
json(io, { id: target, removed: true, wasActive: r.wasActive });
|
|
3785
|
+
else
|
|
3786
|
+
io.out(`${c.green('✓')} Removed ${tilde(r.path, paths.home)}${r.wasActive ? '; the Panel is back on Sky' : ''}.`);
|
|
3787
|
+
return 0;
|
|
3788
|
+
}
|
|
3789
|
+
throw new UsageError(usage);
|
|
3790
|
+
}
|