@taskless-app/swarm 0.6.108 → 0.6.110

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -837,7 +837,7 @@ var init_status = __esm({
837
837
  });
838
838
 
839
839
  // ../swarm-core/src/deps.ts
840
- function judgeDep(runs) {
840
+ function judgeDep(runs, opts) {
841
841
  const real = runs.filter((r) => !r.service);
842
842
  if (real.length === 0) return { ...UNKNOWN };
843
843
  if (real.some((r) => !isTerminalStatus(r.status))) return { ...PENDING };
@@ -845,12 +845,23 @@ function judgeDep(runs) {
845
845
  return { outcome: "done", met: true, status: "done", name: null, stopReason: null };
846
846
  }
847
847
  const last = real[real.length - 1];
848
+ if (last.status === "stopped" && !opts?.taskClosed) {
849
+ return {
850
+ outcome: "pending",
851
+ met: false,
852
+ status: last.status,
853
+ name: last.name ?? null,
854
+ stopReason: last.stopReason ?? null
855
+ };
856
+ }
857
+ const releasedByTaskClose = last.status === "stopped" && opts?.taskClosed === true;
848
858
  return {
849
859
  outcome: "exhausted",
850
860
  met: true,
851
861
  status: last.status,
852
862
  name: last.name ?? null,
853
- stopReason: last.stopReason ?? null
863
+ stopReason: last.stopReason ?? null,
864
+ ...releasedByTaskClose ? { releasedByTaskClose: true } : {}
854
865
  };
855
866
  }
856
867
  var PENDING, UNKNOWN;
@@ -1543,7 +1554,7 @@ function buildZoneModel(entries, opts = {}) {
1543
1554
  if (!m) labelVotes.set(z, m = /* @__PURE__ */ new Map());
1544
1555
  bump(m, manual);
1545
1556
  }
1546
- const rename2 = /* @__PURE__ */ new Map();
1557
+ const rename3 = /* @__PURE__ */ new Map();
1547
1558
  const takenNames = /* @__PURE__ */ new Set([SPINE_ZONE]);
1548
1559
  const clustersByEvidence = [...labelVotes.entries()].sort((a, b) => {
1549
1560
  const sum = (m) => [...m.values()].reduce((x, y) => x + y, 0);
@@ -1552,11 +1563,11 @@ function buildZoneModel(entries, opts = {}) {
1552
1563
  for (const [zone, votes] of clustersByEvidence) {
1553
1564
  const top = topKey(votes);
1554
1565
  if (!top || top.share < 0.6 || takenNames.has(top.key) || top.key === zone) continue;
1555
- rename2.set(zone, top.key);
1566
+ rename3.set(zone, top.key);
1556
1567
  takenNames.add(top.key);
1557
1568
  }
1558
- const renamed = (z) => rename2.get(z) ?? z;
1559
- if (rename2.size) {
1569
+ const renamed = (z) => rename3.get(z) ?? z;
1570
+ if (rename3.size) {
1560
1571
  for (const [f, z] of fileZone) fileZone.set(f, renamed(z));
1561
1572
  for (const [s, z] of taskZone) taskZone.set(s, renamed(z));
1562
1573
  }
@@ -1735,8 +1746,8 @@ function predictFiles(model, opts) {
1735
1746
  }
1736
1747
  const zone = normalizeZoneName(opts.zone) ?? (opts.text ? suggestZonesFromText(model, opts.text)[0]?.zone ?? null : null);
1737
1748
  if (zone) {
1738
- const stat2 = model.zones.find((z) => z.zone === zone);
1739
- if (stat2) stat2.files.slice(0, limit).forEach((f, i) => put(f, Math.max(0.12, 0.45 - i * 0.02), `\u0437\u043E\u043D\u0430 ${zone}`));
1749
+ const stat3 = model.zones.find((z) => z.zone === zone);
1750
+ if (stat3) stat3.files.slice(0, limit).forEach((f, i) => put(f, Math.max(0.12, 0.45 - i * 0.02), `\u0437\u043E\u043D\u0430 ${zone}`));
1740
1751
  }
1741
1752
  return [...best.values()].sort((a, b) => b.weight - a.weight || a.path.localeCompare(b.path)).slice(0, limit);
1742
1753
  }
@@ -2555,13 +2566,13 @@ function ensureCodexHome(worktree, realHome, env = process.env, swarmHome = SWAR
2555
2566
  const real = (env.CODEX_HOME ?? "").trim() || join5(realHome, ".codex");
2556
2567
  for (const file of ["auth.json", "config.toml"]) {
2557
2568
  const target = join5(real, file);
2558
- const link = join5(home, file);
2559
- if (!existsSync3(target) || existsSync3(link)) continue;
2569
+ const link2 = join5(home, file);
2570
+ if (!existsSync3(target) || existsSync3(link2)) continue;
2560
2571
  try {
2561
- symlinkSync(target, link);
2572
+ symlinkSync(target, link2);
2562
2573
  } catch {
2563
2574
  try {
2564
- copyFileSync2(target, link);
2575
+ copyFileSync2(target, link2);
2565
2576
  } catch {
2566
2577
  }
2567
2578
  }
@@ -2749,13 +2760,13 @@ function ensureGrokHome(worktree, realHome, env = process.env, swarmHome = SWARM
2749
2760
  mkdirSync4(home, { recursive: true });
2750
2761
  const real = (env.GROK_HOME ?? "").trim() || join6(realHome, ".grok");
2751
2762
  const target = join6(real, "auth.json");
2752
- const link = join6(home, "auth.json");
2753
- if (existsSync4(target) && !existsSync4(link)) {
2763
+ const link2 = join6(home, "auth.json");
2764
+ if (existsSync4(target) && !existsSync4(link2)) {
2754
2765
  try {
2755
- symlinkSync2(target, link);
2766
+ symlinkSync2(target, link2);
2756
2767
  } catch {
2757
2768
  try {
2758
- copyFileSync3(target, link);
2769
+ copyFileSync3(target, link2);
2759
2770
  } catch {
2760
2771
  }
2761
2772
  }
@@ -3063,14 +3074,14 @@ function ensureKimiHome(worktree, realHome, env = process.env, swarmHome = SWARM
3063
3074
  const home = kimiHomePath(worktree, swarmHome);
3064
3075
  mkdirSync5(home, { recursive: true });
3065
3076
  const realCreds = join7((env.KIMI_CODE_HOME ?? "").trim() || join7(realHome, ".kimi-code"), "credentials");
3066
- const link = join7(home, "credentials");
3067
- if (existsSync5(realCreds) && !existsSync5(link)) {
3077
+ const link2 = join7(home, "credentials");
3078
+ if (existsSync5(realCreds) && !existsSync5(link2)) {
3068
3079
  try {
3069
- symlinkSync3(realCreds, link, "junction");
3080
+ symlinkSync3(realCreds, link2, "junction");
3070
3081
  } catch {
3071
3082
  try {
3072
- mkdirSync5(link, { recursive: true });
3073
- for (const f of readdirSync6(realCreds)) copyFileSync4(join7(realCreds, f), join7(link, f));
3083
+ mkdirSync5(link2, { recursive: true });
3084
+ for (const f of readdirSync6(realCreds)) copyFileSync4(join7(realCreds, f), join7(link2, f));
3074
3085
  } catch {
3075
3086
  }
3076
3087
  }
@@ -3347,7 +3358,7 @@ function tokenFromFile() {
3347
3358
  return "";
3348
3359
  }
3349
3360
  }
3350
- var DB_PATH, EXECUTOR, DRONE_HOME, DRONE_HOME_ISOLATION, DRONE_ISOLATION, WORKTREES_NOINDEX_DIR, WORKTREES_LEGACY_DIR, WORKTREES_DIR, RUN_LOGS_DIR, DAEMON_LOG_PATH, DAEMON_LOG_MAX_BYTES, DAEMON_LOG_KEEP, DAEMON_LOG_CHECK_MS, DIST_BUILD, SWARM_BACKEND, SWARM_OUTBOX, SWARM_MAX_IN_FLIGHT, SWARM_CLAIM_INTERVAL_MS, ENV_CACHE_DIR, ENV_CACHE_ENABLED, ENV_CACHE_KEEP, SWARM_MAX_LOAD_FACTOR, SWARM_MIN_FREE_GB, SWARM_MAX_FD_LOAD_FACTOR, SWARM_MAX_CPU_BUSY, SWARM_CPU_WINDOW_MS, SWARM_CPU_SANITY_BUSY, SWARM_CPU_SANITY_LOAD_FACTOR, SWARM_CPU_SANITY_LAG_MS, SWARM_RELIEF_LOAD_FACTOR, SWARM_RELIEF_MIN_FREE_GB, SWARM_RELIEF_MAX_FD_LOAD_FACTOR, SWARM_RELIEF_CPU_BUSY, SWARM_RELIEF_COST_WINDOW_MS, SWARM_RELIEF_ALERT_PAUSES, SWARM_RELIEF_ALERT_LOST_MS, SWARM_RELIEF_ALERT_MIN_STEPS, SWARM_RELIEF_ALERT_SUSTAIN_MS, SWARM_LOW_DISK_GB, SWARM_REHYDRATE_MS, SWARM_DRONE_BRIDGE_MS, SWARM_PROD_HEARTBEAT_MS, SWARM_VERSION_CHECK_MS, SWARM_SWEEP_INTERVAL_MS, SWARM_WORKTREE_REAP_INTERVAL_MS, DRONE_CHANNEL_ENABLED, DRONE_CHANNEL_PORT, DRONE_CHANNEL_URL, DRONE_CHANNEL_SECRET_PATH, DRONE_CHANNEL_GRACE_MS, HEARTBEAT_PATH, HEARTBEAT_STALE_MS, SWARM_REPO, SWARM_SCAN_DEPTH, SWARM_REPO_PATHS, SWARM_SCAN_ROOTS_RAW, REPO_MAP_PATH, SWARM_REPO_MAP_MS, SWARM_REPO_SCAN_TTL_MS, TASKLESS_API, SWARM_SHOT_TIMEOUT_MS, TASKLESS_MCP_PATH, TASKLESS_REST_PATH, TASKLESS_TOKEN, TASKLESS_WORKSPACE, TASKLESS_WORKSPACE_SLUG, TASKLESS_TASK_URL_BASE, SWARM_VERIFY, SWARM_AUTO_REVIEW, SWARM_AUTO_VERIFY, SWARM_MERGE_QUEUE, REVIEW_CUTOFF_PATH, SWARM_REVIEW_CAP, SWARM_STORM_URL, WEB_PORT, WEB_REDIRECT_URI, SWARM_ANOMALY_RENOTIFY_MS, SWARM_ANOMALY_MAX_REPEATS, SWARM_ANOMALY_RUN_DOWN_WINDOW_MS, SWARM_ANOMALY_FAILED_SPIKE_COUNT, SWARM_ANOMALY_FAILED_SPIKE_WINDOW_MS, SWARM_ANOMALY_QUEUE_STALLED_MS, SWARM_ANOMALY_PR_STUCK_MERGE_MS, SWARM_ANOMALY_PR_NO_REVIEWER_MS, SWARM_ANOMALY_QUESTION_UNANSWERED_MS, SWARM_ANOMALY_OUTBOX_STUCK_MS, SWARM_ANOMALY_RESOURCE_GATE_STALL_MS, SWARM_ANOMALY_DEP_MISSING_MS, SWARM_WATCHDOG_STALL_MS;
3361
+ var DB_PATH, EXECUTOR, DRONE_HOME, DRONE_HOME_ISOLATION, DRONE_ISOLATION, WORKTREES_NOINDEX_DIR, WORKTREES_LEGACY_DIR, WORKTREES_DIR, RUN_LOGS_DIR, DAEMON_LOG_PATH, DAEMON_LOG_MAX_BYTES, DAEMON_LOG_KEEP, DAEMON_LOG_CHECK_MS, DIST_BUILD, SWARM_BACKEND, SWARM_OUTBOX, SWARM_MAX_IN_FLIGHT, SWARM_CLAIM_INTERVAL_MS, ENV_CACHE_DIR, ENV_CACHE_ENABLED, ENV_CACHE_KEEP, SWARM_MAX_LOAD_FACTOR, SWARM_MIN_FREE_GB, SWARM_MAX_FD_LOAD_FACTOR, SWARM_MAX_CPU_BUSY, SWARM_CPU_WINDOW_MS, SWARM_CPU_SANITY_BUSY, SWARM_CPU_SANITY_LOAD_FACTOR, SWARM_CPU_SANITY_LAG_MS, SWARM_RELIEF_LOAD_FACTOR, SWARM_RELIEF_MIN_FREE_GB, SWARM_RELIEF_MAX_FD_LOAD_FACTOR, SWARM_RELIEF_CPU_BUSY, SWARM_RELIEF_COST_WINDOW_MS, SWARM_RELIEF_ALERT_PAUSES, SWARM_RELIEF_ALERT_LOST_MS, SWARM_RELIEF_ALERT_MIN_STEPS, SWARM_RELIEF_ALERT_SUSTAIN_MS, SWARM_LOW_DISK_GB, SWARM_REHYDRATE_MS, SWARM_DRONE_BRIDGE_MS, SWARM_PROD_HEARTBEAT_MS, SWARM_VERSION_CHECK_MS, SWARM_SWEEP_INTERVAL_MS, SWARM_WORKTREE_REAP_INTERVAL_MS, DRONE_CHANNEL_ENABLED, DRONE_CHANNEL_PORT, DRONE_CHANNEL_URL, DRONE_CHANNEL_SECRET_PATH, DRONE_CHANNEL_GRACE_MS, HEARTBEAT_PATH, HEARTBEAT_STALE_MS, SWARM_REPO, SWARM_SCAN_DEPTH, SWARM_REPO_PATHS, SWARM_SCAN_ROOTS_RAW, REPO_MAP_PATH, SWARM_REPO_MAP_MS, SWARM_REPO_SCAN_TTL_MS, TASKLESS_API, SWARM_SHOT_TIMEOUT_MS, TASKLESS_MCP_PATH, TASKLESS_REST_PATH, TASKLESS_TOKEN, TASKLESS_WORKSPACE, TASKLESS_WORKSPACE_SLUG, TASKLESS_TASK_URL_BASE, SWARM_VERIFY, SWARM_AUTO_REVIEW, SWARM_AUTO_VERIFY, SWARM_MERGE_QUEUE, REVIEW_CUTOFF_PATH, SWARM_REVIEW_CAP, SWARM_STORM_URL, WEB_PORT, WEB_REDIRECT_URI, SWARM_ANOMALY_RENOTIFY_MS, SWARM_ANOMALY_MAX_REPEATS, SWARM_ANOMALY_RUN_DOWN_WINDOW_MS, SWARM_ANOMALY_FAILED_SPIKE_COUNT, SWARM_ANOMALY_FAILED_SPIKE_WINDOW_MS, SWARM_ANOMALY_QUEUE_STALLED_MS, SWARM_ANOMALY_PR_STUCK_MERGE_MS, SWARM_ANOMALY_PR_NO_REVIEWER_MS, CHANGES_FRESH_WAKE_AFTER_MS, SWARM_ANOMALY_QUESTION_UNANSWERED_MS, SWARM_ANOMALY_OUTBOX_STUCK_MS, SWARM_ANOMALY_RESOURCE_GATE_STALL_MS, SWARM_ANOMALY_DEP_MISSING_MS, SWARM_WATCHDOG_STALL_MS;
3351
3362
  var init_config = __esm({
3352
3363
  "src/config.ts"() {
3353
3364
  "use strict";
@@ -3439,6 +3450,7 @@ var init_config = __esm({
3439
3450
  SWARM_ANOMALY_QUEUE_STALLED_MS = envNum("SWARM_ANOMALY_QUEUE_STALLED_MS", 10 * 6e4);
3440
3451
  SWARM_ANOMALY_PR_STUCK_MERGE_MS = envNum("SWARM_ANOMALY_PR_STUCK_MERGE_MS", 30 * 6e4);
3441
3452
  SWARM_ANOMALY_PR_NO_REVIEWER_MS = envNum("SWARM_ANOMALY_PR_NO_REVIEWER_MS", 20 * 6e4);
3453
+ CHANGES_FRESH_WAKE_AFTER_MS = Number(process.env.SWARM_CHANGES_FRESH_WAKE_AFTER_MS) || SWARM_ANOMALY_PR_NO_REVIEWER_MS;
3442
3454
  SWARM_ANOMALY_QUESTION_UNANSWERED_MS = envNum("SWARM_ANOMALY_QUESTION_UNANSWERED_MS", 20 * 6e4);
3443
3455
  SWARM_ANOMALY_OUTBOX_STUCK_MS = envNum("SWARM_ANOMALY_OUTBOX_STUCK_MS", 10 * 6e4);
3444
3456
  SWARM_ANOMALY_RESOURCE_GATE_STALL_MS = envNum("SWARM_ANOMALY_RESOURCE_GATE_STALL_MS", 5 * 6e4);
@@ -3880,6 +3892,25 @@ var init_zoneNotes = __esm({
3880
3892
  }
3881
3893
  });
3882
3894
 
3895
+ // src/authorRun.ts
3896
+ function isSlugAuthorRun(run) {
3897
+ if (run.reviews_run_id != null || run.resolves_run_id != null || run.verifies_run_id != null) return false;
3898
+ if (run.superseded_by != null) return false;
3899
+ const kind = run.kind ?? "drone";
3900
+ return kind === "drone" || kind === "hero";
3901
+ }
3902
+ function sessionStartMoved(prev, patch) {
3903
+ const nextStatus = patch.status ?? prev.status;
3904
+ if (nextStatus !== "running") return false;
3905
+ if (prev.status !== "running") return true;
3906
+ return patch.pid != null && patch.pid !== prev.pid;
3907
+ }
3908
+ var init_authorRun = __esm({
3909
+ "src/authorRun.ts"() {
3910
+ "use strict";
3911
+ }
3912
+ });
3913
+
3883
3914
  // src/store.ts
3884
3915
  function isCleanResolve(run) {
3885
3916
  return (run.stop_reason ?? "").includes(RESOLVE_CLEAN_MARK);
@@ -4493,7 +4524,7 @@ var init_package = __esm({
4493
4524
  "package.json"() {
4494
4525
  package_default = {
4495
4526
  name: "@taskless-app/swarm",
4496
- version: "0.6.108",
4527
+ version: "0.6.110",
4497
4528
  type: "module",
4498
4529
  description: "Local control plane for a fleet of AI coding agents (drones), coordinating through Taskless. The overmind runs the swarm.",
4499
4530
  keywords: [
@@ -4545,7 +4576,7 @@ var init_package = __esm({
4545
4576
  undici: "^7.30.1",
4546
4577
  zod: "3.25.76"
4547
4578
  },
4548
- gitHead: "5f0f3fbffee1c48a48899d850caaf0ed10d0b9c2"
4579
+ gitHead: "195231b0b9a3429f4752aa9977020e1bb364ca95"
4549
4580
  };
4550
4581
  }
4551
4582
  });
@@ -4709,246 +4740,14 @@ var init_netTimeout = __esm({
4709
4740
  }
4710
4741
  });
4711
4742
 
4712
- // src/droneChannel.ts
4713
- import { createHmac, randomBytes, timingSafeEqual } from "crypto";
4714
- import { chmodSync as chmodSync2, mkdirSync as mkdirSync9, readFileSync as readFileSync11, writeFileSync as writeFileSync9 } from "fs";
4715
- import { dirname as dirname3 } from "path";
4716
- import { serve } from "@hono/node-server";
4717
- function loadChannelSecret(path) {
4718
- try {
4719
- const s = readFileSync11(path, "utf8").trim();
4720
- if (s.length >= 32) return s;
4721
- } catch {
4722
- }
4723
- const secret = randomBytes(32).toString("hex");
4724
- mkdirSync9(dirname3(path), { recursive: true });
4725
- writeFileSync9(path, secret, { mode: 384 });
4726
- try {
4727
- chmodSync2(path, 384);
4728
- } catch {
4729
- }
4730
- return secret;
4731
- }
4732
- function sign(runKey, secret) {
4733
- return createHmac("sha256", secret).update(runKey).digest("base64url");
4734
- }
4735
- function mintChannelToken(runKey, secret) {
4736
- return `${Buffer.from(runKey, "utf8").toString("base64url")}.${sign(runKey, secret)}`;
4737
- }
4738
- function verifyChannelToken(token, secret) {
4739
- const dot = token.lastIndexOf(".");
4740
- if (dot <= 0) return null;
4741
- const runKey = Buffer.from(token.slice(0, dot), "base64url").toString("utf8");
4742
- if (!runKey) return null;
4743
- const got = Buffer.from(token.slice(dot + 1));
4744
- const want = Buffer.from(sign(runKey, secret));
4745
- if (got.length !== want.length || !timingSafeEqual(got, want)) return null;
4746
- return runKey;
4747
- }
4748
- function mintLocalCliToken(secret) {
4749
- return mintChannelToken(LOCAL_CLI_KEY, secret);
4750
- }
4751
- function verifyLocalCliToken(token, secret) {
4752
- return verifyChannelToken(token, secret) === LOCAL_CLI_KEY;
4753
- }
4754
- var LOCAL_CLI_KEY, EVENT_KIND_SET;
4755
- var init_droneChannel = __esm({
4756
- "src/droneChannel.ts"() {
4757
- "use strict";
4758
- init_src();
4759
- LOCAL_CLI_KEY = "cli";
4760
- EVENT_KIND_SET = new Set(EVENT_KINDS);
4761
- }
4762
- });
4763
-
4764
- // src/authState.ts
4765
- function noteTokenRejected(nowMs = Date.now()) {
4766
- if (!denial) {
4767
- denial = { since: nowMs, lastShoutAt: nowMs, count: 1 };
4768
- return revokedTokenComplaint();
4769
- }
4770
- denial.count += 1;
4771
- if (nowMs - denial.lastShoutAt < SHOUT_EVERY_MS) return null;
4772
- denial.lastShoutAt = nowMs;
4773
- return `${revokedTokenComplaint()}
4774
- ${deniedSinceLine(nowMs)}
4775
- `;
4776
- }
4777
- function noteTokenAccepted() {
4778
- denial = null;
4779
- }
4780
- function authStateLine(nowMs = Date.now()) {
4781
- if (!denial) return null;
4782
- return `\u0414\u041E\u0421\u0422\u0423\u041F \u041A TASKLESS \u041E\u0422\u041E\u0417\u0412\u0410\u041D \u2014 ${deniedSinceLine(nowMs)}. \u041F\u043E\u0447\u0438\u043D\u0438 \u043D\u0430 \u044D\u0442\u043E\u0439 \u043C\u0430\u0448\u0438\u043D\u0435: swarm login`;
4783
- }
4784
- function deniedSinceLine(nowMs) {
4785
- const d = denial;
4786
- if (!d) return "";
4787
- const min = Math.max(1, Math.round((nowMs - d.since) / 6e4));
4788
- return `\u043F\u0440\u043E\u0434 \u043E\u0442\u0432\u0435\u0440\u0433\u0430\u0435\u0442 \u0442\u043E\u043A\u0435\u043D ${min} \u043C\u0438\u043D, \u043E\u0442\u043A\u0430\u0437\u043E\u0432 ${d.count}`;
4789
- }
4790
- var SHOUT_EVERY_MS, denial;
4791
- var init_authState = __esm({
4792
- "src/authState.ts"() {
4793
- "use strict";
4794
- init_agentToken();
4795
- SHOUT_EVERY_MS = 10 * 6e4;
4796
- denial = null;
4797
- }
4798
- });
4799
-
4800
- // src/oauth.ts
4801
- import { createHash, randomBytes as randomBytes2 } from "crypto";
4802
- import { readFileSync as readFileSync12, writeFileSync as writeFileSync10, unlinkSync as unlinkSync3 } from "fs";
4803
- import { join as join14 } from "path";
4804
- function makePkce() {
4805
- const verifier = randomBytes2(48).toString("base64url");
4806
- const challenge = createHash("sha256").update(verifier).digest("base64url");
4807
- return { verifier, challenge };
4808
- }
4809
- async function registerClient(args, fetchFn = fetch) {
4810
- const res = await fetchFn(`${base2(args.api)}${REGISTER}`, {
4811
- method: "POST",
4812
- headers: { "Content-Type": "application/json" },
4813
- body: JSON.stringify({
4814
- client_name: args.name ?? "Taskless Swarm",
4815
- redirect_uris: [args.redirectUri],
4816
- token_endpoint_auth_method: "none"
4817
- })
4818
- });
4819
- if (!res.ok) throw new Error(`register: HTTP ${res.status} ${(await res.text().catch(() => "")).slice(0, 160)}`);
4820
- const j = await res.json();
4821
- if (!j.client_id) throw new Error("register: \u0432 \u043E\u0442\u0432\u0435\u0442\u0435 \u043D\u0435\u0442 client_id");
4822
- return j.client_id;
4823
- }
4824
- function authorizeUrl(args) {
4825
- const u = new URL(`${base2(args.api)}${AUTHORIZE}`);
4826
- u.searchParams.set("response_type", "code");
4827
- u.searchParams.set("client_id", args.clientId);
4828
- u.searchParams.set("redirect_uri", args.redirectUri);
4829
- u.searchParams.set("scope", SCOPE);
4830
- u.searchParams.set("code_challenge", args.challenge);
4831
- u.searchParams.set("code_challenge_method", "S256");
4832
- u.searchParams.set("state", args.state);
4833
- return u.toString();
4834
- }
4835
- async function postToken(api, params, fetchFn) {
4836
- const res = await fetchFn(`${base2(api)}${TOKEN}`, {
4837
- method: "POST",
4838
- headers: { "Content-Type": "application/x-www-form-urlencoded" },
4839
- body: new URLSearchParams(params).toString()
4840
- });
4841
- const text = await res.text();
4842
- if (!res.ok) throw new Error(`token ${params.grant_type}: HTTP ${res.status} ${text.slice(0, 200)}`);
4843
- const j = JSON.parse(text);
4844
- if (!j.access_token) throw new Error("token: \u0432 \u043E\u0442\u0432\u0435\u0442\u0435 \u043D\u0435\u0442 access_token");
4845
- return j;
4846
- }
4847
- function exchangeCode(args, fetchFn = fetch) {
4848
- return postToken(
4849
- args.api,
4850
- {
4851
- grant_type: "authorization_code",
4852
- code: args.code,
4853
- code_verifier: args.verifier,
4854
- client_id: args.clientId,
4855
- redirect_uri: args.redirectUri
4856
- },
4857
- fetchFn
4858
- );
4859
- }
4860
- function refreshTokens(args, fetchFn = fetch) {
4861
- return postToken(
4862
- args.api,
4863
- { grant_type: "refresh_token", refresh_token: args.refreshToken, client_id: args.clientId },
4864
- fetchFn
4865
- );
4866
- }
4867
- function emailFromIdToken(idToken) {
4868
- const payload = idToken?.split(".")[1];
4869
- if (!payload) return void 0;
4870
- try {
4871
- return JSON.parse(Buffer.from(payload, "base64url").toString("utf8")).email;
4872
- } catch {
4873
- return void 0;
4874
- }
4875
- }
4876
- function toStore(clientId, t, now) {
4877
- return {
4878
- clientId,
4879
- accessToken: t.access_token,
4880
- refreshToken: t.refresh_token,
4881
- expiresAt: now + t.expires_in * 1e3,
4882
- email: emailFromIdToken(t.id_token)
4883
- };
4884
- }
4885
- function loadStore() {
4886
- try {
4887
- return JSON.parse(readFileSync12(STORE_PATH2, "utf8"));
4888
- } catch {
4889
- return null;
4890
- }
4891
- }
4892
- function saveStore(s) {
4893
- writeFileSync10(STORE_PATH2, JSON.stringify(s, null, 2), { mode: 384 });
4894
- }
4895
- function clearStore() {
4896
- try {
4897
- unlinkSync3(STORE_PATH2);
4898
- } catch {
4899
- }
4900
- }
4901
- function loadClientId() {
4902
- try {
4903
- return JSON.parse(readFileSync12(CLIENT_PATH, "utf8")).clientId;
4904
- } catch {
4905
- return null;
4906
- }
4907
- }
4908
- async function ensureClientId(api, redirectUri, fetchFn = fetch) {
4909
- const existing = loadClientId();
4910
- if (existing) return existing;
4911
- const clientId = await registerClient({ api, redirectUri }, fetchFn);
4912
- writeFileSync10(CLIENT_PATH, JSON.stringify({ clientId }, null, 2), { mode: 384 });
4913
- return clientId;
4914
- }
4915
- async function ensureAccess(store, opts = {}) {
4916
- const api = opts.api ?? TASKLESS_API;
4917
- const now = opts.now ?? Date.now();
4918
- const fetchFn = opts.fetchFn ?? fetch;
4919
- if (store.expiresAt - now > 6e4) return { accessToken: store.accessToken };
4920
- try {
4921
- const t = await refreshTokens({ api, clientId: store.clientId, refreshToken: store.refreshToken }, fetchFn);
4922
- const next = toStore(store.clientId, t, now);
4923
- next.email = next.email ?? store.email;
4924
- return { accessToken: next.accessToken, store: next };
4925
- } catch {
4926
- return null;
4927
- }
4928
- }
4929
- var REGISTER, AUTHORIZE, TOKEN, SCOPE, STORE_PATH2, CLIENT_PATH, base2;
4930
- var init_oauth = __esm({
4931
- "src/oauth.ts"() {
4932
- "use strict";
4933
- init_config();
4934
- REGISTER = "/api/oauth/register";
4935
- AUTHORIZE = "/api/oauth/authorize";
4936
- TOKEN = "/api/oauth/token";
4937
- SCOPE = "openid profile email taskless:full";
4938
- STORE_PATH2 = join14(SWARM_HOME, "oauth.json");
4939
- CLIENT_PATH = join14(SWARM_HOME, "oauth-client.json");
4940
- base2 = (api) => api.replace(/\/$/, "");
4941
- }
4942
- });
4943
-
4944
4743
  // src/git.ts
4945
- import { existsSync as existsSync12, readdirSync as readdirSync11, realpathSync as realpathSync2, statSync as statSync11 } from "fs";
4744
+ import { existsSync as existsSync11, readdirSync as readdirSync9, realpathSync as realpathSync2, statSync as statSync10 } from "fs";
4946
4745
  import { appendFile, chmod, mkdir, readFile, rename, rm, writeFile } from "fs/promises";
4947
- import { isAbsolute as isAbsolute2, join as join17, resolve as resolve3, sep as sep3 } from "path";
4948
- import { $ as $5 } from "execa";
4746
+ import { isAbsolute as isAbsolute2, join as join14, resolve as resolve3, sep as sep2 } from "path";
4747
+ import { $ as $4 } from "execa";
4949
4748
  function gitNet(repo, args, timeoutMs) {
4950
4749
  return withHardTimeout(
4951
- $5({ reject: false, timeout: timeoutMs })`git -C ${repo} ${args}`,
4750
+ $4({ reject: false, timeout: timeoutMs })`git -C ${repo} ${args}`,
4952
4751
  "git",
4953
4752
  gitCallLabel(repo, args),
4954
4753
  timeoutMs
@@ -4958,17 +4757,17 @@ async function reclaimStaleWorktree(repo, worktree) {
4958
4757
  await detachWorktree(repo, worktree);
4959
4758
  }
4960
4759
  async function inspectWorktreePath(path) {
4961
- if (!existsSync12(path)) return "free";
4760
+ if (!existsSync11(path)) return "free";
4962
4761
  try {
4963
- if (readdirSync11(path).length === 0) return "free";
4762
+ if (readdirSync9(path).length === 0) return "free";
4964
4763
  } catch {
4965
4764
  return "orphan";
4966
4765
  }
4967
4766
  try {
4968
- if (statSync11(join17(path, ".git")).isDirectory()) return "main-checkout";
4767
+ if (statSync10(join14(path, ".git")).isDirectory()) return "main-checkout";
4969
4768
  } catch {
4970
4769
  }
4971
- const top = await $5({ reject: false })`git -C ${path} rev-parse --show-toplevel`;
4770
+ const top = await $4({ reject: false })`git -C ${path} rev-parse --show-toplevel`;
4972
4771
  return top.exitCode === 0 && samePath(top.stdout.trim(), path) ? "worktree" : "orphan";
4973
4772
  }
4974
4773
  function samePath(a, b) {
@@ -5004,7 +4803,7 @@ async function clearWorktreePath(repo, path, branch, opts = {}) {
5004
4803
  await detachWorktree(repo, path);
5005
4804
  opts.onStaleReclaim?.(path);
5006
4805
  }
5007
- if (!existsSync12(path)) return;
4806
+ if (!existsSync11(path)) return;
5008
4807
  await parkOrphanDir(repo, path, branch);
5009
4808
  }
5010
4809
  async function parkOrphanDir(repo, path, branch) {
@@ -5021,23 +4820,23 @@ async function parkOrphanDir(repo, path, branch) {
5021
4820
  console.error(
5022
4821
  `[git] \u043F\u043E \u043F\u0443\u0442\u0438 worktree ${path} \u043B\u0435\u0436\u0430\u043B \u043A\u0430\u0442\u0430\u043B\u043E\u0433, \u043A\u043E\u0442\u043E\u0440\u044B\u0439 git \u0441\u0432\u043E\u0438\u043C \u0440\u0430\u0431\u043E\u0447\u0438\u043C \u0434\u0435\u0440\u0435\u0432\u043E\u043C \u043D\u0435 \u0441\u0447\u0438\u0442\u0430\u0435\u0442 \u2014 \u043E\u0442\u043E\u0434\u0432\u0438\u043D\u0443\u043B \u0432 ${parked}, \u0447\u0442\u043E\u0431\u044B \u0441\u043F\u0430\u0432\u043D ${branch} \u043F\u043E\u0434\u043D\u044F\u043B\u0441\u044F. \u041F\u043E\u0441\u043C\u043E\u0442\u0440\u0438\u0442\u0435, \u0447\u0442\u043E \u0432\u043D\u0443\u0442\u0440\u0438, \u0438 \u0443\u0434\u0430\u043B\u0438\u0442\u0435, \u0435\u0441\u043B\u0438 \u043D\u0435 \u043D\u0443\u0436\u043D\u043E.`
5023
4822
  );
5024
- await $5({ reject: false })`git -C ${repo} worktree prune`;
4823
+ await $4({ reject: false })`git -C ${repo} worktree prune`;
5025
4824
  }
5026
4825
  function isLinkedWorktree(dir) {
5027
4826
  try {
5028
- return statSync11(join17(dir, ".git")).isFile();
4827
+ return statSync10(join14(dir, ".git")).isFile();
5029
4828
  } catch {
5030
4829
  return false;
5031
4830
  }
5032
4831
  }
5033
4832
  async function detachWorktree(repo, worktree) {
5034
- await $5({ reject: false })`git -C ${repo} worktree remove --force ${worktree}`;
4833
+ await $4({ reject: false })`git -C ${repo} worktree remove --force ${worktree}`;
5035
4834
  if (await ensureWorktreeDirGone(worktree)) {
5036
- await $5({ reject: false })`git -C ${repo} worktree prune`;
4835
+ await $4({ reject: false })`git -C ${repo} worktree prune`;
5037
4836
  }
5038
4837
  }
5039
4838
  async function ensureWorktreeDirGone(worktree) {
5040
- if (!existsSync12(worktree)) return false;
4839
+ if (!existsSync11(worktree)) return false;
5041
4840
  if (!isLinkedWorktree(worktree)) {
5042
4841
  console.error(
5043
4842
  `[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.`
@@ -5052,16 +4851,16 @@ async function ensureWorktreeDirGone(worktree) {
5052
4851
  );
5053
4852
  return true;
5054
4853
  }
5055
- if (existsSync12(worktree)) {
4854
+ if (existsSync11(worktree)) {
5056
4855
  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.`);
5057
4856
  }
5058
4857
  return true;
5059
4858
  }
5060
4859
  async function ensureLongPaths(repo, opts = {}) {
5061
4860
  if ((opts.platform ?? process.platform) !== "win32") return false;
5062
- const cur = (await $5({ reject: false })`git -C ${repo} config --get core.longpaths`).stdout.trim();
4861
+ const cur = (await $4({ reject: false })`git -C ${repo} config --get core.longpaths`).stdout.trim();
5063
4862
  if (cur === "true") return false;
5064
- const res = await $5({ reject: false })`git -C ${repo} config core.longpaths true`;
4863
+ const res = await $4({ reject: false })`git -C ${repo} config core.longpaths true`;
5065
4864
  if (res.exitCode !== 0) {
5066
4865
  console.error(
5067
4866
  `[git] \u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0432\u043A\u043B\u044E\u0447\u0438\u0442\u044C core.longpaths \u0432 ${repo} \u2014 \u043D\u0430 Windows \u0441\u043D\u043E\u0441 worktree \u0434\u0440\u043E\u043D\u0430 \u0431\u0443\u0434\u0435\u0442 \u043F\u0430\u0434\u0430\u0442\u044C \xABFilename too long\xBB \u043D\u0430 node_modules. \u0412\u043A\u043B\u044E\u0447\u0438\u0442\u0435 \u0440\u0443\u043A\u0430\u043C\u0438: \`git -C ${repo} config core.longpaths true\`.`
@@ -5072,10 +4871,10 @@ async function ensureLongPaths(repo, opts = {}) {
5072
4871
  return true;
5073
4872
  }
5074
4873
  async function revParse(repo, ref) {
5075
- return (await $5({ reject: false })`git -C ${repo} rev-parse --verify --quiet ${ref}`).stdout.trim();
4874
+ return (await $4({ reject: false })`git -C ${repo} rev-parse --verify --quiet ${ref}`).stdout.trim();
5076
4875
  }
5077
4876
  async function worktreeForBranch(repo, branch) {
5078
- const out = (await $5`git -C ${repo} worktree list --porcelain`).stdout;
4877
+ const out = (await $4`git -C ${repo} worktree list --porcelain`).stdout;
5079
4878
  const target = `refs/heads/${branch}`;
5080
4879
  let current = null;
5081
4880
  for (const line of out.split("\n")) {
@@ -5096,12 +4895,12 @@ async function checkoutWorktree(repo, path, branch, opts) {
5096
4895
  if (!localSha && !originSha) {
5097
4896
  const freshBase = opts.base ?? await freshWorktreeBase(repo);
5098
4897
  await clearWorktreePath(repo, path, branch, opts);
5099
- await $5`git -C ${repo} worktree add -b ${branch} ${path} ${freshBase}`;
4898
+ await $4`git -C ${repo} worktree add -b ${branch} ${path} ${freshBase}`;
5100
4899
  return { reused: false };
5101
4900
  }
5102
4901
  const busyAt = await worktreeForBranch(repo, branch);
5103
4902
  if (busyAt) {
5104
- const exists = existsSync12(busyAt);
4903
+ const exists = existsSync11(busyAt);
5105
4904
  const live2 = exists && (opts.isWorktreeHeldLive ? await opts.isWorktreeHeldLive(busyAt) : true);
5106
4905
  if (live2) throw new WorktreeBusyError(branch, busyAt);
5107
4906
  if (exists && await worktreeDirty(busyAt)) throw new WorktreeBusyError(branch, busyAt);
@@ -5110,30 +4909,30 @@ async function checkoutWorktree(repo, path, branch, opts) {
5110
4909
  }
5111
4910
  await clearWorktreePath(repo, path, branch, opts);
5112
4911
  if (originSha) {
5113
- await $5`git -C ${repo} worktree add -B ${branch} ${path} ${`origin/${branch}`}`;
4912
+ await $4`git -C ${repo} worktree add -B ${branch} ${path} ${`origin/${branch}`}`;
5114
4913
  return { reused: true, from: "origin", sha: originSha };
5115
4914
  }
5116
- await $5`git -C ${repo} worktree add ${path} ${branch}`;
4915
+ await $4`git -C ${repo} worktree add ${path} ${branch}`;
5117
4916
  return { reused: true, from: "local" };
5118
4917
  }
5119
4918
  async function freshWorktreeBase(repo) {
5120
- const hasOrigin = (await $5({ reject: false })`git -C ${repo} remote get-url origin`).exitCode === 0;
4919
+ const hasOrigin = (await $4({ reject: false })`git -C ${repo} remote get-url origin`).exitCode === 0;
5121
4920
  if (!hasOrigin) return "HEAD";
5122
- await $5`git -C ${repo} fetch --quiet origin`;
4921
+ await $4`git -C ${repo} fetch --quiet origin`;
5123
4922
  return remoteMainRef(repo);
5124
4923
  }
5125
4924
  async function setWorktreeIdentity(worktree, name) {
5126
4925
  const local = name.toLowerCase().replace(/\s+/g, "-");
5127
- await $5`git -C ${worktree} config extensions.worktreeConfig true`;
5128
- await $5`git -C ${worktree} config --worktree user.name ${`${name} (swarm drone)`}`;
5129
- await $5`git -C ${worktree} config --worktree user.email ${`${local}@drones.swarm.local`}`;
4926
+ await $4`git -C ${worktree} config extensions.worktreeConfig true`;
4927
+ await $4`git -C ${worktree} config --worktree user.name ${`${name} (swarm drone)`}`;
4928
+ await $4`git -C ${worktree} config --worktree user.email ${`${local}@drones.swarm.local`}`;
5130
4929
  }
5131
4930
  async function ensureGitExcluded(worktree, pattern) {
5132
4931
  try {
5133
4932
  const commonDir = await gitPath(worktree, "--git-common-dir");
5134
4933
  if (!commonDir) return false;
5135
- const infoDir = join17(commonDir, "info");
5136
- const excludeFile = join17(infoDir, "exclude");
4934
+ const infoDir = join14(commonDir, "info");
4935
+ const excludeFile = join14(infoDir, "exclude");
5137
4936
  let current = "";
5138
4937
  try {
5139
4938
  current = await readFile(excludeFile, "utf8");
@@ -5150,10 +4949,10 @@ async function ensureGitExcluded(worktree, pattern) {
5150
4949
  }
5151
4950
  }
5152
4951
  async function gitPath(worktree, flag) {
5153
- const out = await $5({ reject: false })`git -C ${worktree} rev-parse ${flag}`;
4952
+ const out = await $4({ reject: false })`git -C ${worktree} rev-parse ${flag}`;
5154
4953
  const raw = out.stdout.trim();
5155
4954
  if (out.exitCode !== 0 || !raw) return null;
5156
- return isAbsolute2(raw) ? raw : join17(worktree, raw);
4955
+ return isAbsolute2(raw) ? raw : join14(worktree, raw);
5157
4956
  }
5158
4957
  async function ensureWorktreeHygiene(worktree) {
5159
4958
  for (const pattern of SWARM_EXCLUDE_PATTERNS) await ensureGitExcluded(worktree, pattern);
@@ -5163,54 +4962,54 @@ async function installGuardHooks(worktree) {
5163
4962
  try {
5164
4963
  const gitDir = await gitPath(worktree, "--git-dir");
5165
4964
  if (!gitDir) return false;
5166
- const hooksDir = join17(gitDir, "swarm-hooks");
4965
+ const hooksDir = join14(gitDir, "swarm-hooks");
5167
4966
  const prev = await previousHooksPath(worktree);
5168
4967
  await mkdir(hooksDir, { recursive: true });
5169
4968
  for (const hook of GUARD_HOOKS) {
5170
- await writeFile(join17(hooksDir, hook), guardHookScript(hook, prev ? `${posix(prev)}/${hook}` : null));
5171
- await chmod(join17(hooksDir, hook), 493);
4969
+ await writeFile(join14(hooksDir, hook), guardHookScript(hook, prev ? `${posix(prev)}/${hook}` : null));
4970
+ await chmod(join14(hooksDir, hook), 493);
5172
4971
  }
5173
- await $5`git -C ${worktree} config extensions.worktreeConfig true`;
5174
- await $5`git -C ${worktree} config --worktree core.hooksPath ${posix(hooksDir)}`;
4972
+ await $4`git -C ${worktree} config extensions.worktreeConfig true`;
4973
+ await $4`git -C ${worktree} config --worktree core.hooksPath ${posix(hooksDir)}`;
5175
4974
  return true;
5176
4975
  } catch {
5177
4976
  return false;
5178
4977
  }
5179
4978
  }
5180
4979
  function posix(p) {
5181
- return (sep3 === "\\" ? p.replace(/\\/g, "/") : p).replace(/\/+$/, "");
4980
+ return (sep2 === "\\" ? p.replace(/\\/g, "/") : p).replace(/\/+$/, "");
5182
4981
  }
5183
4982
  async function previousHooksPath(worktree) {
5184
4983
  for (const scope of ["--local", "--global", "--system"]) {
5185
- const out = await $5({ reject: false })`git -C ${worktree} config ${scope} --get core.hooksPath`;
4984
+ const out = await $4({ reject: false })`git -C ${worktree} config ${scope} --get core.hooksPath`;
5186
4985
  const value = out.stdout.trim();
5187
4986
  if (out.exitCode === 0 && value) return value;
5188
4987
  }
5189
4988
  const commonDir = await gitPath(worktree, "--git-common-dir");
5190
- return commonDir ? join17(commonDir, "hooks") : null;
4989
+ return commonDir ? join14(commonDir, "hooks") : null;
5191
4990
  }
5192
4991
  async function removeWorktree(repo, path) {
5193
- const branch = (await $5({ reject: false })`git -C ${path} symbolic-ref --quiet --short HEAD`).stdout.trim();
4992
+ const branch = (await $4({ reject: false })`git -C ${path} symbolic-ref --quiet --short HEAD`).stdout.trim();
5194
4993
  await releaseWorktree(repo, path);
5195
- if (branch) await $5({ reject: false })`git -C ${repo} branch -D ${branch}`;
4994
+ if (branch) await $4({ reject: false })`git -C ${repo} branch -D ${branch}`;
5196
4995
  }
5197
4996
  async function releaseWorktree(repo, path) {
5198
4997
  await cleanupWorktreeProcesses(path);
5199
4998
  await detachWorktree(repo, path);
5200
4999
  }
5201
5000
  async function worktreeDirty(path) {
5202
- const st = await $5({ reject: false })`git -C ${path} status --porcelain --untracked-files=all`;
5001
+ const st = await $4({ reject: false })`git -C ${path} status --porcelain --untracked-files=all`;
5203
5002
  if (st.exitCode !== 0) return true;
5204
5003
  const status = st.stdout.trim();
5205
5004
  if (status) return true;
5206
- const unpushed = (await $5({ reject: false })`git -C ${path} rev-list --count HEAD --not --remotes`).stdout.trim();
5005
+ const unpushed = (await $4({ reject: false })`git -C ${path} rev-list --count HEAD --not --remotes`).stdout.trim();
5207
5006
  return unpushed !== "" && unpushed !== "0";
5208
5007
  }
5209
5008
  async function remoteMainRef(repo) {
5210
- const head = (await $5({ reject: false })`git -C ${repo} symbolic-ref --quiet --short refs/remotes/origin/HEAD`).stdout.trim();
5009
+ const head = (await $4({ reject: false })`git -C ${repo} symbolic-ref --quiet --short refs/remotes/origin/HEAD`).stdout.trim();
5211
5010
  if (head) return head;
5212
5011
  for (const cand of ["origin/main", "origin/master"]) {
5213
- const ok2 = await $5({ reject: false })`git -C ${repo} rev-parse --verify --quiet ${cand}`;
5012
+ const ok2 = await $4({ reject: false })`git -C ${repo} rev-parse --verify --quiet ${cand}`;
5214
5013
  if (ok2.exitCode === 0) return cand;
5215
5014
  }
5216
5015
  throw new Error(`\u043D\u0435 \u043D\u0430\u0448\u0451\u043B \u0434\u0435\u0444\u043E\u043B\u0442-\u0432\u0435\u0442\u043A\u0443 origin \u0432 ${repo} (\u043D\u0435\u0442 origin/HEAD, origin/main, origin/master)`);
@@ -5248,9 +5047,306 @@ var init_git = __esm({
5248
5047
  }
5249
5048
  });
5250
5049
 
5050
+ // src/boundedRun.ts
5051
+ import { spawn as spawn2 } from "child_process";
5052
+ var init_boundedRun = __esm({
5053
+ "src/boundedRun.ts"() {
5054
+ "use strict";
5055
+ init_procCleanup();
5056
+ }
5057
+ });
5058
+
5059
+ // src/prepareLock.ts
5060
+ import { createHash } from "crypto";
5061
+ import { closeSync as closeSync4, openSync as openSync4, rmSync, statSync as statSync11, writeSync as writeSync2 } from "fs";
5062
+ import { join as join15 } from "path";
5063
+ import { tmpdir } from "os";
5064
+ var WAIT_TIMEOUT_MS, STALE_MS;
5065
+ var init_prepareLock = __esm({
5066
+ "src/prepareLock.ts"() {
5067
+ "use strict";
5068
+ WAIT_TIMEOUT_MS = 5 * 6e4;
5069
+ STALE_MS = 20 * 6e4;
5070
+ }
5071
+ });
5072
+
5073
+ // src/envCache.ts
5074
+ import { createHash as createHash2 } from "crypto";
5075
+ import { cp, link, lstat, mkdir as mkdir2, readdir, readlink, rename as rename2, rm as rm2, stat, symlink, utimes, writeFile as writeFile2 } from "fs/promises";
5076
+ import { existsSync as existsSync12, readFileSync as readFileSync11 } from "fs";
5077
+ import { join as join16 } from "path";
5078
+ var init_envCache = __esm({
5079
+ "src/envCache.ts"() {
5080
+ "use strict";
5081
+ init_config();
5082
+ }
5083
+ });
5084
+
5085
+ // src/deps.ts
5086
+ import { existsSync as existsSync13, readdirSync as readdirSync10, readFileSync as readFileSync12 } from "fs";
5087
+ import { join as join17 } from "path";
5088
+ import { execa as execa2 } from "execa";
5089
+ var PREPARE_TIMEOUT_MS;
5090
+ var init_deps2 = __esm({
5091
+ "src/deps.ts"() {
5092
+ "use strict";
5093
+ init_boundedRun();
5094
+ init_prepareLock();
5095
+ init_config();
5096
+ init_envCache();
5097
+ PREPARE_TIMEOUT_MS = 15 * 6e4;
5098
+ }
5099
+ });
5100
+
5101
+ // src/orchestrator.ts
5102
+ import { existsSync as existsSync14, mkdirSync as mkdirSync9, rmSync as rmSync2 } from "fs";
5103
+ import { join as join18, dirname as dirname3 } from "path";
5104
+ var init_orchestrator = __esm({
5105
+ "src/orchestrator.ts"() {
5106
+ "use strict";
5107
+ init_src();
5108
+ init_git();
5109
+ init_deps2();
5110
+ init_config();
5111
+ }
5112
+ });
5113
+
5114
+ // src/droneChannel.ts
5115
+ import { createHmac, randomBytes, timingSafeEqual } from "crypto";
5116
+ import { chmodSync as chmodSync2, mkdirSync as mkdirSync10, readFileSync as readFileSync13, writeFileSync as writeFileSync9 } from "fs";
5117
+ import { dirname as dirname4 } from "path";
5118
+ import { serve } from "@hono/node-server";
5119
+ function loadChannelSecret(path) {
5120
+ try {
5121
+ const s = readFileSync13(path, "utf8").trim();
5122
+ if (s.length >= 32) return s;
5123
+ } catch {
5124
+ }
5125
+ const secret = randomBytes(32).toString("hex");
5126
+ mkdirSync10(dirname4(path), { recursive: true });
5127
+ writeFileSync9(path, secret, { mode: 384 });
5128
+ try {
5129
+ chmodSync2(path, 384);
5130
+ } catch {
5131
+ }
5132
+ return secret;
5133
+ }
5134
+ function sign(runKey, secret) {
5135
+ return createHmac("sha256", secret).update(runKey).digest("base64url");
5136
+ }
5137
+ function mintChannelToken(runKey, secret) {
5138
+ return `${Buffer.from(runKey, "utf8").toString("base64url")}.${sign(runKey, secret)}`;
5139
+ }
5140
+ function verifyChannelToken(token, secret) {
5141
+ const dot = token.lastIndexOf(".");
5142
+ if (dot <= 0) return null;
5143
+ const runKey = Buffer.from(token.slice(0, dot), "base64url").toString("utf8");
5144
+ if (!runKey) return null;
5145
+ const got = Buffer.from(token.slice(dot + 1));
5146
+ const want = Buffer.from(sign(runKey, secret));
5147
+ if (got.length !== want.length || !timingSafeEqual(got, want)) return null;
5148
+ return runKey;
5149
+ }
5150
+ function mintLocalCliToken(secret) {
5151
+ return mintChannelToken(LOCAL_CLI_KEY, secret);
5152
+ }
5153
+ function verifyLocalCliToken(token, secret) {
5154
+ return verifyChannelToken(token, secret) === LOCAL_CLI_KEY;
5155
+ }
5156
+ var LOCAL_CLI_KEY, EVENT_KIND_SET;
5157
+ var init_droneChannel = __esm({
5158
+ "src/droneChannel.ts"() {
5159
+ "use strict";
5160
+ init_src();
5161
+ init_orchestrator();
5162
+ LOCAL_CLI_KEY = "cli";
5163
+ EVENT_KIND_SET = new Set(EVENT_KINDS);
5164
+ }
5165
+ });
5166
+
5167
+ // src/authState.ts
5168
+ function noteTokenRejected(nowMs = Date.now()) {
5169
+ if (!denial) {
5170
+ denial = { since: nowMs, lastShoutAt: nowMs, count: 1 };
5171
+ return revokedTokenComplaint();
5172
+ }
5173
+ denial.count += 1;
5174
+ if (nowMs - denial.lastShoutAt < SHOUT_EVERY_MS) return null;
5175
+ denial.lastShoutAt = nowMs;
5176
+ return `${revokedTokenComplaint()}
5177
+ ${deniedSinceLine(nowMs)}
5178
+ `;
5179
+ }
5180
+ function noteTokenAccepted() {
5181
+ denial = null;
5182
+ }
5183
+ function authStateLine(nowMs = Date.now()) {
5184
+ if (!denial) return null;
5185
+ return `\u0414\u041E\u0421\u0422\u0423\u041F \u041A TASKLESS \u041E\u0422\u041E\u0417\u0412\u0410\u041D \u2014 ${deniedSinceLine(nowMs)}. \u041F\u043E\u0447\u0438\u043D\u0438 \u043D\u0430 \u044D\u0442\u043E\u0439 \u043C\u0430\u0448\u0438\u043D\u0435: swarm login`;
5186
+ }
5187
+ function deniedSinceLine(nowMs) {
5188
+ const d = denial;
5189
+ if (!d) return "";
5190
+ const min = Math.max(1, Math.round((nowMs - d.since) / 6e4));
5191
+ return `\u043F\u0440\u043E\u0434 \u043E\u0442\u0432\u0435\u0440\u0433\u0430\u0435\u0442 \u0442\u043E\u043A\u0435\u043D ${min} \u043C\u0438\u043D, \u043E\u0442\u043A\u0430\u0437\u043E\u0432 ${d.count}`;
5192
+ }
5193
+ var SHOUT_EVERY_MS, denial;
5194
+ var init_authState = __esm({
5195
+ "src/authState.ts"() {
5196
+ "use strict";
5197
+ init_agentToken();
5198
+ SHOUT_EVERY_MS = 10 * 6e4;
5199
+ denial = null;
5200
+ }
5201
+ });
5202
+
5203
+ // src/oauth.ts
5204
+ import { createHash as createHash3, randomBytes as randomBytes2 } from "crypto";
5205
+ import { readFileSync as readFileSync14, writeFileSync as writeFileSync10, unlinkSync as unlinkSync3 } from "fs";
5206
+ import { join as join19 } from "path";
5207
+ function makePkce() {
5208
+ const verifier = randomBytes2(48).toString("base64url");
5209
+ const challenge = createHash3("sha256").update(verifier).digest("base64url");
5210
+ return { verifier, challenge };
5211
+ }
5212
+ async function registerClient(args, fetchFn = fetch) {
5213
+ const res = await fetchFn(`${base2(args.api)}${REGISTER}`, {
5214
+ method: "POST",
5215
+ headers: { "Content-Type": "application/json" },
5216
+ body: JSON.stringify({
5217
+ client_name: args.name ?? "Taskless Swarm",
5218
+ redirect_uris: [args.redirectUri],
5219
+ token_endpoint_auth_method: "none"
5220
+ })
5221
+ });
5222
+ if (!res.ok) throw new Error(`register: HTTP ${res.status} ${(await res.text().catch(() => "")).slice(0, 160)}`);
5223
+ const j = await res.json();
5224
+ if (!j.client_id) throw new Error("register: \u0432 \u043E\u0442\u0432\u0435\u0442\u0435 \u043D\u0435\u0442 client_id");
5225
+ return j.client_id;
5226
+ }
5227
+ function authorizeUrl(args) {
5228
+ const u = new URL(`${base2(args.api)}${AUTHORIZE}`);
5229
+ u.searchParams.set("response_type", "code");
5230
+ u.searchParams.set("client_id", args.clientId);
5231
+ u.searchParams.set("redirect_uri", args.redirectUri);
5232
+ u.searchParams.set("scope", SCOPE);
5233
+ u.searchParams.set("code_challenge", args.challenge);
5234
+ u.searchParams.set("code_challenge_method", "S256");
5235
+ u.searchParams.set("state", args.state);
5236
+ return u.toString();
5237
+ }
5238
+ async function postToken(api, params, fetchFn) {
5239
+ const res = await fetchFn(`${base2(api)}${TOKEN}`, {
5240
+ method: "POST",
5241
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
5242
+ body: new URLSearchParams(params).toString()
5243
+ });
5244
+ const text = await res.text();
5245
+ if (!res.ok) throw new Error(`token ${params.grant_type}: HTTP ${res.status} ${text.slice(0, 200)}`);
5246
+ const j = JSON.parse(text);
5247
+ if (!j.access_token) throw new Error("token: \u0432 \u043E\u0442\u0432\u0435\u0442\u0435 \u043D\u0435\u0442 access_token");
5248
+ return j;
5249
+ }
5250
+ function exchangeCode(args, fetchFn = fetch) {
5251
+ return postToken(
5252
+ args.api,
5253
+ {
5254
+ grant_type: "authorization_code",
5255
+ code: args.code,
5256
+ code_verifier: args.verifier,
5257
+ client_id: args.clientId,
5258
+ redirect_uri: args.redirectUri
5259
+ },
5260
+ fetchFn
5261
+ );
5262
+ }
5263
+ function refreshTokens(args, fetchFn = fetch) {
5264
+ return postToken(
5265
+ args.api,
5266
+ { grant_type: "refresh_token", refresh_token: args.refreshToken, client_id: args.clientId },
5267
+ fetchFn
5268
+ );
5269
+ }
5270
+ function emailFromIdToken(idToken) {
5271
+ const payload = idToken?.split(".")[1];
5272
+ if (!payload) return void 0;
5273
+ try {
5274
+ return JSON.parse(Buffer.from(payload, "base64url").toString("utf8")).email;
5275
+ } catch {
5276
+ return void 0;
5277
+ }
5278
+ }
5279
+ function toStore(clientId, t, now) {
5280
+ return {
5281
+ clientId,
5282
+ accessToken: t.access_token,
5283
+ refreshToken: t.refresh_token,
5284
+ expiresAt: now + t.expires_in * 1e3,
5285
+ email: emailFromIdToken(t.id_token)
5286
+ };
5287
+ }
5288
+ function loadStore() {
5289
+ try {
5290
+ return JSON.parse(readFileSync14(STORE_PATH2, "utf8"));
5291
+ } catch {
5292
+ return null;
5293
+ }
5294
+ }
5295
+ function saveStore(s) {
5296
+ writeFileSync10(STORE_PATH2, JSON.stringify(s, null, 2), { mode: 384 });
5297
+ }
5298
+ function clearStore() {
5299
+ try {
5300
+ unlinkSync3(STORE_PATH2);
5301
+ } catch {
5302
+ }
5303
+ }
5304
+ function loadClientId() {
5305
+ try {
5306
+ return JSON.parse(readFileSync14(CLIENT_PATH, "utf8")).clientId;
5307
+ } catch {
5308
+ return null;
5309
+ }
5310
+ }
5311
+ async function ensureClientId(api, redirectUri, fetchFn = fetch) {
5312
+ const existing = loadClientId();
5313
+ if (existing) return existing;
5314
+ const clientId = await registerClient({ api, redirectUri }, fetchFn);
5315
+ writeFileSync10(CLIENT_PATH, JSON.stringify({ clientId }, null, 2), { mode: 384 });
5316
+ return clientId;
5317
+ }
5318
+ async function ensureAccess(store, opts = {}) {
5319
+ const api = opts.api ?? TASKLESS_API;
5320
+ const now = opts.now ?? Date.now();
5321
+ const fetchFn = opts.fetchFn ?? fetch;
5322
+ if (store.expiresAt - now > 6e4) return { accessToken: store.accessToken };
5323
+ try {
5324
+ const t = await refreshTokens({ api, clientId: store.clientId, refreshToken: store.refreshToken }, fetchFn);
5325
+ const next = toStore(store.clientId, t, now);
5326
+ next.email = next.email ?? store.email;
5327
+ return { accessToken: next.accessToken, store: next };
5328
+ } catch {
5329
+ return null;
5330
+ }
5331
+ }
5332
+ var REGISTER, AUTHORIZE, TOKEN, SCOPE, STORE_PATH2, CLIENT_PATH, base2;
5333
+ var init_oauth = __esm({
5334
+ "src/oauth.ts"() {
5335
+ "use strict";
5336
+ init_config();
5337
+ REGISTER = "/api/oauth/register";
5338
+ AUTHORIZE = "/api/oauth/authorize";
5339
+ TOKEN = "/api/oauth/token";
5340
+ SCOPE = "openid profile email taskless:full";
5341
+ STORE_PATH2 = join19(SWARM_HOME, "oauth.json");
5342
+ CLIENT_PATH = join19(SWARM_HOME, "oauth-client.json");
5343
+ base2 = (api) => api.replace(/\/$/, "");
5344
+ }
5345
+ });
5346
+
5251
5347
  // src/attachments.ts
5252
- import { mkdir as mkdir2, readFile as readFile2, readdir, stat, unlink, writeFile as writeFile2 } from "fs/promises";
5253
- import { extname, join as join18 } from "path";
5348
+ import { mkdir as mkdir3, readFile as readFile2, readdir as readdir2, stat as stat2, unlink, writeFile as writeFile3 } from "fs/promises";
5349
+ import { extname, join as join22 } from "path";
5254
5350
  var ATTACHMENTS_DIR, ATTACH_MAX_TOTAL_BYTES, ATTACH_MAX_FILE_BYTES, IMAGE_EXT, DOC_EXT, TEXT_EXT, KNOWN_EXT;
5255
5351
  var init_attachments = __esm({
5256
5352
  "src/attachments.ts"() {
@@ -5269,7 +5365,7 @@ var init_attachments = __esm({
5269
5365
 
5270
5366
  // src/shotUpload.ts
5271
5367
  import { readFile as fsReadFile } from "fs/promises";
5272
- import { basename as basename6, isAbsolute as isAbsolute3, join as join19 } from "path";
5368
+ import { basename as basename6, isAbsolute as isAbsolute3, join as join23 } from "path";
5273
5369
  var SHOT_MAX_FILE_BYTES;
5274
5370
  var init_shotUpload = __esm({
5275
5371
  "src/shotUpload.ts"() {
@@ -5320,11 +5416,11 @@ var init_prodHttp = __esm({
5320
5416
  });
5321
5417
 
5322
5418
  // src/workspace.ts
5323
- import { readFileSync as readFileSync13, writeFileSync as writeFileSync11, unlinkSync as unlinkSync4 } from "fs";
5324
- import { join as join20 } from "path";
5419
+ import { readFileSync as readFileSync15, writeFileSync as writeFileSync11, unlinkSync as unlinkSync4 } from "fs";
5420
+ import { join as join24 } from "path";
5325
5421
  function loadWorkspace() {
5326
5422
  try {
5327
- const w = JSON.parse(readFileSync13(WORKSPACE_PATH, "utf8"));
5423
+ const w = JSON.parse(readFileSync15(WORKSPACE_PATH, "utf8"));
5328
5424
  return w && typeof w.id === "string" && w.id ? w : null;
5329
5425
  } catch {
5330
5426
  return null;
@@ -5347,7 +5443,7 @@ var init_workspace = __esm({
5347
5443
  "src/workspace.ts"() {
5348
5444
  "use strict";
5349
5445
  init_config();
5350
- WORKSPACE_PATH = join20(SWARM_HOME, "workspace.json");
5446
+ WORKSPACE_PATH = join24(SWARM_HOME, "workspace.json");
5351
5447
  }
5352
5448
  });
5353
5449
 
@@ -5788,14 +5884,14 @@ var init_daemonLink = __esm({
5788
5884
  });
5789
5885
 
5790
5886
  // src/pauseState.ts
5791
- import { existsSync as existsSync13, readFileSync as readFileSync14, renameSync as renameSync5, unlinkSync as unlinkSync5, writeFileSync as writeFileSync12 } from "fs";
5792
- import { join as join21 } from "path";
5887
+ import { existsSync as existsSync16, readFileSync as readFileSync16, renameSync as renameSync5, unlinkSync as unlinkSync5, writeFileSync as writeFileSync12 } from "fs";
5888
+ import { join as join25 } from "path";
5793
5889
  function pauseStatePath(home) {
5794
- return join21(home, "pause.json");
5890
+ return join25(home, "pause.json");
5795
5891
  }
5796
5892
  function loadPauseState(home, io = {}) {
5797
- const exists = io.exists ?? existsSync13;
5798
- const readFile3 = io.readFile ?? ((p) => readFileSync14(p, "utf8"));
5893
+ const exists = io.exists ?? existsSync16;
5894
+ const readFile3 = io.readFile ?? ((p) => readFileSync16(p, "utf8"));
5799
5895
  const path = pauseStatePath(home);
5800
5896
  if (!exists(path)) return ACTIVE;
5801
5897
  try {
@@ -5814,15 +5910,15 @@ function loadPauseState(home, io = {}) {
5814
5910
  function savePauseState(home, state, io = {}) {
5815
5911
  const path = pauseStatePath(home);
5816
5912
  if (!state.paused) {
5817
- const remove = io.remove ?? ((p) => existsSync13(p) && unlinkSync5(p));
5913
+ const remove = io.remove ?? ((p) => existsSync16(p) && unlinkSync5(p));
5818
5914
  remove(path);
5819
5915
  return;
5820
5916
  }
5821
- const writeFile3 = io.writeFile ?? ((p, data) => {
5917
+ const writeFile4 = io.writeFile ?? ((p, data) => {
5822
5918
  writeFileSync12(`${p}.tmp`, data);
5823
5919
  renameSync5(`${p}.tmp`, p);
5824
5920
  });
5825
- writeFile3(path, JSON.stringify(state, null, 2));
5921
+ writeFile4(path, JSON.stringify(state, null, 2));
5826
5922
  }
5827
5923
  function makePauseState(source, reason, now = Date.now()) {
5828
5924
  return {
@@ -5856,10 +5952,10 @@ var init_pauseState = __esm({
5856
5952
  });
5857
5953
 
5858
5954
  // src/heartbeat.ts
5859
- import { readFileSync as readFileSync15, renameSync as renameSync6, writeFileSync as writeFileSync13 } from "fs";
5955
+ import { readFileSync as readFileSync17, renameSync as renameSync6, writeFileSync as writeFileSync13 } from "fs";
5860
5956
  function readHeartbeat(path) {
5861
5957
  try {
5862
- const ms = Number(readFileSync15(path, "utf8").trim());
5958
+ const ms = Number(readFileSync17(path, "utf8").trim());
5863
5959
  return Number.isFinite(ms) ? ms : null;
5864
5960
  } catch {
5865
5961
  return null;
@@ -5878,7 +5974,7 @@ __export(db_exports, {
5878
5974
  });
5879
5975
  import { createRequire as createRequire2 } from "module";
5880
5976
  import { randomUUID as randomUUID3 } from "crypto";
5881
- import { existsSync as existsSync14 } from "fs";
5977
+ import { existsSync as existsSync17 } from "fs";
5882
5978
  import { resolve as resolve4 } from "path";
5883
5979
  function rowToQuestion(row) {
5884
5980
  return {
@@ -5966,7 +6062,9 @@ function rowToRun(row) {
5966
6062
  // TASWM-597: repoless-прогон (офлайн-проект, без worktree/PR). null/0 → код-конвейер.
5967
6063
  repoless: row.repoless === 1,
5968
6064
  created_at: row.created_at,
5969
- updated_at: row.updated_at
6065
+ updated_at: row.updated_at,
6066
+ // TASWM-692: нет колонки (строка прочитана до ALTER) → null, границу не выдумываем.
6067
+ started_at: row.started_at ?? null
5970
6068
  };
5971
6069
  }
5972
6070
  function isForeignKeyError(err) {
@@ -5990,6 +6088,7 @@ var init_db = __esm({
5990
6088
  init_names2();
5991
6089
  init_zoneNotes();
5992
6090
  init_storm();
6091
+ init_authorRun();
5993
6092
  init_store();
5994
6093
  init_src();
5995
6094
  TERMINAL_SQL = TERMINAL_STATUSES.map((s) => `'${s}'`).join(",");
@@ -6086,6 +6185,12 @@ CREATE TABLE IF NOT EXISTS imports (
6086
6185
  // для importDb (второй Database, source)
6087
6186
  /** Идентификатор этой жизни файла базы (TASWM-419) — им неймспейсятся каталоги run-log'ов. */
6088
6187
  instanceId;
6188
+ /**
6189
+ * TASWM-680. Слаги, чья задача закрыта. Живёт в памяти процесса: sqlite задач не
6190
+ * хранит, а «закрыта» приходит из Taskless на тике. Рестарт демона карту обнуляет
6191
+ * и спрашивает снова — остановленный блокер без ответа остаётся ожиданием.
6192
+ */
6193
+ taskClosedSlugs = /* @__PURE__ */ new Set();
6089
6194
  constructor(path = "swarm.db", defaultRepo = "") {
6090
6195
  this.defaultRepo = normalizeRepo(defaultRepo);
6091
6196
  this.databaseCtor = loadBetterSqlite3();
@@ -6164,7 +6269,11 @@ CREATE TABLE IF NOT EXISTS imports (
6164
6269
  // потом неоткуда.
6165
6270
  "ALTER TABLE runs ADD COLUMN changed_paths TEXT",
6166
6271
  // TASWM-648: шторм по провайдеру. NULL — запись до задачи (шторм модели роя).
6167
- "ALTER TABLE events ADD COLUMN provider TEXT"
6272
+ "ALTER TABLE events ADD COLUMN provider TEXT",
6273
+ // TASWM-692: когда на прогоне последний раз пошёл работать дрон (не created_at).
6274
+ // Граница сессии для прогонов без события лаунчера. NULL — ещё не стартовал
6275
+ // либо прогон заведён до этой колонки и с тех пор в running не переходил.
6276
+ "ALTER TABLE runs ADD COLUMN started_at TEXT"
6168
6277
  ]) {
6169
6278
  try {
6170
6279
  this.db.exec(alter);
@@ -6308,8 +6417,9 @@ CREATE TABLE IF NOT EXISTS imports (
6308
6417
  return rows.map(rowToRun);
6309
6418
  }
6310
6419
  updateRun(id, patch) {
6420
+ const prev = this.getRun(id);
6311
6421
  const fields = Object.keys(patch);
6312
- if (fields.length === 0) return this.getRun(id);
6422
+ if (fields.length === 0) return prev;
6313
6423
  const set = fields.map((f) => `${f} = ?`).join(", ");
6314
6424
  const vals = fields.map((f) => {
6315
6425
  const v = patch[f];
@@ -6322,6 +6432,9 @@ CREATE TABLE IF NOT EXISTS imports (
6322
6432
  return v;
6323
6433
  });
6324
6434
  this.db.prepare(`UPDATE runs SET ${set}, updated_at = datetime('now') WHERE id = ?`).run(...vals, id);
6435
+ if (prev && sessionStartMoved(prev, patch)) {
6436
+ this.db.prepare("UPDATE runs SET started_at = datetime('now') WHERE id = ?").run(id);
6437
+ }
6325
6438
  return this.getRun(id);
6326
6439
  }
6327
6440
  /**
@@ -6472,7 +6585,7 @@ CREATE TABLE IF NOT EXISTS imports (
6472
6585
  */
6473
6586
  activeRunForSlug(slug) {
6474
6587
  const row = this.db.prepare(
6475
- `SELECT * FROM runs WHERE task_slug = ? AND status NOT IN (${TERMINAL_SQL}) AND reviews_run_id IS NULL AND resolves_run_id IS NULL AND verifies_run_id IS NULL ORDER BY id DESC LIMIT 1`
6588
+ `SELECT * FROM runs WHERE task_slug = ? AND status NOT IN (${TERMINAL_SQL}) AND reviews_run_id IS NULL AND resolves_run_id IS NULL AND verifies_run_id IS NULL AND superseded_by IS NULL AND (kind IS NULL OR kind = 'drone' OR kind = 'hero') ORDER BY id DESC LIMIT 1`
6476
6589
  ).get(slug);
6477
6590
  return row ? rowToRun(row) : null;
6478
6591
  }
@@ -6506,6 +6619,11 @@ CREATE TABLE IF NOT EXISTS imports (
6506
6619
  * Несуществующий/зациклённый слаг прогонов не имеет вовсе → `pending` → прогон ждёт, как и
6507
6620
  * раньше, но очередь не виснет (гейт — пропуск в цикле, не блокировка).
6508
6621
  */
6622
+ /** TASWM-680. См. SwarmStore.noteTaskClosed. */
6623
+ noteTaskClosed(slug, closed) {
6624
+ if (closed) this.taskClosedSlugs.add(slug);
6625
+ else this.taskClosedSlugs.delete(slug);
6626
+ }
6509
6627
  unmetDeps(depends_on) {
6510
6628
  return this.depVerdicts(depends_on).filter((d) => !d.met).map((d) => d.slug);
6511
6629
  }
@@ -6526,7 +6644,10 @@ CREATE TABLE IF NOT EXISTS imports (
6526
6644
  list.push({ status: r.status, name: r.name, stopReason: r.stop_reason });
6527
6645
  bySlug.set(r.task_slug, list);
6528
6646
  }
6529
- return depends_on.map((slug) => ({ slug, ...judgeDep(bySlug.get(slug) ?? []) }));
6647
+ return depends_on.map((slug) => ({
6648
+ slug,
6649
+ ...judgeDep(bySlug.get(slug) ?? [], { taskClosed: this.taskClosedSlugs.has(slug) })
6650
+ }));
6530
6651
  }
6531
6652
  /** Все репо, засветившиеся в прогонах — whitelist для валидации spawn из веба. */
6532
6653
  distinctRepos() {
@@ -6556,7 +6677,7 @@ CREATE TABLE IF NOT EXISTS imports (
6556
6677
  const repoN = normalizeRepo(repo);
6557
6678
  const already = this.db.prepare("SELECT run_count FROM imports WHERE source = ?").get(abs);
6558
6679
  if (already) return { imported: false, runs: already.run_count };
6559
- if (!existsSync14(abs)) throw new Error(`import-db: \u0444\u0430\u0439\u043B\u0430 \u043D\u0435\u0442: ${abs}`);
6680
+ if (!existsSync17(abs)) throw new Error(`import-db: \u0444\u0430\u0439\u043B\u0430 \u043D\u0435\u0442: ${abs}`);
6560
6681
  const src = new this.databaseCtor(abs);
6561
6682
  try {
6562
6683
  const runs = src.prepare("SELECT * FROM runs ORDER BY id").all();
@@ -6924,8 +7045,8 @@ CREATE TABLE IF NOT EXISTS imports (
6924
7045
  });
6925
7046
 
6926
7047
  // src/repoScan.ts
6927
- import { readdirSync as readdirSync12, readFileSync as readFileSync16, statSync as statSync12 } from "fs";
6928
- import { join as join22 } from "path";
7048
+ import { readdirSync as readdirSync13, readFileSync as readFileSync18, statSync as statSync13 } from "fs";
7049
+ import { join as join26 } from "path";
6929
7050
  var init_repoScan = __esm({
6930
7051
  "src/repoScan.ts"() {
6931
7052
  "use strict";
@@ -6935,8 +7056,8 @@ var init_repoScan = __esm({
6935
7056
 
6936
7057
  // src/repoDiscovery.ts
6937
7058
  import { homedir as homedir7 } from "os";
6938
- import { readFileSync as readFileSync17, renameSync as renameSync7, writeFileSync as writeFileSync14 } from "fs";
6939
- import { isAbsolute as isAbsolute4, join as join23, resolve as resolve5 } from "path";
7059
+ import { readFileSync as readFileSync19, renameSync as renameSync7, writeFileSync as writeFileSync14 } from "fs";
7060
+ import { isAbsolute as isAbsolute4, join as join27, resolve as resolve5 } from "path";
6940
7061
  function repoMapLines(rows) {
6941
7062
  if (!rows?.length) return [];
6942
7063
  const missing = rows.filter((r) => !r.path).length;
@@ -6951,7 +7072,7 @@ function repoMapLines(rows) {
6951
7072
  }
6952
7073
  function loadRepoMapCache(path) {
6953
7074
  try {
6954
- const raw = JSON.parse(readFileSync17(path, "utf8"));
7075
+ const raw = JSON.parse(readFileSync19(path, "utf8"));
6955
7076
  if (!Array.isArray(raw?.entries)) return { scannedAt: null, entries: [] };
6956
7077
  return {
6957
7078
  scannedAt: typeof raw.scannedAt === "string" && raw.scannedAt ? raw.scannedAt : null,
@@ -7041,46 +7162,46 @@ function uptimeText(startedAt, now) {
7041
7162
  const hr = Math.floor(min / 60);
7042
7163
  return `${hr} \u0447 ${min % 60} \u043C\u0438\u043D`;
7043
7164
  }
7044
- function linkTrouble(link) {
7045
- if (link.kind === "ok" || link.kind === "no-prod" || link.kind === "starting") return null;
7046
- if (link.kind === "unmeasured") {
7165
+ function linkTrouble(link2) {
7166
+ if (link2.kind === "ok" || link2.kind === "no-prod" || link2.kind === "starting") return null;
7167
+ if (link2.kind === "unmeasured") {
7047
7168
  return {
7048
7169
  id: "link-unmeasured",
7049
- why: `\u043F\u0440\u043E \u0441\u0432\u044F\u0437\u044C \u0441 \u043F\u0440\u043E\u0434\u043E\u043C \u0441\u043A\u0430\u0437\u0430\u0442\u044C \u043D\u0435\u0447\u0435\u043C: \u0434\u0435\u043C\u043E\u043D \u0440\u0430\u0431\u043E\u0442\u0430\u0435\u0442 \u043D\u0430 \u043A\u043E\u0434\u0435 \u0421\u0422\u0410\u0420\u0415\u0415 \u044D\u0442\u043E\u0439 \u043A\u043E\u043C\u0430\u043D\u0434\u044B${link.detail ? ` (${link.detail})` : ""} \u2014 \u0442\u043E\u043A\u0435\u043D \u043C\u043E\u0433 \u0431\u044B\u0442\u044C \u043E\u0442\u0432\u0435\u0440\u0433\u043D\u0443\u0442, \u0430 \u0441\u0435\u0442\u044C \u043B\u0435\u0436\u0430\u0442\u044C, \u0438 \u0441\u0442\u0430\u0442\u0443\u0441 \u044D\u0442\u043E\u0433\u043E \u043D\u0435 \u0443\u0432\u0438\u0434\u0438\u0442`,
7170
+ why: `\u043F\u0440\u043E \u0441\u0432\u044F\u0437\u044C \u0441 \u043F\u0440\u043E\u0434\u043E\u043C \u0441\u043A\u0430\u0437\u0430\u0442\u044C \u043D\u0435\u0447\u0435\u043C: \u0434\u0435\u043C\u043E\u043D \u0440\u0430\u0431\u043E\u0442\u0430\u0435\u0442 \u043D\u0430 \u043A\u043E\u0434\u0435 \u0421\u0422\u0410\u0420\u0415\u0415 \u044D\u0442\u043E\u0439 \u043A\u043E\u043C\u0430\u043D\u0434\u044B${link2.detail ? ` (${link2.detail})` : ""} \u2014 \u0442\u043E\u043A\u0435\u043D \u043C\u043E\u0433 \u0431\u044B\u0442\u044C \u043E\u0442\u0432\u0435\u0440\u0433\u043D\u0443\u0442, \u0430 \u0441\u0435\u0442\u044C \u043B\u0435\u0436\u0430\u0442\u044C, \u0438 \u0441\u0442\u0430\u0442\u0443\u0441 \u044D\u0442\u043E\u0433\u043E \u043D\u0435 \u0443\u0432\u0438\u0434\u0438\u0442`,
7050
7171
  fixes: [
7051
7172
  { what: "\u043F\u0435\u0440\u0435\u0437\u0430\u043F\u0443\u0441\u0442\u0438\u0442\u044C \u0434\u0435\u043C\u043E\u043D\u0430 \u043D\u0430 \u0443\u0441\u0442\u0430\u043D\u043E\u0432\u043B\u0435\u043D\u043D\u043E\u043C \u043A\u043E\u0434\u0435 \u2014 \u043E\u043D \u0441\u0430\u043C \u043D\u0430 \u043D\u0435\u0433\u043E \u043D\u0435 \u043F\u0435\u0440\u0435\u0435\u0434\u0435\u0442", command: "swarm stop && swarm start" },
7052
7173
  { what: "\u043F\u0440\u043E\u0432\u0435\u0440\u0438\u0442\u044C \u043E\u043A\u0440\u0443\u0436\u0435\u043D\u0438\u0435 \u0438 \u0442\u043E\u043A\u0435\u043D \u043D\u0430\u043F\u0440\u044F\u043C\u0443\u044E, \u043F\u043E\u043A\u0430 \u0434\u0435\u043C\u043E\u043D \u0441\u0442\u0430\u0440\u044B\u0439", command: "swarm doctor" }
7053
7174
  ]
7054
7175
  };
7055
7176
  }
7056
- if (link.kind === "no-token") {
7177
+ if (link2.kind === "no-token") {
7057
7178
  return {
7058
7179
  id: "link-no-token",
7059
7180
  why: "\u0432\u0445\u043E\u0434 \u0432 Taskless \u043D\u0435 \u0432\u044B\u043F\u043E\u043B\u043D\u0435\u043D \u2014 \u0431\u0440\u0430\u0442\u044C \u0440\u0430\u0431\u043E\u0442\u0443 \u043D\u0435\u043E\u0442\u043A\u0443\u0434\u0430",
7060
7181
  fixes: [{ what: "\u0432\u043E\u0439\u0442\u0438 \u0432 \u0441\u0432\u043E\u0439 \u0432\u043E\u0440\u043A\u0441\u043F\u0435\u0439\u0441", command: "swarm login" }]
7061
7182
  };
7062
7183
  }
7063
- if (link.kind === "revoked") {
7184
+ if (link2.kind === "revoked") {
7064
7185
  return {
7065
7186
  id: "link-revoked",
7066
7187
  why: "Taskless \u041D\u0415 \u041F\u0420\u0418\u041D\u0418\u041C\u0410\u0415\u0422 \u0442\u043E\u043A\u0435\u043D \u0440\u043E\u044F (401 invalid_token): \u043E\u043D \u0441\u0431\u0440\u043E\u0448\u0435\u043D \u0432\u043B\u0430\u0434\u0435\u043B\u044C\u0446\u0435\u043C \u0438\u043B\u0438 \u0440\u043E\u0439 \u0432\u044B\u043A\u043B\u044E\u0447\u0435\u043D \u043C\u0430\u0441\u0442\u0435\u0440-\u0442\u0443\u043C\u0431\u043B\u0435\u0440\u043E\u043C",
7067
7188
  fixes: [{ what: "\u0432\u043E\u0439\u0442\u0438 \u0437\u0430\u043D\u043E\u0432\u043E \u2014 \u0442\u043E\u043A\u0435\u043D \u0432\u044B\u043F\u0438\u0448\u0435\u0442\u0441\u044F \u043D\u043E\u0432\u044B\u0439", command: "swarm login" }]
7068
7189
  };
7069
7190
  }
7070
- if (link.kind === "server") {
7191
+ if (link2.kind === "server") {
7071
7192
  return {
7072
7193
  id: "link-server",
7073
- why: `Taskless \u043E\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u043E\u0448\u0438\u0431\u043A\u043E\u0439 (${link.detail}) \u2014 \u044D\u0442\u043E \u043D\u0435 \u043C\u0430\u0448\u0438\u043D\u0430 \u0438 \u043D\u0435 \u0442\u043E\u043A\u0435\u043D`,
7194
+ why: `Taskless \u043E\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u043E\u0448\u0438\u0431\u043A\u043E\u0439 (${link2.detail}) \u2014 \u044D\u0442\u043E \u043D\u0435 \u043C\u0430\u0448\u0438\u043D\u0430 \u0438 \u043D\u0435 \u0442\u043E\u043A\u0435\u043D`,
7074
7195
  fixes: [
7075
- { what: "\u043F\u0440\u043E\u0432\u0435\u0440\u0438\u0442\u044C, \u0447\u0442\u043E \u043E\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0441\u0430\u043C \u043F\u0440\u043E\u0434 (\u043E\u0448\u0438\u0431\u043A\u0430 5xx \u2014 \u043D\u0430 \u0435\u0433\u043E \u0441\u0442\u043E\u0440\u043E\u043D\u0435)", command: `curl -sS -o /dev/null -w '%{http_code}\\n' ${link.api}/api/health` },
7196
+ { what: "\u043F\u0440\u043E\u0432\u0435\u0440\u0438\u0442\u044C, \u0447\u0442\u043E \u043E\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0441\u0430\u043C \u043F\u0440\u043E\u0434 (\u043E\u0448\u0438\u0431\u043A\u0430 5xx \u2014 \u043D\u0430 \u0435\u0433\u043E \u0441\u0442\u043E\u0440\u043E\u043D\u0435)", command: `curl -sS -o /dev/null -w '%{http_code}\\n' ${link2.api}/api/health` },
7076
7197
  { what: "\u0440\u0430\u0431\u043E\u0442\u0430 \u043F\u0440\u0438 \u044D\u0442\u043E\u043C \u043D\u0435 \u0442\u0435\u0440\u044F\u0435\u0442\u0441\u044F: \u0431\u0443\u0444\u0435\u0440 \u0434\u043E\u0436\u043C\u0451\u0442\u0441\u044F \u0441\u0430\u043C, \u043A\u043E\u0433\u0434\u0430 \u043F\u0440\u043E\u0434 \u0432\u0435\u0440\u043D\u0451\u0442\u0441\u044F", command: "swarm status # \u043F\u043E\u0432\u0442\u043E\u0440\u0438\u0442\u044C \u0447\u0435\u0440\u0435\u0437 \u043D\u0435\u0441\u043A\u043E\u043B\u044C\u043A\u043E \u043C\u0438\u043D\u0443\u0442" }
7077
7198
  ]
7078
7199
  };
7079
7200
  }
7080
- if (link.kind === "down") {
7201
+ if (link2.kind === "down") {
7081
7202
  return {
7082
7203
  id: "link-down",
7083
- why: `\u0441\u0432\u044F\u0437\u0438 \u0441 \u043F\u0440\u043E\u0434\u043E\u043C \u043D\u0435\u0442${link.detail ? `: ${link.detail}` : ""} \u2014 \u043F\u0440\u0438\u0447\u0438\u043D\u0443 \u043A\u043E\u043D\u043D\u0435\u043A\u0442\u043E\u0440 \u043D\u0435 \u043D\u0430\u0437\u0432\u0430\u043B, \u043E\u0442\u0441\u044E\u0434\u0430 \u0435\u0451 \u043D\u0435 \u043D\u0430\u0437\u0432\u0430\u0442\u044C \u0442\u043E\u0436\u0435`,
7204
+ why: `\u0441\u0432\u044F\u0437\u0438 \u0441 \u043F\u0440\u043E\u0434\u043E\u043C \u043D\u0435\u0442${link2.detail ? `: ${link2.detail}` : ""} \u2014 \u043F\u0440\u0438\u0447\u0438\u043D\u0443 \u043A\u043E\u043D\u043D\u0435\u043A\u0442\u043E\u0440 \u043D\u0435 \u043D\u0430\u0437\u0432\u0430\u043B, \u043E\u0442\u0441\u044E\u0434\u0430 \u0435\u0451 \u043D\u0435 \u043D\u0430\u0437\u0432\u0430\u0442\u044C \u0442\u043E\u0436\u0435`,
7084
7205
  fixes: [
7085
7206
  { what: "\u043F\u0440\u0438\u0447\u0438\u043D\u0443 \u043F\u0435\u0447\u0430\u0442\u0430\u0435\u0442 \u0441\u0430\u043C \u0434\u0435\u043C\u043E\u043D \u2014 \u0441\u043C\u043E\u0442\u0440\u0438 \u0435\u0433\u043E \u043B\u043E\u0433", command: "swarm logs | tail -50" },
7086
7207
  { what: "\u043F\u0440\u043E\u0432\u0435\u0440\u0438\u0442\u044C \u043C\u0430\u0448\u0438\u043D\u0443 \u0446\u0435\u043B\u0438\u043A\u043E\u043C (\u0441\u0435\u0442\u044C, \u0442\u043E\u043A\u0435\u043D, \u043E\u043A\u0440\u0443\u0436\u0435\u043D\u0438\u0435)", command: "swarm doctor" }
@@ -7089,11 +7210,11 @@ function linkTrouble(link) {
7089
7210
  }
7090
7211
  return {
7091
7212
  id: "link-network",
7092
- why: `\u0434\u043E Taskless \u043D\u0435 \u0434\u043E\u0441\u0442\u0443\u0447\u0430\u0442\u044C\u0441\u044F (${link.detail}) \u2014 \u0440\u043E\u0439 \u043D\u0435 \u0432\u0438\u0434\u0438\u0442 \u043D\u0438 \u0437\u0430\u0434\u0430\u0447, \u043D\u0438 \u043C\u0430\u0448\u0438\u043D`,
7213
+ why: `\u0434\u043E Taskless \u043D\u0435 \u0434\u043E\u0441\u0442\u0443\u0447\u0430\u0442\u044C\u0441\u044F (${link2.detail}) \u2014 \u0440\u043E\u0439 \u043D\u0435 \u0432\u0438\u0434\u0438\u0442 \u043D\u0438 \u0437\u0430\u0434\u0430\u0447, \u043D\u0438 \u043C\u0430\u0448\u0438\u043D`,
7093
7214
  fixes: [
7094
7215
  {
7095
7216
  what: "\u043F\u0440\u043E\u0432\u0435\u0440\u0438\u0442\u044C \u0441\u0435\u0442\u044C \u0422\u0415\u041C \u0416\u0415 \u0441\u043F\u043E\u0441\u043E\u0431\u043E\u043C, \u043A\u0430\u043A\u0438\u043C \u0445\u043E\u0434\u0438\u0442 \u0434\u0435\u043C\u043E\u043D (\u0432 WSL curl \u043C\u043E\u0436\u0435\u0442 \u0440\u0430\u0431\u043E\u0442\u0430\u0442\u044C, \u043A\u043E\u0433\u0434\u0430 fetch \u0438\u0437 Node \u2014 \u043D\u0435\u0442: \u0434\u0440\u0443\u0433\u043E\u0439 \u0440\u0435\u0437\u043E\u043B\u0432\u0435\u0440 \u0438 \u043F\u0440\u043E\u043A\u0441\u0438)",
7096
- command: `node -e "fetch('${link.api}/api/health').then(r=>console.log('HTTP',r.status)).catch(e=>console.log('\u041D\u0415 \u0425\u041E\u0414\u0418\u0422:',e.message))"`
7217
+ command: `node -e "fetch('${link2.api}/api/health').then(r=>console.log('HTTP',r.status)).catch(e=>console.log('\u041D\u0415 \u0425\u041E\u0414\u0418\u0422:',e.message))"`
7097
7218
  },
7098
7219
  { what: "\u0435\u0441\u043B\u0438 fetch \u043D\u0435 \u0445\u043E\u0434\u0438\u0442, \u0430 curl \u0445\u043E\u0434\u0438\u0442 \u2014 \u0441\u043C\u043E\u0442\u0440\u0438 HTTPS_PROXY/NO_PROXY \u0438 DNS \u0432 \u044D\u0442\u043E\u043C \u043E\u043A\u0440\u0443\u0436\u0435\u043D\u0438\u0438", command: "env | grep -i proxy; cat /etc/resolv.conf" }
7099
7220
  ]
@@ -7212,15 +7333,15 @@ function troubles(f) {
7212
7333
  if (linkWhenDead) out.push(linkWhenDead);
7213
7334
  return out;
7214
7335
  }
7215
- const link = linkTrouble(f.link);
7216
- if (link) out.push(link);
7336
+ const link2 = linkTrouble(f.link);
7337
+ if (link2) out.push(link2);
7217
7338
  if (f.daemon.pause?.paused) {
7218
7339
  out.push({ id: "paused", why: pauseText(f.daemon.pause, f.now), fixes: [{ what: "\u0432\u0435\u0440\u043D\u0443\u0442\u044C \u0440\u043E\u0439 \u0432 \u0440\u0430\u0431\u043E\u0442\u0443", command: "swarm resume" }] });
7219
7340
  }
7220
7341
  const up = staleMs(f.daemon.startedAt, f.now);
7221
7342
  const heard = staleMs(f.park.lastHeardAt, f.now);
7222
7343
  const neverHeard = (f.link.kind === "ok" || f.link.kind === "starting") && f.park.lastHeardAt == null && up != null && up > PARK_STALE_MS;
7223
- if (!link && (neverHeard || f.park.lastHeardAt && heard != null && heard > PARK_STALE_MS)) {
7344
+ if (!link2 && (neverHeard || f.park.lastHeardAt && heard != null && heard > PARK_STALE_MS)) {
7224
7345
  out.push({
7225
7346
  id: "park-stale",
7226
7347
  why: neverHeard ? `\u0434\u0435\u043C\u043E\u043D \u0440\u0430\u0431\u043E\u0442\u0430\u0435\u0442 ${uptimeText(f.daemon.startedAt, f.now)}, \u0430 \u043F\u0440\u043E\u0434 \u043D\u0435 \u0441\u043B\u044B\u0448\u0430\u043B \u044D\u0442\u0443 \u043C\u0430\u0448\u0438\u043D\u0443 \u041D\u0418 \u0420\u0410\u0417\u0423 \u2014 \u043F\u0443\u043B\u044C\u0441 \u043D\u0435 \u0434\u043E\u0435\u0437\u0436\u0430\u0435\u0442, \u0438 \u0440\u0430\u0431\u043E\u0442\u0443 \u0435\u0439 \u043D\u0435 \u0434\u0430\u044E\u0442` : `\u0434\u0435\u043C\u043E\u043D \u0436\u0438\u0432, \u0430 \u043F\u0440\u043E\u0434 \u043D\u0435 \u0441\u043B\u044B\u0448\u0430\u043B \u044D\u0442\u0443 \u043C\u0430\u0448\u0438\u043D\u0443 ${agoText(f.park.lastHeardAt, f.now)} \u2014 \u043F\u0443\u043B\u044C\u0441 \u043D\u0435 \u0434\u043E\u0435\u0437\u0436\u0430\u0435\u0442, \u0438 \u0432 \u043F\u0430\u0440\u043A\u0435 \u043C\u0430\u0448\u0438\u043D\u0430 \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044F \u043C\u043E\u043B\u0447\u0430\u0449\u0435\u0439`,
@@ -7233,7 +7354,7 @@ function troubles(f) {
7233
7354
  out.push(...blockedTroubles(f));
7234
7355
  const idle = idleTrouble(f);
7235
7356
  if (idle) out.push(idle);
7236
- else if (waitingForDrone(f.work) > 0 && f.work.busy === 0 && !link && out.length === 0) {
7357
+ else if (waitingForDrone(f.work) > 0 && f.work.busy === 0 && !link2 && out.length === 0) {
7237
7358
  out.push({
7238
7359
  id: "idle-unknown",
7239
7360
  why: `\u0436\u0434\u0443\u0442 \u0434\u0440\u043E\u043D\u0430 ${waitingForDrone(f.work)} \u0437\u0430\u0434\u0430\u0447(\u0438) (\u0432 \u043E\u0447\u0435\u0440\u0435\u0434\u0438 \u0432\u0441\u0435\u0433\u043E ${f.work.queued}), \u0434\u0440\u043E\u043D\u043E\u0432 \u0437\u0430\u043D\u044F\u0442\u043E 0, \u0430 \u0432\u0438\u0434\u0438\u043C\u043E\u0439 \u043F\u0440\u0438\u0447\u0438\u043D\u044B \u043D\u0435\u0442 \u2014 \u043E\u0442\u0441\u044E\u0434\u0430 \u0435\u0451 \u043D\u0435 \u043D\u0430\u0437\u0432\u0430\u0442\u044C. \u0427\u0430\u0441\u0442\u044C \u043E\u0447\u0435\u0440\u0435\u0434\u0438 \u043C\u043E\u0433\u043B\u0430 \u0431\u044B\u0442\u044C \u0437\u0430\u043A\u0440\u0435\u043F\u043B\u0435\u043D\u0430 \u0437\u0430 \u0434\u0440\u0443\u0433\u043E\u0439 \u043C\u0430\u0448\u0438\u043D\u043E\u0439`,
@@ -7347,11 +7468,11 @@ __export(statusCli_exports, {
7347
7468
  probeLink: () => probeLink,
7348
7469
  runStatusCli: () => runStatusCli
7349
7470
  });
7350
- import { existsSync as existsSync15, readFileSync as readFileSync18 } from "fs";
7471
+ import { existsSync as existsSync18, readFileSync as readFileSync20 } from "fs";
7351
7472
  function outboxPending(path) {
7352
7473
  try {
7353
- if (!existsSync15(path)) return 0;
7354
- return readFileSync18(path, "utf8").split("\n").filter((l) => l.trim()).length;
7474
+ if (!existsSync18(path)) return 0;
7475
+ return readFileSync20(path, "utf8").split("\n").filter((l) => l.trim()).length;
7355
7476
  } catch {
7356
7477
  return null;
7357
7478
  }
@@ -7365,7 +7486,7 @@ async function probeLink() {
7365
7486
  if (probe === "revoked") return { kind: "revoked", detail: "401 invalid_token", ...base3 };
7366
7487
  return { kind: "network", detail: "\u043F\u0440\u043E\u0434 \u043D\u0435 \u043E\u0442\u0432\u0435\u0442\u0438\u043B (\u0441\u0435\u0442\u044C \u0438\u043B\u0438 \u0441\u0430\u043C \u043F\u0440\u043E\u0434)", ...base3 };
7367
7488
  }
7368
- function factsFromDaemon(st, link, now) {
7489
+ function factsFromDaemon(st, link2, now) {
7369
7490
  const counts = st.counts ?? {};
7370
7491
  return {
7371
7492
  daemon: {
@@ -7378,7 +7499,7 @@ function factsFromDaemon(st, link, now) {
7378
7499
  pause: st.pause ?? (st.paused ? { paused: true, at: "", source: "web" } : null),
7379
7500
  restartWaiting: st.restart?.phase === "waiting"
7380
7501
  },
7381
- link,
7502
+ link: link2,
7382
7503
  park: { lastHeardAt: st.link?.heardAt ?? null },
7383
7504
  work: {
7384
7505
  busy: st.live?.length ?? 0,
@@ -7420,7 +7541,7 @@ function daemonProcessAlive(now) {
7420
7541
  return beat != null && now - beat < HEARTBEAT_FRESH_MS;
7421
7542
  }
7422
7543
  async function factsWithoutDaemon(now) {
7423
- const link = await probeLink();
7544
+ const link2 = await probeLink();
7424
7545
  return {
7425
7546
  daemon: {
7426
7547
  alive: false,
@@ -7436,7 +7557,7 @@ async function factsWithoutDaemon(now) {
7436
7557
  pause: loadPauseState(SWARM_HOME),
7437
7558
  restartWaiting: false
7438
7559
  },
7439
- link,
7560
+ link: link2,
7440
7561
  // Пульса нет по построению: пульсит демон, а его нет. Не выдаём это за «прод молчит».
7441
7562
  park: { lastHeardAt: null },
7442
7563
  work: { busy: 0, queued: 0, queuedReady: null, questions: 0, other: {}, maxDrones: null, storm: null },
@@ -7558,23 +7679,23 @@ var init_prodMergeGate = __esm({
7558
7679
  });
7559
7680
 
7560
7681
  // src/platform.ts
7561
- import { accessSync, constants, existsSync as existsSync16, readFileSync as readFileSync19, realpathSync as realpathSync3 } from "fs";
7562
- import { delimiter, join as join24, posix as posix2, win32 } from "path";
7682
+ import { accessSync, constants, existsSync as existsSync19, readFileSync as readFileSync21, realpathSync as realpathSync3 } from "fs";
7683
+ import { delimiter, join as join28, posix as posix2, win32 } from "path";
7563
7684
  function safeReadText(path) {
7564
7685
  try {
7565
- return readFileSync19(path, "utf8");
7686
+ return readFileSync21(path, "utf8");
7566
7687
  } catch {
7567
7688
  return null;
7568
7689
  }
7569
7690
  }
7570
7691
  function resolveCommandPath(name, env = process.env, platform = process.platform) {
7571
- if (name.includes("/") || name.includes("\\")) return existsSync16(name) ? name : null;
7692
+ if (name.includes("/") || name.includes("\\")) return existsSync19(name) ? name : null;
7572
7693
  const dirs = (env.PATH ?? env.Path ?? "").split(delimiter).filter(Boolean);
7573
7694
  const exts = platform === "win32" ? (env.PATHEXT ?? ".EXE;.CMD;.BAT").split(";").filter(Boolean) : [""];
7574
7695
  for (const dir of dirs) {
7575
7696
  for (const ext of exts) {
7576
- const candidate = join24(dir, name + ext);
7577
- if (existsSync16(candidate)) return candidate;
7697
+ const candidate = join28(dir, name + ext);
7698
+ if (existsSync19(candidate)) return candidate;
7578
7699
  }
7579
7700
  }
7580
7701
  return null;
@@ -7764,18 +7885,18 @@ var init_platform = __esm({
7764
7885
  });
7765
7886
 
7766
7887
  // src/envGate.ts
7767
- import { existsSync as existsSync17 } from "fs";
7768
- import { join as join25 } from "path";
7888
+ import { existsSync as existsSync20 } from "fs";
7889
+ import { join as join29 } from "path";
7769
7890
  import { createConnection } from "net";
7770
- import { execa as execa3 } from "execa";
7891
+ import { execa as execa4 } from "execa";
7771
7892
  function detectRequirements(repo, io = {}) {
7772
- const exists = io.exists ?? existsSync17;
7773
- const marker = COMPOSE_MARKERS.find((f) => exists(join25(repo, f)));
7893
+ const exists = io.exists ?? existsSync20;
7894
+ const marker = COMPOSE_MARKERS.find((f) => exists(join29(repo, f)));
7774
7895
  return marker ? [{ kind: "docker", raw: `docker (\u0434\u0435\u0442\u0435\u043A\u0442: ${marker})` }] : [];
7775
7896
  }
7776
7897
  async function probeDockerDaemon() {
7777
7898
  try {
7778
- const res = await execa3("docker", ["version", "--format", "{{.Server.Version}}"], {
7899
+ const res = await execa4("docker", ["version", "--format", "{{.Server.Version}}"], {
7779
7900
  timeout: PROBE_TIMEOUT_MS2,
7780
7901
  reject: false
7781
7902
  });
@@ -7806,7 +7927,7 @@ var init_envGate = __esm({
7806
7927
  });
7807
7928
 
7808
7929
  // src/doctor.ts
7809
- import { isAbsolute as isAbsolute5, join as join26 } from "path";
7930
+ import { isAbsolute as isAbsolute5, join as join30 } from "path";
7810
7931
  function ok(id, title, detail) {
7811
7932
  return { id, title, status: "ok", detail, remedies: [], critical: false };
7812
7933
  }
@@ -8015,7 +8136,7 @@ function checkRepos(io, snap) {
8015
8136
  critical: true
8016
8137
  };
8017
8138
  }
8018
- if (env && !io.exists(join26(env, ".git"))) {
8139
+ if (env && !io.exists(join30(env, ".git"))) {
8019
8140
  return {
8020
8141
  id: "repos",
8021
8142
  title,
@@ -8025,7 +8146,7 @@ function checkRepos(io, snap) {
8025
8146
  critical: true
8026
8147
  };
8027
8148
  }
8028
- const broken = snap.paths.filter((p) => !io.exists(join26(p, ".git")));
8149
+ const broken = snap.paths.filter((p) => !io.exists(join30(p, ".git")));
8029
8150
  if (broken.length) {
8030
8151
  return {
8031
8152
  id: "repos",
@@ -8215,12 +8336,12 @@ var init_doctor = __esm({
8215
8336
  });
8216
8337
 
8217
8338
  // src/repoMemory.ts
8218
- import { readFileSync as readFileSync20, writeFileSync as writeFileSync15 } from "fs";
8219
- import { join as join27 } from "path";
8339
+ import { readFileSync as readFileSync22, writeFileSync as writeFileSync15 } from "fs";
8340
+ import { join as join31 } from "path";
8220
8341
  function loadRememberedRepos(home) {
8221
8342
  let raw;
8222
8343
  try {
8223
- raw = readFileSync20(join27(home, FILE), "utf8");
8344
+ raw = readFileSync22(join31(home, FILE), "utf8");
8224
8345
  } catch {
8225
8346
  return [];
8226
8347
  }
@@ -8256,7 +8377,7 @@ __export(installCli_exports, {
8256
8377
  runInstallHookCli: () => runInstallHookCli,
8257
8378
  shortenError: () => shortenError
8258
8379
  });
8259
- import { existsSync as existsSync18 } from "fs";
8380
+ import { existsSync as existsSync21 } from "fs";
8260
8381
  function classifyChromiumError(message) {
8261
8382
  if (/playwright-core не установлен|Cannot find (module|package)/i.test(message)) return "no-module";
8262
8383
  if (/error while loading shared libraries|cannot open shared object file|missing dependencies|\blib[\w.+-]*\.so[.\d]*\b/i.test(message)) return "no-libs";
@@ -8311,7 +8432,7 @@ function defaultDoctorIO(packageVersion) {
8311
8432
  packageVersion,
8312
8433
  entry,
8313
8434
  hasCommand: (name) => hasCommandInPath(name),
8314
- exists: existsSync18,
8435
+ exists: existsSync21,
8315
8436
  run: (command) => runQuiet(command),
8316
8437
  latestVersion: () => latestMemo ??= fetchLatestVersion(),
8317
8438
  probeChromium: () => probeChromium(),
@@ -8551,8 +8672,8 @@ var init_updateCli = __esm({
8551
8672
 
8552
8673
  // src/cli.ts
8553
8674
  init_cliIo();
8554
- import { basename as basename7, dirname as dirname5, join as join28 } from "path";
8555
- 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";
8675
+ import { basename as basename7, dirname as dirname6, join as join32 } from "path";
8676
+ import { existsSync as existsSync22, readFileSync as readFileSync23, writeFileSync as writeFileSync16, mkdirSync as mkdirSync13, readdirSync as readdirSync14, statSync as statSync14, openSync as openSync6, readSync as readSync2, closeSync as closeSync6 } from "fs";
8556
8677
  import { setTimeout as sleep2 } from "timers/promises";
8557
8678
 
8558
8679
  // src/swarmClient.ts
@@ -8590,6 +8711,7 @@ function parsePendingRepoRules(raw) {
8590
8711
  // src/swarmClient.ts
8591
8712
  init_slugRetry();
8592
8713
  init_zoneNotes();
8714
+ init_authorRun();
8593
8715
 
8594
8716
  // src/zones.ts
8595
8717
  init_src();
@@ -9207,7 +9329,8 @@ var SwarmClient = class _SwarmClient {
9207
9329
  // воркспейсов, которых демон раньше не мог обслужить.
9208
9330
  workspace_id: input.workspace_id ?? null,
9209
9331
  created_at: now,
9210
- updated_at: now
9332
+ updated_at: now,
9333
+ started_at: null
9211
9334
  };
9212
9335
  this.runs.set(id, d);
9213
9336
  this.keyByLocal.set(id, d.runKey);
@@ -9306,6 +9429,8 @@ var SwarmClient = class _SwarmClient {
9306
9429
  const d = this.runs.get(id);
9307
9430
  if (!d) return null;
9308
9431
  if (Object.keys(patch).length === 0) return this.mat(d);
9432
+ const prevStatus = d.status;
9433
+ const prevPid = this.runtime.get(id)?.pid ?? null;
9309
9434
  if ("pid" in patch || "worktree_path" in patch) {
9310
9435
  const rt = this.runtime.get(id) ?? { pid: null, worktree_path: null };
9311
9436
  if ("pid" in patch) rt.pid = patch.pid ?? null;
@@ -9317,6 +9442,7 @@ var SwarmClient = class _SwarmClient {
9317
9442
  d[k] = v;
9318
9443
  }
9319
9444
  d.updated_at = stamp();
9445
+ if (sessionStartMoved({ status: prevStatus, pid: prevPid }, patch)) d.started_at = stamp();
9320
9446
  this.enqueueRun(d, this.runFields(patch, this.mat(d)));
9321
9447
  return this.mat(d);
9322
9448
  }
@@ -9392,7 +9518,7 @@ var SwarmClient = class _SwarmClient {
9392
9518
  return [...this.runs.values()].filter((r) => r.verifies_run_id === verifyRunId && !TERMINAL_STATUSES.includes(r.status)).sort((a, b) => b.id - a.id).map((d) => this.mat(d));
9393
9519
  }
9394
9520
  activeRunForSlug(slug) {
9395
- const cands = [...this.runs.values()].filter((r) => r.task_slug === slug && !SLUG_TERMINAL.has(r.status)).sort((a, b) => b.id - a.id);
9521
+ const cands = [...this.runs.values()].filter((r) => r.task_slug === slug && !SLUG_TERMINAL.has(r.status) && isSlugAuthorRun(r)).sort((a, b) => b.id - a.id);
9396
9522
  return cands.length ? this.mat(cands[0]) : null;
9397
9523
  }
9398
9524
  runningAreas(repo, exceptGroup) {
@@ -9520,6 +9646,9 @@ var SwarmClient = class _SwarmClient {
9520
9646
  });
9521
9647
  if (!ask.length) return;
9522
9648
  for (const ref of ask) this.depsAskedAt.set(ref, nowMs);
9649
+ if (opts.force) {
9650
+ for (const ref of ask) if (this.depsProd.get(ref)?.releasedByTaskClose) this.depsProd.delete(ref);
9651
+ }
9523
9652
  let res;
9524
9653
  try {
9525
9654
  res = await this.call("swarm_deps_status", { refs: ask });
@@ -9539,13 +9668,15 @@ var SwarmClient = class _SwarmClient {
9539
9668
  if (!ref) continue;
9540
9669
  this.depsUnanswered.delete(ref);
9541
9670
  const outcome = String(d.outcome ?? "pending");
9542
- this.depsProd.set(ref, {
9671
+ const verdict = {
9543
9672
  outcome,
9544
9673
  met: Boolean(d.met),
9545
9674
  status: d.status ?? null,
9546
9675
  name: d.name ?? null,
9547
9676
  stopReason: d.stopReason ?? null
9548
- });
9677
+ };
9678
+ if (d.releasedByTaskClose === true) verdict.releasedByTaskClose = true;
9679
+ this.depsProd.set(ref, verdict);
9549
9680
  if (typeof d.slug === "string" && d.slug) this.depSlug.set(ref, d.slug);
9550
9681
  }
9551
9682
  }
@@ -10994,7 +11125,8 @@ var SwarmClient = class _SwarmClient {
10994
11125
  // дефолт 0; существующая локальная запись НЕ перетирается (поле не в field-copy ниже).
10995
11126
  priority: 0,
10996
11127
  created_at: stamp(),
10997
- updated_at: stamp()
11128
+ updated_at: stamp(),
11129
+ started_at: null
10998
11130
  };
10999
11131
  this.runs.set(id, local);
11000
11132
  this.keyByLocal.set(id, runKey);
@@ -11032,6 +11164,7 @@ var SwarmClient = class _SwarmClient {
11032
11164
  local.parallel_group = pr.parallelGroup ?? null;
11033
11165
  local.workspace_id = pr.workspaceId ?? local.workspace_id ?? null;
11034
11166
  local.status = pr.status ?? local.status;
11167
+ if (typeof pr.startedAt === "string" && pr.startedAt) local.started_at = pr.startedAt;
11035
11168
  local.area = normalizeZoneLabel(pr.area) || null;
11036
11169
  local.depends_on = Array.isArray(pr.dependsOn) ? pr.dependsOn : [];
11037
11170
  local.model = pr.model ?? null;
@@ -11365,12 +11498,24 @@ var SwarmClient = class _SwarmClient {
11365
11498
  }
11366
11499
  };
11367
11500
  function parseDecision(v) {
11368
- if (!v || typeof v !== "string") return null;
11501
+ if (typeof v !== "string" || !v.trim()) return null;
11369
11502
  try {
11370
- return JSON.parse(v);
11503
+ const parsed = JSON.parse(v);
11504
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
11505
+ const row = parsed;
11506
+ if (typeof row.chosen === "string") {
11507
+ return {
11508
+ question: typeof row.question === "string" ? row.question : "",
11509
+ options: Array.isArray(row.options) ? row.options.filter((option) => typeof option === "string") : null,
11510
+ chosen: row.chosen,
11511
+ prior: typeof row.prior === "string" ? row.prior : null,
11512
+ priorState: typeof row.priorState === "string" ? row.priorState : ""
11513
+ };
11514
+ }
11515
+ }
11371
11516
  } catch {
11372
- return null;
11373
11517
  }
11518
+ return { question: "", options: null, chosen: v, prior: null, priorState: "" };
11374
11519
  }
11375
11520
 
11376
11521
  // src/cli.ts
@@ -11548,7 +11693,7 @@ function hostIdentityPath(home) {
11548
11693
  function loadHostIdentity(deps) {
11549
11694
  const exists = deps.exists ?? existsSync10;
11550
11695
  const readFile3 = deps.readFile ?? ((p) => readFileSync10(p, "utf8"));
11551
- const writeFile3 = deps.writeFile ?? ((p, data) => {
11696
+ const writeFile4 = deps.writeFile ?? ((p, data) => {
11552
11697
  writeFileSync8(`${p}.tmp`, data);
11553
11698
  renameSync4(`${p}.tmp`, p);
11554
11699
  });
@@ -11568,7 +11713,7 @@ function loadHostIdentity(deps) {
11568
11713
  }
11569
11714
  const hostId = newId();
11570
11715
  try {
11571
- writeFile3(path, JSON.stringify({ hostId, hostName, createdAt: (/* @__PURE__ */ new Date()).toISOString() }, null, 2));
11716
+ writeFile4(path, JSON.stringify({ hostId, hostName, createdAt: (/* @__PURE__ */ new Date()).toISOString() }, null, 2));
11572
11717
  } catch {
11573
11718
  console.warn(`[overmind] \u043D\u0435 \u0441\u043C\u043E\u0433 \u0437\u0430\u043F\u0438\u0441\u0430\u0442\u044C ${path} \u2014 hostId \u0436\u0438\u0432\u0451\u0442 \u0442\u043E\u043B\u044C\u043A\u043E \u0434\u043E \u0440\u0435\u0441\u0442\u0430\u0440\u0442\u0430 \u043F\u0440\u043E\u0446\u0435\u0441\u0441\u0430`);
11574
11719
  }
@@ -11858,7 +12003,7 @@ init_resources();
11858
12003
  // src/gh.ts
11859
12004
  init_src();
11860
12005
  init_netTimeout();
11861
- import { $ as $4 } from "execa";
12006
+ import { $ as $5 } from "execa";
11862
12007
  import { basename as basename3 } from "path";
11863
12008
 
11864
12009
  // src/ghBudget.ts
@@ -11947,6 +12092,7 @@ var GH_MERGED_LOOKBACK_MS = 30 * 24 * 60 * 60 * 1e3;
11947
12092
 
11948
12093
  // src/reviewCycle.ts
11949
12094
  init_src();
12095
+ init_orchestrator();
11950
12096
  var REVIEW_CYCLE_LIMIT_DEFAULT = 3;
11951
12097
  var REVIEW_CYCLE_LIMIT_CAP = 20;
11952
12098
  function validReviewCycleLimit(n) {
@@ -11977,7 +12123,7 @@ async function runGh(args, timeoutMs, cwd) {
11977
12123
  const label2 = callLabel("gh", args) + (cwd ? ` (repo ${basename3(cwd)})` : "");
11978
12124
  const skipsPause = ghCallSkipsPause(args);
11979
12125
  if (!skipsPause && ghCallsPaused(Date.now())) throw new GhPausedError();
11980
- const child = cwd ? $4({ cwd, timeout: timeoutMs })`gh ${args}` : $4({ timeout: timeoutMs })`gh ${args}`;
12126
+ const child = cwd ? $5({ cwd, timeout: timeoutMs })`gh ${args}` : $5({ timeout: timeoutMs })`gh ${args}`;
11981
12127
  try {
11982
12128
  return (await withHardTimeout(child, "gh", label2, timeoutMs)).stdout;
11983
12129
  } catch (e) {
@@ -12190,7 +12336,7 @@ var GhCallFailedError = class extends Error {
12190
12336
  };
12191
12337
  var realChecksRunner = async (pr) => {
12192
12338
  const label2 = callLabel("gh", ["pr", "checks", pr]);
12193
- const r = await withHardTimeout($4({ reject: false, timeout: 15e3 })`gh pr checks ${pr} --json state,name,bucket,link`, "gh", label2, 15e3);
12339
+ const r = await withHardTimeout($5({ reject: false, timeout: 15e3 })`gh pr checks ${pr} --json state,name,bucket,link`, "gh", label2, 15e3);
12194
12340
  const stdout = r.stdout ?? "";
12195
12341
  const stderr = r.stderr ?? "";
12196
12342
  if (isTimedOut(r)) throw new GhCallFailedError(label2, classifyCallFailure(r));
@@ -14211,16 +14357,16 @@ import { cancelRun, respawnRun, runDaemon, wakeRun, OVERMIND_ENTRY, listDronePro
14211
14357
 
14212
14358
  // src/launcher.ts
14213
14359
  init_procCleanup();
14214
- import { spawn as spawn2 } from "child_process";
14215
- import { closeSync as closeSync4, existsSync as existsSync11, mkdirSync as mkdirSync11, openSync as openSync4, readdirSync as readdirSync10 } from "fs";
14360
+ import { spawn as spawn3 } from "child_process";
14361
+ import { closeSync as closeSync5, existsSync as existsSync15, mkdirSync as mkdirSync12, openSync as openSync5, readdirSync as readdirSync12 } from "fs";
14216
14362
  import { createRequire } from "module";
14217
14363
  import { homedir as homedir6 } from "os";
14218
- import { basename as basename5, dirname as dirname4, join as join16 } from "path";
14364
+ import { basename as basename5, dirname as dirname5, join as join21 } from "path";
14219
14365
  import { fileURLToPath as fileURLToPath2 } from "url";
14220
14366
 
14221
14367
  // src/droneHome.ts
14222
- import { lstatSync, mkdirSync as mkdirSync10, readdirSync as readdirSync9, rmSync, statSync as statSync10, symlinkSync as symlinkSync4 } from "fs";
14223
- import { join as join15, relative, sep as sep2 } from "path";
14368
+ import { lstatSync, mkdirSync as mkdirSync11, readdirSync as readdirSync11, rmSync as rmSync3, statSync as statSync12, symlinkSync as symlinkSync4 } from "fs";
14369
+ import { join as join20, relative, sep as sep3 } from "path";
14224
14370
  var DRONE_HOME_DENY_DEFAULT = [".taskless-swarm", ".bash_history", ".zsh_history"];
14225
14371
  function droneHomeDeny(env = process.env) {
14226
14372
  const extra = (env.SWARM_DRONE_HOME_DENY || "").split(",").map((s) => s.trim()).filter(Boolean);
@@ -14238,34 +14384,34 @@ function buildDroneHome(opts) {
14238
14384
  const { realHome, droneHome } = opts;
14239
14385
  const deny = opts.deny ?? droneHomeDeny();
14240
14386
  const platform = opts.platform ?? process.platform;
14241
- mkdirSync10(droneHome, { recursive: true, mode: 448 });
14242
- const wanted = new Set(mirroredEntries(readdirSync9(realHome), deny, platform));
14387
+ mkdirSync11(droneHome, { recursive: true, mode: 448 });
14388
+ const wanted = new Set(mirroredEntries(readdirSync11(realHome), deny, platform));
14243
14389
  const rel = relative(realHome, droneHome);
14244
- if (rel && !rel.startsWith("..") && !rel.includes(sep2)) wanted.delete(rel);
14245
- for (const existing of readdirSync9(droneHome)) {
14390
+ if (rel && !rel.startsWith("..") && !rel.includes(sep3)) wanted.delete(rel);
14391
+ for (const existing of readdirSync11(droneHome)) {
14246
14392
  if (wanted.has(existing)) continue;
14247
- const p = join15(droneHome, existing);
14393
+ const p = join20(droneHome, existing);
14248
14394
  try {
14249
- if (lstatSync(p).isSymbolicLink()) rmSync(p);
14395
+ if (lstatSync(p).isSymbolicLink()) rmSync3(p);
14250
14396
  } catch {
14251
14397
  }
14252
14398
  }
14253
14399
  for (const name of wanted) {
14254
- const link = join15(droneHome, name);
14400
+ const link2 = join20(droneHome, name);
14255
14401
  try {
14256
- lstatSync(link);
14402
+ lstatSync(link2);
14257
14403
  continue;
14258
14404
  } catch {
14259
14405
  }
14260
- const target = join15(realHome, name);
14406
+ const target = join20(realHome, name);
14261
14407
  let isDir;
14262
14408
  try {
14263
- isDir = statSync10(target).isDirectory();
14409
+ isDir = statSync12(target).isDirectory();
14264
14410
  } catch {
14265
14411
  continue;
14266
14412
  }
14267
14413
  try {
14268
- symlinkSync4(target, link, isDir ? "junction" : "file");
14414
+ symlinkSync4(target, link2, isDir ? "junction" : "file");
14269
14415
  } catch (e) {
14270
14416
  if (e.code !== "EEXIST") throw e;
14271
14417
  }
@@ -14278,7 +14424,7 @@ var REAL_PATH_ENV_PINS = [
14278
14424
  { env: "YARN_GLOBAL_FOLDER", segments: [".yarn", "berry"] }
14279
14425
  ];
14280
14426
  function realPathEnvPins(realHome) {
14281
- return Object.fromEntries(REAL_PATH_ENV_PINS.map(({ env, segments }) => [env, join15(realHome, ...segments)]));
14427
+ return Object.fromEntries(REAL_PATH_ENV_PINS.map(({ env, segments }) => [env, join20(realHome, ...segments)]));
14282
14428
  }
14283
14429
  function dronePrivatePaths(realHome, swarmHome) {
14284
14430
  return [
@@ -14376,7 +14522,7 @@ function droneEnv(worktree, base3 = process.env, isolation, droneCap = null) {
14376
14522
  const env = { ...base3, TASKLESS_SWARM_DRONE: "1" };
14377
14523
  const isolate = base3.SWARM_TURBO_ISOLATE !== "0";
14378
14524
  if (isolate && !base3.TURBO_CACHE_DIR) {
14379
- env.TURBO_CACHE_DIR = join16(worktree, ".turbo", "cache");
14525
+ env.TURBO_CACHE_DIR = join21(worktree, ".turbo", "cache");
14380
14526
  }
14381
14527
  if (!base3.COMPOSE_PROJECT_NAME) {
14382
14528
  const prefix = composeProjectPrefix(basename5(worktree));
@@ -14411,21 +14557,21 @@ var DAEMON_STATE_ENV = [
14411
14557
  ...PROVIDER_TOKEN_ENV
14412
14558
  ];
14413
14559
  function bundledRoleDir(kind) {
14414
- return join16(dirname4(fileURLToPath2(import.meta.url)), "..", "roles", kind);
14560
+ return join21(dirname5(fileURLToPath2(import.meta.url)), "..", "roles", kind);
14415
14561
  }
14416
14562
  function roleDir(worktree, kind) {
14417
- return join16(worktree, ".claude", "roles", kind);
14563
+ return join21(worktree, ".claude", "roles", kind);
14418
14564
  }
14419
14565
  function roleDirs(worktree, kind) {
14420
- return [bundledRoleDir(kind), roleDir(worktree, kind)].filter((dir) => existsSync11(dir));
14566
+ return [bundledRoleDir(kind), roleDir(worktree, kind)].filter((dir) => existsSync15(dir));
14421
14567
  }
14422
14568
  function nextRunLogPath(runLogsDir, runLogKeys) {
14423
14569
  const dir = runLogDirForWrite(runLogsDir, runLogKeys);
14424
14570
  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)");
14425
- mkdirSync11(dir, { recursive: true });
14571
+ mkdirSync12(dir, { recursive: true });
14426
14572
  let files = [];
14427
14573
  try {
14428
- files = readdirSync10(dir);
14574
+ files = readdirSync12(dir);
14429
14575
  } catch {
14430
14576
  }
14431
14577
  let next = 0;
@@ -14433,21 +14579,21 @@ function nextRunLogPath(runLogsDir, runLogKeys) {
14433
14579
  const m = /^(\d+)\.json/.exec(f);
14434
14580
  if (m) next = Math.max(next, Number(m[1]) + 1);
14435
14581
  }
14436
- return join16(dir, `${next}.json`);
14582
+ return join21(dir, `${next}.json`);
14437
14583
  }
14438
14584
  function openNextRunLog(runLogsDir, runLogKeys) {
14439
14585
  for (let attempt = 0; attempt < 50; attempt++) {
14440
14586
  const path = nextRunLogPath(runLogsDir, runLogKeys);
14441
14587
  let out;
14442
14588
  try {
14443
- out = openSync4(path, "wx");
14589
+ out = openSync5(path, "wx");
14444
14590
  } catch (e) {
14445
14591
  if (e.code !== "EEXIST") throw e;
14446
14592
  continue;
14447
14593
  }
14448
14594
  let err = null;
14449
14595
  try {
14450
- err = openSync4(`${path.slice(0, -".json".length)}.err.log`, "w");
14596
+ err = openSync5(`${path.slice(0, -".json".length)}.err.log`, "w");
14451
14597
  } catch {
14452
14598
  err = null;
14453
14599
  }
@@ -14525,9 +14671,9 @@ function makeLauncher(cfg) {
14525
14671
  }
14526
14672
  const realHome = cfg.droneIsolation?.realHome ?? homedir6();
14527
14673
  const home = cfg.droneIsolation ? buildDroneHome({ realHome, droneHome: cfg.droneIsolation.home }) : void 0;
14528
- if (cfg.droneIsolation && process.env.TASKLESS_TOKEN && !existsSync11(join16(cfg.droneIsolation.swarmHome, "token"))) {
14674
+ if (cfg.droneIsolation && process.env.TASKLESS_TOKEN && !existsSync15(join21(cfg.droneIsolation.swarmHome, "token"))) {
14529
14675
  console.error(
14530
- `[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.`
14676
+ `[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 ${join21(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.`
14531
14677
  );
14532
14678
  }
14533
14679
  const executor = cfg.executor ?? executorForRun(run, cfg.swarmModels?.() ?? null);
@@ -14566,7 +14712,7 @@ function makeLauncher(cfg) {
14566
14712
  errFd = fds.err ?? void 0;
14567
14713
  stdio = ["ignore", outFd, errFd ?? "ignore"];
14568
14714
  }
14569
- const child = spawn2(cfg.bin ?? plan.bin, plan.args, {
14715
+ const child = spawn3(cfg.bin ?? plan.bin, plan.args, {
14570
14716
  cwd: worktree,
14571
14717
  detached: true,
14572
14718
  stdio,
@@ -14577,8 +14723,8 @@ function makeLauncher(cfg) {
14577
14723
  // они про его собственное состояние, и перебивать их ройным нечем.
14578
14724
  env: { ...droneEnv(worktree, process.env, home ? { droneHome: home, realHome } : void 0, cfg.droneCap?.() ?? null), ...plan.env }
14579
14725
  });
14580
- if (outFd !== void 0) closeSync4(outFd);
14581
- if (errFd !== void 0) closeSync4(errFd);
14726
+ if (outFd !== void 0) closeSync5(outFd);
14727
+ if (errFd !== void 0) closeSync5(errFd);
14582
14728
  child.unref();
14583
14729
  if (child.pid == null) throw new Error("\u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0437\u0430\u043F\u0443\u0441\u0442\u0438\u0442\u044C \u0434\u0440\u043E\u043D\u0430 (\u043D\u0435\u0442 pid)");
14584
14730
  return child.pid;
@@ -14920,11 +15066,11 @@ init_names2();
14920
15066
  init_executors();
14921
15067
  init_claudeCode();
14922
15068
  init_workspace();
14923
- import { spawn as spawn3 } from "child_process";
15069
+ import { spawn as spawn4 } from "child_process";
14924
15070
 
14925
15071
  // src/login.ts
14926
15072
  init_taskless();
14927
- import { execa as execa2 } from "execa";
15073
+ import { execa as execa3 } from "execa";
14928
15074
  import { createServer } from "net";
14929
15075
  async function waitForLogin(d) {
14930
15076
  const deadline = d.now() + d.timeoutMs;
@@ -15037,7 +15183,7 @@ function parseWhoAmI(res) {
15037
15183
  async function openBrowser(url) {
15038
15184
  const [cmd2, args] = process.platform === "darwin" ? ["open", [url]] : process.platform === "win32" ? ["cmd", ["/c", "start", "", url]] : ["xdg-open", [url]];
15039
15185
  try {
15040
- await execa2(cmd2, args, { stdio: "ignore" });
15186
+ await execa3(cmd2, args, { stdio: "ignore" });
15041
15187
  return true;
15042
15188
  } catch {
15043
15189
  return false;
@@ -15458,7 +15604,7 @@ async function runDaemonLogs(argv) {
15458
15604
  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.`);
15459
15605
  return 1;
15460
15606
  }
15461
- if (!existsSync19(DAEMON_LOG_PATH)) {
15607
+ if (!existsSync22(DAEMON_LOG_PATH)) {
15462
15608
  console.error(`\u043B\u043E\u0433\u0430 \u0434\u0435\u043C\u043E\u043D\u0430 \u043D\u0435\u0442: ${DAEMON_LOG_PATH}`);
15463
15609
  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.");
15464
15610
  return 1;
@@ -15466,25 +15612,25 @@ async function runDaemonLogs(argv) {
15466
15612
  const head = tailFile(DAEMON_LOG_PATH, lines);
15467
15613
  if (head) console.log(head);
15468
15614
  if (!follow) return 0;
15469
- let pos = statSync13(DAEMON_LOG_PATH).size;
15615
+ let pos = statSync14(DAEMON_LOG_PATH).size;
15470
15616
  for (; ; ) {
15471
15617
  await sleep2(500);
15472
15618
  let size;
15473
15619
  try {
15474
- size = statSync13(DAEMON_LOG_PATH).size;
15620
+ size = statSync14(DAEMON_LOG_PATH).size;
15475
15621
  } catch {
15476
15622
  continue;
15477
15623
  }
15478
15624
  if (size < pos) pos = 0;
15479
15625
  if (size === pos) continue;
15480
- const fd = openSync5(DAEMON_LOG_PATH, "r");
15626
+ const fd = openSync6(DAEMON_LOG_PATH, "r");
15481
15627
  try {
15482
15628
  const buf = Buffer.alloc(size - pos);
15483
15629
  const read = readSync2(fd, buf, 0, buf.length, pos);
15484
15630
  process.stdout.write(buf.subarray(0, read).toString("utf8"));
15485
15631
  pos += read;
15486
15632
  } finally {
15487
- closeSync5(fd);
15633
+ closeSync6(fd);
15488
15634
  }
15489
15635
  }
15490
15636
  }
@@ -15740,10 +15886,10 @@ function effectiveWorktreesDir() {
15740
15886
  legacyDir: WORKTREES_LEGACY_DIR,
15741
15887
  targetDir: WORKTREES_DIR,
15742
15888
  envOverride: process.env.SWARM_WORKTREES || "",
15743
- exists: (d) => existsSync19(d),
15889
+ exists: (d) => existsSync22(d),
15744
15890
  isNonEmptyDir: (d) => {
15745
15891
  try {
15746
- return readdirSync13(d).length > 0;
15892
+ return readdirSync14(d).length > 0;
15747
15893
  } catch {
15748
15894
  return false;
15749
15895
  }
@@ -15799,18 +15945,18 @@ async function scoutRepo(repo) {
15799
15945
  await $6({ reject: false })`git -C ${worktree} reset --hard ${baseRef}`;
15800
15946
  }
15801
15947
  await setWorktreeIdentity(worktree, name);
15802
- const abs = (rel) => join28(worktree, rel);
15948
+ const abs = (rel) => join32(worktree, rel);
15803
15949
  const code = await runRepoScout({
15804
15950
  repoFullName,
15805
15951
  repoPath: worktree,
15806
15952
  name,
15807
- readFile: (rel) => existsSync19(abs(rel)) ? readFileSync21(abs(rel), "utf8") : null,
15953
+ readFile: (rel) => existsSync22(abs(rel)) ? readFileSync23(abs(rel), "utf8") : null,
15808
15954
  writeFile: (rel, text) => {
15809
- mkdirSync12(dirname5(abs(rel)), { recursive: true });
15955
+ mkdirSync13(dirname6(abs(rel)), { recursive: true });
15810
15956
  writeFileSync16(abs(rel), text);
15811
15957
  },
15812
15958
  runScout: (prompt) => new Promise((resolve6) => {
15813
- const child = spawn3(bin, [...ISOLATION_FLAGS, "--dangerously-skip-permissions", "-p", prompt], {
15959
+ const child = spawn4(bin, [...ISOLATION_FLAGS, "--dangerously-skip-permissions", "-p", prompt], {
15814
15960
  cwd: worktree,
15815
15961
  stdio: ["ignore", "inherit", "inherit"]
15816
15962
  // человек смотрит на разведку живьём