@taskless-app/swarm 0.6.80 → 0.6.82

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/cli.js +653 -183
  2. package/dist/overmind.js +1245 -388
  3. package/package.json +2 -2
package/dist/cli.js CHANGED
@@ -23,6 +23,11 @@ async function askTty(question) {
23
23
  async function askYesNo(question) {
24
24
  return YES.includes((await askTty(`${question} [y/N]: `)).trim().toLowerCase());
25
25
  }
26
+ function readCommandOutcome(result) {
27
+ if (typeof result === "number") return { exitCode: result, output: "" };
28
+ return { exitCode: result.exitCode, output: `${result.stdout ?? ""}
29
+ ${result.stderr ?? ""}` };
30
+ }
26
31
  async function runQuiet(command, opts = {}) {
27
32
  try {
28
33
  const res = await execa(command, { shell: true, reject: false, timeout: opts.timeoutMs ?? PROBE_TIMEOUT_MS });
@@ -35,6 +40,15 @@ async function execLoud(command) {
35
40
  const res = await execa(command, { shell: true, reject: false, stdio: "inherit" });
36
41
  return res.exitCode ?? 1;
37
42
  }
43
+ async function execCaptured(command) {
44
+ const res = await execa(command, {
45
+ shell: true,
46
+ reject: false,
47
+ stdout: ["pipe", "inherit"],
48
+ stderr: ["pipe", "inherit"]
49
+ });
50
+ return { exitCode: res.exitCode ?? 1, stdout: res.stdout ?? "", stderr: res.stderr ?? "" };
51
+ }
38
52
  var YES, PROBE_TIMEOUT_MS;
39
53
  var init_cliIo = __esm({
40
54
  "src/cliIo.ts"() {
@@ -223,12 +237,13 @@ function verifyStatsLine(s) {
223
237
  const pct = Math.round(s.negativeShare * 100);
224
238
  return `\u0432\u0435\u0440\u0434\u0438\u043A\u0442\u043E\u0432 ${s.total} \xB7 \u043E\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043B\u044C\u043D\u044B\u0445 ${s.negative} (${pct}%): \u043D\u0435 \u0432\u043E\u0441\u043F\u0440\u043E\u0438\u0437\u0432\u0435\u043B\u043E\u0441\u044C ${s.notReproduced}, \u043D\u0430\u0448\u043B\u0438 \u0434\u0435\u0444\u0435\u043A\u0442 ${s.foundIssues}`;
225
239
  }
226
- var VERIFY_VERDICTS, VERIFY_VERDICT_SET;
240
+ var VERIFY_VERDICTS, VERIFY_VERDICT_SET, DRONE_COMMENT_SIGNATURE;
227
241
  var init_verifyVerdict = __esm({
228
242
  "../swarm-core/src/verifyVerdict.ts"() {
229
243
  "use strict";
230
244
  VERIFY_VERDICTS = ["confirmed", "not_reproduced", "found_issues"];
231
245
  VERIFY_VERDICT_SET = new Set(VERIFY_VERDICTS);
246
+ DRONE_COMMENT_SIGNATURE = "\u{1F41D} \u0414\u0440\u043E\u043D";
232
247
  }
233
248
  });
234
249
 
@@ -720,6 +735,25 @@ var init_modelPolicy = __esm({
720
735
  roles: { executor: "grok-4.7", review: "grok-4.7-build-fast" },
721
736
  models: ["grok-4.7", "grok-4.7-build-fast", "grok-4.6", "grok-4.5"]
722
737
  },
738
+ // Kimi Code CLI (Moonshot). Каталог — все 5 моделей из конфига владельца (09.11.2026),
739
+ // полные алиасы как в дефолтном config.toml любого kimi-code: ссылки вида
740
+ // `kimi/kimi-code/k3.1-pro` — parseModelRef режет по первому слэшу, моделью уходит
741
+ // `kimi-code/k3.1-pro` (второй слэш — часть имени). Тарифа нет: подписка, CLI цену не
742
+ // сообщает — честный ноль (costUsd=0 с предупреждением) живёт в адаптере (TASWM-630).
743
+ {
744
+ id: "kimi",
745
+ label: "Kimi (Moonshot)",
746
+ executorId: "kimi",
747
+ selectable: true,
748
+ roles: { executor: "kimi-code/k3.1-pro", review: "kimi-code/k3" },
749
+ models: [
750
+ "kimi-code/kimi-for-coding",
751
+ "kimi-code/k3",
752
+ "kimi-code/k3-256k",
753
+ "kimi-code/k3.1-pro",
754
+ "kimi-code/k3.1-pro-highspeed"
755
+ ]
756
+ },
723
757
  // TASWM-565 · шаг 1 из четырёх: провайдер в реестре ЕСТЬ, выбрать его ещё нельзя.
724
758
  // Имён моделей здесь нет СОЗНАТЕЛЬНО: у владельца подписка, состав моделей в ней нам
725
759
  // неизвестен, а выдуманное имя хуже маркера «решает Codex».
@@ -870,16 +904,30 @@ function sanitizeEventText(text) {
870
904
  if (!cleaned.length) return null;
871
905
  return cleaned.length <= EVENT_TEXT_MAX ? cleaned : clampEventText(cleaned);
872
906
  }
907
+ function sanitizeVerdictEventText(text) {
908
+ if (text == null) return null;
909
+ const cleaned = text.replace(ANSI_CSI_RE, "").replace(/\r\n/g, "\n").replace(/\r/g, "\n").replace(VERDICT_CONTROL_RE, " ").trim();
910
+ if (!cleaned.length) return null;
911
+ return cleaned.length <= EVENT_TEXT_MAX ? cleaned : clampEventText(cleaned);
912
+ }
913
+ function sanitizeStoredEventText(text) {
914
+ if (typeof text === "string") {
915
+ const head = text.trimStart();
916
+ if (head.startsWith("\u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u0440\u0435\u0432\u044C\u044E") || head.startsWith("\u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u0432\u0435\u0440\u0438\u0444\u0438\u043A\u0430\u0446\u0438\u0438")) return sanitizeVerdictEventText(text);
917
+ }
918
+ return sanitizeEventText(text);
919
+ }
873
920
  function clampEventText(text) {
874
921
  const note = ` \u2026 (\u043E\u0431\u0440\u0435\u0437\u0430\u043D\u043E, \u0431\u044B\u043B\u043E ${text.length} \u0441\u0438\u043C\u0432\u043E\u043B\u043E\u0432)`;
875
922
  return text.slice(0, Math.max(0, EVENT_TEXT_MAX - note.length)) + note;
876
923
  }
877
- var ANSI_CSI_RE, CONTROL_CHARS_RE, EVENT_TEXT_MAX;
924
+ var ANSI_CSI_RE, CONTROL_CHARS_RE, VERDICT_CONTROL_RE, EVENT_TEXT_MAX;
878
925
  var init_text = __esm({
879
926
  "../swarm-core/src/text.ts"() {
880
927
  "use strict";
881
928
  ANSI_CSI_RE = /\x1b\[[0-9;]*[A-Za-z]/g;
882
929
  CONTROL_CHARS_RE = /[\x00-\x1f\x7f]/g;
930
+ VERDICT_CONTROL_RE = /[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g;
883
931
  EVENT_TEXT_MAX = 16e3;
884
932
  }
885
933
  });
@@ -2844,6 +2892,179 @@ ${notice}` : spec.prompt;
2844
2892
  }
2845
2893
  });
2846
2894
 
2895
+ // src/executors/kimi.ts
2896
+ import { copyFileSync as copyFileSync4, existsSync as existsSync5, mkdirSync as mkdirSync5, readdirSync as readdirSync6, readFileSync as readFileSync3, statSync as statSync5, symlinkSync as symlinkSync3, writeFileSync as writeFileSync4 } from "fs";
2897
+ import { join as join7 } from "path";
2898
+ function resolveKimiBin(env = process.env) {
2899
+ return (env.SWARM_KIMI_BIN ?? "").trim() || "kimi";
2900
+ }
2901
+ function kimiHomePath(worktree, swarmHome = SWARM_HOME) {
2902
+ const key = worktree.replace(/[^A-Za-z0-9]+/g, "-").replace(/^-|-$/g, "") || "worktree";
2903
+ return join7(swarmHome, "executor-state", "kimi", key);
2904
+ }
2905
+ function kimiSessionRoot(worktree, swarmHome = SWARM_HOME) {
2906
+ return join7(kimiHomePath(worktree, swarmHome), "sessions");
2907
+ }
2908
+ function newestKimiSessionMtime(dir, depth = 4) {
2909
+ let entries;
2910
+ try {
2911
+ entries = readdirSync6(dir, { withFileTypes: true });
2912
+ } catch {
2913
+ return null;
2914
+ }
2915
+ let latest = null;
2916
+ for (const entry of entries) {
2917
+ const full = join7(dir, entry.name);
2918
+ try {
2919
+ if (entry.isDirectory()) {
2920
+ if (depth <= 0) continue;
2921
+ const nested = newestKimiSessionMtime(full, depth - 1);
2922
+ if (nested != null && (latest == null || nested > latest)) latest = nested;
2923
+ } else if (entry.isFile()) {
2924
+ const mtime2 = statSync5(full).mtimeMs;
2925
+ if (latest == null || mtime2 > latest) latest = mtime2;
2926
+ }
2927
+ } catch {
2928
+ }
2929
+ }
2930
+ return latest;
2931
+ }
2932
+ function extractModelsBlocks(config) {
2933
+ const lines = config.split(/\r?\n/);
2934
+ const blocks = [];
2935
+ let current = null;
2936
+ for (const line of lines) {
2937
+ if (/^\s*\[/.test(line)) {
2938
+ if (current) blocks.push(current);
2939
+ current = /^\s*\[models\./.test(line) ? [line] : null;
2940
+ continue;
2941
+ }
2942
+ if (current) current.push(line);
2943
+ }
2944
+ if (current) blocks.push(current);
2945
+ return blocks.map((b) => b.join("\n").trimEnd()).filter((b) => b.trim() !== "");
2946
+ }
2947
+ function kimiMcpJson(spec) {
2948
+ return JSON.stringify(
2949
+ { mcpServers: { [spec.mcp.name]: { command: spec.mcp.command, args: spec.mcp.args, env: spec.mcp.env } } },
2950
+ null,
2951
+ 2
2952
+ );
2953
+ }
2954
+ function ensureKimiHome(worktree, realHome, env = process.env, swarmHome = SWARM_HOME) {
2955
+ const home = kimiHomePath(worktree, swarmHome);
2956
+ mkdirSync5(home, { recursive: true });
2957
+ const realCreds = join7((env.KIMI_CODE_HOME ?? "").trim() || join7(realHome, ".kimi-code"), "credentials");
2958
+ const link = join7(home, "credentials");
2959
+ if (existsSync5(realCreds) && !existsSync5(link)) {
2960
+ try {
2961
+ symlinkSync3(realCreds, link, "junction");
2962
+ } catch {
2963
+ try {
2964
+ mkdirSync5(link, { recursive: true });
2965
+ for (const f of readdirSync6(realCreds)) copyFileSync4(join7(realCreds, f), join7(link, f));
2966
+ } catch {
2967
+ }
2968
+ }
2969
+ }
2970
+ const realConfig = join7((env.KIMI_CODE_HOME ?? "").trim() || join7(realHome, ".kimi-code"), "config.toml");
2971
+ try {
2972
+ const blocks = extractModelsBlocks(readFileSync3(realConfig, "utf8"));
2973
+ if (blocks.length > 0) writeFileSync4(join7(home, "config.toml"), `${blocks.join("\n\n")}
2974
+ `);
2975
+ } catch {
2976
+ }
2977
+ return home;
2978
+ }
2979
+ function modelArgs2(model) {
2980
+ if (!model || isHarnessDefaultModel(model)) return [];
2981
+ return ["-m", model];
2982
+ }
2983
+ function parseKimiResult(raw) {
2984
+ const trimmed = raw.trim();
2985
+ if (!trimmed) return null;
2986
+ let lastAssistant = null;
2987
+ let sawEvent = false;
2988
+ for (const line of trimmed.split(/\r?\n/)) {
2989
+ const s = line.trim();
2990
+ if (!s) continue;
2991
+ let parsed;
2992
+ try {
2993
+ parsed = JSON.parse(s);
2994
+ } catch {
2995
+ continue;
2996
+ }
2997
+ if (typeof parsed !== "object" || parsed === null) continue;
2998
+ sawEvent = true;
2999
+ const rec = parsed;
3000
+ if (rec.role === "assistant" && typeof rec.content === "string") lastAssistant = rec.content;
3001
+ }
3002
+ if (!sawEvent || lastAssistant === null) return null;
3003
+ return {
3004
+ costUsd: 0,
3005
+ warning: "kimi: CLI \u0441\u0442\u043E\u0438\u043C\u043E\u0441\u0442\u044C \u043D\u0435 \u0441\u043E\u043E\u0431\u0449\u0430\u0435\u0442 (\u043F\u043E\u0434\u043F\u0438\u0441\u043A\u0430) \u2014 \u044D\u0442\u043E \u043D\u0435 \u043D\u043E\u043B\u044C \u0432 \u0441\u043C\u044B\u0441\u043B\u0435 \u0431\u0435\u0441\u043F\u043B\u0430\u0442\u043D\u043E"
3006
+ };
3007
+ }
3008
+ var kimiExecutor;
3009
+ var init_kimi = __esm({
3010
+ "src/executors/kimi.ts"() {
3011
+ "use strict";
3012
+ init_src();
3013
+ init_swarmHome();
3014
+ init_swarmFiles();
3015
+ kimiExecutor = {
3016
+ id: "kimi",
3017
+ title: "Kimi Code CLI (kimi)",
3018
+ binEnv: "SWARM_KIMI_BIN",
3019
+ install: {
3020
+ what: "Kimi Code CLI (Moonshot). \u041E\u0444\u0438\u0446\u0438\u0430\u043B\u044C\u043D\u044B\u0439 \u0443\u0441\u0442\u0430\u043D\u043E\u0432\u0449\u0438\u043A \u0441 code.kimi.com \u2014 \u041D\u0415 npm-\u043F\u0430\u043A\u0435\u0442 kimi-code (\u044D\u0442\u043E \u0447\u0443\u0436\u043E\u0439 \u043F\u0440\u043E\u043A\u0441\u0438-\u0432\u0440\u0430\u043F\u043F\u0435\u0440).",
3021
+ pkg: "kimi-code",
3022
+ command: "curl -fsSL https://code.kimi.com/kimi-code/install.sh | bash",
3023
+ windowsCommand: "irm https://code.kimi.com/kimi-code/install.ps1 | iex"
3024
+ },
3025
+ resolveBin: (env) => resolveKimiBin(env ?? process.env),
3026
+ plan: (spec) => {
3027
+ const home = ensureKimiHome(spec.worktree, spec.realHome);
3028
+ writeFileSync4(join7(home, "mcp.json"), kimiMcpJson(spec));
3029
+ writeFileSync4(
3030
+ join7(spec.worktree, SWARM_MCP_CONFIG_FILE),
3031
+ JSON.stringify(
3032
+ { mcpServers: { [spec.mcp.name]: { command: spec.mcp.command, args: spec.mcp.args, env: spec.mcp.env } } },
3033
+ null,
3034
+ 2
3035
+ )
3036
+ );
3037
+ const args = [
3038
+ // `--add-dir` стоит первым: настоящий флаг kimi, по нему реконсайл узнаёт
3039
+ // worktree живого процесса после рестарта демона (worktreeFromKimiCmd).
3040
+ "--add-dir",
3041
+ spec.worktree,
3042
+ "--output-format",
3043
+ "stream-json",
3044
+ ...spec.skillDirs.flatMap((dir) => ["--skills-dir", dir]),
3045
+ ...spec.continueSession ? ["--continue"] : [],
3046
+ ...modelArgs2(spec.model),
3047
+ "-p",
3048
+ spec.prompt
3049
+ ];
3050
+ return { bin: resolveKimiBin(), args, env: { KIMI_CODE_HOME: home } };
3051
+ },
3052
+ parseResult(raw) {
3053
+ return parseKimiResult(raw);
3054
+ },
3055
+ session: {
3056
+ exists: (worktree) => newestKimiSessionMtime(kimiSessionRoot(worktree)) !== null,
3057
+ mtimeMs: (worktree) => newestKimiSessionMtime(kimiSessionRoot(worktree))
3058
+ },
3059
+ probe: {
3060
+ args: ["-p", "ok", "--output-format", "stream-json"],
3061
+ limitPattern: /usage limit|quota|rate.limit|too many requests/i,
3062
+ authPattern: /use \/login to sign in|not logged in|unauthorized|\b401\b|authentication required/i
3063
+ }
3064
+ };
3065
+ }
3066
+ });
3067
+
2847
3068
  // src/liveModels.ts
2848
3069
  import { execFile } from "child_process";
2849
3070
  function liveDefaultModel(providerId) {
@@ -2941,23 +3162,26 @@ var init_executors = __esm({
2941
3162
  init_claudeCode();
2942
3163
  init_codex();
2943
3164
  init_grok();
3165
+ init_kimi();
2944
3166
  init_swarmModels();
2945
3167
  init_types2();
2946
3168
  init_claudeCode();
2947
3169
  init_codex();
2948
3170
  init_grok();
3171
+ init_kimi();
2949
3172
  DEFAULT_EXECUTOR_ID = "claude-code";
2950
3173
  EXECUTORS = {
2951
3174
  [claudeCodeExecutor.id]: claudeCodeExecutor,
2952
3175
  [codexExecutor.id]: codexExecutor,
2953
- [grokExecutor.id]: grokExecutor
3176
+ [grokExecutor.id]: grokExecutor,
3177
+ [kimiExecutor.id]: kimiExecutor
2954
3178
  };
2955
3179
  }
2956
3180
  });
2957
3181
 
2958
3182
  // src/config.ts
2959
- import { basename, join as join7, resolve } from "path";
2960
- import { readFileSync as readFileSync3, realpathSync, renameSync, writeFileSync as writeFileSync4 } from "fs";
3183
+ import { basename, join as join8, resolve } from "path";
3184
+ import { readFileSync as readFileSync4, realpathSync, renameSync, writeFileSync as writeFileSync5 } from "fs";
2961
3185
  function normalizeRepo(repo) {
2962
3186
  const r = (repo ?? "").trim();
2963
3187
  if (!r) return "";
@@ -2971,10 +3195,10 @@ function effectiveRepoOf(repo, fallback) {
2971
3195
  return normalizeRepo(repo || fallback || "");
2972
3196
  }
2973
3197
  function droneWorktreePath(worktreesDir, repo, slug) {
2974
- return join7(droneWorktreeRoot(worktreesDir, repo), slug);
3198
+ return join8(droneWorktreeRoot(worktreesDir, repo), slug);
2975
3199
  }
2976
3200
  function droneWorktreeRoot(worktreesDir, repo) {
2977
- return join7(worktreesDir, basename(normalizeRepo(repo)));
3201
+ return join8(worktreesDir, basename(normalizeRepo(repo)));
2978
3202
  }
2979
3203
  function resolveEffectiveWorktreesDir(deps) {
2980
3204
  if (deps.envOverride) return deps.envOverride;
@@ -3001,7 +3225,7 @@ function mcpEndpoint(api, path = TASKLESS_MCP_PATH) {
3001
3225
  }
3002
3226
  function tokenFromFile() {
3003
3227
  try {
3004
- return readFileSync3(join7(SWARM_HOME, "token"), "utf8").trim();
3228
+ return readFileSync4(join8(SWARM_HOME, "token"), "utf8").trim();
3005
3229
  } catch {
3006
3230
  return "";
3007
3231
  }
@@ -3014,25 +3238,25 @@ var init_config = __esm({
3014
3238
  init_executors();
3015
3239
  init_swarmHome();
3016
3240
  init_swarmHome();
3017
- DB_PATH = process.env.SWARM_DB || join7(SWARM_HOME, "swarm.db");
3241
+ DB_PATH = process.env.SWARM_DB || join8(SWARM_HOME, "swarm.db");
3018
3242
  EXECUTOR = resolveExecutor(process.env.SWARM_EXECUTOR);
3019
- DRONE_HOME = process.env.SWARM_DRONE_HOME || join7(SWARM_HOME, "drone-home");
3243
+ DRONE_HOME = process.env.SWARM_DRONE_HOME || join8(SWARM_HOME, "drone-home");
3020
3244
  DRONE_HOME_ISOLATION = process.env.SWARM_DRONE_ISOLATE_HOME !== "0" && process.platform !== "win32";
3021
3245
  DRONE_ISOLATION = DRONE_HOME_ISOLATION ? { home: DRONE_HOME, swarmHome: SWARM_HOME } : void 0;
3022
- WORKTREES_NOINDEX_DIR = join7(SWARM_HOME, "worktrees.noindex");
3023
- WORKTREES_LEGACY_DIR = join7(SWARM_HOME, "worktrees");
3246
+ WORKTREES_NOINDEX_DIR = join8(SWARM_HOME, "worktrees.noindex");
3247
+ WORKTREES_LEGACY_DIR = join8(SWARM_HOME, "worktrees");
3024
3248
  WORKTREES_DIR = process.env.SWARM_WORKTREES || WORKTREES_NOINDEX_DIR;
3025
- RUN_LOGS_DIR = process.env.SWARM_RUN_LOGS || join7(SWARM_HOME, "run-logs");
3026
- DAEMON_LOG_PATH = process.env.SWARM_DAEMON_LOG || join7(SWARM_HOME, "overmind.log");
3249
+ RUN_LOGS_DIR = process.env.SWARM_RUN_LOGS || join8(SWARM_HOME, "run-logs");
3250
+ DAEMON_LOG_PATH = process.env.SWARM_DAEMON_LOG || join8(SWARM_HOME, "overmind.log");
3027
3251
  DAEMON_LOG_MAX_BYTES = envNum("SWARM_DAEMON_LOG_MAX_BYTES", 16 * 1024 * 1024);
3028
3252
  DAEMON_LOG_KEEP = envNum("SWARM_DAEMON_LOG_KEEP", 2);
3029
3253
  DAEMON_LOG_CHECK_MS = envNum("SWARM_DAEMON_LOG_CHECK_MS", 6e4);
3030
3254
  DIST_BUILD = true;
3031
3255
  SWARM_BACKEND = process.env.SWARM_BACKEND === "client" ? "client" : process.env.SWARM_BACKEND === "sqlite" ? "sqlite" : DIST_BUILD ? "client" : "sqlite";
3032
- SWARM_OUTBOX = process.env.SWARM_OUTBOX || join7(SWARM_HOME, "outbox.jsonl");
3256
+ SWARM_OUTBOX = process.env.SWARM_OUTBOX || join8(SWARM_HOME, "outbox.jsonl");
3033
3257
  SWARM_MAX_IN_FLIGHT = Math.trunc(envNum("SWARM_MAX_IN_FLIGHT", 3));
3034
3258
  SWARM_CLAIM_INTERVAL_MS = envNum("SWARM_CLAIM_INTERVAL_MS", 6e4);
3035
- ENV_CACHE_DIR = process.env.SWARM_ENV_CACHE_DIR || join7(SWARM_HOME, "env-cache");
3259
+ ENV_CACHE_DIR = process.env.SWARM_ENV_CACHE_DIR || join8(SWARM_HOME, "env-cache");
3036
3260
  ENV_CACHE_ENABLED = process.env.SWARM_ENV_CACHE !== "0";
3037
3261
  ENV_CACHE_KEEP = Math.trunc(envNum("SWARM_ENV_CACHE_KEEP", 4));
3038
3262
  SWARM_MAX_LOAD_FACTOR = envNum("SWARM_MAX_LOAD_FACTOR", 0.9);
@@ -3062,15 +3286,15 @@ var init_config = __esm({
3062
3286
  DRONE_CHANNEL_ENABLED = process.env.SWARM_DRONE_CHANNEL !== "0";
3063
3287
  DRONE_CHANNEL_PORT = Number(process.env.SWARM_DRONE_CHANNEL_PORT) || 7421;
3064
3288
  DRONE_CHANNEL_URL = process.env.SWARM_DRONE_CHANNEL_URL || `http://127.0.0.1:${DRONE_CHANNEL_PORT}`;
3065
- DRONE_CHANNEL_SECRET_PATH = process.env.SWARM_DRONE_CHANNEL_SECRET || join7(SWARM_HOME, "drone-channel.key");
3289
+ DRONE_CHANNEL_SECRET_PATH = process.env.SWARM_DRONE_CHANNEL_SECRET || join8(SWARM_HOME, "drone-channel.key");
3066
3290
  DRONE_CHANNEL_GRACE_MS = envNum("SWARM_DRONE_CHANNEL_GRACE_MS", 12e4);
3067
- HEARTBEAT_PATH = process.env.SWARM_HEARTBEAT || join7(SWARM_HOME, "overmind.heartbeat");
3291
+ HEARTBEAT_PATH = process.env.SWARM_HEARTBEAT || join8(SWARM_HOME, "overmind.heartbeat");
3068
3292
  HEARTBEAT_STALE_MS = Number(process.env.SWARM_HEARTBEAT_STALE_MS) || 3e4;
3069
3293
  SWARM_REPO = process.env.SWARM_REPO || "";
3070
3294
  SWARM_SCAN_DEPTH = Number(process.env.SWARM_SCAN_DEPTH) || 3;
3071
3295
  SWARM_REPO_PATHS = (process.env.SWARM_REPOS || SWARM_REPO).split(",").map((s) => s.trim()).filter(Boolean);
3072
3296
  SWARM_SCAN_ROOTS_RAW = process.env.SWARM_SCAN_ROOTS || "";
3073
- REPO_MAP_PATH = process.env.SWARM_REPO_MAP || join7(SWARM_HOME, "repo-map.json");
3297
+ REPO_MAP_PATH = process.env.SWARM_REPO_MAP || join8(SWARM_HOME, "repo-map.json");
3074
3298
  SWARM_REPO_MAP_MS = envNum("SWARM_REPO_MAP_MS", 15 * 6e4);
3075
3299
  SWARM_REPO_SCAN_TTL_MS = envNum("SWARM_REPO_SCAN_TTL_MS", 24 * 60 * 6e4);
3076
3300
  TASKLESS_API = process.env.TASKLESS_API || "https://taskless.ru";
@@ -3085,7 +3309,7 @@ var init_config = __esm({
3085
3309
  SWARM_AUTO_REVIEW = process.env.SWARM_AUTO_REVIEW !== "0";
3086
3310
  SWARM_AUTO_VERIFY = process.env.SWARM_AUTO_VERIFY !== "0";
3087
3311
  SWARM_MERGE_QUEUE = process.env.SWARM_MERGE_QUEUE !== "0";
3088
- REVIEW_CUTOFF_PATH = process.env.SWARM_REVIEW_CUTOFF || join7(SWARM_HOME, "review-cutoff.json");
3312
+ REVIEW_CUTOFF_PATH = process.env.SWARM_REVIEW_CUTOFF || join8(SWARM_HOME, "review-cutoff.json");
3089
3313
  SWARM_REVIEW_CAP = Math.trunc(envNum("SWARM_REVIEW_CAP", 1));
3090
3314
  SWARM_STORM_URL = process.env.SWARM_STORM_URL || "";
3091
3315
  WEB_PORT = Number(process.env.SWARM_WEB_PORT) || 7420;
@@ -3125,7 +3349,7 @@ var init_quietExec = __esm({
3125
3349
 
3126
3350
  // src/resources.ts
3127
3351
  import os from "os";
3128
- import { readFileSync as readFileSync4, statfsSync } from "fs";
3352
+ import { readFileSync as readFileSync5, statfsSync } from "fs";
3129
3353
  function isTransientResourceError(e) {
3130
3354
  const code = e?.code;
3131
3355
  return code === "ENFILE" || code === "EMFILE" || code === "EAGAIN";
@@ -3177,7 +3401,7 @@ function fileDescriptorLoadRatio() {
3177
3401
  }
3178
3402
  if (process.platform === "linux") {
3179
3403
  try {
3180
- const [allocated, , max] = readFileSync4("/proc/sys/fs/file-nr", "utf8").trim().split(/\s+/).map(Number);
3404
+ const [allocated, , max] = readFileSync5("/proc/sys/fs/file-nr", "utf8").trim().split(/\s+/).map(Number);
3181
3405
  if (Number.isFinite(allocated ?? NaN) && Number.isFinite(max ?? NaN) && max) return allocated / max;
3182
3406
  } catch {
3183
3407
  }
@@ -3440,18 +3664,18 @@ var init_store = __esm({
3440
3664
  });
3441
3665
 
3442
3666
  // src/agentToken.ts
3443
- import { readFileSync as readFileSync5, writeFileSync as writeFileSync5, unlinkSync } from "fs";
3444
- import { join as join8 } from "path";
3667
+ import { readFileSync as readFileSync6, writeFileSync as writeFileSync6, unlinkSync } from "fs";
3668
+ import { join as join9 } from "path";
3445
3669
  function loadAgentToken() {
3446
3670
  try {
3447
- const s = JSON.parse(readFileSync5(STORE_PATH, "utf8"));
3671
+ const s = JSON.parse(readFileSync6(STORE_PATH, "utf8"));
3448
3672
  return s.token ? s : null;
3449
3673
  } catch {
3450
3674
  return null;
3451
3675
  }
3452
3676
  }
3453
3677
  function saveAgentToken(s) {
3454
- writeFileSync5(STORE_PATH, JSON.stringify(s, null, 2), { mode: 384 });
3678
+ writeFileSync6(STORE_PATH, JSON.stringify(s, null, 2), { mode: 384 });
3455
3679
  }
3456
3680
  function clearAgentToken() {
3457
3681
  try {
@@ -3522,7 +3746,7 @@ var init_agentToken = __esm({
3522
3746
  "src/agentToken.ts"() {
3523
3747
  "use strict";
3524
3748
  init_config();
3525
- STORE_PATH = join8(SWARM_HOME, "agent.json");
3749
+ STORE_PATH = join9(SWARM_HOME, "agent.json");
3526
3750
  base = (api) => api.replace(/\/$/, "");
3527
3751
  TOKEN_PROBE_TIMEOUT_MS = 8e3;
3528
3752
  }
@@ -3626,6 +3850,7 @@ var init_toolFailure = __esm({
3626
3850
  });
3627
3851
 
3628
3852
  // src/procList.ts
3853
+ import { readFileSync as readFileSync9 } from "fs";
3629
3854
  function parsePsRows(out) {
3630
3855
  const rows = [];
3631
3856
  for (const line of out.split("\n")) {
@@ -3908,7 +4133,7 @@ var init_package = __esm({
3908
4133
  "package.json"() {
3909
4134
  package_default = {
3910
4135
  name: "@taskless-app/swarm",
3911
- version: "0.6.80",
4136
+ version: "0.6.82",
3912
4137
  type: "module",
3913
4138
  description: "Local control plane for a fleet of AI coding agents (drones), coordinating through Taskless. The overmind runs the swarm.",
3914
4139
  keywords: [
@@ -3960,7 +4185,7 @@ var init_package = __esm({
3960
4185
  undici: "^7.30.1",
3961
4186
  zod: "3.25.76"
3962
4187
  },
3963
- gitHead: "5bd6515d0cca44cb563f9ad09b5fe3bc1d70d408"
4188
+ gitHead: "1ca25b5c37db968ab99a966201fd4a1dd35a2ac1"
3964
4189
  };
3965
4190
  }
3966
4191
  });
@@ -4126,18 +4351,18 @@ var init_netTimeout = __esm({
4126
4351
 
4127
4352
  // src/droneChannel.ts
4128
4353
  import { createHmac, randomBytes, timingSafeEqual } from "crypto";
4129
- import { chmodSync as chmodSync2, mkdirSync as mkdirSync8, readFileSync as readFileSync9, writeFileSync as writeFileSync8 } from "fs";
4354
+ import { chmodSync as chmodSync2, mkdirSync as mkdirSync9, readFileSync as readFileSync11, writeFileSync as writeFileSync9 } from "fs";
4130
4355
  import { dirname as dirname3 } from "path";
4131
4356
  import { serve } from "@hono/node-server";
4132
4357
  function loadChannelSecret(path) {
4133
4358
  try {
4134
- const s = readFileSync9(path, "utf8").trim();
4359
+ const s = readFileSync11(path, "utf8").trim();
4135
4360
  if (s.length >= 32) return s;
4136
4361
  } catch {
4137
4362
  }
4138
4363
  const secret = randomBytes(32).toString("hex");
4139
- mkdirSync8(dirname3(path), { recursive: true });
4140
- writeFileSync8(path, secret, { mode: 384 });
4364
+ mkdirSync9(dirname3(path), { recursive: true });
4365
+ writeFileSync9(path, secret, { mode: 384 });
4141
4366
  try {
4142
4367
  chmodSync2(path, 384);
4143
4368
  } catch {
@@ -4214,8 +4439,8 @@ var init_authState = __esm({
4214
4439
 
4215
4440
  // src/oauth.ts
4216
4441
  import { createHash, randomBytes as randomBytes2 } from "crypto";
4217
- import { readFileSync as readFileSync10, writeFileSync as writeFileSync9, unlinkSync as unlinkSync3 } from "fs";
4218
- import { join as join13 } from "path";
4442
+ import { readFileSync as readFileSync12, writeFileSync as writeFileSync10, unlinkSync as unlinkSync3 } from "fs";
4443
+ import { join as join14 } from "path";
4219
4444
  function makePkce() {
4220
4445
  const verifier = randomBytes2(48).toString("base64url");
4221
4446
  const challenge = createHash("sha256").update(verifier).digest("base64url");
@@ -4299,13 +4524,13 @@ function toStore(clientId, t, now) {
4299
4524
  }
4300
4525
  function loadStore() {
4301
4526
  try {
4302
- return JSON.parse(readFileSync10(STORE_PATH2, "utf8"));
4527
+ return JSON.parse(readFileSync12(STORE_PATH2, "utf8"));
4303
4528
  } catch {
4304
4529
  return null;
4305
4530
  }
4306
4531
  }
4307
4532
  function saveStore(s) {
4308
- writeFileSync9(STORE_PATH2, JSON.stringify(s, null, 2), { mode: 384 });
4533
+ writeFileSync10(STORE_PATH2, JSON.stringify(s, null, 2), { mode: 384 });
4309
4534
  }
4310
4535
  function clearStore() {
4311
4536
  try {
@@ -4315,7 +4540,7 @@ function clearStore() {
4315
4540
  }
4316
4541
  function loadClientId() {
4317
4542
  try {
4318
- return JSON.parse(readFileSync10(CLIENT_PATH, "utf8")).clientId;
4543
+ return JSON.parse(readFileSync12(CLIENT_PATH, "utf8")).clientId;
4319
4544
  } catch {
4320
4545
  return null;
4321
4546
  }
@@ -4324,7 +4549,7 @@ async function ensureClientId(api, redirectUri, fetchFn = fetch) {
4324
4549
  const existing = loadClientId();
4325
4550
  if (existing) return existing;
4326
4551
  const clientId = await registerClient({ api, redirectUri }, fetchFn);
4327
- writeFileSync9(CLIENT_PATH, JSON.stringify({ clientId }, null, 2), { mode: 384 });
4552
+ writeFileSync10(CLIENT_PATH, JSON.stringify({ clientId }, null, 2), { mode: 384 });
4328
4553
  return clientId;
4329
4554
  }
4330
4555
  async function ensureAccess(store, opts = {}) {
@@ -4350,16 +4575,16 @@ var init_oauth = __esm({
4350
4575
  AUTHORIZE = "/api/oauth/authorize";
4351
4576
  TOKEN = "/api/oauth/token";
4352
4577
  SCOPE = "openid profile email taskless:full";
4353
- STORE_PATH2 = join13(SWARM_HOME, "oauth.json");
4354
- CLIENT_PATH = join13(SWARM_HOME, "oauth-client.json");
4578
+ STORE_PATH2 = join14(SWARM_HOME, "oauth.json");
4579
+ CLIENT_PATH = join14(SWARM_HOME, "oauth-client.json");
4355
4580
  base2 = (api) => api.replace(/\/$/, "");
4356
4581
  }
4357
4582
  });
4358
4583
 
4359
4584
  // src/git.ts
4360
- import { existsSync as existsSync11, readdirSync as readdirSync10, realpathSync as realpathSync2, statSync as statSync10 } from "fs";
4585
+ import { existsSync as existsSync12, readdirSync as readdirSync11, realpathSync as realpathSync2, statSync as statSync11 } from "fs";
4361
4586
  import { appendFile, chmod, mkdir, readFile, rename, rm, writeFile } from "fs/promises";
4362
- import { isAbsolute, join as join16, resolve as resolve2, sep as sep2 } from "path";
4587
+ import { isAbsolute, join as join17, resolve as resolve2, sep as sep2 } from "path";
4363
4588
  import { $ as $5 } from "execa";
4364
4589
  function gitNet(repo, args, timeoutMs) {
4365
4590
  return withHardTimeout(
@@ -4373,14 +4598,14 @@ async function reclaimStaleWorktree(repo, worktree) {
4373
4598
  await detachWorktree(repo, worktree);
4374
4599
  }
4375
4600
  async function inspectWorktreePath(path) {
4376
- if (!existsSync11(path)) return "free";
4601
+ if (!existsSync12(path)) return "free";
4377
4602
  try {
4378
- if (readdirSync10(path).length === 0) return "free";
4603
+ if (readdirSync11(path).length === 0) return "free";
4379
4604
  } catch {
4380
4605
  return "orphan";
4381
4606
  }
4382
4607
  try {
4383
- if (statSync10(join16(path, ".git")).isDirectory()) return "main-checkout";
4608
+ if (statSync11(join17(path, ".git")).isDirectory()) return "main-checkout";
4384
4609
  } catch {
4385
4610
  }
4386
4611
  const top = await $5({ reject: false })`git -C ${path} rev-parse --show-toplevel`;
@@ -4419,7 +4644,7 @@ async function clearWorktreePath(repo, path, branch, opts = {}) {
4419
4644
  await detachWorktree(repo, path);
4420
4645
  opts.onStaleReclaim?.(path);
4421
4646
  }
4422
- if (!existsSync11(path)) return;
4647
+ if (!existsSync12(path)) return;
4423
4648
  await parkOrphanDir(repo, path, branch);
4424
4649
  }
4425
4650
  async function parkOrphanDir(repo, path, branch) {
@@ -4440,7 +4665,7 @@ async function parkOrphanDir(repo, path, branch) {
4440
4665
  }
4441
4666
  function isLinkedWorktree(dir) {
4442
4667
  try {
4443
- return statSync10(join16(dir, ".git")).isFile();
4668
+ return statSync11(join17(dir, ".git")).isFile();
4444
4669
  } catch {
4445
4670
  return false;
4446
4671
  }
@@ -4452,7 +4677,7 @@ async function detachWorktree(repo, worktree) {
4452
4677
  }
4453
4678
  }
4454
4679
  async function ensureWorktreeDirGone(worktree) {
4455
- if (!existsSync11(worktree)) return false;
4680
+ if (!existsSync12(worktree)) return false;
4456
4681
  if (!isLinkedWorktree(worktree)) {
4457
4682
  console.error(
4458
4683
  `[git] ${worktree} \u2014 \u043D\u0435 \u043F\u0440\u0438\u0441\u0442\u0451\u0433\u043D\u0443\u0442\u044B\u0439 worktree (.git \u043D\u0435 \u0444\u0430\u0439\u043B): \u043A\u0430\u0442\u0430\u043B\u043E\u0433 \u041D\u0415 \u0442\u0440\u043E\u0433\u0430\u044E. \u0415\u0441\u043B\u0438 \u044D\u0442\u043E \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043B\u044C\u043D\u043E worktree \u0434\u0440\u043E\u043D\u0430 \u2014 \u0443\u0431\u0435\u0440\u0438\u0442\u0435 \u0435\u0433\u043E \u0440\u0443\u043A\u0430\u043C\u0438; \u0435\u0441\u043B\u0438 \u044D\u0442\u043E \u043E\u0441\u043D\u043E\u0432\u043D\u043E\u0439 \u0447\u0435\u043A\u0430\u0443\u0442, \u0437\u043D\u0430\u0447\u0438\u0442 \u0432\u0435\u0442\u043A\u0430 \u0441\u043B\u0430\u0433\u0430 \u0447\u0435\u043A\u043D\u0443\u0442\u0430 \u0432 \u043D\u0451\u043C (git checkout <slug>) \u2014 \u043F\u0435\u0440\u0435\u043A\u043B\u044E\u0447\u0438\u0442\u0435 \u0435\u0433\u043E \u043D\u0430 \u0434\u0440\u0443\u0433\u0443\u044E \u0432\u0435\u0442\u043A\u0443.`
@@ -4467,7 +4692,7 @@ async function ensureWorktreeDirGone(worktree) {
4467
4692
  );
4468
4693
  return true;
4469
4694
  }
4470
- if (existsSync11(worktree)) {
4695
+ if (existsSync12(worktree)) {
4471
4696
  console.error(`[git] \u043A\u0430\u0442\u0430\u043B\u043E\u0433 worktree ${worktree} \u043F\u0435\u0440\u0435\u0436\u0438\u043B rm \u2014 \u0443\u0431\u0435\u0440\u0438\u0442\u0435 \u0440\u0443\u043A\u0430\u043C\u0438, \u0438\u043D\u0430\u0447\u0435 \u0441\u043B\u0435\u0434\u0443\u044E\u0449\u0438\u0439 \u0441\u043F\u0430\u0432\u043D \u0441\u043B\u0430\u0433\u0430 \u0432\u0441\u0442\u0430\u043D\u0435\u0442.`);
4472
4697
  }
4473
4698
  return true;
@@ -4516,7 +4741,7 @@ async function checkoutWorktree(repo, path, branch, opts) {
4516
4741
  }
4517
4742
  const busyAt = await worktreeForBranch(repo, branch);
4518
4743
  if (busyAt) {
4519
- const exists = existsSync11(busyAt);
4744
+ const exists = existsSync12(busyAt);
4520
4745
  const live2 = exists && (opts.isWorktreeHeldLive ? await opts.isWorktreeHeldLive(busyAt) : true);
4521
4746
  if (live2) throw new WorktreeBusyError(branch, busyAt);
4522
4747
  if (exists && await worktreeDirty(busyAt)) throw new WorktreeBusyError(branch, busyAt);
@@ -4547,8 +4772,8 @@ async function ensureGitExcluded(worktree, pattern) {
4547
4772
  try {
4548
4773
  const commonDir = await gitPath(worktree, "--git-common-dir");
4549
4774
  if (!commonDir) return false;
4550
- const infoDir = join16(commonDir, "info");
4551
- const excludeFile = join16(infoDir, "exclude");
4775
+ const infoDir = join17(commonDir, "info");
4776
+ const excludeFile = join17(infoDir, "exclude");
4552
4777
  let current = "";
4553
4778
  try {
4554
4779
  current = await readFile(excludeFile, "utf8");
@@ -4568,7 +4793,7 @@ async function gitPath(worktree, flag) {
4568
4793
  const out = await $5({ reject: false })`git -C ${worktree} rev-parse ${flag}`;
4569
4794
  const raw = out.stdout.trim();
4570
4795
  if (out.exitCode !== 0 || !raw) return null;
4571
- return isAbsolute(raw) ? raw : join16(worktree, raw);
4796
+ return isAbsolute(raw) ? raw : join17(worktree, raw);
4572
4797
  }
4573
4798
  async function ensureWorktreeHygiene(worktree) {
4574
4799
  for (const pattern of SWARM_EXCLUDE_PATTERNS) await ensureGitExcluded(worktree, pattern);
@@ -4578,12 +4803,12 @@ async function installGuardHooks(worktree) {
4578
4803
  try {
4579
4804
  const gitDir = await gitPath(worktree, "--git-dir");
4580
4805
  if (!gitDir) return false;
4581
- const hooksDir = join16(gitDir, "swarm-hooks");
4806
+ const hooksDir = join17(gitDir, "swarm-hooks");
4582
4807
  const prev = await previousHooksPath(worktree);
4583
4808
  await mkdir(hooksDir, { recursive: true });
4584
4809
  for (const hook of GUARD_HOOKS) {
4585
- await writeFile(join16(hooksDir, hook), guardHookScript(hook, prev ? `${posix(prev)}/${hook}` : null));
4586
- await chmod(join16(hooksDir, hook), 493);
4810
+ await writeFile(join17(hooksDir, hook), guardHookScript(hook, prev ? `${posix(prev)}/${hook}` : null));
4811
+ await chmod(join17(hooksDir, hook), 493);
4587
4812
  }
4588
4813
  await $5`git -C ${worktree} config extensions.worktreeConfig true`;
4589
4814
  await $5`git -C ${worktree} config --worktree core.hooksPath ${posix(hooksDir)}`;
@@ -4602,7 +4827,7 @@ async function previousHooksPath(worktree) {
4602
4827
  if (out.exitCode === 0 && value) return value;
4603
4828
  }
4604
4829
  const commonDir = await gitPath(worktree, "--git-common-dir");
4605
- return commonDir ? join16(commonDir, "hooks") : null;
4830
+ return commonDir ? join17(commonDir, "hooks") : null;
4606
4831
  }
4607
4832
  async function removeWorktree(repo, path) {
4608
4833
  const branch = (await $5({ reject: false })`git -C ${path} symbolic-ref --quiet --short HEAD`).stdout.trim();
@@ -4665,7 +4890,7 @@ var init_git = __esm({
4665
4890
 
4666
4891
  // src/attachments.ts
4667
4892
  import { mkdir as mkdir2, rm as rm2, writeFile as writeFile2 } from "fs/promises";
4668
- import { join as join17 } from "path";
4893
+ import { join as join18 } from "path";
4669
4894
  var ATTACHMENTS_DIR, ATTACH_MAX_TOTAL_BYTES, ATTACH_MAX_FILE_BYTES, IMAGE_EXT, DOC_EXT, TEXT_EXT, KNOWN_EXT;
4670
4895
  var init_attachments = __esm({
4671
4896
  "src/attachments.ts"() {
@@ -4684,7 +4909,7 @@ var init_attachments = __esm({
4684
4909
 
4685
4910
  // src/shotUpload.ts
4686
4911
  import { readFile as fsReadFile } from "fs/promises";
4687
- import { basename as basename5, isAbsolute as isAbsolute2, join as join18 } from "path";
4912
+ import { basename as basename5, isAbsolute as isAbsolute2, join as join19 } from "path";
4688
4913
  var SHOT_MAX_FILE_BYTES;
4689
4914
  var init_shotUpload = __esm({
4690
4915
  "src/shotUpload.ts"() {
@@ -4735,18 +4960,18 @@ var init_prodHttp = __esm({
4735
4960
  });
4736
4961
 
4737
4962
  // src/workspace.ts
4738
- import { readFileSync as readFileSync11, writeFileSync as writeFileSync10, unlinkSync as unlinkSync4 } from "fs";
4739
- import { join as join19 } from "path";
4963
+ import { readFileSync as readFileSync13, writeFileSync as writeFileSync11, unlinkSync as unlinkSync4 } from "fs";
4964
+ import { join as join20 } from "path";
4740
4965
  function loadWorkspace() {
4741
4966
  try {
4742
- const w = JSON.parse(readFileSync11(WORKSPACE_PATH, "utf8"));
4967
+ const w = JSON.parse(readFileSync13(WORKSPACE_PATH, "utf8"));
4743
4968
  return w && typeof w.id === "string" && w.id ? w : null;
4744
4969
  } catch {
4745
4970
  return null;
4746
4971
  }
4747
4972
  }
4748
4973
  function saveWorkspace(w) {
4749
- writeFileSync10(WORKSPACE_PATH, JSON.stringify(w, null, 2), { mode: 384 });
4974
+ writeFileSync11(WORKSPACE_PATH, JSON.stringify(w, null, 2), { mode: 384 });
4750
4975
  }
4751
4976
  function clearWorkspace() {
4752
4977
  try {
@@ -4762,7 +4987,7 @@ var init_workspace = __esm({
4762
4987
  "src/workspace.ts"() {
4763
4988
  "use strict";
4764
4989
  init_config();
4765
- WORKSPACE_PATH = join19(SWARM_HOME, "workspace.json");
4990
+ WORKSPACE_PATH = join20(SWARM_HOME, "workspace.json");
4766
4991
  }
4767
4992
  });
4768
4993
 
@@ -5203,14 +5428,14 @@ var init_daemonLink = __esm({
5203
5428
  });
5204
5429
 
5205
5430
  // src/pauseState.ts
5206
- import { existsSync as existsSync12, readFileSync as readFileSync12, renameSync as renameSync5, unlinkSync as unlinkSync5, writeFileSync as writeFileSync11 } from "fs";
5207
- import { join as join20 } from "path";
5431
+ import { existsSync as existsSync13, readFileSync as readFileSync14, renameSync as renameSync5, unlinkSync as unlinkSync5, writeFileSync as writeFileSync12 } from "fs";
5432
+ import { join as join21 } from "path";
5208
5433
  function pauseStatePath(home) {
5209
- return join20(home, "pause.json");
5434
+ return join21(home, "pause.json");
5210
5435
  }
5211
5436
  function loadPauseState(home, io = {}) {
5212
- const exists = io.exists ?? existsSync12;
5213
- const readFile2 = io.readFile ?? ((p) => readFileSync12(p, "utf8"));
5437
+ const exists = io.exists ?? existsSync13;
5438
+ const readFile2 = io.readFile ?? ((p) => readFileSync14(p, "utf8"));
5214
5439
  const path = pauseStatePath(home);
5215
5440
  if (!exists(path)) return ACTIVE;
5216
5441
  try {
@@ -5229,12 +5454,12 @@ function loadPauseState(home, io = {}) {
5229
5454
  function savePauseState(home, state, io = {}) {
5230
5455
  const path = pauseStatePath(home);
5231
5456
  if (!state.paused) {
5232
- const remove = io.remove ?? ((p) => existsSync12(p) && unlinkSync5(p));
5457
+ const remove = io.remove ?? ((p) => existsSync13(p) && unlinkSync5(p));
5233
5458
  remove(path);
5234
5459
  return;
5235
5460
  }
5236
5461
  const writeFile3 = io.writeFile ?? ((p, data) => {
5237
- writeFileSync11(`${p}.tmp`, data);
5462
+ writeFileSync12(`${p}.tmp`, data);
5238
5463
  renameSync5(`${p}.tmp`, p);
5239
5464
  });
5240
5465
  writeFile3(path, JSON.stringify(state, null, 2));
@@ -5271,10 +5496,10 @@ var init_pauseState = __esm({
5271
5496
  });
5272
5497
 
5273
5498
  // src/heartbeat.ts
5274
- import { readFileSync as readFileSync13, renameSync as renameSync6, writeFileSync as writeFileSync12 } from "fs";
5499
+ import { readFileSync as readFileSync15, renameSync as renameSync6, writeFileSync as writeFileSync13 } from "fs";
5275
5500
  function readHeartbeat(path) {
5276
5501
  try {
5277
- const ms = Number(readFileSync13(path, "utf8").trim());
5502
+ const ms = Number(readFileSync15(path, "utf8").trim());
5278
5503
  return Number.isFinite(ms) ? ms : null;
5279
5504
  } catch {
5280
5505
  return null;
@@ -5293,7 +5518,7 @@ __export(db_exports, {
5293
5518
  });
5294
5519
  import { createRequire as createRequire2 } from "module";
5295
5520
  import { randomUUID as randomUUID3 } from "crypto";
5296
- import { existsSync as existsSync13 } from "fs";
5521
+ import { existsSync as existsSync14 } from "fs";
5297
5522
  import { resolve as resolve3 } from "path";
5298
5523
  function rowToQuestion(row) {
5299
5524
  return {
@@ -5957,7 +6182,7 @@ CREATE TABLE IF NOT EXISTS imports (
5957
6182
  const repoN = normalizeRepo(repo);
5958
6183
  const already = this.db.prepare("SELECT run_count FROM imports WHERE source = ?").get(abs);
5959
6184
  if (already) return { imported: false, runs: already.run_count };
5960
- if (!existsSync13(abs)) throw new Error(`import-db: \u0444\u0430\u0439\u043B\u0430 \u043D\u0435\u0442: ${abs}`);
6185
+ if (!existsSync14(abs)) throw new Error(`import-db: \u0444\u0430\u0439\u043B\u0430 \u043D\u0435\u0442: ${abs}`);
5961
6186
  const src = new this.databaseCtor(abs);
5962
6187
  try {
5963
6188
  const runs = src.prepare("SELECT * FROM runs ORDER BY id").all();
@@ -6122,7 +6347,7 @@ CREATE TABLE IF NOT EXISTS imports (
6122
6347
  }
6123
6348
  // --- events (лог/хроника) ---
6124
6349
  addEvent(run_id, kind, text, actor = null) {
6125
- const clean = sanitizeEventText(text);
6350
+ const clean = sanitizeStoredEventText(text);
6126
6351
  const insert = () => this.db.prepare("INSERT INTO events (run_id, kind, text, actor) VALUES (?, ?, ?, ?)").run(run_id, kind, clean, actor);
6127
6352
  try {
6128
6353
  insert();
@@ -6285,8 +6510,8 @@ CREATE TABLE IF NOT EXISTS imports (
6285
6510
  });
6286
6511
 
6287
6512
  // src/repoScan.ts
6288
- import { readdirSync as readdirSync11, readFileSync as readFileSync14, statSync as statSync11 } from "fs";
6289
- import { join as join21 } from "path";
6513
+ import { readdirSync as readdirSync12, readFileSync as readFileSync16, statSync as statSync12 } from "fs";
6514
+ import { join as join22 } from "path";
6290
6515
  var init_repoScan = __esm({
6291
6516
  "src/repoScan.ts"() {
6292
6517
  "use strict";
@@ -6296,8 +6521,8 @@ var init_repoScan = __esm({
6296
6521
 
6297
6522
  // src/repoDiscovery.ts
6298
6523
  import { homedir as homedir6 } from "os";
6299
- import { readFileSync as readFileSync15, renameSync as renameSync7, writeFileSync as writeFileSync13 } from "fs";
6300
- import { isAbsolute as isAbsolute3, join as join22, resolve as resolve4 } from "path";
6524
+ import { readFileSync as readFileSync17, renameSync as renameSync7, writeFileSync as writeFileSync14 } from "fs";
6525
+ import { isAbsolute as isAbsolute3, join as join23, resolve as resolve4 } from "path";
6301
6526
  function repoMapLines(rows) {
6302
6527
  if (!rows?.length) return [];
6303
6528
  const missing = rows.filter((r) => !r.path).length;
@@ -6312,7 +6537,7 @@ function repoMapLines(rows) {
6312
6537
  }
6313
6538
  function loadRepoMapCache(path) {
6314
6539
  try {
6315
- const raw = JSON.parse(readFileSync15(path, "utf8"));
6540
+ const raw = JSON.parse(readFileSync17(path, "utf8"));
6316
6541
  if (!Array.isArray(raw?.entries)) return { scannedAt: null, entries: [] };
6317
6542
  return {
6318
6543
  scannedAt: typeof raw.scannedAt === "string" && raw.scannedAt ? raw.scannedAt : null,
@@ -6688,11 +6913,11 @@ __export(statusCli_exports, {
6688
6913
  probeLink: () => probeLink,
6689
6914
  runStatusCli: () => runStatusCli
6690
6915
  });
6691
- import { existsSync as existsSync14, readFileSync as readFileSync16 } from "fs";
6916
+ import { existsSync as existsSync15, readFileSync as readFileSync18 } from "fs";
6692
6917
  function outboxPending(path) {
6693
6918
  try {
6694
- if (!existsSync14(path)) return 0;
6695
- return readFileSync16(path, "utf8").split("\n").filter((l) => l.trim()).length;
6919
+ if (!existsSync15(path)) return 0;
6920
+ return readFileSync18(path, "utf8").split("\n").filter((l) => l.trim()).length;
6696
6921
  } catch {
6697
6922
  return null;
6698
6923
  }
@@ -6899,23 +7124,23 @@ var init_prodMergeGate = __esm({
6899
7124
  });
6900
7125
 
6901
7126
  // src/platform.ts
6902
- import { existsSync as existsSync15, readFileSync as readFileSync17 } from "fs";
6903
- import { delimiter, join as join23 } from "path";
7127
+ import { accessSync, constants, existsSync as existsSync16, readFileSync as readFileSync19, realpathSync as realpathSync3 } from "fs";
7128
+ import { delimiter, join as join24, posix as posix2, win32 } from "path";
6904
7129
  function safeReadText(path) {
6905
7130
  try {
6906
- return readFileSync17(path, "utf8");
7131
+ return readFileSync19(path, "utf8");
6907
7132
  } catch {
6908
7133
  return null;
6909
7134
  }
6910
7135
  }
6911
7136
  function resolveCommandPath(name, env = process.env, platform = process.platform) {
6912
- if (name.includes("/") || name.includes("\\")) return existsSync15(name) ? name : null;
7137
+ if (name.includes("/") || name.includes("\\")) return existsSync16(name) ? name : null;
6913
7138
  const dirs = (env.PATH ?? env.Path ?? "").split(delimiter).filter(Boolean);
6914
7139
  const exts = platform === "win32" ? (env.PATHEXT ?? ".EXE;.CMD;.BAT").split(";").filter(Boolean) : [""];
6915
7140
  for (const dir of dirs) {
6916
7141
  for (const ext of exts) {
6917
- const candidate = join23(dir, name + ext);
6918
- if (existsSync15(candidate)) return candidate;
7142
+ const candidate = join24(dir, name + ext);
7143
+ if (existsSync16(candidate)) return candidate;
6919
7144
  }
6920
7145
  }
6921
7146
  return null;
@@ -6985,7 +7210,11 @@ function detectGlobalPm(entry, io = {}) {
6985
7210
  const has2 = io.hasCommand ?? ((n) => hasCommandInPath(n, env, platform));
6986
7211
  return has2("npm") ? "npm" : "unknown";
6987
7212
  }
6988
- function globalInstallCommand(pm, spec) {
7213
+ function quotePrefix(prefix, platform) {
7214
+ if (platform === "win32") return `"${prefix}"`;
7215
+ return `'${prefix.replaceAll("'", "'\\''")}'`;
7216
+ }
7217
+ function globalInstallCommand(pm, spec, prefix, platform = process.platform) {
6989
7218
  switch (pm) {
6990
7219
  case "pnpm":
6991
7220
  return `pnpm add -g ${spec}`;
@@ -6994,13 +7223,93 @@ function globalInstallCommand(pm, spec) {
6994
7223
  case "yarn":
6995
7224
  return `yarn global add ${spec}`;
6996
7225
  default:
6997
- return `npm i -g ${spec}`;
7226
+ return prefix ? `npm i -g --prefix ${quotePrefix(prefix, platform)} ${spec}` : `npm i -g ${spec}`;
7227
+ }
7228
+ }
7229
+ function resolveReal(entry, io) {
7230
+ const realpath = io.realpath ?? realpathSync3;
7231
+ try {
7232
+ return realpath(entry);
7233
+ } catch {
7234
+ return entry;
6998
7235
  }
6999
7236
  }
7000
- var LINUX_PMS, PLATFORM_LABEL;
7237
+ function npmInstallLocation(entry, io = {}) {
7238
+ if (!entry) return null;
7239
+ const platform = io.platform ?? process.platform;
7240
+ const real = resolveReal(entry, io);
7241
+ const norm = real.replace(/\\/g, "/");
7242
+ if (norm.includes("/_npx/") && norm.includes("/@taskless-app/swarm")) return { kind: "npx" };
7243
+ const marker = platform === "win32" ? WIN_MARKER : UNIX_MARKER;
7244
+ const at = norm.indexOf(marker);
7245
+ if (at < 0) return null;
7246
+ const next = norm[at + marker.length];
7247
+ if (next !== void 0 && next !== "/") return null;
7248
+ let prefix = real.slice(0, at);
7249
+ if (prefix === "") prefix = platform === "win32" ? "" : "/";
7250
+ if (!prefix) return null;
7251
+ const path = platform === "win32" ? win32 : posix2;
7252
+ const modulesDir = platform === "win32" ? path.join(prefix, "node_modules") : path.join(prefix, "lib", "node_modules");
7253
+ return { kind: "prefix", prefix, modulesDir };
7254
+ }
7255
+ function dirWritable(dir, platform, access) {
7256
+ const path = platform === "win32" ? win32 : posix2;
7257
+ let current = dir;
7258
+ for (; ; ) {
7259
+ try {
7260
+ access(current, constants.W_OK);
7261
+ return true;
7262
+ } catch (e) {
7263
+ const code = e && typeof e === "object" && "code" in e ? e.code : void 0;
7264
+ if (code !== "ENOENT") return false;
7265
+ const parent = path.dirname(current);
7266
+ if (parent === current) return false;
7267
+ current = parent;
7268
+ }
7269
+ }
7270
+ }
7271
+ function npxRefusal() {
7272
+ return `\u0440\u043E\u0439 \u0437\u0430\u043F\u0443\u0449\u0435\u043D \u0447\u0435\u0440\u0435\u0437 npx, \u043E\u0431\u043D\u043E\u0432\u043B\u044F\u0442\u044C \u043D\u0435\u0447\u0435\u0433\u043E. \u0427\u0442\u043E\u0431\u044B \u043E\u0431\u043D\u043E\u0432\u043B\u044F\u043B\u0441\u044F \u043A\u043D\u043E\u043F\u043A\u043E\u0439, \u043F\u043E\u0441\u0442\u0430\u0432\u044C \u0435\u0433\u043E \u043F\u043E\u0441\u0442\u043E\u044F\u043D\u043D\u043E: ${LATEST_INSTALL}`;
7273
+ }
7274
+ function unwritableRefusal(modulesDir, prefix, platform = process.platform) {
7275
+ const sudoInstall = `sudo ${globalInstallCommand("npm", `${SWARM_PACKAGE_NAME}@latest`, prefix, platform)}`;
7276
+ return `\u0432 \u043F\u0430\u043F\u043A\u0443 \u0443\u0441\u0442\u0430\u043D\u043E\u0432\u043A\u0438 \u043F\u0438\u0441\u0430\u0442\u044C \u043D\u0435\u043B\u044C\u0437\u044F: ${modulesDir}. npm \u043D\u0435 \u0437\u0430\u043F\u0443\u0441\u043A\u0430\u044E. \u041E\u0434\u0438\u043D \u0440\u0430\u0437: ${sudoInstall}. \u0418\u043B\u0438 \u0441\u0432\u043E\u0439 \u043A\u0430\u0442\u0430\u043B\u043E\u0433: npm config set prefix ~/.npm-global, \u0434\u043E\u0431\u0430\u0432\u044C ~/.npm-global/bin \u0432 PATH \u0438 \u043F\u043E\u0441\u0442\u0430\u0432\u044C \u0437\u0430\u043D\u043E\u0432\u043E.`;
7277
+ }
7278
+ function gatePackageInstall(pm, spec, entry, io = {}) {
7279
+ if (pm === "pnpm" || pm === "bun" || pm === "yarn") {
7280
+ return { action: "run", command: globalInstallCommand(pm, spec) };
7281
+ }
7282
+ if (pm === "sources") {
7283
+ return { action: "run", command: globalInstallCommand("npm", spec) };
7284
+ }
7285
+ const loc = npmInstallLocation(entry, io);
7286
+ if (loc?.kind === "npx") return { action: "refuse", kind: "npx", message: npxRefusal() };
7287
+ if (loc?.kind === "prefix") {
7288
+ const platform = io.platform ?? process.platform;
7289
+ const access = io.access ?? accessSync;
7290
+ if (!dirWritable(loc.modulesDir, platform, access)) {
7291
+ return { action: "refuse", kind: "unwritable", message: unwritableRefusal(loc.modulesDir, loc.prefix, platform) };
7292
+ }
7293
+ return { action: "run", command: globalInstallCommand("npm", spec, loc.prefix, platform) };
7294
+ }
7295
+ return { action: "run", command: globalInstallCommand("npm", spec) };
7296
+ }
7297
+ function npmFailureCode(output) {
7298
+ const plain = output.replace(/\u001b\[[0-9;]*m/g, "");
7299
+ const tagged = plain.match(/(?:npm ERR!|npm error) code ([A-Z][A-Z0-9_]*)/);
7300
+ if (tagged?.[1]) return tagged[1];
7301
+ const bare = plain.match(/\bError: ([A-Z][A-Z0-9_]*):/);
7302
+ return bare?.[1] ?? null;
7303
+ }
7304
+ function installFailureLabel(exitCode, output) {
7305
+ const code = npmFailureCode(output);
7306
+ return code ? `${code}, \u043A\u043E\u0434 ${exitCode}` : `\u043A\u043E\u0434 ${exitCode}`;
7307
+ }
7308
+ var LINUX_PMS, PLATFORM_LABEL, UNIX_MARKER, WIN_MARKER, LATEST_INSTALL;
7001
7309
  var init_platform = __esm({
7002
7310
  "src/platform.ts"() {
7003
7311
  "use strict";
7312
+ init_src();
7004
7313
  LINUX_PMS = [
7005
7314
  { cmd: "apt-get", pm: "apt" },
7006
7315
  { cmd: "dnf", pm: "dnf" },
@@ -7014,17 +7323,20 @@ var init_platform = __esm({
7014
7323
  wsl: "WSL2 (Linux \u0432\u043D\u0443\u0442\u0440\u0438 Windows)",
7015
7324
  windows: "Windows (\u043D\u0430\u0442\u0438\u0432\u043D\u0430\u044F)"
7016
7325
  };
7326
+ UNIX_MARKER = "/lib/node_modules/@taskless-app/swarm";
7327
+ WIN_MARKER = "/node_modules/@taskless-app/swarm";
7328
+ LATEST_INSTALL = `npm i -g ${SWARM_PACKAGE_NAME}@latest`;
7017
7329
  }
7018
7330
  });
7019
7331
 
7020
7332
  // src/envGate.ts
7021
- import { existsSync as existsSync16 } from "fs";
7022
- import { join as join24 } from "path";
7333
+ import { existsSync as existsSync17 } from "fs";
7334
+ import { join as join25 } from "path";
7023
7335
  import { createConnection } from "net";
7024
7336
  import { execa as execa3 } from "execa";
7025
7337
  function detectRequirements(repo, io = {}) {
7026
- const exists = io.exists ?? existsSync16;
7027
- const marker = COMPOSE_MARKERS.find((f) => exists(join24(repo, f)));
7338
+ const exists = io.exists ?? existsSync17;
7339
+ const marker = COMPOSE_MARKERS.find((f) => exists(join25(repo, f)));
7028
7340
  return marker ? [{ kind: "docker", raw: `docker (\u0434\u0435\u0442\u0435\u043A\u0442: ${marker})` }] : [];
7029
7341
  }
7030
7342
  async function dockerAlive() {
@@ -7056,7 +7368,7 @@ var init_envGate = __esm({
7056
7368
  });
7057
7369
 
7058
7370
  // src/doctor.ts
7059
- import { isAbsolute as isAbsolute4, join as join25 } from "path";
7371
+ import { isAbsolute as isAbsolute4, join as join26 } from "path";
7060
7372
  function ok(id, title, detail) {
7061
7373
  return { id, title, status: "ok", detail, remedies: [], critical: false };
7062
7374
  }
@@ -7265,7 +7577,7 @@ function checkRepos(io, snap) {
7265
7577
  critical: true
7266
7578
  };
7267
7579
  }
7268
- if (env && !io.exists(join25(env, ".git"))) {
7580
+ if (env && !io.exists(join26(env, ".git"))) {
7269
7581
  return {
7270
7582
  id: "repos",
7271
7583
  title,
@@ -7275,7 +7587,7 @@ function checkRepos(io, snap) {
7275
7587
  critical: true
7276
7588
  };
7277
7589
  }
7278
- const broken = snap.paths.filter((p) => !io.exists(join25(p, ".git")));
7590
+ const broken = snap.paths.filter((p) => !io.exists(join26(p, ".git")));
7279
7591
  if (broken.length) {
7280
7592
  return {
7281
7593
  id: "repos",
@@ -7465,12 +7777,12 @@ var init_doctor = __esm({
7465
7777
  });
7466
7778
 
7467
7779
  // src/repoMemory.ts
7468
- import { readFileSync as readFileSync18, writeFileSync as writeFileSync14 } from "fs";
7469
- import { join as join26 } from "path";
7780
+ import { readFileSync as readFileSync20, writeFileSync as writeFileSync15 } from "fs";
7781
+ import { join as join27 } from "path";
7470
7782
  function loadRememberedRepos(home) {
7471
7783
  let raw;
7472
7784
  try {
7473
- raw = readFileSync18(join26(home, FILE), "utf8");
7785
+ raw = readFileSync20(join27(home, FILE), "utf8");
7474
7786
  } catch {
7475
7787
  return [];
7476
7788
  }
@@ -7506,7 +7818,7 @@ __export(installCli_exports, {
7506
7818
  runInstallHookCli: () => runInstallHookCli,
7507
7819
  shortenError: () => shortenError
7508
7820
  });
7509
- import { existsSync as existsSync17 } from "fs";
7821
+ import { existsSync as existsSync18 } from "fs";
7510
7822
  function classifyChromiumError(message) {
7511
7823
  if (/playwright-core не установлен|Cannot find (module|package)/i.test(message)) return "no-module";
7512
7824
  if (/error while loading shared libraries|cannot open shared object file|missing dependencies|\blib[\w.+-]*\.so[.\d]*\b/i.test(message)) return "no-libs";
@@ -7561,7 +7873,7 @@ function defaultDoctorIO(packageVersion) {
7561
7873
  packageVersion,
7562
7874
  entry,
7563
7875
  hasCommand: (name) => hasCommandInPath(name),
7564
- exists: existsSync17,
7876
+ exists: existsSync18,
7565
7877
  run: (command) => runQuiet(command),
7566
7878
  latestVersion: () => latestMemo ??= fetchLatestVersion(),
7567
7879
  probeChromium: () => probeChromium(),
@@ -7741,17 +8053,24 @@ __export(updateCli_exports, {
7741
8053
  async function runUpdateCli(argv, deps) {
7742
8054
  const out = deps.out ?? ((l) => console.log(l));
7743
8055
  const err = deps.err ?? ((l) => console.error(l));
7744
- const pm = deps.globalPm ?? detectGlobalPm(process.argv[1]);
7745
- const exec = deps.exec ?? execLoud;
8056
+ const entry = deps.entry ?? process.argv[1];
8057
+ const pm = deps.globalPm ?? detectGlobalPm(entry);
8058
+ const exec = deps.exec ?? execCaptured;
7746
8059
  const latestVersion = deps.latestVersion ?? (() => fetchLatestVersion());
7747
8060
  const daemonAlive = deps.daemonAlive ?? (async () => await daemonStatus2() != null);
7748
8061
  const force = argv.includes("--force");
8062
+ const launchIO = deps.launchIO;
7749
8063
  if (pm === "sources") {
7750
8064
  err("\u0442\u044B \u0437\u0430\u043F\u0443\u0449\u0435\u043D \u0418\u0417 \u0418\u0421\u0425\u041E\u0414\u041D\u0418\u041A\u041E\u0412 \u043C\u043E\u043D\u043E\u0440\u0435\u043F\u044B, \u0430 \u043D\u0435 \u0438\u0437 \u0443\u0441\u0442\u0430\u043D\u043E\u0432\u043B\u0435\u043D\u043D\u043E\u0433\u043E \u043F\u0430\u043A\u0435\u0442\u0430 \u2014 \u043E\u0431\u043D\u043E\u0432\u043B\u044F\u0442\u044C npm-\u043E\u043C \u0442\u0443\u0442 \u043D\u0435\u0447\u0435\u0433\u043E.");
7751
8065
  err(" \u0441\u0432\u0435\u0436\u0438\u0439 \u043A\u043E\u0434 \u0440\u0435\u043F\u043E\u0437\u0438\u0442\u043E\u0440\u0438\u044F: git pull && pnpm install && pnpm --filter @taskless-app/swarm... build");
7752
8066
  err(` \u043F\u043E\u0441\u0442\u0430\u0432\u0438\u0442\u044C \u043F\u0430\u043A\u0435\u0442 \u0440\u044F\u0434\u043E\u043C: ${globalInstallCommand("npm", SWARM_PACKAGE)}`);
7753
8067
  return 1;
7754
8068
  }
8069
+ const early = gatePackageInstall(pm, `${SWARM_PACKAGE}@latest`, entry, launchIO);
8070
+ if (early.action === "refuse" && early.kind === "npx") {
8071
+ err(early.message);
8072
+ return 1;
8073
+ }
7755
8074
  const latest = await latestVersion();
7756
8075
  if (latest === null) {
7757
8076
  err("\u0434\u043E registry.npmjs.org \u043D\u0435 \u0434\u043E\u0437\u0432\u043E\u043D\u0438\u043B\u0438\u0441\u044C \u2014 \u043A\u0430\u043A\u0430\u044F \u0432\u0435\u0440\u0441\u0438\u044F \u043E\u043F\u0443\u0431\u043B\u0438\u043A\u043E\u0432\u0430\u043D\u0430, \u0443\u0437\u043D\u0430\u0442\u044C \u043D\u0435\u0447\u0435\u043C. \u041F\u0440\u043E\u0432\u0435\u0440\u044C \u0441\u0435\u0442\u044C \u0438 \u043F\u043E\u0432\u0442\u043E\u0440\u0438.");
@@ -7761,13 +8080,18 @@ async function runUpdateCli(argv, deps) {
7761
8080
  out(`\u0443\u0436\u0435 \u0441\u0432\u0435\u0436\u0430\u044F \u0432\u0435\u0440\u0441\u0438\u044F: v${deps.packageVersion} (\u043E\u043F\u0443\u0431\u043B\u0438\u043A\u043E\u0432\u0430\u043D\u0430 v${latest}) \u2014 \u043E\u0431\u043D\u043E\u0432\u043B\u044F\u0442\u044C \u043D\u0435\u0447\u0435\u0433\u043E.`);
7762
8081
  return 0;
7763
8082
  }
7764
- const command = globalInstallCommand(pm, `${SWARM_PACKAGE}@${latest}`);
8083
+ const decided = gatePackageInstall(pm, `${SWARM_PACKAGE}@${latest}`, entry, launchIO);
8084
+ if (decided.action === "refuse") {
8085
+ err(decided.message);
8086
+ return 1;
8087
+ }
8088
+ const command = decided.command;
7765
8089
  out(`\u043E\u0431\u043D\u043E\u0432\u043B\u044F\u044E \u0440\u043E\u0439: v${deps.packageVersion} \u2192 v${latest}`);
7766
8090
  out(` $ ${command}`);
7767
- const code = await exec(command);
7768
- if (code !== 0) {
7769
- err(`\u043E\u0431\u043D\u043E\u0432\u043B\u0435\u043D\u0438\u0435 \u043D\u0435 \u043F\u0440\u043E\u0448\u043B\u043E (\u043A\u043E\u0434 ${code}). \u0421\u0442\u0440\u043E\u043A\u0430 \u0432\u044B\u0448\u0435 \u2014 \u0442\u0430 \u0441\u0430\u043C\u0430\u044F, \u0447\u0442\u043E \u043D\u0443\u0436\u043D\u0430; \u0432\u044B\u043F\u043E\u043B\u043D\u0438 \u0435\u0451 \u0440\u0443\u043A\u0430\u043C\u0438 \u0438 \u043F\u043E\u0441\u043C\u043E\u0442\u0440\u0438, \u043D\u0430 \u0447\u0451\u043C \u0441\u043F\u043E\u0442\u044B\u043A\u0430\u0435\u0442\u0441\u044F.`);
7770
- return code;
8091
+ const ran = readCommandOutcome(await exec(command));
8092
+ if (ran.exitCode !== 0) {
8093
+ err(`\u043E\u0431\u043D\u043E\u0432\u043B\u0435\u043D\u0438\u0435 \u043D\u0435 \u043F\u0440\u043E\u0448\u043B\u043E (${installFailureLabel(ran.exitCode, ran.output)}). \u0421\u0442\u0440\u043E\u043A\u0430 \u0432\u044B\u0448\u0435 \u2014 \u0442\u0430 \u0441\u0430\u043C\u0430\u044F, \u0447\u0442\u043E \u043D\u0443\u0436\u043D\u0430; \u0432\u044B\u043F\u043E\u043B\u043D\u0438 \u0435\u0451 \u0440\u0443\u043A\u0430\u043C\u0438 \u0438 \u043F\u043E\u0441\u043C\u043E\u0442\u0440\u0438, \u043D\u0430 \u0447\u0451\u043C \u0441\u043F\u043E\u0442\u044B\u043A\u0430\u0435\u0442\u0441\u044F.`);
8094
+ return ran.exitCode;
7771
8095
  }
7772
8096
  out(`\u0433\u043E\u0442\u043E\u0432\u043E: v${latest}`);
7773
8097
  if (await daemonAlive()) {
@@ -7789,8 +8113,8 @@ var init_updateCli = __esm({
7789
8113
 
7790
8114
  // src/cli.ts
7791
8115
  init_cliIo();
7792
- import { basename as basename6, dirname as dirname5, join as join27 } from "path";
7793
- import { existsSync as existsSync18, readFileSync as readFileSync19, writeFileSync as writeFileSync15, mkdirSync as mkdirSync11, readdirSync as readdirSync12, statSync as statSync12, openSync as openSync5, readSync as readSync2, closeSync as closeSync5 } from "fs";
8116
+ import { basename as basename6, dirname as dirname5, join as join28 } from "path";
8117
+ import { existsSync as existsSync19, readFileSync as readFileSync21, writeFileSync as writeFileSync16, mkdirSync as mkdirSync12, readdirSync as readdirSync13, statSync as statSync13, openSync as openSync5, readSync as readSync2, closeSync as closeSync5 } from "fs";
7794
8118
  import { setTimeout as sleep2 } from "timers/promises";
7795
8119
 
7796
8120
  // src/swarmClient.ts
@@ -7798,7 +8122,7 @@ init_config();
7798
8122
  init_resources();
7799
8123
  init_names2();
7800
8124
  init_storm();
7801
- import { appendFileSync, existsSync as existsSync7, mkdirSync as mkdirSync7, readFileSync as readFileSync6, writeFileSync as writeFileSync6 } from "fs";
8125
+ import { appendFileSync, existsSync as existsSync8, mkdirSync as mkdirSync8, readFileSync as readFileSync7, writeFileSync as writeFileSync7 } from "fs";
7802
8126
  import { dirname as dirname2 } from "path";
7803
8127
  import { randomUUID } from "crypto";
7804
8128
 
@@ -7832,24 +8156,24 @@ init_store();
7832
8156
  init_toolFailure();
7833
8157
 
7834
8158
  // src/logTail.ts
7835
- import { closeSync, existsSync as existsSync6, openSync, readSync, readdirSync as readdirSync7, statSync as statSync6 } from "fs";
7836
- import { join as join10 } from "path";
8159
+ import { closeSync, existsSync as existsSync7, openSync, readSync, readdirSync as readdirSync8, statSync as statSync7 } from "fs";
8160
+ import { join as join11 } from "path";
7837
8161
 
7838
8162
  // src/runLogDir.ts
7839
- import { existsSync as existsSync5, mkdirSync as mkdirSync6, readdirSync as readdirSync6, renameSync as renameSync2, statSync as statSync5 } from "fs";
7840
- import { join as join9 } from "path";
8163
+ import { existsSync as existsSync6, mkdirSync as mkdirSync7, readdirSync as readdirSync7, renameSync as renameSync2, statSync as statSync6 } from "fs";
8164
+ import { join as join10 } from "path";
7841
8165
  function runLogDirName(runLogKey) {
7842
8166
  const safe = runLogKey.replace(/[^A-Za-z0-9_-]+/g, "-").replace(/^[-_]+|[-_]+$/g, "");
7843
8167
  if (!safe) throw new Error(`\u043A\u043B\u044E\u0447 \u043F\u0440\u043E\u0433\u043E\u043D\u0430 \u043D\u0435 \u0433\u043E\u0434\u0438\u0442\u0441\u044F \u0432 \u0438\u043C\u044F \u043A\u0430\u0442\u0430\u043B\u043E\u0433\u0430 run-log'\u043E\u0432: ${JSON.stringify(runLogKey)}`);
7844
8168
  return /^\d+$/.test(safe) ? `k-${safe}` : safe;
7845
8169
  }
7846
8170
  function runLogDirPath(runLogsDir, runLogKey) {
7847
- return join9(runLogsDir, runLogDirName(runLogKey));
8171
+ return join10(runLogsDir, runLogDirName(runLogKey));
7848
8172
  }
7849
8173
  function findRunLogDir(runLogsDir, keys) {
7850
8174
  for (const key of keys) {
7851
8175
  const dir = runLogDirPath(runLogsDir, key);
7852
- if (existsSync5(dir)) return dir;
8176
+ if (existsSync6(dir)) return dir;
7853
8177
  }
7854
8178
  return null;
7855
8179
  }
@@ -8066,26 +8390,26 @@ var SwarmClient = class _SwarmClient {
8066
8390
  this.repoFullNames = registry.map((e) => e.repoFullName);
8067
8391
  this.repoPathByFullName = new Map(registry.map((e) => [e.repoFullName, normalizeRepo(e.path)]));
8068
8392
  this.host = opts.host ?? null;
8069
- this.repoExists = opts.repoExists ?? existsSync7;
8393
+ this.repoExists = opts.repoExists ?? existsSync8;
8070
8394
  this.questionSyncMs = opts.questionSyncMs ?? 3e3;
8071
8395
  this.executorId = opts.executorId ?? EXECUTOR.id;
8072
8396
  this.outboxPath = opts.outboxPath;
8073
8397
  this.mapPath = `${opts.outboxPath}.prodmap.json`;
8074
8398
  this.stormPath = `${opts.outboxPath}.storm.jsonl`;
8075
- mkdirSync7(dirname2(this.outboxPath), { recursive: true });
8399
+ mkdirSync8(dirname2(this.outboxPath), { recursive: true });
8076
8400
  this.recover();
8077
8401
  }
8078
8402
  // ── рестарт: поднять outbox (незаписанные операции) и карту runKey→prodId ─────
8079
8403
  recover() {
8080
- if (existsSync7(this.mapPath)) {
8404
+ if (existsSync8(this.mapPath)) {
8081
8405
  try {
8082
- const obj = JSON.parse(readFileSync6(this.mapPath, "utf8"));
8406
+ const obj = JSON.parse(readFileSync7(this.mapPath, "utf8"));
8083
8407
  for (const [k, v] of Object.entries(obj)) this.prodIdByKey.set(k, v);
8084
8408
  } catch {
8085
8409
  }
8086
8410
  }
8087
- if (existsSync7(this.outboxPath)) {
8088
- const txt = readFileSync6(this.outboxPath, "utf8");
8411
+ if (existsSync8(this.outboxPath)) {
8412
+ const txt = readFileSync7(this.outboxPath, "utf8");
8089
8413
  for (const line of txt.split("\n")) {
8090
8414
  const s = line.trim();
8091
8415
  if (!s) continue;
@@ -8105,10 +8429,10 @@ var SwarmClient = class _SwarmClient {
8105
8429
  // eventsLog ПЕРВЫМИ (до hydrate), в порядке файла (= хронологический); id
8106
8430
  // переприсваиваем локально (id событий — только порядок, не корреляция с продом).
8107
8431
  replayGlobalEvents() {
8108
- if (!existsSync7(this.stormPath)) return;
8432
+ if (!existsSync8(this.stormPath)) return;
8109
8433
  let txt;
8110
8434
  try {
8111
- txt = readFileSync6(this.stormPath, "utf8");
8435
+ txt = readFileSync7(this.stormPath, "utf8");
8112
8436
  } catch {
8113
8437
  return;
8114
8438
  }
@@ -8844,7 +9168,7 @@ var SwarmClient = class _SwarmClient {
8844
9168
  }
8845
9169
  // ── events / хроника ─────────────────────────────────────────────────────────
8846
9170
  addEvent(run_id, kind, text, actor = null) {
8847
- const clean = sanitizeEventText(text);
9171
+ const clean = sanitizeStoredEventText(text);
8848
9172
  const ev = { id: this.nextEventId++, run_id, kind, text: clean, actor: actor ?? null, at: stamp() };
8849
9173
  this.eventsLog.push(ev);
8850
9174
  if (run_id == null) {
@@ -9105,7 +9429,7 @@ var SwarmClient = class _SwarmClient {
9105
9429
  * транзиентным сбоем ОС, который этот PR должен переживать, а не превращать в мор.
9106
9430
  */
9107
9431
  reconcileRuntime(opts) {
9108
- const wtExists = opts.worktreeExists ?? existsSync7;
9432
+ const wtExists = opts.worktreeExists ?? existsSync8;
9109
9433
  const pidByWorktree = /* @__PURE__ */ new Map();
9110
9434
  try {
9111
9435
  for (const p of opts.listProcesses()) if (p.worktree) pidByWorktree.set(p.worktree, p.pid);
@@ -10373,13 +10697,13 @@ var SwarmClient = class _SwarmClient {
10373
10697
  }
10374
10698
  persistPending() {
10375
10699
  try {
10376
- writeFileSync6(this.outboxPath, this.pending.map((e) => JSON.stringify(e)).join("\n") + (this.pending.length ? "\n" : ""));
10700
+ writeFileSync7(this.outboxPath, this.pending.map((e) => JSON.stringify(e)).join("\n") + (this.pending.length ? "\n" : ""));
10377
10701
  } catch {
10378
10702
  }
10379
10703
  }
10380
10704
  persistMap() {
10381
10705
  try {
10382
- writeFileSync6(this.mapPath, JSON.stringify(Object.fromEntries(this.prodIdByKey)));
10706
+ writeFileSync7(this.mapPath, JSON.stringify(Object.fromEntries(this.prodIdByKey)));
10383
10707
  } catch {
10384
10708
  }
10385
10709
  }
@@ -10512,7 +10836,7 @@ init_config();
10512
10836
  import { $ as $6 } from "execa";
10513
10837
 
10514
10838
  // src/daemonLaunch.ts
10515
- import { openSync as openSync2, closeSync as closeSync2, readFileSync as readFileSync7 } from "fs";
10839
+ import { openSync as openSync2, closeSync as closeSync2, readFileSync as readFileSync8 } from "fs";
10516
10840
  import { spawn } from "child_process";
10517
10841
  var FOREGROUND_FLAGS = /* @__PURE__ */ new Set(["--foreground", "-f", "--attach"]);
10518
10842
  function parseStartMode(argv) {
@@ -10572,27 +10896,27 @@ function launchDetached(opts) {
10572
10896
  }
10573
10897
  function tailFile(path, lines) {
10574
10898
  try {
10575
- return tailText(readFileSync7(path, "utf8"), lines);
10899
+ return tailText(readFileSync8(path, "utf8"), lines);
10576
10900
  } catch {
10577
10901
  return "";
10578
10902
  }
10579
10903
  }
10580
10904
 
10581
10905
  // src/logRotate.ts
10582
- import { copyFileSync as copyFileSync4, renameSync as renameSync3, statSync as statSync7, fstatSync, truncateSync, unlinkSync as unlinkSync2, existsSync as existsSync8, openSync as openSync3, writeSync, closeSync as closeSync3 } from "fs";
10906
+ import { copyFileSync as copyFileSync5, renameSync as renameSync3, statSync as statSync8, fstatSync, truncateSync, unlinkSync as unlinkSync2, existsSync as existsSync9, openSync as openSync3, writeSync, closeSync as closeSync3 } from "fs";
10583
10907
  var realIo = {
10584
10908
  size: (path) => {
10585
10909
  try {
10586
- return statSync7(path).size;
10910
+ return statSync8(path).size;
10587
10911
  } catch {
10588
10912
  return null;
10589
10913
  }
10590
10914
  },
10591
- copy: copyFileSync4,
10915
+ copy: copyFileSync5,
10592
10916
  rename: renameSync3,
10593
10917
  truncate: (path) => truncateSync(path, 0),
10594
10918
  unlink: unlinkSync2,
10595
- exists: existsSync8
10919
+ exists: existsSync9
10596
10920
  };
10597
10921
  var realOwnerIo = {
10598
10922
  statFd: (fd) => {
@@ -10605,7 +10929,7 @@ var realOwnerIo = {
10605
10929
  },
10606
10930
  statPath: (path) => {
10607
10931
  try {
10608
- const s = statSync7(path);
10932
+ const s = statSync8(path);
10609
10933
  return { dev: s.dev, ino: s.ino };
10610
10934
  } catch {
10611
10935
  return null;
@@ -10672,17 +10996,17 @@ init_repoRegistry();
10672
10996
 
10673
10997
  // src/hostIdentity.ts
10674
10998
  import { hostname } from "os";
10675
- import { existsSync as existsSync9, readFileSync as readFileSync8, renameSync as renameSync4, writeFileSync as writeFileSync7 } from "fs";
10676
- import { join as join11 } from "path";
10999
+ import { existsSync as existsSync10, readFileSync as readFileSync10, renameSync as renameSync4, writeFileSync as writeFileSync8 } from "fs";
11000
+ import { join as join12 } from "path";
10677
11001
  import { randomUUID as randomUUID2 } from "crypto";
10678
11002
  function hostIdentityPath(home) {
10679
- return join11(home, "host.json");
11003
+ return join12(home, "host.json");
10680
11004
  }
10681
11005
  function loadHostIdentity(deps) {
10682
- const exists = deps.exists ?? existsSync9;
10683
- const readFile2 = deps.readFile ?? ((p) => readFileSync8(p, "utf8"));
11006
+ const exists = deps.exists ?? existsSync10;
11007
+ const readFile2 = deps.readFile ?? ((p) => readFileSync10(p, "utf8"));
10684
11008
  const writeFile3 = deps.writeFile ?? ((p, data) => {
10685
- writeFileSync7(`${p}.tmp`, data);
11009
+ writeFileSync8(`${p}.tmp`, data);
10686
11010
  renameSync4(`${p}.tmp`, p);
10687
11011
  });
10688
11012
  const host = deps.hostname ?? hostname;
@@ -10797,8 +11121,8 @@ import { basename as basename4 } from "path";
10797
11121
  import { serve as serve2 } from "@hono/node-server";
10798
11122
 
10799
11123
  // src/diff.ts
10800
- import { statSync as statSync8 } from "fs";
10801
- import { join as join12 } from "path";
11124
+ import { statSync as statSync9 } from "fs";
11125
+ import { join as join13 } from "path";
10802
11126
  import { $ as $3 } from "execa";
10803
11127
  var MAX_FILES = 200;
10804
11128
  var MAX_LINES_PER_FILE = 1500;
@@ -10941,7 +11265,7 @@ async function resolveBase(wt, baseBranch) {
10941
11265
  }
10942
11266
  function mtime(path) {
10943
11267
  try {
10944
- return statSync8(path).mtimeMs;
11268
+ return statSync9(path).mtimeMs;
10945
11269
  } catch {
10946
11270
  return 0;
10947
11271
  }
@@ -10966,7 +11290,7 @@ async function collectRunDiff(worktree, opts = {}) {
10966
11290
  files.push(pf);
10967
11291
  }
10968
11292
  }
10969
- files.sort((a, b) => mtime(join12(worktree, b.path)) - mtime(join12(worktree, a.path)));
11293
+ files.sort((a, b) => mtime(join13(worktree, b.path)) - mtime(join13(worktree, a.path)));
10970
11294
  const truncatedFiles = files.length > MAX_FILES;
10971
11295
  if (truncatedFiles) files = files.slice(0, MAX_FILES);
10972
11296
  const added = files.reduce((s, f) => s + f.added, 0);
@@ -11010,6 +11334,10 @@ function ghRepoRunner(timeoutMs = GH_CALL_TIMEOUT_MS) {
11010
11334
  }
11011
11335
  var realRunner = ghRunner();
11012
11336
  var realRepoRunner = ghRepoRunner();
11337
+ var GH_PR_RE = /^(?:https?:\/\/)?(?:www\.)?github\.com\/[^/\s]+\/[^/\s]+\/pull\/\d+(?:[/?#].*)?$/i;
11338
+ function isGithubPrUrl(url) {
11339
+ return GH_PR_RE.test(url.trim());
11340
+ }
11013
11341
  async function openPrsForBranch(branch, repoDir, run = realRepoRunner) {
11014
11342
  if (!branch || !repoDir) return [];
11015
11343
  try {
@@ -11020,6 +11348,140 @@ async function openPrsForBranch(branch, repoDir, run = realRepoRunner) {
11020
11348
  return [];
11021
11349
  }
11022
11350
  }
11351
+ var FINDING_CATEGORIES = [
11352
+ "correctness",
11353
+ "security",
11354
+ "reuse",
11355
+ "boundaries",
11356
+ "over-abstraction",
11357
+ "duplication",
11358
+ "spine",
11359
+ "tests",
11360
+ "ui-rules"
11361
+ ];
11362
+ var FINDING_SEVERITIES = ["blocker", "major", "nit"];
11363
+ var FINDINGS_BLOCK_RE = /```findings[^\n]*\n([\s\S]*?)```/gi;
11364
+ var READ_ONLY_PHRASE_RE = /прогнать не мог|окружения нет/i;
11365
+ var FINDING_WHAT_MAX = 400;
11366
+ var FINDING_PATH_MAX = 300;
11367
+ var FINDINGS_MAX = 50;
11368
+ function oneOf(dict, v) {
11369
+ return typeof v === "string" && dict.includes(v) ? v : null;
11370
+ }
11371
+ function normalizeFinding(raw) {
11372
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
11373
+ const r = raw;
11374
+ const what = typeof r.what === "string" ? r.what.trim().slice(0, FINDING_WHAT_MAX) : "";
11375
+ if (!what) return null;
11376
+ const rawLine = typeof r.line === "number" ? r.line : typeof r.line === "string" && r.line.trim() ? Number(r.line) : NaN;
11377
+ return {
11378
+ category: oneOf(FINDING_CATEGORIES, r.category),
11379
+ severity: oneOf(FINDING_SEVERITIES, r.severity),
11380
+ path: typeof r.path === "string" && r.path.trim() ? r.path.trim().slice(0, FINDING_PATH_MAX) : null,
11381
+ // Номер строки — только целый положительный: «7.5», «-1» и NaN значат, что ревьюер
11382
+ // строку не знал, а не что дефект на строке −1 (по такому числу потом ищут в файле).
11383
+ line: Number.isInteger(rawLine) && rawLine > 0 ? rawLine : null,
11384
+ what
11385
+ };
11386
+ }
11387
+ function parseFindingsBlock(body) {
11388
+ const byPhrase = READ_ONLY_PHRASE_RE.test(body) ? "read" : null;
11389
+ const blocks = [...body.matchAll(FINDINGS_BLOCK_RE)];
11390
+ const last = blocks[blocks.length - 1];
11391
+ if (!last) return { findings: null, mode: byPhrase };
11392
+ let payload;
11393
+ try {
11394
+ payload = JSON.parse(last[1]);
11395
+ } catch {
11396
+ console.warn("[gh] \u0431\u043B\u043E\u043A findings \u0432 \u0432\u0435\u0440\u0434\u0438\u043A\u0442-\u043A\u043E\u043C\u043C\u0435\u043D\u0442\u0435 \u043D\u0435 \u0440\u0430\u0437\u043E\u0431\u0440\u0430\u043D (\u0431\u0438\u0442\u044B\u0439 JSON) \u2014 \u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u0437\u0430\u0441\u0447\u0438\u0442\u0430\u043D, \u043D\u0430\u0445\u043E\u0434\u043E\u043A \u043D\u0435\u0442");
11397
+ return { findings: null, mode: byPhrase };
11398
+ }
11399
+ const arr = Array.isArray(payload) ? payload : payload && typeof payload === "object" && Array.isArray(payload.findings) ? payload.findings : null;
11400
+ const mode = payload && typeof payload === "object" && !Array.isArray(payload) ? oneOf(["ran", "read"], payload.mode) ?? byPhrase : byPhrase;
11401
+ if (!arr) {
11402
+ console.warn("[gh] \u0431\u043B\u043E\u043A findings \u0432 \u0432\u0435\u0440\u0434\u0438\u043A\u0442-\u043A\u043E\u043C\u043C\u0435\u043D\u0442\u0435 \u043D\u0435 \u0441\u043E\u0434\u0435\u0440\u0436\u0438\u0442 \u043C\u0430\u0441\u0441\u0438\u0432\u0430 \u043D\u0430\u0445\u043E\u0434\u043E\u043A \u2014 \u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u0437\u0430\u0441\u0447\u0438\u0442\u0430\u043D, \u043D\u0430\u0445\u043E\u0434\u043E\u043A \u043D\u0435\u0442");
11403
+ return { findings: null, mode };
11404
+ }
11405
+ const capped = arr.slice(0, FINDINGS_MAX);
11406
+ if (arr.length > capped.length) {
11407
+ console.warn(`[gh] \u0432 \u0431\u043B\u043E\u043A\u0435 findings ${arr.length} \u0437\u0430\u043F\u0438\u0441\u0435\u0439 \u2014 \u0431\u0435\u0440\u0443 \u043F\u0435\u0440\u0432\u044B\u0435 ${FINDINGS_MAX}, \u043E\u0441\u0442\u0430\u043B\u044C\u043D\u043E\u0435 \u043E\u0442\u0431\u0440\u043E\u0448\u0435\u043D\u043E`);
11408
+ }
11409
+ const findings = capped.map((raw) => normalizeFinding(raw)).filter((f) => f != null);
11410
+ if (findings.length < capped.length) {
11411
+ console.warn("[gh] \u0432 \u0431\u043B\u043E\u043A\u0435 findings \u043F\u0440\u043E\u043F\u0443\u0449\u0435\u043D\u043E \u0437\u0430\u043F\u0438\u0441\u0435\u0439 \u0431\u0435\u0437 \u0441\u0443\u0442\u0438: " + (capped.length - findings.length));
11412
+ }
11413
+ return { findings, mode };
11414
+ }
11415
+ var realCommentsRunner = (prUrl) => runGh(["pr", "view", prUrl, "--json", "comments"], GH_CALL_TIMEOUT_MS);
11416
+ var CHANGES_FIRST_LINE_RE = new RegExp(
11417
+ [
11418
+ "^#\\d+:\\s*CHANGES\\b",
11419
+ "^#\\d+\\s+\u043A\u0440\u0443\u0433\\s+\\d+\\s*:\\s*CHANGES\\b",
11420
+ "^\u041D\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043C\u043E\u0435 \u0440\u0435\u0432\u044C\u044E\\s*[\u2014\u2013-]\\s*CHANGES\\b",
11421
+ "^(?:\u274C\\s*)?(?:\\*\\*)?REQUEST(?:ED)?\\s+CHANGES(?:\\*\\*)?\\b",
11422
+ "^(?:\\*\\*)?CHANGES(?:\\s+REQUESTED)?(?:\\*\\*)?(?=\\s*(?:$|[:.!(\u2014\u2013-]))",
11423
+ '^[\xAB"]?\u043D\u0443\u0436\u043D\u044B \u043F\u0440\u0430\u0432\u043A\u0438[\xBB"]?(?=\\s*(?:$|[:.!(\u2014\u2013-]))'
11424
+ ].join("|"),
11425
+ "iu"
11426
+ );
11427
+ var APPROVE_FIRST_LINE_RE = /^(?:✅\s*)?(?:\*\*)?(?:APPROVED?|LGTM)(?:\*\*)?\b/iu;
11428
+ function firstContentLine(body) {
11429
+ for (const line of body.split(/\r?\n/)) {
11430
+ const trimmed = line.trim();
11431
+ if (trimmed) return trimmed;
11432
+ }
11433
+ return "";
11434
+ }
11435
+ function classifyPrVerdict(body) {
11436
+ const line = firstContentLine(body);
11437
+ if (!line) return null;
11438
+ if (line.includes(DRONE_COMMENT_SIGNATURE)) return null;
11439
+ if (CHANGES_FIRST_LINE_RE.test(line)) return "changes";
11440
+ if (APPROVE_FIRST_LINE_RE.test(line)) return "approve";
11441
+ return null;
11442
+ }
11443
+ async function latestVerdictComment(prUrl, sinceIso, run = realCommentsRunner) {
11444
+ const found = await scanPrComments(prUrl, sinceIso, run, (body) => {
11445
+ const verdict = classifyPrVerdict(body);
11446
+ if (!verdict) return null;
11447
+ const { findings, mode } = parseFindingsBlock(body);
11448
+ return { verdict, findings, reviewMode: mode };
11449
+ });
11450
+ if (!found) return null;
11451
+ return {
11452
+ verdict: found.verdict.verdict,
11453
+ createdAt: found.createdAt,
11454
+ body: found.body,
11455
+ findings: found.verdict.findings,
11456
+ reviewMode: found.verdict.reviewMode
11457
+ };
11458
+ }
11459
+ async function scanPrComments(prUrl, sinceIso, run, pick3) {
11460
+ if (!isGithubPrUrl(prUrl)) return null;
11461
+ let out;
11462
+ try {
11463
+ out = await run(prUrl);
11464
+ } catch {
11465
+ return null;
11466
+ }
11467
+ let j;
11468
+ try {
11469
+ j = JSON.parse(out);
11470
+ } catch {
11471
+ return null;
11472
+ }
11473
+ const comments = Array.isArray(j.comments) ? j.comments : [];
11474
+ const sinceMs = sqliteMs(sinceIso);
11475
+ for (let i = comments.length - 1; i >= 0; i--) {
11476
+ const c = comments[i];
11477
+ if (!c?.body || !c.createdAt) continue;
11478
+ if (Number.isFinite(sinceMs) && Date.parse(c.createdAt) < sinceMs) continue;
11479
+ const verdict = pick3(c.body);
11480
+ if (verdict == null) continue;
11481
+ return { verdict, createdAt: c.createdAt, body: c.body };
11482
+ }
11483
+ return null;
11484
+ }
11023
11485
  var NO_CHECKS_STDERR = /no checks reported/i;
11024
11486
  var CiAccessDeniedError = class extends Error {
11025
11487
  detail;
@@ -12990,15 +13452,15 @@ import { cancelRun, respawnRun, runDaemon, wakeRun, OVERMIND_ENTRY, listDronePro
12990
13452
 
12991
13453
  // src/launcher.ts
12992
13454
  import { spawn as spawn2 } from "child_process";
12993
- import { closeSync as closeSync4, existsSync as existsSync10, mkdirSync as mkdirSync10, openSync as openSync4, readdirSync as readdirSync9 } from "fs";
13455
+ import { closeSync as closeSync4, existsSync as existsSync11, mkdirSync as mkdirSync11, openSync as openSync4, readdirSync as readdirSync10 } from "fs";
12994
13456
  import { createRequire } from "module";
12995
13457
  import { homedir as homedir5 } from "os";
12996
- import { dirname as dirname4, join as join15 } from "path";
13458
+ import { dirname as dirname4, join as join16 } from "path";
12997
13459
  import { fileURLToPath as fileURLToPath2 } from "url";
12998
13460
 
12999
13461
  // src/droneHome.ts
13000
- import { lstatSync, mkdirSync as mkdirSync9, readdirSync as readdirSync8, rmSync, statSync as statSync9, symlinkSync as symlinkSync3 } from "fs";
13001
- import { join as join14, relative, sep } from "path";
13462
+ import { lstatSync, mkdirSync as mkdirSync10, readdirSync as readdirSync9, rmSync, statSync as statSync10, symlinkSync as symlinkSync4 } from "fs";
13463
+ import { join as join15, relative, sep } from "path";
13002
13464
  var DRONE_HOME_DENY_DEFAULT = [".taskless-swarm", ".bash_history", ".zsh_history"];
13003
13465
  function droneHomeDeny(env = process.env) {
13004
13466
  const extra = (env.SWARM_DRONE_HOME_DENY || "").split(",").map((s) => s.trim()).filter(Boolean);
@@ -13016,34 +13478,34 @@ function buildDroneHome(opts) {
13016
13478
  const { realHome, droneHome } = opts;
13017
13479
  const deny = opts.deny ?? droneHomeDeny();
13018
13480
  const platform = opts.platform ?? process.platform;
13019
- mkdirSync9(droneHome, { recursive: true, mode: 448 });
13020
- const wanted = new Set(mirroredEntries(readdirSync8(realHome), deny, platform));
13481
+ mkdirSync10(droneHome, { recursive: true, mode: 448 });
13482
+ const wanted = new Set(mirroredEntries(readdirSync9(realHome), deny, platform));
13021
13483
  const rel = relative(realHome, droneHome);
13022
13484
  if (rel && !rel.startsWith("..") && !rel.includes(sep)) wanted.delete(rel);
13023
- for (const existing of readdirSync8(droneHome)) {
13485
+ for (const existing of readdirSync9(droneHome)) {
13024
13486
  if (wanted.has(existing)) continue;
13025
- const p = join14(droneHome, existing);
13487
+ const p = join15(droneHome, existing);
13026
13488
  try {
13027
13489
  if (lstatSync(p).isSymbolicLink()) rmSync(p);
13028
13490
  } catch {
13029
13491
  }
13030
13492
  }
13031
13493
  for (const name of wanted) {
13032
- const link = join14(droneHome, name);
13494
+ const link = join15(droneHome, name);
13033
13495
  try {
13034
13496
  lstatSync(link);
13035
13497
  continue;
13036
13498
  } catch {
13037
13499
  }
13038
- const target = join14(realHome, name);
13500
+ const target = join15(realHome, name);
13039
13501
  let isDir;
13040
13502
  try {
13041
- isDir = statSync9(target).isDirectory();
13503
+ isDir = statSync10(target).isDirectory();
13042
13504
  } catch {
13043
13505
  continue;
13044
13506
  }
13045
13507
  try {
13046
- symlinkSync3(target, link, isDir ? "junction" : "file");
13508
+ symlinkSync4(target, link, isDir ? "junction" : "file");
13047
13509
  } catch (e) {
13048
13510
  if (e.code !== "EEXIST") throw e;
13049
13511
  }
@@ -13056,7 +13518,7 @@ var REAL_PATH_ENV_PINS = [
13056
13518
  { env: "YARN_GLOBAL_FOLDER", segments: [".yarn", "berry"] }
13057
13519
  ];
13058
13520
  function realPathEnvPins(realHome) {
13059
- return Object.fromEntries(REAL_PATH_ENV_PINS.map(({ env, segments }) => [env, join14(realHome, ...segments)]));
13521
+ return Object.fromEntries(REAL_PATH_ENV_PINS.map(({ env, segments }) => [env, join15(realHome, ...segments)]));
13060
13522
  }
13061
13523
  function dronePrivatePaths(realHome, swarmHome) {
13062
13524
  return [
@@ -13140,7 +13602,7 @@ function droneEnv(worktree, base3 = process.env, isolation, droneCap = null) {
13140
13602
  const env = { ...base3 };
13141
13603
  const isolate = base3.SWARM_TURBO_ISOLATE !== "0";
13142
13604
  if (isolate && !base3.TURBO_CACHE_DIR) {
13143
- env.TURBO_CACHE_DIR = join15(worktree, ".turbo", "cache");
13605
+ env.TURBO_CACHE_DIR = join16(worktree, ".turbo", "cache");
13144
13606
  }
13145
13607
  Object.assign(env, droneTestEnv(droneCap, base3));
13146
13608
  for (const key of DAEMON_STATE_ENV) delete env[key];
@@ -13171,21 +13633,21 @@ var DAEMON_STATE_ENV = [
13171
13633
  ...PROVIDER_TOKEN_ENV
13172
13634
  ];
13173
13635
  function bundledRoleDir(kind) {
13174
- return join15(dirname4(fileURLToPath2(import.meta.url)), "..", "roles", kind);
13636
+ return join16(dirname4(fileURLToPath2(import.meta.url)), "..", "roles", kind);
13175
13637
  }
13176
13638
  function roleDir(worktree, kind) {
13177
- return join15(worktree, ".claude", "roles", kind);
13639
+ return join16(worktree, ".claude", "roles", kind);
13178
13640
  }
13179
13641
  function roleDirs(worktree, kind) {
13180
- return [bundledRoleDir(kind), roleDir(worktree, kind)].filter((dir) => existsSync10(dir));
13642
+ return [bundledRoleDir(kind), roleDir(worktree, kind)].filter((dir) => existsSync11(dir));
13181
13643
  }
13182
13644
  function nextRunLogPath(runLogsDir, runLogKeys) {
13183
13645
  const dir = runLogDirForWrite(runLogsDir, runLogKeys);
13184
13646
  if (!dir) throw new Error("\u043D\u0435\u0447\u0435\u043C \u0430\u0434\u0440\u0435\u0441\u043E\u0432\u0430\u0442\u044C \u043A\u0430\u0442\u0430\u043B\u043E\u0433 run-log'\u043E\u0432: \u0443 \u043F\u0440\u043E\u0433\u043E\u043D\u0430 \u043D\u0435\u0442 \u0441\u0442\u0430\u0431\u0438\u043B\u044C\u043D\u043E\u0433\u043E \u043A\u043B\u044E\u0447\u0430 (SwarmStore.runLogKeys)");
13185
- mkdirSync10(dir, { recursive: true });
13647
+ mkdirSync11(dir, { recursive: true });
13186
13648
  let files = [];
13187
13649
  try {
13188
- files = readdirSync9(dir);
13650
+ files = readdirSync10(dir);
13189
13651
  } catch {
13190
13652
  }
13191
13653
  let next = 0;
@@ -13193,7 +13655,7 @@ function nextRunLogPath(runLogsDir, runLogKeys) {
13193
13655
  const m = /^(\d+)\.json/.exec(f);
13194
13656
  if (m) next = Math.max(next, Number(m[1]) + 1);
13195
13657
  }
13196
- return join15(dir, `${next}.json`);
13658
+ return join16(dir, `${next}.json`);
13197
13659
  }
13198
13660
  function openNextRunLog(runLogsDir, runLogKeys) {
13199
13661
  for (let attempt = 0; attempt < 50; attempt++) {
@@ -13285,9 +13747,9 @@ function makeLauncher(cfg) {
13285
13747
  }
13286
13748
  const realHome = cfg.droneIsolation?.realHome ?? homedir5();
13287
13749
  const home = cfg.droneIsolation ? buildDroneHome({ realHome, droneHome: cfg.droneIsolation.home }) : void 0;
13288
- if (cfg.droneIsolation && process.env.TASKLESS_TOKEN && !existsSync10(join15(cfg.droneIsolation.swarmHome, "token"))) {
13750
+ if (cfg.droneIsolation && process.env.TASKLESS_TOKEN && !existsSync11(join16(cfg.droneIsolation.swarmHome, "token"))) {
13289
13751
  console.error(
13290
- `[launcher] TASKLESS_TOKEN \u0437\u0430\u0434\u0430\u043D \u0442\u043E\u043B\u044C\u043A\u043E \u0432 env \u0434\u0435\u043C\u043E\u043D\u0430 \u2014 \u0434\u0440\u043E\u043D\u0443 \u043E\u043D \u043D\u0435 \u043D\u0430\u0441\u043B\u0435\u0434\u0443\u0435\u0442\u0441\u044F (TASWM-289), \u0430 \u0444\u0430\u0439\u043B\u0430 ${join15(cfg.droneIsolation.swarmHome, "token")} \u043D\u0435\u0442. read_task \u0434\u0440\u043E\u043D\u0430 \u0431\u0443\u0434\u0435\u0442 slug-only. \u041F\u043E\u0447\u0438\u043D\u0438: \`swarm login\` (oauth.json) \u0438\u043B\u0438 \u043F\u043E\u043B\u043E\u0436\u0438 \u0442\u043E\u043A\u0435\u043D \u0432 \u044D\u0442\u043E\u0442 \u0444\u0430\u0439\u043B.`
13752
+ `[launcher] TASKLESS_TOKEN \u0437\u0430\u0434\u0430\u043D \u0442\u043E\u043B\u044C\u043A\u043E \u0432 env \u0434\u0435\u043C\u043E\u043D\u0430 \u2014 \u0434\u0440\u043E\u043D\u0443 \u043E\u043D \u043D\u0435 \u043D\u0430\u0441\u043B\u0435\u0434\u0443\u0435\u0442\u0441\u044F (TASWM-289), \u0430 \u0444\u0430\u0439\u043B\u0430 ${join16(cfg.droneIsolation.swarmHome, "token")} \u043D\u0435\u0442. read_task \u0434\u0440\u043E\u043D\u0430 \u0431\u0443\u0434\u0435\u0442 slug-only. \u041F\u043E\u0447\u0438\u043D\u0438: \`swarm login\` (oauth.json) \u0438\u043B\u0438 \u043F\u043E\u043B\u043E\u0436\u0438 \u0442\u043E\u043A\u0435\u043D \u0432 \u044D\u0442\u043E\u0442 \u0444\u0430\u0439\u043B.`
13291
13753
  );
13292
13754
  }
13293
13755
  const executor = cfg.executor ?? executorForRun(run, cfg.swarmModels?.() ?? null);
@@ -14218,7 +14680,7 @@ async function runDaemonLogs(argv) {
14218
14680
  console.error(`\u043B\u043E\u0433 \u041F\u0420\u041E\u0413\u041E\u041D\u0410 \u2014 \u044D\u0442\u043E \xABswarm log ${stray}\xBB (\u0431\u0435\u0437 s). \xABswarm logs\xBB \u043F\u043E\u043A\u0430\u0437\u044B\u0432\u0430\u0435\u0442 \u043B\u043E\u0433 \u0434\u0435\u043C\u043E\u043D\u0430; \u0447\u0438\u0441\u043B\u043E \u0441\u0442\u0440\u043E\u043A \u2014 \xABswarm logs -n 200\xBB.`);
14219
14681
  return 1;
14220
14682
  }
14221
- if (!existsSync18(DAEMON_LOG_PATH)) {
14683
+ if (!existsSync19(DAEMON_LOG_PATH)) {
14222
14684
  console.error(`\u043B\u043E\u0433\u0430 \u0434\u0435\u043C\u043E\u043D\u0430 \u043D\u0435\u0442: ${DAEMON_LOG_PATH}`);
14223
14685
  console.error("\u043E\u043D \u043F\u0438\u0448\u0435\u0442\u0441\u044F \u043F\u0440\u0438 \u0444\u043E\u043D\u043E\u0432\u043E\u043C \u0437\u0430\u043F\u0443\u0441\u043A\u0435 (swarm start). \u0414\u0435\u043C\u043E\u043D \u043F\u043E\u0434\u043D\u044F\u0442 \u0432 \u0442\u0435\u0440\u043C\u0438\u043D\u0430\u043B\u0435 (--foreground) \u2014 \u0432\u044B\u0432\u043E\u0434 \u0438\u0434\u0451\u0442 \u0442\u0443\u0434\u0430.");
14224
14686
  return 1;
@@ -14226,12 +14688,12 @@ async function runDaemonLogs(argv) {
14226
14688
  const head = tailFile(DAEMON_LOG_PATH, lines);
14227
14689
  if (head) console.log(head);
14228
14690
  if (!follow) return 0;
14229
- let pos = statSync12(DAEMON_LOG_PATH).size;
14691
+ let pos = statSync13(DAEMON_LOG_PATH).size;
14230
14692
  for (; ; ) {
14231
14693
  await sleep2(500);
14232
14694
  let size;
14233
14695
  try {
14234
- size = statSync12(DAEMON_LOG_PATH).size;
14696
+ size = statSync13(DAEMON_LOG_PATH).size;
14235
14697
  } catch {
14236
14698
  continue;
14237
14699
  }
@@ -14500,10 +14962,10 @@ function effectiveWorktreesDir() {
14500
14962
  legacyDir: WORKTREES_LEGACY_DIR,
14501
14963
  targetDir: WORKTREES_DIR,
14502
14964
  envOverride: process.env.SWARM_WORKTREES || "",
14503
- exists: (d) => existsSync18(d),
14965
+ exists: (d) => existsSync19(d),
14504
14966
  isNonEmptyDir: (d) => {
14505
14967
  try {
14506
- return readdirSync12(d).length > 0;
14968
+ return readdirSync13(d).length > 0;
14507
14969
  } catch {
14508
14970
  return false;
14509
14971
  }
@@ -14559,15 +15021,15 @@ async function scoutRepo(repo) {
14559
15021
  await $6({ reject: false })`git -C ${worktree} reset --hard ${baseRef}`;
14560
15022
  }
14561
15023
  await setWorktreeIdentity(worktree, name);
14562
- const abs = (rel) => join27(worktree, rel);
15024
+ const abs = (rel) => join28(worktree, rel);
14563
15025
  const code = await runRepoScout({
14564
15026
  repoFullName,
14565
15027
  repoPath: worktree,
14566
15028
  name,
14567
- readFile: (rel) => existsSync18(abs(rel)) ? readFileSync19(abs(rel), "utf8") : null,
15029
+ readFile: (rel) => existsSync19(abs(rel)) ? readFileSync21(abs(rel), "utf8") : null,
14568
15030
  writeFile: (rel, text) => {
14569
- mkdirSync11(dirname5(abs(rel)), { recursive: true });
14570
- writeFileSync15(abs(rel), text);
15031
+ mkdirSync12(dirname5(abs(rel)), { recursive: true });
15032
+ writeFileSync16(abs(rel), text);
14571
15033
  },
14572
15034
  runScout: (prompt) => new Promise((resolve5) => {
14573
15035
  const child = spawn3(bin, [...ISOLATION_FLAGS, "--dangerously-skip-permissions", "-p", prompt], {
@@ -15081,7 +15543,15 @@ switch (cmd) {
15081
15543
  // иначе побудка codex-прогона при мёртвом демоне теряла продолжаемую сессию.
15082
15544
  hasTranscript: (run2) => !!run2.worktree_path && executorForRun(run2, null).session.exists(run2.worktree_path),
15083
15545
  respawn: (r, mode, nudge) => respawnRun(
15084
- { db, launch, repoFallback: SWARM_REPO, worktreesDir: effectiveWorktreesDir(), getTask: () => Promise.resolve(null) },
15546
+ {
15547
+ db,
15548
+ launch,
15549
+ repoFallback: SWARM_REPO,
15550
+ worktreesDir: effectiveWorktreesDir(),
15551
+ getTask: () => Promise.resolve(null),
15552
+ // TASWM-618: тот же фолбэк комментария PR, что у живого демона.
15553
+ verdictComment: (prUrl, sinceIso) => latestVerdictComment(prUrl, sinceIso)
15554
+ },
15085
15555
  r,
15086
15556
  mode,
15087
15557
  nudge