@taskless-app/swarm 0.6.101 → 0.6.103

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.101",
4493
+ version: "0.6.103",
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: "9216f89857eb8625eecb9a3ededb87cb65a15dec"
4545
+ gitHead: "d680b3efcba1a4f007afd6c69d2f7b45a3498422"
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.101",
14923
+ version: "0.6.103",
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: "9216f89857eb8625eecb9a3ededb87cb65a15dec"
14975
+ gitHead: "d680b3efcba1a4f007afd6c69d2f7b45a3498422"
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,96 +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 fixPartnerHold(input) {
16332
- const reviewOpen = input.reviewVerdict == null;
16333
- const verifyOpen = input.verifyVerdict == null;
16334
- const waitingOn = verifyOpen && input.verifierWorking ? "verifier" : reviewOpen && input.reviewerWorking ? "reviewer" : null;
16335
- if (!waitingOn) return { action: "wake" };
16336
- const elapsed = input.verdictAtMs == null ? 0 : input.nowMs - input.verdictAtMs;
16337
- if (!Number.isFinite(elapsed)) return { action: "partial", waitingOn };
16338
- if (elapsed < input.waitMs) return { action: "wait", waitingOn };
16339
- return { action: "partial", waitingOn };
16340
- }
16341
- var VERDICT_HEAD_RE = /\[head ([0-9a-f]{7,40})\]/i;
16342
- var VERDICT_HEAD_SHA = /^[0-9a-f]{7,40}$/i;
16343
- function appendVerdictHead(text, sha) {
16344
- const trimmed = sha?.trim() ?? "";
16345
- if (!VERDICT_HEAD_SHA.test(trimmed)) return text;
16346
- if (VERDICT_HEAD_RE.test(text)) return text;
16347
- return `${text} [head ${trimmed}]`;
16348
- }
16349
- function verdictHeadSha(text) {
16350
- if (!text) return null;
16351
- return text.match(VERDICT_HEAD_RE)?.[1] ?? null;
16352
- }
16353
- function stripVerdictHead(text) {
16354
- return text.replace(/[ \t]*\[head [0-9a-f]{7,40}\]/gi, "").trim();
16355
- }
16356
- function reviewTransitionPatch(run2, prUrl) {
16357
- const isFixIteration = needsFixIteration(run2);
16358
- if (isFixIteration) {
16359
- if (reviewCyclesExhausted(run2)) {
16360
- return { isFixIteration: false, cycle: null, patch: { status: "review", pr_url: prUrl } };
16361
- }
16362
- const cycle = (run2.review_cycle ?? 0) + 1;
16363
- return {
16364
- isFixIteration: true,
16365
- cycle,
16366
- patch: { status: "review", pr_url: prUrl, review_cycle: cycle, review_verdict: null, verify_verdict: null }
16367
- };
16368
- }
16369
- return { isFixIteration: false, cycle: null, patch: { status: "review", pr_url: prUrl } };
16370
- }
16371
- function branchFromPrPatch(currentBranch, headBranch) {
16372
- if (!headBranch || headBranch === currentBranch) return null;
16373
- return {
16374
- patch: { branch: headBranch },
16375
- 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)`
16376
- };
16377
- }
16378
- function prLiveness(st) {
16379
- if (!st) return "unknown";
16380
- if (st.merged) return "merged";
16381
- const state = (st.state ?? "").toUpperCase();
16382
- if (state === "MERGED") return "merged";
16383
- if (state === "CLOSED") return "closed";
16384
- if (state === "UNKNOWN") return "unknown";
16385
- return "open";
16386
- }
16387
- function applyReviewTransition(db, run2, prUrl) {
16388
- const { patch, ...t } = reviewTransitionPatch(run2, prUrl);
16389
- db.updateRun(run2.id, patch);
16390
- return t;
16391
- }
16392
-
16393
- // src/droneServer.ts
16394
16549
  init_src();
16395
16550
  function readTaskFailureInstruction(slug, failure) {
16396
16551
  const why = describeToolFailure(failure);
@@ -17024,7 +17179,7 @@ ${failText}` : failText }],
17024
17179
  await store.addEvent(
17025
17180
  run2.reviews_run_id,
17026
17181
  "step",
17027
- appendVerdictHead(`\u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u0440\u0435\u0432\u044C\u044E \u043E\u0442 ${run2.name}: ${verdictText}${summary ? ` \u2014 ${summary}` : ""}`, reviewHead)
17182
+ markVerdictHead(`\u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u0440\u0435\u0432\u044C\u044E \u043E\u0442 ${run2.name}: ${verdictText}${summary ? ` \u2014 ${summary}` : ""}`, reviewHead)
17028
17183
  );
