@mutagent/cli 0.1.188 → 0.1.189
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 +98 -16
- package/dist/bin/cli.js.map +5 -5
- package/package.json +1 -1
package/dist/bin/cli.js
CHANGED
|
@@ -5029,6 +5029,45 @@ init_errors();
|
|
|
5029
5029
|
|
|
5030
5030
|
// src/lib/scorecard.ts
|
|
5031
5031
|
import chalk11 from "chalk";
|
|
5032
|
+
function extractPromptText(p) {
|
|
5033
|
+
if (!p)
|
|
5034
|
+
return "";
|
|
5035
|
+
if (p.rawPrompt)
|
|
5036
|
+
return p.rawPrompt;
|
|
5037
|
+
if (p.systemPrompt || p.humanPrompt) {
|
|
5038
|
+
const parts = [];
|
|
5039
|
+
if (p.systemPrompt)
|
|
5040
|
+
parts.push(`[SYSTEM]
|
|
5041
|
+
${p.systemPrompt}`);
|
|
5042
|
+
if (p.humanPrompt)
|
|
5043
|
+
parts.push(`[USER]
|
|
5044
|
+
${p.humanPrompt}`);
|
|
5045
|
+
return parts.join(`
|
|
5046
|
+
|
|
5047
|
+
`);
|
|
5048
|
+
}
|
|
5049
|
+
if (p.messages) {
|
|
5050
|
+
let arr = null;
|
|
5051
|
+
if (Array.isArray(p.messages)) {
|
|
5052
|
+
arr = p.messages;
|
|
5053
|
+
} else if (typeof p.messages === "string") {
|
|
5054
|
+
try {
|
|
5055
|
+
const parsed = JSON.parse(p.messages);
|
|
5056
|
+
if (Array.isArray(parsed))
|
|
5057
|
+
arr = parsed;
|
|
5058
|
+
} catch {
|
|
5059
|
+
return p.messages;
|
|
5060
|
+
}
|
|
5061
|
+
}
|
|
5062
|
+
if (arr && arr.length > 0) {
|
|
5063
|
+
return arr.map((m) => `[${m.role.toUpperCase()}]
|
|
5064
|
+
${m.content}`).join(`
|
|
5065
|
+
|
|
5066
|
+
`);
|
|
5067
|
+
}
|
|
5068
|
+
}
|
|
5069
|
+
return "";
|
|
5070
|
+
}
|
|
5032
5071
|
function formatScoreChange(before, after) {
|
|
5033
5072
|
if (before === undefined || after === undefined)
|
|
5034
5073
|
return "";
|
|
@@ -5060,8 +5099,10 @@ function renderScorecard(data) {
|
|
|
5060
5099
|
const originalScore = data.originalScore;
|
|
5061
5100
|
const bestScore = data.bestScore;
|
|
5062
5101
|
const iterations = data.iterationsCompleted ?? job.config?.maxIterations ?? 0;
|
|
5063
|
-
const
|
|
5064
|
-
const
|
|
5102
|
+
const _rawOriginalText = data.originalPromptText || extractPromptText(data.originalPrompt) || extractPromptText(prompt);
|
|
5103
|
+
const originalText = _rawOriginalText || "(original prompt)";
|
|
5104
|
+
const _rawOptimizedText = data.mutatedPromptText || extractPromptText(prompt);
|
|
5105
|
+
const optimizedText = _rawOptimizedText || "(optimized prompt)";
|
|
5065
5106
|
console.log("");
|
|
5066
5107
|
console.log(topBorder);
|
|
5067
5108
|
console.log(line(chalk11.bold("Optimization Results")));
|
|
@@ -5303,10 +5344,32 @@ function statusDirective(status, promptId) {
|
|
|
5303
5344
|
}
|
|
5304
5345
|
function showPromptDiff(original, optimized) {
|
|
5305
5346
|
console.log("");
|
|
5306
|
-
console.log(chalk11.bold(" Prompt Diff:"));
|
|
5347
|
+
console.log(chalk11.bold(" Prompt Diff (BEFORE → AFTER):"));
|
|
5307
5348
|
console.log("");
|
|
5308
|
-
|
|
5309
|
-
|
|
5349
|
+
if (original === null && optimized === null) {
|
|
5350
|
+
console.log(chalk11.dim(" (no prompt content available — state snapshot may be absent)"));
|
|
5351
|
+
console.log("");
|
|
5352
|
+
return;
|
|
5353
|
+
}
|
|
5354
|
+
const beforeLines = (original ?? "").split(`
|
|
5355
|
+
`);
|
|
5356
|
+
const afterLines = (optimized ?? "").split(`
|
|
5357
|
+
`);
|
|
5358
|
+
console.log(chalk11.dim(" BEFORE:"));
|
|
5359
|
+
for (const ln of beforeLines) {
|
|
5360
|
+
console.log(chalk11.red(` - ${ln}`));
|
|
5361
|
+
}
|
|
5362
|
+
console.log("");
|
|
5363
|
+
console.log(chalk11.dim(" AFTER:"));
|
|
5364
|
+
for (const ln of afterLines) {
|
|
5365
|
+
console.log(chalk11.green(` + ${ln}`));
|
|
5366
|
+
}
|
|
5367
|
+
if (original === null) {
|
|
5368
|
+
console.log("");
|
|
5369
|
+
console.log(chalk11.yellow(" Note: BEFORE content unavailable — source prompt may store content in a different field"));
|
|
5370
|
+
console.log(chalk11.dim(" Hint: check rawPrompt / systemPrompt / humanPrompt / messages on the original prompt via:"));
|
|
5371
|
+
console.log(chalk11.dim(" mutagent prompts get <source-prompt-id> --json"));
|
|
5372
|
+
}
|
|
5310
5373
|
console.log("");
|
|
5311
5374
|
}
|
|
5312
5375
|
|
|
@@ -5874,8 +5937,9 @@ function line2(text) {
|
|
|
5874
5937
|
return `│ ${pad2(text, BOX_WIDTH2 - 2)} │`;
|
|
5875
5938
|
}
|
|
5876
5939
|
function renderIterationBoundaryCard(opts) {
|
|
5877
|
-
const { iteration, maxIterations,
|
|
5878
|
-
const
|
|
5940
|
+
const { iteration, maxIterations, baselineScore } = opts;
|
|
5941
|
+
const bestScore = opts.bestScore ?? undefined;
|
|
5942
|
+
const delta = baselineScore != null && bestScore !== undefined ? bestScore - baselineScore : 0;
|
|
5879
5943
|
const deltaStr = delta >= 0 ? `+${delta.toFixed(2)}` : delta.toFixed(2);
|
|
5880
5944
|
const improving = delta > 0.001;
|
|
5881
5945
|
const statusStr = improving ? "Improving" : "Converging";
|
|
@@ -5883,9 +5947,10 @@ function renderIterationBoundaryCard(opts) {
|
|
|
5883
5947
|
const remaining = BOX_WIDTH2 - title.length - 1;
|
|
5884
5948
|
const topBorder2 = `┌─${title}${"─".repeat(Math.max(0, remaining))}┐`;
|
|
5885
5949
|
const bottomBorder2 = `└${"─".repeat(BOX_WIDTH2)}┘`;
|
|
5950
|
+
const bestScoreStr = bestScore !== undefined ? bestScore.toFixed(2) : "N/A";
|
|
5886
5951
|
const lines = [];
|
|
5887
5952
|
lines.push(topBorder2);
|
|
5888
|
-
lines.push(line2(`Best Score: ${
|
|
5953
|
+
lines.push(line2(`Best Score: ${bestScoreStr} (${deltaStr} from baseline)`));
|
|
5889
5954
|
lines.push(line2(`Status: ${statusStr}`));
|
|
5890
5955
|
lines.push(bottomBorder2);
|
|
5891
5956
|
return lines.join(`
|
|
@@ -5936,10 +6001,11 @@ async function startWatchStream(jobId, isJson, maxIterations, baselineScore) {
|
|
|
5936
6001
|
}
|
|
5937
6002
|
},
|
|
5938
6003
|
onJobComplete: (finalScore) => {
|
|
6004
|
+
const scoreStr = finalScore != null ? finalScore.toFixed(2) : "N/A";
|
|
5939
6005
|
if (isJson) {
|
|
5940
|
-
console.log(JSON.stringify({ type: "job_complete", finalScore }));
|
|
6006
|
+
console.log(JSON.stringify({ type: "job_complete", finalScore: finalScore ?? null }));
|
|
5941
6007
|
} else {
|
|
5942
|
-
console.log(chalk14.green(`✓ Optimization complete! Final score: ${
|
|
6008
|
+
console.log(chalk14.green(`✓ Optimization complete! Final score: ${scoreStr}`));
|
|
5943
6009
|
console.log(chalk14.dim(` View results: mutagent prompts optimize results ${jobId}`));
|
|
5944
6010
|
}
|
|
5945
6011
|
resolve3();
|
|
@@ -6017,25 +6083,35 @@ async function watchAction(jobId, options, parentCommand) {
|
|
|
6017
6083
|
console.log(chalk14.dim(`Watching for live updates...
|
|
6018
6084
|
`));
|
|
6019
6085
|
}
|
|
6020
|
-
await startWatchStream(jobId, isJson, status.maxIterations, status.bestScore);
|
|
6086
|
+
await startWatchStream(jobId, isJson, status.maxIterations, status.bestScore ?? undefined);
|
|
6021
6087
|
break;
|
|
6022
|
-
case "failed":
|
|
6088
|
+
case "failed": {
|
|
6089
|
+
const rawStatus = status;
|
|
6090
|
+
const failureMode = rawStatus.failureMode;
|
|
6091
|
+
const jobError = rawStatus.error;
|
|
6023
6092
|
if (isJson) {
|
|
6024
6093
|
output.output({
|
|
6025
6094
|
success: false,
|
|
6026
|
-
error: "Optimization job failed",
|
|
6095
|
+
error: jobError ?? "Optimization job failed",
|
|
6027
6096
|
status: status.status,
|
|
6028
6097
|
jobId,
|
|
6098
|
+
...failureMode ? { failureMode } : {},
|
|
6029
6099
|
message: status.message
|
|
6030
6100
|
});
|
|
6031
6101
|
} else {
|
|
6032
6102
|
console.error(chalk14.red(`✗ Optimization job ${jobId} failed.`));
|
|
6033
|
-
if (
|
|
6103
|
+
if (failureMode) {
|
|
6104
|
+
console.error(chalk14.dim(` Failure mode: ${failureMode}`));
|
|
6105
|
+
}
|
|
6106
|
+
if (jobError) {
|
|
6107
|
+
console.error(chalk14.dim(` ${jobError}`));
|
|
6108
|
+
} else if (status.message) {
|
|
6034
6109
|
console.error(chalk14.dim(` ${status.message}`));
|
|
6035
6110
|
}
|
|
6036
6111
|
}
|
|
6037
6112
|
process.exitCode = 1;
|
|
6038
6113
|
break;
|
|
6114
|
+
}
|
|
6039
6115
|
case "cancelled":
|
|
6040
6116
|
if (isJson) {
|
|
6041
6117
|
output.output({
|
|
@@ -6578,7 +6654,11 @@ ${chalk16.cyan("Conceptual help (scorecard interpretation, nextAction): .claude/
|
|
|
6578
6654
|
if (options.diff) {
|
|
6579
6655
|
const original = resultData.originalPrompt;
|
|
6580
6656
|
const optimized = resultData.prompt;
|
|
6581
|
-
|
|
6657
|
+
const _beforeRaw = resultData.originalPromptText || extractPromptText(original);
|
|
6658
|
+
const beforeText = _beforeRaw || null;
|
|
6659
|
+
const _afterRaw = resultData.mutatedPromptText || extractPromptText(optimized);
|
|
6660
|
+
const afterText = _afterRaw || null;
|
|
6661
|
+
showPromptDiff(beforeText, afterText);
|
|
6582
6662
|
}
|
|
6583
6663
|
if (options.apply && isCompleted) {
|
|
6584
6664
|
const optimizedPrompt = resultData.prompt;
|
|
@@ -6592,6 +6672,8 @@ ${chalk16.cyan("Conceptual help (scorecard interpretation, nextAction): .claude/
|
|
|
6592
6672
|
updateData.humanPrompt = optimizedPrompt.humanPrompt;
|
|
6593
6673
|
if (optimizedPrompt.rawPrompt)
|
|
6594
6674
|
updateData.rawPrompt = optimizedPrompt.rawPrompt;
|
|
6675
|
+
if (optimizedPrompt.messages)
|
|
6676
|
+
updateData.messages = optimizedPrompt.messages;
|
|
6595
6677
|
await client.updatePrompt(promptIdStr, updateData);
|
|
6596
6678
|
output.success("Optimized prompt applied as new version!");
|
|
6597
6679
|
output.info(`View prompt: ${promptLink(promptIdStr)}`);
|
|
@@ -13678,5 +13760,5 @@ if (isInteractive && !isSkillCommand) {
|
|
|
13678
13760
|
}
|
|
13679
13761
|
program.parse();
|
|
13680
13762
|
|
|
13681
|
-
//# debugId=
|
|
13763
|
+
//# debugId=6F6C59E53DD7DB6E64756E2164756E21
|
|
13682
13764
|
//# sourceMappingURL=cli.js.map
|