@mushi-mushi/cli 0.40.3 → 0.40.4

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.
@@ -32,10 +32,10 @@ import {
32
32
  saveConfig,
33
33
  savedSdkKeyFor,
34
34
  trySaveKeyToKeychain
35
- } from "./chunk-JXGVZWRL.js";
35
+ } from "./chunk-S5YMLTMA.js";
36
36
  import {
37
37
  MUSHI_CLI_VERSION
38
- } from "./chunk-LWFREQOK.js";
38
+ } from "./chunk-XYTPKC65.js";
39
39
  import {
40
40
  FRAMEWORKS,
41
41
  detectFramework,
@@ -2185,7 +2185,7 @@ async function maybeOfferConnect(credentials, options, _consoleBase) {
2185
2185
  if (p.isCancel(answer) || !answer) return;
2186
2186
  const endpoint = resolveCloudEndpoint(options.endpoint);
2187
2187
  try {
2188
- const { runConnect } = await import("./connect-OJXHNDFB.js");
2188
+ const { runConnect } = await import("./connect-VI2GTMQ4.js");
2189
2189
  const saved = loadConfig();
2190
2190
  const result = await runConnect(
2191
2191
  {
@@ -8,10 +8,10 @@ import {
8
8
  requireConfig,
9
9
  requireUuid,
10
10
  tryLoadWorkerKey
11
- } from "./chunk-CGQE3GJK.js";
11
+ } from "./chunk-C6JKAD3Z.js";
12
12
  import {
13
13
  MUSHI_CLI_VERSION
14
- } from "./chunk-ZVNRKEVP.js";
14
+ } from "./chunk-MEQSUWI4.js";
15
15
 
16
16
  // src/worker/daemon.ts
17
17
  import { existsSync as existsSync6, readFileSync as readFileSync5 } from "fs";
@@ -1613,7 +1613,7 @@ function registerWorkCommands(program) {
1613
1613
  if (opts.repoDir || opts.report || opts.followups || opts.recheck) {
1614
1614
  throw new MushiCliError("E_INVALID_INPUT", "--daemon takes its lanes and clones from the worker config, not from --repo-dir, --report or --followups.", "mushi worker install");
1615
1615
  }
1616
- const { runDaemon: runDaemon2 } = await import("./daemon-PPOAKQNF.js");
1616
+ const { runDaemon: runDaemon2 } = await import("./daemon-YM34HXEA.js");
1617
1617
  await runDaemon2({ configPath: opts.workerConfig, ...opts.agent !== void 0 ? { agent } : {}, ...opts.anyRepo ? { anyRepo: true } : {} });
1618
1618
  return;
1619
1619
  }
@@ -9,10 +9,10 @@ import {
9
9
  requireUuid,
10
10
  saveConfig,
11
11
  savedSdkKeyFor
12
- } from "./chunk-CGQE3GJK.js";
12
+ } from "./chunk-C6JKAD3Z.js";
13
13
  import {
14
14
  MUSHI_MCP_PIN_SPEC
15
- } from "./chunk-ZVNRKEVP.js";
15
+ } from "./chunk-MEQSUWI4.js";
16
16
  import {
17
17
  assertEndpoint,
18
18
  normalizeEndpoint
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  MUSHI_CLI_VERSION
4
- } from "./chunk-ZVNRKEVP.js";
4
+ } from "./chunk-MEQSUWI4.js";
5
5
  import {
6
6
  CLOUD_API_ENDPOINT,
7
7
  normalizeEndpoint
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/version.ts
4
+ var MUSHI_CLI_VERSION = true ? "0.40.4" : "0.0.0-dev";
5
+ var MUSHI_MCP_PIN_SPEC = "@mushi-mushi/mcp@0.31.6";
6
+
7
+ export {
8
+ MUSHI_CLI_VERSION,
9
+ MUSHI_MCP_PIN_SPEC
10
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  MUSHI_CLI_VERSION
3
- } from "./chunk-LWFREQOK.js";
3
+ } from "./chunk-XYTPKC65.js";
4
4
  import {
5
5
  assertEndpoint,
6
6
  normalizeEndpoint
@@ -0,0 +1,8 @@
1
+ // src/version.ts
2
+ var MUSHI_CLI_VERSION = true ? "0.40.4" : "0.0.0-dev";
3
+ var MUSHI_MCP_PIN_SPEC = "@mushi-mushi/mcp@0.31.6";
4
+
5
+ export {
6
+ MUSHI_CLI_VERSION,
7
+ MUSHI_MCP_PIN_SPEC
8
+ };
@@ -2,10 +2,10 @@
2
2
  import {
3
3
  resolveSdkEnvKey,
4
4
  runConnect
5
- } from "./chunk-HNVCLEDF.js";
5
+ } from "./chunk-BKSEVNJH.js";
6
6
  import "./chunk-CG5KPP4S.js";
