@mushi-mushi/cli 0.43.1 → 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.
- package/README.md +5 -3
- package/dist/{chunk-WGMJHJAK.js → chunk-25YBYYYC.js} +3085 -345
- package/dist/{chunk-X64CFG54.js → chunk-2XODEIM4.js} +0 -1
- package/dist/chunk-6XKFNK4C.js +8 -0
- package/dist/{connect-MKDJTERU.js → chunk-NEFF6WK5.js} +40 -7
- package/dist/chunk-O6RN5FT5.js +178 -0
- package/dist/{chunk-5N33DJUL.js → chunk-T3Q44NPC.js} +444 -16
- package/dist/{chunk-QI2A4PGK.js → chunk-ZL2HSPR5.js} +12 -8
- package/dist/connect-HTAUIXDX.js +13 -0
- package/dist/{daemon-SA3MBHOQ.js → daemon-VDYY6GWG.js} +6 -5
- package/dist/{endpoint-KN5YEANQ.js → endpoint-BPPL6DJN.js} +3 -5
- package/dist/index.js +3413 -4840
- package/dist/init.js +6 -5
- package/dist/version.d.ts +6 -5
- package/dist/version.js +1 -1
- package/dist/wizard-bin.js +6 -5
- package/package.json +2 -2
- package/templates/node/.env.example +1 -1
- package/templates/svelte/.env.example +1 -1
- package/templates/svelte/src/App.svelte +1 -1
- package/templates/vue/.env.example +1 -1
- package/templates/vue/src/App.vue +1 -1
- package/dist/chunk-AGWQYT6I.js +0 -8
- package/dist/chunk-CG5KPP4S.js +0 -504
- package/dist/chunk-EHLZL2M2.js +0 -765
- package/dist/chunk-FUXYHTWF.js +0 -10
- package/dist/chunk-GNGVUQL3.js +0 -436
- package/dist/chunk-X6SC4JKO.js +0 -67
- package/dist/chunk-ZDAN3RYF.js +0 -85
- package/dist/connect-NUUPZ5ER.js +0 -13
- package/dist/detect-SOXPECZ3.js +0 -25
- package/dist/endpoint-XZHMF6EZ.js +0 -21
- package/dist/snippet-inject-BQO5I2RN.js +0 -15
- package/dist/version-YXVLZLBR.js +0 -9
|
@@ -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
|
-
|
|
9
|
-
} from "./chunk-EHLZL2M2.js";
|
|
10
|
+
savedSdkKeyFor
|
|
11
|
+
} from "./chunk-ZL2HSPR5.js";
|
|
10
12
|
import {
|
|
11
13
|
MUSHI_MCP_PIN_SPEC
|
|
12
|
-
} from "./chunk-
|
|
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-
|
|
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 = "
|
|
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
|
+
};
|