@taskless-app/swarm 0.6.105 → 0.6.106

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 = {
@@ -7046,11 +7047,13 @@ __export(taskless_exports, {
7046
7047
  makeTasklessClient: () => makeTasklessClient,
7047
7048
  parseWorkspaces: () => parseWorkspaces,
7048
7049
  preflightAuth: () => preflightAuth,
7050
+ prepareFromConfig: () => prepareFromConfig,
7049
7051
  requireTaskBody: () => requireTaskBody,
7050
7052
  resetLegacyTokenWarning: () => resetLegacyTokenWarning,
7051
7053
  resolveApiToken: () => resolveApiToken,
7052
7054
  swarmToolArgs: () => swarmToolArgs,
7053
- taskAuthor: () => taskAuthor
7055
+ taskAuthor: () => taskAuthor,
7056
+ verifyCommandsFromProfile: () => verifyCommandsFromProfile
7054
7057
  });
7055
7058
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
7056
7059
  import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
@@ -7064,6 +7067,23 @@ function toolErrorText2(r) {
7064
7067
  const fromContent = (r.content ?? []).map((c) => c.text ?? "").filter(Boolean).join(" ").trim();
7065
7068
  return fromContent || JSON.stringify(r);
7066
7069
  }
7070
+ function prepareFromConfig(structured) {
7071
+ const config = structured?.config;
7072
+ if (!config || typeof config !== "object" || Array.isArray(config)) return null;
7073
+ const prepare = config.prepare;
7074
+ if (!Array.isArray(prepare)) return null;
7075
+ return prepare.filter((c) => typeof c === "string").map((c) => c.trim()).filter((c) => c.length > 0);
7076
+ }
7077
+ function verifyCommandsFromProfile(structured) {
7078
+ const profile = structured?.profile;
7079
+ if (!profile || typeof profile !== "object" || Array.isArray(profile)) return null;
7080
+ const verify = profile.verify;
7081
+ if (verify == null) return null;
7082
+ if (typeof verify !== "object" || Array.isArray(verify)) return null;
7083
+ const commands = verify.commands;
7084
+ if (!Array.isArray(commands)) return null;
7085
+ return commands.filter((c) => typeof c === "string").map((c) => c.trim()).filter((c) => c.length > 0);
7086
+ }
7067
7087
  function makeTasklessClient(call, workspaceId, taskUrlBase, fetchFile, fetchImpl = fetch) {
7068
7088
  const ws = workspaceId ? { workspaceId } : {};
7069
7089
  const idCache = /* @__PURE__ */ new Map();
@@ -7198,6 +7218,30 @@ function makeTasklessClient(call, workspaceId, taskUrlBase, fetchFile, fetchImpl
7198
7218
  ...input.taskSlug ? { taskSlug: input.taskSlug } : {}
7199
7219
  });
7200
7220
  }
