forked from openai/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
219 lines (197 loc) · 7.18 KB
/
Copy pathcli.js
File metadata and controls
219 lines (197 loc) · 7.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
import path from "node:path";
import { compareResults } from "./core/compare.js";
import { analyzePath, explainBudget, recommendMeasures } from "./core/analyze.js";
import { initializeBenchmark, runBenchmark } from "./core/benchmark.js";
import { buildWorkflowGuide } from "./core/workflow-guide.js";
import { readJson, writeText } from "./lib/files.js";
import { renderPayload } from "./renderers/index.js";
function usage() {
return `Plugin Eval helps first-time skill authors start from chat and keep the workflow local-first.
Start here:
plugin-eval start <path> [--request "<chat request>"] [--goal evaluate|budget|measure|benchmark|next] [--format json|markdown|html] [--output <file>]
Core workflows:
plugin-eval analyze <path> [--format json|markdown|html] [--output <file>] [--metric-pack <manifest.json>] [--observed-usage <file>] [--brief-out <file>]
plugin-eval explain-budget <path> [--format json|markdown] [--output <file>]
plugin-eval measurement-plan <path> [--format json|markdown] [--observed-usage <file>] [--output <file>]
plugin-eval init-benchmark <path> [--output <benchmark.json>] [--model <model>] [--format json|markdown]
plugin-eval benchmark <path> [--config <benchmark.json>] [--usage-out <usage.jsonl>] [--result-out <result.json>] [--model <model>] [--format json|markdown|html] [--output <file>]
Reports:
plugin-eval report <result.json> [--format json|markdown|html] [--output <file>]
plugin-eval compare <before.json> <after.json> [--format json|markdown|html] [--output <file>]
Chat-first examples:
plugin-eval start ./skills/my-skill --request "evaluate this skill" --format markdown
plugin-eval start ./skills/my-skill --request "measure the real token usage of this skill" --format markdown
plugin-eval start ./plugins/my-plugin --request "help me benchmark this plugin" --format markdown
plugin-eval start ./skills/my-skill --request "what should I run next?" --format markdown
Compatibility aliases:
guide -> start
recommend-measures -> measurement-plan
`;
}
function parseOptions(argv) {
const positional = [];
const options = {
format: "json",
output: null,
metricPackManifests: [],
observedUsagePaths: [],
configPath: null,
usageOutPath: null,
resultOutPath: null,
model: null,
goal: null,
request: null,
dryRun: false,
briefOut: null,
};
for (let index = 0; index < argv.length; index += 1) {
const arg = argv[index];
if (arg === "--format") {
options.format = argv[index + 1];
index += 1;
} else if (arg === "--output") {
options.output = argv[index + 1];
index += 1;
} else if (arg === "--metric-pack") {
options.metricPackManifests.push(argv[index + 1]);
index += 1;
} else if (arg === "--observed-usage") {
options.observedUsagePaths.push(argv[index + 1]);
index += 1;
} else if (arg === "--config") {
options.configPath = argv[index + 1];
index += 1;
} else if (arg === "--usage-out") {
options.usageOutPath = argv[index + 1];
index += 1;
} else if (arg === "--result-out") {
options.resultOutPath = argv[index + 1];
index += 1;
} else if (arg === "--model") {
options.model = argv[index + 1];
index += 1;
} else if (arg === "--goal") {
options.goal = argv[index + 1];
index += 1;
} else if (arg === "--request") {
options.request = argv[index + 1];
index += 1;
} else if (arg === "--dry-run") {
options.dryRun = true;
} else if (arg === "--brief-out") {
options.briefOut = argv[index + 1];
index += 1;
} else if (arg === "--help" || arg === "-h") {
options.help = true;
} else {
positional.push(arg);
}
}
return { positional, options };
}
async function emit(payload, format, output) {
const rendered = renderPayload(payload, format);
if (output) {
await writeText(path.resolve(output), rendered);
return;
}
process.stdout.write(rendered);
}
export async function runCli(argv) {
const [command, ...rest] = argv;
if (!command || command === "--help" || command === "-h") {
process.stdout.write(usage());
return;
}
const { positional, options } = parseOptions(rest);
if (options.help) {
process.stdout.write(usage());
return;
}
if (command === "analyze") {
if (positional.length < 1) {
throw new Error("Missing target path.\n\n" + usage());
}
const result = await analyzePath(positional[0], {
metricPackManifests: options.metricPackManifests,
observedUsagePaths: options.observedUsagePaths,
});
if (options.briefOut) {
await writeText(path.resolve(options.briefOut), `${JSON.stringify(result.improvementBrief, null, 2)}\n`);
}
await emit(result, options.format, options.output);
return;
}
if (command === "report") {
if (positional.length < 1) {
throw new Error("Missing result.json path.\n\n" + usage());
}
const result = await readJson(path.resolve(positional[0]));
await emit(result, options.format, options.output);
return;
}
if (command === "compare") {
if (positional.length < 2) {
throw new Error("Missing before/after result paths.\n\n" + usage());
}
const before = await readJson(path.resolve(positional[0]));
const after = await readJson(path.resolve(positional[1]));
await emit(compareResults(before, after), options.format, options.output);
return;
}
if (command === "start" || command === "guide") {
if (positional.length < 1) {
throw new Error("Missing target path.\n\n" + usage());
}
const payload = await buildWorkflowGuide(positional[0], {
goal: options.goal,
request: options.request,
});
await emit(payload, options.format, options.output);
return;
}
if (command === "explain-budget") {
if (positional.length < 1) {
throw new Error("Missing target path.\n\n" + usage());
}
const payload = await explainBudget(positional[0]);
await emit(payload, options.format, options.output);
return;
}
if (command === "measurement-plan" || command === "recommend-measures") {
if (positional.length < 1) {
throw new Error("Missing target path.\n\n" + usage());
}
const payload = await recommendMeasures(positional[0], {
observedUsagePaths: options.observedUsagePaths,
});
await emit(payload, options.format, options.output);
return;
}
if (command === "init-benchmark") {
if (positional.length < 1) {
throw new Error("Missing target path.\n\n" + usage());
}
const payload = await initializeBenchmark(positional[0], {
outputPath: options.output,
model: options.model,
});
await emit(payload, options.format, null);
return;
}
if (command === "benchmark") {
if (positional.length < 1) {
throw new Error("Missing target path.\n\n" + usage());
}
const payload = await runBenchmark(positional[0], {
configPath: options.configPath,
usageOutPath: options.usageOutPath,
resultOutPath: options.resultOutPath,
model: options.model,
dryRun: options.dryRun,
});
await emit(payload, options.format, options.output);
return;
}
throw new Error(`Unknown command: ${command}\n\n${usage()}`);
}