@taskless-app/swarm 0.6.90 → 0.6.92

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/cli.js +145 -107
  2. package/dist/overmind.js +539 -326
  3. package/package.json +2 -2
package/dist/overmind.js CHANGED
@@ -1957,8 +1957,8 @@ function predictFiles(model, opts) {
1957
1957
  }
1958
1958
  const zone = normalizeZoneName(opts.zone) ?? (opts.text ? suggestZonesFromText(model, opts.text)[0]?.zone ?? null : null);
1959
1959
  if (zone) {
1960
- const stat2 = model.zones.find((z2) => z2.zone === zone);
1961
- if (stat2) stat2.files.slice(0, limit).forEach((f, i) => put(f, Math.max(0.12, 0.45 - i * 0.02), `\u0437\u043E\u043D\u0430 ${zone}`));
1960
+ const stat3 = model.zones.find((z2) => z2.zone === zone);
1961
+ if (stat3) stat3.files.slice(0, limit).forEach((f, i) => put(f, Math.max(0.12, 0.45 - i * 0.02), `\u0437\u043E\u043D\u0430 ${zone}`));
1962
1962
  }
1963
1963
  return [...best.values()].sort((a, b) => b.weight - a.weight || a.path.localeCompare(b.path)).slice(0, limit);
1964
1964
  }
@@ -3270,7 +3270,16 @@ function extractModelsBlocks(config) {
3270
3270
  }
3271
3271
  function kimiMcpJson(spec) {
3272
3272
  return JSON.stringify(
3273
- { mcpServers: { [spec.mcp.name]: { command: spec.mcp.command, args: spec.mcp.args, env: spec.mcp.env } } },
3273
+ {
3274
+ mcpServers: {
3275
+ [spec.mcp.name]: {
3276
+ command: spec.mcp.command,
3277
+ args: spec.mcp.args,
3278
+ env: spec.mcp.env,
3279
+ toolTimeoutMs: KIMI_SWARM_TOOL_TIMEOUT_MS
3280
+ }
3281
+ }
3282
+ },
3274
3283
  null,
3275
3284
  2
3276
3285
  );
@@ -3343,13 +3352,14 @@ function parseKimiResult(raw) {
3343
3352
  warning: "kimi: CLI \u0441\u0442\u043E\u0438\u043C\u043E\u0441\u0442\u044C \u043D\u0435 \u0441\u043E\u043E\u0431\u0449\u0430\u0435\u0442 (\u043F\u043E\u0434\u043F\u0438\u0441\u043A\u0430) \u2014 \u044D\u0442\u043E \u043D\u0435 \u043D\u043E\u043B\u044C \u0432 \u0441\u043C\u044B\u0441\u043B\u0435 \u0431\u0435\u0441\u043F\u043B\u0430\u0442\u043D\u043E"
3344
3353
  };
3345
3354
  }
