vectorbench 3.0.0 → 3.0.2
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/harness/claude-code.mjs +82 -34
- package/harness/grok-build.mjs +233 -0
- package/package.json +1 -1
- package/scripts/doctor.mjs +5 -3
- package/scripts/harness.mjs +17 -8
- package/scripts/partner.mjs +14 -3
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/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
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
|
|
@@ -118,6 +120,9 @@ If an image does not reach you, write "no image" to the file instead of guessing
|
|
|
118
120
|
const viaSubscription = (model) => model.via === 'anthropic' && !flag('api');
|
|
119
121
|
// OpenAI models run on the ChatGPT subscription through Codex when --codex says so.
|
|
120
122
|
const viaCodex = (model) => model.via === 'openai' && flag('codex');
|
|
123
|
+
// xAI models run on a Grok plan through Grok Build when --grok-build says so.
|
|
124
|
+
const viaGrokBuild = (model) => model.via === 'xai' && flag('grok-build');
|
|
125
|
+
const onPlan = (model) => viaSubscription(model) || viaCodex(model) || viaGrokBuild(model);
|
|
121
126
|
// --via <route>: the OpenAI models named go through a harness-only route
|
|
122
127
|
// (harness/adapters/index.mjs), each only if it was checked for that model.
|
|
123
128
|
const via = option('via');
|
|
@@ -279,6 +284,10 @@ async function ask(prompt, model, renderer, imageId) {
|
|
|
279
284
|
// Claude Code runs the same tool in the same sandbox on the Claude subscription (harness/claude-code.mjs).
|
|
280
285
|
const { drawWithClaudeCode } = await import('../harness/claude-code.mjs');
|
|
281
286
|
result = await drawWithClaudeCode({ model: model.model, effort, maxOutputTokens: cap, text, tool, sandbox, limits: budget });
|
|
287
|
+
} else if (viaGrokBuild(model)) {
|
|
288
|
+
// Grok Build runs the same tool in the same sandbox on the Grok plan (harness/grok-build.mjs).
|
|
289
|
+
const { drawWithGrokBuild } = await import('../harness/grok-build.mjs');
|
|
290
|
+
result = await drawWithGrokBuild({ model: model.model, effort, text, tool, sandbox, limits: budget });
|
|
282
291
|
} else if (viaCodex(model)) {
|
|
283
292
|
// Codex runs the same tool in the same sandbox on the ChatGPT subscription (harness/codex.mjs).
|
|
284
293
|
const { drawWithCodex } = await import('../harness/codex.mjs');
|
|
@@ -321,11 +330,11 @@ async function ask(prompt, model, renderer, imageId) {
|
|
|
321
330
|
}
|
|
322
331
|
const outcome = result.exit === 'refused' ? 'refused' : svg ? 'drawn' : 'invalid';
|
|
323
332
|
// Dollars as the provider reports them, or worked out from list prices.
|
|
324
|
-
// The subscription pays for a Claude Code or
|
|
333
|
+
// The subscription pays for a Claude Code, Codex or Grok Build run, so its figure is what the API would have charged.
|
|
325
334
|
const usage = {
|
|
326
335
|
...result.usage,
|
|
327
336
|
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' :
|
|
337
|
+
costIs: result.usage.cost ? 'reported' : ['claude-code', 'codex', 'grok-build'].includes(result.route.via) ? 'subscription' : 'estimated',
|
|
329
338
|
};
|
|
330
339
|
|
|
331
340
|
await mkdir(join(OUT, 'log', prompt.id), { recursive: true });
|
|
@@ -342,8 +351,8 @@ async function ask(prompt, model, renderer, imageId) {
|
|
|
342
351
|
baseUrl: result.route.url,
|
|
343
352
|
apiModel: model.model,
|
|
344
353
|
effort: effort ?? null,
|
|
345
|
-
// Codex
|
|
346
|
-
maxOutputTokens: viaCodex(model) ? null : cap,
|
|
354
|
+
// Codex and Grok Build send no output cap of ours: the plan's own applies.
|
|
355
|
+
maxOutputTokens: viaCodex(model) || viaGrokBuild(model) ? null : cap,
|
|
347
356
|
servedModel: result.servedModel,
|
|
348
357
|
responseIds: result.responseIds,
|
|
349
358
|
askedAt,
|
|
@@ -473,11 +482,11 @@ if (flag('sheet')) {
|
|
|
473
482
|
const wanted = [];
|
|
474
483
|
for (const model of models.filter((m) => !onlyModels || onlyModels.includes(m.id)).map(routed)) {
|
|
475
484
|
// 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.`);
|
|
485
|
+
if (!onPlan(model) && !flag('paid')) {
|
|
486
|
+
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
487
|
continue;
|
|
479
488
|
}
|
|
480
|
-
if (!
|
|
489
|
+
if (!onPlan(model) && !process.env[keyOf(model)]) {
|
|
481
490
|
console.log(`Skipping ${model.name}: ${keyOf(model)} is not set.`);
|
|
482
491
|
continue;
|
|
483
492
|
}
|
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,
|
|
@@ -71,8 +74,14 @@ for (const p of wantedPrompts) if (!prompts.some((x) => x.id === p)) stop(`There
|
|
|
71
74
|
|
|
72
75
|
/* What it runs on ---------------------------------------------------------- */
|
|
73
76
|
|
|
74
|
-
const route = model.via === 'anthropic' && !flag('api') ? 'Claude Code' : model.via === 'openai' && flag('codex') ? 'Codex' : 'API';
|
|
75
77
|
const keyName = KEYS[model.via];
|
|
78
|
+
// An OpenAI model with no API key goes to the ChatGPT plan when the Codex CLI is here, without being told to.
|
|
79
|
+
const codexBin = process.env.CODEX_BIN || 'codex';
|
|
80
|
+
const codex = model.via === 'openai' && (flag('codex') || (!process.env[keyName] && works(codexBin, ['--version'])));
|
|
81
|
+
// The same for an xAI model and the Grok plan, with Grok Build.
|
|
82
|
+
const grokBin = process.env.GROK_BIN || 'grok';
|
|
83
|
+
const grokBuild = model.via === 'xai' && (flag('grok-build') || (!process.env[keyName] && works(grokBin, ['--version'])));
|
|
84
|
+
const route = model.via === 'anthropic' && !flag('api') ? 'Claude Code' : codex ? 'Codex' : grokBuild ? 'Grok Build' : 'API';
|
|
76
85
|
const chrome = findChrome();
|
|
77
86
|
const missing = check({ model, route });
|
|
78
87
|
|
|
@@ -96,7 +105,9 @@ if (!dryRun && !works('docker', ['image', 'inspect', IMAGE])) {
|
|
|
96
105
|
|
|
97
106
|
// --paid: the partner's own key pays, which is what a partner run is.
|
|
98
107
|
const harnessArgs = ['scripts/harness.mjs', '--model', model.id, '--prompt', wantedPrompts.join(','), '--out', OUT, '--paid'];
|
|
99
|
-
for (const name of ['
|
|
108
|
+
for (const name of ['api', 'dry-run']) if (flag(name)) harnessArgs.push(`--${name}`);
|
|
109
|
+
if (codex) harnessArgs.push('--codex');
|
|
110
|
+
if (grokBuild) harnessArgs.push('--grok-build');
|
|
100
111
|
if (option('concurrency')) harnessArgs.push('--concurrency', option('concurrency'));
|
|
101
112
|
const ran = spawnSync(process.execPath, harnessArgs, {
|
|
102
113
|
cwd: ROOT,
|