@tablation/crew 0.132.1 → 0.133.0
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 +572 -301
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -5463,6 +5463,7 @@ import {
|
|
|
5463
5463
|
readdirSync as readdirSync4,
|
|
5464
5464
|
rmSync as rmSync9
|
|
5465
5465
|
} from "fs";
|
|
5466
|
+
import { tmpdir as tmpdir2 } from "os";
|
|
5466
5467
|
import { dirname as dirname10, basename as basename5, join as join19 } from "path";
|
|
5467
5468
|
var GitError = class extends Error {
|
|
5468
5469
|
};
|
|
@@ -5646,6 +5647,16 @@ function fetchRemote(cwd, remote = "origin") {
|
|
|
5646
5647
|
gitOk(cwd, ["fetch", "--quiet", remote, "refs/tags/*:refs/tags/*"]);
|
|
5647
5648
|
return true;
|
|
5648
5649
|
}
|
|
5650
|
+
function lsRemoteHeads(url) {
|
|
5651
|
+
const out = gitOk(tmpdir2(), ["ls-remote", "--heads", url]);
|
|
5652
|
+
if (out === null) return null;
|
|
5653
|
+
const heads = /* @__PURE__ */ new Map();
|
|
5654
|
+
for (const line of out.split("\n")) {
|
|
5655
|
+
const [sha, ref] = line.split(" ");
|
|
5656
|
+
if (sha && ref?.startsWith("refs/heads/")) heads.set(ref.slice("refs/heads/".length), sha);
|
|
5657
|
+
}
|
|
5658
|
+
return heads;
|
|
5659
|
+
}
|
|
5649
5660
|
function remoteConfigured(cwd, remote = "origin") {
|
|
5650
5661
|
return gitOk(cwd, ["remote", "get-url", remote]) !== null;
|
|
5651
5662
|
}
|
|
@@ -6492,15 +6503,15 @@ import { promisify as promisify2 } from "util";
|
|
|
6492
6503
|
|
|
6493
6504
|
// src/deprovision-host.ts
|
|
6494
6505
|
import { spawnSync as spawnSync7 } from "child_process";
|
|
6495
|
-
import { existsSync as
|
|
6506
|
+
import { existsSync as existsSync30, readdirSync as readdirSync11 } from "fs";
|
|
6496
6507
|
|
|
6497
6508
|
// src/interrupted.ts
|
|
6498
|
-
import { existsSync as
|
|
6509
|
+
import { existsSync as existsSync28, readdirSync as readdirSync9, readFileSync as readFileSync28 } from "fs";
|
|
6499
6510
|
import { join as join31 } from "path";
|
|
6500
6511
|
|
|
6501
6512
|
// src/agent.ts
|
|
6502
6513
|
import { spawnSync as spawnSync6 } from "child_process";
|
|
6503
|
-
import { readFileSync as readFileSync27, existsSync as
|
|
6514
|
+
import { readFileSync as readFileSync27, existsSync as existsSync27, statSync as statSync9, mkdirSync as mkdirSync19, writeFileSync as writeFileSync20, createWriteStream, openSync as openSync4, closeSync as closeSync4, readSync } from "fs";
|
|
6504
6515
|
import { StringDecoder } from "string_decoder";
|
|
6505
6516
|
import { finished } from "stream/promises";
|
|
6506
6517
|
import { join as join30, dirname as dirname15, basename as basename9 } from "path";
|
|
@@ -8423,12 +8434,15 @@ var BeforeFirstEditTracker = class {
|
|
|
8423
8434
|
};
|
|
8424
8435
|
|
|
8425
8436
|
// src/agent-log.ts
|
|
8426
|
-
import { existsSync as
|
|
8437
|
+
import { existsSync as existsSync23, mkdirSync as mkdirSync16, readdirSync as readdirSync7, readFileSync as readFileSync23, rmSync as rmSync13, writeFileSync as writeFileSync17 } from "fs";
|
|
8427
8438
|
import { join as join25 } from "path";
|
|
8428
8439
|
|
|
8429
8440
|
// src/pending-backoff.ts
|
|
8430
8441
|
var sleepBackoff = (attempts) => Math.min(6e4 * 2 ** Math.max(0, attempts - 1), 30 * 6e4);
|
|
8431
8442
|
|
|
8443
|
+
// src/handoff-guard.ts
|
|
8444
|
+
import { existsSync as existsSync22 } from "fs";
|
|
8445
|
+
|
|
8432
8446
|
// src/ticket-branch.ts
|
|
8433
8447
|
import { basename as basename7 } from "path";
|
|
8434
8448
|
|
|
@@ -9465,6 +9479,9 @@ function branchTemplates(cfg, t) {
|
|
|
9465
9479
|
function pushedBranchForTicket(cfg, t, role) {
|
|
9466
9480
|
return branchRenderer(t, role, cfg.branch.lowercase)(branchTemplates(cfg, t).push);
|
|
9467
9481
|
}
|
|
9482
|
+
function branchCandidatesForTicket(cfg, t, role) {
|
|
9483
|
+
return branchCandidates(t.issue_id, branchTemplates(cfg, t), branchRenderer(t, role, cfg.branch.lowercase));
|
|
9484
|
+
}
|
|
9468
9485
|
function existingBranchForTicket(dir, cfg, t, role) {
|
|
9469
9486
|
return branchForIssue(dir, t.issue_id, branchTemplates(cfg, t), branchRenderer(t, role, cfg.branch.lowercase));
|
|
9470
9487
|
}
|
|
@@ -9853,6 +9870,28 @@ function remoteTip(dir, remote, branch) {
|
|
|
9853
9870
|
if (out === null) return null;
|
|
9854
9871
|
return out.split("\n").find((l) => l.endsWith(` refs/heads/${branch}`))?.split(" ")[0] ?? "";
|
|
9855
9872
|
}
|
|
9873
|
+
function inspectRemoteHandoff(origin, cfg, ticket, role) {
|
|
9874
|
+
const remote = cfg.branch.remote;
|
|
9875
|
+
const heads = lsRemoteHeads(origin);
|
|
9876
|
+
if (!heads) return { kind: "unverified", why: `could not reach \`${remote}\` (${origin}) to check the pushed branch` };
|
|
9877
|
+
for (const c of branchCandidatesForTicket(cfg, ticket, role)) {
|
|
9878
|
+
const hit = c.endsWith("*") ? [...heads.keys()].find((b) => b.startsWith(c.slice(0, -1))) : heads.has(c) ? c : void 0;
|
|
9879
|
+
if (hit) return { kind: "pushed", branch: hit, sha: heads.get(hit), remote };
|
|
9880
|
+
}
|
|
9881
|
+
return {
|
|
9882
|
+
kind: "bounce",
|
|
9883
|
+
branch: null,
|
|
9884
|
+
remote,
|
|
9885
|
+
local: null,
|
|
9886
|
+
origin: null,
|
|
9887
|
+
reason: `no branch for this ticket is on \`${remote}\`; the run's clone was deleted with its sandbox, so nothing it did not push can be recovered`
|
|
9888
|
+
};
|
|
9889
|
+
}
|
|
9890
|
+
function describeGuardError(e, dir) {
|
|
9891
|
+
const msg = e.message;
|
|
9892
|
+
if (!/ENOENT/.test(msg)) return msg;
|
|
9893
|
+
return dir && !existsSync22(dir) ? `the run's clone at ${dir} is gone` : "git is not installed on this machine";
|
|
9894
|
+
}
|
|
9856
9895
|
function inspectHandoff(dir, cfg, ticket, role) {
|
|
9857
9896
|
const remote = cfg.branch.remote;
|
|
9858
9897
|
if (!remoteConfigured(dir, remote)) return { kind: "unverified", why: `no remote \`${remote}\` configured` };
|
|
@@ -9970,7 +10009,7 @@ async function enforceHandoff(i) {
|
|
|
9970
10009
|
i.log.emit(`${t.issue_id} is at ${t.status}, not handed off \u2014 nothing to check`, log);
|
|
9971
10010
|
return { kind: "not-handed-off" };
|
|
9972
10011
|
}
|
|
9973
|
-
const v = inspectHandoff(i.dir, i.cfg, t, i.role);
|
|
10012
|
+
const v = i.origin ? inspectRemoteHandoff(i.origin, i.cfg, t, i.role) : inspectHandoff(i.dir, i.cfg, t, i.role);
|
|
9974
10013
|
if (v.kind === "unverified") {
|
|
9975
10014
|
i.log.warn(`${t.issue_id} is at ${t.status} but the push was not checked: ${v.why}`, log);
|
|
9976
10015
|
return { kind: "unverified", why: v.why };
|
|
@@ -10014,7 +10053,7 @@ async function enforceHandoff(i) {
|
|
|
10014
10053
|
i.log.warn(`${t.issue_id} was taken over by another ship during this run \u2014 left alone`, log);
|
|
10015
10054
|
return { kind: "unverified", why: "ticket was taken over during this run" };
|
|
10016
10055
|
}
|
|
10017
|
-
if (!v.local) {
|
|
10056
|
+
if (!v.local && !i.origin) {
|
|
10018
10057
|
i.log.warn(`${t.issue_id} has no local branch on this ship, so it is not this ship's hand-off to bounce: ${v.reason}`, log);
|
|
10019
10058
|
return { kind: "unverified", why: "no local branch on this ship" };
|
|
10020
10059
|
}
|
|
@@ -10052,8 +10091,9 @@ async function enforceHandoff(i) {
|
|
|
10052
10091
|
i.log.warn(`${t.issue_id} bounced back to ${i.contract.statuses.building}: ${v.reason}`, log);
|
|
10053
10092
|
return { kind: "bounced" };
|
|
10054
10093
|
} catch (e) {
|
|
10055
|
-
|
|
10056
|
-
|
|
10094
|
+
const why = describeGuardError(e, i.dir);
|
|
10095
|
+
i.log.warn(`could not check the hand-off: ${why}`, { step: "handoff" });
|
|
10096
|
+
return { kind: "failed", why };
|
|
10057
10097
|
}
|
|
10058
10098
|
}
|
|
10059
10099
|
async function guardRunHandoff(route2, ship, tracker, role, workingId, log, since2) {
|
|
@@ -10061,16 +10101,23 @@ async function guardRunHandoff(route2, ship, tracker, role, workingId, log, sinc
|
|
|
10061
10101
|
if (!workingId || role !== "dev" && role !== "design" && role !== "qa") return null;
|
|
10062
10102
|
const seatId = route2.resolved?.seats[role];
|
|
10063
10103
|
if (!seatId) return null;
|
|
10104
|
+
let checkoutDir;
|
|
10064
10105
|
try {
|
|
10065
10106
|
const t = await tracker.ticket(workingId);
|
|
10066
10107
|
const resolved = repoConfigFor(route2, t);
|
|
10067
10108
|
if (!resolved) return null;
|
|
10068
10109
|
const { target, cfg } = resolved;
|
|
10110
|
+
checkoutDir = target.dir;
|
|
10069
10111
|
if (role === "qa") {
|
|
10070
10112
|
await retireRunWorktree(tracker, target.dir, cfg, t, role, seatId, ship.name, log);
|
|
10071
10113
|
return null;
|
|
10072
10114
|
}
|
|
10073
10115
|
const affinity = await tracker.claimAffinity();
|
|
10116
|
+
const origin = ship.runner === "sandbox" ? sandboxOriginFor(route2, target.name) : void 0;
|
|
10117
|
+
if (ship.runner === "sandbox" && !origin) {
|
|
10118
|
+
log.warn(`${t.issue_id}: the push was not checked: this ship cannot place the remote of ${target.name}`, { ticket: t.issue_id, step: "handoff" });
|
|
10119
|
+
return null;
|
|
10120
|
+
}
|
|
10074
10121
|
const outcome = replayed.includes(workingId) ? { kind: "pushed", sha: "" } : await enforceHandoff({
|
|
10075
10122
|
writer: tracker,
|
|
10076
10123
|
contract: tracker.contract,
|
|
@@ -10082,19 +10129,21 @@ async function guardRunHandoff(route2, ship, tracker, role, workingId, log, sinc
|
|
|
10082
10129
|
shipName: ship.name,
|
|
10083
10130
|
hold: affinity ? { column: affinity.column, shipId: affinity.shipId } : void 0,
|
|
10084
10131
|
since: since2,
|
|
10085
|
-
log
|
|
10132
|
+
log,
|
|
10133
|
+
...origin ? { origin } : {}
|
|
10086
10134
|
});
|
|
10087
|
-
if (
|
|
10135
|
+
if (origin) {
|
|
10136
|
+
} else if (outcome.kind === "pushed") await retireRunWorktree(tracker, target.dir, cfg, t, role, seatId, ship.name, log);
|
|
10088
10137
|
else {
|
|
10089
10138
|
const branch = existingBranchForTicket(target.dir, cfg, t, role);
|
|
10090
10139
|
if (branch && dropEmptyRunBranch(target.dir, cfg, branch)) {
|
|
10091
10140
|
log.emit(`${t.issue_id}: dropped ${branch} \u2014 the run made no commits beyond ${cfg.branch.base}`, { ticket: t.issue_id, step: "handoff" });
|
|
10092
10141
|
}
|
|
10093
10142
|
}
|
|
10094
|
-
if (since2) await guardRunStrays(route2, ship, tracker, role, workingId, since2, log);
|
|
10143
|
+
if (since2 && !origin) await guardRunStrays(route2, ship, tracker, role, workingId, since2, log);
|
|
10095
10144
|
return outcome;
|
|
10096
10145
|
} catch (e) {
|
|
10097
|
-
log.warn(`could not check the hand-off: ${e
|
|
10146
|
+
log.warn(`could not check the hand-off: ${describeGuardError(e, checkoutDir)}`, { step: "handoff" });
|
|
10098
10147
|
return null;
|
|
10099
10148
|
}
|
|
10100
10149
|
}
|
|
@@ -10313,14 +10362,14 @@ async function findTicketRecord(target, t, ref) {
|
|
|
10313
10362
|
);
|
|
10314
10363
|
return rows.length === 1 ? rows[0].id : void 0;
|
|
10315
10364
|
}
|
|
10316
|
-
function counterIncrements(
|
|
10365
|
+
function counterIncrements(run4, cols, have) {
|
|
10317
10366
|
const figures = [
|
|
10318
10367
|
[cols.agentRuns, 1],
|
|
10319
|
-
[cols.tokensIn,
|
|
10320
|
-
[cols.tokensOut,
|
|
10321
|
-
[cols.cacheReadTokens,
|
|
10322
|
-
[cols.cacheWriteTokens,
|
|
10323
|
-
[cols.costUsd,
|
|
10368
|
+
[cols.tokensIn, run4.tokensIn],
|
|
10369
|
+
[cols.tokensOut, run4.tokensOut],
|
|
10370
|
+
[cols.cacheReadTokens, run4.cacheReadTokens],
|
|
10371
|
+
[cols.cacheWriteTokens, run4.cacheWriteTokens],
|
|
10372
|
+
[cols.costUsd, run4.costUsd]
|
|
10324
10373
|
];
|
|
10325
10374
|
const out = {};
|
|
10326
10375
|
for (const [column, value2] of figures) {
|
|
@@ -10399,42 +10448,42 @@ async function post(target, path, body) {
|
|
|
10399
10448
|
if (!res.ok) throw new AgentLogHttpError(`${path}: ${res.status} ${res.statusText}`, res.status);
|
|
10400
10449
|
return await res.json();
|
|
10401
10450
|
}
|
|
10402
|
-
async function reportAgentRun(target,
|
|
10451
|
+
async function reportAgentRun(target, run4) {
|
|
10403
10452
|
let ticketRecordId;
|
|
10404
|
-
if (target.tickets &&
|
|
10453
|
+
if (target.tickets && run4.ticketReference) {
|
|
10405
10454
|
try {
|
|
10406
|
-
ticketRecordId = await findTicketRecord(target, target.tickets,
|
|
10455
|
+
ticketRecordId = await findTicketRecord(target, target.tickets, run4.ticketReference);
|
|
10407
10456
|
} catch {
|
|
10408
10457
|
}
|
|
10409
10458
|
}
|
|
10410
10459
|
const body = {
|
|
10411
10460
|
agentId: target.agentId,
|
|
10412
|
-
ticketReference:
|
|
10413
|
-
outcome:
|
|
10414
|
-
startedAt:
|
|
10415
|
-
finishedAt:
|
|
10461
|
+
ticketReference: run4.ticketReference,
|
|
10462
|
+
outcome: run4.outcome,
|
|
10463
|
+
startedAt: run4.startedAt,
|
|
10464
|
+
finishedAt: run4.finishedAt,
|
|
10416
10465
|
source: "client",
|
|
10417
10466
|
client: "crew",
|
|
10418
|
-
model:
|
|
10419
|
-
tokensIn:
|
|
10420
|
-
tokensOut:
|
|
10421
|
-
cacheReadTokens:
|
|
10422
|
-
cacheWriteTokens:
|
|
10423
|
-
costUsd:
|
|
10424
|
-
numTurns:
|
|
10425
|
-
prefixTokens:
|
|
10426
|
-
promptVersion:
|
|
10427
|
-
promptSha:
|
|
10467
|
+
model: run4.model,
|
|
10468
|
+
tokensIn: run4.tokensIn,
|
|
10469
|
+
tokensOut: run4.tokensOut,
|
|
10470
|
+
cacheReadTokens: run4.cacheReadTokens,
|
|
10471
|
+
cacheWriteTokens: run4.cacheWriteTokens,
|
|
10472
|
+
costUsd: run4.costUsd,
|
|
10473
|
+
numTurns: run4.numTurns,
|
|
10474
|
+
prefixTokens: run4.prefixTokens,
|
|
10475
|
+
promptVersion: run4.promptVersion,
|
|
10476
|
+
promptSha: run4.promptSha
|
|
10428
10477
|
};
|
|
10429
|
-
const { runId, ...legacyBody } = { ...body, runId:
|
|
10478
|
+
const { runId, ...legacyBody } = { ...body, runId: run4.runId };
|
|
10430
10479
|
const workItem = target.tickets && ticketRecordId ? { workItemTable: target.tickets.issuesModelId, workItemRecordId: ticketRecordId } : {};
|
|
10431
10480
|
let entry;
|
|
10432
10481
|
try {
|
|
10433
|
-
entry = await post(target, "/agents/log", { ...body, ...runId ? { runId } : {}, ...workItem, harness:
|
|
10482
|
+
entry = await post(target, "/agents/log", { ...body, ...runId ? { runId } : {}, ...workItem, harness: run4.harness, provider: run4.provider });
|
|
10434
10483
|
} catch (e) {
|
|
10435
10484
|
if (!(e instanceof AgentLogHttpError)) throw new AgentLogUnreachableError(e.message);
|
|
10436
10485
|
if (e.status >= 500) throw new AgentLogUnreachableError(e.message);
|
|
10437
|
-
if (e.status !== 400 || !
|
|
10486
|
+
if (e.status !== 400 || !run4.harness && !run4.provider && !ticketRecordId && !runId) {
|
|
10438
10487
|
e.row = true;
|
|
10439
10488
|
throw e;
|
|
10440
10489
|
}
|
|
@@ -10445,7 +10494,7 @@ async function reportAgentRun(target, run3) {
|
|
|
10445
10494
|
throw e2;
|
|
10446
10495
|
}
|
|
10447
10496
|
}
|
|
10448
|
-
for (const cycle of
|
|
10497
|
+
for (const cycle of run4.cycles) {
|
|
10449
10498
|
await post(target, `/agents/log/${entry.id}/cycles`, {
|
|
10450
10499
|
cycleIndex: cycle.cycleIndex,
|
|
10451
10500
|
occurredAt: cycle.occurredAt,
|
|
@@ -10453,20 +10502,20 @@ async function reportAgentRun(target, run3) {
|
|
|
10453
10502
|
...cycle.role ? { role: cycle.role } : {}
|
|
10454
10503
|
});
|
|
10455
10504
|
}
|
|
10456
|
-
if (
|
|
10505
|
+
if (run4.beforeFirstEdit) await writeBeforeFirstEdit(target, entry.id, run4.beforeFirstEdit);
|
|
10457
10506
|
if (target.tickets && ticketRecordId) {
|
|
10458
10507
|
const bounces = await countAcceptanceBounces(target, target.tickets.issuesModelId, ticketRecordId);
|
|
10459
10508
|
if (bounces !== null) await writeHandoffBounces(target, entry.id, bounces);
|
|
10460
10509
|
}
|
|
10461
10510
|
let counterWarning;
|
|
10462
|
-
let counted =
|
|
10511
|
+
let counted = run4;
|
|
10463
10512
|
if (runId && target.tickets && ticketRecordId) {
|
|
10464
10513
|
try {
|
|
10465
10514
|
const totals = await inferenceTotalsFor(target, runId);
|
|
10466
|
-
if (totals) counted = { ...
|
|
10467
|
-
else counted = { ...
|
|
10515
|
+
if (totals) counted = { ...run4, tokensIn: totals.tokensIn, tokensOut: totals.tokensOut, cacheReadTokens: totals.cacheReadTokens, cacheWriteTokens: totals.cacheWriteTokens, costUsd: totals.costUsd };
|
|
10516
|
+
else counted = { ...run4, ...run4.harnessTotals };
|
|
10468
10517
|
} catch (e) {
|
|
10469
|
-
counterWarning = `could not sum run ${runId}'s inference rows for ${
|
|
10518
|
+
counterWarning = `could not sum run ${runId}'s inference rows for ${run4.ticketReference}: ${e.message}`;
|
|
10470
10519
|
}
|
|
10471
10520
|
}
|
|
10472
10521
|
const counters = target.tickets && ticketRecordId ? await addRunToTicket(target, target.tickets, ticketRecordId, counted) : void 0;
|
|
@@ -10483,20 +10532,20 @@ async function writeCounters(target, w) {
|
|
|
10483
10532
|
if (Object.keys(body).length === 0) return;
|
|
10484
10533
|
await request(target, "PATCH", `/data-models/${w.issuesModelId}/records/${w.recordId}`, body);
|
|
10485
10534
|
}
|
|
10486
|
-
async function addRunToTicket(target, t, recordId,
|
|
10535
|
+
async function addRunToTicket(target, t, recordId, run4) {
|
|
10487
10536
|
const write = {
|
|
10488
10537
|
issuesModelId: t.issuesModelId,
|
|
10489
10538
|
recordId,
|
|
10490
|
-
ticketReference:
|
|
10539
|
+
ticketReference: run4.ticketReference,
|
|
10491
10540
|
counters: t.counters,
|
|
10492
|
-
body: counterIncrements(
|
|
10541
|
+
body: counterIncrements(run4, t.counters, new Set(Object.values(t.counters)))
|
|
10493
10542
|
};
|
|
10494
10543
|
try {
|
|
10495
10544
|
await writeCounters(target, write);
|
|
10496
10545
|
return {};
|
|
10497
10546
|
} catch (e) {
|
|
10498
10547
|
return {
|
|
10499
|
-
warning: `could not add run spend to ${
|
|
10548
|
+
warning: `could not add run spend to ${run4.ticketReference}: ${e.message}`,
|
|
10500
10549
|
...isRetryable(e) ? { retry: write } : {}
|
|
10501
10550
|
};
|
|
10502
10551
|
}
|
|
@@ -10508,7 +10557,7 @@ function queueAgentRun(stateDir, name, q2) {
|
|
|
10508
10557
|
}
|
|
10509
10558
|
async function replayQueuedAgentRuns(stateDir, route2, keyFor, log, now = /* @__PURE__ */ new Date()) {
|
|
10510
10559
|
const dir = queueDir(stateDir);
|
|
10511
|
-
if (!
|
|
10560
|
+
if (!existsSync23(dir)) return 0;
|
|
10512
10561
|
let sent = 0;
|
|
10513
10562
|
for (const f of readdirSync7(dir).filter((n) => n.endsWith(".json")).sort()) {
|
|
10514
10563
|
const path = join25(dir, f);
|
|
@@ -10561,7 +10610,7 @@ function queueTicketCounters(stateDir, name, q2) {
|
|
|
10561
10610
|
}
|
|
10562
10611
|
async function replayQueuedTicketCounters(stateDir, route2, keyFor, log, now = /* @__PURE__ */ new Date()) {
|
|
10563
10612
|
const dir = countersDir(stateDir);
|
|
10564
|
-
if (!
|
|
10613
|
+
if (!existsSync23(dir)) return 0;
|
|
10565
10614
|
let sent = 0;
|
|
10566
10615
|
for (const f of readdirSync7(dir).filter((n) => n.endsWith(".json")).sort()) {
|
|
10567
10616
|
const path = join25(dir, f);
|
|
@@ -10829,10 +10878,10 @@ var HandoffTranscriptTracker = class {
|
|
|
10829
10878
|
import { createHash as createHash4 } from "crypto";
|
|
10830
10879
|
import { spawn as spawn3 } from "child_process";
|
|
10831
10880
|
import { execFileSync as execFileSync7 } from "child_process";
|
|
10832
|
-
import { existsSync as
|
|
10881
|
+
import { existsSync as existsSync24, mkdirSync as mkdirSync17, readFileSync as readFileSync24, renameSync as renameSync3, writeFileSync as writeFileSync18, rmSync as rmSync14, statSync as statSync8 } from "fs";
|
|
10833
10882
|
import { dirname as dirname13, join as join26 } from "path";
|
|
10834
10883
|
import { fileURLToPath } from "url";
|
|
10835
|
-
import { tmpdir as
|
|
10884
|
+
import { tmpdir as tmpdir3 } from "os";
|
|
10836
10885
|
var SANDBOX_BASE_IMAGE = "nvcr.io/nvidia/base/ubuntu:24.04";
|
|
10837
10886
|
var SANDBOX_OPENSHELL_VERSION = "0.1.6";
|
|
10838
10887
|
var SANDBOX_CLAUDE_VERSION = "2.1.309";
|
|
@@ -10847,7 +10896,7 @@ var SANDBOX_BRIDGE_PATH = `${CREW_PREFIX}/bin/intel-bridge`;
|
|
|
10847
10896
|
function readBridgeBundle() {
|
|
10848
10897
|
const here = dirname13(fileURLToPath(import.meta.url));
|
|
10849
10898
|
for (const p of [join26(here, "sandbox-intel-bridge.cjs"), join26(here, "..", "dist", "sandbox-intel-bridge.cjs")]) {
|
|
10850
|
-
if (
|
|
10899
|
+
if (existsSync24(p)) return readFileSync24(p, "utf8");
|
|
10851
10900
|
}
|
|
10852
10901
|
return void 0;
|
|
10853
10902
|
}
|
|
@@ -11065,6 +11114,7 @@ function sandboxImageStatus(state, plan) {
|
|
|
11065
11114
|
if (current.tag !== plan.tag) return { status: "stale", detail: `running ${current.tag} (claude ${current.claude ?? "unknown"}), declaration now builds ${plan.tag} (claude ${plan.claude})` };
|
|
11066
11115
|
return { status: "ok", detail: `${current.tag} built ${current.builtAt}, claude ${current.claude ?? "unknown"}` };
|
|
11067
11116
|
}
|
|
11117
|
+
var BUILD_INTERRUPTED = -1;
|
|
11068
11118
|
var spawnBuildRunner = (engine = "docker") => (args, logPath) => new Promise((resolve8) => {
|
|
11069
11119
|
const child = spawn3(engine, args, { stdio: ["ignore", "pipe", "pipe"] });
|
|
11070
11120
|
const chunks = [];
|
|
@@ -11077,7 +11127,7 @@ ${Buffer.concat(chunks).toString("utf8")}${extra}`, { flag: "a" });
|
|
|
11077
11127
|
};
|
|
11078
11128
|
child.on("error", (e) => done(127, `${e.message}
|
|
11079
11129
|
`));
|
|
11080
|
-
child.on("close", (code) => done(code ??
|
|
11130
|
+
child.on("close", (code) => done(code ?? BUILD_INTERRUPTED));
|
|
11081
11131
|
});
|
|
11082
11132
|
var engineHasImage = (engine = "docker", exec = realExec) => (tag) => {
|
|
11083
11133
|
try {
|
|
@@ -11107,7 +11157,7 @@ async function buildSandboxImage(plan, deps) {
|
|
|
11107
11157
|
const builtLayers = [];
|
|
11108
11158
|
for (const layer of plan.layers) {
|
|
11109
11159
|
if (deps.hasImage(layer.tag)) continue;
|
|
11110
|
-
const ctx = join26(
|
|
11160
|
+
const ctx = join26(tmpdir3(), `crew-sandbox-${hash([layer.tag, process.pid, Date.now()])}`);
|
|
11111
11161
|
mkdirSync17(ctx, { recursive: true });
|
|
11112
11162
|
try {
|
|
11113
11163
|
writeFileSync18(join26(ctx, "Dockerfile"), layer.dockerfile);
|
|
@@ -11117,6 +11167,7 @@ async function buildSandboxImage(plan, deps) {
|
|
|
11117
11167
|
}
|
|
11118
11168
|
if (layer.caBundleFile) writeFileSync18(join26(ctx, layer.caBundleFile), (deps.caBundle ?? readHostCaBundle)());
|
|
11119
11169
|
const code = await deps.run(["build", "--tag", layer.tag, "--file", join26(ctx, "Dockerfile"), ctx], logPath);
|
|
11170
|
+
if (code === BUILD_INTERRUPTED) return { kind: "interrupted", tag: plan.tag };
|
|
11120
11171
|
if (code !== 0) {
|
|
11121
11172
|
state[plan.repo] = { ...entry, failure: { tag: plan.tag, at: now().toISOString(), logPath } };
|
|
11122
11173
|
writeSandboxState(deps.stateDir, state);
|
|
@@ -11143,9 +11194,20 @@ function sandboxFailedItem(repo, tag, layer, logPath, nowIso = (/* @__PURE__ */
|
|
|
11143
11194
|
message: `${repo}: sandbox image ${tag} failed to build at the ${layer} layer (log: ${logPath}); sandboxes keep running the previous image. Retries automatically after the declaration changes or in an hour; \`crew sandbox build\` forces it`
|
|
11144
11195
|
};
|
|
11145
11196
|
}
|
|
11197
|
+
function failureLogIsEmpty(failure) {
|
|
11198
|
+
try {
|
|
11199
|
+
return statSync8(failure.logPath).size === 0;
|
|
11200
|
+
} catch {
|
|
11201
|
+
return true;
|
|
11202
|
+
}
|
|
11203
|
+
}
|
|
11146
11204
|
async function sandboxBuildTick(repos, deps, force = false) {
|
|
11147
11205
|
const nowMs = (deps.now ?? (() => /* @__PURE__ */ new Date()))().getTime();
|
|
11148
11206
|
for (const r of repos) {
|
|
11207
|
+
if (r.unreadable) {
|
|
11208
|
+
deps.log(`sandbox image for ${r.name}: not building, ${r.unreadable}`);
|
|
11209
|
+
continue;
|
|
11210
|
+
}
|
|
11149
11211
|
const plan = planSandbox(r.name, r.decl, r.warm, r.bridge);
|
|
11150
11212
|
const state = readSandboxState(deps.stateDir)[r.name];
|
|
11151
11213
|
const upToDate = state?.tags[0]?.tag === plan.tag && deps.hasImage(plan.tag);
|
|
@@ -11154,10 +11216,12 @@ async function sandboxBuildTick(repos, deps, force = false) {
|
|
|
11154
11216
|
continue;
|
|
11155
11217
|
}
|
|
11156
11218
|
const present = !upToDate && deps.hasImage(plan.tag);
|
|
11157
|
-
if (!force && !present && state?.failure?.tag === plan.tag && nowMs - Date.parse(state.failure.at) < SANDBOX_RETRY_AFTER_MS) continue;
|
|
11219
|
+
if (!force && !present && state?.failure?.tag === plan.tag && nowMs - Date.parse(state.failure.at) < SANDBOX_RETRY_AFTER_MS && !failureLogIsEmpty(state.failure)) continue;
|
|
11158
11220
|
deps.log(`sandbox image for ${r.name}: ${present ? `found ${plan.tag} in the engine, recording it` : `building ${plan.tag}`}`);
|
|
11159
11221
|
const out = await buildSandboxImage(plan, deps);
|
|
11160
|
-
if (out.kind === "
|
|
11222
|
+
if (out.kind === "interrupted") {
|
|
11223
|
+
deps.log(`sandbox image for ${r.name}: build of ${out.tag} was interrupted; it restarts on the next pass`);
|
|
11224
|
+
} else if (out.kind === "failed") {
|
|
11161
11225
|
deps.raise(sandboxFailedItem(r.name, out.tag, out.layer, out.logPath));
|
|
11162
11226
|
deps.log(`sandbox image for ${r.name}: build failed at the ${out.layer} layer, log ${out.logPath}`);
|
|
11163
11227
|
} else {
|
|
@@ -11214,7 +11278,7 @@ function expandSkillMarkers(text2, lookup2, opts = {}) {
|
|
|
11214
11278
|
}
|
|
11215
11279
|
|
|
11216
11280
|
// src/skills.ts
|
|
11217
|
-
import { readFileSync as readFileSync26, readdirSync as readdirSync8, existsSync as
|
|
11281
|
+
import { readFileSync as readFileSync26, readdirSync as readdirSync8, existsSync as existsSync26 } from "fs";
|
|
11218
11282
|
import { join as join28 } from "path";
|
|
11219
11283
|
import { parse as parseYaml } from "yaml";
|
|
11220
11284
|
import { TablationClient as TablationClient3, StaleWriteError as StaleWriteError3, TablationApiError as TablationApiError2 } from "@tablation/client";
|
|
@@ -11231,7 +11295,7 @@ ${additions}`;
|
|
|
11231
11295
|
}
|
|
11232
11296
|
|
|
11233
11297
|
// src/agents.ts
|
|
11234
|
-
import { readFileSync as readFileSync25, existsSync as
|
|
11298
|
+
import { readFileSync as readFileSync25, existsSync as existsSync25 } from "fs";
|
|
11235
11299
|
import { join as join27 } from "path";
|
|
11236
11300
|
import { TablationClient as TablationClient2, StaleWriteError as StaleWriteError2, TablationApiError } from "@tablation/client";
|
|
11237
11301
|
var PERSONA_NAME = {
|
|
@@ -11247,10 +11311,10 @@ var AgentsSyncError = class extends Error {
|
|
|
11247
11311
|
};
|
|
11248
11312
|
function personaDefaultPrompt(promptsDir, role) {
|
|
11249
11313
|
const briefPath = join27(promptsDir, "personas", `lane-${role}.md`);
|
|
11250
|
-
if (!
|
|
11314
|
+
if (!existsSync25(briefPath)) throw new AgentsSyncError(`no brief at ${briefPath}`);
|
|
11251
11315
|
if (SELF_CONTAINED_ROLES.has(role)) return readFileSync25(briefPath, "utf8");
|
|
11252
11316
|
const commonPath = join27(promptsDir, "personas", "common.md");
|
|
11253
|
-
if (!
|
|
11317
|
+
if (!existsSync25(commonPath)) return readFileSync25(briefPath, "utf8");
|
|
11254
11318
|
return `${readFileSync25(commonPath, "utf8")}${readFileSync25(briefPath, "utf8")}`;
|
|
11255
11319
|
}
|
|
11256
11320
|
async function resolveAgentId(route2, role, opts) {
|
|
@@ -11712,7 +11776,7 @@ function parseSkillFile(path) {
|
|
|
11712
11776
|
}
|
|
11713
11777
|
function listLocalSkills(promptsDir) {
|
|
11714
11778
|
const dir = join28(promptsDir, "skills");
|
|
11715
|
-
if (!
|
|
11779
|
+
if (!existsSync26(dir)) return [];
|
|
11716
11780
|
return readdirSync8(dir).filter((f) => f.endsWith(".md")).map((f) => parseSkillFile(join28(dir, f)));
|
|
11717
11781
|
}
|
|
11718
11782
|
async function syncSkills(route2, opts) {
|
|
@@ -11900,7 +11964,7 @@ function skillMarkerWarnings(promptsDir, personaPrompts) {
|
|
|
11900
11964
|
import { spawn as spawn4, execFile, execFileSync as execFileSync8 } from "child_process";
|
|
11901
11965
|
import { mkdtempSync, mkdirSync as mkdirSync18, writeFileSync as writeFileSync19, rmSync as rmSync15 } from "fs";
|
|
11902
11966
|
import { createHash as createHash5 } from "crypto";
|
|
11903
|
-
import { tmpdir as
|
|
11967
|
+
import { tmpdir as tmpdir4 } from "os";
|
|
11904
11968
|
import { basename as basename8, dirname as dirname14, join as join29 } from "path";
|
|
11905
11969
|
import { promisify } from "util";
|
|
11906
11970
|
|
|
@@ -11999,6 +12063,16 @@ function sandboxName(plan, now = Date.now()) {
|
|
|
11999
12063
|
const tag = (h.readUInt32BE(0) % 36 ** 6).toString(36).padStart(6, "0");
|
|
12000
12064
|
return `crew-${tag}${now.toString(36).slice(-8).padStart(8, "0")}`;
|
|
12001
12065
|
}
|
|
12066
|
+
function labelValue(v) {
|
|
12067
|
+
return v.replace(/[^A-Za-z0-9._-]/g, "_").slice(0, 63);
|
|
12068
|
+
}
|
|
12069
|
+
function sandboxLabels(o) {
|
|
12070
|
+
return [
|
|
12071
|
+
`crew.role=${labelValue(o.role)}`,
|
|
12072
|
+
...o.ticket ? [`crew.ticket=${labelValue(o.ticket)}`] : [],
|
|
12073
|
+
`crew.run=${labelValue(o.run)}`
|
|
12074
|
+
];
|
|
12075
|
+
}
|
|
12002
12076
|
var SandboxRunner = class {
|
|
12003
12077
|
kind = "sandbox";
|
|
12004
12078
|
cfg;
|
|
@@ -12041,6 +12115,7 @@ var SandboxRunner = class {
|
|
|
12041
12115
|
}
|
|
12042
12116
|
const create2 = ["sandbox", "create", "--name", name, "--detach"];
|
|
12043
12117
|
if (policyFile) create2.push("--policy", policyFile);
|
|
12118
|
+
for (const l of sandboxLabels({ role: plan.role, ticket: plan.ticket, run: basename8(plan.streamPath).replace(/\.jsonl$/, "") })) create2.push("--label", l);
|
|
12044
12119
|
const image = cfg.image ?? plan.sandboxImage;
|
|
12045
12120
|
if (image) create2.push("--from", image);
|
|
12046
12121
|
if (cfg.cacheVolume) {
|
|
@@ -12085,7 +12160,7 @@ var SandboxRunner = class {
|
|
|
12085
12160
|
const harness = cfg.agentBin ?? basename8(plan.bin);
|
|
12086
12161
|
const viaUpload = Buffer.byteLength(plan.prompt) > SANDBOX_STDIN_LIMIT;
|
|
12087
12162
|
if (viaUpload) {
|
|
12088
|
-
const tmp = mkdtempSync(join29(
|
|
12163
|
+
const tmp = mkdtempSync(join29(tmpdir4(), "crew-prompt-"));
|
|
12089
12164
|
try {
|
|
12090
12165
|
const file = join29(tmp, "prompt.txt");
|
|
12091
12166
|
writeFileSync19(file, plan.prompt, { mode: 384 });
|
|
@@ -12163,16 +12238,16 @@ function runnerOfSidecar(sc) {
|
|
|
12163
12238
|
return sc.runner === "sandbox" ? new SandboxRunner(sc.sandboxBin ? { bin: sc.sandboxBin } : {}) : new HostRunner();
|
|
12164
12239
|
}
|
|
12165
12240
|
var PROBE_CREATE_TIMEOUT_MS = 12e4;
|
|
12166
|
-
function checkSandboxRunner(cfg = {},
|
|
12241
|
+
function checkSandboxRunner(cfg = {}, run4 = (b, a, t) => execFileSync8(b, a, { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], timeout: t ?? 15e3 })) {
|
|
12167
12242
|
const bin = cfg.bin ?? DEFAULT_SANDBOX_CONFIG.bin;
|
|
12168
12243
|
let version;
|
|
12169
12244
|
try {
|
|
12170
|
-
version =
|
|
12245
|
+
version = run4(bin, ["--version"]).trim();
|
|
12171
12246
|
} catch (e) {
|
|
12172
12247
|
return { ok: false, detail: `${bin} is not installed or not on the scheduler PATH (${e.message.split("\n")[0]})` };
|
|
12173
12248
|
}
|
|
12174
12249
|
try {
|
|
12175
|
-
|
|
12250
|
+
run4(bin, ["status"]);
|
|
12176
12251
|
} catch (e) {
|
|
12177
12252
|
const err3 = e;
|
|
12178
12253
|
return {
|
|
@@ -12182,7 +12257,7 @@ function checkSandboxRunner(cfg = {}, run3 = (b, a, t) => execFileSync8(b, a, {
|
|
|
12182
12257
|
}
|
|
12183
12258
|
const probe = sandboxName({ route: "doctor", role: "dev", ticket: void 0 });
|
|
12184
12259
|
try {
|
|
12185
|
-
|
|
12260
|
+
run4(bin, ["sandbox", "create", "--name", probe, "--detach", "--", "sleep", "60"], PROBE_CREATE_TIMEOUT_MS);
|
|
12186
12261
|
} catch (e) {
|
|
12187
12262
|
const err3 = e;
|
|
12188
12263
|
if (err3.code === "ETIMEDOUT" || err3.killed) {
|
|
@@ -12191,7 +12266,7 @@ function checkSandboxRunner(cfg = {}, run3 = (b, a, t) => execFileSync8(b, a, {
|
|
|
12191
12266
|
return { ok: false, detail: `${version}: the gateway refused a probe sandbox named ${probe} (${(err3.stderr || err3.message).trim().split("\n").filter(Boolean).slice(0, 2).join(" / ")})` };
|
|
12192
12267
|
} finally {
|
|
12193
12268
|
try {
|
|
12194
|
-
|
|
12269
|
+
run4(bin, ["sandbox", "delete", probe]);
|
|
12195
12270
|
} catch {
|
|
12196
12271
|
}
|
|
12197
12272
|
}
|
|
@@ -12359,19 +12434,19 @@ function codeBridgeFor(o, harness) {
|
|
|
12359
12434
|
}
|
|
12360
12435
|
function planAgentRun(o) {
|
|
12361
12436
|
const briefPath = join30(o.route.promptsDir, "personas", `lane-${o.role}.md`);
|
|
12362
|
-
if (!
|
|
12437
|
+
if (!existsSync27(briefPath)) {
|
|
12363
12438
|
throw new AgentError(`no brief at ${briefPath} \u2014 refusing to run an unscoped session`);
|
|
12364
12439
|
}
|
|
12365
12440
|
const commonPath = join30(o.route.promptsDir, "personas", "common.md");
|
|
12366
|
-
const usesCommon = !SELF_CONTAINED_ROLES.has(o.role) &&
|
|
12441
|
+
const usesCommon = !SELF_CONTAINED_ROLES.has(o.role) && existsSync27(commonPath);
|
|
12367
12442
|
const now = o.now ?? (() => Date.now());
|
|
12368
12443
|
const routeLabel = routeSlug(o.route.route);
|
|
12369
12444
|
const ownDigest = o.runId ? digestPathFor(o.stateDir, routeLabel, o.role, o.runId) : void 0;
|
|
12370
|
-
const digestPath2 = ownDigest &&
|
|
12445
|
+
const digestPath2 = ownDigest && existsSync27(ownDigest) ? ownDigest : digestPathFor(o.stateDir, routeLabel, o.role);
|
|
12371
12446
|
let digest;
|
|
12372
12447
|
let ageSeconds;
|
|
12373
|
-
if (
|
|
12374
|
-
ageSeconds = Math.floor((now() -
|
|
12448
|
+
if (existsSync27(digestPath2)) {
|
|
12449
|
+
ageSeconds = Math.floor((now() - statSync9(digestPath2).mtimeMs) / 1e3);
|
|
12375
12450
|
if (ageSeconds <= DIGEST_MAX_AGE_SECONDS) digest = readFileSync27(digestPath2, "utf8");
|
|
12376
12451
|
}
|
|
12377
12452
|
const common = usesCommon ? readFileSync27(commonPath, "utf8") : "";
|
|
@@ -12980,9 +13055,9 @@ function spawnAgent(plan, emit, hintMoved) {
|
|
|
12980
13055
|
}
|
|
12981
13056
|
if (begun instanceof Promise) {
|
|
12982
13057
|
return begun.then(
|
|
12983
|
-
(
|
|
13058
|
+
(run4) => {
|
|
12984
13059
|
closeSync4(streamFd);
|
|
12985
|
-
return supervise(
|
|
13060
|
+
return supervise(run4);
|
|
12986
13061
|
},
|
|
12987
13062
|
(e) => {
|
|
12988
13063
|
closeSync4(streamFd);
|
|
@@ -13134,7 +13209,7 @@ var pidAlive = (pid) => {
|
|
|
13134
13209
|
};
|
|
13135
13210
|
function runFinished(streamPath) {
|
|
13136
13211
|
const path = `${streamPath}.meta.json`;
|
|
13137
|
-
if (!
|
|
13212
|
+
if (!existsSync28(path)) return false;
|
|
13138
13213
|
try {
|
|
13139
13214
|
return JSON.parse(readFileSync28(path, "utf8")).running !== true;
|
|
13140
13215
|
} catch {
|
|
@@ -13143,7 +13218,7 @@ function runFinished(streamPath) {
|
|
|
13143
13218
|
}
|
|
13144
13219
|
function orphanedStreams(o) {
|
|
13145
13220
|
const dir = join31(o.stateDir, "streams");
|
|
13146
|
-
if (!
|
|
13221
|
+
if (!existsSync28(dir)) return [];
|
|
13147
13222
|
const ownerAlive = o.isOwnerAlive ?? pidAlive;
|
|
13148
13223
|
const out = [];
|
|
13149
13224
|
for (const name of readdirSync9(dir)) {
|
|
@@ -13201,11 +13276,11 @@ async function reconcileRuns(o) {
|
|
|
13201
13276
|
}
|
|
13202
13277
|
|
|
13203
13278
|
// src/live-runs.ts
|
|
13204
|
-
import { existsSync as
|
|
13279
|
+
import { existsSync as existsSync29, readdirSync as readdirSync10, statSync as statSync10 } from "fs";
|
|
13205
13280
|
import { join as join32 } from "path";
|
|
13206
13281
|
function liveRuns(stateDir, isAlive = runIsAlive) {
|
|
13207
13282
|
const dir = join32(stateDir, "streams");
|
|
13208
|
-
if (!
|
|
13283
|
+
if (!existsSync29(dir)) return [];
|
|
13209
13284
|
const out = [];
|
|
13210
13285
|
for (const name of readdirSync10(dir)) {
|
|
13211
13286
|
if (!name.endsWith(".jsonl") || name.endsWith(".events.jsonl")) continue;
|
|
@@ -13221,13 +13296,13 @@ function runActivity(stateDir, isAlive = runIsAlive) {
|
|
|
13221
13296
|
const activeRuns = liveRuns(stateDir, isAlive).length;
|
|
13222
13297
|
const dir = join32(stateDir, "streams");
|
|
13223
13298
|
let newest = 0;
|
|
13224
|
-
if (
|
|
13299
|
+
if (existsSync29(dir)) {
|
|
13225
13300
|
for (const name of readdirSync10(dir)) {
|
|
13226
13301
|
if (!name.endsWith(".jsonl") || name.endsWith(".events.jsonl")) continue;
|
|
13227
13302
|
const streamPath = join32(dir, name);
|
|
13228
13303
|
if (!runFinished(streamPath)) continue;
|
|
13229
13304
|
try {
|
|
13230
|
-
newest = Math.max(newest,
|
|
13305
|
+
newest = Math.max(newest, statSync10(`${streamPath}.meta.json`).mtimeMs);
|
|
13231
13306
|
} catch {
|
|
13232
13307
|
}
|
|
13233
13308
|
}
|
|
@@ -13263,27 +13338,27 @@ async function settleRunEnd(o) {
|
|
|
13263
13338
|
emit.warn(`could not beat ship idle: ${e.message}`, { step: "agent" });
|
|
13264
13339
|
}
|
|
13265
13340
|
}
|
|
13266
|
-
function describeRun(
|
|
13341
|
+
function describeRun(run4, route2, seatIds, worktreeOf = (d, n) => {
|
|
13267
13342
|
try {
|
|
13268
13343
|
return worktreeForNumber(d, n)?.path ?? null;
|
|
13269
13344
|
} catch {
|
|
13270
13345
|
return null;
|
|
13271
13346
|
}
|
|
13272
13347
|
}) {
|
|
13273
|
-
const ownRoute =
|
|
13274
|
-
const repoDir =
|
|
13275
|
-
const num2 =
|
|
13348
|
+
const ownRoute = run4.route === routeSlug(route2.route);
|
|
13349
|
+
const repoDir = run4.repo ? reposOf(route2).find((t) => t.name === run4.repo)?.dir : void 0;
|
|
13350
|
+
const num2 = run4.ticket?.replace(/^\D+/, "") ?? "";
|
|
13276
13351
|
return {
|
|
13277
|
-
role:
|
|
13278
|
-
seat: ownRoute ? seatIds[
|
|
13279
|
-
ticket:
|
|
13280
|
-
ticketRecordId:
|
|
13281
|
-
repo:
|
|
13352
|
+
role: run4.role,
|
|
13353
|
+
seat: ownRoute ? seatIds[run4.role] ?? null : null,
|
|
13354
|
+
ticket: run4.ticket,
|
|
13355
|
+
ticketRecordId: run4.ticketRecordId,
|
|
13356
|
+
repo: run4.repo ?? null,
|
|
13282
13357
|
worktree: repoDir && num2 ? worktreeOf(repoDir, num2) : null,
|
|
13283
|
-
stream:
|
|
13284
|
-
pid:
|
|
13285
|
-
startedAt:
|
|
13286
|
-
deadline:
|
|
13358
|
+
stream: run4.streamPath,
|
|
13359
|
+
pid: run4.pid,
|
|
13360
|
+
startedAt: run4.spawnedAt,
|
|
13361
|
+
deadline: run4.deadline ?? null
|
|
13287
13362
|
};
|
|
13288
13363
|
}
|
|
13289
13364
|
|
|
@@ -13319,26 +13394,26 @@ function realDeprovisionDeps(cfg, emit, crewHome, getStore) {
|
|
|
13319
13394
|
if (host === "windows") return [];
|
|
13320
13395
|
const ctx = installContext();
|
|
13321
13396
|
const systemd = detectSystemd();
|
|
13322
|
-
return ["run", "release", "passengers"].flatMap((job) => planInstall(cfg.ship, crewHome, host, systemd, job, ctx).unitPaths).filter((p) =>
|
|
13397
|
+
return ["run", "release", "passengers"].flatMap((job) => planInstall(cfg.ship, crewHome, host, systemd, job, ctx).unitPaths).filter((p) => existsSync30(p));
|
|
13323
13398
|
};
|
|
13324
13399
|
return {
|
|
13325
13400
|
liveRuns: () => liveRuns(stateDir).map((r) => ({ role: r.role, route: r.route, pid: r.pid, ticketRecordId: r.ticketRecordId ?? void 0, streamPath: r.streamPath })),
|
|
13326
|
-
killRun: (
|
|
13327
|
-
recordKill(
|
|
13328
|
-
emit.emit(`run_killed: ${
|
|
13401
|
+
killRun: (run4) => killRunGroup(run4.pid),
|
|
13402
|
+
recordKill(run4) {
|
|
13403
|
+
emit.emit(`run_killed: ${run4.role} run on ${run4.route} stopped by crew deprovision`, {
|
|
13329
13404
|
step: "agent",
|
|
13330
|
-
role:
|
|
13331
|
-
data: { event: "run_killed", reason: "deprovision", pid:
|
|
13405
|
+
role: run4.role,
|
|
13406
|
+
data: { event: "run_killed", reason: "deprovision", pid: run4.pid }
|
|
13332
13407
|
});
|
|
13333
13408
|
},
|
|
13334
|
-
async handBack(
|
|
13335
|
-
const route2 = routeFor(
|
|
13336
|
-
if (!
|
|
13337
|
-
const memberId = route2.resolved?.seats[
|
|
13409
|
+
async handBack(run4) {
|
|
13410
|
+
const route2 = routeFor(run4.route);
|
|
13411
|
+
if (!run4.ticketRecordId || !route2) return;
|
|
13412
|
+
const memberId = route2.resolved?.seats[run4.role];
|
|
13338
13413
|
if (!memberId) return;
|
|
13339
|
-
const identity = await resolveSeatKey(route2,
|
|
13414
|
+
const identity = await resolveSeatKey(route2, run4.role, getStore);
|
|
13340
13415
|
const tracker = new Tracker(route2, cfg.ship, { apiKey: identity.apiKey });
|
|
13341
|
-
const t = await tracker.ticket(
|
|
13416
|
+
const t = await tracker.ticket(run4.ticketRecordId);
|
|
13342
13417
|
const target = repoTargetFor(route2, t.repo_id);
|
|
13343
13418
|
const num2 = String(t[tracker.contract.columns.key] ?? "").replace(/^\D+/, "");
|
|
13344
13419
|
const wt = target && num2 ? worktreeForNumber(target.dir, num2) : null;
|
|
@@ -13347,7 +13422,7 @@ function realDeprovisionDeps(cfg, emit, crewHome, getStore) {
|
|
|
13347
13422
|
if (wt) dirty = status(wt.path).length > 0;
|
|
13348
13423
|
} catch {
|
|
13349
13424
|
}
|
|
13350
|
-
await tracker.postEvent(
|
|
13425
|
+
await tracker.postEvent(run4.ticketRecordId, interruptedComment({
|
|
13351
13426
|
branch: wt?.branch ?? null,
|
|
13352
13427
|
dirty,
|
|
13353
13428
|
reason: "the host was released and wiped"
|
|
@@ -13380,7 +13455,7 @@ function realDeprovisionDeps(cfg, emit, crewHome, getStore) {
|
|
|
13380
13455
|
},
|
|
13381
13456
|
remaining() {
|
|
13382
13457
|
const left = [];
|
|
13383
|
-
if (
|
|
13458
|
+
if (existsSync30(cfg.configFile)) left.push(`config ${cfg.configFile}`);
|
|
13384
13459
|
for (const h of forgeHosts()) if (hasForgeToken(cfg.ship.forges, h, stateDir)) left.push(`forge token for ${h}`);
|
|
13385
13460
|
try {
|
|
13386
13461
|
for (const k of readdirSync11(keysDir(stateDir))) left.push(`seat key ${k}`);
|
|
@@ -14037,12 +14112,12 @@ function isSshRemote(url) {
|
|
|
14037
14112
|
function pushAuthHint(remoteUrl) {
|
|
14038
14113
|
return isSshRemote(remoteUrl) ? "make sure an SSH key is loaded for this host (ssh-add), and that the scheduler user can reach it" : "run `gh auth login`, then `gh auth setup-git`";
|
|
14039
14114
|
}
|
|
14040
|
-
function probePushAuth(o,
|
|
14115
|
+
function probePushAuth(o, run4 = realGit, baseEnv = process.env) {
|
|
14041
14116
|
if (o.offline) return { state: "skipped", detail: "skipped (--offline)" };
|
|
14042
14117
|
if (!o.remoteUrl) return { state: "skipped", detail: `no remote "${o.remote}" configured` };
|
|
14043
14118
|
const env = { ...baseEnv, GIT_TERMINAL_PROMPT: "0", GCM_INTERACTIVE: "never", GIT_SSH_COMMAND: `${baseEnv.GIT_SSH_COMMAND ?? "ssh"} -o BatchMode=yes` };
|
|
14044
14119
|
try {
|
|
14045
|
-
|
|
14120
|
+
run4(o.dir, ["push", "--dry-run", o.remote, `HEAD:refs/heads/${PROBE_BRANCH}`], env);
|
|
14046
14121
|
return { state: "ok" };
|
|
14047
14122
|
} catch (e) {
|
|
14048
14123
|
const err3 = e;
|
|
@@ -14058,7 +14133,7 @@ function probePushAuth(o, run3 = realGit, baseEnv = process.env) {
|
|
|
14058
14133
|
};
|
|
14059
14134
|
}
|
|
14060
14135
|
try {
|
|
14061
|
-
|
|
14136
|
+
run4(o.dir, ["ls-remote", "--exit-code", o.remote, "HEAD"], env);
|
|
14062
14137
|
return {
|
|
14063
14138
|
state: "failed",
|
|
14064
14139
|
detail: `the token for forge ${f.host} is read-only (fetch works, push refused): ${detail}`,
|
|
@@ -14100,8 +14175,8 @@ function formatToolCheck(t) {
|
|
|
14100
14175
|
return `${label}${t.need === "required" ? "NOT FOUND" : "not found"} [${t.need}] \u2014 ${t.hint}
|
|
14101
14176
|
`;
|
|
14102
14177
|
}
|
|
14103
|
-
function probeCredentialHelper(command2,
|
|
14104
|
-
const r =
|
|
14178
|
+
function probeCredentialHelper(command2, run4 = realHelperRun) {
|
|
14179
|
+
const r = run4(`${command2} credential get --no-miss`, "protocol=https\nhost=crew-probe.invalid\n\n");
|
|
14105
14180
|
if (r.status === 0 && !/unknown command|usage:/i.test(r.stderr)) return { state: "ok" };
|
|
14106
14181
|
const why = r.stderr.trim().split("\n")[0] || `exit ${r.status}`;
|
|
14107
14182
|
return { state: "failed", detail: `the git credential helper command does not run: ${why}`, hint: "reinstall crew; git cannot authenticate to a private repository until this works" };
|
|
@@ -14192,8 +14267,8 @@ function managedGitIdentityWarnings(kind, identity) {
|
|
|
14192
14267
|
|
|
14193
14268
|
// src/selftest.ts
|
|
14194
14269
|
import { spawn as spawn6 } from "child_process";
|
|
14195
|
-
import { existsSync as
|
|
14196
|
-
import { tmpdir as
|
|
14270
|
+
import { existsSync as existsSync31, mkdirSync as mkdirSync20, mkdtempSync as mkdtempSync2, readFileSync as readFileSync29, rmSync as rmSync16, writeFileSync as writeFileSync21 } from "fs";
|
|
14271
|
+
import { tmpdir as tmpdir5 } from "os";
|
|
14197
14272
|
import { join as join33 } from "path";
|
|
14198
14273
|
var SELFTEST_TIMEOUT_MS = 12e4;
|
|
14199
14274
|
var KEY_VAR = "CREW_API_KEY";
|
|
@@ -14308,17 +14383,17 @@ var REMEDY = {
|
|
|
14308
14383
|
timeout: "the harness did not answer in time \u2014 run it by hand to see where it stalls",
|
|
14309
14384
|
"wrong-answer": "the agent answered but did not name the workspace \u2014 run it by hand to see what it said"
|
|
14310
14385
|
};
|
|
14311
|
-
function classify(spec,
|
|
14386
|
+
function classify(spec, run4, seen) {
|
|
14312
14387
|
const bin = spec.launcher ?? spec.bin;
|
|
14313
14388
|
const fail2 = (failure, what) => ({ failure, detail: `${what} \u2014 ${REMEDY[failure]}` });
|
|
14314
|
-
if (
|
|
14315
|
-
if (
|
|
14316
|
-
return fail2("binary-not-found", `could not start \`${bin}\` (${
|
|
14389
|
+
if (run4.spawnError) {
|
|
14390
|
+
if (run4.spawnError.code === "ENOENT") return fail2("binary-not-found", `\`${bin}\` is not on the scheduler PATH`);
|
|
14391
|
+
return fail2("binary-not-found", `could not start \`${bin}\` (${run4.spawnError.message})`);
|
|
14317
14392
|
}
|
|
14318
|
-
if (
|
|
14393
|
+
if (run4.timedOut) return fail2("timeout", "no answer within the time limit");
|
|
14319
14394
|
const text2 = `${seen.toolOutput}
|
|
14320
|
-
${
|
|
14321
|
-
if (REFUSED.test(seen.toolOutput) || seen.tools.some((t) => t.startsWith("mcp__")) && REFUSED.test(
|
|
14395
|
+
${run4.stderr}`;
|
|
14396
|
+
if (REFUSED.test(seen.toolOutput) || seen.tools.some((t) => t.startsWith("mcp__")) && REFUSED.test(run4.stderr)) {
|
|
14322
14397
|
return fail2("key-refused", "the tracker returned 401/403 to the MCP call");
|
|
14323
14398
|
}
|
|
14324
14399
|
if (seen.mcpFailed || !seen.tools.some((t) => t.startsWith("mcp__")) && MCP_GONE.test(`${text2}
|
|
@@ -14326,13 +14401,13 @@ ${seen.texts.join("\n")}`)) {
|
|
|
14326
14401
|
return fail2("mcp-unavailable", "the tracker MCP tool was not available to the session");
|
|
14327
14402
|
}
|
|
14328
14403
|
const answered = seen.texts.length > 0 || seen.finalText;
|
|
14329
|
-
if (SIGNED_OUT_PATTERN.test(`${
|
|
14404
|
+
if (SIGNED_OUT_PATTERN.test(`${run4.stderr}
|
|
14330
14405
|
${seen.finalText ?? ""}
|
|
14331
14406
|
${seen.texts.join("\n")}`)) {
|
|
14332
14407
|
return { failure: "login-missing", detail: signedOutMessage(spec.name, authModeOf(spec)) };
|
|
14333
14408
|
}
|
|
14334
|
-
if (!answered || LOGIN.test(
|
|
14335
|
-
return fail2("login-missing", `\`${bin}\` exited${
|
|
14409
|
+
if (!answered || LOGIN.test(run4.stderr) || LOGIN.test(seen.finalText ?? "")) {
|
|
14410
|
+
return fail2("login-missing", `\`${bin}\` exited${run4.code !== null ? ` (${run4.code})` : ""} before answering; the vendor login is probably missing`);
|
|
14336
14411
|
}
|
|
14337
14412
|
return fail2("wrong-answer", `the agent replied "${(seen.finalText ?? seen.texts.at(-1) ?? "").trim().slice(0, 80)}"`);
|
|
14338
14413
|
}
|
|
@@ -14360,9 +14435,9 @@ async function runSelftest(i, deps = realDeps) {
|
|
|
14360
14435
|
...adapter.runEnv(spec),
|
|
14361
14436
|
[KEY_VAR]: i.apiKey
|
|
14362
14437
|
};
|
|
14363
|
-
const cwd = mkdtempSync2(join33(
|
|
14438
|
+
const cwd = mkdtempSync2(join33(tmpdir5(), "crew-selftest-"));
|
|
14364
14439
|
try {
|
|
14365
|
-
const
|
|
14440
|
+
const run4 = await deps.run({
|
|
14366
14441
|
bin: invocation.bin,
|
|
14367
14442
|
args: invocation.args,
|
|
14368
14443
|
cwd,
|
|
@@ -14371,14 +14446,14 @@ async function runSelftest(i, deps = realDeps) {
|
|
|
14371
14446
|
`,
|
|
14372
14447
|
timeoutMs: i.timeoutMs ?? SELFTEST_TIMEOUT_MS
|
|
14373
14448
|
});
|
|
14374
|
-
const seen = observe(spec,
|
|
14449
|
+
const seen = observe(spec, run4.stdout);
|
|
14375
14450
|
const answer = [seen.finalText ?? "", ...seen.texts].join("\n");
|
|
14376
14451
|
const usage2 = { ...seen.tokens !== void 0 ? { tokens: seen.tokens } : {}, ...seen.costUsd !== void 0 ? { costUsd: seen.costUsd } : {} };
|
|
14377
|
-
if (!
|
|
14452
|
+
if (!run4.spawnError && !run4.timedOut && answer.toLowerCase().includes(i.workspaceName.toLowerCase())) {
|
|
14378
14453
|
const auth = spec.harness === "claude" ? ` on ${describeClaudeAuth(spec)}` : "";
|
|
14379
14454
|
return finish({ ok: true, workspace: i.workspaceName, detail: `read workspace "${i.workspaceName}"${auth}`, ...usage2 });
|
|
14380
14455
|
}
|
|
14381
|
-
const { failure, detail } = classify(spec,
|
|
14456
|
+
const { failure, detail } = classify(spec, run4, seen);
|
|
14382
14457
|
return finish({ ok: false, failure, detail, ...usage2 });
|
|
14383
14458
|
} finally {
|
|
14384
14459
|
try {
|
|
@@ -14397,7 +14472,7 @@ var fileFor2 = (stateDir) => join33(stateDir, "selftest.json");
|
|
|
14397
14472
|
function readSelftest(stateDir) {
|
|
14398
14473
|
try {
|
|
14399
14474
|
const p = fileFor2(stateDir);
|
|
14400
|
-
return
|
|
14475
|
+
return existsSync31(p) ? JSON.parse(readFileSync29(p, "utf8")) : {};
|
|
14401
14476
|
} catch {
|
|
14402
14477
|
return {};
|
|
14403
14478
|
}
|
|
@@ -14724,7 +14799,7 @@ async function signOutSessions(o) {
|
|
|
14724
14799
|
}
|
|
14725
14800
|
|
|
14726
14801
|
// src/reset.ts
|
|
14727
|
-
import { existsSync as
|
|
14802
|
+
import { existsSync as existsSync32, mkdirSync as mkdirSync22, readFileSync as readFileSync31, readdirSync as readdirSync12, rmSync as rmSync18, statSync as statSync11, writeFileSync as writeFileSync23 } from "fs";
|
|
14728
14803
|
import { dirname as dirname17, join as join35 } from "path";
|
|
14729
14804
|
import { hostFromUrl as hostFromUrl3 } from "@tablation/client";
|
|
14730
14805
|
function clonedCheckoutsFile(stateDir) {
|
|
@@ -14797,7 +14872,7 @@ async function runReset(o, fx) {
|
|
|
14797
14872
|
}
|
|
14798
14873
|
if (o.beforeState) steps.push(...await o.beforeState());
|
|
14799
14874
|
steps.push(...o.wipeState ? wipeStateDir(o.stateDir, o.dryRun) : removeState(o.stateDir, o.dryRun));
|
|
14800
|
-
if (
|
|
14875
|
+
if (existsSync32(o.configFile)) {
|
|
14801
14876
|
if (!o.dryRun) rmSync18(o.configFile, { force: true });
|
|
14802
14877
|
steps.push({ step: "config", target: o.configFile, action: mark(o.dryRun) });
|
|
14803
14878
|
} else {
|
|
@@ -14806,7 +14881,7 @@ async function runReset(o, fx) {
|
|
|
14806
14881
|
return steps;
|
|
14807
14882
|
}
|
|
14808
14883
|
function removeCheckout(dir, dryRun, fx) {
|
|
14809
|
-
if (!
|
|
14884
|
+
if (!existsSync32(dir)) return { step: "checkout", target: dir, action: "absent", detail: "already gone" };
|
|
14810
14885
|
const { dirty, linkedWorktrees } = fx.inspectCheckout(dir);
|
|
14811
14886
|
if (dirty.length) {
|
|
14812
14887
|
return { step: "checkout", target: dir, action: "kept", detail: `has uncommitted changes (${dirty.length} path${dirty.length === 1 ? "" : "s"}: ${dirty.slice(0, 5).join(", ")}${dirty.length > 5 ? ", \u2026" : ""})` };
|
|
@@ -14822,12 +14897,12 @@ function removeState(stateDir, dryRun) {
|
|
|
14822
14897
|
const targets = [join35(stateDir, "resolved"), join35(stateDir, "keys"), clonedCheckoutsFile(stateDir), join35(stateDir, "connect-session.json"), join35(stateDir, "reload-requested"), join35(stateDir, "daemon.started")];
|
|
14823
14898
|
try {
|
|
14824
14899
|
for (const name of readdirSync12(stateDir)) {
|
|
14825
|
-
if (name.startsWith(".") &&
|
|
14900
|
+
if (name.startsWith(".") && statSync11(join35(stateDir, name)).isFile()) targets.push(join35(stateDir, name));
|
|
14826
14901
|
}
|
|
14827
14902
|
} catch {
|
|
14828
14903
|
}
|
|
14829
14904
|
for (const t of targets) {
|
|
14830
|
-
if (!
|
|
14905
|
+
if (!existsSync32(t)) continue;
|
|
14831
14906
|
if (!dryRun) rmSync18(t, { recursive: true, force: true });
|
|
14832
14907
|
out.push({ step: "state", target: t, action: mark(dryRun) });
|
|
14833
14908
|
}
|
|
@@ -14866,21 +14941,21 @@ async function runDeprovision(o, fx, deps) {
|
|
|
14866
14941
|
};
|
|
14867
14942
|
const afterScheduler = async () => {
|
|
14868
14943
|
const steps2 = [];
|
|
14869
|
-
for (const
|
|
14870
|
-
const target = `${
|
|
14944
|
+
for (const run4 of deps.liveRuns()) {
|
|
14945
|
+
const target = `${run4.role} run on ${run4.route} (pid ${run4.pid})`;
|
|
14871
14946
|
if (o.dryRun) {
|
|
14872
14947
|
steps2.push({ step: "run", target, action: "would-remove" });
|
|
14873
14948
|
continue;
|
|
14874
14949
|
}
|
|
14875
14950
|
try {
|
|
14876
|
-
await deps.killRun(
|
|
14877
|
-
deps.recordKill(
|
|
14951
|
+
await deps.killRun(run4);
|
|
14952
|
+
deps.recordKill(run4);
|
|
14878
14953
|
} catch (e) {
|
|
14879
14954
|
steps2.push({ step: "run", target, action: "failed", detail: e.message });
|
|
14880
14955
|
continue;
|
|
14881
14956
|
}
|
|
14882
14957
|
try {
|
|
14883
|
-
await deps.handBack(
|
|
14958
|
+
await deps.handBack(run4);
|
|
14884
14959
|
steps2.push({ step: "run", target, action: "removed", detail: "killed" });
|
|
14885
14960
|
} catch (e) {
|
|
14886
14961
|
steps2.push({ step: "run", target, action: "removed", detail: `killed; could not tell its ticket (${e.message})` });
|
|
@@ -15223,13 +15298,13 @@ function hostArchitecture(arch = process.arch) {
|
|
|
15223
15298
|
|
|
15224
15299
|
// src/pool-member-host.ts
|
|
15225
15300
|
import "child_process";
|
|
15226
|
-
import { existsSync as
|
|
15301
|
+
import { existsSync as existsSync36 } from "fs";
|
|
15227
15302
|
import { hostname as hostname3 } from "os";
|
|
15228
15303
|
|
|
15229
15304
|
// src/machine-id.ts
|
|
15230
15305
|
import { execFileSync as execFileSync11 } from "child_process";
|
|
15231
15306
|
import { createHash as createHash8 } from "crypto";
|
|
15232
|
-
import { existsSync as
|
|
15307
|
+
import { existsSync as existsSync33, mkdirSync as mkdirSync24, readFileSync as readFileSync33, writeFileSync as writeFileSync25 } from "fs";
|
|
15233
15308
|
import { dirname as dirname19, join as join37 } from "path";
|
|
15234
15309
|
function machineIdPathFor(stateDir) {
|
|
15235
15310
|
return join37(stateDir, "machine-id");
|
|
@@ -15245,7 +15320,7 @@ function readRawMachineId(platform2 = process.platform) {
|
|
|
15245
15320
|
return /"IOPlatformUUID"\s*=\s*"([^"]+)"/.exec(out)?.[1];
|
|
15246
15321
|
}
|
|
15247
15322
|
for (const p of ["/etc/machine-id", "/var/lib/dbus/machine-id"]) {
|
|
15248
|
-
if (
|
|
15323
|
+
if (existsSync33(p)) {
|
|
15249
15324
|
const id = readFileSync33(p, "utf8").trim();
|
|
15250
15325
|
if (id) return id;
|
|
15251
15326
|
}
|
|
@@ -15257,7 +15332,7 @@ function readRawMachineId(platform2 = process.platform) {
|
|
|
15257
15332
|
function ensureMachineId(stateDir, opts = {}) {
|
|
15258
15333
|
if (opts.override?.trim()) return sha256(opts.override.trim());
|
|
15259
15334
|
const path = machineIdPathFor(stateDir);
|
|
15260
|
-
if (
|
|
15335
|
+
if (existsSync33(path)) {
|
|
15261
15336
|
const cached = readFileSync33(path, "utf8").trim();
|
|
15262
15337
|
if (/^[0-9a-f]{64}$/.test(cached)) return cached;
|
|
15263
15338
|
}
|
|
@@ -15278,7 +15353,7 @@ function matchShipRows(ships, shipName2, machineId) {
|
|
|
15278
15353
|
|
|
15279
15354
|
// src/provision.ts
|
|
15280
15355
|
import { spawnSync as spawnSync9 } from "child_process";
|
|
15281
|
-
import { existsSync as
|
|
15356
|
+
import { existsSync as existsSync34, readFileSync as readFileSync34, writeFileSync as writeFileSync26 } from "fs";
|
|
15282
15357
|
import { hostname as hostname2 } from "os";
|
|
15283
15358
|
import { parseDocument as parseDocument3, isMap as isMap2, isScalar } from "yaml";
|
|
15284
15359
|
|
|
@@ -15896,7 +15971,7 @@ function realProvisionDeps(crewHome) {
|
|
|
15896
15971
|
};
|
|
15897
15972
|
const configFile = () => {
|
|
15898
15973
|
const f = findConfigFile(crewHome);
|
|
15899
|
-
return
|
|
15974
|
+
return existsSync34(f) ? f : null;
|
|
15900
15975
|
};
|
|
15901
15976
|
return {
|
|
15902
15977
|
crew: spawnCrew,
|
|
@@ -15930,14 +16005,14 @@ function realProvisionDeps(crewHome) {
|
|
|
15930
16005
|
continue;
|
|
15931
16006
|
}
|
|
15932
16007
|
for (const p of plan.unitPaths) {
|
|
15933
|
-
if (!
|
|
16008
|
+
if (!existsSync34(p) || readFileSync34(p, "utf8") !== plan.unitContent[p]) unitsStale = true;
|
|
15934
16009
|
}
|
|
15935
16010
|
}
|
|
15936
16011
|
const label = labelFor(crewHome, "run");
|
|
15937
16012
|
let running = false;
|
|
15938
16013
|
let lingering = true;
|
|
15939
16014
|
if (mechanism === "systemd") {
|
|
15940
|
-
const system = ctx.root ||
|
|
16015
|
+
const system = ctx.root || existsSync34(systemUnitPathFor(label));
|
|
15941
16016
|
const ctl = system ? ["systemctl"] : ["systemctl", "--user"];
|
|
15942
16017
|
running = spawnSync9(ctl[0], [...ctl.slice(1), "is-active", "--quiet", `${label}.service`], { env: withUserBusEnv() }).status === 0;
|
|
15943
16018
|
if (!system) {
|
|
@@ -15993,7 +16068,7 @@ host=${host}
|
|
|
15993
16068
|
|
|
15994
16069
|
// src/tunnel.ts
|
|
15995
16070
|
import { spawn as spawn7 } from "child_process";
|
|
15996
|
-
import { existsSync as
|
|
16071
|
+
import { existsSync as existsSync35, mkdirSync as mkdirSync25, readFileSync as readFileSync35, writeFileSync as writeFileSync27, unlinkSync as unlinkSync3, readdirSync as readdirSync13 } from "fs";
|
|
15997
16072
|
import { randomInt } from "crypto";
|
|
15998
16073
|
import { join as join39 } from "path";
|
|
15999
16074
|
var DEFAULT_SPAWN_OPTIONS = { stdio: "ignore", detached: true };
|
|
@@ -16077,7 +16152,7 @@ function tunnelStatePath(stateDir, workspaceId) {
|
|
|
16077
16152
|
}
|
|
16078
16153
|
function readPersistedTunnel(stateDir, workspaceId) {
|
|
16079
16154
|
const path = tunnelStatePath(stateDir, workspaceId);
|
|
16080
|
-
if (!
|
|
16155
|
+
if (!existsSync35(path)) return void 0;
|
|
16081
16156
|
try {
|
|
16082
16157
|
return JSON.parse(readFileSync35(path, "utf8"));
|
|
16083
16158
|
} catch {
|
|
@@ -16217,7 +16292,7 @@ function syncPassengerTunnels(plans, relayHost, relayPort, privateKeyPath, state
|
|
|
16217
16292
|
}
|
|
16218
16293
|
function readAllPersistedWorkspaceIds(stateDir) {
|
|
16219
16294
|
const dir = join39(stateDir, "passengers");
|
|
16220
|
-
if (!
|
|
16295
|
+
if (!existsSync35(dir)) return [];
|
|
16221
16296
|
return readdirSync13(dir).filter((f) => f.endsWith(".json") && !f.endsWith("-sync.json")).map((f) => f.slice(0, -".json".length));
|
|
16222
16297
|
}
|
|
16223
16298
|
var TUNNEL_REJECTED_KEY = "tunnel_rejected";
|
|
@@ -16257,7 +16332,7 @@ function realPoolMemberDeps(o) {
|
|
|
16257
16332
|
crewVersion: crewVersion(o.crewHome),
|
|
16258
16333
|
hostname: hostname3()
|
|
16259
16334
|
},
|
|
16260
|
-
hasShipConfig: () =>
|
|
16335
|
+
hasShipConfig: () => existsSync36(findConfigFile(o.crewHome)),
|
|
16261
16336
|
async provision(lease, instanceClass, shipKind) {
|
|
16262
16337
|
const hosts = lease.forges.map((f) => f.host.toLowerCase());
|
|
16263
16338
|
const lines2 = [];
|
|
@@ -17133,6 +17208,191 @@ ${waiting.map((t) => `| ${displayKey2(t)} | ${t.status} | ${blockers(t, i)} |`).
|
|
|
17133
17208
|
]);
|
|
17134
17209
|
}
|
|
17135
17210
|
|
|
17211
|
+
// src/sandbox-hygiene.ts
|
|
17212
|
+
import { execFile as execFile3 } from "child_process";
|
|
17213
|
+
import { existsSync as existsSync37, statfsSync as statfsSync2 } from "fs";
|
|
17214
|
+
import { promisify as promisify3 } from "util";
|
|
17215
|
+
var execFileP3 = promisify3(execFile3);
|
|
17216
|
+
var REAP_MIN_AGE_MS = 5 * 6e4;
|
|
17217
|
+
var LEAK_CLEAR_AFTER_MS = 60 * 6e4;
|
|
17218
|
+
var DISK_WARN_PERCENT = 85;
|
|
17219
|
+
var DISK_STOP_PERCENT = 95;
|
|
17220
|
+
var DISK_RESUME_PERCENT = 90;
|
|
17221
|
+
var HYGIENE_INTERVAL_MS = 3e4;
|
|
17222
|
+
var SANDBOX_LEAK_KEY = "sandbox_leak";
|
|
17223
|
+
var DISK_PRESSURE_KEY = "disk_pressure";
|
|
17224
|
+
var DISK_FULL_KEY = "disk_full";
|
|
17225
|
+
var SANDBOX_IN_CONTAINER = /crew-[0-9a-z]{14}/;
|
|
17226
|
+
function parseDockerCreatedAt(s) {
|
|
17227
|
+
const m = /^(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2})(?:\.\d+)? ([+-])(\d{2})(\d{2})/.exec(s.trim());
|
|
17228
|
+
if (!m) return null;
|
|
17229
|
+
const t = Date.parse(`${m[1]}T${m[2]}${m[3]}${m[4]}:${m[5]}`);
|
|
17230
|
+
return Number.isNaN(t) ? null : t;
|
|
17231
|
+
}
|
|
17232
|
+
async function reapOrphanContainers(d, minAgeMs = REAP_MIN_AGE_MS) {
|
|
17233
|
+
const gateway = await d.gatewaySandboxes();
|
|
17234
|
+
if (gateway === null) return [];
|
|
17235
|
+
const known = /* @__PURE__ */ new Set([...gateway, ...d.liveSandboxes()]);
|
|
17236
|
+
const prefix = `openshell-${d.workspace}--`;
|
|
17237
|
+
const out = [];
|
|
17238
|
+
for (const c of await d.containers()) {
|
|
17239
|
+
if (!c.name.startsWith(prefix)) continue;
|
|
17240
|
+
const sandbox = SANDBOX_IN_CONTAINER.exec(c.name)?.[0];
|
|
17241
|
+
if (!sandbox || known.has(sandbox)) continue;
|
|
17242
|
+
const ageMs = d.now() - c.createdMs;
|
|
17243
|
+
if (ageMs < minAgeMs) continue;
|
|
17244
|
+
await d.remove(c.name);
|
|
17245
|
+
out.push({ container: c.name, ageMs });
|
|
17246
|
+
}
|
|
17247
|
+
return out;
|
|
17248
|
+
}
|
|
17249
|
+
function usedPercentAt(path) {
|
|
17250
|
+
try {
|
|
17251
|
+
const s = statfsSync2(path);
|
|
17252
|
+
const used = Number(s.blocks) - Number(s.bfree);
|
|
17253
|
+
const total = used + Number(s.bavail);
|
|
17254
|
+
return total > 0 ? used / total * 100 : null;
|
|
17255
|
+
} catch {
|
|
17256
|
+
return null;
|
|
17257
|
+
}
|
|
17258
|
+
}
|
|
17259
|
+
function fullest(readings) {
|
|
17260
|
+
return readings.reduce((a, r) => !a || r.percent > a.percent ? r : a, null);
|
|
17261
|
+
}
|
|
17262
|
+
function diskVerdict(percent, stopped) {
|
|
17263
|
+
if (percent >= DISK_STOP_PERCENT || stopped && percent >= DISK_RESUME_PERCENT) return "stop";
|
|
17264
|
+
return percent >= DISK_WARN_PERCENT ? "warn" : "ok";
|
|
17265
|
+
}
|
|
17266
|
+
async function checkDisk(o, d, nowIso = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
17267
|
+
const raise = (item) => raiseShipAttention({ state: o.state, emit: o.emit, ship: o.ship, ...o.route ? { route: o.route } : {} }, item);
|
|
17268
|
+
const stopped = openShipAttention(o.state).some((i) => i.key === DISK_FULL_KEY);
|
|
17269
|
+
let worst = fullest(await d.readings());
|
|
17270
|
+
if (!worst) return;
|
|
17271
|
+
let verdict = diskVerdict(worst.percent, stopped);
|
|
17272
|
+
if (verdict === "stop" && !stopped) {
|
|
17273
|
+
await d.reclaim();
|
|
17274
|
+
worst = fullest(await d.readings()) ?? worst;
|
|
17275
|
+
verdict = diskVerdict(worst.percent, false);
|
|
17276
|
+
}
|
|
17277
|
+
const pct = `${Math.round(worst.percent)}%`;
|
|
17278
|
+
if (verdict === "stop") {
|
|
17279
|
+
clearShipAttention(o.state, DISK_PRESSURE_KEY);
|
|
17280
|
+
await raise({
|
|
17281
|
+
kind: "disk_full",
|
|
17282
|
+
key: DISK_FULL_KEY,
|
|
17283
|
+
since: nowIso,
|
|
17284
|
+
message: `${worst.path} is ${pct} full \u2014 no agent run or sandbox image build starts until it is below ${DISK_RESUME_PERCENT}%. Resumes automatically once space is freed`
|
|
17285
|
+
});
|
|
17286
|
+
} else if (verdict === "warn") {
|
|
17287
|
+
clearShipAttention(o.state, DISK_FULL_KEY);
|
|
17288
|
+
await raise({
|
|
17289
|
+
kind: "disk_pressure",
|
|
17290
|
+
key: DISK_PRESSURE_KEY,
|
|
17291
|
+
since: nowIso,
|
|
17292
|
+
message: `${worst.path} is ${pct} full \u2014 runs stop at ${DISK_STOP_PERCENT}%. Resumes normal reporting once it is below ${DISK_WARN_PERCENT}%`
|
|
17293
|
+
});
|
|
17294
|
+
} else {
|
|
17295
|
+
clearShipAttention(o.state, DISK_FULL_KEY);
|
|
17296
|
+
clearShipAttention(o.state, DISK_PRESSURE_KEY);
|
|
17297
|
+
}
|
|
17298
|
+
}
|
|
17299
|
+
async function reportReaped(o, reaped, nowMs = Date.now()) {
|
|
17300
|
+
const prior = openShipAttention(o.state).find((i) => i.key === SANDBOX_LEAK_KEY);
|
|
17301
|
+
if (reaped.length === 0) {
|
|
17302
|
+
if (prior?.lastReapedAt && nowMs - Date.parse(prior.lastReapedAt) > LEAK_CLEAR_AFTER_MS) clearShipAttention(o.state, SANDBOX_LEAK_KEY);
|
|
17303
|
+
return;
|
|
17304
|
+
}
|
|
17305
|
+
for (const r of reaped) {
|
|
17306
|
+
o.emit.warn(`sandbox_reaped: removed ${r.container} (${Math.round(r.ageMs / 6e4)} min old, no live run)`, {
|
|
17307
|
+
data: { event: "sandbox_reaped", container: r.container, ageMs: r.ageMs }
|
|
17308
|
+
});
|
|
17309
|
+
}
|
|
17310
|
+
const total = (prior?.count ?? 0) + reaped.length;
|
|
17311
|
+
await raiseShipAttention(o, {
|
|
17312
|
+
kind: "sandbox_leak",
|
|
17313
|
+
key: SANDBOX_LEAK_KEY,
|
|
17314
|
+
since: new Date(nowMs).toISOString(),
|
|
17315
|
+
count: total,
|
|
17316
|
+
lastReapedAt: new Date(nowMs).toISOString(),
|
|
17317
|
+
message: `${total} sandbox container(s) with no live run have been removed from this ship (latest: ${reaped.length} just now) \u2014 something created them outside a run; see the sandbox_reaped events`
|
|
17318
|
+
});
|
|
17319
|
+
}
|
|
17320
|
+
async function run3(bin, args) {
|
|
17321
|
+
return (await execFileP3(bin, args, { timeout: 6e4, maxBuffer: 16 * 1024 * 1024 })).stdout;
|
|
17322
|
+
}
|
|
17323
|
+
function realReapDeps(ship) {
|
|
17324
|
+
const engine = ship.sandbox?.engine ?? DEFAULT_CACHE_SETTINGS.engine;
|
|
17325
|
+
const osBin = ship.sandbox?.bin ?? "openshell";
|
|
17326
|
+
return {
|
|
17327
|
+
workspace: ship.sandbox?.cacheWorkspace ?? DEFAULT_CACHE_SETTINGS.workspace,
|
|
17328
|
+
containers: async () => {
|
|
17329
|
+
const out = await run3(engine, ["ps", "-a", "--no-trunc", "--format", "{{.Names}} {{.CreatedAt}}"]);
|
|
17330
|
+
const rows = [];
|
|
17331
|
+
for (const line of out.split("\n")) {
|
|
17332
|
+
const [name, created] = line.split(" ");
|
|
17333
|
+
const createdMs = created ? parseDockerCreatedAt(created) : null;
|
|
17334
|
+
if (name && createdMs !== null) rows.push({ name, createdMs });
|
|
17335
|
+
}
|
|
17336
|
+
return rows;
|
|
17337
|
+
},
|
|
17338
|
+
gatewaySandboxes: async () => {
|
|
17339
|
+
try {
|
|
17340
|
+
return [...(await run3(osBin, ["sandbox", "list"])).matchAll(/crew-[0-9a-z]{14}/g)].map((m) => m[0]);
|
|
17341
|
+
} catch {
|
|
17342
|
+
return null;
|
|
17343
|
+
}
|
|
17344
|
+
},
|
|
17345
|
+
liveSandboxes: () => liveRuns(ship.stateDir).flatMap((r) => r.sandbox ? [r.sandbox] : []),
|
|
17346
|
+
remove: async (name) => {
|
|
17347
|
+
await run3(engine, ["rm", "-f", name]);
|
|
17348
|
+
},
|
|
17349
|
+
now: () => Date.now()
|
|
17350
|
+
};
|
|
17351
|
+
}
|
|
17352
|
+
async function realDiskReadings(ship) {
|
|
17353
|
+
const paths = ["/"];
|
|
17354
|
+
try {
|
|
17355
|
+
const root = (await run3(ship.sandbox?.engine ?? DEFAULT_CACHE_SETTINGS.engine, ["info", "--format", "{{.DockerRootDir}}"])).trim();
|
|
17356
|
+
if (root && existsSync37(root)) paths.push(root);
|
|
17357
|
+
} catch {
|
|
17358
|
+
}
|
|
17359
|
+
return paths.flatMap((path) => {
|
|
17360
|
+
const percent = usedPercentAt(path);
|
|
17361
|
+
return percent === null ? [] : [{ path, percent }];
|
|
17362
|
+
});
|
|
17363
|
+
}
|
|
17364
|
+
function makeSandboxHygiene(o) {
|
|
17365
|
+
const now = o.now ?? Date.now;
|
|
17366
|
+
let last = -Infinity;
|
|
17367
|
+
return async () => {
|
|
17368
|
+
if (now() - last < HYGIENE_INTERVAL_MS) return;
|
|
17369
|
+
last = now();
|
|
17370
|
+
const deps = realReapDeps(o.ship);
|
|
17371
|
+
try {
|
|
17372
|
+
await reportReaped(o, await reapOrphanContainers(deps), now());
|
|
17373
|
+
} catch (e) {
|
|
17374
|
+
o.emit.warn(`sandbox reaper failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
17375
|
+
}
|
|
17376
|
+
try {
|
|
17377
|
+
await checkDisk(o, {
|
|
17378
|
+
readings: () => realDiskReadings(o.ship),
|
|
17379
|
+
reclaim: async () => {
|
|
17380
|
+
await reportReaped(o, await reapOrphanContainers(deps), now());
|
|
17381
|
+
try {
|
|
17382
|
+
await run3(o.ship.sandbox?.engine ?? DEFAULT_CACHE_SETTINGS.engine, ["builder", "prune", "-f"]);
|
|
17383
|
+
} catch {
|
|
17384
|
+
}
|
|
17385
|
+
}
|
|
17386
|
+
});
|
|
17387
|
+
} catch (e) {
|
|
17388
|
+
o.emit.warn(`disk check failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
17389
|
+
}
|
|
17390
|
+
};
|
|
17391
|
+
}
|
|
17392
|
+
function diskFullStop(state) {
|
|
17393
|
+
return openShipAttention(state).find((i) => i.kind === "disk_full")?.message ?? null;
|
|
17394
|
+
}
|
|
17395
|
+
|
|
17136
17396
|
// src/poll.ts
|
|
17137
17397
|
import { writeFileSync as writeFileSync28 } from "fs";
|
|
17138
17398
|
import { join as join40 } from "path";
|
|
@@ -17388,8 +17648,9 @@ async function decideCycle(o) {
|
|
|
17388
17648
|
await checkRepoDisks({ state, emit, route: route2, ship });
|
|
17389
17649
|
const floorStop = await checkCrewFloor({ state, emit, route: route2, ship });
|
|
17390
17650
|
const itemStop = repoStopFor(openShipAttention(state), route2);
|
|
17651
|
+
const diskStop = diskFullStop(state);
|
|
17391
17652
|
const selectionInput = {
|
|
17392
|
-
repoStop: floorStop ? () => floorStop : itemStop,
|
|
17653
|
+
repoStop: floorStop ? () => floorStop : diskStop ? () => diskStop : itemStop,
|
|
17393
17654
|
workModes,
|
|
17394
17655
|
tickets,
|
|
17395
17656
|
comments,
|
|
@@ -17634,7 +17895,7 @@ async function resolveOne(tracker, t, seat, approvedStatus, buildingStatus, affi
|
|
|
17634
17895
|
}
|
|
17635
17896
|
|
|
17636
17897
|
// src/repo-refresh.ts
|
|
17637
|
-
import { existsSync as
|
|
17898
|
+
import { existsSync as existsSync38, mkdirSync as mkdirSync26, readFileSync as readFileSync36, writeFileSync as writeFileSync29 } from "fs";
|
|
17638
17899
|
import { dirname as dirname21 } from "path";
|
|
17639
17900
|
var REFRESH_COOLDOWN_MS = 2 * 6e4;
|
|
17640
17901
|
var UNSERVABLE_PASSES_BEFORE_ATTENTION = 3;
|
|
@@ -17664,7 +17925,7 @@ function applyRepoRows(resolved, rows) {
|
|
|
17664
17925
|
}
|
|
17665
17926
|
function persistRepoRows(stateDir, routeName, rows) {
|
|
17666
17927
|
const path = resolvedPathFor(stateDir, routeName);
|
|
17667
|
-
if (!
|
|
17928
|
+
if (!existsSync38(path)) return;
|
|
17668
17929
|
const raw = JSON.parse(readFileSync36(path, "utf8"));
|
|
17669
17930
|
applyRepoRows(raw, rows);
|
|
17670
17931
|
mkdirSync26(dirname21(path), { recursive: true });
|
|
@@ -18119,12 +18380,12 @@ var localRefSkipReported = (ticket, problem, events) => events.some((e) => e.rec
|
|
|
18119
18380
|
|
|
18120
18381
|
// src/connect-wizard.ts
|
|
18121
18382
|
import { delimiter, dirname as dirname22, join as join41 } from "path";
|
|
18122
|
-
import { accessSync as accessSync3, constants as constants3, existsSync as
|
|
18383
|
+
import { accessSync as accessSync3, constants as constants3, existsSync as existsSync39, mkdirSync as mkdirSync27, writeFileSync as writeFileSync30 } from "fs";
|
|
18123
18384
|
import { stringify as stringify3 } from "yaml";
|
|
18124
18385
|
var HOST_PASSENGERS_DOCS_URL = "https://crew.tablation.dev/host-passengers";
|
|
18125
18386
|
function shouldRunWizard(opts) {
|
|
18126
18387
|
if (!opts.isTTY) return false;
|
|
18127
|
-
const exists = opts.configExists ??
|
|
18388
|
+
const exists = opts.configExists ?? existsSync39;
|
|
18128
18389
|
return !configSearchPath(opts.crewHome).some((p) => exists(p));
|
|
18129
18390
|
}
|
|
18130
18391
|
function firstRunConfigPath() {
|
|
@@ -18318,7 +18579,7 @@ function flagWizardAnswers(f, env) {
|
|
|
18318
18579
|
}
|
|
18319
18580
|
|
|
18320
18581
|
// src/diagnostics.ts
|
|
18321
|
-
import { execFile as
|
|
18582
|
+
import { execFile as execFile4 } from "child_process";
|
|
18322
18583
|
var BUNDLE_BUDGET_MS = 3e4;
|
|
18323
18584
|
var JOURNAL_LINES = 200;
|
|
18324
18585
|
var MAX_SECTION_BYTES = 256 * 1024;
|
|
@@ -18343,7 +18604,7 @@ function redactValue(v) {
|
|
|
18343
18604
|
return v;
|
|
18344
18605
|
}
|
|
18345
18606
|
var defaultExec = (bin, args, timeoutMs) => new Promise((resolve8, reject) => {
|
|
18346
|
-
|
|
18607
|
+
execFile4(bin, args, { timeout: timeoutMs, maxBuffer: 4 * 1024 * 1024 }, (e, stdout) => {
|
|
18347
18608
|
if (e && e.code === "ENOENT") return reject(new Error(`${bin} is not installed`));
|
|
18348
18609
|
if (e && e.killed) return reject(new Error(`${bin} timed out`));
|
|
18349
18610
|
resolve8({ stdout: String(stdout), code: typeof e?.code === "number" ? e.code : 0 });
|
|
@@ -18390,9 +18651,9 @@ async function collectDiagnostics(d) {
|
|
|
18390
18651
|
const deadline = new Promise((resolve8) => {
|
|
18391
18652
|
setTimeout(() => resolve8("timeout"), budget).unref();
|
|
18392
18653
|
});
|
|
18393
|
-
const entries = await Promise.all(Object.entries(sections).map(async ([name,
|
|
18654
|
+
const entries = await Promise.all(Object.entries(sections).map(async ([name, run4]) => {
|
|
18394
18655
|
try {
|
|
18395
|
-
const out = await Promise.race([
|
|
18656
|
+
const out = await Promise.race([run4(), deadline]);
|
|
18396
18657
|
if (out === "timeout") return [name, { ok: false, error: `timed out after ${Math.round(budget / 1e3)}s` }];
|
|
18397
18658
|
return [name, { ok: true, data: redactValue(out) }];
|
|
18398
18659
|
} catch (e) {
|
|
@@ -18403,9 +18664,9 @@ async function collectDiagnostics(d) {
|
|
|
18403
18664
|
}
|
|
18404
18665
|
|
|
18405
18666
|
// src/release-run.ts
|
|
18406
|
-
import { readFileSync as readFileSync37, writeFileSync as writeFileSync31, existsSync as
|
|
18667
|
+
import { readFileSync as readFileSync37, writeFileSync as writeFileSync31, existsSync as existsSync40, copyFileSync, mkdirSync as mkdirSync28, mkdtempSync as mkdtempSync3, rmSync as rmSync19 } from "fs";
|
|
18407
18668
|
import { dirname as dirname24, join as join43 } from "path";
|
|
18408
|
-
import { tmpdir as
|
|
18669
|
+
import { tmpdir as tmpdir6, hostname as hostname4 } from "os";
|
|
18409
18670
|
|
|
18410
18671
|
// src/release.ts
|
|
18411
18672
|
function describeUnplaceable(unplaceable, verifiedStatus) {
|
|
@@ -19188,7 +19449,7 @@ async function bump(o, size) {
|
|
|
19188
19449
|
}
|
|
19189
19450
|
const files = o.repo.release.versionFiles.map((f) => join43(o.cwd, f));
|
|
19190
19451
|
const first = files[0];
|
|
19191
|
-
if (!existsAt(first,
|
|
19452
|
+
if (!existsAt(first, existsSync40)) {
|
|
19192
19453
|
o.emit.error(`no ${o.repo.release.versionFiles[0]} to read a version from`);
|
|
19193
19454
|
return null;
|
|
19194
19455
|
}
|
|
@@ -19230,7 +19491,7 @@ function writeChangelog(o, version, entries) {
|
|
|
19230
19491
|
o.emit.emit(`would prepend ${entries.length} entr(ies) to ${file}`);
|
|
19231
19492
|
return;
|
|
19232
19493
|
}
|
|
19233
|
-
const existing = existsAt(path,
|
|
19494
|
+
const existing = existsAt(path, existsSync40) ? readTextAt(path, (p) => readFileSync37(p, "utf8")) : "# Changelog\n";
|
|
19234
19495
|
writeTextAt(path, insertChangelogSection(existing, section), writeFileSync31);
|
|
19235
19496
|
}
|
|
19236
19497
|
async function confirm(o, expected) {
|
|
@@ -19309,22 +19570,22 @@ async function confirmLastRelease(o, decision) {
|
|
|
19309
19570
|
if (!confirmed) o.emit.warn(`${decision.lastTag} is still not confirmed live \u2014 tickets stay verified`);
|
|
19310
19571
|
return { confirmed, version };
|
|
19311
19572
|
}
|
|
19312
|
-
function closeReleaseCheckout(cwd, root, dir, branch,
|
|
19573
|
+
function closeReleaseCheckout(cwd, root, dir, branch, run4 = gitOk) {
|
|
19313
19574
|
try {
|
|
19314
|
-
|
|
19575
|
+
run4(cwd, ["worktree", "remove", "--force", dir]);
|
|
19315
19576
|
} finally {
|
|
19316
19577
|
try {
|
|
19317
19578
|
rmSync19(root, { recursive: true, force: true });
|
|
19318
19579
|
} finally {
|
|
19319
|
-
|
|
19320
|
-
|
|
19580
|
+
run4(cwd, ["worktree", "prune"]);
|
|
19581
|
+
run4(cwd, ["branch", "-D", branch]);
|
|
19321
19582
|
}
|
|
19322
19583
|
}
|
|
19323
19584
|
}
|
|
19324
19585
|
function openReleaseCheckout(o) {
|
|
19325
19586
|
const { remote, base } = o.repo.branch;
|
|
19326
19587
|
const branch = `crew/release-${Date.now()}`;
|
|
19327
|
-
const root = mkdtempSync3(join43(
|
|
19588
|
+
const root = mkdtempSync3(join43(tmpdir6(), "crew-release-"));
|
|
19328
19589
|
const dir = join43(root, "checkout");
|
|
19329
19590
|
o.emit.emit(`release checkout: ${dir}`, { step: "release" });
|
|
19330
19591
|
const close = () => closeReleaseCheckout(o.cwd, root, dir, branch);
|
|
@@ -19336,7 +19597,7 @@ function openReleaseCheckout(o) {
|
|
|
19336
19597
|
}
|
|
19337
19598
|
for (const f of o.repo.worktrees.copy) {
|
|
19338
19599
|
const src = join43(o.cwd, f);
|
|
19339
|
-
if (!
|
|
19600
|
+
if (!existsSync40(src)) continue;
|
|
19340
19601
|
mkdirSync28(dirname24(join43(dir, f)), { recursive: true });
|
|
19341
19602
|
copyFileSync(src, join43(dir, f));
|
|
19342
19603
|
}
|
|
@@ -19489,7 +19750,7 @@ async function runReleaseCycle(o, movedPast2, localRefSkips) {
|
|
|
19489
19750
|
let checkout;
|
|
19490
19751
|
const stranded = recoverStrandedReleaseCheckouts(o.cwd);
|
|
19491
19752
|
if (stranded.length > 0) o.emit.warn(scoped(`dropped release checkout(s) stranded by a crash: ${stranded.join(", ")}`));
|
|
19492
|
-
const swept = sweepStaleReleaseRoots(
|
|
19753
|
+
const swept = sweepStaleReleaseRoots(tmpdir6());
|
|
19493
19754
|
if (swept.length > 0) o.emit.emit(scoped(`removed ${swept.length} stale crew-release-* temp dir(s)`), { step: "release" });
|
|
19494
19755
|
try {
|
|
19495
19756
|
checkout = openReleaseCheckout(o);
|
|
@@ -20173,7 +20434,7 @@ function runForge(a, io) {
|
|
|
20173
20434
|
}
|
|
20174
20435
|
|
|
20175
20436
|
// src/mirror-contract.ts
|
|
20176
|
-
import { existsSync as
|
|
20437
|
+
import { existsSync as existsSync41 } from "fs";
|
|
20177
20438
|
|
|
20178
20439
|
// src/passenger-mirror.ts
|
|
20179
20440
|
import { mkdirSync as mkdirSync29 } from "fs";
|
|
@@ -20214,7 +20475,7 @@ function mirrorOutcome(m) {
|
|
|
20214
20475
|
|
|
20215
20476
|
// src/mirror-contract.ts
|
|
20216
20477
|
function lacksCheckout(ship, dir) {
|
|
20217
|
-
return ship.runner === "sandbox" && !
|
|
20478
|
+
return ship.runner === "sandbox" && !existsSync41(dir) && !remoteOf(dir);
|
|
20218
20479
|
}
|
|
20219
20480
|
function skipsHostCheckout(ship) {
|
|
20220
20481
|
return ship.runner === "sandbox";
|
|
@@ -20294,11 +20555,11 @@ function explainRefusal(readable, unreadable) {
|
|
|
20294
20555
|
}
|
|
20295
20556
|
|
|
20296
20557
|
// src/release-sandbox.ts
|
|
20297
|
-
import { execFile as
|
|
20558
|
+
import { execFile as execFile5 } from "child_process";
|
|
20298
20559
|
import { mkdirSync as mkdirSync30, writeFileSync as writeFileSync32 } from "fs";
|
|
20299
20560
|
import { dirname as dirname26 } from "path";
|
|
20300
|
-
import { promisify as
|
|
20301
|
-
var
|
|
20561
|
+
import { promisify as promisify4 } from "util";
|
|
20562
|
+
var execFileP4 = promisify4(execFile5);
|
|
20302
20563
|
var RELEASE_CLONE_DEPTH = 50;
|
|
20303
20564
|
var FORGE_TOKEN_VAR = "CREW_FORGE_TOKEN";
|
|
20304
20565
|
var FORGE_USER_VAR = "CREW_FORGE_USER";
|
|
@@ -20335,7 +20596,7 @@ function releaseCloneScript(o) {
|
|
|
20335
20596
|
var endpointsOf = (g) => g.groups.flatMap((x) => x.endpoints.map((e) => `${e.host}:${e.port}`));
|
|
20336
20597
|
async function openReleaseSandbox(o) {
|
|
20337
20598
|
const cfg = { ...DEFAULT_SANDBOX_CONFIG, ...o.sandbox };
|
|
20338
|
-
const
|
|
20599
|
+
const run4 = o.exec ?? ((bin, args, env) => execFileP4(bin, args, { env, maxBuffer: 16 * 1024 * 1024 }));
|
|
20339
20600
|
const name = sandboxName({ route: o.route, role: "release", ticket: o.repoName }, o.now?.());
|
|
20340
20601
|
let policyFile = cfg.policy;
|
|
20341
20602
|
let generated;
|
|
@@ -20354,6 +20615,7 @@ async function openReleaseSandbox(o) {
|
|
|
20354
20615
|
}
|
|
20355
20616
|
const create2 = ["sandbox", "create", "--name", name, "--detach"];
|
|
20356
20617
|
if (policyFile) create2.push("--policy", policyFile);
|
|
20618
|
+
for (const l of sandboxLabels({ role: "release", run: name })) create2.push("--label", l);
|
|
20357
20619
|
const image = cfg.image ?? o.image;
|
|
20358
20620
|
if (image) create2.push("--from", image);
|
|
20359
20621
|
if (cfg.cacheVolume) {
|
|
@@ -20366,12 +20628,12 @@ async function openReleaseSandbox(o) {
|
|
|
20366
20628
|
const t0 = Date.now();
|
|
20367
20629
|
const deleteQuietly = async () => {
|
|
20368
20630
|
try {
|
|
20369
|
-
await
|
|
20631
|
+
await run4(cfg.bin, ["sandbox", "delete", name], process.env);
|
|
20370
20632
|
} catch {
|
|
20371
20633
|
}
|
|
20372
20634
|
};
|
|
20373
20635
|
try {
|
|
20374
|
-
await
|
|
20636
|
+
await run4(cfg.bin, create2, secrets);
|
|
20375
20637
|
} catch (e) {
|
|
20376
20638
|
await deleteQuietly();
|
|
20377
20639
|
throw new Error(`openshell could not create the release sandbox: ${describe(e)}`);
|
|
@@ -20385,7 +20647,7 @@ async function openReleaseSandbox(o) {
|
|
|
20385
20647
|
}
|
|
20386
20648
|
const closeSandbox = async () => {
|
|
20387
20649
|
try {
|
|
20388
|
-
const { stdout } = await
|
|
20650
|
+
const { stdout } = await run4(cfg.bin, ["logs", name], process.env);
|
|
20389
20651
|
for (const d of parseDeniedRequests(stdout)) {
|
|
20390
20652
|
const where = `${d.host}${d.port !== void 0 ? `:${d.port}` : ""}${d.binary ? ` by ${d.binary}` : ""}`;
|
|
20391
20653
|
o.emit.warn(`sandbox_denied: ${where}${d.count > 1 ? ` (${d.count}x)` : ""} \u2014 blocked by the sandbox policy`, { data: { event: "sandbox_denied", sandbox: name, ...d } });
|
|
@@ -20407,7 +20669,7 @@ async function openReleaseSandbox(o) {
|
|
|
20407
20669
|
tagPattern: o.tagPattern
|
|
20408
20670
|
})}
|
|
20409
20671
|
${containerEngineStubScript()}`;
|
|
20410
|
-
await
|
|
20672
|
+
await run4(cfg.bin, ["sandbox", "exec", "-n", name, "--no-login-shell", "--", "sh", "-c", clone], process.env);
|
|
20411
20673
|
} catch (e) {
|
|
20412
20674
|
await closeSandbox();
|
|
20413
20675
|
throw new Error(`could not make the release clone in ${name}: ${describe(e)}`);
|
|
@@ -20508,7 +20770,7 @@ function missingReleaserWarning(repo, release, ships, now = Date.now()) {
|
|
|
20508
20770
|
}
|
|
20509
20771
|
|
|
20510
20772
|
// src/watch.ts
|
|
20511
|
-
import { watch as watchFile, existsSync as
|
|
20773
|
+
import { watch as watchFile, existsSync as existsSync42, statSync as statSync12, openSync as openSync5, readSync as readSync2, closeSync as closeSync5 } from "fs";
|
|
20512
20774
|
var E = "\x1B[";
|
|
20513
20775
|
var dim = (s) => `${E}2m${s}${E}0m`;
|
|
20514
20776
|
var bold = (s) => `${E}1m${s}${E}0m`;
|
|
@@ -20609,8 +20871,8 @@ function renderHeaders(states, now = Date.now()) {
|
|
|
20609
20871
|
return states.map((s) => renderHeader(s, now)).join("");
|
|
20610
20872
|
}
|
|
20611
20873
|
function readFrom(file, from) {
|
|
20612
|
-
if (!
|
|
20613
|
-
const size =
|
|
20874
|
+
if (!existsSync42(file)) return { events: [], offset: from };
|
|
20875
|
+
const size = statSync12(file).size;
|
|
20614
20876
|
if (size < from) return readFrom(file, 0);
|
|
20615
20877
|
if (size === from) return { events: [], offset: from };
|
|
20616
20878
|
const fd = openSync5(file, "r");
|
|
@@ -20852,7 +21114,7 @@ function nextRoles(decision, ran) {
|
|
|
20852
21114
|
}
|
|
20853
21115
|
|
|
20854
21116
|
// src/ship-name.ts
|
|
20855
|
-
import { existsSync as
|
|
21117
|
+
import { existsSync as existsSync43, mkdirSync as mkdirSync31, readFileSync as readFileSync38, renameSync as renameSync5, writeFileSync as writeFileSync33 } from "fs";
|
|
20856
21118
|
import { dirname as dirname27 } from "path";
|
|
20857
21119
|
import { parseDocument as parseDocument5 } from "yaml";
|
|
20858
21120
|
var ShipNameError = class extends Error {
|
|
@@ -20914,7 +21176,7 @@ async function syncRouteName(i) {
|
|
|
20914
21176
|
return { status: "ok", ...base, action, name: i.local };
|
|
20915
21177
|
}
|
|
20916
21178
|
function readSyncedName(resolvedFile) {
|
|
20917
|
-
if (!
|
|
21179
|
+
if (!existsSync43(resolvedFile)) return void 0;
|
|
20918
21180
|
try {
|
|
20919
21181
|
const v = JSON.parse(readFileSync38(resolvedFile, "utf8")).shipName;
|
|
20920
21182
|
return typeof v === "string" ? v : void 0;
|
|
@@ -20923,7 +21185,7 @@ function readSyncedName(resolvedFile) {
|
|
|
20923
21185
|
}
|
|
20924
21186
|
}
|
|
20925
21187
|
function writeSyncedName(resolvedFile, name) {
|
|
20926
|
-
if (!
|
|
21188
|
+
if (!existsSync43(resolvedFile)) return;
|
|
20927
21189
|
let raw;
|
|
20928
21190
|
try {
|
|
20929
21191
|
raw = JSON.parse(readFileSync38(resolvedFile, "utf8"));
|
|
@@ -21625,7 +21887,7 @@ function describeCapability(i) {
|
|
|
21625
21887
|
}
|
|
21626
21888
|
|
|
21627
21889
|
// src/agents-sync-run.ts
|
|
21628
|
-
import { existsSync as
|
|
21890
|
+
import { existsSync as existsSync44, mkdirSync as mkdirSync32, readFileSync as readFileSync39, writeFileSync as writeFileSync34 } from "fs";
|
|
21629
21891
|
import { dirname as dirname28 } from "path";
|
|
21630
21892
|
async function runAgentsSync(target, o) {
|
|
21631
21893
|
const dryRun = o.dryRun ?? false;
|
|
@@ -21659,7 +21921,7 @@ async function runAgentsSync(target, o) {
|
|
|
21659
21921
|
for (const s of skillResult?.outcomes ?? []) o.say(describeSkillSyncOutcome(s));
|
|
21660
21922
|
if (!dryRun) {
|
|
21661
21923
|
const resolvedPath = resolvedPathFor(o.stateDir, target.route);
|
|
21662
|
-
const raw =
|
|
21924
|
+
const raw = existsSync44(resolvedPath) ? JSON.parse(readFileSync39(resolvedPath, "utf8")) : {};
|
|
21663
21925
|
raw.agentPersonas = personaResult.agentPersonas;
|
|
21664
21926
|
if (skillResult) raw.agentSkills = skillResult.agentSkills;
|
|
21665
21927
|
if (personaResult.releaseAgentId) raw.releaseAgentId = personaResult.releaseAgentId;
|
|
@@ -21807,21 +22069,21 @@ var POSIX_SHELL = /^(?:ba|z|da|k|a|mk)?sh$|^fish$/;
|
|
|
21807
22069
|
function checkHookSyntax(script, shell) {
|
|
21808
22070
|
const spec = resolveShell(shell);
|
|
21809
22071
|
const name = basename11(spec.bin).replace(/\.exe$/i, "").toLowerCase();
|
|
21810
|
-
let
|
|
22072
|
+
let run4;
|
|
21811
22073
|
if (POSIX_SHELL.test(name)) {
|
|
21812
|
-
|
|
22074
|
+
run4 = spawnSync11(spec.bin, ["-n"], { input: script, encoding: "utf8" });
|
|
21813
22075
|
} else if (/^(pwsh|powershell)$/.test(name)) {
|
|
21814
22076
|
const parse3 = "$e=$null;[void][System.Management.Automation.Language.Parser]::ParseInput($env:CREW_CHECK_SCRIPT,[ref]$null,[ref]$e);if($e){$e|ForEach-Object{[Console]::Error.WriteLine($_.Message)};exit 1}";
|
|
21815
|
-
|
|
22077
|
+
run4 = spawnSync11(spec.bin, ["-NoProfile", "-NonInteractive", "-Command", parse3], {
|
|
21816
22078
|
encoding: "utf8",
|
|
21817
22079
|
env: { ...process.env, CREW_CHECK_SCRIPT: script }
|
|
21818
22080
|
});
|
|
21819
22081
|
} else {
|
|
21820
22082
|
return { status: "unchecked", message: `no syntax check for ${spec.bin}` };
|
|
21821
22083
|
}
|
|
21822
|
-
if (
|
|
21823
|
-
if (
|
|
21824
|
-
const message = `${
|
|
22084
|
+
if (run4.error) return { status: "unchecked", message: `cannot run ${spec.bin}: ${run4.error.message}` };
|
|
22085
|
+
if (run4.status === 0) return { status: "ok" };
|
|
22086
|
+
const message = `${run4.stderr ?? ""}${run4.stdout ?? ""}`.trim() || `${spec.bin} exited ${run4.status}`;
|
|
21825
22087
|
return { status: "error", message };
|
|
21826
22088
|
}
|
|
21827
22089
|
function renderSamples(cfg, dir) {
|
|
@@ -22252,7 +22514,7 @@ async function runAgentSuggest(o) {
|
|
|
22252
22514
|
const before = porcelain(o.dir);
|
|
22253
22515
|
const timeout = AbortSignal.timeout(o.timeoutMs ?? DEFAULT_TIMEOUT_MS);
|
|
22254
22516
|
const signal = o.signal ? AbortSignal.any([o.signal, timeout]) : timeout;
|
|
22255
|
-
const
|
|
22517
|
+
const run4 = await new Promise((resolve8) => {
|
|
22256
22518
|
let out = "";
|
|
22257
22519
|
let err3 = "";
|
|
22258
22520
|
const child = spawn8(bin, args, { cwd: o.dir, env, detached: true, stdio: ["pipe", "pipe", "pipe"] });
|
|
@@ -22287,18 +22549,18 @@ async function runAgentSuggest(o) {
|
|
|
22287
22549
|
});
|
|
22288
22550
|
child.stdin.end(buildAgentPrompt(o.sniff));
|
|
22289
22551
|
});
|
|
22290
|
-
if (
|
|
22552
|
+
if (run4.aborted || signal.aborted) {
|
|
22291
22553
|
throw new AgentSuggestError(o.signal?.aborted ? "cancelled" : "timeout", o.signal?.aborted ? "cancelled" : "the toolchain did not answer in time");
|
|
22292
22554
|
}
|
|
22293
22555
|
const after = porcelain(o.dir);
|
|
22294
22556
|
if (before !== void 0 && after !== before) {
|
|
22295
22557
|
throw new AgentSuggestError("modified_checkout", "the checkout changed during --agent; inspect it with `git status` (the agent result was discarded)");
|
|
22296
22558
|
}
|
|
22297
|
-
const parsed = parseAgentStream(
|
|
22298
|
-
if (
|
|
22299
|
-
const reason = classifyFailure({ code:
|
|
22300
|
-
${
|
|
22301
|
-
throw new AgentSuggestError(reason, reason === "not_installed" ? `${bin} is not installed` : reason === "not_signed_in" ? `${o.spec.name} is not signed in` : (parsed.text ||
|
|
22559
|
+
const parsed = parseAgentStream(run4.out, o.dir);
|
|
22560
|
+
if (run4.spawnError || run4.code !== 0 || parsed.isError) {
|
|
22561
|
+
const reason = classifyFailure({ code: run4.code, ...run4.spawnError ? { spawnError: run4.spawnError } : {}, output: `${parsed.text}
|
|
22562
|
+
${run4.err}` });
|
|
22563
|
+
throw new AgentSuggestError(reason, reason === "not_installed" ? `${bin} is not installed` : reason === "not_signed_in" ? `${o.spec.name} is not signed in` : (parsed.text || run4.err).trim().slice(0, 300) || `exited ${run4.code}`);
|
|
22302
22564
|
}
|
|
22303
22565
|
const { hooks, notes } = parseAgentHooks(parsed.text);
|
|
22304
22566
|
const differsFromSniff = HOOK_KEYS2.filter((k) => hooks[k] !== void 0 && hooks[k] !== o.sniff.hooks[k]);
|
|
@@ -22374,7 +22636,7 @@ function planSampleTicket(i) {
|
|
|
22374
22636
|
}
|
|
22375
22637
|
|
|
22376
22638
|
// src/worktree-sweep.ts
|
|
22377
|
-
import { existsSync as
|
|
22639
|
+
import { existsSync as existsSync45, readFileSync as readFileSync41, readdirSync as readdirSync14 } from "fs";
|
|
22378
22640
|
import { basename as basename13, dirname as dirname30, join as join45, resolve as resolve5 } from "path";
|
|
22379
22641
|
function planWorktreeSweep(target, tickets, contract) {
|
|
22380
22642
|
const terminal = new Set(contract.statuses.resolved.filter((s) => s !== contract.statuses.verified));
|
|
@@ -22487,7 +22749,7 @@ async function applyWorktreeSweep(cwd, actions, dryRun, log, remote = "origin",
|
|
|
22487
22749
|
let removed = 0;
|
|
22488
22750
|
let keptBranches = 0;
|
|
22489
22751
|
for (const a of actions) {
|
|
22490
|
-
if (!dryRun && base && !a.keepBranch &&
|
|
22752
|
+
if (!dryRun && base && !a.keepBranch && existsSync45(a.path) && isHandBackMerge(a.path, base)) {
|
|
22491
22753
|
if (gitOk(a.path, ["merge", "--abort"]) !== null) {
|
|
22492
22754
|
log.emit(
|
|
22493
22755
|
`abandoned the hand-back merge of ${base} in ${a.path}: ${a.ticket.issue_id} deployed without it`,
|
|
@@ -22495,7 +22757,7 @@ async function applyWorktreeSweep(cwd, actions, dryRun, log, remote = "origin",
|
|
|
22495
22757
|
);
|
|
22496
22758
|
}
|
|
22497
22759
|
}
|
|
22498
|
-
if (!dryRun &&
|
|
22760
|
+
if (!dryRun && existsSync45(a.path)) {
|
|
22499
22761
|
let dirty = false;
|
|
22500
22762
|
try {
|
|
22501
22763
|
dirty = status(a.path).length > 0;
|
|
@@ -22506,7 +22768,7 @@ async function applyWorktreeSweep(cwd, actions, dryRun, log, remote = "origin",
|
|
|
22506
22768
|
continue;
|
|
22507
22769
|
}
|
|
22508
22770
|
}
|
|
22509
|
-
if (!dryRun && a.requirePushed && a.branch &&
|
|
22771
|
+
if (!dryRun && a.requirePushed && a.branch && existsSync45(a.path) && remoteConfigured(cwd, remote) && worktreeHoldsUnpushed(a.path, remote)) {
|
|
22510
22772
|
refuse2(a, "unpushed commits", `${a.branch} has commits that are not on ${remote}`);
|
|
22511
22773
|
continue;
|
|
22512
22774
|
}
|
|
@@ -22660,16 +22922,16 @@ function applyRemoteBranchCleanup(cwd, remote, branches2, dryRun, log) {
|
|
|
22660
22922
|
}
|
|
22661
22923
|
|
|
22662
22924
|
// src/stream-sweep.ts
|
|
22663
|
-
import { existsSync as
|
|
22925
|
+
import { existsSync as existsSync46, readdirSync as readdirSync15, rmSync as rmSync20, statSync as statSync13 } from "fs";
|
|
22664
22926
|
import { join as join46 } from "path";
|
|
22665
22927
|
var DAY_MS2 = 24 * 60 * 60 * 1e3;
|
|
22666
22928
|
function planStreamSweep(stateDir, retentionDays, now = Date.now()) {
|
|
22667
22929
|
const dir = join46(stateDir, "streams");
|
|
22668
|
-
if (!
|
|
22930
|
+
if (!existsSync46(dir)) return [];
|
|
22669
22931
|
const cutoff = now - retentionDays * DAY_MS2;
|
|
22670
22932
|
return readdirSync15(dir).map((name) => join46(dir, name)).filter((path) => {
|
|
22671
22933
|
try {
|
|
22672
|
-
return
|
|
22934
|
+
return statSync13(path).mtimeMs < cutoff;
|
|
22673
22935
|
} catch {
|
|
22674
22936
|
return false;
|
|
22675
22937
|
}
|
|
@@ -22693,11 +22955,11 @@ function applyStreamSweep(paths, dryRun, log) {
|
|
|
22693
22955
|
return removed;
|
|
22694
22956
|
}
|
|
22695
22957
|
function planEventsSweep(stateDir, retentionDays, now = Date.now()) {
|
|
22696
|
-
if (!
|
|
22958
|
+
if (!existsSync46(stateDir)) return [];
|
|
22697
22959
|
const cutoff = now - retentionDays * DAY_MS2;
|
|
22698
22960
|
return readdirSync15(stateDir).filter((name) => ROTATED_EVENTS_RE.test(name)).map((name) => join46(stateDir, name)).filter((path) => {
|
|
22699
22961
|
try {
|
|
22700
|
-
return
|
|
22962
|
+
return statSync13(path).mtimeMs < cutoff;
|
|
22701
22963
|
} catch {
|
|
22702
22964
|
return false;
|
|
22703
22965
|
}
|
|
@@ -22705,11 +22967,11 @@ function planEventsSweep(stateDir, retentionDays, now = Date.now()) {
|
|
|
22705
22967
|
}
|
|
22706
22968
|
|
|
22707
22969
|
// src/cli.ts
|
|
22708
|
-
import { realpathSync as realpathSync3, readFileSync as readFileSync48, existsSync as
|
|
22970
|
+
import { realpathSync as realpathSync3, readFileSync as readFileSync48, existsSync as existsSync54, mkdirSync as mkdirSync40, writeFileSync as writeFileSync40, rmSync as rmSync25, unlinkSync as unlinkSync5, copyFileSync as copyFileSync2, renameSync as renameSync7, statSync as statSync17, readdirSync as readdirSync20 } from "fs";
|
|
22709
22971
|
import { createInterface } from "readline/promises";
|
|
22710
22972
|
|
|
22711
22973
|
// src/periscope-cmd.ts
|
|
22712
|
-
import { existsSync as
|
|
22974
|
+
import { existsSync as existsSync47, mkdirSync as mkdirSync33, readFileSync as readFileSync42, rmSync as rmSync21, writeFileSync as writeFileSync35 } from "fs";
|
|
22713
22975
|
import { join as join47 } from "path";
|
|
22714
22976
|
var PeriscopeError = class extends Error {
|
|
22715
22977
|
};
|
|
@@ -22735,7 +22997,7 @@ function writePeriscopePrior(stateDir, ticketRecordId, prior) {
|
|
|
22735
22997
|
function readPeriscopePrior(stateDir, ticketRecordId) {
|
|
22736
22998
|
try {
|
|
22737
22999
|
const p = priorPath(stateDir, ticketRecordId);
|
|
22738
|
-
return
|
|
23000
|
+
return existsSync47(p) ? JSON.parse(readFileSync42(p, "utf8")) : void 0;
|
|
22739
23001
|
} catch {
|
|
22740
23002
|
return void 0;
|
|
22741
23003
|
}
|
|
@@ -23188,7 +23450,7 @@ ${tail2(preview.output)}`);
|
|
|
23188
23450
|
|
|
23189
23451
|
// src/periscope-idle.ts
|
|
23190
23452
|
import { execFileSync as execFileSync13 } from "child_process";
|
|
23191
|
-
import { statSync as
|
|
23453
|
+
import { statSync as statSync14 } from "fs";
|
|
23192
23454
|
import { join as join48 } from "path";
|
|
23193
23455
|
var MAX_SCANNED_FILES = 2e4;
|
|
23194
23456
|
function newestWorktreeMtime(root) {
|
|
@@ -23214,7 +23476,7 @@ function newestTrackedMtime(root) {
|
|
|
23214
23476
|
if (!rel) continue;
|
|
23215
23477
|
if (++scanned > MAX_SCANNED_FILES) break;
|
|
23216
23478
|
try {
|
|
23217
|
-
const m =
|
|
23479
|
+
const m = statSync14(join48(root, rel)).mtimeMs;
|
|
23218
23480
|
if (newest === null || m > newest) newest = m;
|
|
23219
23481
|
} catch {
|
|
23220
23482
|
}
|
|
@@ -23291,7 +23553,7 @@ import { dirname as dirOf2, resolve as resolvePath } from "path";
|
|
|
23291
23553
|
|
|
23292
23554
|
// src/ssh-keys.ts
|
|
23293
23555
|
import { execFileSync as execFileSync14 } from "child_process";
|
|
23294
|
-
import { existsSync as
|
|
23556
|
+
import { existsSync as existsSync48, mkdirSync as mkdirSync34, readFileSync as readFileSync43, chmodSync as chmodSync3 } from "fs";
|
|
23295
23557
|
import { dirname as dirname31, join as join49 } from "path";
|
|
23296
23558
|
var SshKeyError = class extends Error {
|
|
23297
23559
|
};
|
|
@@ -23301,7 +23563,7 @@ function shipSshKeyPathFor(stateDir) {
|
|
|
23301
23563
|
function ensureShipSshKeypair(stateDir) {
|
|
23302
23564
|
const privateKeyPath = shipSshKeyPathFor(stateDir);
|
|
23303
23565
|
const publicKeyPath = `${privateKeyPath}.pub`;
|
|
23304
|
-
if (!
|
|
23566
|
+
if (!existsSync48(privateKeyPath)) {
|
|
23305
23567
|
mkdirSync34(dirname31(privateKeyPath), { recursive: true });
|
|
23306
23568
|
try {
|
|
23307
23569
|
execFileSync14("ssh-keygen", [
|
|
@@ -23322,7 +23584,7 @@ function ensureShipSshKeypair(stateDir) {
|
|
|
23322
23584
|
}
|
|
23323
23585
|
chmodSync3(privateKeyPath, 384);
|
|
23324
23586
|
}
|
|
23325
|
-
if (!
|
|
23587
|
+
if (!existsSync48(publicKeyPath)) {
|
|
23326
23588
|
throw new SshKeyError(`${privateKeyPath} exists but ${publicKeyPath} does not \u2014 regenerate or restore it`);
|
|
23327
23589
|
}
|
|
23328
23590
|
const publicKey = readFileSync43(publicKeyPath, "utf8").trim();
|
|
@@ -23489,7 +23751,7 @@ async function unregisterEndpoint(workspaceId, info, d) {
|
|
|
23489
23751
|
import { createServer as createHttpServer } from "http";
|
|
23490
23752
|
import { spawn as spawn9 } from "child_process";
|
|
23491
23753
|
import { randomBytes } from "crypto";
|
|
23492
|
-
import { existsSync as
|
|
23754
|
+
import { existsSync as existsSync49, mkdirSync as mkdirSync35, readFileSync as readFileSync44, writeFileSync as writeFileSync36, unlinkSync as unlinkSync4, readdirSync as readdirSync16 } from "fs";
|
|
23493
23755
|
import { join as join50 } from "path";
|
|
23494
23756
|
|
|
23495
23757
|
// src/secret-compare.ts
|
|
@@ -23587,7 +23849,7 @@ function syncDaemonStatePath(stateDir, workspaceId) {
|
|
|
23587
23849
|
}
|
|
23588
23850
|
function readPersistedSyncDaemon(stateDir, workspaceId) {
|
|
23589
23851
|
const path = syncDaemonStatePath(stateDir, workspaceId);
|
|
23590
|
-
if (!
|
|
23852
|
+
if (!existsSync49(path)) return void 0;
|
|
23591
23853
|
try {
|
|
23592
23854
|
return JSON.parse(readFileSync44(path, "utf8"));
|
|
23593
23855
|
} catch {
|
|
@@ -23618,7 +23880,7 @@ function waitForExit(pid, alive, timeoutMs = 5e3) {
|
|
|
23618
23880
|
}
|
|
23619
23881
|
function readAllPersistedSyncWorkspaceIds(stateDir) {
|
|
23620
23882
|
const dir = join50(stateDir, "passengers");
|
|
23621
|
-
if (!
|
|
23883
|
+
if (!existsSync49(dir)) return [];
|
|
23622
23884
|
const suffix = "-sync.json";
|
|
23623
23885
|
return readdirSync16(dir).filter((f) => f.endsWith(suffix)).map((f) => f.slice(0, -suffix.length));
|
|
23624
23886
|
}
|
|
@@ -24138,12 +24400,12 @@ function contractFixers(dir, baseRef, tickets, locate) {
|
|
|
24138
24400
|
}
|
|
24139
24401
|
|
|
24140
24402
|
// src/daemon.ts
|
|
24141
|
-
import { existsSync as
|
|
24403
|
+
import { existsSync as existsSync51, mkdirSync as mkdirSync38, readFileSync as readFileSync46, readdirSync as readdirSync17, rmSync as rmSync22, statSync as statSync15, writeFileSync as writeFileSync38 } from "fs";
|
|
24142
24404
|
import { join as join53 } from "path";
|
|
24143
24405
|
import { randomBytes as randomBytes2 } from "crypto";
|
|
24144
24406
|
|
|
24145
24407
|
// src/noop-runs.ts
|
|
24146
|
-
import { existsSync as
|
|
24408
|
+
import { existsSync as existsSync50, mkdirSync as mkdirSync37, readFileSync as readFileSync45, renameSync as renameSync6, writeFileSync as writeFileSync37 } from "fs";
|
|
24147
24409
|
import { join as join52 } from "path";
|
|
24148
24410
|
var NOOP_DELAYS_MS = [5, 15, 60].map((m) => m * 6e4);
|
|
24149
24411
|
var DEFAULT_NOOP_REPEATS = 3;
|
|
@@ -24178,7 +24440,7 @@ function recordNoopRun(stateDir, recordId, repeats, now = Date.now()) {
|
|
|
24178
24440
|
return { count, nextAt, bounce: count >= repeats };
|
|
24179
24441
|
}
|
|
24180
24442
|
function clearNoopRuns(stateDir, recordId) {
|
|
24181
|
-
if (!
|
|
24443
|
+
if (!existsSync50(noopRunsPath(stateDir))) return;
|
|
24182
24444
|
const state = readNoopRuns(stateDir);
|
|
24183
24445
|
if (!(recordId in state)) return;
|
|
24184
24446
|
delete state[recordId];
|
|
@@ -24313,7 +24575,7 @@ async function runDaemonLoop(o) {
|
|
|
24313
24575
|
function latestMtime(path) {
|
|
24314
24576
|
let stat2;
|
|
24315
24577
|
try {
|
|
24316
|
-
stat2 =
|
|
24578
|
+
stat2 = statSync15(path);
|
|
24317
24579
|
} catch {
|
|
24318
24580
|
return 0;
|
|
24319
24581
|
}
|
|
@@ -24330,14 +24592,14 @@ function computeTreeSignature(paths) {
|
|
|
24330
24592
|
}
|
|
24331
24593
|
function makeStaleChecker(paths, opts = {}) {
|
|
24332
24594
|
const initial = computeTreeSignature(paths);
|
|
24333
|
-
return () => computeTreeSignature(paths) !== initial || opts.reloadSentinel !== void 0 &&
|
|
24595
|
+
return () => computeTreeSignature(paths) !== initial || opts.reloadSentinel !== void 0 && existsSync51(opts.reloadSentinel);
|
|
24334
24596
|
}
|
|
24335
24597
|
function reloadSentinelFor(stateDir) {
|
|
24336
24598
|
return join53(stateDir, "reload-requested");
|
|
24337
24599
|
}
|
|
24338
24600
|
function readReloadRequestedAt(stateDir) {
|
|
24339
24601
|
try {
|
|
24340
|
-
return
|
|
24602
|
+
return statSync15(reloadSentinelFor(stateDir)).mtimeMs;
|
|
24341
24603
|
} catch {
|
|
24342
24604
|
return null;
|
|
24343
24605
|
}
|
|
@@ -24362,7 +24624,7 @@ function readDaemonStarted(stateDir) {
|
|
|
24362
24624
|
function configChangedAfter(files, startedAt) {
|
|
24363
24625
|
for (const f of files) {
|
|
24364
24626
|
try {
|
|
24365
|
-
if (
|
|
24627
|
+
if (statSync15(f).mtimeMs > startedAt) return f;
|
|
24366
24628
|
} catch {
|
|
24367
24629
|
}
|
|
24368
24630
|
}
|
|
@@ -24434,6 +24696,13 @@ async function runOnePassUnguarded(o) {
|
|
|
24434
24696
|
} catch (e) {
|
|
24435
24697
|
emit.warn(`could not reconcile earlier agent runs: ${e.message}`, { step: "agent" });
|
|
24436
24698
|
}
|
|
24699
|
+
if (o.sandboxHygiene) {
|
|
24700
|
+
try {
|
|
24701
|
+
await o.sandboxHygiene();
|
|
24702
|
+
} catch (e) {
|
|
24703
|
+
emit.warn(`sandbox hygiene failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
24704
|
+
}
|
|
24705
|
+
}
|
|
24437
24706
|
const decision = await decide(ctx);
|
|
24438
24707
|
o.state.attention(o.route.route).persist(decision.attention);
|
|
24439
24708
|
o.state.unroutable(o.route.route).persist(decision.unroutable);
|
|
@@ -24541,7 +24810,7 @@ async function runOnePassUnguarded(o) {
|
|
|
24541
24810
|
settle = resolve8;
|
|
24542
24811
|
});
|
|
24543
24812
|
const ready = (tookTicket2) => settle(tookTicket2);
|
|
24544
|
-
const
|
|
24813
|
+
const run4 = spawn13(role, decision, ctx, { ready }).then(() => {
|
|
24545
24814
|
breaker.recordSuccess(role);
|
|
24546
24815
|
clearShipAttention(o.state, `role_parked:${role}`);
|
|
24547
24816
|
clearShipAttention(o.state, workspaceAuthKey(role));
|
|
@@ -24596,8 +24865,8 @@ async function runOnePassUnguarded(o) {
|
|
|
24596
24865
|
});
|
|
24597
24866
|
if (o.inFlight) {
|
|
24598
24867
|
const set = o.inFlight;
|
|
24599
|
-
set.add(
|
|
24600
|
-
void
|
|
24868
|
+
set.add(run4);
|
|
24869
|
+
void run4.finally(() => set.delete(run4));
|
|
24601
24870
|
}
|
|
24602
24871
|
const reported2 = TICKET_ROLES.has(role) ? await settled : true;
|
|
24603
24872
|
const tookTicket = reported2 !== false;
|
|
@@ -25057,19 +25326,19 @@ import { createHash as createHash11 } from "crypto";
|
|
|
25057
25326
|
import {
|
|
25058
25327
|
chmodSync as chmodSync4,
|
|
25059
25328
|
closeSync as closeSync6,
|
|
25060
|
-
existsSync as
|
|
25329
|
+
existsSync as existsSync52,
|
|
25061
25330
|
fstatSync,
|
|
25062
25331
|
openSync as openSync6,
|
|
25063
25332
|
readSync as readSync3,
|
|
25064
25333
|
readdirSync as readdirSync18,
|
|
25065
25334
|
rmSync as rmSync23,
|
|
25066
|
-
statSync as
|
|
25335
|
+
statSync as statSync16,
|
|
25067
25336
|
watch
|
|
25068
25337
|
} from "fs";
|
|
25069
25338
|
import { createConnection } from "net";
|
|
25070
25339
|
import { createServer as createServer2 } from "http";
|
|
25071
25340
|
import { basename as basename14, dirname as dirname33, join as join54 } from "path";
|
|
25072
|
-
import { execFile as
|
|
25341
|
+
import { execFile as execFile6, spawn as spawn12 } from "child_process";
|
|
25073
25342
|
|
|
25074
25343
|
// src/periscope-control.ts
|
|
25075
25344
|
import { spawn as spawn11 } from "child_process";
|
|
@@ -25407,7 +25676,7 @@ function readRange(path, from, max) {
|
|
|
25407
25676
|
}
|
|
25408
25677
|
}
|
|
25409
25678
|
function lastLines2(path, n) {
|
|
25410
|
-
const st =
|
|
25679
|
+
const st = statSync16(path);
|
|
25411
25680
|
const cursorAt = (off) => encodeCursor({ dev: st.dev, ino: st.ino, off });
|
|
25412
25681
|
if (n <= 0 || st.size === 0) return { lines: [], cursor: cursorAt(st.size), reset: false };
|
|
25413
25682
|
let start = st.size;
|
|
@@ -25428,7 +25697,7 @@ function lastLines2(path, n) {
|
|
|
25428
25697
|
}
|
|
25429
25698
|
function readTail(live, opts) {
|
|
25430
25699
|
const max = opts.maxBytes ?? MAX_TAIL_BYTES;
|
|
25431
|
-
if (!
|
|
25700
|
+
if (!existsSync52(live)) {
|
|
25432
25701
|
return { lines: [], cursor: opts.after ?? encodeCursor({ dev: 0, ino: 0, off: 0 }), reset: false };
|
|
25433
25702
|
}
|
|
25434
25703
|
const cur = opts.after ? decodeCursor(opts.after) : null;
|
|
@@ -25441,7 +25710,7 @@ function readTail(live, opts) {
|
|
|
25441
25710
|
} else {
|
|
25442
25711
|
const found = candidates(live, opts.rotated ?? false).find((p) => {
|
|
25443
25712
|
try {
|
|
25444
|
-
const s =
|
|
25713
|
+
const s = statSync16(p);
|
|
25445
25714
|
return s.ino === cur.ino && s.dev === cur.dev;
|
|
25446
25715
|
} catch {
|
|
25447
25716
|
return false;
|
|
@@ -25452,7 +25721,7 @@ function readTail(live, opts) {
|
|
|
25452
25721
|
off = cur.off;
|
|
25453
25722
|
} else reset = true;
|
|
25454
25723
|
}
|
|
25455
|
-
let size =
|
|
25724
|
+
let size = statSync16(path).size;
|
|
25456
25725
|
if (off > size) {
|
|
25457
25726
|
off = 0;
|
|
25458
25727
|
reset = true;
|
|
@@ -25460,12 +25729,12 @@ function readTail(live, opts) {
|
|
|
25460
25729
|
if (off >= size && path !== live) {
|
|
25461
25730
|
path = live;
|
|
25462
25731
|
off = 0;
|
|
25463
|
-
size =
|
|
25732
|
+
size = statSync16(path).size;
|
|
25464
25733
|
}
|
|
25465
25734
|
const { text: text2 } = readRange(path, off, max);
|
|
25466
25735
|
const cut = text2.lastIndexOf("\n");
|
|
25467
25736
|
const whole = cut < 0 ? "" : text2.slice(0, cut + 1);
|
|
25468
|
-
const st =
|
|
25737
|
+
const st = statSync16(path);
|
|
25469
25738
|
return {
|
|
25470
25739
|
lines: whole.split("\n").filter((l) => l.length),
|
|
25471
25740
|
cursor: encodeCursor({ dev: st.dev, ino: st.ino, off: off + Buffer.byteLength(whole) }),
|
|
@@ -25582,10 +25851,10 @@ async function route(deps, method, url, req, abort) {
|
|
|
25582
25851
|
if (p === "/events" && get2) return tailReply(eventFileFor(deps.stateDir), url.searchParams, true, abort);
|
|
25583
25852
|
if (p === "/streams" && get2) return reply2(200, { streams: liveRuns(deps.stateDir).map(describeStream) });
|
|
25584
25853
|
if (p.startsWith("/streams/") && get2) {
|
|
25585
|
-
const
|
|
25586
|
-
if (!RUN_NAME_RE.test(
|
|
25587
|
-
const file = join54(deps.stateDir, "streams",
|
|
25588
|
-
if (!
|
|
25854
|
+
const run4 = decodeURIComponent(p.slice("/streams/".length));
|
|
25855
|
+
if (!RUN_NAME_RE.test(run4) || run4.includes("..") || /\.(pid|meta\.json|events\.jsonl)$/.test(run4)) return err2(400, "not a run name");
|
|
25856
|
+
const file = join54(deps.stateDir, "streams", run4.endsWith(".jsonl") ? run4 : `${run4}.jsonl`);
|
|
25857
|
+
if (!existsSync52(file)) return err2(404, "no such run");
|
|
25589
25858
|
return tailReply(file, url.searchParams, false, abort);
|
|
25590
25859
|
}
|
|
25591
25860
|
if ((p === "/pause" || p === "/resume") && post3) {
|
|
@@ -25630,7 +25899,7 @@ function send(res, r) {
|
|
|
25630
25899
|
res.end(body);
|
|
25631
25900
|
}
|
|
25632
25901
|
async function socketIsStale(path) {
|
|
25633
|
-
if (!
|
|
25902
|
+
if (!existsSync52(path)) return false;
|
|
25634
25903
|
return new Promise((resolve8) => {
|
|
25635
25904
|
const c = createConnection(path);
|
|
25636
25905
|
c.once("connect", () => {
|
|
@@ -25649,7 +25918,7 @@ async function startControlServer(deps) {
|
|
|
25649
25918
|
return null;
|
|
25650
25919
|
}
|
|
25651
25920
|
if (await socketIsStale(path)) rmSync23(path, { force: true });
|
|
25652
|
-
else if (
|
|
25921
|
+
else if (existsSync52(path)) {
|
|
25653
25922
|
log(`control API not started: ${path} is in use by another process`);
|
|
25654
25923
|
return null;
|
|
25655
25924
|
}
|
|
@@ -25711,18 +25980,18 @@ function runDetached(commands, spawnFn = spawn12) {
|
|
|
25711
25980
|
});
|
|
25712
25981
|
child.unref();
|
|
25713
25982
|
}
|
|
25714
|
-
function schedulerHandler(control,
|
|
25983
|
+
function schedulerHandler(control, run4 = runDetached) {
|
|
25715
25984
|
return (action) => {
|
|
25716
25985
|
const { startCommand: start, stopCommand: stop } = control;
|
|
25717
25986
|
if (!start || !stop) return { accepted: false, detail: "this host has no service manager for the daemon (cron or none)" };
|
|
25718
25987
|
const commands = action === "start" ? [start] : action === "stop" ? [stop] : [stop, start];
|
|
25719
|
-
|
|
25988
|
+
run4(commands);
|
|
25720
25989
|
return { accepted: true, detail: `${action} requested` };
|
|
25721
25990
|
};
|
|
25722
25991
|
}
|
|
25723
25992
|
function crewJson(args, timeoutMs = 6e4) {
|
|
25724
25993
|
return new Promise((resolve8) => {
|
|
25725
|
-
|
|
25994
|
+
execFile6(process.execPath, [process.argv[1] ?? "", ...args], { timeout: timeoutMs, maxBuffer: 16 * 1024 * 1024 }, (_e, stdout) => {
|
|
25726
25995
|
try {
|
|
25727
25996
|
const v = JSON.parse(String(stdout));
|
|
25728
25997
|
resolve8(v && typeof v === "object" && !Array.isArray(v) ? v : null);
|
|
@@ -25742,7 +26011,7 @@ import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/
|
|
|
25742
26011
|
|
|
25743
26012
|
// src/periscope-endpoints.ts
|
|
25744
26013
|
import { randomBytes as randomBytes3 } from "crypto";
|
|
25745
|
-
import { chmodSync as chmodSync5, existsSync as
|
|
26014
|
+
import { chmodSync as chmodSync5, existsSync as existsSync53, mkdirSync as mkdirSync39, readdirSync as readdirSync19, readFileSync as readFileSync47, rmSync as rmSync24, writeFileSync as writeFileSync39 } from "fs";
|
|
25746
26015
|
import { join as join55 } from "path";
|
|
25747
26016
|
var secretDir = (stateDir) => join55(stateDir, "periscope-mcp");
|
|
25748
26017
|
var secretFile = (stateDir, id) => join55(secretDir(stateDir), `${id}.json`);
|
|
@@ -25785,7 +26054,7 @@ function removePeriscopeEndpointRecord(stateDir, ticketRecordId) {
|
|
|
25785
26054
|
}
|
|
25786
26055
|
function listPeriscopeEndpoints(stateDir) {
|
|
25787
26056
|
const dir = endpointDir(stateDir);
|
|
25788
|
-
if (!
|
|
26057
|
+
if (!existsSync53(dir)) return [];
|
|
25789
26058
|
const out = [];
|
|
25790
26059
|
for (const name of readdirSync19(dir)) {
|
|
25791
26060
|
if (!name.endsWith(".json")) continue;
|
|
@@ -26768,7 +27037,7 @@ if (command === "passenger-sync-daemon") {
|
|
|
26768
27037
|
} else {
|
|
26769
27038
|
const toleratesNoRoutes = command === "credential" || command === "forge" || command === "repos" || command === "ship" || command === "disconnect" && flag("reset") || command === "deprovision" || command === "connect" && flag("sign-out");
|
|
26770
27039
|
const configless = command === "connect" && flag("sign-out") || command === "disconnect" && flag("reset") || command === "deprovision";
|
|
26771
|
-
if (configless && !
|
|
27040
|
+
if (configless && !existsSync54(findConfigFile(CREW_HOME))) {
|
|
26772
27041
|
cfg = loadConfig(CREW_HOME, firstRunConfigPath(), { text: "ship: {}\n", allowNoRoutes: true });
|
|
26773
27042
|
} else {
|
|
26774
27043
|
cfg = loadConfig(CREW_HOME, void 0, toleratesNoRoutes ? { allowNoRoutes: true } : {});
|
|
@@ -27121,7 +27390,7 @@ if (command === "passenger-sync-daemon") {
|
|
|
27121
27390
|
if (host === "linux" && hasSystemd) {
|
|
27122
27391
|
const label = labelFor(CREW_HOME, "run");
|
|
27123
27392
|
const staleTimer = join57(homedir11(), ".config", "systemd", "user", `${label}.timer`);
|
|
27124
|
-
if (
|
|
27393
|
+
if (existsSync54(staleTimer)) {
|
|
27125
27394
|
process.stdout.write(
|
|
27126
27395
|
`removing stale run timer from before the persistent-service cutover: ${staleTimer}${dryRun ? " (dry run)" : ""}
|
|
27127
27396
|
`
|
|
@@ -27150,7 +27419,7 @@ if (command === "passenger-sync-daemon") {
|
|
|
27150
27419
|
const { settled: doctorRepos, errors: refusedRepos } = await settleRepos(reposOf(c), (t) => t.name, (t) => resolveOneRepo(c, t));
|
|
27151
27420
|
for (const e of refusedRepos) problems.push(`repo ${e.repo}: ${e.detail}`);
|
|
27152
27421
|
for (const r of doctorRepos) {
|
|
27153
|
-
if (!
|
|
27422
|
+
if (!existsSync54(r.dir)) problems.push(`repo ${r.name}: ${r.dir} is missing on disk`);
|
|
27154
27423
|
if (!satisfies(host, r.config.platform)) problems.push(`repo ${r.name}: requires ${r.config.platform}, this host is ${host}`);
|
|
27155
27424
|
readiness.push(...validateEffective(r.config).map((p) => `repo ${r.name}: ${p}`));
|
|
27156
27425
|
}
|
|
@@ -27177,7 +27446,7 @@ if (command === "passenger-sync-daemon") {
|
|
|
27177
27446
|
}
|
|
27178
27447
|
async function doctorFix(o) {
|
|
27179
27448
|
const routes = await Promise.all(routesInScope(cfg.routes, named).map((c) => gatherHealth({ route: c.route, enabled: c.enabled, hasRepos: reposOf(c).length > 0 }, () => routeProblems(c))));
|
|
27180
|
-
const unitExists = (p) =>
|
|
27449
|
+
const unitExists = (p) => existsSync54(p);
|
|
27181
27450
|
const crontab = o.host === "linux" ? spawnSync12("crontab", ["-l"], { encoding: "utf8" }).stdout ?? "" : "";
|
|
27182
27451
|
const schedulerAbsent = o.host !== "windows" ? !schedulerInstalled(planInstall(cfg.ship, CREW_HOME, o.host, detectSystemd(), "run", installContext()), unitExists, crontab) : true;
|
|
27183
27452
|
const plan = planFix({ routes, schedulerAbsent, host: o.host });
|
|
@@ -27249,7 +27518,7 @@ ${changed2.map((c) => ` - ${c}
|
|
|
27249
27518
|
if (patterns.length > 0 && Object.keys(warm).length === 0 && firstReport(`warm-empty:${r.name}:${failure}`)) {
|
|
27250
27519
|
emit.emit(`${r.name}: sandbox.warm declares ${patterns.join(", ")} but no file could be read from ${source}${failure ? ` (${failure})` : ""}; the image is built without warm files`);
|
|
27251
27520
|
}
|
|
27252
|
-
out.set(r.name, { name: r.name, decl: intelFlavor(r.config.hooks.intel) === "serena" ? { ...r.config.sandbox, intel: "serena" } : r.config.sandbox, warm, ...wantsCodeBridge(r.config.hooks.intel) ? { bridge: readBridgeBundle() } : {} });
|
|
27521
|
+
out.set(r.name, { name: r.name, ...patterns.length > 0 && failure ? { unreadable: `sandbox.warm files could not be read (${failure})` } : {}, decl: intelFlavor(r.config.hooks.intel) === "serena" ? { ...r.config.sandbox, intel: "serena" } : r.config.sandbox, warm, ...wantsCodeBridge(r.config.hooks.intel) ? { bridge: readBridgeBundle() } : {} });
|
|
27253
27522
|
}
|
|
27254
27523
|
}
|
|
27255
27524
|
return [...out.values()];
|
|
@@ -28597,6 +28866,7 @@ ${cu.tail.trimEnd()}
|
|
|
28597
28866
|
});
|
|
28598
28867
|
if (controlServer) emit.emit(`control API listening on ${controlServer.path}`);
|
|
28599
28868
|
const inFlight = /* @__PURE__ */ new Set();
|
|
28869
|
+
const sandboxHygienePass = cfg.ship.runner === "sandbox" ? makeSandboxHygiene({ state, emit, ship: cfg.ship }) : void 0;
|
|
28600
28870
|
let sandboxBuilding = false;
|
|
28601
28871
|
const stopReason = await runDaemonLoop({
|
|
28602
28872
|
inFlight,
|
|
@@ -28606,6 +28876,7 @@ ${cu.tail.trimEnd()}
|
|
|
28606
28876
|
runPass: () => runOnePass({
|
|
28607
28877
|
inFlight,
|
|
28608
28878
|
sandboxCache: sandboxCachePass,
|
|
28879
|
+
sandboxHygiene: sandboxHygienePass,
|
|
28609
28880
|
route: route2,
|
|
28610
28881
|
ship: cfg.ship,
|
|
28611
28882
|
state,
|
|
@@ -28644,7 +28915,7 @@ ${cu.tail.trimEnd()}
|
|
|
28644
28915
|
),
|
|
28645
28916
|
checkStale: makeStaleChecker(watchPaths, { reloadSentinel: reloadSentinelFor(cfg.ship.stateDir) }),
|
|
28646
28917
|
onPass: (result) => {
|
|
28647
|
-
if (!sandboxBuilding) {
|
|
28918
|
+
if (!sandboxBuilding && !diskFullStop(state)) {
|
|
28648
28919
|
sandboxBuilding = true;
|
|
28649
28920
|
void sandboxReposOf(cfg.routes.filter((r) => r.enabled)).then(withShipSandbox).then((repos) => repos.length ? sandboxBuildTick(repos, sandboxTickDeps(emit, route2)) : null).catch((err3) => emit.warn(`sandbox image build tick failed: ${err3 instanceof Error ? err3.message : String(err3)}`)).finally(() => {
|
|
28650
28921
|
sandboxBuilding = false;
|
|
@@ -28752,9 +29023,9 @@ ${cu.tail.trimEnd()}
|
|
|
28752
29023
|
`);
|
|
28753
29024
|
process.exit(2);
|
|
28754
29025
|
}
|
|
28755
|
-
let
|
|
29026
|
+
let run4;
|
|
28756
29027
|
try {
|
|
28757
|
-
|
|
29028
|
+
run4 = await runAgentsSync(target, {
|
|
28758
29029
|
userAgent: cfg.ship.userAgent,
|
|
28759
29030
|
stateDir: cfg.ship.stateDir,
|
|
28760
29031
|
dryRun,
|
|
@@ -28772,7 +29043,7 @@ ${cu.tail.trimEnd()}
|
|
|
28772
29043
|
}
|
|
28773
29044
|
throw e;
|
|
28774
29045
|
}
|
|
28775
|
-
const { personaResult, skillResult } =
|
|
29046
|
+
const { personaResult, skillResult } = run4;
|
|
28776
29047
|
if (flag("revoke-seat-keys")) {
|
|
28777
29048
|
for (const o of await revokeSeatKeys(target, { userAgent: cfg.ship.userAgent, dryRun, shipName: cfg.ship.name })) {
|
|
28778
29049
|
process.stdout.write(`${describeRevokeOutcome(o)}
|
|
@@ -28793,7 +29064,7 @@ ${cu.tail.trimEnd()}
|
|
|
28793
29064
|
}
|
|
28794
29065
|
}
|
|
28795
29066
|
}
|
|
28796
|
-
if (
|
|
29067
|
+
if (run4.diverged) process.exitCode = 1;
|
|
28797
29068
|
break;
|
|
28798
29069
|
}
|
|
28799
29070
|
case "skills": {
|
|
@@ -28835,7 +29106,7 @@ ${cu.tail.trimEnd()}
|
|
|
28835
29106
|
`);
|
|
28836
29107
|
if (!dryRun) {
|
|
28837
29108
|
const resolvedPath = resolvedPathFor(cfg.ship.stateDir, target.route);
|
|
28838
|
-
const raw =
|
|
29109
|
+
const raw = existsSync54(resolvedPath) ? JSON.parse(readFileSync48(resolvedPath, "utf8")) : {};
|
|
28839
29110
|
raw.agentSkills = result.agentSkills;
|
|
28840
29111
|
mkdirSync40(dirOf2(resolvedPath), { recursive: true });
|
|
28841
29112
|
writeFileSync40(resolvedPath, `${JSON.stringify(raw, null, 2)}
|
|
@@ -28940,8 +29211,8 @@ ${cu.tail.trimEnd()}
|
|
|
28940
29211
|
try {
|
|
28941
29212
|
const a = parseHooksArgs(positional.slice(2), routeNamesOf(configText));
|
|
28942
29213
|
const dir = repoDirOf(configText, dirname35(cfg.configFile), a.route, a.name);
|
|
28943
|
-
if (!
|
|
28944
|
-
const files = { exists: (r) =>
|
|
29214
|
+
if (!existsSync54(dir)) throw new ReposError(`${dir} does not exist on disk`);
|
|
29215
|
+
const files = { exists: (r) => existsSync54(resolvePath(dir, r)), list: (r) => {
|
|
28945
29216
|
try {
|
|
28946
29217
|
return readdirSync20(resolvePath(dir, r));
|
|
28947
29218
|
} catch {
|
|
@@ -29059,7 +29330,7 @@ ${cu.tail.trimEnd()}
|
|
|
29059
29330
|
if (sub === "list" && !routeName) usage2();
|
|
29060
29331
|
if (sub === "add") {
|
|
29061
29332
|
try {
|
|
29062
|
-
const a = parseAddArgs(positional.slice(2), routeNamesOf(configText), (p) =>
|
|
29333
|
+
const a = parseAddArgs(positional.slice(2), routeNamesOf(configText), (p) => existsSync54(resolvePath(p.replace(/^~(?=\/|$)/, homedir11()))));
|
|
29063
29334
|
routeName = a.route;
|
|
29064
29335
|
addPath = a.path;
|
|
29065
29336
|
addName = a.name;
|
|
@@ -29089,7 +29360,7 @@ ${cu.tail.trimEnd()}
|
|
|
29089
29360
|
const resolvedFile = resolvedPathFor(cfg.ship.stateDir, routeName);
|
|
29090
29361
|
if (sub === "list" || sub === "add") {
|
|
29091
29362
|
const liveRoute = cfg.routes.find((r) => r.route === routeName);
|
|
29092
|
-
if (liveRoute?.resolved?.reposModelId &&
|
|
29363
|
+
if (liveRoute?.resolved?.reposModelId && existsSync54(resolvedFile) && !dryRun) {
|
|
29093
29364
|
try {
|
|
29094
29365
|
await hydrateApiKeys([liveRoute]);
|
|
29095
29366
|
persistRepoRows(cfg.ship.stateDir, liveRoute.route, await new Tracker(liveRoute, cfg.ship).repoRowsForMap());
|
|
@@ -29098,7 +29369,7 @@ ${cu.tail.trimEnd()}
|
|
|
29098
29369
|
}
|
|
29099
29370
|
}
|
|
29100
29371
|
let resolvedRemotes;
|
|
29101
|
-
if (
|
|
29372
|
+
if (existsSync54(resolvedFile)) {
|
|
29102
29373
|
try {
|
|
29103
29374
|
resolvedRemotes = JSON.parse(readFileSync48(resolvedFile, "utf8"));
|
|
29104
29375
|
} catch {
|
|
@@ -29107,7 +29378,7 @@ ${cu.tail.trimEnd()}
|
|
|
29107
29378
|
const originOf = (dir) => gitOk(dir, ["remote", "get-url", "origin"]) ?? void 0;
|
|
29108
29379
|
const text2 = configText;
|
|
29109
29380
|
const base = dirname35(cfg.configFile);
|
|
29110
|
-
const isCheckout = (d) =>
|
|
29381
|
+
const isCheckout = (d) => existsSync54(`${d}/.git`);
|
|
29111
29382
|
try {
|
|
29112
29383
|
if (sub === "list") {
|
|
29113
29384
|
if (flag("json")) {
|
|
@@ -29117,7 +29388,7 @@ ${cu.tail.trimEnd()}
|
|
|
29117
29388
|
base,
|
|
29118
29389
|
resolved: resolvedRemotes,
|
|
29119
29390
|
originOf,
|
|
29120
|
-
exists: (d) =>
|
|
29391
|
+
exists: (d) => existsSync54(d),
|
|
29121
29392
|
isCheckout,
|
|
29122
29393
|
repoHasHooks: (d) => REPO_CONFIG_FILENAMES.some((f) => {
|
|
29123
29394
|
try {
|
|
@@ -29139,7 +29410,7 @@ ${cu.tail.trimEnd()}
|
|
|
29139
29410
|
for (const r of repos) {
|
|
29140
29411
|
const origin2 = originOf(r.dir);
|
|
29141
29412
|
const row = matchRepoName(origin2, resolvedRemotes);
|
|
29142
|
-
const note = !
|
|
29413
|
+
const note = !existsSync54(r.dir) ? "missing on disk" : row ? `Repos row: ${row}` : `no Repos row matches ${normalizeRemote(origin2) ?? "this checkout (no origin remote)"}`;
|
|
29143
29414
|
process.stdout.write(`${r.name} ${r.dir} ${note}
|
|
29144
29415
|
`);
|
|
29145
29416
|
}
|
|
@@ -29151,9 +29422,9 @@ ${cu.tail.trimEnd()}
|
|
|
29151
29422
|
` : `${human}
|
|
29152
29423
|
`);
|
|
29153
29424
|
const plan2 = planRepoClone({ text: text2, base, route: routeName, name: addName, resolved: resolvedRemotes, dir: value("dir"), isCheckout });
|
|
29154
|
-
if (
|
|
29425
|
+
if (existsSync54(plan2.target) && (existsSync54(`${plan2.target}/.git`) || readdirSync20(plan2.target).length > 0)) {
|
|
29155
29426
|
throw new ReposError(
|
|
29156
|
-
|
|
29427
|
+
existsSync54(`${plan2.target}/.git`) ? `${plan2.target} is already a checkout \u2014 attach it with \`crew repos add ${routeName} ${plan2.name} ${plan2.target}\`` : `${plan2.target} exists and is not empty \u2014 pass --dir to clone somewhere else`
|
|
29157
29428
|
);
|
|
29158
29429
|
}
|
|
29159
29430
|
if (dryRun) {
|
|
@@ -29178,7 +29449,7 @@ ${cu.tail.trimEnd()}
|
|
|
29178
29449
|
break;
|
|
29179
29450
|
}
|
|
29180
29451
|
const target = resolvePath(addPath.replace(/^~(?=\/|$)/, homedir11()));
|
|
29181
|
-
const top =
|
|
29452
|
+
const top = existsSync54(target) ? gitOk(target, ["rev-parse", "--show-toplevel"]) : null;
|
|
29182
29453
|
if (!top) throw new ReposError(`${target} is not a git checkout`);
|
|
29183
29454
|
const origin = originOf(top);
|
|
29184
29455
|
const plan = planRepoAdd({
|
|
@@ -29230,7 +29501,7 @@ ${cu.tail.trimEnd()}
|
|
|
29230
29501
|
const created = await rowTracker.createRepoRow(rowPayload);
|
|
29231
29502
|
process.stdout.write(`created Repos row ${String(rowPayload.name)} (${String(rowPayload.remote)}) ${created.id}
|
|
29232
29503
|
`);
|
|
29233
|
-
if (
|
|
29504
|
+
if (existsSync54(resolvedFile)) {
|
|
29234
29505
|
const raw = JSON.parse(readFileSync48(resolvedFile, "utf8"));
|
|
29235
29506
|
raw.repoNames = { ...raw.repoNames, [created.id]: String(rowPayload.name) };
|
|
29236
29507
|
raw.repoRemotes = { ...raw.repoRemotes, [created.id]: String(rowPayload.remote) };
|
|
@@ -29656,7 +29927,7 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
|
|
|
29656
29927
|
}
|
|
29657
29928
|
}
|
|
29658
29929
|
let previous;
|
|
29659
|
-
const hadPreviousFile =
|
|
29930
|
+
const hadPreviousFile = existsSync54(resolvedPath);
|
|
29660
29931
|
if (hadPreviousFile) {
|
|
29661
29932
|
try {
|
|
29662
29933
|
previous = JSON.parse(readFileSync48(resolvedPath, "utf8"));
|
|
@@ -29972,7 +30243,7 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
|
|
|
29972
30243
|
if (syncRoute?.resolved) {
|
|
29973
30244
|
try {
|
|
29974
30245
|
process.stderr.write("\n");
|
|
29975
|
-
const
|
|
30246
|
+
const run4 = await runAgentsSync(syncRoute, {
|
|
29976
30247
|
userAgent: cfg.ship.userAgent,
|
|
29977
30248
|
stateDir: cfg.ship.stateDir,
|
|
29978
30249
|
say: (l) => process.stderr.write(` ${l}
|
|
@@ -29987,19 +30258,19 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
|
|
|
29987
30258
|
if (p.state === "forbidden") process.stderr.write(` ${describeSeatForbidden(p.role, p.tables)}
|
|
29988
30259
|
`);
|
|
29989
30260
|
}
|
|
29990
|
-
if (
|
|
29991
|
-
const missing =
|
|
30261
|
+
if (run4.readOnly) {
|
|
30262
|
+
const missing = run4.personaResult.outcomes.some((p) => p.action === "missing");
|
|
29992
30263
|
process.stderr.write(missing ? " A workspace admin has to open the Crew app or run `crew agents sync` once before this ship's seats can run.\n" : " Seats are linked to the workspace's existing personas.\n");
|
|
29993
30264
|
}
|
|
29994
|
-
connectEvents.emit("agents_synced",
|
|
30265
|
+
connectEvents.emit("agents_synced", run4.readOnly ? "agents linked (read-only key)" : "agents synced", {
|
|
29995
30266
|
route: route3,
|
|
29996
|
-
admin: !
|
|
29997
|
-
personas:
|
|
29998
|
-
skills:
|
|
29999
|
-
diverged:
|
|
30267
|
+
admin: !run4.readOnly,
|
|
30268
|
+
personas: run4.personaResult.outcomes,
|
|
30269
|
+
skills: run4.skillResult?.outcomes ?? [],
|
|
30270
|
+
diverged: run4.diverged
|
|
30000
30271
|
});
|
|
30001
30272
|
for (const m of minted) connectEvents.emit("seat_key", describeMintOutcome(m), { route: route3, ...m });
|
|
30002
|
-
if (
|
|
30273
|
+
if (run4.diverged) process.exitCode = 1;
|
|
30003
30274
|
} catch (e) {
|
|
30004
30275
|
if (e instanceof AgentsSyncError || e instanceof SkillSyncError) skip(e.message);
|
|
30005
30276
|
else throw e;
|
|
@@ -30555,7 +30826,7 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
|
|
|
30555
30826
|
prepare: async (path) => {
|
|
30556
30827
|
for (const f of repoWt.config.worktrees.copy) {
|
|
30557
30828
|
const src = join57(repoWt.dir, f);
|
|
30558
|
-
if (!
|
|
30829
|
+
if (!existsSync54(src) || existsSync54(join57(path, f))) continue;
|
|
30559
30830
|
mkdirSync40(dirOf2(join57(path, f)), { recursive: true });
|
|
30560
30831
|
copyFileSync2(src, join57(path, f));
|
|
30561
30832
|
}
|
|
@@ -30778,7 +31049,7 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
|
|
|
30778
31049
|
const shellR = hit && resolveShell(hit.repo.config.shell ?? cfg.ship.shell);
|
|
30779
31050
|
const resumed = await runPeriscopeResume({
|
|
30780
31051
|
find: async () => hit && { row: hit.row, tag: hit.tag },
|
|
30781
|
-
worktreeExists: (p) =>
|
|
31052
|
+
worktreeExists: (p) => existsSync54(p),
|
|
30782
31053
|
prepareDropFile,
|
|
30783
31054
|
startProxy: (wt, url, n) => launchProxy(crewInvocation(CREW_HOME), wt, url, Number(n), { host: hit.row.host || "localhost", inject: hit.repo.config.periscope?.inspector !== "repo" }),
|
|
30784
31055
|
caps: periscopeCaps(cfg.ship),
|
|
@@ -30875,7 +31146,7 @@ ${where.join("\n")}`);
|
|
|
30875
31146
|
prepare: async (path) => {
|
|
30876
31147
|
for (const f of repoP.config.worktrees.copy) {
|
|
30877
31148
|
const src = join57(repoP.dir, f);
|
|
30878
|
-
if (!
|
|
31149
|
+
if (!existsSync54(src)) continue;
|
|
30879
31150
|
mkdirSync40(dirOf2(join57(path, f)), { recursive: true });
|
|
30880
31151
|
copyFileSync2(src, join57(path, f));
|
|
30881
31152
|
}
|
|
@@ -31378,7 +31649,7 @@ ${where.join("\n")}`);
|
|
|
31378
31649
|
}
|
|
31379
31650
|
if (row) {
|
|
31380
31651
|
await tracker.deleteRepoRow(row.id);
|
|
31381
|
-
if (
|
|
31652
|
+
if (existsSync54(resolvedFile)) {
|
|
31382
31653
|
const raw = JSON.parse(readFileSync48(resolvedFile, "utf8"));
|
|
31383
31654
|
if (raw.repoNames) delete raw.repoNames[row.id];
|
|
31384
31655
|
if (raw.repoRemotes) delete raw.repoRemotes[row.id];
|
|
@@ -31386,13 +31657,13 @@ ${where.join("\n")}`);
|
|
|
31386
31657
|
`);
|
|
31387
31658
|
}
|
|
31388
31659
|
}
|
|
31389
|
-
if (
|
|
31660
|
+
if (existsSync54(join57(dir, ".git")) && basename16(dir) === SAMPLE_REPO) rmSync25(dir, { recursive: true, force: true });
|
|
31390
31661
|
say("removed", { dir, closed }, `removed the sample repo${closed.length ? `, closed ${closed.join(", ")}` : ""}`);
|
|
31391
31662
|
break;
|
|
31392
31663
|
}
|
|
31393
31664
|
const projectId = route2.resolved.areaId ?? resolveRepoProject(await tracker.projectRows(), value("project"));
|
|
31394
|
-
const fresh = !
|
|
31395
|
-
if (
|
|
31665
|
+
const fresh = !existsSync54(join57(dir, ".git"));
|
|
31666
|
+
if (existsSync54(dir) && fresh && readdirSync20(dir).length > 0) fail2(`${dir} exists and is not a git checkout \u2014 move it aside`);
|
|
31396
31667
|
if (dryRun) {
|
|
31397
31668
|
say("dry-run", { dir, newCheckout: fresh, repoRow: row?.id ?? null }, `would ${fresh ? "create" : "reuse"} ${dir}${row ? "" : ", create the Repos row"}, and file one ${tracker.contract.statuses.approved} ticket`);
|
|
31398
31669
|
break;
|
|
@@ -31418,7 +31689,7 @@ ${where.join("\n")}`);
|
|
|
31418
31689
|
spec: { platform: "unix", releaseMode: "integrate", ciProvider: "none" }
|
|
31419
31690
|
});
|
|
31420
31691
|
repoId = (await tracker.createRepoRow(payload)).id;
|
|
31421
|
-
if (
|
|
31692
|
+
if (existsSync54(resolvedFile)) {
|
|
31422
31693
|
const raw = JSON.parse(readFileSync48(resolvedFile, "utf8"));
|
|
31423
31694
|
raw.repoNames = { ...raw.repoNames, [repoId]: SAMPLE_REPO };
|
|
31424
31695
|
raw.repoRemotes = { ...raw.repoRemotes, [repoId]: SAMPLE_REMOTE };
|
|
@@ -31774,7 +32045,7 @@ watermark: ${state.watermark()}
|
|
|
31774
32045
|
}
|
|
31775
32046
|
for (const r of repos) {
|
|
31776
32047
|
const remote = r.config.branch.remote;
|
|
31777
|
-
if (
|
|
32048
|
+
if (existsSync54(r.dir)) {
|
|
31778
32049
|
pushAuth.push({
|
|
31779
32050
|
route: c.route,
|
|
31780
32051
|
repo: r.name,
|
|
@@ -31847,7 +32118,7 @@ watermark: ${state.watermark()}
|
|
|
31847
32118
|
}
|
|
31848
32119
|
}
|
|
31849
32120
|
for (const message of roleCapWarnings(cfg.ship)) problems.push({ severity: "note", kind: "role_cap_above_ship_cap", message });
|
|
31850
|
-
const runtimeDir = runtimeDirWarning(process.platform, process.getuid?.() ?? null,
|
|
32121
|
+
const runtimeDir = runtimeDirWarning(process.platform, process.getuid?.() ?? null, existsSync54, userInfo2().username);
|
|
31851
32122
|
if (runtimeDir) problems.push({ severity: "attention", kind: "runtime_dir_missing", message: runtimeDir });
|
|
31852
32123
|
if (!flag("offline")) {
|
|
31853
32124
|
const shipKind = await doctorShipKind(route2, cfg.ship);
|
|
@@ -31912,7 +32183,7 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
|
|
|
31912
32183
|
}
|
|
31913
32184
|
try {
|
|
31914
32185
|
const evFile = eventFileFor(cfg.ship.stateDir);
|
|
31915
|
-
const evSize =
|
|
32186
|
+
const evSize = existsSync54(evFile) ? statSync17(evFile).size : 0;
|
|
31916
32187
|
process.stdout.write(
|
|
31917
32188
|
evSize > cfg.ship.eventsRotateBytes * 4 ? `events log: WARN ${evFile} is ${Math.round(evSize / 1048576)} MB (> 4x eventsRotateBytes); run \`crew reap\` to rotate it
|
|
31918
32189
|
` : "events log: ok\n"
|
|
@@ -31952,7 +32223,7 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
|
|
|
31952
32223
|
if (host === "linux" && detectSystemd()) {
|
|
31953
32224
|
const ctl = planDaemonControl(CREW_HOME, host, true);
|
|
31954
32225
|
const unitPlan = planInstall(cfg.ship, CREW_HOME, host, true, "run", installContext());
|
|
31955
|
-
if (ctl.statusCommand && unitPlan.unitPaths.some((p) =>
|
|
32226
|
+
if (ctl.statusCommand && unitPlan.unitPaths.some((p) => existsSync54(p))) {
|
|
31956
32227
|
const st = spawnSync12(ctl.statusCommand[0], ctl.statusCommand.slice(1), { cwd: CREW_HOME, encoding: "utf8" });
|
|
31957
32228
|
if (!st.error && st.status !== 0) {
|
|
31958
32229
|
process.stdout.write("daemon unit: WARN installed but not running \u2014 no work is picked up; run `crew reload` (or `crew daemon start`), and `crew install` if the unit still says Restart=on-failure\n");
|
|
@@ -31971,7 +32242,7 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
|
|
|
31971
32242
|
const changed2 = configChangedAfter(daemonConfigPaths(cfg), daemonStartedAt);
|
|
31972
32243
|
if (changed2) {
|
|
31973
32244
|
process.stdout.write(
|
|
31974
|
-
`daemon config: WARN ${changed2} changed at ${new Date(
|
|
32245
|
+
`daemon config: WARN ${changed2} changed at ${new Date(statSync17(changed2).mtimeMs).toISOString()} but the daemon started at ${new Date(daemonStartedAt).toISOString()} \u2014 run \`crew reload\`
|
|
31975
32246
|
`
|
|
31976
32247
|
);
|
|
31977
32248
|
}
|