@mushi-mushi/cli 0.43.0 → 0.44.0

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 (41) hide show
  1. package/README.md +5 -3
  2. package/dist/{chunk-AEXZYEUS.js → chunk-25YBYYYC.js} +3085 -345
  3. package/dist/{chunk-X64CFG54.js → chunk-2XODEIM4.js} +0 -1
  4. package/dist/chunk-6XKFNK4C.js +8 -0
  5. package/dist/{connect-HSL2EUEV.js → chunk-NEFF6WK5.js} +40 -7
  6. package/dist/chunk-O6RN5FT5.js +178 -0
  7. package/dist/{chunk-AKUYV2CR.js → chunk-T3Q44NPC.js} +444 -16
  8. package/dist/{chunk-UZQZU5OP.js → chunk-ZL2HSPR5.js} +12 -8
  9. package/dist/connect-HTAUIXDX.js +13 -0
  10. package/dist/{daemon-ZQ6WYRLD.js → daemon-VDYY6GWG.js} +6 -5
  11. package/dist/detect.d.ts +2 -1
  12. package/dist/{endpoint-KN5YEANQ.js → endpoint-BPPL6DJN.js} +3 -5
  13. package/dist/index.d.ts +1 -1
  14. package/dist/index.js +3413 -4840
  15. package/dist/init.d.ts +2 -1
  16. package/dist/init.js +6 -5
  17. package/dist/version.d.ts +6 -5
  18. package/dist/version.js +1 -1
  19. package/dist/wizard-args.d.ts +2 -1
  20. package/dist/wizard-bin.d.ts +2 -1
  21. package/dist/wizard-bin.js +6 -5
  22. package/package.json +5 -5
  23. package/templates/node/.env.example +1 -1
  24. package/templates/svelte/.env.example +1 -1
  25. package/templates/svelte/package.json +4 -4
  26. package/templates/svelte/src/App.svelte +1 -1
  27. package/templates/vue/.env.example +1 -1
  28. package/templates/vue/package.json +2 -2
  29. package/templates/vue/src/App.vue +1 -1
  30. package/dist/chunk-25P6NAME.js +0 -436
  31. package/dist/chunk-CG5KPP4S.js +0 -504
  32. package/dist/chunk-JQQACG3P.js +0 -10
  33. package/dist/chunk-LHSWFJOB.js +0 -765
  34. package/dist/chunk-WJ7ZTOF7.js +0 -8
  35. package/dist/chunk-X6SC4JKO.js +0 -67
  36. package/dist/chunk-ZDAN3RYF.js +0 -85
  37. package/dist/connect-OPWVFSNG.js +0 -13
  38. package/dist/detect-SOXPECZ3.js +0 -25
  39. package/dist/endpoint-XZHMF6EZ.js +0 -21
  40. package/dist/snippet-inject-BQO5I2RN.js +0 -15
  41. package/dist/version-JUEQJNGV.js +0 -9
@@ -1,41 +1,39 @@
1
- import {
2
- ENTRY_CANDIDATES,
3
- MUSHI_MARKER_START,
4
- injectSnippet
5
- } from "./chunk-LFP3NPZT.js";
6
1
  import {
7
2
  CLI_KEY_LABEL,
8
3
  CLI_KEY_SCOPES,
4
+ FULL_CLI_KEY_SCOPES,
9
5
  SDK_KEY_LABEL,
10
6
  SDK_KEY_SCOPES,
11
- apiCall,
12
7
  apiKeyHeaders,
8
+ describeUnsafeSdkKey,
9
+ editorKeyCommand,
10
+ fetchIngestSetup,
11
+ probeKeyScope,
12
+ sanitizeCliCredentials,
13
+ sanitizeEndpoint
14
+ } from "./chunk-O6RN5FT5.js";
15
+ import {
16
+ apiCall,
13
17
  apiKeyHint,
14
18
  cliSetupDeepLink,
15
19
  consoleUrl,
16
- describeUnsafeSdkKey,
17
- editorKeyCommand,
18
20
  ensureClientId,
19
- fetchIngestSetup,
20
21
  loadConfig,
21
22
  maybeShowTelemetryNotice,
22
23
  openInBrowser,
23
24
  peekConfig,
24
- probeKeyScope,
25
25
  projectIdHint,
26
26
  reportsUrl,
27
27
  resolveConsoleUrl,
28
28
  resolveConsoleUrlSync,
29
29
  resolveProfileName,
30
- sanitizeCliCredentials,
31
- sanitizeEndpoint,
32
30
  saveConfig,
33
31
  savedSdkKeyFor,
34
32
  trySaveKeyToKeychain
35
- } from "./chunk-LHSWFJOB.js";
33
+ } from "./chunk-ZL2HSPR5.js";
36
34
  import {
37
35
  MUSHI_CLI_VERSION
38
- } from "./chunk-WJ7ZTOF7.js";
36
+ } from "./chunk-6XKFNK4C.js";
39
37
  import {
40
38
  FRAMEWORKS,
41
39
  detectFramework,
@@ -53,7 +51,12 @@ import {
53
51
  firstEndpoint,
54
52
  normalizeEndpoint,
55
53
  resolveCloudEndpoint
56
- } from "./chunk-X64CFG54.js";
54
+ } from "./chunk-2XODEIM4.js";
55
+ import {
56
+ ENTRY_CANDIDATES,
57
+ MUSHI_MARKER_START,
58
+ injectSnippet
59
+ } from "./chunk-LFP3NPZT.js";
57
60
 
