@jmanuelcorral/bond-app 0.2.2 → 0.3.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/app/mods/bond-agents/main.js +446 -28
- package/app/mods/bond-agents/model.js +236 -0
- package/app/mods/bond-board/main.js +170 -16
- package/app/mods/bond-board/model.js +63 -2
- package/app/mods/bond-settings/main.js +128 -2
- package/package.json +1 -1
- package/runner/versions.env +1 -1
- package/src/config.ts +3 -0
- package/src/core/agent-flags.ts +38 -0
- package/src/core/agent-waiting.ts +38 -0
- package/src/core/agy-login.ts +56 -4
- package/src/core/doctor.ts +58 -12
- package/src/core/handoff.ts +161 -0
- package/src/core/hub-session.ts +14 -2
- package/src/core/hub.ts +3 -3
- package/src/core/loop.ts +241 -0
- package/src/core/orchestrator.ts +961 -181
- package/src/core/pi-compaction.ts +98 -0
- package/src/core/stuck.ts +192 -0
- package/src/db/database.ts +31 -1
- package/src/db/run-repo.ts +38 -3
- package/src/db/settings-repo.ts +138 -0
- package/src/db/ticket-repo.ts +74 -5
- package/src/runner/hc-client.ts +27 -4
- package/src/server/app.ts +175 -3
- package/src/types.ts +74 -0
package/src/db/ticket-repo.ts
CHANGED
|
@@ -9,6 +9,9 @@ import {
|
|
|
9
9
|
SUPPORTED_AGENTS,
|
|
10
10
|
validateBranchName,
|
|
11
11
|
validateVerifyCommands,
|
|
12
|
+
LOOP_DEFAULT_MAX_ITERATIONS,
|
|
13
|
+
LOOP_MAX_ITERATIONS_LIMIT,
|
|
14
|
+
type TicketLoop,
|
|
12
15
|
type Ticket,
|
|
13
16
|
type CreateTicketInput,
|
|
14
17
|
type RunState,
|
|
@@ -250,6 +253,8 @@ export class TicketRepository {
|
|
|
250
253
|
if (input.docker !== undefined && typeof input.docker !== 'boolean') {
|
|
251
254
|
throw new Error("Field 'docker' must be a boolean");
|
|
252
255
|
}
|
|
256
|
+
validateAzureFields(input);
|
|
257
|
+
const loop = this.normalizeLoop(input.loop, Boolean(layout.hub_url) || (layout.repos?.length ?? 0) >= 2);
|
|
253
258
|
if (layoutBases(layout).includes(targetBranch)) {
|
|
254
259
|
throw new Error('target_branch must differ from base_branch: a run only pushes its own branch (P4)');
|
|
255
260
|
}
|
|
@@ -260,8 +265,9 @@ export class TicketRepository {
|
|
|
260
265
|
INSERT INTO tickets (
|
|
261
266
|
id, title, description, repo_url, base_branch, target_branch,
|
|
262
267
|
budget_usd, timeout_minutes, agent, model, prompt, verify_commands,
|
|
263
|
-
hub_url, hub_base, repos, repo_agents, issue_url, story, source_pr_url, team_engine, bondify, docker,
|
|
264
|
-
|
|
268
|
+
hub_url, hub_base, repos, repo_agents, issue_url, story, source_pr_url, team_engine, bondify, docker,
|
|
269
|
+
azure_login, azure_subscription, loop_enabled, loop_max_iterations, status, created_at, updated_at
|
|
270
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
265
271
|
`);
|
|
266
272
|
|
|
267
273
|
const teamEngine = input.team_engine === 'herdr' ? 'herdr' : 'hc';
|
|
@@ -289,6 +295,10 @@ export class TicketRepository {
|
|
|
289
295
|
teamEngine,
|
|
290
296
|
bondify ? 1 : 0,
|
|
291
297
|
input.docker === true ? 1 : 0,
|
|
298
|
+
input.azure_login === true ? 1 : 0,
|
|
299
|
+
input.azure_login === true && input.azure_subscription ? input.azure_subscription : null,
|
|
300
|
+
loop.enabled ? 1 : 0,
|
|
301
|
+
loop.max_iterations,
|
|
292
302
|
status,
|
|
293
303
|
now,
|
|
294
304
|
now
|
|
@@ -297,6 +307,37 @@ export class TicketRepository {
|
|
|
297
307
|
return this.get(id)!;
|
|
298
308
|
}
|
|
299
309
|
|
|
310
|
+
/**
|
|
311
|
+
* LOOP P1: `{ enabled, max_iterations? }` → TicketLoop. Without max_iterations, the current
|
|
312
|
+
* one (an update) or Ajustes' default; null = no limit. Enabled only on hub tickets (v1, D7).
|
|
313
|
+
*/
|
|
314
|
+
private normalizeLoop(raw: unknown, isHub: boolean, current?: TicketLoop): TicketLoop {
|
|
315
|
+
if (raw === undefined || raw === null) return current ?? { enabled: false, max_iterations: this.loopDefaultMax() };
|
|
316
|
+
if (typeof raw !== 'object' || Array.isArray(raw)) throw new Error("Field 'loop' must be an object { enabled, max_iterations? }");
|
|
317
|
+
const r = raw as { enabled?: unknown; max_iterations?: unknown };
|
|
318
|
+
if (r.enabled !== undefined && typeof r.enabled !== 'boolean') throw new Error("Field 'loop.enabled' must be a boolean");
|
|
319
|
+
const enabled = r.enabled === true;
|
|
320
|
+
if (enabled && !isHub) throw new Error('El modo loop solo está disponible en tickets de hub');
|
|
321
|
+
let max: number | null;
|
|
322
|
+
if (r.max_iterations === undefined) max = current ? current.max_iterations : this.loopDefaultMax();
|
|
323
|
+
else if (r.max_iterations === null) max = null;
|
|
324
|
+
else if (typeof r.max_iterations === 'number' && Number.isInteger(r.max_iterations) && r.max_iterations >= 1 && r.max_iterations <= LOOP_MAX_ITERATIONS_LIMIT) max = r.max_iterations;
|
|
325
|
+
else throw new Error(`Field 'loop.max_iterations' must be an integer from 1 to ${LOOP_MAX_ITERATIONS_LIMIT}, or null for no limit`);
|
|
326
|
+
return { enabled, max_iterations: max };
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/** Ajustes' default iterations for a new loop (app_settings), or the built-in one. */
|
|
330
|
+
private loopDefaultMax(): number {
|
|
331
|
+
try {
|
|
332
|
+
const row = this.db.prepare("SELECT value FROM app_settings WHERE key = 'loop_default_max_iterations'").get() as { value?: string } | undefined;
|
|
333
|
+
const v = Number(row?.value);
|
|
334
|
+
if (Number.isInteger(v) && v >= 1 && v <= LOOP_MAX_ITERATIONS_LIMIT) return v;
|
|
335
|
+
} catch {
|
|
336
|
+
/* no settings table yet */
|
|
337
|
+
}
|
|
338
|
+
return LOOP_DEFAULT_MAX_ITERATIONS;
|
|
339
|
+
}
|
|
340
|
+
|
|
300
341
|
get(id: string): Ticket | null {
|
|
301
342
|
const stmt = this.db.prepare('SELECT * FROM tickets WHERE id = ?');
|
|
302
343
|
const row = stmt.get(id) as unknown as Record<string, unknown> | undefined;
|
|
@@ -316,7 +357,7 @@ export class TicketRepository {
|
|
|
316
357
|
stmt.run(status, now, id);
|
|
317
358
|
}
|
|
318
359
|
|
|
319
|
-
update(id: string, updates: Partial<Ticket
|
|
360
|
+
update(id: string, updates: Partial<Omit<Ticket, 'loop'>> & Partial<LayoutInput> & { loop?: CreateTicketInput['loop'] | TicketLoop }): Ticket | null {
|
|
320
361
|
const existing = this.get(id);
|
|
321
362
|
if (!existing) return null;
|
|
322
363
|
|
|
@@ -397,16 +438,23 @@ export class TicketRepository {
|
|
|
397
438
|
if (updates.docker !== undefined && typeof updates.docker !== 'boolean') {
|
|
398
439
|
throw new Error("Field 'docker' must be a boolean");
|
|
399
440
|
}
|
|
441
|
+
validateAzureFields(updates);
|
|
442
|
+
const isHub = Boolean(layout.hub_url) || (layout.repos?.length ?? 0) >= 2;
|
|
443
|
+
// A ticket that stops being a hub loses its loop (v1: hub only); otherwise it keeps it.
|
|
444
|
+
const loop = updates.loop !== undefined
|
|
445
|
+
? this.normalizeLoop(updates.loop, isHub, existing.loop)
|
|
446
|
+
: isHub ? (existing.loop ?? { enabled: false, max_iterations: LOOP_DEFAULT_MAX_ITERATIONS }) : { enabled: false, max_iterations: existing.loop?.max_iterations ?? null };
|
|
400
447
|
|
|
401
448
|
// Preserve status: status is managed via run lifecycle, not arbitrary ticket patch
|
|
402
|
-
const merged = { ...existing, ...updates, status: existing.status, updated_at: new Date().toISOString() };
|
|
449
|
+
const merged = { ...existing, ...updates, loop, status: existing.status, updated_at: new Date().toISOString() };
|
|
403
450
|
this.assertTeamAgents(layout, merged.agent, repoAgents);
|
|
404
451
|
const stmt = this.db.prepare(`
|
|
405
452
|
UPDATE tickets SET
|
|
406
453
|
title = ?, description = ?, repo_url = ?, base_branch = ?, target_branch = ?,
|
|
407
454
|
budget_usd = ?, timeout_minutes = ?, agent = ?, model = ?, prompt = ?,
|
|
408
455
|
verify_commands = ?, hub_url = ?, hub_base = ?, repos = ?, repo_agents = ?,
|
|
409
|
-
issue_url = ?, story = ?, team_engine = ?, bondify = ?, docker = ?,
|
|
456
|
+
issue_url = ?, story = ?, team_engine = ?, bondify = ?, docker = ?, azure_login = ?, azure_subscription = ?,
|
|
457
|
+
loop_enabled = ?, loop_max_iterations = ?, status = ?, updated_at = ?
|
|
410
458
|
WHERE id = ?
|
|
411
459
|
`);
|
|
412
460
|
|
|
@@ -431,6 +479,10 @@ export class TicketRepository {
|
|
|
431
479
|
merged.team_engine === 'herdr' ? 'herdr' : 'hc',
|
|
432
480
|
merged.bondify ? 1 : 0,
|
|
433
481
|
merged.docker ? 1 : 0,
|
|
482
|
+
merged.azure_login ? 1 : 0,
|
|
483
|
+
merged.azure_login && merged.azure_subscription ? merged.azure_subscription : null,
|
|
484
|
+
loop.enabled ? 1 : 0,
|
|
485
|
+
loop.max_iterations,
|
|
434
486
|
merged.status,
|
|
435
487
|
merged.updated_at,
|
|
436
488
|
id
|
|
@@ -476,6 +528,12 @@ export class TicketRepository {
|
|
|
476
528
|
team_engine: (row.team_engine === 'hc' ? 'hc' : 'herdr') as 'hc' | 'herdr',
|
|
477
529
|
bondify: row.bondify !== null && row.bondify !== undefined ? Number(row.bondify) !== 0 : true,
|
|
478
530
|
docker: Number(row.docker ?? 0) !== 0,
|
|
531
|
+
azure_login: Number(row.azure_login ?? 0) !== 0,
|
|
532
|
+
azure_subscription: row.azure_subscription ? String(row.azure_subscription) : null,
|
|
533
|
+
loop: {
|
|
534
|
+
enabled: Number(row.loop_enabled ?? 0) !== 0,
|
|
535
|
+
max_iterations: row.loop_max_iterations === null || row.loop_max_iterations === undefined ? null : Number(row.loop_max_iterations),
|
|
536
|
+
},
|
|
479
537
|
status: row.status as RunState,
|
|
480
538
|
created_at: String(row.created_at),
|
|
481
539
|
updated_at: String(row.updated_at),
|
|
@@ -512,3 +570,14 @@ function parseRepoAgents(raw: unknown): Record<string, string> {
|
|
|
512
570
|
return {};
|
|
513
571
|
}
|
|
514
572
|
}
|
|
573
|
+
|
|
574
|
+
/** Issue #4 (P2): «Login de Azure» is a boolean; its subscription a GUID or null. */
|
|
575
|
+
function validateAzureFields(input: { azure_login?: unknown; azure_subscription?: unknown }): void {
|
|
576
|
+
if (input.azure_login !== undefined && typeof input.azure_login !== 'boolean') {
|
|
577
|
+
throw new Error("Field 'azure_login' must be a boolean");
|
|
578
|
+
}
|
|
579
|
+
const sub = input.azure_subscription;
|
|
580
|
+
if (sub !== undefined && sub !== null && sub !== '' && !(typeof sub === 'string' && /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test(sub))) {
|
|
581
|
+
throw new Error("Field 'azure_subscription' must be a subscription id (GUID) or null");
|
|
582
|
+
}
|
|
583
|
+
}
|
package/src/runner/hc-client.ts
CHANGED
|
@@ -82,6 +82,8 @@ export interface HcTerminalDetails {
|
|
|
82
82
|
turn?: number;
|
|
83
83
|
labels?: Record<string, string>;
|
|
84
84
|
agent?: string;
|
|
85
|
+
/** `hc get`: the command the terminal runs (issue #3 tells the agent kind from it). */
|
|
86
|
+
argv?: string[];
|
|
85
87
|
}
|
|
86
88
|
|
|
87
89
|
export class HcClient {
|
|
@@ -179,6 +181,24 @@ export class HcClient {
|
|
|
179
181
|
return res.address;
|
|
180
182
|
}
|
|
181
183
|
|
|
184
|
+
/**
|
|
185
|
+
* Issue #3: end a terminal's program (`hc kill`: hangup, then escalate) and remove it
|
|
186
|
+
* (`hc rm`), so its name is free for the agent that replaces it. Already finished or gone is
|
|
187
|
+
* fine; the session files stay in the container.
|
|
188
|
+
*/
|
|
189
|
+
async killTerminal(address: string): Promise<void> {
|
|
190
|
+
try {
|
|
191
|
+
await this.call(['kill', address, '--json']);
|
|
192
|
+
} catch {
|
|
193
|
+
/* already finished */
|
|
194
|
+
}
|
|
195
|
+
try {
|
|
196
|
+
await this.call(['rm', address, '--json']);
|
|
197
|
+
} catch {
|
|
198
|
+
/* already removed */
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
182
202
|
/** Set labels on a terminal (`hc label <address> <key>=<value>`). */
|
|
183
203
|
async labelTerminal(address: string, labels: Record<string, string>): Promise<void> {
|
|
184
204
|
const args = Object.entries(labels).map(([k, v]) => `${k}=${v}`);
|
|
@@ -201,6 +221,7 @@ export class HcClient {
|
|
|
201
221
|
cwd?: string;
|
|
202
222
|
labels?: Record<string, string>;
|
|
203
223
|
foreground?: { name?: string };
|
|
224
|
+
argv?: unknown;
|
|
204
225
|
};
|
|
205
226
|
const rawAgent = (res as any).agent || res.name || res.foreground?.name;
|
|
206
227
|
const isGeneric = rawAgent === 'agent' || rawAgent === 'gru' || (typeof rawAgent === 'string' && /^t\d+$/.test(rawAgent));
|
|
@@ -215,13 +236,14 @@ export class HcClient {
|
|
|
215
236
|
turn: typeof res.turn === 'number' ? res.turn : 0,
|
|
216
237
|
labels: res.labels ?? {},
|
|
217
238
|
agent,
|
|
239
|
+
argv: Array.isArray(res.argv) ? res.argv.map(String) : undefined,
|
|
218
240
|
};
|
|
219
241
|
}
|
|
220
242
|
|
|
221
243
|
/**
|
|
222
244
|
* P9: List live terminals across machines, or only terminals on a specific machine.
|
|
223
245
|
*/
|
|
224
|
-
async listTerminals(machine?: string): Promise<Array<{
|
|
246
|
+
async listTerminals(machine?: string, opts: { all?: boolean } = {}): Promise<Array<{
|
|
225
247
|
address: string;
|
|
226
248
|
name?: string;
|
|
227
249
|
cwd?: string;
|
|
@@ -232,7 +254,8 @@ export class HcClient {
|
|
|
232
254
|
labels?: Record<string, string>;
|
|
233
255
|
agent?: string;
|
|
234
256
|
}>> {
|
|
235
|
-
|
|
257
|
+
// --all: finished terminals too (issue #3 relaunches an agent whose program has ended).
|
|
258
|
+
const res = (await this.call(['ls', '--json', ...(opts.all ? ['--all'] : [])])) as {
|
|
236
259
|
terminals?: Array<{
|
|
237
260
|
address: string;
|
|
238
261
|
name?: string;
|
|
@@ -268,8 +291,8 @@ export class HcClient {
|
|
|
268
291
|
* P1 criterion 3: obtains state from `hc ls --json` without N+1 `hc get` per terminal,
|
|
269
292
|
* falling back to `getTerminal` only if the data is missing from ls.
|
|
270
293
|
*/
|
|
271
|
-
async getMachineTerminals(machine: string): Promise<HcTerminalDetails[]> {
|
|
272
|
-
const listed = await this.listTerminals(machine);
|
|
294
|
+
async getMachineTerminals(machine: string, opts: { all?: boolean } = {}): Promise<HcTerminalDetails[]> {
|
|
295
|
+
const listed = await this.listTerminals(machine, opts);
|
|
273
296
|
const details = await Promise.all(
|
|
274
297
|
listed.map(async (t) => {
|
|
275
298
|
const hasStatus = t.status !== undefined;
|
package/src/server/app.ts
CHANGED
|
@@ -461,7 +461,7 @@ export function createServer(orchestrator: Orchestrator, hooks: ServerHooks = {}
|
|
|
461
461
|
const body = await readJson();
|
|
462
462
|
// P4 review M1: the delivery pushes to the ticket's repo and branch; they cannot
|
|
463
463
|
// change under a run that cloned the old ones.
|
|
464
|
-
const pinned = ['repo_url', 'target_branch', 'base_branch', 'repos', 'hub_url', 'hub_base', 'repo_agents'].filter((k) => body[k] !== undefined);
|
|
464
|
+
const pinned = ['repo_url', 'target_branch', 'base_branch', 'repos', 'hub_url', 'hub_base', 'repo_agents', 'loop'].filter((k) => body[k] !== undefined);
|
|
465
465
|
const active = orchestrator.runRepo.listActive().find((r) => r.ticket_id === ticketId);
|
|
466
466
|
if (pinned.length > 0 && active) {
|
|
467
467
|
throw new ConflictError(`Cannot change ${pinned.join(', ')} while run '${active.id}' is active`);
|
|
@@ -604,6 +604,26 @@ export function createServer(orchestrator: Orchestrator, hooks: ServerHooks = {}
|
|
|
604
604
|
return;
|
|
605
605
|
}
|
|
606
606
|
|
|
607
|
+
// «Seguir sin ellos»: start the hub team despite the hub agent's gaps.
|
|
608
|
+
const runProceedMatch = pathname.match(/^\/api\/v1\/runs\/([^/]+)\/hub\/proceed$/);
|
|
609
|
+
if (runProceedMatch && method === 'POST') {
|
|
610
|
+
const runId = runProceedMatch[1];
|
|
611
|
+
if (!orchestrator.runRepo.get(runId)) {
|
|
612
|
+
sendJson(404, { error: `Run '${runId}' not found` });
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
try {
|
|
616
|
+
sendJson(200, await orchestrator.proceedHub(runId));
|
|
617
|
+
} catch (err: unknown) {
|
|
618
|
+
if (err instanceof ValidationError) {
|
|
619
|
+
sendJson(400, { error: (err as Error).message });
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
622
|
+
throw err;
|
|
623
|
+
}
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
626
|
+
|
|
607
627
|
// P5 «Aprobar arreglos»: apply the fixes of the hub analysis and analyse again.
|
|
608
628
|
const runApproveMatch = pathname.match(/^\/api\/v1\/runs\/([^/]+)\/hub\/approve$/);
|
|
609
629
|
if (runApproveMatch && method === 'POST') {
|
|
@@ -646,6 +666,113 @@ export function createServer(orchestrator: Orchestrator, hooks: ServerHooks = {}
|
|
|
646
666
|
return;
|
|
647
667
|
}
|
|
648
668
|
|
|
669
|
+
// LOOP P3 (issue #2): «Iniciar loop» and the person's pause, resume and stop.
|
|
670
|
+
// «Iniciar loop» dialog: the plans gru can carry out (docs/plans/ of the hub).
|
|
671
|
+
const loopPlansMatch = pathname.match(/^\/api\/v1\/runs\/([^/]+)\/loop\/plans$/);
|
|
672
|
+
if (loopPlansMatch && method === 'GET') {
|
|
673
|
+
try {
|
|
674
|
+
sendJson(200, { plans: await orchestrator.listLoopPlans(loopPlansMatch[1]) });
|
|
675
|
+
} catch (err: unknown) {
|
|
676
|
+
if (err instanceof NotFoundError) {
|
|
677
|
+
sendJson(404, { error: (err as Error).message });
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
680
|
+
throw err;
|
|
681
|
+
}
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
const loopMatch = pathname.match(/^\/api\/v1\/runs\/([^/]+)\/loop\/(start|pause|resume|stop|message)$/);
|
|
686
|
+
if (loopMatch && method === 'POST') {
|
|
687
|
+
const [, runId, action] = loopMatch;
|
|
688
|
+
const body = action === 'start' || action === 'message' ? await readJson(16 * 1024) : {};
|
|
689
|
+
try {
|
|
690
|
+
const run = action === 'start' ? await orchestrator.startLoop(runId, { plan: body.plan, instructions: body.instructions, max_iterations: body.max_iterations })
|
|
691
|
+
: action === 'message' ? await orchestrator.messageLoop(runId, body.text)
|
|
692
|
+
: action === 'pause' ? await orchestrator.pauseLoop(runId)
|
|
693
|
+
: action === 'resume' ? await orchestrator.resumeLoop(runId)
|
|
694
|
+
: await orchestrator.stopLoop(runId);
|
|
695
|
+
sendJson(200, run);
|
|
696
|
+
} catch (err: unknown) {
|
|
697
|
+
if (err instanceof NotFoundError) {
|
|
698
|
+
sendJson(404, { error: (err as Error).message });
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
701
|
+
if (err instanceof ValidationError) {
|
|
702
|
+
sendJson(400, { error: (err as Error).message });
|
|
703
|
+
return;
|
|
704
|
+
}
|
|
705
|
+
throw err;
|
|
706
|
+
}
|
|
707
|
+
return;
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
// Issue #3 P4: «Reanudar al restablecerse»: the same agent goes on when its budget is back.
|
|
711
|
+
const resumeMatch = pathname.match(/^\/api\/v1\/runs\/([^/]+)\/agents\/([^/]+)\/resume$/);
|
|
712
|
+
if (resumeMatch && method === 'POST') {
|
|
713
|
+
const body = await readJson(4 * 1024);
|
|
714
|
+
try {
|
|
715
|
+
sendJson(200, await orchestrator.scheduleResume(resumeMatch[1], decodeURIComponent(resumeMatch[2]), body.at));
|
|
716
|
+
} catch (err: unknown) {
|
|
717
|
+
if (err instanceof NotFoundError) {
|
|
718
|
+
sendJson(404, { error: (err as Error).message });
|
|
719
|
+
return;
|
|
720
|
+
}
|
|
721
|
+
if (err instanceof ValidationError) {
|
|
722
|
+
sendJson(400, { error: (err as Error).message });
|
|
723
|
+
return;
|
|
724
|
+
}
|
|
725
|
+
throw err;
|
|
726
|
+
}
|
|
727
|
+
return;
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
// Issue #3: the run's agents that ended and were not replaced (the panel's «Cerrados»).
|
|
731
|
+
const closedMatch = pathname.match(/^\/api\/v1\/runs\/([^/]+)\/closed-agents$/);
|
|
732
|
+
if (closedMatch && method === 'GET') {
|
|
733
|
+
try {
|
|
734
|
+
sendJson(200, await orchestrator.getClosedAgents(closedMatch[1]));
|
|
735
|
+
} catch (err: unknown) {
|
|
736
|
+
if (err instanceof NotFoundError) {
|
|
737
|
+
sendJson(404, { error: (err as Error).message });
|
|
738
|
+
return;
|
|
739
|
+
}
|
|
740
|
+
throw err;
|
|
741
|
+
}
|
|
742
|
+
return;
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
// Issue #3 «Relanzar con resumen»: GET the options and the handoff preview for one agent of
|
|
746
|
+
// the run; POST relaunches it (same kind or another) from that handoff.
|
|
747
|
+
const relaunchMatch = pathname.match(/^\/api\/v1\/runs\/([^/]+)\/agents\/([^/]+)\/relaunch$/);
|
|
748
|
+
if (relaunchMatch && (method === 'GET' || method === 'POST')) {
|
|
749
|
+
const runId = relaunchMatch[1];
|
|
750
|
+
const name = decodeURIComponent(relaunchMatch[2]);
|
|
751
|
+
try {
|
|
752
|
+
if (method === 'GET') {
|
|
753
|
+
const options = await orchestrator.relaunchOptions(runId, name);
|
|
754
|
+
const to = parsedUrl.searchParams.get('agent') || options.from;
|
|
755
|
+
const reason = parsedUrl.searchParams.get('reason') || 'relanzado a mano';
|
|
756
|
+
const handoff = await orchestrator.relaunchHandoff(runId, name, to, reason.slice(0, 200));
|
|
757
|
+
sendJson(200, { ...options, handoff });
|
|
758
|
+
} else {
|
|
759
|
+
const body = await readJson(128 * 1024);
|
|
760
|
+
sendJson(200, await orchestrator.relaunchAgent(runId, name, body));
|
|
761
|
+
}
|
|
762
|
+
} catch (err: unknown) {
|
|
763
|
+
if (err instanceof NotFoundError) {
|
|
764
|
+
sendJson(404, { error: (err as Error).message });
|
|
765
|
+
return;
|
|
766
|
+
}
|
|
767
|
+
if (err instanceof ValidationError) {
|
|
768
|
+
sendJson(400, { error: (err as Error).message });
|
|
769
|
+
return;
|
|
770
|
+
}
|
|
771
|
+
throw err;
|
|
772
|
+
}
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
|
|
649
776
|
// P7: «Terminado»: mark a running or waiting run as finished keeping container and session alive.
|
|
650
777
|
const runFinishMatch = pathname.match(/^\/api\/v1\/runs\/([^/]+)\/finish$/);
|
|
651
778
|
if (runFinishMatch && method === 'POST') {
|
|
@@ -846,14 +973,15 @@ export function createServer(orchestrator: Orchestrator, hooks: ServerHooks = {}
|
|
|
846
973
|
// bond-app-claude-agente P2), codex (ChatGPT, browser callback replayed in the
|
|
847
974
|
// container) and copilot (device code), plan bond-app-codex-copilot P2. The API never
|
|
848
975
|
// returns a token, only the session state.
|
|
849
|
-
const loginMatch = pathname.match(/^\/api\/v1\/settings\/(agy|claude|codex|copilot)\/login(\/.*)?$/);
|
|
976
|
+
const loginMatch = pathname.match(/^\/api\/v1\/settings\/(agy|claude|codex|copilot|azure)\/login(\/.*)?$/);
|
|
850
977
|
if (loginMatch) {
|
|
851
978
|
const loginManager = {
|
|
852
979
|
agy: orchestrator.agyLoginManager,
|
|
853
980
|
claude: orchestrator.claudeLoginManager,
|
|
854
981
|
codex: orchestrator.codexLoginManager,
|
|
855
982
|
copilot: orchestrator.copilotLoginManager,
|
|
856
|
-
|
|
983
|
+
azure: orchestrator.azureLoginManager,
|
|
984
|
+
}[loginMatch[1] as 'agy' | 'claude' | 'codex' | 'copilot' | 'azure'];
|
|
857
985
|
const sub = loginMatch[2] ?? '';
|
|
858
986
|
if (sub === '' || sub === '/status') {
|
|
859
987
|
if (method === 'GET') {
|
|
@@ -902,6 +1030,33 @@ export function createServer(orchestrator: Orchestrator, hooks: ServerHooks = {}
|
|
|
902
1030
|
}
|
|
903
1031
|
}
|
|
904
1032
|
|
|
1033
|
+
// Issue #4 (P1): the Azure session (who, tenant, subscriptions; never a token), the
|
|
1034
|
+
// default subscription, and «Cerrar sesión de Azure».
|
|
1035
|
+
if (pathname === '/api/v1/settings/azure-login') {
|
|
1036
|
+
if (method === 'GET') {
|
|
1037
|
+
sendJson(200, orchestrator.settingsRepo.getAzureLoginSummary());
|
|
1038
|
+
return;
|
|
1039
|
+
}
|
|
1040
|
+
if (method === 'PUT') {
|
|
1041
|
+
const body = await readJson();
|
|
1042
|
+
if (typeof body.subscription_id !== 'string' || !/^[0-9a-fA-F-]{36}$/.test(body.subscription_id)) {
|
|
1043
|
+
sendJson(400, { error: "'subscription_id' must be a subscription id (GUID)" });
|
|
1044
|
+
return;
|
|
1045
|
+
}
|
|
1046
|
+
try {
|
|
1047
|
+
sendJson(200, orchestrator.settingsRepo.setAzureSubscription(body.subscription_id));
|
|
1048
|
+
} catch (err: unknown) {
|
|
1049
|
+
sendJson(400, { error: (err as Error).message });
|
|
1050
|
+
}
|
|
1051
|
+
return;
|
|
1052
|
+
}
|
|
1053
|
+
if (method === 'DELETE') {
|
|
1054
|
+
orchestrator.settingsRepo.deleteAzureLogin();
|
|
1055
|
+
sendJson(200, orchestrator.settingsRepo.getAzureLoginSummary());
|
|
1056
|
+
return;
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
|
|
905
1060
|
// D20: the GitHub credential for the runs' clones (the user's gh session). The API
|
|
906
1061
|
// only ever says whether one is stored and for which login; never the token.
|
|
907
1062
|
if (pathname === '/api/v1/settings/github') {
|
|
@@ -1066,6 +1221,23 @@ export function createServer(orchestrator: Orchestrator, hooks: ServerHooks = {}
|
|
|
1066
1221
|
// W-P1 (wizard): aggregated setup state. GET says what is missing; PUT stores the
|
|
1067
1222
|
// agent selection and setup_done (only via an explicit write). No credentials here:
|
|
1068
1223
|
// the aggregate only says whether each piece is configured (D13 summaries).
|
|
1224
|
+
// LOOP P1 (issue #2): the loop defaults of Ajustes (a new ticket's iterations; stall rounds).
|
|
1225
|
+
if (pathname === '/api/v1/settings/loop') {
|
|
1226
|
+
if (method === 'GET') {
|
|
1227
|
+
sendJson(200, orchestrator.settingsRepo.getLoopDefaults());
|
|
1228
|
+
return;
|
|
1229
|
+
}
|
|
1230
|
+
if (method === 'PUT') {
|
|
1231
|
+
const body = await readJson(4 * 1024);
|
|
1232
|
+
try {
|
|
1233
|
+
sendJson(200, orchestrator.settingsRepo.saveLoopDefaults(body));
|
|
1234
|
+
} catch (err: unknown) {
|
|
1235
|
+
sendJson(400, { error: (err as Error).message });
|
|
1236
|
+
}
|
|
1237
|
+
return;
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
|
|
1069
1241
|
if (pathname === '/api/v1/setup') {
|
|
1070
1242
|
if (method === 'GET') {
|
|
1071
1243
|
sendJson(200, await orchestrator.getSetupState());
|
package/src/types.ts
CHANGED
|
@@ -76,6 +76,21 @@ export interface TicketRepo {
|
|
|
76
76
|
*/
|
|
77
77
|
export type TicketMode = 'single' | 'hub';
|
|
78
78
|
|
|
79
|
+
/**
|
|
80
|
+
* LOOP P1 (issue #2): the ticket's autonomous mode. When enabled, gru supervises the team and
|
|
81
|
+
* the plan runs on its own (the engine is P3). `max_iterations`: gru's review rounds before the
|
|
82
|
+
* loop stops; null = no limit (the ticket's timeout and the stall check still stop it).
|
|
83
|
+
*/
|
|
84
|
+
export interface TicketLoop {
|
|
85
|
+
enabled: boolean;
|
|
86
|
+
max_iterations: number | null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** LOOP defaults (Ajustes): iterations of a new ticket's loop, and rounds without progress = stall. */
|
|
90
|
+
export const LOOP_DEFAULT_MAX_ITERATIONS = 10;
|
|
91
|
+
export const LOOP_DEFAULT_STALL_ITERATIONS = 3;
|
|
92
|
+
export const LOOP_MAX_ITERATIONS_LIMIT = 1000;
|
|
93
|
+
|
|
79
94
|
export interface Ticket {
|
|
80
95
|
id: string;
|
|
81
96
|
title: string;
|
|
@@ -114,6 +129,12 @@ export interface Ticket {
|
|
|
114
129
|
bondify: boolean;
|
|
115
130
|
/** Plan bond-app-ajustes-imagen P4: Docker inside the run (privileged container); default false. */
|
|
116
131
|
docker?: boolean;
|
|
132
|
+
/** Issue #4 (P2): the person's Azure session in the run (az without az login); false unless sent (the form ticks it while there is a session). */
|
|
133
|
+
azure_login?: boolean;
|
|
134
|
+
/** Issue #4 (P2, D4): the subscription for this ticket; null = the default of Ajustes. */
|
|
135
|
+
azure_subscription?: string | null;
|
|
136
|
+
/** LOOP P1: the autonomous mode (hub tickets only, v1); disabled by default. */
|
|
137
|
+
loop?: TicketLoop;
|
|
117
138
|
/** P9: engine for bond team inside run container: 'hc' (default, native panes) or 'herdr' (TUI mode). */
|
|
118
139
|
team_engine?: 'hc' | 'herdr';
|
|
119
140
|
status: RunState;
|
|
@@ -152,6 +173,15 @@ export interface CreateTicketInput {
|
|
|
152
173
|
bondify?: boolean;
|
|
153
174
|
/** Plan bond-app-ajustes-imagen P4: Docker inside the run (privileged container); default false. */
|
|
154
175
|
docker?: boolean;
|
|
176
|
+
/** Issue #4 (P2): «Login de Azure»; default false. */
|
|
177
|
+
azure_login?: boolean;
|
|
178
|
+
/** Issue #4 (P2): a subscription id (GUID) of the session, or null for the default. */
|
|
179
|
+
azure_subscription?: string | null;
|
|
180
|
+
/**
|
|
181
|
+
* LOOP P1: `{ enabled, max_iterations? }`; without max_iterations the default from Ajustes,
|
|
182
|
+
* null = no limit. Hub tickets only (v1, decision D7).
|
|
183
|
+
*/
|
|
184
|
+
loop?: { enabled?: boolean; max_iterations?: number | null };
|
|
155
185
|
/** P9: engine for bond team inside run container: 'hc' (default) or 'herdr'. */
|
|
156
186
|
team_engine?: 'hc' | 'herdr';
|
|
157
187
|
}
|
|
@@ -217,6 +247,21 @@ export interface Run {
|
|
|
217
247
|
/** P3 (D19): the run's hc machine (`bond-<runId>`) and its agent terminal (`<machine>/t1`). */
|
|
218
248
|
hc_machine?: string | null;
|
|
219
249
|
hc_terminal?: string | null;
|
|
250
|
+
/**
|
|
251
|
+
* Issue #3: the agent (and pi model) of this run after «Relanzar con resumen» with another
|
|
252
|
+
* one; null = the ticket's. Only the run changes, not the ticket (decision in the issue).
|
|
253
|
+
*/
|
|
254
|
+
agent_override?: string | null;
|
|
255
|
+
model_override?: string | null;
|
|
256
|
+
/** Issue #3 P4: when to resume an agent whose budget ran out (ISO), and which one. */
|
|
257
|
+
resume_at?: string | null;
|
|
258
|
+
resume_agent?: string | null;
|
|
259
|
+
/** LOOP P3 (issue #2): the loop's state (none until «Iniciar loop»), review rounds and stalls. */
|
|
260
|
+
loop_state?: 'running' | 'paused' | 'finishing' | 'finished' | 'stopped' | null;
|
|
261
|
+
loop_iteration?: number;
|
|
262
|
+
loop_stalls?: number;
|
|
263
|
+
/** The person's set-up of the loop at «Iniciar loop» (plan, instructions, iterations) and their later messages to gru. */
|
|
264
|
+
loop_config?: LoopConfig | null;
|
|
220
265
|
cost_usd: number;
|
|
221
266
|
cleanup_pending?: boolean;
|
|
222
267
|
/** P4: consecutive verification failures; at the limit the run goes to `blocked`. */
|
|
@@ -351,6 +396,23 @@ export interface AgentCredentialSummary {
|
|
|
351
396
|
expires_at?: string;
|
|
352
397
|
}
|
|
353
398
|
|
|
399
|
+
/**
|
|
400
|
+
* Issue #4: the person's Azure session (`az login --use-device-code` in Ajustes), as Ajustes
|
|
401
|
+
* and doctor see it: who, which tenant, the subscriptions and the default one; never a token.
|
|
402
|
+
*/
|
|
403
|
+
export interface AzureLoginSummary {
|
|
404
|
+
configured: boolean;
|
|
405
|
+
user?: string;
|
|
406
|
+
tenant_id?: string;
|
|
407
|
+
/** The default subscription for the runs (Ajustes; a ticket may pick another, P2). */
|
|
408
|
+
subscription?: { id: string; name: string } | null;
|
|
409
|
+
subscriptions?: Array<{ id: string; name: string; tenant_id: string }>;
|
|
410
|
+
updated_at?: string;
|
|
411
|
+
/** The refresh token lapses about 90 days after the login (D5: runs never refresh the store). */
|
|
412
|
+
expires_at?: string;
|
|
413
|
+
expired?: boolean;
|
|
414
|
+
}
|
|
415
|
+
|
|
354
416
|
export type AgyLoginStatus =
|
|
355
417
|
| 'idle'
|
|
356
418
|
| 'starting'
|
|
@@ -514,3 +576,15 @@ export interface RunTerminal {
|
|
|
514
576
|
labels?: Record<string, string>;
|
|
515
577
|
exit_code?: number | null;
|
|
516
578
|
}
|
|
579
|
+
|
|
580
|
+
/** LOOP (issue #2): what the person chose when starting the loop, and what they told gru later. */
|
|
581
|
+
export interface LoopConfig {
|
|
582
|
+
/** The plan gru carries out, relative to the hub (docs/plans/<file>.md). */
|
|
583
|
+
plan: string;
|
|
584
|
+
/** The person's instructions for this loop (may be empty). */
|
|
585
|
+
instructions: string;
|
|
586
|
+
/** Maximum review rounds for this loop; null = no limit. */
|
|
587
|
+
max_iterations: number | null;
|
|
588
|
+
/** Messages the person sent gru while the loop ran. */
|
|
589
|
+
messages: Array<{ at: string; text: string }>;
|
|
590
|
+
}
|