7221
+ async function readRepoConfig(repoFullName, taskSlug) {
7222
+ const drop = slugRetry.within("swarm_repo_config") && !!taskSlug;
7223
+ const args = { repoFullName, ...taskSlug && !drop ? { taskSlug } : {} };
7224
+ let outcome = await callTool("swarm_repo_config", args);
7225
+ if (!outcome.ok && taskSlug && unknownArg(outcome.failure.detail, "taskSlug")) {
7226
+ slugRetry.note("swarm_repo_config");
7227
+ console.warn("[taskless] swarm_repo_config \u043E\u0442\u0432\u0435\u0440\u0433 taskSlug \u2014 \u043F\u043E\u0432\u0442\u043E\u0440\u044F\u044E \u0431\u0435\u0437 \u043D\u0435\u0433\u043E: \u0441\u0435\u0440\u0432\u0435\u0440, \u0432\u0435\u0440\u043E\u044F\u0442\u043D\u043E, \u0441\u0442\u0430\u0440\u0435\u0435 \u0434\u0435\u043C\u043E\u043D\u0430");
7228
+ outcome = await callTool("swarm_repo_config", { repoFullName });
7229
+ }
7230
+ if (!outcome.ok || outcome.res.isError) return null;
7231
+ const sc = outcome.res.structuredContent ?? null;
7232
+ if (sc?.ambiguous === true || sc?.repoAmbiguous === true) return null;
7233
+ return sc;
7234
+ }
7235
+ async function repoVerifyCommands(repoFullName, taskSlug) {
7236
+ const sc = await readRepoConfig(repoFullName, taskSlug);
7237
+ if (!sc) return null;
7238
+ return verifyCommandsFromProfile(sc);
7239
+ }
7240
+ async function repoPrepare(repoFullName, taskSlug) {
7241
+ const sc = await readRepoConfig(repoFullName, taskSlug);
7242
+ if (!sc) return null;
7243
+ return prepareFromConfig(sc);
7244
+ }
7201
7245
  async function callDroppingUnknownSlug(name, args) {
7202
7246
  const drop = slugRetry.within(name) && "taskSlug" in args;
7203
7247
  const sent = drop ? (({ taskSlug: _slug, ...rest }) => rest)(args) : args;
@@ -7299,6 +7343,8 @@ function makeTasklessClient(call, workspaceId, taskUrlBase, fetchFile, fetchImpl
7299
7343
  decideRepoRules,
7300
7344
  proposeZoneNotes,
7301
7345
  confirmZoneNotes,
7346
+ repoVerifyCommands,
7347
+ repoPrepare,
7302
7348
  createTask: async (input) => {
7303
7349
  if (!input.projectId) {
7304
7350
  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 +7657,7 @@ var init_taskless = __esm({
7611
7657
  init_authState();
7612
7658
  init_workspace();
7613
7659
  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"]);
7660
+ WS_FREE_TOOLS = /* @__PURE__ */ new Set(["list_workspaces", "who_am_i", "finalize_upload", "report_acceptance_check", "swarm_repo_config"]);
7615
7661
  TaskBodyUnavailableError = class extends Error {
7616
7662
  /** Код причины — по нему решают, повторять ли (TOOL_FAILURE_RETRIABLE), а не по тексту. */
7617
7663
  code;
@@ -7661,7 +7707,7 @@ __export(db_exports, {
7661
7707
  });
7662
7708
  import { createRequire as createRequire2 } from "module";
7663
7709
  import { randomUUID as randomUUID3 } from "crypto";
7664
- import { existsSync as existsSync18 } from "fs";
7710
+ import { existsSync as existsSync20 } from "fs";
7665
7711
  import { resolve as resolve5 } from "path";
7666
7712
  function rowToQuestion(row) {
7667
7713
  return {
@@ -8339,7 +8385,7 @@ CREATE TABLE IF NOT EXISTS imports (
8339
8385
  const repoN = normalizeRepo(repo);
8340
8386
  const already = this.db.prepare("SELECT run_count FROM imports WHERE source = ?").get(abs);
8341
8387
  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}`);
8388
+ if (!existsSync20(abs)) throw new Error(`import-db: \u0444\u0430\u0439\u043B\u0430 \u043D\u0435\u0442: ${abs}`);
8343
8389
  const src = new this.databaseCtor(abs);
8344
8390
  try {
8345
8391
  const runs = src.prepare("SELECT * FROM runs ORDER BY id").all();
@@ -8750,8 +8796,8 @@ var init_droneStore = __esm({
8750
8796
 
8751
8797
  // src/overmind.ts
8752
8798
  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";
8799
+ import { existsSync as existsSync25, readFileSync as readFileSync30, readdirSync as readdirSync19, renameSync as renameSync12, statSync as statSync17 } from "fs";
8800
+ import { basename as basename8, dirname as dirname7, join as join43 } from "path";
8755
8801
  import { fileURLToPath as fileURLToPath3, pathToFileURL } from "url";
8756
8802
  import { spawn as spawn4 } from "child_process";
8757
8803
 
@@ -13593,9 +13639,9 @@ function latestExhaustedWindow(report, executor) {
13593
13639
  return latest?.window ?? windows[0] ?? null;
13594
13640
  }
13595
13641
  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;
13642
+ const relative4 = /resets\s+in\s+(?:(\d+)\s*h)?\s*(?:(\d+)\s*m)?/i.exec(resetHint);
13643
+ if (relative4 && (relative4[1] || relative4[2])) {
13644
+ return nowMs + (Number(relative4[1] ?? 0) * 60 + Number(relative4[2] ?? 0)) * 6e4;
13599
13645
  }
13600
13646
  const clock = /resets(?:\s+at)?\s+(\d{1,2})(?::(\d{2}))?\s*(am|pm)?\b/i.exec(resetHint);
13601
13647
  if (!clock) return null;
@@ -14520,7 +14566,7 @@ async function ensureWorktreeDeps(worktree, io = {}) {
14520
14566
  const exists = io.exists ?? existsSync16;
14521
14567
  const exec = io.exec ?? ((cmd) => runCommand(cmd, worktree));
14522
14568
  const approve = io.approve ?? (() => true);
14523
- const cachePlan = envCachePlan(worktree, io);
14569
+ const cachePlan = io.skipEnvCache ? null : envCachePlan(worktree, io);
14524
14570
  const cacheIO = io.envCache ?? {};
14525
14571
  const report = {
14526
14572
  ecosystem: null,
@@ -14542,6 +14588,10 @@ async function ensureWorktreeDeps(worktree, io = {}) {
14542
14588
  report.source = plan.source;
14543
14589
  report.outcome = plan.source === "none" ? "not-detected" : "nothing-to-do";
14544
14590
  for (const cmd of plan.commands) {
14591
+ if (io.skipOptional && cmd.optional) {
14592
+ report.skipped.push(cmd.label);
14593
+ continue;
14594
+ }
14545
14595
  if (cmd.skipIfExists && exists(cmd.skipIfExists)) {
14546
14596
  report.skipped.push(cmd.label);
14547
14597
  continue;
@@ -14920,7 +14970,7 @@ function parkReasonUnretriable(reason) {
14920
14970
  // package.json
14921
14971
  var package_default = {
14922
14972
  name: "@taskless-app/swarm",
14923
- version: "0.6.105",
14973
+ version: "0.6.106",
14924
14974
  type: "module",
14925
14975
  description: "Local control plane for a fleet of AI coding agents (drones), coordinating through Taskless. The overmind runs the swarm.",
14926
14976
  keywords: [
@@ -14972,7 +15022,7 @@ var package_default = {
14972
15022
  undici: "^7.30.1",
14973
15023
  zod: "3.25.76"
14974
15024
  },
14975
- gitHead: "d737e797e951d0d8375e73623cb24d6ae9a7cc49"
15025
+ gitHead: "bb60755eda8d72e1dbf0adc4aa4e86b2d9189270"
14976
15026
  };
14977
15027
 
14978
15028
  // src/version.ts
@@ -15596,10 +15646,10 @@ function verdictEventSha(text) {
15596
15646
  }
15597
15647
  function changesLabel(text) {
15598
15648
  const pickup = text.startsWith(REVIEWER_PICKUP_PREFIX);
15599
- const sep4 = pickup ? "): " : ": ";
15600
- const at = text.indexOf(sep4);
15649
+ const sep5 = pickup ? "): " : ": ";
15650
+ const at = text.indexOf(sep5);
15601
15651
  if (at < 0) return false;
15602
- const line = (text.slice(at + sep4.length).split("\n")[0] ?? "").trim();
15652
+ const line = (text.slice(at + sep5.length).split("\n")[0] ?? "").trim();
15603
15653
  const head = line.split(" \u2014 ")[0] ?? line;
15604
15654
  return CHANGES_VERDICT_RE.test(head);
15605
15655
  }
@@ -16546,7 +16596,1266 @@ init_zoneNotes();
16546
16596
  init_src();
16547
16597
  init_src();
16548
16598
  init_src();
16599
+
16600
+ // src/mutationGate.ts
16601
+ init_procCleanup();
16602
+ 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";
16603
+ import { rm as rm3 } from "fs/promises";
16604
+ import { tmpdir as tmpdir2 } from "os";
16605
+ import { basename as basename6, isAbsolute as isAbsolute6, join as join36, relative as relative2, sep as sep4 } from "path";
16606
+ import { execa as execa2 } from "execa";
16607
+ var MAX_OUTPUT_CHARS = 2e5;
16608
+ var GIT_TIMEOUT_MS = 6e4;
16609
+ var WORKTREE_ADD_TIMEOUT_MS = 18e4;
16610
+ var COPY_PREFIX = "taswm-mutation-";
16611
+ var ORPHAN_FRESH_MS = 2 * 60 * 1e3;
16612
+ var TEST_FILE_RE = /(^|\/)[^/]*\.(test|spec)\.[^/]+$/;
16613
+ var DOC_EXT_RE = /\.(md|mdx|rst|adoc|asciidoc)$/i;
16614
+ var SNAPSHOT_DIR_RE = /^(?:__snapshots__|__image_snapshots__|__screenshots__)$/;
16615
+ var SNAPSHOT_SUFFIX_RE = /\.(?:test|spec)\.[^/]+-snapshots$/;
16616
+ var ANSI_RE = /\u001b(?:\[[0-9;?]*[ -/]*[@-~]|\][^\u0007]*(?:\u0007|\u001b\\))/g;
16617
+ var REPORT_PATH_RE = /(?:JSON report written to|Test results written to:?)\s+(.+)/;
16618
+ var ROOT_SKIP_DIRS = /* @__PURE__ */ new Set(["journal", "docs", "changelog"]);
16619
+ var AGENT_ENV_NAMES = /* @__PURE__ */ new Set([
16620
+ "CLAUDECODE",
16621
+ "CLAUDE_CODE",
16622
+ "AI_AGENT",
16623
+ "CURSOR_AGENT",
16624
+ "GEMINI_CLI",
16625
+ "OPENCODE",
16626
+ "REPL_ID",
16627
+ "AUGMENT_AGENT",
16628
+ "GOOSE_PROVIDER",
16629
+ "JUNIE_DATA",
16630
+ "JUNIE_SHIM_PATH",
16631
+ "COPILOT_AGENT",
16632
+ "COPILOT_CLI"
16633
+ ]);
16634
+ var AGENT_ENV_PREFIXES = ["CLAUDE_CODE_", "CODEX_"];
16635
+ var LOCK_NAMES = /* @__PURE__ */ new Set([
16636
+ "pnpm-lock.yaml",
16637
+ "package-lock.json",
16638
+ "npm-shrinkwrap.json",
16639
+ "yarn.lock",
16640
+ "bun.lock",
16641
+ "bun.lockb",
16642
+ "composer.lock",
16643
+ "gemfile.lock",
16644
+ "cargo.lock",
16645
+ "poetry.lock",
16646
+ "deno.lock",
16647
+ "go.sum",
16648
+ "packages.lock.json",
16649
+ "paket.lock",
16650
+ "mix.lock",
16651
+ "pubspec.lock",
16652
+ "flake.lock",
16653
+ "uv.lock"
16654
+ ]);
16655
+ var GateTimeout = class extends Error {
16656
+ constructor() {
16657
+ super("\u0442\u0430\u0439\u043C\u0430\u0443\u0442");
16658
+ this.name = "GateTimeout";
16659
+ }
16660
+ };
16661
+ function isMutationTestFile(path) {
16662
+ const p = normalizePath2(path);
16663
+ if (isSnapshot(p)) return false;
16664
+ if (TEST_FILE_RE.test(p)) return true;
16665
+ return p.split("/").includes("__tests__");
16666
+ }
16667
+ function isMutationSkippedPath(path) {
16668
+ const p = normalizePath2(path);
16669
+ const top = p.split("/")[0] ?? "";
16670
+ if (ROOT_SKIP_DIRS.has(top)) return true;
16671
+ if (isSnapshot(p)) return true;
16672
+ const base3 = p.split("/").pop() ?? p;
16673
+ if (DOC_EXT_RE.test(base3)) return true;
16674
+ if (base3.endsWith(".lock")) return true;
16675
+ return LOCK_NAMES.has(base3.toLowerCase());
16676
+ }
16677
+ function parseNameStatusZ(text) {
16678
+ if (!text) return [];
16679
+ const parts = text.split("\0").filter((p) => p.length > 0);
16680
+ const out = [];
16681
+ for (let i = 0; i < parts.length; ) {
16682
+ const status = parts[i++];
16683
+ if (!status) break;
16684
+ const code = status[0] ?? "?";
16685
+ if (code === "R" || code === "C") {
16686
+ const oldPath = parts[i++];
16687
+ const path2 = parts[i++];
16688
+ 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");
16689
+ out.push({ code, path: normalizePath2(path2), oldPath: normalizePath2(oldPath) });
16690
+ continue;
16691
+ }
16692
+ const path = parts[i++];
16693
+ 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`);
16694
+ out.push({ code, path: normalizePath2(path) });
16695
+ }
16696
+ return out;
16697
+ }
16698
+ function classifyMutationDiff(entries) {
16699
+ const testFiles = [];
16700
+ const restore = [];
16701
+ const remove = [];
16702
+ const bucket = (path, kind) => {
16703
+ if (isMutationSkippedPath(path)) return;
16704
+ if (isMutationTestFile(path)) {
16705
+ if (kind !== "delete") testFiles.push(path);
16706
+ return;
16707
+ }
16708
+ if (kind === "add") remove.push(path);
16709
+ else restore.push(path);
16710
+ };
16711
+ for (const entry of entries) {
16712
+ if (entry.code === "R" || entry.code === "C") {
16713
+ bucket(entry.path, "add");
16714
+ if (entry.oldPath) bucket(entry.oldPath, "delete");
16715
+ continue;
16716
+ }
16717
+ if (entry.code === "A") bucket(entry.path, "add");
16718
+ else if (entry.code === "D") bucket(entry.path, "delete");
16719
+ else bucket(entry.path, "modify");
16720
+ }
16721
+ const tests = uniq(testFiles);
16722
+ const testSet = new Set(tests);
16723
+ const removed = uniq(remove).filter((p) => !testSet.has(p));
16724
+ const removeSet = new Set(removed);
16725
+ return {
16726
+ testFiles: tests,
16727
+ remove: removed,
16728
+ restore: uniq(restore).filter((p) => !testSet.has(p) && !removeSet.has(p))
16729
+ };
16730
+ }
16731
+ var PRESTART_RULES = [
16732
+ {
16733
+ label: "\u043D\u0435\u0442 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430",
16734
+ re: /Executable doesn't exist|browserType\.launch|playwright install/i
16735
+ },
16736
+ {
16737
+ label: "\u043D\u0435\u0442 \u0431\u0430\u0437\u044B",
16738
+ re: /ECONNREFUSED|password authentication failed|could not connect to server|Connection refused|database ".+" does not exist|Can't reach database server|P1001/i
16739
+ },
16740
+ {
16741
+ label: "\u043D\u0435\u0442 \u043E\u043A\u0440\u0443\u0436\u0435\u043D\u0438\u044F",
16742
+ re: /command not found|not recognized as an internal or external command|Cannot find module|MODULE_NOT_FOUND|ENOENT|Missing script:/i
16743
+ }
16744
+ ];
16745
+ var FAIL_MARK_RE = /(?:^|[\s[(])(?:FAILED|FAIL|✖|✗|×|✘)(?=$|[\s[(:])/;
16746
+ var PASS_MARK_RE = /(?:^|[\s[(])(?:PASSED|PASS|✓|✔|√)(?=$|[\s[(:])/;
16747
+ var BUN_FAIL_RE = /(?:^|\s)\(fail\)(?=$|\s)/i;
16748
+ var BUN_PASS_RE = /(?:^|\s)\(pass\)(?=$|\s)/i;
16749
+ async function runMutationGate(opts) {
16750
+ 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)");
16751
+ const base3 = opts.base.trim();
16752
+ if (!/^[A-Za-z0-9._/-]+$/.test(base3) || base3.includes("..") || base3.startsWith("-") || base3.startsWith("/") || base3.endsWith("/")) {
16753
+ 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`);
16754
+ }
16755
+ const worktree = opts.worktree;
16756
+ const baseRef = `origin/${base3}`;
16757
+ const hasBase = await git(worktree, ["rev-parse", "--verify", "--quiet", `${baseRef}^{commit}`]);
16758
+ if (hasBase.exitCode !== 0) {
16759
+ throw new Error(`\u0431\u0430\u0437\u0430 ${baseRef} \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D\u0430 \u0432 ${worktree}`);
16760
+ }
16761
+ const diffOut = await gitOk(worktree, ["diff", "--name-status", "-z", "--find-renames", `${baseRef}...HEAD`]);
16762
+ const diff = classifyMutationDiff(parseNameStatusZ(diffOut));
16763
+ if (diff.testFiles.length === 0) {
16764
+ return { reddened: [], stayedGreen: [], notRun: [], output: "", headOutput: "", exitCode: null, testFiles: [] };
16765
+ }
16766
+ await sweepOrphans2(null);
16767
+ const source = diff.restore.length > 0 ? (await gitOk(worktree, ["merge-base", baseRef, "HEAD"])).trim() : null;
16768
+ const ac = new AbortController();
16769
+ let stop = null;
16770
+ const onExternal = () => {
16771
+ if (!stop) stop = { reason: "\u043E\u0442\u043C\u0435\u043D\u0435\u043D\u043E", code: "aborted" };
16772
+ ac.abort();
16773
+ };
16774
+ if (opts.signal) {
16775
+ if (opts.signal.aborted) onExternal();
16776
+ else opts.signal.addEventListener("abort", onExternal, { once: true });
16777
+ }
16778
+ let timer;
16779
+ let headOutput = "";
16780
+ let parent = "";
16781
+ let hooks = "";
16782
+ let copy = "";
16783
+ try {
16784
+ parent = realpathSync3(mkdtempSync(join36(tmpdir2(), COPY_PREFIX)));
16785
+ writeFileSync17(join36(parent, "owner.pid"), String(process.pid));
16786
+ hooks = join36(parent, "hooks");
16787
+ copy = join36(parent, basename6(parent));
16788
+ mkdirSync13(hooks);
16789
+ const env = runnerEnv(process.env);
16790
+ const reportFor = (phase) => {
16791
+ const file = join36(parent, `report-${phase}.json`);
16792
+ rmSync4(file, { force: true });
16793
+ return file;
16794
+ };
16795
+ await gitOk(worktree, ["worktree", "add", "--detach", copy, "HEAD"], {
16796
+ timeoutMs: WORKTREE_ADD_TIMEOUT_MS,
16797
+ hooksPath: hooks
16798
+ });
16799
+ if (opts.timeoutMs != null) {
16800
+ const ms = Math.max(0, opts.timeoutMs);
16801
+ if (ms === 0) {
16802
+ stop = { reason: "\u0442\u0430\u0439\u043C\u0430\u0443\u0442", code: "timeout" };
16803
+ ac.abort();
16804
+ } else {
16805
+ timer = setTimeout(() => {
16806
+ if (!stop) stop = { reason: "\u0442\u0430\u0439\u043C\u0430\u0443\u0442", code: "timeout" };
16807
+ ac.abort();
16808
+ }, ms);
16809
+ timer.unref?.();
16810
+ }
16811
+ }
16812
+ const headFile = reportFor("head");
16813
+ const headReport = await invokeRun(opts.runTests, { cwd: copy, testFiles: diff.testFiles, phase: "head", signal: ac.signal, env, reportFile: headFile });
16814
+ const headMap = verdicts(diff.testFiles, headReport, { repoRoot: copy, cwd: copy, reportFile: headFile });
16815
+ headOutput = clipTail(combineFull(headReport.stdout, headReport.stderr));
16816
+ const greenOnHead = diff.testFiles.filter((file) => headMap.get(file)?.status === "passed");
16817
+ if (greenOnHead.length === 0) {
16818
+ return {
16819
+ ...headWithoutGreen(diff.testFiles, headMap),
16820
+ output: headOutput,
16821
+ headOutput,
16822
+ exitCode: headReport.exitCode,
16823
+ testFiles: diff.testFiles
16824
+ };
16825
+ }
16826
+ await revertCode(copy, diff, source, hooks, ac.signal);
16827
+ await gitOk(copy, ["clean", "-ffdx", "-e", "node_modules"], { hooksPath: hooks, signal: ac.signal });
16828
+ const baseFile = reportFor("base");
16829
+ const baseReport = await invokeRun(opts.runTests, { cwd: copy, testFiles: greenOnHead, phase: "base", signal: ac.signal, env, reportFile: baseFile });
16830
+ const baseMap = verdicts(greenOnHead, baseReport, { repoRoot: copy, cwd: copy, reportFile: baseFile });
16831
+ return {
16832
+ ...comparePhases(diff.testFiles, headMap, baseMap),
16833
+ output: clipTail(combineFull(baseReport.stdout, baseReport.stderr)),
16834
+ headOutput,
16835
+ exitCode: baseReport.exitCode,
16836
+ testFiles: diff.testFiles
16837
+ };
16838
+ } catch (e) {
16839
+ if (!(e instanceof GateTimeout) && !ac.signal.aborted) throw e;
16840
+ if (copy) {
16841
+ try {
16842
+ await cleanupWorktreeProcesses(copy);
16843
+ } catch {
16844
+ }
16845
+ }
16846
+ const why = stop ?? { reason: "\u0442\u0430\u0439\u043C\u0430\u0443\u0442", code: "timeout" };
16847
+ return {
16848
+ reddened: [],
16849
+ stayedGreen: [],
16850
+ notRun: diff.testFiles.map((file) => ({ file, reason: why.reason, code: why.code })),
16851
+ output: "",
16852
+ headOutput,
16853
+ exitCode: null,
16854
+ testFiles: diff.testFiles
16855
+ };
16856
+ } finally {
16857
+ if (timer) clearTimeout(timer);
16858
+ opts.signal?.removeEventListener("abort", onExternal);
16859
+ if (parent) await destroyCopy(worktree, copy, parent, hooks);
16860
+ }
16861
+ }
16862
+ function comparePhases(testFiles, head, base3) {
16863
+ const reddened = [];
16864
+ const stayedGreen = [];
16865
+ const notRun = [];
16866
+ for (const file of testFiles) {
16867
+ if (notGreenOnHead(file, head.get(file), notRun)) continue;
16868
+ const onBase = base3.get(file);
16869
+ if (!onBase || onBase.status === "not-run") {
16870
+ 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" });
16871
+ } else if (onBase.status === "failed") reddened.push(file);
16872
+ else stayedGreen.push(file);
16873
+ }
16874
+ return { reddened, stayedGreen, notRun };
16875
+ }
16876
+ function headWithoutGreen(testFiles, head) {
16877
+ const stayedGreen = [];
16878
+ const notRun = [];
16879
+ for (const file of testFiles) {
16880
+ if (notGreenOnHead(file, head.get(file), notRun)) continue;
16881
+ stayedGreen.push(file);
16882
+ }
16883
+ return { reddened: [], stayedGreen, notRun };
16884
+ }
16885
+ function notGreenOnHead(file, onHead, notRun) {
16886
+ if (!onHead || onHead.status === "not-run") {
16887
+ 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" });
16888
+ return true;
16889
+ }
16890
+ if (onHead.status === "failed") {
16891
+ 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";
16892
+ notRun.push({ file, reason: cleanReason(why, why), code: "red-on-head" });
16893
+ return true;
16894
+ }
16895
+ return false;
16896
+ }
16897
+ async function revertCode(copy, diff, source, hooks, signal) {
16898
+ const call = { hooksPath: hooks, signal };
16899
+ const removePaths = [...diff.remove].sort((a, b) => b.split("/").length - a.split("/").length || b.length - a.length);
16900
+ for (const chunk of chunks(removePaths, 80)) {
16901
+ await gitOk(copy, ["rm", "-f", "-q", "--", ...chunk], call);
16902
+ }
16903
+ const blocked = /* @__PURE__ */ new Set();
16904
+ for (const rel of diff.restore) {
16905
+ const abs = join36(copy, rel);
16906
+ if (!existsSync18(abs)) continue;
16907
+ let info;
16908
+ try {
16909
+ info = lstatSync2(abs);
16910
+ } catch {
16911
+ continue;
16912
+ }
16913
+ if (!info.isDirectory()) continue;
16914
+ if (treeHoldsKept(copy, abs)) {
16915
+ blocked.add(rel);
16916
+ continue;
16917
+ }
16918
+ rmSync4(abs, { recursive: true, force: true });
16919
+ }
16920
+ const restore = diff.restore.filter((rel) => !blocked.has(rel));
16921
+ if (source && restore.length > 0) {
16922
+ for (const chunk of chunks(restore, 80)) {
16923
+ await gitOk(copy, ["restore", "--source", source, "--worktree", "--staged", "--", ...chunk], call);
16924
+ }
16925
+ }
16926
+ }
16927
+ function treeHoldsKept(copy, absDir) {
16928
+ const pending2 = [absDir];
16929
+ while (pending2.length > 0) {
16930
+ const dir = pending2.pop();
16931
+ if (!dir) continue;
16932
+ let names;
16933
+ try {
16934
+ names = readdirSync18(dir);
16935
+ } catch {
16936
+ continue;
16937
+ }
16938
+ for (const name of names) {
16939
+ const abs = join36(dir, name);
16940
+ let info;
16941
+ try {
16942
+ info = lstatSync2(abs);
16943
+ } catch {
16944
+ continue;
16945
+ }
16946
+ if (info.isDirectory() && !info.isSymbolicLink()) {
16947
+ pending2.push(abs);
16948
+ continue;
16949
+ }
16950
+ if (keptOnRevert(copy, abs)) return true;
16951
+ }
16952
+ }
16953
+ return false;
16954
+ }
16955
+ function keptOnRevert(copy, abs) {
16956
+ let rel = normalizePath2(relative2(copy, abs));
16957
+ if (rel.startsWith("./")) rel = rel.slice(2);
16958
+ if (!rel || rel === ".." || rel.startsWith("../")) return false;
16959
+ return isMutationTestFile(rel) || isMutationSkippedPath(rel);
16960
+ }
16961
+ async function invokeRun(run2, ctx) {
16962
+ if (ctx.signal.aborted) throw new GateTimeout();
16963
+ const pending2 = run2(ctx);
16964
+ pending2.catch(() => {
16965
+ });
16966
+ return await new Promise((resolve6, reject) => {
16967
+ const onAbort = () => reject(new GateTimeout());
16968
+ ctx.signal.addEventListener("abort", onAbort, { once: true });
16969
+ pending2.then(
16970
+ (value) => {
16971
+ ctx.signal.removeEventListener("abort", onAbort);
16972
+ if (ctx.signal.aborted) reject(new GateTimeout());
16973
+ else resolve6(value);
16974
+ },
16975
+ (err) => {
16976
+ ctx.signal.removeEventListener("abort", onAbort);
16977
+ if (ctx.signal.aborted) reject(new GateTimeout());
16978
+ else reject(err);
16979
+ }
16980
+ );
16981
+ });
16982
+ }
16983
+ function verdicts(testFiles, report, scope) {
16984
+ const stripped = stripAnsi(combineFull(report.stdout, report.stderr));
16985
+ if (report.started === false) {
16986
+ 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");
16987
+ return fillAll(testFiles, { status: "not-run", reason: reason2, code: "not-started" });
16988
+ }
16989
+ const fromFile = scope.reportFile ? reportFileVerdicts(testFiles, scope.reportFile, scope.repoRoot ?? "") : null;
16990
+ 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");
16991
+ const explicit = explicitVerdicts(testFiles, report, scope, stripped);
16992
+ 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");
16993
+ const { found: marks, sawFilePass } = readMarks(testFiles, stripped);
16994
+ if (marks.size > 0) {
16995
+ if (!sawFilePass) {
16996
+ for (const file of testFiles) {
16997
+ if (!marks.has(file)) marks.set(file, { status: "passed" });
16998
+ }
16999
+ }
17000
+ 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");
17001
+ }
17002
+ if (report.exitCode === 0) return fillAll(testFiles, { status: "passed" });
17003
+ const prestart = prestartReason(stripped);
17004
+ const reason = cleanReason(
17005
+ report.reason,
17006
+ 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`)
17007
+ );
17008
+ const code = prestart || report.exitCode === null ? "not-started" : "no-verdict";
17009
+ return fillAll(testFiles, { status: "not-run", reason, code });
17010
+ }
17011
+ function explicitVerdicts(testFiles, report, scope, stripped) {
17012
+ const listed = report.files?.filter((f) => f.file.length > 0) ?? [];
17013
+ if (listed.length > 0) return mapReports(testFiles, listed, scope.repoRoot ?? "", "not-started");
17014
+ const fromOut = parseJsonReport(report.stdout) ?? parseJsonReport(report.stderr);
17015
+ if (fromOut) {
17016
+ const mapped = mapReports(testFiles, fromOut, scope.repoRoot ?? "");
17017
+ if (mapped.size > 0) return mapped;
17018
+ }
17019
+ const file = scope.cwd ? reportFileFromOutput(stripped, scope.cwd) : null;
17020
+ return file ? reportFileVerdicts(testFiles, file, scope.repoRoot ?? "") : null;
17021
+ }
17022
+ function reportFileVerdicts(testFiles, file, repoRoot2) {
17023
+ let text;
17024
+ try {
17025
+ text = readFileSync26(file, "utf8");
17026
+ } catch {
17027
+ return null;
17028
+ }
17029
+ const parsed = parseJsonReport(text);
17030
+ if (!parsed) return null;
17031
+ const mapped = mapReports(testFiles, parsed, repoRoot2);
17032
+ return mapped.size > 0 ? mapped : null;
17033
+ }
17034
+ function runnerEnv(source) {
17035
+ const out = {};
17036
+ for (const [key, value] of Object.entries(source)) {
17037
+ if (value === void 0) continue;
17038
+ const upper = key.toUpperCase();
17039
+ if (AGENT_ENV_NAMES.has(upper) || AGENT_ENV_PREFIXES.some((prefix) => upper.startsWith(prefix))) continue;
17040
+ if (upper === "TERM_PROGRAM" && /kiro/.test(value)) continue;
17041
+ if (upper === "EDITOR" && /devin/.test(value)) continue;
17042
+ out[key] = value;
17043
+ }
17044
+ return out;
17045
+ }
17046
+ function mapReports(testFiles, reports, repoRoot2, notRunCode = "no-verdict") {
17047
+ const out = /* @__PURE__ */ new Map();
17048
+ for (const report of reports) {
17049
+ const file = resolveReportedPath(report.file, testFiles, repoRoot2);
17050
+ if (!file) continue;
17051
+ const next = { status: report.status };
17052
+ if (report.reason) next.reason = report.reason;
17053
+ if (report.status === "not-run") next.code = notRunCode;
17054
+ out.set(file, mergeVerdict(out.get(file), next));
17055
+ }
17056
+ return out;
17057
+ }
17058
+ function align(testFiles, found, missingReason) {
17059
+ const out = /* @__PURE__ */ new Map();
17060
+ for (const file of testFiles) {
17061
+ out.set(file, found.get(file) ?? { status: "not-run", reason: missingReason, code: "no-verdict" });
17062
+ }
17063
+ return out;
17064
+ }
17065
+ function fillAll(testFiles, verdict) {
17066
+ const out = /* @__PURE__ */ new Map();
17067
+ for (const file of testFiles) out.set(file, verdict);
17068
+ return out;
17069
+ }
17070
+ function mergeVerdict(prev, next) {
17071
+ if (!prev) return next;
17072
+ const status = prev.status === "failed" || next.status === "failed" ? "failed" : prev.status === "not-run" || next.status === "not-run" ? "not-run" : "passed";
17073
+ const out = { status };
17074
+ const reason = next.reason ?? prev.reason;
17075
+ if (reason) out.reason = reason;
17076
+ const code = next.code ?? prev.code;
17077
+ if (status === "not-run" && code) out.code = code;
17078
+ return out;
17079
+ }
17080
+ function readMarks(testFiles, output) {
17081
+ const found = /* @__PURE__ */ new Map();
17082
+ if (!output) return { found, sawFilePass: false };
17083
+ const index = buildNeedles(testFiles);
17084
+ let current = null;
17085
+ let sawFilePass = false;
17086
+ for (const raw of output.split("\n")) {
17087
+ const line = raw.trim();
17088
+ if (!line) continue;
17089
+ const mentioned = filesOnLine(line, index);
17090
+ if (mentioned.length === 1) current = mentioned[0] ?? null;
17091
+ const failed = FAIL_MARK_RE.test(line) || BUN_FAIL_RE.test(line);
17092
+ const passed = !failed && (PASS_MARK_RE.test(line) || BUN_PASS_RE.test(line));
17093
+ if (!failed && !passed) continue;
17094
+ const targets = mentioned.length > 0 ? mentioned : current ? [current] : [];
17095
+ if (passed && targets.length > 0) sawFilePass = true;
17096
+ const reason = line.slice(0, 300);
17097
+ for (const file of targets) remember(found, file, failed ? "failed" : "passed", reason);
17098
+ }
17099
+ return { found, sawFilePass };
17100
+ }
17101
+ function remember(map, file, status, reason) {
17102
+ const prev = map.get(file);
17103
+ if (prev?.status === "failed") return;
17104
+ if (status === "failed") map.set(file, { status, reason });
17105
+ else if (!prev) map.set(file, { status: "passed" });
17106
+ }
17107
+ function buildNeedles(testFiles) {
17108
+ const out = [];
17109
+ for (const file of testFiles) {
17110
+ out.push({ file, needle: file });
17111
+ const parts = file.split("/");
17112
+ for (let i = 1; i < parts.length; i++) {
17113
+ const needle = parts.slice(i).join("/");
17114
+ const owners = testFiles.filter((f) => f === needle || f.endsWith(`/${needle}`));
17115
+ if (owners.length === 1 && owners[0] === file) out.push({ file, needle });
17116
+ }
17117
+ }
17118
+ out.sort((a, b) => b.needle.length - a.needle.length);
17119
+ return out;
17120
+ }
17121
+ function filesOnLine(line, index) {
17122
+ const seen = /* @__PURE__ */ new Set();
17123
+ const out = [];
17124
+ for (const item of index) {
17125
+ if (seen.has(item.file)) continue;
17126
+ if (!lineMentions(line, item.needle)) continue;
17127
+ seen.add(item.file);
17128
+ out.push(item.file);
17129
+ }
17130
+ return out;
17131
+ }
17132
+ function lineMentions(line, file) {
17133
+ let from = 0;
17134
+ while (from < line.length) {
17135
+ const at = line.indexOf(file, from);
17136
+ if (at < 0) return false;
17137
+ const before = at === 0 ? "" : line[at - 1] ?? "";
17138
+ const after = line[at + file.length] ?? "";
17139
+ if (boundaryBefore(before) && boundaryAfter(after)) return true;
17140
+ from = at + file.length;
17141
+ }
17142
+ return false;
17143
+ }
17144
+ function boundaryBefore(ch) {
17145
+ return ch === "" || /[\s"'`(<:\[]/.test(ch);
17146
+ }
17147
+ function boundaryAfter(ch) {
17148
+ return ch === "" || ch === ":" || /[\s"'`):,\]]/.test(ch);
17149
+ }
17150
+ function parseJsonReport(text) {
17151
+ const trimmed = text.trim();
17152
+ if (!trimmed.startsWith("{")) return null;
17153
+ try {
17154
+ return reportsFromJson(JSON.parse(trimmed));
17155
+ } catch {
17156
+ return null;
17157
+ }
17158
+ }
17159
+ function reportsFromJson(value) {
17160
+ if (!value || typeof value !== "object") return null;
17161
+ const rec = value;
17162
+ if (Array.isArray(rec.testResults)) {
17163
+ const out = [];
17164
+ for (const item of rec.testResults) {
17165
+ if (!item || typeof item !== "object") continue;
17166
+ const row = item;
17167
+ const name = typeof row.name === "string" ? row.name : "";
17168
+ if (!name) continue;
17169
+ const message = typeof row.message === "string" ? row.message.trim() : "";
17170
+ const failure = firstAssertionFailure(row);
17171
+ const reason = (message || failure).slice(0, 300);
17172
+ out.push({
17173
+ file: name,
17174
+ status: mapStatus(typeof row.status === "string" ? row.status : ""),
17175
+ ...reason ? { reason } : {}
17176
+ });
17177
+ }
17178
+ return out.length > 0 ? out : null;
17179
+ }
17180
+ if (Array.isArray(rec.suites)) {
17181
+ const out = [];
17182
+ flattenPlaywright(rec.suites, out);
17183
+ return out.length > 0 ? out : null;
17184
+ }
17185
+ return null;
17186
+ }
17187
+ function firstAssertionFailure(row) {
17188
+ if (!Array.isArray(row.assertionResults)) return "";
17189
+ for (const item of row.assertionResults) {
17190
+ if (!item || typeof item !== "object") continue;
17191
+ const messages = item.failureMessages;
17192
+ if (!Array.isArray(messages)) continue;
17193
+ const text = messages.find((m) => typeof m === "string" && m.trim().length > 0);
17194
+ if (typeof text === "string") return text.trim().split("\n")[0] ?? "";
17195
+ }
17196
+ return "";
17197
+ }
17198
+ function flattenPlaywright(suites, out) {
17199
+ for (const item of suites) {
17200
+ if (!item || typeof item !== "object") continue;
17201
+ const suite = item;
17202
+ const file = typeof suite.file === "string" ? suite.file : "";
17203
+ if (file && Array.isArray(suite.specs)) {
17204
+ const verdict = playwrightSpecs(suite.specs);
17205
+ out.push(verdict.reason ? { file, status: verdict.status, reason: verdict.reason } : { file, status: verdict.status });
17206
+ }
17207
+ if (Array.isArray(suite.suites)) flattenPlaywright(suite.suites, out);
17208
+ }
17209
+ }
17210
+ function playwrightSpecs(specs) {
17211
+ let failed = false;
17212
+ let passed = false;
17213
+ let reason = "";
17214
+ for (const item of specs) {
17215
+ if (!item || typeof item !== "object") continue;
17216
+ const spec = item;
17217
+ if (spec.ok === false) failed = true;
17218
+ const tests = Array.isArray(spec.tests) ? spec.tests : [];
17219
+ for (const test of tests) {
17220
+ if (!test || typeof test !== "object") continue;
17221
+ const results = test.results;
17222
+ if (!Array.isArray(results)) continue;
17223
+ for (const result of results) {
17224
+ if (!result || typeof result !== "object") continue;
17225
+ const status = String(result.status ?? "");
17226
+ if (status === "failed" || status === "timedOut" || status === "interrupted") {
17227
+ failed = true;
17228
+ if (!reason) {
17229
+ const err = result.error;
17230
+ if (err && typeof err === "object" && typeof err.message === "string") {
17231
+ reason = String(err.message);
17232
+ } else reason = status;
17233
+ }
17234
+ } else if (status === "passed" || status === "expected") passed = true;
17235
+ }
17236
+ }
17237
+ }
17238
+ if (failed) return reason ? { status: "failed", reason: reason.slice(0, 300) } : { status: "failed" };
17239
+ if (passed) return { status: "passed" };
17240
+ return { status: "not-run", reason: "\u0442\u0435\u0441\u0442\u044B \u0444\u0430\u0439\u043B\u0430 \u043F\u0440\u043E\u043F\u0443\u0449\u0435\u043D\u044B" };
17241
+ }
17242
+ function mapStatus(status) {
17243
+ const s = status.toLowerCase();
17244
+ if (s === "failed" || s === "fail" || s === "timedout" || s === "interrupted") return "failed";
17245
+ if (s === "passed" || s === "pass" || s === "success" || s === "expected") return "passed";
17246
+ return "not-run";
17247
+ }
17248
+ function resolveReportedPath(reported, testFiles, repoRoot2) {
17249
+ let p = normalizePath2(reported.trim());
17250
+ if (p.startsWith("file://")) p = p.slice("file://".length);
17251
+ const root = normalizePath2(repoRoot2).replace(/\/$/, "");
17252
+ if (root && (p === root || p.startsWith(`${root}/`))) p = p.slice(root.length + 1);
17253
+ if (testFiles.includes(p)) return p;
17254
+ const byAbsolute = testFiles.filter((f) => p === f || p.endsWith(`/${f}`));
17255
+ if (byAbsolute.length === 1) return byAbsolute[0] ?? null;
17256
+ const bySuffix = testFiles.filter((f) => f === p || f.endsWith(`/${p}`));
17257
+ if (bySuffix.length === 1) return bySuffix[0] ?? null;
17258
+ return null;
17259
+ }
17260
+ function reportFileFromOutput(output, cwd) {
17261
+ const match = REPORT_PATH_RE.exec(output);
17262
+ const raw = match?.[1]?.trim();
17263
+ if (!raw) return null;
17264
+ const abs = isAbsolute6(raw) ? raw : join36(cwd, raw);
17265
+ if (!isInside(cwd, abs)) return null;
17266
+ return abs;
17267
+ }
17268
+ function isInside(parent, child) {
17269
+ let root;
17270
+ let target;
17271
+ try {
17272
+ root = realpathSync3(parent);
17273
+ target = realpathSync3(child);
17274
+ } catch {
17275
+ return false;
17276
+ }
17277
+ return target === root || target.startsWith(`${root}${sep4}`);
17278
+ }
17279
+ function prestartReason(output) {
17280
+ if (!output) return null;
17281
+ for (const rule of PRESTART_RULES) {
17282
+ if (!rule.re.test(output)) continue;
17283
+ const line = output.split("\n").map((l) => l.trim()).find((l) => rule.re.test(l));
17284
+ return line ? `${rule.label}: ${line.slice(0, 300)}` : rule.label;
17285
+ }
17286
+ return null;
17287
+ }
17288
+ function combineFull(stdout, stderr) {
17289
+ return [stdout, stderr].map((s) => s.replace(/\s+$/u, "")).filter((s) => s.length > 0).join("\n");
17290
+ }
17291
+ function clipTail(text) {
17292
+ if (text.length <= MAX_OUTPUT_CHARS) return text;
17293
+ 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
17294
+ ${text.slice(-MAX_OUTPUT_CHARS)}`;
17295
+ }
17296
+ function stripAnsi(text) {
17297
+ return text.replace(ANSI_RE, "");
17298
+ }
17299
+ function cleanReason(reason, fallback) {
17300
+ const text = reason?.trim();
17301
+ return (text ? text : fallback).slice(0, 500);
17302
+ }
17303
+ function normalizePath2(path) {
17304
+ return path.replaceAll("\\", "/");
17305
+ }
17306
+ function isSnapshot(path) {
17307
+ const parts = path.split("/");
17308
+ const base3 = parts[parts.length - 1] ?? path;
17309
+ if (base3.endsWith(".snap")) return true;
17310
+ return parts.some((seg) => SNAPSHOT_DIR_RE.test(seg) || SNAPSHOT_SUFFIX_RE.test(seg));
17311
+ }
17312
+ function uniq(items) {
17313
+ const seen = /* @__PURE__ */ new Set();
17314
+ const out = [];
17315
+ for (const item of items) {
17316
+ if (seen.has(item)) continue;
17317
+ seen.add(item);
17318
+ out.push(item);
17319
+ }
17320
+ return out;
17321
+ }
17322
+ function chunks(items, size) {
17323
+ const out = [];
17324
+ for (let i = 0; i < items.length; i += size) out.push(items.slice(i, i + size));
17325
+ return out;
17326
+ }
17327
+ async function git(cwd, args, call = {}) {
17328
+ const prefix = [];
17329
+ if (call.hooksPath) prefix.push("-c", `core.hooksPath=${call.hooksPath.replaceAll("\\", "/")}`);
17330
+ const options = {
17331
+ reject: false,
17332
+ timeout: call.timeoutMs ?? GIT_TIMEOUT_MS,
17333
+ windowsHide: true,
17334
+ env: { ...process.env, GIT_TERMINAL_PROMPT: "0" }
17335
+ };
17336
+ try {
17337
+ const res = await execa2("git", ["-C", cwd, ...prefix, ...args], call.signal ? { ...options, cancelSignal: call.signal } : options);
17338
+ return {
17339
+ stdout: res.stdout ?? "",
17340
+ stderr: res.stderr ?? "",
17341
+ exitCode: typeof res.exitCode === "number" ? res.exitCode : 1
17342
+ };
17343
+ } catch (e) {
17344
+ if (call.signal?.aborted) throw new GateTimeout();
17345
+ const msg = e instanceof Error ? e.message : String(e);
17346
+ throw new Error(`git ${args.join(" ")} \u0432 ${cwd} \u043D\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043B\u0441\u044F: ${msg}`);
17347
+ }
17348
+ }
17349
+ async function gitOk(cwd, args, call) {
17350
+ const res = await git(cwd, args, call);
17351
+ if (res.exitCode !== 0) {
17352
+ const detail = (res.stderr || res.stdout).trim().split("\n")[0] ?? "";
17353
+ throw new Error(`git ${args.join(" ")} \u043D\u0435 \u043F\u0440\u043E\u0448\u0451\u043B (\u043A\u043E\u0434 ${res.exitCode})${detail ? `: ${detail}` : ""}`);
17354
+ }
17355
+ return res.stdout;
17356
+ }
17357
+ function ownerAlive(dir) {
17358
+ try {
17359
+ const pid = Number(readFileSync26(join36(dir, "owner.pid"), "utf8").trim());
17360
+ if (!Number.isInteger(pid) || pid <= 0) return false;
17361
+ process.kill(pid, 0);
17362
+ return true;
17363
+ } catch (e) {
17364
+ return e.code === "EPERM";
17365
+ }
17366
+ }
17367
+ async function sweepOrphans2(exclude) {
17368
+ let names;
17369
+ try {
17370
+ names = readdirSync18(tmpdir2());
17371
+ } catch {
17372
+ return;
17373
+ }
17374
+ const skip = exclude ? safeRealpath(exclude) : null;
17375
+ for (const name of names) {
17376
+ if (!name.startsWith(COPY_PREFIX)) continue;
17377
+ const dir = join36(tmpdir2(), name);
17378
+ let st;
17379
+ try {
17380
+ st = lstatSync2(dir);
17381
+ } catch {
17382
+ continue;
17383
+ }
17384
+ if (st.isSymbolicLink() || !st.isDirectory()) continue;
17385
+ if (st.uid !== process.getuid?.()) continue;
17386
+ const real = safeRealpath(dir);
17387
+ if (!real || skip && real === skip) continue;
17388
+ if (ownerAlive(dir)) continue;
17389
+ if (!existsSync18(join36(dir, "owner.pid"))) {
17390
+ const age = Date.now() - safeMtime(dir);
17391
+ if (age < ORPHAN_FRESH_MS) continue;
17392
+ }
17393
+ try {
17394
+ await forceRemoveCopy(dir, null);
17395
+ } catch {
17396
+ }
17397
+ }
17398
+ }
17399
+ function safeRealpath(path) {
17400
+ try {
17401
+ return realpathSync3(path);
17402
+ } catch {
17403
+ return null;
17404
+ }
17405
+ }
17406
+ function safeMtime(path) {
17407
+ try {
17408
+ return statSync16(path).mtimeMs;
17409
+ } catch {
17410
+ return 0;
17411
+ }
17412
+ }
17413
+ function repoFromGitFile(wt) {
17414
+ try {
17415
+ const text = readFileSync26(join36(wt, ".git"), "utf8");
17416
+ const line = text.split("\n").find((l) => l.startsWith("gitdir:"));
17417
+ if (!line) return null;
17418
+ const gitdir = line.slice("gitdir:".length).trim();
17419
+ const marker = "/.git/worktrees/";
17420
+ const at = gitdir.lastIndexOf(marker);
17421
+ if (at < 0) return null;
17422
+ return gitdir.slice(0, at);
17423
+ } catch {
17424
+ return null;
17425
+ }
17426
+ }
17427
+ async function forceRemoveCopy(dir, repo) {
17428
+ const named = join36(dir, basename6(dir));
17429
+ const legacy = !existsSync18(named);
17430
+ const wt = legacy ? join36(dir, "wt") : named;
17431
+ const hooks = join36(dir, "hooks");
17432
+ const from = repo ?? (existsSync18(wt) ? repoFromGitFile(wt) : null);
17433
+ if (existsSync18(wt)) {
17434
+ try {
17435
+ await cleanupWorktreeProcesses(wt, legacy ? { containers: "keep" } : {});
17436
+ } catch {
17437
+ }
17438
+ if (from) {
17439
+ if (!existsSync18(hooks)) mkdirSync13(hooks, { recursive: true });
17440
+ await git(from, ["worktree", "remove", "-f", "-f", wt], { hooksPath: hooks });
17441
+ }
17442
+ }
17443
+ const call = existsSync18(hooks) ? { hooksPath: hooks } : {};
17444
+ if (from) {
17445
+ try {
17446
+ await git(from, ["worktree", "prune"], call);
17447
+ } catch {
17448
+ }
17449
+ }
17450
+ try {
17451
+ await rm3(dir, { recursive: true, force: true });
17452
+ } catch {
17453
+ try {
17454
+ rmSync4(dir, { recursive: true, force: true });
17455
+ } catch {
17456
+ }
17457
+ }
17458
+ }
17459
+ async function destroyCopy(worktree, copy, parent, hooks) {
17460
+ if (existsSync18(copy)) {
17461
+ try {
17462
+ await cleanupWorktreeProcesses(copy);
17463
+ } catch {
17464
+ }
17465
+ }
17466
+ if (hooks && !existsSync18(hooks)) {
17467
+ try {
17468
+ mkdirSync13(hooks, { recursive: true });
17469
+ } catch {
17470
+ }
17471
+ }
17472
+ const call = hooks && existsSync18(hooks) ? { hooksPath: hooks } : {};
17473
+ try {
17474
+ await git(worktree, ["worktree", "remove", "-f", "-f", copy], call);
17475
+ } catch {
17476
+ }
17477
+ try {
17478
+ await git(worktree, ["worktree", "prune"], call);
17479
+ } catch {
17480
+ }
17481
+ try {
17482
+ await rm3(parent, { recursive: true, force: true });
17483
+ } catch {
17484
+ try {
17485
+ rmSync4(parent, { recursive: true, force: true });
17486
+ } catch {
17487
+ }
17488
+ }
17489
+ }
17490
+
17491
+ // src/doneMutation.ts
17492
+ import { copyFileSync as copyFileSync6, existsSync as existsSync19, mkdirSync as mkdirSync14 } from "fs";
17493
+ import { dirname as dirname6, isAbsolute as isAbsolute7, join as join37, relative as relative3 } from "path";
17494
+ import { execa as execa3 } from "execa";
17495
+ var MUTATION_REFUSAL_LIMIT = 3;
17496
+ var MUTATION_GATE_TIMEOUT_MS = 15 * 6e4;
17497
+ 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";
17498
+ 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";
17499
+ 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";
17500
+ 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";
17501
+ 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";
17502
+ function mutationGateStartEvent(testCount) {
17503
+ 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)`;
17504
+ }
17505
+ var OUTPUT_TAIL = 12e3;
17506
+ function mutationGateApplies(run2) {
17507
+ if (!run2) return true;
17508
+ if (run2.resolves_run_id != null) return false;
17509
+ if (needsFixIteration(run2)) return false;
17510
+ return true;
17511
+ }
17512
+ function mutationBaseBranch(raw) {
17513
+ let name = (raw ?? "").trim();
17514
+ if (name.startsWith("origin/")) name = name.slice("origin/".length).trim();
17515
+ if (!name || name === "HEAD") return "main";
17516
+ return name;
17517
+ }
17518
+ function countMutationRefusals(events) {
17519
+ return events.filter((e) => (e.text ?? "").includes(MUTATION_REFUSAL_MARK)).length;
17520
+ }
17521
+ var TEST_TOOL_RE = /\b(?:vitest|jest|pytest|py\.test|phpunit|rspec|mocha|ava|playwright|cypress|ctest)\b/i;
17522
+ 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;
17523
+ var TEST_WORD_RE = /\b(?:tests?|specs?)\b/i;
17524
+ function isTestCommand(command) {
17525
+ const text = command.trim();
17526
+ if (!text) return false;
17527
+ return TEST_TOOL_RE.test(text) || TEST_RUNNER_RE.test(text) || TEST_WORD_RE.test(text);
17528
+ }
17529
+ function verifyLineDropped(command) {
17530
+ if (/<[^>\n]+>|&lt;[^&\n]*&gt;/.test(command)) return true;
17531
+ if (/\$\(/.test(command)) return true;
17532
+ if (/(?:^|[;&|]\s*)\bcd\b/.test(command)) return true;
17533
+ if (/\bgh\b/.test(command)) return true;
17534
+ if (/\bdocker\b/.test(command)) return true;
17535
+ if (/\b(?:test-db-up|docker-compose|compose|migrate)\b/.test(command)) return true;
17536
+ return false;
17537
+ }
17538
+ var NARROW_TOOL_RE = /\b(?:vitest|jest|pytest|py\.test)\b/i;
17539
+ function selectVerifyCommand(commands) {
17540
+ if (!commands?.length) return null;
17541
+ const lines = commands.map((c) => c.trim()).filter((c) => c.length > 0);
17542
+ if (lines.length === 0) return null;
17543
+ const narrow = lines.filter((line) => !verifyLineDropped(line) && NARROW_TOOL_RE.test(line));
17544
+ if (narrow[0]) return narrow[0];
17545
+ const sawTest = lines.some((line) => isTestCommand(line) || verifyLineDropped(line));
17546
+ return sawTest ? { kind: "unscoped" } : null;
17547
+ }
17548
+ function shellQuote(value) {
17549
+ return `'${value.replace(/'/g, `'\\''`)}'`;
17550
+ }
17551
+ function appendMissingFiles(command, files) {
17552
+ const missing = files.filter((f) => f.length > 0 && !command.includes(f));
17553
+ if (missing.length === 0) return command;
17554
+ return `${command} ${missing.map(shellQuote).join(" ")}`;
17555
+ }
17556
+ function decorateOne(command, ctx) {
17557
+ const report = shellQuote(ctx.reportFile);
17558
+ const hasReport = /--outputFile(?:\s|=)/.test(command);
17559
+ if (/\bvitest\b/.test(command)) {
17560
+ const withReport = hasReport ? command : `${command} --reporter=json --outputFile=${report}`;
17561
+ return appendMissingFiles(withReport, ctx.testFiles);
17562
+ }
17563
+ if (/\bjest\b/.test(command)) {
17564
+ const withReport = hasReport ? command : `${command} --json --outputFile=${report}`;
17565
+ return appendMissingFiles(withReport, ctx.testFiles);
17566
+ }
17567
+ if (/\bpytest\b|\bpy\.test\b/.test(command)) return appendMissingFiles(command, ctx.testFiles);
17568
+ return command;
17569
+ }
17570
+ function decorateTestCommand(command, ctx) {
17571
+ return command.split(/\s*&&\s*/).map((part) => decorateOne(part.trim(), ctx)).filter((part) => part.length > 0).join(" && ");
17572
+ }
17573
+ function stripPnpmFilter(command) {
17574
+ return command.replace(/\s--filter(?:=|\s+)(?:'[^']*'|"[^"]*"|\S+)/g, "").replace(/[ \t]{2,}/g, " ").trim();
17575
+ }
17576
+ function nearestPackageDir(root, fileRel) {
17577
+ let dir = dirname6(join37(root, fileRel));
17578
+ for (; ; ) {
17579
+ const rel = relative3(root, dir);
17580
+ if (rel.startsWith("..") || isAbsolute7(rel)) return root;
17581
+ if (existsSync19(join37(dir, "package.json"))) return dir;
17582
+ if (rel === "") return root;
17583
+ const parent = dirname6(dir);
17584
+ if (parent === dir) return root;
17585
+ dir = parent;
17586
+ }
17587
+ }
17588
+ function scopeVerifyCommand(command, ctx) {
17589
+ const root = ctx.cwd;
17590
+ const first = ctx.testFiles.find((f) => f.length > 0);
17591
+ if (!first || !NARROW_TOOL_RE.test(command)) {
17592
+ return { command: decorateTestCommand(command, ctx), cwd: root };
17593
+ }
17594
+ const pkg = nearestPackageDir(root, first);
17595
+ const relFiles = ctx.testFiles.filter((f) => {
17596
+ const rel = relative3(pkg, join37(root, f));
17597
+ return rel.length > 0 && !rel.startsWith("..") && !isAbsolute7(rel);
17598
+ }).map((f) => relative3(pkg, join37(root, f)).replaceAll("\\", "/"));
17599
+ const scoped = pkg === root ? command : stripPnpmFilter(command);
17600
+ return { command: decorateTestCommand(scoped, { reportFile: ctx.reportFile, testFiles: relFiles }), cwd: pkg };
17601
+ }
17602
+ function asText(value) {
17603
+ return typeof value === "string" ? value : value == null ? "" : String(value);
17604
+ }
17605
+ async function copyIgnoredEnv(sourceWorktree, destRoot) {
17606
+ const res = await execa3("git", ["ls-files", "-oi", "--exclude-standard", "--directory", "-z"], {
17607
+ cwd: sourceWorktree,
17608
+ reject: false
17609
+ });
17610
+ if (typeof res.exitCode === "number" && res.exitCode !== 0) return;
17611
+ for (const rel of asText(res.stdout).split("\0")) {
17612
+ if (!rel) continue;
17613
+ const norm = rel.replaceAll("\\", "/");
17614
+ if (norm.split("/").includes("node_modules")) continue;
17615
+ const base3 = norm.split("/").pop() ?? "";
17616
+ if (!base3.startsWith(".env")) continue;
17617
+ const to = join37(destRoot, rel);
17618
+ mkdirSync14(dirname6(to), { recursive: true });
17619
+ try {
17620
+ copyFileSync6(join37(sourceWorktree, rel), to);
17621
+ } catch {
17622
+ }
17623
+ }
17624
+ }
17625
+ async function runVerifyCommand(command, ctx, prep = {}) {
17626
+ if (ctx.signal.aborted) {
17627
+ return { exitCode: null, stdout: "", stderr: "", started: false, reason: "\u043E\u0442\u043C\u0435\u043D\u0435\u043D\u043E" };
17628
+ }
17629
+ try {
17630
+ if (prep.sourceWorktree) await copyIgnoredEnv(prep.sourceWorktree, ctx.cwd);
17631
+ const prepared = await ensureWorktreeDeps(ctx.cwd, {
17632
+ override: prep.prepare ?? null,
17633
+ skipOptional: true,
17634
+ skipEnvCache: true
17635
+ });
17636
+ if (prepared.outcome === "failed" || prepared.outcome === "blocked") {
17637
+ const why = [...prepared.failed, ...prepared.blocked].join(", ") || prepared.outcome;
17638
+ 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}` };
17639
+ }
17640
+ } catch (e) {
17641
+ const why = e instanceof Error ? e.message : String(e);
17642
+ 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}` };
17643
+ }
17644
+ const scoped = scopeVerifyCommand(command, ctx);
17645
+ const env = { ...ctx.env };
17646
+ delete env.VITEST;
17647
+ delete env.VITEST_WORKER_ID;
17648
+ delete env.VITEST_POOL_ID;
17649
+ try {
17650
+ const res = await execa3(scoped.command, {
17651
+ shell: true,
17652
+ cwd: scoped.cwd,
17653
+ env,
17654
+ extendEnv: false,
17655
+ reject: false,
17656
+ cancelSignal: ctx.signal,
17657
+ maxBuffer: 50 * 1024 * 1024
17658
+ });
17659
+ const aborted = ctx.signal.aborted;
17660
+ return {
17661
+ exitCode: typeof res.exitCode === "number" ? res.exitCode : null,
17662
+ stdout: asText(res.stdout),
17663
+ stderr: asText(res.stderr),
17664
+ started: !aborted,
17665
+ ...aborted ? { reason: "\u043E\u0442\u043C\u0435\u043D\u0435\u043D\u043E" } : {}
17666
+ };
17667
+ } catch (e) {
17668
+ return {
17669
+ exitCode: null,
17670
+ stdout: "",
17671
+ stderr: e instanceof Error ? e.message : String(e),
17672
+ started: false,
17673
+ reason: ctx.signal.aborted ? "\u043E\u0442\u043C\u0435\u043D\u0435\u043D\u043E" : e instanceof Error ? e.message : String(e)
17674
+ };
17675
+ }
17676
+ }
17677
+ function clipTail2(text) {
17678
+ if (text.length <= OUTPUT_TAIL) return text;
17679
+ return `\u2026
17680
+ ${text.slice(-OUTPUT_TAIL)}`;
17681
+ }
17682
+ function mutationNotRunLine(notRun) {
17683
+ if (notRun.length === 0) return null;
17684
+ const parts = notRun.map((n) => `${n.file} \u2014 ${n.reason}`);
17685
+ 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("; ")}`;
17686
+ }
17687
+ function refusalText(result) {
17688
+ const files = result.stayedGreen.map((f) => `- ${f}`).join("\n");
17689
+ return [
17690
+ "\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.",
17691
+ "",
17692
+ "\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:",
17693
+ files,
17694
+ "",
17695
+ "\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.",
17696
+ "\u0421\u0435\u0441\u0441\u0438\u044F \u043F\u0440\u043E\u0434\u043E\u043B\u0436\u0430\u0435\u0442\u0441\u044F.",
17697
+ "",
17698
+ "\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):",
17699
+ clipTail2(result.output)
17700
+ ].join("\n");
17701
+ }
17702
+ function decideMutation(result, priorRefusals) {
17703
+ const notRunLine = mutationNotRunLine(result.notRun);
17704
+ if (result.testFiles.length === 0) {
17705
+ return {
17706
+ kind: "accept",
17707
+ 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"],
17708
+ summaryLine: null,
17709
+ note: ""
17710
+ };
17711
+ }
17712
+ if (result.reddened.length > 0) {
17713
+ return {
17714
+ kind: "accept",
17715
+ 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] : []],
17716
+ summaryLine: notRunLine,
17717
+ note: ""
17718
+ };
17719
+ }
17720
+ const wouldRefuse = result.stayedGreen.length > 0;
17721
+ if (wouldRefuse && priorRefusals >= MUTATION_REFUSAL_LIMIT) {
17722
+ return {
17723
+ kind: "accept",
17724
+ events: [MUTATION_CEILING_EVENT, ...notRunLine ? [notRunLine] : []],
17725
+ summaryLine: notRunLine,
17726
+ note: `
17727
+
17728
+ \u26A0\uFE0F ${MUTATION_CEILING_EVENT}`
17729
+ };
17730
+ }
17731
+ if (wouldRefuse) {
17732
+ return {
17733
+ kind: "refuse",
17734
+ text: refusalText(result),
17735
+ event: `${MUTATION_REFUSAL_MARK}: ${result.stayedGreen.join(", ")}`
17736
+ };
17737
+ }
17738
+ return {
17739
+ kind: "accept",
17740
+ events: notRunLine ? [notRunLine] : [],
17741
+ summaryLine: notRunLine,
17742
+ note: ""
17743
+ };
17744
+ }
17745
+ var UNCAUGHT_TEST_RE = /(?:^|\/)(?:[^/]*_test\.go|test_[^/]*\.py)$/;
17746
+ function uncaughtTestPaths(paths) {
17747
+ const out = [];
17748
+ for (const raw of paths) {
17749
+ const path = raw.replaceAll("\\", "/").replace(/^\.\//, "");
17750
+ if (UNCAUGHT_TEST_RE.test(path) && !out.includes(path)) out.push(path);
17751
+ }
17752
+ return out;
17753
+ }
17754
+ function uncaughtTestLine(paths) {
17755
+ 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`;
17756
+ }
17757
+ async function changedPathsForMutation(worktree, base3) {
17758
+ const res = await execa3("git", ["diff", "--name-only", "-z", `origin/${base3}...HEAD`], {
17759
+ cwd: worktree,
17760
+ reject: false,
17761
+ timeout: 3e4
17762
+ });
17763
+ if (typeof res.exitCode === "number" && res.exitCode !== 0) return [];
17764
+ return asText(res.stdout).split("\0").map((p) => p.trim()).filter((p) => p.length > 0);
17765
+ }
17766
+ function withUncaught(decision, missed) {
17767
+ if (missed.length === 0) return decision;
17768
+ const line = uncaughtTestLine(missed);
17769
+ if (decision.kind === "refuse") {
17770
+ return { ...decision, text: `${decision.text}
17771
+
17772
+ ${line}` };
17773
+ }
17774
+ const events = decision.events.filter((e) => !e.includes("\u043F\u0440\u043E\u0432\u0435\u0440\u044F\u0442\u044C \u043D\u0435\u0447\u0435\u0433\u043E"));
17775
+ events.unshift(line);
17776
+ const summaryLine = decision.summaryLine ? `${decision.summaryLine}
17777
+ ${line}` : line;
17778
+ return { ...decision, events, summaryLine };
17779
+ }
17780
+ function normDiffPath(raw) {
17781
+ return raw.replaceAll("\\", "/").replace(/^\.\//, "");
17782
+ }
17783
+ function mutationTestCount(paths) {
17784
+ let n = 0;
17785
+ for (const raw of paths) {
17786
+ const path = normDiffPath(raw);
17787
+ if (!path || isMutationSkippedPath(path)) continue;
17788
+ if (isMutationTestFile(path)) n += 1;
17789
+ }
17790
+ return n;
17791
+ }
17792
+ function diffIsTestsOnly(paths) {
17793
+ if (mutationTestCount(paths) === 0) return false;
17794
+ for (const raw of paths) {
17795
+ const path = normDiffPath(raw);
17796
+ if (!path || isMutationSkippedPath(path) || isMutationTestFile(path)) continue;
17797
+ return false;
17798
+ }
17799
+ return true;
17800
+ }
17801
+ async function diffNames(input, base3) {
17802
+ try {
17803
+ return input.changedPaths ? await input.changedPaths() : await changedPathsForMutation(input.worktree, base3);
17804
+ } catch {
17805
+ return [];
17806
+ }
17807
+ }
17808
+ async function gateDoneMutation(input) {
17809
+ if (!mutationGateApplies(input.run)) return { kind: "skip" };
17810
+ let loaded;
17811
+ try {
17812
+ loaded = await input.loadCommand();
17813
+ } catch (e) {
17814
+ const why = e instanceof Error ? e.message : String(e);
17815
+ return { kind: "accept", events: [`${MUTATION_UNVERIFIED_EVENT} (${why})`], summaryLine: null, note: "" };
17816
+ }
17817
+ if (loaded && typeof loaded === "object") {
17818
+ return { kind: "accept", events: [MUTATION_UNSCOPED_EVENT], summaryLine: null, note: "" };
17819
+ }
17820
+ const command = loaded;
17821
+ if (!command) {
17822
+ return { kind: "accept", events: [MUTATION_UNVERIFIED_EVENT], summaryLine: null, note: "" };
17823
+ }
17824
+ const base3 = mutationBaseBranch(input.run?.base_branch);
17825
+ const names = await diffNames(input, base3);
17826
+ if (diffIsTestsOnly(names)) {
17827
+ return { kind: "accept", events: [MUTATION_TESTS_ONLY_EVENT], summaryLine: null, note: "" };
17828
+ }
17829
+ if (input.signal?.aborted) return { kind: "cancelled" };
17830
+ try {
17831
+ await input.emit?.(mutationGateStartEvent(mutationTestCount(names)));
17832
+ const result = await input.runGate({
17833
+ worktree: input.worktree,
17834
+ base: base3,
17835
+ command,
17836
+ ...input.signal ? { signal: input.signal } : {}
17837
+ });
17838
+ if (input.signal?.aborted) return { kind: "cancelled" };
17839
+ const decision = decideMutation(result, countMutationRefusals(input.events));
17840
+ return withUncaught(decision, uncaughtTestPaths(names));
17841
+ } catch (e) {
17842
+ if (input.signal?.aborted) return { kind: "cancelled" };
17843
+ const why = e instanceof Error ? e.message : String(e);
17844
+ return {
17845
+ kind: "accept",
17846
+ 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`],
17847
+ summaryLine: null,
17848
+ note: ""
17849
+ };
17850
+ }
17851
+ }
17852
+
17853
+ // src/droneServer.ts
16549
17854
  init_src();
17855
+ var mutationGateInFlight = /* @__PURE__ */ new Set();
17856
+ function mutationFlightKey(runId) {
17857
+ return runId == null ? "run:none" : `run:${runId}`;
17858
+ }
16550
17859
  function readTaskFailureInstruction(slug, failure) {
16551
17860
  const why = describeToolFailure(failure);
16552
17861
  if (TOOL_FAILURE_RETRIABLE[failure.code]) {
@@ -17039,7 +18348,7 @@ ${failText}` : failText }],
17039
18348
  "\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
18349
  )
17041
18350
  },
17042
- guard(async ({ pr_url, verdict, summary, screenshots, rules, rule_verdicts, zone_notes, zone_notes_used }) => {
18351
+ guard(async ({ pr_url, verdict, summary, screenshots, rules, rule_verdicts, zone_notes, zone_notes_used }, extra) => {
17043
18352
  const run2 = await store.myRun();
17044
18353
  let repoFullNameCache = null;
17045
18354
  const repoFullNameOnce = () => repoFullNameCache ??= remoteRepoFullName(opts.worktree ?? process.cwd()).catch(() => null);
@@ -17356,6 +18665,80 @@ ${report}${shots.warning}`,
17356
18665
  isError: true
17357
18666
  };
17358
18667
  }
18668
+ let reportBody = report;
18669
+ let mutationNote = "";
18670
+ if (mutationGateApplies(run2)) {
18671
+ const flightKey = mutationFlightKey(run2?.id);
18672
+ if (extra.signal.aborted) {
18673
+ return { content: [{ type: "text", text: "\u043E\u0442\u043C\u0435\u043D\u0435\u043D\u043E" }], isError: true };
18674
+ }
18675
+ if (mutationGateInFlight.has(flightKey)) {
18676
+ return { content: [{ type: "text", text: "\u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0430 \u0443\u0436\u0435 \u0438\u0434\u0451\u0442" }], isError: true };
18677
+ }
18678
+ mutationGateInFlight.add(flightKey);
18679
+ try {
18680
+ const priorEvents = await store.events(null).catch(() => []);
18681
+ const worktree = opts.worktree ?? process.cwd();
18682
+ const loadPrepare = async () => {
18683
+ try {
18684
+ if (opts.repoPrepare) return await opts.repoPrepare();
18685
+ const read = opts.taskless?.repoPrepare;
18686
+ if (!read) return null;
18687
+ const repo = await remoteRepoFullName(worktree).catch(() => null);
18688
+ if (!repo) return null;
18689
+ const slug = opts.expectedTaskSlug ?? run2?.task_slug;
18690
+ return await read(repo, slug || void 0);
18691
+ } catch {
18692
+ return null;
18693
+ }
18694
+ };
18695
+ const outcome = await gateDoneMutation({
18696
+ run: run2,
18697
+ worktree,
18698
+ events: priorEvents,
18699
+ signal: extra.signal,
18700
+ emit: (event) => store.addEvent(null, "step", event),
18701
+ loadCommand: async () => {
18702
+ if (opts.repoVerify) return opts.repoVerify();
18703
+ const read = opts.taskless?.repoVerifyCommands;
18704
+ if (!read) return null;
18705
+ const repo = await remoteRepoFullName(worktree).catch(() => null);
18706
+ if (!repo) return null;
18707
+ const slug = opts.expectedTaskSlug ?? run2?.task_slug;
18708
+ const commands = await read(repo, slug || void 0).catch(() => null);
18709
+ return selectVerifyCommand(commands);
18710
+ },
18711
+ runGate: async (input) => {
18712
+ if (opts.mutationGate) return opts.mutationGate(input);
18713
+ const prepare = await loadPrepare();
18714
+ return runMutationGate({
18715
+ worktree: input.worktree,
18716
+ base: input.base,
18717
+ timeoutMs: MUTATION_GATE_TIMEOUT_MS,
18718
+ // exactOptionalPropertyTypes: signal есть только когда вызывающий его передал.
18719
+ ...input.signal ? { signal: input.signal } : {},
18720
+ runTests: (ctx) => runVerifyCommand(input.command, ctx, { sourceWorktree: input.worktree, prepare })
18721
+ });
18722
+ }
18723
+ });
18724
+ if (outcome.kind === "cancelled" || extra.signal.aborted) {
18725
+ return { content: [{ type: "text", text: "\u043E\u0442\u043C\u0435\u043D\u0435\u043D\u043E" }], isError: true };
18726
+ }
18727
+ if (outcome.kind === "refuse") {
18728
+ await store.addEvent(null, "step", outcome.event);
18729
+ return { content: [{ type: "text", text: outcome.text }], isError: true };
18730
+ }
18731
+ if (outcome.kind === "accept") {
18732
+ for (const ev of outcome.events) await store.addEvent(null, "step", ev);
18733
+ if (outcome.summaryLine) reportBody = `${report}
18734
+
18735
+ ${outcome.summaryLine}`;
18736
+ mutationNote = outcome.note;
18737
+ }
18738
+ } finally {
18739
+ mutationGateInFlight.delete(flightKey);
18740
+ }
18741
+ }
17359
18742
  const shots = await uploadShots();
17360
18743
  const postReport = async (taskSlug, cycle) => {
17361
18744
  if (!opts.taskless) {
@@ -17367,7 +18750,7 @@ ${report}${shots.warning}`,
17367
18750
  taskSlug,
17368
18751
  `PR: ${pr_url}
17369
18752
 
17370
- ${report}${shots.warning}`,
18753
+ ${reportBody}${shots.warning}`,
17371
18754
  {
17372
18755
  swarmKind: "report",
17373
18756
  // TASWM-265: имени взять неоткуда — честная заглушка, а НЕ "?" и не номер прогона.
@@ -17405,7 +18788,7 @@ ${report}${shots.warning}`,
17405
18788
  await postReport(reportSlug(run2.task_slug), t.cycle ?? run2.review_cycle ?? 0);
17406
18789
  const rulesNote = await offerRules(reportSlug(run2.task_slug));
17407
18790
  const zoneNote = await zoneMemoryNote(reportSlug(run2.task_slug));
17408
- const tail2 = `${shotsNote(shots)}${rulesNote}${zoneNote}`;
18791
+ const tail2 = `${shotsNote(shots)}${rulesNote}${zoneNote}${mutationNote}`;
17409
18792
  if (t.isFixIteration) {
17410
18793
  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
18794
  }
@@ -17415,10 +18798,10 @@ ${report}${shots.warning}`,
17415
18798
  await store.addEvent(null, "pr_opened", pr_url);
17416
18799
  const fallbackSlug = reportSlug(void 0);
17417
18800
  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}`);
18801
+ 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
18802
  const fallbackRulesNote = await offerRules(fallbackSlug);
17420
18803
  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}` }] };
18804
+ return { content: [{ type: "text", text: `\u043F\u0440\u0438\u043D\u044F\u0442\u043E, \u0443\u0448\u043B\u043E \u043D\u0430 \u0440\u0435\u0432\u044C\u044E${shotsNote(shots)}${fallbackRulesNote}${fallbackZoneNote}${mutationNote}` }] };
17422
18805
  }
17423
18806
  await store.updateRun(null, { status: "done" });
17424
18807
  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 +20375,23 @@ async function prodClearMergeIntent(runId, deps = {}) {
18992
20375
  }
18993
20376
 
18994
20377
  // src/envGate.ts
18995
- import { existsSync as existsSync20 } from "fs";
18996
- import { join as join37 } from "path";
20378
+ import { existsSync as existsSync22 } from "fs";
20379
+ import { join as join39 } from "path";
18997
20380
  import { createConnection } from "net";
18998
- import { execa as execa2 } from "execa";
20381
+ import { execa as execa4 } from "execa";
18999
20382
 
19000
20383
  // src/platform.ts
19001
20384
  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";
20385
+ import { accessSync as accessSync2, constants as constants2, existsSync as existsSync21, readFileSync as readFileSync27, realpathSync as realpathSync4 } from "fs";
20386
+ import { delimiter as delimiter2, join as join38, posix as posix2, win32 } from "path";
19004
20387
  function resolveCommandPath(name, env = process.env, platform = process.platform) {
19005
- if (name.includes("/") || name.includes("\\")) return existsSync19(name) ? name : null;
20388
+ if (name.includes("/") || name.includes("\\")) return existsSync21(name) ? name : null;
19006
20389
  const dirs = (env.PATH ?? env.Path ?? "").split(delimiter2).filter(Boolean);
19007
20390
  const exts = platform === "win32" ? (env.PATHEXT ?? ".EXE;.CMD;.BAT").split(";").filter(Boolean) : [""];
19008
20391
  for (const dir of dirs) {
19009
20392
  for (const ext of exts) {
19010
- const candidate = join36(dir, name + ext);
19011
- if (existsSync19(candidate)) return candidate;
20393
+ const candidate = join38(dir, name + ext);
20394
+ if (existsSync21(candidate)) return candidate;
19012
20395
  }
19013
20396
  }
19014
20397
  return null;
@@ -19048,7 +20431,7 @@ function globalInstallCommand(pm, spec, prefix, platform = process.platform) {
19048
20431
  var UNIX_MARKER = "/lib/node_modules/@taskless-app/swarm";
19049
20432
  var WIN_MARKER = "/node_modules/@taskless-app/swarm";
19050
20433
  function resolveReal(entry, io) {
19051
- const realpath = io.realpath ?? realpathSync3;
20434
+ const realpath = io.realpath ?? realpathSync4;
19052
20435
  try {
19053
20436
  return realpath(entry);
19054
20437
  } catch {
@@ -19141,9 +20524,9 @@ function parseRequirements(lines) {
19141
20524
  out.push({ kind: "docker", raw });
19142
20525
  continue;
19143
20526
  }
19144
- const sep4 = raw.indexOf(":");
19145
- const prefix = sep4 === -1 ? "" : lower.slice(0, sep4);
19146
- const rest = sep4 === -1 ? "" : raw.slice(sep4 + 1).trim();
20527
+ const sep5 = raw.indexOf(":");
20528
+ const prefix = sep5 === -1 ? "" : lower.slice(0, sep5);
20529
+ const rest = sep5 === -1 ? "" : raw.slice(sep5 + 1).trim();
19147
20530
  if (!rest) {
19148
20531
  out.push({ kind: "unknown", raw });
19149
20532
  continue;
@@ -19177,8 +20560,8 @@ var COMPOSE_MARKERS = [
19177
20560
  "compose.yaml"
19178
20561
  ];
19179
20562
  function detectRequirements(repo, io = {}) {
19180
- const exists = io.exists ?? existsSync20;
19181
- const marker = COMPOSE_MARKERS.find((f) => exists(join37(repo, f)));
20563
+ const exists = io.exists ?? existsSync22;
20564
+ const marker = COMPOSE_MARKERS.find((f) => exists(join39(repo, f)));
19182
20565
  return marker ? [{ kind: "docker", raw: `docker (\u0434\u0435\u0442\u0435\u043A\u0442: ${marker})` }] : [];
19183
20566
  }
19184
20567
  function resolveRequirements(repo, declared, io = {}) {
@@ -19187,7 +20570,7 @@ function resolveRequirements(repo, declared, io = {}) {
19187
20570
  }
19188
20571
  async function probeDockerDaemon() {
19189
20572
  try {
19190
- const res = await execa2("docker", ["version", "--format", "{{.Server.Version}}"], {
20573
+ const res = await execa4("docker", ["version", "--format", "{{.Server.Version}}"], {
19191
20574
  timeout: PROBE_TIMEOUT_MS,
19192
20575
  reject: false
19193
20576
  });
@@ -19315,7 +20698,7 @@ function makeEnvGate(opts) {
19315
20698
  // src/web.ts
19316
20699
  init_src();
19317
20700
  import { randomBytes as randomBytes3 } from "crypto";
19318
- import { basename as basename6 } from "path";
20701
+ import { basename as basename7 } from "path";
19319
20702
  import { serve as serve2 } from "@hono/node-server";
19320
20703
  init_storm();
19321
20704
  init_swarmModels();
@@ -19559,7 +20942,7 @@ function timelineState(db, now = Date.now(), overmindLog = []) {
19559
20942
  id: r.id,
19560
20943
  name: r.name,
19561
20944
  slug: r.task_slug,
19562
- repo: basename6(r.repo || "") || "?",
20945
+ repo: basename7(r.repo || "") || "?",
19563
20946
  status: r.status,
19564
20947
  area: r.area,
19565
20948
  start: sqliteIso(r.created_at),
@@ -21005,21 +22388,21 @@ function closeWebServer(server) {
21005
22388
 
21006
22389
  // src/hostCommands.ts
21007
22390
  init_src();
21008
- import { readFileSync as readFileSync27, renameSync as renameSync10, writeFileSync as writeFileSync17 } from "fs";
21009
- import { join as join38 } from "path";
22391
+ import { readFileSync as readFileSync28, renameSync as renameSync10, writeFileSync as writeFileSync18 } from "fs";
22392
+ import { join as join40 } from "path";
21010
22393
  function hostCommandStatePath(home) {
21011
- return join38(home, "host-command.json");
22394
+ return join40(home, "host-command.json");
21012
22395
  }
21013
22396
  function readState(path) {
21014
22397
  try {
21015
- return JSON.parse(readFileSync27(path, "utf8"));
22398
+ return JSON.parse(readFileSync28(path, "utf8"));
21016
22399
  } catch {
21017
22400
  return {};
21018
22401
  }
21019
22402
  }
21020
22403
  function writeState(path, state) {
21021
22404
  try {
21022
- writeFileSync17(`${path}.tmp`, JSON.stringify(state));
22405
+ writeFileSync18(`${path}.tmp`, JSON.stringify(state));
21023
22406
  renameSync10(`${path}.tmp`, path);
21024
22407
  } catch {
21025
22408
  }
@@ -21182,20 +22565,20 @@ async function doRestart(cmd, opts, note) {
21182
22565
 
21183
22566
  // src/selfUpdate.ts
21184
22567
  init_git();
21185
- import { existsSync as existsSync21 } from "fs";
21186
- import { join as join39 } from "path";
22568
+ import { existsSync as existsSync23 } from "fs";
22569
+ import { join as join41 } from "path";
21187
22570
  import { $ as $6 } from "execa";
21188
22571
 
21189
22572
  // src/cliIo.ts
21190
22573
  import { createInterface } from "readline/promises";
21191
- import { execa as execa3 } from "execa";
22574
+ import { execa as execa5 } from "execa";
21192
22575
  function readCommandOutcome(result) {
21193
22576
  if (typeof result === "number") return { exitCode: result, output: "" };
21194
22577
  return { exitCode: result.exitCode, output: `${result.stdout ?? ""}
21195
22578
  ${result.stderr ?? ""}` };
21196
22579
  }
21197
22580
  async function execCaptured(command) {
21198
- const res = await execa3(command, {
22581
+ const res = await execa5(command, {
21199
22582
  shell: true,
21200
22583
  reject: false,
21201
22584
  stdout: ["pipe", "inherit"],
@@ -21216,7 +22599,7 @@ function tail(text, max = 400) {
21216
22599
  }
21217
22600
  async function runSelfUpdate(io) {
21218
22601
  const run2 = io.run ?? defaultRun;
21219
- const exists = io.exists ?? existsSync21;
22602
+ const exists = io.exists ?? existsSync23;
21220
22603
  const repo = io.repo;
21221
22604
  await io.onStep("fetch", "\u0442\u044F\u043D\u0443 \u0441\u0432\u0435\u0436\u0438\u0439 \u043A\u043E\u0434");
21222
22605
  const fetched = await run2("git", ["-C", repo, "fetch", "--quiet", "origin"], repo);
@@ -21245,7 +22628,7 @@ async function runSelfUpdate(io) {
21245
22628
  };
21246
22629
  }
21247
22630
  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"))) {
22631
+ if (!exists(join41(repo, "pnpm-lock.yaml"))) {
21249
22632
  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
22633
  }
21251
22634
  const installed2 = await run2("pnpm", ["install", "--frozen-lockfile"], repo);
@@ -21420,19 +22803,19 @@ async function fetchExternalStorm(url, opts = {}) {
21420
22803
  }
21421
22804
 
21422
22805
  // 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";
22806
+ import { existsSync as existsSync24, readFileSync as readFileSync29, renameSync as renameSync11, writeFileSync as writeFileSync19 } from "fs";
22807
+ import { join as join42 } from "path";
21425
22808
  var KEY_TTL_MS = 7 * 24 * 60 * 6e4;
21426
22809
  var MAX_RESOLVED = 200;
21427
22810
  function emptyState() {
21428
22811
  return { since: {}, lastFiredAt: {}, fires: {}, resolved: [], stopQuiet: null };
21429
22812
  }
21430
22813
  function anomalyStatePath(home) {
21431
- return join40(home, "anomaly-state.json");
22814
+ return join42(home, "anomaly-state.json");
21432
22815
  }
21433
22816
  function loadAnomalyState(home, now = Date.now(), io = {}) {
21434
- const exists = io.exists ?? existsSync22;
21435
- const readFile3 = io.readFile ?? ((p) => readFileSync28(p, "utf8"));
22817
+ const exists = io.exists ?? existsSync24;
22818
+ const readFile3 = io.readFile ?? ((p) => readFileSync29(p, "utf8"));
21436
22819
  const path = anomalyStatePath(home);
21437
22820
  if (!exists(path)) return emptyState();
21438
22821
  try {
@@ -21462,7 +22845,7 @@ function loadAnomalyState(home, now = Date.now(), io = {}) {
21462
22845
  function saveAnomalyState(home, state, io = {}) {
21463
22846
  const path = anomalyStatePath(home);
21464
22847
  const writeFile4 = io.writeFile ?? ((p, data) => {
21465
- writeFileSync18(`${p}.tmp`, data);
22848
+ writeFileSync19(`${p}.tmp`, data);
21466
22849
  renameSync11(`${p}.tmp`, p);
21467
22850
  });
21468
22851
  writeFile4(path, JSON.stringify(state, null, 2));
@@ -22647,7 +24030,7 @@ function dockerStandRules(prefix, homeDir = homedir10()) {
22647
24030
  }
22648
24031
  function promptStandRule(worktree, slug) {
22649
24032
  const raw = worktree && worktree.length > 0 ? worktree : slug;
22650
- const prefix = composeProjectPrefix(basename7(raw));
24033
+ const prefix = composeProjectPrefix(basename8(raw));
22651
24034
  return prefix ? dockerStandRules(prefix, homedir10()) : "";
22652
24035
  }
22653
24036
  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 +24247,10 @@ ${task.description}` : `\u0417\u0430\u0434\u0430\u0447\u0430 ${run2.task_slug} (
22864
24247
  }
22865
24248
  return parts.join("\n");
22866
24249
  }
22867
- var HERO_CHARTER_PATH = join41(dirname6(THIS_FILE), "..", "docs", "HERO.md");
24250
+ var HERO_CHARTER_PATH = join43(dirname7(THIS_FILE), "..", "docs", "HERO.md");
22868
24251
  function buildHeroPrompt(task, run2, taskContext, attachmentsBlock) {
22869
24252
  const name = run2.name || `#${run2.id}`;
22870
- const charter = readFileSync29(HERO_CHARTER_PATH, "utf8");
24253
+ const charter = readFileSync30(HERO_CHARTER_PATH, "utf8");
22871
24254
  const head = task ? `\u042D\u041F\u0418\u041A ${run2.task_slug}: ${task.title}
22872
24255
 
22873
24256
  ${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 +24310,9 @@ function ciTrustLine(prUrl, verifyMode, ciClosed = null) {
22927
24310
  }
22928
24311
  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
24312
  }
22930
- var REVIEW_SKILL_PATH = join41(bundledRoleDir("drone"), "skills", "taskless-review", "SKILL.md");
24313
+ var REVIEW_SKILL_PATH = join43(bundledRoleDir("drone"), "skills", "taskless-review", "SKILL.md");
22931
24314
  function reviewDefectClasses(skillPath = REVIEW_SKILL_PATH) {
22932
- const text = readFileSync29(skillPath, "utf8");
24315
+ const text = readFileSync30(skillPath, "utf8");
22933
24316
  const m = /^## Классы дефектов\n([\s\S]*?)(?=^## |(?![\s\S]))/m.exec(text);
22934
24317
  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
24318
  return `\u041A\u043B\u0430\u0441\u0441\u044B \u0434\u0435\u0444\u0435\u043A\u0442\u043E\u0432 (skill taskless-review):
@@ -23564,7 +24947,7 @@ async function wakeRun(deps, runId, opts = {}) {
23564
24947
  if (run2.status === "review" && run2.pr_url && !needsFixIteration(run2) && !stoppedForHuman) {
23565
24948
  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
24949
  }
23567
- const worktreeExists = deps.worktreeExists ?? existsSync23;
24950
+ const worktreeExists = deps.worktreeExists ?? existsSync25;
23568
24951
  const hasTranscript = deps.hasTranscript ?? executorHasSession;
23569
24952
  const wt = run2.worktree_path;
23570
24953
  const canContinue = !!wt && worktreeExists(wt) && hasTranscript(run2);
@@ -23711,9 +25094,9 @@ function repoHasCi(deps, run2) {
23711
25094
  function repoHasCiWorkflows(worktreePath, repo) {
23712
25095
  for (const base3 of [worktreePath, repo]) {
23713
25096
  if (!base3) continue;
23714
- const dir = join41(base3, ".github", "workflows");
25097
+ const dir = join43(base3, ".github", "workflows");
23715
25098
  try {
23716
- if (readdirSync18(dir).some((f) => f.endsWith(".yml") || f.endsWith(".yaml"))) return true;
25099
+ if (readdirSync19(dir).some((f) => f.endsWith(".yml") || f.endsWith(".yaml"))) return true;
23717
25100
  } catch {
23718
25101
  }
23719
25102
  }
@@ -23935,7 +25318,7 @@ async function wakeReviewerOnCiReady(deps, run2, over) {
23935
25318
  return true;
23936
25319
  }
23937
25320
  function worktreeAndTranscriptAlive(deps, run2) {
23938
- const exists = deps.worktreeExists ?? existsSync23;
25321
+ const exists = deps.worktreeExists ?? existsSync25;
23939
25322
  const transcript = deps.hasTranscript ?? executorHasSession;
23940
25323
  const wt = run2.worktree_path;
23941
25324
  return !!wt && exists(wt) && transcript(run2);
@@ -24366,7 +25749,7 @@ async function wakeAuthorOnChanges(deps, snapshot, now, droneCap) {
24366
25749
  }
24367
25750
  const wt = run2.worktree_path;
24368
25751
  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);
25752
+ const worktreeReady = !!wtPath && (deps.worktreeExists ?? existsSync25)(wtPath);
24370
25753
  if (!worktreeReady) {
24371
25754
  const why = await freshChangesWakeBlock(deps, run2, prUrl, now);
24372
25755
  if (why) return blockFix(run2, why);
@@ -24458,7 +25841,7 @@ async function zoneConflictFor(db, models, activeFiles, run2, repo, repoFallback
24458
25841
  activeFiles.prune(holders.map((r) => r.id));
24459
25842
  const fileExists = (p) => {
24460
25843
  try {
24461
- return statSync16(join41(repo, p), { throwIfNoEntry: false })?.isFile() ?? false;
25844
+ return statSync17(join43(repo, p), { throwIfNoEntry: false })?.isFile() ?? false;
24462
25845
  } catch {
24463
25846
  return false;
24464
25847
  }
@@ -24572,8 +25955,8 @@ async function fillSuggestedArea(deps, run2) {
24572
25955
  `\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
25956
  );
24574
25957
  }
24575
- function noteExhaustedDeps(deps, run2, verdicts) {
24576
- const exhausted = verdicts.filter((d) => d.outcome === "exhausted");
25958
+ function noteExhaustedDeps(deps, run2, verdicts2) {
25959
+ const exhausted = verdicts2.filter((d) => d.outcome === "exhausted");
24577
25960
  if (exhausted.length === 0) return;
24578
25961
  const already = new Set(
24579
25962
  deps.db.events(run2.id).filter((e) => e.kind === "dep_cleared").map((e) => e.text ?? "")
@@ -24909,7 +26292,7 @@ async function liftReturners(deps, returners, now, droneCap) {
24909
26292
  deps.returners?.delete(run2.id);
24910
26293
  continue;
24911
26294
  }
24912
- lifted = await wakeAuthorOnRedCi(deps, run2, now, entry.ci, deps.worktreeExists ?? existsSync23, deps.hasTranscript ?? executorHasSession, droneCap);
26295
+ lifted = await wakeAuthorOnRedCi(deps, run2, now, entry.ci, deps.worktreeExists ?? existsSync25, deps.hasTranscript ?? executorHasSession, droneCap);
24913
26296
  }
24914
26297
  if (lifted) deps.returners?.delete(run2.id);
24915
26298
  }
@@ -24934,7 +26317,7 @@ async function resumeWatchdogParked(deps, droneCap) {
24934
26317
  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
26318
  return;
24936
26319
  }
24937
- const worktreeExists = deps.worktreeExists ?? existsSync23;
26320
+ const worktreeExists = deps.worktreeExists ?? existsSync25;
24938
26321
  const hasTranscript = deps.hasTranscript ?? executorHasSession;
24939
26322
  const wt = candidate.worktree_path;
24940
26323
  const canContinue = !!wt && worktreeExists(wt) && hasTranscript(candidate);
@@ -25407,7 +26790,7 @@ async function buildReliefCostCandidatesFor(deps, now, droneCap) {
25407
26790
  if (deps.exclusiveProject && await deps.exclusiveProject(repo)) continue;
25408
26791
  } catch {
25409
26792
  }
25410
- exclusiveRepos.push(basename7(repo));
26793
+ exclusiveRepos.push(basename8(repo));
25411
26794
  }
25412
26795
  const otherHosts = [
25413
26796
  ...new Set(
@@ -25562,10 +26945,10 @@ async function checkerHeadSha(worktree) {
25562
26945
  return headSha(worktree);
25563
26946
  }
25564
26947
  function verdictEventPayload(text) {
25565
- const sep4 = text.startsWith(PICKUP_EVENT_PREFIX) ? "): " : ": ";
25566
- const at = text.indexOf(sep4);
26948
+ const sep5 = text.startsWith(PICKUP_EVENT_PREFIX) ? "): " : ": ";
26949
+ const at = text.indexOf(sep5);
25567
26950
  if (at < 0) return "";
25568
- return stripVerdictHead(text.slice(at + sep4.length).replace(/\s+\[[^\]]*\]\s*$/, "")).trim();
26951
+ return stripVerdictHead(text.slice(at + sep5.length).replace(/\s+\[[^\]]*\]\s*$/, "")).trim();
25569
26952
  }
25570
26953
  function isHeaderOnlyVerdict(text) {
25571
26954
  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 +26959,10 @@ var VERIFY_HEADER_LABELS = /* @__PURE__ */ new Set(["\u041D\u0410\u0428\u0401\u0
25576
26959
  function isVerifyHeaderOnly(text) {
25577
26960
  const pickup = text.startsWith(VERIFY_PICKUP_EVENT_PREFIX);
25578
26961
  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);
26962
+ const sep5 = pickup ? "): " : ": ";
26963
+ const at = text.indexOf(sep5);
25581
26964
  if (at < 0) return true;
25582
- const rest = stripVerdictHead(text.slice(at + sep4.length).replace(/\s+\[[^\]]*\]\s*$/, "")).trim();
26965
+ const rest = stripVerdictHead(text.slice(at + sep5.length).replace(/\s+\[[^\]]*\]\s*$/, "")).trim();
25583
26966
  return rest.length === 0 || VERIFY_HEADER_LABELS.has(rest);
25584
26967
  }
25585
26968
  function isClippedPickup(text) {
@@ -25947,7 +27330,7 @@ async function tickOnce(deps) {
25947
27330
  draftHeldThisTick.clear();
25948
27331
  fixBlockedThisTick.clear();
25949
27332
  resetGrokBalanceTick();
25950
- const worktreeExists = deps.worktreeExists ?? existsSync23;
27333
+ const worktreeExists = deps.worktreeExists ?? existsSync25;
25951
27334
  const hasTranscript = deps.hasTranscript ?? executorHasSession;
25952
27335
  deps.stepClock?.mark("0 \u0437\u0430\u043C\u0435\u0440 \u0445\u043E\u0441\u0442\u0430");
25953
27336
  deps.sampleHost?.();
@@ -25999,12 +27382,12 @@ async function tickOnce(deps) {
25999
27382
  }
26000
27383
  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
27384
  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;
27385
+ const rm4 = deps.repoMap;
27386
+ const sinceLast = rm4.lastAt == null ? Infinity : now - rm4.lastAt;
27387
+ if (sinceLast >= rm4.intervalMs) {
27388
+ rm4.lastAt = now;
26006
27389
  try {
26007
- await rm3.run();
27390
+ await rm4.run();
26008
27391
  } catch (e) {
26009
27392
  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
27393
  }
@@ -26984,7 +28367,7 @@ async function resolveConflict(deps, reviewRun) {
26984
28367
  model: reviewRun.model,
26985
28368
  review_model: reviewRun.review_model
26986
28369
  });
26987
- const wt = join41(deps.worktreesDir, basename7(repo), `${reviewRun.task_slug}-resolve-${resolver.id}`);
28370
+ const wt = join43(deps.worktreesDir, basename8(repo), `${reviewRun.task_slug}-resolve-${resolver.id}`);
26988
28371
  try {
26989
28372
  await deps.git.prepareDetachedWorktree(repo, branch, wt);
26990
28373
  await deps.git.setWorktreeIdentity(wt, resolver.name);
@@ -27065,7 +28448,7 @@ async function spawnReviewer(deps, reviewRun, files) {
27065
28448
  // (своей у ревьюера нет, TASWM-204), и коммент с вердиктом должен уехать именно туда.
27066
28449
  workspace_id: reviewRun.workspace_id
27067
28450
  });
27068
- const wt = join41(deps.worktreesDir, basename7(repo), `${reviewRun.task_slug}-review-${reviewer.id}`);
28451
+ const wt = join43(deps.worktreesDir, basename8(repo), `${reviewRun.task_slug}-review-${reviewer.id}`);
27069
28452
  try {
27070
28453
  await deps.git.prepareDetachedWorktree(repo, branch, wt);
27071
28454
  await deps.git.setWorktreeIdentity(wt, reviewer.name);
@@ -27148,7 +28531,7 @@ async function spawnVerifier(deps, verifiedRun, files) {
27148
28531
  // штамп цикла: фикс-итерацию проверяет свежий верификатор
27149
28532
  workspace_id: verifiedRun.workspace_id
27150
28533
  });
27151
- const wt = join41(deps.worktreesDir, basename7(repo), `${verifiedRun.task_slug}-verify-${verifier.id}`);
28534
+ const wt = join43(deps.worktreesDir, basename8(repo), `${verifiedRun.task_slug}-verify-${verifier.id}`);
27152
28535
  try {
27153
28536
  await deps.git.prepareDetachedWorktree(repo, branch, wt);
27154
28537
  await deps.git.setWorktreeIdentity(wt, verifier.name);
@@ -27263,7 +28646,7 @@ async function respawnRun(deps, run2, mode, nudge) {
27263
28646
  ]);
27264
28647
  const base3 = effectiveBaseBranch(run2.base_branch, projectBase);
27265
28648
  const runToSpawn = base3 && run2.base_branch !== base3 ? deps.db.updateRun(run2.id, { base_branch: base3 }) ?? run2 : run2;
27266
- if (!existsSync23(wt)) {
28649
+ if (!existsSync25(wt)) {
27267
28650
  const branch = runToSpawn.branch || runToSpawn.task_slug;
27268
28651
  const source = await addWorktree(repo, wt, branch, {
27269
28652
  ...base3 ? { base: await remoteBaseRef(repo, base3) } : {},
@@ -27308,7 +28691,7 @@ function worktreePathPatch(run2, wt) {
27308
28691
  return run2.worktree_path === wt ? {} : { worktree_path: wt };
27309
28692
  }
27310
28693
  async function syncCrashedOnStartup(deps) {
27311
- const worktreeExists = deps.worktreeExists ?? existsSync23;
28694
+ const worktreeExists = deps.worktreeExists ?? existsSync25;
27312
28695
  let orphaned = 0;
27313
28696
  let merged = 0;
27314
28697
  let requeued = 0;
@@ -27473,10 +28856,10 @@ async function migrateWorktreesAtStartup() {
27473
28856
  legacyDir: WORKTREES_LEGACY_DIR,
27474
28857
  targetDir: WORKTREES_DIR,
27475
28858
  envOverride: process.env.SWARM_WORKTREES || "",
27476
- exists: (d) => existsSync23(d),
28859
+ exists: (d) => existsSync25(d),
27477
28860
  isNonEmptyDir: (d) => {
27478
28861
  try {
27479
- return readdirSync18(d).length > 0;
28862
+ return readdirSync19(d).length > 0;
27480
28863
  } catch {
27481
28864
  return false;
27482
28865
  }
@@ -27488,7 +28871,7 @@ async function migrateWorktreesAtStartup() {
27488
28871
  });
27489
28872
  } catch (e) {
27490
28873
  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;
28874
+ return existsSync25(WORKTREES_DIR) ? WORKTREES_DIR : WORKTREES_LEGACY_DIR;
27492
28875
  }
27493
28876
  }
27494
28877
  async function reportWorkspaceAccess(tl, db) {
@@ -27525,7 +28908,7 @@ function sweepDaemonStands(opts) {
27525
28908
  worktreesDir,
27526
28909
  activeWorktreePaths: new Set(runsWithWorktree.filter((r) => !isTerminalStatus(r.status)).map((r) => r.worktree_path)),
27527
28910
  containerRunPrefixes: runsWithWorktree.map((r) => ({
27528
- prefix: composeProjectPrefix(basename7(r.worktree_path)),
28911
+ prefix: composeProjectPrefix(basename8(r.worktree_path)),
27529
28912
  active: !isTerminalStatus(r.status)
27530
28913
  })),
27531
28914
  ...opts.scan ? { scan: opts.scan } : {},
@@ -28253,7 +29636,7 @@ async function runDaemon(opts) {
28253
29636
  isDirty: (p) => worktreeDirty(p),
28254
29637
  releaseWorktree: (repo, p) => releaseWorktree(repo || opts.repo, p),
28255
29638
  pruneWorktrees: (repo) => pruneWorktrees(repo || opts.repo),
28256
- worktreeExists: existsSync23,
29639
+ worktreeExists: existsSync25,
28257
29640
  liveWorktrees: () => new Set(listDroneProcesses().map((p) => p.worktree)),
28258
29641
  narrate: narrator.narrate
28259
29642
  });
@@ -28397,13 +29780,13 @@ async function runDaemon(opts) {
28397
29780
  mode,
28398
29781
  nudge
28399
29782
  ),
28400
- worktreeExists: (p) => existsSync23(p),
29783
+ worktreeExists: (p) => existsSync25(p),
28401
29784
  // TASWM-514: с этого момента считаем попытки спавна — счётчик живёт ровно одну жизнь
28402
29785
  // процесса демона и рестарт не переживает (см. preStartAttempts).
28403
29786
  startedAt: Date.now(),
28404
29787
  // TASWM-592: run-aware — где лежит сессия, знает харнесс ПРОГОНА.
28405
29788
  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),
29789
+ runHasSession: (run2) => !!run2.worktree_path && existsSync25(run2.worktree_path) && executorForRun(run2, lastSwarmModels, process.env, runModelRefPin.get(run2.id) ?? null).session.exists(run2.worktree_path),
28407
29790
  // CI-осведомлённость review-PR (TASWM-102): реальный `gh pr checks`/`gh run view --log-failed`
28408
29791
  // (gh.ts) — решение (будить ли дрона) и гейты живут в tickOnce/handleCiRed. failureSummary
28409
29792
  // строится над failing/failingRunIds ИЗ checks — без повторного `gh pr checks`.
@@ -28635,7 +30018,7 @@ async function runDaemon(opts) {
28635
30018
  onStep
28636
30019
  });
28637
30020
  }
28638
- const repo = await repoRoot(dirname6(THIS_FILE)).catch(() => null);
30021
+ const repo = await repoRoot(dirname7(THIS_FILE)).catch(() => null);
28639
30022
  if (!repo) {
28640
30023
  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
30024
  }