@mutagent/cli 0.1.9 → 0.1.10
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/dist/bin/cli.js +389 -46
- package/dist/bin/cli.js.map +9 -8
- package/dist/index.js +57 -1
- package/dist/index.js.map +4 -4
- package/package.json +2 -2
package/dist/bin/cli.js
CHANGED
|
@@ -19,10 +19,10 @@ var __toESM = (mod, isNodeMode, target) => {
|
|
|
19
19
|
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
20
20
|
|
|
21
21
|
// src/bin/cli.ts
|
|
22
|
-
import { Command as
|
|
23
|
-
import
|
|
24
|
-
import { readFileSync as
|
|
25
|
-
import { join as
|
|
22
|
+
import { Command as Command12 } from "commander";
|
|
23
|
+
import chalk13 from "chalk";
|
|
24
|
+
import { readFileSync as readFileSync12 } from "fs";
|
|
25
|
+
import { join as join3, dirname } from "path";
|
|
26
26
|
import { fileURLToPath } from "url";
|
|
27
27
|
|
|
28
28
|
// src/commands/auth.ts
|
|
@@ -211,8 +211,22 @@ class AuthenticationError extends MutagentError {
|
|
|
211
211
|
}
|
|
212
212
|
|
|
213
213
|
class ApiError extends MutagentError {
|
|
214
|
+
statusCode;
|
|
214
215
|
constructor(status, message) {
|
|
215
216
|
super(`API_${status}`, message, status === 401 ? "Check your API key with: mutagent auth status" : undefined, 1);
|
|
217
|
+
this.statusCode = status;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
var WORKSPACE_REMEDIATION_MESSAGE = [
|
|
221
|
+
"Workspace context missing. To fix:",
|
|
222
|
+
" mutagent config set workspace <workspace-id> # Set default workspace",
|
|
223
|
+
" mutagent workspaces list # List available workspaces"
|
|
224
|
+
].join(`
|
|
225
|
+
`);
|
|
226
|
+
|
|
227
|
+
class WorkspaceContextError extends MutagentError {
|
|
228
|
+
constructor(message) {
|
|
229
|
+
super("WORKSPACE_CONTEXT_MISSING", message ?? "Workspace context is required but not configured", "Run: mutagent config set workspace <workspace-id>", 3);
|
|
216
230
|
}
|
|
217
231
|
}
|
|
218
232
|
|
|
@@ -232,12 +246,33 @@ function handleError(error, isJson) {
|
|
|
232
246
|
ciCd: "mutagent auth login --api-key <key>"
|
|
233
247
|
};
|
|
234
248
|
}
|
|
249
|
+
if (error instanceof WorkspaceContextError) {
|
|
250
|
+
jsonOutput.remediation = {
|
|
251
|
+
setWorkspace: "mutagent config set workspace <workspace-id>",
|
|
252
|
+
listWorkspaces: "mutagent workspaces list"
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
if (error instanceof ApiError && error.statusCode === 403) {
|
|
256
|
+
jsonOutput.remediation = {
|
|
257
|
+
interactive: "mutagent auth login --browser",
|
|
258
|
+
nonInteractive: "export MUTAGENT_API_KEY=<your-key>",
|
|
259
|
+
checkPermissions: "Verify your API key has the required permissions"
|
|
260
|
+
};
|
|
261
|
+
}
|
|
235
262
|
console.log(JSON.stringify(jsonOutput, null, 2));
|
|
236
263
|
} else {
|
|
237
264
|
console.error(`Error: ${error.message}`);
|
|
238
265
|
if (error instanceof AuthenticationError) {
|
|
239
266
|
console.error("");
|
|
240
267
|
console.error(AUTH_REMEDIATION_MESSAGE);
|
|
268
|
+
} else if (error instanceof WorkspaceContextError) {
|
|
269
|
+
console.error("");
|
|
270
|
+
console.error(WORKSPACE_REMEDIATION_MESSAGE);
|
|
271
|
+
} else if (error instanceof ApiError && error.statusCode === 403) {
|
|
272
|
+
console.error("");
|
|
273
|
+
console.error("Access denied. To fix:");
|
|
274
|
+
console.error(" mutagent auth login --browser # Re-authenticate");
|
|
275
|
+
console.error(" export MUTAGENT_API_KEY=mt_xxx # Or use a different API key");
|
|
241
276
|
} else if (error instanceof ValidationError) {
|
|
242
277
|
if (error.suggestion) {
|
|
243
278
|
console.error(`Suggestion: ${error.suggestion}`);
|
|
@@ -313,6 +348,13 @@ class SDKClientWrapper {
|
|
|
313
348
|
if (err.statusCode === 401) {
|
|
314
349
|
throw new AuthenticationError;
|
|
315
350
|
}
|
|
351
|
+
if (err.statusCode === 403) {
|
|
352
|
+
throw new ApiError(403, err.message ?? err.body ?? "Access denied");
|
|
353
|
+
}
|
|
354
|
+
const errMessage = (err.message ?? err.body ?? "").toLowerCase();
|
|
355
|
+
if (errMessage.includes("workspace") && (errMessage.includes("missing") || errMessage.includes("required")) || errMessage.includes("x-workspace-id")) {
|
|
356
|
+
throw new WorkspaceContextError(err.message ?? err.body ?? undefined);
|
|
357
|
+
}
|
|
316
358
|
if (err.statusCode) {
|
|
317
359
|
throw new ApiError(err.statusCode, err.message ?? err.body ?? "Unknown error");
|
|
318
360
|
}
|
|
@@ -359,7 +401,14 @@ class SDKClientWrapper {
|
|
|
359
401
|
if (response.status === 401) {
|
|
360
402
|
throw new AuthenticationError;
|
|
361
403
|
}
|
|
404
|
+
if (response.status === 403) {
|
|
405
|
+
throw new ApiError(403, await response.text() || "Access denied");
|
|
406
|
+
}
|
|
362
407
|
const error = await response.text();
|
|
408
|
+
const errorLower = error.toLowerCase();
|
|
409
|
+
if (errorLower.includes("workspace") && (errorLower.includes("missing") || errorLower.includes("required")) || errorLower.includes("x-workspace-id")) {
|
|
410
|
+
throw new WorkspaceContextError(error);
|
|
411
|
+
}
|
|
363
412
|
throw new ApiError(response.status, error);
|
|
364
413
|
}
|
|
365
414
|
return response.json();
|
|
@@ -754,7 +803,14 @@ class SDKClientWrapper {
|
|
|
754
803
|
if (response.status === 401) {
|
|
755
804
|
throw new AuthenticationError;
|
|
756
805
|
}
|
|
806
|
+
if (response.status === 403) {
|
|
807
|
+
throw new ApiError(403, await response.text() || "Access denied");
|
|
808
|
+
}
|
|
757
809
|
const error = await response.text();
|
|
810
|
+
const errorLower = error.toLowerCase();
|
|
811
|
+
if (errorLower.includes("workspace") && (errorLower.includes("missing") || errorLower.includes("required")) || errorLower.includes("x-workspace-id")) {
|
|
812
|
+
throw new WorkspaceContextError(error);
|
|
813
|
+
}
|
|
758
814
|
throw new ApiError(response.status, error);
|
|
759
815
|
}
|
|
760
816
|
return response;
|
|
@@ -1580,10 +1636,10 @@ function promptLinks(promptId) {
|
|
|
1580
1636
|
|
|
1581
1637
|
// src/commands/prompts.ts
|
|
1582
1638
|
var PREREQUISITES_TEXT = `
|
|
1583
|
-
${chalk4.yellow("Prerequisites
|
|
1584
|
-
1.
|
|
1585
|
-
2.
|
|
1586
|
-
|
|
1639
|
+
${chalk4.yellow("Prerequisites:")}
|
|
1640
|
+
1. Evaluation criteria defined ${chalk4.dim("(via dashboard or evaluation create)")}
|
|
1641
|
+
2. Dataset uploaded ${chalk4.dim("mutagent prompts dataset list <prompt-id>")}
|
|
1642
|
+
${chalk4.dim("Note: LLM provider config is only required when the server uses external providers (USE_EXT_PROVIDERS=true)")}`;
|
|
1587
1643
|
function parseValidationErrors(error) {
|
|
1588
1644
|
if (error instanceof ApiError) {
|
|
1589
1645
|
try {
|
|
@@ -1613,14 +1669,6 @@ function warnSingleBraceVariables(content, output) {
|
|
|
1613
1669
|
}
|
|
1614
1670
|
}
|
|
1615
1671
|
}
|
|
1616
|
-
async function checkProviderConfigured() {
|
|
1617
|
-
const client = getSDKClient();
|
|
1618
|
-
const providers = await client.listProviders();
|
|
1619
|
-
if (providers.data.length === 0) {
|
|
1620
|
-
throw new MutagentError("NO_PROVIDER", "No LLM provider configured. Evaluations and optimizations require at least one active provider.", `Configure a provider at: ${providerSettingsLink()}
|
|
1621
|
-
Or check: mutagent providers list`);
|
|
1622
|
-
}
|
|
1623
|
-
}
|
|
1624
1672
|
function parseDatasetFile(rawContent, filePath) {
|
|
1625
1673
|
const trimmed = rawContent.trim();
|
|
1626
1674
|
if (filePath.endsWith(".csv")) {
|
|
@@ -2149,7 +2197,6 @@ ${chalk4.dim("Monitor progress with: mutagent prompts optimize status <job-id>")
|
|
|
2149
2197
|
const isJson = getJsonFlag(prompts);
|
|
2150
2198
|
const output = new OutputFormatter(isJson ? "json" : "table");
|
|
2151
2199
|
try {
|
|
2152
|
-
await checkProviderConfigured();
|
|
2153
2200
|
const client = getSDKClient();
|
|
2154
2201
|
const job = await client.startOptimization(promptId, options.dataset, {
|
|
2155
2202
|
maxIterations: options.maxIterations ? parseInt(options.maxIterations, 10) : undefined,
|
|
@@ -4523,15 +4570,308 @@ Available Models:`));
|
|
|
4523
4570
|
return providers;
|
|
4524
4571
|
}
|
|
4525
4572
|
|
|
4573
|
+
// src/commands/init.ts
|
|
4574
|
+
import { Command as Command11 } from "commander";
|
|
4575
|
+
import inquirer3 from "inquirer";
|
|
4576
|
+
import chalk12 from "chalk";
|
|
4577
|
+
import { existsSync as existsSync10, readFileSync as readFileSync11, writeFileSync as writeFileSync3 } from "fs";
|
|
4578
|
+
import { execSync as execSync2 } from "child_process";
|
|
4579
|
+
import { join as join2 } from "path";
|
|
4580
|
+
var FRAMEWORK_DETECTION_MAP = {
|
|
4581
|
+
"@mastra/core": {
|
|
4582
|
+
name: "mastra",
|
|
4583
|
+
displayName: "Mastra",
|
|
4584
|
+
npmPackage: "@mastra/core"
|
|
4585
|
+
},
|
|
4586
|
+
"@langchain/langgraph": {
|
|
4587
|
+
name: "langgraph",
|
|
4588
|
+
displayName: "LangGraph",
|
|
4589
|
+
npmPackage: "@langchain/langgraph",
|
|
4590
|
+
mutagentPackage: "@mutagent/langgraph"
|
|
4591
|
+
},
|
|
4592
|
+
langchain: {
|
|
4593
|
+
name: "langchain",
|
|
4594
|
+
displayName: "LangChain",
|
|
4595
|
+
npmPackage: "langchain",
|
|
4596
|
+
mutagentPackage: "@mutagent/langchain"
|
|
4597
|
+
},
|
|
4598
|
+
"@langchain/core": {
|
|
4599
|
+
name: "langchain",
|
|
4600
|
+
displayName: "LangChain",
|
|
4601
|
+
npmPackage: "@langchain/core",
|
|
4602
|
+
mutagentPackage: "@mutagent/langchain"
|
|
4603
|
+
},
|
|
4604
|
+
"@ai-sdk/core": {
|
|
4605
|
+
name: "vercel-ai",
|
|
4606
|
+
displayName: "Vercel AI SDK",
|
|
4607
|
+
npmPackage: "@ai-sdk/core",
|
|
4608
|
+
mutagentPackage: "@mutagent/vercel-ai"
|
|
4609
|
+
},
|
|
4610
|
+
ai: {
|
|
4611
|
+
name: "vercel-ai",
|
|
4612
|
+
displayName: "Vercel AI SDK",
|
|
4613
|
+
npmPackage: "ai",
|
|
4614
|
+
mutagentPackage: "@mutagent/vercel-ai"
|
|
4615
|
+
},
|
|
4616
|
+
"@google/genai": {
|
|
4617
|
+
name: "generic",
|
|
4618
|
+
displayName: "Google GenAI",
|
|
4619
|
+
npmPackage: "@google/genai"
|
|
4620
|
+
},
|
|
4621
|
+
openai: {
|
|
4622
|
+
name: "openai",
|
|
4623
|
+
displayName: "OpenAI SDK",
|
|
4624
|
+
npmPackage: "openai",
|
|
4625
|
+
mutagentPackage: "@mutagent/openai"
|
|
4626
|
+
}
|
|
4627
|
+
};
|
|
4628
|
+
function detectPackageManager2(cwd = process.cwd()) {
|
|
4629
|
+
if (existsSync10(join2(cwd, "bun.lockb")) || existsSync10(join2(cwd, "bun.lock"))) {
|
|
4630
|
+
return "bun";
|
|
4631
|
+
}
|
|
4632
|
+
if (existsSync10(join2(cwd, "pnpm-lock.yaml"))) {
|
|
4633
|
+
return "pnpm";
|
|
4634
|
+
}
|
|
4635
|
+
if (existsSync10(join2(cwd, "yarn.lock"))) {
|
|
4636
|
+
return "yarn";
|
|
4637
|
+
}
|
|
4638
|
+
if (existsSync10(join2(cwd, "package-lock.json"))) {
|
|
4639
|
+
return "npm";
|
|
4640
|
+
}
|
|
4641
|
+
try {
|
|
4642
|
+
execSync2("bun --version", { stdio: "ignore" });
|
|
4643
|
+
return "bun";
|
|
4644
|
+
} catch {
|
|
4645
|
+
return "npm";
|
|
4646
|
+
}
|
|
4647
|
+
}
|
|
4648
|
+
function getInstallCommand2(pm, packages) {
|
|
4649
|
+
const pkgList = packages.join(" ");
|
|
4650
|
+
const commands = {
|
|
4651
|
+
bun: `bun add ${pkgList}`,
|
|
4652
|
+
npm: `npm install ${pkgList}`,
|
|
4653
|
+
yarn: `yarn add ${pkgList}`,
|
|
4654
|
+
pnpm: `pnpm add ${pkgList}`
|
|
4655
|
+
};
|
|
4656
|
+
return commands[pm];
|
|
4657
|
+
}
|
|
4658
|
+
function detectFrameworkFromPackageJson(cwd = process.cwd()) {
|
|
4659
|
+
const pkgPath = join2(cwd, "package.json");
|
|
4660
|
+
if (!existsSync10(pkgPath)) {
|
|
4661
|
+
return null;
|
|
4662
|
+
}
|
|
4663
|
+
let pkg;
|
|
4664
|
+
try {
|
|
4665
|
+
pkg = JSON.parse(readFileSync11(pkgPath, "utf-8"));
|
|
4666
|
+
} catch {
|
|
4667
|
+
return null;
|
|
4668
|
+
}
|
|
4669
|
+
const allDeps = {
|
|
4670
|
+
...pkg.dependencies,
|
|
4671
|
+
...pkg.devDependencies
|
|
4672
|
+
};
|
|
4673
|
+
for (const [depName, framework] of Object.entries(FRAMEWORK_DETECTION_MAP)) {
|
|
4674
|
+
if (depName in allDeps) {
|
|
4675
|
+
return framework;
|
|
4676
|
+
}
|
|
4677
|
+
}
|
|
4678
|
+
return null;
|
|
4679
|
+
}
|
|
4680
|
+
function hasRcConfig(cwd = process.cwd()) {
|
|
4681
|
+
return existsSync10(join2(cwd, ".mutagentrc.json"));
|
|
4682
|
+
}
|
|
4683
|
+
function writeRcConfig(config, cwd = process.cwd()) {
|
|
4684
|
+
const rcPath = join2(cwd, ".mutagentrc.json");
|
|
4685
|
+
writeFileSync3(rcPath, JSON.stringify(config, null, 2) + `
|
|
4686
|
+
`);
|
|
4687
|
+
}
|
|
4688
|
+
function createInitCommand() {
|
|
4689
|
+
const init = new Command11("init").description("Initialize MutagenT in your project").option("--non-interactive", "Skip interactive prompts (defaults to CLI-only mode)").addHelpText("after", `
|
|
4690
|
+
Examples:
|
|
4691
|
+
${chalk12.dim("$")} mutagent init # Interactive setup wizard
|
|
4692
|
+
${chalk12.dim("$")} mutagent init --non-interactive # CLI-only mode (no prompts)
|
|
4693
|
+
|
|
4694
|
+
Modes:
|
|
4695
|
+
${chalk12.bold("Full scaffold")} Install SDK + integration package, create config, setup tracing
|
|
4696
|
+
${chalk12.bold("CLI-only")} Verify auth + create .mutagentrc.json with workspace/endpoint
|
|
4697
|
+
${chalk12.bold("Skip")} Exit without changes
|
|
4698
|
+
`).action(async (options) => {
|
|
4699
|
+
const isJson = getJsonFlag(init);
|
|
4700
|
+
const output = new OutputFormatter(isJson ? "json" : "table");
|
|
4701
|
+
try {
|
|
4702
|
+
const isNonInteractive = options.nonInteractive === true || process.env.MUTAGENT_NON_INTERACTIVE === "true" || process.env.CI === "true" || !process.stdin.isTTY;
|
|
4703
|
+
const cwd = process.cwd();
|
|
4704
|
+
if (hasRcConfig(cwd)) {
|
|
4705
|
+
output.warn(".mutagentrc.json already exists in this directory.");
|
|
4706
|
+
if (isNonInteractive) {
|
|
4707
|
+
output.info("Use --force to overwrite (not yet supported). Exiting.");
|
|
4708
|
+
return;
|
|
4709
|
+
}
|
|
4710
|
+
const { overwrite } = await inquirer3.prompt([{
|
|
4711
|
+
type: "confirm",
|
|
4712
|
+
name: "overwrite",
|
|
4713
|
+
message: ".mutagentrc.json already exists. Overwrite?",
|
|
4714
|
+
default: false
|
|
4715
|
+
}]);
|
|
4716
|
+
if (!overwrite) {
|
|
4717
|
+
output.info("Init cancelled.");
|
|
4718
|
+
return;
|
|
4719
|
+
}
|
|
4720
|
+
}
|
|
4721
|
+
const authenticated = hasCredentials();
|
|
4722
|
+
if (!authenticated) {
|
|
4723
|
+
output.warn("Not authenticated.");
|
|
4724
|
+
output.info("Run: mutagent auth login --browser");
|
|
4725
|
+
if (isNonInteractive) {
|
|
4726
|
+
throw new MutagentError("AUTH_REQUIRED", "Authentication required before init", "Run: mutagent auth login --browser");
|
|
4727
|
+
}
|
|
4728
|
+
const { doAuth } = await inquirer3.prompt([{
|
|
4729
|
+
type: "confirm",
|
|
4730
|
+
name: "doAuth",
|
|
4731
|
+
message: "Would you like to authenticate now?",
|
|
4732
|
+
default: true
|
|
4733
|
+
}]);
|
|
4734
|
+
if (doAuth) {
|
|
4735
|
+
output.info('Run "mutagent auth login --browser" and then re-run "mutagent init".');
|
|
4736
|
+
return;
|
|
4737
|
+
}
|
|
4738
|
+
}
|
|
4739
|
+
const detectedFramework = detectFrameworkFromPackageJson(cwd);
|
|
4740
|
+
let mode;
|
|
4741
|
+
let confirmedFramework = detectedFramework;
|
|
4742
|
+
if (isNonInteractive) {
|
|
4743
|
+
mode = "cli-only";
|
|
4744
|
+
if (isJson) {
|
|
4745
|
+
output.output({
|
|
4746
|
+
mode: "cli-only",
|
|
4747
|
+
nonInteractive: true,
|
|
4748
|
+
detectedFramework: detectedFramework?.name ?? null
|
|
4749
|
+
});
|
|
4750
|
+
}
|
|
4751
|
+
} else {
|
|
4752
|
+
if (detectedFramework) {
|
|
4753
|
+
output.info(`Detected framework: ${detectedFramework.displayName} (${detectedFramework.npmPackage})`);
|
|
4754
|
+
const { confirmFramework } = await inquirer3.prompt([{
|
|
4755
|
+
type: "confirm",
|
|
4756
|
+
name: "confirmFramework",
|
|
4757
|
+
message: `Use ${detectedFramework.displayName}?`,
|
|
4758
|
+
default: true
|
|
4759
|
+
}]);
|
|
4760
|
+
if (!confirmFramework) {
|
|
4761
|
+
const frameworkChoices = [
|
|
4762
|
+
{ name: "Mastra", value: "mastra" },
|
|
4763
|
+
{ name: "LangChain", value: "langchain" },
|
|
4764
|
+
{ name: "LangGraph", value: "langgraph" },
|
|
4765
|
+
{ name: "Vercel AI SDK", value: "vercel-ai" },
|
|
4766
|
+
{ name: "OpenAI SDK", value: "openai" },
|
|
4767
|
+
{ name: "Generic (OpenAI-compatible)", value: "generic" },
|
|
4768
|
+
{ name: "None / Skip framework", value: "none" }
|
|
4769
|
+
];
|
|
4770
|
+
const { selectedFramework } = await inquirer3.prompt([{
|
|
4771
|
+
type: "list",
|
|
4772
|
+
name: "selectedFramework",
|
|
4773
|
+
message: "Select your AI framework:",
|
|
4774
|
+
choices: frameworkChoices
|
|
4775
|
+
}]);
|
|
4776
|
+
if (selectedFramework === "none") {
|
|
4777
|
+
confirmedFramework = null;
|
|
4778
|
+
} else {
|
|
4779
|
+
const entry = Object.values(FRAMEWORK_DETECTION_MAP).find((f) => f.name === selectedFramework);
|
|
4780
|
+
confirmedFramework = entry ?? null;
|
|
4781
|
+
}
|
|
4782
|
+
}
|
|
4783
|
+
} else {
|
|
4784
|
+
output.info("No AI framework detected in package.json.");
|
|
4785
|
+
}
|
|
4786
|
+
const modeChoices = [
|
|
4787
|
+
...confirmedFramework?.mutagentPackage ? [{
|
|
4788
|
+
name: `Full scaffold - Install @mutagent/sdk + ${confirmedFramework.mutagentPackage}, create config, setup tracing`,
|
|
4789
|
+
value: "full"
|
|
4790
|
+
}] : [],
|
|
4791
|
+
{
|
|
4792
|
+
name: "CLI-only - Verify auth + create .mutagentrc.json config",
|
|
4793
|
+
value: "cli-only"
|
|
4794
|
+
},
|
|
4795
|
+
{
|
|
4796
|
+
name: "Skip - Exit without changes",
|
|
4797
|
+
value: "skip"
|
|
4798
|
+
}
|
|
4799
|
+
];
|
|
4800
|
+
const { selectedMode } = await inquirer3.prompt([{
|
|
4801
|
+
type: "list",
|
|
4802
|
+
name: "selectedMode",
|
|
4803
|
+
message: "How would you like to initialize MutagenT?",
|
|
4804
|
+
choices: modeChoices
|
|
4805
|
+
}]);
|
|
4806
|
+
mode = selectedMode;
|
|
4807
|
+
}
|
|
4808
|
+
if (mode === "skip") {
|
|
4809
|
+
output.info("Init skipped.");
|
|
4810
|
+
return;
|
|
4811
|
+
}
|
|
4812
|
+
const config = loadConfig();
|
|
4813
|
+
const endpoint = config.endpoint ?? "https://api.mutagent.io";
|
|
4814
|
+
const workspace = config.defaultWorkspace;
|
|
4815
|
+
const rcConfig = {
|
|
4816
|
+
endpoint,
|
|
4817
|
+
...workspace ? { workspace } : {},
|
|
4818
|
+
...confirmedFramework ? { framework: confirmedFramework.name } : {}
|
|
4819
|
+
};
|
|
4820
|
+
if (mode === "full" && confirmedFramework?.mutagentPackage) {
|
|
4821
|
+
const pm = detectPackageManager2(cwd);
|
|
4822
|
+
const packages = ["@mutagent/sdk", confirmedFramework.mutagentPackage];
|
|
4823
|
+
const installCmd = getInstallCommand2(pm, packages);
|
|
4824
|
+
output.info(`Installing: ${packages.join(", ")}`);
|
|
4825
|
+
output.info(`Running: ${installCmd}`);
|
|
4826
|
+
try {
|
|
4827
|
+
execSync2(installCmd, { cwd, stdio: "inherit" });
|
|
4828
|
+
output.success("Packages installed successfully.");
|
|
4829
|
+
} catch {
|
|
4830
|
+
output.error("Package installation failed. You can install manually:");
|
|
4831
|
+
output.info(` ${installCmd}`);
|
|
4832
|
+
}
|
|
4833
|
+
writeRcConfig(rcConfig, cwd);
|
|
4834
|
+
output.success("Created .mutagentrc.json");
|
|
4835
|
+
console.log("");
|
|
4836
|
+
output.info("Next steps:");
|
|
4837
|
+
output.info(` 1. Run: mutagent integrate ${confirmedFramework.name}`);
|
|
4838
|
+
output.info(" 2. Follow the integration guide to add tracing to your code");
|
|
4839
|
+
output.info(" 3. Run: mutagent traces list (to verify traces are arriving)");
|
|
4840
|
+
} else {
|
|
4841
|
+
writeRcConfig(rcConfig, cwd);
|
|
4842
|
+
output.success("Created .mutagentrc.json");
|
|
4843
|
+
if (!authenticated) {
|
|
4844
|
+
output.info("Next: mutagent auth login --browser");
|
|
4845
|
+
} else {
|
|
4846
|
+
output.info('Ready! Run "mutagent --help" to see available commands.');
|
|
4847
|
+
}
|
|
4848
|
+
}
|
|
4849
|
+
if (isJson) {
|
|
4850
|
+
output.output({
|
|
4851
|
+
success: true,
|
|
4852
|
+
mode,
|
|
4853
|
+
configFile: ".mutagentrc.json",
|
|
4854
|
+
config: rcConfig,
|
|
4855
|
+
framework: confirmedFramework?.name ?? null,
|
|
4856
|
+
authenticated
|
|
4857
|
+
});
|
|
4858
|
+
}
|
|
4859
|
+
} catch (error) {
|
|
4860
|
+
handleError(error, isJson);
|
|
4861
|
+
}
|
|
4862
|
+
});
|
|
4863
|
+
return init;
|
|
4864
|
+
}
|
|
4865
|
+
|
|
4526
4866
|
// src/bin/cli.ts
|
|
4527
4867
|
var cliVersion = "0.1.1";
|
|
4528
4868
|
try {
|
|
4529
4869
|
const __dirname2 = dirname(fileURLToPath(import.meta.url));
|
|
4530
|
-
const pkgPath =
|
|
4531
|
-
const pkg = JSON.parse(
|
|
4870
|
+
const pkgPath = join3(__dirname2, "..", "..", "package.json");
|
|
4871
|
+
const pkg = JSON.parse(readFileSync12(pkgPath, "utf-8"));
|
|
4532
4872
|
cliVersion = pkg.version ?? cliVersion;
|
|
4533
4873
|
} catch {}
|
|
4534
|
-
var program = new
|
|
4874
|
+
var program = new Command12;
|
|
4535
4875
|
program.name("mutagent").description(`MutagenT CLI - AI-native prompt optimization platform
|
|
4536
4876
|
|
|
4537
4877
|
Documentation: https://docs.mutagent.io/cli
|
|
@@ -4540,43 +4880,45 @@ program.name("mutagent").description(`MutagenT CLI - AI-native prompt optimizati
|
|
|
4540
4880
|
showGlobalOptions: true
|
|
4541
4881
|
});
|
|
4542
4882
|
program.addHelpText("after", `
|
|
4543
|
-
${
|
|
4544
|
-
Export your API key: ${
|
|
4545
|
-
Or pass inline: ${
|
|
4546
|
-
Machine-readable output: ${
|
|
4547
|
-
Disable prompts: ${
|
|
4548
|
-
Set default workspace: ${
|
|
4549
|
-
Set default org: ${
|
|
4883
|
+
${chalk13.yellow("Non-Interactive Mode (CI/CD & Coding Agents):")}
|
|
4884
|
+
Export your API key: ${chalk13.green("export MUTAGENT_API_KEY=mt_your_key_here")}
|
|
4885
|
+
Or pass inline: ${chalk13.green("mutagent prompts list --api-key mt_your_key")}
|
|
4886
|
+
Machine-readable output: ${chalk13.green("mutagent prompts list --json")}
|
|
4887
|
+
Disable prompts: ${chalk13.green("mutagent prompts list --non-interactive")}
|
|
4888
|
+
Set default workspace: ${chalk13.green("mutagent config set workspace <workspace-id>")}
|
|
4889
|
+
Set default org: ${chalk13.green("mutagent config set org <org-id>")}
|
|
4550
4890
|
`);
|
|
4551
4891
|
program.addHelpText("after", `
|
|
4552
|
-
${
|
|
4553
|
-
${
|
|
4892
|
+
${chalk13.yellow("Workflows:")}
|
|
4893
|
+
${chalk13.bold("Evaluate → Optimize Loop:")}
|
|
4554
4894
|
1. mutagent prompts create --name "..." --raw-file prompt.txt
|
|
4555
4895
|
2. mutagent prompts dataset add <prompt-id> --name "..." --file data.json
|
|
4556
4896
|
3. mutagent prompts evaluation create <prompt-id> --name "..." --file criteria.json
|
|
4557
4897
|
4. mutagent prompts optimize start <prompt-id> --dataset <id> --max-iterations 3
|
|
4558
4898
|
|
|
4559
|
-
${
|
|
4899
|
+
${chalk13.bold("Quick Test:")}
|
|
4560
4900
|
mutagent playground run <prompt-id> --input '{"key":"value"}'
|
|
4561
4901
|
|
|
4562
|
-
${
|
|
4563
|
-
${
|
|
4564
|
-
${
|
|
4565
|
-
${
|
|
4566
|
-
${
|
|
4902
|
+
${chalk13.bold("Prerequisites for Optimization:")}
|
|
4903
|
+
${chalk13.green("✓")} Prompt with input/output parameters
|
|
4904
|
+
${chalk13.green("✓")} Dataset with items (input + expectedOutput pairs)
|
|
4905
|
+
${chalk13.green("✓")} Evaluation with criteria (field-level, input/output focused)
|
|
4906
|
+
${chalk13.dim("•")} LLM provider ${chalk13.dim("(only when server uses external providers)")}
|
|
4567
4907
|
`);
|
|
4568
4908
|
program.addHelpText("after", `
|
|
4569
|
-
${
|
|
4570
|
-
${
|
|
4571
|
-
${
|
|
4572
|
-
${
|
|
4573
|
-
${
|
|
4574
|
-
${
|
|
4575
|
-
${
|
|
4576
|
-
${
|
|
4577
|
-
${
|
|
4578
|
-
${!hasCredentials() ?
|
|
4909
|
+
${chalk13.cyan("┌─ AI AGENT INTEGRATION HINT ────────────────────────────────────────────────┐")}
|
|
4910
|
+
${chalk13.cyan("│")} ${chalk13.cyan("│")}
|
|
4911
|
+
${chalk13.cyan("│")} Frameworks: mastra, langchain, langgraph, vercel-ai, claude-code, generic ${chalk13.cyan("│")}
|
|
4912
|
+
${chalk13.cyan("│")} ${chalk13.cyan("│")}
|
|
4913
|
+
${chalk13.cyan("│")} Get integration guide: mutagent integrate <framework> ${chalk13.cyan("│")}
|
|
4914
|
+
${chalk13.cyan("│")} Verify setup: mutagent integrate <framework> --verify ${chalk13.cyan("│")}
|
|
4915
|
+
${chalk13.cyan("│")} Use --json for AI parsing: mutagent <command> --json ${chalk13.cyan("│")}
|
|
4916
|
+
${chalk13.cyan("│")} ${chalk13.cyan("│")}
|
|
4917
|
+
${chalk13.cyan("└────────────────────────────────────────────────────────────────────────────┘")}
|
|
4918
|
+
${!hasCredentials() ? chalk13.yellow(`
|
|
4579
4919
|
Warning: Not authenticated. Run: mutagent auth login --browser
|
|
4920
|
+
`) : ""}${!hasRcConfig() ? chalk13.green(`
|
|
4921
|
+
Get started: mutagent init
|
|
4580
4922
|
`) : ""}`);
|
|
4581
4923
|
program.hook("preAction", (thisCommand) => {
|
|
4582
4924
|
const globalOpts = thisCommand.optsWithGlobals();
|
|
@@ -4590,6 +4932,7 @@ program.hook("preAction", (thisCommand) => {
|
|
|
4590
4932
|
process.env.MUTAGENT_NON_INTERACTIVE = "true";
|
|
4591
4933
|
}
|
|
4592
4934
|
});
|
|
4935
|
+
program.addCommand(createInitCommand());
|
|
4593
4936
|
program.addCommand(createLoginCommand());
|
|
4594
4937
|
program.addCommand(createAuthCommand());
|
|
4595
4938
|
program.addCommand(createConfigCommand());
|
|
@@ -4602,5 +4945,5 @@ program.addCommand(createWorkspacesCommand());
|
|
|
4602
4945
|
program.addCommand(createProvidersCommand());
|
|
4603
4946
|
program.parse();
|
|
4604
4947
|
|
|
4605
|
-
//# debugId=
|
|
4948
|
+
//# debugId=BAA438F82E7B39A164756E2164756E21
|
|
4606
4949
|
//# sourceMappingURL=cli.js.map
|