@taskless-app/swarm 0.6.98 → 0.6.100
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 +10 -6
- package/dist/overmind.js +485 -160
- package/package.json +2 -2
package/dist/overmind.js
CHANGED
|
@@ -3039,6 +3039,9 @@ function grokAbort(rec) {
|
|
|
3039
3039
|
}
|
|
3040
3040
|
return void 0;
|
|
3041
3041
|
}
|
|
3042
|
+
function grokRecordShape(rec) {
|
|
3043
|
+
return typeof rec.text === "string" || typeof rec.stopReason === "string" || typeof rec.sessionId === "string" || rec.type === "error";
|
|
3044
|
+
}
|
|
3042
3045
|
function parseGrokResult(raw) {
|
|
3043
3046
|
const trimmed = raw.trim();
|
|
3044
3047
|
if (!trimmed) return null;
|
|
@@ -3050,8 +3053,7 @@ function parseGrokResult(raw) {
|
|
|
3050
3053
|
}
|
|
3051
3054
|
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return null;
|
|
3052
3055
|
const rec = parsed;
|
|
3053
|
-
|
|
3054
|
-
if (!hasShape) return null;
|
|
3056
|
+
if (!grokRecordShape(rec)) return null;
|
|
3055
3057
|
const reported = typeof rec.total_cost_usd === "number" && Number.isFinite(rec.total_cost_usd);
|
|
3056
3058
|
const usage = rec.usage;
|
|
3057
3059
|
let tokensIn;
|
|
@@ -3104,7 +3106,7 @@ function readGrokProbeRecord(out) {
|
|
|
3104
3106
|
}
|
|
3105
3107
|
function grokProbeScanText(out) {
|
|
3106
3108
|
const located = locateGrokProbeJson(out);
|
|
3107
|
-
if (!located || grokAbort(located.rec)) return out;
|
|
3109
|
+
if (!located || grokAbort(located.rec) || !grokRecordShape(located.rec)) return out;
|
|
3108
3110
|
const at = out.indexOf(located.raw);
|
|
3109
3111
|
return out.slice(0, at) + out.slice(at + located.raw.length);
|
|
3110
3112
|
}
|
|
@@ -3205,7 +3207,9 @@ ${notice}` : spec.prompt;
|
|
|
3205
3207
|
probe: {
|
|
3206
3208
|
args: ["-p", "ok", "--output-format", "json", "--yolo", "--max-turns", "1", "--no-auto-update"],
|
|
3207
3209
|
// В бинаре 1.0.77 кроме «usage limit» есть weekly/rate limit и «run out of credits».
|
|
3208
|
-
|
|
3210
|
+
// TASWM-659: кончился баланс — «API error (status 402 Payment Required): Grok Build usage
|
|
3211
|
+
// balance exhausted». Код 402 — только рядом со словом ошибки, как 401 в authPattern.
|
|
3212
|
+
limitPattern: /usage limit|weekly limit|rate limit|run out of credits|balance exhausted|payment required|(?:error|api|http|status)[^\n]{0,60}\b402\b/i,
|
|
3209
3213
|
// Голый 401 ловил output_tokens и 0.401. Код — только рядом со словом
|
|
3210
3214
|
// ошибки, как у Claude. «401 Unauthorized» покрывает голое unauthorized.
|
|
3211
3215
|
authPattern: /not logged in|not signed in|unauthorized|(?:error|api|http|status)[^\n]{0,60}\b40[13]\b|(?:invalid|incorrect) api key|authentication required|auth required/i,
|
|
@@ -5455,7 +5459,7 @@ var init_procCleanup = __esm({
|
|
|
5455
5459
|
// src/git.ts
|
|
5456
5460
|
import { existsSync as existsSync14, readdirSync as readdirSync16, realpathSync as realpathSync2, statSync as statSync13 } from "fs";
|
|
5457
5461
|
import { appendFile, chmod, mkdir, readFile, rename, rm, writeFile } from "fs/promises";
|
|
5458
|
-
import { isAbsolute as isAbsolute4, join as
|
|
5462
|
+
import { isAbsolute as isAbsolute4, join as join26, resolve as resolve4, sep as sep3 } from "path";
|
|
5459
5463
|
import { $ as $3 } from "execa";
|
|
5460
5464
|
function gitNet(repo, args, timeoutMs) {
|
|
5461
5465
|
return withHardTimeout(
|
|
@@ -5484,7 +5488,7 @@ async function inspectWorktreePath(path) {
|
|
|
5484
5488
|
return "orphan";
|
|
5485
5489
|
}
|
|
5486
5490
|
try {
|
|
5487
|
-
if (statSync13(
|
|
5491
|
+
if (statSync13(join26(path, ".git")).isDirectory()) return "main-checkout";
|
|
5488
5492
|
} catch {
|
|
5489
5493
|
}
|
|
5490
5494
|
const top = await $3({ reject: false })`git -C ${path} rev-parse --show-toplevel`;
|
|
@@ -5544,7 +5548,7 @@ async function parkOrphanDir(repo, path, branch) {
|
|
|
5544
5548
|
}
|
|
5545
5549
|
function isLinkedWorktree(dir) {
|
|
5546
5550
|
try {
|
|
5547
|
-
return statSync13(
|
|
5551
|
+
return statSync13(join26(dir, ".git")).isFile();
|
|
5548
5552
|
} catch {
|
|
5549
5553
|
return false;
|
|
5550
5554
|
}
|
|
@@ -5656,8 +5660,8 @@ async function ensureGitExcluded(worktree, pattern) {
|
|
|
5656
5660
|
try {
|
|
5657
5661
|
const commonDir = await gitPath(worktree, "--git-common-dir");
|
|
5658
5662
|
if (!commonDir) return false;
|
|
5659
|
-
const infoDir =
|
|
5660
|
-
const excludeFile =
|
|
5663
|
+
const infoDir = join26(commonDir, "info");
|
|
5664
|
+
const excludeFile = join26(infoDir, "exclude");
|
|
5661
5665
|
let current = "";
|
|
5662
5666
|
try {
|
|
5663
5667
|
current = await readFile(excludeFile, "utf8");
|
|
@@ -5677,7 +5681,7 @@ async function gitPath(worktree, flag) {
|
|
|
5677
5681
|
const out = await $3({ reject: false })`git -C ${worktree} rev-parse ${flag}`;
|
|
5678
5682
|
const raw = out.stdout.trim();
|
|
5679
5683
|
if (out.exitCode !== 0 || !raw) return null;
|
|
5680
|
-
return isAbsolute4(raw) ? raw :
|
|
5684
|
+
return isAbsolute4(raw) ? raw : join26(worktree, raw);
|
|
5681
5685
|
}
|
|
5682
5686
|
async function ensureWorktreeHygiene(worktree) {
|
|
5683
5687
|
for (const pattern of SWARM_EXCLUDE_PATTERNS) await ensureGitExcluded(worktree, pattern);
|
|
@@ -5687,12 +5691,12 @@ async function installGuardHooks(worktree) {
|
|
|
5687
5691
|
try {
|
|
5688
5692
|
const gitDir = await gitPath(worktree, "--git-dir");
|
|
5689
5693
|
if (!gitDir) return false;
|
|
5690
|
-
const hooksDir =
|
|
5694
|
+
const hooksDir = join26(gitDir, "swarm-hooks");
|
|
5691
5695
|
const prev = await previousHooksPath(worktree);
|
|
5692
5696
|
await mkdir(hooksDir, { recursive: true });
|
|
5693
5697
|
for (const hook of GUARD_HOOKS) {
|
|
5694
|
-
await writeFile(
|
|
5695
|
-
await chmod(
|
|
5698
|
+
await writeFile(join26(hooksDir, hook), guardHookScript(hook, prev ? `${posix(prev)}/${hook}` : null));
|
|
5699
|
+
await chmod(join26(hooksDir, hook), 493);
|
|
5696
5700
|
}
|
|
5697
5701
|
await $3`git -C ${worktree} config extensions.worktreeConfig true`;
|
|
5698
5702
|
await $3`git -C ${worktree} config --worktree core.hooksPath ${posix(hooksDir)}`;
|
|
@@ -5711,7 +5715,7 @@ async function previousHooksPath(worktree) {
|
|
|
5711
5715
|
if (out.exitCode === 0 && value) return value;
|
|
5712
5716
|
}
|
|
5713
5717
|
const commonDir = await gitPath(worktree, "--git-common-dir");
|
|
5714
|
-
return commonDir ?
|
|
5718
|
+
return commonDir ? join26(commonDir, "hooks") : null;
|
|
5715
5719
|
}
|
|
5716
5720
|
async function removeWorktree(repo, path) {
|
|
5717
5721
|
const branch = (await $3({ reject: false })`git -C ${path} symbolic-ref --quiet --short HEAD`).stdout.trim();
|
|
@@ -5736,7 +5740,7 @@ async function worktreeDirty(path) {
|
|
|
5736
5740
|
async function repairMovedWorktrees(targetDir) {
|
|
5737
5741
|
const subdirs = (dir) => {
|
|
5738
5742
|
try {
|
|
5739
|
-
return readdirSync16(dir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) =>
|
|
5743
|
+
return readdirSync16(dir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => join26(dir, d.name));
|
|
5740
5744
|
} catch {
|
|
5741
5745
|
return [];
|
|
5742
5746
|
}
|
|
@@ -5873,12 +5877,12 @@ __export(droneChannel_exports, {
|
|
|
5873
5877
|
verifyLocalCliToken: () => verifyLocalCliToken
|
|
5874
5878
|
});
|
|
5875
5879
|
import { createHmac, randomBytes, timingSafeEqual } from "crypto";
|
|
5876
|
-
import { chmodSync as chmodSync2, mkdirSync as mkdirSync12, readFileSync as
|
|
5880
|
+
import { chmodSync as chmodSync2, mkdirSync as mkdirSync12, readFileSync as readFileSync23, writeFileSync as writeFileSync14 } from "fs";
|
|
5877
5881
|
import { dirname as dirname5 } from "path";
|
|
5878
5882
|
import { serve } from "@hono/node-server";
|
|
5879
5883
|
function loadChannelSecret(path) {
|
|
5880
5884
|
try {
|
|
5881
|
-
const s =
|
|
5885
|
+
const s = readFileSync23(path, "utf8").trim();
|
|
5882
5886
|
if (s.length >= 32) return s;
|
|
5883
5887
|
} catch {
|
|
5884
5888
|
}
|
|
@@ -6274,7 +6278,7 @@ var init_droneChannel = __esm({
|
|
|
6274
6278
|
|
|
6275
6279
|
// src/attachments.ts
|
|
6276
6280
|
import { mkdir as mkdir3, readFile as readFile2, readdir as readdir2, stat as stat2, unlink, writeFile as writeFile3 } from "fs/promises";
|
|
6277
|
-
import { extname, join as
|
|
6281
|
+
import { extname, join as join31 } from "path";
|
|
6278
6282
|
function attachmentsFromDoc(doc, origin) {
|
|
6279
6283
|
const out = [];
|
|
6280
6284
|
const walk2 = (node) => {
|
|
@@ -6370,7 +6374,7 @@ async function materializeAttachments(opts) {
|
|
|
6370
6374
|
};
|
|
6371
6375
|
const result = { files: [], skipped: [] };
|
|
6372
6376
|
if (opts.refs.length === 0) return result;
|
|
6373
|
-
const dir =
|
|
6377
|
+
const dir = join31(opts.worktree, ATTACHMENTS_DIR);
|
|
6374
6378
|
const existing = (await io.listFiles(dir)).filter((file) => file.name !== ".index.json");
|
|
6375
6379
|
const previousIndex = await readAttachmentIndex(dir, io.readFile);
|
|
6376
6380
|
const nextIndex = {};
|
|
@@ -6456,7 +6460,7 @@ async function materializeAttachments(opts) {
|
|
|
6456
6460
|
await io.mkdir(dir);
|
|
6457
6461
|
dirReady = true;
|
|
6458
6462
|
}
|
|
6459
|
-
await io.writeFile(
|
|
6463
|
+
await io.writeFile(join31(dir, name), file.bytes);
|
|
6460
6464
|
} catch (e) {
|
|
6461
6465
|
const reason = `\u043D\u0435 \u0437\u0430\u043F\u0438\u0441\u0430\u043B\u043E\u0441\u044C \u043D\u0430 \u0434\u0438\u0441\u043A (${errText2(e)})`;
|
|
6462
6466
|
const stem = name.slice(0, name.length - extname(name).length);
|
|
@@ -6480,7 +6484,7 @@ async function materializeAttachments(opts) {
|
|
|
6480
6484
|
}
|
|
6481
6485
|
const wanted = new Set(result.files.map((f) => f.path.split("/").pop()));
|
|
6482
6486
|
for (const old of existing) {
|
|
6483
|
-
if (!wanted.has(old.name)) await io.removeFile(
|
|
6487
|
+
if (!wanted.has(old.name)) await io.removeFile(join31(dir, old.name));
|
|
6484
6488
|
}
|
|
6485
6489
|
if (result.files.length > 0 && JSON.stringify(nextIndex) !== JSON.stringify(previousIndex)) {
|
|
6486
6490
|
try {
|
|
@@ -6488,7 +6492,7 @@ async function materializeAttachments(opts) {
|
|
|
6488
6492
|
await io.mkdir(dir);
|
|
6489
6493
|
dirReady = true;
|
|
6490
6494
|
}
|
|
6491
|
-
await io.writeFile(
|
|
6495
|
+
await io.writeFile(join31(dir, ".index.json"), new TextEncoder().encode(JSON.stringify(nextIndex)));
|
|
6492
6496
|
} catch {
|
|
6493
6497
|
}
|
|
6494
6498
|
}
|
|
@@ -6498,7 +6502,7 @@ async function materializeAttachments(opts) {
|
|
|
6498
6502
|
async function readAttachmentIndex(dir, read) {
|
|
6499
6503
|
if (!read) return {};
|
|
6500
6504
|
try {
|
|
6501
|
-
const parsed = JSON.parse(new TextDecoder().decode(await read(
|
|
6505
|
+
const parsed = JSON.parse(new TextDecoder().decode(await read(join31(dir, ".index.json"))));
|
|
6502
6506
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return {};
|
|
6503
6507
|
const entries = Object.entries(parsed);
|
|
6504
6508
|
if (entries.some(([, url]) => typeof url !== "string")) return {};
|
|
@@ -6511,7 +6515,7 @@ async function listAttachmentFiles(dir) {
|
|
|
6511
6515
|
try {
|
|
6512
6516
|
const entries = await readdir2(dir, { withFileTypes: true });
|
|
6513
6517
|
return await Promise.all(
|
|
6514
|
-
entries.filter((entry) => entry.isFile() && entry.name !== ".index.json").map(async (entry) => ({ name: entry.name, bytes: (await stat2(
|
|
6518
|
+
entries.filter((entry) => entry.isFile() && entry.name !== ".index.json").map(async (entry) => ({ name: entry.name, bytes: (await stat2(join31(dir, entry.name))).size }))
|
|
6515
6519
|
);
|
|
6516
6520
|
} catch (e) {
|
|
6517
6521
|
if (e.code === "ENOENT") return [];
|
|
@@ -6528,7 +6532,7 @@ function renderAttachmentsBlock(result) {
|
|
|
6528
6532
|
"\xAB\u043F\u0435\u0440\u0432\u044B\u0439 \u0441\u043A\u0440\u0438\u043D\xBB \u0438\u0437 \u0442\u0435\u043A\u0441\u0442\u0430 \u2014 \u044D\u0442\u043E 01-\u2026, \xAB\u0432\u0442\u043E\u0440\u043E\u0439\xBB \u2014 02-\u2026 . \u041F\u0440\u043E\u043F\u0443\u0449\u0435\u043D\u043D\u044B\u0439 \u043D\u043E\u043C\u0435\u0440 \u0437\u043D\u0430\u0447\u0438\u0442, \u0447\u0442\u043E \u044D\u0442\u043E \u0432\u043B\u043E\u0436\u0435\u043D\u0438\u0435",
|
|
6529
6533
|
"\u0432\u044B\u043B\u043E\u0436\u0438\u0442\u044C \u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u2014 \u043E\u043D\u043E \u043D\u0430\u0437\u0432\u0430\u043D\u043E \u043D\u0438\u0436\u0435, \u0430 \u043D\u0435 \u043F\u043E\u0442\u0435\u0440\u044F\u043B\u043E\u0441\u044C.",
|
|
6530
6534
|
...result.files.map(
|
|
6531
|
-
(f) => `- ${f.path}${f.caption ? ` \u2014 \xAB${
|
|
6535
|
+
(f) => `- ${f.path}${f.caption ? ` \u2014 \xAB${oneLine2(f.caption)}\xBB` : ""} [${oneLine2(f.origin)}, ${mb(f.bytes)}]` + (f.previousCopyReason ? ` \u2014 \u043F\u0440\u0435\u0436\u043D\u044F\u044F \u043A\u043E\u043F\u0438\u044F, \u0437\u0430\u043D\u043E\u0432\u043E \u0441\u043A\u0430\u0447\u0430\u0442\u044C \u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C (${oneLine2(f.previousCopyReason)})` : "")
|
|
6532
6536
|
),
|
|
6533
6537
|
"\u0415\u0441\u043B\u0438 \u043F\u043E\u0441\u0442\u0430\u043D\u043E\u0432\u043A\u0430 \u0441\u0441\u044B\u043B\u0430\u0435\u0442\u0441\u044F \u043D\u0430 \u0438\u0437\u043E\u0431\u0440\u0430\u0436\u0435\u043D\u0438\u0435 (\xAB\u043E\u0442\u0434\u0435\u043B\u0438\u043B\u0430 \u043A\u0440\u0430\u0441\u043D\u044B\u043C\u0438 \u043F\u043E\u043B\u044F\u043C\u0438\xBB, \xAB\u043A\u0430\u043A \u043D\u0430 \u0441\u043A\u0440\u0438\u043D\u0435\xBB) \u2014 \u041E\u0422\u041A\u0420\u041E\u0419 \u0444\u0430\u0439\u043B, \u0430 \u043D\u0435 \u0434\u043E\u0434\u0443\u043C\u044B\u0432\u0430\u0439."
|
|
6534
6538
|
);
|
|
@@ -6537,7 +6541,7 @@ function renderAttachmentsBlock(result) {
|
|
|
6537
6541
|
lines.push(
|
|
6538
6542
|
result.files.length > 0 ? "" : "\u{1F4CE} \u0412\u041B\u041E\u0416\u0415\u041D\u0418\u042F \u0417\u0410\u0414\u0410\u0427\u0418: \u0432\u044B\u043B\u043E\u0436\u0438\u0442\u044C \u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u043D\u0438\u0447\u0435\u0433\u043E.",
|
|
6539
6543
|
`\u26A0\uFE0F \u041D\u0415 \u0432\u044B\u043B\u043E\u0436\u0435\u043D\u043E (${result.skipped.length}) \u2014 \u0442\u044B \u0438\u0445 \u041D\u0415 \u0432\u0438\u0434\u0435\u043B, \u0443\u0447\u0438\u0442\u044B\u0432\u0430\u0439 \u044D\u0442\u043E:`,
|
|
6540
|
-
...result.skipped.map((s) => `- ${
|
|
6544
|
+
...result.skipped.map((s) => `- ${oneLine2(s)}`),
|
|
6541
6545
|
"\u041D\u0443\u0436\u0435\u043D \u043F\u0440\u043E\u043F\u0443\u0449\u0435\u043D\u043D\u044B\u0439 \u0444\u0430\u0439\u043B \u0434\u043B\u044F \u0440\u0430\u0431\u043E\u0442\u044B \u2014 \u0441\u043F\u0440\u043E\u0441\u0438 \u043E\u043F\u0435\u0440\u0430\u0442\u043E\u0440\u0430 \u0447\u0435\u0440\u0435\u0437 ask(), \u043D\u0435 \u0433\u0430\u0434\u0430\u0439 \u043F\u043E \u043D\u0430\u0437\u0432\u0430\u043D\u0438\u044E."
|
|
6542
6546
|
);
|
|
6543
6547
|
}
|
|
@@ -6554,7 +6558,7 @@ async function prepareTaskAttachments(opts) {
|
|
|
6554
6558
|
}
|
|
6555
6559
|
if (result.files.length > 0 || result.skipped.length > 0) {
|
|
6556
6560
|
const failures = result.downloadFailures ?? [];
|
|
6557
|
-
const failureText = failures.length ? `\u043D\u0435 \u0441\u043A\u0430\u0447\u0430\u043B\u043E\u0441\u044C ${failures.length} (${failures.map((f) =>
|
|
6561
|
+
const failureText = failures.length ? `\u043D\u0435 \u0441\u043A\u0430\u0447\u0430\u043B\u043E\u0441\u044C ${failures.length} (${failures.map((f) => oneLine2(f.label)).join(", ")}), \u043F\u0440\u0435\u0436\u043D\u044F\u044F \u043A\u043E\u043F\u0438\u044F \u043E\u0441\u0442\u0430\u0432\u043B\u0435\u043D\u0430 \u0443 ${failures.filter((f) => f.previousCopy).length}; ` : "";
|
|
6558
6562
|
await opts.onEvent?.(
|
|
6559
6563
|
`\u0432\u043B\u043E\u0436\u0435\u043D\u0438\u044F \u0437\u0430\u0434\u0430\u0447\u0438: ${failureText}\u0432\u044B\u043B\u043E\u0436\u0435\u043D\u043E ${result.files.length} \u0432 ${ATTACHMENTS_DIR}` + (result.skipped.length ? `, \u043F\u0440\u043E\u043F\u0443\u0449\u0435\u043D\u043E ${result.skipped.length} (\u043F\u0435\u0440\u0435\u0447\u0438\u0441\u043B\u0435\u043D\u044B \u0432 \u043F\u0440\u043E\u043C\u043F\u0442\u0435)` : "")
|
|
6560
6564
|
);
|
|
@@ -6568,7 +6572,7 @@ async function prepareTaskAttachments(opts) {
|
|
|
6568
6572
|
function str(v) {
|
|
6569
6573
|
return typeof v === "string" ? v : "";
|
|
6570
6574
|
}
|
|
6571
|
-
function
|
|
6575
|
+
function oneLine2(s) {
|
|
6572
6576
|
const flat = s.replace(/\s+/g, " ").trim();
|
|
6573
6577
|
return flat.length > 200 ? `${flat.slice(0, 200)}\u2026` : flat;
|
|
6574
6578
|
}
|
|
@@ -6658,7 +6662,7 @@ var init_attachments = __esm({
|
|
|
6658
6662
|
|
|
6659
6663
|
// src/shotUpload.ts
|
|
6660
6664
|
import { readFile as fsReadFile } from "fs/promises";
|
|
6661
|
-
import { basename as basename5, isAbsolute as isAbsolute5, join as
|
|
6665
|
+
import { basename as basename5, isAbsolute as isAbsolute5, join as join32 } from "path";
|
|
6662
6666
|
function shotMimetype(path) {
|
|
6663
6667
|
const dot = path.lastIndexOf(".");
|
|
6664
6668
|
if (dot < 0) return null;
|
|
@@ -6684,7 +6688,7 @@ async function readShots(paths, opts) {
|
|
|
6684
6688
|
}
|
|
6685
6689
|
let bytes;
|
|
6686
6690
|
try {
|
|
6687
|
-
bytes = await read(isAbsolute5(path) ? path :
|
|
6691
|
+
bytes = await read(isAbsolute5(path) ? path : join32(opts.worktree, path));
|
|
6688
6692
|
} catch (e) {
|
|
6689
6693
|
skipped.push({ path, reason: `\u043D\u0435 \u043F\u0440\u043E\u0447\u0438\u0442\u0430\u043D: ${e instanceof Error ? e.message : String(e)}` });
|
|
6690
6694
|
continue;
|
|
@@ -6765,8 +6769,8 @@ var init_shotUpload = __esm({
|
|
|
6765
6769
|
|
|
6766
6770
|
// src/oauth.ts
|
|
6767
6771
|
import { createHash as createHash4, randomBytes as randomBytes2 } from "crypto";
|
|
6768
|
-
import { readFileSync as
|
|
6769
|
-
import { join as
|
|
6772
|
+
import { readFileSync as readFileSync24, writeFileSync as writeFileSync15, unlinkSync as unlinkSync4 } from "fs";
|
|
6773
|
+
import { join as join33 } from "path";
|
|
6770
6774
|
function makePkce() {
|
|
6771
6775
|
const verifier = randomBytes2(48).toString("base64url");
|
|
6772
6776
|
const challenge = createHash4("sha256").update(verifier).digest("base64url");
|
|
@@ -6850,7 +6854,7 @@ function toStore(clientId, t, now) {
|
|
|
6850
6854
|
}
|
|
6851
6855
|
function loadStore() {
|
|
6852
6856
|
try {
|
|
6853
|
-
return JSON.parse(
|
|
6857
|
+
return JSON.parse(readFileSync24(STORE_PATH2, "utf8"));
|
|
6854
6858
|
} catch {
|
|
6855
6859
|
return null;
|
|
6856
6860
|
}
|
|
@@ -6866,7 +6870,7 @@ function clearStore() {
|
|
|
6866
6870
|
}
|
|
6867
6871
|
function loadClientId() {
|
|
6868
6872
|
try {
|
|
6869
|
-
return JSON.parse(
|
|
6873
|
+
return JSON.parse(readFileSync24(CLIENT_PATH, "utf8")).clientId;
|
|
6870
6874
|
} catch {
|
|
6871
6875
|
return null;
|
|
6872
6876
|
}
|
|
@@ -6901,8 +6905,8 @@ var init_oauth = __esm({
|
|
|
6901
6905
|
AUTHORIZE = "/api/oauth/authorize";
|
|
6902
6906
|
TOKEN = "/api/oauth/token";
|
|
6903
6907
|
SCOPE = "openid profile email taskless:full";
|
|
6904
|
-
STORE_PATH2 =
|
|
6905
|
-
CLIENT_PATH =
|
|
6908
|
+
STORE_PATH2 = join33(SWARM_HOME, "oauth.json");
|
|
6909
|
+
CLIENT_PATH = join33(SWARM_HOME, "oauth-client.json");
|
|
6906
6910
|
base2 = (api) => api.replace(/\/$/, "");
|
|
6907
6911
|
}
|
|
6908
6912
|
});
|
|
@@ -6989,11 +6993,11 @@ var init_authState = __esm({
|
|
|
6989
6993
|
});
|
|
6990
6994
|
|
|
6991
6995
|
// src/workspace.ts
|
|
6992
|
-
import { readFileSync as
|
|
6993
|
-
import { join as
|
|
6996
|
+
import { readFileSync as readFileSync25, writeFileSync as writeFileSync16, unlinkSync as unlinkSync5 } from "fs";
|
|
6997
|
+
import { join as join34 } from "path";
|
|
6994
6998
|
function loadWorkspace() {
|
|
6995
6999
|
try {
|
|
6996
|
-
const w = JSON.parse(
|
|
7000
|
+
const w = JSON.parse(readFileSync25(WORKSPACE_PATH, "utf8"));
|
|
6997
7001
|
return w && typeof w.id === "string" && w.id ? w : null;
|
|
6998
7002
|
} catch {
|
|
6999
7003
|
return null;
|
|
@@ -7007,7 +7011,7 @@ var init_workspace = __esm({
|
|
|
7007
7011
|
"src/workspace.ts"() {
|
|
7008
7012
|
"use strict";
|
|
7009
7013
|
init_config();
|
|
7010
|
-
WORKSPACE_PATH =
|
|
7014
|
+
WORKSPACE_PATH = join34(SWARM_HOME, "workspace.json");
|
|
7011
7015
|
}
|
|
7012
7016
|
});
|
|
7013
7017
|
|
|
@@ -8734,9 +8738,9 @@ var init_droneStore = __esm({
|
|
|
8734
8738
|
});
|
|
8735
8739
|
|
|
8736
8740
|
// src/overmind.ts
|
|
8737
|
-
import { homedir as
|
|
8738
|
-
import { existsSync as existsSync23, readFileSync as
|
|
8739
|
-
import { basename as basename7, dirname as dirname6, join as
|
|
8741
|
+
import { homedir as homedir10 } from "os";
|
|
8742
|
+
import { existsSync as existsSync23, readFileSync as readFileSync29, readdirSync as readdirSync18, renameSync as renameSync12, statSync as statSync16 } from "fs";
|
|
8743
|
+
import { basename as basename7, dirname as dirname6, join as join41 } from "path";
|
|
8740
8744
|
import { fileURLToPath as fileURLToPath3, pathToFileURL } from "url";
|
|
8741
8745
|
import { spawn as spawn4 } from "child_process";
|
|
8742
8746
|
|
|
@@ -13422,7 +13426,84 @@ function makeAbortReader(runLogsDir, runLogKeys, executorFor = () => resolveExec
|
|
|
13422
13426
|
// src/limitWait.ts
|
|
13423
13427
|
init_src();
|
|
13424
13428
|
import { closeSync as closeSync5, fstatSync as fstatSync2, openSync as openSync5, readdirSync as readdirSync14, readSync as readSync2 } from "fs";
|
|
13429
|
+
import { join as join23 } from "path";
|
|
13430
|
+
|
|
13431
|
+
// src/grokBalance.ts
|
|
13432
|
+
init_src();
|
|
13433
|
+
import { readFileSync as readFileSync19 } from "fs";
|
|
13434
|
+
import { homedir as homedir8 } from "os";
|
|
13425
13435
|
import { join as join22 } from "path";
|
|
13436
|
+
var GROK_BALANCE_WAIT_TAG = "balance-exhausted";
|
|
13437
|
+
var GROK_BALANCE_SIGNAL_KEY = "grok_balance_exhausted";
|
|
13438
|
+
var GROK_BALANCE_SIGNAL_KEY_ROOM = 120 - GROK_BALANCE_SIGNAL_KEY.length - 1;
|
|
13439
|
+
function grokBalanceSignalKey(selfHostId) {
|
|
13440
|
+
const id = (selfHostId ?? "").trim();
|
|
13441
|
+
if (!id) return GROK_BALANCE_SIGNAL_KEY;
|
|
13442
|
+
const suffix = id.length <= GROK_BALANCE_SIGNAL_KEY_ROOM ? id : id.slice(0, GROK_BALANCE_SIGNAL_KEY_ROOM);
|
|
13443
|
+
return `${GROK_BALANCE_SIGNAL_KEY}:${suffix}`;
|
|
13444
|
+
}
|
|
13445
|
+
var GROK_BALANCE_RENOTIFY_MS = 6 * 60 * 60 * 1e3;
|
|
13446
|
+
var GROK_BALANCE_SUCCESS_MS = 5 * 60 * 1e3;
|
|
13447
|
+
var GROK_BALANCE_ACTION = "\u043F\u043E\u043F\u043E\u043B\u043D\u0438 \u0431\u0430\u043B\u0430\u043D\u0441 \u0438\u043B\u0438 \u043F\u0435\u0440\u0435\u043A\u043B\u044E\u0447\u0438 \u0443\u0447\u0451\u0442\u043A\u0443";
|
|
13448
|
+
var EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
13449
|
+
var EMAIL_MAX = 320;
|
|
13450
|
+
function isGrokBalanceLimitText(text) {
|
|
13451
|
+
return /balance exhausted|payment required/i.test(text) || /(?:error|api|http|status)[^\n]{0,80}\b402\b/i.test(text);
|
|
13452
|
+
}
|
|
13453
|
+
function isGrokBalanceWait(stopReason) {
|
|
13454
|
+
const wait = parseLimitWait(stopReason);
|
|
13455
|
+
return wait?.executor === "grok" && (stopReason ?? "").includes(GROK_BALANCE_WAIT_TAG);
|
|
13456
|
+
}
|
|
13457
|
+
function grokBalanceWaitText() {
|
|
13458
|
+
return `${GROK_BALANCE_WAIT_TAG}: \u043A\u043E\u043D\u0447\u0438\u043B\u0441\u044F \u0431\u0430\u043B\u0430\u043D\u0441 Grok, ${GROK_BALANCE_ACTION}`;
|
|
13459
|
+
}
|
|
13460
|
+
function pluralRuns(n) {
|
|
13461
|
+
const abs = Math.abs(Math.trunc(n)) % 100;
|
|
13462
|
+
const last = abs % 10;
|
|
13463
|
+
if (abs >= 11 && abs <= 14) return "\u043F\u0440\u043E\u0433\u043E\u043D\u043E\u0432";
|
|
13464
|
+
if (last === 1) return "\u043F\u0440\u043E\u0433\u043E\u043D";
|
|
13465
|
+
if (last >= 2 && last <= 4) return "\u043F\u0440\u043E\u0433\u043E\u043D\u0430";
|
|
13466
|
+
return "\u043F\u0440\u043E\u0433\u043E\u043D\u043E\u0432";
|
|
13467
|
+
}
|
|
13468
|
+
function oneLine(text) {
|
|
13469
|
+
return text.replace(/[\r\n]+/g, " ").replace(/[ \t]{2,}/g, " ").trim();
|
|
13470
|
+
}
|
|
13471
|
+
function grokBalanceSignal(input) {
|
|
13472
|
+
const host = oneLine(input.hostName) || "\u043C\u0430\u0448\u0438\u043D\u0430";
|
|
13473
|
+
const email = input.email && isPlainEmail(input.email) ? input.email.trim() : null;
|
|
13474
|
+
const n = Number.isFinite(input.waiting) ? Math.max(0, Math.trunc(input.waiting)) : 0;
|
|
13475
|
+
const account = email ? `\u0423\u0447\u0451\u0442\u043A\u0430 ${email}.` : "\u041F\u043E\u0447\u0442\u0430 \u0443\u0447\u0451\u0442\u043A\u0438 \u043D\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043D\u0430.";
|
|
13476
|
+
const body = oneLine(`\u041C\u0430\u0448\u0438\u043D\u0430 ${host}. ${account} \u0416\u0434\u0443\u0442 ${n} ${pluralRuns(n)}. ${GROK_BALANCE_ACTION}.`);
|
|
13477
|
+
return { title: `${host}: \u043A\u043E\u043D\u0447\u0438\u043B\u0441\u044F \u0431\u0430\u043B\u0430\u043D\u0441 Grok`, body };
|
|
13478
|
+
}
|
|
13479
|
+
function isPlainEmail(value) {
|
|
13480
|
+
const trimmed = value.trim();
|
|
13481
|
+
return trimmed.length > 0 && trimmed.length <= EMAIL_MAX && EMAIL_RE.test(trimmed) && !/[\r\n]/.test(value);
|
|
13482
|
+
}
|
|
13483
|
+
function readGrokAccountEmail(authPath) {
|
|
13484
|
+
let raw;
|
|
13485
|
+
try {
|
|
13486
|
+
raw = readFileSync19(authPath, "utf8");
|
|
13487
|
+
} catch {
|
|
13488
|
+
return null;
|
|
13489
|
+
}
|
|
13490
|
+
let parsed;
|
|
13491
|
+
try {
|
|
13492
|
+
parsed = JSON.parse(raw);
|
|
13493
|
+
} catch {
|
|
13494
|
+
return null;
|
|
13495
|
+
}
|
|
13496
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
|
|
13497
|
+
const email = parsed.email;
|
|
13498
|
+
if (typeof email !== "string" || !isPlainEmail(email)) return null;
|
|
13499
|
+
return email.trim();
|
|
13500
|
+
}
|
|
13501
|
+
function grokAccountAuthPath(env, home = homedir8()) {
|
|
13502
|
+
const configured = (env.GROK_HOME ?? "").trim();
|
|
13503
|
+
return join22(configured || join22(home, ".grok"), "auth.json");
|
|
13504
|
+
}
|
|
13505
|
+
|
|
13506
|
+
// src/limitWait.ts
|
|
13426
13507
|
var TAIL_BYTES = 8 * 1024;
|
|
13427
13508
|
var SNAPSHOT_FRESH_MS = 15 * 6e4;
|
|
13428
13509
|
var RESULT_FILE_RE2 = /^(\d+)\.json(\.done)?$/;
|
|
@@ -13523,12 +13604,14 @@ function makeLimitReader(logsDir, logKeys, executorOf, snapshot = () => null) {
|
|
|
13523
13604
|
const executor = executorOf(run2);
|
|
13524
13605
|
const launch = latestLaunch(logsDir, logKeys(run2.id));
|
|
13525
13606
|
if (!launch) return null;
|
|
13526
|
-
const stderr = readTail2(
|
|
13527
|
-
const stdout = launch.stdoutName ? readTail2(
|
|
13607
|
+
const stderr = readTail2(join23(launch.dir, `${launch.index}.err.log`)) ?? "";
|
|
13608
|
+
const stdout = launch.stdoutName ? readTail2(join23(launch.dir, launch.stdoutName), true) ?? "" : "";
|
|
13528
13609
|
const stdoutText = nonJsonLines(stdout);
|
|
13529
13610
|
const limitText = matchesLimit(executor.probe.limitPattern, stderr) ? stderr : matchesLimit(executor.probe.limitPattern, stdoutText) ? stdoutText : null;
|
|
13530
13611
|
if (limitText !== null) {
|
|
13531
|
-
|
|
13612
|
+
const hit = { executor: executor.id, resetHint: limitText.match(RESET_RE)?.[0]?.trim() ?? null };
|
|
13613
|
+
if (executor.id === "grok") hit.balance = isGrokBalanceLimitText(limitText);
|
|
13614
|
+
return hit;
|
|
13532
13615
|
}
|
|
13533
13616
|
if (executor.id === "kimi") {
|
|
13534
13617
|
const report = snapshot();
|
|
@@ -13578,7 +13661,7 @@ init_src();
|
|
|
13578
13661
|
init_swarmModels();
|
|
13579
13662
|
init_executors();
|
|
13580
13663
|
import { accessSync, constants } from "fs";
|
|
13581
|
-
import { delimiter, join as
|
|
13664
|
+
import { delimiter, join as join24 } from "path";
|
|
13582
13665
|
function binRunnable(bin, env) {
|
|
13583
13666
|
if (!bin) return false;
|
|
13584
13667
|
if (bin.includes("/") || bin.includes("\\")) {
|
|
@@ -13594,7 +13677,7 @@ function binRunnable(bin, env) {
|
|
|
13594
13677
|
if (!dir) continue;
|
|
13595
13678
|
for (const ext of exts) {
|
|
13596
13679
|
try {
|
|
13597
|
-
accessSync(
|
|
13680
|
+
accessSync(join24(dir, bin + ext), constants.X_OK);
|
|
13598
13681
|
return true;
|
|
13599
13682
|
} catch {
|
|
13600
13683
|
}
|
|
@@ -13638,9 +13721,9 @@ function providerUnavailableReason(providerId, available) {
|
|
|
13638
13721
|
|
|
13639
13722
|
// src/modelLimits.ts
|
|
13640
13723
|
import { createHash } from "crypto";
|
|
13641
|
-
import { readFileSync as
|
|
13642
|
-
import { homedir as
|
|
13643
|
-
import { join as
|
|
13724
|
+
import { readFileSync as readFileSync20, readdirSync as readdirSync15, statSync as statSync12 } from "fs";
|
|
13725
|
+
import { homedir as homedir9 } from "os";
|
|
13726
|
+
import { join as join25 } from "path";
|
|
13644
13727
|
var KIMI_USAGES_URL = "https://api.kimi.com/coding/v1/usages";
|
|
13645
13728
|
var DEFAULT_POLL_MS = 3e5;
|
|
13646
13729
|
var FETCH_TIMEOUT_MS = 1e4;
|
|
@@ -13663,15 +13746,15 @@ function accountKey(userId) {
|
|
|
13663
13746
|
}
|
|
13664
13747
|
function readKimiCredentials(env = process.env) {
|
|
13665
13748
|
try {
|
|
13666
|
-
const root = env.KIMI_CODE_HOME?.trim() ||
|
|
13667
|
-
const dir =
|
|
13668
|
-
const files = readdirSync15(dir).filter((name) => name.endsWith(".json")).map((name) => ({ name, path:
|
|
13749
|
+
const root = env.KIMI_CODE_HOME?.trim() || join25(homedir9(), ".kimi-code");
|
|
13750
|
+
const dir = join25(root, "credentials");
|
|
13751
|
+
const files = readdirSync15(dir).filter((name) => name.endsWith(".json")).map((name) => ({ name, path: join25(dir, name) })).filter((entry) => statSync12(entry.path).isFile());
|
|
13669
13752
|
const preferred = files.filter((entry) => entry.name.startsWith("kimi-code-env-"));
|
|
13670
13753
|
const candidates = preferred.length ? preferred : files;
|
|
13671
13754
|
candidates.sort((a, b) => statSync12(b.path).mtimeMs - statSync12(a.path).mtimeMs || a.name.localeCompare(b.name));
|
|
13672
13755
|
const newest2 = candidates[0];
|
|
13673
13756
|
if (!newest2) return null;
|
|
13674
|
-
const body = record(JSON.parse(
|
|
13757
|
+
const body = record(JSON.parse(readFileSync20(newest2.path, "utf8")));
|
|
13675
13758
|
if (typeof body?.access_token !== "string" || !body.access_token) return null;
|
|
13676
13759
|
const userId = jwtUserId(body.access_token);
|
|
13677
13760
|
return { accessToken: body.access_token, accountKey: accountKey(userId) };
|
|
@@ -13806,20 +13889,20 @@ init_src();
|
|
|
13806
13889
|
init_git();
|
|
13807
13890
|
|
|
13808
13891
|
// src/deps.ts
|
|
13809
|
-
import { existsSync as existsSync16, readdirSync as readdirSync17, readFileSync as
|
|
13810
|
-
import { join as
|
|
13892
|
+
import { existsSync as existsSync16, readdirSync as readdirSync17, readFileSync as readFileSync22 } from "fs";
|
|
13893
|
+
import { join as join29 } from "path";
|
|
13811
13894
|
import { execa } from "execa";
|
|
13812
13895
|
|
|
13813
13896
|
// src/prepareLock.ts
|
|
13814
13897
|
import { createHash as createHash2 } from "crypto";
|
|
13815
13898
|
import { closeSync as closeSync6, openSync as openSync6, rmSync as rmSync2, statSync as statSync14, writeSync as writeSync2 } from "fs";
|
|
13816
|
-
import { join as
|
|
13899
|
+
import { join as join27 } from "path";
|
|
13817
13900
|
import { tmpdir } from "os";
|
|
13818
13901
|
var WAIT_TIMEOUT_MS = 5 * 6e4;
|
|
13819
13902
|
var POLL_MS = 300;
|
|
13820
13903
|
var STALE_MS = 20 * 6e4;
|
|
13821
13904
|
function machineLockPath(key, dir = tmpdir()) {
|
|
13822
|
-
return
|
|
13905
|
+
return join27(dir, `swarm-prepare-${createHash2("sha1").update(key).digest("hex").slice(0, 16)}.lock`);
|
|
13823
13906
|
}
|
|
13824
13907
|
function defaultTryCreate(path, content) {
|
|
13825
13908
|
try {
|
|
@@ -13880,8 +13963,8 @@ init_config();
|
|
|
13880
13963
|
init_config();
|
|
13881
13964
|
import { createHash as createHash3 } from "crypto";
|
|
13882
13965
|
import { cp, link, lstat, mkdir as mkdir2, readdir, readlink, rename as rename2, rm as rm2, stat, symlink, utimes, writeFile as writeFile2 } from "fs/promises";
|
|
13883
|
-
import { existsSync as existsSync15, readFileSync as
|
|
13884
|
-
import { join as
|
|
13966
|
+
import { existsSync as existsSync15, readFileSync as readFileSync21 } from "fs";
|
|
13967
|
+
import { join as join28 } from "path";
|
|
13885
13968
|
function fingerprint(parts) {
|
|
13886
13969
|
const h = createHash3("sha256");
|
|
13887
13970
|
for (const p of parts) {
|
|
@@ -13895,8 +13978,8 @@ async function cloneTree(src, dst) {
|
|
|
13895
13978
|
const entries = await readdir(src, { withFileTypes: true });
|
|
13896
13979
|
await Promise.all(
|
|
13897
13980
|
entries.map(async (e) => {
|
|
13898
|
-
const from =
|
|
13899
|
-
const to =
|
|
13981
|
+
const from = join28(src, e.name);
|
|
13982
|
+
const to = join28(dst, e.name);
|
|
13900
13983
|
if (e.isDirectory()) return cloneTree(from, to);
|
|
13901
13984
|
if (e.isSymbolicLink()) {
|
|
13902
13985
|
return symlink(await readlink(from), to).catch(() => cp(from, to, { recursive: true, verbatimSymlinks: true }));
|
|
@@ -13909,11 +13992,11 @@ function cacheRoot(io) {
|
|
|
13909
13992
|
return io.root ?? ENV_CACHE_DIR;
|
|
13910
13993
|
}
|
|
13911
13994
|
function snapshotDir(io, key) {
|
|
13912
|
-
return
|
|
13995
|
+
return join28(cacheRoot(io), key);
|
|
13913
13996
|
}
|
|
13914
13997
|
function readManifest(dir) {
|
|
13915
13998
|
try {
|
|
13916
|
-
const parsed = JSON.parse(
|
|
13999
|
+
const parsed = JSON.parse(readFileSync21(join28(dir, "manifest.json"), "utf8"));
|
|
13917
14000
|
if (!parsed || typeof parsed !== "object") return null;
|
|
13918
14001
|
const m = parsed;
|
|
13919
14002
|
if (typeof m.key !== "string" || !Array.isArray(m.dirs)) return null;
|
|
@@ -13926,7 +14009,7 @@ function readManifest(dir) {
|
|
|
13926
14009
|
}
|
|
13927
14010
|
function hasEnvSnapshot(key, io = {}) {
|
|
13928
14011
|
const exists = io.exists ?? existsSync15;
|
|
13929
|
-
return exists(
|
|
14012
|
+
return exists(join28(snapshotDir(io, key), "manifest.json"));
|
|
13930
14013
|
}
|
|
13931
14014
|
async function restoreEnvSnapshot(worktree, key, io = {}) {
|
|
13932
14015
|
const exists = io.exists ?? existsSync15;
|
|
@@ -13938,13 +14021,13 @@ async function restoreEnvSnapshot(worktree, key, io = {}) {
|
|
|
13938
14021
|
try {
|
|
13939
14022
|
for (let i = 0; i < manifest.dirs.length; i++) {
|
|
13940
14023
|
const rel = manifest.dirs[i] ?? "";
|
|
13941
|
-
const target =
|
|
14024
|
+
const target = join28(worktree, rel);
|
|
13942
14025
|
if (exists(target)) continue;
|
|
13943
|
-
await clone(
|
|
14026
|
+
await clone(join28(dir, "trees", String(i)), target);
|
|
13944
14027
|
made.push(rel);
|
|
13945
14028
|
}
|
|
13946
14029
|
} catch {
|
|
13947
|
-
for (const rel of made) await rm2(
|
|
14030
|
+
for (const rel of made) await rm2(join28(worktree, rel), { recursive: true, force: true }).catch(() => {
|
|
13948
14031
|
});
|
|
13949
14032
|
return null;
|
|
13950
14033
|
}
|
|
@@ -13960,16 +14043,16 @@ async function saveEnvSnapshot(worktree, key, dirs, io = {}) {
|
|
|
13960
14043
|
const exists = io.exists ?? existsSync15;
|
|
13961
14044
|
const clone = io.clone ?? cloneTree;
|
|
13962
14045
|
if (hasEnvSnapshot(key, io)) return true;
|
|
13963
|
-
const present = dirs.filter((rel) => exists(
|
|
14046
|
+
const present = dirs.filter((rel) => exists(join28(worktree, rel)));
|
|
13964
14047
|
if (!present.length) return false;
|
|
13965
14048
|
const root = cacheRoot(io);
|
|
13966
|
-
const tmp =
|
|
14049
|
+
const tmp = join28(root, `.tmp-${key}-${process.pid}`);
|
|
13967
14050
|
try {
|
|
13968
14051
|
await rm2(tmp, { recursive: true, force: true });
|
|
13969
|
-
await mkdir2(
|
|
13970
|
-
for (let i = 0; i < present.length; i++) await clone(
|
|
14052
|
+
await mkdir2(join28(tmp, "trees"), { recursive: true });
|
|
14053
|
+
for (let i = 0; i < present.length; i++) await clone(join28(worktree, present[i] ?? ""), join28(tmp, "trees", String(i)));
|
|
13971
14054
|
const manifest = { key, dirs: present, createdAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
13972
|
-
await writeFile2(
|
|
14055
|
+
await writeFile2(join28(tmp, "manifest.json"), JSON.stringify(manifest, null, 2));
|
|
13973
14056
|
await rename2(tmp, snapshotDir(io, key));
|
|
13974
14057
|
return true;
|
|
13975
14058
|
} catch {
|
|
@@ -13989,13 +14072,13 @@ async function pruneEnvSnapshots(io = {}) {
|
|
|
13989
14072
|
}
|
|
13990
14073
|
const withTime = [];
|
|
13991
14074
|
for (const name of names) {
|
|
13992
|
-
const s = await stat(
|
|
14075
|
+
const s = await stat(join28(root, name)).catch(() => null);
|
|
13993
14076
|
if (s) withTime.push({ name, mtime: s.mtimeMs });
|
|
13994
14077
|
}
|
|
13995
14078
|
withTime.sort((a, b) => b.mtime - a.mtime);
|
|
13996
14079
|
let removed = 0;
|
|
13997
14080
|
for (const { name } of withTime.slice(Math.max(0, keep))) {
|
|
13998
|
-
await rm2(
|
|
14081
|
+
await rm2(join28(root, name), { recursive: true, force: true }).catch(() => {
|
|
13999
14082
|
});
|
|
14000
14083
|
removed++;
|
|
14001
14084
|
}
|
|
@@ -14011,9 +14094,9 @@ async function sweepEnvCacheTemp(io = {}) {
|
|
|
14011
14094
|
}
|
|
14012
14095
|
let removed = 0;
|
|
14013
14096
|
for (const name of names) {
|
|
14014
|
-
const s = await lstat(
|
|
14097
|
+
const s = await lstat(join28(root, name)).catch(() => null);
|
|
14015
14098
|
if (!s || Date.now() - s.mtimeMs < 60 * 6e4) continue;
|
|
14016
|
-
await rm2(
|
|
14099
|
+
await rm2(join28(root, name), { recursive: true, force: true }).catch(() => {
|
|
14017
14100
|
});
|
|
14018
14101
|
removed++;
|
|
14019
14102
|
}
|
|
@@ -14040,7 +14123,7 @@ async function runCommand(cmd, worktree) {
|
|
|
14040
14123
|
}
|
|
14041
14124
|
function safeReadText(p) {
|
|
14042
14125
|
try {
|
|
14043
|
-
return
|
|
14126
|
+
return readFileSync22(p, "utf8");
|
|
14044
14127
|
} catch {
|
|
14045
14128
|
return null;
|
|
14046
14129
|
}
|
|
@@ -14082,19 +14165,19 @@ function overridePlan(override) {
|
|
|
14082
14165
|
function detectPackageManager(worktree, io = {}) {
|
|
14083
14166
|
const exists = io.exists ?? existsSync16;
|
|
14084
14167
|
const readText = io.readText ?? safeReadText;
|
|
14085
|
-
const hasPkgJson = exists(
|
|
14168
|
+
const hasPkgJson = exists(join29(worktree, "package.json"));
|
|
14086
14169
|
if (!hasPkgJson) {
|
|
14087
|
-
if (exists(
|
|
14170
|
+
if (exists(join29(worktree, "deno.json")) || exists(join29(worktree, "deno.jsonc")) || exists(join29(worktree, "deno.lock"))) return "deno";
|
|
14088
14171
|
return null;
|
|
14089
14172
|
}
|
|
14090
|
-
const pkg = readJson(readText,
|
|
14173
|
+
const pkg = readJson(readText, join29(worktree, "package.json"));
|
|
14091
14174
|
const declared = typeof pkg?.packageManager === "string" ? pkg.packageManager.split("@")[0] : void 0;
|
|
14092
14175
|
if (declared === "pnpm" || declared === "bun" || declared === "npm" || declared === "yarn") return declared;
|
|
14093
|
-
if (exists(
|
|
14094
|
-
if (exists(
|
|
14095
|
-
if (exists(
|
|
14096
|
-
if (exists(
|
|
14097
|
-
if (exists(
|
|
14176
|
+
if (exists(join29(worktree, "bun.lock")) || exists(join29(worktree, "bun.lockb"))) return "bun";
|
|
14177
|
+
if (exists(join29(worktree, "pnpm-lock.yaml"))) return "pnpm";
|
|
14178
|
+
if (exists(join29(worktree, "yarn.lock"))) return "yarn";
|
|
14179
|
+
if (exists(join29(worktree, "package-lock.json"))) return "npm";
|
|
14180
|
+
if (exists(join29(worktree, "deno.lock"))) return "deno";
|
|
14098
14181
|
return "npm";
|
|
14099
14182
|
}
|
|
14100
14183
|
function jsInstallCommand(pm) {
|
|
@@ -14158,7 +14241,7 @@ function detectPlan(worktree, io) {
|
|
|
14158
14241
|
// node_modules на месте — установку пропускаем (быстрый путь переиспользованного worktree).
|
|
14159
14242
|
// У deno каталога может не быть вовсе (кэш в DENO_DIR) — тогда `deno install` отработает
|
|
14160
14243
|
// заново, но он дешёвый: тянет из того же общего кэша.
|
|
14161
|
-
{ label: `${pm} install`, run: jsInstallCommand(pm), skipIfExists:
|
|
14244
|
+
{ label: `${pm} install`, run: jsInstallCommand(pm), skipIfExists: join29(worktree, "node_modules"), source: "detect" }
|
|
14162
14245
|
];
|
|
14163
14246
|
for (const target of workspaceBuildTargets(worktree, io)) {
|
|
14164
14247
|
commands.push({ label: `\u0441\u0431\u043E\u0440\u043A\u0430 ${target.name}`, run: jsRunScript(pm, "build"), cwd: target.dir, source: "detect" });
|
|
@@ -14167,12 +14250,12 @@ function detectPlan(worktree, io) {
|
|
|
14167
14250
|
return { source: "detect", ecosystem: `node/${pm}`, commands };
|
|
14168
14251
|
}
|
|
14169
14252
|
for (const marker of ECOSYSTEM_MARKERS) {
|
|
14170
|
-
const hit = marker.files.some((f) => exists(
|
|
14253
|
+
const hit = marker.files.some((f) => exists(join29(worktree, f))) || marker.ext !== void 0 && listFiles(worktree).some((n) => n.endsWith(marker.ext));
|
|
14171
14254
|
if (!hit) continue;
|
|
14172
14255
|
let ecosystem = marker.ecosystem;
|
|
14173
14256
|
let command = marker.command;
|
|
14174
14257
|
for (const refine of marker.refine ?? []) {
|
|
14175
|
-
if (!exists(
|
|
14258
|
+
if (!exists(join29(worktree, refine.file))) continue;
|
|
14176
14259
|
ecosystem = refine.ecosystem;
|
|
14177
14260
|
command = refine.command;
|
|
14178
14261
|
break;
|
|
@@ -14229,12 +14312,12 @@ var CI_INSTALL_PATTERNS = [
|
|
|
14229
14312
|
function ciWorkflowPlan(worktree, io) {
|
|
14230
14313
|
const readText = io.readText ?? safeReadText;
|
|
14231
14314
|
const listFiles = io.listFiles ?? safeListFiles;
|
|
14232
|
-
const dir =
|
|
14315
|
+
const dir = join29(worktree, ".github", "workflows");
|
|
14233
14316
|
const files = listFiles(dir).filter((n) => n.endsWith(".yml") || n.endsWith(".yaml"));
|
|
14234
14317
|
const seen = /* @__PURE__ */ new Set();
|
|
14235
14318
|
const commands = [];
|
|
14236
14319
|
for (const name of files.sort()) {
|
|
14237
|
-
const yaml = readText(
|
|
14320
|
+
const yaml = readText(join29(dir, name));
|
|
14238
14321
|
if (yaml === null) continue;
|
|
14239
14322
|
for (const raw of workflowRunLines(yaml)) {
|
|
14240
14323
|
const line = raw.replace(/\s+/g, " ").trim();
|
|
@@ -14249,7 +14332,7 @@ function ciWorkflowPlan(worktree, io) {
|
|
|
14249
14332
|
return commands.length ? { source: "ci-workflow", ecosystem: "ci-\u043A\u043E\u043D\u0444\u0438\u0433", commands } : null;
|
|
14250
14333
|
}
|
|
14251
14334
|
function workspaceGlobs(worktree, readText) {
|
|
14252
|
-
const yaml = readText(
|
|
14335
|
+
const yaml = readText(join29(worktree, "pnpm-workspace.yaml"));
|
|
14253
14336
|
if (yaml !== null) {
|
|
14254
14337
|
const globs = [];
|
|
14255
14338
|
let inPackages = false;
|
|
@@ -14269,7 +14352,7 @@ function workspaceGlobs(worktree, readText) {
|
|
|
14269
14352
|
}
|
|
14270
14353
|
if (globs.length) return globs;
|
|
14271
14354
|
}
|
|
14272
|
-
const pkg = readJson(readText,
|
|
14355
|
+
const pkg = readJson(readText, join29(worktree, "package.json"));
|
|
14273
14356
|
const ws = pkg?.workspaces;
|
|
14274
14357
|
const list = Array.isArray(ws) ? ws : Array.isArray(ws?.packages) ? ws.packages : [];
|
|
14275
14358
|
return list.filter((g) => typeof g === "string");
|
|
@@ -14280,14 +14363,14 @@ function workspaceDirs(worktree, globs, io) {
|
|
|
14280
14363
|
if (glob.startsWith("!")) continue;
|
|
14281
14364
|
const star = glob.indexOf("*");
|
|
14282
14365
|
if (star === -1) {
|
|
14283
|
-
const dir =
|
|
14284
|
-
if (io.exists(
|
|
14366
|
+
const dir = join29(worktree, glob);
|
|
14367
|
+
if (io.exists(join29(dir, "package.json"))) dirs.add(dir);
|
|
14285
14368
|
continue;
|
|
14286
14369
|
}
|
|
14287
|
-
const base3 =
|
|
14370
|
+
const base3 = join29(worktree, glob.slice(0, star).replace(/\/$/, ""));
|
|
14288
14371
|
for (const name of io.listDirs(base3)) {
|
|
14289
|
-
const dir =
|
|
14290
|
-
if (io.exists(
|
|
14372
|
+
const dir = join29(base3, name);
|
|
14373
|
+
if (io.exists(join29(dir, "package.json"))) dirs.add(dir);
|
|
14291
14374
|
}
|
|
14292
14375
|
}
|
|
14293
14376
|
return [...dirs];
|
|
@@ -14315,11 +14398,11 @@ function workspaceBuildTargets(worktree, io = {}) {
|
|
|
14315
14398
|
if (!globs.length) return [];
|
|
14316
14399
|
const pkgs = [];
|
|
14317
14400
|
for (const dir of workspaceDirs(worktree, globs, { exists, listDirs })) {
|
|
14318
|
-
const pkg = readJson(readText,
|
|
14401
|
+
const pkg = readJson(readText, join29(dir, "package.json"));
|
|
14319
14402
|
if (!pkg || typeof pkg.name !== "string") continue;
|
|
14320
14403
|
const scripts = pkg.scripts ?? {};
|
|
14321
14404
|
const entries = entryPaths(pkg);
|
|
14322
|
-
const needsBuild = typeof scripts.build === "string" && entries.length > 0 && entries.some((e) => !exists(
|
|
14405
|
+
const needsBuild = typeof scripts.build === "string" && entries.length > 0 && entries.some((e) => !exists(join29(dir, e)));
|
|
14323
14406
|
const deps = Object.keys({ ...pkg.dependencies ?? {}, ...pkg.devDependencies ?? {} });
|
|
14324
14407
|
pkgs.push({ name: pkg.name, dir, deps, needsBuild });
|
|
14325
14408
|
}
|
|
@@ -14347,7 +14430,7 @@ function devDatabaseUrl(worktree, io = {}) {
|
|
|
14347
14430
|
const fromEnv = (io.env ?? process.env).DATABASE_URL;
|
|
14348
14431
|
if (fromEnv && fromEnv.trim()) return fromEnv.trim();
|
|
14349
14432
|
for (const file of [".env", ".env.example"]) {
|
|
14350
|
-
const raw = readText(
|
|
14433
|
+
const raw = readText(join29(worktree, file));
|
|
14351
14434
|
if (raw === null) continue;
|
|
14352
14435
|
const m = /^\s*(?:export\s+)?DATABASE_URL\s*=\s*(.*)$/m.exec(raw);
|
|
14353
14436
|
const value = (m?.[1] ?? "").trim().replace(/^['"]|['"]$/g, "");
|
|
@@ -14367,7 +14450,7 @@ function prismaPackages(worktree, io) {
|
|
|
14367
14450
|
const readText = io.readText ?? safeReadText;
|
|
14368
14451
|
const listDirs = io.listDirs ?? safeListDirs;
|
|
14369
14452
|
const dirs = [worktree, ...workspaceDirs(worktree, workspaceGlobs(worktree, readText), { exists, listDirs })];
|
|
14370
|
-
return dirs.filter((dir) => exists(
|
|
14453
|
+
return dirs.filter((dir) => exists(join29(dir, "prisma", "schema.prisma")) && listDirs(join29(dir, "prisma", "migrations")).length > 0);
|
|
14371
14454
|
}
|
|
14372
14455
|
function jsExecBin(pm, command) {
|
|
14373
14456
|
switch (pm) {
|
|
@@ -14404,18 +14487,18 @@ function envCachePlan(worktree, io = {}) {
|
|
|
14404
14487
|
if (!pm) return null;
|
|
14405
14488
|
const parts = [`pm:${pm}`];
|
|
14406
14489
|
for (const name of ENV_DEFINING_FILES) {
|
|
14407
|
-
const raw = readText(
|
|
14490
|
+
const raw = readText(join29(worktree, name));
|
|
14408
14491
|
if (raw !== null) parts.push(`${name}
|
|
14409
14492
|
${raw}`);
|
|
14410
14493
|
}
|
|
14411
14494
|
const pkgDirs = workspaceDirs(worktree, workspaceGlobs(worktree, readText), { exists, listDirs });
|
|
14412
14495
|
const rels = pkgDirs.map((dir) => dir.slice(worktree.length + 1)).sort();
|
|
14413
14496
|
for (const rel of ["", ...rels]) {
|
|
14414
|
-
const raw = readText(
|
|
14497
|
+
const raw = readText(join29(worktree, rel, "package.json"));
|
|
14415
14498
|
if (raw !== null) parts.push(`${rel}/package.json
|
|
14416
14499
|
${raw}`);
|
|
14417
14500
|
}
|
|
14418
|
-
return { key: fingerprint(parts), dirs: ["node_modules", ...rels.map((rel) =>
|
|
14501
|
+
return { key: fingerprint(parts), dirs: ["node_modules", ...rels.map((rel) => join29(rel, "node_modules"))] };
|
|
14419
14502
|
}
|
|
14420
14503
|
function planPrepare(worktree, io = {}) {
|
|
14421
14504
|
const plan = overridePlan(io.override) ?? detectPlan(worktree, io) ?? ciWorkflowPlan(worktree, io);
|
|
@@ -14440,7 +14523,7 @@ async function ensureWorktreeDeps(worktree, io = {}) {
|
|
|
14440
14523
|
restored: [],
|
|
14441
14524
|
cached: false
|
|
14442
14525
|
};
|
|
14443
|
-
if (cachePlan && !exists(
|
|
14526
|
+
if (cachePlan && !exists(join29(worktree, "node_modules"))) {
|
|
14444
14527
|
report.restored = await restoreEnvSnapshot(worktree, cachePlan.key, cacheIO) ?? [];
|
|
14445
14528
|
}
|
|
14446
14529
|
const plan = planPrepare(worktree, io);
|
|
@@ -14528,7 +14611,7 @@ function depsPromptNotice(report) {
|
|
|
14528
14611
|
// src/orchestrator.ts
|
|
14529
14612
|
init_config();
|
|
14530
14613
|
import { existsSync as existsSync17, mkdirSync as mkdirSync11, rmSync as rmSync3 } from "fs";
|
|
14531
|
-
import { join as
|
|
14614
|
+
import { join as join30, dirname as dirname4 } from "path";
|
|
14532
14615
|
function droneLaunchedText(workdir, pid) {
|
|
14533
14616
|
return `\u0434\u0440\u043E\u043D \u0437\u0430\u043F\u0443\u0449\u0435\u043D \u0432 ${workdir} (pid ${pid})`;
|
|
14534
14617
|
}
|
|
@@ -14544,7 +14627,7 @@ function droneLaunchedPid(text) {
|
|
|
14544
14627
|
return m ? Number(m[1]) : null;
|
|
14545
14628
|
}
|
|
14546
14629
|
function repolessRunDir(worktreesDir, taskSlug) {
|
|
14547
|
-
return
|
|
14630
|
+
return join30(dirname4(worktreesDir), "runs", taskSlug);
|
|
14548
14631
|
}
|
|
14549
14632
|
var WORKTREE_HELD_STATUSES = /* @__PURE__ */ new Set(["running", "blocked", "review", "paused", "storm_dead"]);
|
|
14550
14633
|
function worktreePathHeldLive(db, path, exceptRunId) {
|
|
@@ -14826,7 +14909,7 @@ function parkReasonUnretriable(reason) {
|
|
|
14826
14909
|
// package.json
|
|
14827
14910
|
var package_default = {
|
|
14828
14911
|
name: "@taskless-app/swarm",
|
|
14829
|
-
version: "0.6.
|
|
14912
|
+
version: "0.6.100",
|
|
14830
14913
|
type: "module",
|
|
14831
14914
|
description: "Local control plane for a fleet of AI coding agents (drones), coordinating through Taskless. The overmind runs the swarm.",
|
|
14832
14915
|
keywords: [
|
|
@@ -14878,7 +14961,7 @@ var package_default = {
|
|
|
14878
14961
|
undici: "^7.30.1",
|
|
14879
14962
|
zod: "3.25.76"
|
|
14880
14963
|
},
|
|
14881
|
-
gitHead: "
|
|
14964
|
+
gitHead: "a0643b2118fce225b5afbe7ce9c1afbe7cd25d39"
|
|
14882
14965
|
};
|
|
14883
14966
|
|
|
14884
14967
|
// src/version.ts
|
|
@@ -16001,7 +16084,7 @@ init_git();
|
|
|
16001
16084
|
|
|
16002
16085
|
// src/diff.ts
|
|
16003
16086
|
import { statSync as statSync15 } from "fs";
|
|
16004
|
-
import { join as
|
|
16087
|
+
import { join as join35 } from "path";
|
|
16005
16088
|
import { $ as $5 } from "execa";
|
|
16006
16089
|
var MAX_FILES = 200;
|
|
16007
16090
|
var MAX_LINES_PER_FILE = 1500;
|
|
@@ -16169,7 +16252,7 @@ async function collectRunDiff(worktree, opts = {}) {
|
|
|
16169
16252
|
files.push(pf);
|
|
16170
16253
|
}
|
|
16171
16254
|
}
|
|
16172
|
-
files.sort((a, b) => mtime(
|
|
16255
|
+
files.sort((a, b) => mtime(join35(worktree, b.path)) - mtime(join35(worktree, a.path)));
|
|
16173
16256
|
const truncatedFiles = files.length > MAX_FILES;
|
|
16174
16257
|
if (truncatedFiles) files = files.slice(0, MAX_FILES);
|
|
16175
16258
|
const added = files.reduce((s, f) => s + f.added, 0);
|
|
@@ -17503,6 +17586,10 @@ var AnomalyTracker = class {
|
|
|
17503
17586
|
this.fires.delete(key);
|
|
17504
17587
|
this.persist();
|
|
17505
17588
|
}
|
|
17589
|
+
/** Когда по этому ключу последний раз ушёл сигнал. Нет — ещё не звонили. Кулдаун rearm не сбрасывает. */
|
|
17590
|
+
lastFiredMs(key) {
|
|
17591
|
+
return this.lastFiredAt.get(key);
|
|
17592
|
+
}
|
|
17506
17593
|
/**
|
|
17507
17594
|
* Пора ли снова спросить внешний мир (gh) про ключ (TAS-1100): не чаще everyMs.
|
|
17508
17595
|
* Только память: после рестарта первый вопрос уйдёт сразу — один вызов на прогон, не поток.
|
|
@@ -18677,21 +18764,21 @@ async function prodClearMergeIntent(runId, deps = {}) {
|
|
|
18677
18764
|
|
|
18678
18765
|
// src/envGate.ts
|
|
18679
18766
|
import { existsSync as existsSync20 } from "fs";
|
|
18680
|
-
import { join as
|
|
18767
|
+
import { join as join37 } from "path";
|
|
18681
18768
|
import { createConnection } from "net";
|
|
18682
18769
|
import { execa as execa2 } from "execa";
|
|
18683
18770
|
|
|
18684
18771
|
// src/platform.ts
|
|
18685
18772
|
init_src();
|
|
18686
|
-
import { accessSync as accessSync2, constants as constants2, existsSync as existsSync19, readFileSync as
|
|
18687
|
-
import { delimiter as delimiter2, join as
|
|
18773
|
+
import { accessSync as accessSync2, constants as constants2, existsSync as existsSync19, readFileSync as readFileSync26, realpathSync as realpathSync3 } from "fs";
|
|
18774
|
+
import { delimiter as delimiter2, join as join36, posix as posix2, win32 } from "path";
|
|
18688
18775
|
function resolveCommandPath(name, env = process.env, platform = process.platform) {
|
|
18689
18776
|
if (name.includes("/") || name.includes("\\")) return existsSync19(name) ? name : null;
|
|
18690
18777
|
const dirs = (env.PATH ?? env.Path ?? "").split(delimiter2).filter(Boolean);
|
|
18691
18778
|
const exts = platform === "win32" ? (env.PATHEXT ?? ".EXE;.CMD;.BAT").split(";").filter(Boolean) : [""];
|
|
18692
18779
|
for (const dir of dirs) {
|
|
18693
18780
|
for (const ext of exts) {
|
|
18694
|
-
const candidate =
|
|
18781
|
+
const candidate = join36(dir, name + ext);
|
|
18695
18782
|
if (existsSync19(candidate)) return candidate;
|
|
18696
18783
|
}
|
|
18697
18784
|
}
|
|
@@ -18862,7 +18949,7 @@ var COMPOSE_MARKERS = [
|
|
|
18862
18949
|
];
|
|
18863
18950
|
function detectRequirements(repo, io = {}) {
|
|
18864
18951
|
const exists = io.exists ?? existsSync20;
|
|
18865
|
-
const marker = COMPOSE_MARKERS.find((f) => exists(
|
|
18952
|
+
const marker = COMPOSE_MARKERS.find((f) => exists(join37(repo, f)));
|
|
18866
18953
|
return marker ? [{ kind: "docker", raw: `docker (\u0434\u0435\u0442\u0435\u043A\u0442: ${marker})` }] : [];
|
|
18867
18954
|
}
|
|
18868
18955
|
function resolveRequirements(repo, declared, io = {}) {
|
|
@@ -20689,14 +20776,14 @@ function closeWebServer(server) {
|
|
|
20689
20776
|
|
|
20690
20777
|
// src/hostCommands.ts
|
|
20691
20778
|
init_src();
|
|
20692
|
-
import { readFileSync as
|
|
20693
|
-
import { join as
|
|
20779
|
+
import { readFileSync as readFileSync27, renameSync as renameSync10, writeFileSync as writeFileSync17 } from "fs";
|
|
20780
|
+
import { join as join38 } from "path";
|
|
20694
20781
|
function hostCommandStatePath(home) {
|
|
20695
|
-
return
|
|
20782
|
+
return join38(home, "host-command.json");
|
|
20696
20783
|
}
|
|
20697
20784
|
function readState(path) {
|
|
20698
20785
|
try {
|
|
20699
|
-
return JSON.parse(
|
|
20786
|
+
return JSON.parse(readFileSync27(path, "utf8"));
|
|
20700
20787
|
} catch {
|
|
20701
20788
|
return {};
|
|
20702
20789
|
}
|
|
@@ -20867,7 +20954,7 @@ async function doRestart(cmd, opts, note) {
|
|
|
20867
20954
|
// src/selfUpdate.ts
|
|
20868
20955
|
init_git();
|
|
20869
20956
|
import { existsSync as existsSync21 } from "fs";
|
|
20870
|
-
import { join as
|
|
20957
|
+
import { join as join39 } from "path";
|
|
20871
20958
|
import { $ as $6 } from "execa";
|
|
20872
20959
|
|
|
20873
20960
|
// src/cliIo.ts
|
|
@@ -20929,7 +21016,7 @@ async function runSelfUpdate(io) {
|
|
|
20929
21016
|
};
|
|
20930
21017
|
}
|
|
20931
21018
|
await io.onStep("install", "\u0441\u0442\u0430\u0432\u043B\u044E \u0437\u0430\u0432\u0438\u0441\u0438\u043C\u043E\u0441\u0442\u0438");
|
|
20932
|
-
if (!exists(
|
|
21019
|
+
if (!exists(join39(repo, "pnpm-lock.yaml"))) {
|
|
20933
21020
|
return { ok: false, step: "install", message: "\u0432 \u0440\u0435\u043F\u043E\u0437\u0438\u0442\u043E\u0440\u0438\u0438 \u0434\u0435\u043C\u043E\u043D\u0430 \u043D\u0435\u0442 pnpm-lock.yaml \u2014 \u043E\u0431\u043D\u043E\u0432\u043B\u044F\u0442\u044C \u0435\u0433\u043E \u044D\u0442\u0438\u043C \u043F\u0443\u0442\u0451\u043C \u043D\u0435 \u0431\u0435\u0440\u0443\u0441\u044C" };
|
|
20934
21021
|
}
|
|
20935
21022
|
const installed2 = await run2("pnpm", ["install", "--frozen-lockfile"], repo);
|
|
@@ -21104,19 +21191,19 @@ async function fetchExternalStorm(url, opts = {}) {
|
|
|
21104
21191
|
}
|
|
21105
21192
|
|
|
21106
21193
|
// src/anomalyState.ts
|
|
21107
|
-
import { existsSync as existsSync22, readFileSync as
|
|
21108
|
-
import { join as
|
|
21194
|
+
import { existsSync as existsSync22, readFileSync as readFileSync28, renameSync as renameSync11, writeFileSync as writeFileSync18 } from "fs";
|
|
21195
|
+
import { join as join40 } from "path";
|
|
21109
21196
|
var KEY_TTL_MS = 7 * 24 * 60 * 6e4;
|
|
21110
21197
|
var MAX_RESOLVED = 200;
|
|
21111
21198
|
function emptyState() {
|
|
21112
21199
|
return { since: {}, lastFiredAt: {}, fires: {}, resolved: [], stopQuiet: null };
|
|
21113
21200
|
}
|
|
21114
21201
|
function anomalyStatePath(home) {
|
|
21115
|
-
return
|
|
21202
|
+
return join40(home, "anomaly-state.json");
|
|
21116
21203
|
}
|
|
21117
21204
|
function loadAnomalyState(home, now = Date.now(), io = {}) {
|
|
21118
21205
|
const exists = io.exists ?? existsSync22;
|
|
21119
|
-
const readFile3 = io.readFile ?? ((p) =>
|
|
21206
|
+
const readFile3 = io.readFile ?? ((p) => readFileSync28(p, "utf8"));
|
|
21120
21207
|
const path = anomalyStatePath(home);
|
|
21121
21208
|
if (!exists(path)) return emptyState();
|
|
21122
21209
|
try {
|
|
@@ -22180,6 +22267,10 @@ async function spawnVerifiersForOpenPrs(deps, _stormActive) {
|
|
|
22180
22267
|
noteDraftHold(run2);
|
|
22181
22268
|
continue;
|
|
22182
22269
|
}
|
|
22270
|
+
if (grokBalanceBlocksChecker(deps, run2)) {
|
|
22271
|
+
noteGrokBalanceSkip(deps, run2, "\u0432\u0435\u0440\u0438\u0444\u0438\u043A\u0430\u0442\u043E\u0440\u0430");
|
|
22272
|
+
continue;
|
|
22273
|
+
}
|
|
22183
22274
|
await deps.spawnVerifier(run2, st?.files ?? []);
|
|
22184
22275
|
narrate(deps, `PR ${droneLabel(run2)} \u043E\u0442\u043A\u0440\u044B\u0442 \u2014 \u043F\u043E\u0434\u043D\u0438\u043C\u0430\u044E \u0432\u0435\u0440\u0438\u0444\u0438\u043A\u0430\u0442\u043E\u0440\u0430: \u043F\u0443\u0441\u0442\u044C \u043F\u043E\u043F\u0440\u043E\u0431\u0443\u0435\u0442 \u043E\u043F\u0440\u043E\u0432\u0435\u0440\u0433\u043D\u0443\u0442\u044C \u0437\u0430\u044F\u0432\u043B\u0435\u043D\u043D\u043E\u0435.`);
|
|
22185
22276
|
} catch (e) {
|
|
@@ -22241,13 +22332,13 @@ function buildCiReadyNudge(prUrl, over) {
|
|
|
22241
22332
|
].join("\n");
|
|
22242
22333
|
}
|
|
22243
22334
|
var SUBMISSION_REVIEW_STEP = "2. `/code-review --fix` \u2014 \u043F\u0440\u043E\u0433\u043E\u043D\u0438 \u0440\u0435\u0432\u044C\u044E \u0441\u0432\u043E\u0435\u0433\u043E \u0434\u0438\u0444\u0444\u0430, \u043A\u043B\u0430\u0441\u0441\u044B \u0434\u0435\u0444\u0435\u043A\u0442\u043E\u0432 \u2014 \u0432 skill `swarm-drone:taskless-review`; \u043F\u0440\u0438\u043C\u0435\u043D\u0451\u043D\u043D\u044B\u0435 \u043F\u0440\u0430\u0432\u043A\u0438 \u043F\u0435\u0440\u0435\u0447\u0438\u0442\u0430\u0439 \u0438 \u043F\u0435\u0440\u0435\u0443\u0431\u0435\u0434\u0438\u0441\u044C, \u0447\u0442\u043E \u043D\u0435 \u0441\u043B\u043E\u043C\u0430\u043B \u0444\u0438\u0447\u0443.";
|
|
22244
|
-
function dockerStandRules(prefix, homeDir =
|
|
22335
|
+
function dockerStandRules(prefix, homeDir = homedir10()) {
|
|
22245
22336
|
return `\u0421\u0432\u043E\u0438 \u043A\u043E\u043D\u0442\u0435\u0439\u043D\u0435\u0440\u044B \u043D\u0430\u0437\u044B\u0432\u0430\u0439 \u0441 \u043F\u0440\u0435\u0444\u0438\u043A\u0441\u043E\u043C ${prefix}: \`docker compose\` \u0431\u0435\u0437 \`-p\` \u0443\u0436\u0435 \u0435\u0433\u043E \u0431\u0435\u0440\u0451\u0442, \u0438\u043C\u0435\u043D\u0430 \u043A\u043E\u043D\u0442\u0435\u0439\u043D\u0435\u0440\u043E\u0432 \u2014 \`\${COMPOSE_PROJECT_NAME}-<\u0441\u0435\u0440\u0432\u0438\u0441>-1\`, \u043D\u0435 \u0438\u0437 README \u0440\u0435\u043F\u043E\u0437\u0438\u0442\u043E\u0440\u0438\u044F (\u0432 alex-gpt apps/e2e/README.md \u0437\u0430\u0448\u0438\u0442\u044B alexgpt-postgres-1 \u0438 alexgpt-redis-1). Compose \u043F\u043E\u0434\u043D\u0438\u043C\u0430\u0439 \u0442\u043E\u043B\u044C\u043A\u043E \u0438\u0437 \u0441\u0432\u043E\u0435\u0433\u043E worktree, \u043D\u0435 \u0438\u0437 /tmp. \u0414\u043B\u044F \`docker run\` \u2014 \`--name ${prefix}-pg --label taskless.swarm.home=${homeDir}\`. \u041F\u043E\u0440\u0442\u044B \u043F\u0443\u0431\u043B\u0438\u043A\u0443\u0439 \u0442\u043E\u043B\u044C\u043A\u043E \u043D\u0430 \`127.0.0.1\` (\`-p 127.0.0.1:<\u043F\u043E\u0440\u0442>:5432\`): Docker \u0438\u0434\u0451\u0442 \u043C\u0438\u043C\u043E \u0444\u0430\u0439\u0440\u0432\u043E\u043B\u0430, \u043E\u0442\u043A\u0440\u044B\u0442\u0443\u044E \u0431\u0430\u0437\u0443 \u0432\u0437\u043B\u0430\u043C\u044B\u0432\u0430\u044E\u0442 \u0437\u0430 \u0434\u043D\u0438.`;
|
|
22246
22337
|
}
|
|
22247
22338
|
function promptStandRule(worktree, slug) {
|
|
22248
22339
|
const raw = worktree && worktree.length > 0 ? worktree : slug;
|
|
22249
22340
|
const prefix = composeProjectPrefix(basename7(raw));
|
|
22250
|
-
return prefix ? dockerStandRules(prefix,
|
|
22341
|
+
return prefix ? dockerStandRules(prefix, homedir10()) : "";
|
|
22251
22342
|
}
|
|
22252
22343
|
function buildChangesFixPrompt(args) {
|
|
22253
22344
|
const { prUrl, slug, branch, base: base3, worktree, verdict } = args;
|
|
@@ -22439,10 +22530,10 @@ ${task.description}` : `\u0417\u0430\u0434\u0430\u0447\u0430 ${run2.task_slug} (
|
|
|
22439
22530
|
}
|
|
22440
22531
|
return parts.join("\n");
|
|
22441
22532
|
}
|
|
22442
|
-
var HERO_CHARTER_PATH =
|
|
22533
|
+
var HERO_CHARTER_PATH = join41(dirname6(THIS_FILE), "..", "docs", "HERO.md");
|
|
22443
22534
|
function buildHeroPrompt(task, run2, taskContext, attachmentsBlock) {
|
|
22444
22535
|
const name = run2.name || `#${run2.id}`;
|
|
22445
|
-
const charter =
|
|
22536
|
+
const charter = readFileSync29(HERO_CHARTER_PATH, "utf8");
|
|
22446
22537
|
const head = task ? `\u042D\u041F\u0418\u041A ${run2.task_slug}: ${task.title}
|
|
22447
22538
|
|
|
22448
22539
|
${task.description}` : `\u042D\u041F\u0418\u041A ${run2.task_slug} (\u0442\u0435\u043B\u043E \u043D\u0435\u0434\u043E\u0441\u0442\u0443\u043F\u043D\u043E \u2014 \u0440\u0430\u0431\u043E\u0442\u0430\u0439 \u043F\u043E slug \u0438 \u0437\u0434\u0440\u0430\u0432\u043E\u043C\u0443 \u0441\u043C\u044B\u0441\u043B\u0443).`;
|
|
@@ -22502,9 +22593,9 @@ function ciTrustLine(prUrl, verifyMode, ciClosed = null) {
|
|
|
22502
22593
|
}
|
|
22503
22594
|
return `\u041D\u0435 \u043F\u0435\u0440\u0435\u0433\u043E\u043D\u044F\u0439 \u0442\u0435\u0441\u0442-\u0441\u044C\u044E\u0442/typecheck \u0437\u0430\u043D\u043E\u0432\u043E \u2014 \u044D\u0442\u043E \u0443\u0436\u0435 \u0441\u0434\u0435\u043B\u0430\u043B CI \u043D\u0430 \u044D\u0442\u043E\u043C \u0436\u0435 \u043A\u043E\u043C\u043C\u0438\u0442\u0435 (\u0434\u0432\u043E\u0439\u043D\u043E\u0439 \u043F\u0440\u043E\u0433\u043E\u043D \u043D\u0430 \u043C\u0430\u0448\u0438\u043D\u0435 \u0432\u043B\u0430\u0434\u0435\u043B\u044C\u0446\u0430 \u043E\u0442\u043C\u0435\u043D\u0451\u043D, TASWM-249). \u041F\u0440\u043E\u0447\u0438\u0442\u0430\u0439 \u0435\u0433\u043E \u0440\u0435\u0437\u0443\u043B\u044C\u0442\u0430\u0442 \u0441\u0430\u043C: ${readChecks}. \u0414\u0430\u043B\u044C\u0448\u0435 \u0442\u0440\u0438 \u0440\u0430\u0437\u043D\u044B\u0445 \u0441\u043B\u0443\u0447\u0430\u044F: \u2460 \u0445\u043E\u0442\u044C \u043E\u0434\u0438\u043D \u0447\u0435\u043A \u0435\u0449\u0451 PENDING \u2014 \u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u0432\u043E\u043E\u0431\u0449\u0435 \u043D\u0435 \u0432\u044B\u043D\u043E\u0441\u0438: \u043D\u0435 \u043F\u043E\u0441\u0442\u0438 REQUEST CHANGES, \u043D\u0435 \u0437\u043E\u0432\u0438 done(), \u043F\u0440\u043E\u0441\u0442\u043E \u0437\u0430\u0432\u0435\u0440\u0448\u0438 \u0441\u0435\u0441\u0441\u0438\u044E \u043A\u0430\u043A \u0435\u0441\u0442\u044C \u2014 \u0440\u043E\u0439 \u0441\u0430\u043C \u0437\u0430\u043C\u0435\u0442\u0438\u0442, \u0447\u0442\u043E \u0442\u044B \u0436\u0434\u0451\u0448\u044C CI, \u0438 \u0440\u0430\u0437\u0431\u0443\u0434\u0438\u0442 \u0434\u043E\u0434\u0435\u043B\u0430\u0442\u044C \u0440\u0435\u0432\u044C\u044E, \u043A\u043E\u0433\u0434\u0430 \u0432\u0441\u0435 \u0447\u0435\u043A\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0442\u0441\u044F (\u044D\u0442\u043E \u0448\u0442\u0430\u0442\u043D\u044B\u0439 \u043F\u0443\u0442\u044C, \u043E\u043F\u0435\u0440\u0430\u0442\u043E\u0440\u0430 \u0437\u0432\u0430\u0442\u044C \u043D\u0435 \u043D\u0443\u0436\u043D\u043E). \u2461 \u0432\u0441\u0435 \u0447\u0435\u043A\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043B\u0438\u0441\u044C \u0438 \u0435\u0441\u0442\u044C FAIL \u2014 REQUEST CHANGES, \u043D\u0430\u0437\u043E\u0432\u0438 \u043F\u043E\u0438\u043C\u0451\u043D\u043D\u043E, \u0447\u0442\u043E \u0443\u043F\u0430\u043B\u043E. \u2462 \u043D\u0430 \u044D\u0442\u043E\u043C \u043A\u043E\u043C\u043C\u0438\u0442\u0435 \u0447\u0435\u043A\u043E\u0432 \u043D\u0435\u0442 \u0432\u043E\u0432\u0441\u0435 \u2014 \u0442\u043E \u0436\u0435, \u0447\u0442\u043E \u2460: \u0432\u0435\u0440\u0434\u0438\u043A\u0442 \u043D\u0435 \u0432\u044B\u043D\u043E\u0441\u0438, \u043D\u0435 \u043F\u0438\u0448\u0438 REQUEST CHANGES, \u043D\u0435 \u0437\u043E\u0432\u0438 done(), \u043F\u0440\u043E\u0441\u0442\u043E \u0437\u0430\u0432\u0435\u0440\u0448\u0438 \u0441\u0435\u0441\u0441\u0438\u044E. \u0427\u0435\u043A\u043E\u0432 \u043C\u043E\u0436\u0435\u0442 \u043D\u0435 \u0431\u044B\u0442\u044C, \u043F\u043E\u0442\u043E\u043C\u0443 \u0447\u0442\u043E \u0441\u0442\u0430\u0440\u044B\u0439 \u043F\u0440\u043E\u0433\u043E\u043D \u0442\u043E\u043B\u044C\u043A\u043E \u0447\u0442\u043E \u043E\u0442\u043C\u0435\u043D\u0451\u043D \u043D\u043E\u0432\u044B\u043C \u043F\u0443\u0448\u0435\u043C \u0438\u043B\u0438 \u0440\u0430\u043D\u043D\u0435\u0440\u044B \u0437\u0430\u043D\u044F\u0442\u044B. \u0420\u043E\u0439 \u0441\u0430\u043C \u0440\u0430\u0437\u0431\u0443\u0434\u0438\u0442, \u043A\u043E\u0433\u0434\u0430 \u0447\u0435\u043A\u0438 \u043F\u043E\u044F\u0432\u044F\u0442\u0441\u044F \u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0442\u0441\u044F, \u0438\u043B\u0438 \u0441\u043A\u0430\u0436\u0435\u0442, \u0447\u0442\u043E \u0438\u0445 \u043D\u0435 \u0431\u0443\u0434\u0435\u0442. ${dontTrustAuthor}`;
|
|
22504
22595
|
}
|
|
22505
|
-
var REVIEW_SKILL_PATH =
|
|
22596
|
+
var REVIEW_SKILL_PATH = join41(bundledRoleDir("drone"), "skills", "taskless-review", "SKILL.md");
|
|
22506
22597
|
function reviewDefectClasses(skillPath = REVIEW_SKILL_PATH) {
|
|
22507
|
-
const text =
|
|
22598
|
+
const text = readFileSync29(skillPath, "utf8");
|
|
22508
22599
|
const m = /^## Классы дефектов\n([\s\S]*?)(?=^## |(?![\s\S]))/m.exec(text);
|
|
22509
22600
|
if (!m) throw new Error(`${skillPath}: \u043D\u0435\u0442 \u0440\u0430\u0437\u0434\u0435\u043B\u0430 \xAB## \u041A\u043B\u0430\u0441\u0441\u044B \u0434\u0435\u0444\u0435\u043A\u0442\u043E\u0432\xBB \u2014 \u0444\u043E\u0440\u043C\u0430\u0442 skill taskless-review \u043F\u043E\u043C\u0435\u043D\u044F\u043B\u0441\u044F?`);
|
|
22510
22601
|
return `\u041A\u043B\u0430\u0441\u0441\u044B \u0434\u0435\u0444\u0435\u043A\u0442\u043E\u0432 (skill taskless-review):
|
|
@@ -23270,7 +23361,7 @@ function repoHasCi(deps, run2) {
|
|
|
23270
23361
|
function repoHasCiWorkflows(worktreePath, repo) {
|
|
23271
23362
|
for (const base3 of [worktreePath, repo]) {
|
|
23272
23363
|
if (!base3) continue;
|
|
23273
|
-
const dir =
|
|
23364
|
+
const dir = join41(base3, ".github", "workflows");
|
|
23274
23365
|
try {
|
|
23275
23366
|
if (readdirSync18(dir).some((f) => f.endsWith(".yml") || f.endsWith(".yaml"))) return true;
|
|
23276
23367
|
} catch {
|
|
@@ -23502,6 +23593,183 @@ function worktreeAndTranscriptAlive(deps, run2) {
|
|
|
23502
23593
|
function limitWaitCandidate(deps, run2) {
|
|
23503
23594
|
return deps.exitLimit?.(run2) ?? null;
|
|
23504
23595
|
}
|
|
23596
|
+
var grokBalanceResumedThisTick = /* @__PURE__ */ new Set();
|
|
23597
|
+
var grokBalanceProbes = /* @__PURE__ */ new WeakMap();
|
|
23598
|
+
var grokBalanceFixHeldThisTick = /* @__PURE__ */ new Set();
|
|
23599
|
+
var grokBalanceDeadMemo = null;
|
|
23600
|
+
function resetGrokBalanceTick() {
|
|
23601
|
+
grokBalanceResumedThisTick.clear();
|
|
23602
|
+
grokBalanceDeadMemo = null;
|
|
23603
|
+
grokBalanceFixHeldThisTick.clear();
|
|
23604
|
+
}
|
|
23605
|
+
function grokBalanceProbeMap(db) {
|
|
23606
|
+
let map = grokBalanceProbes.get(db);
|
|
23607
|
+
if (!map) {
|
|
23608
|
+
map = /* @__PURE__ */ new Map();
|
|
23609
|
+
grokBalanceProbes.set(db, map);
|
|
23610
|
+
}
|
|
23611
|
+
return map;
|
|
23612
|
+
}
|
|
23613
|
+
function grokLogShowsBalance(deps, run2) {
|
|
23614
|
+
const hit = limitWaitCandidate(deps, run2);
|
|
23615
|
+
return hit?.executor === "grok" && hit.balance === true;
|
|
23616
|
+
}
|
|
23617
|
+
function grokBalanceProbeOpen(deps, runId) {
|
|
23618
|
+
return grokBalanceProbes.get(deps.db)?.has(runId) === true;
|
|
23619
|
+
}
|
|
23620
|
+
function releaseGrokBalanceAfterProbeSuccess(deps, now = deps.now ? deps.now() : Date.now()) {
|
|
23621
|
+
const probes = grokBalanceProbes.get(deps.db);
|
|
23622
|
+
if (!probes || probes.size === 0) return;
|
|
23623
|
+
let succeeded = false;
|
|
23624
|
+
for (const [id, probe] of [...probes]) {
|
|
23625
|
+
const run2 = deps.db.getRun(id);
|
|
23626
|
+
if (!run2) {
|
|
23627
|
+
probes.delete(id);
|
|
23628
|
+
continue;
|
|
23629
|
+
}
|
|
23630
|
+
const live2 = run2.status === "running" && run2.pid != null && deps.isAlive(run2.pid);
|
|
23631
|
+
if (!live2 || now - probe.startedAt < GROK_BALANCE_SUCCESS_MS || grokLogShowsBalance(deps, run2)) continue;
|
|
23632
|
+
probes.delete(id);
|
|
23633
|
+
succeeded = true;
|
|
23634
|
+
}
|
|
23635
|
+
if (!succeeded) return;
|
|
23636
|
+
const waiting = deps.db.listRuns("paused").filter((run2) => isGrokBalanceWait(run2.stop_reason));
|
|
23637
|
+
const stopReason = limitWaitReason({
|
|
23638
|
+
executor: "grok",
|
|
23639
|
+
resetsAt: new Date(now).toISOString(),
|
|
23640
|
+
text: "\u0431\u0430\u043B\u0430\u043D\u0441 Grok \u0432\u0435\u0440\u043D\u0443\u043B\u0441\u044F, \u043F\u0440\u043E\u0434\u043E\u043B\u0436\u0438\u0442 \u043F\u043E\u0441\u043B\u0435 \u0441\u0431\u0440\u043E\u0441\u0430"
|
|
23641
|
+
});
|
|
23642
|
+
for (const run2 of waiting) {
|
|
23643
|
+
deps.db.updateRun(run2.id, { stop_reason: stopReason });
|
|
23644
|
+
deps.db.addEvent(run2.id, "step", "\u0431\u0430\u043B\u0430\u043D\u0441 Grok \u043D\u0430 \u044D\u0442\u043E\u0439 \u043C\u0430\u0448\u0438\u043D\u0435 \u0432\u0435\u0440\u043D\u0443\u043B\u0441\u044F \u2014 \u0441\u0432\u043E\u0435\u0433\u043E \u0441\u0431\u0440\u043E\u0441\u0430 \u043D\u0435 \u0436\u0434\u0443, \u043F\u0440\u043E\u0434\u043E\u043B\u0436\u0443 \u043E\u0431\u044B\u0447\u043D\u044B\u043C \u0432\u043E\u0437\u0432\u0440\u0430\u0442\u043E\u043C \u043F\u043E\u0441\u043B\u0435 \u043B\u0438\u043C\u0438\u0442\u0430");
|
|
23645
|
+
}
|
|
23646
|
+
if (waiting.length > 0) {
|
|
23647
|
+
narrate(deps, "\u0411\u0430\u043B\u0430\u043D\u0441 Grok \u0432\u0435\u0440\u043D\u0443\u043B\u0441\u044F \u2014 \u043E\u0441\u0442\u0430\u043B\u044C\u043D\u044B\u0435 \u043F\u0430\u0443\u0437\u044B \u0431\u0430\u043B\u0430\u043D\u0441\u0430 \u044D\u0442\u043E\u0439 \u043C\u0430\u0448\u0438\u043D\u044B \u043F\u0440\u043E\u0434\u043E\u043B\u0436\u0430\u0442 \u043E\u0431\u044B\u0447\u043D\u044B\u043C \u0432\u043E\u0437\u0432\u0440\u0430\u0442\u043E\u043C \u043F\u043E\u0441\u043B\u0435 \u043B\u0438\u043C\u0438\u0442\u0430.");
|
|
23648
|
+
}
|
|
23649
|
+
}
|
|
23650
|
+
function grokBalanceProbeHolds(deps) {
|
|
23651
|
+
releaseGrokBalanceAfterProbeSuccess(deps);
|
|
23652
|
+
const probes = grokBalanceProbes.get(deps.db);
|
|
23653
|
+
if (!probes || probes.size === 0) return false;
|
|
23654
|
+
let holds = false;
|
|
23655
|
+
for (const id of [...probes.keys()]) {
|
|
23656
|
+
const run2 = deps.db.getRun(id);
|
|
23657
|
+
if (!run2) {
|
|
23658
|
+
probes.delete(id);
|
|
23659
|
+
continue;
|
|
23660
|
+
}
|
|
23661
|
+
const live2 = run2.status === "running" && run2.pid != null && deps.isAlive(run2.pid);
|
|
23662
|
+
if (!live2) {
|
|
23663
|
+
if (run2.status === "running" || run2.status === "blocked") {
|
|
23664
|
+
holds = true;
|
|
23665
|
+
continue;
|
|
23666
|
+
}
|
|
23667
|
+
probes.delete(id);
|
|
23668
|
+
continue;
|
|
23669
|
+
}
|
|
23670
|
+
holds = true;
|
|
23671
|
+
}
|
|
23672
|
+
return holds;
|
|
23673
|
+
}
|
|
23674
|
+
function grokBalanceSkipReason() {
|
|
23675
|
+
return `\u043A\u043E\u043D\u0447\u0438\u043B\u0441\u044F \u0431\u0430\u043B\u0430\u043D\u0441 Grok \u2014 \u043D\u043E\u0432\u044B\u0439 \u043F\u0440\u043E\u0433\u043E\u043D \u043D\u0430 Grok \u043D\u0435 \u043F\u043E\u0434\u043D\u0438\u043C\u0430\u044E, \u043E\u0447\u0435\u0440\u0435\u0434\u044C \u0436\u0434\u0451\u0442. ${GROK_BALANCE_ACTION}`;
|
|
23676
|
+
}
|
|
23677
|
+
function runUsesGrok(deps, run2) {
|
|
23678
|
+
const pinned = parseModelRef(run2.model ?? null);
|
|
23679
|
+
if (pinned) return findProvider(pinned.providerId)?.executorId === "grok";
|
|
23680
|
+
try {
|
|
23681
|
+
const id = deps.storm?.providerFor?.(run2);
|
|
23682
|
+
if (!id) return false;
|
|
23683
|
+
return findProvider(id)?.executorId === "grok";
|
|
23684
|
+
} catch {
|
|
23685
|
+
return false;
|
|
23686
|
+
}
|
|
23687
|
+
}
|
|
23688
|
+
function deadRunningGrokBalance(deps) {
|
|
23689
|
+
if (grokBalanceDeadMemo != null) return grokBalanceDeadMemo;
|
|
23690
|
+
let found = false;
|
|
23691
|
+
if (deps.exitLimit) {
|
|
23692
|
+
for (const status of ["running", "blocked"]) {
|
|
23693
|
+
for (const run2 of deps.db.listRuns(status)) {
|
|
23694
|
+
if (run2.pid != null && deps.isAlive(run2.pid)) continue;
|
|
23695
|
+
const hit = limitWaitCandidate(deps, run2);
|
|
23696
|
+
if (hit?.executor === "grok" && hit.balance === true) {
|
|
23697
|
+
found = true;
|
|
23698
|
+
break;
|
|
23699
|
+
}
|
|
23700
|
+
}
|
|
23701
|
+
if (found) break;
|
|
23702
|
+
}
|
|
23703
|
+
}
|
|
23704
|
+
grokBalanceDeadMemo = found;
|
|
23705
|
+
return found;
|
|
23706
|
+
}
|
|
23707
|
+
function grokBalanceHolds(deps) {
|
|
23708
|
+
if (grokBalanceProbeHolds(deps)) return true;
|
|
23709
|
+
if (grokBalanceResumedThisTick.size > 0) return true;
|
|
23710
|
+
for (const run2 of deps.db.listRuns("paused")) {
|
|
23711
|
+
if (isGrokBalanceWait(run2.stop_reason)) return true;
|
|
23712
|
+
}
|
|
23713
|
+
return deadRunningGrokBalance(deps);
|
|
23714
|
+
}
|
|
23715
|
+
function grokBalanceBlocksRun(deps, run2) {
|
|
23716
|
+
return grokBalanceHolds(deps) && runUsesGrok(deps, run2);
|
|
23717
|
+
}
|
|
23718
|
+
function grokBalanceBlocksChecker(deps, author) {
|
|
23719
|
+
return grokBalanceBlocksRun(deps, { kind: "reviewer", model: author.review_model ?? null });
|
|
23720
|
+
}
|
|
23721
|
+
function grokBalanceBlocksIntake(deps) {
|
|
23722
|
+
if (!grokBalanceHolds(deps)) return false;
|
|
23723
|
+
return runUsesGrok(deps, { kind: "drone", model: null });
|
|
23724
|
+
}
|
|
23725
|
+
function noteGrokBalanceSkip(deps, run2, who) {
|
|
23726
|
+
const reason = grokBalanceSkipReason();
|
|
23727
|
+
const d = noteDefer(deps.spawnDefer ??= /* @__PURE__ */ new Map(), `grok-balance:${run2.id}`, reason, GATE_LOG_HEARTBEAT_TICKS);
|
|
23728
|
+
if (d.changed) deps.db.addEvent(run2.id, "step", `\u0441\u043F\u0430\u0432\u043D \u043E\u0442\u043B\u043E\u0436\u0435\u043D: ${reason}`);
|
|
23729
|
+
if (d.log) {
|
|
23730
|
+
console.error(
|
|
23731
|
+
`[overmind] ${who} ${droneLabel(run2)} (${run2.task_slug}) \u043D\u0435 \u043F\u043E\u0434\u043D\u0438\u043C\u0430\u044E: ${reason}${d.changed ? "" : ` \u2014 \u0435\u0449\u0451 \u0432\u0438\u0441\u0438\u0442, \u0442\u0438\u043A ${d.ticks}`}`
|
|
23732
|
+
);
|
|
23733
|
+
}
|
|
23734
|
+
}
|
|
23735
|
+
function safeGrokEmail(deps) {
|
|
23736
|
+
try {
|
|
23737
|
+
const value = deps.grokAccountEmail?.() ?? null;
|
|
23738
|
+
return typeof value === "string" && value.includes("@") ? value : null;
|
|
23739
|
+
} catch {
|
|
23740
|
+
return null;
|
|
23741
|
+
}
|
|
23742
|
+
}
|
|
23743
|
+
function grokBalanceWaitingCount(deps) {
|
|
23744
|
+
const ids = new Set(grokBalanceResumedThisTick);
|
|
23745
|
+
for (const run2 of deps.db.listRuns("paused")) {
|
|
23746
|
+
if (isGrokBalanceWait(run2.stop_reason)) ids.add(run2.id);
|
|
23747
|
+
}
|
|
23748
|
+
return ids.size;
|
|
23749
|
+
}
|
|
23750
|
+
function grokBalanceHostName(deps) {
|
|
23751
|
+
const name = (deps.selfHostName || deps.storm?.hostName || "").trim();
|
|
23752
|
+
return name || "\u043C\u0430\u0448\u0438\u043D\u0430";
|
|
23753
|
+
}
|
|
23754
|
+
function grokBalanceKey(deps) {
|
|
23755
|
+
return grokBalanceSignalKey(deps.selfHostId);
|
|
23756
|
+
}
|
|
23757
|
+
function grokBalanceAnomalyCandidate(deps) {
|
|
23758
|
+
if (!grokBalanceHolds(deps)) return null;
|
|
23759
|
+
return {
|
|
23760
|
+
key: grokBalanceKey(deps),
|
|
23761
|
+
once: true,
|
|
23762
|
+
minDurationMs: 0,
|
|
23763
|
+
build: () => {
|
|
23764
|
+
const signal = grokBalanceSignal({
|
|
23765
|
+
hostName: grokBalanceHostName(deps),
|
|
23766
|
+
email: safeGrokEmail(deps),
|
|
23767
|
+
waiting: grokBalanceWaitingCount(deps)
|
|
23768
|
+
});
|
|
23769
|
+
return { level: "decision", title: signal.title, body: clipChars(signal.body, ANOMALY_BODY_MAX) };
|
|
23770
|
+
}
|
|
23771
|
+
};
|
|
23772
|
+
}
|
|
23505
23773
|
async function projectWantsChecks(deps, run2) {
|
|
23506
23774
|
if (!deps.autoReviewForRepo) return true;
|
|
23507
23775
|
return await deps.autoReviewForRepo(effectiveRepo(deps, run2), run2.task_slug).catch((e) => {
|
|
@@ -23522,6 +23790,10 @@ async function spawnFreshReviewerAfterStall(deps, run2, why) {
|
|
|
23522
23790
|
}
|
|
23523
23791
|
const gate = await prGateForReviewer(deps, run2, run2.pr_url, "\u043F\u043E\u043A\u0430 \u0436\u0434\u0430\u043B CI");
|
|
23524
23792
|
if (gate.kind !== "spawn") return;
|
|
23793
|
+
if (grokBalanceBlocksChecker(deps, run2)) {
|
|
23794
|
+
noteGrokBalanceSkip(deps, run2, "\u0440\u0435\u0432\u044C\u044E\u0435\u0440\u0430");
|
|
23795
|
+
return;
|
|
23796
|
+
}
|
|
23525
23797
|
const st = gate.st;
|
|
23526
23798
|
try {
|
|
23527
23799
|
await deps.spawnReviewer(run2, st.files ?? []);
|
|
@@ -23557,6 +23829,9 @@ function draftHoldBody(prUrl) {
|
|
|
23557
23829
|
function tickSuppressesAnomaly(key) {
|
|
23558
23830
|
for (const id of draftHeldThisTick.keys()) if (key === `pr_no_reviewer:${id}`) return true;
|
|
23559
23831
|
for (const id of fixBlockedThisTick.keys()) if (key === `pr_stuck_changes:${id}`) return true;
|
|
23832
|
+
for (const id of grokBalanceFixHeldThisTick) {
|
|
23833
|
+
if (key === `pr_stuck_changes:${id}` || key === `pr_no_reviewer:${id}`) return true;
|
|
23834
|
+
}
|
|
23560
23835
|
return false;
|
|
23561
23836
|
}
|
|
23562
23837
|
function tickAnomalyCandidates(autoReviewSnapshot) {
|
|
@@ -23619,6 +23894,11 @@ async function wakeAuthorOnChanges(deps, snapshot, now, droneCap) {
|
|
|
23619
23894
|
const run2 = deps.db.getRun(snapshot.id);
|
|
23620
23895
|
if (!run2 || isAwaitingBudget(run2.status, run2.stop_reason)) return false;
|
|
23621
23896
|
if (run2.pid != null && deps.isAlive(run2.pid)) return false;
|
|
23897
|
+
if (grokBalanceBlocksRun(deps, run2)) {
|
|
23898
|
+
grokBalanceFixHeldThisTick.add(run2.id);
|
|
23899
|
+
noteGrokBalanceSkip(deps, run2, "\u0444\u0438\u043A\u0441-\u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044E");
|
|
23900
|
+
return false;
|
|
23901
|
+
}
|
|
23622
23902
|
if (deps.db.activeReviewersFor(run2.id).some((r) => r.status !== "stalled" && !isAwaitingCi(r.status, r.stop_reason))) {
|
|
23623
23903
|
return blockFix(run2, "\u0440\u0435\u0432\u044C\u044E\u0435\u0440 \u0435\u0449\u0451 \u0432 \u0440\u0430\u0431\u043E\u0442\u0435");
|
|
23624
23904
|
}
|
|
@@ -23778,7 +24058,7 @@ async function zoneConflictFor(db, models, activeFiles, run2, repo, repoFallback
|
|
|
23778
24058
|
activeFiles.prune(holders.map((r) => r.id));
|
|
23779
24059
|
const fileExists = (p) => {
|
|
23780
24060
|
try {
|
|
23781
|
-
return statSync16(
|
|
24061
|
+
return statSync16(join41(repo, p), { throwIfNoEntry: false })?.isFile() ?? false;
|
|
23782
24062
|
} catch {
|
|
23783
24063
|
return false;
|
|
23784
24064
|
}
|
|
@@ -23942,6 +24222,9 @@ async function trySpawnQueuedRun(deps, run2) {
|
|
|
23942
24222
|
// причина одна на машину — в лог уходит одной строкой, а не по строке на прогон
|
|
23943
24223
|
});
|
|
23944
24224
|
}
|
|
24225
|
+
if (grokBalanceBlocksRun(deps, run2)) {
|
|
24226
|
+
return deferSpawn(deps, run2, `${grokBalanceSkipReason()} (TASWM-660)`, { logKey: "grok-balance" });
|
|
24227
|
+
}
|
|
23945
24228
|
const heavy = heavyRunsInFlight(deps);
|
|
23946
24229
|
if (heavy.length && heavy.every((h) => h.id !== run2.id)) {
|
|
23947
24230
|
return deferSpawn(deps, run2, intakeHoldReason(heavy.map(droneLabel).join(", ")), {
|
|
@@ -24436,6 +24719,16 @@ function lastLimitResumeMs(deps, runId) {
|
|
|
24436
24719
|
const event = deps.db.events(runId).filter((item) => item.kind === "resumed" && item.text === LIMIT_RESUMED_TEXT).at(-1);
|
|
24437
24720
|
return event ? stampMs(event.at) : null;
|
|
24438
24721
|
}
|
|
24722
|
+
function returnGrokBalanceProbeToPause(deps, run2, now) {
|
|
24723
|
+
const resetsAt = new Date(now + LIMIT_RESUME_RETRY_MS).toISOString();
|
|
24724
|
+
const text = grokBalanceWaitText();
|
|
24725
|
+
const stopReason = limitWaitReason({ executor: "grok", resetsAt, text });
|
|
24726
|
+
deps.db.updateRun(run2.id, { status: "paused", stop_reason: stopReason });
|
|
24727
|
+
const resetClock = new Date(resetsAt).toLocaleTimeString("ru-RU", { hour: "2-digit", minute: "2-digit" });
|
|
24728
|
+
deps.db.addEvent(run2.id, "paused", `${text}, \u043F\u0440\u043E\u0431\u0430 \u0443\u043C\u0435\u0440\u043B\u0430 \u0440\u0430\u043D\u044C\u0448\u0435 5 \u043C\u0438\u043D\u0443\u0442, \u043F\u043E\u0432\u0442\u043E\u0440 \u043D\u0435 \u0440\u0430\u043D\u044C\u0448\u0435 ${resetClock}`);
|
|
24729
|
+
narrate(deps, `${droneLabel(run2)} \u043F\u0440\u043E\u0431\u0430 \u0431\u0430\u043B\u0430\u043D\u0441\u0430 \u0443\u043C\u0435\u0440\u043B\u0430 \u0440\u0430\u043D\u044C\u0448\u0435 5 \u043C\u0438\u043D\u0443\u0442 \u2014 \u0441\u043D\u043E\u0432\u0430 \u0436\u0434\u0443. ${GROK_BALANCE_ACTION}`);
|
|
24730
|
+
grokBalanceProbeMap(deps.db).delete(run2.id);
|
|
24731
|
+
}
|
|
24439
24732
|
async function resumeLimitWaits(deps, now, droneCap, _stormActive) {
|
|
24440
24733
|
if (!deps.respawn || countActiveDrones(deps.db) >= droneCap) return;
|
|
24441
24734
|
const candidates = deps.db.listRuns("paused").filter((run2) => isLimitWaitDue(run2.stop_reason, now)).filter((run2) => run2.pid == null || !deps.isAlive(run2.pid)).sort((a, b) => a.updated_at.localeCompare(b.updated_at));
|
|
@@ -24457,11 +24750,16 @@ async function resumeLimitWaits(deps, now, droneCap, _stormActive) {
|
|
|
24457
24750
|
console.error(`[overmind] \u0440\u0435\u043A\u043B\u0435\u0439\u043C worktree \u043F\u0435\u0440\u0435\u0434 \u0432\u043E\u0437\u0432\u0440\u0430\u0442\u043E\u043C \u043F\u043E\u0441\u043B\u0435 \u043B\u0438\u043C\u0438\u0442\u0430 ${droneLabel(candidate)} \u0441\u043E\u0440\u0432\u0430\u043B\u0441\u044F:`, e);
|
|
24458
24751
|
}
|
|
24459
24752
|
}
|
|
24753
|
+
const balanceWait = isGrokBalanceWait(candidate.stop_reason);
|
|
24460
24754
|
try {
|
|
24461
24755
|
await deps.respawn(candidate, mode);
|
|
24462
24756
|
deps.db.updateRun(candidate.id, { stop_reason: null });
|
|
24463
24757
|
if (mode === "fresh") deps.db.addEvent(candidate.id, "step", "\u0441\u0435\u0441\u0441\u0438\u044F \u043F\u043E\u0442\u0435\u0440\u044F\u043D\u0430, \u043D\u0430\u0447\u0430\u043B \u0437\u0430\u043D\u043E\u0432\u043E");
|
|
24464
24758
|
deps.db.addEvent(candidate.id, "resumed", LIMIT_RESUMED_TEXT);
|
|
24759
|
+
if (balanceWait) {
|
|
24760
|
+
grokBalanceProbeMap(deps.db).set(candidate.id, { startedAt: now });
|
|
24761
|
+
grokBalanceResumedThisTick.add(candidate.id);
|
|
24762
|
+
}
|
|
24465
24763
|
narrate(deps, `\u041B\u0438\u043C\u0438\u0442 \u0441\u0431\u0440\u043E\u0448\u0435\u043D \u2014 \u0432\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u044E ${droneLabel(candidate)} \u0432 \u0440\u0430\u0431\u043E\u0442\u0443.`);
|
|
24466
24764
|
} catch (e) {
|
|
24467
24765
|
const reason = `\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u043F\u0440\u043E\u0434\u043E\u043B\u0436\u0438\u0442\u044C \u043F\u043E\u0441\u043B\u0435 \u043B\u0438\u043C\u0438\u0442\u0430: ${String(e)}`;
|
|
@@ -25196,6 +25494,7 @@ async function tickOnce(deps) {
|
|
|
25196
25494
|
beginGhMergePass(deps.ghMerges);
|
|
25197
25495
|
draftHeldThisTick.clear();
|
|
25198
25496
|
fixBlockedThisTick.clear();
|
|
25497
|
+
resetGrokBalanceTick();
|
|
25199
25498
|
const worktreeExists = deps.worktreeExists ?? existsSync23;
|
|
25200
25499
|
const hasTranscript = deps.hasTranscript ?? executorHasSession;
|
|
25201
25500
|
deps.stepClock?.mark("0 \u0437\u0430\u043C\u0435\u0440 \u0445\u043E\u0441\u0442\u0430");
|
|
@@ -25329,12 +25628,14 @@ async function tickOnce(deps) {
|
|
|
25329
25628
|
}
|
|
25330
25629
|
if (deps.exitOutcome && endedItself(deps.exitOutcome(run2))) continue;
|
|
25331
25630
|
if (limitWaitCandidate(deps, run2)) continue;
|
|
25631
|
+
if (grokBalanceProbeOpen(deps, run2.id)) continue;
|
|
25332
25632
|
deps.db.recordDeath(run2.id, `\u0434\u0440\u043E\u043D \u0443\u043C\u0435\u0440 (pid ${run2.pid} \u043D\u0435 \u043E\u0442\u0432\u0435\u0447\u0430\u0435\u0442)`);
|
|
25333
25633
|
}
|
|
25334
25634
|
stormActive = await manageStorm(deps, now, worktreeExists, hasTranscript);
|
|
25335
25635
|
}
|
|
25336
25636
|
const droneCap = deps.maxDrones ? await deps.maxDrones() : Infinity;
|
|
25337
25637
|
deps.stepClock?.mark("0e \u0432\u043E\u0437\u0432\u0440\u0430\u0442 \u043F\u043E\u0441\u043B\u0435 \u043B\u0438\u043C\u0438\u0442\u0430");
|
|
25638
|
+
releaseGrokBalanceAfterProbeSuccess(deps, now);
|
|
25338
25639
|
await resumeLimitWaits(deps, now, droneCap, stormActive);
|
|
25339
25640
|
deps.stepClock?.mark("1 \u043F\u043E\u0434\u043D\u044F\u0442\u044C \u043E\u0447\u0435\u0440\u0435\u0434\u044C");
|
|
25340
25641
|
if (stormActive) noteStormStall(deps);
|
|
@@ -25591,20 +25892,24 @@ async function tickOnce(deps) {
|
|
|
25591
25892
|
if ((!deps.resourcesOk || deps.resourcesOk()) && reviewersCapOk) {
|
|
25592
25893
|
const gate = await prGateForReviewer(deps, run2, prUrl, "\u043F\u043E\u043A\u0430 \u0436\u0434\u0430\u043B \u0440\u0435\u0432\u044C\u044E\u0435\u0440\u0430");
|
|
25593
25894
|
if (gate.kind === "spawn") {
|
|
25594
|
-
|
|
25595
|
-
|
|
25596
|
-
|
|
25597
|
-
|
|
25598
|
-
|
|
25599
|
-
|
|
25600
|
-
deps
|
|
25601
|
-
|
|
25602
|
-
|
|
25603
|
-
|
|
25604
|
-
|
|
25605
|
-
|
|
25606
|
-
|
|
25607
|
-
|
|
25895
|
+
if (grokBalanceBlocksChecker(deps, run2)) {
|
|
25896
|
+
noteGrokBalanceSkip(deps, run2, "\u0440\u0435\u0432\u044C\u044E\u0435\u0440\u0430");
|
|
25897
|
+
} else {
|
|
25898
|
+
run2 = syncBranchFromPr(deps.db, run2, gate.st.headBranch);
|
|
25899
|
+
try {
|
|
25900
|
+
await deps.spawnReviewer(run2, st.files ?? []);
|
|
25901
|
+
narrate(deps, `PR ${droneLabel(run2)} \u0433\u043E\u0442\u043E\u0432 \u2014 \u043F\u043E\u0434\u043D\u0438\u043C\u0430\u044E \u043D\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043C\u043E\u0433\u043E \u0440\u0435\u0432\u044C\u044E\u0435\u0440\u0430.`);
|
|
25902
|
+
} catch (e) {
|
|
25903
|
+
if (isUnrecoverableRefError(e)) {
|
|
25904
|
+
deps.db.addEvent(
|
|
25905
|
+
run2.id,
|
|
25906
|
+
"step",
|
|
25907
|
+
`${unrecoverableMark}: ${String(e)} \u2014 \u043F\u043E\u0432\u0442\u043E\u0440\u043E\u043C \u043D\u0435 \u043B\u0435\u0447\u0438\u0442\u0441\u044F, \u0430\u0432\u0442\u043E-\u0440\u0435\u0432\u044C\u044E \u0434\u043B\u044F \u044D\u0442\u043E\u0433\u043E \u043F\u0440\u043E\u0433\u043E\u043D\u0430 \u043E\u0441\u0442\u0430\u043D\u043E\u0432\u043B\u0435\u043D\u043E, \u043D\u0443\u0436\u0435\u043D \u0447\u0435\u043B\u043E\u0432\u0435\u043A`
|
|
25908
|
+
);
|
|
25909
|
+
narrate(deps, `\u0420\u0435\u0432\u044C\u044E\u0435\u0440\u0430 ${droneLabel(run2)} \u043D\u0435 \u043F\u043E\u0434\u043D\u044F\u0442\u044C: \u0432\u0435\u0442\u043A\u0438 PR \u043D\u0435\u0442 \u043D\u0430 origin \u2014 \u0437\u043E\u0432\u0443 \u0447\u0435\u043B\u043E\u0432\u0435\u043A\u0430 \u0441\u0440\u0430\u0437\u0443, \u043F\u043E\u043F\u044B\u0442\u043A\u0438 \u043D\u0435 \u0436\u0433\u0443.`);
|
|
25910
|
+
} else {
|
|
25911
|
+
deps.db.addEvent(run2.id, "step", `\u0430\u0432\u0442\u043E-\u0440\u0435\u0432\u044C\u044E \u043D\u0435 \u043F\u043E\u0434\u043D\u044F\u043B\u043E\u0441\u044C: ${String(e)}`);
|
|
25912
|
+
}
|
|
25608
25913
|
}
|
|
25609
25914
|
}
|
|
25610
25915
|
}
|
|
@@ -25666,15 +25971,20 @@ async function tickOnce(deps) {
|
|
|
25666
25971
|
continue;
|
|
25667
25972
|
}
|
|
25668
25973
|
}
|
|
25669
|
-
|
|
25670
|
-
|
|
25974
|
+
if (!alive && grokBalanceProbeOpen(deps, run2.id)) {
|
|
25975
|
+
returnGrokBalanceProbeToPause(deps, run2, now);
|
|
25976
|
+
continue;
|
|
25977
|
+
}
|
|
25978
|
+
const limitHit = !alive && (run2.status === "running" || run2.status === "blocked") ? limitWaitCandidate(deps, run2) : null;
|
|
25979
|
+
const balancePause = limitHit?.executor === "grok" && limitHit.balance === true;
|
|
25980
|
+
if (limitHit && (run2.status === "running" || balancePause)) {
|
|
25671
25981
|
const report = deps.limitsSnapshot?.() ?? null;
|
|
25672
25982
|
let resetsAt = limitResetAt({ executor: limitHit.executor, report, resetHint: limitHit.resetHint, nowMs: now });
|
|
25673
25983
|
const lastResumeMs = lastLimitResumeMs(deps, run2.id);
|
|
25674
25984
|
if (lastResumeMs !== null && now - lastResumeMs < LIMIT_RESUME_RETRY_MS) {
|
|
25675
25985
|
resetsAt = new Date(Math.max(Date.parse(resetsAt), now + LIMIT_RESUME_RETRY_MS)).toISOString();
|
|
25676
25986
|
}
|
|
25677
|
-
const text = limitWaitText(limitHit.executor, limitWaitWindow(report, limitHit.executor));
|
|
25987
|
+
const text = limitHit.balance === true && limitHit.executor === "grok" ? grokBalanceWaitText() : limitWaitText(limitHit.executor, limitWaitWindow(report, limitHit.executor));
|
|
25678
25988
|
const resetClock = new Date(resetsAt).toLocaleTimeString("ru-RU", { hour: "2-digit", minute: "2-digit" });
|
|
25679
25989
|
const stopReason = limitWaitReason({ executor: limitHit.executor, resetsAt, text });
|
|
25680
25990
|
deps.db.updateRun(run2.id, { status: "paused", stop_reason: stopReason });
|
|
@@ -26010,9 +26320,16 @@ async function tickOnce(deps) {
|
|
|
26010
26320
|
// труба, тот же дедуп «один раз на эпизод». Пустой список при нормальной работе.
|
|
26011
26321
|
...await buildReliefCostCandidatesFor(deps, now, droneCap)
|
|
26012
26322
|
];
|
|
26323
|
+
const balanceCandidate = grokBalanceAnomalyCandidate(deps);
|
|
26324
|
+
if (balanceCandidate) {
|
|
26325
|
+
const balanceKey = grokBalanceKey(deps);
|
|
26326
|
+
const last = az.tracker.lastFiredMs(balanceKey);
|
|
26327
|
+
if (last != null && now - last >= GROK_BALANCE_RENOTIFY_MS) az.tracker.rearm(balanceKey);
|
|
26328
|
+
}
|
|
26013
26329
|
const candidates = [
|
|
26014
26330
|
...detected.filter((c) => !tickSuppressesAnomaly(c.key)),
|
|
26015
|
-
...tickAnomalyCandidates(autoReviewSnapshot)
|
|
26331
|
+
...tickAnomalyCandidates(autoReviewSnapshot),
|
|
26332
|
+
...balanceCandidate ? [balanceCandidate] : []
|
|
26016
26333
|
];
|
|
26017
26334
|
ready = collapseSignals(az.tracker.eligible(now, candidates));
|
|
26018
26335
|
} catch (e) {
|
|
@@ -26073,11 +26390,16 @@ async function tickOnce(deps) {
|
|
|
26073
26390
|
}
|
|
26074
26391
|
deps.stepClock?.mark("5 \u0430\u0432\u0442\u043E-\u0438\u043D\u0442\u0435\u0439\u043A");
|
|
26075
26392
|
const heavyInFlight = heavyRunsInFlight(deps);
|
|
26393
|
+
if (deps.intake && grokBalanceBlocksIntake(deps)) {
|
|
26394
|
+
const reason = grokBalanceSkipReason();
|
|
26395
|
+
const d = noteDefer(deps.spawnDefer ??= /* @__PURE__ */ new Map(), "grok-balance-intake", reason, GATE_LOG_HEARTBEAT_TICKS);
|
|
26396
|
+
if (d.log) console.error(`[overmind] \u0430\u0432\u0442\u043E-\u0438\u043D\u0442\u0435\u0439\u043A \u043F\u0440\u0438\u0434\u0435\u0440\u0436\u0430\u043D: ${reason}${d.changed ? "" : ` \u2014 \u0435\u0449\u0451 \u0432\u0438\u0441\u0438\u0442, \u0442\u0438\u043A ${d.ticks}`}`);
|
|
26397
|
+
}
|
|
26076
26398
|
if (heavyInFlight.length && deps.intake) {
|
|
26077
26399
|
const d = noteDefer(deps.spawnDefer ??= /* @__PURE__ */ new Map(), "weight-intake-hold", intakeHoldReason(heavyInFlight.map(droneLabel).join(", ")), GATE_LOG_HEARTBEAT_TICKS);
|
|
26078
26400
|
if (d.log) console.error(`[overmind] \u0430\u0432\u0442\u043E-\u0438\u043D\u0442\u0435\u0439\u043A \u043F\u0440\u0438\u0434\u0435\u0440\u0436\u0430\u043D: ${intakeHoldReason(heavyInFlight.map(droneLabel).join(", "))}${d.changed ? "" : ` \u2014 \u0435\u0449\u0451 \u0432\u0438\u0441\u0438\u0442, \u0442\u0438\u043A ${d.ticks}`}`);
|
|
26079
26401
|
}
|
|
26080
|
-
if (deps.intake && !stormBlocksIntake(deps) && !deps.control?.paused && !heavyInFlight.length && deps.intake.maxInFlight > 0 && (!deps.resourcesOk || deps.resourcesOk())) {
|
|
26402
|
+
if (deps.intake && !stormBlocksIntake(deps) && !grokBalanceBlocksIntake(deps) && !deps.control?.paused && !heavyInFlight.length && deps.intake.maxInFlight > 0 && (!deps.resourcesOk || deps.resourcesOk())) {
|
|
26081
26403
|
const it = deps.intake;
|
|
26082
26404
|
const claimCap = deps.maxDrones ? droneCap : it.maxInFlight;
|
|
26083
26405
|
const sinceLastClaim = it.lastClaimAt == null ? Infinity : now - it.lastClaimAt;
|
|
@@ -26185,7 +26507,7 @@ async function resolveConflict(deps, reviewRun) {
|
|
|
26185
26507
|
model: reviewRun.model,
|
|
26186
26508
|
review_model: reviewRun.review_model
|
|
26187
26509
|
});
|
|
26188
|
-
const wt =
|
|
26510
|
+
const wt = join41(deps.worktreesDir, basename7(repo), `${reviewRun.task_slug}-resolve-${resolver.id}`);
|
|
26189
26511
|
try {
|
|
26190
26512
|
await deps.git.prepareDetachedWorktree(repo, branch, wt);
|
|
26191
26513
|
await deps.git.setWorktreeIdentity(wt, resolver.name);
|
|
@@ -26266,7 +26588,7 @@ async function spawnReviewer(deps, reviewRun, files) {
|
|
|
26266
26588
|
// (своей у ревьюера нет, TASWM-204), и коммент с вердиктом должен уехать именно туда.
|
|
26267
26589
|
workspace_id: reviewRun.workspace_id
|
|
26268
26590
|
});
|
|
26269
|
-
const wt =
|
|
26591
|
+
const wt = join41(deps.worktreesDir, basename7(repo), `${reviewRun.task_slug}-review-${reviewer.id}`);
|
|
26270
26592
|
try {
|
|
26271
26593
|
await deps.git.prepareDetachedWorktree(repo, branch, wt);
|
|
26272
26594
|
await deps.git.setWorktreeIdentity(wt, reviewer.name);
|
|
@@ -26349,7 +26671,7 @@ async function spawnVerifier(deps, verifiedRun, files) {
|
|
|
26349
26671
|
// штамп цикла: фикс-итерацию проверяет свежий верификатор
|
|
26350
26672
|
workspace_id: verifiedRun.workspace_id
|
|
26351
26673
|
});
|
|
26352
|
-
const wt =
|
|
26674
|
+
const wt = join41(deps.worktreesDir, basename7(repo), `${verifiedRun.task_slug}-verify-${verifier.id}`);
|
|
26353
26675
|
try {
|
|
26354
26676
|
await deps.git.prepareDetachedWorktree(repo, branch, wt);
|
|
26355
26677
|
await deps.git.setWorktreeIdentity(wt, verifier.name);
|
|
@@ -26548,7 +26870,7 @@ async function makeStore(repo, worktreesDir, repoFlag, executorFor) {
|
|
|
26548
26870
|
console.warn(`[overmind] \u043D\u0435 \u0441\u043C\u043E\u0433 \u0437\u0430\u043F\u043E\u043C\u043D\u0438\u0442\u044C \u043F\u0443\u0442\u044C \u043A \u0440\u0435\u043F\u043E\u0437\u0438\u0442\u043E\u0440\u0438\u044E (${e instanceof Error ? e.message : e}) \u2014 \u0441\u043B\u0435\u0434\u0443\u044E\u0449\u0438\u0439 \u0437\u0430\u043F\u0443\u0441\u043A \u0441\u043D\u043E\u0432\u0430 \u043F\u043E\u043F\u0440\u043E\u0441\u0438\u0442 --repo`);
|
|
26549
26871
|
}
|
|
26550
26872
|
}
|
|
26551
|
-
const scanRootsList = resolveScanRoots(SWARM_SCAN_ROOTS_RAW,
|
|
26873
|
+
const scanRootsList = resolveScanRoots(SWARM_SCAN_ROOTS_RAW, homedir10(), repoPaths);
|
|
26552
26874
|
const repoMap = emptyRepoMapState(scanRootsList);
|
|
26553
26875
|
if (SWARM_BACKEND !== "client") {
|
|
26554
26876
|
const { SwarmDb: SwarmDb2 } = await loadSqlite();
|
|
@@ -26686,7 +27008,7 @@ function lastModelLimits() {
|
|
|
26686
27008
|
}
|
|
26687
27009
|
function sweepDaemonStands(opts) {
|
|
26688
27010
|
const { db, worktreesDir } = opts;
|
|
26689
|
-
const homeDir = opts.homeDir ??
|
|
27011
|
+
const homeDir = opts.homeDir ?? homedir10();
|
|
26690
27012
|
const runs = db.listRuns();
|
|
26691
27013
|
const runsWithWorktree = runs.filter((r) => r.worktree_path);
|
|
26692
27014
|
const bySlug = /* @__PURE__ */ new Map();
|
|
@@ -27472,6 +27794,9 @@ async function runDaemon(opts) {
|
|
|
27472
27794
|
// Кто мы как машина (TASWM-281) — чтобы отличить ДРУГИЕ машины роя от своей, когда рой
|
|
27473
27795
|
// советует увезти прогоны туда (TASWM-316).
|
|
27474
27796
|
selfHostId: host.hostId,
|
|
27797
|
+
selfHostName: host.hostName,
|
|
27798
|
+
// Только email. readGrokAccountEmail не возвращает остальные поля auth.json.
|
|
27799
|
+
grokAccountEmail: () => readGrokAccountEmail(grokAccountAuthPath(process.env)),
|
|
27475
27800
|
// Состояние градуального контроллера (окна ramp/pause, reliefSince) + журнал цены
|
|
27476
27801
|
// разгрузки (TASWM-316) — заводим ОДИН раз на цикл демона, tickOnce (manageRelief)
|
|
27477
27802
|
// мутирует эти же поля каждый тик.
|