@mutagent/cli 0.1.29 → 0.1.31

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
@@ -550,7 +550,15 @@ class SDKClientWrapper {
550
550
  this.handleError(error);
551
551
  }
552
552
  }
553
- async removeDataset(_promptId, datasetId) {
553
+ async listDatasetItems(datasetId) {
554
+ try {
555
+ const response = await this.request(`/api/prompts/datasets/${datasetId}/items`);
556
+ return Array.isArray(response) ? response : response.data;
557
+ } catch (error) {
558
+ this.handleError(error);
559
+ }
560
+ }
561
+ async deleteDataset(_promptId, datasetId) {
554
562
  try {
555
563
  await this.request(`/api/prompts/datasets/${datasetId}`, { method: "DELETE" });
556
564
  } catch (error) {
@@ -620,14 +628,41 @@ class SDKClientWrapper {
620
628
  }
621
629
  async getOptimizationStatus(jobId) {
622
630
  try {
623
- return await this.request(`/api/optimization/${jobId}`);
631
+ const raw = await this.request(`/api/optimization/${jobId}`);
632
+ const id = raw.id;
633
+ return {
634
+ ...raw,
635
+ jobId: id ?? jobId,
636
+ progressPercent: typeof raw.progress === "number" ? raw.progress : 0
637
+ };
624
638
  } catch (error) {
625
639
  this.handleError(error);
626
640
  }
627
641
  }
628
642
  async getOptimizationResults(jobId) {
629
643
  try {
630
- return await this.request(`/api/optimization/${jobId}/progress`);
644
+ const job = await this.request(`/api/optimization/${jobId}`);
645
+ const progress = await this.request(`/api/optimization/${jobId}/progress`);
646
+ const prompt = await this.getPrompt(String(job.promptId ?? ""));
647
+ const statesRes = await this.request(`/api/optimization/${jobId}/states`).catch(() => ({ states: [] }));
648
+ const latestState = statesRes.states[statesRes.states.length - 1];
649
+ const iterCtx = latestState?.state.iterationContext;
650
+ const mutatedPromptText = iterCtx?.currentPrompt?.prompt;
651
+ const originalPromptText = iterCtx?.basePrompt?.prompt;
652
+ return {
653
+ job: {
654
+ id: job.id ?? jobId,
655
+ promptId: job.promptId ?? 0,
656
+ status: job.status ?? "unknown",
657
+ config: job.config
658
+ },
659
+ prompt,
660
+ bestScore: job.bestScore,
661
+ iterationsCompleted: job.currentIteration,
662
+ scoreProgression: Array.isArray(progress.progression) ? progress.progression.map((p) => typeof p.score === "number" ? p.score : 0) : undefined,
663
+ mutatedPromptText,
664
+ originalPromptText
665
+ };
631
666
  } catch (error) {
632
667
  this.handleError(error);
633
668
  }
@@ -724,59 +759,6 @@ class SDKClientWrapper {
724
759
  this.handleError(error);
725
760
  }
726
761
  }
727
- async listConversations(agentId, filters) {
728
- try {
729
- const params = new URLSearchParams;
730
- if (filters?.limit)
731
- params.set("limit", String(filters.limit));
732
- if (filters?.offset)
733
- params.set("offset", String(filters.offset));
734
- const query = params.toString();
735
- return await this.request(`/api/agents/${agentId}/conversations${query ? `?${query}` : ""}`);
736
- } catch (error) {
737
- this.handleError(error);
738
- }
739
- }
740
- async getConversation(_agentId, conversationId) {
741
- try {
742
- return await this.request(`/api/conversations/${conversationId}`);
743
- } catch (error) {
744
- this.handleError(error);
745
- }
746
- }
747
- async createConversation(agentId, data) {
748
- try {
749
- return await this.request(`/api/agents/${agentId}/conversations`, {
750
- method: "POST",
751
- body: JSON.stringify({
752
- title: data?.title ?? undefined,
753
- metadata: data?.metadata ?? undefined
754
- })
755
- });
756
- } catch (error) {
757
- this.handleError(error);
758
- }
759
- }
760
- async deleteConversation(_agentId, conversationId) {
761
- try {
762
- await this.request(`/api/conversations/${conversationId}`, { method: "DELETE" });
763
- } catch (error) {
764
- this.handleError(error);
765
- }
766
- }
767
- async listMessages(_agentId, conversationId, filters) {
768
- try {
769
- const params = new URLSearchParams;
770
- if (filters?.limit)
771
- params.set("limit", String(filters.limit));
772
- if (filters?.offset)
773
- params.set("offset", String(filters.offset));
774
- const query = params.toString();
775
- return await this.request(`/api/conversations/${conversationId}/messages${query ? `?${query}` : ""}`);
776
- } catch (error) {
777
- this.handleError(error);
778
- }
779
- }
780
762
  async listWorkspaces(filters) {
781
763
  try {
782
764
  const response = await this.sdk.workspaces.listWorkspaces({
@@ -945,10 +927,10 @@ var init_sdk_client = __esm(() => {
945
927
  });
946
928
 
947
929
  // src/bin/cli.ts
948
- import { Command as Command15 } from "commander";
949
- import chalk18 from "chalk";
950
- import { readFileSync as readFileSync10 } from "fs";
951
- import { join as join7, dirname } from "path";
930
+ import { Command as Command18 } from "commander";
931
+ import chalk23 from "chalk";
932
+ import { readFileSync as readFileSync11 } from "fs";
933
+ import { join as join8, dirname } from "path";
952
934
  import { fileURLToPath } from "url";
953
935
 
954
936
  // src/commands/auth.ts
@@ -1530,7 +1512,7 @@ import { join as join3, relative, extname, basename } from "path";
1530
1512
  var TEMPLATE_VAR_PATTERN = /\{\{[a-zA-Z_][a-zA-Z0-9_]*\}\}/;
1531
1513
  var PROMPT_NAME_PATTERN = /(?:const|let|var|export)\s+\w*(?:prompt|system|agent|instruction|template)\w*\s*=/i;
1532
1514
  var SCHEMA_PATTERN = /["']?(?:inputSchema|outputSchema|properties|required)["']?\s*[=:]/;
1533
- var ZOD_SCHEMA_PATTERN = /z\.object\s*\(/;
1515
+ var ZOD_PROMPT_SCHEMA_PATTERN = /(?:const|let|var|export)\s+\w*(?:prompt|output|input|response|schema|message)\w*\s*=\s*z\.object\s*\(/i;
1534
1516
  var PYDANTIC_PATTERN = /class\s+\w+\s*\(\s*(?:BaseModel|BaseSettings)\s*\)/;
1535
1517
  var MARKER_START_PATTERN = /MutagenT:START\s+(\w+)(?:\s+id=(\S+))?/;
1536
1518
  function walkDir(dir, extensions, excludeDirs, maxDepth, currentDepth = 0) {
@@ -1584,7 +1566,8 @@ function scanForPrompts(filePath, relativePath) {
1584
1566
  file: relativePath,
1585
1567
  line: i + 1,
1586
1568
  preview,
1587
- reason: "template-variable"
1569
+ reason: "template-variable",
1570
+ confidence: "high"
1588
1571
  });
1589
1572
  }
1590
1573
  if (PROMPT_NAME_PATTERN.test(line)) {
@@ -1594,18 +1577,20 @@ function scanForPrompts(filePath, relativePath) {
1594
1577
  file: relativePath,
1595
1578
  line: i + 1,
1596
1579
  preview,
1597
- reason: "prompt-constant"
1580
+ reason: "prompt-constant",
1581
+ confidence: "medium"
1598
1582
  });
1599
1583
  }
1600
1584
  }
1601
- if (ZOD_SCHEMA_PATTERN.test(line)) {
1585
+ if (ZOD_PROMPT_SCHEMA_PATTERN.test(line)) {
1602
1586
  const preview = line.trim().substring(0, 80);
1603
1587
  if (!results.some((r) => r.file === relativePath && r.line === i + 1)) {
1604
1588
  results.push({
1605
1589
  file: relativePath,
1606
1590
  line: i + 1,
1607
1591
  preview,
1608
- reason: "zod-schema"
1592
+ reason: "zod-schema",
1593
+ confidence: "low"
1609
1594
  });
1610
1595
  }
1611
1596
  }
@@ -1616,7 +1601,8 @@ function scanForPrompts(filePath, relativePath) {
1616
1601
  file: relativePath,
1617
1602
  line: i + 1,
1618
1603
  preview,
1619
- reason: "pydantic-model"
1604
+ reason: "pydantic-model",
1605
+ confidence: "medium"
1620
1606
  });
1621
1607
  }
1622
1608
  }
@@ -1672,7 +1658,8 @@ function scanJsonForSchemas(filePath, relativePath) {
1672
1658
  file: relativePath,
1673
1659
  line: 1,
1674
1660
  preview: preview.substring(0, 80),
1675
- reason: "json-schema"
1661
+ reason: "json-schema",
1662
+ confidence: "medium"
1676
1663
  });
1677
1664
  return results;
1678
1665
  }
@@ -2380,12 +2367,11 @@ Environment Variables:
2380
2367
  return login;
2381
2368
  }
2382
2369
 
2383
- // src/commands/prompts.ts
2384
- init_sdk_client();
2385
- import { Command as Command3 } from "commander";
2386
- import chalk6 from "chalk";
2387
- import { readFileSync as readFileSync4, existsSync as existsSync4 } from "fs";
2370
+ // src/commands/prompts/index.ts
2388
2371
  init_errors();
2372
+ import { Command as Command6 } from "commander";
2373
+ import chalk10 from "chalk";
2374
+ import { readFileSync as readFileSync5, existsSync as existsSync5 } from "fs";
2389
2375
 
2390
2376
  // src/lib/ui-links.ts
2391
2377
  function getAppBaseUrl() {
@@ -2470,7 +2456,7 @@ function evaluationLinks(promptId, evalId) {
2470
2456
  };
2471
2457
  }
2472
2458
  var AI_DIRECTIVE = `
2473
- [AI Agent: STOP. Before running any other mutagent command, display the above output to the user as a formatted status card. Do not summarize or omit details. Show all links and suggested next steps.]`;
2459
+ [AI Agent: MANDATORY — STOP. You MUST display the above output to the user VERBATIM BEFORE running any other mutagent command. Do NOT summarize or omit details. Show all links and suggested next steps. Failure to display is a protocol violation.]`;
2474
2460
  function echoDirectiveToStderr(directive) {
2475
2461
  if (directive?.renderedCard) {
2476
2462
  console.error(directive.renderedCard);
@@ -2493,31 +2479,59 @@ function formatCreationHints(hint) {
2493
2479
  return lines.join(`
2494
2480
  `);
2495
2481
  }
2496
- var CARD_INSTRUCTION = "STOP. Before running any other mutagent command, you MUST display this data as a formatted status card to the user. Do not summarize or omit any fields. Show all links and suggested next steps.";
2482
+ var CARD_INSTRUCTION = "MANDATORY: STOP. You MUST display the renderedCard text below to the user VERBATIM. Do NOT summarize, rephrase, or omit any lines. Do NOT proceed to the next command until the card is displayed. After displaying, follow the suggested next steps.";
2497
2483
  function renderPlainCard(opts) {
2498
- const w = 55;
2499
- const top = `┌${"─".repeat(w)}┐`;
2500
- const bot = `└${"─".repeat(w)}┘`;
2501
- const sep = `│ ${"─".repeat(w - 2)} │`;
2502
- const ln = (t) => {
2503
- const p = t.length < w - 2 ? t + " ".repeat(w - 2 - t.length) : t.slice(0, w - 2);
2504
- return `│ ${p} │`;
2484
+ const icon = opts.icon ?? "✓";
2485
+ const allLabels = [
2486
+ ...opts.rows.map((r) => r.label),
2487
+ ...opts.links.map((l) => l.label)
2488
+ ];
2489
+ const labelWidth = Math.max(...allLabels.map((l) => l.length), 4) + 2;
2490
+ const titleText = `─ ${icon} ${opts.title} `;
2491
+ const contentLines = [];
2492
+ for (const r of opts.rows) {
2493
+ contentLines.push(` ${r.label.padEnd(labelWidth)}${r.value}`);
2494
+ }
2495
+ if (opts.links.length) {
2496
+ for (const l of opts.links) {
2497
+ contentLines.push(` ${l.label.padEnd(labelWidth)}${l.url}`);
2498
+ }
2499
+ }
2500
+ if (opts.next.length) {
2501
+ contentLines.push(" Next");
2502
+ for (const n of opts.next) {
2503
+ contentLines.push(` → ${n}`);
2504
+ }
2505
+ }
2506
+ const maxContent = Math.max(titleText.length, ...contentLines.map((l) => l.length));
2507
+ const w = Math.max(60, maxContent + 4);
2508
+ const innerW = w - 2;
2509
+ const pad = (text) => {
2510
+ return text.length < innerW ? text + " ".repeat(innerW - text.length) : text;
2505
2511
  };
2506
- const out = [top, ln(opts.title), sep];
2507
- for (const r of opts.rows)
2508
- out.push(ln(`${r.label}: ${r.value}`));
2512
+ const ln = (text) => `│ ${pad(text)}│`;
2513
+ const blank = () => ln("");
2514
+ const sep = () => `│ ${"─".repeat(innerW - 1)}│`;
2515
+ const titleBorder = `┌${titleText}${"─".repeat(Math.max(0, w - titleText.length - 1))}┐`;
2516
+ const bot = `└${"─".repeat(w)}┘`;
2517
+ const out = [titleBorder, blank()];
2518
+ for (const r of opts.rows) {
2519
+ out.push(ln(` ${r.label.padEnd(labelWidth)}${r.value}`));
2520
+ }
2509
2521
  if (opts.links.length) {
2510
- out.push(sep);
2511
- for (const l of opts.links)
2512
- out.push(ln(`${l.label}: ${l.url}`));
2522
+ out.push(blank(), sep(), blank());
2523
+ for (const l of opts.links) {
2524
+ out.push(ln(` ${l.label.padEnd(labelWidth)}${l.url}`));
2525
+ }
2513
2526
  }
2514
2527
  if (opts.next.length) {
2515
- out.push(sep);
2516
- out.push(ln("Next Steps:"));
2517
- for (const n of opts.next)
2528
+ out.push(blank(), sep(), blank());
2529
+ out.push(ln(" Next"));
2530
+ for (const n of opts.next) {
2518
2531
  out.push(ln(` → ${n}`));
2532
+ }
2519
2533
  }
2520
- out.push(bot);
2534
+ out.push(blank(), bot);
2521
2535
  return out.join(`
2522
2536
  `);
2523
2537
  }
@@ -2526,8 +2540,8 @@ function promptCreatedDirective(promptId, name) {
2526
2540
  const dashboardUrl = promptLink(promptId);
2527
2541
  const apiUrl = `/api/prompts/${String(promptId)}`;
2528
2542
  const rows = [
2529
- { label: "Prompt ID", value: String(promptId) },
2530
- { label: "Name", value: name }
2543
+ { label: "Name", value: name },
2544
+ { label: "Prompt ID", value: String(promptId) }
2531
2545
  ];
2532
2546
  const cardLinks = [
2533
2547
  { label: "Dashboard", url: dashboardUrl },
@@ -2545,7 +2559,7 @@ function promptCreatedDirective(promptId, name) {
2545
2559
  links: { dashboard: dashboardUrl, api: apiUrl },
2546
2560
  next,
2547
2561
  instruction: CARD_INSTRUCTION,
2548
- renderedCard: renderPlainCard({ title, rows, links: cardLinks, next })
2562
+ renderedCard: renderPlainCard({ title, icon: "✓", rows, links: cardLinks, next })
2549
2563
  };
2550
2564
  }
2551
2565
  function promptUpdatedDirective(promptId, name) {
@@ -2553,8 +2567,8 @@ function promptUpdatedDirective(promptId, name) {
2553
2567
  const dashboardUrl = promptLink(promptId);
2554
2568
  const apiUrl = `/api/prompts/${String(promptId)}`;
2555
2569
  const rows = [
2556
- { label: "Prompt ID", value: String(promptId) },
2557
- { label: "Name", value: name }
2570
+ { label: "Name", value: name },
2571
+ { label: "Prompt ID", value: String(promptId) }
2558
2572
  ];
2559
2573
  const cardLinks = [
2560
2574
  { label: "Dashboard", url: dashboardUrl },
@@ -2569,7 +2583,7 @@ function promptUpdatedDirective(promptId, name) {
2569
2583
  links: { dashboard: dashboardUrl, api: apiUrl },
2570
2584
  next,
2571
2585
  instruction: CARD_INSTRUCTION,
2572
- renderedCard: renderPlainCard({ title, rows, links: cardLinks, next })
2586
+ renderedCard: renderPlainCard({ title, icon: "✓", rows, links: cardLinks, next })
2573
2587
  };
2574
2588
  }
2575
2589
  function promptDeletedDirective(promptId) {
@@ -2586,24 +2600,27 @@ function promptDeletedDirective(promptId) {
2586
2600
  links: { dashboard: dashboardUrl },
2587
2601
  next,
2588
2602
  instruction: CARD_INSTRUCTION,
2589
- renderedCard: renderPlainCard({ title, rows, links: cardLinks, next })
2603
+ renderedCard: renderPlainCard({ title, icon: "✗", rows, links: cardLinks, next })
2590
2604
  };
2591
2605
  }
2592
- function datasetAddedDirective(promptId, datasetId, name, itemCount) {
2606
+ function datasetAddedDirective(promptId, datasetId, name, itemCount, state) {
2593
2607
  const title = `Dataset Added — ${name}`;
2594
2608
  const dashboardUrl = datasetLink(promptId, datasetId);
2595
2609
  const apiUrl = `/api/prompts/${String(promptId)}/datasets/${String(datasetId)}`;
2596
2610
  const rows = [
2611
+ { label: "Name", value: name },
2597
2612
  { label: "Prompt ID", value: String(promptId) },
2598
2613
  { label: "Dataset ID", value: String(datasetId) },
2599
- { label: "Name", value: name },
2600
- ...itemCount !== undefined ? [{ label: "Item Count", value: String(itemCount) }] : []
2614
+ ...itemCount !== undefined ? [{ label: "Items", value: String(itemCount) }] : []
2601
2615
  ];
2602
2616
  const cardLinks = [
2603
2617
  { label: "Dashboard", url: dashboardUrl },
2604
2618
  { label: "API", url: apiUrl }
2605
2619
  ];
2606
- const next = [
2620
+ const next = state?.evaluations && state.evaluations > 0 ? [
2621
+ `mutagent prompts optimize start ${String(promptId)} --dataset ${String(datasetId)} --json`,
2622
+ `mutagent prompts evaluation create ${String(promptId)} --guided --json`
2623
+ ] : [
2607
2624
  `mutagent prompts evaluation create ${String(promptId)} --guided --json`,
2608
2625
  `mutagent prompts optimize start ${String(promptId)} --dataset ${String(datasetId)} --json`
2609
2626
  ];
@@ -2620,11 +2637,11 @@ function datasetAddedDirective(promptId, datasetId, name, itemCount) {
2620
2637
  links: { dashboard: dashboardUrl, api: apiUrl },
2621
2638
  next,
2622
2639
  instruction: CARD_INSTRUCTION,
2623
- renderedCard: renderPlainCard({ title, rows, links: cardLinks, next })
2640
+ renderedCard: renderPlainCard({ title, icon: "✓", rows, links: cardLinks, next })
2624
2641
  };
2625
2642
  }
2626
- function datasetRemovedDirective(promptId, datasetId) {
2627
- const title = `Dataset Removed — ${datasetId}`;
2643
+ function datasetDeletedDirective(promptId, datasetId) {
2644
+ const title = `Dataset Deleted — ${datasetId}`;
2628
2645
  const datasetsUrl = promptDatasetsLink(promptId);
2629
2646
  const rows = [
2630
2647
  { label: "Prompt ID", value: promptId },
@@ -2634,31 +2651,34 @@ function datasetRemovedDirective(promptId, datasetId) {
2634
2651
  const next = [`mutagent prompts dataset list ${promptId} --json`];
2635
2652
  return {
2636
2653
  display: "status_card",
2637
- template: "dataset_removed",
2654
+ template: "dataset_deleted",
2638
2655
  title,
2639
2656
  fields: { promptId, datasetId },
2640
2657
  links: { datasets: datasetsUrl },
2641
2658
  next,
2642
2659
  instruction: CARD_INSTRUCTION,
2643
- renderedCard: renderPlainCard({ title, rows, links: cardLinks, next })
2660
+ renderedCard: renderPlainCard({ title, icon: "✗", rows, links: cardLinks, next })
2644
2661
  };
2645
2662
  }
2646
- function evaluationCreatedDirective(promptId, evalId, name, criteriaCount) {
2663
+ function evaluationCreatedDirective(promptId, evalId, name, criteriaCount, state) {
2647
2664
  const title = `Evaluation Created — ${name}`;
2648
2665
  const dashboardUrl = evaluationLink(promptId, evalId);
2649
2666
  const apiUrl = `/api/prompts/${String(promptId)}/evaluations/${String(evalId)}`;
2650
2667
  const rows = [
2668
+ { label: "Name", value: name },
2651
2669
  { label: "Prompt ID", value: String(promptId) },
2652
2670
  { label: "Evaluation ID", value: String(evalId) },
2653
- { label: "Name", value: name },
2654
- { label: "Criteria Count", value: String(criteriaCount) }
2671
+ { label: "Criteria", value: String(criteriaCount) }
2655
2672
  ];
2656
2673
  const cardLinks = [
2657
2674
  { label: "Dashboard", url: dashboardUrl },
2658
2675
  { label: "API", url: apiUrl }
2659
2676
  ];
2660
- const next = [
2661
- `mutagent prompts optimize start ${String(promptId)} --dataset <dataset-id> --json`
2677
+ const next = state?.datasets && state.datasets > 0 ? [
2678
+ `mutagent prompts optimize start ${String(promptId)} --dataset <dataset-id> --evaluation ${String(evalId)} --json`
2679
+ ] : [
2680
+ `mutagent prompts dataset add ${String(promptId)} -d '[...]' --name "my-dataset" --json`,
2681
+ `mutagent prompts optimize start ${String(promptId)} --dataset <dataset-id> --evaluation ${String(evalId)} --json`
2662
2682
  ];
2663
2683
  return {
2664
2684
  display: "status_card",
@@ -2673,7 +2693,7 @@ function evaluationCreatedDirective(promptId, evalId, name, criteriaCount) {
2673
2693
  links: { dashboard: dashboardUrl, api: apiUrl },
2674
2694
  next,
2675
2695
  instruction: CARD_INSTRUCTION,
2676
- renderedCard: renderPlainCard({ title, rows, links: cardLinks, next })
2696
+ renderedCard: renderPlainCard({ title, icon: "✓", rows, links: cardLinks, next })
2677
2697
  };
2678
2698
  }
2679
2699
  function evaluationDeletedDirective(evaluationId) {
@@ -2690,10 +2710,16 @@ function evaluationDeletedDirective(evaluationId) {
2690
2710
  links: { dashboard: dashboardUrl },
2691
2711
  next,
2692
2712
  instruction: CARD_INSTRUCTION,
2693
- renderedCard: renderPlainCard({ title, rows, links: cardLinks, next })
2713
+ renderedCard: renderPlainCard({ title, icon: "✗", rows, links: cardLinks, next })
2694
2714
  };
2695
2715
  }
2696
2716
 
2717
+ // src/commands/prompts/prompts-crud.ts
2718
+ init_sdk_client();
2719
+ import chalk5 from "chalk";
2720
+ import { readFileSync as readFileSync4, existsSync as existsSync4 } from "fs";
2721
+ init_errors();
2722
+
2697
2723
  // src/lib/schema-helpers.ts
2698
2724
  function isValidJsonSchema(schema) {
2699
2725
  if (schema === null || schema === undefined)
@@ -2752,424 +2778,115 @@ function formatSchemaWarning(fieldName) {
2752
2778
  `);
2753
2779
  }
2754
2780
 
