@taskless-app/swarm 0.6.99 → 0.6.100

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.100",
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: "a0643b2118fce225b5afbe7ce9c1afbe7cd25d39"
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);
@@ -17507,6 +17586,10 @@ var AnomalyTracker = class {
17507
17586
  this.fires.delete(key);
17508
17587
  this.persist();
17509
17588
  }
17589
+ /** Когда по этому ключу последний раз ушёл сигнал. Нет — ещё не звонили. Кулдаун rearm не сбрасывает. */
17590
+ lastFiredMs(key) {
17591
+ return this.lastFiredAt.get(key);
17592
+ }
17510
17593
  /**
17511
17594
  * Пора ли снова спросить внешний мир (gh) про ключ (TAS-1100): не чаще everyMs.
17512
17595
  * Только память: после рестарта первый вопрос уйдёт сразу — один вызов на прогон, не поток.
@@ -18681,21 +18764,21 @@ async function prodClearMergeIntent(runId, deps = {}) {
18681
18764
 
18682
18765
  // src/envGate.ts
18683
18766
  import { existsSync as existsSync20 } from "fs";
18684
- import { join as join36 } from "path";
18767
+ import { join as join37 } from "path";
18685
18768
  import { createConnection } from "net";
18686
18769
  import { execa as execa2 } from "execa";
18687
18770
 
18688
18771
  // src/platform.ts
18689
18772
  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";
18773
+ import { accessSync as accessSync2, constants as constants2, existsSync as existsSync19, readFileSync as readFileSync26, realpathSync as realpathSync3 } from "fs";
18774
+ import { delimiter as delimiter2, join as join36, posix as posix2, win32 } from "path";
18692
18775
  function resolveCommandPath(name, env = process.env, platform = process.platform) {
18693
18776
  if (name.includes("/") || name.includes("\\")) return existsSync19(name) ? name : null;
18694
18777
  const dirs = (env.PATH ?? env.Path ?? "").split(delimiter2).filter(Boolean);
18695
18778
  const exts = platform === "win32" ? (env.PATHEXT ?? ".EXE;.CMD;.BAT").split(";").filter(Boolean) : [""];
18696
18779
  for (const dir of dirs) {
18697
18780
  for (const ext of exts) {
18698
- const candidate = join35(dir, name + ext);
18781
+ const candidate = join36(dir, name + ext);
18699
18782
  if (existsSync19(candidate)) return candidate;
18700
18783
  }
18701
18784
  }
@@ -18866,7 +18949,7 @@ var COMPOSE_MARKERS = [
18866
18949
  ];
18867
18950
  function detectRequirements(repo, io = {}) {
18868
18951
  const exists = io.exists ?? existsSync20;
18869
- const marker = COMPOSE_MARKERS.find((f) => exists(join36(repo, f)));
18952
+ const marker = COMPOSE_MARKERS.find((f) => exists(join37(repo, f)));
18870
18953
  return marker ? [{ kind: "docker", raw: `docker (\u0434\u0435\u0442\u0435\u043A\u0442: ${marker})` }] : [];
18871
18954
  }
18872
18955
  function resolveRequirements(repo, declared, io = {}) {
@@ -20693,14 +20776,14 @@ function closeWebServer(server) {
20693
20776
 
20694
20777
  // src/hostCommands.ts
20695
20778
  init_src();
20696
- import { readFileSync as readFileSync26, renameSync as renameSync10, writeFileSync as writeFileSync17 } from "fs";
20697
- import { join as join37 } from "path";
20779
+ import { readFileSync as readFileSync27, renameSync as renameSync10, writeFileSync as writeFileSync17 } from "fs";
20780
+ import { join as join38 } from "path";
20698
20781
  function hostCommandStatePath(home) {
20699
- return join37(home, "host-command.json");
20782
+ return join38(home, "host-command.json");
20700
20783
  }
20701
20784
  function readState(path) {
20702
20785
  try {
20703
- return JSON.parse(readFileSync26(path, "utf8"));
20786
+ return JSON.parse(readFileSync27(path, "utf8"));
20704
20787
  } catch {
20705
20788
  return {};
20706
20789
  }
@@ -20871,7 +20954,7 @@ async function doRestart(cmd, opts, note) {
20871
20954
  // src/selfUpdate.ts
20872
20955
  init_git();
20873
20956
  import { existsSync as existsSync21 } from "fs";
20874
- import { join as join38 } from "path";
20957
+ import { join as join39 } from "path";
20875
20958
  import { $ as $6 } from "execa";
20876
20959
 
20877
20960
  // src/cliIo.ts
@@ -20933,7 +21016,7 @@ async function runSelfUpdate(io) {
20933
21016
  };
20934
21017
  }
20935
21018
  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"))) {
21019
+ if (!exists(join39(repo, "pnpm-lock.yaml"))) {
20937
21020
  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
21021
  }
20939
21022
  const installed2 = await run2("pnpm", ["install", "--frozen-lockfile"], repo);
@@ -21108,19 +21191,19 @@ async function fetchExternalStorm(url, opts = {}) {
21108
21191
  }
21109
21192
 
21110
21193
  // 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";
21194
+ import { existsSync as existsSync22, readFileSync as readFileSync28, renameSync as renameSync11, writeFileSync as writeFileSync18 } from "fs";
21195
+ import { join as join40 } from "path";
21113
21196
  var KEY_TTL_MS = 7 * 24 * 60 * 6e4;
21114
21197
  var MAX_RESOLVED = 200;
21115
21198
  function emptyState() {
21116
21199
  return { since: {}, lastFiredAt: {}, fires: {}, resolved: [], stopQuiet: null };
21117
21200
  }
21118
21201
  function anomalyStatePath(home) {
21119
- return join39(home, "anomaly-state.json");
21202
+ return join40(home, "anomaly-state.json");
21120
21203
  }
21121
21204
  function loadAnomalyState(home, now = Date.now(), io = {}) {
21122
21205
  const exists = io.exists ?? existsSync22;
21123
- const readFile3 = io.readFile ?? ((p) => readFileSync27(p, "utf8"));
21206
+ const readFile3 = io.readFile ?? ((p) => readFileSync28(p, "utf8"));
21124
21207
  const path = anomalyStatePath(home);
21125
21208
  if (!exists(path)) return emptyState();
21126
21209
  try {
@@ -22184,6 +22267,10 @@ async function spawnVerifiersForOpenPrs(deps, _stormActive) {
22184
22267
  noteDraftHold(run2);
22185
22268
  continue;
22186
22269
  }
22270
+ if (grokBalanceBlocksChecker(deps, run2)) {
22271
+ noteGrokBalanceSkip(deps, run2, "\u0432\u0435\u0440\u0438\u0444\u0438\u043A\u0430\u0442\u043E\u0440\u0430");
22272
+ continue;
22273
+ }
22187
22274
  await deps.spawnVerifier(run2, st?.files ?? []);
22188
22275
  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
22276
  } catch (e) {
@@ -22245,13 +22332,13 @@ function buildCiReadyNudge(prUrl, over) {
22245
22332
  ].join("\n");
22246
22333
  }
22247
22334
  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()) {
22335
+ function dockerStandRules(prefix, homeDir = homedir10()) {
22249
22336
  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
22337
  }
22251
22338
  function promptStandRule(worktree, slug) {
22252
22339
  const raw = worktree && worktree.length > 0 ? worktree : slug;
22253
22340
  const prefix = composeProjectPrefix(basename7(raw));
22254
- return prefix ? dockerStandRules(prefix, homedir9()) : "";
22341
+ return prefix ? dockerStandRules(prefix, homedir10()) : "";
22255
22342
  }
22256
22343
  function buildChangesFixPrompt(args) {
22257
22344
  const { prUrl, slug, branch, base: base3, worktree, verdict } = args;
@@ -22443,10 +22530,10 @@ ${task.description}` : `\u0417\u0430\u0434\u0430\u0447\u0430 ${run2.task_slug} (
22443
22530
  }
22444
22531
  return parts.join("\n");
22445
22532
  }
22446
- var HERO_CHARTER_PATH = join40(dirname6(THIS_FILE), "..", "docs", "HERO.md");
22533
+ var HERO_CHARTER_PATH = join41(dirname6(THIS_FILE), "..", "docs", "HERO.md");
22447
22534
  function buildHeroPrompt(task, run2, taskContext, attachmentsBlock) {
22448
22535
  const name = run2.name || `#${run2.id}`;
22449
- const charter = readFileSync28(HERO_CHARTER_PATH, "utf8");
22536
+ const charter = readFileSync29(HERO_CHARTER_PATH, "utf8");
22450
22537
  const head = task ? `\u042D\u041F\u0418\u041A ${run2.task_slug}: ${task.title}
22451
22538
 
22452
22539
  ${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 +22593,9 @@ function ciTrustLine(prUrl, verifyMode, ciClosed = null) {
22506
22593
  }
22507
22594
  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
22595
  }
22509
- var REVIEW_SKILL_PATH = join40(bundledRoleDir("drone"), "skills", "taskless-review", "SKILL.md");
22596
+ var REVIEW_SKILL_PATH = join41(bundledRoleDir("drone"), "skills", "taskless-review", "SKILL.md");
22510
22597
  function reviewDefectClasses(skillPath = REVIEW_SKILL_PATH) {
22511
- const text = readFileSync28(skillPath, "utf8");
22598
+ const text = readFileSync29(skillPath, "utf8");
22512
22599
  const m = /^## Классы дефектов\n([\s\S]*?)(?=^## |(?![\s\S]))/m.exec(text);
22513
22600
  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
22601
  return `\u041A\u043B\u0430\u0441\u0441\u044B \u0434\u0435\u0444\u0435\u043A\u0442\u043E\u0432 (skill taskless-review):
@@ -23274,7 +23361,7 @@ function repoHasCi(deps, run2) {
23274
23361
  function repoHasCiWorkflows(worktreePath, repo) {
23275
23362
  for (const base3 of [worktreePath, repo]) {
23276
23363
  if (!base3) continue;
23277
- const dir = join40(base3, ".github", "workflows");
23364
+ const dir = join41(base3, ".github", "workflows");
23278
23365
  try {
23279
23366
  if (readdirSync18(dir).some((f) => f.endsWith(".yml") || f.endsWith(".yaml"))) return true;
23280
23367
  } catch {
@@ -23506,6 +23593,183 @@ function worktreeAndTranscriptAlive(deps, run2) {
23506
23593
  function limitWaitCandidate(deps, run2) {
23507
23594
  return deps.exitLimit?.(run2) ?? null;
23508
23595
  }
23596
+ var grokBalanceResumedThisTick = /* @__PURE__ */ new Set();
23597
+ var grokBalanceProbes = /* @__PURE__ */ new WeakMap();
23598
+ var grokBalanceFixHeldThisTick = /* @__PURE__ */ new Set();
23599
+ var grokBalanceDeadMemo = null;
23600
+ function resetGrokBalanceTick() {
23601
+ grokBalanceResumedThisTick.clear();
23602
+ grokBalanceDeadMemo = null;
23603
+ grokBalanceFixHeldThisTick.clear();
23604
+ }
23605
+ function grokBalanceProbeMap(db) {
23606
+ let map = grokBalanceProbes.get(db);
23607
+ if (!map) {
23608
+ map = /* @__PURE__ */ new Map();
23609
+ grokBalanceProbes.set(db, map);
23610
+ }
23611
+ return map;
23612
+ }
23613
+ function grokLogShowsBalance(deps, run2) {
23614
+ const hit = limitWaitCandidate(deps, run2);
23615
+ return hit?.executor === "grok" && hit.balance === true;
23616
+ }
23617
+ function grokBalanceProbeOpen(deps, runId) {
23618
+ return grokBalanceProbes.get(deps.db)?.has(runId) === true;
23619
+ }
23620
+ function releaseGrokBalanceAfterProbeSuccess(deps, now = deps.now ? deps.now() : Date.now()) {
23621
+ const probes = grokBalanceProbes.get(deps.db);
23622
+ if (!probes || probes.size === 0) return;
23623
+ let succeeded = false;
23624
+ for (const [id, probe] of [...probes]) {
23625
+ const run2 = deps.db.getRun(id);
23626
+ if (!run2) {
23627
+ probes.delete(id);
23628
+ continue;
23629
+ }
23630
+ const live2 = run2.status === "running" && run2.pid != null && deps.isAlive(run2.pid);
23631
+ if (!live2 || now - probe.startedAt < GROK_BALANCE_SUCCESS_MS || grokLogShowsBalance(deps, run2)) continue;
23632
+ probes.delete(id);
23633
+ succeeded = true;
23634
+ }
23635
+ if (!succeeded) return;
23636
+ const waiting = deps.db.listRuns("paused").filter((run2) => isGrokBalanceWait(run2.stop_reason));
23637
+ const stopReason = limitWaitReason({
23638
+ executor: "grok",
23639
+ resetsAt: new Date(now).toISOString(),
23640
+ 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"
23641
+ });
23642
+ for (const run2 of waiting) {
23643
+ deps.db.updateRun(run2.id, { stop_reason: stopReason });
23644
+ 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");
23645
+ }
23646
+ if (waiting.length > 0) {
23647
+ 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.");
23648
+ }
23649
+ }
23650
+ function grokBalanceProbeHolds(deps) {
23651
+ releaseGrokBalanceAfterProbeSuccess(deps);
23652
+ const probes = grokBalanceProbes.get(deps.db);
23653
+ if (!probes || probes.size === 0) return false;
23654
+ let holds = false;
23655
+ for (const id of [...probes.keys()]) {
23656
+ const run2 = deps.db.getRun(id);
23657
+ if (!run2) {
23658
+ probes.delete(id);
23659
+ continue;
23660
+ }
23661
+ const live2 = run2.status === "running" && run2.pid != null && deps.isAlive(run2.pid);
23662
+ if (!live2) {
23663
+ if (run2.status === "running" || run2.status === "blocked") {
23664
+ holds = true;
23665
+ continue;
23666
+ }
23667
+ probes.delete(id);
23668
+ continue;
23669
+ }
23670
+ holds = true;
23671
+ }
23672
+ return holds;
23673
+ }
23674
+ function grokBalanceSkipReason() {
23675
+ 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}`;
23676
+ }
23677
+ function runUsesGrok(deps, run2) {
23678
+ const pinned = parseModelRef(run2.model ?? null);
23679
+ if (pinned) return findProvider(pinned.providerId)?.executorId === "grok";
23680
+ try {
23681
+ const id = deps.storm?.providerFor?.(run2);
23682
+ if (!id) return false;
23683
+ return findProvider(id)?.executorId === "grok";
23684
+ } catch {
23685
+ return false;
23686
+ }
23687
+ }
23688
+ function deadRunningGrokBalance(deps) {
23689
+ if (grokBalanceDeadMemo != null) return grokBalanceDeadMemo;
23690
+ let found = false;
23691
+ if (deps.exitLimit) {
23692
+ for (const status of ["running", "blocked"]) {
23693
+ for (const run2 of deps.db.listRuns(status)) {
23694
+ if (run2.pid != null && deps.isAlive(run2.pid)) continue;
23695
+ const hit = limitWaitCandidate(deps, run2);
23696
+ if (hit?.executor === "grok" && hit.balance === true) {
23697
+ found = true;
23698
+ break;
23699
+ }
23700
+ }
23701
+ if (found) break;
23702
+ }
23703
+ }
23704
+ grokBalanceDeadMemo = found;
23705
+ return found;
23706
+ }
23707
+ function grokBalanceHolds(deps) {
23708
+ if (grokBalanceProbeHolds(deps)) return true;
23709
+ if (grokBalanceResumedThisTick.size > 0) return true;
23710
+ for (const run2 of deps.db.listRuns("paused")) {
23711
+ if (isGrokBalanceWait(run2.stop_reason)) return true;
23712
+ }
23713
+ return deadRunningGrokBalance(deps);
23714
+ }
23715
+ function grokBalanceBlocksRun(deps, run2) {
23716
+ return grokBalanceHolds(deps) && runUsesGrok(deps, run2);
23717
+ }
23718
+ function grokBalanceBlocksChecker(deps, author) {
23719
+ return grokBalanceBlocksRun(deps, { kind: "reviewer", model: author.review_model ?? null });
23720
+ }
23721
+ function grokBalanceBlocksIntake(deps) {
23722
+ if (!grokBalanceHolds(deps)) return false;
23723
+ return runUsesGrok(deps, { kind: "drone", model: null });
23724
+ }
23725
+ function noteGrokBalanceSkip(deps, run2, who) {
23726
+ const reason = grokBalanceSkipReason();
23727
+ const d = noteDefer(deps.spawnDefer ??= /* @__PURE__ */ new Map(), `grok-balance:${run2.id}`, reason, GATE_LOG_HEARTBEAT_TICKS);
23728
+ if (d.changed) deps.db.addEvent(run2.id, "step", `\u0441\u043F\u0430\u0432\u043D \u043E\u0442\u043B\u043E\u0436\u0435\u043D: ${reason}`);
23729
+ if (d.log) {
23730
+ console.error(
23731
+ `[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}`}`
23732
+ );
23733
+ }
23734
+ }
23735
+ function safeGrokEmail(deps) {
23736
+ try {
23737
+ const value = deps.grokAccountEmail?.() ?? null;
23738
+ return typeof value === "string" && value.includes("@") ? value : null;
23739
+ } catch {
23740
+ return null;
23741
+ }
23742
+ }
23743
+ function grokBalanceWaitingCount(deps) {
23744
+ const ids = new Set(grokBalanceResumedThisTick);
23745
+ for (const run2 of deps.db.listRuns("paused")) {
23746
+ if (isGrokBalanceWait(run2.stop_reason)) ids.add(run2.id);
23747
+ }
23748
+ return ids.size;
23749
+ }
23750
+ function grokBalanceHostName(deps) {
23751
+ const name = (deps.selfHostName || deps.storm?.hostName || "").trim();
23752
+ return name || "\u043C\u0430\u0448\u0438\u043D\u0430";
23753
+ }
23754
+ function grokBalanceKey(deps) {
23755
+ return grokBalanceSignalKey(deps.selfHostId);
23756
+ }
23757
+ function grokBalanceAnomalyCandidate(deps) {
23758
+ if (!grokBalanceHolds(deps)) return null;
23759
+ return {
23760
+ key: grokBalanceKey(deps),
23761
+ once: true,
23762
+ minDurationMs: 0,
23763
+ build: () => {
23764
+ const signal = grokBalanceSignal({
23765
+ hostName: grokBalanceHostName(deps),
23766
+ email: safeGrokEmail(deps),
23767
+ waiting: grokBalanceWaitingCount(deps)
23768
+ });
23769
+ return { level: "decision", title: signal.title, body: clipChars(signal.body, ANOMALY_BODY_MAX) };
23770
+ }
23771
+ };
23772
+ }
23509
23773
  async function projectWantsChecks(deps, run2) {
23510
23774
  if (!deps.autoReviewForRepo) return true;
23511
23775
  return await deps.autoReviewForRepo(effectiveRepo(deps, run2), run2.task_slug).catch((e) => {
@@ -23526,6 +23790,10 @@ async function spawnFreshReviewerAfterStall(deps, run2, why) {
23526
23790
  }
23527
23791
  const gate = await prGateForReviewer(deps, run2, run2.pr_url, "\u043F\u043E\u043A\u0430 \u0436\u0434\u0430\u043B CI");
23528
23792
  if (gate.kind !== "spawn") return;
23793
+ if (grokBalanceBlocksChecker(deps, run2)) {
23794
+ noteGrokBalanceSkip(deps, run2, "\u0440\u0435\u0432\u044C\u044E\u0435\u0440\u0430");
23795
+ return;
23796
+ }
23529
23797
  const st = gate.st;
23530
23798
  try {
23531
23799
  await deps.spawnReviewer(run2, st.files ?? []);
@@ -23561,6 +23829,9 @@ function draftHoldBody(prUrl) {
23561
23829
  function tickSuppressesAnomaly(key) {
23562
23830
  for (const id of draftHeldThisTick.keys()) if (key === `pr_no_reviewer:${id}`) return true;
23563
23831
  for (const id of fixBlockedThisTick.keys()) if (key === `pr_stuck_changes:${id}`) return true;
23832
+ for (const id of grokBalanceFixHeldThisTick) {
23833
+ if (key === `pr_stuck_changes:${id}` || key === `pr_no_reviewer:${id}`) return true;
23834
+ }
23564
23835
  return false;
23565
23836
  }
23566
23837
  function tickAnomalyCandidates(autoReviewSnapshot) {
@@ -23623,6 +23894,11 @@ async function wakeAuthorOnChanges(deps, snapshot, now, droneCap) {
23623
23894
  const run2 = deps.db.getRun(snapshot.id);
23624
23895
  if (!run2 || isAwaitingBudget(run2.status, run2.stop_reason)) return false;
23625
23896
  if (run2.pid != null && deps.isAlive(run2.pid)) return false;
23897
+ if (grokBalanceBlocksRun(deps, run2)) {
23898
+ grokBalanceFixHeldThisTick.add(run2.id);
23899
+ noteGrokBalanceSkip(deps, run2, "\u0444\u0438\u043A\u0441-\u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044E");
23900
+ return false;
23901
+ }
23626
23902
  if (deps.db.activeReviewersFor(run2.id).some((r) => r.status !== "stalled" && !isAwaitingCi(r.status, r.stop_reason))) {
23627
23903
  return blockFix(run2, "\u0440\u0435\u0432\u044C\u044E\u0435\u0440 \u0435\u0449\u0451 \u0432 \u0440\u0430\u0431\u043E\u0442\u0435");
23628
23904
  }
@@ -23782,7 +24058,7 @@ async function zoneConflictFor(db, models, activeFiles, run2, repo, repoFallback
23782
24058
  activeFiles.prune(holders.map((r) => r.id));
23783
24059
  const fileExists = (p) => {
23784
24060
  try {
23785
- return statSync16(join40(repo, p), { throwIfNoEntry: false })?.isFile() ?? false;
24061
+ return statSync16(join41(repo, p), { throwIfNoEntry: false })?.isFile() ?? false;
23786
24062
  } catch {
23787
24063
  return false;
23788
24064
  }
@@ -23946,6 +24222,9 @@ async function trySpawnQueuedRun(deps, run2) {
23946
24222
  // причина одна на машину — в лог уходит одной строкой, а не по строке на прогон
23947
24223
  });
23948
24224
  }
24225
+ if (grokBalanceBlocksRun(deps, run2)) {
24226
+ return deferSpawn(deps, run2, `${grokBalanceSkipReason()} (TASWM-660)`, { logKey: "grok-balance" });
24227
+ }
23949
24228
  const heavy = heavyRunsInFlight(deps);
23950
24229
  if (heavy.length && heavy.every((h) => h.id !== run2.id)) {
23951
24230
  return deferSpawn(deps, run2, intakeHoldReason(heavy.map(droneLabel).join(", ")), {
@@ -24440,6 +24719,16 @@ function lastLimitResumeMs(deps, runId) {
24440
24719
  const event = deps.db.events(runId).filter((item) => item.kind === "resumed" && item.text === LIMIT_RESUMED_TEXT).at(-1);
24441
24720
  return event ? stampMs(event.at) : null;
24442
24721
  }
24722
+ function returnGrokBalanceProbeToPause(deps, run2, now) {
24723
+ const resetsAt = new Date(now + LIMIT_RESUME_RETRY_MS).toISOString();
24724
+ const text = grokBalanceWaitText();
24725
+ const stopReason = limitWaitReason({ executor: "grok", resetsAt, text });
24726
+ deps.db.updateRun(run2.id, { status: "paused", stop_reason: stopReason });
24727
+ const resetClock = new Date(resetsAt).toLocaleTimeString("ru-RU", { hour: "2-digit", minute: "2-digit" });
24728
+ 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}`);
24729
+ 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}`);
24730
+ grokBalanceProbeMap(deps.db).delete(run2.id);
24731
+ }
24443
24732
  async function resumeLimitWaits(deps, now, droneCap, _stormActive) {
24444
24733
  if (!deps.respawn || countActiveDrones(deps.db) >= droneCap) return;
24445
24734
  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 +24750,16 @@ async function resumeLimitWaits(deps, now, droneCap, _stormActive) {
24461
24750
  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
24751
  }
24463
24752
  }
24753
+ const balanceWait = isGrokBalanceWait(candidate.stop_reason);
24464
24754
  try {
24465
24755
  await deps.respawn(candidate, mode);
24466
24756
  deps.db.updateRun(candidate.id, { stop_reason: null });
24467
24757
  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
24758
  deps.db.addEvent(candidate.id, "resumed", LIMIT_RESUMED_TEXT);
24759
+ if (balanceWait) {
24760
+ grokBalanceProbeMap(deps.db).set(candidate.id, { startedAt: now });
24761
+ grokBalanceResumedThisTick.add(candidate.id);
24762
+ }
24469
24763
  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
24764
  } catch (e) {
24471
24765
  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)}`;
@@ -25200,6 +25494,7 @@ async function tickOnce(deps) {
25200
25494
  beginGhMergePass(deps.ghMerges);
25201
25495
  draftHeldThisTick.clear();
25202
25496
  fixBlockedThisTick.clear();
25497
+ resetGrokBalanceTick();
25203
25498
  const worktreeExists = deps.worktreeExists ?? existsSync23;
25204
25499
  const hasTranscript = deps.hasTranscript ?? executorHasSession;
25205
25500
  deps.stepClock?.mark("0 \u0437\u0430\u043C\u0435\u0440 \u0445\u043E\u0441\u0442\u0430");
@@ -25333,12 +25628,14 @@ async function tickOnce(deps) {
25333
25628
  }
25334
25629
  if (deps.exitOutcome && endedItself(deps.exitOutcome(run2))) continue;
25335
25630
  if (limitWaitCandidate(deps, run2)) continue;
25631
+ if (grokBalanceProbeOpen(deps, run2.id)) continue;
25336
25632
  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
25633
  }
25338
25634
  stormActive = await manageStorm(deps, now, worktreeExists, hasTranscript);
25339
25635
  }
25340
25636
  const droneCap = deps.maxDrones ? await deps.maxDrones() : Infinity;
25341
25637
  deps.stepClock?.mark("0e \u0432\u043E\u0437\u0432\u0440\u0430\u0442 \u043F\u043E\u0441\u043B\u0435 \u043B\u0438\u043C\u0438\u0442\u0430");
25638
+ releaseGrokBalanceAfterProbeSuccess(deps, now);
25342
25639
  await resumeLimitWaits(deps, now, droneCap, stormActive);
25343
25640
  deps.stepClock?.mark("1 \u043F\u043E\u0434\u043D\u044F\u0442\u044C \u043E\u0447\u0435\u0440\u0435\u0434\u044C");
25344
25641
  if (stormActive) noteStormStall(deps);
@@ -25595,20 +25892,24 @@ async function tickOnce(deps) {
25595
25892
  if ((!deps.resourcesOk || deps.resourcesOk()) && reviewersCapOk) {
25596
25893
  const gate = await prGateForReviewer(deps, run2, prUrl, "\u043F\u043E\u043A\u0430 \u0436\u0434\u0430\u043B \u0440\u0435\u0432\u044C\u044E\u0435\u0440\u0430");
25597
25894
  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)}`);
25895
+ if (grokBalanceBlocksChecker(deps, run2)) {
25896
+ noteGrokBalanceSkip(deps, run2, "\u0440\u0435\u0432\u044C\u044E\u0435\u0440\u0430");
25897
+ } else {
25898
+ run2 = syncBranchFromPr(deps.db, run2, gate.st.headBranch);
25899
+ try {
25900
+ await deps.spawnReviewer(run2, st.files ?? []);
25901
+ 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.`);
25902
+ } catch (e) {
25903
+ if (isUnrecoverableRefError(e)) {
25904
+ deps.db.addEvent(
25905
+ run2.id,
25906
+ "step",
25907
+ `${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`
25908
+ );
25909
+ 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.`);
25910
+ } else {
25911
+ 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)}`);
25912
+ }
25612
25913
  }
25613
25914
  }
25614
25915
  }
@@ -25670,15 +25971,20 @@ async function tickOnce(deps) {
25670
25971
  continue;
25671
25972
  }
25672
25973
  }
25673
- const limitHit = !alive && run2.status === "running" ? limitWaitCandidate(deps, run2) : null;
25674
- if (limitHit) {
25974
+ if (!alive && grokBalanceProbeOpen(deps, run2.id)) {
25975
+ returnGrokBalanceProbeToPause(deps, run2, now);
25976
+ continue;
25977
+ }
25978
+ const limitHit = !alive && (run2.status === "running" || run2.status === "blocked") ? limitWaitCandidate(deps, run2) : null;
25979
+ const balancePause = limitHit?.executor === "grok" && limitHit.balance === true;
25980
+ if (limitHit && (run2.status === "running" || balancePause)) {
25675
25981
  const report = deps.limitsSnapshot?.() ?? null;
25676
25982
  let resetsAt = limitResetAt({ executor: limitHit.executor, report, resetHint: limitHit.resetHint, nowMs: now });
25677
25983
  const lastResumeMs = lastLimitResumeMs(deps, run2.id);
25678
25984
  if (lastResumeMs !== null && now - lastResumeMs < LIMIT_RESUME_RETRY_MS) {
25679
25985
  resetsAt = new Date(Math.max(Date.parse(resetsAt), now + LIMIT_RESUME_RETRY_MS)).toISOString();
25680
25986
  }
25681
- const text = limitWaitText(limitHit.executor, limitWaitWindow(report, limitHit.executor));
25987
+ const text = limitHit.balance === true && limitHit.executor === "grok" ? grokBalanceWaitText() : limitWaitText(limitHit.executor, limitWaitWindow(report, limitHit.executor));
25682
25988
  const resetClock = new Date(resetsAt).toLocaleTimeString("ru-RU", { hour: "2-digit", minute: "2-digit" });
25683
25989
  const stopReason = limitWaitReason({ executor: limitHit.executor, resetsAt, text });
25684
25990
  deps.db.updateRun(run2.id, { status: "paused", stop_reason: stopReason });
@@ -26014,9 +26320,16 @@ async function tickOnce(deps) {
26014
26320
  // труба, тот же дедуп «один раз на эпизод». Пустой список при нормальной работе.
26015
26321
  ...await buildReliefCostCandidatesFor(deps, now, droneCap)
26016
26322
  ];
26323
+ const balanceCandidate = grokBalanceAnomalyCandidate(deps);
26324
+ if (balanceCandidate) {
26325
+ const balanceKey = grokBalanceKey(deps);
26326
+ const last = az.tracker.lastFiredMs(balanceKey);
26327
+ if (last != null && now - last >= GROK_BALANCE_RENOTIFY_MS) az.tracker.rearm(balanceKey);
26328
+ }
26017
26329
  const candidates = [
26018
26330
  ...detected.filter((c) => !tickSuppressesAnomaly(c.key)),
26019
- ...tickAnomalyCandidates(autoReviewSnapshot)
26331
+ ...tickAnomalyCandidates(autoReviewSnapshot),
26332
+ ...balanceCandidate ? [balanceCandidate] : []
26020
26333
  ];
26021
26334
  ready = collapseSignals(az.tracker.eligible(now, candidates));
26022
26335
  } catch (e) {
@@ -26077,11 +26390,16 @@ async function tickOnce(deps) {
26077
26390
  }
26078
26391
  deps.stepClock?.mark("5 \u0430\u0432\u0442\u043E-\u0438\u043D\u0442\u0435\u0439\u043A");
26079
26392
  const heavyInFlight = heavyRunsInFlight(deps);
26393
+ if (deps.intake && grokBalanceBlocksIntake(deps)) {
26394
+ const reason = grokBalanceSkipReason();
26395
+ const d = noteDefer(deps.spawnDefer ??= /* @__PURE__ */ new Map(), "grok-balance-intake", reason, GATE_LOG_HEARTBEAT_TICKS);
26396
+ 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}`}`);
26397
+ }
26080
26398
  if (heavyInFlight.length && deps.intake) {
26081
26399
  const d = noteDefer(deps.spawnDefer ??= /* @__PURE__ */ new Map(), "weight-intake-hold", intakeHoldReason(heavyInFlight.map(droneLabel).join(", ")), GATE_LOG_HEARTBEAT_TICKS);
26082
26400
  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
26401
  }
26084
- if (deps.intake && !stormBlocksIntake(deps) && !deps.control?.paused && !heavyInFlight.length && deps.intake.maxInFlight > 0 && (!deps.resourcesOk || deps.resourcesOk())) {
26402
+ if (deps.intake && !stormBlocksIntake(deps) && !grokBalanceBlocksIntake(deps) && !deps.control?.paused && !heavyInFlight.length && deps.intake.maxInFlight > 0 && (!deps.resourcesOk || deps.resourcesOk())) {
26085
26403
  const it = deps.intake;
26086
26404
  const claimCap = deps.maxDrones ? droneCap : it.maxInFlight;
26087
26405
  const sinceLastClaim = it.lastClaimAt == null ? Infinity : now - it.lastClaimAt;
@@ -26189,7 +26507,7 @@ async function resolveConflict(deps, reviewRun) {
26189
26507
  model: reviewRun.model,
26190
26508
  review_model: reviewRun.review_model
26191
26509
  });
26192
- const wt = join40(deps.worktreesDir, basename7(repo), `${reviewRun.task_slug}-resolve-${resolver.id}`);
26510
+ const wt = join41(deps.worktreesDir, basename7(repo), `${reviewRun.task_slug}-resolve-${resolver.id}`);
26193
26511
  try {
26194
26512
  await deps.git.prepareDetachedWorktree(repo, branch, wt);
26195
26513
  await deps.git.setWorktreeIdentity(wt, resolver.name);
@@ -26270,7 +26588,7 @@ async function spawnReviewer(deps, reviewRun, files) {
26270
26588
  // (своей у ревьюера нет, TASWM-204), и коммент с вердиктом должен уехать именно туда.
26271
26589
  workspace_id: reviewRun.workspace_id
26272
26590
  });
26273
- const wt = join40(deps.worktreesDir, basename7(repo), `${reviewRun.task_slug}-review-${reviewer.id}`);
26591
+ const wt = join41(deps.worktreesDir, basename7(repo), `${reviewRun.task_slug}-review-${reviewer.id}`);
26274
26592
  try {
26275
26593
  await deps.git.prepareDetachedWorktree(repo, branch, wt);
26276
26594
  await deps.git.setWorktreeIdentity(wt, reviewer.name);
@@ -26353,7 +26671,7 @@ async function spawnVerifier(deps, verifiedRun, files) {
26353
26671
  // штамп цикла: фикс-итерацию проверяет свежий верификатор
26354
26672
  workspace_id: verifiedRun.workspace_id
26355
26673
  });
26356
- const wt = join40(deps.worktreesDir, basename7(repo), `${verifiedRun.task_slug}-verify-${verifier.id}`);
26674
+ const wt = join41(deps.worktreesDir, basename7(repo), `${verifiedRun.task_slug}-verify-${verifier.id}`);
26357
26675
  try {
26358
26676
  await deps.git.prepareDetachedWorktree(repo, branch, wt);
26359
26677
  await deps.git.setWorktreeIdentity(wt, verifier.name);
@@ -26552,7 +26870,7 @@ async function makeStore(repo, worktreesDir, repoFlag, executorFor) {
26552
26870
  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
26871
  }
26554
26872
  }
26555
- const scanRootsList = resolveScanRoots(SWARM_SCAN_ROOTS_RAW, homedir9(), repoPaths);
26873
+ const scanRootsList = resolveScanRoots(SWARM_SCAN_ROOTS_RAW, homedir10(), repoPaths);
26556
26874
  const repoMap = emptyRepoMapState(scanRootsList);
26557
26875
  if (SWARM_BACKEND !== "client") {
26558
26876
  const { SwarmDb: SwarmDb2 } = await loadSqlite();
@@ -26690,7 +27008,7 @@ function lastModelLimits() {
26690
27008
  }
26691
27009
  function sweepDaemonStands(opts) {
26692
27010
  const { db, worktreesDir } = opts;
26693
- const homeDir = opts.homeDir ?? homedir9();
27011
+ const homeDir = opts.homeDir ?? homedir10();
26694
27012
  const runs = db.listRuns();
26695
27013
  const runsWithWorktree = runs.filter((r) => r.worktree_path);
26696
27014
  const bySlug = /* @__PURE__ */ new Map();
@@ -27476,6 +27794,9 @@ async function runDaemon(opts) {
27476
27794
  // Кто мы как машина (TASWM-281) — чтобы отличить ДРУГИЕ машины роя от своей, когда рой
27477
27795
  // советует увезти прогоны туда (TASWM-316).
27478
27796
  selfHostId: host.hostId,
27797
+ selfHostName: host.hostName,
27798
+ // Только email. readGrokAccountEmail не возвращает остальные поля auth.json.
27799
+ grokAccountEmail: () => readGrokAccountEmail(grokAccountAuthPath(process.env)),
27479
27800
  // Состояние градуального контроллера (окна ramp/pause, reliefSince) + журнал цены
27480
27801
  // разгрузки (TASWM-316) — заводим ОДИН раз на цикл демона, tickOnce (manageRelief)
27481
27802
  // мутирует эти же поля каждый тик.