@jmanuelcorral/bond-app 0.1.4 → 0.1.5
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 +41 -1
- package/app/mods/bond-agents/config.js +4 -0
- package/app/mods/bond-agents/main.js +10 -5
- package/app/mods/bond-agents/model.js +47 -2
- package/app/mods/bond-board/config.js +4 -0
- package/app/mods/bond-board/main.js +500 -54
- package/app/mods/bond-board/model.js +47 -0
- package/app/mods/bond-settings/config.js +4 -0
- package/app/mods/bond-settings/main.js +689 -12
- package/app/mods/bond-settings/pi-models.js +144 -0
- package/app/mods/bond-status/config.js +4 -0
- package/app/mods/bond-titlebar/main.js +47 -43
- package/package.json +1 -1
- package/runner/Dockerfile +42 -13
- package/runner/SPIKE-BOND.md +85 -0
- package/runner/build-config/.none +0 -0
- package/runner/build-creds/.none +0 -0
- package/runner/config.example/README.md +27 -0
- package/runner/config.example/pi/models.json +22 -0
- package/runner/credentials.example.env +27 -0
- package/runner/setup.sh +496 -0
- package/runner/versions.env +30 -0
- package/scripts/app-install.ts +4 -0
- package/src/config.ts +8 -0
- package/src/core/hub-session.ts +9 -7
- package/src/core/orchestrator.ts +459 -99
- package/src/core/setup.ts +178 -0
- package/src/db/database.ts +14 -0
- package/src/db/settings-repo.ts +108 -0
- package/src/db/ticket-repo.ts +34 -4
- package/src/runner/docker-client.ts +29 -0
- package/src/runner/github-client.ts +119 -0
- package/src/runner/hc-client.ts +9 -2
- package/src/runner/image-builder.ts +146 -6
- package/src/server/app.ts +211 -7
- package/src/types.ts +40 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { execFile } from 'node:child_process';
|
|
2
2
|
import { promisify } from 'node:util';
|
|
3
|
+
import fs from 'node:fs';
|
|
3
4
|
import path from 'node:path';
|
|
4
5
|
import { fileURLToPath } from 'node:url';
|
|
5
6
|
|
|
@@ -29,6 +30,26 @@ export interface RunnerVersions {
|
|
|
29
30
|
pi?: string;
|
|
30
31
|
}
|
|
31
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Image plan P2: what a rebuild bakes besides versions. `agents` is the setup.sh agent
|
|
35
|
+
* list (default ['pi'], parity with the current image). `config_dir` and `credentials_file`
|
|
36
|
+
* are absolute paths that must live inside `data_dir` (validated: no traversal, no
|
|
37
|
+
* symlink escape); they get staged into the build context for the duration of the build.
|
|
38
|
+
*/
|
|
39
|
+
export interface RunnerBuildOptions extends RunnerVersions {
|
|
40
|
+
agents?: string[];
|
|
41
|
+
/** System CLIs (setup.sh --skip-gh / --skip-az); az is heavy and rarely needed. */
|
|
42
|
+
skip_az?: boolean;
|
|
43
|
+
skip_gh?: boolean;
|
|
44
|
+
config_dir?: string;
|
|
45
|
+
credentials_file?: string;
|
|
46
|
+
/** Root the staged paths must resolve inside of (the orchestrator injects its data dir). */
|
|
47
|
+
data_dir?: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** The agent list runner/setup.sh accepts (kept in sync; setup.sh is still the judge). */
|
|
51
|
+
export const RUNNER_AGENT_NAMES = ['pi', 'claude', 'codex', 'copilot', 'agy'] as const;
|
|
52
|
+
|
|
32
53
|
export class InvalidVersionError extends Error {
|
|
33
54
|
constructor(message: string) {
|
|
34
55
|
super(message);
|
|
@@ -36,6 +57,14 @@ export class InvalidVersionError extends Error {
|
|
|
36
57
|
}
|
|
37
58
|
}
|
|
38
59
|
|
|
60
|
+
/** P2 (image plan): bad agents/config_dir/credentials_file; the server maps it to 400. */
|
|
61
|
+
export class InvalidBuildOptionsError extends Error {
|
|
62
|
+
constructor(message: string) {
|
|
63
|
+
super(message);
|
|
64
|
+
this.name = 'InvalidBuildOptionsError';
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
39
68
|
/** Sanitized build failure: the message never carries docker's stderr. */
|
|
40
69
|
export class RunnerBuildError extends Error {
|
|
41
70
|
constructor(message: string) {
|
|
@@ -57,16 +86,115 @@ export type DockerExec = (
|
|
|
57
86
|
options: Record<string, unknown>
|
|
58
87
|
) => Promise<unknown>;
|
|
59
88
|
|
|
89
|
+
/** Validate the agent list: non-empty array of known names, no duplicates. */
|
|
90
|
+
export function validateRunnerAgents(agents: unknown): string[] {
|
|
91
|
+
if (!Array.isArray(agents) || agents.length === 0) {
|
|
92
|
+
throw new InvalidBuildOptionsError("'agents' must be a non-empty array of agent names");
|
|
93
|
+
}
|
|
94
|
+
const out: string[] = [];
|
|
95
|
+
for (const a of agents) {
|
|
96
|
+
if (typeof a !== 'string' || !a) {
|
|
97
|
+
throw new InvalidBuildOptionsError("'agents' must contain non-empty strings");
|
|
98
|
+
}
|
|
99
|
+
if (!(RUNNER_AGENT_NAMES as readonly string[]).includes(a)) {
|
|
100
|
+
throw new InvalidBuildOptionsError(
|
|
101
|
+
`unsupported agent '${a}': setup.sh installs ${RUNNER_AGENT_NAMES.join(', ')}`
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
if (out.includes(a)) {
|
|
105
|
+
throw new InvalidBuildOptionsError(`duplicate agent in 'agents': '${a}'`);
|
|
106
|
+
}
|
|
107
|
+
out.push(a);
|
|
108
|
+
}
|
|
109
|
+
return out;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* A staged path (config_dir / credentials_file) must be absolute and resolve — following
|
|
114
|
+
* symlinks — inside data_dir. Rejects traversal ('..') and symlink escape (V).
|
|
115
|
+
*/
|
|
116
|
+
function assertInsideDataDir(p: string, dataDir: string, label: string): string {
|
|
117
|
+
if (!path.isAbsolute(p)) {
|
|
118
|
+
throw new InvalidBuildOptionsError(`'${label}' must be an absolute path inside the data dir`);
|
|
119
|
+
}
|
|
120
|
+
const root = fs.realpathSync(dataDir);
|
|
121
|
+
let real: string;
|
|
122
|
+
try {
|
|
123
|
+
real = fs.realpathSync(p);
|
|
124
|
+
} catch {
|
|
125
|
+
throw new InvalidBuildOptionsError(`'${label}' does not exist: not a readable path`);
|
|
126
|
+
}
|
|
127
|
+
if (real !== root && !real.startsWith(root + path.sep)) {
|
|
128
|
+
throw new InvalidBuildOptionsError(`'${label}' must stay inside the data dir`);
|
|
129
|
+
}
|
|
130
|
+
return real;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Stage the optional config/credentials into the build context and return a cleanup that
|
|
135
|
+
* restores the empty (".none") state. The Dockerfile COPYs both directories unconditionally:
|
|
136
|
+
* build-config/.none / build-creds/.none mean "nothing staged".
|
|
137
|
+
*/
|
|
138
|
+
export function stageBuildContext(
|
|
139
|
+
context: string,
|
|
140
|
+
options: Pick<RunnerBuildOptions, 'config_dir' | 'credentials_file' | 'data_dir'>
|
|
141
|
+
): () => void {
|
|
142
|
+
const configDir = path.join(context, 'build-config');
|
|
143
|
+
const credsDir = path.join(context, 'build-creds');
|
|
144
|
+
|
|
145
|
+
const resetDir = (dir: string) => {
|
|
146
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
147
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
148
|
+
fs.writeFileSync(path.join(dir, '.none'), '');
|
|
149
|
+
};
|
|
150
|
+
resetDir(configDir);
|
|
151
|
+
resetDir(credsDir);
|
|
152
|
+
|
|
153
|
+
if (options.config_dir !== undefined) {
|
|
154
|
+
const src = assertInsideDataDir(options.config_dir, options.data_dir ?? '', 'config_dir');
|
|
155
|
+
if (!fs.statSync(src).isDirectory()) {
|
|
156
|
+
throw new InvalidBuildOptionsError("'config_dir' is not a directory");
|
|
157
|
+
}
|
|
158
|
+
fs.rmSync(configDir, { recursive: true, force: true });
|
|
159
|
+
fs.cpSync(src, configDir, { recursive: true });
|
|
160
|
+
fs.rmSync(path.join(configDir, '.none'), { force: true });
|
|
161
|
+
}
|
|
162
|
+
if (options.credentials_file !== undefined) {
|
|
163
|
+
const src = assertInsideDataDir(
|
|
164
|
+
options.credentials_file,
|
|
165
|
+
options.data_dir ?? '',
|
|
166
|
+
'credentials_file'
|
|
167
|
+
);
|
|
168
|
+
const st = fs.statSync(src);
|
|
169
|
+
if (!st.isFile()) {
|
|
170
|
+
throw new InvalidBuildOptionsError("'credentials_file' is not a regular file");
|
|
171
|
+
}
|
|
172
|
+
if ((st.mode & 0o777) !== 0o600) {
|
|
173
|
+
throw new InvalidBuildOptionsError("'credentials_file' must have mode 0600");
|
|
174
|
+
}
|
|
175
|
+
fs.writeFileSync(path.join(credsDir, 'env'), fs.readFileSync(src), { mode: 0o600 });
|
|
176
|
+
fs.chmodSync(path.join(credsDir, 'env'), 0o600);
|
|
177
|
+
fs.rmSync(path.join(credsDir, '.none'), { force: true });
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return () => {
|
|
181
|
+
resetDir(configDir);
|
|
182
|
+
resetDir(credsDir);
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
60
186
|
/**
|
|
61
|
-
* P2 criterion 7 (D7): rebuild the runner image to pick up new pinned
|
|
62
|
-
*
|
|
63
|
-
*
|
|
187
|
+
* P2 criterion 7 (D7) + image plan P2: rebuild the runner image to pick up new pinned
|
|
188
|
+
* versions and a new agent list. Credentials only ever reach the build through the
|
|
189
|
+
* staged 0600 file when explicitly asked for (D-A: that image is a local secret);
|
|
190
|
+
* nothing secret is passed on the docker command line.
|
|
64
191
|
*/
|
|
65
192
|
export async function rebuildRunnerImage(
|
|
66
193
|
image: string,
|
|
67
|
-
|
|
194
|
+
options: RunnerBuildOptions = {},
|
|
68
195
|
exec: DockerExec = execFileAsync as unknown as DockerExec
|
|
69
196
|
): Promise<void> {
|
|
197
|
+
const { agents, skip_az, skip_gh, config_dir, credentials_file, data_dir, ...versions } = options;
|
|
70
198
|
const args: string[] = ['build', '--pull'];
|
|
71
199
|
if ((versions.hc === undefined) !== (versions.hc_sha256 === undefined)) {
|
|
72
200
|
throw new InvalidVersionError("'hc' and 'hc_sha256' go together: a new hc version needs its checksum");
|
|
@@ -98,10 +226,20 @@ export async function rebuildRunnerImage(
|
|
|
98
226
|
}
|
|
99
227
|
args.push('--build-arg', `${argName}=${value}`);
|
|
100
228
|
}
|
|
101
|
-
args.push('-t', image, runnerBuildContext);
|
|
102
229
|
|
|
230
|
+
// Image plan P2: the agent list (default pi = parity with the current image) and the
|
|
231
|
+
// optional staged config/credentials.
|
|
232
|
+
const agentList = agents === undefined ? ['pi'] : validateRunnerAgents(agents);
|
|
233
|
+
args.push('--build-arg', `AGENTS=${agentList.join(',')}`);
|
|
234
|
+
if (skip_az !== undefined) args.push('--build-arg', `SKIP_AZ=${skip_az ? '1' : '0'}`);
|
|
235
|
+
if (skip_gh !== undefined) args.push('--build-arg', `SKIP_GH=${skip_gh ? '1' : '0'}`);
|
|
236
|
+
if ((config_dir !== undefined || credentials_file !== undefined) && !data_dir) {
|
|
237
|
+
throw new InvalidBuildOptionsError("'data_dir' is required to stage config or credentials");
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const cleanup = stageBuildContext(runnerBuildContext, { config_dir, credentials_file, data_dir });
|
|
103
241
|
try {
|
|
104
|
-
await exec('docker', args, {
|
|
242
|
+
await exec('docker', [...args, '-t', image, runnerBuildContext], {
|
|
105
243
|
env: { ...process.env, DOCKER_BUILDKIT: '0' },
|
|
106
244
|
timeout: BUILD_TIMEOUT_MS,
|
|
107
245
|
maxBuffer: 32 * 1024 * 1024,
|
|
@@ -111,5 +249,7 @@ export async function rebuildRunnerImage(
|
|
|
111
249
|
// Full docker output stays in the orchestrator's log only, never in the HTTP body.
|
|
112
250
|
console.error(`[bond-app] docker build failed for ${image}: ${detail}`);
|
|
113
251
|
throw new RunnerBuildError(`Runner image build failed for ${image}`);
|
|
252
|
+
} finally {
|
|
253
|
+
cleanup();
|
|
114
254
|
}
|
|
115
255
|
}
|
package/src/server/app.ts
CHANGED
|
@@ -12,9 +12,11 @@ import {
|
|
|
12
12
|
JsonParseError,
|
|
13
13
|
PayloadTooLargeError,
|
|
14
14
|
} from '../core/orchestrator.ts';
|
|
15
|
-
import { InvalidVersionError, type RunnerVersions } from '../runner/image-builder.ts';
|
|
15
|
+
import { InvalidBuildOptionsError, InvalidVersionError, type RunnerVersions } from '../runner/image-builder.ts';
|
|
16
|
+
import { GitHubApiError } from '../runner/github-client.ts';
|
|
17
|
+
import { listProviderModels, normalizeProviderBase, ProviderModelsError } from '../core/setup.ts';
|
|
16
18
|
import { InvalidStateTransitionError } from '../core/state-machine.ts';
|
|
17
|
-
import { isValidAgent, validateGitHubLogin, validateGitHubToken, type CreateTicketInput, type RunState } from '../types.ts';
|
|
19
|
+
import { isValidAgent, isSetupAgent, SETUP_AGENTS, validateGitHubLogin, validateGitHubToken, type CreateTicketInput, type RunState } from '../types.ts';
|
|
18
20
|
|
|
19
21
|
export function createServer(orchestrator: Orchestrator): Server {
|
|
20
22
|
return http.createServer(async (req: IncomingMessage, res: ServerResponse) => {
|
|
@@ -152,6 +154,89 @@ export function createServer(orchestrator: Orchestrator): Server {
|
|
|
152
154
|
}
|
|
153
155
|
}
|
|
154
156
|
|
|
157
|
+
// Plan bond-app-nuevo-ticket (P1, D2): issues to link a new ticket to — the ones
|
|
158
|
+
// assigned to the user (GitHub session from Ajustes), open, `ready` first.
|
|
159
|
+
if (pathname === '/api/v1/issues/assigned' && method === 'GET') {
|
|
160
|
+
const provider = parsedUrl.searchParams.get('provider') || 'github';
|
|
161
|
+
if (provider !== 'github') {
|
|
162
|
+
sendJson(400, { error: `Unknown issue provider: ${provider}` });
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const ghToken = orchestrator.settingsRepo.getGitHubToken();
|
|
166
|
+
if (!ghToken) {
|
|
167
|
+
sendJson(409, { error: 'github_not_configured' });
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
try {
|
|
171
|
+
const issues = await orchestrator.github.listAssigned(ghToken);
|
|
172
|
+
const summary = orchestrator.settingsRepo.getGitHubSummary();
|
|
173
|
+
sendJson(200, { ok: true, provider: 'github', login: summary.login ?? null, issues });
|
|
174
|
+
} catch (err: unknown) {
|
|
175
|
+
const status = err instanceof GitHubApiError ? err.status : 0;
|
|
176
|
+
if (status === 401 || status === 403 || status === 404) {
|
|
177
|
+
sendJson(409, { error: 'github_not_configured' });
|
|
178
|
+
} else {
|
|
179
|
+
sendJson(502, { error: 'github_api_error', detail: (err as Error).message });
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Plan bond-app-nuevo-ticket (P2): primer paso de la búsqueda combinada del diálogo —
|
|
186
|
+
// repos por nombre (buscador de GitHub), con la misma sesión de gh de Ajustes.
|
|
187
|
+
if (pathname === '/api/v1/repos/search' && method === 'GET') {
|
|
188
|
+
const q = String(parsedUrl.searchParams.get('q') || '').trim();
|
|
189
|
+
if (!q) {
|
|
190
|
+
sendJson(400, { error: 'q_required' });
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
const ghToken = orchestrator.settingsRepo.getGitHubToken();
|
|
194
|
+
if (!ghToken) {
|
|
195
|
+
sendJson(409, { error: 'github_not_configured' });
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
try {
|
|
199
|
+
const repos = await orchestrator.github.searchRepos(ghToken, q);
|
|
200
|
+
sendJson(200, { ok: true, provider: 'github', repos });
|
|
201
|
+
} catch (err: unknown) {
|
|
202
|
+
const status = err instanceof GitHubApiError ? err.status : 0;
|
|
203
|
+
if (status === 401 || status === 403 || status === 404) {
|
|
204
|
+
sendJson(409, { error: 'github_not_configured' });
|
|
205
|
+
} else {
|
|
206
|
+
sendJson(502, { error: 'github_api_error', detail: (err as Error).message });
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// Segundo paso: issues abiertas de un repo (ready primero, las mías asignadas después).
|
|
213
|
+
if (pathname === '/api/v1/issues/repo' && method === 'GET') {
|
|
214
|
+
const owner = String(parsedUrl.searchParams.get('owner') || '');
|
|
215
|
+
const repo = String(parsedUrl.searchParams.get('repo') || '');
|
|
216
|
+
if (!/^[A-Za-z0-9_.-]+$/.test(owner) || !/^[A-Za-z0-9_.-]+$/.test(repo)) {
|
|
217
|
+
sendJson(400, { error: 'repo_invalid' });
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
const ghToken = orchestrator.settingsRepo.getGitHubToken();
|
|
221
|
+
if (!ghToken) {
|
|
222
|
+
sendJson(409, { error: 'github_not_configured' });
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
try {
|
|
226
|
+
const summary = orchestrator.settingsRepo.getGitHubSummary();
|
|
227
|
+
const issues = await orchestrator.github.listRepoIssues(ghToken, owner, repo, summary.login ?? null);
|
|
228
|
+
sendJson(200, { ok: true, provider: 'github', owner, repo, issues });
|
|
229
|
+
} catch (err: unknown) {
|
|
230
|
+
const status = err instanceof GitHubApiError ? err.status : 0;
|
|
231
|
+
if (status === 401 || status === 403 || status === 404) {
|
|
232
|
+
sendJson(409, { error: 'github_not_configured' });
|
|
233
|
+
} else {
|
|
234
|
+
sendJson(502, { error: 'github_api_error', detail: (err as Error).message });
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
|
|
155
240
|
const ticketPreviewMatch = pathname.match(/^\/api\/v1\/tickets\/([^/]+)\/delete_preview$/);
|
|
156
241
|
if (ticketPreviewMatch && method === 'GET') {
|
|
157
242
|
const ticketId = ticketPreviewMatch[1];
|
|
@@ -564,9 +649,106 @@ export function createServer(orchestrator: Orchestrator): Server {
|
|
|
564
649
|
}
|
|
565
650
|
}
|
|
566
651
|
|
|
567
|
-
//
|
|
568
|
-
//
|
|
569
|
-
//
|
|
652
|
+
// W-P1 (wizard): aggregated setup state. GET says what is missing; PUT stores the
|
|
653
|
+
// agent selection and setup_done (only via an explicit write). No credentials here:
|
|
654
|
+
// the aggregate only says whether each piece is configured (D13 summaries).
|
|
655
|
+
if (pathname === '/api/v1/setup') {
|
|
656
|
+
if (method === 'GET') {
|
|
657
|
+
sendJson(200, await orchestrator.getSetupState());
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
if (method === 'PUT') {
|
|
661
|
+
const body = await readJson();
|
|
662
|
+
const selection: {
|
|
663
|
+
agents_selected?: string[];
|
|
664
|
+
setup_done?: boolean;
|
|
665
|
+
suggestions_model?: string | null;
|
|
666
|
+
default_model?: string | null;
|
|
667
|
+
models?: string[];
|
|
668
|
+
} = {};
|
|
669
|
+
if (body.agents_selected !== undefined) {
|
|
670
|
+
const sel: unknown = body.agents_selected;
|
|
671
|
+
if (!Array.isArray(sel) || sel.some((a) => typeof a !== 'string' || !isSetupAgent(a))) {
|
|
672
|
+
sendJson(400, {
|
|
673
|
+
error: `'agents_selected' must be a list of the agents the image supports: ${SETUP_AGENTS.join(', ')}`,
|
|
674
|
+
});
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
selection.agents_selected = [...new Set(sel as string[])];
|
|
678
|
+
}
|
|
679
|
+
if (body.setup_done !== undefined) {
|
|
680
|
+
if (typeof body.setup_done !== 'boolean') {
|
|
681
|
+
sendJson(400, { error: "'setup_done' must be a boolean" });
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
selection.setup_done = body.setup_done;
|
|
685
|
+
}
|
|
686
|
+
if (body.suggestions_model !== undefined) {
|
|
687
|
+
// W-P4: loose validation (the plan's contract): a string id or null; whether
|
|
688
|
+
// the model still exists in the provider is not checked — a later PUT or run
|
|
689
|
+
// simply stops using it. '' reads as «sin sugerencias».
|
|
690
|
+
const v = body.suggestions_model;
|
|
691
|
+
if (v === null) selection.suggestions_model = null;
|
|
692
|
+
else if (typeof v === 'string') selection.suggestions_model = v.trim() || null;
|
|
693
|
+
else {
|
|
694
|
+
sendJson(400, { error: "'suggestions_model' must be a string or null" });
|
|
695
|
+
return;
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
if (body.default_model !== undefined) {
|
|
699
|
+
const v = body.default_model;
|
|
700
|
+
if (v === null) selection.default_model = null;
|
|
701
|
+
else if (typeof v === 'string') selection.default_model = v.trim() || null;
|
|
702
|
+
else {
|
|
703
|
+
sendJson(400, { error: "'default_model' must be a string or null" });
|
|
704
|
+
return;
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
if (body.models !== undefined) {
|
|
708
|
+
const m = body.models;
|
|
709
|
+
if (!Array.isArray(m) || m.some((x) => typeof x !== 'string')) {
|
|
710
|
+
sendJson(400, { error: "'models' must be an array of strings" });
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
const sanitized = (m as string[]).map((x) => x.trim()).filter(Boolean);
|
|
714
|
+
selection.models = [...new Set(sanitized)];
|
|
715
|
+
}
|
|
716
|
+
orchestrator.saveSetup(selection);
|
|
717
|
+
sendJson(200, await orchestrator.getSetupState());
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
// W-P4: model list of an OpenAI-compatible provider, proxied by the orchestrator
|
|
723
|
+
// (the browser never talks to the provider and the API key never goes to the log).
|
|
724
|
+
if (pathname === '/api/v1/setup/models' && method === 'POST') {
|
|
725
|
+
const body = await readJson(16 * 1024);
|
|
726
|
+
const baseUrl = typeof body.base_url === 'string' ? body.base_url.trim() : '';
|
|
727
|
+
if (!baseUrl || !normalizeProviderBase(baseUrl)) {
|
|
728
|
+
sendJson(400, { error: "'base_url' must be an http(s) URL" });
|
|
729
|
+
return;
|
|
730
|
+
}
|
|
731
|
+
const apiKey = typeof body.api_key === 'string' && body.api_key.trim() ? body.api_key.trim() : undefined;
|
|
732
|
+
try {
|
|
733
|
+
const models = await listProviderModels({ baseUrl, apiKey });
|
|
734
|
+
sendJson(200, { models });
|
|
735
|
+
} catch (err) {
|
|
736
|
+
// ProviderModelsError messages carry neither the key nor the URL.
|
|
737
|
+
if (err instanceof ProviderModelsError) {
|
|
738
|
+
sendJson(502, { error: err.message });
|
|
739
|
+
} else {
|
|
740
|
+
sendJson(502, { error: 'could not list the provider models' });
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
return;
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
// P2 criterion 7 (D7) + image plan P2: rebuild the runner image. Optional JSON body
|
|
747
|
+
// {bond?, hc?, hc_sha256?, herdr?, herdr_sha256?, pi?} pins new versions via --build-arg
|
|
748
|
+
// (review M4; a new hc version needs its checksum, P2 debt N1), and {agents?}
|
|
749
|
+
// (non-empty string array) picks the agent list baked by runner/setup.sh. Optional
|
|
750
|
+
// config_dir / credentials_file name paths inside the data dir (validated by the
|
|
751
|
+
// builder; credentials must be 0600, and an image built with them is a local secret, D-A).
|
|
570
752
|
if (pathname === '/api/v1/system/rebuild' && method === 'POST') {
|
|
571
753
|
let body: Record<string, unknown> = {};
|
|
572
754
|
// Optional JSON body; readJson resolves {} on an empty body, and this keeps
|
|
@@ -577,7 +759,29 @@ export function createServer(orchestrator: Orchestrator): Server {
|
|
|
577
759
|
const value = body[key];
|
|
578
760
|
if (value !== undefined) versions[key] = String(value);
|
|
579
761
|
}
|
|
580
|
-
const
|
|
762
|
+
const extras: {
|
|
763
|
+
agents?: string[];
|
|
764
|
+
skip_az?: boolean;
|
|
765
|
+
skip_gh?: boolean;
|
|
766
|
+
config_dir?: string;
|
|
767
|
+
credentials_file?: string;
|
|
768
|
+
} = {};
|
|
769
|
+
if (body.agents !== undefined) {
|
|
770
|
+
if (!Array.isArray(body.agents) || body.agents.length === 0) {
|
|
771
|
+
sendJson(400, { error: "'agents' must be a non-empty array of agent names" });
|
|
772
|
+
return;
|
|
773
|
+
}
|
|
774
|
+
extras.agents = body.agents.map((a) => String(a));
|
|
775
|
+
}
|
|
776
|
+
for (const key of ['skip_az', 'skip_gh'] as const) {
|
|
777
|
+
const value = body[key];
|
|
778
|
+
if (typeof value === 'boolean') extras[key] = value;
|
|
779
|
+
}
|
|
780
|
+
for (const key of ['config_dir', 'credentials_file'] as const) {
|
|
781
|
+
const value = body[key];
|
|
782
|
+
if (typeof value === 'string' && value.trim()) extras[key] = value.trim();
|
|
783
|
+
}
|
|
784
|
+
const result = await orchestrator.rebuildRunnerImage(versions, extras);
|
|
581
785
|
sendJson(200, result);
|
|
582
786
|
return;
|
|
583
787
|
}
|
|
@@ -589,7 +793,7 @@ export function createServer(orchestrator: Orchestrator): Server {
|
|
|
589
793
|
sendJson(409, { error: (err as Error).message });
|
|
590
794
|
return;
|
|
591
795
|
}
|
|
592
|
-
if (err instanceof InvalidVersionError || err instanceof JsonParseError || err instanceof ValidationError) {
|
|
796
|
+
if (err instanceof InvalidVersionError || err instanceof InvalidBuildOptionsError || err instanceof JsonParseError || err instanceof ValidationError) {
|
|
593
797
|
sendJson(400, { error: (err as Error).message });
|
|
594
798
|
return;
|
|
595
799
|
}
|
package/src/types.ts
CHANGED
|
@@ -42,6 +42,18 @@ export function isValidAgent(agent: string): agent is SupportedAgent {
|
|
|
42
42
|
return (SUPPORTED_AGENTS as readonly string[]).includes(agent);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Wizard plan (D-W3, image plan D-B): the agents runner/setup.sh can bake into the image,
|
|
47
|
+
* which are the ones the setup wizard offers and `agents_selected` validates against.
|
|
48
|
+
* opencode/crush/coding-by-stdin are not selectable yet.
|
|
49
|
+
*/
|
|
50
|
+
export const SETUP_AGENTS = ['pi', 'claude', 'codex', 'copilot', 'agy'] as const;
|
|
51
|
+
export type SetupAgent = (typeof SETUP_AGENTS)[number];
|
|
52
|
+
|
|
53
|
+
export function isSetupAgent(agent: string): agent is SetupAgent {
|
|
54
|
+
return (SETUP_AGENTS as readonly string[]).includes(agent);
|
|
55
|
+
}
|
|
56
|
+
|
|
45
57
|
export function validateBranchName(name: string): boolean {
|
|
46
58
|
if (!name || typeof name !== 'string') return false;
|
|
47
59
|
const trimmed = name.trim();
|
|
@@ -91,6 +103,8 @@ export interface Ticket {
|
|
|
91
103
|
prompt?: string;
|
|
92
104
|
/** P4: shell commands run in the clone (as `runner`) before the push; all must pass. */
|
|
93
105
|
verify_commands: string[];
|
|
106
|
+
/** P4 (D-U): auto-bondify the cloned repo if not already bondified; default true. */
|
|
107
|
+
bondify: boolean;
|
|
94
108
|
/** P9: engine for bond team inside run container: 'hc' (default, native panes) or 'herdr' (TUI mode). */
|
|
95
109
|
team_engine?: 'hc' | 'herdr';
|
|
96
110
|
status: RunState;
|
|
@@ -119,6 +133,8 @@ export interface CreateTicketInput {
|
|
|
119
133
|
model?: string;
|
|
120
134
|
prompt?: string;
|
|
121
135
|
verify_commands?: string[];
|
|
136
|
+
/** P4 (D-U): auto-bondify the cloned repo if not already bondified; default true. */
|
|
137
|
+
bondify?: boolean;
|
|
122
138
|
/** P9: engine for bond team inside run container: 'hc' (default) or 'herdr'. */
|
|
123
139
|
team_engine?: 'hc' | 'herdr';
|
|
124
140
|
}
|
|
@@ -303,6 +319,30 @@ export interface GitHubCredentialSummary {
|
|
|
303
319
|
updated_at?: string;
|
|
304
320
|
}
|
|
305
321
|
|
|
322
|
+
/** W-P1: what the API says about the runner image (presence and, when the image carries
|
|
323
|
+
* the /opt/runner-agents manifest, the agents baked into it). */
|
|
324
|
+
export interface RunnerImageInfo {
|
|
325
|
+
present: boolean;
|
|
326
|
+
agents?: string[];
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/** W-P1: the aggregated setup state the wizard and the Ajustes panel read. */
|
|
330
|
+
export interface SetupState {
|
|
331
|
+
/** gh configured + at least one agent with credential + runner image present. */
|
|
332
|
+
complete: boolean;
|
|
333
|
+
setup_done: boolean;
|
|
334
|
+
agents_selected: string[];
|
|
335
|
+
agents: Array<{ agent: string; configured: boolean }>;
|
|
336
|
+
github: { configured: boolean; login?: string };
|
|
337
|
+
image: RunnerImageInfo;
|
|
338
|
+
/** W-P4: model chosen for prompt suggestions (supi); null = «sin sugerencias». */
|
|
339
|
+
suggestions_model: string | null;
|
|
340
|
+
/** D-M1: default working model for pi; null = provider baked default. */
|
|
341
|
+
default_model: string | null;
|
|
342
|
+
/** P3: full model ids configured for pi (provider/id). */
|
|
343
|
+
models: string[];
|
|
344
|
+
}
|
|
345
|
+
|
|
306
346
|
/** gh / GitHub tokens: gho_…, ghp_…, github_pat_… — one word, no whitespace. */
|
|
307
347
|
export function validateGitHubToken(token: unknown): token is string {
|
|
308
348
|
return typeof token === 'string' && /^[A-Za-z0-9_]{20,255}$/.test(token);
|