17029
17184
  const reviewedSlug = reportSlug(reviewed?.task_slug);
17030
17185
  let shots = { attachments: [], warning: "" };
@@ -17090,13 +17245,34 @@ ${failText}` : failText }],
17090
17245
  };
17091
17246
  }
17092
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
+ }
17093
17269
  const verdictText = verifyVerdictLabel(verdict);
17094
17270
  const verifyHead = await headSha(opts.worktree ?? process.cwd());
17095
17271
  await store.updateRun(run2.verifies_run_id, { verify_verdict: verdict });
17096
17272
  await store.addEvent(
17097
17273
  run2.verifies_run_id,
17098
17274
  "step",
17099
- appendVerdictHead(`\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)
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)
17100
17276
  );
17101
17277
  const verifiedSlug = reportSlug(verified?.task_slug);
17102
17278
  let shots = { attachments: [], warning: "" };
@@ -17210,21 +17386,30 @@ ${report}${shots.warning}`,
17210
17386
  const held = await changedPaths(opts.worktree ?? process.cwd(), { baseBranch: run2?.base_branch ?? null }).catch(() => []);
17211
17387
  const heldPatch = held.length ? { changed_paths: held } : {};
17212
17388
  if (run2) {
17213
- 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
+ }
17214
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
+ }
17215
17404
  await store.addEvent(null, "pr_opened", pr_url);
17216
17405
  await postReport(reportSlug(run2.task_slug), t.cycle ?? run2.review_cycle ?? 0);
17217
17406
  const rulesNote = await offerRules(reportSlug(run2.task_slug));
17218
17407
  const zoneNote = await zoneMemoryNote(reportSlug(run2.task_slug));
17408
+ const tail2 = `${shotsNote(shots)}${rulesNote}${zoneNote}`;
17219
17409
  if (t.isFixIteration) {
17220
- await store.addEvent(
17221
- null,
17222
- "step",
17223
- `\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}`
17224
- );
17225
- 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}` }] };
17226
17411
  }
17227
- 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}` }] };
17228
17413
  }
17229
17414
  await store.updateRun(null, { status: "review", pr_url, ...branchFix?.patch ?? {}, ...heldPatch });
17230
17415
  await store.addEvent(null, "pr_opened", pr_url);
@@ -17409,6 +17594,7 @@ async function runDroneServer(runId) {
17409
17594
  taskless,
17410
17595
  runKind: expectedKind,
17411
17596
  prHeadBranch,
17597
+ prHeadOid,
17412
17598
  ...expectedTaskSlug ? { expectedTaskSlug } : {},
17413
17599
  ...Number.isInteger(spawnReviewsRunId) && spawnReviewsRunId > 0 ? { reviewsRunId: spawnReviewsRunId } : {},
17414
17600
  ...Number.isInteger(spawnVerifiesRunId) && spawnVerifiesRunId > 0 ? { verifiesRunId: spawnVerifiesRunId } : {},
@@ -18598,6 +18784,14 @@ function makeMergeIntentResolver(deps) {
18598
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`
18599
18785
  };
18600
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
+ }
18601
18795
  if (st.checks === "none") {
18602
18796
  if (runs.total > 0) {
18603
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` };
@@ -21979,6 +22173,87 @@ async function retireOutdatedReviewers(deps, run2) {
21979
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.`);
21980
22174
  }
21981
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
+ }
21982
22257
  async function finalizeMergedReview(deps, run2, opts) {
21983
22258
  if (!opts?.workChecked) {
21984
22259
  const work = await taskWorkState(deps, run2.task_slug, run2.repo || "", run2.pr_url ?? null);
@@ -23392,6 +23667,22 @@ async function handleCi(deps, run2, now, worktreeExists, hasTranscript, droneCap
23392
23667
  }
23393
23668
  return;
23394
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
+ }
23395
23686
  if (ci?.bucket === "pass" && await wakeReviewerOnCiReady(deps, run2, { kind: "pass", ci })) return;
23396
23687
  const counts = ci && ci.total > 0 ? ` (${ci.pass}/${ci.total})` : "";
23397
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);
@@ -23935,8 +24226,17 @@ function tickAnomalyCandidates(autoReviewSnapshot) {
23935
24226
  }