7
- import "./chunk-CGQE3GJK.js";
8
- import "./chunk-ZVNRKEVP.js";
7
+ import "./chunk-C6JKAD3Z.js";
8
+ import "./chunk-MEQSUWI4.js";
9
9
  import "./chunk-LGGE3LH7.js";
10
10
  export {
11
11
  resolveSdkEnvKey,
@@ -6,10 +6,10 @@ import {
6
6
  saveConfig,
7
7
  savedSdkKeyFor,
8
8
  waitForIngestReady
9
- } from "./chunk-JXGVZWRL.js";
9
+ } from "./chunk-S5YMLTMA.js";
10
10
  import {
11
11
  MUSHI_MCP_PIN_SPEC
12
- } from "./chunk-LWFREQOK.js";
12
+ } from "./chunk-XYTPKC65.js";
13
13
  import {
14
14
  detectFramework,
15
15
  envVarsToWrite,
@@ -11,9 +11,9 @@ import {
11
11
  readWorkerKey,
12
12
  runDaemon,
13
13
  workerHostId
14
- } from "./chunk-5TO6PSO6.js";
15
- import "./chunk-CGQE3GJK.js";
16
- import "./chunk-ZVNRKEVP.js";
14
+ } from "./chunk-AUWZX4P3.js";
15
+ import "./chunk-C6JKAD3Z.js";
16
+ import "./chunk-MEQSUWI4.js";
17
17
  import "./chunk-LGGE3LH7.js";
