sideby 0.17.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/README.md +11 -1
  2. package/ai-tasks.json +90 -0
  3. package/dist/build.json +1 -1
  4. package/dist/src/cli/commands.d.ts +9 -1
  5. package/dist/src/cli/commands.js +507 -26
  6. package/dist/src/cli/json-schemas.js +196 -19
  7. package/dist/src/cli/main.js +79 -13
  8. package/dist/src/core/after-install.d.ts +54 -0
  9. package/dist/src/core/after-install.js +78 -0
  10. package/dist/src/core/ask.d.ts +87 -1
  11. package/dist/src/core/ask.js +122 -7
  12. package/dist/src/core/autostart.d.ts +38 -8
  13. package/dist/src/core/autostart.js +85 -39
  14. package/dist/src/core/brand-mark.d.ts +49 -11
  15. package/dist/src/core/brand-mark.js +116 -38
  16. package/dist/src/core/browser-profiles.js +7 -32
  17. package/dist/src/core/config.d.ts +19 -0
  18. package/dist/src/core/config.js +75 -2
  19. package/dist/src/core/desktop-app.d.ts +1 -1
  20. package/dist/src/core/desktop-app.js +2 -2
  21. package/dist/src/core/edit-settings.d.ts +24 -0
  22. package/dist/src/core/edit-settings.js +97 -0
  23. package/dist/src/core/handoff-brief.d.ts +4 -2
  24. package/dist/src/core/handoff-brief.js +6 -1
  25. package/dist/src/core/handoff-chain.d.ts +24 -0
  26. package/dist/src/core/handoff-chain.js +2 -0
  27. package/dist/src/core/handoff-run.d.ts +4 -3
  28. package/dist/src/core/handoff-run.js +14 -9
  29. package/dist/src/core/launch.d.ts +2 -0
  30. package/dist/src/core/launch.js +14 -10
  31. package/dist/src/core/local-build.d.ts +12 -5
  32. package/dist/src/core/local-build.js +49 -31
  33. package/dist/src/core/lock.d.ts +30 -0
  34. package/dist/src/core/lock.js +143 -0
  35. package/dist/src/core/pick-commands.d.ts +42 -0
  36. package/dist/src/core/pick-commands.js +44 -0
  37. package/dist/src/core/quota-levels.d.ts +6 -1
  38. package/dist/src/core/quota-levels.js +16 -5
  39. package/dist/src/core/shell-init.js +3 -1
  40. package/dist/src/core/shell-setup.d.ts +40 -0
  41. package/dist/src/core/shell-setup.js +54 -0
  42. package/dist/src/core/skill-check.d.ts +2 -0
  43. package/dist/src/core/skill-check.js +2 -0
  44. package/dist/src/core/task-spec.d.ts +95 -0
  45. package/dist/src/core/task-spec.js +209 -0
  46. package/dist/src/core/terminal.d.ts +21 -4
  47. package/dist/src/core/terminal.js +155 -10
  48. package/dist/src/core/update.d.ts +27 -16
  49. package/dist/src/core/update.js +69 -95
  50. package/dist/src/core/windows-dirs.d.ts +19 -0
  51. package/dist/src/core/windows-dirs.js +39 -0
  52. package/dist/src/desktop/icon.js +12 -15
  53. package/dist/src/families/claude/ai-task.d.ts +8 -0
  54. package/dist/src/families/claude/ai-task.js +38 -0
  55. package/dist/src/families/claude/handoff-hook.js +4 -4
  56. package/dist/src/families/claude/index.js +3 -0
  57. package/dist/src/families/codex/handoff-hook.js +4 -4
  58. package/dist/src/families/codex/index.js +9 -0
  59. package/dist/src/families/grok/handoff-hook.js +4 -4
  60. package/dist/src/families/grok/index.js +1 -0
  61. package/dist/src/families/pi/index.js +1 -0
  62. package/dist/src/handoff/hook.js +51 -30
  63. package/dist/src/handoff/levels.d.ts +24 -0
  64. package/dist/src/handoff/levels.js +70 -0
  65. package/dist/src/handoff/messages.d.ts +6 -3
  66. package/dist/src/handoff/messages.js +20 -7
  67. package/dist/src/handoff/reader.d.ts +6 -3
  68. package/dist/src/menubar/agent.d.ts +3 -0
  69. package/dist/src/menubar/agent.js +21 -0
  70. package/dist/src/menubar/script.d.ts +8 -0
  71. package/dist/src/menubar/script.js +457 -0
  72. package/dist/src/menubar/snapshot.d.ts +115 -0
  73. package/dist/src/menubar/snapshot.js +255 -0
  74. package/dist/src/menubar/strings.d.ts +87 -0
  75. package/dist/src/menubar/strings.js +88 -0
  76. package/dist/src/panel/background.js +12 -19
  77. package/dist/src/panel/handler.d.ts +30 -0
  78. package/dist/src/panel/handler.js +148 -80
  79. package/dist/src/panel/i18n.d.ts +72 -0
  80. package/dist/src/panel/i18n.js +144 -0
  81. package/dist/src/panel/page-logic.d.ts +105 -0
  82. package/dist/src/panel/page-logic.js +170 -15
  83. package/dist/src/panel/page-script.js +419 -111
  84. package/dist/src/panel/page-styles.js +45 -13
  85. package/dist/src/panel/page.d.ts +7 -0
  86. package/dist/src/panel/page.js +11 -1
  87. package/dist/src/runtime.d.ts +44 -2
  88. package/dist/src/runtime.js +107 -6
  89. package/dist/src/types.d.ts +14 -0
  90. package/package.json +4 -3
  91. package/schemas/alias-list.json +119 -0
  92. package/schemas/alias.json +27 -1
  93. package/schemas/ask-choices.json +168 -0
  94. package/schemas/ask-print.json +87 -0
  95. package/schemas/config.json +28 -1
  96. package/schemas/edit.json +119 -0
  97. package/schemas/error.json +4 -0
  98. package/schemas/families.json +4 -0
  99. package/schemas/list.json +4 -0
  100. package/schemas/local.json +1 -1
  101. package/schemas/menubar-snapshot.json +646 -0
  102. package/schemas/menubar-start.json +112 -0
  103. package/schemas/menubar.json +165 -0
  104. package/schemas/new.json +19 -0
  105. package/schemas/shell-init-setup.json +124 -0
  106. package/skills/sideby/SKILL.md +11 -4
  107. package/skills/sideby/references/accounts.md +10 -0
  108. package/skills/sideby/references/ai-tasks.md +10 -0
  109. package/skills/sideby/references/handoff.md +3 -1
  110. package/skills/sideby/references/panel.md +6 -0
  111. package/skills/sideby/references/setup.md +1 -1
  112. package/skills/sideby/references/update.md +1 -1
