@taskless-app/swarm 0.6.105 → 0.6.107

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/overmind.js CHANGED
@@ -1061,12 +1061,12 @@ function splitOversizedBlock(block, budget) {
1061
1061
  const inner = lines.slice(1, lines[lines.length - 1].trim().startsWith(close.slice(0, 3)) ? -1 : void 0);
1062
1062
  const wrap = open.length + close.length + 2;
1063
1063
  const innerBudget = Math.max(16, budget - wrap);
1064
- const chunks = [];
1064
+ const chunks2 = [];
1065
1065
  let cur2 = [];
1066
1066
  let len = 0;
1067
1067
  const flush2 = () => {
1068
1068
  if (cur2.length === 0) return;
1069
- chunks.push(`${open}
1069
+ chunks2.push(`${open}
1070
1070
  ${cur2.join("\n")}
1071
1071
  ${close}`);
1072
1072
  cur2 = [];
@@ -1080,7 +1080,7 @@ ${close}`);
1080
1080
  }
1081
1081
  }
1082
1082
  flush2();
1083
- return chunks.length ? chunks : [`${open}
1083
+ return chunks2.length ? chunks2 : [`${open}
1084
1084
  ${close}`];
1085
1085
  }
1086
1086
  const pieces = [];
@@ -1110,10 +1110,10 @@ function splitCommentIntoThread(body, opts = {}) {
1110
1110
 
1111
1111
  `.length;
1112
1112
  const budget = Math.max(64, maxChars - reserve);
1113
- const chunks = [];
1113
+ const chunks2 = [];
1114
1114
  let cur = "";
1115
1115
  const flush = () => {
1116
- if (cur.trim()) chunks.push(cur.trim());
1116
+ if (cur.trim()) chunks2.push(cur.trim());
1117
1117
  cur = "";
1118
1118
  };
1119
1119
  for (const block of toBlocks(body)) {
@@ -1134,12 +1134,12 @@ function splitCommentIntoThread(body, opts = {}) {
1134
1134
  }
1135
1135
  flush();
1136
1136
  let truncated = false;
1137
- if (chunks.length > maxParts) {
1138
- chunks.length = maxParts;
1137
+ if (chunks2.length > maxParts) {
1138
+ chunks2.length = maxParts;
1139
1139
  truncated = true;
1140
1140
  }
1141
- const total = chunks.length;
1142
- const parts = chunks.map((text, i) => `${partMarker(i, total)}
1141
+ const total = chunks2.length;
1142
+ const parts = chunks2.map((text, i) => `${partMarker(i, total)}
1143
1143
 
1144
1144
  ${text}`);
1145
1145
  if (truncated) {
@@ -1657,8 +1657,8 @@ var init_taskWeight = __esm({
1657
1657
  function hasZoneModel(m) {
1658
1658
  return m.tasks > 0 && m.zones.length > 0;
1659
1659
  }
1660
- function testFileFeature(basename8) {
1661
- const head = basename8.replace(/\.(test|spec)\.[a-z]+$/i, "").split(".")[0].toLowerCase();
1660
+ function testFileFeature(basename9) {
1661
+ const head = basename9.replace(/\.(test|spec)\.[a-z]+$/i, "").split(".")[0].toLowerCase();
1662
1662
  return head && !GENERIC_DIRS.has(head) ? head : null;
1663
1663
  }
1664
1664
  function pathZoneCandidate(path) {
@@ -2809,7 +2809,7 @@ function tomlValue(v) {
2809
2809
  return `{${Object.entries(v).map(([k, val]) => `${k} = ${tomlValue(val)}`).join(", ")}}`;
2810
2810
  }
2811
2811
  function mcpConfigArgs(spec) {
2812
- const inline = `{command = ${tomlValue(spec.mcp.command)}, args = ${tomlValue(spec.mcp.args)}, env = ${tomlValue(spec.mcp.env)}}`;
2812
+ const inline = `{command = ${tomlValue(spec.mcp.command)}, args = ${tomlValue(spec.mcp.args)}, env = ${tomlValue(spec.mcp.env)}, tool_timeout_sec = ${CODEX_SWARM_TOOL_TIMEOUT_SEC}}`;
2813
2813
  return ["-c", `mcp_servers.${spec.mcp.name}=${inline}`];
2814
2814
  }
2815
2815
  function skillsNotice(skillDirs) {
@@ -2873,7 +2873,7 @@ function newestRolloutMtime(dir, depth = 4) {
2873
2873
  }
2874
2874
  return latest;
2875
2875
  }
2876
- var BYPASS_FLAG, SKIP_GIT_CHECK_FLAG, CODEX_MODEL_PRICING, TERMINAL_EVENTS, codexExecutor;
2876
+ var BYPASS_FLAG, SKIP_GIT_CHECK_FLAG, CODEX_SWARM_TOOL_TIMEOUT_SEC, CODEX_MODEL_PRICING, TERMINAL_EVENTS, codexExecutor;
2877
2877
  var init_codex = __esm({
2878
2878
  "src/executors/codex.ts"() {
2879
2879
  "use strict";
@@ -2881,6 +2881,7 @@ var init_codex = __esm({
2881
2881
  init_pricing();
2882
2882
  BYPASS_FLAG = "--dangerously-bypass-approvals-and-sandbox";
2883
2883
  SKIP_GIT_CHECK_FLAG = "--skip-git-repo-check";
2884
+ CODEX_SWARM_TOOL_TIMEOUT_SEC = 7 * 24 * 60 * 60;
2884
2885
  CODEX_MODEL_PRICING = {};
2885
2886
  TERMINAL_EVENTS = /* @__PURE__ */ new Set(["task_complete", "turn.completed", "thread.completed", "session.completed"]);
2886
2887
  codexExecutor = {
@@ -2971,6 +2972,7 @@ function grokMcpToml(spec) {
2971
2972
  "command = " + tomlBasic(spec.mcp.command),
2972
2973
  "args = [" + args + "]",
2973
2974
  "env = { " + env + " }",
2975
+ "tool_timeout_sec = " + String(GROK_SWARM_TOOL_TIMEOUT_SEC),
2974
2976
  ""
2975
2977
  ].join("\n");
2976
2978
  }
@@ -3145,7 +3147,7 @@ function extractJsonObject(raw) {
3145
3147
  }
3146
3148
  return null;
3147
3149
  }
3148
- var grokExecutor;
3150
+ var GROK_SWARM_TOOL_TIMEOUT_SEC, grokExecutor;
3149
3151
  var init_grok = __esm({
3150
3152
  "src/executors/grok.ts"() {
3151
3153
  "use strict";
@@ -3153,6 +3155,7 @@ var init_grok = __esm({
3153
3155
  init_swarmHome();
3154
3156
  init_swarmFiles();
3155
3157
  init_codex();
3158
+ GROK_SWARM_TOOL_TIMEOUT_SEC = 7 * 24 * 60 * 60;
3156
3159
  grokExecutor = {
3157
3160
  id: "grok",
3158
3161
  title: "Grok CLI (grok)",
@@ -3940,14 +3943,14 @@ function diskGb(path = process.cwd()) {
3940
3943
  }
3941
3944
  }
3942
3945
  function readCpuTicks(cpus) {
3943
- let idle = 0;
3946
+ let idle2 = 0;
3944
3947
  let total = 0;
3945
3948
  for (const c of cpus) {
3946
3949
  const t = c.times;
3947
- idle += t.idle;
3950
+ idle2 += t.idle;
3948
3951
  total += t.user + t.nice + t.sys + t.idle + t.irq;
3949
3952
  }
3950
- return { idle, total };
3953
+ return { idle: idle2, total };
3951
3954
  }
3952
3955
  function cpuBusyFromTicks(prev, cur) {
3953
3956
  if (!prev) return null;
@@ -7046,11 +7049,13 @@ __export(taskless_exports, {
7046
7049
  makeTasklessClient: () => makeTasklessClient,
7047
7050
  parseWorkspaces: () => parseWorkspaces,
7048
7051
  preflightAuth: () => preflightAuth,
7052
+ prepareFromConfig: () => prepareFromConfig,
7049
7053
  requireTaskBody: () => requireTaskBody,
7050
7054
  resetLegacyTokenWarning: () => resetLegacyTokenWarning,
7051
7055
  resolveApiToken: () => resolveApiToken,
7052
7056
  swarmToolArgs: () => swarmToolArgs,
7053
- taskAuthor: () => taskAuthor
7057
+ taskAuthor: () => taskAuthor,
7058
+ verifyCommandsFromProfile: () => verifyCommandsFromProfile
7054
7059
  });
7055
7060
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
7056
7061
  import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
@@ -7064,6 +7069,23 @@ function toolErrorText2(r) {
7064
7069
  const fromContent = (r.content ?? []).map((c) => c.text ?? "").filter(Boolean).join(" ").trim();
7065
7070
  return fromContent || JSON.stringify(r);
7066
7071
  }
7072
+ function prepareFromConfig(structured) {
7073
+ const config = structured?.config;
7074
+ if (!config || typeof config !== "object" || Array.isArray(config)) return null;
7075
+ const prepare = config.prepare;
7076
+ if (!Array.isArray(prepare)) return null;
7077
+ return prepare.filter((c) => typeof c === "string").map((c) => c.trim()).filter((c) => c.length > 0);
7078
+ }
7079
+ function verifyCommandsFromProfile(structured) {
7080
+ const profile = structured?.profile;
7081
+ if (!profile || typeof profile !== "object" || Array.isArray(profile)) return null;
7082
+ const verify = profile.verify;
7083
+ if (verify == null) return null;
7084
+ if (typeof verify !== "object" || Array.isArray(verify)) return null;
7085
+ const commands = verify.commands;
7086
+ if (!Array.isArray(commands)) return null;
7087
+ return commands.filter((c) => typeof c === "string").map((c) => c.trim()).filter((c) => c.length > 0);
7088
+ }
7067
7089
  function makeTasklessClient(call, workspaceId, taskUrlBase, fetchFile, fetchImpl = fetch) {
7068
7090
  const ws = workspaceId ? { workspaceId } : {};
7069
7091
  const idCache = /* @__PURE__ */ new Map();
@@ -7198,6 +7220,31 @@ function makeTasklessClient(call, workspaceId, taskUrlBase, fetchFile, fetchImpl
7198
7220
  ...input.taskSlug ? { taskSlug: input.taskSlug } : {}
7199
7221
  });
7200
7222
  }
7223
+ async function readRepoConfig(repoFullName, taskSlug) {
7224
+ const drop = slugRetry.within("swarm_repo_config") && !!taskSlug;
7225
+ const args = { repoFullName, ...taskSlug && !drop ? { taskSlug } : {} };
7226
+ let outcome = await callTool("swarm_repo_config", args);
7227
+ if (!outcome.ok && taskSlug && unknownArg(outcome.failure.detail, "taskSlug")) {
7228
+ slugRetry.note("swarm_repo_config");
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");
7230
+ outcome = await callTool("swarm_repo_config", { repoFullName });
7231
+ }
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");
7234
+ const sc = outcome.res.structuredContent ?? null;
7235
+ if (sc?.ambiguous === true || sc?.repoAmbiguous === true) return null;
7236
+ return sc;
7237
+ }
7238
+ async function repoVerifyCommands(repoFullName, taskSlug) {
7239
+ const sc = await readRepoConfig(repoFullName, taskSlug);
7240
+ if (!sc) return null;
7241
+ return verifyCommandsFromProfile(sc);
7242
+ }
7243
+ async function repoPrepare(repoFullName, taskSlug) {
7244
+ const sc = await readRepoConfig(repoFullName, taskSlug);
7245
+ if (!sc) return null;
7246
+ return prepareFromConfig(sc);
7247
+ }
7201
7248
  async function callDroppingUnknownSlug(name, args) {
7202
7249
  const drop = slugRetry.within(name) && "taskSlug" in args;
7203
7250
  const sent = drop ? (({ taskSlug: _slug, ...rest }) => rest)(args) : args;
@@ -7299,6 +7346,8 @@ function makeTasklessClient(call, workspaceId, taskUrlBase, fetchFile, fetchImpl
7299
7346
  decideRepoRules,
7300
7347
  proposeZoneNotes,
7301
7348
  confirmZoneNotes,
7349
+ repoVerifyCommands,
7350
+ repoPrepare,
7302
7351
  createTask: async (input) => {
7303
7352
  if (!input.projectId) {
7304
7353
  throw new Error("createTask: projectId \u043E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u0435\u043D \u2014 \u0430\u0432\u0442\u043E-\u0441\u043E\u0437\u0434\u0430\u043D\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0440\u043E\u0435\u043C \u0431\u0435\u0437 \u043F\u0440\u043E\u0435\u043A\u0442\u0430 \u0437\u0430\u043F\u0440\u0435\u0449\u0435\u043D\u043E (TASWM-204)");
@@ -7611,7 +7660,7 @@ var init_taskless = __esm({
7611
7660
  init_authState();
7612
7661
  init_workspace();
7613
7662
  SLUG_RE = /^[A-Za-z][A-Za-z0-9]*-\d+$/;
7614
- WS_FREE_TOOLS = /* @__PURE__ */ new Set(["list_workspaces", "who_am_i", "finalize_upload", "report_acceptance_check"]);
7663
+ WS_FREE_TOOLS = /* @__PURE__ */ new Set(["list_workspaces", "who_am_i", "finalize_upload", "report_acceptance_check", "swarm_repo_config"]);
7615
7664
  TaskBodyUnavailableError = class extends Error {
7616
7665
  /** Код причины — по нему решают, повторять ли (TOOL_FAILURE_RETRIABLE), а не по тексту. */
7617
7666
  code;
@@ -7661,7 +7710,7 @@ __export(db_exports, {
7661
7710
  });
7662
7711
  import { createRequire as createRequire2 } from "module";
7663
7712
  import { randomUUID as randomUUID3 } from "crypto";
7664
- import { existsSync as existsSync18 } from "fs";
7713
+ import { existsSync as existsSync21 } from "fs";
7665
7714
  import { resolve as resolve5 } from "path";
7666
7715
  function rowToQuestion(row) {
7667
7716
  return {
@@ -8339,7 +8388,7 @@ CREATE TABLE IF NOT EXISTS imports (
8339
8388
  const repoN = normalizeRepo(repo);
8340
8389
  const already = this.db.prepare("SELECT run_count FROM imports WHERE source = ?").get(abs);
8341
8390
  if (already) return { imported: false, runs: already.run_count };
8342
- if (!existsSync18(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}`);
8343
8392
  const src = new this.databaseCtor(abs);
8344
8393
  try {
8345
8394
  const runs = src.prepare("SELECT * FROM runs ORDER BY id").all();
@@ -8750,10 +8799,10 @@ var init_droneStore = __esm({
8750
8799
 
8751
8800
  // src/overmind.ts
8752
8801
  import { homedir as homedir10 } from "os";
8753
- import { existsSync as existsSync23, readFileSync as readFileSync29, readdirSync as readdirSync18, renameSync as renameSync12, statSync as statSync16 } from "fs";
8754
- import { basename as basename7, dirname as dirname6, join as join41 } 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";
8755
8804
  import { fileURLToPath as fileURLToPath3, pathToFileURL } from "url";
8756
- import { spawn as spawn4 } from "child_process";
8805
+ import { spawn as spawn5 } from "child_process";
8757
8806
 
8758
8807
  // src/restart.ts
8759
8808
  init_src();
@@ -12813,8 +12862,8 @@ function computeReliefCost(state, now, windowMs) {
12813
12862
  }
12814
12863
  function reliefAlertDue(cost, t) {
12815
12864
  if (cost.pauses < t.pauses) return false;
12816
- const idle = cost.stepsBetween != null && cost.stepsBetween < t.minSteps;
12817
- return cost.lostMs >= t.lostMs || idle;
12865
+ const idle2 = cost.stepsBetween != null && cost.stepsBetween < t.minSteps;
12866
+ return cost.lostMs >= t.lostMs || idle2;
12818
12867
  }
12819
12868
  var ADVICE_LIST_CAP = 3;
12820
12869
  var MAX_ALERT_BODY_CHARS = 1800;
@@ -12838,7 +12887,7 @@ function humanMinutes(ms) {
12838
12887
  if (total < 60) return `${total} \u043C\u0438\u043D`;
12839
12888
  return `${Math.floor(total / 60)} \u0447 ${String(total % 60).padStart(2, "0")} \u043C\u0438\u043D`;
12840
12889
  }
12841
- function reliefAlertBody(cost, pressure, advice, windowMs, minSteps) {
12890
+ function reliefAlertBody(cost, pressure, advice2, windowMs, minSteps) {
12842
12891
  const window = humanMinutes(windowMs);
12843
12892
  const perPause = cost.pauses > 0 ? humanMinutes(cost.lostMs / cost.pauses) : null;
12844
12893
  const parts = [
@@ -12852,7 +12901,7 @@ function reliefAlertBody(cost, pressure, advice, windowMs, minSteps) {
12852
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.`);
12853
12902
  if (pressure.culprits.length) parts.push(`\u0423\u043F\u0438\u0440\u0430\u0435\u0442\u0441\u044F \u0432: ${pressure.culprits.join("; ")}.`);
12854
12903
  parts.push(`\u041F\u043E\u043A\u0430\u0437\u0430\u043D\u0438\u044F \u0445\u043E\u0441\u0442\u0430 \u2014 ${pressure.readings.join("; ")}.`);
12855
- 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("; ")}.`);
12856
12905
  const body = parts.join(" ");
12857
12906
  return body.length <= MAX_ALERT_BODY_CHARS ? body : `${body.slice(0, MAX_ALERT_BODY_CHARS - 1)}\u2026`;
12858
12907
  }
@@ -13593,9 +13642,9 @@ function latestExhaustedWindow(report, executor) {
13593
13642
  return latest?.window ?? windows[0] ?? null;
13594
13643
  }
13595
13644
  function resetFromHint(resetHint, nowMs) {
13596
- const relative2 = /resets\s+in\s+(?:(\d+)\s*h)?\s*(?:(\d+)\s*m)?/i.exec(resetHint);
13597
- if (relative2 && (relative2[1] || relative2[2])) {
13598
- return nowMs + (Number(relative2[1] ?? 0) * 60 + Number(relative2[2] ?? 0)) * 6e4;
13645
+ const relative4 = /resets\s+in\s+(?:(\d+)\s*h)?\s*(?:(\d+)\s*m)?/i.exec(resetHint);
13646
+ if (relative4 && (relative4[1] || relative4[2])) {
13647
+ return nowMs + (Number(relative4[1] ?? 0) * 60 + Number(relative4[2] ?? 0)) * 6e4;
13599
13648
  }
13600
13649
  const clock = /resets(?:\s+at)?\s+(\d{1,2})(?::(\d{2}))?\s*(am|pm)?\b/i.exec(resetHint);
13601
13650
  if (!clock) return null;
@@ -13904,6 +13953,85 @@ import { existsSync as existsSync16, readdirSync as readdirSync17, readFileSync
13904
13953
  import { join as join29 } from "path";
13905
13954
  import { execa } from "execa";
13906
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
+
13907
14035
  // src/prepareLock.ts
13908
14036
  import { createHash as createHash2 } from "crypto";
13909
14037
  import { closeSync as closeSync6, openSync as openSync6, rmSync as rmSync2, statSync as statSync14, writeSync as writeSync2 } from "fs";
@@ -14117,8 +14245,15 @@ async function sweepEnvCacheTemp(io = {}) {
14117
14245
  // src/deps.ts
14118
14246
  var PREPARE_TIMEOUT_MS = 15 * 6e4;
14119
14247
  var MAX_PLAN_COMMANDS = 12;
14120
- async function runCommand(cmd, worktree) {
14248
+ async function runCommand(cmd, worktree, signal) {
14121
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
+ }
14122
14257
  const res = await execa(cmd.run, {
14123
14258
  cwd: cmd.cwd ?? worktree,
14124
14259
  shell: true,
@@ -14518,9 +14653,9 @@ function planPrepare(worktree, io = {}) {
14518
14653
  }
14519
14654
  async function ensureWorktreeDeps(worktree, io = {}) {
14520
14655
  const exists = io.exists ?? existsSync16;
14521
- const exec = io.exec ?? ((cmd) => runCommand(cmd, worktree));
14656
+ const exec = io.exec ?? ((cmd) => runCommand(cmd, worktree, io.signal));
14522
14657
  const approve = io.approve ?? (() => true);
14523
- const cachePlan = envCachePlan(worktree, io);
14658
+ const cachePlan = io.skipEnvCache ? null : envCachePlan(worktree, io);
14524
14659
  const cacheIO = io.envCache ?? {};
14525
14660
  const report = {
14526
14661
  ecosystem: null,
@@ -14542,6 +14677,15 @@ async function ensureWorktreeDeps(worktree, io = {}) {
14542
14677
  report.source = plan.source;
14543
14678
  report.outcome = plan.source === "none" ? "not-detected" : "nothing-to-do";
14544
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
+ }
14685
+ if (io.skipOptional && cmd.optional) {
14686
+ report.skipped.push(cmd.label);
14687
+ continue;
14688
+ }
14545
14689
  if (cmd.skipIfExists && exists(cmd.skipIfExists)) {
14546
14690
  report.skipped.push(cmd.label);
14547
14691
  continue;
@@ -14554,6 +14698,10 @@ async function ensureWorktreeDeps(worktree, io = {}) {
14554
14698
  if (await exec(cmd)) {
14555
14699
  report.ran.push(cmd.label);
14556
14700
  report.outcome = "prepared";
14701
+ } else if (io.signal?.aborted) {
14702
+ report.failed.push(cmd.label);
14703
+ report.outcome = "failed";
14704
+ break;
14557
14705
  } else if (cmd.optional) {
14558
14706
  report.warned.push(cmd.label);
14559
14707
  } else {
@@ -14920,7 +15068,7 @@ function parkReasonUnretriable(reason) {
14920
15068
  // package.json
14921
15069
  var package_default = {
14922
15070
  name: "@taskless-app/swarm",
14923
- version: "0.6.105",
15071
+ version: "0.6.107",
14924
15072
  type: "module",
14925
15073
  description: "Local control plane for a fleet of AI coding agents (drones), coordinating through Taskless. The overmind runs the swarm.",
14926
15074
  keywords: [
@@ -14972,7 +15120,7 @@ var package_default = {
14972
15120
  undici: "^7.30.1",
14973
15121
  zod: "3.25.76"
14974
15122
  },
14975
- gitHead: "d737e797e951d0d8375e73623cb24d6ae9a7cc49"
15123
+ gitHead: "ca9dbf062f7b6364a2bcb264cf769d342fe5d185"
14976
15124
  };
14977
15125
 
14978
15126
  // src/version.ts
@@ -15596,10 +15744,10 @@ function verdictEventSha(text) {
15596
15744
  }
15597
15745
  function changesLabel(text) {
15598
15746
  const pickup = text.startsWith(REVIEWER_PICKUP_PREFIX);
15599
- const sep4 = pickup ? "): " : ": ";
15600
- const at = text.indexOf(sep4);
15747
+ const sep5 = pickup ? "): " : ": ";
15748
+ const at = text.indexOf(sep5);
15601
15749
  if (at < 0) return false;
15602
- const line = (text.slice(at + sep4.length).split("\n")[0] ?? "").trim();
15750
+ const line = (text.slice(at + sep5.length).split("\n")[0] ?? "").trim();
15603
15751
  const head = line.split(" \u2014 ")[0] ?? line;
15604
15752
  return CHANGES_VERDICT_RE.test(head);
15605
15753
  }
@@ -16546,156 +16694,1922 @@ init_zoneNotes();
16546
16694
  init_src();
16547
16695
  init_src();
16548
16696
  init_src();
16549
- init_src();
16550
- function readTaskFailureInstruction(slug, failure) {
16551
- const why = describeToolFailure(failure);
16552
- if (TOOL_FAILURE_RETRIABLE[failure.code]) {
16553
- return `\u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u043F\u0435\u0440\u0435\u0447\u0438\u0442\u0430\u0442\u044C \u0437\u0430\u0434\u0430\u0447\u0443 ${slug}: ${why}. \u042D\u0442\u043E \u0432\u0440\u0435\u043C\u0435\u043D\u043D\u043E \u0438 \u043B\u0435\u0447\u0438\u0442\u0441\u044F \u043F\u043E\u0432\u0442\u043E\u0440\u043E\u043C \u2014 \u0440\u0430\u0431\u043E\u0442\u0430\u0439 \u043F\u043E\u043A\u0430 \u043F\u043E \u0442\u043E\u043C\u0443, \u0447\u0442\u043E \u0443\u0436\u0435 \u0432 \u043F\u0440\u043E\u043C\u043F\u0442\u0435, \u0438 \u043F\u043E\u0437\u043E\u0432\u0438 read_task \u0435\u0449\u0451 \u0440\u0430\u0437 \u043F\u043E\u0437\u0436\u0435 (\u043F\u0435\u0440\u0435\u0434 \u0441\u0434\u0430\u0447\u0435\u0439 \u2014 \u043E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u043E).`;
16697
+
16698
+ // src/mutationGate.ts
16699
+ init_procCleanup();
16700
+ import { existsSync as existsSync18, lstatSync as lstatSync2, mkdirSync as mkdirSync13, mkdtempSync, readdirSync as readdirSync18, readFileSync as readFileSync26, realpathSync as realpathSync3, rmSync as rmSync4, statSync as statSync16, writeFileSync as writeFileSync17 } from "fs";
16701
+ import { rm as rm3 } from "fs/promises";
16702
+ import { tmpdir as tmpdir2 } from "os";
16703
+ import { basename as basename6, isAbsolute as isAbsolute6, join as join36, relative as relative2, sep as sep4 } from "path";
16704
+ import { execa as execa2 } from "execa";
16705
+ var MAX_OUTPUT_CHARS = 2e5;
16706
+ var GIT_TIMEOUT_MS = 6e4;
16707
+ var WORKTREE_ADD_TIMEOUT_MS = 18e4;
16708
+ var COPY_PREFIX = "taswm-mutation-";
16709
+ var ORPHAN_FRESH_MS = 2 * 60 * 1e3;
16710
+ var TEST_FILE_RE = /(^|\/)[^/]*\.(test|spec)\.[^/]+$/;
16711
+ var DOC_EXT_RE = /\.(md|mdx|rst|adoc|asciidoc)$/i;
16712
+ var SNAPSHOT_DIR_RE = /^(?:__snapshots__|__image_snapshots__|__screenshots__)$/;
16713
+ var SNAPSHOT_SUFFIX_RE = /\.(?:test|spec)\.[^/]+-snapshots$/;
16714
+ var ANSI_RE = /\u001b(?:\[[0-9;?]*[ -/]*[@-~]|\][^\u0007]*(?:\u0007|\u001b\\))/g;
16715
+ var REPORT_PATH_RE = /(?:JSON report written to|Test results written to:?)\s+(.+)/;
16716
+ var ROOT_SKIP_DIRS = /* @__PURE__ */ new Set(["journal", "docs", "changelog"]);
16717
+ var AGENT_ENV_NAMES = /* @__PURE__ */ new Set([
16718
+ "CLAUDECODE",
16719
+ "CLAUDE_CODE",
16720
+ "AI_AGENT",
16721
+ "CURSOR_AGENT",
16722
+ "GEMINI_CLI",
16723
+ "OPENCODE",
16724
+ "REPL_ID",
16725
+ "AUGMENT_AGENT",
16726
+ "GOOSE_PROVIDER",
16727
+ "JUNIE_DATA",
16728
+ "JUNIE_SHIM_PATH",
16729
+ "COPILOT_AGENT",
16730
+ "COPILOT_CLI"
16731
+ ]);
16732
+ var AGENT_ENV_PREFIXES = ["CLAUDE_CODE_", "CODEX_"];
16733
+ var LOCK_NAMES = /* @__PURE__ */ new Set([
16734
+ "pnpm-lock.yaml",
16735
+ "package-lock.json",
16736
+ "npm-shrinkwrap.json",
16737
+ "yarn.lock",
16738
+ "bun.lock",
16739
+ "bun.lockb",
16740
+ "composer.lock",
16741
+ "gemfile.lock",
16742
+ "cargo.lock",
16743
+ "poetry.lock",
16744
+ "deno.lock",
16745
+ "go.sum",
16746
+ "packages.lock.json",
16747
+ "paket.lock",
16748
+ "mix.lock",
16749
+ "pubspec.lock",
16750
+ "flake.lock",
16751
+ "uv.lock"
16752
+ ]);
16753
+ var GateTimeout = class extends Error {
16754
+ constructor() {
16755
+ super("\u0442\u0430\u0439\u043C\u0430\u0443\u0442");
16756
+ this.name = "GateTimeout";
16554
16757
  }
16555
- return [
16556
- `\u26D4 \u0417\u0410\u0414\u0410\u0427\u0423 ${slug} \u041F\u0420\u041E\u0427\u0418\u0422\u0410\u0422\u042C \u041D\u0415\u041B\u042C\u0417\u042F: ${why}.`,
16557
- "\u041F\u043E\u0432\u0442\u043E\u0440 \u0442\u0443\u0442 \u043D\u0435 \u043F\u043E\u043C\u043E\u0436\u0435\u0442 \u2014 \u043F\u0440\u0438\u0447\u0438\u043D\u0430 \u043D\u0435 \u0432 \u0441\u0435\u0442\u0438, \u043E\u043D\u0430 \u0441\u0430\u043C\u0430 \u043D\u0435 \u0440\u0430\u0437\u043E\u0439\u0434\u0451\u0442\u0441\u044F.",
16558
- "\u041D\u0415 \u0440\u0430\u0431\u043E\u0442\u0430\u0439 \u043F\u043E \u0441\u043B\u0430\u0433\u0443 \u0438 \u043F\u043E \u043F\u0430\u043C\u044F\u0442\u0438: \u043F\u043E\u0441\u0442\u0430\u043D\u043E\u0432\u043A\u0430, \u043A\u043E\u0442\u043E\u0440\u043E\u0439 \u0442\u044B \u043D\u0435 \u0432\u0438\u0434\u0435\u043B, \u043D\u0435 \u0432\u043E\u0441\u0441\u0442\u0430\u043D\u0430\u0432\u043B\u0438\u0432\u0430\u0435\u0442\u0441\u044F \u0438\u0437 \u043D\u0430\u0437\u0432\u0430\u043D\u0438\u044F \u0437\u0430\u0434\u0430\u0447\u0438 (TASWM-288).",
16559
- "\u0421\u043F\u0440\u043E\u0441\u0438 \u043E\u043F\u0435\u0440\u0430\u0442\u043E\u0440\u0430 \u0447\u0435\u0440\u0435\u0437 ask() \u2014 \u043D\u0430\u0437\u043E\u0432\u0438 \u0435\u043C\u0443 \u044D\u0442\u0443 \u043F\u0440\u0438\u0447\u0438\u043D\u0443 \u0434\u043E\u0441\u043B\u043E\u0432\u043D\u043E \u2014 \u0438 \u0434\u0430\u043B\u044C\u0448\u0435 \u0434\u0435\u043B\u0430\u0439 \u0442\u043E, \u0447\u0442\u043E \u043E\u043D \u043E\u0442\u0432\u0435\u0442\u0438\u0442."
16560
- ].join("\n");
16561
- }
16562
- function freezeInstruction(branch, reason = "\u0435\u0433\u043E \u043F\u0443\u043B\u044C\u0441 (heartbeat) \u0443\u0441\u0442\u0430\u0440\u0435\u043B") {
16563
- return [
16564
- `\u26D4 OVERMIND \u041D\u0415\u0414\u041E\u0421\u0422\u0423\u041F\u0415\u041D \u2014 ${reason}. \u041D\u0430\u0434\u0437\u043E\u0440\u0430 \u043D\u0430\u0434 \u0442\u043E\u0431\u043E\u0439 \u0441\u0435\u0439\u0447\u0430\u0441 \u043D\u0435\u0442: \u043D\u0435\u043A\u043E\u043C\u0443`,
16565
- "\u043F\u0440\u0438\u043D\u044F\u0442\u044C \u0442\u0432\u043E\u0439 \u0432\u043E\u043F\u0440\u043E\u0441, \u0437\u0430\u043C\u0435\u0442\u0438\u0442\u044C \u0441\u043C\u0435\u0440\u0442\u044C, \u0441\u043C\u0435\u0440\u0436\u0438\u0442\u044C PR \u0438\u043B\u0438 \u0440\u0430\u0437\u0440\u0443\u043B\u0438\u0442\u044C \u043A\u043E\u043D\u0444\u043B\u0438\u043A\u0442. \u0420\u0430\u0431\u043E\u0442\u0430\u0442\u044C \u0432\u0441\u043B\u0435\u043F\u0443\u044E \u043D\u0435\u043B\u044C\u0437\u044F.",
16566
- "\u0417\u0410\u041C\u0420\u0418 \u0438 \u0441\u043E\u0445\u0440\u0430\u043D\u0438\u0441\u044C, \u0447\u0442\u043E\u0431\u044B \u0440\u0430\u0431\u043E\u0442\u0430 \u043D\u0435 \u043F\u0440\u043E\u043F\u0430\u043B\u0430:",
16567
- "1. \u0417\u0430\u043A\u043E\u043C\u043C\u0438\u0442\u044C \u0412\u0421\u042E \u0442\u0435\u043A\u0443\u0449\u0443\u044E \u0440\u0430\u0431\u043E\u0442\u0443 \u043A\u0430\u043A \u0435\u0441\u0442\u044C: `git add -A && git commit` (\u0442\u0440\u0435\u0439\u043B\u0435\u0440 \u043F\u0440\u043E \u0434\u0440\u043E\u043D\u0430 \u2014 \u043A\u0430\u043A \u043E\u0431\u044B\u0447\u043D\u043E).",
16568
- " \u041D\u043E\u0432\u044B\u0439 \u043A\u043E\u0434 \u041D\u0415 \u043F\u0438\u0448\u0438, \u0437\u0430\u0434\u0430\u0447\u0443 \u0434\u0430\u043B\u044C\u0448\u0435 \u041D\u0415 \u0434\u0435\u043B\u0430\u0439 \u2014 \u0442\u043E\u043B\u044C\u043A\u043E \u0441\u043E\u0445\u0440\u0430\u043D\u0438 \u0443\u0436\u0435 \u0441\u0434\u0435\u043B\u0430\u043D\u043D\u043E\u0435, \u0431\u0435\u0437 \u043C\u0443\u0441\u043E\u0440\u043D\u044B\u0445 \u043A\u043E\u043C\u043C\u0438\u0442\u043E\u0432.",
16569
- `2. \u0417\u0430\u043F\u0443\u0448\u044C \u0432\u0435\u0442\u043A\u0443: \`git push -u origin ${branch}\` \u2014 \u043D\u0435\u0437\u0430\u043F\u0443\u0448\u0435\u043D\u043D\u043E\u0435 \u0443\u043C\u0440\u0451\u0442 \u0432\u043C\u0435\u0441\u0442\u0435 \u0441 \u043F\u0440\u043E\u0446\u0435\u0441\u0441\u043E\u043C.`,
16570
- "3. \u0417\u0430\u0432\u0435\u0440\u0448\u0438 \u0440\u0430\u0431\u043E\u0442\u0443 \u2014 \u0431\u043E\u043B\u044C\u0448\u0435 \u0438\u043D\u0441\u0442\u0440\u0443\u043C\u0435\u043D\u0442\u043E\u0432 \u041D\u0415 \u0437\u043E\u0432\u0438 (\u043D\u0438 report_step, \u043D\u0438 ask, \u043D\u0438 done). \u041F\u0440\u043E\u0441\u0442\u043E \u043E\u0441\u0442\u0430\u043D\u043E\u0432\u0438 \u0441\u0435\u0441\u0441\u0438\u044E.",
16571
- "\u041F\u0440\u043E\u0433\u043E\u043D \u043F\u043E\u043C\u0435\u0447\u0435\u043D \xABpaused\xBB. \u041A\u043E\u0433\u0434\u0430 \u043F\u043E\u0434\u043D\u0438\u043C\u0435\u0442\u0441\u044F \u043D\u043E\u0432\u044B\u0439 overmind, \u043E\u043D \u0440\u0430\u0437\u0431\u0443\u0434\u0438\u0442 \u0442\u0435\u0431\u044F \u0441 \u044D\u0442\u043E\u0433\u043E \u043C\u0435\u0441\u0442\u0430 (--continue) \u2014",
16572
- "\u043F\u0440\u043E\u0434\u043E\u043B\u0436\u0438\u0448\u044C \u043E\u0442\u0442\u0443\u0434\u0430. \u041D\u0435 \u043F\u0435\u0440\u0435\u0441\u043F\u0440\u0430\u0448\u0438\u0432\u0430\u0439 \u0438 \u043D\u0435 \u043F\u0440\u043E\u0434\u043E\u043B\u0436\u0430\u0439 \u0437\u0430\u0434\u0430\u0447\u0443 \u0441\u0435\u0439\u0447\u0430\u0441."
16573
- ].join("\n");
16758
+ };
16759
+ function isMutationTestFile(path) {
16760
+ const p = normalizePath2(path);
16761
+ if (isSnapshot(p)) return false;
16762
+ if (TEST_FILE_RE.test(p)) return true;
16763
+ return p.split("/").includes("__tests__");
16764
+ }
16765
+ function isMutationSkippedPath(path) {
16766
+ const p = normalizePath2(path);
16767
+ const top = p.split("/")[0] ?? "";
16768
+ if (ROOT_SKIP_DIRS.has(top)) return true;
16769
+ if (isSnapshot(p)) return true;
16770
+ const base3 = p.split("/").pop() ?? p;
16771
+ if (DOC_EXT_RE.test(base3)) return true;
16772
+ if (base3.endsWith(".lock")) return true;
16773
+ return LOCK_NAMES.has(base3.toLowerCase());
16774
+ }
16775
+ function parseNameStatusZ(text) {
16776
+ if (!text) return [];
16777
+ const parts = text.split("\0").filter((p) => p.length > 0);
16778
+ const out = [];
16779
+ for (let i = 0; i < parts.length; ) {
16780
+ const status = parts[i++];
16781
+ if (!status) break;
16782
+ const code = status[0] ?? "?";
16783
+ if (code === "R" || code === "C") {
16784
+ const oldPath = parts[i++];
16785
+ const path2 = parts[i++];
16786
+ if (!oldPath || !path2) throw new Error("\u0431\u0438\u0442\u044B\u0439 name-status: \u043F\u0435\u0440\u0435\u0438\u043C\u0435\u043D\u043E\u0432\u0430\u043D\u0438\u0435 \u0431\u0435\u0437 \u043F\u0443\u0442\u0435\u0439");
16787
+ out.push({ code, path: normalizePath2(path2), oldPath: normalizePath2(oldPath) });
16788
+ continue;
16789
+ }
16790
+ const path = parts[i++];
16791
+ if (!path) throw new Error(`\u0431\u0438\u0442\u044B\u0439 name-status: \u0441\u0442\u0430\u0442\u0443\u0441 ${status} \u0431\u0435\u0437 \u043F\u0443\u0442\u0438`);
16792
+ out.push({ code, path: normalizePath2(path) });
16793
+ }
16794
+ return out;
16574
16795
  }
16575
- function restInstruction() {
16576
- return [
16577
- "\u{1F4A4} \u0422\u044B \u0437\u0430\u043C\u0435\u0440 (rest). \u041F\u0440\u043E\u0433\u043E\u043D \u043F\u043E\u043C\u0435\u0447\u0435\u043D \xABpaused\xBB, \u0438 \u0441\u0435\u0439\u0447\u0430\u0441 \u043F\u0440\u043E\u0446\u0435\u0441\u0441 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u0441\u044F \u2014 \u044D\u0442\u043E \u041D\u041E\u0420\u041C\u0410 \u0434\u043B\u044F \u0413\u0435\u0440\u043E\u044F:",
16578
- "headless-\u0441\u0435\u0441\u0441\u0438\u044F \u0436\u0438\u0432\u0430, \u0442\u043E\u043B\u044C\u043A\u043E \u043F\u043E\u043A\u0430 \u0442\u044B \u0437\u043E\u0432\u0451\u0448\u044C \u0438\u043D\u0441\u0442\u0440\u0443\u043C\u0435\u043D\u0442\u044B, \u043F\u043E\u044D\u0442\u043E\u043C\u0443 \u0442\u044B \u0440\u0430\u0431\u043E\u0442\u0430\u0435\u0448\u044C \u0440\u044B\u0432\u043A\u0430\u043C\u0438.",
16579
- "\u0422\u0435\u0431\u044F \u0440\u0430\u0437\u0431\u0443\u0434\u0438\u0442 \u043E\u0432\u0435\u0440\u043C\u0430\u0439\u043D\u0434, \u043A\u043E\u0433\u0434\u0430 \u0432 \u043E\u0442\u0440\u044F\u0434\u0435 \u0447\u0442\u043E-\u0442\u043E \u043F\u0440\u043E\u0438\u0437\u043E\u0439\u0434\u0451\u0442 (\u0434\u0440\u043E\u043D \u0437\u0430\u0434\u0430\u043B \u0432\u043E\u043F\u0440\u043E\u0441, \u0441\u0434\u0430\u043B PR, \u0443\u043C\u0435\u0440),",
16580
- "\u0438\u043B\u0438 \u043E\u043F\u0435\u0440\u0430\u0442\u043E\u0440 \u0432\u0440\u0443\u0447\u043D\u0443\u044E (`swarm wake <runId>`). \u0422\u043E\u0433\u0434\u0430 \u043F\u0440\u043E\u0434\u043E\u043B\u0436\u0438\u0448\u044C \u0441 \u044D\u0442\u043E\u0433\u043E \u043C\u0435\u0441\u0442\u0430 (--continue).",
16581
- "\u0421\u0435\u0439\u0447\u0430\u0441 \u043F\u0440\u043E\u0441\u0442\u043E \u0437\u0430\u0432\u0435\u0440\u0448\u0438 \u0441\u0435\u0441\u0441\u0438\u044E: \u0431\u043E\u043B\u044C\u0448\u0435 \u0438\u043D\u0441\u0442\u0440\u0443\u043C\u0435\u043D\u0442\u043E\u0432 \u041D\u0415 \u0437\u043E\u0432\u0438. \u041D\u0438\u0447\u0435\u0433\u043E \u043D\u0435 \u043F\u0435\u0440\u0435\u0441\u043F\u0440\u0430\u0448\u0438\u0432\u0430\u0439."
16582
- ].join("\n");
16796
+ function classifyMutationDiff(entries) {
16797
+ const testFiles = [];
16798
+ const restore = [];
16799
+ const remove = [];
16800
+ const bucket = (path, kind) => {
16801
+ if (isMutationSkippedPath(path)) return;
16802
+ if (isMutationTestFile(path)) {
16803
+ if (kind !== "delete") testFiles.push(path);
16804
+ return;
16805
+ }
16806
+ if (kind === "add") remove.push(path);
16807
+ else restore.push(path);
16808
+ };
16809
+ for (const entry of entries) {
16810
+ if (entry.code === "R" || entry.code === "C") {
16811
+ bucket(entry.path, "add");
16812
+ if (entry.oldPath) bucket(entry.oldPath, "delete");
16813
+ continue;
16814
+ }
16815
+ if (entry.code === "A") bucket(entry.path, "add");
16816
+ else if (entry.code === "D") bucket(entry.path, "delete");
16817
+ else bucket(entry.path, "modify");
16818
+ }
16819
+ const tests = uniq(testFiles);
16820
+ const testSet = new Set(tests);
16821
+ const removed = uniq(remove).filter((p) => !testSet.has(p));
16822
+ const removeSet = new Set(removed);
16823
+ return {
16824
+ testFiles: tests,
16825
+ remove: removed,
16826
+ restore: uniq(restore).filter((p) => !testSet.has(p) && !removeSet.has(p))
16827
+ };
16583
16828
  }
16584
- function channelDownInstruction(slug, detail) {
16585
- return [
16586
- `\u26D4 \u0421\u0412\u042F\u0417\u042C \u0421 \u0414\u0415\u041C\u041E\u041D\u041E\u041C \u041F\u041E\u0422\u0415\u0420\u042F\u041D\u0410 \u2014 ${detail}.`,
16587
- "\u041E\u0442\u0447\u0438\u0442\u0430\u0442\u044C\u0441\u044F, \u0437\u0430\u0434\u0430\u0442\u044C \u0432\u043E\u043F\u0440\u043E\u0441 \u0438\u043B\u0438 \u0441\u0434\u0430\u0442\u044C \u0440\u0430\u0431\u043E\u0442\u0443 \u0441\u0435\u0439\u0447\u0430\u0441 \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043A\u0438 \u043D\u0435\u0447\u0435\u043C: \u0435\u0434\u0438\u043D\u0441\u0442\u0432\u0435\u043D\u043D\u044B\u0439 \u043A\u0430\u043D\u0430\u043B \u043D\u0430\u0440\u0443\u0436\u0443 \u2014 \u0434\u0435\u043C\u043E\u043D.",
16588
- "\u0417\u0410\u041C\u0420\u0418 \u0438 \u0441\u043E\u0445\u0440\u0430\u043D\u0438\u0441\u044C, \u0447\u0442\u043E\u0431\u044B \u0440\u0430\u0431\u043E\u0442\u0430 \u043D\u0435 \u043F\u0440\u043E\u043F\u0430\u043B\u0430:",
16589
- "1. \u0417\u0430\u043A\u043E\u043C\u043C\u0438\u0442\u044C \u0412\u0421\u042E \u0442\u0435\u043A\u0443\u0449\u0443\u044E \u0440\u0430\u0431\u043E\u0442\u0443 \u043A\u0430\u043A \u0435\u0441\u0442\u044C: `git add -A && git commit` (\u0442\u0440\u0435\u0439\u043B\u0435\u0440 \u043F\u0440\u043E \u0434\u0440\u043E\u043D\u0430 \u2014 \u043A\u0430\u043A \u043E\u0431\u044B\u0447\u043D\u043E).",
16590
- `2. \u0417\u0430\u043F\u0443\u0448\u044C \u0432\u0435\u0442\u043A\u0443: \`git push -u origin ${slug}\` \u2014 \u043D\u0435\u0437\u0430\u043F\u0443\u0448\u0435\u043D\u043D\u043E\u0435 \u0443\u043C\u0440\u0451\u0442 \u0432\u043C\u0435\u0441\u0442\u0435 \u0441 \u043F\u0440\u043E\u0446\u0435\u0441\u0441\u043E\u043C.`,
16591
- "3. \u0417\u0430\u0432\u0435\u0440\u0448\u0438 \u0440\u0430\u0431\u043E\u0442\u0443 \u2014 \u0438\u043D\u0441\u0442\u0440\u0443\u043C\u0435\u043D\u0442\u044B \u0431\u043E\u043B\u044C\u0448\u0435 \u041D\u0415 \u0437\u043E\u0432\u0438, \u043E\u043D\u0438 \u0432\u0441\u0451 \u0440\u0430\u0432\u043D\u043E \u043D\u0435 \u0434\u043E\u0435\u0434\u0443\u0442.",
16592
- "\u041A\u043E\u0433\u0434\u0430 \u0434\u0435\u043C\u043E\u043D \u043F\u043E\u0434\u043D\u0438\u043C\u0435\u0442\u0441\u044F, \u043E\u043D \u0443\u0432\u0438\u0434\u0438\u0442 \u0442\u0432\u043E\u044E \u0432\u0435\u0442\u043A\u0443 \u0438 \u0440\u0430\u0437\u0431\u0443\u0434\u0438\u0442 \u0442\u0435\u0431\u044F \u0441 \u044D\u0442\u043E\u0433\u043E \u043C\u0435\u0441\u0442\u0430 (--continue)."
16593
- ].join("\n");
16829
+ var PRESTART_RULES = [
16830
+ {
16831
+ label: "\u043D\u0435\u0442 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430",
16832
+ re: /Executable doesn't exist|browserType\.launch|playwright install/i
16833
+ },
16834
+ {
16835
+ label: "\u043D\u0435\u0442 \u0431\u0430\u0437\u044B",
16836
+ re: /ECONNREFUSED|password authentication failed|could not connect to server|Connection refused|database ".+" does not exist|Can't reach database server|P1001/i
16837
+ },
16838
+ {
16839
+ label: "\u043D\u0435\u0442 \u043E\u043A\u0440\u0443\u0436\u0435\u043D\u0438\u044F",
16840
+ re: /command not found|not recognized as an internal or external command|Cannot find module|MODULE_NOT_FOUND|ENOENT|Missing script:/i
16841
+ }
16842
+ ];
16843
+ var FAIL_MARK_RE = /(?:^|[\s[(])(?:FAILED|FAIL|✖|✗|×|✘)(?=$|[\s[(:])/;
16844
+ var PASS_MARK_RE = /(?:^|[\s[(])(?:PASSED|PASS|✓|✔|√)(?=$|[\s[(:])/;
16845
+ var BUN_FAIL_RE = /(?:^|\s)\(fail\)(?=$|\s)/i;
16846
+ var BUN_PASS_RE = /(?:^|\s)\(pass\)(?=$|\s)/i;
16847
+ async function runMutationGate(opts) {
16848
+ if (typeof opts.runTests !== "function") throw new Error("runMutationGate: \u043D\u0443\u0436\u043D\u0430 \u043A\u043E\u043C\u0430\u043D\u0434\u0430 \u0442\u0435\u0441\u0442\u043E\u0432 (runTests)");
16849
+ const base3 = opts.base.trim();
16850
+ if (!/^[A-Za-z0-9._/-]+$/.test(base3) || base3.includes("..") || base3.startsWith("-") || base3.startsWith("/") || base3.endsWith("/")) {
16851
+ throw new Error(`\u0431\u0430\u0437\u043E\u0432\u0430\u044F \u0432\u0435\u0442\u043A\u0430 \xAB${opts.base}\xBB \u043D\u0435 \u043F\u043E\u0445\u043E\u0436\u0430 \u043D\u0430 \u0438\u043C\u044F \u0432\u0435\u0442\u043A\u0438`);
16852
+ }
16853
+ const worktree = opts.worktree;
16854
+ const baseRef = `origin/${base3}`;
16855
+ const hasBase = await git(worktree, ["rev-parse", "--verify", "--quiet", `${baseRef}^{commit}`]);
16856
+ if (hasBase.exitCode !== 0) {
16857
+ throw new Error(`\u0431\u0430\u0437\u0430 ${baseRef} \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D\u0430 \u0432 ${worktree}`);
16858
+ }
16859
+ const diffOut = await gitOk(worktree, ["diff", "--name-status", "-z", "--find-renames", `${baseRef}...HEAD`]);
16860
+ const diff = classifyMutationDiff(parseNameStatusZ(diffOut));
16861
+ if (diff.testFiles.length === 0) {
16862
+ return { reddened: [], stayedGreen: [], notRun: [], output: "", headOutput: "", exitCode: null, testFiles: [] };
16863
+ }
16864
+ await sweepOrphans2(null);
16865
+ const source = diff.restore.length > 0 ? (await gitOk(worktree, ["merge-base", baseRef, "HEAD"])).trim() : null;
16866
+ const ac = new AbortController();
16867
+ let stop = null;
16868
+ const onExternal = () => {
16869
+ if (!stop) stop = { reason: "\u043E\u0442\u043C\u0435\u043D\u0435\u043D\u043E", code: "aborted" };
16870
+ ac.abort();
16871
+ };
16872
+ if (opts.signal) {
16873
+ if (opts.signal.aborted) onExternal();
16874
+ else opts.signal.addEventListener("abort", onExternal, { once: true });
16875
+ }
16876
+ let timer;
16877
+ let headOutput = "";
16878
+ let parent = "";
16879
+ let hooks = "";
16880
+ let copy = "";
16881
+ try {
16882
+ parent = realpathSync3(mkdtempSync(join36(tmpdir2(), COPY_PREFIX)));
16883
+ writeFileSync17(join36(parent, "owner.pid"), String(process.pid));
16884
+ hooks = join36(parent, "hooks");
16885
+ copy = join36(parent, basename6(parent));
16886
+ mkdirSync13(hooks);
16887
+ const env = runnerEnv(process.env);
16888
+ const reportFor = (phase) => {
16889
+ const file = join36(parent, `report-${phase}.json`);
16890
+ rmSync4(file, { force: true });
16891
+ return file;
16892
+ };
16893
+ await gitOk(worktree, ["worktree", "add", "--detach", copy, "HEAD"], {
16894
+ timeoutMs: WORKTREE_ADD_TIMEOUT_MS,
16895
+ hooksPath: hooks
16896
+ });
16897
+ if (opts.timeoutMs != null) {
16898
+ const ms = Math.max(0, opts.timeoutMs);
16899
+ if (ms === 0) {
16900
+ stop = { reason: "\u0442\u0430\u0439\u043C\u0430\u0443\u0442", code: "timeout" };
16901
+ ac.abort();
16902
+ } else {
16903
+ timer = setTimeout(() => {
16904
+ if (!stop) stop = { reason: "\u0442\u0430\u0439\u043C\u0430\u0443\u0442", code: "timeout" };
16905
+ ac.abort();
16906
+ }, ms);
16907
+ timer.unref?.();
16908
+ }
16909
+ }
16910
+ const headFile = reportFor("head");
16911
+ const headReport = await invokeRun(opts.runTests, { cwd: copy, testFiles: diff.testFiles, phase: "head", signal: ac.signal, env, reportFile: headFile });
16912
+ const headMap = verdicts(diff.testFiles, headReport, { repoRoot: copy, cwd: copy, reportFile: headFile });
16913
+ headOutput = clipTail(combineFull(headReport.stdout, headReport.stderr));
16914
+ const greenOnHead = diff.testFiles.filter((file) => headMap.get(file)?.status === "passed");
16915
+ if (greenOnHead.length === 0) {
16916
+ return {
16917
+ ...headWithoutGreen(diff.testFiles, headMap),
16918
+ output: headOutput,
16919
+ headOutput,
16920
+ exitCode: headReport.exitCode,
16921
+ testFiles: diff.testFiles
16922
+ };
16923
+ }
16924
+ await revertCode(copy, diff, source, hooks, ac.signal);
16925
+ await gitOk(copy, ["clean", "-ffdx", "-e", "node_modules"], { hooksPath: hooks, signal: ac.signal });
16926
+ const baseFile = reportFor("base");
16927
+ const baseReport = await invokeRun(opts.runTests, { cwd: copy, testFiles: greenOnHead, phase: "base", signal: ac.signal, env, reportFile: baseFile });
16928
+ const baseMap = verdicts(greenOnHead, baseReport, { repoRoot: copy, cwd: copy, reportFile: baseFile });
16929
+ return {
16930
+ ...comparePhases(diff.testFiles, headMap, baseMap),
16931
+ output: clipTail(combineFull(baseReport.stdout, baseReport.stderr)),
16932
+ headOutput,
16933
+ exitCode: baseReport.exitCode,
16934
+ testFiles: diff.testFiles
16935
+ };
16936
+ } catch (e) {
16937
+ if (!(e instanceof GateTimeout) && !ac.signal.aborted) throw e;
16938
+ if (copy) {
16939
+ try {
16940
+ await cleanupWorktreeProcesses(copy);
16941
+ } catch {
16942
+ }
16943
+ }
16944
+ const why = stop ?? { reason: "\u0442\u0430\u0439\u043C\u0430\u0443\u0442", code: "timeout" };
16945
+ return {
16946
+ reddened: [],
16947
+ stayedGreen: [],
16948
+ notRun: diff.testFiles.map((file) => ({ file, reason: why.reason, code: why.code })),
16949
+ output: "",
16950
+ headOutput,
16951
+ exitCode: null,
16952
+ testFiles: diff.testFiles
16953
+ };
16954
+ } finally {
16955
+ if (timer) clearTimeout(timer);
16956
+ opts.signal?.removeEventListener("abort", onExternal);
16957
+ if (parent) await destroyCopy(worktree, copy, parent, hooks);
16958
+ }
16959
+ }
16960
+ function comparePhases(testFiles, head, base3) {
16961
+ const reddened = [];
16962
+ const stayedGreen = [];
16963
+ const notRun = [];
16964
+ for (const file of testFiles) {
16965
+ if (notGreenOnHead(file, head.get(file), notRun)) continue;
16966
+ const onBase = base3.get(file);
16967
+ if (!onBase || onBase.status === "not-run") {
16968
+ notRun.push({ file, reason: cleanReason(onBase?.reason, "\u043D\u0430 \u0431\u0430\u0437\u0435 \u0442\u0435\u0441\u0442 \u043D\u0435 \u0437\u0430\u043F\u0443\u0441\u0442\u0438\u043B\u0441\u044F"), code: onBase?.code ?? "no-verdict" });
16969
+ } else if (onBase.status === "failed") reddened.push(file);
16970
+ else stayedGreen.push(file);
16971
+ }
16972
+ return { reddened, stayedGreen, notRun };
16973
+ }
16974
+ function headWithoutGreen(testFiles, head) {
16975
+ const stayedGreen = [];
16976
+ const notRun = [];
16977
+ for (const file of testFiles) {
16978
+ if (notGreenOnHead(file, head.get(file), notRun)) continue;
16979
+ stayedGreen.push(file);
16980
+ }
16981
+ return { reddened: [], stayedGreen, notRun };
16982
+ }
16983
+ function notGreenOnHead(file, onHead, notRun) {
16984
+ if (!onHead || onHead.status === "not-run") {
16985
+ notRun.push({ file, reason: cleanReason(onHead?.reason, "\u043D\u0430 HEAD \u0442\u0435\u0441\u0442 \u043D\u0435 \u0437\u0430\u043F\u0443\u0441\u0442\u0438\u043B\u0441\u044F"), code: onHead?.code ?? "no-verdict" });
16986
+ return true;
16987
+ }
16988
+ if (onHead.status === "failed") {
16989
+ const why = onHead.reason ? `\u043D\u0430 HEAD \u0443\u0436\u0435 \u043A\u0440\u0430\u0441\u043D\u044B\u0439: ${onHead.reason}` : "\u043D\u0430 HEAD \u0443\u0436\u0435 \u043A\u0440\u0430\u0441\u043D\u044B\u0439";
16990
+ notRun.push({ file, reason: cleanReason(why, why), code: "red-on-head" });
16991
+ return true;
16992
+ }
16993
+ return false;
16594
16994
  }
16595
- async function buildDroneServer(store, opts = {}) {
16596
- const askPollMs = opts.askPollMs ?? 2e3;
16597
- const server = new McpServer({ name: "overmind-drone", version: "0.1.0" });
16598
- const overmindDead = async () => !await store.alive();
16599
- const slugForInstruction = (fallback) => opts.expectedTaskSlug ?? fallback ?? "<slug>";
16600
- const iAmReviewer = (run2) => run2?.reviews_run_id != null || run2?.kind === "reviewer" || opts.reviewsRunId != null || opts.runKind === "reviewer";
16601
- const iAmVerifier = (run2) => run2?.verifies_run_id != null || run2?.kind === "verifier" || opts.verifiesRunId != null || opts.runKind === "verifier";
16602
- let pendingQuestion = null;
16603
- const freeze = async (withdraw = false) => {
16604
- let slug;
16605
- let branch;
16995
+ async function revertCode(copy, diff, source, hooks, signal) {
16996
+ const call = { hooksPath: hooks, signal };
16997
+ const removePaths = [...diff.remove].sort((a, b) => b.split("/").length - a.split("/").length || b.length - a.length);
16998
+ for (const chunk of chunks(removePaths, 80)) {
16999
+ await gitOk(copy, ["rm", "-f", "-q", "--", ...chunk], call);
17000
+ }
17001
+ const blocked = /* @__PURE__ */ new Set();
17002
+ for (const rel of diff.restore) {
17003
+ const abs = join36(copy, rel);
17004
+ if (!existsSync18(abs)) continue;
17005
+ let info;
16606
17006
  try {
16607
- 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");
16608
- const run2 = await store.myRun();
16609
- slug = run2?.task_slug;
16610
- branch = !opts.expectedTaskSlug || opts.expectedTaskSlug === run2?.task_slug ? run2?.branch : null;
16611
- if (run2 && run2.status !== "paused") {
16612
- await store.updateRun(null, { status: "paused" });
16613
- await store.addEvent(null, "paused", "overmind \u043D\u0435\u0434\u043E\u0441\u0442\u0443\u043F\u0435\u043D \u2014 \u0434\u0440\u043E\u043D \u0437\u0430\u043C\u0435\u0440, \u0440\u0430\u0431\u043E\u0442\u0430 \u0432 origin, \u0436\u0434\u0451\u0442 \u043F\u0435\u0440\u0435\u043F\u043E\u0434\u044A\u0451\u043C\u0430");
16614
- }
16615
- } catch (e) {
16616
- console.error("[overmind-drone] \u043F\u043E\u043C\u0435\u0442\u0438\u0442\u044C \u043F\u0440\u043E\u0433\u043E\u043D paused \u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C (\u043D\u0430\u0434\u0437\u043E\u0440 \u043D\u0435\u0434\u043E\u0441\u0442\u0443\u043F\u0435\u043D):", e);
17007
+ info = lstatSync2(abs);
17008
+ } catch {
17009
+ continue;
16617
17010
  }
16618
- return { content: [{ type: "text", text: freezeInstruction(branch || slugForInstruction(slug), opts.deadReason) }] };
16619
- };
16620
- const guard = (fn) => async (a, extra) => {
17011
+ if (!info.isDirectory()) continue;
17012
+ if (treeHoldsKept(copy, abs)) {
17013
+ blocked.add(rel);
17014
+ continue;
17015
+ }
17016
+ rmSync4(abs, { recursive: true, force: true });
17017
+ }
17018
+ const restore = diff.restore.filter((rel) => !blocked.has(rel));
17019
+ if (source && restore.length > 0) {
17020
+ for (const chunk of chunks(restore, 80)) {
17021
+ await gitOk(copy, ["restore", "--source", source, "--worktree", "--staged", "--", ...chunk], call);
17022
+ }
17023
+ }
17024
+ }
17025
+ function treeHoldsKept(copy, absDir) {
17026
+ const pending2 = [absDir];
17027
+ while (pending2.length > 0) {
17028
+ const dir = pending2.pop();
17029
+ if (!dir) continue;
17030
+ let names;
16621
17031
  try {
16622
- const result = await fn(a, extra);
16623
- const question = pendingQuestion;
16624
- if (question === null || extra.signal.aborted) return result;
17032
+ names = readdirSync18(dir);
17033
+ } catch {
17034
+ continue;
17035
+ }
17036
+ for (const name of names) {
17037
+ const abs = join36(dir, name);
17038
+ let info;
16625
17039
  try {
16626
- const cur = await store.myLastQuestion();
16627
- if (cur && cur.status === "answered" && cur.answer != null && cur.answer.trim() !== "" && sameQuestion(cur.text, question) && pendingQuestion === question && !extra.signal.aborted) {
16628
- pendingQuestion = null;
16629
- return { ...result, content: [{ type: "text", text: lateAnswerText(question, cur.answer) }, ...result.content] };
16630
- }
17040
+ info = lstatSync2(abs);
16631
17041
  } catch {
17042
+ continue;
16632
17043
  }
16633
- return result;
16634
- } catch (e) {
16635
- if (!(e instanceof ChannelUnavailableError)) throw e;
16636
- const text = channelDownInstruction(slugForInstruction(null), e.message);
16637
- console.error(`[overmind-drone] ${e.message} \u2014 \u0434\u0440\u043E\u043D \u0437\u0430\u043C\u0438\u0440\u0430\u0435\u0442`);
16638
- return { content: [{ type: "text", text }], isError: true };
16639
- }
16640
- };
16641
- server.tool(
16642
- "report_step",
16643
- "\u0417\u0430\u043F\u0438\u0441\u0430\u0442\u044C \u0442\u0435\u043A\u0443\u0449\u0438\u0439 \u0448\u0430\u0433 \u0440\u0430\u0431\u043E\u0442\u044B (\u0432\u0438\u0434\u0435\u043D \u043E\u043F\u0435\u0440\u0430\u0442\u043E\u0440\u0443 \u0432 \u043B\u043E\u0433\u0435 \u043F\u0440\u043E\u0433\u043E\u043D\u0430).",
16644
- { text: z.string().describe("\u0447\u0442\u043E \u0434\u0435\u043B\u0430\u0435\u0448\u044C \u043F\u0440\u044F\u043C\u043E \u0441\u0435\u0439\u0447\u0430\u0441") },
16645
- guard(async ({ text }) => {
16646
- if (await overmindDead()) return freeze();
16647
- await store.addEvent(null, "step", text);
16648
- return { content: [{ type: "text", text: "ok" }] };
16649
- })
16650
- );
16651
- server.tool(
16652
- "read_task",
16653
- "\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).",
16654
- {},
16655
- guard(async () => {
16656
- if (!opts.taskless) {
16657
- return {
16658
- 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." }],
16659
- isError: true
16660
- };
16661
- }
16662
- const run2 = await store.myRun().catch(() => null);
16663
- const slug = opts.expectedTaskSlug ?? run2?.task_slug;
16664
- let mismatchNote;
16665
- if (opts.expectedTaskSlug && !run2) {
16666
- mismatchNote = `\u26A0\uFE0F \u0434\u0435\u043C\u043E\u043D \u043D\u0435 \u043E\u0442\u0434\u0430\u043B \u0442\u0432\u043E\u0439 \u043F\u0440\u043E\u0433\u043E\u043D \u2014 \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u043D slug \u0438\u0437 \u0441\u043F\u0430\u0432\u043D\u0430.`;
16667
- } else if (opts.expectedTaskSlug && run2 && run2.task_slug !== opts.expectedTaskSlug) {
16668
- mismatchNote = `\u26A0\uFE0F \u0434\u0435\u043C\u043E\u043D \u0447\u0438\u0441\u043B\u0438\u0442 \u0442\u0432\u043E\u0439 \u043F\u0440\u043E\u0433\u043E\u043D \u043A\u0430\u043A \xAB${run2.task_slug}\xBB \u2014 \u044D\u0442\u043E \u041D\u0415 \u0442\u0432\u043E\u044F \u0437\u0430\u0434\u0430\u0447\u0430 (TASWM-211). \u0418\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u043D \u0434\u043E\u0432\u0435\u0440\u0435\u043D\u043D\u044B\u0439 slug \u0438\u0437 \u0441\u043F\u0430\u0432\u043D\u0430.`;
17044
+ if (info.isDirectory() && !info.isSymbolicLink()) {
17045
+ pending2.push(abs);
17046
+ continue;
16669
17047
  }
16670
- if (!slug) return { content: [{ type: "text", text: "\u043F\u0440\u043E\u0433\u043E\u043D \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D" }], isError: true };
16671
- const read = await opts.taskless.getTaskDetailed(slug);
16672
- if (!read.ok) {
16673
- const failText = readTaskFailureInstruction(slug, read.failure);
16674
- return {
16675
- content: [{ type: "text", text: mismatchNote ? `${mismatchNote}
16676
-
16677
- ${failText}` : failText }],
16678
- isError: true
16679
- };
17048
+ if (keptOnRevert(copy, abs)) return true;
17049
+ }
17050
+ }
17051
+ return false;
17052
+ }
17053
+ function keptOnRevert(copy, abs) {
17054
+ let rel = normalizePath2(relative2(copy, abs));
17055
+ if (rel.startsWith("./")) rel = rel.slice(2);
17056
+ if (!rel || rel === ".." || rel.startsWith("../")) return false;
17057
+ return isMutationTestFile(rel) || isMutationSkippedPath(rel);
17058
+ }
17059
+ async function invokeRun(run2, ctx) {
17060
+ if (ctx.signal.aborted) throw new GateTimeout();
17061
+ const pending2 = run2(ctx);
17062
+ pending2.catch(() => {
17063
+ });
17064
+ return await new Promise((resolve6, reject) => {
17065
+ const onAbort = () => reject(new GateTimeout());
17066
+ ctx.signal.addEventListener("abort", onAbort, { once: true });
17067
+ pending2.then(
17068
+ (value) => {
17069
+ ctx.signal.removeEventListener("abort", onAbort);
17070
+ if (ctx.signal.aborted) reject(new GateTimeout());
17071
+ else resolve6(value);
17072
+ },
17073
+ (err) => {
17074
+ ctx.signal.removeEventListener("abort", onAbort);
17075
+ if (ctx.signal.aborted) reject(new GateTimeout());
17076
+ else reject(err);
16680
17077
  }
16681
- const task = read.task;
16682
- const context = await fetchTaskContext(opts.taskless, task, { full: true });
16683
- const attachments = await prepareTaskAttachments({
16684
- worktree: opts.worktree ?? process.cwd(),
16685
- refs: task.attachments,
16686
- fetchFile: opts.taskless.fetchFile?.bind(opts.taskless),
16687
- onEvent: (text) => text.includes("\u043D\u0435 \u0441\u043A\u0430\u0447\u0430\u043B\u043E\u0441\u044C") ? store.addEvent(null, "step", text) : void 0
16688
- });
16689
- const lines = [
16690
- `**${task.title}** \xB7 ${task.slug}${task.url ? ` (${task.url})` : ""}`,
16691
- "",
16692
- task.description || "(\u043F\u0443\u0441\u0442\u043E)"
16693
- ];
16694
- if (context) lines.push("", context);
16695
- if (attachments) lines.push("", attachments);
16696
- if (mismatchNote) lines.unshift(mismatchNote, "");
16697
- return { content: [{ type: "text", text: lines.join("\n") }] };
16698
- })
17078
+ );
17079
+ });
17080
+ }
17081
+ function verdicts(testFiles, report, scope) {
17082
+ const stripped = stripAnsi(combineFull(report.stdout, report.stderr));
17083
+ if (report.started === false) {
17084
+ const reason2 = cleanReason(report.reason, prestartReason(stripped) ?? "\u043A\u043E\u043C\u0430\u043D\u0434\u0430 \u0443\u043F\u0430\u043B\u0430 \u0434\u043E \u0437\u0430\u043F\u0443\u0441\u043A\u0430 \u0442\u0435\u0441\u0442\u043E\u0432");
17085
+ return fillAll(testFiles, { status: "not-run", reason: reason2, code: "not-started" });
17086
+ }
17087
+ const fromFile = scope.reportFile ? reportFileVerdicts(testFiles, scope.reportFile, scope.repoRoot ?? "") : null;
17088
+ if (fromFile) return align(testFiles, fromFile, "\u043E\u0442\u0447\u0451\u0442 \u0440\u0430\u043D\u043D\u0435\u0440\u0430 \u043D\u0435 \u043D\u0430\u0437\u0432\u0430\u043B \u044D\u0442\u043E\u0442 \u0444\u0430\u0439\u043B");
17089
+ const explicit = explicitVerdicts(testFiles, report, scope, stripped);
17090
+ if (explicit) return align(testFiles, explicit, "\u043A\u043E\u043C\u0430\u043D\u0434\u0430 \u043D\u0435 \u0441\u043E\u043E\u0431\u0449\u0438\u043B\u0430 \u0438\u0442\u043E\u0433 \u043F\u043E \u044D\u0442\u043E\u043C\u0443 \u0444\u0430\u0439\u043B\u0443");
17091
+ const { found: marks, sawFilePass } = readMarks(testFiles, stripped);
17092
+ if (marks.size > 0) {
17093
+ if (!sawFilePass) {
17094
+ for (const file of testFiles) {
17095
+ if (!marks.has(file)) marks.set(file, { status: "passed" });
17096
+ }
17097
+ }
17098
+ return align(testFiles, marks, "\u0432 \u0432\u044B\u0432\u043E\u0434\u0435 \u043A\u043E\u043C\u0430\u043D\u0434\u044B \u043D\u0435\u0442 \u0438\u0442\u043E\u0433\u0430 \u043F\u043E \u044D\u0442\u043E\u043C\u0443 \u0444\u0430\u0439\u043B\u0443");
17099
+ }
17100
+ if (report.exitCode === 0) return fillAll(testFiles, { status: "passed" });
17101
+ const prestart = prestartReason(stripped);
17102
+ const reason = cleanReason(
17103
+ report.reason,
17104
+ prestart ?? (report.exitCode === null ? "\u043A\u043E\u043C\u0430\u043D\u0434\u0430 \u043D\u0435 \u0437\u0430\u043F\u0443\u0441\u0442\u0438\u043B\u0430\u0441\u044C" : `\u043A\u043E\u043C\u0430\u043D\u0434\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043B\u0430\u0441\u044C \u0441 \u043A\u043E\u0434\u043E\u043C ${report.exitCode}, \u043D\u0435 \u043D\u0430\u0437\u0432\u0430\u0432 \u0442\u0435\u0441\u0442\u044B`)
17105
+ );
17106
+ const code = prestart || report.exitCode === null ? "not-started" : "no-verdict";
17107
+ return fillAll(testFiles, { status: "not-run", reason, code });
17108
+ }
17109
+ function explicitVerdicts(testFiles, report, scope, stripped) {
17110
+ const listed = report.files?.filter((f) => f.file.length > 0) ?? [];
17111
+ if (listed.length > 0) return mapReports(testFiles, listed, scope.repoRoot ?? "", "not-started");
17112
+ const fromOut = parseJsonReport(report.stdout) ?? parseJsonReport(report.stderr);
17113
+ if (fromOut) {
17114
+ const mapped = mapReports(testFiles, fromOut, scope.repoRoot ?? "");
17115
+ if (mapped.size > 0) return mapped;
17116
+ }
17117
+ const file = scope.cwd ? reportFileFromOutput(stripped, scope.cwd) : null;
17118
+ return file ? reportFileVerdicts(testFiles, file, scope.repoRoot ?? "") : null;
17119
+ }
17120
+ function reportFileVerdicts(testFiles, file, repoRoot2) {
17121
+ let text;
17122
+ try {
17123
+ text = readFileSync26(file, "utf8");
17124
+ } catch {
17125
+ return null;
17126
+ }
17127
+ const parsed = parseJsonReport(text);
17128
+ if (!parsed) return null;
17129
+ const mapped = mapReports(testFiles, parsed, repoRoot2);
17130
+ return mapped.size > 0 ? mapped : null;
17131
+ }
17132
+ function runnerEnv(source) {
17133
+ const out = {};
17134
+ for (const [key, value] of Object.entries(source)) {
17135
+ if (value === void 0) continue;
17136
+ const upper = key.toUpperCase();
17137
+ if (AGENT_ENV_NAMES.has(upper) || AGENT_ENV_PREFIXES.some((prefix) => upper.startsWith(prefix))) continue;
17138
+ if (upper === "TERM_PROGRAM" && /kiro/.test(value)) continue;
17139
+ if (upper === "EDITOR" && /devin/.test(value)) continue;
17140
+ out[key] = value;
17141
+ }
17142
+ return out;
17143
+ }
17144
+ function mapReports(testFiles, reports, repoRoot2, notRunCode = "no-verdict") {
17145
+ const out = /* @__PURE__ */ new Map();
17146
+ for (const report of reports) {
17147
+ const file = resolveReportedPath(report.file, testFiles, repoRoot2);
17148
+ if (!file) continue;
17149
+ const next = { status: report.status };
17150
+ if (report.reason) next.reason = report.reason;
17151
+ if (report.status === "not-run") next.code = notRunCode;
17152
+ out.set(file, mergeVerdict(out.get(file), next));
17153
+ }
17154
+ return out;
17155
+ }
17156
+ function align(testFiles, found, missingReason) {
17157
+ const out = /* @__PURE__ */ new Map();
17158
+ for (const file of testFiles) {
17159
+ out.set(file, found.get(file) ?? { status: "not-run", reason: missingReason, code: "no-verdict" });
17160
+ }
17161
+ return out;
17162
+ }
17163
+ function fillAll(testFiles, verdict) {
17164
+ const out = /* @__PURE__ */ new Map();
17165
+ for (const file of testFiles) out.set(file, verdict);
17166
+ return out;
17167
+ }
17168
+ function mergeVerdict(prev, next) {
17169
+ if (!prev) return next;
17170
+ const status = prev.status === "failed" || next.status === "failed" ? "failed" : prev.status === "not-run" || next.status === "not-run" ? "not-run" : "passed";
17171
+ const out = { status };
17172
+ const reason = next.reason ?? prev.reason;
17173
+ if (reason) out.reason = reason;
17174
+ const code = next.code ?? prev.code;
17175
+ if (status === "not-run" && code) out.code = code;
17176
+ return out;
17177
+ }
17178
+ function readMarks(testFiles, output) {
17179
+ const found = /* @__PURE__ */ new Map();
17180
+ if (!output) return { found, sawFilePass: false };
17181
+ const index = buildNeedles(testFiles);
17182
+ let current = null;
17183
+ let sawFilePass = false;
17184
+ for (const raw of output.split("\n")) {
17185
+ const line = raw.trim();
17186
+ if (!line) continue;
17187
+ const mentioned = filesOnLine(line, index);
17188
+ if (mentioned.length === 1) current = mentioned[0] ?? null;
17189
+ const failed = FAIL_MARK_RE.test(line) || BUN_FAIL_RE.test(line);
17190
+ const passed = !failed && (PASS_MARK_RE.test(line) || BUN_PASS_RE.test(line));
17191
+ if (!failed && !passed) continue;
17192
+ const targets = mentioned.length > 0 ? mentioned : current ? [current] : [];
17193
+ if (passed && targets.length > 0) sawFilePass = true;
17194
+ const reason = line.slice(0, 300);
17195
+ for (const file of targets) remember(found, file, failed ? "failed" : "passed", reason);
17196
+ }
17197
+ return { found, sawFilePass };
17198
+ }
17199
+ function remember(map, file, status, reason) {
17200
+ const prev = map.get(file);
17201
+ if (prev?.status === "failed") return;
17202
+ if (status === "failed") map.set(file, { status, reason });
17203
+ else if (!prev) map.set(file, { status: "passed" });
17204
+ }
17205
+ function buildNeedles(testFiles) {
17206
+ const out = [];
17207
+ for (const file of testFiles) {
17208
+ out.push({ file, needle: file });
17209
+ const parts = file.split("/");
17210
+ for (let i = 1; i < parts.length; i++) {
17211
+ const needle = parts.slice(i).join("/");
17212
+ const owners = testFiles.filter((f) => f === needle || f.endsWith(`/${needle}`));
17213
+ if (owners.length === 1 && owners[0] === file) out.push({ file, needle });
17214
+ }
17215
+ }
17216
+ out.sort((a, b) => b.needle.length - a.needle.length);
17217
+ return out;
17218
+ }
17219
+ function filesOnLine(line, index) {
17220
+ const seen = /* @__PURE__ */ new Set();
17221
+ const out = [];
17222
+ for (const item of index) {
17223
+ if (seen.has(item.file)) continue;
17224
+ if (!lineMentions(line, item.needle)) continue;
17225
+ seen.add(item.file);
17226
+ out.push(item.file);
17227
+ }
17228
+ return out;
17229
+ }
17230
+ function lineMentions(line, file) {
17231
+ let from = 0;
17232
+ while (from < line.length) {
17233
+ const at = line.indexOf(file, from);
17234
+ if (at < 0) return false;
17235
+ const before = at === 0 ? "" : line[at - 1] ?? "";
17236
+ const after = line[at + file.length] ?? "";
17237
+ if (boundaryBefore(before) && boundaryAfter(after)) return true;
17238
+ from = at + file.length;
17239
+ }
17240
+ return false;
17241
+ }
17242
+ function boundaryBefore(ch) {
17243
+ return ch === "" || /[\s"'`(<:\[]/.test(ch);
17244
+ }
17245
+ function boundaryAfter(ch) {
17246
+ return ch === "" || ch === ":" || /[\s"'`):,\]]/.test(ch);
17247
+ }
17248
+ function parseJsonReport(text) {
17249
+ const trimmed = text.trim();
17250
+ if (!trimmed.startsWith("{")) return null;
17251
+ try {
17252
+ return reportsFromJson(JSON.parse(trimmed));
17253
+ } catch {
17254
+ return null;
17255
+ }
17256
+ }
17257
+ function reportsFromJson(value) {
17258
+ if (!value || typeof value !== "object") return null;
17259
+ const rec = value;
17260
+ if (Array.isArray(rec.testResults)) {
17261
+ const out = [];
17262
+ for (const item of rec.testResults) {
17263
+ if (!item || typeof item !== "object") continue;
17264
+ const row = item;
17265
+ const name = typeof row.name === "string" ? row.name : "";
17266
+ if (!name) continue;
17267
+ const message = typeof row.message === "string" ? row.message.trim() : "";
17268
+ const failure = firstAssertionFailure(row);
17269
+ const reason = (message || failure).slice(0, 300);
17270
+ out.push({
17271
+ file: name,
17272
+ status: mapStatus(typeof row.status === "string" ? row.status : ""),
17273
+ ...reason ? { reason } : {}
17274
+ });
17275
+ }
17276
+ return out.length > 0 ? out : null;
17277
+ }
17278
+ if (Array.isArray(rec.suites)) {
17279
+ const out = [];
17280
+ flattenPlaywright(rec.suites, out);
17281
+ return out.length > 0 ? out : null;
17282
+ }
17283
+ return null;
17284
+ }
17285
+ function firstAssertionFailure(row) {
17286
+ if (!Array.isArray(row.assertionResults)) return "";
17287
+ for (const item of row.assertionResults) {
17288
+ if (!item || typeof item !== "object") continue;
17289
+ const messages = item.failureMessages;
17290
+ if (!Array.isArray(messages)) continue;
17291
+ const text = messages.find((m) => typeof m === "string" && m.trim().length > 0);
17292
+ if (typeof text === "string") return text.trim().split("\n")[0] ?? "";
17293
+ }
17294
+ return "";
17295
+ }
17296
+ function flattenPlaywright(suites, out) {
17297
+ for (const item of suites) {
17298
+ if (!item || typeof item !== "object") continue;
17299
+ const suite = item;
17300
+ const file = typeof suite.file === "string" ? suite.file : "";
17301
+ if (file && Array.isArray(suite.specs)) {
17302
+ const verdict = playwrightSpecs(suite.specs);
17303
+ out.push(verdict.reason ? { file, status: verdict.status, reason: verdict.reason } : { file, status: verdict.status });
17304
+ }
17305
+ if (Array.isArray(suite.suites)) flattenPlaywright(suite.suites, out);
17306
+ }
17307
+ }
17308
+ function playwrightSpecs(specs) {
17309
+ let failed = false;
17310
+ let passed = false;
17311
+ let reason = "";
17312
+ for (const item of specs) {
17313
+ if (!item || typeof item !== "object") continue;
17314
+ const spec = item;
17315
+ if (spec.ok === false) failed = true;
17316
+ const tests = Array.isArray(spec.tests) ? spec.tests : [];
17317
+ for (const test of tests) {
17318
+ if (!test || typeof test !== "object") continue;
17319
+ const results = test.results;
17320
+ if (!Array.isArray(results)) continue;
17321
+ for (const result of results) {
17322
+ if (!result || typeof result !== "object") continue;
17323
+ const status = String(result.status ?? "");
17324
+ if (status === "failed" || status === "timedOut" || status === "interrupted") {
17325
+ failed = true;
17326
+ if (!reason) {
17327
+ const err = result.error;
17328
+ if (err && typeof err === "object" && typeof err.message === "string") {
17329
+ reason = String(err.message);
17330
+ } else reason = status;
17331
+ }
17332
+ } else if (status === "passed" || status === "expected") passed = true;
17333
+ }
17334
+ }
17335
+ }
17336
+ if (failed) return reason ? { status: "failed", reason: reason.slice(0, 300) } : { status: "failed" };
17337
+ if (passed) return { status: "passed" };
17338
+ return { status: "not-run", reason: "\u0442\u0435\u0441\u0442\u044B \u0444\u0430\u0439\u043B\u0430 \u043F\u0440\u043E\u043F\u0443\u0449\u0435\u043D\u044B" };
17339
+ }
17340
+ function mapStatus(status) {
17341
+ const s = status.toLowerCase();
17342
+ if (s === "failed" || s === "fail" || s === "timedout" || s === "interrupted") return "failed";
17343
+ if (s === "passed" || s === "pass" || s === "success" || s === "expected") return "passed";
17344
+ return "not-run";
17345
+ }
17346
+ function resolveReportedPath(reported, testFiles, repoRoot2) {
17347
+ let p = normalizePath2(reported.trim());
17348
+ if (p.startsWith("file://")) p = p.slice("file://".length);
17349
+ const root = normalizePath2(repoRoot2).replace(/\/$/, "");
17350
+ if (root && (p === root || p.startsWith(`${root}/`))) p = p.slice(root.length + 1);
17351
+ if (testFiles.includes(p)) return p;
17352
+ const byAbsolute = testFiles.filter((f) => p === f || p.endsWith(`/${f}`));
17353
+ if (byAbsolute.length === 1) return byAbsolute[0] ?? null;
17354
+ const bySuffix = testFiles.filter((f) => f === p || f.endsWith(`/${p}`));
17355
+ if (bySuffix.length === 1) return bySuffix[0] ?? null;
17356
+ return null;
17357
+ }
17358
+ function reportFileFromOutput(output, cwd) {
17359
+ const match = REPORT_PATH_RE.exec(output);
17360
+ const raw = match?.[1]?.trim();
17361
+ if (!raw) return null;
17362
+ const abs = isAbsolute6(raw) ? raw : join36(cwd, raw);
17363
+ if (!isInside(cwd, abs)) return null;
17364
+ return abs;
17365
+ }
17366
+ function isInside(parent, child) {
17367
+ let root;
17368
+ let target;
17369
+ try {
17370
+ root = realpathSync3(parent);
17371
+ target = realpathSync3(child);
17372
+ } catch {
17373
+ return false;
17374
+ }
17375
+ return target === root || target.startsWith(`${root}${sep4}`);
17376
+ }
17377
+ function prestartReason(output) {
17378
+ if (!output) return null;
17379
+ for (const rule of PRESTART_RULES) {
17380
+ if (!rule.re.test(output)) continue;
17381
+ const line = output.split("\n").map((l) => l.trim()).find((l) => rule.re.test(l));
17382
+ return line ? `${rule.label}: ${line.slice(0, 300)}` : rule.label;
17383
+ }
17384
+ return null;
17385
+ }
17386
+ function combineFull(stdout, stderr) {
17387
+ return [stdout, stderr].map((s) => s.replace(/\s+$/u, "")).filter((s) => s.length > 0).join("\n");
17388
+ }
17389
+ function clipTail(text) {
17390
+ if (text.length <= MAX_OUTPUT_CHARS) return text;
17391
+ return `\u2026 \u0432\u044B\u0432\u043E\u0434 \u043E\u0431\u0440\u0435\u0437\u0430\u043D, \u043F\u043E\u043A\u0430\u0437\u0430\u043D \u0445\u0432\u043E\u0441\u0442
17392
+ ${text.slice(-MAX_OUTPUT_CHARS)}`;
17393
+ }
17394
+ function stripAnsi(text) {
17395
+ return text.replace(ANSI_RE, "");
17396
+ }
17397
+ function cleanReason(reason, fallback) {
17398
+ const text = reason?.trim();
17399
+ return (text ? text : fallback).slice(0, 500);
17400
+ }
17401
+ function normalizePath2(path) {
17402
+ return path.replaceAll("\\", "/");
17403
+ }
17404
+ function isSnapshot(path) {
17405
+ const parts = path.split("/");
17406
+ const base3 = parts[parts.length - 1] ?? path;
17407
+ if (base3.endsWith(".snap")) return true;
17408
+ return parts.some((seg) => SNAPSHOT_DIR_RE.test(seg) || SNAPSHOT_SUFFIX_RE.test(seg));
17409
+ }
17410
+ function uniq(items) {
17411
+ const seen = /* @__PURE__ */ new Set();
17412
+ const out = [];
17413
+ for (const item of items) {
17414
+ if (seen.has(item)) continue;
17415
+ seen.add(item);
17416
+ out.push(item);
17417
+ }
17418
+ return out;
17419
+ }
17420
+ function chunks(items, size) {
17421
+ const out = [];
17422
+ for (let i = 0; i < items.length; i += size) out.push(items.slice(i, i + size));
17423
+ return out;
17424
+ }
17425
+ async function git(cwd, args, call = {}) {
17426
+ const prefix = [];
17427
+ if (call.hooksPath) prefix.push("-c", `core.hooksPath=${call.hooksPath.replaceAll("\\", "/")}`);
17428
+ const options = {
17429
+ reject: false,
17430
+ timeout: call.timeoutMs ?? GIT_TIMEOUT_MS,
17431
+ windowsHide: true,
17432
+ env: { ...process.env, GIT_TERMINAL_PROMPT: "0" }
17433
+ };
17434
+ try {
17435
+ const res = await execa2("git", ["-C", cwd, ...prefix, ...args], call.signal ? { ...options, cancelSignal: call.signal } : options);
17436
+ return {
17437
+ stdout: res.stdout ?? "",
17438
+ stderr: res.stderr ?? "",
17439
+ exitCode: typeof res.exitCode === "number" ? res.exitCode : 1
17440
+ };
17441
+ } catch (e) {
17442
+ if (call.signal?.aborted) throw new GateTimeout();
17443
+ const msg = e instanceof Error ? e.message : String(e);
17444
+ throw new Error(`git ${args.join(" ")} \u0432 ${cwd} \u043D\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043B\u0441\u044F: ${msg}`);
17445
+ }
17446
+ }
17447
+ async function gitOk(cwd, args, call) {
17448
+ const res = await git(cwd, args, call);
17449
+ if (res.exitCode !== 0) {
17450
+ const detail = (res.stderr || res.stdout).trim().split("\n")[0] ?? "";
17451
+ throw new Error(`git ${args.join(" ")} \u043D\u0435 \u043F\u0440\u043E\u0448\u0451\u043B (\u043A\u043E\u0434 ${res.exitCode})${detail ? `: ${detail}` : ""}`);
17452
+ }
17453
+ return res.stdout;
17454
+ }
17455
+ function ownerAlive(dir) {
17456
+ try {
17457
+ const pid = Number(readFileSync26(join36(dir, "owner.pid"), "utf8").trim());
17458
+ if (!Number.isInteger(pid) || pid <= 0) return false;
17459
+ process.kill(pid, 0);
17460
+ return true;
17461
+ } catch (e) {
17462
+ return e.code === "EPERM";
17463
+ }
17464
+ }
17465
+ async function sweepOrphans2(exclude) {
17466
+ let names;
17467
+ try {
17468
+ names = readdirSync18(tmpdir2());
17469
+ } catch {
17470
+ return;
17471
+ }
17472
+ const skip = exclude ? safeRealpath(exclude) : null;
17473
+ for (const name of names) {
17474
+ if (!name.startsWith(COPY_PREFIX)) continue;
17475
+ const dir = join36(tmpdir2(), name);
17476
+ let st;
17477
+ try {
17478
+ st = lstatSync2(dir);
17479
+ } catch {
17480
+ continue;
17481
+ }
17482
+ if (st.isSymbolicLink() || !st.isDirectory()) continue;
17483
+ if (st.uid !== process.getuid?.()) continue;
17484
+ const real = safeRealpath(dir);
17485
+ if (!real || skip && real === skip) continue;
17486
+ if (ownerAlive(dir)) continue;
17487
+ if (!existsSync18(join36(dir, "owner.pid"))) {
17488
+ const age = Date.now() - safeMtime(dir);
17489
+ if (age < ORPHAN_FRESH_MS) continue;
17490
+ }
17491
+ try {
17492
+ await forceRemoveCopy(dir, null);
17493
+ } catch {
17494
+ }
17495
+ }
17496
+ }
17497
+ function safeRealpath(path) {
17498
+ try {
17499
+ return realpathSync3(path);
17500
+ } catch {
17501
+ return null;
17502
+ }
17503
+ }
17504
+ function safeMtime(path) {
17505
+ try {
17506
+ return statSync16(path).mtimeMs;
17507
+ } catch {
17508
+ return 0;
17509
+ }
17510
+ }
17511
+ function repoFromGitFile(wt) {
17512
+ try {
17513
+ const text = readFileSync26(join36(wt, ".git"), "utf8");
17514
+ const line = text.split("\n").find((l) => l.startsWith("gitdir:"));
17515
+ if (!line) return null;
17516
+ const gitdir = line.slice("gitdir:".length).trim();
17517
+ const marker = "/.git/worktrees/";
17518
+ const at = gitdir.lastIndexOf(marker);
17519
+ if (at < 0) return null;
17520
+ return gitdir.slice(0, at);
17521
+ } catch {
17522
+ return null;
17523
+ }
17524
+ }
17525
+ async function forceRemoveCopy(dir, repo) {
17526
+ const named = join36(dir, basename6(dir));
17527
+ const legacy = !existsSync18(named);
17528
+ const wt = legacy ? join36(dir, "wt") : named;
17529
+ const hooks = join36(dir, "hooks");
17530
+ const from = repo ?? (existsSync18(wt) ? repoFromGitFile(wt) : null);
17531
+ if (existsSync18(wt)) {
17532
+ try {
17533
+ await cleanupWorktreeProcesses(wt, legacy ? { containers: "keep" } : {});
17534
+ } catch {
17535
+ }
17536
+ if (from) {
17537
+ if (!existsSync18(hooks)) mkdirSync13(hooks, { recursive: true });
17538
+ await git(from, ["worktree", "remove", "-f", "-f", wt], { hooksPath: hooks });
17539
+ }
17540
+ }
17541
+ const call = existsSync18(hooks) ? { hooksPath: hooks } : {};
17542
+ if (from) {
17543
+ try {
17544
+ await git(from, ["worktree", "prune"], call);
17545
+ } catch {
17546
+ }
17547
+ }
17548
+ try {
17549
+ await rm3(dir, { recursive: true, force: true });
17550
+ } catch {
17551
+ try {
17552
+ rmSync4(dir, { recursive: true, force: true });
17553
+ } catch {
17554
+ }
17555
+ }
17556
+ }
17557
+ async function destroyCopy(worktree, copy, parent, hooks) {
17558
+ if (existsSync18(copy)) {
17559
+ try {
17560
+ await cleanupWorktreeProcesses(copy);
17561
+ } catch {
17562
+ }
17563
+ }
17564
+ if (hooks && !existsSync18(hooks)) {
17565
+ try {
17566
+ mkdirSync13(hooks, { recursive: true });
17567
+ } catch {
17568
+ }
17569
+ }
17570
+ const call = hooks && existsSync18(hooks) ? { hooksPath: hooks } : {};
17571
+ try {
17572
+ await git(worktree, ["worktree", "remove", "-f", "-f", copy], call);
17573
+ } catch {
17574
+ }
17575
+ try {
17576
+ await git(worktree, ["worktree", "prune"], call);
17577
+ } catch {
17578
+ }
17579
+ try {
17580
+ await rm3(parent, { recursive: true, force: true });
17581
+ } catch {
17582
+ try {
17583
+ rmSync4(parent, { recursive: true, force: true });
17584
+ } catch {
17585
+ }
17586
+ }
17587
+ }
17588
+
17589
+ // src/doneMutation.ts
17590
+ import { copyFileSync as copyFileSync6, existsSync as existsSync19, mkdirSync as mkdirSync14 } from "fs";
17591
+ import { dirname as dirname6, isAbsolute as isAbsolute7, join as join37, relative as relative3 } from "path";
17592
+ import { execa as execa3 } from "execa";
17593
+ var MUTATION_REFUSAL_LIMIT = 3;
17594
+ var MUTATION_GATE_TIMEOUT_MS = 15 * 6e4;
17595
+ var MUTATION_REFUSAL_MARK = "\u0433\u0435\u0439\u0442 \u043C\u0443\u0442\u0430\u0446\u0438\u0438: \u0441\u0434\u0430\u0447\u0430 \u043D\u0435 \u043F\u0440\u0438\u043D\u044F\u0442\u0430";
17596
+ var MUTATION_UNVERIFIED_EVENT = "\u043D\u0435\u0447\u0435\u043C \u0433\u043E\u043D\u044F\u0442\u044C \u0442\u0435\u0441\u0442\u044B \u2014 \u043C\u0443\u0442\u0430\u0446\u0438\u044F \u043D\u0435 \u043F\u0440\u043E\u0432\u0435\u0440\u0435\u043D\u0430";
17597
+ var MUTATION_CEILING_EVENT = "\u0433\u0435\u0439\u0442 \u043C\u0443\u0442\u0430\u0446\u0438\u0438: \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";
17598
+ var MUTATION_UNSCOPED_EVENT = "\u043A\u043E\u043C\u0430\u043D\u0434\u0430 \u0442\u0435\u0441\u0442\u043E\u0432 \u043D\u0435 \u0441\u0443\u0436\u0430\u0435\u0442\u0441\u044F \u0434\u043E \u0444\u0430\u0439\u043B\u043E\u0432 \u2014 \u043C\u0443\u0442\u0430\u0446\u0438\u044F \u043D\u0435 \u043F\u0440\u043E\u0432\u0435\u0440\u0435\u043D\u0430";
17599
+ var MUTATION_TESTS_ONLY_EVENT = "\u0432 \u0434\u0438\u0444\u0444\u0435 \u0442\u043E\u043B\u044C\u043A\u043E \u0442\u0435\u0441\u0442\u044B \u2014 \u043E\u0442\u043A\u0430\u0442\u044B\u0432\u0430\u0442\u044C \u043D\u0435\u0447\u0435\u0433\u043E";
17600
+ function mutationGateStartEvent(testCount) {
17601
+ return `\u0433\u0435\u0439\u0442 \u043C\u0443\u0442\u0430\u0446\u0438\u0438: \u043F\u0440\u043E\u0432\u0435\u0440\u044F\u044E ${testCount} \u0442\u0435\u0441\u0442\u043E\u0432 \u0432 \u043A\u043E\u043F\u0438\u0438 (\u0434\u043E 15 \u043C\u0438\u043D)`;
17602
+ }
17603
+ var OUTPUT_TAIL = 12e3;
17604
+ function mutationGateApplies(run2) {
17605
+ if (!run2) return true;
17606
+ if (run2.resolves_run_id != null) return false;
17607
+ if (needsFixIteration(run2)) return false;
17608
+ return true;
17609
+ }
17610
+ function mutationBaseBranch(raw) {
17611
+ let name = (raw ?? "").trim();
17612
+ if (name.startsWith("origin/")) name = name.slice("origin/".length).trim();
17613
+ if (!name || name === "HEAD") return "main";
17614
+ return name;
17615
+ }
17616
+ function countMutationRefusals(events) {
17617
+ return events.filter((e) => (e.text ?? "").includes(MUTATION_REFUSAL_MARK)).length;
17618
+ }
17619
+ var TEST_TOOL_RE = /\b(?:vitest|jest|pytest|py\.test|phpunit|rspec|mocha|ava|playwright|cypress|ctest)\b/i;
17620
+ var TEST_RUNNER_RE = /\b(?:go|cargo|mvn|gradle|dotnet|mix|swift|flutter|dart|composer|bun|deno|npm|pnpm|yarn)\b[^\n;&|]*\btest\b/i;
17621
+ var TEST_WORD_RE = /\b(?:tests?|specs?)\b/i;
17622
+ function isTestCommand(command) {
17623
+ const text = command.trim();
17624
+ if (!text) return false;
17625
+ return TEST_TOOL_RE.test(text) || TEST_RUNNER_RE.test(text) || TEST_WORD_RE.test(text);
17626
+ }
17627
+ function verifyLineDropped(command) {
17628
+ if (/<[^>\n]+>|&lt;[^&\n]*&gt;/.test(command)) return true;
17629
+ if (/\$\(/.test(command)) return true;
17630
+ if (/(?:^|[;&|]\s*)\bcd\b/.test(command)) return true;
17631
+ if (/\bgh\b/.test(command)) return true;
17632
+ if (/\bdocker\b/.test(command)) return true;
17633
+ if (/\b(?:test-db-up|docker-compose|compose|migrate)\b/.test(command)) return true;
17634
+ return false;
17635
+ }
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
+ }
17645
+ function selectVerifyCommand(commands) {
17646
+ if (!commands?.length) return null;
17647
+ const lines = commands.map((c) => c.trim()).filter((c) => c.length > 0);
17648
+ if (lines.length === 0) return null;
17649
+ const narrow = lines.filter((line) => !verifyLineDropped(line) && NARROW_TOOL_RE.test(line));
17650
+ if (narrow[0]) return narrow[0];
17651
+ const sawTest = lines.some((line) => isTestCommand(line) || verifyLineDropped(line));
17652
+ return sawTest ? { kind: "unscoped" } : null;
17653
+ }
17654
+ function shellQuote(value) {
17655
+ return `'${value.replace(/'/g, `'\\''`)}'`;
17656
+ }
17657
+ function appendMissingFiles(command, files) {
17658
+ const missing = files.filter((f) => f.length > 0 && !command.includes(f));
17659
+ if (missing.length === 0) return command;
17660
+ return `${command} ${missing.map(shellQuote).join(" ")}`;
17661
+ }
17662
+ function decorateOne(command, ctx) {
17663
+ const report = shellQuote(ctx.reportFile);
17664
+ const hasReport = /--outputFile(?:\s|=)/.test(command);
17665
+ if (/\bvitest\b/.test(command)) {
17666
+ const withReport = hasReport ? command : `${command} --reporter=json --outputFile=${report}`;
17667
+ return appendMissingFiles(withReport, ctx.testFiles);
17668
+ }
17669
+ if (/\bjest\b/.test(command)) {
17670
+ const withReport = hasReport ? command : `${command} --json --outputFile=${report}`;
17671
+ return appendMissingFiles(withReport, ctx.testFiles);
17672
+ }
17673
+ if (/\bpytest\b|\bpy\.test\b/.test(command)) return appendMissingFiles(command, ctx.testFiles);
17674
+ return command;
17675
+ }
17676
+ function decorateTestCommand(command, ctx) {
17677
+ return command.split(/\s*&&\s*/).map((part) => decorateOne(part.trim(), ctx)).filter((part) => part.length > 0).join(" && ");
17678
+ }
17679
+ function stripPnpmFilter(command) {
17680
+ return command.replace(/\s--filter(?:=|\s+)(?:'[^']*'|"[^"]*"|\S+)/g, "").replace(/[ \t]{2,}/g, " ").trim();
17681
+ }
17682
+ function nearestPackageDir(root, fileRel) {
17683
+ let dir = dirname6(join37(root, fileRel));
17684
+ for (; ; ) {
17685
+ const rel = relative3(root, dir);
17686
+ if (rel.startsWith("..") || isAbsolute7(rel)) return root;
17687
+ if (existsSync19(join37(dir, "package.json"))) return dir;
17688
+ if (rel === "") return root;
17689
+ const parent = dirname6(dir);
17690
+ if (parent === dir) return root;
17691
+ dir = parent;
17692
+ }
17693
+ }
17694
+ function scopeVerifyCommand(command, ctx) {
17695
+ const root = ctx.cwd;
17696
+ const first = ctx.testFiles.find((f) => f.length > 0);
17697
+ if (!first || !NARROW_TOOL_RE.test(command)) {
17698
+ return { command: decorateTestCommand(command, ctx), cwd: root };
17699
+ }
17700
+ const pkg = nearestPackageDir(root, first);
17701
+ const relFiles = ctx.testFiles.filter((f) => {
17702
+ const rel = relative3(pkg, join37(root, f));
17703
+ return rel.length > 0 && !rel.startsWith("..") && !isAbsolute7(rel);
17704
+ }).map((f) => relative3(pkg, join37(root, f)).replaceAll("\\", "/"));
17705
+ const scoped = pkg === root ? command : stripPnpmFilter(command);
17706
+ return { command: decorateTestCommand(scoped, { reportFile: ctx.reportFile, testFiles: relFiles }), cwd: pkg };
17707
+ }
17708
+ function asText(value) {
17709
+ return typeof value === "string" ? value : value == null ? "" : String(value);
17710
+ }
17711
+ async function copyIgnoredEnv(sourceWorktree, destRoot) {
17712
+ const res = await execa3("git", ["ls-files", "-oi", "--exclude-standard", "--directory", "-z"], {
17713
+ cwd: sourceWorktree,
17714
+ reject: false
17715
+ });
17716
+ if (typeof res.exitCode === "number" && res.exitCode !== 0) return;
17717
+ for (const rel of asText(res.stdout).split("\0")) {
17718
+ if (!rel) continue;
17719
+ const norm = rel.replaceAll("\\", "/");
17720
+ if (norm.split("/").includes("node_modules")) continue;
17721
+ const base3 = norm.split("/").pop() ?? "";
17722
+ if (!base3.startsWith(".env")) continue;
17723
+ const to = join37(destRoot, rel);
17724
+ mkdirSync14(dirname6(to), { recursive: true });
17725
+ try {
17726
+ copyFileSync6(join37(sourceWorktree, rel), to);
17727
+ } catch {
17728
+ }
17729
+ }
17730
+ }
17731
+ async function runVerifyCommand(command, ctx, prep = {}) {
17732
+ if (ctx.signal.aborted) {
17733
+ return { exitCode: null, stdout: "", stderr: "", started: false, reason: "\u043E\u0442\u043C\u0435\u043D\u0435\u043D\u043E" };
17734
+ }
17735
+ try {
17736
+ if (prep.sourceWorktree) await copyIgnoredEnv(prep.sourceWorktree, ctx.cwd);
17737
+ const prepared = await ensureWorktreeDeps(ctx.cwd, {
17738
+ override: prep.prepare ?? null,
17739
+ skipOptional: true,
17740
+ skipEnvCache: true
17741
+ });
17742
+ if (prepared.outcome === "failed" || prepared.outcome === "blocked") {
17743
+ const why = [...prepared.failed, ...prepared.blocked].join(", ") || prepared.outcome;
17744
+ return { exitCode: null, stdout: "", stderr: why, started: false, reason: `\u043A\u043E\u043F\u0438\u044E \u043D\u0435 \u043F\u043E\u0434\u0433\u043E\u0442\u043E\u0432\u0438\u0442\u044C: ${why}` };
17745
+ }
17746
+ } catch (e) {
17747
+ const why = e instanceof Error ? e.message : String(e);
17748
+ return { exitCode: null, stdout: "", stderr: why, started: false, reason: `\u043A\u043E\u043F\u0438\u044E \u043D\u0435 \u043F\u043E\u0434\u0433\u043E\u0442\u043E\u0432\u0438\u0442\u044C: ${why}` };
17749
+ }
17750
+ const scoped = scopeVerifyCommand(command, ctx);
17751
+ const env = { ...ctx.env };
17752
+ delete env.VITEST;
17753
+ delete env.VITEST_WORKER_ID;
17754
+ delete env.VITEST_POOL_ID;
17755
+ try {
17756
+ const res = await execa3(scoped.command, {
17757
+ shell: true,
17758
+ cwd: scoped.cwd,
17759
+ env,
17760
+ extendEnv: false,
17761
+ reject: false,
17762
+ cancelSignal: ctx.signal,
17763
+ maxBuffer: 50 * 1024 * 1024
17764
+ });
17765
+ const aborted = ctx.signal.aborted;
17766
+ return {
17767
+ exitCode: typeof res.exitCode === "number" ? res.exitCode : null,
17768
+ stdout: asText(res.stdout),
17769
+ stderr: asText(res.stderr),
17770
+ started: !aborted,
17771
+ ...aborted ? { reason: "\u043E\u0442\u043C\u0435\u043D\u0435\u043D\u043E" } : {}
17772
+ };
17773
+ } catch (e) {
17774
+ return {
17775
+ exitCode: null,
17776
+ stdout: "",
17777
+ stderr: e instanceof Error ? e.message : String(e),
17778
+ started: false,
17779
+ reason: ctx.signal.aborted ? "\u043E\u0442\u043C\u0435\u043D\u0435\u043D\u043E" : e instanceof Error ? e.message : String(e)
17780
+ };
17781
+ }
17782
+ }
17783
+ function clipTail2(text) {
17784
+ if (text.length <= OUTPUT_TAIL) return text;
17785
+ return `\u2026
17786
+ ${text.slice(-OUTPUT_TAIL)}`;
17787
+ }
17788
+ function mutationNotRunLine(notRun) {
17789
+ if (notRun.length === 0) return null;
17790
+ const parts = notRun.map((n) => `${n.file} \u2014 ${n.reason}`);
17791
+ return `\u041C\u0443\u0442\u0430\u0446\u0438\u044F: \u043D\u0435 \u0437\u0430\u043F\u0443\u0441\u0442\u0438\u043B\u0438\u0441\u044C (\u0441\u0434\u0430\u0447\u0443 \u043D\u0435 \u0431\u043B\u043E\u043A\u0438\u0440\u0443\u044E\u0442): ${parts.join("; ")}`;
17792
+ }
17793
+ function refusalText(result) {
17794
+ const files = result.stayedGreen.map((f) => `- ${f}`).join("\n");
17795
+ return [
17796
+ "\u0413\u0435\u0439\u0442 \u043C\u0443\u0442\u0430\u0446\u0438\u0438: \u0441\u0434\u0430\u0447\u0430 \u043D\u0435 \u043F\u0440\u0438\u043D\u044F\u0442\u0430.",
17797
+ "",
17798
+ "\u0422\u0435\u0441\u0442\u044B \u043E\u0441\u0442\u0430\u043B\u0438\u0441\u044C \u0437\u0435\u043B\u0451\u043D\u044B\u043C\u0438 \u0431\u0435\u0437 \u043F\u0440\u0430\u0432\u043A\u0438:",
17799
+ files,
17800
+ "",
17801
+ "\u0427\u0442\u043E \u0441\u0434\u0435\u043B\u0430\u0442\u044C: \u0442\u0435\u0441\u0442 \u0434\u043E\u043B\u0436\u0435\u043D \u043F\u0440\u043E\u0432\u0435\u0440\u044F\u0442\u044C \u043F\u0440\u0430\u0432\u043A\u0443. \u041E\u043D \u0437\u0435\u043B\u0451\u043D\u044B\u0439 \u0438 \u043D\u0430 \u043A\u043E\u0434\u0435 \u0431\u0430\u0437\u044B, \u0437\u043D\u0430\u0447\u0438\u0442 \u043D\u0435 \u043B\u043E\u0432\u0438\u0442 \u0434\u0435\u0444\u0435\u043A\u0442. \u041F\u043E\u043F\u0440\u0430\u0432\u044C \u0442\u0435\u0441\u0442 \u0442\u0430\u043A, \u0447\u0442\u043E\u0431\u044B \u0431\u0435\u0437 \u043F\u0440\u0430\u0432\u043A\u0438 \u043E\u043D \u043F\u0430\u0434\u0430\u043B, \u0438 \u0437\u043E\u0432\u0438 done() \u0441\u043D\u043E\u0432\u0430.",
17802
+ "\u0421\u0435\u0441\u0441\u0438\u044F \u043F\u0440\u043E\u0434\u043E\u043B\u0436\u0430\u0435\u0442\u0441\u044F.",
17803
+ "",
17804
+ "\u0412\u044B\u0432\u043E\u0434 \u043F\u0440\u043E\u0433\u043E\u043D\u0430 (\u043A\u043E\u0434 \u0431\u0430\u0437\u044B, \u0431\u0435\u0437 \u043F\u0440\u0430\u0432\u043A\u0438):",
17805
+ clipTail2(result.output)
17806
+ ].join("\n");
17807
+ }
17808
+ function decideMutation(result, priorRefusals) {
17809
+ const notRunLine = mutationNotRunLine(result.notRun);
17810
+ if (result.testFiles.length === 0) {
17811
+ return {
17812
+ kind: "accept",
17813
+ events: ["\u043C\u0443\u0442\u0430\u0446\u0438\u044F: \u043D\u043E\u0432\u044B\u0445 \u0438\u043B\u0438 \u0438\u0437\u043C\u0435\u043D\u0451\u043D\u043D\u044B\u0445 \u0442\u0435\u0441\u0442\u043E\u0432 \u043D\u0435\u0442 \u2014 \u043F\u0440\u043E\u0432\u0435\u0440\u044F\u0442\u044C \u043D\u0435\u0447\u0435\u0433\u043E"],
17814
+ summaryLine: null,
17815
+ note: ""
17816
+ };
17817
+ }
17818
+ if (result.reddened.length > 0) {
17819
+ return {
17820
+ kind: "accept",
17821
+ events: [`\u043C\u0443\u0442\u0430\u0446\u0438\u044F: \u043F\u043E\u043A\u0440\u0430\u0441\u043D\u0435\u043B\u0438 \u0431\u0435\u0437 \u043F\u0440\u0430\u0432\u043A\u0438: ${result.reddened.join(", ")}`, ...notRunLine ? [notRunLine] : []],
17822
+ summaryLine: notRunLine,
17823
+ note: ""
17824
+ };
17825
+ }
17826
+ const wouldRefuse = result.stayedGreen.length > 0;
17827
+ if (wouldRefuse && priorRefusals >= MUTATION_REFUSAL_LIMIT) {
17828
+ return {
17829
+ kind: "accept",
17830
+ events: [MUTATION_CEILING_EVENT, ...notRunLine ? [notRunLine] : []],
17831
+ summaryLine: notRunLine,
17832
+ note: `
17833
+
17834
+ \u26A0\uFE0F ${MUTATION_CEILING_EVENT}`
17835
+ };
17836
+ }
17837
+ if (wouldRefuse) {
17838
+ return {
17839
+ kind: "refuse",
17840
+ text: refusalText(result),
17841
+ event: `${MUTATION_REFUSAL_MARK}: ${result.stayedGreen.join(", ")}`
17842
+ };
17843
+ }
17844
+ return {
17845
+ kind: "accept",
17846
+ events: notRunLine ? [notRunLine] : [],
17847
+ summaryLine: notRunLine,
17848
+ note: ""
17849
+ };
17850
+ }
17851
+ var UNCAUGHT_TEST_RE = /(?:^|\/)(?:[^/]*_test\.go|test_[^/]*\.py)$/;
17852
+ function uncaughtTestPaths(paths) {
17853
+ const out = [];
17854
+ for (const raw of paths) {
17855
+ const path = raw.replaceAll("\\", "/").replace(/^\.\//, "");
17856
+ if (UNCAUGHT_TEST_RE.test(path) && !out.includes(path)) out.push(path);
17857
+ }
17858
+ return out;
17859
+ }
17860
+ function uncaughtTestLine(paths) {
17861
+ return `\u043D\u0435 \u0441\u043C\u043E\u0433 \u043F\u0440\u043E\u0432\u0435\u0440\u0438\u0442\u044C \u043C\u0443\u0442\u0430\u0446\u0438\u044E: ${paths.join(", ")} \u2014 *_test.go \u0438 test_*.py \u043C\u043E\u0434\u0443\u043B\u044C \u0441\u0447\u0438\u0442\u0430\u0435\u0442 \u043A\u043E\u0434\u043E\u043C, \u044D\u0442\u043E \u043D\u0435 \xAB\u043F\u0440\u043E\u0448\u043B\u043E\xBB \u0438 \u043D\u0435 \xAB\u0442\u0435\u0441\u0442\u043E\u0432 \u043D\u0435\u0442\xBB`;
17862
+ }
17863
+ async function changedPathsForMutation(worktree, base3) {
17864
+ const res = await execa3("git", ["diff", "--name-only", "-z", `origin/${base3}...HEAD`], {
17865
+ cwd: worktree,
17866
+ reject: false,
17867
+ timeout: 3e4
17868
+ });
17869
+ if (typeof res.exitCode === "number" && res.exitCode !== 0) return [];
17870
+ return asText(res.stdout).split("\0").map((p) => p.trim()).filter((p) => p.length > 0);
17871
+ }
17872
+ function withUncaught(decision, missed) {
17873
+ if (missed.length === 0) return decision;
17874
+ const line = uncaughtTestLine(missed);
17875
+ if (decision.kind === "refuse") {
17876
+ return { ...decision, text: `${decision.text}
17877
+
17878
+ ${line}` };
17879
+ }
17880
+ const events = decision.events.filter((e) => !e.includes("\u043F\u0440\u043E\u0432\u0435\u0440\u044F\u0442\u044C \u043D\u0435\u0447\u0435\u0433\u043E"));
17881
+ events.unshift(line);
17882
+ const summaryLine = decision.summaryLine ? `${decision.summaryLine}
17883
+ ${line}` : line;
17884
+ return { ...decision, events, summaryLine };
17885
+ }
17886
+ function normDiffPath(raw) {
17887
+ return raw.replaceAll("\\", "/").replace(/^\.\//, "");
17888
+ }
17889
+ function mutationTestCount(paths) {
17890
+ let n = 0;
17891
+ for (const raw of paths) {
17892
+ const path = normDiffPath(raw);
17893
+ if (!path || isMutationSkippedPath(path)) continue;
17894
+ if (isMutationTestFile(path)) n += 1;
17895
+ }
17896
+ return n;
17897
+ }
17898
+ function diffIsTestsOnly(paths) {
17899
+ if (mutationTestCount(paths) === 0) return false;
17900
+ for (const raw of paths) {
17901
+ const path = normDiffPath(raw);
17902
+ if (!path || isMutationSkippedPath(path) || isMutationTestFile(path)) continue;
17903
+ return false;
17904
+ }
17905
+ return true;
17906
+ }
17907
+ async function diffNames(input, base3) {
17908
+ try {
17909
+ return input.changedPaths ? await input.changedPaths() : await changedPathsForMutation(input.worktree, base3);
17910
+ } catch {
17911
+ return [];
17912
+ }
17913
+ }
17914
+ async function gateDoneMutation(input) {
17915
+ if (!mutationGateApplies(input.run)) return { kind: "skip" };
17916
+ let loaded;
17917
+ try {
17918
+ loaded = await input.loadCommand();
17919
+ } catch (e) {
17920
+ const why = e instanceof Error ? e.message : String(e);
17921
+ return { kind: "accept", events: [`${MUTATION_UNVERIFIED_EVENT} (${why})`], summaryLine: null, note: "" };
17922
+ }
17923
+ if (loaded && typeof loaded === "object") {
17924
+ return { kind: "accept", events: [MUTATION_UNSCOPED_EVENT], summaryLine: null, note: "" };
17925
+ }
17926
+ const command = loaded;
17927
+ if (!command) {
17928
+ return { kind: "accept", events: [MUTATION_UNVERIFIED_EVENT], summaryLine: null, note: "" };
17929
+ }
17930
+ const base3 = mutationBaseBranch(input.run?.base_branch);
17931
+ const names = await diffNames(input, base3);
17932
+ if (diffIsTestsOnly(names)) {
17933
+ return { kind: "accept", events: [MUTATION_TESTS_ONLY_EVENT], summaryLine: null, note: "" };
17934
+ }
17935
+ if (input.signal?.aborted) return { kind: "cancelled" };
17936
+ try {
17937
+ await input.emit?.(mutationGateStartEvent(mutationTestCount(names)));
17938
+ const result = await input.runGate({
17939
+ worktree: input.worktree,
17940
+ base: base3,
17941
+ command,
17942
+ ...input.signal ? { signal: input.signal } : {}
17943
+ });
17944
+ if (input.signal?.aborted) return { kind: "cancelled" };
17945
+ const decision = decideMutation(result, countMutationRefusals(input.events));
17946
+ return withUncaught(decision, uncaughtTestPaths(names));
17947
+ } catch (e) {
17948
+ if (input.signal?.aborted) return { kind: "cancelled" };
17949
+ const why = e instanceof Error ? e.message : String(e);
17950
+ return {
17951
+ kind: "accept",
17952
+ events: [`\u0433\u0435\u0439\u0442 \u043C\u0443\u0442\u0430\u0446\u0438\u0438 \u043D\u0435 \u043E\u0442\u0440\u0430\u0431\u043E\u0442\u0430\u043B (${why}) \u2014 \u0441\u0434\u0430\u0447\u0430 \u043D\u0435 \u0431\u043B\u043E\u043A\u0438\u0440\u0443\u0435\u0442\u0441\u044F`],
17953
+ summaryLine: null,
17954
+ note: ""
17955
+ };
17956
+ }
17957
+ }
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
+
18458
+ // src/droneServer.ts
18459
+ init_src();
18460
+ var mutationGateInFlight = /* @__PURE__ */ new Set();
18461
+ function mutationFlightKey(runId) {
18462
+ return runId == null ? "run:none" : `run:${runId}`;
18463
+ }
18464
+ function readTaskFailureInstruction(slug, failure) {
18465
+ const why = describeToolFailure(failure);
18466
+ if (TOOL_FAILURE_RETRIABLE[failure.code]) {
18467
+ return `\u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u043F\u0435\u0440\u0435\u0447\u0438\u0442\u0430\u0442\u044C \u0437\u0430\u0434\u0430\u0447\u0443 ${slug}: ${why}. \u042D\u0442\u043E \u0432\u0440\u0435\u043C\u0435\u043D\u043D\u043E \u0438 \u043B\u0435\u0447\u0438\u0442\u0441\u044F \u043F\u043E\u0432\u0442\u043E\u0440\u043E\u043C \u2014 \u0440\u0430\u0431\u043E\u0442\u0430\u0439 \u043F\u043E\u043A\u0430 \u043F\u043E \u0442\u043E\u043C\u0443, \u0447\u0442\u043E \u0443\u0436\u0435 \u0432 \u043F\u0440\u043E\u043C\u043F\u0442\u0435, \u0438 \u043F\u043E\u0437\u043E\u0432\u0438 read_task \u0435\u0449\u0451 \u0440\u0430\u0437 \u043F\u043E\u0437\u0436\u0435 (\u043F\u0435\u0440\u0435\u0434 \u0441\u0434\u0430\u0447\u0435\u0439 \u2014 \u043E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u043E).`;
18468
+ }
18469
+ return [
18470
+ `\u26D4 \u0417\u0410\u0414\u0410\u0427\u0423 ${slug} \u041F\u0420\u041E\u0427\u0418\u0422\u0410\u0422\u042C \u041D\u0415\u041B\u042C\u0417\u042F: ${why}.`,
18471
+ "\u041F\u043E\u0432\u0442\u043E\u0440 \u0442\u0443\u0442 \u043D\u0435 \u043F\u043E\u043C\u043E\u0436\u0435\u0442 \u2014 \u043F\u0440\u0438\u0447\u0438\u043D\u0430 \u043D\u0435 \u0432 \u0441\u0435\u0442\u0438, \u043E\u043D\u0430 \u0441\u0430\u043C\u0430 \u043D\u0435 \u0440\u0430\u0437\u043E\u0439\u0434\u0451\u0442\u0441\u044F.",
18472
+ "\u041D\u0415 \u0440\u0430\u0431\u043E\u0442\u0430\u0439 \u043F\u043E \u0441\u043B\u0430\u0433\u0443 \u0438 \u043F\u043E \u043F\u0430\u043C\u044F\u0442\u0438: \u043F\u043E\u0441\u0442\u0430\u043D\u043E\u0432\u043A\u0430, \u043A\u043E\u0442\u043E\u0440\u043E\u0439 \u0442\u044B \u043D\u0435 \u0432\u0438\u0434\u0435\u043B, \u043D\u0435 \u0432\u043E\u0441\u0441\u0442\u0430\u043D\u0430\u0432\u043B\u0438\u0432\u0430\u0435\u0442\u0441\u044F \u0438\u0437 \u043D\u0430\u0437\u0432\u0430\u043D\u0438\u044F \u0437\u0430\u0434\u0430\u0447\u0438 (TASWM-288).",
18473
+ "\u0421\u043F\u0440\u043E\u0441\u0438 \u043E\u043F\u0435\u0440\u0430\u0442\u043E\u0440\u0430 \u0447\u0435\u0440\u0435\u0437 ask() \u2014 \u043D\u0430\u0437\u043E\u0432\u0438 \u0435\u043C\u0443 \u044D\u0442\u0443 \u043F\u0440\u0438\u0447\u0438\u043D\u0443 \u0434\u043E\u0441\u043B\u043E\u0432\u043D\u043E \u2014 \u0438 \u0434\u0430\u043B\u044C\u0448\u0435 \u0434\u0435\u043B\u0430\u0439 \u0442\u043E, \u0447\u0442\u043E \u043E\u043D \u043E\u0442\u0432\u0435\u0442\u0438\u0442."
18474
+ ].join("\n");
18475
+ }
18476
+ function freezeInstruction(branch, reason = "\u0435\u0433\u043E \u043F\u0443\u043B\u044C\u0441 (heartbeat) \u0443\u0441\u0442\u0430\u0440\u0435\u043B") {
18477
+ return [
18478
+ `\u26D4 OVERMIND \u041D\u0415\u0414\u041E\u0421\u0422\u0423\u041F\u0415\u041D \u2014 ${reason}. \u041D\u0430\u0434\u0437\u043E\u0440\u0430 \u043D\u0430\u0434 \u0442\u043E\u0431\u043E\u0439 \u0441\u0435\u0439\u0447\u0430\u0441 \u043D\u0435\u0442: \u043D\u0435\u043A\u043E\u043C\u0443`,
18479
+ "\u043F\u0440\u0438\u043D\u044F\u0442\u044C \u0442\u0432\u043E\u0439 \u0432\u043E\u043F\u0440\u043E\u0441, \u0437\u0430\u043C\u0435\u0442\u0438\u0442\u044C \u0441\u043C\u0435\u0440\u0442\u044C, \u0441\u043C\u0435\u0440\u0436\u0438\u0442\u044C PR \u0438\u043B\u0438 \u0440\u0430\u0437\u0440\u0443\u043B\u0438\u0442\u044C \u043A\u043E\u043D\u0444\u043B\u0438\u043A\u0442. \u0420\u0430\u0431\u043E\u0442\u0430\u0442\u044C \u0432\u0441\u043B\u0435\u043F\u0443\u044E \u043D\u0435\u043B\u044C\u0437\u044F.",
18480
+ "\u0417\u0410\u041C\u0420\u0418 \u0438 \u0441\u043E\u0445\u0440\u0430\u043D\u0438\u0441\u044C, \u0447\u0442\u043E\u0431\u044B \u0440\u0430\u0431\u043E\u0442\u0430 \u043D\u0435 \u043F\u0440\u043E\u043F\u0430\u043B\u0430:",
18481
+ "1. \u0417\u0430\u043A\u043E\u043C\u043C\u0438\u0442\u044C \u0412\u0421\u042E \u0442\u0435\u043A\u0443\u0449\u0443\u044E \u0440\u0430\u0431\u043E\u0442\u0443 \u043A\u0430\u043A \u0435\u0441\u0442\u044C: `git add -A && git commit` (\u0442\u0440\u0435\u0439\u043B\u0435\u0440 \u043F\u0440\u043E \u0434\u0440\u043E\u043D\u0430 \u2014 \u043A\u0430\u043A \u043E\u0431\u044B\u0447\u043D\u043E).",
18482
+ " \u041D\u043E\u0432\u044B\u0439 \u043A\u043E\u0434 \u041D\u0415 \u043F\u0438\u0448\u0438, \u0437\u0430\u0434\u0430\u0447\u0443 \u0434\u0430\u043B\u044C\u0448\u0435 \u041D\u0415 \u0434\u0435\u043B\u0430\u0439 \u2014 \u0442\u043E\u043B\u044C\u043A\u043E \u0441\u043E\u0445\u0440\u0430\u043D\u0438 \u0443\u0436\u0435 \u0441\u0434\u0435\u043B\u0430\u043D\u043D\u043E\u0435, \u0431\u0435\u0437 \u043C\u0443\u0441\u043E\u0440\u043D\u044B\u0445 \u043A\u043E\u043C\u043C\u0438\u0442\u043E\u0432.",
18483
+ `2. \u0417\u0430\u043F\u0443\u0448\u044C \u0432\u0435\u0442\u043A\u0443: \`git push -u origin ${branch}\` \u2014 \u043D\u0435\u0437\u0430\u043F\u0443\u0448\u0435\u043D\u043D\u043E\u0435 \u0443\u043C\u0440\u0451\u0442 \u0432\u043C\u0435\u0441\u0442\u0435 \u0441 \u043F\u0440\u043E\u0446\u0435\u0441\u0441\u043E\u043C.`,
18484
+ "3. \u0417\u0430\u0432\u0435\u0440\u0448\u0438 \u0440\u0430\u0431\u043E\u0442\u0443 \u2014 \u0431\u043E\u043B\u044C\u0448\u0435 \u0438\u043D\u0441\u0442\u0440\u0443\u043C\u0435\u043D\u0442\u043E\u0432 \u041D\u0415 \u0437\u043E\u0432\u0438 (\u043D\u0438 report_step, \u043D\u0438 ask, \u043D\u0438 done). \u041F\u0440\u043E\u0441\u0442\u043E \u043E\u0441\u0442\u0430\u043D\u043E\u0432\u0438 \u0441\u0435\u0441\u0441\u0438\u044E.",
18485
+ "\u041F\u0440\u043E\u0433\u043E\u043D \u043F\u043E\u043C\u0435\u0447\u0435\u043D \xABpaused\xBB. \u041A\u043E\u0433\u0434\u0430 \u043F\u043E\u0434\u043D\u0438\u043C\u0435\u0442\u0441\u044F \u043D\u043E\u0432\u044B\u0439 overmind, \u043E\u043D \u0440\u0430\u0437\u0431\u0443\u0434\u0438\u0442 \u0442\u0435\u0431\u044F \u0441 \u044D\u0442\u043E\u0433\u043E \u043C\u0435\u0441\u0442\u0430 (--continue) \u2014",
18486
+ "\u043F\u0440\u043E\u0434\u043E\u043B\u0436\u0438\u0448\u044C \u043E\u0442\u0442\u0443\u0434\u0430. \u041D\u0435 \u043F\u0435\u0440\u0435\u0441\u043F\u0440\u0430\u0448\u0438\u0432\u0430\u0439 \u0438 \u043D\u0435 \u043F\u0440\u043E\u0434\u043E\u043B\u0436\u0430\u0439 \u0437\u0430\u0434\u0430\u0447\u0443 \u0441\u0435\u0439\u0447\u0430\u0441."
18487
+ ].join("\n");
18488
+ }
18489
+ function restInstruction() {
18490
+ return [
18491
+ "\u{1F4A4} \u0422\u044B \u0437\u0430\u043C\u0435\u0440 (rest). \u041F\u0440\u043E\u0433\u043E\u043D \u043F\u043E\u043C\u0435\u0447\u0435\u043D \xABpaused\xBB, \u0438 \u0441\u0435\u0439\u0447\u0430\u0441 \u043F\u0440\u043E\u0446\u0435\u0441\u0441 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u0441\u044F \u2014 \u044D\u0442\u043E \u041D\u041E\u0420\u041C\u0410 \u0434\u043B\u044F \u0413\u0435\u0440\u043E\u044F:",
18492
+ "headless-\u0441\u0435\u0441\u0441\u0438\u044F \u0436\u0438\u0432\u0430, \u0442\u043E\u043B\u044C\u043A\u043E \u043F\u043E\u043A\u0430 \u0442\u044B \u0437\u043E\u0432\u0451\u0448\u044C \u0438\u043D\u0441\u0442\u0440\u0443\u043C\u0435\u043D\u0442\u044B, \u043F\u043E\u044D\u0442\u043E\u043C\u0443 \u0442\u044B \u0440\u0430\u0431\u043E\u0442\u0430\u0435\u0448\u044C \u0440\u044B\u0432\u043A\u0430\u043C\u0438.",
18493
+ "\u0422\u0435\u0431\u044F \u0440\u0430\u0437\u0431\u0443\u0434\u0438\u0442 \u043E\u0432\u0435\u0440\u043C\u0430\u0439\u043D\u0434, \u043A\u043E\u0433\u0434\u0430 \u0432 \u043E\u0442\u0440\u044F\u0434\u0435 \u0447\u0442\u043E-\u0442\u043E \u043F\u0440\u043E\u0438\u0437\u043E\u0439\u0434\u0451\u0442 (\u0434\u0440\u043E\u043D \u0437\u0430\u0434\u0430\u043B \u0432\u043E\u043F\u0440\u043E\u0441, \u0441\u0434\u0430\u043B PR, \u0443\u043C\u0435\u0440),",
18494
+ "\u0438\u043B\u0438 \u043E\u043F\u0435\u0440\u0430\u0442\u043E\u0440 \u0432\u0440\u0443\u0447\u043D\u0443\u044E (`swarm wake <runId>`). \u0422\u043E\u0433\u0434\u0430 \u043F\u0440\u043E\u0434\u043E\u043B\u0436\u0438\u0448\u044C \u0441 \u044D\u0442\u043E\u0433\u043E \u043C\u0435\u0441\u0442\u0430 (--continue).",
18495
+ "\u0421\u0435\u0439\u0447\u0430\u0441 \u043F\u0440\u043E\u0441\u0442\u043E \u0437\u0430\u0432\u0435\u0440\u0448\u0438 \u0441\u0435\u0441\u0441\u0438\u044E: \u0431\u043E\u043B\u044C\u0448\u0435 \u0438\u043D\u0441\u0442\u0440\u0443\u043C\u0435\u043D\u0442\u043E\u0432 \u041D\u0415 \u0437\u043E\u0432\u0438. \u041D\u0438\u0447\u0435\u0433\u043E \u043D\u0435 \u043F\u0435\u0440\u0435\u0441\u043F\u0440\u0430\u0448\u0438\u0432\u0430\u0439."
18496
+ ].join("\n");
18497
+ }
18498
+ function channelDownInstruction(slug, detail) {
18499
+ return [
18500
+ `\u26D4 \u0421\u0412\u042F\u0417\u042C \u0421 \u0414\u0415\u041C\u041E\u041D\u041E\u041C \u041F\u041E\u0422\u0415\u0420\u042F\u041D\u0410 \u2014 ${detail}.`,
18501
+ "\u041E\u0442\u0447\u0438\u0442\u0430\u0442\u044C\u0441\u044F, \u0437\u0430\u0434\u0430\u0442\u044C \u0432\u043E\u043F\u0440\u043E\u0441 \u0438\u043B\u0438 \u0441\u0434\u0430\u0442\u044C \u0440\u0430\u0431\u043E\u0442\u0443 \u0441\u0435\u0439\u0447\u0430\u0441 \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043A\u0438 \u043D\u0435\u0447\u0435\u043C: \u0435\u0434\u0438\u043D\u0441\u0442\u0432\u0435\u043D\u043D\u044B\u0439 \u043A\u0430\u043D\u0430\u043B \u043D\u0430\u0440\u0443\u0436\u0443 \u2014 \u0434\u0435\u043C\u043E\u043D.",
18502
+ "\u0417\u0410\u041C\u0420\u0418 \u0438 \u0441\u043E\u0445\u0440\u0430\u043D\u0438\u0441\u044C, \u0447\u0442\u043E\u0431\u044B \u0440\u0430\u0431\u043E\u0442\u0430 \u043D\u0435 \u043F\u0440\u043E\u043F\u0430\u043B\u0430:",
18503
+ "1. \u0417\u0430\u043A\u043E\u043C\u043C\u0438\u0442\u044C \u0412\u0421\u042E \u0442\u0435\u043A\u0443\u0449\u0443\u044E \u0440\u0430\u0431\u043E\u0442\u0443 \u043A\u0430\u043A \u0435\u0441\u0442\u044C: `git add -A && git commit` (\u0442\u0440\u0435\u0439\u043B\u0435\u0440 \u043F\u0440\u043E \u0434\u0440\u043E\u043D\u0430 \u2014 \u043A\u0430\u043A \u043E\u0431\u044B\u0447\u043D\u043E).",
18504
+ `2. \u0417\u0430\u043F\u0443\u0448\u044C \u0432\u0435\u0442\u043A\u0443: \`git push -u origin ${slug}\` \u2014 \u043D\u0435\u0437\u0430\u043F\u0443\u0448\u0435\u043D\u043D\u043E\u0435 \u0443\u043C\u0440\u0451\u0442 \u0432\u043C\u0435\u0441\u0442\u0435 \u0441 \u043F\u0440\u043E\u0446\u0435\u0441\u0441\u043E\u043C.`,
18505
+ "3. \u0417\u0430\u0432\u0435\u0440\u0448\u0438 \u0440\u0430\u0431\u043E\u0442\u0443 \u2014 \u0438\u043D\u0441\u0442\u0440\u0443\u043C\u0435\u043D\u0442\u044B \u0431\u043E\u043B\u044C\u0448\u0435 \u041D\u0415 \u0437\u043E\u0432\u0438, \u043E\u043D\u0438 \u0432\u0441\u0451 \u0440\u0430\u0432\u043D\u043E \u043D\u0435 \u0434\u043E\u0435\u0434\u0443\u0442.",
18506
+ "\u041A\u043E\u0433\u0434\u0430 \u0434\u0435\u043C\u043E\u043D \u043F\u043E\u0434\u043D\u0438\u043C\u0435\u0442\u0441\u044F, \u043E\u043D \u0443\u0432\u0438\u0434\u0438\u0442 \u0442\u0432\u043E\u044E \u0432\u0435\u0442\u043A\u0443 \u0438 \u0440\u0430\u0437\u0431\u0443\u0434\u0438\u0442 \u0442\u0435\u0431\u044F \u0441 \u044D\u0442\u043E\u0433\u043E \u043C\u0435\u0441\u0442\u0430 (--continue)."
18507
+ ].join("\n");
18508
+ }
18509
+ async function buildDroneServer(store, opts = {}) {
18510
+ const askPollMs = opts.askPollMs ?? 2e3;
18511
+ const server = new McpServer({ name: "overmind-drone", version: "0.1.0" });
18512
+ const overmindDead = async () => !await store.alive();
18513
+ const slugForInstruction = (fallback) => opts.expectedTaskSlug ?? fallback ?? "<slug>";
18514
+ const iAmReviewer = (run2) => run2?.reviews_run_id != null || run2?.kind === "reviewer" || opts.reviewsRunId != null || opts.runKind === "reviewer";
18515
+ const iAmVerifier = (run2) => run2?.verifies_run_id != null || run2?.kind === "verifier" || opts.verifiesRunId != null || opts.runKind === "verifier";
18516
+ let pendingQuestion = null;
18517
+ const freeze = async (withdraw = false) => {
18518
+ let slug;
18519
+ let branch;
18520
+ try {
18521
+ 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");
18522
+ const run2 = await store.myRun();
18523
+ slug = run2?.task_slug;
18524
+ branch = !opts.expectedTaskSlug || opts.expectedTaskSlug === run2?.task_slug ? run2?.branch : null;
18525
+ if (run2 && run2.status !== "paused") {
18526
+ await store.updateRun(null, { status: "paused" });
18527
+ await store.addEvent(null, "paused", "overmind \u043D\u0435\u0434\u043E\u0441\u0442\u0443\u043F\u0435\u043D \u2014 \u0434\u0440\u043E\u043D \u0437\u0430\u043C\u0435\u0440, \u0440\u0430\u0431\u043E\u0442\u0430 \u0432 origin, \u0436\u0434\u0451\u0442 \u043F\u0435\u0440\u0435\u043F\u043E\u0434\u044A\u0451\u043C\u0430");
18528
+ }
18529
+ } catch (e) {
18530
+ console.error("[overmind-drone] \u043F\u043E\u043C\u0435\u0442\u0438\u0442\u044C \u043F\u0440\u043E\u0433\u043E\u043D paused \u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C (\u043D\u0430\u0434\u0437\u043E\u0440 \u043D\u0435\u0434\u043E\u0441\u0442\u0443\u043F\u0435\u043D):", e);
18531
+ }
18532
+ return { content: [{ type: "text", text: freezeInstruction(branch || slugForInstruction(slug), opts.deadReason) }] };
18533
+ };
18534
+ const guard = (fn) => async (a, extra) => {
18535
+ try {
18536
+ const result = await fn(a, extra);
18537
+ const question = pendingQuestion;
18538
+ if (question === null || extra.signal.aborted) return result;
18539
+ try {
18540
+ const cur = await store.myLastQuestion();
18541
+ if (cur && cur.status === "answered" && cur.answer != null && cur.answer.trim() !== "" && sameQuestion(cur.text, question) && pendingQuestion === question && !extra.signal.aborted) {
18542
+ pendingQuestion = null;
18543
+ return { ...result, content: [{ type: "text", text: lateAnswerText(question, cur.answer) }, ...result.content] };
18544
+ }
18545
+ } catch {
18546
+ }
18547
+ return result;
18548
+ } catch (e) {
18549
+ if (!(e instanceof ChannelUnavailableError)) throw e;
18550
+ const text = channelDownInstruction(slugForInstruction(null), e.message);
18551
+ console.error(`[overmind-drone] ${e.message} \u2014 \u0434\u0440\u043E\u043D \u0437\u0430\u043C\u0438\u0440\u0430\u0435\u0442`);
18552
+ return { content: [{ type: "text", text }], isError: true };
18553
+ }
18554
+ };
18555
+ server.tool(
18556
+ "report_step",
18557
+ "\u0417\u0430\u043F\u0438\u0441\u0430\u0442\u044C \u0442\u0435\u043A\u0443\u0449\u0438\u0439 \u0448\u0430\u0433 \u0440\u0430\u0431\u043E\u0442\u044B (\u0432\u0438\u0434\u0435\u043D \u043E\u043F\u0435\u0440\u0430\u0442\u043E\u0440\u0443 \u0432 \u043B\u043E\u0433\u0435 \u043F\u0440\u043E\u0433\u043E\u043D\u0430).",
18558
+ { text: z.string().describe("\u0447\u0442\u043E \u0434\u0435\u043B\u0430\u0435\u0448\u044C \u043F\u0440\u044F\u043C\u043E \u0441\u0435\u0439\u0447\u0430\u0441") },
18559
+ guard(async ({ text }) => {
18560
+ if (await overmindDead()) return freeze();
18561
+ await store.addEvent(null, "step", text);
18562
+ return { content: [{ type: "text", text: "ok" }] };
18563
+ })
18564
+ );
18565
+ server.tool(
18566
+ "read_task",
18567
+ "\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).",
18568
+ {},
18569
+ guard(async () => {
18570
+ if (!opts.taskless) {
18571
+ return {
18572
+ 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." }],
18573
+ isError: true
18574
+ };
18575
+ }
18576
+ const run2 = await store.myRun().catch(() => null);
18577
+ const slug = opts.expectedTaskSlug ?? run2?.task_slug;
18578
+ let mismatchNote;
18579
+ if (opts.expectedTaskSlug && !run2) {
18580
+ mismatchNote = `\u26A0\uFE0F \u0434\u0435\u043C\u043E\u043D \u043D\u0435 \u043E\u0442\u0434\u0430\u043B \u0442\u0432\u043E\u0439 \u043F\u0440\u043E\u0433\u043E\u043D \u2014 \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u043D slug \u0438\u0437 \u0441\u043F\u0430\u0432\u043D\u0430.`;
18581
+ } else if (opts.expectedTaskSlug && run2 && run2.task_slug !== opts.expectedTaskSlug) {
18582
+ mismatchNote = `\u26A0\uFE0F \u0434\u0435\u043C\u043E\u043D \u0447\u0438\u0441\u043B\u0438\u0442 \u0442\u0432\u043E\u0439 \u043F\u0440\u043E\u0433\u043E\u043D \u043A\u0430\u043A \xAB${run2.task_slug}\xBB \u2014 \u044D\u0442\u043E \u041D\u0415 \u0442\u0432\u043E\u044F \u0437\u0430\u0434\u0430\u0447\u0430 (TASWM-211). \u0418\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u043D \u0434\u043E\u0432\u0435\u0440\u0435\u043D\u043D\u044B\u0439 slug \u0438\u0437 \u0441\u043F\u0430\u0432\u043D\u0430.`;
18583
+ }
18584
+ if (!slug) return { content: [{ type: "text", text: "\u043F\u0440\u043E\u0433\u043E\u043D \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D" }], isError: true };
18585
+ const read = await opts.taskless.getTaskDetailed(slug);
18586
+ if (!read.ok) {
18587
+ const failText = readTaskFailureInstruction(slug, read.failure);
18588
+ return {
18589
+ content: [{ type: "text", text: mismatchNote ? `${mismatchNote}
18590
+
18591
+ ${failText}` : failText }],
18592
+ isError: true
18593
+ };
18594
+ }
18595
+ const task = read.task;
18596
+ const context = await fetchTaskContext(opts.taskless, task, { full: true });
18597
+ const attachments = await prepareTaskAttachments({
18598
+ worktree: opts.worktree ?? process.cwd(),
18599
+ refs: task.attachments,
18600
+ fetchFile: opts.taskless.fetchFile?.bind(opts.taskless),
18601
+ onEvent: (text) => text.includes("\u043D\u0435 \u0441\u043A\u0430\u0447\u0430\u043B\u043E\u0441\u044C") ? store.addEvent(null, "step", text) : void 0
18602
+ });
18603
+ const lines = [
18604
+ `**${task.title}** \xB7 ${task.slug}${task.url ? ` (${task.url})` : ""}`,
18605
+ "",
18606
+ task.description || "(\u043F\u0443\u0441\u0442\u043E)"
18607
+ ];
18608
+ if (context) lines.push("", context);
18609
+ if (attachments) lines.push("", attachments);
18610
+ if (mismatchNote) lines.unshift(mismatchNote, "");
18611
+ return { content: [{ type: "text", text: lines.join("\n") }] };
18612
+ })
16699
18613
  );
16700
18614
  server.tool(
16701
18615
  "report_acceptance_check",
@@ -17039,7 +18953,7 @@ ${failText}` : failText }],
17039
18953
  "\u0422\u041E\u041B\u042C\u041A\u041E \u0414\u041B\u042F \u0420\u0415\u0412\u042C\u042E\u0415\u0420\u0410 (TASWM-431): \u0440\u0435\u0448\u0435\u043D\u0438\u0435 \u043F\u043E \u043F\u0440\u0430\u0432\u0438\u043B\u0430\u043C, \u043A\u043E\u0442\u043E\u0440\u044B\u0435 \u043F\u0440\u0438\u043D\u0451\u0441 \u0434\u0440\u043E\u043D (\u043E\u043D\u0438 \u043F\u0435\u0440\u0435\u0447\u0438\u0441\u043B\u0435\u043D\u044B \u0432 \u0442\u0432\u043E\u0451\u043C \u043F\u0440\u043E\u043C\u043F\u0442\u0435). apply=true \u2014 \u043F\u0440\u0430\u0432\u0438\u043B\u043E \u043D\u0430\u0441\u0442\u043E\u044F\u0449\u0435\u0435, apply=false \u2014 \u043E\u0442\u043F\u0438\u0441\u043A\u0430, \u0441\u043D\u044F\u0442\u044C. verify/conventions/brief \u043F\u0440\u0438\u043C\u0435\u043D\u044F\u0442\u0441\u044F \u0432 \u043A\u0430\u0440\u0442\u043E\u0447\u043A\u0443 \u0441\u0440\u0430\u0437\u0443, env/zones/spine \u0443\u0439\u0434\u0443\u0442 \u0447\u0435\u043B\u043E\u0432\u0435\u043A\u0443 \u0432 \u043B\u044E\u0431\u043E\u043C \u0441\u043B\u0443\u0447\u0430\u0435."
17040
18954
  )
17041
18955
  },
17042
- guard(async ({ pr_url, verdict, summary, screenshots, rules, rule_verdicts, zone_notes, zone_notes_used }) => {
18956
+ guard(async ({ pr_url, verdict, summary, screenshots, rules, rule_verdicts, zone_notes, zone_notes_used }, extra) => {
17043
18957
  const run2 = await store.myRun();
17044
18958
  let repoFullNameCache = null;
17045
18959
  const repoFullNameOnce = () => repoFullNameCache ??= remoteRepoFullName(opts.worktree ?? process.cwd()).catch(() => null);
@@ -17356,6 +19270,123 @@ ${report}${shots.warning}`,
17356
19270
  isError: true
17357
19271
  };
17358
19272
  }
19273
+ let reportBody = report;
19274
+ let mutationNote = "";
19275
+ let freshNote = "";
19276
+ if (mutationGateApplies(run2)) {
19277
+ const flightKey = mutationFlightKey(run2?.id);
19278
+ if (extra.signal.aborted) {
19279
+ return { content: [{ type: "text", text: "\u043E\u0442\u043C\u0435\u043D\u0435\u043D\u043E" }], isError: true };
19280
+ }
19281
+ if (mutationGateInFlight.has(flightKey)) {
19282
+ return { content: [{ type: "text", text: "\u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0430 \u0443\u0436\u0435 \u0438\u0434\u0451\u0442" }], isError: true };
19283
+ }
19284
+ mutationGateInFlight.add(flightKey);
19285
+ try {
19286
+ const priorEvents = await store.events(null).catch(() => []);
19287
+ const worktree = opts.worktree ?? process.cwd();
19288
+ const loadPrepare = async () => {
19289
+ try {
19290
+ if (opts.repoPrepare) return await opts.repoPrepare();
19291
+ const read = opts.taskless?.repoPrepare;
19292
+ if (!read) return null;
19293
+ const repo = await remoteRepoFullName(worktree).catch(() => null);
19294
+ if (!repo) return null;
19295
+ const slug = opts.expectedTaskSlug ?? run2?.task_slug;
19296
+ return await read(repo, slug || void 0);
19297
+ } catch {
19298
+ return null;
19299
+ }
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
+ }
19343
+ const outcome = await gateDoneMutation({
19344
+ run: run2,
19345
+ worktree,
19346
+ events: priorEvents,
19347
+ signal: extra.signal,
19348
+ emit: (event) => store.addEvent(null, "step", event),
19349
+ loadCommand: async () => {
19350
+ if (opts.repoVerify) return opts.repoVerify();
19351
+ const read = opts.taskless?.repoVerifyCommands;
19352
+ if (!read) return null;
19353
+ const repo = await remoteRepoFullName(worktree).catch(() => null);
19354
+ if (!repo) return null;
19355
+ const slug = opts.expectedTaskSlug ?? run2?.task_slug;
19356
+ const commands = await read(repo, slug || void 0).catch(() => null);
19357
+ return selectVerifyCommand(commands);
19358
+ },
19359
+ runGate: async (input) => {
19360
+ if (opts.mutationGate) return opts.mutationGate(input);
19361
+ const prepare = await loadPrepare();
19362
+ return runMutationGate({
19363
+ worktree: input.worktree,
19364
+ base: input.base,
19365
+ timeoutMs: MUTATION_GATE_TIMEOUT_MS,
19366
+ // exactOptionalPropertyTypes: signal есть только когда вызывающий его передал.
19367
+ ...input.signal ? { signal: input.signal } : {},
19368
+ runTests: (ctx) => runVerifyCommand(input.command, ctx, { sourceWorktree: input.worktree, prepare })
19369
+ });
19370
+ }
19371
+ });
19372
+ if (outcome.kind === "cancelled" || extra.signal.aborted) {
19373
+ return { content: [{ type: "text", text: "\u043E\u0442\u043C\u0435\u043D\u0435\u043D\u043E" }], isError: true };
19374
+ }
19375
+ if (outcome.kind === "refuse") {
19376
+ await store.addEvent(null, "step", outcome.event);
19377
+ return { content: [{ type: "text", text: outcome.text }], isError: true };
19378
+ }
19379
+ if (outcome.kind === "accept") {
19380
+ for (const ev of outcome.events) await store.addEvent(null, "step", ev);
19381
+ if (outcome.summaryLine) reportBody = `${report}
19382
+
19383
+ ${outcome.summaryLine}`;
19384
+ mutationNote = outcome.note;
19385
+ }
19386
+ } finally {
19387
+ mutationGateInFlight.delete(flightKey);
19388
+ }
19389
+ }
17359
19390
  const shots = await uploadShots();
17360
19391
  const postReport = async (taskSlug, cycle) => {
17361
19392
  if (!opts.taskless) {
@@ -17367,7 +19398,7 @@ ${report}${shots.warning}`,
17367
19398
  taskSlug,
17368
19399
  `PR: ${pr_url}
17369
19400
 
17370
- ${report}${shots.warning}`,
19401
+ ${reportBody}${shots.warning}`,
17371
19402
  {
17372
19403
  swarmKind: "report",
17373
19404
  // TASWM-265: имени взять неоткуда — честная заглушка, а НЕ "?" и не номер прогона.
@@ -17405,7 +19436,7 @@ ${report}${shots.warning}`,
17405
19436
  await postReport(reportSlug(run2.task_slug), t.cycle ?? run2.review_cycle ?? 0);
17406
19437
  const rulesNote = await offerRules(reportSlug(run2.task_slug));
17407
19438
  const zoneNote = await zoneMemoryNote(reportSlug(run2.task_slug));
17408
- const tail2 = `${shotsNote(shots)}${rulesNote}${zoneNote}`;
19439
+ const tail2 = `${shotsNote(shots)}${rulesNote}${zoneNote}${freshNote}${mutationNote}`;
17409
19440
  if (t.isFixIteration) {
17410
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}` }] };
17411
19442
  }
@@ -17415,10 +19446,10 @@ ${report}${shots.warning}`,
17415
19446
  await store.addEvent(null, "pr_opened", pr_url);
17416
19447
  const fallbackSlug = reportSlug(void 0);
17417
19448
  if (fallbackSlug) await postReport(fallbackSlug, void 0);
17418
- 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): ${report}`);
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}`);
17419
19450
  const fallbackRulesNote = await offerRules(fallbackSlug);
17420
19451
  const fallbackZoneNote = await zoneMemoryNote(fallbackSlug);
17421
- 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}` }] };
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}` }] };
17422
19453
  }
17423
19454
  await store.updateRun(null, { status: "done" });
17424
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");
@@ -18992,23 +21023,23 @@ async function prodClearMergeIntent(runId, deps = {}) {
18992
21023
  }
18993
21024
 
18994
21025
  // src/envGate.ts
18995
- import { existsSync as existsSync20 } from "fs";
18996
- import { join as join37 } from "path";
21026
+ import { existsSync as existsSync23 } from "fs";
21027
+ import { join as join40 } from "path";
18997
21028
  import { createConnection } from "net";
18998
- import { execa as execa2 } from "execa";
21029
+ import { execa as execa5 } from "execa";
18999
21030
 
19000
21031
  // src/platform.ts
19001
21032
  init_src();
19002
- import { accessSync as accessSync2, constants as constants2, existsSync as existsSync19, readFileSync as readFileSync26, realpathSync as realpathSync3 } from "fs";
19003
- import { delimiter as delimiter2, join as join36, 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";
19004
21035
  function resolveCommandPath(name, env = process.env, platform = process.platform) {
19005
- if (name.includes("/") || name.includes("\\")) return existsSync19(name) ? name : null;
21036
+ if (name.includes("/") || name.includes("\\")) return existsSync22(name) ? name : null;
19006
21037
  const dirs = (env.PATH ?? env.Path ?? "").split(delimiter2).filter(Boolean);
19007
21038
  const exts = platform === "win32" ? (env.PATHEXT ?? ".EXE;.CMD;.BAT").split(";").filter(Boolean) : [""];
19008
21039
  for (const dir of dirs) {
19009
21040
  for (const ext of exts) {
19010
- const candidate = join36(dir, name + ext);
19011
- if (existsSync19(candidate)) return candidate;
21041
+ const candidate = join39(dir, name + ext);
21042
+ if (existsSync22(candidate)) return candidate;
19012
21043
  }
19013
21044
  }
19014
21045
  return null;
@@ -19048,7 +21079,7 @@ function globalInstallCommand(pm, spec, prefix, platform = process.platform) {
19048
21079
  var UNIX_MARKER = "/lib/node_modules/@taskless-app/swarm";
19049
21080
  var WIN_MARKER = "/node_modules/@taskless-app/swarm";
19050
21081
  function resolveReal(entry, io) {
19051
- const realpath = io.realpath ?? realpathSync3;
21082
+ const realpath = io.realpath ?? realpathSync4;
19052
21083
  try {
19053
21084
  return realpath(entry);
19054
21085
  } catch {
@@ -19141,9 +21172,9 @@ function parseRequirements(lines) {
19141
21172
  out.push({ kind: "docker", raw });
19142
21173
  continue;
19143
21174
  }
19144
- const sep4 = raw.indexOf(":");
19145
- const prefix = sep4 === -1 ? "" : lower.slice(0, sep4);
19146
- const rest = sep4 === -1 ? "" : raw.slice(sep4 + 1).trim();
21175
+ const sep5 = raw.indexOf(":");
21176
+ const prefix = sep5 === -1 ? "" : lower.slice(0, sep5);
21177
+ const rest = sep5 === -1 ? "" : raw.slice(sep5 + 1).trim();
19147
21178
  if (!rest) {
19148
21179
  out.push({ kind: "unknown", raw });
19149
21180
  continue;
@@ -19177,8 +21208,8 @@ var COMPOSE_MARKERS = [
19177
21208
  "compose.yaml"
19178
21209
  ];
19179
21210
  function detectRequirements(repo, io = {}) {
19180
- const exists = io.exists ?? existsSync20;
19181
- const marker = COMPOSE_MARKERS.find((f) => exists(join37(repo, f)));
21211
+ const exists = io.exists ?? existsSync23;
21212
+ const marker = COMPOSE_MARKERS.find((f) => exists(join40(repo, f)));
19182
21213
  return marker ? [{ kind: "docker", raw: `docker (\u0434\u0435\u0442\u0435\u043A\u0442: ${marker})` }] : [];
19183
21214
  }
19184
21215
  function resolveRequirements(repo, declared, io = {}) {
@@ -19187,7 +21218,7 @@ function resolveRequirements(repo, declared, io = {}) {
19187
21218
  }
19188
21219
  async function probeDockerDaemon() {
19189
21220
  try {
19190
- const res = await execa2("docker", ["version", "--format", "{{.Server.Version}}"], {
21221
+ const res = await execa5("docker", ["version", "--format", "{{.Server.Version}}"], {
19191
21222
  timeout: PROBE_TIMEOUT_MS,
19192
21223
  reject: false
19193
21224
  });
@@ -19315,7 +21346,7 @@ function makeEnvGate(opts) {
19315
21346
  // src/web.ts
19316
21347
  init_src();
19317
21348
  import { randomBytes as randomBytes3 } from "crypto";
19318
- import { basename as basename6 } from "path";
21349
+ import { basename as basename7 } from "path";
19319
21350
  import { serve as serve2 } from "@hono/node-server";
19320
21351
  init_storm();
19321
21352
  init_swarmModels();
@@ -19559,7 +21590,7 @@ function timelineState(db, now = Date.now(), overmindLog = []) {
19559
21590
  id: r.id,
19560
21591
  name: r.name,
19561
21592
  slug: r.task_slug,
19562
- repo: basename6(r.repo || "") || "?",
21593
+ repo: basename7(r.repo || "") || "?",
19563
21594
  status: r.status,
19564
21595
  area: r.area,
19565
21596
  start: sqliteIso(r.created_at),
@@ -21005,21 +23036,21 @@ function closeWebServer(server) {
21005
23036
 
21006
23037
  // src/hostCommands.ts
21007
23038
  init_src();
21008
- import { readFileSync as readFileSync27, renameSync as renameSync10, writeFileSync as writeFileSync17 } from "fs";
21009
- import { join as join38 } from "path";
23039
+ import { readFileSync as readFileSync28, renameSync as renameSync10, writeFileSync as writeFileSync18 } from "fs";
23040
+ import { join as join41 } from "path";
21010
23041
  function hostCommandStatePath(home) {
21011
- return join38(home, "host-command.json");
23042
+ return join41(home, "host-command.json");
21012
23043
  }
21013
23044
  function readState(path) {
21014
23045
  try {
21015
- return JSON.parse(readFileSync27(path, "utf8"));
23046
+ return JSON.parse(readFileSync28(path, "utf8"));
21016
23047
  } catch {
21017
23048
  return {};
21018
23049
  }
21019
23050
  }
21020
23051
  function writeState(path, state) {
21021
23052
  try {
21022
- writeFileSync17(`${path}.tmp`, JSON.stringify(state));
23053
+ writeFileSync18(`${path}.tmp`, JSON.stringify(state));
21023
23054
  renameSync10(`${path}.tmp`, path);
21024
23055
  } catch {
21025
23056
  }
@@ -21182,20 +23213,20 @@ async function doRestart(cmd, opts, note) {
21182
23213
 
21183
23214
  // src/selfUpdate.ts
21184
23215
  init_git();
21185
- import { existsSync as existsSync21 } from "fs";
21186
- import { join as join39 } from "path";
23216
+ import { existsSync as existsSync24 } from "fs";
23217
+ import { join as join42 } from "path";
21187
23218
  import { $ as $6 } from "execa";
21188
23219
 
21189
23220
  // src/cliIo.ts
21190
23221
  import { createInterface } from "readline/promises";
21191
- import { execa as execa3 } from "execa";
23222
+ import { execa as execa6 } from "execa";
21192
23223
  function readCommandOutcome(result) {
21193
23224
  if (typeof result === "number") return { exitCode: result, output: "" };
21194
23225
  return { exitCode: result.exitCode, output: `${result.stdout ?? ""}
21195
23226
  ${result.stderr ?? ""}` };
21196
23227
  }
21197
23228
  async function execCaptured(command) {
21198
- const res = await execa3(command, {
23229
+ const res = await execa6(command, {
21199
23230
  shell: true,
21200
23231
  reject: false,
21201
23232
  stdout: ["pipe", "inherit"],
@@ -21216,7 +23247,7 @@ function tail(text, max = 400) {
21216
23247
  }
21217
23248
  async function runSelfUpdate(io) {
21218
23249
  const run2 = io.run ?? defaultRun;
21219
- const exists = io.exists ?? existsSync21;
23250
+ const exists = io.exists ?? existsSync24;
21220
23251
  const repo = io.repo;
21221
23252
  await io.onStep("fetch", "\u0442\u044F\u043D\u0443 \u0441\u0432\u0435\u0436\u0438\u0439 \u043A\u043E\u0434");
21222
23253
  const fetched = await run2("git", ["-C", repo, "fetch", "--quiet", "origin"], repo);
@@ -21245,7 +23276,7 @@ async function runSelfUpdate(io) {
21245
23276
  };
21246
23277
  }
21247
23278
  await io.onStep("install", "\u0441\u0442\u0430\u0432\u043B\u044E \u0437\u0430\u0432\u0438\u0441\u0438\u043C\u043E\u0441\u0442\u0438");
21248
- if (!exists(join39(repo, "pnpm-lock.yaml"))) {
23279
+ if (!exists(join42(repo, "pnpm-lock.yaml"))) {
21249
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" };
21250
23281
  }
21251
23282
  const installed2 = await run2("pnpm", ["install", "--frozen-lockfile"], repo);
@@ -21352,7 +23383,7 @@ function orphanNoteText(run2, q) {
21352
23383
 
21353
23384
  // src/probe.ts
21354
23385
  init_executors();
21355
- import { spawn as spawn3 } from "child_process";
23386
+ import { spawn as spawn4 } from "child_process";
21356
23387
  var RESET_RE2 = /resets[^\n]*/i;
21357
23388
  function executorHealthy(opts = {}) {
21358
23389
  const executor = opts.executor ?? resolveExecutor();
@@ -21371,7 +23402,7 @@ function executorHealthy(opts = {}) {
21371
23402
  }
21372
23403
  resolve6(r);
21373
23404
  };
21374
- const child = spawn3(bin, [...executor.probe.args], {
23405
+ const child = spawn4(bin, [...executor.probe.args], {
21375
23406
  stdio: ["ignore", "pipe", "pipe"],
21376
23407
  ...opts.env ? { env: { ...process.env, ...opts.env } } : {}
21377
23408
  });
@@ -21420,19 +23451,19 @@ async function fetchExternalStorm(url, opts = {}) {
21420
23451
  }
21421
23452
 
21422
23453
  // src/anomalyState.ts
21423
- import { existsSync as existsSync22, readFileSync as readFileSync28, renameSync as renameSync11, writeFileSync as writeFileSync18 } from "fs";
21424
- import { join as join40 } 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";
21425
23456
  var KEY_TTL_MS = 7 * 24 * 60 * 6e4;
21426
23457
  var MAX_RESOLVED = 200;
21427
23458
  function emptyState() {
21428
23459
  return { since: {}, lastFiredAt: {}, fires: {}, resolved: [], stopQuiet: null };
21429
23460
  }
21430
23461
  function anomalyStatePath(home) {
21431
- return join40(home, "anomaly-state.json");
23462
+ return join43(home, "anomaly-state.json");
21432
23463
  }
21433
23464
  function loadAnomalyState(home, now = Date.now(), io = {}) {
21434
- const exists = io.exists ?? existsSync22;
21435
- const readFile3 = io.readFile ?? ((p) => readFileSync28(p, "utf8"));
23465
+ const exists = io.exists ?? existsSync25;
23466
+ const readFile3 = io.readFile ?? ((p) => readFileSync29(p, "utf8"));
21436
23467
  const path = anomalyStatePath(home);
21437
23468
  if (!exists(path)) return emptyState();
21438
23469
  try {
@@ -21462,7 +23493,7 @@ function loadAnomalyState(home, now = Date.now(), io = {}) {
21462
23493
  function saveAnomalyState(home, state, io = {}) {
21463
23494
  const path = anomalyStatePath(home);
21464
23495
  const writeFile4 = io.writeFile ?? ((p, data) => {
21465
- writeFileSync18(`${p}.tmp`, data);
23496
+ writeFileSync19(`${p}.tmp`, data);
21466
23497
  renameSync11(`${p}.tmp`, p);
21467
23498
  });
21468
23499
  writeFile4(path, JSON.stringify(state, null, 2));
@@ -22647,7 +24678,7 @@ function dockerStandRules(prefix, homeDir = homedir10()) {
22647
24678
  }
22648
24679
  function promptStandRule(worktree, slug) {
22649
24680
  const raw = worktree && worktree.length > 0 ? worktree : slug;
22650
- const prefix = composeProjectPrefix(basename7(raw));
24681
+ const prefix = composeProjectPrefix(basename8(raw));
22651
24682
  return prefix ? dockerStandRules(prefix, homedir10()) : "";
22652
24683
  }
22653
24684
  var FIX_NO_REVIEW_ITEMS = "\u0420\u0435\u0432\u044C\u044E\u0435\u0440 \u043F\u0440\u0430\u0432\u043E\u043A \u043D\u0435 \u043F\u0440\u043E\u0441\u0438\u043B.";
@@ -22864,10 +24895,10 @@ ${task.description}` : `\u0417\u0430\u0434\u0430\u0447\u0430 ${run2.task_slug} (
22864
24895
  }
22865
24896
  return parts.join("\n");
22866
24897
  }
22867
- var HERO_CHARTER_PATH = join41(dirname6(THIS_FILE), "..", "docs", "HERO.md");
24898
+ var HERO_CHARTER_PATH = join44(dirname7(THIS_FILE), "..", "docs", "HERO.md");
22868
24899
  function buildHeroPrompt(task, run2, taskContext, attachmentsBlock) {
22869
24900
  const name = run2.name || `#${run2.id}`;
22870
- const charter = readFileSync29(HERO_CHARTER_PATH, "utf8");
24901
+ const charter = readFileSync30(HERO_CHARTER_PATH, "utf8");
22871
24902
  const head = task ? `\u042D\u041F\u0418\u041A ${run2.task_slug}: ${task.title}
22872
24903
 
22873
24904
  ${task.description}` : `\u042D\u041F\u0418\u041A ${run2.task_slug} (\u0442\u0435\u043B\u043E \u043D\u0435\u0434\u043E\u0441\u0442\u0443\u043F\u043D\u043E \u2014 \u0440\u0430\u0431\u043E\u0442\u0430\u0439 \u043F\u043E slug \u0438 \u0437\u0434\u0440\u0430\u0432\u043E\u043C\u0443 \u0441\u043C\u044B\u0441\u043B\u0443).`;
@@ -22927,9 +24958,9 @@ function ciTrustLine(prUrl, verifyMode, ciClosed = null) {
22927
24958
  }
22928
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}`;
22929
24960
  }
22930
- var REVIEW_SKILL_PATH = join41(bundledRoleDir("drone"), "skills", "taskless-review", "SKILL.md");
24961
+ var REVIEW_SKILL_PATH = join44(bundledRoleDir("drone"), "skills", "taskless-review", "SKILL.md");
22931
24962
  function reviewDefectClasses(skillPath = REVIEW_SKILL_PATH) {
22932
- const text = readFileSync29(skillPath, "utf8");
24963
+ const text = readFileSync30(skillPath, "utf8");
22933
24964
  const m = /^## Классы дефектов\n([\s\S]*?)(?=^## |(?![\s\S]))/m.exec(text);
22934
24965
  if (!m) throw new Error(`${skillPath}: \u043D\u0435\u0442 \u0440\u0430\u0437\u0434\u0435\u043B\u0430 \xAB## \u041A\u043B\u0430\u0441\u0441\u044B \u0434\u0435\u0444\u0435\u043A\u0442\u043E\u0432\xBB \u2014 \u0444\u043E\u0440\u043C\u0430\u0442 skill taskless-review \u043F\u043E\u043C\u0435\u043D\u044F\u043B\u0441\u044F?`);
22935
24966
  return `\u041A\u043B\u0430\u0441\u0441\u044B \u0434\u0435\u0444\u0435\u043A\u0442\u043E\u0432 (skill taskless-review):
@@ -23564,7 +25595,7 @@ async function wakeRun(deps, runId, opts = {}) {
23564
25595
  if (run2.status === "review" && run2.pr_url && !needsFixIteration(run2) && !stoppedForHuman) {
23565
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` };
23566
25597
  }
23567
- const worktreeExists = deps.worktreeExists ?? existsSync23;
25598
+ const worktreeExists = deps.worktreeExists ?? existsSync26;
23568
25599
  const hasTranscript = deps.hasTranscript ?? executorHasSession;
23569
25600
  const wt = run2.worktree_path;
23570
25601
  const canContinue = !!wt && worktreeExists(wt) && hasTranscript(run2);
@@ -23711,9 +25742,9 @@ function repoHasCi(deps, run2) {
23711
25742
  function repoHasCiWorkflows(worktreePath, repo) {
23712
25743
  for (const base3 of [worktreePath, repo]) {
23713
25744
  if (!base3) continue;
23714
- const dir = join41(base3, ".github", "workflows");
25745
+ const dir = join44(base3, ".github", "workflows");
23715
25746
  try {
23716
- if (readdirSync18(dir).some((f) => f.endsWith(".yml") || f.endsWith(".yaml"))) return true;
25747
+ if (readdirSync19(dir).some((f) => f.endsWith(".yml") || f.endsWith(".yaml"))) return true;
23717
25748
  } catch {
23718
25749
  }
23719
25750
  }
@@ -23935,7 +25966,7 @@ async function wakeReviewerOnCiReady(deps, run2, over) {
23935
25966
  return true;
23936
25967
  }
23937
25968
  function worktreeAndTranscriptAlive(deps, run2) {
23938
- const exists = deps.worktreeExists ?? existsSync23;
25969
+ const exists = deps.worktreeExists ?? existsSync26;
23939
25970
  const transcript = deps.hasTranscript ?? executorHasSession;
23940
25971
  const wt = run2.worktree_path;
23941
25972
  return !!wt && exists(wt) && transcript(run2);
@@ -24366,7 +26397,7 @@ async function wakeAuthorOnChanges(deps, snapshot, now, droneCap) {
24366
26397
  }
24367
26398
  const wt = run2.worktree_path;
24368
26399
  const wtPath = wt || (deps.worktreesDir ? droneWorktreePath(deps.worktreesDir, normalizeRepo(run2.repo || deps.repoFallback || ""), run2.task_slug) : null);
24369
- const worktreeReady = !!wtPath && (deps.worktreeExists ?? existsSync23)(wtPath);
26400
+ const worktreeReady = !!wtPath && (deps.worktreeExists ?? existsSync26)(wtPath);
24370
26401
  if (!worktreeReady) {
24371
26402
  const why = await freshChangesWakeBlock(deps, run2, prUrl, now);
24372
26403
  if (why) return blockFix(run2, why);
@@ -24458,7 +26489,7 @@ async function zoneConflictFor(db, models, activeFiles, run2, repo, repoFallback
24458
26489
  activeFiles.prune(holders.map((r) => r.id));
24459
26490
  const fileExists = (p) => {
24460
26491
  try {
24461
- return statSync16(join41(repo, p), { throwIfNoEntry: false })?.isFile() ?? false;
26492
+ return statSync17(join44(repo, p), { throwIfNoEntry: false })?.isFile() ?? false;
24462
26493
  } catch {
24463
26494
  return false;
24464
26495
  }
@@ -24572,8 +26603,8 @@ async function fillSuggestedArea(deps, run2) {
24572
26603
  `\u0437\u043E\u043D\u0430 \u0437\u0430\u0434\u0430\u0447\u0438 \u0438\u0437 \u0438\u0441\u0442\u043E\u0440\u0438\u0438 \u0440\u0435\u043F\u043E: ${guess.zone} (${Math.round(guess.confidence * 100)}% \u2014 ${guess.why}) \u2014 TASWM-348`
24573
26604
  );
24574
26605
  }
24575
- function noteExhaustedDeps(deps, run2, verdicts) {
24576
- const exhausted = verdicts.filter((d) => d.outcome === "exhausted");
26606
+ function noteExhaustedDeps(deps, run2, verdicts2) {
26607
+ const exhausted = verdicts2.filter((d) => d.outcome === "exhausted");
24577
26608
  if (exhausted.length === 0) return;
24578
26609
  const already = new Set(
24579
26610
  deps.db.events(run2.id).filter((e) => e.kind === "dep_cleared").map((e) => e.text ?? "")
@@ -24909,7 +26940,7 @@ async function liftReturners(deps, returners, now, droneCap) {
24909
26940
  deps.returners?.delete(run2.id);
24910
26941
  continue;
24911
26942
  }
24912
- lifted = await wakeAuthorOnRedCi(deps, run2, now, entry.ci, deps.worktreeExists ?? existsSync23, deps.hasTranscript ?? executorHasSession, droneCap);
26943
+ lifted = await wakeAuthorOnRedCi(deps, run2, now, entry.ci, deps.worktreeExists ?? existsSync26, deps.hasTranscript ?? executorHasSession, droneCap);
24913
26944
  }
24914
26945
  if (lifted) deps.returners?.delete(run2.id);
24915
26946
  }
@@ -24934,7 +26965,7 @@ async function resumeWatchdogParked(deps, droneCap) {
24934
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");
24935
26966
  return;
24936
26967
  }
24937
- const worktreeExists = deps.worktreeExists ?? existsSync23;
26968
+ const worktreeExists = deps.worktreeExists ?? existsSync26;
24938
26969
  const hasTranscript = deps.hasTranscript ?? executorHasSession;
24939
26970
  const wt = candidate.worktree_path;
24940
26971
  const canContinue = !!wt && worktreeExists(wt) && hasTranscript(candidate);
@@ -25407,14 +27438,14 @@ async function buildReliefCostCandidatesFor(deps, now, droneCap) {
25407
27438
  if (deps.exclusiveProject && await deps.exclusiveProject(repo)) continue;
25408
27439
  } catch {
25409
27440
  }
25410
- exclusiveRepos.push(basename7(repo));
27441
+ exclusiveRepos.push(basename8(repo));
25411
27442
  }
25412
27443
  const otherHosts = [
25413
27444
  ...new Set(
25414
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)
25415
27446
  )
25416
27447
  ];
25417
- const advice = reliefAdvice({
27448
+ const advice2 = reliefAdvice({
25418
27449
  maxDrones: droneCap,
25419
27450
  activeDrones: occupying.length,
25420
27451
  exclusiveRepos,
@@ -25422,7 +27453,7 @@ async function buildReliefCostCandidatesFor(deps, now, droneCap) {
25422
27453
  totalGb: pressure.totalGb
25423
27454
  });
25424
27455
  const worstRun = cost.worst ? runById.get(cost.worst.runId) ?? null : null;
25425
- 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);
25426
27457
  const title = reliefAlertTitle(cost, SWARM_RELIEF_COST_WINDOW_MS);
25427
27458
  return buildReliefCostCandidates(cost, thresholds, SWARM_RELIEF_ALERT_SUSTAIN_MS, () => ({
25428
27459
  title,
@@ -25562,10 +27593,10 @@ async function checkerHeadSha(worktree) {
25562
27593
  return headSha(worktree);
25563
27594
  }
25564
27595
  function verdictEventPayload(text) {
25565
- const sep4 = text.startsWith(PICKUP_EVENT_PREFIX) ? "): " : ": ";
25566
- const at = text.indexOf(sep4);
27596
+ const sep5 = text.startsWith(PICKUP_EVENT_PREFIX) ? "): " : ": ";
27597
+ const at = text.indexOf(sep5);
25567
27598
  if (at < 0) return "";
25568
- return stripVerdictHead(text.slice(at + sep4.length).replace(/\s+\[[^\]]*\]\s*$/, "")).trim();
27599
+ return stripVerdictHead(text.slice(at + sep5.length).replace(/\s+\[[^\]]*\]\s*$/, "")).trim();
25569
27600
  }
25570
27601
  function isHeaderOnlyVerdict(text) {
25571
27602
  if (!text.startsWith(PICKUP_EVENT_PREFIX) && !text.startsWith("\u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u0440\u0435\u0432\u044C\u044E \u043E\u0442")) return false;
@@ -25576,10 +27607,10 @@ var VERIFY_HEADER_LABELS = /* @__PURE__ */ new Set(["\u041D\u0410\u0428\u0401\u0
25576
27607
  function isVerifyHeaderOnly(text) {
25577
27608
  const pickup = text.startsWith(VERIFY_PICKUP_EVENT_PREFIX);
25578
27609
  if (!pickup && !text.startsWith("\u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u0432\u0435\u0440\u0438\u0444\u0438\u043A\u0430\u0446\u0438\u0438 \u043E\u0442")) return false;
25579
- const sep4 = pickup ? "): " : ": ";
25580
- const at = text.indexOf(sep4);
27610
+ const sep5 = pickup ? "): " : ": ";
27611
+ const at = text.indexOf(sep5);
25581
27612
  if (at < 0) return true;
25582
- const rest = stripVerdictHead(text.slice(at + sep4.length).replace(/\s+\[[^\]]*\]\s*$/, "")).trim();
27613
+ const rest = stripVerdictHead(text.slice(at + sep5.length).replace(/\s+\[[^\]]*\]\s*$/, "")).trim();
25583
27614
  return rest.length === 0 || VERIFY_HEADER_LABELS.has(rest);
25584
27615
  }
25585
27616
  function isClippedPickup(text) {
@@ -25947,7 +27978,7 @@ async function tickOnce(deps) {
25947
27978
  draftHeldThisTick.clear();
25948
27979
  fixBlockedThisTick.clear();
25949
27980
  resetGrokBalanceTick();
25950
- const worktreeExists = deps.worktreeExists ?? existsSync23;
27981
+ const worktreeExists = deps.worktreeExists ?? existsSync26;
25951
27982
  const hasTranscript = deps.hasTranscript ?? executorHasSession;
25952
27983
  deps.stepClock?.mark("0 \u0437\u0430\u043C\u0435\u0440 \u0445\u043E\u0441\u0442\u0430");
25953
27984
  deps.sampleHost?.();
@@ -25999,12 +28030,12 @@ async function tickOnce(deps) {
25999
28030
  }
26000
28031
  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");
26001
28032
  if (deps.repoMap) {
26002
- const rm3 = deps.repoMap;
26003
- const sinceLast = rm3.lastAt == null ? Infinity : now - rm3.lastAt;
26004
- if (sinceLast >= rm3.intervalMs) {
26005
- rm3.lastAt = now;
28033
+ const rm4 = deps.repoMap;
28034
+ const sinceLast = rm4.lastAt == null ? Infinity : now - rm4.lastAt;
28035
+ if (sinceLast >= rm4.intervalMs) {
28036
+ rm4.lastAt = now;
26006
28037
  try {
26007
- await rm3.run();
28038
+ await rm4.run();
26008
28039
  } catch (e) {
26009
28040
  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);
26010
28041
  }
@@ -26984,7 +29015,7 @@ async function resolveConflict(deps, reviewRun) {
26984
29015
  model: reviewRun.model,
26985
29016
  review_model: reviewRun.review_model
26986
29017
  });
26987
- const wt = join41(deps.worktreesDir, basename7(repo), `${reviewRun.task_slug}-resolve-${resolver.id}`);
29018
+ const wt = join44(deps.worktreesDir, basename8(repo), `${reviewRun.task_slug}-resolve-${resolver.id}`);
26988
29019
  try {
26989
29020
  await deps.git.prepareDetachedWorktree(repo, branch, wt);
26990
29021
  await deps.git.setWorktreeIdentity(wt, resolver.name);
@@ -27065,7 +29096,7 @@ async function spawnReviewer(deps, reviewRun, files) {
27065
29096
  // (своей у ревьюера нет, TASWM-204), и коммент с вердиктом должен уехать именно туда.
27066
29097
  workspace_id: reviewRun.workspace_id
27067
29098
  });
27068
- const wt = join41(deps.worktreesDir, basename7(repo), `${reviewRun.task_slug}-review-${reviewer.id}`);
29099
+ const wt = join44(deps.worktreesDir, basename8(repo), `${reviewRun.task_slug}-review-${reviewer.id}`);
27069
29100
  try {
27070
29101
  await deps.git.prepareDetachedWorktree(repo, branch, wt);
27071
29102
  await deps.git.setWorktreeIdentity(wt, reviewer.name);
@@ -27148,7 +29179,7 @@ async function spawnVerifier(deps, verifiedRun, files) {
27148
29179
  // штамп цикла: фикс-итерацию проверяет свежий верификатор
27149
29180
  workspace_id: verifiedRun.workspace_id
27150
29181
  });
27151
- const wt = join41(deps.worktreesDir, basename7(repo), `${verifiedRun.task_slug}-verify-${verifier.id}`);
29182
+ const wt = join44(deps.worktreesDir, basename8(repo), `${verifiedRun.task_slug}-verify-${verifier.id}`);
27152
29183
  try {
27153
29184
  await deps.git.prepareDetachedWorktree(repo, branch, wt);
27154
29185
  await deps.git.setWorktreeIdentity(wt, verifier.name);
@@ -27263,7 +29294,7 @@ async function respawnRun(deps, run2, mode, nudge) {
27263
29294
  ]);
27264
29295
  const base3 = effectiveBaseBranch(run2.base_branch, projectBase);
27265
29296
  const runToSpawn = base3 && run2.base_branch !== base3 ? deps.db.updateRun(run2.id, { base_branch: base3 }) ?? run2 : run2;
27266
- if (!existsSync23(wt)) {
29297
+ if (!existsSync26(wt)) {
27267
29298
  const branch = runToSpawn.branch || runToSpawn.task_slug;
27268
29299
  const source = await addWorktree(repo, wt, branch, {
27269
29300
  ...base3 ? { base: await remoteBaseRef(repo, base3) } : {},
@@ -27308,7 +29339,7 @@ function worktreePathPatch(run2, wt) {
27308
29339
  return run2.worktree_path === wt ? {} : { worktree_path: wt };
27309
29340
  }
27310
29341
  async function syncCrashedOnStartup(deps) {
27311
- const worktreeExists = deps.worktreeExists ?? existsSync23;
29342
+ const worktreeExists = deps.worktreeExists ?? existsSync26;
27312
29343
  let orphaned = 0;
27313
29344
  let merged = 0;
27314
29345
  let requeued = 0;
@@ -27473,10 +29504,10 @@ async function migrateWorktreesAtStartup() {
27473
29504
  legacyDir: WORKTREES_LEGACY_DIR,
27474
29505
  targetDir: WORKTREES_DIR,
27475
29506
  envOverride: process.env.SWARM_WORKTREES || "",
27476
- exists: (d) => existsSync23(d),
29507
+ exists: (d) => existsSync26(d),
27477
29508
  isNonEmptyDir: (d) => {
27478
29509
  try {
27479
- return readdirSync18(d).length > 0;
29510
+ return readdirSync19(d).length > 0;
27480
29511
  } catch {
27481
29512
  return false;
27482
29513
  }
@@ -27488,7 +29519,7 @@ async function migrateWorktreesAtStartup() {
27488
29519
  });
27489
29520
  } catch (e) {
27490
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);
27491
- return existsSync23(WORKTREES_DIR) ? WORKTREES_DIR : WORKTREES_LEGACY_DIR;
29522
+ return existsSync26(WORKTREES_DIR) ? WORKTREES_DIR : WORKTREES_LEGACY_DIR;
27492
29523
  }
27493
29524
  }
27494
29525
  async function reportWorkspaceAccess(tl, db) {
@@ -27525,7 +29556,7 @@ function sweepDaemonStands(opts) {
27525
29556
  worktreesDir,
27526
29557
  activeWorktreePaths: new Set(runsWithWorktree.filter((r) => !isTerminalStatus(r.status)).map((r) => r.worktree_path)),
27527
29558
  containerRunPrefixes: runsWithWorktree.map((r) => ({
27528
- prefix: composeProjectPrefix(basename7(r.worktree_path)),
29559
+ prefix: composeProjectPrefix(basename8(r.worktree_path)),
27529
29560
  active: !isTerminalStatus(r.status)
27530
29561
  })),
27531
29562
  ...opts.scan ? { scan: opts.scan } : {},
@@ -28253,7 +30284,7 @@ async function runDaemon(opts) {
28253
30284
  isDirty: (p) => worktreeDirty(p),
28254
30285
  releaseWorktree: (repo, p) => releaseWorktree(repo || opts.repo, p),
28255
30286
  pruneWorktrees: (repo) => pruneWorktrees(repo || opts.repo),
28256
- worktreeExists: existsSync23,
30287
+ worktreeExists: existsSync26,
28257
30288
  liveWorktrees: () => new Set(listDroneProcesses().map((p) => p.worktree)),
28258
30289
  narrate: narrator.narrate
28259
30290
  });
@@ -28397,13 +30428,13 @@ async function runDaemon(opts) {
28397
30428
  mode,
28398
30429
  nudge
28399
30430
  ),
28400
- worktreeExists: (p) => existsSync23(p),
30431
+ worktreeExists: (p) => existsSync26(p),
28401
30432
  // TASWM-514: с этого момента считаем попытки спавна — счётчик живёт ровно одну жизнь
28402
30433
  // процесса демона и рестарт не переживает (см. preStartAttempts).
28403
30434
  startedAt: Date.now(),
28404
30435
  // TASWM-592: run-aware — где лежит сессия, знает харнесс ПРОГОНА.
28405
30436
  hasTranscript: (run2) => !!run2.worktree_path && executorForRun(run2, lastSwarmModels, process.env, runModelRefPin.get(run2.id) ?? null).session.exists(run2.worktree_path),
28406
- runHasSession: (run2) => !!run2.worktree_path && existsSync23(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),
28407
30438
  // CI-осведомлённость review-PR (TASWM-102): реальный `gh pr checks`/`gh run view --log-failed`
28408
30439
  // (gh.ts) — решение (будить ли дрона) и гейты живут в tickOnce/handleCiRed. failureSummary
28409
30440
  // строится над failing/failingRunIds ИЗ checks — без повторного `gh pr checks`.
@@ -28501,7 +30532,7 @@ async function runDaemon(opts) {
28501
30532
  setTimeout(() => {
28502
30533
  Promise.all([closeWebServer(web.server), droneChannel ? closeDroneChannel(droneChannel.server) : Promise.resolve()]).then(() => {
28503
30534
  if (!stopping) {
28504
- spawn4(process.execPath, respawnArgs, {
30535
+ spawn5(process.execPath, respawnArgs, {
28505
30536
  detached: true,
28506
30537
  // TASWM-497: в ЛОГ, а не в /dev/null. Со `stdio: "ignore"` демон после каждого
28507
30538
  // `update`/`restart` замолкал навсегда, и разбирать инциденты по логу было нечем.
@@ -28635,7 +30666,7 @@ async function runDaemon(opts) {
28635
30666
  onStep
28636
30667
  });
28637
30668
  }
28638
- const repo = await repoRoot(dirname6(THIS_FILE)).catch(() => null);
30669
+ const repo = await repoRoot(dirname7(THIS_FILE)).catch(() => null);
28639
30670
  if (!repo) {
28640
30671
  return { ok: false, step: "fetch", message: "\u0431\u0435\u0433\u0443 \u0438\u0437 \u0438\u0441\u0445\u043E\u0434\u043D\u0438\u043A\u043E\u0432, \u043D\u043E git-\u0440\u0435\u043F\u043E\u0437\u0438\u0442\u043E\u0440\u0438\u044F \u043D\u0430\u0434 \u043D\u0438\u043C\u0438 \u043D\u0435\u0442 \u2014 \u043E\u0431\u043D\u043E\u0432\u043B\u044F\u0442\u044C \u043D\u0435\u0447\u0435\u0433\u043E" };
28641
30672
  }