@mutagent/cli 0.1.13 → 0.1.15
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 +461 -222
- package/dist/bin/cli.js +2004 -492
- package/dist/bin/cli.js.map +20 -13
- package/dist/index.js +124 -90
- package/dist/index.js.map +7 -7
- package/package.json +3 -8
package/dist/index.js
CHANGED
|
@@ -15,6 +15,16 @@ var __toESM = (mod, isNodeMode, target) => {
|
|
|
15
15
|
});
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
|
+
var __export = (target, all) => {
|
|
19
|
+
for (var name in all)
|
|
20
|
+
__defProp(target, name, {
|
|
21
|
+
get: all[name],
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
set: (newValue) => all[name] = () => newValue
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
18
28
|
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
19
29
|
|
|
20
30
|
// src/lib/config.ts
|
|
@@ -23,23 +33,6 @@ import { z } from "zod";
|
|
|
23
33
|
import { homedir } from "os";
|
|
24
34
|
import { join } from "path";
|
|
25
35
|
import { existsSync, readFileSync, writeFileSync, mkdirSync } from "fs";
|
|
26
|
-
var configSchema = z.object({
|
|
27
|
-
apiKey: z.string().optional(),
|
|
28
|
-
endpoint: z.string().default("https://api.mutagent.io"),
|
|
29
|
-
format: z.enum(["table", "json"]).default("table"),
|
|
30
|
-
timeout: z.number().default(30000),
|
|
31
|
-
defaultWorkspace: z.string().optional(),
|
|
32
|
-
defaultOrganization: z.string().optional()
|
|
33
|
-
});
|
|
34
|
-
var credentialsSchema = z.object({
|
|
35
|
-
apiKey: z.string().optional(),
|
|
36
|
-
endpoint: z.string().optional(),
|
|
37
|
-
defaultWorkspace: z.string().optional(),
|
|
38
|
-
defaultOrganization: z.string().optional(),
|
|
39
|
-
expiresAt: z.string().optional()
|
|
40
|
-
}).loose();
|
|
41
|
-
var CREDENTIALS_DIR = join(homedir(), ".config", "mutagent");
|
|
42
|
-
var CREDENTIALS_FILE = join(CREDENTIALS_DIR, "credentials.json");
|
|
43
36
|
function parseJsonSafe(content, schema) {
|
|
44
37
|
try {
|
|
45
38
|
const parsed = JSON.parse(content);
|
|
@@ -147,79 +140,28 @@ function setDefaultOrganization(organizationId) {
|
|
|
147
140
|
};
|
|
148
141
|
writeFileSync(CREDENTIALS_FILE, JSON.stringify(updated, null, 2));
|
|
149
142
|
}
|
|
150
|
-
|
|
151
|
-
|
|
143
|
+
var configSchema, credentialsSchema, CREDENTIALS_DIR, CREDENTIALS_FILE;
|
|
144
|
+
var init_config = __esm(() => {
|
|
145
|
+
configSchema = z.object({
|
|
146
|
+
apiKey: z.string().optional(),
|
|
147
|
+
endpoint: z.string().default("https://api.mutagent.io"),
|
|
148
|
+
format: z.enum(["table", "json"]).default("table"),
|
|
149
|
+
timeout: z.number().default(30000),
|
|
150
|
+
defaultWorkspace: z.string().optional(),
|
|
151
|
+
defaultOrganization: z.string().optional()
|
|
152
|
+
});
|
|
153
|
+
credentialsSchema = z.object({
|
|
154
|
+
apiKey: z.string().optional(),
|
|
155
|
+
endpoint: z.string().optional(),
|
|
156
|
+
defaultWorkspace: z.string().optional(),
|
|
157
|
+
defaultOrganization: z.string().optional(),
|
|
158
|
+
expiresAt: z.string().optional()
|
|
159
|
+
}).loose();
|
|
160
|
+
CREDENTIALS_DIR = join(homedir(), ".config", "mutagent");
|
|
161
|
+
CREDENTIALS_FILE = join(CREDENTIALS_DIR, "credentials.json");
|
|
162
|
+
});
|
|
152
163
|
|
|
153
164
|
// src/lib/errors.ts
|
|
154
|
-
class MutagentError extends Error {
|
|
155
|
-
code;
|
|
156
|
-
suggestion;
|
|
157
|
-
exitCode;
|
|
158
|
-
constructor(code, message, suggestion, exitCode = 1) {
|
|
159
|
-
super(message);
|
|
160
|
-
this.code = code;
|
|
161
|
-
this.suggestion = suggestion;
|
|
162
|
-
this.exitCode = exitCode;
|
|
163
|
-
this.name = "MutagentError";
|
|
164
|
-
}
|
|
165
|
-
toJSON() {
|
|
166
|
-
return {
|
|
167
|
-
error: {
|
|
168
|
-
code: this.code,
|
|
169
|
-
message: this.message,
|
|
170
|
-
suggestion: this.suggestion
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
var AUTH_REMEDIATION_MESSAGE = [
|
|
176
|
-
"Authentication required. Options:",
|
|
177
|
-
" Interactive: mutagent auth login --browser",
|
|
178
|
-
" Non-interactive: export MUTAGENT_API_KEY=<your-key>",
|
|
179
|
-
" CI/CD: mutagent auth login --api-key <key>"
|
|
180
|
-
].join(`
|
|
181
|
-
`);
|
|
182
|
-
|
|
183
|
-
class AuthenticationError extends MutagentError {
|
|
184
|
-
suggestions;
|
|
185
|
-
cause;
|
|
186
|
-
constructor(message, options = {}) {
|
|
187
|
-
super("AUTH_REQUIRED", message ?? 'Authentication required. Please run "mutagent auth login"', options.suggestions ? options.suggestions[0] : "Run: mutagent auth login --browser", 2);
|
|
188
|
-
this.suggestions = options.suggestions ?? [
|
|
189
|
-
"mutagent auth login --browser",
|
|
190
|
-
"export MUTAGENT_API_KEY=<your-key>",
|
|
191
|
-
"mutagent auth login --api-key <key>"
|
|
192
|
-
];
|
|
193
|
-
this.suggestion = options.suggestions ? options.suggestions[0] : "Run: mutagent auth login --browser";
|
|
194
|
-
this.cause = options.cause;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
class ApiError extends MutagentError {
|
|
199
|
-
statusCode;
|
|
200
|
-
constructor(status, message) {
|
|
201
|
-
super(`API_${status}`, message, status === 401 ? "Check your API key with: mutagent auth status" : undefined, 1);
|
|
202
|
-
this.statusCode = status;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
var WORKSPACE_REMEDIATION_MESSAGE = [
|
|
206
|
-
"Workspace context missing. To fix:",
|
|
207
|
-
" mutagent config set workspace <workspace-id> # Set default workspace",
|
|
208
|
-
" mutagent workspaces list # List available workspaces"
|
|
209
|
-
].join(`
|
|
210
|
-
`);
|
|
211
|
-
|
|
212
|
-
class WorkspaceContextError extends MutagentError {
|
|
213
|
-
constructor(message) {
|
|
214
|
-
super("WORKSPACE_CONTEXT_MISSING", message ?? "Workspace context is required but not configured", "Run: mutagent config set workspace <workspace-id>", 3);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
class ValidationError extends MutagentError {
|
|
219
|
-
constructor(message) {
|
|
220
|
-
super("VALIDATION_ERROR", message, "Check the command syntax with: mutagent <command> --help", 1);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
165
|
function handleError(error, isJson) {
|
|
224
166
|
if (error instanceof MutagentError) {
|
|
225
167
|
if (isJson) {
|
|
@@ -298,8 +240,87 @@ function handleError(error, isJson) {
|
|
|
298
240
|
}
|
|
299
241
|
process.exit(1);
|
|
300
242
|
}
|
|
243
|
+
var MutagentError, AUTH_REMEDIATION_MESSAGE, AuthenticationError, ApiError, WORKSPACE_REMEDIATION_MESSAGE, WorkspaceContextError, ValidationError;
|
|
244
|
+
var init_errors = __esm(() => {
|
|
245
|
+
MutagentError = class MutagentError extends Error {
|
|
246
|
+
code;
|
|
247
|
+
suggestion;
|
|
248
|
+
exitCode;
|
|
249
|
+
constructor(code, message, suggestion, exitCode = 1) {
|
|
250
|
+
super(message);
|
|
251
|
+
this.code = code;
|
|
252
|
+
this.suggestion = suggestion;
|
|
253
|
+
this.exitCode = exitCode;
|
|
254
|
+
this.name = "MutagentError";
|
|
255
|
+
}
|
|
256
|
+
toJSON() {
|
|
257
|
+
return {
|
|
258
|
+
error: {
|
|
259
|
+
code: this.code,
|
|
260
|
+
message: this.message,
|
|
261
|
+
suggestion: this.suggestion
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
AUTH_REMEDIATION_MESSAGE = [
|
|
267
|
+
"Authentication required. Options:",
|
|
268
|
+
" Interactive: mutagent auth login --browser",
|
|
269
|
+
" Non-interactive: export MUTAGENT_API_KEY=<your-key>",
|
|
270
|
+
" CI/CD: mutagent auth login --api-key <key>"
|
|
271
|
+
].join(`
|
|
272
|
+
`);
|
|
273
|
+
AuthenticationError = class AuthenticationError extends MutagentError {
|
|
274
|
+
suggestions;
|
|
275
|
+
cause;
|
|
276
|
+
constructor(message, options = {}) {
|
|
277
|
+
super("AUTH_REQUIRED", message ?? 'Authentication required. Please run "mutagent auth login"', options.suggestions ? options.suggestions[0] : "Run: mutagent auth login --browser", 2);
|
|
278
|
+
this.suggestions = options.suggestions ?? [
|
|
279
|
+
"mutagent auth login --browser",
|
|
280
|
+
"export MUTAGENT_API_KEY=<your-key>",
|
|
281
|
+
"mutagent auth login --api-key <key>"
|
|
282
|
+
];
|
|
283
|
+
this.suggestion = options.suggestions ? options.suggestions[0] : "Run: mutagent auth login --browser";
|
|
284
|
+
this.cause = options.cause;
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
ApiError = class ApiError extends MutagentError {
|
|
288
|
+
statusCode;
|
|
289
|
+
constructor(status, message) {
|
|
290
|
+
super(`API_${String(status)}`, message, status === 401 ? "Check your API key with: mutagent auth status" : undefined, 1);
|
|
291
|
+
this.statusCode = status;
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
WORKSPACE_REMEDIATION_MESSAGE = [
|
|
295
|
+
"Workspace context missing. To fix:",
|
|
296
|
+
" mutagent config set workspace <workspace-id> # Set default workspace",
|
|
297
|
+
" mutagent workspaces list # List available workspaces"
|
|
298
|
+
].join(`
|
|
299
|
+
`);
|
|
300
|
+
WorkspaceContextError = class WorkspaceContextError extends MutagentError {
|
|
301
|
+
constructor(message) {
|
|
302
|
+
super("WORKSPACE_CONTEXT_MISSING", message ?? "Workspace context is required but not configured", "Run: mutagent config set workspace <workspace-id>", 3);
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
ValidationError = class ValidationError extends MutagentError {
|
|
306
|
+
constructor(message) {
|
|
307
|
+
super("VALIDATION_ERROR", message, "Check the command syntax with: mutagent <command> --help", 1);
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
});
|
|
301
311
|
|
|
302
312
|
// src/lib/sdk-client.ts
|
|
313
|
+
var exports_sdk_client = {};
|
|
314
|
+
__export(exports_sdk_client, {
|
|
315
|
+
validateApiKey: () => validateApiKey,
|
|
316
|
+
resetSDKClient: () => resetSDKClient,
|
|
317
|
+
getSDKClient: () => getSDKClient,
|
|
318
|
+
fetchWorkspaces: () => fetchWorkspaces,
|
|
319
|
+
fetchOrganizations: () => fetchOrganizations,
|
|
320
|
+
MutagentSDK: () => SDKClientWrapper
|
|
321
|
+
});
|
|
322
|
+
import { Mutagent, HTTPClient } from "@mutagent/sdk";
|
|
323
|
+
|
|
303
324
|
class SDKClientWrapper {
|
|
304
325
|
sdk;
|
|
305
326
|
apiKey;
|
|
@@ -838,7 +859,6 @@ class SDKClientWrapper {
|
|
|
838
859
|
}
|
|
839
860
|
}
|
|
840
861
|
}
|
|
841
|
-
var sdkClient = null;
|
|
842
862
|
function getSDKClient() {
|
|
843
863
|
if (!sdkClient) {
|
|
844
864
|
const apiKey = getApiKey();
|
|
@@ -855,6 +875,9 @@ function getSDKClient() {
|
|
|
855
875
|
}
|
|
856
876
|
return sdkClient;
|
|
857
877
|
}
|
|
878
|
+
function resetSDKClient() {
|
|
879
|
+
sdkClient = null;
|
|
880
|
+
}
|
|
858
881
|
async function validateApiKey(apiKey, endpoint) {
|
|
859
882
|
try {
|
|
860
883
|
const response = await fetch(`${endpoint}/api/organizations`, {
|
|
@@ -891,6 +914,16 @@ async function fetchWorkspaces(apiKey, endpoint, orgId) {
|
|
|
891
914
|
return [];
|
|
892
915
|
}
|
|
893
916
|
}
|
|
917
|
+
var sdkClient = null;
|
|
918
|
+
var init_sdk_client = __esm(() => {
|
|
919
|
+
init_errors();
|
|
920
|
+
init_config();
|
|
921
|
+
});
|
|
922
|
+
|
|
923
|
+
// src/index.ts
|
|
924
|
+
init_config();
|
|
925
|
+
init_sdk_client();
|
|
926
|
+
|
|
894
927
|
// src/lib/output.ts
|
|
895
928
|
import chalk from "chalk";
|
|
896
929
|
function getJsonFlag(command) {
|
|
@@ -1013,6 +1046,7 @@ ${String(data.length)} result(s)`));
|
|
|
1013
1046
|
}
|
|
1014
1047
|
|
|
1015
1048
|
// src/index.ts
|
|
1049
|
+
init_errors();
|
|
1016
1050
|
var version = "0.1.0";
|
|
1017
1051
|
export {
|
|
1018
1052
|
version,
|
|
@@ -1027,5 +1061,5 @@ export {
|
|
|
1027
1061
|
ApiError
|
|
1028
1062
|
};
|
|
1029
1063
|
|
|
1030
|
-
//# debugId=
|
|
1064
|
+
//# debugId=6DF19185F53A347764756E2164756E21
|
|
1031
1065
|
//# sourceMappingURL=index.js.map
|