@taskless-app/swarm 0.6.106 → 0.6.108

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -2740,6 +2740,7 @@ function grokMcpToml(spec) {
2740
2740
  "command = " + tomlBasic(spec.mcp.command),
2741
2741
  "args = [" + args + "]",
2742
2742
  "env = { " + env + " }",
2743
+ "tool_timeout_sec = " + String(GROK_SWARM_TOOL_TIMEOUT_SEC),
2743
2744
  ""
2744
2745
  ].join("\n");
2745
2746
  }
@@ -2914,7 +2915,7 @@ function extractJsonObject(raw) {
2914
2915
  }
2915
2916
  return null;
2916
2917
  }
2917
- var grokExecutor;
2918
+ var GROK_SWARM_TOOL_TIMEOUT_SEC, grokExecutor;
2918
2919
  var init_grok = __esm({
2919
2920
  "src/executors/grok.ts"() {
2920
2921
  "use strict";
@@ -2922,6 +2923,7 @@ var init_grok = __esm({
2922
2923
  init_swarmHome();
2923
2924
  init_swarmFiles();
2924
2925
  init_codex();
2926
+ GROK_SWARM_TOOL_TIMEOUT_SEC = 7 * 24 * 60 * 60;
2925
2927
  grokExecutor = {
2926
2928
  id: "grok",
2927
2929
  title: "Grok CLI (grok)",
@@ -4491,7 +4493,7 @@ var init_package = __esm({
4491
4493
  "package.json"() {
4492
4494
  package_default = {
4493
4495
  name: "@taskless-app/swarm",
4494
- version: "0.6.106",
4496
+ version: "0.6.108",
4495
4497
  type: "module",
4496
4498
  description: "Local control plane for a fleet of AI coding agents (drones), coordinating through Taskless. The overmind runs the swarm.",
4497
4499
  keywords: [
@@ -4543,7 +4545,7 @@ var init_package = __esm({
4543
4545
  undici: "^7.30.1",
4544
4546
  zod: "3.25.76"
4545
4547
  },
4546
- gitHead: "bb60755eda8d72e1dbf0adc4aa4e86b2d9189270"
4548
+ gitHead: "5f0f3fbffee1c48a48899d850caaf0ed10d0b9c2"
4547
4549
  };
4548
4550
  }
4549
4551
  });
package/dist/overmind.js CHANGED
@@ -2972,6 +2972,7 @@ function grokMcpToml(spec) {
2972
2972
  "command = " + tomlBasic(spec.mcp.command),
2973
2973
  "args = [" + args + "]",
2974
2974
  "env = { " + env + " }",
2975
+ "tool_timeout_sec = " + String(GROK_SWARM_TOOL_TIMEOUT_SEC),
2975
2976
  ""
2976
2977
  ].join("\n");
2977
2978
  }
@@ -3146,7 +3147,7 @@ function extractJsonObject(raw) {
3146
3147
  }
3147
3148
  return null;
3148
3149
  }
3149
- var grokExecutor;
3150
+ var GROK_SWARM_TOOL_TIMEOUT_SEC, grokExecutor;
3150
3151
  var init_grok = __esm({
3151
3152
  "src/executors/grok.ts"() {
3152
3153
  "use strict";
@@ -3154,6 +3155,7 @@ var init_grok = __esm({
3154
3155
  init_swarmHome();
3155
3156
  init_swarmFiles();
3156
3157
  init_codex();
3158
+ GROK_SWARM_TOOL_TIMEOUT_SEC = 7 * 24 * 60 * 60;
3157
3159
  grokExecutor = {
3158
3160
  id: "grok",
3159
3161
  title: "Grok CLI (grok)",
@@ -3941,14 +3943,14 @@ function diskGb(path = process.cwd()) {
3941
3943
  }
3942
3944
  }
3943
3945
  function readCpuTicks(cpus) {
3944
- let idle = 0;
3946
+ let idle2 = 0;
3945
3947
  let total = 0;
3946
3948
  for (const c of cpus) {
3947
3949
  const t = c.times;
3948
- idle += t.idle;
3950
+ idle2 += t.idle;
3949
3951
  total += t.user + t.nice + t.sys + t.idle + t.irq;
3950
3952
  }
3951
- return { idle, total };
3953
+ return { idle: idle2, total };
3952
3954
  }
3953
3955
  function cpuBusyFromTicks(prev, cur) {
3954
3956
  if (!prev) return null;
@@ -7227,7 +7229,8 @@ function makeTasklessClient(call, workspaceId, taskUrlBase, fetchFile, fetchImpl
7227
7229
  console.warn("[taskless] swarm_repo_config \u043E\u0442\u0432\u0435\u0440\u0433 taskSlug \u2014 \u043F\u043E\u0432\u0442\u043E\u0440\u044F\u044E \u0431\u0435\u0437 \u043D\u0435\u0433\u043E: \u0441\u0435\u0440\u0432\u0435\u0440, \u0432\u0435\u0440\u043E\u044F\u0442\u043D\u043E, \u0441\u0442\u0430\u0440\u0435\u0435 \u0434\u0435\u043C\u043E\u043D\u0430");
7228
7230
  outcome = await callTool("swarm_repo_config", { repoFullName });
7229
7231
  }
7230
- if (!outcome.ok || outcome.res.isError) return null;
7232
+ if (!outcome.ok) throw new Error(outcome.failure.detail || "swarm_repo_config");
7233
+ if (outcome.res.isError) throw new Error(toolErrorText2(outcome.res) || "swarm_repo_config");
7231
7234
  const sc = outcome.res.structuredContent ?? null;
7232
7235
  if (sc?.ambiguous === true || sc?.repoAmbiguous === true) return null;
7233
7236
  return sc;
@@ -7707,7 +7710,7 @@ __export(db_exports, {
7707
7710
  });
7708
7711
  import { createRequire as createRequire2 } from "module";
7709
7712
  import { randomUUID as randomUUID3 } from "crypto";
7710
- import { existsSync as existsSync20 } from "fs";
7713
+ import { existsSync as existsSync21 } from "fs";
7711
7714
  import { resolve as resolve5 } from "path";
7712
7715
  function rowToQuestion(row) {
7713
7716
  return {
@@ -8385,7 +8388,7 @@ CREATE TABLE IF NOT EXISTS imports (
8385
8388
  const repoN = normalizeRepo(repo);
8386
8389
  const already = this.db.prepare("SELECT run_count FROM imports WHERE source = ?").get(abs);
8387
8390
  if (already) return { imported: false, runs: already.run_count };
8388
- if (!existsSync20(abs)) throw new Error(`import-db: \u0444\u0430\u0439\u043B\u0430 \u043D\u0435\u0442: ${abs}`);
8391
+ if (!existsSync21(abs)) throw new Error(`import-db: \u0444\u0430\u0439\u043B\u0430 \u043D\u0435\u0442: ${abs}`);
8389
8392
  const src = new this.databaseCtor(abs);
8390
8393
  try {
8391
8394
  const runs = src.prepare("SELECT * FROM runs ORDER BY id").all();
@@ -8796,10 +8799,10 @@ var init_droneStore = __esm({
8796
8799
 
8797
8800
  // src/overmind.ts
8798
8801
  import { homedir as homedir10 } from "os";
8799
- import { existsSync as existsSync25, readFileSync as readFileSync30, readdirSync as readdirSync19, renameSync as renameSync12, statSync as statSync17 } from "fs";
8800
- import { basename as basename8, dirname as dirname7, join as join43 } from "path";
8802
+ import { existsSync as existsSync26, readFileSync as readFileSync30, readdirSync as readdirSync19, renameSync as renameSync12, statSync as statSync17 } from "fs";
8803
+ import { basename as basename8, dirname as dirname7, join as join44 } from "path";
8801
8804
  import { fileURLToPath as fileURLToPath3, pathToFileURL } from "url";
8802
- import { spawn as spawn4 } from "child_process";
8805
+ import { spawn as spawn5 } from "child_process";
8803
8806
 
8804
8807
  // src/restart.ts
8805
8808
  init_src();
@@ -12859,8 +12862,8 @@ function computeReliefCost(state, now, windowMs) {
12859
12862
  }
12860
12863
  function reliefAlertDue(cost, t) {
12861
12864
  if (cost.pauses < t.pauses) return false;
12862
- const idle = cost.stepsBetween != null && cost.stepsBetween < t.minSteps;
12863
- return cost.lostMs >= t.lostMs || idle;
12865
+ const idle2 = cost.stepsBetween != null && cost.stepsBetween < t.minSteps;
12866
+ return cost.lostMs >= t.lostMs || idle2;
12864
12867
  }
12865
12868
  var ADVICE_LIST_CAP = 3;
12866
12869
  var MAX_ALERT_BODY_CHARS = 1800;
@@ -12884,7 +12887,7 @@ function humanMinutes(ms) {
12884
12887
  if (total < 60) return `${total} \u043C\u0438\u043D`;
12885
12888
  return `${Math.floor(total / 60)} \u0447 ${String(total % 60).padStart(2, "0")} \u043C\u0438\u043D`;
12886
12889
  }
12887
- function reliefAlertBody(cost, pressure, advice, windowMs, minSteps) {
12890
+ function reliefAlertBody(cost, pressure, advice2, windowMs, minSteps) {
12888
12891
  const window = humanMinutes(windowMs);
12889
12892
  const perPause = cost.pauses > 0 ? humanMinutes(cost.lostMs / cost.pauses) : null;
12890
12893
  const parts = [
@@ -12898,7 +12901,7 @@ function reliefAlertBody(cost, pressure, advice, windowMs, minSteps) {
12898
12901
  if (cost.worst && cost.runs > 1) parts.push(`\u0411\u043E\u043B\u044C\u0448\u0435 \u0432\u0441\u0435\u0445 \u0434\u043E\u0441\u0442\u0430\u043B\u043E\u0441\u044C ${cost.worst.label} \u2014 ${cost.worst.pauses} \u0440\u0430\u0437.`);
12899
12902
  if (pressure.culprits.length) parts.push(`\u0423\u043F\u0438\u0440\u0430\u0435\u0442\u0441\u044F \u0432: ${pressure.culprits.join("; ")}.`);
12900
12903
  parts.push(`\u041F\u043E\u043A\u0430\u0437\u0430\u043D\u0438\u044F \u0445\u043E\u0441\u0442\u0430 \u2014 ${pressure.readings.join("; ")}.`);
12901
- parts.push(`\u0427\u0442\u043E \u0434\u0435\u043B\u0430\u0442\u044C \u043F\u043E \u043F\u043E\u0440\u044F\u0434\u043A\u0443: ${advice.map((s, i) => `${i + 1}) ${s}`).join("; ")}.`);
12904
+ parts.push(`\u0427\u0442\u043E \u0434\u0435\u043B\u0430\u0442\u044C \u043F\u043E \u043F\u043E\u0440\u044F\u0434\u043A\u0443: ${advice2.map((s, i) => `${i + 1}) ${s}`).join("; ")}.`);
12902
12905
  const body = parts.join(" ");
12903
12906
  return body.length <= MAX_ALERT_BODY_CHARS ? body : `${body.slice(0, MAX_ALERT_BODY_CHARS - 1)}\u2026`;
12904
12907
  }
@@ -13950,6 +13953,85 @@ import { existsSync as existsSync16, readdirSync as readdirSync17, readFileSync
13950
13953
  import { join as join29 } from "path";
13951
13954
  import { execa } from "execa";
13952
13955
 
13956
+ // src/boundedRun.ts
13957
+ init_procCleanup();
13958
+ import { spawn as spawn3 } from "child_process";
13959
+ var OUTPUT_KEEP = 2e5;
13960
+ var KILL_GRACE_MS = 200;
13961
+ function appendChunk(prev, chunk) {
13962
+ const next = prev + chunk.toString();
13963
+ return next.length > OUTPUT_KEEP ? next.slice(-OUTPUT_KEEP) : next;
13964
+ }
13965
+ function signalGroup(pid, signal) {
13966
+ try {
13967
+ killProcessGroup(pid, signal);
13968
+ } catch {
13969
+ }
13970
+ }
13971
+ async function runBounded(spec, opts) {
13972
+ if (opts.signal?.aborted) return { code: null, stdout: "", stderr: "", timedOut: false, aborted: true };
13973
+ const child = spawn3("shell" in spec ? spec.shell : spec.file, "shell" in spec ? [] : spec.args, {
13974
+ cwd: opts.cwd,
13975
+ env: opts.env ?? process.env,
13976
+ shell: "shell" in spec,
13977
+ detached: true,
13978
+ stdio: ["ignore", "pipe", "pipe"]
13979
+ });
13980
+ let stdout = "";
13981
+ let stderr = "";
13982
+ child.stdout?.on("data", (chunk) => {
13983
+ stdout = appendChunk(stdout, chunk);
13984
+ });
13985
+ child.stderr?.on("data", (chunk) => {
13986
+ stderr = appendChunk(stderr, chunk);
13987
+ });
13988
+ const pid = child.pid;
13989
+ let timedOut = false;
13990
+ let aborted = false;
13991
+ let settled = false;
13992
+ let resolveDone = () => {
13993
+ };
13994
+ const done = new Promise((resolve6) => {
13995
+ resolveDone = resolve6;
13996
+ });
13997
+ const finish = (code2) => {
13998
+ if (settled) return;
13999
+ settled = true;
14000
+ resolveDone(code2);
14001
+ };
14002
+ let killTimer;
14003
+ let finishTimer;
14004
+ const stop = (why) => {
14005
+ if (why === "timeout") timedOut = true;
14006
+ else aborted = true;
14007
+ if (pid) {
14008
+ signalGroup(pid, "SIGTERM");
14009
+ killTimer = setTimeout(() => signalGroup(pid, "SIGKILL"), KILL_GRACE_MS);
14010
+ killTimer.unref?.();
14011
+ }
14012
+ finishTimer = setTimeout(() => finish(null), KILL_GRACE_MS + 250);
14013
+ finishTimer.unref?.();
14014
+ };
14015
+ const onAbort = () => stop("abort");
14016
+ if (opts.signal) opts.signal.addEventListener("abort", onAbort, { once: true });
14017
+ const timer = setTimeout(() => stop("timeout"), Math.max(1, opts.timeoutMs));
14018
+ timer.unref?.();
14019
+ child.once("error", () => finish(null));
14020
+ child.once("close", (exitCode) => finish(typeof exitCode === "number" ? exitCode : null));
14021
+ const code = await done;
14022
+ clearTimeout(timer);
14023
+ if (killTimer) clearTimeout(killTimer);
14024
+ if (finishTimer) clearTimeout(finishTimer);
14025
+ opts.signal?.removeEventListener("abort", onAbort);
14026
+ if (pid && (timedOut || aborted || opts.signal?.aborted)) signalGroup(pid, "SIGKILL");
14027
+ try {
14028
+ child.stdout?.destroy();
14029
+ child.stderr?.destroy();
14030
+ } catch {
14031
+ }
14032
+ return { code, stdout, stderr, timedOut, aborted: aborted || !!opts.signal?.aborted };
14033
+ }
14034
+
13953
14035
  // src/prepareLock.ts
13954
14036
  import { createHash as createHash2 } from "crypto";
13955
14037
  import { closeSync as closeSync6, openSync as openSync6, rmSync as rmSync2, statSync as statSync14, writeSync as writeSync2 } from "fs";
@@ -14163,8 +14245,15 @@ async function sweepEnvCacheTemp(io = {}) {
14163
14245
  // src/deps.ts
14164
14246
  var PREPARE_TIMEOUT_MS = 15 * 6e4;
14165
14247
  var MAX_PLAN_COMMANDS = 12;
14166
- async function runCommand(cmd, worktree) {
14248
+ async function runCommand(cmd, worktree, signal) {
14167
14249
  const exec = async () => {
14250
+ if (signal) {
14251
+ const res2 = await runBounded(
14252
+ { shell: cmd.run },
14253
+ { cwd: cmd.cwd ?? worktree, env: { ...process.env, ...cmd.env }, timeoutMs: PREPARE_TIMEOUT_MS, signal }
14254
+ );
14255
+ return res2.code === 0 && !res2.aborted && !res2.timedOut;
14256
+ }
14168
14257
  const res = await execa(cmd.run, {
14169
14258
  cwd: cmd.cwd ?? worktree,
14170
14259
  shell: true,
@@ -14564,7 +14653,7 @@ function planPrepare(worktree, io = {}) {
14564
14653
  }
14565
14654
  async function ensureWorktreeDeps(worktree, io = {}) {
14566
14655
  const exists = io.exists ?? existsSync16;
14567
- const exec = io.exec ?? ((cmd) => runCommand(cmd, worktree));
14656
+ const exec = io.exec ?? ((cmd) => runCommand(cmd, worktree, io.signal));
14568
14657
  const approve = io.approve ?? (() => true);
14569
14658
  const cachePlan = io.skipEnvCache ? null : envCachePlan(worktree, io);
14570
14659
  const cacheIO = io.envCache ?? {};
@@ -14588,6 +14677,11 @@ async function ensureWorktreeDeps(worktree, io = {}) {
14588
14677
  report.source = plan.source;
14589
14678
  report.outcome = plan.source === "none" ? "not-detected" : "nothing-to-do";
14590
14679
  for (const cmd of plan.commands) {
14680
+ if (io.signal?.aborted) {
14681
+ report.failed.push(cmd.label);
14682
+ report.outcome = "failed";
14683
+ break;
14684
+ }
14591
14685
  if (io.skipOptional && cmd.optional) {
14592
14686
  report.skipped.push(cmd.label);
14593
14687
  continue;
@@ -14604,6 +14698,10 @@ async function ensureWorktreeDeps(worktree, io = {}) {
14604
14698
  if (await exec(cmd)) {
14605
14699
  report.ran.push(cmd.label);
14606
14700
  report.outcome = "prepared";
14701
+ } else if (io.signal?.aborted) {
14702
+ report.failed.push(cmd.label);
14703
+ report.outcome = "failed";
14704
+ break;
14607
14705
  } else if (cmd.optional) {
14608
14706
  report.warned.push(cmd.label);
14609
14707
  } else {
@@ -14970,7 +15068,7 @@ function parkReasonUnretriable(reason) {
14970
15068
  // package.json
14971
15069
  var package_default = {
14972
15070
  name: "@taskless-app/swarm",
14973
- version: "0.6.106",
15071
+ version: "0.6.108",
14974
15072
  type: "module",
14975
15073
  description: "Local control plane for a fleet of AI coding agents (drones), coordinating through Taskless. The overmind runs the swarm.",
14976
15074
  keywords: [
@@ -15022,7 +15120,7 @@ var package_default = {
15022
15120
  undici: "^7.30.1",
15023
15121
  zod: "3.25.76"
15024
15122
  },
15025
- gitHead: "bb60755eda8d72e1dbf0adc4aa4e86b2d9189270"
15123
+ gitHead: "5f0f3fbffee1c48a48899d850caaf0ed10d0b9c2"
15026
15124
  };
15027
15125
 
15028
15126
  // src/version.ts
@@ -17536,6 +17634,14 @@ function verifyLineDropped(command) {
17536
17634
  return false;
17537
17635
  }
17538
17636
  var NARROW_TOOL_RE = /\b(?:vitest|jest|pytest|py\.test)\b/i;
17637
+ var SUITE_TOOL_RE = /\b(?:phpunit|rspec|mocha|ava|playwright|cypress|ctest)\b/i;
17638
+ var SUITE_SCRIPT_RE = /\b(?:npm|pnpm|yarn|bun|turbo|nx|go|cargo|mvn|gradle|dotnet|mix|swift|flutter|dart|deno|composer)\b(?:\s+(?!(?:exec|dlx|x)\b)[^\s;&|]+)*?\s+(?:run\s+)?test(?::[\w:.-]+)?(?=$|[\s;&|])/i;
17639
+ function isUnscopedTestCommand(command) {
17640
+ const text = command.trim();
17641
+ if (!text || verifyLineDropped(text)) return false;
17642
+ if (NARROW_TOOL_RE.test(text)) return false;
17643
+ return SUITE_TOOL_RE.test(text) || SUITE_SCRIPT_RE.test(text);
17644
+ }
17539
17645
  function selectVerifyCommand(commands) {
17540
17646
  if (!commands?.length) return null;
17541
17647
  const lines = commands.map((c) => c.trim()).filter((c) => c.length > 0);
@@ -17850,6 +17956,505 @@ async function gateDoneMutation(input) {
17850
17956
  }
17851
17957
  }
17852
17958
 
17959
+ // src/doneFresh.ts
17960
+ init_netTimeout();
17961
+ import { existsSync as existsSync20 } from "fs";
17962
+ import { isAbsolute as isAbsolute8, join as join38 } from "path";
17963
+ import { execa as execa4 } from "execa";
17964
+ var FRESH_REFUSAL_LIMIT = 3;
17965
+ var FRESH_REFUSAL_MARK = "\u0441\u0432\u0435\u0436\u0430\u044F \u0431\u0430\u0437\u0430: \u0441\u0434\u0430\u0447\u0430 \u043D\u0435 \u043F\u0440\u0438\u043D\u044F\u0442\u0430";
17966
+ var FRESH_CEILING_EVENT = "\u0441\u0432\u0435\u0436\u0430\u044F \u0431\u0430\u0437\u0430: \u0442\u0440\u0438 \u043E\u0442\u043A\u0430\u0437\u0430 \u043D\u0430 \u043F\u0440\u043E\u0433\u043E\u043D \u2014 \u0441\u0434\u0430\u0447\u0430 \u043F\u0440\u0438\u043D\u044F\u0442\u0430 \u0441 \u043F\u043E\u043C\u0435\u0442\u043A\u043E\u0439, \u0447\u0442\u043E\u0431\u044B \u0434\u0440\u043E\u043D \u043D\u0435 \u0437\u0430\u0441\u0442\u0440\u044F\u043B";
17967
+ var FRESH_NO_VERIFY_EVENT = "\u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0430 \u043F\u0440\u043E\u0435\u043A\u0442\u0430 \u043D\u0435 \u0437\u0430\u0434\u0430\u043D\u0430 \u0432 \u043A\u0430\u0440\u0442\u043E\u0447\u043A\u0435";
17968
+ var FRESH_PLACEHOLDER_EVENT = "\u0432 \u043A\u0430\u0440\u0442\u043E\u0447\u043A\u0435 \u0442\u043E\u043B\u044C\u043A\u043E \u0448\u0430\u0431\u043B\u043E\u043D\u044B \u043A\u043E\u043C\u0430\u043D\u0434 \u2014 \u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0430 \u043F\u0440\u043E\u0435\u043A\u0442\u0430 \u043F\u0440\u043E\u043F\u0443\u0449\u0435\u043D\u0430";
17969
+ var FRESH_UNSCOPED_EVENT = "\u043D\u0435\u0441\u0443\u0436\u0430\u0435\u043C\u0430\u044F \u0442\u0435\u0441\u0442\u043E\u0432\u0430\u044F \u043A\u043E\u043C\u0430\u043D\u0434\u0430 \u043F\u0440\u043E\u043F\u0443\u0449\u0435\u043D\u0430";
17970
+ var FRESH_TAIL_LINES = 80;
17971
+ var FRESH_VERIFY_TIMEOUT_MS = 15 * 6e4;
17972
+ var FRESH_DEPS_HINT = "\u043F\u043E\u0441\u043B\u0435 \u0432\u043B\u0438\u0432\u0430\u043D\u0438\u044F \u0431\u0430\u0437\u044B \u043E\u0431\u043D\u043E\u0432\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043C\u043E\u0441\u0442\u0438: pnpm install";
17973
+ var FRESH_BUSY_TEXT = "\u0437\u0430\u043A\u043E\u043D\u0447\u0438 merge/rebase, \u0437\u0430\u043A\u043E\u043C\u043C\u0438\u0442\u044C, \u0437\u0430\u043F\u0443\u0448\u044C, \u0437\u043E\u0432\u0438 done()";
17974
+ var OUTPUT_CAP = 12e3;
17975
+ var DEP_DIFF_RE = /(?:^|\/)(?:pnpm-lock\.yaml|package-lock\.json|yarn\.lock|bun\.lockb?|npm-shrinkwrap\.json|schema\.prisma)$|(?:^|\/)migrations\//;
17976
+ function countFreshRefusals(events) {
17977
+ return events.filter((e) => (e.text ?? "").includes(FRESH_REFUSAL_MARK)).length;
17978
+ }
17979
+ function conflictText(base3, files) {
17980
+ const list = files.length > 0 ? files.join(", ") : "(git \u043D\u0435 \u043D\u0430\u0437\u0432\u0430\u043B \u0444\u0430\u0439\u043B\u044B)";
17981
+ return [
17982
+ `\u043A\u043E\u043D\u0444\u043B\u0438\u043A\u0442 \u0441 ${base3} \u0432 \u0444\u0430\u0439\u043B\u0430\u0445 ${list}, \u0432\u043B\u0435\u0439 \u0438 \u0440\u0430\u0437\u0440\u0435\u0448\u0438`,
17983
+ "",
17984
+ `git merge origin/${base3}`,
17985
+ "\u0440\u0430\u0437\u0440\u0435\u0448\u0438 \u043A\u043E\u043D\u0444\u043B\u0438\u043A\u0442\u044B",
17986
+ "git commit",
17987
+ "git push",
17988
+ "done()",
17989
+ "",
17990
+ "\u0421\u0434\u0430\u0447\u0430 \u043D\u0435 \u043F\u0440\u0438\u043D\u044F\u0442\u0430. \u0421\u0435\u0441\u0441\u0438\u044F \u043F\u0440\u043E\u0434\u043E\u043B\u0436\u0430\u0435\u0442\u0441\u044F."
17991
+ ].join("\n");
17992
+ }
17993
+ function pushText(base3) {
17994
+ return `\u0432\u043B\u0438\u043B origin/${base3}, \u0437\u0430\u043F\u0443\u0448\u044C`;
17995
+ }
17996
+ function divergeText(branch) {
17997
+ return `\u0432\u043B\u0435\u0439 origin/${branch}`;
17998
+ }
17999
+ function pushSteps(branch) {
18000
+ return [branch ? `git push origin ${branch}` : "git push", "done()"];
18001
+ }
18002
+ function unpushedText(base3, branch, merged) {
18003
+ const head = merged ? pushText(base3) : `\u0437\u0430\u043F\u0443\u0448\u044C: HEAD \u0435\u0449\u0451 \u043D\u0435 \u043D\u0430 origin${branch ? `/${branch}` : ""}`;
18004
+ return [head, "", ...pushSteps(branch)].join("\n");
18005
+ }
18006
+ function divergedText(branch) {
18007
+ return [
18008
+ divergeText(branch),
18009
+ "",
18010
+ `git merge origin/${branch}`,
18011
+ "\u0440\u0430\u0437\u0440\u0435\u0448\u0438 \u043A\u043E\u043D\u0444\u043B\u0438\u043A\u0442\u044B, \u0435\u0441\u043B\u0438 \u0435\u0441\u0442\u044C, \u0438 git commit",
18012
+ ...pushSteps(branch)
18013
+ ].join("\n");
18014
+ }
18015
+ function detachedText(branch, head) {
18016
+ return [
18017
+ "HEAD \u043E\u0442\u0432\u044F\u0437\u0430\u043D \u043E\u0442 \u0432\u0435\u0442\u043A\u0438, \u043D\u0438\u0447\u0435\u0433\u043E \u043D\u0435 \u0432\u043B\u0438\u0432\u0430\u043B",
18018
+ "",
18019
+ `git switch ${branch}`,
18020
+ head ? `git merge ${head}` : "\u043F\u0435\u0440\u0435\u043D\u0435\u0441\u0438 \u043A\u043E\u043C\u043C\u0438\u0442\u044B \u0441 \u043E\u0442\u0432\u044F\u0437\u0430\u043D\u043D\u043E\u0433\u043E HEAD (git merge <sha>)",
18021
+ ...pushSteps(branch)
18022
+ ].join("\n");
18023
+ }
18024
+ function freshGreenEvent(head) {
18025
+ return head ? `\u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0430 \u043F\u0440\u043E\u0435\u043A\u0442\u0430 \u0437\u0435\u043B\u0451\u043D\u0430\u044F @${head}` : "\u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0430 \u043F\u0440\u043E\u0435\u043A\u0442\u0430 \u0437\u0435\u043B\u0451\u043D\u0430\u044F";
18026
+ }
18027
+ function tailLines(text, lines = FRESH_TAIL_LINES) {
18028
+ const parts = text.replace(/\r\n/g, "\n").split("\n");
18029
+ if (parts.length > 0 && parts[parts.length - 1] === "") parts.pop();
18030
+ const tail2 = parts.length > lines ? parts.slice(-lines) : parts;
18031
+ let out = tail2.join("\n");
18032
+ if (out.length > OUTPUT_CAP) out = `\u2026
18033
+ ${out.slice(-OUTPUT_CAP)}`;
18034
+ return out;
18035
+ }
18036
+ function verifyRedText(command, output, hint) {
18037
+ const lines = [
18038
+ "\u041F\u0440\u043E\u0432\u0435\u0440\u043A\u0430 \u043F\u0440\u043E\u0435\u043A\u0442\u0430: \u0441\u0434\u0430\u0447\u0430 \u043D\u0435 \u043F\u0440\u0438\u043D\u044F\u0442\u0430.",
18039
+ "",
18040
+ `\u041A\u043E\u043C\u0430\u043D\u0434\u0430: ${command}`,
18041
+ "",
18042
+ "\u0425\u0432\u043E\u0441\u0442 \u0432\u044B\u0432\u043E\u0434\u0430:",
18043
+ tailLines(output)
18044
+ ];
18045
+ if (hint) lines.push("", hint);
18046
+ lines.push("", "\u041F\u043E\u043F\u0440\u0430\u0432\u044C \u0438 \u0437\u043E\u0432\u0438 done() \u0441\u043D\u043E\u0432\u0430. \u0421\u0435\u0441\u0441\u0438\u044F \u043F\u0440\u043E\u0434\u043E\u043B\u0436\u0430\u0435\u0442\u0441\u044F.");
18047
+ return lines.join("\n");
18048
+ }
18049
+ function partitionProjectCommands(commands) {
18050
+ if (commands == null) return { runnable: null, skippedTests: [] };
18051
+ const skippedTests = [];
18052
+ const runnable = [];
18053
+ for (const raw of commands) {
18054
+ const line = raw.trim();
18055
+ if (!line || verifyLineDropped(line)) continue;
18056
+ if (isUnscopedTestCommand(line)) {
18057
+ skippedTests.push(line);
18058
+ continue;
18059
+ }
18060
+ runnable.push(line);
18061
+ }
18062
+ return { runnable, skippedTests };
18063
+ }
18064
+ function oneLine3(text, max = 300) {
18065
+ const line = text.replace(/\s+/g, " ").trim();
18066
+ if (line.length <= max) return line || "\u0431\u0435\u0437 \u0442\u0435\u043A\u0441\u0442\u0430";
18067
+ return `${line.slice(0, max)}\u2026`;
18068
+ }
18069
+ function asText2(value) {
18070
+ return typeof value === "string" ? value : value == null ? "" : String(value);
18071
+ }
18072
+ async function gitOut(worktree, args, timeoutMs = 3e4) {
18073
+ const res = await execa4("git", args, { cwd: worktree, reject: false, timeout: timeoutMs });
18074
+ return {
18075
+ code: typeof res.exitCode === "number" ? res.exitCode : 1,
18076
+ out: asText2(res.stdout),
18077
+ err: asText2(res.stderr)
18078
+ };
18079
+ }
18080
+ async function isAncestor(worktree, ancestor, descendant) {
18081
+ const res = await gitOut(worktree, ["merge-base", "--is-ancestor", ancestor, descendant]);
18082
+ return res.code === 0;
18083
+ }
18084
+ async function gitMarker(worktree, name) {
18085
+ const res = await gitOut(worktree, ["rev-parse", "--git-path", name]);
18086
+ if (res.code !== 0) return false;
18087
+ const rel = res.out.trim();
18088
+ if (!rel) return false;
18089
+ const full = isAbsolute8(rel) ? rel : join38(worktree, rel);
18090
+ return existsSync20(full);
18091
+ }
18092
+ async function unfinishedGit(worktree) {
18093
+ const inside = await gitOut(worktree, ["rev-parse", "--is-inside-work-tree"]);
18094
+ if (inside.code !== 0 || inside.out.trim() !== "true") return null;
18095
+ for (const name of ["MERGE_HEAD", "REBASE_HEAD", "CHERRY_PICK_HEAD", "rebase-merge", "rebase-apply"]) {
18096
+ if (await gitMarker(worktree, name)) return name;
18097
+ }
18098
+ const staged = await gitOut(worktree, ["diff", "--cached", "--quiet"]);
18099
+ if (staged.code !== 0) return "index";
18100
+ const dirty = await gitOut(worktree, ["diff", "--quiet"]);
18101
+ if (dirty.code !== 0) return "dirty";
18102
+ return null;
18103
+ }
18104
+ async function attachedBranch(worktree) {
18105
+ const ref = await gitOut(worktree, ["symbolic-ref", "-q", "--short", "HEAD"]);
18106
+ const name = ref.out.trim();
18107
+ return ref.code === 0 && name ? name : null;
18108
+ }
18109
+ async function previousBranch(worktree) {
18110
+ const prev = await gitOut(worktree, ["rev-parse", "--abbrev-ref", "@{-1}"]);
18111
+ const name = prev.out.trim();
18112
+ if (prev.code !== 0 || !name || name === "HEAD") return void 0;
18113
+ return name;
18114
+ }
18115
+ async function publishState(worktree, branch) {
18116
+ const remote = `origin/${branch}`;
18117
+ const remoteExists = (await gitOut(worktree, ["rev-parse", "--verify", "--quiet", `${remote}^{commit}`])).code === 0;
18118
+ if (!remoteExists) return { needsPush: true };
18119
+ const onOrigin = await isAncestor(worktree, "HEAD", remote);
18120
+ if (onOrigin) return { needsPush: false };
18121
+ if (await isAncestor(worktree, remote, "HEAD")) return { needsPush: true };
18122
+ return { needsPush: false, divergedFrom: branch };
18123
+ }
18124
+ async function diffTouchesDeps(worktree, before, after) {
18125
+ const diff = await gitOut(worktree, ["diff", "--name-only", before, after]);
18126
+ if (diff.code !== 0) return false;
18127
+ return diff.out.split("\n").some((line) => DEP_DIFF_RE.test(line.trim()));
18128
+ }
18129
+ function idle(failed) {
18130
+ const result = { clean: true, changed: false, needsPush: false, conflicts: [] };
18131
+ if (failed) result.failed = failed;
18132
+ return result;
18133
+ }
18134
+ function busyResult(why) {
18135
+ return { clean: true, changed: false, needsPush: false, conflicts: [], busy: why };
18136
+ }
18137
+ async function integrateOriginBase(worktree, base3, signal) {
18138
+ if (signal?.aborted) return idle("\u043E\u0442\u043C\u0435\u043D\u0435\u043D\u043E");
18139
+ const inside = await gitOut(worktree, ["rev-parse", "--is-inside-work-tree"]);
18140
+ if (inside.code !== 0 || inside.out.trim() !== "true") {
18141
+ return idle(oneLine3(inside.err || "\u043D\u0435 \u0440\u0430\u0431\u043E\u0447\u0435\u0435 \u0434\u0435\u0440\u0435\u0432\u043E git"));
18142
+ }
18143
+ const whyBusy = await unfinishedGit(worktree);
18144
+ if (whyBusy) return busyResult(whyBusy);
18145
+ const before = await gitOut(worktree, ["rev-parse", "HEAD"]);
18146
+ if (before.code !== 0) return idle(oneLine3(before.err || "\u043D\u0435\u0442 HEAD"));
18147
+ const beforeSha = before.out.trim();
18148
+ const branch = await attachedBranch(worktree);
18149
+ if (!branch) {
18150
+ const prev = await previousBranch(worktree);
18151
+ return {
18152
+ clean: true,
18153
+ changed: false,
18154
+ needsPush: false,
18155
+ conflicts: [],
18156
+ detached: true,
18157
+ ...beforeSha ? { head: beforeSha } : {},
18158
+ ...prev ? { branch: prev } : {}
18159
+ };
18160
+ }
18161
+ if (signal?.aborted) return idle("\u043E\u0442\u043C\u0435\u043D\u0435\u043D\u043E");
18162
+ const fetched = await runBounded(
18163
+ { file: "git", args: ["fetch", "--quiet", "origin"] },
18164
+ { cwd: worktree, timeoutMs: GIT_HEAVY_NET_TIMEOUT_MS, ...signal ? { signal } : {} }
18165
+ );
18166
+ if (fetched.aborted || signal?.aborted) return idle("\u043E\u0442\u043C\u0435\u043D\u0435\u043D\u043E");
18167
+ if (fetched.timedOut) return idle("git fetch: \u0442\u0430\u0439\u043C\u0430\u0443\u0442");
18168
+ if (fetched.code !== 0) return idle(oneLine3(fetched.stderr || fetched.stdout || "git fetch \u043D\u0435 \u043F\u0440\u043E\u0448\u0451\u043B"));
18169
+ const settle = async (partial) => {
18170
+ const published = await publishState(worktree, branch);
18171
+ return { ...partial, ...published, branch };
18172
+ };
18173
+ const ref = `origin/${base3}`;
18174
+ const hasRef = await gitOut(worktree, ["rev-parse", "--verify", "--quiet", `${ref}^{commit}`]);
18175
+ if (hasRef.code !== 0) return settle({ clean: true, changed: false, conflicts: [], failed: `\u043D\u0435\u0442 ${ref}` });
18176
+ const hadMerge = await gitMarker(worktree, "MERGE_HEAD");
18177
+ const mergeRun = await runBounded(
18178
+ {
18179
+ file: "git",
18180
+ args: ["-c", "merge.ff=true", "-c", "commit.gpgsign=false", "merge", "--no-edit", "--no-verify", ref]
18181
+ },
18182
+ { cwd: worktree, timeoutMs: 6e4, ...signal ? { signal } : {} }
18183
+ );
18184
+ if (mergeRun.aborted || signal?.aborted) {
18185
+ if (await gitMarker(worktree, "MERGE_HEAD") && !hadMerge) await gitOut(worktree, ["merge", "--abort"]);
18186
+ return idle("\u043E\u0442\u043C\u0435\u043D\u0435\u043D\u043E");
18187
+ }
18188
+ if (mergeRun.timedOut) {
18189
+ if (await gitMarker(worktree, "MERGE_HEAD") && !hadMerge) await gitOut(worktree, ["merge", "--abort"]);
18190
+ return settle({ clean: true, changed: false, conflicts: [], failed: "git merge: \u0442\u0430\u0439\u043C\u0430\u0443\u0442" });
18191
+ }
18192
+ const merge = {
18193
+ code: typeof mergeRun.code === "number" ? mergeRun.code : 1,
18194
+ out: mergeRun.stdout,
18195
+ err: mergeRun.stderr
18196
+ };
18197
+ if (merge.code === 0) {
18198
+ const after = (await gitOut(worktree, ["rev-parse", "HEAD"])).out.trim();
18199
+ const changed = after !== beforeSha;
18200
+ const depsStale = changed && beforeSha !== "" && after !== "" && await diffTouchesDeps(worktree, beforeSha, after);
18201
+ return settle({
18202
+ clean: true,
18203
+ changed,
18204
+ conflicts: [],
18205
+ ...after ? { head: after } : {},
18206
+ ...depsStale ? { depsStale: true } : {}
18207
+ });
18208
+ }
18209
+ const unmerged = await gitOut(worktree, ["diff", "--name-only", "--diff-filter=U"]);
18210
+ const conflicts = unmerged.out.split("\n").map((p) => p.trim()).filter((p) => p.length > 0);
18211
+ const hasMerge = await gitMarker(worktree, "MERGE_HEAD");
18212
+ if (hasMerge && !hadMerge) await gitOut(worktree, ["merge", "--abort"]);
18213
+ if (conflicts.length > 0) return { clean: false, changed: false, needsPush: false, conflicts };
18214
+ if (hasMerge && hadMerge) return busyResult("MERGE_HEAD");
18215
+ return {
18216
+ clean: true,
18217
+ changed: false,
18218
+ needsPush: false,
18219
+ conflicts: [],
18220
+ rejected: oneLine3(merge.err || merge.out || "merge \u043D\u0435 \u043F\u0440\u043E\u0448\u0451\u043B")
18221
+ };
18222
+ }
18223
+ function publishHeld(integrated) {
18224
+ if (integrated.busy || integrated.rejected || !integrated.clean) return false;
18225
+ if (integrated.detached) return true;
18226
+ if (integrated.divergedFrom) return true;
18227
+ return integrated.needsPush;
18228
+ }
18229
+ function advice(base3, integrated, runBranch) {
18230
+ if (!publishHeld(integrated)) return "";
18231
+ if (integrated.detached) return detachedText(runBranch ?? integrated.branch ?? "<\u0432\u0435\u0442\u043A\u0430 PR>", integrated.head);
18232
+ if (integrated.divergedFrom) return divergedText(integrated.divergedFrom);
18233
+ return unpushedText(base3, integrated.branch ?? runBranch, integrated.changed);
18234
+ }
18235
+ function pushRefusal(base3, integrated, events, runBranch) {
18236
+ const line = advice(base3, integrated, runBranch);
18237
+ const remote = integrated.divergedFrom;
18238
+ const target = remote ?? integrated.branch ?? runBranch;
18239
+ const why = target ? `HEAD \u0446\u0435\u043B\u0438\u043A\u043E\u043C \u043D\u0435 \u043D\u0430 origin/${target}` : "HEAD \u0446\u0435\u043B\u0438\u043A\u043E\u043C \u043D\u0435 \u043D\u0430 origin";
18240
+ const event = remote ? `${FRESH_REFUSAL_MARK}: \u0432\u043B\u0435\u0439 origin/${remote}` : integrated.changed ? `${FRESH_REFUSAL_MARK}: \u0432\u043B\u0438\u043B origin/${base3}, \u0436\u0434\u0443 push` : `${FRESH_REFUSAL_MARK}: ${why}, \u0436\u0434\u0443 push`;
18241
+ return {
18242
+ kind: "refuse",
18243
+ text: `${line}
18244
+
18245
+ \u0421\u0434\u0430\u0447\u0430 \u043D\u0435 \u043F\u0440\u0438\u043D\u044F\u0442\u0430, \u043F\u043E\u043A\u0430 ${why}. \u0421\u0435\u0441\u0441\u0438\u044F \u043F\u0440\u043E\u0434\u043E\u043B\u0436\u0430\u0435\u0442\u0441\u044F.`,
18246
+ event,
18247
+ events
18248
+ };
18249
+ }
18250
+ function ceilingNote(base3, integrated, runBranch) {
18251
+ const line = advice(base3, integrated, runBranch);
18252
+ const parts = [line, `\u26A0\uFE0F ${FRESH_CEILING_EVENT}`].filter((p) => p.length > 0);
18253
+ return `
18254
+
18255
+ ${parts.join("\n\n")}`;
18256
+ }
18257
+ function seenGreenAt(events, head) {
18258
+ if (!head) return false;
18259
+ const mark = freshGreenEvent(head);
18260
+ return events.some((e) => (e.text ?? "").includes(mark));
18261
+ }
18262
+ async function gateDoneFresh(input) {
18263
+ if (!mutationGateApplies(input.run)) return { kind: "skip" };
18264
+ if (input.signal?.aborted) return { kind: "cancelled" };
18265
+ const base3 = mutationBaseBranch(input.run?.base_branch);
18266
+ const runBranch = input.run?.branch?.trim() || void 0;
18267
+ const ceiling = countFreshRefusals(input.events) >= FRESH_REFUSAL_LIMIT;
18268
+ let integrated;
18269
+ try {
18270
+ integrated = await input.integrate({
18271
+ worktree: input.worktree,
18272
+ base: base3,
18273
+ ...input.signal ? { signal: input.signal } : {}
18274
+ });
18275
+ } catch (e) {
18276
+ if (input.signal?.aborted) return { kind: "cancelled" };
18277
+ integrated = idle(oneLine3(e instanceof Error ? e.message : String(e)));
18278
+ }
18279
+ if (input.signal?.aborted) return { kind: "cancelled" };
18280
+ const events = [];
18281
+ const say = async (line) => {
18282
+ if (input.emit) await input.emit(line);
18283
+ else events.push(line);
18284
+ };
18285
+ const counted = (text, event) => {
18286
+ if (!ceiling && !events.includes(FRESH_CEILING_EVENT)) return { kind: "refuse", text, event, events };
18287
+ if (!events.includes(FRESH_CEILING_EVENT)) events.push(FRESH_CEILING_EVENT);
18288
+ return null;
18289
+ };
18290
+ let releasedByCeiling = false;
18291
+ if (integrated.busy) {
18292
+ const text = `${FRESH_BUSY_TEXT}
18293
+
18294
+ \u0421\u0434\u0430\u0447\u0430 \u043D\u0435 \u043F\u0440\u0438\u043D\u044F\u0442\u0430. \u0421\u0435\u0441\u0441\u0438\u044F \u043F\u0440\u043E\u0434\u043E\u043B\u0436\u0430\u0435\u0442\u0441\u044F.`;
18295
+ const held = counted(text, `${FRESH_REFUSAL_MARK}: ${FRESH_BUSY_TEXT} (${integrated.busy})`);
18296
+ if (held) return held;
18297
+ releasedByCeiling = true;
18298
+ } else if (integrated.detached) {
18299
+ const text = `${advice(base3, integrated, runBranch)}
18300
+
18301
+ \u0421\u0434\u0430\u0447\u0430 \u043D\u0435 \u043F\u0440\u0438\u043D\u044F\u0442\u0430, \u043F\u043E\u043A\u0430 HEAD \u043D\u0435 \u043D\u0430 \u0432\u0435\u0442\u043A\u0435 \u0438 \u043D\u0435 \u043D\u0430 origin. \u0421\u0435\u0441\u0441\u0438\u044F \u043F\u0440\u043E\u0434\u043E\u043B\u0436\u0430\u0435\u0442\u0441\u044F.`;
18302
+ const held = counted(text, `${FRESH_REFUSAL_MARK}: HEAD \u043E\u0442\u0432\u044F\u0437\u0430\u043D \u043E\u0442 \u0432\u0435\u0442\u043A\u0438`);
18303
+ if (held) return held;
18304
+ releasedByCeiling = true;
18305
+ } else if (!integrated.clean) {
18306
+ const text = conflictText(base3, integrated.conflicts);
18307
+ const event = `${FRESH_REFUSAL_MARK}: \u043A\u043E\u043D\u0444\u043B\u0438\u043A\u0442 \u0441 ${base3} \u0432 ${integrated.conflicts.join(", ") || "\u0444\u0430\u0439\u043B\u0430\u0445"}`;
18308
+ const held = counted(text, event);
18309
+ if (held) return held;
18310
+ releasedByCeiling = true;
18311
+ } else if (integrated.rejected) {
18312
+ const text = [
18313
+ `\u0441\u043B\u0438\u044F\u043D\u0438\u0435 \u0441 ${base3} \u043D\u0435 \u043F\u0440\u043E\u0448\u043B\u043E: ${integrated.rejected}`,
18314
+ "",
18315
+ "\u0421\u0434\u0430\u0447\u0430 \u043D\u0435 \u043F\u0440\u0438\u043D\u044F\u0442\u0430. \u0421\u0435\u0441\u0441\u0438\u044F \u043F\u0440\u043E\u0434\u043E\u043B\u0436\u0430\u0435\u0442\u0441\u044F."
18316
+ ].join("\n");
18317
+ const held = counted(text, `${FRESH_REFUSAL_MARK}: \u0441\u043B\u0438\u044F\u043D\u0438\u0435 \u0441 ${base3} \u043D\u0435 \u043F\u0440\u043E\u0448\u043B\u043E`);
18318
+ if (held) return held;
18319
+ releasedByCeiling = true;
18320
+ } else if (integrated.failed) {
18321
+ const held = publishHeld(integrated);
18322
+ await say(`\u0441\u0432\u0435\u0436\u0443\u044E \u0431\u0430\u0437\u0443 \u043D\u0435 \u0432\u043B\u0438\u043B (${oneLine3(integrated.failed)})${held ? "" : " \u2014 \u0441\u0434\u0430\u0447\u0430 \u043D\u0435 \u0431\u043B\u043E\u043A\u0438\u0440\u0443\u0435\u0442\u0441\u044F"}`);
18323
+ } else if (integrated.changed) {
18324
+ await say(`\u0432\u043B\u0438\u043B origin/${base3}`);
18325
+ }
18326
+ const afterChecks = (hint) => {
18327
+ const hitCeiling = events.includes(FRESH_CEILING_EVENT);
18328
+ const wantPush = publishHeld(integrated);
18329
+ if (wantPush) {
18330
+ if (!ceiling && !hitCeiling) {
18331
+ const refused = pushRefusal(base3, integrated, events, runBranch);
18332
+ if (hint && !refused.text.includes(hint)) refused.text = `${refused.text}
18333
+
18334
+ ${hint}`;
18335
+ return refused;
18336
+ }
18337
+ if (!hitCeiling) events.push(FRESH_CEILING_EVENT);
18338
+ const note2 = ceilingNote(base3, integrated, runBranch);
18339
+ return { kind: "accept", events, note: hint ? `${note2}
18340
+
18341
+ ${hint}` : note2 };
18342
+ }
18343
+ const note = hitCeiling ? ceilingNote(base3, integrated, runBranch) : "";
18344
+ return { kind: "accept", events, note: hint && !note.includes(hint) ? `${note}
18345
+
18346
+ ${hint}`.trim() : note };
18347
+ };
18348
+ if (releasedByCeiling) return afterChecks();
18349
+ if (seenGreenAt(input.events, integrated.head)) return afterChecks();
18350
+ let depsHint;
18351
+ if (integrated.depsStale && !integrated.failed && !integrated.busy) {
18352
+ depsHint = FRESH_DEPS_HINT;
18353
+ if (input.ensureDeps) {
18354
+ try {
18355
+ await input.ensureDeps({
18356
+ worktree: input.worktree,
18357
+ ...input.signal ? { signal: input.signal } : {}
18358
+ });
18359
+ } catch (e) {
18360
+ if (input.signal?.aborted) return { kind: "cancelled" };
18361
+ await say(`\u0437\u0430\u0432\u0438\u0441\u0438\u043C\u043E\u0441\u0442\u0438 \u043F\u043E\u0441\u043B\u0435 \u0441\u043B\u0438\u044F\u043D\u0438\u044F \u043D\u0435 \u0432\u0441\u0442\u0430\u043B\u0438 (${oneLine3(e instanceof Error ? e.message : String(e))})`);
18362
+ }
18363
+ }
18364
+ }
18365
+ let raw;
18366
+ try {
18367
+ raw = await input.loadCommands();
18368
+ } catch (e) {
18369
+ if (input.signal?.aborted) return { kind: "cancelled" };
18370
+ const why = oneLine3(e instanceof Error ? e.message : String(e));
18371
+ events.push(`\u043A\u0430\u0440\u0442\u043E\u0447\u043A\u0443 \u0440\u0435\u043F\u043E\u0437\u0438\u0442\u043E\u0440\u0438\u044F \u043D\u0435 \u043F\u0440\u043E\u0447\u0438\u0442\u0430\u043B\u0438 (${why}) \u2014 \u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0430 \u043F\u0440\u043E\u0435\u043A\u0442\u0430 \u043F\u0440\u043E\u043F\u0443\u0449\u0435\u043D\u0430`);
18372
+ return afterChecks(depsHint);
18373
+ }
18374
+ const split = partitionProjectCommands(raw);
18375
+ const runnable = split.runnable;
18376
+ const hadLines = (raw ?? []).some((c) => c.trim().length > 0);
18377
+ if (split.skippedTests.length > 0) {
18378
+ await say(`${FRESH_UNSCOPED_EVENT}: ${split.skippedTests.join("; ")}`);
18379
+ }
18380
+ if (raw == null || !hadLines) {
18381
+ events.push(FRESH_NO_VERIFY_EVENT);
18382
+ return afterChecks(depsHint);
18383
+ }
18384
+ if (!runnable || runnable.length === 0) {
18385
+ if (split.skippedTests.length === 0) events.push(FRESH_PLACEHOLDER_EVENT);
18386
+ return afterChecks(depsHint);
18387
+ }
18388
+ if (input.signal?.aborted) return { kind: "cancelled" };
18389
+ const shown = runnable.join(" && ");
18390
+ await say(`\u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0430 \u043F\u0440\u043E\u0435\u043A\u0442\u0430: ${oneLine3(shown, 400)}`);
18391
+ let ran;
18392
+ try {
18393
+ ran = await input.runVerify({
18394
+ worktree: input.worktree,
18395
+ commands: runnable,
18396
+ ...input.signal ? { signal: input.signal } : {}
18397
+ });
18398
+ } catch (e) {
18399
+ if (input.signal?.aborted) return { kind: "cancelled" };
18400
+ const why = oneLine3(e instanceof Error ? e.message : String(e));
18401
+ events.push(`\u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0430 \u043F\u0440\u043E\u0435\u043A\u0442\u0430 \u043D\u0435 \u0437\u0430\u043F\u0443\u0441\u0442\u0438\u043B\u0430\u0441\u044C (${why}) \u2014 \u0441\u0434\u0430\u0447\u0430 \u043D\u0435 \u0431\u043B\u043E\u043A\u0438\u0440\u0443\u0435\u0442\u0441\u044F`);
18402
+ return afterChecks(depsHint);
18403
+ }
18404
+ if (input.signal?.aborted) return { kind: "cancelled" };
18405
+ if (ran.blocked) {
18406
+ const why = ran.reason ?? "\u043D\u0435 \u0437\u0430\u043F\u0443\u0441\u0442\u0438\u043B\u0430\u0441\u044C";
18407
+ events.push(`\u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0430 \u043F\u0440\u043E\u0435\u043A\u0442\u0430 \u043D\u0435 \u0437\u0430\u043F\u0443\u0441\u0442\u0438\u043B\u0430\u0441\u044C (${why}: ${ran.command}) \u2014 \u0441\u0434\u0430\u0447\u0430 \u043D\u0435 \u0431\u043B\u043E\u043A\u0438\u0440\u0443\u0435\u0442\u0441\u044F`);
18408
+ return afterChecks(depsHint);
18409
+ }
18410
+ if (!ran.ok) {
18411
+ const prefix = advice(base3, integrated, runBranch);
18412
+ const text = `${prefix ? `${prefix}
18413
+
18414
+ ` : ""}${verifyRedText(ran.command, ran.output, depsHint)}`;
18415
+ const event = `${FRESH_REFUSAL_MARK}: \u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0430 \u043F\u0440\u043E\u0435\u043A\u0442\u0430 \u043A\u0440\u0430\u0441\u043D\u0430\u044F (${ran.command})`;
18416
+ const held = counted(text, event);
18417
+ if (held) return held;
18418
+ events.push(`\u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0430 \u043F\u0440\u043E\u0435\u043A\u0442\u0430 \u043A\u0440\u0430\u0441\u043D\u0430\u044F, \u043F\u043E\u0442\u043E\u043B\u043E\u043A \u043E\u0442\u043A\u0430\u0437\u043E\u0432 \u0438\u0441\u0447\u0435\u0440\u043F\u0430\u043D: ${ran.command}`);
18419
+ return { kind: "accept", events, note: ceilingNote(base3, integrated, runBranch) };
18420
+ }
18421
+ events.push(freshGreenEvent(integrated.head));
18422
+ if (!publishHeld(integrated)) return afterChecks();
18423
+ return afterChecks(depsHint);
18424
+ }
18425
+ async function runProjectVerify(worktree, commands, signal) {
18426
+ const env = { ...process.env };
18427
+ delete env.VITEST;
18428
+ delete env.VITEST_WORKER_ID;
18429
+ delete env.VITEST_POOL_ID;
18430
+ const deadline = Date.now() + FRESH_VERIFY_TIMEOUT_MS;
18431
+ const chunks2 = [];
18432
+ const joined = commands.join(" && ");
18433
+ for (const command of commands) {
18434
+ if (signal?.aborted) {
18435
+ return { ok: false, command, output: chunks2.join("\n"), blocked: true, reason: "\u043E\u0442\u043C\u0435\u043D\u0435\u043D\u043E" };
18436
+ }
18437
+ const remaining = deadline - Date.now();
18438
+ if (remaining <= 0) {
18439
+ return { ok: false, command, output: chunks2.join("\n"), blocked: true, reason: "\u0442\u0430\u0439\u043C\u0430\u0443\u0442" };
18440
+ }
18441
+ const res = await runBounded(
18442
+ { shell: command },
18443
+ { cwd: worktree, env, timeoutMs: remaining, ...signal ? { signal } : {} }
18444
+ );
18445
+ const out = [res.stdout, res.stderr].filter((s) => s.length > 0).join("\n");
18446
+ if (out) chunks2.push(out);
18447
+ if (res.aborted || signal?.aborted) {
18448
+ return { ok: false, command, output: chunks2.join("\n"), blocked: true, reason: "\u043E\u0442\u043C\u0435\u043D\u0435\u043D\u043E" };
18449
+ }
18450
+ if (res.timedOut) {
18451
+ return { ok: false, command, output: chunks2.join("\n"), blocked: true, reason: "\u0442\u0430\u0439\u043C\u0430\u0443\u0442" };
18452
+ }
18453
+ if (res.code !== 0) return { ok: false, command, output: chunks2.join("\n") };
18454
+ }
18455
+ return { ok: true, command: joined, output: chunks2.join("\n") };
18456
+ }
18457
+
17853
18458
  // src/droneServer.ts
17854
18459
  init_src();
17855
18460
  var mutationGateInFlight = /* @__PURE__ */ new Set();
@@ -18667,6 +19272,7 @@ ${report}${shots.warning}`,
18667
19272
  }
18668
19273
  let reportBody = report;
18669
19274
  let mutationNote = "";
19275
+ let freshNote = "";
18670
19276
  if (mutationGateApplies(run2)) {
18671
19277
  const flightKey = mutationFlightKey(run2?.id);
18672
19278
  if (extra.signal.aborted) {
@@ -18692,6 +19298,48 @@ ${report}${shots.warning}`,
18692
19298
  return null;
18693
19299
  }
18694
19300
  };
19301
+ const fresh = await gateDoneFresh({
19302
+ run: run2,
19303
+ worktree,
19304
+ events: priorEvents,
19305
+ ...extra.signal ? { signal: extra.signal } : {},
19306
+ emit: (event) => store.addEvent(null, "step", event),
19307
+ integrate: (req) => opts.integrateBase ? opts.integrateBase(req) : integrateOriginBase(req.worktree, req.base, req.signal),
19308
+ loadCommands: async () => {
19309
+ if (opts.projectCommands) return opts.projectCommands();
19310
+ const read = opts.taskless?.repoVerifyCommands;
19311
+ if (!read) return null;
19312
+ const repo = await remoteRepoFullName(worktree).catch(() => null);
19313
+ if (!repo) return null;
19314
+ const slug = opts.expectedTaskSlug ?? run2?.task_slug;
19315
+ return await read(repo, slug || void 0);
19316
+ },
19317
+ ensureDeps: async (req) => {
19318
+ const prepare = await loadPrepare();
19319
+ const report2 = await ensureWorktreeDeps(req.worktree, {
19320
+ override: prepare,
19321
+ skipOptional: true,
19322
+ ...req.signal ? { signal: req.signal } : {}
19323
+ });
19324
+ if (report2.outcome === "failed" || report2.outcome === "blocked") {
19325
+ const why = [...report2.failed, ...report2.blocked].join(", ") || report2.outcome;
19326
+ throw new Error(why);
19327
+ }
19328
+ },
19329
+ runVerify: (req) => opts.projectVerify ? opts.projectVerify(req) : runProjectVerify(req.worktree, req.commands, req.signal)
19330
+ });
19331
+ if (fresh.kind === "cancelled" || extra.signal.aborted) {
19332
+ return { content: [{ type: "text", text: "\u043E\u0442\u043C\u0435\u043D\u0435\u043D\u043E" }], isError: true };
19333
+ }
19334
+ if (fresh.kind === "refuse") {
19335
+ for (const ev of fresh.events) await store.addEvent(null, "step", ev);
19336
+ await store.addEvent(null, "step", fresh.event);
19337
+ return { content: [{ type: "text", text: fresh.text }], isError: true };
19338
+ }
19339
+ if (fresh.kind === "accept") {
19340
+ for (const ev of fresh.events) await store.addEvent(null, "step", ev);
19341
+ freshNote = fresh.note;
19342
+ }
18695
19343
  const outcome = await gateDoneMutation({
18696
19344
  run: run2,
18697
19345
  worktree,
@@ -18788,7 +19436,7 @@ ${reportBody}${shots.warning}`,
18788
19436
  await postReport(reportSlug(run2.task_slug), t.cycle ?? run2.review_cycle ?? 0);
18789
19437
  const rulesNote = await offerRules(reportSlug(run2.task_slug));
18790
19438
  const zoneNote = await zoneMemoryNote(reportSlug(run2.task_slug));
18791
- const tail2 = `${shotsNote(shots)}${rulesNote}${zoneNote}${mutationNote}`;
19439
+ const tail2 = `${shotsNote(shots)}${rulesNote}${zoneNote}${freshNote}${mutationNote}`;
18792
19440
  if (t.isFixIteration) {
18793
19441
  return { content: [{ type: "text", text: `\u043F\u0440\u0438\u043D\u044F\u0442\u043E, \u0443\u0448\u043B\u043E \u043D\u0430 \u0440\u0435-\u0440\u0435\u0432\u044C\u044E (\u0444\u0438\u043A\u0441-\u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044F)${tail2}` }] };
18794
19442
  }
@@ -18801,7 +19449,7 @@ ${reportBody}${shots.warning}`,
18801
19449
  else await store.addEvent(null, "step", `\u043E\u0442\u0447\u0451\u0442 \u0434\u0440\u043E\u043D\u0430 (\u0437\u0430\u0434\u0430\u0447\u0430 \u043D\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043D\u0430 \u2014 \u043F\u0440\u043E\u0433\u043E\u043D\u0430 \u043D\u0435\u0442 \u0432 \u0441\u0442\u043E\u0440\u0435): ${reportBody}`);
18802
19450
  const fallbackRulesNote = await offerRules(fallbackSlug);
18803
19451
  const fallbackZoneNote = await zoneMemoryNote(fallbackSlug);
18804
- return { content: [{ type: "text", text: `\u043F\u0440\u0438\u043D\u044F\u0442\u043E, \u0443\u0448\u043B\u043E \u043D\u0430 \u0440\u0435\u0432\u044C\u044E${shotsNote(shots)}${fallbackRulesNote}${fallbackZoneNote}${mutationNote}` }] };
19452
+ return { content: [{ type: "text", text: `\u043F\u0440\u0438\u043D\u044F\u0442\u043E, \u0443\u0448\u043B\u043E \u043D\u0430 \u0440\u0435\u0432\u044C\u044E${shotsNote(shots)}${fallbackRulesNote}${fallbackZoneNote}${freshNote}${mutationNote}` }] };
18805
19453
  }
18806
19454
  await store.updateRun(null, { status: "done" });
18807
19455
  await store.addEvent(null, "done", pr_url ? `\u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043D\u043E \u0431\u0435\u0437 GitHub-PR (${pr_url})` : "\u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043D\u043E \u0431\u0435\u0437 GitHub-PR");
@@ -20375,23 +21023,23 @@ async function prodClearMergeIntent(runId, deps = {}) {
20375
21023
  }
20376
21024
 
20377
21025
  // src/envGate.ts
20378
- import { existsSync as existsSync22 } from "fs";
20379
- import { join as join39 } from "path";
21026
+ import { existsSync as existsSync23 } from "fs";
21027
+ import { join as join40 } from "path";
20380
21028
  import { createConnection } from "net";
20381
- import { execa as execa4 } from "execa";
21029
+ import { execa as execa5 } from "execa";
20382
21030
 
20383
21031
  // src/platform.ts
20384
21032
  init_src();
20385
- import { accessSync as accessSync2, constants as constants2, existsSync as existsSync21, readFileSync as readFileSync27, realpathSync as realpathSync4 } from "fs";
20386
- import { delimiter as delimiter2, join as join38, posix as posix2, win32 } from "path";
21033
+ import { accessSync as accessSync2, constants as constants2, existsSync as existsSync22, readFileSync as readFileSync27, realpathSync as realpathSync4 } from "fs";
21034
+ import { delimiter as delimiter2, join as join39, posix as posix2, win32 } from "path";
20387
21035
  function resolveCommandPath(name, env = process.env, platform = process.platform) {
20388
- if (name.includes("/") || name.includes("\\")) return existsSync21(name) ? name : null;
21036
+ if (name.includes("/") || name.includes("\\")) return existsSync22(name) ? name : null;
20389
21037
  const dirs = (env.PATH ?? env.Path ?? "").split(delimiter2).filter(Boolean);
20390
21038
  const exts = platform === "win32" ? (env.PATHEXT ?? ".EXE;.CMD;.BAT").split(";").filter(Boolean) : [""];
20391
21039
  for (const dir of dirs) {
20392
21040
  for (const ext of exts) {
20393
- const candidate = join38(dir, name + ext);
20394
- if (existsSync21(candidate)) return candidate;
21041
+ const candidate = join39(dir, name + ext);
21042
+ if (existsSync22(candidate)) return candidate;
20395
21043
  }
20396
21044
  }
20397
21045
  return null;
@@ -20560,8 +21208,8 @@ var COMPOSE_MARKERS = [
20560
21208
  "compose.yaml"
20561
21209
  ];
20562
21210
  function detectRequirements(repo, io = {}) {
20563
- const exists = io.exists ?? existsSync22;
20564
- const marker = COMPOSE_MARKERS.find((f) => exists(join39(repo, f)));
21211
+ const exists = io.exists ?? existsSync23;
21212
+ const marker = COMPOSE_MARKERS.find((f) => exists(join40(repo, f)));
20565
21213
  return marker ? [{ kind: "docker", raw: `docker (\u0434\u0435\u0442\u0435\u043A\u0442: ${marker})` }] : [];
20566
21214
  }
20567
21215
  function resolveRequirements(repo, declared, io = {}) {
@@ -20570,7 +21218,7 @@ function resolveRequirements(repo, declared, io = {}) {
20570
21218
  }
20571
21219
  async function probeDockerDaemon() {
20572
21220
  try {
20573
- const res = await execa4("docker", ["version", "--format", "{{.Server.Version}}"], {
21221
+ const res = await execa5("docker", ["version", "--format", "{{.Server.Version}}"], {
20574
21222
  timeout: PROBE_TIMEOUT_MS,
20575
21223
  reject: false
20576
21224
  });
@@ -22389,9 +23037,9 @@ function closeWebServer(server) {
22389
23037
  // src/hostCommands.ts
22390
23038
  init_src();
22391
23039
  import { readFileSync as readFileSync28, renameSync as renameSync10, writeFileSync as writeFileSync18 } from "fs";
22392
- import { join as join40 } from "path";
23040
+ import { join as join41 } from "path";
22393
23041
  function hostCommandStatePath(home) {
22394
- return join40(home, "host-command.json");
23042
+ return join41(home, "host-command.json");
22395
23043
  }
22396
23044
  function readState(path) {
22397
23045
  try {
@@ -22565,20 +23213,20 @@ async function doRestart(cmd, opts, note) {
22565
23213
 
22566
23214
  // src/selfUpdate.ts
22567
23215
  init_git();
22568
- import { existsSync as existsSync23 } from "fs";
22569
- import { join as join41 } from "path";
23216
+ import { existsSync as existsSync24 } from "fs";
23217
+ import { join as join42 } from "path";
22570
23218
  import { $ as $6 } from "execa";
22571
23219
 
22572
23220
  // src/cliIo.ts
22573
23221
  import { createInterface } from "readline/promises";
22574
- import { execa as execa5 } from "execa";
23222
+ import { execa as execa6 } from "execa";
22575
23223
  function readCommandOutcome(result) {
22576
23224
  if (typeof result === "number") return { exitCode: result, output: "" };
22577
23225
  return { exitCode: result.exitCode, output: `${result.stdout ?? ""}
22578
23226
  ${result.stderr ?? ""}` };
22579
23227
  }
22580
23228
  async function execCaptured(command) {
22581
- const res = await execa5(command, {
23229
+ const res = await execa6(command, {
22582
23230
  shell: true,
22583
23231
  reject: false,
22584
23232
  stdout: ["pipe", "inherit"],
@@ -22599,7 +23247,7 @@ function tail(text, max = 400) {
22599
23247
  }
22600
23248
  async function runSelfUpdate(io) {
22601
23249
  const run2 = io.run ?? defaultRun;
22602
- const exists = io.exists ?? existsSync23;
23250
+ const exists = io.exists ?? existsSync24;
22603
23251
  const repo = io.repo;
22604
23252
  await io.onStep("fetch", "\u0442\u044F\u043D\u0443 \u0441\u0432\u0435\u0436\u0438\u0439 \u043A\u043E\u0434");
22605
23253
  const fetched = await run2("git", ["-C", repo, "fetch", "--quiet", "origin"], repo);
@@ -22628,7 +23276,7 @@ async function runSelfUpdate(io) {
22628
23276
  };
22629
23277
  }
22630
23278
  await io.onStep("install", "\u0441\u0442\u0430\u0432\u043B\u044E \u0437\u0430\u0432\u0438\u0441\u0438\u043C\u043E\u0441\u0442\u0438");
22631
- if (!exists(join41(repo, "pnpm-lock.yaml"))) {
23279
+ if (!exists(join42(repo, "pnpm-lock.yaml"))) {
22632
23280
  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" };
22633
23281
  }
22634
23282
  const installed2 = await run2("pnpm", ["install", "--frozen-lockfile"], repo);
@@ -22735,7 +23383,7 @@ function orphanNoteText(run2, q) {
22735
23383
 
22736
23384
  // src/probe.ts
22737
23385
  init_executors();
22738
- import { spawn as spawn3 } from "child_process";
23386
+ import { spawn as spawn4 } from "child_process";
22739
23387
  var RESET_RE2 = /resets[^\n]*/i;
22740
23388
  function executorHealthy(opts = {}) {
22741
23389
  const executor = opts.executor ?? resolveExecutor();
@@ -22754,7 +23402,7 @@ function executorHealthy(opts = {}) {
22754
23402
  }
22755
23403
  resolve6(r);
22756
23404
  };
22757
- const child = spawn3(bin, [...executor.probe.args], {
23405
+ const child = spawn4(bin, [...executor.probe.args], {
22758
23406
  stdio: ["ignore", "pipe", "pipe"],
22759
23407
  ...opts.env ? { env: { ...process.env, ...opts.env } } : {}
22760
23408
  });
@@ -22803,18 +23451,18 @@ async function fetchExternalStorm(url, opts = {}) {
22803
23451
  }
22804
23452
 
22805
23453
  // src/anomalyState.ts
22806
- import { existsSync as existsSync24, readFileSync as readFileSync29, renameSync as renameSync11, writeFileSync as writeFileSync19 } from "fs";
22807
- import { join as join42 } from "path";
23454
+ import { existsSync as existsSync25, readFileSync as readFileSync29, renameSync as renameSync11, writeFileSync as writeFileSync19 } from "fs";
23455
+ import { join as join43 } from "path";
22808
23456
  var KEY_TTL_MS = 7 * 24 * 60 * 6e4;
22809
23457
  var MAX_RESOLVED = 200;
22810
23458
  function emptyState() {
22811
23459
  return { since: {}, lastFiredAt: {}, fires: {}, resolved: [], stopQuiet: null };
22812
23460
  }
22813
23461
  function anomalyStatePath(home) {
22814
- return join42(home, "anomaly-state.json");
23462
+ return join43(home, "anomaly-state.json");
22815
23463
  }
22816
23464
  function loadAnomalyState(home, now = Date.now(), io = {}) {
22817
- const exists = io.exists ?? existsSync24;
23465
+ const exists = io.exists ?? existsSync25;
22818
23466
  const readFile3 = io.readFile ?? ((p) => readFileSync29(p, "utf8"));
22819
23467
  const path = anomalyStatePath(home);
22820
23468
  if (!exists(path)) return emptyState();
@@ -24247,7 +24895,7 @@ ${task.description}` : `\u0417\u0430\u0434\u0430\u0447\u0430 ${run2.task_slug} (
24247
24895
  }
24248
24896
  return parts.join("\n");
24249
24897
  }
24250
- var HERO_CHARTER_PATH = join43(dirname7(THIS_FILE), "..", "docs", "HERO.md");
24898
+ var HERO_CHARTER_PATH = join44(dirname7(THIS_FILE), "..", "docs", "HERO.md");
24251
24899
  function buildHeroPrompt(task, run2, taskContext, attachmentsBlock) {
24252
24900
  const name = run2.name || `#${run2.id}`;
24253
24901
  const charter = readFileSync30(HERO_CHARTER_PATH, "utf8");
@@ -24310,7 +24958,7 @@ function ciTrustLine(prUrl, verifyMode, ciClosed = null) {
24310
24958
  }
24311
24959
  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}`;
24312
24960
  }
24313
- var REVIEW_SKILL_PATH = join43(bundledRoleDir("drone"), "skills", "taskless-review", "SKILL.md");
24961
+ var REVIEW_SKILL_PATH = join44(bundledRoleDir("drone"), "skills", "taskless-review", "SKILL.md");
24314
24962
  function reviewDefectClasses(skillPath = REVIEW_SKILL_PATH) {
24315
24963
  const text = readFileSync30(skillPath, "utf8");
24316
24964
  const m = /^## Классы дефектов\n([\s\S]*?)(?=^## |(?![\s\S]))/m.exec(text);
@@ -24947,7 +25595,7 @@ async function wakeRun(deps, runId, opts = {}) {
24947
25595
  if (run2.status === "review" && run2.pr_url && !needsFixIteration(run2) && !stoppedForHuman) {
24948
25596
  return { ok: false, why: `\u043F\u0440\u043E\u0433\u043E\u043D #${runId} \u0443\u0436\u0435 \u0441\u0434\u0430\u043D \u043D\u0430 \u0440\u0435\u0432\u044C\u044E (${run2.pr_url}) \u2014 \u0431\u0443\u0434\u0438\u0442\u044C \u043D\u0435\u0447\u0435\u0433\u043E; \u043F\u0440\u0430\u0432\u043A\u0438 \u043F\u043E\u0434\u043D\u0438\u043C\u0435\u0442 \u0440\u043E\u0439 \u043F\u043E \u0432\u0435\u0440\u0434\u0438\u043A\u0442\u0443` };
24949
25597
  }
24950
- const worktreeExists = deps.worktreeExists ?? existsSync25;
25598
+ const worktreeExists = deps.worktreeExists ?? existsSync26;
24951
25599
  const hasTranscript = deps.hasTranscript ?? executorHasSession;
24952
25600
  const wt = run2.worktree_path;
24953
25601
  const canContinue = !!wt && worktreeExists(wt) && hasTranscript(run2);
@@ -25094,7 +25742,7 @@ function repoHasCi(deps, run2) {
25094
25742
  function repoHasCiWorkflows(worktreePath, repo) {
25095
25743
  for (const base3 of [worktreePath, repo]) {
25096
25744
  if (!base3) continue;
25097
- const dir = join43(base3, ".github", "workflows");
25745
+ const dir = join44(base3, ".github", "workflows");
25098
25746
  try {
25099
25747
  if (readdirSync19(dir).some((f) => f.endsWith(".yml") || f.endsWith(".yaml"))) return true;
25100
25748
  } catch {
@@ -25318,7 +25966,7 @@ async function wakeReviewerOnCiReady(deps, run2, over) {
25318
25966
  return true;
25319
25967
  }
25320
25968
  function worktreeAndTranscriptAlive(deps, run2) {
25321
- const exists = deps.worktreeExists ?? existsSync25;
25969
+ const exists = deps.worktreeExists ?? existsSync26;
25322
25970
  const transcript = deps.hasTranscript ?? executorHasSession;
25323
25971
  const wt = run2.worktree_path;
25324
25972
  return !!wt && exists(wt) && transcript(run2);
@@ -25749,7 +26397,7 @@ async function wakeAuthorOnChanges(deps, snapshot, now, droneCap) {
25749
26397
  }
25750
26398
  const wt = run2.worktree_path;
25751
26399
  const wtPath = wt || (deps.worktreesDir ? droneWorktreePath(deps.worktreesDir, normalizeRepo(run2.repo || deps.repoFallback || ""), run2.task_slug) : null);
25752
- const worktreeReady = !!wtPath && (deps.worktreeExists ?? existsSync25)(wtPath);
26400
+ const worktreeReady = !!wtPath && (deps.worktreeExists ?? existsSync26)(wtPath);
25753
26401
  if (!worktreeReady) {
25754
26402
  const why = await freshChangesWakeBlock(deps, run2, prUrl, now);
25755
26403
  if (why) return blockFix(run2, why);
@@ -25841,7 +26489,7 @@ async function zoneConflictFor(db, models, activeFiles, run2, repo, repoFallback
25841
26489
  activeFiles.prune(holders.map((r) => r.id));
25842
26490
  const fileExists = (p) => {
25843
26491
  try {
25844
- return statSync17(join43(repo, p), { throwIfNoEntry: false })?.isFile() ?? false;
26492
+ return statSync17(join44(repo, p), { throwIfNoEntry: false })?.isFile() ?? false;
25845
26493
  } catch {
25846
26494
  return false;
25847
26495
  }
@@ -26292,7 +26940,7 @@ async function liftReturners(deps, returners, now, droneCap) {
26292
26940
  deps.returners?.delete(run2.id);
26293
26941
  continue;
26294
26942
  }
26295
- lifted = await wakeAuthorOnRedCi(deps, run2, now, entry.ci, deps.worktreeExists ?? existsSync25, deps.hasTranscript ?? executorHasSession, droneCap);
26943
+ lifted = await wakeAuthorOnRedCi(deps, run2, now, entry.ci, deps.worktreeExists ?? existsSync26, deps.hasTranscript ?? executorHasSession, droneCap);
26296
26944
  }
26297
26945
  if (lifted) deps.returners?.delete(run2.id);
26298
26946
  }
@@ -26317,7 +26965,7 @@ async function resumeWatchdogParked(deps, droneCap) {
26317
26965
  await handOffAtCycleCap(deps, candidate, capHolder, "\u0432\u043E\u0437\u0432\u0440\u0430\u0442 \u0438\u0437 \u043F\u0430\u0440\u043A\u043E\u0432\u043A\u0438 \u0441\u0442\u043E\u0440\u043E\u0436\u0430");
26318
26966
  return;
26319
26967
  }
26320
- const worktreeExists = deps.worktreeExists ?? existsSync25;
26968
+ const worktreeExists = deps.worktreeExists ?? existsSync26;
26321
26969
  const hasTranscript = deps.hasTranscript ?? executorHasSession;
26322
26970
  const wt = candidate.worktree_path;
26323
26971
  const canContinue = !!wt && worktreeExists(wt) && hasTranscript(candidate);
@@ -26797,7 +27445,7 @@ async function buildReliefCostCandidatesFor(deps, now, droneCap) {
26797
27445
  allRuns.filter((r) => ACTIVE_DRONE_STATUSES.has(r.status) && r.host_id && r.host_id !== deps.selfHostId).map((r) => r.host_name || r.host_id).filter((h) => !!h)
26798
27446
  )
26799
27447
  ];
26800
- const advice = reliefAdvice({
27448
+ const advice2 = reliefAdvice({
26801
27449
  maxDrones: droneCap,
26802
27450
  activeDrones: occupying.length,
26803
27451
  exclusiveRepos,
@@ -26805,7 +27453,7 @@ async function buildReliefCostCandidatesFor(deps, now, droneCap) {
26805
27453
  totalGb: pressure.totalGb
26806
27454
  });
26807
27455
  const worstRun = cost.worst ? runById.get(cost.worst.runId) ?? null : null;
26808
- const body = reliefAlertBody(cost, pressure, advice, SWARM_RELIEF_COST_WINDOW_MS, SWARM_RELIEF_ALERT_MIN_STEPS);
27456
+ const body = reliefAlertBody(cost, pressure, advice2, SWARM_RELIEF_COST_WINDOW_MS, SWARM_RELIEF_ALERT_MIN_STEPS);
26809
27457
  const title = reliefAlertTitle(cost, SWARM_RELIEF_COST_WINDOW_MS);
26810
27458
  return buildReliefCostCandidates(cost, thresholds, SWARM_RELIEF_ALERT_SUSTAIN_MS, () => ({
26811
27459
  title,
@@ -27330,7 +27978,7 @@ async function tickOnce(deps) {
27330
27978
  draftHeldThisTick.clear();
27331
27979
  fixBlockedThisTick.clear();
27332
27980
  resetGrokBalanceTick();
27333
- const worktreeExists = deps.worktreeExists ?? existsSync25;
27981
+ const worktreeExists = deps.worktreeExists ?? existsSync26;
27334
27982
  const hasTranscript = deps.hasTranscript ?? executorHasSession;
27335
27983
  deps.stepClock?.mark("0 \u0437\u0430\u043C\u0435\u0440 \u0445\u043E\u0441\u0442\u0430");
27336
27984
  deps.sampleHost?.();
@@ -28367,7 +29015,7 @@ async function resolveConflict(deps, reviewRun) {
28367
29015
  model: reviewRun.model,
28368
29016
  review_model: reviewRun.review_model
28369
29017
  });
28370
- const wt = join43(deps.worktreesDir, basename8(repo), `${reviewRun.task_slug}-resolve-${resolver.id}`);
29018
+ const wt = join44(deps.worktreesDir, basename8(repo), `${reviewRun.task_slug}-resolve-${resolver.id}`);
28371
29019
  try {
28372
29020
  await deps.git.prepareDetachedWorktree(repo, branch, wt);
28373
29021
  await deps.git.setWorktreeIdentity(wt, resolver.name);
@@ -28448,7 +29096,7 @@ async function spawnReviewer(deps, reviewRun, files) {
28448
29096
  // (своей у ревьюера нет, TASWM-204), и коммент с вердиктом должен уехать именно туда.
28449
29097
  workspace_id: reviewRun.workspace_id
28450
29098
  });
28451
- const wt = join43(deps.worktreesDir, basename8(repo), `${reviewRun.task_slug}-review-${reviewer.id}`);
29099
+ const wt = join44(deps.worktreesDir, basename8(repo), `${reviewRun.task_slug}-review-${reviewer.id}`);
28452
29100
  try {
28453
29101
  await deps.git.prepareDetachedWorktree(repo, branch, wt);
28454
29102
  await deps.git.setWorktreeIdentity(wt, reviewer.name);
@@ -28531,7 +29179,7 @@ async function spawnVerifier(deps, verifiedRun, files) {
28531
29179
  // штамп цикла: фикс-итерацию проверяет свежий верификатор
28532
29180
  workspace_id: verifiedRun.workspace_id
28533
29181
  });
28534
- const wt = join43(deps.worktreesDir, basename8(repo), `${verifiedRun.task_slug}-verify-${verifier.id}`);
29182
+ const wt = join44(deps.worktreesDir, basename8(repo), `${verifiedRun.task_slug}-verify-${verifier.id}`);
28535
29183
  try {
28536
29184
  await deps.git.prepareDetachedWorktree(repo, branch, wt);
28537
29185
  await deps.git.setWorktreeIdentity(wt, verifier.name);
@@ -28646,7 +29294,7 @@ async function respawnRun(deps, run2, mode, nudge) {
28646
29294
  ]);
28647
29295
  const base3 = effectiveBaseBranch(run2.base_branch, projectBase);
28648
29296
  const runToSpawn = base3 && run2.base_branch !== base3 ? deps.db.updateRun(run2.id, { base_branch: base3 }) ?? run2 : run2;
28649
- if (!existsSync25(wt)) {
29297
+ if (!existsSync26(wt)) {
28650
29298
  const branch = runToSpawn.branch || runToSpawn.task_slug;
28651
29299
  const source = await addWorktree(repo, wt, branch, {
28652
29300
  ...base3 ? { base: await remoteBaseRef(repo, base3) } : {},
@@ -28691,7 +29339,7 @@ function worktreePathPatch(run2, wt) {
28691
29339
  return run2.worktree_path === wt ? {} : { worktree_path: wt };
28692
29340
  }
28693
29341
  async function syncCrashedOnStartup(deps) {
28694
- const worktreeExists = deps.worktreeExists ?? existsSync25;
29342
+ const worktreeExists = deps.worktreeExists ?? existsSync26;
28695
29343
  let orphaned = 0;
28696
29344
  let merged = 0;
28697
29345
  let requeued = 0;
@@ -28856,7 +29504,7 @@ async function migrateWorktreesAtStartup() {
28856
29504
  legacyDir: WORKTREES_LEGACY_DIR,
28857
29505
  targetDir: WORKTREES_DIR,
28858
29506
  envOverride: process.env.SWARM_WORKTREES || "",
28859
- exists: (d) => existsSync25(d),
29507
+ exists: (d) => existsSync26(d),
28860
29508
  isNonEmptyDir: (d) => {
28861
29509
  try {
28862
29510
  return readdirSync19(d).length > 0;
@@ -28871,7 +29519,7 @@ async function migrateWorktreesAtStartup() {
28871
29519
  });
28872
29520
  } catch (e) {
28873
29521
  console.error("[migrate] \u043C\u0438\u0433\u0440\u0430\u0446\u0438\u044F worktrees \u0441\u043E\u0440\u0432\u0430\u043B\u0430\u0441\u044C \u2014 \u0444\u043E\u043B\u0431\u044D\u043A:", e);
28874
- return existsSync25(WORKTREES_DIR) ? WORKTREES_DIR : WORKTREES_LEGACY_DIR;
29522
+ return existsSync26(WORKTREES_DIR) ? WORKTREES_DIR : WORKTREES_LEGACY_DIR;
28875
29523
  }
28876
29524
  }
28877
29525
  async function reportWorkspaceAccess(tl, db) {
@@ -29636,7 +30284,7 @@ async function runDaemon(opts) {
29636
30284
  isDirty: (p) => worktreeDirty(p),
29637
30285
  releaseWorktree: (repo, p) => releaseWorktree(repo || opts.repo, p),
29638
30286
  pruneWorktrees: (repo) => pruneWorktrees(repo || opts.repo),
29639
- worktreeExists: existsSync25,
30287
+ worktreeExists: existsSync26,
29640
30288
  liveWorktrees: () => new Set(listDroneProcesses().map((p) => p.worktree)),
29641
30289
  narrate: narrator.narrate
29642
30290
  });
@@ -29780,13 +30428,13 @@ async function runDaemon(opts) {
29780
30428
  mode,
29781
30429
  nudge
29782
30430
  ),
29783
- worktreeExists: (p) => existsSync25(p),
30431
+ worktreeExists: (p) => existsSync26(p),
29784
30432
  // TASWM-514: с этого момента считаем попытки спавна — счётчик живёт ровно одну жизнь
29785
30433
  // процесса демона и рестарт не переживает (см. preStartAttempts).
29786
30434
  startedAt: Date.now(),
29787
30435
  // TASWM-592: run-aware — где лежит сессия, знает харнесс ПРОГОНА.
29788
30436
  hasTranscript: (run2) => !!run2.worktree_path && executorForRun(run2, lastSwarmModels, process.env, runModelRefPin.get(run2.id) ?? null).session.exists(run2.worktree_path),
29789
- runHasSession: (run2) => !!run2.worktree_path && existsSync25(run2.worktree_path) && executorForRun(run2, lastSwarmModels, process.env, runModelRefPin.get(run2.id) ?? null).session.exists(run2.worktree_path),
30437
+ runHasSession: (run2) => !!run2.worktree_path && existsSync26(run2.worktree_path) && executorForRun(run2, lastSwarmModels, process.env, runModelRefPin.get(run2.id) ?? null).session.exists(run2.worktree_path),
29790
30438
  // CI-осведомлённость review-PR (TASWM-102): реальный `gh pr checks`/`gh run view --log-failed`
29791
30439
  // (gh.ts) — решение (будить ли дрона) и гейты живут в tickOnce/handleCiRed. failureSummary
29792
30440
  // строится над failing/failingRunIds ИЗ checks — без повторного `gh pr checks`.
@@ -29884,7 +30532,7 @@ async function runDaemon(opts) {
29884
30532
  setTimeout(() => {
29885
30533
  Promise.all([closeWebServer(web.server), droneChannel ? closeDroneChannel(droneChannel.server) : Promise.resolve()]).then(() => {
29886
30534
  if (!stopping) {
29887
- spawn4(process.execPath, respawnArgs, {
30535
+ spawn5(process.execPath, respawnArgs, {
29888
30536
  detached: true,
29889
30537
  // TASWM-497: в ЛОГ, а не в /dev/null. Со `stdio: "ignore"` демон после каждого
29890
30538
  // `update`/`restart` замолкал навсегда, и разбирать инциденты по логу было нечем.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taskless-app/swarm",
3
- "version": "0.6.106",
3
+ "version": "0.6.108",
4
4
  "type": "module",
5
5
  "description": "Local control plane for a fleet of AI coding agents (drones), coordinating through Taskless. The overmind runs the swarm.",
6
6
  "keywords": [
@@ -40,7 +40,7 @@
40
40
  "undici": "^7.30.1",
41
41
  "zod": "3.25.76"
42
42
  },
43
- "gitHead": "bb60755eda8d72e1dbf0adc4aa4e86b2d9189270",
43
+ "gitHead": "5f0f3fbffee1c48a48899d850caaf0ed10d0b9c2",
44
44
  "scripts": {
45
45
  "overmind": "NODE_OPTIONS=\"${NODE_OPTIONS:-} --conditions=development\" tsx src/overmind.ts",
46
46
  "swarm": "NODE_OPTIONS=\"${NODE_OPTIONS:-} --conditions=development\" tsx src/cli.ts",