sideby 0.16.1 → 0.18.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 +7 -3
- package/ai-tasks.json +90 -0
- package/dist/build.json +1 -1
- package/dist/src/cli/commands.d.ts +25 -1
- package/dist/src/cli/commands.js +802 -15
- package/dist/src/cli/json-schemas.js +252 -1
- package/dist/src/cli/main.js +143 -4
- 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 +222 -0
- package/dist/src/core/ask.js +465 -0
- package/dist/src/core/attachments.d.ts +50 -0
- package/dist/src/core/attachments.js +442 -0
- package/dist/src/core/autostart.d.ts +118 -0
- package/dist/src/core/autostart.js +302 -0
- package/dist/src/core/brand-mark.d.ts +49 -11
- package/dist/src/core/brand-mark.js +116 -38
- package/dist/src/core/config.d.ts +102 -0
- package/dist/src/core/config.js +289 -11
- 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 +17 -4
- package/dist/src/core/launch.js +32 -24
- package/dist/src/core/local-build.d.ts +17 -5
- package/dist/src/core/local-build.js +61 -23
- package/dist/src/core/lock.d.ts +30 -0
- package/dist/src/core/lock.js +143 -0
- package/dist/src/core/probe.d.ts +78 -0
- package/dist/src/core/probe.js +127 -0
- package/dist/src/core/quota-levels.d.ts +6 -1
- package/dist/src/core/quota-levels.js +16 -5
- package/dist/src/core/same-login.d.ts +9 -4
- package/dist/src/core/same-login.js +9 -4
- package/dist/src/core/secret-file.d.ts +26 -0
- package/dist/src/core/secret-file.js +126 -7
- 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 +93 -0
- package/dist/src/core/terminal.js +376 -0
- package/dist/src/core/update.d.ts +34 -12
- package/dist/src/core/update.js +96 -84
- 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 +6 -0
- package/dist/src/families/claude/quota-cache.d.ts +24 -7
- package/dist/src/families/claude/quota-cache.js +72 -21
- package/dist/src/families/codex/handoff-hook.js +4 -4
- package/dist/src/families/codex/index.js +16 -0
- package/dist/src/families/codex/login-key.d.ts +8 -0
- package/dist/src/families/codex/login-key.js +33 -0
- package/dist/src/families/grok/handoff-hook.js +4 -4
- package/dist/src/families/grok/index.js +4 -0
- package/dist/src/families/login-keys.d.ts +6 -0
- package/dist/src/families/login-keys.js +6 -0
- package/dist/src/families/pi/index.js +5 -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 +15 -21
- package/dist/src/panel/handler.d.ts +41 -2
- package/dist/src/panel/handler.js +394 -10
- package/dist/src/panel/i18n.d.ts +205 -2
- package/dist/src/panel/i18n.js +441 -35
- package/dist/src/panel/page-logic.d.ts +301 -0
- package/dist/src/panel/page-logic.js +532 -0
- package/dist/src/panel/page-script.js +1135 -185
- package/dist/src/panel/page-styles.js +111 -32
- package/dist/src/panel/page.d.ts +12 -0
- package/dist/src/panel/page.js +7 -0
- package/dist/src/panel/server.d.ts +16 -2
- package/dist/src/panel/server.js +41 -13
- package/dist/src/plugins/check.d.ts +47 -0
- package/dist/src/plugins/check.js +544 -0
- package/dist/src/plugins/scaffold.d.ts +21 -0
- package/dist/src/plugins/scaffold.js +123 -0
- package/dist/src/quota/statusline-tap.js +1 -1
- package/dist/src/runtime.d.ts +19 -1
- package/dist/src/runtime.js +53 -14
- package/dist/src/types.d.ts +33 -0
- package/package.json +4 -3
- package/schemas/ask-choices.json +168 -0
- package/schemas/ask-print.json +87 -0
- package/schemas/ask.json +180 -0
- package/schemas/autostart.json +165 -0
- package/schemas/config-get.json +132 -0
- package/schemas/config-set.json +107 -0
- package/schemas/config.json +90 -7
- package/schemas/edit.json +119 -0
- package/schemas/error.json +4 -0
- package/schemas/families.json +4 -0
- package/schemas/key.json +93 -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/plugins-check.json +113 -0
- package/schemas/plugins-new.json +87 -0
- package/schemas/terminal.json +152 -0
- package/schemas/try.json +109 -0
- package/schemas/update.json +4 -0
- package/skills/sideby/SKILL.md +16 -6
- package/skills/sideby/references/accounts.md +1 -1
- package/skills/sideby/references/ai-tasks.md +126 -0
- package/skills/sideby/references/handoff.md +3 -1
- package/skills/sideby/references/panel.md +20 -0
- package/skills/sideby/references/update.md +1 -1
|
@@ -4,6 +4,7 @@ import { execFile } from 'node:child_process';
|
|
|
4
4
|
import { readFile } from 'node:fs/promises';
|
|
5
5
|
import { promisify } from 'node:util';
|
|
6
6
|
import { writeFileAtomic } from './fs-safe.js';
|
|
7
|
+
import { BRIEF_DONE } from './handoff-chain.js';
|
|
7
8
|
const run = promisify(execFile);
|
|
8
9
|
const GIT_TIMEOUT_MS = 3000;
|
|
9
10
|
const MAX_STATUS_LINES = 50;
|
|
@@ -54,9 +55,11 @@ async function nonEmpty(path) {
|
|
|
54
55
|
}
|
|
55
56
|
}
|
|
56
57
|
export const ASSEMBLED_NOTE = '> Put together by sideby from the previous session’s records, without a model; it may be incomplete. Check the repository before continuing.';
|
|
58
|
+
export const UNFINISHED_NOTE = '> The previous session did not finish the brief above. sideby added what it found in the session’s records below.';
|
|
57
59
|
/**
|
|
58
60
|
* Writes the final Brief to `target` (mode 600) and says where it came from: the user's or the session's Brief
|
|
59
|
-
* named in `ready`, the session's Brief already at `target`, else `assembled`, plus the repository state.
|
|
61
|
+
* named in `ready`, the session's Brief already at `target`, else `assembled`, plus the repository state. A session's
|
|
62
|
+
* Brief without `BRIEF_DONE` is kept, with `assembled` added under it (ADR-0032).
|
|
60
63
|
*/
|
|
61
64
|
export async function finishBrief(opts) {
|
|
62
65
|
let body = await nonEmpty(opts.ready.brief);
|
|
@@ -69,6 +72,8 @@ export async function finishBrief(opts) {
|
|
|
69
72
|
source = 'sideby';
|
|
70
73
|
body = `${ASSEMBLED_NOTE}\n\n${opts.assembled ?? 'sideby could not read the previous session’s records.\n'}`;
|
|
71
74
|
}
|
|
75
|
+
else if (source === 'agent' && !body.includes(BRIEF_DONE) && opts.assembled)
|
|
76
|
+
body = `${body.trimEnd()}\n\n${UNFINISHED_NOTE}\n\n${opts.assembled}`;
|
|
72
77
|
const repo = await gitSection(opts.cwd);
|
|
73
78
|
await writeFileAtomic(opts.target, `${body.trimEnd()}\n${repo ? `\n${repo}` : ''}`, 0o600);
|
|
74
79
|
return { path: opts.target, source };
|
|
@@ -5,6 +5,15 @@ export declare const HANDOFF_ENV: {
|
|
|
5
5
|
readonly dir: 'SIDEBY_HANDOFF_DIR';
|
|
6
6
|
};
|
|
7
7
|
export type HandoffTrigger = 'threshold' | 'limit' | 'manual';
|
|
8
|
+
/** The last line of a Brief the session finished (ADR-0032); a Brief without it is treated as unfinished. */
|
|
9
|
+
export declare const BRIEF_DONE = "<!-- handoff brief complete -->";
|
|
10
|
+
/** One Quota window as the hook read it: which window, how full, when it resets. */
|
|
11
|
+
export interface WindowReading {
|
|
12
|
+
/** `5h`, `7d` or `<n>m`, as `QuotaWindow.label`. */
|
|
13
|
+
label: string;
|
|
14
|
+
usedPercent: number;
|
|
15
|
+
resetsAt: string;
|
|
16
|
+
}
|
|
8
17
|
/** What the parent decided the next Handoff would do, refreshed while the Host runs. */
|
|
9
18
|
export interface PlanFile {
|
|
10
19
|
/** The run this plan is for; a plan left by an earlier hop of the chain is ignored. */
|
|
@@ -18,6 +27,8 @@ export interface PlanFile {
|
|
|
18
27
|
until?: string;
|
|
19
28
|
prepareAt: number;
|
|
20
29
|
threshold: number;
|
|
30
|
+
/** Each window hands over at its own pace (ADR-0032); missing (an older parent) means every window uses `threshold`. */
|
|
31
|
+
adaptive?: boolean;
|
|
21
32
|
/** False when the session cannot write its Brief: no preparing step, and the threshold only ends the turn. */
|
|
22
33
|
agentBrief?: boolean;
|
|
23
34
|
/** The parent reads `to` from a manual request; a parent from before 0.9.3 does not write it and ignores `to`. */
|
|
@@ -30,6 +41,15 @@ export interface RunState {
|
|
|
30
41
|
stopBlocked?: boolean;
|
|
31
42
|
/** The user was told this run waits for a reset instead of moving on (ADR-0018). */
|
|
32
43
|
waitNoticeSentAt?: string;
|
|
44
|
+
/** The window that reached its Hand-over Level, when the threshold message went out. */
|
|
45
|
+
thresholdWindow?: WindowReading;
|
|
46
|
+
/** Each window at the last `Stop`, by label: where the next turn's growth is measured from (ADR-0032). */
|
|
47
|
+
turnMark?: Record<string, {
|
|
48
|
+
usedPercent: number;
|
|
49
|
+
resetsAt: string;
|
|
50
|
+
}>;
|
|
51
|
+
/** Each window's growth in the run's last finished turns, newest last, by label. */
|
|
52
|
+
turnUse?: Record<string, number[]>;
|
|
33
53
|
sessionId?: string;
|
|
34
54
|
transcriptPath?: string;
|
|
35
55
|
}
|
|
@@ -41,6 +61,8 @@ export interface ReadyFile {
|
|
|
41
61
|
/** The Brief file, when the session or the user wrote one. */
|
|
42
62
|
brief?: string;
|
|
43
63
|
briefSource?: 'agent' | 'user';
|
|
64
|
+
/** The window that started a `threshold` or `limit` Handoff. */
|
|
65
|
+
window?: WindowReading;
|
|
44
66
|
/** `sideby handoff ready --to`: the Account ref to hand over to. */
|
|
45
67
|
to?: string;
|
|
46
68
|
sessionId?: string;
|
|
@@ -59,6 +81,8 @@ export interface ChainHop {
|
|
|
59
81
|
trigger?: HandoffTrigger;
|
|
60
82
|
briefSource?: 'agent' | 'sideby' | 'user';
|
|
61
83
|
brief?: string;
|
|
84
|
+
/** The window that started the Handoff, when the Quota did. */
|
|
85
|
+
window?: WindowReading;
|
|
62
86
|
}
|
|
63
87
|
export interface ChainFile {
|
|
64
88
|
hops: ChainHop[];
|
|
@@ -13,6 +13,8 @@ export const HANDOFF_ENV = {
|
|
|
13
13
|
family: 'SIDEBY_HANDOFF_FAMILY',
|
|
14
14
|
dir: 'SIDEBY_HANDOFF_DIR',
|
|
15
15
|
};
|
|
16
|
+
/** The last line of a Brief the session finished (ADR-0032); a Brief without it is treated as unfinished. */
|
|
17
|
+
export const BRIEF_DONE = '<!-- handoff brief complete -->';
|
|
16
18
|
export const FILES = {
|
|
17
19
|
plan: 'plan.json',
|
|
18
20
|
ready: 'ready.json',
|
|
@@ -21,10 +21,11 @@ export declare function hookEntryWorks(env: Env): Promise<boolean>;
|
|
|
21
21
|
* Runs `ref` with Auto Handoff when the config, the Family, the run and the terminal allow it, and returns the exit
|
|
22
22
|
* code of the last Host; null when Auto Handoff does not apply and the caller should run the Host as usual.
|
|
23
23
|
*/
|
|
24
|
-
export declare function runWithHandoff(rt: Runtime, ref: string, userArgs: readonly string[], io: HandoffIo,
|
|
25
|
-
/** For tests: how long the Host gets to exit after SIGTERM. */
|
|
26
|
-
opts?: {
|
|
24
|
+
export declare function runWithHandoff(rt: Runtime, ref: string, userArgs: readonly string[], io: HandoffIo, opts?: {
|
|
25
|
+
/** For tests: how long the Host gets to exit after SIGTERM. */
|
|
27
26
|
exitGraceMs?: number;
|
|
27
|
+
/** An AI Task (ADR-0031): every Account it hands over to starts without permission bypasses too. */
|
|
28
|
+
aiTask?: boolean;
|
|
28
29
|
}): Promise<number | null>;
|
|
29
30
|
/**
|
|
30
31
|
* For `sideby handoff ready`: where a Handoff from the session running under `env` would go now, using the chain's
|
|
@@ -6,7 +6,7 @@ import { watch } from 'node:fs';
|
|
|
6
6
|
import { rm } from 'node:fs/promises';
|
|
7
7
|
import { join } from 'node:path';
|
|
8
8
|
import { HOOK_FAMILIES } from '../handoff/hook.js';
|
|
9
|
-
import { firstPrompt } from '../handoff/messages.js';
|
|
9
|
+
import { firstPrompt, windowText } from '../handoff/messages.js';
|
|
10
10
|
import { aliasArgs } from './config.js';
|
|
11
11
|
import { UserError } from './errors.js';
|
|
12
12
|
import { finishBrief } from './handoff-brief.js';
|
|
@@ -147,14 +147,13 @@ async function decide(rt, account, used, to, manual = false) {
|
|
|
147
147
|
* Runs `ref` with Auto Handoff when the config, the Family, the run and the terminal allow it, and returns the exit
|
|
148
148
|
* code of the last Host; null when Auto Handoff does not apply and the caller should run the Host as usual.
|
|
149
149
|
*/
|
|
150
|
-
export async function runWithHandoff(rt, ref, userArgs, io,
|
|
151
|
-
/** For tests: how long the Host gets to exit after SIGTERM. */
|
|
152
|
-
opts = {}) {
|
|
150
|
+
export async function runWithHandoff(rt, ref, userArgs, io, opts = {}) {
|
|
153
151
|
const grace = opts.exitGraceMs ?? EXIT_GRACE_MS;
|
|
154
152
|
const settings = rt.handoffSettings();
|
|
155
153
|
if (!settings.auto || !io.stdin.isTTY)
|
|
156
154
|
return null;
|
|
157
|
-
const
|
|
155
|
+
const launchOpts = opts.aiTask ? { aiTask: true } : {};
|
|
156
|
+
const firstLaunch = await rt.prepareLaunch(ref, userArgs, 'run', launchOpts);
|
|
158
157
|
const firstHandoff = firstLaunch.family.handoff;
|
|
159
158
|
// Only built-in Families have a hook reader (spec §3.17); a Plugin Family can only take over.
|
|
160
159
|
if (!firstHandoff?.starts.length || !HOOK_FAMILIES.includes(firstLaunch.family.id))
|
|
@@ -183,7 +182,7 @@ opts = {}) {
|
|
|
183
182
|
let hop = { ref, args: [...aliasArgs(own), ...userArgs] };
|
|
184
183
|
let n = 1;
|
|
185
184
|
for (;;) {
|
|
186
|
-
const launch = n === 1 ? firstLaunch : await rt.prepareLaunch(hop.ref, hop.args, 'run');
|
|
185
|
+
const launch = n === 1 ? firstLaunch : await rt.prepareLaunch(hop.ref, hop.args, 'run', launchOpts);
|
|
187
186
|
const account = launch.account;
|
|
188
187
|
const h = launch.family.handoff;
|
|
189
188
|
if (!h)
|
|
@@ -236,6 +235,7 @@ opts = {}) {
|
|
|
236
235
|
...(d.kind === 'wait' ? { until: d.until } : {}),
|
|
237
236
|
prepareAt: settings.prepareAt,
|
|
238
237
|
threshold: settings.threshold,
|
|
238
|
+
adaptive: settings.adaptive,
|
|
239
239
|
...(elig.agentBrief === false ? { agentBrief: false } : {}),
|
|
240
240
|
acceptsTo: true,
|
|
241
241
|
};
|
|
@@ -316,11 +316,16 @@ opts = {}) {
|
|
|
316
316
|
cwd: process.cwd(),
|
|
317
317
|
});
|
|
318
318
|
const last = hops.hops[hops.hops.length - 1];
|
|
319
|
-
Object.assign(last, {
|
|
319
|
+
Object.assign(last, {
|
|
320
|
+
trigger: ready.trigger,
|
|
321
|
+
briefSource: done.source,
|
|
322
|
+
brief: done.path,
|
|
323
|
+
...(ready.window ? { window: ready.window } : {}),
|
|
324
|
+
});
|
|
320
325
|
await writeJsonFile(join(dir, FILES.chain), hops);
|
|
321
326
|
await rm(join(dir, FILES.ready), { force: true });
|
|
322
327
|
await rm(join(dir, FILES.request), { force: true });
|
|
323
|
-
io.err(`sideby: ${account.ref} saved its session and is handing over because ${WHY[ready.trigger]}; next is ${decision.ref}${skippedText(decision)}. Brief: ${done.path}`);
|
|
328
|
+
io.err(`sideby: ${account.ref} saved its session and is handing over because ${WHY[ready.trigger]}${ready.window ? ` (${windowText(ready.window)})` : ''}; next is ${decision.ref}${skippedText(decision)}. Brief: ${done.path}`);
|
|
324
329
|
if (settings.countdownSeconds > 0 &&
|
|
325
330
|
(await countdown(io, settings.countdownSeconds, decision.ref, account.ref))) {
|
|
326
331
|
io.err(`sideby: staying in ${account.ref}`);
|
|
@@ -329,7 +334,7 @@ opts = {}) {
|
|
|
329
334
|
return ended.code;
|
|
330
335
|
}
|
|
331
336
|
const backArgs = [...h.continueArgs(hop.args), ...h.resumeArgs(ready.sessionId)];
|
|
332
|
-
const back = await rt.prepareLaunch(account.ref, backArgs, 'run');
|
|
337
|
+
const back = await rt.prepareLaunch(account.ref, backArgs, 'run', launchOpts);
|
|
333
338
|
// The same per-Account arguments as before (Grok's leader socket), without sideby's hooks.
|
|
334
339
|
const backElig = await h.eligibility(back.args, account, back.env);
|
|
335
340
|
return runHost({ ...back, args: beforeDashes(back.args, backElig.args ?? []) });
|
|
@@ -39,18 +39,31 @@ export declare function sidebyBinProblem(env: Env, why: string): Promise<string
|
|
|
39
39
|
* the Family's `selectVar` set for every Account but the Main Account.
|
|
40
40
|
*/
|
|
41
41
|
export declare function accountEnv(family: FamilyDef, account: Account, baseEnv: Env): Env;
|
|
42
|
-
export
|
|
42
|
+
export interface LaunchCommandOptions {
|
|
43
43
|
account: Account;
|
|
44
44
|
family: FamilyDef;
|
|
45
|
-
baseEnv: Env;
|
|
46
45
|
accountArgs: readonly string[];
|
|
47
46
|
userArgs: readonly string[];
|
|
48
47
|
command: 'run' | 'login';
|
|
48
|
+
/** An AI Task (spec §3.28): the Family's `aiTaskArgs` removes every permission bypass (ADR-0031). */
|
|
49
|
+
aiTask?: boolean;
|
|
50
|
+
/** Config `accountTitle`: set the terminal title to `[<label>]` and keep the Host from replacing it. */
|
|
51
|
+
title?: boolean;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The Host and its arguments for a Launch before any `launch.before` hook: Family defaults, the title arguments, the
|
|
55
|
+
* Account's config arguments, then the user's. Pure: reads no file and runs no Plugin, so a preview can show it.
|
|
56
|
+
*/
|
|
57
|
+
export declare function launchCommand(opts: LaunchCommandOptions): {
|
|
58
|
+
bin: string;
|
|
59
|
+
args: string[];
|
|
60
|
+
notice?: string;
|
|
61
|
+
};
|
|
62
|
+
export declare function prepareLaunch(opts: LaunchCommandOptions & {
|
|
63
|
+
baseEnv: Env;
|
|
49
64
|
bus: HookBus;
|
|
50
65
|
/** What the Host may show as the Account (`SIDEBY_LABEL`): the short command, else the ref. */
|
|
51
66
|
label?: string;
|
|
52
|
-
/** Config `accountTitle`: set the terminal title to `[<label>]` and keep the Host from replacing it. */
|
|
53
|
-
title?: boolean;
|
|
54
67
|
}): Promise<PreparedLaunch>;
|
|
55
68
|
/**
|
|
56
69
|
* Runs the Host with the terminal attached and returns sideby's exit code (spec §3.5):
|
package/dist/src/core/launch.js
CHANGED
|
@@ -72,6 +72,34 @@ export function accountEnv(family, account, baseEnv) {
|
|
|
72
72
|
env[family.selectVar] = account.dir;
|
|
73
73
|
return env;
|
|
74
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* The Host and its arguments for a Launch before any `launch.before` hook: Family defaults, the title arguments, the
|
|
77
|
+
* Account's config arguments, then the user's. Pure: reads no file and runs no Plugin, so a preview can show it.
|
|
78
|
+
*/
|
|
79
|
+
export function launchCommand(opts) {
|
|
80
|
+
const { account, family } = opts;
|
|
81
|
+
if (opts.command === 'login') {
|
|
82
|
+
// Family arguments still apply: Codex must store a non-main login in the Account's own file.
|
|
83
|
+
const base = family.defaultArgs?.(account, []) ?? [];
|
|
84
|
+
return family.login.args
|
|
85
|
+
? { bin: family.bin, args: [...base, ...family.login.args] }
|
|
86
|
+
: { bin: family.bin, args: base, notice: family.login.hint };
|
|
87
|
+
}
|
|
88
|
+
const keep = opts.title && family.keepTitle && !opts.userArgs.some((a) => a.includes(family.keepTitle.key))
|
|
89
|
+
? family.keepTitle.args
|
|
90
|
+
: [];
|
|
91
|
+
const args = [
|
|
92
|
+
...(family.defaultArgs?.(account, opts.userArgs) ?? []),
|
|
93
|
+
...keep,
|
|
94
|
+
...opts.accountArgs,
|
|
95
|
+
...opts.userArgs,
|
|
96
|
+
];
|
|
97
|
+
return { bin: family.bin, args: opts.aiTask ? aiTaskArgs(family, args) : args };
|
|
98
|
+
}
|
|
99
|
+
/** The arguments of an AI Task's Launch, without the Family's permission bypasses (ADR-0031). */
|
|
100
|
+
function aiTaskArgs(family, args) {
|
|
101
|
+
return family.aiTaskArgs ? family.aiTaskArgs(args) : args;
|
|
102
|
+
}
|
|
75
103
|
export async function prepareLaunch(opts) {
|
|
76
104
|
const { account, family } = opts;
|
|
77
105
|
const env = accountEnv(family, account, opts.baseEnv);
|
|
@@ -84,29 +112,7 @@ export async function prepareLaunch(opts) {
|
|
|
84
112
|
// inherited from another sideby Launch never leaks through.
|
|
85
113
|
env.SIDEBY_ACCOUNT = account.ref;
|
|
86
114
|
env.SIDEBY_LABEL = opts.label || account.ref;
|
|
87
|
-
|
|
88
|
-
let notice;
|
|
89
|
-
if (opts.command === 'login') {
|
|
90
|
-
// Family arguments still apply: Codex must store a non-main login in the Account's own file.
|
|
91
|
-
const base = family.defaultArgs?.(account, []) ?? [];
|
|
92
|
-
if (family.login.args)
|
|
93
|
-
args = [...base, ...family.login.args];
|
|
94
|
-
else {
|
|
95
|
-
args = base;
|
|
96
|
-
notice = family.login.hint;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
const keep = opts.title && family.keepTitle && !opts.userArgs.some((a) => a.includes(family.keepTitle.key))
|
|
101
|
-
? family.keepTitle.args
|
|
102
|
-
: [];
|
|
103
|
-
args = [
|
|
104
|
-
...(family.defaultArgs?.(account, opts.userArgs) ?? []),
|
|
105
|
-
...keep,
|
|
106
|
-
...opts.accountArgs,
|
|
107
|
-
...opts.userArgs,
|
|
108
|
-
];
|
|
109
|
-
}
|
|
115
|
+
const { args, notice } = launchCommand(opts);
|
|
110
116
|
await opts.bus.run('launch.before', family.id, {
|
|
111
117
|
account,
|
|
112
118
|
family,
|
|
@@ -115,6 +121,8 @@ export async function prepareLaunch(opts) {
|
|
|
115
121
|
config: {},
|
|
116
122
|
command: opts.command,
|
|
117
123
|
});
|
|
124
|
+
// A `launch.before` hook cannot add a bypass back into an AI Task either.
|
|
125
|
+
const finalArgs = opts.aiTask && opts.command === 'run' ? aiTaskArgs(family, args) : args;
|
|
118
126
|
// Control characters would end the escape sequence early; labels are shell-safe names, so this is a guard only.
|
|
119
127
|
const title = opts.title
|
|
120
128
|
? [...`[${env.SIDEBY_LABEL ?? account.ref}]`].filter((ch) => ch >= ' ' && ch !== '\x7f').join('')
|
|
@@ -123,7 +131,7 @@ export async function prepareLaunch(opts) {
|
|
|
123
131
|
account,
|
|
124
132
|
family,
|
|
125
133
|
bin: family.bin,
|
|
126
|
-
args,
|
|
134
|
+
args: finalArgs,
|
|
127
135
|
env,
|
|
128
136
|
...(notice ? { notice } : {}),
|
|
129
137
|
...(title ? { title } : {}),
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Env } from '../types.ts';
|
|
2
|
+
import { type AutostartContext } from './autostart.ts';
|
|
2
3
|
import type { Paths } from './paths.ts';
|
|
3
4
|
import { type LocalBuild } from './version.ts';
|
|
4
5
|
export interface LocalDirs {
|
|
@@ -10,6 +11,12 @@ export interface LocalDirs {
|
|
|
10
11
|
export declare const pkgDir: (d: LocalDirs) => string;
|
|
11
12
|
export declare const globalPkg: (d: LocalDirs) => string;
|
|
12
13
|
export declare const devDir: (env: Env) => string;
|
|
14
|
+
/**
|
|
15
|
+
* The environment to ask npm for its global prefix in. A pnpm script gets pnpm's own `--dir` (`pnpm -C <dir> …`) as
|
|
16
|
+
* `npm_config_dir` and `npm_config_prefix`, and npm would answer with that directory; npm reads the user's real
|
|
17
|
+
* setting from its config files and from `NPM_CONFIG_PREFIX` without them.
|
|
18
|
+
*/
|
|
19
|
+
export declare function npmEnv(env: Env): Env;
|
|
13
20
|
/** Where the switch works, with npm's global prefix from `npm prefix -g`; null when npm cannot be asked. */
|
|
14
21
|
export declare function localDirs(env: Env): Promise<LocalDirs | null>;
|
|
15
22
|
export declare function kind(p: string): Promise<'link' | 'dir' | 'file' | null>;
|
|
@@ -50,19 +57,22 @@ export interface SwitchResult {
|
|
|
50
57
|
unchanged?: boolean;
|
|
51
58
|
restartedPanel: boolean;
|
|
52
59
|
/**
|
|
53
|
-
* Back on npm, `sideby update --yes` of the npm code brought the skill agents read to its version (true), or
|
|
54
|
-
* failed (false); absent for a switch to the Local Build, which has no skill of its own to bring.
|
|
60
|
+
* Back on npm, `sideby update --skill --yes` of the npm code brought the skill agents read to its version (true), or
|
|
61
|
+
* that failed (false); absent for a switch to the Local Build, which has no skill of its own to bring.
|
|
55
62
|
*/
|
|
56
63
|
skillSynced?: boolean;
|
|
57
|
-
/** With `skillSync: 'background'`: that `sideby update --yes` started on its own and is not waited for. */
|
|
64
|
+
/** With `skillSync: 'background'`: that `sideby update --skill --yes` started on its own and is not waited for. */
|
|
58
65
|
skillSyncStarted?: boolean;
|
|
59
66
|
/** Another install held the lock; nothing ran. */
|
|
60
67
|
busy?: boolean;
|
|
68
|
+
/** An existing login item (ADR-0029) now starts the sideby switched to; absent when there was none to change. */
|
|
69
|
+
refreshedAutostart?: boolean;
|
|
61
70
|
}
|
|
62
71
|
/**
|
|
63
72
|
* Puts `to` behind the global `sideby`. `local` links the newest Local Build; `npm` restores the kept package or
|
|
64
|
-
* installs `latest` (a failed install links the Local Build back, so `sideby` never goes missing). Afterwards
|
|
65
|
-
*
|
|
73
|
+
* installs `latest` (a failed install links the Local Build back, so `sideby` never goes missing). Afterwards
|
|
74
|
+
* (after-install.ts) an existing login item follows, back on npm the skill does, and a background Panel on `panelPort`
|
|
75
|
+
* starts again from the new code, last. One install at a time (the Update lock).
|
|
66
76
|
*/
|
|
67
77
|
export declare function switchLocal(paths: Paths, d: LocalDirs, to: LocalTarget, env: Env, opts?: {
|
|
68
78
|
panelPort?: () => Promise<number | null>;
|
|
@@ -72,4 +82,6 @@ export declare function switchLocal(paths: Paths, d: LocalDirs, to: LocalTarget,
|
|
|
72
82
|
* network and can take minutes, longer than a Portal waits for an answer (`background`, the Panel).
|
|
73
83
|
*/
|
|
74
84
|
skillSync?: 'wait' | 'background';
|
|
85
|
+
/** Internal, for tests: parts of the machine the login item refresh uses. */
|
|
86
|
+
autostart?: Partial<AutostartContext>;
|
|
75
87
|
}): Promise<SwitchResult>;
|
|
@@ -2,19 +2,33 @@
|
|
|
2
2
|
// these; `sideby local` and the Panel's version popover switch between the newest Local Build and npm without the
|
|
3
3
|
// checkout. Only an npm global install is handled: `<prefix>/lib/node_modules/sideby` is the folder every caller
|
|
4
4
|
// resolves, a link to `<dev>/pkg` while a Local Build runs.
|
|
5
|
-
import { lstat, mkdir, readFile, readlink, rename, rm, symlink } from 'node:fs/promises';
|
|
5
|
+
import { lstat, mkdir, readFile, readlink, realpath, rename, rm, symlink } from 'node:fs/promises';
|
|
6
6
|
import { homedir } from 'node:os';
|
|
7
7
|
import { dirname, join, relative } from 'node:path';
|
|
8
|
-
import {
|
|
8
|
+
import { MENUBAR_AGENT } from '../menubar/agent.js';
|
|
9
|
+
import { afterInstall } from './after-install.js';
|
|
10
|
+
import { refreshAutostart } from './autostart.js';
|
|
11
|
+
import { compareVersions, fetchLatest, runProgram, takeInstallLock, updateMachine } from './update.js';
|
|
9
12
|
import { parseLocalBuild } from './version.js';
|
|
10
13
|
const BIN = 'dist/src/cli/main.js';
|
|
11
14
|
export const pkgDir = (d) => join(d.dev, 'pkg');
|
|
12
15
|
export const globalPkg = (d) => join(d.prefix, 'lib', 'node_modules', 'sideby');
|
|
13
16
|
const globalBin = (d) => join(d.prefix, 'bin', 'sideby');
|
|
14
17
|
export const devDir = (env) => join(env.XDG_DATA_HOME || join(env.HOME || homedir(), '.local', 'share'), 'sideby-dev');
|
|
18
|
+
/**
|
|
19
|
+
* The environment to ask npm for its global prefix in. A pnpm script gets pnpm's own `--dir` (`pnpm -C <dir> …`) as
|
|
20
|
+
* `npm_config_dir` and `npm_config_prefix`, and npm would answer with that directory; npm reads the user's real
|
|
21
|
+
* setting from its config files and from `NPM_CONFIG_PREFIX` without them.
|
|
22
|
+
*/
|
|
23
|
+
export function npmEnv(env) {
|
|
24
|
+
if (!env.npm_config_user_agent?.startsWith('pnpm/'))
|
|
25
|
+
return env;
|
|
26
|
+
const { npm_config_prefix: _prefix, npm_config_dir: _dir, ...rest } = env;
|
|
27
|
+
return rest;
|
|
28
|
+
}
|
|
15
29
|
/** Where the switch works, with npm's global prefix from `npm prefix -g`; null when npm cannot be asked. */
|
|
16
30
|
export async function localDirs(env) {
|
|
17
|
-
const r = await runProgram('npm', ['prefix', '-g'], { env }).catch(() => null);
|
|
31
|
+
const r = await runProgram('npm', ['prefix', '-g'], { env: npmEnv(env) }).catch(() => null);
|
|
18
32
|
const prefix = r && r.code === 0 ? r.output.trim().split('\n').at(-1)?.trim() : '';
|
|
19
33
|
return prefix ? { dev: devDir(env), prefix } : null;
|
|
20
34
|
}
|
|
@@ -122,10 +136,25 @@ export function switchBlocker(s, to) {
|
|
|
122
136
|
return 'there is no local build yet; run `pnpm local` in the sideby checkout';
|
|
123
137
|
return null;
|
|
124
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* Points an existing login item at the sideby now behind the global command (spec §3.29): its entry, with this Node.
|
|
141
|
+
* Never creates one and never throws; undefined when there is no login item of sideby's, or the entry is missing.
|
|
142
|
+
*/
|
|
143
|
+
async function refreshLoginItem(paths, d, ctx = {}) {
|
|
144
|
+
const entry = await realpath(join(globalPkg(d), BIN)).catch(() => null);
|
|
145
|
+
if (!entry)
|
|
146
|
+
return undefined;
|
|
147
|
+
const agentCtx = { home: paths.home, launcher: { node: process.execPath, entry }, ...ctx };
|
|
148
|
+
// The menu bar item (ADR-0034) records the same Node and entry; it is reported nowhere, like a failure here.
|
|
149
|
+
await refreshAutostart(agentCtx, MENUBAR_AGENT);
|
|
150
|
+
const r = await refreshAutostart(agentCtx);
|
|
151
|
+
return r.state === 'on' || r.state === 'stale' ? r.rewritten : undefined;
|
|
152
|
+
}
|
|
125
153
|
/**
|
|
126
154
|
* Puts `to` behind the global `sideby`. `local` links the newest Local Build; `npm` restores the kept package or
|
|
127
|
-
* installs `latest` (a failed install links the Local Build back, so `sideby` never goes missing). Afterwards
|
|
128
|
-
*
|
|
155
|
+
* installs `latest` (a failed install links the Local Build back, so `sideby` never goes missing). Afterwards
|
|
156
|
+
* (after-install.ts) an existing login item follows, back on npm the skill does, and a background Panel on `panelPort`
|
|
157
|
+
* starts again from the new code, last. One install at a time (the Update lock).
|
|
129
158
|
*/
|
|
130
159
|
export async function switchLocal(paths, d, to, env, opts = {}) {
|
|
131
160
|
const before = await localStatus(d);
|
|
@@ -152,6 +181,13 @@ export async function switchLocal(paths, d, to, env, opts = {}) {
|
|
|
152
181
|
const release = await takeInstallLock(paths);
|
|
153
182
|
if (!release)
|
|
154
183
|
return fail('a sideby update is running; wait for it to finish, then switch again', { busy: true });
|
|
184
|
+
let released = false;
|
|
185
|
+
const free = async () => {
|
|
186
|
+
if (released)
|
|
187
|
+
return;
|
|
188
|
+
released = true;
|
|
189
|
+
await release().catch(() => { });
|
|
190
|
+
};
|
|
155
191
|
let message;
|
|
156
192
|
try {
|
|
157
193
|
if (to === 'local') {
|
|
@@ -179,27 +215,29 @@ export async function switchLocal(paths, d, to, env, opts = {}) {
|
|
|
179
215
|
message = `the global sideby runs the npm package ${want}`;
|
|
180
216
|
}
|
|
181
217
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
218
|
+
// The login item records the sideby it starts, like `sideby update` keeps it pointing at the one in use. Back on
|
|
219
|
+
// npm the skill is part of the version (spec §3.23): the npm code updates it alone, by name so the new code runs,
|
|
220
|
+
// after the lock is free. A failure there keeps the switch.
|
|
221
|
+
const after = await afterInstall(updateMachine(), env, {
|
|
222
|
+
home: paths.home,
|
|
223
|
+
release: free,
|
|
224
|
+
autostart: () => refreshLoginItem(paths, d, opts.autostart),
|
|
225
|
+
...(to === 'npm' ? { skill: 'by-name' } : {}),
|
|
226
|
+
...(opts.skillSync ? { skillSync: opts.skillSync } : {}),
|
|
227
|
+
...(opts.panelPort ? { panelPort: opts.panelPort } : {}),
|
|
228
|
+
...(opts.onOutput ? { onOutput: opts.onOutput } : {}),
|
|
229
|
+
});
|
|
193
230
|
return {
|
|
194
231
|
ok: true,
|
|
195
232
|
message,
|
|
196
233
|
running: to,
|
|
197
|
-
restartedPanel,
|
|
198
|
-
|
|
234
|
+
restartedPanel: after.restartedPanel,
|
|
235
|
+
...(after.refreshedAutostart === undefined ? {} : { refreshedAutostart: after.refreshedAutostart }),
|
|
236
|
+
...(after.skillSynced === undefined ? {} : { skillSynced: after.skillSynced }),
|
|
237
|
+
...(after.skillSyncStarted === undefined ? {} : { skillSyncStarted: after.skillSyncStarted }),
|
|
199
238
|
};
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
204
|
-
return { ok: true, message, running: to, restartedPanel, skillSynced: u.code === 0 };
|
|
239
|
+
}
|
|
240
|
+
finally {
|
|
241
|
+
await free();
|
|
242
|
+
}
|
|
205
243
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface FileLockOptions {
|
|
2
|
+
/** A lock its holder has not touched for this long is free, whether or not its pid runs. */
|
|
3
|
+
staleMs: number;
|
|
4
|
+
/** How often the holder touches its lock. Keep it well under `staleMs`. */
|
|
5
|
+
beatMs: number;
|
|
6
|
+
/** A lock older than this is free even when touched: its pid may since belong to another process. Default: none. */
|
|
7
|
+
maxMs?: number;
|
|
8
|
+
/** How long an empty or unreadable lock counts as held (its owner may still be writing it). Default: `staleMs`. */
|
|
9
|
+
writeGraceMs?: number;
|
|
10
|
+
/** Whether a pid runs. Default: `processAlive`. */
|
|
11
|
+
alive?: (pid: number) => boolean;
|
|
12
|
+
/** Milliseconds since epoch, for the lock's content and its age. Default: `Date.now`. */
|
|
13
|
+
now?: () => number;
|
|
14
|
+
/** Wait for a held lock, checking every `pollMs`, up to `timeoutMs`. Without it a held lock gives null at once. */
|
|
15
|
+
wait?: {
|
|
16
|
+
timeoutMs: number;
|
|
17
|
+
pollMs: number;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/** Stops the heartbeat and removes the lock, only while it still holds this holder's content. */
|
|
21
|
+
export type ReleaseLock = () => Promise<void>;
|
|
22
|
+
/** Whether a Linux `/proc/<pid>/stat` line is of a zombie: the state after the parenthesised command name is `Z`. */
|
|
23
|
+
export declare function isZombieStat(line: string): boolean;
|
|
24
|
+
/** Whether `pid` runs. A zombie (exited, nobody waited for it) answers signal 0 on Linux but holds nothing. */
|
|
25
|
+
export declare function processAlive(pid: number): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Takes the lock `file` (its directory must exist). Returns its release function, or null when another holder keeps
|
|
28
|
+
* it (after waiting, with `wait`). Errors other than the file existing are thrown.
|
|
29
|
+
*/
|
|
30
|
+
export declare function takeFileLock(file: string, opts: FileLockOptions): Promise<ReleaseLock | null>;
|