@mutagent/cli 0.1.139 → 0.1.141

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 CHANGED
@@ -1243,7 +1243,7 @@ var init_sdk_client = __esm(() => {
1243
1243
  // src/bin/cli.ts
1244
1244
  import { Command as Command21 } from "commander";
1245
1245
  import chalk39 from "chalk";
1246
- import { readFileSync as readFileSync13, existsSync as existsSync15 } from "fs";
1246
+ import { readFileSync as readFileSync13, existsSync as existsSync16 } from "fs";
1247
1247
  import { join as join11, dirname as dirname3 } from "path";
1248
1248
  import { fileURLToPath as fileURLToPath2 } from "url";
1249
1249
 
@@ -6008,7 +6008,10 @@ Examples:
6008
6008
  ${chalk16.dim("$")} mutagent prompts optimize status <job-id>
6009
6009
  ${chalk16.dim("$")} mutagent prompts optimize results <job-id>
6010
6010
 
6011
- Workflow: start -> status (poll) -> results | start --watch | watch <job-id>`).action(() => {
6011
+ Workflow: start -> status (poll) -> results | start --watch | watch <job-id>
6012
+
6013
+ ${chalk16.bold("Hit a bug or unexpected result?")}
6014
+ ${chalk16.cyan('mutagent feedback send --category bug -m "describe what went wrong"')}`).action(() => {
6012
6015
  optimize.help();
6013
6016
  });
6014
6017
  prompts.addCommand(optimize);
@@ -6039,6 +6042,9 @@ ${chalk16.yellow(`⚠ COST WARNING — AI Agent:
6039
6042
  max-iterations > 1 without user consent is a protocol violation.`)}
6040
6043
 
6041
6044
  ${chalk16.yellow("AI Agent: ALWAYS append --json to this command.")}
6045
+
6046
+ ${chalk16.bold("Hit a bug or unexpected result?")}
6047
+ ${chalk16.cyan('mutagent feedback send --category bug -m "describe what went wrong"')}
6042
6048
  `).action(async (promptId, options) => {
6043
6049
  const isJson = getJsonFlag(prompts);
6044
6050
  const output = new OutputFormatter(isJson ? "json" : "table");
@@ -6282,6 +6288,8 @@ Suggested fixes:`));
6282
6288
  }
6283
6289
  console.error("");
6284
6290
  console.error(PREREQUISITES_TEXT);
6291
+ console.error(chalk16.dim(`
6292
+ Hit a recurring bug? mutagent feedback send --category bug -m "describe what went wrong"`));
6285
6293
  }
6286
6294
  }
6287
6295
  handleError(error, isJson);
@@ -9546,6 +9554,65 @@ After every CLI command:
9546
9554
 
9547
9555
  ---
9548
9556
 
