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
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { Runtime } from '../runtime.ts';
|
|
2
|
+
import { type AiTaskInput } from './ask.ts';
|
|
3
|
+
import { type Attachment } from './attachments.ts';
|
|
4
|
+
import { UserError } from './errors.ts';
|
|
5
|
+
/** The largest Task Spec read from stdin. */
|
|
6
|
+
export declare const MAX_SPEC_BYTES: number;
|
|
7
|
+
/** The Task Spec version this sideby understands; a Portal that sends another one is told to update sideby. */
|
|
8
|
+
export declare const SPEC_VERSION = 1;
|
|
9
|
+
/** Why a Task Spec was refused; `spec-version` exits 2 so a Portal can tell "update sideby" apart. */
|
|
10
|
+
export type SpecErrorCode = 'spec-invalid' | 'spec-too-large' | 'spec-version' | 'bad-cwd';
|
|
11
|
+
export declare class SpecError extends UserError {
|
|
12
|
+
readonly code: SpecErrorCode;
|
|
13
|
+
constructor(code: SpecErrorCode, message: string);
|
|
14
|
+
}
|
|
15
|
+
interface SpecCommon {
|
|
16
|
+
lang?: 'en' | 'zh';
|
|
17
|
+
account?: string;
|
|
18
|
+
terminal?: string;
|
|
19
|
+
remember?: boolean;
|
|
20
|
+
files?: string[];
|
|
21
|
+
}
|
|
22
|
+
export type TaskSpec = (SpecCommon & {
|
|
23
|
+
prompt: string;
|
|
24
|
+
cwd?: string;
|
|
25
|
+
}) | (SpecCommon & {
|
|
26
|
+
native: {
|
|
27
|
+
task: string;
|
|
28
|
+
text?: string;
|
|
29
|
+
context?: AiTaskInput['context'];
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
/** Reads a Task Spec from `input` (stdin), refusing more than MAX_SPEC_BYTES before it is all read. */
|
|
33
|
+
export declare function readSpecText(input: AsyncIterable<Buffer | string>): Promise<string>;
|
|
34
|
+
/** Checks a Task Spec's shape. Values are kept as given; `cwd` is checked later against the HOME. */
|
|
35
|
+
export declare function parseTaskSpec(text: string): TaskSpec;
|
|
36
|
+
/**
|
|
37
|
+
* The folder a Task Spec's prompt starts in: an existing directory inside the HOME, as its real path. Without one,
|
|
38
|
+
* sideby's own task work folder (`"cwd": "engine"` in a Tool's declaration).
|
|
39
|
+
*/
|
|
40
|
+
export declare function specCwd(rt: Runtime, cwd: string | undefined): Promise<string | undefined>;
|
|
41
|
+
/** `sideby ask --spec - --print`: the prompt the Host would get, without writing a task or copying a file. */
|
|
42
|
+
export declare function previewTaskSpec(rt: Runtime, spec: TaskSpec): Promise<{
|
|
43
|
+
schemaVersion: 1;
|
|
44
|
+
prompt: string;
|
|
45
|
+
removedSecrets: boolean;
|
|
46
|
+
}>;
|
|
47
|
+
/** `sideby ask --spec -`: starts the AI Task the spec describes; the result is `startAiTask`'s. */
|
|
48
|
+
export declare function startTaskSpec(rt: Runtime, spec: TaskSpec): Promise<{
|
|
49
|
+
schemaVersion: 1;
|
|
50
|
+
task: null;
|
|
51
|
+
account: null;
|
|
52
|
+
terminal: null;
|
|
53
|
+
opened: boolean;
|
|
54
|
+
command: null;
|
|
55
|
+
prompt: string;
|
|
56
|
+
reason: import("./ask.ts").AiTaskReason;
|
|
57
|
+
detail: string;
|
|
58
|
+
removedSecrets: boolean;
|
|
59
|
+
attachments: Attachment[];
|
|
60
|
+
} | {
|
|
61
|
+
schemaVersion: 1;
|
|
62
|
+
task: string;
|
|
63
|
+
account: string;
|
|
64
|
+
terminal: string;
|
|
65
|
+
opened: boolean;
|
|
66
|
+
command: string;
|
|
67
|
+
reason?: import("./ask.ts").AiTaskReason | undefined;
|
|
68
|
+
detail?: string | undefined;
|
|
69
|
+
prompt?: undefined;
|
|
70
|
+
removedSecrets: boolean;
|
|
71
|
+
attachments: Attachment[];
|
|
72
|
+
}>;
|
|
73
|
+
/**
|
|
74
|
+
* `sideby ask --choices` (ADR-0030): what a Portal's dialog offers before it starts a task. `account` is what an AI
|
|
75
|
+
* Task would pick now (null with `reason` and `detail` when nothing can be picked); `accounts` lists every API
|
|
76
|
+
* Account and Subscription Account, signed-in ones first; `terminals` the supported terminals installed here, with
|
|
77
|
+
* the one a task would open in `terminal`.
|
|
78
|
+
*/
|
|
79
|
+
export declare function taskChoices(rt: Runtime): Promise<{
|
|
80
|
+
schemaVersion: 1;
|
|
81
|
+
account: string | null;
|
|
82
|
+
accounts: {
|
|
83
|
+
ref: string;
|
|
84
|
+
label: string;
|
|
85
|
+
signedIn: boolean;
|
|
86
|
+
}[];
|
|
87
|
+
terminal: import("./terminal.ts").TerminalId;
|
|
88
|
+
terminals: {
|
|
89
|
+
id: import("./terminal.ts").TerminalId;
|
|
90
|
+
label: string;
|
|
91
|
+
}[];
|
|
92
|
+
reason: "all-full" | "no-accounts" | "none-signed-in" | null;
|
|
93
|
+
detail: string | null;
|
|
94
|
+
}>;
|
|
95
|
+
export {};
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
// Task Specs (spec §3.28 "Portal 交来的任务", ADR-0030): a Portal hands sideby an AI Task as one JSON object on
|
|
2
|
+
// stdin, either a Task Prompt it wrote for another Tool or one of sideby's own tasks (`native`). sideby picks the
|
|
3
|
+
// Account, takes the attachments and opens the Preferred Terminal exactly as for its own AI Tasks; the prompt reaches
|
|
4
|
+
// the Host only through the task file, never a shell.
|
|
5
|
+
import { isAbsolute } from 'node:path';
|
|
6
|
+
import { AI_TASK_KINDS, attachedSection, stripSecrets } from '../panel/page-logic.js';
|
|
7
|
+
import { newTaskId, openPromptTask, PICK_DETAIL, pickTaskAccount, previewAttachments, promptForTask, realCwdInHome, startAiTask, taskContext, taskLang, terminals, } from './ask.js';
|
|
8
|
+
import { checkAttachmentFiles, copyAttachments, MAX_ATTACHMENTS } from './attachments.js';
|
|
9
|
+
import { UserError } from './errors.js';
|
|
10
|
+
import { TERMINALS } from './terminal.js';
|
|
11
|
+
/** The largest Task Spec read from stdin. */
|
|
12
|
+
export const MAX_SPEC_BYTES = 1024 * 1024;
|
|
13
|
+
/** The Task Spec version this sideby understands; a Portal that sends another one is told to update sideby. */
|
|
14
|
+
export const SPEC_VERSION = 1;
|
|
15
|
+
export class SpecError extends UserError {
|
|
16
|
+
code;
|
|
17
|
+
constructor(code, message) {
|
|
18
|
+
super(message, { code });
|
|
19
|
+
this.code = code;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const invalid = (message) => new SpecError('spec-invalid', `${message}; fix the Task Spec and send it again.`);
|
|
23
|
+
const COMMON = ['specVersion', 'lang', 'account', 'terminal', 'remember', 'files'];
|
|
24
|
+
/** Reads a Task Spec from `input` (stdin), refusing more than MAX_SPEC_BYTES before it is all read. */
|
|
25
|
+
export async function readSpecText(input) {
|
|
26
|
+
const chunks = [];
|
|
27
|
+
let size = 0;
|
|
28
|
+
for await (const chunk of input) {
|
|
29
|
+
const buf = typeof chunk === 'string' ? Buffer.from(chunk) : chunk;
|
|
30
|
+
size += buf.length;
|
|
31
|
+
if (size > MAX_SPEC_BYTES)
|
|
32
|
+
throw new SpecError('spec-too-large', `The Task Spec is larger than ${MAX_SPEC_BYTES} bytes; attach big content as files instead.`);
|
|
33
|
+
chunks.push(buf);
|
|
34
|
+
}
|
|
35
|
+
return Buffer.concat(chunks).toString('utf8');
|
|
36
|
+
}
|
|
37
|
+
/** Checks a Task Spec's shape. Values are kept as given; `cwd` is checked later against the HOME. */
|
|
38
|
+
export function parseTaskSpec(text) {
|
|
39
|
+
let raw;
|
|
40
|
+
try {
|
|
41
|
+
raw = JSON.parse(text);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
throw invalid('The Task Spec is not valid JSON');
|
|
45
|
+
}
|
|
46
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw))
|
|
47
|
+
throw invalid('The Task Spec must be one JSON object');
|
|
48
|
+
const o = raw;
|
|
49
|
+
if (o.specVersion !== SPEC_VERSION) {
|
|
50
|
+
if (typeof o.specVersion === 'number')
|
|
51
|
+
throw new SpecError('spec-version', `This sideby reads Task Spec version ${SPEC_VERSION}, not ${o.specVersion}; update sideby with \`sideby update\`.`);
|
|
52
|
+
throw invalid(`"specVersion" must be ${SPEC_VERSION}`);
|
|
53
|
+
}
|
|
54
|
+
const hasPrompt = o.prompt !== undefined;
|
|
55
|
+
const hasNative = o.native !== undefined;
|
|
56
|
+
if (hasPrompt === hasNative)
|
|
57
|
+
throw invalid('Give either "prompt" (with "cwd") or "native", not both or neither');
|
|
58
|
+
const allowed = new Set([...COMMON, ...(hasPrompt ? ['prompt', 'cwd'] : ['native'])]);
|
|
59
|
+
for (const k of Object.keys(o))
|
|
60
|
+
if (!allowed.has(k))
|
|
61
|
+
throw invalid(`Unknown field "${k}"`);
|
|
62
|
+
const common = {};
|
|
63
|
+
if (o.lang !== undefined && o.lang !== null) {
|
|
64
|
+
if (o.lang !== 'en' && o.lang !== 'zh')
|
|
65
|
+
throw invalid('"lang" must be "en" or "zh"');
|
|
66
|
+
common.lang = o.lang;
|
|
67
|
+
}
|
|
68
|
+
for (const key of ['account', 'terminal']) {
|
|
69
|
+
const v = o[key];
|
|
70
|
+
if (v === undefined || v === null)
|
|
71
|
+
continue;
|
|
72
|
+
if (typeof v !== 'string' || !v)
|
|
73
|
+
throw invalid(`"${key}" must be a string or null`);
|
|
74
|
+
common[key] = v;
|
|
75
|
+
}
|
|
76
|
+
if (common.terminal && !TERMINALS.some((t) => t.id === common.terminal))
|
|
77
|
+
throw invalid(`"terminal" must be one of ${TERMINALS.map((t) => t.id).join(', ')}`);
|
|
78
|
+
if (o.remember !== undefined && o.remember !== null) {
|
|
79
|
+
if (typeof o.remember !== 'boolean')
|
|
80
|
+
throw invalid('"remember" must be true or false');
|
|
81
|
+
common.remember = o.remember;
|
|
82
|
+
}
|
|
83
|
+
if (o.files !== undefined && o.files !== null) {
|
|
84
|
+
const f = o.files;
|
|
85
|
+
if (!Array.isArray(f) ||
|
|
86
|
+
f.length > MAX_ATTACHMENTS ||
|
|
87
|
+
!f.every((p) => typeof p === 'string' && isAbsolute(p) && !p.includes('\0')))
|
|
88
|
+
throw invalid(`"files" must list at most ${MAX_ATTACHMENTS} absolute paths`);
|
|
89
|
+
if (f.length)
|
|
90
|
+
common.files = f;
|
|
91
|
+
}
|
|
92
|
+
if (hasPrompt) {
|
|
93
|
+
if (typeof o.prompt !== 'string' || !o.prompt.trim())
|
|
94
|
+
throw invalid('"prompt" must be a non-empty string');
|
|
95
|
+
if (o.cwd !== undefined && o.cwd !== null && typeof o.cwd !== 'string')
|
|
96
|
+
throw invalid('"cwd" must be a path');
|
|
97
|
+
return { ...common, prompt: o.prompt, ...(typeof o.cwd === 'string' ? { cwd: o.cwd } : {}) };
|
|
98
|
+
}
|
|
99
|
+
const n = o.native;
|
|
100
|
+
if (!n || typeof n !== 'object' || Array.isArray(n))
|
|
101
|
+
throw invalid('"native" must be an object');
|
|
102
|
+
const native = n;
|
|
103
|
+
for (const k of Object.keys(native))
|
|
104
|
+
if (!['task', 'text', 'context'].includes(k))
|
|
105
|
+
throw invalid(`Unknown field "native.${k}"`);
|
|
106
|
+
if (typeof native.task !== 'string' || !AI_TASK_KINDS.includes(native.task))
|
|
107
|
+
throw invalid(`"native.task" must be one of ${AI_TASK_KINDS.join(', ')}`);
|
|
108
|
+
if (native.text !== undefined && native.text !== null && typeof native.text !== 'string')
|
|
109
|
+
throw invalid('"native.text" must be a string');
|
|
110
|
+
const context = taskContext(native.context, (m) => invalid(m.replace('"context', '"native.context')));
|
|
111
|
+
return {
|
|
112
|
+
...common,
|
|
113
|
+
native: {
|
|
114
|
+
task: native.task,
|
|
115
|
+
...(typeof native.text === 'string' && native.text ? { text: native.text } : {}),
|
|
116
|
+
...(context ? { context } : {}),
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* The folder a Task Spec's prompt starts in: an existing directory inside the HOME, as its real path. Without one,
|
|
122
|
+
* sideby's own task work folder (`"cwd": "engine"` in a Tool's declaration).
|
|
123
|
+
*/
|
|
124
|
+
export async function specCwd(rt, cwd) {
|
|
125
|
+
if (cwd === undefined)
|
|
126
|
+
return undefined;
|
|
127
|
+
const bad = (why) => new SpecError('bad-cwd', `The task folder ${JSON.stringify(cwd)} ${why}; name an existing folder in your home.`);
|
|
128
|
+
const checked = await realCwdInHome(cwd, rt.paths.home);
|
|
129
|
+
if ('why' in checked)
|
|
130
|
+
throw bad(checked.why);
|
|
131
|
+
return checked.real;
|
|
132
|
+
}
|
|
133
|
+
function nativeInput(spec) {
|
|
134
|
+
return {
|
|
135
|
+
task: spec.native.task,
|
|
136
|
+
...(spec.native.text ? { text: spec.native.text } : {}),
|
|
137
|
+
...(spec.native.context ? { context: spec.native.context } : {}),
|
|
138
|
+
...(spec.lang ? { lang: spec.lang } : {}),
|
|
139
|
+
...(spec.account ? { account: spec.account } : {}),
|
|
140
|
+
...(spec.terminal ? { terminal: spec.terminal } : {}),
|
|
141
|
+
...(spec.remember ? { remember: spec.remember } : {}),
|
|
142
|
+
...(spec.files ? { files: spec.files } : {}),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/** A Portal's prompt as the Host gets it: keys removed again, then the attachments section at its heading level. */
|
|
146
|
+
function specPrompt(rt, spec, attachments) {
|
|
147
|
+
const cleaned = stripSecrets(spec.prompt);
|
|
148
|
+
const heading = /^(#{1,6} )\S/m.exec(cleaned.text)?.[1] ?? '';
|
|
149
|
+
const files = attachments.map(({ path, kind }) => ({ path, kind }));
|
|
150
|
+
const section = attachedSection(files, taskLang(rt, spec.lang), heading);
|
|
151
|
+
return {
|
|
152
|
+
prompt: section ? `${cleaned.text.trimEnd()}\n\n${section}` : cleaned.text,
|
|
153
|
+
removedSecrets: cleaned.removed,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
/** `sideby ask --spec - --print`: the prompt the Host would get, without writing a task or copying a file. */
|
|
157
|
+
export async function previewTaskSpec(rt, spec) {
|
|
158
|
+
if ('native' in spec) {
|
|
159
|
+
const input = nativeInput(spec);
|
|
160
|
+
const { prompt, removedSecrets } = promptForTask(rt, input, await previewAttachments(rt, input));
|
|
161
|
+
return { schemaVersion: 1, prompt, removedSecrets };
|
|
162
|
+
}
|
|
163
|
+
await specCwd(rt, spec.cwd);
|
|
164
|
+
const files = spec.files ? await checkAttachmentFiles(spec.files) : [];
|
|
165
|
+
return { schemaVersion: 1, ...specPrompt(rt, spec, files) };
|
|
166
|
+
}
|
|
167
|
+
/** `sideby ask --spec -`: starts the AI Task the spec describes; the result is `startAiTask`'s. */
|
|
168
|
+
export async function startTaskSpec(rt, spec) {
|
|
169
|
+
if ('native' in spec)
|
|
170
|
+
return startAiTask(rt, nativeInput(spec));
|
|
171
|
+
// The folder is checked before any attachment is copied.
|
|
172
|
+
const cwd = await specCwd(rt, spec.cwd);
|
|
173
|
+
const taskId = newTaskId();
|
|
174
|
+
const attachments = spec.files ? await copyAttachments(rt.paths, spec.files, taskId) : [];
|
|
175
|
+
const written = specPrompt(rt, spec, attachments);
|
|
176
|
+
return openPromptTask(rt, spec, { taskId, ...written, attachments, ...(cwd ? { cwd } : {}) });
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* `sideby ask --choices` (ADR-0030): what a Portal's dialog offers before it starts a task. `account` is what an AI
|
|
180
|
+
* Task would pick now (null with `reason` and `detail` when nothing can be picked); `accounts` lists every API
|
|
181
|
+
* Account and Subscription Account, signed-in ones first; `terminals` the supported terminals installed here, with
|
|
182
|
+
* the one a task would open in `terminal`.
|
|
183
|
+
*/
|
|
184
|
+
export async function taskChoices(rt) {
|
|
185
|
+
const pick = await pickTaskAccount(rt);
|
|
186
|
+
const signedIn = [];
|
|
187
|
+
const api = [];
|
|
188
|
+
const signedOut = [];
|
|
189
|
+
const all = [...(await rt.accounts())].sort((a, b) => (a.ref < b.ref ? -1 : a.ref > b.ref ? 1 : 0));
|
|
190
|
+
for (const a of all) {
|
|
191
|
+
if (a.kind === 'api')
|
|
192
|
+
api.push({ ref: a.ref, label: `${a.ref} · API`, signedIn: true });
|
|
193
|
+
else if ((await rt.status(a)).login === 'logged-in')
|
|
194
|
+
signedIn.push({ ref: a.ref, label: a.ref, signedIn: true });
|
|
195
|
+
else
|
|
196
|
+
signedOut.push({ ref: a.ref, label: a.ref, signedIn: false });
|
|
197
|
+
}
|
|
198
|
+
const t = await terminals(rt);
|
|
199
|
+
const name = (id) => TERMINALS.find((x) => x.id === id)?.name ?? id;
|
|
200
|
+
return {
|
|
201
|
+
schemaVersion: 1,
|
|
202
|
+
account: 'account' in pick ? pick.account.ref : null,
|
|
203
|
+
accounts: [...signedIn, ...api, ...signedOut],
|
|
204
|
+
terminal: t.guess.id,
|
|
205
|
+
terminals: t.installed.map((i) => ({ id: i.id, label: name(i.id) })),
|
|
206
|
+
reason: 'reason' in pick ? pick.reason : null,
|
|
207
|
+
detail: 'reason' in pick ? PICK_DETAIL[pick.reason] : null,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { access, stat } from 'node:fs/promises';
|
|
2
|
+
import type { Env } from '../types.ts';
|
|
3
|
+
import type { DesktopDeps } from './desktop-app.ts';
|
|
4
|
+
export type TerminalId = 'terminal' | 'iterm2' | 'ghostty' | 'orca' | 'wezterm' | 'kitty' | 'alacritty' | 'custom';
|
|
5
|
+
export interface TerminalDef {
|
|
6
|
+
id: TerminalId;
|
|
7
|
+
name: string;
|
|
8
|
+
bundleId: string | null;
|
|
9
|
+
app: string | null;
|
|
10
|
+
termPrograms: readonly string[];
|
|
11
|
+
marker?: string;
|
|
12
|
+
binary?: string;
|
|
13
|
+
}
|
|
14
|
+
/** Supported macOS terminals; custom templates have no app bundle or environment marker. */
|
|
15
|
+
export declare const TERMINALS: readonly TerminalDef[];
|
|
16
|
+
export interface InstalledTerminal {
|
|
17
|
+
id: TerminalId;
|
|
18
|
+
appPath?: string;
|
|
19
|
+
executable?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface TerminalDeps {
|
|
22
|
+
home: string;
|
|
23
|
+
env: Env;
|
|
24
|
+
platform?: NodeJS.Platform;
|
|
25
|
+
appDirs?: readonly string[];
|
|
26
|
+
fs?: {
|
|
27
|
+
stat: typeof stat;
|
|
28
|
+
access: typeof access;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/** Finds bundles and command line launchers without opening apps or reading user files. */
|
|
32
|
+
export declare function installedTerminals(deps: TerminalDeps): Promise<InstalledTerminal[]>;
|
|
33
|
+
/** Chooses an installed preference, then the launching environment, then macOS Terminal. */
|
|
34
|
+
export declare function guessTerminal(opts: {
|
|
35
|
+
preferred?: string;
|
|
36
|
+
env: Env;
|
|
37
|
+
installed: readonly InstalledTerminal[];
|
|
38
|
+
}): {
|
|
39
|
+
id: TerminalId;
|
|
40
|
+
source: 'config' | 'env' | 'default';
|
|
41
|
+
};
|
|
42
|
+
/** What the terminal runs: this Node and this sideby's CLI entry, so neither PATH nor the login shell matters. */
|
|
43
|
+
export interface AskLauncher {
|
|
44
|
+
node: string;
|
|
45
|
+
entry: string;
|
|
46
|
+
}
|
|
47
|
+
/** This process's Node and the real path of the CLI entry next to this module (`main.ts` from source, `main.js` from dist). */
|
|
48
|
+
export declare function askLauncher(): AskLauncher;
|
|
49
|
+
/** Why the terminal cannot run this launcher, or null when it can. */
|
|
50
|
+
export declare function launcherProblem(launcher: AskLauncher, stateDir?: string): {
|
|
51
|
+
ok: false;
|
|
52
|
+
reason: 'npx-cache' | 'unsafe-path';
|
|
53
|
+
detail: string;
|
|
54
|
+
} | null;
|
|
55
|
+
/**
|
|
56
|
+
* Builds the only shell command accepted by the AI Task terminal launcher: the quoted Node and CLI entry, or
|
|
57
|
+
* `sideby` by name when `launcher` is null (a command for the user to paste where sideby is on PATH). It carries the
|
|
58
|
+
* state folder the task was written to, so a terminal whose environment differs from the Panel's still finds it.
|
|
59
|
+
*/
|
|
60
|
+
export declare function askRunCommand(taskId: string, stateDir: string, launcher?: AskLauncher | null): string;
|
|
61
|
+
export interface TerminalLaunchOptions {
|
|
62
|
+
cwd: string;
|
|
63
|
+
command: string;
|
|
64
|
+
custom?: string;
|
|
65
|
+
appPath?: string;
|
|
66
|
+
executable?: string;
|
|
67
|
+
}
|
|
68
|
+
export interface TerminalCommand {
|
|
69
|
+
file: string;
|
|
70
|
+
args: string[];
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Splits a custom terminal template into argv, throwing unless it names a program first and has both `{cmd}` and
|
|
74
|
+
* `{cwd}` in its arguments.
|
|
75
|
+
*/
|
|
76
|
+
export declare function validateCustomTemplate(template: string): [string, ...string[]];
|
|
77
|
+
/** Builds argv only. The caller supplies discovered bundle/binary paths when available. */
|
|
78
|
+
export declare function launchArgs(id: TerminalId, opts: TerminalLaunchOptions): TerminalCommand;
|
|
79
|
+
export type TerminalOpenResult = {
|
|
80
|
+
ok: true;
|
|
81
|
+
} | {
|
|
82
|
+
ok: false;
|
|
83
|
+
reason: 'unsupported-platform';
|
|
84
|
+
} | {
|
|
85
|
+
ok: false;
|
|
86
|
+
reason: 'not-installed' | 'automation-denied' | 'failed' | 'npx-cache' | 'unsafe-path';
|
|
87
|
+
detail: string;
|
|
88
|
+
};
|
|
89
|
+
/** Opens through the injected Desktop exec boundary, returning safe, actionable failures only. */
|
|
90
|
+
export declare function openTerminal(id: TerminalId, opts: TerminalLaunchOptions & {
|
|
91
|
+
platform?: NodeJS.Platform;
|
|
92
|
+
installed: readonly InstalledTerminal[];
|
|
93
|
+
}, exec: DesktopDeps['exec']): Promise<TerminalOpenResult>;
|