@taskless-app/swarm 0.6.107 → 0.6.109

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
  }
@@ -4493,7 +4504,7 @@ var init_package = __esm({
4493
4504
  "package.json"() {
4494
4505
  package_default = {
4495
4506
  name: "@taskless-app/swarm",
4496
- version: "0.6.107",
4507
+ version: "0.6.109",
4497
4508
  type: "module",
4498
4509
  description: "Local control plane for a fleet of AI coding agents (drones), coordinating through Taskless. The overmind runs the swarm.",
4499
4510
  keywords: [
@@ -4545,7 +4556,7 @@ var init_package = __esm({
4545
4556
  undici: "^7.30.1",
4546
4557
  zod: "3.25.76"
4547
4558
  },
4548
- gitHead: "ca9dbf062f7b6364a2bcb264cf769d342fe5d185"
4559
+ gitHead: "e7283e2c41d32d7cefa13c6a2311ed343a8a4aa1"
4549
4560
  };
4550
4561
  }
4551
4562
  });
@@ -4709,246 +4720,14 @@ var init_netTimeout = __esm({
4709
4720
  }
4710
4721
  });
4711
4722
 
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
4723
  // src/git.ts
4945
- import { existsSync as existsSync12, readdirSync as readdirSync11, realpathSync as realpathSync2, statSync as statSync11 } from "fs";
4724
+ import { existsSync as existsSync11, readdirSync as readdirSync9, realpathSync as realpathSync2, statSync as statSync10 } from "fs";
4946
4725
  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";
4726
+ import { isAbsolute as isAbsolute2, join as join14, resolve as resolve3, sep as sep2 } from "path";
4727
+ import { $ as $4 } from "execa";
4949
4728
  function gitNet(repo, args, timeoutMs) {
4950
4729
  return withHardTimeout(
4951
- $5({ reject: false, timeout: timeoutMs })`git -C ${repo} ${args}`,
4730
+ $4({ reject: false, timeout: timeoutMs })`git -C ${repo} ${args}`,
4952
4731
  "git",
4953
4732
  gitCallLabel(repo, args),
4954
4733
  timeoutMs
@@ -4958,17 +4737,17 @@ async function reclaimStaleWorktree(repo, worktree) {
4958
4737
  await detachWorktree(repo, worktree);
4959
4738
  }
4960
4739
  async function inspectWorktreePath(path) {
4961
- if (!existsSync12(path)) return "free";
4740
+ if (!existsSync11(path)) return "free";
4962
4741
  try {
4963
- if (readdirSync11(path).length === 0) return "free";
4742
+ if (readdirSync9(path).length === 0) return "free";
4964
4743
  } catch {
4965
4744
  return "orphan";
4966
4745
  }
4967
4746
  try {
4968
- if (statSync11(join17(path, ".git")).isDirectory()) return "main-checkout";
4747
+ if (statSync10(join14(path, ".git")).isDirectory()) return "main-checkout";
4969
4748
  } catch {
4970
4749
  }
4971
- const top = await $5({ reject: false })`git -C ${path} rev-parse --show-toplevel`;
4750
+ const top = await $4({ reject: false })`git -C ${path} rev-parse --show-toplevel`;
4972
4751
  return top.exitCode === 0 && samePath(top.stdout.trim(), path) ? "worktree" : "orphan";
4973
4752
  }
4974
4753
  function samePath(a, b) {
@@ -5004,7 +4783,7 @@ async function clearWorktreePath(repo, path, branch, opts = {}) {
5004
4783
  await detachWorktree(repo, path);
5005
4784
  opts.onStaleReclaim?.(path);
5006
4785
  }
5007
- if (!existsSync12(path)) return;
4786
+ if (!existsSync11(path)) return;
5008
4787
  await parkOrphanDir(repo, path, branch);
5009
4788
  }
5010
4789
  async function parkOrphanDir(repo, path, branch) {
@@ -5021,23 +4800,23 @@ async function parkOrphanDir(repo, path, branch) {
5021
4800
  console.error(
5022
4801
  `[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
4802
  );
5024
- await $5({ reject: false })`git -C ${repo} worktree prune`;
4803
+ await $4({ reject: false })`git -C ${repo} worktree prune`;
5025
4804
  }
5026
4805
  function isLinkedWorktree(dir) {
5027
4806
  try {
5028
- return statSync11(join17(dir, ".git")).isFile();
4807
+ return statSync10(join14(dir, ".git")).isFile();
5029
4808
  } catch {
5030
4809
  return false;
5031
4810
  }
5032
4811
  }
5033
4812
  async function detachWorktree(repo, worktree) {
5034
- await $5({ reject: false })`git -C ${repo} worktree remove --force ${worktree}`;
4813
+ await $4({ reject: false })`git -C ${repo} worktree remove --force ${worktree}`;
5035
4814
  if (await ensureWorktreeDirGone(worktree)) {
5036
- await $5({ reject: false })`git -C ${repo} worktree prune`;
4815
+ await $4({ reject: false })`git -C ${repo} worktree prune`;
5037
4816
  }
5038
4817
  }
5039
4818
  async function ensureWorktreeDirGone(worktree) {
5040
- if (!existsSync12(worktree)) return false;
4819
+ if (!existsSync11(worktree)) return false;
5041
4820
  if (!isLinkedWorktree(worktree)) {
5042
4821
  console.error(
5043
4822
  `[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 +4831,16 @@ async function ensureWorktreeDirGone(worktree) {
5052
4831
  );
5053
4832
  return true;
5054
4833
  }
5055
- if (existsSync12(worktree)) {
4834
+ if (existsSync11(worktree)) {
5056
4835
  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
4836
  }
5058
4837
  return true;
5059
4838
  }
5060
4839
  async function ensureLongPaths(repo, opts = {}) {
5061
4840
  if ((opts.platform ?? process.platform) !== "win32") return false;
5062
- const cur = (await $5({ reject: false })`git -C ${repo} config --get core.longpaths`).stdout.trim();
4841
+ const cur = (await $4({ reject: false })`git -C ${repo} config --get core.longpaths`).stdout.trim();
5063
4842
  if (cur === "true") return false;
5064
- const res = await $5({ reject: false })`git -C ${repo} config core.longpaths true`;
4843
+ const res = await $4({ reject: false })`git -C ${repo} config core.longpaths true`;
5065
4844
  if (res.exitCode !== 0) {
5066
4845
  console.error(
5067
4846
  `[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 +4851,10 @@ async function ensureLongPaths(repo, opts = {}) {
5072
4851
  return true;
5073
4852
  }
5074
4853
  async function revParse(repo, ref) {
5075
- return (await $5({ reject: false })`git -C ${repo} rev-parse --verify --quiet ${ref}`).stdout.trim();
4854
+ return (await $4({ reject: false })`git -C ${repo} rev-parse --verify --quiet ${ref}`).stdout.trim();
5076
4855
  }
5077
4856
  async function worktreeForBranch(repo, branch) {
5078
- const out = (await $5`git -C ${repo} worktree list --porcelain`).stdout;
4857
+ const out = (await $4`git -C ${repo} worktree list --porcelain`).stdout;
5079
4858
  const target = `refs/heads/${branch}`;
5080
4859
  let current = null;
5081
4860
  for (const line of out.split("\n")) {
@@ -5096,12 +4875,12 @@ async function checkoutWorktree(repo, path, branch, opts) {
5096
4875
  if (!localSha && !originSha) {
5097
4876
  const freshBase = opts.base ?? await freshWorktreeBase(repo);
5098
4877
  await clearWorktreePath(repo, path, branch, opts);
5099
- await $5`git -C ${repo} worktree add -b ${branch} ${path} ${freshBase}`;
4878
+ await $4`git -C ${repo} worktree add -b ${branch} ${path} ${freshBase}`;
5100
4879
  return { reused: false };
5101
4880
  }
5102
4881
  const busyAt = await worktreeForBranch(repo, branch);
5103
4882
  if (busyAt) {
5104
- const exists = existsSync12(busyAt);
4883
+ const exists = existsSync11(busyAt);
5105
4884
  const live2 = exists && (opts.isWorktreeHeldLive ? await opts.isWorktreeHeldLive(busyAt) : true);
5106
4885
  if (live2) throw new WorktreeBusyError(branch, busyAt);
5107
4886
  if (exists && await worktreeDirty(busyAt)) throw new WorktreeBusyError(branch, busyAt);
@@ -5110,30 +4889,30 @@ async function checkoutWorktree(repo, path, branch, opts) {
5110
4889
  }
5111
4890
  await clearWorktreePath(repo, path, branch, opts);
5112
4891
  if (originSha) {
5113
- await $5`git -C ${repo} worktree add -B ${branch} ${path} ${`origin/${branch}`}`;
4892
+ await $4`git -C ${repo} worktree add -B ${branch} ${path} ${`origin/${branch}`}`;
5114
4893
  return { reused: true, from: "origin", sha: originSha };
5115
4894
  }
5116
- await $5`git -C ${repo} worktree add ${path} ${branch}`;
4895
+ await $4`git -C ${repo} worktree add ${path} ${branch}`;
5117
4896
  return { reused: true, from: "local" };
5118
4897
  }
5119
4898
  async function freshWorktreeBase(repo) {
5120
- const hasOrigin = (await $5({ reject: false })`git -C ${repo} remote get-url origin`).exitCode === 0;
4899
+ const hasOrigin = (await $4({ reject: false })`git -C ${repo} remote get-url origin`).exitCode === 0;
5121
4900
  if (!hasOrigin) return "HEAD";
5122
- await $5`git -C ${repo} fetch --quiet origin`;
4901
+ await $4`git -C ${repo} fetch --quiet origin`;
5123
4902
  return remoteMainRef(repo);
5124
4903
  }
5125
4904
  async function setWorktreeIdentity(worktree, name) {
5126
4905
  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`}`;
4906
+ await $4`git -C ${worktree} config extensions.worktreeConfig true`;
4907
+ await $4`git -C ${worktree} config --worktree user.name ${`${name} (swarm drone)`}`;
4908
+ await $4`git -C ${worktree} config --worktree user.email ${`${local}@drones.swarm.local`}`;
5130
4909
  }
5131
4910
  async function ensureGitExcluded(worktree, pattern) {
5132
4911
  try {
5133
4912
  const commonDir = await gitPath(worktree, "--git-common-dir");
5134
4913
  if (!commonDir) return false;
5135
- const infoDir = join17(commonDir, "info");
5136
- const excludeFile = join17(infoDir, "exclude");
4914
+ const infoDir = join14(commonDir, "info");
4915
+ const excludeFile = join14(infoDir, "exclude");
5137
4916
  let current = "";
5138
4917
  try {
5139
4918
  current = await readFile(excludeFile, "utf8");
@@ -5150,10 +4929,10 @@ async function ensureGitExcluded(worktree, pattern) {
5150
4929
  }
5151
4930
  }
5152
4931
  async function gitPath(worktree, flag) {
5153
- const out = await $5({ reject: false })`git -C ${worktree} rev-parse ${flag}`;
4932
+ const out = await $4({ reject: false })`git -C ${worktree} rev-parse ${flag}`;
5154
4933
  const raw = out.stdout.trim();
5155
4934
  if (out.exitCode !== 0 || !raw) return null;
5156
- return isAbsolute2(raw) ? raw : join17(worktree, raw);
4935
+ return isAbsolute2(raw) ? raw : join14(worktree, raw);
5157
4936
  }
5158
4937
  async function ensureWorktreeHygiene(worktree) {
5159
4938
  for (const pattern of SWARM_EXCLUDE_PATTERNS) await ensureGitExcluded(worktree, pattern);
@@ -5163,54 +4942,54 @@ async function installGuardHooks(worktree) {
5163
4942
  try {
5164
4943
  const gitDir = await gitPath(worktree, "--git-dir");
5165
4944
  if (!gitDir) return false;
5166
- const hooksDir = join17(gitDir, "swarm-hooks");
4945
+ const hooksDir = join14(gitDir, "swarm-hooks");
5167
4946
  const prev = await previousHooksPath(worktree);
5168
4947
  await mkdir(hooksDir, { recursive: true });
5169
4948
  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);
4949
+ await writeFile(join14(hooksDir, hook), guardHookScript(hook, prev ? `${posix(prev)}/${hook}` : null));
4950
+ await chmod(join14(hooksDir, hook), 493);
5172
4951
  }
5173
- await $5`git -C ${worktree} config extensions.worktreeConfig true`;
5174
- await $5`git -C ${worktree} config --worktree core.hooksPath ${posix(hooksDir)}`;
4952
+ await $4`git -C ${worktree} config extensions.worktreeConfig true`;
4953
+ await $4`git -C ${worktree} config --worktree core.hooksPath ${posix(hooksDir)}`;
5175
4954
  return true;
5176
4955
  } catch {
5177
4956
  return false;
5178
4957
  }
5179
4958
  }
5180
4959
  function posix(p) {
5181
- return (sep3 === "\\" ? p.replace(/\\/g, "/") : p).replace(/\/+$/, "");
4960
+ return (sep2 === "\\" ? p.replace(/\\/g, "/") : p).replace(/\/+$/, "");
5182
4961
  }
5183
4962
  async function previousHooksPath(worktree) {
5184
4963
  for (const scope of ["--local", "--global", "--system"]) {
5185
- const out = await $5({ reject: false })`git -C ${worktree} config ${scope} --get core.hooksPath`;
4964
+ const out = await $4({ reject: false })`git -C ${worktree} config ${scope} --get core.hooksPath`;
5186
4965
  const value = out.stdout.trim();
5187
4966
  if (out.exitCode === 0 && value) return value;
5188
4967
  }
5189
4968
  const commonDir = await gitPath(worktree, "--git-common-dir");
5190
- return commonDir ? join17(commonDir, "hooks") : null;
4969
+ return commonDir ? join14(commonDir, "hooks") : null;
5191
4970
  }
5192
4971
  async function removeWorktree(repo, path) {
5193
- const branch = (await $5({ reject: false })`git -C ${path} symbolic-ref --quiet --short HEAD`).stdout.trim();
4972
+ const branch = (await $4({ reject: false })`git -C ${path} symbolic-ref --quiet --short HEAD`).stdout.trim();
5194
4973
  await releaseWorktree(repo, path);
5195
- if (branch) await $5({ reject: false })`git -C ${repo} branch -D ${branch}`;
4974
+ if (branch) await $4({ reject: false })`git -C ${repo} branch -D ${branch}`;
5196
4975
  }
5197
4976
  async function releaseWorktree(repo, path) {
5198
4977
  await cleanupWorktreeProcesses(path);
5199
4978
  await detachWorktree(repo, path);
5200
4979
  }
5201
4980
  async function worktreeDirty(path) {
5202
- const st = await $5({ reject: false })`git -C ${path} status --porcelain --untracked-files=all`;
4981
+ const st = await $4({ reject: false })`git -C ${path} status --porcelain --untracked-files=all`;
5203
4982
  if (st.exitCode !== 0) return true;
5204
4983
  const status = st.stdout.trim();
5205
4984
  if (status) return true;
5206
- const unpushed = (await $5({ reject: false })`git -C ${path} rev-list --count HEAD --not --remotes`).stdout.trim();
4985
+ const unpushed = (await $4({ reject: false })`git -C ${path} rev-list --count HEAD --not --remotes`).stdout.trim();
5207
4986
  return unpushed !== "" && unpushed !== "0";
5208
4987
  }
5209
4988
  async function remoteMainRef(repo) {
5210
- const head = (await $5({ reject: false })`git -C ${repo} symbolic-ref --quiet --short refs/remotes/origin/HEAD`).stdout.trim();
4989
+ const head = (await $4({ reject: false })`git -C ${repo} symbolic-ref --quiet --short refs/remotes/origin/HEAD`).stdout.trim();
5211
4990
  if (head) return head;
5212
4991
  for (const cand of ["origin/main", "origin/master"]) {
5213
- const ok2 = await $5({ reject: false })`git -C ${repo} rev-parse --verify --quiet ${cand}`;
4992
+ const ok2 = await $4({ reject: false })`git -C ${repo} rev-parse --verify --quiet ${cand}`;
5214
4993
  if (ok2.exitCode === 0) return cand;
5215
4994
  }
5216
4995
  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 +5027,241 @@ var init_git = __esm({
5248
5027
  }
5249
5028
  });
5250
5029
 
5030
+ // src/droneChannel.ts
5031
+ import { createHmac, randomBytes, timingSafeEqual } from "crypto";
5032
+ import { chmodSync as chmodSync2, mkdirSync as mkdirSync10, readFileSync as readFileSync13, writeFileSync as writeFileSync9 } from "fs";
5033
+ import { dirname as dirname4 } from "path";
5034
+ import { serve } from "@hono/node-server";
5035
+ function loadChannelSecret(path) {
5036
+ try {
5037
+ const s = readFileSync13(path, "utf8").trim();
5038
+ if (s.length >= 32) return s;
5039
+ } catch {
5040
+ }
5041
+ const secret = randomBytes(32).toString("hex");
5042
+ mkdirSync10(dirname4(path), { recursive: true });
5043
+ writeFileSync9(path, secret, { mode: 384 });
5044
+ try {
5045
+ chmodSync2(path, 384);
5046
+ } catch {
5047
+ }
5048
+ return secret;
5049
+ }
5050
+ function sign(runKey, secret) {
5051
+ return createHmac("sha256", secret).update(runKey).digest("base64url");
5052
+ }
5053
+ function mintChannelToken(runKey, secret) {
5054
+ return `${Buffer.from(runKey, "utf8").toString("base64url")}.${sign(runKey, secret)}`;
5055
+ }
5056
+ function verifyChannelToken(token, secret) {
5057
+ const dot = token.lastIndexOf(".");
5058
+ if (dot <= 0) return null;
5059
+ const runKey = Buffer.from(token.slice(0, dot), "base64url").toString("utf8");
5060
+ if (!runKey) return null;
5061
+ const got = Buffer.from(token.slice(dot + 1));
5062
+ const want = Buffer.from(sign(runKey, secret));
5063
+ if (got.length !== want.length || !timingSafeEqual(got, want)) return null;
5064
+ return runKey;
5065
+ }
5066
+ function mintLocalCliToken(secret) {
5067
+ return mintChannelToken(LOCAL_CLI_KEY, secret);
5068
+ }
5069
+ function verifyLocalCliToken(token, secret) {
5070
+ return verifyChannelToken(token, secret) === LOCAL_CLI_KEY;
5071
+ }
5072
+ var LOCAL_CLI_KEY, EVENT_KIND_SET;
5073
+ var init_droneChannel = __esm({
5074
+ "src/droneChannel.ts"() {
5075
+ "use strict";
5076
+ init_src();
5077
+ LOCAL_CLI_KEY = "cli";
5078
+ EVENT_KIND_SET = new Set(EVENT_KINDS);
5079
+ }
5080
+ });
5081
+
5082
+ // src/authState.ts
5083
+ function noteTokenRejected(nowMs = Date.now()) {
5084
+ if (!denial) {
5085
+ denial = { since: nowMs, lastShoutAt: nowMs, count: 1 };
5086
+ return revokedTokenComplaint();
5087
+ }
5088
+ denial.count += 1;
5089
+ if (nowMs - denial.lastShoutAt < SHOUT_EVERY_MS) return null;
5090
+ denial.lastShoutAt = nowMs;
5091
+ return `${revokedTokenComplaint()}
5092
+ ${deniedSinceLine(nowMs)}
5093
+ `;
5094
+ }
5095
+ function noteTokenAccepted() {
5096
+ denial = null;
5097
+ }
5098
+ function authStateLine(nowMs = Date.now()) {
5099
+ if (!denial) return null;
5100
+ 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`;
5101
+ }
5102
+ function deniedSinceLine(nowMs) {
5103
+ const d = denial;
5104
+ if (!d) return "";
5105
+ const min = Math.max(1, Math.round((nowMs - d.since) / 6e4));
5106
+ 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}`;
5107
+ }
5108
+ var SHOUT_EVERY_MS, denial;
5109
+ var init_authState = __esm({
5110
+ "src/authState.ts"() {
5111
+ "use strict";
5112
+ init_agentToken();
5113
+ SHOUT_EVERY_MS = 10 * 6e4;
5114
+ denial = null;
5115
+ }
5116
+ });
5117
+
5118
+ // src/oauth.ts
5119
+ import { createHash as createHash3, randomBytes as randomBytes2 } from "crypto";
5120
+ import { readFileSync as readFileSync14, writeFileSync as writeFileSync10, unlinkSync as unlinkSync3 } from "fs";
5121
+ import { join as join19 } from "path";
5122
+ function makePkce() {
5123
+ const verifier = randomBytes2(48).toString("base64url");
5124
+ const challenge = createHash3("sha256").update(verifier).digest("base64url");
5125
+ return { verifier, challenge };
5126
+ }
5127
+ async function registerClient(args, fetchFn = fetch) {
5128
+ const res = await fetchFn(`${base2(args.api)}${REGISTER}`, {
5129
+ method: "POST",
5130
+ headers: { "Content-Type": "application/json" },
5131
+ body: JSON.stringify({
5132
+ client_name: args.name ?? "Taskless Swarm",
5133
+ redirect_uris: [args.redirectUri],
5134
+ token_endpoint_auth_method: "none"
5135
+ })
5136
+ });
5137
+ if (!res.ok) throw new Error(`register: HTTP ${res.status} ${(await res.text().catch(() => "")).slice(0, 160)}`);
5138
+ const j = await res.json();
5139
+ if (!j.client_id) throw new Error("register: \u0432 \u043E\u0442\u0432\u0435\u0442\u0435 \u043D\u0435\u0442 client_id");
5140
+ return j.client_id;
5141
+ }
5142
+ function authorizeUrl(args) {
5143
+ const u = new URL(`${base2(args.api)}${AUTHORIZE}`);
5144
+ u.searchParams.set("response_type", "code");
5145
+ u.searchParams.set("client_id", args.clientId);
5146
+ u.searchParams.set("redirect_uri", args.redirectUri);
5147
+ u.searchParams.set("scope", SCOPE);
5148
+ u.searchParams.set("code_challenge", args.challenge);
5149
+ u.searchParams.set("code_challenge_method", "S256");
5150
+ u.searchParams.set("state", args.state);
5151
+ return u.toString();
5152
+ }
5153
+ async function postToken(api, params, fetchFn) {
5154
+ const res = await fetchFn(`${base2(api)}${TOKEN}`, {
5155
+ method: "POST",
5156
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
5157
+ body: new URLSearchParams(params).toString()
5158
+ });
5159
+ const text = await res.text();
5160
+ if (!res.ok) throw new Error(`token ${params.grant_type}: HTTP ${res.status} ${text.slice(0, 200)}`);
5161
+ const j = JSON.parse(text);
5162
+ if (!j.access_token) throw new Error("token: \u0432 \u043E\u0442\u0432\u0435\u0442\u0435 \u043D\u0435\u0442 access_token");
5163
+ return j;
5164
+ }
5165
+ function exchangeCode(args, fetchFn = fetch) {
5166
+ return postToken(
5167
+ args.api,
5168
+ {
5169
+ grant_type: "authorization_code",
5170
+ code: args.code,
5171
+ code_verifier: args.verifier,
5172
+ client_id: args.clientId,
5173
+ redirect_uri: args.redirectUri
5174
+ },
5175
+ fetchFn
5176
+ );
5177
+ }
5178
+ function refreshTokens(args, fetchFn = fetch) {
5179
+ return postToken(
5180
+ args.api,
5181
+ { grant_type: "refresh_token", refresh_token: args.refreshToken, client_id: args.clientId },
5182
+ fetchFn
5183
+ );
5184
+ }
5185
+ function emailFromIdToken(idToken) {
5186
+ const payload = idToken?.split(".")[1];
5187
+ if (!payload) return void 0;
5188
+ try {
5189
+ return JSON.parse(Buffer.from(payload, "base64url").toString("utf8")).email;
5190
+ } catch {
5191
+ return void 0;
5192
+ }
5193
+ }
5194
+ function toStore(clientId, t, now) {
5195
+ return {
5196
+ clientId,
5197
+ accessToken: t.access_token,
5198
+ refreshToken: t.refresh_token,
5199
+ expiresAt: now + t.expires_in * 1e3,
5200
+ email: emailFromIdToken(t.id_token)
5201
+ };
5202
+ }
5203
+ function loadStore() {
5204
+ try {
5205
+ return JSON.parse(readFileSync14(STORE_PATH2, "utf8"));
5206
+ } catch {
5207
+ return null;
5208
+ }
5209
+ }
5210
+ function saveStore(s) {
5211
+ writeFileSync10(STORE_PATH2, JSON.stringify(s, null, 2), { mode: 384 });
5212
+ }
5213
+ function clearStore() {
5214
+ try {
5215
+ unlinkSync3(STORE_PATH2);
5216
+ } catch {
5217
+ }
5218
+ }
5219
+ function loadClientId() {
5220
+ try {
5221
+ return JSON.parse(readFileSync14(CLIENT_PATH, "utf8")).clientId;
5222
+ } catch {
5223
+ return null;
5224
+ }
5225
+ }
5226
+ async function ensureClientId(api, redirectUri, fetchFn = fetch) {
5227
+ const existing = loadClientId();
5228
+ if (existing) return existing;
5229
+ const clientId = await registerClient({ api, redirectUri }, fetchFn);
5230
+ writeFileSync10(CLIENT_PATH, JSON.stringify({ clientId }, null, 2), { mode: 384 });
5231
+ return clientId;
5232
+ }
5233
+ async function ensureAccess(store, opts = {}) {
5234
+ const api = opts.api ?? TASKLESS_API;
5235
+ const now = opts.now ?? Date.now();
5236
+ const fetchFn = opts.fetchFn ?? fetch;
5237
+ if (store.expiresAt - now > 6e4) return { accessToken: store.accessToken };
5238
+ try {
5239
+ const t = await refreshTokens({ api, clientId: store.clientId, refreshToken: store.refreshToken }, fetchFn);
5240
+ const next = toStore(store.clientId, t, now);
5241
+ next.email = next.email ?? store.email;
5242
+ return { accessToken: next.accessToken, store: next };
5243
+ } catch {
5244
+ return null;
5245
+ }
5246
+ }
5247
+ var REGISTER, AUTHORIZE, TOKEN, SCOPE, STORE_PATH2, CLIENT_PATH, base2;
5248
+ var init_oauth = __esm({
5249
+ "src/oauth.ts"() {
5250
+ "use strict";
5251
+ init_config();
5252
+ REGISTER = "/api/oauth/register";
5253
+ AUTHORIZE = "/api/oauth/authorize";
5254
+ TOKEN = "/api/oauth/token";
5255
+ SCOPE = "openid profile email taskless:full";
5256
+ STORE_PATH2 = join19(SWARM_HOME, "oauth.json");
5257
+ CLIENT_PATH = join19(SWARM_HOME, "oauth-client.json");
5258
+ base2 = (api) => api.replace(/\/$/, "");
5259
+ }
5260
+ });
5261
+
5251
5262
  // 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";
5263
+ import { mkdir as mkdir3, readFile as readFile2, readdir as readdir2, stat as stat2, unlink, writeFile as writeFile3 } from "fs/promises";
5264
+ import { extname, join as join22 } from "path";
5254
5265
  var ATTACHMENTS_DIR, ATTACH_MAX_TOTAL_BYTES, ATTACH_MAX_FILE_BYTES, IMAGE_EXT, DOC_EXT, TEXT_EXT, KNOWN_EXT;
5255
5266
  var init_attachments = __esm({
5256
5267
  "src/attachments.ts"() {
@@ -5269,7 +5280,7 @@ var init_attachments = __esm({
5269
5280
 
5270
5281
  // src/shotUpload.ts
5271
5282
  import { readFile as fsReadFile } from "fs/promises";
5272
- import { basename as basename6, isAbsolute as isAbsolute3, join as join19 } from "path";
5283
+ import { basename as basename6, isAbsolute as isAbsolute3, join as join23 } from "path";
5273
5284
  var SHOT_MAX_FILE_BYTES;
5274
5285
  var init_shotUpload = __esm({
5275
5286
  "src/shotUpload.ts"() {
@@ -5320,11 +5331,11 @@ var init_prodHttp = __esm({
5320
5331
  });
5321
5332
 
5322
5333
  // src/workspace.ts
5323
- import { readFileSync as readFileSync13, writeFileSync as writeFileSync11, unlinkSync as unlinkSync4 } from "fs";
5324
- import { join as join20 } from "path";
5334
+ import { readFileSync as readFileSync15, writeFileSync as writeFileSync11, unlinkSync as unlinkSync4 } from "fs";
5335
+ import { join as join24 } from "path";
5325
5336
  function loadWorkspace() {
5326
5337
  try {
5327
- const w = JSON.parse(readFileSync13(WORKSPACE_PATH, "utf8"));
5338
+ const w = JSON.parse(readFileSync15(WORKSPACE_PATH, "utf8"));
5328
5339
  return w && typeof w.id === "string" && w.id ? w : null;
5329
5340
  } catch {
5330
5341
  return null;
@@ -5347,7 +5358,7 @@ var init_workspace = __esm({
5347
5358
  "src/workspace.ts"() {
5348
5359
  "use strict";
5349
5360
  init_config();
5350
- WORKSPACE_PATH = join20(SWARM_HOME, "workspace.json");
5361
+ WORKSPACE_PATH = join24(SWARM_HOME, "workspace.json");
5351
5362
  }
5352
5363
  });
5353
5364
 
@@ -5788,14 +5799,14 @@ var init_daemonLink = __esm({
5788
5799
  });
5789
5800
 
5790
5801
  // 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";
5802
+ import { existsSync as existsSync16, readFileSync as readFileSync16, renameSync as renameSync5, unlinkSync as unlinkSync5, writeFileSync as writeFileSync12 } from "fs";
5803
+ import { join as join25 } from "path";
5793
5804
  function pauseStatePath(home) {
5794
- return join21(home, "pause.json");
5805
+ return join25(home, "pause.json");
5795
5806
  }
5796
5807
  function loadPauseState(home, io = {}) {
5797
- const exists = io.exists ?? existsSync13;
5798
- const readFile3 = io.readFile ?? ((p) => readFileSync14(p, "utf8"));
5808
+ const exists = io.exists ?? existsSync16;
5809
+ const readFile3 = io.readFile ?? ((p) => readFileSync16(p, "utf8"));
5799
5810
  const path = pauseStatePath(home);
5800
5811
  if (!exists(path)) return ACTIVE;
5801
5812
  try {
@@ -5814,15 +5825,15 @@ function loadPauseState(home, io = {}) {
5814
5825
  function savePauseState(home, state, io = {}) {
5815
5826
  const path = pauseStatePath(home);
5816
5827
  if (!state.paused) {
5817
- const remove = io.remove ?? ((p) => existsSync13(p) && unlinkSync5(p));
5828
+ const remove = io.remove ?? ((p) => existsSync16(p) && unlinkSync5(p));
5818
5829
  remove(path);
5819
5830
  return;
5820
5831
  }
5821
- const writeFile3 = io.writeFile ?? ((p, data) => {
5832
+ const writeFile4 = io.writeFile ?? ((p, data) => {
5822
5833
  writeFileSync12(`${p}.tmp`, data);
5823
5834
  renameSync5(`${p}.tmp`, p);
5824
5835
  });
5825
- writeFile3(path, JSON.stringify(state, null, 2));
5836
+ writeFile4(path, JSON.stringify(state, null, 2));
5826
5837
  }
5827
5838
  function makePauseState(source, reason, now = Date.now()) {
5828
5839
  return {
@@ -5856,10 +5867,10 @@ var init_pauseState = __esm({
5856
5867
  });
5857
5868
 
5858
5869
  // src/heartbeat.ts
5859
- import { readFileSync as readFileSync15, renameSync as renameSync6, writeFileSync as writeFileSync13 } from "fs";
5870
+ import { readFileSync as readFileSync17, renameSync as renameSync6, writeFileSync as writeFileSync13 } from "fs";
5860
5871
  function readHeartbeat(path) {
5861
5872
  try {
5862
- const ms = Number(readFileSync15(path, "utf8").trim());
5873
+ const ms = Number(readFileSync17(path, "utf8").trim());
5863
5874
  return Number.isFinite(ms) ? ms : null;
5864
5875
  } catch {
5865
5876
  return null;
@@ -5878,7 +5889,7 @@ __export(db_exports, {
5878
5889
  });
5879
5890
  import { createRequire as createRequire2 } from "module";
5880
5891
  import { randomUUID as randomUUID3 } from "crypto";
5881
- import { existsSync as existsSync14 } from "fs";
5892
+ import { existsSync as existsSync17 } from "fs";
5882
5893
  import { resolve as resolve4 } from "path";
5883
5894
  function rowToQuestion(row) {
5884
5895
  return {
@@ -6086,6 +6097,12 @@ CREATE TABLE IF NOT EXISTS imports (
6086
6097
  // для importDb (второй Database, source)
6087
6098
  /** Идентификатор этой жизни файла базы (TASWM-419) — им неймспейсятся каталоги run-log'ов. */
6088
6099
  instanceId;
6100
+ /**
6101
+ * TASWM-680. Слаги, чья задача закрыта. Живёт в памяти процесса: sqlite задач не
6102
+ * хранит, а «закрыта» приходит из Taskless на тике. Рестарт демона карту обнуляет
6103
+ * и спрашивает снова — остановленный блокер без ответа остаётся ожиданием.
6104
+ */
6105
+ taskClosedSlugs = /* @__PURE__ */ new Set();
6089
6106
  constructor(path = "swarm.db", defaultRepo = "") {
6090
6107
  this.defaultRepo = normalizeRepo(defaultRepo);
6091
6108
  this.databaseCtor = loadBetterSqlite3();
@@ -6506,6 +6523,11 @@ CREATE TABLE IF NOT EXISTS imports (
6506
6523
  * Несуществующий/зациклённый слаг прогонов не имеет вовсе → `pending` → прогон ждёт, как и
6507
6524
  * раньше, но очередь не виснет (гейт — пропуск в цикле, не блокировка).
6508
6525
  */
6526
+ /** TASWM-680. См. SwarmStore.noteTaskClosed. */
6527
+ noteTaskClosed(slug, closed) {
6528
+ if (closed) this.taskClosedSlugs.add(slug);
6529
+ else this.taskClosedSlugs.delete(slug);
6530
+ }
6509
6531
  unmetDeps(depends_on) {
6510
6532
  return this.depVerdicts(depends_on).filter((d) => !d.met).map((d) => d.slug);
6511
6533
  }
@@ -6526,7 +6548,10 @@ CREATE TABLE IF NOT EXISTS imports (
6526
6548
  list.push({ status: r.status, name: r.name, stopReason: r.stop_reason });
6527
6549
  bySlug.set(r.task_slug, list);
6528
6550
  }
6529
- return depends_on.map((slug) => ({ slug, ...judgeDep(bySlug.get(slug) ?? []) }));
6551
+ return depends_on.map((slug) => ({
6552
+ slug,
6553
+ ...judgeDep(bySlug.get(slug) ?? [], { taskClosed: this.taskClosedSlugs.has(slug) })
6554
+ }));
6530
6555
  }
6531
6556
  /** Все репо, засветившиеся в прогонах — whitelist для валидации spawn из веба. */
6532
6557
  distinctRepos() {
@@ -6556,7 +6581,7 @@ CREATE TABLE IF NOT EXISTS imports (
6556
6581
  const repoN = normalizeRepo(repo);
6557
6582
  const already = this.db.prepare("SELECT run_count FROM imports WHERE source = ?").get(abs);
6558
6583
  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}`);
6584
+ if (!existsSync17(abs)) throw new Error(`import-db: \u0444\u0430\u0439\u043B\u0430 \u043D\u0435\u0442: ${abs}`);
6560
6585
  const src = new this.databaseCtor(abs);
6561
6586
  try {
6562
6587
  const runs = src.prepare("SELECT * FROM runs ORDER BY id").all();
@@ -6924,8 +6949,8 @@ CREATE TABLE IF NOT EXISTS imports (
6924
6949
  });
6925
6950
 
6926
6951
  // src/repoScan.ts
6927
- import { readdirSync as readdirSync12, readFileSync as readFileSync16, statSync as statSync12 } from "fs";
6928
- import { join as join22 } from "path";
6952
+ import { readdirSync as readdirSync13, readFileSync as readFileSync18, statSync as statSync13 } from "fs";
6953
+ import { join as join26 } from "path";
6929
6954
  var init_repoScan = __esm({
6930
6955
  "src/repoScan.ts"() {
6931
6956
  "use strict";
@@ -6935,8 +6960,8 @@ var init_repoScan = __esm({
6935
6960
 
6936
6961
  // src/repoDiscovery.ts
6937
6962
  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";
6963
+ import { readFileSync as readFileSync19, renameSync as renameSync7, writeFileSync as writeFileSync14 } from "fs";
6964
+ import { isAbsolute as isAbsolute4, join as join27, resolve as resolve5 } from "path";
6940
6965
  function repoMapLines(rows) {
6941
6966
  if (!rows?.length) return [];
6942
6967
  const missing = rows.filter((r) => !r.path).length;
@@ -6951,7 +6976,7 @@ function repoMapLines(rows) {
6951
6976
  }
6952
6977
  function loadRepoMapCache(path) {
6953
6978
  try {
6954
- const raw = JSON.parse(readFileSync17(path, "utf8"));
6979
+ const raw = JSON.parse(readFileSync19(path, "utf8"));
6955
6980
  if (!Array.isArray(raw?.entries)) return { scannedAt: null, entries: [] };
6956
6981
  return {
6957
6982
  scannedAt: typeof raw.scannedAt === "string" && raw.scannedAt ? raw.scannedAt : null,
@@ -7041,46 +7066,46 @@ function uptimeText(startedAt, now) {
7041
7066
  const hr = Math.floor(min / 60);
7042
7067
  return `${hr} \u0447 ${min % 60} \u043C\u0438\u043D`;
7043
7068
  }
7044
- function linkTrouble(link) {
7045
- if (link.kind === "ok" || link.kind === "no-prod" || link.kind === "starting") return null;
7046
- if (link.kind === "unmeasured") {
7069
+ function linkTrouble(link2) {
7070
+ if (link2.kind === "ok" || link2.kind === "no-prod" || link2.kind === "starting") return null;
7071
+ if (link2.kind === "unmeasured") {
7047
7072
  return {
7048
7073
  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`,
7074
+ 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
7075
  fixes: [
7051
7076
  { 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
7077
  { 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
7078
  ]
7054
7079
  };
7055
7080
  }
7056
- if (link.kind === "no-token") {
7081
+ if (link2.kind === "no-token") {
7057
7082
  return {
7058
7083
  id: "link-no-token",
7059
7084
  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
7085
  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
7086
  };
7062
7087
  }
7063
- if (link.kind === "revoked") {
7088
+ if (link2.kind === "revoked") {
7064
7089
  return {
7065
7090
  id: "link-revoked",
7066
7091
  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
7092
  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
7093
  };
7069
7094
  }
7070
- if (link.kind === "server") {
7095
+ if (link2.kind === "server") {
7071
7096
  return {
7072
7097
  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`,
7098
+ 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
7099
  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` },
7100
+ { 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
7101
  { 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
7102
  ]
7078
7103
  };
7079
7104
  }
7080
- if (link.kind === "down") {
7105
+ if (link2.kind === "down") {
7081
7106
  return {
7082
7107
  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`,
7108
+ 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
7109
  fixes: [
7085
7110
  { 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
7111
  { 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 +7114,11 @@ function linkTrouble(link) {
7089
7114
  }
7090
7115
  return {
7091
7116
  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`,
7117
+ 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
7118
  fixes: [
7094
7119
  {
7095
7120
  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))"`
7121
+ 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
7122
  },
7098
7123
  { 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
7124
  ]
@@ -7212,15 +7237,15 @@ function troubles(f) {
7212
7237
  if (linkWhenDead) out.push(linkWhenDead);
7213
7238
  return out;
7214
7239
  }
7215
- const link = linkTrouble(f.link);
7216
- if (link) out.push(link);
7240
+ const link2 = linkTrouble(f.link);
7241
+ if (link2) out.push(link2);
7217
7242
  if (f.daemon.pause?.paused) {
7218
7243
  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
7244
  }
7220
7245
  const up = staleMs(f.daemon.startedAt, f.now);
7221
7246
  const heard = staleMs(f.park.lastHeardAt, f.now);
7222
7247
  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)) {
7248
+ if (!link2 && (neverHeard || f.park.lastHeardAt && heard != null && heard > PARK_STALE_MS)) {
7224
7249
  out.push({
7225
7250
  id: "park-stale",
7226
7251
  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 +7258,7 @@ function troubles(f) {
7233
7258
  out.push(...blockedTroubles(f));
7234
7259
  const idle = idleTrouble(f);
7235
7260
  if (idle) out.push(idle);
7236
- else if (waitingForDrone(f.work) > 0 && f.work.busy === 0 && !link && out.length === 0) {
7261
+ else if (waitingForDrone(f.work) > 0 && f.work.busy === 0 && !link2 && out.length === 0) {
7237
7262
  out.push({
7238
7263
  id: "idle-unknown",
7239
7264
  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 +7372,11 @@ __export(statusCli_exports, {
7347
7372
  probeLink: () => probeLink,
7348
7373
  runStatusCli: () => runStatusCli
7349
7374
  });
7350
- import { existsSync as existsSync15, readFileSync as readFileSync18 } from "fs";
7375
+ import { existsSync as existsSync18, readFileSync as readFileSync20 } from "fs";
7351
7376
  function outboxPending(path) {
7352
7377
  try {
7353
- if (!existsSync15(path)) return 0;
7354
- return readFileSync18(path, "utf8").split("\n").filter((l) => l.trim()).length;
7378
+ if (!existsSync18(path)) return 0;
7379
+ return readFileSync20(path, "utf8").split("\n").filter((l) => l.trim()).length;
7355
7380
  } catch {
7356
7381
  return null;
7357
7382
  }
@@ -7365,7 +7390,7 @@ async function probeLink() {
7365
7390
  if (probe === "revoked") return { kind: "revoked", detail: "401 invalid_token", ...base3 };
7366
7391
  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
7392
  }
7368
- function factsFromDaemon(st, link, now) {
7393
+ function factsFromDaemon(st, link2, now) {
7369
7394
  const counts = st.counts ?? {};
7370
7395
  return {
7371
7396
  daemon: {
@@ -7378,7 +7403,7 @@ function factsFromDaemon(st, link, now) {
7378
7403
  pause: st.pause ?? (st.paused ? { paused: true, at: "", source: "web" } : null),
7379
7404
  restartWaiting: st.restart?.phase === "waiting"
7380
7405
  },
7381
- link,
7406
+ link: link2,
7382
7407
  park: { lastHeardAt: st.link?.heardAt ?? null },
7383
7408
  work: {
7384
7409
  busy: st.live?.length ?? 0,
@@ -7420,7 +7445,7 @@ function daemonProcessAlive(now) {
7420
7445
  return beat != null && now - beat < HEARTBEAT_FRESH_MS;
7421
7446
  }
7422
7447
  async function factsWithoutDaemon(now) {
7423
- const link = await probeLink();
7448
+ const link2 = await probeLink();
7424
7449
  return {
7425
7450
  daemon: {
7426
7451
  alive: false,
@@ -7436,7 +7461,7 @@ async function factsWithoutDaemon(now) {
7436
7461
  pause: loadPauseState(SWARM_HOME),
7437
7462
  restartWaiting: false
7438
7463
  },
7439
- link,
7464
+ link: link2,
7440
7465
  // Пульса нет по построению: пульсит демон, а его нет. Не выдаём это за «прод молчит».
7441
7466
  park: { lastHeardAt: null },
7442
7467
  work: { busy: 0, queued: 0, queuedReady: null, questions: 0, other: {}, maxDrones: null, storm: null },
@@ -7558,23 +7583,23 @@ var init_prodMergeGate = __esm({
7558
7583
  });
7559
7584
 
7560
7585
  // 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";
7586
+ import { accessSync, constants, existsSync as existsSync19, readFileSync as readFileSync21, realpathSync as realpathSync3 } from "fs";
7587
+ import { delimiter, join as join28, posix as posix2, win32 } from "path";
7563
7588
  function safeReadText(path) {
7564
7589
  try {
7565
- return readFileSync19(path, "utf8");
7590
+ return readFileSync21(path, "utf8");
7566
7591
  } catch {
7567
7592
  return null;
7568
7593
  }
7569
7594
  }
7570
7595
  function resolveCommandPath(name, env = process.env, platform = process.platform) {
7571
- if (name.includes("/") || name.includes("\\")) return existsSync16(name) ? name : null;
7596
+ if (name.includes("/") || name.includes("\\")) return existsSync19(name) ? name : null;
7572
7597
  const dirs = (env.PATH ?? env.Path ?? "").split(delimiter).filter(Boolean);
7573
7598
  const exts = platform === "win32" ? (env.PATHEXT ?? ".EXE;.CMD;.BAT").split(";").filter(Boolean) : [""];
7574
7599
  for (const dir of dirs) {
7575
7600
  for (const ext of exts) {
7576
- const candidate = join24(dir, name + ext);
7577
- if (existsSync16(candidate)) return candidate;
7601
+ const candidate = join28(dir, name + ext);
7602
+ if (existsSync19(candidate)) return candidate;
7578
7603
  }
7579
7604
  }
7580
7605
  return null;
@@ -7764,18 +7789,18 @@ var init_platform = __esm({
7764
7789
  });
7765
7790
 
7766
7791
  // src/envGate.ts
7767
- import { existsSync as existsSync17 } from "fs";
7768
- import { join as join25 } from "path";
7792
+ import { existsSync as existsSync20 } from "fs";
7793
+ import { join as join29 } from "path";
7769
7794
  import { createConnection } from "net";
7770
- import { execa as execa3 } from "execa";
7795
+ import { execa as execa4 } from "execa";
7771
7796
  function detectRequirements(repo, io = {}) {
7772
- const exists = io.exists ?? existsSync17;
7773
- const marker = COMPOSE_MARKERS.find((f) => exists(join25(repo, f)));
7797
+ const exists = io.exists ?? existsSync20;
7798
+ const marker = COMPOSE_MARKERS.find((f) => exists(join29(repo, f)));
7774
7799
  return marker ? [{ kind: "docker", raw: `docker (\u0434\u0435\u0442\u0435\u043A\u0442: ${marker})` }] : [];
7775
7800
  }
7776
7801
  async function probeDockerDaemon() {
7777
7802
  try {
7778
- const res = await execa3("docker", ["version", "--format", "{{.Server.Version}}"], {
7803
+ const res = await execa4("docker", ["version", "--format", "{{.Server.Version}}"], {
7779
7804
  timeout: PROBE_TIMEOUT_MS2,
7780
7805
  reject: false
7781
7806
  });
@@ -7806,7 +7831,7 @@ var init_envGate = __esm({
7806
7831
  });
7807
7832
 
7808
7833
  // src/doctor.ts
7809
- import { isAbsolute as isAbsolute5, join as join26 } from "path";
7834
+ import { isAbsolute as isAbsolute5, join as join30 } from "path";
7810
7835
  function ok(id, title, detail) {
7811
7836
  return { id, title, status: "ok", detail, remedies: [], critical: false };
7812
7837
  }
@@ -8015,7 +8040,7 @@ function checkRepos(io, snap) {
8015
8040
  critical: true
8016
8041
  };
8017
8042
  }
8018
- if (env && !io.exists(join26(env, ".git"))) {
8043
+ if (env && !io.exists(join30(env, ".git"))) {
8019
8044
  return {
8020
8045
  id: "repos",
8021
8046
  title,
@@ -8025,7 +8050,7 @@ function checkRepos(io, snap) {
8025
8050
  critical: true
8026
8051
  };
8027
8052
  }
8028
- const broken = snap.paths.filter((p) => !io.exists(join26(p, ".git")));
8053
+ const broken = snap.paths.filter((p) => !io.exists(join30(p, ".git")));
8029
8054
  if (broken.length) {
8030
8055
  return {
8031
8056
  id: "repos",
@@ -8215,12 +8240,12 @@ var init_doctor = __esm({
8215
8240
  });
8216
8241
 
8217
8242
  // src/repoMemory.ts
8218
- import { readFileSync as readFileSync20, writeFileSync as writeFileSync15 } from "fs";
8219
- import { join as join27 } from "path";
8243
+ import { readFileSync as readFileSync22, writeFileSync as writeFileSync15 } from "fs";
8244
+ import { join as join31 } from "path";
8220
8245
  function loadRememberedRepos(home) {
8221
8246
  let raw;
8222
8247
  try {
8223
- raw = readFileSync20(join27(home, FILE), "utf8");
8248
+ raw = readFileSync22(join31(home, FILE), "utf8");
8224
8249
  } catch {
8225
8250
  return [];
8226
8251
  }
@@ -8256,7 +8281,7 @@ __export(installCli_exports, {
8256
8281
  runInstallHookCli: () => runInstallHookCli,
8257
8282
  shortenError: () => shortenError
8258
8283
  });
8259
- import { existsSync as existsSync18 } from "fs";
8284
+ import { existsSync as existsSync21 } from "fs";
8260
8285
  function classifyChromiumError(message) {
8261
8286
  if (/playwright-core не установлен|Cannot find (module|package)/i.test(message)) return "no-module";
8262
8287
  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 +8336,7 @@ function defaultDoctorIO(packageVersion) {
8311
8336
  packageVersion,
8312
8337
  entry,
8313
8338
  hasCommand: (name) => hasCommandInPath(name),
8314
- exists: existsSync18,
8339
+ exists: existsSync21,
8315
8340
  run: (command) => runQuiet(command),
8316
8341
  latestVersion: () => latestMemo ??= fetchLatestVersion(),
8317
8342
  probeChromium: () => probeChromium(),
@@ -8551,8 +8576,8 @@ var init_updateCli = __esm({
8551
8576
 
8552
8577
  // src/cli.ts
8553
8578
  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";
8579
+ import { basename as basename7, dirname as dirname6, join as join32 } from "path";
8580
+ 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
8581
  import { setTimeout as sleep2 } from "timers/promises";
8557
8582
 
8558
8583
  // src/swarmClient.ts
@@ -9520,6 +9545,9 @@ var SwarmClient = class _SwarmClient {
9520
9545
  });
9521
9546
  if (!ask.length) return;
9522
9547
  for (const ref of ask) this.depsAskedAt.set(ref, nowMs);
9548
+ if (opts.force) {
9549
+ for (const ref of ask) if (this.depsProd.get(ref)?.releasedByTaskClose) this.depsProd.delete(ref);
9550
+ }
9523
9551
  let res;
9524
9552
  try {
9525
9553
  res = await this.call("swarm_deps_status", { refs: ask });
@@ -9539,13 +9567,15 @@ var SwarmClient = class _SwarmClient {
9539
9567
  if (!ref) continue;
9540
9568
  this.depsUnanswered.delete(ref);
9541
9569
  const outcome = String(d.outcome ?? "pending");
9542
- this.depsProd.set(ref, {
9570
+ const verdict = {
9543
9571
  outcome,
9544
9572
  met: Boolean(d.met),
9545
9573
  status: d.status ?? null,
9546
9574
  name: d.name ?? null,
9547
9575
  stopReason: d.stopReason ?? null
9548
- });
9576
+ };
9577
+ if (d.releasedByTaskClose === true) verdict.releasedByTaskClose = true;
9578
+ this.depsProd.set(ref, verdict);
9549
9579
  if (typeof d.slug === "string" && d.slug) this.depSlug.set(ref, d.slug);
9550
9580
  }
9551
9581
  }
@@ -11365,12 +11395,24 @@ var SwarmClient = class _SwarmClient {
11365
11395
  }
11366
11396
  };
11367
11397
  function parseDecision(v) {
11368
- if (!v || typeof v !== "string") return null;
11398
+ if (typeof v !== "string" || !v.trim()) return null;
11369
11399
  try {
11370
- return JSON.parse(v);
11400
+ const parsed = JSON.parse(v);
11401
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
11402
+ const row = parsed;
11403
+ if (typeof row.chosen === "string") {
11404
+ return {
11405
+ question: typeof row.question === "string" ? row.question : "",
11406
+ options: Array.isArray(row.options) ? row.options.filter((option) => typeof option === "string") : null,
11407
+ chosen: row.chosen,
11408
+ prior: typeof row.prior === "string" ? row.prior : null,
11409
+ priorState: typeof row.priorState === "string" ? row.priorState : ""
11410
+ };
11411
+ }
11412
+ }
11371
11413
  } catch {
11372
- return null;
11373
11414
  }
11415
+ return { question: "", options: null, chosen: v, prior: null, priorState: "" };
11374
11416
  }
11375
11417
 
11376
11418
  // src/cli.ts
@@ -11548,7 +11590,7 @@ function hostIdentityPath(home) {
11548
11590
  function loadHostIdentity(deps) {
11549
11591
  const exists = deps.exists ?? existsSync10;
11550
11592
  const readFile3 = deps.readFile ?? ((p) => readFileSync10(p, "utf8"));
11551
- const writeFile3 = deps.writeFile ?? ((p, data) => {
11593
+ const writeFile4 = deps.writeFile ?? ((p, data) => {
11552
11594
  writeFileSync8(`${p}.tmp`, data);
11553
11595
  renameSync4(`${p}.tmp`, p);
11554
11596
  });
@@ -11568,7 +11610,7 @@ function loadHostIdentity(deps) {
11568
11610
  }
11569
11611
  const hostId = newId();
11570
11612
  try {
11571
- writeFile3(path, JSON.stringify({ hostId, hostName, createdAt: (/* @__PURE__ */ new Date()).toISOString() }, null, 2));
11613
+ writeFile4(path, JSON.stringify({ hostId, hostName, createdAt: (/* @__PURE__ */ new Date()).toISOString() }, null, 2));
11572
11614
  } catch {
11573
11615
  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
11616
  }
@@ -11858,7 +11900,7 @@ init_resources();
11858
11900
  // src/gh.ts
11859
11901
  init_src();
11860
11902
  init_netTimeout();
11861
- import { $ as $4 } from "execa";
11903
+ import { $ as $5 } from "execa";
11862
11904
  import { basename as basename3 } from "path";
11863
11905
 
11864
11906
  // src/ghBudget.ts
@@ -11947,6 +11989,47 @@ var GH_MERGED_LOOKBACK_MS = 30 * 24 * 60 * 60 * 1e3;
11947
11989
 
11948
11990
  // src/reviewCycle.ts
11949
11991
  init_src();
11992
+
11993
+ // src/orchestrator.ts
11994
+ init_src();
11995
+ init_git();
11996
+
11997
+ // src/deps.ts
11998
+ import { existsSync as existsSync13, readdirSync as readdirSync10, readFileSync as readFileSync12 } from "fs";
11999
+ import { join as join17 } from "path";
12000
+ import { execa as execa2 } from "execa";
12001
+
12002
+ // src/boundedRun.ts
12003
+ init_procCleanup();
12004
+ import { spawn as spawn2 } from "child_process";
12005
+
12006
+ // src/prepareLock.ts
12007
+ import { createHash } from "crypto";
12008
+ import { closeSync as closeSync4, openSync as openSync4, rmSync, statSync as statSync11, writeSync as writeSync2 } from "fs";
12009
+ import { join as join15 } from "path";
12010
+ import { tmpdir } from "os";
12011
+ var WAIT_TIMEOUT_MS = 5 * 6e4;
12012
+ var STALE_MS = 20 * 6e4;
12013
+
12014
+ // src/deps.ts
12015
+ init_config();
12016
+
12017
+ // src/envCache.ts
12018
+ init_config();
12019
+ import { createHash as createHash2 } from "crypto";
12020
+ import { cp, link, lstat, mkdir as mkdir2, readdir, readlink, rename as rename2, rm as rm2, stat, symlink, utimes, writeFile as writeFile2 } from "fs/promises";
12021
+ import { existsSync as existsSync12, readFileSync as readFileSync11 } from "fs";
12022
+ import { join as join16 } from "path";
12023
+
12024
+ // src/deps.ts
12025
+ var PREPARE_TIMEOUT_MS = 15 * 6e4;
12026
+
12027
+ // src/orchestrator.ts
12028
+ init_config();
12029
+ import { existsSync as existsSync14, mkdirSync as mkdirSync9, rmSync as rmSync2 } from "fs";
12030
+ import { join as join18, dirname as dirname3 } from "path";
12031
+
12032
+ // src/reviewCycle.ts
11950
12033
  var REVIEW_CYCLE_LIMIT_DEFAULT = 3;
11951
12034
  var REVIEW_CYCLE_LIMIT_CAP = 20;
11952
12035
  function validReviewCycleLimit(n) {
@@ -11977,7 +12060,7 @@ async function runGh(args, timeoutMs, cwd) {
11977
12060
  const label2 = callLabel("gh", args) + (cwd ? ` (repo ${basename3(cwd)})` : "");
11978
12061
  const skipsPause = ghCallSkipsPause(args);
11979
12062
  if (!skipsPause && ghCallsPaused(Date.now())) throw new GhPausedError();
11980
- const child = cwd ? $4({ cwd, timeout: timeoutMs })`gh ${args}` : $4({ timeout: timeoutMs })`gh ${args}`;
12063
+ const child = cwd ? $5({ cwd, timeout: timeoutMs })`gh ${args}` : $5({ timeout: timeoutMs })`gh ${args}`;
11981
12064
  try {
11982
12065
  return (await withHardTimeout(child, "gh", label2, timeoutMs)).stdout;
11983
12066
  } catch (e) {
@@ -12190,7 +12273,7 @@ var GhCallFailedError = class extends Error {
12190
12273
  };
12191
12274
  var realChecksRunner = async (pr) => {
12192
12275
  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);
12276
+ const r = await withHardTimeout($5({ reject: false, timeout: 15e3 })`gh pr checks ${pr} --json state,name,bucket,link`, "gh", label2, 15e3);
12194
12277
  const stdout = r.stdout ?? "";
12195
12278
  const stderr = r.stderr ?? "";
12196
12279
  if (isTimedOut(r)) throw new GhCallFailedError(label2, classifyCallFailure(r));
@@ -14211,16 +14294,16 @@ import { cancelRun, respawnRun, runDaemon, wakeRun, OVERMIND_ENTRY, listDronePro
14211
14294
 
14212
14295
  // src/launcher.ts
14213
14296
  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";
14297
+ import { spawn as spawn3 } from "child_process";
14298
+ import { closeSync as closeSync5, existsSync as existsSync15, mkdirSync as mkdirSync12, openSync as openSync5, readdirSync as readdirSync12 } from "fs";
14216
14299
  import { createRequire } from "module";
14217
14300
  import { homedir as homedir6 } from "os";
14218
- import { basename as basename5, dirname as dirname4, join as join16 } from "path";
14301
+ import { basename as basename5, dirname as dirname5, join as join21 } from "path";
14219
14302
  import { fileURLToPath as fileURLToPath2 } from "url";
14220
14303
 
14221
14304
  // 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";
14305
+ import { lstatSync, mkdirSync as mkdirSync11, readdirSync as readdirSync11, rmSync as rmSync3, statSync as statSync12, symlinkSync as symlinkSync4 } from "fs";
14306
+ import { join as join20, relative, sep as sep3 } from "path";
14224
14307
  var DRONE_HOME_DENY_DEFAULT = [".taskless-swarm", ".bash_history", ".zsh_history"];
14225
14308
  function droneHomeDeny(env = process.env) {
14226
14309
  const extra = (env.SWARM_DRONE_HOME_DENY || "").split(",").map((s) => s.trim()).filter(Boolean);
@@ -14238,34 +14321,34 @@ function buildDroneHome(opts) {
14238
14321
  const { realHome, droneHome } = opts;
14239
14322
  const deny = opts.deny ?? droneHomeDeny();
14240
14323
  const platform = opts.platform ?? process.platform;
14241
- mkdirSync10(droneHome, { recursive: true, mode: 448 });
14242
- const wanted = new Set(mirroredEntries(readdirSync9(realHome), deny, platform));
14324
+ mkdirSync11(droneHome, { recursive: true, mode: 448 });
14325
+ const wanted = new Set(mirroredEntries(readdirSync11(realHome), deny, platform));
14243
14326
  const rel = relative(realHome, droneHome);
14244
- if (rel && !rel.startsWith("..") && !rel.includes(sep2)) wanted.delete(rel);
14245
- for (const existing of readdirSync9(droneHome)) {
14327
+ if (rel && !rel.startsWith("..") && !rel.includes(sep3)) wanted.delete(rel);
14328
+ for (const existing of readdirSync11(droneHome)) {
14246
14329
  if (wanted.has(existing)) continue;
14247
- const p = join15(droneHome, existing);
14330
+ const p = join20(droneHome, existing);
14248
14331
  try {
14249
- if (lstatSync(p).isSymbolicLink()) rmSync(p);
14332
+ if (lstatSync(p).isSymbolicLink()) rmSync3(p);
14250
14333
  } catch {
14251
14334
  }
14252
14335
  }
14253
14336
  for (const name of wanted) {
14254
- const link = join15(droneHome, name);
14337
+ const link2 = join20(droneHome, name);
14255
14338
  try {
14256
- lstatSync(link);
14339
+ lstatSync(link2);
14257
14340
  continue;
14258
14341
  } catch {
14259
14342
  }
14260
- const target = join15(realHome, name);
14343
+ const target = join20(realHome, name);
14261
14344
  let isDir;
14262
14345
  try {
14263
- isDir = statSync10(target).isDirectory();
14346
+ isDir = statSync12(target).isDirectory();
14264
14347
  } catch {
14265
14348
  continue;
14266
14349
  }
14267
14350
  try {
14268
- symlinkSync4(target, link, isDir ? "junction" : "file");
14351
+ symlinkSync4(target, link2, isDir ? "junction" : "file");
14269
14352
  } catch (e) {
14270
14353
  if (e.code !== "EEXIST") throw e;
14271
14354
  }
@@ -14278,7 +14361,7 @@ var REAL_PATH_ENV_PINS = [
14278
14361
  { env: "YARN_GLOBAL_FOLDER", segments: [".yarn", "berry"] }
14279
14362
  ];
14280
14363
  function realPathEnvPins(realHome) {
14281
- return Object.fromEntries(REAL_PATH_ENV_PINS.map(({ env, segments }) => [env, join15(realHome, ...segments)]));
14364
+ return Object.fromEntries(REAL_PATH_ENV_PINS.map(({ env, segments }) => [env, join20(realHome, ...segments)]));
14282
14365
  }
14283
14366
  function dronePrivatePaths(realHome, swarmHome) {
14284
14367
  return [
@@ -14376,7 +14459,7 @@ function droneEnv(worktree, base3 = process.env, isolation, droneCap = null) {
14376
14459
  const env = { ...base3, TASKLESS_SWARM_DRONE: "1" };
14377
14460
  const isolate = base3.SWARM_TURBO_ISOLATE !== "0";
14378
14461
  if (isolate && !base3.TURBO_CACHE_DIR) {
14379
- env.TURBO_CACHE_DIR = join16(worktree, ".turbo", "cache");
14462
+ env.TURBO_CACHE_DIR = join21(worktree, ".turbo", "cache");
14380
14463
  }
14381
14464
  if (!base3.COMPOSE_PROJECT_NAME) {
14382
14465
  const prefix = composeProjectPrefix(basename5(worktree));
@@ -14411,21 +14494,21 @@ var DAEMON_STATE_ENV = [
14411
14494
  ...PROVIDER_TOKEN_ENV
14412
14495
  ];
14413
14496
  function bundledRoleDir(kind) {
14414
- return join16(dirname4(fileURLToPath2(import.meta.url)), "..", "roles", kind);
14497
+ return join21(dirname5(fileURLToPath2(import.meta.url)), "..", "roles", kind);
14415
14498
  }
14416
14499
  function roleDir(worktree, kind) {
14417
- return join16(worktree, ".claude", "roles", kind);
14500
+ return join21(worktree, ".claude", "roles", kind);
14418
14501
  }
14419
14502
  function roleDirs(worktree, kind) {
14420
- return [bundledRoleDir(kind), roleDir(worktree, kind)].filter((dir) => existsSync11(dir));
14503
+ return [bundledRoleDir(kind), roleDir(worktree, kind)].filter((dir) => existsSync15(dir));
14421
14504
  }
14422
14505
  function nextRunLogPath(runLogsDir, runLogKeys) {
14423
14506
  const dir = runLogDirForWrite(runLogsDir, runLogKeys);
14424
14507
  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 });
14508
+ mkdirSync12(dir, { recursive: true });
14426
14509
  let files = [];
14427
14510
  try {
14428
- files = readdirSync10(dir);
14511
+ files = readdirSync12(dir);
14429
14512
  } catch {
14430
14513
  }
14431
14514
  let next = 0;
@@ -14433,21 +14516,21 @@ function nextRunLogPath(runLogsDir, runLogKeys) {
14433
14516
  const m = /^(\d+)\.json/.exec(f);
14434
14517
  if (m) next = Math.max(next, Number(m[1]) + 1);
14435
14518
  }
14436
- return join16(dir, `${next}.json`);
14519
+ return join21(dir, `${next}.json`);
14437
14520
  }
14438
14521
  function openNextRunLog(runLogsDir, runLogKeys) {
14439
14522
  for (let attempt = 0; attempt < 50; attempt++) {
14440
14523
  const path = nextRunLogPath(runLogsDir, runLogKeys);
14441
14524
  let out;
14442
14525
  try {
14443
- out = openSync4(path, "wx");
14526
+ out = openSync5(path, "wx");
14444
14527
  } catch (e) {
14445
14528
  if (e.code !== "EEXIST") throw e;
14446
14529
  continue;
14447
14530
  }
14448
14531
  let err = null;
14449
14532
  try {
14450
- err = openSync4(`${path.slice(0, -".json".length)}.err.log`, "w");
14533
+ err = openSync5(`${path.slice(0, -".json".length)}.err.log`, "w");
14451
14534
  } catch {
14452
14535
  err = null;
14453
14536
  }
@@ -14525,9 +14608,9 @@ function makeLauncher(cfg) {
14525
14608
  }
14526
14609
  const realHome = cfg.droneIsolation?.realHome ?? homedir6();
14527
14610
  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"))) {
14611
+ if (cfg.droneIsolation && process.env.TASKLESS_TOKEN && !existsSync15(join21(cfg.droneIsolation.swarmHome, "token"))) {
14529
14612
  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.`
14613
+ `[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
14614
  );
14532
14615
  }
14533
14616
  const executor = cfg.executor ?? executorForRun(run, cfg.swarmModels?.() ?? null);
@@ -14566,7 +14649,7 @@ function makeLauncher(cfg) {
14566
14649
  errFd = fds.err ?? void 0;
14567
14650
  stdio = ["ignore", outFd, errFd ?? "ignore"];
14568
14651
  }
14569
- const child = spawn2(cfg.bin ?? plan.bin, plan.args, {
14652
+ const child = spawn3(cfg.bin ?? plan.bin, plan.args, {
14570
14653
  cwd: worktree,
14571
14654
  detached: true,
14572
14655
  stdio,
@@ -14577,8 +14660,8 @@ function makeLauncher(cfg) {
14577
14660
  // они про его собственное состояние, и перебивать их ройным нечем.
14578
14661
  env: { ...droneEnv(worktree, process.env, home ? { droneHome: home, realHome } : void 0, cfg.droneCap?.() ?? null), ...plan.env }
14579
14662
  });
14580
- if (outFd !== void 0) closeSync4(outFd);
14581
- if (errFd !== void 0) closeSync4(errFd);
14663
+ if (outFd !== void 0) closeSync5(outFd);
14664
+ if (errFd !== void 0) closeSync5(errFd);
14582
14665
  child.unref();
14583
14666
  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
14667
  return child.pid;
@@ -14920,11 +15003,11 @@ init_names2();
14920
15003
  init_executors();
14921
15004
  init_claudeCode();
14922
15005
  init_workspace();
14923
- import { spawn as spawn3 } from "child_process";
15006
+ import { spawn as spawn4 } from "child_process";
14924
15007
 
14925
15008
  // src/login.ts
14926
15009
  init_taskless();
14927
- import { execa as execa2 } from "execa";
15010
+ import { execa as execa3 } from "execa";
14928
15011
  import { createServer } from "net";
14929
15012
  async function waitForLogin(d) {
14930
15013
  const deadline = d.now() + d.timeoutMs;
@@ -15037,7 +15120,7 @@ function parseWhoAmI(res) {
15037
15120
  async function openBrowser(url) {
15038
15121
  const [cmd2, args] = process.platform === "darwin" ? ["open", [url]] : process.platform === "win32" ? ["cmd", ["/c", "start", "", url]] : ["xdg-open", [url]];
15039
15122
  try {
15040
- await execa2(cmd2, args, { stdio: "ignore" });
15123
+ await execa3(cmd2, args, { stdio: "ignore" });
15041
15124
  return true;
15042
15125
  } catch {
15043
15126
  return false;
@@ -15458,7 +15541,7 @@ async function runDaemonLogs(argv) {
15458
15541
  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
15542
  return 1;
15460
15543
  }
15461
- if (!existsSync19(DAEMON_LOG_PATH)) {
15544
+ if (!existsSync22(DAEMON_LOG_PATH)) {
15462
15545
  console.error(`\u043B\u043E\u0433\u0430 \u0434\u0435\u043C\u043E\u043D\u0430 \u043D\u0435\u0442: ${DAEMON_LOG_PATH}`);
15463
15546
  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
15547
  return 1;
@@ -15466,25 +15549,25 @@ async function runDaemonLogs(argv) {
15466
15549
  const head = tailFile(DAEMON_LOG_PATH, lines);
15467
15550
  if (head) console.log(head);
15468
15551
  if (!follow) return 0;
15469
- let pos = statSync13(DAEMON_LOG_PATH).size;
15552
+ let pos = statSync14(DAEMON_LOG_PATH).size;
15470
15553
  for (; ; ) {
15471
15554
  await sleep2(500);
15472
15555
  let size;
15473
15556
  try {
15474
- size = statSync13(DAEMON_LOG_PATH).size;
15557
+ size = statSync14(DAEMON_LOG_PATH).size;
15475
15558
  } catch {
15476
15559
  continue;
15477
15560
  }
15478
15561
  if (size < pos) pos = 0;
15479
15562
  if (size === pos) continue;
15480
- const fd = openSync5(DAEMON_LOG_PATH, "r");
15563
+ const fd = openSync6(DAEMON_LOG_PATH, "r");
15481
15564
  try {
15482
15565
  const buf = Buffer.alloc(size - pos);
15483
15566
  const read = readSync2(fd, buf, 0, buf.length, pos);
15484
15567
  process.stdout.write(buf.subarray(0, read).toString("utf8"));
15485
15568
  pos += read;
15486
15569
  } finally {
15487
- closeSync5(fd);
15570
+ closeSync6(fd);
15488
15571
  }
15489
15572
  }
15490
15573
  }
@@ -15740,10 +15823,10 @@ function effectiveWorktreesDir() {
15740
15823
  legacyDir: WORKTREES_LEGACY_DIR,
15741
15824
  targetDir: WORKTREES_DIR,
15742
15825
  envOverride: process.env.SWARM_WORKTREES || "",
15743
- exists: (d) => existsSync19(d),
15826
+ exists: (d) => existsSync22(d),
15744
15827
  isNonEmptyDir: (d) => {
15745
15828
  try {
15746
- return readdirSync13(d).length > 0;
15829
+ return readdirSync14(d).length > 0;
15747
15830
  } catch {
15748
15831
  return false;
15749
15832
  }
@@ -15799,18 +15882,18 @@ async function scoutRepo(repo) {
15799
15882
  await $6({ reject: false })`git -C ${worktree} reset --hard ${baseRef}`;
15800
15883
  }
15801
15884
  await setWorktreeIdentity(worktree, name);
15802
- const abs = (rel) => join28(worktree, rel);
15885
+ const abs = (rel) => join32(worktree, rel);
15803
15886
  const code = await runRepoScout({
15804
15887
  repoFullName,
15805
15888
  repoPath: worktree,
15806
15889
  name,
15807
- readFile: (rel) => existsSync19(abs(rel)) ? readFileSync21(abs(rel), "utf8") : null,
15890
+ readFile: (rel) => existsSync22(abs(rel)) ? readFileSync23(abs(rel), "utf8") : null,
15808
15891
  writeFile: (rel, text) => {
15809
- mkdirSync12(dirname5(abs(rel)), { recursive: true });
15892
+ mkdirSync13(dirname6(abs(rel)), { recursive: true });
15810
15893
  writeFileSync16(abs(rel), text);
15811
15894
  },
15812
15895
  runScout: (prompt) => new Promise((resolve6) => {
15813
- const child = spawn3(bin, [...ISOLATION_FLAGS, "--dangerously-skip-permissions", "-p", prompt], {
15896
+ const child = spawn4(bin, [...ISOLATION_FLAGS, "--dangerously-skip-permissions", "-p", prompt], {
15814
15897
  cwd: worktree,
15815
15898
  stdio: ["ignore", "inherit", "inherit"]
15816
15899
  // человек смотрит на разведку живьём