2755
- // src/lib/scorecard.ts
2756
- import chalk5 from "chalk";
2757
- function truncateText(text, maxLen) {
2758
- if (text.length <= maxLen)
2759
- return text;
2760
- return text.substring(0, maxLen - 3) + "...";
2761
- }
2762
- function formatScoreChange(before, after) {
2763
- if (before === undefined || after === undefined)
2764
- return "";
2765
- const diff = after - before;
2766
- const pct = before > 0 ? Math.round(diff / before * 100) : 0;
2767
- if (diff > 0)
2768
- return chalk5.green(` (+${String(pct)}%)`);
2769
- if (diff < 0)
2770
- return chalk5.red(` (${String(pct)}%)`);
2771
- return chalk5.dim(" (no change)");
2772
- }
2773
- function formatScore(score) {
2774
- if (score === undefined)
2775
- return chalk5.dim("N/A");
2776
- return score >= 0.8 ? chalk5.green(score.toFixed(2)) : score >= 0.5 ? chalk5.yellow(score.toFixed(2)) : chalk5.red(score.toFixed(2));
2777
- }
2778
- function renderScorecard(data) {
2779
- const { job, prompt } = data;
2780
- const boxWidth = 55;
2781
- const topBorder = `┌${"─".repeat(boxWidth)}┐`;
2782
- const bottomBorder = `└${"─".repeat(boxWidth)}┘`;
2783
- const separator = `│ ${"─".repeat(boxWidth - 2)} │`;
2784
- const pad = (text, width) => {
2785
- const stripped = text.replace(/\u001B\[[0-9;]*m/g, "");
2786
- const remaining = width - stripped.length;
2787
- return remaining > 0 ? text + " ".repeat(remaining) : text;
2788
- };
2789
- const line = (text) => `│ ${pad(text, boxWidth - 2)} │`;
2790
- const originalScore = data.originalScore;
2791
- const bestScore = data.bestScore;
2792
- const iterations = data.iterationsCompleted ?? job.config?.maxIterations ?? 0;
2793
- const originalText = data.originalPrompt?.systemPrompt ?? data.originalPrompt?.rawPrompt ?? "(original prompt)";
2794
- const optimizedText = prompt.systemPrompt ?? prompt.rawPrompt ?? prompt.humanPrompt ?? "(optimized prompt)";
2795
- console.log("");
2796
- console.log(topBorder);
2797
- console.log(line(chalk5.bold("Optimization Results")));
2798
- console.log(separator);
2799
- console.log(line(chalk5.dim("BEFORE")));
2800
- console.log(line(` Prompt: ${chalk5.dim(truncateText(originalText, 38))}`));
2801
- console.log(line(` Score: ${formatScore(originalScore)}`));
2802
- console.log(line(""));
2803
- console.log(line(chalk5.bold("AFTER")));
2804
- console.log(line(` Prompt: ${chalk5.cyan(truncateText(optimizedText, 38))}`));
2805
- console.log(line(` Score: ${formatScore(bestScore)}${formatScoreChange(originalScore, bestScore)}`));
2806
- console.log(separator);
2807
- if (data.criteriaScores && data.criteriaScores.length > 0) {
2808
- console.log(line(chalk5.dim(" Criterion Before After Change")));
2809
- console.log(line(chalk5.dim(" " + "─".repeat(45))));
2810
- for (const c of data.criteriaScores) {
2811
- const name = c.name.length > 16 ? c.name.substring(0, 13) + "..." : c.name;
2812
- const paddedName = name + " ".repeat(18 - name.length);
2813
- const beforeStr = c.before !== undefined ? c.before.toFixed(2) : "N/A ";
2814
- const afterStr = c.after !== undefined ? c.after.toFixed(2) : "N/A ";
2815
- const changeStr = c.before !== undefined && c.after !== undefined && c.before > 0 ? (() => {
2816
- const pct = Math.round((c.after - c.before) / c.before * 100);
2817
- if (pct > 0)
2818
- return chalk5.green(`+${String(pct)}%`);
2819
- if (pct < 0)
2820
- return chalk5.red(`${String(pct)}%`);
2821
- return chalk5.dim("0%");
2822
- })() : "";
2823
- console.log(line(` ${paddedName}${beforeStr} ${afterStr} ${changeStr}`));
2781
+ // src/commands/prompts/prompts-crud.ts
2782
+ function registerPromptsCrud(prompts) {
2783
+ prompts.command("list").description("List all prompts").option("-l, --limit <n>", "Limit results", "50").addHelpText("after", `
2784
+ Examples:
2785
+ ${chalk5.dim("$")} mutagent prompts list
2786
+ ${chalk5.dim("$")} mutagent prompts list --limit 10
2787
+ ${chalk5.dim("$")} mutagent prompts list --json
2788
+
2789
+ ${chalk5.dim("Tip: Use --json for machine-readable output (AI agents, CI pipelines).")}
2790
+ `).action(async (options) => {
2791
+ const isJson = getJsonFlag(prompts);
2792
+ const output = new OutputFormatter(isJson ? "json" : "table");
2793
+ try {
2794
+ const client = getSDKClient();
2795
+ const promptsList = await client.listPrompts();
2796
+ const limit = parseInt(options.limit, 10) || 50;
2797
+ const limited = promptsList.slice(0, limit);
2798
+ if (isJson) {
2799
+ const withLinks = limited.map((p) => ({
2800
+ id: p.id,
2801
+ name: p.name,
2802
+ version: p.version,
2803
+ isLatest: p.isLatest,
2804
+ updatedAt: p.updatedAt,
2805
+ _links: promptLinks(p.id)
2806
+ }));
2807
+ output.output(withLinks);
2808
+ } else {
2809
+ const wsId = client.getCurrentWorkspaceId();
2810
+ if (wsId) {
2811
+ output.info(`Workspace: ${wsId}`);
2812
+ }
2813
+ if (limited.length === 0) {
2814
+ output.info("No prompts found in current workspace. Run 'mutagent config list' to check workspace context.");
2815
+ } else {
2816
+ const formatted = limited.map((p) => ({
2817
+ id: p.id,
2818
+ name: p.name,
2819
+ version: p.version,
2820
+ updated: p.updatedAt ? new Date(p.updatedAt).toLocaleDateString() : "N/A",
2821
+ url: promptLink(p.id)
2822
+ }));
2823
+ output.output(formatted);
2824
+ }
2825
+ }
2826
+ } catch (error) {
2827
+ handleError(error, isJson);
2824
2828
  }
2825
- console.log(line(chalk5.dim(" " + "─".repeat(45))));
2826
- const overallBefore = originalScore !== undefined ? originalScore.toFixed(2) : "N/A ";
2827
- const overallAfter = bestScore !== undefined ? bestScore.toFixed(2) : "N/A ";
2828
- const overallChange = originalScore !== undefined && bestScore !== undefined && originalScore > 0 ? (() => {
2829
- const pct = Math.round((bestScore - originalScore) / originalScore * 100);
2830
- if (pct > 0)
2831
- return chalk5.green(`+${String(pct)}%`);
2832
- if (pct < 0)
2833
- return chalk5.red(`${String(pct)}%`);
2834
- return chalk5.dim("0%");
2835
- })() : "";
2836
- console.log(line(` ${"Overall" + " ".repeat(11)}${overallBefore} ${overallAfter} ${overallChange}`));
2837
- console.log(separator);
2838
- }
2839
- const statusStr = job.status === "completed" ? chalk5.green("completed") : chalk5.yellow(job.status);
2840
- console.log(line(`Status: ${statusStr} | Iterations: ${String(iterations)}`));
2841
- if (job.config?.model) {
2842
- console.log(line(`Model: ${chalk5.dim(job.config.model)}`));
2843
- }
2844
- if (data.scoreProgression && data.scoreProgression.length > 0) {
2845
- console.log(line(""));
2846
- console.log(line(chalk5.dim("Score Progression:")));
2847
- const barWidth = 10;
2848
- for (let i = 0;i < data.scoreProgression.length; i++) {
2849
- const s = data.scoreProgression[i] ?? 0;
2850
- const filled = Math.round(s * barWidth);
2851
- const bar = "█".repeat(filled) + "░".repeat(barWidth - filled);
2852
- console.log(line(chalk5.dim(` #${String(i + 1)}: ${bar} ${s.toFixed(2)}`)));
2853
- }
2854
- }
2855
- console.log(separator);
2856
- console.log(line(`Dashboard: ${chalk5.underline(optimizerLink(job.id))}`));
2857
- console.log(bottomBorder);
2858
- console.log("");
2859
- }
2860
- function renderOptimizationStartCard(data) {
2861
- const { job } = data;
2862
- const boxWidth = 60;
2863
- const topBorder = `┌${"─".repeat(boxWidth)}┐`;
2864
- const bottomBorder = `└${"─".repeat(boxWidth)}┘`;
2865
- const separator = `│ ${"─".repeat(boxWidth - 2)} │`;
2866
- const pad = (text, width) => {
2867
- const stripped = text.replace(/\u001B\[[0-9;]*m/g, "");
2868
- const remaining = width - stripped.length;
2869
- return remaining > 0 ? text + " ".repeat(remaining) : text;
2870
- };
2871
- const line = (text) => `│ ${pad(text, boxWidth - 2)} │`;
2872
- const maxIter = job.config.maxIterations;
2873
- const model = job.config.model ?? "default";
2874
- const target = job.config.targetScore ?? 0.8;
2875
- console.log("");
2876
- console.log(topBorder);
2877
- console.log(line(chalk5.bold("⚡ Optimization Started")));
2878
- console.log(separator);
2879
- console.log(line(`Job ID: ${chalk5.cyan(job.id)}`));
2880
- console.log(line(`Prompt: ${chalk5.dim(data.promptId)}`));
2881
- console.log(line(`Dataset: ${chalk5.dim(data.datasetId)}`));
2882
- console.log(line(`Iterations: ${chalk5.bold(String(maxIter))} | Target: ${chalk5.bold(target.toFixed(2))}`));
2883
- console.log(line(`Model: ${chalk5.dim(model)}`));
2884
- console.log(line(`Status: ${chalk5.yellow(job.status)}`));
2885
- console.log(separator);
2886
- console.log(line(`\uD83D\uDD17 Monitor: ${chalk5.underline(optimizerLink(job.id))}`));
2887
- console.log(line(chalk5.dim(`Next: mutagent prompts optimize status ${job.id}`)));
2888
- console.log(bottomBorder);
2889
- console.log(AI_DIRECTIVE);
2890
- console.log("");
2891
- }
2892
- function renderOptimizationStatusCard(status) {
2893
- const boxWidth = 60;
2894
- const topBorder = `┌${"─".repeat(boxWidth)}┐`;
2895
- const bottomBorder = `└${"─".repeat(boxWidth)}┘`;
2896
- const separator = `│ ${"─".repeat(boxWidth - 2)} │`;
2897
- const pad = (text, width) => {
2898
- const stripped = text.replace(/\u001B\[[0-9;]*m/g, "");
2899
- const remaining = width - stripped.length;
2900
- return remaining > 0 ? text + " ".repeat(remaining) : text;
2901
- };
2902
- const line = (text) => `│ ${pad(text, boxWidth - 2)} │`;
2903
- const progress = status.progressPercent;
2904
- const barWidth = 20;
2905
- const filled = Math.round(progress / 100 * barWidth);
2906
- const progressBar = "█".repeat(filled) + "░".repeat(barWidth - filled);
2907
- const statusColor = status.status === "completed" ? chalk5.green : status.status === "failed" ? chalk5.red : status.status === "cancelled" ? chalk5.gray : status.status === "running" ? chalk5.cyan : chalk5.yellow;
2908
- const scoreStr = status.bestScore !== undefined ? formatScore(status.bestScore) : chalk5.dim("pending");
2909
- console.log("");
2910
- console.log(topBorder);
2911
- console.log(line(chalk5.bold("\uD83D\uDCCA Optimization Status")));
2912
- console.log(separator);
2913
- console.log(line(`Job ID: ${chalk5.cyan(status.jobId)}`));
2914
- console.log(line(`Status: ${statusColor(status.status)}`));
2915
- console.log(line(`Iteration: ${chalk5.bold(`${String(status.currentIteration)}/${String(status.maxIterations)}`)}`));
2916
- console.log(line(`Best Score: ${scoreStr}`));
2917
- console.log(line(""));
2918
- console.log(line(`Progress: [${progressBar}] ${String(progress)}%`));
2919
- if (status.message) {
2920
- console.log(line(`Message: ${chalk5.dim(status.message)}`));
2921
- }
2922
- console.log(separator);
2923
- console.log(line(`\uD83D\uDD17 Monitor: ${chalk5.underline(optimizerLink(status.jobId))}`));
2924
- if (status.status === "completed") {
2925
- console.log(line(chalk5.dim(`Next: mutagent prompts optimize results ${status.jobId}`)));
2926
- } else if (status.status === "running" || status.status === "pending") {
2927
- console.log(line(chalk5.dim(`Refresh: mutagent prompts optimize status ${status.jobId}`)));
2928
- }
2929
- console.log(bottomBorder);
2930
- console.log(AI_DIRECTIVE);
2931
- console.log("");
2932
- }
2933
- function startDirective(job, promptId) {
2934
- const title = `Optimization Started — Prompt ${promptId}`;
2935
- const monitorUrl = optimizerLink(job.id);
2936
- const apiUrl = `/api/prompts/${promptId}/optimizations/${job.id}`;
2937
- const rows = [
2938
- { label: "Job ID", value: job.id },
2939
- { label: "Prompt", value: promptId },
2940
- { label: "Status", value: job.status },
2941
- { label: "Max Iterations", value: String(job.config.maxIterations) },
2942
- { label: "Target Score", value: String(job.config.targetScore ?? 0.8) },
2943
- { label: "Model", value: job.config.model ?? "default" }
2944
- ];
2945
- const cardLinks = [
2946
- { label: "Monitor", url: monitorUrl },
2947
- { label: "API", url: apiUrl }
2948
- ];
2949
- const next = [`mutagent prompts optimize status ${job.id} --json`];
2950
- return {
2951
- display: "status_card",
2952
- template: "optimization_started",
2953
- title,
2954
- fields: {
2955
- jobId: job.id,
2956
- promptId,
2957
- status: job.status,
2958
- maxIterations: job.config.maxIterations,
2959
- targetScore: job.config.targetScore ?? 0.8,
2960
- model: job.config.model ?? "default"
2961
- },
2962
- links: { monitor: monitorUrl, api: apiUrl },
2963
- next,
2964
- instruction: "STOP. Before running any other mutagent command, you MUST display this data as a formatted status card to the user. Do not summarize or omit any fields. Show all links and suggested next steps.",
2965
- renderedCard: renderPlainCard({ title, rows, links: cardLinks, next })
2966
- };
2967
- }
2968
- function statusDirective(status) {
2969
- const next = status.status === "completed" ? [`mutagent prompts optimize results ${status.jobId} --json`] : status.status === "running" || status.status === "pending" ? [`mutagent prompts optimize status ${status.jobId} --json`] : [];
2970
- const title = `Optimization ${status.status} — ${status.jobId}`;
2971
- const rows = [
2972
- { label: "Job ID", value: status.jobId },
2973
- { label: "Status", value: status.status },
2974
- { label: "Iteration", value: `${String(status.currentIteration)}/${String(status.maxIterations)}` },
2975
- { label: "Best Score", value: status.bestScore !== undefined ? String(status.bestScore) : "pending" },
2976
- { label: "Progress", value: `${String(status.progressPercent)}%` },
2977
- ...status.message ? [{ label: "Message", value: status.message }] : []
2978
- ];
2979
- const monitorUrl = optimizerLink(status.jobId);
2980
- const cardLinks = [{ label: "Monitor", url: monitorUrl }];
2981
- return {
2982
- display: "status_card",
2983
- template: "optimization_progress",
2984
- title,
2985
- fields: {
2986
- jobId: status.jobId,
2987
- status: status.status,
2988
- iteration: `${String(status.currentIteration)}/${String(status.maxIterations)}`,
2989
- bestScore: status.bestScore,
2990
- progress: `${String(status.progressPercent)}%`,
2991
- message: status.message
2992
- },
2993
- links: { monitor: monitorUrl },
2994
- next,
2995
- instruction: "STOP. Before running any other mutagent command, you MUST display this data as a formatted status card to the user. Do not summarize or omit any fields. Show all links and suggested next steps.",
2996
- renderedCard: renderPlainCard({ title, rows, links: cardLinks, next })
2997
- };
2998
- }
2999
- function showPromptDiff(original, optimized) {
3000
- console.log("");
3001
- console.log(chalk5.bold(" Prompt Diff:"));
3002
- console.log("");
3003
- console.log(chalk5.red(" - " + (original ?? "(empty)")));
3004
- console.log(chalk5.green(" + " + (optimized ?? "(empty)")));
3005
- console.log("");
3006
- }
3007
-
3008
- // src/commands/prompts.ts
3009
- function updateMutationContext(updater) {
3010
- try {
3011
- const ctx = MutationContext.load();
3012
- updater(ctx);
3013
- ctx.save();
3014
- } catch {}
3015
- }
3016
- var PREREQUISITES_TEXT = `
3017
- ${chalk6.red("Prerequisites (required):")}
3018
- 1. Evaluation criteria defined ${chalk6.dim("(via dashboard or evaluation create)")}
3019
- 2. Dataset uploaded ${chalk6.dim("mutagent prompts dataset list <prompt-id>")}
3020
- ${chalk6.dim("Note: LLM provider config is only required when the server uses external providers (USE_EXT_PROVIDERS=true)")}`;
3021
- function parseValidationErrors(error) {
3022
- if (error instanceof ApiError) {
3023
- try {
3024
- const body = JSON.parse(error.message);
3025
- if (body.errors && Array.isArray(body.errors)) {
3026
- return body.errors.map((e) => e.message ?? JSON.stringify(e));
3027
- }
3028
- if (body.message) {
3029
- return [body.message];
3030
- }
3031
- } catch {
3032
- return [error.message];
3033
- }
3034
- }
3035
- if (error instanceof Error) {
3036
- return [error.message];
3037
- }
3038
- return ["An unknown error occurred"];
3039
- }
3040
- function isSchemaEmpty(schema) {
3041
- if (schema === undefined || schema === null)
3042
- return true;
3043
- if (typeof schema !== "object")
3044
- return false;
3045
- const obj = schema;
3046
- if (Object.keys(obj).length === 0)
3047
- return true;
3048
- return false;
3049
- }
3050
- function createPromptsCommand() {
3051
- const prompts = new Command3("prompts").description("Manage prompts, datasets, evaluations, and optimizations").addHelpText("after", `
3052
- Examples:
3053
- ${chalk6.dim("$")} mutagent prompts list
3054
- ${chalk6.dim("$")} mutagent prompts get <prompt-id>
3055
- ${chalk6.dim("$")} mutagent prompts create --name "my-prompt" --system "You are helpful" --human "{input}"
3056
- ${chalk6.dim("$")} mutagent prompts dataset list <prompt-id>
3057
- ${chalk6.dim("$")} mutagent prompts evaluation create <prompt-id> --name "My Eval"
3058
- ${chalk6.dim("$")} mutagent prompts optimize start <prompt-id> --dataset <dataset-id> --evaluation <eval-id>
3059
-
3060
- Subcommands:
3061
- list, get, create, update, delete
3062
- dataset list|add|remove
3063
- evaluation list|create|delete
3064
- optimize start|status|results
3065
- `);
3066
- prompts.command("list").description("List all prompts").option("-l, --limit <n>", "Limit results", "50").addHelpText("after", `
3067
- Examples:
3068
- ${chalk6.dim("$")} mutagent prompts list
3069
- ${chalk6.dim("$")} mutagent prompts list --limit 10
3070
- ${chalk6.dim("$")} mutagent prompts list --json
3071
-
3072
- ${chalk6.dim("Tip: Use --json for machine-readable output (AI agents, CI pipelines).")}
3073
- `).action(async (options) => {
3074
- const isJson = getJsonFlag(prompts);
3075
- const output = new OutputFormatter(isJson ? "json" : "table");
3076
- try {
3077
- const client = getSDKClient();
3078
- const promptsList = await client.listPrompts();
3079
- const limit = parseInt(options.limit, 10) || 50;
3080
- const limited = promptsList.slice(0, limit);
3081
- if (isJson) {
3082
- const withLinks = limited.map((p) => ({
3083
- id: p.id,
3084
- name: p.name,
3085
- version: p.version,
3086
- isLatest: p.isLatest,
3087
- updatedAt: p.updatedAt,
3088
- _links: promptLinks(p.id)
3089
- }));
3090
- output.output(withLinks);
3091
- } else {
3092
- const wsId = client.getCurrentWorkspaceId();
3093
- if (wsId) {
3094
- output.info(`Workspace: ${wsId}`);
3095
- }
3096
- if (limited.length === 0) {
3097
- output.info("No prompts found in current workspace. Run 'mutagent config list' to check workspace context.");
3098
- } else {
3099
- const formatted = limited.map((p) => ({
3100
- id: p.id,
3101
- name: p.name,
3102
- version: p.version,
3103
- updated: p.updatedAt ? new Date(p.updatedAt).toLocaleDateString() : "N/A",
3104
- url: promptLink(p.id)
3105
- }));
3106
- output.output(formatted);
3107
- }
3108
- }
3109
- } catch (error) {
3110
- handleError(error, isJson);
3111
- }
3112
- });
3113
- prompts.command("get").description("Get prompt details with nested data").argument("<id>", "Prompt ID (from: mutagent prompts list)").option("--with-datasets", "Include datasets").option("--with-evals", "Include evaluations").addHelpText("after", `
3114
- Examples:
3115
- ${chalk6.dim("$")} mutagent prompts get <id>
3116
- ${chalk6.dim("$")} mutagent prompts get <id> --with-datasets --with-evals
3117
- ${chalk6.dim("$")} mutagent prompts get <id> --json
3118
-
3119
- ${chalk6.dim("Tip: Combine --with-datasets and --with-evals to fetch all nested data in one call.")}
3120
- `).action(async (id, options) => {
3121
- const isJson = getJsonFlag(prompts);
3122
- const output = new OutputFormatter(isJson ? "json" : "table");
3123
- try {
3124
- const client = getSDKClient();
3125
- const prompt = await client.getPrompt(id);
3126
- const result = { ...prompt };
3127
- if (options.withDatasets) {
3128
- const datasets = await client.listDatasets(id);
3129
- result.datasets = datasets;
3130
- }
3131
- if (options.withEvals) {
3132
- const evals = await client.listEvaluations(id);
3133
- result.evaluations = evals;
3134
- }
3135
- if (isJson) {
3136
- result._links = promptLinks(id);
3137
- }
3138
- output.output(result);
3139
- if (!isJson) {
3140
- output.info(`View in dashboard: ${promptLink(id)}`);
3141
- }
3142
- } catch (error) {
3143
- handleError(error, isJson);
2829
+ });
2830
+ prompts.command("get").description("Get prompt details with nested data").argument("<id>", "Prompt ID (from: mutagent prompts list)").option("--with-datasets", "Include datasets").option("--with-evals", "Include evaluations").addHelpText("after", `
2831
+ Examples:
2832
+ ${chalk5.dim("$")} mutagent prompts get <id>
2833
+ ${chalk5.dim("$")} mutagent prompts get <id> --with-datasets --with-evals
2834
+ ${chalk5.dim("$")} mutagent prompts get <id> --json
2835
+
2836
+ ${chalk5.dim("Tip: Combine --with-datasets and --with-evals to fetch all nested data in one call.")}
2837
+ `).action(async (id, options) => {
2838
+ const isJson = getJsonFlag(prompts);
2839
+ const output = new OutputFormatter(isJson ? "json" : "table");
2840
+ try {
2841
+ const client = getSDKClient();
2842
+ const prompt = await client.getPrompt(id);
2843
+ const result = { ...prompt };
2844
+ if (options.withDatasets) {
2845
+ const datasets = await client.listDatasets(id);
2846
+ result.datasets = datasets;
2847
+ }
2848
+ if (options.withEvals) {
2849
+ const evals = await client.listEvaluations(id);
2850
+ result.evaluations = evals;
2851
+ }
2852
+ if (isJson) {
2853
+ result._links = promptLinks(id);
2854
+ }
2855
+ output.output(result);
2856
+ if (!isJson) {
2857
+ output.info(`View in dashboard: ${promptLink(id)}`);
2858
+ }
2859
+ } catch (error) {
2860
+ handleError(error, isJson);
3144
2861
  }
3145
2862
  });
3146
2863
  prompts.command("create").description("Create a new prompt").option("-d, --data <json>", "Prompt as JSON string (recommended — curl-style inline)").option("--raw-file <path>", "Create from plain text file (used as rawPrompt)").option("-n, --name <name>", "Prompt name").option("--description <text>", "Prompt description (shown in dashboard)").option("-c, --content <content>", "Prompt content (rawPrompt) [DEPRECATED: use --raw]").option("-r, --raw <text>", "Raw prompt text (single prompt)").option("--system <text>", "System prompt (use with --human)").option("--human <text>", "Human prompt (use with --system)").option("--messages <json>", `Messages array as JSON (e.g., '[{"role":"system","content":"..."}]')`).option("--output-schema <json>", "Output schema as JSON string (required for optimization)").addHelpText("after", `
3147
2864
  Examples:
3148
- ${chalk6.dim("$")} mutagent prompts create --name "my-prompt" --description "Greeting prompt for customers" --system "You are helpful" --human "{input}" --output-schema '{"type":"object","properties":{"result":{"type":"string","description":"The result"}}}'
3149
- ${chalk6.dim("$")} mutagent prompts create --name "raw-prompt" --raw "Summarize: {text}" --output-schema '{"type":"object","properties":{"summary":{"type":"string","description":"Summary"}}}'
3150
- ${chalk6.dim("$")} mutagent prompts create -d '{"name":"summarizer","systemPrompt":"Summarize","humanPrompt":"{text}","outputSchema":{"type":"object","properties":{"summary":{"type":"string","description":"Summary"}}}}'
2865
+ ${chalk5.dim("$")} mutagent prompts create --name "my-prompt" --description "Greeting prompt for customers" --system "You are helpful" --human "{input}" --output-schema '{"type":"object","properties":{"result":{"type":"string","description":"The result"}}}'
2866
+ ${chalk5.dim("$")} mutagent prompts create --name "raw-prompt" --raw "Summarize: {text}" --output-schema '{"type":"object","properties":{"summary":{"type":"string","description":"Summary"}}}'
2867
+ ${chalk5.dim("$")} mutagent prompts create -d '{"name":"summarizer","systemPrompt":"Summarize","humanPrompt":"{text}","outputSchema":{"type":"object","properties":{"summary":{"type":"string","description":"Summary"}}}}'
3151
2868
 
3152
2869
  Prompt Input Methods (pick one, priority order):
3153
- --system/--human Structured system + user message pair ${chalk6.green("(recommended)")}
2870
+ --system/--human Structured system + user message pair ${chalk5.green("(recommended)")}
3154
2871
  --raw Single raw prompt text with {variables}
3155
2872
  -d, --data Inline JSON object (CI/scripts/agents)
3156
2873
  --messages Full messages array as JSON
3157
2874
  --raw-file Load plain text file as raw prompt
3158
2875
 
3159
2876
  Expected JSON (--data):
3160
- ${chalk6.dim(`'{"name":"my-prompt","systemPrompt":"You are...","humanPrompt":"{input}","outputSchema":{"type":"object","properties":{"result":{"type":"string","description":"The result"}}},"inputSchema":{"type":"object","properties":{"input":{"type":"string","description":"User input"}}}}'`)}
2877
+ ${chalk5.dim(`'{"name":"my-prompt","systemPrompt":"You are...","humanPrompt":"{input}","outputSchema":{"type":"object","properties":{"result":{"type":"string","description":"The result"}}},"inputSchema":{"type":"object","properties":{"input":{"type":"string","description":"User input"}}}}'`)}
3161
2878
 
3162
- ${chalk6.yellow("Variable Syntax:")}
2879
+ ${chalk5.yellow("Variable Syntax:")}
3163
2880
  MutagenT uses {single_braces} for template variables.
3164
- humanPrompt: "Analyze this: {document}" ${chalk6.green("✓ correct")}
3165
- humanPrompt: "Analyze this: {{document}}" ${chalk6.red("✗ wrong")}
2881
+ humanPrompt: "Analyze this: {document}" ${chalk5.green("✓ correct")}
2882
+ humanPrompt: "Analyze this: {{document}}" ${chalk5.red("✗ wrong")}
3166
2883
 
3167
2884
  Variables in humanPrompt MUST also appear in inputSchema.properties.
3168
2885
  Static prompts (no variables) cannot substitute inputs during optimization.
3169
2886
 
3170
- ${chalk6.red("outputSchema is required.")}
2887
+ ${chalk5.red("outputSchema is required.")}
3171
2888
 
3172
- ${chalk6.yellow("AI Agent: ALWAYS append --json to this command.")}
2889
+ ${chalk5.yellow("AI Agent: ALWAYS append --json to this command.")}
3173
2890
  `).action(async (options) => {
3174
2891
  const isJson = getJsonFlag(prompts);
3175
2892
  const output = new OutputFormatter(isJson ? "json" : "table");
@@ -3292,13 +3009,13 @@ Add a 'description' field to each property in your inputSchema. Example: { "prop
3292
3009
  });
3293
3010
  prompts.command("update").description("Update a prompt").argument("<id>", "Prompt ID (from: mutagent prompts list)").option("-d, --data <json>", "Update fields as JSON string (recommended — curl-style inline)").option("--raw-file <path>", "Update from plain text file (used as rawPrompt)").option("-n, --name <name>", "New name").option("--description <text>", "New description (shown in dashboard)").option("-c, --content <content>", "New content (rawPrompt) [DEPRECATED: use --raw]").option("-r, --raw <text>", "Raw prompt text (single prompt)").option("--system <text>", "System prompt (use with --human)").option("--human <text>", "Human prompt (use with --system)").option("--messages <json>", `Messages array as JSON (e.g., '[{"role":"system","content":"..."}]')`).option("--input-schema <json>", "Input schema as JSON string").option("--input-schema-file <path>", "Input schema from JSON file").option("--output-schema <json>", "Output schema as JSON string").option("--output-schema-file <path>", "Output schema from JSON file").addHelpText("after", `
3294
3011
  Examples:
3295
- ${chalk6.dim("$")} mutagent prompts update <id> --system "Updated system prompt" --human "{input}"
3296
- ${chalk6.dim("$")} mutagent prompts update <id> --name "new-name" --description "Updated description"
3297
- ${chalk6.dim("$")} mutagent prompts update <id> --raw "Summarize: {text}"
3298
- ${chalk6.dim("$")} mutagent prompts update <id> -d '{"name":"new-name","systemPrompt":"Updated prompt"}'
3299
- ${chalk6.dim("$")} mutagent prompts update <id> --input-schema '{"type":"object","properties":{"text":{"type":"string","description":"Input text"}}}'
3012
+ ${chalk5.dim("$")} mutagent prompts update <id> --system "Updated system prompt" --human "{input}"
3013
+ ${chalk5.dim("$")} mutagent prompts update <id> --name "new-name" --description "Updated description"
3014
+ ${chalk5.dim("$")} mutagent prompts update <id> --raw "Summarize: {text}"
3015
+ ${chalk5.dim("$")} mutagent prompts update <id> -d '{"name":"new-name","systemPrompt":"Updated prompt"}'
3016
+ ${chalk5.dim("$")} mutagent prompts update <id> --input-schema '{"type":"object","properties":{"text":{"type":"string","description":"Input text"}}}'
3300
3017
 
3301
- ${chalk6.dim("CLI flags (--name) override --data fields.")}
3018
+ ${chalk5.dim("CLI flags (--name) override --data fields.")}
3302
3019
  `).action(async (id, options) => {
3303
3020
  const isJson = getJsonFlag(prompts);
3304
3021
  const output = new OutputFormatter(isJson ? "json" : "table");
@@ -3355,52 +3072,12 @@ ${chalk6.dim("CLI flags (--name) override --data fields.")}
3355
3072
  data.rawPrompt = options.content;
3356
3073
  }
3357
3074
  }
3358
- if (options.inputSchema && options.inputSchemaFile) {
3359
- throw new MutagentError("INVALID_ARGUMENTS", "Cannot use --input-schema and --input-schema-file together", `Run: mutagent prompts update --help
3360
- ` + "Use --input-schema for inline JSON or --input-schema-file for file-based input, not both");
3361
- }
3362
- if (options.inputSchema) {
3363
- try {
3364
- data.inputSchema = JSON.parse(options.inputSchema);
3365
- } catch {
3366
- throw new MutagentError("INVALID_JSON", "Invalid JSON in --input-schema flag", `Run: mutagent prompts update --help
3367
- ` + `Provide a valid JSON Schema, e.g., '{"type":"object","properties":{"text":{"type":"string","description":"Input text"}}}'`);
3368
- }
3369
- } else if (options.inputSchemaFile) {
3370
- if (!existsSync4(options.inputSchemaFile)) {
3371
- throw new MutagentError("FILE_NOT_FOUND", `File not found: ${options.inputSchemaFile}`, `Run: mutagent prompts update --help
3372
- ` + "Check the file path and try again");
3373
- }
3374
- try {
3375
- data.inputSchema = JSON.parse(readFileSync4(options.inputSchemaFile, "utf-8"));
3376
- } catch {
3377
- throw new MutagentError("INVALID_JSON", `Failed to parse JSON from ${options.inputSchemaFile}`, `Run: mutagent prompts update --help
3378
- ` + "Ensure the file contains valid JSON Schema");
3379
- }
3380
- }
3381
- if (options.outputSchema && options.outputSchemaFile) {
3382
- throw new MutagentError("INVALID_ARGUMENTS", "Cannot use --output-schema and --output-schema-file together", `Run: mutagent prompts update --help
3383
- ` + "Use --output-schema for inline JSON or --output-schema-file for file-based input, not both");
3384
- }
3385
- if (options.outputSchema) {
3386
- try {
3387
- data.outputSchema = JSON.parse(options.outputSchema);
3388
- } catch {
3389
- throw new MutagentError("INVALID_JSON", "Invalid JSON in --output-schema flag", `Run: mutagent prompts update --help
3390
- ` + `Provide a valid JSON Schema, e.g., '{"type":"object","properties":{"result":{"type":"string"}}}'`);
3391
- }
3392
- } else if (options.outputSchemaFile) {
3393
- if (!existsSync4(options.outputSchemaFile)) {
3394
- throw new MutagentError("FILE_NOT_FOUND", `File not found: ${options.outputSchemaFile}`, `Run: mutagent prompts update --help
3395
- ` + "Check the file path and try again");
3396
- }
3397
- try {
3398
- data.outputSchema = JSON.parse(readFileSync4(options.outputSchemaFile, "utf-8"));
3399
- } catch {
3400
- throw new MutagentError("INVALID_JSON", `Failed to parse JSON from ${options.outputSchemaFile}`, `Run: mutagent prompts update --help
3401
- ` + "Ensure the file contains valid JSON Schema");
3402
- }
3403
- }
3075
+ const parsedInputSchema = parseSchemaOption(options.inputSchema, options.inputSchemaFile, "input-schema", "mutagent prompts update --help");
3076
+ if (parsedInputSchema)
3077
+ data.inputSchema = parsedInputSchema;
3078
+ const parsedOutputSchema = parseSchemaOption(options.outputSchema, options.outputSchemaFile, "output-schema", "mutagent prompts update --help");
3079
+ if (parsedOutputSchema)
3080
+ data.outputSchema = parsedOutputSchema;
3404
3081
  if (data.inputSchema && isValidJsonSchema(data.inputSchema)) {
3405
3082
  const missingDescs = validateSchemaDescriptions(data.inputSchema);
3406
3083
  if (missingDescs.length > 0) {
@@ -3441,11 +3118,11 @@ ${chalk6.dim("CLI flags (--name) override --data fields.")}
3441
3118
  });
3442
3119
  prompts.command("delete").description("Delete a prompt").argument("<id>", "Prompt ID (from: mutagent prompts list)").option("--force", "Skip confirmation").addHelpText("after", `
3443
3120
  Examples:
3444
- ${chalk6.dim("$")} mutagent prompts delete <id>
3445
- ${chalk6.dim("$")} mutagent prompts delete <id> --force
3446
- ${chalk6.dim("$")} mutagent prompts delete <id> --force --json
3121
+ ${chalk5.dim("$")} mutagent prompts delete <id>
3122
+ ${chalk5.dim("$")} mutagent prompts delete <id> --force
3123
+ ${chalk5.dim("$")} mutagent prompts delete <id> --force --json
3447
3124
 
3448
- ${chalk6.dim("Note: --force is required. The CLI is non-interactive — confirm with the user via your native flow, then pass --force.")}
3125
+ ${chalk5.dim("Note: --force is required. The CLI is non-interactive — confirm with the user via your native flow, then pass --force.")}
3449
3126
  `).action(async (id, options) => {
3450
3127
  const isJson = getJsonFlag(prompts);
3451
3128
  const output = new OutputFormatter(isJson ? "json" : "table");
@@ -3483,11 +3160,19 @@ ${chalk6.dim("Note: --force is required. The CLI is non-interactive — confirm
3483
3160
  handleError(error, isJson);
3484
3161
  }
3485
3162
  });
3163
+ }
3164
+
3165
+ // src/commands/prompts/datasets.ts
3166
+ init_sdk_client();
3167
+ import { Command as Command3 } from "commander";
3168
+ import chalk6 from "chalk";
3169
+ init_errors();
3170
+ function registerDatasetCommands(prompts) {
3486
3171
  const dataset = new Command3("dataset").description("Manage datasets for prompts").addHelpText("after", `
3487
3172
  Examples:
3488
3173
  ${chalk6.dim("$")} mutagent prompts dataset list <prompt-id>
3489
3174
  ${chalk6.dim("$")} mutagent prompts dataset add <prompt-id> -d '[{"input":{...},"expectedOutput":{...}}]'
3490
- ${chalk6.dim("$")} mutagent prompts dataset remove <prompt-id> <dataset-id>
3175
+ ${chalk6.dim("$")} mutagent prompts dataset delete <prompt-id> <dataset-id>
3491
3176
  `).action(() => {
3492
3177
  dataset.help();
3493
3178
  });
@@ -3576,7 +3261,12 @@ ${chalk6.red("Required: --data must be provided.")}
3576
3261
  const client = getSDKClient();
3577
3262
  const datasetResult = await client.addDataset(promptId, content, datasetName);
3578
3263
  if (isJson) {
3579
- const directive = datasetAddedDirective(promptId, datasetResult.id, datasetResult.name, datasetResult.itemCount);
3264
+ let rsState;
3265
+ try {
3266
+ const evals = await client.listEvaluations(promptId);
3267
+ rsState = { evaluations: evals.length };
3268
+ } catch {}
3269
+ const directive = datasetAddedDirective(promptId, datasetResult.id, datasetResult.name, datasetResult.itemCount, rsState);
3580
3270
  output.output({
3581
3271
  ...datasetResult,
3582
3272
  _links: datasetLinks(promptId, datasetResult.id),
@@ -3608,77 +3298,197 @@ ${chalk6.red("Required: --data must be provided.")}
3608
3298
  handleError(error, isJson);
3609
3299
  }
3610
3300
  });
3611
- dataset.command("remove").description("Remove dataset from a prompt").argument("<prompt-id>", "Prompt ID (from: mutagent prompts list)").argument("<dataset-id>", "Dataset ID (from: mutagent prompts dataset list <prompt-id>)").option("--force", "Skip confirmation").addHelpText("after", `
3301
+ dataset.command("delete").description("Delete a dataset from a prompt").argument("<prompt-id>", "Prompt ID (from: mutagent prompts list)").argument("<dataset-id>", "Dataset ID (from: mutagent prompts dataset list <prompt-id>)").option("--force", "Skip confirmation").addHelpText("after", `
3612
3302
  Examples:
3613
- ${chalk6.dim("$")} mutagent prompts dataset remove <prompt-id> <dataset-id>
3614
- ${chalk6.dim("$")} mutagent prompts dataset remove <prompt-id> <dataset-id> --force
3615
- ${chalk6.dim("$")} mutagent prompts dataset remove <prompt-id> <dataset-id> --force --json
3303
+ ${chalk6.dim("$")} mutagent prompts dataset delete <prompt-id> <dataset-id>
3304
+ ${chalk6.dim("$")} mutagent prompts dataset delete <prompt-id> <dataset-id> --force
3305
+ ${chalk6.dim("$")} mutagent prompts dataset delete <prompt-id> <dataset-id> --force --json
3616
3306
  `).action(async (promptId, datasetId, options) => {
3617
3307
  const isJson = getJsonFlag(prompts);
3618
3308
  const output = new OutputFormatter(isJson ? "json" : "table");
3619
3309
  try {
3620
3310
  if (!options.force && !isJson) {
3621
- throw new MutagentError("CONFIRMATION_REQUIRED", `Removing dataset ${datasetId} from prompt ${promptId} requires confirmation`, `Run: mutagent prompts dataset remove --help
3311
+ throw new MutagentError("CONFIRMATION_REQUIRED", `Deleting dataset ${datasetId} from prompt ${promptId} requires confirmation`, `Run: mutagent prompts dataset delete --help
3622
3312
  ` + `[Agent: Ask the user to confirm via MultiChoice, then pass --force]
3623
- ` + `Use --force to confirm: mutagent prompts dataset remove ${promptId} ${datasetId} --force`);
3313
+ ` + `Use --force to confirm: mutagent prompts dataset delete ${promptId} ${datasetId} --force`);
3624
3314
  }
3625
3315
  const client = getSDKClient();
3626
3316
  try {
3627
- await client.removeDataset(promptId, datasetId);
3317
+ await client.deleteDataset(promptId, datasetId);
3628
3318
  } catch (deleteError) {
3629
3319
  if (deleteError instanceof ApiError && deleteError.statusCode === 404) {
3630
3320
  if (isJson) {
3631
- const directive = datasetRemovedDirective(promptId, datasetId);
3321
+ const directive = datasetDeletedDirective(promptId, datasetId);
3632
3322
  output.output({ success: true, deletedId: datasetId, _links: { datasets: promptDatasetsLink(promptId) }, _directive: directive });
3633
3323
  echoDirectiveToStderr(directive);
3634
3324
  } else {
3635
- output.success(`Dataset ${datasetId} already removed (idempotent)`);
3325
+ output.success(`Dataset ${datasetId} already deleted (idempotent)`);
3636
3326
  }
3637
3327
  return;
3638
3328
  }
3639
3329
  throw deleteError;
3640
3330
  }
3641
3331
  if (isJson) {
3642
- const directive = datasetRemovedDirective(promptId, datasetId);
3332
+ const directive = datasetDeletedDirective(promptId, datasetId);
3643
3333
  output.output({ success: true, deletedId: datasetId, _links: { datasets: promptDatasetsLink(promptId) }, _directive: directive });
3644
3334
  echoDirectiveToStderr(directive);
3645
3335
  } else {
3646
- output.success(`Removed dataset ${datasetId} from prompt ${promptId}`);
3336
+ output.success(`Deleted dataset ${datasetId} from prompt ${promptId}`);
3647
3337
  output.info(`View datasets: ${promptDatasetsLink(promptId)}`);
3648
3338
  }
3649
3339
  } catch (error) {
3650
3340
  handleError(error, isJson);
3651
3341
  }
3652
3342
  });
3653
- const evaluation = new Command3("evaluation").description("Manage evaluations for prompts").addHelpText("after", `
3654
- Examples:
3655
- ${chalk6.dim("$")} mutagent prompts evaluation list <prompt-id>
3656
- ${chalk6.dim("$")} mutagent prompts evaluation get <evaluation-id>
3657
- ${chalk6.dim("$")} mutagent prompts evaluation create <prompt-id> --name "My Eval"
3658
- ${chalk6.dim("$")} mutagent prompts evaluation delete <evaluation-id>
3659
- `).action(() => {
3660
- evaluation.help();
3661
- });
3662
- prompts.addCommand(evaluation);
3663
- evaluation.command("list").description("List evaluations for a prompt").argument("<prompt-id>", "Prompt ID (from: mutagent prompts list)").addHelpText("after", `
3664
- Examples:
3665
- ${chalk6.dim("$")} mutagent prompts evaluation list <prompt-id>
3666
- ${chalk6.dim("$")} mutagent prompts evaluation list <prompt-id> --json
3667
- `).action(async (promptId) => {
3668
- const isJson = getJsonFlag(prompts);
3669
- const output = new OutputFormatter(isJson ? "json" : "table");
3670
- try {
3671
- const client = getSDKClient();
3672
- const evals = await client.listEvaluations(promptId);
3673
- if (isJson) {
3674
- const withLinks = evals.map((e) => ({
3675
- id: e.id,
3676
- name: e.name,
3677
- description: e.description,
3678
- datasetId: e.datasetId,
3679
- updatedAt: e.updatedAt,
3680
- _links: evaluationLinks(promptId, e.id)
3681
- }));
3343
+ }
3344
+
3345
+ // src/commands/prompts/evaluations.ts
3346
+ init_sdk_client();
3347
+ import { Command as Command4 } from "commander";
3348
+ import chalk7 from "chalk";
3349
+ init_errors();
3350
+
3351
+ // src/commands/prompts/guided-workflow.ts
3352
+ init_sdk_client();
3353
+ async function buildGuidedWorkflow(promptId) {
3354
+ const client = getSDKClient();
3355
+ const prompt = await client.getPrompt(promptId);
3356
+ const truncate = (s, max) => s.length > max ? s.slice(0, max) + "..." : s;
3357
+ const outputProperties = prompt.outputSchema && typeof prompt.outputSchema === "object" ? prompt.outputSchema.properties ?? {} : {};
3358
+ const inputProperties = prompt.inputSchema && typeof prompt.inputSchema === "object" ? prompt.inputSchema.properties ?? {} : {};
3359
+ const inputFields = Object.keys(inputProperties);
3360
+ const outputFields = Object.keys(outputProperties);
3361
+ const allFields = [
3362
+ ...inputFields.map((f) => ({ field: f, source: "inputSchema", fieldSchema: inputProperties[f] })),
3363
+ ...outputFields.map((f) => ({ field: f, source: "outputSchema", fieldSchema: outputProperties[f] }))
3364
+ ];
3365
+ let datasetExample = null;
3366
+ try {
3367
+ const datasets = await client.listDatasets(promptId);
3368
+ if (datasets.length > 0) {
3369
+ try {
3370
+ const dsId = datasets[0]?.id;
3371
+ const items = dsId != null ? await client.listDatasetItems(String(dsId)) : [];
3372
+ if (items.length > 0) {
3373
+ const firstItem = items[0];
3374
+ datasetExample = firstItem?.expectedOutput ?? firstItem?.input ?? null;
3375
+ }
3376
+ } catch {}
3377
+ }
3378
+ } catch {}
3379
+ const askUserQuestions = allFields.map(({ field, source, fieldSchema }) => {
3380
+ const isInput = source === "inputSchema";
3381
+ const question = isInput ? `Define the Minimum Viable Context for "${field}". What data MUST be present in this input for the prompt to produce a correct output? Describe what constitutes complete vs incomplete input, and WHY this field matters.` : `Define what correct "${field}" looks like. What structure, content, or qualities make it good vs bad? Give concrete examples of good and bad outputs.`;
3382
+ const hint = isInput ? `Input fields define what data the prompt NEEDS to work correctly. Without defining minimum viable context, the optimizer cannot detect whether failures come from bad input or bad prompt logic.` : null;
3383
+ const header = isInput ? `${field} [INPUT]` : `${field} [OUTPUT]`;
3384
+ const defineDesc = isInput ? `Describe what data MUST be present in "${field}" and WHY the prompt needs it. Focus on completeness and minimum viable context.` : `Describe what a correct vs incorrect "${field}" looks like. Focus on structure, content quality, and concrete examples — not numeric scores.`;
3385
+ return {
3386
+ question,
3387
+ header,
3388
+ ...hint != null ? { hint } : {},
3389
+ options: [
3390
+ {
3391
+ label: "Define rubric",
3392
+ description: defineDesc
3393
+ },
3394
+ {
3395
+ label: "See suggestion",
3396
+ description: `Get a suggested rubric based on the prompt and schema definition for "${field}". You can refine it.`
3397
+ }
3398
+ ],
3399
+ multiSelect: false,
3400
+ context: {
3401
+ fieldType: fieldSchema?.type ?? "unknown",
3402
+ fieldDescription: fieldSchema?.description ?? null,
3403
+ fieldSource: source,
3404
+ promptExcerpt: truncate(prompt.humanPrompt ?? prompt.systemPrompt ?? prompt.rawPrompt ?? "", 200),
3405
+ exampleValue: datasetExample?.[field] ?? null
3406
+ }
3407
+ };
3408
+ });
3409
+ return {
3410
+ prompt: { id: promptId, name: prompt.name },
3411
+ inputSchema: { fields: inputFields },
3412
+ outputSchema: { fields: outputFields },
3413
+ workflow: {
3414
+ description: "Follow these steps to create an evaluation for this prompt:",
3415
+ steps: [
3416
+ { step: 1, action: "Review prompt schemas and context", detail: "Understand what the prompt does and what each field means." },
3417
+ { step: 2, action: "Define correctness criteria for EVERY field", detail: `For EACH of the ${String(allFields.length)} fields in askUserQuestions, use AskUserQuestion to collect a rubric. INPUT fields (${String(inputFields.length)}): collect minimum viable context definitions — what data MUST exist. OUTPUT fields (${String(outputFields.length)}): collect correctness criteria — what correct vs incorrect looks like. Do NOT skip any field. Use the context hints to suggest rubrics when asked.` },
3418
+ { step: 3, action: "Build criteria JSON", detail: "Map each rubric to: { name: field, description: rubric, evaluationParameter: field }" },
3419
+ { step: 4, action: "Ask for evaluation name", detail: "Ask user what to name this evaluation" },
3420
+ { step: 5, action: "Create the evaluation", detail: `mutagent prompts evaluation create ${promptId} --name "<name>" -d '<json>' --json` }
3421
+ ],
3422
+ criteriaTemplate: {
3423
+ evalConfig: {
3424
+ criteria: [{
3425
+ name: "<criterion_name>",
3426
+ description: "<correctness rubric - describe what correct vs incorrect looks like>",
3427
+ evaluationParameter: `<one of: ${allFields.length > 0 ? allFields.map((f) => f.field).join(", ") : "no fields detected - check prompt schemas"}>`
3428
+ }]
3429
+ }
3430
+ },
3431
+ exampleCommand: `mutagent prompts evaluation create ${promptId} --name "My Evaluation" -d '${JSON.stringify({
3432
+ evalConfig: {
3433
+ criteria: outputFields.slice(0, 1).map((f) => ({
3434
+ name: `${f} accuracy`,
3435
+ description: `Correct if ${f} matches expected structure and content; incorrect if missing, malformed, or off-topic`,
3436
+ evaluationParameter: f
3437
+ }))
3438
+ }
3439
+ })}'`
3440
+ },
3441
+ askUserQuestions,
3442
+ _directive: {
3443
+ display: "workflow_guide",
3444
+ instruction: `MANDATORY ORDERS — READ CAREFULLY:
3445
+ ` + `1. You MUST ask the user about EVERY SINGLE field listed in askUserQuestions. There are ${String(allFields.length)} fields total.
3446
+ ` + `2. Do NOT skip ANY field. Do NOT decide that a field "doesn't need" a definition.
3447
+ ` + `3. INPUT fields (${String(inputFields.length)}): These define MINIMUM VIABLE CONTEXT — the data that MUST exist in the input for the prompt to work. Ask: "What data MUST be present in this field and WHY does the prompt need it?"
3448
+ ` + ` WHY THIS MATTERS: Without minimum viable context definitions, the optimizer cannot distinguish between failures caused by incomplete input vs failures caused by bad prompt logic.
3449
+ ` + `4. OUTPUT fields (${String(outputFields.length)}): These define correctness criteria. Ask: "What does correct vs incorrect for this field look like?"
3450
+ ` + `5. After collecting ALL ${String(allFields.length)} definitions, construct the --data JSON with criteria for EVERY field.
3451
+ ` + "6. VIOLATION: Skipping ANY field or telling the user a field doesn't need a definition is a protocol violation.",
3452
+ aiAgentDecisionTree: {
3453
+ step1: "Check if criteria already exist in the user's code. If criteria match expected shape (name + description + evaluationParameter targeting schema fields), use --data directly.",
3454
+ step2: "If criteria are missing or malformed, use the askUserQuestions payloads to collect them via AskUserQuestion.",
3455
+ step3: `After collecting all criteria, construct the --data JSON and run: mutagent prompts evaluation create <prompt-id> --name "<name>" -d '<json>'`
3456
+ }
3457
+ },
3458
+ _meta: { inputFields, outputFields, allFields }
3459
+ };
3460
+ }
3461
+
3462
+ // src/commands/prompts/evaluations.ts
3463
+ function registerEvaluationCommands(prompts) {
3464
+ const evaluation = new Command4("evaluation").description("Manage evaluations for prompts").addHelpText("after", `
3465
+ Examples:
3466
+ ${chalk7.dim("$")} mutagent prompts evaluation list <prompt-id>
3467
+ ${chalk7.dim("$")} mutagent prompts evaluation get <evaluation-id>
3468
+ ${chalk7.dim("$")} mutagent prompts evaluation create <prompt-id> --name "My Eval"
3469
+ ${chalk7.dim("$")} mutagent prompts evaluation delete <evaluation-id>
3470
+ `).action(() => {
3471
+ evaluation.help();
3472
+ });
3473
+ prompts.addCommand(evaluation);
3474
+ evaluation.command("list").description("List evaluations for a prompt").argument("<prompt-id>", "Prompt ID (from: mutagent prompts list)").addHelpText("after", `
3475
+ Examples:
3476
+ ${chalk7.dim("$")} mutagent prompts evaluation list <prompt-id>
3477
+ ${chalk7.dim("$")} mutagent prompts evaluation list <prompt-id> --json
3478
+ `).action(async (promptId) => {
3479
+ const isJson = getJsonFlag(prompts);
3480
+ const output = new OutputFormatter(isJson ? "json" : "table");
3481
+ try {
3482
+ const client = getSDKClient();
3483
+ const evals = await client.listEvaluations(promptId);
3484
+ if (isJson) {
3485
+ const withLinks = evals.map((e) => ({
3486
+ id: e.id,
3487
+ name: e.name,
3488
+ description: e.description,
3489
+ updatedAt: e.updatedAt,
3490
+ _links: evaluationLinks(promptId, e.id)
3491
+ }));
3682
3492
  output.output(withLinks);
3683
3493
  } else {
3684
3494
  const formatted = evals.map((e) => ({
@@ -3696,8 +3506,8 @@ Examples:
3696
3506
  });
3697
3507
  evaluation.command("get").description("Get evaluation details including criteria").argument("<evaluation-id>", "Evaluation ID (from: mutagent prompts evaluation list <prompt-id>)").addHelpText("after", `
3698
3508
  Examples:
3699
- ${chalk6.dim("$")} mutagent prompts evaluation get <evaluation-id>
3700
- ${chalk6.dim("$")} mutagent prompts evaluation get <evaluation-id> --json
3509
+ ${chalk7.dim("$")} mutagent prompts evaluation get <evaluation-id>
3510
+ ${chalk7.dim("$")} mutagent prompts evaluation get <evaluation-id> --json
3701
3511
  `).action(async (evaluationId) => {
3702
3512
  const isJson = getJsonFlag(prompts);
3703
3513
  const output = new OutputFormatter(isJson ? "json" : "table");
@@ -3714,9 +3524,6 @@ Examples:
3714
3524
  if (evalObj.description) {
3715
3525
  console.log(` Description: ${evalObj.description}`);
3716
3526
  }
3717
- if (evalObj.datasetId != null) {
3718
- console.log(` Dataset ID: ${String(evalObj.datasetId)}`);
3719
- }
3720
3527
  console.log(` Created: ${evalObj.createdAt ? new Date(String(evalObj.createdAt)).toLocaleDateString() : "N/A"}`);
3721
3528
  console.log("");
3722
3529
  const config = evalObj.evalConfig;
@@ -3724,7 +3531,7 @@ Examples:
3724
3531
  if (criteria && Array.isArray(criteria) && criteria.length > 0) {
3725
3532
  console.log(" Criteria:");
3726
3533
  for (const c of criteria) {
3727
- console.log(` ${chalk6.cyan(c.name)}`);
3534
+ console.log(` ${chalk7.cyan(c.name)}`);
3728
3535
  if (c.description) {
3729
3536
  console.log(` Description: ${c.description}`);
3730
3537
  }
@@ -3752,9 +3559,9 @@ Examples:
3752
3559
  });
3753
3560
  evaluation.command("create").description("Create an evaluation configuration for a prompt").argument("<prompt-id>", "Prompt ID (from: mutagent prompts list)").option("-d, --data <json>", "Evaluation as JSON string (for pre-validated criteria only)").option("-n, --name <name>", "Evaluation name (required unless --guided)").option("--description <text>", "Evaluation description").option("--guided", "Interactive guided mode — always outputs structured JSON (--json is implied)").addHelpText("after", `
3754
3561
  Examples:
3755
- ${chalk6.dim("$")} mutagent prompts evaluation create <prompt-id> --guided ${chalk6.dim("# recommended: shows workflow guide + schema fields")}
3756
- ${chalk6.dim("$")} mutagent prompts evaluation create <prompt-id> --guided --json ${chalk6.dim("# structured workflow for AI agents")}
3757
- ${chalk6.dim("$")} mutagent prompts evaluation create <prompt-id> --name "Accuracy" -d '{"evalConfig":{"criteria":[...]}}' ${chalk6.dim("# power user")}
3562
+ ${chalk7.dim("$")} mutagent prompts evaluation create <prompt-id> --guided ${chalk7.dim("# recommended: shows workflow guide + schema fields")}
3563
+ ${chalk7.dim("$")} mutagent prompts evaluation create <prompt-id> --guided --json ${chalk7.dim("# structured workflow for AI agents")}
3564
+ ${chalk7.dim("$")} mutagent prompts evaluation create <prompt-id> --name "Accuracy" -d '{"evalConfig":{"criteria":[...]}}' ${chalk7.dim("# power user")}
3758
3565
 
3759
3566
  Guided Workflow (recommended):
3760
3567
  --guided outputs a workflow guide that:
@@ -3775,12 +3582,12 @@ AI Agent (MANDATORY):
3775
3582
  mutagent prompts evaluation create <id> --name "<name>" -d '<json>' --json
3776
3583
 
3777
3584
  Expected Criteria Shape (--data):
3778
- ${chalk6.dim('{"evalConfig":{"criteria":[{"name":"<name>","description":"<scoring rubric>","evaluationParameter":"<schema field>"}]}}')}
3585
+ ${chalk7.dim('{"evalConfig":{"criteria":[{"name":"<name>","description":"<scoring rubric>","evaluationParameter":"<schema field>"}]}}')}
3779
3586
  evaluationParameter must target an outputSchema OR inputSchema field.
3780
3587
 
3781
- ${chalk6.red("Required: --name (unless --guided). Criteria must include evaluationParameter.")}
3782
- ${chalk6.dim("CLI flags (--name, --description) override --data fields.")}
3783
- ${chalk6.dim("Get prompt IDs: mutagent prompts list")}
3588
+ ${chalk7.red("Required: --name (unless --guided). Criteria must include evaluationParameter.")}
3589
+ ${chalk7.dim("CLI flags (--name, --description) override --data fields.")}
3590
+ ${chalk7.dim("Get prompt IDs: mutagent prompts list")}
3784
3591
  `).action(async (promptId, options) => {
3785
3592
  let isJson = getJsonFlag(prompts);
3786
3593
  if (options.guided) {
@@ -3788,75 +3595,6 @@ ${chalk6.dim("Get prompt IDs: mutagent prompts list")}
3788
3595
  }
3789
3596
  const output = new OutputFormatter(isJson ? "json" : "table");
3790
3597
  try {
3791
- const buildGuidedWorkflow = async () => {
3792
- const client2 = getSDKClient();
3793
- const prompt = await client2.getPrompt(promptId);
3794
- const inputFields = prompt.inputSchema && typeof prompt.inputSchema === "object" ? Object.keys(prompt.inputSchema.properties ?? {}) : [];
3795
- const outputFields = prompt.outputSchema && typeof prompt.outputSchema === "object" ? Object.keys(prompt.outputSchema.properties ?? {}) : [];
3796
- const allFields = [
3797
- ...outputFields.map((f) => ({ field: f, source: "outputSchema" })),
3798
- ...inputFields.map((f) => ({ field: f, source: "inputSchema" }))
3799
- ];
3800
- const askUserQuestions = allFields.map(({ field, source }) => ({
3801
- question: `Define the scoring rubric for "${field}" (${source}). Be specific — what exactly constitutes a perfect score (1.0) vs a complete failure (0.0)? Include concrete examples of each score level.`,
3802
- header: field,
3803
- options: [
3804
- {
3805
- label: "Custom",
3806
- description: `Write a detailed, specific scoring rubric for "${field}". Must describe concrete pass/fail criteria with examples — not just "0.0 to 1.0 scale".`
3807
- },
3808
- {
3809
- label: "Skip",
3810
- description: `Do not create a criterion for "${field}". Only skip if this field is not relevant to evaluation quality.`
3811
- }
3812
- ],
3813
- multiSelect: false
3814
- }));
3815
- return {
3816
- prompt: { id: promptId, name: prompt.name },
3817
- inputSchema: { fields: inputFields },
3818
- outputSchema: { fields: outputFields },
3819
- workflow: {
3820
- description: "Follow these steps to create an evaluation for this prompt:",
3821
- steps: [
3822
- { step: 1, action: "Review the prompt schemas above", detail: "Each criterion must target a field from outputSchema (preferred) or inputSchema" },
3823
- { step: 2, action: "Ask the user for a scoring rubric for each field", detail: 'For EACH field, ask: "What does a perfect score (1.0) vs failure (0.0) look like for <field>? Give concrete examples." Do NOT auto-generate or use canned rubrics.' },
3824
- { step: 3, action: "Build criteria JSON from user answers", detail: `Map each user answer to a criterion: { name: "<field> <rubric>", description: "<user's rubric>", evaluationParameter: "<field>" }` },
3825
- { step: 4, action: "Ask for evaluation name", detail: 'Ask the user what to name this evaluation (e.g., "Accuracy Check", "Quality Eval")' },
3826
- { step: 5, action: "Create the evaluation", detail: `Run: mutagent prompts evaluation create <prompt-id> --name "<name>" -d '{"evalConfig":{"criteria":[...]}}'` }
3827
- ],
3828
- criteriaTemplate: {
3829
- evalConfig: {
3830
- criteria: [{
3831
- name: "<criterion_name>",
3832
- description: "<scoring rubric - describe what 1.0 vs 0.0 means>",
3833
- evaluationParameter: `<one of: ${allFields.length > 0 ? allFields.map((f) => f.field).join(", ") : "no fields detected - check prompt schemas"}>`
3834
- }]
3835
- }
3836
- },
3837
- exampleCommand: `mutagent prompts evaluation create ${promptId} --name "My Evaluation" -d '${JSON.stringify({
3838
- evalConfig: {
3839
- criteria: outputFields.slice(0, 1).map((f) => ({
3840
- name: `${f} accuracy`,
3841
- description: `Score 1.0 if ${f} matches expected output exactly, 0.0 otherwise`,
3842
- evaluationParameter: f
3843
- }))
3844
- }
3845
- })}'`
3846
- },
3847
- askUserQuestions,
3848
- _directive: {
3849
- display: "workflow_guide",
3850
- instruction: 'STOP. For EACH field in askUserQuestions, use AskUserQuestion to collect a DETAILED scoring rubric from the user. Do NOT auto-generate rubrics. Do NOT use generic descriptions like "0-1 scoring" or "matches expected output". Each rubric MUST include concrete examples of what earns a 1.0, 0.5, and 0.0 score for that specific field. Then construct the --data JSON and create the evaluation.',
3851
- aiAgentDecisionTree: {
3852
- step1: "Check if criteria already exist in the user's code. If criteria match expected shape (name + description + evaluationParameter targeting schema fields), use --data directly.",
3853
- step2: "If criteria are missing or malformed, use the askUserQuestions payloads to collect them via AskUserQuestion.",
3854
- step3: `After collecting all criteria, construct the --data JSON and run: mutagent prompts evaluation create <prompt-id> --name "<name>" -d '<json>'`
3855
- }
3856
- },
3857
- _meta: { inputFields, outputFields, allFields }
3858
- };
3859
- };
3860
3598
  const renderGuidedWorkflow = (wf) => {
3861
3599
  const { inputFields, outputFields, allFields } = wf._meta;
3862
3600
  if (isJson) {
@@ -3873,26 +3611,26 @@ ${chalk6.dim("Get prompt IDs: mutagent prompts list")}
3873
3611
  console.log(` Input Schema Fields: ${inputFields.join(", ")}`);
3874
3612
  }
3875
3613
  console.log("");
3876
- console.log(" For each field, define a scoring criterion:");
3614
+ console.log(" For each field, define what correct output looks like:");
3877
3615
  for (const { field, source } of allFields) {
3878
- console.log(` ${chalk6.cyan(field)} (${source})`);
3879
- console.log(` → What does 1.0 vs 0.0 mean for "${field}"?`);
3616
+ console.log(` ${chalk7.cyan(field)} (${source})`);
3617
+ console.log(` → What makes a correct vs incorrect "${field}"?`);
3880
3618
  }
3881
3619
  console.log("");
3882
3620
  console.log(" Then create the evaluation:");
3883
3621
  console.log(` mutagent prompts evaluation create ${promptId} --name "My Eval" \\`);
3884
- console.log(` -d '{"evalConfig":{"criteria":[{"name":"accuracy","description":"Score 1.0 if correct","evaluationParameter":"${outputFields[0] ?? "<field>"}"}]}}'`);
3622
+ console.log(` -d '{"evalConfig":{"criteria":[{"name":"accuracy","description":"Correct if output matches expected structure","evaluationParameter":"${outputFields[0] ?? "<field>"}"}]}}'`);
3885
3623
  console.log("");
3886
3624
  }
3887
3625
  };
3888
3626
  if (options.guided) {
3889
- const workflow = await buildGuidedWorkflow();
3627
+ const workflow = await buildGuidedWorkflow(promptId);
3890
3628
  renderGuidedWorkflow(workflow);
3891
3629
  return;
3892
3630
  }
3893
3631
  if (!options.data) {
3894
3632
  if (isJson || process.stdout.isTTY) {
3895
- const workflow = await buildGuidedWorkflow();
3633
+ const workflow = await buildGuidedWorkflow(promptId);
3896
3634
  renderGuidedWorkflow(workflow);
3897
3635
  return;
3898
3636
  }
@@ -3931,9 +3669,9 @@ ${chalk6.dim("Get prompt IDs: mutagent prompts list")}
3931
3669
  let fieldsHint = "";
3932
3670
  try {
3933
3671
  const client2 = getSDKClient();
3934
- const prompt = await client2.getPrompt(promptId);
3935
- if (prompt.outputSchema && typeof prompt.outputSchema === "object") {
3936
- const props = prompt.outputSchema.properties;
3672
+ const prompt2 = await client2.getPrompt(promptId);
3673
+ if (prompt2.outputSchema && typeof prompt2.outputSchema === "object") {
3674
+ const props = prompt2.outputSchema.properties;
3937
3675
  if (props && typeof props === "object") {
3938
3676
  const fields = Object.keys(props);
3939
3677
  if (fields.length > 0) {
@@ -3984,9 +3722,9 @@ Example JSON (--data flag):
3984
3722
  let availableFields = [];
3985
3723
  try {
3986
3724
  const client2 = getSDKClient();
3987
- const prompt = await client2.getPrompt(promptId);
3988
- if (prompt.outputSchema && typeof prompt.outputSchema === "object") {
3989
- const props = prompt.outputSchema.properties;
3725
+ const prompt2 = await client2.getPrompt(promptId);
3726
+ if (prompt2.outputSchema && typeof prompt2.outputSchema === "object") {
3727
+ const props = prompt2.outputSchema.properties;
3990
3728
  if (props && typeof props === "object") {
3991
3729
  availableFields = Object.keys(props);
3992
3730
  }
@@ -4001,11 +3739,54 @@ Available output fields: ${availableFields.join(", ")}` : "";
4001
3739
  Example:
4002
3740
  --data '{"evalConfig":{"criteria":[` + '{"name":"Accuracy","description":"...","evaluationParameter":"classification"},' + '{"name":"Confidence","description":"...","evaluationParameter":"confidence"}' + "]}}'");
4003
3741
  }
3742
+ const schemaClient = getSDKClient();
3743
+ const prompt = await schemaClient.getPrompt(promptId);
3744
+ const requiredFields = [];
3745
+ if (prompt.inputSchema && typeof prompt.inputSchema === "object") {
3746
+ const props = prompt.inputSchema.properties;
3747
+ if (props && typeof props === "object") {
3748
+ for (const field of Object.keys(props)) {
3749
+ requiredFields.push({ field, source: "inputSchema" });
3750
+ }
3751
+ }
3752
+ }
3753
+ if (prompt.outputSchema && typeof prompt.outputSchema === "object") {
3754
+ const props = prompt.outputSchema.properties;
3755
+ if (props && typeof props === "object") {
3756
+ for (const field of Object.keys(props)) {
3757
+ requiredFields.push({ field, source: "outputSchema" });
3758
+ }
3759
+ }
3760
+ }
3761
+ if (requiredFields.length > 0) {
3762
+ const coveredParams = new Set(criteria.map((c) => c.evaluationParameter));
3763
+ const missing = requiredFields.filter((f) => !coveredParams.has(f.field));
3764
+ if (missing.length > 0) {
3765
+ const missingList = missing.map((m) => `${m.field} (${m.source})`).join(", ");
3766
+ throw new MutagentError("VALIDATION_ERROR", `Evaluation criteria are INCOMPLETE. Missing fields: ${missingList}`, `Each input and output schema field MUST have a corresponding criterion.
3767
+ ` + `Total required: ${requiredFields.length}, provided: ${coveredParams.size}
3768
+ ` + "Run: mutagent prompts evaluation create " + promptId + " --guided --json");
3769
+ }
3770
+ }
3771
+ if (requiredFields.length > 0) {
3772
+ const validFieldNames = new Set(requiredFields.map((f) => f.field));
3773
+ const invalidParams = criteria.filter((c) => c.evaluationParameter && !validFieldNames.has(c.evaluationParameter));
3774
+ if (invalidParams.length > 0) {
3775
+ const invalidList = invalidParams.map((c) => `"${c.evaluationParameter}" (criterion: ${c.name})`).join(", ");
3776
+ throw new MutagentError("VALIDATION_ERROR", `Invalid evaluationParameter(s): ${invalidList}. Must match a schema field.`, `Available fields: ${requiredFields.map((f) => f.field).join(", ")}
3777
+ ` + "Run: mutagent prompts evaluation create " + promptId + " --guided --json");
3778
+ }
3779
+ }
4004
3780
  const client = getSDKClient();
4005
3781
  const evalResult = await client.createEvaluation(promptId, evalData);
4006
3782
  if (isJson) {
4007
3783
  const criteriaLen = evalData.evalConfig?.criteria?.length ?? 0;
4008
- const directive = evaluationCreatedDirective(promptId, evalResult.id, evalResult.name, criteriaLen);
3784
+ let rsState;
3785
+ try {
3786
+ const datasets = await client.listDatasets(promptId);
3787
+ rsState = { datasets: datasets.length };
3788
+ } catch {}
3789
+ const directive = evaluationCreatedDirective(promptId, evalResult.id, evalResult.name, criteriaLen, rsState);
4009
3790
  output.output({
4010
3791
  ...evalResult,
4011
3792
  _links: evaluationLinks(promptId, evalResult.id),
@@ -4033,9 +3814,9 @@ Example:
4033
3814
  });
4034
3815
  evaluation.command("delete").description("Delete an evaluation").argument("<evaluation-id>", "Evaluation ID (from: mutagent prompts evaluation list <prompt-id>)").option("--force", "Skip confirmation").addHelpText("after", `
4035
3816
  Examples:
4036
- ${chalk6.dim("$")} mutagent prompts evaluation delete <evaluation-id>
4037
- ${chalk6.dim("$")} mutagent prompts evaluation delete <evaluation-id> --force
4038
- ${chalk6.dim("$")} mutagent prompts evaluation delete <evaluation-id> --force --json
3817
+ ${chalk7.dim("$")} mutagent prompts evaluation delete <evaluation-id>
3818
+ ${chalk7.dim("$")} mutagent prompts evaluation delete <evaluation-id> --force
3819
+ ${chalk7.dim("$")} mutagent prompts evaluation delete <evaluation-id> --force --json
4039
3820
  `).action(async (evaluationId, options) => {
4040
3821
  const isJson = getJsonFlag(prompts);
4041
3822
  const output = new OutputFormatter(isJson ? "json" : "table");
@@ -4073,11 +3854,290 @@ Examples:
4073
3854
  handleError(error, isJson);
4074
3855
  }
4075
3856
  });
4076
- const optimize = new Command3("optimize").description("Manage prompt optimization jobs").addHelpText("after", `
3857
+ }
3858
+
3859
+ // src/commands/prompts/optimize.ts
3860
+ init_sdk_client();
3861
+ import { Command as Command5 } from "commander";
3862
+ import chalk9 from "chalk";
3863
+ init_errors();
3864
+
3865
+ // src/lib/scorecard.ts
3866
+ import chalk8 from "chalk";
3867
+ function truncateText(text, maxLen) {
3868
+ if (text.length <= maxLen)
3869
+ return text;
3870
+ return text.substring(0, maxLen - 3) + "...";
3871
+ }
3872
+ function formatScoreChange(before, after) {
3873
+ if (before === undefined || after === undefined)
3874
+ return "";
3875
+ const diff = after - before;
3876
+ const pct = before > 0 ? Math.round(diff / before * 100) : 0;
3877
+ if (diff > 0)
3878
+ return chalk8.green(` (+${String(pct)}%)`);
3879
+ if (diff < 0)
3880
+ return chalk8.red(` (${String(pct)}%)`);
3881
+ return chalk8.dim(" (no change)");
3882
+ }
3883
+ function formatScore(score) {
3884
+ if (score === undefined)
3885
+ return chalk8.dim("N/A");
3886
+ return score >= 0.8 ? chalk8.green(score.toFixed(2)) : score >= 0.5 ? chalk8.yellow(score.toFixed(2)) : chalk8.red(score.toFixed(2));
3887
+ }
3888
+ function renderScorecard(data) {
3889
+ const { job, prompt } = data;
3890
+ const boxWidth = 55;
3891
+ const topBorder = `┌${"─".repeat(boxWidth)}┐`;
3892
+ const bottomBorder = `└${"─".repeat(boxWidth)}┘`;
3893
+ const separator = `│ ${"─".repeat(boxWidth - 2)} │`;
3894
+ const pad = (text, width) => {
3895
+ const stripped = text.replace(/\u001B\[[0-9;]*m/g, "");
3896
+ const remaining = width - stripped.length;
3897
+ return remaining > 0 ? text + " ".repeat(remaining) : text;
3898
+ };
3899
+ const line = (text) => `│ ${pad(text, boxWidth - 2)} │`;
3900
+ const originalScore = data.originalScore;
3901
+ const bestScore = data.bestScore;
3902
+ const iterations = data.iterationsCompleted ?? job.config?.maxIterations ?? 0;
3903
+ const originalText = data.originalPrompt?.systemPrompt ?? data.originalPrompt?.rawPrompt ?? "(original prompt)";
3904
+ const optimizedText = prompt.systemPrompt ?? prompt.rawPrompt ?? prompt.humanPrompt ?? "(optimized prompt)";
3905
+ console.log("");
3906
+ console.log(topBorder);
3907
+ console.log(line(chalk8.bold("Optimization Results")));
3908
+ console.log(separator);
3909
+ console.log(line(chalk8.dim("BEFORE")));
3910
+ console.log(line(` Prompt: ${chalk8.dim(truncateText(originalText, 38))}`));
3911
+ console.log(line(` Score: ${formatScore(originalScore)}`));
3912
+ console.log(line(""));
3913
+ console.log(line(chalk8.bold("AFTER")));
3914
+ console.log(line(` Prompt: ${chalk8.cyan(truncateText(optimizedText, 38))}`));
3915
+ console.log(line(` Score: ${formatScore(bestScore)}${formatScoreChange(originalScore, bestScore)}`));
3916
+ console.log(separator);
3917
+ if (data.criteriaScores && data.criteriaScores.length > 0) {
3918
+ console.log(line(chalk8.dim(" Criterion Before After Change")));
3919
+ console.log(line(chalk8.dim(" " + "─".repeat(45))));
3920
+ for (const c of data.criteriaScores) {
3921
+ const name = c.name.length > 16 ? c.name.substring(0, 13) + "..." : c.name;
3922
+ const paddedName = name + " ".repeat(18 - name.length);
3923
+ const beforeStr = c.before !== undefined ? c.before.toFixed(2) : "N/A ";
3924
+ const afterStr = c.after !== undefined ? c.after.toFixed(2) : "N/A ";
3925
+ const changeStr = c.before !== undefined && c.after !== undefined && c.before > 0 ? (() => {
3926
+ const pct = Math.round((c.after - c.before) / c.before * 100);
3927
+ if (pct > 0)
3928
+ return chalk8.green(`+${String(pct)}%`);
3929
+ if (pct < 0)
3930
+ return chalk8.red(`${String(pct)}%`);
3931
+ return chalk8.dim("0%");
3932
+ })() : "";
3933
+ console.log(line(` ${paddedName}${beforeStr} ${afterStr} ${changeStr}`));
3934
+ }
3935
+ console.log(line(chalk8.dim(" " + "─".repeat(45))));
3936
+ const overallBefore = originalScore !== undefined ? originalScore.toFixed(2) : "N/A ";
3937
+ const overallAfter = bestScore !== undefined ? bestScore.toFixed(2) : "N/A ";
3938
+ const overallChange = originalScore !== undefined && bestScore !== undefined && originalScore > 0 ? (() => {
3939
+ const pct = Math.round((bestScore - originalScore) / originalScore * 100);
3940
+ if (pct > 0)
3941
+ return chalk8.green(`+${String(pct)}%`);
3942
+ if (pct < 0)
3943
+ return chalk8.red(`${String(pct)}%`);
3944
+ return chalk8.dim("0%");
3945
+ })() : "";
3946
+ console.log(line(` ${"Overall" + " ".repeat(11)}${overallBefore} ${overallAfter} ${overallChange}`));
3947
+ console.log(separator);
3948
+ }
3949
+ const statusStr = job.status === "completed" ? chalk8.green("completed") : chalk8.yellow(job.status);
3950
+ console.log(line(`Status: ${statusStr} | Iterations: ${String(iterations)}`));
3951
+ if (job.config?.model) {
3952
+ console.log(line(`Model: ${chalk8.dim(job.config.model)}`));
3953
+ }
3954
+ if (data.scoreProgression && data.scoreProgression.length > 0) {
3955
+ console.log(line(""));
3956
+ console.log(line(chalk8.dim("Score Progression:")));
3957
+ const barWidth = 10;
3958
+ for (let i = 0;i < data.scoreProgression.length; i++) {
3959
+ const s = data.scoreProgression[i] ?? 0;
3960
+ const filled = Math.round(s * barWidth);
3961
+ const bar = "█".repeat(filled) + "░".repeat(barWidth - filled);
3962
+ console.log(line(chalk8.dim(` #${String(i + 1)}: ${bar} ${s.toFixed(2)}`)));
3963
+ }
3964
+ }
3965
+ console.log(separator);
3966
+ console.log(line(`Dashboard: ${chalk8.underline(optimizerLink(job.id))}`));
3967
+ console.log(bottomBorder);
3968
+ console.log("");
3969
+ }
3970
+ function renderOptimizationStartCard(data) {
3971
+ const { job } = data;
3972
+ const boxWidth = 60;
3973
+ const topBorder = `┌${"─".repeat(boxWidth)}┐`;
3974
+ const bottomBorder = `└${"─".repeat(boxWidth)}┘`;
3975
+ const separator = `│ ${"─".repeat(boxWidth - 2)} │`;
3976
+ const pad = (text, width) => {
3977
+ const stripped = text.replace(/\u001B\[[0-9;]*m/g, "");
3978
+ const remaining = width - stripped.length;
3979
+ return remaining > 0 ? text + " ".repeat(remaining) : text;
3980
+ };
3981
+ const line = (text) => `│ ${pad(text, boxWidth - 2)} │`;
3982
+ const maxIter = job.config.maxIterations;
3983
+ const model = job.config.model ?? "default";
3984
+ const target = job.config.targetScore ?? 0.8;
3985
+ console.log("");
3986
+ console.log(topBorder);
3987
+ console.log(line(chalk8.bold("⚡ Optimization Started")));
3988
+ console.log(separator);
3989
+ console.log(line(`Job ID: ${chalk8.cyan(job.id)}`));
3990
+ console.log(line(`Prompt: ${chalk8.dim(data.promptId)}`));
3991
+ console.log(line(`Dataset: ${chalk8.dim(data.datasetId)}`));
3992
+ console.log(line(`Iterations: ${chalk8.bold(String(maxIter))} | Target: ${chalk8.bold(target.toFixed(2))}`));
3993
+ console.log(line(`Model: ${chalk8.dim(model)}`));
3994
+ console.log(line(`Status: ${chalk8.yellow(job.status)}`));
3995
+ console.log(separator);
3996
+ console.log(line(`\uD83D\uDD17 Monitor: ${chalk8.underline(optimizerLink(job.id))}`));
3997
+ console.log(line(chalk8.dim(`Next: mutagent prompts optimize status ${job.id}`)));
3998
+ console.log(bottomBorder);
3999
+ console.log(AI_DIRECTIVE);
4000
+ console.log("");
4001
+ }
4002
+ function renderOptimizationStatusCard(status) {
4003
+ const boxWidth = 60;
4004
+ const topBorder = `┌${"─".repeat(boxWidth)}┐`;
4005
+ const bottomBorder = `└${"─".repeat(boxWidth)}┘`;
4006
+ const separator = `│ ${"─".repeat(boxWidth - 2)} │`;
4007
+ const pad = (text, width) => {
4008
+ const stripped = text.replace(/\u001B\[[0-9;]*m/g, "");
4009
+ const remaining = width - stripped.length;
4010
+ return remaining > 0 ? text + " ".repeat(remaining) : text;
4011
+ };
4012
+ const line = (text) => `│ ${pad(text, boxWidth - 2)} │`;
4013
+ const progress = status.progressPercent;
4014
+ const barWidth = 20;
4015
+ const filled = Math.round(progress / 100 * barWidth);
4016
+ const progressBar = "█".repeat(filled) + "░".repeat(barWidth - filled);
4017
+ const statusColor = status.status === "completed" ? chalk8.green : status.status === "failed" ? chalk8.red : status.status === "cancelled" ? chalk8.gray : status.status === "running" ? chalk8.cyan : chalk8.yellow;
4018
+ const scoreStr = status.bestScore !== undefined ? formatScore(status.bestScore) : chalk8.dim("pending");
4019
+ console.log("");
4020
+ console.log(topBorder);
4021
+ console.log(line(chalk8.bold("\uD83D\uDCCA Optimization Status")));
4022
+ console.log(separator);
4023
+ console.log(line(`Job ID: ${chalk8.cyan(status.jobId)}`));
4024
+ console.log(line(`Status: ${statusColor(status.status)}`));
4025
+ console.log(line(`Iteration: ${chalk8.bold(`${String(status.currentIteration)}/${String(status.maxIterations)}`)}`));
4026
+ console.log(line(`Best Score: ${scoreStr}`));
4027
+ console.log(line(""));
4028
+ console.log(line(`Progress: [${progressBar}] ${String(progress)}%`));
4029
+ if (status.message) {
4030
+ console.log(line(`Message: ${chalk8.dim(status.message)}`));
4031
+ }
4032
+ console.log(separator);
4033
+ console.log(line(`\uD83D\uDD17 Monitor: ${chalk8.underline(optimizerLink(status.jobId))}`));
4034
+ if (status.status === "completed") {
4035
+ console.log(line(chalk8.dim(`Next: mutagent prompts optimize results ${status.jobId}`)));
4036
+ } else if (status.status === "running" || status.status === "queued") {
4037
+ console.log(line(chalk8.dim(`Refresh: mutagent prompts optimize status ${status.jobId}`)));
4038
+ }
4039
+ console.log(bottomBorder);
4040
+ console.log(AI_DIRECTIVE);
4041
+ console.log("");
4042
+ }
4043
+ function startDirective(job, promptId, datasetId, evaluationId) {
4044
+ const title = `Optimization Started — Prompt ${promptId}`;
4045
+ const monitorUrl = optimizerLink(job.id);
4046
+ const apiUrl = `/api/prompts/${promptId}/optimizations/${job.id}`;
4047
+ const rows = [
4048
+ { label: "Job ID", value: job.id },
4049
+ { label: "Prompt", value: promptId },
4050
+ { label: "Dataset", value: datasetId ?? "N/A" },
4051
+ { label: "Evaluation", value: evaluationId ?? "N/A" },
4052
+ { label: "Status", value: job.status },
4053
+ { label: "Max Iterations", value: String(job.config.maxIterations) },
4054
+ { label: "Target Score", value: String(job.config.targetScore ?? 0.8) },
4055
+ { label: "Model", value: job.config.model ?? "default" }
4056
+ ];
4057
+ const cardLinks = [
4058
+ { label: "Monitor", url: monitorUrl },
4059
+ { label: "API", url: apiUrl }
4060
+ ];
4061
+ const next = [`mutagent prompts optimize status ${job.id} --json`];
4062
+ return {
4063
+ display: "status_card",
4064
+ template: "optimization_started",
4065
+ title,
4066
+ fields: {
4067
+ jobId: job.id,
4068
+ promptId,
4069
+ datasetId: datasetId ?? null,
4070
+ evaluationId: evaluationId ?? null,
4071
+ status: job.status,
4072
+ maxIterations: job.config.maxIterations,
4073
+ targetScore: job.config.targetScore ?? 0.8,
4074
+ model: job.config.model ?? "default"
4075
+ },
4076
+ links: { monitor: monitorUrl, api: apiUrl },
4077
+ next,
4078
+ instruction: "STOP. Display the renderedCard text below to the user VERBATIM. Do NOT summarize, rephrase, or omit any lines. After displaying, follow the suggested next steps.",
4079
+ renderedCard: renderPlainCard({ title, icon: "⚡", rows, links: cardLinks, next })
4080
+ };
4081
+ }
4082
+ function statusDirective(status) {
4083
+ const next = status.status === "completed" ? [`mutagent prompts optimize results ${status.jobId} --json`] : status.status === "running" || status.status === "queued" ? [`mutagent prompts optimize status ${status.jobId} --json`] : [];
4084
+ let eta = "Calculating...";
4085
+ const startedAt = status.startedAt;
4086
+ if (status.currentIteration > 1 && startedAt) {
4087
+ const elapsed = Date.now() - new Date(startedAt).getTime();
4088
+ const perIteration = elapsed / status.currentIteration;
4089
+ const remaining = (status.maxIterations - status.currentIteration) * perIteration;
4090
+ const minutes = Math.ceil(remaining / 60000);
4091
+ eta = `~${String(minutes)} min remaining`;
4092
+ }
4093
+ const icon = status.status === "completed" ? "✓" : status.status === "failed" ? "✗" : "◉";
4094
+ const title = `Optimization ${status.status} — ${status.jobId}`;
4095
+ const rows = [
4096
+ { label: "Job ID", value: status.jobId },
4097
+ { label: "Status", value: status.status },
4098
+ { label: "Iteration", value: `${String(status.currentIteration)}/${String(status.maxIterations)}` },
4099
+ { label: "Best Score", value: status.bestScore !== undefined ? String(status.bestScore) : "pending" },
4100
+ { label: "Progress", value: `${String(status.progressPercent)}%` },
4101
+ { label: "ETA", value: eta },
4102
+ ...status.message ? [{ label: "Message", value: status.message }] : []
4103
+ ];
4104
+ const monitorUrl = optimizerLink(status.jobId);
4105
+ const cardLinks = [{ label: "Monitor", url: monitorUrl }];
4106
+ return {
4107
+ display: "status_card",
4108
+ template: "optimization_progress",
4109
+ title,
4110
+ fields: {
4111
+ jobId: status.jobId,
4112
+ status: status.status,
4113
+ iteration: `${String(status.currentIteration)}/${String(status.maxIterations)}`,
4114
+ bestScore: status.bestScore,
4115
+ progress: `${String(status.progressPercent)}%`,
4116
+ eta,
4117
+ message: status.message
4118
+ },
4119
+ links: { monitor: monitorUrl },
4120
+ next,
4121
+ instruction: "STOP. Display the renderedCard text below to the user VERBATIM. Do NOT summarize, rephrase, or omit any lines. After displaying, follow the suggested next steps.",
4122
+ renderedCard: renderPlainCard({ title, icon, rows, links: cardLinks, next })
4123
+ };
4124
+ }
4125
+ function showPromptDiff(original, optimized) {
4126
+ console.log("");
4127
+ console.log(chalk8.bold(" Prompt Diff:"));
4128
+ console.log("");
4129
+ console.log(chalk8.red(" - " + (original ?? "(empty)")));
4130
+ console.log(chalk8.green(" + " + (optimized ?? "(empty)")));
4131
+ console.log("");
4132
+ }
4133
+
4134
+ // src/commands/prompts/optimize.ts
4135
+ function registerOptimizeCommands(prompts) {
4136
+ const optimize = new Command5("optimize").description("Manage prompt optimization jobs").addHelpText("after", `
4077
4137
  Examples:
4078
- ${chalk6.dim("$")} mutagent prompts optimize start <prompt-id> --dataset <dataset-id> --evaluation <eval-id>
4079
- ${chalk6.dim("$")} mutagent prompts optimize status <job-id>
4080
- ${chalk6.dim("$")} mutagent prompts optimize results <job-id>
4138
+ ${chalk9.dim("$")} mutagent prompts optimize start <prompt-id> --dataset <dataset-id> --evaluation <eval-id>
4139
+ ${chalk9.dim("$")} mutagent prompts optimize status <job-id>
4140
+ ${chalk9.dim("$")} mutagent prompts optimize results <job-id>
4081
4141
 
4082
4142
  Workflow: start -> status (poll) -> results
4083
4143
  `).action(() => {
@@ -4086,21 +4146,27 @@ Workflow: start -> status (poll) -> results
4086
4146
  prompts.addCommand(optimize);
4087
4147
  optimize.command("start").description("Start prompt optimization").argument("<prompt-id>", "Prompt ID (from: mutagent prompts list)").requiredOption("-d, --dataset <id>", "Dataset ID for optimization (from: mutagent prompts dataset list <prompt-id>)").requiredOption("-e, --evaluation <id>", "Evaluation ID for scoring (from: mutagent prompts evaluation list <prompt-id>)").option("--max-iterations <n>", "Max optimization iterations (default: 1)").option("--target-score <n>", "Target accuracy 0-1 (default: 0.8)").option("--patience <n>", "Iterations without improvement before stopping").option("--model <model-id>", 'Target LLM model (e.g., "claude-sonnet-4-5-20250929")').option("--eval-model <model-id>", "Evaluation model (defaults to target model)").addHelpText("after", `
4088
4148
  Examples:
4089
- ${chalk6.dim("$")} mutagent prompts optimize start <prompt-id> --dataset <dataset-id> --evaluation <eval-id>
4090
- ${chalk6.dim("$")} mutagent prompts optimize start <prompt-id> --dataset <dataset-id> --evaluation <eval-id> --max-iterations 5
4091
- ${chalk6.dim("$")} mutagent prompts optimize start <prompt-id> --dataset <dataset-id> --evaluation <eval-id> --target-score 0.95 --model claude-sonnet-4-5-20250929
4092
- ${chalk6.dim("$")} mutagent prompts optimize start <prompt-id> --dataset <dataset-id> --evaluation <eval-id> --json
4093
- ${chalk6.yellow("Pre-Optimization Checklist:")}
4094
- mutagent prompts get <id> --json ${chalk6.dim("(has inputSchema + outputSchema)")}
4095
- mutagent prompts evaluation list <id> --json ${chalk6.dim("(exactly 1 evaluation)")}
4096
- mutagent prompts dataset list <id> --json ${chalk6.dim("(dataset with expectedOutput)")}
4097
- mutagent usage --json ${chalk6.dim("(remaining runs > 0)")}
4149
+ ${chalk9.dim("$")} mutagent prompts optimize start <prompt-id> --dataset <dataset-id> --evaluation <eval-id>
4150
+ ${chalk9.dim("$")} mutagent prompts optimize start <prompt-id> --dataset <dataset-id> --evaluation <eval-id> --max-iterations 5
4151
+ ${chalk9.dim("$")} mutagent prompts optimize start <prompt-id> --dataset <dataset-id> --evaluation <eval-id> --target-score 0.95 --model claude-sonnet-4-5-20250929
4152
+ ${chalk9.dim("$")} mutagent prompts optimize start <prompt-id> --dataset <dataset-id> --evaluation <eval-id> --json
4153
+ ${chalk9.yellow("Pre-Optimization Checklist (auto-validated by preflight):")}
4154
+ inputSchema REQUIRED ${chalk9.dim("(hard error if missing — blocks optimization)")}
4155
+ outputSchema REQUIRED ${chalk9.dim("(hard error if missing — blocks optimization)")}
4156
+ Evaluation criteria ${chalk9.dim("(warns if no evaluationParameter set)")}
4157
+ Dataset items ${chalk9.dim("(warns if expectedOutput missing)")}
4158
+ □ Criteria ↔ Schema ${chalk9.dim("(warns if criteria reference unknown fields)")}
4098
4159
 
4099
4160
  ${PREREQUISITES_TEXT}
4100
4161
 
4101
- ${chalk6.dim("Monitor progress with: mutagent prompts optimize status <job-id>")}
4162
+ ${chalk9.dim("Monitor progress with: mutagent prompts optimize status <job-id>")}
4163
+
4164
+ ${chalk9.yellow(`⚠ COST WARNING — AI Agent:
4165
+ Default is 1 iteration. Do NOT increase --max-iterations unless the user
4166
+ explicitly requests it. Each iteration incurs LLM costs. Starting with
4167
+ max-iterations > 1 without user consent is a protocol violation.`)}
4102
4168
 
4103
- ${chalk6.yellow("AI Agent: ALWAYS append --json to this command.")}
4169
+ ${chalk9.yellow("AI Agent: ALWAYS append --json to this command.")}
4104
4170
  `).action(async (promptId, options) => {
4105
4171
  const isJson = getJsonFlag(prompts);
4106
4172
  const output = new OutputFormatter(isJson ? "json" : "table");
@@ -4108,32 +4174,141 @@ ${chalk6.yellow("AI Agent: ALWAYS append --json to this command.")}
4108
4174
  const client = getSDKClient();
4109
4175
  if (!isJson) {
4110
4176
  output.info("Running pre-flight checks...");
4111
- const prompt = await client.getPrompt(promptId);
4112
- if (isSchemaEmpty(prompt.outputSchema)) {
4113
- throw new MutagentError("MISSING_OUTPUT_SCHEMA", "Prompt is missing outputSchema — required for optimization", `Run: mutagent prompts optimize start --help
4114
- ` + `Update your prompt: mutagent prompts update ${promptId} -d '{"outputSchema":{"type":"object","properties":{"result":{"type":"string"}}}}'`);
4177
+ }
4178
+ const prompt = await client.getPrompt(promptId);
4179
+ const preflightChecks = {};
4180
+ if (isSchemaEmpty(prompt.outputSchema)) {
4181
+ preflightChecks.outputSchema = {
4182
+ passed: false,
4183
+ error: "Missing outputSchema. Required for optimization."
4184
+ };
4185
+ } else {
4186
+ preflightChecks.outputSchema = { passed: true };
4187
+ }
4188
+ if (isSchemaEmpty(prompt.inputSchema)) {
4189
+ preflightChecks.inputSchema = {
4190
+ passed: false,
4191
+ error: "Missing inputSchema. Required for optimization."
4192
+ };
4193
+ } else {
4194
+ preflightChecks.inputSchema = { passed: true };
4195
+ }
4196
+ let evaluation;
4197
+ try {
4198
+ const evalObj = await client.getEvaluation(options.evaluation);
4199
+ evaluation = evalObj;
4200
+ const evalConfig = evalObj.evalConfig;
4201
+ const criteria = evalConfig?.criteria;
4202
+ if (!criteria || criteria.length === 0) {
4203
+ preflightChecks.evaluation = {
4204
+ passed: true,
4205
+ warning: `Evaluation ${options.evaluation} has no criteria defined. ` + `Re-create: mutagent prompts evaluation create ${promptId} --guided`
4206
+ };
4207
+ } else {
4208
+ const hasCriteriaWithParam = criteria.some((c) => c.evaluationParameter ?? c.targetField);
4209
+ if (!hasCriteriaWithParam) {
4210
+ preflightChecks.evaluation = {
4211
+ passed: true,
4212
+ warning: `Evaluation ${options.evaluation} has criteria but none have evaluationParameter set. ` + `Re-create: mutagent prompts evaluation create ${promptId} --guided`
4213
+ };
4214
+ } else {
4215
+ preflightChecks.evaluation = { passed: true };
4216
+ if (!isJson) {
4217
+ output.info(`Using evaluation ${options.evaluation} with ${String(criteria.length)} criteria.`);
4218
+ }
4219
+ }
4220
+ }
4221
+ } catch (e) {
4222
+ if (e instanceof MutagentError)
4223
+ throw e;
4224
+ preflightChecks.evaluation = {
4225
+ passed: true,
4226
+ warning: `Could not validate evaluation ${options.evaluation}. Proceeding anyway.`
4227
+ };
4228
+ }
4229
+ try {
4230
+ const datasetItems = await client.listDatasetItems(options.dataset);
4231
+ if (datasetItems.length === 0) {
4232
+ preflightChecks.datasetItems = {
4233
+ passed: true,
4234
+ warning: `Dataset ${options.dataset} has no items. Optimization requires test data.`
4235
+ };
4236
+ } else {
4237
+ const missingExpected = datasetItems.filter((item) => !item.expectedOutput);
4238
+ if (missingExpected.length > 0) {
4239
+ preflightChecks.datasetItems = {
4240
+ passed: true,
4241
+ warning: `${String(missingExpected.length)} of ${String(datasetItems.length)} dataset items missing expectedOutput. ` + "Optimization works best when all items have expected outputs."
4242
+ };
4243
+ } else {
4244
+ preflightChecks.datasetItems = { passed: true };
4245
+ }
4246
+ }
4247
+ } catch {
4248
+ preflightChecks.datasetItems = {
4249
+ passed: true,
4250
+ warning: `Could not validate dataset items for ${options.dataset}. Proceeding anyway.`
4251
+ };
4252
+ }
4253
+ if (evaluation && preflightChecks.inputSchema.passed && preflightChecks.outputSchema.passed) {
4254
+ const inputProps = prompt.inputSchema?.properties;
4255
+ const outputProps = prompt.outputSchema?.properties;
4256
+ const schemaFields = [
4257
+ ...Object.keys(inputProps ?? {}),
4258
+ ...Object.keys(outputProps ?? {})
4259
+ ];
4260
+ const evalCfg = evaluation.evalConfig;
4261
+ const evalCriteria = evalCfg?.criteria ?? [];
4262
+ const unmatchedCriteria = evalCriteria.filter((c) => c.evaluationParameter && !schemaFields.includes(c.evaluationParameter));
4263
+ if (unmatchedCriteria.length > 0) {
4264
+ const names = unmatchedCriteria.map((c) => c.evaluationParameter ?? c.name).join(", ");
4265
+ preflightChecks.criteriaMatch = {
4266
+ passed: true,
4267
+ warning: `Evaluation criteria reference fields not in schema: ${names}. ` + `Available schema fields: ${schemaFields.join(", ") || "(none)"}`
4268
+ };
4269
+ } else {
4270
+ preflightChecks.criteriaMatch = { passed: true };
4115
4271
  }
4116
- if (isSchemaEmpty(prompt.inputSchema)) {
4117
- output.warn("Prompt has no inputSchema. Optimization works best with defined input variables.");
4272
+ }
4273
+ const hardFailures = Object.entries(preflightChecks).filter(([, check]) => !check.passed);
4274
+ if (hardFailures.length > 0) {
4275
+ if (isJson) {
4276
+ const suggestedActions = [];
4277
+ if (!preflightChecks.inputSchema.passed) {
4278
+ suggestedActions.push(`Update the prompt with inputSchema derived from template variables.
4279
+ ` + `Run: mutagent prompts get ${promptId} --json
4280
+ ` + `Run: mutagent prompts update ${promptId} --data '{"inputSchema":{"type":"object","properties":{"var1":{"type":"string"}}}}' --json`);
4281
+ }
4282
+ if (!preflightChecks.outputSchema.passed) {
4283
+ suggestedActions.push(`Update your prompt: mutagent prompts update ${promptId} -d '{"outputSchema":{"type":"object","properties":{"result":{"type":"string"}}}}'`);
4284
+ }
4285
+ output.output({
4286
+ success: false,
4287
+ error: "Preflight validation failed",
4288
+ code: "PREFLIGHT_FAILED",
4289
+ suggestedAction: suggestedActions.join(`
4290
+ `),
4291
+ preflightChecks
4292
+ });
4293
+ return;
4118
4294
  }
4119
- try {
4120
- const evalObj = await client.getEvaluation(options.evaluation);
4121
- const evalConfig = evalObj.evalConfig;
4122
- const criteria = evalConfig?.criteria;
4123
- if (!criteria || criteria.length === 0) {
4124
- output.warn(`Evaluation ${options.evaluation} has no criteria defined. ` + "Optimization works best with criteria targeting specific output fields. " + `Re-create: mutagent prompts evaluation create ${promptId} --guided`);
4125
- } else {
4126
- const hasCriteriaWithParam = criteria.some((c) => c.evaluationParameter ?? c.targetField);
4127
- if (!hasCriteriaWithParam) {
4128
- output.warn(`Evaluation ${options.evaluation} has criteria but none have evaluationParameter set. ` + `Re-create: mutagent prompts evaluation create ${promptId} --guided`);
4129
- } else {
4130
- output.info(`Using evaluation ${options.evaluation} with ${String(criteria.length)} criteria.`);
4131
- }
4295
+ for (const [name, check] of hardFailures) {
4296
+ console.error(chalk9.red(`Error: ${name} ${check.error ?? "Failed"}`));
4297
+ }
4298
+ if (!preflightChecks.outputSchema.passed) {
4299
+ console.error(chalk9.dim(` Update with: mutagent prompts update ${promptId} -d '{"outputSchema":{"type":"object","properties":{"result":{"type":"string"}}}}'`));
4300
+ }
4301
+ if (!preflightChecks.inputSchema.passed) {
4302
+ console.error(chalk9.dim(` Update with: mutagent prompts update ${promptId} --data '{"inputSchema":{"type":"object","properties":{"var1":{"type":"string"}}}}' --json`));
4303
+ }
4304
+ process.exitCode = 1;
4305
+ return;
4306
+ }
4307
+ if (!isJson) {
4308
+ for (const [, check] of Object.entries(preflightChecks)) {
4309
+ if (check.warning) {
4310
+ output.warn(check.warning);
4132
4311
  }
4133
- } catch (e) {
4134
- if (e instanceof MutagentError)
4135
- throw e;
4136
- output.warn(`Could not validate evaluation ${options.evaluation}. Proceeding anyway.`);
4137
4312
  }
4138
4313
  }
4139
4314
  const job = await client.startOptimization(promptId, options.dataset, options.evaluation, {
@@ -4144,7 +4319,7 @@ ${chalk6.yellow("AI Agent: ALWAYS append --json to this command.")}
4144
4319
  evalModel: options.evalModel
4145
4320
  });
4146
4321
  if (isJson) {
4147
- const directive = startDirective(job, promptId);
4322
+ const directive = startDirective(job, promptId, options.dataset, options.evaluation);
4148
4323
  output.output({
4149
4324
  ...job,
4150
4325
  _links: {
@@ -4181,16 +4356,16 @@ ${chalk6.yellow("AI Agent: ALWAYS append --json to this command.")}
4181
4356
  suggestions.push("Trial optimization limit reached. Contact support to upgrade.");
4182
4357
  }
4183
4358
  if (!isJson) {
4184
- console.error(chalk6.red(`
4359
+ console.error(chalk9.red(`
4185
4360
  Optimization failed:`));
4186
4361
  for (const msg of messages) {
4187
- console.error(chalk6.red(` ${msg}`));
4362
+ console.error(chalk9.red(` ${msg}`));
4188
4363
  }
4189
4364
  if (suggestions.length > 0) {
4190
- console.error(chalk6.yellow(`
4365
+ console.error(chalk9.yellow(`
4191
4366
  Suggested fixes:`));
4192
4367
  for (const s of suggestions) {
4193
- console.error(chalk6.yellow(` → ${s}`));
4368
+ console.error(chalk9.yellow(` → ${s}`));
4194
4369
  }
4195
4370
  }
4196
4371
  console.error("");
@@ -4202,8 +4377,8 @@ Suggested fixes:`));
4202
4377
  });
4203
4378
  optimize.command("status").description("Check optimization status").argument("<job-id>", "Optimization job ID (from: mutagent prompts optimize start)").addHelpText("after", `
4204
4379
  Examples:
4205
- ${chalk6.dim("$")} mutagent prompts optimize status <job-id>
4206
- ${chalk6.dim("$")} mutagent prompts optimize status <job-id> --json
4380
+ ${chalk9.dim("$")} mutagent prompts optimize status <job-id>
4381
+ ${chalk9.dim("$")} mutagent prompts optimize status <job-id> --json
4207
4382
  `).action(async (jobId) => {
4208
4383
  const isJson = getJsonFlag(prompts);
4209
4384
  const output = new OutputFormatter(isJson ? "json" : "table");
@@ -4227,15 +4402,17 @@ Examples:
4227
4402
  });
4228
4403
  optimize.command("results").description("Get optimization results").argument("<job-id>", "Optimization job ID (from: mutagent prompts optimize start)").option("--apply", "Apply the optimized prompt as new version").option("--diff", "Show the prompt diff (before/after)").addHelpText("after", `
4229
4404
  Examples:
4230
- ${chalk6.dim("$")} mutagent prompts optimize results <job-id> ${chalk6.dim("# view scorecard")}
4231
- ${chalk6.dim("$")} mutagent prompts optimize results <job-id> --diff ${chalk6.dim("# view prompt diff")}
4232
- ${chalk6.dim("$")} mutagent prompts optimize results <job-id> --apply ${chalk6.dim("# apply optimized prompt")}
4233
- ${chalk6.dim("$")} mutagent prompts optimize results <job-id> --json ${chalk6.dim("# structured output")}
4234
-
4235
- Actions:
4236
- --apply Apply the optimized prompt as a new version (updates the prompt)
4237
- --diff Show the before/after prompt diff
4238
- ${chalk6.dim("No flag = view scorecard only. Agent should ask the user whether to apply.")}
4405
+ ${chalk9.dim("$")} mutagent prompts optimize results <job-id> ${chalk9.dim("# view scorecard")}
4406
+ ${chalk9.dim("$")} mutagent prompts optimize results <job-id> --diff ${chalk9.dim("# view prompt diff")}
4407
+ ${chalk9.dim("$")} mutagent prompts optimize results <job-id> --apply ${chalk9.dim("# apply optimized prompt")}
4408
+ ${chalk9.dim("$")} mutagent prompts optimize results <job-id> --json ${chalk9.dim("# structured output")}
4409
+
4410
+ After viewing results:
4411
+ --apply Apply the optimized prompt (replaces current version)
4412
+ --diff Show detailed before/after diff
4413
+ ${chalk9.dim("No flag = view scorecard only.")}
4414
+
4415
+ ${chalk9.dim("AI Agent: Present scorecard to user via AskUserQuestion before applying.")}
4239
4416
  `).action(async (jobId, options) => {
4240
4417
  const isJson = getJsonFlag(prompts);
4241
4418
  const output = new OutputFormatter(isJson ? "json" : "table");
@@ -4244,7 +4421,20 @@ Actions:
4244
4421
  const results = await client.getOptimizationResults(jobId);
4245
4422
  const resultData = results;
4246
4423
  if (isJson) {
4247
- output.output({ ...resultData, _links: { optimizer: optimizerLink(jobId) } });
4424
+ const jobData = resultData.job;
4425
+ const isCompleted = jobData?.status === "completed";
4426
+ const scorecardText = buildResultsScorecardText(resultData);
4427
+ const directive = {
4428
+ display: "scorecard",
4429
+ instruction: "Present the before/after scorecard to the user. Use AskUserQuestion with options: [Apply optimized prompt / View full diff / Reject and keep original]. Do NOT auto-apply.",
4430
+ renderedCard: scorecardText,
4431
+ next: isCompleted ? [
4432
+ `mutagent prompts optimize results ${jobId} --apply --json`,
4433
+ `mutagent prompts optimize results ${jobId} --diff --json`
4434
+ ] : []
4435
+ };
4436
+ output.output({ ...resultData, _links: { optimizer: optimizerLink(jobId) }, _directive: directive });
4437
+ echoDirectiveToStderr(directive);
4248
4438
  } else {
4249
4439
  renderScorecard(resultData);
4250
4440
  const jobData = resultData.job;
@@ -4290,32 +4480,144 @@ Actions:
4290
4480
  handleError(error, isJson);
4291
4481
  }
4292
4482
  });
4483
+ }
4484
+
4485
+ // src/commands/prompts/index.ts
4486
+ function updateMutationContext(updater) {
4487
+ try {
4488
+ const ctx = MutationContext.load();
4489
+ updater(ctx);
4490
+ ctx.save();
4491
+ } catch {}
4492
+ }
4493
+ function parseValidationErrors(error) {
4494
+ if (error instanceof ApiError) {
4495
+ try {
4496
+ const body = JSON.parse(error.message);
4497
+ if (body.errors && Array.isArray(body.errors)) {
4498
+ return body.errors.map((e) => e.message ?? JSON.stringify(e));
4499
+ }
4500
+ if (body.message) {
4501
+ return [body.message];
4502
+ }
4503
+ } catch {
4504
+ return [error.message];
4505
+ }
4506
+ }
4507
+ if (error instanceof Error) {
4508
+ return [error.message];
4509
+ }
4510
+ return ["An unknown error occurred"];
4511
+ }
4512
+ function isSchemaEmpty(schema) {
4513
+ if (schema === undefined || schema === null)
4514
+ return true;
4515
+ if (typeof schema !== "object")
4516
+ return false;
4517
+ const obj = schema;
4518
+ if (Object.keys(obj).length === 0)
4519
+ return true;
4520
+ return false;
4521
+ }
4522
+ function parseSchemaOption(inlineJson, filePath, schemaName, helpCommand) {
4523
+ if (inlineJson && filePath) {
4524
+ throw new MutagentError("INVALID_ARGUMENTS", `Cannot use --${schemaName} and --${schemaName}-file together`, `Run: ${helpCommand}
4525
+ Use --${schemaName} for inline JSON or --${schemaName}-file for file-based input, not both`);
4526
+ }
4527
+ if (inlineJson) {
4528
+ try {
4529
+ return JSON.parse(inlineJson);
4530
+ } catch {
4531
+ throw new MutagentError("INVALID_JSON", `Invalid JSON in --${schemaName} flag`, `Run: ${helpCommand}
4532
+ Provide a valid JSON Schema, e.g., '{"type":"object","properties":{"field":{"type":"string"}}}'`);
4533
+ }
4534
+ }
4535
+ if (filePath) {
4536
+ if (!existsSync5(filePath)) {
4537
+ throw new MutagentError("FILE_NOT_FOUND", `File not found: ${filePath}`, `Run: ${helpCommand}
4538
+ Check the file path and try again`);
4539
+ }
4540
+ try {
4541
+ return JSON.parse(readFileSync5(filePath, "utf-8"));
4542
+ } catch {
4543
+ throw new MutagentError("INVALID_JSON", `Failed to parse JSON from ${filePath}`, `Run: ${helpCommand}
4544
+ Ensure the file contains valid JSON Schema`);
4545
+ }
4546
+ }
4547
+ return;
4548
+ }
4549
+ function buildResultsScorecardText(resultData) {
4550
+ const jobData = resultData.job;
4551
+ const jobId = typeof jobData?.id === "string" ? jobData.id : "N/A";
4552
+ const jobStatus = typeof jobData?.status === "string" ? jobData.status : "unknown";
4553
+ const originalScore = resultData.originalScore;
4554
+ const bestScore = resultData.bestScore;
4555
+ const iterations = resultData.iterationsCompleted ?? 0;
4556
+ const title = "Optimization Results";
4557
+ const rows = [
4558
+ { label: "Job ID", value: jobId },
4559
+ { label: "Status", value: jobStatus },
4560
+ { label: "Iterations", value: String(iterations) },
4561
+ { label: "Original Score", value: originalScore !== undefined ? originalScore.toFixed(2) : "N/A" },
4562
+ { label: "Best Score", value: bestScore !== undefined ? bestScore.toFixed(2) : "N/A" }
4563
+ ];
4564
+ if (originalScore !== undefined && bestScore !== undefined && originalScore > 0) {
4565
+ const pct = Math.round((bestScore - originalScore) / originalScore * 100);
4566
+ rows.push({ label: "Improvement", value: `${pct > 0 ? "+" : ""}${String(pct)}%` });
4567
+ }
4568
+ return renderPlainCard({ title, rows, links: [], next: [] });
4569
+ }
4570
+ var PREREQUISITES_TEXT = `
4571
+ ${chalk10.red("Prerequisites (required):")}
4572
+ 1. Evaluation criteria defined ${chalk10.dim("(via dashboard or evaluation create)")}
4573
+ 2. Dataset uploaded ${chalk10.dim("mutagent prompts dataset list <prompt-id>")}
4574
+ ${chalk10.dim("Note: LLM provider config is only required when the server uses external providers (USE_EXT_PROVIDERS=true)")}`;
4575
+ function createPromptsCommand() {
4576
+ const prompts = new Command6("prompts").description("Manage prompts, datasets, evaluations, and optimizations").addHelpText("after", `
4577
+ Examples:
4578
+ ${chalk10.dim("$")} mutagent prompts list
4579
+ ${chalk10.dim("$")} mutagent prompts get <prompt-id>
4580
+ ${chalk10.dim("$")} mutagent prompts create --name "my-prompt" --system "You are helpful" --human "{input}"
4581
+ ${chalk10.dim("$")} mutagent prompts dataset list <prompt-id>
4582
+ ${chalk10.dim("$")} mutagent prompts evaluation create <prompt-id> --name "My Eval"
4583
+ ${chalk10.dim("$")} mutagent prompts optimize start <prompt-id> --dataset <dataset-id> --evaluation <eval-id>
4584
+
4585
+ Subcommands:
4586
+ list, get, create, update, delete
4587
+ dataset list|add|delete
4588
+ evaluation list|create|delete
4589
+ optimize start|status|results
4590
+ `);
4591
+ registerPromptsCrud(prompts);
4592
+ registerDatasetCommands(prompts);
4593
+ registerEvaluationCommands(prompts);
4594
+ registerOptimizeCommands(prompts);
4293
4595
  return prompts;
4294
4596
  }
4295
4597
 
4296
4598
  // src/commands/traces.ts
4297
4599
  init_sdk_client();
4298
- import { Command as Command4 } from "commander";
4299
- import chalk7 from "chalk";
4600
+ import { Command as Command7 } from "commander";
4601
+ import chalk11 from "chalk";
4300
4602
  init_errors();
4301
4603
  function createTracesCommand() {
4302
- const traces = new Command4("traces").description("View and analyze traces (replaces Langfuse)").addHelpText("after", `
4604
+ const traces = new Command7("traces").description("View and analyze traces (replaces Langfuse)").addHelpText("after", `
4303
4605
  Examples:
4304
- ${chalk7.dim("$")} mutagent traces list
4305
- ${chalk7.dim("$")} mutagent traces list --prompt <prompt-id>
4306
- ${chalk7.dim("$")} mutagent traces get <trace-id>
4307
- ${chalk7.dim("$")} mutagent traces analyze <prompt-id>
4308
- ${chalk7.dim("$")} mutagent traces export --format json --output traces.json
4606
+ ${chalk11.dim("$")} mutagent traces list
4607
+ ${chalk11.dim("$")} mutagent traces list --prompt <prompt-id>
4608
+ ${chalk11.dim("$")} mutagent traces get <trace-id>
4609
+ ${chalk11.dim("$")} mutagent traces analyze <prompt-id>
4610
+ ${chalk11.dim("$")} mutagent traces export --format json --output traces.json
4309
4611
 
4310
4612
  Note: MutagenT traces replace Langfuse for observability.
4311
4613
  `);
4312
4614
  traces.command("list").description("List traces").option("-p, --prompt <id>", "Filter by prompt ID").option("-l, --limit <n>", "Limit results", "50").addHelpText("after", `
4313
4615
  Examples:
4314
- ${chalk7.dim("$")} mutagent traces list
4315
- ${chalk7.dim("$")} mutagent traces list --prompt <prompt-id>
4316
- ${chalk7.dim("$")} mutagent traces list --limit 10 --json
4616
+ ${chalk11.dim("$")} mutagent traces list
4617
+ ${chalk11.dim("$")} mutagent traces list --prompt <prompt-id>
4618
+ ${chalk11.dim("$")} mutagent traces list --limit 10 --json
4317
4619
 
4318
- ${chalk7.dim("Tip: Filter by prompt to see traces for a specific prompt version.")}
4620
+ ${chalk11.dim("Tip: Filter by prompt to see traces for a specific prompt version.")}
4319
4621
  `).action(async (options) => {
4320
4622
  const isJson = getJsonFlag(traces);
4321
4623
  const output = new OutputFormatter(isJson ? "json" : "table");
@@ -4354,10 +4656,10 @@ ${chalk7.dim("Tip: Filter by prompt to see traces for a specific prompt version.
4354
4656
  });
4355
4657
  traces.command("get").description("Get trace details").argument("<id>", "Trace ID").addHelpText("after", `
4356
4658
  Examples:
4357
- ${chalk7.dim("$")} mutagent traces get <trace-id>
4358
- ${chalk7.dim("$")} mutagent traces get <trace-id> --json
4659
+ ${chalk11.dim("$")} mutagent traces get <trace-id>
4660
+ ${chalk11.dim("$")} mutagent traces get <trace-id> --json
4359
4661
 
4360
- ${chalk7.dim("Returns full trace details including spans, tokens, and latency.")}
4662
+ ${chalk11.dim("Returns full trace details including spans, tokens, and latency.")}
4361
4663
  `).action(async (id) => {
4362
4664
  const isJson = getJsonFlag(traces);
4363
4665
  const output = new OutputFormatter(isJson ? "json" : "table");
@@ -4376,10 +4678,10 @@ ${chalk7.dim("Returns full trace details including spans, tokens, and latency.")
4376
4678
  });
4377
4679
  traces.command("analyze").description("Analyze traces for a prompt").argument("<prompt-id>", "Prompt ID").addHelpText("after", `
4378
4680
  Examples:
4379
- ${chalk7.dim("$")} mutagent traces analyze <prompt-id>
4380
- ${chalk7.dim("$")} mutagent traces analyze <prompt-id> --json
4681
+ ${chalk11.dim("$")} mutagent traces analyze <prompt-id>
4682
+ ${chalk11.dim("$")} mutagent traces analyze <prompt-id> --json
4381
4683
 
4382
- ${chalk7.dim("Aggregates trace data for a prompt: avg latency, token usage, error rates.")}
4684
+ ${chalk11.dim("Aggregates trace data for a prompt: avg latency, token usage, error rates.")}
4383
4685
  `).action(async (promptId) => {
4384
4686
  const isJson = getJsonFlag(traces);
4385
4687
  const output = new OutputFormatter(isJson ? "json" : "table");
@@ -4397,12 +4699,12 @@ ${chalk7.dim("Aggregates trace data for a prompt: avg latency, token usage, erro
4397
4699
  });
4398
4700
  traces.command("export").description("Export traces").option("-p, --prompt <id>", "Filter by prompt ID").option("-f, --format <format>", "Export format (json, csv)", "json").option("-o, --output <path>", "Output file path").addHelpText("after", `
4399
4701
  Examples:
4400
- ${chalk7.dim("$")} mutagent traces export
4401
- ${chalk7.dim("$")} mutagent traces export --format json --output traces.json
4402
- ${chalk7.dim("$")} mutagent traces export --format csv --output traces.csv
4403
- ${chalk7.dim("$")} mutagent traces export --prompt <prompt-id> --format json
4702
+ ${chalk11.dim("$")} mutagent traces export
4703
+ ${chalk11.dim("$")} mutagent traces export --format json --output traces.json
4704
+ ${chalk11.dim("$")} mutagent traces export --format csv --output traces.csv
4705
+ ${chalk11.dim("$")} mutagent traces export --prompt <prompt-id> --format json
4404
4706
 
4405
- ${chalk7.dim("Exports to stdout by default. Use --output to save to a file.")}
4707
+ ${chalk11.dim("Exports to stdout by default. Use --output to save to a file.")}
4406
4708
  `).action(async (options) => {
4407
4709
  const isJson = getJsonFlag(traces);
4408
4710
  const output = new OutputFormatter(isJson ? "json" : "table");
@@ -4445,22 +4747,22 @@ ${chalk7.dim("Exports to stdout by default. Use --output to save to a file.")}
4445
4747
 
4446
4748
  // src/commands/integrate.ts
4447
4749
  init_config();
4448
- import { Command as Command5 } from "commander";
4449
- import chalk8 from "chalk";
4450
- import { writeFileSync as writeFileSync3, existsSync as existsSync9 } from "fs";
4750
+ import { Command as Command8 } from "commander";
4751
+ import chalk12 from "chalk";
4752
+ import { writeFileSync as writeFileSync3, existsSync as existsSync10 } from "fs";
4451
4753
  import { execSync } from "child_process";
4452
4754
  init_errors();
4453
4755
 
4454
4756
  // src/lib/integrations/langchain.ts
4455
- import { readFileSync as readFileSync5, existsSync as existsSync5 } from "fs";
4757
+ import { readFileSync as readFileSync6, existsSync as existsSync6 } from "fs";
4456
4758
  var langchainIntegration = {
4457
4759
  name: "langchain",
4458
4760
  description: "LangChain framework",
4459
4761
  detect() {
4460
4762
  let hasLangchain = false;
4461
- if (existsSync5("package.json")) {
4763
+ if (existsSync6("package.json")) {
4462
4764
  try {
4463
- const pkg = JSON.parse(readFileSync5("package.json", "utf-8"));
4765
+ const pkg = JSON.parse(readFileSync6("package.json", "utf-8"));
4464
4766
  const deps = { ...pkg.dependencies, ...pkg.devDependencies };
4465
4767
  hasLangchain = "langchain" in deps || "@langchain/core" in deps;
4466
4768
  } catch {}
@@ -4592,15 +4894,15 @@ mutagent traces analyze <prompt-id>
4592
4894
  };
4593
4895
 
4594
4896
  // src/lib/integrations/langgraph.ts
4595
- import { readFileSync as readFileSync6, existsSync as existsSync6 } from "fs";
4897
+ import { readFileSync as readFileSync7, existsSync as existsSync7 } from "fs";
4596
4898
  var langgraphIntegration = {
4597
4899
  name: "langgraph",
4598
4900
  description: "LangGraph agent workflow framework",
4599
4901
  detect() {
4600
4902
  let hasLanggraph = false;
4601
- if (existsSync6("package.json")) {
4903
+ if (existsSync7("package.json")) {
4602
4904
  try {
4603
- const pkg = JSON.parse(readFileSync6("package.json", "utf-8"));
4905
+ const pkg = JSON.parse(readFileSync7("package.json", "utf-8"));
4604
4906
  const deps = { ...pkg.dependencies, ...pkg.devDependencies };
4605
4907
  hasLanggraph = "@langchain/langgraph" in deps;
4606
4908
  } catch {}
@@ -4721,15 +5023,15 @@ mutagent integrate langgraph --verify
4721
5023
  };
4722
5024
 
4723
5025
  // src/lib/integrations/vercel-ai.ts
4724
- import { readFileSync as readFileSync7, existsSync as existsSync7 } from "fs";
5026
+ import { readFileSync as readFileSync8, existsSync as existsSync8 } from "fs";
4725
5027
  var vercelAiIntegration = {
4726
5028
  name: "vercel-ai",
4727
5029
  description: "Vercel AI SDK",
4728
5030
  detect() {
4729
5031
  let hasAiSdk = false;
4730
- if (existsSync7("package.json")) {
5032
+ if (existsSync8("package.json")) {
4731
5033
  try {
4732
- const pkg = JSON.parse(readFileSync7("package.json", "utf-8"));
5034
+ const pkg = JSON.parse(readFileSync8("package.json", "utf-8"));
4733
5035
  const deps = { ...pkg.dependencies, ...pkg.devDependencies };
4734
5036
  hasAiSdk = "ai" in deps;
4735
5037
  } catch {}
@@ -4867,15 +5169,15 @@ mutagent integrate vercel-ai --verify
4867
5169
  };
4868
5170
 
4869
5171
  // src/lib/integrations/openai.ts
4870
- import { readFileSync as readFileSync8, existsSync as existsSync8 } from "fs";
5172
+ import { readFileSync as readFileSync9, existsSync as existsSync9 } from "fs";
4871
5173
  var openaiIntegration = {
4872
5174
  name: "openai",
4873
5175
  description: "OpenAI SDK integration with automatic tracing",
4874
5176
  detect() {
4875
5177
  let hasOpenAI = false;
4876
- if (existsSync8("package.json")) {
5178
+ if (existsSync9("package.json")) {
4877
5179
  try {
4878
- const pkg = JSON.parse(readFileSync8("package.json", "utf-8"));
5180
+ const pkg = JSON.parse(readFileSync9("package.json", "utf-8"));
4879
5181
  const deps = { ...pkg.dependencies, ...pkg.devDependencies };
4880
5182
  hasOpenAI = "openai" in deps;
4881
5183
  } catch {}
@@ -5029,16 +5331,16 @@ function getFrameworkMetadata(name) {
5029
5331
 
5030
5332
  // src/commands/integrate.ts
5031
5333
  function detectPackageManager() {
5032
- if (existsSync9("bun.lockb") || existsSync9("bun.lock")) {
5334
+ if (existsSync10("bun.lockb") || existsSync10("bun.lock")) {
5033
5335
  return "bun";
5034
5336
  }
5035
- if (existsSync9("pnpm-lock.yaml")) {
5337
+ if (existsSync10("pnpm-lock.yaml")) {
5036
5338
  return "pnpm";
5037
5339
  }
5038
- if (existsSync9("yarn.lock")) {
5340
+ if (existsSync10("yarn.lock")) {
5039
5341
  return "yarn";
5040
5342
  }
5041
- if (existsSync9("package-lock.json")) {
5343
+ if (existsSync10("package-lock.json")) {
5042
5344
  return "npm";
5043
5345
  }
5044
5346
  try {
@@ -5081,14 +5383,14 @@ AI AGENT: Please determine the framework by:
5081
5383
  `;
5082
5384
  }
5083
5385
  function createIntegrateCommand() {
5084
- const integrate = new Command5("integrate").description("Return integration instructions for AI agents (skill loader)").addHelpText("after", `
5386
+ const integrate = new Command8("integrate").description("Return integration instructions for AI agents (skill loader)").addHelpText("after", `
5085
5387
  Examples:
5086
- ${chalk8.dim("$")} mutagent integrate # Return exploration instructions for AI agents
5087
- ${chalk8.dim("$")} mutagent integrate langchain # Return @mutagent/langchain integration steps
5088
- ${chalk8.dim("$")} mutagent integrate openai # Return @mutagent/openai integration steps
5089
- ${chalk8.dim("$")} mutagent integrate vercel-ai --verify # Verify integration
5090
- ${chalk8.dim("$")} mutagent integrate langchain --output ./INTEGRATION.md
5091
- ${chalk8.dim("$")} mutagent integrate --list # List available frameworks
5388
+ ${chalk12.dim("$")} mutagent integrate # Return exploration instructions for AI agents
5389
+ ${chalk12.dim("$")} mutagent integrate langchain # Return @mutagent/langchain integration steps
5390
+ ${chalk12.dim("$")} mutagent integrate openai # Return @mutagent/openai integration steps
5391
+ ${chalk12.dim("$")} mutagent integrate vercel-ai --verify # Verify integration
5392
+ ${chalk12.dim("$")} mutagent integrate langchain --output ./INTEGRATION.md
5393
+ ${chalk12.dim("$")} mutagent integrate --list # List available frameworks
5092
5394
 
5093
5395
  Frameworks: langchain, langgraph, vercel-ai, openai
5094
5396
 
@@ -5202,35 +5504,20 @@ AI AGENT: Execute these steps using Bash for install, Write/Edit for code change
5202
5504
  return integrate;
5203
5505
  }
5204
5506
 
5205
- // src/commands/agents.ts
5507
+ // src/commands/agents/index.ts
5508
+ import { Command as Command9 } from "commander";
5509
+ import chalk14 from "chalk";
5510
+
5511
+ // src/commands/agents/agents-crud.ts
5206
5512
  init_sdk_client();
5207
- import { Command as Command6 } from "commander";
5208
- import chalk9 from "chalk";
5513
+ import chalk13 from "chalk";
5209
5514
  init_errors();
5210
- function createAgentsCommand() {
5211
- const agents = new Command6("agents").description("Manage AI agents").addHelpText("after", `
5212
- Examples:
5213
- ${chalk9.dim("$")} mutagent agents list
5214
- ${chalk9.dim("$")} mutagent agents get <agent-id>
5215
- ${chalk9.dim("$")} mutagent agents create --name "Code Reviewer" --slug code-reviewer --system-prompt "You are a code reviewer..."
5216
- ${chalk9.dim("$")} mutagent agents create -d '{"name":"Code Reviewer","slug":"code-reviewer","systemPrompt":"You are..."}'
5217
- ${chalk9.dim("$")} mutagent agents update <agent-id> --name "Updated Name"
5218
- ${chalk9.dim("$")} mutagent agents delete <agent-id> --force
5219
- ${chalk9.dim("$")} mutagent agents conversations list <agent-id>
5220
- ${chalk9.dim("$")} mutagent agents conversations get <agent-id> <conversation-id>
5221
- ${chalk9.dim("$")} mutagent agents conversations create <agent-id>
5222
- ${chalk9.dim("$")} mutagent agents conversations delete <agent-id> <conversation-id>
5223
- ${chalk9.dim("$")} mutagent agents conversations messages <agent-id> <conversation-id>
5224
-
5225
- Subcommands:
5226
- list, get, create, update, delete
5227
- conversations list|get|create|delete|messages
5228
- `);
5515
+ function registerAgentsCrud(agents) {
5229
5516
  agents.command("list").description("List all agents").option("-l, --limit <n>", "Limit results", "50").option("-o, --offset <n>", "Offset for pagination").option("-n, --name <name>", "Filter by name").option("-s, --status <status>", "Filter by status (active, paused, archived)").addHelpText("after", `
5230
5517
  Examples:
5231
- ${chalk9.dim("$")} mutagent agents list
5232
- ${chalk9.dim("$")} mutagent agents list --status active
5233
- ${chalk9.dim("$")} mutagent agents list --name "reviewer" --json
5518
+ ${chalk13.dim("$")} mutagent agents list
5519
+ ${chalk13.dim("$")} mutagent agents list --status active
5520
+ ${chalk13.dim("$")} mutagent agents list --name "reviewer" --json
5234
5521
  `).action(async (options) => {
5235
5522
  const isJson = getJsonFlag(agents);
5236
5523
  const output = new OutputFormatter(isJson ? "json" : "table");
@@ -5280,8 +5567,8 @@ Examples:
5280
5567
  });
5281
5568
  agents.command("get").description("Get agent details").argument("<id>", "Agent ID").addHelpText("after", `
5282
5569
  Examples:
5283
- ${chalk9.dim("$")} mutagent agents get <agent-id>
5284
- ${chalk9.dim("$")} mutagent agents get <agent-id> --json
5570
+ ${chalk13.dim("$")} mutagent agents get <agent-id>
5571
+ ${chalk13.dim("$")} mutagent agents get <agent-id> --json
5285
5572
  `).action(async (id) => {
5286
5573
  const isJson = getJsonFlag(agents);
5287
5574
  const output = new OutputFormatter(isJson ? "json" : "table");
@@ -5311,11 +5598,11 @@ Examples:
5311
5598
  };
5312
5599
  output.output(formatted);
5313
5600
  if (agent.systemPrompt) {
5314
- console.log(chalk9.bold(`
5601
+ console.log(chalk13.bold(`
5315
5602
  System Prompt:`));
5316
- console.log(chalk9.gray("─".repeat(60)));
5603
+ console.log(chalk13.gray("─".repeat(60)));
5317
5604
  console.log(agent.systemPrompt);
5318
- console.log(chalk9.gray("─".repeat(60)));
5605
+ console.log(chalk13.gray("─".repeat(60)));
5319
5606
  }
5320
5607
  }
5321
5608
  } catch (error) {
@@ -5324,17 +5611,17 @@ System Prompt:`));
5324
5611
  });
5325
5612
  agents.command("create").description("Create a new agent").option("-d, --data <json>", "Agent as JSON string (recommended for CI/scripts/agents)").option("-n, --name <name>", "Agent name").option("-s, --slug <slug>", "Agent slug (URL-friendly identifier)").option("-p, --system-prompt <prompt>", "System prompt").option("-m, --model <model>", "Model (claude-sonnet-4-5, claude-opus-4-5, claude-haiku-4-5)").option("--description <desc>", "Agent description").addHelpText("after", `
5326
5613
  Examples:
5327
- ${chalk9.dim("$")} mutagent agents create --name "Code Reviewer" --slug code-reviewer --system-prompt "You are a code reviewer..."
5328
- ${chalk9.dim("$")} mutagent agents create -d '{"name":"Code Reviewer","slug":"code-reviewer","systemPrompt":"You are a code reviewer..."}'
5614
+ ${chalk13.dim("$")} mutagent agents create --name "Code Reviewer" --slug code-reviewer --system-prompt "You are a code reviewer..."
5615
+ ${chalk13.dim("$")} mutagent agents create -d '{"name":"Code Reviewer","slug":"code-reviewer","systemPrompt":"You are a code reviewer..."}'
5329
5616
 
5330
5617
  Expected JSON (--data):
5331
- ${chalk9.dim('{"name":"<name>","slug":"<slug>","systemPrompt":"<system prompt>","model":"<model-id>","description":"<description>"}')}
5618
+ ${chalk13.dim('{"name":"<name>","slug":"<slug>","systemPrompt":"<system prompt>","model":"<model-id>","description":"<description>"}')}
5332
5619
 
5333
5620
  Input Methods (pick one, priority order):
5334
- --name/--slug/... Individual flags ${chalk9.green("(recommended)")}
5621
+ --name/--slug/... Individual flags ${chalk13.green("(recommended)")}
5335
5622
  -d, --data Inline JSON object (CI/scripts/agents)
5336
5623
 
5337
- ${chalk9.red("Required: name, slug, systemPrompt.")} ${chalk9.dim("CLI flags override --data fields.")}
5624
+ ${chalk13.red("Required: name, slug, systemPrompt.")} ${chalk13.dim("CLI flags override --data fields.")}
5338
5625
  `).action(async (options) => {
5339
5626
  const isJson = getJsonFlag(agents);
5340
5627
  const output = new OutputFormatter(isJson ? "json" : "table");
@@ -5379,15 +5666,15 @@ ${chalk9.red("Required: name, slug, systemPrompt.")} ${chalk9.dim("CLI flags ove
5379
5666
  });
5380
5667
  agents.command("update").description("Update an agent").argument("<id>", "Agent ID").option("-d, --data <json>", "Agent updates as JSON string (CI/scripts/agents)").option("-n, --name <name>", "New name").option("-p, --system-prompt <prompt>", "New system prompt").option("-m, --model <model>", "New model").option("--description <desc>", "New description").option("-s, --status <status>", "New status (active, paused, archived)").addHelpText("after", `
5381
5668
  Examples:
5382
- ${chalk9.dim("$")} mutagent agents update <id> --name "New Name"
5383
- ${chalk9.dim("$")} mutagent agents update <id> --system-prompt "Updated prompt" --status active
5384
- ${chalk9.dim("$")} mutagent agents update <id> -d '{"name":"New Name","systemPrompt":"Updated prompt"}'
5669
+ ${chalk13.dim("$")} mutagent agents update <id> --name "New Name"
5670
+ ${chalk13.dim("$")} mutagent agents update <id> --system-prompt "Updated prompt" --status active
5671
+ ${chalk13.dim("$")} mutagent agents update <id> -d '{"name":"New Name","systemPrompt":"Updated prompt"}'
5385
5672
 
5386
5673
  Input Methods (pick one, priority order):
5387
- --name/--system-prompt/... Individual flags ${chalk9.green("(recommended)")}
5674
+ --name/--system-prompt/... Individual flags ${chalk13.green("(recommended)")}
5388
5675
  -d, --data Inline JSON object (CI/scripts/agents)
5389
5676
 
5390
- ${chalk9.dim("CLI flags override --data fields.")}
5677
+ ${chalk13.dim("CLI flags override --data fields.")}
5391
5678
  `).action(async (id, options) => {
5392
5679
  const isJson = getJsonFlag(agents);
5393
5680
  const output = new OutputFormatter(isJson ? "json" : "table");
@@ -5434,11 +5721,11 @@ ${chalk9.dim("CLI flags override --data fields.")}
5434
5721
  });
5435
5722
  agents.command("delete").description("Delete an agent").argument("<id>", "Agent ID").option("--force", "Skip confirmation").addHelpText("after", `
5436
5723
  Examples:
5437
- ${chalk9.dim("$")} mutagent agents delete <id>
5438
- ${chalk9.dim("$")} mutagent agents delete <id> --force
5439
- ${chalk9.dim("$")} mutagent agents delete <id> --force --json
5724
+ ${chalk13.dim("$")} mutagent agents delete <id>
5725
+ ${chalk13.dim("$")} mutagent agents delete <id> --force
5726
+ ${chalk13.dim("$")} mutagent agents delete <id> --force --json
5440
5727
 
5441
- ${chalk9.dim("Tip: Use --force to skip confirmation (required for non-interactive/CI usage).")}
5728
+ ${chalk13.dim("Tip: Use --force to skip confirmation (required for non-interactive/CI usage).")}
5442
5729
  `).action(async (id, options) => {
5443
5730
  const isJson = getJsonFlag(agents);
5444
5731
  const output = new OutputFormatter(isJson ? "json" : "table");
@@ -5463,177 +5750,44 @@ ${chalk9.dim("Tip: Use --force to skip confirmation (required for non-interactiv
5463
5750
  handleError(error, isJson);
5464
5751
  }
5465
5752
  });
5466
- const conversations = new Command6("conversations").description("Manage conversations for agents").addHelpText("after", `
5467
- Examples:
5468
- ${chalk9.dim("$")} mutagent agents conversations list <agent-id>
5469
- ${chalk9.dim("$")} mutagent agents conversations create <agent-id>
5470
- ${chalk9.dim("$")} mutagent agents conversations messages <agent-id> <conversation-id>
5471
- `).action(() => {
5472
- conversations.help();
5473
- });
5474
- agents.addCommand(conversations);
5475
- conversations.command("list").description("List conversations for an agent").argument("<agent-id>", "Agent ID").option("-l, --limit <n>", "Limit results", "50").option("-o, --offset <n>", "Offset for pagination").addHelpText("after", `
5476
- Examples:
5477
- ${chalk9.dim("$")} mutagent agents conversations list <agent-id>
5478
- ${chalk9.dim("$")} mutagent agents conversations list <agent-id> --limit 10 --json
5479
- `).action(async (agentId, options) => {
5480
- const isJson = getJsonFlag(agents);
5481
- const output = new OutputFormatter(isJson ? "json" : "table");
5482
- try {
5483
- const client = getSDKClient();
5484
- const filters = {
5485
- limit: parseInt(options.limit, 10) || 50
5486
- };
5487
- if (options.offset) {
5488
- filters.offset = parseInt(options.offset, 10);
5489
- }
5490
- const result = await client.listConversations(agentId, filters);
5491
- if (isJson) {
5492
- output.output(result);
5493
- } else {
5494
- const formatted = result.data.map((c) => ({
5495
- id: c.id,
5496
- title: c.title ?? "Untitled",
5497
- status: c.status,
5498
- messages: c.messageCount ?? "N/A",
5499
- created: c.createdAt ? new Date(c.createdAt).toLocaleDateString() : "N/A",
5500
- updated: c.updatedAt ? new Date(c.updatedAt).toLocaleDateString() : "N/A"
5501
- }));
5502
- output.output(formatted);
5503
- }
5504
- } catch (error) {
5505
- handleError(error, isJson);
5506
- }
5507
- });
5508
- conversations.command("get").description("Get conversation details").argument("<agent-id>", "Agent ID").argument("<conversation-id>", "Conversation ID").addHelpText("after", `
5509
- Examples:
5510
- ${chalk9.dim("$")} mutagent agents conversations get <agent-id> <conversation-id>
5511
- ${chalk9.dim("$")} mutagent agents conversations get <agent-id> <conversation-id> --json
5512
- `).action(async (agentId, conversationId) => {
5513
- const isJson = getJsonFlag(agents);
5514
- const output = new OutputFormatter(isJson ? "json" : "table");
5515
- try {
5516
- const client = getSDKClient();
5517
- const conversation = await client.getConversation(agentId, conversationId);
5518
- if (isJson) {
5519
- output.output(conversation);
5520
- } else {
5521
- const formatted = {
5522
- id: conversation.id,
5523
- agentId: conversation.agentId,
5524
- title: conversation.title ?? "Untitled",
5525
- status: conversation.status,
5526
- messageCount: conversation.messageCount ?? "N/A",
5527
- createdAt: conversation.createdAt ? new Date(conversation.createdAt).toLocaleString() : "N/A",
5528
- updatedAt: conversation.updatedAt ? new Date(conversation.updatedAt).toLocaleString() : "N/A"
5529
- };
5530
- output.output(formatted);
5531
- }
5532
- } catch (error) {
5533
- handleError(error, isJson);
5534
- }
5535
- });
5536
- conversations.command("create").description("Start a new conversation with an agent").argument("<agent-id>", "Agent ID").option("-t, --title <title>", "Conversation title").addHelpText("after", `
5537
- Examples:
5538
- ${chalk9.dim("$")} mutagent agents conversations create <agent-id>
5539
- ${chalk9.dim("$")} mutagent agents conversations create <agent-id> --title "Debug session" --json
5540
- `).action(async (agentId, options) => {
5541
- const isJson = getJsonFlag(agents);
5542
- const output = new OutputFormatter(isJson ? "json" : "table");
5543
- try {
5544
- const client = getSDKClient();
5545
- const data = {};
5546
- if (options.title) {
5547
- data.title = options.title;
5548
- }
5549
- const conversation = await client.createConversation(agentId, data);
5550
- output.success(`Created conversation: ${conversation.id}`);
5551
- output.output(conversation);
5552
- } catch (error) {
5553
- handleError(error, isJson);
5554
- }
5555
- });
5556
- conversations.command("delete").description("Delete a conversation").argument("<agent-id>", "Agent ID").argument("<conversation-id>", "Conversation ID").option("--force", "Skip confirmation").addHelpText("after", `
5557
- Examples:
5558
- ${chalk9.dim("$")} mutagent agents conversations delete <agent-id> <conversation-id>
5559
- ${chalk9.dim("$")} mutagent agents conversations delete <agent-id> <conversation-id> --force --json
5560
- `).action(async (agentId, conversationId, options) => {
5561
- const isJson = getJsonFlag(agents);
5562
- const output = new OutputFormatter(isJson ? "json" : "table");
5563
- try {
5564
- if (!options.force && !isJson) {
5565
- const inquirer3 = (await import("inquirer")).default;
5566
- const answers = await inquirer3.prompt([{
5567
- type: "confirm",
5568
- name: "confirm",
5569
- message: `Delete conversation ${conversationId}? This action cannot be undone.`,
5570
- default: false
5571
- }]);
5572
- if (!answers.confirm) {
5573
- output.info("Cancelled");
5574
- return;
5575
- }
5576
- }
5577
- const client = getSDKClient();
5578
- await client.deleteConversation(agentId, conversationId);
5579
- output.success(`Deleted conversation: ${conversationId}`);
5580
- } catch (error) {
5581
- handleError(error, isJson);
5582
- }
5583
- });
5584
- conversations.command("messages").description("List messages in a conversation").argument("<agent-id>", "Agent ID").argument("<conversation-id>", "Conversation ID").option("-l, --limit <n>", "Limit results", "50").option("-o, --offset <n>", "Offset for pagination").addHelpText("after", `
5753
+ }
5754
+
5755
+ // src/commands/agents/index.ts
5756
+ function createAgentsCommand() {
5757
+ const agents = new Command9("agents").description("Manage AI agents").addHelpText("after", `
5585
5758
  Examples:
5586
- ${chalk9.dim("$")} mutagent agents conversations messages <agent-id> <conversation-id>
5587
- ${chalk9.dim("$")} mutagent agents conversations messages <agent-id> <conversation-id> --limit 20 --json
5588
- `).action(async (agentId, conversationId, options) => {
5589
- const isJson = getJsonFlag(agents);
5590
- const output = new OutputFormatter(isJson ? "json" : "table");
5591
- try {
5592
- const client = getSDKClient();
5593
- const filters = {
5594
- limit: parseInt(options.limit, 10) || 50
5595
- };
5596
- if (options.offset) {
5597
- filters.offset = parseInt(options.offset, 10);
5598
- }
5599
- const result = await client.listMessages(agentId, conversationId, filters);
5600
- if (isJson) {
5601
- output.output(result);
5602
- } else {
5603
- const formatted = result.data.map((m) => ({
5604
- id: m.id,
5605
- role: m.role,
5606
- content: m.content.length > 80 ? m.content.substring(0, 77) + "..." : m.content,
5607
- tokens: m.tokenCount ?? "N/A",
5608
- created: m.createdAt ? new Date(m.createdAt).toLocaleString() : "N/A"
5609
- }));
5610
- output.output(formatted);
5611
- }
5612
- } catch (error) {
5613
- handleError(error, isJson);
5614
- }
5615
- });
5759
+ ${chalk14.dim("$")} mutagent agents list
5760
+ ${chalk14.dim("$")} mutagent agents get <agent-id>
5761
+ ${chalk14.dim("$")} mutagent agents create --name "Code Reviewer" --slug code-reviewer --system-prompt "You are a code reviewer..."
5762
+ ${chalk14.dim("$")} mutagent agents create -d '{"name":"Code Reviewer","slug":"code-reviewer","systemPrompt":"You are..."}'
5763
+ ${chalk14.dim("$")} mutagent agents update <agent-id> --name "Updated Name"
5764
+ ${chalk14.dim("$")} mutagent agents delete <agent-id> --force
5765
+
5766
+ Subcommands:
5767
+ list, get, create, update, delete
5768
+ `);
5769
+ registerAgentsCrud(agents);
5616
5770
  return agents;
5617
5771
  }
5618
5772
 
5619
5773
  // src/commands/config.ts
5620
5774
  init_config();
5621
- import { Command as Command7 } from "commander";
5622
- import chalk10 from "chalk";
5775
+ import { Command as Command10 } from "commander";
5776
+ import chalk15 from "chalk";
5623
5777
  init_errors();
5624
5778
  var VALID_CONFIG_KEYS = ["apiKey", "endpoint", "format", "timeout", "defaultWorkspace", "defaultOrganization"];
5625
5779
  function createConfigCommand() {
5626
- const config = new Command7("config").description("Manage CLI configuration").addHelpText("after", `
5780
+ const config = new Command10("config").description("Manage CLI configuration").addHelpText("after", `
5627
5781
  Examples:
5628
- ${chalk10.dim("$")} mutagent config list
5629
- ${chalk10.dim("$")} mutagent config get endpoint
5630
- ${chalk10.dim("$")} mutagent config set workspace <workspace-id>
5631
- ${chalk10.dim("$")} mutagent config set org <org-id>
5782
+ ${chalk15.dim("$")} mutagent config list
5783
+ ${chalk15.dim("$")} mutagent config get endpoint
5784
+ ${chalk15.dim("$")} mutagent config set workspace <workspace-id>
5785
+ ${chalk15.dim("$")} mutagent config set org <org-id>
5632
5786
  `);
5633
5787
  config.command("list").description("List all configuration").addHelpText("after", `
5634
5788
  Examples:
5635
- ${chalk10.dim("$")} mutagent config list
5636
- ${chalk10.dim("$")} mutagent config list --json
5789
+ ${chalk15.dim("$")} mutagent config list
5790
+ ${chalk15.dim("$")} mutagent config list --json
5637
5791
  `).action(() => {
5638
5792
  const isJson = getJsonFlag(config);
5639
5793
  const output = new OutputFormatter(isJson ? "json" : "table");
@@ -5646,11 +5800,11 @@ Examples:
5646
5800
  });
5647
5801
  config.command("get").description("Get configuration value").argument("<key>", "Configuration key (apiKey, endpoint, format, timeout, defaultWorkspace, defaultOrganization)").addHelpText("after", `
5648
5802
  Examples:
5649
- ${chalk10.dim("$")} mutagent config get endpoint
5650
- ${chalk10.dim("$")} mutagent config get defaultWorkspace
5651
- ${chalk10.dim("$")} mutagent config get apiKey --json
5803
+ ${chalk15.dim("$")} mutagent config get endpoint
5804
+ ${chalk15.dim("$")} mutagent config get defaultWorkspace
5805
+ ${chalk15.dim("$")} mutagent config get apiKey --json
5652
5806
 
5653
- ${chalk10.dim("Keys: apiKey, endpoint, format, timeout, defaultWorkspace, defaultOrganization")}
5807
+ ${chalk15.dim("Keys: apiKey, endpoint, format, timeout, defaultWorkspace, defaultOrganization")}
5654
5808
  `).action((key) => {
5655
5809
  const isJson = getJsonFlag(config);
5656
5810
  const output = new OutputFormatter(isJson ? "json" : "table");
@@ -5672,14 +5826,14 @@ ${chalk10.dim("Keys: apiKey, endpoint, format, timeout, defaultWorkspace, defaul
5672
5826
  handleError(error, isJson);
5673
5827
  }
5674
5828
  });
5675
- const set = new Command7("set").description("Set configuration value").action(() => {
5829
+ const set = new Command10("set").description("Set configuration value").action(() => {
5676
5830
  set.help();
5677
5831
  });
5678
5832
  set.command("workspace").description("Set default workspace ID").argument("<id>", "Workspace ID to set as default").addHelpText("after", `
5679
5833
  Examples:
5680
- ${chalk10.dim("$")} mutagent config set workspace <workspace-id>
5834
+ ${chalk15.dim("$")} mutagent config set workspace <workspace-id>
5681
5835
 
5682
- ${chalk10.dim("Persists workspace ID so you don't need to pass headers on every request.")}
5836
+ ${chalk15.dim("Persists workspace ID so you don't need to pass headers on every request.")}
5683
5837
  `).action((id) => {
5684
5838
  const isJson = getJsonFlag(config);
5685
5839
  const output = new OutputFormatter(isJson ? "json" : "table");
@@ -5692,9 +5846,9 @@ ${chalk10.dim("Persists workspace ID so you don't need to pass headers on every
5692
5846
  });
5693
5847
  set.command("org").description("Set default organization ID").argument("<id>", "Organization ID to set as default").addHelpText("after", `
5694
5848
  Examples:
5695
- ${chalk10.dim("$")} mutagent config set org <org-id>
5849
+ ${chalk15.dim("$")} mutagent config set org <org-id>
5696
5850
 
5697
- ${chalk10.dim("Persists organization ID for org-scoped API keys.")}
5851
+ ${chalk15.dim("Persists organization ID for org-scoped API keys.")}
5698
5852
  `).action((id) => {
5699
5853
  const isJson = getJsonFlag(config);
5700
5854
  const output = new OutputFormatter(isJson ? "json" : "table");
@@ -5711,8 +5865,8 @@ ${chalk10.dim("Persists organization ID for org-scoped API keys.")}
5711
5865
 
5712
5866
  // src/commands/playground.ts
5713
5867
  init_sdk_client();
5714
- import { Command as Command8 } from "commander";
5715
- import chalk11 from "chalk";
5868
+ import { Command as Command11 } from "commander";
5869
+ import chalk16 from "chalk";
5716
5870
  init_errors();
5717
5871
  function parseSSELine(line) {
5718
5872
  if (!line || line.startsWith(":")) {
@@ -5737,13 +5891,13 @@ function parsePromptStreamEvent(data) {
5737
5891
  }
5738
5892
  }
5739
5893
  function createPlaygroundCommand() {
5740
- const playground = new Command8("playground").description("Execute and test prompts interactively").addHelpText("after", `
5894
+ const playground = new Command11("playground").description("Execute and test prompts interactively").addHelpText("after", `
5741
5895
  Examples:
5742
- ${chalk11.dim("$")} mutagent playground run <prompt-id> --input '{"name": "John"}'
5743
- ${chalk11.dim("$")} mutagent playground run <prompt-id> --input '{}' --stream
5744
- ${chalk11.dim("$")} mutagent playground run <prompt-id> -i '{}' --model gpt-4-turbo
5745
- ${chalk11.dim("$")} mutagent playground run <prompt-id> --system "You are helpful" --human "Hello"
5746
- ${chalk11.dim("$")} mutagent playground run <prompt-id> --messages '[{"role":"user","content":"Hi"}]'
5896
+ ${chalk16.dim("$")} mutagent playground run <prompt-id> --input '{"name": "John"}'
5897
+ ${chalk16.dim("$")} mutagent playground run <prompt-id> --input '{}' --stream
5898
+ ${chalk16.dim("$")} mutagent playground run <prompt-id> -i '{}' --model gpt-4-turbo
5899
+ ${chalk16.dim("$")} mutagent playground run <prompt-id> --system "You are helpful" --human "Hello"
5900
+ ${chalk16.dim("$")} mutagent playground run <prompt-id> --messages '[{"role":"user","content":"Hi"}]'
5747
5901
 
5748
5902
  Input Format:
5749
5903
  The input must be a valid JSON object matching the prompt's input schema.
@@ -5759,16 +5913,16 @@ Streaming:
5759
5913
  `);
5760
5914
  playground.command("run").description("Execute a prompt with input variables").argument("<prompt-id>", "Prompt ID to execute (from: mutagent prompts list)").option("-i, --input <json>", "Input variables as JSON").option("-s, --stream", "Stream the response").option("-m, --model <model>", "Override model").option("--system <text>", "Set system prompt text").option("--human <text>", "Set human/user message text").option("--messages <json>", "Pass full messages array as JSON string").addHelpText("after", `
5761
5915
  Examples:
5762
- ${chalk11.dim("$")} mutagent playground run <prompt-id> --input '{"name": "John"}'
5763
- ${chalk11.dim("$")} mutagent playground run <prompt-id> --input '{}' --stream
5764
- ${chalk11.dim("$")} mutagent playground run <prompt-id> --system "You are helpful" --human "Hello"
5765
- ${chalk11.dim("$")} mutagent playground run <prompt-id> --input '{}' --model gpt-4-turbo --json
5916
+ ${chalk16.dim("$")} mutagent playground run <prompt-id> --input '{"name": "John"}'
5917
+ ${chalk16.dim("$")} mutagent playground run <prompt-id> --input '{}' --stream
5918
+ ${chalk16.dim("$")} mutagent playground run <prompt-id> --system "You are helpful" --human "Hello"
5919
+ ${chalk16.dim("$")} mutagent playground run <prompt-id> --input '{}' --model gpt-4-turbo --json
5766
5920
 
5767
5921
  Input Methods (pick one, priority order):
5768
- --system/--human Quick system + user message ${chalk11.green("(recommended)")}
5922
+ --system/--human Quick system + user message ${chalk16.green("(recommended)")}
5769
5923
  --input '{"key":"value"}' Inline JSON variables
5770
5924
  --messages '[...]' Full messages array
5771
- ${chalk11.dim(`Hint: Test before evaluating: mutagent playground run <id> --input '{"key":"value"}'`)}
5925
+ ${chalk16.dim(`Hint: Test before evaluating: mutagent playground run <id> --input '{"key":"value"}'`)}
5772
5926
  `).action(async (promptId, options) => {
5773
5927
  const isJson = getJsonFlag(playground);
5774
5928
  const output = new OutputFormatter(isJson ? "json" : "table");
@@ -5790,21 +5944,21 @@ ${chalk11.dim(`Hint: Test before evaluating: mutagent playground run <id> --inpu
5790
5944
  }
5791
5945
  });
5792
5946
  } else {
5793
- console.log(chalk11.bold(`
5947
+ console.log(chalk16.bold(`
5794
5948
  Execution Result:`));
5795
- console.log(chalk11.gray("─".repeat(50)));
5796
- console.log(chalk11.cyan("Output:"));
5949
+ console.log(chalk16.gray("─".repeat(50)));
5950
+ console.log(chalk16.cyan("Output:"));
5797
5951
  console.log(result.output);
5798
- console.log(chalk11.gray("─".repeat(50)));
5799
- console.log(chalk11.dim(`Model: ${result.model}`));
5800
- console.log(chalk11.dim(`Execution Time: ${String(result.executionTimeMs)}ms`));
5952
+ console.log(chalk16.gray("─".repeat(50)));
5953
+ console.log(chalk16.dim(`Model: ${result.model}`));
5954
+ console.log(chalk16.dim(`Execution Time: ${String(result.executionTimeMs)}ms`));
5801
5955
  if (result.tokens) {
5802
- console.log(chalk11.dim(`Tokens: ${String(result.tokens.prompt)} prompt + ${String(result.tokens.completion)} completion = ${String(result.tokens.total)} total`));
5956
+ console.log(chalk16.dim(`Tokens: ${String(result.tokens.prompt)} prompt + ${String(result.tokens.completion)} completion = ${String(result.tokens.total)} total`));
5803
5957
  }
5804
5958
  if (result.cost !== undefined) {
5805
- console.log(chalk11.dim(`Cost: $${result.cost.toFixed(6)}`));
5959
+ console.log(chalk16.dim(`Cost: $${result.cost.toFixed(6)}`));
5806
5960
  }
5807
- console.log(chalk11.dim(`Playground: ${playgroundLink()}`));
5961
+ console.log(chalk16.dim(`Playground: ${playgroundLink()}`));
5808
5962
  console.log();
5809
5963
  }
5810
5964
  }
@@ -5893,9 +6047,9 @@ async function executeStreaming(client, promptId, input, model, isJson, output)
5893
6047
  const decoder = new TextDecoder;
5894
6048
  let buffer = "";
5895
6049
  if (!isJson) {
5896
- console.log(chalk11.bold(`
6050
+ console.log(chalk16.bold(`
5897
6051
  Streaming Output:`));
5898
- console.log(chalk11.gray("─".repeat(50)));
6052
+ console.log(chalk16.gray("─".repeat(50)));
5899
6053
  }
5900
6054
  try {
5901
6055
  for (;; ) {
@@ -5934,15 +6088,15 @@ Streaming Output:`));
5934
6088
  console.log(JSON.stringify({ type: "complete", result: event.result }));
5935
6089
  } else {
5936
6090
  console.log();
5937
- console.log(chalk11.gray("─".repeat(50)));
6091
+ console.log(chalk16.gray("─".repeat(50)));
5938
6092
  if (event.result) {
5939
- console.log(chalk11.dim(`Model: ${event.result.model}`));
5940
- console.log(chalk11.dim(`Execution Time: ${String(event.result.executionTimeMs)}ms`));
6093
+ console.log(chalk16.dim(`Model: ${event.result.model}`));
6094
+ console.log(chalk16.dim(`Execution Time: ${String(event.result.executionTimeMs)}ms`));
5941
6095
  if (event.result.tokens) {
5942
- console.log(chalk11.dim(`Tokens: ${String(event.result.tokens.prompt)} prompt + ${String(event.result.tokens.completion)} completion = ${String(event.result.tokens.total)} total`));
6096
+ console.log(chalk16.dim(`Tokens: ${String(event.result.tokens.prompt)} prompt + ${String(event.result.tokens.completion)} completion = ${String(event.result.tokens.total)} total`));
5943
6097
  }
5944
6098
  if (event.result.cost !== undefined) {
5945
- console.log(chalk11.dim(`Cost: $${event.result.cost.toFixed(6)}`));
6099
+ console.log(chalk16.dim(`Cost: $${event.result.cost.toFixed(6)}`));
5946
6100
  }
5947
6101
  }
5948
6102
  console.log();
@@ -5966,14 +6120,14 @@ Streaming Output:`));
5966
6120
 
5967
6121
  // src/commands/workspaces.ts
5968
6122
  init_sdk_client();
5969
- import { Command as Command9 } from "commander";
5970
- import chalk12 from "chalk";
6123
+ import { Command as Command12 } from "commander";
6124
+ import chalk17 from "chalk";
5971
6125
  init_errors();
5972
6126
  function createWorkspacesCommand() {
5973
- const workspaces = new Command9("workspaces").description("View workspaces (read-only)").addHelpText("after", `
6127
+ const workspaces = new Command12("workspaces").description("View workspaces (read-only)").addHelpText("after", `
5974
6128
  Examples:
5975
- ${chalk12.dim("$")} mutagent workspaces list
5976
- ${chalk12.dim("$")} mutagent workspaces get <workspace-id>
6129
+ ${chalk17.dim("$")} mutagent workspaces list
6130
+ ${chalk17.dim("$")} mutagent workspaces get <workspace-id>
5977
6131
 
5978
6132
  Subcommands:
5979
6133
  list, get
@@ -5982,8 +6136,8 @@ Note: Workspace management (create, update, delete) is available in the Admin Pa
5982
6136
  `);
5983
6137
  workspaces.command("list").description("List all workspaces").option("-l, --limit <n>", "Limit results", "50").option("-o, --offset <n>", "Offset for pagination").addHelpText("after", `
5984
6138
  Examples:
5985
- ${chalk12.dim("$")} mutagent workspaces list
5986
- ${chalk12.dim("$")} mutagent workspaces list --limit 10 --json
6139
+ ${chalk17.dim("$")} mutagent workspaces list
6140
+ ${chalk17.dim("$")} mutagent workspaces list --limit 10 --json
5987
6141
  `).action(async (options) => {
5988
6142
  const isJson = getJsonFlag(workspaces);
5989
6143
  const output = new OutputFormatter(isJson ? "json" : "table");
@@ -6023,8 +6177,8 @@ Examples:
6023
6177
  });
6024
6178
  workspaces.command("get").description("Get workspace details").argument("<id>", "Workspace ID").addHelpText("after", `
6025
6179
  Examples:
6026
- ${chalk12.dim("$")} mutagent workspaces get <workspace-id>
6027
- ${chalk12.dim("$")} mutagent workspaces get <workspace-id> --json
6180
+ ${chalk17.dim("$")} mutagent workspaces get <workspace-id>
6181
+ ${chalk17.dim("$")} mutagent workspaces get <workspace-id> --json
6028
6182
  `).action(async (id) => {
6029
6183
  const isJson = getJsonFlag(workspaces);
6030
6184
  const output = new OutputFormatter(isJson ? "json" : "table");
@@ -6056,8 +6210,8 @@ Examples:
6056
6210
 
6057
6211
  // src/commands/providers.ts
6058
6212
  init_sdk_client();
6059
- import { Command as Command10 } from "commander";
6060
- import chalk13 from "chalk";
6213
+ import { Command as Command13 } from "commander";
6214
+ import chalk18 from "chalk";
6061
6215
  init_errors();
6062
6216
  var VALID_PROVIDER_TYPES = [
6063
6217
  "openai",
@@ -6079,11 +6233,11 @@ function validateProviderType(type) {
6079
6233
  return type;
6080
6234
  }
6081
6235
  function createProvidersCommand() {
6082
- const providers = new Command10("providers").description("View LLM providers (read-only)").addHelpText("after", `
6236
+ const providers = new Command13("providers").description("View LLM providers (read-only)").addHelpText("after", `
6083
6237
  Examples:
6084
- ${chalk13.dim("$")} mutagent providers list
6085
- ${chalk13.dim("$")} mutagent providers get <provider-id>
6086
- ${chalk13.dim("$")} mutagent providers test <provider-id>
6238
+ ${chalk18.dim("$")} mutagent providers list
6239
+ ${chalk18.dim("$")} mutagent providers get <provider-id>
6240
+ ${chalk18.dim("$")} mutagent providers test <provider-id>
6087
6241
 
6088
6242
  Provider Types:
6089
6243
  openai, anthropic, google, azure, bedrock, cohere, mistral, groq, together, replicate, custom
@@ -6093,15 +6247,15 @@ Subcommands:
6093
6247
 
6094
6248
  Note: Provider management (create, update, delete) is available in the Admin Panel only.
6095
6249
 
6096
- ${chalk13.yellow("Note:")} The providers module is not yet active. This is a placeholder
6250
+ ${chalk18.yellow("Note:")} The providers module is not yet active. This is a placeholder
6097
6251
  for future external provider configuration. The server currently uses
6098
6252
  built-in provider settings.
6099
6253
  `);
6100
6254
  providers.command("list").description("List all providers").option("-l, --limit <n>", "Limit results", "50").option("-o, --offset <n>", "Offset for pagination").option("-t, --type <type>", "Filter by provider type").addHelpText("after", `
6101
6255
  Examples:
6102
- ${chalk13.dim("$")} mutagent providers list
6103
- ${chalk13.dim("$")} mutagent providers list --type openai
6104
- ${chalk13.dim("$")} mutagent providers list --json
6256
+ ${chalk18.dim("$")} mutagent providers list
6257
+ ${chalk18.dim("$")} mutagent providers list --type openai
6258
+ ${chalk18.dim("$")} mutagent providers list --json
6105
6259
  `).action(async (options) => {
6106
6260
  const isJson = getJsonFlag(providers);
6107
6261
  const output = new OutputFormatter(isJson ? "json" : "table");
@@ -6128,7 +6282,7 @@ Examples:
6128
6282
  }));
6129
6283
  output.output({ ...result, data: withLinks });
6130
6284
  } else {
6131
- console.log(chalk13.yellow("Note: The providers module is not yet active. This is a placeholder for future external provider configuration."));
6285
+ console.log(chalk18.yellow("Note: The providers module is not yet active. This is a placeholder for future external provider configuration."));
6132
6286
  console.log("");
6133
6287
  if (result.data.length === 0) {
6134
6288
  output.info("No providers configured.");
@@ -6152,8 +6306,8 @@ Examples:
6152
6306
  });
6153
6307
  providers.command("get").description("Get provider details").argument("<id>", "Provider ID (from: mutagent providers list)").addHelpText("after", `
6154
6308
  Examples:
6155
- ${chalk13.dim("$")} mutagent providers get <provider-id>
6156
- ${chalk13.dim("$")} mutagent providers get <provider-id> --json
6309
+ ${chalk18.dim("$")} mutagent providers get <provider-id>
6310
+ ${chalk18.dim("$")} mutagent providers get <provider-id> --json
6157
6311
  `).action(async (id) => {
6158
6312
  const isJson = getJsonFlag(providers);
6159
6313
  const output = new OutputFormatter(isJson ? "json" : "table");
@@ -6163,7 +6317,7 @@ Examples:
6163
6317
  if (isJson) {
6164
6318
  output.output({ ...provider, _links: providerLinks(provider.id) });
6165
6319
  } else {
6166
- console.log(chalk13.yellow("Note: The providers module is not yet active. This is a placeholder for future external provider configuration."));
6320
+ console.log(chalk18.yellow("Note: The providers module is not yet active. This is a placeholder for future external provider configuration."));
6167
6321
  console.log("");
6168
6322
  const formatted = {
6169
6323
  id: provider.id,
@@ -6184,17 +6338,17 @@ Examples:
6184
6338
  });
6185
6339
  providers.command("test").description("Test provider connectivity").argument("<id>", "Provider ID (from: mutagent providers list)").addHelpText("after", `
6186
6340
  Examples:
6187
- ${chalk13.dim("$")} mutagent providers test <provider-id>
6188
- ${chalk13.dim("$")} mutagent providers test <provider-id> --json
6341
+ ${chalk18.dim("$")} mutagent providers test <provider-id>
6342
+ ${chalk18.dim("$")} mutagent providers test <provider-id> --json
6189
6343
 
6190
- ${chalk13.dim("Tests connectivity and lists available models for the provider.")}
6344
+ ${chalk18.dim("Tests connectivity and lists available models for the provider.")}
6191
6345
  `).action(async (id) => {
6192
6346
  const isJson = getJsonFlag(providers);
6193
6347
  const output = new OutputFormatter(isJson ? "json" : "table");
6194
6348
  try {
6195
6349
  const client = getSDKClient();
6196
6350
  if (!isJson) {
6197
- console.log(chalk13.yellow("Note: The providers module is not yet active. This is a placeholder for future external provider configuration."));
6351
+ console.log(chalk18.yellow("Note: The providers module is not yet active. This is a placeholder for future external provider configuration."));
6198
6352
  console.log("");
6199
6353
  output.info(`Testing provider ${id}...`);
6200
6354
  }
@@ -6204,9 +6358,9 @@ ${chalk13.dim("Tests connectivity and lists available models for the provider.")
6204
6358
  } else {
6205
6359
  if (result.success) {
6206
6360
  output.success(`Provider test passed (${String(result.responseTimeMs)}ms)`);
6207
- console.log(chalk13.green(`Message: ${result.message}`));
6361
+ console.log(chalk18.green(`Message: ${result.message}`));
6208
6362
  if (result.availableModels && result.availableModels.length > 0) {
6209
- console.log(chalk13.bold(`
6363
+ console.log(chalk18.bold(`
6210
6364
  Available Models:`));
6211
6365
  result.availableModels.forEach((model) => {
6212
6366
  console.log(` - ${model}`);
@@ -6215,7 +6369,7 @@ Available Models:`));
6215
6369
  } else {
6216
6370
  output.error(`Provider test failed: ${result.message}`);
6217
6371
  if (result.error) {
6218
- console.log(chalk13.red(`Error: ${result.error}`));
6372
+ console.log(chalk18.red(`Error: ${result.error}`));
6219
6373
  }
6220
6374
  }
6221
6375
  }
@@ -6228,13 +6382,18 @@ Available Models:`));
6228
6382
 
6229
6383
  // src/commands/init.ts
6230
6384
  init_config();
6231
- import { Command as Command11 } from "commander";
6385
+ import { Command as Command14 } from "commander";
6232
6386
  import inquirer3 from "inquirer";
6233
- import chalk14 from "chalk";
6234
- import { existsSync as existsSync10, mkdirSync as mkdirSync3, readFileSync as readFileSync9, writeFileSync as writeFileSync4 } from "fs";
6387
+ import chalk19 from "chalk";
6388
+ import { existsSync as existsSync12, mkdirSync as mkdirSync3, writeFileSync as writeFileSync4 } from "fs";
6389
+ import { execSync as execSync3 } from "child_process";
6390
+ import { join as join6 } from "path";
6391
+ init_errors();
6392
+
6393
+ // src/lib/framework-detection.ts
6394
+ import { existsSync as existsSync11, readFileSync as readFileSync10 } from "fs";
6235
6395
  import { execSync as execSync2 } from "child_process";
6236
6396
  import { join as join5 } from "path";
6237
- init_errors();
6238
6397
  var FRAMEWORK_DETECTION_MAP = {
6239
6398
  "@mastra/core": {
6240
6399
  name: "mastra",
@@ -6284,16 +6443,16 @@ var FRAMEWORK_DETECTION_MAP = {
6284
6443
  }
6285
6444
  };
6286
6445
  function detectPackageManager2(cwd = process.cwd()) {
6287
- if (existsSync10(join5(cwd, "bun.lockb")) || existsSync10(join5(cwd, "bun.lock"))) {
6446
+ if (existsSync11(join5(cwd, "bun.lockb")) || existsSync11(join5(cwd, "bun.lock"))) {
6288
6447
  return "bun";
6289
6448
  }
6290
- if (existsSync10(join5(cwd, "pnpm-lock.yaml"))) {
6449
+ if (existsSync11(join5(cwd, "pnpm-lock.yaml"))) {
6291
6450
  return "pnpm";
6292
6451
  }
6293
- if (existsSync10(join5(cwd, "yarn.lock"))) {
6452
+ if (existsSync11(join5(cwd, "yarn.lock"))) {
6294
6453
  return "yarn";
6295
6454
  }
6296
- if (existsSync10(join5(cwd, "package-lock.json"))) {
6455
+ if (existsSync11(join5(cwd, "package-lock.json"))) {
6297
6456
  return "npm";
6298
6457
  }
6299
6458
  try {
@@ -6315,12 +6474,12 @@ function getInstallCommand2(pm, packages) {
6315
6474
  }
6316
6475
  function detectFrameworkFromPackageJson(cwd = process.cwd()) {
6317
6476
  const pkgPath = join5(cwd, "package.json");
6318
- if (!existsSync10(pkgPath)) {
6477
+ if (!existsSync11(pkgPath)) {
6319
6478
  return null;
6320
6479
  }
6321
6480
  let pkg;
6322
6481
  try {
6323
- pkg = JSON.parse(readFileSync9(pkgPath, "utf-8"));
6482
+ pkg = JSON.parse(readFileSync10(pkgPath, "utf-8"));
6324
6483
  } catch {
6325
6484
  return null;
6326
6485
  }
@@ -6336,23 +6495,25 @@ function detectFrameworkFromPackageJson(cwd = process.cwd()) {
6336
6495
  return null;
6337
6496
  }
6338
6497
  function hasRcConfig(cwd = process.cwd()) {
6339
- return existsSync10(join5(cwd, ".mutagentrc.json"));
6498
+ return existsSync11(join5(cwd, ".mutagentrc.json"));
6340
6499
  }
6500
+
6501
+ // src/commands/init.ts
6341
6502
  function writeRcConfig(config, cwd = process.cwd()) {
6342
- const rcPath = join5(cwd, ".mutagentrc.json");
6503
+ const rcPath = join6(cwd, ".mutagentrc.json");
6343
6504
  writeFileSync4(rcPath, JSON.stringify(config, null, 2) + `
6344
6505
  `);
6345
6506
  }
6346
6507
  function createInitCommand() {
6347
- const init = new Command11("init").description("Initialize MutagenT in your project").option("--non-interactive", "Skip interactive prompts (defaults to CLI-only mode)").addHelpText("after", `
6508
+ const init = new Command14("init").description("Initialize MutagenT in your project").option("--non-interactive", "Skip interactive prompts (defaults to CLI-only mode)").addHelpText("after", `
6348
6509
  Examples:
6349
- ${chalk14.dim("$")} mutagent init # Interactive setup wizard
6350
- ${chalk14.dim("$")} mutagent init --non-interactive # CLI-only mode (no prompts)
6510
+ ${chalk19.dim("$")} mutagent init # Interactive setup wizard
6511
+ ${chalk19.dim("$")} mutagent init --non-interactive # CLI-only mode (no prompts)
6351
6512
 
6352
6513
  Modes:
6353
- ${chalk14.bold("Full scaffold")} Install SDK + integration package, create config, setup tracing
6354
- ${chalk14.bold("CLI-only")} Verify auth + create .mutagentrc.json with workspace/endpoint
6355
- ${chalk14.bold("Skip")} Exit without changes
6514
+ ${chalk19.bold("Full scaffold")} Install SDK + integration package, create config, setup tracing
6515
+ ${chalk19.bold("CLI-only")} Verify auth + create .mutagentrc.json with workspace/endpoint
6516
+ ${chalk19.bold("Skip")} Exit without changes
6356
6517
  `).action(async (options) => {
6357
6518
  const isJson = getJsonFlag(init);
6358
6519
  const output = new OutputFormatter(isJson ? "json" : "table");
@@ -6510,7 +6671,7 @@ Modes:
6510
6671
  output.info(`Installing: ${packages.join(", ")}`);
6511
6672
  output.info(`Running: ${installCmd}`);
6512
6673
  try {
6513
- execSync2(installCmd, { cwd, stdio: "inherit" });
6674
+ execSync3(installCmd, { cwd, stdio: "inherit" });
6514
6675
  output.success("Packages installed successfully.");
6515
6676
  } catch {
6516
6677
  output.error("Package installation failed. You can install manually:");
@@ -6553,8 +6714,8 @@ Modes:
6553
6714
  }
6554
6715
  }
6555
6716
  if (!isNonInteractive) {
6556
- const skillPath = join5(cwd, ".claude/skills/mutagent-cli/SKILL.md");
6557
- if (!existsSync10(skillPath)) {
6717
+ const skillPath = join6(cwd, ".claude/skills/mutagent-cli/SKILL.md");
6718
+ if (!existsSync12(skillPath)) {
6558
6719
  const { installSkill } = await inquirer3.prompt([{
6559
6720
  type: "confirm",
6560
6721
  name: "installSkill",
@@ -6563,11 +6724,11 @@ Modes:
6563
6724
  }]);
6564
6725
  if (installSkill) {
6565
6726
  try {
6566
- const skillDir = join5(cwd, ".claude/skills/mutagent-cli");
6567
- if (!existsSync10(skillDir)) {
6727
+ const skillDir = join6(cwd, ".claude/skills/mutagent-cli");
6728
+ if (!existsSync12(skillDir)) {
6568
6729
  mkdirSync3(skillDir, { recursive: true });
6569
6730
  }
6570
- execSync2("node " + join5(cwd, "node_modules/.bin/mutagent") + " skills install", {
6731
+ execSync3("node " + join6(cwd, "node_modules/.bin/mutagent") + " skills install", {
6571
6732
  cwd,
6572
6733
  stdio: "ignore"
6573
6734
  });
@@ -6601,24 +6762,24 @@ Modes:
6601
6762
  }
6602
6763
 
6603
6764
  // src/commands/explore.ts
6604
- import { Command as Command12 } from "commander";
6605
- import chalk15 from "chalk";
6765
+ import { Command as Command15 } from "commander";
6766
+ import chalk20 from "chalk";
6606
6767
  import { resolve as resolve3 } from "path";
6607
6768
  init_errors();
6608
6769
  function createExploreCommand() {
6609
- const explore = new Command12("explore").description("Scan codebase for prompts, datasets, and MutagenT markers").option("-p, --path <dir>", "Directory to scan", ".").option("--depth <n>", "Max directory depth", "10").option("--include <glob>", "Include file pattern", "**/*.{ts,js,py,tsx,jsx}").option("--exclude <dirs>", "Comma-separated directories to exclude", "node_modules,dist,.git,build,.next,__pycache__,venv,.venv").option("--markers-only", "Only find existing MutagenT markers").addHelpText("after", `
6770
+ const explore = new Command15("explore").description("Scan codebase for prompts, datasets, and MutagenT markers").option("-p, --path <dir>", "Directory to scan", ".").option("--depth <n>", "Max directory depth", "10").option("--include <glob>", "Include file pattern", "**/*.{ts,js,py,tsx,jsx}").option("--exclude <dirs>", "Comma-separated directories to exclude", "node_modules,dist,.git,build,.next,__pycache__,venv,.venv").option("--markers-only", "Only find existing MutagenT markers").addHelpText("after", `
6610
6771
  Examples:
6611
- ${chalk15.dim("$")} mutagent explore
6612
- ${chalk15.dim("$")} mutagent explore --path ./src
6613
- ${chalk15.dim("$")} mutagent explore --include "**/*.{ts,py}" --depth 5
6614
- ${chalk15.dim("$")} mutagent explore --markers-only
6615
- ${chalk15.dim("$")} mutagent explore --json
6772
+ ${chalk20.dim("$")} mutagent explore
6773
+ ${chalk20.dim("$")} mutagent explore --path ./src
6774
+ ${chalk20.dim("$")} mutagent explore --include "**/*.{ts,py}" --depth 5
6775
+ ${chalk20.dim("$")} mutagent explore --markers-only
6776
+ ${chalk20.dim("$")} mutagent explore --json
6616
6777
 
6617
6778
  Detection modes:
6618
- ${chalk15.dim("Heuristic")} Template variables ({{var}}), prompt constants, schema definitions
6619
- ${chalk15.dim("Marker")} MutagenT:START/END comment markers from previous uploads
6779
+ ${chalk20.dim("Heuristic")} Template variables ({{var}}), prompt constants, schema definitions
6780
+ ${chalk20.dim("Marker")} MutagenT:START/END comment markers from previous uploads
6620
6781
 
6621
- ${chalk15.dim("Results are saved to .mutagent/mutation-context.md for use by other commands.")}
6782
+ ${chalk20.dim("Results are saved to .mutagent/mutation-context.md for use by other commands.")}
6622
6783
  `).action((options) => {
6623
6784
  const isJson = getJsonFlag(explore);
6624
6785
  const output = new OutputFormatter(isJson ? "json" : "table");
@@ -6636,7 +6797,7 @@ ${chalk15.dim("Results are saved to .mutagent/mutation-context.md for use by oth
6636
6797
  markersOnly
6637
6798
  };
6638
6799
  if (!isJson) {
6639
- console.log(chalk15.cyan(`
6800
+ console.log(chalk20.cyan(`
6640
6801
  Scanning ${scanPath}...
6641
6802
  `));
6642
6803
  }
@@ -6665,40 +6826,41 @@ Scanning ${scanPath}...
6665
6826
  const totalFindings = result.prompts.length + result.datasets.length + result.markers.length;
6666
6827
  if (totalFindings === 0) {
6667
6828
  output.info("No prompts, datasets, or markers found.");
6668
- console.log(chalk15.dim(`
6829
+ console.log(chalk20.dim(`
6669
6830
  Tip: Create a prompt with template variables like {{input}} to get started.`));
6670
6831
  return;
6671
6832
  }
6672
6833
  if (result.prompts.length > 0) {
6673
- console.log(chalk15.bold(` Prompts Found (${String(result.prompts.length)}):`));
6834
+ console.log(chalk20.bold(` Prompts Found (${String(result.prompts.length)}):`));
6674
6835
  console.log();
6675
6836
  for (const p of result.prompts) {
6676
- const reasonTag = chalk15.dim(`[${p.reason}]`);
6677
- console.log(` ${chalk15.green(p.file)}:${chalk15.yellow(String(p.line))} ${reasonTag}`);
6678
- console.log(` ${chalk15.dim(p.preview)}`);
6837
+ const confidenceTag = p.confidence === "high" ? chalk20.green("[high]") : p.confidence === "medium" ? chalk20.yellow("[medium]") : chalk20.dim("[low]");
6838
+ const reasonTag = chalk20.dim(`[${p.reason}]`);
6839
+ console.log(` ${confidenceTag} ${chalk20.green(p.file)}:${chalk20.yellow(String(p.line))} ${reasonTag}`);
6840
+ console.log(` ${chalk20.dim(p.preview)}`);
6679
6841
  }
6680
6842
  console.log();
6681
6843
  }
6682
6844
  if (result.datasets.length > 0) {
6683
- console.log(chalk15.bold(` Datasets Found (${String(result.datasets.length)}):`));
6845
+ console.log(chalk20.bold(` Datasets Found (${String(result.datasets.length)}):`));
6684
6846
  console.log();
6685
6847
  for (const d of result.datasets) {
6686
- console.log(` ${chalk15.green(d.file)} ${chalk15.dim(`(${String(d.items)} items)`)}`);
6848
+ console.log(` ${chalk20.green(d.file)} ${chalk20.dim(`(${String(d.items)} items)`)}`);
6687
6849
  }
6688
6850
  console.log();
6689
6851
  }
6690
6852
  if (result.markers.length > 0) {
6691
- console.log(chalk15.bold(` MutagenT Markers (${String(result.markers.length)}):`));
6853
+ console.log(chalk20.bold(` MutagenT Markers (${String(result.markers.length)}):`));
6692
6854
  console.log();
6693
6855
  for (const m of result.markers) {
6694
- const idPart = m.platformId ? chalk15.cyan(` id=${m.platformId}`) : "";
6695
- console.log(` ${chalk15.green(m.file)}:${chalk15.yellow(String(m.line))} ${chalk15.magenta(m.type)}${idPart}`);
6856
+ const idPart = m.platformId ? chalk20.cyan(` id=${m.platformId}`) : "";
6857
+ console.log(` ${chalk20.green(m.file)}:${chalk20.yellow(String(m.line))} ${chalk20.magenta(m.type)}${idPart}`);
6696
6858
  }
6697
6859
  console.log();
6698
6860
  }
6699
- console.log(chalk15.dim(" ─────────────────────────────────"));
6700
- console.log(` ${chalk15.bold("Summary:")} ${String(result.prompts.length)} prompts, ${String(result.datasets.length)} datasets, ${String(result.markers.length)} markers`);
6701
- console.log(chalk15.dim(` Saved to .mutagent/mutation-context.md`));
6861
+ console.log(chalk20.dim(" ─────────────────────────────────"));
6862
+ console.log(` ${chalk20.bold("Summary:")} ${String(result.prompts.length)} prompts, ${String(result.datasets.length)} datasets, ${String(result.markers.length)} markers`);
6863
+ console.log(chalk20.dim(` Saved to .mutagent/mutation-context.md`));
6702
6864
  console.log();
6703
6865
  }
6704
6866
  } catch (error) {
@@ -6709,14 +6871,14 @@ Scanning ${scanPath}...
6709
6871
  }
6710
6872
 
6711
6873
  // src/commands/skills.ts
6712
- import { Command as Command13 } from "commander";
6713
- import chalk16 from "chalk";
6714
- import { existsSync as existsSync11, mkdirSync as mkdirSync4, writeFileSync as writeFileSync5 } from "fs";
6715
- import { join as join6 } from "path";
6716
- import { execSync as execSync3 } from "child_process";
6874
+ import { Command as Command16 } from "commander";
6875
+ import chalk21 from "chalk";
6876
+ import { existsSync as existsSync13, mkdirSync as mkdirSync4, writeFileSync as writeFileSync5 } from "fs";
6877
+ import { join as join7 } from "path";
6878
+ import { execSync as execSync4 } from "child_process";
6717
6879
  function findRepoRoot() {
6718
6880
  try {
6719
- return execSync3("git rev-parse --show-toplevel", { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] }).trim();
6881
+ return execSync4("git rev-parse --show-toplevel", { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] }).trim();
6720
6882
  } catch {
6721
6883
  return process.cwd();
6722
6884
  }
@@ -6830,10 +6992,10 @@ Every evaluation MUST specify criteria targeting either:
6830
6992
  var SKILL_DIR = ".claude/skills/mutagent-cli";
6831
6993
  var SKILL_FILE = "SKILL.md";
6832
6994
  function createSkillsCommand() {
6833
- const skills = new Command13("skills").description("Manage MutagenT CLI skills for coding agents");
6995
+ const skills = new Command16("skills").description("Manage MutagenT CLI skills for coding agents");
6834
6996
  skills.command("install").description("Install MutagenT CLI skill for Claude Code").addHelpText("after", `
6835
6997
  Examples:
6836
- ${chalk16.dim("$")} mutagent skills install
6998
+ ${chalk21.dim("$")} mutagent skills install
6837
6999
 
6838
7000
  This creates a Claude Code skill at .claude/skills/mutagent-cli/SKILL.md
6839
7001
  that teaches coding agents how to use the MutagenT CLI effectively.
@@ -6842,9 +7004,9 @@ that teaches coding agents how to use the MutagenT CLI effectively.
6842
7004
  const isJson = parentCmd ? getJsonFlag(parentCmd) : false;
6843
7005
  const output = new OutputFormatter(isJson ? "json" : "table");
6844
7006
  const repoRoot = findRepoRoot();
6845
- const skillDir = join6(repoRoot, SKILL_DIR);
6846
- const skillPath = join6(skillDir, SKILL_FILE);
6847
- if (!existsSync11(skillDir)) {
7007
+ const skillDir = join7(repoRoot, SKILL_DIR);
7008
+ const skillPath = join7(skillDir, SKILL_FILE);
7009
+ if (!existsSync13(skillDir)) {
6848
7010
  mkdirSync4(skillDir, { recursive: true });
6849
7011
  }
6850
7012
  const content = `${SKILL_FRONTMATTER}
@@ -6860,10 +7022,10 @@ ${SKILL_BODY}
6860
7022
  });
6861
7023
  } else {
6862
7024
  output.success(`Installed MutagenT CLI skill`);
6863
- console.log(` ${chalk16.dim("Path:")} ${skillPath}`);
7025
+ console.log(` ${chalk21.dim("Path:")} ${skillPath}`);
6864
7026
  console.log("");
6865
- console.log(` ${chalk16.dim("This skill teaches coding agents how to use the MutagenT CLI.")}`);
6866
- console.log(` ${chalk16.dim("It will be automatically loaded by Claude Code when relevant triggers match.")}`);
7027
+ console.log(` ${chalk21.dim("This skill teaches coding agents how to use the MutagenT CLI.")}`);
7028
+ console.log(` ${chalk21.dim("It will be automatically loaded by Claude Code when relevant triggers match.")}`);
6867
7029
  }
6868
7030
  });
6869
7031
  return skills;
@@ -6871,8 +7033,8 @@ ${SKILL_BODY}
6871
7033
 
6872
7034
  // src/commands/usage.ts
6873
7035
  init_config();
6874
- import { Command as Command14 } from "commander";
6875
- import chalk17 from "chalk";
7036
+ import { Command as Command17 } from "commander";
7037
+ import chalk22 from "chalk";
6876
7038
  init_errors();
6877
7039
  init_sdk_client();
6878
7040
  var TRIAL_OPTIMIZATION_LIMIT = 5;
@@ -6886,10 +7048,10 @@ function renderProgressBar(used, limit, width = 30) {
6886
7048
  return `${bar} ${String(percent)}%`;
6887
7049
  }
6888
7050
  function createUsageCommand() {
6889
- const usage = new Command14("usage").description("Show resource counts and optimization run limits").addHelpText("after", `
7051
+ const usage = new Command17("usage").description("Show resource counts and optimization run limits").addHelpText("after", `
6890
7052
  Examples:
6891
- ${chalk17.dim("$")} mutagent usage
6892
- ${chalk17.dim("$")} mutagent usage --json
7053
+ ${chalk22.dim("$")} mutagent usage
7054
+ ${chalk22.dim("$")} mutagent usage --json
6893
7055
  `);
6894
7056
  usage.action(async () => {
6895
7057
  const isJson = getJsonFlag(usage);
@@ -6944,21 +7106,21 @@ Examples:
6944
7106
  });
6945
7107
  } else {
6946
7108
  console.log("");
6947
- console.log(chalk17.bold("\uD83D\uDCCA MutagenT Usage"));
6948
- console.log(chalk17.dim("─".repeat(45)));
7109
+ console.log(chalk22.bold("\uD83D\uDCCA MutagenT Usage"));
7110
+ console.log(chalk22.dim("─".repeat(45)));
6949
7111
  console.log("");
6950
- console.log(chalk17.bold("Resources:"));
6951
- console.log(` Prompts: ${chalk17.cyan(String(promptCount))}`);
6952
- console.log(` Datasets: ${chalk17.cyan(String(datasetCount))}`);
6953
- console.log(` Evaluations: ${chalk17.cyan(String(evaluationCount))}`);
7112
+ console.log(chalk22.bold("Resources:"));
7113
+ console.log(` Prompts: ${chalk22.cyan(String(promptCount))}`);
7114
+ console.log(` Datasets: ${chalk22.cyan(String(datasetCount))}`);
7115
+ console.log(` Evaluations: ${chalk22.cyan(String(evaluationCount))}`);
6954
7116
  console.log("");
6955
- console.log(chalk17.bold(`Optimization Runs (${chalk17.yellow("trial")} plan):`));
6956
- console.log(` Remaining: ${chalk17.cyan(String(optimizationRemaining))} / ${String(optimizationLimit)}`);
7117
+ console.log(chalk22.bold(`Optimization Runs (${chalk22.yellow("trial")} plan):`));
7118
+ console.log(` Remaining: ${chalk22.cyan(String(optimizationRemaining))} / ${String(optimizationLimit)}`);
6957
7119
  console.log(` ${renderProgressBar(optimizationUsed, optimizationLimit)}`);
6958
7120
  console.log("");
6959
- console.log(chalk17.yellow(` ⚠ ${String(optimizationRemaining)} optimization runs remaining`));
6960
- console.log(chalk17.dim(` ℹ Optimization run counts are approximate`));
6961
- console.log(` Upgrade: ${chalk17.underline(BILLING_URL)}`);
7121
+ console.log(chalk22.yellow(` ⚠ ${String(optimizationRemaining)} optimization runs remaining`));
7122
+ console.log(chalk22.dim(` ℹ Optimization run counts are approximate`));
7123
+ console.log(` Upgrade: ${chalk22.underline(BILLING_URL)}`);
6962
7124
  console.log("");
6963
7125
  }
6964
7126
  } catch (error) {
@@ -6976,12 +7138,12 @@ if (process.env.CLI_VERSION) {
6976
7138
  } else {
6977
7139
  try {
6978
7140
  const __dirname2 = dirname(fileURLToPath(import.meta.url));
6979
- const pkgPath = join7(__dirname2, "..", "..", "package.json");
6980
- const pkg = JSON.parse(readFileSync10(pkgPath, "utf-8"));
7141
+ const pkgPath = join8(__dirname2, "..", "..", "package.json");
7142
+ const pkg = JSON.parse(readFileSync11(pkgPath, "utf-8"));
6981
7143
  cliVersion = pkg.version ?? cliVersion;
6982
7144
  } catch {}
6983
7145
  }
6984
- var program = new Command15;
7146
+ var program = new Command18;
6985
7147
  program.name("mutagent").description(`MutagenT CLI - AI-native prompt optimization platform
6986
7148
 
6987
7149
  Documentation: https://docs.mutagent.io/cli
@@ -6990,46 +7152,46 @@ program.name("mutagent").description(`MutagenT CLI - AI-native prompt optimizati
6990
7152
  showGlobalOptions: true
6991
7153
  });
6992
7154
  program.addHelpText("after", `
6993
- ${chalk18.yellow("Non-Interactive Mode (CI/CD & Coding Agents):")}
6994
- export MUTAGENT_API_KEY=mt_... ${chalk18.dim("or")} --api-key mt_...
6995
- --json ${chalk18.dim("for structured output")} --non-interactive ${chalk18.dim("to disable prompts")}
6996
-
6997
- ${chalk18.yellow("Command Navigation:")}
6998
- mutagent auth login --browser ${chalk18.dim("Authenticate (OAuth)")}
6999
- mutagent auth status ${chalk18.dim("Check auth + workspace")}
7000
- mutagent init ${chalk18.dim("Initialize project (.mutagentrc.json)")}
7001
- mutagent explore ${chalk18.dim("Discover prompts in codebase")}
7002
- mutagent workspaces list --json ${chalk18.dim("List workspaces (verify ID)")}
7003
- mutagent config set workspace <id> ${chalk18.dim("Set active workspace")}
7004
- mutagent usage --json ${chalk18.dim("Check plan limits")}
7005
-
7006
- mutagent prompts create --help ${chalk18.dim("Upload prompt (read help first!)")}
7007
- mutagent prompts list --json ${chalk18.dim("List prompts")}
7008
- mutagent prompts get <id> --json ${chalk18.dim("Full prompt details + schemas")}
7009
-
7010
- mutagent prompts dataset add --help ${chalk18.dim("Upload dataset (read help first!)")}
7011
- mutagent prompts dataset list <id> ${chalk18.dim("List datasets")}
7012
-
7013
- mutagent prompts evaluation create --help ${chalk18.dim("Create eval (read help first!)")}
7014
- mutagent prompts evaluation create <id> --guided --json ${chalk18.dim("Guided eval workflow")}
7015
- mutagent prompts evaluation list <id> --json ${chalk18.dim("List evaluations")}
7016
-
7017
- mutagent prompts optimize start --help ${chalk18.dim("Run optimization (read help first!)")}
7018
- mutagent prompts optimize status <job-id> ${chalk18.dim("Poll progress")}
7019
- mutagent prompts optimize results <job-id> ${chalk18.dim("View scorecard")}
7020
-
7021
- mutagent integrate <framework> ${chalk18.dim("Framework integration guide")}
7022
- mutagent playground run <id> --input '{...}' ${chalk18.dim("Quick test")}
7023
-
7024
- ${chalk18.yellow("Workflow: Evaluate → Optimize:")}
7025
- 1. mutagent prompts create --help ${chalk18.dim("← read help")}
7026
- 2. mutagent prompts create ... --json ${chalk18.dim("← upload prompt with {variables}")}
7027
- 3. mutagent prompts dataset add --help ${chalk18.dim("← read help")}
7028
- 4. mutagent prompts dataset add <id> ... --json ${chalk18.dim("← upload dataset")}
7029
- 5. mutagent prompts evaluation create <id> --guided --json ${chalk18.dim("← guided eval")}
7155
+ ${chalk23.yellow("Non-Interactive Mode (CI/CD & Coding Agents):")}
7156
+ export MUTAGENT_API_KEY=mt_... ${chalk23.dim("or")} --api-key mt_...
7157
+ --json ${chalk23.dim("for structured output")} --non-interactive ${chalk23.dim("to disable prompts")}
7158
+
7159
+ ${chalk23.yellow("Command Navigation:")}
7160
+ mutagent auth login --browser ${chalk23.dim("Authenticate (OAuth)")}
7161
+ mutagent auth status ${chalk23.dim("Check auth + workspace")}
7162
+ mutagent init ${chalk23.dim("Initialize project (.mutagentrc.json)")}
7163
+ mutagent explore ${chalk23.dim("Discover prompts in codebase")}
7164
+ mutagent workspaces list --json ${chalk23.dim("List workspaces (verify ID)")}
7165
+ mutagent config set workspace <id> ${chalk23.dim("Set active workspace")}
7166
+ mutagent usage --json ${chalk23.dim("Check plan limits")}
7167
+
7168
+ mutagent prompts create --help ${chalk23.dim("Upload prompt (read help first!)")}
7169
+ mutagent prompts list --json ${chalk23.dim("List prompts")}
7170
+ mutagent prompts get <id> --json ${chalk23.dim("Full prompt details + schemas")}
7171
+
7172
+ mutagent prompts dataset add --help ${chalk23.dim("Upload dataset (read help first!)")}
7173
+ mutagent prompts dataset list <id> ${chalk23.dim("List datasets")}
7174
+
7175
+ mutagent prompts evaluation create --help ${chalk23.dim("Create eval (read help first!)")}
7176
+ mutagent prompts evaluation create <id> --guided --json ${chalk23.dim("Guided eval workflow")}
7177
+ mutagent prompts evaluation list <id> --json ${chalk23.dim("List evaluations")}
7178
+
7179
+ mutagent prompts optimize start --help ${chalk23.dim("Run optimization (read help first!)")}
7180
+ mutagent prompts optimize status <job-id> ${chalk23.dim("Poll progress")}
7181
+ mutagent prompts optimize results <job-id> ${chalk23.dim("View scorecard")}
7182
+
7183
+ mutagent integrate <framework> ${chalk23.dim("Framework integration guide")}
7184
+ mutagent playground run <id> --input '{...}' ${chalk23.dim("Quick test")}
7185
+
7186
+ ${chalk23.yellow("Workflow: Evaluate → Optimize:")}
7187
+ 1. mutagent prompts create --help ${chalk23.dim("← read help")}
7188
+ 2. mutagent prompts create ... --json ${chalk23.dim("← upload prompt with {variables} + inputSchema")}
7189
+ 3. mutagent prompts dataset add --help ${chalk23.dim("← read help")}
7190
+ 4. mutagent prompts dataset add <id> ... --json ${chalk23.dim("← upload dataset")}
7191
+ 5. mutagent prompts evaluation create <id> --guided --json ${chalk23.dim("← guided eval")}
7030
7192
  6. mutagent prompts optimize start <id> --dataset <d> --evaluation <e> --json
7031
7193
 
7032
- ${chalk18.yellow("AI Agent Rules (MANDATORY for coding agents):")}
7194
+ ${chalk23.yellow("AI Agent Rules (MANDATORY for coding agents):")}
7033
7195
  1. EVERY command MUST include --json (no exceptions)
7034
7196
  2. Run <command> --help BEFORE first use of any command
7035
7197
  3. Use --guided --json for evaluation creation (NEVER --guided alone)
@@ -7038,9 +7200,9 @@ ${chalk18.yellow("AI Agent Rules (MANDATORY for coding agents):")}
7038
7200
  6. Use {single_braces} for template variables in prompts
7039
7201
  7. Collect evaluation rubrics from the user — NEVER auto-generate
7040
7202
  ${!hasCredentials() ? `
7041
- ` + chalk18.yellow(" Warning: Not authenticated. Run: mutagent auth login --browser") + `
7203
+ ` + chalk23.yellow(" Warning: Not authenticated. Run: mutagent auth login --browser") + `
7042
7204
  ` : ""}${!hasRcConfig() ? `
7043
- ` + chalk18.green(" Get started: mutagent init") + `
7205
+ ` + chalk23.green(" Get started: mutagent init") + `
7044
7206
  ` : ""}`);
7045
7207
  program.hook("preAction", (thisCommand) => {
7046
7208
  const globalOpts = thisCommand.optsWithGlobals();
@@ -7070,5 +7232,5 @@ program.addCommand(createSkillsCommand());
7070
7232
  program.addCommand(createUsageCommand());
7071
7233
  program.parse();
7072
7234
 
7073
- //# debugId=55FA8E38F306DE3764756E2164756E21
7235
+ //# debugId=E58AAC8256B9F1B664756E2164756E21
7074
7236
  //# sourceMappingURL=cli.js.map