@bendyline/gezel-cli 1.2.11 → 1.2.13
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/README.md +9 -1
- package/dist/app-author-command.js +6 -3
- package/dist/app-command.js +3 -0
- package/dist/bin/gezel-main.js +1186 -96
- package/dist/handboek-export.js +2756 -1435
- package/dist/knowledge-command.js +3 -0
- package/dist/tui/index.js +54 -3
- package/package.json +10 -10
package/dist/bin/gezel-main.js
CHANGED
|
@@ -8,13 +8,16 @@ import {
|
|
|
8
8
|
IMAGE_QUALITIES,
|
|
9
9
|
ImageAspectRatioSchema,
|
|
10
10
|
ImageQualitySchema,
|
|
11
|
+
SCORECARD,
|
|
11
12
|
evaluateApiCompat as evaluateApiCompat2,
|
|
12
13
|
getLogLevel as getLogLevel2,
|
|
13
14
|
getLogOutput as getLogOutput2,
|
|
14
15
|
setLogLevel as setLogLevel2,
|
|
15
16
|
setLogOutput as setLogOutput2
|
|
16
17
|
} from "@bendyline/gezel";
|
|
17
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
streamChatEvents
|
|
20
|
+
} from "@bendyline/gezel-client";
|
|
18
21
|
import {
|
|
19
22
|
GezelClient as GezelClient2,
|
|
20
23
|
createTrustingFetch as createTrustingFetch2,
|
|
@@ -30,42 +33,15 @@ import {
|
|
|
30
33
|
import { resolveOnDeviceProvider as resolveOnDeviceProvider3 } from "@bendyline/gezel/native";
|
|
31
34
|
import { Command, Option } from "commander";
|
|
32
35
|
|
|
33
|
-
// src/
|
|
34
|
-
|
|
35
|
-
if (!(err instanceof Error)) return null;
|
|
36
|
-
if (err.name === "CliError") return err.message;
|
|
37
|
-
if (err.name !== "GezelApiError" || env2.GEZEL_DEBUG === "1") return null;
|
|
38
|
-
const { status, details } = err;
|
|
39
|
-
const request = /\bon ([A-Z]+ \S+)/.exec(err.message)?.[1];
|
|
40
|
-
const serviceText = detailText(details);
|
|
41
|
-
if (status === 404) {
|
|
42
|
-
const what = serviceText && serviceText.toLowerCase() !== "not found" ? serviceText : void 0;
|
|
43
|
-
return `error: not found${what ? `: ${what}` : request ? ` (${request})` : ""}`;
|
|
44
|
-
}
|
|
45
|
-
const lines = [`error: ${serviceText ?? err.message}`];
|
|
46
|
-
if (serviceText && request) lines.push(`(Gezel service answered ${status ?? "?"} to ${request})`);
|
|
47
|
-
lines.push("Set GEZEL_DEBUG=1 to see the full error.");
|
|
48
|
-
return lines.join("\n");
|
|
49
|
-
}
|
|
50
|
-
function isNotFound(err) {
|
|
51
|
-
return err instanceof Error && err.name === "GezelApiError" && err.status === 404;
|
|
52
|
-
}
|
|
53
|
-
function detailText(details) {
|
|
54
|
-
if (typeof details === "string" && details.trim()) return details.trim();
|
|
55
|
-
if (details && typeof details === "object") {
|
|
56
|
-
for (const key of ["message", "error"]) {
|
|
57
|
-
const value = details[key];
|
|
58
|
-
if (typeof value === "string" && value.trim()) return value.trim();
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return void 0;
|
|
62
|
-
}
|
|
36
|
+
// src/account-command.ts
|
|
37
|
+
import { GezelApiError as GezelApiError2, apiErrorMessage } from "@bendyline/gezel-client";
|
|
63
38
|
|
|
64
39
|
// src/connection.ts
|
|
65
40
|
import { createHash, randomUUID } from "crypto";
|
|
66
41
|
import { chmod, mkdir, readFile, realpath, rm, writeFile } from "fs/promises";
|
|
67
42
|
import { homedir } from "os";
|
|
68
43
|
import { basename, dirname, join, resolve } from "path";
|
|
44
|
+
import { fileURLToPath } from "url";
|
|
69
45
|
import {
|
|
70
46
|
evaluateApiCompat,
|
|
71
47
|
getLogLevel,
|
|
@@ -83,6 +59,7 @@ import {
|
|
|
83
59
|
authorizeLocalOwner
|
|
84
60
|
} from "@bendyline/gezel-app-sdk";
|
|
85
61
|
import {
|
|
62
|
+
DaemonInAnotherNamespaceError,
|
|
86
63
|
GezelApiError,
|
|
87
64
|
GezelClient,
|
|
88
65
|
LiveDaemonUnhealthyError,
|
|
@@ -96,6 +73,7 @@ import {
|
|
|
96
73
|
readSystemServiceEndpoint,
|
|
97
74
|
resolveDaemonEntry,
|
|
98
75
|
stopOwnedDaemon,
|
|
76
|
+
systemServiceRuntimeIsStale,
|
|
99
77
|
systemSharedAssetsDir
|
|
100
78
|
} from "@bendyline/gezel-client/node";
|
|
101
79
|
import { gezelHome, gezelPaths, nativePayloadVerificationPath } from "@bendyline/gezel/paths";
|
|
@@ -196,7 +174,7 @@ async function connectOwned(globals, options = {}) {
|
|
|
196
174
|
...process.env.GEZEL_HOME ? { home: process.env.GEZEL_HOME } : {}
|
|
197
175
|
}
|
|
198
176
|
}).catch((error) => {
|
|
199
|
-
throw isIncompatibleDaemonError(error) ? incompatibleDaemonCliError(error) : error;
|
|
177
|
+
throw isIncompatibleDaemonError(error) ? incompatibleDaemonCliError(error) : localDaemonCliError(error) ?? error;
|
|
200
178
|
});
|
|
201
179
|
if (authorized.daemon.mode === "spawned" && options.announceSpawn !== false) {
|
|
202
180
|
process.stderr.write(spawnedDaemonNotice(authorized.daemon.pid));
|
|
@@ -207,6 +185,17 @@ async function connectOwned(globals, options = {}) {
|
|
|
207
185
|
);
|
|
208
186
|
return connected.client;
|
|
209
187
|
}
|
|
188
|
+
var NO_RUNNING_SERVICE_MESSAGE = "No Gezel service is running, and --no-start keeps this command from starting one. Run `gezel start` first, or leave out --no-start.";
|
|
189
|
+
async function connectRunning(globals, deps = {}) {
|
|
190
|
+
applyHome(globals);
|
|
191
|
+
const preferred = await connectPreferredService(globals);
|
|
192
|
+
if (preferred) return preferred.client;
|
|
193
|
+
const runtime = await (deps.readRuntime ?? readRuntime)();
|
|
194
|
+
if (!runtime || !(deps.isAlive ?? isProcessAlive)(runtime.pid)) {
|
|
195
|
+
throw new CliError(NO_RUNNING_SERVICE_MESSAGE);
|
|
196
|
+
}
|
|
197
|
+
return (deps.connectOwned ?? connectOwned)(globals, { announceSpawn: false });
|
|
198
|
+
}
|
|
210
199
|
async function connectForTui(globals) {
|
|
211
200
|
applyHome(globals);
|
|
212
201
|
const preferred = await connectPreferredService(globals);
|
|
@@ -286,9 +275,8 @@ async function authorizeLocalOwnedDaemon(deps = {}) {
|
|
|
286
275
|
});
|
|
287
276
|
return await (deps.connect ?? defaultConnectAsOwner)(authorized);
|
|
288
277
|
} catch (error) {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
}
|
|
278
|
+
const local = localDaemonCliError(error);
|
|
279
|
+
if (local) throw local;
|
|
292
280
|
if (!(error instanceof GezelSdkError) || error.code !== "daemon_not_running") {
|
|
293
281
|
throw cliGrantError(error, "the local Gezel daemon");
|
|
294
282
|
}
|
|
@@ -302,6 +290,13 @@ async function authorizeLocalOwnedDaemon(deps = {}) {
|
|
|
302
290
|
function defaultConnectAsOwner(authorized) {
|
|
303
291
|
return connectionFromAuthorization(authorized, "The local Gezel owner authorization");
|
|
304
292
|
}
|
|
293
|
+
function localDaemonCliError(error) {
|
|
294
|
+
if (error instanceof LiveDaemonUnhealthyError) {
|
|
295
|
+
return unhealthyLocalDaemonError(error.pid, error.baseUrl);
|
|
296
|
+
}
|
|
297
|
+
if (error instanceof DaemonInAnotherNamespaceError) return new CliError(error.message);
|
|
298
|
+
return null;
|
|
299
|
+
}
|
|
305
300
|
function unhealthyLocalDaemonError(pid, baseUrl) {
|
|
306
301
|
return new CliError(
|
|
307
302
|
`The local Gezel daemon (pid ${pid}) is running but did not answer at ${baseUrl}. Stop or repair it before retrying.`
|
|
@@ -445,7 +440,16 @@ async function describeMachineEngineBroker(deps = {}) {
|
|
|
445
440
|
...health.startedAt !== void 0 ? { startedAt: health.startedAt } : {}
|
|
446
441
|
};
|
|
447
442
|
} catch {
|
|
448
|
-
|
|
443
|
+
const stale = await (deps.isRuntimeStale ?? systemServiceRuntimeIsStale)(endpoint.home).catch(
|
|
444
|
+
() => false
|
|
445
|
+
);
|
|
446
|
+
return {
|
|
447
|
+
present: true,
|
|
448
|
+
healthy: false,
|
|
449
|
+
baseUrl: endpoint.baseUrl,
|
|
450
|
+
port: endpoint.port,
|
|
451
|
+
...stale ? { staleRuntimeDir: join(endpoint.home, "runtime") } : {}
|
|
452
|
+
};
|
|
449
453
|
} finally {
|
|
450
454
|
clearTimeout(timeout);
|
|
451
455
|
}
|
|
@@ -570,12 +574,18 @@ var CLI_CLIENT_LABEL = "this gezel CLI";
|
|
|
570
574
|
function isIncompatibleDaemonError(error) {
|
|
571
575
|
return error instanceof GezelSdkError && error.code === "daemon_incompatible";
|
|
572
576
|
}
|
|
577
|
+
function cliUpdateCommand(moduleUrl = import.meta.url) {
|
|
578
|
+
const path = fileURLToPath(moduleUrl).replaceAll("\\", "/");
|
|
579
|
+
if (path.includes("/_npx/")) return "npx gezel-cli@latest";
|
|
580
|
+
const shortName = path.includes("/node_modules/gezel-cli/node_modules/@bendyline/gezel-cli/");
|
|
581
|
+
return `npm install -g ${shortName ? "gezel-cli" : "@bendyline/gezel-cli"}`;
|
|
582
|
+
}
|
|
573
583
|
function incompatibleDaemonCliError(source) {
|
|
574
584
|
const verdict = source instanceof GezelSdkError ? { ...source.cause, systemService: false } : source;
|
|
575
585
|
const service = `the Gezel service${verdict.version ? ` (${verdict.version})` : ""}`;
|
|
576
586
|
if (verdict.code === "client-too-old") {
|
|
577
587
|
return new CliError(
|
|
578
|
-
`This gezel CLI is older than ${service} supports. Update it with
|
|
588
|
+
`This gezel CLI is older than ${service} supports. Update it with \`${cliUpdateCommand()}\`, then try again.`
|
|
579
589
|
);
|
|
580
590
|
}
|
|
581
591
|
if (verdict.code === "machine-engine-role") {
|
|
@@ -769,6 +779,691 @@ async function resolveTuiProject(client, globals) {
|
|
|
769
779
|
return resolveCommandProject(client, globals);
|
|
770
780
|
}
|
|
771
781
|
|
|
782
|
+
// src/account-command.ts
|
|
783
|
+
async function readNewPassword(options, input = process.stdin, write = (text) => process.stderr.write(text)) {
|
|
784
|
+
if (options.passwordStdin) {
|
|
785
|
+
if (input.isTTY) throw new CliError("--password-stdin needs piped input.");
|
|
786
|
+
const chunks = [];
|
|
787
|
+
for await (const chunk of input) {
|
|
788
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
789
|
+
if (chunks.reduce((n, c) => n + c.length, 0) > 4096) {
|
|
790
|
+
throw new CliError("The password is too long.");
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
return Buffer.concat(chunks).toString("utf8").replace(/\r?\n$/, "");
|
|
794
|
+
}
|
|
795
|
+
if (!input.isTTY || !input.setRawMode) {
|
|
796
|
+
throw new CliError("No terminal to type a password into. Pipe it in with --password-stdin.");
|
|
797
|
+
}
|
|
798
|
+
const first = await promptHidden("New password: ", input, write);
|
|
799
|
+
const second = await promptHidden("Type it again: ", input, write);
|
|
800
|
+
if (first !== second) throw new CliError("The two passwords did not match.");
|
|
801
|
+
return first;
|
|
802
|
+
}
|
|
803
|
+
function promptHidden(prompt, input, write) {
|
|
804
|
+
write(prompt);
|
|
805
|
+
return new Promise((resolve7, reject) => {
|
|
806
|
+
let value = "";
|
|
807
|
+
const done = (error) => {
|
|
808
|
+
input.off?.("data", onData);
|
|
809
|
+
input.setRawMode?.(false);
|
|
810
|
+
input.pause?.();
|
|
811
|
+
write("\n");
|
|
812
|
+
if (error) reject(error);
|
|
813
|
+
else resolve7(value);
|
|
814
|
+
};
|
|
815
|
+
const onData = (chunk) => {
|
|
816
|
+
for (const ch of chunk.toString("utf8")) {
|
|
817
|
+
if (ch === "\r" || ch === "\n") return done();
|
|
818
|
+
if (ch === "") return done(new CliError("Canceled."));
|
|
819
|
+
if (ch === "\x7F" || ch === "\b") value = value.slice(0, -1);
|
|
820
|
+
else if (ch >= " ") value += ch;
|
|
821
|
+
}
|
|
822
|
+
};
|
|
823
|
+
input.setRawMode?.(true);
|
|
824
|
+
input.resume?.();
|
|
825
|
+
input.on?.("data", onData);
|
|
826
|
+
});
|
|
827
|
+
}
|
|
828
|
+
async function findAccount(client, name) {
|
|
829
|
+
const key = name.trim().toLowerCase();
|
|
830
|
+
const { accounts } = await client.listAccounts();
|
|
831
|
+
const match = accounts.find((a) => a.name.toLowerCase() === key || a.id === name);
|
|
832
|
+
if (!match) throw new CliError(`There is no account called "${name}". See "gezel account list".`);
|
|
833
|
+
return match;
|
|
834
|
+
}
|
|
835
|
+
async function plainly(run) {
|
|
836
|
+
try {
|
|
837
|
+
return await run();
|
|
838
|
+
} catch (error) {
|
|
839
|
+
if (error instanceof GezelApiError2 && error.status < 500 && error.status > 0) {
|
|
840
|
+
const details = error.details;
|
|
841
|
+
if (error.status === 404 && details?.error === "accounts_unavailable") {
|
|
842
|
+
throw new CliError("This Gezel service has no accounts.");
|
|
843
|
+
}
|
|
844
|
+
throw new CliError(apiErrorMessage(error));
|
|
845
|
+
}
|
|
846
|
+
throw error;
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
function describeAccount(account) {
|
|
850
|
+
const state = account.disabledAt ? "disabled" : account.role;
|
|
851
|
+
const seen = account.lastSignInAt ? `last signed in ${account.lastSignInAt.slice(0, 10)}` : "never signed in";
|
|
852
|
+
return `${account.name} ${state} ${seen}`;
|
|
853
|
+
}
|
|
854
|
+
function describeSession(session) {
|
|
855
|
+
return [
|
|
856
|
+
session.label ?? "unknown",
|
|
857
|
+
session.address ?? "",
|
|
858
|
+
`last seen ${session.lastSeenAt.slice(0, 16).replace("T", " ")}`
|
|
859
|
+
].filter(Boolean).join(" ");
|
|
860
|
+
}
|
|
861
|
+
function registerAccountCommands(program2, connect, output = console.log, input = process.stdin) {
|
|
862
|
+
const account = program2.command("account").description("Manage the accounts that sign in to this Gezel from a browser");
|
|
863
|
+
account.command("list").description("List accounts").option("--json", "Output as JSON").action(async (options) => {
|
|
864
|
+
const { accounts } = await plainly(async () => (await connect()).listAccounts());
|
|
865
|
+
if (options.json) return output(JSON.stringify({ accounts }));
|
|
866
|
+
output(accounts.length ? accounts.map(describeAccount).join("\n") : "No accounts yet.");
|
|
867
|
+
});
|
|
868
|
+
account.command("create <name>").description("Add an account. Everyone you add can do everything you can.").option("--password-stdin", "Read the password from piped stdin").option("--json", "Output as JSON").action(async (name, options) => {
|
|
869
|
+
const client = await connect();
|
|
870
|
+
const password = await readNewPassword(options, input);
|
|
871
|
+
const created = await plainly(() => client.createAccount(name, password));
|
|
872
|
+
output(options.json ? JSON.stringify(created) : `${created.account.name} can now sign in.`);
|
|
873
|
+
});
|
|
874
|
+
account.command("reset-password <name>").description("Set someone's password and sign them out everywhere").option("--password-stdin", "Read the password from piped stdin").action(async (name, options) => {
|
|
875
|
+
const client = await connect();
|
|
876
|
+
const target = await findAccount(client, name);
|
|
877
|
+
const password = await readNewPassword(options, input);
|
|
878
|
+
await plainly(() => client.setAccountPassword(target.id, password));
|
|
879
|
+
output(`${target.name}'s password was changed. They are signed out everywhere.`);
|
|
880
|
+
});
|
|
881
|
+
for (const [verb, disabled, done] of [
|
|
882
|
+
["disable", true, "can no longer sign in"],
|
|
883
|
+
["enable", false, "can sign in again"]
|
|
884
|
+
]) {
|
|
885
|
+
account.command(`${verb} <name>`).description(disabled ? "Stop an account signing in" : "Let a disabled account sign in again").action(async (name) => {
|
|
886
|
+
const client = await connect();
|
|
887
|
+
const target = await findAccount(client, name);
|
|
888
|
+
await plainly(() => client.updateAccount(target.id, { disabled }));
|
|
889
|
+
output(`${target.name} ${done}.`);
|
|
890
|
+
});
|
|
891
|
+
}
|
|
892
|
+
account.command("remove <name>").description("Remove an account and sign it out everywhere").option("--yes", "Do not ask for confirmation").action(async (name, options) => {
|
|
893
|
+
if (!options.yes)
|
|
894
|
+
throw new CliError("Removing an account cannot be undone. Add --yes to go ahead.");
|
|
895
|
+
const client = await connect();
|
|
896
|
+
const target = await findAccount(client, name);
|
|
897
|
+
await plainly(() => client.removeAccount(target.id));
|
|
898
|
+
output(`${target.name} was removed.`);
|
|
899
|
+
});
|
|
900
|
+
account.command("sessions <name>").description("List where an account is signed in").option("--json", "Output as JSON").action(async (name, options) => {
|
|
901
|
+
const client = await connect();
|
|
902
|
+
const target = await findAccount(client, name);
|
|
903
|
+
const { sessions } = await plainly(() => client.listAccountSessions(target.id));
|
|
904
|
+
if (options.json) return output(JSON.stringify({ sessions }));
|
|
905
|
+
output(
|
|
906
|
+
sessions.length ? sessions.map(describeSession).join("\n") : `${target.name} is not signed in anywhere.`
|
|
907
|
+
);
|
|
908
|
+
});
|
|
909
|
+
account.command("sign-out-all <name>").description("Sign an account out of every browser").action(async (name) => {
|
|
910
|
+
const client = await connect();
|
|
911
|
+
const target = await findAccount(client, name);
|
|
912
|
+
const { signedOut } = await plainly(() => client.signOutAccountEverywhere(target.id));
|
|
913
|
+
output(
|
|
914
|
+
`Signed ${target.name} out of ${signedOut} ${signedOut === 1 ? "browser" : "browsers"}.`
|
|
915
|
+
);
|
|
916
|
+
});
|
|
917
|
+
account.command("setup-link").description("Print a new link to create the first account (only while there is none)").action(async () => {
|
|
918
|
+
const { code, url } = await plainly(async () => (await connect()).createSetupLink());
|
|
919
|
+
if (!code)
|
|
920
|
+
throw new CliError('This Gezel already has an account. Use "gezel account create".');
|
|
921
|
+
output(url ? `Open this link to create the first account:
|
|
922
|
+
${url}` : `Setup code: ${code}`);
|
|
923
|
+
});
|
|
924
|
+
}
|
|
925
|
+
function registerIntegrationCommands(program2, connect, output = console.log) {
|
|
926
|
+
const token = program2.command("integrations").description("Connect other apps to this Gezel").command("token").description("Make or revoke an app key");
|
|
927
|
+
token.command("create <appId>").description("Make a key for an app (OpenAI-compatible access by default)").option("--name <name>", "The name Integrations shows for the app").option(
|
|
928
|
+
"--scope <scope...>",
|
|
929
|
+
"What the key may do: openai, knowledge, images, product or cli (default: openai)"
|
|
930
|
+
).option("--json", "Output as JSON").action(async (appId, options) => {
|
|
931
|
+
const client = await connect();
|
|
932
|
+
const created = await plainly(
|
|
933
|
+
() => client.createAppToken(appId, {
|
|
934
|
+
...options.name ? { appName: options.name } : {},
|
|
935
|
+
...options.scope?.length ? { scopes: options.scope } : {}
|
|
936
|
+
})
|
|
937
|
+
);
|
|
938
|
+
if (options.json) return output(JSON.stringify(created));
|
|
939
|
+
output(
|
|
940
|
+
[
|
|
941
|
+
`Key for ${created.appId} (${created.scopes.join(", ")}):`,
|
|
942
|
+
` ${created.token}`,
|
|
943
|
+
"",
|
|
944
|
+
"Use it as the API key, with the base URL ending in /v1.",
|
|
945
|
+
'It is shown once. Revoke it with "gezel integrations token revoke".'
|
|
946
|
+
].join("\n")
|
|
947
|
+
);
|
|
948
|
+
});
|
|
949
|
+
token.command("revoke <appId>").description("Revoke an app's key").action(async (appId) => {
|
|
950
|
+
const { revoked } = await plainly(async () => (await connect()).revokeAppToken(appId));
|
|
951
|
+
output(revoked ? `${appId} can no longer connect.` : `${appId} had no key.`);
|
|
952
|
+
});
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
// src/bench-command.ts
|
|
956
|
+
import { execFile } from "child_process";
|
|
957
|
+
import { readFileSync } from "fs";
|
|
958
|
+
import { readFile as readFile2, writeFile as writeFile2 } from "fs/promises";
|
|
959
|
+
import { cpus } from "os";
|
|
960
|
+
import { join as join2 } from "path";
|
|
961
|
+
import { promisify } from "util";
|
|
962
|
+
import { ScorecardDatasetSchema } from "@bendyline/gezel";
|
|
963
|
+
import { gildePackageRoot } from "@bendyline/gezel-catalog";
|
|
964
|
+
import {
|
|
965
|
+
EVAL_SUBSET_NOTE,
|
|
966
|
+
SCORECARD_SUITE_IDS,
|
|
967
|
+
SCORECARD_SUITE_LABELS,
|
|
968
|
+
buildEvalMatrix,
|
|
969
|
+
describeEvalHost,
|
|
970
|
+
describeEvalRun,
|
|
971
|
+
evalDeviceFromHost,
|
|
972
|
+
evalEngineBuilds,
|
|
973
|
+
evalRunId,
|
|
974
|
+
evalRunProvenance,
|
|
975
|
+
evalShard,
|
|
976
|
+
evalSuiteResult,
|
|
977
|
+
isSuiteSubset,
|
|
978
|
+
medianDecodeTokensPerSec,
|
|
979
|
+
smokeSuiteIdFor
|
|
980
|
+
} from "@bendyline/gezel/eval";
|
|
981
|
+
var BENCH_CONFIRM_ABOVE_MS = 60 * 6e4;
|
|
982
|
+
var BENCH_SUBMIT_REPO = "bendyline/gezel";
|
|
983
|
+
function formatDuration(ms) {
|
|
984
|
+
if (ms < 6e4) return `${Math.max(1, Math.round(ms / 1e3))}s`;
|
|
985
|
+
const minutes = Math.round(ms / 6e4);
|
|
986
|
+
if (minutes < 60) return `${minutes}m`;
|
|
987
|
+
const hours = Math.floor(minutes / 60);
|
|
988
|
+
const rest = minutes % 60;
|
|
989
|
+
return rest ? `${hours}h ${rest}m` : `${hours}h`;
|
|
990
|
+
}
|
|
991
|
+
function resolveBenchSuites(catalog, opts) {
|
|
992
|
+
const wanted = !opts.suite || opts.suite === "core" || opts.suite === "default" ? ["core"] : opts.suite === "all" ? (
|
|
993
|
+
// Every scorecard suite this daemon's catalog carries; an older
|
|
994
|
+
// harness without one of them still runs the rest.
|
|
995
|
+
SCORECARD_SUITE_IDS.filter((id) => catalog.suites.some((s) => s.id === id))
|
|
996
|
+
) : opts.suite.split(",").map((s) => s.trim()).filter(Boolean);
|
|
997
|
+
const suites = [];
|
|
998
|
+
for (const id of wanted) {
|
|
999
|
+
const base = catalog.suites.find((s) => s.id === id);
|
|
1000
|
+
if (!base) {
|
|
1001
|
+
throw new CliError(
|
|
1002
|
+
`Unknown suite "${id}". Choose one of: ${SCORECARD_SUITE_IDS.join(", ")}, or all. \`gezel bench list\` shows every suite.`
|
|
1003
|
+
);
|
|
1004
|
+
}
|
|
1005
|
+
if (opts.smoke) {
|
|
1006
|
+
const smokeId = smokeSuiteIdFor(id, catalog);
|
|
1007
|
+
const smoke = smokeId ? catalog.suites.find((s) => s.id === smokeId) : void 0;
|
|
1008
|
+
if (!smoke) {
|
|
1009
|
+
throw new CliError(`The ${id} suite has no smoke variant in this catalog.`);
|
|
1010
|
+
}
|
|
1011
|
+
suites.push(smoke);
|
|
1012
|
+
} else {
|
|
1013
|
+
suites.push(base);
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
return suites;
|
|
1017
|
+
}
|
|
1018
|
+
function resolveBenchTarget(catalog, targets, opts) {
|
|
1019
|
+
const available = targets.filter((t) => t.available);
|
|
1020
|
+
if (opts.model) {
|
|
1021
|
+
const matches = available.filter(
|
|
1022
|
+
(t) => t.modelId === opts.model && (!opts.provider || t.provider === opts.provider)
|
|
1023
|
+
);
|
|
1024
|
+
const preferred = matches.find((t) => t.provider === catalog.defaultProvider) ?? matches[0];
|
|
1025
|
+
if (preferred) return preferred;
|
|
1026
|
+
const unavailable = targets.find(
|
|
1027
|
+
(t) => t.modelId === opts.model && (!opts.provider || t.provider === opts.provider)
|
|
1028
|
+
);
|
|
1029
|
+
throw new CliError(
|
|
1030
|
+
unavailable?.unavailableReason ? `${opts.model} can't run here: ${unavailable.unavailableReason}` : `No model "${opts.model}"${opts.provider ? ` on ${opts.provider}` : ""} is available to evaluate. \`gezel model list\` shows what is installed.`
|
|
1031
|
+
);
|
|
1032
|
+
}
|
|
1033
|
+
const byProvider = opts.provider ? available.filter((t) => t.provider === opts.provider) : available;
|
|
1034
|
+
const chosen = byProvider.find((t) => t.isDefault && t.provider === catalog.defaultProvider) ?? byProvider.find((t) => t.isDefault) ?? byProvider.find((t) => t.provider === catalog.defaultProvider) ?? byProvider[0];
|
|
1035
|
+
if (!chosen) {
|
|
1036
|
+
throw new CliError(
|
|
1037
|
+
"No model is available to evaluate. Download one with `gezel model pull <id>` or sign in to a cloud provider, then try again."
|
|
1038
|
+
);
|
|
1039
|
+
}
|
|
1040
|
+
return chosen;
|
|
1041
|
+
}
|
|
1042
|
+
function planBench(catalog, targets, opts) {
|
|
1043
|
+
const count = opts.count ?? 1;
|
|
1044
|
+
if (!Number.isInteger(count) || count < 1 || count > 10) {
|
|
1045
|
+
throw new CliError(
|
|
1046
|
+
"--count must be a whole number from 1 to 10 (3 is what it takes to quote a rate)."
|
|
1047
|
+
);
|
|
1048
|
+
}
|
|
1049
|
+
const suites = resolveBenchSuites(catalog, opts);
|
|
1050
|
+
const target = resolveBenchTarget(catalog, targets, opts);
|
|
1051
|
+
const worstCaseMs = suites.reduce((sum, s) => sum + s.authoredCeilingMs * count, 0);
|
|
1052
|
+
return { suites, target, count, worstCaseMs, smoke: Boolean(opts.smoke) };
|
|
1053
|
+
}
|
|
1054
|
+
function describePlan(plan, catalog) {
|
|
1055
|
+
const lines = [
|
|
1056
|
+
`Model: ${plan.target.label} (${plan.target.modelId} on ${plan.target.provider})`,
|
|
1057
|
+
`Trials per task: ${plan.count}${plan.count < catalog.minTrialsForRate ? ` \u2014 results show as counts; ${catalog.minTrialsForRate} trials is what it takes to quote a rate` : ""}`
|
|
1058
|
+
];
|
|
1059
|
+
for (const suite of plan.suites) {
|
|
1060
|
+
lines.push(
|
|
1061
|
+
`Suite: ${suite.id} \u2014 ${suite.scenarioIds.length} tasks, at most ${formatDuration(
|
|
1062
|
+
suite.authoredCeilingMs * plan.count
|
|
1063
|
+
)}`
|
|
1064
|
+
);
|
|
1065
|
+
if (plan.smoke) lines.push(` ${suite.description}`);
|
|
1066
|
+
}
|
|
1067
|
+
lines.push(
|
|
1068
|
+
`At most ${formatDuration(plan.worstCaseMs)} in all. The run keeps going if this terminal closes.`
|
|
1069
|
+
);
|
|
1070
|
+
return lines;
|
|
1071
|
+
}
|
|
1072
|
+
function describeJobOutcome(job) {
|
|
1073
|
+
switch (job.status) {
|
|
1074
|
+
case "completed":
|
|
1075
|
+
return null;
|
|
1076
|
+
case "failed":
|
|
1077
|
+
return `The run could not start: ${job.error ?? "the harness reported a setup error"}.`;
|
|
1078
|
+
case "cancelled":
|
|
1079
|
+
return "The run was stopped before it finished.";
|
|
1080
|
+
case "interrupted":
|
|
1081
|
+
return "The Gezel service stopped while the run was in progress; the trials it finished are counted.";
|
|
1082
|
+
default:
|
|
1083
|
+
return `The run ended in state "${job.status}".`;
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
function renderSuiteReport(suite, target, trials, minTrialsForRate) {
|
|
1087
|
+
const matrix = buildEvalMatrix(trials, { scenarioOrder: suite.scenarioIds });
|
|
1088
|
+
const column = matrix.columns.find(
|
|
1089
|
+
(c) => c.modelId === target.modelId && (c.provider ?? target.provider) === target.provider
|
|
1090
|
+
);
|
|
1091
|
+
const width = Math.min(40, Math.max(12, ...suite.scenarioIds.map((id) => id.length)) + 2);
|
|
1092
|
+
const lines = [];
|
|
1093
|
+
for (const scenarioId of suite.scenarioIds) {
|
|
1094
|
+
const cell = column ? matrix.cell(scenarioId, column.key) : void 0;
|
|
1095
|
+
const claim = cell ? cell.claim : "not run";
|
|
1096
|
+
const extra = cell?.nonModelFailures ? ` (${cell.nonModelFailures} not counted: not the model's fault)` : "";
|
|
1097
|
+
lines.push(` ${scenarioId.padEnd(width)}${claim}${extra}`);
|
|
1098
|
+
}
|
|
1099
|
+
const total = column ? column.claim : "not measured";
|
|
1100
|
+
const label = SCORECARD_SUITE_LABELS[suite.id] ?? suite.id;
|
|
1101
|
+
lines.push(` ${"suite".padEnd(width)}${total}`);
|
|
1102
|
+
if (column && column.passRate === null && column.attributableTrials > 0) {
|
|
1103
|
+
lines.push(
|
|
1104
|
+
` A count, not a rate: ${minTrialsForRate} trials per task is the floor for quoting a percentage.`
|
|
1105
|
+
);
|
|
1106
|
+
}
|
|
1107
|
+
const decode = medianDecodeTokensPerSec(trials);
|
|
1108
|
+
lines.push(
|
|
1109
|
+
` Decode: ${decode ? `${decode.toFixed(1)} tok/s (median over finished tasks)` : "not recorded"}. Prefill: not recorded by the daemon's trial index.`
|
|
1110
|
+
);
|
|
1111
|
+
return [`${label} (${suite.id})`, ...lines];
|
|
1112
|
+
}
|
|
1113
|
+
function createJobFollower(suite, count) {
|
|
1114
|
+
let lastTrial = null;
|
|
1115
|
+
let lastCompleted = -1;
|
|
1116
|
+
let announcedWaiting = false;
|
|
1117
|
+
let announcedPreflight = false;
|
|
1118
|
+
return {
|
|
1119
|
+
update(job) {
|
|
1120
|
+
const lines = [];
|
|
1121
|
+
const target = job.targets[0];
|
|
1122
|
+
if (job.status === "waiting-for-device" && !announcedWaiting) {
|
|
1123
|
+
announcedWaiting = true;
|
|
1124
|
+
lines.push(
|
|
1125
|
+
`Waiting: another evaluation${job.waitingOn ? ` (${job.waitingOn})` : ""} holds this machine's engines.`
|
|
1126
|
+
);
|
|
1127
|
+
}
|
|
1128
|
+
if (!target) return lines;
|
|
1129
|
+
if (target.preflight && !announcedPreflight) {
|
|
1130
|
+
announcedPreflight = true;
|
|
1131
|
+
const p = target.preflight;
|
|
1132
|
+
lines.push(
|
|
1133
|
+
p.admitted === null ? `Fitness check skipped${p.skippedReason ? `: ${p.skippedReason}` : ""}.` : p.admitted ? `Fitness check passed${p.decodeTokensPerSec ? ` \xB7 ${p.decodeTokensPerSec.toFixed(1)} tok/s` : ""}.` : `Fitness check failed${p.skippedReason ? `: ${p.skippedReason}` : ""}.`
|
|
1134
|
+
);
|
|
1135
|
+
}
|
|
1136
|
+
const planned = target.plannedTrials ?? suite.scenarioIds.length * count;
|
|
1137
|
+
if (target.completedTrials !== lastCompleted && lastCompleted >= 0) {
|
|
1138
|
+
lines.push(` ${target.completedTrials}/${planned} done, ${target.passedTrials} passed`);
|
|
1139
|
+
}
|
|
1140
|
+
lastCompleted = target.completedTrials;
|
|
1141
|
+
const current = target.currentTrial;
|
|
1142
|
+
if (current && current.trialId !== lastTrial) {
|
|
1143
|
+
lastTrial = current.trialId;
|
|
1144
|
+
lines.push(` ${current.scenarioId} (${current.trialIndex}/${planned}) running\u2026`);
|
|
1145
|
+
}
|
|
1146
|
+
return lines;
|
|
1147
|
+
}
|
|
1148
|
+
};
|
|
1149
|
+
}
|
|
1150
|
+
function finishedJob(job) {
|
|
1151
|
+
return job.status === "completed" || job.status === "failed" || job.status === "cancelled" || job.status === "interrupted";
|
|
1152
|
+
}
|
|
1153
|
+
async function followJob(client, job, suite, count, io, verbose = false) {
|
|
1154
|
+
const follower = createJobFollower(suite, count);
|
|
1155
|
+
let latest = job;
|
|
1156
|
+
for (const line of follower.update(job)) io.note(line);
|
|
1157
|
+
await client.streamEvalJob(job.id, (event) => {
|
|
1158
|
+
if (event.type === "log") {
|
|
1159
|
+
if (verbose) io.note(` ${event.line}`);
|
|
1160
|
+
return;
|
|
1161
|
+
}
|
|
1162
|
+
latest = event.job;
|
|
1163
|
+
for (const line of follower.update(event.job)) io.note(line);
|
|
1164
|
+
});
|
|
1165
|
+
if (!finishedJob(latest)) latest = await client.getEvalJob(job.id);
|
|
1166
|
+
return latest;
|
|
1167
|
+
}
|
|
1168
|
+
function defaultGildeVersion() {
|
|
1169
|
+
try {
|
|
1170
|
+
const pkg = JSON.parse(readFileSync(join2(gildePackageRoot(), "package.json"), "utf8"));
|
|
1171
|
+
return pkg.version ?? "unknown";
|
|
1172
|
+
} catch {
|
|
1173
|
+
return "unknown";
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
function defaultCpuModel() {
|
|
1177
|
+
return cpus()[0]?.model?.trim() || void 0;
|
|
1178
|
+
}
|
|
1179
|
+
async function runBench(client, opts, io) {
|
|
1180
|
+
const [catalog, targetsResponse, host] = await Promise.all([
|
|
1181
|
+
client.getEvalCatalog(),
|
|
1182
|
+
client.listEvalTargets(),
|
|
1183
|
+
client.getSystemDiagnostics()
|
|
1184
|
+
]);
|
|
1185
|
+
const plan = planBench(catalog, targetsResponse.targets, opts);
|
|
1186
|
+
const cpuModel = io.cpuModel ? io.cpuModel() : void 0;
|
|
1187
|
+
io.note(describeEvalHost(host, cpuModel));
|
|
1188
|
+
for (const line of describePlan(plan, catalog)) io.note(line);
|
|
1189
|
+
if (plan.worstCaseMs > BENCH_CONFIRM_ABOVE_MS && !opts.yes) {
|
|
1190
|
+
if (!io.confirm) {
|
|
1191
|
+
throw new CliError(
|
|
1192
|
+
`This run could take ${formatDuration(plan.worstCaseMs)}. Add --yes to start it without a prompt.`
|
|
1193
|
+
);
|
|
1194
|
+
}
|
|
1195
|
+
const go = await io.confirm(`Start a run of up to ${formatDuration(plan.worstCaseMs)}? [y/N] `);
|
|
1196
|
+
if (!go) throw new CliError("Not started.");
|
|
1197
|
+
}
|
|
1198
|
+
const startedAt = (io.now?.() ?? /* @__PURE__ */ new Date()).toISOString();
|
|
1199
|
+
const device = evalDeviceFromHost(host, cpuModel);
|
|
1200
|
+
const scenariosBySuite = {};
|
|
1201
|
+
const jobs = [];
|
|
1202
|
+
const results = [];
|
|
1203
|
+
const runId = evalRunId(startedAt, device, plan.target.modelId);
|
|
1204
|
+
const gildeVersion = (io.gildeVersion ?? defaultGildeVersion)();
|
|
1205
|
+
const run = evalRunProvenance({
|
|
1206
|
+
id: runId,
|
|
1207
|
+
startedAt,
|
|
1208
|
+
device,
|
|
1209
|
+
gezelVersion: host.version,
|
|
1210
|
+
gildeVersion,
|
|
1211
|
+
count: plan.count,
|
|
1212
|
+
engineBuilds: evalEngineBuilds(host),
|
|
1213
|
+
scenariosBySuite: Object.fromEntries(plan.suites.map((s) => [s.id, s.scenarioIds])),
|
|
1214
|
+
subset: false,
|
|
1215
|
+
...opts.note ? { note: opts.note } : {}
|
|
1216
|
+
});
|
|
1217
|
+
for (const suite of plan.suites) {
|
|
1218
|
+
const spec = {
|
|
1219
|
+
suiteId: suite.id,
|
|
1220
|
+
count: plan.count,
|
|
1221
|
+
...plan.count > 1 ? { countStrict: true } : {},
|
|
1222
|
+
targets: [{ provider: plan.target.provider, modelId: plan.target.modelId }],
|
|
1223
|
+
note: `gezel bench ${runId}`
|
|
1224
|
+
};
|
|
1225
|
+
io.note("");
|
|
1226
|
+
io.note(`Starting ${suite.id}\u2026`);
|
|
1227
|
+
const created = await client.createEvalJob(spec);
|
|
1228
|
+
const job = await followJob(client, created, suite, plan.count, io, opts.verbose);
|
|
1229
|
+
jobs.push(job);
|
|
1230
|
+
scenariosBySuite[suite.id] = suite.scenarioIds;
|
|
1231
|
+
const outcome = describeJobOutcome(job);
|
|
1232
|
+
if (outcome) io.note(outcome);
|
|
1233
|
+
const { trials } = await client.listEvalTrials({ jobId: job.id, limit: 2e3 });
|
|
1234
|
+
results.push(evalSuiteResult({ run, suite, target: plan.target, trials }));
|
|
1235
|
+
io.out("");
|
|
1236
|
+
for (const line of renderSuiteReport(suite, plan.target, trials, catalog.minTrialsForRate)) {
|
|
1237
|
+
io.out(line);
|
|
1238
|
+
}
|
|
1239
|
+
if (plan.smoke) io.out(` ${suite.description}`);
|
|
1240
|
+
}
|
|
1241
|
+
io.out("");
|
|
1242
|
+
io.out(describeEvalRun(run, [plan.target.provider]));
|
|
1243
|
+
io.out(
|
|
1244
|
+
`Results are kept in ${targetsResponse.environment.runsDir}; Settings \u2192 Benchmarks shows the same runs.`
|
|
1245
|
+
);
|
|
1246
|
+
const shard = evalShard(run, results);
|
|
1247
|
+
if (opts.json) {
|
|
1248
|
+
await writeFile2(opts.json, `${JSON.stringify(shard, null, 2)}
|
|
1249
|
+
`, "utf8");
|
|
1250
|
+
io.out(`Wrote ${opts.json}. Share it with \`gezel bench submit ${opts.json}\`.`);
|
|
1251
|
+
}
|
|
1252
|
+
return { run, results, jobs, shard };
|
|
1253
|
+
}
|
|
1254
|
+
function renderSuiteList(catalog) {
|
|
1255
|
+
const width = Math.max(...catalog.suites.map((s) => s.id.length)) + 2;
|
|
1256
|
+
const lines = [
|
|
1257
|
+
"Suites (`gezel bench --suite <id>`); times are the authored ceilings at one trial per task:"
|
|
1258
|
+
];
|
|
1259
|
+
const scorecard = catalog.suites.filter(
|
|
1260
|
+
(s) => SCORECARD_SUITE_IDS.includes(s.id)
|
|
1261
|
+
);
|
|
1262
|
+
const rest = catalog.suites.filter((s) => !scorecard.includes(s));
|
|
1263
|
+
for (const suite of [...scorecard, ...rest]) {
|
|
1264
|
+
const label = SCORECARD_SUITE_LABELS[suite.id];
|
|
1265
|
+
lines.push(
|
|
1266
|
+
` ${suite.id.padEnd(width)}${String(suite.scenarioIds.length).padStart(2)} tasks ${formatDuration(
|
|
1267
|
+
suite.authoredCeilingMs
|
|
1268
|
+
).padStart(7)} ${label ?? suite.description}`
|
|
1269
|
+
);
|
|
1270
|
+
}
|
|
1271
|
+
lines.push(
|
|
1272
|
+
"",
|
|
1273
|
+
`The published scorecard runs ${SCORECARD_SUITE_IDS.join(", ")}. Add --smoke for a suite's pulse check; it is not a suite score.`
|
|
1274
|
+
);
|
|
1275
|
+
return lines;
|
|
1276
|
+
}
|
|
1277
|
+
async function renderResults(client, catalog, limit) {
|
|
1278
|
+
const { jobs } = await client.listEvalJobs();
|
|
1279
|
+
const finished = jobs.filter(finishedJob).slice(0, limit);
|
|
1280
|
+
if (finished.length === 0)
|
|
1281
|
+
return ["No finished runs on this machine yet. `gezel bench` starts one."];
|
|
1282
|
+
const lines = [];
|
|
1283
|
+
for (const job of finished) {
|
|
1284
|
+
const suite = job.spec.suiteId ? catalog.suites.find((s) => s.id === job.spec.suiteId) : void 0;
|
|
1285
|
+
const target = job.targets[0];
|
|
1286
|
+
const { trials } = await client.listEvalTrials({ jobId: job.id, limit: 2e3 });
|
|
1287
|
+
const order = suite?.scenarioIds ?? [...new Set(trials.map((t) => t.scenarioId))];
|
|
1288
|
+
const matrix = buildEvalMatrix(trials, { scenarioOrder: order });
|
|
1289
|
+
const column = target ? matrix.columns.find(
|
|
1290
|
+
(c) => c.modelId === target.modelId && (c.provider ?? target.provider) === target.provider
|
|
1291
|
+
) : matrix.columns[0];
|
|
1292
|
+
const subset = suite && job.spec.scenarioIds ? isSuiteSubset(suite, job.spec.scenarioIds) : false;
|
|
1293
|
+
const what = suite ? `${suite.id}${subset ? " (subset)" : ""}` : `${job.spec.scenarioIds?.length ?? 0} tasks`;
|
|
1294
|
+
lines.push(
|
|
1295
|
+
`${(job.finishedAt ?? job.createdAt).slice(0, 16).replace("T", " ")} ${(target?.modelId ?? "?").padEnd(24)} ${what.padEnd(22)} ${column?.claim ?? "not measured"}${job.status !== "completed" ? ` [${job.status}]` : ""}`
|
|
1296
|
+
);
|
|
1297
|
+
if (subset) lines.push(` ${EVAL_SUBSET_NOTE}`);
|
|
1298
|
+
}
|
|
1299
|
+
return lines;
|
|
1300
|
+
}
|
|
1301
|
+
function describeSubmission(shard) {
|
|
1302
|
+
const run = shard.runs[0];
|
|
1303
|
+
const models = [...new Set(shard.results.map((r) => `${r.modelId} (${r.engine})`))];
|
|
1304
|
+
const suites = run.suites.join(", ");
|
|
1305
|
+
const title = `Bench result: ${models.join(", ")} on ${run.provenance.device.label}`;
|
|
1306
|
+
const body = [
|
|
1307
|
+
"## Community bench result",
|
|
1308
|
+
"",
|
|
1309
|
+
`- Run: \`${run.id}\``,
|
|
1310
|
+
`- ${describeEvalRun(run, [...new Set(shard.results.map((r) => r.engine))])}`,
|
|
1311
|
+
`- Suites: ${suites}`,
|
|
1312
|
+
...run.note ? [`- Note: ${run.note}`] : [],
|
|
1313
|
+
"",
|
|
1314
|
+
"Results (count below three trials per task, rate otherwise):",
|
|
1315
|
+
...shard.results.map((r) => {
|
|
1316
|
+
const matrixLike = r.cells.reduce(
|
|
1317
|
+
(acc, c) => {
|
|
1318
|
+
acc.trials += Math.max(0, c.trials - c.nonModelFailures);
|
|
1319
|
+
acc.successes += c.successes;
|
|
1320
|
+
return acc;
|
|
1321
|
+
},
|
|
1322
|
+
{ trials: 0, successes: 0 }
|
|
1323
|
+
);
|
|
1324
|
+
return `- ${r.suiteId}: ${matrixLike.successes}/${matrixLike.trials}`;
|
|
1325
|
+
}),
|
|
1326
|
+
"",
|
|
1327
|
+
"The JSON shard produced by `gezel bench --json` is attached below. It is a `ScorecardDataset` and ingests with the same code as a published round; community rounds are shown separately from Bendyline rounds.",
|
|
1328
|
+
"",
|
|
1329
|
+
"<details><summary>shard.json</summary>",
|
|
1330
|
+
"",
|
|
1331
|
+
"```json",
|
|
1332
|
+
JSON.stringify(shard, null, 2),
|
|
1333
|
+
"```",
|
|
1334
|
+
"",
|
|
1335
|
+
"</details>"
|
|
1336
|
+
].join("\n");
|
|
1337
|
+
return { title, body };
|
|
1338
|
+
}
|
|
1339
|
+
var execFileAsync = promisify(execFile);
|
|
1340
|
+
var BENCH_RESULT_LABEL = "bench-result";
|
|
1341
|
+
function labelMissing(error) {
|
|
1342
|
+
const { stderr, message } = error ?? {};
|
|
1343
|
+
const text = typeof stderr === "string" && stderr ? stderr : String(message ?? error);
|
|
1344
|
+
return /could not add label/i.test(text) || text.includes(`'${BENCH_RESULT_LABEL}' not found`);
|
|
1345
|
+
}
|
|
1346
|
+
async function submitBench(file, io, deps = {}) {
|
|
1347
|
+
const text = await (deps.readFile ?? ((p) => readFile2(p, "utf8")))(file);
|
|
1348
|
+
let shard;
|
|
1349
|
+
try {
|
|
1350
|
+
shard = ScorecardDatasetSchema.parse(JSON.parse(text));
|
|
1351
|
+
} catch (error) {
|
|
1352
|
+
throw new CliError(
|
|
1353
|
+
`${file} is not a bench result file: ${error instanceof Error ? error.message.split("\n")[0] : String(error)}. Produce one with \`gezel bench --json <file>\`.`
|
|
1354
|
+
);
|
|
1355
|
+
}
|
|
1356
|
+
if (shard.runs.length !== 1) {
|
|
1357
|
+
throw new CliError(`${file} holds ${shard.runs.length} runs; submit one run per issue.`);
|
|
1358
|
+
}
|
|
1359
|
+
const { title, body } = describeSubmission(shard);
|
|
1360
|
+
const params = new URLSearchParams({ title, labels: BENCH_RESULT_LABEL });
|
|
1361
|
+
const url = `https://github.com/${BENCH_SUBMIT_REPO}/issues/new?${params.toString()}`;
|
|
1362
|
+
const gh = deps.gh ?? (async (args) => (await execFileAsync("gh", args, { encoding: "utf8" })).stdout);
|
|
1363
|
+
const createIssue = (labeled) => gh([
|
|
1364
|
+
"issue",
|
|
1365
|
+
"create",
|
|
1366
|
+
"--repo",
|
|
1367
|
+
BENCH_SUBMIT_REPO,
|
|
1368
|
+
"--title",
|
|
1369
|
+
title,
|
|
1370
|
+
...labeled ? ["--label", BENCH_RESULT_LABEL] : [],
|
|
1371
|
+
"--body",
|
|
1372
|
+
body
|
|
1373
|
+
]);
|
|
1374
|
+
try {
|
|
1375
|
+
let stdout;
|
|
1376
|
+
try {
|
|
1377
|
+
stdout = await createIssue(true);
|
|
1378
|
+
} catch (error) {
|
|
1379
|
+
if (!labelMissing(error)) throw error;
|
|
1380
|
+
stdout = await createIssue(false);
|
|
1381
|
+
}
|
|
1382
|
+
const issueUrl = stdout.trim().split("\n").pop() ?? "";
|
|
1383
|
+
io.out(`Opened ${issueUrl}`);
|
|
1384
|
+
return { title, body, url, issueUrl };
|
|
1385
|
+
} catch {
|
|
1386
|
+
io.out("Open this page and attach the file to the issue:");
|
|
1387
|
+
io.out(` ${url}`);
|
|
1388
|
+
io.out(` file: ${file}`);
|
|
1389
|
+
io.note("(Install the GitHub CLI, `gh`, and sign in to have this done for you.)");
|
|
1390
|
+
return { title, body, url };
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
function registerBenchCommands(program2, connect, io = {
|
|
1394
|
+
out: (line) => console.log(line),
|
|
1395
|
+
note: (line) => console.error(line),
|
|
1396
|
+
confirm: process.stdin.isTTY ? confirmOnTerminal : void 0,
|
|
1397
|
+
cpuModel: defaultCpuModel
|
|
1398
|
+
}) {
|
|
1399
|
+
const bench = program2.command("bench").description(
|
|
1400
|
+
"Run the model scorecard on this machine: the same tasks, checks and counting rules as the published scorecard"
|
|
1401
|
+
).option(
|
|
1402
|
+
"--suite <id>",
|
|
1403
|
+
"core (default), productivity, developer, complex-work, a comma list, or all"
|
|
1404
|
+
).option("--smoke", "Run the suite's pulse check instead (fast; not a suite score)").option("--model <id>", "Model to evaluate (default: the model chats use)").option("--provider <id>", "Provider for --model when a model is on more than one").option(
|
|
1405
|
+
"--count <n>",
|
|
1406
|
+
"Trials per task; 3 is what it takes to quote a rate (default 1)",
|
|
1407
|
+
(v) => Number.parseInt(v, 10)
|
|
1408
|
+
).option("--json <file>", "Also write the results as a scorecard shard").option("--note <text>", "A note kept with the run").option("--yes", "Start without asking, however long the run").option("--verbose", "Show the harness's own log lines while it runs").action(async (opts) => {
|
|
1409
|
+
const client = await connect();
|
|
1410
|
+
await runBench(client, opts, io);
|
|
1411
|
+
});
|
|
1412
|
+
bench.command("list").description("Show the suites, how many tasks each has, and how long it can take").action(async () => {
|
|
1413
|
+
const client = await connect();
|
|
1414
|
+
for (const line of renderSuiteList(await client.getEvalCatalog())) io.out(line);
|
|
1415
|
+
});
|
|
1416
|
+
bench.command("results").description("Show finished runs on this machine").option("--limit <n>", "How many runs to show (default 20)", (v) => Number.parseInt(v, 10)).action(async (opts) => {
|
|
1417
|
+
const client = await connect();
|
|
1418
|
+
const catalog = await client.getEvalCatalog();
|
|
1419
|
+
for (const line of await renderResults(client, catalog, opts.limit ?? 20)) io.out(line);
|
|
1420
|
+
});
|
|
1421
|
+
bench.command("submit <file>").description("Share a results shard from `gezel bench --json` as a GitHub issue").action(async (file) => {
|
|
1422
|
+
await submitBench(file, io);
|
|
1423
|
+
});
|
|
1424
|
+
}
|
|
1425
|
+
async function confirmOnTerminal(question) {
|
|
1426
|
+
const { createInterface } = await import("readline/promises");
|
|
1427
|
+
const rl = createInterface({ input: process.stdin, output: process.stderr });
|
|
1428
|
+
try {
|
|
1429
|
+
const answer = await rl.question(question);
|
|
1430
|
+
return /^y(es)?$/i.test(answer.trim());
|
|
1431
|
+
} finally {
|
|
1432
|
+
rl.close();
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
|
|
1436
|
+
// src/cli-errors.ts
|
|
1437
|
+
function formatCliFailure(err, env2 = process.env) {
|
|
1438
|
+
if (!(err instanceof Error)) return null;
|
|
1439
|
+
if (err.name === "CliError") return err.message;
|
|
1440
|
+
if (err.name !== "GezelApiError" || env2.GEZEL_DEBUG === "1") return null;
|
|
1441
|
+
const { status, details } = err;
|
|
1442
|
+
const request = /\bon ([A-Z]+ \S+)/.exec(err.message)?.[1];
|
|
1443
|
+
const serviceText = detailText(details);
|
|
1444
|
+
if (status === 404) {
|
|
1445
|
+
const what = serviceText && serviceText.toLowerCase() !== "not found" ? serviceText : void 0;
|
|
1446
|
+
return `error: not found${what ? `: ${what}` : request ? ` (${request})` : ""}`;
|
|
1447
|
+
}
|
|
1448
|
+
const lines = [`error: ${serviceText ?? err.message}`];
|
|
1449
|
+
if (serviceText && request) lines.push(`(Gezel service answered ${status ?? "?"} to ${request})`);
|
|
1450
|
+
lines.push("Set GEZEL_DEBUG=1 to see the full error.");
|
|
1451
|
+
return lines.join("\n");
|
|
1452
|
+
}
|
|
1453
|
+
function isNotFound(err) {
|
|
1454
|
+
return err instanceof Error && err.name === "GezelApiError" && err.status === 404;
|
|
1455
|
+
}
|
|
1456
|
+
function detailText(details) {
|
|
1457
|
+
if (typeof details === "string" && details.trim()) return details.trim();
|
|
1458
|
+
if (details && typeof details === "object") {
|
|
1459
|
+
for (const key of ["message", "error"]) {
|
|
1460
|
+
const value = details[key];
|
|
1461
|
+
if (typeof value === "string" && value.trim()) return value.trim();
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
return void 0;
|
|
1465
|
+
}
|
|
1466
|
+
|
|
772
1467
|
// src/craftbook-command.ts
|
|
773
1468
|
import { setTimeout as delay } from "timers/promises";
|
|
774
1469
|
import {
|
|
@@ -1076,7 +1771,7 @@ async function waitForMlxRuntime(client, writeProgress, options = {}) {
|
|
|
1076
1771
|
`\rpreparing the MLX Python runtime (one-time, a few minutes): ${Math.floor(elapsed / 60)}m ${String(elapsed % 60).padStart(2, "0")}s`
|
|
1077
1772
|
);
|
|
1078
1773
|
shown = true;
|
|
1079
|
-
await new Promise((
|
|
1774
|
+
await new Promise((resolve7) => setTimeout(resolve7, pollMs));
|
|
1080
1775
|
continue;
|
|
1081
1776
|
}
|
|
1082
1777
|
if (status.phase === "error") {
|
|
@@ -1345,7 +2040,8 @@ function errorMessage(error) {
|
|
|
1345
2040
|
import {
|
|
1346
2041
|
classifySecurityLevel,
|
|
1347
2042
|
resolveSecurityPolicy,
|
|
1348
|
-
securityCapabilitiesOf
|
|
2043
|
+
securityCapabilitiesOf,
|
|
2044
|
+
securityPolicyForLevel
|
|
1349
2045
|
} from "@bendyline/gezel";
|
|
1350
2046
|
var SECURITY_LEVEL_LABELS = {
|
|
1351
2047
|
"super-lockdown": "Super Lockdown",
|
|
@@ -1380,6 +2076,42 @@ var SECURITY_SWITCHES = [
|
|
|
1380
2076
|
description: "Show or set on/off for gezels adding or changing the scripts in package.json"
|
|
1381
2077
|
}
|
|
1382
2078
|
];
|
|
2079
|
+
var CAPABILITY_LABELS = [
|
|
2080
|
+
["allowExternalChat", "Cloud models"],
|
|
2081
|
+
["allowFileEdits", "File edits and the model\u2019s Git tools"],
|
|
2082
|
+
["allowScriptExecution", "Sandboxed scripts"],
|
|
2083
|
+
["allowAppNetwork", "Update checks and the connector syncs you start"],
|
|
2084
|
+
["allowExternalServices", "Web search, mail and other outside services"],
|
|
2085
|
+
["allowPackageScriptExecution", "Run package scripts"],
|
|
2086
|
+
["allowPackageScriptEdits", "Edit package scripts"]
|
|
2087
|
+
];
|
|
2088
|
+
var LEVEL_ALIASES = {
|
|
2089
|
+
"super-lockdown": "super-lockdown",
|
|
2090
|
+
superlockdown: "super-lockdown",
|
|
2091
|
+
lockdown: "lockdown",
|
|
2092
|
+
free: "free",
|
|
2093
|
+
unrestricted: "free"
|
|
2094
|
+
};
|
|
2095
|
+
function parseSecurityLevel(input) {
|
|
2096
|
+
const level = LEVEL_ALIASES[input.trim().toLowerCase()];
|
|
2097
|
+
if (!level) {
|
|
2098
|
+
throw new CliError(
|
|
2099
|
+
`Unknown security level "${input}". Choose super-lockdown, lockdown, or free (shown as Unrestricted in Settings).`
|
|
2100
|
+
);
|
|
2101
|
+
}
|
|
2102
|
+
return level;
|
|
2103
|
+
}
|
|
2104
|
+
function describeSecurityLevel(policy) {
|
|
2105
|
+
const caps = securityCapabilitiesOf(resolveSecurityPolicy({ securityPolicy: policy }));
|
|
2106
|
+
const level = classifySecurityLevel(caps);
|
|
2107
|
+
const width = Math.max(...CAPABILITY_LABELS.map(([, label]) => label.length));
|
|
2108
|
+
return [
|
|
2109
|
+
`Security level: ${SECURITY_LEVEL_LABELS[level]}${level === "custom" ? "" : ` (${level})`}`,
|
|
2110
|
+
...CAPABILITY_LABELS.map(
|
|
2111
|
+
([key, label]) => ` ${label.padEnd(width)} ${caps[key] ? "on" : "off"}`
|
|
2112
|
+
)
|
|
2113
|
+
];
|
|
2114
|
+
}
|
|
1383
2115
|
function enabledValue(state) {
|
|
1384
2116
|
if (state === void 0) return void 0;
|
|
1385
2117
|
if (state === "on") return true;
|
|
@@ -1388,6 +2120,34 @@ function enabledValue(state) {
|
|
|
1388
2120
|
}
|
|
1389
2121
|
function registerSecurityCommands(program2, connect) {
|
|
1390
2122
|
const security = program2.command("security").description("Inspect or explicitly change security settings");
|
|
2123
|
+
security.command("level [action] [level]").description(
|
|
2124
|
+
"Show the security level, or set a preset: `level set super-lockdown|lockdown|free`"
|
|
2125
|
+
).option("--json", "Output the level and its capabilities as JSON").action(
|
|
2126
|
+
async (action, requested, options) => {
|
|
2127
|
+
if (action !== void 0 && action !== "show" && action !== "set") {
|
|
2128
|
+
throw new CliError("Use `gezel security level`, `level show`, or `level set <level>`.");
|
|
2129
|
+
}
|
|
2130
|
+
if (action === "set" && requested === void 0) {
|
|
2131
|
+
throw new CliError("Name a level: super-lockdown, lockdown, or free.");
|
|
2132
|
+
}
|
|
2133
|
+
if (action !== "set" && requested !== void 0) {
|
|
2134
|
+
throw new CliError("To change the level, use `gezel security level set <level>`.");
|
|
2135
|
+
}
|
|
2136
|
+
const next = action === "set" ? parseSecurityLevel(requested) : void 0;
|
|
2137
|
+
const client = await connect();
|
|
2138
|
+
const policy = next ? securityPolicyForLevel(next) : {
|
|
2139
|
+
level: "custom",
|
|
2140
|
+
...securityCapabilitiesOf(resolveSecurityPolicy(await client.getConfig()))
|
|
2141
|
+
};
|
|
2142
|
+
if (next) await client.updateConfig({ securityPolicy: policy });
|
|
2143
|
+
if (options.json) {
|
|
2144
|
+
const caps = securityCapabilitiesOf(resolveSecurityPolicy({ securityPolicy: policy }));
|
|
2145
|
+
console.log(JSON.stringify({ level: classifySecurityLevel(caps), ...caps }));
|
|
2146
|
+
return;
|
|
2147
|
+
}
|
|
2148
|
+
for (const line of describeSecurityLevel(policy)) console.log(line);
|
|
2149
|
+
}
|
|
2150
|
+
);
|
|
1391
2151
|
for (const setting of SECURITY_SWITCHES) {
|
|
1392
2152
|
security.command(`${setting.command} [state]`).description(setting.description).option("--json", "Output the setting as JSON").action(async (state, options) => {
|
|
1393
2153
|
const enabled = enabledValue(state);
|
|
@@ -1583,7 +2343,7 @@ function terminalPrompter(terminal = { input: process.stdin, output: process.std
|
|
|
1583
2343
|
function ask(terminal, question, secret) {
|
|
1584
2344
|
const { input, output } = terminal;
|
|
1585
2345
|
return import("readline").then(
|
|
1586
|
-
({ clearScreenDown, createInterface, cursorTo, moveCursor }) => new Promise((
|
|
2346
|
+
({ clearScreenDown, createInterface, cursorTo, moveCursor }) => new Promise((resolve7, reject) => {
|
|
1587
2347
|
const rl = createInterface({
|
|
1588
2348
|
input,
|
|
1589
2349
|
output: secret ? new Writable({ write: (_chunk, _encoding, done) => done() }) : output,
|
|
@@ -1630,13 +2390,13 @@ function ask(terminal, question, secret) {
|
|
|
1630
2390
|
if (settled) return;
|
|
1631
2391
|
settle();
|
|
1632
2392
|
output.write("\n");
|
|
1633
|
-
|
|
2393
|
+
resolve7("");
|
|
1634
2394
|
});
|
|
1635
2395
|
rl.question(question, (answer) => {
|
|
1636
2396
|
settle();
|
|
1637
2397
|
rl.close();
|
|
1638
2398
|
if (secret) output.write("\n");
|
|
1639
|
-
|
|
2399
|
+
resolve7(answer);
|
|
1640
2400
|
});
|
|
1641
2401
|
draw();
|
|
1642
2402
|
})
|
|
@@ -1756,8 +2516,8 @@ async function ensureEngines(client, engines, write) {
|
|
|
1756
2516
|
|
|
1757
2517
|
// src/craftbook-shorthand.ts
|
|
1758
2518
|
import { existsSync } from "fs";
|
|
1759
|
-
import { readFile as
|
|
1760
|
-
import { join as
|
|
2519
|
+
import { readFile as readFile3, readdir } from "fs/promises";
|
|
2520
|
+
import { join as join3 } from "path";
|
|
1761
2521
|
import { projectLocalCraftbooksRoot } from "@bendyline/gezel/paths";
|
|
1762
2522
|
var SHORTHAND_FLAG = "--via-craftbook-shorthand";
|
|
1763
2523
|
var VALUE_OPTIONS = /* @__PURE__ */ new Set(["--connect", "--token", "--home"]);
|
|
@@ -1794,7 +2554,7 @@ async function workspaceCraftbookId(workspaceDir, word) {
|
|
|
1794
2554
|
const ids = [];
|
|
1795
2555
|
for (const entry of await readdir(root, { withFileTypes: true })) {
|
|
1796
2556
|
if (!entry.isDirectory()) continue;
|
|
1797
|
-
const manifest = await
|
|
2557
|
+
const manifest = await readFile3(join3(root, entry.name, "manifest.json"), "utf8").then((text) => JSON.parse(text)).catch(() => null);
|
|
1798
2558
|
if (!manifest) continue;
|
|
1799
2559
|
const id = typeof manifest.id === "string" ? manifest.id : entry.name;
|
|
1800
2560
|
if (typeof manifest.command === "string" && manifest.command.toLowerCase() === query) return id;
|
|
@@ -1829,6 +2589,112 @@ function isGezeldCommand(command) {
|
|
|
1829
2589
|
return /(?:^|[\\/\s"'])gezeld(?:\.[cm]?js|\.exe)?(?=["'\s]|$)/i.test(command);
|
|
1830
2590
|
}
|
|
1831
2591
|
|
|
2592
|
+
// src/doctor-report.ts
|
|
2593
|
+
import {
|
|
2594
|
+
describeProvenance,
|
|
2595
|
+
measuredClaim,
|
|
2596
|
+
measuredResultFor,
|
|
2597
|
+
measuredRowsFor,
|
|
2598
|
+
scorecardHardwareKey,
|
|
2599
|
+
scorecardHardwareLabel
|
|
2600
|
+
} from "@bendyline/gezel";
|
|
2601
|
+
var CHECK_LABELS = {
|
|
2602
|
+
spawn: "starts",
|
|
2603
|
+
toolRoundTrip: "answers a tool call",
|
|
2604
|
+
throughput: "decodes fast enough",
|
|
2605
|
+
reasoningBudget: "bounded reasoning",
|
|
2606
|
+
contextFit: "room for a prompt"
|
|
2607
|
+
};
|
|
2608
|
+
function renderFitness(entry, probing) {
|
|
2609
|
+
if (probing) return ["fitness check: running now"];
|
|
2610
|
+
if (!entry) {
|
|
2611
|
+
return [
|
|
2612
|
+
"fitness check: not run yet \u2014 Gezel runs it when a model is installed, or from Settings \u2192 Models"
|
|
2613
|
+
];
|
|
2614
|
+
}
|
|
2615
|
+
const { record } = entry;
|
|
2616
|
+
const head = record.status === "probed" ? record.admitted ? "fitness check: passed" : "fitness check: FAILED" : `fitness check: ${record.status}`;
|
|
2617
|
+
const qualifiers = [
|
|
2618
|
+
entry.stale ? "the model changed since; treat as not run" : "",
|
|
2619
|
+
entry.hardwareChanged ? "this machine's memory changed since" : "",
|
|
2620
|
+
record.genTokensPerSec ? `${record.genTokensPerSec.toFixed(1)} tok/s` : "",
|
|
2621
|
+
record.createdAt ? record.createdAt.slice(0, 10) : ""
|
|
2622
|
+
].filter(Boolean);
|
|
2623
|
+
const lines = [`${head}${qualifiers.length ? ` (${qualifiers.join(", ")})` : ""}`];
|
|
2624
|
+
for (const key of Object.keys(CHECK_LABELS)) {
|
|
2625
|
+
const check = record.checks[key];
|
|
2626
|
+
if (!check) continue;
|
|
2627
|
+
lines.push(` ${check.ok ? "ok " : "NO "} ${CHECK_LABELS[key].padEnd(20)} ${check.detail}`);
|
|
2628
|
+
}
|
|
2629
|
+
return lines;
|
|
2630
|
+
}
|
|
2631
|
+
function hardwareClassCoverage(dataset, modelId, device) {
|
|
2632
|
+
const key = scorecardHardwareKey(device);
|
|
2633
|
+
const name = scorecardHardwareLabel(device);
|
|
2634
|
+
const rounds = dataset.runs.filter(
|
|
2635
|
+
(run) => run.scope !== "subset" && scorecardHardwareKey(run.provenance.device) === key
|
|
2636
|
+
).length;
|
|
2637
|
+
const mine = measuredRowsFor(dataset, modelId).filter(
|
|
2638
|
+
(row) => scorecardHardwareKey(row.run.provenance.device) === key
|
|
2639
|
+
).length;
|
|
2640
|
+
if (rounds === 0) {
|
|
2641
|
+
return ` on ${name}: no published scorecard round has run on ${name} yet \u2014 \`gezel bench\` would be the first`;
|
|
2642
|
+
}
|
|
2643
|
+
const roundWord = rounds === 1 ? "round" : "rounds";
|
|
2644
|
+
if (mine === 0) {
|
|
2645
|
+
return ` on ${name}: ${rounds} published ${roundWord}, none with this model \u2014 \`gezel bench\` measures it here`;
|
|
2646
|
+
}
|
|
2647
|
+
return ` on ${name}: ${rounds} published ${roundWord}; ${mine} ${mine === 1 ? "result" : "results"} for this model`;
|
|
2648
|
+
}
|
|
2649
|
+
function renderMeasured(dataset, modelId, device, rows = 4) {
|
|
2650
|
+
const headline = measuredResultFor(dataset, modelId, device);
|
|
2651
|
+
const coverage = hardwareClassCoverage(dataset, modelId, device);
|
|
2652
|
+
if (!headline) {
|
|
2653
|
+
return [
|
|
2654
|
+
"measured: not measured in a published round \u2014 `gezel bench` measures it on this machine",
|
|
2655
|
+
coverage
|
|
2656
|
+
];
|
|
2657
|
+
}
|
|
2658
|
+
const lines = [
|
|
2659
|
+
`measured: ${measuredClaim(headline)}${headline.sameHardwareClass ? "" : " \u2014 a different platform; your numbers may differ"}`,
|
|
2660
|
+
coverage
|
|
2661
|
+
];
|
|
2662
|
+
for (const row of measuredRowsFor(dataset, modelId).slice(0, rows)) {
|
|
2663
|
+
lines.push(
|
|
2664
|
+
` ${row.result.suiteId.padEnd(14)} ${row.score.claim.padEnd(36)} ${describeProvenance(row.run, [row.result.engine])}`
|
|
2665
|
+
);
|
|
2666
|
+
}
|
|
2667
|
+
lines.push(" Full tables: https://gezel.com/docs/model-scorecard/");
|
|
2668
|
+
return lines;
|
|
2669
|
+
}
|
|
2670
|
+
function renderDoctorModel(input) {
|
|
2671
|
+
if (!input.modelId) {
|
|
2672
|
+
return [
|
|
2673
|
+
`model: none for ${input.provider}`,
|
|
2674
|
+
" `gezel model list --available` shows what fits this machine; `gezel model pull <id>` downloads one."
|
|
2675
|
+
];
|
|
2676
|
+
}
|
|
2677
|
+
const lines = [`model: ${input.modelId} (${input.provider})`];
|
|
2678
|
+
for (const line of renderFitness(input.fitness, input.probing)) lines.push(` ${line}`);
|
|
2679
|
+
for (const line of renderMeasured(input.dataset, input.modelId, input.device, input.rows)) {
|
|
2680
|
+
lines.push(` ${line}`);
|
|
2681
|
+
}
|
|
2682
|
+
return lines;
|
|
2683
|
+
}
|
|
2684
|
+
function doctorVerdict(input) {
|
|
2685
|
+
if (!input.nodeOk) return "Verdict: install Node.js 24 or newer, then run `gezel doctor` again.";
|
|
2686
|
+
if (!input.serviceReachable) {
|
|
2687
|
+
return 'Verdict: Gezel is installed but no service is running. `gezel start` starts one; `gezel run "hello"` starts one and sends a message.';
|
|
2688
|
+
}
|
|
2689
|
+
if (!input.modelId) {
|
|
2690
|
+
return "Verdict: the service runs but has no model to chat with. `gezel model list --available` shows what fits; `gezel model pull <id>` downloads one.";
|
|
2691
|
+
}
|
|
2692
|
+
if (input.fitnessAdmitted === false) {
|
|
2693
|
+
return `Verdict: ${input.modelId} failed its fitness check on this machine. Pick a smaller model with \`gezel model list --available\`, or re-run the check from Settings \u2192 Models.`;
|
|
2694
|
+
}
|
|
2695
|
+
return `Verdict: ready. ${input.modelId} is installed and ${input.fitnessAdmitted ? "passed its fitness check" : "has not been fitness-checked yet"}; \`gezel run "hello"\` to talk to it, \`gezel bench\` to measure it.`;
|
|
2696
|
+
}
|
|
2697
|
+
|
|
1832
2698
|
// src/engagement-mode.ts
|
|
1833
2699
|
var CLI_ENGAGEMENT_MODES = [
|
|
1834
2700
|
{
|
|
@@ -1881,7 +2747,7 @@ var CLI_ENGAGEMENT_MODE_USAGE = CLI_ENGAGEMENT_MODES.map((option) => option.name
|
|
|
1881
2747
|
);
|
|
1882
2748
|
|
|
1883
2749
|
// src/generate.ts
|
|
1884
|
-
import { mkdir as mkdir2, readFile as
|
|
2750
|
+
import { mkdir as mkdir2, readFile as readFile4, writeFile as writeFile3 } from "fs/promises";
|
|
1885
2751
|
import { basename as basename2, dirname as dirname2, resolve as resolve2 } from "path";
|
|
1886
2752
|
async function resolvePromptText(parts, file, label) {
|
|
1887
2753
|
const inline = (parts ?? []).join(" ").trim();
|
|
@@ -1889,7 +2755,7 @@ async function resolvePromptText(parts, file, label) {
|
|
|
1889
2755
|
if (inline) throw new CliError(`provide either ${label} text or --file, not both.`);
|
|
1890
2756
|
let raw;
|
|
1891
2757
|
try {
|
|
1892
|
-
raw = await
|
|
2758
|
+
raw = await readFile4(resolve2(file), "utf8");
|
|
1893
2759
|
} catch (err) {
|
|
1894
2760
|
throw new CliError(`could not read --file "${file}": ${err.message}`);
|
|
1895
2761
|
}
|
|
@@ -1925,7 +2791,7 @@ async function saveArtifact(client, projectId, artifactPath, output) {
|
|
|
1925
2791
|
const bytes = Buffer.from(await blob.arrayBuffer());
|
|
1926
2792
|
const dest = output ? resolve2(output) : resolve2(process.cwd(), basename2(artifactPath));
|
|
1927
2793
|
await mkdir2(dirname2(dest), { recursive: true });
|
|
1928
|
-
await
|
|
2794
|
+
await writeFile3(dest, bytes);
|
|
1929
2795
|
return dest;
|
|
1930
2796
|
}
|
|
1931
2797
|
|
|
@@ -1981,7 +2847,7 @@ import {
|
|
|
1981
2847
|
harnessAgentFileLine,
|
|
1982
2848
|
harnessPromptInvocation
|
|
1983
2849
|
} from "@bendyline/gezel";
|
|
1984
|
-
import { GezelApiError as
|
|
2850
|
+
import { GezelApiError as GezelApiError3, apiErrorMessage as apiErrorMessage2 } from "@bendyline/gezel-client";
|
|
1985
2851
|
var STATE_WORDS = {
|
|
1986
2852
|
configured: "set up",
|
|
1987
2853
|
"not-configured": "not set up",
|
|
@@ -2009,7 +2875,7 @@ async function call(fn) {
|
|
|
2009
2875
|
try {
|
|
2010
2876
|
return await fn();
|
|
2011
2877
|
} catch (error) {
|
|
2012
|
-
if (error instanceof
|
|
2878
|
+
if (error instanceof GezelApiError3) throw new CliError(apiErrorMessage2(error));
|
|
2013
2879
|
throw error;
|
|
2014
2880
|
}
|
|
2015
2881
|
}
|
|
@@ -2079,6 +2945,10 @@ function registerMcpCommands(program2, connect, output = console.log) {
|
|
|
2079
2945
|
}
|
|
2080
2946
|
|
|
2081
2947
|
// src/model-choice.ts
|
|
2948
|
+
import {
|
|
2949
|
+
measuredClaim as measuredClaim2,
|
|
2950
|
+
measuredResultFor as measuredResultFor2
|
|
2951
|
+
} from "@bendyline/gezel";
|
|
2082
2952
|
async function installedChatModels(client, engine) {
|
|
2083
2953
|
const { models } = engine === "mlx" ? await client.listMlxModels() : engine === "ds4" ? await client.listDs4Models() : await client.listLlamaCppModels();
|
|
2084
2954
|
return models.map((model2) => model2.id);
|
|
@@ -2110,9 +2980,10 @@ async function availableChatModels(client, engine) {
|
|
|
2110
2980
|
};
|
|
2111
2981
|
}
|
|
2112
2982
|
function formatAvailableChatModels(input) {
|
|
2113
|
-
const { engine, ranked, installed, pinned } = input;
|
|
2983
|
+
const { engine, ranked, installed, pinned, measured } = input;
|
|
2114
2984
|
if (ranked.length === 0) return `(no ${engine} chat models in the catalog for this machine)`;
|
|
2115
2985
|
const width = Math.max(...ranked.map((model2) => model2.id.length));
|
|
2986
|
+
const measuredWidth = measured ? Math.max("not measured".length, ...ranked.map((m) => (measured.get(m.id) ?? "").length)) : 0;
|
|
2116
2987
|
const lines = [`${engine} chat models for this machine, best first:`];
|
|
2117
2988
|
ranked.forEach((model2, index) => {
|
|
2118
2989
|
const notes = [
|
|
@@ -2120,8 +2991,9 @@ function formatAvailableChatModels(input) {
|
|
|
2120
2991
|
installed.has(model2.id) ? "installed" : "",
|
|
2121
2992
|
model2.id === pinned ? "in use" : ""
|
|
2122
2993
|
].filter(Boolean);
|
|
2994
|
+
const claim = measured ? ` ${(measured.get(model2.id) ?? "not measured").padEnd(measuredWidth)}` : "";
|
|
2123
2995
|
lines.push(
|
|
2124
|
-
` ${model2.id.padEnd(width)} ${formatDownloadSize(model2.approxSizeBytes).padStart(7)} ${FIT_LABEL[model2.fit].padEnd(22)} ${model2.name}${notes.length > 0 ? ` (${notes.join(", ")})` : ""}`
|
|
2996
|
+
` ${model2.id.padEnd(width)} ${formatDownloadSize(model2.approxSizeBytes).padStart(7)} ${FIT_LABEL[model2.fit].padEnd(22)}${claim} ${model2.name}${notes.length > 0 ? ` (${notes.join(", ")})` : ""}`
|
|
2125
2997
|
);
|
|
2126
2998
|
});
|
|
2127
2999
|
const flag = providerFlag(engine, input.platformDefault);
|
|
@@ -2131,8 +3003,18 @@ function formatAvailableChatModels(input) {
|
|
|
2131
3003
|
`Download one with \`gezel model pull <id>${flag}\`. The smallest is ${smallest.id} (${formatDownloadSize(smallest.approxSizeBytes)}).`,
|
|
2132
3004
|
`\`gezel model use <id>${flag}\` picks the installed model chats use.`
|
|
2133
3005
|
);
|
|
3006
|
+
if (measured) {
|
|
3007
|
+
lines.push(
|
|
3008
|
+
'"Fits" is about memory. The measured column is the published scorecard\'s pass rate on real jobs, on the hardware named; `gezel bench` measures a model on this machine.'
|
|
3009
|
+
);
|
|
3010
|
+
}
|
|
2134
3011
|
return lines.join("\n");
|
|
2135
3012
|
}
|
|
3013
|
+
function measuredClaimsFor(dataset, ids, device) {
|
|
3014
|
+
const claims = /* @__PURE__ */ new Map();
|
|
3015
|
+
for (const id of ids) claims.set(id, measuredClaim2(measuredResultFor2(dataset, id, device)));
|
|
3016
|
+
return claims;
|
|
3017
|
+
}
|
|
2136
3018
|
async function useChatModel(client, id, options) {
|
|
2137
3019
|
const order = options.requested ? [options.requested] : [options.platformDefault, ...["mlx", "llama-cpp", "ds4"]].filter(
|
|
2138
3020
|
(engine2, index, all) => all.indexOf(engine2) === index
|
|
@@ -2469,7 +3351,7 @@ async function settledFirstRunConfig(client, options = {}) {
|
|
|
2469
3351
|
let config = await client.getConfig();
|
|
2470
3352
|
for (let attempt = 0; attempt < attempts; attempt += 1) {
|
|
2471
3353
|
if (config.firstRunCompleted || config.provider !== "copilot") return config;
|
|
2472
|
-
await new Promise((
|
|
3354
|
+
await new Promise((resolve7) => setTimeout(resolve7, delayMs));
|
|
2473
3355
|
config = await client.getConfig();
|
|
2474
3356
|
}
|
|
2475
3357
|
return config;
|
|
@@ -2508,6 +3390,10 @@ async function checkRunReadiness(client, gezelId, env2 = process.env) {
|
|
|
2508
3390
|
})
|
|
2509
3391
|
};
|
|
2510
3392
|
}
|
|
3393
|
+
function canOfferRunSetup(io = process, env2 = process.env) {
|
|
3394
|
+
if (env2.CI) return false;
|
|
3395
|
+
return io.stdin.isTTY === true && io.stderr.isTTY === true;
|
|
3396
|
+
}
|
|
2511
3397
|
function formatRunSetupMessage(input) {
|
|
2512
3398
|
const { provider, engineMissing, pinned, installedIds } = input;
|
|
2513
3399
|
const flag = providerFlag(
|
|
@@ -2674,7 +3560,7 @@ var RunOutput = class {
|
|
|
2674
3560
|
};
|
|
2675
3561
|
|
|
2676
3562
|
// src/secrets-command.ts
|
|
2677
|
-
import { GezelApiError as
|
|
3563
|
+
import { GezelApiError as GezelApiError4 } from "@bendyline/gezel-client";
|
|
2678
3564
|
var credentialFlags = {
|
|
2679
3565
|
githubToken: "hasGithubToken",
|
|
2680
3566
|
openaiApiKey: "hasOpenaiApiKey",
|
|
@@ -2728,7 +3614,7 @@ async function writeCredential(client, patch) {
|
|
|
2728
3614
|
try {
|
|
2729
3615
|
await client.updateConfig(patch);
|
|
2730
3616
|
} catch (error) {
|
|
2731
|
-
const status = error instanceof
|
|
3617
|
+
const status = error instanceof GezelApiError4 ? ` (HTTP ${error.status})` : "";
|
|
2732
3618
|
throw new CliError(
|
|
2733
3619
|
`Could not update the credential${status}. Check the service connection and permissions.`
|
|
2734
3620
|
);
|
|
@@ -2778,6 +3664,50 @@ function registerSecretCommands(program2, connect, output = console.log) {
|
|
|
2778
3664
|
});
|
|
2779
3665
|
}
|
|
2780
3666
|
|
|
3667
|
+
// src/start-reuse.ts
|
|
3668
|
+
var SIGN_IN_STATE_TIMEOUT_MS = 3e3;
|
|
3669
|
+
async function startShortfall(runtime, want, deps) {
|
|
3670
|
+
if (want.port !== void 0 && runtime.port !== want.port) return "port";
|
|
3671
|
+
if (!want.web) return null;
|
|
3672
|
+
if (new URL(runtime.baseUrl).protocol !== "http:") return "web";
|
|
3673
|
+
if ((await deps.readWebUiToken()).trim().length === 0) return "web";
|
|
3674
|
+
if (want.accounts && !await requiresAccounts(runtime.baseUrl, deps.fetch ?? fetch)) {
|
|
3675
|
+
return "accounts";
|
|
3676
|
+
}
|
|
3677
|
+
return null;
|
|
3678
|
+
}
|
|
3679
|
+
async function requiresAccounts(baseUrl, fetchImpl) {
|
|
3680
|
+
const controller = new AbortController();
|
|
3681
|
+
const timer = setTimeout(() => controller.abort(), SIGN_IN_STATE_TIMEOUT_MS);
|
|
3682
|
+
timer.unref?.();
|
|
3683
|
+
try {
|
|
3684
|
+
const res = await fetchImpl(`${new URL(baseUrl).origin}/v1/apps/signin/state`, {
|
|
3685
|
+
signal: controller.signal
|
|
3686
|
+
});
|
|
3687
|
+
if (!res.ok) return false;
|
|
3688
|
+
const state = await res.json();
|
|
3689
|
+
return state.accountsRequired === true;
|
|
3690
|
+
} catch {
|
|
3691
|
+
return false;
|
|
3692
|
+
} finally {
|
|
3693
|
+
clearTimeout(timer);
|
|
3694
|
+
}
|
|
3695
|
+
}
|
|
3696
|
+
function startShortfallMessage(shortfall, running, want) {
|
|
3697
|
+
const has = shortfall === "port" ? `on port ${running.port}` : shortfall === "web" ? "without the web UI" : "with the web UI but without accounts";
|
|
3698
|
+
const retry = ["gezel start"];
|
|
3699
|
+
if (want.port !== void 0) retry.push(`--port ${want.port}`);
|
|
3700
|
+
if (want.web) retry.push("--web");
|
|
3701
|
+
if (want.accounts) retry.push("--accounts");
|
|
3702
|
+
retry.push("--restart");
|
|
3703
|
+
return `gezeld is already running for this home ${has} (pid ${running.pid}).
|
|
3704
|
+
Restart it ${startRestartWanted(want)} with \`${retry.join(" ")}\`, or stop it first with \`gezel stop\`.`;
|
|
3705
|
+
}
|
|
3706
|
+
function startRestartWanted(want) {
|
|
3707
|
+
if (want.accounts) return "with the web UI and accounts";
|
|
3708
|
+
return want.web ? "with the web UI" : `on port ${want.port}`;
|
|
3709
|
+
}
|
|
3710
|
+
|
|
2781
3711
|
// src/storage-format.ts
|
|
2782
3712
|
function formatBytes2(bytes) {
|
|
2783
3713
|
if (bytes >= 1024 ** 3) return `${(bytes / 1024 ** 3).toFixed(1)} GB`;
|
|
@@ -2960,6 +3890,33 @@ function resolveRestoreSelection(review, opts) {
|
|
|
2960
3890
|
return { items, skipped };
|
|
2961
3891
|
}
|
|
2962
3892
|
|
|
3893
|
+
// src/task-output.ts
|
|
3894
|
+
import { mkdir as mkdir3, writeFile as writeFile4 } from "fs/promises";
|
|
3895
|
+
import { dirname as dirname4, isAbsolute as isAbsolute2, join as join4, relative, resolve as resolve5, sep } from "path";
|
|
3896
|
+
async function copyTaskOutput(client, projectId, artifactDir, outDir) {
|
|
3897
|
+
const root = resolve5(outDir);
|
|
3898
|
+
const listing = await client.listProjectArtifacts(projectId, artifactDir, true);
|
|
3899
|
+
const copied = [];
|
|
3900
|
+
for (const file of listing.files) {
|
|
3901
|
+
if (file.isDirectory) continue;
|
|
3902
|
+
const rel = relative(artifactDir, file.path).split(sep).join("/");
|
|
3903
|
+
if (!rel || rel.startsWith("..") || isAbsolute2(rel)) continue;
|
|
3904
|
+
if (rel === "inputs" || rel.startsWith("inputs/")) continue;
|
|
3905
|
+
const target = join4(root, rel);
|
|
3906
|
+
if (relative(root, target).startsWith("..")) continue;
|
|
3907
|
+
const blob = await client.fetchProjectArtifactBlob(projectId, file.path);
|
|
3908
|
+
await mkdir3(dirname4(target), { recursive: true });
|
|
3909
|
+
await writeFile4(target, Buffer.from(await blob.arrayBuffer()));
|
|
3910
|
+
copied.push(rel);
|
|
3911
|
+
}
|
|
3912
|
+
if (listing.truncated) {
|
|
3913
|
+
throw new CliError(
|
|
3914
|
+
`The task made more files than one listing returns; ${copied.length} were copied to ${root}. Open the rest from the task's folder in Gezel.`
|
|
3915
|
+
);
|
|
3916
|
+
}
|
|
3917
|
+
return copied;
|
|
3918
|
+
}
|
|
3919
|
+
|
|
2963
3920
|
// src/unknown-command.ts
|
|
2964
3921
|
function unknownCommandMessage(operands, known) {
|
|
2965
3922
|
const word = operands[0] ?? "";
|
|
@@ -3007,7 +3964,7 @@ function editDistance(a, b) {
|
|
|
3007
3964
|
|
|
3008
3965
|
// src/workflow-command.ts
|
|
3009
3966
|
import { realpath as realpath2 } from "fs/promises";
|
|
3010
|
-
import { isAbsolute as
|
|
3967
|
+
import { isAbsolute as isAbsolute3, relative as relative2, resolve as resolve6 } from "path";
|
|
3011
3968
|
import { pathToFileURL } from "url";
|
|
3012
3969
|
import {
|
|
3013
3970
|
craftbookFromDoc,
|
|
@@ -3024,10 +3981,10 @@ function validateWorkflowCraftbook(document) {
|
|
|
3024
3981
|
}
|
|
3025
3982
|
async function runWorkflow(client, projectId, workspace, file, args, log = console.error, invocation) {
|
|
3026
3983
|
const named = /^[a-z][a-z0-9-]*$/.test(file);
|
|
3027
|
-
const path = await realpath2(
|
|
3984
|
+
const path = await realpath2(resolve6(workspace, named ? `.gezel/workflows/${file}.mjs` : file));
|
|
3028
3985
|
if (invocation) {
|
|
3029
|
-
const local =
|
|
3030
|
-
if (
|
|
3986
|
+
const local = relative2(await realpath2(workspace), path);
|
|
3987
|
+
if (isAbsolute3(local) || local === ".." || local.startsWith("../") || local.startsWith("..\\")) {
|
|
3031
3988
|
throw new CliError("A craftbook workflow module must remain inside its project workspace.");
|
|
3032
3989
|
}
|
|
3033
3990
|
}
|
|
@@ -3046,7 +4003,7 @@ async function runWorkflow(client, projectId, workspace, file, args, log = conso
|
|
|
3046
4003
|
return module.run({
|
|
3047
4004
|
client,
|
|
3048
4005
|
projectId,
|
|
3049
|
-
workspace:
|
|
4006
|
+
workspace: resolve6(workspace),
|
|
3050
4007
|
args,
|
|
3051
4008
|
...invocation ?? {},
|
|
3052
4009
|
log,
|
|
@@ -3108,6 +4065,16 @@ async function runWorkflow(client, projectId, workspace, file, args, log = conso
|
|
|
3108
4065
|
});
|
|
3109
4066
|
}
|
|
3110
4067
|
|
|
4068
|
+
// src/bin/node-version.ts
|
|
4069
|
+
var MINIMUM_NODE_MAJOR = 24;
|
|
4070
|
+
function unsupportedNodeMessage(version) {
|
|
4071
|
+
const major = Number.parseInt(version, 10);
|
|
4072
|
+
if (!Number.isFinite(major) || major >= MINIMUM_NODE_MAJOR) return void 0;
|
|
4073
|
+
return `Gezel needs Node.js ${MINIMUM_NODE_MAJOR} or newer (found v${version}).
|
|
4074
|
+
Install Node.js ${MINIMUM_NODE_MAJOR} or later from https://nodejs.org, then run the command again.
|
|
4075
|
+
`;
|
|
4076
|
+
}
|
|
4077
|
+
|
|
3111
4078
|
// src/bin/gezel.ts
|
|
3112
4079
|
var program = new Command();
|
|
3113
4080
|
program.name("gezel").description("Gezel \u2014 assemble a team of AI companions (gezels) and put them to work.").addHelpText(
|
|
@@ -3124,8 +4091,12 @@ program.name("gezel").description("Gezel \u2014 assemble a team of AI companions
|
|
|
3124
4091
|
"Use this folder as the active project (default and bare flag: cwd)."
|
|
3125
4092
|
);
|
|
3126
4093
|
var cliGlobals = () => program.opts();
|
|
4094
|
+
var connectForInspection = (opts) => opts.start === false ? connectRunning(cliGlobals()) : connectOwned(cliGlobals());
|
|
3127
4095
|
registerSecretCommands(program, () => connectOwned(cliGlobals()));
|
|
4096
|
+
registerAccountCommands(program, async () => (await connectOwned(cliGlobals())).accounts);
|
|
4097
|
+
registerIntegrationCommands(program, () => connectOwned(cliGlobals()));
|
|
3128
4098
|
registerMcpCommands(program, () => connectOwned(cliGlobals()));
|
|
4099
|
+
registerBenchCommands(program, () => connectOwned(cliGlobals()));
|
|
3129
4100
|
registerSecurityCommands(program, () => connectOwned(cliGlobals()));
|
|
3130
4101
|
registerGrowthCommand(program, () => connectOwned(cliGlobals()));
|
|
3131
4102
|
program.hook("preAction", () => {
|
|
@@ -3203,6 +4174,9 @@ program.command("start").description("Start the Gezel daemon (no-op if already r
|
|
|
3203
4174
|
"--web",
|
|
3204
4175
|
"Serve the web UI over HTTP on loopback and print a browser URL whose sign-in token lasts until the service restarts (reuses a daemon already serving it)."
|
|
3205
4176
|
).option("--open", "With --web, open the printed URL in your default browser.").option(
|
|
4177
|
+
"--accounts",
|
|
4178
|
+
"With --web, sign in with an account instead of a one-time URL; the first run prints a link to create one."
|
|
4179
|
+
).option(
|
|
3206
4180
|
"--restart",
|
|
3207
4181
|
"With --web or --port, stop a running daemon started without them and start a new one."
|
|
3208
4182
|
).action(
|
|
@@ -3226,6 +4200,7 @@ program.command("start").description("Start the Gezel daemon (no-op if already r
|
|
|
3226
4200
|
if (opts.web) {
|
|
3227
4201
|
spawnEnv.GEZEL_WEB = "1";
|
|
3228
4202
|
spawnEnv.GEZEL_INSECURE_TRANSPORT = "1";
|
|
4203
|
+
if (opts.accounts) spawnEnv.GEZEL_WEB_ACCOUNTS = "1";
|
|
3229
4204
|
}
|
|
3230
4205
|
if (opts.foreground) {
|
|
3231
4206
|
await startForeground(spawnEnv);
|
|
@@ -3234,18 +4209,18 @@ program.command("start").description("Start the Gezel daemon (no-op if already r
|
|
|
3234
4209
|
if (port !== void 0 || opts.web) {
|
|
3235
4210
|
const runtime = await readRuntime2();
|
|
3236
4211
|
const running = runtime && isProcessAlive2(runtime.pid) ? runtime : null;
|
|
3237
|
-
const
|
|
3238
|
-
|
|
3239
|
-
|
|
4212
|
+
const want = {
|
|
4213
|
+
port,
|
|
4214
|
+
web: opts.web === true,
|
|
4215
|
+
accounts: opts.web === true && opts.accounts === true
|
|
4216
|
+
};
|
|
4217
|
+
const shortfall = running ? await startShortfall(running, want, { readWebUiToken }) : null;
|
|
4218
|
+
const reuse = running !== null && shortfall === null;
|
|
4219
|
+
if (running && shortfall) {
|
|
3240
4220
|
if (!opts.restart) {
|
|
3241
|
-
|
|
3242
|
-
if (opts.web) retry.push("--web");
|
|
3243
|
-
throw new CliError(
|
|
3244
|
-
`gezeld is already running for this home ${opts.web ? "without the web UI" : `on port ${running.port}`} (pid ${running.pid}).
|
|
3245
|
-
Restart it ${wanted} with \`${[...retry, "--restart"].join(" ")}\`, or stop it first with \`gezel stop\`.`
|
|
3246
|
-
);
|
|
4221
|
+
throw new CliError(startShortfallMessage(shortfall, running, want));
|
|
3247
4222
|
}
|
|
3248
|
-
console.error(`Restarting gezeld (pid ${running.pid}) ${
|
|
4223
|
+
console.error(`Restarting gezeld (pid ${running.pid}) ${startRestartWanted(want)}\u2026`);
|
|
3249
4224
|
if (!await stopDaemonPid(running.pid)) {
|
|
3250
4225
|
throw new CliError(`failed to confirm gezeld pid=${running.pid} stopped`);
|
|
3251
4226
|
}
|
|
@@ -3255,7 +4230,7 @@ Restart it ${wanted} with \`${[...retry, "--restart"].join(" ")}\`, or stop it f
|
|
|
3255
4230
|
daemonEntry: entry,
|
|
3256
4231
|
detached: true,
|
|
3257
4232
|
env: spawnEnv,
|
|
3258
|
-
// Never adopt a daemon that lacks the requested port or
|
|
4233
|
+
// Never adopt a daemon that lacks the requested port, transport or accounts.
|
|
3259
4234
|
// A forced spawn accepts only its own process, so losing a race
|
|
3260
4235
|
// fails here instead of reporting someone else's daemon.
|
|
3261
4236
|
forceSpawn: !reuse,
|
|
@@ -3270,7 +4245,11 @@ Restart it ${wanted} with \`${[...retry, "--restart"].join(" ")}\`, or stop it f
|
|
|
3270
4245
|
console.log(
|
|
3271
4246
|
`gezeld running (version ${health2.version}) on port ${new URL(result.baseUrl).port}`
|
|
3272
4247
|
);
|
|
3273
|
-
if (opts.web
|
|
4248
|
+
if (opts.web && opts.accounts) {
|
|
4249
|
+
await printAccountsWebUrl(result.client.accounts, result.baseUrl, opts.open === true);
|
|
4250
|
+
} else if (opts.web) {
|
|
4251
|
+
await printWebUrl(result.baseUrl, opts.open === true);
|
|
4252
|
+
}
|
|
3274
4253
|
return;
|
|
3275
4254
|
}
|
|
3276
4255
|
const client = await connectOwned(cliGlobals(), { announceSpawn: false });
|
|
@@ -3278,19 +4257,30 @@ Restart it ${wanted} with \`${[...retry, "--restart"].join(" ")}\`, or stop it f
|
|
|
3278
4257
|
console.log(`gezeld running (version ${health.version})`);
|
|
3279
4258
|
}
|
|
3280
4259
|
);
|
|
3281
|
-
async function
|
|
3282
|
-
|
|
3283
|
-
if (!want.web) return true;
|
|
3284
|
-
if (new URL(runtime.baseUrl).protocol !== "http:") return false;
|
|
3285
|
-
const { readFile: readFile4 } = await import("fs/promises");
|
|
4260
|
+
async function readWebUiToken() {
|
|
4261
|
+
const { readFile: readFile5 } = await import("fs/promises");
|
|
3286
4262
|
const { gezelPaths: gezelPaths2 } = await import("@bendyline/gezel/paths");
|
|
3287
|
-
|
|
3288
|
-
|
|
4263
|
+
return readFile5(gezelPaths2().runtime.webUiToken, "utf8").catch(() => "");
|
|
4264
|
+
}
|
|
4265
|
+
async function printAccountsWebUrl(client, baseUrl, open) {
|
|
4266
|
+
const origin = new URL(baseUrl).origin;
|
|
4267
|
+
const state = await client.getSignInState();
|
|
4268
|
+
let url = `${origin}/`;
|
|
4269
|
+
if (state.setupRequired) {
|
|
4270
|
+
const link = await client.createSetupLink();
|
|
4271
|
+
if (link.code) url = `${origin}/?setup=${encodeURIComponent(link.code)}`;
|
|
4272
|
+
}
|
|
4273
|
+
console.log("");
|
|
4274
|
+
console.log(
|
|
4275
|
+
state.setupRequired ? ` Create your account \u2192 ${url}` : ` Gezel web UI \u2192 ${url} (sign in with your account)`
|
|
4276
|
+
);
|
|
4277
|
+
console.log("");
|
|
4278
|
+
if (open) await openInBrowser(url);
|
|
3289
4279
|
}
|
|
3290
4280
|
async function printWebUrl(baseUrl, open) {
|
|
3291
|
-
const { readFile:
|
|
4281
|
+
const { readFile: readFile5 } = await import("fs/promises");
|
|
3292
4282
|
const { gezelPaths: gezelPaths2 } = await import("@bendyline/gezel/paths");
|
|
3293
|
-
const token = (await
|
|
4283
|
+
const token = (await readFile5(gezelPaths2().runtime.webUiToken, "utf8").catch(() => "")).trim();
|
|
3294
4284
|
if (!token) {
|
|
3295
4285
|
throw new CliError(
|
|
3296
4286
|
"gezeld is running, but it published no web UI token, so there is no browser URL to print. Run `gezel start --web --restart`."
|
|
@@ -3336,10 +4326,10 @@ async function startForeground(env2) {
|
|
|
3336
4326
|
process.on("SIGINT", requestStop);
|
|
3337
4327
|
process.on("SIGTERM", requestStop);
|
|
3338
4328
|
try {
|
|
3339
|
-
await new Promise((
|
|
4329
|
+
await new Promise((resolve7) => {
|
|
3340
4330
|
child.on("exit", (code) => {
|
|
3341
4331
|
process.exitCode = code ?? 0;
|
|
3342
|
-
|
|
4332
|
+
resolve7();
|
|
3343
4333
|
});
|
|
3344
4334
|
});
|
|
3345
4335
|
} finally {
|
|
@@ -3468,11 +4458,11 @@ program.command("stop").description(
|
|
|
3468
4458
|
}
|
|
3469
4459
|
});
|
|
3470
4460
|
async function clearStaleRuntime(stoppedPid, opts = {}) {
|
|
3471
|
-
const { readFile:
|
|
4461
|
+
const { readFile: readFile5, rm: rm3 } = await import("fs/promises");
|
|
3472
4462
|
const { gezelPaths: gezelPaths2 } = await import("@bendyline/gezel/paths");
|
|
3473
4463
|
const runtime = gezelPaths2().runtime;
|
|
3474
4464
|
const recorded = Number.parseInt(
|
|
3475
|
-
(await
|
|
4465
|
+
(await readFile5(runtime.pid, "utf8").catch(() => "")).trim(),
|
|
3476
4466
|
10
|
|
3477
4467
|
);
|
|
3478
4468
|
if (recorded !== stoppedPid || !opts.pidReused && isProcessAlive2(stoppedPid)) return;
|
|
@@ -3602,7 +4592,9 @@ Examples:
|
|
|
3602
4592
|
gezel run - < prompt.txt
|
|
3603
4593
|
|
|
3604
4594
|
A sole - reads UTF-8 stdin to EOF. Empty input is rejected.
|
|
3605
|
-
Replies go to stdout; diagnostics go to stderr
|
|
4595
|
+
Replies go to stdout; diagnostics go to stderr.
|
|
4596
|
+
With no model set up yet, a run in a terminal first offers to download one,
|
|
4597
|
+
then runs the prompt.`
|
|
3606
4598
|
).action(async (promptParts, opts) => {
|
|
3607
4599
|
const prompt = await resolveRunPrompt(promptParts);
|
|
3608
4600
|
const previousLogOutput = getLogOutput2();
|
|
@@ -3623,7 +4615,25 @@ Replies go to stdout; diagnostics go to stderr.`
|
|
|
3623
4615
|
const { client } = conn;
|
|
3624
4616
|
const projectId = await resolveRunProject(client, cliGlobals());
|
|
3625
4617
|
const gezelId = opts.gezel ? await resolveRunGezel(client, opts.gezel) : await ensureCliProjectLead(client, projectId);
|
|
3626
|
-
|
|
4618
|
+
let readiness = await checkRunReadiness(client, gezelId);
|
|
4619
|
+
if (!readiness.ready && canOfferRunSetup()) {
|
|
4620
|
+
const tuiModule = "../tui/index.js";
|
|
4621
|
+
const { launchRunSetup } = await import(tuiModule);
|
|
4622
|
+
const runLogLevel = getLogLevel2();
|
|
4623
|
+
if (!process.env.GEZEL_LOG_LEVEL) setLogLevel2("error");
|
|
4624
|
+
let finished;
|
|
4625
|
+
try {
|
|
4626
|
+
finished = await launchRunSetup({ client });
|
|
4627
|
+
} finally {
|
|
4628
|
+
setLogLevel2(runLogLevel);
|
|
4629
|
+
}
|
|
4630
|
+
if (!finished) {
|
|
4631
|
+
console.error("Setup stopped. Your request was not run.");
|
|
4632
|
+
process.exitCode = 130;
|
|
4633
|
+
return;
|
|
4634
|
+
}
|
|
4635
|
+
readiness = await checkRunReadiness(client, gezelId);
|
|
4636
|
+
}
|
|
3627
4637
|
if (!readiness.ready) {
|
|
3628
4638
|
console.error(readiness.message);
|
|
3629
4639
|
process.exitCode = 1;
|
|
@@ -3685,7 +4695,7 @@ Examples:
|
|
|
3685
4695
|
"named craftbook parameter (repeatable)",
|
|
3686
4696
|
(value, values) => [...values, value],
|
|
3687
4697
|
[]
|
|
3688
|
-
).option("--wait", "wait for completion; exit nonzero when blocked, canceled, or timed out").option("--timeout <seconds>", "wait budget in seconds; timeout leaves the task running", "7200").option("--json", "emit one JSON result on stdout").option(
|
|
4698
|
+
).option("--wait", "wait for completion; exit nonzero when blocked, canceled, or timed out").option("--timeout <seconds>", "wait budget in seconds; timeout leaves the task running", "7200").option("--out <dir>", "wait, then copy what the task made into this folder").option("--json", "emit one JSON result on stdout").option(
|
|
3689
4699
|
"--strict-sandbox",
|
|
3690
4700
|
"require OS network isolation for custom scripts (CLI launches otherwise trust this recipe snapshot)"
|
|
3691
4701
|
).addOption(new Option(SHORTHAND_FLAG).hideHelp()).action(
|
|
@@ -3765,9 +4775,17 @@ Examples:
|
|
|
3765
4775
|
trustScripts: !opts.strictSandbox,
|
|
3766
4776
|
roleBasedNameOnlyMode: true
|
|
3767
4777
|
});
|
|
3768
|
-
if (opts.wait) {
|
|
4778
|
+
if (opts.wait || opts.out) {
|
|
3769
4779
|
console.error(`started ${created.ref} \u2014 ${created.title}`);
|
|
3770
|
-
await printTaskWait(client, created.ref, { ...opts, timeoutMs });
|
|
4780
|
+
const waited = await printTaskWait(client, created.ref, { ...opts, timeoutMs });
|
|
4781
|
+
if (opts.out && waited.outcome === "complete") {
|
|
4782
|
+
const dir = waited.task.artifactDir;
|
|
4783
|
+
if (!dir) throw new CliError(`${created.ref} finished without a task folder to copy.`);
|
|
4784
|
+
const copied = await copyTaskOutput(client, projectId, dir, opts.out);
|
|
4785
|
+
console.error(
|
|
4786
|
+
`copied ${copied.length} file${copied.length === 1 ? "" : "s"} to ${opts.out}`
|
|
4787
|
+
);
|
|
4788
|
+
}
|
|
3771
4789
|
} else
|
|
3772
4790
|
console.log(
|
|
3773
4791
|
opts.json ? JSON.stringify(created) : `started ${created.ref} \u2014 ${created.title}`
|
|
@@ -3813,12 +4831,13 @@ async function printTaskWait(client, ref, opts) {
|
|
|
3813
4831
|
console.error(`See its notes with \`gezel task notes ${result.task.ref}\`.`);
|
|
3814
4832
|
}
|
|
3815
4833
|
process.exitCode = result.exitCode;
|
|
4834
|
+
return result;
|
|
3816
4835
|
}
|
|
3817
4836
|
var craftbook = program.command("craftbook").description("Browse the craftbooks `gezel do` can start");
|
|
3818
4837
|
craftbook.command("list [words...]").description(
|
|
3819
4838
|
"List the craftbooks `gezel do` can start in this folder's project; words filter by command, title and tags"
|
|
3820
|
-
).option("--json", "emit the list as JSON").action(async (words, opts) => {
|
|
3821
|
-
const client = await
|
|
4839
|
+
).option("--json", "emit the list as JSON").option("--no-start", "Use a running service only; never start one").action(async (words, opts) => {
|
|
4840
|
+
const client = await connectForInspection(opts);
|
|
3822
4841
|
const preview = await previewRunProject(client, cliGlobals());
|
|
3823
4842
|
const projectId = preview.projectId ?? "default";
|
|
3824
4843
|
const [config, result] = await Promise.all([
|
|
@@ -4018,6 +5037,9 @@ handboek.command("export").description("Render the Handboek as a static HTML sit
|
|
|
4018
5037
|
).option("--og-out <dir>", "directory to render Open Graph cards into; must be outside --out").option(
|
|
4019
5038
|
"--og-base <url>",
|
|
4020
5039
|
"absolute URL the card directory is served from (e.g. https://gezel.com/og/); required with --og-out"
|
|
5040
|
+
).option(
|
|
5041
|
+
"--apps-out <dir>",
|
|
5042
|
+
"also write the apps library (gezel.com/apps) into this directory, outside --out"
|
|
4021
5043
|
).action(
|
|
4022
5044
|
async (opts) => {
|
|
4023
5045
|
if (Boolean(opts.ogOut) !== Boolean(opts.ogBase)) {
|
|
@@ -4033,10 +5055,15 @@ handboek.command("export").description("Render the Handboek as a static HTML sit
|
|
|
4033
5055
|
siteUrl: opts.siteUrl,
|
|
4034
5056
|
canonicalBase: opts.canonicalBase,
|
|
4035
5057
|
ogOut: opts.ogOut,
|
|
4036
|
-
ogBase: opts.ogBase
|
|
5058
|
+
ogBase: opts.ogBase,
|
|
5059
|
+
appsOut: opts.appsOut
|
|
4037
5060
|
});
|
|
4038
5061
|
console.log(`Handboek exported: ${result.pages} pages \u2192 ${result.out}`);
|
|
5062
|
+
if (result.apps) {
|
|
5063
|
+
console.log(`Apps library: ${result.apps.apps} apps, ${result.apps.demos} with demos`);
|
|
5064
|
+
}
|
|
4039
5065
|
for (const id of result.skipped) console.error(` skipped (no body): ${id}`);
|
|
5066
|
+
for (const note of result.warnings) console.error(` data table: ${note}`);
|
|
4040
5067
|
const cards = result.cards;
|
|
4041
5068
|
if (cards?.skipped) {
|
|
4042
5069
|
console.error(` no Open Graph cards: ${cards.skipped}`);
|
|
@@ -4636,16 +5663,27 @@ model.command("context <id> [tokens]").description("Show or set a model context
|
|
|
4636
5663
|
);
|
|
4637
5664
|
}
|
|
4638
5665
|
);
|
|
4639
|
-
model.command("list").description("List downloaded chat models, or with --available the catalog models that fit").option("-p, --provider <engine>", "mlx | llama-cpp | ds4 (default: platform default)").option("-a, --available", "List catalog models for this machine, with download sizes").action(async (opts) => {
|
|
4640
|
-
const client = await
|
|
5666
|
+
model.command("list").description("List downloaded chat models, or with --available the catalog models that fit").option("-p, --provider <engine>", "mlx | llama-cpp | ds4 (default: platform default)").option("-a, --available", "List catalog models for this machine, with download sizes").option("--no-start", "Use a running service only; never start one").action(async (opts) => {
|
|
5667
|
+
const client = await connectForInspection(opts);
|
|
4641
5668
|
const provider = resolveModelProvider(opts.provider);
|
|
4642
5669
|
if (opts.available) {
|
|
4643
5670
|
const available = await availableChatModels(client, provider);
|
|
5671
|
+
const health = await client.health().catch(() => null);
|
|
5672
|
+
const device = {
|
|
5673
|
+
platform: health?.platform ?? process.platform,
|
|
5674
|
+
arch: process.arch,
|
|
5675
|
+
label: health?.platform ?? process.platform
|
|
5676
|
+
};
|
|
4644
5677
|
console.log(
|
|
4645
5678
|
formatAvailableChatModels({
|
|
4646
5679
|
engine: provider,
|
|
4647
5680
|
platformDefault: resolveOnDeviceProvider3(process.platform, process.arch),
|
|
4648
|
-
...available
|
|
5681
|
+
...available,
|
|
5682
|
+
measured: measuredClaimsFor(
|
|
5683
|
+
SCORECARD,
|
|
5684
|
+
available.ranked.map((m) => m.id),
|
|
5685
|
+
device
|
|
5686
|
+
)
|
|
4649
5687
|
})
|
|
4650
5688
|
);
|
|
4651
5689
|
return;
|
|
@@ -4712,6 +5750,10 @@ program.command("doctor").description("Check the Gezel installation").action(asy
|
|
|
4712
5750
|
console.log(
|
|
4713
5751
|
`machine engine: healthy (${broker.baseUrl}) version=${broker.version} \u2014 compute broker; the product API is the per-user daemon`
|
|
4714
5752
|
);
|
|
5753
|
+
} else if (broker?.present && broker.healthy === false && broker.staleRuntimeDir) {
|
|
5754
|
+
console.log(
|
|
5755
|
+
`machine service: not running; its runtime files were left behind in ${broker.staleRuntimeDir} (remove them if you uninstalled the Gezel app)`
|
|
5756
|
+
);
|
|
4715
5757
|
} else if (broker?.present && broker.healthy === false) {
|
|
4716
5758
|
console.log(`machine service: runtime files present but unreachable (port ${broker.port})`);
|
|
4717
5759
|
} else if (broker?.present) {
|
|
@@ -4722,6 +5764,7 @@ program.command("doctor").description("Check the Gezel installation").action(asy
|
|
|
4722
5764
|
console.log("machine service: not installed");
|
|
4723
5765
|
}
|
|
4724
5766
|
console.log(`runtime file: ${runtime ? "present" : "missing"}`);
|
|
5767
|
+
let serviceReachable = Boolean(system);
|
|
4725
5768
|
if (runtime) {
|
|
4726
5769
|
const alive = isProcessAlive2(runtime.pid);
|
|
4727
5770
|
console.log(` port=${runtime.port} pid=${runtime.pid} alive=${alive}`);
|
|
@@ -4733,12 +5776,59 @@ program.command("doctor").description("Check the Gezel installation").action(asy
|
|
|
4733
5776
|
...runtime.cert ? { fetch: createTrustingFetch2({ cert: runtime.cert }) } : {}
|
|
4734
5777
|
});
|
|
4735
5778
|
const health = await client.health();
|
|
5779
|
+
serviceReachable = true;
|
|
4736
5780
|
const engineNote = health.machineEngineConnected !== void 0 ? ` machine engine connected: ${health.machineEngineConnected ? "yes" : "no"}` : "";
|
|
4737
5781
|
console.log(` role=${health.serviceRole ?? "user"}${engineNote}`);
|
|
4738
5782
|
} catch {
|
|
4739
5783
|
}
|
|
4740
5784
|
}
|
|
4741
5785
|
}
|
|
5786
|
+
let modelId;
|
|
5787
|
+
let fitnessAdmitted = null;
|
|
5788
|
+
if (serviceReachable || globals.connect) {
|
|
5789
|
+
try {
|
|
5790
|
+
await withTransientConnection(globals, async (client) => {
|
|
5791
|
+
const [config, fitness, health] = await Promise.all([
|
|
5792
|
+
client.getConfig(),
|
|
5793
|
+
client.listModelFitness().catch(() => ({
|
|
5794
|
+
records: [],
|
|
5795
|
+
probing: []
|
|
5796
|
+
})),
|
|
5797
|
+
client.health().catch(() => null)
|
|
5798
|
+
]);
|
|
5799
|
+
const provider = config.provider ?? "llama-cpp";
|
|
5800
|
+
modelId = config.defaultModel?.[provider];
|
|
5801
|
+
const key = modelId ? `${provider}:${modelId}` : "";
|
|
5802
|
+
const entry = fitness.records.find((r) => r.key === key);
|
|
5803
|
+
if (entry?.record.status === "probed" && !entry.stale)
|
|
5804
|
+
fitnessAdmitted = entry.record.admitted;
|
|
5805
|
+
const device = {
|
|
5806
|
+
platform: health?.platform ?? process.platform,
|
|
5807
|
+
arch: process.arch,
|
|
5808
|
+
label: health?.platform ?? process.platform
|
|
5809
|
+
};
|
|
5810
|
+
for (const line of renderDoctorModel({
|
|
5811
|
+
provider,
|
|
5812
|
+
modelId,
|
|
5813
|
+
fitness: entry,
|
|
5814
|
+
probing: fitness.probing.includes(key),
|
|
5815
|
+
dataset: SCORECARD,
|
|
5816
|
+
device
|
|
5817
|
+
})) {
|
|
5818
|
+
console.log(line);
|
|
5819
|
+
}
|
|
5820
|
+
});
|
|
5821
|
+
} catch {
|
|
5822
|
+
}
|
|
5823
|
+
}
|
|
5824
|
+
console.log(
|
|
5825
|
+
doctorVerdict({
|
|
5826
|
+
nodeOk: unsupportedNodeMessage(process.versions.node) === void 0,
|
|
5827
|
+
serviceReachable,
|
|
5828
|
+
modelId,
|
|
5829
|
+
fitnessAdmitted
|
|
5830
|
+
})
|
|
5831
|
+
);
|
|
4742
5832
|
});
|
|
4743
5833
|
program.command("cleanup").description("Show or reclaim the space Gezel is using on this device").option("--refresh", "Re-measure instead of using the cached sizes").option("--models", "Delete downloaded models").option("--engines", "Delete engine binaries and their caches").option("--toolsets", "Delete installed tools and the automation browser").option("--caches", "Delete catalog content and generated indexes").option("--redownloadable", "Delete everything Gezel can download again").option(
|
|
4744
5834
|
"--content <what>",
|