@jmanuelcorral/bond-app 0.1.3 → 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.
Files changed (40) hide show
  1. package/README.md +41 -1
  2. package/app/mods/bond-agents/config.js +4 -0
  3. package/app/mods/bond-agents/main.js +10 -5
  4. package/app/mods/bond-agents/model.js +52 -4
  5. package/app/mods/bond-board/config.js +4 -0
  6. package/app/mods/bond-board/main.js +555 -84
  7. package/app/mods/bond-board/model.js +115 -2
  8. package/app/mods/bond-settings/config.js +4 -0
  9. package/app/mods/bond-settings/main.js +689 -12
  10. package/app/mods/bond-settings/pi-models.js +144 -0
  11. package/app/mods/bond-status/config.js +4 -0
  12. package/app/mods/bond-titlebar/main.js +63 -46
  13. package/package.json +1 -1
  14. package/runner/Dockerfile +42 -13
  15. package/runner/SPIKE-BOND.md +85 -0
  16. package/runner/build-config/.none +0 -0
  17. package/runner/build-creds/.none +0 -0
  18. package/runner/config.example/README.md +27 -0
  19. package/runner/config.example/pi/models.json +22 -0
  20. package/runner/credentials.example.env +27 -0
  21. package/runner/setup.sh +496 -0
  22. package/runner/versions.env +30 -0
  23. package/scripts/app-install.ts +38 -7
  24. package/src/config.ts +11 -0
  25. package/src/core/delivery.ts +61 -7
  26. package/src/core/hub-session.ts +154 -17
  27. package/src/core/hub.ts +55 -20
  28. package/src/core/orchestrator.ts +844 -200
  29. package/src/core/setup.ts +178 -0
  30. package/src/core/watchdog.ts +2 -2
  31. package/src/db/database.ts +14 -0
  32. package/src/db/run-repo.ts +8 -1
  33. package/src/db/settings-repo.ts +108 -0
  34. package/src/db/ticket-repo.ts +34 -4
  35. package/src/runner/docker-client.ts +42 -0
  36. package/src/runner/github-client.ts +126 -2
  37. package/src/runner/hc-client.ts +67 -9
  38. package/src/runner/image-builder.ts +146 -6
  39. package/src/server/app.ts +263 -36
  40. package/src/types.ts +40 -0
package/src/server/app.ts CHANGED
@@ -1,10 +1,22 @@
1
1
  import http, { IncomingMessage, ServerResponse, Server } from 'node:http';
2
2
  import { URL } from 'node:url';
3
3
  import crypto from 'node:crypto';
4
- import { Orchestrator, ValidationError, RebuildInProgressError, GitHubCredentialMissingError, UnmergedBranchError } from '../core/orchestrator.ts';
5
- import { InvalidVersionError, type RunnerVersions } from '../runner/image-builder.ts';
4
+ import {
5
+ Orchestrator,
6
+ ValidationError,
7
+ RebuildInProgressError,
8
+ GitHubCredentialMissingError,
9
+ UnmergedBranchError,
10
+ NotFoundError,
11
+ ConflictError,
12
+ JsonParseError,
13
+ PayloadTooLargeError,
14
+ } from '../core/orchestrator.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';
6
18
  import { InvalidStateTransitionError } from '../core/state-machine.ts';
7
- 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';
8
20
 