9557
+ ## Error Recovery — Agent-Aware Bug Reporting
9558
+
9559
+ When ANY mutagent CLI command returns a non-zero exit code or an error response,
9560
+ follow this protocol:
9561
+
9562
+ 1. **Show the error to the user** (always) — reproduce the exact command and output.
9563
+ 2. **ASK the user** if they want to file a bug report with session context.
9564
+ 3. **On user approval**, run:
9565
+ \`\`\`bash
9566
+ echo '{"command":"<failed-cmd>","error":"<error-text>","steps":[...]}' \\
9567
+ | mutagent feedback send --category bug --context - -m "<one-line summary>"
9568
+ \`\`\`
9569
+ - The \`--context -\` flag reads structured JSON from stdin.
9570
+ - Include: the failed command, error message, and recent steps that led to it.
9571
+ - Use \`--json\` for structured confirmation: \`mutagent feedback send ... --json\`
9572
+
9573
+ 4. **After a rejected or failed optimization attempt**, ALSO OFFER this proactively:
9574
+ > "The optimization attempt failed/was rejected. Would you like to file a bug report
9575
+ > so the MutagenT team can investigate? I'll include the session context."
9576
+ On approval, pipe the optimizer job ID, error, and iteration context to \`--context -\`.
9577
+
9578
+ ### Context payload shape
9579
+
9580
+ The \`--context\` flag accepts your JSON payload (caller intent). The CLI wraps
9581
+ auto-captured fields under the reserved \`_auto\` key so they never overwrite
9582
+ top-level keys you supply:
9583
+
9584
+ \`\`\`json
9585
+ {
9586
+ "command": "mutagent prompts optimize start ...",
9587
+ "error": "ApiError: 428 Precondition Required",
9588
+ "jobId": "opt_abc123",
9589
+ "promptId": "prompt_xyz",
9590
+ "steps": ["prompts create", "dataset add", "evaluation create", "optimize start"],
9591
+ "_auto": {
9592
+ "cliVersion": "0.2.1",
9593
+ "platform": "darwin",
9594
+ "nodeVersion": "v20.11.0",
9595
+ "workspaceId": "ws_your_workspace",
9596
+ "timestamp": "2026-04-15T10:00:00.000Z"
9597
+ }
9598
+ }
9599
+ \`\`\`
9600
+
9601
+ \`_auto\` is always populated by the CLI — do **not** set it manually. Your
9602
+ top-level keys are never overwritten; if you supply \`workspaceId: "ws_agent_B"\`,
9603
+ the CLI's current workspace A goes into \`_auto.workspaceId\`, not the top level.
9604
+
9605
+ ### If \`mutagent feedback send\` itself fails
9606
+
9607
+ If the feedback command returns a non-zero exit code, DO NOT retry silently. Show the user:
9608
+
9609
+ 1. The output of \`mutagent auth status\` (confirms login state).
9610
+ 2. The fallback: open https://app.mutagent.io and use the in-app feedback form.
9611
+ 3. Offer to copy the prepared bug report to the clipboard (if running in a macOS/Linux
9612
+ terminal with \`pbcopy\` / \`xclip\`).
9613
+
9614
+ ---
9615
+
9549
9616
  ## Extensibility
9550
9617
 
9551
9618
  Add \`workflows/custom-<name>.md\` with frontmatter \`triggers: ["phrase"]\` — auto-discovered by the decision tree fallback row. No rebuild needed.
@@ -11562,7 +11629,7 @@ import { Command as Command20 } from "commander";
11562
11629
  import chalk38 from "chalk";
11563
11630
  init_errors();
11564
11631
  init_config();
11565
- import { readFileSync as readFileSync12 } from "fs";
11632
+ import { readFileSync as readFileSync12, existsSync as existsSync15 } from "fs";
11566
11633
  import { join as join10, dirname as dirname2 } from "path";
11567
11634
  import { fileURLToPath } from "url";
11568
11635
  var VALID_CATEGORIES = ["bug", "feature", "improvement", "praise"];
@@ -11579,6 +11646,56 @@ function getCliVersion() {
11579
11646
  return "0.1.1";
11580
11647
  }
11581
11648
  }
11649
+ async function readStdin2() {
11650
+ if (process.stdin.isTTY) {
11651
+ throw new MutagentError("INVALID_ARGUMENTS", "--context - requires piped stdin, but stdin is a terminal.", [
11652
+ "Pipe JSON in:",
11653
+ ` echo '{"k":"v"}' | mutagent feedback send --context - ...`,
11654
+ "Or use a file / inline JSON:",
11655
+ " mutagent feedback send --context @/tmp/ctx.json ...",
11656
+ ` mutagent feedback send --context '{"k":"v"}' ...`
11657
+ ].join(`
11658
+ `));
11659
+ }
11660
+ const chunks = [];
11661
+ for await (const chunk of process.stdin) {
11662
+ chunks.push(chunk);
11663
+ }
11664
+ return Buffer.concat(chunks).toString("utf-8").trim();
11665
+ }
11666
+ async function resolveContextSource(source, _readStdinOverride) {
11667
+ if (!source)
11668
+ return null;
11669
+ let raw;
11670
+ if (source === "-") {
11671
+ raw = await (_readStdinOverride ?? readStdin2)();
11672
+ } else if (source.startsWith("@")) {
11673
+ const filePath = source.slice(1);
11674
+ if (!existsSync15(filePath)) {
11675
+ throw new MutagentError("INVALID_ARGUMENTS", `Context file not found: ${filePath}`, `Verify the path exists: ls -la "${filePath}"
11676
+ Or use inline JSON: --context '{"key":"value"}'`);
11677
+ }
11678
+ try {
11679
+ raw = readFileSync12(filePath, "utf-8").trim();
11680
+ } catch (err) {
11681
+ const msg = err instanceof Error ? err.message : String(err);
11682
+ throw new MutagentError("INVALID_ARGUMENTS", `Cannot read context file "${filePath}": ${msg}`, `Check file permissions: ls -la "${filePath}"`);
11683
+ }
11684
+ } else {
11685
+ raw = source.trim();
11686
+ }
11687
+ try {
11688
+ return JSON.parse(raw);
11689
+ } catch {
11690
+ throw new MutagentError("INVALID_ARGUMENTS", `Context is not valid JSON. Received: ${raw.slice(0, 120)}${raw.length > 120 ? "..." : ""}`, [
11691
+ "Provide valid JSON via:",
11692
+ ` Stdin: echo '{"key":"value"}' | mutagent feedback send --context - ...`,
11693
+ " File: mutagent feedback send --context @/path/to/context.json ...",
11694
+ ` Inline: mutagent feedback send --context '{"key":"value"}' ...`
11695
+ ].join(`
11696
+ `));
11697
+ }
11698
+ }
11582
11699
  async function postToServer(payload, endpoint, apiKey, workspaceId, organizationId) {
11583
11700
  const headers = {
11584
11701
  "Content-Type": "application/json",
@@ -11621,6 +11738,7 @@ ${chalk38.bold("Examples:")}
11621
11738
  ${chalk38.yellow("AI Agent (MANDATORY):")}
11622
11739
  ALWAYS use --json: mutagent feedback send -m "..." --category improvement --json
11623
11740
  Use this command to report bugs, request features, or share UX feedback.
11741
+ With session context: echo '{"command":"...","error":"..."}' | mutagent feedback send --category bug --context - -m "..." --json
11624
11742
  `).action(() => {
11625
11743
  feedback.help();
11626
11744
  });