58
61
  // src/init.ts
59
62
  import * as p from "@clack/prompts";
@@ -296,6 +299,38 @@ async function mintProjectKey(endpoint, cliToken, projectId, opts = {}) {
296
299
  res.status
297
300
  );
298
301
  }
302
+ async function revokeProjectKey(endpoint, cliToken, projectId, keyPrefix, newKeyId) {
303
+ const base = trimTrailingSlash(endpoint);
304
+ const url = `${base}/v1/cli/projects/${encodeURIComponent(projectId)}/keys/${encodeURIComponent(keyPrefix)}/revoke`;
305
+ let res;
306
+ try {
307
+ res = await deviceFetch(url, {
308
+ method: "DELETE",
309
+ headers: {
310
+ ...cliAuthHeaders(cliToken),
311
+ "Content-Type": "application/json"
312
+ },
313
+ body: newKeyId ? JSON.stringify({ newKeyId }) : void 0
314
+ });
315
+ } catch (err) {
316
+ throw new DeviceAuthRequestError(
317
+ "revoke_key",
318
+ `Could not reach ${url}: ${err instanceof Error ? err.message : String(err)}`
319
+ );
320
+ }
321
+ const json = await res.json().catch(() => null);
322
+ if (res.ok && json?.ok) {
323
+ return {
324
+ revoked: json.revoked ?? 0,
325
+ revokedAt: json.revokedAt
326
+ };
327
+ }
328
+ throw new DeviceAuthRequestError(
329
+ "revoke_key",
330
+ json?.error?.message ?? `Could not revoke key (HTTP ${res.status}).`,
331
+ res.status
332
+ );
333
+ }
299
334
 
300
335
  // src/auth-ui.ts
301
336
  var LINE = "\u2500".repeat(58);
@@ -323,8 +358,109 @@ function printAuthBanner(userCode, verificationUri) {
323
358
  console.log(" \u23F3 Waiting for browser approval\u2026 (Ctrl+C to cancel)");
324
359
  console.log("");
325
360
  }
361
+ function printAuthApproved() {
362
+ console.log("");
363
+ console.log(" \u2713 Approved! Continuing setup in this terminal\u2026");
364
+ console.log("");
365
+ }
366
+ function printAuthFailed(reason, detail) {
367
+ console.log("");
368
+ if (reason === "denied") {
369
+ console.error(" \u2717 Browser sign-in was denied.");
370
+ console.error(" If that was a mistake, run mushi login again.");
371
+ } else if (reason === "timeout") {
372
+ console.error(" \u2717 Browser sign-in timed out (10 minutes elapsed).");
373
+ console.error(" Run mushi login again \u2014 a new code will be generated.");
374
+ } else {
375
+ console.error(` \u2717 Browser sign-in failed: ${detail ?? "unknown error"}`);
376
+ console.error(" Run mushi login again, or use:");
377
+ console.error(" mushi login --api-key <key> --project-id <uuid>");
378
+ }
379
+ console.log("");
380
+ }
381
+
382
+ // src/env-key-override.ts
383
+ function envKeyOverrideLines(env, savedKey, platform = process.platform) {
384
+ const envKey = env.MUSHI_API_KEY?.trim();
385
+ if (!envKey || savedKey && envKey === savedKey) return [];
386
+ const where = platform === "win32" ? 'Remove it under Windows Settings \u2192 System \u2192 About \u2192 Advanced system settings \u2192 Environment Variables, or open a new terminal after `[Environment]::SetEnvironmentVariable("MUSHI_API_KEY", $null, "User")` in PowerShell.' : "Remove the `export MUSHI_API_KEY=\u2026` line from your shell profile, or run `unset MUSHI_API_KEY` in this terminal.";
387
+ return [
388
+ `\u26A0 MUSHI_API_KEY is set in your environment (${envKey.slice(0, 12)}\u2026), and it overrides ${savedKey ? `the saved key (${savedKey.slice(0, 12)}\u2026)` : "the saved key"}.`,
389
+ ` Commands in this terminal use the environment key. ${where}`
390
+ ];
391
+ }
326
392
 
