@taskless-app/swarm 0.6.100 → 0.6.102

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/cli.js CHANGED
@@ -4490,7 +4490,7 @@ var init_package = __esm({
4490
4490
  "package.json"() {
4491
4491
  package_default = {
4492
4492
  name: "@taskless-app/swarm",
4493
- version: "0.6.100",
4493
+ version: "0.6.102",
4494
4494
  type: "module",
4495
4495
  description: "Local control plane for a fleet of AI coding agents (drones), coordinating through Taskless. The overmind runs the swarm.",
4496
4496
  keywords: [
@@ -4542,7 +4542,7 @@ var init_package = __esm({
4542
4542
  undici: "^7.30.1",
4543
4543
  zod: "3.25.76"
4544
4544
  },
4545
- gitHead: "a0643b2118fce225b5afbe7ce9c1afbe7cd25d39"
4545
+ gitHead: "34ee99661e59073f43dae1487e6a5f27102cdd8d"
4546
4546
  };
4547
4547
  }
4548
4548
  });
@@ -11942,6 +11942,27 @@ init_src();
11942
11942
  var GH_MERGED_ABSENT_TTL_MS = 5 * 60 * 1e3;
11943
11943
  var GH_MERGED_LOOKBACK_MS = 30 * 24 * 60 * 60 * 1e3;
11944
11944
 
11945
+ // src/reviewCycle.ts
11946
+ init_src();
11947
+ var REVIEW_CYCLE_LIMIT_DEFAULT = 3;
11948
+ var REVIEW_CYCLE_LIMIT_CAP = 20;
11949
+ function validReviewCycleLimit(n) {
11950
+ return n != null && Number.isInteger(n) && n >= 1 && n <= REVIEW_CYCLE_LIMIT_CAP;
11951
+ }
11952
+ function parseReviewCycleLimitEnv(raw) {
11953
+ if (raw == null || raw.trim() === "") return REVIEW_CYCLE_LIMIT_DEFAULT;
11954
+ const n = Number(raw);
11955
+ return validReviewCycleLimit(n) ? n : REVIEW_CYCLE_LIMIT_DEFAULT;
11956
+ }
11957
+ var REVIEW_CYCLE_LIMIT = parseReviewCycleLimitEnv(process.env.SWARM_REVIEW_CYCLE_LIMIT);
11958
+ var TRAILING_HEAD_RE = /\[head ([0-9a-f]{7,40})\](?:\s*\[[^\]]*\])?\s*$/i;
11959
+ function verdictHeadSha(text) {
11960
+ if (!text) return null;
11961
+ return text.match(TRAILING_HEAD_RE)?.[1] ?? null;
11962
+ }
11963
+ var REVIEW_CYCLE_OPENED_MARK = "\u043E\u0442\u043A\u0440\u044B\u0442 \u0446\u0438\u043A\u043B \u0440\u0435-\u0440\u0435\u0432\u044C\u044E";
11964
+ var REVIEW_CYCLE_OPENED_PREFIX = `\u0444\u0438\u043A\u0441-\u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044F: \u043D\u043E\u0432\u044B\u0435 \u043A\u043E\u043C\u043C\u0438\u0442\u044B \u043F\u043E\u0441\u043B\u0435 \u0432\u0435\u0440\u0434\u0438\u043A\u0442\u0430 \xAB\u043D\u0443\u0436\u043D\u044B \u043F\u0440\u0430\u0432\u043A\u0438\xBB \u2014 ${REVIEW_CYCLE_OPENED_MARK} #`;
11965
+
11945
11966
  // src/gh.ts
11946
11967
  function ghCallSkipsPause(args) {
11947
11968
  if (args[0] === "pr" && args[1] === "checks") return true;
@@ -12113,7 +12134,8 @@ async function latestVerdictComment(prUrl, sinceIso, run = realCommentsRunner) {
12113
12134
  createdAt: found.createdAt,
12114
12135
  body: found.body,
12115
12136
  findings: found.verdict.findings,
12116
- reviewMode: found.verdict.reviewMode
12137
+ reviewMode: found.verdict.reviewMode,
12138
+ headSha: verdictHeadSha(found.body)
12117
12139
  };
12118
12140
  }
12119
12141
  async function scanPrComments(prUrl, sinceIso, run, pick3) {
@@ -12352,6 +12374,14 @@ function makeMergeIntentResolver(deps) {
12352
12374
  reason: `\u043D\u0430 ${shortSha(sha)} \u0435\u0449\u0451 \u0438\u0434\u0443\u0442 \u043F\u0440\u043E\u0433\u043E\u043D\u044B GitHub Actions: ${runs.active.join(", ")} \u2014 \u0432\u0438\u0434\u0438\u043C\u044B\u0435 \u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0438 \u043C\u043E\u0433\u0443\u0442 \u0431\u044B\u0442\u044C \u0437\u0435\u043B\u0451\u043D\u044B\u043C\u0438, \u043F\u043E\u043A\u0430 \u0441\u043B\u0435\u0434\u0443\u044E\u0449\u0430\u044F \u0432\u043E\u043B\u043D\u0430 \u0434\u0436\u043E\u0431 \u043D\u0435 \u0441\u043E\u0437\u0434\u0430\u043D\u0430`
12353
12375
  };
12354
12376
  }
12377
+ const cancelled = runs.cancelled ?? [];
12378
+ if (cancelled.length > 0) {
12379
+ return {
12380
+ action: "wait",
12381
+ code: "checks_pending",
12382
+ reason: `\u043D\u0430 ${shortSha(sha)} \u043F\u0440\u043E\u0433\u043E\u043D GitHub Actions \u043E\u0442\u043C\u0435\u043D\u0451\u043D: ${cancelled.join(", ")} \u2014 \u044D\u0442\u043E \u043D\u0435 \u0437\u0435\u043B\u0451\u043D\u044B\u0439 CI, \u0436\u0434\u0443 \u043F\u0435\u0440\u0435\u0437\u0430\u043F\u0443\u0441\u043A\u0430`
12383
+ };
12384
+ }
12355
12385
  if (st.checks === "none") {
12356
12386
  if (runs.total > 0) {
12357
12387
  return { action: "wait", code: "checks_pending", reason: `\u043F\u0440\u043E\u0433\u043E\u043D\u044B GitHub Actions \u043D\u0430 ${shortSha(sha)} \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043B\u0438\u0441\u044C, \u0430 \u043F\u0440\u043E\u0432\u0435\u0440\u043E\u043A \u0443 PR \u0435\u0449\u0451 \u043D\u0435 \u0432\u0438\u0434\u043D\u043E \u2014 \u0436\u0434\u0443, \u043F\u043E\u043A\u0430 GitHub \u0438\u0445 \u043F\u043E\u043A\u0430\u0436\u0435\u0442` };
package/dist/overmind.js CHANGED
@@ -6057,6 +6057,12 @@ function makeChannelHandler(deps) {
6057
6057
  deps.store.addEvent(id, kind, text, actor);
6058
6058
  return Response.json({ ok: true });
6059
6059
  }
6060
+ case "events": {
6061
+ const id = targetId(p.id);
6062
+ if (id == null) return bad(403, "\u043F\u0440\u043E\u0433\u043E\u043D \u0432\u043D\u0435 \u0441\u043A\u043E\u0443\u043F\u0430 \u043A\u0430\u043D\u0430\u043B\u0430");
6063
+ const events = deps.store.events(id).map((e) => ({ kind: e.kind ?? null, text: e.text ?? null }));
6064
+ return Response.json({ events });
6065
+ }
6060
6066
  case "ask": {
6061
6067
  const text = str2(p.text).trim();
6062
6068
  if (!text) return bad(400, "\u043F\u0443\u0441\u0442\u043E\u0439 \u0432\u043E\u043F\u0440\u043E\u0441");
@@ -6214,6 +6220,10 @@ function channelDroneStore(opts) {
6214
6220
  addEvent: async (id, kind, text, actor) => {
6215
6221
  await call("addEvent", { id, kind, text, actor: actor ?? null });
6216
6222
  },
6223
+ events: async (id) => {
6224
+ const events = (await call("events", { id })).events;
6225
+ return events.map((e) => ({ kind: e.kind ?? null, text: e.text ?? null }));
6226
+ },
6217
6227
  ask: async (text, options) => (await call("ask", { text, options: options ?? null })).question,
6218
6228
  myLastQuestion: async () => (await call("myLastQuestion")).question,
6219
6229
  withdrawMyQuestion: async (reason) => {
@@ -8714,6 +8724,7 @@ function localDroneStore(db, runId, opts) {
8714
8724
  addEvent: async (id, kind, text, actor) => {
8715
8725
  db.addEvent(target(id), kind, text, actor ?? null);
8716
8726
  },
8727
+ events: async (id) => db.events(target(id)).map((e) => ({ kind: e.kind ?? null, text: e.text ?? null })),
8717
8728
  ask: async (text, options) => db.ask(runId, text, options),
8718
8729
  myLastQuestion: async () => {
8719
8730
  const qs = db.questionsFor(runId);
@@ -14909,7 +14920,7 @@ function parkReasonUnretriable(reason) {
14909
14920
  // package.json
14910
14921
  var package_default = {
14911
14922
  name: "@taskless-app/swarm",
14912
- version: "0.6.100",
14923
+ version: "0.6.102",
14913
14924
  type: "module",
14914
14925
  description: "Local control plane for a fleet of AI coding agents (drones), coordinating through Taskless. The overmind runs the swarm.",
14915
14926
  keywords: [
@@ -14961,7 +14972,7 @@ var package_default = {
14961
14972
  undici: "^7.30.1",
14962
14973
  zod: "3.25.76"
14963
14974
  },
14964
- gitHead: "a0643b2118fce225b5afbe7ce9c1afbe7cd25d39"
14975
+ gitHead: "34ee99661e59073f43dae1487e6a5f27102cdd8d"
14965
14976
  };
14966
14977
 
14967
14978
  // src/version.ts
@@ -15470,6 +15481,204 @@ async function askBranch(deps, cache, repo, branch, taskCreatedAt, now) {
15470
15481
  }
15471
15482
  }
15472
15483
 
15484
+ // src/reviewCycle.ts
15485
+ init_src();
15486
+ var REVIEW_CYCLE_LIMIT_DEFAULT = 3;
15487
+ var REVIEW_CYCLE_LIMIT_CAP = 20;
15488
+ function validReviewCycleLimit(n) {
15489
+ return n != null && Number.isInteger(n) && n >= 1 && n <= REVIEW_CYCLE_LIMIT_CAP;
15490
+ }
15491
+ function parseReviewCycleLimitEnv(raw) {
15492
+ if (raw == null || raw.trim() === "") return REVIEW_CYCLE_LIMIT_DEFAULT;
15493
+ const n = Number(raw);
15494
+ return validReviewCycleLimit(n) ? n : REVIEW_CYCLE_LIMIT_DEFAULT;
15495
+ }
15496
+ var REVIEW_CYCLE_LIMIT = parseReviewCycleLimitEnv(process.env.SWARM_REVIEW_CYCLE_LIMIT);
15497
+ var configuredReviewCycleLimit = null;
15498
+ function configureReviewCycleLimit(n) {
15499
+ configuredReviewCycleLimit = validReviewCycleLimit(n) ? n : null;
15500
+ }
15501
+ function effectiveReviewCycleLimit() {
15502
+ return configuredReviewCycleLimit ?? REVIEW_CYCLE_LIMIT;
15503
+ }
15504
+ function reviewCyclesExhausted(run2) {
15505
+ return (run2.review_cycle ?? 0) >= effectiveReviewCycleLimit();
15506
+ }
15507
+ function needsFixIteration(run2) {
15508
+ return run2.review_verdict === "changes" || isNegativeVerifyVerdict(toVerifyVerdict(run2.verify_verdict));
15509
+ }
15510
+ function fixPartnerHold(input) {
15511
+ const reviewOpen = input.reviewVerdict == null;
15512
+ const verifyOpen = input.verifyVerdict == null;
15513
+ const waitingOn = verifyOpen && input.verifierWorking ? "verifier" : reviewOpen && input.reviewerWorking ? "reviewer" : null;
15514
+ if (!waitingOn) return { action: "wake" };
15515
+ const elapsed = input.verdictAtMs == null ? 0 : input.nowMs - input.verdictAtMs;
15516
+ if (!Number.isFinite(elapsed)) return { action: "partial", waitingOn };
15517
+ if (elapsed < input.waitMs) return { action: "wait", waitingOn };
15518
+ return { action: "partial", waitingOn };
15519
+ }
15520
+ var TRAILING_HEAD_RE = /\[head ([0-9a-f]{7,40})\](?:\s*\[[^\]]*\])?\s*$/i;
15521
+ var VERDICT_HEAD_SHA = /^[0-9a-f]{7,40}$/i;
15522
+ function appendVerdictHead(text, sha) {
15523
+ const trimmed = sha?.trim() ?? "";
15524
+ if (!VERDICT_HEAD_SHA.test(trimmed)) return text;
15525
+ const trailing = text.match(TRAILING_HEAD_RE)?.[1] ?? null;
15526
+ if (trailing && sameCommitSha(trailing, trimmed)) return text;
15527
+ return `${text} [head ${trimmed}]`;
15528
+ }
15529
+ function verdictHeadSha(text) {
15530
+ if (!text) return null;
15531
+ return text.match(TRAILING_HEAD_RE)?.[1] ?? null;
15532
+ }
15533
+ function escapeHeadQuotes(text) {
15534
+ return text.replace(/\[head ([0-9a-f]{7,40})\]/gi, "(head $1)");
15535
+ }
15536
+ function markVerdictHead(text, sha) {
15537
+ return appendVerdictHead(escapeHeadQuotes(text), sha);
15538
+ }
15539
+ function stripVerdictHead(text) {
15540
+ return text.replace(/[ \t]*\[head [0-9a-f]{7,40}\]/gi, "").trim();
15541
+ }
15542
+ function sameCommitSha(a, b) {
15543
+ const left = a?.trim().toLowerCase() ?? "";
15544
+ const right = b?.trim().toLowerCase() ?? "";
15545
+ if (!VERDICT_HEAD_SHA.test(left) || !VERDICT_HEAD_SHA.test(right)) return false;
15546
+ return left === right || left.startsWith(right) || right.startsWith(left);
15547
+ }
15548
+ function changesVerdictIsStale(verdict, verdictSha, headSha2) {
15549
+ if (verdict !== "changes") return false;
15550
+ const verdictOk = VERDICT_HEAD_SHA.test(verdictSha?.trim() ?? "");
15551
+ const headOk = VERDICT_HEAD_SHA.test(headSha2?.trim() ?? "");
15552
+ if (!verdictOk || !headOk) return false;
15553
+ return !sameCommitSha(verdictSha, headSha2);
15554
+ }
15555
+ var STALE_HEAD_VERDICT_MARK = "\u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u043D\u0430 \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0435\u0439 \u0433\u043E\u043B\u043E\u0432\u0435, \u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0430 \u043F\u0435\u0440\u0435\u0437\u0430\u043F\u0443\u0449\u0435\u043D\u0430";
15556
+ function isStaleHeadEvent(text) {
15557
+ return (text ?? "").startsWith(STALE_HEAD_VERDICT_MARK);
15558
+ }
15559
+ var REVIEW_CYCLE_OPENED_MARK = "\u043E\u0442\u043A\u0440\u044B\u0442 \u0446\u0438\u043A\u043B \u0440\u0435-\u0440\u0435\u0432\u044C\u044E";
15560
+ var REVIEW_CYCLE_OPENED_PREFIX = `\u0444\u0438\u043A\u0441-\u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044F: \u043D\u043E\u0432\u044B\u0435 \u043A\u043E\u043C\u043C\u0438\u0442\u044B \u043F\u043E\u0441\u043B\u0435 \u0432\u0435\u0440\u0434\u0438\u043A\u0442\u0430 \xAB\u043D\u0443\u0436\u043D\u044B \u043F\u0440\u0430\u0432\u043A\u0438\xBB \u2014 ${REVIEW_CYCLE_OPENED_MARK} #`;
15561
+ function isReviewCycleOpenedEvent(text) {
15562
+ return (text ?? "").startsWith(REVIEW_CYCLE_OPENED_PREFIX);
15563
+ }
15564
+ function reviewCycleOpenedText(cycle, verdictSha) {
15565
+ return appendVerdictHead(`${REVIEW_CYCLE_OPENED_PREFIX}${cycle}`, verdictSha);
15566
+ }
15567
+ function feedBoundaryIndex(events) {
15568
+ let cycleOpen = -1;
15569
+ let submission = -1;
15570
+ for (let i = 0; i < events.length; i++) {
15571
+ if (isReviewCycleOpenedEvent(events[i]?.text)) cycleOpen = i;
15572
+ const kind = events[i]?.kind ?? "";
15573
+ if (kind === "pr_opened" || kind === "done") submission = i;
15574
+ }
15575
+ return cycleOpen >= 0 ? cycleOpen : submission;
15576
+ }
15577
+ function repeatChangesOnSameHead(input) {
15578
+ if (!input?.verdictSha || !input.headSha || !input.openedCycleSha) return false;
15579
+ if (!sameCommitSha(input.verdictSha, input.headSha)) return false;
15580
+ return sameCommitSha(input.openedCycleSha, input.headSha);
15581
+ }
15582
+ var CHANGES_VERDICT_RE = /REQUEST CHANGES|нужны правки/i;
15583
+ var OPERATOR_REVIEW_PREFIX = "\u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u0440\u0435\u0432\u044C\u044E \u043E\u0442 \u043E\u043F\u0435\u0440\u0430\u0442\u043E\u0440\u0430";
15584
+ var REVIEWER_REVIEW_PREFIX = "\u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u0440\u0435\u0432\u044C\u044E \u043E\u0442 ";
15585
+ var REVIEWER_PICKUP_PREFIX = "\u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u0440\u0435\u0432\u044C\u044E \u043F\u043E\u0434\u0445\u0432\u0430\u0447\u0435\u043D \u0438\u0437 PR-\u043A\u043E\u043C\u043C\u0435\u043D\u0442\u0430";
15586
+ var HEAD_MARKED_PREFIXES = [
15587
+ REVIEWER_REVIEW_PREFIX,
15588
+ REVIEWER_PICKUP_PREFIX,
15589
+ "\u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u0432\u0435\u0440\u0438\u0444\u0438\u043A\u0430\u0446\u0438\u0438 \u043E\u0442 ",
15590
+ "\u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u0432\u0435\u0440\u0438\u0444\u0438\u043A\u0430\u0446\u0438\u0438 \u043F\u043E\u0434\u0445\u0432\u0430\u0447\u0435\u043D \u0438\u0437 PR-\u043A\u043E\u043C\u043C\u0435\u043D\u0442\u0430"
15591
+ ];
15592
+ function verdictEventSha(text) {
15593
+ if (!text || text.startsWith(OPERATOR_REVIEW_PREFIX)) return null;
15594
+ if (!HEAD_MARKED_PREFIXES.some((p) => text.startsWith(p))) return null;
15595
+ return verdictHeadSha(text);
15596
+ }
15597
+ function changesLabel(text) {
15598
+ const pickup = text.startsWith(REVIEWER_PICKUP_PREFIX);
15599
+ const sep4 = pickup ? "): " : ": ";
15600
+ const at = text.indexOf(sep4);
15601
+ if (at < 0) return false;
15602
+ const line = (text.slice(at + sep4.length).split("\n")[0] ?? "").trim();
15603
+ const head = line.split(" \u2014 ")[0] ?? line;
15604
+ return CHANGES_VERDICT_RE.test(head);
15605
+ }
15606
+ function isChangesVerdictText(text) {
15607
+ if (!text) return false;
15608
+ if (text.startsWith(OPERATOR_REVIEW_PREFIX)) return true;
15609
+ if (text.startsWith(REVIEWER_REVIEW_PREFIX) || text.startsWith(REVIEWER_PICKUP_PREFIX)) return changesLabel(text);
15610
+ return false;
15611
+ }
15612
+ function asFeed(events) {
15613
+ return events.map((e) => typeof e === "string" || e == null ? { text: typeof e === "string" ? e : null } : e);
15614
+ }
15615
+ function reviewHeadContext(events, headSha2) {
15616
+ const feed = asFeed(events);
15617
+ let openedCycleSha = null;
15618
+ for (const event of feed) {
15619
+ if (!isReviewCycleOpenedEvent(event.text)) continue;
15620
+ const sha = verdictHeadSha(event.text);
15621
+ if (sha) openedCycleSha = sha;
15622
+ }
15623
+ const boundary = feedBoundaryIndex(feed);
15624
+ let verdictSha = null;
15625
+ let sawVerdict = false;
15626
+ for (let i = boundary + 1; i < feed.length; i++) {
15627
+ const text = feed[i]?.text ?? "";
15628
+ if (!isChangesVerdictText(text)) continue;
15629
+ sawVerdict = true;
15630
+ verdictSha = verdictEventSha(text);
15631
+ }
15632
+ return {
15633
+ verdictSha: sawVerdict ? verdictSha : null,
15634
+ headSha: headSha2 ?? null,
15635
+ openedCycleSha
15636
+ };
15637
+ }
15638
+ function latestChangesVerdictSha(events) {
15639
+ return reviewHeadContext(events, null).verdictSha ?? null;
15640
+ }
15641
+ function reviewTransitionPatch(run2, prUrl, head) {
15642
+ const isFixIteration = needsFixIteration(run2);
15643
+ if (isFixIteration) {
15644
+ if (reviewCyclesExhausted(run2)) {
15645
+ return { isFixIteration: false, cycle: null, patch: { status: "review", pr_url: prUrl } };
15646
+ }
15647
+ const verifyAlso = isNegativeVerifyVerdict(toVerifyVerdict(run2.verify_verdict));
15648
+ if (run2.review_verdict === "changes" && !verifyAlso && repeatChangesOnSameHead(head)) {
15649
+ return { isFixIteration: false, cycle: null, patch: { status: "review", pr_url: prUrl } };
15650
+ }
15651
+ const cycle = (run2.review_cycle ?? 0) + 1;
15652
+ return {
15653
+ isFixIteration: true,
15654
+ cycle,
15655
+ patch: { status: "review", pr_url: prUrl, review_cycle: cycle, review_verdict: null, verify_verdict: null }
15656
+ };
15657
+ }
15658
+ return { isFixIteration: false, cycle: null, patch: { status: "review", pr_url: prUrl } };
15659
+ }
15660
+ function branchFromPrPatch(currentBranch, headBranch) {
15661
+ if (!headBranch || headBranch === currentBranch) return null;
15662
+ return {
15663
+ patch: { branch: headBranch },
15664
+ event: currentBranch ? `\u0432\u0435\u0442\u043A\u0430 \u043F\u0440\u043E\u0433\u043E\u043D\u0430 \u0432\u0437\u044F\u0442\u0430 \u0443 PR: ${currentBranch} \u2192 ${headBranch} (\u043F\u043E\u043B\u0435 \u0431\u044B\u043B\u043E \u0441\u043E\u0431\u0440\u0430\u043D\u043E \u0438\u0437 \u0441\u043B\u0430\u0433\u0430 \u2014 TASWM-356)` : `\u0432\u0435\u0442\u043A\u0430 \u043F\u0440\u043E\u0433\u043E\u043D\u0430 \u0432\u0437\u044F\u0442\u0430 \u0443 PR: ${headBranch} (TASWM-356)`
15665
+ };
15666
+ }
15667
+ function prLiveness(st) {
15668
+ if (!st) return "unknown";
15669
+ if (st.merged) return "merged";
15670
+ const state = (st.state ?? "").toUpperCase();
15671
+ if (state === "MERGED") return "merged";
15672
+ if (state === "CLOSED") return "closed";
15673
+ if (state === "UNKNOWN") return "unknown";
15674
+ return "open";
15675
+ }
15676
+ function applyReviewTransition(db, run2, prUrl, head) {
15677
+ const { patch, ...t } = reviewTransitionPatch(run2, prUrl, head);
15678
+ db.updateRun(run2.id, patch);
15679
+ return t;
15680
+ }
15681
+
15473
15682
  // src/gh.ts
15474
15683
  function ghCallSkipsPause(args) {
15475
15684
  if (args[0] === "pr" && args[1] === "checks") return true;
@@ -15516,13 +15725,13 @@ function isGithubPrUrl(url) {
15516
15725
  return GH_PR_RE.test(url.trim());
15517
15726
  }
15518
15727
  function softStatus() {
15519
- return { merged: false, state: "UNKNOWN", mergeable: "UNKNOWN", mergeStateStatus: "UNKNOWN", conflicting: false, isDraft: false, files: [], headBranch: null };
15728
+ return { merged: false, state: "UNKNOWN", mergeable: "UNKNOWN", mergeStateStatus: "UNKNOWN", conflicting: false, isDraft: false, files: [], headBranch: null, headSha: null };
15520
15729
  }
15521
15730
  async function prStatus(prUrl, run2 = realRunner) {
15522
15731
  if (!isGithubPrUrl(prUrl)) return softStatus();
15523
15732
  let out;
15524
15733
  try {
15525
- out = await run2(["pr", "view", prUrl, "--json", "state,mergedAt,mergeable,mergeStateStatus,isDraft,files,headRefName"]);
15734
+ out = await run2(["pr", "view", prUrl, "--json", "state,mergedAt,mergeable,mergeStateStatus,isDraft,files,headRefName,headRefOid"]);
15526
15735
  } catch {
15527
15736
  return softStatus();
15528
15737
  }
@@ -15544,9 +15753,35 @@ async function prStatus(prUrl, run2 = realRunner) {
15544
15753
  conflicting: !merged && state === "OPEN" && mergeable === "CONFLICTING",
15545
15754
  isDraft: j.isDraft === true,
15546
15755
  files: Array.isArray(j.files) ? j.files.map((f) => f.path).filter((p) => typeof p === "string") : [],
15547
- headBranch: typeof j.headRefName === "string" && j.headRefName ? j.headRefName : null
15756
+ headBranch: typeof j.headRefName === "string" && j.headRefName ? j.headRefName : null,
15757
+ headSha: commitSha(j.headRefOid)
15548
15758
  };
15549
15759
  }
15760
+ var COMMIT_SHA_RE = /^[0-9a-f]{7,40}$/i;
15761
+ function commitSha(raw) {
15762
+ const sha = raw?.trim() ?? "";
15763
+ return COMMIT_SHA_RE.test(sha) ? sha : null;
15764
+ }
15765
+ async function prHeadOid(prUrl, run2 = realRunner) {
15766
+ if (!isGithubPrUrl(prUrl)) return null;
15767
+ try {
15768
+ const out = await run2(["pr", "view", prUrl, "--json", "headRefOid"]);
15769
+ const j = JSON.parse(out);
15770
+ return commitSha(j.headRefOid);
15771
+ } catch {
15772
+ return null;
15773
+ }
15774
+ }
15775
+ async function rerunActionsRun(prUrl, runId, run2 = realRunner) {
15776
+ const repo = prRepoPath(prUrl);
15777
+ if (!repo || !/^\d+$/.test(runId)) return false;
15778
+ try {
15779
+ await run2(["run", "rerun", runId, "-R", repo]);
15780
+ return true;
15781
+ } catch {
15782
+ return false;
15783
+ }
15784
+ }
15550
15785
  async function prHeadBranch(prUrl, run2 = realRunner) {
15551
15786
  if (!isGithubPrUrl(prUrl)) return null;
15552
15787
  try {
@@ -15594,10 +15829,13 @@ async function prActionsRuns(prUrl, headSha2, run2 = realRunner) {
15594
15829
  if (!seen || (r.id ?? 0) > (seen.id ?? 0)) latest.set(key, r);
15595
15830
  }
15596
15831
  const label2 = (r, what) => `${r.name || "workflow"} (${what || "?"})`;
15832
+ const latestRows = [...latest.values()];
15597
15833
  return {
15598
15834
  total: runs.length,
15599
15835
  active: runs.filter((r) => r.status !== "completed").map((r) => label2(r, r.status)),
15600
- failed: [...latest.values()].filter((r) => r.status === "completed" && !ACTIONS_RUN_OK.has(r.conclusion ?? "")).map((r) => label2(r, r.conclusion))
15836
+ failed: latestRows.filter((r) => r.status === "completed" && r.conclusion !== "cancelled" && !ACTIONS_RUN_OK.has(r.conclusion ?? "")).map((r) => label2(r, r.conclusion)),
15837
+ // Отмена — не красный и не «добежал». Свежий cancelled не даёт влить PR.
15838
+ cancelled: latestRows.filter((r) => r.status === "completed" && r.conclusion === "cancelled").map((r) => label2(r, r.conclusion))
15601
15839
  };
15602
15840
  } catch {
15603
15841
  return null;
@@ -15777,7 +16015,8 @@ async function latestVerdictComment(prUrl, sinceIso, run2 = realCommentsRunner)
15777
16015
  createdAt: found.createdAt,
15778
16016
  body: found.body,
15779
16017
  findings: found.verdict.findings,
15780
- reviewMode: found.verdict.reviewMode
16018
+ reviewMode: found.verdict.reviewMode,
16019
+ headSha: verdictHeadSha(found.body)
15781
16020
  };
15782
16021
  }
15783
16022
  async function scanPrComments(prUrl, sinceIso, run2, pick4) {
@@ -15965,13 +16204,19 @@ async function prCiStatus(pr, run2 = realChecksRunner) {
15965
16204
  const pass = rows.filter((r) => r.bucket === "pass").length;
15966
16205
  const pending2 = rows.filter((r) => r.bucket === "pending").length;
15967
16206
  const counts = { total, pass, pending: pending2 };
15968
- const failingRows = rows.filter((r) => r.bucket === "fail" || r.bucket === "cancel");
16207
+ const failingRows = rows.filter((r) => r.bucket === "fail");
15969
16208
  if (failingRows.length > 0) {
15970
16209
  const failing = failingRows.map((r) => r.name);
15971
16210
  const failingRunIds = [...new Set(failingRows.map((r) => runIdFromLink(r.link)).filter((id) => id != null))];
15972
16211
  return { bucket: "fail", failing, failingRunIds, ...counts };
15973
16212
  }
15974
16213
  if (rows.some((r) => r.bucket === "pending")) return { bucket: "pending", failing: [], failingRunIds: [], ...counts };
16214
+ const cancelRows = rows.filter((r) => r.bucket === "cancel");
16215
+ if (cancelRows.length > 0) {
16216
+ const cancelled = cancelRows.map((r) => r.name);
16217
+ const cancelledRunIds = [...new Set(cancelRows.map((r) => runIdFromLink(r.link)).filter((id) => id != null))];
16218
+ return { bucket: "cancelled", failing: [], failingRunIds: [], cancelled, cancelledRunIds, ...counts };
16219
+ }
15975
16220
  return { bucket: "pass", failing: [], failingRunIds: [], ...counts };
15976
16221
  }
15977
16222
  var realRunLogRunner = async (runId) => {
@@ -16301,71 +16546,6 @@ init_zoneNotes();
16301
16546
  init_src();
16302
16547
  init_src();
16303
16548
  init_src();
16304
-
16305
- // src/reviewCycle.ts
16306
- init_src();
16307
- var REVIEW_CYCLE_LIMIT_DEFAULT = 3;
16308
- var REVIEW_CYCLE_LIMIT_CAP = 20;
16309
- function validReviewCycleLimit(n) {
16310
- return n != null && Number.isInteger(n) && n >= 1 && n <= REVIEW_CYCLE_LIMIT_CAP;
16311
- }
16312
- function parseReviewCycleLimitEnv(raw) {
16313
- if (raw == null || raw.trim() === "") return REVIEW_CYCLE_LIMIT_DEFAULT;
16314
- const n = Number(raw);
16315
- return validReviewCycleLimit(n) ? n : REVIEW_CYCLE_LIMIT_DEFAULT;
16316
- }
16317
- var REVIEW_CYCLE_LIMIT = parseReviewCycleLimitEnv(process.env.SWARM_REVIEW_CYCLE_LIMIT);
16318
- var configuredReviewCycleLimit = null;
16319
- function configureReviewCycleLimit(n) {
16320
- configuredReviewCycleLimit = validReviewCycleLimit(n) ? n : null;
16321
- }
16322
- function effectiveReviewCycleLimit() {
16323
- return configuredReviewCycleLimit ?? REVIEW_CYCLE_LIMIT;
16324
- }
16325
- function reviewCyclesExhausted(run2) {
16326
- return (run2.review_cycle ?? 0) >= effectiveReviewCycleLimit();
16327
- }
16328
- function needsFixIteration(run2) {
16329
- return run2.review_verdict === "changes" || isNegativeVerifyVerdict(toVerifyVerdict(run2.verify_verdict));
16330
- }
16331
- function reviewTransitionPatch(run2, prUrl) {
16332
- const isFixIteration = needsFixIteration(run2);
16333
- if (isFixIteration) {
16334
- if (reviewCyclesExhausted(run2)) {
16335
- return { isFixIteration: false, cycle: null, patch: { status: "review", pr_url: prUrl } };
16336
- }
16337
- const cycle = (run2.review_cycle ?? 0) + 1;
16338
- return {
16339
- isFixIteration: true,
16340
- cycle,
16341
- patch: { status: "review", pr_url: prUrl, review_cycle: cycle, review_verdict: null, verify_verdict: null }
16342
- };
16343
- }
16344
- return { isFixIteration: false, cycle: null, patch: { status: "review", pr_url: prUrl } };
16345
- }
16346
- function branchFromPrPatch(currentBranch, headBranch) {
16347
- if (!headBranch || headBranch === currentBranch) return null;
16348
- return {
16349
- patch: { branch: headBranch },
16350
- event: currentBranch ? `\u0432\u0435\u0442\u043A\u0430 \u043F\u0440\u043E\u0433\u043E\u043D\u0430 \u0432\u0437\u044F\u0442\u0430 \u0443 PR: ${currentBranch} \u2192 ${headBranch} (\u043F\u043E\u043B\u0435 \u0431\u044B\u043B\u043E \u0441\u043E\u0431\u0440\u0430\u043D\u043E \u0438\u0437 \u0441\u043B\u0430\u0433\u0430 \u2014 TASWM-356)` : `\u0432\u0435\u0442\u043A\u0430 \u043F\u0440\u043E\u0433\u043E\u043D\u0430 \u0432\u0437\u044F\u0442\u0430 \u0443 PR: ${headBranch} (TASWM-356)`
16351
- };
16352
- }
16353
- function prLiveness(st) {
16354
- if (!st) return "unknown";
16355
- if (st.merged) return "merged";
16356
- const state = (st.state ?? "").toUpperCase();
16357
- if (state === "MERGED") return "merged";
16358
- if (state === "CLOSED") return "closed";
16359
- if (state === "UNKNOWN") return "unknown";
16360
- return "open";
16361
- }
16362
- function applyReviewTransition(db, run2, prUrl) {
16363
- const { patch, ...t } = reviewTransitionPatch(run2, prUrl);
16364
- db.updateRun(run2.id, patch);
16365
- return t;
16366
- }
16367
-
16368
- // src/droneServer.ts
16369
16549
  init_src();
16370
16550
  function readTaskFailureInstruction(slug, failure) {
16371
16551
  const why = describeToolFailure(failure);
@@ -16994,8 +17174,13 @@ ${failText}` : failText }],
16994
17174
  }
16995
17175
  const reviewed = await store.getRun(run2.reviews_run_id);
16996
17176
  const verdictText = verdictLabel(verdict);
17177
+ const reviewHead = await headSha(opts.worktree ?? process.cwd());
16997
17178
  await store.updateRun(run2.reviews_run_id, { review_verdict: verdict });
16998
- await store.addEvent(run2.reviews_run_id, "step", `\u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u0440\u0435\u0432\u044C\u044E \u043E\u0442 ${run2.name}: ${verdictText}${summary ? ` \u2014 ${summary}` : ""}`);
17179
+ await store.addEvent(
17180
+ run2.reviews_run_id,
17181
+ "step",
17182
+ markVerdictHead(`\u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u0440\u0435\u0432\u044C\u044E \u043E\u0442 ${run2.name}: ${verdictText}${summary ? ` \u2014 ${summary}` : ""}`, reviewHead)
17183
+ );
16999
17184
  const reviewedSlug = reportSlug(reviewed?.task_slug);
17000
17185
  let shots = { attachments: [], warning: "" };
17001
17186
  let commentWarning = "";
@@ -17060,9 +17245,35 @@ ${failText}` : failText }],
17060
17245
  };
17061
17246
  }
17062
17247
  const verified = await store.getRun(run2.verifies_run_id);
17248
+ if ((run2.review_cycle ?? 0) < (verified?.review_cycle ?? 0)) {
17249
+ await store.updateRun(null, { status: "superseded", stop_reason: null });
17250
+ await store.addEvent(
17251
+ null,
17252
+ "superseded",
17253
+ `\u043A\u0440\u0443\u0433 ${run2.review_cycle ?? 0} \u0443\u0436\u0435 \u043D\u0435 \u0442\u0435\u043A\u0443\u0449\u0438\u0439 (\u0441\u0435\u0439\u0447\u0430\u0441 ${verified?.review_cycle ?? 0}) \u2014 \u043F\u043E\u0437\u0434\u043D\u0438\u0439 \u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u043D\u0435 \u0437\u0430\u0441\u0447\u0438\u0442\u0430\u043D`
17254
+ );
17255
+ await store.addEvent(
17256
+ run2.verifies_run_id,
17257
+ "step",
17258
+ `\u043F\u043E\u0437\u0434\u043D\u0438\u0439 \u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u0432\u0435\u0440\u0438\u0444\u0438\u043A\u0430\u0442\u043E\u0440\u0430 ${run2.name} \u043F\u0440\u043E\u0448\u043B\u043E\u0433\u043E \u043A\u0440\u0443\u0433\u0430 \u043D\u0435 \u0437\u0430\u0441\u0447\u0438\u0442\u0430\u043D \u0438 \u0444\u0438\u043A\u0441-\u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044E \u043D\u0435 \u043E\u0442\u043A\u0440\u044B\u0432\u0430\u0435\u0442`
17259
+ );
17260
+ return {
17261
+ content: [
17262
+ {
17263
+ type: "text",
17264
+ text: "\u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u043F\u0440\u043E\u0448\u043B\u043E\u0433\u043E \u043A\u0440\u0443\u0433\u0430 \u043D\u0435 \u0437\u0430\u0441\u0447\u0438\u0442\u0430\u043D: \u0430\u0432\u0442\u043E\u0440 \u0443\u0436\u0435 \u0441\u0434\u0430\u043B \u043D\u043E\u0432\u044B\u0439 \u043A\u0440\u0443\u0433, \u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0430 \u0437\u0430\u043A\u0440\u044B\u0442\u0430"
17265
+ }
17266
+ ]
17267
+ };
17268
+ }
17063
17269
  const verdictText = verifyVerdictLabel(verdict);
17270
+ const verifyHead = await headSha(opts.worktree ?? process.cwd());
17064
17271
  await store.updateRun(run2.verifies_run_id, { verify_verdict: verdict });
17065
- await store.addEvent(run2.verifies_run_id, "step", `\u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u0432\u0435\u0440\u0438\u0444\u0438\u043A\u0430\u0446\u0438\u0438 \u043E\u0442 ${run2.name}: ${verdictText}${summary ? ` \u2014 ${summary}` : ""}`);
17272
+ await store.addEvent(
17273
+ run2.verifies_run_id,
17274
+ "step",
17275
+ markVerdictHead(`\u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u0432\u0435\u0440\u0438\u0444\u0438\u043A\u0430\u0446\u0438\u0438 \u043E\u0442 ${run2.name}: ${verdictText}${summary ? ` \u2014 ${summary}` : ""}`, verifyHead)
17276
+ );
17066
17277
  const verifiedSlug = reportSlug(verified?.task_slug);
17067
17278
  let shots = { attachments: [], warning: "" };
17068
17279
  let commentWarning = "";
@@ -17175,21 +17386,30 @@ ${report}${shots.warning}`,
17175
17386
  const held = await changedPaths(opts.worktree ?? process.cwd(), { baseBranch: run2?.base_branch ?? null }).catch(() => []);
17176
17387
  const heldPatch = held.length ? { changed_paths: held } : {};
17177
17388
  if (run2) {
17178
- const t = reviewTransitionPatch(run2, pr_url);
17389
+ const headOid = opts.prHeadOid ? await opts.prHeadOid(pr_url).catch(() => null) : null;
17390
+ const headEvents = headOid ? await store.events(null).then((evs) => evs.map((e) => ({ kind: e.kind ?? null, text: e.text }))).catch(() => []) : [];
17391
+ const headCtx = headOid ? reviewHeadContext(headEvents, headOid) : void 0;
17392
+ const t = reviewTransitionPatch(run2, pr_url, headCtx);
17393
+ if (run2.review_verdict === "changes" && headCtx && repeatChangesOnSameHead(headCtx) && !t.isFixIteration) {
17394
+ await store.addEvent(
17395
+ null,
17396
+ "step",
17397
+ "\u043F\u043E\u0432\u0442\u043E\u0440\u043D\u044B\u0439 REQUEST CHANGES \u043D\u0430 \u0442\u0443 \u0436\u0435 \u0433\u043E\u043B\u043E\u0432\u0443 \u0431\u0435\u0437 \u043D\u043E\u0432\u044B\u0445 \u043A\u043E\u043C\u043C\u0438\u0442\u043E\u0432 \u2014 \u043A\u0440\u0443\u0433 \u0440\u0435\u0432\u044C\u044E \u043D\u0435 \u0443\u0432\u0435\u043B\u0438\u0447\u0435\u043D (TASWM-666)"
17398
+ );
17399
+ }
17179
17400
  await store.updateRun(null, { ...t.patch, ...branchFix?.patch ?? {}, ...heldPatch });
17401
+ if (t.isFixIteration) {
17402
+ await store.addEvent(null, "step", reviewCycleOpenedText(t.cycle ?? 0, headCtx?.verdictSha));
17403
+ }
17180
17404
  await store.addEvent(null, "pr_opened", pr_url);
17181
17405
  await postReport(reportSlug(run2.task_slug), t.cycle ?? run2.review_cycle ?? 0);
17182
17406
  const rulesNote = await offerRules(reportSlug(run2.task_slug));
17183
17407
  const zoneNote = await zoneMemoryNote(reportSlug(run2.task_slug));
17408
+ const tail2 = `${shotsNote(shots)}${rulesNote}${zoneNote}`;
17184
17409
  if (t.isFixIteration) {
17185
- await store.addEvent(
17186
- null,
17187
- "step",
17188
- `\u0444\u0438\u043A\u0441-\u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044F: \u043D\u043E\u0432\u044B\u0435 \u043A\u043E\u043C\u043C\u0438\u0442\u044B \u043F\u043E\u0441\u043B\u0435 \u0432\u0435\u0440\u0434\u0438\u043A\u0442\u0430 \xAB\u043D\u0443\u0436\u043D\u044B \u043F\u0440\u0430\u0432\u043A\u0438\xBB \u2014 \u043E\u0442\u043A\u0440\u044B\u0442 \u0446\u0438\u043A\u043B \u0440\u0435-\u0440\u0435\u0432\u044C\u044E #${t.cycle}`
17189
- );
17190
- return { content: [{ type: "text", text: `\u043F\u0440\u0438\u043D\u044F\u0442\u043E, \u0443\u0448\u043B\u043E \u043D\u0430 \u0440\u0435-\u0440\u0435\u0432\u044C\u044E (\u0444\u0438\u043A\u0441-\u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044F)${shotsNote(shots)}${rulesNote}${zoneNote}` }] };
17410
+ return { content: [{ type: "text", text: `\u043F\u0440\u0438\u043D\u044F\u0442\u043E, \u0443\u0448\u043B\u043E \u043D\u0430 \u0440\u0435-\u0440\u0435\u0432\u044C\u044E (\u0444\u0438\u043A\u0441-\u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044F)${tail2}` }] };
17191
17411
  }
17192
- return { content: [{ type: "text", text: `\u043F\u0440\u0438\u043D\u044F\u0442\u043E, \u0443\u0448\u043B\u043E \u043D\u0430 \u0440\u0435\u0432\u044C\u044E${shotsNote(shots)}${rulesNote}${zoneNote}` }] };
17412
+ return { content: [{ type: "text", text: `\u043F\u0440\u0438\u043D\u044F\u0442\u043E, \u0443\u0448\u043B\u043E \u043D\u0430 \u0440\u0435\u0432\u044C\u044E${tail2}` }] };
17193
17413
  }
17194
17414
  await store.updateRun(null, { status: "review", pr_url, ...branchFix?.patch ?? {}, ...heldPatch });
17195
17415
  await store.addEvent(null, "pr_opened", pr_url);
@@ -17374,6 +17594,7 @@ async function runDroneServer(runId) {
17374
17594
  taskless,
17375
17595
  runKind: expectedKind,
17376
17596
  prHeadBranch,
17597
+ prHeadOid,
17377
17598
  ...expectedTaskSlug ? { expectedTaskSlug } : {},
17378
17599
  ...Number.isInteger(spawnReviewsRunId) && spawnReviewsRunId > 0 ? { reviewsRunId: spawnReviewsRunId } : {},
17379
17600
  ...Number.isInteger(spawnVerifiesRunId) && spawnVerifiesRunId > 0 ? { verifiesRunId: spawnVerifiesRunId } : {},
@@ -18563,6 +18784,14 @@ function makeMergeIntentResolver(deps) {
18563
18784
  reason: `\u043D\u0430 ${shortSha(sha)} \u0435\u0449\u0451 \u0438\u0434\u0443\u0442 \u043F\u0440\u043E\u0433\u043E\u043D\u044B GitHub Actions: ${runs.active.join(", ")} \u2014 \u0432\u0438\u0434\u0438\u043C\u044B\u0435 \u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0438 \u043C\u043E\u0433\u0443\u0442 \u0431\u044B\u0442\u044C \u0437\u0435\u043B\u0451\u043D\u044B\u043C\u0438, \u043F\u043E\u043A\u0430 \u0441\u043B\u0435\u0434\u0443\u044E\u0449\u0430\u044F \u0432\u043E\u043B\u043D\u0430 \u0434\u0436\u043E\u0431 \u043D\u0435 \u0441\u043E\u0437\u0434\u0430\u043D\u0430`
18564
18785
  };
18565
18786
  }
18787
+ const cancelled = runs.cancelled ?? [];
18788
+ if (cancelled.length > 0) {
18789
+ return {
18790
+ action: "wait",
18791
+ code: "checks_pending",
18792
+ reason: `\u043D\u0430 ${shortSha(sha)} \u043F\u0440\u043E\u0433\u043E\u043D GitHub Actions \u043E\u0442\u043C\u0435\u043D\u0451\u043D: ${cancelled.join(", ")} \u2014 \u044D\u0442\u043E \u043D\u0435 \u0437\u0435\u043B\u0451\u043D\u044B\u0439 CI, \u0436\u0434\u0443 \u043F\u0435\u0440\u0435\u0437\u0430\u043F\u0443\u0441\u043A\u0430`
18793
+ };
18794
+ }
18566
18795
  if (st.checks === "none") {
18567
18796
  if (runs.total > 0) {
18568
18797
  return { action: "wait", code: "checks_pending", reason: `\u043F\u0440\u043E\u0433\u043E\u043D\u044B GitHub Actions \u043D\u0430 ${shortSha(sha)} \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043B\u0438\u0441\u044C, \u0430 \u043F\u0440\u043E\u0432\u0435\u0440\u043E\u043A \u0443 PR \u0435\u0449\u0451 \u043D\u0435 \u0432\u0438\u0434\u043D\u043E \u2014 \u0436\u0434\u0443, \u043F\u043E\u043A\u0430 GitHub \u0438\u0445 \u043F\u043E\u043A\u0430\u0436\u0435\u0442` };
@@ -21944,6 +22173,87 @@ async function retireOutdatedReviewers(deps, run2) {
21944
22173
  narrate(deps, `${droneLabel(run2)}: \u0440\u0435\u0432\u044C\u044E\u0435\u0440 \u043F\u0440\u043E\u0448\u043B\u043E\u0433\u043E \u043A\u0440\u0443\u0433\u0430 \u0435\u0449\u0451 \u0436\u0438\u0432 \u2014 \u0437\u0430\u043A\u0440\u044B\u0432\u0430\u044E \u0435\u0433\u043E, \u0432\u0442\u043E\u0440\u043E\u0433\u043E \u043F\u043E\u0432\u0435\u0440\u0445 \u043D\u0435 \u0434\u0435\u0440\u0436\u0443.`);
21945
22174
  }
21946
22175
  }
22176
+ async function retireOutdatedVerifiers(deps, run2) {
22177
+ const cycle = run2.review_cycle ?? 0;
22178
+ const outdated = deps.db.activeVerifiersFor(run2.id).filter((v) => (v.review_cycle ?? 0) < cycle);
22179
+ for (const vr of outdated) {
22180
+ await supersedeChecker(
22181
+ deps,
22182
+ vr,
22183
+ `\u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0430 \u043F\u043E\u0448\u043B\u0430 \u043D\u0430 \u043D\u043E\u0432\u044B\u0439 \u043A\u0440\u0443\u0433 (\u0446\u0438\u043A\u043B ${vr.review_cycle ?? 0} \u2192 ${cycle}: \u0430\u0432\u0442\u043E\u0440 \u0441\u0434\u0430\u043B \u043F\u0440\u0430\u0432\u043A\u0438) \u2014 \u044D\u0442\u0430 \u043F\u043E\u043F\u044B\u0442\u043A\u0430 \u0437\u0430\u043A\u0440\u044B\u0442\u0430, \u0434\u0438\u0444 \u043F\u043E\u0434 \u043D\u0435\u0439 \u0443\u0436\u0435 \u0434\u0440\u0443\u0433\u043E\u0439`
22184
+ );
22185
+ deps.db.addEvent(run2.id, "step", `\u0432\u0435\u0440\u0438\u0444\u0438\u043A\u0430\u0442\u043E\u0440 ${vr.name} (#${vr.id}) \u043F\u0440\u043E\u0448\u043B\u043E\u0433\u043E \u0446\u0438\u043A\u043B\u0430 \u0437\u0430\u043A\u0440\u044B\u0442 \u2014 \u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0443 \u043F\u043E\u0434\u043D\u0438\u043C\u0435\u043C \u0441\u0432\u0435\u0436\u0435\u0439`);
22186
+ narrate(deps, `${droneLabel(run2)}: \u0432\u0435\u0440\u0438\u0444\u0438\u043A\u0430\u0442\u043E\u0440 \u043F\u0440\u043E\u0448\u043B\u043E\u0433\u043E \u043A\u0440\u0443\u0433\u0430 \u0435\u0449\u0451 \u0436\u0438\u0432 \u2014 \u0437\u0430\u043A\u0440\u044B\u0432\u0430\u044E \u0435\u0433\u043E, \u043F\u043E\u0437\u0434\u043D\u0438\u0439 \u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u043D\u0435 \u0437\u0430\u0441\u0447\u0438\u0442\u0430\u044E.`);
22187
+ }
22188
+ }
22189
+ async function supersedeChecker(deps, checker, reason) {
22190
+ if (checker.pid != null && deps.kill && deps.isAlive(checker.pid)) {
22191
+ try {
22192
+ deps.kill(checker.pid);
22193
+ } catch {
22194
+ }
22195
+ }
22196
+ if (checker.worktree_path) await deps.removeWorktree(checker.repo, checker.worktree_path).catch(() => {
22197
+ });
22198
+ deps.db.updateRun(checker.id, { status: "superseded", stop_reason: null });
22199
+ deps.db.addEvent(checker.id, "superseded", reason);
22200
+ }
22201
+ function staleDiscardKey(cycle, verdictSha) {
22202
+ return `[cycle ${cycle}] [head ${verdictSha}]`;
22203
+ }
22204
+ var DAEMON_STALE_HEAD_NOTE = "\u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u0441\u043D\u044F\u0442 \u043A\u0430\u043A \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0438\u0439, \u043D\u0443\u0436\u043D\u0430 \u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0430 \u0447\u0435\u043B\u043E\u0432\u0435\u043A\u043E\u043C";
22205
+ function isStaleDiscardEvent(text) {
22206
+ return isStaleHeadEvent(text) || (text ?? "").startsWith(DAEMON_STALE_HEAD_NOTE);
22207
+ }
22208
+ function lastStaleDiscardAt(events) {
22209
+ let at = null;
22210
+ for (const event of events) {
22211
+ if (isStaleDiscardEvent(event.text) && event.at) at = event.at;
22212
+ }
22213
+ return at;
22214
+ }
22215
+ function commentAfterStaleDiscard(events, createdAt) {
22216
+ const staleAt = lastStaleDiscardAt(events);
22217
+ if (!staleAt) return true;
22218
+ const commentMs = stampMs(createdAt);
22219
+ const staleMs = stampMs(staleAt);
22220
+ if (!Number.isFinite(commentMs) || !Number.isFinite(staleMs)) return false;
22221
+ return commentMs > staleMs;
22222
+ }
22223
+ function staleDiscardNote(restart) {
22224
+ return restart ? STALE_HEAD_VERDICT_MARK : DAEMON_STALE_HEAD_NOTE;
22225
+ }
22226
+ function noteVerdictCommentSeen(deps, runId, createdAt, restart = true) {
22227
+ const seen = verdictCommentMark(createdAt);
22228
+ if (deps.db.events(runId).some((e) => (e.text ?? "").includes(seen))) return;
22229
+ deps.db.addEvent(runId, "step", `${staleDiscardNote(restart)} [${seen}]`);
22230
+ }
22231
+ async function staleRestartPossible(deps, prUrl) {
22232
+ const st = await deps.prStatus(prUrl).catch(() => null);
22233
+ return !touchesDaemonCode(st?.files ?? []);
22234
+ }
22235
+ async function discardStaleChangesVerdict(deps, run2, verdictSha, headSha2, commentAt, opts) {
22236
+ deps.db.updateRun(run2.id, { review_verdict: null });
22237
+ const cycle = run2.review_cycle ?? 0;
22238
+ const key = staleDiscardKey(cycle, verdictSha);
22239
+ const restart = opts?.restart !== false;
22240
+ const note = staleDiscardNote(restart);
22241
+ const already = deps.db.events(run2.id).some((e) => (e.text ?? "").startsWith(note) && (e.text ?? "").includes(key));
22242
+ if (!already) {
22243
+ deps.db.addEvent(run2.id, "step", `${note}: \u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u043D\u0430 ${verdictSha.slice(0, 7)}, \u0433\u043E\u043B\u043E\u0432\u0430 PR ${headSha2.slice(0, 7)} ${key}`);
22244
+ }
22245
+ if (commentAt) noteVerdictCommentSeen(deps, run2.id, commentAt, restart);
22246
+ const delivered = deps.db.listRuns().filter(
22247
+ (r) => r.reviews_run_id === run2.id && (r.review_cycle ?? 0) === cycle && (r.status === "review" || r.status === "done")
22248
+ );
22249
+ for (const rv of delivered) {
22250
+ await supersedeChecker(deps, rv, `${note} \u2014 \u044D\u0442\u0430 \u0441\u0434\u0430\u0447\u0430 \u0441\u043C\u043E\u0442\u0440\u0435\u043B\u0430 \u043D\u0435 \u0442\u0443 \u0433\u043E\u043B\u043E\u0432\u0443`);
22251
+ }
22252
+ narrate(
22253
+ deps,
22254
+ restart ? `${droneLabel(run2)}: \u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u043D\u0430 \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0435\u0439 \u0433\u043E\u043B\u043E\u0432\u0435 \u2014 \u0430\u0432\u0442\u043E\u0440\u0430 \u043D\u0435 \u0431\u0443\u0436\u0443, \u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0443 \u043F\u043E\u0434\u043D\u0438\u043C\u0443 \u043D\u0430 \u0442\u0435\u043A\u0443\u0449\u0435\u0439.` : `${droneLabel(run2)}: \u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u0441\u043D\u044F\u0442 \u043A\u0430\u043A \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0438\u0439 \u2014 \u0430\u0432\u0442\u043E\u0440\u0430 \u043D\u0435 \u0431\u0443\u0436\u0443, \u043D\u0430 \u043A\u043E\u0434\u0435 \u0434\u0435\u043C\u043E\u043D\u0430 \u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0443 \u043D\u0435 \u043F\u043E\u0434\u043D\u0438\u043C\u0430\u044E, \u043D\u0443\u0436\u0435\u043D \u0447\u0435\u043B\u043E\u0432\u0435\u043A.`
22255
+ );
22256
+ }
21947
22257
  async function finalizeMergedReview(deps, run2, opts) {
21948
22258
  if (!opts?.workChecked) {
21949
22259
  const work = await taskWorkState(deps, run2.task_slug, run2.repo || "", run2.pr_url ?? null);
@@ -22340,8 +22650,32 @@ function promptStandRule(worktree, slug) {
22340
22650
  const prefix = composeProjectPrefix(basename7(raw));
22341
22651
  return prefix ? dockerStandRules(prefix, homedir10()) : "";
22342
22652
  }
22653
+ var FIX_NO_REVIEW_ITEMS = "\u0420\u0435\u0432\u044C\u044E\u0435\u0440 \u043F\u0440\u0430\u0432\u043E\u043A \u043D\u0435 \u043F\u0440\u043E\u0441\u0438\u043B.";
22654
+ var FIX_NO_VERIFY_ITEMS = "\u0412\u0435\u0440\u0438\u0444\u0438\u043A\u0430\u0442\u043E\u0440 \u043F\u043E\u0434\u0442\u0432\u0435\u0440\u0434\u0438\u043B \u2014 \u043E\u0442\u0434\u0435\u043B\u044C\u043D\u044B\u0445 \u043D\u0430\u0445\u043E\u0434\u043E\u043A \u043D\u0435\u0442.";
22655
+ var FIX_NO_VERDICT_YET = "\u0412\u0435\u0440\u0434\u0438\u043A\u0442\u0430 \u043D\u0430 \u044D\u0442\u0443 \u0433\u043E\u043B\u043E\u0432\u0443 \u043D\u0435\u0442.";
22656
+ var FIX_VERDICT_MISSING = "\u0412\u0435\u0440\u0434\u0438\u043A\u0442 \u043D\u0435 \u0441\u043E\u0445\u0440\u0430\u043D\u0438\u043B\u0441\u044F \u0432 \u043B\u0435\u043D\u0442\u0435 \u2014 \u0447\u0438\u0442\u0430\u0439 \u0435\u0433\u043E \u043A\u043E\u043C\u043C\u0435\u043D\u0442\u043E\u043C \u0432 PR (\u043A\u043E\u043C\u0430\u043D\u0434\u0430 \u043D\u0438\u0436\u0435).";
22657
+ function fixShaLine(sha) {
22658
+ return sha && /^[0-9a-f]{7,40}$/i.test(sha) ? `SHA: ${sha}` : "SHA: \u043D\u0435 \u0437\u0430\u043F\u0438\u0441\u0430\u043D";
22659
+ }
22660
+ function renderFixVerdicts(verdict, review, verify) {
22661
+ const reviewBody = review?.body?.trim() || null;
22662
+ const verifyBody = verify?.body?.trim() || null;
22663
+ if (review && verify && (reviewBody || verifyBody)) {
22664
+ return [
22665
+ "### \u041F\u0443\u043D\u043A\u0442\u044B \u0440\u0435\u0432\u044C\u044E\u0435\u0440\u0430",
22666
+ fixShaLine(review.sha),
22667
+ reviewBody ?? (review.recorded ? FIX_VERDICT_MISSING : FIX_NO_VERDICT_YET),
22668
+ "",
22669
+ "### \u041D\u0430\u0445\u043E\u0434\u043A\u0438 \u0432\u0435\u0440\u0438\u0444\u0438\u043A\u0430\u0442\u043E\u0440\u0430",
22670
+ fixShaLine(verify.sha),
22671
+ verifyBody ?? (verify.recorded ? FIX_VERDICT_MISSING : FIX_NO_VERDICT_YET)
22672
+ ].join("\n");
22673
+ }
22674
+ return verdict ?? FIX_VERDICT_MISSING;
22675
+ }
22343
22676
  function buildChangesFixPrompt(args) {
22344
- const { prUrl, slug, branch, base: base3, worktree, verdict } = args;
22677
+ const { prUrl, slug, branch, base: base3, worktree } = args;
22678
+ const verdictBlock = renderFixVerdicts(args.verdict, args.reviewSection, args.verifySection);
22345
22679
  const baseRef = base3 ? `origin/${base3}` : "origin/HEAD";
22346
22680
  const standRule = promptStandRule(worktree, slug);
22347
22681
  return [
@@ -22367,7 +22701,7 @@ function buildChangesFixPrompt(args) {
22367
22701
  "\u041C\u043E\u043B\u0447\u0430 \u043F\u0440\u043E\u043F\u0443\u0449\u0435\u043D\u043D\u044B\u0439 \u043F\u0443\u043D\u043A\u0442 \u2014 \u043D\u0435 \u0441\u0434\u0430\u043D\u043E.",
22368
22702
  "\u0415\u0441\u043B\u0438 \u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u0434\u0430\u0451\u0442 \u0433\u043E\u0442\u043E\u0432\u043E\u0435 \u0440\u0435\u0448\u0435\u043D\u0438\u0435 (\xAB\u0441\u0434\u0435\u043B\u0430\u0439 \u0442\u0430\u043A\xBB), \u0432\u044B\u043F\u043E\u043B\u043D\u0438 \u0435\u0433\u043E \u043A\u0430\u043A \u043D\u0430\u043F\u0438\u0441\u0430\u043D\u043E, \u0430 \u043D\u0435 \u043F\u043E-\u0441\u0432\u043E\u0435\u043C\u0443.",
22369
22703
  "",
22370
- verdict ?? "\u0412\u0435\u0440\u0434\u0438\u043A\u0442 \u043D\u0435 \u0441\u043E\u0445\u0440\u0430\u043D\u0438\u043B\u0441\u044F \u0432 \u043B\u0435\u043D\u0442\u0435 \u2014 \u0447\u0438\u0442\u0430\u0439 \u0435\u0433\u043E \u043A\u043E\u043C\u043C\u0435\u043D\u0442\u043E\u043C \u0432 PR (\u043A\u043E\u043C\u0430\u043D\u0434\u0430 \u043D\u0438\u0436\u0435).",
22704
+ verdictBlock,
22371
22705
  "",
22372
22706
  "## \u0412\u0432\u0435\u0434\u0438 \u0441\u0435\u0431\u044F \u0432 \u043A\u0443\u0440\u0441 \u0421\u0410\u041C \u2014 \u043F\u0430\u043C\u044F\u0442\u0438 \u043F\u0440\u043E\u0448\u043B\u043E\u0439 \u0441\u0435\u0441\u0441\u0438\u0438 \u0443 \u0442\u0435\u0431\u044F \u043D\u0435\u0442",
22373
22707
  "```",
@@ -23333,6 +23667,22 @@ async function handleCi(deps, run2, now, worktreeExists, hasTranscript, droneCap
23333
23667
  }
23334
23668
  return;
23335
23669
  }
23670
+ if (ci?.bucket === "cancelled") {
23671
+ const ids = ci.cancelledRunIds ?? [];
23672
+ const restarted = [];
23673
+ for (const id of ids) {
23674
+ const ok = deps.ci?.rerun ? await deps.ci.rerun(id, run2.pr_url).catch(() => false) : false;
23675
+ if (ok) restarted.push(id);
23676
+ }
23677
+ const names = (ci.cancelled ?? []).filter(Boolean).join(", ") || "\u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0438";
23678
+ const how = restarted.length > 0 ? `\u043F\u0435\u0440\u0435\u0437\u0430\u043F\u0443\u0441\u043A\u0430\u044E (${restarted.join(", ")})` : ids.length === 0 ? "\u043D\u0435\u0442 id \u043F\u0440\u043E\u0433\u043E\u043D\u0430 \u2014 \u043F\u0435\u0440\u0435\u0437\u0430\u043F\u0443\u0441\u0442\u0438\u0442\u044C \u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C" : "\u043F\u0435\u0440\u0435\u0437\u0430\u043F\u0443\u0441\u0442\u0438\u0442\u044C \u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C";
23679
+ deps.db.addEvent(run2.id, "ci_checked", `CI cancelled (${names}) \u2014 ${how}, \u043D\u0435 \u043A\u0440\u0430\u0441\u043D\u044B\u0439 [${CI_WAIT_POLL_MARK}]`);
23680
+ narrate(
23681
+ deps,
23682
+ restarted.length > 0 ? `${droneLabel(run2)}: CI \u043E\u0442\u043C\u0435\u043D\u0451\u043D \u2014 \u043F\u0435\u0440\u0435\u0437\u0430\u043F\u0443\u0441\u043A\u0430\u044E, \u043A\u0440\u0430\u0441\u043D\u044B\u043C \u043D\u0435 \u0441\u0447\u0438\u0442\u0430\u044E.` : `${droneLabel(run2)}: CI \u043E\u0442\u043C\u0435\u043D\u0451\u043D \u2014 \u043F\u0435\u0440\u0435\u0437\u0430\u043F\u0443\u0441\u0442\u0438\u0442\u044C \u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C, \u043A\u0440\u0430\u0441\u043D\u044B\u043C \u043D\u0435 \u0441\u0447\u0438\u0442\u0430\u044E.`
23683
+ );
23684
+ return;
23685
+ }
23336
23686
  if (ci?.bucket === "pass" && await wakeReviewerOnCiReady(deps, run2, { kind: "pass", ci })) return;
23337
23687
  const counts = ci && ci.total > 0 ? ` (${ci.pass}/${ci.total})` : "";
23338
23688
  const why = ci == null ? "\u043E\u043F\u0440\u043E\u0441 CI \u0441\u043E\u0440\u0432\u0430\u043B\u0441\u044F \u0446\u0435\u043B\u0438\u043A\u043E\u043C (checks \u0431\u0440\u043E\u0441\u0438\u043B) \u2014 \u0436\u0434\u0443 \u0441\u043B\u0435\u0434\u0443\u044E\u0449\u0435\u0433\u043E \u043E\u043F\u0440\u043E\u0441\u0430" : ciUnavailableNote(ci);
@@ -23876,8 +24226,17 @@ function tickAnomalyCandidates(autoReviewSnapshot) {
23876
24226
  }
23877
24227
  var DAEMON_CODE_FIX_HOLD_REASON = "PR \u0442\u0440\u043E\u0433\u0430\u0435\u0442 \u043A\u043E\u0434 \u0434\u0435\u043C\u043E\u043D\u0430 (TASWM-270) \u2014 \u043D\u0430\u0445\u043E\u0434\u043A\u0438 \u0432\u0435\u0440\u0438\u0444\u0438\u043A\u0430\u0442\u043E\u0440\u0430 \u0436\u0434\u0443\u0442 \u0440\u0435\u0448\u0435\u043D\u0438\u044F \u0447\u0435\u043B\u043E\u0432\u0435\u043A\u0430: \u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u0440\u0435\u0432\u044C\u044E \u0438\u043B\u0438 wake_run";
23878
24228
  async function liftFixIterationStep(deps, snapshot, st, _stormActive, now, droneCap) {
23879
- const run2 = deps.db.getRun(snapshot.id) ?? snapshot;
24229
+ let run2 = deps.db.getRun(snapshot.id) ?? snapshot;
23880
24230
  if (run2.status !== "review") return null;
24231
+ if (run2.review_verdict === "changes" && st.headSha) {
24232
+ const verdictSha = latestChangesVerdictSha(deps.db.events(run2.id));
24233
+ if (verdictSha && changesVerdictIsStale("changes", verdictSha, st.headSha)) {
24234
+ await discardStaleChangesVerdict(deps, run2, verdictSha, st.headSha, void 0, {
24235
+ restart: !touchesDaemonCode(st.files ?? [])
24236
+ });
24237
+ run2 = deps.db.getRun(run2.id) ?? run2;
24238
+ }
24239
+ }
23881
24240
  if (needsFixIteration(run2) && !stormHolds(deps, run2) && !st.conflicting && !deps.db.activeResolverFor(run2.id)) {
23882
24241
  const capFull = countActiveDrones(deps.db) >= droneCap;
23883
24242
  if (await wakeAuthorOnChanges(deps, run2, now, droneCap)) {
@@ -23889,6 +24248,27 @@ async function liftFixIterationStep(deps, snapshot, st, _stormActive, now, drone
23889
24248
  }
23890
24249
  return run2;
23891
24250
  }
24251
+ function sameCycleCheckerWorking(runs, cycle, respectAwaitingCi) {
24252
+ return runs.some((r) => {
24253
+ if ((r.review_cycle ?? 0) !== cycle) return false;
24254
+ if (r.status === "stalled") return false;
24255
+ if (r.status === "paused" && isLimitWait(r.stop_reason)) return false;
24256
+ if (respectAwaitingCi && isAwaitingCi(r.status, r.stop_reason)) return false;
24257
+ return true;
24258
+ });
24259
+ }
24260
+ function noteFixPartnerTimeout(deps, run2, waitingOn) {
24261
+ const cycle = run2.review_cycle ?? 0;
24262
+ const mark = `\u0432\u0442\u043E\u0440\u043E\u0439 \u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u0442\u043E\u0439 \u0436\u0435 \u0433\u043E\u043B\u043E\u0432\u044B \u043D\u0435 \u0434\u043E\u0436\u0434\u0430\u043B\u0438\u0441\u044C (\u043A\u0440\u0443\u0433 ${cycle})`;
24263
+ if (deps.db.events(run2.id).some((e) => (e.text ?? "").includes(mark))) return;
24264
+ const who = waitingOn === "verifier" ? "\u0432\u0435\u0440\u0438\u0444\u0438\u043A\u0430\u0442\u043E\u0440" : "\u0440\u0435\u0432\u044C\u044E\u0435\u0440";
24265
+ const mins = Math.max(1, Math.round(CHANGES_FRESH_WAKE_AFTER_MS / 6e4));
24266
+ deps.db.addEvent(
24267
+ run2.id,
24268
+ "step",
24269
+ `${mark}: ${who} \u0435\u0449\u0451 \u043D\u0435 \u0432\u044B\u043D\u0435\u0441 \u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u0437\u0430 ${mins} \u043C\u0438\u043D \u2014 \u0444\u0438\u043A\u0441-\u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044F \u0438\u0434\u0451\u0442 \u0441 \u0442\u0435\u043C, \u0447\u0442\u043E \u0435\u0441\u0442\u044C (TASWM-665)`
24270
+ );
24271
+ }
23892
24272
  async function wakeAuthorOnChanges(deps, snapshot, now, droneCap) {
23893
24273
  if (!deps.respawn) return false;
23894
24274
  const run2 = deps.db.getRun(snapshot.id);
@@ -23899,7 +24279,26 @@ async function wakeAuthorOnChanges(deps, snapshot, now, droneCap) {
23899
24279
  noteGrokBalanceSkip(deps, run2, "\u0444\u0438\u043A\u0441-\u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044E");
23900
24280
  return false;
23901
24281
  }
23902
- if (deps.db.activeReviewersFor(run2.id).some((r) => r.status !== "stalled" && !isAwaitingCi(r.status, r.stop_reason))) {
24282
+ const cycle = run2.review_cycle ?? 0;
24283
+ const reviewerWorking = run2.review_verdict == null && sameCycleCheckerWorking(deps.db.activeReviewersFor(run2.id), cycle, true);
24284
+ const verifierWorking = run2.verify_verdict == null && sameCycleCheckerWorking(deps.db.activeVerifiersFor(run2.id), cycle, false);
24285
+ const verdictAt = changesVerdictAt(deps.db, run2, now);
24286
+ const partner = fixPartnerHold({
24287
+ nowMs: now,
24288
+ // stampMs, не sqliteMs: у гидрированного прогона `at` бывает ISO, и sqliteMs даёт NaN.
24289
+ // NaN в fixPartnerHold — partial, а не вечное ожидание (метка гейт не держит).
24290
+ verdictAtMs: verdictAt ? stampMs(verdictAt) : null,
24291
+ waitMs: CHANGES_FRESH_WAKE_AFTER_MS,
24292
+ reviewVerdict: run2.review_verdict,
24293
+ verifyVerdict: run2.verify_verdict,
24294
+ reviewerWorking,
24295
+ verifierWorking
24296
+ });
24297
+ if (partner.action === "wait") return false;
24298
+ const gaveUpOnReviewer = partner.action === "partial" && partner.waitingOn === "reviewer";
24299
+ if (!gaveUpOnReviewer && deps.db.activeReviewersFor(run2.id).some(
24300
+ (r) => r.status !== "stalled" && !isAwaitingCi(r.status, r.stop_reason) && !(r.status === "paused" && isLimitWait(r.stop_reason))
24301
+ )) {
23903
24302
  return blockFix(run2, "\u0440\u0435\u0432\u044C\u044E\u0435\u0440 \u0435\u0449\u0451 \u0432 \u0440\u0430\u0431\u043E\u0442\u0435");
23904
24303
  }
23905
24304
  if (deps.resourcesOk && !deps.resourcesOk()) return blockFix(run2, "\u043C\u0430\u0448\u0438\u043D\u0430 \u043F\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0435\u043D\u0430");
@@ -23979,6 +24378,7 @@ async function wakeAuthorOnChanges(deps, snapshot, now, droneCap) {
23979
24378
  if (run2.stop_reason != null) deps.db.updateRun(run2.id, { stop_reason: null });
23980
24379
  const how = worktreeReady ? "\u0441\u0432\u0435\u0436\u0438\u0439 \u0434\u0440\u043E\u043D \u0441 \u0431\u0440\u0438\u0444\u043E\u043C \u0444\u0438\u043A\u0441-\u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u0432 \u0442\u043E\u043C \u0436\u0435 worktree" : "\u0441\u0432\u0435\u0436\u0438\u0439 \u0434\u0440\u043E\u043D \u0441 \u0431\u0440\u0438\u0444\u043E\u043C \u0444\u0438\u043A\u0441-\u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438, worktree \u043F\u0435\u0440\u0435-\u0441\u043E\u0437\u0434\u0430\u0451\u0442\u0441\u044F \u0441 origin";
23981
24380
  deps.db.addEvent(run2.id, "resumed", `${CHANGES_WAKE_MARK} \u2014 ${how}`);
24381
+ if (partner.action === "partial") noteFixPartnerTimeout(deps, run2, partner.waitingOn);
23982
24382
  narrate(deps, `\u0420\u0435\u0432\u044C\u044E\u0435\u0440 \u043F\u043E\u043F\u0440\u043E\u0441\u0438\u043B \u043F\u0440\u0430\u0432\u043A\u0438 \u0443 ${droneLabel(run2)} \u2014 \u043F\u043E\u0434\u043D\u0438\u043C\u0430\u044E \u0441\u0432\u0435\u0436\u0435\u0433\u043E \u0434\u0440\u043E\u043D\u0430 \u043D\u0430 \u0444\u0438\u043A\u0441-\u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044E.`);
23983
24383
  return true;
23984
24384
  } catch (e) {
@@ -25099,7 +25499,10 @@ async function worktreeBranchFor(run2, prHead) {
25099
25499
  return fromPr || run2.task_slug;
25100
25500
  }
25101
25501
  async function adoptDroneToReview(deps, run2, prUrl) {
25102
- const t = applyReviewTransition(deps.db, run2, prUrl);
25502
+ const headOid = deps.prHeadOid ? await deps.prHeadOid(prUrl).catch(() => null) : null;
25503
+ const headCtx = headOid ? reviewHeadContext(deps.db.events(run2.id), headOid) : void 0;
25504
+ const t = applyReviewTransition(deps.db, run2, prUrl, headCtx);
25505
+ if (t.isFixIteration) deps.db.addEvent(run2.id, "step", reviewCycleOpenedText(t.cycle ?? 0, headCtx?.verdictSha));
25103
25506
  const adopted = syncBranchFromPr(deps.db, run2, deps.prHeadBranch ? await deps.prHeadBranch(prUrl).catch(() => null) : null);
25104
25507
  deps.db.addEvent(run2.id, "pr_opened", prUrl);
25105
25508
  deps.db.addEvent(
@@ -25145,20 +25548,24 @@ function clipPickupBody(body) {
25145
25548
  const headLen = Math.max(0, PICKUP_BODY_MAX - note.length - tail2.length);
25146
25549
  return body.slice(0, headLen) + note + tail2;
25147
25550
  }
25148
- function pickedVerdictEventText(how, verdict, body, mark) {
25551
+ function pickedVerdictEventText(how, verdict, body, mark, sha) {
25149
25552
  const review = verdict === "approve" || verdict === "changes";
25150
25553
  const prefix = review ? PICKUP_EVENT_PREFIX : VERIFY_PICKUP_EVENT_PREFIX;
25151
25554
  const label2 = review ? verdictLabel(verdict) : verifyVerdictLabel(verdict);
25152
25555
  const trimmed = body?.trim() ?? "";
25153
25556
  const payload = trimmed ? clipPickupBody(trimmed) : label2;
25154
25557
  const tail2 = mark ? ` [${mark}]` : "";
25155
- return `${prefix} (${how}): ${payload}${tail2}`;
25558
+ return `${markVerdictHead(`${prefix} (${how}): ${payload}`, sha)}${tail2}`;
25559
+ }
25560
+ async function checkerHeadSha(worktree) {
25561
+ if (!worktree) return null;
25562
+ return headSha(worktree);
25156
25563
  }
25157
25564
  function verdictEventPayload(text) {
25158
25565
  const sep4 = text.startsWith(PICKUP_EVENT_PREFIX) ? "): " : ": ";
25159
25566
  const at = text.indexOf(sep4);
25160
25567
  if (at < 0) return "";
25161
- return text.slice(at + sep4.length).trim().replace(/\s+\[[^\]]*\]\s*$/, "").trim();
25568
+ return stripVerdictHead(text.slice(at + sep4.length).replace(/\s+\[[^\]]*\]\s*$/, "")).trim();
25162
25569
  }
25163
25570
  function isHeaderOnlyVerdict(text) {
25164
25571
  if (!text.startsWith(PICKUP_EVENT_PREFIX) && !text.startsWith("\u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u0440\u0435\u0432\u044C\u044E \u043E\u0442")) return false;
@@ -25172,7 +25579,7 @@ function isVerifyHeaderOnly(text) {
25172
25579
  const sep4 = pickup ? "): " : ": ";
25173
25580
  const at = text.indexOf(sep4);
25174
25581
  if (at < 0) return true;
25175
- const rest = text.slice(at + sep4.length).trim().replace(/\s+\[[^\]]*\]\s*$/, "").trim();
25582
+ const rest = stripVerdictHead(text.slice(at + sep4.length).replace(/\s+\[[^\]]*\]\s*$/, "")).trim();
25176
25583
  return rest.length === 0 || VERIFY_HEADER_LABELS.has(rest);
25177
25584
  }
25178
25585
  function isClippedPickup(text) {
@@ -25187,10 +25594,29 @@ async function salvageVerdictFromPrComment(deps, rv, reviewsRunId, since, ctx) {
25187
25594
  if (!deps.verdictComment || !rv.pr_url) return false;
25188
25595
  const found = await deps.verdictComment(rv.pr_url, since).catch(() => null);
25189
25596
  if (!found) return false;
25597
+ const commentSha = await checkerHeadSha(rv.worktree_path);
25598
+ const prHead = deps.prHeadOid ? await deps.prHeadOid(rv.pr_url).catch(() => null) : null;
25599
+ const fresh = commentAfterStaleDiscard(deps.db.events(reviewsRunId), found.createdAt);
25600
+ const stale = found.verdict === "changes" && changesVerdictIsStale("changes", commentSha, prHead);
25601
+ if (found.verdict === "changes" && (stale || !fresh)) {
25602
+ const reviewedNow = deps.db.getRun(reviewsRunId);
25603
+ const restart = await staleRestartPossible(deps, rv.pr_url);
25604
+ if (stale && reviewedNow && commentSha && prHead) {
25605
+ await discardStaleChangesVerdict(deps, reviewedNow, commentSha, prHead, found.createdAt, { restart });
25606
+ } else {
25607
+ noteVerdictCommentSeen(deps, reviewsRunId, found.createdAt, restart);
25608
+ }
25609
+ await supersedeChecker(deps, rv, `${staleDiscardNote(restart)} \u2014 \u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u043A\u043E\u043C\u043C\u0435\u043D\u0442\u043E\u043C \u0441\u043C\u043E\u0442\u0440\u0435\u043B \u043D\u0435 \u0442\u0443 \u0433\u043E\u043B\u043E\u0432\u0443`);
25610
+ return true;
25611
+ }
25190
25612
  const verdictText = verdictLabel(found.verdict);
25191
25613
  deps.db.updateRun(reviewsRunId, { review_verdict: found.verdict });
25192
25614
  recordReviewFindings(deps, rv, found);
25193
- deps.db.addEvent(reviewsRunId, "step", pickedVerdictEventText(ctx.how, found.verdict, found.body));
25615
+ deps.db.addEvent(
25616
+ reviewsRunId,
25617
+ "step",
25618
+ pickedVerdictEventText(ctx.how, found.verdict, found.body, void 0, commentSha)
25619
+ );
25194
25620
  await closeReviewerRun(
25195
25621
  deps,
25196
25622
  rv,
@@ -25210,9 +25636,23 @@ async function salvageVerifyVerdictFromPrComment(deps, vr, verifiesRunId, since,
25210
25636
  if (!deps.verifyVerdictComment || !vr.pr_url) return false;
25211
25637
  const found = await deps.verifyVerdictComment(vr.pr_url, since).catch(() => null);
25212
25638
  if (!found) return false;
25639
+ const parent = deps.db.getRun(verifiesRunId);
25640
+ if (parent && (vr.review_cycle ?? 0) < (parent.review_cycle ?? 0)) {
25641
+ await supersedeChecker(
25642
+ deps,
25643
+ vr,
25644
+ `\u0432\u0435\u0440\u0438\u0444\u0438\u043A\u0430\u0442\u043E\u0440 \u043F\u0440\u043E\u0448\u043B\u043E\u0433\u043E \u043A\u0440\u0443\u0433\u0430 (${vr.review_cycle ?? 0}) \u0437\u0430\u043A\u0440\u044B\u0442: \u0430\u0432\u0442\u043E\u0440 \u0443\u0436\u0435 \u043D\u0430 \u043A\u0440\u0443\u0433\u0435 ${parent.review_cycle ?? 0}, \u043F\u043E\u0437\u0434\u043D\u0438\u0439 \u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u043D\u0435 \u0437\u0430\u0441\u0447\u0438\u0442\u0430\u043D`
25645
+ );
25646
+ deps.db.addEvent(verifiesRunId, "step", `\u043F\u043E\u0437\u0434\u043D\u0438\u0439 \u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u0432\u0435\u0440\u0438\u0444\u0438\u043A\u0430\u0442\u043E\u0440\u0430 ${vr.name} \u043F\u0440\u043E\u0448\u043B\u043E\u0433\u043E \u043A\u0440\u0443\u0433\u0430 \u043D\u0435 \u0437\u0430\u0441\u0447\u0438\u0442\u0430\u043D \u0438 \u0444\u0438\u043A\u0441-\u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044E \u043D\u0435 \u043E\u0442\u043A\u0440\u044B\u0432\u0430\u0435\u0442`);
25647
+ return true;
25648
+ }
25213
25649
  const verdictText = verifyVerdictLabel(found.verdict);
25214
25650
  deps.db.updateRun(verifiesRunId, { verify_verdict: found.verdict });
25215
- deps.db.addEvent(verifiesRunId, "step", pickedVerdictEventText(how, found.verdict, found.body));
25651
+ deps.db.addEvent(
25652
+ verifiesRunId,
25653
+ "step",
25654
+ pickedVerdictEventText(how, found.verdict, found.body, void 0, await checkerHeadSha(vr.worktree_path))
25655
+ );
25216
25656
  await closeReviewerRun(deps, vr, `\u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u0432\u044B\u043D\u0435\u0441\u0435\u043D \u043A\u043E\u043C\u043C\u0435\u043D\u0442\u043E\u043C (${verdictText}), ${how} \u2014 \u0432\u0435\u0440\u0438\u0444\u0438\u043A\u0430\u0446\u0438\u044F \u0437\u0430\u043A\u0440\u044B\u0442\u0430 \u0431\u0435\u0437 \u0441\u043F\u0430\u0432\u043D\u0430 \u0432\u0442\u043E\u0440\u043E\u0433\u043E \u0432\u0435\u0440\u0438\u0444\u0438\u043A\u0430\u0442\u043E\u0440\u0430`);
25217
25657
  narrate(deps, `${droneLabel(vr)} \u043E\u0441\u0442\u0430\u0432\u0438\u043B \u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u0432\u0435\u0440\u0438\u0444\u0438\u043A\u0430\u0446\u0438\u0438 (${verdictText}) \u043A\u043E\u043C\u043C\u0435\u043D\u0442\u043E\u043C \u2014 \u0437\u0430\u0441\u0447\u0438\u0442\u0430\u043B, \u0432\u0442\u043E\u0440\u043E\u0433\u043E \u0432\u0435\u0440\u0438\u0444\u0438\u043A\u0430\u0442\u043E\u0440\u0430 \u043D\u0435 \u043F\u043E\u0434\u043D\u0438\u043C\u0430\u044E.`);
25218
25658
  return true;
@@ -25489,6 +25929,18 @@ async function maybeRearmCycleStop(deps, run2, now, key, episodes) {
25489
25929
  }
25490
25930
  if (moved) episodes.rearm(key);
25491
25931
  }
25932
+ function reviewerCancelledWhat(deps, parent) {
25933
+ let last = "";
25934
+ if (parent) {
25935
+ for (const event of deps.db.events(parent.id)) {
25936
+ const text = event.text ?? "";
25937
+ if (text.startsWith("CI cancelled")) last = text;
25938
+ }
25939
+ }
25940
+ if (last.includes("\u043F\u0435\u0440\u0435\u0437\u0430\u043F\u0443\u0441\u0442\u0438\u0442\u044C \u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C")) return "CI \u043E\u0442\u043C\u0435\u043D\u0451\u043D \u2014 \u043F\u0435\u0440\u0435\u0437\u0430\u043F\u0443\u0441\u0442\u0438\u0442\u044C \u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C, \u043D\u0435 \u043A\u0440\u0430\u0441\u043D\u044B\u0439";
25941
+ if (last.includes("\u043F\u0435\u0440\u0435\u0437\u0430\u043F\u0443\u0441\u043A\u0430\u044E")) return "CI \u043E\u0442\u043C\u0435\u043D\u0451\u043D \u2014 \u043F\u0435\u0440\u0435\u0437\u0430\u043F\u0443\u0441\u043A\u0430\u044E, \u043D\u0435 \u043A\u0440\u0430\u0441\u043D\u044B\u0439";
25942
+ return "CI \u043E\u0442\u043C\u0435\u043D\u0451\u043D \u2014 \u043D\u0435 \u043A\u0440\u0430\u0441\u043D\u044B\u0439, \u0436\u0434\u0443 \u043F\u0435\u0440\u0435\u0437\u0430\u043F\u0443\u0441\u043A\u0430";
25943
+ }
25492
25944
  async function tickOnce(deps) {
25493
25945
  const now = deps.now ? deps.now() : Date.now();
25494
25946
  beginGhMergePass(deps.ghMerges);
@@ -25731,6 +26183,7 @@ async function tickOnce(deps) {
25731
26183
  continue;
25732
26184
  }
25733
26185
  if (touchesDaemonCode(st.files ?? [])) {
26186
+ await retireOutdatedVerifiers(deps, run2);
25734
26187
  const already = deps.db.events(run2.id).some((e) => (e.text ?? "").includes(SELF_REFERENCE_MARK));
25735
26188
  if (!already) {
25736
26189
  const signal = {
@@ -25761,6 +26214,7 @@ async function tickOnce(deps) {
25761
26214
  continue;
25762
26215
  }
25763
26216
  await retireOutdatedReviewers(deps, run2);
26217
+ await retireOutdatedVerifiers(deps, run2);
25764
26218
  let intentBaseStale = false;
25765
26219
  if (hasMergeIntent(run2)) {
25766
26220
  const drop = mergeIntentDropReason(deps, run2, st.conflicting === true);
@@ -25864,6 +26318,23 @@ async function tickOnce(deps) {
25864
26318
  lastAttempt = deps.db.lastReviewerAttemptFor(run2.id);
25865
26319
  verdictFromComment = await deps.verdictComment(prUrl, lastAttempt?.created_at ?? run2.created_at).catch(() => null);
25866
26320
  }
26321
+ if (verdictFromComment?.verdict === "changes") {
26322
+ const commentSha = await checkerHeadSha(lastAttempt?.worktree_path);
26323
+ const stale = !!(commentSha && st.headSha && changesVerdictIsStale("changes", commentSha, st.headSha));
26324
+ const fresh = commentAfterStaleDiscard(deps.db.events(run2.id), verdictFromComment.createdAt);
26325
+ if (stale || !fresh) {
26326
+ if (stale && commentSha && st.headSha) {
26327
+ await discardStaleChangesVerdict(deps, run2, commentSha, st.headSha, verdictFromComment.createdAt);
26328
+ } else {
26329
+ noteVerdictCommentSeen(deps, run2.id, verdictFromComment.createdAt);
26330
+ }
26331
+ if (lastAttempt && (lastAttempt.status === "review" || lastAttempt.status === "done")) {
26332
+ await supersedeChecker(deps, lastAttempt, `${STALE_HEAD_VERDICT_MARK} \u2014 \u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u043A\u043E\u043C\u043C\u0435\u043D\u0442\u043E\u043C \u0441\u043C\u043E\u0442\u0440\u0435\u043B \u043D\u0435 \u0442\u0443 \u0433\u043E\u043B\u043E\u0432\u0443`);
26333
+ }
26334
+ verdictFromComment = null;
26335
+ run2 = deps.db.getRun(run2.id) ?? run2;
26336
+ }
26337
+ }
25867
26338
  if (verdictFromComment) {
25868
26339
  const mark = verdictCommentMark(verdictFromComment.createdAt);
25869
26340
  const alreadyProcessed = deps.db.events(run2.id).some((e) => (e.text ?? "").includes(mark));
@@ -25873,7 +26344,13 @@ async function tickOnce(deps) {
25873
26344
  deps.db.addEvent(
25874
26345
  run2.id,
25875
26346
  "step",
25876
- pickedVerdictEventText("done() \u0431\u044B\u043B \u043D\u0435\u0434\u043E\u0441\u0442\u0443\u043F\u0435\u043D \u0440\u0435\u0432\u044C\u044E\u0435\u0440\u0443", verdictFromComment.verdict, verdictFromComment.body, mark)
26347
+ pickedVerdictEventText(
26348
+ "done() \u0431\u044B\u043B \u043D\u0435\u0434\u043E\u0441\u0442\u0443\u043F\u0435\u043D \u0440\u0435\u0432\u044C\u044E\u0435\u0440\u0443",
26349
+ verdictFromComment.verdict,
26350
+ verdictFromComment.body,
26351
+ mark,
26352
+ await checkerHeadSha(lastAttempt?.worktree_path)
26353
+ )
25877
26354
  );
25878
26355
  narrate(deps, `\u0420\u0435\u0432\u044C\u044E ${droneLabel(run2)} \u2014 \u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u043D\u0430\u0448\u0451\u043B\u0441\u044F \u0432 \u043A\u043E\u043C\u043C\u0435\u043D\u0442\u0430\u0445 PR (${verdictText}), \u0440\u0435\u0441\u043F\u0430\u0432\u043D \u043D\u0435 \u043D\u0443\u0436\u0435\u043D.`);
25879
26356
  await postScrapedVerdictReport(deps, run2.id, run2.task_slug, verdictFromComment.verdict, lastAttempt?.name || "(\u0438\u043C\u044F \u043D\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043D\u043E)", run2.workspace_id, run2.review_cycle ?? 0);
@@ -26141,12 +26618,12 @@ async function tickOnce(deps) {
26141
26618
  const ciWatchOff = parent != null && ciWatchClosed(deps.db, parent);
26142
26619
  const ci = ciWatchOff ? null : await deps.ci.checks(run2.pr_url).catch(() => null);
26143
26620
  const noCiRepo = ci?.bucket === "none" && !repoHasCi(deps, run2);
26144
- if (!ciWatchOff && !noCiRepo && (ci == null || ci.bucket === "pending" || ci.bucket === "none" || ci.bucket === "denied" || ci.bucket === "unavailable")) {
26621
+ if (!ciWatchOff && !noCiRepo && (ci == null || ci.bucket === "pending" || ci.bucket === "none" || ci.bucket === "denied" || ci.bucket === "unavailable" || ci.bucket === "cancelled")) {
26145
26622
  const what = ci == null ? "gh \u043D\u0435 \u043E\u0442\u0432\u0435\u0442\u0438\u043B \u043F\u0440\u043E \u0447\u0435\u043A\u0438 \u2014 \u0436\u0434\u0443, \u043F\u043E\u043A\u0430 \u043F\u0440\u043E\u044F\u0441\u043D\u0438\u0442\u0441\u044F" : ci.bucket === "none" ? "\u0447\u0435\u043A\u043E\u0432 \u043D\u0430 PR \u043F\u043E\u043A\u0430 \u043D\u0435 \u0432\u0438\u0434\u043D\u043E \u2014 \u043D\u0438 \u043E\u0434\u043D\u043E\u0433\u043E \u0447\u0435\u043A-\u0440\u0430\u043D\u0430, \u043D\u043E workflow \u0432 \u0440\u0435\u043F\u043E\u0437\u0438\u0442\u043E\u0440\u0438\u0438 \u0435\u0441\u0442\u044C" : ci.bucket === "denied" ? `\u0447\u0435\u043A\u0438 \u0440\u043E\u044E \u043D\u0435 \u0432\u0438\u0434\u043D\u044B: GitHub \u043E\u0442\u043A\u0430\u0437\u0430\u043B \u043F\u043E \u043F\u0440\u0430\u0432\u0430\u043C (403)${ci.detail ? ` \u2014 ${ci.detail}` : ""}` : (
26146
26623
  // TASWM-497: и здесь причина СЛОВАМИ, а не общее «gh не ответил». Тот же словарь,
26147
26624
  // что в ленте опроса (callFailureWord), чтобы одно и то же состояние в журнале
26148
26625
  // прогона и в событии парковки не называлось двумя разными способами.
26149
- ci.bucket === "unavailable" ? `\u0441\u043F\u0440\u043E\u0441\u0438\u0442\u044C \u0447\u0435\u043A\u0438 \u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C: gh ${callFailureWord({ reason: ci.reason ?? "empty", detail: "" })}${ci.detail ? ` \u2014 ${ci.detail}` : ""}` : `CI ${ci.pass}/${ci.total}`
26626
+ ci.bucket === "unavailable" ? `\u0441\u043F\u0440\u043E\u0441\u0438\u0442\u044C \u0447\u0435\u043A\u0438 \u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C: gh ${callFailureWord({ reason: ci.reason ?? "empty", detail: "" })}${ci.detail ? ` \u2014 ${ci.detail}` : ""}` : ci.bucket === "cancelled" ? reviewerCancelledWhat(deps, parent) : `CI ${ci.pass}/${ci.total}`
26150
26627
  );
26151
26628
  deps.db.updateRun(run2.id, { status: "paused", stop_reason: AWAITING_CI_REASON });
26152
26629
  deps.db.addEvent(run2.id, "paused", `${AWAITING_CI_REASON} (${what}) \u2014 \u043D\u0435 \u0441\u043C\u0435\u0440\u0442\u044C: \u0440\u0430\u0437\u0431\u0443\u0436\u0443 \u0441\u0430\u043C, \u043A\u043E\u0433\u0434\u0430 \u0447\u0435\u043A\u0438 \u0434\u043E\u0439\u0434\u0443\u0442 \u0434\u043E \u043A\u043E\u043D\u0446\u0430`);
@@ -26568,7 +27045,7 @@ function makeCheckerAttachmentsReader(tl) {
26568
27045
  async function spawnReviewer(deps, reviewRun, files) {
26569
27046
  const repo = normalizeRepo(reviewRun.repo || deps.repoFallback);
26570
27047
  const branch = await worktreeBranchFor(reviewRun, deps.prHeadBranch);
26571
- const priorReview = reviewRun.review_cycle > 0 ? lastChangesSummary(deps.db, reviewRun.id) : null;
27048
+ const priorReview = reviewRun.review_cycle > 0 ? stripVerdictHead(lastChangesSummary(deps.db, reviewRun.id) ?? "") || null : null;
26572
27049
  const verifyMode = deps.verifyMode ? await deps.verifyMode(repo, reviewRun.task_slug).catch(() => void 0) : void 0;
26573
27050
  const ciClosed = verifyMode === "local" ? null : ciWatchCloseKind(deps.db, reviewRun);
26574
27051
  const checklist = buildReviewChecklist(reviewRun, files, priorReview, verifyMode, ciClosed);
@@ -26696,31 +27173,52 @@ async function spawnVerifier(deps, verifiedRun, files) {
26696
27173
  }
26697
27174
  function lastSubmissionSince(db, run2) {
26698
27175
  const events = db.events(run2.id);
26699
- for (let i = events.length - 1; i >= 0; i--) {
26700
- const kind = events[i].kind;
26701
- if (kind === "pr_opened" || kind === "done") return events[i].at;
26702
- }
27176
+ const boundary = feedBoundaryIndex(events);
27177
+ if (boundary >= 0) return events[boundary].at;
26703
27178
  return run2.created_at;
26704
27179
  }
26705
- async function verdictTextForFixBrief(deps, run2) {
26706
- const fromFeed = lastChangesSummary(deps.db, run2.id);
26707
- const feedBlocked = !!fromFeed && (isHeaderOnlyVerdict(fromFeed) || verdictEventIsApprove(fromFeed));
26708
- if (fromFeed && !feedBlocked) {
26709
- if (!isClippedPickup(fromFeed)) return fromFeed;
26710
- return await fullReviewComment(deps, run2) ?? fromFeed;
26711
- }
26712
- if (run2.review_verdict !== "changes") {
26713
- const verify = lastVerifySummary(deps.db, run2.id);
26714
- if (verify) {
26715
- const headerOnly = isVerifyHeaderOnly(verify);
26716
- if (headerOnly || isClippedPickup(verify)) {
26717
- const fromVerify = await fullVerifyComment(deps, run2);
26718
- if (fromVerify) return fromVerify;
26719
- }
26720
- if (!headerOnly) return verify;
26721
- }
27180
+ function lastTextThisHead(db, runId, match) {
27181
+ const events = db.events(runId);
27182
+ const boundary = feedBoundaryIndex(events);
27183
+ for (let i = events.length - 1; i > boundary; i--) {
27184
+ const text = events[i].text ?? "";
27185
+ if (match(text)) return text;
26722
27186
  }
26723
- return fullReviewComment(deps, run2);
27187
+ return null;
27188
+ }
27189
+ async function reviewSectionForFix(deps, run2) {
27190
+ const fromFeed = lastTextThisHead(deps.db, run2.id, isVerdictEventText);
27191
+ const sha = verdictEventSha(fromFeed);
27192
+ const approveFeed = !!fromFeed && verdictEventIsApprove(fromFeed);
27193
+ if (run2.review_verdict === "approve" || run2.review_verdict !== "changes" && approveFeed) {
27194
+ const comment2 = await fullReviewComment(deps, run2);
27195
+ if (comment2) return { body: stripVerdictHead(comment2), sha };
27196
+ return { body: FIX_NO_REVIEW_ITEMS, sha };
27197
+ }
27198
+ if (fromFeed && !isHeaderOnlyVerdict(fromFeed)) {
27199
+ const raw = isClippedPickup(fromFeed) ? await fullReviewComment(deps, run2) ?? fromFeed : fromFeed;
27200
+ return { body: stripVerdictHead(raw), sha };
27201
+ }
27202
+ const comment = await fullReviewComment(deps, run2);
27203
+ if (comment) return { body: stripVerdictHead(comment), sha };
27204
+ return { body: null, sha, recorded: run2.review_verdict === "changes" };
27205
+ }
27206
+ async function verifySectionForFix(deps, run2) {
27207
+ const fromFeed = lastTextThisHead(deps.db, run2.id, (text) => VERIFY_EVENT_PREFIXES.some((p) => text.startsWith(p)));
27208
+ const sha = verdictEventSha(fromFeed);
27209
+ if (run2.verify_verdict === "confirmed") return { body: FIX_NO_VERIFY_ITEMS, sha };
27210
+ if (fromFeed && !isVerifyHeaderOnly(fromFeed)) {
27211
+ const raw = isClippedPickup(fromFeed) ? await fullVerifyComment(deps, run2) ?? fromFeed : fromFeed;
27212
+ return { body: stripVerdictHead(raw), sha };
27213
+ }
27214
+ const comment = await fullVerifyComment(deps, run2);
27215
+ if (comment) return { body: stripVerdictHead(comment), sha };
27216
+ return { body: null, sha, recorded: isNegativeVerifyVerdict(run2.verify_verdict) };
27217
+ }
27218
+ async function fixBriefParts(deps, run2) {
27219
+ const review = await reviewSectionForFix(deps, run2);
27220
+ const verify = await verifySectionForFix(deps, run2);
27221
+ return { verdict: null, review, verify };
26724
27222
  }
26725
27223
  async function fullReviewComment(deps, run2) {
26726
27224
  if (!deps.verdictComment || !run2.pr_url) return null;
@@ -26785,13 +27283,16 @@ async function respawnRun(deps, run2, mode, nudge) {
26785
27283
  fetchFile: deps.fetchFile,
26786
27284
  onEvent: (text) => deps.db.addEvent(run2.id, "step", text)
26787
27285
  });
27286
+ const fixParts = mode === "fix" ? await fixBriefParts(deps, runToSpawn) : null;
26788
27287
  const freshPrompt = mode === "fix" ? buildChangesFixPrompt({
26789
27288
  prUrl: runToSpawn.pr_url ?? "",
26790
27289
  slug: runToSpawn.task_slug,
26791
27290
  branch: runToSpawn.branch || runToSpawn.task_slug,
26792
27291
  base: base3 || "",
26793
27292
  worktree: wt,
26794
- verdict: await verdictTextForFixBrief(deps, runToSpawn),
27293
+ verdict: fixParts.verdict,
27294
+ reviewSection: fixParts.review,
27295
+ verifySection: fixParts.verify,
26795
27296
  name: runToSpawn.name,
26796
27297
  taskTitle: task?.title ?? null,
26797
27298
  taskUrl: task?.url ?? null,
@@ -27539,6 +28040,7 @@ async function runDaemon(opts) {
27539
28040
  checks: async (url) => {
27540
28041
  const ci = await prCiStatus(url);
27541
28042
  if (ci.bucket === "denied" || ci.bucket === "unavailable") return null;
28043
+ if (ci.bucket === "cancelled") return { bucket: "pending" };
27542
28044
  return { bucket: ci.bucket };
27543
28045
  },
27544
28046
  // TASWM-577: прогоны GitHub Actions на HEAD — только вливанию по намерению: рой
@@ -27610,7 +28112,7 @@ async function runDaemon(opts) {
27610
28112
  if (task) db.updateRun(run2.id, { task_title: task.title, task_desc: task.description, task_url: task.url });
27611
28113
  if (taskClient) await taskClient.startTask(runToSpawn.task_slug);
27612
28114
  },
27613
- prStatus: (url) => prStatus(url).then((s) => ({ merged: s.merged, conflicting: s.conflicting, isDraft: s.isDraft, files: s.files, state: s.state, headBranch: s.headBranch })),
28115
+ prStatus: (url) => prStatus(url).then((s) => ({ merged: s.merged, conflicting: s.conflicting, isDraft: s.isDraft, files: s.files, state: s.state, headBranch: s.headBranch, headSha: s.headSha })),
27614
28116
  // Открытые PR ветки прогона (готча №14): gh pr list --head <slug> в репо прогона
27615
28117
  // (фолбэк — дефолт-репо роя). Реальный gh; логика усыновления — в tickOnce (тестируется).
27616
28118
  openPrsForBranch: (branch, repoDir) => openPrsForBranch(branch, repoDir || opts.repo),
@@ -27672,6 +28174,8 @@ async function runDaemon(opts) {
27672
28174
  prCommitTitles: (prUrl) => prCommitTitles(prUrl),
27673
28175
  prHeadBranch: (prUrl) => prHeadBranch(prUrl),
27674
28176
  // TASWM-356: ветка PR на усыновлении, узким запросом
28177
+ prHeadOid: (prUrl) => prHeadOid(prUrl),
28178
+ // TASWM-666: голова PR на усыновлении и повторной сдаче
27675
28179
  journalForBranch: (repo, branch, slug) => journalForBranch(repo || opts.repo, branch, slug),
27676
28180
  removeWorktree: (repo, p) => removeWorktree(repo || opts.repo, p),
27677
28181
  // TASWM-303: тот же фолбэк repo, что у removeWorktree/journalForBranch — run.repo пуст
@@ -27905,7 +28409,8 @@ async function runDaemon(opts) {
27905
28409
  // строится над failing/failingRunIds ИЗ checks — без повторного `gh pr checks`.
27906
28410
  ci: {
27907
28411
  checks: (url) => prCiStatus(url),
27908
- failureSummary: (failing, failingRunIds) => ciFailureSummary(failing, failingRunIds)
28412
+ failureSummary: (failing, failingRunIds) => ciFailureSummary(failing, failingRunIds),
28413
+ rerun: (runId, prUrl) => rerunActionsRun(prUrl ?? "", runId)
27909
28414
  },
27910
28415
  // Штормовой режим (TASWM-23): health-probe на отбой (реальный claude) + внешний
27911
28416
  // сигнал SWARM_STORM_URL (2-й слой, если задан). Логика/пороги — в manageStorm/storm.ts.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taskless-app/swarm",
3
- "version": "0.6.100",
3
+ "version": "0.6.102",
4
4
  "type": "module",
5
5
  "description": "Local control plane for a fleet of AI coding agents (drones), coordinating through Taskless. The overmind runs the swarm.",
6
6
  "keywords": [
@@ -40,7 +40,7 @@
40
40
  "undici": "^7.30.1",
41
41
  "zod": "3.25.76"
42
42
  },
43
- "gitHead": "a0643b2118fce225b5afbe7ce9c1afbe7cd25d39",
43
+ "gitHead": "34ee99661e59073f43dae1487e6a5f27102cdd8d",
44
44
  "scripts": {
45
45
  "overmind": "NODE_OPTIONS=\"${NODE_OPTIONS:-} --conditions=development\" tsx src/overmind.ts",
46
46
  "swarm": "NODE_OPTIONS=\"${NODE_OPTIONS:-} --conditions=development\" tsx src/cli.ts",