duckhunt-runner 0.24.0 → 0.25.1
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/dist/announced-capabilities.d.ts.map +1 -1
- package/dist/announced-capabilities.js +2 -0
- package/dist/announced-capabilities.js.map +1 -1
- package/dist/claim.d.ts.map +1 -1
- package/dist/claim.js +2 -1
- package/dist/claim.js.map +1 -1
- package/dist/claude-args.d.ts +1 -0
- package/dist/claude-args.d.ts.map +1 -1
- package/dist/claude-args.js +2 -0
- package/dist/claude-args.js.map +1 -1
- package/dist/claude.d.ts +2 -1
- package/dist/claude.d.ts.map +1 -1
- package/dist/claude.js +2 -0
- package/dist/claude.js.map +1 -1
- package/dist/daemon.d.ts +3 -2
- package/dist/daemon.d.ts.map +1 -1
- package/dist/daemon.js +127 -30
- package/dist/daemon.js.map +1 -1
- package/dist/live-session.d.ts +12 -2
- package/dist/live-session.d.ts.map +1 -1
- package/dist/live-session.js +49 -9
- package/dist/live-session.js.map +1 -1
- package/dist/platforms/duckhunt42.d.ts +5 -1
- package/dist/platforms/duckhunt42.d.ts.map +1 -1
- package/dist/platforms/duckhunt42.js +32 -1
- package/dist/platforms/duckhunt42.js.map +1 -1
- package/dist/platforms/platform.d.ts +7 -1
- package/dist/platforms/platform.d.ts.map +1 -1
- package/dist/platforms/platform.js.map +1 -1
- package/dist/rewind-files.d.ts +0 -2
- package/dist/rewind-files.d.ts.map +1 -1
- package/dist/rewind-files.js +1 -11
- package/dist/rewind-files.js.map +1 -1
- package/dist/turn-changes.d.ts +15 -2
- package/dist/turn-changes.d.ts.map +1 -1
- package/dist/turn-changes.js +63 -2
- package/dist/turn-changes.js.map +1 -1
- package/dist/vendor/runner-protocol/capabilities.d.ts +1 -0
- package/dist/vendor/runner-protocol/capabilities.d.ts.map +1 -1
- package/dist/vendor/runner-protocol/capabilities.js +3 -0
- package/dist/vendor/runner-protocol/capabilities.js.map +1 -1
- package/dist/vendor/runner-protocol/live.d.ts +39 -3
- package/dist/vendor/runner-protocol/live.d.ts.map +1 -1
- package/dist/vendor/runner-protocol/live.js +10 -0
- package/dist/vendor/runner-protocol/live.js.map +1 -1
- package/package.json +1 -1
package/dist/daemon.js
CHANGED
|
@@ -131,7 +131,7 @@ import { concurrency, configPath, mergeEntries, parseConfig, parseConfigV2, pars
|
|
|
131
131
|
import { derivedMachineId, ensureMachineId, ensureMachineSecret } from './machine.js';
|
|
132
132
|
import { browserVaultDeny, otherPlatformsDeny, otherScratchDeny, secretPathsDeny } from './secret-paths.js';
|
|
133
133
|
import { CLAIM_OUTCOME } from './server-state.js';
|
|
134
|
-
import { consumeStreamLine, detectClaude, newStreamState, supportsPermissionPromptTool, supportsRewind } from './claude.js';
|
|
134
|
+
import { consumeStreamLine, detectClaude, newStreamState, supportsPermissionPromptTool, supportsRewind, reportedModel } from './claude.js';
|
|
135
135
|
import { buildClaudeArgs, claudeRunEnv } from './claude-args.js';
|
|
136
136
|
import { LiveSession } from './live-session.js';
|
|
137
137
|
import { announcedCapabilities } from './announced-capabilities.js';
|
|
@@ -141,8 +141,8 @@ import { EventUploader } from './event-uploader.js';
|
|
|
141
141
|
import { clip, feedEventsFromStream, systemEvent } from './feed.js';
|
|
142
142
|
import { scrubEnv } from './scrub-env.js';
|
|
143
143
|
import { reportFor } from './status-report.js';
|
|
144
|
-
import { combineChanges, remainingLimits,
|
|
145
|
-
import { assertRestorable,
|
|
144
|
+
import { combineChanges, remainingLimits, startSnapshot, turnChanges } from './turn-changes.js';
|
|
145
|
+
import { assertRestorable, restoreTree } from './rewind-files.js';
|
|
146
146
|
import { sameRepoKey } from './repo-key.js';
|
|
147
147
|
import { AuditLog, AUDIT_OUTCOME, claimedRecord, closedRecord, DAY_MS, nextMidnight, outcomeCode, pruneAudit, rejectedRecord, retentionDays, toolsetSummary } from './audit.js';
|
|
148
148
|
import { mergeShellVerdicts, readShellGuard, readShellLog, readShellNote } from './read-shell-guard.js';
|
|
@@ -200,6 +200,27 @@ const STDERR_TAIL_MAX_CHARS = 4000;
|
|
|
200
200
|
const SHUTDOWN_GRACE_MS = 20_000;
|
|
201
201
|
const EXIT_CODE_SIGINT = 130;
|
|
202
202
|
const EXIT_CODE_SIGTERM = 143;
|
|
203
|
+
// el tope del texto final de un turno (el mismo que el del status en el server).
|
|
204
|
+
const TURN_RESULT_MAX_CHARS = 20_000;
|
|
205
|
+
const finite = (v) => (typeof v === 'number' && Number.isFinite(v) ? v : undefined);
|
|
206
|
+
/** lo que un `result` cuenta de su turno (t#636, fase 3): el total de la sesión, sus vueltas y las tool calls desde `toolCallsAt`. */
|
|
207
|
+
function turnEndedOf(ev, stream, toolCallsAt) {
|
|
208
|
+
const cost = finite(ev.total_cost_usd);
|
|
209
|
+
const turns = finite(ev.num_turns);
|
|
210
|
+
const model = reportedModel(stream.initModel, ev.modelUsage);
|
|
211
|
+
return {
|
|
212
|
+
toolCallsTotal: stream.toolCalls,
|
|
213
|
+
report: {
|
|
214
|
+
...(cost !== undefined ? { costUsd: cost } : {}),
|
|
215
|
+
...(turns !== undefined ? { numTurns: turns } : {}),
|
|
216
|
+
toolCalls: Math.max(0, stream.toolCalls - toolCallsAt),
|
|
217
|
+
...(stream.sessionId ? { sessionId: stream.sessionId } : {}),
|
|
218
|
+
...(model ? { model } : {}),
|
|
219
|
+
...(typeof ev.result === 'string' ? { result: ev.result.slice(0, TURN_RESULT_MAX_CHARS) } : {}),
|
|
220
|
+
...(stream.lastAssistantUuid ? { lastMessageUuid: stream.lastAssistantUuid } : {}),
|
|
221
|
+
},
|
|
222
|
+
};
|
|
223
|
+
}
|
|
203
224
|
// pausa entre long-polls del buzón cuando uno vuelve vacío antes de tiempo (error de red, server que no espera).
|
|
204
225
|
const INBOX_RETRY_MS = 2_000;
|
|
205
226
|
// espera que se corta al abortar (el proceso salió).
|
|
@@ -247,10 +268,9 @@ const localPart = (cfg) => {
|
|
|
247
268
|
async function extraSnapshots(res) {
|
|
248
269
|
const out = [];
|
|
249
270
|
for (const a of res.addDirs.filter((d) => d.checkout)) {
|
|
250
|
-
const
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
out.push({ repo: a.key, dir: a.dir, tree, head });
|
|
271
|
+
const snap = await startSnapshot(a.dir, res.env);
|
|
272
|
+
if (snap !== null && snap.head !== null)
|
|
273
|
+
out.push({ repo: a.key, dir: a.dir, ...snap, head: snap.head });
|
|
254
274
|
}
|
|
255
275
|
return out;
|
|
256
276
|
}
|
|
@@ -263,7 +283,7 @@ export async function withExtraChanges(primary, extras, limits, env) {
|
|
|
263
283
|
const left = remainingLimits(limits, combined);
|
|
264
284
|
// sin sitio en la lista solo cuenta en filesTotal: el patch de un fichero que no sale en ella no lo encontraría nadie.
|
|
265
285
|
const room = left.filesMax === 0 ? { ...left, patchMaxChars: 0 } : left;
|
|
266
|
-
combined = combineChanges([combined, await turnChanges(x.dir, env, x
|
|
286
|
+
combined = combineChanges([combined, await turnChanges(x.dir, env, x, room, x.repo)]);
|
|
267
287
|
}
|
|
268
288
|
return combined;
|
|
269
289
|
}
|
|
@@ -1189,6 +1209,8 @@ export class RunnerDaemon {
|
|
|
1189
1209
|
// mapear, aws_strict) lo pone el recurso aws (resources/aws.ts) y se suelta al cerrar el segmento.
|
|
1190
1210
|
const env = { ...scrubEnv(process.env), AWS_PAGER: '' };
|
|
1191
1211
|
// identidad del proceso en cada llamada del run (servers anteriores a los segmentos: nada).
|
|
1212
|
+
// mutable (t#636, fase 3): al partir un turno dentro del proceso pasa al segmento nuevo, y el latido, el feed y el buzón
|
|
1213
|
+
// lo leen en cada llamada.
|
|
1192
1214
|
const seg = run.segment !== null ? { segment: run.segment } : {};
|
|
1193
1215
|
const heartbeat = this.startHeartbeat(sup, lease, claim.heartbeatMs, seg);
|
|
1194
1216
|
const feed = claim.events?.enabled ? new EventUploader((events) => sup.platform.events(run.id, events, seg), claim.events, tag) : null;
|
|
@@ -1243,15 +1265,28 @@ export class RunnerDaemon {
|
|
|
1243
1265
|
const lockWaitMs = Date.now() - lockStart;
|
|
1244
1266
|
// volver atrás con los ficheros (t#564, ver cabecera): antes de la foto del turno y con el cwd ya tomado.
|
|
1245
1267
|
const restoreError = claim.restore ? await this.restoreFiles(claim, res, note) : null;
|
|
1246
|
-
// diff del turno (t#514, turn-changes.ts): la foto de antes, ya con el turno del cwd tomado.
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1268
|
+
// diff del turno (t#514, turn-changes.ts): la foto de antes, ya con el turno del cwd tomado. y su HEAD (t#564): con la
|
|
1269
|
+
// foto, el punto al que podrá volver este turno. los de los repos adicionales (t#597), si el claim pide su diff.
|
|
1270
|
+
const snapshotStart = async () => {
|
|
1271
|
+
const changesFrom = claim.changes && res.cwd.checkout ? await startSnapshot(res.cwd.dir, res.env) : null;
|
|
1272
|
+
const extraFrom = changesFrom !== null && claim.changes?.extraRepos ? await extraSnapshots(res) : [];
|
|
1273
|
+
const start = changesFrom !== null && changesFrom.head !== null
|
|
1274
|
+
? {
|
|
1275
|
+
startTree: changesFrom.tree,
|
|
1276
|
+
startHead: changesFrom.head,
|
|
1277
|
+
...(extraFrom.length > 0 ? { extraStarts: extraFrom.map(({ repo, tree, head }) => ({ repo, tree, head })) } : {}),
|
|
1278
|
+
}
|
|
1279
|
+
: {};
|
|
1280
|
+
return { changesFrom, extraFrom, start };
|
|
1281
|
+
};
|
|
1282
|
+
// el turno en curso (t#636, fase 3: un proceso vivo puede partir sus turnos): su foto de inicio, las tool calls con las
|
|
1283
|
+
// que empezó y lo que contó el `result` que lo cerró, hasta que el siguiente empiece.
|
|
1284
|
+
const turn = {
|
|
1285
|
+
...(restoreError === null ? await snapshotStart() : { changesFrom: null, extraFrom: [], start: {} }),
|
|
1286
|
+
toolCallsAt: 0,
|
|
1287
|
+
ended: null,
|
|
1288
|
+
chain: Promise.resolve(),
|
|
1289
|
+
};
|
|
1255
1290
|
// mcp-config con el token per-run (run-mcp-config.ts: 0600 en un directorio 0700; se borra al terminar).
|
|
1256
1291
|
let mcpFile = null;
|
|
1257
1292
|
let report;
|
|
@@ -1264,7 +1299,37 @@ export class RunnerDaemon {
|
|
|
1264
1299
|
resourceMcp = await res.mcp();
|
|
1265
1300
|
// la tool de permisos (t#527) junto a los de los recursos: res_<tipo>_<clave> nunca choca con su nombre.
|
|
1266
1301
|
mcpFile = writeRunMcpConfig(run.id, claim.mcp, sup.id, claim.extraMcp, { ...permissionMcpServers(claim), ...resourceMcp.servers });
|
|
1267
|
-
|
|
1302
|
+
// los límites de turno dentro del proceso (t#636, fase 3): con `live.turns` y un cli que acusa los mensajes de stdin.
|
|
1303
|
+
const liveTurns = claim.live?.turns === true && this.claude.supported.has('--input-format') && this.claude.supported.has('--replay-user-messages');
|
|
1304
|
+
const turns = liveTurns
|
|
1305
|
+
? (stream) => ({
|
|
1306
|
+
onTurnEnd: (ev) => {
|
|
1307
|
+
turn.ended = turnEndedOf(ev, stream, turn.toolCallsAt);
|
|
1308
|
+
},
|
|
1309
|
+
onTurnStart: (delivered) => {
|
|
1310
|
+
// lo del turno que acaba se toma YA: el `result` del siguiente puede llegar antes de que el cambio en fila
|
|
1311
|
+
// corra, y lo pisaría. la base de tool calls del turno nuevo, también ya.
|
|
1312
|
+
const ended = turn.ended;
|
|
1313
|
+
const base = turn.toolCallsAt;
|
|
1314
|
+
turn.ended = null;
|
|
1315
|
+
if (ended !== null)
|
|
1316
|
+
turn.toolCallsAt = ended.toolCallsTotal;
|
|
1317
|
+
turn.chain = turn.chain
|
|
1318
|
+
.then(() => this.rollTurn(sup, claim, res, seg, turn, snapshotStart, ended, base, delivered))
|
|
1319
|
+
.catch((err) => console.error(`${log} ${tag}: cambio de turno: ${err.message}`));
|
|
1320
|
+
},
|
|
1321
|
+
onDelivered: (ids) => {
|
|
1322
|
+
if (seg.segment !== undefined)
|
|
1323
|
+
void sup.platform.delivered?.(run.id, { segment: seg.segment, ids });
|
|
1324
|
+
},
|
|
1325
|
+
})
|
|
1326
|
+
: null;
|
|
1327
|
+
({ report, attempt } = await this.runAttempts(sup, withResourceTools(claim, resourceMcp), lease, res, mcpFile, feed, ctx, note, seg, { turns, toolCallsAt: () => turn.toolCallsAt }));
|
|
1328
|
+
// un cambio de turno en vuelo termina antes del cierre: el informe es del último turno.
|
|
1329
|
+
await turn.chain;
|
|
1330
|
+
// las tool calls del último turno (el proceso las cuenta desde que empezó).
|
|
1331
|
+
if (turn.toolCallsAt > 0 && report.toolCalls !== undefined)
|
|
1332
|
+
report = { ...report, toolCalls: Math.max(0, report.toolCalls - turn.toolCallsAt) };
|
|
1268
1333
|
}
|
|
1269
1334
|
catch (err) {
|
|
1270
1335
|
report = { status: 'failed', error: err === restoreError || resourceMcp !== null ? err.message : legacyResourceError(err) };
|
|
@@ -1288,8 +1353,8 @@ export class RunnerDaemon {
|
|
|
1288
1353
|
}
|
|
1289
1354
|
// la foto de después y su diff, antes de soltar los recursos (el worktree puede borrarse) y con el cwd aún tomado; los
|
|
1290
1355
|
// de los repos adicionales detrás, con los topes que queden (t#597).
|
|
1291
|
-
const primaryChanges = changesFrom !== null && claim.changes ? await turnChanges(res.cwd.dir, res.env, changesFrom, claim.changes) : null;
|
|
1292
|
-
const changes = claim.changes ? await withExtraChanges(primaryChanges, extraFrom, claim.changes, res.env) : primaryChanges;
|
|
1356
|
+
const primaryChanges = turn.changesFrom !== null && claim.changes ? await turnChanges(res.cwd.dir, res.env, turn.changesFrom, claim.changes) : null;
|
|
1357
|
+
const changes = claim.changes ? await withExtraChanges(primaryChanges, turn.extraFrom, claim.changes, res.env) : primaryChanges;
|
|
1293
1358
|
// los recursos se sueltan (el worktree se marca o se borra) ANTES de reportar: ver cabecera. y con sus
|
|
1294
1359
|
// turnos aún tomados: un recurso exclusivo se suelta entero antes de que lo reciba el siguiente run.
|
|
1295
1360
|
// un recurso que no se pudo preparar: nada se lanzó, se suelta todo como aborted (sin devolver nada al vault).
|
|
@@ -1301,7 +1366,7 @@ export class RunnerDaemon {
|
|
|
1301
1366
|
await sup.platform.changes?.(run.id, changes, seg);
|
|
1302
1367
|
const code = restoreError !== null ? AUDIT_OUTCOME.runnerError : resourceMcp === null ? AUDIT_OUTCOME.resourceUnavailable : outcomeCode(report.status, attempt && attemptFacts(attempt));
|
|
1303
1368
|
audited({ lockWaitMs, materialized: res.resources, report, toolsByName: attempt?.stream.toolsByName ?? {}, code });
|
|
1304
|
-
await sup.platform.result(run.id, { ...report, ...start, ...withShadow, ...seg });
|
|
1369
|
+
await sup.platform.result(run.id, { ...report, ...turn.start, ...withShadow, ...seg });
|
|
1305
1370
|
console.log(`${log} ${tag} terminado (${report.status}${report.error ? `: ${report.error}` : ''})`);
|
|
1306
1371
|
void this.syncSlashCommands(sup);
|
|
1307
1372
|
}
|
|
@@ -1417,7 +1482,7 @@ export class RunnerDaemon {
|
|
|
1417
1482
|
}
|
|
1418
1483
|
// uno o dos intentos: reanudación fallida antes de que el asistente hablara (sesión inexistente
|
|
1419
1484
|
// en esta máquina, borrada, de otro daemon) → un solo reintento desde cero con el prompt de respaldo.
|
|
1420
|
-
async runAttempts(sup, claim, lease, res, mcpFile, feed, ctx, note) {
|
|
1485
|
+
async runAttempts(sup, claim, lease, res, mcpFile, feed, ctx, note, seg, turnsOf) {
|
|
1421
1486
|
const { run } = claim;
|
|
1422
1487
|
// settings leídos por run (pueden cambiar con el daemon vivo): lectura solo carga los de usuario y
|
|
1423
1488
|
// espeja su shell y su escritura; un run de reglas carga todos y espeja su escritura; edición, nada.
|
|
@@ -1462,16 +1527,17 @@ export class RunnerDaemon {
|
|
|
1462
1527
|
addDirs: res.addDirs.map((a) => a.dir),
|
|
1463
1528
|
readOnlyDirsDeny: readOnlyDeny,
|
|
1464
1529
|
liveInput: live !== null,
|
|
1530
|
+
liveTurns: live !== null && turnsOf.turns !== null,
|
|
1465
1531
|
});
|
|
1466
1532
|
// reanudar o no lo decide el server: manda sessionId solo cuando hay sesión que retomar.
|
|
1467
1533
|
const resume = run.sessionId;
|
|
1468
|
-
const liveOf = (prompt) => (live ? { prompt, waitMs: live.waitMs } : null);
|
|
1469
|
-
let attempt = await this.spawnClaude(sup, claim, lease, args(claim.prompt, resume), res, feed, ctx, liveOf(claim.prompt));
|
|
1534
|
+
const liveOf = (prompt) => (live ? { prompt, waitMs: live.waitMs, turns: turnsOf.turns } : null);
|
|
1535
|
+
let attempt = await this.spawnClaude(sup, claim, lease, args(claim.prompt, resume), res, feed, ctx, seg, turnsOf.toolCallsAt, liveOf(claim.prompt));
|
|
1470
1536
|
let resumed = resume ? true : undefined;
|
|
1471
1537
|
if (resume && attempt.killedBy === null && attempt.exitCode !== 0 && !attempt.stream.sawAssistant && claim.fallbackPrompt) {
|
|
1472
1538
|
console.log(`${this.tagOf(sup)} run ${run.id}: la sesión ${resume} no se pudo reanudar`);
|
|
1473
1539
|
note('la sesión anterior no se pudo reanudar en este runner: reintento desde cero');
|
|
1474
|
-
attempt = await this.spawnClaude(sup, claim, lease, args(claim.fallbackPrompt, null), res, feed, ctx, liveOf(claim.fallbackPrompt));
|
|
1540
|
+
attempt = await this.spawnClaude(sup, claim, lease, args(claim.fallbackPrompt, null), res, feed, ctx, seg, turnsOf.toolCallsAt, liveOf(claim.fallbackPrompt));
|
|
1475
1541
|
resumed = false;
|
|
1476
1542
|
}
|
|
1477
1543
|
return { report: reportFor(attempt, resumed), attempt };
|
|
@@ -1480,9 +1546,8 @@ export class RunnerDaemon {
|
|
|
1480
1546
|
// y stderr (tail), bombea el progreso y aplica el timeout wall-clock. si el run ya murió (cancel o
|
|
1481
1547
|
// parada mientras esperaba turno) no lo lanza. resuelve siempre (nunca rechaza). con `live` (t#636, fase 2) el prompt
|
|
1482
1548
|
// va por stdin, que sigue abierto mientras haga falta (live-session.ts), y atiende el buzón del run mientras vive.
|
|
1483
|
-
spawnClaude(sup, claim, lease, args, res, feed, ctx, live = null) {
|
|
1549
|
+
spawnClaude(sup, claim, lease, args, res, feed, ctx, seg, toolCallsAt, live = null) {
|
|
1484
1550
|
const runId = claim.run.id;
|
|
1485
|
-
const seg = claim.run.segment !== null ? { segment: claim.run.segment } : {};
|
|
1486
1551
|
if (lease.killedBy)
|
|
1487
1552
|
return Promise.resolve({ exitCode: null, killedBy: lease.killedBy, stream: newStreamState(), stderrTail: '' });
|
|
1488
1553
|
return new Promise((resolve) => {
|
|
@@ -1523,7 +1588,7 @@ export class RunnerDaemon {
|
|
|
1523
1588
|
killTimer = setTimeout(() => signalGroup(child, 'SIGKILL'), KILL_GRACE_MS);
|
|
1524
1589
|
};
|
|
1525
1590
|
lease.attach(child, kill);
|
|
1526
|
-
const session = live && child.stdin ? new LiveSession(child.stdin) : null;
|
|
1591
|
+
const session = live && child.stdin ? new LiveSession(child.stdin, undefined, live.turns?.(stream) ?? null) : null;
|
|
1527
1592
|
const inboxAbort = new AbortController();
|
|
1528
1593
|
if (session && live) {
|
|
1529
1594
|
session.start(live.prompt);
|
|
@@ -1551,9 +1616,11 @@ export class RunnerDaemon {
|
|
|
1551
1616
|
let lastProgressAt = Date.now();
|
|
1552
1617
|
const progress = setInterval(() => {
|
|
1553
1618
|
const now = Date.now();
|
|
1554
|
-
|
|
1619
|
+
// las del turno en curso (t#636, fase 3: el proceso puede haber partido turnos).
|
|
1620
|
+
const turnCalls = stream.toolCalls - toolCallsAt();
|
|
1621
|
+
if (turnCalls === reportedToolCalls || now - lastProgressAt < PROGRESS_MIN_INTERVAL_MS)
|
|
1555
1622
|
return;
|
|
1556
|
-
reportedToolCalls =
|
|
1623
|
+
reportedToolCalls = turnCalls;
|
|
1557
1624
|
lastProgressAt = now;
|
|
1558
1625
|
this.postProgress(sup, runId, reportedToolCalls, seg);
|
|
1559
1626
|
}, PROGRESS_TICK_MS);
|
|
@@ -1587,6 +1654,36 @@ export class RunnerDaemon {
|
|
|
1587
1654
|
});
|
|
1588
1655
|
});
|
|
1589
1656
|
}
|
|
1657
|
+
// parte el turno dentro del proceso vivo (t#636, fase 3): el diff del que acaba con su segmento, la foto del que empieza y
|
|
1658
|
+
// POST …/turn; con el segmento nuevo, el latido, el feed y el buzón siguen con él. el server que no lo parte (null) deja
|
|
1659
|
+
// todo como estaba: el cierre lo contará como un solo turno.
|
|
1660
|
+
async rollTurn(sup, claim, res, seg, turn, snapshotStart, ended, base, delivered) {
|
|
1661
|
+
const runId = claim.run.id;
|
|
1662
|
+
const from = seg.segment;
|
|
1663
|
+
if (ended === null || from === undefined || !sup.platform.turn) {
|
|
1664
|
+
turn.toolCallsAt = base;
|
|
1665
|
+
if (delivered.length > 0 && from !== undefined)
|
|
1666
|
+
await sup.platform.delivered?.(runId, { segment: from, ids: delivered });
|
|
1667
|
+
return;
|
|
1668
|
+
}
|
|
1669
|
+
if (turn.changesFrom !== null && claim.changes) {
|
|
1670
|
+
const primary = await turnChanges(res.cwd.dir, res.env, turn.changesFrom, claim.changes);
|
|
1671
|
+
const changes = await withExtraChanges(primary, turn.extraFrom, claim.changes, res.env);
|
|
1672
|
+
if (changes !== null)
|
|
1673
|
+
await sup.platform.changes?.(runId, changes, seg);
|
|
1674
|
+
}
|
|
1675
|
+
const next = await snapshotStart();
|
|
1676
|
+
const out = await sup.platform.turn(runId, { segment: from, report: { ...ended.report, ...turn.start }, delivered });
|
|
1677
|
+
// sin partir (un server que no lo acepta): todo cuenta como un turno, también sus tool calls.
|
|
1678
|
+
if (out === null) {
|
|
1679
|
+
turn.toolCallsAt = base;
|
|
1680
|
+
return;
|
|
1681
|
+
}
|
|
1682
|
+
seg.segment = out.segment;
|
|
1683
|
+
turn.changesFrom = next.changesFrom;
|
|
1684
|
+
turn.extraFrom = next.extraFrom;
|
|
1685
|
+
turn.start = next.start;
|
|
1686
|
+
}
|
|
1590
1687
|
// el buzón del proceso vivo (t#636, fase 2): long-poll mientras stdin siga abierto; cada orden va al proceso. un fallo de
|
|
1591
1688
|
// red espera y reintenta; un run que ya no las acepta (null) deja de pedir.
|
|
1592
1689
|
async pollInbox(sup, runId, seg, waitMs, session, signal) {
|