327
393
  // src/login.ts
394
+ function getPostLoginBannerMessage(opts) {
395
+ if (opts.suppressPostLoginBanner) return null;
396
+ if (opts.upgradeScope) {
397
+ return " Key upgraded! Re-run 'mushi setup' to update your IDE's MCP config, then restart the IDE.";
398
+ }
399
+ return " Run 'mushi init' to set up the SDK in this project.";
400
+ }
401
+ function printPostLoginBanner(opts) {
402
+ const message = getPostLoginBannerMessage(opts);
403
+ if (message) console.log(message);
404
+ }
405
+ var MAX_CONSECUTIVE_ERRORS = 5;
406
+ async function pollUntilApproved(endpoint, deviceData, deps) {
407
+ const sleep = deps.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
408
+ const now = deps.now ?? Date.now;
409
+ let pollIntervalMs = (deviceData.interval ?? 5) * 1e3;
410
+ const deadline = now() + (deviceData.expires_in ?? 600) * 1e3;
411
+ let consecutiveErrors = 0;
412
+ let firstPoll = true;
413
+ while (now() < deadline) {
414
+ if (!firstPoll) {
415
+ await sleep(pollIntervalMs);
416
+ }
417
+ firstPoll = false;
418
+ const outcome = await deps.poll(endpoint, deviceData.device_code);
419
+ switch (outcome.status) {
420
+ case "approved":
421
+ return { status: "approved", cliToken: outcome.cliToken };
422
+ case "pending":
423
+ consecutiveErrors = 0;
424
+ continue;
425
+ case "slow_down":
426
+ consecutiveErrors = 0;
427
+ pollIntervalMs = Math.max(pollIntervalMs, outcome.retryAfterMs);
428
+ continue;
429
+ case "error":
430
+ if (outcome.retryable) {
431
+ consecutiveErrors += 1;
432
+ if (consecutiveErrors < MAX_CONSECUTIVE_ERRORS) continue;
433
+ }
434
+ return { status: "error", message: outcome.message };
435
+ case "denied":
436
+ return { status: "denied" };
437
+ case "expired":
438
+ return { status: "timeout" };
439
+ }
440
+ }
441
+ return { status: "timeout" };
442
+ }
443
+ async function resolveProjectChoice(projectsList, ask) {
444
+ if (projectsList.length > 0) {
445
+ console.log("");
446
+ console.log(" Your projects:");
447
+ projectsList.forEach((p2, i) => {
448
+ console.log(` ${i + 1}. ${p2.name} (${p2.id})`);
449
+ });
450
+ console.log(` ${projectsList.length + 1}. Create a new project`);
451
+ console.log("");
452
+ const choice = await ask(` Pick a project [1-${projectsList.length + 1}]: `);
453
+ const num = parseInt(choice, 10);
454
+ if (num >= 1 && num <= projectsList.length) {
455
+ const picked = projectsList[num - 1];
456
+ return { kind: "picked", id: picked.id, name: picked.name };
457
+ }
458
+ }
459
+ console.log("");
460
+ const newName = (await ask(" Project name: ")).trim();
461
+ if (!newName) return { kind: "empty_name" };
462
+ return { kind: "create", name: newName };
463
+ }
328
464
  function slugify(value) {
329
465
  return value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
330
466
  }
@@ -341,6 +477,196 @@ function chooseProjectNonInteractive(projects, preferredName, appFolder = true)
341
477
  if (!appFolder && projects.length > 0) return { kind: "ask" };
342
478
  return { kind: "new", name: preferredName };
343
479
  }