@@ -11628,12 +11746,17 @@ ${chalk38.yellow("AI Agent (MANDATORY):")}
11628
11746
  return feedback;
11629
11747
  }
11630
11748
  function registerFeedbackSend(feedback) {
11631
- feedback.command("send").description("Send feedback about the MutagenT platform").requiredOption("-m, --message <text>", "Feedback message").option("--category <type>", `Feedback category: ${VALID_CATEGORIES.join(", ")}`, "improvement").option("--session <id>", "Link feedback to a specific session").addHelpText("after", `
11749
+ feedback.command("send").description("Send feedback about the MutagenT platform").requiredOption("-m, --message <text>", "Feedback message").option("--category <type>", `Feedback category: ${VALID_CATEGORIES.join(", ")}`, "improvement").option("--session <id>", "Link feedback to a specific session").option("--context <source>", 'Structured JSON context: "-" for stdin, "@<path>" for file, or inline JSON string. Merged with auto-captured fields.').addHelpText("after", `
11632
11750
  ${chalk38.bold("Examples:")}
11633
11751
  ${chalk38.dim("$")} mutagent feedback send -m "The optimization UX could show progress better"
11634
11752
  ${chalk38.dim("$")} mutagent feedback send -m "CLI errored on traces export" --category bug
11635
11753
  ${chalk38.dim("$")} mutagent feedback send -m "Love the guided eval!" --category praise --json
11636
11754
 
11755
+ ${chalk38.bold("With structured context (for agents):")}
11756
+ ${chalk38.dim("$")} echo '{"jobId":"opt_123","error":"timeout"}' | mutagent feedback send --category bug --context - -m "Optimizer timed out"
11757
+ ${chalk38.dim("$")} mutagent feedback send --category bug --context @/tmp/session.json -m "Session data attached"
11758
+ ${chalk38.dim("$")} mutagent feedback send --category bug --context '{"step":"eval-create"}' -m "Eval creation failed"
11759
+
11637
11760
  ${chalk38.bold("Categories:")}
11638
11761
  ${chalk38.bold("bug")} Something is broken or not working as expected
11639
11762
  ${chalk38.bold("feature")} Request a new capability
@@ -11643,6 +11766,7 @@ ${chalk38.bold("Categories:")}
11643
11766
  ${chalk38.yellow("AI Agent (MANDATORY):")}
11644
11767
  ALWAYS use --json: mutagent feedback send -m "..." --json
11645
11768
  Auto-captured context (CLI version, platform, node version) is included automatically.
11769
+ Use --context - to pipe a JSON session summary for richer bug reports.
11646
11770
  `).action(async (options) => {
11647
11771
  const isJson = getJsonFlag(feedback);
11648
11772
  const output = new OutputFormatter(isJson ? "json" : "table");
@@ -11656,18 +11780,24 @@ Valid categories: ${VALID_CATEGORIES.join(", ")}`);
11656
11780
  throw new MutagentError("AUTH_REQUIRED", "Authentication required to send feedback.", `Authenticate first: mutagent auth login
11657
11781
  Or set an API key: mutagent config set apiKey <key>`);
11658
11782
  }
