@jmanuelcorral/bond-app 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -1
- package/app/mods/bond-agents/config.js +4 -0
- package/app/mods/bond-agents/main.js +10 -5
- package/app/mods/bond-agents/model.js +47 -2
- package/app/mods/bond-board/config.js +4 -0
- package/app/mods/bond-board/main.js +500 -54
- package/app/mods/bond-board/model.js +47 -0
- package/app/mods/bond-settings/config.js +4 -0
- package/app/mods/bond-settings/main.js +689 -12
- package/app/mods/bond-settings/pi-models.js +144 -0
- package/app/mods/bond-status/config.js +4 -0
- package/app/mods/bond-titlebar/main.js +47 -43
- package/package.json +1 -1
- package/runner/Dockerfile +42 -13
- package/runner/SPIKE-BOND.md +85 -0
- package/runner/build-config/.none +0 -0
- package/runner/build-creds/.none +0 -0
- package/runner/config.example/README.md +27 -0
- package/runner/config.example/pi/models.json +22 -0
- package/runner/credentials.example.env +27 -0
- package/runner/setup.sh +496 -0
- package/runner/versions.env +30 -0
- package/scripts/app-install.ts +4 -0
- package/src/config.ts +8 -0
- package/src/core/hub-session.ts +9 -7
- package/src/core/orchestrator.ts +459 -99
- package/src/core/setup.ts +178 -0
- package/src/db/database.ts +14 -0
- package/src/db/settings-repo.ts +108 -0
- package/src/db/ticket-repo.ts +34 -4
- package/src/runner/docker-client.ts +29 -0
- package/src/runner/github-client.ts +119 -0
- package/src/runner/hc-client.ts +9 -2
- package/src/runner/image-builder.ts +146 -6
- package/src/server/app.ts +211 -7
- package/src/types.ts +40 -0
package/src/core/orchestrator.ts
CHANGED
|
@@ -9,9 +9,9 @@ import { EventBus } from '../sse/event-bus.ts';
|
|
|
9
9
|
import { DockerClient, type DockerContainerSummary } from '../runner/docker-client.ts';
|
|
10
10
|
import { Watchdog } from './watchdog.ts';
|
|
11
11
|
import { CostTracker } from './cost-tracker.ts';
|
|
12
|
-
import { HcClient, HcError, machineNameForRun, type HcMachineInfo } from '../runner/hc-client.ts';
|
|
12
|
+
import { HcClient, HcError, machineNameForRun, type HcMachineInfo, type HcTerminalDetails } from '../runner/hc-client.ts';
|
|
13
13
|
import { validateTransition, InvalidStateTransitionError } from './state-machine.ts';
|
|
14
|
-
import { rebuildRunnerImage as rebuildRunnerImageImpl, type RunnerVersions } from '../runner/image-builder.ts';
|
|
14
|
+
import { rebuildRunnerImage as rebuildRunnerImageImpl, type RunnerBuildOptions, type RunnerVersions } from '../runner/image-builder.ts';
|
|
15
15
|
import { GitHubClient, parseGitHubRepo } from '../runner/github-client.ts';
|
|
16
16
|
import {
|
|
17
17
|
assertHubPushTarget,
|
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
TREE_SCRIPT,
|
|
29
29
|
} from './delivery.ts';
|
|
30
30
|
import { HubMountError, HubSession, proposeUrls } from './hub-session.ts';
|
|
31
|
+
import { buildSetupState } from './setup.ts';
|
|
31
32
|
import { HUB_DIR, NAME_RE, agentGaps, analysisPrompt, buildAnalysis, fixedGaps, parseAgentAnswer, repoNameFromUrl, teamAgentFor, teamAgents, type HubToml } from './hub.ts';
|
|
32
33
|
import {
|
|
33
34
|
validateGitHubUrl,
|
|
@@ -42,6 +43,8 @@ import {
|
|
|
42
43
|
type RunState,
|
|
43
44
|
type FailureReason,
|
|
44
45
|
type TeamStatusRow,
|
|
46
|
+
type RunnerImageInfo,
|
|
47
|
+
type SetupState,
|
|
45
48
|
} from '../types.ts';
|
|
46
49
|
import type { AppConfig } from '../config.ts';
|
|
47
50
|
|
|
@@ -165,7 +168,7 @@ export class Orchestrator {
|
|
|
165
168
|
private missingContainerStrikes = new Map<string, number>();
|
|
166
169
|
// P2 criterion 7: guard against concurrent image rebuilds.
|
|
167
170
|
private rebuildInFlight = false;
|
|
168
|
-
private rebuildImpl: (image: string,
|
|
171
|
+
private rebuildImpl: (image: string, options?: RunnerBuildOptions) => Promise<void>;
|
|
169
172
|
// P4: deliveries in progress (verify, commit, push, PR), one per run.
|
|
170
173
|
private deliveries = new Map<string, Promise<Run>>();
|
|
171
174
|
// P4: a token given explicitly at start (not stored); delivery falls back to the stored one.
|
|
@@ -190,7 +193,7 @@ export class Orchestrator {
|
|
|
190
193
|
dockerClient: DockerClient,
|
|
191
194
|
config: AppConfig,
|
|
192
195
|
// P2 criterion 7: injectable for tests; the real docker build is never run in unit/UI tests.
|
|
193
|
-
rebuildImpl: (image: string,
|
|
196
|
+
rebuildImpl: (image: string, options?: RunnerBuildOptions) => Promise<void> = rebuildRunnerImageImpl,
|
|
194
197
|
hcClient: HcClient = new HcClient(),
|
|
195
198
|
github: GitHubClient = new GitHubClient()
|
|
196
199
|
) {
|
|
@@ -266,7 +269,8 @@ export class Orchestrator {
|
|
|
266
269
|
*/
|
|
267
270
|
async injectCredentials(containerName: string, agents: string[], home = '/home/runner'): Promise<string[]> {
|
|
268
271
|
const written: string[] = [];
|
|
269
|
-
|
|
272
|
+
const wanted = new Set(agents);
|
|
273
|
+
for (const agent of wanted) {
|
|
270
274
|
const credential = this.settingsRepo.getCredential(agent);
|
|
271
275
|
if (!credential) continue;
|
|
272
276
|
const destPath = home + this.getAgentConfigPath(agent).slice('/home/runner'.length);
|
|
@@ -281,6 +285,26 @@ export class Orchestrator {
|
|
|
281
285
|
}
|
|
282
286
|
written.push(destPath);
|
|
283
287
|
}
|
|
288
|
+
// W-P4: prompt-suggestions config for supi, written next to pi's models.json when a
|
|
289
|
+
// suggestions model is stored (null = «sin sugerencias» writes nothing). The supi
|
|
290
|
+
// package itself comes with the runner image (image plan P2); until then the file is
|
|
291
|
+
// simply inert, so this never depends on the image's contents.
|
|
292
|
+
if (wanted.has('pi')) {
|
|
293
|
+
const model = this.settingsRepo.getSetupSelection().suggestions_model;
|
|
294
|
+
if (model) {
|
|
295
|
+
const destPath = `${home}/.pi/agent/supi/config.json`;
|
|
296
|
+
const res = await this.dockerClient.injectStdin(
|
|
297
|
+
containerName,
|
|
298
|
+
['sh', '-c', 'umask 077; mkdir -p "$(dirname "$1")" && cat > "$1"', '--', destPath],
|
|
299
|
+
JSON.stringify({ promptSuggestions: { model } }, null, 2),
|
|
300
|
+
'runner'
|
|
301
|
+
);
|
|
302
|
+
if (res.exitCode !== 0) {
|
|
303
|
+
throw new Error(`Supi suggestions config failed with code ${res.exitCode}: ${res.stderr}`);
|
|
304
|
+
}
|
|
305
|
+
written.push(destPath);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
284
308
|
return written;
|
|
285
309
|
}
|
|
286
310
|
|
|
@@ -1285,7 +1309,7 @@ export class Orchestrator {
|
|
|
1285
1309
|
const n = Number(/\/t(\d+)$/.exec(run.hc_terminal || '')?.[1] || '1') + 1;
|
|
1286
1310
|
const terminal = await this.hcClient.startTerminal(
|
|
1287
1311
|
run.hc_machine,
|
|
1288
|
-
this.
|
|
1312
|
+
await this.resolveAgentCommand(run.container_name, ticket, message),
|
|
1289
1313
|
'/workspace/repo',
|
|
1290
1314
|
`agent-${n}`
|
|
1291
1315
|
);
|
|
@@ -1345,103 +1369,220 @@ export class Orchestrator {
|
|
|
1345
1369
|
}
|
|
1346
1370
|
|
|
1347
1371
|
/**
|
|
1348
|
-
*
|
|
1372
|
+
* P2: Build the orchestrator / leader row for a run, used in getRunTeamStatus.
|
|
1373
|
+
* Guarantees that any run (hub or single, running or waiting or queued,
|
|
1374
|
+
* modern or legacy bare agent) returns an orchestrator row.
|
|
1375
|
+
*/
|
|
1376
|
+
private async buildOrchestratorRow(
|
|
1377
|
+
run: Run,
|
|
1378
|
+
ticket: Ticket | null,
|
|
1379
|
+
terminalInfo?: HcTerminalDetails | null
|
|
1380
|
+
): Promise<TeamStatusRow> {
|
|
1381
|
+
const isHub = ticket?.mode === 'hub';
|
|
1382
|
+
const agentKind = ticket?.agent || 'pi';
|
|
1383
|
+
|
|
1384
|
+
let t = terminalInfo ?? null;
|
|
1385
|
+
if (!t && run.hc_terminal) {
|
|
1386
|
+
try {
|
|
1387
|
+
t = await this.hcClient.getTerminal(run.hc_terminal);
|
|
1388
|
+
} catch {}
|
|
1389
|
+
}
|
|
1390
|
+
if (!t && run.hc_machine) {
|
|
1391
|
+
try {
|
|
1392
|
+
const terminals = await this.hcClient.getMachineTerminals(run.hc_machine);
|
|
1393
|
+
t =
|
|
1394
|
+
terminals.find(
|
|
1395
|
+
(x) =>
|
|
1396
|
+
x.name === 'hub leader' ||
|
|
1397
|
+
x.name === 'orquestador' ||
|
|
1398
|
+
x.address?.endsWith('/t1')
|
|
1399
|
+
) ||
|
|
1400
|
+
terminals[0] ||
|
|
1401
|
+
null;
|
|
1402
|
+
} catch {}
|
|
1403
|
+
}
|
|
1404
|
+
|
|
1405
|
+
const isGenericAgent = (name?: string) => !name || name === 'agent' || /^t\d+$/.test(name);
|
|
1406
|
+
|
|
1407
|
+
let listedAgent: string | undefined;
|
|
1408
|
+
if (isGenericAgent(t?.agent) && (run.hc_machine || run.hc_terminal || t?.address)) {
|
|
1409
|
+
try {
|
|
1410
|
+
const listed = await this.hcClient.listTerminals(run.hc_machine || undefined);
|
|
1411
|
+
const match = listed.find(
|
|
1412
|
+
(x) => x.address === (t?.address || run.hc_terminal) || x.address?.endsWith('/t1')
|
|
1413
|
+
);
|
|
1414
|
+
if (match?.agent && !isGenericAgent(match.agent)) {
|
|
1415
|
+
listedAgent = match.agent;
|
|
1416
|
+
}
|
|
1417
|
+
} catch {}
|
|
1418
|
+
}
|
|
1419
|
+
|
|
1420
|
+
if (t && listedAgent && isGenericAgent(t.agent)) {
|
|
1421
|
+
t.agent = listedAgent;
|
|
1422
|
+
}
|
|
1423
|
+
|
|
1424
|
+
const detectedAgent =
|
|
1425
|
+
t?.agent && !isGenericAgent(t.agent)
|
|
1426
|
+
? t.agent
|
|
1427
|
+
: listedAgent && !isGenericAgent(listedAgent)
|
|
1428
|
+
? listedAgent
|
|
1429
|
+
: ticket?.agent || 'pi';
|
|
1430
|
+
const agentName = isHub ? 'hub leader' : detectedAgent;
|
|
1431
|
+
const pane =
|
|
1432
|
+
t?.address ||
|
|
1433
|
+
run.hc_terminal ||
|
|
1434
|
+
(run.hc_machine ? `${run.hc_machine}/t1` : undefined);
|
|
1435
|
+
|
|
1436
|
+
let state = 'trabajando';
|
|
1437
|
+
let status = 'working';
|
|
1438
|
+
let question: string | undefined = undefined;
|
|
1439
|
+
|
|
1440
|
+
if (run.state === 'queued' || run.state === 'ready') {
|
|
1441
|
+
state = 'arrancando';
|
|
1442
|
+
status = 'arrancando';
|
|
1443
|
+
} else if (run.state === 'waiting') {
|
|
1444
|
+
state = 'bloqueado';
|
|
1445
|
+
status = 'en espera';
|
|
1446
|
+
question = run.failure_reason || (agentName ? `Esperando respuesta: ${agentName}` : undefined);
|
|
1447
|
+
} else if (t) {
|
|
1448
|
+
const isWaiting =
|
|
1449
|
+
t.status === 'blocked' ||
|
|
1450
|
+
((t.status === 'idle' || t.status === 'done') && (t.turn ?? 0) > 0);
|
|
1451
|
+
|
|
1452
|
+
if (isWaiting) {
|
|
1453
|
+
state = 'bloqueado';
|
|
1454
|
+
status = 'en espera';
|
|
1455
|
+
question = run.failure_reason || (agentName ? `Esperando respuesta: ${agentName}` : undefined);
|
|
1456
|
+
} else if (t.status === 'working') {
|
|
1457
|
+
state = 'trabajando';
|
|
1458
|
+
status = 'working';
|
|
1459
|
+
} else if (t.status === 'idle') {
|
|
1460
|
+
state = 'idle';
|
|
1461
|
+
status = 'idle';
|
|
1462
|
+
} else if (t.status === 'live') {
|
|
1463
|
+
state = 'live';
|
|
1464
|
+
status = 'live';
|
|
1465
|
+
} else if (t.status) {
|
|
1466
|
+
state = t.status;
|
|
1467
|
+
status = t.status;
|
|
1468
|
+
} else if (t.state === 'live') {
|
|
1469
|
+
// Live terminal without agent status hook (e.g. p6 with bond tui, or bare pi)
|
|
1470
|
+
state = 'live';
|
|
1471
|
+
status = 'live';
|
|
1472
|
+
} else {
|
|
1473
|
+
state = 'sin estado';
|
|
1474
|
+
status = 'sin estado';
|
|
1475
|
+
}
|
|
1476
|
+
} else {
|
|
1477
|
+
if (run.state === 'running') {
|
|
1478
|
+
state = 'arrancando';
|
|
1479
|
+
status = 'arrancando';
|
|
1480
|
+
} else if (run.state === 'finished') {
|
|
1481
|
+
state = 'lista';
|
|
1482
|
+
status = 'finished';
|
|
1483
|
+
} else if (run.state === 'failed') {
|
|
1484
|
+
state = 'bloqueado';
|
|
1485
|
+
status = 'failed';
|
|
1486
|
+
} else {
|
|
1487
|
+
state = 'sin estado';
|
|
1488
|
+
status = 'sin estado';
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1492
|
+
return {
|
|
1493
|
+
branch: ticket?.target_branch || '',
|
|
1494
|
+
path: isHub ? '/workspace/hub' : '/workspace/repo',
|
|
1495
|
+
repo: 'orquestador',
|
|
1496
|
+
state,
|
|
1497
|
+
ahead: 0,
|
|
1498
|
+
files: [],
|
|
1499
|
+
dirty: 0,
|
|
1500
|
+
integrated: false,
|
|
1501
|
+
agent: {
|
|
1502
|
+
name: agentName,
|
|
1503
|
+
kind: agentKind,
|
|
1504
|
+
status,
|
|
1505
|
+
question,
|
|
1506
|
+
pane,
|
|
1507
|
+
terminal: pane,
|
|
1508
|
+
},
|
|
1509
|
+
};
|
|
1510
|
+
}
|
|
1511
|
+
|
|
1512
|
+
/**
|
|
1513
|
+
* P7 (criterion 8 & Ampliación) & P2: get the team status for a run.
|
|
1349
1514
|
* For hub runs, includes the hub orchestrator agent (pi in hub root) at the top,
|
|
1350
1515
|
* labelled as «hub leader» (orquestador), merged with repo agents from `bond team status --json`.
|
|
1516
|
+
* For single runs, returns the orchestrator agent row.
|
|
1351
1517
|
*/
|
|
1352
1518
|
async getRunTeamStatus(runId: string): Promise<TeamStatusRow[]> {
|
|
1353
1519
|
const run = this.runRepo.get(runId);
|
|
1354
1520
|
if (!run) throw new ValidationError(`Run '${runId}' not found`);
|
|
1355
|
-
if (!run.container_name) return [];
|
|
1356
1521
|
|
|
1357
1522
|
const ticket = this.ticketRepo.get(run.ticket_id);
|
|
1358
1523
|
const isHub = ticket?.mode === 'hub';
|
|
1359
1524
|
|
|
1525
|
+
if (!run.container_name) {
|
|
1526
|
+
return [await this.buildOrchestratorRow(run, ticket)];
|
|
1527
|
+
}
|
|
1528
|
+
|
|
1360
1529
|
// P9: HC engine - get status directly from hc, NO docker exec
|
|
1361
|
-
if (
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1530
|
+
if (ticket?.team_engine !== 'herdr') {
|
|
1531
|
+
if (isHub) {
|
|
1532
|
+
try {
|
|
1533
|
+
const machine = run.hc_machine || machineNameForRun(run.id);
|
|
1534
|
+
const terminals = await this.hcClient.getMachineTerminals(machine);
|
|
1365
1535
|
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1536
|
+
const isLeader = (t: { name?: string; cwd?: string; address?: string }) => {
|
|
1537
|
+
if (t.name === 'hub leader' || t.name === 'hub-leader' || t.name === 'leader' || t.name === 'orquestador') {
|
|
1538
|
+
return true;
|
|
1539
|
+
}
|
|
1540
|
+
const cleanCwd = t.cwd?.replace(/\/+$/, '');
|
|
1541
|
+
if (cleanCwd === '/workspace/hub') return true;
|
|
1542
|
+
if (t.address?.endsWith('/t1')) return true;
|
|
1543
|
+
return false;
|
|
1544
|
+
};
|
|
1375
1545
|
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
let leaderStatus = 'working';
|
|
1381
|
-
if (leader.status === 'blocked') {
|
|
1382
|
-
leaderState = 'bloqueado';
|
|
1383
|
-
leaderStatus = 'blocked';
|
|
1384
|
-
} else if ((leader.status === 'idle' || leader.status === 'done') && (leader.turn ?? 0) > 0) {
|
|
1385
|
-
leaderState = 'bloqueado';
|
|
1386
|
-
leaderStatus = 'en espera';
|
|
1387
|
-
} else if (leader.status === 'working') {
|
|
1388
|
-
leaderState = 'trabajando';
|
|
1389
|
-
leaderStatus = 'working';
|
|
1390
|
-
} else {
|
|
1391
|
-
leaderState = 'trabajando';
|
|
1392
|
-
leaderStatus = leader.status || 'working';
|
|
1546
|
+
const rows: TeamStatusRow[] = [];
|
|
1547
|
+
const leader = terminals.find(isLeader);
|
|
1548
|
+
if (leader) {
|
|
1549
|
+
rows.push(await this.buildOrchestratorRow(run, ticket, leader));
|
|
1393
1550
|
}
|
|
1394
1551
|
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
else if (t.status === 'working') state = 'trabajando';
|
|
1423
|
-
return {
|
|
1424
|
-
branch,
|
|
1425
|
-
path: t.cwd || '',
|
|
1426
|
-
repo: repoName,
|
|
1427
|
-
state,
|
|
1428
|
-
ahead: 0,
|
|
1429
|
-
files: [],
|
|
1430
|
-
dirty: 0,
|
|
1431
|
-
integrated: false,
|
|
1432
|
-
agent: {
|
|
1433
|
-
name: t.name || repoName,
|
|
1434
|
-
kind: t.agent || ticket?.agent || 'pi',
|
|
1435
|
-
status: t.status || 'unknown',
|
|
1436
|
-
pane: t.address,
|
|
1437
|
-
terminal: t.address,
|
|
1438
|
-
},
|
|
1439
|
-
};
|
|
1440
|
-
});
|
|
1552
|
+
const repoRows: TeamStatusRow[] = terminals
|
|
1553
|
+
.filter((t) => !isLeader(t))
|
|
1554
|
+
.map((t) => {
|
|
1555
|
+
const repoName = t.labels?.['bond.repo']?.replace(/^repos\//, '') || t.name || 'agente';
|
|
1556
|
+
const branch = t.labels?.['bond.branch'] || ticket?.target_branch || '';
|
|
1557
|
+
let state = 'trabajando';
|
|
1558
|
+
if (t.status === 'blocked') state = 'bloqueado';
|
|
1559
|
+
else if ((t.status === 'idle' || t.status === 'done') && (t.turn ?? 0) > 0) state = 'lista';
|
|
1560
|
+
else if (t.status === 'working') state = 'trabajando';
|
|
1561
|
+
return {
|
|
1562
|
+
branch,
|
|
1563
|
+
path: t.cwd || '',
|
|
1564
|
+
repo: repoName,
|
|
1565
|
+
state,
|
|
1566
|
+
ahead: 0,
|
|
1567
|
+
files: [],
|
|
1568
|
+
dirty: 0,
|
|
1569
|
+
integrated: false,
|
|
1570
|
+
agent: {
|
|
1571
|
+
name: t.name || repoName,
|
|
1572
|
+
kind: t.agent || ticket?.agent || 'pi',
|
|
1573
|
+
status: t.status || 'unknown',
|
|
1574
|
+
pane: t.address,
|
|
1575
|
+
terminal: t.address,
|
|
1576
|
+
},
|
|
1577
|
+
};
|
|
1578
|
+
});
|
|
1441
1579
|
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1580
|
+
return [...rows, ...repoRows];
|
|
1581
|
+
} catch {
|
|
1582
|
+
return [await this.buildOrchestratorRow(run, ticket)];
|
|
1583
|
+
}
|
|
1584
|
+
} else {
|
|
1585
|
+
return [await this.buildOrchestratorRow(run, ticket)];
|
|
1445
1586
|
}
|
|
1446
1587
|
}
|
|
1447
1588
|
|
|
@@ -1567,11 +1708,13 @@ export class Orchestrator {
|
|
|
1567
1708
|
r.agent?.name !== 'hub leader'
|
|
1568
1709
|
),
|
|
1569
1710
|
];
|
|
1711
|
+
} else if (rows.length === 0) {
|
|
1712
|
+
rows = [await this.buildOrchestratorRow(run, ticket)];
|
|
1570
1713
|
}
|
|
1571
1714
|
|
|
1572
1715
|
return rows;
|
|
1573
1716
|
} catch {
|
|
1574
|
-
return [];
|
|
1717
|
+
return [await this.buildOrchestratorRow(run, ticket)];
|
|
1575
1718
|
}
|
|
1576
1719
|
}
|
|
1577
1720
|
|
|
@@ -2011,8 +2154,10 @@ export class Orchestrator {
|
|
|
2011
2154
|
if (cmd) return [...cmd];
|
|
2012
2155
|
// Hub agent runs read-only pi in print mode regardless of the ticket's agent (P3 criterion 5)
|
|
2013
2156
|
const argv = ['pi', '-p', '--no-session', '--no-approve', '--tools', 'read,grep,find,ls'];
|
|
2014
|
-
// Review L-4 / M-4: pass model only when ticket.agent is pi
|
|
2015
|
-
|
|
2157
|
+
// Review L-4 / M-4: pass model only when ticket.agent is pi; default_model applies if ticket has no model (D-M1)
|
|
2158
|
+
const defaultModel = ticket.agent === 'pi' ? this.settingsRepo?.getSetupSelection?.()?.default_model : null;
|
|
2159
|
+
const model = ticket.agent === 'pi' ? (ticket.model || defaultModel) : null;
|
|
2160
|
+
if (model && /^[A-Za-z0-9_./:@-]{1,120}$/.test(model)) argv.push('--model', model);
|
|
2016
2161
|
return argv;
|
|
2017
2162
|
}
|
|
2018
2163
|
|
|
@@ -2064,6 +2209,7 @@ export class Orchestrator {
|
|
|
2064
2209
|
if (!reused) {
|
|
2065
2210
|
const terminal = await session.launchTeam(this.hcClient, run.hc_machine!, ticket, analysis.repos, {
|
|
2066
2211
|
onTerminal: (address) => this.runRepo.update(runId, { hc_terminal: address }),
|
|
2212
|
+
defaultModel: this.settingsRepo?.getSetupSelection?.()?.default_model,
|
|
2067
2213
|
});
|
|
2068
2214
|
this.runRepo.update(runId, { hc_terminal: terminal });
|
|
2069
2215
|
} else {
|
|
@@ -2704,8 +2850,14 @@ fi
|
|
|
2704
2850
|
return this.runRepo.get(run.id)!;
|
|
2705
2851
|
}
|
|
2706
2852
|
|
|
2853
|
+
if (!options.skipClone) {
|
|
2854
|
+
await this.bondifyRepo(containerInfo.containerName, ticket, run.id);
|
|
2855
|
+
}
|
|
2856
|
+
|
|
2857
|
+
assertQueued();
|
|
2858
|
+
|
|
2707
2859
|
const agentCwd = options.skipClone ? '/workspace' : '/workspace/repo';
|
|
2708
|
-
const hcTerminal = await this.hcClient.startTerminal(hcMachine, this.
|
|
2860
|
+
const hcTerminal = await this.hcClient.startTerminal(hcMachine, await this.resolveAgentCommand(containerInfo.containerName, ticket), agentCwd);
|
|
2709
2861
|
this.runRepo.update(run.id, { hc_terminal: hcTerminal });
|
|
2710
2862
|
await this.hcClient.assertTerminalAlive(hcTerminal);
|
|
2711
2863
|
|
|
@@ -2813,13 +2965,169 @@ fi
|
|
|
2813
2965
|
}
|
|
2814
2966
|
const story = [ticket.story ?? '', ticket.prompt ?? ''].filter((s) => s.trim()).join('\n\n');
|
|
2815
2967
|
const prompt = (promptOverride ?? story).trim();
|
|
2816
|
-
// P4: the ticket's model for pi (`--model provider/id`),
|
|
2817
|
-
|
|
2818
|
-
|
|
2968
|
+
// P4 & D-M1: the ticket's model for pi (`--model provider/id`), or default_model if ticket has none.
|
|
2969
|
+
const defaultModel = ticket.agent === 'pi' ? this.settingsRepo?.getSetupSelection?.()?.default_model : null;
|
|
2970
|
+
const model = ticket.agent === 'pi' ? (ticket.model || defaultModel) : null;
|
|
2971
|
+
if (ticket.agent === 'pi' && model) {
|
|
2972
|
+
return prompt ? ['pi', '--model', model, prompt] : ['pi', '--model', model];
|
|
2819
2973
|
}
|
|
2820
2974
|
return prompt ? [ticket.agent, prompt] : [ticket.agent];
|
|
2821
2975
|
}
|
|
2822
2976
|
|
|
2977
|
+
/**
|
|
2978
|
+
* P4 (D-U): Auto-bondify repository if it lacks .bond/bond.toml.
|
|
2979
|
+
* If config.runnerLauncher === 'bond' and ticket.bondify !== false:
|
|
2980
|
+
* Probes `command -v bond >/dev/null 2>&1 && [ ! -f /workspace/repo/.bond/bond.toml ]`.
|
|
2981
|
+
* If true, runs in /workspace/repo `bond init --yes --agents <ticket.agent>`, then commits
|
|
2982
|
+
* the MINIMAL bondification à la bond-hub: only `.bond/bond.toml` (and `AGENTS.md` when bond
|
|
2983
|
+
* init created or modified it). The runtime output of bond init (`.agents/`, `.pi/`, ...)
|
|
2984
|
+
* stays on disk for the agent but is appended to `.git/info/exclude` so neither this commit
|
|
2985
|
+
* nor the agent's own `git add -A` ever carries it into the PR.
|
|
2986
|
+
* Emits agentEvent on completion or failure.
|
|
2987
|
+
*
|
|
2988
|
+
* Pi non-interactive trust: /workspace is already trusted in /home/runner/.pi/agent/trust.json
|
|
2989
|
+
* (baked into the runner image in runner/Dockerfile via runner/pi-trust.json). Because pi and
|
|
2990
|
+
* bond match the nearest ancestor directory when checking trust, any path inside /workspace/repo
|
|
2991
|
+
* inherits project trust automatically without user prompts or confirmation dialogs.
|
|
2992
|
+
*
|
|
2993
|
+
* If .bond/bond.toml already exists, does nothing.
|
|
2994
|
+
* If ticket.bondify === false, does not probe at all.
|
|
2995
|
+
* If bond init or commit fails, logs and records an event, but continues without throwing.
|
|
2996
|
+
*/
|
|
2997
|
+
async bondifyRepo(
|
|
2998
|
+
containerName: string | null | undefined,
|
|
2999
|
+
ticket: Ticket,
|
|
3000
|
+
runId: string
|
|
3001
|
+
): Promise<boolean> {
|
|
3002
|
+
if (this.config.runnerLauncher !== 'bond' || ticket.bondify === false || !containerName) {
|
|
3003
|
+
return false;
|
|
3004
|
+
}
|
|
3005
|
+
|
|
3006
|
+
try {
|
|
3007
|
+
const probe = await this.dockerClient.exec(
|
|
3008
|
+
containerName,
|
|
3009
|
+
['sh', '-c', 'command -v bond >/dev/null 2>&1 && [ ! -f /workspace/repo/.bond/bond.toml ]'],
|
|
3010
|
+
'runner',
|
|
3011
|
+
15000
|
|
3012
|
+
);
|
|
3013
|
+
if (probe.exitCode !== 0) {
|
|
3014
|
+
return false;
|
|
3015
|
+
}
|
|
3016
|
+
|
|
3017
|
+
const initRes = await this.dockerClient.exec(
|
|
3018
|
+
containerName,
|
|
3019
|
+
['sh', '-c', `cd /workspace/repo && bond init --yes --agents ${ticket.agent}`],
|
|
3020
|
+
'runner',
|
|
3021
|
+
30000
|
|
3022
|
+
);
|
|
3023
|
+
if (initRes.exitCode !== 0) {
|
|
3024
|
+
if (this.eventBus) {
|
|
3025
|
+
const run = this.runRepo?.get?.(runId);
|
|
3026
|
+
if (run) {
|
|
3027
|
+
this.agentEvent(run, 'bond.init_failed', { exitCode: initRes.exitCode, stderr: initRes.stderr });
|
|
3028
|
+
} else {
|
|
3029
|
+
this.eventBus.publish(runId, ticket.id, 'agent.event', {
|
|
3030
|
+
run_id: runId,
|
|
3031
|
+
ticket_id: ticket.id,
|
|
3032
|
+
event: 'bond.init_failed',
|
|
3033
|
+
exitCode: initRes.exitCode,
|
|
3034
|
+
stderr: initRes.stderr,
|
|
3035
|
+
});
|
|
3036
|
+
}
|
|
3037
|
+
}
|
|
3038
|
+
return false;
|
|
3039
|
+
}
|
|
3040
|
+
|
|
3041
|
+
const commitRes = await this.dockerClient.exec(
|
|
3042
|
+
containerName,
|
|
3043
|
+
[
|
|
3044
|
+
'sh',
|
|
3045
|
+
'-c',
|
|
3046
|
+
'cd /workspace/repo && printf "%s\\n" /.agents/ /.pi/ /.claude/ /.codex/ >> .git/info/exclude'
|
|
3047
|
+
+ ' && git add .bond/bond.toml'
|
|
3048
|
+
+ ' && { git add AGENTS.md 2>/dev/null || true; }'
|
|
3049
|
+
+ ' && { git diff --cached --quiet || git -c user.name=bond-app -c user.email=bond-app@localhost commit -q -m "chore: bond init"; }',
|
|
3050
|
+
],
|
|
3051
|
+
'runner',
|
|
3052
|
+
15000
|
|
3053
|
+
);
|
|
3054
|
+
if (commitRes.exitCode !== 0) {
|
|
3055
|
+
if (this.eventBus) {
|
|
3056
|
+
const run = this.runRepo?.get?.(runId);
|
|
3057
|
+
if (run) {
|
|
3058
|
+
this.agentEvent(run, 'bond.commit_failed', { exitCode: commitRes.exitCode, stderr: commitRes.stderr });
|
|
3059
|
+
} else {
|
|
3060
|
+
this.eventBus.publish(runId, ticket.id, 'agent.event', {
|
|
3061
|
+
run_id: runId,
|
|
3062
|
+
ticket_id: ticket.id,
|
|
3063
|
+
event: 'bond.commit_failed',
|
|
3064
|
+
exitCode: commitRes.exitCode,
|
|
3065
|
+
stderr: commitRes.stderr,
|
|
3066
|
+
});
|
|
3067
|
+
}
|
|
3068
|
+
}
|
|
3069
|
+
return false;
|
|
3070
|
+
}
|
|
3071
|
+
|
|
3072
|
+
if (this.eventBus) {
|
|
3073
|
+
const run = this.runRepo?.get?.(runId);
|
|
3074
|
+
if (run) {
|
|
3075
|
+
this.agentEvent(run, 'bond.init_done', { agent: ticket.agent, commit: 'chore: bond init' });
|
|
3076
|
+
} else {
|
|
3077
|
+
this.eventBus.publish(runId, ticket.id, 'agent.event', {
|
|
3078
|
+
run_id: runId,
|
|
3079
|
+
ticket_id: ticket.id,
|
|
3080
|
+
event: 'bond.init_done',
|
|
3081
|
+
agent: ticket.agent,
|
|
3082
|
+
commit: 'chore: bond init',
|
|
3083
|
+
});
|
|
3084
|
+
}
|
|
3085
|
+
}
|
|
3086
|
+
return true;
|
|
3087
|
+
} catch {
|
|
3088
|
+
return false;
|
|
3089
|
+
}
|
|
3090
|
+
}
|
|
3091
|
+
|
|
3092
|
+
/**
|
|
3093
|
+
* D-G (image plan): the launch command is `bond tui --agent <agente>` - bond is the
|
|
3094
|
+
* harness (skills, AGENTS.md, sync, decisions, the rich agent bar); the ticket prompt
|
|
3095
|
+
* travels after `--` so it reaches the agent as its first message (runner/SPIKE-BOND.md).
|
|
3096
|
+
* Falls back to the bare launcher (agentCommandFor) when runner_launcher is "pi", an
|
|
3097
|
+
* explicit BOND_APP_AGENT_COMMAND wins, the image has no bond with `tui`, or the clone
|
|
3098
|
+
* is not a bond repo - there bond would stop to offer `bond init`.
|
|
3099
|
+
*/
|
|
3100
|
+
async resolveAgentCommand(
|
|
3101
|
+
containerName: string | null | undefined,
|
|
3102
|
+
ticket: Ticket,
|
|
3103
|
+
promptOverride?: string
|
|
3104
|
+
): Promise<string[]> {
|
|
3105
|
+
if (this.config.runnerLauncher !== 'bond' || this.config.agentCommand || !containerName) {
|
|
3106
|
+
return this.agentCommandFor(ticket, promptOverride);
|
|
3107
|
+
}
|
|
3108
|
+
try {
|
|
3109
|
+
const probe = await this.dockerClient.exec(containerName, [
|
|
3110
|
+
'sh', '-c',
|
|
3111
|
+
'command -v bond >/dev/null 2>&1 && bond tui --help >/dev/null 2>&1 && [ -f "/workspace/repo/.bond/bond.toml" ]',
|
|
3112
|
+
]);
|
|
3113
|
+
if (probe.exitCode !== 0) return this.agentCommandFor(ticket, promptOverride);
|
|
3114
|
+
} catch {
|
|
3115
|
+
return this.agentCommandFor(ticket, promptOverride);
|
|
3116
|
+
}
|
|
3117
|
+
if (!isValidAgent(ticket.agent)) {
|
|
3118
|
+
throw new ValidationError(`Unsupported agent '${ticket.agent}'`);
|
|
3119
|
+
}
|
|
3120
|
+
const story = [ticket.story ?? '', ticket.prompt ?? ''].filter((s) => s.trim()).join('\n\n');
|
|
3121
|
+
const prompt = (promptOverride ?? story).trim();
|
|
3122
|
+
const argv = ['bond', 'tui', '--agent', ticket.agent, '--'];
|
|
3123
|
+
// P4 (D-D) & D-M1: el modelo solo aplica a pi; default_model si el ticket no trae modelo.
|
|
3124
|
+
const defaultModel = ticket.agent === 'pi' ? this.settingsRepo?.getSetupSelection?.()?.default_model : null;
|
|
3125
|
+
const model = ticket.agent === 'pi' ? (ticket.model || defaultModel) : null;
|
|
3126
|
+
if (ticket.agent === 'pi' && model) argv.push('--model', model);
|
|
3127
|
+
if (prompt) argv.push(prompt);
|
|
3128
|
+
return argv;
|
|
3129
|
+
}
|
|
3130
|
+
|
|
2823
3131
|
/**
|
|
2824
3132
|
* Teardown the run's hc machine, container and network (N1, M3, M4, P3).
|
|
2825
3133
|
* The hc machine is forgotten first; the container and network are removed even if
|
|
@@ -3196,26 +3504,78 @@ fi
|
|
|
3196
3504
|
|
|
3197
3505
|
/**
|
|
3198
3506
|
* P2 criterion 7 (D7): rebuild the runner image with the new pinned versions of
|
|
3199
|
-
* bond, hc and the agents.
|
|
3200
|
-
*
|
|
3507
|
+
* bond, hc and the agents. Image plan P2: the body may also pick the agent list and
|
|
3508
|
+
* optional staged config/credentials; the data dir root for their validation is
|
|
3509
|
+
* injected here, never taken from the request.
|
|
3510
|
+
* Credentials are never touched by a plain rebuild: they never live in the image
|
|
3511
|
+
* unless explicitly staged (D-A) and nothing secret goes on the docker command line.
|
|
3201
3512
|
*/
|
|
3202
|
-
async rebuildRunnerImage(
|
|
3513
|
+
async rebuildRunnerImage(
|
|
3514
|
+
versions: RunnerVersions = {},
|
|
3515
|
+
extras: {
|
|
3516
|
+
agents?: string[];
|
|
3517
|
+
skip_az?: boolean;
|
|
3518
|
+
skip_gh?: boolean;
|
|
3519
|
+
config_dir?: string;
|
|
3520
|
+
credentials_file?: string;
|
|
3521
|
+
} = {}
|
|
3522
|
+
): Promise<{ image: string; rebuilt_at: string; credentials_touched: boolean }> {
|
|
3203
3523
|
if (this.rebuildInFlight) {
|
|
3204
3524
|
throw new RebuildInProgressError('A rebuild is already in progress');
|
|
3205
3525
|
}
|
|
3206
3526
|
this.rebuildInFlight = true;
|
|
3207
3527
|
try {
|
|
3208
|
-
await this.rebuildImpl(this.config.runnerImage,
|
|
3528
|
+
await this.rebuildImpl(this.config.runnerImage, {
|
|
3529
|
+
...versions,
|
|
3530
|
+
...extras,
|
|
3531
|
+
data_dir: this.config.dataDir,
|
|
3532
|
+
});
|
|
3209
3533
|
return {
|
|
3210
3534
|
image: this.config.runnerImage,
|
|
3211
3535
|
rebuilt_at: new Date().toISOString(),
|
|
3212
|
-
credentials_touched:
|
|
3536
|
+
credentials_touched: extras.credentials_file !== undefined,
|
|
3213
3537
|
};
|
|
3214
3538
|
} finally {
|
|
3215
3539
|
this.rebuildInFlight = false;
|
|
3216
3540
|
}
|
|
3217
3541
|
}
|
|
3218
3542
|
|
|
3543
|
+
/**
|
|
3544
|
+
* W-P1 (wizard): the aggregated setup state — selection, per-agent credentials, the gh
|
|
3545
|
+
* session and the runner image. Recomputed on every call (a stored credential shows up
|
|
3546
|
+
* without a restart); a docker that is not there or fails reads as image absent.
|
|
3547
|
+
*/
|
|
3548
|
+
async getSetupState(): Promise<SetupState> {
|
|
3549
|
+
let image: RunnerImageInfo;
|
|
3550
|
+
try {
|
|
3551
|
+
image = await this.dockerClient.inspectRunnerImage(this.config.runnerImage);
|
|
3552
|
+
} catch {
|
|
3553
|
+
image = { present: false };
|
|
3554
|
+
}
|
|
3555
|
+
const selection = this.settingsRepo.getSetupSelection();
|
|
3556
|
+
return buildSetupState({
|
|
3557
|
+
setup_done: selection.setup_done,
|
|
3558
|
+
agents_selected: selection.agents_selected,
|
|
3559
|
+
credentials: this.settingsRepo.listSummaries(),
|
|
3560
|
+
github: this.settingsRepo.getGitHubSummary(),
|
|
3561
|
+
image,
|
|
3562
|
+
suggestions_model: selection.suggestions_model,
|
|
3563
|
+
default_model: selection.default_model,
|
|
3564
|
+
models: selection.models,
|
|
3565
|
+
});
|
|
3566
|
+
}
|
|
3567
|
+
|
|
3568
|
+
/** W-P1: persists the wizard's selection; only the given fields change (validated by the API). */
|
|
3569
|
+
saveSetup(selection: {
|
|
3570
|
+
agents_selected?: string[];
|
|
3571
|
+
setup_done?: boolean;
|
|
3572
|
+
suggestions_model?: string | null;
|
|
3573
|
+
default_model?: string | null;
|
|
3574
|
+
models?: string[];
|
|
3575
|
+
}): void {
|
|
3576
|
+
this.settingsRepo.saveSetupSelection(selection);
|
|
3577
|
+
}
|
|
3578
|
+
|
|
3219
3579
|
/**
|
|
3220
3580
|
* State transitions. Terminal transitions delegate directly to terminateRun (H4, N2).
|
|
3221
3581
|
*/
|