23936
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";
23937
24228
  async function liftFixIterationStep(deps, snapshot, st, _stormActive, now, droneCap) {
23938
- const run2 = deps.db.getRun(snapshot.id) ?? snapshot;
24229
+ let run2 = deps.db.getRun(snapshot.id) ?? snapshot;
23939
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
+ }
23940
24240
  if (needsFixIteration(run2) && !stormHolds(deps, run2) && !st.conflicting && !deps.db.activeResolverFor(run2.id)) {
23941
24241
  const capFull = countActiveDrones(deps.db) >= droneCap;
23942
24242
  if (await wakeAuthorOnChanges(deps, run2, now, droneCap)) {
@@ -25199,7 +25499,10 @@ async function worktreeBranchFor(run2, prHead) {
25199
25499
  return fromPr || run2.task_slug;
25200
25500
  }
25201
25501
  async function adoptDroneToReview(deps, run2, prUrl) {
25202
- 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));
25203
25506
  const adopted = syncBranchFromPr(deps.db, run2, deps.prHeadBranch ? await deps.prHeadBranch(prUrl).catch(() => null) : null);
25204
25507
  deps.db.addEvent(run2.id, "pr_opened", prUrl);
25205
25508
  deps.db.addEvent(
@@ -25252,7 +25555,7 @@ function pickedVerdictEventText(how, verdict, body, mark, sha) {
25252
25555
  const trimmed = body?.trim() ?? "";
25253
25556
  const payload = trimmed ? clipPickupBody(trimmed) : label2;
25254
25557
  const tail2 = mark ? ` [${mark}]` : "";
25255
- return `${appendVerdictHead(`${prefix} (${how}): ${payload}`, sha)}${tail2}`;
25558
+ return `${markVerdictHead(`${prefix} (${how}): ${payload}`, sha)}${tail2}`;
25256
25559
  }
25257
25560
  async function checkerHeadSha(worktree) {
25258
25561
  if (!worktree) return null;
@@ -25291,13 +25594,28 @@ async function salvageVerdictFromPrComment(deps, rv, reviewsRunId, since, ctx) {
25291
25594
  if (!deps.verdictComment || !rv.pr_url) return false;
25292
25595
  const found = await deps.verdictComment(rv.pr_url, since).catch(() => null);
25293
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
+ }
25294
25612
  const verdictText = verdictLabel(found.verdict);
25295
25613
  deps.db.updateRun(reviewsRunId, { review_verdict: found.verdict });
25296
25614
  recordReviewFindings(deps, rv, found);
25297
25615
  deps.db.addEvent(
25298
25616
  reviewsRunId,
25299
25617
  "step",
25300
- pickedVerdictEventText(ctx.how, found.verdict, found.body, void 0, await checkerHeadSha(rv.worktree_path))
25618
+ pickedVerdictEventText(ctx.how, found.verdict, found.body, void 0, commentSha)
25301
25619
  );
25302
25620
  await closeReviewerRun(
25303
25621
  deps,
@@ -25318,6 +25636,16 @@ async function salvageVerifyVerdictFromPrComment(deps, vr, verifiesRunId, since,
25318
25636
  if (!deps.verifyVerdictComment || !vr.pr_url) return false;
25319
25637
  const found = await deps.verifyVerdictComment(vr.pr_url, since).catch(() => null);
25320
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
+ }
25321
25649
  const verdictText = verifyVerdictLabel(found.verdict);
25322
25650
  deps.db.updateRun(verifiesRunId, { verify_verdict: found.verdict });
25323
25651
  deps.db.addEvent(
@@ -25601,6 +25929,18 @@ async function maybeRearmCycleStop(deps, run2, now, key, episodes) {
25601
25929
  }
25602
25930
  if (moved) episodes.rearm(key);
25603
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
+ }
25604
25944
  async function tickOnce(deps) {
25605
25945
  const now = deps.now ? deps.now() : Date.now();
25606
25946
  beginGhMergePass(deps.ghMerges);
@@ -25843,6 +26183,7 @@ async function tickOnce(deps) {
25843
26183
  continue;
25844
26184
  }
25845
26185
  if (touchesDaemonCode(st.files ?? [])) {
26186
+ await retireOutdatedVerifiers(deps, run2);
25846
26187
  const already = deps.db.events(run2.id).some((e) => (e.text ?? "").includes(SELF_REFERENCE_MARK));
25847
26188
  if (!already) {
25848
26189
  const signal = {
@@ -25873,6 +26214,7 @@ async function tickOnce(deps) {
25873
26214
  continue;
25874
26215
  }
25875
26216
  await retireOutdatedReviewers(deps, run2);
26217
+ await retireOutdatedVerifiers(deps, run2);
25876
26218
  let intentBaseStale = false;
25877
26219
  if (hasMergeIntent(run2)) {
25878
26220
  const drop = mergeIntentDropReason(deps, run2, st.conflicting === true);
@@ -25976,6 +26318,23 @@ async function tickOnce(deps) {
25976
26318
  lastAttempt = deps.db.lastReviewerAttemptFor(run2.id);
25977
26319
  verdictFromComment = await deps.verdictComment(prUrl, lastAttempt?.created_at ?? run2.created_at).catch(() => null);
25978
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
+ }
25979
26338
  if (verdictFromComment) {
25980
26339
  const mark = verdictCommentMark(verdictFromComment.createdAt);
25981
26340
  const alreadyProcessed = deps.db.events(run2.id).some((e) => (e.text ?? "").includes(mark));
@@ -26259,12 +26618,12 @@ async function tickOnce(deps) {
26259
26618
  const ciWatchOff = parent != null && ciWatchClosed(deps.db, parent);
26260
26619
  const ci = ciWatchOff ? null : await deps.ci.checks(run2.pr_url).catch(() => null);
26261
26620
  const noCiRepo = ci?.bucket === "none" && !repoHasCi(deps, run2);
26262
- 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")) {
26263
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}` : ""}` : (
26264
26623
  // TASWM-497: и здесь причина СЛОВАМИ, а не общее «gh не ответил». Тот же словарь,
26265
26624
  // что в ленте опроса (callFailureWord), чтобы одно и то же состояние в журнале
26266
26625
  // прогона и в событии парковки не называлось двумя разными способами.
26267
- 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}`
26268
26627
  );
26269
26628
  deps.db.updateRun(run2.id, { status: "paused", stop_reason: AWAITING_CI_REASON });
26270
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`);
@@ -26686,7 +27045,7 @@ function makeCheckerAttachmentsReader(tl) {
26686
27045
  async function spawnReviewer(deps, reviewRun, files) {
26687
27046
  const repo = normalizeRepo(reviewRun.repo || deps.repoFallback);
26688
27047
  const branch = await worktreeBranchFor(reviewRun, deps.prHeadBranch);
26689
- 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;
26690
27049
  const verifyMode = deps.verifyMode ? await deps.verifyMode(repo, reviewRun.task_slug).catch(() => void 0) : void 0;
26691
27050
  const ciClosed = verifyMode === "local" ? null : ciWatchCloseKind(deps.db, reviewRun);
26692
27051
  const checklist = buildReviewChecklist(reviewRun, files, priorReview, verifyMode, ciClosed);
@@ -26814,22 +27173,13 @@ async function spawnVerifier(deps, verifiedRun, files) {
26814
27173
  }
26815
27174
  function lastSubmissionSince(db, run2) {
26816
27175
  const events = db.events(run2.id);
26817
- for (let i = events.length - 1; i >= 0; i--) {
26818
- const kind = events[i].kind;
26819
- if (kind === "pr_opened" || kind === "done") return events[i].at;
26820
- }
27176
+ const boundary = feedBoundaryIndex(events);
27177
+ if (boundary >= 0) return events[boundary].at;
26821
27178
  return run2.created_at;
26822
27179
  }
26823
27180
  function lastTextThisHead(db, runId, match) {
26824
27181
  const events = db.events(runId);
26825
- let boundary = -1;
26826
- for (let i = events.length - 1; i >= 0; i--) {
26827
- const kind = events[i].kind;
26828
- if (kind === "pr_opened" || kind === "done") {
26829
- boundary = i;
26830
- break;
26831
- }
26832
- }
27182
+ const boundary = feedBoundaryIndex(events);
26833
27183
  for (let i = events.length - 1; i > boundary; i--) {
26834
27184
  const text = events[i].text ?? "";
26835
27185
  if (match(text)) return text;
@@ -26838,7 +27188,7 @@ function lastTextThisHead(db, runId, match) {
26838
27188
  }
26839
27189
  async function reviewSectionForFix(deps, run2) {
26840
27190
  const fromFeed = lastTextThisHead(deps.db, run2.id, isVerdictEventText);
26841
- const sha = verdictHeadSha(fromFeed);
27191
+ const sha = verdictEventSha(fromFeed);
26842
27192
  const approveFeed = !!fromFeed && verdictEventIsApprove(fromFeed);
26843
27193
  if (run2.review_verdict === "approve" || run2.review_verdict !== "changes" && approveFeed) {
26844
27194
  const comment2 = await fullReviewComment(deps, run2);
@@ -26847,7 +27197,7 @@ async function reviewSectionForFix(deps, run2) {
26847
27197
  }
26848
27198
  if (fromFeed && !isHeaderOnlyVerdict(fromFeed)) {
26849
27199
  const raw = isClippedPickup(fromFeed) ? await fullReviewComment(deps, run2) ?? fromFeed : fromFeed;
26850
- return { body: stripVerdictHead(raw), sha: sha ?? verdictHeadSha(raw) };
27200
+ return { body: stripVerdictHead(raw), sha };
26851
27201
  }
26852
27202
  const comment = await fullReviewComment(deps, run2);
26853
27203
  if (comment) return { body: stripVerdictHead(comment), sha };
@@ -26855,11 +27205,11 @@ async function reviewSectionForFix(deps, run2) {
26855
27205
  }
26856
27206
  async function verifySectionForFix(deps, run2) {
26857
27207
  const fromFeed = lastTextThisHead(deps.db, run2.id, (text) => VERIFY_EVENT_PREFIXES.some((p) => text.startsWith(p)));
26858
- const sha = verdictHeadSha(fromFeed);
27208
+ const sha = verdictEventSha(fromFeed);
26859
27209
  if (run2.verify_verdict === "confirmed") return { body: FIX_NO_VERIFY_ITEMS, sha };
26860
27210
  if (fromFeed && !isVerifyHeaderOnly(fromFeed)) {
26861
27211
  const raw = isClippedPickup(fromFeed) ? await fullVerifyComment(deps, run2) ?? fromFeed : fromFeed;
26862
- return { body: stripVerdictHead(raw), sha: sha ?? verdictHeadSha(raw) };
27212
+ return { body: stripVerdictHead(raw), sha };
26863
27213
  }
26864
27214
  const comment = await fullVerifyComment(deps, run2);
26865
27215
  if (comment) return { body: stripVerdictHead(comment), sha };
@@ -27690,6 +28040,7 @@ async function runDaemon(opts) {
27690
28040
  checks: async (url) => {
27691
28041
  const ci = await prCiStatus(url);
27692
28042
  if (ci.bucket === "denied" || ci.bucket === "unavailable") return null;
28043
+ if (ci.bucket === "cancelled") return { bucket: "pending" };
27693
28044
  return { bucket: ci.bucket };
27694
28045
  },
27695
28046
  // TASWM-577: прогоны GitHub Actions на HEAD — только вливанию по намерению: рой
@@ -27761,7 +28112,7 @@ async function runDaemon(opts) {
27761
28112
  if (task) db.updateRun(run2.id, { task_title: task.title, task_desc: task.description, task_url: task.url });
27762
28113
  if (taskClient) await taskClient.startTask(runToSpawn.task_slug);
27763
28114
  },
27764
- 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 })),
27765
28116
  // Открытые PR ветки прогона (готча №14): gh pr list --head <slug> в репо прогона
27766
28117
  // (фолбэк — дефолт-репо роя). Реальный gh; логика усыновления — в tickOnce (тестируется).
27767
28118
  openPrsForBranch: (branch, repoDir) => openPrsForBranch(branch, repoDir || opts.repo),
@@ -27823,6 +28174,8 @@ async function runDaemon(opts) {
27823
28174
  prCommitTitles: (prUrl) => prCommitTitles(prUrl),
27824
28175
  prHeadBranch: (prUrl) => prHeadBranch(prUrl),
27825
28176
  // TASWM-356: ветка PR на усыновлении, узким запросом
28177
+ prHeadOid: (prUrl) => prHeadOid(prUrl),
28178
+ // TASWM-666: голова PR на усыновлении и повторной сдаче
27826
28179
  journalForBranch: (repo, branch, slug) => journalForBranch(repo || opts.repo, branch, slug),
27827
28180
  removeWorktree: (repo, p) => removeWorktree(repo || opts.repo, p),
27828
28181
  // TASWM-303: тот же фолбэк repo, что у removeWorktree/journalForBranch — run.repo пуст
@@ -28056,7 +28409,8 @@ async function runDaemon(opts) {
28056
28409
  // строится над failing/failingRunIds ИЗ checks — без повторного `gh pr checks`.
28057
28410
  ci: {
28058
28411
  checks: (url) => prCiStatus(url),
28059
- failureSummary: (failing, failingRunIds) => ciFailureSummary(failing, failingRunIds)
28412
+ failureSummary: (failing, failingRunIds) => ciFailureSummary(failing, failingRunIds),
28413
+ rerun: (runId, prUrl) => rerunActionsRun(prUrl ?? "", runId)
28060
28414
  },
28061
28415
  // Штормовой режим (TASWM-23): health-probe на отбой (реальный claude) + внешний
28062
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.101",
3
+ "version": "0.6.103",
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": "9216f89857eb8625eecb9a3ededb87cb65a15dec",
43
+ "gitHead": "d680b3efcba1a4f007afd6c69d2f7b45a3498422",
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",