@tablation/crew 0.150.1 → 0.150.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.
Files changed (2) hide show
  1. package/dist/cli.js +129 -20
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -71,12 +71,12 @@ function routePeriscopeProblems(o) {
71
71
  });
72
72
  }
73
73
  }
74
- if (o.tablePresent === false) {
74
+ if (o.tablePresent === false && !o.snapshotStale) {
75
75
  out.push({
76
76
  severity: "blocker",
77
77
  kind: "periscopes_table_missing",
78
78
  route: o.route,
79
- message: `${o.route}: hostPeriscopes is on but this workspace has no Periscopes table \u2014 update the Issues template and run \`crew connect\``
79
+ message: `${o.route}: hostPeriscopes is on but this workspace has no Periscopes table (confirmed against the workspace) \u2014 a workspace admin updates the Issues app to add it, then run \`crew connect\``
80
80
  });
81
81
  }
82
82
  return out;
@@ -4418,6 +4418,7 @@ function parseResolved(raw, m, where) {
4418
4418
  holds: holds2,
4419
4419
  contract: raw.contract ?? void 0,
4420
4420
  ...typeof raw.releaseSeat === "string" && raw.releaseSeat ? { releaseSeat: raw.releaseSeat } : {},
4421
+ ...typeof raw.connectedAt === "string" && raw.connectedAt ? { connectedAt: raw.connectedAt } : {},
4421
4422
  ...typeof raw.releaseAgentId === "string" && raw.releaseAgentId ? { releaseAgentId: raw.releaseAgentId } : {},
4422
4423
  ...typeof raw.role === "string" && raw.role ? { role: raw.role } : {},
4423
4424
  ...Array.isArray(raw.capabilityMisses) && raw.capabilityMisses.length > 0 ? { capabilityMisses: raw.capabilityMisses.filter((x) => typeof x === "string") } : {},
@@ -17233,6 +17234,9 @@ var sound = (r) => r.hasRepos && r.problems.length === 0;
17233
17234
  function planFix(f) {
17234
17235
  const actions = [];
17235
17236
  const notes = [];
17237
+ for (const r of f.routes) {
17238
+ if (r.snapshotStale) actions.push({ kind: "refresh-snapshot", route: r.route });
17239
+ }
17236
17240
  for (const r of f.routes) {
17237
17241
  if (!r.enabled && sound(r)) {
17238
17242
  actions.push({ kind: "enable", route: r.route });
@@ -17253,14 +17257,18 @@ function planFix(f) {
17253
17257
  async function gatherHealth(c, check) {
17254
17258
  let problems;
17255
17259
  let readiness = [];
17260
+ let snapshotStale = false;
17256
17261
  try {
17257
17262
  const r = await check();
17258
17263
  if (Array.isArray(r)) problems = r;
17259
- else ({ problems, readiness } = r);
17264
+ else {
17265
+ ({ problems, readiness } = r);
17266
+ snapshotStale = r.snapshotStale === true;
17267
+ }
17260
17268
  } catch (e) {
17261
17269
  problems = [`checks could not run: ${e instanceof Error ? e.message : String(e)}`];
17262
17270
  }
17263
- return { route: c.route, enabled: c.enabled, hasRepos: c.hasRepos, problems, readiness };
17271
+ return { route: c.route, enabled: c.enabled, hasRepos: c.hasRepos, problems, readiness, ...snapshotStale ? { snapshotStale } : {} };
17264
17272
  }
17265
17273
  function routesInScope(routes, named) {
17266
17274
  return named ? routes.filter((r) => r.route === named) : routes;
@@ -19676,8 +19684,8 @@ function failureComparison(b, previousNote) {
19676
19684
  if (!before.length || !now.length) {
19677
19685
  lines2.push("- Same failure both times? Unknown: the output of at least one run names no file.");
19678
19686
  } else {
19679
- const same = now.filter((f) => before.includes(f));
19680
- lines2.push(same.length ? `- Same failure both times: yes, ${same.map((f) => `\`${f}\``).join(", ")} fails in both.` : `- Same failure both times: **no**. First ${before.slice(0, 3).map((f) => `\`${f}\``).join(", ")}, now ${now.slice(0, 3).map((f) => `\`${f}\``).join(", ")}. Two different failures look like a flake, not a branch that keeps breaking.`);
19687
+ const same2 = now.filter((f) => before.includes(f));
19688
+ lines2.push(same2.length ? `- Same failure both times: yes, ${same2.map((f) => `\`${f}\``).join(", ")} fails in both.` : `- Same failure both times: **no**. First ${before.slice(0, 3).map((f) => `\`${f}\``).join(", ")}, now ${now.slice(0, 3).map((f) => `\`${f}\``).join(", ")}. Two different failures look like a flake, not a branch that keeps breaking.`);
19681
19689
  }
19682
19690
  lines2.push(b.inBranch == null ? "- Failing files among the branch's changes? Unknown: the failure names no file." : b.inBranch ? "- Failing files among the branch's changes: yes." : "- Failing files among the branch's changes: **no**, none of them. Not proof, but the branch probably did not break it.");
19683
19691
  return lines2.join("\n");
@@ -24340,11 +24348,11 @@ function readStartFailure(stateDir) {
24340
24348
  function noteStartFailure(stateDir, reason, nowMs = Date.now()) {
24341
24349
  const previous = readStartFailure(stateDir);
24342
24350
  const nowIso = new Date(nowMs).toISOString();
24343
- const same = previous?.reason === reason;
24351
+ const same2 = previous?.reason === reason;
24344
24352
  const record = {
24345
24353
  reason,
24346
- count: same ? previous.count + 1 : 1,
24347
- firstAt: same ? previous.firstAt : nowIso,
24354
+ count: same2 ? previous.count + 1 : 1,
24355
+ firstAt: same2 ? previous.firstAt : nowIso,
24348
24356
  lastAt: nowIso
24349
24357
  };
24350
24358
  mkdirSync37(stateDir, { recursive: true });
@@ -25812,10 +25820,10 @@ function summarizeJobs(results, o) {
25812
25820
  };
25813
25821
  if (o.dryRun || o.verbose) return results.map(line);
25814
25822
  const lines2 = results.filter((r) => r.action !== "unchanged").map(line);
25815
- const same = results.filter((r) => r.action === "unchanged");
25816
- if (same.length > 0) {
25817
- const names = same.map((r) => r.job).join(", ");
25818
- lines2.push(same.length === results.length ? `all ${same.length} jobs already ${state} (${names})` : `${same.length} job${same.length === 1 ? "" : "s"} already ${state} (${names})`);
25823
+ const same2 = results.filter((r) => r.action === "unchanged");
25824
+ if (same2.length > 0) {
25825
+ const names = same2.map((r) => r.job).join(", ");
25826
+ lines2.push(same2.length === results.length ? `all ${same2.length} jobs already ${state} (${names})` : `${same2.length} job${same2.length === 1 ? "" : "s"} already ${state} (${names})`);
25819
25827
  }
25820
25828
  return lines2;
25821
25829
  }
@@ -26580,6 +26588,59 @@ function planSampleTicket(i) {
26580
26588
  };
26581
26589
  }
26582
26590
 
26591
+ // src/snapshot-staleness.ts
26592
+ var SNAPSHOT_TABLES = [
26593
+ { key: "periscopesModelId", name: "Periscopes" },
26594
+ { key: "shipsModelId", name: "Ships" },
26595
+ { key: "epicsModelId", name: "Epics" },
26596
+ { key: "locksModelId", name: "Locks" },
26597
+ { key: "reposModelId", name: "Repos" },
26598
+ { key: "areaModelId", name: "Projects" }
26599
+ ];
26600
+ var same = (a, b) => a.trim().toLowerCase() === b.trim().toLowerCase();
26601
+ function liveReleaseSeat(crew, shipRowId) {
26602
+ if (!shipRowId) return void 0;
26603
+ const idOf = (v) => typeof v === "string" ? v : v && typeof v === "object" ? v.id : void 0;
26604
+ return crew.find((r) => idOf(r.ship_id) === shipRowId && (r.name ?? "").toLowerCase().includes("release"))?.id;
26605
+ }
26606
+ function compareSnapshot(resolved, live2) {
26607
+ const added = [];
26608
+ const removed = [];
26609
+ for (const t of SNAPSHOT_TABLES) {
26610
+ const have = resolved[t.key];
26611
+ const now = live2.models.find((m) => same(m.name, t.name))?.id;
26612
+ if (now && !have) added.push(t.name);
26613
+ else if (have && now !== have) removed.push(t.name);
26614
+ }
26615
+ return {
26616
+ added,
26617
+ removed,
26618
+ releaseSeatNew: !resolved.releaseSeat && !!live2.releaseSeat,
26619
+ shipRowLacksMachineId: live2.shipRowHasMachineId === false
26620
+ };
26621
+ }
26622
+ var isStale = (d) => d.added.length > 0 || d.removed.length > 0 || d.releaseSeatNew || d.shipRowLacksMachineId;
26623
+ function snapshotAge(connectedAt, now = /* @__PURE__ */ new Date()) {
26624
+ if (!connectedAt) return "unknown (connected before connectedAt was recorded)";
26625
+ const ms3 = now.getTime() - Date.parse(connectedAt);
26626
+ if (!Number.isFinite(ms3) || ms3 < 0) return "unknown";
26627
+ const units = [["day", 864e5], ["hour", 36e5], ["minute", 6e4]];
26628
+ for (const [u, size] of units) {
26629
+ const n = Math.floor(ms3 / size);
26630
+ if (n >= 1) return `${n} ${u}${n === 1 ? "" : "s"}`;
26631
+ }
26632
+ return "just now";
26633
+ }
26634
+ function staleSnapshotMessage(route2, d) {
26635
+ if (!isStale(d)) return void 0;
26636
+ const parts = [];
26637
+ if (d.added.length) parts.push(`new in the workspace: ${d.added.join(", ")}`);
26638
+ if (d.removed.length) parts.push(`no longer in the workspace: ${d.removed.join(", ")}`);
26639
+ if (d.releaseSeatNew) parts.push("this ship's Release seat row exists");
26640
+ if (d.shipRowLacksMachineId) parts.push("the Ships row has no machine_id (it predates machine ids; connect writes it)");
26641
+ return `${route2}: the connect snapshot for this route is out of date (${parts.join("; ")}) \u2014 run \`crew connect ${route2}\` then \`crew reload\` (or \`crew doctor ${route2} --fix\`)`;
26642
+ }
26643
+
26583
26644
  // src/doctor-report.ts
26584
26645
  var DOCTOR_SECTIONS = [
26585
26646
  { id: "ship", title: "Ship" },
@@ -27185,7 +27246,7 @@ import { dirname as dirOf2, resolve as resolvePath } from "path";
27185
27246
  import { existsSync as existsSync56, readdirSync as readdirSync18, statSync as statSync17 } from "fs";
27186
27247
  import { join as join58 } from "path";
27187
27248
  function builtVersion() {
27188
- return true ? "0.150.1" : null;
27249
+ return true ? "0.150.2" : null;
27189
27250
  }
27190
27251
  var REBUILD_HINT = "rebuild with npm run build";
27191
27252
  function newestMtime(path) {
@@ -30342,6 +30403,27 @@ if (command === "passenger-sync-daemon") {
30342
30403
  }
30343
30404
  return true;
30344
30405
  }
30406
+ async function snapshotDiffFor(c) {
30407
+ const r = c.resolved;
30408
+ if (!r?.projectId || flag("offline")) return void 0;
30409
+ try {
30410
+ const models = await get(
30411
+ { baseUrl: c.baseUrl, apiKey: resolveApiKey(c), userAgent: cfg.ship.userAgent },
30412
+ `/data-models?projectId=${r.projectId}`
30413
+ );
30414
+ const tracker = new Tracker(c, cfg.ship);
30415
+ const [ships, crew] = await Promise.all([tracker.shipRows(), tracker.crewRows()]);
30416
+ const matched = matchShipRows(ships, cfg.ship.name, doctorMachineId(cfg.ship.stateDir));
30417
+ const row = matched.rows.length === 1 ? matched.rows[0] : void 0;
30418
+ return compareSnapshot(r, {
30419
+ models,
30420
+ releaseSeat: liveReleaseSeat(crew, row?.id),
30421
+ shipRowHasMachineId: row && matched.hasColumn ? matched.by === "machine_id" : void 0
30422
+ });
30423
+ } catch {
30424
+ return void 0;
30425
+ }
30426
+ }
30345
30427
  async function routeProblems(c) {
30346
30428
  const host = hostPlatform();
30347
30429
  const problems = [];
@@ -30378,7 +30460,8 @@ if (command === "passenger-sync-daemon") {
30378
30460
  problems.push(`tracker unreachable: ${e instanceof Error ? e.message : String(e)}`);
30379
30461
  }
30380
30462
  if (await tracker.eventLogTracksStatus() === false) problems.push(EVENT_LOG_STATUS_UNTRACKED(tracker.contract.columns.status));
30381
- return { problems, readiness };
30463
+ const diff = await snapshotDiffFor(c);
30464
+ return { problems, readiness, snapshotStale: !!diff && isStale(diff) };
30382
30465
  }
30383
30466
  async function doctorShipKind(route3, ship) {
30384
30467
  try {
@@ -30407,7 +30490,19 @@ if (command === "passenger-sync-daemon") {
30407
30490
  const enabledSound = new Set(routes.filter((r) => r.enabled && r.hasRepos && r.problems.length === 0).map((r) => r.route));
30408
30491
  try {
30409
30492
  for (const a of plan.actions) {
30410
- if (a.kind === "enable") {
30493
+ if (a.kind === "refresh-snapshot") {
30494
+ if (prompter && !await prompter.confirm(`${a.route}: the connect snapshot is out of date \u2014 run \`crew connect ${a.route}\` and reload the daemon?`, true)) continue;
30495
+ const self = selfLaunch();
30496
+ const run4 = (args) => spawnSync14(self.command, [...self.args, ...args], { stdio: "inherit", cwd: process.cwd(), env: process.env });
30497
+ const conn = run4(["connect", a.route]);
30498
+ if (conn.status !== 0) {
30499
+ process.stdout.write(`fix: crew connect ${a.route} exited ${conn.status ?? "abnormally"} \u2014 snapshot not refreshed
30500
+ `);
30501
+ continue;
30502
+ }
30503
+ const rel = run4(["reload"]);
30504
+ changed2.push(`refreshed the connect snapshot for ${a.route} (\`crew connect\`)${rel.status === 0 ? " and reloaded the daemon" : "; `crew reload` failed \u2014 run it by hand"}`);
30505
+ } else if (a.kind === "enable") {
30411
30506
  if (prompter && !await prompter.confirm(`Route ${a.route} passes every check \u2014 set enabled: true in ${cfg.configFile}?`, false)) continue;
30412
30507
  writeFileSync44(cfg.configFile, planEnable(readFileSync56(cfg.configFile, "utf8"), a.route));
30413
30508
  enabledSound.add(a.route);
@@ -33157,6 +33252,7 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
33157
33252
  seats: found.seats,
33158
33253
  holds: found.holds.map((h) => ({ id: h.id, role: h.name })),
33159
33254
  ...found.releaseSeat ? { releaseSeat: found.releaseSeat } : {},
33255
+ connectedAt: (/* @__PURE__ */ new Date()).toISOString(),
33160
33256
  ...found.role ?? previous?.role ? { role: found.role ?? previous?.role } : {},
33161
33257
  ...capabilityMisses.length > 0 ? { capabilityMisses } : {},
33162
33258
  ...operator ? { operator } : {},
@@ -35280,10 +35376,13 @@ ${where.join("\n")}`);
35280
35376
  }
35281
35377
  const previewProblem2 = await previewHostProblem(cfg);
35282
35378
  if (previewProblem2) problems.push(previewHostFinding(previewProblem2));
35379
+ const jsonDiff = await snapshotDiffFor(route2);
35380
+ const jsonStale = jsonDiff ? staleSnapshotMessage(route2.route, jsonDiff) : void 0;
35381
+ if (jsonStale) problems.push({ severity: "attention", kind: "connect_snapshot_stale", route: route2.route, message: jsonStale, remedy: `crew connect ${route2.route} && crew reload` });
35283
35382
  if (cfg.routes.some((x) => x.route === route2.route && x.enabled && x.hostPeriscopes)) {
35284
35383
  const { settled } = await settleRepos(reposOf(route2), (t) => t.name, (t) => resolveOneRepo(route2, t));
35285
35384
  const tablePresent = flag("offline") ? void 0 : (await new Tracker(route2, cfg.ship).periscopesStatus().catch(() => ({ present: true }))).present;
35286
- problems.push(...routePeriscopeProblems({ route: route2.route, hosts: true, repos: settled.map((r) => ({ name: r.name, hasPreviewHook: !!r.config.hooks.preview })), tablePresent }));
35385
+ problems.push(...routePeriscopeProblems({ route: route2.route, hosts: true, repos: settled.map((r) => ({ name: r.name, hasPreviewHook: !!r.config.hooks.preview })), tablePresent, snapshotStale: !!jsonDiff && isStale(jsonDiff) }));
35287
35386
  if (!flag("offline")) problems.push(...await duplicateLivePeriscopeProblems(route2, cfg.ship));
35288
35387
  }
35289
35388
  problems.push(...attentionProblems(openShipAttention(state), problems));
@@ -35495,12 +35594,20 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
35495
35594
  `
35496
35595
  );
35497
35596
  const periscopes = await tracker.periscopesStatus();
35597
+ const snapDiff = await snapshotDiffFor(route2);
35598
+ const snapStale = !!snapDiff && isStale(snapDiff);
35599
+ const offlineNote = flag("offline") ? " (from the last connect; not checked against the workspace under --offline)" : "";
35600
+ if (flag("verbose")) R.line(`connect snapshot: taken ${snapshotAge(route2.resolved?.connectedAt)} ago${offlineNote}
35601
+ `);
35602
+ if (snapDiff && snapStale) R.line(`connect snapshot: WARN ${staleSnapshotMessage(route2.route, snapDiff)}
35603
+ `);
35498
35604
  if (cfg.routes.some((x) => x.route === route2.route && x.enabled && x.hostPeriscopes)) {
35499
35605
  const { settled } = await settleRepos(reposOf(route2), (t) => t.name, (t) => resolveOneRepo(route2, t));
35500
35606
  for (const f of routePeriscopeProblems({
35501
35607
  route: route2.route,
35502
35608
  hosts: true,
35503
- tablePresent: periscopes.present,
35609
+ tablePresent: flag("offline") ? void 0 : periscopes.present,
35610
+ snapshotStale: snapStale,
35504
35611
  repos: settled.map((r) => ({ name: r.name, hasPreviewHook: !!r.config.hooks.preview }))
35505
35612
  })) {
35506
35613
  R.line(`periscopes: ${f.severity.toUpperCase()} ${f.message}
@@ -35514,12 +35621,14 @@ routes: ${cfg.routes.map((c) => c.route).join(", ")}
35514
35621
  }
35515
35622
  }
35516
35623
  R.line(
35517
- !periscopes.present ? "periscopes: Periscopes table absent \u2014 this workspace cannot host periscopes\n" : periscopes.missing.length === 0 ? `periscopes: Periscopes table present (${periscopes.modelId})
35624
+ snapStale && snapDiff.added.includes("Periscopes") ? "periscopes: Periscopes table is in the workspace but not in the connect snapshot \u2014 see the connect snapshot line above\n" : !periscopes.present ? `periscopes: ${flag("offline") ? `no Periscopes table in the snapshot${offlineNote}` : "Periscopes table absent \u2014 this workspace cannot host periscopes"}
35625
+ ` : periscopes.missing.length === 0 ? `periscopes: Periscopes table present (${periscopes.modelId})
35518
35626
  ` : `periscopes: Periscopes table present (${periscopes.modelId}) but missing ${periscopes.missing.join(", ")} \u2014 update the Issues template
35519
35627
  `
35520
35628
  );
35521
35629
  R.line(
35522
- route2.resolved?.releaseSeat ? "release seat: this ship has its own Release Crew row\n" : "release seat: none \u2014 release comments are credited to the dev seat; run `crew connect` once the Crew table has this ship's row\n"
35630
+ route2.resolved?.releaseSeat ? "release seat: this ship has its own Release Crew row\n" : snapDiff?.releaseSeatNew ? "release seat: the workspace has this ship's Release row but the connect snapshot does not \u2014 see the connect snapshot line above\n" : flag("offline") ? `release seat: none in the snapshot${offlineNote}
35631
+ ` : "release seat: none \u2014 release comments are credited to the dev seat; run `crew connect` once the Crew table has this ship's row\n"
35523
35632
  );
35524
35633
  const keyRole = route2.resolved?.role ?? await fetchKeyRole(route2, cfg.ship.userAgent);
35525
35634
  const roleRoute = route2.resolved && keyRole ? { ...route2, resolved: { ...route2.resolved, role: keyRole } } : route2;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tablation/crew",
3
- "version": "0.150.1",
3
+ "version": "0.150.2",
4
4
  "description": "A standing team of headless agents that picks work off a Tablation board, does it on a machine you control, and reports back.",
5
5
  "type": "module",
6
6
  "license": "MIT",