@tablation/crew 0.152.0 → 0.152.2
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 +77 -25
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -4151,6 +4151,7 @@ var SHIP_KEYS = /* @__PURE__ */ new Set([
|
|
|
4151
4151
|
"roleConcurrency",
|
|
4152
4152
|
"streamRetentionDays",
|
|
4153
4153
|
"eventsRotateBytes",
|
|
4154
|
+
"stateMaxBytes",
|
|
4154
4155
|
"reposBasePath",
|
|
4155
4156
|
"relayHost",
|
|
4156
4157
|
"relayPort",
|
|
@@ -4508,6 +4509,10 @@ Create the first of those:
|
|
|
4508
4509
|
if (!Number.isInteger(streamRetentionDays) || streamRetentionDays < 1) {
|
|
4509
4510
|
missing.add(`ship.streamRetentionDays must be a positive integer (got "${shipRaw.streamRetentionDays}")`);
|
|
4510
4511
|
}
|
|
4512
|
+
const stateMaxBytes = shipRaw.stateMaxBytes === void 0 ? 2 * 1024 * 1024 * 1024 : Number(shipRaw.stateMaxBytes);
|
|
4513
|
+
if (!Number.isInteger(stateMaxBytes) || stateMaxBytes < 1) {
|
|
4514
|
+
missing.add(`ship.stateMaxBytes must be a positive integer (got "${shipRaw.stateMaxBytes}")`);
|
|
4515
|
+
}
|
|
4511
4516
|
const maxPeriscopes = shipRaw.maxPeriscopes === void 0 ? DEFAULT_MAX_PERISCOPES : Number(shipRaw.maxPeriscopes);
|
|
4512
4517
|
if (!Number.isInteger(maxPeriscopes) || maxPeriscopes < 1) {
|
|
4513
4518
|
missing.add(`ship.maxPeriscopes must be a positive integer (got "${shipRaw.maxPeriscopes}")`);
|
|
@@ -4606,6 +4611,7 @@ Create the first of those:
|
|
|
4606
4611
|
roleConcurrency,
|
|
4607
4612
|
streamRetentionDays,
|
|
4608
4613
|
eventsRotateBytes,
|
|
4614
|
+
stateMaxBytes,
|
|
4609
4615
|
relayHost: shipRaw.relayHost ? String(shipRaw.relayHost) : void 0,
|
|
4610
4616
|
// 2222 matches the relay's own RELAY_SSH_PORT default (crew-relay README).
|
|
4611
4617
|
relayPort: shipRaw.relayPort !== void 0 ? Number(shipRaw.relayPort) : 2222,
|
|
@@ -9403,6 +9409,14 @@ var Tracker = class {
|
|
|
9403
9409
|
limit: 500
|
|
9404
9410
|
});
|
|
9405
9411
|
}
|
|
9412
|
+
/** Tickets by `issue_id` (CREW-3323: resolving a run's key to its display tag). */
|
|
9413
|
+
async ticketsByKeys(keys) {
|
|
9414
|
+
if (keys.length === 0) return [];
|
|
9415
|
+
return this.client.records.list(this.models.issues, {
|
|
9416
|
+
filters: encodeFilters([{ columnName: this.contract.columns.key, operator: "IN", value: keys }]),
|
|
9417
|
+
limit: 500
|
|
9418
|
+
});
|
|
9419
|
+
}
|
|
9406
9420
|
async ticket(id) {
|
|
9407
9421
|
return this.client.records.get(this.models.issues, id);
|
|
9408
9422
|
}
|
|
@@ -14920,7 +14934,8 @@ function describeRun(run4, route2, seatIds, worktreeOf = (d, n) => {
|
|
|
14920
14934
|
return {
|
|
14921
14935
|
role: run4.role,
|
|
14922
14936
|
seat: ownRoute ? seatIds[run4.role] ?? null : null,
|
|
14923
|
-
|
|
14937
|
+
// CREW-3323: the display tag when the board knows one; `num` and matching stay on the key the run carries.
|
|
14938
|
+
ticket: run4.ticket ? o.tags?.get(run4.ticket) ?? run4.ticket : run4.ticket,
|
|
14924
14939
|
ticketRecordId: run4.ticketRecordId,
|
|
14925
14940
|
repo: run4.repo ?? null,
|
|
14926
14941
|
worktree: repoDir && num2 ? worktreeOf(repoDir, num2) : null,
|
|
@@ -27293,6 +27308,38 @@ function planEventsSweep(stateDir, retentionDays, now = Date.now()) {
|
|
|
27293
27308
|
}
|
|
27294
27309
|
}).sort();
|
|
27295
27310
|
}
|
|
27311
|
+
function planSizeCapSweep(stateDir, maxBytes, now = Date.now()) {
|
|
27312
|
+
const files = [];
|
|
27313
|
+
const add = (dir, keep) => {
|
|
27314
|
+
if (!existsSync55(dir)) return;
|
|
27315
|
+
for (const name of readdirSync17(dir)) {
|
|
27316
|
+
if (!keep(name)) continue;
|
|
27317
|
+
const path = join58(dir, name);
|
|
27318
|
+
try {
|
|
27319
|
+
const st = statSync16(path);
|
|
27320
|
+
if (st.isFile()) files.push({ path, mtime: st.mtimeMs, size: st.size });
|
|
27321
|
+
} catch {
|
|
27322
|
+
}
|
|
27323
|
+
}
|
|
27324
|
+
};
|
|
27325
|
+
add(join58(stateDir, "streams"), () => true);
|
|
27326
|
+
add(stateDir, (name) => ROTATED_EVENTS_RE.test(name));
|
|
27327
|
+
let total = files.reduce((n, f) => n + f.size, 0);
|
|
27328
|
+
const out = [];
|
|
27329
|
+
for (const f of files.sort((a, b) => a.mtime - b.mtime)) {
|
|
27330
|
+
if (total <= maxBytes) break;
|
|
27331
|
+
if (f.mtime > now - DAY_MS2) break;
|
|
27332
|
+
out.push(f.path);
|
|
27333
|
+
total -= f.size;
|
|
27334
|
+
}
|
|
27335
|
+
return out;
|
|
27336
|
+
}
|
|
27337
|
+
function planStateSweep(stateDir, retentionDays, maxBytes, now = Date.now()) {
|
|
27338
|
+
const aged = [...planStreamSweep(stateDir, retentionDays, now), ...planEventsSweep(stateDir, retentionDays, now)];
|
|
27339
|
+
const gone = new Set(aged);
|
|
27340
|
+
const capped = planSizeCapSweep(stateDir, maxBytes, now).filter((p) => !gone.has(p));
|
|
27341
|
+
return [...aged, ...capped];
|
|
27342
|
+
}
|
|
27296
27343
|
|
|
27297
27344
|
// src/cli.ts
|
|
27298
27345
|
import { realpathSync as realpathSync3, readFileSync as readFileSync57, existsSync as existsSync60, mkdirSync as mkdirSync43, writeFileSync as writeFileSync44, rmSync as rmSync27, unlinkSync as unlinkSync6, copyFileSync as copyFileSync2, renameSync as renameSync10, statSync as statSync19, readdirSync as readdirSync22 } from "fs";
|
|
@@ -27374,7 +27421,7 @@ import { dirname as dirOf2, resolve as resolvePath } from "path";
|
|
|
27374
27421
|
import { existsSync as existsSync56, readdirSync as readdirSync18, statSync as statSync17 } from "fs";
|
|
27375
27422
|
import { join as join59 } from "path";
|
|
27376
27423
|
function builtVersion() {
|
|
27377
|
-
return true ? "0.152.
|
|
27424
|
+
return true ? "0.152.2" : null;
|
|
27378
27425
|
}
|
|
27379
27426
|
var REBUILD_HINT = "rebuild with npm run build";
|
|
27380
27427
|
function newestMtime(path) {
|
|
@@ -29986,6 +30033,17 @@ if (command === "passenger-sync-daemon") {
|
|
|
29986
30033
|
controlUrlFor: (slug2) => `${relayBaseUrlFor(slug2, relayHost, cfg.ship.relayHttpPort, cfg.ship.relayPublicDomain)}/control`,
|
|
29987
30034
|
warn: (m) => emit.warn(m, { step: "passengers" })
|
|
29988
30035
|
};
|
|
30036
|
+
}, sweepStateDir = function() {
|
|
30037
|
+
try {
|
|
30038
|
+
const paths = planStateSweep(cfg.ship.stateDir, cfg.ship.streamRetentionDays, cfg.ship.stateMaxBytes);
|
|
30039
|
+
if (paths.length) {
|
|
30040
|
+
emit.enter("worktree");
|
|
30041
|
+
const removed = applyStreamSweep(paths, dryRun, emit);
|
|
30042
|
+
emit.emit(`swept ${removed} stream artifact(s)`, { step: "worktree" });
|
|
30043
|
+
}
|
|
30044
|
+
} catch (e) {
|
|
30045
|
+
emit.warn(`stream sweep failed: ${e.message}`, { step: "worktree" });
|
|
30046
|
+
}
|
|
29989
30047
|
}, releaseRefused = function() {
|
|
29990
30048
|
const why = state.releaseSkipReason();
|
|
29991
30049
|
if (!why) return false;
|
|
@@ -30057,7 +30115,7 @@ if (command === "passenger-sync-daemon") {
|
|
|
30057
30115
|
}
|
|
30058
30116
|
};
|
|
30059
30117
|
};
|
|
30060
|
-
routineLine2 = routineLine, die2 = die, requireArmed2 = requireArmed, parseTicketNumber2 = parseTicketNumber, routeRelayUrl2 = routeRelayUrl, previewRelayFor2 = previewRelayFor, passengerApiKeys2 = passengerApiKeys, endpointApiFor2 = endpointApiFor, periscopeEndpointDeps2 = periscopeEndpointDeps, periscopeMcpDeps2 = periscopeMcpDeps, endpointReconcileDeps2 = endpointReconcileDeps, releaseRefused2 = releaseRefused, doctorMachineId2 = doctorMachineId, baseHealth2 = baseHealth, sandboxCacheRepos2 = sandboxCacheRepos, buildSandboxCachePass2 = buildSandboxCachePass, sandboxTickDeps2 = sandboxTickDeps;
|
|
30118
|
+
routineLine2 = routineLine, die2 = die, requireArmed2 = requireArmed, parseTicketNumber2 = parseTicketNumber, routeRelayUrl2 = routeRelayUrl, previewRelayFor2 = previewRelayFor, passengerApiKeys2 = passengerApiKeys, endpointApiFor2 = endpointApiFor, periscopeEndpointDeps2 = periscopeEndpointDeps, periscopeMcpDeps2 = periscopeMcpDeps, endpointReconcileDeps2 = endpointReconcileDeps, sweepStateDir2 = sweepStateDir, releaseRefused2 = releaseRefused, doctorMachineId2 = doctorMachineId, baseHealth2 = baseHealth, sandboxCacheRepos2 = sandboxCacheRepos, buildSandboxCachePass2 = buildSandboxCachePass, sandboxTickDeps2 = sandboxTickDeps;
|
|
30061
30119
|
async function failDaemonStart(o) {
|
|
30062
30120
|
const failEmit = new Emitter({
|
|
30063
30121
|
route: "",
|
|
@@ -30411,6 +30469,7 @@ if (command === "passenger-sync-daemon") {
|
|
|
30411
30469
|
}
|
|
30412
30470
|
}
|
|
30413
30471
|
async function releaseFleet(opts = {}) {
|
|
30472
|
+
sweepStateDir();
|
|
30414
30473
|
if (releaseRefused()) return;
|
|
30415
30474
|
precheckTickets.clear();
|
|
30416
30475
|
const summaries = [];
|
|
@@ -30436,19 +30495,7 @@ if (command === "passenger-sync-daemon") {
|
|
|
30436
30495
|
for (const t of chosen) summaries.push({ ...await releasePhase(route2, t, opts), route: route2.route });
|
|
30437
30496
|
emitReleaseSummary(emit, summaries);
|
|
30438
30497
|
if (!dryRun) state.releaseHeartbeat().touch();
|
|
30439
|
-
|
|
30440
|
-
const paths = [
|
|
30441
|
-
...planStreamSweep(cfg.ship.stateDir, cfg.ship.streamRetentionDays),
|
|
30442
|
-
...planEventsSweep(cfg.ship.stateDir, cfg.ship.streamRetentionDays)
|
|
30443
|
-
];
|
|
30444
|
-
if (paths.length) {
|
|
30445
|
-
emit.enter("worktree");
|
|
30446
|
-
const removed = applyStreamSweep(paths, dryRun, emit);
|
|
30447
|
-
emit.emit(`swept ${removed} stream artifact(s)`, { step: "worktree" });
|
|
30448
|
-
}
|
|
30449
|
-
} catch (e) {
|
|
30450
|
-
emit.warn(`stream sweep failed: ${e.message}`, { step: "worktree" });
|
|
30451
|
-
}
|
|
30498
|
+
sweepStateDir();
|
|
30452
30499
|
}
|
|
30453
30500
|
const repoRowCache = /* @__PURE__ */ new Map();
|
|
30454
30501
|
const projectRowCache = /* @__PURE__ */ new Map();
|
|
@@ -33873,10 +33920,7 @@ ${found.problems.map((p) => ` - ${p}`).join("\n")}`);
|
|
|
33873
33920
|
emit.emit(`rotated oversized event log to ${rotated}`, { step: "worktree" });
|
|
33874
33921
|
}
|
|
33875
33922
|
}
|
|
33876
|
-
const streamPaths =
|
|
33877
|
-
...planStreamSweep(cfg.ship.stateDir, cfg.ship.streamRetentionDays),
|
|
33878
|
-
...planEventsSweep(cfg.ship.stateDir, cfg.ship.streamRetentionDays)
|
|
33879
|
-
];
|
|
33923
|
+
const streamPaths = planStateSweep(cfg.ship.stateDir, cfg.ship.streamRetentionDays, cfg.ship.stateMaxBytes);
|
|
33880
33924
|
if (streamPaths.length) {
|
|
33881
33925
|
anything = true;
|
|
33882
33926
|
const removed = applyStreamSweep(streamPaths, dryRun, emit);
|
|
@@ -35071,7 +35115,7 @@ ${where.join("\n")}`);
|
|
|
35071
35115
|
const shipRows = await statusTracker.shipRows();
|
|
35072
35116
|
const engagedTicketIds = shipRows.map((s) => s.engaged_ticket_id).filter((id) => !!id);
|
|
35073
35117
|
const engagedTickets = engagedTicketIds.length ? await statusTracker.ticketsByIds(engagedTicketIds) : [];
|
|
35074
|
-
const issueLabelById = new Map(engagedTickets.map((t) => [t.id, t
|
|
35118
|
+
const issueLabelById = new Map(engagedTickets.map((t) => [t.id, displayKey(t)]));
|
|
35075
35119
|
const todo = await statusTracker.openTickets().then((open) => operatorTodo(open, statusTracker.contract, route2.resolved?.operator ?? "")).catch(() => []);
|
|
35076
35120
|
const projects = projectModeLabels(await statusTracker.projectRowsWithModes().catch(() => []));
|
|
35077
35121
|
const crewMinVersion = await readCrewFloor(route2, cfg.ship) ?? null;
|
|
@@ -35080,6 +35124,13 @@ ${where.join("\n")}`);
|
|
|
35080
35124
|
(await statusTracker.ticketsByIds([...new Set(runs.map((x) => x.ticketRecordId).filter((id) => !!id))]).catch(() => [])).map((t) => [t.id, t.title ?? null])
|
|
35081
35125
|
);
|
|
35082
35126
|
const lastRuns = lastRunsBySeat(cfg.ship.stateDir);
|
|
35127
|
+
const wantedKeys = [...new Set([...runs.map((x) => x.ticket), ...[...lastRuns.values()].map((l) => l.ticket)].filter((k) => !!k))];
|
|
35128
|
+
const tagByKey = /* @__PURE__ */ new Map();
|
|
35129
|
+
for (const t of [
|
|
35130
|
+
...await statusTracker.ticketsByIds([...new Set(runs.map((x) => x.ticketRecordId).filter((id) => !!id))]).catch(() => []),
|
|
35131
|
+
...await statusTracker.ticketsByKeys(wantedKeys).catch(() => [])
|
|
35132
|
+
]) tagByKey.set(t.issue_id, displayKey(t));
|
|
35133
|
+
const tagOf = (k) => k ? tagByKey.get(k) ?? k : null;
|
|
35083
35134
|
const periscopes = await periscopesForStatus(cfg.ship.stateDir);
|
|
35084
35135
|
const runPreviews = new Map(periscopes.filter((p) => p.serving).map((p) => [p.ticketRecordId, p.url]));
|
|
35085
35136
|
if (flag("json")) {
|
|
@@ -35103,7 +35154,7 @@ ${where.join("\n")}`);
|
|
|
35103
35154
|
// Additive (CREW-2822): how many runs this seat has live right now.
|
|
35104
35155
|
running: runs.filter((x) => x.role === r && x.route === routeSlug(route2.route)).length,
|
|
35105
35156
|
// Additive (CREW-3247): this seat's newest finished run on this ship, or null.
|
|
35106
|
-
lastRun: ((l) => l ? { ticket: l.ticket, startedAt: l.startedAt, finishedAt: l.finishedAt, outcome: l.outcome, exitCode: l.exitCode } : null)(lastRuns.get(`${routeSlug(route2.route)}/${r}`))
|
|
35157
|
+
lastRun: ((l) => l ? { ticket: tagOf(l.ticket), startedAt: l.startedAt, finishedAt: l.finishedAt, outcome: l.outcome, exitCode: l.exitCode } : null)(lastRuns.get(`${routeSlug(route2.route)}/${r}`))
|
|
35107
35158
|
};
|
|
35108
35159
|
});
|
|
35109
35160
|
process.stdout.write(`${JSON.stringify({
|
|
@@ -35153,7 +35204,7 @@ ${where.join("\n")}`);
|
|
|
35153
35204
|
seats: seats2
|
|
35154
35205
|
},
|
|
35155
35206
|
// Additive (CREW-2822): every live run on this ship. `version` stays 1.
|
|
35156
|
-
runs: runs.map((x) => describeRun(x, route2, seatIds, void 0, { titles: runTitles, previews: runPreviews })),
|
|
35207
|
+
runs: runs.map((x) => describeRun(x, route2, seatIds, void 0, { titles: runTitles, previews: runPreviews, tags: tagByKey })),
|
|
35157
35208
|
// Additive (CREW-2857): every live periscope on this ship, from its local record. `version` stays 1.
|
|
35158
35209
|
periscopes,
|
|
35159
35210
|
watermark: state.watermark(routeSlug(route2.route)),
|
|
@@ -35240,7 +35291,7 @@ ${where.join("\n")}`);
|
|
|
35240
35291
|
});
|
|
35241
35292
|
}
|
|
35242
35293
|
const reloadWaitingAt = readReloadRequestedAt(cfg.ship.stateDir);
|
|
35243
|
-
const lastRunView = [...lastRuns.values()].filter((l) => l.route === routeSlug(route2.route)).map((l) => ({ role: l.role, ticket: l.ticket, finishedAt: l.finishedAt, outcome: l.outcome }));
|
|
35294
|
+
const lastRunView = [...lastRuns.values()].filter((l) => l.route === routeSlug(route2.route)).map((l) => ({ role: l.role, ticket: tagOf(l.ticket), finishedAt: l.finishedAt, outcome: l.outcome }));
|
|
35244
35295
|
for (const line of renderStatus({
|
|
35245
35296
|
ship: { name: cfg.ship.name, platform: cfg.ship.platform },
|
|
35246
35297
|
route: { name: route2.route, dir: route2.dir, enabled: route2.enabled },
|
|
@@ -35255,7 +35306,7 @@ ${where.join("\n")}`);
|
|
|
35255
35306
|
watermark: String(state.watermark(routeSlug(route2.route))),
|
|
35256
35307
|
projects: projects.map((p) => p.label),
|
|
35257
35308
|
reloadRequestedSecondsAgo: reloadWaitingAt === null ? null : Math.max(0, Math.round((Date.now() - reloadWaitingAt) / 1e3)),
|
|
35258
|
-
runs: runs.map((x) => ({ role: x.role, ticket: x.ticket, repo: x.repo, pid: x.pid, spawnedAt: x.spawnedAt, deadline: x.deadline })),
|
|
35309
|
+
runs: runs.map((x) => ({ role: x.role, ticket: tagOf(x.ticket), repo: x.repo, pid: x.pid, spawnedAt: x.spawnedAt, deadline: x.deadline })),
|
|
35259
35310
|
lastRuns: lastRunView,
|
|
35260
35311
|
attention: shipAttention.map((i) => ({ kind: i.kind, message: i.message, since: i.since })),
|
|
35261
35312
|
waiting: todo.map((i) => ({
|
|
@@ -36097,6 +36148,7 @@ var endpointApiFor2;
|
|
|
36097
36148
|
var periscopeEndpointDeps2;
|
|
36098
36149
|
var periscopeMcpDeps2;
|
|
36099
36150
|
var endpointReconcileDeps2;
|
|
36151
|
+
var sweepStateDir2;
|
|
36100
36152
|
var releaseRefused2;
|
|
36101
36153
|
var doctorMachineId2;
|
|
36102
36154
|
var baseHealth2;
|
package/package.json
CHANGED