zelio-cli 0.1.0-beta.8 → 0.1.0-beta.9

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 (67) hide show
  1. package/README.md +2 -0
  2. package/dist/cli-main.js +521 -0
  3. package/dist/cli-main.js.map +1 -0
  4. package/dist/cli.js +17 -495
  5. package/dist/cli.js.map +1 -1
  6. package/dist/cloud/account.js +109 -0
  7. package/dist/cloud/account.js.map +1 -0
  8. package/dist/cloud/command.js +4 -20
  9. package/dist/cloud/command.js.map +1 -1
  10. package/dist/cloud/login.js +2 -1
  11. package/dist/cloud/login.js.map +1 -1
  12. package/dist/db/db.js +42 -15
  13. package/dist/db/db.js.map +1 -1
  14. package/dist/db/lifecycle.js.map +1 -1
  15. package/dist/limits.js +1 -1
  16. package/dist/orchestrator/contract.js +4 -0
  17. package/dist/orchestrator/contract.js.map +1 -1
  18. package/dist/orchestrator/pi-session.js +6 -0
  19. package/dist/orchestrator/pi-session.js.map +1 -1
  20. package/dist/orchestrator/runtime.js +8 -0
  21. package/dist/orchestrator/runtime.js.map +1 -1
  22. package/dist/repo/linked-boards.js +12 -0
  23. package/dist/repo/linked-boards.js.map +1 -1
  24. package/dist/run/auto-review.js +17 -3
  25. package/dist/run/auto-review.js.map +1 -1
  26. package/dist/run/claude-runtime.js +17 -3
  27. package/dist/run/claude-runtime.js.map +1 -1
  28. package/dist/run/codex-client.js +14 -3
  29. package/dist/run/codex-client.js.map +1 -1
  30. package/dist/run/codex-runtime.js +1 -1
  31. package/dist/run/codex-runtime.js.map +1 -1
  32. package/dist/run/consult.js +5 -1
  33. package/dist/run/consult.js.map +1 -1
  34. package/dist/run/developer-sandbox.js +67 -0
  35. package/dist/run/developer-sandbox.js.map +1 -0
  36. package/dist/run/finish.js +34 -12
  37. package/dist/run/finish.js.map +1 -1
  38. package/dist/run/harnesses.js +15 -0
  39. package/dist/run/harnesses.js.map +1 -1
  40. package/dist/run/lead.js +25 -1
  41. package/dist/run/lead.js.map +1 -1
  42. package/dist/run/manager.js +199 -28
  43. package/dist/run/manager.js.map +1 -1
  44. package/dist/run/pi-packages.js +72 -0
  45. package/dist/run/pi-packages.js.map +1 -0
  46. package/dist/run/pi-rpc.js +30 -5
  47. package/dist/run/pi-rpc.js.map +1 -1
  48. package/dist/run/prompt.js +17 -0
  49. package/dist/run/prompt.js.map +1 -1
  50. package/dist/run/settings.js.map +1 -1
  51. package/dist/run/watchdog.js +12 -5
  52. package/dist/run/watchdog.js.map +1 -1
  53. package/dist/server/app.js +122 -88
  54. package/dist/server/app.js.map +1 -1
  55. package/dist/setup/config.js +0 -31
  56. package/dist/setup/config.js.map +1 -1
  57. package/dist/setup/onboarding.js +0 -9
  58. package/dist/setup/onboarding.js.map +1 -1
  59. package/dist/setup/run.js +4 -5
  60. package/dist/setup/run.js.map +1 -1
  61. package/dist/web/assets/index-D48AtOGe.js +258 -0
  62. package/dist/web/assets/index-TN5sUF2z.css +1 -0
  63. package/dist/web/index.html +2 -2
  64. package/dist/web/sw.js +1 -1
  65. package/package.json +3 -2
  66. package/dist/web/assets/index-C-Gz9qIz.css +0 -1
  67. package/dist/web/assets/index-DQEP5F30.js +0 -255