18
18
  export {
19
19
  assertWorkerKey,
package/dist/index.js CHANGED
@@ -28,7 +28,7 @@ import {
28
28
  sanitizeEndpoint,
29
29
  sanitizeProjectId,
30
30
  writeMcpServerEntry
31
- } from "./chunk-HNVCLEDF.js";
31
+ } from "./chunk-BKSEVNJH.js";
32
32
  import {
33
33
  FRAMEWORKS,
34
34
  FRAMEWORK_IDS,
@@ -59,7 +59,7 @@ import {
59
59
  registerUxCommands,
60
60
  registerWorkCommands,
61
61
  validateWorkerConfig
62
- } from "./chunk-5TO6PSO6.js";
62
+ } from "./chunk-AUWZX4P3.js";
63
63
  import {
64
64
  CONFIG_PATH,
65
65
  MushiCliError,
@@ -99,11 +99,11 @@ import {
99
99
  tryLoadKeyFromKeychain,
100
100
  trySaveKeyToKeychain,
101
101
  trySaveWorkerKey
102
- } from "./chunk-CGQE3GJK.js";
102
+ } from "./chunk-C6JKAD3Z.js";
103
103
  import {
104
104
  MUSHI_CLI_VERSION,
105
105
  MUSHI_MCP_PIN_SPEC
106
- } from "./chunk-ZVNRKEVP.js";
106
+ } from "./chunk-MEQSUWI4.js";
107
107
  import {
108
108
  CLOUD_API_ENDPOINT,
109
109
  CLOUD_MCP_OAUTH_URL,
@@ -1623,7 +1623,7 @@ async function checkOnboardingStatus(config, _consoleBase, cwd, doFetch = global
1623
1623
  }
1624
1624
  async function checkVersionDrift(cwd, doFetch) {
1625
1625
  const checks = [];
1626
- const { MUSHI_CLI_VERSION: MUSHI_CLI_VERSION2 } = await import("./version-I4APZBTF.js");
1626
+ const { MUSHI_CLI_VERSION: MUSHI_CLI_VERSION2 } = await import("./version-F3M2GCMT.js");
1627
1627
  if (MUSHI_CLI_VERSION2 === "0.0.0-dev") return checks;
1628
1628
  const parse2 = (v) => {
1629
1629
  const m = v.replace(/^[~^]/, "").match(/^(\d+)\.(\d+)\.(\d+)/);
@@ -2642,7 +2642,7 @@ async function maybeOfferConnect(credentials, options, _consoleBase) {
2642
2642
  if (p.isCancel(answer) || !answer) return;
2643
2643
  const endpoint = resolveCloudEndpoint(options.endpoint);
2644
2644
  try {
2645
- const { runConnect: runConnect2 } = await import("./connect-FNGAJ532.js");
2645
+ const { runConnect: runConnect2 } = await import("./connect-NQHKFL2H.js");
2646
2646
  const saved = loadConfig();
2647
2647
  const result = await runConnect2(
2648
2648
  {
@@ -7232,6 +7232,7 @@ import { createHmac, randomBytes } from "crypto";
7232
7232
  import { existsSync as existsSync3, mkdtempSync, readFileSync as readFileSync3, rmSync, writeFileSync as writeFileSync2 } from "fs";
7233
7233
  import { tmpdir } from "os";
7234
7234
  import { dirname as dirname2, join as join5, resolve as resolve3 } from "path";
7235
+ import { pathToFileURL } from "url";
7235
7236
  function supabaseCliVersion() {
7236
7237
  try {
7237
7238
  const r = spawnSync("supabase", ["--version"], { encoding: "utf8", timeout: 5e3 });
@@ -7323,6 +7324,7 @@ var SELFHOST_PLAN_SQL = [
7323
7324
  ""
7324
7325
  ].join("\n");
7325
7326
  var CLOUD_PROJECT_REF = "dxptnwrhwsqckaftyymj";
7327
+ var SELF_HOST_DOCS = "https://kensaur.us/mushi-mushi/docs/self-hosting";
7326
7328
  function buildSelfhostSteps(input, printOnly, internalToken, tmpDir) {
7327
7329
  const steps = [];
7328
7330
  const target = linkedTargetFlag(input.cliMajor);
@@ -7367,10 +7369,13 @@ function buildSelfhostSteps(input, printOnly, internalToken, tmpDir) {
7367
7369
  }
7368
7370
  steps.push({ label: "apply database migrations", args: ["db", "push", target], critical: true });
7369
7371
  const token = printOnly ? "<YOUR_INTERNAL_CALLER_SECRET>" : internalToken;
7370
- const secretLines = [`MUSHI_INTERNAL_CALLER_SECRET=${token}`];
7372
+ const secretLines = [`MUSHI_INTERNAL_CALLER_SECRET=${token}`, "MUSHI_INSTANCE_MODE=self-hosted"];
7371
7373
  if (input.anthropicKey) secretLines.push(`ANTHROPIC_API_KEY=${printOnly ? "sk-ant-..." : input.anthropicKey}`);
7372
7374
  if (input.openaiKey) secretLines.push(`OPENAI_API_KEY=${printOnly ? "sk-..." : input.openaiKey}`);
7373
- if (input.consoleUrl) secretLines.push(`ADMIN_BASE_URL=${input.consoleUrl}`);
7375
+ if (input.consoleUrl) {
7376
+ secretLines.push(`ADMIN_BASE_URL=${input.consoleUrl}`);
7377
+ secretLines.push(`MUSHI_ADMIN_ORIGIN_ALLOWLIST=${new URL(input.consoleUrl).origin}`);
7378
+ }
7374
7379
  const secretsFile = join5(tmpDir, "mushi-secrets.env");
7375
7380
  steps.push({
7376
7381
  label: `set function secrets (${secretLines.map((l) => l.split("=")[0]).join(", ")})`,
@@ -7387,7 +7392,7 @@ function buildSelfhostSteps(input, printOnly, internalToken, tmpDir) {
7387
7392
  files: [{ path: sqlFile, content: buildRuntimeConfigSql(input.supabaseUrl, token) }]
7388
7393
  });
7389
7394
  if (!input.skipDeploy) {
7390
- steps.push({ label: "deploy every edge function", args: ["functions", "deploy"] });
7395
+ steps.push({ label: "deploy every edge function", args: ["functions", "deploy"], stampDeployInfo: true });
7391
7396
  }
7392
7397
  return { ok: true, steps };
7393
7398
  }
@@ -7395,6 +7400,54 @@ function selfhostConfigPatch(existing, endpoint, consoleUrl2) {
7395
7400
  if (existing.apiKey && existing.endpoint !== endpoint) return null;
7396
7401
  return consoleUrl2 ? { endpoint, consoleUrl: consoleUrl2 } : { endpoint };
7397
7402
  }
7403
+ var DEPLOY_INFO_PATH = join5("packages", "server", "supabase", "functions", "_shared", "deploy-info.ts");
7404
+ async function loadDeployStamper(root) {
7405
+ const script = join5(root, "scripts", "deploy-edge-function.mjs");
7406
+ if (!existsSync3(script)) return null;
7407
+ try {
7408
+ const mod = await import(pathToFileURL(script).href);
7409
+ return typeof mod.deployInfoSource === "function" && typeof mod.resolveDeploySha === "function" ? mod : null;
7410
+ } catch {
7411
+ return null;
7412
+ }
7413
+ }
7414
+ function stampDeployInfo(root, stamper, now = /* @__PURE__ */ new Date()) {
7415
+ const file = join5(root, DEPLOY_INFO_PATH);
7416
+ let original;
7417
+ try {
7418
+ original = readFileSync3(file, "utf8");
7419
+ } catch {
7420
+ return null;
7421
+ }
7422
+ const sha = stamper.resolveDeploySha(root);
7423
+ writeFileSync2(file, stamper.deployInfoSource(sha, now.toISOString()));
7424
+ let restored = false;
7425
+ return {
7426
+ sha,
7427
+ restore: () => {
7428
+ if (restored) return;
7429
+ restored = true;
7430
+ writeFileSync2(file, original);
7431
+ }
7432
+ };
7433
+ }
7434
+ function runStamped(step, root, stamper, run) {
7435
+ const stamp = step.stampDeployInfo && stamper ? stampDeployInfo(root, stamper) : null;
7436
+ if (!stamp) return run();
7437
+ const onSignal = () => {
7438
+ stamp.restore();
7439
+ process.exit(130);
7440
+ };
7441
+ process.once("SIGINT", onSignal);
7442
+ process.once("exit", stamp.restore);
7443
+ try {
7444
+ return run();
7445
+ } finally {
7446
+ stamp.restore();
7447
+ process.removeListener("SIGINT", onSignal);
7448
+ process.removeListener("exit", stamp.restore);
7449
+ }
7450
+ }
7398
7451
  function readLinkedRef(supabaseDir) {
7399
7452
  try {
7400
7453
  const ref = readFileSync3(join5(supabaseDir, ".temp", "project-ref"), "utf8").trim();
@@ -7429,7 +7482,7 @@ function printNoLlmNote() {
7429
7482
  console.log(" and get a rule-based category and severity. Without a key there is no");
7430
7483
  console.log(" plain-English diagnosis, no fix drafts and no duplicate detection.");
7431
7484
  console.log(" Add one later: supabase secrets set ANTHROPIC_API_KEY=\u2026 (or OPENAI_API_KEY=\u2026),");
7432
- console.log(" or per project in the console under Settings \u2192 API Keys.");
7485
+ console.log(" or per app in the console under Settings \u2192 AI keys.");
7433
7486
  }
7434
7487
  async function runSelfhostUp(opts) {
7435
7488
  const root = resolve3(opts.cwd ?? ".");
@@ -7523,6 +7576,11 @@ async function runSelfhostUp(opts) {
7523
7576
  console.log("# LLM key (optional): add ANTHROPIC_API_KEY=\u2026 or OPENAI_API_KEY=\u2026 to mushi-secrets.env");
7524
7577
  console.log("");
7525
7578
  }
7579
+ if (!opts.skipDeploy) {
7580
+ console.log("# A plain `supabase functions deploy` leaves _shared/deploy-info.ts unstamped, so");
7581
+ console.log('# /health reports version "dev". `mushi selfhost up` stamps the commit for you.');
7582
+ console.log("");
7583
+ }
7526
7584
  console.log("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
7527
7585
  console.log("Then point the CLI at it and check it:");
7528
7586
  console.log(` mushi config endpoint ${endpoint}`);
@@ -7549,9 +7607,13 @@ async function runSelfhostUp(opts) {
7549
7607
  if (!llm.anthropicKey && !llm.openaiKey) printNoLlmNote();
7550
7608
  console.log("");
7551
7609
  const secrets = [internalToken, llm.anthropicKey ?? "", llm.openaiKey ?? ""];
7610
+ const stamper = built.steps.some((s) => s.stampDeployInfo) ? await loadDeployStamper(root) : null;
7611
+ if (!stamper && !opts.skipDeploy) {
7612
+ console.log(' This clone cannot stamp the deploy (no scripts/deploy-edge-function.mjs helpers): /health will report "dev".');
7613
+ }
7552
7614
  let failed = false;
7553
7615
  for (const step of built.steps) {
7554
- const result = runSupabase(step, { cwd: serverDir, secrets });
7616
+ const result = runStamped(step, root, stamper, () => runSupabase(step, { cwd: serverDir, secrets }));
7555
7617
  if (result.ok) continue;
7556
7618
  process.stderr.write(` ${result.stderr.split("\n").slice(0, 3).join("\n ")}
7557
7619
  `);
@@ -7579,6 +7641,8 @@ async function runSelfhostUp(opts) {
7579
7641
  } else {
7580
7642
  console.log(` OK /health ${probe.status} ${probe.latencyMs}ms`);
7581
7643
  }
7644
+ const health = await serverHealthCheck(endpoint, fetch);
7645
+ for (const line of formatSelfhostCheck(health)) console.log(` ${line}`);
7582
7646
  console.log("");
7583
7647
  if (failed) {
7584
7648
  console.log("Some steps failed (see above). Fix them and re-run, or deploy the rest by hand.");
@@ -7588,7 +7652,7 @@ async function runSelfhostUp(opts) {
7588
7652
  console.log("");
7589
7653
  console.log("Next steps:");
7590
7654
  if (!consoleUrl2) {
7591
- console.log(" 0. Serve the admin console (docs/SELF_HOSTED.md, step 4), then:");
7655
+ console.log(` 0. Serve the admin console (${SELF_HOST_DOCS}/admin-spa), then:`);
7592
7656
  console.log(" mushi config consoleUrl <console url>");
7593
7657
  console.log(" Without it, `mushi login` opens the Mushi Mushi Cloud console.");
7594
7658
  }
@@ -7663,13 +7727,101 @@ function runSelfhostSecrets(opts) {
7663
7727
  console.log(" MUSHI_INTERNAL_CALLER_SECRET");
7664
7728
  console.log(" Optional: ANTHROPIC_API_KEY or OPENAI_API_KEY (edit the file)");
7665
7729
  }
7730
+ function selfhostDoctorExitCode(checks) {
7731
+ if (checks.some((c) => c.status === "fail")) return 1;
7732
+ if (checks.some((c) => c.status === "warn")) return 2;
7733
+ return 0;
7734
+ }
7735
+ function isCloudEndpoint(endpoint) {
7736
+ return endpoint.includes(CLOUD_PROJECT_REF) || /^https:\/\/kensaur\.us\//.test(endpoint);
7737
+ }
7738
+ var HOSTED_CONSOLE = "https://kensaur.us/mushi-mushi/admin";
7739
+ async function consoleCheck(consoleUrl2, endpoint, doFetch) {
7740
+ if (isCloudEndpoint(endpoint)) return null;
7741
+ const base = { name: "console_reachable", label: "Console answers" };
7742
+ const url = consoleUrl2?.trim().replace(/\/+$/, "");
7743
+ if (!url) {
7744
+ return {
7745
+ ...base,
7746
+ status: "info",
7747
+ summary: "No console address saved, so `mushi login` opens Mushi Mushi Cloud.",
7748
+ hint: "mushi config consoleUrl <your console url>"
7749
+ };
7750
+ }
7751
+ if (url.startsWith(HOSTED_CONSOLE)) {
7752
+ return {
7753
+ ...base,
7754
+ status: "warn",
7755
+ summary: "The saved console is Mushi Mushi Cloud\u2019s, but the API is yours: `mushi login` would sign you in on Cloud.",
7756
+ hint: "mushi config consoleUrl <your console url>"
7757
+ };
7758
+ }
7759
+ try {
7760
+ const res = await doFetch(url, { signal: AbortSignal.timeout(8e3), redirect: "follow" });
7761
+ const type = res.headers.get("content-type") ?? "";
7762
+ if (res.ok && type.includes("text/html")) return { ...base, status: "pass", summary: `${url} answers (HTTP ${res.status}).` };
7763
+ return {
7764
+ ...base,
7765
+ status: "warn",
7766
+ summary: `${url} returned HTTP ${res.status}${type ? ` (${type.split(";")[0]})` : ""}, not the console page.`,
7767
+ hint: `Serve apps/admin/dist there with an index.html fallback (${SELF_HOST_DOCS}/admin-spa).`
7768
+ };
7769
+ } catch (err) {
7770
+ return {
7771
+ ...base,
7772
+ status: "warn",
7773
+ summary: `${url} did not answer: ${err instanceof Error ? err.message : String(err)}.`,
7774
+ hint: `Check the console is served at that address (${SELF_HOST_DOCS}/admin-spa).`
7775
+ };
7776
+ }
7777
+ }
7778
+ async function serverHealthCheck(endpoint, doFetch) {
7779
+ const base = { name: "server_deploy", label: "Server deploy" };
7780
+ try {
7781
+ const res = await doFetch(`${endpoint.replace(/\/+$/, "")}/health`, { signal: AbortSignal.timeout(8e3) });
7782
+ if (!res.ok) {
7783
+ return { ...base, status: "fail", summary: `/health returned HTTP ${res.status}.`, hint: "Check the `api` function deployed and its logs." };
7784
+ }
7785
+ const body = await res.json().catch(() => ({}));
7786
+ const version = typeof body.version === "string" ? body.version : null;
7787
+ if (body.mode === "hosted" && !isCloudEndpoint(endpoint)) {
7788
+ return {
7789
+ ...base,
7790
+ status: "warn",
7791
+ summary: "The server says it is Mushi Mushi Cloud, so the console labels this instance wrongly.",
7792
+ hint: "supabase secrets set MUSHI_INSTANCE_MODE=self-hosted (selfhost up sets it)."
7793
+ };
7794
+ }
7795
+ if (!version || version === "dev" || version === "unknown") {
7796
+ return {
7797
+ ...base,
7798
+ status: "info",
7799
+ summary: 'The deploy is not stamped with a commit (/health says "dev"), so you cannot tell which code runs.',
7800
+ hint: "Supabase: re-run `npx mushi-mushi selfhost up`; it stamps the commit. Compose builds are unstamped; compare the image with `git log -1`."
7801
+ };
7802
+ }
7803
+ return { ...base, status: "pass", summary: `Running commit ${version.slice(0, 7)}.` };
7804
+ } catch (err) {
7805
+ return {
7806
+ ...base,
7807
+ status: "fail",
7808
+ summary: `/health did not answer: ${err instanceof Error ? err.message : String(err)}.`,
7809
+ hint: `Check that ${endpoint} is deployed and reachable.`
7810
+ };
7811
+ }
7812
+ }
7813
+ var TAG = { pass: "OK ", info: "INFO", warn: "WARN", fail: "FAIL" };
7814
+ function formatSelfhostCheck(check) {
7815
+ const title = `${check.label ?? check.name}${check.appName ? ` (${check.appName})` : ""}`;
7816
+ const lines = [`${TAG[check.status]} ${title}: ${check.summary}`];
7817
+ if (check.hint && check.status !== "pass") lines.push(` \u2192 ${check.hint}`);
7818
+ return lines;
7819
+ }
7666
7820
  async function runSelfhostDoctor(opts) {
7667
7821
  const config = loadConfig();
7668
- const endpoint = opts.endpoint || config.endpoint;
7822
+ const endpoint = (opts.endpoint || config.endpoint)?.replace(/\/+$/, "");
7669
7823
  if (!endpoint) {
7670
- process.stderr.write(
7671
- "error: endpoint required \u2014 pass --endpoint or run `mushi login` first.\n"
7672
- );
7824
+ process.stderr.write("error: endpoint required \u2014 pass --endpoint or run `mushi login` first.\n");
7673
7825
  process.exit(1);
7674
7826
  }
7675
7827
  let serverChecks = [];
@@ -7685,9 +7837,10 @@ async function runSelfhostDoctor(opts) {
7685
7837
  serverChecks = [
7686
7838
  {
7687
7839
  name: "server_doctor",
7840
+ label: "Server doctor",
7688
7841
  status: "fail",
7689
7842
  summary: `/v1/admin/doctor returned HTTP ${res.status}`,
7690
- hint: "401 \u2192 check API key scope (needs mcp:read or admin); 403 \u2192 key not owner of this project"
7843
+ hint: res.status === 401 || res.status === 403 ? `Sign the CLI in to this server: mushi login --endpoint ${endpoint} (the key needs mcp:read).` : "Check the `api` function logs."
7691
7844
  }
7692
7845
  ];
7693
7846
  }
@@ -7695,28 +7848,28 @@ async function runSelfhostDoctor(opts) {
7695
7848
  serverChecks = [
7696
7849
  {
7697
7850
  name: "server_doctor",
7851
+ label: "Server doctor",
7698
7852
  status: "fail",
7699
7853
  summary: `unreachable: ${err instanceof Error ? err.message : String(err)}`,
7700
7854
  hint: `Check that ${endpoint} is deployed and reachable.`
7701
7855
  }
7702
7856
  ];
7703
7857
  }
7858
+ const [health, consoleLine] = await Promise.all([
7859
+ serverHealthCheck(endpoint, fetch),
7860
+ consoleCheck(opts.consoleUrl || config.consoleUrl, endpoint, fetch)
7861
+ ]);
7862
+ const checks = [health, ...consoleLine ? [consoleLine] : [], ...serverChecks];
7863
+ const code = selfhostDoctorExitCode(checks);
7704
7864
  if (opts.json) {
7705
- const overallStatus = serverChecks.some((c) => c.status === "fail") ? "fail" : serverChecks.some((c) => c.status === "warn") ? "warn" : "pass";
7706
- console.log(JSON.stringify({ status: overallStatus, checks: serverChecks }, null, 2));
7865
+ console.log(JSON.stringify({ status: code === 1 ? "fail" : code === 2 ? "warn" : "pass", checks }, null, 2));
7707
7866
  } else {
7708
- for (const check of serverChecks) {
7709
- const tag = check.status === "pass" ? "OK " : check.status === "warn" ? "WARN" : "FAIL";
7710
- console.log(`${tag} ${check.name} ${check.summary}`);
7711
- if (check.hint && check.status !== "pass") {
7712
- console.log(` \u2192 Fix: ${check.hint}`);
7713
- }
7867
+ const rank = { fail: 0, warn: 1, info: 2, pass: 3 };
7868
+ for (const check of [...checks].sort((a, b) => rank[a.status] - rank[b.status])) {
7869
+ for (const line of formatSelfhostCheck(check)) console.log(line);
7714
7870
  }
7715
7871
  }
7716
- const hasFailure = serverChecks.some((c) => c.status === "fail");
7717
- const hasWarn = serverChecks.some((c) => c.status === "warn");
7718
- if (hasFailure) process.exit(1);
7719
- if (hasWarn) process.exit(2);
7872
+ if (code !== 0) process.exit(code);
7720
7873
  }
7721
7874
  function registerSelfhostCommands(program2) {
7722
7875
  const selfhost = program2.command("selfhost").description("Self-hosted deployment tools");
@@ -7753,10 +7906,10 @@ Examples:
7753
7906
  ).option(
7754
7907
  "--endpoint <url>",
7755
7908
  `Mushi API endpoint (default: from ${CONFIG_PATH})`
7756
- ).option("--json", "Machine-readable JSON output").addHelpText(
7909
+ ).option("--console-url <url>", "Console address to check (default: consoleUrl from the CLI config)").option("--json", "Machine-readable JSON output").addHelpText(
7757
7910
  "after",
7758
7911
  `
7759
- Exit codes: 0 all pass \xB7 2 warnings only \xB7 1 any hard failure
7912
+ Exit codes: 0 healthy (INFO lines are optional extras) \xB7 2 warnings only \xB7 1 any hard failure
7760
7913
 
7761
7914
  Examples:
7762
7915
  mushi selfhost doctor
package/dist/init.js CHANGED
@@ -13,10 +13,10 @@ import {
13
13
  sampleBugSnippet,
14
14
  sanitizeSecret,
15
15
  snippetTarget
16
- } from "./chunk-6ZQFL7SD.js";
16
+ } from "./chunk-2N7XJA5W.js";
17
17
  import "./chunk-LFP3NPZT.js";
18
- import "./chunk-JXGVZWRL.js";
19
- import "./chunk-LWFREQOK.js";
18
+ import "./chunk-S5YMLTMA.js";
19
+ import "./chunk-XYTPKC65.js";
20
20
  import "./chunk-AWASJDQI.js";
21
21
  import "./chunk-2DMHQVRU.js";
22
22
  export {
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  MUSHI_CLI_VERSION,
4
4
  MUSHI_MCP_PIN_SPEC
5
- } from "./chunk-ZVNRKEVP.js";
5
+ } from "./chunk-MEQSUWI4.js";
6
6
  export {
7
7
  MUSHI_CLI_VERSION,
8
8
  MUSHI_MCP_PIN_SPEC
package/dist/version.d.ts CHANGED
@@ -14,6 +14,6 @@ declare const MUSHI_CLI_VERSION: string;
14
14
  * setup refreshes the pin. Synced to packages/mcp/package.json by
15
15
  * `scripts/sync-mcp-pin.mjs` — never hand-edit the version.
16
16
  */
17
- declare const MUSHI_MCP_PIN_SPEC = "@mushi-mushi/mcp@0.31.5";
17
+ declare const MUSHI_MCP_PIN_SPEC = "@mushi-mushi/mcp@0.31.6";
18
18
 
19
19
  export { MUSHI_CLI_VERSION, MUSHI_MCP_PIN_SPEC };
package/dist/version.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  MUSHI_CLI_VERSION,
3
3
  MUSHI_MCP_PIN_SPEC
4
- } from "./chunk-LWFREQOK.js";
4
+ } from "./chunk-XYTPKC65.js";
5
5
  export {
6
6
  MUSHI_CLI_VERSION,
7
7
  MUSHI_MCP_PIN_SPEC
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  runInit
3
- } from "./chunk-6ZQFL7SD.js";
3
+ } from "./chunk-2N7XJA5W.js";
4
4
  import {
5
5
  FLAGS_HELP,
6
6
  UNKNOWN_COMMAND_EXIT,
@@ -11,8 +11,8 @@ import {
11
11
  scaffoldTemplate
12
12
  } from "./chunk-4JF7C3MY.js";
13
13
  import "./chunk-LFP3NPZT.js";
14
- import "./chunk-JXGVZWRL.js";
15
- import "./chunk-LWFREQOK.js";
14
+ import "./chunk-S5YMLTMA.js";
15
+ import "./chunk-XYTPKC65.js";
16
16
  import "./chunk-AWASJDQI.js";
17
17
  import "./chunk-2DMHQVRU.js";
18
18
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mushi-mushi/cli",
3
- "version": "0.40.3",
3
+ "version": "0.40.4",
4
4
  "license": "MIT",
5
5
  "description": "Mushi Mushi CLI: SDK setup, MCP wiring, triage. One place to improve AI-built apps: fix bugs, smooth user journeys and clean up the code.",
6
6
  "bin": {
@@ -1,8 +0,0 @@
1
- // src/version.ts
2
- var MUSHI_CLI_VERSION = true ? "0.40.3" : "0.0.0-dev";
3
- var MUSHI_MCP_PIN_SPEC = "@mushi-mushi/mcp@0.31.5";
4
-
5
- export {
6
- MUSHI_CLI_VERSION,
7
- MUSHI_MCP_PIN_SPEC
8
- };
@@ -1,10 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- // src/version.ts
4
- var MUSHI_CLI_VERSION = true ? "0.40.3" : "0.0.0-dev";
5
- var MUSHI_MCP_PIN_SPEC = "@mushi-mushi/mcp@0.31.5";
6
-
7
- export {
8
- MUSHI_CLI_VERSION,
9
- MUSHI_MCP_PIN_SPEC
10
- };