@archme/cli 0.4.4 → 0.4.5

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 +50 -24
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -8666,12 +8666,6 @@ var init_enroll = __esm({
8666
8666
  init_execa();
8667
8667
  init_credentials();
8668
8668
  init_defaults();
8669
- if (import.meta.url === `file://${process.argv[1]}`) {
8670
- runLogin().catch((err2) => {
8671
- console.error(err2 instanceof Error ? err2.message : err2);
8672
- process.exit(1);
8673
- });
8674
- }
8675
8669
  }
8676
8670
  });
8677
8671
 
@@ -8726,13 +8720,43 @@ var init_paths = __esm({
8726
8720
  }
8727
8721
  });
8728
8722
 
8723
+ // src/daemon/supervision.ts
8724
+ function isSupervised(env) {
8725
+ return env[SUPERVISED_ENV_VAR] === "1";
8726
+ }
8727
+ function resolveExitCode(code, env) {
8728
+ return isSupervised(env) && PERMANENT_EXIT_CODES.has(code) ? 0 : code;
8729
+ }
8730
+ function supervisedStopNotice(code, env) {
8731
+ if (!isSupervised(env) || !PERMANENT_EXIT_CODES.has(code)) return null;
8732
+ return "this cannot be fixed by restarting, so the service is stopping rather than retrying; re-run `archme daemon start` once resolved";
8733
+ }
8734
+ var PERMANENT_EXIT_CODES, SUPERVISED_ENV_VAR;
8735
+ var init_supervision = __esm({
8736
+ "src/daemon/supervision.ts"() {
8737
+ "use strict";
8738
+ PERMANENT_EXIT_CODES = /* @__PURE__ */ new Set([
8739
+ 1,
8740
+ // missing/unreadable config
8741
+ 2,
8742
+ // no stored credentials — needs `archme login`
8743
+ 78
8744
+ // several accounts on one machine — needs a human to choose
8745
+ ]);
8746
+ SUPERVISED_ENV_VAR = "ARCHME_SUPERVISED";
8747
+ }
8748
+ });
8749
+
8729
8750
  // src/daemon/service/unitFiles.ts
8751
+ function unitEnv(env) {
8752
+ return { ...env, [SUPERVISED_ENV_VAR]: "1" };
8753
+ }
8730
8754
  function xmlEscape(s) {
8731
8755
  return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
8732
8756
  }
