@tablation/crew 0.150.0 → 0.150.1

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 +71 -47
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -5680,13 +5680,17 @@ function runAll(commands, cwd, log) {
5680
5680
  }
5681
5681
  async function applyInstall(plan, crewHome, dryRun, log) {
5682
5682
  let changed2 = plan.crontabLine !== null;
5683
+ let replaced = false;
5683
5684
  for (const path of plan.unitPaths) {
5684
5685
  if (dryRun) {
5685
5686
  log.emit(`would write ${path}`);
5686
5687
  continue;
5687
5688
  }
5688
5689
  const before = existsSync16(path) ? readFileSync17(path, "utf8") : null;
5689
- if (before !== plan.unitContent[path]) changed2 = true;
5690
+ if (before !== plan.unitContent[path]) {
5691
+ changed2 = true;
5692
+ if (before !== null) replaced = true;
5693
+ }
5690
5694
  mkdirSync12(dirname9(path), { recursive: true });
5691
5695
  writeFileSync13(path, plan.unitContent[path]);
5692
5696
  log.emit(`wrote ${path}`);
@@ -5703,7 +5707,7 @@ async function applyInstall(plan, crewHome, dryRun, log) {
5703
5707
  if (dryRun) {
5704
5708
  for (const c of plan.preLoadCommands) log.emit(`would run: ${c.join(" ")}`);
5705
5709
  } else {
5706
- const ok = runAll(plan.preLoadCommands, crewHome, log);
5710
+ const ok = runAll(plan.preLoadCommands, crewHome, { emit: log.emit.bind(log), warn: (m) => log.emit(m) });
5707
5711
  if (!ok) log.emit("unload before reload failed \u2014 likely not loaded yet, continuing");
5708
5712
  }
5709
5713
  }
@@ -5727,19 +5731,20 @@ async function applyInstall(plan, crewHome, dryRun, log) {
5727
5731
  }
5728
5732
  log.emit(`crew's own log: ${plan.crewLog}`);
5729
5733
  log.emit(`scheduler log (only what escapes the crew, e.g. a crash before it starts): ${plan.schedulerLog}`);
5730
- return { changed: changed2 };
5734
+ return { changed: changed2, action: !changed2 ? "unchanged" : replaced ? "replaced" : "installed" };
5731
5735
  }
5732
5736
  async function applyUninstall(plan, crewHome, dryRun, log) {
5737
+ let changed2 = false;
5733
5738
  if (plan.mechanism === "none") {
5734
5739
  log.emit("nothing to uninstall on this platform");
5735
- return;
5740
+ return { changed: changed2 };
5736
5741
  }
5737
5742
  if (plan.unloadCommands.length) {
5738
5743
  if (dryRun) {
5739
5744
  for (const c of plan.unloadCommands) log.emit(`would run: ${c.join(" ")}`);
5740
5745
  } else {
5741
- const ok = runAll(plan.unloadCommands, crewHome, log);
5742
- if (!ok) log.warn("unload command failed \u2014 it may not have been loaded; continuing to remove files");
5746
+ const ok = runAll(plan.unloadCommands, crewHome, { emit: log.emit.bind(log), warn: (m) => log.emit(m) });
5747
+ if (!ok) log.emit("unload command failed \u2014 it may not have been loaded; continuing to remove files");
5743
5748
  }
5744
5749
  }
5745
5750
  if (plan.removeLabel) {
@@ -5747,6 +5752,7 @@ async function applyUninstall(plan, crewHome, dryRun, log) {
5747
5752
  log.emit(`would run: launchctl remove ${plan.removeLabel}`);
5748
5753
  } else {
5749
5754
  if (spawnSync5("launchctl", ["remove", plan.removeLabel], { encoding: "utf8" }).status === 0) {
5755
+ changed2 = true;
5750
5756
  log.emit(`removed loaded job ${plan.removeLabel}`);
5751
5757
  }
5752
5758
  }
@@ -5758,6 +5764,7 @@ async function applyUninstall(plan, crewHome, dryRun, log) {
5758
5764
  continue;
5759
5765
  }
5760
5766
  unlinkSync2(path);
5767
+ changed2 = true;
5761
5768
  log.emit(`removed ${path}`);
5762
5769
  }
5763
5770
  if (plan.crontabLine) {
@@ -5765,9 +5772,11 @@ async function applyUninstall(plan, crewHome, dryRun, log) {
5765
5772
  log.emit("would remove crontab entry");
5766
5773
  } else {
5767
5774
  removeCrontabLine(plan.crontabLine);
5775
+ changed2 = true;
5768
5776
  log.emit("removed crontab entry");
5769
5777
  }
5770
5778
  }
5779
+ return { changed: changed2 };
5771
5780
  }
5772
5781
  var CREW_LAUNCHD_PREFIX = "com.tablation.crew";
5773
5782
  function launchAgentsDir() {
@@ -5835,8 +5844,8 @@ function clearForeignLaunchdUnits(crewHome, replace, dryRun, log, dir, loaded) {
5835
5844
  }
5836
5845
  for (const unit of foreign) {
5837
5846
  const why = unit.orphan ? "removing a loaded job whose plist is gone" : unit.program === null ? "replacing a unit with no readable ProgramArguments" : unit.programExists ? "replacing a live other install" : "removing a stale unit whose program is gone";
5838
- log.emit(`${why}: ${unit.label}`);
5839
- removeLaunchdUnit(unit, dryRun, log);
5847
+ log.emit(`${why}: ${unit.label}${dryRun ? " (dry run, not applied)" : ""}`);
5848
+ removeLaunchdUnit(unit, dryRun, { emit: () => void 0, warn: log.warn.bind(log) });
5840
5849
  }
5841
5850
  return true;
5842
5851
  }
@@ -25793,6 +25802,23 @@ function summarizeOutcomes(outcomes, describe2, isRoutine, noun, verbose) {
25793
25802
  function withFix(message, fix) {
25794
25803
  return `${message.replace(/[.\s]+$/, "")} \u2014 try: ${fix}`;
25795
25804
  }
25805
+ function summarizeJobs(results, o) {
25806
+ const state = o.uninstall ? "not installed" : "installed";
25807
+ const mark3 = o.dryRun ? " (dry run, not applied)" : "";
25808
+ const line = (r) => {
25809
+ if (o.dryRun) return `would ${o.uninstall ? "remove" : "install"} ${r.job} via ${r.mechanism} for ${o.host}${mark3}`;
25810
+ if (r.action === "unchanged") return `${r.job} already ${state} (${r.mechanism})`;
25811
+ return `${r.action} ${r.job} via ${r.mechanism} for ${o.host}`;
25812
+ };
25813
+ if (o.dryRun || o.verbose) return results.map(line);
25814
+ 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})`);
25819
+ }
25820
+ return lines2;
25821
+ }
25796
25822
 
25797
25823
  // src/agents-sync-run.ts
25798
25824
  async function runAgentsSync(target, o) {
@@ -27159,7 +27185,7 @@ import { dirname as dirOf2, resolve as resolvePath } from "path";
27159
27185
  import { existsSync as existsSync56, readdirSync as readdirSync18, statSync as statSync17 } from "fs";
27160
27186
  import { join as join58 } from "path";
27161
27187
  function builtVersion() {
27162
- return true ? "0.150.0" : null;
27188
+ return true ? "0.150.1" : null;
27163
27189
  }
27164
27190
  var REBUILD_HINT = "rebuild with npm run build";
27165
27191
  function newestMtime(path) {
@@ -30252,33 +30278,33 @@ if (command === "passenger-sync-daemon") {
30252
30278
  async function installScheduler(opts = {}) {
30253
30279
  const host = hostPlatform();
30254
30280
  if (host === "windows") {
30255
- process.stderr.write("crew install: no scheduler support yet for Windows (Task Scheduler is planned, not built)\n");
30256
- process.exit(2);
30281
+ die("crew install", "no scheduler support yet for Windows (Task Scheduler is planned, not built)", "run `crew daemon` in a terminal instead");
30257
30282
  }
30283
+ const installLog = {
30284
+ emit: (m) => emit.note(m),
30285
+ warn: (m) => emit.warn(withFix(`crew install: ${m}`, "`crew doctor`"))
30286
+ };
30258
30287
  if (host === "macos") {
30259
30288
  const ok = clearForeignLaunchdUnits(CREW_HOME, !!opts.replace, dryRun, {
30260
- emit: (m) => process.stdout.write(`${m}
30261
- `),
30262
- warn: (m) => process.stderr.write(`crew install: ${m}
30263
- `)
30289
+ // A removed foreign unit is a real change, so it is shown by default.
30290
+ emit: (m) => emit.emit(m),
30291
+ warn: (m) => emit.warn(withFix(`crew install: ${m}`, "`crew install --replace`"))
30264
30292
  }, void 0, loadedCrewLabels());
30265
30293
  if (!ok) return false;
30266
30294
  }
30267
30295
  const installPathProblem = cfg.routes.some((r) => r.enabled && r.hostPassengers) ? dockerPathProblem(cfg.ship) : void 0;
30268
30296
  if (installPathProblem) {
30269
- process.stderr.write(`crew install: Host Passengers is on but ${installPathProblem}
30270
- `);
30297
+ emit.error(withFix(`crew install: Host Passengers is on but ${installPathProblem}`, "`crew doctor`"));
30271
30298
  process.exitCode = 1;
30272
30299
  } else if (!dryRun && cfg.routes.some((r) => r.enabled && r.hostPassengers) && dockerAvailable()) {
30273
30300
  const image = passengerImageRef(cfg);
30274
30301
  if (imagePresent(image)) {
30275
- process.stdout.write(`Host Passengers image ${image} is already present
30276
- `);
30302
+ emit.note(`Host Passengers image ${image} is already present`);
30277
30303
  } else {
30278
- process.stdout.write(`pulling Host Passengers image ${image}
30279
- `);
30304
+ emit.note(`pulling Host Passengers image ${image}`);
30280
30305
  try {
30281
30306
  ensureImage(image);
30307
+ emit.emit(`pulled Host Passengers image ${image}`);
30282
30308
  } catch (e) {
30283
30309
  emit.warn(withFix(`crew install: could not pull Host Passengers image ${image}: ${e.message}`, "`crew doctor`"));
30284
30310
  process.exitCode = 1;
@@ -30286,24 +30312,24 @@ if (command === "passenger-sync-daemon") {
30286
30312
  }
30287
30313
  }
30288
30314
  const hasSystemd = detectSystemd();
30315
+ const results = [];
30289
30316
  for (const job of ["run", "release", "passengers"]) {
30290
30317
  const plan = planInstall(cfg.ship, CREW_HOME, host, hasSystemd, job, installContext());
30291
- process.stdout.write(`installing ${job} via ${plan.mechanism} for ${host}${dryRun ? " (dry run)" : ""}
30292
- `);
30293
- await applyInstall(plan, CREW_HOME, dryRun, {
30294
- emit: (m) => process.stdout.write(`${m}
30295
- `),
30296
- warn: (m) => process.stderr.write(`crew install: ${m}
30297
- `)
30298
- });
30318
+ emit.note(`installing ${job} via ${plan.mechanism} for ${host}${dryRun ? " (dry run)" : ""}`);
30319
+ try {
30320
+ const { action } = await applyInstall(plan, CREW_HOME, dryRun, installLog);
30321
+ results.push({ job, mechanism: plan.mechanism, action });
30322
+ } catch (e) {
30323
+ return die("crew install", e.message.replace(/^crew install:\s*/, ""), "`crew doctor`", 1);
30324
+ }
30299
30325
  }
30326
+ for (const l of summarizeJobs(results, { dryRun, verbose: flag("verbose"), host })) emit.emit(l);
30300
30327
  if (host === "linux" && hasSystemd) {
30301
30328
  const label = labelFor(CREW_HOME, "run");
30302
30329
  const staleTimer = join64(homedir11(), ".config", "systemd", "user", `${label}.timer`);
30303
30330
  if (existsSync60(staleTimer)) {
30304
- process.stdout.write(
30305
- `removing stale run timer from before the persistent-service cutover: ${staleTimer}${dryRun ? " (dry run)" : ""}
30306
- `
30331
+ emit.emit(
30332
+ `removing stale run timer from before the persistent-service cutover: ${staleTimer}${dryRun ? " (dry run, not applied)" : ""}`
30307
30333
  );
30308
30334
  if (!dryRun) {
30309
30335
  spawnSync14("systemctl", ["--user", "disable", "--now", `${label}.timer`], { cwd: CREW_HOME, env: withUserBusEnv() });
@@ -34617,28 +34643,26 @@ ${where.join("\n")}`);
34617
34643
  case "uninstall": {
34618
34644
  const host = hostPlatform();
34619
34645
  if (host === "windows") {
34620
- process.stdout.write("nothing installed on Windows\n");
34646
+ emit.emit("nothing installed on Windows");
34621
34647
  break;
34622
34648
  }
34649
+ const uninstallLog = {
34650
+ emit: (m) => emit.note(m),
34651
+ warn: (m) => emit.warn(withFix(`crew uninstall: ${m}`, "`crew doctor`"))
34652
+ };
34653
+ const results = [];
34623
34654
  for (const job of ["run", "release", "passengers"]) {
34624
34655
  const plan = planUninstall(cfg.ship, CREW_HOME, host, detectSystemd(), job);
34625
- process.stdout.write(`uninstalling ${job} ${plan.mechanism} for ${host}${dryRun ? " (dry run)" : ""}
34626
- `);
34627
- await applyUninstall(plan, CREW_HOME, dryRun, {
34628
- emit: (m) => process.stdout.write(`${m}
34629
- `),
34630
- warn: (m) => process.stderr.write(`crew uninstall: ${m}
34631
- `)
34632
- });
34656
+ emit.note(`uninstalling ${job} ${plan.mechanism} for ${host}${dryRun ? " (dry run)" : ""}`);
34657
+ const { changed: changed2 } = await applyUninstall(plan, CREW_HOME, dryRun, uninstallLog);
34658
+ results.push({ job, mechanism: plan.mechanism, action: changed2 ? "removed" : "unchanged" });
34633
34659
  }
34660
+ for (const l of summarizeJobs(results, { uninstall: true, dryRun, verbose: flag("verbose"), host })) emit.emit(l);
34634
34661
  if (flag("all") && host === "macos") {
34635
- process.stdout.write(`uninstalling every crew launchd unit${dryRun ? " (dry run)" : ""}
34636
- `);
34662
+ emit.note(`uninstalling every crew launchd unit${dryRun ? " (dry run)" : ""}`);
34637
34663
  removeAllLaunchdUnits(dryRun, {
34638
- emit: (m) => process.stdout.write(`${m}
34639
- `),
34640
- warn: (m) => process.stderr.write(`crew uninstall: ${m}
34641
- `)
34664
+ emit: (m) => emit.emit(m),
34665
+ warn: uninstallLog.warn
34642
34666
  }, void 0, loadedCrewLabels());
34643
34667
  }
34644
34668
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tablation/crew",
3
- "version": "0.150.0",
3
+ "version": "0.150.1",
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",