sideby 0.27.1 → 0.28.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/dist/build.json +1 -1
- package/dist/src/cli/commands.js +14 -7
- package/dist/src/cli/json-schemas.js +4 -1
- package/dist/src/cli/main.js +7 -5
- package/dist/src/core/autostart.d.ts +22 -1
- package/dist/src/core/autostart.js +188 -17
- package/dist/src/panel/handler.d.ts +1 -0
- package/dist/src/panel/handler.js +1 -0
- package/dist/src/panel/i18n.d.ts +2 -0
- package/dist/src/panel/i18n.js +6 -2
- package/dist/src/panel/page-script.js +3 -2
- package/package.json +1 -1
- package/schemas/autostart.json +17 -0
- package/schemas/menubar.json +17 -0
- package/skills/sideby/SKILL.md +1 -1
- package/skills/sideby/references/panel.md +1 -1
package/dist/build.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"id":"
|
|
1
|
+
{"id":"20261028T132743-ee8214"}
|
package/dist/src/cli/commands.js
CHANGED
|
@@ -1532,6 +1532,8 @@ export async function cmdUi(a, io) {
|
|
|
1532
1532
|
io.err(c.red(`✗ could not stop the background panel: ${r.detail}`));
|
|
1533
1533
|
return r.status === 'failed' ? 1 : 0;
|
|
1534
1534
|
}
|
|
1535
|
+
if (a.flags.has('wait') && !a.flags.has('background'))
|
|
1536
|
+
throw new UsageError('--wait goes with --background: sideby ui --background --wait');
|
|
1535
1537
|
if (a.flags.has(bg.DETACHED_FLAG))
|
|
1536
1538
|
return bg.serveDetached({
|
|
1537
1539
|
paths,
|
|
@@ -1553,6 +1555,10 @@ export async function cmdUi(a, io) {
|
|
|
1553
1555
|
: `sideby panel: ${r.url} (in the background${r.replaced ? ', replacing the one from an older sideby' : ''}; stop it with \`sideby ui --stop\`)`);
|
|
1554
1556
|
if (!a.flags.has('no-open') && !(await openBrowser(r.url)))
|
|
1555
1557
|
io.out(`open ${r.url} in your browser`);
|
|
1558
|
+
// Under WSL the Startup script's `wsl.exe` waits here, so WSL keeps the distribution (and the Panel) up (ADR-0055).
|
|
1559
|
+
if (a.flags.has('wait'))
|
|
1560
|
+
while ((await bg.backgroundPanelPort(paths)) !== null)
|
|
1561
|
+
await new Promise((r) => setTimeout(r, 30_000));
|
|
1556
1562
|
return 0;
|
|
1557
1563
|
}
|
|
1558
1564
|
const srv = await startPanelServer({
|
|
@@ -2470,7 +2476,7 @@ export async function cmdTry(a, io) {
|
|
|
2470
2476
|
}
|
|
2471
2477
|
/** `sideby autostart [on|off] [--yes]` (spec §3.29, ADR-0029): start the Panel in the background at login. */
|
|
2472
2478
|
export async function cmdAutostart(a, io) {
|
|
2473
|
-
const { applyAutostart, autostartStatus, planAutostart, refreshAutostart } = await import('../core/autostart.js');
|
|
2479
|
+
const { applyAutostart, autostartStatus, autostartWhen, planAutostart, refreshAutostart } = await import('../core/autostart.js');
|
|
2474
2480
|
const [action, extra] = a.positionals;
|
|
2475
2481
|
if (extra !== undefined || (action !== undefined && action !== 'on' && action !== 'off'))
|
|
2476
2482
|
throw new UsageError('usage: sideby autostart [on|off] [--yes] [--json]');
|
|
@@ -2502,13 +2508,13 @@ export async function cmdAutostart(a, io) {
|
|
|
2502
2508
|
else if (!s.supported)
|
|
2503
2509
|
io.out(`${s.reason}.`);
|
|
2504
2510
|
else if (s.state === 'off')
|
|
2505
|
-
io.out(
|
|
2511
|
+
io.out(`Off: sideby does not start ${autostartWhen(s.mechanism)}. Turn it on: sideby autostart on`);
|
|
2506
2512
|
else if (s.state === 'foreign')
|
|
2507
2513
|
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.`);
|
|
2508
2514
|
else if (s.state === 'stale')
|
|
2509
2515
|
io.out(`Out of date: the login item starts ${s.missing.join(' and ')}, which no longer exists. Run \`sideby autostart on\` to point it at this sideby.`);
|
|
2510
2516
|
else {
|
|
2511
|
-
io.out(
|
|
2517
|
+
io.out(`On: the panel starts in the background ${autostartWhen(s.mechanism)}, without opening a window.`);
|
|
2512
2518
|
if (!s.current)
|
|
2513
2519
|
io.out(c.dim('It starts another sideby than this one; `sideby autostart on` points it here.'));
|
|
2514
2520
|
io.out(c.dim('Turn it off: sideby autostart off'));
|
|
@@ -2546,9 +2552,10 @@ export async function cmdAutostart(a, io) {
|
|
|
2546
2552
|
}
|
|
2547
2553
|
else
|
|
2548
2554
|
io.out(`Removes ${tilde(plan.path, home)}.`);
|
|
2549
|
-
|
|
2555
|
+
if (plan.commands.length)
|
|
2556
|
+
io.out(`Then runs: ${plan.commands.map((cmd) => cmd.join(' ')).join('; ')}`);
|
|
2550
2557
|
io.out(action === 'on'
|
|
2551
|
-
?
|
|
2558
|
+
? `Then the panel starts in the background ${autostartWhen(plan.status.mechanism)}, without opening a window. Run again with --yes to turn it on.`
|
|
2552
2559
|
: 'Run again with --yes to turn it off.');
|
|
2553
2560
|
}
|
|
2554
2561
|
return 10;
|
|
@@ -2564,8 +2571,8 @@ export async function cmdAutostart(a, io) {
|
|
|
2564
2571
|
});
|
|
2565
2572
|
else {
|
|
2566
2573
|
io.out(action === 'on'
|
|
2567
|
-
?
|
|
2568
|
-
:
|
|
2574
|
+
? `On: the panel starts in the background ${autostartWhen(plan.status.mechanism)}. Undo: sideby autostart off`
|
|
2575
|
+
: `Off: sideby no longer starts ${autostartWhen(plan.status.mechanism)}.`);
|
|
2569
2576
|
if (r.note)
|
|
2570
2577
|
io.out(c.dim(r.note));
|
|
2571
2578
|
}
|
|
@@ -22,7 +22,7 @@ const hotkeyProps = {
|
|
|
22
22
|
problem: Type.Optional(Type.Object({ code: Str, message: Str }, { description: 'A value config allows but a new choice would be refused for; it still works.' })),
|
|
23
23
|
};
|
|
24
24
|
const MenubarHotkeyView = Type.Object(hotkeyProps);
|
|
25
|
-
/** `sideby autostart` and `sideby menubar` (ADR-0029, ADR-0034):
|
|
25
|
+
/** `sideby autostart` and `sideby menubar` (ADR-0029, ADR-0034, ADR-0055): the login item sideby writes. */
|
|
26
26
|
const loginItem = (current) => Type.Object({
|
|
27
27
|
schemaVersion: Version,
|
|
28
28
|
supported: Type.Boolean({
|
|
@@ -33,6 +33,9 @@ const loginItem = (current) => Type.Object({
|
|
|
33
33
|
description: '`stale`: the Node or sideby it starts no longer exists; `foreign`: a file at that path that sideby did not write.',
|
|
34
34
|
}),
|
|
35
35
|
path: Str,
|
|
36
|
+
mechanism: Type.Optional(Type.Union(['launchd', 'xdg', 'wsl-startup'].map((k) => Type.Literal(k)), {
|
|
37
|
+
description: 'How it starts at login: a LaunchAgent (macOS), an XDG autostart entry (Linux desktop sessions), or a script in the Windows Startup folder (WSL). Absent when unsupported.',
|
|
38
|
+
})),
|
|
36
39
|
programArguments: Type.Optional(Type.Array(Str)),
|
|
37
40
|
current: Type.Boolean({ description: current }),
|
|
38
41
|
missing: Type.Optional(Type.Array(Str)),
|
package/dist/src/cli/main.js
CHANGED
|
@@ -118,8 +118,8 @@ Usage:
|
|
|
118
118
|
sideby plugins new <id> create a local Family Plugin skeleton
|
|
119
119
|
sideby plugins check <id|path> check a plugin and show fixes
|
|
120
120
|
sideby update [--yes] update sideby to the newest version (shows the command first)
|
|
121
|
-
sideby autostart [on|off] [--yes] start the panel in the background at login (macOS
|
|
122
|
-
file first)
|
|
121
|
+
sideby autostart [on|off] [--yes] start the panel in the background at login (macOS, Linux, WSL;
|
|
122
|
+
shows the file first)
|
|
123
123
|
sideby menubar [on|off] [--yes] show quota in the macOS menu bar; click an account to start it
|
|
124
124
|
sideby menubar hotkey [<keys>|off] show or change the shortcut that opens that menu (⌥X)
|
|
125
125
|
sideby theme [list] the Panel's Themes; use <name> switches, use --undo goes back, use default clears
|
|
@@ -365,8 +365,10 @@ malformed command line.`,
|
|
|
365
365
|
autostart: `sideby autostart [on|off] [--yes] [--json]
|
|
366
366
|
|
|
367
367
|
Start the panel in the background when you log in, so it already shows fresh quota when you open it. It never
|
|
368
|
-
opens a window or a browser and never starts a host.
|
|
369
|
-
~/Library/LaunchAgents/dev.sideby.panel.plist,
|
|
368
|
+
opens a window or a browser and never starts a host. It starts this Node and this sideby with ui --background:
|
|
369
|
+
on macOS from a LaunchAgent (~/Library/LaunchAgents/dev.sideby.panel.plist), on Linux from an autostart entry
|
|
370
|
+
(~/.config/autostart/dev.sideby.panel.desktop, run by desktop sessions), and under WSL from sideby-panel.vbs in
|
|
371
|
+
the Windows Startup folder, when you sign in to Windows.
|
|
370
372
|
|
|
371
373
|
Without on or off it says whether it is on, off, out of date (the Node or sideby it starts was moved) or blocked
|
|
372
374
|
by a file that is not sideby's. on and off show the file and the launchctl command first; --yes does it.
|
|
@@ -560,7 +562,7 @@ const COMMANDS = {
|
|
|
560
562
|
flags: ['json', 'yes', 'same-family', 'no-same-family', 'other-ai', 'no-other-ai', 'api', 'no-api'],
|
|
561
563
|
valued: ['brief', 'to', 'order', 'ai-order', 'prepare-at', 'threshold', 'wait-minutes', 'countdown'],
|
|
562
564
|
},
|
|
563
|
-
ui: { flags: ['no-open', 'background', 'stop', 'serve-detached'], valued: ['port'] },
|
|
565
|
+
ui: { flags: ['no-open', 'background', 'stop', 'serve-detached', 'wait'], valued: ['port'] },
|
|
564
566
|
app: { flags: ['json'], valued: ['url'] },
|
|
565
567
|
desktop: { flags: ['json', 'remove', 'yes'] },
|
|
566
568
|
sessions: { flags: ['json'], valued: ['as', 'lang'] },
|
|
@@ -26,6 +26,10 @@ export interface LoginAgent {
|
|
|
26
26
|
environment?: (env: Env) => Record<string, string>;
|
|
27
27
|
}
|
|
28
28
|
export type AutostartState = 'off' | 'on' | 'stale' | 'foreign';
|
|
29
|
+
/** How the system starts the agent at login: launchd (macOS), an XDG autostart entry (Linux), the Windows Startup folder (WSL). */
|
|
30
|
+
export type AutostartMechanism = 'launchd' | 'xdg' | 'wsl-startup';
|
|
31
|
+
/** The Windows file name under WSL; its folder is the current Windows user's Startup folder. */
|
|
32
|
+
export declare const WSL_STARTUP_FILE = "sideby-panel.vbs";
|
|
29
33
|
/** Runs a program and resolves with its exit code and output; never rejects. */
|
|
30
34
|
export type AutostartExec = (file: string, args: readonly string[]) => Promise<{
|
|
31
35
|
code: number;
|
|
@@ -44,6 +48,13 @@ export interface AutostartContext {
|
|
|
44
48
|
env?: Env;
|
|
45
49
|
/** Waits between launchctl calls; tests pass one that returns at once. */
|
|
46
50
|
sleep?: (ms: number) => Promise<void>;
|
|
51
|
+
/** On WSL, the distribution and where Windows drives are mounted; null on other Linux. Found from the environment by default. */
|
|
52
|
+
wsl?: {
|
|
53
|
+
distro: string;
|
|
54
|
+
mount: string;
|
|
55
|
+
} | null;
|
|
56
|
+
/** On WSL, the Windows Startup folder as WSL sees it; asked from `cmd.exe` by default (only for the login home). */
|
|
57
|
+
startupDir?: string;
|
|
47
58
|
}
|
|
48
59
|
export interface AutostartStatus {
|
|
49
60
|
/** False on a system sideby cannot start at login yet; `reason` says so. */
|
|
@@ -51,6 +62,8 @@ export interface AutostartStatus {
|
|
|
51
62
|
reason?: string;
|
|
52
63
|
state: AutostartState;
|
|
53
64
|
path: string;
|
|
65
|
+
/** How it starts at login; absent when unsupported. */
|
|
66
|
+
mechanism?: AutostartMechanism;
|
|
54
67
|
/** What sideby's agent starts (absent when off or foreign). */
|
|
55
68
|
programArguments?: string[];
|
|
56
69
|
/** The agent starts this sideby with this Node. */
|
|
@@ -104,8 +117,16 @@ export declare const programArgumentsFor: (l: AskLauncher) => string[];
|
|
|
104
117
|
export declare function plistContent(args: readonly string[], agent?: LoginAgent, environment?: Record<string, string>): string;
|
|
105
118
|
/** The ProgramArguments of a file sideby wrote; null when it holds none. */
|
|
106
119
|
export declare function parseProgramArguments(content: string): string[] | null;
|
|
120
|
+
/** The mechanism for this system and agent; null when there is none. Only the Panel's agent runs outside macOS. */
|
|
121
|
+
export declare function autostartMechanism(ctx: AutostartContext, agent?: LoginAgent): AutostartMechanism | null;
|
|
122
|
+
/** The XDG autostart entry; the `sideby-args` line keeps the arguments for status. */
|
|
123
|
+
export declare function desktopContent(args: readonly string[], agent?: LoginAgent): string;
|
|
124
|
+
/** The Windows Startup script: runs `wsl.exe` with a hidden window and does not wait for it. */
|
|
125
|
+
export declare function vbsContent(args: readonly string[], distro: string, agent?: LoginAgent): string;
|
|
126
|
+
/** What turning it on means for the user, by mechanism; used by the CLI and the Panel. */
|
|
127
|
+
export declare function autostartWhen(mech: AutostartMechanism | undefined): string;
|
|
107
128
|
/** Whether a sideby agent (with the marker) is installed; reads only that one file. */
|
|
108
|
-
export declare function autostartInstalled(home: string, agent?: LoginAgent): Promise<boolean>;
|
|
129
|
+
export declare function autostartInstalled(home: string, agent?: LoginAgent, ctx?: Partial<AutostartContext>): Promise<boolean>;
|
|
109
130
|
export declare function autostartStatus(ctx: AutostartContext, agent?: LoginAgent): Promise<AutostartStatus>;
|
|
110
131
|
/** Why the agent cannot start this launcher, with what to do instead; null when it can. */
|
|
111
132
|
export declare function autostartLauncherProblem(l: AskLauncher, command?: string): Promise<{
|
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
// Start the Panel at login (spec §3.29, ADR-0029): a LaunchAgent on macOS
|
|
2
|
-
//
|
|
1
|
+
// Start the Panel at login (spec §3.29, ADR-0029, ADR-0055): a LaunchAgent on macOS, an XDG autostart entry on Linux,
|
|
2
|
+
// and a `.vbs` in the Windows Startup folder under WSL, each running this Node and this sideby's entry with
|
|
3
|
+
// `ui --background --no-open`. sideby writes, replaces or removes only a file that carries its marker; any other
|
|
3
4
|
// file at that path is reported and left alone. Every program runs through `AutostartContext.exec`, so tests never
|
|
4
5
|
// load a real agent.
|
|
5
6
|
import { execFile } from 'node:child_process';
|
|
6
7
|
import { mkdir, readFile, rm } from 'node:fs/promises';
|
|
7
8
|
import { tmpdir, userInfo } from 'node:os';
|
|
8
|
-
import { dirname, join } from 'node:path';
|
|
9
|
+
import { dirname, isAbsolute, join } from 'node:path';
|
|
9
10
|
import { UserError } from './errors.js';
|
|
10
11
|
import { fileHash, realpathOrNull, sha256, statOrNull, writeIfUnchanged } from './fs-safe.js';
|
|
11
12
|
import { askLauncher, launcherProblem } from './terminal.js';
|
|
13
|
+
import { toUnix } from './windows-dirs.js';
|
|
12
14
|
export const AUTOSTART_LABEL = 'dev.sideby.panel';
|
|
13
15
|
/** Present in every agent sideby writes; a file without it is someone else's. */
|
|
14
16
|
export const AUTOSTART_MARKER = 'Written by `sideby autostart`';
|
|
17
|
+
/** The Windows file name under WSL; its folder is the current Windows user's Startup folder. */
|
|
18
|
+
export const WSL_STARTUP_FILE = 'sideby-panel.vbs';
|
|
15
19
|
export const defaultExec = (file, args) => new Promise((resolve) => {
|
|
16
20
|
execFile(file, [...args], { timeout: 15_000 }, (err, stdout, stderr) => {
|
|
17
21
|
const code = err ? (typeof err.code === 'number' ? err.code : 1) : 0;
|
|
@@ -80,7 +84,127 @@ export function parseProgramArguments(content) {
|
|
|
80
84
|
return [...m[1].matchAll(/<string>([\s\S]*?)<\/string>/g)].map((s) => unxml(s[1]));
|
|
81
85
|
}
|
|
82
86
|
const platformOf = (ctx) => ctx.platform ?? process.platform;
|
|
83
|
-
const UNSUPPORTED = 'sideby
|
|
87
|
+
const UNSUPPORTED = 'sideby cannot start at login on this system yet; it can on macOS, Linux and WSL';
|
|
88
|
+
const UNSUPPORTED_AGENT = 'this login item is for macOS only';
|
|
89
|
+
function wslOf(ctx) {
|
|
90
|
+
if (ctx.wsl !== undefined)
|
|
91
|
+
return ctx.wsl;
|
|
92
|
+
const distro = (ctx.env ?? process.env).WSL_DISTRO_NAME;
|
|
93
|
+
return distro ? { distro, mount: '/mnt' } : null;
|
|
94
|
+
}
|
|
95
|
+
/** The mechanism for this system and agent; null when there is none. Only the Panel's agent runs outside macOS. */
|
|
96
|
+
export function autostartMechanism(ctx, agent = PANEL_AGENT) {
|
|
97
|
+
const platform = platformOf(ctx);
|
|
98
|
+
if (platform === 'darwin')
|
|
99
|
+
return 'launchd';
|
|
100
|
+
if (platform !== 'linux' || agent.label !== AUTOSTART_LABEL)
|
|
101
|
+
return null;
|
|
102
|
+
return wslOf(ctx) ? 'wsl-startup' : 'xdg';
|
|
103
|
+
}
|
|
104
|
+
const loginHomeOf = (ctx) => {
|
|
105
|
+
if (ctx.loginHome !== undefined)
|
|
106
|
+
return ctx.loginHome;
|
|
107
|
+
try {
|
|
108
|
+
return userInfo().homedir;
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
return '';
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* The Windows Startup folder as WSL sees it, from one `cmd.exe` call. Another HOME than the login one (a demo or test
|
|
116
|
+
* HOME) gets a folder inside it instead, so it never writes into the real Windows profile.
|
|
117
|
+
*/
|
|
118
|
+
async function wslStartupDir(ctx, mount) {
|
|
119
|
+
if (ctx.startupDir)
|
|
120
|
+
return ctx.startupDir;
|
|
121
|
+
if (loginHomeOf(ctx) !== ctx.home)
|
|
122
|
+
return join(ctx.home, '.sideby-windows-startup');
|
|
123
|
+
const r = await (ctx.exec ?? defaultExec)(join(mount, 'c', 'Windows', 'System32', 'cmd.exe'), [
|
|
124
|
+
'/d',
|
|
125
|
+
'/c',
|
|
126
|
+
'echo %APPDATA%',
|
|
127
|
+
]).catch(() => null);
|
|
128
|
+
const appData = r?.code === 0 ? toUnix(r.output.trim().split(/\r?\n/)[0] ?? '', mount) : undefined;
|
|
129
|
+
return appData ? join(appData, 'Microsoft', 'Windows', 'Start Menu', 'Programs', 'Startup') : null;
|
|
130
|
+
}
|
|
131
|
+
/** Where the agent's file goes for this mechanism; null when Windows could not be asked. */
|
|
132
|
+
async function agentFile(ctx, agent, mech) {
|
|
133
|
+
if (mech === 'launchd')
|
|
134
|
+
return agentPath(ctx.home, agent);
|
|
135
|
+
if (mech === 'xdg') {
|
|
136
|
+
const xdg = (ctx.env ?? process.env).XDG_CONFIG_HOME;
|
|
137
|
+
const config = xdg && isAbsolute(xdg) ? xdg : join(ctx.home, '.config');
|
|
138
|
+
return join(config, 'autostart', `${agent.label}.desktop`);
|
|
139
|
+
}
|
|
140
|
+
const dir = await wslStartupDir(ctx, wslOf(ctx).mount);
|
|
141
|
+
return dir ? join(dir, WSL_STARTUP_FILE) : null;
|
|
142
|
+
}
|
|
143
|
+
/** The arguments the agent records: under WSL, `--wait` keeps `wsl.exe` attached so WSL keeps the distribution up. */
|
|
144
|
+
const wantedArguments = (agent, l, mech) => mech === 'wsl-startup' ? [...agent.programArguments(l), '--wait'] : agent.programArguments(l);
|
|
145
|
+
/** One argument of a desktop entry's `Exec` line (Desktop Entry Specification, "The Exec key"). */
|
|
146
|
+
function desktopArg(a) {
|
|
147
|
+
const q = /^[A-Za-z0-9_/.:=+,@-]+$/.test(a) ? a : `"${a.replace(/[\\"`$]/g, (m) => `\\${m}`)}"`;
|
|
148
|
+
return q.replace(/%/g, '%%');
|
|
149
|
+
}
|
|
150
|
+
/** The XDG autostart entry; the `sideby-args` line keeps the arguments for status. */
|
|
151
|
+
export function desktopContent(args, agent = PANEL_AGENT) {
|
|
152
|
+
return `[Desktop Entry]
|
|
153
|
+
# ${agent.marker}: ${agent.comment}. Turn it off with \`sideby ${agent.command} off\`.
|
|
154
|
+
# sideby-args: ${JSON.stringify(args)}
|
|
155
|
+
Type=Application
|
|
156
|
+
Name=sideby panel
|
|
157
|
+
Comment=${agent.comment}
|
|
158
|
+
Exec=${args.map(desktopArg).join(' ')}
|
|
159
|
+
Terminal=false
|
|
160
|
+
NoDisplay=true
|
|
161
|
+
X-GNOME-Autostart-enabled=true
|
|
162
|
+
`;
|
|
163
|
+
}
|
|
164
|
+
/** The Windows Startup script: runs `wsl.exe` with a hidden window and does not wait for it. */
|
|
165
|
+
export function vbsContent(args, distro, agent = PANEL_AGENT) {
|
|
166
|
+
const q = (a) => `""${a}""`;
|
|
167
|
+
// `wsl.exe -d` does not unquote the distribution name (WSL 2.4.13 exits -1), so it goes bare; see `unsafeDistro`.
|
|
168
|
+
const line = `wsl.exe -d ${distro} --exec ${args.map(q).join(' ')}`;
|
|
169
|
+
return [
|
|
170
|
+
`' ${agent.marker}: ${agent.comment.replace(/ at login$/, '')} when you sign in to Windows. Turn it off with \`sideby ${agent.command} off\`.`,
|
|
171
|
+
`' sideby-args: ${JSON.stringify(args)}`,
|
|
172
|
+
`CreateObject("WScript.Shell").Run "${line}", 0, False`,
|
|
173
|
+
'',
|
|
174
|
+
].join('\r\n');
|
|
175
|
+
}
|
|
176
|
+
/** What a WSL Startup script cannot carry safely: a `"`, a `%`, or anything outside printable ASCII. */
|
|
177
|
+
const unsafeDistro = (s) => !/^[A-Za-z0-9._-]+$/.test(s);
|
|
178
|
+
const unsafeForVbs = (s) => !/^[\x20-\x7e]+$/.test(s) || /["%]/.test(s);
|
|
179
|
+
function contentFor(ctx, agent, mech, args) {
|
|
180
|
+
if (mech === 'xdg')
|
|
181
|
+
return desktopContent(args, agent);
|
|
182
|
+
if (mech === 'wsl-startup')
|
|
183
|
+
return vbsContent(args, wslOf(ctx).distro, agent);
|
|
184
|
+
return plistContent(args, agent, agent.environment?.(ctx.env ?? process.env));
|
|
185
|
+
}
|
|
186
|
+
function parseArgsFor(mech, content) {
|
|
187
|
+
if (mech === 'launchd')
|
|
188
|
+
return parseProgramArguments(content);
|
|
189
|
+
const m = /sideby-args: (\[.*\])/.exec(content);
|
|
190
|
+
if (!m)
|
|
191
|
+
return null;
|
|
192
|
+
try {
|
|
193
|
+
const v = JSON.parse(m[1]);
|
|
194
|
+
return Array.isArray(v) && v.every((x) => typeof x === 'string') ? v : null;
|
|
195
|
+
}
|
|
196
|
+
catch {
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/** What turning it on means for the user, by mechanism; used by the CLI and the Panel. */
|
|
201
|
+
export function autostartWhen(mech) {
|
|
202
|
+
if (mech === 'wsl-startup')
|
|
203
|
+
return 'when you sign in to Windows';
|
|
204
|
+
if (mech === 'xdg')
|
|
205
|
+
return 'when your desktop session starts';
|
|
206
|
+
return 'at login';
|
|
207
|
+
}
|
|
84
208
|
async function readAgent(path) {
|
|
85
209
|
try {
|
|
86
210
|
return await readFile(path, 'utf8');
|
|
@@ -92,20 +216,32 @@ async function readAgent(path) {
|
|
|
92
216
|
}
|
|
93
217
|
}
|
|
94
218
|
/** Whether a sideby agent (with the marker) is installed; reads only that one file. */
|
|
95
|
-
export async function autostartInstalled(home, agent = PANEL_AGENT) {
|
|
96
|
-
const
|
|
219
|
+
export async function autostartInstalled(home, agent = PANEL_AGENT, ctx = {}) {
|
|
220
|
+
const c = { ...ctx, home };
|
|
221
|
+
const mech = autostartMechanism(c, agent);
|
|
222
|
+
const path = mech ? await agentFile(c, agent, mech).catch(() => null) : null;
|
|
223
|
+
const content = path ? await readAgent(path).catch(() => null) : null;
|
|
97
224
|
return content?.includes(agent.marker) ?? false;
|
|
98
225
|
}
|
|
99
226
|
export async function autostartStatus(ctx, agent = PANEL_AGENT) {
|
|
100
|
-
const
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
227
|
+
const mech = autostartMechanism(ctx, agent);
|
|
228
|
+
const unsupported = (reason, path = agentPath(ctx.home, agent)) => ({
|
|
229
|
+
supported: false,
|
|
230
|
+
reason,
|
|
231
|
+
path,
|
|
232
|
+
current: false,
|
|
233
|
+
state: 'off',
|
|
234
|
+
});
|
|
235
|
+
if (!mech)
|
|
236
|
+
return unsupported(platformOf(ctx) === 'linux' || platformOf(ctx) === 'darwin' ? UNSUPPORTED_AGENT : UNSUPPORTED);
|
|
237
|
+
const path = await agentFile(ctx, agent, mech);
|
|
238
|
+
if (!path)
|
|
239
|
+
return unsupported('sideby could not ask Windows for your Startup folder (cmd.exe did not answer); check that WSL can run Windows programs, then try again', '');
|
|
240
|
+
const base = { supported: true, path, mechanism: mech, current: false };
|
|
105
241
|
const content = await readAgent(path);
|
|
106
242
|
if (content === null)
|
|
107
243
|
return { ...base, state: 'off' };
|
|
108
|
-
const args = content.includes(agent.marker) ?
|
|
244
|
+
const args = content.includes(agent.marker) ? parseArgsFor(mech, content) : null;
|
|
109
245
|
if (!args)
|
|
110
246
|
return { ...base, state: 'foreign' };
|
|
111
247
|
const missing = [];
|
|
@@ -113,9 +249,11 @@ export async function autostartStatus(ctx, agent = PANEL_AGENT) {
|
|
|
113
249
|
if (!(await statOrNull(p)))
|
|
114
250
|
missing.push(p);
|
|
115
251
|
const launcher = ctx.launcher ?? askLauncher();
|
|
116
|
-
const want = agent
|
|
252
|
+
const want = wantedArguments(agent, launcher, mech);
|
|
117
253
|
const current = args.length === want.length && args.every((a, i) => a === want[i]);
|
|
118
|
-
const loaded = agent.restartOnCrash && !launchctlNote(ctx)
|
|
254
|
+
const loaded = mech === 'launchd' && agent.restartOnCrash && !launchctlNote(ctx)
|
|
255
|
+
? await agentLoaded(ctx, agent)
|
|
256
|
+
: undefined;
|
|
119
257
|
return {
|
|
120
258
|
...base,
|
|
121
259
|
state: missing.length ? 'stale' : 'on',
|
|
@@ -188,15 +326,28 @@ export async function planAutostart(ctx, action, agent = PANEL_AGENT) {
|
|
|
188
326
|
message: `${path} was not written by sideby, so sideby leaves it alone; look at it, and remove or rename it yourself before \`sideby ${agent.command} ${action}\` if it is not needed`,
|
|
189
327
|
},
|
|
190
328
|
});
|
|
329
|
+
const mech = status.mechanism;
|
|
330
|
+
const launchd = mech === 'launchd';
|
|
191
331
|
if (action === 'off')
|
|
192
|
-
return status.state === 'off'
|
|
332
|
+
return status.state === 'off'
|
|
333
|
+
? plan({})
|
|
334
|
+
: plan({ changed: true, commands: launchd ? [bootout(ctx, agent)] : [] });
|
|
193
335
|
const launcher = ctx.launcher ?? askLauncher();
|
|
194
336
|
const blocked = await autostartLauncherProblem(launcher, agent.command);
|
|
195
337
|
if (blocked)
|
|
196
338
|
return plan({ blocked });
|
|
197
|
-
const programArguments = agent
|
|
198
|
-
|
|
339
|
+
const programArguments = wantedArguments(agent, launcher, mech);
|
|
340
|
+
if (mech === 'wsl-startup' && (programArguments.some(unsafeForVbs) || unsafeDistro(wslOf(ctx).distro)))
|
|
341
|
+
return plan({
|
|
342
|
+
blocked: {
|
|
343
|
+
code: 'unsafe-path',
|
|
344
|
+
message: `the path of sideby or Node, or the WSL distribution name, has a character the Windows Startup script cannot carry (\`"\`, \`%\` or a non-ASCII letter); install sideby with \`npm i -g sideby\` in an ordinary folder, then run \`sideby ${agent.command} on\` again`,
|
|
345
|
+
},
|
|
346
|
+
});
|
|
347
|
+
const content = contentFor(ctx, agent, mech, programArguments);
|
|
199
348
|
const same = hash !== null && hash === sha256(content);
|
|
349
|
+
if (!launchd)
|
|
350
|
+
return plan({ changed: !same, content, programArguments });
|
|
200
351
|
// The file alone does not start it: launchd may have let it go (a `launchctl bootout`, a failed start), and then
|
|
201
352
|
// only loading it again brings it back.
|
|
202
353
|
const loaded = !same || (status.loaded ?? (await agentLoaded(ctx, agent)));
|
|
@@ -264,6 +415,26 @@ export async function applyAutostart(ctx, plan, agent = PANEL_AGENT) {
|
|
|
264
415
|
throw new UserError(`${path} changed since sideby looked at it; nothing was changed. Run the command again`, {
|
|
265
416
|
code: 'changed',
|
|
266
417
|
});
|
|
418
|
+
if (plan.status.mechanism !== 'launchd') {
|
|
419
|
+
// An autostart entry or a Startup script: nothing to tell, it takes effect at the next login.
|
|
420
|
+
if (plan.action === 'off') {
|
|
421
|
+
await rm(path, { force: true });
|
|
422
|
+
return { changed: true, state: 'off', path, loaded: false };
|
|
423
|
+
}
|
|
424
|
+
await mkdir(dirname(path), { recursive: true, mode: 0o755 });
|
|
425
|
+
if (!(await writeIfUnchanged(path, plan.hash, plan.content, 0o644)))
|
|
426
|
+
throw new UserError(`${path} changed while sideby was writing it; nothing was changed. Run the command again`, {
|
|
427
|
+
code: 'changed',
|
|
428
|
+
});
|
|
429
|
+
return {
|
|
430
|
+
changed: true,
|
|
431
|
+
state: 'on',
|
|
432
|
+
path,
|
|
433
|
+
programArguments: plan.programArguments,
|
|
434
|
+
loaded: false,
|
|
435
|
+
note: agent.later,
|
|
436
|
+
};
|
|
437
|
+
}
|
|
267
438
|
const exec = ctx.exec ?? defaultExec;
|
|
268
439
|
const note = launchctlNote(ctx);
|
|
269
440
|
const run = async (cmd) => (note ? null : exec(cmd[0], cmd.slice(1)));
|
|
@@ -274,6 +274,7 @@ export declare function autostartView(s: AutostartStatus, home: string): {
|
|
|
274
274
|
reason?: string | undefined;
|
|
275
275
|
state: import("../core/autostart.ts").AutostartState;
|
|
276
276
|
path: string;
|
|
277
|
+
mechanism?: import("../core/autostart.ts").AutostartMechanism | undefined;
|
|
277
278
|
current: boolean;
|
|
278
279
|
programArguments?: string[] | undefined;
|
|
279
280
|
missing?: string[] | undefined;
|
|
@@ -142,6 +142,7 @@ export function autostartView(s, home) {
|
|
|
142
142
|
...(s.reason ? { reason: s.reason } : {}),
|
|
143
143
|
state: s.state,
|
|
144
144
|
path: t(s.path),
|
|
145
|
+
...(s.mechanism ? { mechanism: s.mechanism } : {}),
|
|
145
146
|
current: s.current,
|
|
146
147
|
...(s.programArguments ? { programArguments: s.programArguments.map(t) } : {}),
|
|
147
148
|
...(s.missing ? { missing: s.missing.map(t) } : {}),
|
package/dist/src/panel/i18n.d.ts
CHANGED
package/dist/src/panel/i18n.js
CHANGED
|
@@ -1358,7 +1358,9 @@ const en = {
|
|
|
1358
1358
|
'as.hint': 'No window opens; the panel is up to date when you open it.',
|
|
1359
1359
|
'as.checking': 'Checking…',
|
|
1360
1360
|
'as.failed': 'Could not check: {msg}',
|
|
1361
|
-
'as.unsupported': 'Not supported on this system yet; Linux and
|
|
1361
|
+
'as.unsupported': 'Not supported on this system yet; it works on macOS, Linux and WSL.',
|
|
1362
|
+
'as.labelWsl': 'Start sideby in the background when you sign in to Windows',
|
|
1363
|
+
'as.hintXdg': 'No window opens; your desktop session starts it at login.',
|
|
1362
1364
|
'as.foreign': 'A login item with the same name was not made by sideby, so sideby leaves it alone.',
|
|
1363
1365
|
'as.stale': 'It points to a sideby that is no longer there.',
|
|
1364
1366
|
'as.other': 'It starts another copy of sideby, not this one.',
|
|
@@ -2831,7 +2833,9 @@ const zh = {
|
|
|
2831
2833
|
'as.hint': '不打开窗口,打开面板时就是最新状态',
|
|
2832
2834
|
'as.checking': '正在检查…',
|
|
2833
2835
|
'as.failed': '没能检查:{msg}',
|
|
2834
|
-
'as.unsupported': '这个系统暂不支持,Linux 和
|
|
2836
|
+
'as.unsupported': '这个系统暂不支持,macOS、Linux 和 WSL 可以用。',
|
|
2837
|
+
'as.labelWsl': '登录 Windows 后在后台启动 sideby',
|
|
2838
|
+
'as.hintXdg': '不打开窗口,登录桌面时自动启动',
|
|
2835
2839
|
'as.foreign': '同名的登录项不是 sideby 建的,sideby 不动它。',
|
|
2836
2840
|
'as.stale': '它指向的 sideby 已经不在了。',
|
|
2837
2841
|
'as.other': '它启动的是另一份 sideby,不是现在这份。',
|
|
@@ -6153,8 +6153,9 @@ const MAIN = String.raw `
|
|
|
6153
6153
|
const st = li[k]
|
|
6154
6154
|
const s = st.status
|
|
6155
6155
|
const n = autostartNote(s, BOOT.readOnly)
|
|
6156
|
-
const
|
|
6157
|
-
const
|
|
6156
|
+
const mech = k === 'autostart' && s ? s.mechanism : undefined
|
|
6157
|
+
const label = lt(k, mech === 'wsl-startup' ? 'labelWsl' : 'label')
|
|
6158
|
+
const hint = [st.error ? lt(k, 'failed', { msg: st.error.message }) : lt(k, n.key === 'as.hint' && mech === 'xdg' ? 'hintXdg' : n.key.slice(3))]
|
|
6158
6159
|
// The menu bar item: how to bring it back once hidden, and why a running one may not show (Rectangle, Stats).
|
|
6159
6160
|
if (k === 'menubar' && s && s.supported && !st.error && n.key === 'as.hint') {
|
|
6160
6161
|
if (!n.on) hint.push(' ', lt(k, 'hintOff'))
|
package/package.json
CHANGED
package/schemas/autostart.json
CHANGED
|
@@ -45,6 +45,23 @@
|
|
|
45
45
|
"path": {
|
|
46
46
|
"type": "string"
|
|
47
47
|
},
|
|
48
|
+
"mechanism": {
|
|
49
|
+
"anyOf": [
|
|
50
|
+
{
|
|
51
|
+
"type": "string",
|
|
52
|
+
"const": "launchd"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"type": "string",
|
|
56
|
+
"const": "xdg"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"type": "string",
|
|
60
|
+
"const": "wsl-startup"
|
|
61
|
+
}
|
|
62
|
+
],
|
|
63
|
+
"description": "How it starts at login: a LaunchAgent (macOS), an XDG autostart entry (Linux desktop sessions), or a script in the Windows Startup folder (WSL). Absent when unsupported."
|
|
64
|
+
},
|
|
48
65
|
"programArguments": {
|
|
49
66
|
"type": "array",
|
|
50
67
|
"items": {
|
package/schemas/menubar.json
CHANGED
|
@@ -45,6 +45,23 @@
|
|
|
45
45
|
"path": {
|
|
46
46
|
"type": "string"
|
|
47
47
|
},
|
|
48
|
+
"mechanism": {
|
|
49
|
+
"anyOf": [
|
|
50
|
+
{
|
|
51
|
+
"type": "string",
|
|
52
|
+
"const": "launchd"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"type": "string",
|
|
56
|
+
"const": "xdg"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"type": "string",
|
|
60
|
+
"const": "wsl-startup"
|
|
61
|
+
}
|
|
62
|
+
],
|
|
63
|
+
"description": "How it starts at login: a LaunchAgent (macOS), an XDG autostart entry (Linux desktop sessions), or a script in the Windows Startup folder (WSL). Absent when unsupported."
|
|
64
|
+
},
|
|
48
65
|
"programArguments": {
|
|
49
66
|
"type": "array",
|
|
50
67
|
"items": {
|
package/skills/sideby/SKILL.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
name: sideby
|
|
3
3
|
description: Use when the user runs, or wants to run, several AI coding accounts (Claude Code, Codex, Grok Build, pi) side by side. Covers installing sideby and setting up a new account ("install sideby", "set up another Claude account", "add cc008", "配置一个 cc00x", "再加一个 Codex 账号"), explaining what accounts share and what stays separate ("what do my accounts share?", "这些账号共享了什么"), showing which account a session is ("show [cc001] in the status line", "加上账号标识"), finding a past session of any account ("找一下我上周改登录页的那个会话"), seeing accounts, quota and usage, moving on when one hits its 5-hour or weekly limit, moving the current task to another account ("用 cc008 继续", "交回 cc008"), adding a short command (alias) or a pick command that starts whichever account has the most quota ("加个 cc"), adding an API account from a vendor's docs ("加一个 DeepSeek API 账号"), supporting a new tool, and repairing drifted account directories (skills, hooks, rules or settings not shared, wrong symlinks, credential file permissions). Drives the `sideby` CLI with `--json`; the agent does every step except browser sign-in, filling in secrets and starting interactive sessions, which it hands to the user as one command (inside an Auto Handoff session, `sideby handoff ready --to` moves the task itself).
|
|
4
4
|
metadata:
|
|
5
|
-
version: "0.
|
|
5
|
+
version: "0.28.0"
|
|
6
6
|
requires:
|
|
7
7
|
bins: [sideby, node]
|
|
8
8
|
cliHelp: sideby --help
|
|
@@ -58,7 +58,7 @@ A value the key does not take fails with code `bad-value` and changes nothing; a
|
|
|
58
58
|
|
|
59
59
|
`sideby autostart --json` returns `supported`, `state` and `path`. `state` is `off`, `on`, `stale` (the Node or sideby it starts was moved; `missing` names it) or `foreign` (a file at that path sideby did not write: leave it, and tell the user). `current` is false when it starts another sideby than this one.
|
|
60
60
|
|
|
61
|
-
To turn it on ("start sideby at login", "开机启动"), run `sideby autostart on --json`: exit 10 returns the `content` of the file, the `programArguments` and the `commands` it will run. Show that, and run `sideby autostart on --yes --json` after the user agrees; `stale` or `current: false` is fixed the same way. `sideby autostart off` turns it off the same way. At login the Panel starts in the background without opening a window. macOS only
|
|
61
|
+
To turn it on ("start sideby at login", "开机启动"), run `sideby autostart on --json`: exit 10 returns the `content` of the file, the `programArguments` and the `commands` it will run. Show that, and run `sideby autostart on --yes --json` after the user agrees; `stale` or `current: false` is fixed the same way. `sideby autostart off` turns it off the same way. At login the Panel starts in the background without opening a window. `mechanism` says how: `launchd` (macOS), `xdg` (Linux, `~/.config/autostart/dev.sideby.panel.desktop`, run by desktop sessions only) or `wsl-startup` (WSL: `sideby-panel.vbs` in the Windows Startup folder, so it starts when the user signs in to Windows; `commands` is empty there and the change takes effect at the next sign-in, `sideby ui --background` starts it now). Native Windows has `supported` false and `on` fails with code `unsupported`; under WSL a path with `"`, `%` or non-ASCII letters fails with `unsafe-path`. Running from the npx cache or a temporary folder fails with `npx-cache` or `temp-dir`: hand the user `npm i -g sideby` first. `sideby update` keeps an existing login item pointing at the new version.
|
|
62
62
|
|
|
63
63
|
## Quota in the menu bar
|
|
64
64
|
|