11783
+ const manualContext = await resolveContextSource(options.context);
11659
11784
  const config = loadConfig();
11785
+ const autoContext = {
11786
+ cliVersion: getCliVersion(),
11787
+ platform: process.platform,
11788
+ nodeVersion: process.version,
11789
+ workspaceId: config.defaultWorkspace,
11790
+ timestamp: new Date().toISOString()
11791
+ };
11792
+ const mergedContext = {
11793
+ ...manualContext ?? {},
11794
+ _auto: autoContext
11795
+ };
11660
11796
  const payload = {
11661
11797
  message: options.message,
11662
11798
  category: options.category,
11663
11799
  sessionId: options.session,
11664
- context: {
11665
- cliVersion: getCliVersion(),
11666
- platform: process.platform,
11667
- nodeVersion: process.version,
11668
- workspaceId: config.defaultWorkspace,
11669
- timestamp: new Date().toISOString()
11670
- }
11800
+ context: mergedContext
11671
11801
  };
11672
11802
  const endpoint = config.endpoint ?? "https://api.mutagent.io";
11673
11803
  const result = await postToServer(payload, endpoint, apiKey, config.defaultWorkspace, config.defaultOrganization);
@@ -11678,7 +11808,7 @@ Or set an API key: mutagent config set apiKey <key>`);
11678
11808
  category: options.category,
11679
11809
  message: options.message,
11680
11810
  _links: {
11681
- send: 'mutagent feedback send -m "..." [--category bug|feature|improvement|praise]'
11811
+ send: 'mutagent feedback send -m "..." [--category bug|feature|improvement|praise] [--context <source>]'
11682
11812
  }
11683
11813
  });
11684
11814
  } else {
@@ -11746,6 +11876,11 @@ ${chalk39.yellow("Command Navigation:")}
11746
11876
  mutagent feedback send -m "..." --category bug ${chalk39.dim("Report a bug")}
11747
11877
 
11748
11878
  mutagent integrate <framework> ${chalk39.dim("Framework integration guide")}
11879
+
11880
+ ${chalk39.bold.red("Report Issues:")}
11881
+ Hit a bug? Run: ${chalk39.cyan('mutagent feedback send --category bug -m "describe what went wrong"')}
11882
+ With session context (for AI agents): ${chalk39.cyan('mutagent feedback send --category bug --context - -m "..."')}
11883
+ (pipe JSON session summary via stdin for richer reports)
11749
11884
  mutagent hooks --help ${chalk39.dim("Hook setup for Claude Code telemetry")}
11750
11885
  mutagent skills install ${chalk39.dim("Install the MutagenT CLI skill for AI agents")}
11751
11886
  mutagent playground run <id> --input '{...}' ${chalk39.dim("Quick test")}
@@ -11869,11 +12004,11 @@ var isInteractive = process.stdin.isTTY && !rawArgs.includes("--json") && proces
11869
12004
  var isSkillCommand = rawArgs[0] === "skills" || rawArgs[0] === "hooks";
11870
12005
  if (isInteractive && !isSkillCommand) {
11871
12006
  const skillPath = join11(process.cwd(), ".claude/skills/mutagent-cli/SKILL.md");
11872
- if (!existsSync15(skillPath)) {
12007
+ if (!existsSync16(skillPath)) {
11873
12008
  console.log(chalk39.dim("MutagenT SKILL not installed. Install it for AI agent support? Run:"), chalk39.cyan("mutagent skills install"));
11874
12009
  }
11875
12010
  }
11876
12011
  program.parse();
11877
12012
 
11878
- //# debugId=7CCCA447B8F6661464756E2164756E21
12013
+ //# debugId=9845BF283636AD6E64756E2164756E21
11879
12014
  //# sourceMappingURL=cli.js.map