@jmanuelcorral/bond-app 0.1.5 → 0.1.6
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 +211 -17
- package/app/brand/TOKENS.md +5 -5
- package/app/layouts/bond.json +10 -14
- package/app/mods/bond-agents/api.js +35 -0
- package/app/mods/bond-agents/branch.svg +1 -0
- package/app/mods/bond-agents/brand.js +53 -2
- package/app/mods/bond-agents/config.js +4 -0
- package/app/mods/bond-agents/eye-off.svg +1 -0
- package/app/mods/bond-agents/eye.svg +1 -0
- package/app/mods/bond-agents/main.js +308 -327
- package/app/mods/bond-agents/model.js +354 -5
- package/app/mods/bond-board/api.js +35 -0
- package/app/mods/bond-board/branch.svg +1 -0
- package/app/mods/bond-board/brand.js +53 -2
- package/app/mods/bond-board/config.js +4 -0
- package/app/mods/bond-board/main.js +686 -444
- package/app/mods/bond-board/model.js +99 -25
- package/app/mods/bond-pane/close.svg +1 -0
- package/app/mods/bond-pane/hide.svg +1 -0
- package/app/mods/bond-pane/main.js +103 -0
- package/app/mods/bond-pane/mod.json +1 -0
- package/app/mods/bond-pane/model.js +18 -0
- package/app/mods/bond-pane/split-down.svg +1 -0
- package/app/mods/bond-pane/split-right.svg +1 -0
- package/app/mods/bond-pane/unzoom.svg +1 -0
- package/app/mods/bond-pane/zoom.svg +1 -0
- package/app/mods/bond-settings/api.js +35 -0
- package/app/mods/bond-settings/brand.js +53 -2
- package/app/mods/bond-settings/config.js +4 -0
- package/app/mods/bond-settings/main.js +1159 -278
- package/app/mods/bond-settings/mod.json +1 -1
- package/app/mods/bond-status/api.js +35 -0
- package/app/mods/bond-status/brand.js +53 -2
- package/app/mods/bond-status/config.js +4 -0
- package/app/mods/bond-status/main.js +37 -15
- package/app/mods/bond-status/model.js +19 -1
- package/app/mods/bond-tabs/brand.js +53 -2
- package/app/mods/bond-tabs/main.js +45 -3
- package/app/mods/bond-titlebar/brand.js +53 -2
- package/app/mods/bond-titlebar/main.js +85 -29
- package/app/mods/bond-titlebar/version.js +3 -0
- package/app/themes/bond-dark.json +5 -5
- package/app/themes/bond-light.json +5 -5
- package/package.json +1 -1
- package/runner/Dockerfile +16 -2
- package/runner/SPIKE-BOND.md +6 -2
- package/runner/entrypoint.sh +16 -0
- package/runner/setup.sh +439 -8
- package/runner/versions.env +32 -1
- package/scripts/app-install.ts +60 -1
- package/src/cli.ts +53 -3
- package/src/core/agy-login.ts +682 -0
- package/src/core/delivery.ts +3 -1
- package/src/core/orchestrator.ts +736 -78
- package/src/core/repo-host.ts +60 -0
- package/src/core/setup.ts +62 -1
- package/src/core/watchdog.ts +6 -6
- package/src/db/database.ts +41 -1
- package/src/db/settings-repo.ts +332 -7
- package/src/db/ticket-repo.ts +46 -20
- package/src/index.ts +4 -4
- package/src/runner/azure-devops-client.ts +163 -0
- package/src/runner/docker-client.ts +59 -9
- package/src/runner/github-client.ts +30 -3
- package/src/runner/hc-client.ts +33 -5
- package/src/runner/image-builder.ts +123 -5
- package/src/runner/jira-client.ts +368 -0
- package/src/runner/tool-catalog.ts +84 -0
- package/src/server/app.ts +377 -5
- package/src/types.ts +129 -2
package/src/server/app.ts
CHANGED
|
@@ -14,11 +14,33 @@ import {
|
|
|
14
14
|
} from '../core/orchestrator.ts';
|
|
15
15
|
import { InvalidBuildOptionsError, InvalidVersionError, type RunnerVersions } from '../runner/image-builder.ts';
|
|
16
16
|
import { GitHubApiError } from '../runner/github-client.ts';
|
|
17
|
+
import { JiraApiError } from '../runner/jira-client.ts';
|
|
18
|
+
import { validateAptExtra, validateToolGroups } from '../runner/tool-catalog.ts';
|
|
19
|
+
import { normalizeAzureOrgUrl } from '../runner/azure-devops-client.ts';
|
|
20
|
+
import { validateRepoUrl } from '../core/repo-host.ts';
|
|
21
|
+
import { keepPiKeys } from '../db/settings-repo.ts';
|
|
17
22
|
import { listProviderModels, normalizeProviderBase, ProviderModelsError } from '../core/setup.ts';
|
|
18
23
|
import { InvalidStateTransitionError } from '../core/state-machine.ts';
|
|
19
|
-
import {
|
|
24
|
+
import {
|
|
25
|
+
isValidAgent,
|
|
26
|
+
isSetupAgent,
|
|
27
|
+
SETUP_AGENTS,
|
|
28
|
+
validateGitHubLogin,
|
|
29
|
+
validateGitHubToken,
|
|
30
|
+
validateJiraSite,
|
|
31
|
+
validateJiraEmail,
|
|
32
|
+
validateJiraToken,
|
|
33
|
+
type CreateTicketInput,
|
|
34
|
+
type RunState,
|
|
35
|
+
} from '../types.ts';
|
|
36
|
+
|
|
37
|
+
/** What the server can ask of the process that runs it. */
|
|
38
|
+
export interface ServerHooks {
|
|
39
|
+
/** Stop like Ctrl+C and start again with the same argv and environment (Ajustes «Reiniciar»). */
|
|
40
|
+
onRestart?: () => void;
|
|
41
|
+
}
|
|
20
42
|
|
|
21
|
-
export function createServer(orchestrator: Orchestrator): Server {
|
|
43
|
+
export function createServer(orchestrator: Orchestrator, hooks: ServerHooks = {}): Server {
|
|
22
44
|
return http.createServer(async (req: IncomingMessage, res: ServerResponse) => {
|
|
23
45
|
const sendJson = (statusCode: number, data: unknown) => {
|
|
24
46
|
res.writeHead(statusCode, { 'Content-Type': 'application/json' });
|
|
@@ -155,13 +177,39 @@ export function createServer(orchestrator: Orchestrator): Server {
|
|
|
155
177
|
}
|
|
156
178
|
|
|
157
179
|
// 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.
|
|
180
|
+
// assigned to the user (GitHub session from Ajustes, or Jira Cloud), open, `ready` first.
|
|
159
181
|
if (pathname === '/api/v1/issues/assigned' && method === 'GET') {
|
|
160
182
|
const provider = parsedUrl.searchParams.get('provider') || 'github';
|
|
161
|
-
if (provider !== 'github') {
|
|
183
|
+
if (provider !== 'github' && provider !== 'jira') {
|
|
162
184
|
sendJson(400, { error: `Unknown issue provider: ${provider}` });
|
|
163
185
|
return;
|
|
164
186
|
}
|
|
187
|
+
if (provider === 'jira') {
|
|
188
|
+
const jiraCred = orchestrator.settingsRepo.getJiraCredential();
|
|
189
|
+
if (!jiraCred) {
|
|
190
|
+
sendJson(409, { error: 'jira_not_configured' });
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
try {
|
|
194
|
+
const issues = await orchestrator.jira.listAssigned(jiraCred.site, jiraCred.email, jiraCred.token);
|
|
195
|
+
const summary = orchestrator.settingsRepo.getJiraSummary();
|
|
196
|
+
sendJson(200, {
|
|
197
|
+
ok: true,
|
|
198
|
+
provider: 'jira',
|
|
199
|
+
login: summary.account_name ?? summary.email ?? null,
|
|
200
|
+
site: summary.site,
|
|
201
|
+
issues,
|
|
202
|
+
});
|
|
203
|
+
} catch (err: unknown) {
|
|
204
|
+
const status = err instanceof JiraApiError ? err.status : 0;
|
|
205
|
+
if (status === 401 || status === 403) {
|
|
206
|
+
sendJson(409, { error: 'jira_not_configured', detail: (err as Error).message });
|
|
207
|
+
} else {
|
|
208
|
+
sendJson(502, { error: 'jira_api_error', detail: (err as Error).message });
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
165
213
|
const ghToken = orchestrator.settingsRepo.getGitHubToken();
|
|
166
214
|
if (!ghToken) {
|
|
167
215
|
sendJson(409, { error: 'github_not_configured' });
|
|
@@ -182,6 +230,30 @@ export function createServer(orchestrator: Orchestrator): Server {
|
|
|
182
230
|
return;
|
|
183
231
|
}
|
|
184
232
|
|
|
233
|
+
// Plan bond-app-azure-jira (P2): búsqueda de issues de Jira por texto y/o proyecto
|
|
234
|
+
if (pathname === '/api/v1/issues/jira/search' && method === 'GET') {
|
|
235
|
+
const q = String(parsedUrl.searchParams.get('q') || '').trim();
|
|
236
|
+
const project = String(parsedUrl.searchParams.get('project') || '').trim();
|
|
237
|
+
const mine = parsedUrl.searchParams.get('mine') === '1';
|
|
238
|
+
const jiraCred = orchestrator.settingsRepo.getJiraCredential();
|
|
239
|
+
if (!jiraCred) {
|
|
240
|
+
sendJson(409, { error: 'jira_not_configured' });
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
try {
|
|
244
|
+
const issues = await orchestrator.jira.search(jiraCred.site, jiraCred.email, jiraCred.token, { q, project, mine });
|
|
245
|
+
sendJson(200, { ok: true, provider: 'jira', issues });
|
|
246
|
+
} catch (err: unknown) {
|
|
247
|
+
const status = err instanceof JiraApiError ? err.status : 0;
|
|
248
|
+
if (status === 401 || status === 403) {
|
|
249
|
+
sendJson(409, { error: 'jira_not_configured', detail: (err as Error).message });
|
|
250
|
+
} else {
|
|
251
|
+
sendJson(502, { error: 'jira_api_error', detail: (err as Error).message });
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
|
|
185
257
|
// Plan bond-app-nuevo-ticket (P2): primer paso de la búsqueda combinada del diálogo —
|
|
186
258
|
// repos por nombre (buscador de GitHub), con la misma sesión de gh de Ajustes.
|
|
187
259
|
if (pathname === '/api/v1/repos/search' && method === 'GET') {
|
|
@@ -209,6 +281,56 @@ export function createServer(orchestrator: Orchestrator): Server {
|
|
|
209
281
|
return;
|
|
210
282
|
}
|
|
211
283
|
|
|
284
|
+
// Alta de ticket (Dónde): favoritos, recientes, Azure Repos y GitHub en una lista.
|
|
285
|
+
if (pathname === '/api/v1/repos/suggest' && method === 'GET') {
|
|
286
|
+
const q = String(parsedUrl.searchParams.get('q') || '').slice(0, 100);
|
|
287
|
+
sendJson(200, await orchestrator.suggestRepos(q));
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
if (pathname === '/api/v1/repos/favorites') {
|
|
291
|
+
if (method === 'GET') {
|
|
292
|
+
sendJson(200, { favorites: orchestrator.settingsRepo.getFavoriteRepos() });
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
if (method === 'PUT') {
|
|
296
|
+
const body = await readJson();
|
|
297
|
+
const list: unknown = body.favorites;
|
|
298
|
+
if (!Array.isArray(list) || list.some((u) => typeof u !== 'string' || !validateRepoUrl(u))) {
|
|
299
|
+
sendJson(400, { error: "'favorites' must be a list of GitHub or Azure Repos URLs" });
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
sendJson(200, { favorites: orchestrator.settingsRepo.setFavoriteRepos(list as string[]) });
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// Plan bond-app-ajustes-imagen P4: ¿trae el repo devcontainer? (pre-marca «Docker en el run»).
|
|
308
|
+
// Alta en tres bloques: y ¿es un hub (hub.toml)? (el alta pasa sola a modo hub).
|
|
309
|
+
if (pathname === '/api/v1/repos/devcontainer' && method === 'GET') {
|
|
310
|
+
const owner = String(parsedUrl.searchParams.get('owner') || '');
|
|
311
|
+
const repo = String(parsedUrl.searchParams.get('repo') || '');
|
|
312
|
+
const ref = String(parsedUrl.searchParams.get('ref') || '').trim() || undefined;
|
|
313
|
+
if (!/^[A-Za-z0-9_.-]+$/.test(owner) || !/^[A-Za-z0-9_.-]+$/.test(repo) || (ref && !/^[A-Za-z0-9._\/-]{1,200}$/.test(ref))) {
|
|
314
|
+
sendJson(400, { error: 'repo_invalid' });
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
const ghToken = orchestrator.settingsRepo.getGitHubToken();
|
|
318
|
+
if (!ghToken) {
|
|
319
|
+
sendJson(200, { devcontainer: false, hub: false, checked: false });
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
try {
|
|
323
|
+
const [devcontainer, hub] = await Promise.all([
|
|
324
|
+
orchestrator.github.hasDevcontainer(ghToken, owner, repo, ref),
|
|
325
|
+
orchestrator.github.isHub(ghToken, owner, repo, ref),
|
|
326
|
+
]);
|
|
327
|
+
sendJson(200, { devcontainer, hub, checked: true });
|
|
328
|
+
} catch {
|
|
329
|
+
sendJson(200, { devcontainer: false, hub: false, checked: false });
|
|
330
|
+
}
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
|
|
212
334
|
// Segundo paso: issues abiertas de un repo (ready primero, las mías asignadas después).
|
|
213
335
|
if (pathname === '/api/v1/issues/repo' && method === 'GET') {
|
|
214
336
|
const owner = String(parsedUrl.searchParams.get('owner') || '');
|
|
@@ -496,6 +618,27 @@ export function createServer(orchestrator: Orchestrator): Server {
|
|
|
496
618
|
return;
|
|
497
619
|
}
|
|
498
620
|
|
|
621
|
+
// P4: endpoint GET /runs/:id/terminals (proxy hc ls for the run's machine)
|
|
622
|
+
const runTerminalsMatch = pathname.match(/^(?:\/api\/v1)?\/runs\/([^/]+)\/terminals$/);
|
|
623
|
+
if (runTerminalsMatch && method === 'GET') {
|
|
624
|
+
const runId = runTerminalsMatch[1];
|
|
625
|
+
if (!orchestrator.runRepo.get(runId)) {
|
|
626
|
+
sendJson(404, { error: `Run '${runId}' not found` });
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
629
|
+
try {
|
|
630
|
+
const terminals = await orchestrator.getRunTerminals(runId);
|
|
631
|
+
sendJson(200, terminals);
|
|
632
|
+
} catch (err: unknown) {
|
|
633
|
+
if (err instanceof ValidationError) {
|
|
634
|
+
sendJson(400, { error: (err as Error).message });
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
637
|
+
sendJson(500, { error: (err as Error).message });
|
|
638
|
+
}
|
|
639
|
+
return;
|
|
640
|
+
}
|
|
641
|
+
|
|
499
642
|
const runTransitionMatch =pathname.match(/^\/api\/v1\/runs\/([^/]+)\/transition$/);
|
|
500
643
|
if (runTransitionMatch && method === 'POST') {
|
|
501
644
|
const runId = runTransitionMatch[1];
|
|
@@ -614,13 +757,81 @@ export function createServer(orchestrator: Orchestrator): Server {
|
|
|
614
757
|
sendJson(400, { error: "'config_json' is required" });
|
|
615
758
|
return;
|
|
616
759
|
}
|
|
617
|
-
|
|
760
|
+
// pi: a provider saved without a key keeps the stored one (Ajustes never shows it).
|
|
761
|
+
const toStore = agent === 'pi' ? keepPiKeys(orchestrator.settingsRepo.getCredential('pi')?.config_json, configJson) : configJson;
|
|
762
|
+
orchestrator.settingsRepo.setCredential(agent, toStore, provider);
|
|
763
|
+
const summary = orchestrator.settingsRepo.getSummary(agent);
|
|
764
|
+
sendJson(200, summary);
|
|
765
|
+
return;
|
|
766
|
+
}
|
|
767
|
+
if (method === 'DELETE') {
|
|
768
|
+
orchestrator.settingsRepo.deleteCredential(agent);
|
|
618
769
|
const summary = orchestrator.settingsRepo.getSummary(agent);
|
|
619
770
|
sendJson(200, summary);
|
|
620
771
|
return;
|
|
621
772
|
}
|
|
622
773
|
}
|
|
623
774
|
|
|
775
|
+
// OAuth login per agent: agy (P1), claude (`claude setup-token`, plan
|
|
776
|
+
// bond-app-claude-agente P2), codex (ChatGPT, browser callback replayed in the
|
|
777
|
+
// container) and copilot (device code), plan bond-app-codex-copilot P2. The API never
|
|
778
|
+
// returns a token, only the session state.
|
|
779
|
+
const loginMatch = pathname.match(/^\/api\/v1\/settings\/(agy|claude|codex|copilot)\/login(\/.*)?$/);
|
|
780
|
+
if (loginMatch) {
|
|
781
|
+
const loginManager = {
|
|
782
|
+
agy: orchestrator.agyLoginManager,
|
|
783
|
+
claude: orchestrator.claudeLoginManager,
|
|
784
|
+
codex: orchestrator.codexLoginManager,
|
|
785
|
+
copilot: orchestrator.copilotLoginManager,
|
|
786
|
+
}[loginMatch[1] as 'agy' | 'claude' | 'codex' | 'copilot'];
|
|
787
|
+
const sub = loginMatch[2] ?? '';
|
|
788
|
+
if (sub === '' || sub === '/status') {
|
|
789
|
+
if (method === 'GET') {
|
|
790
|
+
sendJson(200, loginManager.getStatus());
|
|
791
|
+
return;
|
|
792
|
+
}
|
|
793
|
+
if (method === 'POST') {
|
|
794
|
+
const status = await loginManager.start();
|
|
795
|
+
sendJson(200, status);
|
|
796
|
+
return;
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
if (sub === '/start' && method === 'POST') {
|
|
800
|
+
const status = await loginManager.start();
|
|
801
|
+
sendJson(200, status);
|
|
802
|
+
return;
|
|
803
|
+
}
|
|
804
|
+
if (sub === '/url' && method === 'GET') {
|
|
805
|
+
const status = loginManager.getStatus();
|
|
806
|
+
sendJson(200, { url: status.url ?? null });
|
|
807
|
+
return;
|
|
808
|
+
}
|
|
809
|
+
if (sub === '/code' && method === 'POST') {
|
|
810
|
+
const body = await readJson();
|
|
811
|
+
if (typeof body.code !== 'string' || !body.code.trim()) {
|
|
812
|
+
sendJson(400, { error: "'code' must be a non-empty string" });
|
|
813
|
+
return;
|
|
814
|
+
}
|
|
815
|
+
try {
|
|
816
|
+
const status = await loginManager.submitCode(body.code.trim());
|
|
817
|
+
sendJson(200, status);
|
|
818
|
+
} catch (err: unknown) {
|
|
819
|
+
sendJson(400, { error: (err as Error).message });
|
|
820
|
+
}
|
|
821
|
+
return;
|
|
822
|
+
}
|
|
823
|
+
if (sub === '/finish' && method === 'POST') {
|
|
824
|
+
const res = await loginManager.finish();
|
|
825
|
+
sendJson(200, res);
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
828
|
+
if ((sub === '/cancel' && method === 'POST') || (sub === '' && method === 'DELETE')) {
|
|
829
|
+
const status = await loginManager.cancel();
|
|
830
|
+
sendJson(200, status);
|
|
831
|
+
return;
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
|
|
624
835
|
// D20: the GitHub credential for the runs' clones (the user's gh session). The API
|
|
625
836
|
// only ever says whether one is stored and for which login; never the token.
|
|
626
837
|
if (pathname === '/api/v1/settings/github') {
|
|
@@ -649,6 +860,122 @@ export function createServer(orchestrator: Orchestrator): Server {
|
|
|
649
860
|
}
|
|
650
861
|
}
|
|
651
862
|
|
|
863
|
+
// Plan bond-app-azure-jira (P2): Jira Cloud credential (email + API token).
|
|
864
|
+
// The API only ever says whether one is stored, for which site, email and account; never the token.
|
|
865
|
+
if (pathname === '/api/v1/settings/jira') {
|
|
866
|
+
if (method === 'GET') {
|
|
867
|
+
sendJson(200, orchestrator.settingsRepo.getJiraSummary());
|
|
868
|
+
return;
|
|
869
|
+
}
|
|
870
|
+
if (method === 'PUT') {
|
|
871
|
+
const body = await readJson();
|
|
872
|
+
const site = typeof body.site === 'string' ? body.site.trim() : '';
|
|
873
|
+
const email = typeof body.email === 'string' ? body.email.trim() : '';
|
|
874
|
+
const agentsEnabled = body.agents_enabled !== false;
|
|
875
|
+
|
|
876
|
+
if (!validateJiraSite(site)) {
|
|
877
|
+
sendJson(400, { error: "'site' must be a Jira Cloud URL (https://<name>.atlassian.net)" });
|
|
878
|
+
return;
|
|
879
|
+
}
|
|
880
|
+
if (!validateJiraEmail(email)) {
|
|
881
|
+
sendJson(400, { error: "'email' is required and must be a valid email" });
|
|
882
|
+
return;
|
|
883
|
+
}
|
|
884
|
+
let token = typeof body.token === 'string' ? body.token.trim() : '';
|
|
885
|
+
if (!validateJiraToken(token)) {
|
|
886
|
+
// Empty token with a credential already stored: keep the stored one, so the
|
|
887
|
+
// site, the email or the «Disponible para los agentes» switch can be
|
|
888
|
+
// changed without retyping the token (the API never shows it).
|
|
889
|
+
const existing = orchestrator.settingsRepo.getJiraCredential();
|
|
890
|
+
if (!existing) {
|
|
891
|
+
sendJson(400, { error: "'token' is required" });
|
|
892
|
+
return;
|
|
893
|
+
}
|
|
894
|
+
token = existing.token;
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
let accountName: string | undefined;
|
|
898
|
+
try {
|
|
899
|
+
const user = await orchestrator.jira.myself(site, email, token);
|
|
900
|
+
accountName = user.displayName;
|
|
901
|
+
} catch (err: unknown) {
|
|
902
|
+
const status = err instanceof JiraApiError ? err.status : 0;
|
|
903
|
+
const msg = (err as Error).message;
|
|
904
|
+
if (status === 401 || status === 403) {
|
|
905
|
+
sendJson(409, { error: 'jira_authentication_failed', detail: msg });
|
|
906
|
+
} else {
|
|
907
|
+
sendJson(400, { error: 'jira_connection_failed', detail: msg });
|
|
908
|
+
}
|
|
909
|
+
return;
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
const summary = orchestrator.settingsRepo.setJiraCredential(
|
|
913
|
+
site,
|
|
914
|
+
email,
|
|
915
|
+
token,
|
|
916
|
+
agentsEnabled,
|
|
917
|
+
accountName
|
|
918
|
+
);
|
|
919
|
+
sendJson(200, summary);
|
|
920
|
+
return;
|
|
921
|
+
}
|
|
922
|
+
if (method === 'DELETE') {
|
|
923
|
+
orchestrator.settingsRepo.deleteJiraCredential();
|
|
924
|
+
sendJson(200, orchestrator.settingsRepo.getJiraSummary());
|
|
925
|
+
return;
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
// Plan bond-app-azure-jira P1: the Azure DevOps PAT (Azure Repos). PUT checks it against
|
|
930
|
+
// the organization before storing it; the PAT never comes back.
|
|
931
|
+
if (pathname === '/api/v1/settings/azure-devops') {
|
|
932
|
+
const repo = orchestrator.settingsRepo;
|
|
933
|
+
if (method === 'GET') {
|
|
934
|
+
sendJson(200, repo.getAzureDevOpsSummary());
|
|
935
|
+
return;
|
|
936
|
+
}
|
|
937
|
+
if (method === 'PUT') {
|
|
938
|
+
const body = await readJson();
|
|
939
|
+
const agents = body.agents_enabled === undefined ? undefined : body.agents_enabled;
|
|
940
|
+
if (agents !== undefined && typeof agents !== 'boolean') {
|
|
941
|
+
sendJson(400, { error: "'agents_enabled' must be a boolean" });
|
|
942
|
+
return;
|
|
943
|
+
}
|
|
944
|
+
if (body.pat === undefined && body.org_url === undefined) {
|
|
945
|
+
if (agents === undefined || !repo.getAzureDevOpsCredential()) {
|
|
946
|
+
sendJson(400, { error: "'org_url' and 'pat' are required" });
|
|
947
|
+
return;
|
|
948
|
+
}
|
|
949
|
+
sendJson(200, repo.setAzureDevOpsAgentsEnabled(agents));
|
|
950
|
+
return;
|
|
951
|
+
}
|
|
952
|
+
const orgUrl = normalizeAzureOrgUrl(String(body.org_url ?? ''));
|
|
953
|
+
if (!orgUrl) {
|
|
954
|
+
sendJson(400, { error: "'org_url' must be https://dev.azure.com/<organización>" });
|
|
955
|
+
return;
|
|
956
|
+
}
|
|
957
|
+
const pat = String(body.pat ?? '').trim();
|
|
958
|
+
if (!/^[A-Za-z0-9]{20,200}$/.test(pat)) {
|
|
959
|
+
sendJson(400, { error: "'pat' must be an Azure DevOps personal access token" });
|
|
960
|
+
return;
|
|
961
|
+
}
|
|
962
|
+
let who: { name: string; email?: string };
|
|
963
|
+
try {
|
|
964
|
+
who = await orchestrator.azure.whoAmI(pat, orgUrl);
|
|
965
|
+
} catch (err: unknown) {
|
|
966
|
+
sendJson(409, { error: 'azure_devops_rejected', detail: (err as Error).message });
|
|
967
|
+
return;
|
|
968
|
+
}
|
|
969
|
+
sendJson(200, repo.setAzureDevOpsCredential(orgUrl, pat, who.email ? `${who.name} <${who.email}>` : who.name, agents ?? true));
|
|
970
|
+
return;
|
|
971
|
+
}
|
|
972
|
+
if (method === 'DELETE') {
|
|
973
|
+
repo.deleteAzureDevOpsCredential();
|
|
974
|
+
sendJson(200, repo.getAzureDevOpsSummary());
|
|
975
|
+
return;
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
|
|
652
979
|
// W-P1 (wizard): aggregated setup state. GET says what is missing; PUT stores the
|
|
653
980
|
// agent selection and setup_done (only via an explicit write). No credentials here:
|
|
654
981
|
// the aggregate only says whether each piece is configured (D13 summaries).
|
|
@@ -665,6 +992,8 @@ export function createServer(orchestrator: Orchestrator): Server {
|
|
|
665
992
|
suggestions_model?: string | null;
|
|
666
993
|
default_model?: string | null;
|
|
667
994
|
models?: string[];
|
|
995
|
+
tools_selected?: string[];
|
|
996
|
+
apt_extra?: string[];
|
|
668
997
|
} = {};
|
|
669
998
|
if (body.agents_selected !== undefined) {
|
|
670
999
|
const sel: unknown = body.agents_selected;
|
|
@@ -713,6 +1042,14 @@ export function createServer(orchestrator: Orchestrator): Server {
|
|
|
713
1042
|
const sanitized = (m as string[]).map((x) => x.trim()).filter(Boolean);
|
|
714
1043
|
selection.models = [...new Set(sanitized)];
|
|
715
1044
|
}
|
|
1045
|
+
// Plan bond-app-ajustes-imagen P2: tool groups of the catalog and extra Debian packages.
|
|
1046
|
+
try {
|
|
1047
|
+
if (body.tools_selected !== undefined) selection.tools_selected = validateToolGroups(body.tools_selected);
|
|
1048
|
+
if (body.apt_extra !== undefined) selection.apt_extra = validateAptExtra(body.apt_extra);
|
|
1049
|
+
} catch (err: unknown) {
|
|
1050
|
+
sendJson(400, { error: (err as Error).message });
|
|
1051
|
+
return;
|
|
1052
|
+
}
|
|
716
1053
|
orchestrator.saveSetup(selection);
|
|
717
1054
|
sendJson(200, await orchestrator.getSetupState());
|
|
718
1055
|
return;
|
|
@@ -749,6 +1086,25 @@ export function createServer(orchestrator: Orchestrator): Server {
|
|
|
749
1086
|
// (non-empty string array) picks the agent list baked by runner/setup.sh. Optional
|
|
750
1087
|
// config_dir / credentials_file name paths inside the data dir (validated by the
|
|
751
1088
|
// builder; credentials must be 0600, and an image built with them is a local secret, D-A).
|
|
1089
|
+
// «Reiniciar orquestador» (Ajustes): answer first, then the process stops like Ctrl+C
|
|
1090
|
+
// and starts again with the same argv and environment (RUNNER_IMAGE, --data-dir...).
|
|
1091
|
+
if (pathname === '/api/v1/system/restart' && method === 'POST') {
|
|
1092
|
+
const onRestart = hooks.onRestart;
|
|
1093
|
+
if (!onRestart) {
|
|
1094
|
+
sendJson(501, { error: 'this orchestrator process cannot restart itself' });
|
|
1095
|
+
return;
|
|
1096
|
+
}
|
|
1097
|
+
res.once('finish', () => setImmediate(onRestart));
|
|
1098
|
+
sendJson(202, { restarting: true });
|
|
1099
|
+
return;
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
// Progress of the image build in flight, or how the last one ended (Ajustes → Imagen).
|
|
1103
|
+
if (pathname === '/api/v1/system/rebuild' && method === 'GET') {
|
|
1104
|
+
sendJson(200, orchestrator.getRebuildStatus());
|
|
1105
|
+
return;
|
|
1106
|
+
}
|
|
1107
|
+
|
|
752
1108
|
if (pathname === '/api/v1/system/rebuild' && method === 'POST') {
|
|
753
1109
|
let body: Record<string, unknown> = {};
|
|
754
1110
|
// Optional JSON body; readJson resolves {} on an empty body, and this keeps
|
|
@@ -763,6 +1119,8 @@ export function createServer(orchestrator: Orchestrator): Server {
|
|
|
763
1119
|
agents?: string[];
|
|
764
1120
|
skip_az?: boolean;
|
|
765
1121
|
skip_gh?: boolean;
|
|
1122
|
+
tools?: string[];
|
|
1123
|
+
apt_extra?: string[];
|
|
766
1124
|
config_dir?: string;
|
|
767
1125
|
credentials_file?: string;
|
|
768
1126
|
} = {};
|
|
@@ -773,6 +1131,20 @@ export function createServer(orchestrator: Orchestrator): Server {
|
|
|
773
1131
|
}
|
|
774
1132
|
extras.agents = body.agents.map((a) => String(a));
|
|
775
1133
|
}
|
|
1134
|
+
if (body.tools !== undefined) {
|
|
1135
|
+
if (!Array.isArray(body.tools)) {
|
|
1136
|
+
sendJson(400, { error: "'tools' must be an array of tool group ids" });
|
|
1137
|
+
return;
|
|
1138
|
+
}
|
|
1139
|
+
extras.tools = body.tools.map((t) => String(t));
|
|
1140
|
+
}
|
|
1141
|
+
if (body.apt_extra !== undefined) {
|
|
1142
|
+
if (!Array.isArray(body.apt_extra)) {
|
|
1143
|
+
sendJson(400, { error: "'apt_extra' must be an array of Debian package names" });
|
|
1144
|
+
return;
|
|
1145
|
+
}
|
|
1146
|
+
extras.apt_extra = body.apt_extra.map((t) => String(t));
|
|
1147
|
+
}
|
|
776
1148
|
for (const key of ['skip_az', 'skip_gh'] as const) {
|
|
777
1149
|
const value = body[key];
|
|
778
1150
|
if (typeof value === 'boolean') extras[key] = value;
|
package/src/types.ts
CHANGED
|
@@ -35,7 +35,7 @@ export type FailureReason =
|
|
|
35
35
|
| 'invalid_issue_url'
|
|
36
36
|
| 'issue_inaccessible';
|
|
37
37
|
|
|
38
|
-
export const SUPPORTED_AGENTS = ['pi', 'claude', 'codex', '
|
|
38
|
+
export const SUPPORTED_AGENTS = ['pi', 'claude', 'codex', 'copilot', 'agy'] as const;
|
|
39
39
|
export type SupportedAgent = (typeof SUPPORTED_AGENTS)[number];
|
|
40
40
|
|
|
41
41
|
export function isValidAgent(agent: string): agent is SupportedAgent {
|
|
@@ -45,7 +45,7 @@ export function isValidAgent(agent: string): agent is SupportedAgent {
|
|
|
45
45
|
/**
|
|
46
46
|
* Wizard plan (D-W3, image plan D-B): the agents runner/setup.sh can bake into the image,
|
|
47
47
|
* which are the ones the setup wizard offers and `agents_selected` validates against.
|
|
48
|
-
*
|
|
48
|
+
* Since 2026-11-24 the same five as SUPPORTED_AGENTS (opencode and crush were dropped).
|
|
49
49
|
*/
|
|
50
50
|
export const SETUP_AGENTS = ['pi', 'claude', 'codex', 'copilot', 'agy'] as const;
|
|
51
51
|
export type SetupAgent = (typeof SETUP_AGENTS)[number];
|
|
@@ -97,6 +97,7 @@ export interface Ticket {
|
|
|
97
97
|
mode: TicketMode;
|
|
98
98
|
target_branch: string;
|
|
99
99
|
budget_usd: number;
|
|
100
|
+
/** Max minutes before the watchdog terminates the run; 0 (the default) = no timeout. */
|
|
100
101
|
timeout_minutes: number;
|
|
101
102
|
agent: string;
|
|
102
103
|
model?: string;
|
|
@@ -105,6 +106,8 @@ export interface Ticket {
|
|
|
105
106
|
verify_commands: string[];
|
|
106
107
|
/** P4 (D-U): auto-bondify the cloned repo if not already bondified; default true. */
|
|
107
108
|
bondify: boolean;
|
|
109
|
+
/** Plan bond-app-ajustes-imagen P4: Docker inside the run (privileged container); default false. */
|
|
110
|
+
docker?: boolean;
|
|
108
111
|
/** P9: engine for bond team inside run container: 'hc' (default, native panes) or 'herdr' (TUI mode). */
|
|
109
112
|
team_engine?: 'hc' | 'herdr';
|
|
110
113
|
status: RunState;
|
|
@@ -128,6 +131,7 @@ export interface CreateTicketInput {
|
|
|
128
131
|
repo_agents?: Record<string, string>;
|
|
129
132
|
target_branch?: string;
|
|
130
133
|
budget_usd?: number;
|
|
134
|
+
/** Timeout in minutes; 0 (the default) = no timeout, negative is rejected. */
|
|
131
135
|
timeout_minutes?: number;
|
|
132
136
|
agent?: string;
|
|
133
137
|
model?: string;
|
|
@@ -135,6 +139,8 @@ export interface CreateTicketInput {
|
|
|
135
139
|
verify_commands?: string[];
|
|
136
140
|
/** P4 (D-U): auto-bondify the cloned repo if not already bondified; default true. */
|
|
137
141
|
bondify?: boolean;
|
|
142
|
+
/** Plan bond-app-ajustes-imagen P4: Docker inside the run (privileged container); default false. */
|
|
143
|
+
docker?: boolean;
|
|
138
144
|
/** P9: engine for bond team inside run container: 'hc' (default) or 'herdr'. */
|
|
139
145
|
team_engine?: 'hc' | 'herdr';
|
|
140
146
|
}
|
|
@@ -172,6 +178,24 @@ export function parseGitHubIssueUrl(url: string): { owner: string; repo: string;
|
|
|
172
178
|
};
|
|
173
179
|
}
|
|
174
180
|
|
|
181
|
+
/** Plan bond-app-azure-jira P2: validate Jira issue URL: https://<site>.atlassian.net/browse/<KEY-123> */
|
|
182
|
+
export function validateJiraIssueUrl(url: string): boolean {
|
|
183
|
+
if (!url || typeof url !== 'string') return false;
|
|
184
|
+
const clean = url.trim().replace(/[#?].*$/, '');
|
|
185
|
+
return /^https:\/\/[a-zA-Z0-9_-]+\.atlassian\.net\/browse\/[a-zA-Z0-9_-]+$/.test(clean);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** Plan bond-app-azure-jira P2: parse Jira issue URL into site and issueKey. */
|
|
189
|
+
export function parseJiraIssueUrl(url: string): { site: string; issueKey: string } {
|
|
190
|
+
const clean = url.trim().replace(/[#?].*$/, '');
|
|
191
|
+
const m = /^https:\/\/([a-zA-Z0-9_-]+\.atlassian\.net)\/browse\/([a-zA-Z0-9_-]+)$/.exec(clean);
|
|
192
|
+
if (!m) throw new Error(`Not a Jira issue URL: '${url}'`);
|
|
193
|
+
return {
|
|
194
|
+
site: `https://${m[1]}`,
|
|
195
|
+
issueKey: m[2],
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
175
199
|
export interface Run {
|
|
176
200
|
id: string;
|
|
177
201
|
ticket_id: string;
|
|
@@ -310,6 +334,41 @@ export interface AgentCredentialSummary {
|
|
|
310
334
|
provider?: string;
|
|
311
335
|
configured: boolean;
|
|
312
336
|
updated_at?: string;
|
|
337
|
+
/** P1: account email for agy (read from id_token_email of antigravity-oauth-token; never the token). */
|
|
338
|
+
email?: string;
|
|
339
|
+
/** claude: when its `claude setup-token` token ends (one year after it was stored). */
|
|
340
|
+
expires_at?: string;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
export type AgyLoginStatus =
|
|
344
|
+
| 'idle'
|
|
345
|
+
| 'starting'
|
|
346
|
+
| 'waiting_code'
|
|
347
|
+
| 'authenticating'
|
|
348
|
+
| 'success'
|
|
349
|
+
| 'error';
|
|
350
|
+
|
|
351
|
+
export interface AgyLoginSessionState {
|
|
352
|
+
status: AgyLoginStatus;
|
|
353
|
+
url?: string;
|
|
354
|
+
/** Device flows (copilot): the code the person types at `url`; nothing to paste back. */
|
|
355
|
+
user_code?: string;
|
|
356
|
+
/** True when the login finishes by itself once authorized (no code to submit). */
|
|
357
|
+
device?: boolean;
|
|
358
|
+
/** The orchestrator catches the browser's return itself (codex); pasting is the fallback. */
|
|
359
|
+
auto?: boolean;
|
|
360
|
+
email?: string;
|
|
361
|
+
error?: string;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/** Plan bond-app-azure-jira P1: what the API says about the Azure DevOps PAT (never the PAT). */
|
|
365
|
+
export interface AzureDevOpsCredentialSummary {
|
|
366
|
+
configured: boolean;
|
|
367
|
+
org_url?: string;
|
|
368
|
+
account?: string;
|
|
369
|
+
/** The PAT also reaches the run's agents (AZURE_DEVOPS_* variables). */
|
|
370
|
+
agents_enabled?: boolean;
|
|
371
|
+
updated_at?: string;
|
|
313
372
|
}
|
|
314
373
|
|
|
315
374
|
/** D20: what the API says about the stored GitHub credential (never the token). */
|
|
@@ -324,6 +383,19 @@ export interface GitHubCredentialSummary {
|
|
|
324
383
|
export interface RunnerImageInfo {
|
|
325
384
|
present: boolean;
|
|
326
385
|
agents?: string[];
|
|
386
|
+
/** Plan bond-app-ajustes-imagen P2: tool groups and extra apt packages it was built with. */
|
|
387
|
+
tools?: string[];
|
|
388
|
+
apt_extra?: string[];
|
|
389
|
+
/** Filled by the setup state: what it lacks against the selection (⟳ in Ajustes). */
|
|
390
|
+
stale?: boolean;
|
|
391
|
+
missing_agents?: string[];
|
|
392
|
+
missing_tools?: string[];
|
|
393
|
+
extra_tools?: string[];
|
|
394
|
+
apt_changed?: boolean;
|
|
395
|
+
/** Fingerprint of the recipe it was built with (image label); absent on older images. */
|
|
396
|
+
recipe?: string;
|
|
397
|
+
/** The recipe (Dockerfile, setup.sh, versions.env…) changed since it was built. */
|
|
398
|
+
recipe_changed?: boolean;
|
|
327
399
|
}
|
|
328
400
|
|
|
329
401
|
/** W-P1: the aggregated setup state the wizard and the Ajustes panel read. */
|
|
@@ -341,6 +413,11 @@ export interface SetupState {
|
|
|
341
413
|
default_model: string | null;
|
|
342
414
|
/** P3: full model ids configured for pi (provider/id). */
|
|
343
415
|
models: string[];
|
|
416
|
+
/** Plan bond-app-ajustes-imagen P2: tool groups and extra apt packages chosen for the image. */
|
|
417
|
+
tools_selected: string[];
|
|
418
|
+
apt_extra: string[];
|
|
419
|
+
/** The tool groups the image can carry (id, label, description, default, size_mb). */
|
|
420
|
+
catalog: Array<{ id: string; label: string; description: string; default: boolean; size_mb: number }>;
|
|
344
421
|
}
|
|
345
422
|
|
|
346
423
|
/** gh / GitHub tokens: gho_…, ghp_…, github_pat_… — one word, no whitespace. */
|
|
@@ -353,6 +430,42 @@ export function validateGitHubLogin(login: unknown): login is string {
|
|
|
353
430
|
return typeof login === 'string' && /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,38})$/.test(login);
|
|
354
431
|
}
|
|
355
432
|
|
|
433
|
+
/** Plan bond-app-azure-jira P2: Jira Cloud credential. */
|
|
434
|
+
export interface JiraCredential {
|
|
435
|
+
site: string;
|
|
436
|
+
email: string;
|
|
437
|
+
token: string;
|
|
438
|
+
agents_enabled: boolean;
|
|
439
|
+
account_name?: string | null;
|
|
440
|
+
updated_at: string;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
export interface JiraCredentialSummary {
|
|
444
|
+
configured: boolean;
|
|
445
|
+
site?: string;
|
|
446
|
+
email?: string;
|
|
447
|
+
agents_enabled?: boolean;
|
|
448
|
+
account_name?: string | null;
|
|
449
|
+
updated_at?: string;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
export function validateJiraSite(site: unknown): site is string {
|
|
453
|
+
if (typeof site !== 'string') return false;
|
|
454
|
+
return /^https:\/\/[a-zA-Z0-9_-]+\.atlassian\.net\/?$/.test(site.trim());
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
export function normalizeJiraSite(site: string): string {
|
|
458
|
+
return site.trim().replace(/\/+$/, '');
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
export function validateJiraEmail(email: unknown): email is string {
|
|
462
|
+
return typeof email === 'string' && /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email.trim());
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
export function validateJiraToken(token: unknown): token is string {
|
|
466
|
+
return typeof token === 'string' && token.trim().length > 0;
|
|
467
|
+
}
|
|
468
|
+
|
|
356
469
|
/** P7: Row of `bond team status --json` inside the run's container. */
|
|
357
470
|
export interface TeamStatusRow {
|
|
358
471
|
branch: string;
|
|
@@ -376,3 +489,17 @@ export interface TeamStatusRow {
|
|
|
376
489
|
notice?: boolean;
|
|
377
490
|
};
|
|
378
491
|
}
|
|
492
|
+
|
|
493
|
+
/** P4: Live terminal of a run machine reported by hc. */
|
|
494
|
+
export interface RunTerminal {
|
|
495
|
+
address: string;
|
|
496
|
+
name: string;
|
|
497
|
+
agent: string;
|
|
498
|
+
state: string;
|
|
499
|
+
status: unknown;
|
|
500
|
+
turn: number;
|
|
501
|
+
where: string;
|
|
502
|
+
cwd: string;
|
|
503
|
+
labels?: Record<string, string>;
|
|
504
|
+
exit_code?: number | null;
|
|
505
|
+
}
|