@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
@@ -56,7 +56,6 @@ function normalizeEndpoint(url) {
56
56
  export {
57
57
  TEST_REPORT_FETCH_TIMEOUT_MS,
58
58
  CLOUD_API_ENDPOINT,
59
- resolvePublicOrigin,
60
59
  CLOUD_MCP_OAUTH_URL,
61
60
  firstEndpoint,
62
61
  resolveCloudEndpoint,
@@ -0,0 +1,8 @@
1
+ // src/version.ts
2
+ var MUSHI_CLI_VERSION = true ? "0.44.0" : "0.0.0-dev";
3
+ var MUSHI_MCP_PIN_SPEC = "@mushi-mushi/mcp@^0.34";
4
+
5
+ export {
6
+ MUSHI_CLI_VERSION,
7
+ MUSHI_MCP_PIN_SPEC
8
+ };
@@ -1,15 +1,17 @@
1
1
  import {
2
- CONFIG_PATH,
3
2
  describeUnsafeSdkKey,
4
3
  probeKeyScope,
4
+ waitForIngestReady
5
+ } from "./chunk-O6RN5FT5.js";
6
+ import {
7
+ CONFIG_PATH,
5
8
  requireUuid,
6
9
  saveConfig,
7
- savedSdkKeyFor,
8
- waitForIngestReady
9
- } from "./chunk-LHSWFJOB.js";
10
+ savedSdkKeyFor
11
+ } from "./chunk-ZL2HSPR5.js";
10
12
  import {
11
13
  MUSHI_MCP_PIN_SPEC
12
- } from "./chunk-WJ7ZTOF7.js";
14
+ } from "./chunk-6XKFNK4C.js";
13
15
  import {
14
16
  detectFramework,
15
17
  envVarsToWrite,
@@ -17,7 +19,7 @@ import {
17
19
  } from "./chunk-AWASJDQI.js";
18
20
  import {
19
21
  assertEndpoint
20
- } from "./chunk-X64CFG54.js";
22
+ } from "./chunk-2XODEIM4.js";
21
23
 
22
24
  // src/connect.ts
23
25
  import { appendFile, readFile as readFile2, writeFile as writeFile2 } from "fs/promises";
@@ -26,7 +28,20 @@ import { join, resolve } from "path";
26
28
  // src/mcp-config.ts
27
29
  import { mkdir, readFile, writeFile } from "fs/promises";
28
30
  import { dirname } from "path";
29
- var DEFAULT_MUSHI_FEATURES = "triage,fixes,inventory,setup,docs";
31
+ var DEFAULT_MUSHI_FEATURES = "core";
32
+ var MCP_CLIENTS = ["cursor", "claude", "continue", "zed"];
33
+ function isMcpClient(value) {
34
+ return typeof value === "string" && MCP_CLIENTS.includes(value);
35
+ }
36
+ var MCP_CLIENT_LABEL = {
37
+ cursor: "Cursor",
38
+ claude: "Claude Code",
39
+ continue: "Continue",
40
+ zed: "Zed"
41
+ };
42
+ function buildHostedMcpServerBlock(url, oauth) {
43
+ return oauth ? { type: "http", url, oauth } : { type: "http", url };
44
+ }
30
45
  function isPlainObject(value) {
31
46
  return typeof value === "object" && value !== null && !Array.isArray(value);
32
47
  }
@@ -87,6 +102,15 @@ function buildMcpServerBlock(opts) {
87
102
  }
88
103
  };
89
104
  }
