@tablation/crew 0.143.4 → 0.145.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 +487 -352
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -6936,7 +6936,7 @@ import { promisify as promisify2 } from "util";
|
|
|
6936
6936
|
|
|
6937
6937
|
// src/deprovision-host.ts
|
|
6938
6938
|
import { spawnSync as spawnSync7 } from "child_process";
|
|
6939
|
-
import { existsSync as
|
|
6939
|
+
import { existsSync as existsSync33, readdirSync as readdirSync13 } from "fs";
|
|
6940
6940
|
|
|
6941
6941
|
// src/repo-env.ts
|
|
6942
6942
|
import { existsSync as existsSync19, mkdirSync as mkdirSync14, readFileSync as readFileSync20, renameSync as renameSync3, rmSync as rmSync10, writeFileSync as writeFileSync15 } from "fs";
|
|
@@ -14403,15 +14403,125 @@ async function reconcileRuns(o) {
|
|
|
14403
14403
|
}
|
|
14404
14404
|
|
|
14405
14405
|
// src/live-runs.ts
|
|
14406
|
-
import { existsSync as
|
|
14406
|
+
import { existsSync as existsSync32, readdirSync as readdirSync12, statSync as statSync11 } from "fs";
|
|
14407
|
+
import { join as join35 } from "path";
|
|
14408
|
+
|
|
14409
|
+
// src/run-snapshot.ts
|
|
14410
|
+
import { closeSync as closeSync5, existsSync as existsSync31, fstatSync, openSync as openSync5, readSync as readSync2, readdirSync as readdirSync11, statSync as statSync10, readFileSync as readFileSync32, writeFileSync as writeFileSync23, renameSync as renameSync5 } from "fs";
|
|
14407
14411
|
import { join as join34 } from "path";
|
|
14408
|
-
|
|
14412
|
+
var TAIL_BYTES = 256 * 1024;
|
|
14413
|
+
var EXCERPT_CHARS = 280;
|
|
14414
|
+
function endsWithQuestion(text2) {
|
|
14415
|
+
return /\?[\s"'”’)\]*_`]*$/.test(text2.trim());
|
|
14416
|
+
}
|
|
14417
|
+
function lastStreamEvent(streamPath) {
|
|
14418
|
+
let fd;
|
|
14419
|
+
try {
|
|
14420
|
+
fd = openSync5(streamPath, "r");
|
|
14421
|
+
} catch {
|
|
14422
|
+
return null;
|
|
14423
|
+
}
|
|
14424
|
+
try {
|
|
14425
|
+
const st = fstatSync(fd);
|
|
14426
|
+
const start = Math.max(0, st.size - TAIL_BYTES);
|
|
14427
|
+
const buf = Buffer.alloc(st.size - start);
|
|
14428
|
+
readSync2(fd, buf, 0, buf.length, start);
|
|
14429
|
+
const lines2 = buf.toString("utf8").split("\n");
|
|
14430
|
+
if (start > 0) lines2.shift();
|
|
14431
|
+
for (let i = lines2.length - 1; i >= 0; i--) {
|
|
14432
|
+
const line = lines2[i].trim();
|
|
14433
|
+
if (!line.startsWith("{")) continue;
|
|
14434
|
+
let parsed;
|
|
14435
|
+
try {
|
|
14436
|
+
parsed = JSON.parse(line);
|
|
14437
|
+
} catch {
|
|
14438
|
+
continue;
|
|
14439
|
+
}
|
|
14440
|
+
if (parsed.type !== "assistant" || !Array.isArray(parsed.message?.content)) continue;
|
|
14441
|
+
const blocks = parsed.message.content;
|
|
14442
|
+
for (let j = blocks.length - 1; j >= 0; j--) {
|
|
14443
|
+
const b = blocks[j];
|
|
14444
|
+
if (b.type !== "text" || !b.text?.trim()) continue;
|
|
14445
|
+
const text2 = b.text.replace(/\s+/g, " ").trim();
|
|
14446
|
+
return {
|
|
14447
|
+
text: text2.length > EXCERPT_CHARS ? `${text2.slice(0, EXCERPT_CHARS - 1)}\u2026` : text2,
|
|
14448
|
+
at: new Date(st.mtimeMs).toISOString(),
|
|
14449
|
+
question: endsWithQuestion(text2)
|
|
14450
|
+
};
|
|
14451
|
+
}
|
|
14452
|
+
}
|
|
14453
|
+
return null;
|
|
14454
|
+
} catch {
|
|
14455
|
+
return null;
|
|
14456
|
+
} finally {
|
|
14457
|
+
closeSync5(fd);
|
|
14458
|
+
}
|
|
14459
|
+
}
|
|
14460
|
+
function outcomeOf(m) {
|
|
14461
|
+
if (m.interrupted) return "interrupted";
|
|
14462
|
+
return m.exitCode === void 0 || m.exitCode === null || m.exitCode === 0 ? "ok" : "failed";
|
|
14463
|
+
}
|
|
14464
|
+
function lastRunsBySeat(stateDir) {
|
|
14409
14465
|
const dir = join34(stateDir, "streams");
|
|
14410
|
-
|
|
14411
|
-
|
|
14466
|
+
const out = /* @__PURE__ */ new Map();
|
|
14467
|
+
if (!existsSync31(dir)) return out;
|
|
14412
14468
|
for (const name of readdirSync11(dir)) {
|
|
14413
14469
|
if (!name.endsWith(".jsonl") || name.endsWith(".events.jsonl")) continue;
|
|
14414
14470
|
const streamPath = join34(dir, name);
|
|
14471
|
+
if (!runFinished(streamPath)) continue;
|
|
14472
|
+
const metaPath = `${streamPath}.meta.json`;
|
|
14473
|
+
let meta;
|
|
14474
|
+
let mtimeMs;
|
|
14475
|
+
try {
|
|
14476
|
+
meta = JSON.parse(readFileSync32(metaPath, "utf8"));
|
|
14477
|
+
mtimeMs = statSync10(metaPath).mtimeMs;
|
|
14478
|
+
} catch {
|
|
14479
|
+
continue;
|
|
14480
|
+
}
|
|
14481
|
+
if (!meta.route || !meta.role) continue;
|
|
14482
|
+
const key = `${meta.route}/${meta.role}`;
|
|
14483
|
+
const finishedAt = new Date(mtimeMs).toISOString();
|
|
14484
|
+
const have = out.get(key);
|
|
14485
|
+
if (have && have.finishedAt >= finishedAt) continue;
|
|
14486
|
+
out.set(key, {
|
|
14487
|
+
ticket: meta.ticket ?? null,
|
|
14488
|
+
startedAt: meta.startedAt ?? null,
|
|
14489
|
+
finishedAt,
|
|
14490
|
+
outcome: outcomeOf(meta),
|
|
14491
|
+
exitCode: meta.exitCode ?? null,
|
|
14492
|
+
route: meta.route,
|
|
14493
|
+
role: meta.role
|
|
14494
|
+
});
|
|
14495
|
+
}
|
|
14496
|
+
return out;
|
|
14497
|
+
}
|
|
14498
|
+
var notesPathFor = (streamPath) => `${streamPath}.notes.json`;
|
|
14499
|
+
function readRunNotes(streamPath) {
|
|
14500
|
+
try {
|
|
14501
|
+
const parsed = JSON.parse(readFileSync32(notesPathFor(streamPath), "utf8"));
|
|
14502
|
+
return Array.isArray(parsed) ? parsed : [];
|
|
14503
|
+
} catch {
|
|
14504
|
+
return [];
|
|
14505
|
+
}
|
|
14506
|
+
}
|
|
14507
|
+
function appendRunNote(streamPath, note) {
|
|
14508
|
+
try {
|
|
14509
|
+
const path = notesPathFor(streamPath);
|
|
14510
|
+
const tmp = `${path}.${process.pid}.tmp`;
|
|
14511
|
+
writeFileSync23(tmp, JSON.stringify([...readRunNotes(streamPath), note]));
|
|
14512
|
+
renameSync5(tmp, path);
|
|
14513
|
+
} catch {
|
|
14514
|
+
}
|
|
14515
|
+
}
|
|
14516
|
+
|
|
14517
|
+
// src/live-runs.ts
|
|
14518
|
+
function liveRuns(stateDir, isAlive = runIsAlive) {
|
|
14519
|
+
const dir = join35(stateDir, "streams");
|
|
14520
|
+
if (!existsSync32(dir)) return [];
|
|
14521
|
+
const out = [];
|
|
14522
|
+
for (const name of readdirSync12(dir)) {
|
|
14523
|
+
if (!name.endsWith(".jsonl") || name.endsWith(".events.jsonl")) continue;
|
|
14524
|
+
const streamPath = join35(dir, name);
|
|
14415
14525
|
if (runFinished(streamPath)) continue;
|
|
14416
14526
|
const sidecar = readRunSidecar(streamPath);
|
|
14417
14527
|
if (!sidecar || !isAlive(sidecar)) continue;
|
|
@@ -14421,15 +14531,15 @@ function liveRuns(stateDir, isAlive = runIsAlive) {
|
|
|
14421
14531
|
}
|
|
14422
14532
|
function runActivity(stateDir, isAlive = runIsAlive) {
|
|
14423
14533
|
const activeRuns = liveRuns(stateDir, isAlive).length;
|
|
14424
|
-
const dir =
|
|
14534
|
+
const dir = join35(stateDir, "streams");
|
|
14425
14535
|
let newest = 0;
|
|
14426
|
-
if (
|
|
14427
|
-
for (const name of
|
|
14536
|
+
if (existsSync32(dir)) {
|
|
14537
|
+
for (const name of readdirSync12(dir)) {
|
|
14428
14538
|
if (!name.endsWith(".jsonl") || name.endsWith(".events.jsonl")) continue;
|
|
14429
|
-
const streamPath =
|
|
14539
|
+
const streamPath = join35(dir, name);
|
|
14430
14540
|
if (!runFinished(streamPath)) continue;
|
|
14431
14541
|
try {
|
|
14432
|
-
newest = Math.max(newest,
|
|
14542
|
+
newest = Math.max(newest, statSync11(`${streamPath}.meta.json`).mtimeMs);
|
|
14433
14543
|
} catch {
|
|
14434
14544
|
}
|
|
14435
14545
|
}
|
|
@@ -14479,7 +14589,7 @@ function describeRun(run4, route2, seatIds, worktreeOf = (d, n) => {
|
|
|
14479
14589
|
} catch {
|
|
14480
14590
|
return null;
|
|
14481
14591
|
}
|
|
14482
|
-
}) {
|
|
14592
|
+
}, o = {}) {
|
|
14483
14593
|
const ownRoute = run4.route === routeSlug(route2.route);
|
|
14484
14594
|
const repoDir = run4.repo ? reposOf(route2).find((t) => t.name === run4.repo)?.dir : void 0;
|
|
14485
14595
|
const num2 = run4.ticket?.replace(/^\D+/, "") ?? "";
|
|
@@ -14496,7 +14606,18 @@ function describeRun(run4, route2, seatIds, worktreeOf = (d, n) => {
|
|
|
14496
14606
|
deadline: run4.deadline ?? null,
|
|
14497
14607
|
// CREW-3119: the harness still reads notes, and the process holding its stdin is alive.
|
|
14498
14608
|
acceptsInput: !!run4.acceptsInput && pidAlive2(run4.ownerPid),
|
|
14499
|
-
agentLogId: run4.agentLogRowId ?? null
|
|
14609
|
+
agentLogId: run4.agentLogRowId ?? null,
|
|
14610
|
+
// CREW-3247: the ticket's title, from the board (null when it could not be read).
|
|
14611
|
+
ticketTitle: run4.ticketRecordId ? o.titles?.get(run4.ticketRecordId) ?? null : null,
|
|
14612
|
+
// CREW-3247: this run's own latest text turn, so two runs of one role each have an excerpt.
|
|
14613
|
+
lastEvent: lastStreamEvent(run4.streamPath),
|
|
14614
|
+
// CREW-3247: a live run needs attention when it has outlived its wall-clock limit. A run that
|
|
14615
|
+
// failed is finished and reported on its seat's `lastRun` instead.
|
|
14616
|
+
// CREW-3248: operator notes sent to this run through the control API, kept past the pane that sent them.
|
|
14617
|
+
notes: readRunNotes(run4.streamPath),
|
|
14618
|
+
// CREW-3248: the serving periscope preview for this run's ticket, or null when it has none.
|
|
14619
|
+
previewUrl: run4.ticketRecordId ? o.previews?.get(run4.ticketRecordId) ?? null : null,
|
|
14620
|
+
attention: run4.deadline && Date.parse(run4.deadline) < (o.now ?? Date.now()) ? "past_deadline" : null
|
|
14500
14621
|
};
|
|
14501
14622
|
}
|
|
14502
14623
|
|
|
@@ -14532,7 +14653,7 @@ function realDeprovisionDeps(cfg, emit, crewHome, getStore) {
|
|
|
14532
14653
|
if (host === "windows") return [];
|
|
14533
14654
|
const ctx = installContext();
|
|
14534
14655
|
const systemd = detectSystemd();
|
|
14535
|
-
return ["run", "release", "passengers"].flatMap((job) => planInstall(cfg.ship, crewHome, host, systemd, job, ctx).unitPaths).filter((p) =>
|
|
14656
|
+
return ["run", "release", "passengers"].flatMap((job) => planInstall(cfg.ship, crewHome, host, systemd, job, ctx).unitPaths).filter((p) => existsSync33(p));
|
|
14536
14657
|
};
|
|
14537
14658
|
return {
|
|
14538
14659
|
liveRuns: () => liveRuns(stateDir).map((r) => ({ role: r.role, route: r.route, pid: r.pid, ticketRecordId: r.ticketRecordId ?? void 0, streamPath: r.streamPath })),
|
|
@@ -14600,11 +14721,11 @@ function realDeprovisionDeps(cfg, emit, crewHome, getStore) {
|
|
|
14600
14721
|
},
|
|
14601
14722
|
remaining() {
|
|
14602
14723
|
const left = [];
|
|
14603
|
-
if (
|
|
14724
|
+
if (existsSync33(cfg.configFile)) left.push(`config ${cfg.configFile}`);
|
|
14604
14725
|
for (const h of forgeHosts()) if (hasForgeToken(cfg.ship.forges, h, stateDir)) left.push(`forge token for ${h}`);
|
|
14605
14726
|
if (hasRepositoryEnv(stateDir)) left.push("repository environment");
|
|
14606
14727
|
try {
|
|
14607
|
-
for (const k of
|
|
14728
|
+
for (const k of readdirSync13(keysDir(stateDir))) left.push(`seat key ${k}`);
|
|
14608
14729
|
} catch {
|
|
14609
14730
|
}
|
|
14610
14731
|
for (const s of sandboxes()) left.push(`sandbox ${s}`);
|
|
@@ -15425,9 +15546,9 @@ function managedGitIdentityWarnings(kind, identity) {
|
|
|
15425
15546
|
|
|
15426
15547
|
// src/selftest.ts
|
|
15427
15548
|
import { spawn as spawn7 } from "child_process";
|
|
15428
|
-
import { existsSync as
|
|
15549
|
+
import { existsSync as existsSync34, mkdirSync as mkdirSync22, mkdtempSync as mkdtempSync2, readFileSync as readFileSync33, rmSync as rmSync17, writeFileSync as writeFileSync24 } from "fs";
|
|
15429
15550
|
import { tmpdir as tmpdir5 } from "os";
|
|
15430
|
-
import { join as
|
|
15551
|
+
import { join as join36 } from "path";
|
|
15431
15552
|
var SELFTEST_TIMEOUT_MS = 12e4;
|
|
15432
15553
|
var KEY_VAR = "CREW_API_KEY";
|
|
15433
15554
|
var SELFTEST_PROMPT = "This is a read-only connectivity check. Use the tracker MCP tool to read this workspace (the workspaces find-one tool, using the workspace id below) and reply with the workspace's name alone, on one line. Do not write anything, do not create files, and do not use any other tool.\n\nWorkspace id: ";
|
|
@@ -15593,7 +15714,7 @@ async function runSelftest(i, deps = realDeps) {
|
|
|
15593
15714
|
...adapter.runEnv(spec),
|
|
15594
15715
|
[KEY_VAR]: i.apiKey
|
|
15595
15716
|
};
|
|
15596
|
-
const cwd = mkdtempSync2(
|
|
15717
|
+
const cwd = mkdtempSync2(join36(tmpdir5(), "crew-selftest-"));
|
|
15597
15718
|
try {
|
|
15598
15719
|
const run4 = await deps.run({
|
|
15599
15720
|
bin: invocation.bin,
|
|
@@ -15626,11 +15747,11 @@ function formatResult(r) {
|
|
|
15626
15747
|
const secs = `${(r.ms / 1e3).toFixed(1)}s`;
|
|
15627
15748
|
return r.ok ? `${r.toolchain}: PASS ${r.detail} (${secs}${tok})` : `${r.toolchain}: FAIL ${r.failure} \u2014 ${r.detail} (${secs})`;
|
|
15628
15749
|
}
|
|
15629
|
-
var fileFor2 = (stateDir) =>
|
|
15750
|
+
var fileFor2 = (stateDir) => join36(stateDir, "selftest.json");
|
|
15630
15751
|
function readSelftest(stateDir) {
|
|
15631
15752
|
try {
|
|
15632
15753
|
const p = fileFor2(stateDir);
|
|
15633
|
-
return
|
|
15754
|
+
return existsSync34(p) ? JSON.parse(readFileSync33(p, "utf8")) : {};
|
|
15634
15755
|
} catch {
|
|
15635
15756
|
return {};
|
|
15636
15757
|
}
|
|
@@ -15639,7 +15760,7 @@ function recordSelftest(stateDir, results) {
|
|
|
15639
15760
|
const all = readSelftest(stateDir);
|
|
15640
15761
|
for (const r of results) all[r.toolchain] = r;
|
|
15641
15762
|
mkdirSync22(stateDir, { recursive: true });
|
|
15642
|
-
|
|
15763
|
+
writeFileSync24(fileFor2(stateDir), `${JSON.stringify(all, null, 2)}
|
|
15643
15764
|
`);
|
|
15644
15765
|
}
|
|
15645
15766
|
function doctorSelftestLines(stored, toolchains) {
|
|
@@ -15651,7 +15772,7 @@ function doctorSelftestLines(stored, toolchains) {
|
|
|
15651
15772
|
}
|
|
15652
15773
|
|
|
15653
15774
|
// src/cli.ts
|
|
15654
|
-
import { resolve as resolve7, dirname as dirname37, join as
|
|
15775
|
+
import { resolve as resolve7, dirname as dirname37, join as join63, basename as basename17 } from "path";
|
|
15655
15776
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
15656
15777
|
import { hostname as hostname5, homedir as homedir11, userInfo as userInfo2 } from "os";
|
|
15657
15778
|
import { spawnSync as spawnSync14 } from "child_process";
|
|
@@ -15860,14 +15981,14 @@ function rosterMarkdown(roster, meId) {
|
|
|
15860
15981
|
}
|
|
15861
15982
|
|
|
15862
15983
|
// src/connect-resume.ts
|
|
15863
|
-
import { mkdirSync as mkdirSync23, readFileSync as
|
|
15864
|
-
import { dirname as dirname17, join as
|
|
15984
|
+
import { mkdirSync as mkdirSync23, readFileSync as readFileSync34, rmSync as rmSync18, writeFileSync as writeFileSync25 } from "fs";
|
|
15985
|
+
import { dirname as dirname17, join as join37 } from "path";
|
|
15865
15986
|
function lastSessionFile(stateDir) {
|
|
15866
|
-
return
|
|
15987
|
+
return join37(stateDir, "connect-session.json");
|
|
15867
15988
|
}
|
|
15868
15989
|
function readPointers(stateDir) {
|
|
15869
15990
|
try {
|
|
15870
|
-
const parsed = JSON.parse(
|
|
15991
|
+
const parsed = JSON.parse(readFileSync34(lastSessionFile(stateDir), "utf8"));
|
|
15871
15992
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return {};
|
|
15872
15993
|
const out = {};
|
|
15873
15994
|
for (const [host, v] of Object.entries(parsed)) {
|
|
@@ -15882,7 +16003,7 @@ function readPointers(stateDir) {
|
|
|
15882
16003
|
function writePointers(stateDir, pointers) {
|
|
15883
16004
|
const file = lastSessionFile(stateDir);
|
|
15884
16005
|
mkdirSync23(dirname17(file), { recursive: true });
|
|
15885
|
-
|
|
16006
|
+
writeFileSync25(file, `${JSON.stringify(pointers, null, 2)}
|
|
15886
16007
|
`, { mode: 384 });
|
|
15887
16008
|
}
|
|
15888
16009
|
function rememberSession(stateDir, host, workspaceSlug) {
|
|
@@ -15967,15 +16088,15 @@ async function signOutSessions(o) {
|
|
|
15967
16088
|
}
|
|
15968
16089
|
|
|
15969
16090
|
// src/reset.ts
|
|
15970
|
-
import { existsSync as
|
|
15971
|
-
import { dirname as dirname18, join as
|
|
16091
|
+
import { existsSync as existsSync35, mkdirSync as mkdirSync24, readFileSync as readFileSync35, readdirSync as readdirSync14, rmSync as rmSync19, statSync as statSync12, writeFileSync as writeFileSync26 } from "fs";
|
|
16092
|
+
import { dirname as dirname18, join as join38 } from "path";
|
|
15972
16093
|
import { hostFromUrl as hostFromUrl3 } from "@tablation/client";
|
|
15973
16094
|
function clonedCheckoutsFile(stateDir) {
|
|
15974
|
-
return
|
|
16095
|
+
return join38(stateDir, "cloned-checkouts.json");
|
|
15975
16096
|
}
|
|
15976
16097
|
function readClonedCheckouts(stateDir) {
|
|
15977
16098
|
try {
|
|
15978
|
-
const parsed = JSON.parse(
|
|
16099
|
+
const parsed = JSON.parse(readFileSync35(clonedCheckoutsFile(stateDir), "utf8"));
|
|
15979
16100
|
return Array.isArray(parsed) ? parsed.filter((d) => typeof d === "string") : [];
|
|
15980
16101
|
} catch {
|
|
15981
16102
|
return [];
|
|
@@ -15986,7 +16107,7 @@ function recordClonedCheckout(stateDir, dir) {
|
|
|
15986
16107
|
if (known.includes(dir)) return;
|
|
15987
16108
|
const file = clonedCheckoutsFile(stateDir);
|
|
15988
16109
|
mkdirSync24(dirname18(file), { recursive: true });
|
|
15989
|
-
|
|
16110
|
+
writeFileSync26(file, `${JSON.stringify([...known, dir], null, 2)}
|
|
15990
16111
|
`);
|
|
15991
16112
|
}
|
|
15992
16113
|
var mark = (dryRun) => dryRun ? "would-remove" : "removed";
|
|
@@ -16040,7 +16161,7 @@ async function runReset(o, fx) {
|
|
|
16040
16161
|
}
|
|
16041
16162
|
if (o.beforeState) steps.push(...await o.beforeState());
|
|
16042
16163
|
steps.push(...o.wipeState ? wipeStateDir(o.stateDir, o.dryRun) : removeState(o.stateDir, o.dryRun));
|
|
16043
|
-
if (
|
|
16164
|
+
if (existsSync35(o.configFile)) {
|
|
16044
16165
|
if (!o.dryRun) rmSync19(o.configFile, { force: true });
|
|
16045
16166
|
steps.push({ step: "config", target: o.configFile, action: mark(o.dryRun) });
|
|
16046
16167
|
} else {
|
|
@@ -16049,7 +16170,7 @@ async function runReset(o, fx) {
|
|
|
16049
16170
|
return steps;
|
|
16050
16171
|
}
|
|
16051
16172
|
function removeCheckout(dir, dryRun, fx) {
|
|
16052
|
-
if (!
|
|
16173
|
+
if (!existsSync35(dir)) return { step: "checkout", target: dir, action: "absent", detail: "already gone" };
|
|
16053
16174
|
const { dirty, linkedWorktrees } = fx.inspectCheckout(dir);
|
|
16054
16175
|
if (dirty.length) {
|
|
16055
16176
|
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" : ""})` };
|
|
@@ -16062,15 +16183,15 @@ function removeCheckout(dir, dryRun, fx) {
|
|
|
16062
16183
|
}
|
|
16063
16184
|
function removeState(stateDir, dryRun) {
|
|
16064
16185
|
const out = [];
|
|
16065
|
-
const targets = [
|
|
16186
|
+
const targets = [join38(stateDir, "resolved"), join38(stateDir, "keys"), clonedCheckoutsFile(stateDir), join38(stateDir, "connect-session.json"), join38(stateDir, "reload-requested"), join38(stateDir, "daemon.started")];
|
|
16066
16187
|
try {
|
|
16067
|
-
for (const name of
|
|
16068
|
-
if (name.startsWith(".") &&
|
|
16188
|
+
for (const name of readdirSync14(stateDir)) {
|
|
16189
|
+
if (name.startsWith(".") && statSync12(join38(stateDir, name)).isFile()) targets.push(join38(stateDir, name));
|
|
16069
16190
|
}
|
|
16070
16191
|
} catch {
|
|
16071
16192
|
}
|
|
16072
16193
|
for (const t of targets) {
|
|
16073
|
-
if (!
|
|
16194
|
+
if (!existsSync35(t)) continue;
|
|
16074
16195
|
if (!dryRun) rmSync19(t, { recursive: true, force: true });
|
|
16075
16196
|
out.push({ step: "state", target: t, action: mark(dryRun) });
|
|
16076
16197
|
}
|
|
@@ -16080,12 +16201,12 @@ function removeState(stateDir, dryRun) {
|
|
|
16080
16201
|
function wipeStateDir(stateDir, dryRun) {
|
|
16081
16202
|
let names;
|
|
16082
16203
|
try {
|
|
16083
|
-
names =
|
|
16204
|
+
names = readdirSync14(stateDir);
|
|
16084
16205
|
} catch {
|
|
16085
16206
|
return [{ step: "state", target: stateDir, action: "absent", detail: "no state directory" }];
|
|
16086
16207
|
}
|
|
16087
16208
|
if (!names.length) return [{ step: "state", target: stateDir, action: "absent", detail: "already empty" }];
|
|
16088
|
-
if (!dryRun) for (const n of names) rmSync19(
|
|
16209
|
+
if (!dryRun) for (const n of names) rmSync19(join38(stateDir, n), { recursive: true, force: true });
|
|
16089
16210
|
return [{ step: "state", target: stateDir, action: mark(dryRun), detail: `${names.length} entr${names.length === 1 ? "y" : "ies"}` }];
|
|
16090
16211
|
}
|
|
16091
16212
|
function describeResetStep(s) {
|
|
@@ -16167,9 +16288,9 @@ async function runDeprovision(o, fx, deps) {
|
|
|
16167
16288
|
}
|
|
16168
16289
|
|
|
16169
16290
|
// src/pool-member.ts
|
|
16170
|
-
import { mkdirSync as mkdirSync25, readFileSync as
|
|
16291
|
+
import { mkdirSync as mkdirSync25, readFileSync as readFileSync36, renameSync as renameSync6, writeFileSync as writeFileSync27 } from "fs";
|
|
16171
16292
|
import { homedir as homedir8 } from "os";
|
|
16172
|
-
import { dirname as dirname19, join as
|
|
16293
|
+
import { dirname as dirname19, join as join39 } from "path";
|
|
16173
16294
|
var POOL_EXIT = { ok: 0, failed: 1, credential: 2 };
|
|
16174
16295
|
function backoffMs(attempt) {
|
|
16175
16296
|
return Math.min(6e4, 5e3 * 2 ** Math.max(0, attempt));
|
|
@@ -16411,14 +16532,14 @@ async function runPoolMember(deps) {
|
|
|
16411
16532
|
}
|
|
16412
16533
|
}
|
|
16413
16534
|
function defaultMemberDir(env = process.env) {
|
|
16414
|
-
return env.CREW_POOL_DIR ??
|
|
16535
|
+
return env.CREW_POOL_DIR ?? join39(env.XDG_STATE_HOME ?? join39(homedir8(), ".local", "state"), "crew-pool-member");
|
|
16415
16536
|
}
|
|
16416
16537
|
function fileMemberStore(dir) {
|
|
16417
|
-
const file =
|
|
16538
|
+
const file = join39(dir, "member.json");
|
|
16418
16539
|
return {
|
|
16419
16540
|
read() {
|
|
16420
16541
|
try {
|
|
16421
|
-
return JSON.parse(
|
|
16542
|
+
return JSON.parse(readFileSync36(file, "utf8"));
|
|
16422
16543
|
} catch {
|
|
16423
16544
|
return {};
|
|
16424
16545
|
}
|
|
@@ -16426,9 +16547,9 @@ function fileMemberStore(dir) {
|
|
|
16426
16547
|
write(f) {
|
|
16427
16548
|
mkdirSync25(dirname19(file), { recursive: true, mode: 448 });
|
|
16428
16549
|
const tmp = `${file}.tmp`;
|
|
16429
|
-
|
|
16550
|
+
writeFileSync27(tmp, `${JSON.stringify(f)}
|
|
16430
16551
|
`, { mode: 384 });
|
|
16431
|
-
|
|
16552
|
+
renameSync6(tmp, file);
|
|
16432
16553
|
}
|
|
16433
16554
|
};
|
|
16434
16555
|
}
|
|
@@ -16478,16 +16599,16 @@ function hostArchitecture(arch = process.arch) {
|
|
|
16478
16599
|
|
|
16479
16600
|
// src/pool-member-host.ts
|
|
16480
16601
|
import "child_process";
|
|
16481
|
-
import { existsSync as
|
|
16602
|
+
import { existsSync as existsSync38 } from "fs";
|
|
16482
16603
|
import { hostname as hostname3 } from "os";
|
|
16483
16604
|
|
|
16484
16605
|
// src/machine-id.ts
|
|
16485
16606
|
import { execFileSync as execFileSync12 } from "child_process";
|
|
16486
16607
|
import { createHash as createHash8 } from "crypto";
|
|
16487
|
-
import { existsSync as
|
|
16488
|
-
import { dirname as dirname20, join as
|
|
16608
|
+
import { existsSync as existsSync36, mkdirSync as mkdirSync26, readFileSync as readFileSync37, writeFileSync as writeFileSync28 } from "fs";
|
|
16609
|
+
import { dirname as dirname20, join as join40 } from "path";
|
|
16489
16610
|
function machineIdPathFor(stateDir) {
|
|
16490
|
-
return
|
|
16611
|
+
return join40(stateDir, "machine-id");
|
|
16491
16612
|
}
|
|
16492
16613
|
var sha256 = (s) => createHash8("sha256").update(s).digest("hex");
|
|
16493
16614
|
function readRawMachineId(platform2 = process.platform) {
|
|
@@ -16500,8 +16621,8 @@ function readRawMachineId(platform2 = process.platform) {
|
|
|
16500
16621
|
return /"IOPlatformUUID"\s*=\s*"([^"]+)"/.exec(out)?.[1];
|
|
16501
16622
|
}
|
|
16502
16623
|
for (const p of ["/etc/machine-id", "/var/lib/dbus/machine-id"]) {
|
|
16503
|
-
if (
|
|
16504
|
-
const id =
|
|
16624
|
+
if (existsSync36(p)) {
|
|
16625
|
+
const id = readFileSync37(p, "utf8").trim();
|
|
16505
16626
|
if (id) return id;
|
|
16506
16627
|
}
|
|
16507
16628
|
}
|
|
@@ -16512,15 +16633,15 @@ function readRawMachineId(platform2 = process.platform) {
|
|
|
16512
16633
|
function ensureMachineId(stateDir, opts = {}) {
|
|
16513
16634
|
if (opts.override?.trim()) return sha256(opts.override.trim());
|
|
16514
16635
|
const path = machineIdPathFor(stateDir);
|
|
16515
|
-
if (
|
|
16516
|
-
const cached =
|
|
16636
|
+
if (existsSync36(path)) {
|
|
16637
|
+
const cached = readFileSync37(path, "utf8").trim();
|
|
16517
16638
|
if (/^[0-9a-f]{64}$/.test(cached)) return cached;
|
|
16518
16639
|
}
|
|
16519
16640
|
const raw = (opts.read ?? readRawMachineId)();
|
|
16520
16641
|
if (!raw) return void 0;
|
|
16521
16642
|
const hashed = sha256(raw);
|
|
16522
16643
|
mkdirSync26(dirname20(path), { recursive: true });
|
|
16523
|
-
|
|
16644
|
+
writeFileSync28(path, `${hashed}
|
|
16524
16645
|
`, { mode: 384 });
|
|
16525
16646
|
return hashed;
|
|
16526
16647
|
}
|
|
@@ -16533,7 +16654,7 @@ function matchShipRows(ships, shipName2, machineId) {
|
|
|
16533
16654
|
|
|
16534
16655
|
// src/provision.ts
|
|
16535
16656
|
import { spawnSync as spawnSync9 } from "child_process";
|
|
16536
|
-
import { existsSync as
|
|
16657
|
+
import { existsSync as existsSync37, readFileSync as readFileSync38, writeFileSync as writeFileSync29 } from "fs";
|
|
16537
16658
|
import { hostname as hostname2 } from "os";
|
|
16538
16659
|
import { parseDocument as parseDocument3, isMap as isMap2, isScalar } from "yaml";
|
|
16539
16660
|
|
|
@@ -16542,7 +16663,7 @@ import { parseDocument as parseDocument2 } from "yaml";
|
|
|
16542
16663
|
|
|
16543
16664
|
// src/repos-cmd.ts
|
|
16544
16665
|
import { homedir as homedir9 } from "os";
|
|
16545
|
-
import { basename as basename10, join as
|
|
16666
|
+
import { basename as basename10, join as join41, resolve as resolve4 } from "path";
|
|
16546
16667
|
import { isMap, isSeq, parseDocument, stringify as stringify2 } from "yaml";
|
|
16547
16668
|
var ReposError = class extends Error {
|
|
16548
16669
|
};
|
|
@@ -16820,7 +16941,7 @@ function planRepoClone(i) {
|
|
|
16820
16941
|
}
|
|
16821
16942
|
const ship = doc.get("ship", true);
|
|
16822
16943
|
const basePath = String(m.get("reposBasePath") ?? (isMap(ship) ? ship.get("reposBasePath") : void 0) ?? "~/Crew");
|
|
16823
|
-
const target = i.dir ? expandDir(i.dir, i.base) :
|
|
16944
|
+
const target = i.dir ? expandDir(i.dir, i.base) : join41(expandDir(basePath, i.base), i.route.split("/")[0], name);
|
|
16824
16945
|
const add = planRepoAdd({ text: i.text, base: i.base, route: i.route, path: target, origin: remote, resolved: i.resolved, name, isCheckout: i.isCheckout });
|
|
16825
16946
|
const forgeHost = i.resolved?.repoForgeHosts?.[id];
|
|
16826
16947
|
return { ...add, remote, target, ...forgeHost ? { forgeHost } : {} };
|
|
@@ -17151,7 +17272,7 @@ function realProvisionDeps(crewHome) {
|
|
|
17151
17272
|
};
|
|
17152
17273
|
const configFile = () => {
|
|
17153
17274
|
const f = findConfigFile(crewHome);
|
|
17154
|
-
return
|
|
17275
|
+
return existsSync37(f) ? f : null;
|
|
17155
17276
|
};
|
|
17156
17277
|
return {
|
|
17157
17278
|
crew: spawnCrew,
|
|
@@ -17159,13 +17280,13 @@ function realProvisionDeps(crewHome) {
|
|
|
17159
17280
|
enableRoute(route2) {
|
|
17160
17281
|
const file = configFile();
|
|
17161
17282
|
if (!file) return false;
|
|
17162
|
-
const text2 =
|
|
17283
|
+
const text2 = readFileSync38(file, "utf8");
|
|
17163
17284
|
const doc = parseDocument3(text2);
|
|
17164
17285
|
const routes = doc.get("routes");
|
|
17165
17286
|
const entry = routes?.items?.find((r) => r.get("route") === route2);
|
|
17166
17287
|
if (!entry) throw new Error(`route ${route2} is not in ${file}`);
|
|
17167
17288
|
if (entry.get("enabled") === true) return false;
|
|
17168
|
-
|
|
17289
|
+
writeFileSync29(file, planEnable(text2, route2));
|
|
17169
17290
|
return true;
|
|
17170
17291
|
},
|
|
17171
17292
|
installState() {
|
|
@@ -17185,14 +17306,14 @@ function realProvisionDeps(crewHome) {
|
|
|
17185
17306
|
continue;
|
|
17186
17307
|
}
|
|
17187
17308
|
for (const p of plan.unitPaths) {
|
|
17188
|
-
if (!
|
|
17309
|
+
if (!existsSync37(p) || readFileSync38(p, "utf8") !== plan.unitContent[p]) unitsStale = true;
|
|
17189
17310
|
}
|
|
17190
17311
|
}
|
|
17191
17312
|
const label = labelFor(crewHome, "run");
|
|
17192
17313
|
let running = false;
|
|
17193
17314
|
let lingering = true;
|
|
17194
17315
|
if (mechanism === "systemd") {
|
|
17195
|
-
const system = ctx.root ||
|
|
17316
|
+
const system = ctx.root || existsSync37(systemUnitPathFor(label));
|
|
17196
17317
|
const ctl = system ? ["systemctl"] : ["systemctl", "--user"];
|
|
17197
17318
|
running = spawnSync9(ctl[0], [...ctl.slice(1), "is-active", "--quiet", `${label}.service`], { env: withUserBusEnv() }).status === 0;
|
|
17198
17319
|
if (!system) {
|
|
@@ -17209,18 +17330,18 @@ function realProvisionDeps(crewHome) {
|
|
|
17209
17330
|
setShipSetting(key, value2) {
|
|
17210
17331
|
const file = configFile();
|
|
17211
17332
|
if (!file) return false;
|
|
17212
|
-
const doc = parseDocument3(
|
|
17333
|
+
const doc = parseDocument3(readFileSync38(file, "utf8"));
|
|
17213
17334
|
if (doc.getIn(["ship", key]) === value2) return false;
|
|
17214
17335
|
doc.setIn(["ship", key], value2);
|
|
17215
|
-
|
|
17336
|
+
writeFileSync29(file, doc.toString());
|
|
17216
17337
|
return true;
|
|
17217
17338
|
},
|
|
17218
17339
|
applyManagedDefaults() {
|
|
17219
17340
|
const file = configFile();
|
|
17220
17341
|
if (!file) return [];
|
|
17221
|
-
const doc = parseDocument3(
|
|
17342
|
+
const doc = parseDocument3(readFileSync38(file, "utf8"));
|
|
17222
17343
|
const wrote = applyManagedDefaultsToDoc(doc);
|
|
17223
|
-
if (wrote.length)
|
|
17344
|
+
if (wrote.length) writeFileSync29(file, doc.toString());
|
|
17224
17345
|
return wrote;
|
|
17225
17346
|
},
|
|
17226
17347
|
ensureGitIdentity(name, email) {
|
|
@@ -17270,7 +17391,7 @@ function realPoolMemberDeps(o) {
|
|
|
17270
17391
|
crewVersion: crewVersion(o.crewHome),
|
|
17271
17392
|
hostname: hostname3()
|
|
17272
17393
|
},
|
|
17273
|
-
hasShipConfig: () =>
|
|
17394
|
+
hasShipConfig: () => existsSync38(findConfigFile(o.crewHome)),
|
|
17274
17395
|
async provision(lease, instanceClass, shipKind) {
|
|
17275
17396
|
const hosts = lease.forges.map((f) => f.host.toLowerCase());
|
|
17276
17397
|
const lines2 = [];
|
|
@@ -18194,7 +18315,7 @@ ${waiting.map((t) => `| ${displayKey2(t)} | ${t.status} | ${blockers(t, i)} |`).
|
|
|
18194
18315
|
|
|
18195
18316
|
// src/sandbox-hygiene.ts
|
|
18196
18317
|
import { execFile as execFile3 } from "child_process";
|
|
18197
|
-
import { existsSync as
|
|
18318
|
+
import { existsSync as existsSync39, statfsSync as statfsSync2 } from "fs";
|
|
18198
18319
|
import { promisify as promisify3 } from "util";
|
|
18199
18320
|
var execFileP3 = promisify3(execFile3);
|
|
18200
18321
|
var REAP_MIN_AGE_MS = 5 * 6e4;
|
|
@@ -18337,7 +18458,7 @@ async function realDiskReadings(ship) {
|
|
|
18337
18458
|
const paths = ["/"];
|
|
18338
18459
|
try {
|
|
18339
18460
|
const root = (await run3(ship.sandbox?.engine ?? DEFAULT_CACHE_SETTINGS.engine, ["info", "--format", "{{.DockerRootDir}}"])).trim();
|
|
18340
|
-
if (root &&
|
|
18461
|
+
if (root && existsSync39(root)) paths.push(root);
|
|
18341
18462
|
} catch {
|
|
18342
18463
|
}
|
|
18343
18464
|
return paths.flatMap((path) => {
|
|
@@ -18378,8 +18499,8 @@ function diskFullStop(state) {
|
|
|
18378
18499
|
}
|
|
18379
18500
|
|
|
18380
18501
|
// src/poll.ts
|
|
18381
|
-
import { writeFileSync as
|
|
18382
|
-
import { join as
|
|
18502
|
+
import { writeFileSync as writeFileSync30 } from "fs";
|
|
18503
|
+
import { join as join42 } from "path";
|
|
18383
18504
|
|
|
18384
18505
|
// src/stalled.ts
|
|
18385
18506
|
var STALLED_AFTER_CYCLES = 30;
|
|
@@ -18695,7 +18816,7 @@ async function decideCycle(o) {
|
|
|
18695
18816
|
}
|
|
18696
18817
|
return decision;
|
|
18697
18818
|
}
|
|
18698
|
-
var digestPath = (stateDir, route2, role, runId) =>
|
|
18819
|
+
var digestPath = (stateDir, route2, role, runId) => join42(stateDir, `digest-${route2}-${role}${runId ? `-${runId}` : ""}.md`);
|
|
18699
18820
|
function otherRunsRemoved(tickets, own) {
|
|
18700
18821
|
if (!own) return tickets;
|
|
18701
18822
|
return tickets.filter((t) => t.id === own.ticket.id || !own.inFlight(t.id));
|
|
@@ -18781,7 +18902,7 @@ function writeDigest(o, d, role, stateDir, runId, own) {
|
|
|
18781
18902
|
|
|
18782
18903
|
${body}` : body;
|
|
18783
18904
|
const path = digestPath(stateDir, routeSlug(o.route.route), role, runId);
|
|
18784
|
-
|
|
18905
|
+
writeFileSync30(path, text2);
|
|
18785
18906
|
o.emit.emit(`queue digest written for ${role} (${Buffer.byteLength(text2)} bytes)`, {
|
|
18786
18907
|
data: { role, bytes: Buffer.byteLength(text2) }
|
|
18787
18908
|
});
|
|
@@ -18904,7 +19025,7 @@ async function claimStillHeld(tracker, t, buildingStatus, affinity) {
|
|
|
18904
19025
|
}
|
|
18905
19026
|
|
|
18906
19027
|
// src/repo-refresh.ts
|
|
18907
|
-
import { existsSync as
|
|
19028
|
+
import { existsSync as existsSync40, mkdirSync as mkdirSync27, readFileSync as readFileSync39, writeFileSync as writeFileSync31 } from "fs";
|
|
18908
19029
|
import { dirname as dirname22 } from "path";
|
|
18909
19030
|
var REFRESH_COOLDOWN_MS = 2 * 6e4;
|
|
18910
19031
|
var UNSERVABLE_PASSES_BEFORE_ATTENTION = 3;
|
|
@@ -18934,11 +19055,11 @@ function applyRepoRows(resolved, rows) {
|
|
|
18934
19055
|
}
|
|
18935
19056
|
function persistRepoRows(stateDir, routeName, rows) {
|
|
18936
19057
|
const path = resolvedPathFor(stateDir, routeName);
|
|
18937
|
-
if (!
|
|
18938
|
-
const raw = JSON.parse(
|
|
19058
|
+
if (!existsSync40(path)) return;
|
|
19059
|
+
const raw = JSON.parse(readFileSync39(path, "utf8"));
|
|
18939
19060
|
applyRepoRows(raw, rows);
|
|
18940
19061
|
mkdirSync27(dirname22(path), { recursive: true });
|
|
18941
|
-
|
|
19062
|
+
writeFileSync31(path, `${JSON.stringify(raw, null, 2)}
|
|
18942
19063
|
`);
|
|
18943
19064
|
}
|
|
18944
19065
|
async function refreshUnknownRepos(o) {
|
|
@@ -19414,7 +19535,7 @@ Ship ${shipName2} found: ${problem}. The release refuses to squash a ref nobody
|
|
|
19414
19535
|
var localRefSkipReported = (ticket, problem, events) => events.some((e) => e.record_id === ticket.id && e.event_type === "local_ref_skip" && (e.message ?? "").includes(problem));
|
|
19415
19536
|
|
|
19416
19537
|
// src/platform-gate.ts
|
|
19417
|
-
import { join as
|
|
19538
|
+
import { join as join43 } from "path";
|
|
19418
19539
|
function platformAdmitters(dir, baseRef, ship, tickets, locate) {
|
|
19419
19540
|
const out = [];
|
|
19420
19541
|
for (const t of tickets) {
|
|
@@ -19426,7 +19547,7 @@ function platformAdmitters(dir, baseRef, ship, tickets, locate) {
|
|
|
19426
19547
|
const text2 = gitOk(dir, ["show", `${branch}:${file}`]);
|
|
19427
19548
|
if (text2 === null) continue;
|
|
19428
19549
|
try {
|
|
19429
|
-
const { platform: platform2 } = parseRepoConfig(text2,
|
|
19550
|
+
const { platform: platform2 } = parseRepoConfig(text2, join43(dir, file));
|
|
19430
19551
|
if (satisfies(ship, platform2)) out.push({ issueId: t.issue_id, branch, platform: platform2 });
|
|
19431
19552
|
} catch (e) {
|
|
19432
19553
|
if (e instanceof RepoConfigError) continue;
|
|
@@ -19442,13 +19563,13 @@ function platformStuckNote(repo, required, ship, issueIds) {
|
|
|
19442
19563
|
}
|
|
19443
19564
|
|
|
19444
19565
|
// src/connect-wizard.ts
|
|
19445
|
-
import { delimiter, dirname as dirname23, join as
|
|
19446
|
-
import { accessSync as accessSync3, constants as constants3, existsSync as
|
|
19566
|
+
import { delimiter, dirname as dirname23, join as join44 } from "path";
|
|
19567
|
+
import { accessSync as accessSync3, constants as constants3, existsSync as existsSync41, mkdirSync as mkdirSync28, writeFileSync as writeFileSync32 } from "fs";
|
|
19447
19568
|
import { stringify as stringify3 } from "yaml";
|
|
19448
19569
|
var HOST_PASSENGERS_DOCS_URL = "https://crew.tablation.dev/host-passengers";
|
|
19449
19570
|
function shouldRunWizard(opts) {
|
|
19450
19571
|
if (!opts.isTTY) return false;
|
|
19451
|
-
const exists = opts.configExists ??
|
|
19572
|
+
const exists = opts.configExists ?? existsSync41;
|
|
19452
19573
|
return !configSearchPath(opts.crewHome).some((p) => exists(p));
|
|
19453
19574
|
}
|
|
19454
19575
|
function firstRunConfigPath() {
|
|
@@ -19465,7 +19586,7 @@ function defaultIsExecutable(p) {
|
|
|
19465
19586
|
function findOnPath2(name, pathEnv, isExecutable = defaultIsExecutable) {
|
|
19466
19587
|
for (const dir of pathEnv.split(delimiter)) {
|
|
19467
19588
|
if (!dir) continue;
|
|
19468
|
-
const candidate =
|
|
19589
|
+
const candidate = join44(dir, name);
|
|
19469
19590
|
if (isExecutable(candidate)) return candidate;
|
|
19470
19591
|
}
|
|
19471
19592
|
return void 0;
|
|
@@ -19528,7 +19649,7 @@ ${routeBlock}`;
|
|
|
19528
19649
|
function writeNewConfig(path, text2) {
|
|
19529
19650
|
mkdirSync28(dirname23(path), { recursive: true });
|
|
19530
19651
|
try {
|
|
19531
|
-
|
|
19652
|
+
writeFileSync32(path, text2, { mode: 384, flag: "wx" });
|
|
19532
19653
|
return true;
|
|
19533
19654
|
} catch (e) {
|
|
19534
19655
|
if (e.code === "EEXIST") return false;
|
|
@@ -19562,7 +19683,7 @@ Wrote ${o.configPath}.
|
|
|
19562
19683
|
// src/connect-json.ts
|
|
19563
19684
|
import { accessSync as accessSync4, constants as constants4 } from "fs";
|
|
19564
19685
|
import { homedir as homedir10 } from "os";
|
|
19565
|
-
import { dirname as dirname24, join as
|
|
19686
|
+
import { dirname as dirname24, join as join45 } from "path";
|
|
19566
19687
|
import { delimiter as delimiter2 } from "path";
|
|
19567
19688
|
var CHOICE_EXIT_CODE = 3;
|
|
19568
19689
|
function createEmitter(json2, write) {
|
|
@@ -19601,12 +19722,12 @@ function agentBinSearchDirs(home, pathEnv, extraPath) {
|
|
|
19601
19722
|
const dirs = [
|
|
19602
19723
|
...pathEnv.split(delimiter2),
|
|
19603
19724
|
...(extraPath ?? "").split(delimiter2),
|
|
19604
|
-
|
|
19605
|
-
|
|
19725
|
+
join45(home, ".local/bin"),
|
|
19726
|
+
join45(home, ".claude/local"),
|
|
19606
19727
|
"/opt/homebrew/bin",
|
|
19607
19728
|
"/usr/local/bin",
|
|
19608
|
-
|
|
19609
|
-
|
|
19729
|
+
join45(home, ".npm-global/bin"),
|
|
19730
|
+
join45(home, ".volta/bin")
|
|
19610
19731
|
];
|
|
19611
19732
|
return [...new Set(dirs.filter(Boolean))];
|
|
19612
19733
|
}
|
|
@@ -19727,8 +19848,8 @@ async function collectDiagnostics(d) {
|
|
|
19727
19848
|
}
|
|
19728
19849
|
|
|
19729
19850
|
// src/release-run.ts
|
|
19730
|
-
import { readFileSync as
|
|
19731
|
-
import { dirname as dirname25, join as
|
|
19851
|
+
import { readFileSync as readFileSync40, writeFileSync as writeFileSync33, existsSync as existsSync42, copyFileSync, mkdirSync as mkdirSync29, mkdtempSync as mkdtempSync3, rmSync as rmSync20 } from "fs";
|
|
19852
|
+
import { dirname as dirname25, join as join46 } from "path";
|
|
19732
19853
|
import { tmpdir as tmpdir6, hostname as hostname4 } from "os";
|
|
19733
19854
|
|
|
19734
19855
|
// src/release.ts
|
|
@@ -20518,13 +20639,13 @@ async function bump(o, size) {
|
|
|
20518
20639
|
}
|
|
20519
20640
|
return printed;
|
|
20520
20641
|
}
|
|
20521
|
-
const files = o.repo.release.versionFiles.map((f) =>
|
|
20642
|
+
const files = o.repo.release.versionFiles.map((f) => join46(o.cwd, f));
|
|
20522
20643
|
const first = files[0];
|
|
20523
|
-
if (!existsAt(first,
|
|
20644
|
+
if (!existsAt(first, existsSync42)) {
|
|
20524
20645
|
o.emit.error(`no ${o.repo.release.versionFiles[0]} to read a version from`);
|
|
20525
20646
|
return null;
|
|
20526
20647
|
}
|
|
20527
|
-
const firstText = readTextAt(first, (p) =>
|
|
20648
|
+
const firstText = readTextAt(first, (p) => readFileSync40(p, "utf8"));
|
|
20528
20649
|
const problem = versionFileProblem(o.repo.release.versionFiles[0], firstText);
|
|
20529
20650
|
if (problem) {
|
|
20530
20651
|
o.emit.error(problem);
|
|
@@ -20543,27 +20664,27 @@ async function bump(o, size) {
|
|
|
20543
20664
|
return version;
|
|
20544
20665
|
}
|
|
20545
20666
|
for (const f of files) {
|
|
20546
|
-
const src = readTextAt(f, (p) =>
|
|
20667
|
+
const src = readTextAt(f, (p) => readFileSync40(p, "utf8"));
|
|
20547
20668
|
const out = src.replace(/("version"\s*:\s*")[^"]*(")/, `$1${version}$2`);
|
|
20548
20669
|
if (out === src) {
|
|
20549
20670
|
o.emit.error(`no version field in ${f}`);
|
|
20550
20671
|
return null;
|
|
20551
20672
|
}
|
|
20552
|
-
writeTextAt(f, out,
|
|
20673
|
+
writeTextAt(f, out, writeFileSync33);
|
|
20553
20674
|
}
|
|
20554
20675
|
return version;
|
|
20555
20676
|
}
|
|
20556
20677
|
function writeChangelog(o, version, entries) {
|
|
20557
20678
|
const file = o.repo.release.changelog;
|
|
20558
20679
|
if (!file || entries.length === 0) return;
|
|
20559
|
-
const path =
|
|
20680
|
+
const path = join46(o.cwd, file);
|
|
20560
20681
|
const section = renderChangelogSection(version, (/* @__PURE__ */ new Date()).toISOString().slice(0, 10), entries);
|
|
20561
20682
|
if (o.dryRun) {
|
|
20562
20683
|
o.emit.emit(`would prepend ${entries.length} entr(ies) to ${file}`);
|
|
20563
20684
|
return;
|
|
20564
20685
|
}
|
|
20565
|
-
const existing = existsAt(path,
|
|
20566
|
-
writeTextAt(path, insertChangelogSection(existing, section),
|
|
20686
|
+
const existing = existsAt(path, existsSync42) ? readTextAt(path, (p) => readFileSync40(p, "utf8")) : "# Changelog\n";
|
|
20687
|
+
writeTextAt(path, insertChangelogSection(existing, section), writeFileSync33);
|
|
20567
20688
|
}
|
|
20568
20689
|
async function confirm(o, expected) {
|
|
20569
20690
|
if (!o.repo.hooks.released) return void 0;
|
|
@@ -20656,8 +20777,8 @@ function closeReleaseCheckout(cwd, root, dir, branch, run4 = gitOk) {
|
|
|
20656
20777
|
function openReleaseCheckout(o) {
|
|
20657
20778
|
const { remote, base } = o.repo.branch;
|
|
20658
20779
|
const branch = `crew/release-${Date.now()}`;
|
|
20659
|
-
const root = mkdtempSync3(
|
|
20660
|
-
const dir =
|
|
20780
|
+
const root = mkdtempSync3(join46(tmpdir6(), "crew-release-"));
|
|
20781
|
+
const dir = join46(root, "checkout");
|
|
20661
20782
|
o.emit.emit(`release checkout: ${dir}`, { step: "release" });
|
|
20662
20783
|
const close = () => closeReleaseCheckout(o.cwd, root, dir, branch);
|
|
20663
20784
|
try {
|
|
@@ -20667,10 +20788,10 @@ function openReleaseCheckout(o) {
|
|
|
20667
20788
|
throw e;
|
|
20668
20789
|
}
|
|
20669
20790
|
for (const f of o.repo.worktrees.copy) {
|
|
20670
|
-
const src =
|
|
20671
|
-
if (!
|
|
20672
|
-
mkdirSync29(dirname25(
|
|
20673
|
-
copyFileSync(src,
|
|
20791
|
+
const src = join46(o.cwd, f);
|
|
20792
|
+
if (!existsSync42(src)) continue;
|
|
20793
|
+
mkdirSync29(dirname25(join46(dir, f)), { recursive: true });
|
|
20794
|
+
copyFileSync(src, join46(dir, f));
|
|
20674
20795
|
}
|
|
20675
20796
|
return { dir, branch, close };
|
|
20676
20797
|
}
|
|
@@ -21489,15 +21610,15 @@ async function runCommentDeliveryPass(deps) {
|
|
|
21489
21610
|
}
|
|
21490
21611
|
|
|
21491
21612
|
// src/launchd-start.ts
|
|
21492
|
-
import { readFileSync as
|
|
21613
|
+
import { readFileSync as readFileSync47 } from "fs";
|
|
21493
21614
|
import { spawnSync as spawnSync12 } from "child_process";
|
|
21494
21615
|
|
|
21495
21616
|
// src/daemon-liveness.ts
|
|
21496
|
-
import { existsSync as
|
|
21617
|
+
import { existsSync as existsSync49, readFileSync as readFileSync46 } from "fs";
|
|
21497
21618
|
|
|
21498
21619
|
// src/daemon.ts
|
|
21499
|
-
import { existsSync as
|
|
21500
|
-
import { join as
|
|
21620
|
+
import { existsSync as existsSync48, mkdirSync as mkdirSync35, readFileSync as readFileSync45, readdirSync as readdirSync15, rmSync as rmSync22, statSync as statSync14, writeFileSync as writeFileSync37 } from "fs";
|
|
21621
|
+
import { join as join51 } from "path";
|
|
21501
21622
|
import { randomBytes } from "crypto";
|
|
21502
21623
|
|
|
21503
21624
|
// src/fleet.ts
|
|
@@ -21587,16 +21708,16 @@ function nextRoles(decision, ran) {
|
|
|
21587
21708
|
}
|
|
21588
21709
|
|
|
21589
21710
|
// src/noop-runs.ts
|
|
21590
|
-
import { existsSync as
|
|
21591
|
-
import { join as
|
|
21711
|
+
import { existsSync as existsSync43, mkdirSync as mkdirSync30, readFileSync as readFileSync41, renameSync as renameSync7, writeFileSync as writeFileSync34 } from "fs";
|
|
21712
|
+
import { join as join47 } from "path";
|
|
21592
21713
|
var NOOP_DELAYS_MS = [5, 15, 60].map((m) => m * 6e4);
|
|
21593
21714
|
var DEFAULT_NOOP_REPEATS = 3;
|
|
21594
21715
|
var NOOP_BOUNCED_MARKER = calloutHeader("WARNING", "Runs Changed Nothing");
|
|
21595
|
-
var noopRunsPath = (stateDir) =>
|
|
21716
|
+
var noopRunsPath = (stateDir) => join47(stateDir, "noop-runs.json");
|
|
21596
21717
|
var noopRunsKey = (issueId) => `noop_runs:${issueId}`;
|
|
21597
21718
|
function readNoopRuns(stateDir) {
|
|
21598
21719
|
try {
|
|
21599
|
-
const v = JSON.parse(
|
|
21720
|
+
const v = JSON.parse(readFileSync41(noopRunsPath(stateDir), "utf8"));
|
|
21600
21721
|
return v && typeof v === "object" && !Array.isArray(v) ? v : {};
|
|
21601
21722
|
} catch {
|
|
21602
21723
|
return {};
|
|
@@ -21605,9 +21726,9 @@ function readNoopRuns(stateDir) {
|
|
|
21605
21726
|
function writeNoopRuns(stateDir, state) {
|
|
21606
21727
|
mkdirSync30(stateDir, { recursive: true });
|
|
21607
21728
|
const file = noopRunsPath(stateDir);
|
|
21608
|
-
|
|
21729
|
+
writeFileSync34(`${file}.tmp`, `${JSON.stringify(state, null, 2)}
|
|
21609
21730
|
`);
|
|
21610
|
-
|
|
21731
|
+
renameSync7(`${file}.tmp`, file);
|
|
21611
21732
|
}
|
|
21612
21733
|
function noopBackedOff(stateDir, recordId, now = Date.now()) {
|
|
21613
21734
|
const e = readNoopRuns(stateDir)[recordId];
|
|
@@ -21622,7 +21743,7 @@ function recordNoopRun(stateDir, recordId, repeats, now = Date.now()) {
|
|
|
21622
21743
|
return { count, nextAt, bounce: count >= repeats };
|
|
21623
21744
|
}
|
|
21624
21745
|
function clearNoopRuns(stateDir, recordId) {
|
|
21625
|
-
if (!
|
|
21746
|
+
if (!existsSync43(noopRunsPath(stateDir))) return;
|
|
21626
21747
|
const state = readNoopRuns(stateDir);
|
|
21627
21748
|
if (!(recordId in state)) return;
|
|
21628
21749
|
delete state[recordId];
|
|
@@ -21682,7 +21803,7 @@ async function settleNoopRun(o) {
|
|
|
21682
21803
|
}
|
|
21683
21804
|
|
|
21684
21805
|
// src/ship-name.ts
|
|
21685
|
-
import { existsSync as
|
|
21806
|
+
import { existsSync as existsSync44, mkdirSync as mkdirSync31, readFileSync as readFileSync42, renameSync as renameSync8, writeFileSync as writeFileSync35 } from "fs";
|
|
21686
21807
|
import { dirname as dirname26 } from "path";
|
|
21687
21808
|
import { parseDocument as parseDocument4 } from "yaml";
|
|
21688
21809
|
var ShipNameError = class extends Error {
|
|
@@ -21744,19 +21865,19 @@ async function syncRouteName(i) {
|
|
|
21744
21865
|
return { status: "ok", ...base, action, name: i.local };
|
|
21745
21866
|
}
|
|
21746
21867
|
function readSyncedName(resolvedFile) {
|
|
21747
|
-
if (!
|
|
21868
|
+
if (!existsSync44(resolvedFile)) return void 0;
|
|
21748
21869
|
try {
|
|
21749
|
-
const v = JSON.parse(
|
|
21870
|
+
const v = JSON.parse(readFileSync42(resolvedFile, "utf8")).shipName;
|
|
21750
21871
|
return typeof v === "string" ? v : void 0;
|
|
21751
21872
|
} catch {
|
|
21752
21873
|
return void 0;
|
|
21753
21874
|
}
|
|
21754
21875
|
}
|
|
21755
21876
|
function writeSyncedName(resolvedFile, name) {
|
|
21756
|
-
if (!
|
|
21877
|
+
if (!existsSync44(resolvedFile)) return;
|
|
21757
21878
|
let raw;
|
|
21758
21879
|
try {
|
|
21759
|
-
raw = JSON.parse(
|
|
21880
|
+
raw = JSON.parse(readFileSync42(resolvedFile, "utf8"));
|
|
21760
21881
|
} catch {
|
|
21761
21882
|
return;
|
|
21762
21883
|
}
|
|
@@ -21764,14 +21885,14 @@ function writeSyncedName(resolvedFile, name) {
|
|
|
21764
21885
|
raw.shipName = name;
|
|
21765
21886
|
mkdirSync31(dirname26(resolvedFile), { recursive: true });
|
|
21766
21887
|
const tmp = `${resolvedFile}.tmp${process.pid}`;
|
|
21767
|
-
|
|
21888
|
+
writeFileSync35(tmp, `${JSON.stringify(raw, null, 2)}
|
|
21768
21889
|
`);
|
|
21769
|
-
|
|
21890
|
+
renameSync8(tmp, resolvedFile);
|
|
21770
21891
|
}
|
|
21771
21892
|
async function reconcileShipName(i) {
|
|
21772
21893
|
let local = i.ship.name;
|
|
21773
21894
|
try {
|
|
21774
|
-
local = shipNameOfYaml(
|
|
21895
|
+
local = shipNameOfYaml(readFileSync42(i.configFile, "utf8")) ?? local;
|
|
21775
21896
|
} catch {
|
|
21776
21897
|
}
|
|
21777
21898
|
const resolvedFile = resolvedPathFor(i.stateDir, i.route);
|
|
@@ -21795,8 +21916,8 @@ async function reconcileShipName(i) {
|
|
|
21795
21916
|
}
|
|
21796
21917
|
if (result.status !== "ok") return result;
|
|
21797
21918
|
if (result.action === "adopt" || result.action === "row-wins") {
|
|
21798
|
-
const text2 =
|
|
21799
|
-
|
|
21919
|
+
const text2 = readFileSync42(i.configFile, "utf8");
|
|
21920
|
+
writeFileSync35(i.configFile, setShipNameInYaml(text2, result.name));
|
|
21800
21921
|
i.ship.name = result.name;
|
|
21801
21922
|
if (result.action === "row-wins") {
|
|
21802
21923
|
i.emit?.warn(
|
|
@@ -21841,7 +21962,7 @@ async function reconcileRouteShipName(o) {
|
|
|
21841
21962
|
}
|
|
21842
21963
|
|
|
21843
21964
|
// src/mirror-contract.ts
|
|
21844
|
-
import { existsSync as
|
|
21965
|
+
import { existsSync as existsSync45 } from "fs";
|
|
21845
21966
|
|
|
21846
21967
|
// src/passenger-mirror.ts
|
|
21847
21968
|
import { mkdirSync as mkdirSync32 } from "fs";
|
|
@@ -21882,7 +22003,7 @@ function mirrorOutcome(m) {
|
|
|
21882
22003
|
|
|
21883
22004
|
// src/mirror-contract.ts
|
|
21884
22005
|
function lacksCheckout(ship, dir) {
|
|
21885
|
-
return ship.runner === "sandbox" && !
|
|
22006
|
+
return ship.runner === "sandbox" && !existsSync45(dir) && !remoteOf(dir);
|
|
21886
22007
|
}
|
|
21887
22008
|
function skipsHostCheckout(ship) {
|
|
21888
22009
|
return ship.runner === "sandbox";
|
|
@@ -21963,17 +22084,17 @@ function explainRefusal(readable, unreadable) {
|
|
|
21963
22084
|
|
|
21964
22085
|
// src/ssh-keys.ts
|
|
21965
22086
|
import { execFileSync as execFileSync13 } from "child_process";
|
|
21966
|
-
import { existsSync as
|
|
21967
|
-
import { dirname as dirname28, join as
|
|
22087
|
+
import { existsSync as existsSync46, mkdirSync as mkdirSync33, readFileSync as readFileSync43, chmodSync as chmodSync3 } from "fs";
|
|
22088
|
+
import { dirname as dirname28, join as join48 } from "path";
|
|
21968
22089
|
var SshKeyError = class extends Error {
|
|
21969
22090
|
};
|
|
21970
22091
|
function shipSshKeyPathFor(stateDir) {
|
|
21971
|
-
return
|
|
22092
|
+
return join48(stateDir, "ssh", "id_ed25519");
|
|
21972
22093
|
}
|
|
21973
22094
|
function ensureShipSshKeypair(stateDir) {
|
|
21974
22095
|
const privateKeyPath = shipSshKeyPathFor(stateDir);
|
|
21975
22096
|
const publicKeyPath = `${privateKeyPath}.pub`;
|
|
21976
|
-
if (!
|
|
22097
|
+
if (!existsSync46(privateKeyPath)) {
|
|
21977
22098
|
mkdirSync33(dirname28(privateKeyPath), { recursive: true });
|
|
21978
22099
|
try {
|
|
21979
22100
|
execFileSync13("ssh-keygen", [
|
|
@@ -21994,10 +22115,10 @@ function ensureShipSshKeypair(stateDir) {
|
|
|
21994
22115
|
}
|
|
21995
22116
|
chmodSync3(privateKeyPath, 384);
|
|
21996
22117
|
}
|
|
21997
|
-
if (!
|
|
22118
|
+
if (!existsSync46(publicKeyPath)) {
|
|
21998
22119
|
throw new SshKeyError(`${privateKeyPath} exists but ${publicKeyPath} does not \u2014 regenerate or restore it`);
|
|
21999
22120
|
}
|
|
22000
|
-
const publicKey =
|
|
22121
|
+
const publicKey = readFileSync43(publicKeyPath, "utf8").trim();
|
|
22001
22122
|
return { privateKeyPath, publicKeyPath, publicKey };
|
|
22002
22123
|
}
|
|
22003
22124
|
function sshKeygenAvailable() {
|
|
@@ -22011,8 +22132,8 @@ function sshKeygenAvailable() {
|
|
|
22011
22132
|
|
|
22012
22133
|
// src/periscope-idle.ts
|
|
22013
22134
|
import { execFileSync as execFileSync14 } from "child_process";
|
|
22014
|
-
import { statSync as
|
|
22015
|
-
import { join as
|
|
22135
|
+
import { statSync as statSync13 } from "fs";
|
|
22136
|
+
import { join as join49 } from "path";
|
|
22016
22137
|
var MAX_SCANNED_FILES = 2e4;
|
|
22017
22138
|
function newestWorktreeMtime(root) {
|
|
22018
22139
|
const a = newestTrackedMtime(root);
|
|
@@ -22037,7 +22158,7 @@ function newestTrackedMtime(root) {
|
|
|
22037
22158
|
if (!rel) continue;
|
|
22038
22159
|
if (++scanned > MAX_SCANNED_FILES) break;
|
|
22039
22160
|
try {
|
|
22040
|
-
const m =
|
|
22161
|
+
const m = statSync13(join49(root, rel)).mtimeMs;
|
|
22041
22162
|
if (newest === null || m > newest) newest = m;
|
|
22042
22163
|
} catch {
|
|
22043
22164
|
}
|
|
@@ -22111,8 +22232,8 @@ async function runPeriscopeIdlePass(d) {
|
|
|
22111
22232
|
}
|
|
22112
22233
|
|
|
22113
22234
|
// src/periscope-cmd.ts
|
|
22114
|
-
import { existsSync as
|
|
22115
|
-
import { join as
|
|
22235
|
+
import { existsSync as existsSync47, mkdirSync as mkdirSync34, readFileSync as readFileSync44, rmSync as rmSync21, writeFileSync as writeFileSync36 } from "fs";
|
|
22236
|
+
import { join as join50 } from "path";
|
|
22116
22237
|
var PeriscopeError = class extends Error {
|
|
22117
22238
|
};
|
|
22118
22239
|
var LivePeriscopeError = class extends PeriscopeError {
|
|
@@ -22122,22 +22243,22 @@ var LivePeriscopeError = class extends PeriscopeError {
|
|
|
22122
22243
|
this.data = { refused: "live_periscope_exists", ...live2 };
|
|
22123
22244
|
}
|
|
22124
22245
|
};
|
|
22125
|
-
var priorDir = (stateDir) =>
|
|
22126
|
-
var priorPath = (stateDir, ticketRecordId) =>
|
|
22246
|
+
var priorDir = (stateDir) => join50(stateDir, "periscope-priors");
|
|
22247
|
+
var priorPath = (stateDir, ticketRecordId) => join50(priorDir(stateDir), `${ticketRecordId}.json`);
|
|
22127
22248
|
function removePeriscopePrior(stateDir, ticketRecordId) {
|
|
22128
22249
|
rmSync21(priorPath(stateDir, ticketRecordId), { force: true });
|
|
22129
22250
|
}
|
|
22130
22251
|
function writePeriscopePrior(stateDir, ticketRecordId, prior) {
|
|
22131
22252
|
try {
|
|
22132
22253
|
mkdirSync34(priorDir(stateDir), { recursive: true });
|
|
22133
|
-
|
|
22254
|
+
writeFileSync36(priorPath(stateDir, ticketRecordId), JSON.stringify(prior));
|
|
22134
22255
|
} catch {
|
|
22135
22256
|
}
|
|
22136
22257
|
}
|
|
22137
22258
|
function readPeriscopePrior(stateDir, ticketRecordId) {
|
|
22138
22259
|
try {
|
|
22139
22260
|
const p = priorPath(stateDir, ticketRecordId);
|
|
22140
|
-
return
|
|
22261
|
+
return existsSync47(p) ? JSON.parse(readFileSync44(p, "utf8")) : void 0;
|
|
22141
22262
|
} catch {
|
|
22142
22263
|
return void 0;
|
|
22143
22264
|
}
|
|
@@ -22699,15 +22820,15 @@ async function runDaemonLoop(o) {
|
|
|
22699
22820
|
function latestMtime(path) {
|
|
22700
22821
|
let stat2;
|
|
22701
22822
|
try {
|
|
22702
|
-
stat2 =
|
|
22823
|
+
stat2 = statSync14(path);
|
|
22703
22824
|
} catch {
|
|
22704
22825
|
return 0;
|
|
22705
22826
|
}
|
|
22706
22827
|
if (stat2.isFile()) return stat2.mtimeMs;
|
|
22707
22828
|
if (!stat2.isDirectory()) return 0;
|
|
22708
22829
|
let latest = stat2.mtimeMs;
|
|
22709
|
-
for (const entry of
|
|
22710
|
-
latest = Math.max(latest, latestMtime(
|
|
22830
|
+
for (const entry of readdirSync15(path, { withFileTypes: true })) {
|
|
22831
|
+
latest = Math.max(latest, latestMtime(join51(path, entry.name)));
|
|
22711
22832
|
}
|
|
22712
22833
|
return latest;
|
|
22713
22834
|
}
|
|
@@ -22716,30 +22837,30 @@ function computeTreeSignature(paths) {
|
|
|
22716
22837
|
}
|
|
22717
22838
|
function makeStaleChecker(paths, opts = {}) {
|
|
22718
22839
|
const initial = computeTreeSignature(paths);
|
|
22719
|
-
return () => computeTreeSignature(paths) !== initial || opts.reloadSentinel !== void 0 &&
|
|
22840
|
+
return () => computeTreeSignature(paths) !== initial || opts.reloadSentinel !== void 0 && existsSync48(opts.reloadSentinel);
|
|
22720
22841
|
}
|
|
22721
22842
|
function reloadSentinelFor(stateDir) {
|
|
22722
|
-
return
|
|
22843
|
+
return join51(stateDir, "reload-requested");
|
|
22723
22844
|
}
|
|
22724
22845
|
function readReloadRequestedAt(stateDir) {
|
|
22725
22846
|
try {
|
|
22726
|
-
return
|
|
22847
|
+
return statSync14(reloadSentinelFor(stateDir)).mtimeMs;
|
|
22727
22848
|
} catch {
|
|
22728
22849
|
return null;
|
|
22729
22850
|
}
|
|
22730
22851
|
}
|
|
22731
22852
|
function daemonStampFor(stateDir) {
|
|
22732
|
-
return
|
|
22853
|
+
return join51(stateDir, "daemon.started");
|
|
22733
22854
|
}
|
|
22734
22855
|
function noteDaemonStarted(stateDir, now = Date.now()) {
|
|
22735
22856
|
mkdirSync35(stateDir, { recursive: true });
|
|
22736
22857
|
rmSync22(reloadSentinelFor(stateDir), { force: true });
|
|
22737
|
-
|
|
22858
|
+
writeFileSync37(daemonStampFor(stateDir), `${JSON.stringify({ pid: process.pid, startedAt: now })}
|
|
22738
22859
|
`);
|
|
22739
22860
|
}
|
|
22740
22861
|
function readDaemonStarted(stateDir) {
|
|
22741
22862
|
try {
|
|
22742
|
-
const v = JSON.parse(
|
|
22863
|
+
const v = JSON.parse(readFileSync45(daemonStampFor(stateDir), "utf8")).startedAt;
|
|
22743
22864
|
return typeof v === "number" ? v : null;
|
|
22744
22865
|
} catch {
|
|
22745
22866
|
return null;
|
|
@@ -22748,7 +22869,7 @@ function readDaemonStarted(stateDir) {
|
|
|
22748
22869
|
function configChangedAfter(files, startedAt) {
|
|
22749
22870
|
for (const f of files) {
|
|
22750
22871
|
try {
|
|
22751
|
-
if (
|
|
22872
|
+
if (statSync14(f).mtimeMs > startedAt) return f;
|
|
22752
22873
|
} catch {
|
|
22753
22874
|
}
|
|
22754
22875
|
}
|
|
@@ -23596,7 +23717,7 @@ function parseSystemctlShow(text2) {
|
|
|
23596
23717
|
}
|
|
23597
23718
|
function lastLogLine(path, read = (p) => {
|
|
23598
23719
|
try {
|
|
23599
|
-
return
|
|
23720
|
+
return readFileSync46(p, "utf8");
|
|
23600
23721
|
} catch {
|
|
23601
23722
|
return null;
|
|
23602
23723
|
}
|
|
@@ -23623,7 +23744,7 @@ function probeDaemonUnit(o) {
|
|
|
23623
23744
|
const r = spawnSync11(cmd[0], cmd.slice(1), { encoding: "utf8" });
|
|
23624
23745
|
return r.error ? null : { status: r.status, stdout: r.stdout ?? "" };
|
|
23625
23746
|
});
|
|
23626
|
-
const installed = o.plan.unitPaths.some((p) =>
|
|
23747
|
+
const installed = o.plan.unitPaths.some((p) => existsSync49(p));
|
|
23627
23748
|
let reading = null;
|
|
23628
23749
|
if (installed && o.plan.mechanism === "launchd") {
|
|
23629
23750
|
const r = run4(["launchctl", "print", `gui/${o.uid}/${o.label}`]);
|
|
@@ -23673,7 +23794,7 @@ function daemonProblem(d, route2) {
|
|
|
23673
23794
|
}
|
|
23674
23795
|
function readDaemonStamp(stateDir) {
|
|
23675
23796
|
try {
|
|
23676
|
-
const v = JSON.parse(
|
|
23797
|
+
const v = JSON.parse(readFileSync46(daemonStampFor(stateDir), "utf8"));
|
|
23677
23798
|
if (typeof v.startedAt !== "number") return null;
|
|
23678
23799
|
return typeof v.pid === "number" ? { pid: v.pid, startedAt: v.startedAt } : { startedAt: v.startedAt };
|
|
23679
23800
|
} catch {
|
|
@@ -23702,7 +23823,7 @@ function defaultSleep2(ms3) {
|
|
|
23702
23823
|
}
|
|
23703
23824
|
function defaultReadLog(path) {
|
|
23704
23825
|
try {
|
|
23705
|
-
return
|
|
23826
|
+
return readFileSync47(path, "utf8");
|
|
23706
23827
|
} catch {
|
|
23707
23828
|
return null;
|
|
23708
23829
|
}
|
|
@@ -23769,15 +23890,15 @@ function startLaunchdDaemon(o) {
|
|
|
23769
23890
|
}
|
|
23770
23891
|
|
|
23771
23892
|
// src/daemon-start-failure.ts
|
|
23772
|
-
import { existsSync as
|
|
23773
|
-
import { dirname as dirname29, join as
|
|
23893
|
+
import { existsSync as existsSync50, mkdirSync as mkdirSync36, readFileSync as readFileSync48, unlinkSync as unlinkSync4, writeFileSync as writeFileSync38 } from "fs";
|
|
23894
|
+
import { dirname as dirname29, join as join52 } from "path";
|
|
23774
23895
|
var DAEMON_START_FAILED_KEY = "daemon_start_failed";
|
|
23775
23896
|
var START_FAILURE_BACKOFF_MS = 6e4;
|
|
23776
23897
|
var BACKOFF_AFTER_FAILURES = 2;
|
|
23777
|
-
var fileFor3 = (stateDir) =>
|
|
23898
|
+
var fileFor3 = (stateDir) => join52(stateDir, ".daemon-start-failure.json");
|
|
23778
23899
|
function readStartFailure(stateDir) {
|
|
23779
23900
|
try {
|
|
23780
|
-
const parsed = JSON.parse(
|
|
23901
|
+
const parsed = JSON.parse(readFileSync48(fileFor3(stateDir), "utf8"));
|
|
23781
23902
|
return typeof parsed.reason === "string" && typeof parsed.count === "number" ? { reason: parsed.reason, count: parsed.count, firstAt: String(parsed.firstAt), lastAt: String(parsed.lastAt) } : null;
|
|
23782
23903
|
} catch {
|
|
23783
23904
|
return null;
|
|
@@ -23794,7 +23915,7 @@ function noteStartFailure(stateDir, reason, nowMs = Date.now()) {
|
|
|
23794
23915
|
lastAt: nowIso
|
|
23795
23916
|
};
|
|
23796
23917
|
mkdirSync36(stateDir, { recursive: true });
|
|
23797
|
-
|
|
23918
|
+
writeFileSync38(fileFor3(stateDir), JSON.stringify(record));
|
|
23798
23919
|
return record;
|
|
23799
23920
|
}
|
|
23800
23921
|
function startFailureDelayMs(count) {
|
|
@@ -23808,7 +23929,7 @@ function startFailureItem(record, o = {}) {
|
|
|
23808
23929
|
return { kind: "daemon_start_failed", key: DAEMON_START_FAILED_KEY, message: parts.join(". ").replace(/\.\./g, "."), since: record.firstAt };
|
|
23809
23930
|
}
|
|
23810
23931
|
function clearStartFailure(state, stateDir) {
|
|
23811
|
-
if (
|
|
23932
|
+
if (existsSync50(fileFor3(stateDir))) {
|
|
23812
23933
|
try {
|
|
23813
23934
|
unlinkSync4(fileFor3(stateDir));
|
|
23814
23935
|
} catch {
|
|
@@ -23835,7 +23956,7 @@ async function reportStartFailure(o) {
|
|
|
23835
23956
|
return delay;
|
|
23836
23957
|
}
|
|
23837
23958
|
function fallbackStateDir(configFile) {
|
|
23838
|
-
return
|
|
23959
|
+
return join52(dirname29(configFile), "state");
|
|
23839
23960
|
}
|
|
23840
23961
|
|
|
23841
23962
|
// src/projects-cmd.ts
|
|
@@ -23949,7 +24070,7 @@ function runForge(a, io) {
|
|
|
23949
24070
|
|
|
23950
24071
|
// src/release-sandbox.ts
|
|
23951
24072
|
import { execFile as execFile5 } from "child_process";
|
|
23952
|
-
import { mkdirSync as mkdirSync37, writeFileSync as
|
|
24073
|
+
import { mkdirSync as mkdirSync37, writeFileSync as writeFileSync39 } from "fs";
|
|
23953
24074
|
import { dirname as dirname30 } from "path";
|
|
23954
24075
|
import { promisify as promisify4 } from "util";
|
|
23955
24076
|
var execFileP4 = promisify4(execFile5);
|
|
@@ -23997,7 +24118,7 @@ async function openReleaseSandbox(o) {
|
|
|
23997
24118
|
generated = generateSandboxPolicy({ mirrorDir: cfg.mirrorDir, workDir: cfg.workDir, ...o.policy });
|
|
23998
24119
|
policyFile = o.policyFile;
|
|
23999
24120
|
mkdirSync37(dirname30(policyFile), { recursive: true });
|
|
24000
|
-
|
|
24121
|
+
writeFileSync39(policyFile, generated.yaml, { mode: 384 });
|
|
24001
24122
|
}
|
|
24002
24123
|
const secrets = { ...process.env };
|
|
24003
24124
|
const secretKeys = [];
|
|
@@ -24163,7 +24284,7 @@ function missingReleaserWarning(repo, release, ships, now = Date.now()) {
|
|
|
24163
24284
|
}
|
|
24164
24285
|
|
|
24165
24286
|
// src/watch.ts
|
|
24166
|
-
import { watch as watchFile, existsSync as
|
|
24287
|
+
import { watch as watchFile, existsSync as existsSync51, statSync as statSync15, openSync as openSync6, readSync as readSync3, closeSync as closeSync6 } from "fs";
|
|
24167
24288
|
var E = "\x1B[";
|
|
24168
24289
|
var dim = (s) => `${E}2m${s}${E}0m`;
|
|
24169
24290
|
var bold = (s) => `${E}1m${s}${E}0m`;
|
|
@@ -24264,14 +24385,14 @@ function renderHeaders(states, now = Date.now()) {
|
|
|
24264
24385
|
return states.map((s) => renderHeader(s, now)).join("");
|
|
24265
24386
|
}
|
|
24266
24387
|
function readFrom(file, from) {
|
|
24267
|
-
if (!
|
|
24268
|
-
const size =
|
|
24388
|
+
if (!existsSync51(file)) return { events: [], offset: from };
|
|
24389
|
+
const size = statSync15(file).size;
|
|
24269
24390
|
if (size < from) return readFrom(file, 0);
|
|
24270
24391
|
if (size === from) return { events: [], offset: from };
|
|
24271
|
-
const fd =
|
|
24392
|
+
const fd = openSync6(file, "r");
|
|
24272
24393
|
const buf = Buffer.alloc(size - from);
|
|
24273
|
-
|
|
24274
|
-
|
|
24394
|
+
readSync3(fd, buf, 0, buf.length, from);
|
|
24395
|
+
closeSync6(fd);
|
|
24275
24396
|
const text2 = buf.toString("utf8");
|
|
24276
24397
|
const lastNewline = text2.lastIndexOf("\n");
|
|
24277
24398
|
if (lastNewline === -1) return { events: [], offset: from };
|
|
@@ -25081,14 +25202,14 @@ function describeCapability(i) {
|
|
|
25081
25202
|
}
|
|
25082
25203
|
|
|
25083
25204
|
// src/persona-avatars.ts
|
|
25084
|
-
import { existsSync as
|
|
25085
|
-
import { join as
|
|
25205
|
+
import { existsSync as existsSync52, readFileSync as readFileSync49 } from "fs";
|
|
25206
|
+
import { join as join53 } from "path";
|
|
25086
25207
|
var IMAGE_TYPES = { png: "image/png", svg: "image/svg+xml" };
|
|
25087
25208
|
function personaAvatarFile(promptsDir, role) {
|
|
25088
25209
|
for (const ext of ["png", "svg"]) {
|
|
25089
25210
|
const name = `lane-${role}.${ext}`;
|
|
25090
|
-
const path =
|
|
25091
|
-
if (
|
|
25211
|
+
const path = join53(promptsDir, "personas", name);
|
|
25212
|
+
if (existsSync52(path)) return { path, mimeType: IMAGE_TYPES[ext], name };
|
|
25092
25213
|
}
|
|
25093
25214
|
return void 0;
|
|
25094
25215
|
}
|
|
@@ -25102,7 +25223,7 @@ async function syncPersonaAvatars(route2, agentPersonas, opts) {
|
|
|
25102
25223
|
if (!file || !agentId) continue;
|
|
25103
25224
|
try {
|
|
25104
25225
|
const form = new FormData();
|
|
25105
|
-
form.append("file", new Blob([
|
|
25226
|
+
form.append("file", new Blob([readFileSync49(file.path)], { type: file.mimeType }), file.name);
|
|
25106
25227
|
const res = await fetch(`${base}/${agentId}/avatar`, {
|
|
25107
25228
|
method: "PUT",
|
|
25108
25229
|
headers: { Authorization: `Bearer ${resolveApiKey(route2)}`, "User-Agent": opts.userAgent ?? "Mozilla/5.0 TablationCrewAgent/1.0" },
|
|
@@ -25143,14 +25264,14 @@ function avatarFailures(raw) {
|
|
|
25143
25264
|
}
|
|
25144
25265
|
function routeAvatarFailures(stateDir, route2) {
|
|
25145
25266
|
try {
|
|
25146
|
-
return avatarFailures(JSON.parse(
|
|
25267
|
+
return avatarFailures(JSON.parse(readFileSync49(resolvedPathFor(stateDir, route2), "utf8")));
|
|
25147
25268
|
} catch {
|
|
25148
25269
|
return [];
|
|
25149
25270
|
}
|
|
25150
25271
|
}
|
|
25151
25272
|
|
|
25152
25273
|
// src/agents-sync-run.ts
|
|
25153
|
-
import { existsSync as
|
|
25274
|
+
import { existsSync as existsSync53, mkdirSync as mkdirSync38, readFileSync as readFileSync50, writeFileSync as writeFileSync40 } from "fs";
|
|
25154
25275
|
import { dirname as dirname31 } from "path";
|
|
25155
25276
|
async function runAgentsSync(target, o) {
|
|
25156
25277
|
const dryRun = o.dryRun ?? false;
|
|
@@ -25196,13 +25317,13 @@ async function runAgentsSync(target, o) {
|
|
|
25196
25317
|
}
|
|
25197
25318
|
if (!dryRun) {
|
|
25198
25319
|
const resolvedPath = resolvedPathFor(o.stateDir, target.route);
|
|
25199
|
-
const raw =
|
|
25320
|
+
const raw = existsSync53(resolvedPath) ? JSON.parse(readFileSync50(resolvedPath, "utf8")) : {};
|
|
25200
25321
|
raw.agentPersonas = personaResult.agentPersonas;
|
|
25201
25322
|
if (skillResult) raw.agentSkills = skillResult.agentSkills;
|
|
25202
25323
|
if (!readOnly) raw.avatarSyncFailures = avatarFailures2;
|
|
25203
25324
|
if (personaResult.releaseAgentId) raw.releaseAgentId = personaResult.releaseAgentId;
|
|
25204
25325
|
mkdirSync38(dirname31(resolvedPath), { recursive: true });
|
|
25205
|
-
|
|
25326
|
+
writeFileSync40(resolvedPath, `${JSON.stringify(raw, null, 2)}
|
|
25206
25327
|
`);
|
|
25207
25328
|
if (target.resolved) {
|
|
25208
25329
|
target.resolved.agentPersonas = personaResult.agentPersonas;
|
|
@@ -25339,7 +25460,7 @@ async function showLogEntry(route2, entryId, opts = {}) {
|
|
|
25339
25460
|
|
|
25340
25461
|
// src/repos-check.ts
|
|
25341
25462
|
import { spawnSync as spawnSync13 } from "child_process";
|
|
25342
|
-
import { readFileSync as
|
|
25463
|
+
import { readFileSync as readFileSync51 } from "fs";
|
|
25343
25464
|
import { basename as basename12 } from "path";
|
|
25344
25465
|
var POSIX_SHELL = /^(?:ba|z|da|k|a|mk)?sh$|^fish$/;
|
|
25345
25466
|
function checkHookSyntax(script, shell) {
|
|
@@ -25380,7 +25501,7 @@ function checkRepoSpec(dir, opts = {}) {
|
|
|
25380
25501
|
}
|
|
25381
25502
|
let parsed;
|
|
25382
25503
|
try {
|
|
25383
|
-
parsed = parseRepoConfig(
|
|
25504
|
+
parsed = parseRepoConfig(readFileSync51(file, "utf8"), file);
|
|
25384
25505
|
} catch (e) {
|
|
25385
25506
|
if (!(e instanceof RepoConfigError)) throw e;
|
|
25386
25507
|
return { ...empty, file, error: e.message, exitCode: 1 };
|
|
@@ -25844,7 +25965,7 @@ ${run4.err}` });
|
|
|
25844
25965
|
}
|
|
25845
25966
|
|
|
25846
25967
|
// src/sample-ticket.ts
|
|
25847
|
-
import { basename as basename13, dirname as dirname32, join as
|
|
25968
|
+
import { basename as basename13, dirname as dirname32, join as join54 } from "path";
|
|
25848
25969
|
var SAMPLE_REPO = "crew-sample";
|
|
25849
25970
|
var SAMPLE_REMOTE = `local/${SAMPLE_REPO}`;
|
|
25850
25971
|
var SAMPLE_MARKER = "sample: true";
|
|
@@ -25867,8 +25988,8 @@ has something safe to work on: its test and build hooks always pass, it has no
|
|
|
25867
25988
|
remote, and \`crew sample-ticket --remove\` deletes it.
|
|
25868
25989
|
`;
|
|
25869
25990
|
function sampleDir(existing, reposBase, workspace) {
|
|
25870
|
-
if (existing.length > 0) return
|
|
25871
|
-
return
|
|
25991
|
+
if (existing.length > 0) return join54(dirname32(existing[0]), SAMPLE_REPO);
|
|
25992
|
+
return join54(reposBase, workspace, SAMPLE_REPO);
|
|
25872
25993
|
}
|
|
25873
25994
|
var SAMPLE_TITLE = "Sample: add a documented `greet` function with a test";
|
|
25874
25995
|
function sampleDescription() {
|
|
@@ -25912,8 +26033,8 @@ function planSampleTicket(i) {
|
|
|
25912
26033
|
}
|
|
25913
26034
|
|
|
25914
26035
|
// src/worktree-sweep.ts
|
|
25915
|
-
import { existsSync as
|
|
25916
|
-
import { basename as basename14, dirname as dirname33, join as
|
|
26036
|
+
import { existsSync as existsSync54, readFileSync as readFileSync52, readdirSync as readdirSync16 } from "fs";
|
|
26037
|
+
import { basename as basename14, dirname as dirname33, join as join55, resolve as resolve5 } from "path";
|
|
25917
26038
|
function planWorktreeSweep(target, tickets, contract) {
|
|
25918
26039
|
const terminal = new Set(contract.statuses.resolved.filter((s) => s !== contract.statuses.verified));
|
|
25919
26040
|
const verified = contract.statuses.verified;
|
|
@@ -25982,7 +26103,7 @@ function siblingWorktreeDirs(target) {
|
|
|
25982
26103
|
const registered = new Set(worktrees(target.dir).map((w) => resolve5(w.path)));
|
|
25983
26104
|
let names;
|
|
25984
26105
|
try {
|
|
25985
|
-
names =
|
|
26106
|
+
names = readdirSync16(parent);
|
|
25986
26107
|
} catch {
|
|
25987
26108
|
return [];
|
|
25988
26109
|
}
|
|
@@ -25990,7 +26111,7 @@ function siblingWorktreeDirs(target) {
|
|
|
25990
26111
|
for (const name of names) {
|
|
25991
26112
|
if (!name.startsWith(stem)) continue;
|
|
25992
26113
|
const m = DIR_NUMBER_SUFFIXED.exec(name);
|
|
25993
|
-
const path =
|
|
26114
|
+
const path = join55(parent, name);
|
|
25994
26115
|
if (m && !registered.has(resolve5(path))) out.push({ path, number: m[1] });
|
|
25995
26116
|
}
|
|
25996
26117
|
return out;
|
|
@@ -26025,7 +26146,7 @@ async function applyWorktreeSweep(cwd, actions, dryRun, log, remote = "origin",
|
|
|
26025
26146
|
let removed = 0;
|
|
26026
26147
|
let keptBranches = 0;
|
|
26027
26148
|
for (const a of actions) {
|
|
26028
|
-
if (!dryRun && base && !a.keepBranch &&
|
|
26149
|
+
if (!dryRun && base && !a.keepBranch && existsSync54(a.path) && isHandBackMerge(a.path, base)) {
|
|
26029
26150
|
if (gitOk(a.path, ["merge", "--abort"]) !== null) {
|
|
26030
26151
|
log.emit(
|
|
26031
26152
|
`abandoned the hand-back merge of ${base} in ${a.path}: ${a.ticket.issue_id} deployed without it`,
|
|
@@ -26042,11 +26163,11 @@ async function applyWorktreeSweep(cwd, actions, dryRun, log, remote = "origin",
|
|
|
26042
26163
|
{ ticket: a.ticket.issue_id, step: "worktree" }
|
|
26043
26164
|
);
|
|
26044
26165
|
};
|
|
26045
|
-
if (!dryRun && liveRun &&
|
|
26166
|
+
if (!dryRun && liveRun && existsSync54(a.path)) {
|
|
26046
26167
|
defer();
|
|
26047
26168
|
continue;
|
|
26048
26169
|
}
|
|
26049
|
-
if (!dryRun &&
|
|
26170
|
+
if (!dryRun && existsSync54(a.path)) {
|
|
26050
26171
|
let dirty = false;
|
|
26051
26172
|
try {
|
|
26052
26173
|
dirty = status(a.path).length > 0;
|
|
@@ -26061,7 +26182,7 @@ async function applyWorktreeSweep(cwd, actions, dryRun, log, remote = "origin",
|
|
|
26061
26182
|
continue;
|
|
26062
26183
|
}
|
|
26063
26184
|
}
|
|
26064
|
-
if (!dryRun && a.requirePushed && a.branch &&
|
|
26185
|
+
if (!dryRun && a.requirePushed && a.branch && existsSync54(a.path) && remoteConfigured(cwd, remote) && worktreeHoldsUnpushed(a.path, remote)) {
|
|
26065
26186
|
if (pids.length) {
|
|
26066
26187
|
defer();
|
|
26067
26188
|
continue;
|
|
@@ -26112,7 +26233,7 @@ function isHandBackMerge(path, base) {
|
|
|
26112
26233
|
if (!msgPath) return false;
|
|
26113
26234
|
let first;
|
|
26114
26235
|
try {
|
|
26115
|
-
first =
|
|
26236
|
+
first = readFileSync52(resolve5(path, msgPath), "utf8").split("\n")[0] ?? "";
|
|
26116
26237
|
} catch {
|
|
26117
26238
|
return false;
|
|
26118
26239
|
}
|
|
@@ -26217,16 +26338,16 @@ function applyRemoteBranchCleanup(cwd, remote, branches2, dryRun, log) {
|
|
|
26217
26338
|
}
|
|
26218
26339
|
|
|
26219
26340
|
// src/stream-sweep.ts
|
|
26220
|
-
import { existsSync as
|
|
26221
|
-
import { join as
|
|
26341
|
+
import { existsSync as existsSync55, readdirSync as readdirSync17, rmSync as rmSync23, statSync as statSync16 } from "fs";
|
|
26342
|
+
import { join as join56 } from "path";
|
|
26222
26343
|
var DAY_MS2 = 24 * 60 * 60 * 1e3;
|
|
26223
26344
|
function planStreamSweep(stateDir, retentionDays, now = Date.now()) {
|
|
26224
|
-
const dir =
|
|
26225
|
-
if (!
|
|
26345
|
+
const dir = join56(stateDir, "streams");
|
|
26346
|
+
if (!existsSync55(dir)) return [];
|
|
26226
26347
|
const cutoff = now - retentionDays * DAY_MS2;
|
|
26227
|
-
return
|
|
26348
|
+
return readdirSync17(dir).map((name) => join56(dir, name)).filter((path) => {
|
|
26228
26349
|
try {
|
|
26229
|
-
return
|
|
26350
|
+
return statSync16(path).mtimeMs < cutoff;
|
|
26230
26351
|
} catch {
|
|
26231
26352
|
return false;
|
|
26232
26353
|
}
|
|
@@ -26250,11 +26371,11 @@ function applyStreamSweep(paths, dryRun, log) {
|
|
|
26250
26371
|
return removed;
|
|
26251
26372
|
}
|
|
26252
26373
|
function planEventsSweep(stateDir, retentionDays, now = Date.now()) {
|
|
26253
|
-
if (!
|
|
26374
|
+
if (!existsSync55(stateDir)) return [];
|
|
26254
26375
|
const cutoff = now - retentionDays * DAY_MS2;
|
|
26255
|
-
return
|
|
26376
|
+
return readdirSync17(stateDir).filter((name) => ROTATED_EVENTS_RE.test(name)).map((name) => join56(stateDir, name)).filter((path) => {
|
|
26256
26377
|
try {
|
|
26257
|
-
return
|
|
26378
|
+
return statSync16(path).mtimeMs < cutoff;
|
|
26258
26379
|
} catch {
|
|
26259
26380
|
return false;
|
|
26260
26381
|
}
|
|
@@ -26262,7 +26383,7 @@ function planEventsSweep(stateDir, retentionDays, now = Date.now()) {
|
|
|
26262
26383
|
}
|
|
26263
26384
|
|
|
26264
26385
|
// src/cli.ts
|
|
26265
|
-
import { realpathSync as realpathSync3, readFileSync as
|
|
26386
|
+
import { realpathSync as realpathSync3, readFileSync as readFileSync55, existsSync as existsSync60, mkdirSync as mkdirSync42, writeFileSync as writeFileSync43, rmSync as rmSync26, unlinkSync as unlinkSync6, copyFileSync as copyFileSync2, renameSync as renameSync9, statSync as statSync19, readdirSync as readdirSync22 } from "fs";
|
|
26266
26387
|
import { createInterface } from "readline/promises";
|
|
26267
26388
|
|
|
26268
26389
|
// src/periscope-resume.ts
|
|
@@ -26338,33 +26459,33 @@ ${tail2(preview.output)}`);
|
|
|
26338
26459
|
import { dirname as dirOf2, resolve as resolvePath } from "path";
|
|
26339
26460
|
|
|
26340
26461
|
// src/bundle-staleness.ts
|
|
26341
|
-
import { existsSync as
|
|
26342
|
-
import { join as
|
|
26462
|
+
import { existsSync as existsSync56, readdirSync as readdirSync18, statSync as statSync17 } from "fs";
|
|
26463
|
+
import { join as join57 } from "path";
|
|
26343
26464
|
function builtVersion() {
|
|
26344
|
-
return true ? "0.
|
|
26465
|
+
return true ? "0.145.0" : null;
|
|
26345
26466
|
}
|
|
26346
26467
|
var REBUILD_HINT = "rebuild with npm run build";
|
|
26347
26468
|
function newestMtime(path) {
|
|
26348
26469
|
let stat2;
|
|
26349
26470
|
try {
|
|
26350
|
-
stat2 =
|
|
26471
|
+
stat2 = statSync17(path);
|
|
26351
26472
|
} catch {
|
|
26352
26473
|
return 0;
|
|
26353
26474
|
}
|
|
26354
26475
|
if (stat2.isFile()) return stat2.mtimeMs;
|
|
26355
26476
|
if (!stat2.isDirectory()) return 0;
|
|
26356
26477
|
let latest = stat2.mtimeMs;
|
|
26357
|
-
for (const e of
|
|
26478
|
+
for (const e of readdirSync18(path, { withFileTypes: true })) latest = Math.max(latest, newestMtime(join57(path, e.name)));
|
|
26358
26479
|
return latest;
|
|
26359
26480
|
}
|
|
26360
26481
|
function bundleStaleness(i) {
|
|
26361
26482
|
if (i.built === null || i.compiled) return null;
|
|
26362
|
-
const src =
|
|
26363
|
-
if (!
|
|
26483
|
+
const src = join57(i.home, "src");
|
|
26484
|
+
if (!existsSync56(src)) return null;
|
|
26364
26485
|
if (i.built !== i.current) {
|
|
26365
26486
|
return { kind: "version", builtVersion: i.built, message: `running a bundle built from ${i.built} (package.json names ${i.current}); ${REBUILD_HINT}` };
|
|
26366
26487
|
}
|
|
26367
|
-
const bundle = statSafe(
|
|
26488
|
+
const bundle = statSafe(join57(i.home, "dist", "cli.js"));
|
|
26368
26489
|
if (bundle === null) return null;
|
|
26369
26490
|
if (newestMtime(src) > bundle) {
|
|
26370
26491
|
return { kind: "source", builtVersion: i.built, message: `running a bundle older than the source in src/ (both ${i.current}); ${REBUILD_HINT}` };
|
|
@@ -26373,7 +26494,7 @@ function bundleStaleness(i) {
|
|
|
26373
26494
|
}
|
|
26374
26495
|
function statSafe(p) {
|
|
26375
26496
|
try {
|
|
26376
|
-
return
|
|
26497
|
+
return statSync17(p).mtimeMs;
|
|
26377
26498
|
} catch {
|
|
26378
26499
|
return null;
|
|
26379
26500
|
}
|
|
@@ -26531,8 +26652,8 @@ async function unregisterEndpoint(workspaceId, info, d) {
|
|
|
26531
26652
|
import { createServer as createHttpServer } from "http";
|
|
26532
26653
|
import { spawn as spawn9 } from "child_process";
|
|
26533
26654
|
import { randomBytes as randomBytes2 } from "crypto";
|
|
26534
|
-
import { existsSync as
|
|
26535
|
-
import { join as
|
|
26655
|
+
import { existsSync as existsSync57, mkdirSync as mkdirSync39, readFileSync as readFileSync53, writeFileSync as writeFileSync41, unlinkSync as unlinkSync5, readdirSync as readdirSync19 } from "fs";
|
|
26656
|
+
import { join as join58 } from "path";
|
|
26536
26657
|
|
|
26537
26658
|
// src/secret-compare.ts
|
|
26538
26659
|
import { timingSafeEqual } from "crypto";
|
|
@@ -26625,21 +26746,21 @@ var defaultSpawn2 = (cmd, args, env) => {
|
|
|
26625
26746
|
return child;
|
|
26626
26747
|
};
|
|
26627
26748
|
function syncDaemonStatePath(stateDir, workspaceId) {
|
|
26628
|
-
return
|
|
26749
|
+
return join58(stateDir, "passengers", `${workspaceId}-sync.json`);
|
|
26629
26750
|
}
|
|
26630
26751
|
function readPersistedSyncDaemon(stateDir, workspaceId) {
|
|
26631
26752
|
const path = syncDaemonStatePath(stateDir, workspaceId);
|
|
26632
|
-
if (!
|
|
26753
|
+
if (!existsSync57(path)) return void 0;
|
|
26633
26754
|
try {
|
|
26634
|
-
return JSON.parse(
|
|
26755
|
+
return JSON.parse(readFileSync53(path, "utf8"));
|
|
26635
26756
|
} catch {
|
|
26636
26757
|
return void 0;
|
|
26637
26758
|
}
|
|
26638
26759
|
}
|
|
26639
26760
|
function writePersistedSyncDaemon(stateDir, state) {
|
|
26640
26761
|
const path = syncDaemonStatePath(stateDir, state.workspaceId);
|
|
26641
|
-
mkdirSync39(
|
|
26642
|
-
|
|
26762
|
+
mkdirSync39(join58(stateDir, "passengers"), { recursive: true });
|
|
26763
|
+
writeFileSync41(path, `${JSON.stringify(state, null, 2)}
|
|
26643
26764
|
`);
|
|
26644
26765
|
}
|
|
26645
26766
|
function removePersistedSyncDaemon(stateDir, workspaceId) {
|
|
@@ -26659,10 +26780,10 @@ function waitForExit(pid, alive, timeoutMs = 5e3) {
|
|
|
26659
26780
|
}
|
|
26660
26781
|
}
|
|
26661
26782
|
function readAllPersistedSyncWorkspaceIds(stateDir) {
|
|
26662
|
-
const dir =
|
|
26663
|
-
if (!
|
|
26783
|
+
const dir = join58(stateDir, "passengers");
|
|
26784
|
+
if (!existsSync57(dir)) return [];
|
|
26664
26785
|
const suffix = "-sync.json";
|
|
26665
|
-
return
|
|
26786
|
+
return readdirSync19(dir).filter((f) => f.endsWith(suffix)).map((f) => f.slice(0, -suffix.length));
|
|
26666
26787
|
}
|
|
26667
26788
|
function syncPassengerSyncDaemons(plans, cfg, stateDir, deps = {}) {
|
|
26668
26789
|
const alive = deps.isPidAlive ?? isPidAlive;
|
|
@@ -27126,7 +27247,7 @@ async function startWorktreeIntel(d) {
|
|
|
27126
27247
|
}
|
|
27127
27248
|
|
|
27128
27249
|
// src/contract-refusal.ts
|
|
27129
|
-
import { join as
|
|
27250
|
+
import { join as join59 } from "path";
|
|
27130
27251
|
function contractFixers(dir, baseRef, tickets, locate) {
|
|
27131
27252
|
const out = [];
|
|
27132
27253
|
for (const t of tickets) {
|
|
@@ -27138,7 +27259,7 @@ function contractFixers(dir, baseRef, tickets, locate) {
|
|
|
27138
27259
|
const text2 = gitOk(dir, ["show", `${branch}:${file}`]);
|
|
27139
27260
|
if (text2 === null) continue;
|
|
27140
27261
|
try {
|
|
27141
|
-
parseRepoConfig(text2,
|
|
27262
|
+
parseRepoConfig(text2, join59(dir, file));
|
|
27142
27263
|
} catch (e) {
|
|
27143
27264
|
if (e instanceof RepoConfigError) continue;
|
|
27144
27265
|
throw e;
|
|
@@ -27152,19 +27273,19 @@ function contractFixers(dir, baseRef, tickets, locate) {
|
|
|
27152
27273
|
import { createHash as createHash11 } from "crypto";
|
|
27153
27274
|
import {
|
|
27154
27275
|
chmodSync as chmodSync4,
|
|
27155
|
-
closeSync as
|
|
27156
|
-
existsSync as
|
|
27157
|
-
fstatSync,
|
|
27158
|
-
openSync as
|
|
27159
|
-
readSync as
|
|
27160
|
-
readdirSync as
|
|
27276
|
+
closeSync as closeSync7,
|
|
27277
|
+
existsSync as existsSync58,
|
|
27278
|
+
fstatSync as fstatSync2,
|
|
27279
|
+
openSync as openSync7,
|
|
27280
|
+
readSync as readSync4,
|
|
27281
|
+
readdirSync as readdirSync20,
|
|
27161
27282
|
rmSync as rmSync24,
|
|
27162
|
-
statSync as
|
|
27283
|
+
statSync as statSync18,
|
|
27163
27284
|
watch
|
|
27164
27285
|
} from "fs";
|
|
27165
27286
|
import { createConnection } from "net";
|
|
27166
27287
|
import { createServer as createServer2 } from "http";
|
|
27167
|
-
import { basename as basename15, dirname as dirname35, join as
|
|
27288
|
+
import { basename as basename15, dirname as dirname35, join as join60 } from "path";
|
|
27168
27289
|
import { execFile as execFile6, spawn as spawn12 } from "child_process";
|
|
27169
27290
|
|
|
27170
27291
|
// src/periscope-control.ts
|
|
@@ -27401,7 +27522,7 @@ function runCrew(args, onLine, timeoutMs = 20 * 6e4) {
|
|
|
27401
27522
|
// src/control-api.ts
|
|
27402
27523
|
var PAUSABLE = ["dev", "design", "qa"];
|
|
27403
27524
|
var CONTROL_SOCKET_NAME = "control.sock";
|
|
27404
|
-
var controlSocketFor = (stateDir) =>
|
|
27525
|
+
var controlSocketFor = (stateDir) => join60(stateDir, CONTROL_SOCKET_NAME);
|
|
27405
27526
|
var MAX_SOCKET_PATH = 100;
|
|
27406
27527
|
var MAX_TAIL_BYTES = 1024 * 1024;
|
|
27407
27528
|
var MAX_WAIT_SECONDS = 30;
|
|
@@ -27488,30 +27609,30 @@ function candidates(live2, rotated) {
|
|
|
27488
27609
|
const out = [live2];
|
|
27489
27610
|
if (!rotated) return out;
|
|
27490
27611
|
try {
|
|
27491
|
-
for (const n of
|
|
27612
|
+
for (const n of readdirSync20(dirname35(live2))) if (ROTATED_EVENTS_RE.test(n)) out.push(join60(dirname35(live2), n));
|
|
27492
27613
|
} catch {
|
|
27493
27614
|
}
|
|
27494
27615
|
return out;
|
|
27495
27616
|
}
|
|
27496
27617
|
function readRange(path, from, max) {
|
|
27497
|
-
const fd =
|
|
27618
|
+
const fd = openSync7(path, "r");
|
|
27498
27619
|
try {
|
|
27499
|
-
const size =
|
|
27620
|
+
const size = fstatSync2(fd).size;
|
|
27500
27621
|
const len = Math.max(0, Math.min(size - from, max));
|
|
27501
27622
|
const buf = Buffer.alloc(len);
|
|
27502
27623
|
let got = 0;
|
|
27503
27624
|
while (got < len) {
|
|
27504
|
-
const n =
|
|
27625
|
+
const n = readSync4(fd, buf, got, len - got, from + got);
|
|
27505
27626
|
if (n <= 0) break;
|
|
27506
27627
|
got += n;
|
|
27507
27628
|
}
|
|
27508
27629
|
return { text: buf.subarray(0, got).toString("utf8"), size };
|
|
27509
27630
|
} finally {
|
|
27510
|
-
|
|
27631
|
+
closeSync7(fd);
|
|
27511
27632
|
}
|
|
27512
27633
|
}
|
|
27513
27634
|
function lastLines2(path, n) {
|
|
27514
|
-
const st =
|
|
27635
|
+
const st = statSync18(path);
|
|
27515
27636
|
const cursorAt = (off) => encodeCursor({ dev: st.dev, ino: st.ino, off });
|
|
27516
27637
|
if (n <= 0 || st.size === 0) return { lines: [], cursor: cursorAt(st.size), reset: false };
|
|
27517
27638
|
let start = st.size;
|
|
@@ -27532,7 +27653,7 @@ function lastLines2(path, n) {
|
|
|
27532
27653
|
}
|
|
27533
27654
|
function readTail(live2, opts) {
|
|
27534
27655
|
const max = opts.maxBytes ?? MAX_TAIL_BYTES;
|
|
27535
|
-
if (!
|
|
27656
|
+
if (!existsSync58(live2)) {
|
|
27536
27657
|
return { lines: [], cursor: opts.after ?? encodeCursor({ dev: 0, ino: 0, off: 0 }), reset: false };
|
|
27537
27658
|
}
|
|
27538
27659
|
const cur = opts.after ? decodeCursor(opts.after) : null;
|
|
@@ -27545,7 +27666,7 @@ function readTail(live2, opts) {
|
|
|
27545
27666
|
} else {
|
|
27546
27667
|
const found = candidates(live2, opts.rotated ?? false).find((p) => {
|
|
27547
27668
|
try {
|
|
27548
|
-
const s =
|
|
27669
|
+
const s = statSync18(p);
|
|
27549
27670
|
return s.ino === cur.ino && s.dev === cur.dev;
|
|
27550
27671
|
} catch {
|
|
27551
27672
|
return false;
|
|
@@ -27556,7 +27677,7 @@ function readTail(live2, opts) {
|
|
|
27556
27677
|
off = cur.off;
|
|
27557
27678
|
} else reset = true;
|
|
27558
27679
|
}
|
|
27559
|
-
let size =
|
|
27680
|
+
let size = statSync18(path).size;
|
|
27560
27681
|
if (off > size) {
|
|
27561
27682
|
off = 0;
|
|
27562
27683
|
reset = true;
|
|
@@ -27564,12 +27685,12 @@ function readTail(live2, opts) {
|
|
|
27564
27685
|
if (off >= size && path !== live2) {
|
|
27565
27686
|
path = live2;
|
|
27566
27687
|
off = 0;
|
|
27567
|
-
size =
|
|
27688
|
+
size = statSync18(path).size;
|
|
27568
27689
|
}
|
|
27569
27690
|
const { text: text2 } = readRange(path, off, max);
|
|
27570
27691
|
const cut = text2.lastIndexOf("\n");
|
|
27571
27692
|
const whole = cut < 0 ? "" : text2.slice(0, cut + 1);
|
|
27572
|
-
const st =
|
|
27693
|
+
const st = statSync18(path);
|
|
27573
27694
|
return {
|
|
27574
27695
|
lines: whole.split("\n").filter((l) => l.length),
|
|
27575
27696
|
cursor: encodeCursor({ dev: st.dev, ino: st.ino, off: off + Buffer.byteLength(whole) }),
|
|
@@ -27671,6 +27792,13 @@ async function postRunMessage(deps, run4, body) {
|
|
|
27671
27792
|
const acceptsInput = input.accepts();
|
|
27672
27793
|
const state = acceptsInput ? await input.deliver(recorded, body.author || void 0) : "carried_forward";
|
|
27673
27794
|
if (!acceptsInput) await markMessage(input.target, rowId, recorded.id, "carried_forward");
|
|
27795
|
+
appendRunNote(live2.streamPath, {
|
|
27796
|
+
id: recorded.id,
|
|
27797
|
+
text: text2,
|
|
27798
|
+
author: body.author || null,
|
|
27799
|
+
at: recorded.occurredAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
27800
|
+
state: state === "delivered" ? "delivered" : "carried_forward"
|
|
27801
|
+
});
|
|
27674
27802
|
return reply2(200, { cycleId: recorded.id, state, acceptsInput });
|
|
27675
27803
|
} catch (e) {
|
|
27676
27804
|
return err2(409, `the platform did not take the note: ${e.message}. ${carry}`);
|
|
@@ -27711,8 +27839,8 @@ async function route(deps, method, url, req, abort) {
|
|
|
27711
27839
|
if (p.startsWith("/streams/") && get2) {
|
|
27712
27840
|
const run4 = decodeURIComponent(p.slice("/streams/".length));
|
|
27713
27841
|
if (!RUN_NAME_RE.test(run4) || run4.includes("..") || /\.(pid|meta\.json|events\.jsonl)$/.test(run4)) return err2(400, "not a run name");
|
|
27714
|
-
const file =
|
|
27715
|
-
if (!
|
|
27842
|
+
const file = join60(deps.stateDir, "streams", run4.endsWith(".jsonl") ? run4 : `${run4}.jsonl`);
|
|
27843
|
+
if (!existsSync58(file)) return err2(404, "no such run");
|
|
27716
27844
|
return tailReply(file, url.searchParams, false, abort);
|
|
27717
27845
|
}
|
|
27718
27846
|
const note = /^\/streams\/([^/]+)\/messages$/.exec(p);
|
|
@@ -27759,7 +27887,7 @@ function send2(res, r) {
|
|
|
27759
27887
|
res.end(body);
|
|
27760
27888
|
}
|
|
27761
27889
|
async function socketIsStale(path) {
|
|
27762
|
-
if (!
|
|
27890
|
+
if (!existsSync58(path)) return false;
|
|
27763
27891
|
return new Promise((resolve8) => {
|
|
27764
27892
|
const c = createConnection(path);
|
|
27765
27893
|
c.once("connect", () => {
|
|
@@ -27778,7 +27906,7 @@ async function startControlServer(deps) {
|
|
|
27778
27906
|
return null;
|
|
27779
27907
|
}
|
|
27780
27908
|
if (await socketIsStale(path)) rmSync24(path, { force: true });
|
|
27781
|
-
else if (
|
|
27909
|
+
else if (existsSync58(path)) {
|
|
27782
27910
|
log(`control API not started: ${path} is in use by another process`);
|
|
27783
27911
|
return null;
|
|
27784
27912
|
}
|
|
@@ -27864,31 +27992,31 @@ function crewJson(args, timeoutMs = 6e4) {
|
|
|
27864
27992
|
|
|
27865
27993
|
// src/periscope-mcp.ts
|
|
27866
27994
|
import { lstat, mkdir, readdir, readFile, readlink, realpath, rm, stat, writeFile } from "fs/promises";
|
|
27867
|
-
import { basename as basename16, dirname as dirname36, isAbsolute as isAbsolute5, join as
|
|
27995
|
+
import { basename as basename16, dirname as dirname36, isAbsolute as isAbsolute5, join as join62, relative as relative2, resolve as resolve6, sep } from "path";
|
|
27868
27996
|
import { z } from "zod";
|
|
27869
27997
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
27870
27998
|
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
27871
27999
|
|
|
27872
28000
|
// src/periscope-endpoints.ts
|
|
27873
28001
|
import { randomBytes as randomBytes3 } from "crypto";
|
|
27874
|
-
import { chmodSync as chmodSync5, existsSync as
|
|
27875
|
-
import { join as
|
|
27876
|
-
var secretDir = (stateDir) =>
|
|
27877
|
-
var secretFile = (stateDir, id) =>
|
|
27878
|
-
var endpointDir = (stateDir) =>
|
|
27879
|
-
var endpointFile = (stateDir, id) =>
|
|
28002
|
+
import { chmodSync as chmodSync5, existsSync as existsSync59, mkdirSync as mkdirSync41, readdirSync as readdirSync21, readFileSync as readFileSync54, rmSync as rmSync25, writeFileSync as writeFileSync42 } from "fs";
|
|
28003
|
+
import { join as join61 } from "path";
|
|
28004
|
+
var secretDir = (stateDir) => join61(stateDir, "periscope-mcp");
|
|
28005
|
+
var secretFile = (stateDir, id) => join61(secretDir(stateDir), `${id}.json`);
|
|
28006
|
+
var endpointDir = (stateDir) => join61(stateDir, "periscope-endpoints");
|
|
28007
|
+
var endpointFile = (stateDir, id) => join61(endpointDir(stateDir), `${id}.json`);
|
|
27880
28008
|
function mintPeriscopeSecret(stateDir, ticketRecordId) {
|
|
27881
28009
|
mkdirSync41(secretDir(stateDir), { recursive: true, mode: 448 });
|
|
27882
28010
|
const secret = randomBytes3(32).toString("base64url");
|
|
27883
28011
|
const file = secretFile(stateDir, ticketRecordId);
|
|
27884
|
-
|
|
28012
|
+
writeFileSync42(file, `${JSON.stringify({ secret })}
|
|
27885
28013
|
`, { mode: 384 });
|
|
27886
28014
|
chmodSync5(file, 384);
|
|
27887
28015
|
return secret;
|
|
27888
28016
|
}
|
|
27889
28017
|
function readPeriscopeSecret(stateDir, ticketRecordId) {
|
|
27890
28018
|
try {
|
|
27891
|
-
const v = JSON.parse(
|
|
28019
|
+
const v = JSON.parse(readFileSync54(secretFile(stateDir, ticketRecordId), "utf8"));
|
|
27892
28020
|
return typeof v.secret === "string" && v.secret ? v.secret : void 0;
|
|
27893
28021
|
} catch {
|
|
27894
28022
|
return void 0;
|
|
@@ -27899,14 +28027,14 @@ function removePeriscopeSecret(stateDir, ticketRecordId) {
|
|
|
27899
28027
|
}
|
|
27900
28028
|
function readPeriscopeEndpoint(stateDir, ticketRecordId) {
|
|
27901
28029
|
try {
|
|
27902
|
-
return JSON.parse(
|
|
28030
|
+
return JSON.parse(readFileSync54(endpointFile(stateDir, ticketRecordId), "utf8"));
|
|
27903
28031
|
} catch {
|
|
27904
28032
|
return void 0;
|
|
27905
28033
|
}
|
|
27906
28034
|
}
|
|
27907
28035
|
function writePeriscopeEndpoint(stateDir, rec) {
|
|
27908
28036
|
mkdirSync41(endpointDir(stateDir), { recursive: true });
|
|
27909
|
-
|
|
28037
|
+
writeFileSync42(endpointFile(stateDir, rec.ticketRecordId), `${JSON.stringify(rec, null, 2)}
|
|
27910
28038
|
`);
|
|
27911
28039
|
}
|
|
27912
28040
|
function removePeriscopeEndpointRecord(stateDir, ticketRecordId) {
|
|
@@ -27914,9 +28042,9 @@ function removePeriscopeEndpointRecord(stateDir, ticketRecordId) {
|
|
|
27914
28042
|
}
|
|
27915
28043
|
function listPeriscopeEndpoints(stateDir) {
|
|
27916
28044
|
const dir = endpointDir(stateDir);
|
|
27917
|
-
if (!
|
|
28045
|
+
if (!existsSync59(dir)) return [];
|
|
27918
28046
|
const out = [];
|
|
27919
|
-
for (const name of
|
|
28047
|
+
for (const name of readdirSync21(dir)) {
|
|
27920
28048
|
if (!name.endsWith(".json")) continue;
|
|
27921
28049
|
const rec = readPeriscopeEndpoint(stateDir, name.slice(0, -".json".length));
|
|
27922
28050
|
if (rec && typeof rec.endpointId === "string") out.push(rec);
|
|
@@ -28017,13 +28145,13 @@ async function resolveInWorktree(root, requested) {
|
|
|
28017
28145
|
let abs;
|
|
28018
28146
|
if (isAbsolute5(requested)) {
|
|
28019
28147
|
abs = resolve6(requested);
|
|
28020
|
-
if (isInside(root, abs)) abs =
|
|
28148
|
+
if (isInside(root, abs)) abs = join62(realRoot, relative2(root, abs));
|
|
28021
28149
|
} else {
|
|
28022
28150
|
abs = resolve6(realRoot, requested);
|
|
28023
28151
|
}
|
|
28024
28152
|
if (!isInside(realRoot, abs)) throw new PathRefusal(`${requested} is outside this periscope's worktree`);
|
|
28025
28153
|
const { real, rest } = await realAncestor(abs);
|
|
28026
|
-
const final = rest ?
|
|
28154
|
+
const final = rest ? join62(real, rest) : real;
|
|
28027
28155
|
if (!isInside(realRoot, final)) throw new PathRefusal(`${requested} is outside this periscope's worktree`);
|
|
28028
28156
|
if (relative2(realRoot, final).split(sep).includes(".git")) throw new PathRefusal(".git is not reachable from a periscope");
|
|
28029
28157
|
return final;
|
|
@@ -28091,7 +28219,7 @@ function createPeriscopeMcpServer(d, sc) {
|
|
|
28091
28219
|
const entries = (await readdir(abs, { withFileTypes: true })).filter((e) => e.name !== ".git");
|
|
28092
28220
|
const lines2 = await Promise.all(entries.map(async (e) => {
|
|
28093
28221
|
if (e.isDirectory()) return `[DIR] ${e.name}`;
|
|
28094
|
-
const size = (await lstat(
|
|
28222
|
+
const size = (await lstat(join62(abs, e.name))).size;
|
|
28095
28223
|
return `[FILE] ${e.name} (${size} bytes)`;
|
|
28096
28224
|
}));
|
|
28097
28225
|
return text(lines2.join("\n") || "(empty)");
|
|
@@ -28157,7 +28285,7 @@ function createPeriscopeMcpServer(d, sc) {
|
|
|
28157
28285
|
annotations: { readOnlyHint: false, destructiveHint: true, openWorldHint: false }
|
|
28158
28286
|
}, async ({ path }) => {
|
|
28159
28287
|
const parent = await inTree(dirname36(path) === "" ? "." : dirname36(path));
|
|
28160
|
-
const abs =
|
|
28288
|
+
const abs = join62(parent, basename16(path));
|
|
28161
28289
|
if (basename16(path) === ".git" || abs === parent) return text("path must name a file", true);
|
|
28162
28290
|
const st = await lstat(abs).catch(() => void 0);
|
|
28163
28291
|
if (!st) return text(`${path} does not exist`, true);
|
|
@@ -28652,7 +28780,7 @@ if (command === "provision") {
|
|
|
28652
28780
|
process.exit(outcome.code);
|
|
28653
28781
|
}
|
|
28654
28782
|
if (command === "pool-member") {
|
|
28655
|
-
const pool = poolConfigFrom(argv, process.env, () =>
|
|
28783
|
+
const pool = poolConfigFrom(argv, process.env, () => readFileSync55(0, "utf8"));
|
|
28656
28784
|
if (typeof pool === "string") {
|
|
28657
28785
|
process.stderr.write(`crew pool-member: ${pool}
|
|
28658
28786
|
`);
|
|
@@ -28973,7 +29101,7 @@ if (command === "passenger-sync-daemon") {
|
|
|
28973
29101
|
} else {
|
|
28974
29102
|
const toleratesNoRoutes = command === "credential" || command === "forge" || command === "repos" || command === "ship" || command === "disconnect" && flag("reset") || command === "deprovision" || command === "connect" && flag("sign-out");
|
|
28975
29103
|
const configless = command === "connect" && flag("sign-out") || command === "disconnect" && flag("reset") || command === "deprovision";
|
|
28976
|
-
if (configless && !
|
|
29104
|
+
if (configless && !existsSync60(findConfigFile(CREW_HOME))) {
|
|
28977
29105
|
cfg = loadConfig(CREW_HOME, firstRunConfigPath(), { text: "ship: {}\n", allowNoRoutes: true });
|
|
28978
29106
|
} else {
|
|
28979
29107
|
cfg = loadConfig(CREW_HOME, void 0, toleratesNoRoutes ? { allowNoRoutes: true } : {});
|
|
@@ -28996,7 +29124,7 @@ if (command === "passenger-sync-daemon") {
|
|
|
28996
29124
|
throw e;
|
|
28997
29125
|
}
|
|
28998
29126
|
if (command === "credential") {
|
|
28999
|
-
const r = runCredential(positional[1],
|
|
29127
|
+
const r = runCredential(positional[1], readFileSync55(0, "utf8"), cfg.ship.forges, cfg.ship.stateDir, process.env, !flag("no-miss"));
|
|
29000
29128
|
process.stdout.write(r.out);
|
|
29001
29129
|
process.stderr.write(r.err);
|
|
29002
29130
|
process.exit(r.code);
|
|
@@ -29008,9 +29136,9 @@ if (command === "passenger-sync-daemon") {
|
|
|
29008
29136
|
forges: cfg.ship.forges,
|
|
29009
29137
|
stateDir: cfg.ship.stateDir,
|
|
29010
29138
|
configFile: cfg.configFile,
|
|
29011
|
-
readFile: (p) =>
|
|
29012
|
-
writeFile: (p, t) =>
|
|
29013
|
-
stdin: () =>
|
|
29139
|
+
readFile: (p) => readFileSync55(p, "utf8"),
|
|
29140
|
+
writeFile: (p, t) => writeFileSync43(p, t),
|
|
29141
|
+
stdin: () => readFileSync55(0, "utf8"),
|
|
29014
29142
|
env: process.env
|
|
29015
29143
|
}
|
|
29016
29144
|
);
|
|
@@ -29349,8 +29477,8 @@ if (command === "passenger-sync-daemon") {
|
|
|
29349
29477
|
}
|
|
29350
29478
|
if (host === "linux" && hasSystemd) {
|
|
29351
29479
|
const label = labelFor(CREW_HOME, "run");
|
|
29352
|
-
const staleTimer =
|
|
29353
|
-
if (
|
|
29480
|
+
const staleTimer = join63(homedir11(), ".config", "systemd", "user", `${label}.timer`);
|
|
29481
|
+
if (existsSync60(staleTimer)) {
|
|
29354
29482
|
process.stdout.write(
|
|
29355
29483
|
`removing stale run timer from before the persistent-service cutover: ${staleTimer}${dryRun ? " (dry run)" : ""}
|
|
29356
29484
|
`
|
|
@@ -29379,7 +29507,7 @@ if (command === "passenger-sync-daemon") {
|
|
|
29379
29507
|
const { settled: doctorRepos, errors: refusedRepos } = await settleRepos(reposOf(c), (t) => t.name, (t) => resolveOneRepo(c, t));
|
|
29380
29508
|
for (const e of refusedRepos) problems.push(`repo ${e.repo}: ${e.detail}`);
|
|
29381
29509
|
for (const r of doctorRepos) {
|
|
29382
|
-
if (!
|
|
29510
|
+
if (!existsSync60(r.dir)) problems.push(`repo ${r.name}: ${r.dir} is missing on disk`);
|
|
29383
29511
|
if (!satisfies(host, r.config.platform)) problems.push(`repo ${r.name}: requires ${r.config.platform}, this host is ${host}`);
|
|
29384
29512
|
readiness.push(...validateEffective(r.config).map((p) => `repo ${r.name}: ${p}`));
|
|
29385
29513
|
}
|
|
@@ -29415,7 +29543,7 @@ if (command === "passenger-sync-daemon") {
|
|
|
29415
29543
|
}
|
|
29416
29544
|
async function doctorFix(o) {
|
|
29417
29545
|
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))));
|
|
29418
|
-
const unitExists = (p) =>
|
|
29546
|
+
const unitExists = (p) => existsSync60(p);
|
|
29419
29547
|
const crontab = o.host === "linux" ? spawnSync14("crontab", ["-l"], { encoding: "utf8" }).stdout ?? "" : "";
|
|
29420
29548
|
const schedulerAbsent = o.host !== "windows" ? !schedulerInstalled(planInstall(cfg.ship, CREW_HOME, o.host, detectSystemd(), "run", installContext()), unitExists, crontab) : true;
|
|
29421
29549
|
const plan = planFix({ routes, schedulerAbsent, host: o.host });
|
|
@@ -29432,7 +29560,7 @@ if (command === "passenger-sync-daemon") {
|
|
|
29432
29560
|
for (const a of plan.actions) {
|
|
29433
29561
|
if (a.kind === "enable") {
|
|
29434
29562
|
if (prompter && !await prompter.confirm(`Route ${a.route} passes every check \u2014 set enabled: true in ${cfg.configFile}?`, false)) continue;
|
|
29435
|
-
|
|
29563
|
+
writeFileSync43(cfg.configFile, planEnable(readFileSync55(cfg.configFile, "utf8"), a.route));
|
|
29436
29564
|
enabledSound.add(a.route);
|
|
29437
29565
|
changed2.push(`enabled route ${a.route} in ${cfg.configFile}`);
|
|
29438
29566
|
} else {
|
|
@@ -29661,7 +29789,7 @@ ${changed2.map((c) => ` - ${c}
|
|
|
29661
29789
|
harnessBin: "claude",
|
|
29662
29790
|
...contract.sandboxNetwork ? { extraHosts: contract.sandboxNetwork.hosts, toolchains: contract.sandboxNetwork.toolchains } : {}
|
|
29663
29791
|
},
|
|
29664
|
-
policyFile:
|
|
29792
|
+
policyFile: join63(cfg.ship.stateDir, "release", `${target.name}.policy.yaml`),
|
|
29665
29793
|
repo: mirror,
|
|
29666
29794
|
origin: forgeDescriptorFor(forgeHost).httpsUrl(mirror.host, mirror.path),
|
|
29667
29795
|
base: effective.branch.base,
|
|
@@ -30928,7 +31056,7 @@ ${f.tail.trimEnd()}
|
|
|
30928
31056
|
logFile: cfg.ship.logFile
|
|
30929
31057
|
});
|
|
30930
31058
|
}
|
|
30931
|
-
const watchPaths = isCompiledBinary(import.meta.url) ? [process.execPath] : [
|
|
31059
|
+
const watchPaths = isCompiledBinary(import.meta.url) ? [process.execPath] : [join63(CREW_HOME, "src"), join63(CREW_HOME, "dist"), join63(CREW_HOME, "bin")];
|
|
30932
31060
|
const configPaths = daemonConfigPaths(cfg);
|
|
30933
31061
|
watchPaths.push(...configPaths);
|
|
30934
31062
|
noteDaemonStarted(cfg.ship.stateDir);
|
|
@@ -31266,10 +31394,10 @@ ${f.tail.trimEnd()}
|
|
|
31266
31394
|
`);
|
|
31267
31395
|
if (!dryRun) {
|
|
31268
31396
|
const resolvedPath = resolvedPathFor(cfg.ship.stateDir, target.route);
|
|
31269
|
-
const raw =
|
|
31397
|
+
const raw = existsSync60(resolvedPath) ? JSON.parse(readFileSync55(resolvedPath, "utf8")) : {};
|
|
31270
31398
|
raw.agentSkills = result.agentSkills;
|
|
31271
31399
|
mkdirSync42(dirOf2(resolvedPath), { recursive: true });
|
|
31272
|
-
|
|
31400
|
+
writeFileSync43(resolvedPath, `${JSON.stringify(raw, null, 2)}
|
|
31273
31401
|
`);
|
|
31274
31402
|
}
|
|
31275
31403
|
if (result.outcomes.some((o) => o.action === "diverged")) process.exitCode = 1;
|
|
@@ -31292,7 +31420,7 @@ ${f.tail.trimEnd()}
|
|
|
31292
31420
|
throw e;
|
|
31293
31421
|
}
|
|
31294
31422
|
const oldName = cfg.ship.name;
|
|
31295
|
-
|
|
31423
|
+
writeFileSync43(cfg.configFile, setShipNameInYaml(readFileSync55(cfg.configFile, "utf8"), newName));
|
|
31296
31424
|
cfg.ship.name = newName;
|
|
31297
31425
|
let renameMachineId;
|
|
31298
31426
|
try {
|
|
@@ -31339,7 +31467,7 @@ ${f.tail.trimEnd()}
|
|
|
31339
31467
|
process.exit(2);
|
|
31340
31468
|
};
|
|
31341
31469
|
if (sub !== "add" && sub !== "list" && sub !== "clone" && sub !== "hooks" && sub !== "check") usage2();
|
|
31342
|
-
const configText =
|
|
31470
|
+
const configText = readFileSync55(cfg.configFile, "utf8");
|
|
31343
31471
|
if (sub === "check") {
|
|
31344
31472
|
try {
|
|
31345
31473
|
const routeArg = value("route") ?? positional[2];
|
|
@@ -31371,16 +31499,16 @@ ${f.tail.trimEnd()}
|
|
|
31371
31499
|
try {
|
|
31372
31500
|
const a = parseHooksArgs(positional.slice(2), routeNamesOf(configText));
|
|
31373
31501
|
const dir = repoDirOf(configText, dirname37(cfg.configFile), a.route, a.name);
|
|
31374
|
-
if (!
|
|
31375
|
-
const files = { exists: (r) =>
|
|
31502
|
+
if (!existsSync60(dir)) throw new ReposError(`${dir} does not exist on disk`);
|
|
31503
|
+
const files = { exists: (r) => existsSync60(resolvePath(dir, r)), list: (r) => {
|
|
31376
31504
|
try {
|
|
31377
|
-
return
|
|
31505
|
+
return readdirSync22(resolvePath(dir, r));
|
|
31378
31506
|
} catch {
|
|
31379
31507
|
return [];
|
|
31380
31508
|
}
|
|
31381
31509
|
}, read: (r) => {
|
|
31382
31510
|
try {
|
|
31383
|
-
return
|
|
31511
|
+
return readFileSync55(resolvePath(dir, r), "utf8");
|
|
31384
31512
|
} catch {
|
|
31385
31513
|
return void 0;
|
|
31386
31514
|
}
|
|
@@ -31422,19 +31550,19 @@ ${f.tail.trimEnd()}
|
|
|
31422
31550
|
let cleared;
|
|
31423
31551
|
if (clear2) {
|
|
31424
31552
|
const plan = clearRouteHooks(configText, a.route, a.name);
|
|
31425
|
-
if (plan.removed.length > 0)
|
|
31553
|
+
if (plan.removed.length > 0) writeFileSync43(cfg.configFile, plan.text);
|
|
31426
31554
|
cleared = { file: cfg.configFile, removed: plan.removed };
|
|
31427
31555
|
}
|
|
31428
31556
|
if (write && suggestion.source === null && recipeIds.length === 0 && hookSpecs.length === 0) throw new ReposError(`nothing to write: ${suggestion.notes[0]}`);
|
|
31429
31557
|
if (write === "route") {
|
|
31430
31558
|
const plan = planRouteHooks(configText, a.route, a.name, picked.hooks, { replace: flag("replace") });
|
|
31431
|
-
|
|
31559
|
+
writeFileSync43(cfg.configFile, plan.text);
|
|
31432
31560
|
written = { target: "route", file: cfg.configFile, hooks: plan.written, kept: plan.kept, replaced: plan.replaced };
|
|
31433
31561
|
} else if (write === "repo") {
|
|
31434
31562
|
const have = existingRepoConfig(files);
|
|
31435
31563
|
if (have) throw new ReposError(`${resolvePath(dir, have)} already exists; not overwriting it`);
|
|
31436
31564
|
const file = resolvePath(dir, ".crew.yaml");
|
|
31437
|
-
|
|
31565
|
+
writeFileSync43(file, starterRepoConfig(picked.hooks, picked.release), { flag: "wx" });
|
|
31438
31566
|
written = { target: "repo", file, hooks: Object.keys(picked.hooks), kept: [], replaced: [] };
|
|
31439
31567
|
}
|
|
31440
31568
|
if (flag("json")) {
|
|
@@ -31490,7 +31618,7 @@ ${f.tail.trimEnd()}
|
|
|
31490
31618
|
if (sub === "list" && !routeName) usage2();
|
|
31491
31619
|
if (sub === "add") {
|
|
31492
31620
|
try {
|
|
31493
|
-
const a = parseAddArgs(positional.slice(2), routeNamesOf(configText), (p) =>
|
|
31621
|
+
const a = parseAddArgs(positional.slice(2), routeNamesOf(configText), (p) => existsSync60(resolvePath(p.replace(/^~(?=\/|$)/, homedir11()))));
|
|
31494
31622
|
routeName = a.route;
|
|
31495
31623
|
addPath = a.path;
|
|
31496
31624
|
addName = a.name;
|
|
@@ -31520,7 +31648,7 @@ ${f.tail.trimEnd()}
|
|
|
31520
31648
|
const resolvedFile = resolvedPathFor(cfg.ship.stateDir, routeName);
|
|
31521
31649
|
if (sub === "list" || sub === "add") {
|
|
31522
31650
|
const liveRoute = cfg.routes.find((r) => r.route === routeName);
|
|
31523
|
-
if (liveRoute?.resolved?.reposModelId &&
|
|
31651
|
+
if (liveRoute?.resolved?.reposModelId && existsSync60(resolvedFile) && !dryRun) {
|
|
31524
31652
|
try {
|
|
31525
31653
|
await hydrateApiKeys([liveRoute]);
|
|
31526
31654
|
persistRepoRows(cfg.ship.stateDir, liveRoute.route, await new Tracker(liveRoute, cfg.ship).repoRowsForMap());
|
|
@@ -31529,16 +31657,16 @@ ${f.tail.trimEnd()}
|
|
|
31529
31657
|
}
|
|
31530
31658
|
}
|
|
31531
31659
|
let resolvedRemotes;
|
|
31532
|
-
if (
|
|
31660
|
+
if (existsSync60(resolvedFile)) {
|
|
31533
31661
|
try {
|
|
31534
|
-
resolvedRemotes = JSON.parse(
|
|
31662
|
+
resolvedRemotes = JSON.parse(readFileSync55(resolvedFile, "utf8"));
|
|
31535
31663
|
} catch {
|
|
31536
31664
|
}
|
|
31537
31665
|
}
|
|
31538
31666
|
const originOf = (dir) => gitOk(dir, ["remote", "get-url", "origin"]) ?? void 0;
|
|
31539
31667
|
const text2 = configText;
|
|
31540
31668
|
const base = dirname37(cfg.configFile);
|
|
31541
|
-
const isCheckout = (d) =>
|
|
31669
|
+
const isCheckout = (d) => existsSync60(`${d}/.git`);
|
|
31542
31670
|
try {
|
|
31543
31671
|
if (sub === "list") {
|
|
31544
31672
|
if (flag("json")) {
|
|
@@ -31548,12 +31676,12 @@ ${f.tail.trimEnd()}
|
|
|
31548
31676
|
base,
|
|
31549
31677
|
resolved: resolvedRemotes,
|
|
31550
31678
|
originOf,
|
|
31551
|
-
exists: (d) =>
|
|
31679
|
+
exists: (d) => existsSync60(d),
|
|
31552
31680
|
isCheckout,
|
|
31553
31681
|
repoHasHooks: (d) => REPO_CONFIG_FILENAMES.some((f) => {
|
|
31554
31682
|
try {
|
|
31555
31683
|
const path = resolvePath(d, f);
|
|
31556
|
-
return Object.keys(parseRepoConfig(
|
|
31684
|
+
return Object.keys(parseRepoConfig(readFileSync55(path, "utf8"), path).hooks).length > 0;
|
|
31557
31685
|
} catch {
|
|
31558
31686
|
return false;
|
|
31559
31687
|
}
|
|
@@ -31570,7 +31698,7 @@ ${f.tail.trimEnd()}
|
|
|
31570
31698
|
for (const r of repos) {
|
|
31571
31699
|
const origin2 = originOf(r.dir);
|
|
31572
31700
|
const row = matchRepoName(origin2, resolvedRemotes);
|
|
31573
|
-
const note = !
|
|
31701
|
+
const note = !existsSync60(r.dir) ? "missing on disk" : row ? `Repos row: ${row}` : `no Repos row matches ${normalizeRemote2(origin2) ?? "this checkout (no origin remote)"}`;
|
|
31574
31702
|
process.stdout.write(`${r.name} ${r.dir} ${note}
|
|
31575
31703
|
`);
|
|
31576
31704
|
}
|
|
@@ -31582,9 +31710,9 @@ ${f.tail.trimEnd()}
|
|
|
31582
31710
|
` : `${human}
|
|
31583
31711
|
`);
|
|
31584
31712
|
const plan2 = planRepoClone({ text: text2, base, route: routeName, name: addName, resolved: resolvedRemotes, dir: value("dir"), isCheckout });
|
|
31585
|
-
if (
|
|
31713
|
+
if (existsSync60(plan2.target) && (existsSync60(`${plan2.target}/.git`) || readdirSync22(plan2.target).length > 0)) {
|
|
31586
31714
|
throw new ReposError(
|
|
31587
|
-
|
|
31715
|
+
existsSync60(`${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`
|
|
31588
31716
|
);
|
|
31589
31717
|
}
|
|
31590
31718
|
if (dryRun) {
|
|
@@ -31602,14 +31730,14 @@ ${f.tail.trimEnd()}
|
|
|
31602
31730
|
throw new ReposError(`${e.message}${authHint}
|
|
31603
31731
|
crew.yaml was not changed`);
|
|
31604
31732
|
}
|
|
31605
|
-
|
|
31733
|
+
writeFileSync43(cfg.configFile, plan2.text);
|
|
31606
31734
|
if (plan2.droppedDir) process.stderr.write(`crew repos: dropped dir: ${plan2.droppedDir} from route ${routeName} \u2014 it is not a checkout (the clone base); checkouts now live under repos:
|
|
31607
31735
|
`);
|
|
31608
31736
|
say("attached", { route: routeName, name: plan2.name, dir: plan2.target, mode: plan2.mode }, `cloned and attached ${plan2.target} to ${routeName} as ${plan2.mode === "dir" ? "dir" : `repos.${plan2.name}`} in ${cfg.configFile}`);
|
|
31609
31737
|
break;
|
|
31610
31738
|
}
|
|
31611
31739
|
const target = resolvePath(addPath.replace(/^~(?=\/|$)/, homedir11()));
|
|
31612
|
-
const top =
|
|
31740
|
+
const top = existsSync60(target) ? gitOk(target, ["rev-parse", "--show-toplevel"]) : null;
|
|
31613
31741
|
if (!top) throw new ReposError(`${target} is not a git checkout`);
|
|
31614
31742
|
const origin = originOf(top);
|
|
31615
31743
|
const plan = planRepoAdd({
|
|
@@ -31661,15 +31789,15 @@ ${f.tail.trimEnd()}
|
|
|
31661
31789
|
const created = await rowTracker.createRepoRow(rowPayload);
|
|
31662
31790
|
process.stdout.write(`created Repos row ${String(rowPayload.name)} (${String(rowPayload.remote)}) ${created.id}
|
|
31663
31791
|
`);
|
|
31664
|
-
if (
|
|
31665
|
-
const raw = JSON.parse(
|
|
31792
|
+
if (existsSync60(resolvedFile)) {
|
|
31793
|
+
const raw = JSON.parse(readFileSync55(resolvedFile, "utf8"));
|
|
31666
31794
|
raw.repoNames = { ...raw.repoNames, [created.id]: String(rowPayload.name) };
|
|
31667
31795
|
raw.repoRemotes = { ...raw.repoRemotes, [created.id]: String(rowPayload.remote) };
|
|
31668
|
-
|
|
31796
|
+
writeFileSync43(resolvedFile, `${JSON.stringify(raw, null, 2)}
|
|
31669
31797
|
`);
|
|
31670
31798
|
}
|
|
31671
31799
|
}
|
|
31672
|
-
|
|
31800
|
+
writeFileSync43(cfg.configFile, plan.text);
|
|
31673
31801
|
process.stdout.write(`added ${top} to ${routeName} as ${plan.mode === "dir" ? "dir" : `repos.${plan.name}`} in ${cfg.configFile}
|
|
31674
31802
|
`);
|
|
31675
31803
|
} catch (e) {
|
|
@@ -32044,7 +32172,7 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
|
|
|
32044
32172
|
process.exit(2);
|
|
32045
32173
|
}
|
|
32046
32174
|
if (found.shipNameAdopted && !dryRun) {
|
|
32047
|
-
|
|
32175
|
+
writeFileSync43(cfg.configFile, setShipNameInYaml(readFileSync55(cfg.configFile, "utf8"), found.shipNameAdopted));
|
|
32048
32176
|
cfg.ship.name = found.shipNameAdopted;
|
|
32049
32177
|
}
|
|
32050
32178
|
if (found.shipRow) {
|
|
@@ -32087,10 +32215,10 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
|
|
|
32087
32215
|
}
|
|
32088
32216
|
}
|
|
32089
32217
|
let previous;
|
|
32090
|
-
const hadPreviousFile =
|
|
32218
|
+
const hadPreviousFile = existsSync60(resolvedPath);
|
|
32091
32219
|
if (hadPreviousFile) {
|
|
32092
32220
|
try {
|
|
32093
|
-
previous = JSON.parse(
|
|
32221
|
+
previous = JSON.parse(readFileSync55(resolvedPath, "utf8"));
|
|
32094
32222
|
} catch {
|
|
32095
32223
|
}
|
|
32096
32224
|
}
|
|
@@ -32223,9 +32351,9 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
|
|
|
32223
32351
|
mkdirSync42(dirname37(resolvedPath), { recursive: true });
|
|
32224
32352
|
if (hadPreviousFile) copyFileSync2(resolvedPath, `${resolvedPath}.bak`);
|
|
32225
32353
|
const tmpPath = `${resolvedPath}.tmp${process.pid}`;
|
|
32226
|
-
|
|
32354
|
+
writeFileSync43(tmpPath, `${JSON.stringify(resolved, null, 2)}
|
|
32227
32355
|
`);
|
|
32228
|
-
|
|
32356
|
+
renameSync9(tmpPath, resolvedPath);
|
|
32229
32357
|
process.stderr.write(`Resolved ids written to ${resolvedPath}
|
|
32230
32358
|
`);
|
|
32231
32359
|
}
|
|
@@ -32270,7 +32398,7 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
|
|
|
32270
32398
|
`);
|
|
32271
32399
|
} else {
|
|
32272
32400
|
mkdirSync42(dirname37(apiKeyFile), { recursive: true });
|
|
32273
|
-
|
|
32401
|
+
writeFileSync43(apiKeyFile, `${apiKeyVar}=${apiKey}
|
|
32274
32402
|
`, { mode: 384 });
|
|
32275
32403
|
process.stderr.write(`API key written to ${apiKeyFile}
|
|
32276
32404
|
`);
|
|
@@ -32985,10 +33113,10 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
|
|
|
32985
33113
|
startupSeconds: cfg.ship.intelStartupSeconds,
|
|
32986
33114
|
prepare: async (path) => {
|
|
32987
33115
|
for (const f of repoWt.config.worktrees.copy) {
|
|
32988
|
-
const src =
|
|
32989
|
-
if (!
|
|
32990
|
-
mkdirSync42(dirOf2(
|
|
32991
|
-
copyFileSync2(src,
|
|
33116
|
+
const src = join63(repoWt.dir, f);
|
|
33117
|
+
if (!existsSync60(src) || existsSync60(join63(path, f))) continue;
|
|
33118
|
+
mkdirSync42(dirOf2(join63(path, f)), { recursive: true });
|
|
33119
|
+
copyFileSync2(src, join63(path, f));
|
|
32992
33120
|
}
|
|
32993
33121
|
const setup = repoWt.config.hooks.setup;
|
|
32994
33122
|
return setup ? runScript(setup, { cwd: path, shell: shellWt }) : null;
|
|
@@ -33214,7 +33342,7 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
|
|
|
33214
33342
|
const shellR = hit && resolveShell(hit.repo.config.shell ?? cfg.ship.shell);
|
|
33215
33343
|
const resumed = await runPeriscopeResume({
|
|
33216
33344
|
find: async () => hit && { row: hit.row, tag: hit.tag },
|
|
33217
|
-
worktreeExists: (p) =>
|
|
33345
|
+
worktreeExists: (p) => existsSync60(p),
|
|
33218
33346
|
prepareDropFile,
|
|
33219
33347
|
startProxy: (wt, url, n) => launchProxy(crewInvocation(CREW_HOME), wt, url, Number(n), { host: hit.row.host || "localhost", inject: hit.repo.config.periscope?.inspector !== "repo" }),
|
|
33220
33348
|
relay: hit && previewRelayFor(hit.route) && {
|
|
@@ -33317,10 +33445,10 @@ ${where.join("\n")}`);
|
|
|
33317
33445
|
},
|
|
33318
33446
|
prepare: async (path) => {
|
|
33319
33447
|
for (const f of repoP.config.worktrees.copy) {
|
|
33320
|
-
const src =
|
|
33321
|
-
if (!
|
|
33322
|
-
mkdirSync42(dirOf2(
|
|
33323
|
-
copyFileSync2(src,
|
|
33448
|
+
const src = join63(repoP.dir, f);
|
|
33449
|
+
if (!existsSync60(src)) continue;
|
|
33450
|
+
mkdirSync42(dirOf2(join63(path, f)), { recursive: true });
|
|
33451
|
+
copyFileSync2(src, join63(path, f));
|
|
33324
33452
|
}
|
|
33325
33453
|
const setup = repoP.config.hooks.setup;
|
|
33326
33454
|
return setup ? runScript(setup, { cwd: path, shell: shellP, onLine: (l) => {
|
|
@@ -33632,7 +33760,7 @@ ${where.join("\n")}`);
|
|
|
33632
33760
|
};
|
|
33633
33761
|
const droppedRoutes = [];
|
|
33634
33762
|
try {
|
|
33635
|
-
const rawCfg = parseYaml3(
|
|
33763
|
+
const rawCfg = parseYaml3(readFileSync55(cfg.configFile, "utf8"));
|
|
33636
33764
|
for (const r of rawCfg?.routes ?? []) {
|
|
33637
33765
|
if (typeof r?.route !== "string" || cfg.routes.some((x) => x.route === r.route)) continue;
|
|
33638
33766
|
try {
|
|
@@ -33697,7 +33825,7 @@ ${where.join("\n")}`);
|
|
|
33697
33825
|
break;
|
|
33698
33826
|
}
|
|
33699
33827
|
mkdirSync42(cfg.ship.stateDir, { recursive: true });
|
|
33700
|
-
|
|
33828
|
+
writeFileSync43(sentinel, `${(/* @__PURE__ */ new Date()).toISOString()}
|
|
33701
33829
|
`);
|
|
33702
33830
|
process.stdout.write(
|
|
33703
33831
|
"crew reload: requested \u2014 the daemon relaunches with the new config once its running agents end (it starts no new work meanwhile); if it is busy, `crew reload --now` forces the relaunch and interrupts them\n"
|
|
@@ -33762,7 +33890,7 @@ ${where.join("\n")}`);
|
|
|
33762
33890
|
}
|
|
33763
33891
|
case "log": {
|
|
33764
33892
|
try {
|
|
33765
|
-
const text2 =
|
|
33893
|
+
const text2 = readFileSync55(cfg.ship.logFile, "utf8").split("\n");
|
|
33766
33894
|
process.stdout.write(`${text2.slice(-(Number(value("tail")) || 40)).join("\n")}
|
|
33767
33895
|
`);
|
|
33768
33896
|
} catch {
|
|
@@ -33785,7 +33913,7 @@ ${where.join("\n")}`);
|
|
|
33785
33913
|
};
|
|
33786
33914
|
if (!route2.resolved) fail2(`route ${route2.route} is not connected \u2014 run \`crew connect\` first`);
|
|
33787
33915
|
const tracker = new Tracker(route2, cfg.ship);
|
|
33788
|
-
const configText =
|
|
33916
|
+
const configText = readFileSync55(cfg.configFile, "utf8");
|
|
33789
33917
|
const cfgBase = dirname37(cfg.configFile);
|
|
33790
33918
|
const configured2 = configuredRepos(configText, route2.route, cfgBase);
|
|
33791
33919
|
const dir = configured2.find((r) => r.name === SAMPLE_REPO)?.dir ?? sampleDir(configured2.map((r) => r.dir), route2.reposBasePath, route2.route.split("/")[0]);
|
|
@@ -33814,7 +33942,7 @@ ${where.join("\n")}`);
|
|
|
33814
33942
|
}
|
|
33815
33943
|
if (configured2.some((r) => r.dir === dir)) {
|
|
33816
33944
|
try {
|
|
33817
|
-
|
|
33945
|
+
writeFileSync43(cfg.configFile, planRepoRemove(configText, cfgBase, route2.route, dir).text);
|
|
33818
33946
|
} catch (e) {
|
|
33819
33947
|
if (e instanceof ReposError) fail2(e.message);
|
|
33820
33948
|
throw e;
|
|
@@ -33822,29 +33950,29 @@ ${where.join("\n")}`);
|
|
|
33822
33950
|
}
|
|
33823
33951
|
if (row) {
|
|
33824
33952
|
await tracker.deleteRepoRow(row.id);
|
|
33825
|
-
if (
|
|
33826
|
-
const raw = JSON.parse(
|
|
33953
|
+
if (existsSync60(resolvedFile)) {
|
|
33954
|
+
const raw = JSON.parse(readFileSync55(resolvedFile, "utf8"));
|
|
33827
33955
|
if (raw.repoNames) delete raw.repoNames[row.id];
|
|
33828
33956
|
if (raw.repoRemotes) delete raw.repoRemotes[row.id];
|
|
33829
|
-
|
|
33957
|
+
writeFileSync43(resolvedFile, `${JSON.stringify(raw, null, 2)}
|
|
33830
33958
|
`);
|
|
33831
33959
|
}
|
|
33832
33960
|
}
|
|
33833
|
-
if (
|
|
33961
|
+
if (existsSync60(join63(dir, ".git")) && basename17(dir) === SAMPLE_REPO) rmSync26(dir, { recursive: true, force: true });
|
|
33834
33962
|
say("removed", { dir, closed }, `removed the sample repo${closed.length ? `, closed ${closed.join(", ")}` : ""}`);
|
|
33835
33963
|
break;
|
|
33836
33964
|
}
|
|
33837
33965
|
const projectId = route2.resolved.areaId ?? resolveRepoProject(await tracker.projectRows(), value("project"));
|
|
33838
|
-
const fresh = !
|
|
33839
|
-
if (
|
|
33966
|
+
const fresh = !existsSync60(join63(dir, ".git"));
|
|
33967
|
+
if (existsSync60(dir) && fresh && readdirSync22(dir).length > 0) fail2(`${dir} exists and is not a git checkout \u2014 move it aside`);
|
|
33840
33968
|
if (dryRun) {
|
|
33841
33969
|
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`);
|
|
33842
33970
|
break;
|
|
33843
33971
|
}
|
|
33844
33972
|
if (fresh) {
|
|
33845
33973
|
mkdirSync42(dir, { recursive: true });
|
|
33846
|
-
|
|
33847
|
-
|
|
33974
|
+
writeFileSync43(join63(dir, "README.md"), SAMPLE_README);
|
|
33975
|
+
writeFileSync43(join63(dir, ".crew.yaml"), SAMPLE_CREW_YAML);
|
|
33848
33976
|
const g = (...a) => {
|
|
33849
33977
|
const r = spawnSync14("git", a, { cwd: dir, encoding: "utf8" });
|
|
33850
33978
|
if (r.status !== 0) fail2(`git ${a[0]} failed in ${dir}: ${(r.stderr || r.stdout).trim()}`);
|
|
@@ -33862,17 +33990,17 @@ ${where.join("\n")}`);
|
|
|
33862
33990
|
spec: { platform: "unix", releaseMode: "integrate", ciProvider: "none" }
|
|
33863
33991
|
});
|
|
33864
33992
|
repoId = (await tracker.createRepoRow(payload)).id;
|
|
33865
|
-
if (
|
|
33866
|
-
const raw = JSON.parse(
|
|
33993
|
+
if (existsSync60(resolvedFile)) {
|
|
33994
|
+
const raw = JSON.parse(readFileSync55(resolvedFile, "utf8"));
|
|
33867
33995
|
raw.repoNames = { ...raw.repoNames, [repoId]: SAMPLE_REPO };
|
|
33868
33996
|
raw.repoRemotes = { ...raw.repoRemotes, [repoId]: SAMPLE_REMOTE };
|
|
33869
|
-
|
|
33997
|
+
writeFileSync43(resolvedFile, `${JSON.stringify(raw, null, 2)}
|
|
33870
33998
|
`);
|
|
33871
33999
|
}
|
|
33872
34000
|
}
|
|
33873
34001
|
if (!configured2.some((r) => r.dir === dir)) {
|
|
33874
34002
|
try {
|
|
33875
|
-
|
|
34003
|
+
writeFileSync43(cfg.configFile, planRepoAdd({ text: configText, base: cfgBase, route: route2.route, path: dir, name: SAMPLE_REPO }).text);
|
|
33876
34004
|
} catch (e) {
|
|
33877
34005
|
if (e instanceof ReposError) fail2(e.message);
|
|
33878
34006
|
throw e;
|
|
@@ -34017,7 +34145,12 @@ ${where.join("\n")}`);
|
|
|
34017
34145
|
const projects = projectModeLabels(await statusTracker.projectRowsWithModes().catch(() => []));
|
|
34018
34146
|
const crewMinVersion = await readCrewFloor(route2, cfg.ship) ?? null;
|
|
34019
34147
|
const runs = liveRuns(cfg.ship.stateDir);
|
|
34148
|
+
const runTitles = new Map(
|
|
34149
|
+
(await statusTracker.ticketsByIds([...new Set(runs.map((x) => x.ticketRecordId).filter((id) => !!id))]).catch(() => [])).map((t) => [t.id, t.title ?? null])
|
|
34150
|
+
);
|
|
34151
|
+
const lastRuns = lastRunsBySeat(cfg.ship.stateDir);
|
|
34020
34152
|
const periscopes = await periscopesForStatus(cfg.ship.stateDir);
|
|
34153
|
+
const runPreviews = new Map(periscopes.filter((p) => p.serving).map((p) => [p.ticketRecordId, p.url]));
|
|
34021
34154
|
if (flag("json")) {
|
|
34022
34155
|
const nameSync = await reconcileRouteShipName({ route: route2, ship: cfg.ship, configFile: cfg.configFile, readOnly: true });
|
|
34023
34156
|
const repos = await resolvedRepos(route2);
|
|
@@ -34037,7 +34170,9 @@ ${where.join("\n")}`);
|
|
|
34037
34170
|
name: crewRow?.name ?? null,
|
|
34038
34171
|
personaName,
|
|
34039
34172
|
// Additive (CREW-2822): how many runs this seat has live right now.
|
|
34040
|
-
running: runs.filter((x) => x.role === r && x.route === routeSlug(route2.route)).length
|
|
34173
|
+
running: runs.filter((x) => x.role === r && x.route === routeSlug(route2.route)).length,
|
|
34174
|
+
// Additive (CREW-3247): this seat's newest finished run on this ship, or null.
|
|
34175
|
+
lastRun: ((l) => l ? { ticket: l.ticket, startedAt: l.startedAt, finishedAt: l.finishedAt, outcome: l.outcome, exitCode: l.exitCode } : null)(lastRuns.get(`${routeSlug(route2.route)}/${r}`))
|
|
34041
34176
|
};
|
|
34042
34177
|
});
|
|
34043
34178
|
process.stdout.write(`${JSON.stringify({
|
|
@@ -34087,7 +34222,7 @@ ${where.join("\n")}`);
|
|
|
34087
34222
|
seats: seats2
|
|
34088
34223
|
},
|
|
34089
34224
|
// Additive (CREW-2822): every live run on this ship. `version` stays 1.
|
|
34090
|
-
runs: runs.map((x) => describeRun(x, route2, seatIds)),
|
|
34225
|
+
runs: runs.map((x) => describeRun(x, route2, seatIds, void 0, { titles: runTitles, previews: runPreviews })),
|
|
34091
34226
|
// Additive (CREW-2857): every live periscope on this ship, from its local record. `version` stays 1.
|
|
34092
34227
|
periscopes,
|
|
34093
34228
|
watermark: state.watermark(routeSlug(route2.route)),
|
|
@@ -34241,7 +34376,7 @@ watermark: ${state.watermark(routeSlug(route2.route))}
|
|
|
34241
34376
|
plan,
|
|
34242
34377
|
label,
|
|
34243
34378
|
uid: process.getuid?.() ?? 0,
|
|
34244
|
-
system: plan.mechanism === "systemd" &&
|
|
34379
|
+
system: plan.mechanism === "systemd" && existsSync60(systemUnitPathFor(label)),
|
|
34245
34380
|
stamp: readDaemonStamp(cfg.ship.stateDir)
|
|
34246
34381
|
});
|
|
34247
34382
|
})();
|
|
@@ -34257,7 +34392,7 @@ watermark: ${state.watermark(routeSlug(route2.route))}
|
|
|
34257
34392
|
}
|
|
34258
34393
|
for (const r of repos) {
|
|
34259
34394
|
const remote = r.config.branch.remote;
|
|
34260
|
-
if (
|
|
34395
|
+
if (existsSync60(r.dir)) {
|
|
34261
34396
|
pushAuth.push({
|
|
34262
34397
|
route: c.route,
|
|
34263
34398
|
repo: r.name,
|
|
@@ -34341,7 +34476,7 @@ watermark: ${state.watermark(routeSlug(route2.route))}
|
|
|
34341
34476
|
else passed++;
|
|
34342
34477
|
}
|
|
34343
34478
|
if (staleBundle) problems.push({ severity: "blocker", kind: "stale_bundle", message: staleBundle.message, remedy: "npm run build" });
|
|
34344
|
-
const runtimeDir = runtimeDirWarning(process.platform, process.getuid?.() ?? null,
|
|
34479
|
+
const runtimeDir = runtimeDirWarning(process.platform, process.getuid?.() ?? null, existsSync60, userInfo2().username);
|
|
34345
34480
|
if (runtimeDir) problems.push({ severity: "attention", kind: "runtime_dir_missing", message: runtimeDir });
|
|
34346
34481
|
if (!flag("offline")) {
|
|
34347
34482
|
const shipKind = await doctorShipKind(route2, cfg.ship);
|
|
@@ -34413,7 +34548,7 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
|
|
|
34413
34548
|
}
|
|
34414
34549
|
try {
|
|
34415
34550
|
const evFile = eventFileFor(cfg.ship.stateDir);
|
|
34416
|
-
const evSize =
|
|
34551
|
+
const evSize = existsSync60(evFile) ? statSync19(evFile).size : 0;
|
|
34417
34552
|
process.stdout.write(
|
|
34418
34553
|
evSize > cfg.ship.eventsRotateBytes * 4 ? `events log: WARN ${evFile} is ${Math.round(evSize / 1048576)} MB (> 4x eventsRotateBytes); run \`crew reap\` to rotate it
|
|
34419
34554
|
` : "events log: ok\n"
|
|
@@ -34424,7 +34559,7 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
|
|
|
34424
34559
|
const unitPlan = planInstall(cfg.ship, CREW_HOME, host, detectSystemd(), "run", installContext());
|
|
34425
34560
|
const abandons = unitAbandonsAgents(unitPlan, (p) => {
|
|
34426
34561
|
try {
|
|
34427
|
-
return
|
|
34562
|
+
return readFileSync55(p, "utf8");
|
|
34428
34563
|
} catch {
|
|
34429
34564
|
return null;
|
|
34430
34565
|
}
|
|
@@ -34439,7 +34574,7 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
|
|
|
34439
34574
|
const pPlan = planInstall(cfg.ship, CREW_HOME, host, true, "passengers", installContext());
|
|
34440
34575
|
const keeps = unitAbandonsAgents(pPlan, (p) => {
|
|
34441
34576
|
try {
|
|
34442
|
-
return
|
|
34577
|
+
return readFileSync55(p, "utf8");
|
|
34443
34578
|
} catch {
|
|
34444
34579
|
return null;
|
|
34445
34580
|
}
|
|
@@ -34453,7 +34588,7 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
|
|
|
34453
34588
|
if (host === "linux" && detectSystemd()) {
|
|
34454
34589
|
const ctl = planDaemonControl(CREW_HOME, host, true);
|
|
34455
34590
|
const unitPlan = planInstall(cfg.ship, CREW_HOME, host, true, "run", installContext());
|
|
34456
|
-
if (ctl.statusCommand && unitPlan.unitPaths.some((p) =>
|
|
34591
|
+
if (ctl.statusCommand && unitPlan.unitPaths.some((p) => existsSync60(p))) {
|
|
34457
34592
|
const st = spawnSync14(ctl.statusCommand[0], ctl.statusCommand.slice(1), { cwd: CREW_HOME, encoding: "utf8" });
|
|
34458
34593
|
if (!st.error && st.status !== 0) {
|
|
34459
34594
|
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");
|
|
@@ -34478,8 +34613,8 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
|
|
|
34478
34613
|
const changed2 = configChangedAfter(daemonConfigPaths(cfg), daemonStartedAt);
|
|
34479
34614
|
if (changed2) {
|
|
34480
34615
|
process.stdout.write(
|
|
34481
|
-
daemonDead ? `daemon config: WARN ${changed2} changed at ${new Date(
|
|
34482
|
-
` : `daemon config: WARN ${changed2} changed at ${new Date(
|
|
34616
|
+
daemonDead ? `daemon config: WARN ${changed2} changed at ${new Date(statSync19(changed2).mtimeMs).toISOString()} \u2014 no daemon is running; the new config applies when it starts
|
|
34617
|
+
` : `daemon config: WARN ${changed2} changed at ${new Date(statSync19(changed2).mtimeMs).toISOString()} but the daemon started at ${new Date(daemonStartedAt).toISOString()} \u2014 run \`crew reload\`
|
|
34483
34618
|
`
|
|
34484
34619
|
);
|
|
34485
34620
|
}
|