9
21
  export function createServer(orchestrator: Orchestrator): Server {
10
22
  return http.createServer(async (req: IncomingMessage, res: ServerResponse) => {
@@ -62,8 +74,8 @@ export function createServer(orchestrator: Orchestrator): Server {
62
74
  req.on('data', (chunk) => {
63
75
  bytes += chunk.length;
64
76
  if (bytes > maxBytes) {
65
- req.destroy();
66
- reject(new Error('Payload too large'));
77
+ req.pause();
78
+ reject(new PayloadTooLargeError('Payload too large'));
67
79
  return;
68
80
  }
69
81
  body += chunk.toString();
@@ -76,12 +88,12 @@ export function createServer(orchestrator: Orchestrator): Server {
76
88
  try {
77
89
  const parsed = JSON.parse(body);
78
90
  if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
79
- reject(new Error('JSON body must be an object'));
91
+ reject(new JsonParseError('JSON body must be an object'));
80
92
  return;
81
93
  }
82
94
  resolve(parsed);
83
95
  } catch {
84
- reject(new Error('Invalid JSON'));
96
+ reject(new JsonParseError('Invalid JSON'));
85
97
  }
86
98
  });
87
99
  req.on('error', reject);
@@ -142,6 +154,89 @@ export function createServer(orchestrator: Orchestrator): Server {
142
154
  }
143
155
  }
144
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
+
145
240
  const ticketPreviewMatch = pathname.match(/^\/api\/v1\/tickets\/([^/]+)\/delete_preview$/);
146
241
  if (ticketPreviewMatch && method === 'GET') {
147
242
  const ticketId = ticketPreviewMatch[1];
@@ -149,8 +244,11 @@ export function createServer(orchestrator: Orchestrator): Server {
149
244
  const preview = await orchestrator.getDeletePreview(ticketId);
150
245
  sendJson(200, preview);
151
246
  } catch (err: unknown) {
152
- const msg = (err as Error).message;
153
- sendJson(msg.includes('not found') ? 404 : 500, { error: msg });
247
+ if (err instanceof NotFoundError) {
248
+ sendJson(404, { error: (err as Error).message });
249
+ } else {
250
+ sendJson(500, { error: (err as Error).message });
251
+ }
154
252
  }
155
253
  return;
156
254
  }
@@ -174,8 +272,7 @@ export function createServer(orchestrator: Orchestrator): Server {
174
272
  const pinned = ['repo_url', 'target_branch', 'base_branch', 'repos', 'hub_url', 'hub_base', 'repo_agents'].filter((k) => body[k] !== undefined);
175
273
  const active = orchestrator.runRepo.listActive().find((r) => r.ticket_id === ticketId);
176
274
  if (pinned.length > 0 && active) {
177
- sendJson(409, { error: `Cannot change ${pinned.join(', ')} while run '${active.id}' is active` });
178
- return;
275
+ throw new ConflictError(`Cannot change ${pinned.join(', ')} while run '${active.id}' is active`);
179
276
  }
180
277
  try {
181
278
  const updated = orchestrator.ticketRepo.update(ticketId, body);
@@ -203,9 +300,10 @@ export function createServer(orchestrator: Orchestrator): Server {
203
300
  branch: err.branch,
204
301
  base: err.base,
205
302
  });
303
+ } else if (err instanceof NotFoundError) {
304
+ sendJson(404, { error: (err as Error).message });
206
305
  } else {
207
- const msg = (err as Error).message;
208
- sendJson(msg.includes('not found') ? 404 : 500, { error: msg });
306
+ sendJson(500, { error: (err as Error).message });
209
307
  }
210
308
  }
211
309
  return;
@@ -232,11 +330,12 @@ export function createServer(orchestrator: Orchestrator): Server {
232
330
  const run = orchestrator.createRun(ticketId);
233
331
  sendJson(201, run);
234
332
  } catch (err: unknown) {
235
- const msg = (err as Error).message;
236
- if (msg.includes('not found')) {
237
- sendJson(404, { error: msg });
333
+ if (err instanceof NotFoundError) {
334
+ sendJson(404, { error: (err as Error).message });
335
+ } else if (err instanceof ValidationError) {
336
+ sendJson(400, { error: (err as Error).message });
238
337
  } else {
239
- sendJson(400, { error: msg });
338
+ sendJson(500, { error: (err as Error).message });
240
339
  }
241
340
  }
242
341
  return;
@@ -263,12 +362,11 @@ export function createServer(orchestrator: Orchestrator): Server {
263
362
  sendJson(400, { error: message, code: err.code });
264
363
  } else if (
265
364
  err instanceof ValidationError ||
266
- message.includes('not found') ||
267
- message.includes('Missing') ||
268
- message.includes('Invalid') ||
269
- message.includes('already exists')
365
+ err instanceof InvalidStateTransitionError
270
366
  ) {
271
367
  sendJson(400, { error: message });
368
+ } else if (err instanceof NotFoundError) {
369
+ sendJson(404, { error: message });
272
370
  } else {
273
371
  // L1: Return 500 for infrastructure errors
274
372
  sendJson(500, { error: message });
@@ -413,6 +511,14 @@ export function createServer(orchestrator: Orchestrator): Server {
413
511
  sendJson(400, { error: "'state' is required" });
414
512
  return;
415
513
  }
514
+ // D1: /transition only allows cancel and transitions that do not skip verification or PR
515
+ const DISALLOWED_STATES = new Set<RunState>(['finished', 'pr_ready', 'verifying']);
516
+ if (DISALLOWED_STATES.has(newState)) {
517
+ sendJson(400, {
518
+ error: `Transition to '${newState}' is not allowed: /transition only allows cancel and transitions that do not skip verification or PR (D1)`,
519
+ });
520
+ return;
521
+ }
416
522
  const run = await orchestrator.transitionRun(runId, newState, reason);
417
523
  sendJson(200, run);
418
524
  return;
@@ -469,9 +575,10 @@ export function createServer(orchestrator: Orchestrator): Server {
469
575
  branch: err.branch,
470
576
  base: err.base,
471
577
  });
578
+ } else if (err instanceof NotFoundError) {
579
+ sendJson(404, { error: (err as Error).message });
472
580
  } else {
473
- const msg = (err as Error).message;
474
- sendJson(msg.includes('not found') ? 404 : 500, { error: msg });
581
+ sendJson(500, { error: (err as Error).message });
475
582
  }
476
583
  }
477
584
  return;
@@ -542,9 +649,106 @@ export function createServer(orchestrator: Orchestrator): Server {
542
649
  }
543
650
  }