105
+ function printKeyExportHint(client, configPath = CONFIG_PATH) {
106
+ console.log("");
107
+ console.log(" No API key was written into the MCP config (safe to commit).");
108
+ console.log(` The MCP server uses the key \`mushi login\` saved in ${configPath}.`);
109
+ if (apiKeyPlaceholderFor(client) !== null) {
110
+ console.log(` To use a different key, export MUSHI_API_KEY in the environment ${MCP_CLIENT_LABEL[client]} is launched from.`);
111
+ }
112
+ console.log(" To write the key into the file instead (keep it out of git), re-run with --inline-key.");
113
+ }
90
114
  function buildMcpServerName(opts) {
91
115
  if (opts.legacy) return "mushi";
92
116
  if (opts.projectName) {
@@ -230,7 +254,16 @@ async function runConnect(opts, baseConfig = {}) {
230
254
  const ok = !envRefused && (!opts.wait || Boolean(heartbeat?.ok));
231
255
  return { ok, envPath, mcpPath, heartbeat, messages };
232
256
  }
257
+
233
258
  export {
259
+ MCP_CLIENTS,
260
+ isMcpClient,
261
+ MCP_CLIENT_LABEL,
262
+ buildHostedMcpServerBlock,
263
+ writeMcpServerEntry,
264
+ buildMcpServerBlock,
265
+ printKeyExportHint,
266
+ buildMcpServerName,
234
267
  resolveSdkEnvKey,
235
268
  runConnect
236
269
  };
@@ -0,0 +1,178 @@
1
+ import {
2
+ assertEndpoint,
3
+ normalizeEndpoint
4
+ } from "./chunk-2XODEIM4.js";
5
+
6
+ // src/key-scopes.ts
7
+ var SDK_KEY_SCOPES = ["report:write"];
8
+ var CLI_KEY_SCOPES = ["report:write", "mcp:read"];
9
+ var FULL_CLI_KEY_SCOPES = ["report:write", "mcp:read", "mcp:write"];
10
+ function editorKeyCommand(projectId) {
11
+ return `npx mushi-mushi login${projectId ? ` --project-id ${projectId}` : ""}`;
12
+ }
13
+ var SDK_KEY_LABEL = "sdk-ingest";
14
+ var CLI_KEY_LABEL = "cli-login";
15
+ async function probeKeyScope(endpoint, apiKey, projectId, doFetch = globalThis.fetch) {
16
+ let base = endpoint;
17
+ while (base.endsWith("/")) base = base.slice(0, -1);
18
+ let res;
19
+ try {
20
+ res = await doFetch(`${base}/v1/admin/mcp/account-overview`, {
21
+ headers: { "X-Mushi-Api-Key": apiKey, "X-Mushi-Project": projectId },
22
+ signal: AbortSignal.timeout(8e3)
23
+ });
24
+ } catch (err) {
25
+ return { result: "unreachable", message: err instanceof Error ? err.message : String(err) };
26
+ }
27
+ if (res.ok) return { result: "mcp", status: res.status };
28
+ if (res.status === 401) return { result: "invalid", status: res.status };
29
+ if (res.status === 403) {
30
+ const body = await res.json().catch(() => null);
31
+ const code = body?.error?.code ?? body?.code;
32
+ if (code === "INSUFFICIENT_SCOPE") return { result: "ingest-only", status: res.status };
33
+ }
34
+ return { result: "unknown", status: res.status };
35
+ }
36
+ function describeUnsafeSdkKey(probe, endpoint) {
37
+ switch (probe.result) {
38
+ case "mcp":
39
+ return "this key can read your bug reports (mcp scope), and SDK env vars ship inside the app bundle";
40
+ case "invalid":
41
+ return "the backend rejected this key";
42
+ case "unreachable":
43
+ return `could not reach ${endpoint} to confirm the key is ingest-only (${probe.message ?? "network error"})`;
44
+ case "unknown":
45
+ return `could not confirm the key is ingest-only (HTTP ${probe.status ?? "?"})`;
46
+ case "ingest-only":
47
+ return "the key is ingest-only";
48
+ }
49
+ }
50
+
51
+ // src/sanitize-config.ts
52
+ var PROJECT_ID_RE = /^(?:proj_[A-Za-z0-9_-]{10,}|[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$/i;
53
+ var API_KEY_RE = /^(mushi_|mush_pk_)[A-Za-z0-9_-]{10,}$/;
54
+ function sanitizeApiKey(raw) {
55
+ const key = raw.replace(/[\r\n\0]/g, "");
56
+ if (!API_KEY_RE.test(key)) {
57
+ throw new Error(
58
+ "Invalid API key in config \u2014 run `mushi login --api-key <key>` to refresh credentials."
59
+ );
60
+ }
61
+ return key;
62
+ }
63
+ function sanitizeProjectId(raw) {
64
+ const id = raw.trim();
65
+ if (!PROJECT_ID_RE.test(id)) {
66
+ throw new Error(
67
+ "Invalid project ID in config \u2014 expected a UUID or proj_* slug from the admin console."
68
+ );
69
+ }
70
+ return id;
71
+ }
72
+ function sanitizeEndpoint(raw) {
73
+ return assertEndpoint(normalizeEndpoint(raw));
74
+ }
75
+ function sanitizeCliCredentials(config) {
76
+ if (!config.endpoint || !config.apiKey || !config.projectId) {
77
+ throw new Error("Missing endpoint, apiKey, or projectId");
78
+ }
79
+ return {
80
+ endpoint: sanitizeEndpoint(config.endpoint),
81
+ apiKey: sanitizeApiKey(config.apiKey),
82
+ projectId: sanitizeProjectId(config.projectId)
83
+ };
84
+ }
85
+ function apiKeyHeaders(apiKey, projectId) {
86
+ const headers = {
87
+ Authorization: `Bearer ${apiKey}`,
88
+ "X-Mushi-Api-Key": apiKey
89
+ };
90
+ if (projectId) headers["X-Mushi-Project"] = projectId;
91
+ return headers;
92
+ }
93
+
94
+ // src/heartbeat-wait.ts
95
+ var IngestSetupHttpError = class extends Error {
96
+ status;
97
+ constructor(status) {
98
+ super(`ingest-setup HTTP ${status}`);
99
+ this.name = "IngestSetupHttpError";
100
+ this.status = status;
101
+ }
102
+ };
103
+ var NON_RETRYABLE_STATUSES = /* @__PURE__ */ new Set([401, 403, 404]);
104
+ async function fetchIngestSetup(config, doFetch = globalThis.fetch) {
105
+ const endpoint = sanitizeEndpoint(config.endpoint);
106
+ const apiKey = sanitizeApiKey(config.apiKey);
107
+ const projectId = config.projectId ? sanitizeProjectId(config.projectId) : void 0;
108
+ const res = await doFetch(`${endpoint}/v1/sync/ingest-setup`, {
109
+ headers: apiKeyHeaders(apiKey, projectId),
110
+ signal: AbortSignal.timeout(8e3)
111
+ });
112
+ if (!res.ok) {
113
+ if (NON_RETRYABLE_STATUSES.has(res.status)) throw new IngestSetupHttpError(res.status);
114
+ return null;
115
+ }
116
+ const body = await res.json();
117
+ return body.ok && body.data ? body.data : null;
118
+ }
119
+ async function waitForIngestReady(options) {
120
+ const doFetch = options.fetch ?? globalThis.fetch;
121
+ const maxAttempts = options.maxAttempts ?? 40;
122
+ const intervalMs = options.intervalMs ?? 3e3;
123
+ let lastPayload = null;
124
+ for (let attempt = 1; attempt <= maxAttempts; attempt++) {
125
+ if (options.signal?.aborted) {
126
+ return { ok: false, payload: lastPayload, attempts: attempt - 1, reason: "aborted" };
127
+ }
128
+ try {
129
+ lastPayload = await fetchIngestSetup(
130
+ { endpoint: options.endpoint, apiKey: options.apiKey, projectId: options.projectId },
131
+ doFetch
132
+ );
133
+ if (lastPayload) {
134
+ options.onPoll?.(lastPayload, attempt);
135
+ if (lastPayload.ready) {
136
+ return { ok: true, payload: lastPayload, attempts: attempt, reason: "ready" };
137
+ }
138
+ const sdkStep = lastPayload.steps.find((s) => s.id === "sdk_installed");
139
+ if (sdkStep?.complete) {
140
+ return { ok: true, payload: lastPayload, attempts: attempt, reason: "heartbeat" };
141
+ }
142
+ }
143
+ } catch (err) {
144
+ const msg = err instanceof Error ? err.message : String(err);
145
+ if (err instanceof IngestSetupHttpError) {
146
+ return { ok: false, payload: lastPayload, attempts: attempt, reason: "unauthorized", error: msg };
147
+ }
148
+ if (options.signal?.aborted) {
149
+ return { ok: false, payload: lastPayload, attempts: attempt, reason: "aborted", error: msg };
150
+ }
151
+ if (attempt === maxAttempts) {
152
+ return { ok: false, payload: lastPayload, attempts: attempt, reason: "fetch-error", error: msg };
153
+ }
154
+ }
155
+ if (attempt < maxAttempts) {
156
+ await new Promise((r) => setTimeout(r, intervalMs));
157
+ }
158
+ }
159
+ return { ok: false, payload: lastPayload, attempts: maxAttempts, reason: "timeout" };
160
+ }
161
+
162
+ export {
163
+ SDK_KEY_SCOPES,
164
+ CLI_KEY_SCOPES,
165
+ FULL_CLI_KEY_SCOPES,
166
+ editorKeyCommand,
167
+ SDK_KEY_LABEL,
168
+ CLI_KEY_LABEL,
169
+ probeKeyScope,
170
+ describeUnsafeSdkKey,
171
+ sanitizeApiKey,
172
+ sanitizeProjectId,
173
+ sanitizeEndpoint,
174
+ sanitizeCliCredentials,
175
+ apiKeyHeaders,
176
+ fetchIngestSetup,
177
+ waitForIngestReady
178
+ };