@taskless-app/swarm 0.6.99 → 0.6.101

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/overmind.js CHANGED
@@ -5459,7 +5459,7 @@ var init_procCleanup = __esm({
5459
5459
  // src/git.ts
5460
5460
  import { existsSync as existsSync14, readdirSync as readdirSync16, realpathSync as realpathSync2, statSync as statSync13 } from "fs";
5461
5461
  import { appendFile, chmod, mkdir, readFile, rename, rm, writeFile } from "fs/promises";
5462
- import { isAbsolute as isAbsolute4, join as join25, resolve as resolve4, sep as sep3 } from "path";
5462
+ import { isAbsolute as isAbsolute4, join as join26, resolve as resolve4, sep as sep3 } from "path";
5463
5463
  import { $ as $3 } from "execa";
5464
5464
  function gitNet(repo, args, timeoutMs) {
5465
5465
  return withHardTimeout(
@@ -5488,7 +5488,7 @@ async function inspectWorktreePath(path) {
5488
5488
  return "orphan";
5489
5489
  }
5490
5490
  try {
5491
- if (statSync13(join25(path, ".git")).isDirectory()) return "main-checkout";
5491
+ if (statSync13(join26(path, ".git")).isDirectory()) return "main-checkout";
5492
5492
  } catch {
5493
5493
  }
5494
5494
  const top = await $3({ reject: false })`git -C ${path} rev-parse --show-toplevel`;
@@ -5548,7 +5548,7 @@ async function parkOrphanDir(repo, path, branch) {
5548
5548
  }
5549
5549
  function isLinkedWorktree(dir) {
5550
5550
  try {
5551
- return statSync13(join25(dir, ".git")).isFile();
5551
+ return statSync13(join26(dir, ".git")).isFile();
5552
5552
  } catch {
5553
5553
  return false;
5554
5554
  }
@@ -5660,8 +5660,8 @@ async function ensureGitExcluded(worktree, pattern) {
5660
5660
  try {
5661
5661
  const commonDir = await gitPath(worktree, "--git-common-dir");
5662
5662
  if (!commonDir) return false;
5663
- const infoDir = join25(commonDir, "info");
5664
- const excludeFile = join25(infoDir, "exclude");
5663
+ const infoDir = join26(commonDir, "info");
5664
+ const excludeFile = join26(infoDir, "exclude");
5665
5665
  let current = "";
5666
5666
  try {
5667
5667
  current = await readFile(excludeFile, "utf8");
@@ -5681,7 +5681,7 @@ async function gitPath(worktree, flag) {
5681
5681
  const out = await $3({ reject: false })`git -C ${worktree} rev-parse ${flag}`;
5682
5682
  const raw = out.stdout.trim();
5683
5683
  if (out.exitCode !== 0 || !raw) return null;
5684
- return isAbsolute4(raw) ? raw : join25(worktree, raw);
5684
+ return isAbsolute4(raw) ? raw : join26(worktree, raw);
5685
5685
  }
5686
5686
  async function ensureWorktreeHygiene(worktree) {
5687
5687
  for (const pattern of SWARM_EXCLUDE_PATTERNS) await ensureGitExcluded(worktree, pattern);
@@ -5691,12 +5691,12 @@ async function installGuardHooks(worktree) {
5691
5691
  try {
5692
5692
  const gitDir = await gitPath(worktree, "--git-dir");
5693
5693
  if (!gitDir) return false;
5694
- const hooksDir = join25(gitDir, "swarm-hooks");
5694
+ const hooksDir = join26(gitDir, "swarm-hooks");
5695
5695
  const prev = await previousHooksPath(worktree);
5696
5696
  await mkdir(hooksDir, { recursive: true });
5697
5697
  for (const hook of GUARD_HOOKS) {
5698
- await writeFile(join25(hooksDir, hook), guardHookScript(hook, prev ? `${posix(prev)}/${hook}` : null));
5699
- await chmod(join25(hooksDir, hook), 493);
5698
+ await writeFile(join26(hooksDir, hook), guardHookScript(hook, prev ? `${posix(prev)}/${hook}` : null));
5699
+ await chmod(join26(hooksDir, hook), 493);
5700
5700
  }
5701
5701
  await $3`git -C ${worktree} config extensions.worktreeConfig true`;
5702
5702
  await $3`git -C ${worktree} config --worktree core.hooksPath ${posix(hooksDir)}`;
@@ -5715,7 +5715,7 @@ async function previousHooksPath(worktree) {
5715
5715
  if (out.exitCode === 0 && value) return value;
5716
5716
  }
5717
5717
  const commonDir = await gitPath(worktree, "--git-common-dir");
5718
- return commonDir ? join25(commonDir, "hooks") : null;
5718
+ return commonDir ? join26(commonDir, "hooks") : null;
5719
5719
  }
5720
5720
  async function removeWorktree(repo, path) {
5721
5721
  const branch = (await $3({ reject: false })`git -C ${path} symbolic-ref --quiet --short HEAD`).stdout.trim();
@@ -5740,7 +5740,7 @@ async function worktreeDirty(path) {
5740
5740
  async function repairMovedWorktrees(targetDir) {
5741
5741
  const subdirs = (dir) => {
5742
5742
  try {
5743
- return readdirSync16(dir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => join25(dir, d.name));
5743
+ return readdirSync16(dir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => join26(dir, d.name));
5744
5744
  } catch {
5745
5745
  return [];
5746
5746
  }
@@ -5877,12 +5877,12 @@ __export(droneChannel_exports, {
5877
5877
  verifyLocalCliToken: () => verifyLocalCliToken
5878
5878
  });
5879
5879
  import { createHmac, randomBytes, timingSafeEqual } from "crypto";
5880
- import { chmodSync as chmodSync2, mkdirSync as mkdirSync12, readFileSync as readFileSync22, writeFileSync as writeFileSync14 } from "fs";
5880
+ import { chmodSync as chmodSync2, mkdirSync as mkdirSync12, readFileSync as readFileSync23, writeFileSync as writeFileSync14 } from "fs";
5881
5881
  import { dirname as dirname5 } from "path";
5882
5882
  import { serve } from "@hono/node-server";
5883
5883
  function loadChannelSecret(path) {
5884
5884
  try {
5885
- const s = readFileSync22(path, "utf8").trim();
5885
+ const s = readFileSync23(path, "utf8").trim();
5886
5886
  if (s.length >= 32) return s;
5887
5887
  } catch {
5888
5888
  }
@@ -6278,7 +6278,7 @@ var init_droneChannel = __esm({
6278
6278
 
6279
6279
  // src/attachments.ts
6280
6280
  import { mkdir as mkdir3, readFile as readFile2, readdir as readdir2, stat as stat2, unlink, writeFile as writeFile3 } from "fs/promises";
6281
- import { extname, join as join30 } from "path";
6281
+ import { extname, join as join31 } from "path";
6282
6282
  function attachmentsFromDoc(doc, origin) {
6283
6283
  const out = [];
6284
6284
  const walk2 = (node) => {
@@ -6374,7 +6374,7 @@ async function materializeAttachments(opts) {
6374
6374
  };
6375
6375
  const result = { files: [], skipped: [] };
6376
6376
  if (opts.refs.length === 0) return result;
6377
- const dir = join30(opts.worktree, ATTACHMENTS_DIR);
6377
+ const dir = join31(opts.worktree, ATTACHMENTS_DIR);
6378
6378
  const existing = (await io.listFiles(dir)).filter((file) => file.name !== ".index.json");
6379
6379
  const previousIndex = await readAttachmentIndex(dir, io.readFile);
6380
6380
  const nextIndex = {};
@@ -6460,7 +6460,7 @@ async function materializeAttachments(opts) {
6460
6460
  await io.mkdir(dir);
6461
6461
  dirReady = true;
6462
6462
  }
6463
- await io.writeFile(join30(dir, name), file.bytes);
6463
+ await io.writeFile(join31(dir, name), file.bytes);
6464
6464
  } catch (e) {
6465
6465
  const reason = `\u043D\u0435 \u0437\u0430\u043F\u0438\u0441\u0430\u043B\u043E\u0441\u044C \u043D\u0430 \u0434\u0438\u0441\u043A (${errText2(e)})`;
6466
6466
  const stem = name.slice(0, name.length - extname(name).length);
@@ -6484,7 +6484,7 @@ async function materializeAttachments(opts) {
6484
6484
  }
6485
6485
  const wanted = new Set(result.files.map((f) => f.path.split("/").pop()));
6486
6486
  for (const old of existing) {
6487
- if (!wanted.has(old.name)) await io.removeFile(join30(dir, old.name));
6487
+ if (!wanted.has(old.name)) await io.removeFile(join31(dir, old.name));
6488
6488
  }
6489
6489
  if (result.files.length > 0 && JSON.stringify(nextIndex) !== JSON.stringify(previousIndex)) {
6490
6490
  try {
@@ -6492,7 +6492,7 @@ async function materializeAttachments(opts) {
6492
6492
  await io.mkdir(dir);
6493
6493
  dirReady = true;
6494
6494
  }
6495
- await io.writeFile(join30(dir, ".index.json"), new TextEncoder().encode(JSON.stringify(nextIndex)));
6495
+ await io.writeFile(join31(dir, ".index.json"), new TextEncoder().encode(JSON.stringify(nextIndex)));
6496
6496
  } catch {
6497
6497
  }
6498
6498
  }
@@ -6502,7 +6502,7 @@ async function materializeAttachments(opts) {
6502
6502
  async function readAttachmentIndex(dir, read) {
6503
6503
  if (!read) return {};
6504
6504
  try {
6505
- const parsed = JSON.parse(new TextDecoder().decode(await read(join30(dir, ".index.json"))));
6505
+ const parsed = JSON.parse(new TextDecoder().decode(await read(join31(dir, ".index.json"))));
6506
6506
  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return {};
6507
6507
  const entries = Object.entries(parsed);
6508
6508
  if (entries.some(([, url]) => typeof url !== "string")) return {};
@@ -6515,7 +6515,7 @@ async function listAttachmentFiles(dir) {
6515
6515
  try {
6516
6516
  const entries = await readdir2(dir, { withFileTypes: true });
6517
6517
  return await Promise.all(
6518
- entries.filter((entry) => entry.isFile() && entry.name !== ".index.json").map(async (entry) => ({ name: entry.name, bytes: (await stat2(join30(dir, entry.name))).size }))
6518
+ entries.filter((entry) => entry.isFile() && entry.name !== ".index.json").map(async (entry) => ({ name: entry.name, bytes: (await stat2(join31(dir, entry.name))).size }))
6519
6519
  );
6520
6520
  } catch (e) {
6521
6521
  if (e.code === "ENOENT") return [];
@@ -6532,7 +6532,7 @@ function renderAttachmentsBlock(result) {
6532
6532
  "\xAB\u043F\u0435\u0440\u0432\u044B\u0439 \u0441\u043A\u0440\u0438\u043D\xBB \u0438\u0437 \u0442\u0435\u043A\u0441\u0442\u0430 \u2014 \u044D\u0442\u043E 01-\u2026, \xAB\u0432\u0442\u043E\u0440\u043E\u0439\xBB \u2014 02-\u2026 . \u041F\u0440\u043E\u043F\u0443\u0449\u0435\u043D\u043D\u044B\u0439 \u043D\u043E\u043C\u0435\u0440 \u0437\u043D\u0430\u0447\u0438\u0442, \u0447\u0442\u043E \u044D\u0442\u043E \u0432\u043B\u043E\u0436\u0435\u043D\u0438\u0435",
6533
6533
  "\u0432\u044B\u043B\u043E\u0436\u0438\u0442\u044C \u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u2014 \u043E\u043D\u043E \u043D\u0430\u0437\u0432\u0430\u043D\u043E \u043D\u0438\u0436\u0435, \u0430 \u043D\u0435 \u043F\u043E\u0442\u0435\u0440\u044F\u043B\u043E\u0441\u044C.",
6534
6534
  ...result.files.map(
6535
- (f) => `- ${f.path}${f.caption ? ` \u2014 \xAB${oneLine(f.caption)}\xBB` : ""} [${oneLine(f.origin)}, ${mb(f.bytes)}]` + (f.previousCopyReason ? ` \u2014 \u043F\u0440\u0435\u0436\u043D\u044F\u044F \u043A\u043E\u043F\u0438\u044F, \u0437\u0430\u043D\u043E\u0432\u043E \u0441\u043A\u0430\u0447\u0430\u0442\u044C \u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C (${oneLine(f.previousCopyReason)})` : "")
6535
+ (f) => `- ${f.path}${f.caption ? ` \u2014 \xAB${oneLine2(f.caption)}\xBB` : ""} [${oneLine2(f.origin)}, ${mb(f.bytes)}]` + (f.previousCopyReason ? ` \u2014 \u043F\u0440\u0435\u0436\u043D\u044F\u044F \u043A\u043E\u043F\u0438\u044F, \u0437\u0430\u043D\u043E\u0432\u043E \u0441\u043A\u0430\u0447\u0430\u0442\u044C \u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C (${oneLine2(f.previousCopyReason)})` : "")
6536
6536
  ),
6537
6537
  "\u0415\u0441\u043B\u0438 \u043F\u043E\u0441\u0442\u0430\u043D\u043E\u0432\u043A\u0430 \u0441\u0441\u044B\u043B\u0430\u0435\u0442\u0441\u044F \u043D\u0430 \u0438\u0437\u043E\u0431\u0440\u0430\u0436\u0435\u043D\u0438\u0435 (\xAB\u043E\u0442\u0434\u0435\u043B\u0438\u043B\u0430 \u043A\u0440\u0430\u0441\u043D\u044B\u043C\u0438 \u043F\u043E\u043B\u044F\u043C\u0438\xBB, \xAB\u043A\u0430\u043A \u043D\u0430 \u0441\u043A\u0440\u0438\u043D\u0435\xBB) \u2014 \u041E\u0422\u041A\u0420\u041E\u0419 \u0444\u0430\u0439\u043B, \u0430 \u043D\u0435 \u0434\u043E\u0434\u0443\u043C\u044B\u0432\u0430\u0439."
6538
6538
  );
@@ -6541,7 +6541,7 @@ function renderAttachmentsBlock(result) {
6541
6541
  lines.push(
6542
6542
  result.files.length > 0 ? "" : "\u{1F4CE} \u0412\u041B\u041E\u0416\u0415\u041D\u0418\u042F \u0417\u0410\u0414\u0410\u0427\u0418: \u0432\u044B\u043B\u043E\u0436\u0438\u0442\u044C \u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u043D\u0438\u0447\u0435\u0433\u043E.",
6543
6543
  `\u26A0\uFE0F \u041D\u0415 \u0432\u044B\u043B\u043E\u0436\u0435\u043D\u043E (${result.skipped.length}) \u2014 \u0442\u044B \u0438\u0445 \u041D\u0415 \u0432\u0438\u0434\u0435\u043B, \u0443\u0447\u0438\u0442\u044B\u0432\u0430\u0439 \u044D\u0442\u043E:`,
6544
- ...result.skipped.map((s) => `- ${oneLine(s)}`),
6544
+ ...result.skipped.map((s) => `- ${oneLine2(s)}`),
6545
6545
  "\u041D\u0443\u0436\u0435\u043D \u043F\u0440\u043E\u043F\u0443\u0449\u0435\u043D\u043D\u044B\u0439 \u0444\u0430\u0439\u043B \u0434\u043B\u044F \u0440\u0430\u0431\u043E\u0442\u044B \u2014 \u0441\u043F\u0440\u043E\u0441\u0438 \u043E\u043F\u0435\u0440\u0430\u0442\u043E\u0440\u0430 \u0447\u0435\u0440\u0435\u0437 ask(), \u043D\u0435 \u0433\u0430\u0434\u0430\u0439 \u043F\u043E \u043D\u0430\u0437\u0432\u0430\u043D\u0438\u044E."
6546
6546
  );
6547
6547
  }
@@ -6558,7 +6558,7 @@ async function prepareTaskAttachments(opts) {
6558
6558
  }
6559
6559
  if (result.files.length > 0 || result.skipped.length > 0) {
6560
6560
  const failures = result.downloadFailures ?? [];
6561
- const failureText = failures.length ? `\u043D\u0435 \u0441\u043A\u0430\u0447\u0430\u043B\u043E\u0441\u044C ${failures.length} (${failures.map((f) => oneLine(f.label)).join(", ")}), \u043F\u0440\u0435\u0436\u043D\u044F\u044F \u043A\u043E\u043F\u0438\u044F \u043E\u0441\u0442\u0430\u0432\u043B\u0435\u043D\u0430 \u0443 ${failures.filter((f) => f.previousCopy).length}; ` : "";
6561
+ const failureText = failures.length ? `\u043D\u0435 \u0441\u043A\u0430\u0447\u0430\u043B\u043E\u0441\u044C ${failures.length} (${failures.map((f) => oneLine2(f.label)).join(", ")}), \u043F\u0440\u0435\u0436\u043D\u044F\u044F \u043A\u043E\u043F\u0438\u044F \u043E\u0441\u0442\u0430\u0432\u043B\u0435\u043D\u0430 \u0443 ${failures.filter((f) => f.previousCopy).length}; ` : "";
6562
6562
  await opts.onEvent?.(
6563
6563
  `\u0432\u043B\u043E\u0436\u0435\u043D\u0438\u044F \u0437\u0430\u0434\u0430\u0447\u0438: ${failureText}\u0432\u044B\u043B\u043E\u0436\u0435\u043D\u043E ${result.files.length} \u0432 ${ATTACHMENTS_DIR}` + (result.skipped.length ? `, \u043F\u0440\u043E\u043F\u0443\u0449\u0435\u043D\u043E ${result.skipped.length} (\u043F\u0435\u0440\u0435\u0447\u0438\u0441\u043B\u0435\u043D\u044B \u0432 \u043F\u0440\u043E\u043C\u043F\u0442\u0435)` : "")
6564
6564
  );
@@ -6572,7 +6572,7 @@ async function prepareTaskAttachments(opts) {
6572
6572
  function str(v) {
6573
6573
  return typeof v === "string" ? v : "";
6574
6574
  }
6575
- function oneLine(s) {
6575
+ function oneLine2(s) {
6576
6576
  const flat = s.replace(/\s+/g, " ").trim();
6577
6577
  return flat.length > 200 ? `${flat.slice(0, 200)}\u2026` : flat;
6578
6578
  }
@@ -6662,7 +6662,7 @@ var init_attachments = __esm({
6662
6662
 
6663
6663
  // src/shotUpload.ts
6664
6664
  import { readFile as fsReadFile } from "fs/promises";
6665
- import { basename as basename5, isAbsolute as isAbsolute5, join as join31 } from "path";
6665
+ import { basename as basename5, isAbsolute as isAbsolute5, join as join32 } from "path";
6666
6666
  function shotMimetype(path) {
6667
6667
  const dot = path.lastIndexOf(".");
6668
6668
  if (dot < 0) return null;
@@ -6688,7 +6688,7 @@ async function readShots(paths, opts) {
6688
6688
  }
6689
6689
  let bytes;
6690
6690
  try {
6691
- bytes = await read(isAbsolute5(path) ? path : join31(opts.worktree, path));
6691
+ bytes = await read(isAbsolute5(path) ? path : join32(opts.worktree, path));
6692
6692
  } catch (e) {
6693
6693
  skipped.push({ path, reason: `\u043D\u0435 \u043F\u0440\u043E\u0447\u0438\u0442\u0430\u043D: ${e instanceof Error ? e.message : String(e)}` });
6694
6694
  continue;
@@ -6769,8 +6769,8 @@ var init_shotUpload = __esm({
6769
6769
 
6770
6770
  // src/oauth.ts
6771
6771
  import { createHash as createHash4, randomBytes as randomBytes2 } from "crypto";
6772
- import { readFileSync as readFileSync23, writeFileSync as writeFileSync15, unlinkSync as unlinkSync4 } from "fs";
6773
- import { join as join32 } from "path";
6772
+ import { readFileSync as readFileSync24, writeFileSync as writeFileSync15, unlinkSync as unlinkSync4 } from "fs";
6773
+ import { join as join33 } from "path";
6774
6774
  function makePkce() {
6775
6775
  const verifier = randomBytes2(48).toString("base64url");
6776
6776
  const challenge = createHash4("sha256").update(verifier).digest("base64url");
@@ -6854,7 +6854,7 @@ function toStore(clientId, t, now) {
6854
6854
  }
6855
6855
  function loadStore() {
6856
6856
  try {
6857
- return JSON.parse(readFileSync23(STORE_PATH2, "utf8"));
6857
+ return JSON.parse(readFileSync24(STORE_PATH2, "utf8"));
6858
6858
  } catch {
6859
6859
  return null;
6860
6860
  }
@@ -6870,7 +6870,7 @@ function clearStore() {
6870
6870
  }
6871
6871
  function loadClientId() {
6872
6872
  try {
6873
- return JSON.parse(readFileSync23(CLIENT_PATH, "utf8")).clientId;
6873
+ return JSON.parse(readFileSync24(CLIENT_PATH, "utf8")).clientId;
6874
6874
  } catch {
6875
6875
  return null;
6876
6876
  }
@@ -6905,8 +6905,8 @@ var init_oauth = __esm({
6905
6905
  AUTHORIZE = "/api/oauth/authorize";
6906
6906
  TOKEN = "/api/oauth/token";
6907
6907
  SCOPE = "openid profile email taskless:full";
6908
- STORE_PATH2 = join32(SWARM_HOME, "oauth.json");
6909
- CLIENT_PATH = join32(SWARM_HOME, "oauth-client.json");
6908
+ STORE_PATH2 = join33(SWARM_HOME, "oauth.json");
6909
+ CLIENT_PATH = join33(SWARM_HOME, "oauth-client.json");
6910
6910
  base2 = (api) => api.replace(/\/$/, "");
6911
6911
  }
6912
6912
  });
@@ -6993,11 +6993,11 @@ var init_authState = __esm({
6993
6993
  });
6994
6994
 
6995
6995
  // src/workspace.ts
6996
- import { readFileSync as readFileSync24, writeFileSync as writeFileSync16, unlinkSync as unlinkSync5 } from "fs";
6997
- import { join as join33 } from "path";
6996
+ import { readFileSync as readFileSync25, writeFileSync as writeFileSync16, unlinkSync as unlinkSync5 } from "fs";
6997
+ import { join as join34 } from "path";
6998
6998
  function loadWorkspace() {
6999
6999
  try {
7000
- const w = JSON.parse(readFileSync24(WORKSPACE_PATH, "utf8"));
7000
+ const w = JSON.parse(readFileSync25(WORKSPACE_PATH, "utf8"));
7001
7001
  return w && typeof w.id === "string" && w.id ? w : null;
7002
7002
  } catch {
7003
7003
  return null;
@@ -7011,7 +7011,7 @@ var init_workspace = __esm({
7011
7011
  "src/workspace.ts"() {
7012
7012
  "use strict";
7013
7013
  init_config();
7014
- WORKSPACE_PATH = join33(SWARM_HOME, "workspace.json");
7014
+ WORKSPACE_PATH = join34(SWARM_HOME, "workspace.json");
7015
7015
  }
7016
7016
  });
7017
7017
 
@@ -8738,9 +8738,9 @@ var init_droneStore = __esm({
8738
8738
  });
8739
8739
 
8740
8740
  // src/overmind.ts
8741
- import { homedir as homedir9 } from "os";
8742
- import { existsSync as existsSync23, readFileSync as readFileSync28, readdirSync as readdirSync18, renameSync as renameSync12, statSync as statSync16 } from "fs";
8743
- import { basename as basename7, dirname as dirname6, join as join40 } from "path";
8741
+ import { homedir as homedir10 } from "os";
8742
+ import { existsSync as existsSync23, readFileSync as readFileSync29, readdirSync as readdirSync18, renameSync as renameSync12, statSync as statSync16 } from "fs";
8743
+ import { basename as basename7, dirname as dirname6, join as join41 } from "path";
8744
8744
  import { fileURLToPath as fileURLToPath3, pathToFileURL } from "url";
8745
8745
  import { spawn as spawn4 } from "child_process";
8746
8746
 
@@ -13426,7 +13426,84 @@ function makeAbortReader(runLogsDir, runLogKeys, executorFor = () => resolveExec
13426
13426
  // src/limitWait.ts
13427
13427
  init_src();
13428
13428
  import { closeSync as closeSync5, fstatSync as fstatSync2, openSync as openSync5, readdirSync as readdirSync14, readSync as readSync2 } from "fs";
13429
+ import { join as join23 } from "path";
13430
+
13431
+ // src/grokBalance.ts
13432
+ init_src();
13433
+ import { readFileSync as readFileSync19 } from "fs";
13434
+ import { homedir as homedir8 } from "os";
13429
13435
  import { join as join22 } from "path";
13436
+ var GROK_BALANCE_WAIT_TAG = "balance-exhausted";
13437
+ var GROK_BALANCE_SIGNAL_KEY = "grok_balance_exhausted";
13438
+ var GROK_BALANCE_SIGNAL_KEY_ROOM = 120 - GROK_BALANCE_SIGNAL_KEY.length - 1;
13439
+ function grokBalanceSignalKey(selfHostId) {
13440
+ const id = (selfHostId ?? "").trim();
13441
+ if (!id) return GROK_BALANCE_SIGNAL_KEY;
13442
+ const suffix = id.length <= GROK_BALANCE_SIGNAL_KEY_ROOM ? id : id.slice(0, GROK_BALANCE_SIGNAL_KEY_ROOM);
13443
+ return `${GROK_BALANCE_SIGNAL_KEY}:${suffix}`;
13444
+ }
13445
+ var GROK_BALANCE_RENOTIFY_MS = 6 * 60 * 60 * 1e3;
13446
+ var GROK_BALANCE_SUCCESS_MS = 5 * 60 * 1e3;
13447
+ var GROK_BALANCE_ACTION = "\u043F\u043E\u043F\u043E\u043B\u043D\u0438 \u0431\u0430\u043B\u0430\u043D\u0441 \u0438\u043B\u0438 \u043F\u0435\u0440\u0435\u043A\u043B\u044E\u0447\u0438 \u0443\u0447\u0451\u0442\u043A\u0443";
13448
+ var EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
13449
+ var EMAIL_MAX = 320;
13450
+ function isGrokBalanceLimitText(text) {
13451
+ return /balance exhausted|payment required/i.test(text) || /(?:error|api|http|status)[^\n]{0,80}\b402\b/i.test(text);
13452
+ }
13453
+ function isGrokBalanceWait(stopReason) {
13454
+ const wait = parseLimitWait(stopReason);
13455
+ return wait?.executor === "grok" && (stopReason ?? "").includes(GROK_BALANCE_WAIT_TAG);
13456
+ }
13457
+ function grokBalanceWaitText() {
13458
+ return `${GROK_BALANCE_WAIT_TAG}: \u043A\u043E\u043D\u0447\u0438\u043B\u0441\u044F \u0431\u0430\u043B\u0430\u043D\u0441 Grok, ${GROK_BALANCE_ACTION}`;
13459
+ }
13460
+ function pluralRuns(n) {
13461
+ const abs = Math.abs(Math.trunc(n)) % 100;
13462
+ const last = abs % 10;
13463
+ if (abs >= 11 && abs <= 14) return "\u043F\u0440\u043E\u0433\u043E\u043D\u043E\u0432";
13464
+ if (last === 1) return "\u043F\u0440\u043E\u0433\u043E\u043D";
13465
+ if (last >= 2 && last <= 4) return "\u043F\u0440\u043E\u0433\u043E\u043D\u0430";
13466
+ return "\u043F\u0440\u043E\u0433\u043E\u043D\u043E\u0432";
13467
+ }
13468
+ function oneLine(text) {
13469
+ return text.replace(/[\r\n]+/g, " ").replace(/[ \t]{2,}/g, " ").trim();
13470
+ }
13471
+ function grokBalanceSignal(input) {
13472
+ const host = oneLine(input.hostName) || "\u043C\u0430\u0448\u0438\u043D\u0430";
13473
+ const email = input.email && isPlainEmail(input.email) ? input.email.trim() : null;
13474
+ const n = Number.isFinite(input.waiting) ? Math.max(0, Math.trunc(input.waiting)) : 0;
13475
+ const account = email ? `\u0423\u0447\u0451\u0442\u043A\u0430 ${email}.` : "\u041F\u043E\u0447\u0442\u0430 \u0443\u0447\u0451\u0442\u043A\u0438 \u043D\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043D\u0430.";
13476
+ const body = oneLine(`\u041C\u0430\u0448\u0438\u043D\u0430 ${host}. ${account} \u0416\u0434\u0443\u0442 ${n} ${pluralRuns(n)}. ${GROK_BALANCE_ACTION}.`);
13477
+ return { title: `${host}: \u043A\u043E\u043D\u0447\u0438\u043B\u0441\u044F \u0431\u0430\u043B\u0430\u043D\u0441 Grok`, body };
13478
+ }
13479
+ function isPlainEmail(value) {
13480
+ const trimmed = value.trim();
13481
+ return trimmed.length > 0 && trimmed.length <= EMAIL_MAX && EMAIL_RE.test(trimmed) && !/[\r\n]/.test(value);
13482
+ }
13483
+ function readGrokAccountEmail(authPath) {
13484
+ let raw;
13485
+ try {
13486
+ raw = readFileSync19(authPath, "utf8");
13487
+ } catch {
13488
+ return null;
13489
+ }
13490
+ let parsed;
13491
+ try {
13492
+ parsed = JSON.parse(raw);
13493
+ } catch {
13494
+ return null;
13495
+ }
13496
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
13497
+ const email = parsed.email;
13498
+ if (typeof email !== "string" || !isPlainEmail(email)) return null;
13499
+ return email.trim();
13500
+ }
13501
+ function grokAccountAuthPath(env, home = homedir8()) {
13502
+ const configured = (env.GROK_HOME ?? "").trim();
13503
+ return join22(configured || join22(home, ".grok"), "auth.json");
13504
+ }
13505
+
13506
+ // src/limitWait.ts
13430
13507
  var TAIL_BYTES = 8 * 1024;
13431
13508
  var SNAPSHOT_FRESH_MS = 15 * 6e4;
13432
13509
  var RESULT_FILE_RE2 = /^(\d+)\.json(\.done)?$/;
@@ -13527,12 +13604,14 @@ function makeLimitReader(logsDir, logKeys, executorOf, snapshot = () => null) {
13527
13604
  const executor = executorOf(run2);
13528
13605
  const launch = latestLaunch(logsDir, logKeys(run2.id));
13529
13606
  if (!launch) return null;
13530
- const stderr = readTail2(join22(launch.dir, `${launch.index}.err.log`)) ?? "";
13531
- const stdout = launch.stdoutName ? readTail2(join22(launch.dir, launch.stdoutName), true) ?? "" : "";
13607
+ const stderr = readTail2(join23(launch.dir, `${launch.index}.err.log`)) ?? "";
13608
+ const stdout = launch.stdoutName ? readTail2(join23(launch.dir, launch.stdoutName), true) ?? "" : "";
13532
13609
  const stdoutText = nonJsonLines(stdout);
13533
13610
  const limitText = matchesLimit(executor.probe.limitPattern, stderr) ? stderr : matchesLimit(executor.probe.limitPattern, stdoutText) ? stdoutText : null;
13534
13611
  if (limitText !== null) {
13535
- return { executor: executor.id, resetHint: limitText.match(RESET_RE)?.[0]?.trim() ?? null };
13612
+ const hit = { executor: executor.id, resetHint: limitText.match(RESET_RE)?.[0]?.trim() ?? null };
13613
+ if (executor.id === "grok") hit.balance = isGrokBalanceLimitText(limitText);
13614
+ return hit;
13536
13615
  }
13537
13616
  if (executor.id === "kimi") {
13538
13617
  const report = snapshot();
@@ -13582,7 +13661,7 @@ init_src();
13582
13661
  init_swarmModels();
13583
13662
  init_executors();
13584
13663
  import { accessSync, constants } from "fs";
13585
- import { delimiter, join as join23 } from "path";
13664
+ import { delimiter, join as join24 } from "path";
13586
13665
  function binRunnable(bin, env) {
13587
13666
  if (!bin) return false;
13588
13667
  if (bin.includes("/") || bin.includes("\\")) {
@@ -13598,7 +13677,7 @@ function binRunnable(bin, env) {
13598
13677
  if (!dir) continue;
13599
13678
  for (const ext of exts) {
13600
13679
  try {
13601
- accessSync(join23(dir, bin + ext), constants.X_OK);
13680
+ accessSync(join24(dir, bin + ext), constants.X_OK);
13602
13681
  return true;
13603
13682
  } catch {
13604
13683
  }
@@ -13642,9 +13721,9 @@ function providerUnavailableReason(providerId, available) {
13642
13721
 
13643
13722
  // src/modelLimits.ts
13644
13723
  import { createHash } from "crypto";
13645
- import { readFileSync as readFileSync19, readdirSync as readdirSync15, statSync as statSync12 } from "fs";
13646
- import { homedir as homedir8 } from "os";
13647
- import { join as join24 } from "path";
13724
+ import { readFileSync as readFileSync20, readdirSync as readdirSync15, statSync as statSync12 } from "fs";
13725
+ import { homedir as homedir9 } from "os";
13726
+ import { join as join25 } from "path";
13648
13727
  var KIMI_USAGES_URL = "https://api.kimi.com/coding/v1/usages";
13649
13728
  var DEFAULT_POLL_MS = 3e5;
13650
13729
  var FETCH_TIMEOUT_MS = 1e4;
@@ -13667,15 +13746,15 @@ function accountKey(userId) {
13667
13746
  }
13668
13747
  function readKimiCredentials(env = process.env) {
13669
13748
  try {
13670
- const root = env.KIMI_CODE_HOME?.trim() || join24(homedir8(), ".kimi-code");
13671
- const dir = join24(root, "credentials");
13672
- const files = readdirSync15(dir).filter((name) => name.endsWith(".json")).map((name) => ({ name, path: join24(dir, name) })).filter((entry) => statSync12(entry.path).isFile());
13749
+ const root = env.KIMI_CODE_HOME?.trim() || join25(homedir9(), ".kimi-code");
13750
+ const dir = join25(root, "credentials");
13751
+ const files = readdirSync15(dir).filter((name) => name.endsWith(".json")).map((name) => ({ name, path: join25(dir, name) })).filter((entry) => statSync12(entry.path).isFile());
13673
13752
  const preferred = files.filter((entry) => entry.name.startsWith("kimi-code-env-"));
13674
13753
  const candidates = preferred.length ? preferred : files;
13675
13754
  candidates.sort((a, b) => statSync12(b.path).mtimeMs - statSync12(a.path).mtimeMs || a.name.localeCompare(b.name));
13676
13755
  const newest2 = candidates[0];
13677
13756
  if (!newest2) return null;
13678
- const body = record(JSON.parse(readFileSync19(newest2.path, "utf8")));
13757
+ const body = record(JSON.parse(readFileSync20(newest2.path, "utf8")));
13679
13758
  if (typeof body?.access_token !== "string" || !body.access_token) return null;
13680
13759
  const userId = jwtUserId(body.access_token);
13681
13760
  return { accessToken: body.access_token, accountKey: accountKey(userId) };
@@ -13810,20 +13889,20 @@ init_src();
13810
13889
  init_git();
13811
13890
 
13812
13891
  // src/deps.ts
13813
- import { existsSync as existsSync16, readdirSync as readdirSync17, readFileSync as readFileSync21 } from "fs";
13814
- import { join as join28 } from "path";
13892
+ import { existsSync as existsSync16, readdirSync as readdirSync17, readFileSync as readFileSync22 } from "fs";
13893
+ import { join as join29 } from "path";
13815
13894
  import { execa } from "execa";
13816
13895
 
13817
13896
  // src/prepareLock.ts
13818
13897
  import { createHash as createHash2 } from "crypto";
13819
13898
  import { closeSync as closeSync6, openSync as openSync6, rmSync as rmSync2, statSync as statSync14, writeSync as writeSync2 } from "fs";
13820
- import { join as join26 } from "path";
13899
+ import { join as join27 } from "path";
13821
13900
  import { tmpdir } from "os";
13822
13901
  var WAIT_TIMEOUT_MS = 5 * 6e4;
13823
13902
  var POLL_MS = 300;
13824
13903
  var STALE_MS = 20 * 6e4;
13825
13904
  function machineLockPath(key, dir = tmpdir()) {
13826
- return join26(dir, `swarm-prepare-${createHash2("sha1").update(key).digest("hex").slice(0, 16)}.lock`);
13905
+ return join27(dir, `swarm-prepare-${createHash2("sha1").update(key).digest("hex").slice(0, 16)}.lock`);
13827
13906
  }
13828
13907
  function defaultTryCreate(path, content) {
13829
13908
  try {
@@ -13884,8 +13963,8 @@ init_config();
13884
13963
  init_config();
13885
13964
  import { createHash as createHash3 } from "crypto";
13886
13965
  import { cp, link, lstat, mkdir as mkdir2, readdir, readlink, rename as rename2, rm as rm2, stat, symlink, utimes, writeFile as writeFile2 } from "fs/promises";
13887
- import { existsSync as existsSync15, readFileSync as readFileSync20 } from "fs";
13888
- import { join as join27 } from "path";
13966
+ import { existsSync as existsSync15, readFileSync as readFileSync21 } from "fs";
13967
+ import { join as join28 } from "path";
13889
13968
  function fingerprint(parts) {
13890
13969
  const h = createHash3("sha256");
13891
13970
  for (const p of parts) {
@@ -13899,8 +13978,8 @@ async function cloneTree(src, dst) {
13899
13978
  const entries = await readdir(src, { withFileTypes: true });
13900
13979
  await Promise.all(
13901
13980
  entries.map(async (e) => {
13902
- const from = join27(src, e.name);
13903
- const to = join27(dst, e.name);
13981
+ const from = join28(src, e.name);
13982
+ const to = join28(dst, e.name);
13904
13983
  if (e.isDirectory()) return cloneTree(from, to);
13905
13984
  if (e.isSymbolicLink()) {
13906
13985
  return symlink(await readlink(from), to).catch(() => cp(from, to, { recursive: true, verbatimSymlinks: true }));
@@ -13913,11 +13992,11 @@ function cacheRoot(io) {
13913
13992
  return io.root ?? ENV_CACHE_DIR;
13914
13993
  }
13915
13994
  function snapshotDir(io, key) {
13916
- return join27(cacheRoot(io), key);
13995
+ return join28(cacheRoot(io), key);
13917
13996
  }
13918
13997
  function readManifest(dir) {
13919
13998
  try {
13920
- const parsed = JSON.parse(readFileSync20(join27(dir, "manifest.json"), "utf8"));
13999
+ const parsed = JSON.parse(readFileSync21(join28(dir, "manifest.json"), "utf8"));
13921
14000
  if (!parsed || typeof parsed !== "object") return null;
13922
14001
  const m = parsed;
13923
14002
  if (typeof m.key !== "string" || !Array.isArray(m.dirs)) return null;
@@ -13930,7 +14009,7 @@ function readManifest(dir) {
13930
14009
  }
13931
14010
  function hasEnvSnapshot(key, io = {}) {
13932
14011
  const exists = io.exists ?? existsSync15;
13933
- return exists(join27(snapshotDir(io, key), "manifest.json"));
14012
+ return exists(join28(snapshotDir(io, key), "manifest.json"));
13934
14013
  }
13935
14014
  async function restoreEnvSnapshot(worktree, key, io = {}) {
13936
14015
  const exists = io.exists ?? existsSync15;
@@ -13942,13 +14021,13 @@ async function restoreEnvSnapshot(worktree, key, io = {}) {
13942
14021
  try {
13943
14022
  for (let i = 0; i < manifest.dirs.length; i++) {
13944
14023
  const rel = manifest.dirs[i] ?? "";
13945
- const target = join27(worktree, rel);
14024
+ const target = join28(worktree, rel);
13946
14025
  if (exists(target)) continue;
13947
- await clone(join27(dir, "trees", String(i)), target);
14026
+ await clone(join28(dir, "trees", String(i)), target);
13948
14027
  made.push(rel);
13949
14028
  }
13950
14029
  } catch {
13951
- for (const rel of made) await rm2(join27(worktree, rel), { recursive: true, force: true }).catch(() => {
14030
+ for (const rel of made) await rm2(join28(worktree, rel), { recursive: true, force: true }).catch(() => {
13952
14031
  });
13953
14032
  return null;
13954
14033
  }
@@ -13964,16 +14043,16 @@ async function saveEnvSnapshot(worktree, key, dirs, io = {}) {
13964
14043
  const exists = io.exists ?? existsSync15;
13965
14044
  const clone = io.clone ?? cloneTree;
13966
14045
  if (hasEnvSnapshot(key, io)) return true;
13967
- const present = dirs.filter((rel) => exists(join27(worktree, rel)));
14046
+ const present = dirs.filter((rel) => exists(join28(worktree, rel)));
13968
14047
  if (!present.length) return false;
13969
14048
  const root = cacheRoot(io);
13970
- const tmp = join27(root, `.tmp-${key}-${process.pid}`);
14049
+ const tmp = join28(root, `.tmp-${key}-${process.pid}`);
13971
14050
  try {
13972
14051
  await rm2(tmp, { recursive: true, force: true });
13973
- await mkdir2(join27(tmp, "trees"), { recursive: true });
13974
- for (let i = 0; i < present.length; i++) await clone(join27(worktree, present[i] ?? ""), join27(tmp, "trees", String(i)));
14052
+ await mkdir2(join28(tmp, "trees"), { recursive: true });
14053
+ for (let i = 0; i < present.length; i++) await clone(join28(worktree, present[i] ?? ""), join28(tmp, "trees", String(i)));
13975
14054
  const manifest = { key, dirs: present, createdAt: (/* @__PURE__ */ new Date()).toISOString() };
13976
- await writeFile2(join27(tmp, "manifest.json"), JSON.stringify(manifest, null, 2));
14055
+ await writeFile2(join28(tmp, "manifest.json"), JSON.stringify(manifest, null, 2));
13977
14056
  await rename2(tmp, snapshotDir(io, key));
13978
14057
  return true;
13979
14058
  } catch {
@@ -13993,13 +14072,13 @@ async function pruneEnvSnapshots(io = {}) {
13993
14072
  }
13994
14073
  const withTime = [];
13995
14074
  for (const name of names) {
13996
- const s = await stat(join27(root, name)).catch(() => null);
14075
+ const s = await stat(join28(root, name)).catch(() => null);
13997
14076
  if (s) withTime.push({ name, mtime: s.mtimeMs });
13998
14077
  }
13999
14078
  withTime.sort((a, b) => b.mtime - a.mtime);
14000
14079
  let removed = 0;
14001
14080
  for (const { name } of withTime.slice(Math.max(0, keep))) {
14002
- await rm2(join27(root, name), { recursive: true, force: true }).catch(() => {
14081
+ await rm2(join28(root, name), { recursive: true, force: true }).catch(() => {
14003
14082
  });
14004
14083
  removed++;
14005
14084
  }
@@ -14015,9 +14094,9 @@ async function sweepEnvCacheTemp(io = {}) {
14015
14094
  }
14016
14095
  let removed = 0;
14017
14096
  for (const name of names) {
14018
- const s = await lstat(join27(root, name)).catch(() => null);
14097
+ const s = await lstat(join28(root, name)).catch(() => null);
14019
14098
  if (!s || Date.now() - s.mtimeMs < 60 * 6e4) continue;
14020
- await rm2(join27(root, name), { recursive: true, force: true }).catch(() => {
14099
+ await rm2(join28(root, name), { recursive: true, force: true }).catch(() => {
14021
14100
  });
14022
14101
  removed++;
14023
14102
  }
@@ -14044,7 +14123,7 @@ async function runCommand(cmd, worktree) {
14044
14123
  }
14045
14124
  function safeReadText(p) {
14046
14125
  try {
14047
- return readFileSync21(p, "utf8");
14126
+ return readFileSync22(p, "utf8");
14048
14127
  } catch {
14049
14128
  return null;
14050
14129
  }
@@ -14086,19 +14165,19 @@ function overridePlan(override) {
14086
14165
  function detectPackageManager(worktree, io = {}) {
14087
14166
  const exists = io.exists ?? existsSync16;
14088
14167
  const readText = io.readText ?? safeReadText;
14089
- const hasPkgJson = exists(join28(worktree, "package.json"));
14168
+ const hasPkgJson = exists(join29(worktree, "package.json"));
14090
14169
  if (!hasPkgJson) {
14091
- if (exists(join28(worktree, "deno.json")) || exists(join28(worktree, "deno.jsonc")) || exists(join28(worktree, "deno.lock"))) return "deno";
14170
+ if (exists(join29(worktree, "deno.json")) || exists(join29(worktree, "deno.jsonc")) || exists(join29(worktree, "deno.lock"))) return "deno";
14092
14171
  return null;
14093
14172
  }
14094
- const pkg = readJson(readText, join28(worktree, "package.json"));
14173
+ const pkg = readJson(readText, join29(worktree, "package.json"));
14095
14174
  const declared = typeof pkg?.packageManager === "string" ? pkg.packageManager.split("@")[0] : void 0;
14096
14175
  if (declared === "pnpm" || declared === "bun" || declared === "npm" || declared === "yarn") return declared;
14097
- if (exists(join28(worktree, "bun.lock")) || exists(join28(worktree, "bun.lockb"))) return "bun";
14098
- if (exists(join28(worktree, "pnpm-lock.yaml"))) return "pnpm";
14099
- if (exists(join28(worktree, "yarn.lock"))) return "yarn";
14100
- if (exists(join28(worktree, "package-lock.json"))) return "npm";
14101
- if (exists(join28(worktree, "deno.lock"))) return "deno";
14176
+ if (exists(join29(worktree, "bun.lock")) || exists(join29(worktree, "bun.lockb"))) return "bun";
14177
+ if (exists(join29(worktree, "pnpm-lock.yaml"))) return "pnpm";
14178
+ if (exists(join29(worktree, "yarn.lock"))) return "yarn";
14179
+ if (exists(join29(worktree, "package-lock.json"))) return "npm";
14180
+ if (exists(join29(worktree, "deno.lock"))) return "deno";
14102
14181
  return "npm";
14103
14182
  }
14104
14183
  function jsInstallCommand(pm) {
@@ -14162,7 +14241,7 @@ function detectPlan(worktree, io) {
14162
14241
  // node_modules на месте — установку пропускаем (быстрый путь переиспользованного worktree).
14163
14242
  // У deno каталога может не быть вовсе (кэш в DENO_DIR) — тогда `deno install` отработает
14164
14243
  // заново, но он дешёвый: тянет из того же общего кэша.
14165
- { label: `${pm} install`, run: jsInstallCommand(pm), skipIfExists: join28(worktree, "node_modules"), source: "detect" }
14244
+ { label: `${pm} install`, run: jsInstallCommand(pm), skipIfExists: join29(worktree, "node_modules"), source: "detect" }
14166
14245
  ];
14167
14246
  for (const target of workspaceBuildTargets(worktree, io)) {
14168
14247
  commands.push({ label: `\u0441\u0431\u043E\u0440\u043A\u0430 ${target.name}`, run: jsRunScript(pm, "build"), cwd: target.dir, source: "detect" });
@@ -14171,12 +14250,12 @@ function detectPlan(worktree, io) {
14171
14250
  return { source: "detect", ecosystem: `node/${pm}`, commands };
14172
14251
  }
14173
14252
  for (const marker of ECOSYSTEM_MARKERS) {
14174
- const hit = marker.files.some((f) => exists(join28(worktree, f))) || marker.ext !== void 0 && listFiles(worktree).some((n) => n.endsWith(marker.ext));
14253
+ const hit = marker.files.some((f) => exists(join29(worktree, f))) || marker.ext !== void 0 && listFiles(worktree).some((n) => n.endsWith(marker.ext));
14175
14254
  if (!hit) continue;
14176
14255
  let ecosystem = marker.ecosystem;
14177
14256
  let command = marker.command;
14178
14257
  for (const refine of marker.refine ?? []) {
14179
- if (!exists(join28(worktree, refine.file))) continue;
14258
+ if (!exists(join29(worktree, refine.file))) continue;
14180
14259
  ecosystem = refine.ecosystem;
14181
14260
  command = refine.command;
14182
14261
  break;
@@ -14233,12 +14312,12 @@ var CI_INSTALL_PATTERNS = [
14233
14312
  function ciWorkflowPlan(worktree, io) {
14234
14313
  const readText = io.readText ?? safeReadText;
14235
14314
  const listFiles = io.listFiles ?? safeListFiles;
14236
- const dir = join28(worktree, ".github", "workflows");
14315
+ const dir = join29(worktree, ".github", "workflows");
14237
14316
  const files = listFiles(dir).filter((n) => n.endsWith(".yml") || n.endsWith(".yaml"));
14238
14317
  const seen = /* @__PURE__ */ new Set();
14239
14318
  const commands = [];
14240
14319
  for (const name of files.sort()) {
14241
- const yaml = readText(join28(dir, name));
14320
+ const yaml = readText(join29(dir, name));
14242
14321
  if (yaml === null) continue;
14243
14322
  for (const raw of workflowRunLines(yaml)) {
14244
14323
  const line = raw.replace(/\s+/g, " ").trim();
@@ -14253,7 +14332,7 @@ function ciWorkflowPlan(worktree, io) {
14253
14332
  return commands.length ? { source: "ci-workflow", ecosystem: "ci-\u043A\u043E\u043D\u0444\u0438\u0433", commands } : null;
14254
14333
  }
14255
14334
  function workspaceGlobs(worktree, readText) {
14256
- const yaml = readText(join28(worktree, "pnpm-workspace.yaml"));
14335
+ const yaml = readText(join29(worktree, "pnpm-workspace.yaml"));
14257
14336
  if (yaml !== null) {
14258
14337
  const globs = [];
14259
14338
  let inPackages = false;
@@ -14273,7 +14352,7 @@ function workspaceGlobs(worktree, readText) {
14273
14352
  }
14274
14353
  if (globs.length) return globs;
14275
14354
  }
14276
- const pkg = readJson(readText, join28(worktree, "package.json"));
14355
+ const pkg = readJson(readText, join29(worktree, "package.json"));
14277
14356
  const ws = pkg?.workspaces;
14278
14357
  const list = Array.isArray(ws) ? ws : Array.isArray(ws?.packages) ? ws.packages : [];
14279
14358
  return list.filter((g) => typeof g === "string");
@@ -14284,14 +14363,14 @@ function workspaceDirs(worktree, globs, io) {
14284
14363
  if (glob.startsWith("!")) continue;
14285
14364
  const star = glob.indexOf("*");
14286
14365
  if (star === -1) {
14287
- const dir = join28(worktree, glob);
14288
- if (io.exists(join28(dir, "package.json"))) dirs.add(dir);
14366
+ const dir = join29(worktree, glob);
14367
+ if (io.exists(join29(dir, "package.json"))) dirs.add(dir);
14289
14368
  continue;
14290
14369
  }
14291
- const base3 = join28(worktree, glob.slice(0, star).replace(/\/$/, ""));
14370
+ const base3 = join29(worktree, glob.slice(0, star).replace(/\/$/, ""));
14292
14371
  for (const name of io.listDirs(base3)) {
14293
- const dir = join28(base3, name);
14294
- if (io.exists(join28(dir, "package.json"))) dirs.add(dir);
14372
+ const dir = join29(base3, name);
14373
+ if (io.exists(join29(dir, "package.json"))) dirs.add(dir);
14295
14374
  }
14296
14375
  }
14297
14376
  return [...dirs];
@@ -14319,11 +14398,11 @@ function workspaceBuildTargets(worktree, io = {}) {
14319
14398
  if (!globs.length) return [];
14320
14399
  const pkgs = [];
14321
14400
  for (const dir of workspaceDirs(worktree, globs, { exists, listDirs })) {
14322
- const pkg = readJson(readText, join28(dir, "package.json"));
14401
+ const pkg = readJson(readText, join29(dir, "package.json"));
14323
14402
  if (!pkg || typeof pkg.name !== "string") continue;
14324
14403
  const scripts = pkg.scripts ?? {};
14325
14404
  const entries = entryPaths(pkg);
14326
- const needsBuild = typeof scripts.build === "string" && entries.length > 0 && entries.some((e) => !exists(join28(dir, e)));
14405
+ const needsBuild = typeof scripts.build === "string" && entries.length > 0 && entries.some((e) => !exists(join29(dir, e)));
14327
14406
  const deps = Object.keys({ ...pkg.dependencies ?? {}, ...pkg.devDependencies ?? {} });
14328
14407
  pkgs.push({ name: pkg.name, dir, deps, needsBuild });
14329
14408
  }
@@ -14351,7 +14430,7 @@ function devDatabaseUrl(worktree, io = {}) {
14351
14430
  const fromEnv = (io.env ?? process.env).DATABASE_URL;
14352
14431
  if (fromEnv && fromEnv.trim()) return fromEnv.trim();
14353
14432
  for (const file of [".env", ".env.example"]) {
14354
- const raw = readText(join28(worktree, file));
14433
+ const raw = readText(join29(worktree, file));
14355
14434
  if (raw === null) continue;
14356
14435
  const m = /^\s*(?:export\s+)?DATABASE_URL\s*=\s*(.*)$/m.exec(raw);
14357
14436
  const value = (m?.[1] ?? "").trim().replace(/^['"]|['"]$/g, "");
@@ -14371,7 +14450,7 @@ function prismaPackages(worktree, io) {
14371
14450
  const readText = io.readText ?? safeReadText;
14372
14451
  const listDirs = io.listDirs ?? safeListDirs;
14373
14452
  const dirs = [worktree, ...workspaceDirs(worktree, workspaceGlobs(worktree, readText), { exists, listDirs })];
14374
- return dirs.filter((dir) => exists(join28(dir, "prisma", "schema.prisma")) && listDirs(join28(dir, "prisma", "migrations")).length > 0);
14453
+ return dirs.filter((dir) => exists(join29(dir, "prisma", "schema.prisma")) && listDirs(join29(dir, "prisma", "migrations")).length > 0);
14375
14454
  }
14376
14455
  function jsExecBin(pm, command) {
14377
14456
  switch (pm) {
@@ -14408,18 +14487,18 @@ function envCachePlan(worktree, io = {}) {
14408
14487
  if (!pm) return null;
14409
14488
  const parts = [`pm:${pm}`];
14410
14489
  for (const name of ENV_DEFINING_FILES) {
14411
- const raw = readText(join28(worktree, name));
14490
+ const raw = readText(join29(worktree, name));
14412
14491
  if (raw !== null) parts.push(`${name}
14413
14492
  ${raw}`);
14414
14493
  }
14415
14494
  const pkgDirs = workspaceDirs(worktree, workspaceGlobs(worktree, readText), { exists, listDirs });
14416
14495
  const rels = pkgDirs.map((dir) => dir.slice(worktree.length + 1)).sort();
14417
14496
  for (const rel of ["", ...rels]) {
14418
- const raw = readText(join28(worktree, rel, "package.json"));
14497
+ const raw = readText(join29(worktree, rel, "package.json"));
14419
14498
  if (raw !== null) parts.push(`${rel}/package.json
14420
14499
  ${raw}`);
14421
14500
  }
14422
- return { key: fingerprint(parts), dirs: ["node_modules", ...rels.map((rel) => join28(rel, "node_modules"))] };
14501
+ return { key: fingerprint(parts), dirs: ["node_modules", ...rels.map((rel) => join29(rel, "node_modules"))] };
14423
14502
  }
14424
14503
  function planPrepare(worktree, io = {}) {
14425
14504
  const plan = overridePlan(io.override) ?? detectPlan(worktree, io) ?? ciWorkflowPlan(worktree, io);
@@ -14444,7 +14523,7 @@ async function ensureWorktreeDeps(worktree, io = {}) {
14444
14523
  restored: [],
14445
14524
  cached: false
14446
14525
  };
14447
- if (cachePlan && !exists(join28(worktree, "node_modules"))) {
14526
+ if (cachePlan && !exists(join29(worktree, "node_modules"))) {
14448
14527
  report.restored = await restoreEnvSnapshot(worktree, cachePlan.key, cacheIO) ?? [];
14449
14528
  }
14450
14529
  const plan = planPrepare(worktree, io);
@@ -14532,7 +14611,7 @@ function depsPromptNotice(report) {
14532
14611
  // src/orchestrator.ts
14533
14612
  init_config();
14534
14613
  import { existsSync as existsSync17, mkdirSync as mkdirSync11, rmSync as rmSync3 } from "fs";
14535
- import { join as join29, dirname as dirname4 } from "path";
14614
+ import { join as join30, dirname as dirname4 } from "path";
14536
14615
  function droneLaunchedText(workdir, pid) {
14537
14616
  return `\u0434\u0440\u043E\u043D \u0437\u0430\u043F\u0443\u0449\u0435\u043D \u0432 ${workdir} (pid ${pid})`;
14538
14617
  }
@@ -14548,7 +14627,7 @@ function droneLaunchedPid(text) {
14548
14627
  return m ? Number(m[1]) : null;
14549
14628
  }
14550
14629
  function repolessRunDir(worktreesDir, taskSlug) {
14551
- return join29(dirname4(worktreesDir), "runs", taskSlug);
14630
+ return join30(dirname4(worktreesDir), "runs", taskSlug);
14552
14631
  }
14553
14632
  var WORKTREE_HELD_STATUSES = /* @__PURE__ */ new Set(["running", "blocked", "review", "paused", "storm_dead"]);
14554
14633
  function worktreePathHeldLive(db, path, exceptRunId) {
@@ -14830,7 +14909,7 @@ function parkReasonUnretriable(reason) {
14830
14909
  // package.json
14831
14910
  var package_default = {
14832
14911
  name: "@taskless-app/swarm",
14833
- version: "0.6.99",
14912
+ version: "0.6.101",
14834
14913
  type: "module",
14835
14914
  description: "Local control plane for a fleet of AI coding agents (drones), coordinating through Taskless. The overmind runs the swarm.",
14836
14915
  keywords: [
@@ -14882,7 +14961,7 @@ var package_default = {
14882
14961
  undici: "^7.30.1",
14883
14962
  zod: "3.25.76"
14884
14963
  },
14885
- gitHead: "c9fdf089ff8f593a9d14f77bb6be981355bf9749"
14964
+ gitHead: "9216f89857eb8625eecb9a3ededb87cb65a15dec"
14886
14965
  };
14887
14966
 
14888
14967
  // src/version.ts
@@ -16005,7 +16084,7 @@ init_git();
16005
16084
 
16006
16085
  // src/diff.ts
16007
16086
  import { statSync as statSync15 } from "fs";
16008
- import { join as join34 } from "path";
16087
+ import { join as join35 } from "path";
16009
16088
  import { $ as $5 } from "execa";
16010
16089
  var MAX_FILES = 200;
16011
16090
  var MAX_LINES_PER_FILE = 1500;
@@ -16173,7 +16252,7 @@ async function collectRunDiff(worktree, opts = {}) {
16173
16252
  files.push(pf);
16174
16253
  }
16175
16254
  }
16176
- files.sort((a, b) => mtime(join34(worktree, b.path)) - mtime(join34(worktree, a.path)));
16255
+ files.sort((a, b) => mtime(join35(worktree, b.path)) - mtime(join35(worktree, a.path)));
16177
16256
  const truncatedFiles = files.length > MAX_FILES;
16178
16257
  if (truncatedFiles) files = files.slice(0, MAX_FILES);
16179
16258
  const added = files.reduce((s, f) => s + f.added, 0);
@@ -16249,6 +16328,31 @@ function reviewCyclesExhausted(run2) {
16249
16328
  function needsFixIteration(run2) {
16250
16329
  return run2.review_verdict === "changes" || isNegativeVerifyVerdict(toVerifyVerdict(run2.verify_verdict));
16251
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
+ }
16252
16356
  function reviewTransitionPatch(run2, prUrl) {
16253
16357
  const isFixIteration = needsFixIteration(run2);
16254
16358
  if (isFixIteration) {
@@ -16915,8 +17019,13 @@ ${failText}` : failText }],
16915
17019
  }
16916
17020
  const reviewed = await store.getRun(run2.reviews_run_id);
16917
17021
  const verdictText = verdictLabel(verdict);
17022
+ const reviewHead = await headSha(opts.worktree ?? process.cwd());
16918
17023
  await store.updateRun(run2.reviews_run_id, { review_verdict: verdict });
16919
- 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}` : ""}`);
17024
+ await store.addEvent(
17025
+ run2.reviews_run_id,
17026
+ "step",
17027
+ appendVerdictHead(`\u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u0440\u0435\u0432\u044C\u044E \u043E\u0442 ${run2.name}: ${verdictText}${summary ? ` \u2014 ${summary}` : ""}`, reviewHead)
17028
+ );
16920
17029
  const reviewedSlug = reportSlug(reviewed?.task_slug);
16921
17030
  let shots = { attachments: [], warning: "" };
16922
17031
  let commentWarning = "";
@@ -16982,8 +17091,13 @@ ${failText}` : failText }],
16982
17091
  }
16983
17092
  const verified = await store.getRun(run2.verifies_run_id);
16984
17093
  const verdictText = verifyVerdictLabel(verdict);
17094
+ const verifyHead = await headSha(opts.worktree ?? process.cwd());
16985
17095
  await store.updateRun(run2.verifies_run_id, { verify_verdict: verdict });
16986
- 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}` : ""}`);
17096
+ await store.addEvent(
17097
+ run2.verifies_run_id,
17098
+ "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)
17100
+ );
16987
17101
  const verifiedSlug = reportSlug(verified?.task_slug);
16988
17102
  let shots = { attachments: [], warning: "" };
16989
17103
  let commentWarning = "";
@@ -17507,6 +17621,10 @@ var AnomalyTracker = class {
17507
17621
  this.fires.delete(key);
17508
17622
  this.persist();
17509
17623
  }
17624
+ /** Когда по этому ключу последний раз ушёл сигнал. Нет — ещё не звонили. Кулдаун rearm не сбрасывает. */
17625
+ lastFiredMs(key) {
17626
+ return this.lastFiredAt.get(key);
17627
+ }
17510
17628
  /**
17511
17629
  * Пора ли снова спросить внешний мир (gh) про ключ (TAS-1100): не чаще everyMs.
17512
17630
  * Только память: после рестарта первый вопрос уйдёт сразу — один вызов на прогон, не поток.
@@ -18681,21 +18799,21 @@ async function prodClearMergeIntent(runId, deps = {}) {
18681
18799
 
18682
18800
  // src/envGate.ts
18683
18801
  import { existsSync as existsSync20 } from "fs";
18684
- import { join as join36 } from "path";
18802
+ import { join as join37 } from "path";
18685
18803
  import { createConnection } from "net";
18686
18804
  import { execa as execa2 } from "execa";
18687
18805
 
18688
18806
  // src/platform.ts
18689
18807
  init_src();
18690
- import { accessSync as accessSync2, constants as constants2, existsSync as existsSync19, readFileSync as readFileSync25, realpathSync as realpathSync3 } from "fs";
18691
- import { delimiter as delimiter2, join as join35, posix as posix2, win32 } from "path";
18808
+ import { accessSync as accessSync2, constants as constants2, existsSync as existsSync19, readFileSync as readFileSync26, realpathSync as realpathSync3 } from "fs";
18809
+ import { delimiter as delimiter2, join as join36, posix as posix2, win32 } from "path";
18692
18810
  function resolveCommandPath(name, env = process.env, platform = process.platform) {
18693
18811
  if (name.includes("/") || name.includes("\\")) return existsSync19(name) ? name : null;
18694
18812
  const dirs = (env.PATH ?? env.Path ?? "").split(delimiter2).filter(Boolean);
18695
18813
  const exts = platform === "win32" ? (env.PATHEXT ?? ".EXE;.CMD;.BAT").split(";").filter(Boolean) : [""];
18696
18814
  for (const dir of dirs) {
18697
18815
  for (const ext of exts) {
18698
- const candidate = join35(dir, name + ext);
18816
+ const candidate = join36(dir, name + ext);
18699
18817
  if (existsSync19(candidate)) return candidate;
18700
18818
  }
18701
18819
  }
@@ -18866,7 +18984,7 @@ var COMPOSE_MARKERS = [
18866
18984
  ];
18867
18985
  function detectRequirements(repo, io = {}) {
18868
18986
  const exists = io.exists ?? existsSync20;
18869
- const marker = COMPOSE_MARKERS.find((f) => exists(join36(repo, f)));
18987
+ const marker = COMPOSE_MARKERS.find((f) => exists(join37(repo, f)));
18870
18988
  return marker ? [{ kind: "docker", raw: `docker (\u0434\u0435\u0442\u0435\u043A\u0442: ${marker})` }] : [];
18871
18989
  }
18872
18990
  function resolveRequirements(repo, declared, io = {}) {
@@ -20693,14 +20811,14 @@ function closeWebServer(server) {
20693
20811
 
20694
20812
  // src/hostCommands.ts
20695
20813
  init_src();
20696
- import { readFileSync as readFileSync26, renameSync as renameSync10, writeFileSync as writeFileSync17 } from "fs";
20697
- import { join as join37 } from "path";
20814
+ import { readFileSync as readFileSync27, renameSync as renameSync10, writeFileSync as writeFileSync17 } from "fs";
20815
+ import { join as join38 } from "path";
20698
20816
  function hostCommandStatePath(home) {
20699
- return join37(home, "host-command.json");
20817
+ return join38(home, "host-command.json");
20700
20818
  }
20701
20819
  function readState(path) {
20702
20820
  try {
20703
- return JSON.parse(readFileSync26(path, "utf8"));
20821
+ return JSON.parse(readFileSync27(path, "utf8"));
20704
20822
  } catch {
20705
20823
  return {};
20706
20824
  }
@@ -20871,7 +20989,7 @@ async function doRestart(cmd, opts, note) {
20871
20989
  // src/selfUpdate.ts
20872
20990
  init_git();
20873
20991
  import { existsSync as existsSync21 } from "fs";
20874
- import { join as join38 } from "path";
20992
+ import { join as join39 } from "path";
20875
20993
  import { $ as $6 } from "execa";
20876
20994
 
20877
20995
  // src/cliIo.ts
@@ -20933,7 +21051,7 @@ async function runSelfUpdate(io) {
20933
21051
  };
20934
21052
  }
20935
21053
  await io.onStep("install", "\u0441\u0442\u0430\u0432\u043B\u044E \u0437\u0430\u0432\u0438\u0441\u0438\u043C\u043E\u0441\u0442\u0438");
20936
- if (!exists(join38(repo, "pnpm-lock.yaml"))) {
21054
+ if (!exists(join39(repo, "pnpm-lock.yaml"))) {
20937
21055
  return { ok: false, step: "install", message: "\u0432 \u0440\u0435\u043F\u043E\u0437\u0438\u0442\u043E\u0440\u0438\u0438 \u0434\u0435\u043C\u043E\u043D\u0430 \u043D\u0435\u0442 pnpm-lock.yaml \u2014 \u043E\u0431\u043D\u043E\u0432\u043B\u044F\u0442\u044C \u0435\u0433\u043E \u044D\u0442\u0438\u043C \u043F\u0443\u0442\u0451\u043C \u043D\u0435 \u0431\u0435\u0440\u0443\u0441\u044C" };
20938
21056
  }
20939
21057
  const installed2 = await run2("pnpm", ["install", "--frozen-lockfile"], repo);
@@ -21108,19 +21226,19 @@ async function fetchExternalStorm(url, opts = {}) {
21108
21226
  }
21109
21227
 
21110
21228
  // src/anomalyState.ts
21111
- import { existsSync as existsSync22, readFileSync as readFileSync27, renameSync as renameSync11, writeFileSync as writeFileSync18 } from "fs";
21112
- import { join as join39 } from "path";
21229
+ import { existsSync as existsSync22, readFileSync as readFileSync28, renameSync as renameSync11, writeFileSync as writeFileSync18 } from "fs";
21230
+ import { join as join40 } from "path";
21113
21231
  var KEY_TTL_MS = 7 * 24 * 60 * 6e4;
21114
21232
  var MAX_RESOLVED = 200;
21115
21233
  function emptyState() {
21116
21234
  return { since: {}, lastFiredAt: {}, fires: {}, resolved: [], stopQuiet: null };
21117
21235
  }
21118
21236
  function anomalyStatePath(home) {
21119
- return join39(home, "anomaly-state.json");
21237
+ return join40(home, "anomaly-state.json");
21120
21238
  }
21121
21239
  function loadAnomalyState(home, now = Date.now(), io = {}) {
21122
21240
  const exists = io.exists ?? existsSync22;
21123
- const readFile3 = io.readFile ?? ((p) => readFileSync27(p, "utf8"));
21241
+ const readFile3 = io.readFile ?? ((p) => readFileSync28(p, "utf8"));
21124
21242
  const path = anomalyStatePath(home);
21125
21243
  if (!exists(path)) return emptyState();
21126
21244
  try {
@@ -22184,6 +22302,10 @@ async function spawnVerifiersForOpenPrs(deps, _stormActive) {
22184
22302
  noteDraftHold(run2);
22185
22303
  continue;
22186
22304
  }
22305
+ if (grokBalanceBlocksChecker(deps, run2)) {
22306
+ noteGrokBalanceSkip(deps, run2, "\u0432\u0435\u0440\u0438\u0444\u0438\u043A\u0430\u0442\u043E\u0440\u0430");
22307
+ continue;
22308
+ }
22187
22309
  await deps.spawnVerifier(run2, st?.files ?? []);
22188
22310
  narrate(deps, `PR ${droneLabel(run2)} \u043E\u0442\u043A\u0440\u044B\u0442 \u2014 \u043F\u043E\u0434\u043D\u0438\u043C\u0430\u044E \u0432\u0435\u0440\u0438\u0444\u0438\u043A\u0430\u0442\u043E\u0440\u0430: \u043F\u0443\u0441\u0442\u044C \u043F\u043E\u043F\u0440\u043E\u0431\u0443\u0435\u0442 \u043E\u043F\u0440\u043E\u0432\u0435\u0440\u0433\u043D\u0443\u0442\u044C \u0437\u0430\u044F\u0432\u043B\u0435\u043D\u043D\u043E\u0435.`);
22189
22311
  } catch (e) {
@@ -22245,16 +22367,40 @@ function buildCiReadyNudge(prUrl, over) {
22245
22367
  ].join("\n");
22246
22368
  }
22247
22369
  var SUBMISSION_REVIEW_STEP = "2. `/code-review --fix` \u2014 \u043F\u0440\u043E\u0433\u043E\u043D\u0438 \u0440\u0435\u0432\u044C\u044E \u0441\u0432\u043E\u0435\u0433\u043E \u0434\u0438\u0444\u0444\u0430, \u043A\u043B\u0430\u0441\u0441\u044B \u0434\u0435\u0444\u0435\u043A\u0442\u043E\u0432 \u2014 \u0432 skill `swarm-drone:taskless-review`; \u043F\u0440\u0438\u043C\u0435\u043D\u0451\u043D\u043D\u044B\u0435 \u043F\u0440\u0430\u0432\u043A\u0438 \u043F\u0435\u0440\u0435\u0447\u0438\u0442\u0430\u0439 \u0438 \u043F\u0435\u0440\u0435\u0443\u0431\u0435\u0434\u0438\u0441\u044C, \u0447\u0442\u043E \u043D\u0435 \u0441\u043B\u043E\u043C\u0430\u043B \u0444\u0438\u0447\u0443.";
22248
- function dockerStandRules(prefix, homeDir = homedir9()) {
22370
+ function dockerStandRules(prefix, homeDir = homedir10()) {
22249
22371
  return `\u0421\u0432\u043E\u0438 \u043A\u043E\u043D\u0442\u0435\u0439\u043D\u0435\u0440\u044B \u043D\u0430\u0437\u044B\u0432\u0430\u0439 \u0441 \u043F\u0440\u0435\u0444\u0438\u043A\u0441\u043E\u043C ${prefix}: \`docker compose\` \u0431\u0435\u0437 \`-p\` \u0443\u0436\u0435 \u0435\u0433\u043E \u0431\u0435\u0440\u0451\u0442, \u0438\u043C\u0435\u043D\u0430 \u043A\u043E\u043D\u0442\u0435\u0439\u043D\u0435\u0440\u043E\u0432 \u2014 \`\${COMPOSE_PROJECT_NAME}-<\u0441\u0435\u0440\u0432\u0438\u0441>-1\`, \u043D\u0435 \u0438\u0437 README \u0440\u0435\u043F\u043E\u0437\u0438\u0442\u043E\u0440\u0438\u044F (\u0432 alex-gpt apps/e2e/README.md \u0437\u0430\u0448\u0438\u0442\u044B alexgpt-postgres-1 \u0438 alexgpt-redis-1). Compose \u043F\u043E\u0434\u043D\u0438\u043C\u0430\u0439 \u0442\u043E\u043B\u044C\u043A\u043E \u0438\u0437 \u0441\u0432\u043E\u0435\u0433\u043E worktree, \u043D\u0435 \u0438\u0437 /tmp. \u0414\u043B\u044F \`docker run\` \u2014 \`--name ${prefix}-pg --label taskless.swarm.home=${homeDir}\`. \u041F\u043E\u0440\u0442\u044B \u043F\u0443\u0431\u043B\u0438\u043A\u0443\u0439 \u0442\u043E\u043B\u044C\u043A\u043E \u043D\u0430 \`127.0.0.1\` (\`-p 127.0.0.1:<\u043F\u043E\u0440\u0442>:5432\`): Docker \u0438\u0434\u0451\u0442 \u043C\u0438\u043C\u043E \u0444\u0430\u0439\u0440\u0432\u043E\u043B\u0430, \u043E\u0442\u043A\u0440\u044B\u0442\u0443\u044E \u0431\u0430\u0437\u0443 \u0432\u0437\u043B\u0430\u043C\u044B\u0432\u0430\u044E\u0442 \u0437\u0430 \u0434\u043D\u0438.`;
22250
22372
  }
22251
22373
  function promptStandRule(worktree, slug) {
22252
22374
  const raw = worktree && worktree.length > 0 ? worktree : slug;
22253
22375
  const prefix = composeProjectPrefix(basename7(raw));
22254
- return prefix ? dockerStandRules(prefix, homedir9()) : "";
22376
+ return prefix ? dockerStandRules(prefix, homedir10()) : "";
22377
+ }
22378
+ 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.";
22379
+ 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.";
22380
+ 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.";
22381
+ 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).";
22382
+ function fixShaLine(sha) {
22383
+ return sha && /^[0-9a-f]{7,40}$/i.test(sha) ? `SHA: ${sha}` : "SHA: \u043D\u0435 \u0437\u0430\u043F\u0438\u0441\u0430\u043D";
22384
+ }
22385
+ function renderFixVerdicts(verdict, review, verify) {
22386
+ const reviewBody = review?.body?.trim() || null;
22387
+ const verifyBody = verify?.body?.trim() || null;
22388
+ if (review && verify && (reviewBody || verifyBody)) {
22389
+ return [
22390
+ "### \u041F\u0443\u043D\u043A\u0442\u044B \u0440\u0435\u0432\u044C\u044E\u0435\u0440\u0430",
22391
+ fixShaLine(review.sha),
22392
+ reviewBody ?? (review.recorded ? FIX_VERDICT_MISSING : FIX_NO_VERDICT_YET),
22393
+ "",
22394
+ "### \u041D\u0430\u0445\u043E\u0434\u043A\u0438 \u0432\u0435\u0440\u0438\u0444\u0438\u043A\u0430\u0442\u043E\u0440\u0430",
22395
+ fixShaLine(verify.sha),
22396
+ verifyBody ?? (verify.recorded ? FIX_VERDICT_MISSING : FIX_NO_VERDICT_YET)
22397
+ ].join("\n");
22398
+ }
22399
+ return verdict ?? FIX_VERDICT_MISSING;
22255
22400
  }
22256
22401
  function buildChangesFixPrompt(args) {
22257
- const { prUrl, slug, branch, base: base3, worktree, verdict } = args;
22402
+ const { prUrl, slug, branch, base: base3, worktree } = args;
22403
+ const verdictBlock = renderFixVerdicts(args.verdict, args.reviewSection, args.verifySection);
22258
22404
  const baseRef = base3 ? `origin/${base3}` : "origin/HEAD";
22259
22405
  const standRule = promptStandRule(worktree, slug);
22260
22406
  return [
@@ -22280,7 +22426,7 @@ function buildChangesFixPrompt(args) {
22280
22426
  "\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.",
22281
22427
  "\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.",
22282
22428
  "",
22283
- 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).",
22429
+ verdictBlock,
22284
22430
  "",
22285
22431
  "## \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",
22286
22432
  "```",
@@ -22443,10 +22589,10 @@ ${task.description}` : `\u0417\u0430\u0434\u0430\u0447\u0430 ${run2.task_slug} (
22443
22589
  }
22444
22590
  return parts.join("\n");
22445
22591
  }
22446
- var HERO_CHARTER_PATH = join40(dirname6(THIS_FILE), "..", "docs", "HERO.md");
22592
+ var HERO_CHARTER_PATH = join41(dirname6(THIS_FILE), "..", "docs", "HERO.md");
22447
22593
  function buildHeroPrompt(task, run2, taskContext, attachmentsBlock) {
22448
22594
  const name = run2.name || `#${run2.id}`;
22449
- const charter = readFileSync28(HERO_CHARTER_PATH, "utf8");
22595
+ const charter = readFileSync29(HERO_CHARTER_PATH, "utf8");
22450
22596
  const head = task ? `\u042D\u041F\u0418\u041A ${run2.task_slug}: ${task.title}
22451
22597
 
22452
22598
  ${task.description}` : `\u042D\u041F\u0418\u041A ${run2.task_slug} (\u0442\u0435\u043B\u043E \u043D\u0435\u0434\u043E\u0441\u0442\u0443\u043F\u043D\u043E \u2014 \u0440\u0430\u0431\u043E\u0442\u0430\u0439 \u043F\u043E slug \u0438 \u0437\u0434\u0440\u0430\u0432\u043E\u043C\u0443 \u0441\u043C\u044B\u0441\u043B\u0443).`;
@@ -22506,9 +22652,9 @@ function ciTrustLine(prUrl, verifyMode, ciClosed = null) {
22506
22652
  }
22507
22653
  return `\u041D\u0435 \u043F\u0435\u0440\u0435\u0433\u043E\u043D\u044F\u0439 \u0442\u0435\u0441\u0442-\u0441\u044C\u044E\u0442/typecheck \u0437\u0430\u043D\u043E\u0432\u043E \u2014 \u044D\u0442\u043E \u0443\u0436\u0435 \u0441\u0434\u0435\u043B\u0430\u043B CI \u043D\u0430 \u044D\u0442\u043E\u043C \u0436\u0435 \u043A\u043E\u043C\u043C\u0438\u0442\u0435 (\u0434\u0432\u043E\u0439\u043D\u043E\u0439 \u043F\u0440\u043E\u0433\u043E\u043D \u043D\u0430 \u043C\u0430\u0448\u0438\u043D\u0435 \u0432\u043B\u0430\u0434\u0435\u043B\u044C\u0446\u0430 \u043E\u0442\u043C\u0435\u043D\u0451\u043D, TASWM-249). \u041F\u0440\u043E\u0447\u0438\u0442\u0430\u0439 \u0435\u0433\u043E \u0440\u0435\u0437\u0443\u043B\u044C\u0442\u0430\u0442 \u0441\u0430\u043C: ${readChecks}. \u0414\u0430\u043B\u044C\u0448\u0435 \u0442\u0440\u0438 \u0440\u0430\u0437\u043D\u044B\u0445 \u0441\u043B\u0443\u0447\u0430\u044F: \u2460 \u0445\u043E\u0442\u044C \u043E\u0434\u0438\u043D \u0447\u0435\u043A \u0435\u0449\u0451 PENDING \u2014 \u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u0432\u043E\u043E\u0431\u0449\u0435 \u043D\u0435 \u0432\u044B\u043D\u043E\u0441\u0438: \u043D\u0435 \u043F\u043E\u0441\u0442\u0438 REQUEST CHANGES, \u043D\u0435 \u0437\u043E\u0432\u0438 done(), \u043F\u0440\u043E\u0441\u0442\u043E \u0437\u0430\u0432\u0435\u0440\u0448\u0438 \u0441\u0435\u0441\u0441\u0438\u044E \u043A\u0430\u043A \u0435\u0441\u0442\u044C \u2014 \u0440\u043E\u0439 \u0441\u0430\u043C \u0437\u0430\u043C\u0435\u0442\u0438\u0442, \u0447\u0442\u043E \u0442\u044B \u0436\u0434\u0451\u0448\u044C CI, \u0438 \u0440\u0430\u0437\u0431\u0443\u0434\u0438\u0442 \u0434\u043E\u0434\u0435\u043B\u0430\u0442\u044C \u0440\u0435\u0432\u044C\u044E, \u043A\u043E\u0433\u0434\u0430 \u0432\u0441\u0435 \u0447\u0435\u043A\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0442\u0441\u044F (\u044D\u0442\u043E \u0448\u0442\u0430\u0442\u043D\u044B\u0439 \u043F\u0443\u0442\u044C, \u043E\u043F\u0435\u0440\u0430\u0442\u043E\u0440\u0430 \u0437\u0432\u0430\u0442\u044C \u043D\u0435 \u043D\u0443\u0436\u043D\u043E). \u2461 \u0432\u0441\u0435 \u0447\u0435\u043A\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043B\u0438\u0441\u044C \u0438 \u0435\u0441\u0442\u044C FAIL \u2014 REQUEST CHANGES, \u043D\u0430\u0437\u043E\u0432\u0438 \u043F\u043E\u0438\u043C\u0451\u043D\u043D\u043E, \u0447\u0442\u043E \u0443\u043F\u0430\u043B\u043E. \u2462 \u043D\u0430 \u044D\u0442\u043E\u043C \u043A\u043E\u043C\u043C\u0438\u0442\u0435 \u0447\u0435\u043A\u043E\u0432 \u043D\u0435\u0442 \u0432\u043E\u0432\u0441\u0435 \u2014 \u0442\u043E \u0436\u0435, \u0447\u0442\u043E \u2460: \u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u043D\u0435 \u0432\u044B\u043D\u043E\u0441\u0438, \u043D\u0435 \u043F\u0438\u0448\u0438 REQUEST CHANGES, \u043D\u0435 \u0437\u043E\u0432\u0438 done(), \u043F\u0440\u043E\u0441\u0442\u043E \u0437\u0430\u0432\u0435\u0440\u0448\u0438 \u0441\u0435\u0441\u0441\u0438\u044E. \u0427\u0435\u043A\u043E\u0432 \u043C\u043E\u0436\u0435\u0442 \u043D\u0435 \u0431\u044B\u0442\u044C, \u043F\u043E\u0442\u043E\u043C\u0443 \u0447\u0442\u043E \u0441\u0442\u0430\u0440\u044B\u0439 \u043F\u0440\u043E\u0433\u043E\u043D \u0442\u043E\u043B\u044C\u043A\u043E \u0447\u0442\u043E \u043E\u0442\u043C\u0435\u043D\u0451\u043D \u043D\u043E\u0432\u044B\u043C \u043F\u0443\u0448\u0435\u043C \u0438\u043B\u0438 \u0440\u0430\u043D\u043D\u0435\u0440\u044B \u0437\u0430\u043D\u044F\u0442\u044B. \u0420\u043E\u0439 \u0441\u0430\u043C \u0440\u0430\u0437\u0431\u0443\u0434\u0438\u0442, \u043A\u043E\u0433\u0434\u0430 \u0447\u0435\u043A\u0438 \u043F\u043E\u044F\u0432\u044F\u0442\u0441\u044F \u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0442\u0441\u044F, \u0438\u043B\u0438 \u0441\u043A\u0430\u0436\u0435\u0442, \u0447\u0442\u043E \u0438\u0445 \u043D\u0435 \u0431\u0443\u0434\u0435\u0442. ${dontTrustAuthor}`;
22508
22654
  }
22509
- var REVIEW_SKILL_PATH = join40(bundledRoleDir("drone"), "skills", "taskless-review", "SKILL.md");
22655
+ var REVIEW_SKILL_PATH = join41(bundledRoleDir("drone"), "skills", "taskless-review", "SKILL.md");
22510
22656
  function reviewDefectClasses(skillPath = REVIEW_SKILL_PATH) {
22511
- const text = readFileSync28(skillPath, "utf8");
22657
+ const text = readFileSync29(skillPath, "utf8");
22512
22658
  const m = /^## Классы дефектов\n([\s\S]*?)(?=^## |(?![\s\S]))/m.exec(text);
22513
22659
  if (!m) throw new Error(`${skillPath}: \u043D\u0435\u0442 \u0440\u0430\u0437\u0434\u0435\u043B\u0430 \xAB## \u041A\u043B\u0430\u0441\u0441\u044B \u0434\u0435\u0444\u0435\u043A\u0442\u043E\u0432\xBB \u2014 \u0444\u043E\u0440\u043C\u0430\u0442 skill taskless-review \u043F\u043E\u043C\u0435\u043D\u044F\u043B\u0441\u044F?`);
22514
22660
  return `\u041A\u043B\u0430\u0441\u0441\u044B \u0434\u0435\u0444\u0435\u043A\u0442\u043E\u0432 (skill taskless-review):
@@ -23274,7 +23420,7 @@ function repoHasCi(deps, run2) {
23274
23420
  function repoHasCiWorkflows(worktreePath, repo) {
23275
23421
  for (const base3 of [worktreePath, repo]) {
23276
23422
  if (!base3) continue;
23277
- const dir = join40(base3, ".github", "workflows");
23423
+ const dir = join41(base3, ".github", "workflows");
23278
23424
  try {
23279
23425
  if (readdirSync18(dir).some((f) => f.endsWith(".yml") || f.endsWith(".yaml"))) return true;
23280
23426
  } catch {
@@ -23506,6 +23652,183 @@ function worktreeAndTranscriptAlive(deps, run2) {
23506
23652
  function limitWaitCandidate(deps, run2) {
23507
23653
  return deps.exitLimit?.(run2) ?? null;
23508
23654
  }
23655
+ var grokBalanceResumedThisTick = /* @__PURE__ */ new Set();
23656
+ var grokBalanceProbes = /* @__PURE__ */ new WeakMap();
23657
+ var grokBalanceFixHeldThisTick = /* @__PURE__ */ new Set();
23658
+ var grokBalanceDeadMemo = null;
23659
+ function resetGrokBalanceTick() {
23660
+ grokBalanceResumedThisTick.clear();
23661
+ grokBalanceDeadMemo = null;
23662
+ grokBalanceFixHeldThisTick.clear();
23663
+ }
23664
+ function grokBalanceProbeMap(db) {
23665
+ let map = grokBalanceProbes.get(db);
23666
+ if (!map) {
23667
+ map = /* @__PURE__ */ new Map();
23668
+ grokBalanceProbes.set(db, map);
23669
+ }
23670
+ return map;
23671
+ }
23672
+ function grokLogShowsBalance(deps, run2) {
23673
+ const hit = limitWaitCandidate(deps, run2);
23674
+ return hit?.executor === "grok" && hit.balance === true;
23675
+ }
23676
+ function grokBalanceProbeOpen(deps, runId) {
23677
+ return grokBalanceProbes.get(deps.db)?.has(runId) === true;
23678
+ }
23679
+ function releaseGrokBalanceAfterProbeSuccess(deps, now = deps.now ? deps.now() : Date.now()) {
23680
+ const probes = grokBalanceProbes.get(deps.db);
23681
+ if (!probes || probes.size === 0) return;
23682
+ let succeeded = false;
23683
+ for (const [id, probe] of [...probes]) {
23684
+ const run2 = deps.db.getRun(id);
23685
+ if (!run2) {
23686
+ probes.delete(id);
23687
+ continue;
23688
+ }
23689
+ const live2 = run2.status === "running" && run2.pid != null && deps.isAlive(run2.pid);
23690
+ if (!live2 || now - probe.startedAt < GROK_BALANCE_SUCCESS_MS || grokLogShowsBalance(deps, run2)) continue;
23691
+ probes.delete(id);
23692
+ succeeded = true;
23693
+ }
23694
+ if (!succeeded) return;
23695
+ const waiting = deps.db.listRuns("paused").filter((run2) => isGrokBalanceWait(run2.stop_reason));
23696
+ const stopReason = limitWaitReason({
23697
+ executor: "grok",
23698
+ resetsAt: new Date(now).toISOString(),
23699
+ text: "\u0431\u0430\u043B\u0430\u043D\u0441 Grok \u0432\u0435\u0440\u043D\u0443\u043B\u0441\u044F, \u043F\u0440\u043E\u0434\u043E\u043B\u0436\u0438\u0442 \u043F\u043E\u0441\u043B\u0435 \u0441\u0431\u0440\u043E\u0441\u0430"
23700
+ });
23701
+ for (const run2 of waiting) {
23702
+ deps.db.updateRun(run2.id, { stop_reason: stopReason });
23703
+ deps.db.addEvent(run2.id, "step", "\u0431\u0430\u043B\u0430\u043D\u0441 Grok \u043D\u0430 \u044D\u0442\u043E\u0439 \u043C\u0430\u0448\u0438\u043D\u0435 \u0432\u0435\u0440\u043D\u0443\u043B\u0441\u044F \u2014 \u0441\u0432\u043E\u0435\u0433\u043E \u0441\u0431\u0440\u043E\u0441\u0430 \u043D\u0435 \u0436\u0434\u0443, \u043F\u0440\u043E\u0434\u043E\u043B\u0436\u0443 \u043E\u0431\u044B\u0447\u043D\u044B\u043C \u0432\u043E\u0437\u0432\u0440\u0430\u0442\u043E\u043C \u043F\u043E\u0441\u043B\u0435 \u043B\u0438\u043C\u0438\u0442\u0430");
23704
+ }
23705
+ if (waiting.length > 0) {
23706
+ narrate(deps, "\u0411\u0430\u043B\u0430\u043D\u0441 Grok \u0432\u0435\u0440\u043D\u0443\u043B\u0441\u044F \u2014 \u043E\u0441\u0442\u0430\u043B\u044C\u043D\u044B\u0435 \u043F\u0430\u0443\u0437\u044B \u0431\u0430\u043B\u0430\u043D\u0441\u0430 \u044D\u0442\u043E\u0439 \u043C\u0430\u0448\u0438\u043D\u044B \u043F\u0440\u043E\u0434\u043E\u043B\u0436\u0430\u0442 \u043E\u0431\u044B\u0447\u043D\u044B\u043C \u0432\u043E\u0437\u0432\u0440\u0430\u0442\u043E\u043C \u043F\u043E\u0441\u043B\u0435 \u043B\u0438\u043C\u0438\u0442\u0430.");
23707
+ }
23708
+ }
23709
+ function grokBalanceProbeHolds(deps) {
23710
+ releaseGrokBalanceAfterProbeSuccess(deps);
23711
+ const probes = grokBalanceProbes.get(deps.db);
23712
+ if (!probes || probes.size === 0) return false;
23713
+ let holds = false;
23714
+ for (const id of [...probes.keys()]) {
23715
+ const run2 = deps.db.getRun(id);
23716
+ if (!run2) {
23717
+ probes.delete(id);
23718
+ continue;
23719
+ }
23720
+ const live2 = run2.status === "running" && run2.pid != null && deps.isAlive(run2.pid);
23721
+ if (!live2) {
23722
+ if (run2.status === "running" || run2.status === "blocked") {
23723
+ holds = true;
23724
+ continue;
23725
+ }
23726
+ probes.delete(id);
23727
+ continue;
23728
+ }
23729
+ holds = true;
23730
+ }
23731
+ return holds;
23732
+ }
23733
+ function grokBalanceSkipReason() {
23734
+ return `\u043A\u043E\u043D\u0447\u0438\u043B\u0441\u044F \u0431\u0430\u043B\u0430\u043D\u0441 Grok \u2014 \u043D\u043E\u0432\u044B\u0439 \u043F\u0440\u043E\u0433\u043E\u043D \u043D\u0430 Grok \u043D\u0435 \u043F\u043E\u0434\u043D\u0438\u043C\u0430\u044E, \u043E\u0447\u0435\u0440\u0435\u0434\u044C \u0436\u0434\u0451\u0442. ${GROK_BALANCE_ACTION}`;
23735
+ }
23736
+ function runUsesGrok(deps, run2) {
23737
+ const pinned = parseModelRef(run2.model ?? null);
23738
+ if (pinned) return findProvider(pinned.providerId)?.executorId === "grok";
23739
+ try {
23740
+ const id = deps.storm?.providerFor?.(run2);
23741
+ if (!id) return false;
23742
+ return findProvider(id)?.executorId === "grok";
23743
+ } catch {
23744
+ return false;
23745
+ }
23746
+ }
23747
+ function deadRunningGrokBalance(deps) {
23748
+ if (grokBalanceDeadMemo != null) return grokBalanceDeadMemo;
23749
+ let found = false;
23750
+ if (deps.exitLimit) {
23751
+ for (const status of ["running", "blocked"]) {
23752
+ for (const run2 of deps.db.listRuns(status)) {
23753
+ if (run2.pid != null && deps.isAlive(run2.pid)) continue;
23754
+ const hit = limitWaitCandidate(deps, run2);
23755
+ if (hit?.executor === "grok" && hit.balance === true) {
23756
+ found = true;
23757
+ break;
23758
+ }
23759
+ }
23760
+ if (found) break;
23761
+ }
23762
+ }
23763
+ grokBalanceDeadMemo = found;
23764
+ return found;
23765
+ }
23766
+ function grokBalanceHolds(deps) {
23767
+ if (grokBalanceProbeHolds(deps)) return true;
23768
+ if (grokBalanceResumedThisTick.size > 0) return true;
23769
+ for (const run2 of deps.db.listRuns("paused")) {
23770
+ if (isGrokBalanceWait(run2.stop_reason)) return true;
23771
+ }
23772
+ return deadRunningGrokBalance(deps);
23773
+ }
23774
+ function grokBalanceBlocksRun(deps, run2) {
23775
+ return grokBalanceHolds(deps) && runUsesGrok(deps, run2);
23776
+ }
23777
+ function grokBalanceBlocksChecker(deps, author) {
23778
+ return grokBalanceBlocksRun(deps, { kind: "reviewer", model: author.review_model ?? null });
23779
+ }
23780
+ function grokBalanceBlocksIntake(deps) {
23781
+ if (!grokBalanceHolds(deps)) return false;
23782
+ return runUsesGrok(deps, { kind: "drone", model: null });
23783
+ }
23784
+ function noteGrokBalanceSkip(deps, run2, who) {
23785
+ const reason = grokBalanceSkipReason();
23786
+ const d = noteDefer(deps.spawnDefer ??= /* @__PURE__ */ new Map(), `grok-balance:${run2.id}`, reason, GATE_LOG_HEARTBEAT_TICKS);
23787
+ if (d.changed) deps.db.addEvent(run2.id, "step", `\u0441\u043F\u0430\u0432\u043D \u043E\u0442\u043B\u043E\u0436\u0435\u043D: ${reason}`);
23788
+ if (d.log) {
23789
+ console.error(
23790
+ `[overmind] ${who} ${droneLabel(run2)} (${run2.task_slug}) \u043D\u0435 \u043F\u043E\u0434\u043D\u0438\u043C\u0430\u044E: ${reason}${d.changed ? "" : ` \u2014 \u0435\u0449\u0451 \u0432\u0438\u0441\u0438\u0442, \u0442\u0438\u043A ${d.ticks}`}`
23791
+ );
23792
+ }
23793
+ }
23794
+ function safeGrokEmail(deps) {
23795
+ try {
23796
+ const value = deps.grokAccountEmail?.() ?? null;
23797
+ return typeof value === "string" && value.includes("@") ? value : null;
23798
+ } catch {
23799
+ return null;
23800
+ }
23801
+ }
23802
+ function grokBalanceWaitingCount(deps) {
23803
+ const ids = new Set(grokBalanceResumedThisTick);
23804
+ for (const run2 of deps.db.listRuns("paused")) {
23805
+ if (isGrokBalanceWait(run2.stop_reason)) ids.add(run2.id);
23806
+ }
23807
+ return ids.size;
23808
+ }
23809
+ function grokBalanceHostName(deps) {
23810
+ const name = (deps.selfHostName || deps.storm?.hostName || "").trim();
23811
+ return name || "\u043C\u0430\u0448\u0438\u043D\u0430";
23812
+ }
23813
+ function grokBalanceKey(deps) {
23814
+ return grokBalanceSignalKey(deps.selfHostId);
23815
+ }
23816
+ function grokBalanceAnomalyCandidate(deps) {
23817
+ if (!grokBalanceHolds(deps)) return null;
23818
+ return {
23819
+ key: grokBalanceKey(deps),
23820
+ once: true,
23821
+ minDurationMs: 0,
23822
+ build: () => {
23823
+ const signal = grokBalanceSignal({
23824
+ hostName: grokBalanceHostName(deps),
23825
+ email: safeGrokEmail(deps),
23826
+ waiting: grokBalanceWaitingCount(deps)
23827
+ });
23828
+ return { level: "decision", title: signal.title, body: clipChars(signal.body, ANOMALY_BODY_MAX) };
23829
+ }
23830
+ };
23831
+ }
23509
23832
  async function projectWantsChecks(deps, run2) {
23510
23833
  if (!deps.autoReviewForRepo) return true;
23511
23834
  return await deps.autoReviewForRepo(effectiveRepo(deps, run2), run2.task_slug).catch((e) => {
@@ -23526,6 +23849,10 @@ async function spawnFreshReviewerAfterStall(deps, run2, why) {
23526
23849
  }
23527
23850
  const gate = await prGateForReviewer(deps, run2, run2.pr_url, "\u043F\u043E\u043A\u0430 \u0436\u0434\u0430\u043B CI");
23528
23851
  if (gate.kind !== "spawn") return;
23852
+ if (grokBalanceBlocksChecker(deps, run2)) {
23853
+ noteGrokBalanceSkip(deps, run2, "\u0440\u0435\u0432\u044C\u044E\u0435\u0440\u0430");
23854
+ return;
23855
+ }
23529
23856
  const st = gate.st;
23530
23857
  try {
23531
23858
  await deps.spawnReviewer(run2, st.files ?? []);
@@ -23561,6 +23888,9 @@ function draftHoldBody(prUrl) {
23561
23888
  function tickSuppressesAnomaly(key) {
23562
23889
  for (const id of draftHeldThisTick.keys()) if (key === `pr_no_reviewer:${id}`) return true;
23563
23890
  for (const id of fixBlockedThisTick.keys()) if (key === `pr_stuck_changes:${id}`) return true;
23891
+ for (const id of grokBalanceFixHeldThisTick) {
23892
+ if (key === `pr_stuck_changes:${id}` || key === `pr_no_reviewer:${id}`) return true;
23893
+ }
23564
23894
  return false;
23565
23895
  }
23566
23896
  function tickAnomalyCandidates(autoReviewSnapshot) {
@@ -23618,12 +23948,57 @@ async function liftFixIterationStep(deps, snapshot, st, _stormActive, now, drone
23618
23948
  }
23619
23949
  return run2;
23620
23950
  }
23951
+ function sameCycleCheckerWorking(runs, cycle, respectAwaitingCi) {
23952
+ return runs.some((r) => {
23953
+ if ((r.review_cycle ?? 0) !== cycle) return false;
23954
+ if (r.status === "stalled") return false;
23955
+ if (r.status === "paused" && isLimitWait(r.stop_reason)) return false;
23956
+ if (respectAwaitingCi && isAwaitingCi(r.status, r.stop_reason)) return false;
23957
+ return true;
23958
+ });
23959
+ }
23960
+ function noteFixPartnerTimeout(deps, run2, waitingOn) {
23961
+ const cycle = run2.review_cycle ?? 0;
23962
+ 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})`;
23963
+ if (deps.db.events(run2.id).some((e) => (e.text ?? "").includes(mark))) return;
23964
+ const who = waitingOn === "verifier" ? "\u0432\u0435\u0440\u0438\u0444\u0438\u043A\u0430\u0442\u043E\u0440" : "\u0440\u0435\u0432\u044C\u044E\u0435\u0440";
23965
+ const mins = Math.max(1, Math.round(CHANGES_FRESH_WAKE_AFTER_MS / 6e4));
23966
+ deps.db.addEvent(
23967
+ run2.id,
23968
+ "step",
23969
+ `${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)`
23970
+ );
23971
+ }
23621
23972
  async function wakeAuthorOnChanges(deps, snapshot, now, droneCap) {
23622
23973
  if (!deps.respawn) return false;
23623
23974
  const run2 = deps.db.getRun(snapshot.id);
23624
23975
  if (!run2 || isAwaitingBudget(run2.status, run2.stop_reason)) return false;
23625
23976
  if (run2.pid != null && deps.isAlive(run2.pid)) return false;
23626
- if (deps.db.activeReviewersFor(run2.id).some((r) => r.status !== "stalled" && !isAwaitingCi(r.status, r.stop_reason))) {
23977
+ if (grokBalanceBlocksRun(deps, run2)) {
23978
+ grokBalanceFixHeldThisTick.add(run2.id);
23979
+ noteGrokBalanceSkip(deps, run2, "\u0444\u0438\u043A\u0441-\u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044E");
23980
+ return false;
23981
+ }
23982
+ const cycle = run2.review_cycle ?? 0;
23983
+ const reviewerWorking = run2.review_verdict == null && sameCycleCheckerWorking(deps.db.activeReviewersFor(run2.id), cycle, true);
23984
+ const verifierWorking = run2.verify_verdict == null && sameCycleCheckerWorking(deps.db.activeVerifiersFor(run2.id), cycle, false);
23985
+ const verdictAt = changesVerdictAt(deps.db, run2, now);
23986
+ const partner = fixPartnerHold({
23987
+ nowMs: now,
23988
+ // stampMs, не sqliteMs: у гидрированного прогона `at` бывает ISO, и sqliteMs даёт NaN.
23989
+ // NaN в fixPartnerHold — partial, а не вечное ожидание (метка гейт не держит).
23990
+ verdictAtMs: verdictAt ? stampMs(verdictAt) : null,
23991
+ waitMs: CHANGES_FRESH_WAKE_AFTER_MS,
23992
+ reviewVerdict: run2.review_verdict,
23993
+ verifyVerdict: run2.verify_verdict,
23994
+ reviewerWorking,
23995
+ verifierWorking
23996
+ });
23997
+ if (partner.action === "wait") return false;
23998
+ const gaveUpOnReviewer = partner.action === "partial" && partner.waitingOn === "reviewer";
23999
+ if (!gaveUpOnReviewer && deps.db.activeReviewersFor(run2.id).some(
24000
+ (r) => r.status !== "stalled" && !isAwaitingCi(r.status, r.stop_reason) && !(r.status === "paused" && isLimitWait(r.stop_reason))
24001
+ )) {
23627
24002
  return blockFix(run2, "\u0440\u0435\u0432\u044C\u044E\u0435\u0440 \u0435\u0449\u0451 \u0432 \u0440\u0430\u0431\u043E\u0442\u0435");
23628
24003
  }
23629
24004
  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");
@@ -23703,6 +24078,7 @@ async function wakeAuthorOnChanges(deps, snapshot, now, droneCap) {
23703
24078
  if (run2.stop_reason != null) deps.db.updateRun(run2.id, { stop_reason: null });
23704
24079
  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";
23705
24080
  deps.db.addEvent(run2.id, "resumed", `${CHANGES_WAKE_MARK} \u2014 ${how}`);
24081
+ if (partner.action === "partial") noteFixPartnerTimeout(deps, run2, partner.waitingOn);
23706
24082
  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.`);
23707
24083
  return true;
23708
24084
  } catch (e) {
@@ -23782,7 +24158,7 @@ async function zoneConflictFor(db, models, activeFiles, run2, repo, repoFallback
23782
24158
  activeFiles.prune(holders.map((r) => r.id));
23783
24159
  const fileExists = (p) => {
23784
24160
  try {
23785
- return statSync16(join40(repo, p), { throwIfNoEntry: false })?.isFile() ?? false;
24161
+ return statSync16(join41(repo, p), { throwIfNoEntry: false })?.isFile() ?? false;
23786
24162
  } catch {
23787
24163
  return false;
23788
24164
  }
@@ -23946,6 +24322,9 @@ async function trySpawnQueuedRun(deps, run2) {
23946
24322
  // причина одна на машину — в лог уходит одной строкой, а не по строке на прогон
23947
24323
  });
23948
24324
  }
24325
+ if (grokBalanceBlocksRun(deps, run2)) {
24326
+ return deferSpawn(deps, run2, `${grokBalanceSkipReason()} (TASWM-660)`, { logKey: "grok-balance" });
24327
+ }
23949
24328
  const heavy = heavyRunsInFlight(deps);
23950
24329
  if (heavy.length && heavy.every((h) => h.id !== run2.id)) {
23951
24330
  return deferSpawn(deps, run2, intakeHoldReason(heavy.map(droneLabel).join(", ")), {
@@ -24440,6 +24819,16 @@ function lastLimitResumeMs(deps, runId) {
24440
24819
  const event = deps.db.events(runId).filter((item) => item.kind === "resumed" && item.text === LIMIT_RESUMED_TEXT).at(-1);
24441
24820
  return event ? stampMs(event.at) : null;
24442
24821
  }
24822
+ function returnGrokBalanceProbeToPause(deps, run2, now) {
24823
+ const resetsAt = new Date(now + LIMIT_RESUME_RETRY_MS).toISOString();
24824
+ const text = grokBalanceWaitText();
24825
+ const stopReason = limitWaitReason({ executor: "grok", resetsAt, text });
24826
+ deps.db.updateRun(run2.id, { status: "paused", stop_reason: stopReason });
24827
+ const resetClock = new Date(resetsAt).toLocaleTimeString("ru-RU", { hour: "2-digit", minute: "2-digit" });
24828
+ deps.db.addEvent(run2.id, "paused", `${text}, \u043F\u0440\u043E\u0431\u0430 \u0443\u043C\u0435\u0440\u043B\u0430 \u0440\u0430\u043D\u044C\u0448\u0435 5 \u043C\u0438\u043D\u0443\u0442, \u043F\u043E\u0432\u0442\u043E\u0440 \u043D\u0435 \u0440\u0430\u043D\u044C\u0448\u0435 ${resetClock}`);
24829
+ narrate(deps, `${droneLabel(run2)} \u043F\u0440\u043E\u0431\u0430 \u0431\u0430\u043B\u0430\u043D\u0441\u0430 \u0443\u043C\u0435\u0440\u043B\u0430 \u0440\u0430\u043D\u044C\u0448\u0435 5 \u043C\u0438\u043D\u0443\u0442 \u2014 \u0441\u043D\u043E\u0432\u0430 \u0436\u0434\u0443. ${GROK_BALANCE_ACTION}`);
24830
+ grokBalanceProbeMap(deps.db).delete(run2.id);
24831
+ }
24443
24832
  async function resumeLimitWaits(deps, now, droneCap, _stormActive) {
24444
24833
  if (!deps.respawn || countActiveDrones(deps.db) >= droneCap) return;
24445
24834
  const candidates = deps.db.listRuns("paused").filter((run2) => isLimitWaitDue(run2.stop_reason, now)).filter((run2) => run2.pid == null || !deps.isAlive(run2.pid)).sort((a, b) => a.updated_at.localeCompare(b.updated_at));
@@ -24461,11 +24850,16 @@ async function resumeLimitWaits(deps, now, droneCap, _stormActive) {
24461
24850
  console.error(`[overmind] \u0440\u0435\u043A\u043B\u0435\u0439\u043C worktree \u043F\u0435\u0440\u0435\u0434 \u0432\u043E\u0437\u0432\u0440\u0430\u0442\u043E\u043C \u043F\u043E\u0441\u043B\u0435 \u043B\u0438\u043C\u0438\u0442\u0430 ${droneLabel(candidate)} \u0441\u043E\u0440\u0432\u0430\u043B\u0441\u044F:`, e);
24462
24851
  }
24463
24852
  }
24853
+ const balanceWait = isGrokBalanceWait(candidate.stop_reason);
24464
24854
  try {
24465
24855
  await deps.respawn(candidate, mode);
24466
24856
  deps.db.updateRun(candidate.id, { stop_reason: null });
24467
24857
  if (mode === "fresh") deps.db.addEvent(candidate.id, "step", "\u0441\u0435\u0441\u0441\u0438\u044F \u043F\u043E\u0442\u0435\u0440\u044F\u043D\u0430, \u043D\u0430\u0447\u0430\u043B \u0437\u0430\u043D\u043E\u0432\u043E");
24468
24858
  deps.db.addEvent(candidate.id, "resumed", LIMIT_RESUMED_TEXT);
24859
+ if (balanceWait) {
24860
+ grokBalanceProbeMap(deps.db).set(candidate.id, { startedAt: now });
24861
+ grokBalanceResumedThisTick.add(candidate.id);
24862
+ }
24469
24863
  narrate(deps, `\u041B\u0438\u043C\u0438\u0442 \u0441\u0431\u0440\u043E\u0448\u0435\u043D \u2014 \u0432\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u044E ${droneLabel(candidate)} \u0432 \u0440\u0430\u0431\u043E\u0442\u0443.`);
24470
24864
  } catch (e) {
24471
24865
  const reason = `\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u043F\u0440\u043E\u0434\u043E\u043B\u0436\u0438\u0442\u044C \u043F\u043E\u0441\u043B\u0435 \u043B\u0438\u043C\u0438\u0442\u0430: ${String(e)}`;
@@ -24851,20 +25245,24 @@ function clipPickupBody(body) {
24851
25245
  const headLen = Math.max(0, PICKUP_BODY_MAX - note.length - tail2.length);
24852
25246
  return body.slice(0, headLen) + note + tail2;
24853
25247
  }
24854
- function pickedVerdictEventText(how, verdict, body, mark) {
25248
+ function pickedVerdictEventText(how, verdict, body, mark, sha) {
24855
25249
  const review = verdict === "approve" || verdict === "changes";
24856
25250
  const prefix = review ? PICKUP_EVENT_PREFIX : VERIFY_PICKUP_EVENT_PREFIX;
24857
25251
  const label2 = review ? verdictLabel(verdict) : verifyVerdictLabel(verdict);
24858
25252
  const trimmed = body?.trim() ?? "";
24859
25253
  const payload = trimmed ? clipPickupBody(trimmed) : label2;
24860
25254
  const tail2 = mark ? ` [${mark}]` : "";
24861
- return `${prefix} (${how}): ${payload}${tail2}`;
25255
+ return `${appendVerdictHead(`${prefix} (${how}): ${payload}`, sha)}${tail2}`;
25256
+ }
25257
+ async function checkerHeadSha(worktree) {
25258
+ if (!worktree) return null;
25259
+ return headSha(worktree);
24862
25260
  }
24863
25261
  function verdictEventPayload(text) {
24864
25262
  const sep4 = text.startsWith(PICKUP_EVENT_PREFIX) ? "): " : ": ";
24865
25263
  const at = text.indexOf(sep4);
24866
25264
  if (at < 0) return "";
24867
- return text.slice(at + sep4.length).trim().replace(/\s+\[[^\]]*\]\s*$/, "").trim();
25265
+ return stripVerdictHead(text.slice(at + sep4.length).replace(/\s+\[[^\]]*\]\s*$/, "")).trim();
24868
25266
  }
24869
25267
  function isHeaderOnlyVerdict(text) {
24870
25268
  if (!text.startsWith(PICKUP_EVENT_PREFIX) && !text.startsWith("\u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u0440\u0435\u0432\u044C\u044E \u043E\u0442")) return false;
@@ -24878,7 +25276,7 @@ function isVerifyHeaderOnly(text) {
24878
25276
  const sep4 = pickup ? "): " : ": ";
24879
25277
  const at = text.indexOf(sep4);
24880
25278
  if (at < 0) return true;
24881
- const rest = text.slice(at + sep4.length).trim().replace(/\s+\[[^\]]*\]\s*$/, "").trim();
25279
+ const rest = stripVerdictHead(text.slice(at + sep4.length).replace(/\s+\[[^\]]*\]\s*$/, "")).trim();
24882
25280
  return rest.length === 0 || VERIFY_HEADER_LABELS.has(rest);
24883
25281
  }
24884
25282
  function isClippedPickup(text) {
@@ -24896,7 +25294,11 @@ async function salvageVerdictFromPrComment(deps, rv, reviewsRunId, since, ctx) {
24896
25294
  const verdictText = verdictLabel(found.verdict);
24897
25295
  deps.db.updateRun(reviewsRunId, { review_verdict: found.verdict });
24898
25296
  recordReviewFindings(deps, rv, found);
24899
- deps.db.addEvent(reviewsRunId, "step", pickedVerdictEventText(ctx.how, found.verdict, found.body));
25297
+ deps.db.addEvent(
25298
+ reviewsRunId,
25299
+ "step",
25300
+ pickedVerdictEventText(ctx.how, found.verdict, found.body, void 0, await checkerHeadSha(rv.worktree_path))
25301
+ );
24900
25302
  await closeReviewerRun(
24901
25303
  deps,
24902
25304
  rv,
@@ -24918,7 +25320,11 @@ async function salvageVerifyVerdictFromPrComment(deps, vr, verifiesRunId, since,
24918
25320
  if (!found) return false;
24919
25321
  const verdictText = verifyVerdictLabel(found.verdict);
24920
25322
  deps.db.updateRun(verifiesRunId, { verify_verdict: found.verdict });
24921
- deps.db.addEvent(verifiesRunId, "step", pickedVerdictEventText(how, found.verdict, found.body));
25323
+ deps.db.addEvent(
25324
+ verifiesRunId,
25325
+ "step",
25326
+ pickedVerdictEventText(how, found.verdict, found.body, void 0, await checkerHeadSha(vr.worktree_path))
25327
+ );
24922
25328
  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`);
24923
25329
  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.`);
24924
25330
  return true;
@@ -25200,6 +25606,7 @@ async function tickOnce(deps) {
25200
25606
  beginGhMergePass(deps.ghMerges);
25201
25607
  draftHeldThisTick.clear();
25202
25608
  fixBlockedThisTick.clear();
25609
+ resetGrokBalanceTick();
25203
25610
  const worktreeExists = deps.worktreeExists ?? existsSync23;
25204
25611
  const hasTranscript = deps.hasTranscript ?? executorHasSession;
25205
25612
  deps.stepClock?.mark("0 \u0437\u0430\u043C\u0435\u0440 \u0445\u043E\u0441\u0442\u0430");
@@ -25333,12 +25740,14 @@ async function tickOnce(deps) {
25333
25740
  }
25334
25741
  if (deps.exitOutcome && endedItself(deps.exitOutcome(run2))) continue;
25335
25742
  if (limitWaitCandidate(deps, run2)) continue;
25743
+ if (grokBalanceProbeOpen(deps, run2.id)) continue;
25336
25744
  deps.db.recordDeath(run2.id, `\u0434\u0440\u043E\u043D \u0443\u043C\u0435\u0440 (pid ${run2.pid} \u043D\u0435 \u043E\u0442\u0432\u0435\u0447\u0430\u0435\u0442)`);
25337
25745
  }
25338
25746
  stormActive = await manageStorm(deps, now, worktreeExists, hasTranscript);
25339
25747
  }
25340
25748
  const droneCap = deps.maxDrones ? await deps.maxDrones() : Infinity;
25341
25749
  deps.stepClock?.mark("0e \u0432\u043E\u0437\u0432\u0440\u0430\u0442 \u043F\u043E\u0441\u043B\u0435 \u043B\u0438\u043C\u0438\u0442\u0430");
25750
+ releaseGrokBalanceAfterProbeSuccess(deps, now);
25342
25751
  await resumeLimitWaits(deps, now, droneCap, stormActive);
25343
25752
  deps.stepClock?.mark("1 \u043F\u043E\u0434\u043D\u044F\u0442\u044C \u043E\u0447\u0435\u0440\u0435\u0434\u044C");
25344
25753
  if (stormActive) noteStormStall(deps);
@@ -25576,7 +25985,13 @@ async function tickOnce(deps) {
25576
25985
  deps.db.addEvent(
25577
25986
  run2.id,
25578
25987
  "step",
25579
- 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)
25988
+ pickedVerdictEventText(
25989
+ "done() \u0431\u044B\u043B \u043D\u0435\u0434\u043E\u0441\u0442\u0443\u043F\u0435\u043D \u0440\u0435\u0432\u044C\u044E\u0435\u0440\u0443",
25990
+ verdictFromComment.verdict,
25991
+ verdictFromComment.body,
25992
+ mark,
25993
+ await checkerHeadSha(lastAttempt?.worktree_path)
25994
+ )
25580
25995
  );
25581
25996
  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.`);
25582
25997
  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);
@@ -25595,20 +26010,24 @@ async function tickOnce(deps) {
25595
26010
  if ((!deps.resourcesOk || deps.resourcesOk()) && reviewersCapOk) {
25596
26011
  const gate = await prGateForReviewer(deps, run2, prUrl, "\u043F\u043E\u043A\u0430 \u0436\u0434\u0430\u043B \u0440\u0435\u0432\u044C\u044E\u0435\u0440\u0430");
25597
26012
  if (gate.kind === "spawn") {
25598
- run2 = syncBranchFromPr(deps.db, run2, gate.st.headBranch);
25599
- try {
25600
- await deps.spawnReviewer(run2, st.files ?? []);
25601
- narrate(deps, `PR ${droneLabel(run2)} \u0433\u043E\u0442\u043E\u0432 \u2014 \u043F\u043E\u0434\u043D\u0438\u043C\u0430\u044E \u043D\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043C\u043E\u0433\u043E \u0440\u0435\u0432\u044C\u044E\u0435\u0440\u0430.`);
25602
- } catch (e) {
25603
- if (isUnrecoverableRefError(e)) {
25604
- deps.db.addEvent(
25605
- run2.id,
25606
- "step",
25607
- `${unrecoverableMark}: ${String(e)} \u2014 \u043F\u043E\u0432\u0442\u043E\u0440\u043E\u043C \u043D\u0435 \u043B\u0435\u0447\u0438\u0442\u0441\u044F, \u0430\u0432\u0442\u043E-\u0440\u0435\u0432\u044C\u044E \u0434\u043B\u044F \u044D\u0442\u043E\u0433\u043E \u043F\u0440\u043E\u0433\u043E\u043D\u0430 \u043E\u0441\u0442\u0430\u043D\u043E\u0432\u043B\u0435\u043D\u043E, \u043D\u0443\u0436\u0435\u043D \u0447\u0435\u043B\u043E\u0432\u0435\u043A`
25608
- );
25609
- narrate(deps, `\u0420\u0435\u0432\u044C\u044E\u0435\u0440\u0430 ${droneLabel(run2)} \u043D\u0435 \u043F\u043E\u0434\u043D\u044F\u0442\u044C: \u0432\u0435\u0442\u043A\u0438 PR \u043D\u0435\u0442 \u043D\u0430 origin \u2014 \u0437\u043E\u0432\u0443 \u0447\u0435\u043B\u043E\u0432\u0435\u043A\u0430 \u0441\u0440\u0430\u0437\u0443, \u043F\u043E\u043F\u044B\u0442\u043A\u0438 \u043D\u0435 \u0436\u0433\u0443.`);
25610
- } else {
25611
- deps.db.addEvent(run2.id, "step", `\u0430\u0432\u0442\u043E-\u0440\u0435\u0432\u044C\u044E \u043D\u0435 \u043F\u043E\u0434\u043D\u044F\u043B\u043E\u0441\u044C: ${String(e)}`);
26013
+ if (grokBalanceBlocksChecker(deps, run2)) {
26014
+ noteGrokBalanceSkip(deps, run2, "\u0440\u0435\u0432\u044C\u044E\u0435\u0440\u0430");
26015
+ } else {
26016
+ run2 = syncBranchFromPr(deps.db, run2, gate.st.headBranch);
26017
+ try {
26018
+ await deps.spawnReviewer(run2, st.files ?? []);
26019
+ narrate(deps, `PR ${droneLabel(run2)} \u0433\u043E\u0442\u043E\u0432 \u2014 \u043F\u043E\u0434\u043D\u0438\u043C\u0430\u044E \u043D\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043C\u043E\u0433\u043E \u0440\u0435\u0432\u044C\u044E\u0435\u0440\u0430.`);
26020
+ } catch (e) {
26021
+ if (isUnrecoverableRefError(e)) {
26022
+ deps.db.addEvent(
26023
+ run2.id,
26024
+ "step",
26025
+ `${unrecoverableMark}: ${String(e)} \u2014 \u043F\u043E\u0432\u0442\u043E\u0440\u043E\u043C \u043D\u0435 \u043B\u0435\u0447\u0438\u0442\u0441\u044F, \u0430\u0432\u0442\u043E-\u0440\u0435\u0432\u044C\u044E \u0434\u043B\u044F \u044D\u0442\u043E\u0433\u043E \u043F\u0440\u043E\u0433\u043E\u043D\u0430 \u043E\u0441\u0442\u0430\u043D\u043E\u0432\u043B\u0435\u043D\u043E, \u043D\u0443\u0436\u0435\u043D \u0447\u0435\u043B\u043E\u0432\u0435\u043A`
26026
+ );
26027
+ narrate(deps, `\u0420\u0435\u0432\u044C\u044E\u0435\u0440\u0430 ${droneLabel(run2)} \u043D\u0435 \u043F\u043E\u0434\u043D\u044F\u0442\u044C: \u0432\u0435\u0442\u043A\u0438 PR \u043D\u0435\u0442 \u043D\u0430 origin \u2014 \u0437\u043E\u0432\u0443 \u0447\u0435\u043B\u043E\u0432\u0435\u043A\u0430 \u0441\u0440\u0430\u0437\u0443, \u043F\u043E\u043F\u044B\u0442\u043A\u0438 \u043D\u0435 \u0436\u0433\u0443.`);
26028
+ } else {
26029
+ deps.db.addEvent(run2.id, "step", `\u0430\u0432\u0442\u043E-\u0440\u0435\u0432\u044C\u044E \u043D\u0435 \u043F\u043E\u0434\u043D\u044F\u043B\u043E\u0441\u044C: ${String(e)}`);
26030
+ }
25612
26031
  }
25613
26032
  }
25614
26033
  }
@@ -25670,15 +26089,20 @@ async function tickOnce(deps) {
25670
26089
  continue;
25671
26090
  }
25672
26091
  }
25673
- const limitHit = !alive && run2.status === "running" ? limitWaitCandidate(deps, run2) : null;
25674
- if (limitHit) {
26092
+ if (!alive && grokBalanceProbeOpen(deps, run2.id)) {
26093
+ returnGrokBalanceProbeToPause(deps, run2, now);
26094
+ continue;
26095
+ }
26096
+ const limitHit = !alive && (run2.status === "running" || run2.status === "blocked") ? limitWaitCandidate(deps, run2) : null;
26097
+ const balancePause = limitHit?.executor === "grok" && limitHit.balance === true;
26098
+ if (limitHit && (run2.status === "running" || balancePause)) {
25675
26099
  const report = deps.limitsSnapshot?.() ?? null;
25676
26100
  let resetsAt = limitResetAt({ executor: limitHit.executor, report, resetHint: limitHit.resetHint, nowMs: now });
25677
26101
  const lastResumeMs = lastLimitResumeMs(deps, run2.id);
25678
26102
  if (lastResumeMs !== null && now - lastResumeMs < LIMIT_RESUME_RETRY_MS) {
25679
26103
  resetsAt = new Date(Math.max(Date.parse(resetsAt), now + LIMIT_RESUME_RETRY_MS)).toISOString();
25680
26104
  }
25681
- const text = limitWaitText(limitHit.executor, limitWaitWindow(report, limitHit.executor));
26105
+ const text = limitHit.balance === true && limitHit.executor === "grok" ? grokBalanceWaitText() : limitWaitText(limitHit.executor, limitWaitWindow(report, limitHit.executor));
25682
26106
  const resetClock = new Date(resetsAt).toLocaleTimeString("ru-RU", { hour: "2-digit", minute: "2-digit" });
25683
26107
  const stopReason = limitWaitReason({ executor: limitHit.executor, resetsAt, text });
25684
26108
  deps.db.updateRun(run2.id, { status: "paused", stop_reason: stopReason });
@@ -26014,9 +26438,16 @@ async function tickOnce(deps) {
26014
26438
  // труба, тот же дедуп «один раз на эпизод». Пустой список при нормальной работе.
26015
26439
  ...await buildReliefCostCandidatesFor(deps, now, droneCap)
26016
26440
  ];
26441
+ const balanceCandidate = grokBalanceAnomalyCandidate(deps);
26442
+ if (balanceCandidate) {
26443
+ const balanceKey = grokBalanceKey(deps);
26444
+ const last = az.tracker.lastFiredMs(balanceKey);
26445
+ if (last != null && now - last >= GROK_BALANCE_RENOTIFY_MS) az.tracker.rearm(balanceKey);
26446
+ }
26017
26447
  const candidates = [
26018
26448
  ...detected.filter((c) => !tickSuppressesAnomaly(c.key)),
26019
- ...tickAnomalyCandidates(autoReviewSnapshot)
26449
+ ...tickAnomalyCandidates(autoReviewSnapshot),
26450
+ ...balanceCandidate ? [balanceCandidate] : []
26020
26451
  ];
26021
26452
  ready = collapseSignals(az.tracker.eligible(now, candidates));
26022
26453
  } catch (e) {
@@ -26077,11 +26508,16 @@ async function tickOnce(deps) {
26077
26508
  }
26078
26509
  deps.stepClock?.mark("5 \u0430\u0432\u0442\u043E-\u0438\u043D\u0442\u0435\u0439\u043A");
26079
26510
  const heavyInFlight = heavyRunsInFlight(deps);
26511
+ if (deps.intake && grokBalanceBlocksIntake(deps)) {
26512
+ const reason = grokBalanceSkipReason();
26513
+ const d = noteDefer(deps.spawnDefer ??= /* @__PURE__ */ new Map(), "grok-balance-intake", reason, GATE_LOG_HEARTBEAT_TICKS);
26514
+ if (d.log) console.error(`[overmind] \u0430\u0432\u0442\u043E-\u0438\u043D\u0442\u0435\u0439\u043A \u043F\u0440\u0438\u0434\u0435\u0440\u0436\u0430\u043D: ${reason}${d.changed ? "" : ` \u2014 \u0435\u0449\u0451 \u0432\u0438\u0441\u0438\u0442, \u0442\u0438\u043A ${d.ticks}`}`);
26515
+ }
26080
26516
  if (heavyInFlight.length && deps.intake) {
26081
26517
  const d = noteDefer(deps.spawnDefer ??= /* @__PURE__ */ new Map(), "weight-intake-hold", intakeHoldReason(heavyInFlight.map(droneLabel).join(", ")), GATE_LOG_HEARTBEAT_TICKS);
26082
26518
  if (d.log) console.error(`[overmind] \u0430\u0432\u0442\u043E-\u0438\u043D\u0442\u0435\u0439\u043A \u043F\u0440\u0438\u0434\u0435\u0440\u0436\u0430\u043D: ${intakeHoldReason(heavyInFlight.map(droneLabel).join(", "))}${d.changed ? "" : ` \u2014 \u0435\u0449\u0451 \u0432\u0438\u0441\u0438\u0442, \u0442\u0438\u043A ${d.ticks}`}`);
26083
26519
  }
26084
- if (deps.intake && !stormBlocksIntake(deps) && !deps.control?.paused && !heavyInFlight.length && deps.intake.maxInFlight > 0 && (!deps.resourcesOk || deps.resourcesOk())) {
26520
+ if (deps.intake && !stormBlocksIntake(deps) && !grokBalanceBlocksIntake(deps) && !deps.control?.paused && !heavyInFlight.length && deps.intake.maxInFlight > 0 && (!deps.resourcesOk || deps.resourcesOk())) {
26085
26521
  const it = deps.intake;
26086
26522
  const claimCap = deps.maxDrones ? droneCap : it.maxInFlight;
26087
26523
  const sinceLastClaim = it.lastClaimAt == null ? Infinity : now - it.lastClaimAt;
@@ -26189,7 +26625,7 @@ async function resolveConflict(deps, reviewRun) {
26189
26625
  model: reviewRun.model,
26190
26626
  review_model: reviewRun.review_model
26191
26627
  });
26192
- const wt = join40(deps.worktreesDir, basename7(repo), `${reviewRun.task_slug}-resolve-${resolver.id}`);
26628
+ const wt = join41(deps.worktreesDir, basename7(repo), `${reviewRun.task_slug}-resolve-${resolver.id}`);
26193
26629
  try {
26194
26630
  await deps.git.prepareDetachedWorktree(repo, branch, wt);
26195
26631
  await deps.git.setWorktreeIdentity(wt, resolver.name);
@@ -26270,7 +26706,7 @@ async function spawnReviewer(deps, reviewRun, files) {
26270
26706
  // (своей у ревьюера нет, TASWM-204), и коммент с вердиктом должен уехать именно туда.
26271
26707
  workspace_id: reviewRun.workspace_id
26272
26708
  });
26273
- const wt = join40(deps.worktreesDir, basename7(repo), `${reviewRun.task_slug}-review-${reviewer.id}`);
26709
+ const wt = join41(deps.worktreesDir, basename7(repo), `${reviewRun.task_slug}-review-${reviewer.id}`);
26274
26710
  try {
26275
26711
  await deps.git.prepareDetachedWorktree(repo, branch, wt);
26276
26712
  await deps.git.setWorktreeIdentity(wt, reviewer.name);
@@ -26353,7 +26789,7 @@ async function spawnVerifier(deps, verifiedRun, files) {
26353
26789
  // штамп цикла: фикс-итерацию проверяет свежий верификатор
26354
26790
  workspace_id: verifiedRun.workspace_id
26355
26791
  });
26356
- const wt = join40(deps.worktreesDir, basename7(repo), `${verifiedRun.task_slug}-verify-${verifier.id}`);
26792
+ const wt = join41(deps.worktreesDir, basename7(repo), `${verifiedRun.task_slug}-verify-${verifier.id}`);
26357
26793
  try {
26358
26794
  await deps.git.prepareDetachedWorktree(repo, branch, wt);
26359
26795
  await deps.git.setWorktreeIdentity(wt, verifier.name);
@@ -26384,25 +26820,55 @@ function lastSubmissionSince(db, run2) {
26384
26820
  }
26385
26821
  return run2.created_at;
26386
26822
  }
26387
- async function verdictTextForFixBrief(deps, run2) {
26388
- const fromFeed = lastChangesSummary(deps.db, run2.id);
26389
- const feedBlocked = !!fromFeed && (isHeaderOnlyVerdict(fromFeed) || verdictEventIsApprove(fromFeed));
26390
- if (fromFeed && !feedBlocked) {
26391
- if (!isClippedPickup(fromFeed)) return fromFeed;
26392
- return await fullReviewComment(deps, run2) ?? fromFeed;
26393
- }
26394
- if (run2.review_verdict !== "changes") {
26395
- const verify = lastVerifySummary(deps.db, run2.id);
26396
- if (verify) {
26397
- const headerOnly = isVerifyHeaderOnly(verify);
26398
- if (headerOnly || isClippedPickup(verify)) {
26399
- const fromVerify = await fullVerifyComment(deps, run2);
26400
- if (fromVerify) return fromVerify;
26401
- }
26402
- if (!headerOnly) return verify;
26823
+ function lastTextThisHead(db, runId, match) {
26824
+ 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;
26403
26831
  }
26404
26832
  }
26405
- return fullReviewComment(deps, run2);
26833
+ for (let i = events.length - 1; i > boundary; i--) {
26834
+ const text = events[i].text ?? "";
26835
+ if (match(text)) return text;
26836
+ }
26837
+ return null;
26838
+ }
26839
+ async function reviewSectionForFix(deps, run2) {
26840
+ const fromFeed = lastTextThisHead(deps.db, run2.id, isVerdictEventText);
26841
+ const sha = verdictHeadSha(fromFeed);
26842
+ const approveFeed = !!fromFeed && verdictEventIsApprove(fromFeed);
26843
+ if (run2.review_verdict === "approve" || run2.review_verdict !== "changes" && approveFeed) {
26844
+ const comment2 = await fullReviewComment(deps, run2);
26845
+ if (comment2) return { body: stripVerdictHead(comment2), sha };
26846
+ return { body: FIX_NO_REVIEW_ITEMS, sha };
26847
+ }
26848
+ if (fromFeed && !isHeaderOnlyVerdict(fromFeed)) {
26849
+ const raw = isClippedPickup(fromFeed) ? await fullReviewComment(deps, run2) ?? fromFeed : fromFeed;
26850
+ return { body: stripVerdictHead(raw), sha: sha ?? verdictHeadSha(raw) };
26851
+ }
26852
+ const comment = await fullReviewComment(deps, run2);
26853
+ if (comment) return { body: stripVerdictHead(comment), sha };
26854
+ return { body: null, sha, recorded: run2.review_verdict === "changes" };
26855
+ }
26856
+ async function verifySectionForFix(deps, run2) {
26857
+ const fromFeed = lastTextThisHead(deps.db, run2.id, (text) => VERIFY_EVENT_PREFIXES.some((p) => text.startsWith(p)));
26858
+ const sha = verdictHeadSha(fromFeed);
26859
+ if (run2.verify_verdict === "confirmed") return { body: FIX_NO_VERIFY_ITEMS, sha };
26860
+ if (fromFeed && !isVerifyHeaderOnly(fromFeed)) {
26861
+ const raw = isClippedPickup(fromFeed) ? await fullVerifyComment(deps, run2) ?? fromFeed : fromFeed;
26862
+ return { body: stripVerdictHead(raw), sha: sha ?? verdictHeadSha(raw) };
26863
+ }
26864
+ const comment = await fullVerifyComment(deps, run2);
26865
+ if (comment) return { body: stripVerdictHead(comment), sha };
26866
+ return { body: null, sha, recorded: isNegativeVerifyVerdict(run2.verify_verdict) };
26867
+ }
26868
+ async function fixBriefParts(deps, run2) {
26869
+ const review = await reviewSectionForFix(deps, run2);
26870
+ const verify = await verifySectionForFix(deps, run2);
26871
+ return { verdict: null, review, verify };
26406
26872
  }
26407
26873
  async function fullReviewComment(deps, run2) {
26408
26874
  if (!deps.verdictComment || !run2.pr_url) return null;
@@ -26467,13 +26933,16 @@ async function respawnRun(deps, run2, mode, nudge) {
26467
26933
  fetchFile: deps.fetchFile,
26468
26934
  onEvent: (text) => deps.db.addEvent(run2.id, "step", text)
26469
26935
  });
26936
+ const fixParts = mode === "fix" ? await fixBriefParts(deps, runToSpawn) : null;
26470
26937
  const freshPrompt = mode === "fix" ? buildChangesFixPrompt({
26471
26938
  prUrl: runToSpawn.pr_url ?? "",
26472
26939
  slug: runToSpawn.task_slug,
26473
26940
  branch: runToSpawn.branch || runToSpawn.task_slug,
26474
26941
  base: base3 || "",
26475
26942
  worktree: wt,
26476
- verdict: await verdictTextForFixBrief(deps, runToSpawn),
26943
+ verdict: fixParts.verdict,
26944
+ reviewSection: fixParts.review,
26945
+ verifySection: fixParts.verify,
26477
26946
  name: runToSpawn.name,
26478
26947
  taskTitle: task?.title ?? null,
26479
26948
  taskUrl: task?.url ?? null,
@@ -26552,7 +27021,7 @@ async function makeStore(repo, worktreesDir, repoFlag, executorFor) {
26552
27021
  console.warn(`[overmind] \u043D\u0435 \u0441\u043C\u043E\u0433 \u0437\u0430\u043F\u043E\u043C\u043D\u0438\u0442\u044C \u043F\u0443\u0442\u044C \u043A \u0440\u0435\u043F\u043E\u0437\u0438\u0442\u043E\u0440\u0438\u044E (${e instanceof Error ? e.message : e}) \u2014 \u0441\u043B\u0435\u0434\u0443\u044E\u0449\u0438\u0439 \u0437\u0430\u043F\u0443\u0441\u043A \u0441\u043D\u043E\u0432\u0430 \u043F\u043E\u043F\u0440\u043E\u0441\u0438\u0442 --repo`);
26553
27022
  }
26554
27023
  }
26555
- const scanRootsList = resolveScanRoots(SWARM_SCAN_ROOTS_RAW, homedir9(), repoPaths);
27024
+ const scanRootsList = resolveScanRoots(SWARM_SCAN_ROOTS_RAW, homedir10(), repoPaths);
26556
27025
  const repoMap = emptyRepoMapState(scanRootsList);
26557
27026
  if (SWARM_BACKEND !== "client") {
26558
27027
  const { SwarmDb: SwarmDb2 } = await loadSqlite();
@@ -26690,7 +27159,7 @@ function lastModelLimits() {
26690
27159
  }
26691
27160
  function sweepDaemonStands(opts) {
26692
27161
  const { db, worktreesDir } = opts;
26693
- const homeDir = opts.homeDir ?? homedir9();
27162
+ const homeDir = opts.homeDir ?? homedir10();
26694
27163
  const runs = db.listRuns();
26695
27164
  const runsWithWorktree = runs.filter((r) => r.worktree_path);
26696
27165
  const bySlug = /* @__PURE__ */ new Map();
@@ -27476,6 +27945,9 @@ async function runDaemon(opts) {
27476
27945
  // Кто мы как машина (TASWM-281) — чтобы отличить ДРУГИЕ машины роя от своей, когда рой
27477
27946
  // советует увезти прогоны туда (TASWM-316).
27478
27947
  selfHostId: host.hostId,
27948
+ selfHostName: host.hostName,
27949
+ // Только email. readGrokAccountEmail не возвращает остальные поля auth.json.
27950
+ grokAccountEmail: () => readGrokAccountEmail(grokAccountAuthPath(process.env)),
27479
27951
  // Состояние градуального контроллера (окна ramp/pause, reliefSince) + журнал цены
27480
27952
  // разгрузки (TASWM-316) — заводим ОДИН раз на цикл демона, tickOnce (manageRelief)
27481
27953
  // мутирует эти же поля каждый тик.