8733
8757
  function renderLaunchdPlist(opts) {
8734
8758
  const argLines = [opts.nodeBin, opts.cliEntry, "daemon", "run"].map((a2) => ` <string>${xmlEscape(a2)}</string>`).join("\n");
8735
- const envLines = Object.entries(opts.env).map(
8759
+ const envLines = Object.entries(unitEnv(opts.env)).map(
8736
8760
  ([k, v]) => ` <key>${xmlEscape(k)}</key>
8737
8761
  <string>${xmlEscape(v)}</string>`
8738
8762
  ).join("\n");
@@ -8750,8 +8774,8 @@ ${argLines}
8750
8774
  <true/>
8751
8775
  <key>KeepAlive</key>
8752
8776
  <dict>
8753
- <key>Crashed</key>
8754
- <true/>
8777
+ <key>SuccessfulExit</key>
8778
+ <false/>
8755
8779
  </dict>
8756
8780
  <key>ThrottleInterval</key>
8757
8781
  <integer>10</integer>
@@ -8774,7 +8798,7 @@ function systemdArgQuote(s) {
8774
8798
  return `"${s.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
8775
8799
  }
8776
8800
  function renderSystemdUnit(opts) {
8777
- const envLines = Object.entries(opts.env).map(([k, v]) => `Environment="${k}=${systemdEnvEscape(v)}"`).join("\n");
8801
+ const envLines = Object.entries(unitEnv(opts.env)).map(([k, v]) => `Environment="${k}=${systemdEnvEscape(v)}"`).join("\n");
8778
8802
  const execStart = [
8779
8803
  systemdArgQuote(opts.nodeBin),
8780
8804
  systemdArgQuote(opts.cliEntry),
@@ -8801,6 +8825,7 @@ var init_unitFiles = __esm({
8801
8825
  "src/daemon/service/unitFiles.ts"() {
8802
8826
  "use strict";
8803
8827
  init_paths();
8828
+ init_supervision();
8804
8829
  }
8805
8830
  });
8806
8831
 
@@ -14192,15 +14217,17 @@ async function acquireSingleInstanceLock(pidfile) {
14192
14217
  }
14193
14218
  };
14194
14219
  }
14195
- var SingleInstanceLockedError;
14220
+ var SINGLE_INSTANCE_EXIT_CODE, LOCK_HELD_MESSAGE, SingleInstanceLockedError;
14196
14221
  var init_singleInstanceLock = __esm({
14197
14222
  "src/daemon/service/singleInstanceLock.ts"() {
14198
14223
  "use strict";
14224
+ SINGLE_INSTANCE_EXIT_CODE = 64;
14225
+ LOCK_HELD_MESSAGE = "already holds";
14199
14226
  SingleInstanceLockedError = class extends Error {
14200
14227
  heldByPid;
14201
14228
  constructor(pidfile, heldByPid) {
14202
14229
  super(
14203
- heldByPid != null ? `another archme daemon already holds ${pidfile} (pid ${heldByPid})` : `another archme daemon already holds ${pidfile}`
14230
+ heldByPid != null ? `another archme daemon ${LOCK_HELD_MESSAGE} ${pidfile} (pid ${heldByPid})` : `another archme daemon ${LOCK_HELD_MESSAGE} ${pidfile}`
14204
14231
  );
14205
14232
  this.heldByPid = heldByPid;
14206
14233
  this.name = "SingleInstanceLockedError";
@@ -15687,7 +15714,6 @@ import { randomUUID } from "node:crypto";
15687
15714
  import { mkdtemp as mkdtemp3, mkdir as mkdir10, writeFile as writeFile10, rm as rm6, stat as stat8, chmod as chmod3 } from "node:fs/promises";
15688
15715
  import { tmpdir as tmpdir3 } from "node:os";
15689
15716
  import { join as join18 } from "node:path";
15690
- import { pathToFileURL } from "node:url";
15691
15717
  import { homedir as homedir5 } from "node:os";
15692
15718
  function attributeKillCause(result, recorded) {
15693
15719
  if (recorded) return recorded;
@@ -16876,6 +16902,11 @@ async function signInAccount(creds, makeAuth) {
16876
16902
  }
16877
16903
  return { active, lastErr, usedFallback };
16878
16904
  }
16905
+ function exitDaemon(code) {
16906
+ const notice = supervisedStopNotice(code, process.env);
16907
+ if (notice) console.error(notice);
16908
+ process.exit(resolveExitCode(code, process.env));
16909
+ }
16879
16910
  async function runDaemon() {
16880
16911
  let lockHandle = null;
16881
16912
  try {
@@ -16883,7 +16914,7 @@ async function runDaemon() {
16883
16914
  } catch (err2) {
16884
16915
  if (err2 instanceof SingleInstanceLockedError) {
16885
16916
  console.error(String(err2.message));
16886
- process.exit(64);
16917
+ process.exit(SINGLE_INSTANCE_EXIT_CODE);
16887
16918
  }
16888
16919
  throw err2;
16889
16920
  }
@@ -16899,7 +16930,7 @@ async function runDaemon() {
16899
16930
  } catch {
16900
16931
  }
16901
16932
  }
16902
- process.exit(1);
16933
+ exitDaemon(1);
16903
16934
  }
16904
16935
  throw err2;
16905
16936
  }
@@ -16930,7 +16961,7 @@ async function runDaemon() {
16930
16961
  } catch {
16931
16962
  }
16932
16963
  }
16933
- process.exit(2);
16964
+ exitDaemon(2);
16934
16965
  }
16935
16966
  let credentials;
16936
16967
  try {
@@ -16944,7 +16975,7 @@ async function runDaemon() {
16944
16975
  } catch {
16945
16976
  }
16946
16977
  }
16947
- process.exit(78);
16978
+ exitDaemon(78);
16948
16979
  }
16949
16980
  throw err2;
16950
16981
  }
@@ -16959,7 +16990,7 @@ async function runDaemon() {
16959
16990
  } catch {
16960
16991
  }
16961
16992
  }
16962
- process.exit(75);
16993
+ exitDaemon(75);
16963
16994
  }
16964
16995
  const auth = active.auth;
16965
16996
  const client = createClient(SUPABASE_URL, SUPABASE_ANON_KEY, {
@@ -17141,6 +17172,7 @@ var init_run = __esm({
17141
17172
  init_dispatch();
17142
17173
  init_defaults();
17143
17174
  init_singleInstanceLock();
17175
+ init_supervision();
17144
17176
  init_paths();
17145
17177
  init_semaphore();
17146
17178
  init_bearer();
@@ -17341,12 +17373,6 @@ ${ANCHOR_VERIFICATION}`;
17341
17373
  return daemonVersion;
17342
17374
  }
17343
17375
  };
17344
- if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
17345
- runDaemon().catch((err2) => {
17346
- console.error("fatal:", err2);
17347
- process.exit(1);
17348
- });
17349
- }
17350
17376
  }
17351
17377
  });
17352
17378
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@archme/cli",
3
- "version": "0.4.4",
3
+ "version": "0.4.5",
4
4
  "description": "Map your codebase into a living architecture diagram: run `archme init` in a repo to scan it, `archme daemon start` to keep it current on every commit.",
5
5
  "type": "module",
6
6
  "license": "SEE LICENSE IN LICENSE",