3346
- var kimiExecutor;
3355
+ var KIMI_SWARM_TOOL_TIMEOUT_MS, kimiExecutor;
3347
3356
  var init_kimi = __esm({
3348
3357
  "src/executors/kimi.ts"() {
3349
3358
  "use strict";
3350
3359
  init_src();
3351
3360
  init_swarmHome();
3352
3361
  init_swarmFiles();
3362
+ KIMI_SWARM_TOOL_TIMEOUT_MS = 7 * 24 * 60 * 60 * 1e3;
3353
3363
  kimiExecutor = {
3354
3364
  id: "kimi",
3355
3365
  title: "Kimi Code CLI (kimi)",
@@ -4950,11 +4960,11 @@ function processStartedAt(pid, opts = {}) {
4950
4960
  const platform = opts.platform ?? process.platform;
4951
4961
  if (!Number.isInteger(pid) || pid <= 0 || platform === "win32") return null;
4952
4962
  if (platform === "linux") {
4953
- const readFile2 = opts.readFile ?? ((p) => readFileSync16(p, "utf8"));
4963
+ const readFile3 = opts.readFile ?? ((p) => readFileSync16(p, "utf8"));
4954
4964
  try {
4955
- const stat2 = readFile2(`/proc/${pid}/stat`);
4956
- const ticks = Number(stat2.slice(stat2.lastIndexOf(")") + 1).trim().split(/\s+/)[19]);
4957
- const btime = Number(/^btime\s+(\d+)$/m.exec(readFile2("/proc/stat"))?.[1]);
4965
+ const stat3 = readFile3(`/proc/${pid}/stat`);
4966
+ const ticks = Number(stat3.slice(stat3.lastIndexOf(")") + 1).trim().split(/\s+/)[19]);
4967
+ const btime = Number(/^btime\s+(\d+)$/m.exec(readFile3("/proc/stat"))?.[1]);
4958
4968
  const tck = (opts.clkTck ?? realClkTck)();
4959
4969
  if (!Number.isFinite(ticks) || !Number.isFinite(btime) || !(tck > 0)) return null;
4960
4970
  return Math.round((btime + ticks / tck) * 1e3);
@@ -5446,17 +5456,17 @@ var init_procCleanup = __esm({
5446
5456
  import { existsSync as existsSync14, readdirSync as readdirSync16, realpathSync as realpathSync2, statSync as statSync13 } from "fs";
5447
5457
  import { appendFile, chmod, mkdir, readFile, rename, rm, writeFile } from "fs/promises";
5448
5458
  import { isAbsolute as isAbsolute4, join as join25, resolve as resolve4, sep as sep3 } from "path";
5449
- import { $ as $2 } from "execa";
5459
+ import { $ as $3 } from "execa";
5450
5460
  function gitNet(repo, args, timeoutMs) {
5451
5461
  return withHardTimeout(
5452
- $2({ reject: false, timeout: timeoutMs })`git -C ${repo} ${args}`,
5462
+ $3({ reject: false, timeout: timeoutMs })`git -C ${repo} ${args}`,
5453
5463
  "git",
5454
5464
  gitCallLabel(repo, args),
5455
5465
  timeoutMs
5456
5466
  ).catch(() => null);
5457
5467
  }
5458
5468
  function gitNetStrict(repo, args, timeoutMs) {
5459
- return withHardTimeout($2({ timeout: timeoutMs })`git -C ${repo} ${args}`, "git", gitCallLabel(repo, args), timeoutMs);
5469
+ return withHardTimeout($3({ timeout: timeoutMs })`git -C ${repo} ${args}`, "git", gitCallLabel(repo, args), timeoutMs);
5460
5470
  }
5461
5471
  function isUnrecoverableRefError(e) {
5462
5472
  if (e instanceof MissingRefError) return true;
@@ -5477,7 +5487,7 @@ async function inspectWorktreePath(path) {
5477
5487
  if (statSync13(join25(path, ".git")).isDirectory()) return "main-checkout";
5478
5488
  } catch {
5479
5489
  }
5480
- const top = await $2({ reject: false })`git -C ${path} rev-parse --show-toplevel`;
5490
+ const top = await $3({ reject: false })`git -C ${path} rev-parse --show-toplevel`;
5481
5491
  return top.exitCode === 0 && samePath(top.stdout.trim(), path) ? "worktree" : "orphan";
5482
5492
  }
5483
5493
  function samePath(a, b) {
@@ -5530,7 +5540,7 @@ async function parkOrphanDir(repo, path, branch) {
5530
5540
  console.error(
5531
5541
  `[git] \u043F\u043E \u043F\u0443\u0442\u0438 worktree ${path} \u043B\u0435\u0436\u0430\u043B \u043A\u0430\u0442\u0430\u043B\u043E\u0433, \u043A\u043E\u0442\u043E\u0440\u044B\u0439 git \u0441\u0432\u043E\u0438\u043C \u0440\u0430\u0431\u043E\u0447\u0438\u043C \u0434\u0435\u0440\u0435\u0432\u043E\u043C \u043D\u0435 \u0441\u0447\u0438\u0442\u0430\u0435\u0442 \u2014 \u043E\u0442\u043E\u0434\u0432\u0438\u043D\u0443\u043B \u0432 ${parked}, \u0447\u0442\u043E\u0431\u044B \u0441\u043F\u0430\u0432\u043D ${branch} \u043F\u043E\u0434\u043D\u044F\u043B\u0441\u044F. \u041F\u043E\u0441\u043C\u043E\u0442\u0440\u0438\u0442\u0435, \u0447\u0442\u043E \u0432\u043D\u0443\u0442\u0440\u0438, \u0438 \u0443\u0434\u0430\u043B\u0438\u0442\u0435, \u0435\u0441\u043B\u0438 \u043D\u0435 \u043D\u0443\u0436\u043D\u043E.`
5532
5542
  );
5533
- await $2({ reject: false })`git -C ${repo} worktree prune`;
5543
+ await $3({ reject: false })`git -C ${repo} worktree prune`;
5534
5544
  }
5535
5545
  function isLinkedWorktree(dir) {
5536
5546
  try {
@@ -5540,9 +5550,9 @@ function isLinkedWorktree(dir) {
5540
5550
  }
5541
5551
  }
5542
5552
  async function detachWorktree(repo, worktree) {
5543
- await $2({ reject: false })`git -C ${repo} worktree remove --force ${worktree}`;
5553
+ await $3({ reject: false })`git -C ${repo} worktree remove --force ${worktree}`;
5544
5554
  if (await ensureWorktreeDirGone(worktree)) {
5545
- await $2({ reject: false })`git -C ${repo} worktree prune`;
5555
+ await $3({ reject: false })`git -C ${repo} worktree prune`;
5546
5556
  }
5547
5557
  }
5548
5558
  async function ensureWorktreeDirGone(worktree) {
@@ -5568,9 +5578,9 @@ async function ensureWorktreeDirGone(worktree) {
5568
5578
  }
5569
5579
  async function ensureLongPaths(repo, opts = {}) {
5570
5580
  if ((opts.platform ?? process.platform) !== "win32") return false;
5571
- const cur = (await $2({ reject: false })`git -C ${repo} config --get core.longpaths`).stdout.trim();
5581
+ const cur = (await $3({ reject: false })`git -C ${repo} config --get core.longpaths`).stdout.trim();
5572
5582
  if (cur === "true") return false;
5573
- const res = await $2({ reject: false })`git -C ${repo} config core.longpaths true`;
5583
+ const res = await $3({ reject: false })`git -C ${repo} config core.longpaths true`;
5574
5584
  if (res.exitCode !== 0) {
5575
5585
  console.error(
5576
5586
  `[git] \u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0432\u043A\u043B\u044E\u0447\u0438\u0442\u044C core.longpaths \u0432 ${repo} \u2014 \u043D\u0430 Windows \u0441\u043D\u043E\u0441 worktree \u0434\u0440\u043E\u043D\u0430 \u0431\u0443\u0434\u0435\u0442 \u043F\u0430\u0434\u0430\u0442\u044C \xABFilename too long\xBB \u043D\u0430 node_modules. \u0412\u043A\u043B\u044E\u0447\u0438\u0442\u0435 \u0440\u0443\u043A\u0430\u043C\u0438: \`git -C ${repo} config core.longpaths true\`.`
@@ -5581,10 +5591,10 @@ async function ensureLongPaths(repo, opts = {}) {
5581
5591
  return true;
5582
5592
  }
5583
5593
  async function revParse(repo, ref) {
5584
- return (await $2({ reject: false })`git -C ${repo} rev-parse --verify --quiet ${ref}`).stdout.trim();
5594
+ return (await $3({ reject: false })`git -C ${repo} rev-parse --verify --quiet ${ref}`).stdout.trim();
5585
5595
  }
5586
5596
  async function worktreeForBranch(repo, branch) {
5587
- const out = (await $2`git -C ${repo} worktree list --porcelain`).stdout;
5597
+ const out = (await $3`git -C ${repo} worktree list --porcelain`).stdout;
5588
5598
  const target = `refs/heads/${branch}`;
5589
5599
  let current = null;
5590
5600
  for (const line of out.split("\n")) {
@@ -5605,7 +5615,7 @@ async function checkoutWorktree(repo, path, branch, opts) {
5605
5615
  if (!localSha && !originSha) {
5606
5616
  const freshBase = opts.base ?? await freshWorktreeBase(repo);
5607
5617
  await clearWorktreePath(repo, path, branch, opts);
5608
- await $2`git -C ${repo} worktree add -b ${branch} ${path} ${freshBase}`;
5618
+ await $3`git -C ${repo} worktree add -b ${branch} ${path} ${freshBase}`;
5609
5619
  return { reused: false };
5610
5620
  }
5611
5621
  const busyAt = await worktreeForBranch(repo, branch);
@@ -5619,16 +5629,16 @@ async function checkoutWorktree(repo, path, branch, opts) {
5619
5629
  }
5620
5630
  await clearWorktreePath(repo, path, branch, opts);
5621
5631
  if (originSha) {
5622
- await $2`git -C ${repo} worktree add -B ${branch} ${path} ${`origin/${branch}`}`;
5632
+ await $3`git -C ${repo} worktree add -B ${branch} ${path} ${`origin/${branch}`}`;
5623
5633
  return { reused: true, from: "origin", sha: originSha };
5624
5634
  }
5625
- await $2`git -C ${repo} worktree add ${path} ${branch}`;
5635
+ await $3`git -C ${repo} worktree add ${path} ${branch}`;
5626
5636
  return { reused: true, from: "local" };
5627
5637
  }
5628
5638
  async function freshWorktreeBase(repo) {
5629
- const hasOrigin = (await $2({ reject: false })`git -C ${repo} remote get-url origin`).exitCode === 0;
5639
+ const hasOrigin = (await $3({ reject: false })`git -C ${repo} remote get-url origin`).exitCode === 0;
5630
5640
  if (!hasOrigin) return "HEAD";
5631
- await $2`git -C ${repo} fetch --quiet origin`;
5641
+ await $3`git -C ${repo} fetch --quiet origin`;
5632
5642
  return remoteMainRef(repo);
5633
5643
  }
5634
5644
  function worktreeSourceMessage(branch, res) {
@@ -5638,9 +5648,9 @@ function worktreeSourceMessage(branch, res) {
5638
5648
  }
5639
5649
  async function setWorktreeIdentity(worktree, name) {
5640
5650
  const local = name.toLowerCase().replace(/\s+/g, "-");
5641
- await $2`git -C ${worktree} config extensions.worktreeConfig true`;
5642
- await $2`git -C ${worktree} config --worktree user.name ${`${name} (swarm drone)`}`;
5643
- await $2`git -C ${worktree} config --worktree user.email ${`${local}@drones.swarm.local`}`;
5651
+ await $3`git -C ${worktree} config extensions.worktreeConfig true`;
5652
+ await $3`git -C ${worktree} config --worktree user.name ${`${name} (swarm drone)`}`;
5653
+ await $3`git -C ${worktree} config --worktree user.email ${`${local}@drones.swarm.local`}`;
5644
5654
  }
5645
5655
  async function ensureGitExcluded(worktree, pattern) {
5646
5656
  try {
@@ -5664,7 +5674,7 @@ async function ensureGitExcluded(worktree, pattern) {
5664
5674
  }
5665
5675
  }
5666
5676
  async function gitPath(worktree, flag) {
5667
- const out = await $2({ reject: false })`git -C ${worktree} rev-parse ${flag}`;
5677
+ const out = await $3({ reject: false })`git -C ${worktree} rev-parse ${flag}`;
5668
5678
  const raw = out.stdout.trim();
5669
5679
  if (out.exitCode !== 0 || !raw) return null;
5670
5680
  return isAbsolute4(raw) ? raw : join25(worktree, raw);
@@ -5684,8 +5694,8 @@ async function installGuardHooks(worktree) {
5684
5694
  await writeFile(join25(hooksDir, hook), guardHookScript(hook, prev ? `${posix(prev)}/${hook}` : null));
5685
5695
  await chmod(join25(hooksDir, hook), 493);
5686
5696
  }
5687
- await $2`git -C ${worktree} config extensions.worktreeConfig true`;
5688
- await $2`git -C ${worktree} config --worktree core.hooksPath ${posix(hooksDir)}`;
5697
+ await $3`git -C ${worktree} config extensions.worktreeConfig true`;
5698
+ await $3`git -C ${worktree} config --worktree core.hooksPath ${posix(hooksDir)}`;
5689
5699
  return true;
5690
5700
  } catch {
5691
5701
  return false;
@@ -5696,7 +5706,7 @@ function posix(p) {
5696
5706
  }
5697
5707
  async function previousHooksPath(worktree) {
5698
5708
  for (const scope of ["--local", "--global", "--system"]) {
5699
- const out = await $2({ reject: false })`git -C ${worktree} config ${scope} --get core.hooksPath`;
5709
+ const out = await $3({ reject: false })`git -C ${worktree} config ${scope} --get core.hooksPath`;
5700
5710
  const value = out.stdout.trim();
5701
5711
  if (out.exitCode === 0 && value) return value;
5702
5712
  }
@@ -5704,23 +5714,23 @@ async function previousHooksPath(worktree) {
5704
5714
  return commonDir ? join25(commonDir, "hooks") : null;
5705
5715
  }
5706
5716
  async function removeWorktree(repo, path) {
5707
- const branch = (await $2({ reject: false })`git -C ${path} symbolic-ref --quiet --short HEAD`).stdout.trim();
5717
+ const branch = (await $3({ reject: false })`git -C ${path} symbolic-ref --quiet --short HEAD`).stdout.trim();
5708
5718
  await releaseWorktree(repo, path);
5709
- if (branch) await $2({ reject: false })`git -C ${repo} branch -D ${branch}`;
5719
+ if (branch) await $3({ reject: false })`git -C ${repo} branch -D ${branch}`;
5710
5720
  }
5711
5721
  async function releaseWorktree(repo, path) {
5712
5722
  await cleanupWorktreeProcesses(path);
5713
5723
  await detachWorktree(repo, path);
5714
5724
  }
5715
5725
  async function pruneWorktrees(repo) {
5716
- await $2({ reject: false })`git -C ${repo} worktree prune`;
5726
+ await $3({ reject: false })`git -C ${repo} worktree prune`;
5717
5727
  }
5718
5728
  async function worktreeDirty(path) {
5719
- const st = await $2({ reject: false })`git -C ${path} status --porcelain --untracked-files=all`;
5729
+ const st = await $3({ reject: false })`git -C ${path} status --porcelain --untracked-files=all`;
5720
5730
  if (st.exitCode !== 0) return true;
5721
5731
  const status = st.stdout.trim();
5722
5732
  if (status) return true;
5723
- const unpushed = (await $2({ reject: false })`git -C ${path} rev-list --count HEAD --not --remotes`).stdout.trim();
5733
+ const unpushed = (await $3({ reject: false })`git -C ${path} rev-list --count HEAD --not --remotes`).stdout.trim();
5724
5734
  return unpushed !== "" && unpushed !== "0";
5725
5735
  }
5726
5736
  async function repairMovedWorktrees(targetDir) {
@@ -5733,18 +5743,18 @@ async function repairMovedWorktrees(targetDir) {
5733
5743
  };
5734
5744
  for (const repoDir of subdirs(targetDir)) {
5735
5745
  for (const wt of subdirs(repoDir)) {
5736
- await $2({ reject: false })`git -C ${wt} worktree repair`;
5746
+ await $3({ reject: false })`git -C ${wt} worktree repair`;
5737
5747
  }
5738
5748
  }
5739
5749
  }
5740
5750
  async function repoRoot(cwd) {
5741
- return (await $2`git -C ${cwd} rev-parse --show-toplevel`).stdout.trim();
5751
+ return (await $3`git -C ${cwd} rev-parse --show-toplevel`).stdout.trim();
5742
5752
  }
5743
5753
  async function remoteMainRef(repo) {
5744
- const head = (await $2({ reject: false })`git -C ${repo} symbolic-ref --quiet --short refs/remotes/origin/HEAD`).stdout.trim();
5754
+ const head = (await $3({ reject: false })`git -C ${repo} symbolic-ref --quiet --short refs/remotes/origin/HEAD`).stdout.trim();
5745
5755
  if (head) return head;
5746
5756
  for (const cand of ["origin/main", "origin/master"]) {
5747
- const ok = await $2({ reject: false })`git -C ${repo} rev-parse --verify --quiet ${cand}`;
5757
+ const ok = await $3({ reject: false })`git -C ${repo} rev-parse --verify --quiet ${cand}`;
5748
5758
  if (ok.exitCode === 0) return cand;
5749
5759
  }
5750
5760
  throw new Error(`\u043D\u0435 \u043D\u0430\u0448\u0451\u043B \u0434\u0435\u0444\u043E\u043B\u0442-\u0432\u0435\u0442\u043A\u0443 origin \u0432 ${repo} (\u043D\u0435\u0442 origin/HEAD, origin/main, origin/master)`);
@@ -5766,7 +5776,7 @@ async function remoteRepoFullName(repo, timeoutMs = GIT_LOCAL_TIMEOUT_MS) {
5766
5776
  }
5767
5777
  async function journalForBranch(repo, branch, slug) {
5768
5778
  await gitNet(repo, ["fetch", "--quiet", "origin", branch], GIT_NET_TIMEOUT_MS);
5769
- const out = await $2({ reject: false })`git -C ${repo} show ${`origin/${branch}:journal/${slug}.md`}`;
5779
+ const out = await $3({ reject: false })`git -C ${repo} show ${`origin/${branch}:journal/${slug}.md`}`;
5770
5780
  return out.exitCode === 0 && out.stdout ? out.stdout : null;
5771
5781
  }
5772
5782
  async function prepareDetachedWorktree(repo, branch, worktree, opts = {}) {
@@ -5774,17 +5784,17 @@ async function prepareDetachedWorktree(repo, branch, worktree, opts = {}) {
5774
5784
  const ref = `origin/${branch}`;
5775
5785
  if (!await revParse(repo, `${ref}^{commit}`)) throw new MissingRefError(ref, repo);
5776
5786
  await clearWorktreePath(repo, worktree, branch, opts);
5777
- await $2`git -C ${repo} worktree add --detach --force ${worktree} ${ref}`;
5787
+ await $3`git -C ${repo} worktree add --detach --force ${worktree} ${ref}`;
5778
5788
  await ensureWorktreeHygiene(worktree);
5779
5789
  }
5780
5790
  async function mergeRef(worktree, ref) {
5781
- const before = (await $2`git -C ${worktree} rev-parse HEAD`).stdout.trim();
5782
- const merge = await $2({ reject: false })`git -C ${worktree} merge --no-edit ${ref}`;
5791
+ const before = (await $3`git -C ${worktree} rev-parse HEAD`).stdout.trim();
5792
+ const merge = await $3({ reject: false })`git -C ${worktree} merge --no-edit ${ref}`;
5783
5793
  if (merge.exitCode === 0) {
5784
- const after = (await $2`git -C ${worktree} rev-parse HEAD`).stdout.trim();
5794
+ const after = (await $3`git -C ${worktree} rev-parse HEAD`).stdout.trim();
5785
5795
  return { clean: true, conflicts: [], changed: after !== before };
5786
5796
  }
5787
- const u = (await $2({ reject: false })`git -C ${worktree} diff --name-only --diff-filter=U`).stdout.trim();
5797
+ const u = (await $3({ reject: false })`git -C ${worktree} diff --name-only --diff-filter=U`).stdout.trim();
5788
5798
  return { clean: false, conflicts: u ? u.split("\n") : [], changed: false };
5789
5799
  }
5790
5800
  async function pushHeadTo(worktree, branch) {
@@ -5792,10 +5802,10 @@ async function pushHeadTo(worktree, branch) {
5792
5802
  }
5793
5803
  async function snapshotWorktree(worktree, message) {
5794
5804
  try {
5795
- const status = (await $2({ reject: false })`git -C ${worktree} status --porcelain`).stdout.trim();
5805
+ const status = (await $3({ reject: false })`git -C ${worktree} status --porcelain`).stdout.trim();
5796
5806
  if (!status) return false;
5797
- await $2({ reject: false })`git -C ${worktree} add -A`;
5798
- const commit = await $2({ reject: false })`git -C ${worktree} commit --no-verify -m ${message}`;
5807
+ await $3({ reject: false })`git -C ${worktree} add -A`;
5808
+ const commit = await $3({ reject: false })`git -C ${worktree} commit --no-verify -m ${message}`;
5799
5809
  if (commit.exitCode !== 0) return false;
5800
5810
  await gitNet(worktree, ["push"], GIT_NET_TIMEOUT_MS);
5801
5811
  return true;
@@ -5804,7 +5814,7 @@ async function snapshotWorktree(worktree, message) {
5804
5814
  }
5805
5815
  }
5806
5816
  async function worktreeLastCommitMs(worktree) {
5807
- const out = (await $2({ reject: false })`git -C ${worktree} log -1 --format=%ct HEAD`).stdout.trim();
5817
+ const out = (await $3({ reject: false })`git -C ${worktree} log -1 --format=%ct HEAD`).stdout.trim();
5808
5818
  const sec = Number(out);
5809
5819
  return Number.isInteger(sec) && sec > 0 ? sec * 1e3 : null;
5810
5820
  }
@@ -6263,8 +6273,8 @@ var init_droneChannel = __esm({
6263
6273
  });
6264
6274
 
6265
6275
  // src/attachments.ts
6266
- import { mkdir as mkdir3, rm as rm3, writeFile as writeFile3 } from "fs/promises";
6267
- import { join as join30 } from "path";
6276
+ import { mkdir as mkdir3, readFile as readFile2, readdir as readdir2, stat as stat2, unlink, writeFile as writeFile3 } from "fs/promises";
6277
+ import { extname, join as join30 } from "path";
6268
6278
  function attachmentsFromDoc(doc, origin) {
6269
6279
  const out = [];
6270
6280
  const walk2 = (node) => {
@@ -6348,16 +6358,24 @@ async function materializeAttachments(opts) {
6348
6358
  const maxFiles = opts.maxFiles ?? ATTACH_MAX_FILES;
6349
6359
  const maxTotal = opts.maxTotalBytes ?? ATTACH_MAX_TOTAL_BYTES;
6350
6360
  const maxFile = opts.maxFileBytes ?? ATTACH_MAX_FILE_BYTES;
6361
+ const retryDelaysMs = opts.retryDelaysMs ?? [1e3, 3e3];
6351
6362
  const io = opts.io ?? {
6352
- removeDir: async (dir2) => rm3(dir2, { recursive: true, force: true }),
6363
+ listFiles: listAttachmentFiles,
6353
6364
  mkdir: async (dir2) => void await mkdir3(dir2, { recursive: true }),
6354
- writeFile: async (path, bytes) => writeFile3(path, bytes)
6365
+ readFile: async (path) => readFile2(path),
6366
+ writeFile: async (path, bytes) => writeFile3(path, bytes),
6367
+ removeFile: async (path) => unlink(path).catch((e) => {
6368
+ if (e.code !== "ENOENT") throw e;
6369
+ })
6355
6370
  };
6356
6371
  const result = { files: [], skipped: [] };
6357
6372
  if (opts.refs.length === 0) return result;
6358
6373
  const dir = join30(opts.worktree, ATTACHMENTS_DIR);
6359
- await io.removeDir(dir);
6360
- let dirReady = false;
6374
+ const existing = (await io.listFiles(dir)).filter((file) => file.name !== ".index.json");
6375
+ const previousIndex = await readAttachmentIndex(dir, io.readFile);
6376
+ const nextIndex = {};
6377
+ const downloads = [];
6378
+ const downloadFailures = [];
6361
6379
  let total = 0;
6362
6380
  let index = 0;
6363
6381
  for (const ref of opts.refs) {
@@ -6377,14 +6395,38 @@ async function materializeAttachments(opts) {
6377
6395
  continue;
6378
6396
  }
6379
6397
  let file = null;
6380
- try {
6381
- file = await opts.fetchFile(ref.url);
6382
- } catch (e) {
6383
- result.skipped.push(`${label2} \u2014 \u043D\u0435 \u0441\u043A\u0430\u0447\u0430\u043B\u043E\u0441\u044C (${errText2(e)})`);
6384
- continue;
6398
+ let failureReason = "\u043D\u0435\u0442 \u0434\u043E\u0441\u0442\u0443\u043F\u0430 \u0438\u043B\u0438 \u0444\u0430\u0439\u043B \u0443\u0434\u0430\u043B\u0451\u043D";
6399
+ for (let attempt = 0; ; attempt++) {
6400
+ try {
6401
+ file = await opts.fetchFile(ref.url);
6402
+ if (!file) failureReason = "\u043D\u0435\u0442 \u0434\u043E\u0441\u0442\u0443\u043F\u0430 \u0438\u043B\u0438 \u0444\u0430\u0439\u043B \u0443\u0434\u0430\u043B\u0451\u043D";
6403
+ break;
6404
+ } catch (e) {
6405
+ failureReason = errText2(e);
6406
+ if (attempt >= retryDelaysMs.length || e instanceof Error && e.name === "TimeoutError") break;
6407
+ await new Promise((resolve6) => setTimeout(resolve6, retryDelaysMs[attempt]));
6408
+ }
6385
6409
  }
6386
6410
  if (!file) {
6387
- result.skipped.push(`${label2} \u2014 \u043D\u0435 \u0441\u043A\u0430\u0447\u0430\u043B\u043E\u0441\u044C (\u043D\u0435\u0442 \u0434\u043E\u0441\u0442\u0443\u043F\u0430 \u0438\u043B\u0438 \u0444\u0430\u0439\u043B \u0443\u0434\u0430\u043B\u0451\u043D)`);
6411
+ const stem = attachmentFileName(index, ref.caption, "").replace(/\.$/, "");
6412
+ const previous = existing.find(
6413
+ (candidate) => candidate.name.startsWith(`${stem}.`) && previousIndex[candidate.name] === ref.url
6414
+ );
6415
+ if (previous && previous.bytes <= maxFile && total + previous.bytes <= maxTotal) {
6416
+ total += previous.bytes;
6417
+ nextIndex[previous.name] = ref.url;
6418
+ result.files.push({
6419
+ path: `${ATTACHMENTS_DIR}/${previous.name}`,
6420
+ caption: ref.caption,
6421
+ origin: ref.origin,
6422
+ bytes: previous.bytes,
6423
+ previousCopyReason: failureReason
6424
+ });
6425
+ downloadFailures.push({ label: label2, reason: failureReason, previousCopy: true });
6426
+ } else {
6427
+ result.skipped.push(`${label2} \u2014 \u043D\u0435 \u0441\u043A\u0430\u0447\u0430\u043B\u043E\u0441\u044C (${failureReason})`);
6428
+ downloadFailures.push({ label: label2, reason: failureReason, previousCopy: false });
6429
+ }
6388
6430
  continue;
6389
6431
  }
6390
6432
  if (file.bytes.byteLength > maxFile) {
@@ -6396,6 +6438,19 @@ async function materializeAttachments(opts) {
6396
6438
  continue;
6397
6439
  }
6398
6440
  const name = attachmentFileName(index, ref.caption, attachmentExt(ref, file.contentType));
6441
+ downloads.push({ name, file, label: label2 });
6442
+ nextIndex[name] = ref.url;
6443
+ total += file.bytes.byteLength;
6444
+ result.files.push({
6445
+ path: `${ATTACHMENTS_DIR}/${name}`,
6446
+ caption: ref.caption,
6447
+ origin: ref.origin,
6448
+ bytes: file.bytes.byteLength
6449
+ });
6450
+ }
6451
+ let dirReady = false;
6452
+ const failedWrites = /* @__PURE__ */ new Set();
6453
+ for (const { name, file, label: label2 } of downloads) {
6399
6454
  try {
6400
6455
  if (!dirReady) {
6401
6456
  await io.mkdir(dir);
@@ -6403,19 +6458,66 @@ async function materializeAttachments(opts) {
6403
6458
  }
6404
6459
  await io.writeFile(join30(dir, name), file.bytes);
6405
6460
  } catch (e) {
6406
- result.skipped.push(`${label2} \u2014 \u043D\u0435 \u0437\u0430\u043F\u0438\u0441\u0430\u043B\u043E\u0441\u044C \u043D\u0430 \u0434\u0438\u0441\u043A (${errText2(e)})`);
6407
- continue;
6461
+ const reason = `\u043D\u0435 \u0437\u0430\u043F\u0438\u0441\u0430\u043B\u043E\u0441\u044C \u043D\u0430 \u0434\u0438\u0441\u043A (${errText2(e)})`;
6462
+ const stem = name.slice(0, name.length - extname(name).length);
6463
+ const url = nextIndex[name];
6464
+ const previous = existing.find(
6465
+ (candidate) => candidate.name.startsWith(`${stem}.`) && previousIndex[candidate.name] === url
6466
+ );
6467
+ const entry = result.files.find((f) => f.path === `${ATTACHMENTS_DIR}/${name}`);
6468
+ delete nextIndex[name];
6469
+ if (previous && entry) {
6470
+ nextIndex[previous.name] = url;
6471
+ Object.assign(entry, { path: `${ATTACHMENTS_DIR}/${previous.name}`, bytes: previous.bytes, previousCopyReason: reason });
6472
+ } else {
6473
+ failedWrites.add(name);
6474
+ result.skipped.push(`${label2} \u2014 ${reason}`);
6475
+ }
6408
6476
  }
6409
- total += file.bytes.byteLength;
6410
- result.files.push({
6411
- path: `${ATTACHMENTS_DIR}/${name}`,
6412
- caption: ref.caption,
6413
- origin: ref.origin,
6414
- bytes: file.bytes.byteLength
6415
- });
6416
6477
  }
6478
+ if (failedWrites.size > 0) {
6479
+ result.files = result.files.filter((f) => !failedWrites.has(f.path.split("/").pop()));
6480
+ }
6481
+ const wanted = new Set(result.files.map((f) => f.path.split("/").pop()));
6482
+ for (const old of existing) {
6483
+ if (!wanted.has(old.name)) await io.removeFile(join30(dir, old.name));
6484
+ }
6485
+ if (result.files.length > 0 && JSON.stringify(nextIndex) !== JSON.stringify(previousIndex)) {
6486
+ try {
6487
+ if (!dirReady) {
6488
+ await io.mkdir(dir);
6489
+ dirReady = true;
6490
+ }
6491
+ await io.writeFile(join30(dir, ".index.json"), new TextEncoder().encode(JSON.stringify(nextIndex)));
6492
+ } catch {
6493
+ }
6494
+ }
6495
+ if (downloadFailures.length > 0) result.downloadFailures = downloadFailures;
6417
6496
  return result;
6418
6497
  }
6498
+ async function readAttachmentIndex(dir, read) {
6499
+ if (!read) return {};
6500
+ try {
6501
+ const parsed = JSON.parse(new TextDecoder().decode(await read(join30(dir, ".index.json"))));
6502
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return {};
6503
+ const entries = Object.entries(parsed);
6504
+ if (entries.some(([, url]) => typeof url !== "string")) return {};
6505
+ return Object.fromEntries(entries);
6506
+ } catch {
6507
+ return {};
6508
+ }
6509
+ }
6510
+ async function listAttachmentFiles(dir) {
6511
+ try {
6512
+ const entries = await readdir2(dir, { withFileTypes: true });
6513
+ return await Promise.all(
6514
+ entries.filter((entry) => entry.isFile() && entry.name !== ".index.json").map(async (entry) => ({ name: entry.name, bytes: (await stat2(join30(dir, entry.name))).size }))
6515
+ );
6516
+ } catch (e) {
6517
+ if (e.code === "ENOENT") return [];
6518
+ throw e;
6519
+ }
6520
+ }
6419
6521
  function renderAttachmentsBlock(result) {
6420
6522
  if (result.files.length === 0 && result.skipped.length === 0) return void 0;
6421
6523
  const lines = [];
@@ -6426,7 +6528,7 @@ function renderAttachmentsBlock(result) {
6426
6528
  "\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",
6427
6529
  "\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.",
6428
6530
  ...result.files.map(
6429
- (f) => `- ${f.path}${f.caption ? ` \u2014 \xAB${oneLine(f.caption)}\xBB` : ""} [${oneLine(f.origin)}, ${mb(f.bytes)}]`
6531
+ (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)})` : "")
6430
6532
  ),
6431
6533
  "\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."
6432
6534
  );
@@ -6451,13 +6553,15 @@ async function prepareTaskAttachments(opts) {
6451
6553
  await exclude(opts.worktree, `/${SWARM_TASK_DIR}/`);
6452
6554
  }
6453
6555
  if (result.files.length > 0 || result.skipped.length > 0) {
6454
- opts.onEvent?.(
6455
- `\u0432\u043B\u043E\u0436\u0435\u043D\u0438\u044F \u0437\u0430\u0434\u0430\u0447\u0438: \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)` : "")
6556
+ const failures = result.downloadFailures ?? [];
6557
+ 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}; ` : "";
6558
+ await opts.onEvent?.(
6559
+ `\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)` : "")
6456
6560
  );
6457
6561
  }
6458
6562
  return renderAttachmentsBlock(result);
6459
6563
  } catch (e) {
6460
- opts.onEvent?.(`\u0432\u043B\u043E\u0436\u0435\u043D\u0438\u044F \u0437\u0430\u0434\u0430\u0447\u0438 \u0432\u044B\u043B\u043E\u0436\u0438\u0442\u044C \u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C: ${errText2(e)} \u2014 \u0434\u0440\u043E\u043D \u0441\u0442\u0430\u0440\u0442\u0443\u0435\u0442 \u0431\u0435\u0437 \u043D\u0438\u0445`);
6564
+ await opts.onEvent?.(`\u0432\u043B\u043E\u0436\u0435\u043D\u0438\u044F \u0437\u0430\u0434\u0430\u0447\u0438 \u0432\u044B\u043B\u043E\u0436\u0438\u0442\u044C \u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C: ${errText2(e)} \u2014 \u0434\u0440\u043E\u043D \u0441\u0442\u0430\u0440\u0442\u0443\u0435\u0442 \u0431\u0435\u0437 \u043D\u0438\u0445`);
6461
6565
  return void 0;
6462
6566
  }
6463
6567
  }
@@ -7623,6 +7727,9 @@ function rowToRun(row) {
7623
7727
  // старые прогоны без колонки → 0 (обычный приоритет)
7624
7728
  base_branch: row.base_branch ?? null,
7625
7729
  // базовая ветка PR (TASWM-285); null → дефолтная
7730
+ // TASWM-656: группа параллельной работы. Демон её в прод не пишет; в sqlite
7731
+ // колонка нужна, чтобы зеркало и запасной замок зоны её видели. Нет колонки → null.
7732
+ parallel_group: row.parallel_group ?? null,
7626
7733
  workspace_id: row.workspace_id ?? null,
7627
7734
  // воркспейс задачи прогона (TASWM-288); null → глобальный пин
7628
7735
  // TASWM-597: repoless-прогон (офлайн-проект, без worktree/PR). null/0 → код-конвейер.
@@ -7697,6 +7804,7 @@ CREATE TABLE IF NOT EXISTS runs (
7697
7804
  task_url TEXT,
7698
7805
  priority INTEGER NOT NULL DEFAULT 0,
7699
7806
  base_branch TEXT,
7807
+ parallel_group TEXT,
7700
7808
  workspace_id TEXT,
7701
7809
  repoless INTEGER,
7702
7810
  created_at TEXT NOT NULL DEFAULT (datetime('now')),
@@ -7794,6 +7902,8 @@ CREATE TABLE IF NOT EXISTS imports (
7794
7902
  "ALTER TABLE runs ADD COLUMN priority INTEGER NOT NULL DEFAULT 0",
7795
7903
  // Базовая ветка PR (TASWM-285): куда дрон открывает PR и от чего ответвляется.
7796
7904
  "ALTER TABLE runs ADD COLUMN base_branch TEXT",
7905
+ // TASWM-656: группа параллельной работы. NULL — гейт как раньше.
7906
+ "ALTER TABLE runs ADD COLUMN parallel_group TEXT",
7797
7907
  // Воркспейс задачи прогона (TASWM-288): им пинятся задачные MCP-вызовы прогона.
7798
7908
  "ALTER TABLE runs ADD COLUMN workspace_id TEXT",
7799
7909
  // TASWM-597: repoless-прогон — задача офлайн-проекта, спавн без worktree/ветки/PR.
@@ -8140,10 +8250,16 @@ CREATE TABLE IF NOT EXISTS imports (
8140
8250
  * С repo — только в этом репозитории (одна area в разных репо не конфликтует).
8141
8251
  * Без repo — по всему рою (обратная совместимость).
8142
8252
  */
8143
- runningAreas(repo) {
8144
- const base3 = "SELECT DISTINCT area FROM runs WHERE status IN ('running','blocked') AND area IS NOT NULL";
8145
- const rows = repo === void 0 ? this.db.prepare(base3).all() : this.db.prepare(`${base3} AND repo = ?`).all(repo);
8146
- return rows.map((r) => normalizeZoneLabel(r.area)).filter((a) => a.length > 0);
8253
+ runningAreas(repo, exceptGroup) {
8254
+ const base3 = "SELECT r.area AS area, COALESCE(NULLIF(r.parallel_group, ''), p.parallel_group) AS parallel_group FROM runs r LEFT JOIN runs p ON p.id = r.resolves_run_id WHERE r.status IN ('running','blocked') AND r.area IS NOT NULL";
8255
+ const rows = repo === void 0 ? this.db.prepare(base3).all() : this.db.prepare(`${base3} AND r.repo = ?`).all(repo);
8256
+ const seen = /* @__PURE__ */ new Set();
8257
+ for (const r of rows) {
8258
+ if (exceptGroup && r.parallel_group === exceptGroup) continue;
8259
+ const zone = normalizeZoneLabel(r.area);
8260
+ if (zone) seen.add(zone);
8261
+ }
8262
+ return [...seen];
8147
8263
  }
8148
8264
  /**
8149
8265
  * Из depends_on прогона — слаги зависимостей, ещё НЕ исчерпанных. Пусто → все выполнены,
@@ -8642,11 +8758,11 @@ function pauseStatePath(home) {
8642
8758
  var ACTIVE = { paused: false, at: "", source: "cli" };
8643
8759
  function loadPauseState(home, io = {}) {
8644
8760
  const exists = io.exists ?? existsSync;
8645
- const readFile2 = io.readFile ?? ((p) => readFileSync(p, "utf8"));
8761
+ const readFile3 = io.readFile ?? ((p) => readFileSync(p, "utf8"));
8646
8762
  const path = pauseStatePath(home);
8647
8763
  if (!exists(path)) return ACTIVE;
8648
8764
  try {
8649
- const parsed = JSON.parse(readFile2(path));
8765
+ const parsed = JSON.parse(readFile3(path));
8650
8766
  if (parsed.paused !== true) return ACTIVE;
8651
8767
  return {
8652
8768
  paused: true,
@@ -8755,6 +8871,209 @@ function renderPendingRulesBlock(rules) {
8755
8871
  // src/swarmClient.ts
8756
8872
  init_slugRetry();
8757
8873
  init_zoneNotes();
8874
+
8875
+ // src/zones.ts
8876
+ init_src();
8877
+
8878
+ // src/gitHistory.ts
8879
+ import { $ } from "execa";
8880
+ var REC = "";
8881
+ var FIELD = "";
8882
+ var LOG_FORMAT = `${REC}%H${FIELD}%s`;
8883
+ var SLUG_IN_SUBJECT = /\b([A-Z][A-Z0-9]{0,7}-\d+)\b/;
8884
+ function slugFromSubject(subject) {
8885
+ return SLUG_IN_SUBJECT.exec(subject)?.[1] ?? null;
8886
+ }
8887
+ function unquotePath(raw) {
8888
+ const p = raw.trim();
8889
+ return p.length >= 2 && p.startsWith('"') && p.endsWith('"') ? p.slice(1, -1) : p;
8890
+ }
8891
+ function parseGitLog(out) {
8892
+ const commits = [];
8893
+ for (const chunk of out.split(REC)) {
8894
+ if (!chunk.trim()) continue;
8895
+ const [head, ...rest] = chunk.split("\n");
8896
+ const [sha, subject] = (head ?? "").split(FIELD);
8897
+ if (!sha) continue;
8898
+ const files = rest.map(unquotePath).filter(Boolean);
8899
+ commits.push({ sha, subject: subject ?? "", files });
8900
+ }
8901
+ return commits;
8902
+ }
8903
+ var NOISE_RE = /^(journal\/|changelog\/|docs\/|design\/|scratch\/|\.claude\/|.*\.lock$|pnpm-lock\.yaml$)/;
8904
+ function isNoisePath(path) {
8905
+ return NOISE_RE.test(path);
8906
+ }
8907
+ var GROUP_DEFAULTS = { maxFilesPerCommit: 120, ignore: isNoisePath };
8908
+ function groupTaskHistory(commits, opts = {}) {
8909
+ const o = { ...GROUP_DEFAULTS, ...opts };
8910
+ const bySlug = /* @__PURE__ */ new Map();
8911
+ for (const c of commits) {
8912
+ const slug = slugFromSubject(c.subject);
8913
+ if (!slug) continue;
8914
+ if (c.files.length > o.maxFilesPerCommit) continue;
8915
+ const files = c.files.filter((f) => !o.ignore(f));
8916
+ if (!files.length) continue;
8917
+ let acc = bySlug.get(slug);
8918
+ if (!acc) bySlug.set(slug, acc = { files: /* @__PURE__ */ new Set(), texts: [] });
8919
+ for (const f of files) acc.files.add(f);
8920
+ acc.texts.push(c.subject);
8921
+ }
8922
+ return [...bySlug.entries()].map(([slug, acc]) => ({
8923
+ slug,
8924
+ files: [...acc.files],
8925
+ text: acc.texts.join(" \xB7 ")
8926
+ }));
8927
+ }
8928
+ async function readCommitLog(repo, opts = {}) {
8929
+ const max = opts.maxCommits ?? 1500;
8930
+ try {
8931
+ const { stdout } = await $({ cwd: repo, reject: false })`git log --no-merges --name-only --pretty=format:${LOG_FORMAT} -n ${String(max)} ${opts.ref ?? "HEAD"}`;
8932
+ return parseGitLog(stdout ?? "");
8933
+ } catch {
8934
+ return [];
8935
+ }
8936
+ }
8937
+ async function readTaskHistory(repo, opts = {}) {
8938
+ return groupTaskHistory(await readCommitLog(repo, opts), opts);
8939
+ }
8940
+ async function headSha(repo) {
8941
+ try {
8942
+ const { stdout, exitCode } = await $({ cwd: repo, reject: false })`git rev-parse HEAD`;
8943
+ return exitCode === 0 ? stdout.trim() : null;
8944
+ } catch {
8945
+ return null;
8946
+ }
8947
+ }
8948
+
8949
+ // src/zones.ts
8950
+ function runText(run2) {
8951
+ return [run2.task_title ?? "", run2.task_desc ?? ""].join(" ").trim();
8952
+ }
8953
+ function predictForRun(model, run2, fileExists) {
8954
+ return predictFiles(model, { zone: run2.area, text: runText(run2), ...fileExists ? { fileExists } : {} });
8955
+ }
8956
+ function effectiveGroup(r, getRun) {
8957
+ if (r.parallel_group) return r.parallel_group;
8958
+ if (r.resolves_run_id == null) return null;
8959
+ return getRun(r.resolves_run_id)?.parallel_group || null;
8960
+ }
8961
+ function clearWith(alongside) {
8962
+ return alongside.length ? { kind: "clear", alongside } : { kind: "clear" };
8963
+ }
8964
+ function short(files, n = 3) {
8965
+ return files.slice(0, n).join(", ") + (files.length > n ? ` \u0438 \u0435\u0449\u0451 ${files.length - n}` : "");
8966
+ }
8967
+ function heldBecause(w) {
8968
+ const parts = [];
8969
+ if (w.prUrl) parts.push(`\u0440\u0430\u0431\u043E\u0442\u0430 \u0441\u0434\u0430\u043D\u0430, PR \u0435\u0449\u0451 \u043D\u0435 \u0432\u043B\u0438\u0442: ${w.prUrl}`);
8970
+ if (!w.actual) parts.push(w.prUrl ? "\u0444\u0430\u0439\u043B\u044B \u0432\u0437\u044F\u0442\u044B \u043F\u043E \u043F\u0440\u0435\u0434\u0441\u043A\u0430\u0437\u0430\u043D\u0438\u044E \u2014 \u0441\u043D\u0438\u043C\u043A\u0430 \u043D\u0435 \u043E\u0441\u0442\u0430\u043B\u043E\u0441\u044C" : "\u043F\u043E \u043F\u0440\u0435\u0434\u0441\u043A\u0430\u0437\u0430\u043D\u0438\u044E \u2014 \u0434\u0440\u043E\u043D \u0435\u0449\u0451 \u043D\u0435 \u043D\u0430\u0447\u0430\u043B \u043F\u0438\u0441\u0430\u0442\u044C \u043A\u043E\u0434");
8971
+ return parts.length ? ` (${parts.join("; ")})` : "";
8972
+ }
8973
+ var SPINE_PREDICTION_WEIGHT = 0.7;
8974
+ function spineOfPrediction(spine, predicted) {
8975
+ return predicted.filter((p) => spine.has(p.path) && p.weight >= SPINE_PREDICTION_WEIGHT).map((p) => p.path);
8976
+ }
8977
+ function decideConflict({ model, candidate, active, fileExists }) {
8978
+ if ((candidate.kind ?? "drone") !== "drone") return { kind: "clear" };
8979
+ const group = candidate.parallel_group || null;
8980
+ const alongside = group ? active.filter((w) => w.run.parallel_group === group).map((w) => w.run) : [];
8981
+ const others = group ? active.filter((w) => w.run.parallel_group !== group) : active;
8982
+ if (!hasZoneModel(model)) return { kind: "unknown" };
8983
+ const predicted = predictForRun(model, candidate, fileExists);
8984
+ if (!predicted.length) return { kind: "unknown" };
8985
+ if (!others.length) return clearWith(alongside);
8986
+ const spine = new Set(model.spine);
8987
+ const candidateSpine = new Set(spineOfPrediction(spine, predicted));
8988
+ if (candidateSpine.size) {
8989
+ for (const w of others) {
8990
+ const theirSpine = w.actual ? w.files.filter((f) => spine.has(f)) : spineOfPrediction(spine, predictForRun(model, w.run, fileExists));
8991
+ const shared = theirSpine.filter((f) => candidateSpine.has(f));
8992
+ if (!shared.length) continue;
8993
+ return {
8994
+ kind: "wait",
8995
+ blockedBy: w.run,
8996
+ message: `\u044D\u0442\u0438 \u0434\u0432\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0442\u0440\u043E\u0433\u0430\u044E\u0442 \u043E\u0434\u043D\u0438 \u0444\u0430\u0439\u043B\u044B \u043E\u0431\u0449\u0435\u0433\u043E \u0445\u0440\u0435\u0431\u0442\u0430 (${short(shared)}) \u2014 \u0442\u0430\u043A\u0438\u0435 \u0438\u0434\u0443\u0442 \u043F\u043E\u0441\u043B\u0435\u0434\u043E\u0432\u0430\u0442\u0435\u043B\u044C\u043D\u043E \u043D\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043C\u043E \u043E\u0442 \u0437\u043E\u043D\u044B: \u0436\u0434\u0443 ${w.run.task_slug} (#${w.run.id})` + heldBecause(w)
8997
+ };
8998
+ }
8999
+ }
9000
+ for (const w of others) {
9001
+ const risk = overlapRisk(predicted, w.files);
9002
+ if (!risk.overlap) continue;
9003
+ const what = risk.sharedFiles.length ? `\u043E\u0434\u043D\u0438 \u0444\u0430\u0439\u043B\u044B (${short(risk.sharedFiles)})` : `\u043E\u0434\u0438\u043D \u043A\u0430\u0442\u0430\u043B\u043E\u0433 (${short(risk.sharedDirs)})`;
9004
+ return {
9005
+ kind: "wait",
9006
+ blockedBy: w.run,
9007
+ message: `\u044D\u0442\u0438 \u0434\u0432\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0442\u0440\u043E\u0433\u0430\u044E\u0442 ${what} \u2014 \u0441\u0442\u0430\u0432\u0438\u043C \u043F\u043E\u0441\u043B\u0435\u0434\u043E\u0432\u0430\u0442\u0435\u043B\u044C\u043D\u043E: \u0436\u0434\u0443 ${w.run.task_slug} (#${w.run.id})` + heldBecause(w)
9008
+ };
9009
+ }
9010
+ return clearWith(alongside);
9011
+ }
9012
+ function suggestAreaForRun(model, run2) {
9013
+ if (!hasZoneModel(model)) return null;
9014
+ const text = runText(run2);
9015
+ if (!text) return null;
9016
+ const top = suggestZonesFromText(model, text)[0];
9017
+ return top && top.confidence >= 0.3 ? { zone: top.zone, confidence: top.confidence, why: top.why } : null;
9018
+ }
9019
+ var DEFAULT_TTL_MS = 10 * 6e4;
9020
+ var ZoneModels = class {
9021
+ constructor(opts = {}) {
9022
+ this.opts = opts;
9023
+ }
9024
+ opts;
9025
+ cache = /* @__PURE__ */ new Map();
9026
+ /** Модель репо. Истории нет / это не git — EMPTY_ZONE_MODEL (раздача на старом локе). */
9027
+ async forRepo(repo, now = Date.now()) {
9028
+ if (!repo) return EMPTY_ZONE_MODEL;
9029
+ const head = await headSha(repo);
9030
+ const hit = this.cache.get(repo);
9031
+ if (hit && hit.head === head && now - hit.builtAt < (this.opts.ttlMs ?? DEFAULT_TTL_MS)) return hit.model;
9032
+ const model = await this.build(repo);
9033
+ this.cache.set(repo, { head, builtAt: now, model });
9034
+ return model;
9035
+ }
9036
+ /** Сбросить кэш (тесты, `swarm zones --refresh`). */
9037
+ clear() {
9038
+ this.cache.clear();
9039
+ }
9040
+ async build(repo) {
9041
+ const history = await readTaskHistory(repo, { ...this.opts.maxCommits ? { maxCommits: this.opts.maxCommits } : {} });
9042
+ return buildZoneModel(withManualAreas(history, this.opts.manualAreas?.() ?? /* @__PURE__ */ new Map()));
9043
+ }
9044
+ };
9045
+ var ActiveFilesCache = class {
9046
+ constructor(read, ttlMs = 3e4) {
9047
+ this.read = read;
9048
+ this.ttlMs = ttlMs;
9049
+ }
9050
+ read;
9051
+ ttlMs;
9052
+ cache = /* @__PURE__ */ new Map();
9053
+ async filesOf(run2, now = Date.now()) {
9054
+ const hit = this.cache.get(run2.id);
9055
+ if (hit && now - hit.at < this.ttlMs) return hit.files;
9056
+ const files = await this.read(run2);
9057
+ this.cache.set(run2.id, { at: now, files });
9058
+ return files;
9059
+ }
9060
+ /**
9061
+ * Забыть всех, кто больше НЕ ДЕРЖИТ файлы. Раньше здесь стоял список ЖИВЫХ дронов и
9062
+ * комментарий «дрон закончил — его файлы больше не заняты»; это и была дырка TASWM-506:
9063
+ * дрон заканчивал, открывал PR, PR висел непомерженным — а строки уже считались
9064
+ * свободными. Держатель теперь переживает своего дрона и уходит из кэша на мерже
9065
+ * (прогон выходит из `review`), см. holdsFiles.
9066
+ */
9067
+ prune(holderIds) {
9068
+ const holders = new Set(holderIds);
9069
+ for (const id of [...this.cache.keys()]) if (!holders.has(id)) this.cache.delete(id);
9070
+ }
9071
+ };
9072
+ function withManualAreas(history, areas) {
9073
+ return history.map((e) => ({ ...e, area: normalizeZoneName(areas.get(e.slug) ?? null) }));
9074
+ }
9075
+
9076
+ // src/swarmClient.ts
8758
9077
  init_store();
8759
9078
  init_toolFailure();
8760
9079
 
@@ -9423,6 +9742,9 @@ var SwarmClient = class _SwarmClient {
9423
9742
  // Базовая ветка PR (TASWM-285): явная при спавне (CLI --base) либо null —
9424
9743
  // тогда её проставит spawnDrone, разрешив проектную настройку.
9425
9744
  base_branch: input.base_branch ?? null,
9745
+ // TASWM-656: группу ставит постановщик в проде. Локально заведённый прогон
9746
+ // её не имеет, пока hydrateRun не принесёт parallelGroup.
9747
+ parallel_group: null,
9426
9748
  // Воркспейс задачи (TASWM-288): у локально заведённого под-прогона (ревьюер,
9427
9749
  // резолвер, переигровка) — унаследованный от родителя, иначе null. В прод НЕ
9428
9750
  // уходит (см. runFields): там workspaceId проставляется по самой задаче, и
@@ -9618,12 +9940,13 @@ var SwarmClient = class _SwarmClient {
9618
9940
  const cands = [...this.runs.values()].filter((r) => r.task_slug === slug && !SLUG_TERMINAL.has(r.status)).sort((a, b) => b.id - a.id);
9619
9941
  return cands.length ? this.mat(cands[0]) : null;
9620
9942
  }
9621
- runningAreas(repo) {
9943
+ runningAreas(repo, exceptGroup) {
9622
9944
  const seen = /* @__PURE__ */ new Set();
9623
9945
  for (const r of this.runs.values()) {
9624
9946
  if (!(r.status === "running" || r.status === "blocked")) continue;
9625
9947
  if (r.area == null) continue;
9626
9948
  if (repo !== void 0 && r.repo !== repo) continue;
9949
+ if (exceptGroup && effectiveGroup(this.mat(r), (id) => this.getRun(id)) === exceptGroup) continue;
9627
9950
  seen.add(r.area);
9628
9951
  }
9629
9952
  return [...seen];
@@ -11208,6 +11531,8 @@ var SwarmClient = class _SwarmClient {
11208
11531
  host_pinned: false,
11209
11532
  // Базовая ветка PR (TASWM-285) — прод-поле, заполняется ниже из ответа.
11210
11533
  base_branch: null,
11534
+ // TASWM-656: группа параллельной работы — прод-поле постановщика, ниже из ответа.
11535
+ parallel_group: null,
11211
11536
  // Воркспейс задачи (TASWM-288) — прод-поле, заполняется ниже из ответа.
11212
11537
  workspace_id: null,
11213
11538
  // Локальная бухгалтерия (в прод не уходит, как review_cycle) — на гидрации из прода
@@ -11249,6 +11574,7 @@ var SwarmClient = class _SwarmClient {
11249
11574
  local.host_pinned = pr.hostPinned === true;
11250
11575
  local.branch = pr.branch ?? null;
11251
11576
  local.base_branch = pr.baseBranch ?? null;
11577
+ local.parallel_group = pr.parallelGroup ?? null;
11252
11578
  local.workspace_id = pr.workspaceId ?? local.workspace_id ?? null;
11253
11579
  local.status = pr.status ?? local.status;
11254
11580
  local.area = normalizeZoneLabel(pr.area) || null;
@@ -11783,7 +12109,7 @@ init_linkFailure();
11783
12109
 
11784
12110
  // src/repoRegistry.ts
11785
12111
  init_config();
11786
- import { $ } from "execa";
12112
+ import { $ as $2 } from "execa";
11787
12113
  function effectiveRepoPaths(flagRepo, envPaths) {
11788
12114
  const seen = /* @__PURE__ */ new Set();
11789
12115
  const out = [];
@@ -11802,7 +12128,7 @@ function parseRepoFullName(remoteUrl) {
11802
12128
  return `${m[1]}/${m[2]}`.toLowerCase();
11803
12129
  }
11804
12130
  async function resolveRepoFullName(path) {
11805
- const res = await $({ reject: false })`git -C ${path} remote get-url origin`;
12131
+ const res = await $2({ reject: false })`git -C ${path} remote get-url origin`;
11806
12132
  if (res.exitCode !== 0) return null;
11807
12133
  return parseRepoFullName(res.stdout);
11808
12134
  }
@@ -12206,7 +12532,7 @@ function hostIdentityPath(home) {
12206
12532
  }
12207
12533
  function loadHostIdentity(deps) {
12208
12534
  const exists = deps.exists ?? existsSync11;
12209
- const readFile2 = deps.readFile ?? ((p) => readFileSync14(p, "utf8"));
12535
+ const readFile3 = deps.readFile ?? ((p) => readFileSync14(p, "utf8"));
12210
12536
  const writeFile4 = deps.writeFile ?? ((p, data) => {
12211
12537
  writeFileSync12(`${p}.tmp`, data);
12212
12538
  renameSync7(`${p}.tmp`, p);
@@ -12218,7 +12544,7 @@ function loadHostIdentity(deps) {
12218
12544
  if (deps.envHostId) return { hostId: deps.envHostId, hostName };
12219
12545
  if (exists(path)) {
12220
12546
  try {
12221
- const parsed = JSON.parse(readFile2(path));
12547
+ const parsed = JSON.parse(readFile3(path));
12222
12548
  if (typeof parsed.hostId === "string" && parsed.hostId.trim()) {
12223
12549
  return { hostId: parsed.hostId.trim(), hostName };
12224
12550
  }
@@ -12341,11 +12667,11 @@ function reliefLoopStatePath(home) {
12341
12667
  }
12342
12668
  function loadReliefLoopState(home, now = Date.now(), io = {}, cfg = DEFAULT_RELIEF_LOOP_CONFIG) {
12343
12669
  const exists = io.exists ?? existsSync12;
12344
- const readFile2 = io.readFile ?? ((p) => readFileSync15(p, "utf8"));
12670
+ const readFile3 = io.readFile ?? ((p) => readFileSync15(p, "utf8"));
12345
12671
  const path = reliefLoopStatePath(home);
12346
12672
  if (!exists(path)) return {};
12347
12673
  try {
12348
- const raw = JSON.parse(readFile2(path));
12674
+ const raw = JSON.parse(readFile3(path));
12349
12675
  const out = {};
12350
12676
  for (const [key, value] of Object.entries(raw ?? {})) {
12351
12677
  const v = value;
@@ -14206,6 +14532,13 @@ import { join as join29, dirname as dirname4 } from "path";
14206
14532
  function droneLaunchedText(workdir, pid) {
14207
14533
  return `\u0434\u0440\u043E\u043D \u0437\u0430\u043F\u0443\u0449\u0435\u043D \u0432 ${workdir} (pid ${pid})`;
14208
14534
  }
14535
+ function alongsideStepText(group, holders) {
14536
+ const slugs = [...new Set(holders.map((r) => r.task_slug).filter((s) => s.length > 0))];
14537
+ const shown = slugs.slice(0, 5);
14538
+ const rest = slugs.length - shown.length;
14539
+ const who = shown.join(", ") + (rest > 0 ? ` \u0438 \u0435\u0449\u0451 ${rest}` : "");
14540
+ return `\u0435\u0434\u0443 \u0440\u044F\u0434\u043E\u043C \u0441 ${who}: \u0433\u0440\u0443\u043F\u043F\u0430 \u043F\u0430\u0440\u0430\u043B\u043B\u0435\u043B\u044C\u043D\u043E\u0439 \u0440\u0430\u0431\u043E\u0442\u044B \xAB${group}\xBB, \u0444\u0430\u0439\u043B\u043E\u0432\u044B\u0439 \u0433\u0435\u0439\u0442 \u043C\u0435\u0436\u0434\u0443 \u0437\u0430\u0434\u0430\u0447\u0430\u043C\u0438 \u0433\u0440\u0443\u043F\u043F\u044B \u0441\u043D\u044F\u0442 \u043F\u043E\u0441\u0442\u0430\u043D\u043E\u0432\u0449\u0438\u043A\u043E\u043C`;
14541
+ }
14209
14542
  function droneLaunchedPid(text) {
14210
14543
  const m = /^дрон запущен в .* \(pid (\d+)\)$/.exec(text ?? "");
14211
14544
  return m ? Number(m[1]) : null;
@@ -14289,7 +14622,7 @@ async function spawnDrone(deps, run2) {
14289
14622
  if (!repo) throw new Error(`\u0443 \u043F\u0440\u043E\u0433\u043E\u043D\u0430 #${run2.id} (${run2.task_slug}) \u043D\u0435\u0442 repo \u0438 \u043D\u0435\u0442 \u0434\u0435\u0444\u043E\u043B\u0442\u0430 SWARM_REPO`);
14290
14623
  const conflict = deps.conflicts ? await deps.conflicts(run2, repo) : { kind: "unknown" };
14291
14624
  if (conflict.kind === "wait") throw new FileOverlapError(conflict.message, conflict.blockedBy.id);
14292
- if (conflict.kind === "unknown" && run2.area && deps.db.runningAreas(repo).includes(run2.area)) {
14625
+ if (conflict.kind === "unknown" && run2.area && deps.db.runningAreas(repo, run2.parallel_group).includes(run2.area)) {
14293
14626
  throw new AreaBusyError(run2.area);
14294
14627
  }
14295
14628
  const branch = run2.task_slug;
@@ -14315,6 +14648,10 @@ ${notice}` : built;
14315
14648
  assertStillWanted(deps.db, run2.id);
14316
14649
  const pid = deps.launch({ worktree, run: run2, prompt });
14317
14650
  deps.db.addEvent(run2.id, "step", droneLaunchedText(worktree, pid));
14651
+ if (conflict.kind === "clear" && conflict.alongside?.length) {
14652
+ const group = run2.parallel_group || null;
14653
+ if (group) deps.db.addEvent(run2.id, "step", alongsideStepText(group, conflict.alongside));
14654
+ }
14318
14655
  return deps.db.updateRun(run2.id, {
14319
14656
  status: "running",
14320
14657
  repo,
@@ -14489,7 +14826,7 @@ function parkReasonUnretriable(reason) {
14489
14826
  // package.json
14490
14827
  var package_default = {
14491
14828
  name: "@taskless-app/swarm",
14492
- version: "0.6.90",
14829
+ version: "0.6.92",
14493
14830
  type: "module",
14494
14831
  description: "Local control plane for a fleet of AI coding agents (drones), coordinating through Taskless. The overmind runs the swarm.",
14495
14832
  keywords: [
@@ -14541,7 +14878,7 @@ var package_default = {
14541
14878
  undici: "^7.30.1",
14542
14879
  zod: "3.25.76"
14543
14880
  },
14544
- gitHead: "15adc44473d82d392f25ec8d21c0f445d3d4fb91"
14881
+ gitHead: "5a0d3d1cf23a984b2328737669a3043601d4cd9e"
14545
14882
  };
14546
14883
 
14547
14884
  // src/version.ts
@@ -14793,7 +15130,7 @@ init_git();
14793
15130
  // src/gh.ts
14794
15131
  init_src();
14795
15132
  init_netTimeout();
14796
- import { $ as $3 } from "execa";
15133
+ import { $ as $4 } from "execa";
14797
15134
  import { basename as basename4 } from "path";
14798
15135
 
14799
15136
  // src/ghBudget.ts
@@ -15061,7 +15398,7 @@ async function runGh(args, timeoutMs, cwd) {
15061
15398
  const label2 = callLabel("gh", args) + (cwd ? ` (repo ${basename4(cwd)})` : "");
15062
15399
  const skipsPause = ghCallSkipsPause(args);
15063
15400
  if (!skipsPause && ghCallsPaused(Date.now())) throw new GhPausedError();
15064
- const child = cwd ? $3({ cwd, timeout: timeoutMs })`gh ${args}` : $3({ timeout: timeoutMs })`gh ${args}`;
15401
+ const child = cwd ? $4({ cwd, timeout: timeoutMs })`gh ${args}` : $4({ timeout: timeoutMs })`gh ${args}`;
15065
15402
  try {
15066
15403
  return (await withHardTimeout(child, "gh", label2, timeoutMs)).stdout;
15067
15404
  } catch (e) {
@@ -15463,7 +15800,7 @@ var GhCallFailedError = class extends Error {
15463
15800
  };
15464
15801
  var realChecksRunner = async (pr) => {
15465
15802
  const label2 = callLabel("gh", ["pr", "checks", pr]);
15466
- const r = await withHardTimeout($3({ reject: false, timeout: 15e3 })`gh pr checks ${pr} --json state,name,bucket,link`, "gh", label2, 15e3);
15803
+ const r = await withHardTimeout($4({ reject: false, timeout: 15e3 })`gh pr checks ${pr} --json state,name,bucket,link`, "gh", label2, 15e3);
15467
15804
  const stdout = r.stdout ?? "";
15468
15805
  const stderr = r.stderr ?? "";
15469
15806
  if (isTimedOut(r)) throw new GhCallFailedError(label2, classifyCallFailure(r));
@@ -15556,7 +15893,7 @@ async function prCiStatus(pr, run2 = realChecksRunner) {
15556
15893
  }
15557
15894
  var realRunLogRunner = async (runId) => {
15558
15895
  const r = await withHardTimeout(
15559
- $3({ reject: false, timeout: 3e4, maxBuffer: 10 * 1024 * 1024 })`gh run view ${runId} --log-failed`,
15896
+ $4({ reject: false, timeout: 3e4, maxBuffer: 10 * 1024 * 1024 })`gh run view ${runId} --log-failed`,
15560
15897
  "gh",
15561
15898
  callLabel("gh", ["run", "view", runId]),
15562
15899
  3e4
@@ -15665,7 +16002,7 @@ init_git();
15665
16002
  // src/diff.ts
15666
16003
  import { statSync as statSync15 } from "fs";
15667
16004
  import { join as join34 } from "path";
15668
- import { $ as $4 } from "execa";
16005
+ import { $ as $5 } from "execa";
15669
16006
  var MAX_FILES = 200;
15670
16007
  var MAX_LINES_PER_FILE = 1500;
15671
16008
  var MAX_UNTRACKED = 60;
@@ -15785,12 +16122,12 @@ function truncateFile(f) {
15785
16122
  }
15786
16123
  async function resolveBase(wt, baseBranch) {
15787
16124
  const tryRef = async (ref) => {
15788
- const sha = (await $4({ reject: false })`git -C ${wt} rev-parse --verify --quiet ${ref + "^{commit}"}`).stdout.trim();
16125
+ const sha = (await $5({ reject: false })`git -C ${wt} rev-parse --verify --quiet ${ref + "^{commit}"}`).stdout.trim();
15789
16126
  if (!sha) return null;
15790
- const mb2 = (await $4({ reject: false })`git -C ${wt} merge-base HEAD ${ref}`).stdout.trim();
16127
+ const mb2 = (await $5({ reject: false })`git -C ${wt} merge-base HEAD ${ref}`).stdout.trim();
15791
16128
  return mb2 || null;
15792
16129
  };
15793
- const originHead = (await $4({ reject: false })`git -C ${wt} symbolic-ref --quiet --short refs/remotes/origin/HEAD`).stdout.trim();
16130
+ const originHead = (await $5({ reject: false })`git -C ${wt} symbolic-ref --quiet --short refs/remotes/origin/HEAD`).stdout.trim();
15794
16131
  const candidates = [
15795
16132
  ...baseBranch ? [`origin/${baseBranch}`, baseBranch] : [],
15796
16133
  originHead,
@@ -15816,16 +16153,16 @@ async function collectRunDiff(worktree, opts = {}) {
15816
16153
  const stub = (reason) => ({ ok: false, reason, pr: opts.pr ?? null, files: [], added: 0, removed: 0 });
15817
16154
  const gone = opts.status === "queued" ? "\u0434\u0440\u043E\u043D \u0435\u0449\u0451 \u0432 \u043E\u0447\u0435\u0440\u0435\u0434\u0438 \u2014 \u043A\u043E\u0434\u0430 \u043F\u043E\u043A\u0430 \u043D\u0435\u0442" : "worktree \u0443\u0431\u0440\u0430\u043D \u2014 \u043A\u043E\u0434 \u0441\u043C\u043E\u0442\u0440\u0438 \u0432 PR";
15818
16155
  if (!worktree) return stub(gone);
15819
- const isWt = (await $4({ reject: false })`git -C ${worktree} rev-parse --is-inside-work-tree`).stdout.trim();
16156
+ const isWt = (await $5({ reject: false })`git -C ${worktree} rev-parse --is-inside-work-tree`).stdout.trim();
15820
16157
  if (isWt !== "true") return stub(gone);
15821
16158
  const base3 = await resolveBase(worktree, opts.baseBranch);
15822
16159
  const from = base3 ?? "HEAD";
15823
- const trackedTxt = (await $4({ reject: false })`git -C ${worktree} diff --no-color --find-renames ${from} --`).stdout;
16160
+ const trackedTxt = (await $5({ reject: false })`git -C ${worktree} diff --no-color --find-renames ${from} --`).stdout;
15824
16161
  let files = parseUnifiedDiff(trackedTxt);
15825
- const untrackedRaw = (await $4({ reject: false })`git -C ${worktree} ls-files --others --exclude-standard -z`).stdout;
16162
+ const untrackedRaw = (await $5({ reject: false })`git -C ${worktree} ls-files --others --exclude-standard -z`).stdout;
15826
16163
  const untracked = untrackedRaw.split("\0").filter(Boolean).slice(0, MAX_UNTRACKED);
15827
16164
  for (const rel of untracked) {
15828
- const t = (await $4({ reject: false })`git -C ${worktree} diff --no-color --no-index -- /dev/null ${rel}`).stdout;
16165
+ const t = (await $5({ reject: false })`git -C ${worktree} diff --no-color --no-index -- /dev/null ${rel}`).stdout;
15829
16166
  for (const pf of parseUnifiedDiff(t)) {
15830
16167
  pf.status = "added";
15831
16168
  if (!pf.path || pf.path === "/dev/null") pf.path = rel;
@@ -15850,11 +16187,11 @@ async function collectRunDiff(worktree, opts = {}) {
15850
16187
  async function runCommitCount(worktree, opts = {}) {
15851
16188
  if (!worktree) return 0;
15852
16189
  try {
15853
- const isWt = (await $4({ reject: false })`git -C ${worktree} rev-parse --is-inside-work-tree`).stdout.trim();
16190
+ const isWt = (await $5({ reject: false })`git -C ${worktree} rev-parse --is-inside-work-tree`).stdout.trim();
15854
16191
  if (isWt !== "true") return 0;
15855
16192
  const base3 = await resolveBase(worktree, opts.baseBranch);
15856
16193
  if (!base3) return 0;
15857
- const out = (await $4({ reject: false })`git -C ${worktree} rev-list --count ${`${base3}..HEAD`}`).stdout.trim();
16194
+ const out = (await $5({ reject: false })`git -C ${worktree} rev-list --count ${`${base3}..HEAD`}`).stdout.trim();
15858
16195
  const n = Number(out);
15859
16196
  return Number.isInteger(n) && n > 0 ? n : 0;
15860
16197
  } catch {
@@ -15864,11 +16201,11 @@ async function runCommitCount(worktree, opts = {}) {
15864
16201
  async function changedPaths(worktree, opts = {}) {
15865
16202
  if (!worktree) return [];
15866
16203
  try {
15867
- const isWt = (await $4({ reject: false })`git -C ${worktree} rev-parse --is-inside-work-tree`).stdout.trim();
16204
+ const isWt = (await $5({ reject: false })`git -C ${worktree} rev-parse --is-inside-work-tree`).stdout.trim();
15868
16205
  if (isWt !== "true") return [];
15869
16206
  const from = await resolveBase(worktree, opts.baseBranch) ?? "HEAD";
15870
- const tracked = (await $4({ reject: false })`git -C ${worktree} diff --name-only --find-renames ${from} --`).stdout;
15871
- const untracked = (await $4({ reject: false })`git -C ${worktree} ls-files --others --exclude-standard -z`).stdout;
16207
+ const tracked = (await $5({ reject: false })`git -C ${worktree} diff --name-only --find-renames ${from} --`).stdout;
16208
+ const untracked = (await $5({ reject: false })`git -C ${worktree} ls-files --others --exclude-standard -z`).stdout;
15872
16209
  const all = [...tracked.split("\n"), ...untracked.split("\0")].map((s) => s.trim()).filter(Boolean);
15873
16210
  return [...new Set(all)].sort();
15874
16211
  } catch {
@@ -15999,11 +16336,12 @@ async function buildDroneServer(store, opts = {}) {
15999
16336
  const slugForInstruction = (fallback) => opts.expectedTaskSlug ?? fallback ?? "<slug>";
16000
16337
  const iAmReviewer = (run2) => run2?.reviews_run_id != null || run2?.kind === "reviewer" || opts.reviewsRunId != null || opts.runKind === "reviewer";
16001
16338
  const iAmVerifier = (run2) => run2?.verifies_run_id != null || run2?.kind === "verifier" || opts.verifiesRunId != null || opts.runKind === "verifier";
16339
+ let pendingQuestion = null;
16002
16340
  const freeze = async (withdraw = false) => {
16003
16341
  let slug;
16004
16342
  let branch;
16005
16343
  try {
16006
- if (withdraw) await store.withdrawMyQuestion("overmind \u043D\u0435\u0434\u043E\u0441\u0442\u0443\u043F\u0435\u043D \u2014 \u0434\u0440\u043E\u043D \u0437\u0430\u043C\u0435\u0440, \u0432\u043E\u043F\u0440\u043E\u0441 \u0441\u043D\u044F\u0442");
16344
+ if (withdraw || pendingQuestion !== null) await store.withdrawMyQuestion("overmind \u043D\u0435\u0434\u043E\u0441\u0442\u0443\u043F\u0435\u043D \u2014 \u0434\u0440\u043E\u043D \u0437\u0430\u043C\u0435\u0440, \u0432\u043E\u043F\u0440\u043E\u0441 \u0441\u043D\u044F\u0442");
16007
16345
  const run2 = await store.myRun();
16008
16346
  slug = run2?.task_slug;
16009
16347
  branch = !opts.expectedTaskSlug || opts.expectedTaskSlug === run2?.task_slug ? run2?.branch : null;
@@ -16016,9 +16354,20 @@ async function buildDroneServer(store, opts = {}) {
16016
16354
  }
16017
16355
  return { content: [{ type: "text", text: freezeInstruction(branch || slugForInstruction(slug), opts.deadReason) }] };
16018
16356
  };
16019
- const guard = (fn) => async (a) => {
16357
+ const guard = (fn) => async (a, extra) => {
16020
16358
  try {
16021
- return await fn(a);
16359
+ const result = await fn(a, extra);
16360
+ const question = pendingQuestion;
16361
+ if (question === null || extra.signal.aborted) return result;
16362
+ try {
16363
+ const cur = await store.myLastQuestion();
16364
+ if (cur && cur.status === "answered" && cur.answer != null && cur.answer.trim() !== "" && sameQuestion(cur.text, question) && pendingQuestion === question && !extra.signal.aborted) {
16365
+ pendingQuestion = null;
16366
+ return { ...result, content: [{ type: "text", text: lateAnswerText(question, cur.answer) }, ...result.content] };
16367
+ }
16368
+ } catch {
16369
+ }
16370
+ return result;
16022
16371
  } catch (e) {
16023
16372
  if (!(e instanceof ChannelUnavailableError)) throw e;
16024
16373
  const text = channelDownInstruction(slugForInstruction(null), e.message);
@@ -16040,7 +16389,7 @@ async function buildDroneServer(store, opts = {}) {
16040
16389
  "read_task",
16041
16390
  "\u0421\u0432\u0435\u0436\u0438\u0439 \u0441\u043D\u0430\u043F\u0448\u043E\u0442 \u0442\u0432\u043E\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u041F\u0420\u042F\u041C\u041E \u0421\u0415\u0419\u0427\u0410\u0421: \u043E\u043F\u0438\u0441\u0430\u043D\u0438\u0435 + \u043A\u0440\u0438\u0442\u0435\u0440\u0438\u0438 \u0433\u043E\u0442\u043E\u0432\u043D\u043E\u0441\u0442\u0438 + \u043A\u043E\u043C\u043C\u0435\u043D\u0442\u0430\u0440\u0438\u0438 (\u0430\u0432\u0442\u043E\u0440+\u0432\u0440\u0435\u043C\u044F+\u0442\u0435\u043A\u0441\u0442) + \u0441\u043E\u0434\u0435\u0440\u0436\u0438\u043C\u043E\u0435 \u043F\u0440\u0438\u0432\u044F\u0437\u0430\u043D\u043D\u044B\u0445 \u0434\u043E\u043A\u0443\u043C\u0435\u043D\u0442\u043E\u0432 (\u0441\u043F\u0435\u043A\u0438 \u043E\u0431\u044B\u0447\u043D\u043E \u043B\u0435\u0436\u0430\u0442 \u0438\u043C\u0435\u043D\u043D\u043E \u0442\u0430\u043C) + \u0447\u0435\u043C \u043A\u043E\u043D\u0447\u0438\u043B\u0438\u0441\u044C \u0441\u043E\u0441\u0435\u0434\u043D\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0432 \u0442\u043E\u0439 \u0436\u0435 \u0437\u043E\u043D\u0435 \u043A\u043E\u0434\u0430 \u0438 \u043A\u0442\u043E \u0438\u0437 \u0440\u043E\u044F \u0440\u0430\u0431\u043E\u0442\u0430\u0435\u0442 \u0440\u044F\u0434\u043E\u043C. \u0411\u0435\u0437 \u043F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u043E\u0432. \u0417\u043E\u0432\u0438 \u043F\u0435\u0440\u0435\u0434 done() \u2014 \u043E\u043F\u0435\u0440\u0430\u0442\u043E\u0440 \u043C\u043E\u0433 \u0434\u043E\u043F\u0438\u0441\u0430\u0442\u044C \u0442\u0440\u0435\u0431\u043E\u0432\u0430\u043D\u0438\u0435 \u043A\u043E\u043C\u043C\u0435\u043D\u0442\u043E\u043C \u0443\u0436\u0435 \u043F\u043E\u0441\u043B\u0435 \u0442\u0432\u043E\u0435\u0433\u043E \u0441\u0442\u0430\u0440\u0442\u0430, \u0430 \u0441\u0442\u0430\u0440\u0442\u043E\u0432\u044B\u0439 \u043F\u0440\u043E\u043C\u043F\u0442 \u044D\u0442\u043E\u0433\u043E \u043D\u0435 \u0443\u0432\u0438\u0434\u0438\u0442 (\u043E\u043D \u0441\u043E\u0431\u0440\u0430\u043D \u043E\u0434\u0438\u043D \u0440\u0430\u0437 \u043F\u0440\u0438 \u0441\u043F\u0430\u0432\u043D\u0435).",
16042
16391
  {},
16043
- async () => {
16392
+ guard(async () => {
16044
16393
  if (!opts.taskless) {
16045
16394
  return {
16046
16395
  content: [{ type: "text", text: "Taskless \u043D\u0435\u0434\u043E\u0441\u0442\u0443\u043F\u0435\u043D (slug-only \u0440\u0435\u0436\u0438\u043C) \u2014 \u0441\u0432\u0435\u0436\u0435\u0433\u043E \u0441\u043D\u0430\u043F\u0448\u043E\u0442\u0430 \u043D\u0435\u0442, \u0440\u0430\u0431\u043E\u0442\u0430\u0439 \u043F\u043E \u0442\u043E\u043C\u0443, \u0447\u0442\u043E \u0443\u0436\u0435 \u0432 \u043F\u0440\u043E\u043C\u043F\u0442\u0435." }],
@@ -16071,7 +16420,8 @@ ${failText}` : failText }],
16071
16420
  const attachments = await prepareTaskAttachments({
16072
16421
  worktree: opts.worktree ?? process.cwd(),
16073
16422
  refs: task.attachments,
16074
- fetchFile: opts.taskless.fetchFile?.bind(opts.taskless)
16423
+ fetchFile: opts.taskless.fetchFile?.bind(opts.taskless),
16424
+ onEvent: (text) => text.includes("\u043D\u0435 \u0441\u043A\u0430\u0447\u0430\u043B\u043E\u0441\u044C") ? store.addEvent(null, "step", text) : void 0
16075
16425
  });
16076
16426
  const lines = [
16077
16427
  `**${task.title}** \xB7 ${task.slug}${task.url ? ` (${task.url})` : ""}`,
@@ -16082,7 +16432,7 @@ ${failText}` : failText }],
16082
16432
  if (attachments) lines.push("", attachments);
16083
16433
  if (mismatchNote) lines.unshift(mismatchNote, "");
16084
16434
  return { content: [{ type: "text", text: lines.join("\n") }] };
16085
- }
16435
+ })
16086
16436
  );
16087
16437
  server.tool(
16088
16438
  "report_acceptance_check",
@@ -16092,7 +16442,7 @@ ${failText}` : failText }],
16092
16442
  state: z.enum(["passed", "failed", "pending"]).describe("passed | failed | pending \u2014 \u043F\u043E \u0444\u0430\u043A\u0442\u0443 \u043F\u0440\u043E\u0433\u043E\u043D\u0430"),
16093
16443
  evidence: z.string().max(4e3).optional().describe("\u0447\u0435\u043C \u0434\u043E\u043A\u0430\u0437\u0430\u043D\u043E: \u0432\u044B\u0432\u043E\u0434 \u043A\u043E\u043C\u0430\u043D\u0434\u044B, \u0441\u0441\u044B\u043B\u043A\u0430 \u043D\u0430 PR/\u0441\u043A\u0440\u0438\u043D, \u043D\u0430\u0431\u043B\u044E\u0434\u0430\u0435\u043C\u043E\u0435 \u043F\u043E\u0432\u0435\u0434\u0435\u043D\u0438\u0435")
16094
16444
  },
16095
- async ({ id, state, evidence }) => {
16445
+ guard(async ({ id, state, evidence }) => {
16096
16446
  if (!opts.taskless) {
16097
16447
  return {
16098
16448
  content: [
@@ -16119,7 +16469,7 @@ ${failText}` : failText }],
16119
16469
  await store.addEvent(null, "step", `${ACCEPTANCE_CHECK_MARK}: ${id} \u2192 ${state}`, null).catch(() => {
16120
16470
  });
16121
16471
  return { content: [{ type: "text", text }] };
16122
- }
16472
+ })
16123
16473
  );
16124
16474
  server.tool(
16125
16475
  "ask",
@@ -16128,16 +16478,62 @@ ${failText}` : failText }],
16128
16478
  question: z.string().describe("\u0432\u043E\u043F\u0440\u043E\u0441, \u043D\u0430 \u043A\u043E\u0442\u043E\u0440\u044B\u0439 \u043D\u0443\u0436\u0435\u043D \u043E\u0442\u0432\u0435\u0442"),
16129
16479
  options: z.array(z.string()).optional().describe("2\u20134 \u0432\u0430\u0440\u0438\u0430\u043D\u0442\u0430 \u043E\u0442\u0432\u0435\u0442\u0430 (\u043A\u043D\u043E\u043F\u043A\u0438); \u043E\u043F\u0443\u0441\u0442\u0438 \u0434\u043B\u044F \u043E\u0442\u043A\u0440\u044B\u0442\u043E\u0433\u043E \u0432\u043E\u043F\u0440\u043E\u0441\u0430")
16130
16480
  },
16131
- guard(async ({ question, options }) => {
16481
+ guard(async ({ question, options }, extra) => {
16132
16482
  if (await overmindDead()) return freeze();
16133
- const asked = await store.ask(question, options);
16134
- for (; ; ) {
16135
- await new Promise((r) => setTimeout(r, askPollMs));
16483
+ let asked;
16484
+ if (pendingQuestion !== null && sameQuestion(pendingQuestion, question)) {
16136
16485
  const cur = await store.myLastQuestion();
16137
- if (cur && cur.status === "answered" && cur.answer != null && sameQuestion(cur.text, asked.text)) {
16138
- return { content: [{ type: "text", text: cur.answer }] };
16486
+ if (cur && sameQuestion(cur.text, pendingQuestion)) {
16487
+ if (cur.status === "answered" && cur.answer != null && cur.answer.trim() !== "") {
16488
+ pendingQuestion = null;
16489
+ return { content: [{ type: "text", text: cur.answer }] };
16490
+ }
16491
+ asked = cur;
16492
+ pendingQuestion = null;
16493
+ } else {
16494
+ pendingQuestion = null;
16495
+ asked = await store.ask(question, options);
16139
16496
  }
16140
- if (await overmindDead()) return freeze(true);
16497
+ } else {
16498
+ if (pendingQuestion !== null) {
16499
+ const prevQuestion = pendingQuestion;
16500
+ let prev = await store.myLastQuestion();
16501
+ if (prev && sameQuestion(prev.text, prevQuestion) && prev.status === "open") {
16502
+ await store.withdrawMyQuestion(`\u0434\u0440\u043E\u043D \u0437\u0430\u0434\u0430\u043B \u0434\u0440\u0443\u0433\u043E\u0439 \u0432\u043E\u043F\u0440\u043E\u0441: \xAB${question.slice(0, 200)}\xBB`);
16503
+ prev = await store.myLastQuestion();
16504
+ }
16505
+ if (prev && sameQuestion(prev.text, prevQuestion) && prev.status === "answered" && prev.answer?.trim()) {
16506
+ pendingQuestion = null;
16507
+ const text = lateAnswerText(prevQuestion, prev.answer) + "\n\n\u041D\u043E\u0432\u044B\u0439 \u0432\u043E\u043F\u0440\u043E\u0441 \u041D\u0415 \u043E\u0442\u043F\u0440\u0430\u0432\u043B\u0435\u043D: \u0441\u043D\u0430\u0447\u0430\u043B\u0430 \u0443\u0447\u0442\u0438 \u044D\u0442\u043E\u0442 \u043E\u0442\u0432\u0435\u0442. \u0415\u0441\u043B\u0438 \u0432\u043E\u043F\u0440\u043E\u0441 \u043E\u0441\u0442\u0430\u043B\u0441\u044F, \u0437\u0430\u0434\u0430\u0439 \u0435\u0433\u043E \u0435\u0449\u0451 \u0440\u0430\u0437.";
16508
+ return { content: [{ type: "text", text }] };
16509
+ }
16510
+ }
16511
+ pendingQuestion = null;
16512
+ asked = await store.ask(question, options);
16513
+ }
16514
+ let marked = false;
16515
+ const markPending = () => {
16516
+ if (marked) return;
16517
+ marked = true;
16518
+ pendingQuestion = asked.text;
16519
+ };
16520
+ extra.signal.addEventListener("abort", markPending, { once: true });
16521
+ if (extra.signal.aborted) markPending();
16522
+ try {
16523
+ for (; ; ) {
16524
+ await new Promise((r) => setTimeout(r, askPollMs));
16525
+ if (extra.signal.aborted) {
16526
+ markPending();
16527
+ return { content: [{ type: "text", text: "\u043E\u0436\u0438\u0434\u0430\u043D\u0438\u0435 \u043E\u0442\u0432\u0435\u0442\u0430 \u043E\u0442\u043C\u0435\u043D\u0435\u043D\u043E \u043A\u043B\u0438\u0435\u043D\u0442\u043E\u043C" }] };
16528
+ }
16529
+ const cur = await store.myLastQuestion();
16530
+ if (cur && cur.status === "answered" && cur.answer != null && sameQuestion(cur.text, asked.text)) {
16531
+ return { content: [{ type: "text", text: cur.answer }] };
16532
+ }
16533
+ if (await overmindDead()) return freeze(true);
16534
+ }
16535
+ } finally {
16536
+ extra.signal.removeEventListener("abort", markPending);
16141
16537
  }
16142
16538
  })
16143
16539
  );
@@ -16854,6 +17250,12 @@ ${report}${shots.warning}`,
16854
17250
  }
16855
17251
  return server;
16856
17252
  }
17253
+ function lateAnswerText(question, answer) {
17254
+ return `\u{1F4E8} \u041E\u0422\u0412\u0415\u0422 \u041E\u041F\u0415\u0420\u0410\u0422\u041E\u0420\u0410 \u043D\u0430 \u0442\u0432\u043E\u0439 \u0432\u043E\u043F\u0440\u043E\u0441 \xAB${question.slice(0, 200)}\xBB:
17255
+ ${answer}
17256
+
17257
+ \u041E\u0442\u0432\u0435\u0442 \u043F\u0440\u0438\u0448\u0451\u043B \u043F\u043E\u0441\u043B\u0435 \u0442\u043E\u0433\u043E, \u043A\u0430\u043A ask() \u043F\u0435\u0440\u0435\u0441\u0442\u0430\u043B \u0436\u0434\u0430\u0442\u044C. \u0423\u0447\u0442\u0438 \u0435\u0433\u043E \u0441\u0435\u0439\u0447\u0430\u0441. \u0415\u0441\u043B\u0438 \u0443\u0436\u0435 \u0441\u0434\u0435\u043B\u0430\u043B \u0438\u043D\u0430\u0447\u0435, \u043F\u043E\u043F\u0440\u0430\u0432\u044C.`;
17258
+ }
16857
17259
  function sameQuestion(a, b) {
16858
17260
  return a.trim().replace(/\s+/g, " ") === b.trim().replace(/\s+/g, " ");
16859
17261
  }
@@ -18698,6 +19100,8 @@ function roySnapshot(db, now = Date.now(), overmindLog = [], paused = false, dae
18698
19100
  // машина прогона (TASWM-281); sqlite-бэкенд — всегда пусто
18699
19101
  baseBranch: r.base_branch ?? null,
18700
19102
  // базовая ветка PR (TASWM-285); пусто — ветка по умолчанию
19103
+ parallelGroup: r.parallel_group ?? null,
19104
+ // TASWM-656: в UI не рисуется
18701
19105
  hostId: r.host_id ?? null
18702
19106
  // ключ группировки (TASWM-282)
18703
19107
  };
@@ -20441,7 +20845,7 @@ async function doRestart(cmd, opts, note) {
20441
20845
  init_git();
20442
20846
  import { existsSync as existsSync21 } from "fs";
20443
20847
  import { join as join38 } from "path";
20444
- import { $ as $5 } from "execa";
20848
+ import { $ as $6 } from "execa";
20445
20849
 
20446
20850
  // src/cliIo.ts
20447
20851
  import { createInterface } from "readline/promises";
@@ -20464,7 +20868,7 @@ async function execCaptured(command) {
20464
20868
  // src/selfUpdate.ts
20465
20869
  var DAEMON_PACKAGE = "@taskless-app/swarm";
20466
20870
  var defaultRun = async (cmd, args, cwd) => {
20467
- const res = await $5({ reject: false, cwd })(cmd, args);
20871
+ const res = await $6({ reject: false, cwd })(cmd, args);
20468
20872
  return { exitCode: res.exitCode ?? 1, stdout: res.stdout ?? "", stderr: res.stderr ?? "" };
20469
20873
  };
20470
20874
  function tail(text, max = 400) {
@@ -20689,11 +21093,11 @@ function anomalyStatePath(home) {
20689
21093
  }
20690
21094
  function loadAnomalyState(home, now = Date.now(), io = {}) {
20691
21095
  const exists = io.exists ?? existsSync22;
20692
- const readFile2 = io.readFile ?? ((p) => readFileSync27(p, "utf8"));
21096
+ const readFile3 = io.readFile ?? ((p) => readFileSync27(p, "utf8"));
20693
21097
  const path = anomalyStatePath(home);
20694
21098
  if (!exists(path)) return emptyState();
20695
21099
  try {
20696
- const raw = JSON.parse(readFile2(path));
21100
+ const raw = JSON.parse(readFile3(path));
20697
21101
  const since = numbers(raw.since);
20698
21102
  const lastFiredAt = numbers(raw.lastFiredAt);
20699
21103
  const fires = numbers(raw.fires);
@@ -20860,7 +21264,7 @@ function activeDroneCount(db) {
20860
21264
  }
20861
21265
  function isCapacityBlocked(db, run2, exclusivityBlocked) {
20862
21266
  if (db.unmetDeps(run2.depends_on).length > 0) return false;
20863
- if (run2.area && db.runningAreas(run2.repo).includes(run2.area)) return false;
21267
+ if (run2.area && db.runningAreas(run2.repo, run2.parallel_group).includes(run2.area)) return false;
20864
21268
  if (exclusivityBlocked?.has(run2.id)) return false;
20865
21269
  return true;
20866
21270
  }
@@ -20969,198 +21373,6 @@ function decideWatchdogAction(db, now, state, thresholds, droneCap, wt, exclusiv
20969
21373
  // src/overmind.ts
20970
21374
  init_storm();
20971
21375
  init_src();
20972
-
20973
- // src/zones.ts
20974
- init_src();
20975
-
20976
- // src/gitHistory.ts
20977
- import { $ as $6 } from "execa";
20978
- var REC = "";
20979
- var FIELD = "";
20980
- var LOG_FORMAT = `${REC}%H${FIELD}%s`;
20981
- var SLUG_IN_SUBJECT = /\b([A-Z][A-Z0-9]{0,7}-\d+)\b/;
20982
- function slugFromSubject(subject) {
20983
- return SLUG_IN_SUBJECT.exec(subject)?.[1] ?? null;
20984
- }
20985
- function unquotePath(raw) {
20986
- const p = raw.trim();
20987
- return p.length >= 2 && p.startsWith('"') && p.endsWith('"') ? p.slice(1, -1) : p;
20988
- }
20989
- function parseGitLog(out) {
20990
- const commits = [];
20991
- for (const chunk of out.split(REC)) {
20992
- if (!chunk.trim()) continue;
20993
- const [head, ...rest] = chunk.split("\n");
20994
- const [sha, subject] = (head ?? "").split(FIELD);
20995
- if (!sha) continue;
20996
- const files = rest.map(unquotePath).filter(Boolean);
20997
- commits.push({ sha, subject: subject ?? "", files });
20998
- }
20999
- return commits;
21000
- }
21001
- var NOISE_RE = /^(journal\/|changelog\/|docs\/|design\/|scratch\/|\.claude\/|.*\.lock$|pnpm-lock\.yaml$)/;
21002
- function isNoisePath(path) {
21003
- return NOISE_RE.test(path);
21004
- }
21005
- var GROUP_DEFAULTS = { maxFilesPerCommit: 120, ignore: isNoisePath };
21006
- function groupTaskHistory(commits, opts = {}) {
21007
- const o = { ...GROUP_DEFAULTS, ...opts };
21008
- const bySlug = /* @__PURE__ */ new Map();
21009
- for (const c of commits) {
21010
- const slug = slugFromSubject(c.subject);
21011
- if (!slug) continue;
21012
- if (c.files.length > o.maxFilesPerCommit) continue;
21013
- const files = c.files.filter((f) => !o.ignore(f));
21014
- if (!files.length) continue;
21015
- let acc = bySlug.get(slug);
21016
- if (!acc) bySlug.set(slug, acc = { files: /* @__PURE__ */ new Set(), texts: [] });
21017
- for (const f of files) acc.files.add(f);
21018
- acc.texts.push(c.subject);
21019
- }
21020
- return [...bySlug.entries()].map(([slug, acc]) => ({
21021
- slug,
21022
- files: [...acc.files],
21023
- text: acc.texts.join(" \xB7 ")
21024
- }));
21025
- }
21026
- async function readCommitLog(repo, opts = {}) {
21027
- const max = opts.maxCommits ?? 1500;
21028
- try {
21029
- const { stdout } = await $6({ cwd: repo, reject: false })`git log --no-merges --name-only --pretty=format:${LOG_FORMAT} -n ${String(max)} ${opts.ref ?? "HEAD"}`;
21030
- return parseGitLog(stdout ?? "");
21031
- } catch {
21032
- return [];
21033
- }
21034
- }
21035
- async function readTaskHistory(repo, opts = {}) {
21036
- return groupTaskHistory(await readCommitLog(repo, opts), opts);
21037
- }
21038
- async function headSha(repo) {
21039
- try {
21040
- const { stdout, exitCode } = await $6({ cwd: repo, reject: false })`git rev-parse HEAD`;
21041
- return exitCode === 0 ? stdout.trim() : null;
21042
- } catch {
21043
- return null;
21044
- }
21045
- }
21046
-
21047
- // src/zones.ts
21048
- function runText(run2) {
21049
- return [run2.task_title ?? "", run2.task_desc ?? ""].join(" ").trim();
21050
- }
21051
- function predictForRun(model, run2, fileExists) {
21052
- return predictFiles(model, { zone: run2.area, text: runText(run2), ...fileExists ? { fileExists } : {} });
21053
- }
21054
- function short(files, n = 3) {
21055
- return files.slice(0, n).join(", ") + (files.length > n ? ` \u0438 \u0435\u0449\u0451 ${files.length - n}` : "");
21056
- }
21057
- function heldBecause(w) {
21058
- const parts = [];
21059
- if (w.prUrl) parts.push(`\u0440\u0430\u0431\u043E\u0442\u0430 \u0441\u0434\u0430\u043D\u0430, PR \u0435\u0449\u0451 \u043D\u0435 \u0432\u043B\u0438\u0442: ${w.prUrl}`);
21060
- if (!w.actual) parts.push(w.prUrl ? "\u0444\u0430\u0439\u043B\u044B \u0432\u0437\u044F\u0442\u044B \u043F\u043E \u043F\u0440\u0435\u0434\u0441\u043A\u0430\u0437\u0430\u043D\u0438\u044E \u2014 \u0441\u043D\u0438\u043C\u043A\u0430 \u043D\u0435 \u043E\u0441\u0442\u0430\u043B\u043E\u0441\u044C" : "\u043F\u043E \u043F\u0440\u0435\u0434\u0441\u043A\u0430\u0437\u0430\u043D\u0438\u044E \u2014 \u0434\u0440\u043E\u043D \u0435\u0449\u0451 \u043D\u0435 \u043D\u0430\u0447\u0430\u043B \u043F\u0438\u0441\u0430\u0442\u044C \u043A\u043E\u0434");
21061
- return parts.length ? ` (${parts.join("; ")})` : "";
21062
- }
21063
- var SPINE_PREDICTION_WEIGHT = 0.7;
21064
- function spineOfPrediction(spine, predicted) {
21065
- return predicted.filter((p) => spine.has(p.path) && p.weight >= SPINE_PREDICTION_WEIGHT).map((p) => p.path);
21066
- }
21067
- function decideConflict({ model, candidate, active, fileExists }) {
21068
- if ((candidate.kind ?? "drone") !== "drone") return { kind: "clear" };
21069
- if (!hasZoneModel(model)) return { kind: "unknown" };
21070
- const predicted = predictForRun(model, candidate, fileExists);
21071
- if (!predicted.length) return { kind: "unknown" };
21072
- if (!active.length) return { kind: "clear" };
21073
- const spine = new Set(model.spine);
21074
- const candidateSpine = new Set(spineOfPrediction(spine, predicted));
21075
- if (candidateSpine.size) {
21076
- for (const w of active) {
21077
- const theirSpine = w.actual ? w.files.filter((f) => spine.has(f)) : spineOfPrediction(spine, predictForRun(model, w.run, fileExists));
21078
- const shared = theirSpine.filter((f) => candidateSpine.has(f));
21079
- if (!shared.length) continue;
21080
- return {
21081
- kind: "wait",
21082
- blockedBy: w.run,
21083
- message: `\u044D\u0442\u0438 \u0434\u0432\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0442\u0440\u043E\u0433\u0430\u044E\u0442 \u043E\u0434\u043D\u0438 \u0444\u0430\u0439\u043B\u044B \u043E\u0431\u0449\u0435\u0433\u043E \u0445\u0440\u0435\u0431\u0442\u0430 (${short(shared)}) \u2014 \u0442\u0430\u043A\u0438\u0435 \u0438\u0434\u0443\u0442 \u043F\u043E\u0441\u043B\u0435\u0434\u043E\u0432\u0430\u0442\u0435\u043B\u044C\u043D\u043E \u043D\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043C\u043E \u043E\u0442 \u0437\u043E\u043D\u044B: \u0436\u0434\u0443 ${w.run.task_slug} (#${w.run.id})` + heldBecause(w)
21084
- };
21085
- }
21086
- }
21087
- for (const w of active) {
21088
- const risk = overlapRisk(predicted, w.files);
21089
- if (!risk.overlap) continue;
21090
- const what = risk.sharedFiles.length ? `\u043E\u0434\u043D\u0438 \u0444\u0430\u0439\u043B\u044B (${short(risk.sharedFiles)})` : `\u043E\u0434\u0438\u043D \u043A\u0430\u0442\u0430\u043B\u043E\u0433 (${short(risk.sharedDirs)})`;
21091
- return {
21092
- kind: "wait",
21093
- blockedBy: w.run,
21094
- message: `\u044D\u0442\u0438 \u0434\u0432\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0442\u0440\u043E\u0433\u0430\u044E\u0442 ${what} \u2014 \u0441\u0442\u0430\u0432\u0438\u043C \u043F\u043E\u0441\u043B\u0435\u0434\u043E\u0432\u0430\u0442\u0435\u043B\u044C\u043D\u043E: \u0436\u0434\u0443 ${w.run.task_slug} (#${w.run.id})` + heldBecause(w)
21095
- };
21096
- }
21097
- return { kind: "clear" };
21098
- }
21099
- function suggestAreaForRun(model, run2) {
21100
- if (!hasZoneModel(model)) return null;
21101
- const text = runText(run2);
21102
- if (!text) return null;
21103
- const top = suggestZonesFromText(model, text)[0];
21104
- return top && top.confidence >= 0.3 ? { zone: top.zone, confidence: top.confidence, why: top.why } : null;
21105
- }
21106
- var DEFAULT_TTL_MS = 10 * 6e4;
21107
- var ZoneModels = class {
21108
- constructor(opts = {}) {
21109
- this.opts = opts;
21110
- }
21111
- opts;
21112
- cache = /* @__PURE__ */ new Map();
21113
- /** Модель репо. Истории нет / это не git — EMPTY_ZONE_MODEL (раздача на старом локе). */
21114
- async forRepo(repo, now = Date.now()) {
21115
- if (!repo) return EMPTY_ZONE_MODEL;
21116
- const head = await headSha(repo);
21117
- const hit = this.cache.get(repo);
21118
- if (hit && hit.head === head && now - hit.builtAt < (this.opts.ttlMs ?? DEFAULT_TTL_MS)) return hit.model;
21119
- const model = await this.build(repo);
21120
- this.cache.set(repo, { head, builtAt: now, model });
21121
- return model;
21122
- }
21123
- /** Сбросить кэш (тесты, `swarm zones --refresh`). */
21124
- clear() {
21125
- this.cache.clear();
21126
- }
21127
- async build(repo) {
21128
- const history = await readTaskHistory(repo, { ...this.opts.maxCommits ? { maxCommits: this.opts.maxCommits } : {} });
21129
- return buildZoneModel(withManualAreas(history, this.opts.manualAreas?.() ?? /* @__PURE__ */ new Map()));
21130
- }
21131
- };
21132
- var ActiveFilesCache = class {
21133
- constructor(read, ttlMs = 3e4) {
21134
- this.read = read;
21135
- this.ttlMs = ttlMs;
21136
- }
21137
- read;
21138
- ttlMs;
21139
- cache = /* @__PURE__ */ new Map();
21140
- async filesOf(run2, now = Date.now()) {
21141
- const hit = this.cache.get(run2.id);
21142
- if (hit && now - hit.at < this.ttlMs) return hit.files;
21143
- const files = await this.read(run2);
21144
- this.cache.set(run2.id, { at: now, files });
21145
- return files;
21146
- }
21147
- /**
21148
- * Забыть всех, кто больше НЕ ДЕРЖИТ файлы. Раньше здесь стоял список ЖИВЫХ дронов и
21149
- * комментарий «дрон закончил — его файлы больше не заняты»; это и была дырка TASWM-506:
21150
- * дрон заканчивал, открывал PR, PR висел непомерженным — а строки уже считались
21151
- * свободными. Держатель теперь переживает своего дрона и уходит из кэша на мерже
21152
- * (прогон выходит из `review`), см. holdsFiles.
21153
- */
21154
- prune(holderIds) {
21155
- const holders = new Set(holderIds);
21156
- for (const id of [...this.cache.keys()]) if (!holders.has(id)) this.cache.delete(id);
21157
- }
21158
- };
21159
- function withManualAreas(history, areas) {
21160
- return history.map((e) => ({ ...e, area: normalizeZoneName(areas.get(e.slug) ?? null) }));
21161
- }
21162
-
21163
- // src/overmind.ts
21164
21376
  var ANOMALY_RESOLVE_BATCH = 50;
21165
21377
  var THIS_FILE = fileURLToPath3(import.meta.url);
21166
21378
  var executorHasSession = (run2) => !!run2.worktree_path && EXECUTOR.session.exists(run2.worktree_path);
@@ -23555,8 +23767,9 @@ async function zoneConflictFor(db, models, activeFiles, run2, repo, repoFallback
23555
23767
  const snapshot = r.changed_paths ?? [];
23556
23768
  const files = snapshot.length ? snapshot : await activeFiles.filesOf(r);
23557
23769
  const prUrl = r.status === "review" ? r.pr_url : null;
23770
+ const seen = { ...r, parallel_group: effectiveGroup(r, (id) => db.getRun(id)) };
23558
23771
  active.push(
23559
- files.length ? { run: r, files, actual: true, prUrl } : { run: r, files: heldByPrediction(predictForRun(model, r, fileExists)), actual: false, prUrl }
23772
+ files.length ? { run: seen, files, actual: true, prUrl } : { run: seen, files: heldByPrediction(predictForRun(model, r, fileExists)), actual: false, prUrl }
23560
23773
  );
23561
23774
  }
23562
23775
  return decideConflict({ model, candidate: run2, active, fileExists });
@@ -24982,12 +25195,12 @@ async function tickOnce(deps) {
24982
25195
  }
24983
25196
  deps.stepClock?.mark("0a4 \u043A\u0430\u0440\u0442\u0430 \u0440\u0435\u043F\u043E\u0437\u0438\u0442\u043E\u0440\u0438\u0435\u0432 \u043C\u0430\u0448\u0438\u043D\u044B");
24984
25197
  if (deps.repoMap) {
24985
- const rm4 = deps.repoMap;
24986
- const sinceLast = rm4.lastAt == null ? Infinity : now - rm4.lastAt;
24987
- if (sinceLast >= rm4.intervalMs) {
24988
- rm4.lastAt = now;
25198
+ const rm3 = deps.repoMap;
25199
+ const sinceLast = rm3.lastAt == null ? Infinity : now - rm3.lastAt;
25200
+ if (sinceLast >= rm3.intervalMs) {
25201
+ rm3.lastAt = now;
24989
25202
  try {
24990
- await rm4.run();
25203
+ await rm3.run();
24991
25204
  } catch (e) {
24992
25205
  console.error("[overmind] \u043E\u0431\u043D\u043E\u0432\u043B\u0435\u043D\u0438\u0435 \u043A\u0430\u0440\u0442\u044B \u0440\u0435\u043F\u043E\u0437\u0438\u0442\u043E\u0440\u0438\u0435\u0432 \u0441\u043E\u0440\u0432\u0430\u043B\u043E\u0441\u044C:", e);
24993
25206
  }