@@ -2,6 +2,7 @@ import { taskPrompt } from '../panel/page-logic.ts';
2
2
  import type { Runtime } from '../runtime.ts';
3
3
  import type { Account, Env } from '../types.ts';
4
4
  import { type Attachment } from './attachments.ts';
5
+ import { UserError } from './errors.ts';
5
6
  import { type Paths } from './paths.ts';
6
7
  import { type ProbeDeps } from './probe.ts';
7
8
  import { type TerminalId } from './terminal.ts';
@@ -14,7 +15,8 @@ export declare function pickTaskAccount(rt: Runtime, opts?: {
14
15
  reason: 'no-accounts' | 'none-signed-in' | 'all-full';
15
16
  }>;
16
17
  export interface TaskFile {
17
- kind: 'prompt' | 'login';
18
+ /** `run` starts the Host as `sideby run` does, from the Menu Bar Item (spec §3.31). */
19
+ kind: 'prompt' | 'login' | 'run';
18
20
  account: string;
19
21
  prompt?: string;
20
22
  cwd: string;
@@ -27,7 +29,23 @@ export interface TaskFile {
27
29
  path: string;
28
30
  kind: 'image' | 'video';
29
31
  }[];
32
+ /**
33
+ * The folder came from a Task Spec (ADR-0030): `cwd` is its real path, which must still be an existing folder inside
34
+ * `home` when the task is written and again when `ask --run` has changed into it.
35
+ */
36
+ cwdInHome?: true;
30
37
  }
38
+ /**
39
+ * Why `cwd` cannot be the folder of a Portal's task (ADR-0030), or its real path: it must be an absolute path whose
40
+ * real path is an existing directory inside the real `home`. A link, or a link in an ancestor, counts where it points.
41
+ */
42
+ export declare function realCwdInHome(cwd: string, home: string): Promise<{
43
+ real: string;
44
+ } | {
45
+ why: string;
46
+ }>;
47
+ /** A Portal's task folder that stopped being a folder inside the HOME after it was checked. */
48
+ export declare function movedCwdError(why: string): UserError;
31
49
  export declare function taskWorkDir(paths?: Paths): Promise<string>;
32
50
  export declare const newTaskId: () => string;
33
51
  export declare function writeTask(task: TaskFile, paths?: Paths, id?: string): Promise<string>;
@@ -82,14 +100,22 @@ export interface AiTaskInput {
82
100
  /** The user's own files to attach (`sideby ask --attach`). */
83
101
  files?: string[];
84
102
  }
103
+ /**
104
+ * The `context` of an AI Task as a page or a Task Spec sends it (spec §3.28): only the strings and findings a Task
105
+ * Prompt shows; anything else is refused through `fail`, which makes the caller's error (a 400, a Task Spec error).
106
+ */
107
+ export declare function taskContext(c: unknown, fail: (message: string) => Error): AiTaskInput['context'];
85
108
  /** The attachments a prompt shown before the task exists lists: uploads still staged, the user's files in place. */
86
109
  export declare function previewAttachments(rt: Runtime, input: AiTaskInput): Promise<Attachment[]>;
110
+ /** The language of a Task Prompt: the one asked for, else Chinese under a `zh` locale, else English. */
111
+ export declare function taskLang(rt: Runtime, lang?: string): string;
87
112
  export declare function promptForTask(rt: Runtime, input: AiTaskInput, attachments?: readonly Attachment[]): {
88
113
  prompt: string;
89
114
  removedSecrets: boolean;
90
115
  };
91
116
  /** Machine-readable reasons an AI Task did not open; `detail` says what to do. */
92
117
  export type AiTaskReason = 'no-accounts' | 'none-signed-in' | 'all-full' | 'not-installed' | 'automation-denied' | 'npx-cache' | 'unsafe-path' | 'failed' | 'unsupported-platform';
118
+ export declare const PICK_DETAIL: Record<'no-accounts' | 'none-signed-in' | 'all-full', string>;
93
119
  export declare function startAiTask(rt: Runtime, input: AiTaskInput): Promise<{
94
120
  schemaVersion: 1;
95
121
  task: null;
@@ -115,6 +141,41 @@ export declare function startAiTask(rt: Runtime, input: AiTaskInput): Promise<{
115
141
  removedSecrets: boolean;
116
142
  attachments: Attachment[];
117
143
  }>;
144
+ /**
145
+ * Picks the Account and opens the Preferred Terminal for a written Task Prompt, as every AI Task does (spec §3.28):
146
+ * sideby's own, and one a Portal hands over in a Task Spec (ADR-0030), which names its own `cwd`.
147
+ */
148
+ export declare function openPromptTask(rt: Runtime, input: Pick<AiTaskInput, 'account' | 'family' | 'terminal' | 'remember'>, written: {
149
+ taskId: string;
150
+ prompt: string;
151
+ removedSecrets: boolean;
152
+ attachments: Attachment[];
153
+ cwd?: string;
154
+ }): Promise<{
155
+ schemaVersion: 1;
156
+ task: null;
157
+ account: null;
158
+ terminal: null;
159
+ opened: boolean;
160
+ command: null;
161
+ prompt: string;
162
+ reason: AiTaskReason;
163
+ detail: string;
164
+ removedSecrets: boolean;
165
+ attachments: Attachment[];
166
+ } | {
167
+ schemaVersion: 1;
168
+ task: string;
169
+ account: string;
170
+ terminal: string;
171
+ opened: boolean;
172
+ command: string;
173
+ reason?: AiTaskReason | undefined;
174
+ detail?: string | undefined;
175
+ prompt?: undefined;
176
+ removedSecrets: boolean;
177
+ attachments: Attachment[];
178
+ }>;
118
179
  export declare function openLoginInTerminal(rt: Runtime, ref: string): Promise<{
119
180
  schemaVersion: 1;
120
181
  task: string;
@@ -125,6 +186,31 @@ export declare function openLoginInTerminal(rt: Runtime, ref: string): Promise<{
125
186
  reason?: AiTaskReason | undefined;
126
187
  detail?: string | undefined;
127
188
  }>;
189
+ /** Starts an Account in the Preferred Terminal as `sideby run` would, in the HOME folder (spec §3.31). */
190
+ export declare function openRunInTerminal(rt: Runtime, ref: string): Promise<{
191
+ schemaVersion: 1;
192
+ task: string;
193
+ account: string;
194
+ terminal: string;
195
+ opened: boolean;
196
+ command: string;
197
+ reason?: AiTaskReason | undefined;
198
+ detail?: string | undefined;
199
+ }>;
200
+ /**
201
+ * Starts a Pick Command in the Preferred Terminal (spec §3.13): the terminal runs it as `sideby run <name>` does, so it
202
+ * picks the Account when it starts and says which there.
203
+ */
204
+ export declare function openPickInTerminal(rt: Runtime, name: string): Promise<{
205
+ schemaVersion: 1;
206
+ task: string;
207
+ account: string;
208
+ terminal: string;
209
+ opened: boolean;
210
+ command: string;
211
+ reason?: AiTaskReason | undefined;
212
+ detail?: string | undefined;
213
+ }>;
128
214
  /**
129
215
  * What `try` will run for an Account, computed as `sideby run` would (Family defaults, config arguments) but without
130
216
  * reading its Secret File or running `launch.before` hooks: nothing runs before the user agrees.
@@ -1,7 +1,8 @@
1
1
  import { randomBytes } from 'node:crypto';
2
2
  import { constants } from 'node:fs';
3
- import { lstat, mkdtemp, open, readdir, rm, unlink } from 'node:fs/promises';
4
- import { dirname, isAbsolute, join } from 'node:path';
3
+ import { lstat, mkdtemp, open, readdir, realpath, rm, stat, unlink } from 'node:fs/promises';
4
+ import { userInfo } from 'node:os';
5
+ import { dirname, isAbsolute, join, sep } from 'node:path';
5
6
  import { AI_TASK_KINDS, stripSecrets, taskPrompt } from '../panel/page-logic.js';
6
7
  import { checkAttachmentFiles, copyAttachments, MAX_ATTACHMENTS, privateDir, removeOldAttachments, stagedAttachments, takeStaged, } from './attachments.js';
7
8
  import { editConfigAsk, editConfigTerminal } from './config.js';
@@ -11,7 +12,7 @@ import { writeFileAtomic } from './fs-safe.js';
11
12
  import { planHandoff } from './handoff.js';
12
13
  import { resolvePaths } from './paths.js';
13
14
  import { runProbe, spawnProbe } from './probe.js';
14
- import { askLauncher, askRunCommand, guessTerminal, installedTerminals, launcherProblem, openTerminal, TERMINALS, validateCustomTemplate, } from './terminal.js';
15
+ import { askLauncher, askRunCommand, guessTerminal, installedTerminals, launcherProblem, openTerminal, TERMINALS, validateCustomTemplate, wslDistro, } from './terminal.js';
15
16
  export async function pickTaskAccount(rt, opts = {}) {
16
17
  const all = (await rt.accounts()).filter((a) => !opts.family || a.family === opts.family);
17
18
  if (opts.account) {
@@ -40,6 +41,31 @@ export async function pickTaskAccount(rt, opts = {}) {
40
41
  const account = all.find((a) => a.ref === plan.pick);
41
42
  return account ? { account } : { reason: 'all-full' };
42
43
  }
44
+ /**
45
+ * Why `cwd` cannot be the folder of a Portal's task (ADR-0030), or its real path: it must be an absolute path whose
46
+ * real path is an existing directory inside the real `home`. A link, or a link in an ancestor, counts where it points.
47
+ */
48
+ export async function realCwdInHome(cwd, home) {
49
+ if (!isAbsolute(cwd) || cwd.includes('\0'))
50
+ return { why: 'is not an absolute path' };
51
+ let real;
52
+ try {
53
+ real = await realpath(cwd);
54
+ if (!(await stat(real)).isDirectory())
55
+ return { why: 'is not a folder' };
56
+ }
57
+ catch {
58
+ return { why: 'does not exist' };
59
+ }
60
+ const realHome = await realpath(home).catch(() => home);
61
+ if (real !== realHome && !real.startsWith(realHome + sep))
62
+ return { why: 'is outside your home' };
63
+ return { real };
64
+ }
65
+ /** A Portal's task folder that stopped being a folder inside the HOME after it was checked. */
66
+ export function movedCwdError(why) {
67
+ return new UserError(`The task folder ${why} now; it changed after the task was prepared. Check the folder, then start the task again.`, { code: 'bad-cwd' });
68
+ }
43
69
  export async function taskWorkDir(paths = resolvePaths()) {
44
70
  return privateDir(join(paths.stateDir, 'ai'));
45
71
  }
@@ -150,12 +176,13 @@ export async function readTask(id, paths = resolvePaths()) {
150
176
  throw invalid();
151
177
  const task = JSON.parse(await handle.readFile('utf8'));
152
178
  if (!task ||
153
- !['prompt', 'login'].includes(task.kind) ||
179
+ !['prompt', 'login', 'run'].includes(task.kind) ||
154
180
  typeof task.account !== 'string' ||
155
181
  typeof task.cwd !== 'string' ||
156
182
  !isAbsolute(task.cwd) ||
157
183
  (task.kind === 'prompt' && typeof task.prompt !== 'string') ||
158
184
  (task.attachments !== undefined && !validAttachments(task.attachments)) ||
185
+ (task.cwdInHome !== undefined && task.cwdInHome !== true) ||
159
186
  // Paths are all there or all absent (a task written before they were recorded), and the state folder is the
160
187
  // one the task was read from.
161
188
  !((task.home === undefined && task.configDir === undefined && task.stateDir === undefined) ||
@@ -184,6 +211,7 @@ export async function terminals(rt) {
184
211
  env: rt.env,
185
212
  platform: deps.platform,
186
213
  appDirs,
214
+ ...(deps.wslMount ? { wslMount: deps.wslMount, exec: (file, args) => deps.exec(file, args) } : {}),
187
215
  });
188
216
  if (rt.config.terminal?.custom)
189
217
  installed.push({ id: 'custom' });
@@ -213,6 +241,54 @@ export async function setCustomTerminal(rt, template) {
213
241
  const r = await editConfigTerminal(rt.paths.configFile, { custom: template, preferred: 'custom' });
214
242
  rt.config.terminal = r.after;
215
243
  }
244
+ /**
245
+ * The `context` of an AI Task as a page or a Task Spec sends it (spec §3.28): only the strings and findings a Task
246
+ * Prompt shows; anything else is refused through `fail`, which makes the caller's error (a 400, a Task Spec error).
247
+ */
248
+ export function taskContext(c, fail) {
249
+ if (c === undefined || c === null)
250
+ return undefined;
251
+ if (typeof c !== 'object' || Array.isArray(c))
252
+ throw fail('"context" must be an object');
253
+ const out = {};
254
+ const str = (v, what) => {
255
+ if (typeof v !== 'string')
256
+ throw fail(`${what} must be a string`);
257
+ return v;
258
+ };
259
+ for (const [k, v] of Object.entries(c)) {
260
+ if (k === 'account' || k === 'family' || k === 'quotaReason' || k === 'version' || k === 'terminalCustom')
261
+ out[k] = str(v, `"context.${k}"`);
262
+ else if (k === 'terminals') {
263
+ if (!Array.isArray(v) || v.length > 50)
264
+ throw fail('"context.terminals" must be a list');
265
+ out.terminals = v.map((x) => str(x, 'each of "context.terminals"'));
266
+ }
267
+ else if (k === 'handoff') {
268
+ if (!Array.isArray(v) || v.length > 100)
269
+ throw fail('"context.handoff" must be a list');
270
+ out.handoff = v.map((x) => str(x, 'each of "context.handoff"'));
271
+ }
272
+ else if (k === 'findings') {
273
+ if (!Array.isArray(v) || v.length > 100)
274
+ throw fail('"context.findings" must be a list');
275
+ out.findings = v.map((f) => {
276
+ if (!f || typeof f !== 'object' || Array.isArray(f) || typeof f.message !== 'string')
277
+ throw fail('each finding needs a "message"');
278
+ const one = {
279
+ message: f.message,
280
+ };
281
+ for (const key of ['code', 'account', 'item', 'hint'])
282
+ if (f[key] !== undefined && f[key] !== null)
283
+ one[key] = str(f[key], `"finding.${key}"`);
284
+ return one;
285
+ });
286
+ }
287
+ else
288
+ throw fail(`unknown context "${k}"`);
289
+ }
290
+ return out;
291
+ }
216
292
  /** The attachments a prompt shown before the task exists lists: uploads still staged, the user's files in place. */
217
293
  export async function previewAttachments(rt, input) {
218
294
  if (input.uploads?.length)
@@ -228,6 +304,10 @@ async function takeAttachments(rt, input, taskId) {
228
304
  return copyAttachments(rt.paths, input.files, taskId);
229
305
  return [];
230
306
  }
307
+ /** The language of a Task Prompt: the one asked for, else Chinese under a `zh` locale, else English. */
308
+ export function taskLang(rt, lang) {
309
+ return lang ?? (/^zh/i.test(rt.env.LC_ALL || rt.env.LC_MESSAGES || rt.env.LANG || '') ? 'zh' : 'en');
310
+ }
231
311
  export function promptForTask(rt, input, attachments = []) {
232
312
  if (input.task && !AI_TASK_KINDS.includes(input.task))
233
313
  throw new UserError(`Choose a task: ${AI_TASK_KINDS.join(', ')}; rerun \`sideby ask\`.`);
@@ -236,7 +316,7 @@ export function promptForTask(rt, input, attachments = []) {
236
316
  ...input,
237
317
  task: input.task ?? 'free',
238
318
  attachments: attachments.map(({ path, kind }) => ({ path, kind })),
239
- lang: input.lang ?? (/^zh/i.test(rt.env.LC_ALL || rt.env.LC_MESSAGES || rt.env.LANG || '') ? 'zh' : 'en'),
319
+ lang: taskLang(rt, input.lang),
240
320
  }, (text) => {
241
321
  const cleaned = stripSecrets(text);
242
322
  removedSecrets ||= cleaned.removed;
@@ -244,7 +324,7 @@ export function promptForTask(rt, input, attachments = []) {
244
324
  });
245
325
  return { prompt, removedSecrets };
246
326
  }
247
- const PICK_DETAIL = {
327
+ export const PICK_DETAIL = {
248
328
  'no-accounts': 'No account yet: create one with `sideby new <family> --next`, or paste the prompt into any AI.',
249
329
  'none-signed-in': 'No account is signed in: run `sideby list`, then `sideby login <account>`; or paste the prompt into any AI.',
250
330
  'all-full': 'Every account has used its quota: wait for a reset (`sideby quota`), or paste the prompt into any AI.',
@@ -254,6 +334,14 @@ async function openTask(rt, task, terminal, launcher = askLauncher(), taskId = n
254
334
  const id = terminal ?? choices.guess.id;
255
335
  if (!TERMINALS.some((t) => t.id === id))
256
336
  throw new UserError(`Unknown terminal; choose one of ${TERMINALS.map((t) => t.id).join(', ')}, or run \`sideby terminal\` to see which are installed.`);
337
+ // A Portal's folder was checked before the Account and terminal were chosen; it may have been swapped since.
338
+ if (task.cwdInHome) {
339
+ const now = await realCwdInHome(task.cwd, rt.paths.home);
340
+ if ('why' in now)
341
+ throw movedCwdError(now.why);
342
+ if (now.real !== task.cwd)
343
+ throw movedCwdError('points somewhere else');
344
+ }
257
345
  await writeTask(task, rt.paths, taskId);
258
346
  const problem = launcherProblem(launcher, rt.paths.stateDir);
259
347
  // An unsafe path cannot go into the command; the user pastes it where sideby is on PATH.
@@ -266,6 +354,10 @@ async function openTask(rt, task, terminal, launcher = askLauncher(), taskId = n
266
354
  custom: rt.config.terminal?.custom,
267
355
  installed: choices.installed,
268
356
  platform: deps.platform,
357
+ // Both open from WSL into this distribution (Orca picks its worktree from it).
358
+ ...(id === 'windows-terminal' || (id === 'orca' && deps.platform === 'linux')
359
+ ? { wslDistro: await wslDistro(rt.env, deps.exec), shell: userInfo().shell ?? undefined }
360
+ : {}),
269
361
  }, deps.exec));
270
362
  return {
271
363
  schemaVersion: 1,
@@ -290,6 +382,14 @@ export async function startAiTask(rt, input) {
290
382
  const taskId = newTaskId();
291
383
  const attachments = await takeAttachments(rt, input, taskId);
292
384
  const { prompt, removedSecrets } = promptForTask(rt, input, attachments);
385
+ return openPromptTask(rt, input, { taskId, prompt, removedSecrets, attachments });
386
+ }
387
+ /**
388
+ * Picks the Account and opens the Preferred Terminal for a written Task Prompt, as every AI Task does (spec §3.28):
389
+ * sideby's own, and one a Portal hands over in a Task Spec (ADR-0030), which names its own `cwd`.
390
+ */
391
+ export async function openPromptTask(rt, input, written) {
392
+ const { taskId, prompt, removedSecrets, attachments } = written;
293
393
  const pick = await pickTaskAccount(rt, input);
294
394
  // Without an account the prompt is copied instead; the saved attachments stay where it says, until the cleanup.
295
395
  if ('reason' in pick)
@@ -317,7 +417,8 @@ export async function startAiTask(rt, input) {
317
417
  kind: 'prompt',
318
418
  account: pick.account.ref,
319
419
  prompt,
320
- cwd: await taskWorkDir(rt.paths),
420
+ cwd: written.cwd ?? (await taskWorkDir(rt.paths)),
421
+ ...(written.cwd ? { cwdInHome: true } : {}),
321
422
  };
322
423
  if (attachments.length)
323
424
  task.attachments = attachments.map(({ path, kind }) => ({ path, kind }));
@@ -331,6 +432,20 @@ export async function openLoginInTerminal(rt, ref) {
331
432
  const account = await rt.resolve(ref);
332
433
  return openTask(rt, { kind: 'login', account: account.ref, cwd: await taskWorkDir(rt.paths) });
333
434
  }
435
+ /** Starts an Account in the Preferred Terminal as `sideby run` would, in the HOME folder (spec §3.31). */
436
+ export async function openRunInTerminal(rt, ref) {
437
+ const account = await rt.resolve(ref);
438
+ return openTask(rt, { kind: 'run', account: account.ref, cwd: rt.paths.home });
439
+ }
440
+ /**
441
+ * Starts a Pick Command in the Preferred Terminal (spec §3.13): the terminal runs it as `sideby run <name>` does, so it
442
+ * picks the Account when it starts and says which there.
443
+ */
444
+ export async function openPickInTerminal(rt, name) {
445
+ if (rt.pickCommandFamily(name) === undefined)
446
+ throw new UserError(`No short command "${name}" picks an account; add one in the Panel or with \`sideby alias add ${name} --pick <family>\`.`);
447
+ return openTask(rt, { kind: 'run', account: name, cwd: rt.paths.home });
448
+ }
334
449
  /**
335
450
  * What `try` will run for an Account, computed as `sideby run` would (Family defaults, config arguments) but without
336
451
  * reading its Secret File or running `launch.before` hooks: nothing runs before the user agrees.
@@ -1,7 +1,30 @@
1
+ import type { Env } from '../types.ts';
1
2
  import { type AskLauncher } from './terminal.ts';
2
3
  export declare const AUTOSTART_LABEL = "dev.sideby.panel";
3
4
  /** Present in every agent sideby writes; a file without it is someone else's. */
4
5
  export declare const AUTOSTART_MARKER = "Written by `sideby autostart`";
6
+ /** One LaunchAgent sideby can write: the Panel's (`autostart`) or the menu bar item's (`menubar`, ADR-0034). */
7
+ export interface LoginAgent {
8
+ label: string;
9
+ /** Present in every file of this agent sideby writes; a file without it is someone else's. */
10
+ marker: string;
11
+ /** The sideby subcommand that turns it on and off, for messages. */
12
+ command: string;
13
+ /** The comment after the marker: what the agent starts. */
14
+ comment: string;
15
+ programArguments: (l: AskLauncher) => string[];
16
+ /** The recorded paths that must still exist (state `stale` otherwise). */
17
+ launcherPaths: (args: readonly string[]) => string[];
18
+ /** What starts at the next login when launchd could not be told now. */
19
+ later: string;
20
+ /** Restarted by launchd when it exits with an error (a long-running process); a clean exit stays out. */
21
+ restartOnCrash?: boolean;
22
+ /**
23
+ * Variables the agent's process gets, taken from the environment that turns it on: launchd starts jobs with only
24
+ * `/usr/bin:/bin:/usr/sbin:/sbin`, so Hosts installed elsewhere would not be found.
25
+ */
26
+ environment?: (env: Env) => Record<string, string>;
27
+ }
5
28
  export type AutostartState = 'off' | 'on' | 'stale' | 'foreign';
6
29
  /** Runs a program and resolves with its exit code and output; never rejects. */
7
30
  export type AutostartExec = (file: string, args: readonly string[]) => Promise<{
@@ -17,6 +40,8 @@ export interface AutostartContext {
17
40
  uid?: number;
18
41
  /** The home launchd reads LaunchAgents from (the login user's); `launchctl` runs only when `home` is it. */
19
42
  loginHome?: string;
43
+ /** The environment an agent's `environment` takes its variables from; this process's by default. */
44
+ env?: Env;
20
45
  }
21
46
  export interface AutostartStatus {
22
47
  /** False on a system sideby cannot start at login yet; `reason` says so. */
@@ -59,29 +84,34 @@ export interface AutostartResult {
59
84
  loaded: boolean;
60
85
  note?: string;
61
86
  }
87
+ export declare const PANEL_AGENT: LoginAgent;
88
+ export declare const agentPath: (home: string, agent: LoginAgent) => string;
62
89
  export declare const autostartPath: (home: string) => string;
63
90
  export declare const programArgumentsFor: (l: AskLauncher) => string[];
64
- /** The agent's file: starts the Panel once at login, never again by itself, and lets it outlive the job. */
65
- export declare function plistContent(args: readonly string[]): string;
91
+ /**
92
+ * The agent's file. The Panel's starts once at login, never again by itself, and outlives the job; an agent with
93
+ * `restartOnCrash` is the long-running process itself, which launchd starts again only after a failed exit.
94
+ */
95
+ export declare function plistContent(args: readonly string[], agent?: LoginAgent, environment?: Record<string, string>): string;
66
96
  /** The ProgramArguments of a file sideby wrote; null when it holds none. */
67
97
  export declare function parseProgramArguments(content: string): string[] | null;
68
98
  /** Whether a sideby agent (with the marker) is installed; reads only that one file. */
69
- export declare function autostartInstalled(home: string): Promise<boolean>;
70
- export declare function autostartStatus(ctx: AutostartContext): Promise<AutostartStatus>;
99
+ export declare function autostartInstalled(home: string, agent?: LoginAgent): Promise<boolean>;
100
+ export declare function autostartStatus(ctx: AutostartContext, agent?: LoginAgent): Promise<AutostartStatus>;
71
101
  /** Why the agent cannot start this launcher, with what to do instead; null when it can. */
72
- export declare function autostartLauncherProblem(l: AskLauncher): Promise<{
102
+ export declare function autostartLauncherProblem(l: AskLauncher, command?: string): Promise<{
73
103
  code: string;
74
104
  message: string;
75
105
  } | null>;
76
106
  /** What `on` or `off` would change; writes nothing. */
77
- export declare function planAutostart(ctx: AutostartContext, action: 'on' | 'off'): Promise<AutostartPlan>;
107
+ export declare function planAutostart(ctx: AutostartContext, action: 'on' | 'off', agent?: LoginAgent): Promise<AutostartPlan>;
78
108
  /** Carries out a plan the user confirmed. Refuses, changing nothing, when the file changed since it was planned. */
79
- export declare function applyAutostart(ctx: AutostartContext, plan: AutostartPlan): Promise<AutostartResult>;
109
+ export declare function applyAutostart(ctx: AutostartContext, plan: AutostartPlan, agent?: LoginAgent): Promise<AutostartResult>;
80
110
  /**
81
111
  * After `sideby update` or `pnpm local`: rewrites an existing sideby agent so it starts `launcher`. Never creates one,
82
112
  * never touches a foreign file, and never throws; `rewritten` says whether the file changed.
83
113
  */
84
- export declare function refreshAutostart(ctx: AutostartContext): Promise<{
114
+ export declare function refreshAutostart(ctx: AutostartContext, agent?: LoginAgent): Promise<{
85
115
  rewritten: boolean;
86
116
  state: AutostartState;
87
117
  note?: string;