544
651
 
545
- // P2 criterion 7 (D7): rebuild the runner image without touching credentials.
546
- // Optional body {bond?, hc?, hc_sha256?, herdr?, herdr_sha256?, pi?} pins new versions via --build-arg (review M4);
547
- // a new hc version needs its checksum (P2 debt N1).
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).
548
752
  if (pathname === '/api/v1/system/rebuild' && method === 'POST') {
549
753
  let body: Record<string, unknown> = {};
550
754
  // Optional JSON body; readJson resolves {} on an empty body, and this keeps
@@ -555,7 +759,29 @@ export function createServer(orchestrator: Orchestrator): Server {
555
759
  const value = body[key];
556
760
  if (value !== undefined) versions[key] = String(value);
557
761
  }
558
- const result = await orchestrator.rebuildRunnerImage(versions);
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);
559
785
  sendJson(200, result);
560
786
  return;
561
787
  }
@@ -563,12 +789,12 @@ export function createServer(orchestrator: Orchestrator): Server {
563
789
  // Not found
564
790
  sendJson(404, { error: 'Not found' });
565
791
  } catch (err: unknown) {
566
- if (err instanceof RebuildInProgressError) {
567
- sendJson(409, { error: err.message });
792
+ if (err instanceof RebuildInProgressError || err instanceof ConflictError) {
793
+ sendJson(409, { error: (err as Error).message });
568
794
  return;
569
795
  }
570
- if (err instanceof InvalidVersionError) {
571
- sendJson(400, { error: err.message });
796
+ if (err instanceof InvalidVersionError || err instanceof InvalidBuildOptionsError || err instanceof JsonParseError || err instanceof ValidationError) {
797
+ sendJson(400, { error: (err as Error).message });
572
798
  return;
573
799
  }
574
800
  if (err instanceof InvalidStateTransitionError) {
@@ -579,15 +805,16 @@ export function createServer(orchestrator: Orchestrator): Server {
579
805
  });
580
806
  return;
581
807
  }
582
- const e = err as Error;
583
- if (e.message === 'Invalid JSON' || e.message === 'JSON body must be an object') {
584
- sendJson(400, { error: e.message });
808
+ if (err instanceof PayloadTooLargeError) {
809
+ sendJson(413, { error: (err as Error).message });
810
+ req.destroy();
585
811
  return;
586
812
  }
587
- if (e.message === 'Payload too large') {
588
- sendJson(413, { error: e.message });
813
+ if (err instanceof NotFoundError) {
814
+ sendJson(404, { error: (err as Error).message });
589
815
  return;
590
816
  }
817
+ const e = err as Error;
591
818
  sendJson(500, { error: e.message || 'Internal server error' });
592
819
  }
593
820
  });
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);