vectorbench 3.0.0 → 3.0.3
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/.env.example +2 -1
- package/README.md +4 -3
- package/bin/vectorbench.mjs +1 -1
- package/harness/claude-code.mjs +82 -34
- package/harness/grok-build.mjs +233 -0
- package/package.json +2 -1
- package/scripts/doctor.mjs +5 -3
- package/scripts/harness.mjs +52 -31
- package/scripts/partner.mjs +47 -5
- package/scripts/sheet.mjs +75 -0
package/.env.example
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# Keys for drawing through a provider's API (`vectorbench draw`, `npm run
|
|
2
2
|
# partner`, `npm run generate`). Copy to .env (which git ignores) and fill in
|
|
3
3
|
# the providers you want to run; models whose key is missing are skipped. A
|
|
4
|
-
# Claude model on Claude Code,
|
|
4
|
+
# Claude model on Claude Code, an OpenAI model on Codex, or an xAI model on
|
|
5
|
+
# Grok Build, needs no key.
|
|
5
6
|
ANTHROPIC_API_KEY=
|
|
6
7
|
OPENAI_API_KEY=
|
|
7
8
|
GEMINI_API_KEY=
|
package/README.md
CHANGED
|
@@ -107,9 +107,10 @@ Then ask:
|
|
|
107
107
|
`--paid` allows a run on API credits, which you pay for. For a Claude model
|
|
108
108
|
add `--api` as well, for example
|
|
109
109
|
`--model claude-opus-5-5 --prompt chessboard --api --paid`. Without `--api`
|
|
110
|
-
Claude models run through Claude Code on a Claude subscription
|
|
111
|
-
`--codex` OpenAI models run through the Codex CLI on a ChatGPT plan
|
|
112
|
-
|
|
110
|
+
Claude models run through Claude Code on a Claude subscription; with
|
|
111
|
+
`--codex` OpenAI models run through the Codex CLI on a ChatGPT plan, and
|
|
112
|
+
with `--grok-build` xAI models run through Grok Build on a Grok plan. Each
|
|
113
|
+
needs that tool installed and signed in.
|
|
113
114
|
|
|
114
115
|
The drawing is written to `harness/trial/chessboard/gpt-6.2-astra.svg`. The
|
|
115
116
|
log next to it, in `harness/trial/log/`, records the request, the reasoning
|
package/bin/vectorbench.mjs
CHANGED
|
@@ -16,7 +16,7 @@ const { version } = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf8'))
|
|
|
16
16
|
const HELP = `vectorbench ${version}: draw VectorBench's prompts with your own model (https://vectorbench.ai)
|
|
17
17
|
|
|
18
18
|
vectorbench draw --model <id> draw every prompt with one model and zip the drawings to send
|
|
19
|
-
(--prompt <id> for one first; \`vectorbench draw\`
|
|
19
|
+
(--prompt <id> for one first; \`vectorbench draw --help\` lists the options)
|
|
20
20
|
vectorbench doctor check this machine has what a drawing run needs
|
|
21
21
|
vectorbench prompts list the prompts
|
|
22
22
|
vectorbench dev run the site locally with made-up data (in a clone of the repository)
|
package/harness/claude-code.mjs
CHANGED
|
@@ -71,11 +71,30 @@ function readArguments(input) {
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
/**
|
|
74
|
-
*
|
|
74
|
+
* What differs between the agents that speak this stream format. Claude Code
|
|
75
|
+
* is the default; harness/grok-build.mjs passes its own.
|
|
76
|
+
*/
|
|
77
|
+
const CLAUDE_CODE = {
|
|
78
|
+
by: 'claude-code',
|
|
79
|
+
name: 'Claude Code',
|
|
80
|
+
/** The tools a session may offer the model. */
|
|
81
|
+
allowed: (tool) => [toolName(tool)],
|
|
82
|
+
/** Whether our tool has to be in the session's first list of tools. */
|
|
83
|
+
listsOurTool: true,
|
|
84
|
+
/** Whether `apiKeySource` says the plan pays, not a key. */
|
|
85
|
+
onPlan: (source) => !source || source === 'none',
|
|
86
|
+
/** A tool_use block's arguments for our tool, or null when the call is one the agent answers itself. */
|
|
87
|
+
unwrap: (block, input) => input,
|
|
88
|
+
/** Whether the agent runs a call as soon as its block is whole, before the reply has ended. */
|
|
89
|
+
eager: false,
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* One run's state, fed the agent's stream-json events (`handle`) and our
|
|
75
94
|
* tool's calls (`call`). It decides when the run is over, the way loop.mjs
|
|
76
95
|
* does, and calls `end()` once when it is; `say(text)` sends a user message.
|
|
77
96
|
*/
|
|
78
|
-
export function session({ tool, sandbox, limits, say, end, clock = Date.now }) {
|
|
97
|
+
export function session({ tool, sandbox, limits, say, end, clock = Date.now, agent = CLAUDE_CODE }) {
|
|
79
98
|
const startedAt = clock();
|
|
80
99
|
const replies = [];
|
|
81
100
|
const owners = new Map(); // tool_use id → its reply
|
|
@@ -117,7 +136,10 @@ export function session({ tool, sandbox, limits, say, end, clock = Date.now }) {
|
|
|
117
136
|
|
|
118
137
|
// Every call of a finished reply has its result: where the loop would ask again.
|
|
119
138
|
const settle = (reply) => {
|
|
120
|
-
if (exit || failure || !reply.stopped
|
|
139
|
+
if (exit || failure || !reply.stopped) return;
|
|
140
|
+
// A reply that only used the agent's own tools: the agent asks again once they are answered.
|
|
141
|
+
if (!reply.calls.length && reply.own.length && reply.own.every((id) => reply.results.has(id))) return void overBudget();
|
|
142
|
+
if (!reply.calls.length) return;
|
|
121
143
|
if (reply.calls.some((call) => !reply.results.has(call.id))) return;
|
|
122
144
|
if (submitted) finish('submitted');
|
|
123
145
|
else overBudget();
|
|
@@ -131,31 +153,52 @@ export function session({ tool, sandbox, limits, say, end, clock = Date.now }) {
|
|
|
131
153
|
finish('replies');
|
|
132
154
|
return;
|
|
133
155
|
}
|
|
134
|
-
current = { n: replies.length + 1, id: message.id ?? null, model: message.model ?? null, blocks: [], json: [], stop: null, counts: message.usage ?? {}, calls: [], uses: [], results: new Map(), notes: [], stopped: false };
|
|
156
|
+
current = { n: replies.length + 1, id: message.id ?? null, model: message.model ?? null, blocks: [], json: [], stop: null, counts: message.usage ?? {}, calls: [], uses: [], own: [], results: new Map(), notes: [], stopped: false };
|
|
135
157
|
replies.push(current);
|
|
136
158
|
}
|
|
137
159
|
|
|
160
|
+
// The call a tool_use block makes of our tool, or null when the agent answers it itself.
|
|
161
|
+
function callOf(reply, index) {
|
|
162
|
+
const block = reply.blocks[index];
|
|
163
|
+
let input = block.input ?? {};
|
|
164
|
+
if (reply.json[index]) {
|
|
165
|
+
try {
|
|
166
|
+
input = JSON.parse(reply.json[index]);
|
|
167
|
+
} catch {
|
|
168
|
+
block.partial_json = reply.json[index];
|
|
169
|
+
return { id: block.id, error: `The arguments of that call were not valid JSON, so nothing was run. They began: ${reply.json[index].slice(0, 200)}` };
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
block.input = input;
|
|
173
|
+
const ours = agent.unwrap(block, input, tool);
|
|
174
|
+
if (ours === null) return null;
|
|
175
|
+
const read = readArguments(ours);
|
|
176
|
+
return read.error ? { id: block.id, error: read.error } : { id: block.id, command: read.command };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// An eager agent calls us when the block is whole: the call is known then, with the reply still open.
|
|
180
|
+
function blockEnded(reply, index) {
|
|
181
|
+
if (!agent.eager || reply.blocks[index]?.type !== 'tool_use') return;
|
|
182
|
+
const call = callOf(reply, index);
|
|
183
|
+
if (!call) return;
|
|
184
|
+
reply.all = [...(reply.all ?? []), call];
|
|
185
|
+
reply.calls = reply.all;
|
|
186
|
+
reply.budget ??= budgetLine(reply.n, startedAt, limits, clock());
|
|
187
|
+
poke();
|
|
188
|
+
}
|
|
189
|
+
|
|
138
190
|
function stopped(reply) {
|
|
139
191
|
reply.stopped = true;
|
|
140
192
|
reply.at = new Date(clock()).toISOString();
|
|
141
193
|
reply.ended = ENDED[reply.stop] ?? 'truncated';
|
|
142
|
-
reply.budget
|
|
194
|
+
reply.budget ??= budgetLine(reply.n, startedAt, limits, clock());
|
|
143
195
|
const calls = [];
|
|
196
|
+
reply.own = [];
|
|
144
197
|
reply.blocks.forEach((block, index) => {
|
|
145
198
|
if (block?.type !== 'tool_use') return;
|
|
146
|
-
|
|
147
|
-
if (
|
|
148
|
-
|
|
149
|
-
input = JSON.parse(reply.json[index]);
|
|
150
|
-
} catch {
|
|
151
|
-
calls.push({ id: block.id, error: `The arguments of that call were not valid JSON, so nothing was run. They began: ${reply.json[index].slice(0, 200)}` });
|
|
152
|
-
block.partial_json = reply.json[index];
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
block.input = input;
|
|
157
|
-
const read = readArguments(input);
|
|
158
|
-
calls.push(read.error ? { id: block.id, error: read.error } : { id: block.id, command: read.command });
|
|
199
|
+
const call = callOf(reply, index);
|
|
200
|
+
if (call) calls.push(call);
|
|
201
|
+
else reply.own.push(block.id);
|
|
159
202
|
});
|
|
160
203
|
reply.uses = calls.map((call) => call.id);
|
|
161
204
|
reply.all = calls;
|
|
@@ -165,8 +208,11 @@ export function session({ tool, sandbox, limits, say, end, clock = Date.now }) {
|
|
|
165
208
|
|
|
166
209
|
if (reply.ended === 'refused') return finish('refused');
|
|
167
210
|
if (reply.ended === 'truncated')
|
|
168
|
-
reply.notes.push({ role: 'harness', by:
|
|
211
|
+
reply.notes.push({ role: 'harness', by: agent.by, text: `The reply hit the output cap. ${agent.name} goes on with such a turn itself, asking the model in its own words to resume.` });
|
|
212
|
+
if (reply.own.length) reply.notes.push({ role: 'harness', by: agent.by, text: `This reply used ${agent.name}'s own tools (${reply.blocks.filter((block) => reply.own.includes(block?.id)).map((block) => block.name).join(', ')}), which ${agent.name} answered itself.` });
|
|
169
213
|
if (reply.calls.length) misses = 0;
|
|
214
|
+
// A reply spent on the agent's own tools ran no command, but it is not a reply without a call.
|
|
215
|
+
else if (reply.own.length && reply.ended === 'calls') poke();
|
|
170
216
|
else if (++misses >= limits.misses) return finish('no-commands');
|
|
171
217
|
poke();
|
|
172
218
|
settle(reply);
|
|
@@ -190,6 +236,8 @@ export function session({ tool, sandbox, limits, say, end, clock = Date.now }) {
|
|
|
190
236
|
else if (delta.type === 'thinking_delta') block.thinking = (block.thinking ?? '') + delta.thinking;
|
|
191
237
|
else if (delta.type === 'signature_delta') block.signature = delta.signature;
|
|
192
238
|
else if (delta.type === 'input_json_delta') reply.json[event.index] = (reply.json[event.index] ?? '') + delta.partial_json;
|
|
239
|
+
} else if (event.type === 'content_block_stop') {
|
|
240
|
+
blockEnded(reply, event.index);
|
|
193
241
|
} else if (event.type === 'message_delta') {
|
|
194
242
|
if (event.delta?.stop_reason) reply.stop = event.delta.stop_reason;
|
|
195
243
|
const counted = Object.entries(event.usage ?? {}).filter(([, value]) => value != null);
|
|
@@ -207,9 +255,9 @@ export function session({ tool, sandbox, limits, say, end, clock = Date.now }) {
|
|
|
207
255
|
if (result.is_error || result.subtype !== 'success') {
|
|
208
256
|
if (result.subtype === 'error_max_turns' && replies.length >= limits.replies) return finish('replies');
|
|
209
257
|
const why = result.result || (result.errors ?? []).join('; ') || result.subtype || 'no answer';
|
|
210
|
-
return fail(new ProviderError(
|
|
258
|
+
return fail(new ProviderError(`${agent.name}: ${why}`, { fatal: /authenticate|log ?in|signed in|time limit|usage limit/i.test(why) }));
|
|
211
259
|
}
|
|
212
|
-
if (!last || last.calls.length) return fail(new ProviderError(
|
|
260
|
+
if (!last || last.calls.length) return fail(new ProviderError(`${agent.name} ended the turn before the reply's results were back (${result.stop_reason ?? result.subtype})`));
|
|
213
261
|
if (overBudget()) return;
|
|
214
262
|
last.said = last.ended === 'truncated' ? cutOff : noCommand;
|
|
215
263
|
say(last.said);
|
|
@@ -224,7 +272,7 @@ export function session({ tool, sandbox, limits, say, end, clock = Date.now }) {
|
|
|
224
272
|
const content = typeof block.content === 'string' ? [{ type: 'text', text: block.content }] : (block.content ?? []);
|
|
225
273
|
reply.results.set(block.tool_use_id, {
|
|
226
274
|
id: block.tool_use_id,
|
|
227
|
-
by:
|
|
275
|
+
by: agent.by,
|
|
228
276
|
text: content.filter((part) => part.type === 'text').map((part) => part.text).join('\n'),
|
|
229
277
|
images: content.filter((part) => part.type === 'image').map((part) => ({ mime: part.source?.media_type, data: part.source?.data })),
|
|
230
278
|
});
|
|
@@ -279,14 +327,14 @@ export function session({ tool, sandbox, limits, say, end, clock = Date.now }) {
|
|
|
279
327
|
claude_code_version: event.claude_code_version,
|
|
280
328
|
};
|
|
281
329
|
raw.unshift({ type: 'session', init });
|
|
282
|
-
if (
|
|
283
|
-
return fail(new ProviderError(
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
if (
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
330
|
+
if (!agent.onPlan(event.apiKeySource))
|
|
331
|
+
return fail(new ProviderError(`${agent.name} used an API key (${event.apiKeySource}), not the subscription`, { fatal: true }));
|
|
332
|
+
const allowed = agent.allowed(tool);
|
|
333
|
+
const extra = (event.tools ?? []).filter((name) => !allowed.includes(name));
|
|
334
|
+
if (extra.length) return fail(new ProviderError(`${agent.name} offered the model tools besides ours: ${extra.join(', ')}`, { fatal: true }));
|
|
335
|
+
const status = (event.mcp_servers ?? []).find((server) => server.name === SERVER)?.status ?? 'missing';
|
|
336
|
+
if (agent.listsOurTool ? !(event.tools ?? []).includes(toolName(tool)) : status === 'missing')
|
|
337
|
+
return fail(new ProviderError(`${agent.name} didn't get our tool (MCP server ${status})`));
|
|
290
338
|
} else if (event.type === 'stream_event') {
|
|
291
339
|
streamed(event.event ?? {});
|
|
292
340
|
} else if (event.type === 'user') {
|
|
@@ -300,7 +348,7 @@ export function session({ tool, sandbox, limits, say, end, clock = Date.now }) {
|
|
|
300
348
|
} else if (event.type === 'system' && event.subtype !== 'status') {
|
|
301
349
|
// Retries, compaction and anything else Claude Code did on its own, for the record.
|
|
302
350
|
raw.push(event);
|
|
303
|
-
if (event.subtype === 'compact_boundary') current?.notes.push({ role: 'harness', by:
|
|
351
|
+
if (event.subtype === 'compact_boundary') current?.notes.push({ role: 'harness', by: agent.by, text: `${agent.name} compacted the conversation here.` });
|
|
304
352
|
}
|
|
305
353
|
},
|
|
306
354
|
|
|
@@ -315,8 +363,8 @@ export function session({ tool, sandbox, limits, say, end, clock = Date.now }) {
|
|
|
315
363
|
// Without an id (an older Claude Code), the first unanswered call with the same command.
|
|
316
364
|
const unanswered = (r) => r.all?.find((c) => !r.results.has(c.id) && c.command === read.command);
|
|
317
365
|
const reply = await until(() => {
|
|
318
|
-
const owner = id ? owners.get(id) : replies.findLast((r) => r.stopped && unanswered(r));
|
|
319
|
-
return owner?.stopped ? owner : null;
|
|
366
|
+
const owner = id ? owners.get(id) : replies.findLast((r) => (r.stopped || agent.eager) && unanswered(r));
|
|
367
|
+
return owner?.stopped || (agent.eager && owner) ? owner : null;
|
|
320
368
|
}, CATCH_UP_MS);
|
|
321
369
|
if (!reply) return { text: 'Not run: the harness could not match this call to a reply.', images: [], isError: true };
|
|
322
370
|
const useId = id ?? unanswered(reply).id;
|
|
@@ -418,7 +466,7 @@ export async function answerRpc(message, { tool, call }) {
|
|
|
418
466
|
}
|
|
419
467
|
|
|
420
468
|
/** Serves our tool to one Claude Code process: 127.0.0.1, a free port, a path no one else knows. */
|
|
421
|
-
async function serve(handler) {
|
|
469
|
+
export async function serve(handler) {
|
|
422
470
|
const path = `/mcp/${randomBytes(16).toString('hex')}`;
|
|
423
471
|
const server = createServer(async (request, response) => {
|
|
424
472
|
if (request.url !== path) return response.writeHead(404).end();
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
// The xAI models with tools on a Grok plan: Grok Build's headless mode asks
|
|
2
|
+
// the model, and the one tool that runs anything is ours, served from this
|
|
3
|
+
// process over MCP, so the model gets the same request, the same tool, the
|
|
4
|
+
// same sandbox and the same budget as harness/loop.mjs gives it through the
|
|
5
|
+
// API. The model of this file is harness/claude-code.mjs: Grok Build writes
|
|
6
|
+
// the same stream of events, so the run's state is that file's `session`.
|
|
7
|
+
//
|
|
8
|
+
// What the model has (Grok Build 1.0.100, 4 December 2026): three tools.
|
|
9
|
+
// `vb__bash` is ours, with our description and schema. `search_tool` and
|
|
10
|
+
// `use_tool` are Grok Build's way to MCP tools and can't be switched off:
|
|
11
|
+
// the model usually looks our tool up with the first and calls it through
|
|
12
|
+
// the second ({"tool_name": "vb__bash", "tool_input": {...}}), which reaches
|
|
13
|
+
// us as the same call. A reply spent on `search_tool` counts against the
|
|
14
|
+
// budget of replies like any other, so a run here may have one or two fewer
|
|
15
|
+
// for drawing than the same run through the API. Every built-in that reads,
|
|
16
|
+
// writes or runs anything on this machine, the web and X search, sub-agents,
|
|
17
|
+
// plans, memory and skills are off; the first event of each run lists the
|
|
18
|
+
// tools the session had, and the run fails if there is one more.
|
|
19
|
+
//
|
|
20
|
+
// What Grok Build sends that our loop does not: a short system prompt of its
|
|
21
|
+
// own (about 1,300 input tokens with the tools; an agent file with an empty
|
|
22
|
+
// body is as bare as it goes), the working directory (an empty temp folder)
|
|
23
|
+
// and the date. No output cap is ours to set. Pictures reach the model as
|
|
24
|
+
// pictures (`expose_image_base64 = false`): in the probe it described the
|
|
25
|
+
// stripes `view` showed it.
|
|
26
|
+
//
|
|
27
|
+
// Grok Build runs a call before it has written the end of the reply that
|
|
28
|
+
// made it, so a call is matched to its reply (by its command: the MCP call
|
|
29
|
+
// carries no id) as soon as the block is whole.
|
|
30
|
+
//
|
|
31
|
+
// Headless mode takes one prompt and reads nothing after it, so the loop's
|
|
32
|
+
// "That reply ran no command" message is sent by resuming the session in a
|
|
33
|
+
// new process.
|
|
34
|
+
|
|
35
|
+
import { spawn } from 'node:child_process';
|
|
36
|
+
import { randomUUID } from 'node:crypto';
|
|
37
|
+
import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises';
|
|
38
|
+
import { homedir, tmpdir } from 'node:os';
|
|
39
|
+
import { join } from 'node:path';
|
|
40
|
+
import { ProviderError } from '../src/model-apis.js';
|
|
41
|
+
import { answerRpc, serve, session } from './claude-code.mjs';
|
|
42
|
+
|
|
43
|
+
const SERVER = 'vb';
|
|
44
|
+
const GRACE_MINUTES = 30;
|
|
45
|
+
|
|
46
|
+
/** The name the model calls our tool by, directly or inside `use_tool`. */
|
|
47
|
+
export const toolName = (tool) => `${SERVER}__${tool.name}`;
|
|
48
|
+
|
|
49
|
+
// Every tool Grok Build has of its own that a flag can take away. A name it
|
|
50
|
+
// doesn't know only earns a warning, and one that is missing here stops the
|
|
51
|
+
// run at its first event, so the list errs long.
|
|
52
|
+
export const BUILT_INS = [
|
|
53
|
+
'run_terminal_command', 'read_file', 'search_replace', 'list_dir', 'grep', 'write', 'kill_command_or_subagent',
|
|
54
|
+
'get_command_or_subagent_output', 'wait_commands_or_subagents', 'monitor', 'workflow', 'todo_write',
|
|
55
|
+
'scheduler_create', 'scheduler_delete', 'scheduler_list', 'enter_plan_mode', 'exit_plan_mode', 'ask_user_question',
|
|
56
|
+
'send_feedback', 'image_gen', 'image_edit', 'image_to_video', 'reference_to_video', 'Agent', 'x_search',
|
|
57
|
+
];
|
|
58
|
+
|
|
59
|
+
/** What harness/claude-code.mjs's session needs to know about Grok Build. */
|
|
60
|
+
export const GROK_BUILD = {
|
|
61
|
+
by: 'grok-build',
|
|
62
|
+
name: 'Grok Build',
|
|
63
|
+
allowed: (tool) => ['search_tool', 'use_tool', toolName(tool)],
|
|
64
|
+
// The first event comes before the MCP server has answered: it may not list our tool yet.
|
|
65
|
+
listsOurTool: false,
|
|
66
|
+
onPlan: (source) => source === 'oauth',
|
|
67
|
+
// Seen on 1.0.100: the tool is called once its block is whole, and the reply's end is written after the result.
|
|
68
|
+
eager: true,
|
|
69
|
+
unwrap(block, input, tool) {
|
|
70
|
+
if (block.name === toolName(tool)) return input;
|
|
71
|
+
if (block.name !== 'use_tool' || ![toolName(tool), tool.name].includes(input?.tool_name)) return null;
|
|
72
|
+
let args = input.tool_input;
|
|
73
|
+
if (typeof args === 'string') {
|
|
74
|
+
try {
|
|
75
|
+
args = JSON.parse(args);
|
|
76
|
+
} catch {}
|
|
77
|
+
}
|
|
78
|
+
return args ?? {};
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/** Where the plan's sign-in is kept. Used in place, never copied: Grok Build refreshes it. */
|
|
83
|
+
export const authPath = (from = process.env) => from.GROK_AUTH_PATH || join(from.GROK_HOME || join(homedir(), '.grok'), 'auth.json');
|
|
84
|
+
|
|
85
|
+
/** Grok Build's own settings for one run, as config.toml in a home of its own. */
|
|
86
|
+
export const config = ({ mcpUrl, limits }) =>
|
|
87
|
+
[
|
|
88
|
+
'[cli]',
|
|
89
|
+
'auto_update = false',
|
|
90
|
+
'',
|
|
91
|
+
`[mcp_servers.${SERVER}]`,
|
|
92
|
+
`url = ${JSON.stringify(mcpUrl)}`,
|
|
93
|
+
// Long enough for a command that runs to its limit, and the collection after it.
|
|
94
|
+
`tool_timeout_sec = ${limits.commandSeconds + 120}`,
|
|
95
|
+
// Pictures go to the model as pictures, not as base64 text.
|
|
96
|
+
'expose_image_base64 = false',
|
|
97
|
+
'',
|
|
98
|
+
].join('\n');
|
|
99
|
+
|
|
100
|
+
/** An agent with no instructions of ours and none of Grok Build's skills. */
|
|
101
|
+
export const AGENT = ['---', 'name: vb', 'description: One tool, served over MCP.', 'promptMode: full', 'discoverSkills: false', 'inheritSkills: false', '---', ''].join('\n');
|
|
102
|
+
|
|
103
|
+
/** The environment Grok Build runs in: ours, less anything that would change who pays or what it sends. */
|
|
104
|
+
export function environment({ home }, from = process.env) {
|
|
105
|
+
const env = {};
|
|
106
|
+
for (const [name, value] of Object.entries(from)) {
|
|
107
|
+
if (/^(XAI_|GROK_)/.test(name)) continue;
|
|
108
|
+
env[name] = value;
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
...env,
|
|
112
|
+
// A home of its own: no settings, sessions, skills or MCP servers of the user's (Grok Build also reads ~/.claude).
|
|
113
|
+
HOME: home,
|
|
114
|
+
GROK_HOME: home,
|
|
115
|
+
GROK_AUTH_PATH: authPath(from),
|
|
116
|
+
GROK_MEMORY: '0',
|
|
117
|
+
GROK_DISABLE_AUTOUPDATER: '1',
|
|
118
|
+
// Every image `view` made reaches the model, however many one command makes.
|
|
119
|
+
GROK_MAX_MCP_OUTPUT_BYTES: '50000000',
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Grok Build's flags: as bare as it allows. `resume` goes on with the session instead of starting it. */
|
|
124
|
+
export function flags({ model, effort, limits, agentFile, promptFile, cwd, sessionId, resume = false }) {
|
|
125
|
+
return [
|
|
126
|
+
...(resume ? ['--resume', sessionId] : ['--session-id', sessionId]),
|
|
127
|
+
'--prompt-file', promptFile, '--verbatim',
|
|
128
|
+
'-m', model, ...(effort ? ['--reasoning-effort', effort] : []),
|
|
129
|
+
'--agent', agentFile, '--disallowed-tools', BUILT_INS.join(','),
|
|
130
|
+
'--always-approve', '--no-subagents', '--no-plan', '--no-memory', '--disable-web-search',
|
|
131
|
+
// A backstop only: the run is stopped by its own count of replies first.
|
|
132
|
+
'--max-turns', String(limits.replies + 1),
|
|
133
|
+
'--output-format', 'streaming-messages-json', '--include-partial-messages',
|
|
134
|
+
'--cwd', cwd,
|
|
135
|
+
];
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Runs one drawing through Grok Build. Returns what draw() in loop.mjs
|
|
140
|
+
* returns, plus `route`. Throws ProviderError when the run isn't an answer.
|
|
141
|
+
*/
|
|
142
|
+
export async function drawWithGrokBuild({ model, effort, text, tool, sandbox, limits }) {
|
|
143
|
+
const bin = process.env.GROK_BIN || 'grok';
|
|
144
|
+
const home = await mkdtemp(join(tmpdir(), 'vb-grok-'));
|
|
145
|
+
// An empty folder of its own: Grok Build tells the model its working directory.
|
|
146
|
+
const cwd = join(home, 'work');
|
|
147
|
+
await mkdir(cwd);
|
|
148
|
+
const agentFile = join(home, 'vb-agent.md');
|
|
149
|
+
await writeFile(agentFile, AGENT);
|
|
150
|
+
const sessionId = randomUUID();
|
|
151
|
+
|
|
152
|
+
let child = null;
|
|
153
|
+
let next = null; // what to say when the process that heard the last turn has gone
|
|
154
|
+
let stopping = false;
|
|
155
|
+
const stop = () => {
|
|
156
|
+
stopping = true;
|
|
157
|
+
if (!child) return;
|
|
158
|
+
const ending = child;
|
|
159
|
+
ending.kill('SIGTERM');
|
|
160
|
+
setTimeout(() => ending.exitCode === null && ending.signalCode === null && ending.kill('SIGKILL'), 5000).unref();
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const run = session({ tool, sandbox, limits, say: (said) => (next = said), end: stop, agent: GROK_BUILD });
|
|
164
|
+
const server = await serve((message) => answerRpc(message, { tool, call: run.call }));
|
|
165
|
+
await writeFile(join(home, 'config.toml'), config({ mcpUrl: server.url, limits }));
|
|
166
|
+
const watchdog = setTimeout(() => run.fail(new ProviderError(`Grok Build was still going ${GRACE_MINUTES} minutes past the time budget`)), (limits.minutes + GRACE_MINUTES) * 60000);
|
|
167
|
+
|
|
168
|
+
let stderr = '';
|
|
169
|
+
let turn = 0;
|
|
170
|
+
/** One process: one user message and everything the model does until it stops calling tools. */
|
|
171
|
+
const ask = async (said, resume) => {
|
|
172
|
+
const promptFile = join(home, `prompt-${++turn}.txt`);
|
|
173
|
+
await writeFile(promptFile, said);
|
|
174
|
+
return new Promise((done) => {
|
|
175
|
+
try {
|
|
176
|
+
child = spawn(bin, flags({ model, effort, limits, agentFile, promptFile, cwd, sessionId, resume }), { cwd, env: environment({ home }), stdio: ['ignore', 'pipe', 'pipe'] });
|
|
177
|
+
} catch (error) {
|
|
178
|
+
run.fail(new ProviderError(`couldn't start grok: ${error.message}`, { fatal: true }));
|
|
179
|
+
return done({});
|
|
180
|
+
}
|
|
181
|
+
let pending = '';
|
|
182
|
+
child.stdout.setEncoding('utf8');
|
|
183
|
+
child.stdout.on('data', (chunk) => {
|
|
184
|
+
pending += chunk;
|
|
185
|
+
let newline;
|
|
186
|
+
while ((newline = pending.indexOf('\n')) >= 0) {
|
|
187
|
+
const line = pending.slice(0, newline);
|
|
188
|
+
pending = pending.slice(newline + 1);
|
|
189
|
+
if (!line.trim()) continue;
|
|
190
|
+
let event;
|
|
191
|
+
try {
|
|
192
|
+
event = JSON.parse(line);
|
|
193
|
+
} catch {
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
try {
|
|
197
|
+
run.handle(event);
|
|
198
|
+
} catch (error) {
|
|
199
|
+
run.fail(error);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
child.stderr.setEncoding('utf8');
|
|
204
|
+
child.stderr.on('data', (chunk) => (stderr = (stderr + chunk).slice(-20_000)));
|
|
205
|
+
child.on('error', (error) => run.fail(new ProviderError(`couldn't start grok: ${error.message}`, { fatal: true })));
|
|
206
|
+
child.on('close', (code, signal) => done({ code, signal }));
|
|
207
|
+
});
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
let closed;
|
|
211
|
+
try {
|
|
212
|
+
closed = await ask(text, false);
|
|
213
|
+
while (next && !stopping && !run.exit && !run.failure) {
|
|
214
|
+
const said = next;
|
|
215
|
+
next = null;
|
|
216
|
+
closed = await ask(said, true);
|
|
217
|
+
}
|
|
218
|
+
} finally {
|
|
219
|
+
clearTimeout(watchdog);
|
|
220
|
+
await server.close();
|
|
221
|
+
await rm(home, { recursive: true, force: true });
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (run.failure) throw run.failure;
|
|
225
|
+
if (!run.exit) {
|
|
226
|
+
const why = stderr.trim().split('\n').slice(-3).join(' ') || `it exited (${closed.signal ?? closed.code}) before the run was over`;
|
|
227
|
+
throw new ProviderError(`Grok Build: ${why}`, { fatal: /authenticat|log ?in|signed in|sign in|usage limit|rate limit/i.test(why) });
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const svg = await sandbox.read('drawing.svg');
|
|
231
|
+
const { init, ...result } = run.outcome();
|
|
232
|
+
return { ...result, svg, route: { via: 'grok-build', style: 'grok-build', url: 'https://cli-chat-proxy.grok.com/v1' } };
|
|
233
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vectorbench",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.3",
|
|
4
4
|
"description": "Draw VectorBench's SVG prompts with your own model, in the same sandbox as the benchmark at vectorbench.ai",
|
|
5
5
|
"homepage": "https://vectorbench.ai",
|
|
6
6
|
"repository": {
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"scripts/harness.mjs",
|
|
30
30
|
"scripts/doctor.mjs",
|
|
31
31
|
"scripts/zip.mjs",
|
|
32
|
+
"scripts/sheet.mjs",
|
|
32
33
|
"harness/*.mjs",
|
|
33
34
|
"harness/adapters/",
|
|
34
35
|
"harness/box/",
|
package/scripts/doctor.mjs
CHANGED
|
@@ -78,19 +78,21 @@ export function machine() {
|
|
|
78
78
|
export function routes() {
|
|
79
79
|
return [
|
|
80
80
|
{ name: 'Claude Code (Claude models, on your Claude plan)', ok: works('claude', ['--version']), fix: 'Install it and sign in, or use ANTHROPIC_API_KEY with --api.' },
|
|
81
|
-
{ name: 'The Codex CLI (OpenAI models, on your ChatGPT plan, with --codex)', ok: works(process.env.CODEX_BIN || 'codex', ['--version']), fix: 'Install it and sign in, or use OPENAI_API_KEY.' },
|
|
81
|
+
{ name: 'The Codex CLI (OpenAI models, on your ChatGPT plan: used when OPENAI_API_KEY is not set, or with --codex)', ok: works(process.env.CODEX_BIN || 'codex', ['--version']), fix: 'Install it and sign in, or use OPENAI_API_KEY.' },
|
|
82
|
+
{ name: 'Grok Build (xAI models, on your Grok plan: used when XAI_API_KEY is not set, or with --grok-build)', ok: works(process.env.GROK_BIN || 'grok', ['--version']), fix: 'Install it and sign in, or use XAI_API_KEY.' },
|
|
82
83
|
...PROVIDERS.map((provider) => [provider, KEYS[provider]]).map(([provider, key]) => ({ name: `${key} (${provider}'s API)`, ok: Boolean(process.env[key]), fix: `Set it in the environment or in a .env file here, to draw through ${provider}'s API.` })),
|
|
83
84
|
];
|
|
84
85
|
}
|
|
85
86
|
|
|
86
|
-
/** What is missing to draw with `model` over `route` ('Claude Code' | 'Codex' | 'API'): lines to print. */
|
|
87
|
+
/** What is missing to draw with `model` over `route` ('Claude Code' | 'Codex' | 'Grok Build' | 'API'): lines to print. */
|
|
87
88
|
export function check({ model, route }) {
|
|
88
89
|
const missing = machine()
|
|
89
90
|
.filter((item) => !item.ok)
|
|
90
91
|
.map((item) => `${item.name}. ${item.fix}`);
|
|
91
92
|
if (route === 'Claude Code' && !works('claude', ['--version'])) missing.push('Claude Code, installed and signed in (or pass --api to use ANTHROPIC_API_KEY).');
|
|
92
93
|
if (route === 'Codex' && !works(process.env.CODEX_BIN || 'codex', ['--version'])) missing.push('The Codex CLI, installed and signed in.');
|
|
93
|
-
if (route === '
|
|
94
|
+
if (route === 'Grok Build' && !works(process.env.GROK_BIN || 'grok', ['--version'])) missing.push('Grok Build, installed and signed in.');
|
|
95
|
+
if (route === 'API' && !process.env[KEYS[model.via]]) missing.push(`${KEYS[model.via]}, in the environment or in a .env file here${model.via === 'openai' ? ' (or install the Codex CLI and sign in, to use your ChatGPT plan)' : model.via === 'xai' ? ' (or install Grok Build and sign in, to use your Grok plan)' : ''}.`);
|
|
94
96
|
return missing;
|
|
95
97
|
}
|
|
96
98
|
|
package/scripts/harness.mjs
CHANGED
|
@@ -19,8 +19,10 @@
|
|
|
19
19
|
// --effort <level> ask at this effort instead of each model's own
|
|
20
20
|
// --replies <n> --minutes <n> another budget than harness/request.mjs's
|
|
21
21
|
// --concurrency <n> runs at once per provider (default 3)
|
|
22
|
+
// --grok-build ask xAI models through Grok Build on a Grok plan
|
|
23
|
+
// (harness/grok-build.mjs), the same way. GROK_BIN picks the install.
|
|
22
24
|
// --paid also ask models that would run on paid API credits. Without it
|
|
23
|
-
// only plan routes run (Claude Code,
|
|
25
|
+
// only plan routes run (Claude Code, Codex with --codex, Grok Build with --grok-build): the
|
|
24
26
|
// owner's rule from 19 November 2026 is to draw on the Claude and
|
|
25
27
|
// ChatGPT plans only, so pass it only when the owner says to
|
|
26
28
|
// --harness 1 ask the way version 1 did (its request, budget and sandbox
|
|
@@ -45,7 +47,7 @@
|
|
|
45
47
|
// model could finish a run through it, and six of 17 drawings came back over
|
|
46
48
|
// the site's 200 KB limit, which nothing in the sandbox checked.
|
|
47
49
|
|
|
48
|
-
import {
|
|
50
|
+
import { spawnSync } from 'node:child_process';
|
|
49
51
|
import { existsSync } from 'node:fs';
|
|
50
52
|
import { mkdir, readFile, rm, writeFile } from 'node:fs/promises';
|
|
51
53
|
import { join, relative, resolve } from 'node:path';
|
|
@@ -57,6 +59,8 @@ import { maxOutputTokens, models as lineup, prompts, upcomingModels } from '../b
|
|
|
57
59
|
// VB_EXTRA_MODELS, as rows shaped like bench.config.mjs's).
|
|
58
60
|
const extraModels = process.env.VB_EXTRA_MODELS ? JSON.parse(process.env.VB_EXTRA_MODELS) : [];
|
|
59
61
|
const models = [...lineup, ...upcomingModels, ...extraModels];
|
|
62
|
+
/** The ids of the containers that are up, to take down if the run is stopped. */
|
|
63
|
+
const running = new Set();
|
|
60
64
|
import { PRICE_RATIO, VIA_CHECKED, keyOf, open } from '../harness/adapters/index.mjs';
|
|
61
65
|
import { draw } from '../harness/loop.mjs';
|
|
62
66
|
import { estimate } from '../harness/prices.mjs';
|
|
@@ -65,10 +69,15 @@ import { HARNESS, firstLimits, firstRequest, limits, request, tool } from '../ha
|
|
|
65
69
|
import { IMAGE, imageId as sandboxImageId, openSandbox } from '../harness/sandbox.mjs';
|
|
66
70
|
import { ProviderError } from '../src/model-apis.js';
|
|
67
71
|
import { cleanSvg } from '../worker/svg.js';
|
|
68
|
-
import { findChrome } from './doctor.mjs';
|
|
72
|
+
import { INSTALLED, findChrome } from './doctor.mjs';
|
|
73
|
+
import { writeSheet } from './sheet.mjs';
|
|
69
74
|
|
|
70
75
|
const ROOT = fileURLToPath(new URL('../', import.meta.url));
|
|
71
76
|
const CONCURRENCY = Number(process.argv.includes('--concurrency') ? process.argv[process.argv.indexOf('--concurrency') + 1] : 3); // per provider
|
|
77
|
+
if (!Number.isInteger(CONCURRENCY) || CONCURRENCY < 1) {
|
|
78
|
+
console.error('--concurrency takes a whole number, 1 or more.');
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
72
81
|
|
|
73
82
|
try {
|
|
74
83
|
process.loadEnvFile(join(ROOT, '.env'));
|
|
@@ -118,6 +127,9 @@ If an image does not reach you, write "no image" to the file instead of guessing
|
|
|
118
127
|
const viaSubscription = (model) => model.via === 'anthropic' && !flag('api');
|
|
119
128
|
// OpenAI models run on the ChatGPT subscription through Codex when --codex says so.
|
|
120
129
|
const viaCodex = (model) => model.via === 'openai' && flag('codex');
|
|
130
|
+
// xAI models run on a Grok plan through Grok Build when --grok-build says so.
|
|
131
|
+
const viaGrokBuild = (model) => model.via === 'xai' && flag('grok-build');
|
|
132
|
+
const onPlan = (model) => viaSubscription(model) || viaCodex(model) || viaGrokBuild(model);
|
|
121
133
|
// --via <route>: the OpenAI models named go through a harness-only route
|
|
122
134
|
// (harness/adapters/index.mjs), each only if it was checked for that model.
|
|
123
135
|
const via = option('via');
|
|
@@ -181,20 +193,6 @@ async function readJson(path) {
|
|
|
181
193
|
}
|
|
182
194
|
}
|
|
183
195
|
|
|
184
|
-
function run(command, commandArgs, { log } = {}) {
|
|
185
|
-
return new Promise((done) => {
|
|
186
|
-
const child = spawn(command, commandArgs, { cwd: ROOT, env: process.env, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
187
|
-
let out = '';
|
|
188
|
-
child.stdout.on('data', (chunk) => (out += chunk));
|
|
189
|
-
child.stderr.on('data', (chunk) => (out += chunk));
|
|
190
|
-
child.on('error', (error) => done({ code: -1, out: String(error) }));
|
|
191
|
-
child.on('close', async (code) => {
|
|
192
|
-
if (log) await writeFile(log, out);
|
|
193
|
-
done({ code, out });
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
|
|
198
196
|
/** Chromium on this machine: the last word on whether the file draws. */
|
|
199
197
|
async function openRenderer() {
|
|
200
198
|
const { chromium } = await import('playwright-core');
|
|
@@ -270,6 +268,7 @@ async function ask(prompt, model, renderer, imageId) {
|
|
|
270
268
|
let result;
|
|
271
269
|
try {
|
|
272
270
|
sandbox = await openSandbox({ image: version.image, commandSeconds: budget.commandSeconds });
|
|
271
|
+
running.add(sandbox.id);
|
|
273
272
|
if (probe) {
|
|
274
273
|
await sandbox.run(
|
|
275
274
|
`python3 -c "from PIL import Image, ImageDraw, ImageFont; i = Image.new('RGB', (480, 200), 'white'); ImageDraw.Draw(i).text((110, 40), '${number}', fill='black', font=ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf', 110)); i.save('probe.png')"`,
|
|
@@ -279,6 +278,10 @@ async function ask(prompt, model, renderer, imageId) {
|
|
|
279
278
|
// Claude Code runs the same tool in the same sandbox on the Claude subscription (harness/claude-code.mjs).
|
|
280
279
|
const { drawWithClaudeCode } = await import('../harness/claude-code.mjs');
|
|
281
280
|
result = await drawWithClaudeCode({ model: model.model, effort, maxOutputTokens: cap, text, tool, sandbox, limits: budget });
|
|
281
|
+
} else if (viaGrokBuild(model)) {
|
|
282
|
+
// Grok Build runs the same tool in the same sandbox on the Grok plan (harness/grok-build.mjs).
|
|
283
|
+
const { drawWithGrokBuild } = await import('../harness/grok-build.mjs');
|
|
284
|
+
result = await drawWithGrokBuild({ model: model.model, effort, text, tool, sandbox, limits: budget });
|
|
282
285
|
} else if (viaCodex(model)) {
|
|
283
286
|
// Codex runs the same tool in the same sandbox on the ChatGPT subscription (harness/codex.mjs).
|
|
284
287
|
const { drawWithCodex } = await import('../harness/codex.mjs');
|
|
@@ -302,6 +305,7 @@ async function ask(prompt, model, renderer, imageId) {
|
|
|
302
305
|
if (probe) result.probe = { sent: number, answer: (await sandbox.read('answer.txt'))?.trim() ?? null, seen: (await sandbox.read('seen.txt'))?.trim() ?? null };
|
|
303
306
|
} finally {
|
|
304
307
|
await sandbox?.close();
|
|
308
|
+
running.delete(sandbox?.id);
|
|
305
309
|
}
|
|
306
310
|
await saveRun(folder, result);
|
|
307
311
|
|
|
@@ -321,11 +325,11 @@ async function ask(prompt, model, renderer, imageId) {
|
|
|
321
325
|
}
|
|
322
326
|
const outcome = result.exit === 'refused' ? 'refused' : svg ? 'drawn' : 'invalid';
|
|
323
327
|
// Dollars as the provider reports them, or worked out from list prices.
|
|
324
|
-
// The subscription pays for a Claude Code or
|
|
328
|
+
// The subscription pays for a Claude Code, Codex or Grok Build run, so its figure is what the API would have charged.
|
|
325
329
|
const usage = {
|
|
326
330
|
...result.usage,
|
|
327
331
|
cost: result.usage.cost ?? (estimate(model.id, result.usage) == null ? null : estimate(model.id, result.usage) * (PRICE_RATIO[model.via] ?? 1)),
|
|
328
|
-
costIs: result.usage.cost ? 'reported' :
|
|
332
|
+
costIs: result.usage.cost ? 'reported' : ['claude-code', 'codex', 'grok-build'].includes(result.route.via) ? 'subscription' : 'estimated',
|
|
329
333
|
};
|
|
330
334
|
|
|
331
335
|
await mkdir(join(OUT, 'log', prompt.id), { recursive: true });
|
|
@@ -342,8 +346,8 @@ async function ask(prompt, model, renderer, imageId) {
|
|
|
342
346
|
baseUrl: result.route.url,
|
|
343
347
|
apiModel: model.model,
|
|
344
348
|
effort: effort ?? null,
|
|
345
|
-
// Codex
|
|
346
|
-
maxOutputTokens: viaCodex(model) ? null : cap,
|
|
349
|
+
// Codex and Grok Build send no output cap of ours: the plan's own applies.
|
|
350
|
+
maxOutputTokens: viaCodex(model) || viaGrokBuild(model) ? null : cap,
|
|
347
351
|
servedModel: result.servedModel,
|
|
348
352
|
responseIds: result.responseIds,
|
|
349
353
|
askedAt,
|
|
@@ -461,23 +465,32 @@ ${sections.join('\n')}
|
|
|
461
465
|
);
|
|
462
466
|
}
|
|
463
467
|
|
|
468
|
+
// The plain-request drawings are in the repository, not in the npm package: without them there is nothing to compare with.
|
|
469
|
+
const COMPARES = existsSync(join(ROOT, 'drawings'));
|
|
470
|
+
|
|
471
|
+
/** index.html and manifest.json for everything in OUT, and compare.html where there is something to compare with. */
|
|
472
|
+
async function writeSheets(asked) {
|
|
473
|
+
// In a clone the manifest is what `npm run arena -- import` reads, so it lists the lineup; a partner's own model is always in.
|
|
474
|
+
await writeSheet({ out: OUT, models: INSTALLED ? models : [...lineup, ...extraModels], prompts });
|
|
475
|
+
if (COMPARES) await writeComparison(asked);
|
|
476
|
+
}
|
|
477
|
+
|
|
464
478
|
/* Run --------------------------------------------------------------------- */
|
|
465
479
|
|
|
466
480
|
const asked = probe ? [PROBE] : prompts.filter((p) => onlyPrompts.includes(p.id));
|
|
467
481
|
if (flag('sheet')) {
|
|
468
|
-
await
|
|
469
|
-
|
|
470
|
-
console.log(`Rebuilt ${shown(OUT)}/compare.html and index.html.`);
|
|
482
|
+
await writeSheets(asked);
|
|
483
|
+
console.log(`Rebuilt ${shown(OUT)}/${COMPARES ? 'compare.html and ' : ''}index.html.`);
|
|
471
484
|
process.exit(0);
|
|
472
485
|
}
|
|
473
486
|
const wanted = [];
|
|
474
487
|
for (const model of models.filter((m) => !onlyModels || onlyModels.includes(m.id)).map(routed)) {
|
|
475
488
|
// Owner's rule, 19 Nov 2026: drawings are made on the Claude and ChatGPT plans only.
|
|
476
|
-
if (!
|
|
477
|
-
console.log(`Skipping ${model.name}: it would run on paid API credits${model.via === 'openai' ? ' (--codex puts it on the ChatGPT plan)' : ''}. --paid allows that, billed to your own key.`);
|
|
489
|
+
if (!onPlan(model) && !flag('paid')) {
|
|
490
|
+
console.log(`Skipping ${model.name}: it would run on paid API credits${model.via === 'openai' ? ' (--codex puts it on the ChatGPT plan)' : model.via === 'xai' ? ' (--grok-build puts it on the Grok plan)' : ''}. --paid allows that, billed to your own key.`);
|
|
478
491
|
continue;
|
|
479
492
|
}
|
|
480
|
-
if (!
|
|
493
|
+
if (!onPlan(model) && !process.env[keyOf(model)]) {
|
|
481
494
|
console.log(`Skipping ${model.name}: ${keyOf(model)} is not set.`);
|
|
482
495
|
continue;
|
|
483
496
|
}
|
|
@@ -488,7 +501,7 @@ for (const model of models.filter((m) => !onlyModels || onlyModels.includes(m.id
|
|
|
488
501
|
}
|
|
489
502
|
if (!wanted.length) {
|
|
490
503
|
console.log('Nothing to ask.');
|
|
491
|
-
if (!probe) await
|
|
504
|
+
if (!probe) await writeSheets(asked);
|
|
492
505
|
process.exit(0);
|
|
493
506
|
}
|
|
494
507
|
console.log(`${wanted.length} runs to make, into ${shown(OUT)}/:`);
|
|
@@ -498,6 +511,15 @@ if (flag('dry-run')) process.exit(0);
|
|
|
498
511
|
const imageId = await sandboxImageId(version.image);
|
|
499
512
|
if (!imageId) fail(`The sandbox image ${version.image} is missing. \`npm run partner\` (or \`vectorbench draw\`) builds it; the build command itself is in harness/Dockerfile.`);
|
|
500
513
|
|
|
514
|
+
// Stopped by hand (Ctrl-C): the containers would otherwise sit there for hours.
|
|
515
|
+
for (const signal of ['SIGINT', 'SIGTERM']) {
|
|
516
|
+
process.once(signal, () => {
|
|
517
|
+
if (running.size) spawnSync('docker', ['rm', '-f', ...running], { stdio: 'ignore' });
|
|
518
|
+
console.error(`\nStopped. The drawings that have an answer are kept: the same command picks up the rest.`);
|
|
519
|
+
process.exit(130);
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
|
|
501
523
|
const renderer = await openRenderer();
|
|
502
524
|
const queues = new Map();
|
|
503
525
|
const lines = [];
|
|
@@ -531,8 +553,7 @@ await Promise.all([...queues.values()].map((tasks) => pool(tasks, CONCURRENCY)))
|
|
|
531
553
|
await renderer.close();
|
|
532
554
|
|
|
533
555
|
if (!probe) {
|
|
534
|
-
await
|
|
535
|
-
|
|
536
|
-
console.log(`\nLook them over in ${shown(OUT)}/compare.html (beside the plain-request drawings) or ${shown(OUT)}/index.html.`);
|
|
556
|
+
await writeSheets(asked);
|
|
557
|
+
console.log(`\nLook them over in ${COMPARES ? `${shown(OUT)}/compare.html (beside the plain-request drawings) or ` : ''}${shown(OUT)}/index.html.`);
|
|
537
558
|
}
|
|
538
559
|
await writeFile(join(OUT, 'summary.txt'), lines.join('\n') + '\n');
|
package/scripts/partner.mjs
CHANGED
|
@@ -10,7 +10,10 @@
|
|
|
10
10
|
// --via <provider> anthropic | openai | gemini | xai | openrouter: whose API answers
|
|
11
11
|
// --api-model <id> the model's id at that API (default: the --model id)
|
|
12
12
|
// --effort <level> its highest reasoning setting, up to max
|
|
13
|
-
// --codex an OpenAI model through the Codex CLI on your ChatGPT plan
|
|
13
|
+
// --codex an OpenAI model through the Codex CLI on your ChatGPT plan; the default
|
|
14
|
+
// when OPENAI_API_KEY isn't set and Codex is installed
|
|
15
|
+
// --grok-build an xAI model through Grok Build on your Grok plan; the default
|
|
16
|
+
// when XAI_API_KEY isn't set and Grok Build is installed
|
|
14
17
|
// --api a Claude model on API credits; without it, through Claude Code on your Claude plan
|
|
15
18
|
// --dry-run show what would be asked and what is missing, and ask nothing
|
|
16
19
|
// --out <dir> where to write (default harness/trial-partner/<model> in a clone,
|
|
@@ -39,7 +42,23 @@ const COMMAND = process.env.VB_COMMAND || 'npm run partner --';
|
|
|
39
42
|
|
|
40
43
|
loadEnv();
|
|
41
44
|
|
|
42
|
-
const
|
|
45
|
+
const OPTIONS = ` --model <id> the model to draw with (the only one that is needed)
|
|
46
|
+
--prompt <ids> only these prompts, comma-separated: one first shows the cost (\`vectorbench prompts\` lists them)
|
|
47
|
+
--via <provider> for a model we don't list: whose API answers (${PROVIDERS.join(', ')})
|
|
48
|
+
--api-model <id> for a model we don't list: its id at that API, if it differs from --model
|
|
49
|
+
--effort <level> for a model we don't list: its highest reasoning setting, up to max
|
|
50
|
+
--name <name> for a model we don't list: what to call it
|
|
51
|
+
--codex an OpenAI model through the Codex CLI, on your ChatGPT plan (the default when OPENAI_API_KEY isn't set)
|
|
52
|
+
--grok-build an xAI model through Grok Build, on your Grok plan (the default when XAI_API_KEY isn't set)
|
|
53
|
+
--api a Claude model on ANTHROPIC_API_KEY, instead of Claude Code on your Claude plan
|
|
54
|
+
--dry-run show what would be asked and what is missing, and ask nothing
|
|
55
|
+
--out <dir> where to write
|
|
56
|
+
--concurrency <n> drawings at once (default 3)`;
|
|
57
|
+
const VALUED = ['model', 'prompt', 'via', 'api-model', 'effort', 'name', 'out', 'concurrency'];
|
|
58
|
+
const FLAGS = ['codex', 'grok-build', 'api', 'dry-run', 'help'];
|
|
59
|
+
|
|
60
|
+
// --name=value is the same as --name value.
|
|
61
|
+
const args = process.argv.slice(2).flatMap((arg) => (/^--[a-z-]+=/.test(arg) ? [arg.slice(0, arg.indexOf('=')), arg.slice(arg.indexOf('=') + 1)] : [arg]));
|
|
43
62
|
const flag = (name) => args.includes(`--${name}`);
|
|
44
63
|
const option = (name) => (args.includes(`--${name}`) ? args[args.indexOf(`--${name}`) + 1] : undefined);
|
|
45
64
|
const dryRun = flag('dry-run');
|
|
@@ -48,10 +67,25 @@ const stop = (message) => {
|
|
|
48
67
|
process.exit(1);
|
|
49
68
|
};
|
|
50
69
|
|
|
70
|
+
if (flag('help') || args.includes('-h')) {
|
|
71
|
+
console.log(`${COMMAND} --model <id> [options]\n\n${OPTIONS}\n\nThe models we list: ${[...lineup, ...upcomingModels].map((m) => m.id).join(', ')}.`);
|
|
72
|
+
process.exit(0);
|
|
73
|
+
}
|
|
74
|
+
// A mistyped option would otherwise be dropped without a word, and the run would not be the one that was meant.
|
|
75
|
+
for (let i = 0; i < args.length; i++) {
|
|
76
|
+
const name = args[i].startsWith('--') ? args[i].slice(2) : null;
|
|
77
|
+
if (name === null) stop(`"${args[i]}" isn't an option. The options:\n\n${OPTIONS}`);
|
|
78
|
+
if (VALUED.includes(name)) {
|
|
79
|
+
if (args[i + 1] === undefined || args[i + 1].startsWith('--')) stop(`--${name} takes a value. The options:\n\n${OPTIONS}`);
|
|
80
|
+
i++;
|
|
81
|
+
} else if (!FLAGS.includes(name)) stop(`There is no --${name} option. The options:\n\n${OPTIONS}`);
|
|
82
|
+
}
|
|
83
|
+
if (option('concurrency') && !/^[1-9]\d*$/.test(option('concurrency'))) stop('--concurrency takes a whole number, 1 or more.');
|
|
84
|
+
|
|
51
85
|
/* The model ---------------------------------------------------------------- */
|
|
52
86
|
|
|
53
87
|
const id = option('model');
|
|
54
|
-
if (!id || id.
|
|
88
|
+
if (!id || id.includes(',')) stop(`Name one model: ${COMMAND} --model <id>\nThe ones we list: ${[...lineup, ...upcomingModels].map((m) => m.id).join(', ')}.\nAny other: add --via <${PROVIDERS.join('|')}> --effort <its highest reasoning setting>.\n\nThe options:\n\n${OPTIONS}`);
|
|
55
89
|
|
|
56
90
|
let model = [...lineup, ...upcomingModels].find((m) => m.id === id);
|
|
57
91
|
let extra = null;
|
|
@@ -71,8 +105,14 @@ for (const p of wantedPrompts) if (!prompts.some((x) => x.id === p)) stop(`There
|
|
|
71
105
|
|
|
72
106
|
/* What it runs on ---------------------------------------------------------- */
|
|
73
107
|
|
|
74
|
-
const route = model.via === 'anthropic' && !flag('api') ? 'Claude Code' : model.via === 'openai' && flag('codex') ? 'Codex' : 'API';
|
|
75
108
|
const keyName = KEYS[model.via];
|
|
109
|
+
// An OpenAI model with no API key goes to the ChatGPT plan when the Codex CLI is here, without being told to.
|
|
110
|
+
const codexBin = process.env.CODEX_BIN || 'codex';
|
|
111
|
+
const codex = model.via === 'openai' && (flag('codex') || (!process.env[keyName] && works(codexBin, ['--version'])));
|
|
112
|
+
// The same for an xAI model and the Grok plan, with Grok Build.
|
|
113
|
+
const grokBin = process.env.GROK_BIN || 'grok';
|
|
114
|
+
const grokBuild = model.via === 'xai' && (flag('grok-build') || (!process.env[keyName] && works(grokBin, ['--version'])));
|
|
115
|
+
const route = model.via === 'anthropic' && !flag('api') ? 'Claude Code' : codex ? 'Codex' : grokBuild ? 'Grok Build' : 'API';
|
|
76
116
|
const chrome = findChrome();
|
|
77
117
|
const missing = check({ model, route });
|
|
78
118
|
|
|
@@ -96,7 +136,9 @@ if (!dryRun && !works('docker', ['image', 'inspect', IMAGE])) {
|
|
|
96
136
|
|
|
97
137
|
// --paid: the partner's own key pays, which is what a partner run is.
|
|
98
138
|
const harnessArgs = ['scripts/harness.mjs', '--model', model.id, '--prompt', wantedPrompts.join(','), '--out', OUT, '--paid'];
|
|
99
|
-
for (const name of ['
|
|
139
|
+
for (const name of ['api', 'dry-run']) if (flag(name)) harnessArgs.push(`--${name}`);
|
|
140
|
+
if (codex) harnessArgs.push('--codex');
|
|
141
|
+
if (grokBuild) harnessArgs.push('--grok-build');
|
|
100
142
|
if (option('concurrency')) harnessArgs.push('--concurrency', option('concurrency'));
|
|
101
143
|
const ran = spawnSync(process.execPath, harnessArgs, {
|
|
102
144
|
cwd: ROOT,
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// The review sheet for a folder of drawings: manifest.json (what
|
|
2
|
+
// `npm run arena -- import` reads) and index.html, to look them over.
|
|
3
|
+
// scripts/generate.mjs and scripts/harness.mjs both end by writing it, and
|
|
4
|
+
// the npm package carries it, so `vectorbench draw` leaves the same sheet.
|
|
5
|
+
|
|
6
|
+
import { existsSync } from 'node:fs';
|
|
7
|
+
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
8
|
+
import { join } from 'node:path';
|
|
9
|
+
|
|
10
|
+
const escape = (s) => String(s).replace(/[&<>"]/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"' })[c]);
|
|
11
|
+
|
|
12
|
+
/** Rebuilds manifest.json and index.html in `out` from what's on disk there. Returns how many drawings it found. */
|
|
13
|
+
export async function writeSheet({ out, models, prompts }) {
|
|
14
|
+
const svgPath = (prompt, model) => join(out, prompt.id, `${model.id}.svg`);
|
|
15
|
+
const readLog = async (prompt, model) => {
|
|
16
|
+
try {
|
|
17
|
+
return JSON.parse(await readFile(join(out, 'log', prompt.id, `${model.id}.json`), 'utf8'));
|
|
18
|
+
} catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const entries = [];
|
|
23
|
+
const sections = [];
|
|
24
|
+
for (const prompt of prompts) {
|
|
25
|
+
const cells = [];
|
|
26
|
+
for (const model of models) {
|
|
27
|
+
const log = await readLog(prompt, model);
|
|
28
|
+
if (!log) continue;
|
|
29
|
+
if (log.outcome === 'drawn' && existsSync(svgPath(prompt, model))) {
|
|
30
|
+
// The setting this drawing was asked at, which can differ from the model's setting now.
|
|
31
|
+
entries.push({ prompt: prompt.id, model: model.id, file: `${prompt.id}/${model.id}.svg`, effort: log.effort ?? null });
|
|
32
|
+
cells.push(`<figure><img src="${prompt.id}/${model.id}.svg" alt="" loading="lazy"><figcaption>${escape(model.name)}</figcaption></figure>`);
|
|
33
|
+
} else {
|
|
34
|
+
cells.push(`<figure><p>${escape(log.outcome)}: ${escape(log.problem ?? 'no drawing')}</p><figcaption>${escape(model.name)}</figcaption></figure>`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (cells.length) sections.push(`<h2>${escape(prompt.text)}</h2>\n<div class="row">${cells.join('')}</div>`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const used = new Set(entries.map((e) => e.model));
|
|
41
|
+
const drawn = new Set(entries.map((e) => e.prompt));
|
|
42
|
+
await mkdir(out, { recursive: true });
|
|
43
|
+
await writeFile(
|
|
44
|
+
join(out, 'manifest.json'),
|
|
45
|
+
JSON.stringify(
|
|
46
|
+
{
|
|
47
|
+
models: models.filter((m) => used.has(m.id)).map(({ id, name, provider }) => ({ id, name, provider })),
|
|
48
|
+
prompts: prompts.filter((p) => drawn.has(p.id)),
|
|
49
|
+
entries,
|
|
50
|
+
},
|
|
51
|
+
null,
|
|
52
|
+
2,
|
|
53
|
+
) + '\n',
|
|
54
|
+
);
|
|
55
|
+
await writeFile(
|
|
56
|
+
join(out, 'index.html'),
|
|
57
|
+
`<!doctype html>
|
|
58
|
+
<meta charset="utf-8">
|
|
59
|
+
<title>VectorBench drawings</title>
|
|
60
|
+
<style>
|
|
61
|
+
body { margin: 32px; background: #000; color: #eef2fa; font: 15px/1.4 system-ui, sans-serif; }
|
|
62
|
+
h1 { font-weight: 300; }
|
|
63
|
+
h2 { margin: 40px 0 12px; font-size: 18px; font-weight: 500; }
|
|
64
|
+
.row { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
|
|
65
|
+
figure { margin: 0; }
|
|
66
|
+
img, figure p { display: block; width: 100%; aspect-ratio: 1; margin: 0; background: #fff; object-fit: contain; }
|
|
67
|
+
figure p { display: grid; place-items: center; padding: 16px; box-sizing: border-box; background: #1a1f2b; color: #ffb4a2; text-align: center; }
|
|
68
|
+
figcaption { padding: 6px 0; color: #8c95a8; }
|
|
69
|
+
</style>
|
|
70
|
+
<h1>${entries.length} drawings to look over before importing</h1>
|
|
71
|
+
${sections.join('\n')}
|
|
72
|
+
`,
|
|
73
|
+
);
|
|
74
|
+
return entries.length;
|
|
75
|
+
}
|