@taskless-app/swarm 0.6.110 → 0.6.112

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
@@ -2926,7 +2926,7 @@ function extractJsonObject(raw) {
2926
2926
  }
2927
2927
  return null;
2928
2928
  }
2929
- var GROK_SWARM_TOOL_TIMEOUT_SEC, grokExecutor;
2929
+ var GROK_SWARM_TOOL_TIMEOUT_SEC, GROK_POLICY_TOML, grokExecutor;
2930
2930
  var init_grok = __esm({
2931
2931
  "src/executors/grok.ts"() {
2932
2932
  "use strict";
@@ -2935,6 +2935,7 @@ var init_grok = __esm({
2935
2935
  init_swarmFiles();
2936
2936
  init_codex();
2937
2937
  GROK_SWARM_TOOL_TIMEOUT_SEC = 7 * 24 * 60 * 60;
2938
+ GROK_POLICY_TOML = ["allow_managed_hooks_only = true", "enable_all_project_mcp_servers = false", ""].join("\n");
2938
2939
  grokExecutor = {
2939
2940
  id: "grok",
2940
2941
  title: "Grok CLI (grok)",
@@ -2949,6 +2950,7 @@ var init_grok = __esm({
2949
2950
  plan: (spec) => {
2950
2951
  const home = ensureGrokHome(spec.worktree, spec.realHome);
2951
2952
  writeFileSync3(join6(home, "config.toml"), grokMcpToml(spec));
2953
+ writeFileSync3(join6(home, "managed_config.toml"), GROK_POLICY_TOML);
2952
2954
  writeFileSync3(
2953
2955
  join6(spec.worktree, SWARM_MCP_CONFIG_FILE),
2954
2956
  JSON.stringify(
@@ -2970,6 +2972,8 @@ ${notice}` : spec.prompt;
2970
2972
  "--output-format",
2971
2973
  "json",
2972
2974
  "--yolo",
2975
+ // Скрытый флаг: в `grok --help` его нет, но 1.0.92 его принимает.
2976
+ "--trust",
2973
2977
  ...spec.continueSession ? ["--continue"] : [],
2974
2978
  ...modelArgs(spec.model),
2975
2979
  ...spec.effort ? ["--effort", spec.effort] : [],
@@ -4524,7 +4528,7 @@ var init_package = __esm({
4524
4528
  "package.json"() {
4525
4529
  package_default = {
4526
4530
  name: "@taskless-app/swarm",
4527
- version: "0.6.110",
4531
+ version: "0.6.112",
4528
4532
  type: "module",
4529
4533
  description: "Local control plane for a fleet of AI coding agents (drones), coordinating through Taskless. The overmind runs the swarm.",
4530
4534
  keywords: [
@@ -4576,7 +4580,7 @@ var init_package = __esm({
4576
4580
  undici: "^7.30.1",
4577
4581
  zod: "3.25.76"
4578
4582
  },
4579
- gitHead: "195231b0b9a3429f4752aa9977020e1bb364ca95"
4583
+ gitHead: "56961ce59a886cc0dd233e313151622391d133cc"
4580
4584
  };
4581
4585
  }
4582
4586
  });
@@ -6427,6 +6431,7 @@ CREATE TABLE IF NOT EXISTS imports (
6427
6431
  const arr = v;
6428
6432
  return arr && arr.length ? JSON.stringify(arr) : null;
6429
6433
  }
6434
+ if (f === "decision") return v ? JSON.stringify(v) : null;
6430
6435
  if (f === "repoless") return v === true ? 1 : v === false ? 0 : null;
6431
6436
  if (f === "area" && typeof v === "string") return normalizeZoneLabel(v) || null;
6432
6437
  return v;
@@ -8674,7 +8679,7 @@ var init_updateCli = __esm({
8674
8679
  init_cliIo();
8675
8680
  import { basename as basename7, dirname as dirname6, join as join32 } from "path";
8676
8681
  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";
8677
- import { setTimeout as sleep2 } from "timers/promises";
8682
+ import { setTimeout as sleep3 } from "timers/promises";
8678
8683
 
8679
8684
  // src/swarmClient.ts
8680
8685
  init_config();
@@ -9028,6 +9033,8 @@ var SwarmClient = class _SwarmClient {
9028
9033
  stormPath;
9029
9034
  // durable-сайдкар глобальных (штормовых) событий
9030
9035
  pending = [];
9036
+ /** TASWM-694: id, чья последняя refreshRun не дошла до прода. */
9037
+ missedProd = /* @__PURE__ */ new Set();
9031
9038
  nextSeq = 1;
9032
9039
  flushing = false;
9033
9040
  flushTimer = null;
@@ -9767,20 +9774,34 @@ var SwarmClient = class _SwarmClient {
9767
9774
  if (!d) return null;
9768
9775
  const prodId = this.prodIdByKey.get(d.runKey);
9769
9776
  if (!prodId) return this.mat(d);
9770
- if (this.pending.some((e) => e.t === "run" && e.runKey === d.runKey)) return this.mat(d);
9777
+ const pendingFields = unflushedRunFields(this.pending, d.runKey);
9771
9778
  let res;
9772
9779
  try {
9773
9780
  res = await this.call("swarm_list_runs", { taskId: d.task_slug, view: "full" });
9774
9781
  } catch {
9782
+ this.missedProd.add(id);
9783
+ return this.mat(d);
9784
+ }
9785
+ if (res?.isError) {
9786
+ this.missedProd.add(id);
9775
9787
  return this.mat(d);
9776
9788
  }
9777
- if (res?.isError) return this.mat(d);
9778
9789
  const rows = res.structuredContent?.runs ?? [];
9779
9790
  const row = rows.find((r) => String(r.id ?? "") === prodId);
9780
- if (!row) return this.mat(d);
9791
+ if (!row) {
9792
+ this.missedProd.delete(id);
9793
+ return this.mat(d);
9794
+ }
9795
+ const saved = pendingFields ? snapshotUnflushedRun(d, pendingFields) : null;
9781
9796
  const local = this.hydrateRun(row);
9797
+ if (local && saved) restoreUnflushedRun(local, saved);
9798
+ if (local) this.missedProd.delete(id);
9782
9799
  return local ? this.mat(local) : null;
9783
9800
  }
9801
+ /** TASWM-694: true, пока последняя сверка этого id не дошла до прода. */
9802
+ refreshMissedProd(id) {
9803
+ return this.missedProd.has(id);
9804
+ }
9784
9805
  distinctRepos() {
9785
9806
  const seen = /* @__PURE__ */ new Set();
9786
9807
  for (const r of this.runs.values()) if (r.repo) seen.add(r.repo);
@@ -11497,6 +11518,60 @@ var SwarmClient = class _SwarmClient {
11497
11518
  void this.flush();
11498
11519
  }
11499
11520
  };
11521
+ var OUTBOX_RUN_FIELD = {
11522
+ status: "status",
11523
+ area: "area",
11524
+ model: "model",
11525
+ reviewModel: "review_model",
11526
+ effort: "effort",
11527
+ droneName: "name",
11528
+ costUsd: "cost_usd",
11529
+ tokensIn: "tokens_in",
11530
+ tokensOut: "tokens_out",
11531
+ durationMs: "duration_ms",
11532
+ costUnmeasured: "cost_unmeasured",
11533
+ respawns: "respawns",
11534
+ prUrl: "pr_url",
11535
+ changedPaths: "changed_paths",
11536
+ branch: "branch",
11537
+ repo: "repo",
11538
+ stopReason: "stop_reason",
11539
+ returnReason: "return_reason",
11540
+ dependsOn: "depends_on",
11541
+ decision: "decision",
11542
+ role: "kind",
11543
+ reviewVerdict: "review_verdict",
11544
+ verifyVerdict: "verify_verdict",
11545
+ hostId: "host_id",
11546
+ hostPinned: "host_pinned",
11547
+ reviewPhase: "review_phase",
11548
+ baseBranch: "base_branch",
11549
+ heroId: "hero_run_id",
11550
+ resolvesRunId: "resolves_run_id",
11551
+ supersededById: "superseded_by",
11552
+ reviewsRunId: "reviews_run_id",
11553
+ verifiesRunId: "verifies_run_id"
11554
+ };
11555
+ function unflushedRunFields(pending2, runKey) {
11556
+ let merged = null;
11557
+ for (const e of pending2) {
11558
+ if (e.t !== "run" || e.runKey !== runKey) continue;
11559
+ merged = Object.assign(merged ?? {}, e.fields);
11560
+ }
11561
+ return merged;
11562
+ }
11563
+ function snapshotUnflushedRun(run, fields) {
11564
+ const saved = /* @__PURE__ */ new Map();
11565
+ for (const key of Object.keys(fields)) {
11566
+ const local = OUTBOX_RUN_FIELD[key];
11567
+ if (!local || saved.has(local)) continue;
11568
+ saved.set(local, run[local]);
11569
+ }
11570
+ return saved;
11571
+ }
11572
+ function restoreUnflushedRun(run, saved) {
11573
+ for (const [key, value] of saved) run[key] = value;
11574
+ }
11500
11575
  function parseDecision(v) {
11501
11576
  if (typeof v !== "string" || !v.trim()) return null;
11502
11577
  try {
@@ -11541,13 +11616,13 @@ function tailText(text, lines) {
11541
11616
  }
11542
11617
  async function waitForReady(opts) {
11543
11618
  const now = opts.now ?? Date.now;
11544
- const sleep3 = opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
11619
+ const sleep4 = opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
11545
11620
  const started = now();
11546
11621
  for (; ; ) {
11547
11622
  if (await opts.probe()) return "ready";
11548
11623
  if (!opts.alive()) return "died";
11549
11624
  if (now() - started >= opts.timeoutMs) return "timeout";
11550
- await sleep3(opts.pollMs);
11625
+ await sleep4(opts.pollMs);
11551
11626
  }
11552
11627
  }
11553
11628
  function launchDetached(opts) {
@@ -14758,7 +14833,7 @@ function resilientSwarmMcp(opts = {}) {
14758
14833
  const backoff = opts.backoffMs?.length ? opts.backoffMs : DEFAULT_BACKOFF_MS;
14759
14834
  const downAfterMs = opts.downAfterMs ?? DEFAULT_DOWN_AFTER_MS;
14760
14835
  const retryDelays = opts.retryDelaysMs ?? DEFAULT_RETRY_DELAYS_MS;
14761
- const sleep3 = opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
14836
+ const sleep4 = opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
14762
14837
  const clock = opts.now ?? Date.now;
14763
14838
  const passBudgetMs = opts.passBudgetMs ?? PROD_PASS_BUDGET_MS;
14764
14839
  let passSpentMs = null;
@@ -14846,7 +14921,7 @@ function resilientSwarmMcp(opts = {}) {
14846
14921
  return errorResult(reason, kind === "offline" || kind === "unknown" || kind === "unauthorized" || isProdTimeout(e));
14847
14922
  }
14848
14923
  opts.onRetry?.({ tool: name, attempt: attempt + 1, reason });
14849
- await sleep3(delay);
14924
+ await sleep4(delay);
14850
14925
  }
14851
14926
  }
14852
14927
  };
@@ -15298,6 +15373,485 @@ async function runShotCli(argv, deps = {}) {
15298
15373
  }
15299
15374
  }
15300
15375
 
15376
+ // src/watch.ts
15377
+ init_linkFailure();
15378
+ init_taskless();
15379
+ import { writeSync as writeSync3 } from "fs";
15380
+ import { setTimeout as sleep2 } from "timers/promises";
15381
+ var WATCH_NETWORK_DOWN_MS = 5 * 60 * 1e3;
15382
+ var WATCH_RETRY_MS = 1e3;
15383
+ var WATCH_RETRY_MAX_MS = 15e3;
15384
+ var FEED_HANDSHAKE_MS = 2e4;
15385
+ var FEED_IDLE_MS = 9e4;
15386
+ var AGENT_FORBIDDEN_LINE = "swarm_watch \u043D\u0435\u0434\u043E\u0441\u0442\u0443\u043F\u0435\u043D \u0442\u043E\u043A\u0435\u043D\u0443 \u0430\u043A\u043A\u0430\u0443\u043D\u0442\u0430-\u0430\u0433\u0435\u043D\u0442\u0430. \u0412\u043E\u0437\u044C\u043C\u0438 \u0430\u0434\u0440\u0435\u0441 \u0441\u0432\u043E\u0438\u043C \u0432\u044B\u0437\u043E\u0432\u043E\u043C swarm_watch \u0438 \u0437\u0430\u043F\u0443\u0441\u0442\u0438 swarm watch --url <\u0430\u0434\u0440\u0435\u0441>. \u0410\u0434\u0440\u0435\u0441 \u2014 \u0441\u0435\u043A\u0440\u0435\u0442, \u0432 \u0432\u044B\u0432\u043E\u0434 \u0435\u0433\u043E \u043D\u0435 \u043A\u043E\u043F\u0438\u0440\u0443\u0439.";
15387
+ var WATCH_BACKGROUND_HINT = "\u0437\u0430\u043F\u0443\u0441\u0442\u0438 \u0444\u043E\u043D\u043E\u043C \u0438 \u043F\u0440\u043E\u0447\u0438\u0442\u0430\u0439 \u0432\u044B\u0432\u043E\u0434, \u043A\u043E\u0433\u0434\u0430 \u043A\u043E\u043C\u0430\u043D\u0434\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u0441\u044F \u2014 \u043F\u0435\u0440\u0432\u0430\u044F \u0441\u0442\u0440\u043E\u043A\u0430 \u0438 \u0435\u0441\u0442\u044C \u0434\u0435\u043B\u043E";
15388
+ var WatchDown = class extends Error {
15389
+ constructor(message) {
15390
+ super(message);
15391
+ this.name = "WatchDown";
15392
+ }
15393
+ };
15394
+ var WatchGaveUp = class extends Error {
15395
+ constructor(message) {
15396
+ super(message);
15397
+ this.name = "WatchGaveUp";
15398
+ }
15399
+ };
15400
+ var WatchAbort = class extends Error {
15401
+ constructor() {
15402
+ super("\u043E\u0441\u0442\u0430\u043D\u043E\u0432\u043B\u0435\u043D\u043E");
15403
+ this.name = "WatchAbort";
15404
+ }
15405
+ };
15406
+ var STALE_ERRORS = /* @__PURE__ */ new Set(["token_expired", "invalid_token", "password_reset"]);
15407
+ function isRepoRef(name) {
15408
+ const slash = name.indexOf("/");
15409
+ if (slash <= 0 || name.indexOf("/", slash + 1) !== -1) return false;
15410
+ const owner = name.slice(0, slash);
15411
+ const repo = name.slice(slash + 1);
15412
+ if (!/^[A-Za-z0-9][A-Za-z0-9-]{0,38}$/.test(owner)) return false;
15413
+ if (!/^[A-Za-z0-9._-]{1,100}$/.test(repo) || /^\.+$/.test(repo)) return false;
15414
+ return true;
15415
+ }
15416
+ function parseRepoList(raw) {
15417
+ const items = raw.split(",").map((part) => part.trim()).filter((part) => part.length > 0);
15418
+ if (items.length === 0) return { ok: false };
15419
+ const seen = /* @__PURE__ */ new Set();
15420
+ for (const item of items) {
15421
+ if (!isRepoRef(item)) return { ok: false };
15422
+ seen.add(item.toLowerCase());
15423
+ }
15424
+ return { ok: true, repos: [...seen].sort() };
15425
+ }
15426
+ function parseWatchArgs(argv) {
15427
+ const repos = [];
15428
+ let url = null;
15429
+ let stream = false;
15430
+ let sawRepos = false;
15431
+ for (let i = 0; i < argv.length; i++) {
15432
+ const arg = argv[i] ?? "";
15433
+ if (arg === "--stream") {
15434
+ stream = true;
15435
+ continue;
15436
+ }
15437
+ if (arg === "--repos") {
15438
+ if (sawRepos) return { ok: false, error: "\u0444\u043B\u0430\u0433 --repos \u0437\u0430\u0434\u0430\u0451\u0442\u0441\u044F \u043E\u0434\u0438\u043D \u0440\u0430\u0437" };
15439
+ sawRepos = true;
15440
+ const raw = argv[++i];
15441
+ if (!raw || raw.startsWith("--")) return { ok: false, error: "\u043F\u043E\u0441\u043B\u0435 --repos \u043D\u0443\u0436\u0435\u043D \u0441\u043F\u0438\u0441\u043E\u043A owner/repo \u0447\u0435\u0440\u0435\u0437 \u0437\u0430\u043F\u044F\u0442\u0443\u044E" };
15442
+ const parsed = parseRepoList(raw);
15443
+ if (!parsed.ok) return { ok: false, error: "\u0444\u0438\u043B\u044C\u0442\u0440 --repos: \u043D\u0443\u0436\u043D\u043E owner/repo \u0447\u0435\u0440\u0435\u0437 \u0437\u0430\u043F\u044F\u0442\u0443\u044E" };
15444
+ repos.push(...parsed.repos);
15445
+ continue;
15446
+ }
15447
+ if (arg === "--url") {
15448
+ if (url) return { ok: false, error: "\u0444\u043B\u0430\u0433 --url \u0437\u0430\u0434\u0430\u0451\u0442\u0441\u044F \u043E\u0434\u0438\u043D \u0440\u0430\u0437" };
15449
+ const raw = argv[++i];
15450
+ if (!raw || raw.startsWith("--")) return { ok: false, error: "\u043F\u043E\u0441\u043B\u0435 --url \u043D\u0443\u0436\u0435\u043D \u0430\u0434\u0440\u0435\u0441 \u043B\u0435\u043D\u0442\u044B" };
15451
+ if (!/^https?:\/\//i.test(raw)) return { ok: false, error: "\u0430\u0434\u0440\u0435\u0441 \u043B\u0435\u043D\u0442\u044B \u0434\u043E\u043B\u0436\u0435\u043D \u043D\u0430\u0447\u0438\u043D\u0430\u0442\u044C\u0441\u044F \u0441 http:// \u0438\u043B\u0438 https://" };
15452
+ url = raw;
15453
+ continue;
15454
+ }
15455
+ return { ok: false, error: "\u043D\u0435 \u043F\u043E\u043D\u044F\u043B \u0430\u0440\u0433\u0443\u043C\u0435\u043D\u0442. \u041D\u0443\u0436\u043D\u043E: swarm watch [--repos owner/repo,\u2026] [--url <\u0430\u0434\u0440\u0435\u0441>] [--stream]" };
15456
+ }
15457
+ return { ok: true, repos, url, stream };
15458
+ }
15459
+ function redactFeedSecrets(text, secrets) {
15460
+ let out = text;
15461
+ const values = secrets.filter((secret) => secret.length >= 6).sort((a, b) => b.length - a.length);
15462
+ for (const secret of values) {
15463
+ if (out.includes(secret)) out = out.split(secret).join("\u2026");
15464
+ }
15465
+ return out.replace(/([?&](?:token|access_token)=)[^&\s"'<>]+/gi, "$1\u2026").replace(/\btlswarm_[A-Za-z0-9._-]+/g, "tlswarm_\u2026");
15466
+ }
15467
+ function toolText(res) {
15468
+ return (res.content ?? []).map((part) => part.text ?? "").filter((part) => part.length > 0).join(" ").trim();
15469
+ }
15470
+ function sseUrlFromWatchResult(res) {
15471
+ const text = toolText(res);
15472
+ if (res.unavailable) {
15473
+ const link2 = explainLinkFailure(text || "fetch failed");
15474
+ throw new WatchDown(redactFeedSecrets(link2.detail, []));
15475
+ }
15476
+ if (res.isError) {
15477
+ if (/agent_forbidden/.test(text)) throw new WatchGaveUp(AGENT_FORBIDDEN_LINE);
15478
+ const link2 = explainLinkFailure(text || "swarm_watch \u043E\u0442\u043A\u0430\u0437\u0430\u043B");
15479
+ if (link2.kind === "offline") throw new WatchDown(redactFeedSecrets(link2.detail, []));
15480
+ throw new WatchGaveUp(redactFeedSecrets(text || link2.detail, []));
15481
+ }
15482
+ const sse = res.structuredContent?.sseUrl;
15483
+ if (typeof sse !== "string" || sse.length === 0) throw new WatchGaveUp("swarm_watch \u043D\u0435 \u0432\u0435\u0440\u043D\u0443\u043B \u0430\u0434\u0440\u0435\u0441 \u043B\u0435\u043D\u0442\u044B");
15484
+ return sse;
15485
+ }
15486
+ async function obtainFeedUrl(repos, call) {
15487
+ const caller = call ?? await connectSwarmMcp();
15488
+ if (!caller) {
15489
+ const why = lastSwarmConnectFailure() ?? "\u043D\u0435\u0442 \u0442\u043E\u043A\u0435\u043D\u0430 \u0440\u043E\u044F \u2014 swarm login \u0438\u043B\u0438 swarm watch --url <\u0430\u0434\u0440\u0435\u0441>";
15490
+ const link2 = explainLinkFailure(why);
15491
+ if (link2.kind === "offline") throw new WatchDown(redactFeedSecrets(link2.detail, []));
15492
+ throw new WatchGaveUp(redactFeedSecrets(why, []));
15493
+ }
15494
+ let res;
15495
+ try {
15496
+ res = await caller("swarm_watch", repos.length > 0 ? { repos: [...repos] } : {});
15497
+ } catch (e) {
15498
+ const link2 = explainLinkFailure(e);
15499
+ if (link2.kind === "offline") throw new WatchDown(redactFeedSecrets(link2.detail, []));
15500
+ throw new WatchGaveUp(redactFeedSecrets(link2.detail, []));
15501
+ }
15502
+ return sseUrlFromWatchResult(res);
15503
+ }
15504
+ var SseParser = class {
15505
+ buf = "";
15506
+ push(chunk) {
15507
+ this.buf += chunk.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
15508
+ const out = [];
15509
+ while (true) {
15510
+ const idx = this.buf.indexOf("\n\n");
15511
+ if (idx < 0) break;
15512
+ const raw = this.buf.slice(0, idx);
15513
+ this.buf = this.buf.slice(idx + 2);
15514
+ const ev = parseBlock(raw);
15515
+ if (ev) out.push(ev);
15516
+ }
15517
+ return out;
15518
+ }
15519
+ };
15520
+ function parseBlock(raw) {
15521
+ let event = "message";
15522
+ const data = [];
15523
+ let comment = false;
15524
+ for (const line of raw.split("\n")) {
15525
+ if (line.length === 0 || line.startsWith(":")) {
15526
+ if (line.startsWith(":")) comment = true;
15527
+ continue;
15528
+ }
15529
+ if (line.startsWith("event:")) event = line.slice(6).trim();
15530
+ else if (line.startsWith("data:")) data.push(line.slice(5).replace(/^ /, ""));
15531
+ }
15532
+ if (data.length === 0) return comment ? { kind: "life" } : null;
15533
+ let json;
15534
+ try {
15535
+ json = JSON.parse(data.join("\n"));
15536
+ } catch {
15537
+ return null;
15538
+ }
15539
+ if (!json || typeof json !== "object") return null;
15540
+ const rec = json;
15541
+ const error = typeof rec.error === "string" ? rec.error : event === "error" ? "error" : "";
15542
+ if (error) {
15543
+ const message = typeof rec.message === "string" && rec.message.trim() ? rec.message.trim() : error;
15544
+ if (STALE_ERRORS.has(error)) return { kind: "stale", message };
15545
+ return { kind: "down", message };
15546
+ }
15547
+ if (typeof rec.text === "string" && rec.text.trim()) return { kind: "item", text: rec.text };
15548
+ return null;
15549
+ }
15550
+ function errorMessage(body, fallback) {
15551
+ try {
15552
+ const json = JSON.parse(body);
15553
+ if (typeof json.message === "string" && json.message.trim()) return json.message.trim();
15554
+ if (typeof json.error === "string" && json.error.trim()) return json.error.trim();
15555
+ } catch {
15556
+ }
15557
+ const text = body.replace(/\s+/g, " ").trim();
15558
+ if (!text || text.length > 300) return fallback;
15559
+ return text;
15560
+ }
15561
+ function oneLine(text) {
15562
+ return text.replace(/\r\n|[\r\n]/g, " ").trim();
15563
+ }
15564
+ async function connectFeed(url, signal, idleMs = FEED_IDLE_MS) {
15565
+ if (signal.aborted) throw new WatchAbort();
15566
+ const ctrl = new AbortController();
15567
+ const onAbort = () => ctrl.abort();
15568
+ signal.addEventListener("abort", onAbort);
15569
+ let gotHeaders = false;
15570
+ const timer = setTimeout(() => {
15571
+ if (!gotHeaders) ctrl.abort();
15572
+ }, FEED_HANDSHAKE_MS);
15573
+ const detach = () => {
15574
+ clearTimeout(timer);
15575
+ signal.removeEventListener("abort", onAbort);
15576
+ };
15577
+ const down = (e) => {
15578
+ if (signal.aborted) throw new WatchAbort();
15579
+ throw new WatchDown(redactFeedSecrets(describeError(e), [url]));
15580
+ };
15581
+ try {
15582
+ const res = await fetch(url, {
15583
+ headers: { accept: "text/event-stream" },
15584
+ redirect: "manual",
15585
+ signal: ctrl.signal
15586
+ });
15587
+ gotHeaders = true;
15588
+ clearTimeout(timer);
15589
+ const reader = res.body?.getReader() ?? null;
15590
+ const decoder = new TextDecoder();
15591
+ let flushed = false;
15592
+ const read = async () => {
15593
+ if (signal.aborted) throw new WatchAbort();
15594
+ if (!reader) return null;
15595
+ let idleHit = false;
15596
+ let idle;
15597
+ try {
15598
+ const chunk = await new Promise((resolve6, reject) => {
15599
+ idle = setTimeout(() => {
15600
+ idleHit = true;
15601
+ ctrl.abort();
15602
+ void reader.cancel().catch(() => {
15603
+ });
15604
+ reject(new WatchDown("\u043B\u0435\u043D\u0442\u0430 \u043C\u043E\u043B\u0447\u0438\u0442"));
15605
+ }, idleMs);
15606
+ reader.read().then(resolve6, reject);
15607
+ });
15608
+ if (chunk.done) {
15609
+ if (flushed) return null;
15610
+ flushed = true;
15611
+ const tail = decoder.decode();
15612
+ return tail.length > 0 ? tail : null;
15613
+ }
15614
+ return decoder.decode(chunk.value, { stream: true });
15615
+ } catch (e) {
15616
+ if (idleHit && !signal.aborted) throw new WatchDown("\u043B\u0435\u043D\u0442\u0430 \u043C\u043E\u043B\u0447\u0438\u0442");
15617
+ if (e instanceof WatchAbort || e instanceof WatchDown) throw e;
15618
+ return down(e);
15619
+ } finally {
15620
+ if (idle) clearTimeout(idle);
15621
+ }
15622
+ };
15623
+ const text = async () => {
15624
+ let out = "";
15625
+ while (out.length < 4096) {
15626
+ const chunk = await read();
15627
+ if (chunk === null) break;
15628
+ out += chunk;
15629
+ }
15630
+ return out;
15631
+ };
15632
+ return {
15633
+ status: res.status,
15634
+ read,
15635
+ text,
15636
+ close() {
15637
+ detach();
15638
+ ctrl.abort();
15639
+ void reader?.cancel().catch(() => {
15640
+ });
15641
+ }
15642
+ };
15643
+ } catch (e) {
15644
+ detach();
15645
+ if (e instanceof WatchAbort || e instanceof WatchDown) throw e;
15646
+ return down(e);
15647
+ }
15648
+ }
15649
+ async function runWatch(args, io) {
15650
+ const signal = args.signal ?? new AbortController().signal;
15651
+ const secrets = [];
15652
+ const hide = (text) => redactFeedSecrets(text, secrets);
15653
+ const remember = (url2) => {
15654
+ secrets.push(url2);
15655
+ try {
15656
+ const token = new URL(url2).searchParams.get("token");
15657
+ if (token) secrets.push(token);
15658
+ } catch {
15659
+ }
15660
+ };
15661
+ let url = args.url;
15662
+ if (url) remember(url);
15663
+ let refreshed = false;
15664
+ let delay = WATCH_RETRY_MS;
15665
+ let downSince = null;
15666
+ const giveUpDown = (cause) => {
15667
+ const t = io.now();
15668
+ if (downSince === null) downSince = t;
15669
+ if (t - downSince >= WATCH_NETWORK_DOWN_MS) {
15670
+ io.writeError(`\u0441\u0435\u0442\u044C \u043D\u0435\u0434\u043E\u0441\u0442\u0443\u043F\u043D\u0430 \u0434\u043E\u043B\u044C\u0448\u0435 5 \u043C\u0438\u043D\u0443\u0442: ${hide(cause)}`);
15671
+ return 2;
15672
+ }
15673
+ return null;
15674
+ };
15675
+ const paused = async () => {
15676
+ if (signal.aborted) throw new WatchAbort();
15677
+ await io.sleep(delay);
15678
+ if (signal.aborted) throw new WatchAbort();
15679
+ delay = Math.min(delay * 2, WATCH_RETRY_MAX_MS);
15680
+ };
15681
+ const takeError = (e) => {
15682
+ if (e instanceof WatchAbort || e instanceof WatchDown || e instanceof WatchGaveUp) return e;
15683
+ if (signal.aborted) return new WatchAbort();
15684
+ const link2 = explainLinkFailure(e);
15685
+ if (link2.kind === "offline") return new WatchDown(link2.detail);
15686
+ return new WatchGaveUp(link2.detail);
15687
+ };
15688
+ try {
15689
+ while (!signal.aborted) {
15690
+ if (!url) {
15691
+ try {
15692
+ url = await io.obtainUrl(args.repos);
15693
+ remember(url);
15694
+ refreshed = true;
15695
+ } catch (e) {
15696
+ const err = takeError(e);
15697
+ if (err instanceof WatchAbort) return 130;
15698
+ if (err instanceof WatchGaveUp) {
15699
+ io.writeError(hide(err.message));
15700
+ return 2;
15701
+ }
15702
+ const code = giveUpDown(err.message);
15703
+ if (code) return code;
15704
+ await paused();
15705
+ continue;
15706
+ }
15707
+ }
15708
+ let step = "pause";
15709
+ let cause = "\u0441\u043E\u0435\u0434\u0438\u043D\u0435\u043D\u0438\u0435 \u043E\u0431\u043E\u0440\u0432\u0430\u043B\u043E\u0441\u044C";
15710
+ let exit;
15711
+ let clearUrl = false;
15712
+ let body = null;
15713
+ try {
15714
+ body = await io.connect(url, signal);
15715
+ if (body.status === 401) {
15716
+ const message = errorMessage(await body.text(), "\u0430\u0434\u0440\u0435\u0441 \u043B\u0435\u043D\u0442\u044B \u043D\u0435 \u043F\u0440\u0438\u043D\u044F\u0442");
15717
+ if (refreshed) {
15718
+ io.writeError(hide(message));
15719
+ return 2;
15720
+ }
15721
+ clearUrl = true;
15722
+ step = "again";
15723
+ } else if (body.status === 400) {
15724
+ io.writeError(hide(errorMessage(await body.text(), "\u0430\u0434\u0440\u0435\u0441 \u043B\u0435\u043D\u0442\u044B \u043E\u0442\u0432\u0435\u0440\u0433\u043D\u0443\u0442")));
15725
+ return 2;
15726
+ } else if (body.status !== 200) {
15727
+ cause = `\u043B\u0435\u043D\u0442\u0430 \u043E\u0442\u0432\u0435\u0442\u0438\u043B\u0430 ${body.status}`;
15728
+ step = "down";
15729
+ } else {
15730
+ const read = await readStream(body);
15731
+ step = read.step;
15732
+ cause = read.cause;
15733
+ exit = read.exit;
15734
+ clearUrl = read.clearUrl;
15735
+ }
15736
+ } catch (e) {
15737
+ const err = takeError(e);
15738
+ if (err instanceof WatchAbort) return 130;
15739
+ if (err instanceof WatchGaveUp) {
15740
+ io.writeError(hide(err.message));
15741
+ return 2;
15742
+ }
15743
+ cause = err.message;
15744
+ step = "down";
15745
+ } finally {
15746
+ body?.close();
15747
+ }
15748
+ if (exit !== void 0) return exit;
15749
+ if (clearUrl) url = null;
15750
+ if (step === "again") continue;
15751
+ if (step === "down") {
15752
+ const code = giveUpDown(cause);
15753
+ if (code) return code;
15754
+ } else {
15755
+ downSince = null;
15756
+ }
15757
+ await paused();
15758
+ }
15759
+ return 130;
15760
+ } catch (e) {
15761
+ if (e instanceof WatchAbort || signal.aborted) return 130;
15762
+ if (e instanceof WatchGaveUp) {
15763
+ io.writeError(hide(e.message));
15764
+ return 2;
15765
+ }
15766
+ throw e;
15767
+ }
15768
+ async function readStream(stream) {
15769
+ const parser = new SseParser();
15770
+ let life = false;
15771
+ const noteUp = () => {
15772
+ life = true;
15773
+ downSince = null;
15774
+ delay = WATCH_RETRY_MS;
15775
+ };
15776
+ while (!signal.aborted) {
15777
+ const chunk = await stream.read();
15778
+ if (chunk === null) {
15779
+ return life ? { step: "pause", cause: "", clearUrl: false } : { step: "down", cause: "\u0441\u043E\u0435\u0434\u0438\u043D\u0435\u043D\u0438\u0435 \u043E\u0431\u043E\u0440\u0432\u0430\u043B\u043E\u0441\u044C", clearUrl: false };
15780
+ }
15781
+ for (const ev of parser.push(chunk)) {
15782
+ if (ev.kind === "life") {
15783
+ noteUp();
15784
+ continue;
15785
+ }
15786
+ if (ev.kind === "item") {
15787
+ noteUp();
15788
+ refreshed = false;
15789
+ const line = hide(oneLine(ev.text));
15790
+ if (!line) continue;
15791
+ io.write(line);
15792
+ if (!args.stream) return { step: "again", cause: "", exit: 0, clearUrl: false };
15793
+ continue;
15794
+ }
15795
+ if (ev.kind === "stale") {
15796
+ if (refreshed) {
15797
+ io.writeError(hide(ev.message || "\u0430\u0434\u0440\u0435\u0441 \u043B\u0435\u043D\u0442\u044B \u043F\u0440\u043E\u0442\u0443\u0445"));
15798
+ return { step: "again", cause: "", exit: 2, clearUrl: false };
15799
+ }
15800
+ return { step: "again", cause: "", clearUrl: true };
15801
+ }
15802
+ return { step: "down", cause: ev.message || "\u043B\u0435\u043D\u0442\u0430 \u043D\u0435\u0434\u043E\u0441\u0442\u0443\u043F\u043D\u0430", clearUrl: false };
15803
+ }
15804
+ }
15805
+ return { step: "again", cause: "", exit: 130, clearUrl: false };
15806
+ }
15807
+ }
15808
+ function writeFd(fd, line) {
15809
+ try {
15810
+ writeSync3(fd, `${line}
15811
+ `);
15812
+ } catch (e) {
15813
+ const code = e.code;
15814
+ if (code === "EPIPE") throw new WatchAbort();
15815
+ throw e;
15816
+ }
15817
+ }
15818
+ async function sleepAbortable(ms, signal) {
15819
+ if (signal.aborted) throw new WatchAbort();
15820
+ try {
15821
+ await sleep2(ms, void 0, { signal });
15822
+ } catch (e) {
15823
+ if (signal.aborted) throw new WatchAbort();
15824
+ throw e;
15825
+ }
15826
+ }
15827
+ async function runWatchCli(argv) {
15828
+ const parsed = parseWatchArgs(argv);
15829
+ if (!parsed.ok) {
15830
+ writeFd(2, parsed.error);
15831
+ return 1;
15832
+ }
15833
+ const ac = new AbortController();
15834
+ const stop = () => ac.abort();
15835
+ process.on("SIGINT", stop);
15836
+ process.on("SIGTERM", stop);
15837
+ try {
15838
+ return await runWatch(
15839
+ { repos: parsed.repos, url: parsed.url, stream: parsed.stream, signal: ac.signal },
15840
+ {
15841
+ now: () => Date.now(),
15842
+ sleep: (ms) => sleepAbortable(ms, ac.signal),
15843
+ write: (line) => writeFd(1, line),
15844
+ writeError: (line) => writeFd(2, line),
15845
+ connect: connectFeed,
15846
+ obtainUrl: (repos) => obtainFeedUrl(repos)
15847
+ }
15848
+ );
15849
+ } finally {
15850
+ process.off("SIGINT", stop);
15851
+ process.off("SIGTERM", stop);
15852
+ }
15853
+ }
15854
+
15301
15855
  // src/cli.ts
15302
15856
  init_daemonLink();
15303
15857
  init_pauseState();
@@ -15446,7 +16000,7 @@ async function runLoginFlow(db2, opts) {
15446
16000
  loadStore,
15447
16001
  beforeToken: null,
15448
16002
  now: Date.now,
15449
- sleep: sleep2,
16003
+ sleep: sleep3,
15450
16004
  timeoutMs: 5 * 6e4,
15451
16005
  pollMs: 1e3
15452
16006
  });
@@ -15540,7 +16094,7 @@ async function waitDaemonDown(opts) {
15540
16094
  console.log(lastLive ? `\u0436\u0434\u0443 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043D\u0438\u044F \u0436\u0438\u0432\u044B\u0445 \u0441\u0435\u0441\u0441\u0438\u0439: ${lastLive}\u2026` : "\u0436\u0438\u0432\u044B\u0445 \u0441\u0435\u0441\u0441\u0438\u0439 \u043D\u0435 \u043E\u0441\u0442\u0430\u043B\u043E\u0441\u044C \u2014 \u0433\u0430\u0448\u0443\u2026");
15541
16095
  }
15542
16096
  if (Date.now() >= until) return false;
15543
- await sleep2(pollMs);
16097
+ await sleep3(pollMs);
15544
16098
  }
15545
16099
  }
15546
16100
  var START_READY_TIMEOUT_MS = 45e3;
@@ -15614,7 +16168,7 @@ async function runDaemonLogs(argv) {
15614
16168
  if (!follow) return 0;
15615
16169
  let pos = statSync14(DAEMON_LOG_PATH).size;
15616
16170
  for (; ; ) {
15617
- await sleep2(500);
16171
+ await sleep3(500);
15618
16172
  let size;
15619
16173
  try {
15620
16174
  size = statSync14(DAEMON_LOG_PATH).size;
@@ -15851,6 +16405,15 @@ function usage() {
15851
16405
  swarm logs [-n 200] [-f] \u043B\u043E\u0433 \u0414\u0415\u041C\u041E\u041D\u0410 (~/.taskless-swarm/overmind.log)
15852
16406
  swarm log <runId> \u043B\u043E\u0433 \u043E\u0434\u043D\u043E\u0433\u043E \u041F\u0420\u041E\u0413\u041E\u041D\u0410 \u2014 \u043D\u0435 \u043F\u0443\u0442\u0430\u0442\u044C \u0441 \u043F\u0440\u0435\u0434\u044B\u0434\u0443\u0449\u0435\u0439
15853
16407
  swarm web \u0432\u0435\u0431-\u043C\u043E\u0440\u0434\u0430 \u0440\u043E\u044F \u043D\u0430 127.0.0.1:${WEB_PORT}
16408
+ swarm watch [--repos owner/repo,\u2026] [--url <\u0430\u0434\u0440\u0435\u0441>] [--stream]
16409
+ \u0436\u0434\u0430\u0442\u044C \u0434\u0435\u043B\u043E \u043B\u0435\u043D\u0442\u044B \u043E\u0440\u043A\u0435\u0441\u0442\u0440\u0430\u0442\u043E\u0440\u0430. \u0410\u0434\u0440\u0435\u0441 \u2014 MCP swarm_watch
16410
+ \u0442\u043E\u043A\u0435\u043D\u043E\u043C \u044D\u0442\u043E\u0439 \u043C\u0430\u0448\u0438\u043D\u044B \u0438\u043B\u0438 --url. \u0422\u043E\u043A\u0435\u043D \u0438\u0437 \u0430\u0434\u0440\u0435\u0441\u0430 \u043D\u0435 \u043F\u0435\u0447\u0430\u0442\u0430\u0435\u0442\u0441\u044F.
16411
+ \u0411\u0435\u0437 --stream \u2014 \u043F\u0435\u0440\u0432\u0430\u044F \u0441\u0442\u0440\u043E\u043A\u0430 \u0434\u0435\u043B\u0430 \u0438 \u0432\u044B\u0445\u043E\u0434 0. ${WATCH_BACKGROUND_HINT}:
16412
+ swarm watch
16413
+ --stream \u2014 \u0441\u0442\u0440\u043E\u043A\u0430 \u043D\u0430 \u043A\u0430\u0436\u0434\u043E\u0435 \u0434\u0435\u043B\u043E, \u043F\u0440\u043E\u0446\u0435\u0441\u0441 \u043D\u0435 \u0432\u044B\u0445\u043E\u0434\u0438\u0442.
16414
+ \u041E\u0431\u0440\u044B\u0432 \u2014 \u043F\u0435\u0440\u0435\u043F\u043E\u0434\u043A\u043B\u044E\u0447\u0435\u043D\u0438\u0435. \u0410\u0434\u0440\u0435\u0441 \u043F\u0440\u043E\u0442\u0443\u0445 \u2014 \u043D\u043E\u0432\u044B\u0439 \u0447\u0435\u0440\u0435\u0437
16415
+ swarm_watch. \u0421\u0435\u0442\u044C \u043D\u0435\u0434\u043E\u0441\u0442\u0443\u043F\u043D\u0430 5 \u043C\u0438\u043D\u0443\u0442 \u2014 \u0432\u044B\u0445\u043E\u0434 2 \u0438 \u0441\u0442\u0440\u043E\u043A\u0430
16416
+ \u043F\u0440\u0438\u0447\u0438\u043D\u044B.
15854
16417
 
15855
16418
  \u041F\u0420\u041E\u0427\u0415\u0415
15856
16419
  swarm whoami \u043A\u0442\u043E \u0432\u043E\u0448\u0451\u043B \u0438 \u0432 \u043A\u0430\u043A\u043E\u043C \u0432\u043E\u0440\u043A\u0441\u043F\u0435\u0439\u0441\u0435
@@ -16309,6 +16872,9 @@ if (cmd === "shot") {
16309
16872
  const code = await runShotCli(rawArgs);
16310
16873
  process.exit(code);
16311
16874
  }
16875
+ if (cmd === "watch") {
16876
+ process.exit(await runWatchCli(rawArgs));
16877
+ }
16312
16878
  if (!cmd || cmd === "--help" || cmd === "-h") {
16313
16879
  usage();
16314
16880
  process.exit(0);
@@ -16466,7 +17032,7 @@ switch (cmd) {
16466
17032
  // TASWM-592 (ревью): сессию ищет харнесс ПРОГОНА, а не глобальный исполнитель —
16467
17033
  // иначе побудка codex-прогона при мёртвом демоне теряла продолжаемую сессию.
16468
17034
  hasTranscript: (run2) => !!run2.worktree_path && executorForRun(run2, null).session.exists(run2.worktree_path),
16469
- respawn: (r, mode, nudge) => respawnRun(
17035
+ respawn: (r, mode, nudge, note) => respawnRun(
16470
17036
  {
16471
17037
  db,
16472
17038
  launch,
@@ -16478,7 +17044,8 @@ switch (cmd) {
16478
17044
  },
16479
17045
  r,
16480
17046
  mode,
16481
- nudge
17047
+ nudge,
17048
+ note
16482
17049
  )
16483
17050
  },
16484
17051
  runId