@tablation/crew 0.137.11 → 0.138.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 +814 -580
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -6885,33 +6885,95 @@ import { promisify as promisify2 } from "util";
|
|
|
6885
6885
|
|
|
6886
6886
|
// src/deprovision-host.ts
|
|
6887
6887
|
import { spawnSync as spawnSync7 } from "child_process";
|
|
6888
|
-
import { existsSync as
|
|
6888
|
+
import { existsSync as existsSync32, readdirSync as readdirSync12 } from "fs";
|
|
6889
|
+
|
|
6890
|
+
// src/repo-env.ts
|
|
6891
|
+
import { existsSync as existsSync19, mkdirSync as mkdirSync14, readFileSync as readFileSync20, renameSync as renameSync3, rmSync as rmSync10, writeFileSync as writeFileSync15 } from "fs";
|
|
6892
|
+
import { dirname as dirname11, join as join22 } from "path";
|
|
6893
|
+
function repoEnvPathFor(stateDir) {
|
|
6894
|
+
return join22(stateDir, "repo-env.json");
|
|
6895
|
+
}
|
|
6896
|
+
function normalizeRemote(remote) {
|
|
6897
|
+
return remote.trim().toLowerCase().replace(/^[a-z+]+:\/\//, "").replace(/^[^@/]+@/, "").replace(":", "/").replace(/\.git$/, "").replace(/\/+$/, "");
|
|
6898
|
+
}
|
|
6899
|
+
function sanitizeRepositoryEnv(raw) {
|
|
6900
|
+
if (!Array.isArray(raw)) return [];
|
|
6901
|
+
const out = [];
|
|
6902
|
+
for (const e of raw) {
|
|
6903
|
+
if (!e || typeof e !== "object" || !e.env || typeof e.env !== "object") continue;
|
|
6904
|
+
const repoRowId = typeof e.repoRowId === "string" && e.repoRowId ? e.repoRowId : void 0;
|
|
6905
|
+
const remote = typeof e.remote === "string" && e.remote ? e.remote : void 0;
|
|
6906
|
+
if (!repoRowId && !remote) continue;
|
|
6907
|
+
const env = {};
|
|
6908
|
+
for (const [k, v] of Object.entries(e.env)) {
|
|
6909
|
+
if (/^[A-Za-z_][A-Za-z0-9_]*$/.test(k) && typeof v === "string") env[k] = v;
|
|
6910
|
+
}
|
|
6911
|
+
if (Object.keys(env).length) out.push({ ...repoRowId ? { repoRowId } : {}, ...remote ? { remote } : {}, env });
|
|
6912
|
+
}
|
|
6913
|
+
return out;
|
|
6914
|
+
}
|
|
6915
|
+
function readRepositoryEnv(stateDir) {
|
|
6916
|
+
try {
|
|
6917
|
+
return sanitizeRepositoryEnv(JSON.parse(readFileSync20(repoEnvPathFor(stateDir), "utf8")));
|
|
6918
|
+
} catch {
|
|
6919
|
+
return [];
|
|
6920
|
+
}
|
|
6921
|
+
}
|
|
6922
|
+
function writeRepositoryEnv(stateDir, entries) {
|
|
6923
|
+
const file = repoEnvPathFor(stateDir);
|
|
6924
|
+
const clean = sanitizeRepositoryEnv(entries);
|
|
6925
|
+
if (!clean.length) {
|
|
6926
|
+
eraseRepositoryEnv(stateDir);
|
|
6927
|
+
return;
|
|
6928
|
+
}
|
|
6929
|
+
mkdirSync14(dirname11(file), { recursive: true, mode: 448 });
|
|
6930
|
+
const tmp = `${file}.tmp`;
|
|
6931
|
+
writeFileSync15(tmp, `${JSON.stringify(clean)}
|
|
6932
|
+
`, { mode: 384 });
|
|
6933
|
+
renameSync3(tmp, file);
|
|
6934
|
+
}
|
|
6935
|
+
function eraseRepositoryEnv(stateDir) {
|
|
6936
|
+
rmSync10(repoEnvPathFor(stateDir), { force: true });
|
|
6937
|
+
}
|
|
6938
|
+
function hasRepositoryEnv(stateDir) {
|
|
6939
|
+
return existsSync19(repoEnvPathFor(stateDir));
|
|
6940
|
+
}
|
|
6941
|
+
function repositoryEnvCount(stateDir) {
|
|
6942
|
+
return readRepositoryEnv(stateDir).length;
|
|
6943
|
+
}
|
|
6944
|
+
function envForRepository(entries, repo) {
|
|
6945
|
+
const byId = repo.repoRowId ? entries.find((e) => e.repoRowId === repo.repoRowId) : void 0;
|
|
6946
|
+
if (byId) return { ...byId.env };
|
|
6947
|
+
const want = repo.remote ? normalizeRemote(repo.remote) : "";
|
|
6948
|
+
const byRemote = want ? entries.find((e) => e.remote && normalizeRemote(e.remote) === want) : void 0;
|
|
6949
|
+
return byRemote ? { ...byRemote.env } : {};
|
|
6950
|
+
}
|
|
6889
6951
|
|
|
6890
6952
|
// src/interrupted.ts
|
|
6891
|
-
import { existsSync as
|
|
6892
|
-
import { join as
|
|
6953
|
+
import { existsSync as existsSync30, readdirSync as readdirSync10, readFileSync as readFileSync31 } from "fs";
|
|
6954
|
+
import { join as join33 } from "path";
|
|
6893
6955
|
|
|
6894
6956
|
// src/agent.ts
|
|
6895
6957
|
import { spawnSync as spawnSync6 } from "child_process";
|
|
6896
|
-
import { readFileSync as
|
|
6958
|
+
import { readFileSync as readFileSync30, existsSync as existsSync29, statSync as statSync9, mkdirSync as mkdirSync21, writeFileSync as writeFileSync22, createWriteStream, openSync as openSync4, closeSync as closeSync4, readSync } from "fs";
|
|
6897
6959
|
import { StringDecoder } from "string_decoder";
|
|
6898
6960
|
import { finished } from "stream/promises";
|
|
6899
|
-
import { join as
|
|
6961
|
+
import { join as join32, dirname as dirname16, basename as basename9 } from "path";
|
|
6900
6962
|
import { createHash as createHash6, randomUUID } from "crypto";
|
|
6901
6963
|
|
|
6902
6964
|
// src/state.ts
|
|
6903
|
-
import { readFileSync as
|
|
6904
|
-
import { join as
|
|
6965
|
+
import { readFileSync as readFileSync21, writeFileSync as writeFileSync16, existsSync as existsSync20, mkdirSync as mkdirSync15, rmSync as rmSync11, statSync as statSync7, readdirSync as readdirSync6 } from "fs";
|
|
6966
|
+
import { join as join23 } from "path";
|
|
6905
6967
|
var EPOCH = "1970-01-01T00:00:00.000Z";
|
|
6906
6968
|
var watermarkFile = (scope) => scope ? `.poll-watermark-${scope}` : ".poll-watermark";
|
|
6907
6969
|
var State = class _State {
|
|
6908
6970
|
dir;
|
|
6909
6971
|
constructor(dir) {
|
|
6910
6972
|
this.dir = dir;
|
|
6911
|
-
|
|
6973
|
+
mkdirSync15(dir, { recursive: true });
|
|
6912
6974
|
}
|
|
6913
6975
|
path(...parts) {
|
|
6914
|
-
return
|
|
6976
|
+
return join23(this.dir, ...parts);
|
|
6915
6977
|
}
|
|
6916
6978
|
/**
|
|
6917
6979
|
* The timestamp every "new since last poll" check is measured against.
|
|
@@ -6922,7 +6984,7 @@ var State = class _State {
|
|
|
6922
6984
|
*/
|
|
6923
6985
|
watermark(scope) {
|
|
6924
6986
|
try {
|
|
6925
|
-
const v =
|
|
6987
|
+
const v = readFileSync21(this.path(watermarkFile(scope)), "utf8").trim();
|
|
6926
6988
|
return v || EPOCH;
|
|
6927
6989
|
} catch {
|
|
6928
6990
|
if (scope) return this.watermark();
|
|
@@ -6930,7 +6992,7 @@ var State = class _State {
|
|
|
6930
6992
|
}
|
|
6931
6993
|
}
|
|
6932
6994
|
setWatermark(at, scope) {
|
|
6933
|
-
|
|
6995
|
+
writeFileSync16(this.path(watermarkFile(scope)), `${at}
|
|
6934
6996
|
`);
|
|
6935
6997
|
}
|
|
6936
6998
|
/**
|
|
@@ -6948,19 +7010,19 @@ var State = class _State {
|
|
|
6948
7010
|
}
|
|
6949
7011
|
/** Whole-crew pause, and the per-role sentinels one level down. */
|
|
6950
7012
|
isPaused() {
|
|
6951
|
-
return
|
|
7013
|
+
return existsSync20(this.path(".crew-paused"));
|
|
6952
7014
|
}
|
|
6953
7015
|
isRolePaused(role) {
|
|
6954
|
-
return
|
|
7016
|
+
return existsSync20(this.path(`.role-paused-${role}`));
|
|
6955
7017
|
}
|
|
6956
7018
|
pausedRoles(roles) {
|
|
6957
7019
|
return new Set(roles.filter((r) => this.isRolePaused(r)));
|
|
6958
7020
|
}
|
|
6959
7021
|
pause(role) {
|
|
6960
|
-
|
|
7022
|
+
writeFileSync16(role ? this.path(`.role-paused-${role}`) : this.path(".crew-paused"), "");
|
|
6961
7023
|
}
|
|
6962
7024
|
resume(role) {
|
|
6963
|
-
|
|
7025
|
+
rmSync11(role ? this.path(`.role-paused-${role}`) : this.path(".crew-paused"), { force: true });
|
|
6964
7026
|
}
|
|
6965
7027
|
/**
|
|
6966
7028
|
* The release phase (merge, deploy, release) has its own sentinel, one
|
|
@@ -6968,11 +7030,11 @@ var State = class _State {
|
|
|
6968
7030
|
* while agents keep working.
|
|
6969
7031
|
*/
|
|
6970
7032
|
isReleasePaused() {
|
|
6971
|
-
return
|
|
7033
|
+
return existsSync20(this.path(".release-paused"));
|
|
6972
7034
|
}
|
|
6973
7035
|
setReleasePaused(paused) {
|
|
6974
|
-
if (paused)
|
|
6975
|
-
else
|
|
7036
|
+
if (paused) writeFileSync16(this.path(".release-paused"), "");
|
|
7037
|
+
else rmSync11(this.path(".release-paused"), { force: true });
|
|
6976
7038
|
}
|
|
6977
7039
|
/**
|
|
6978
7040
|
* Why a release cycle must not run right now, or null when it may. Every
|
|
@@ -7009,7 +7071,7 @@ var State = class _State {
|
|
|
7009
7071
|
const name = _State.safe(rawName);
|
|
7010
7072
|
const file = this.path(`.${name}.lock`);
|
|
7011
7073
|
try {
|
|
7012
|
-
const existing = Number.parseInt(
|
|
7074
|
+
const existing = Number.parseInt(readFileSync21(file, "utf8").trim(), 10);
|
|
7013
7075
|
if (Number.isFinite(existing) && existing > 0) {
|
|
7014
7076
|
try {
|
|
7015
7077
|
process.kill(existing, 0);
|
|
@@ -7019,13 +7081,13 @@ var State = class _State {
|
|
|
7019
7081
|
}
|
|
7020
7082
|
} catch {
|
|
7021
7083
|
}
|
|
7022
|
-
|
|
7084
|
+
writeFileSync16(file, `${process.pid}
|
|
7023
7085
|
`);
|
|
7024
7086
|
return {
|
|
7025
7087
|
ok: true,
|
|
7026
7088
|
release: () => {
|
|
7027
7089
|
try {
|
|
7028
|
-
|
|
7090
|
+
rmSync11(file, { force: true });
|
|
7029
7091
|
} catch {
|
|
7030
7092
|
}
|
|
7031
7093
|
}
|
|
@@ -7047,7 +7109,7 @@ var State = class _State {
|
|
|
7047
7109
|
if (!/^\.release-.+\.lock$/.test(n)) continue;
|
|
7048
7110
|
let pid = 0;
|
|
7049
7111
|
try {
|
|
7050
|
-
pid = Number.parseInt(
|
|
7112
|
+
pid = Number.parseInt(readFileSync21(this.path(n), "utf8").trim(), 10);
|
|
7051
7113
|
} catch {
|
|
7052
7114
|
continue;
|
|
7053
7115
|
}
|
|
@@ -7133,7 +7195,7 @@ var State = class _State {
|
|
|
7133
7195
|
ticketInFlight(recordId) {
|
|
7134
7196
|
const file = this.path(`.${_State.safe(`crew-ticket-${recordId}`)}.lock`);
|
|
7135
7197
|
try {
|
|
7136
|
-
const pid = Number.parseInt(
|
|
7198
|
+
const pid = Number.parseInt(readFileSync21(file, "utf8").trim(), 10);
|
|
7137
7199
|
if (!Number.isFinite(pid) || pid <= 0) return false;
|
|
7138
7200
|
process.kill(pid, 0);
|
|
7139
7201
|
return true;
|
|
@@ -7167,7 +7229,7 @@ var State = class _State {
|
|
|
7167
7229
|
const heldReported = `.release-held-${suffix}`;
|
|
7168
7230
|
const read = (f) => {
|
|
7169
7231
|
try {
|
|
7170
|
-
return
|
|
7232
|
+
return readFileSync21(this.path(f), "utf8").trim() || null;
|
|
7171
7233
|
} catch {
|
|
7172
7234
|
return null;
|
|
7173
7235
|
}
|
|
@@ -7176,12 +7238,12 @@ var State = class _State {
|
|
|
7176
7238
|
blockedCount: () => Number.parseInt(read(blocked) ?? "", 10) || 0,
|
|
7177
7239
|
noteBlocked: () => {
|
|
7178
7240
|
const n = (Number.parseInt(read(blocked) ?? "", 10) || 0) + 1;
|
|
7179
|
-
|
|
7241
|
+
writeFileSync16(this.path(blocked), `${n}
|
|
7180
7242
|
`);
|
|
7181
7243
|
return n;
|
|
7182
7244
|
},
|
|
7183
7245
|
clearBlocked: () => {
|
|
7184
|
-
|
|
7246
|
+
rmSync11(this.path(blocked), { force: true });
|
|
7185
7247
|
},
|
|
7186
7248
|
/**
|
|
7187
7249
|
* The commit a deploy last failed on.
|
|
@@ -7193,11 +7255,11 @@ var State = class _State {
|
|
|
7193
7255
|
*/
|
|
7194
7256
|
deployFailedSha: () => read(failed),
|
|
7195
7257
|
noteDeployFailed: (sha) => {
|
|
7196
|
-
|
|
7258
|
+
writeFileSync16(this.path(failed), `${sha}
|
|
7197
7259
|
`);
|
|
7198
7260
|
},
|
|
7199
7261
|
clearDeployFailed: () => {
|
|
7200
|
-
|
|
7262
|
+
rmSync11(this.path(failed), { force: true });
|
|
7201
7263
|
},
|
|
7202
7264
|
/**
|
|
7203
7265
|
* Consecutive test-gate failures on the same head (CREW-1368). A failure
|
|
@@ -7207,31 +7269,31 @@ var State = class _State {
|
|
|
7207
7269
|
noteTestGateFailed: (sha) => {
|
|
7208
7270
|
const [prev, n] = (read(gateFailed) ?? "").split(" ");
|
|
7209
7271
|
const next = prev === sha ? (Number.parseInt(n ?? "", 10) || 0) + 1 : 1;
|
|
7210
|
-
|
|
7272
|
+
writeFileSync16(this.path(gateFailed), `${sha} ${next}
|
|
7211
7273
|
`);
|
|
7212
7274
|
return next;
|
|
7213
7275
|
},
|
|
7214
7276
|
clearTestGateFailed: () => {
|
|
7215
|
-
|
|
7277
|
+
rmSync11(this.path(gateFailed), { force: true });
|
|
7216
7278
|
},
|
|
7217
7279
|
/** Whether the board was already told about this head's red gate. */
|
|
7218
7280
|
heldReported: () => {
|
|
7219
7281
|
try {
|
|
7220
|
-
return
|
|
7282
|
+
return readFileSync21(this.path(heldReported), "utf8").replace(/\n$/, "") || null;
|
|
7221
7283
|
} catch {
|
|
7222
7284
|
return null;
|
|
7223
7285
|
}
|
|
7224
7286
|
},
|
|
7225
7287
|
noteHeldReported: (signature) => {
|
|
7226
|
-
|
|
7288
|
+
writeFileSync16(this.path(heldReported), `${signature}
|
|
7227
7289
|
`);
|
|
7228
7290
|
},
|
|
7229
7291
|
clearHeldReported: () => {
|
|
7230
|
-
|
|
7292
|
+
rmSync11(this.path(heldReported), { force: true });
|
|
7231
7293
|
},
|
|
7232
7294
|
testGateReported: (sha) => read(gateReported) === sha,
|
|
7233
7295
|
noteTestGateReported: (sha) => {
|
|
7234
|
-
|
|
7296
|
+
writeFileSync16(this.path(gateReported), `${sha}
|
|
7235
7297
|
`);
|
|
7236
7298
|
}
|
|
7237
7299
|
};
|
|
@@ -7254,13 +7316,13 @@ var State = class _State {
|
|
|
7254
7316
|
const ticketStreakFile = `.fairness-ticket-streak-${suffix}`;
|
|
7255
7317
|
const read = (f) => {
|
|
7256
7318
|
try {
|
|
7257
|
-
return
|
|
7319
|
+
return readFileSync21(this.path(f), "utf8").trim() || null;
|
|
7258
7320
|
} catch {
|
|
7259
7321
|
return null;
|
|
7260
7322
|
}
|
|
7261
7323
|
};
|
|
7262
7324
|
const clear2 = () => {
|
|
7263
|
-
for (const f of [streakFile, ticketFile, sinceFile, ticketStreakFile])
|
|
7325
|
+
for (const f of [streakFile, ticketFile, sinceFile, ticketStreakFile]) rmSync11(this.path(f), { force: true });
|
|
7264
7326
|
};
|
|
7265
7327
|
return {
|
|
7266
7328
|
/** Consecutive cycles this route had actionable work and did not win. */
|
|
@@ -7287,18 +7349,18 @@ var State = class _State {
|
|
|
7287
7349
|
clear2();
|
|
7288
7350
|
return;
|
|
7289
7351
|
}
|
|
7290
|
-
|
|
7352
|
+
writeFileSync16(this.path(streakFile), `${this.readInt(streakFile) + 1}
|
|
7291
7353
|
`);
|
|
7292
7354
|
const prior = read(ticketFile);
|
|
7293
7355
|
if (topTicket && topTicket === prior) {
|
|
7294
|
-
|
|
7356
|
+
writeFileSync16(this.path(ticketStreakFile), `${this.readInt(ticketStreakFile) + 1}
|
|
7295
7357
|
`);
|
|
7296
7358
|
} else if (topTicket) {
|
|
7297
|
-
|
|
7359
|
+
writeFileSync16(this.path(ticketFile), `${topTicket}
|
|
7298
7360
|
`);
|
|
7299
|
-
|
|
7361
|
+
writeFileSync16(this.path(sinceFile), `${(/* @__PURE__ */ new Date()).toISOString()}
|
|
7300
7362
|
`);
|
|
7301
|
-
|
|
7363
|
+
writeFileSync16(this.path(ticketStreakFile), "1\n");
|
|
7302
7364
|
}
|
|
7303
7365
|
}
|
|
7304
7366
|
};
|
|
@@ -7319,14 +7381,14 @@ var State = class _State {
|
|
|
7319
7381
|
return {
|
|
7320
7382
|
previous: () => {
|
|
7321
7383
|
try {
|
|
7322
|
-
const parsed = JSON.parse(
|
|
7384
|
+
const parsed = JSON.parse(readFileSync21(this.path(file), "utf8"));
|
|
7323
7385
|
return parsed && typeof parsed === "object" ? parsed : {};
|
|
7324
7386
|
} catch {
|
|
7325
7387
|
return {};
|
|
7326
7388
|
}
|
|
7327
7389
|
},
|
|
7328
7390
|
persist: (next) => {
|
|
7329
|
-
|
|
7391
|
+
writeFileSync16(this.path(file), JSON.stringify(next));
|
|
7330
7392
|
}
|
|
7331
7393
|
};
|
|
7332
7394
|
}
|
|
@@ -7342,14 +7404,14 @@ var State = class _State {
|
|
|
7342
7404
|
return {
|
|
7343
7405
|
previous: () => {
|
|
7344
7406
|
try {
|
|
7345
|
-
const parsed = JSON.parse(
|
|
7407
|
+
const parsed = JSON.parse(readFileSync21(this.path(file), "utf8"));
|
|
7346
7408
|
return Array.isArray(parsed) ? parsed.filter((x) => typeof x === "string") : [];
|
|
7347
7409
|
} catch {
|
|
7348
7410
|
return [];
|
|
7349
7411
|
}
|
|
7350
7412
|
},
|
|
7351
7413
|
persist: (next) => {
|
|
7352
|
-
|
|
7414
|
+
writeFileSync16(this.path(file), JSON.stringify(next));
|
|
7353
7415
|
}
|
|
7354
7416
|
};
|
|
7355
7417
|
}
|
|
@@ -7363,14 +7425,14 @@ var State = class _State {
|
|
|
7363
7425
|
return {
|
|
7364
7426
|
previous: () => {
|
|
7365
7427
|
try {
|
|
7366
|
-
const parsed = JSON.parse(
|
|
7428
|
+
const parsed = JSON.parse(readFileSync21(this.path(file), "utf8"));
|
|
7367
7429
|
return Array.isArray(parsed) ? parsed : [];
|
|
7368
7430
|
} catch {
|
|
7369
7431
|
return [];
|
|
7370
7432
|
}
|
|
7371
7433
|
},
|
|
7372
7434
|
persist: (next) => {
|
|
7373
|
-
|
|
7435
|
+
writeFileSync16(this.path(file), JSON.stringify(next));
|
|
7374
7436
|
}
|
|
7375
7437
|
};
|
|
7376
7438
|
}
|
|
@@ -7383,7 +7445,7 @@ var State = class _State {
|
|
|
7383
7445
|
const file = ".release-last-run";
|
|
7384
7446
|
return {
|
|
7385
7447
|
touch: () => {
|
|
7386
|
-
|
|
7448
|
+
writeFileSync16(this.path(file), (/* @__PURE__ */ new Date()).toISOString());
|
|
7387
7449
|
},
|
|
7388
7450
|
at: () => {
|
|
7389
7451
|
try {
|
|
@@ -7396,7 +7458,7 @@ var State = class _State {
|
|
|
7396
7458
|
}
|
|
7397
7459
|
readInt(file) {
|
|
7398
7460
|
try {
|
|
7399
|
-
return Number.parseInt(
|
|
7461
|
+
return Number.parseInt(readFileSync21(this.path(file), "utf8").trim(), 10) || 0;
|
|
7400
7462
|
} catch {
|
|
7401
7463
|
return 0;
|
|
7402
7464
|
}
|
|
@@ -7404,7 +7466,7 @@ var State = class _State {
|
|
|
7404
7466
|
};
|
|
7405
7467
|
|
|
7406
7468
|
// src/signed-out.ts
|
|
7407
|
-
import { readFileSync as
|
|
7469
|
+
import { readFileSync as readFileSync22 } from "fs";
|
|
7408
7470
|
var SIGNED_OUT_PATTERN = /not logged in|please run \/?login|\/login|invalid api key|failed to authenticate|oauth session expired|could not be refreshed|reauthentication is needed|application default credentials/i;
|
|
7409
7471
|
function authModeOf(spec, hostEnv = process.env) {
|
|
7410
7472
|
const env = { ...hostEnv, ...spec.env };
|
|
@@ -7451,7 +7513,7 @@ function eventsShowSignedOut(events) {
|
|
|
7451
7513
|
function streamShowsSignedOut(streamPath) {
|
|
7452
7514
|
let raw;
|
|
7453
7515
|
try {
|
|
7454
|
-
raw =
|
|
7516
|
+
raw = readFileSync22(streamPath, "utf8");
|
|
7455
7517
|
} catch {
|
|
7456
7518
|
return false;
|
|
7457
7519
|
}
|
|
@@ -7469,7 +7531,7 @@ function streamShowsSignedOut(streamPath) {
|
|
|
7469
7531
|
function streamShowsRealTurn(streamPath) {
|
|
7470
7532
|
let raw;
|
|
7471
7533
|
try {
|
|
7472
|
-
raw =
|
|
7534
|
+
raw = readFileSync22(streamPath, "utf8");
|
|
7473
7535
|
} catch {
|
|
7474
7536
|
return false;
|
|
7475
7537
|
}
|
|
@@ -8412,8 +8474,8 @@ function renderEnvironment(i) {
|
|
|
8412
8474
|
}
|
|
8413
8475
|
|
|
8414
8476
|
// src/intel-bridge.ts
|
|
8415
|
-
import { existsSync as
|
|
8416
|
-
import { dirname as
|
|
8477
|
+
import { existsSync as existsSync21, mkdirSync as mkdirSync16, readFileSync as readFileSync23, rmSync as rmSync12, writeFileSync as writeFileSync17 } from "fs";
|
|
8478
|
+
import { dirname as dirname12, join as join24 } from "path";
|
|
8417
8479
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
8418
8480
|
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
8419
8481
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
@@ -8429,17 +8491,17 @@ var statusFailed = (reason) => `The symbol service did not start (${reason}). Ru
|
|
|
8429
8491
|
var STATUS_LOST = "The symbol service stopped answering, so its tools are unavailable. They return if the service comes back; until then use text search.";
|
|
8430
8492
|
function intelDir(stateDir, route2, ticket) {
|
|
8431
8493
|
const safe = (s) => s.replace(/[^A-Za-z0-9._-]+/g, "_");
|
|
8432
|
-
return
|
|
8494
|
+
return join24(stateDir, "intel", safe(route2), safe(ticket));
|
|
8433
8495
|
}
|
|
8434
|
-
var attachFilePath = (stateDir, route2, ticket) =>
|
|
8496
|
+
var attachFilePath = (stateDir, route2, ticket) => join24(intelDir(stateDir, route2, ticket), "url");
|
|
8435
8497
|
function writeAttachFile(file, url) {
|
|
8436
|
-
|
|
8437
|
-
|
|
8498
|
+
mkdirSync16(dirname12(file), { recursive: true });
|
|
8499
|
+
writeFileSync17(file, `${url}
|
|
8438
8500
|
`);
|
|
8439
8501
|
}
|
|
8440
8502
|
function readAttachFile(file) {
|
|
8441
8503
|
try {
|
|
8442
|
-
const url =
|
|
8504
|
+
const url = readFileSync23(file, "utf8").trim();
|
|
8443
8505
|
return /^https?:\/\/\S+$/i.test(url) ? url : void 0;
|
|
8444
8506
|
} catch {
|
|
8445
8507
|
return void 0;
|
|
@@ -8561,7 +8623,7 @@ function createBridge(o) {
|
|
|
8561
8623
|
tryAttach,
|
|
8562
8624
|
async start(transport) {
|
|
8563
8625
|
await server.connect(transport);
|
|
8564
|
-
if (
|
|
8626
|
+
if (existsSync21(o.attachFile)) await tryAttach();
|
|
8565
8627
|
timer = setInterval(() => {
|
|
8566
8628
|
void tryAttach();
|
|
8567
8629
|
}, o.pollMs ?? 1e3);
|
|
@@ -8818,14 +8880,14 @@ var BeforeFirstEditTracker = class {
|
|
|
8818
8880
|
};
|
|
8819
8881
|
|
|
8820
8882
|
// src/agent-log.ts
|
|
8821
|
-
import { existsSync as
|
|
8822
|
-
import { join as
|
|
8883
|
+
import { existsSync as existsSync25, mkdirSync as mkdirSync18, readdirSync as readdirSync8, readFileSync as readFileSync25, rmSync as rmSync14, writeFileSync as writeFileSync19 } from "fs";
|
|
8884
|
+
import { join as join27 } from "path";
|
|
8823
8885
|
|
|
8824
8886
|
// src/pending-backoff.ts
|
|
8825
8887
|
var sleepBackoff = (attempts) => Math.min(6e4 * 2 ** Math.max(0, attempts - 1), 30 * 6e4);
|
|
8826
8888
|
|
|
8827
8889
|
// src/handoff-guard.ts
|
|
8828
|
-
import { existsSync as
|
|
8890
|
+
import { existsSync as existsSync24 } from "fs";
|
|
8829
8891
|
|
|
8830
8892
|
// src/ticket-branch.ts
|
|
8831
8893
|
import { basename as basename7 } from "path";
|
|
@@ -9911,23 +9973,23 @@ function materializeBranchForTicket(dir, cfg, t, role, onProblem, onReset) {
|
|
|
9911
9973
|
}
|
|
9912
9974
|
|
|
9913
9975
|
// src/pending-handoff.ts
|
|
9914
|
-
import { existsSync as
|
|
9915
|
-
import { join as
|
|
9976
|
+
import { existsSync as existsSync22, mkdirSync as mkdirSync17, readdirSync as readdirSync7, readFileSync as readFileSync24, rmSync as rmSync13, writeFileSync as writeFileSync18 } from "fs";
|
|
9977
|
+
import { join as join25 } from "path";
|
|
9916
9978
|
var PENDING_MAX_AGE_MS = 48 * 36e5;
|
|
9917
|
-
var pendingDirFor = (stateDir) =>
|
|
9918
|
-
var stateDirOfStream = (streamPath) =>
|
|
9979
|
+
var pendingDirFor = (stateDir) => join25(stateDir, "pending-handoffs");
|
|
9980
|
+
var stateDirOfStream = (streamPath) => join25(streamPath, "..", "..");
|
|
9919
9981
|
function writePendingHandoff(stateDir, rec) {
|
|
9920
9982
|
const dir = pendingDirFor(stateDir);
|
|
9921
|
-
|
|
9922
|
-
|
|
9983
|
+
mkdirSync17(dir, { recursive: true });
|
|
9984
|
+
writeFileSync18(join25(dir, `${rec.ticketRecordId}.json`), JSON.stringify(rec, null, 2));
|
|
9923
9985
|
}
|
|
9924
9986
|
function listPendingHandoffs(stateDir, route2) {
|
|
9925
9987
|
const dir = pendingDirFor(stateDir);
|
|
9926
|
-
if (!
|
|
9988
|
+
if (!existsSync22(dir)) return [];
|
|
9927
9989
|
const out = [];
|
|
9928
9990
|
for (const f of readdirSync7(dir).filter((n) => n.endsWith(".json")).sort()) {
|
|
9929
9991
|
try {
|
|
9930
|
-
const rec = JSON.parse(
|
|
9992
|
+
const rec = JSON.parse(readFileSync24(join25(dir, f), "utf8"));
|
|
9931
9993
|
if (rec.version === 1 && rec.ticketRecordId && (!route2 || rec.route === route2)) out.push(rec);
|
|
9932
9994
|
} catch {
|
|
9933
9995
|
}
|
|
@@ -9935,7 +9997,7 @@ function listPendingHandoffs(stateDir, route2) {
|
|
|
9935
9997
|
return out;
|
|
9936
9998
|
}
|
|
9937
9999
|
function removePendingHandoff(stateDir, ticketRecordId) {
|
|
9938
|
-
|
|
10000
|
+
rmSync13(join25(pendingDirFor(stateDir), `${ticketRecordId}.json`), { force: true });
|
|
9939
10001
|
}
|
|
9940
10002
|
function pendingHandoffFor(stateDir, ticketRecordId) {
|
|
9941
10003
|
return listPendingHandoffs(stateDir).find((r) => r.ticketRecordId === ticketRecordId);
|
|
@@ -10111,8 +10173,8 @@ function holdWarnings(tickets, ships, contract, humanHolds, now = Date.now()) {
|
|
|
10111
10173
|
}
|
|
10112
10174
|
|
|
10113
10175
|
// src/run-worktree.ts
|
|
10114
|
-
import { existsSync as
|
|
10115
|
-
import { dirname as
|
|
10176
|
+
import { existsSync as existsSync23 } from "fs";
|
|
10177
|
+
import { dirname as dirname13, join as join26 } from "path";
|
|
10116
10178
|
var describeRunWorktreePlan = (p) => {
|
|
10117
10179
|
switch (p.action) {
|
|
10118
10180
|
case "cut-remote":
|
|
@@ -10153,7 +10215,7 @@ function planRunWorktree(dir, cfg, t, role, opts = {}) {
|
|
|
10153
10215
|
const existing = worktreeForNumber(dir, num2);
|
|
10154
10216
|
const located = locateBranchForTicket(dir, cfg, t, role);
|
|
10155
10217
|
const baseRef = hasRemote ? `${remote}/${base}` : base;
|
|
10156
|
-
if (existing && !existing.prunable &&
|
|
10218
|
+
if (existing && !existing.prunable && existsSync23(existing.path)) {
|
|
10157
10219
|
const branch = existing.branch;
|
|
10158
10220
|
if (status(existing.path).length > 0) {
|
|
10159
10221
|
return { action: opts.resumeInterrupted ? "resume-dirty" : "leave-dirty", path: existing.path, branch };
|
|
@@ -10169,7 +10231,7 @@ function planRunWorktree(dir, cfg, t, role, opts = {}) {
|
|
|
10169
10231
|
if (countCommits(existing.path, `${baseRef}..HEAD`) > 0) return { action: "leave-unpushed", path: existing.path, branch };
|
|
10170
10232
|
return { action: "recut", path: existing.path, branch, base: baseRef };
|
|
10171
10233
|
}
|
|
10172
|
-
const path =
|
|
10234
|
+
const path = join26(dirname13(dir), worktreeForTicket(dir, cfg, t, role));
|
|
10173
10235
|
if (located?.where === "remote" || located && hasRemote && remoteBranchExists(dir, remote, located.branch)) {
|
|
10174
10236
|
return { action: "cut-remote", path, branch: located.branch };
|
|
10175
10237
|
}
|
|
@@ -10223,7 +10285,7 @@ function dropEmptyRunBranch(dir, cfg, branch) {
|
|
|
10223
10285
|
if (remoteConfigured(dir, remote) && remoteBranchExists(dir, remote, branch)) return false;
|
|
10224
10286
|
if (countCommits(dir, `${baseRef}..${branch}`) !== 0) return false;
|
|
10225
10287
|
const wt = worktrees(dir).find((w) => w.branch === branch && !w.prunable && w.path !== dir);
|
|
10226
|
-
if (wt &&
|
|
10288
|
+
if (wt && existsSync23(wt.path)) {
|
|
10227
10289
|
if (status(wt.path).length > 0) return false;
|
|
10228
10290
|
if (gitOk(dir, ["worktree", "remove", wt.path]) === null) return false;
|
|
10229
10291
|
}
|
|
@@ -10231,7 +10293,7 @@ function dropEmptyRunBranch(dir, cfg, branch) {
|
|
|
10231
10293
|
}
|
|
10232
10294
|
async function finishRunWorktree(dir, cfg, branch) {
|
|
10233
10295
|
const wt = worktrees(dir).find((w) => w.branch === branch && !w.prunable && w.path !== dir);
|
|
10234
|
-
if (!wt || !
|
|
10296
|
+
if (!wt || !existsSync23(wt.path)) return { kind: "none" };
|
|
10235
10297
|
if (cfg.hooks.handoff) return { kind: "kept-handoff", path: wt.path };
|
|
10236
10298
|
if (status(wt.path).length > 0) return { kind: "kept-dirty", path: wt.path };
|
|
10237
10299
|
if (remoteConfigured(dir, cfg.branch.remote) && worktreeHoldsUnpushed(wt.path, cfg.branch.remote)) {
|
|
@@ -10243,7 +10305,7 @@ async function finishRunWorktree(dir, cfg, branch) {
|
|
|
10243
10305
|
if (pids.length) await killGently(pids);
|
|
10244
10306
|
}
|
|
10245
10307
|
gitOk(dir, ["worktree", "remove", wt.path]);
|
|
10246
|
-
return
|
|
10308
|
+
return existsSync23(wt.path) ? { kind: "kept-dirty", path: wt.path } : { kind: "removed", path: wt.path };
|
|
10247
10309
|
}
|
|
10248
10310
|
|
|
10249
10311
|
// src/handoff-guard.ts
|
|
@@ -10301,7 +10363,7 @@ function inspectRemoteHandoff(origin, cfg, ticket, role) {
|
|
|
10301
10363
|
function describeGuardError(e, dir) {
|
|
10302
10364
|
const msg = e.message;
|
|
10303
10365
|
if (!/ENOENT/.test(msg)) return msg;
|
|
10304
|
-
return dir && !
|
|
10366
|
+
return dir && !existsSync24(dir) ? `the run's clone at ${dir} is gone` : "git is not installed on this machine";
|
|
10305
10367
|
}
|
|
10306
10368
|
function inspectHandoff(dir, cfg, ticket, role) {
|
|
10307
10369
|
const remote = cfg.branch.remote;
|
|
@@ -10859,9 +10921,12 @@ async function writeHandoffBounces(target, rowId, count) {
|
|
|
10859
10921
|
}
|
|
10860
10922
|
}
|
|
10861
10923
|
async function post(target, path, body) {
|
|
10924
|
+
return send(target, "POST", path, body);
|
|
10925
|
+
}
|
|
10926
|
+
async function send(target, method, path, body) {
|
|
10862
10927
|
const url = `${target.baseUrl.replace(/\/+$/, "")}/api/workspaces/${target.workspaceId}${path}`;
|
|
10863
10928
|
const res = await fetch(url, {
|
|
10864
|
-
method
|
|
10929
|
+
method,
|
|
10865
10930
|
headers: {
|
|
10866
10931
|
Authorization: `Bearer ${target.apiKey}`,
|
|
10867
10932
|
// Cloudflare 403s default agents on this host — same header connect.ts sends.
|
|
@@ -10873,24 +10938,41 @@ async function post(target, path, body) {
|
|
|
10873
10938
|
if (!res.ok) throw new AgentLogHttpError(`${path}: ${res.status} ${res.statusText}`, res.status);
|
|
10874
10939
|
return await res.json();
|
|
10875
10940
|
}
|
|
10876
|
-
var RUNNING_OUTCOME = "running";
|
|
10877
10941
|
async function startAgentRunRow(target, s) {
|
|
10942
|
+
if (!target.actor && !s.runId) return void 0;
|
|
10943
|
+
const body = {
|
|
10944
|
+
agentId: target.agentId,
|
|
10945
|
+
ticketReference: s.ticketReference,
|
|
10946
|
+
startedAt: s.startedAt,
|
|
10947
|
+
source: "client",
|
|
10948
|
+
client: "crew",
|
|
10949
|
+
model: s.model,
|
|
10950
|
+
promptVersion: s.promptVersion,
|
|
10951
|
+
promptSha: s.promptSha,
|
|
10952
|
+
runId: s.runId,
|
|
10953
|
+
harness: s.harness,
|
|
10954
|
+
provider: s.provider
|
|
10955
|
+
};
|
|
10956
|
+
let actor = {};
|
|
10957
|
+
if (target.actor) {
|
|
10958
|
+
let label = s.actorLabel;
|
|
10959
|
+
try {
|
|
10960
|
+
const row = await request(target, "GET", `/data-models/${target.actor.table}/records/${target.actor.recordId}`);
|
|
10961
|
+
if (row.name) label = row.name;
|
|
10962
|
+
} catch {
|
|
10963
|
+
}
|
|
10964
|
+
actor = { actorTable: target.actor.table, actorRecordId: target.actor.recordId, ...label ? { actorLabel: label } : {} };
|
|
10965
|
+
}
|
|
10878
10966
|
try {
|
|
10879
|
-
const entry = await post(target, "/agents/log", {
|
|
10880
|
-
|
|
10881
|
-
|
|
10882
|
-
|
|
10883
|
-
|
|
10884
|
-
|
|
10885
|
-
|
|
10886
|
-
|
|
10887
|
-
|
|
10888
|
-
promptSha: s.promptSha,
|
|
10889
|
-
runId: s.runId,
|
|
10890
|
-
harness: s.harness,
|
|
10891
|
-
provider: s.provider
|
|
10892
|
-
});
|
|
10893
|
-
return entry.id;
|
|
10967
|
+
const entry = await post(target, "/agents/log", { ...body, ...actor });
|
|
10968
|
+
return { id: entry.id, live: target.actor !== void 0 };
|
|
10969
|
+
} catch (e) {
|
|
10970
|
+
if (!(e instanceof AgentLogHttpError) || e.status !== 400 || Object.keys(actor).length === 0) return void 0;
|
|
10971
|
+
}
|
|
10972
|
+
if (!s.runId) return void 0;
|
|
10973
|
+
try {
|
|
10974
|
+
const entry = await post(target, "/agents/log", body);
|
|
10975
|
+
return { id: entry.id, live: false };
|
|
10894
10976
|
} catch {
|
|
10895
10977
|
return void 0;
|
|
10896
10978
|
}
|
|
@@ -10936,6 +11018,92 @@ async function updateStartedRow(target, rowId, body) {
|
|
|
10936
11018
|
throw e;
|
|
10937
11019
|
}
|
|
10938
11020
|
}
|
|
11021
|
+
var CYCLE_BODY_LIMIT_BYTES = 2048;
|
|
11022
|
+
var CYCLE_TRUNCATION_MARKER = " \u2026[truncated]";
|
|
11023
|
+
var MAX_CYCLES_PER_BATCH = 200;
|
|
11024
|
+
function capCycleText(text2) {
|
|
11025
|
+
if (Buffer.byteLength(text2) <= CYCLE_BODY_LIMIT_BYTES) return text2;
|
|
11026
|
+
const room = CYCLE_BODY_LIMIT_BYTES - Buffer.byteLength(CYCLE_TRUNCATION_MARKER);
|
|
11027
|
+
let out = text2.slice(0, room);
|
|
11028
|
+
while (Buffer.byteLength(out) > room) out = out.slice(0, -1);
|
|
11029
|
+
return out + CYCLE_TRUNCATION_MARKER;
|
|
11030
|
+
}
|
|
11031
|
+
var LiveRunReporter = class {
|
|
11032
|
+
/** Cycles delivered to the row, from the start of the run. */
|
|
11033
|
+
posted = 0;
|
|
11034
|
+
live = true;
|
|
11035
|
+
nextIndex = 0;
|
|
11036
|
+
pending = [];
|
|
11037
|
+
lastSent = Date.now();
|
|
11038
|
+
timer;
|
|
11039
|
+
inFlight = Promise.resolve();
|
|
11040
|
+
windowMs;
|
|
11041
|
+
heartbeatMs;
|
|
11042
|
+
target;
|
|
11043
|
+
rowId;
|
|
11044
|
+
o;
|
|
11045
|
+
constructor(target, rowId, o = {}, alreadyPosted = 0) {
|
|
11046
|
+
this.target = target;
|
|
11047
|
+
this.rowId = rowId;
|
|
11048
|
+
this.o = o;
|
|
11049
|
+
this.windowMs = o.windowMs ?? 4e3;
|
|
11050
|
+
this.heartbeatMs = o.heartbeatMs ?? 3e4;
|
|
11051
|
+
this.posted = alreadyPosted;
|
|
11052
|
+
this.nextIndex = alreadyPosted;
|
|
11053
|
+
}
|
|
11054
|
+
start() {
|
|
11055
|
+
if (this.timer || !this.live) return;
|
|
11056
|
+
this.timer = setInterval(() => {
|
|
11057
|
+
void this.tick();
|
|
11058
|
+
}, this.windowMs);
|
|
11059
|
+
this.timer.unref?.();
|
|
11060
|
+
}
|
|
11061
|
+
/** Buffers one cycle for the next batch. A cycle already delivered or buffered is ignored. */
|
|
11062
|
+
add(c) {
|
|
11063
|
+
if (!this.live || c.cycleIndex < this.nextIndex) return;
|
|
11064
|
+
this.nextIndex = c.cycleIndex + 1;
|
|
11065
|
+
this.pending.push({ ...c, thinking: capCycleText(c.thinking) });
|
|
11066
|
+
}
|
|
11067
|
+
/** One window: send the buffered cycles, or a heartbeat when idle too long. Serialized. */
|
|
11068
|
+
tick() {
|
|
11069
|
+
this.inFlight = this.inFlight.then(() => this.step());
|
|
11070
|
+
return this.inFlight;
|
|
11071
|
+
}
|
|
11072
|
+
/** Stops the timer and waits out a send in flight. What is still buffered is left to the end-of-run report. */
|
|
11073
|
+
async stop() {
|
|
11074
|
+
if (this.timer) clearInterval(this.timer);
|
|
11075
|
+
this.timer = void 0;
|
|
11076
|
+
await this.inFlight;
|
|
11077
|
+
}
|
|
11078
|
+
async step() {
|
|
11079
|
+
if (!this.live) return;
|
|
11080
|
+
try {
|
|
11081
|
+
if (this.pending.length > 0) {
|
|
11082
|
+
const batch = this.pending.slice(0, MAX_CYCLES_PER_BATCH);
|
|
11083
|
+
await post(this.target, `/agents/log/${this.rowId}/cycles`, batch.map((c) => ({
|
|
11084
|
+
cycleIndex: c.cycleIndex,
|
|
11085
|
+
occurredAt: c.occurredAt,
|
|
11086
|
+
thinking: c.thinking,
|
|
11087
|
+
...c.role ? { role: c.role } : {}
|
|
11088
|
+
})));
|
|
11089
|
+
this.pending.splice(0, batch.length);
|
|
11090
|
+
this.posted = batch[batch.length - 1].cycleIndex + 1;
|
|
11091
|
+
this.lastSent = Date.now();
|
|
11092
|
+
this.o.onPosted?.(this.posted);
|
|
11093
|
+
} else if (Date.now() - this.lastSent >= this.heartbeatMs) {
|
|
11094
|
+
await send(this.target, "PATCH", `/agents/log/${this.rowId}`, {});
|
|
11095
|
+
this.lastSent = Date.now();
|
|
11096
|
+
}
|
|
11097
|
+
} catch (e) {
|
|
11098
|
+
if (e instanceof AgentLogHttpError && e.status < 500) {
|
|
11099
|
+
this.live = false;
|
|
11100
|
+
if (this.timer) clearInterval(this.timer);
|
|
11101
|
+
this.timer = void 0;
|
|
11102
|
+
this.pending.length = 0;
|
|
11103
|
+
}
|
|
11104
|
+
}
|
|
11105
|
+
}
|
|
11106
|
+
};
|
|
10939
11107
|
async function reportAgentRun(target, run4) {
|
|
10940
11108
|
let ticketRecordId;
|
|
10941
11109
|
if (target.tickets && run4.ticketReference) {
|
|
@@ -10985,7 +11153,7 @@ async function reportAgentRun(target, run4) {
|
|
|
10985
11153
|
}
|
|
10986
11154
|
}
|
|
10987
11155
|
}
|
|
10988
|
-
for (const cycle of run4.cycles) {
|
|
11156
|
+
for (const cycle of run4.cycles.slice(run4.cyclesPosted ?? 0)) {
|
|
10989
11157
|
await post(target, `/agents/log/${entry.id}/cycles`, {
|
|
10990
11158
|
cycleIndex: cycle.cycleIndex,
|
|
10991
11159
|
occurredAt: cycle.occurredAt,
|
|
@@ -11041,20 +11209,20 @@ async function addRunToTicket(target, t, recordId, run4) {
|
|
|
11041
11209
|
};
|
|
11042
11210
|
}
|
|
11043
11211
|
}
|
|
11044
|
-
var queueDir = (stateDir) =>
|
|
11212
|
+
var queueDir = (stateDir) => join27(stateDir, "pending-agent-logs");
|
|
11045
11213
|
function queueAgentRun(stateDir, name, q2) {
|
|
11046
|
-
|
|
11047
|
-
|
|
11214
|
+
mkdirSync18(queueDir(stateDir), { recursive: true });
|
|
11215
|
+
writeFileSync19(join27(queueDir(stateDir), `${name}.json`), JSON.stringify(q2));
|
|
11048
11216
|
}
|
|
11049
11217
|
async function replayQueuedAgentRuns(stateDir, route2, keyFor, log, now = /* @__PURE__ */ new Date()) {
|
|
11050
11218
|
const dir = queueDir(stateDir);
|
|
11051
|
-
if (!
|
|
11219
|
+
if (!existsSync25(dir)) return 0;
|
|
11052
11220
|
let sent = 0;
|
|
11053
11221
|
for (const f of readdirSync8(dir).filter((n) => n.endsWith(".json")).sort()) {
|
|
11054
|
-
const path =
|
|
11222
|
+
const path = join27(dir, f);
|
|
11055
11223
|
let q2;
|
|
11056
11224
|
try {
|
|
11057
|
-
q2 = JSON.parse(
|
|
11225
|
+
q2 = JSON.parse(readFileSync25(path, "utf8"));
|
|
11058
11226
|
} catch {
|
|
11059
11227
|
continue;
|
|
11060
11228
|
}
|
|
@@ -11073,17 +11241,17 @@ async function replayQueuedAgentRuns(stateDir, route2, keyFor, log, now = /* @__
|
|
|
11073
11241
|
attempts: 0,
|
|
11074
11242
|
nextAttemptAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
11075
11243
|
});
|
|
11076
|
-
|
|
11244
|
+
rmSync14(path, { force: true });
|
|
11077
11245
|
sent += 1;
|
|
11078
11246
|
log.emit(`sent a queued Agent Log report (${f})`);
|
|
11079
11247
|
} catch (e) {
|
|
11080
11248
|
if (!(e instanceof AgentLogUnreachableError)) {
|
|
11081
|
-
|
|
11249
|
+
rmSync14(path, { force: true });
|
|
11082
11250
|
log.warn(`dropped a queued Agent Log report (${f}): ${e.message}`);
|
|
11083
11251
|
continue;
|
|
11084
11252
|
}
|
|
11085
11253
|
const attempts = q2.attempts + 1;
|
|
11086
|
-
|
|
11254
|
+
writeFileSync19(path, JSON.stringify({
|
|
11087
11255
|
...q2,
|
|
11088
11256
|
attempts,
|
|
11089
11257
|
warned: true,
|
|
@@ -11094,20 +11262,20 @@ async function replayQueuedAgentRuns(stateDir, route2, keyFor, log, now = /* @__
|
|
|
11094
11262
|
}
|
|
11095
11263
|
return sent;
|
|
11096
11264
|
}
|
|
11097
|
-
var countersDir = (stateDir) =>
|
|
11265
|
+
var countersDir = (stateDir) => join27(stateDir, "pending-ticket-counters");
|
|
11098
11266
|
function queueTicketCounters(stateDir, name, q2) {
|
|
11099
|
-
|
|
11100
|
-
|
|
11267
|
+
mkdirSync18(countersDir(stateDir), { recursive: true });
|
|
11268
|
+
writeFileSync19(join27(countersDir(stateDir), `${name}.json`), JSON.stringify(q2));
|
|
11101
11269
|
}
|
|
11102
11270
|
async function replayQueuedTicketCounters(stateDir, route2, keyFor, log, now = /* @__PURE__ */ new Date()) {
|
|
11103
11271
|
const dir = countersDir(stateDir);
|
|
11104
|
-
if (!
|
|
11272
|
+
if (!existsSync25(dir)) return 0;
|
|
11105
11273
|
let sent = 0;
|
|
11106
11274
|
for (const f of readdirSync8(dir).filter((n) => n.endsWith(".json")).sort()) {
|
|
11107
|
-
const path =
|
|
11275
|
+
const path = join27(dir, f);
|
|
11108
11276
|
let q2;
|
|
11109
11277
|
try {
|
|
11110
|
-
q2 = JSON.parse(
|
|
11278
|
+
q2 = JSON.parse(readFileSync25(path, "utf8"));
|
|
11111
11279
|
} catch {
|
|
11112
11280
|
continue;
|
|
11113
11281
|
}
|
|
@@ -11116,17 +11284,17 @@ async function replayQueuedTicketCounters(stateDir, route2, keyFor, log, now = /
|
|
|
11116
11284
|
const apiKey = await keyFor(q2.role);
|
|
11117
11285
|
if (!apiKey) continue;
|
|
11118
11286
|
await writeCounters({ ...q2.target, apiKey }, q2.write);
|
|
11119
|
-
|
|
11287
|
+
rmSync14(path, { force: true });
|
|
11120
11288
|
sent += 1;
|
|
11121
11289
|
log.emit(`added a queued run's spend to ${q2.write.ticketReference ?? q2.write.recordId} (${f})`);
|
|
11122
11290
|
} catch (e) {
|
|
11123
11291
|
if (!isRetryable(e)) {
|
|
11124
|
-
|
|
11292
|
+
rmSync14(path, { force: true });
|
|
11125
11293
|
log.warn(`dropped a queued ticket counter update (${f}): ${e.message}`);
|
|
11126
11294
|
continue;
|
|
11127
11295
|
}
|
|
11128
11296
|
const attempts = q2.attempts + 1;
|
|
11129
|
-
|
|
11297
|
+
writeFileSync19(path, JSON.stringify({
|
|
11130
11298
|
...q2,
|
|
11131
11299
|
attempts,
|
|
11132
11300
|
warned: true,
|
|
@@ -11369,8 +11537,8 @@ var HandoffTranscriptTracker = class {
|
|
|
11369
11537
|
import { createHash as createHash4 } from "crypto";
|
|
11370
11538
|
import { spawn as spawn4 } from "child_process";
|
|
11371
11539
|
import { execFileSync as execFileSync8 } from "child_process";
|
|
11372
|
-
import { existsSync as
|
|
11373
|
-
import { dirname as
|
|
11540
|
+
import { existsSync as existsSync26, mkdirSync as mkdirSync19, readFileSync as readFileSync26, renameSync as renameSync4, writeFileSync as writeFileSync20, rmSync as rmSync15, statSync as statSync8 } from "fs";
|
|
11541
|
+
import { dirname as dirname14, join as join28 } from "path";
|
|
11374
11542
|
import { fileURLToPath } from "url";
|
|
11375
11543
|
import { tmpdir as tmpdir3 } from "os";
|
|
11376
11544
|
var SANDBOX_BASE_IMAGE = "nvcr.io/nvidia/base/ubuntu:24.04";
|
|
@@ -11385,9 +11553,9 @@ var SANDBOX_UID = 1e3;
|
|
|
11385
11553
|
var CREW_PREFIX = "/opt/crew";
|
|
11386
11554
|
var SANDBOX_BRIDGE_PATH = `${CREW_PREFIX}/bin/intel-bridge`;
|
|
11387
11555
|
function readBridgeBundle() {
|
|
11388
|
-
const here =
|
|
11389
|
-
for (const p of [
|
|
11390
|
-
if (
|
|
11556
|
+
const here = dirname14(fileURLToPath(import.meta.url));
|
|
11557
|
+
for (const p of [join28(here, "sandbox-intel-bridge.cjs"), join28(here, "..", "dist", "sandbox-intel-bridge.cjs")]) {
|
|
11558
|
+
if (existsSync26(p)) return readFileSync26(p, "utf8");
|
|
11391
11559
|
}
|
|
11392
11560
|
return void 0;
|
|
11393
11561
|
}
|
|
@@ -11471,7 +11639,7 @@ var HOST_CA_BUNDLES = ["/etc/ssl/certs/ca-certificates.crt", "/etc/pki/tls/certs
|
|
|
11471
11639
|
function readHostCaBundle(paths = HOST_CA_BUNDLES) {
|
|
11472
11640
|
for (const path of paths) {
|
|
11473
11641
|
try {
|
|
11474
|
-
return
|
|
11642
|
+
return readFileSync26(path, "utf8");
|
|
11475
11643
|
} catch {
|
|
11476
11644
|
}
|
|
11477
11645
|
}
|
|
@@ -11562,21 +11730,21 @@ function planSandbox(repo, decl, warm = {}, bridge) {
|
|
|
11562
11730
|
}
|
|
11563
11731
|
var SHIP_SANDBOX_KEY = "@ship";
|
|
11564
11732
|
var shipSandboxRef = () => ({ name: SHIP_SANDBOX_KEY, decl: { packages: [], setup: [] } });
|
|
11565
|
-
var sandboxStatePath = (stateDir) =>
|
|
11733
|
+
var sandboxStatePath = (stateDir) => join28(stateDir, "sandbox-images.json");
|
|
11566
11734
|
function readSandboxState(stateDir) {
|
|
11567
11735
|
try {
|
|
11568
|
-
const v = JSON.parse(
|
|
11736
|
+
const v = JSON.parse(readFileSync26(sandboxStatePath(stateDir), "utf8"));
|
|
11569
11737
|
return v && typeof v === "object" && !Array.isArray(v) ? v : {};
|
|
11570
11738
|
} catch {
|
|
11571
11739
|
return {};
|
|
11572
11740
|
}
|
|
11573
11741
|
}
|
|
11574
11742
|
function writeSandboxState(stateDir, state) {
|
|
11575
|
-
|
|
11743
|
+
mkdirSync19(stateDir, { recursive: true });
|
|
11576
11744
|
const file = sandboxStatePath(stateDir);
|
|
11577
|
-
|
|
11745
|
+
writeFileSync20(`${file}.tmp`, `${JSON.stringify(state, null, 2)}
|
|
11578
11746
|
`);
|
|
11579
|
-
|
|
11747
|
+
renameSync4(`${file}.tmp`, file);
|
|
11580
11748
|
}
|
|
11581
11749
|
function sandboxImageFor(state, repo) {
|
|
11582
11750
|
return state[repo]?.tags[0]?.tag ?? null;
|
|
@@ -11612,7 +11780,7 @@ var spawnBuildRunner = (engine = "docker") => (args, logPath) => new Promise((re
|
|
|
11612
11780
|
child.stdout.on("data", (d) => chunks.push(d));
|
|
11613
11781
|
child.stderr.on("data", (d) => chunks.push(d));
|
|
11614
11782
|
const done = (code, extra = "") => {
|
|
11615
|
-
|
|
11783
|
+
writeFileSync20(logPath, `$ ${engine} ${args.join(" ")}
|
|
11616
11784
|
${Buffer.concat(chunks).toString("utf8")}${extra}`, { flag: "a" });
|
|
11617
11785
|
resolve8(code);
|
|
11618
11786
|
};
|
|
@@ -11634,7 +11802,7 @@ var engineRemoveImage = (engine = "docker", exec = realExec) => (tag) => {
|
|
|
11634
11802
|
} catch {
|
|
11635
11803
|
}
|
|
11636
11804
|
};
|
|
11637
|
-
var sandboxLogDir = (stateDir) =>
|
|
11805
|
+
var sandboxLogDir = (stateDir) => join28(stateDir, "sandbox-logs");
|
|
11638
11806
|
async function buildSandboxImage(plan, deps) {
|
|
11639
11807
|
const now = deps.now ?? (() => /* @__PURE__ */ new Date());
|
|
11640
11808
|
const state = readSandboxState(deps.stateDir);
|
|
@@ -11643,21 +11811,21 @@ async function buildSandboxImage(plan, deps) {
|
|
|
11643
11811
|
return { kind: "reused", tag: plan.tag };
|
|
11644
11812
|
}
|
|
11645
11813
|
const logDir = sandboxLogDir(deps.stateDir);
|
|
11646
|
-
|
|
11647
|
-
const logPath =
|
|
11814
|
+
mkdirSync19(logDir, { recursive: true });
|
|
11815
|
+
const logPath = join28(logDir, `${slug(plan.repo)}-${now().toISOString().replace(/[:.]/g, "-")}.log`);
|
|
11648
11816
|
const builtLayers = [];
|
|
11649
11817
|
for (const layer of plan.layers) {
|
|
11650
11818
|
if (deps.hasImage(layer.tag)) continue;
|
|
11651
|
-
const ctx =
|
|
11652
|
-
|
|
11819
|
+
const ctx = join28(tmpdir3(), `crew-sandbox-${hash([layer.tag, process.pid, Date.now()])}`);
|
|
11820
|
+
mkdirSync19(ctx, { recursive: true });
|
|
11653
11821
|
try {
|
|
11654
|
-
|
|
11822
|
+
writeFileSync20(join28(ctx, "Dockerfile"), layer.dockerfile);
|
|
11655
11823
|
for (const [name, content] of Object.entries(layer.files)) {
|
|
11656
|
-
|
|
11657
|
-
|
|
11824
|
+
mkdirSync19(dirname14(join28(ctx, name)), { recursive: true });
|
|
11825
|
+
writeFileSync20(join28(ctx, name), content);
|
|
11658
11826
|
}
|
|
11659
|
-
if (layer.caBundleFile)
|
|
11660
|
-
const code = await deps.run(["build", "--tag", layer.tag, "--file",
|
|
11827
|
+
if (layer.caBundleFile) writeFileSync20(join28(ctx, layer.caBundleFile), (deps.caBundle ?? readHostCaBundle)());
|
|
11828
|
+
const code = await deps.run(["build", "--tag", layer.tag, "--file", join28(ctx, "Dockerfile"), ctx], logPath);
|
|
11661
11829
|
if (code === BUILD_INTERRUPTED) return { kind: "interrupted", tag: plan.tag };
|
|
11662
11830
|
if (code !== 0) {
|
|
11663
11831
|
state[plan.repo] = { ...entry, failure: { tag: plan.tag, at: now().toISOString(), logPath } };
|
|
@@ -11666,7 +11834,7 @@ async function buildSandboxImage(plan, deps) {
|
|
|
11666
11834
|
}
|
|
11667
11835
|
builtLayers.push(layer.name);
|
|
11668
11836
|
} finally {
|
|
11669
|
-
|
|
11837
|
+
rmSync15(ctx, { recursive: true, force: true });
|
|
11670
11838
|
}
|
|
11671
11839
|
}
|
|
11672
11840
|
const tags = [{ tag: plan.tag, builtAt: now().toISOString(), claude: plan.claude }, ...entry.tags.filter((t) => t.tag !== plan.tag)];
|
|
@@ -11769,8 +11937,8 @@ function expandSkillMarkers(text2, lookup2, opts = {}) {
|
|
|
11769
11937
|
}
|
|
11770
11938
|
|
|
11771
11939
|
// src/skills.ts
|
|
11772
|
-
import { readFileSync as
|
|
11773
|
-
import { join as
|
|
11940
|
+
import { readFileSync as readFileSync29, readdirSync as readdirSync9, existsSync as existsSync28 } from "fs";
|
|
11941
|
+
import { join as join30 } from "path";
|
|
11774
11942
|
import { parse as parseYaml2 } from "yaml";
|
|
11775
11943
|
import { TablationClient as TablationClient3, StaleWriteError as StaleWriteError3, TablationApiError as TablationApiError2 } from "@tablation/client";
|
|
11776
11944
|
|
|
@@ -11786,7 +11954,7 @@ ${additions}`;
|
|
|
11786
11954
|
}
|
|
11787
11955
|
|
|
11788
11956
|
// src/persona-file.ts
|
|
11789
|
-
import { readFileSync as
|
|
11957
|
+
import { readFileSync as readFileSync27 } from "fs";
|
|
11790
11958
|
import { parse as parseYaml } from "yaml";
|
|
11791
11959
|
function parsePersonaText(text2, path) {
|
|
11792
11960
|
const match = /^---\n([\s\S]*?)\n---\n([\s\S]*)$/.exec(text2);
|
|
@@ -11798,12 +11966,12 @@ function parsePersonaText(text2, path) {
|
|
|
11798
11966
|
return { body: match[2], ...typeof meta.chat_enabled === "boolean" ? { chatEnabled: meta.chat_enabled } : {} };
|
|
11799
11967
|
}
|
|
11800
11968
|
function readPersonaFile(path) {
|
|
11801
|
-
return parsePersonaText(
|
|
11969
|
+
return parsePersonaText(readFileSync27(path, "utf8"), path);
|
|
11802
11970
|
}
|
|
11803
11971
|
|
|
11804
11972
|
// src/agents.ts
|
|
11805
|
-
import { readFileSync as
|
|
11806
|
-
import { join as
|
|
11973
|
+
import { readFileSync as readFileSync28, existsSync as existsSync27 } from "fs";
|
|
11974
|
+
import { join as join29 } from "path";
|
|
11807
11975
|
import { TablationClient as TablationClient2, StaleWriteError as StaleWriteError2, TablationApiError } from "@tablation/client";
|
|
11808
11976
|
var PERSONA_NAME = {
|
|
11809
11977
|
dev: "Developer",
|
|
@@ -11817,17 +11985,17 @@ var CREW_AGENT_COLUMN = "agent_id";
|
|
|
11817
11985
|
var AgentsSyncError = class extends Error {
|
|
11818
11986
|
};
|
|
11819
11987
|
function personaDefaultPrompt(promptsDir, role) {
|
|
11820
|
-
const briefPath =
|
|
11821
|
-
if (!
|
|
11988
|
+
const briefPath = join29(promptsDir, "personas", `lane-${role}.md`);
|
|
11989
|
+
if (!existsSync27(briefPath)) throw new AgentsSyncError(`no brief at ${briefPath}`);
|
|
11822
11990
|
const brief = readPersonaFile(briefPath).body;
|
|
11823
11991
|
if (SELF_CONTAINED_ROLES.has(role)) return brief;
|
|
11824
|
-
const commonPath =
|
|
11825
|
-
if (!
|
|
11826
|
-
return `${
|
|
11992
|
+
const commonPath = join29(promptsDir, "personas", "common.md");
|
|
11993
|
+
if (!existsSync27(commonPath)) return brief;
|
|
11994
|
+
return `${readFileSync28(commonPath, "utf8")}${brief}`;
|
|
11827
11995
|
}
|
|
11828
11996
|
function personaChatEnabled(promptsDir, role) {
|
|
11829
|
-
const briefPath =
|
|
11830
|
-
return
|
|
11997
|
+
const briefPath = join29(promptsDir, "personas", `lane-${role}.md`);
|
|
11998
|
+
return existsSync27(briefPath) ? readPersonaFile(briefPath).chatEnabled : void 0;
|
|
11831
11999
|
}
|
|
11832
12000
|
async function resolveAgentId(route2, role, opts) {
|
|
11833
12001
|
const cached = route2.resolved?.agentPersonas?.[role]?.agentId;
|
|
@@ -12297,7 +12465,7 @@ function describeCrewLink(o) {
|
|
|
12297
12465
|
var SkillSyncError = class extends Error {
|
|
12298
12466
|
};
|
|
12299
12467
|
function parseSkillFile(path) {
|
|
12300
|
-
const text2 =
|
|
12468
|
+
const text2 = readFileSync29(path, "utf8");
|
|
12301
12469
|
const match = /^---\n([\s\S]*?)\n---\n([\s\S]*)$/.exec(text2);
|
|
12302
12470
|
if (!match) throw new SkillSyncError(`${path}: missing YAML frontmatter (expected a leading --- block)`);
|
|
12303
12471
|
const frontmatter = match[1];
|
|
@@ -12324,9 +12492,9 @@ function parseSkillFile(path) {
|
|
|
12324
12492
|
};
|
|
12325
12493
|
}
|
|
12326
12494
|
function listLocalSkills(promptsDir) {
|
|
12327
|
-
const dir =
|
|
12328
|
-
if (!
|
|
12329
|
-
return readdirSync9(dir).filter((f) => f.endsWith(".md")).map((f) => parseSkillFile(
|
|
12495
|
+
const dir = join30(promptsDir, "skills");
|
|
12496
|
+
if (!existsSync28(dir)) return [];
|
|
12497
|
+
return readdirSync9(dir).filter((f) => f.endsWith(".md")).map((f) => parseSkillFile(join30(dir, f)));
|
|
12330
12498
|
}
|
|
12331
12499
|
function personaColumn(model) {
|
|
12332
12500
|
for (const c of ["persona_id", "persona"]) if (model.fields?.some((f) => f.columnName === c)) return c;
|
|
@@ -12560,10 +12728,10 @@ function skillMarkerWarnings(promptsDir, personaPrompts) {
|
|
|
12560
12728
|
|
|
12561
12729
|
// src/runner.ts
|
|
12562
12730
|
import { spawn as spawn5, execFile, execFileSync as execFileSync9 } from "child_process";
|
|
12563
|
-
import { mkdtempSync, mkdirSync as
|
|
12731
|
+
import { mkdtempSync, mkdirSync as mkdirSync20, writeFileSync as writeFileSync21, rmSync as rmSync16 } from "fs";
|
|
12564
12732
|
import { createHash as createHash5 } from "crypto";
|
|
12565
12733
|
import { tmpdir as tmpdir4 } from "os";
|
|
12566
|
-
import { basename as basename8, dirname as
|
|
12734
|
+
import { basename as basename8, dirname as dirname15, join as join31 } from "path";
|
|
12567
12735
|
import { promisify } from "util";
|
|
12568
12736
|
|
|
12569
12737
|
// src/run-limit.ts
|
|
@@ -12698,6 +12866,12 @@ var SandboxRunner = class {
|
|
|
12698
12866
|
if (/[\r\n]/.test(v)) throw new Error(`the sandbox environment variable ${k} contains a newline, which the sandbox gateway refuses`);
|
|
12699
12867
|
}
|
|
12700
12868
|
const createEnv = { ...process.env, ...plan.setEnv };
|
|
12869
|
+
for (const [k, v] of Object.entries(plan.sandboxRepoEnv ?? {})) {
|
|
12870
|
+
if (k in plan.setEnv) continue;
|
|
12871
|
+
if (/[\r\n]/.test(v)) throw new Error(`the repository environment variable ${k} contains a newline, which the sandbox gateway refuses`);
|
|
12872
|
+
createEnv[k] = v;
|
|
12873
|
+
if (!secretKeys.includes(k)) secretKeys.push(k);
|
|
12874
|
+
}
|
|
12701
12875
|
if (cfg.forgeTokenVar && o.env[cfg.forgeTokenVar] !== void 0) createEnv[cfg.forgeTokenVar] = o.env[cfg.forgeTokenVar];
|
|
12702
12876
|
let policyFile = cfg.policy;
|
|
12703
12877
|
let generated;
|
|
@@ -12708,8 +12882,8 @@ var SandboxRunner = class {
|
|
|
12708
12882
|
throw new Error(`cannot generate the sandbox policy: ${e.message}`);
|
|
12709
12883
|
}
|
|
12710
12884
|
policyFile = policyPathFor(plan.streamPath);
|
|
12711
|
-
|
|
12712
|
-
|
|
12885
|
+
mkdirSync20(dirname15(policyFile), { recursive: true });
|
|
12886
|
+
writeFileSync21(policyFile, generated.yaml, { mode: 384 });
|
|
12713
12887
|
}
|
|
12714
12888
|
const create2 = ["sandbox", "create", "--name", name, "--detach"];
|
|
12715
12889
|
if (policyFile) create2.push("--policy", policyFile);
|
|
@@ -12758,13 +12932,13 @@ var SandboxRunner = class {
|
|
|
12758
12932
|
const harness = cfg.agentBin ?? basename8(plan.bin);
|
|
12759
12933
|
const viaUpload = Buffer.byteLength(plan.prompt) > SANDBOX_STDIN_LIMIT;
|
|
12760
12934
|
if (viaUpload) {
|
|
12761
|
-
const tmp = mkdtempSync(
|
|
12935
|
+
const tmp = mkdtempSync(join31(tmpdir4(), "crew-prompt-"));
|
|
12762
12936
|
try {
|
|
12763
|
-
const file =
|
|
12764
|
-
|
|
12937
|
+
const file = join31(tmp, "prompt.txt");
|
|
12938
|
+
writeFileSync21(file, plan.prompt, { mode: 384 });
|
|
12765
12939
|
await this.os(["sandbox", "upload", name, file, SANDBOX_PROMPT_PATH]);
|
|
12766
12940
|
} finally {
|
|
12767
|
-
|
|
12941
|
+
rmSync16(tmp, { recursive: true, force: true });
|
|
12768
12942
|
}
|
|
12769
12943
|
}
|
|
12770
12944
|
const withStubs = `${sandboxEnvExports()}PATH=${shQuote2(SANDBOX_STUB_DIR)}:"$PATH"; export PATH; `;
|
|
@@ -12959,7 +13133,7 @@ var ALLOWANCE_REFUSAL_MARKER = "AI_ALLOWANCE_EXCEEDED";
|
|
|
12959
13133
|
function streamShowsAllowanceRefusal(streamPath) {
|
|
12960
13134
|
let raw;
|
|
12961
13135
|
try {
|
|
12962
|
-
raw =
|
|
13136
|
+
raw = readFileSync30(streamPath, "utf8");
|
|
12963
13137
|
} catch {
|
|
12964
13138
|
return false;
|
|
12965
13139
|
}
|
|
@@ -12982,7 +13156,7 @@ function streamShowsAllowanceRefusal(streamPath) {
|
|
|
12982
13156
|
}
|
|
12983
13157
|
return false;
|
|
12984
13158
|
}
|
|
12985
|
-
var digestPathFor = (stateDir, routeLabel, role, runId) =>
|
|
13159
|
+
var digestPathFor = (stateDir, routeLabel, role, runId) => join32(stateDir, `digest-${routeLabel}-${role}${runId ? `-${runId}` : ""}.md`);
|
|
12986
13160
|
function codeBridgeFor(o, harness) {
|
|
12987
13161
|
if (!o.ticket) return void 0;
|
|
12988
13162
|
const number = /(\d+)$/.exec(o.ticket)?.[1];
|
|
@@ -13009,7 +13183,7 @@ function codeBridgeFor(o, harness) {
|
|
|
13009
13183
|
"--clone",
|
|
13010
13184
|
o.ship.sandbox?.workDir ?? DEFAULT_SANDBOX_WORKDIR,
|
|
13011
13185
|
"--state-dir",
|
|
13012
|
-
|
|
13186
|
+
dirname16(SANDBOX_INTEL_DIR),
|
|
13013
13187
|
"--ticket",
|
|
13014
13188
|
number,
|
|
13015
13189
|
...seed ? ["--seed-cache", seed] : []
|
|
@@ -13022,32 +13196,32 @@ function codeBridgeFor(o, harness) {
|
|
|
13022
13196
|
bridge.settingsFile = `${SANDBOX_INTEL_DIR}/gemini-settings.json`;
|
|
13023
13197
|
bridge.files = [{ path: bridge.settingsFile, content: text2 }];
|
|
13024
13198
|
} else {
|
|
13025
|
-
const file =
|
|
13026
|
-
|
|
13027
|
-
|
|
13199
|
+
const file = join32(intelDir(o.stateDir, o.route.route, number), "gemini-settings.json");
|
|
13200
|
+
mkdirSync21(dirname16(file), { recursive: true });
|
|
13201
|
+
writeFileSync22(file, text2);
|
|
13028
13202
|
bridge.settingsFile = file;
|
|
13029
13203
|
}
|
|
13030
13204
|
}
|
|
13031
13205
|
return bridge;
|
|
13032
13206
|
}
|
|
13033
13207
|
function planAgentRun(o) {
|
|
13034
|
-
const briefPath =
|
|
13035
|
-
if (!
|
|
13208
|
+
const briefPath = join32(o.route.promptsDir, "personas", `lane-${o.role}.md`);
|
|
13209
|
+
if (!existsSync29(briefPath)) {
|
|
13036
13210
|
throw new AgentError(`no brief at ${briefPath} \u2014 refusing to run an unscoped session`);
|
|
13037
13211
|
}
|
|
13038
|
-
const commonPath =
|
|
13039
|
-
const usesCommon = !SELF_CONTAINED_ROLES.has(o.role) &&
|
|
13212
|
+
const commonPath = join32(o.route.promptsDir, "personas", "common.md");
|
|
13213
|
+
const usesCommon = !SELF_CONTAINED_ROLES.has(o.role) && existsSync29(commonPath);
|
|
13040
13214
|
const now = o.now ?? (() => Date.now());
|
|
13041
13215
|
const routeLabel = routeSlug(o.route.route);
|
|
13042
13216
|
const ownDigest = o.runId ? digestPathFor(o.stateDir, routeLabel, o.role, o.runId) : void 0;
|
|
13043
|
-
const digestPath2 = ownDigest &&
|
|
13217
|
+
const digestPath2 = ownDigest && existsSync29(ownDigest) ? ownDigest : digestPathFor(o.stateDir, routeLabel, o.role);
|
|
13044
13218
|
let digest;
|
|
13045
13219
|
let ageSeconds;
|
|
13046
|
-
if (
|
|
13220
|
+
if (existsSync29(digestPath2)) {
|
|
13047
13221
|
ageSeconds = Math.floor((now() - statSync9(digestPath2).mtimeMs) / 1e3);
|
|
13048
|
-
if (ageSeconds <= DIGEST_MAX_AGE_SECONDS) digest =
|
|
13222
|
+
if (ageSeconds <= DIGEST_MAX_AGE_SECONDS) digest = readFileSync30(digestPath2, "utf8");
|
|
13049
13223
|
}
|
|
13050
|
-
const common = usesCommon ?
|
|
13224
|
+
const common = usesCommon ? readFileSync30(commonPath, "utf8") : "";
|
|
13051
13225
|
const brief = readPersonaFile(briefPath).body;
|
|
13052
13226
|
const effectiveCommon = o.divergedPrompt ? "" : common;
|
|
13053
13227
|
const effectiveBrief = appendAdditions(o.divergedPrompt ?? brief, o.personaAdditions);
|
|
@@ -13071,7 +13245,7 @@ function planAgentRun(o) {
|
|
|
13071
13245
|
digest
|
|
13072
13246
|
});
|
|
13073
13247
|
const promptSha = createHash6("sha256").update(expanded.text).digest("hex");
|
|
13074
|
-
const streamsDir =
|
|
13248
|
+
const streamsDir = join32(o.stateDir, "streams");
|
|
13075
13249
|
const base = `${routeLabel}-${o.role}-${o.cycle}${o.runId ? `-${o.runId}` : ""}`;
|
|
13076
13250
|
const seat = resolveSeat(o.ship, o.route, o.role, o.agentPersona ?? (o.agentModel ? { model: o.agentModel } : {}), o.repo);
|
|
13077
13251
|
const { model } = seat;
|
|
@@ -13091,6 +13265,7 @@ function planAgentRun(o) {
|
|
|
13091
13265
|
const code = codeBridgeFor(o, adapter.harness);
|
|
13092
13266
|
const sandboxLsp = o.ship.runner === "sandbox" && adapter.harness === "claude" ? sandboxLspPluginFor(o.route, o.repo) : void 0;
|
|
13093
13267
|
const sandboxOrigin = o.ship.runner === "sandbox" ? sandboxOriginFor(o.route, o.repo) : void 0;
|
|
13268
|
+
const repoEnv = o.ship.runner === "sandbox" && o.repo ? envForRepository(readRepositoryEnv(o.stateDir), { repoRowId: repoIdForName(o.route, o.repo), remote: sandboxOrigin }) : {};
|
|
13094
13269
|
const sandboxChoice = o.ship.runner === "sandbox" ? sandboxImageOf(o.route, o.repo, o.stateDir, o.repoContract) : void 0;
|
|
13095
13270
|
const sandboxImage = sandboxChoice?.image;
|
|
13096
13271
|
const sandboxFiles = [...code?.files ?? [], ...sandboxLsp?.files ?? []];
|
|
@@ -13110,6 +13285,7 @@ function planAgentRun(o) {
|
|
|
13110
13285
|
apiKey: o.apiKey,
|
|
13111
13286
|
userAgent: o.ship.userAgent,
|
|
13112
13287
|
agentId: o.resolvedAgentId,
|
|
13288
|
+
...o.route.resolved.models?.crew && o.route.resolved.seats?.[o.role] ? { actor: { table: o.route.resolved.models.crew, recordId: o.route.resolved.seats[o.role] } } : {},
|
|
13113
13289
|
...o.route.resolved.models?.issues ? { tickets: {
|
|
13114
13290
|
issuesModelId: o.route.resolved.models.issues,
|
|
13115
13291
|
keyColumn: columns.key,
|
|
@@ -13147,6 +13323,7 @@ function planAgentRun(o) {
|
|
|
13147
13323
|
runner: "sandbox",
|
|
13148
13324
|
...o.ship.sandbox ? { sandboxConfig: o.ship.sandbox } : {},
|
|
13149
13325
|
...sandboxOrigin ? { sandboxOrigin } : {},
|
|
13326
|
+
...Object.keys(repoEnv).length ? { sandboxRepoEnv: repoEnv } : {},
|
|
13150
13327
|
...sandboxImage ? { sandboxImage } : {},
|
|
13151
13328
|
...sandboxChoice ? { sandboxImageReason: sandboxChoice.reason } : {},
|
|
13152
13329
|
sandboxPolicy: sandboxPolicyInputFor(o.route, toolchain, { harnessBin: invocation.bin, repo: o.repo, sandbox: o.ship.sandbox, contract: o.repoContract }),
|
|
@@ -13176,8 +13353,8 @@ function planAgentRun(o) {
|
|
|
13176
13353
|
digestAttached: digest !== void 0,
|
|
13177
13354
|
digestAgeSeconds: ageSeconds,
|
|
13178
13355
|
model,
|
|
13179
|
-
streamPath:
|
|
13180
|
-
eventsPath:
|
|
13356
|
+
streamPath: join32(streamsDir, `${base}.jsonl`),
|
|
13357
|
+
eventsPath: join32(streamsDir, `${base}.events.jsonl`),
|
|
13181
13358
|
ticket: o.ticket,
|
|
13182
13359
|
ticketRecordId: o.ticketRecordId ?? null,
|
|
13183
13360
|
repo: o.repo ?? null,
|
|
@@ -13206,10 +13383,18 @@ function describePlan(p) {
|
|
|
13206
13383
|
`stream: ${p.streamPath}`
|
|
13207
13384
|
].join("\n");
|
|
13208
13385
|
}
|
|
13386
|
+
function updateSidecar(streamPath, patch2) {
|
|
13387
|
+
const sc = readRunSidecar(streamPath);
|
|
13388
|
+
if (!sc) return;
|
|
13389
|
+
try {
|
|
13390
|
+
writeFileSync22(pidPathFor(streamPath), JSON.stringify({ ...sc, ...patch2 }));
|
|
13391
|
+
} catch {
|
|
13392
|
+
}
|
|
13393
|
+
}
|
|
13209
13394
|
var pidPathFor = (streamPath) => `${streamPath}.pid`;
|
|
13210
13395
|
function readRunSidecar(streamPath) {
|
|
13211
13396
|
try {
|
|
13212
|
-
const sc = JSON.parse(
|
|
13397
|
+
const sc = JSON.parse(readFileSync30(pidPathFor(streamPath), "utf8"));
|
|
13213
13398
|
return typeof sc.pid === "number" && typeof sc.spawnedAt === "string" && typeof sc.role === "string" ? sc : null;
|
|
13214
13399
|
} catch {
|
|
13215
13400
|
return null;
|
|
@@ -13257,7 +13442,7 @@ async function killForDeadline(kill, pid, emit, role, ticket, spawnedAt, limitMi
|
|
|
13257
13442
|
var withoutKey = ({ apiKey: _apiKey, ...rest }) => rest;
|
|
13258
13443
|
function openSink(path) {
|
|
13259
13444
|
try {
|
|
13260
|
-
|
|
13445
|
+
mkdirSync21(dirname16(path), { recursive: true });
|
|
13261
13446
|
return createWriteStream(path, { flags: "a" });
|
|
13262
13447
|
} catch {
|
|
13263
13448
|
return void 0;
|
|
@@ -13300,6 +13485,8 @@ var FileTail = class {
|
|
|
13300
13485
|
var TAIL_POLL_MS = 200;
|
|
13301
13486
|
var RunObserver = class {
|
|
13302
13487
|
cycles = [];
|
|
13488
|
+
/** CREW-3116: sends the cycles to the run's Agent Log row as they are mapped. */
|
|
13489
|
+
reporter;
|
|
13303
13490
|
attribution = new TicketAttributionTracker();
|
|
13304
13491
|
/** Hand-off writes and their outcomes, to tell a run whose hand-off never landed (CREW-2363). */
|
|
13305
13492
|
handoff = new HandoffTranscriptTracker();
|
|
@@ -13333,6 +13520,11 @@ var RunObserver = class {
|
|
|
13333
13520
|
this.liveTicket = id.ticket ?? void 0;
|
|
13334
13521
|
this.mapper = adapter.createStreamMapper?.() ?? { map: (p) => adapter.mapStreamLine(p), flush: () => [] };
|
|
13335
13522
|
}
|
|
13523
|
+
/** Hands the live reporter every cycle mapped so far, then each new one as it arrives. */
|
|
13524
|
+
attachReporter(r) {
|
|
13525
|
+
this.reporter = r;
|
|
13526
|
+
for (const c of this.cycles) r.add(c);
|
|
13527
|
+
}
|
|
13336
13528
|
feed(text2) {
|
|
13337
13529
|
this.buf += text2;
|
|
13338
13530
|
const lines2 = this.buf.split("\n");
|
|
@@ -13414,7 +13606,7 @@ var RunObserver = class {
|
|
|
13414
13606
|
turnText += `${ev.text}
|
|
13415
13607
|
`;
|
|
13416
13608
|
const cycleIndex = this.cycles.length;
|
|
13417
|
-
|
|
13609
|
+
const cycle = {
|
|
13418
13610
|
cycleIndex,
|
|
13419
13611
|
occurredAt: e.at,
|
|
13420
13612
|
thinking: ev.text,
|
|
@@ -13425,7 +13617,9 @@ var RunObserver = class {
|
|
|
13425
13617
|
// for the same column. A `thought` cycle stays untagged, same
|
|
13426
13618
|
// as before this change.
|
|
13427
13619
|
...ev.kind === "text" ? { role: "assistant" } : {}
|
|
13428
|
-
}
|
|
13620
|
+
};
|
|
13621
|
+
this.cycles.push(cycle);
|
|
13622
|
+
this.reporter?.add(cycle);
|
|
13429
13623
|
if (!this.muted) {
|
|
13430
13624
|
this.eventsSink?.write(`${JSON.stringify({
|
|
13431
13625
|
...e,
|
|
@@ -13443,7 +13637,7 @@ var RunObserver = class {
|
|
|
13443
13637
|
};
|
|
13444
13638
|
function writeRunMeta(id, startedAt, liveTicket, extra) {
|
|
13445
13639
|
try {
|
|
13446
|
-
|
|
13640
|
+
writeFileSync22(`${id.streamPath}.meta.json`, JSON.stringify({
|
|
13447
13641
|
route: id.route,
|
|
13448
13642
|
role: id.role,
|
|
13449
13643
|
hint: id.ticket,
|
|
@@ -13550,6 +13744,7 @@ async function finishRun(id, obs, emit, startedAt, end, agentLogKey, hintMoved)
|
|
|
13550
13744
|
// CREW-2980: under `auth: workspace` the endpoint's rows are the accounting; the run row
|
|
13551
13745
|
// keeps turns only, and `reportAgentRun` sums those rows into the ticket counters.
|
|
13552
13746
|
...id.agentLogRowId ? { rowId: id.agentLogRowId } : {},
|
|
13747
|
+
...obs.reporter ? { cyclesPosted: obs.reporter.posted } : {},
|
|
13553
13748
|
...id.workspaceRunId ? { runId: id.workspaceRunId } : {
|
|
13554
13749
|
tokensIn: result?.inputTokens,
|
|
13555
13750
|
tokensOut: result?.outputTokens,
|
|
@@ -13635,7 +13830,7 @@ function spawnAgent(plan, emit, hintMoved) {
|
|
|
13635
13830
|
const id = identityOf(plan, adapter.harness);
|
|
13636
13831
|
let streamFd;
|
|
13637
13832
|
try {
|
|
13638
|
-
|
|
13833
|
+
mkdirSync21(dirname16(plan.streamPath), { recursive: true });
|
|
13639
13834
|
streamFd = openSync4(plan.streamPath, "a");
|
|
13640
13835
|
} catch (e) {
|
|
13641
13836
|
void endSink(eventsSink);
|
|
@@ -13694,11 +13889,12 @@ function spawnAgent(plan, emit, hintMoved) {
|
|
|
13694
13889
|
...plan.workspaceRunId ? { workspaceRunId: plan.workspaceRunId } : {}
|
|
13695
13890
|
};
|
|
13696
13891
|
try {
|
|
13697
|
-
|
|
13892
|
+
writeFileSync22(pidPathFor(plan.streamPath), JSON.stringify(sidecar));
|
|
13698
13893
|
} catch {
|
|
13699
13894
|
}
|
|
13700
13895
|
}
|
|
13701
|
-
const
|
|
13896
|
+
const obs = new RunObserver(id, adapter, eventsSink, emit.cycle);
|
|
13897
|
+
const startedRow = plan.agentLog ? startAgentRunRow(plan.agentLog, {
|
|
13702
13898
|
runId: plan.workspaceRunId,
|
|
13703
13899
|
ticketReference: plan.ticket ?? void 0,
|
|
13704
13900
|
startedAt,
|
|
@@ -13706,19 +13902,20 @@ function spawnAgent(plan, emit, hintMoved) {
|
|
|
13706
13902
|
harness: id.harness,
|
|
13707
13903
|
provider: id.provider,
|
|
13708
13904
|
promptVersion: plan.promptVersion,
|
|
13709
|
-
promptSha: plan.promptSha
|
|
13710
|
-
|
|
13711
|
-
|
|
13712
|
-
|
|
13713
|
-
|
|
13714
|
-
|
|
13715
|
-
|
|
13716
|
-
|
|
13717
|
-
|
|
13718
|
-
}
|
|
13905
|
+
promptSha: plan.promptSha,
|
|
13906
|
+
actorLabel: plan.role
|
|
13907
|
+
}).then((row) => {
|
|
13908
|
+
if (!row) return;
|
|
13909
|
+
id.agentLogRowId = row.id;
|
|
13910
|
+
updateSidecar(plan.streamPath, { agentLogRowId: row.id });
|
|
13911
|
+
if (row.live && plan.agentLog) {
|
|
13912
|
+
const reporter = new LiveRunReporter(plan.agentLog, row.id, {
|
|
13913
|
+
onPosted: (n) => updateSidecar(plan.streamPath, { cyclesPosted: n })
|
|
13914
|
+
});
|
|
13915
|
+
obs.attachReporter(reporter);
|
|
13916
|
+
reporter.start();
|
|
13719
13917
|
}
|
|
13720
13918
|
}) : Promise.resolve();
|
|
13721
|
-
const obs = new RunObserver(id, adapter, eventsSink, emit.cycle);
|
|
13722
13919
|
const meta = { pid: child.pid ?? null, ...deadline ? { deadline } : {} };
|
|
13723
13920
|
obs.onClaim = () => writeRunMeta(id, startedAt, obs.liveTicket, meta);
|
|
13724
13921
|
if (child.pid !== void 0) writeRunMeta(id, startedAt, obs.liveTicket, meta);
|
|
@@ -13750,6 +13947,7 @@ function spawnAgent(plan, emit, hintMoved) {
|
|
|
13750
13947
|
killed = { limitMinutes: plan.maxRunMinutes ?? 0, elapsedMs: Date.now() - Date.parse(spawnedAt) };
|
|
13751
13948
|
}
|
|
13752
13949
|
await startedRow;
|
|
13950
|
+
await obs.reporter?.stop();
|
|
13753
13951
|
const { ms: ms3, handoffPending } = await finishRun(
|
|
13754
13952
|
id,
|
|
13755
13953
|
obs,
|
|
@@ -13779,6 +13977,13 @@ async function reattachRun(streamPath, sc, emit, o = {}) {
|
|
|
13779
13977
|
obs.muted = true;
|
|
13780
13978
|
obs.feed(tail3.poll());
|
|
13781
13979
|
obs.muted = false;
|
|
13980
|
+
if (sc.agentLogRowId && sc.agentLog && o.agentLogKey) {
|
|
13981
|
+
const reporter = new LiveRunReporter({ ...sc.agentLog, apiKey: o.agentLogKey }, sc.agentLogRowId, {
|
|
13982
|
+
onPosted: (n) => updateSidecar(streamPath, { cyclesPosted: n })
|
|
13983
|
+
}, sc.cyclesPosted ?? 0);
|
|
13984
|
+
obs.attachReporter(reporter);
|
|
13985
|
+
reporter.start();
|
|
13986
|
+
}
|
|
13782
13987
|
const runner = runnerOfSidecar(sc);
|
|
13783
13988
|
const adopted = isAlive(sc);
|
|
13784
13989
|
let killed;
|
|
@@ -13796,6 +14001,7 @@ async function reattachRun(streamPath, sc, emit, o = {}) {
|
|
|
13796
14001
|
}
|
|
13797
14002
|
obs.feed(tail3.poll());
|
|
13798
14003
|
obs.end();
|
|
14004
|
+
await obs.reporter?.stop();
|
|
13799
14005
|
await endSink(eventsSink);
|
|
13800
14006
|
await runner.release(runner.reattach(sc), emit);
|
|
13801
14007
|
const interrupted = killed ? WALL_CLOCK_REASON : obs.sawResult ? void 0 : adopted ? "no-result" : "daemon-exit";
|
|
@@ -13829,21 +14035,21 @@ var pidAlive = (pid) => {
|
|
|
13829
14035
|
};
|
|
13830
14036
|
function runFinished(streamPath) {
|
|
13831
14037
|
const path = `${streamPath}.meta.json`;
|
|
13832
|
-
if (!
|
|
14038
|
+
if (!existsSync30(path)) return false;
|
|
13833
14039
|
try {
|
|
13834
|
-
return JSON.parse(
|
|
14040
|
+
return JSON.parse(readFileSync31(path, "utf8")).running !== true;
|
|
13835
14041
|
} catch {
|
|
13836
14042
|
return true;
|
|
13837
14043
|
}
|
|
13838
14044
|
}
|
|
13839
14045
|
function orphanedStreams(o) {
|
|
13840
|
-
const dir =
|
|
13841
|
-
if (!
|
|
14046
|
+
const dir = join33(o.stateDir, "streams");
|
|
14047
|
+
if (!existsSync30(dir)) return [];
|
|
13842
14048
|
const ownerAlive = o.isOwnerAlive ?? pidAlive;
|
|
13843
14049
|
const out = [];
|
|
13844
14050
|
for (const name of readdirSync10(dir)) {
|
|
13845
14051
|
if (!name.endsWith(".jsonl") || name.endsWith(".events.jsonl")) continue;
|
|
13846
|
-
const streamPath =
|
|
14052
|
+
const streamPath = join33(dir, name);
|
|
13847
14053
|
if (runFinished(streamPath)) continue;
|
|
13848
14054
|
const sidecar = readRunSidecar(streamPath);
|
|
13849
14055
|
if (!sidecar || sidecar.route !== o.routeLabel) continue;
|
|
@@ -13896,15 +14102,15 @@ async function reconcileRuns(o) {
|
|
|
13896
14102
|
}
|
|
13897
14103
|
|
|
13898
14104
|
// src/live-runs.ts
|
|
13899
|
-
import { existsSync as
|
|
13900
|
-
import { join as
|
|
14105
|
+
import { existsSync as existsSync31, readdirSync as readdirSync11, statSync as statSync10 } from "fs";
|
|
14106
|
+
import { join as join34 } from "path";
|
|
13901
14107
|
function liveRuns(stateDir, isAlive = runIsAlive) {
|
|
13902
|
-
const dir =
|
|
13903
|
-
if (!
|
|
14108
|
+
const dir = join34(stateDir, "streams");
|
|
14109
|
+
if (!existsSync31(dir)) return [];
|
|
13904
14110
|
const out = [];
|
|
13905
14111
|
for (const name of readdirSync11(dir)) {
|
|
13906
14112
|
if (!name.endsWith(".jsonl") || name.endsWith(".events.jsonl")) continue;
|
|
13907
|
-
const streamPath =
|
|
14113
|
+
const streamPath = join34(dir, name);
|
|
13908
14114
|
if (runFinished(streamPath)) continue;
|
|
13909
14115
|
const sidecar = readRunSidecar(streamPath);
|
|
13910
14116
|
if (!sidecar || !isAlive(sidecar)) continue;
|
|
@@ -13914,12 +14120,12 @@ function liveRuns(stateDir, isAlive = runIsAlive) {
|
|
|
13914
14120
|
}
|
|
13915
14121
|
function runActivity(stateDir, isAlive = runIsAlive) {
|
|
13916
14122
|
const activeRuns = liveRuns(stateDir, isAlive).length;
|
|
13917
|
-
const dir =
|
|
14123
|
+
const dir = join34(stateDir, "streams");
|
|
13918
14124
|
let newest = 0;
|
|
13919
|
-
if (
|
|
14125
|
+
if (existsSync31(dir)) {
|
|
13920
14126
|
for (const name of readdirSync11(dir)) {
|
|
13921
14127
|
if (!name.endsWith(".jsonl") || name.endsWith(".events.jsonl")) continue;
|
|
13922
|
-
const streamPath =
|
|
14128
|
+
const streamPath = join34(dir, name);
|
|
13923
14129
|
if (!runFinished(streamPath)) continue;
|
|
13924
14130
|
try {
|
|
13925
14131
|
newest = Math.max(newest, statSync10(`${streamPath}.meta.json`).mtimeMs);
|
|
@@ -14014,7 +14220,7 @@ function realDeprovisionDeps(cfg, emit, crewHome, getStore) {
|
|
|
14014
14220
|
if (host === "windows") return [];
|
|
14015
14221
|
const ctx = installContext();
|
|
14016
14222
|
const systemd = detectSystemd();
|
|
14017
|
-
return ["run", "release", "passengers"].flatMap((job) => planInstall(cfg.ship, crewHome, host, systemd, job, ctx).unitPaths).filter((p) =>
|
|
14223
|
+
return ["run", "release", "passengers"].flatMap((job) => planInstall(cfg.ship, crewHome, host, systemd, job, ctx).unitPaths).filter((p) => existsSync32(p));
|
|
14018
14224
|
};
|
|
14019
14225
|
return {
|
|
14020
14226
|
liveRuns: () => liveRuns(stateDir).map((r) => ({ role: r.role, route: r.route, pid: r.pid, ticketRecordId: r.ticketRecordId ?? void 0, streamPath: r.streamPath })),
|
|
@@ -14070,6 +14276,9 @@ function realDeprovisionDeps(cfg, emit, crewHome, getStore) {
|
|
|
14070
14276
|
},
|
|
14071
14277
|
forgeHosts,
|
|
14072
14278
|
eraseForgeToken: (host) => eraseForgeToken(cfg.ship.forges, host, stateDir),
|
|
14279
|
+
eraseRepositoryEnv: () => {
|
|
14280
|
+
eraseRepositoryEnv(stateDir);
|
|
14281
|
+
},
|
|
14073
14282
|
labeled: labeledDocker,
|
|
14074
14283
|
removeVolume: (name) => {
|
|
14075
14284
|
docker(["volume", "rm", "-f", name]);
|
|
@@ -14079,8 +14288,9 @@ function realDeprovisionDeps(cfg, emit, crewHome, getStore) {
|
|
|
14079
14288
|
},
|
|
14080
14289
|
remaining() {
|
|
14081
14290
|
const left = [];
|
|
14082
|
-
if (
|
|
14291
|
+
if (existsSync32(cfg.configFile)) left.push(`config ${cfg.configFile}`);
|
|
14083
14292
|
for (const h of forgeHosts()) if (hasForgeToken(cfg.ship.forges, h, stateDir)) left.push(`forge token for ${h}`);
|
|
14293
|
+
if (hasRepositoryEnv(stateDir)) left.push("repository environment");
|
|
14084
14294
|
try {
|
|
14085
14295
|
for (const k of readdirSync12(keysDir(stateDir))) left.push(`seat key ${k}`);
|
|
14086
14296
|
} catch {
|
|
@@ -14903,9 +15113,9 @@ function managedGitIdentityWarnings(kind, identity) {
|
|
|
14903
15113
|
|
|
14904
15114
|
// src/selftest.ts
|
|
14905
15115
|
import { spawn as spawn7 } from "child_process";
|
|
14906
|
-
import { existsSync as
|
|
15116
|
+
import { existsSync as existsSync33, mkdirSync as mkdirSync22, mkdtempSync as mkdtempSync2, readFileSync as readFileSync32, rmSync as rmSync17, writeFileSync as writeFileSync23 } from "fs";
|
|
14907
15117
|
import { tmpdir as tmpdir5 } from "os";
|
|
14908
|
-
import { join as
|
|
15118
|
+
import { join as join35 } from "path";
|
|
14909
15119
|
var SELFTEST_TIMEOUT_MS = 12e4;
|
|
14910
15120
|
var KEY_VAR = "CREW_API_KEY";
|
|
14911
15121
|
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: ";
|
|
@@ -15071,7 +15281,7 @@ async function runSelftest(i, deps = realDeps) {
|
|
|
15071
15281
|
...adapter.runEnv(spec),
|
|
15072
15282
|
[KEY_VAR]: i.apiKey
|
|
15073
15283
|
};
|
|
15074
|
-
const cwd = mkdtempSync2(
|
|
15284
|
+
const cwd = mkdtempSync2(join35(tmpdir5(), "crew-selftest-"));
|
|
15075
15285
|
try {
|
|
15076
15286
|
const run4 = await deps.run({
|
|
15077
15287
|
bin: invocation.bin,
|
|
@@ -15093,7 +15303,7 @@ async function runSelftest(i, deps = realDeps) {
|
|
|
15093
15303
|
return finish({ ok: false, failure, detail, ...usage2 });
|
|
15094
15304
|
} finally {
|
|
15095
15305
|
try {
|
|
15096
|
-
|
|
15306
|
+
rmSync17(cwd, { recursive: true, force: true });
|
|
15097
15307
|
} catch {
|
|
15098
15308
|
}
|
|
15099
15309
|
}
|
|
@@ -15104,11 +15314,11 @@ function formatResult(r) {
|
|
|
15104
15314
|
const secs = `${(r.ms / 1e3).toFixed(1)}s`;
|
|
15105
15315
|
return r.ok ? `${r.toolchain}: PASS ${r.detail} (${secs}${tok})` : `${r.toolchain}: FAIL ${r.failure} \u2014 ${r.detail} (${secs})`;
|
|
15106
15316
|
}
|
|
15107
|
-
var fileFor2 = (stateDir) =>
|
|
15317
|
+
var fileFor2 = (stateDir) => join35(stateDir, "selftest.json");
|
|
15108
15318
|
function readSelftest(stateDir) {
|
|
15109
15319
|
try {
|
|
15110
15320
|
const p = fileFor2(stateDir);
|
|
15111
|
-
return
|
|
15321
|
+
return existsSync33(p) ? JSON.parse(readFileSync32(p, "utf8")) : {};
|
|
15112
15322
|
} catch {
|
|
15113
15323
|
return {};
|
|
15114
15324
|
}
|
|
@@ -15116,8 +15326,8 @@ function readSelftest(stateDir) {
|
|
|
15116
15326
|
function recordSelftest(stateDir, results) {
|
|
15117
15327
|
const all = readSelftest(stateDir);
|
|
15118
15328
|
for (const r of results) all[r.toolchain] = r;
|
|
15119
|
-
|
|
15120
|
-
|
|
15329
|
+
mkdirSync22(stateDir, { recursive: true });
|
|
15330
|
+
writeFileSync23(fileFor2(stateDir), `${JSON.stringify(all, null, 2)}
|
|
15121
15331
|
`);
|
|
15122
15332
|
}
|
|
15123
15333
|
function doctorSelftestLines(stored, toolchains) {
|
|
@@ -15129,7 +15339,7 @@ function doctorSelftestLines(stored, toolchains) {
|
|
|
15129
15339
|
}
|
|
15130
15340
|
|
|
15131
15341
|
// src/cli.ts
|
|
15132
|
-
import { resolve as resolve7, dirname as
|
|
15342
|
+
import { resolve as resolve7, dirname as dirname37, join as join60, basename as basename16 } from "path";
|
|
15133
15343
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
15134
15344
|
import { hostname as hostname5, homedir as homedir11, userInfo as userInfo2 } from "os";
|
|
15135
15345
|
import { spawnSync as spawnSync13 } from "child_process";
|
|
@@ -15328,14 +15538,14 @@ function rosterMarkdown(roster, meId) {
|
|
|
15328
15538
|
}
|
|
15329
15539
|
|
|
15330
15540
|
// src/connect-resume.ts
|
|
15331
|
-
import { mkdirSync as
|
|
15332
|
-
import { dirname as
|
|
15541
|
+
import { mkdirSync as mkdirSync23, readFileSync as readFileSync33, rmSync as rmSync18, writeFileSync as writeFileSync24 } from "fs";
|
|
15542
|
+
import { dirname as dirname17, join as join36 } from "path";
|
|
15333
15543
|
function lastSessionFile(stateDir) {
|
|
15334
|
-
return
|
|
15544
|
+
return join36(stateDir, "connect-session.json");
|
|
15335
15545
|
}
|
|
15336
15546
|
function readPointers(stateDir) {
|
|
15337
15547
|
try {
|
|
15338
|
-
const parsed = JSON.parse(
|
|
15548
|
+
const parsed = JSON.parse(readFileSync33(lastSessionFile(stateDir), "utf8"));
|
|
15339
15549
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return {};
|
|
15340
15550
|
const out = {};
|
|
15341
15551
|
for (const [host, v] of Object.entries(parsed)) {
|
|
@@ -15349,8 +15559,8 @@ function readPointers(stateDir) {
|
|
|
15349
15559
|
}
|
|
15350
15560
|
function writePointers(stateDir, pointers) {
|
|
15351
15561
|
const file = lastSessionFile(stateDir);
|
|
15352
|
-
|
|
15353
|
-
|
|
15562
|
+
mkdirSync23(dirname17(file), { recursive: true });
|
|
15563
|
+
writeFileSync24(file, `${JSON.stringify(pointers, null, 2)}
|
|
15354
15564
|
`, { mode: 384 });
|
|
15355
15565
|
}
|
|
15356
15566
|
function rememberSession(stateDir, host, workspaceSlug) {
|
|
@@ -15367,7 +15577,7 @@ function forgetWorkspace(stateDir, host, workspaceSlug) {
|
|
|
15367
15577
|
const { [host]: _old, ...rest } = all;
|
|
15368
15578
|
const next = left.length ? { ...rest, [host]: left } : rest;
|
|
15369
15579
|
if (Object.keys(next).length) writePointers(stateDir, next);
|
|
15370
|
-
else
|
|
15580
|
+
else rmSync18(lastSessionFile(stateDir), { force: true });
|
|
15371
15581
|
} catch {
|
|
15372
15582
|
}
|
|
15373
15583
|
}
|
|
@@ -15407,7 +15617,7 @@ function forgetSession(stateDir, host) {
|
|
|
15407
15617
|
try {
|
|
15408
15618
|
const { [host]: _gone, ...rest } = readPointers(stateDir);
|
|
15409
15619
|
if (Object.keys(rest).length) writePointers(stateDir, rest);
|
|
15410
|
-
else
|
|
15620
|
+
else rmSync18(lastSessionFile(stateDir), { force: true });
|
|
15411
15621
|
} catch {
|
|
15412
15622
|
}
|
|
15413
15623
|
}
|
|
@@ -15435,15 +15645,15 @@ async function signOutSessions(o) {
|
|
|
15435
15645
|
}
|
|
15436
15646
|
|
|
15437
15647
|
// src/reset.ts
|
|
15438
|
-
import { existsSync as
|
|
15439
|
-
import { dirname as
|
|
15648
|
+
import { existsSync as existsSync34, mkdirSync as mkdirSync24, readFileSync as readFileSync34, readdirSync as readdirSync13, rmSync as rmSync19, statSync as statSync11, writeFileSync as writeFileSync25 } from "fs";
|
|
15649
|
+
import { dirname as dirname18, join as join37 } from "path";
|
|
15440
15650
|
import { hostFromUrl as hostFromUrl3 } from "@tablation/client";
|
|
15441
15651
|
function clonedCheckoutsFile(stateDir) {
|
|
15442
|
-
return
|
|
15652
|
+
return join37(stateDir, "cloned-checkouts.json");
|
|
15443
15653
|
}
|
|
15444
15654
|
function readClonedCheckouts(stateDir) {
|
|
15445
15655
|
try {
|
|
15446
|
-
const parsed = JSON.parse(
|
|
15656
|
+
const parsed = JSON.parse(readFileSync34(clonedCheckoutsFile(stateDir), "utf8"));
|
|
15447
15657
|
return Array.isArray(parsed) ? parsed.filter((d) => typeof d === "string") : [];
|
|
15448
15658
|
} catch {
|
|
15449
15659
|
return [];
|
|
@@ -15453,8 +15663,8 @@ function recordClonedCheckout(stateDir, dir) {
|
|
|
15453
15663
|
const known = readClonedCheckouts(stateDir);
|
|
15454
15664
|
if (known.includes(dir)) return;
|
|
15455
15665
|
const file = clonedCheckoutsFile(stateDir);
|
|
15456
|
-
|
|
15457
|
-
|
|
15666
|
+
mkdirSync24(dirname18(file), { recursive: true });
|
|
15667
|
+
writeFileSync25(file, `${JSON.stringify([...known, dir], null, 2)}
|
|
15458
15668
|
`);
|
|
15459
15669
|
}
|
|
15460
15670
|
var mark = (dryRun) => dryRun ? "would-remove" : "removed";
|
|
@@ -15508,8 +15718,8 @@ async function runReset(o, fx) {
|
|
|
15508
15718
|
}
|
|
15509
15719
|
if (o.beforeState) steps.push(...await o.beforeState());
|
|
15510
15720
|
steps.push(...o.wipeState ? wipeStateDir(o.stateDir, o.dryRun) : removeState(o.stateDir, o.dryRun));
|
|
15511
|
-
if (
|
|
15512
|
-
if (!o.dryRun)
|
|
15721
|
+
if (existsSync34(o.configFile)) {
|
|
15722
|
+
if (!o.dryRun) rmSync19(o.configFile, { force: true });
|
|
15513
15723
|
steps.push({ step: "config", target: o.configFile, action: mark(o.dryRun) });
|
|
15514
15724
|
} else {
|
|
15515
15725
|
steps.push({ step: "config", target: o.configFile, action: "absent" });
|
|
@@ -15517,7 +15727,7 @@ async function runReset(o, fx) {
|
|
|
15517
15727
|
return steps;
|
|
15518
15728
|
}
|
|
15519
15729
|
function removeCheckout(dir, dryRun, fx) {
|
|
15520
|
-
if (!
|
|
15730
|
+
if (!existsSync34(dir)) return { step: "checkout", target: dir, action: "absent", detail: "already gone" };
|
|
15521
15731
|
const { dirty, linkedWorktrees } = fx.inspectCheckout(dir);
|
|
15522
15732
|
if (dirty.length) {
|
|
15523
15733
|
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" : ""})` };
|
|
@@ -15525,21 +15735,21 @@ function removeCheckout(dir, dryRun, fx) {
|
|
|
15525
15735
|
if (linkedWorktrees.length) {
|
|
15526
15736
|
return { step: "checkout", target: dir, action: "kept", detail: `has linked worktrees (${linkedWorktrees.join(", ")}); remove them first` };
|
|
15527
15737
|
}
|
|
15528
|
-
if (!dryRun)
|
|
15738
|
+
if (!dryRun) rmSync19(dir, { recursive: true, force: true });
|
|
15529
15739
|
return { step: "checkout", target: dir, action: mark(dryRun) };
|
|
15530
15740
|
}
|
|
15531
15741
|
function removeState(stateDir, dryRun) {
|
|
15532
15742
|
const out = [];
|
|
15533
|
-
const targets = [
|
|
15743
|
+
const targets = [join37(stateDir, "resolved"), join37(stateDir, "keys"), clonedCheckoutsFile(stateDir), join37(stateDir, "connect-session.json"), join37(stateDir, "reload-requested"), join37(stateDir, "daemon.started")];
|
|
15534
15744
|
try {
|
|
15535
15745
|
for (const name of readdirSync13(stateDir)) {
|
|
15536
|
-
if (name.startsWith(".") && statSync11(
|
|
15746
|
+
if (name.startsWith(".") && statSync11(join37(stateDir, name)).isFile()) targets.push(join37(stateDir, name));
|
|
15537
15747
|
}
|
|
15538
15748
|
} catch {
|
|
15539
15749
|
}
|
|
15540
15750
|
for (const t of targets) {
|
|
15541
|
-
if (!
|
|
15542
|
-
if (!dryRun)
|
|
15751
|
+
if (!existsSync34(t)) continue;
|
|
15752
|
+
if (!dryRun) rmSync19(t, { recursive: true, force: true });
|
|
15543
15753
|
out.push({ step: "state", target: t, action: mark(dryRun) });
|
|
15544
15754
|
}
|
|
15545
15755
|
if (!out.length) out.push({ step: "state", target: stateDir, action: "absent", detail: "nothing to remove" });
|
|
@@ -15553,7 +15763,7 @@ function wipeStateDir(stateDir, dryRun) {
|
|
|
15553
15763
|
return [{ step: "state", target: stateDir, action: "absent", detail: "no state directory" }];
|
|
15554
15764
|
}
|
|
15555
15765
|
if (!names.length) return [{ step: "state", target: stateDir, action: "absent", detail: "already empty" }];
|
|
15556
|
-
if (!dryRun) for (const n of names)
|
|
15766
|
+
if (!dryRun) for (const n of names) rmSync19(join37(stateDir, n), { recursive: true, force: true });
|
|
15557
15767
|
return [{ step: "state", target: stateDir, action: mark(dryRun), detail: `${names.length} entr${names.length === 1 ? "y" : "ies"}` }];
|
|
15558
15768
|
}
|
|
15559
15769
|
function describeResetStep(s) {
|
|
@@ -15619,6 +15829,7 @@ async function runDeprovision(o, fx, deps) {
|
|
|
15619
15829
|
steps2.push({ step: "forge", target: host, action: "failed", detail: e.message });
|
|
15620
15830
|
}
|
|
15621
15831
|
}
|
|
15832
|
+
if (!o.dryRun) deps.eraseRepositoryEnv?.();
|
|
15622
15833
|
const { volumes, images } = deps.labeled();
|
|
15623
15834
|
for (const v of volumes) steps2.push(attempt("cache", `volume ${v}`, () => {
|
|
15624
15835
|
deps.removeVolume(v);
|
|
@@ -15634,9 +15845,9 @@ async function runDeprovision(o, fx, deps) {
|
|
|
15634
15845
|
}
|
|
15635
15846
|
|
|
15636
15847
|
// src/pool-member.ts
|
|
15637
|
-
import { mkdirSync as
|
|
15848
|
+
import { mkdirSync as mkdirSync25, readFileSync as readFileSync35, renameSync as renameSync5, writeFileSync as writeFileSync26 } from "fs";
|
|
15638
15849
|
import { homedir as homedir8 } from "os";
|
|
15639
|
-
import { dirname as
|
|
15850
|
+
import { dirname as dirname19, join as join38 } from "path";
|
|
15640
15851
|
var POOL_EXIT = { ok: 0, failed: 1, credential: 2 };
|
|
15641
15852
|
function backoffMs(attempt) {
|
|
15642
15853
|
return Math.min(6e4, 5e3 * 2 ** Math.max(0, attempt));
|
|
@@ -15842,6 +16053,13 @@ async function runPoolMember(deps) {
|
|
|
15842
16053
|
deps.log(`tokens: ${applied.reason ?? "could not apply the delivered forge tokens"}`);
|
|
15843
16054
|
continue;
|
|
15844
16055
|
}
|
|
16056
|
+
if (Array.isArray(body.repositoryEnv) && deps.applyRepositoryEnv) {
|
|
16057
|
+
const env = await deps.applyRepositoryEnv(body.repositoryEnv);
|
|
16058
|
+
if (!env.ok) {
|
|
16059
|
+
deps.log(`tokens: ${env.reason ?? "could not apply the delivered repository environment"}`);
|
|
16060
|
+
continue;
|
|
16061
|
+
}
|
|
16062
|
+
}
|
|
15845
16063
|
deps.log(`tokens: replaced the forge tokens (${(body.forges ?? []).length} host${(body.forges ?? []).length === 1 ? "" : "s"})`);
|
|
15846
16064
|
const r2 = await report("running", { leaseId: current });
|
|
15847
16065
|
if (r2 === "credential") return POOL_EXIT.credential;
|
|
@@ -15859,6 +16077,10 @@ async function runPoolMember(deps) {
|
|
|
15859
16077
|
if (r === "stopped") return POOL_EXIT.ok;
|
|
15860
16078
|
const done = await deps.provision(lease, platform2.instanceClassKey, platform2.shipKind ?? "pooled_instance");
|
|
15861
16079
|
if (!done.ok) return fail2(lease.id, done.reason ?? "provisioning failed");
|
|
16080
|
+
if (deps.applyRepositoryEnv) {
|
|
16081
|
+
const env = await deps.applyRepositoryEnv(lease.repositoryEnv ?? []);
|
|
16082
|
+
if (!env.ok) return fail2(lease.id, env.reason ?? "could not store the repository environment");
|
|
16083
|
+
}
|
|
15862
16084
|
r = await report("running", { leaseId: lease.id });
|
|
15863
16085
|
if (r === "credential") return POOL_EXIT.credential;
|
|
15864
16086
|
current = lease.id;
|
|
@@ -15867,24 +16089,24 @@ async function runPoolMember(deps) {
|
|
|
15867
16089
|
}
|
|
15868
16090
|
}
|
|
15869
16091
|
function defaultMemberDir(env = process.env) {
|
|
15870
|
-
return env.CREW_POOL_DIR ??
|
|
16092
|
+
return env.CREW_POOL_DIR ?? join38(env.XDG_STATE_HOME ?? join38(homedir8(), ".local", "state"), "crew-pool-member");
|
|
15871
16093
|
}
|
|
15872
16094
|
function fileMemberStore(dir) {
|
|
15873
|
-
const file =
|
|
16095
|
+
const file = join38(dir, "member.json");
|
|
15874
16096
|
return {
|
|
15875
16097
|
read() {
|
|
15876
16098
|
try {
|
|
15877
|
-
return JSON.parse(
|
|
16099
|
+
return JSON.parse(readFileSync35(file, "utf8"));
|
|
15878
16100
|
} catch {
|
|
15879
16101
|
return {};
|
|
15880
16102
|
}
|
|
15881
16103
|
},
|
|
15882
16104
|
write(f) {
|
|
15883
|
-
|
|
16105
|
+
mkdirSync25(dirname19(file), { recursive: true, mode: 448 });
|
|
15884
16106
|
const tmp = `${file}.tmp`;
|
|
15885
|
-
|
|
16107
|
+
writeFileSync26(tmp, `${JSON.stringify(f)}
|
|
15886
16108
|
`, { mode: 384 });
|
|
15887
|
-
|
|
16109
|
+
renameSync5(tmp, file);
|
|
15888
16110
|
}
|
|
15889
16111
|
};
|
|
15890
16112
|
}
|
|
@@ -15934,16 +16156,16 @@ function hostArchitecture(arch = process.arch) {
|
|
|
15934
16156
|
|
|
15935
16157
|
// src/pool-member-host.ts
|
|
15936
16158
|
import "child_process";
|
|
15937
|
-
import { existsSync as
|
|
16159
|
+
import { existsSync as existsSync37 } from "fs";
|
|
15938
16160
|
import { hostname as hostname3 } from "os";
|
|
15939
16161
|
|
|
15940
16162
|
// src/machine-id.ts
|
|
15941
16163
|
import { execFileSync as execFileSync12 } from "child_process";
|
|
15942
16164
|
import { createHash as createHash8 } from "crypto";
|
|
15943
|
-
import { existsSync as
|
|
15944
|
-
import { dirname as
|
|
16165
|
+
import { existsSync as existsSync35, mkdirSync as mkdirSync26, readFileSync as readFileSync36, writeFileSync as writeFileSync27 } from "fs";
|
|
16166
|
+
import { dirname as dirname20, join as join39 } from "path";
|
|
15945
16167
|
function machineIdPathFor(stateDir) {
|
|
15946
|
-
return
|
|
16168
|
+
return join39(stateDir, "machine-id");
|
|
15947
16169
|
}
|
|
15948
16170
|
var sha256 = (s) => createHash8("sha256").update(s).digest("hex");
|
|
15949
16171
|
function readRawMachineId(platform2 = process.platform) {
|
|
@@ -15956,8 +16178,8 @@ function readRawMachineId(platform2 = process.platform) {
|
|
|
15956
16178
|
return /"IOPlatformUUID"\s*=\s*"([^"]+)"/.exec(out)?.[1];
|
|
15957
16179
|
}
|
|
15958
16180
|
for (const p of ["/etc/machine-id", "/var/lib/dbus/machine-id"]) {
|
|
15959
|
-
if (
|
|
15960
|
-
const id =
|
|
16181
|
+
if (existsSync35(p)) {
|
|
16182
|
+
const id = readFileSync36(p, "utf8").trim();
|
|
15961
16183
|
if (id) return id;
|
|
15962
16184
|
}
|
|
15963
16185
|
}
|
|
@@ -15968,15 +16190,15 @@ function readRawMachineId(platform2 = process.platform) {
|
|
|
15968
16190
|
function ensureMachineId(stateDir, opts = {}) {
|
|
15969
16191
|
if (opts.override?.trim()) return sha256(opts.override.trim());
|
|
15970
16192
|
const path = machineIdPathFor(stateDir);
|
|
15971
|
-
if (
|
|
15972
|
-
const cached =
|
|
16193
|
+
if (existsSync35(path)) {
|
|
16194
|
+
const cached = readFileSync36(path, "utf8").trim();
|
|
15973
16195
|
if (/^[0-9a-f]{64}$/.test(cached)) return cached;
|
|
15974
16196
|
}
|
|
15975
16197
|
const raw = (opts.read ?? readRawMachineId)();
|
|
15976
16198
|
if (!raw) return void 0;
|
|
15977
16199
|
const hashed = sha256(raw);
|
|
15978
|
-
|
|
15979
|
-
|
|
16200
|
+
mkdirSync26(dirname20(path), { recursive: true });
|
|
16201
|
+
writeFileSync27(path, `${hashed}
|
|
15980
16202
|
`, { mode: 384 });
|
|
15981
16203
|
return hashed;
|
|
15982
16204
|
}
|
|
@@ -15989,7 +16211,7 @@ function matchShipRows(ships, shipName2, machineId) {
|
|
|
15989
16211
|
|
|
15990
16212
|
// src/provision.ts
|
|
15991
16213
|
import { spawnSync as spawnSync9 } from "child_process";
|
|
15992
|
-
import { existsSync as
|
|
16214
|
+
import { existsSync as existsSync36, readFileSync as readFileSync37, writeFileSync as writeFileSync28 } from "fs";
|
|
15993
16215
|
import { hostname as hostname2 } from "os";
|
|
15994
16216
|
import { parseDocument as parseDocument3, isMap as isMap2, isScalar } from "yaml";
|
|
15995
16217
|
|
|
@@ -15998,11 +16220,11 @@ import { parseDocument as parseDocument2 } from "yaml";
|
|
|
15998
16220
|
|
|
15999
16221
|
// src/repos-cmd.ts
|
|
16000
16222
|
import { homedir as homedir9 } from "os";
|
|
16001
|
-
import { basename as basename10, join as
|
|
16223
|
+
import { basename as basename10, join as join40, resolve as resolve4 } from "path";
|
|
16002
16224
|
import { isMap, isSeq, parseDocument, stringify as stringify2 } from "yaml";
|
|
16003
16225
|
var ReposError = class extends Error {
|
|
16004
16226
|
};
|
|
16005
|
-
function
|
|
16227
|
+
function normalizeRemote2(url) {
|
|
16006
16228
|
if (!url) return void 0;
|
|
16007
16229
|
let s = url.trim();
|
|
16008
16230
|
if (!s) return void 0;
|
|
@@ -16015,10 +16237,10 @@ function normalizeRemote(url) {
|
|
|
16015
16237
|
return parts.slice(-2).join("/").toLowerCase();
|
|
16016
16238
|
}
|
|
16017
16239
|
function matchRepoName(origin, resolved) {
|
|
16018
|
-
const want =
|
|
16240
|
+
const want = normalizeRemote2(origin);
|
|
16019
16241
|
if (!want || !resolved?.repoRemotes) return void 0;
|
|
16020
16242
|
for (const [id, remote] of Object.entries(resolved.repoRemotes)) {
|
|
16021
|
-
if (
|
|
16243
|
+
if (normalizeRemote2(remote) === want) return resolved.repoNames?.[id];
|
|
16022
16244
|
}
|
|
16023
16245
|
return void 0;
|
|
16024
16246
|
}
|
|
@@ -16098,15 +16320,15 @@ function listRepoRows(i) {
|
|
|
16098
16320
|
const originFor = (c, remote) => {
|
|
16099
16321
|
const o = i.originOf(c.dir) ?? null;
|
|
16100
16322
|
if (!o) return null;
|
|
16101
|
-
return remote !== null &&
|
|
16323
|
+
return remote !== null && normalizeRemote2(o) === normalizeRemote2(remote) ? null : o;
|
|
16102
16324
|
};
|
|
16103
16325
|
const rows = [];
|
|
16104
16326
|
const names = i.resolved?.repoNames ?? {};
|
|
16105
16327
|
const remotes = i.resolved?.repoRemotes ?? {};
|
|
16106
16328
|
for (const [id, name] of Object.entries(names)) {
|
|
16107
16329
|
const remote = remotes[id] ?? null;
|
|
16108
|
-
const want =
|
|
16109
|
-
let idx = checkouts.findIndex((c2, n) => !claimed.has(n) && want !== void 0 &&
|
|
16330
|
+
const want = normalizeRemote2(remote);
|
|
16331
|
+
let idx = checkouts.findIndex((c2, n) => !claimed.has(n) && want !== void 0 && normalizeRemote2(i.originOf(c2.dir)) === want);
|
|
16110
16332
|
if (idx < 0) idx = checkouts.findIndex((c2, n) => !claimed.has(n) && c2.name === name);
|
|
16111
16333
|
const c = idx >= 0 ? checkouts[idx] : void 0;
|
|
16112
16334
|
if (idx >= 0) claimed.add(idx);
|
|
@@ -16159,11 +16381,11 @@ function planRepoAdd(i) {
|
|
|
16159
16381
|
throw new ReposError(`${target} is already configured on route ${i.route}`);
|
|
16160
16382
|
}
|
|
16161
16383
|
const matched = matchRepoName(i.origin, i.resolved);
|
|
16162
|
-
const name = matched ?? i.name ??
|
|
16384
|
+
const name = matched ?? i.name ?? normalizeRemote2(i.origin)?.split("/").pop() ?? basename10(target);
|
|
16163
16385
|
let warning;
|
|
16164
16386
|
if (!matched) {
|
|
16165
16387
|
const known = Object.values(i.resolved?.repoNames ?? {});
|
|
16166
|
-
warning = i.origin ? `the tracker has no Repos row for remote ${
|
|
16388
|
+
warning = i.origin ? `the tracker has no Repos row for remote ${normalizeRemote2(i.origin) ?? i.origin}${known.length ? ` (known: ${known.join(", ")})` : ""} \u2014 added anyway; create the row so ticket routing can find it` : "this checkout has no origin remote, so it cannot be matched to a Repos row \u2014 added anyway";
|
|
16167
16389
|
}
|
|
16168
16390
|
const repos = m.get("repos", true);
|
|
16169
16391
|
let mode;
|
|
@@ -16216,7 +16438,7 @@ function renderBlock(m) {
|
|
|
16216
16438
|
}
|
|
16217
16439
|
var LOCAL_RELEASE_MODES = /* @__PURE__ */ new Set(["integrate", "external"]);
|
|
16218
16440
|
function planRepoRow(i) {
|
|
16219
|
-
const remote =
|
|
16441
|
+
const remote = normalizeRemote2(i.origin);
|
|
16220
16442
|
if (!remote) throw new ReposError(`cannot derive an owner/repo from origin "${i.origin}"`);
|
|
16221
16443
|
const mode = i.spec?.releaseMode;
|
|
16222
16444
|
return {
|
|
@@ -16262,7 +16484,7 @@ function planRepoClone(i) {
|
|
|
16262
16484
|
throw new ReposError(`the tracker has no Repos row named "${i.name}" for route ${i.route}${known.length ? ` (known: ${known.join(", ")})` : " \u2014 run `crew connect` to refresh them"}`);
|
|
16263
16485
|
}
|
|
16264
16486
|
const name = names[id];
|
|
16265
|
-
const remote =
|
|
16487
|
+
const remote = normalizeRemote2(i.resolved?.repoRemotes?.[id]);
|
|
16266
16488
|
if (!remote) {
|
|
16267
16489
|
throw new ReposError(
|
|
16268
16490
|
`the Repos row "${name}" has no remote to clone from \u2014 attach an existing checkout with \`crew repos add ${i.route} ${name} <path>\`, or set the row's remote in the tracker and re-run \`crew connect\``
|
|
@@ -16276,7 +16498,7 @@ function planRepoClone(i) {
|
|
|
16276
16498
|
}
|
|
16277
16499
|
const ship = doc.get("ship", true);
|
|
16278
16500
|
const basePath = String(m.get("reposBasePath") ?? (isMap(ship) ? ship.get("reposBasePath") : void 0) ?? "~/Crew");
|
|
16279
|
-
const target = i.dir ? expandDir(i.dir, i.base) :
|
|
16501
|
+
const target = i.dir ? expandDir(i.dir, i.base) : join40(expandDir(basePath, i.base), i.route.split("/")[0], name);
|
|
16280
16502
|
const add = planRepoAdd({ text: i.text, base: i.base, route: i.route, path: target, origin: remote, resolved: i.resolved, name, isCheckout: i.isCheckout });
|
|
16281
16503
|
const forgeHost = i.resolved?.repoForgeHosts?.[id];
|
|
16282
16504
|
return { ...add, remote, target, ...forgeHost ? { forgeHost } : {} };
|
|
@@ -16607,7 +16829,7 @@ function realProvisionDeps(crewHome) {
|
|
|
16607
16829
|
};
|
|
16608
16830
|
const configFile = () => {
|
|
16609
16831
|
const f = findConfigFile(crewHome);
|
|
16610
|
-
return
|
|
16832
|
+
return existsSync36(f) ? f : null;
|
|
16611
16833
|
};
|
|
16612
16834
|
return {
|
|
16613
16835
|
crew: spawnCrew,
|
|
@@ -16615,13 +16837,13 @@ function realProvisionDeps(crewHome) {
|
|
|
16615
16837
|
enableRoute(route2) {
|
|
16616
16838
|
const file = configFile();
|
|
16617
16839
|
if (!file) return false;
|
|
16618
|
-
const text2 =
|
|
16840
|
+
const text2 = readFileSync37(file, "utf8");
|
|
16619
16841
|
const doc = parseDocument3(text2);
|
|
16620
16842
|
const routes = doc.get("routes");
|
|
16621
16843
|
const entry = routes?.items?.find((r) => r.get("route") === route2);
|
|
16622
16844
|
if (!entry) throw new Error(`route ${route2} is not in ${file}`);
|
|
16623
16845
|
if (entry.get("enabled") === true) return false;
|
|
16624
|
-
|
|
16846
|
+
writeFileSync28(file, planEnable(text2, route2));
|
|
16625
16847
|
return true;
|
|
16626
16848
|
},
|
|
16627
16849
|
installState() {
|
|
@@ -16641,14 +16863,14 @@ function realProvisionDeps(crewHome) {
|
|
|
16641
16863
|
continue;
|
|
16642
16864
|
}
|
|
16643
16865
|
for (const p of plan.unitPaths) {
|
|
16644
|
-
if (!
|
|
16866
|
+
if (!existsSync36(p) || readFileSync37(p, "utf8") !== plan.unitContent[p]) unitsStale = true;
|
|
16645
16867
|
}
|
|
16646
16868
|
}
|
|
16647
16869
|
const label = labelFor(crewHome, "run");
|
|
16648
16870
|
let running = false;
|
|
16649
16871
|
let lingering = true;
|
|
16650
16872
|
if (mechanism === "systemd") {
|
|
16651
|
-
const system = ctx.root ||
|
|
16873
|
+
const system = ctx.root || existsSync36(systemUnitPathFor(label));
|
|
16652
16874
|
const ctl = system ? ["systemctl"] : ["systemctl", "--user"];
|
|
16653
16875
|
running = spawnSync9(ctl[0], [...ctl.slice(1), "is-active", "--quiet", `${label}.service`], { env: withUserBusEnv() }).status === 0;
|
|
16654
16876
|
if (!system) {
|
|
@@ -16665,18 +16887,18 @@ function realProvisionDeps(crewHome) {
|
|
|
16665
16887
|
setShipSetting(key, value2) {
|
|
16666
16888
|
const file = configFile();
|
|
16667
16889
|
if (!file) return false;
|
|
16668
|
-
const doc = parseDocument3(
|
|
16890
|
+
const doc = parseDocument3(readFileSync37(file, "utf8"));
|
|
16669
16891
|
if (doc.getIn(["ship", key]) === value2) return false;
|
|
16670
16892
|
doc.setIn(["ship", key], value2);
|
|
16671
|
-
|
|
16893
|
+
writeFileSync28(file, doc.toString());
|
|
16672
16894
|
return true;
|
|
16673
16895
|
},
|
|
16674
16896
|
applyManagedDefaults() {
|
|
16675
16897
|
const file = configFile();
|
|
16676
16898
|
if (!file) return [];
|
|
16677
|
-
const doc = parseDocument3(
|
|
16899
|
+
const doc = parseDocument3(readFileSync37(file, "utf8"));
|
|
16678
16900
|
const wrote = applyManagedDefaultsToDoc(doc);
|
|
16679
|
-
if (wrote.length)
|
|
16901
|
+
if (wrote.length) writeFileSync28(file, doc.toString());
|
|
16680
16902
|
return wrote;
|
|
16681
16903
|
},
|
|
16682
16904
|
ensureGitIdentity(name, email) {
|
|
@@ -16726,7 +16948,7 @@ function realPoolMemberDeps(o) {
|
|
|
16726
16948
|
crewVersion: crewVersion(o.crewHome),
|
|
16727
16949
|
hostname: hostname3()
|
|
16728
16950
|
},
|
|
16729
|
-
hasShipConfig: () =>
|
|
16951
|
+
hasShipConfig: () => existsSync37(findConfigFile(o.crewHome)),
|
|
16730
16952
|
async provision(lease, instanceClass, shipKind) {
|
|
16731
16953
|
const hosts = lease.forges.map((f) => f.host.toLowerCase());
|
|
16732
16954
|
const lines2 = [];
|
|
@@ -16775,6 +16997,16 @@ function realPoolMemberDeps(o) {
|
|
|
16775
16997
|
}
|
|
16776
16998
|
return { ok: true };
|
|
16777
16999
|
},
|
|
17000
|
+
async applyRepositoryEnv(entries) {
|
|
17001
|
+
const cfg = loadShip(o.crewHome);
|
|
17002
|
+
if (!cfg) return { ok: false, reason: "no ship config to store the repository environment under" };
|
|
17003
|
+
try {
|
|
17004
|
+
writeRepositoryEnv(cfg.ship.stateDir, entries);
|
|
17005
|
+
} catch (e) {
|
|
17006
|
+
return { ok: false, reason: `repository environment: ${e.message}` };
|
|
17007
|
+
}
|
|
17008
|
+
return { ok: true };
|
|
17009
|
+
},
|
|
16778
17010
|
async reconcile() {
|
|
16779
17011
|
const before = provisionDeps.installState();
|
|
16780
17012
|
if (before.unitsStale || !before.running || !before.lingering) {
|
|
@@ -17604,7 +17836,7 @@ ${waiting.map((t) => `| ${displayKey2(t)} | ${t.status} | ${blockers(t, i)} |`).
|
|
|
17604
17836
|
|
|
17605
17837
|
// src/sandbox-hygiene.ts
|
|
17606
17838
|
import { execFile as execFile3 } from "child_process";
|
|
17607
|
-
import { existsSync as
|
|
17839
|
+
import { existsSync as existsSync38, statfsSync as statfsSync2 } from "fs";
|
|
17608
17840
|
import { promisify as promisify3 } from "util";
|
|
17609
17841
|
var execFileP3 = promisify3(execFile3);
|
|
17610
17842
|
var REAP_MIN_AGE_MS = 5 * 6e4;
|
|
@@ -17747,7 +17979,7 @@ async function realDiskReadings(ship) {
|
|
|
17747
17979
|
const paths = ["/"];
|
|
17748
17980
|
try {
|
|
17749
17981
|
const root = (await run3(ship.sandbox?.engine ?? DEFAULT_CACHE_SETTINGS.engine, ["info", "--format", "{{.DockerRootDir}}"])).trim();
|
|
17750
|
-
if (root &&
|
|
17982
|
+
if (root && existsSync38(root)) paths.push(root);
|
|
17751
17983
|
} catch {
|
|
17752
17984
|
}
|
|
17753
17985
|
return paths.flatMap((path) => {
|
|
@@ -17788,8 +18020,8 @@ function diskFullStop(state) {
|
|
|
17788
18020
|
}
|
|
17789
18021
|
|
|
17790
18022
|
// src/poll.ts
|
|
17791
|
-
import { writeFileSync as
|
|
17792
|
-
import { join as
|
|
18023
|
+
import { writeFileSync as writeFileSync29 } from "fs";
|
|
18024
|
+
import { join as join41 } from "path";
|
|
17793
18025
|
|
|
17794
18026
|
// src/stalled.ts
|
|
17795
18027
|
var STALLED_AFTER_CYCLES = 30;
|
|
@@ -18103,7 +18335,7 @@ async function decideCycle(o) {
|
|
|
18103
18335
|
}
|
|
18104
18336
|
return decision;
|
|
18105
18337
|
}
|
|
18106
|
-
var digestPath = (stateDir, route2, role, runId) =>
|
|
18338
|
+
var digestPath = (stateDir, route2, role, runId) => join41(stateDir, `digest-${route2}-${role}${runId ? `-${runId}` : ""}.md`);
|
|
18107
18339
|
function otherRunsRemoved(tickets, own) {
|
|
18108
18340
|
if (!own) return tickets;
|
|
18109
18341
|
return tickets.filter((t) => t.id === own.ticket.id || !own.inFlight(t.id));
|
|
@@ -18187,7 +18419,7 @@ function writeDigest(o, d, role, stateDir, runId, own) {
|
|
|
18187
18419
|
|
|
18188
18420
|
${body}` : body;
|
|
18189
18421
|
const path = digestPath(stateDir, routeSlug(o.route.route), role, runId);
|
|
18190
|
-
|
|
18422
|
+
writeFileSync29(path, text2);
|
|
18191
18423
|
o.emit.emit(`queue digest written for ${role} (${Buffer.byteLength(text2)} bytes)`, {
|
|
18192
18424
|
data: { role, bytes: Buffer.byteLength(text2) }
|
|
18193
18425
|
});
|
|
@@ -18310,8 +18542,8 @@ async function claimStillHeld(tracker, t, buildingStatus, affinity) {
|
|
|
18310
18542
|
}
|
|
18311
18543
|
|
|
18312
18544
|
// src/repo-refresh.ts
|
|
18313
|
-
import { existsSync as
|
|
18314
|
-
import { dirname as
|
|
18545
|
+
import { existsSync as existsSync39, mkdirSync as mkdirSync27, readFileSync as readFileSync38, writeFileSync as writeFileSync30 } from "fs";
|
|
18546
|
+
import { dirname as dirname22 } from "path";
|
|
18315
18547
|
var REFRESH_COOLDOWN_MS = 2 * 6e4;
|
|
18316
18548
|
var UNSERVABLE_PASSES_BEFORE_ATTENTION = 3;
|
|
18317
18549
|
var lastAsked = /* @__PURE__ */ new Map();
|
|
@@ -18340,11 +18572,11 @@ function applyRepoRows(resolved, rows) {
|
|
|
18340
18572
|
}
|
|
18341
18573
|
function persistRepoRows(stateDir, routeName, rows) {
|
|
18342
18574
|
const path = resolvedPathFor(stateDir, routeName);
|
|
18343
|
-
if (!
|
|
18344
|
-
const raw = JSON.parse(
|
|
18575
|
+
if (!existsSync39(path)) return;
|
|
18576
|
+
const raw = JSON.parse(readFileSync38(path, "utf8"));
|
|
18345
18577
|
applyRepoRows(raw, rows);
|
|
18346
|
-
|
|
18347
|
-
|
|
18578
|
+
mkdirSync27(dirname22(path), { recursive: true });
|
|
18579
|
+
writeFileSync30(path, `${JSON.stringify(raw, null, 2)}
|
|
18348
18580
|
`);
|
|
18349
18581
|
}
|
|
18350
18582
|
async function refreshUnknownRepos(o) {
|
|
@@ -18794,7 +19026,7 @@ Ship ${shipName2} found: ${problem}. The release refuses to squash a ref nobody
|
|
|
18794
19026
|
var localRefSkipReported = (ticket, problem, events) => events.some((e) => e.record_id === ticket.id && e.event_type === "local_ref_skip" && (e.message ?? "").includes(problem));
|
|
18795
19027
|
|
|
18796
19028
|
// src/platform-gate.ts
|
|
18797
|
-
import { join as
|
|
19029
|
+
import { join as join42 } from "path";
|
|
18798
19030
|
function platformAdmitters(dir, baseRef, ship, tickets, locate) {
|
|
18799
19031
|
const out = [];
|
|
18800
19032
|
for (const t of tickets) {
|
|
@@ -18806,7 +19038,7 @@ function platformAdmitters(dir, baseRef, ship, tickets, locate) {
|
|
|
18806
19038
|
const text2 = gitOk(dir, ["show", `${branch}:${file}`]);
|
|
18807
19039
|
if (text2 === null) continue;
|
|
18808
19040
|
try {
|
|
18809
|
-
const { platform: platform2 } = parseRepoConfig(text2,
|
|
19041
|
+
const { platform: platform2 } = parseRepoConfig(text2, join42(dir, file));
|
|
18810
19042
|
if (satisfies(ship, platform2)) out.push({ issueId: t.issue_id, branch, platform: platform2 });
|
|
18811
19043
|
} catch (e) {
|
|
18812
19044
|
if (e instanceof RepoConfigError) continue;
|
|
@@ -18822,13 +19054,13 @@ function platformStuckNote(repo, required, ship, issueIds) {
|
|
|
18822
19054
|
}
|
|
18823
19055
|
|
|
18824
19056
|
// src/connect-wizard.ts
|
|
18825
|
-
import { delimiter, dirname as
|
|
18826
|
-
import { accessSync as accessSync3, constants as constants3, existsSync as
|
|
19057
|
+
import { delimiter, dirname as dirname23, join as join43 } from "path";
|
|
19058
|
+
import { accessSync as accessSync3, constants as constants3, existsSync as existsSync40, mkdirSync as mkdirSync28, writeFileSync as writeFileSync31 } from "fs";
|
|
18827
19059
|
import { stringify as stringify3 } from "yaml";
|
|
18828
19060
|
var HOST_PASSENGERS_DOCS_URL = "https://crew.tablation.dev/host-passengers";
|
|
18829
19061
|
function shouldRunWizard(opts) {
|
|
18830
19062
|
if (!opts.isTTY) return false;
|
|
18831
|
-
const exists = opts.configExists ??
|
|
19063
|
+
const exists = opts.configExists ?? existsSync40;
|
|
18832
19064
|
return !configSearchPath(opts.crewHome).some((p) => exists(p));
|
|
18833
19065
|
}
|
|
18834
19066
|
function firstRunConfigPath() {
|
|
@@ -18845,7 +19077,7 @@ function defaultIsExecutable(p) {
|
|
|
18845
19077
|
function findOnPath2(name, pathEnv, isExecutable = defaultIsExecutable) {
|
|
18846
19078
|
for (const dir of pathEnv.split(delimiter)) {
|
|
18847
19079
|
if (!dir) continue;
|
|
18848
|
-
const candidate =
|
|
19080
|
+
const candidate = join43(dir, name);
|
|
18849
19081
|
if (isExecutable(candidate)) return candidate;
|
|
18850
19082
|
}
|
|
18851
19083
|
return void 0;
|
|
@@ -18871,9 +19103,9 @@ async function runWizard(p, env) {
|
|
|
18871
19103
|
if (entered && isExec(entered)) agentBin = entered;
|
|
18872
19104
|
else p.say(entered ? `${entered} is not an executable file.` : "A path is required.");
|
|
18873
19105
|
}
|
|
18874
|
-
const nodeDir =
|
|
19106
|
+
const nodeDir = dirname23(env.nodePath);
|
|
18875
19107
|
const pnpmPath = findOnPath2("pnpm", env.pathEnv, isExec);
|
|
18876
|
-
const baseDirs = [nodeDir, pnpmPath ?
|
|
19108
|
+
const baseDirs = [nodeDir, pnpmPath ? dirname23(pnpmPath) : void 0];
|
|
18877
19109
|
p.say(
|
|
18878
19110
|
`
|
|
18879
19111
|
Host Passengers lets this machine run the agent sessions that other people's
|
|
@@ -18884,7 +19116,7 @@ Tablation workspaces ask for, in a container. More: ${HOST_PASSENGERS_DOCS_URL}`
|
|
|
18884
19116
|
p.say("Docker is not available here, so nothing will be hosted until it is. Your answer is recorded anyway.");
|
|
18885
19117
|
}
|
|
18886
19118
|
const dockerPath = hostPassengers ? findOnPath2("docker", env.pathEnv, isExec) : void 0;
|
|
18887
|
-
const extraPath = deriveExtraPath([...baseDirs, dockerPath ?
|
|
19119
|
+
const extraPath = deriveExtraPath([...baseDirs, dockerPath ? dirname23(dockerPath) : void 0]);
|
|
18888
19120
|
if (extraPath) {
|
|
18889
19121
|
p.say(`Hooks will get ${extraPath} on their PATH (where node, pnpm${dockerPath ? " and docker" : ""} live).`);
|
|
18890
19122
|
}
|
|
@@ -18906,9 +19138,9 @@ routes:
|
|
|
18906
19138
|
${routeBlock}`;
|
|
18907
19139
|
}
|
|
18908
19140
|
function writeNewConfig(path, text2) {
|
|
18909
|
-
|
|
19141
|
+
mkdirSync28(dirname23(path), { recursive: true });
|
|
18910
19142
|
try {
|
|
18911
|
-
|
|
19143
|
+
writeFileSync31(path, text2, { mode: 384, flag: "wx" });
|
|
18912
19144
|
return true;
|
|
18913
19145
|
} catch (e) {
|
|
18914
19146
|
if (e.code === "EEXIST") return false;
|
|
@@ -18942,7 +19174,7 @@ Wrote ${o.configPath}.
|
|
|
18942
19174
|
// src/connect-json.ts
|
|
18943
19175
|
import { accessSync as accessSync4, constants as constants4 } from "fs";
|
|
18944
19176
|
import { homedir as homedir10 } from "os";
|
|
18945
|
-
import { dirname as
|
|
19177
|
+
import { dirname as dirname24, join as join44 } from "path";
|
|
18946
19178
|
import { delimiter as delimiter2 } from "path";
|
|
18947
19179
|
var CHOICE_EXIT_CODE = 3;
|
|
18948
19180
|
function createEmitter(json2, write) {
|
|
@@ -18981,12 +19213,12 @@ function agentBinSearchDirs(home, pathEnv, extraPath) {
|
|
|
18981
19213
|
const dirs = [
|
|
18982
19214
|
...pathEnv.split(delimiter2),
|
|
18983
19215
|
...(extraPath ?? "").split(delimiter2),
|
|
18984
|
-
|
|
18985
|
-
|
|
19216
|
+
join44(home, ".local/bin"),
|
|
19217
|
+
join44(home, ".claude/local"),
|
|
18986
19218
|
"/opt/homebrew/bin",
|
|
18987
19219
|
"/usr/local/bin",
|
|
18988
|
-
|
|
18989
|
-
|
|
19220
|
+
join44(home, ".npm-global/bin"),
|
|
19221
|
+
join44(home, ".volta/bin")
|
|
18990
19222
|
];
|
|
18991
19223
|
return [...new Set(dirs.filter(Boolean))];
|
|
18992
19224
|
}
|
|
@@ -19008,7 +19240,7 @@ function flagWizardAnswers(f, env) {
|
|
|
19008
19240
|
const agentBin = f.agentBin ?? found?.bin;
|
|
19009
19241
|
const pnpmPath = findOnPath2("pnpm", env.pathEnv, isExec);
|
|
19010
19242
|
const dockerPath = f.hostPassengers ? findOnPath2("docker", env.pathEnv, isExec) : void 0;
|
|
19011
|
-
const extraPath = f.extraPath ?? deriveExtraPath([
|
|
19243
|
+
const extraPath = f.extraPath ?? deriveExtraPath([dirname24(env.nodePath), pnpmPath ? dirname24(pnpmPath) : void 0, dockerPath ? dirname24(dockerPath) : void 0]);
|
|
19012
19244
|
return {
|
|
19013
19245
|
answers: {
|
|
19014
19246
|
name: f.shipName?.trim() || env.hostname,
|
|
@@ -19107,8 +19339,8 @@ async function collectDiagnostics(d) {
|
|
|
19107
19339
|
}
|
|
19108
19340
|
|
|
19109
19341
|
// src/release-run.ts
|
|
19110
|
-
import { readFileSync as
|
|
19111
|
-
import { dirname as
|
|
19342
|
+
import { readFileSync as readFileSync39, writeFileSync as writeFileSync32, existsSync as existsSync41, copyFileSync, mkdirSync as mkdirSync29, mkdtempSync as mkdtempSync3, rmSync as rmSync20 } from "fs";
|
|
19343
|
+
import { dirname as dirname25, join as join45 } from "path";
|
|
19112
19344
|
import { tmpdir as tmpdir6, hostname as hostname4 } from "os";
|
|
19113
19345
|
|
|
19114
19346
|
// src/release.ts
|
|
@@ -19890,13 +20122,13 @@ async function bump(o, size) {
|
|
|
19890
20122
|
}
|
|
19891
20123
|
return printed;
|
|
19892
20124
|
}
|
|
19893
|
-
const files = o.repo.release.versionFiles.map((f) =>
|
|
20125
|
+
const files = o.repo.release.versionFiles.map((f) => join45(o.cwd, f));
|
|
19894
20126
|
const first = files[0];
|
|
19895
|
-
if (!existsAt(first,
|
|
20127
|
+
if (!existsAt(first, existsSync41)) {
|
|
19896
20128
|
o.emit.error(`no ${o.repo.release.versionFiles[0]} to read a version from`);
|
|
19897
20129
|
return null;
|
|
19898
20130
|
}
|
|
19899
|
-
const firstText = readTextAt(first, (p) =>
|
|
20131
|
+
const firstText = readTextAt(first, (p) => readFileSync39(p, "utf8"));
|
|
19900
20132
|
const problem = versionFileProblem(o.repo.release.versionFiles[0], firstText);
|
|
19901
20133
|
if (problem) {
|
|
19902
20134
|
o.emit.error(problem);
|
|
@@ -19915,27 +20147,27 @@ async function bump(o, size) {
|
|
|
19915
20147
|
return version;
|
|
19916
20148
|
}
|
|
19917
20149
|
for (const f of files) {
|
|
19918
|
-
const src = readTextAt(f, (p) =>
|
|
20150
|
+
const src = readTextAt(f, (p) => readFileSync39(p, "utf8"));
|
|
19919
20151
|
const out = src.replace(/("version"\s*:\s*")[^"]*(")/, `$1${version}$2`);
|
|
19920
20152
|
if (out === src) {
|
|
19921
20153
|
o.emit.error(`no version field in ${f}`);
|
|
19922
20154
|
return null;
|
|
19923
20155
|
}
|
|
19924
|
-
writeTextAt(f, out,
|
|
20156
|
+
writeTextAt(f, out, writeFileSync32);
|
|
19925
20157
|
}
|
|
19926
20158
|
return version;
|
|
19927
20159
|
}
|
|
19928
20160
|
function writeChangelog(o, version, entries) {
|
|
19929
20161
|
const file = o.repo.release.changelog;
|
|
19930
20162
|
if (!file || entries.length === 0) return;
|
|
19931
|
-
const path =
|
|
20163
|
+
const path = join45(o.cwd, file);
|
|
19932
20164
|
const section = renderChangelogSection(version, (/* @__PURE__ */ new Date()).toISOString().slice(0, 10), entries);
|
|
19933
20165
|
if (o.dryRun) {
|
|
19934
20166
|
o.emit.emit(`would prepend ${entries.length} entr(ies) to ${file}`);
|
|
19935
20167
|
return;
|
|
19936
20168
|
}
|
|
19937
|
-
const existing = existsAt(path,
|
|
19938
|
-
writeTextAt(path, insertChangelogSection(existing, section),
|
|
20169
|
+
const existing = existsAt(path, existsSync41) ? readTextAt(path, (p) => readFileSync39(p, "utf8")) : "# Changelog\n";
|
|
20170
|
+
writeTextAt(path, insertChangelogSection(existing, section), writeFileSync32);
|
|
19939
20171
|
}
|
|
19940
20172
|
async function confirm(o, expected) {
|
|
19941
20173
|
if (!o.repo.hooks.released) return void 0;
|
|
@@ -20018,7 +20250,7 @@ function closeReleaseCheckout(cwd, root, dir, branch, run4 = gitOk) {
|
|
|
20018
20250
|
run4(cwd, ["worktree", "remove", "--force", dir]);
|
|
20019
20251
|
} finally {
|
|
20020
20252
|
try {
|
|
20021
|
-
|
|
20253
|
+
rmSync20(root, { recursive: true, force: true });
|
|
20022
20254
|
} finally {
|
|
20023
20255
|
run4(cwd, ["worktree", "prune"]);
|
|
20024
20256
|
run4(cwd, ["branch", "-D", branch]);
|
|
@@ -20028,8 +20260,8 @@ function closeReleaseCheckout(cwd, root, dir, branch, run4 = gitOk) {
|
|
|
20028
20260
|
function openReleaseCheckout(o) {
|
|
20029
20261
|
const { remote, base } = o.repo.branch;
|
|
20030
20262
|
const branch = `crew/release-${Date.now()}`;
|
|
20031
|
-
const root = mkdtempSync3(
|
|
20032
|
-
const dir =
|
|
20263
|
+
const root = mkdtempSync3(join45(tmpdir6(), "crew-release-"));
|
|
20264
|
+
const dir = join45(root, "checkout");
|
|
20033
20265
|
o.emit.emit(`release checkout: ${dir}`, { step: "release" });
|
|
20034
20266
|
const close = () => closeReleaseCheckout(o.cwd, root, dir, branch);
|
|
20035
20267
|
try {
|
|
@@ -20039,10 +20271,10 @@ function openReleaseCheckout(o) {
|
|
|
20039
20271
|
throw e;
|
|
20040
20272
|
}
|
|
20041
20273
|
for (const f of o.repo.worktrees.copy) {
|
|
20042
|
-
const src =
|
|
20043
|
-
if (!
|
|
20044
|
-
|
|
20045
|
-
copyFileSync(src,
|
|
20274
|
+
const src = join45(o.cwd, f);
|
|
20275
|
+
if (!existsSync41(src)) continue;
|
|
20276
|
+
mkdirSync29(dirname25(join45(dir, f)), { recursive: true });
|
|
20277
|
+
copyFileSync(src, join45(dir, f));
|
|
20046
20278
|
}
|
|
20047
20279
|
return { dir, branch, close };
|
|
20048
20280
|
}
|
|
@@ -20768,11 +21000,11 @@ Passed: ${passed}.${willClose ? " Closing this alert." : ""}`,
|
|
|
20768
21000
|
}
|
|
20769
21001
|
|
|
20770
21002
|
// src/daemon-liveness.ts
|
|
20771
|
-
import { existsSync as
|
|
21003
|
+
import { existsSync as existsSync48, readFileSync as readFileSync45 } from "fs";
|
|
20772
21004
|
|
|
20773
21005
|
// src/daemon.ts
|
|
20774
|
-
import { existsSync as
|
|
20775
|
-
import { join as
|
|
21006
|
+
import { existsSync as existsSync47, mkdirSync as mkdirSync35, readFileSync as readFileSync44, readdirSync as readdirSync14, rmSync as rmSync22, statSync as statSync13, writeFileSync as writeFileSync36 } from "fs";
|
|
21007
|
+
import { join as join50 } from "path";
|
|
20776
21008
|
import { randomBytes } from "crypto";
|
|
20777
21009
|
|
|
20778
21010
|
// src/fleet.ts
|
|
@@ -20862,27 +21094,27 @@ function nextRoles(decision, ran) {
|
|
|
20862
21094
|
}
|
|
20863
21095
|
|
|
20864
21096
|
// src/noop-runs.ts
|
|
20865
|
-
import { existsSync as
|
|
20866
|
-
import { join as
|
|
21097
|
+
import { existsSync as existsSync42, mkdirSync as mkdirSync30, readFileSync as readFileSync40, renameSync as renameSync6, writeFileSync as writeFileSync33 } from "fs";
|
|
21098
|
+
import { join as join46 } from "path";
|
|
20867
21099
|
var NOOP_DELAYS_MS = [5, 15, 60].map((m) => m * 6e4);
|
|
20868
21100
|
var DEFAULT_NOOP_REPEATS = 3;
|
|
20869
21101
|
var NOOP_BOUNCED_MARKER = calloutHeader("WARNING", "Runs Changed Nothing");
|
|
20870
|
-
var noopRunsPath = (stateDir) =>
|
|
21102
|
+
var noopRunsPath = (stateDir) => join46(stateDir, "noop-runs.json");
|
|
20871
21103
|
var noopRunsKey = (issueId) => `noop_runs:${issueId}`;
|
|
20872
21104
|
function readNoopRuns(stateDir) {
|
|
20873
21105
|
try {
|
|
20874
|
-
const v = JSON.parse(
|
|
21106
|
+
const v = JSON.parse(readFileSync40(noopRunsPath(stateDir), "utf8"));
|
|
20875
21107
|
return v && typeof v === "object" && !Array.isArray(v) ? v : {};
|
|
20876
21108
|
} catch {
|
|
20877
21109
|
return {};
|
|
20878
21110
|
}
|
|
20879
21111
|
}
|
|
20880
21112
|
function writeNoopRuns(stateDir, state) {
|
|
20881
|
-
|
|
21113
|
+
mkdirSync30(stateDir, { recursive: true });
|
|
20882
21114
|
const file = noopRunsPath(stateDir);
|
|
20883
|
-
|
|
21115
|
+
writeFileSync33(`${file}.tmp`, `${JSON.stringify(state, null, 2)}
|
|
20884
21116
|
`);
|
|
20885
|
-
|
|
21117
|
+
renameSync6(`${file}.tmp`, file);
|
|
20886
21118
|
}
|
|
20887
21119
|
function noopBackedOff(stateDir, recordId, now = Date.now()) {
|
|
20888
21120
|
const e = readNoopRuns(stateDir)[recordId];
|
|
@@ -20897,7 +21129,7 @@ function recordNoopRun(stateDir, recordId, repeats, now = Date.now()) {
|
|
|
20897
21129
|
return { count, nextAt, bounce: count >= repeats };
|
|
20898
21130
|
}
|
|
20899
21131
|
function clearNoopRuns(stateDir, recordId) {
|
|
20900
|
-
if (!
|
|
21132
|
+
if (!existsSync42(noopRunsPath(stateDir))) return;
|
|
20901
21133
|
const state = readNoopRuns(stateDir);
|
|
20902
21134
|
if (!(recordId in state)) return;
|
|
20903
21135
|
delete state[recordId];
|
|
@@ -20957,8 +21189,8 @@ async function settleNoopRun(o) {
|
|
|
20957
21189
|
}
|
|
20958
21190
|
|
|
20959
21191
|
// src/ship-name.ts
|
|
20960
|
-
import { existsSync as
|
|
20961
|
-
import { dirname as
|
|
21192
|
+
import { existsSync as existsSync43, mkdirSync as mkdirSync31, readFileSync as readFileSync41, renameSync as renameSync7, writeFileSync as writeFileSync34 } from "fs";
|
|
21193
|
+
import { dirname as dirname26 } from "path";
|
|
20962
21194
|
import { parseDocument as parseDocument4 } from "yaml";
|
|
20963
21195
|
var ShipNameError = class extends Error {
|
|
20964
21196
|
};
|
|
@@ -21019,34 +21251,34 @@ async function syncRouteName(i) {
|
|
|
21019
21251
|
return { status: "ok", ...base, action, name: i.local };
|
|
21020
21252
|
}
|
|
21021
21253
|
function readSyncedName(resolvedFile) {
|
|
21022
|
-
if (!
|
|
21254
|
+
if (!existsSync43(resolvedFile)) return void 0;
|
|
21023
21255
|
try {
|
|
21024
|
-
const v = JSON.parse(
|
|
21256
|
+
const v = JSON.parse(readFileSync41(resolvedFile, "utf8")).shipName;
|
|
21025
21257
|
return typeof v === "string" ? v : void 0;
|
|
21026
21258
|
} catch {
|
|
21027
21259
|
return void 0;
|
|
21028
21260
|
}
|
|
21029
21261
|
}
|
|
21030
21262
|
function writeSyncedName(resolvedFile, name) {
|
|
21031
|
-
if (!
|
|
21263
|
+
if (!existsSync43(resolvedFile)) return;
|
|
21032
21264
|
let raw;
|
|
21033
21265
|
try {
|
|
21034
|
-
raw = JSON.parse(
|
|
21266
|
+
raw = JSON.parse(readFileSync41(resolvedFile, "utf8"));
|
|
21035
21267
|
} catch {
|
|
21036
21268
|
return;
|
|
21037
21269
|
}
|
|
21038
21270
|
if (raw.shipName === name) return;
|
|
21039
21271
|
raw.shipName = name;
|
|
21040
|
-
|
|
21272
|
+
mkdirSync31(dirname26(resolvedFile), { recursive: true });
|
|
21041
21273
|
const tmp = `${resolvedFile}.tmp${process.pid}`;
|
|
21042
|
-
|
|
21274
|
+
writeFileSync34(tmp, `${JSON.stringify(raw, null, 2)}
|
|
21043
21275
|
`);
|
|
21044
|
-
|
|
21276
|
+
renameSync7(tmp, resolvedFile);
|
|
21045
21277
|
}
|
|
21046
21278
|
async function reconcileShipName(i) {
|
|
21047
21279
|
let local = i.ship.name;
|
|
21048
21280
|
try {
|
|
21049
|
-
local = shipNameOfYaml(
|
|
21281
|
+
local = shipNameOfYaml(readFileSync41(i.configFile, "utf8")) ?? local;
|
|
21050
21282
|
} catch {
|
|
21051
21283
|
}
|
|
21052
21284
|
const resolvedFile = resolvedPathFor(i.stateDir, i.route);
|
|
@@ -21070,8 +21302,8 @@ async function reconcileShipName(i) {
|
|
|
21070
21302
|
}
|
|
21071
21303
|
if (result.status !== "ok") return result;
|
|
21072
21304
|
if (result.action === "adopt" || result.action === "row-wins") {
|
|
21073
|
-
const text2 =
|
|
21074
|
-
|
|
21305
|
+
const text2 = readFileSync41(i.configFile, "utf8");
|
|
21306
|
+
writeFileSync34(i.configFile, setShipNameInYaml(text2, result.name));
|
|
21075
21307
|
i.ship.name = result.name;
|
|
21076
21308
|
if (result.action === "row-wins") {
|
|
21077
21309
|
i.emit?.warn(
|
|
@@ -21116,11 +21348,11 @@ async function reconcileRouteShipName(o) {
|
|
|
21116
21348
|
}
|
|
21117
21349
|
|
|
21118
21350
|
// src/mirror-contract.ts
|
|
21119
|
-
import { existsSync as
|
|
21351
|
+
import { existsSync as existsSync44 } from "fs";
|
|
21120
21352
|
|
|
21121
21353
|
// src/passenger-mirror.ts
|
|
21122
|
-
import { mkdirSync as
|
|
21123
|
-
import { dirname as
|
|
21354
|
+
import { mkdirSync as mkdirSync32 } from "fs";
|
|
21355
|
+
import { dirname as dirname27 } from "path";
|
|
21124
21356
|
function mirrorRepoOf(spec) {
|
|
21125
21357
|
const fromOrigin = spec.originUrl ? parseRemote(spec.originUrl) : null;
|
|
21126
21358
|
if (fromOrigin) return fromOrigin;
|
|
@@ -21138,9 +21370,9 @@ async function materializeMirrorCheckouts(specs, cacheFor = (s) => new SandboxCa
|
|
|
21138
21370
|
continue;
|
|
21139
21371
|
}
|
|
21140
21372
|
try {
|
|
21141
|
-
const parent =
|
|
21142
|
-
|
|
21143
|
-
|
|
21373
|
+
const parent = dirname27(spec.dir);
|
|
21374
|
+
mkdirSync32(parent, { recursive: true });
|
|
21375
|
+
mkdirSync32(spec.dir, { recursive: true });
|
|
21144
21376
|
const r = await cacheFor(spec).materialize(repo, spec.base, parent, spec.name);
|
|
21145
21377
|
out.push({ ...base, action: r.changed ? "updated" : "unchanged", detail: r.tip });
|
|
21146
21378
|
} catch (e) {
|
|
@@ -21157,7 +21389,7 @@ function mirrorOutcome(m) {
|
|
|
21157
21389
|
|
|
21158
21390
|
// src/mirror-contract.ts
|
|
21159
21391
|
function lacksCheckout(ship, dir) {
|
|
21160
|
-
return ship.runner === "sandbox" && !
|
|
21392
|
+
return ship.runner === "sandbox" && !existsSync44(dir) && !remoteOf(dir);
|
|
21161
21393
|
}
|
|
21162
21394
|
function skipsHostCheckout(ship) {
|
|
21163
21395
|
return ship.runner === "sandbox";
|
|
@@ -21238,18 +21470,18 @@ function explainRefusal(readable, unreadable) {
|
|
|
21238
21470
|
|
|
21239
21471
|
// src/ssh-keys.ts
|
|
21240
21472
|
import { execFileSync as execFileSync13 } from "child_process";
|
|
21241
|
-
import { existsSync as
|
|
21242
|
-
import { dirname as
|
|
21473
|
+
import { existsSync as existsSync45, mkdirSync as mkdirSync33, readFileSync as readFileSync42, chmodSync as chmodSync3 } from "fs";
|
|
21474
|
+
import { dirname as dirname28, join as join47 } from "path";
|
|
21243
21475
|
var SshKeyError = class extends Error {
|
|
21244
21476
|
};
|
|
21245
21477
|
function shipSshKeyPathFor(stateDir) {
|
|
21246
|
-
return
|
|
21478
|
+
return join47(stateDir, "ssh", "id_ed25519");
|
|
21247
21479
|
}
|
|
21248
21480
|
function ensureShipSshKeypair(stateDir) {
|
|
21249
21481
|
const privateKeyPath = shipSshKeyPathFor(stateDir);
|
|
21250
21482
|
const publicKeyPath = `${privateKeyPath}.pub`;
|
|
21251
|
-
if (!
|
|
21252
|
-
|
|
21483
|
+
if (!existsSync45(privateKeyPath)) {
|
|
21484
|
+
mkdirSync33(dirname28(privateKeyPath), { recursive: true });
|
|
21253
21485
|
try {
|
|
21254
21486
|
execFileSync13("ssh-keygen", [
|
|
21255
21487
|
"-t",
|
|
@@ -21269,10 +21501,10 @@ function ensureShipSshKeypair(stateDir) {
|
|
|
21269
21501
|
}
|
|
21270
21502
|
chmodSync3(privateKeyPath, 384);
|
|
21271
21503
|
}
|
|
21272
|
-
if (!
|
|
21504
|
+
if (!existsSync45(publicKeyPath)) {
|
|
21273
21505
|
throw new SshKeyError(`${privateKeyPath} exists but ${publicKeyPath} does not \u2014 regenerate or restore it`);
|
|
21274
21506
|
}
|
|
21275
|
-
const publicKey =
|
|
21507
|
+
const publicKey = readFileSync42(publicKeyPath, "utf8").trim();
|
|
21276
21508
|
return { privateKeyPath, publicKeyPath, publicKey };
|
|
21277
21509
|
}
|
|
21278
21510
|
function sshKeygenAvailable() {
|
|
@@ -21287,7 +21519,7 @@ function sshKeygenAvailable() {
|
|
|
21287
21519
|
// src/periscope-idle.ts
|
|
21288
21520
|
import { execFileSync as execFileSync14 } from "child_process";
|
|
21289
21521
|
import { statSync as statSync12 } from "fs";
|
|
21290
|
-
import { join as
|
|
21522
|
+
import { join as join48 } from "path";
|
|
21291
21523
|
var MAX_SCANNED_FILES = 2e4;
|
|
21292
21524
|
function newestWorktreeMtime(root) {
|
|
21293
21525
|
const a = newestTrackedMtime(root);
|
|
@@ -21312,7 +21544,7 @@ function newestTrackedMtime(root) {
|
|
|
21312
21544
|
if (!rel) continue;
|
|
21313
21545
|
if (++scanned > MAX_SCANNED_FILES) break;
|
|
21314
21546
|
try {
|
|
21315
|
-
const m = statSync12(
|
|
21547
|
+
const m = statSync12(join48(root, rel)).mtimeMs;
|
|
21316
21548
|
if (newest === null || m > newest) newest = m;
|
|
21317
21549
|
} catch {
|
|
21318
21550
|
}
|
|
@@ -21386,8 +21618,8 @@ async function runPeriscopeIdlePass(d) {
|
|
|
21386
21618
|
}
|
|
21387
21619
|
|
|
21388
21620
|
// src/periscope-cmd.ts
|
|
21389
|
-
import { existsSync as
|
|
21390
|
-
import { join as
|
|
21621
|
+
import { existsSync as existsSync46, mkdirSync as mkdirSync34, readFileSync as readFileSync43, rmSync as rmSync21, writeFileSync as writeFileSync35 } from "fs";
|
|
21622
|
+
import { join as join49 } from "path";
|
|
21391
21623
|
var PeriscopeError = class extends Error {
|
|
21392
21624
|
};
|
|
21393
21625
|
var LivePeriscopeError = class extends PeriscopeError {
|
|
@@ -21397,22 +21629,22 @@ var LivePeriscopeError = class extends PeriscopeError {
|
|
|
21397
21629
|
this.data = { refused: "live_periscope_exists", ...live };
|
|
21398
21630
|
}
|
|
21399
21631
|
};
|
|
21400
|
-
var priorDir = (stateDir) =>
|
|
21401
|
-
var priorPath = (stateDir, ticketRecordId) =>
|
|
21632
|
+
var priorDir = (stateDir) => join49(stateDir, "periscope-priors");
|
|
21633
|
+
var priorPath = (stateDir, ticketRecordId) => join49(priorDir(stateDir), `${ticketRecordId}.json`);
|
|
21402
21634
|
function removePeriscopePrior(stateDir, ticketRecordId) {
|
|
21403
|
-
|
|
21635
|
+
rmSync21(priorPath(stateDir, ticketRecordId), { force: true });
|
|
21404
21636
|
}
|
|
21405
21637
|
function writePeriscopePrior(stateDir, ticketRecordId, prior) {
|
|
21406
21638
|
try {
|
|
21407
|
-
|
|
21408
|
-
|
|
21639
|
+
mkdirSync34(priorDir(stateDir), { recursive: true });
|
|
21640
|
+
writeFileSync35(priorPath(stateDir, ticketRecordId), JSON.stringify(prior));
|
|
21409
21641
|
} catch {
|
|
21410
21642
|
}
|
|
21411
21643
|
}
|
|
21412
21644
|
function readPeriscopePrior(stateDir, ticketRecordId) {
|
|
21413
21645
|
try {
|
|
21414
21646
|
const p = priorPath(stateDir, ticketRecordId);
|
|
21415
|
-
return
|
|
21647
|
+
return existsSync46(p) ? JSON.parse(readFileSync43(p, "utf8")) : void 0;
|
|
21416
21648
|
} catch {
|
|
21417
21649
|
return void 0;
|
|
21418
21650
|
}
|
|
@@ -21981,7 +22213,7 @@ function latestMtime(path) {
|
|
|
21981
22213
|
if (!stat2.isDirectory()) return 0;
|
|
21982
22214
|
let latest = stat2.mtimeMs;
|
|
21983
22215
|
for (const entry of readdirSync14(path, { withFileTypes: true })) {
|
|
21984
|
-
latest = Math.max(latest, latestMtime(
|
|
22216
|
+
latest = Math.max(latest, latestMtime(join50(path, entry.name)));
|
|
21985
22217
|
}
|
|
21986
22218
|
return latest;
|
|
21987
22219
|
}
|
|
@@ -21990,10 +22222,10 @@ function computeTreeSignature(paths) {
|
|
|
21990
22222
|
}
|
|
21991
22223
|
function makeStaleChecker(paths, opts = {}) {
|
|
21992
22224
|
const initial = computeTreeSignature(paths);
|
|
21993
|
-
return () => computeTreeSignature(paths) !== initial || opts.reloadSentinel !== void 0 &&
|
|
22225
|
+
return () => computeTreeSignature(paths) !== initial || opts.reloadSentinel !== void 0 && existsSync47(opts.reloadSentinel);
|
|
21994
22226
|
}
|
|
21995
22227
|
function reloadSentinelFor(stateDir) {
|
|
21996
|
-
return
|
|
22228
|
+
return join50(stateDir, "reload-requested");
|
|
21997
22229
|
}
|
|
21998
22230
|
function readReloadRequestedAt(stateDir) {
|
|
21999
22231
|
try {
|
|
@@ -22003,17 +22235,17 @@ function readReloadRequestedAt(stateDir) {
|
|
|
22003
22235
|
}
|
|
22004
22236
|
}
|
|
22005
22237
|
function daemonStampFor(stateDir) {
|
|
22006
|
-
return
|
|
22238
|
+
return join50(stateDir, "daemon.started");
|
|
22007
22239
|
}
|
|
22008
22240
|
function noteDaemonStarted(stateDir, now = Date.now()) {
|
|
22009
|
-
|
|
22010
|
-
|
|
22011
|
-
|
|
22241
|
+
mkdirSync35(stateDir, { recursive: true });
|
|
22242
|
+
rmSync22(reloadSentinelFor(stateDir), { force: true });
|
|
22243
|
+
writeFileSync36(daemonStampFor(stateDir), `${JSON.stringify({ pid: process.pid, startedAt: now })}
|
|
22012
22244
|
`);
|
|
22013
22245
|
}
|
|
22014
22246
|
function readDaemonStarted(stateDir) {
|
|
22015
22247
|
try {
|
|
22016
|
-
const v = JSON.parse(
|
|
22248
|
+
const v = JSON.parse(readFileSync44(daemonStampFor(stateDir), "utf8")).startedAt;
|
|
22017
22249
|
return typeof v === "number" ? v : null;
|
|
22018
22250
|
} catch {
|
|
22019
22251
|
return null;
|
|
@@ -22869,7 +23101,7 @@ function parseSystemctlShow(text2) {
|
|
|
22869
23101
|
}
|
|
22870
23102
|
function lastLogLine(path, read = (p) => {
|
|
22871
23103
|
try {
|
|
22872
|
-
return
|
|
23104
|
+
return readFileSync45(p, "utf8");
|
|
22873
23105
|
} catch {
|
|
22874
23106
|
return null;
|
|
22875
23107
|
}
|
|
@@ -22896,7 +23128,7 @@ function probeDaemonUnit(o) {
|
|
|
22896
23128
|
const r = spawnSync11(cmd[0], cmd.slice(1), { encoding: "utf8" });
|
|
22897
23129
|
return r.error ? null : { status: r.status, stdout: r.stdout ?? "" };
|
|
22898
23130
|
});
|
|
22899
|
-
const installed = o.plan.unitPaths.some((p) =>
|
|
23131
|
+
const installed = o.plan.unitPaths.some((p) => existsSync48(p));
|
|
22900
23132
|
let reading = null;
|
|
22901
23133
|
if (installed && o.plan.mechanism === "launchd") {
|
|
22902
23134
|
const r = run4(["launchctl", "print", `gui/${o.uid}/${o.label}`]);
|
|
@@ -22946,7 +23178,7 @@ function daemonProblem(d, route2) {
|
|
|
22946
23178
|
}
|
|
22947
23179
|
function readDaemonStamp(stateDir) {
|
|
22948
23180
|
try {
|
|
22949
|
-
const v = JSON.parse(
|
|
23181
|
+
const v = JSON.parse(readFileSync45(daemonStampFor(stateDir), "utf8"));
|
|
22950
23182
|
if (typeof v.startedAt !== "number") return null;
|
|
22951
23183
|
return typeof v.pid === "number" ? { pid: v.pid, startedAt: v.startedAt } : { startedAt: v.startedAt };
|
|
22952
23184
|
} catch {
|
|
@@ -22955,15 +23187,15 @@ function readDaemonStamp(stateDir) {
|
|
|
22955
23187
|
}
|
|
22956
23188
|
|
|
22957
23189
|
// src/daemon-start-failure.ts
|
|
22958
|
-
import { existsSync as
|
|
22959
|
-
import { dirname as
|
|
23190
|
+
import { existsSync as existsSync49, mkdirSync as mkdirSync36, readFileSync as readFileSync46, unlinkSync as unlinkSync4, writeFileSync as writeFileSync37 } from "fs";
|
|
23191
|
+
import { dirname as dirname29, join as join51 } from "path";
|
|
22960
23192
|
var DAEMON_START_FAILED_KEY = "daemon_start_failed";
|
|
22961
23193
|
var START_FAILURE_BACKOFF_MS = 6e4;
|
|
22962
23194
|
var BACKOFF_AFTER_FAILURES = 2;
|
|
22963
|
-
var fileFor3 = (stateDir) =>
|
|
23195
|
+
var fileFor3 = (stateDir) => join51(stateDir, ".daemon-start-failure.json");
|
|
22964
23196
|
function readStartFailure(stateDir) {
|
|
22965
23197
|
try {
|
|
22966
|
-
const parsed = JSON.parse(
|
|
23198
|
+
const parsed = JSON.parse(readFileSync46(fileFor3(stateDir), "utf8"));
|
|
22967
23199
|
return typeof parsed.reason === "string" && typeof parsed.count === "number" ? { reason: parsed.reason, count: parsed.count, firstAt: String(parsed.firstAt), lastAt: String(parsed.lastAt) } : null;
|
|
22968
23200
|
} catch {
|
|
22969
23201
|
return null;
|
|
@@ -22979,8 +23211,8 @@ function noteStartFailure(stateDir, reason, nowMs = Date.now()) {
|
|
|
22979
23211
|
firstAt: same ? previous.firstAt : nowIso,
|
|
22980
23212
|
lastAt: nowIso
|
|
22981
23213
|
};
|
|
22982
|
-
|
|
22983
|
-
|
|
23214
|
+
mkdirSync36(stateDir, { recursive: true });
|
|
23215
|
+
writeFileSync37(fileFor3(stateDir), JSON.stringify(record));
|
|
22984
23216
|
return record;
|
|
22985
23217
|
}
|
|
22986
23218
|
function startFailureDelayMs(count) {
|
|
@@ -22994,7 +23226,7 @@ function startFailureItem(record, o = {}) {
|
|
|
22994
23226
|
return { kind: "daemon_start_failed", key: DAEMON_START_FAILED_KEY, message: parts.join(". ").replace(/\.\./g, "."), since: record.firstAt };
|
|
22995
23227
|
}
|
|
22996
23228
|
function clearStartFailure(state, stateDir) {
|
|
22997
|
-
if (
|
|
23229
|
+
if (existsSync49(fileFor3(stateDir))) {
|
|
22998
23230
|
try {
|
|
22999
23231
|
unlinkSync4(fileFor3(stateDir));
|
|
23000
23232
|
} catch {
|
|
@@ -23021,7 +23253,7 @@ async function reportStartFailure(o) {
|
|
|
23021
23253
|
return delay;
|
|
23022
23254
|
}
|
|
23023
23255
|
function fallbackStateDir(configFile) {
|
|
23024
|
-
return
|
|
23256
|
+
return join51(dirname29(configFile), "state");
|
|
23025
23257
|
}
|
|
23026
23258
|
|
|
23027
23259
|
// src/projects-cmd.ts
|
|
@@ -23135,8 +23367,8 @@ function runForge(a, io) {
|
|
|
23135
23367
|
|
|
23136
23368
|
// src/release-sandbox.ts
|
|
23137
23369
|
import { execFile as execFile5 } from "child_process";
|
|
23138
|
-
import { mkdirSync as
|
|
23139
|
-
import { dirname as
|
|
23370
|
+
import { mkdirSync as mkdirSync37, writeFileSync as writeFileSync38 } from "fs";
|
|
23371
|
+
import { dirname as dirname30 } from "path";
|
|
23140
23372
|
import { promisify as promisify4 } from "util";
|
|
23141
23373
|
var execFileP4 = promisify4(execFile5);
|
|
23142
23374
|
var RELEASE_CLONE_DEPTH = 50;
|
|
@@ -23182,8 +23414,8 @@ async function openReleaseSandbox(o) {
|
|
|
23182
23414
|
if (!policyFile) {
|
|
23183
23415
|
generated = generateSandboxPolicy({ mirrorDir: cfg.mirrorDir, workDir: cfg.workDir, ...o.policy });
|
|
23184
23416
|
policyFile = o.policyFile;
|
|
23185
|
-
|
|
23186
|
-
|
|
23417
|
+
mkdirSync37(dirname30(policyFile), { recursive: true });
|
|
23418
|
+
writeFileSync38(policyFile, generated.yaml, { mode: 384 });
|
|
23187
23419
|
}
|
|
23188
23420
|
const secrets = { ...process.env };
|
|
23189
23421
|
const secretKeys = [];
|
|
@@ -23349,7 +23581,7 @@ function missingReleaserWarning(repo, release, ships, now = Date.now()) {
|
|
|
23349
23581
|
}
|
|
23350
23582
|
|
|
23351
23583
|
// src/watch.ts
|
|
23352
|
-
import { watch as watchFile, existsSync as
|
|
23584
|
+
import { watch as watchFile, existsSync as existsSync50, statSync as statSync14, openSync as openSync5, readSync as readSync2, closeSync as closeSync5 } from "fs";
|
|
23353
23585
|
var E = "\x1B[";
|
|
23354
23586
|
var dim = (s) => `${E}2m${s}${E}0m`;
|
|
23355
23587
|
var bold = (s) => `${E}1m${s}${E}0m`;
|
|
@@ -23450,7 +23682,7 @@ function renderHeaders(states, now = Date.now()) {
|
|
|
23450
23682
|
return states.map((s) => renderHeader(s, now)).join("");
|
|
23451
23683
|
}
|
|
23452
23684
|
function readFrom(file, from) {
|
|
23453
|
-
if (!
|
|
23685
|
+
if (!existsSync50(file)) return { events: [], offset: from };
|
|
23454
23686
|
const size = statSync14(file).size;
|
|
23455
23687
|
if (size < from) return readFrom(file, 0);
|
|
23456
23688
|
if (size === from) return { events: [], offset: from };
|
|
@@ -24221,8 +24453,8 @@ function describeCapability(i) {
|
|
|
24221
24453
|
}
|
|
24222
24454
|
|
|
24223
24455
|
// src/agents-sync-run.ts
|
|
24224
|
-
import { existsSync as
|
|
24225
|
-
import { dirname as
|
|
24456
|
+
import { existsSync as existsSync51, mkdirSync as mkdirSync38, readFileSync as readFileSync47, writeFileSync as writeFileSync39 } from "fs";
|
|
24457
|
+
import { dirname as dirname31 } from "path";
|
|
24226
24458
|
async function runAgentsSync(target, o) {
|
|
24227
24459
|
const dryRun = o.dryRun ?? false;
|
|
24228
24460
|
const force = o.force ?? false;
|
|
@@ -24257,12 +24489,12 @@ async function runAgentsSync(target, o) {
|
|
|
24257
24489
|
for (const w of skillResult?.warnings ?? []) o.warn(`warning: ${w}`);
|
|
24258
24490
|
if (!dryRun) {
|
|
24259
24491
|
const resolvedPath = resolvedPathFor(o.stateDir, target.route);
|
|
24260
|
-
const raw =
|
|
24492
|
+
const raw = existsSync51(resolvedPath) ? JSON.parse(readFileSync47(resolvedPath, "utf8")) : {};
|
|
24261
24493
|
raw.agentPersonas = personaResult.agentPersonas;
|
|
24262
24494
|
if (skillResult) raw.agentSkills = skillResult.agentSkills;
|
|
24263
24495
|
if (personaResult.releaseAgentId) raw.releaseAgentId = personaResult.releaseAgentId;
|
|
24264
|
-
|
|
24265
|
-
|
|
24496
|
+
mkdirSync38(dirname31(resolvedPath), { recursive: true });
|
|
24497
|
+
writeFileSync39(resolvedPath, `${JSON.stringify(raw, null, 2)}
|
|
24266
24498
|
`);
|
|
24267
24499
|
if (target.resolved) {
|
|
24268
24500
|
target.resolved.agentPersonas = personaResult.agentPersonas;
|
|
@@ -24399,7 +24631,7 @@ async function showLogEntry(route2, entryId, opts = {}) {
|
|
|
24399
24631
|
|
|
24400
24632
|
// src/repos-check.ts
|
|
24401
24633
|
import { spawnSync as spawnSync12 } from "child_process";
|
|
24402
|
-
import { readFileSync as
|
|
24634
|
+
import { readFileSync as readFileSync48 } from "fs";
|
|
24403
24635
|
import { basename as basename11 } from "path";
|
|
24404
24636
|
var POSIX_SHELL = /^(?:ba|z|da|k|a|mk)?sh$|^fish$/;
|
|
24405
24637
|
function checkHookSyntax(script, shell) {
|
|
@@ -24440,7 +24672,7 @@ function checkRepoSpec(dir, opts = {}) {
|
|
|
24440
24672
|
}
|
|
24441
24673
|
let parsed;
|
|
24442
24674
|
try {
|
|
24443
|
-
parsed = parseRepoConfig(
|
|
24675
|
+
parsed = parseRepoConfig(readFileSync48(file, "utf8"), file);
|
|
24444
24676
|
} catch (e) {
|
|
24445
24677
|
if (!(e instanceof RepoConfigError)) throw e;
|
|
24446
24678
|
return { ...empty, file, error: e.message, exitCode: 1 };
|
|
@@ -24904,7 +25136,7 @@ ${run4.err}` });
|
|
|
24904
25136
|
}
|
|
24905
25137
|
|
|
24906
25138
|
// src/sample-ticket.ts
|
|
24907
|
-
import { basename as basename12, dirname as
|
|
25139
|
+
import { basename as basename12, dirname as dirname32, join as join52 } from "path";
|
|
24908
25140
|
var SAMPLE_REPO = "crew-sample";
|
|
24909
25141
|
var SAMPLE_REMOTE = `local/${SAMPLE_REPO}`;
|
|
24910
25142
|
var SAMPLE_MARKER = "sample: true";
|
|
@@ -24927,8 +25159,8 @@ has something safe to work on: its test and build hooks always pass, it has no
|
|
|
24927
25159
|
remote, and \`crew sample-ticket --remove\` deletes it.
|
|
24928
25160
|
`;
|
|
24929
25161
|
function sampleDir(existing, reposBase, workspace) {
|
|
24930
|
-
if (existing.length > 0) return
|
|
24931
|
-
return
|
|
25162
|
+
if (existing.length > 0) return join52(dirname32(existing[0]), SAMPLE_REPO);
|
|
25163
|
+
return join52(reposBase, workspace, SAMPLE_REPO);
|
|
24932
25164
|
}
|
|
24933
25165
|
var SAMPLE_TITLE = "Sample: add a documented `greet` function with a test";
|
|
24934
25166
|
function sampleDescription() {
|
|
@@ -24972,8 +25204,8 @@ function planSampleTicket(i) {
|
|
|
24972
25204
|
}
|
|
24973
25205
|
|
|
24974
25206
|
// src/worktree-sweep.ts
|
|
24975
|
-
import { existsSync as
|
|
24976
|
-
import { basename as basename13, dirname as
|
|
25207
|
+
import { existsSync as existsSync52, readFileSync as readFileSync49, readdirSync as readdirSync15 } from "fs";
|
|
25208
|
+
import { basename as basename13, dirname as dirname33, join as join53, resolve as resolve5 } from "path";
|
|
24977
25209
|
function planWorktreeSweep(target, tickets, contract) {
|
|
24978
25210
|
const terminal = new Set(contract.statuses.resolved.filter((s) => s !== contract.statuses.verified));
|
|
24979
25211
|
const verified = contract.statuses.verified;
|
|
@@ -25037,7 +25269,7 @@ function worktreeTicketNumbers(target) {
|
|
|
25037
25269
|
return [...nums];
|
|
25038
25270
|
}
|
|
25039
25271
|
function siblingWorktreeDirs(target) {
|
|
25040
|
-
const parent =
|
|
25272
|
+
const parent = dirname33(target.dir.replace(/[/\\]+$/, ""));
|
|
25041
25273
|
const stem = `${basename13(target.dir.replace(/[/\\]+$/, ""))}-`;
|
|
25042
25274
|
const registered = new Set(worktrees(target.dir).map((w) => resolve5(w.path)));
|
|
25043
25275
|
let names;
|
|
@@ -25050,7 +25282,7 @@ function siblingWorktreeDirs(target) {
|
|
|
25050
25282
|
for (const name of names) {
|
|
25051
25283
|
if (!name.startsWith(stem)) continue;
|
|
25052
25284
|
const m = DIR_NUMBER_SUFFIXED.exec(name);
|
|
25053
|
-
const path =
|
|
25285
|
+
const path = join53(parent, name);
|
|
25054
25286
|
if (m && !registered.has(resolve5(path))) out.push({ path, number: m[1] });
|
|
25055
25287
|
}
|
|
25056
25288
|
return out;
|
|
@@ -25085,7 +25317,7 @@ async function applyWorktreeSweep(cwd, actions, dryRun, log, remote = "origin",
|
|
|
25085
25317
|
let removed = 0;
|
|
25086
25318
|
let keptBranches = 0;
|
|
25087
25319
|
for (const a of actions) {
|
|
25088
|
-
if (!dryRun && base && !a.keepBranch &&
|
|
25320
|
+
if (!dryRun && base && !a.keepBranch && existsSync52(a.path) && isHandBackMerge(a.path, base)) {
|
|
25089
25321
|
if (gitOk(a.path, ["merge", "--abort"]) !== null) {
|
|
25090
25322
|
log.emit(
|
|
25091
25323
|
`abandoned the hand-back merge of ${base} in ${a.path}: ${a.ticket.issue_id} deployed without it`,
|
|
@@ -25093,7 +25325,7 @@ async function applyWorktreeSweep(cwd, actions, dryRun, log, remote = "origin",
|
|
|
25093
25325
|
);
|
|
25094
25326
|
}
|
|
25095
25327
|
}
|
|
25096
|
-
if (!dryRun &&
|
|
25328
|
+
if (!dryRun && existsSync52(a.path)) {
|
|
25097
25329
|
let dirty = false;
|
|
25098
25330
|
try {
|
|
25099
25331
|
dirty = status(a.path).length > 0;
|
|
@@ -25104,7 +25336,7 @@ async function applyWorktreeSweep(cwd, actions, dryRun, log, remote = "origin",
|
|
|
25104
25336
|
continue;
|
|
25105
25337
|
}
|
|
25106
25338
|
}
|
|
25107
|
-
if (!dryRun && a.requirePushed && a.branch &&
|
|
25339
|
+
if (!dryRun && a.requirePushed && a.branch && existsSync52(a.path) && remoteConfigured(cwd, remote) && worktreeHoldsUnpushed(a.path, remote)) {
|
|
25108
25340
|
refuse2(a, "unpushed commits", `${a.branch} has commits that are not on ${remote}`);
|
|
25109
25341
|
continue;
|
|
25110
25342
|
}
|
|
@@ -25153,7 +25385,7 @@ function isHandBackMerge(path, base) {
|
|
|
25153
25385
|
if (!msgPath) return false;
|
|
25154
25386
|
let first;
|
|
25155
25387
|
try {
|
|
25156
|
-
first =
|
|
25388
|
+
first = readFileSync49(resolve5(path, msgPath), "utf8").split("\n")[0] ?? "";
|
|
25157
25389
|
} catch {
|
|
25158
25390
|
return false;
|
|
25159
25391
|
}
|
|
@@ -25258,14 +25490,14 @@ function applyRemoteBranchCleanup(cwd, remote, branches2, dryRun, log) {
|
|
|
25258
25490
|
}
|
|
25259
25491
|
|
|
25260
25492
|
// src/stream-sweep.ts
|
|
25261
|
-
import { existsSync as
|
|
25262
|
-
import { join as
|
|
25493
|
+
import { existsSync as existsSync53, readdirSync as readdirSync16, rmSync as rmSync23, statSync as statSync15 } from "fs";
|
|
25494
|
+
import { join as join54 } from "path";
|
|
25263
25495
|
var DAY_MS2 = 24 * 60 * 60 * 1e3;
|
|
25264
25496
|
function planStreamSweep(stateDir, retentionDays, now = Date.now()) {
|
|
25265
|
-
const dir =
|
|
25266
|
-
if (!
|
|
25497
|
+
const dir = join54(stateDir, "streams");
|
|
25498
|
+
if (!existsSync53(dir)) return [];
|
|
25267
25499
|
const cutoff = now - retentionDays * DAY_MS2;
|
|
25268
|
-
return readdirSync16(dir).map((name) =>
|
|
25500
|
+
return readdirSync16(dir).map((name) => join54(dir, name)).filter((path) => {
|
|
25269
25501
|
try {
|
|
25270
25502
|
return statSync15(path).mtimeMs < cutoff;
|
|
25271
25503
|
} catch {
|
|
@@ -25281,7 +25513,7 @@ function applyStreamSweep(paths, dryRun, log) {
|
|
|
25281
25513
|
continue;
|
|
25282
25514
|
}
|
|
25283
25515
|
try {
|
|
25284
|
-
|
|
25516
|
+
rmSync23(path, { force: true });
|
|
25285
25517
|
removed++;
|
|
25286
25518
|
log.emit(`removed stream artifact ${path}`, { step: "worktree" });
|
|
25287
25519
|
} catch (e) {
|
|
@@ -25291,9 +25523,9 @@ function applyStreamSweep(paths, dryRun, log) {
|
|
|
25291
25523
|
return removed;
|
|
25292
25524
|
}
|
|
25293
25525
|
function planEventsSweep(stateDir, retentionDays, now = Date.now()) {
|
|
25294
|
-
if (!
|
|
25526
|
+
if (!existsSync53(stateDir)) return [];
|
|
25295
25527
|
const cutoff = now - retentionDays * DAY_MS2;
|
|
25296
|
-
return readdirSync16(stateDir).filter((name) => ROTATED_EVENTS_RE.test(name)).map((name) =>
|
|
25528
|
+
return readdirSync16(stateDir).filter((name) => ROTATED_EVENTS_RE.test(name)).map((name) => join54(stateDir, name)).filter((path) => {
|
|
25297
25529
|
try {
|
|
25298
25530
|
return statSync15(path).mtimeMs < cutoff;
|
|
25299
25531
|
} catch {
|
|
@@ -25303,7 +25535,7 @@ function planEventsSweep(stateDir, retentionDays, now = Date.now()) {
|
|
|
25303
25535
|
}
|
|
25304
25536
|
|
|
25305
25537
|
// src/cli.ts
|
|
25306
|
-
import { realpathSync as realpathSync3, readFileSync as
|
|
25538
|
+
import { realpathSync as realpathSync3, readFileSync as readFileSync52, existsSync as existsSync57, mkdirSync as mkdirSync42, writeFileSync as writeFileSync42, rmSync as rmSync26, unlinkSync as unlinkSync6, copyFileSync as copyFileSync2, renameSync as renameSync8, statSync as statSync17, readdirSync as readdirSync20 } from "fs";
|
|
25307
25539
|
import { createInterface } from "readline/promises";
|
|
25308
25540
|
|
|
25309
25541
|
// src/periscope-resume.ts
|
|
@@ -25530,8 +25762,8 @@ async function unregisterEndpoint(workspaceId, info, d) {
|
|
|
25530
25762
|
import { createServer as createHttpServer } from "http";
|
|
25531
25763
|
import { spawn as spawn9 } from "child_process";
|
|
25532
25764
|
import { randomBytes as randomBytes2 } from "crypto";
|
|
25533
|
-
import { existsSync as
|
|
25534
|
-
import { join as
|
|
25765
|
+
import { existsSync as existsSync54, mkdirSync as mkdirSync39, readFileSync as readFileSync50, writeFileSync as writeFileSync40, unlinkSync as unlinkSync5, readdirSync as readdirSync17 } from "fs";
|
|
25766
|
+
import { join as join55 } from "path";
|
|
25535
25767
|
|
|
25536
25768
|
// src/secret-compare.ts
|
|
25537
25769
|
import { timingSafeEqual } from "crypto";
|
|
@@ -25624,21 +25856,21 @@ var defaultSpawn2 = (cmd, args, env) => {
|
|
|
25624
25856
|
return child;
|
|
25625
25857
|
};
|
|
25626
25858
|
function syncDaemonStatePath(stateDir, workspaceId) {
|
|
25627
|
-
return
|
|
25859
|
+
return join55(stateDir, "passengers", `${workspaceId}-sync.json`);
|
|
25628
25860
|
}
|
|
25629
25861
|
function readPersistedSyncDaemon(stateDir, workspaceId) {
|
|
25630
25862
|
const path = syncDaemonStatePath(stateDir, workspaceId);
|
|
25631
|
-
if (!
|
|
25863
|
+
if (!existsSync54(path)) return void 0;
|
|
25632
25864
|
try {
|
|
25633
|
-
return JSON.parse(
|
|
25865
|
+
return JSON.parse(readFileSync50(path, "utf8"));
|
|
25634
25866
|
} catch {
|
|
25635
25867
|
return void 0;
|
|
25636
25868
|
}
|
|
25637
25869
|
}
|
|
25638
25870
|
function writePersistedSyncDaemon(stateDir, state) {
|
|
25639
25871
|
const path = syncDaemonStatePath(stateDir, state.workspaceId);
|
|
25640
|
-
|
|
25641
|
-
|
|
25872
|
+
mkdirSync39(join55(stateDir, "passengers"), { recursive: true });
|
|
25873
|
+
writeFileSync40(path, `${JSON.stringify(state, null, 2)}
|
|
25642
25874
|
`);
|
|
25643
25875
|
}
|
|
25644
25876
|
function removePersistedSyncDaemon(stateDir, workspaceId) {
|
|
@@ -25658,8 +25890,8 @@ function waitForExit(pid, alive, timeoutMs = 5e3) {
|
|
|
25658
25890
|
}
|
|
25659
25891
|
}
|
|
25660
25892
|
function readAllPersistedSyncWorkspaceIds(stateDir) {
|
|
25661
|
-
const dir =
|
|
25662
|
-
if (!
|
|
25893
|
+
const dir = join55(stateDir, "passengers");
|
|
25894
|
+
if (!existsSync54(dir)) return [];
|
|
25663
25895
|
const suffix = "-sync.json";
|
|
25664
25896
|
return readdirSync17(dir).filter((f) => f.endsWith(suffix)).map((f) => f.slice(0, -suffix.length));
|
|
25665
25897
|
}
|
|
@@ -25717,12 +25949,12 @@ function syncPassengerSyncDaemons(plans, cfg, stateDir, deps = {}) {
|
|
|
25717
25949
|
|
|
25718
25950
|
// src/periscope-proxy.ts
|
|
25719
25951
|
import { spawn as spawn10 } from "child_process";
|
|
25720
|
-
import { appendFileSync as appendFileSync3, mkdirSync as
|
|
25952
|
+
import { appendFileSync as appendFileSync3, mkdirSync as mkdirSync40 } from "fs";
|
|
25721
25953
|
import { createServer, request as httpRequest } from "http";
|
|
25722
25954
|
import { request as httpsRequest } from "https";
|
|
25723
25955
|
import { connect as netConnect } from "net";
|
|
25724
25956
|
import { connect as tlsConnect } from "tls";
|
|
25725
|
-
import { dirname as
|
|
25957
|
+
import { dirname as dirname34, isAbsolute as isAbsolute4 } from "path";
|
|
25726
25958
|
import { brotliDecompressSync, gunzipSync, inflateSync } from "zlib";
|
|
25727
25959
|
|
|
25728
25960
|
// src/periscope-inspector.ts
|
|
@@ -25836,7 +26068,7 @@ function parsePointedBody(raw) {
|
|
|
25836
26068
|
return entry;
|
|
25837
26069
|
}
|
|
25838
26070
|
function appendPointed(file, entry, now = /* @__PURE__ */ new Date()) {
|
|
25839
|
-
|
|
26071
|
+
mkdirSync40(dirname34(file), { recursive: true });
|
|
25840
26072
|
appendFileSync3(file, `${JSON.stringify({ ...entry, at: now.toISOString() })}
|
|
25841
26073
|
`);
|
|
25842
26074
|
}
|
|
@@ -26125,7 +26357,7 @@ async function startWorktreeIntel(d) {
|
|
|
26125
26357
|
}
|
|
26126
26358
|
|
|
26127
26359
|
// src/contract-refusal.ts
|
|
26128
|
-
import { join as
|
|
26360
|
+
import { join as join56 } from "path";
|
|
26129
26361
|
function contractFixers(dir, baseRef, tickets, locate) {
|
|
26130
26362
|
const out = [];
|
|
26131
26363
|
for (const t of tickets) {
|
|
@@ -26137,7 +26369,7 @@ function contractFixers(dir, baseRef, tickets, locate) {
|
|
|
26137
26369
|
const text2 = gitOk(dir, ["show", `${branch}:${file}`]);
|
|
26138
26370
|
if (text2 === null) continue;
|
|
26139
26371
|
try {
|
|
26140
|
-
parseRepoConfig(text2,
|
|
26372
|
+
parseRepoConfig(text2, join56(dir, file));
|
|
26141
26373
|
} catch (e) {
|
|
26142
26374
|
if (e instanceof RepoConfigError) continue;
|
|
26143
26375
|
throw e;
|
|
@@ -26152,18 +26384,18 @@ import { createHash as createHash11 } from "crypto";
|
|
|
26152
26384
|
import {
|
|
26153
26385
|
chmodSync as chmodSync4,
|
|
26154
26386
|
closeSync as closeSync6,
|
|
26155
|
-
existsSync as
|
|
26387
|
+
existsSync as existsSync55,
|
|
26156
26388
|
fstatSync,
|
|
26157
26389
|
openSync as openSync6,
|
|
26158
26390
|
readSync as readSync3,
|
|
26159
26391
|
readdirSync as readdirSync18,
|
|
26160
|
-
rmSync as
|
|
26392
|
+
rmSync as rmSync24,
|
|
26161
26393
|
statSync as statSync16,
|
|
26162
26394
|
watch
|
|
26163
26395
|
} from "fs";
|
|
26164
26396
|
import { createConnection } from "net";
|
|
26165
26397
|
import { createServer as createServer2 } from "http";
|
|
26166
|
-
import { basename as basename14, dirname as
|
|
26398
|
+
import { basename as basename14, dirname as dirname35, join as join57 } from "path";
|
|
26167
26399
|
import { execFile as execFile6, spawn as spawn12 } from "child_process";
|
|
26168
26400
|
|
|
26169
26401
|
// src/periscope-control.ts
|
|
@@ -26400,7 +26632,7 @@ function runCrew(args, onLine, timeoutMs = 20 * 6e4) {
|
|
|
26400
26632
|
// src/control-api.ts
|
|
26401
26633
|
var PAUSABLE = ["dev", "design", "qa"];
|
|
26402
26634
|
var CONTROL_SOCKET_NAME = "control.sock";
|
|
26403
|
-
var controlSocketFor = (stateDir) =>
|
|
26635
|
+
var controlSocketFor = (stateDir) => join57(stateDir, CONTROL_SOCKET_NAME);
|
|
26404
26636
|
var MAX_SOCKET_PATH = 100;
|
|
26405
26637
|
var MAX_TAIL_BYTES = 1024 * 1024;
|
|
26406
26638
|
var MAX_WAIT_SECONDS = 30;
|
|
@@ -26487,7 +26719,7 @@ function candidates(live, rotated) {
|
|
|
26487
26719
|
const out = [live];
|
|
26488
26720
|
if (!rotated) return out;
|
|
26489
26721
|
try {
|
|
26490
|
-
for (const n of readdirSync18(
|
|
26722
|
+
for (const n of readdirSync18(dirname35(live))) if (ROTATED_EVENTS_RE.test(n)) out.push(join57(dirname35(live), n));
|
|
26491
26723
|
} catch {
|
|
26492
26724
|
}
|
|
26493
26725
|
return out;
|
|
@@ -26531,7 +26763,7 @@ function lastLines2(path, n) {
|
|
|
26531
26763
|
}
|
|
26532
26764
|
function readTail(live, opts) {
|
|
26533
26765
|
const max = opts.maxBytes ?? MAX_TAIL_BYTES;
|
|
26534
|
-
if (!
|
|
26766
|
+
if (!existsSync55(live)) {
|
|
26535
26767
|
return { lines: [], cursor: opts.after ?? encodeCursor({ dev: 0, ino: 0, off: 0 }), reset: false };
|
|
26536
26768
|
}
|
|
26537
26769
|
const cur = opts.after ? decodeCursor(opts.after) : null;
|
|
@@ -26647,7 +26879,7 @@ async function tailReply(path, q2, rotated, abort) {
|
|
|
26647
26879
|
const deadline = Date.now() + Math.min(wait, MAX_WAIT_SECONDS) * 1e3;
|
|
26648
26880
|
let r = readTail(path, { after, tail: tail3, rotated });
|
|
26649
26881
|
while (after && !r.lines.length && !r.reset && Date.now() < deadline && !abort.aborted) {
|
|
26650
|
-
await waitForChange(
|
|
26882
|
+
await waitForChange(dirname35(path), deadline - Date.now(), abort);
|
|
26651
26883
|
r = readTail(path, { after: r.cursor, rotated });
|
|
26652
26884
|
}
|
|
26653
26885
|
return reply2(200, r);
|
|
@@ -26687,8 +26919,8 @@ async function route(deps, method, url, req, abort) {
|
|
|
26687
26919
|
if (p.startsWith("/streams/") && get2) {
|
|
26688
26920
|
const run4 = decodeURIComponent(p.slice("/streams/".length));
|
|
26689
26921
|
if (!RUN_NAME_RE.test(run4) || run4.includes("..") || /\.(pid|meta\.json|events\.jsonl)$/.test(run4)) return err2(400, "not a run name");
|
|
26690
|
-
const file =
|
|
26691
|
-
if (!
|
|
26922
|
+
const file = join57(deps.stateDir, "streams", run4.endsWith(".jsonl") ? run4 : `${run4}.jsonl`);
|
|
26923
|
+
if (!existsSync55(file)) return err2(404, "no such run");
|
|
26692
26924
|
return tailReply(file, url.searchParams, false, abort);
|
|
26693
26925
|
}
|
|
26694
26926
|
if ((p === "/pause" || p === "/resume") && post3) {
|
|
@@ -26718,7 +26950,7 @@ async function route(deps, method, url, req, abort) {
|
|
|
26718
26950
|
if (known.includes(p) || p.startsWith("/streams/") || sched) return err2(405, "method not allowed");
|
|
26719
26951
|
return err2(404, "not found");
|
|
26720
26952
|
}
|
|
26721
|
-
function
|
|
26953
|
+
function send2(res, r) {
|
|
26722
26954
|
if (r.stream) {
|
|
26723
26955
|
res.writeHead(200, { "Content-Type": "application/x-ndjson", "Cache-Control": "no-store" });
|
|
26724
26956
|
return r.stream((ev) => {
|
|
@@ -26733,7 +26965,7 @@ function send(res, r) {
|
|
|
26733
26965
|
res.end(body);
|
|
26734
26966
|
}
|
|
26735
26967
|
async function socketIsStale(path) {
|
|
26736
|
-
if (!
|
|
26968
|
+
if (!existsSync55(path)) return false;
|
|
26737
26969
|
return new Promise((resolve8) => {
|
|
26738
26970
|
const c = createConnection(path);
|
|
26739
26971
|
c.once("connect", () => {
|
|
@@ -26751,8 +26983,8 @@ async function startControlServer(deps) {
|
|
|
26751
26983
|
log(`control API not started: socket path is too long for a unix socket (${path})`);
|
|
26752
26984
|
return null;
|
|
26753
26985
|
}
|
|
26754
|
-
if (await socketIsStale(path))
|
|
26755
|
-
else if (
|
|
26986
|
+
if (await socketIsStale(path)) rmSync24(path, { force: true });
|
|
26987
|
+
else if (existsSync55(path)) {
|
|
26756
26988
|
log(`control API not started: ${path} is in use by another process`);
|
|
26757
26989
|
return null;
|
|
26758
26990
|
}
|
|
@@ -26763,21 +26995,21 @@ async function startControlServer(deps) {
|
|
|
26763
26995
|
try {
|
|
26764
26996
|
const mcp = /^\/periscopes\/([^/]+)\/mcp\/?$/.exec(new URL(req.url ?? "/", "http://ship").pathname);
|
|
26765
26997
|
if (mcp) {
|
|
26766
|
-
if (!deps.periscopeMcp) return
|
|
26998
|
+
if (!deps.periscopeMcp) return send2(res, err2(404, "not found"));
|
|
26767
26999
|
return await deps.periscopeMcp(req, res, decodeURIComponent(mcp[1]));
|
|
26768
27000
|
}
|
|
26769
27001
|
if (isPeriscopePath(new URL(req.url ?? "/", "http://ship").pathname.replace(/\/+$/, "") || "/")) {
|
|
26770
|
-
return await
|
|
27002
|
+
return await send2(res, await route(deps, req.method ?? "GET", new URL(req.url ?? "/", "http://ship"), req, abort.signal));
|
|
26771
27003
|
}
|
|
26772
27004
|
const m = /^Bearer (.+)$/.exec(req.headers.authorization ?? "");
|
|
26773
27005
|
const verdict = await deps.auth.verify(m?.[1]?.trim() ?? "");
|
|
26774
|
-
if (verdict === "unauthorized") return
|
|
26775
|
-
if (verdict === "forbidden") return
|
|
26776
|
-
if (verdict === "unavailable") return
|
|
26777
|
-
await
|
|
27006
|
+
if (verdict === "unauthorized") return send2(res, err2(401, "invalid or revoked key"));
|
|
27007
|
+
if (verdict === "forbidden") return send2(res, err2(403, "this key does not belong to a workspace this ship serves"));
|
|
27008
|
+
if (verdict === "unavailable") return send2(res, err2(503, "could not verify the key right now"));
|
|
27009
|
+
await send2(res, await route(deps, req.method ?? "GET", new URL(req.url ?? "/", "http://ship"), req, abort.signal));
|
|
26778
27010
|
} catch (e) {
|
|
26779
27011
|
log(`control API request failed: ${e.message}`);
|
|
26780
|
-
if (!res.headersSent)
|
|
27012
|
+
if (!res.headersSent) send2(res, err2(500, "internal error"));
|
|
26781
27013
|
else res.end();
|
|
26782
27014
|
}
|
|
26783
27015
|
})();
|
|
@@ -26798,7 +27030,7 @@ async function startControlServer(deps) {
|
|
|
26798
27030
|
path,
|
|
26799
27031
|
close: () => new Promise((done) => {
|
|
26800
27032
|
server.close(() => {
|
|
26801
|
-
|
|
27033
|
+
rmSync24(path, { force: true });
|
|
26802
27034
|
done();
|
|
26803
27035
|
});
|
|
26804
27036
|
})
|
|
@@ -26838,57 +27070,57 @@ function crewJson(args, timeoutMs = 6e4) {
|
|
|
26838
27070
|
|
|
26839
27071
|
// src/periscope-mcp.ts
|
|
26840
27072
|
import { lstat, mkdir, readdir, readFile, readlink, realpath, rm, stat, writeFile } from "fs/promises";
|
|
26841
|
-
import { basename as basename15, dirname as
|
|
27073
|
+
import { basename as basename15, dirname as dirname36, isAbsolute as isAbsolute5, join as join59, relative as relative2, resolve as resolve6, sep } from "path";
|
|
26842
27074
|
import { z } from "zod";
|
|
26843
27075
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
26844
27076
|
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
26845
27077
|
|
|
26846
27078
|
// src/periscope-endpoints.ts
|
|
26847
27079
|
import { randomBytes as randomBytes3 } from "crypto";
|
|
26848
|
-
import { chmodSync as chmodSync5, existsSync as
|
|
26849
|
-
import { join as
|
|
26850
|
-
var secretDir = (stateDir) =>
|
|
26851
|
-
var secretFile = (stateDir, id) =>
|
|
26852
|
-
var endpointDir = (stateDir) =>
|
|
26853
|
-
var endpointFile = (stateDir, id) =>
|
|
27080
|
+
import { chmodSync as chmodSync5, existsSync as existsSync56, mkdirSync as mkdirSync41, readdirSync as readdirSync19, readFileSync as readFileSync51, rmSync as rmSync25, writeFileSync as writeFileSync41 } from "fs";
|
|
27081
|
+
import { join as join58 } from "path";
|
|
27082
|
+
var secretDir = (stateDir) => join58(stateDir, "periscope-mcp");
|
|
27083
|
+
var secretFile = (stateDir, id) => join58(secretDir(stateDir), `${id}.json`);
|
|
27084
|
+
var endpointDir = (stateDir) => join58(stateDir, "periscope-endpoints");
|
|
27085
|
+
var endpointFile = (stateDir, id) => join58(endpointDir(stateDir), `${id}.json`);
|
|
26854
27086
|
function mintPeriscopeSecret(stateDir, ticketRecordId) {
|
|
26855
|
-
|
|
27087
|
+
mkdirSync41(secretDir(stateDir), { recursive: true, mode: 448 });
|
|
26856
27088
|
const secret = randomBytes3(32).toString("base64url");
|
|
26857
27089
|
const file = secretFile(stateDir, ticketRecordId);
|
|
26858
|
-
|
|
27090
|
+
writeFileSync41(file, `${JSON.stringify({ secret })}
|
|
26859
27091
|
`, { mode: 384 });
|
|
26860
27092
|
chmodSync5(file, 384);
|
|
26861
27093
|
return secret;
|
|
26862
27094
|
}
|
|
26863
27095
|
function readPeriscopeSecret(stateDir, ticketRecordId) {
|
|
26864
27096
|
try {
|
|
26865
|
-
const v = JSON.parse(
|
|
27097
|
+
const v = JSON.parse(readFileSync51(secretFile(stateDir, ticketRecordId), "utf8"));
|
|
26866
27098
|
return typeof v.secret === "string" && v.secret ? v.secret : void 0;
|
|
26867
27099
|
} catch {
|
|
26868
27100
|
return void 0;
|
|
26869
27101
|
}
|
|
26870
27102
|
}
|
|
26871
27103
|
function removePeriscopeSecret(stateDir, ticketRecordId) {
|
|
26872
|
-
|
|
27104
|
+
rmSync25(secretFile(stateDir, ticketRecordId), { force: true });
|
|
26873
27105
|
}
|
|
26874
27106
|
function readPeriscopeEndpoint(stateDir, ticketRecordId) {
|
|
26875
27107
|
try {
|
|
26876
|
-
return JSON.parse(
|
|
27108
|
+
return JSON.parse(readFileSync51(endpointFile(stateDir, ticketRecordId), "utf8"));
|
|
26877
27109
|
} catch {
|
|
26878
27110
|
return void 0;
|
|
26879
27111
|
}
|
|
26880
27112
|
}
|
|
26881
27113
|
function writePeriscopeEndpoint(stateDir, rec) {
|
|
26882
|
-
|
|
26883
|
-
|
|
27114
|
+
mkdirSync41(endpointDir(stateDir), { recursive: true });
|
|
27115
|
+
writeFileSync41(endpointFile(stateDir, rec.ticketRecordId), `${JSON.stringify(rec, null, 2)}
|
|
26884
27116
|
`);
|
|
26885
27117
|
}
|
|
26886
27118
|
function removePeriscopeEndpointRecord(stateDir, ticketRecordId) {
|
|
26887
|
-
|
|
27119
|
+
rmSync25(endpointFile(stateDir, ticketRecordId), { force: true });
|
|
26888
27120
|
}
|
|
26889
27121
|
function listPeriscopeEndpoints(stateDir) {
|
|
26890
27122
|
const dir = endpointDir(stateDir);
|
|
26891
|
-
if (!
|
|
27123
|
+
if (!existsSync56(dir)) return [];
|
|
26892
27124
|
const out = [];
|
|
26893
27125
|
for (const name of readdirSync19(dir)) {
|
|
26894
27126
|
if (!name.endsWith(".json")) continue;
|
|
@@ -26976,10 +27208,10 @@ async function realAncestor(p) {
|
|
|
26976
27208
|
}
|
|
26977
27209
|
if (isLink) {
|
|
26978
27210
|
if (++hops > 40) throw new PathRefusal(`too many symbolic links resolving ${p}`);
|
|
26979
|
-
cur = resolve6(
|
|
27211
|
+
cur = resolve6(dirname36(cur), await readlink(cur));
|
|
26980
27212
|
continue;
|
|
26981
27213
|
}
|
|
26982
|
-
const parent =
|
|
27214
|
+
const parent = dirname36(cur);
|
|
26983
27215
|
if (parent === cur) throw new PathRefusal(`cannot resolve ${p}`);
|
|
26984
27216
|
tail3.push(basename15(cur));
|
|
26985
27217
|
cur = parent;
|
|
@@ -26991,13 +27223,13 @@ async function resolveInWorktree(root, requested) {
|
|
|
26991
27223
|
let abs;
|
|
26992
27224
|
if (isAbsolute5(requested)) {
|
|
26993
27225
|
abs = resolve6(requested);
|
|
26994
|
-
if (isInside(root, abs)) abs =
|
|
27226
|
+
if (isInside(root, abs)) abs = join59(realRoot, relative2(root, abs));
|
|
26995
27227
|
} else {
|
|
26996
27228
|
abs = resolve6(realRoot, requested);
|
|
26997
27229
|
}
|
|
26998
27230
|
if (!isInside(realRoot, abs)) throw new PathRefusal(`${requested} is outside this periscope's worktree`);
|
|
26999
27231
|
const { real, rest } = await realAncestor(abs);
|
|
27000
|
-
const final = rest ?
|
|
27232
|
+
const final = rest ? join59(real, rest) : real;
|
|
27001
27233
|
if (!isInside(realRoot, final)) throw new PathRefusal(`${requested} is outside this periscope's worktree`);
|
|
27002
27234
|
if (relative2(realRoot, final).split(sep).includes(".git")) throw new PathRefusal(".git is not reachable from a periscope");
|
|
27003
27235
|
return final;
|
|
@@ -27065,7 +27297,7 @@ function createPeriscopeMcpServer(d, sc) {
|
|
|
27065
27297
|
const entries = (await readdir(abs, { withFileTypes: true })).filter((e) => e.name !== ".git");
|
|
27066
27298
|
const lines2 = await Promise.all(entries.map(async (e) => {
|
|
27067
27299
|
if (e.isDirectory()) return `[DIR] ${e.name}`;
|
|
27068
|
-
const size = (await lstat(
|
|
27300
|
+
const size = (await lstat(join59(abs, e.name))).size;
|
|
27069
27301
|
return `[FILE] ${e.name} (${size} bytes)`;
|
|
27070
27302
|
}));
|
|
27071
27303
|
return text(lines2.join("\n") || "(empty)");
|
|
@@ -27090,7 +27322,7 @@ function createPeriscopeMcpServer(d, sc) {
|
|
|
27090
27322
|
if (Buffer.byteLength(content) > MAX_WRITE_BYTES) return text(`content exceeds ${MAX_WRITE_BYTES} bytes`, true);
|
|
27091
27323
|
const abs = await inTree(path);
|
|
27092
27324
|
if (abs === await realpath(root)) return text("path must name a file", true);
|
|
27093
|
-
await mkdir(
|
|
27325
|
+
await mkdir(dirname36(abs), { recursive: true });
|
|
27094
27326
|
await inTree(path);
|
|
27095
27327
|
await writeFile(abs, content);
|
|
27096
27328
|
return text(`Wrote ${Buffer.byteLength(content)} bytes to ${await rel(abs)}`);
|
|
@@ -27130,8 +27362,8 @@ function createPeriscopeMcpServer(d, sc) {
|
|
|
27130
27362
|
inputSchema: { path: z.string() },
|
|
27131
27363
|
annotations: { readOnlyHint: false, destructiveHint: true, openWorldHint: false }
|
|
27132
27364
|
}, async ({ path }) => {
|
|
27133
|
-
const parent = await inTree(
|
|
27134
|
-
const abs =
|
|
27365
|
+
const parent = await inTree(dirname36(path) === "" ? "." : dirname36(path));
|
|
27366
|
+
const abs = join59(parent, basename15(path));
|
|
27135
27367
|
if (basename15(path) === ".git" || abs === parent) return text("path must name a file", true);
|
|
27136
27368
|
const st = await lstat(abs).catch(() => void 0);
|
|
27137
27369
|
if (!st) return text(`${path} does not exist`, true);
|
|
@@ -27252,7 +27484,7 @@ function findPeriscope(sidecars, segment) {
|
|
|
27252
27484
|
}
|
|
27253
27485
|
|
|
27254
27486
|
// src/cli.ts
|
|
27255
|
-
var CREW_HOME = isCompiledBinary(import.meta.url) ?
|
|
27487
|
+
var CREW_HOME = isCompiledBinary(import.meta.url) ? dirname37(process.execPath) : resolve7(dirname37(fileURLToPath2(import.meta.url)), "..");
|
|
27256
27488
|
var RELEASE_LOCK_TTL_MS = 20 * 60 * 1e3;
|
|
27257
27489
|
var CYCLE_SECONDS2 = 120;
|
|
27258
27490
|
var STALE_CYCLES = 3;
|
|
@@ -27622,7 +27854,7 @@ if (command === "provision") {
|
|
|
27622
27854
|
process.exit(outcome.code);
|
|
27623
27855
|
}
|
|
27624
27856
|
if (command === "pool-member") {
|
|
27625
|
-
const pool = poolConfigFrom(argv, process.env, () =>
|
|
27857
|
+
const pool = poolConfigFrom(argv, process.env, () => readFileSync52(0, "utf8"));
|
|
27626
27858
|
if (typeof pool === "string") {
|
|
27627
27859
|
process.stderr.write(`crew pool-member: ${pool}
|
|
27628
27860
|
`);
|
|
@@ -27943,7 +28175,7 @@ if (command === "passenger-sync-daemon") {
|
|
|
27943
28175
|
} else {
|
|
27944
28176
|
const toleratesNoRoutes = command === "credential" || command === "forge" || command === "repos" || command === "ship" || command === "disconnect" && flag("reset") || command === "deprovision" || command === "connect" && flag("sign-out");
|
|
27945
28177
|
const configless = command === "connect" && flag("sign-out") || command === "disconnect" && flag("reset") || command === "deprovision";
|
|
27946
|
-
if (configless && !
|
|
28178
|
+
if (configless && !existsSync57(findConfigFile(CREW_HOME))) {
|
|
27947
28179
|
cfg = loadConfig(CREW_HOME, firstRunConfigPath(), { text: "ship: {}\n", allowNoRoutes: true });
|
|
27948
28180
|
} else {
|
|
27949
28181
|
cfg = loadConfig(CREW_HOME, void 0, toleratesNoRoutes ? { allowNoRoutes: true } : {});
|
|
@@ -27966,7 +28198,7 @@ if (command === "passenger-sync-daemon") {
|
|
|
27966
28198
|
throw e;
|
|
27967
28199
|
}
|
|
27968
28200
|
if (command === "credential") {
|
|
27969
|
-
const r = runCredential(positional[1],
|
|
28201
|
+
const r = runCredential(positional[1], readFileSync52(0, "utf8"), cfg.ship.forges, cfg.ship.stateDir, process.env, !flag("no-miss"));
|
|
27970
28202
|
process.stdout.write(r.out);
|
|
27971
28203
|
process.stderr.write(r.err);
|
|
27972
28204
|
process.exit(r.code);
|
|
@@ -27978,9 +28210,9 @@ if (command === "passenger-sync-daemon") {
|
|
|
27978
28210
|
forges: cfg.ship.forges,
|
|
27979
28211
|
stateDir: cfg.ship.stateDir,
|
|
27980
28212
|
configFile: cfg.configFile,
|
|
27981
|
-
readFile: (p) =>
|
|
27982
|
-
writeFile: (p, t) =>
|
|
27983
|
-
stdin: () =>
|
|
28213
|
+
readFile: (p) => readFileSync52(p, "utf8"),
|
|
28214
|
+
writeFile: (p, t) => writeFileSync42(p, t),
|
|
28215
|
+
stdin: () => readFileSync52(0, "utf8"),
|
|
27984
28216
|
env: process.env
|
|
27985
28217
|
}
|
|
27986
28218
|
);
|
|
@@ -28314,8 +28546,8 @@ if (command === "passenger-sync-daemon") {
|
|
|
28314
28546
|
}
|
|
28315
28547
|
if (host === "linux" && hasSystemd) {
|
|
28316
28548
|
const label = labelFor(CREW_HOME, "run");
|
|
28317
|
-
const staleTimer =
|
|
28318
|
-
if (
|
|
28549
|
+
const staleTimer = join60(homedir11(), ".config", "systemd", "user", `${label}.timer`);
|
|
28550
|
+
if (existsSync57(staleTimer)) {
|
|
28319
28551
|
process.stdout.write(
|
|
28320
28552
|
`removing stale run timer from before the persistent-service cutover: ${staleTimer}${dryRun ? " (dry run)" : ""}
|
|
28321
28553
|
`
|
|
@@ -28344,7 +28576,7 @@ if (command === "passenger-sync-daemon") {
|
|
|
28344
28576
|
const { settled: doctorRepos, errors: refusedRepos } = await settleRepos(reposOf(c), (t) => t.name, (t) => resolveOneRepo(c, t));
|
|
28345
28577
|
for (const e of refusedRepos) problems.push(`repo ${e.repo}: ${e.detail}`);
|
|
28346
28578
|
for (const r of doctorRepos) {
|
|
28347
|
-
if (!
|
|
28579
|
+
if (!existsSync57(r.dir)) problems.push(`repo ${r.name}: ${r.dir} is missing on disk`);
|
|
28348
28580
|
if (!satisfies(host, r.config.platform)) problems.push(`repo ${r.name}: requires ${r.config.platform}, this host is ${host}`);
|
|
28349
28581
|
readiness.push(...validateEffective(r.config).map((p) => `repo ${r.name}: ${p}`));
|
|
28350
28582
|
}
|
|
@@ -28379,7 +28611,7 @@ if (command === "passenger-sync-daemon") {
|
|
|
28379
28611
|
}
|
|
28380
28612
|
async function doctorFix(o) {
|
|
28381
28613
|
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))));
|
|
28382
|
-
const unitExists = (p) =>
|
|
28614
|
+
const unitExists = (p) => existsSync57(p);
|
|
28383
28615
|
const crontab = o.host === "linux" ? spawnSync13("crontab", ["-l"], { encoding: "utf8" }).stdout ?? "" : "";
|
|
28384
28616
|
const schedulerAbsent = o.host !== "windows" ? !schedulerInstalled(planInstall(cfg.ship, CREW_HOME, o.host, detectSystemd(), "run", installContext()), unitExists, crontab) : true;
|
|
28385
28617
|
const plan = planFix({ routes, schedulerAbsent, host: o.host });
|
|
@@ -28396,7 +28628,7 @@ if (command === "passenger-sync-daemon") {
|
|
|
28396
28628
|
for (const a of plan.actions) {
|
|
28397
28629
|
if (a.kind === "enable") {
|
|
28398
28630
|
if (prompter && !await prompter.confirm(`Route ${a.route} passes every check \u2014 set enabled: true in ${cfg.configFile}?`, false)) continue;
|
|
28399
|
-
|
|
28631
|
+
writeFileSync42(cfg.configFile, planEnable(readFileSync52(cfg.configFile, "utf8"), a.route));
|
|
28400
28632
|
enabledSound.add(a.route);
|
|
28401
28633
|
changed2.push(`enabled route ${a.route} in ${cfg.configFile}`);
|
|
28402
28634
|
} else {
|
|
@@ -28625,7 +28857,7 @@ ${changed2.map((c) => ` - ${c}
|
|
|
28625
28857
|
harnessBin: "claude",
|
|
28626
28858
|
...contract.sandboxNetwork ? { extraHosts: contract.sandboxNetwork.hosts, toolchains: contract.sandboxNetwork.toolchains } : {}
|
|
28627
28859
|
},
|
|
28628
|
-
policyFile:
|
|
28860
|
+
policyFile: join60(cfg.ship.stateDir, "release", `${target.name}.policy.yaml`),
|
|
28629
28861
|
repo: mirror,
|
|
28630
28862
|
origin: forgeDescriptorFor(forgeHost).httpsUrl(mirror.host, mirror.path),
|
|
28631
28863
|
base: effective.branch.base,
|
|
@@ -29827,7 +30059,7 @@ ${cu.tail.trimEnd()}
|
|
|
29827
30059
|
logFile: cfg.ship.logFile
|
|
29828
30060
|
});
|
|
29829
30061
|
}
|
|
29830
|
-
const watchPaths = isCompiledBinary(import.meta.url) ? [process.execPath] : [
|
|
30062
|
+
const watchPaths = isCompiledBinary(import.meta.url) ? [process.execPath] : [join60(CREW_HOME, "src"), join60(CREW_HOME, "dist"), join60(CREW_HOME, "bin")];
|
|
29831
30063
|
const configPaths = daemonConfigPaths(cfg);
|
|
29832
30064
|
watchPaths.push(...configPaths);
|
|
29833
30065
|
noteDaemonStarted(cfg.ship.stateDir);
|
|
@@ -30145,10 +30377,10 @@ ${cu.tail.trimEnd()}
|
|
|
30145
30377
|
`);
|
|
30146
30378
|
if (!dryRun) {
|
|
30147
30379
|
const resolvedPath = resolvedPathFor(cfg.ship.stateDir, target.route);
|
|
30148
|
-
const raw =
|
|
30380
|
+
const raw = existsSync57(resolvedPath) ? JSON.parse(readFileSync52(resolvedPath, "utf8")) : {};
|
|
30149
30381
|
raw.agentSkills = result.agentSkills;
|
|
30150
|
-
|
|
30151
|
-
|
|
30382
|
+
mkdirSync42(dirOf2(resolvedPath), { recursive: true });
|
|
30383
|
+
writeFileSync42(resolvedPath, `${JSON.stringify(raw, null, 2)}
|
|
30152
30384
|
`);
|
|
30153
30385
|
}
|
|
30154
30386
|
if (result.outcomes.some((o) => o.action === "diverged")) process.exitCode = 1;
|
|
@@ -30171,7 +30403,7 @@ ${cu.tail.trimEnd()}
|
|
|
30171
30403
|
throw e;
|
|
30172
30404
|
}
|
|
30173
30405
|
const oldName = cfg.ship.name;
|
|
30174
|
-
|
|
30406
|
+
writeFileSync42(cfg.configFile, setShipNameInYaml(readFileSync52(cfg.configFile, "utf8"), newName));
|
|
30175
30407
|
cfg.ship.name = newName;
|
|
30176
30408
|
let renameMachineId;
|
|
30177
30409
|
try {
|
|
@@ -30218,14 +30450,14 @@ ${cu.tail.trimEnd()}
|
|
|
30218
30450
|
process.exit(2);
|
|
30219
30451
|
};
|
|
30220
30452
|
if (sub !== "add" && sub !== "list" && sub !== "clone" && sub !== "hooks" && sub !== "check") usage2();
|
|
30221
|
-
const configText =
|
|
30453
|
+
const configText = readFileSync52(cfg.configFile, "utf8");
|
|
30222
30454
|
if (sub === "check") {
|
|
30223
30455
|
try {
|
|
30224
30456
|
const routeArg = value("route") ?? positional[2];
|
|
30225
30457
|
const found = cfg.routes.find((r) => r.route === routeArg);
|
|
30226
30458
|
if (!found) throw new ReposError(`no route "${routeArg}" in the config (have: ${cfg.routes.map((r) => r.route).join(", ") || "none"})`);
|
|
30227
30459
|
const named2 = value("route") ? void 0 : positional[3];
|
|
30228
|
-
const dir = named2 ? repoDirOf(configText,
|
|
30460
|
+
const dir = named2 ? repoDirOf(configText, dirname37(cfg.configFile), found.route, named2) : resolvePath(positional[value("route") ? 2 : 3] ?? ".");
|
|
30229
30461
|
const target = reposOf(found).find((t) => resolvePath(t.dir) === dir || t.name === named2);
|
|
30230
30462
|
const o = target ? found.repoOverrides[target.name] : void 0;
|
|
30231
30463
|
runReposCheck(dir, {
|
|
@@ -30249,9 +30481,9 @@ ${cu.tail.trimEnd()}
|
|
|
30249
30481
|
if (sub === "hooks") {
|
|
30250
30482
|
try {
|
|
30251
30483
|
const a = parseHooksArgs(positional.slice(2), routeNamesOf(configText));
|
|
30252
|
-
const dir = repoDirOf(configText,
|
|
30253
|
-
if (!
|
|
30254
|
-
const files = { exists: (r) =>
|
|
30484
|
+
const dir = repoDirOf(configText, dirname37(cfg.configFile), a.route, a.name);
|
|
30485
|
+
if (!existsSync57(dir)) throw new ReposError(`${dir} does not exist on disk`);
|
|
30486
|
+
const files = { exists: (r) => existsSync57(resolvePath(dir, r)), list: (r) => {
|
|
30255
30487
|
try {
|
|
30256
30488
|
return readdirSync20(resolvePath(dir, r));
|
|
30257
30489
|
} catch {
|
|
@@ -30259,7 +30491,7 @@ ${cu.tail.trimEnd()}
|
|
|
30259
30491
|
}
|
|
30260
30492
|
}, read: (r) => {
|
|
30261
30493
|
try {
|
|
30262
|
-
return
|
|
30494
|
+
return readFileSync52(resolvePath(dir, r), "utf8");
|
|
30263
30495
|
} catch {
|
|
30264
30496
|
return void 0;
|
|
30265
30497
|
}
|
|
@@ -30301,19 +30533,19 @@ ${cu.tail.trimEnd()}
|
|
|
30301
30533
|
let cleared;
|
|
30302
30534
|
if (clear2) {
|
|
30303
30535
|
const plan = clearRouteHooks(configText, a.route, a.name);
|
|
30304
|
-
if (plan.removed.length > 0)
|
|
30536
|
+
if (plan.removed.length > 0) writeFileSync42(cfg.configFile, plan.text);
|
|
30305
30537
|
cleared = { file: cfg.configFile, removed: plan.removed };
|
|
30306
30538
|
}
|
|
30307
30539
|
if (write && suggestion.source === null && recipeIds.length === 0 && hookSpecs.length === 0) throw new ReposError(`nothing to write: ${suggestion.notes[0]}`);
|
|
30308
30540
|
if (write === "route") {
|
|
30309
30541
|
const plan = planRouteHooks(configText, a.route, a.name, picked.hooks, { replace: flag("replace") });
|
|
30310
|
-
|
|
30542
|
+
writeFileSync42(cfg.configFile, plan.text);
|
|
30311
30543
|
written = { target: "route", file: cfg.configFile, hooks: plan.written, kept: plan.kept, replaced: plan.replaced };
|
|
30312
30544
|
} else if (write === "repo") {
|
|
30313
30545
|
const have = existingRepoConfig(files);
|
|
30314
30546
|
if (have) throw new ReposError(`${resolvePath(dir, have)} already exists; not overwriting it`);
|
|
30315
30547
|
const file = resolvePath(dir, ".crew.yaml");
|
|
30316
|
-
|
|
30548
|
+
writeFileSync42(file, starterRepoConfig(picked.hooks, picked.release), { flag: "wx" });
|
|
30317
30549
|
written = { target: "repo", file, hooks: Object.keys(picked.hooks), kept: [], replaced: [] };
|
|
30318
30550
|
}
|
|
30319
30551
|
if (flag("json")) {
|
|
@@ -30369,7 +30601,7 @@ ${cu.tail.trimEnd()}
|
|
|
30369
30601
|
if (sub === "list" && !routeName) usage2();
|
|
30370
30602
|
if (sub === "add") {
|
|
30371
30603
|
try {
|
|
30372
|
-
const a = parseAddArgs(positional.slice(2), routeNamesOf(configText), (p) =>
|
|
30604
|
+
const a = parseAddArgs(positional.slice(2), routeNamesOf(configText), (p) => existsSync57(resolvePath(p.replace(/^~(?=\/|$)/, homedir11()))));
|
|
30373
30605
|
routeName = a.route;
|
|
30374
30606
|
addPath = a.path;
|
|
30375
30607
|
addName = a.name;
|
|
@@ -30399,7 +30631,7 @@ ${cu.tail.trimEnd()}
|
|
|
30399
30631
|
const resolvedFile = resolvedPathFor(cfg.ship.stateDir, routeName);
|
|
30400
30632
|
if (sub === "list" || sub === "add") {
|
|
30401
30633
|
const liveRoute = cfg.routes.find((r) => r.route === routeName);
|
|
30402
|
-
if (liveRoute?.resolved?.reposModelId &&
|
|
30634
|
+
if (liveRoute?.resolved?.reposModelId && existsSync57(resolvedFile) && !dryRun) {
|
|
30403
30635
|
try {
|
|
30404
30636
|
await hydrateApiKeys([liveRoute]);
|
|
30405
30637
|
persistRepoRows(cfg.ship.stateDir, liveRoute.route, await new Tracker(liveRoute, cfg.ship).repoRowsForMap());
|
|
@@ -30408,16 +30640,16 @@ ${cu.tail.trimEnd()}
|
|
|
30408
30640
|
}
|
|
30409
30641
|
}
|
|
30410
30642
|
let resolvedRemotes;
|
|
30411
|
-
if (
|
|
30643
|
+
if (existsSync57(resolvedFile)) {
|
|
30412
30644
|
try {
|
|
30413
|
-
resolvedRemotes = JSON.parse(
|
|
30645
|
+
resolvedRemotes = JSON.parse(readFileSync52(resolvedFile, "utf8"));
|
|
30414
30646
|
} catch {
|
|
30415
30647
|
}
|
|
30416
30648
|
}
|
|
30417
30649
|
const originOf = (dir) => gitOk(dir, ["remote", "get-url", "origin"]) ?? void 0;
|
|
30418
30650
|
const text2 = configText;
|
|
30419
|
-
const base =
|
|
30420
|
-
const isCheckout = (d) =>
|
|
30651
|
+
const base = dirname37(cfg.configFile);
|
|
30652
|
+
const isCheckout = (d) => existsSync57(`${d}/.git`);
|
|
30421
30653
|
try {
|
|
30422
30654
|
if (sub === "list") {
|
|
30423
30655
|
if (flag("json")) {
|
|
@@ -30427,12 +30659,12 @@ ${cu.tail.trimEnd()}
|
|
|
30427
30659
|
base,
|
|
30428
30660
|
resolved: resolvedRemotes,
|
|
30429
30661
|
originOf,
|
|
30430
|
-
exists: (d) =>
|
|
30662
|
+
exists: (d) => existsSync57(d),
|
|
30431
30663
|
isCheckout,
|
|
30432
30664
|
repoHasHooks: (d) => REPO_CONFIG_FILENAMES.some((f) => {
|
|
30433
30665
|
try {
|
|
30434
30666
|
const path = resolvePath(d, f);
|
|
30435
|
-
return Object.keys(parseRepoConfig(
|
|
30667
|
+
return Object.keys(parseRepoConfig(readFileSync52(path, "utf8"), path).hooks).length > 0;
|
|
30436
30668
|
} catch {
|
|
30437
30669
|
return false;
|
|
30438
30670
|
}
|
|
@@ -30449,7 +30681,7 @@ ${cu.tail.trimEnd()}
|
|
|
30449
30681
|
for (const r of repos) {
|
|
30450
30682
|
const origin2 = originOf(r.dir);
|
|
30451
30683
|
const row = matchRepoName(origin2, resolvedRemotes);
|
|
30452
|
-
const note = !
|
|
30684
|
+
const note = !existsSync57(r.dir) ? "missing on disk" : row ? `Repos row: ${row}` : `no Repos row matches ${normalizeRemote2(origin2) ?? "this checkout (no origin remote)"}`;
|
|
30453
30685
|
process.stdout.write(`${r.name} ${r.dir} ${note}
|
|
30454
30686
|
`);
|
|
30455
30687
|
}
|
|
@@ -30461,9 +30693,9 @@ ${cu.tail.trimEnd()}
|
|
|
30461
30693
|
` : `${human}
|
|
30462
30694
|
`);
|
|
30463
30695
|
const plan2 = planRepoClone({ text: text2, base, route: routeName, name: addName, resolved: resolvedRemotes, dir: value("dir"), isCheckout });
|
|
30464
|
-
if (
|
|
30696
|
+
if (existsSync57(plan2.target) && (existsSync57(`${plan2.target}/.git`) || readdirSync20(plan2.target).length > 0)) {
|
|
30465
30697
|
throw new ReposError(
|
|
30466
|
-
|
|
30698
|
+
existsSync57(`${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`
|
|
30467
30699
|
);
|
|
30468
30700
|
}
|
|
30469
30701
|
if (dryRun) {
|
|
@@ -30481,14 +30713,14 @@ ${cu.tail.trimEnd()}
|
|
|
30481
30713
|
throw new ReposError(`${e.message}${authHint}
|
|
30482
30714
|
crew.yaml was not changed`);
|
|
30483
30715
|
}
|
|
30484
|
-
|
|
30716
|
+
writeFileSync42(cfg.configFile, plan2.text);
|
|
30485
30717
|
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:
|
|
30486
30718
|
`);
|
|
30487
30719
|
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}`);
|
|
30488
30720
|
break;
|
|
30489
30721
|
}
|
|
30490
30722
|
const target = resolvePath(addPath.replace(/^~(?=\/|$)/, homedir11()));
|
|
30491
|
-
const top =
|
|
30723
|
+
const top = existsSync57(target) ? gitOk(target, ["rev-parse", "--show-toplevel"]) : null;
|
|
30492
30724
|
if (!top) throw new ReposError(`${target} is not a git checkout`);
|
|
30493
30725
|
const origin = originOf(top);
|
|
30494
30726
|
const plan = planRepoAdd({
|
|
@@ -30540,15 +30772,15 @@ ${cu.tail.trimEnd()}
|
|
|
30540
30772
|
const created = await rowTracker.createRepoRow(rowPayload);
|
|
30541
30773
|
process.stdout.write(`created Repos row ${String(rowPayload.name)} (${String(rowPayload.remote)}) ${created.id}
|
|
30542
30774
|
`);
|
|
30543
|
-
if (
|
|
30544
|
-
const raw = JSON.parse(
|
|
30775
|
+
if (existsSync57(resolvedFile)) {
|
|
30776
|
+
const raw = JSON.parse(readFileSync52(resolvedFile, "utf8"));
|
|
30545
30777
|
raw.repoNames = { ...raw.repoNames, [created.id]: String(rowPayload.name) };
|
|
30546
30778
|
raw.repoRemotes = { ...raw.repoRemotes, [created.id]: String(rowPayload.remote) };
|
|
30547
|
-
|
|
30779
|
+
writeFileSync42(resolvedFile, `${JSON.stringify(raw, null, 2)}
|
|
30548
30780
|
`);
|
|
30549
30781
|
}
|
|
30550
30782
|
}
|
|
30551
|
-
|
|
30783
|
+
writeFileSync42(cfg.configFile, plan.text);
|
|
30552
30784
|
process.stdout.write(`added ${top} to ${routeName} as ${plan.mode === "dir" ? "dir" : `repos.${plan.name}`} in ${cfg.configFile}
|
|
30553
30785
|
`);
|
|
30554
30786
|
} catch (e) {
|
|
@@ -30923,7 +31155,7 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
|
|
|
30923
31155
|
process.exit(2);
|
|
30924
31156
|
}
|
|
30925
31157
|
if (found.shipNameAdopted && !dryRun) {
|
|
30926
|
-
|
|
31158
|
+
writeFileSync42(cfg.configFile, setShipNameInYaml(readFileSync52(cfg.configFile, "utf8"), found.shipNameAdopted));
|
|
30927
31159
|
cfg.ship.name = found.shipNameAdopted;
|
|
30928
31160
|
}
|
|
30929
31161
|
if (found.shipRow) {
|
|
@@ -30966,10 +31198,10 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
|
|
|
30966
31198
|
}
|
|
30967
31199
|
}
|
|
30968
31200
|
let previous;
|
|
30969
|
-
const hadPreviousFile =
|
|
31201
|
+
const hadPreviousFile = existsSync57(resolvedPath);
|
|
30970
31202
|
if (hadPreviousFile) {
|
|
30971
31203
|
try {
|
|
30972
|
-
previous = JSON.parse(
|
|
31204
|
+
previous = JSON.parse(readFileSync52(resolvedPath, "utf8"));
|
|
30973
31205
|
} catch {
|
|
30974
31206
|
}
|
|
30975
31207
|
}
|
|
@@ -31099,12 +31331,12 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
|
|
|
31099
31331
|
process.stderr.write(`(dry run) would write resolved ids to ${resolvedPath}
|
|
31100
31332
|
`);
|
|
31101
31333
|
} else {
|
|
31102
|
-
|
|
31334
|
+
mkdirSync42(dirname37(resolvedPath), { recursive: true });
|
|
31103
31335
|
if (hadPreviousFile) copyFileSync2(resolvedPath, `${resolvedPath}.bak`);
|
|
31104
31336
|
const tmpPath = `${resolvedPath}.tmp${process.pid}`;
|
|
31105
|
-
|
|
31337
|
+
writeFileSync42(tmpPath, `${JSON.stringify(resolved, null, 2)}
|
|
31106
31338
|
`);
|
|
31107
|
-
|
|
31339
|
+
renameSync8(tmpPath, resolvedPath);
|
|
31108
31340
|
process.stderr.write(`Resolved ids written to ${resolvedPath}
|
|
31109
31341
|
`);
|
|
31110
31342
|
}
|
|
@@ -31148,8 +31380,8 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
|
|
|
31148
31380
|
process.stderr.write(`(dry run) would write the minted API key to ${apiKeyFile}
|
|
31149
31381
|
`);
|
|
31150
31382
|
} else {
|
|
31151
|
-
|
|
31152
|
-
|
|
31383
|
+
mkdirSync42(dirname37(apiKeyFile), { recursive: true });
|
|
31384
|
+
writeFileSync42(apiKeyFile, `${apiKeyVar}=${apiKey}
|
|
31153
31385
|
`, { mode: 384 });
|
|
31154
31386
|
process.stderr.write(`API key written to ${apiKeyFile}
|
|
31155
31387
|
`);
|
|
@@ -31864,10 +32096,10 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
|
|
|
31864
32096
|
startupSeconds: cfg.ship.intelStartupSeconds,
|
|
31865
32097
|
prepare: async (path) => {
|
|
31866
32098
|
for (const f of repoWt.config.worktrees.copy) {
|
|
31867
|
-
const src =
|
|
31868
|
-
if (!
|
|
31869
|
-
|
|
31870
|
-
copyFileSync2(src,
|
|
32099
|
+
const src = join60(repoWt.dir, f);
|
|
32100
|
+
if (!existsSync57(src) || existsSync57(join60(path, f))) continue;
|
|
32101
|
+
mkdirSync42(dirOf2(join60(path, f)), { recursive: true });
|
|
32102
|
+
copyFileSync2(src, join60(path, f));
|
|
31871
32103
|
}
|
|
31872
32104
|
const setup = repoWt.config.hooks.setup;
|
|
31873
32105
|
return setup ? runScript(setup, { cwd: path, shell: shellWt }) : null;
|
|
@@ -32093,7 +32325,7 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
|
|
|
32093
32325
|
const shellR = hit && resolveShell(hit.repo.config.shell ?? cfg.ship.shell);
|
|
32094
32326
|
const resumed = await runPeriscopeResume({
|
|
32095
32327
|
find: async () => hit && { row: hit.row, tag: hit.tag },
|
|
32096
|
-
worktreeExists: (p) =>
|
|
32328
|
+
worktreeExists: (p) => existsSync57(p),
|
|
32097
32329
|
prepareDropFile,
|
|
32098
32330
|
startProxy: (wt, url, n) => launchProxy(crewInvocation(CREW_HOME), wt, url, Number(n), { host: hit.row.host || "localhost", inject: hit.repo.config.periscope?.inspector !== "repo" }),
|
|
32099
32331
|
relay: hit && previewRelayFor(hit.route) && {
|
|
@@ -32196,10 +32428,10 @@ ${where.join("\n")}`);
|
|
|
32196
32428
|
},
|
|
32197
32429
|
prepare: async (path) => {
|
|
32198
32430
|
for (const f of repoP.config.worktrees.copy) {
|
|
32199
|
-
const src =
|
|
32200
|
-
if (!
|
|
32201
|
-
|
|
32202
|
-
copyFileSync2(src,
|
|
32431
|
+
const src = join60(repoP.dir, f);
|
|
32432
|
+
if (!existsSync57(src)) continue;
|
|
32433
|
+
mkdirSync42(dirOf2(join60(path, f)), { recursive: true });
|
|
32434
|
+
copyFileSync2(src, join60(path, f));
|
|
32203
32435
|
}
|
|
32204
32436
|
const setup = repoP.config.hooks.setup;
|
|
32205
32437
|
return setup ? runScript(setup, { cwd: path, shell: shellP, onLine: (l) => {
|
|
@@ -32511,7 +32743,7 @@ ${where.join("\n")}`);
|
|
|
32511
32743
|
};
|
|
32512
32744
|
const droppedRoutes = [];
|
|
32513
32745
|
try {
|
|
32514
|
-
const rawCfg = parseYaml3(
|
|
32746
|
+
const rawCfg = parseYaml3(readFileSync52(cfg.configFile, "utf8"));
|
|
32515
32747
|
for (const r of rawCfg?.routes ?? []) {
|
|
32516
32748
|
if (typeof r?.route !== "string" || cfg.routes.some((x) => x.route === r.route)) continue;
|
|
32517
32749
|
try {
|
|
@@ -32575,8 +32807,8 @@ ${where.join("\n")}`);
|
|
|
32575
32807
|
process.stdout.write("crew reload: no daemon unit is running \u2014 nothing to reload (the next run reads crew.yaml fresh)\n");
|
|
32576
32808
|
break;
|
|
32577
32809
|
}
|
|
32578
|
-
|
|
32579
|
-
|
|
32810
|
+
mkdirSync42(cfg.ship.stateDir, { recursive: true });
|
|
32811
|
+
writeFileSync42(sentinel, `${(/* @__PURE__ */ new Date()).toISOString()}
|
|
32580
32812
|
`);
|
|
32581
32813
|
process.stdout.write(
|
|
32582
32814
|
"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"
|
|
@@ -32641,7 +32873,7 @@ ${where.join("\n")}`);
|
|
|
32641
32873
|
}
|
|
32642
32874
|
case "log": {
|
|
32643
32875
|
try {
|
|
32644
|
-
const text2 =
|
|
32876
|
+
const text2 = readFileSync52(cfg.ship.logFile, "utf8").split("\n");
|
|
32645
32877
|
process.stdout.write(`${text2.slice(-(Number(value("tail")) || 40)).join("\n")}
|
|
32646
32878
|
`);
|
|
32647
32879
|
} catch {
|
|
@@ -32664,8 +32896,8 @@ ${where.join("\n")}`);
|
|
|
32664
32896
|
};
|
|
32665
32897
|
if (!route2.resolved) fail2(`route ${route2.route} is not connected \u2014 run \`crew connect\` first`);
|
|
32666
32898
|
const tracker = new Tracker(route2, cfg.ship);
|
|
32667
|
-
const configText =
|
|
32668
|
-
const cfgBase =
|
|
32899
|
+
const configText = readFileSync52(cfg.configFile, "utf8");
|
|
32900
|
+
const cfgBase = dirname37(cfg.configFile);
|
|
32669
32901
|
const configured2 = configuredRepos(configText, route2.route, cfgBase);
|
|
32670
32902
|
const dir = configured2.find((r) => r.name === SAMPLE_REPO)?.dir ?? sampleDir(configured2.map((r) => r.dir), route2.reposBasePath, route2.route.split("/")[0]);
|
|
32671
32903
|
const resolvedFile = resolvedPathFor(cfg.ship.stateDir, route2.route);
|
|
@@ -32693,7 +32925,7 @@ ${where.join("\n")}`);
|
|
|
32693
32925
|
}
|
|
32694
32926
|
if (configured2.some((r) => r.dir === dir)) {
|
|
32695
32927
|
try {
|
|
32696
|
-
|
|
32928
|
+
writeFileSync42(cfg.configFile, planRepoRemove(configText, cfgBase, route2.route, dir).text);
|
|
32697
32929
|
} catch (e) {
|
|
32698
32930
|
if (e instanceof ReposError) fail2(e.message);
|
|
32699
32931
|
throw e;
|
|
@@ -32701,29 +32933,29 @@ ${where.join("\n")}`);
|
|
|
32701
32933
|
}
|
|
32702
32934
|
if (row) {
|
|
32703
32935
|
await tracker.deleteRepoRow(row.id);
|
|
32704
|
-
if (
|
|
32705
|
-
const raw = JSON.parse(
|
|
32936
|
+
if (existsSync57(resolvedFile)) {
|
|
32937
|
+
const raw = JSON.parse(readFileSync52(resolvedFile, "utf8"));
|
|
32706
32938
|
if (raw.repoNames) delete raw.repoNames[row.id];
|
|
32707
32939
|
if (raw.repoRemotes) delete raw.repoRemotes[row.id];
|
|
32708
|
-
|
|
32940
|
+
writeFileSync42(resolvedFile, `${JSON.stringify(raw, null, 2)}
|
|
32709
32941
|
`);
|
|
32710
32942
|
}
|
|
32711
32943
|
}
|
|
32712
|
-
if (
|
|
32944
|
+
if (existsSync57(join60(dir, ".git")) && basename16(dir) === SAMPLE_REPO) rmSync26(dir, { recursive: true, force: true });
|
|
32713
32945
|
say("removed", { dir, closed }, `removed the sample repo${closed.length ? `, closed ${closed.join(", ")}` : ""}`);
|
|
32714
32946
|
break;
|
|
32715
32947
|
}
|
|
32716
32948
|
const projectId = route2.resolved.areaId ?? resolveRepoProject(await tracker.projectRows(), value("project"));
|
|
32717
|
-
const fresh = !
|
|
32718
|
-
if (
|
|
32949
|
+
const fresh = !existsSync57(join60(dir, ".git"));
|
|
32950
|
+
if (existsSync57(dir) && fresh && readdirSync20(dir).length > 0) fail2(`${dir} exists and is not a git checkout \u2014 move it aside`);
|
|
32719
32951
|
if (dryRun) {
|
|
32720
32952
|
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`);
|
|
32721
32953
|
break;
|
|
32722
32954
|
}
|
|
32723
32955
|
if (fresh) {
|
|
32724
|
-
|
|
32725
|
-
|
|
32726
|
-
|
|
32956
|
+
mkdirSync42(dir, { recursive: true });
|
|
32957
|
+
writeFileSync42(join60(dir, "README.md"), SAMPLE_README);
|
|
32958
|
+
writeFileSync42(join60(dir, ".crew.yaml"), SAMPLE_CREW_YAML);
|
|
32727
32959
|
const g = (...a) => {
|
|
32728
32960
|
const r = spawnSync13("git", a, { cwd: dir, encoding: "utf8" });
|
|
32729
32961
|
if (r.status !== 0) fail2(`git ${a[0]} failed in ${dir}: ${(r.stderr || r.stdout).trim()}`);
|
|
@@ -32741,17 +32973,17 @@ ${where.join("\n")}`);
|
|
|
32741
32973
|
spec: { platform: "unix", releaseMode: "integrate", ciProvider: "none" }
|
|
32742
32974
|
});
|
|
32743
32975
|
repoId = (await tracker.createRepoRow(payload)).id;
|
|
32744
|
-
if (
|
|
32745
|
-
const raw = JSON.parse(
|
|
32976
|
+
if (existsSync57(resolvedFile)) {
|
|
32977
|
+
const raw = JSON.parse(readFileSync52(resolvedFile, "utf8"));
|
|
32746
32978
|
raw.repoNames = { ...raw.repoNames, [repoId]: SAMPLE_REPO };
|
|
32747
32979
|
raw.repoRemotes = { ...raw.repoRemotes, [repoId]: SAMPLE_REMOTE };
|
|
32748
|
-
|
|
32980
|
+
writeFileSync42(resolvedFile, `${JSON.stringify(raw, null, 2)}
|
|
32749
32981
|
`);
|
|
32750
32982
|
}
|
|
32751
32983
|
}
|
|
32752
32984
|
if (!configured2.some((r) => r.dir === dir)) {
|
|
32753
32985
|
try {
|
|
32754
|
-
|
|
32986
|
+
writeFileSync42(cfg.configFile, planRepoAdd({ text: configText, base: cfgBase, route: route2.route, path: dir, name: SAMPLE_REPO }).text);
|
|
32755
32987
|
} catch (e) {
|
|
32756
32988
|
if (e instanceof ReposError) fail2(e.message);
|
|
32757
32989
|
throw e;
|
|
@@ -32940,6 +33172,8 @@ ${where.join("\n")}`);
|
|
|
32940
33172
|
model: x.model
|
|
32941
33173
|
})),
|
|
32942
33174
|
stateDir: cfg.ship.stateDir,
|
|
33175
|
+
// CREW-3084: how many repositories carry environment; never their names or values.
|
|
33176
|
+
repositoriesWithEnv: repositoryEnvCount(cfg.ship.stateDir),
|
|
32943
33177
|
logFile: cfg.ship.logFile,
|
|
32944
33178
|
eventFile: eventFileFor(cfg.ship.stateDir),
|
|
32945
33179
|
// Additive (CREW-1373): open ship-level items, including the
|
|
@@ -33118,7 +33352,7 @@ watermark: ${state.watermark(routeSlug(route2.route))}
|
|
|
33118
33352
|
plan,
|
|
33119
33353
|
label,
|
|
33120
33354
|
uid: process.getuid?.() ?? 0,
|
|
33121
|
-
system: plan.mechanism === "systemd" &&
|
|
33355
|
+
system: plan.mechanism === "systemd" && existsSync57(systemUnitPathFor(label)),
|
|
33122
33356
|
stamp: readDaemonStamp(cfg.ship.stateDir)
|
|
33123
33357
|
});
|
|
33124
33358
|
})();
|
|
@@ -33134,7 +33368,7 @@ watermark: ${state.watermark(routeSlug(route2.route))}
|
|
|
33134
33368
|
}
|
|
33135
33369
|
for (const r of repos) {
|
|
33136
33370
|
const remote = r.config.branch.remote;
|
|
33137
|
-
if (
|
|
33371
|
+
if (existsSync57(r.dir)) {
|
|
33138
33372
|
pushAuth.push({
|
|
33139
33373
|
route: c.route,
|
|
33140
33374
|
repo: r.name,
|
|
@@ -33216,7 +33450,7 @@ watermark: ${state.watermark(routeSlug(route2.route))}
|
|
|
33216
33450
|
if (dp) problems.push(dp);
|
|
33217
33451
|
else passed++;
|
|
33218
33452
|
}
|
|
33219
|
-
const runtimeDir = runtimeDirWarning(process.platform, process.getuid?.() ?? null,
|
|
33453
|
+
const runtimeDir = runtimeDirWarning(process.platform, process.getuid?.() ?? null, existsSync57, userInfo2().username);
|
|
33220
33454
|
if (runtimeDir) problems.push({ severity: "attention", kind: "runtime_dir_missing", message: runtimeDir });
|
|
33221
33455
|
if (!flag("offline")) {
|
|
33222
33456
|
const shipKind = await doctorShipKind(route2, cfg.ship);
|
|
@@ -33281,7 +33515,7 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
|
|
|
33281
33515
|
}
|
|
33282
33516
|
try {
|
|
33283
33517
|
const evFile = eventFileFor(cfg.ship.stateDir);
|
|
33284
|
-
const evSize =
|
|
33518
|
+
const evSize = existsSync57(evFile) ? statSync17(evFile).size : 0;
|
|
33285
33519
|
process.stdout.write(
|
|
33286
33520
|
evSize > cfg.ship.eventsRotateBytes * 4 ? `events log: WARN ${evFile} is ${Math.round(evSize / 1048576)} MB (> 4x eventsRotateBytes); run \`crew reap\` to rotate it
|
|
33287
33521
|
` : "events log: ok\n"
|
|
@@ -33292,7 +33526,7 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
|
|
|
33292
33526
|
const unitPlan = planInstall(cfg.ship, CREW_HOME, host, detectSystemd(), "run", installContext());
|
|
33293
33527
|
const abandons = unitAbandonsAgents(unitPlan, (p) => {
|
|
33294
33528
|
try {
|
|
33295
|
-
return
|
|
33529
|
+
return readFileSync52(p, "utf8");
|
|
33296
33530
|
} catch {
|
|
33297
33531
|
return null;
|
|
33298
33532
|
}
|
|
@@ -33307,7 +33541,7 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
|
|
|
33307
33541
|
const pPlan = planInstall(cfg.ship, CREW_HOME, host, true, "passengers", installContext());
|
|
33308
33542
|
const keeps = unitAbandonsAgents(pPlan, (p) => {
|
|
33309
33543
|
try {
|
|
33310
|
-
return
|
|
33544
|
+
return readFileSync52(p, "utf8");
|
|
33311
33545
|
} catch {
|
|
33312
33546
|
return null;
|
|
33313
33547
|
}
|
|
@@ -33321,7 +33555,7 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
|
|
|
33321
33555
|
if (host === "linux" && detectSystemd()) {
|
|
33322
33556
|
const ctl = planDaemonControl(CREW_HOME, host, true);
|
|
33323
33557
|
const unitPlan = planInstall(cfg.ship, CREW_HOME, host, true, "run", installContext());
|
|
33324
|
-
if (ctl.statusCommand && unitPlan.unitPaths.some((p) =>
|
|
33558
|
+
if (ctl.statusCommand && unitPlan.unitPaths.some((p) => existsSync57(p))) {
|
|
33325
33559
|
const st = spawnSync13(ctl.statusCommand[0], ctl.statusCommand.slice(1), { cwd: CREW_HOME, encoding: "utf8" });
|
|
33326
33560
|
if (!st.error && st.status !== 0) {
|
|
33327
33561
|
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");
|