@@ -10,6 +10,7 @@ import { captureRunFacts, captureWorktree, commitAttempt, worktreeHead, worktree
10
10
  import { buildTicketPrompt, CODING_AGENT_PROMPT, commandTimingsSection, RESUME_PROMPT, VERIFIED_CODING_AGENT_PROMPT, VERIFIED_RESUME_PROMPT, withExtraInstructions, } from "./prompt.js";
11
11
  import { readRepoInstructions } from "../repo/instructions.js";
12
12
  import { buildDeveloperContextPack } from "./context.js";
13
+ import { modelFitsHarness } from "./harnesses.js";
13
14
  import { profileFor } from "./profiles.js";
14
15
  import { chosenSkills, readSkills, skillStoreOf } from "./skills.js";
15
16
  import { commentActionsFor, wasteSignalDetails } from "./retro.js";
@@ -19,7 +20,7 @@ import { evidenceRevision } from "./evidence.js";
19
20
  import { resultComment } from "./result.js";
20
21
  import { stripWorktreeCd } from "./actions.js";
21
22
  import { pipedEvidence, unpipedCommand } from "./piped-check.js";
22
- import { commitTicketWork, failureReport, hasTicketChanges, publishBranch, runChecks, ticketDiff, worktreeFingerprint, } from "./finish.js";
23
+ import { commitTicketWork, failureReport, hasTicketChanges, publishBranch, runChecks, ticketDiff, ticketDiffWithBase, worktreeFingerprint, } from "./finish.js";
23
24
  import { MAX_WATCHDOG_CHECKS, MAX_WATCHDOG_STEERS, STEER_HEADING, WATCHDOG_BACKSTOP_MS, WATCHDOG_COOLDOWN_TICKS, WATCHDOG_TICK_MS, callLines, lookLabel, watchdogSignals, watchdogSummary, } from "./watchdog.js";
24
25
  import { MAX_AUTO_REVIEWS } from "./auto-review.js";
25
26
  import { isTestPath, redCheck, ticketChanges } from "./red-check.js";
@@ -28,7 +29,24 @@ const execFileAsync = promisify(execFile);
28
29
  /** How a review that sent the work back starts its board comment; the count reads it. */
29
30
  export const REVIEW_CHANGES_HEADING = "Automatic review: changes needed before Review.";
30
31
  /** Sent to the developer with the reviewer's findings, the way a failed check's output is. */
31
- export const REVIEW_CHANGES_PROMPT = `The board's checks pass, but the automatic review found that the work does not yet give the person what they asked for. The checks are the minimum; done means the person gets what they asked for. Read the findings below, open the ticket's screenshots if it has any, make the change, and end your turn when it is done. Do not argue with a finding by restating the acceptance: if a finding is wrong, say why in your reply and change nothing for it.`;
32
+ export const REVIEW_CHANGES_PROMPT = `The board's checks pass, but the automatic review found that the work does not yet give the person what they asked for. The checks are the minimum; done means the person gets what they asked for.
33
+
34
+ Before changing code, reproduce each finding against the ticket's own diff. The board names the commit it reviewed when it knows it; the branch can also carry commits that were already on main before this ticket started, and those are not this ticket's work to revert. If a finding describes files this run did not change, say so with the diff you checked and leave them alone.
35
+
36
+ Read the findings below, open the ticket's screenshots if it has any, make the rest of the change, and end your turn when it is done. Do not argue with a finding by restating the acceptance: if a finding is wrong, say why in your reply and change nothing for it.`;
37
+ /** The line that names the commit a review's findings were read from. */
38
+ function reviewBaseNote(base) {
39
+ return base
40
+ ? `\n\nReviewed against ${base}: \`git diff ${base}...HEAD\` shows only this ticket's change.`
41
+ : "";
42
+ }
43
+ /** A review comment's findings, without the diff-base note the board appends. */
44
+ function reviewFindings(text) {
45
+ return text
46
+ .slice(REVIEW_CHANGES_HEADING.length)
47
+ .replace(/\n\nReviewed against [0-9a-f]+: `git diff [0-9a-f]+\.\.\.HEAD` shows only this ticket's change\.$/, "")
48
+ .trim();
49
+ }
32
50
  /** Sent when the ticket's checks also pass on the code before the change; the test files it copied are named after it. */
33
51
  export const RED_CHECK_PROMPT = "The board's checks pass, but they also pass on the code before your change, with your test changes copied in. So they do not test what the ticket asks for. Add or extend tests that fail without your change and pass with it, one for each acceptance criterion including its failure case, then end your turn. Do not weaken or delete existing assertions. If the ticket is a refactor that must not change behaviour, say so in your reply and end your turn without new tests.";
34
52
  /** Sent when a run that was asked for a change ends without changing the worktree. */
@@ -43,6 +61,21 @@ export function developerCheckPassed(command, evidence, inFlightCommands, curren
43
61
  const latest = evidence.findLast((item) => item.command === normalized);
44
62
  return latest?.outcome === "passed" && latest.revision === currentRevision;
45
63
  }
64
+ /** Two consecutive failures of the same Verify command on known identical work. */
65
+ export function repeatedVerifyFailure(verify, evidence) {
66
+ const commands = new Set(verify.map((check) => stripWorktreeCd(check.command)));
67
+ for (const command of commands) {
68
+ const matching = evidence.filter((item) => item.command === command);
69
+ const last = matching.at(-1);
70
+ const previous = matching.at(-2);
71
+ if (last?.outcome === "failed" &&
72
+ previous?.outcome === "failed" &&
73
+ last.revision !== null &&
74
+ last.revision === previous.revision)
75
+ return last;
76
+ }
77
+ return undefined;
78
+ }
46
79
  export class RunAlreadyActiveError extends Error {
47
80
  constructor(ticketId) {
48
81
  super(`${ticketId} is already running`);
@@ -430,9 +463,10 @@ export class RunManager {
430
463
  return started ? (this.statuses.get(ticket.id) ?? null) : null;
431
464
  }
432
465
  /**
433
- * Starts a run once the model list it needs is read. Only a developer run on
434
- * the harness that names the card's model needs the list; every other run
435
- * starts at once with `start`.
466
+ * Starts a run once the model it will use is checked against the harness's
467
+ * list. A model the harness does not list never reaches the harness: the
468
+ * ticket blocks with the reason instead. Only a run with a model needs the
469
+ * list; every other run starts at once with `start`.
436
470
  */
437
471
  async begin(ticket, worktree, attempt = 1, job) {
438
472
  const profileName = job?.profile ?? ticket.profile ?? "developer";
@@ -440,16 +474,98 @@ export class RunManager {
440
474
  const defaults = this.defaults();
441
475
  const profileHarness = profile.harness.trim() || defaults.harness;
442
476
  const command = job?.command?.trim() ||
477
+ (profileName === "developer" ? ticket.developer_harness?.trim() : "") ||
443
478
  (this.plannerChoiceEnabled() && profileName === "developer" && ticket.planner_harness?.trim()
444
479
  ? ticket.planner_harness.trim()
445
480
  : profileHarness);
446
- const cardOnHarness = this.plannerChoiceEnabled() &&
481
+ const cardOnHarness = (this.plannerChoiceEnabled() || Boolean(ticket.developer_harness?.trim())) &&
447
482
  profileName === "developer" &&
448
- command === (ticket.planner_harness?.trim() || profileHarness) &&
483
+ command ===
484
+ (ticket.developer_harness?.trim() || ticket.planner_harness?.trim() || profileHarness) &&
449
485
  Boolean(ticket.model?.trim());
450
- const models = cardOnHarness ? await this.modelsOf(command) : undefined;
486
+ // The same choice `start` makes for the model it passes on.
487
+ const profileModel = command === profileHarness ? profile.model.trim() : "";
488
+ const defaultModel = command === defaults.harness ? defaults.model.trim() : "";
489
+ const requested = job?.model !== undefined
490
+ ? { model: job.model.trim(), from: "planner" }
491
+ : cardOnHarness
492
+ ? { model: ticket.model?.trim() ?? "", from: "card" }
493
+ : profileModel
494
+ ? { model: profileModel, from: "agent" }
495
+ : { model: defaultModel, from: "default" };
496
+ if (requested.model === "")
497
+ return this.start(ticket, worktree, attempt, job);
498
+ const models = await this.modelsOf(command);
499
+ if (!modelFitsHarness(command, requested.model, models)) {
500
+ return this.refuseModel(ticket, { command, ...requested }, attempt, job);
501
+ }
451
502
  return this.start(ticket, worktree, attempt, job, models);
452
503
  }
504
+ /**
505
+ * A model the harness does not list fails there, or is dropped without a word.
506
+ * The ticket blocks with the reason, and no process starts. Only an in-progress
507
+ * ticket blocks; a conflict repair from Review just reports the failure.
508
+ */
509
+ refuseModel(ticket, request, attempt, job) {
510
+ const profile = job?.profile ?? ticket.profile ?? "developer";
511
+ // Each source has one place to fix it. The planner's pick on the card is
512
+ // cleared here, so the next run falls back to the agent instead of
513
+ // refusing again: there is nowhere to edit a card's model once it exists.
514
+ const missing = `Model "${request.model}" isn't available on ${request.command}`;
515
+ const advice = {
516
+ card: {
517
+ text: `${missing}. It was the planner's pick for this card, so it was removed from the card.`,
518
+ unblock: `Mention @developer to continue on the developer agent's model, or pick one in Edit agents first.`,
519
+ },
520
+ agent: {
521
+ text: `${missing}. It is the ${profile} agent's model.`,
522
+ unblock: `Pick another model for the ${profile} in Edit agents, then mention @${profile} to continue.`,
523
+ },
524
+ default: {
525
+ text: `${missing}. It is the default developer model.`,
526
+ unblock: `Pick a model for the developer in Edit agents, then mention @developer to continue.`,
527
+ },
528
+ planner: {
529
+ text: `${missing}. It is the planner's model, which the ${profile} runs on.`,
530
+ unblock: `Pick another planner model in New task, then mention @${profile} again.`,
531
+ },
532
+ }[request.from];
533
+ const text = advice.text;
534
+ const record = this.db.startAgentRun(ticket.id, attempt, null, {
535
+ profile,
536
+ harness: request.command,
537
+ model: request.model,
538
+ source: job?.source ?? "ticket",
539
+ });
540
+ this.finishRecord(record.id, "failed", null, null, null, text);
541
+ const failed = {
542
+ ticketId: ticket.id,
543
+ runId: record.id,
544
+ label: "Run failed",
545
+ tool: null,
546
+ startedAt: Date.now(),
547
+ endedAt: Date.now(),
548
+ phase: "failed",
549
+ profile,
550
+ attempt,
551
+ attempts: this.retry.maxAttempts,
552
+ tail: [],
553
+ error: text,
554
+ };
555
+ this.statuses.set(ticket.id, failed);
556
+ this.onStatus(failed);
557
+ if (this.db.getTicket(ticket.id)?.state === "in_progress") {
558
+ this.db.transition(ticket.id, "blocked", {
559
+ blocker_kind: "needs_human",
560
+ blocker_reason: text,
561
+ blocker_unblock: advice.unblock,
562
+ ...(request.from === "planner" ? {} : { blocker_action: "edit_agents" }),
563
+ ...(request.from === "card" ? { model: null } : {}),
564
+ });
565
+ this.db.addComment({ ticket_id: ticket.id, type: "system", author: "zelio", text });
566
+ }
567
+ return failed;
568
+ }
453
569
  async modelsOf(command) {
454
570
  return Promise.resolve()
455
571
  .then(() => this.listModels(command))
@@ -479,6 +595,7 @@ export class RunManager {
479
595
  const profile = this.db.getProfile(resolvedJob.profile) ?? profileFor(resolvedJob.profile);
480
596
  const defaults = this.defaults();
481
597
  const command = resolvedJob.command?.trim() ||
598
+ (resolvedJob.profile === "developer" ? ticket.developer_harness?.trim() : "") ||
482
599
  (this.plannerChoiceEnabled() &&
483
600
  resolvedJob.profile === "developer" &&
484
601
  ticket.planner_harness?.trim()
@@ -491,15 +608,22 @@ export class RunManager {
491
608
  // developer run on that harness, and only if that harness lists it. Anything
492
609
  // else runs on the default model, which is the one the board records. The
493
610
  // person's switch decides whether the planner's choice applies at all.
494
- const cardModel = this.plannerChoiceEnabled() &&
611
+ const cardModel = (this.plannerChoiceEnabled() || Boolean(ticket.developer_harness?.trim())) &&
495
612
  resolvedJob.profile === "developer" &&
496
- command === (ticket.planner_harness?.trim() || profileHarness) &&
497
- models?.includes(ticket.model?.trim() ?? "")
613
+ command ===
614
+ (ticket.developer_harness?.trim() || ticket.planner_harness?.trim() || profileHarness) &&
615
+ models !== undefined &&
616
+ models.length > 0 &&
617
+ modelFitsHarness(command, ticket.model?.trim() ?? "", models)
498
618
  ? (ticket.model?.trim() ?? "")
499
619
  : "";
500
- const model = cardModel ||
501
- (command === profileHarness ? profile.model.trim() : "") ||
502
- (command === defaults.harness ? defaults.model : "");
620
+ // A job that names its model (the reviewer's planner setup) uses exactly
621
+ // that; an empty one means the harness default, never the profile's.
622
+ const model = resolvedJob.model !== undefined
623
+ ? resolvedJob.model.trim()
624
+ : cardModel ||
625
+ (command === profileHarness ? profile.model.trim() : "") ||
626
+ (command === defaults.harness ? defaults.model : "");
503
627
  // A pi run can seed its own session id before the process starts. Codex
504
628
  // returns a thread id instead, so its row stays open until that arrives.
505
629
  const seedId = !this.runtime.sessionIdFromHarness?.(command);
@@ -637,7 +761,7 @@ export class RunManager {
637
761
  : resolvedJob.prompt;
638
762
  run = this.runtime.spawn(worktree.path, prompt, {
639
763
  env,
640
- thinking: ticket.thinking ?? profile.thinking,
764
+ thinking: resolvedJob.thinking ?? ticket.thinking ?? profile.thinking,
641
765
  model: model || undefined,
642
766
  command,
643
767
  readOnly: !profile.touchesRepo,
@@ -887,9 +1011,12 @@ export class RunManager {
887
1011
  const missingDeveloperChecks = ticket.verify.filter((check) => !developerCheckPassed(check.command, active.developerCommandEvidence, inFlightCommands, currentRevision));
888
1012
  if (missingDeveloperChecks.length) {
889
1013
  const commands = missingDeveloperChecks.map((check) => `\`${check.command}\``).join(", ");
1014
+ const repeated = repeatedVerifyFailure(missingDeveloperChecks, active.developerCommandEvidence);
890
1015
  return this.failRound(ticketId, runId, active, final, {
891
1016
  handoffOnly: true,
892
- prompt: `Before handing this ticket to the board, run and finish these Verify commands yourself, each in its own shell call and exactly as written, without piping the output through tail, head or grep: ${commands}. The board will wait for your checks before its next verification. A command that is still running, failed, or passed before your latest edits does not count. If the shell returns a session id, keep reading that same session until it exits, then fix any failure and run the command again.`,
1017
+ prompt: repeated
1018
+ ? `The Verify command \`${repeated.command}\` failed twice on unchanged work. Do not simply rerun it. Inspect the failure output, failing test, setup and relevant code; identify the cause or missing evidence first. Stay within the ticket's authorization. Before handing this ticket to the board, finish these Verify commands yourself, each in its own shell call and exactly as written: ${commands}.`
1019
+ : `Before handing this ticket to the board, run and finish these Verify commands yourself, each in its own shell call and exactly as written, without piping the output through tail, head or grep: ${commands}. The board will wait for your checks before its next verification. A command that is still running, failed, or passed before your latest edits does not count. If the shell returns a session id, keep reading that same session until it exits, then fix any failure and run the command again.`,
893
1020
  summary: `the developer did not finish Verify: ${missingDeveloperChecks.map((check) => check.label).join(", ")}`,
894
1021
  blocked: {
895
1022
  summary: `The developer did not finish the ticket's Verify command after ${MAX_VERIFY_ROUNDS} handoff attempts.`,
@@ -1222,6 +1349,7 @@ export class RunManager {
1222
1349
  outOfScope: ticket.out_of_scope,
1223
1350
  acceptance: ticket.acceptance,
1224
1351
  context: [...(ticket.context ?? [])],
1352
+ plan: ticket.plan ?? null,
1225
1353
  screenshots: absoluteAttachments(this.repoRoot, ticket.attachments),
1226
1354
  diff,
1227
1355
  round,
@@ -1277,13 +1405,14 @@ export class RunManager {
1277
1405
  .filter((comment) => comment.author === "reviewer" &&
1278
1406
  comment.type === "review" &&
1279
1407
  comment.text.startsWith(REVIEW_CHANGES_HEADING))
1280
- .map((comment) => comment.text.slice(REVIEW_CHANGES_HEADING.length).trim());
1408
+ .map((comment) => reviewFindings(comment.text));
1281
1409
  if (earlier.length >= MAX_AUTO_REVIEWS) {
1282
1410
  note(`The automatic review sent this ticket back ${MAX_AUTO_REVIEWS} times; it goes to Review for you to decide, with the last findings above.`);
1283
1411
  return null;
1284
1412
  }
1285
1413
  const round = earlier.length + 1;
1286
1414
  this.update(ticketId, active, { label: "Reviewing against the request", tool: null });
1415
+ const change = await ticketDiffWithBase(active.worktreePath);
1287
1416
  let verdict = null;
1288
1417
  try {
1289
1418
  verdict = await reviewer({
@@ -1293,8 +1422,10 @@ export class RunManager {
1293
1422
  outOfScope: ticket.out_of_scope,
1294
1423
  acceptance: ticket.acceptance,
1295
1424
  context: [...(ticket.context ?? [])],
1425
+ plan: ticket.plan ?? null,
1296
1426
  screenshots: absoluteAttachments(this.repoRoot, ticket.attachments),
1297
- diff: await ticketDiff(active.worktreePath),
1427
+ diff: change.diff,
1428
+ diffBase: change.base,
1298
1429
  round,
1299
1430
  earlier,
1300
1431
  worktreePath: active.worktreePath,
@@ -1323,11 +1454,11 @@ export class RunManager {
1323
1454
  ticket_id: ticketId,
1324
1455
  type: "review",
1325
1456
  author: "reviewer",
1326
- text: `${REVIEW_CHANGES_HEADING}\n\n${verdict.findings}`,
1457
+ text: `${REVIEW_CHANGES_HEADING}\n\n${verdict.findings}${reviewBaseNote(change.base)}`,
1327
1458
  });
1328
1459
  return {
1329
1460
  kind: "continue",
1330
- prompt: `${REVIEW_CHANGES_PROMPT}\n\n## Review findings\n\n${verdict.findings}`,
1461
+ prompt: `${REVIEW_CHANGES_PROMPT}\n\n## Review findings\n\n${verdict.findings}${reviewBaseNote(change.base)}`,
1331
1462
  summary: "the automatic review asked for changes",
1332
1463
  label: `Addressing review (round ${round}/${MAX_AUTO_REVIEWS})`,
1333
1464
  };
@@ -1445,6 +1576,14 @@ export class RunManager {
1445
1576
  likelyFiles: ticket.likely_files,
1446
1577
  worktreePath: worktree.path,
1447
1578
  });
1579
+ const repeated = repeatedVerifyFailure(ticket.verify, active.developerCommandEvidence);
1580
+ if (repeated && repeated.id !== dog.repeatFailureId) {
1581
+ signals.push({
1582
+ kind: "repeating",
1583
+ text: `Verify command "${repeated.command}" failed twice on unchanged work; investigate before rerunning`,
1584
+ });
1585
+ dog.repeatFailureId = repeated.id;
1586
+ }
1448
1587
  const now = Date.now();
1449
1588
  const due = now - dog.lastCheckAt >= (watchdog.backstopMs ?? WATCHDOG_BACKSTOP_MS);
1450
1589
  if (signals.length === 0 && !due)
@@ -2048,7 +2187,11 @@ export class RunManager {
2048
2187
  outcome: callFailed ? "failed" : "passed",
2049
2188
  revision: null,
2050
2189
  };
2051
- if (!callFailed && canUseAgentEvidence) {
2190
+ const isVerify = currentTicket?.verify.some((check) => {
2191
+ const command = stripWorktreeCd(check.command);
2192
+ return command === stripWorktreeCd(call.command) || command === piped?.command;
2193
+ });
2194
+ if (canUseAgentEvidence && (!callFailed || isVerify)) {
2052
2195
  const pending = evidenceRevision(worktree.path);
2053
2196
  active.evidencePending = pending;
2054
2197
  try {
@@ -2384,6 +2527,14 @@ export class RunManager {
2384
2527
  if (!lead || !current || current.state !== "in_progress" || this.active.has(ticketId))
2385
2528
  return;
2386
2529
  try {
2530
+ const failedCall = this.db
2531
+ .listToolCalls(active.status.runId)
2532
+ .findLast((call) => call.tool === "bash" && call.state === "failed" && call.output?.trim());
2533
+ const captured = failedCall?.output
2534
+ ? `Latest failed developer command: ${failedCall.detail}\nCaptured output (tail):\n${failedCall.output.slice(-3000)}`
2535
+ : "";
2536
+ const failure = [request.failure.slice(-3000), captured].filter(Boolean).join("\n\n");
2537
+ const enrichedRequest = { ...request, failure };
2387
2538
  const consult = this.leadConsults(ticketId) + 1;
2388
2539
  this.db.addComment({
2389
2540
  ticket_id: ticketId,
@@ -2393,6 +2544,7 @@ export class RunManager {
2393
2544
  });
2394
2545
  let decision = null;
2395
2546
  let problem = null;
2547
+ let attempt = "";
2396
2548
  try {
2397
2549
  const input = {
2398
2550
  ticketId,
@@ -2405,11 +2557,25 @@ export class RunManager {
2405
2557
  verify: current.verify,
2406
2558
  trigger: request.trigger,
2407
2559
  reason: request.reason,
2408
- failure: request.failure,
2560
+ failure,
2561
+ onAttempt: (text) => {
2562
+ attempt = text.slice(-3000);
2563
+ },
2409
2564
  diff: await ticketDiff(worktree.path),
2410
- actions: active.actions
2411
- .slice(-25)
2412
- .map((action) => `[${action.state === "failed" ? "FAILED" : action.state}] ${action.detail}`),
2565
+ actions: [
2566
+ ...active.actions
2567
+ .slice(-25)
2568
+ .map((action) => `[${action.state === "failed" ? "FAILED" : action.state}] ${action.detail}`),
2569
+ ...active.developerCommandEvidence.slice(-10).map((item, index, items) => {
2570
+ const previous = items[index - 1];
2571
+ const change = !item.revision || !previous?.revision
2572
+ ? "worktree comparison unavailable"
2573
+ : item.revision === previous.revision
2574
+ ? "worktree unchanged since previous command"
2575
+ : "worktree changed since previous command";
2576
+ return `[developer ${item.outcome}; ${change}] ${item.command}`;
2577
+ }),
2578
+ ],
2413
2579
  consult,
2414
2580
  earlier: this.db
2415
2581
  .listComments(ticketId)
@@ -2418,7 +2584,7 @@ export class RunManager {
2418
2584
  watchdog: this.watchdogSteers(ticketId),
2419
2585
  worktreePath: worktree.path,
2420
2586
  };
2421
- decision = await lead(input).catch(() => null);
2587
+ decision = await lead(input);
2422
2588
  }
2423
2589
  catch (cause) {
2424
2590
  problem = cause instanceof Error ? cause.message : String(cause);
@@ -2434,7 +2600,12 @@ export class RunManager {
2434
2600
  return;
2435
2601
  }
2436
2602
  if (!decision) {
2437
- this.blockForLead(ticketId, request, problem === null ? null : `The lead failed: ${problem}`);
2603
+ this.blockForLead(ticketId, enrichedRequest, [
2604
+ problem === null ? null : `The lead failed: ${problem}`,
2605
+ attempt ? `Lead attempt (tail):\n${attempt}` : "",
2606
+ ]
2607
+ .filter(Boolean)
2608
+ .join("\n\n") || null);
2438
2609
  return;
2439
2610
  }
2440
2611
  try {
@@ -2442,7 +2613,7 @@ export class RunManager {
2442
2613
  }
2443
2614
  catch (cause) {
2444
2615
  const message = cause instanceof Error ? cause.message : String(cause);
2445
- this.blockForLead(ticketId, request, `The lead's answer could not be applied: ${message}`);
2616
+ this.blockForLead(ticketId, enrichedRequest, `The lead's answer could not be applied: ${message}`);
2446
2617
  }
2447
2618
  }
2448
2619
  catch (cause) {