480
+ async function runLogin(opts = {}) {
481
+ const { CLOUD_API_ENDPOINT: CLOUD_API_ENDPOINT2, resolveCloudEndpoint: resolveCloudEndpoint2 } = await import("./endpoint-BPPL6DJN.js");
482
+ const saved = loadConfig().endpoint;
483
+ const endpoint = opts.endpoint ? resolveCloudEndpoint2(opts.endpoint) : saved ? resolveCloudEndpoint2(saved) : CLOUD_API_ENDPOINT2;
484
+ const consoleBase = await resolveConsoleUrl();
485
+ let apiKey = opts.apiKey;
486
+ let projectId = opts.projectId;
487
+ if (apiKey) {
488
+ const config2 = loadConfig();
489
+ config2.apiKey = apiKey;
490
+ config2.endpoint = endpoint;
491
+ if (projectId) config2.projectId = projectId;
492
+ config2.consoleUrl = consoleBase;
493
+ saveConfig(config2);
494
+ console.log("");
495
+ console.log(" \u2713 Credentials saved.");
496
+ const verifyResult = await apiCall("/v1/sync/whoami", { apiKey, endpoint, projectId });
497
+ if (!verifyResult.ok) {
498
+ console.warn(` \u26A0 Key saved, but verification failed: ${verifyResult.error?.message ?? "unknown error"}`);
499
+ console.warn(` Check your key at: ${cliSetupDeepLink(consoleBase)}`);
500
+ return;
501
+ }
502
+ const d = verifyResult.data;
503
+ if (d.project_name) {
504
+ if (!projectId && d.project_id) {
505
+ config2.projectId = d.project_id;
506
+ saveConfig(config2);
507
+ }
508
+ console.log(` \u2713 Project: ${d.project_name} (${d.project_id})`);
509
+ }
510
+ console.log(` \u2713 Endpoint: ${endpoint}`);
511
+ console.log("");
512
+ if (!opts.suppressPostLoginBanner) {
513
+ console.log(" Run 'mushi whoami' to verify \xB7 'mushi init' to set up the SDK");
514
+ }
515
+ return;
516
+ }
517
+ if (!opts.suppressPostLoginBanner) {
518
+ console.log("");
519
+ }
520
+ if (opts.upgradeScope) {
521
+ console.log(" Mushi login \u2014 scope upgrade");
522
+ 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");
523
+ console.log(" Re-authenticating to mint a new key with report:write + mcp:read + mcp:write scopes.");
524
+ console.log(" This lets the CLI admin commands (including writes) and MCP server both work with a single key.");
525
+ console.log("");
526
+ } else if (!opts.suppressPostLoginBanner) {
527
+ console.log(" Mushi login");
528
+ console.log(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
529
+ }
530
+ let deviceData;
531
+ try {
532
+ deviceData = await startDeviceAuth(endpoint, ensureClientId());
533
+ } catch (err) {
534
+ process.stderr.write(`
535
+ error: Could not start login session: ${err instanceof Error ? err.message : String(err)}
536
+ `);
537
+ process.stderr.write(` Fallback: mushi login --api-key <key> --project-id <uuid>
538
+ `);
539
+ process.exit(1);
540
+ }
541
+ const verifyUrl = deviceData.verification_uri;
542
+ if (opts.browser !== false) {
543
+ try {
544
+ await openInBrowser(verifyUrl);
545
+ } catch {
546
+ }
547
+ }
548
+ printAuthBanner(deviceData.user_code, verifyUrl);
549
+ const pollResult = await pollUntilApproved(endpoint, deviceData, {
550
+ poll: pollDeviceToken
551
+ });
552
+ if (pollResult.status !== "approved") {
553
+ if (pollResult.status === "denied") printAuthFailed("denied");
554
+ else if (pollResult.status === "error") printAuthFailed("error", pollResult.message);
555
+ else printAuthFailed("timeout");
556
+ process.exit(1);
557
+ }
558
+ const cliToken = pollResult.cliToken;
559
+ printAuthApproved();
560
+ const projectsList = await listProjects(endpoint, cliToken);
561
+ let chosenProjectId = projectId;
562
+ let chosenProjectName;
563
+ const mintScopes = opts.upgradeScope ? FULL_CLI_KEY_SCOPES : CLI_KEY_SCOPES;
564
+ if (!chosenProjectId) {
565
+ let choice;
566
+ if (process.stdin.isTTY) {
567
+ const { createInterface } = await import("readline");
568
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
569
+ const ask = (q) => new Promise((resolve2) => rl.question(q, (a) => resolve2(a.trim())));
570
+ choice = await resolveProjectChoice(projectsList, ask);
571
+ rl.close();
572
+ } else {
573
+ const { readPackageJson: readPackageJson2 } = await import("./detect.js");
574
+ const cwd = process.cwd();
575
+ const pkg = readPackageJson2(cwd);
576
+ const { existsSync: existsSync3 } = await import("fs");
577
+ const { join: join3 } = await import("path");
578
+ const nonInteractive = chooseProjectNonInteractive(
579
+ projectsList,
580
+ defaultProjectName(pkg?.name, cwd),
581
+ Boolean(pkg) || existsSync3(join3(cwd, ".git"))
582
+ );
583
+ if (nonInteractive.kind === "ask") {
584
+ process.stderr.write(
585
+ `
586
+ error: This folder is not an app (no package.json or .git), so no project was picked or created.
587
+ Run it again from your app's folder, or name the project:
588
+ ` + projectsList.map((p2) => ` mushi login --project-id ${p2.id} # ${p2.name}
589
+ `).join("")
590
+ );
591
+ process.exit(2);
592
+ }
593
+ choice = nonInteractive.kind === "existing" ? { kind: "picked", id: nonInteractive.id, name: nonInteractive.name } : { kind: "create", name: nonInteractive.name };
594
+ console.log(
595
+ choice.kind === "picked" ? ` Using project "${choice.name}" (matches this folder \u2014 pass --project-id to pick another).` : ` Creating project "${choice.name}" (no project matches this folder \u2014 pass --project-id to use an existing one).`
596
+ );
597
+ }
598
+ if (choice.kind === "empty_name") {
599
+ process.stderr.write("\nerror: Project name is required.\n");
600
+ process.exit(2);
601
+ }
602
+ if (choice.kind === "picked") {
603
+ chosenProjectId = choice.id;
604
+ chosenProjectName = choice.name;
605
+ } else {
606
+ try {
607
+ const created = await createProject(endpoint, cliToken, choice.name, { scopes: mintScopes });
608
+ chosenProjectId = created.id;
609
+ chosenProjectName = created.name;
610
+ apiKey = created.apiKey ?? void 0;
611
+ console.log(` \u2713 Created project "${chosenProjectName}"`);
612
+ } catch (err) {
613
+ process.stderr.write(`
614
+ error: Could not create project: ${err instanceof Error ? err.message : String(err)}
615
+ `);
616
+ process.exit(1);
617
+ }
618
+ }
619
+ }
620
+ let mintError = null;
621
+ if (!apiKey && chosenProjectId) {
622
+ try {
623
+ apiKey = await mintProjectKey(endpoint, cliToken, chosenProjectId, { scopes: mintScopes }) ?? void 0;
624
+ } catch (err) {
625
+ mintError = err instanceof Error ? err.message : String(err);
626
+ }
627
+ }
628
+ if (mintError) {
629
+ process.stderr.write(`
630
+ \u2717 No key was created for ${chosenProjectName ?? chosenProjectId}.
631
+ ${mintError}
632
+ `);
633
+ if (/owner or admin|forbidden|403/i.test(mintError) && !/approved as/i.test(mintError)) {
634
+ process.stderr.write(" The account that approved in the browser is not an owner or admin of this app. Ask an owner to make it an admin on Team, or approve with an owner or admin account.\n");
635
+ }
636
+ process.stderr.write(` Then run again: mushi login${opts.upgradeScope ? " --upgrade-scope" : ""}${chosenProjectId ? ` --project-id ${chosenProjectId}` : ""}
637
+ `);
638
+ process.stderr.write(" Your saved login was not changed.\n\n");
639
+ process.exit(1);
640
+ }
641
+ const config = loadConfig();
642
+ config.endpoint = endpoint;
643
+ config.consoleUrl = consoleBase;
644
+ if (chosenProjectId) config.projectId = chosenProjectId;
645
+ if (apiKey) config.apiKey = apiKey;
646
+ saveConfig(config);
647
+ if (apiKey) {
648
+ const profile = resolveProfileName(void 0, config.activeProfile);
649
+ trySaveKeyToKeychain(apiKey, profile);
650
+ }
651
+ console.log("");
652
+ if (chosenProjectName) console.log(` \u2713 Project: ${chosenProjectName}`);
653
+ if (apiKey) {
654
+ if (opts.upgradeScope) {
655
+ console.log(` \u2713 Full-scope CLI key saved (${apiKey.slice(0, 12)}\u2026)`);
656
+ console.log(` Scopes: report:write \xB7 mcp:read \xB7 mcp:write \u2014 SDK + MCP + admin CLI (incl. writes) all work with this key`);
657
+ for (const line of envKeyOverrideLines(process.env, apiKey)) console.log(` ${line}`);
658
+ } else {
659
+ console.log(` \u2713 CLI key saved (${apiKey.slice(0, 12)}\u2026)`);
660
+ for (const line of envKeyOverrideLines(process.env, apiKey)) console.log(` ${line}`);
661
+ console.log(` Scopes: report:write \xB7 mcp:read \u2014 SDK ingest + MCP read tools.`);
662
+ console.log(` Admin writes (mushi work, fix merge, billing cap, pipeline start) need: mushi login --upgrade-scope${chosenProjectId ? ` --project-id ${chosenProjectId}` : ""}`);
663
+ }
664
+ } else {
665
+ console.log(` \u2139 Get an SDK key at: ${apiKeyHint(consoleBase)}`);
666
+ }
667
+ console.log("");
668
+ printPostLoginBanner(opts);
669
+ }
344
670
 
345
671
  // src/freshness.ts
346
672
  var REGISTRY = "https://registry.npmjs.org";
@@ -1166,6 +1492,92 @@ function fixHintForCheck(name) {
1166
1492
  if (name.startsWith("[mcp]")) return FIX_HINTS["[mcp]"];
1167
1493
  return void 0;
1168
1494
  }
1495
+ async function checkOnboardingStatus(config, _consoleBase, cwd, doFetch = globalThis.fetch) {
1496
+ if (!config.apiKey || !config.projectId || !config.endpoint) {
1497
+ if (config.apiKey && config.endpoint) {
1498
+ return {
1499
+ nextAction: "Select or create a project: run `mushi project create` or pick one with `mushi project list`",
1500
+ ctaPath: "/onboarding?tab=steps&setup=cli",
1501
+ done: false
1502
+ };
1503
+ }
1504
+ return {
1505
+ nextAction: "Sign in to Mushi: run `npx mushi-mushi` (browser opens automatically \u2014 do NOT type the code in the terminal)",
1506
+ ctaPath: "/onboarding?tab=steps&setup=cli",
1507
+ done: false
1508
+ };
1509
+ }
1510
+ try {
1511
+ const { readFile } = await import("fs/promises");
1512
+ const { join: join3, resolve: resolve2 } = await import("path");
1513
+ const root = resolve2(cwd);
1514
+ let envContent = "";
1515
+ for (const f of [".env.local", ".env"]) {
1516
+ try {
1517
+ envContent = await readFile(join3(root, f), "utf8");
1518
+ break;
1519
+ } catch {
1520
+ }
1521
+ }
1522
+ const hasEnvVars = /(?:VITE_|NEXT_PUBLIC_|EXPO_PUBLIC_|NUXT_PUBLIC_)?MUSHI_PROJECT_ID=/.test(
1523
+ envContent
1524
+ );
1525
+ if (!hasEnvVars) {
1526
+ return {
1527
+ nextAction: "Write env vars to your app: run `npx mushi-mushi` or `mushi connect --write-env`",
1528
+ ctaPath: "/onboarding?tab=sdk",
1529
+ done: false
1530
+ };
1531
+ }
1532
+ } catch {
1533
+ }
1534
+ try {
1535
+ const sdkCheck = await checkSdkInstall(cwd);
1536
+ if (sdkCheck && !sdkCheck.ok) {
1537
+ return {
1538
+ nextAction: `Install the Mushi SDK: ${sdkCheck.detail}`,
1539
+ ctaPath: "/onboarding?tab=sdk",
1540
+ done: false
1541
+ };
1542
+ }
1543
+ } catch {
1544
+ }
1545
+ try {
1546
+ const data = await fetchIngestSetup(
1547
+ { endpoint: config.endpoint, apiKey: config.apiKey, projectId: config.projectId },
1548
+ doFetch
1549
+ );
1550
+ if (data) {
1551
+ const steps = data.steps ?? [];
1552
+ const incomplete = steps.find((s) => s.required && !s.complete);
1553
+ if (incomplete) {
1554
+ const tabMap = {
1555
+ project_created: "/onboarding?tab=steps&setup=cli",
1556
+ api_key_generated: "/onboarding?tab=verify",
1557
+ sdk_installed: "/onboarding?tab=sdk",
1558
+ first_report_received: "/onboarding?tab=verify"
1559
+ };
1560
+ const tab = tabMap[incomplete.id] ?? "/onboarding?tab=verify";
1561
+ return {
1562
+ nextAction: incomplete.hint ?? `Complete setup step: ${incomplete.label}`,
1563
+ ctaPath: tab,
1564
+ done: false
1565
+ };
1566
+ }
1567
+ return {
1568
+ nextAction: "All 4 required setup steps are complete! Open the console to explore.",
1569
+ ctaPath: "/reports",
1570
+ done: true
1571
+ };
1572
+ }
1573
+ } catch {
1574
+ }
1575
+ return {
1576
+ nextAction: "Open the onboarding wizard in the console to check your setup status.",
1577
+ ctaPath: "/onboarding",
1578
+ done: false
1579
+ };
1580
+ }
1169
1581
  async function checkVersionDrift(cwd, doFetch) {
1170
1582
  const checks = [];
1171
1583
  const { MUSHI_CLI_VERSION: MUSHI_CLI_VERSION2 } = await import("./version.js");
@@ -2194,7 +2606,7 @@ async function maybeOfferConnect(credentials, options, _consoleBase) {
2194
2606
  if (p.isCancel(answer) || !answer) return;
2195
2607
  const endpoint = resolveCloudEndpoint(options.endpoint);
2196
2608
  try {
2197
- const { runConnect } = await import("./connect-HSL2EUEV.js");
2609
+ const { runConnect } = await import("./connect-HTAUIXDX.js");
2198
2610
  const saved = loadConfig();
2199
2611
  const result = await runConnect(
2200
2612
  {
@@ -2505,6 +2917,22 @@ function isSameDirectory(a, b) {
2505
2917
  }
2506
2918
 
2507
2919
  export {
2920
+ startDeviceAuth,
2921
+ waitForCliToken,
2922
+ listProjects,
2923
+ createProject,
2924
+ mintProjectKey,
2925
+ revokeProjectKey,
2926
+ printAuthBanner,
2927
+ printAuthApproved,
2928
+ printAuthFailed,
2929
+ envKeyOverrideLines,
2930
+ runLogin,
2931
+ checkFreshness,
2932
+ fixHintForCheck,
2933
+ checkOnboardingStatus,
2934
+ runDoctor,
2935
+ formatDoctorResult,
2508
2936
  CLI_FRESHNESS_SOURCE,
2509
2937
  runInit,
2510
2938
  resolveSavedCredentials,
@@ -1,12 +1,10 @@
1
- #!/usr/bin/env node
2
1
  import {
3
2
  MUSHI_CLI_VERSION
4
- } from "./chunk-JQQACG3P.js";
3
+ } from "./chunk-6XKFNK4C.js";
5
4
  import {
6
5
  CLOUD_API_ENDPOINT,
7
- normalizeEndpoint,
8
- resolvePublicOrigin
9
- } from "./chunk-X6SC4JKO.js";
6
+ normalizeEndpoint
7
+ } from "./chunk-2XODEIM4.js";
10
8
 
11
9
  // src/errors.ts
12
10
  var EXIT_CODE_MAP = {
@@ -474,14 +472,16 @@ function tightenWindowsAcl(path, type) {
474
472
  // src/console-url.ts
475
473
  import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
476
474
  import { dirname as dirname2, join as join2 } from "path";
477
- var HOSTED_CONSOLE_BASE = `${resolvePublicOrigin()}/mushi-mushi/admin`;
475
+ var HOSTED_CONSOLE_BASE = "https://mushi.kensaur.us";
476
+ var LEGACY_HOSTED_CONSOLE_BASES = ["https://kensaur.us/mushi-mushi/admin", "https://www.kensaur.us/mushi-mushi/admin"];
478
477
  var LOCAL_ADMIN_URL = "http://localhost:6464";
479
478
  var LOCAL_PROBE_MS = 800;
480
479
  function normalizeConsoleBase(url) {
481
480
  const trimmed = url.trim();
482
481
  let end = trimmed.length;
483
482
  while (end > 0 && trimmed.charCodeAt(end - 1) === 47) end--;
484
- return trimmed.slice(0, end);
483
+ const base = trimmed.slice(0, end);
484
+ return LEGACY_HOSTED_CONSOLE_BASES.includes(base) ? HOSTED_CONSOLE_BASE : base;
485
485
  }
486
486
  function consoleUrl(base, route) {
487
487
  const normalizedRoute = route.startsWith("/") ? route : `/${route}`;
@@ -701,10 +701,12 @@ async function apiCall(path, config, options = {}, callOptions = {}) {
701
701
  };
702
702
  }
703
703
  if (typeof body === "object" && body !== null && body.ok === false) {
704
+ const data = body.data;
704
705
  return {
705
706
  ok: false,
706
707
  httpStatus: res.status,
707
- error: normalizeApiError(body.error, res.status)
708
+ error: normalizeApiError(body.error, res.status),
709
+ ...data !== void 0 ? { data } : {}
708
710
  };
709
711
  }
710
712
  return body;
@@ -807,6 +809,8 @@ export {
807
809
  saveConfig,
808
810
  listProfiles,
809
811
  setActiveProfile,
812
+ HOSTED_CONSOLE_BASE,
813
+ normalizeConsoleBase,
810
814
  consoleUrl,
811
815
  resolveConsoleUrlSync,
812
816
  resolveConsoleUrl,
@@ -0,0 +1,13 @@
1
+ import {
2
+ resolveSdkEnvKey,
3
+ runConnect
4
+ } from "./chunk-NEFF6WK5.js";
5
+ import "./chunk-O6RN5FT5.js";
6
+ import "./chunk-ZL2HSPR5.js";
7
+ import "./chunk-6XKFNK4C.js";
8
+ import "./chunk-AWASJDQI.js";
9
+ import "./chunk-2XODEIM4.js";
10
+ export {
11
+ resolveSdkEnvKey,
12
+ runConnect
13
+ };
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env node
2
1
  import {
3
2
  assertWorkerKey,
4
3
  createDaemon,
@@ -8,14 +7,15 @@ import {
8
7
  infraBackoffMs,
9
8
  machineFailed,
10
9
  modelFor,
10
+ noSandboxProblem,
11
11
  readWorkerKey,
12
12
  runDaemon,
13
13
  stopHint,
14
14
  workerHostId
15
- } from "./chunk-AEXZYEUS.js";
16
- import "./chunk-UZQZU5OP.js";
17
- import "./chunk-JQQACG3P.js";
18
- import "./chunk-X6SC4JKO.js";
15
+ } from "./chunk-25YBYYYC.js";
16
+ import "./chunk-ZL2HSPR5.js";
17
+ import "./chunk-6XKFNK4C.js";
18
+ import "./chunk-2XODEIM4.js";
19
19
  export {
20
20
  assertWorkerKey,
21
21
  createDaemon,
@@ -25,6 +25,7 @@ export {
25
25
  infraBackoffMs,
26
26
  machineFailed,
27
27
  modelFor,
28
+ noSandboxProblem,
28
29
  readWorkerKey,
29
30
  runDaemon,
30
31
  stopHint,
package/dist/detect.d.ts CHANGED
@@ -43,4 +43,5 @@ declare function detectPackageManager(cwd: string): PackageManager;
43
43
  declare function installCommand(pm: PackageManager, packages: string[]): string;
44
44
  declare function envVarsToWrite(apiKey: string, projectId: string, framework: Framework, endpoint?: string): string;
45
45
 
46
- export { FRAMEWORKS, FRAMEWORK_IDS, type Framework, type FrameworkId, type PackageJson, type PackageManager, detectFramework, detectPackageManager, envVarsToWrite, installCommand, isFrameworkId, isLauncherOnly, isMushiSdkPackage, readPackageJson };
46
+ export { FRAMEWORKS, FRAMEWORK_IDS, detectFramework, detectPackageManager, envVarsToWrite, installCommand, isFrameworkId, isLauncherOnly, isMushiSdkPackage, readPackageJson };
47
+ export type { Framework, FrameworkId, PackageJson, PackageManager };
@@ -5,9 +5,8 @@ import {
5
5
  assertEndpoint,
6
6
  firstEndpoint,
7
7
  normalizeEndpoint,
8
- resolveCloudEndpoint,
9
- resolvePublicOrigin
10
- } from "./chunk-X64CFG54.js";
8
+ resolveCloudEndpoint
9
+ } from "./chunk-2XODEIM4.js";
11
10
  export {
12
11
  CLOUD_API_ENDPOINT,
13
12
  CLOUD_MCP_OAUTH_URL,
@@ -15,6 +14,5 @@ export {
15
14
  assertEndpoint,
16
15
  firstEndpoint,
17
16
  normalizeEndpoint,
18
- resolveCloudEndpoint,
19
- resolvePublicOrigin
17
+ resolveCloudEndpoint
20
18
  };
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
 
2
- export { }
2
+ export { };