@bendyline/gezel-cli 1.2.11 → 1.2.12

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.
@@ -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 { streamChatEvents } from "@bendyline/gezel-client";
18
+ import {
19
+ streamChatEvents
20
+ } from "@bendyline/gezel-client";
18
21
  import {
19
22
  GezelClient as GezelClient2,
20
23
  createTrustingFetch as createTrustingFetch2,
@@ -30,36 +33,8 @@ import {
30
33
  import { resolveOnDeviceProvider as resolveOnDeviceProvider3 } from "@bendyline/gezel/native";
31
34
  import { Command, Option } from "commander";
32
35
 
33
- // src/cli-errors.ts
34
- function formatCliFailure(err, env2 = process.env) {
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";
@@ -96,6 +71,7 @@ import {
96
71
  readSystemServiceEndpoint,
97
72
  resolveDaemonEntry,
98
73
  stopOwnedDaemon,
74
+ systemServiceRuntimeIsStale,
99
75
  systemSharedAssetsDir
100
76
  } from "@bendyline/gezel-client/node";
101
77
  import { gezelHome, gezelPaths, nativePayloadVerificationPath } from "@bendyline/gezel/paths";
@@ -207,6 +183,17 @@ async function connectOwned(globals, options = {}) {
207
183
  );
208
184
  return connected.client;
209
185
  }
186
+ 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.";
187
+ async function connectRunning(globals, deps = {}) {
188
+ applyHome(globals);
189
+ const preferred = await connectPreferredService(globals);
190
+ if (preferred) return preferred.client;
191
+ const runtime = await (deps.readRuntime ?? readRuntime)();
192
+ if (!runtime || !(deps.isAlive ?? isProcessAlive)(runtime.pid)) {
193
+ throw new CliError(NO_RUNNING_SERVICE_MESSAGE);
194
+ }
195
+ return (deps.connectOwned ?? connectOwned)(globals, { announceSpawn: false });
196
+ }
210
197
  async function connectForTui(globals) {
211
198
  applyHome(globals);
212
199
  const preferred = await connectPreferredService(globals);
@@ -445,7 +432,16 @@ async function describeMachineEngineBroker(deps = {}) {
445
432
  ...health.startedAt !== void 0 ? { startedAt: health.startedAt } : {}
446
433
  };
447
434
  } catch {
448
- return { present: true, healthy: false, baseUrl: endpoint.baseUrl, port: endpoint.port };
435
+ const stale = await (deps.isRuntimeStale ?? systemServiceRuntimeIsStale)(endpoint.home).catch(
436
+ () => false
437
+ );
438
+ return {
439
+ present: true,
440
+ healthy: false,
441
+ baseUrl: endpoint.baseUrl,
442
+ port: endpoint.port,
443
+ ...stale ? { staleRuntimeDir: join(endpoint.home, "runtime") } : {}
444
+ };
449
445
  } finally {
450
446
  clearTimeout(timeout);
451
447
  }
@@ -769,6 +765,679 @@ async function resolveTuiProject(client, globals) {
769
765
  return resolveCommandProject(client, globals);
770
766
  }
771
767
 
768
+ // src/account-command.ts
769
+ async function readNewPassword(options, input = process.stdin, write = (text) => process.stderr.write(text)) {
770
+ if (options.passwordStdin) {
771
+ if (input.isTTY) throw new CliError("--password-stdin needs piped input.");
772
+ const chunks = [];
773
+ for await (const chunk of input) {
774
+ chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
775
+ if (chunks.reduce((n, c) => n + c.length, 0) > 4096) {
776
+ throw new CliError("The password is too long.");
777
+ }
778
+ }
779
+ return Buffer.concat(chunks).toString("utf8").replace(/\r?\n$/, "");
780
+ }
781
+ if (!input.isTTY || !input.setRawMode) {
782
+ throw new CliError("No terminal to type a password into. Pipe it in with --password-stdin.");
783
+ }
784
+ const first = await promptHidden("New password: ", input, write);
785
+ const second = await promptHidden("Type it again: ", input, write);
786
+ if (first !== second) throw new CliError("The two passwords did not match.");
787
+ return first;
788
+ }
789
+ function promptHidden(prompt, input, write) {
790
+ write(prompt);
791
+ return new Promise((resolve7, reject) => {
792
+ let value = "";
793
+ const done = (error) => {
794
+ input.off?.("data", onData);
795
+ input.setRawMode?.(false);
796
+ input.pause?.();
797
+ write("\n");
798
+ if (error) reject(error);
799
+ else resolve7(value);
800
+ };
801
+ const onData = (chunk) => {
802
+ for (const ch of chunk.toString("utf8")) {
803
+ if (ch === "\r" || ch === "\n") return done();
804
+ if (ch === "") return done(new CliError("Canceled."));
805
+ if (ch === "\x7F" || ch === "\b") value = value.slice(0, -1);
806
+ else if (ch >= " ") value += ch;
807
+ }
808
+ };
809
+ input.setRawMode?.(true);
810
+ input.resume?.();
811
+ input.on?.("data", onData);
812
+ });
813
+ }
814
+ async function findAccount(client, name) {
815
+ const key = name.trim().toLowerCase();
816
+ const { accounts } = await client.listAccounts();
817
+ const match = accounts.find((a) => a.name.toLowerCase() === key || a.id === name);
818
+ if (!match) throw new CliError(`There is no account called "${name}". See "gezel account list".`);
819
+ return match;
820
+ }
821
+ async function plainly(run) {
822
+ try {
823
+ return await run();
824
+ } catch (error) {
825
+ if (error instanceof GezelApiError2 && error.status < 500 && error.status > 0) {
826
+ const details = error.details;
827
+ if (error.status === 404 && details?.error === "accounts_unavailable") {
828
+ throw new CliError("This Gezel service has no accounts.");
829
+ }
830
+ throw new CliError(apiErrorMessage(error));
831
+ }
832
+ throw error;
833
+ }
834
+ }
835
+ function describeAccount(account) {
836
+ const state = account.disabledAt ? "disabled" : account.role;
837
+ const seen = account.lastSignInAt ? `last signed in ${account.lastSignInAt.slice(0, 10)}` : "never signed in";
838
+ return `${account.name} ${state} ${seen}`;
839
+ }
840
+ function describeSession(session) {
841
+ return [
842
+ session.label ?? "unknown",
843
+ session.address ?? "",
844
+ `last seen ${session.lastSeenAt.slice(0, 16).replace("T", " ")}`
845
+ ].filter(Boolean).join(" ");
846
+ }
847
+ function registerAccountCommands(program2, connect, output = console.log, input = process.stdin) {
848
+ const account = program2.command("account").description("Manage the accounts that sign in to this Gezel from a browser");
849
+ account.command("list").description("List accounts").option("--json", "Output as JSON").action(async (options) => {
850
+ const { accounts } = await plainly(async () => (await connect()).listAccounts());
851
+ if (options.json) return output(JSON.stringify({ accounts }));
852
+ output(accounts.length ? accounts.map(describeAccount).join("\n") : "No accounts yet.");
853
+ });
854
+ 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) => {
855
+ const client = await connect();
856
+ const password = await readNewPassword(options, input);
857
+ const created = await plainly(() => client.createAccount(name, password));
858
+ output(options.json ? JSON.stringify(created) : `${created.account.name} can now sign in.`);
859
+ });
860
+ 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) => {
861
+ const client = await connect();
862
+ const target = await findAccount(client, name);
863
+ const password = await readNewPassword(options, input);
864
+ await plainly(() => client.setAccountPassword(target.id, password));
865
+ output(`${target.name}'s password was changed. They are signed out everywhere.`);
866
+ });
867
+ for (const [verb, disabled, done] of [
868
+ ["disable", true, "can no longer sign in"],
869
+ ["enable", false, "can sign in again"]
870
+ ]) {
871
+ account.command(`${verb} <name>`).description(disabled ? "Stop an account signing in" : "Let a disabled account sign in again").action(async (name) => {
872
+ const client = await connect();
873
+ const target = await findAccount(client, name);
874
+ await plainly(() => client.updateAccount(target.id, { disabled }));
875
+ output(`${target.name} ${done}.`);
876
+ });
877
+ }
878
+ account.command("remove <name>").description("Remove an account and sign it out everywhere").option("--yes", "Do not ask for confirmation").action(async (name, options) => {
879
+ if (!options.yes)
880
+ throw new CliError("Removing an account cannot be undone. Add --yes to go ahead.");
881
+ const client = await connect();
882
+ const target = await findAccount(client, name);
883
+ await plainly(() => client.removeAccount(target.id));
884
+ output(`${target.name} was removed.`);
885
+ });
886
+ account.command("sessions <name>").description("List where an account is signed in").option("--json", "Output as JSON").action(async (name, options) => {
887
+ const client = await connect();
888
+ const target = await findAccount(client, name);
889
+ const { sessions } = await plainly(() => client.listAccountSessions(target.id));
890
+ if (options.json) return output(JSON.stringify({ sessions }));
891
+ output(
892
+ sessions.length ? sessions.map(describeSession).join("\n") : `${target.name} is not signed in anywhere.`
893
+ );
894
+ });
895
+ account.command("sign-out-all <name>").description("Sign an account out of every browser").action(async (name) => {
896
+ const client = await connect();
897
+ const target = await findAccount(client, name);
898
+ const { signedOut } = await plainly(() => client.signOutAccountEverywhere(target.id));
899
+ output(
900
+ `Signed ${target.name} out of ${signedOut} ${signedOut === 1 ? "browser" : "browsers"}.`
901
+ );
902
+ });
903
+ account.command("setup-link").description("Print a new link to create the first account (only while there is none)").action(async () => {
904
+ const { code, url } = await plainly(async () => (await connect()).createSetupLink());
905
+ if (!code)
906
+ throw new CliError('This Gezel already has an account. Use "gezel account create".');
907
+ output(url ? `Open this link to create the first account:
908
+ ${url}` : `Setup code: ${code}`);
909
+ });
910
+ }
911
+ function registerIntegrationCommands(program2, connect, output = console.log) {
912
+ const token = program2.command("integrations").description("Connect other apps to this Gezel").command("token").description("Make or revoke an app key");
913
+ 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(
914
+ "--scope <scope...>",
915
+ "What the key may do: openai, knowledge, images, product or cli (default: openai)"
916
+ ).option("--json", "Output as JSON").action(async (appId, options) => {
917
+ const client = await connect();
918
+ const created = await plainly(
919
+ () => client.createAppToken(appId, {
920
+ ...options.name ? { appName: options.name } : {},
921
+ ...options.scope?.length ? { scopes: options.scope } : {}
922
+ })
923
+ );
924
+ if (options.json) return output(JSON.stringify(created));
925
+ output(
926
+ [
927
+ `Key for ${created.appId} (${created.scopes.join(", ")}):`,
928
+ ` ${created.token}`,
929
+ "",
930
+ "Use it as the API key, with the base URL ending in /v1.",
931
+ 'It is shown once. Revoke it with "gezel integrations token revoke".'
932
+ ].join("\n")
933
+ );
934
+ });
935
+ token.command("revoke <appId>").description("Revoke an app's key").action(async (appId) => {
936
+ const { revoked } = await plainly(async () => (await connect()).revokeAppToken(appId));
937
+ output(revoked ? `${appId} can no longer connect.` : `${appId} had no key.`);
938
+ });
939
+ }
940
+
941
+ // src/bench-command.ts
942
+ import { execFile } from "child_process";
943
+ import { readFileSync } from "fs";
944
+ import { readFile as readFile2, writeFile as writeFile2 } from "fs/promises";
945
+ import { cpus } from "os";
946
+ import { join as join2 } from "path";
947
+ import { promisify } from "util";
948
+ import { ScorecardDatasetSchema } from "@bendyline/gezel";
949
+ import { gildePackageRoot } from "@bendyline/gezel-catalog";
950
+ import {
951
+ EVAL_SUBSET_NOTE,
952
+ SCORECARD_SUITE_IDS,
953
+ SCORECARD_SUITE_LABELS,
954
+ buildEvalMatrix,
955
+ describeEvalHost,
956
+ describeEvalRun,
957
+ evalDeviceFromHost,
958
+ evalEngineBuilds,
959
+ evalRunId,
960
+ evalRunProvenance,
961
+ evalShard,
962
+ evalSuiteResult,
963
+ isSuiteSubset,
964
+ medianDecodeTokensPerSec,
965
+ smokeSuiteIdFor
966
+ } from "@bendyline/gezel/eval";
967
+ var BENCH_CONFIRM_ABOVE_MS = 60 * 6e4;
968
+ var BENCH_SUBMIT_REPO = "bendyline/gezel";
969
+ function formatDuration(ms) {
970
+ if (ms < 6e4) return `${Math.max(1, Math.round(ms / 1e3))}s`;
971
+ const minutes = Math.round(ms / 6e4);
972
+ if (minutes < 60) return `${minutes}m`;
973
+ const hours = Math.floor(minutes / 60);
974
+ const rest = minutes % 60;
975
+ return rest ? `${hours}h ${rest}m` : `${hours}h`;
976
+ }
977
+ function resolveBenchSuites(catalog, opts) {
978
+ const wanted = !opts.suite || opts.suite === "core" || opts.suite === "default" ? ["core"] : opts.suite === "all" ? (
979
+ // Every scorecard suite this daemon's catalog carries; an older
980
+ // harness without one of them still runs the rest.
981
+ SCORECARD_SUITE_IDS.filter((id) => catalog.suites.some((s) => s.id === id))
982
+ ) : opts.suite.split(",").map((s) => s.trim()).filter(Boolean);
983
+ const suites = [];
984
+ for (const id of wanted) {
985
+ const base = catalog.suites.find((s) => s.id === id);
986
+ if (!base) {
987
+ throw new CliError(
988
+ `Unknown suite "${id}". Choose one of: ${SCORECARD_SUITE_IDS.join(", ")}, or all. \`gezel bench list\` shows every suite.`
989
+ );
990
+ }
991
+ if (opts.smoke) {
992
+ const smokeId = smokeSuiteIdFor(id, catalog);
993
+ const smoke = smokeId ? catalog.suites.find((s) => s.id === smokeId) : void 0;
994
+ if (!smoke) {
995
+ throw new CliError(`The ${id} suite has no smoke variant in this catalog.`);
996
+ }
997
+ suites.push(smoke);
998
+ } else {
999
+ suites.push(base);
1000
+ }
1001
+ }
1002
+ return suites;
1003
+ }
1004
+ function resolveBenchTarget(catalog, targets, opts) {
1005
+ const available = targets.filter((t) => t.available);
1006
+ if (opts.model) {
1007
+ const matches = available.filter(
1008
+ (t) => t.modelId === opts.model && (!opts.provider || t.provider === opts.provider)
1009
+ );
1010
+ const preferred = matches.find((t) => t.provider === catalog.defaultProvider) ?? matches[0];
1011
+ if (preferred) return preferred;
1012
+ const unavailable = targets.find(
1013
+ (t) => t.modelId === opts.model && (!opts.provider || t.provider === opts.provider)
1014
+ );
1015
+ throw new CliError(
1016
+ 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.`
1017
+ );
1018
+ }
1019
+ const byProvider = opts.provider ? available.filter((t) => t.provider === opts.provider) : available;
1020
+ 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];
1021
+ if (!chosen) {
1022
+ throw new CliError(
1023
+ "No model is available to evaluate. Download one with `gezel model pull <id>` or sign in to a cloud provider, then try again."
1024
+ );
1025
+ }
1026
+ return chosen;
1027
+ }
1028
+ function planBench(catalog, targets, opts) {
1029
+ const count = opts.count ?? 1;
1030
+ if (!Number.isInteger(count) || count < 1 || count > 10) {
1031
+ throw new CliError(
1032
+ "--count must be a whole number from 1 to 10 (3 is what it takes to quote a rate)."
1033
+ );
1034
+ }
1035
+ const suites = resolveBenchSuites(catalog, opts);
1036
+ const target = resolveBenchTarget(catalog, targets, opts);
1037
+ const worstCaseMs = suites.reduce((sum, s) => sum + s.authoredCeilingMs * count, 0);
1038
+ return { suites, target, count, worstCaseMs, smoke: Boolean(opts.smoke) };
1039
+ }
1040
+ function describePlan(plan, catalog) {
1041
+ const lines = [
1042
+ `Model: ${plan.target.label} (${plan.target.modelId} on ${plan.target.provider})`,
1043
+ `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` : ""}`
1044
+ ];
1045
+ for (const suite of plan.suites) {
1046
+ lines.push(
1047
+ `Suite: ${suite.id} \u2014 ${suite.scenarioIds.length} tasks, at most ${formatDuration(
1048
+ suite.authoredCeilingMs * plan.count
1049
+ )}`
1050
+ );
1051
+ if (plan.smoke) lines.push(` ${suite.description}`);
1052
+ }
1053
+ lines.push(
1054
+ `At most ${formatDuration(plan.worstCaseMs)} in all. The run keeps going if this terminal closes.`
1055
+ );
1056
+ return lines;
1057
+ }
1058
+ function describeJobOutcome(job) {
1059
+ switch (job.status) {
1060
+ case "completed":
1061
+ return null;
1062
+ case "failed":
1063
+ return `The run could not start: ${job.error ?? "the harness reported a setup error"}.`;
1064
+ case "cancelled":
1065
+ return "The run was stopped before it finished.";
1066
+ case "interrupted":
1067
+ return "The Gezel service stopped while the run was in progress; the trials it finished are counted.";
1068
+ default:
1069
+ return `The run ended in state "${job.status}".`;
1070
+ }
1071
+ }
1072
+ function renderSuiteReport(suite, target, trials, minTrialsForRate) {
1073
+ const matrix = buildEvalMatrix(trials, { scenarioOrder: suite.scenarioIds });
1074
+ const column = matrix.columns.find(
1075
+ (c) => c.modelId === target.modelId && (c.provider ?? target.provider) === target.provider
1076
+ );
1077
+ const width = Math.min(40, Math.max(12, ...suite.scenarioIds.map((id) => id.length)) + 2);
1078
+ const lines = [];
1079
+ for (const scenarioId of suite.scenarioIds) {
1080
+ const cell = column ? matrix.cell(scenarioId, column.key) : void 0;
1081
+ const claim = cell ? cell.claim : "not run";
1082
+ const extra = cell?.nonModelFailures ? ` (${cell.nonModelFailures} not counted: not the model's fault)` : "";
1083
+ lines.push(` ${scenarioId.padEnd(width)}${claim}${extra}`);
1084
+ }
1085
+ const total = column ? column.claim : "not measured";
1086
+ const label = SCORECARD_SUITE_LABELS[suite.id] ?? suite.id;
1087
+ lines.push(` ${"suite".padEnd(width)}${total}`);
1088
+ if (column && column.passRate === null && column.attributableTrials > 0) {
1089
+ lines.push(
1090
+ ` A count, not a rate: ${minTrialsForRate} trials per task is the floor for quoting a percentage.`
1091
+ );
1092
+ }
1093
+ const decode = medianDecodeTokensPerSec(trials);
1094
+ lines.push(
1095
+ ` Decode: ${decode ? `${decode.toFixed(1)} tok/s (median over finished tasks)` : "not recorded"}. Prefill: not recorded by the daemon's trial index.`
1096
+ );
1097
+ return [`${label} (${suite.id})`, ...lines];
1098
+ }
1099
+ function createJobFollower(suite, count) {
1100
+ let lastTrial = null;
1101
+ let lastCompleted = -1;
1102
+ let announcedWaiting = false;
1103
+ let announcedPreflight = false;
1104
+ return {
1105
+ update(job) {
1106
+ const lines = [];
1107
+ const target = job.targets[0];
1108
+ if (job.status === "waiting-for-device" && !announcedWaiting) {
1109
+ announcedWaiting = true;
1110
+ lines.push(
1111
+ `Waiting: another evaluation${job.waitingOn ? ` (${job.waitingOn})` : ""} holds this machine's engines.`
1112
+ );
1113
+ }
1114
+ if (!target) return lines;
1115
+ if (target.preflight && !announcedPreflight) {
1116
+ announcedPreflight = true;
1117
+ const p = target.preflight;
1118
+ lines.push(
1119
+ 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}` : ""}.`
1120
+ );
1121
+ }
1122
+ const planned = target.plannedTrials ?? suite.scenarioIds.length * count;
1123
+ if (target.completedTrials !== lastCompleted && lastCompleted >= 0) {
1124
+ lines.push(` ${target.completedTrials}/${planned} done, ${target.passedTrials} passed`);
1125
+ }
1126
+ lastCompleted = target.completedTrials;
1127
+ const current = target.currentTrial;
1128
+ if (current && current.trialId !== lastTrial) {
1129
+ lastTrial = current.trialId;
1130
+ lines.push(` ${current.scenarioId} (${current.trialIndex}/${planned}) running\u2026`);
1131
+ }
1132
+ return lines;
1133
+ }
1134
+ };
1135
+ }
1136
+ function finishedJob(job) {
1137
+ return job.status === "completed" || job.status === "failed" || job.status === "cancelled" || job.status === "interrupted";
1138
+ }
1139
+ async function followJob(client, job, suite, count, io, verbose = false) {
1140
+ const follower = createJobFollower(suite, count);
1141
+ let latest = job;
1142
+ for (const line of follower.update(job)) io.note(line);
1143
+ await client.streamEvalJob(job.id, (event) => {
1144
+ if (event.type === "log") {
1145
+ if (verbose) io.note(` ${event.line}`);
1146
+ return;
1147
+ }
1148
+ latest = event.job;
1149
+ for (const line of follower.update(event.job)) io.note(line);
1150
+ });
1151
+ if (!finishedJob(latest)) latest = await client.getEvalJob(job.id);
1152
+ return latest;
1153
+ }
1154
+ function defaultGildeVersion() {
1155
+ try {
1156
+ const pkg = JSON.parse(readFileSync(join2(gildePackageRoot(), "package.json"), "utf8"));
1157
+ return pkg.version ?? "unknown";
1158
+ } catch {
1159
+ return "unknown";
1160
+ }
1161
+ }
1162
+ function defaultCpuModel() {
1163
+ return cpus()[0]?.model?.trim() || void 0;
1164
+ }
1165
+ async function runBench(client, opts, io) {
1166
+ const [catalog, targetsResponse, host] = await Promise.all([
1167
+ client.getEvalCatalog(),
1168
+ client.listEvalTargets(),
1169
+ client.getSystemDiagnostics()
1170
+ ]);
1171
+ const plan = planBench(catalog, targetsResponse.targets, opts);
1172
+ const cpuModel = io.cpuModel ? io.cpuModel() : void 0;
1173
+ io.note(describeEvalHost(host, cpuModel));
1174
+ for (const line of describePlan(plan, catalog)) io.note(line);
1175
+ if (plan.worstCaseMs > BENCH_CONFIRM_ABOVE_MS && !opts.yes) {
1176
+ if (!io.confirm) {
1177
+ throw new CliError(
1178
+ `This run could take ${formatDuration(plan.worstCaseMs)}. Add --yes to start it without a prompt.`
1179
+ );
1180
+ }
1181
+ const go = await io.confirm(`Start a run of up to ${formatDuration(plan.worstCaseMs)}? [y/N] `);
1182
+ if (!go) throw new CliError("Not started.");
1183
+ }
1184
+ const startedAt = (io.now?.() ?? /* @__PURE__ */ new Date()).toISOString();
1185
+ const device = evalDeviceFromHost(host, cpuModel);
1186
+ const scenariosBySuite = {};
1187
+ const jobs = [];
1188
+ const results = [];
1189
+ const runId = evalRunId(startedAt, device, plan.target.modelId);
1190
+ const gildeVersion = (io.gildeVersion ?? defaultGildeVersion)();
1191
+ const run = evalRunProvenance({
1192
+ id: runId,
1193
+ startedAt,
1194
+ device,
1195
+ gezelVersion: host.version,
1196
+ gildeVersion,
1197
+ count: plan.count,
1198
+ engineBuilds: evalEngineBuilds(host),
1199
+ scenariosBySuite: Object.fromEntries(plan.suites.map((s) => [s.id, s.scenarioIds])),
1200
+ subset: false,
1201
+ ...opts.note ? { note: opts.note } : {}
1202
+ });
1203
+ for (const suite of plan.suites) {
1204
+ const spec = {
1205
+ suiteId: suite.id,
1206
+ count: plan.count,
1207
+ ...plan.count > 1 ? { countStrict: true } : {},
1208
+ targets: [{ provider: plan.target.provider, modelId: plan.target.modelId }],
1209
+ note: `gezel bench ${runId}`
1210
+ };
1211
+ io.note("");
1212
+ io.note(`Starting ${suite.id}\u2026`);
1213
+ const created = await client.createEvalJob(spec);
1214
+ const job = await followJob(client, created, suite, plan.count, io, opts.verbose);
1215
+ jobs.push(job);
1216
+ scenariosBySuite[suite.id] = suite.scenarioIds;
1217
+ const outcome = describeJobOutcome(job);
1218
+ if (outcome) io.note(outcome);
1219
+ const { trials } = await client.listEvalTrials({ jobId: job.id, limit: 2e3 });
1220
+ results.push(evalSuiteResult({ run, suite, target: plan.target, trials }));
1221
+ io.out("");
1222
+ for (const line of renderSuiteReport(suite, plan.target, trials, catalog.minTrialsForRate)) {
1223
+ io.out(line);
1224
+ }
1225
+ if (plan.smoke) io.out(` ${suite.description}`);
1226
+ }
1227
+ io.out("");
1228
+ io.out(describeEvalRun(run, [plan.target.provider]));
1229
+ io.out(
1230
+ `Results are kept in ${targetsResponse.environment.runsDir}; Settings \u2192 Benchmarks shows the same runs.`
1231
+ );
1232
+ const shard = evalShard(run, results);
1233
+ if (opts.json) {
1234
+ await writeFile2(opts.json, `${JSON.stringify(shard, null, 2)}
1235
+ `, "utf8");
1236
+ io.out(`Wrote ${opts.json}. Share it with \`gezel bench submit ${opts.json}\`.`);
1237
+ }
1238
+ return { run, results, jobs, shard };
1239
+ }
1240
+ function renderSuiteList(catalog) {
1241
+ const width = Math.max(...catalog.suites.map((s) => s.id.length)) + 2;
1242
+ const lines = [
1243
+ "Suites (`gezel bench --suite <id>`); times are the authored ceilings at one trial per task:"
1244
+ ];
1245
+ const scorecard = catalog.suites.filter(
1246
+ (s) => SCORECARD_SUITE_IDS.includes(s.id)
1247
+ );
1248
+ const rest = catalog.suites.filter((s) => !scorecard.includes(s));
1249
+ for (const suite of [...scorecard, ...rest]) {
1250
+ const label = SCORECARD_SUITE_LABELS[suite.id];
1251
+ lines.push(
1252
+ ` ${suite.id.padEnd(width)}${String(suite.scenarioIds.length).padStart(2)} tasks ${formatDuration(
1253
+ suite.authoredCeilingMs
1254
+ ).padStart(7)} ${label ?? suite.description}`
1255
+ );
1256
+ }
1257
+ lines.push(
1258
+ "",
1259
+ `The published scorecard runs ${SCORECARD_SUITE_IDS.join(", ")}. Add --smoke for a suite's pulse check; it is not a suite score.`
1260
+ );
1261
+ return lines;
1262
+ }
1263
+ async function renderResults(client, catalog, limit) {
1264
+ const { jobs } = await client.listEvalJobs();
1265
+ const finished = jobs.filter(finishedJob).slice(0, limit);
1266
+ if (finished.length === 0)
1267
+ return ["No finished runs on this machine yet. `gezel bench` starts one."];
1268
+ const lines = [];
1269
+ for (const job of finished) {
1270
+ const suite = job.spec.suiteId ? catalog.suites.find((s) => s.id === job.spec.suiteId) : void 0;
1271
+ const target = job.targets[0];
1272
+ const { trials } = await client.listEvalTrials({ jobId: job.id, limit: 2e3 });
1273
+ const order = suite?.scenarioIds ?? [...new Set(trials.map((t) => t.scenarioId))];
1274
+ const matrix = buildEvalMatrix(trials, { scenarioOrder: order });
1275
+ const column = target ? matrix.columns.find(
1276
+ (c) => c.modelId === target.modelId && (c.provider ?? target.provider) === target.provider
1277
+ ) : matrix.columns[0];
1278
+ const subset = suite && job.spec.scenarioIds ? isSuiteSubset(suite, job.spec.scenarioIds) : false;
1279
+ const what = suite ? `${suite.id}${subset ? " (subset)" : ""}` : `${job.spec.scenarioIds?.length ?? 0} tasks`;
1280
+ lines.push(
1281
+ `${(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}]` : ""}`
1282
+ );
1283
+ if (subset) lines.push(` ${EVAL_SUBSET_NOTE}`);
1284
+ }
1285
+ return lines;
1286
+ }
1287
+ function describeSubmission(shard) {
1288
+ const run = shard.runs[0];
1289
+ const models = [...new Set(shard.results.map((r) => `${r.modelId} (${r.engine})`))];
1290
+ const suites = run.suites.join(", ");
1291
+ const title = `Bench result: ${models.join(", ")} on ${run.provenance.device.label}`;
1292
+ const body = [
1293
+ "## Community bench result",
1294
+ "",
1295
+ `- Run: \`${run.id}\``,
1296
+ `- ${describeEvalRun(run, [...new Set(shard.results.map((r) => r.engine))])}`,
1297
+ `- Suites: ${suites}`,
1298
+ ...run.note ? [`- Note: ${run.note}`] : [],
1299
+ "",
1300
+ "Results (count below three trials per task, rate otherwise):",
1301
+ ...shard.results.map((r) => {
1302
+ const matrixLike = r.cells.reduce(
1303
+ (acc, c) => {
1304
+ acc.trials += Math.max(0, c.trials - c.nonModelFailures);
1305
+ acc.successes += c.successes;
1306
+ return acc;
1307
+ },
1308
+ { trials: 0, successes: 0 }
1309
+ );
1310
+ return `- ${r.suiteId}: ${matrixLike.successes}/${matrixLike.trials}`;
1311
+ }),
1312
+ "",
1313
+ "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.",
1314
+ "",
1315
+ "<details><summary>shard.json</summary>",
1316
+ "",
1317
+ "```json",
1318
+ JSON.stringify(shard, null, 2),
1319
+ "```",
1320
+ "",
1321
+ "</details>"
1322
+ ].join("\n");
1323
+ return { title, body };
1324
+ }
1325
+ var execFileAsync = promisify(execFile);
1326
+ async function submitBench(file, io, deps = {}) {
1327
+ const text = await (deps.readFile ?? ((p) => readFile2(p, "utf8")))(file);
1328
+ let shard;
1329
+ try {
1330
+ shard = ScorecardDatasetSchema.parse(JSON.parse(text));
1331
+ } catch (error) {
1332
+ throw new CliError(
1333
+ `${file} is not a bench result file: ${error instanceof Error ? error.message.split("\n")[0] : String(error)}. Produce one with \`gezel bench --json <file>\`.`
1334
+ );
1335
+ }
1336
+ if (shard.runs.length !== 1) {
1337
+ throw new CliError(`${file} holds ${shard.runs.length} runs; submit one run per issue.`);
1338
+ }
1339
+ const { title, body } = describeSubmission(shard);
1340
+ const params = new URLSearchParams({ title, labels: "bench-result" });
1341
+ const url = `https://github.com/${BENCH_SUBMIT_REPO}/issues/new?${params.toString()}`;
1342
+ const gh = deps.gh ?? (async (args) => (await execFileAsync("gh", args, { encoding: "utf8" })).stdout);
1343
+ try {
1344
+ const stdout = await gh([
1345
+ "issue",
1346
+ "create",
1347
+ "--repo",
1348
+ BENCH_SUBMIT_REPO,
1349
+ "--title",
1350
+ title,
1351
+ "--label",
1352
+ "bench-result",
1353
+ "--body",
1354
+ body
1355
+ ]);
1356
+ const issueUrl = stdout.trim().split("\n").pop() ?? "";
1357
+ io.out(`Opened ${issueUrl}`);
1358
+ return { title, body, url, issueUrl };
1359
+ } catch {
1360
+ io.out("Open this page and attach the file to the issue:");
1361
+ io.out(` ${url}`);
1362
+ io.out(` file: ${file}`);
1363
+ io.note("(Install the GitHub CLI, `gh`, and sign in to have this done for you.)");
1364
+ return { title, body, url };
1365
+ }
1366
+ }
1367
+ function registerBenchCommands(program2, connect, io = {
1368
+ out: (line) => console.log(line),
1369
+ note: (line) => console.error(line),
1370
+ confirm: process.stdin.isTTY ? confirmOnTerminal : void 0,
1371
+ cpuModel: defaultCpuModel
1372
+ }) {
1373
+ const bench = program2.command("bench").description(
1374
+ "Run the model scorecard on this machine: the same tasks, checks and counting rules as the published scorecard"
1375
+ ).option(
1376
+ "--suite <id>",
1377
+ "core (default), productivity, developer, complex-work, a comma list, or all"
1378
+ ).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(
1379
+ "--count <n>",
1380
+ "Trials per task; 3 is what it takes to quote a rate (default 1)",
1381
+ (v) => Number.parseInt(v, 10)
1382
+ ).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) => {
1383
+ const client = await connect();
1384
+ await runBench(client, opts, io);
1385
+ });
1386
+ bench.command("list").description("Show the suites, how many tasks each has, and how long it can take").action(async () => {
1387
+ const client = await connect();
1388
+ for (const line of renderSuiteList(await client.getEvalCatalog())) io.out(line);
1389
+ });
1390
+ 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) => {
1391
+ const client = await connect();
1392
+ const catalog = await client.getEvalCatalog();
1393
+ for (const line of await renderResults(client, catalog, opts.limit ?? 20)) io.out(line);
1394
+ });
1395
+ bench.command("submit <file>").description("Share a results shard from `gezel bench --json` as a GitHub issue").action(async (file) => {
1396
+ await submitBench(file, io);
1397
+ });
1398
+ }
1399
+ async function confirmOnTerminal(question) {
1400
+ const { createInterface } = await import("readline/promises");
1401
+ const rl = createInterface({ input: process.stdin, output: process.stderr });
1402
+ try {
1403
+ const answer = await rl.question(question);
1404
+ return /^y(es)?$/i.test(answer.trim());
1405
+ } finally {
1406
+ rl.close();
1407
+ }
1408
+ }
1409
+
1410
+ // src/cli-errors.ts
1411
+ function formatCliFailure(err, env2 = process.env) {
1412
+ if (!(err instanceof Error)) return null;
1413
+ if (err.name === "CliError") return err.message;
1414
+ if (err.name !== "GezelApiError" || env2.GEZEL_DEBUG === "1") return null;
1415
+ const { status, details } = err;
1416
+ const request = /\bon ([A-Z]+ \S+)/.exec(err.message)?.[1];
1417
+ const serviceText = detailText(details);
1418
+ if (status === 404) {
1419
+ const what = serviceText && serviceText.toLowerCase() !== "not found" ? serviceText : void 0;
1420
+ return `error: not found${what ? `: ${what}` : request ? ` (${request})` : ""}`;
1421
+ }
1422
+ const lines = [`error: ${serviceText ?? err.message}`];
1423
+ if (serviceText && request) lines.push(`(Gezel service answered ${status ?? "?"} to ${request})`);
1424
+ lines.push("Set GEZEL_DEBUG=1 to see the full error.");
1425
+ return lines.join("\n");
1426
+ }
1427
+ function isNotFound(err) {
1428
+ return err instanceof Error && err.name === "GezelApiError" && err.status === 404;
1429
+ }
1430
+ function detailText(details) {
1431
+ if (typeof details === "string" && details.trim()) return details.trim();
1432
+ if (details && typeof details === "object") {
1433
+ for (const key of ["message", "error"]) {
1434
+ const value = details[key];
1435
+ if (typeof value === "string" && value.trim()) return value.trim();
1436
+ }
1437
+ }
1438
+ return void 0;
1439
+ }
1440
+
772
1441
  // src/craftbook-command.ts
773
1442
  import { setTimeout as delay } from "timers/promises";
774
1443
  import {
@@ -1076,7 +1745,7 @@ async function waitForMlxRuntime(client, writeProgress, options = {}) {
1076
1745
  `\rpreparing the MLX Python runtime (one-time, a few minutes): ${Math.floor(elapsed / 60)}m ${String(elapsed % 60).padStart(2, "0")}s`
1077
1746
  );
1078
1747
  shown = true;
1079
- await new Promise((resolve6) => setTimeout(resolve6, pollMs));
1748
+ await new Promise((resolve7) => setTimeout(resolve7, pollMs));
1080
1749
  continue;
1081
1750
  }
1082
1751
  if (status.phase === "error") {
@@ -1345,7 +2014,8 @@ function errorMessage(error) {
1345
2014
  import {
1346
2015
  classifySecurityLevel,
1347
2016
  resolveSecurityPolicy,
1348
- securityCapabilitiesOf
2017
+ securityCapabilitiesOf,
2018
+ securityPolicyForLevel
1349
2019
  } from "@bendyline/gezel";
1350
2020
  var SECURITY_LEVEL_LABELS = {
1351
2021
  "super-lockdown": "Super Lockdown",
@@ -1380,6 +2050,42 @@ var SECURITY_SWITCHES = [
1380
2050
  description: "Show or set on/off for gezels adding or changing the scripts in package.json"
1381
2051
  }
1382
2052
  ];
2053
+ var CAPABILITY_LABELS = [
2054
+ ["allowExternalChat", "Cloud models"],
2055
+ ["allowFileEdits", "File edits and the model\u2019s Git tools"],
2056
+ ["allowScriptExecution", "Sandboxed scripts"],
2057
+ ["allowAppNetwork", "Update checks and the connector syncs you start"],
2058
+ ["allowExternalServices", "Web search, mail and other outside services"],
2059
+ ["allowPackageScriptExecution", "Run package scripts"],
2060
+ ["allowPackageScriptEdits", "Edit package scripts"]
2061
+ ];
2062
+ var LEVEL_ALIASES = {
2063
+ "super-lockdown": "super-lockdown",
2064
+ superlockdown: "super-lockdown",
2065
+ lockdown: "lockdown",
2066
+ free: "free",
2067
+ unrestricted: "free"
2068
+ };
2069
+ function parseSecurityLevel(input) {
2070
+ const level = LEVEL_ALIASES[input.trim().toLowerCase()];
2071
+ if (!level) {
2072
+ throw new CliError(
2073
+ `Unknown security level "${input}". Choose super-lockdown, lockdown, or free (shown as Unrestricted in Settings).`
2074
+ );
2075
+ }
2076
+ return level;
2077
+ }
2078
+ function describeSecurityLevel(policy) {
2079
+ const caps = securityCapabilitiesOf(resolveSecurityPolicy({ securityPolicy: policy }));
2080
+ const level = classifySecurityLevel(caps);
2081
+ const width = Math.max(...CAPABILITY_LABELS.map(([, label]) => label.length));
2082
+ return [
2083
+ `Security level: ${SECURITY_LEVEL_LABELS[level]}${level === "custom" ? "" : ` (${level})`}`,
2084
+ ...CAPABILITY_LABELS.map(
2085
+ ([key, label]) => ` ${label.padEnd(width)} ${caps[key] ? "on" : "off"}`
2086
+ )
2087
+ ];
2088
+ }
1383
2089
  function enabledValue(state) {
1384
2090
  if (state === void 0) return void 0;
1385
2091
  if (state === "on") return true;
@@ -1388,6 +2094,34 @@ function enabledValue(state) {
1388
2094
  }
1389
2095
  function registerSecurityCommands(program2, connect) {
1390
2096
  const security = program2.command("security").description("Inspect or explicitly change security settings");
2097
+ security.command("level [action] [level]").description(
2098
+ "Show the security level, or set a preset: `level set super-lockdown|lockdown|free`"
2099
+ ).option("--json", "Output the level and its capabilities as JSON").action(
2100
+ async (action, requested, options) => {
2101
+ if (action !== void 0 && action !== "show" && action !== "set") {
2102
+ throw new CliError("Use `gezel security level`, `level show`, or `level set <level>`.");
2103
+ }
2104
+ if (action === "set" && requested === void 0) {
2105
+ throw new CliError("Name a level: super-lockdown, lockdown, or free.");
2106
+ }
2107
+ if (action !== "set" && requested !== void 0) {
2108
+ throw new CliError("To change the level, use `gezel security level set <level>`.");
2109
+ }
2110
+ const next = action === "set" ? parseSecurityLevel(requested) : void 0;
2111
+ const client = await connect();
2112
+ const policy = next ? securityPolicyForLevel(next) : {
2113
+ level: "custom",
2114
+ ...securityCapabilitiesOf(resolveSecurityPolicy(await client.getConfig()))
2115
+ };
2116
+ if (next) await client.updateConfig({ securityPolicy: policy });
2117
+ if (options.json) {
2118
+ const caps = securityCapabilitiesOf(resolveSecurityPolicy({ securityPolicy: policy }));
2119
+ console.log(JSON.stringify({ level: classifySecurityLevel(caps), ...caps }));
2120
+ return;
2121
+ }
2122
+ for (const line of describeSecurityLevel(policy)) console.log(line);
2123
+ }
2124
+ );
1391
2125
  for (const setting of SECURITY_SWITCHES) {
1392
2126
  security.command(`${setting.command} [state]`).description(setting.description).option("--json", "Output the setting as JSON").action(async (state, options) => {
1393
2127
  const enabled = enabledValue(state);
@@ -1583,7 +2317,7 @@ function terminalPrompter(terminal = { input: process.stdin, output: process.std
1583
2317
  function ask(terminal, question, secret) {
1584
2318
  const { input, output } = terminal;
1585
2319
  return import("readline").then(
1586
- ({ clearScreenDown, createInterface, cursorTo, moveCursor }) => new Promise((resolve6, reject) => {
2320
+ ({ clearScreenDown, createInterface, cursorTo, moveCursor }) => new Promise((resolve7, reject) => {
1587
2321
  const rl = createInterface({
1588
2322
  input,
1589
2323
  output: secret ? new Writable({ write: (_chunk, _encoding, done) => done() }) : output,
@@ -1630,13 +2364,13 @@ function ask(terminal, question, secret) {
1630
2364
  if (settled) return;
1631
2365
  settle();
1632
2366
  output.write("\n");
1633
- resolve6("");
2367
+ resolve7("");
1634
2368
  });
1635
2369
  rl.question(question, (answer) => {
1636
2370
  settle();
1637
2371
  rl.close();
1638
2372
  if (secret) output.write("\n");
1639
- resolve6(answer);
2373
+ resolve7(answer);
1640
2374
  });
1641
2375
  draw();
1642
2376
  })
@@ -1756,8 +2490,8 @@ async function ensureEngines(client, engines, write) {
1756
2490
 
1757
2491
  // src/craftbook-shorthand.ts
1758
2492
  import { existsSync } from "fs";
1759
- import { readFile as readFile2, readdir } from "fs/promises";
1760
- import { join as join2 } from "path";
2493
+ import { readFile as readFile3, readdir } from "fs/promises";
2494
+ import { join as join3 } from "path";
1761
2495
  import { projectLocalCraftbooksRoot } from "@bendyline/gezel/paths";
1762
2496
  var SHORTHAND_FLAG = "--via-craftbook-shorthand";
1763
2497
  var VALUE_OPTIONS = /* @__PURE__ */ new Set(["--connect", "--token", "--home"]);
@@ -1794,7 +2528,7 @@ async function workspaceCraftbookId(workspaceDir, word) {
1794
2528
  const ids = [];
1795
2529
  for (const entry of await readdir(root, { withFileTypes: true })) {
1796
2530
  if (!entry.isDirectory()) continue;
1797
- const manifest = await readFile2(join2(root, entry.name, "manifest.json"), "utf8").then((text) => JSON.parse(text)).catch(() => null);
2531
+ const manifest = await readFile3(join3(root, entry.name, "manifest.json"), "utf8").then((text) => JSON.parse(text)).catch(() => null);
1798
2532
  if (!manifest) continue;
1799
2533
  const id = typeof manifest.id === "string" ? manifest.id : entry.name;
1800
2534
  if (typeof manifest.command === "string" && manifest.command.toLowerCase() === query) return id;
@@ -1829,6 +2563,112 @@ function isGezeldCommand(command) {
1829
2563
  return /(?:^|[\\/\s"'])gezeld(?:\.[cm]?js|\.exe)?(?=["'\s]|$)/i.test(command);
1830
2564
  }
1831
2565
 
2566
+ // src/doctor-report.ts
2567
+ import {
2568
+ describeProvenance,
2569
+ measuredClaim,
2570
+ measuredResultFor,
2571
+ measuredRowsFor,
2572
+ scorecardHardwareKey,
2573
+ scorecardHardwareLabel
2574
+ } from "@bendyline/gezel";
2575
+ var CHECK_LABELS = {
2576
+ spawn: "starts",
2577
+ toolRoundTrip: "answers a tool call",
2578
+ throughput: "decodes fast enough",
2579
+ reasoningBudget: "bounded reasoning",
2580
+ contextFit: "room for a prompt"
2581
+ };
2582
+ function renderFitness(entry, probing) {
2583
+ if (probing) return ["fitness check: running now"];
2584
+ if (!entry) {
2585
+ return [
2586
+ "fitness check: not run yet \u2014 Gezel runs it when a model is installed, or from Settings \u2192 Models"
2587
+ ];
2588
+ }
2589
+ const { record } = entry;
2590
+ const head = record.status === "probed" ? record.admitted ? "fitness check: passed" : "fitness check: FAILED" : `fitness check: ${record.status}`;
2591
+ const qualifiers = [
2592
+ entry.stale ? "the model changed since; treat as not run" : "",
2593
+ entry.hardwareChanged ? "this machine's memory changed since" : "",
2594
+ record.genTokensPerSec ? `${record.genTokensPerSec.toFixed(1)} tok/s` : "",
2595
+ record.createdAt ? record.createdAt.slice(0, 10) : ""
2596
+ ].filter(Boolean);
2597
+ const lines = [`${head}${qualifiers.length ? ` (${qualifiers.join(", ")})` : ""}`];
2598
+ for (const key of Object.keys(CHECK_LABELS)) {
2599
+ const check = record.checks[key];
2600
+ if (!check) continue;
2601
+ lines.push(` ${check.ok ? "ok " : "NO "} ${CHECK_LABELS[key].padEnd(20)} ${check.detail}`);
2602
+ }
2603
+ return lines;
2604
+ }
2605
+ function hardwareClassCoverage(dataset, modelId, device) {
2606
+ const key = scorecardHardwareKey(device);
2607
+ const name = scorecardHardwareLabel(device);
2608
+ const rounds = dataset.runs.filter(
2609
+ (run) => run.scope !== "subset" && scorecardHardwareKey(run.provenance.device) === key
2610
+ ).length;
2611
+ const mine = measuredRowsFor(dataset, modelId).filter(
2612
+ (row) => scorecardHardwareKey(row.run.provenance.device) === key
2613
+ ).length;
2614
+ if (rounds === 0) {
2615
+ return ` on ${name}: no published scorecard round has run on ${name} yet \u2014 \`gezel bench\` would be the first`;
2616
+ }
2617
+ const roundWord = rounds === 1 ? "round" : "rounds";
2618
+ if (mine === 0) {
2619
+ return ` on ${name}: ${rounds} published ${roundWord}, none with this model \u2014 \`gezel bench\` measures it here`;
2620
+ }
2621
+ return ` on ${name}: ${rounds} published ${roundWord}; ${mine} ${mine === 1 ? "result" : "results"} for this model`;
2622
+ }
2623
+ function renderMeasured(dataset, modelId, device, rows = 4) {
2624
+ const headline = measuredResultFor(dataset, modelId, device);
2625
+ const coverage = hardwareClassCoverage(dataset, modelId, device);
2626
+ if (!headline) {
2627
+ return [
2628
+ "measured: not measured in a published round \u2014 `gezel bench` measures it on this machine",
2629
+ coverage
2630
+ ];
2631
+ }
2632
+ const lines = [
2633
+ `measured: ${measuredClaim(headline)}${headline.sameHardwareClass ? "" : " \u2014 a different platform; your numbers may differ"}`,
2634
+ coverage
2635
+ ];
2636
+ for (const row of measuredRowsFor(dataset, modelId).slice(0, rows)) {
2637
+ lines.push(
2638
+ ` ${row.result.suiteId.padEnd(14)} ${row.score.claim.padEnd(36)} ${describeProvenance(row.run, [row.result.engine])}`
2639
+ );
2640
+ }
2641
+ lines.push(" Full tables: https://gezel.com/docs/model-scorecard/");
2642
+ return lines;
2643
+ }
2644
+ function renderDoctorModel(input) {
2645
+ if (!input.modelId) {
2646
+ return [
2647
+ `model: none for ${input.provider}`,
2648
+ " `gezel model list --available` shows what fits this machine; `gezel model pull <id>` downloads one."
2649
+ ];
2650
+ }
2651
+ const lines = [`model: ${input.modelId} (${input.provider})`];
2652
+ for (const line of renderFitness(input.fitness, input.probing)) lines.push(` ${line}`);
2653
+ for (const line of renderMeasured(input.dataset, input.modelId, input.device, input.rows)) {
2654
+ lines.push(` ${line}`);
2655
+ }
2656
+ return lines;
2657
+ }
2658
+ function doctorVerdict(input) {
2659
+ if (!input.nodeOk) return "Verdict: install Node.js 24 or newer, then run `gezel doctor` again.";
2660
+ if (!input.serviceReachable) {
2661
+ return 'Verdict: Gezel is installed but no service is running. `gezel start` starts one; `gezel run "hello"` starts one and sends a message.';
2662
+ }
2663
+ if (!input.modelId) {
2664
+ 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.";
2665
+ }
2666
+ if (input.fitnessAdmitted === false) {
2667
+ 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.`;
2668
+ }
2669
+ 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.`;
2670
+ }
2671
+
1832
2672
  // src/engagement-mode.ts
1833
2673
  var CLI_ENGAGEMENT_MODES = [
1834
2674
  {
@@ -1881,7 +2721,7 @@ var CLI_ENGAGEMENT_MODE_USAGE = CLI_ENGAGEMENT_MODES.map((option) => option.name
1881
2721
  );
1882
2722
 
1883
2723
  // src/generate.ts
1884
- import { mkdir as mkdir2, readFile as readFile3, writeFile as writeFile2 } from "fs/promises";
2724
+ import { mkdir as mkdir2, readFile as readFile4, writeFile as writeFile3 } from "fs/promises";
1885
2725
  import { basename as basename2, dirname as dirname2, resolve as resolve2 } from "path";
1886
2726
  async function resolvePromptText(parts, file, label) {
1887
2727
  const inline = (parts ?? []).join(" ").trim();
@@ -1889,7 +2729,7 @@ async function resolvePromptText(parts, file, label) {
1889
2729
  if (inline) throw new CliError(`provide either ${label} text or --file, not both.`);
1890
2730
  let raw;
1891
2731
  try {
1892
- raw = await readFile3(resolve2(file), "utf8");
2732
+ raw = await readFile4(resolve2(file), "utf8");
1893
2733
  } catch (err) {
1894
2734
  throw new CliError(`could not read --file "${file}": ${err.message}`);
1895
2735
  }
@@ -1925,7 +2765,7 @@ async function saveArtifact(client, projectId, artifactPath, output) {
1925
2765
  const bytes = Buffer.from(await blob.arrayBuffer());
1926
2766
  const dest = output ? resolve2(output) : resolve2(process.cwd(), basename2(artifactPath));
1927
2767
  await mkdir2(dirname2(dest), { recursive: true });
1928
- await writeFile2(dest, bytes);
2768
+ await writeFile3(dest, bytes);
1929
2769
  return dest;
1930
2770
  }
1931
2771
 
@@ -1981,7 +2821,7 @@ import {
1981
2821
  harnessAgentFileLine,
1982
2822
  harnessPromptInvocation
1983
2823
  } from "@bendyline/gezel";
1984
- import { GezelApiError as GezelApiError2, apiErrorMessage } from "@bendyline/gezel-client";
2824
+ import { GezelApiError as GezelApiError3, apiErrorMessage as apiErrorMessage2 } from "@bendyline/gezel-client";
1985
2825
  var STATE_WORDS = {
1986
2826
  configured: "set up",
1987
2827
  "not-configured": "not set up",
@@ -2009,7 +2849,7 @@ async function call(fn) {
2009
2849
  try {
2010
2850
  return await fn();
2011
2851
  } catch (error) {
2012
- if (error instanceof GezelApiError2) throw new CliError(apiErrorMessage(error));
2852
+ if (error instanceof GezelApiError3) throw new CliError(apiErrorMessage2(error));
2013
2853
  throw error;
2014
2854
  }
2015
2855
  }
@@ -2079,6 +2919,10 @@ function registerMcpCommands(program2, connect, output = console.log) {
2079
2919
  }
2080
2920
 
2081
2921
  // src/model-choice.ts
2922
+ import {
2923
+ measuredClaim as measuredClaim2,
2924
+ measuredResultFor as measuredResultFor2
2925
+ } from "@bendyline/gezel";
2082
2926
  async function installedChatModels(client, engine) {
2083
2927
  const { models } = engine === "mlx" ? await client.listMlxModels() : engine === "ds4" ? await client.listDs4Models() : await client.listLlamaCppModels();
2084
2928
  return models.map((model2) => model2.id);
@@ -2110,9 +2954,10 @@ async function availableChatModels(client, engine) {
2110
2954
  };
2111
2955
  }
2112
2956
  function formatAvailableChatModels(input) {
2113
- const { engine, ranked, installed, pinned } = input;
2957
+ const { engine, ranked, installed, pinned, measured } = input;
2114
2958
  if (ranked.length === 0) return `(no ${engine} chat models in the catalog for this machine)`;
2115
2959
  const width = Math.max(...ranked.map((model2) => model2.id.length));
2960
+ const measuredWidth = measured ? Math.max("not measured".length, ...ranked.map((m) => (measured.get(m.id) ?? "").length)) : 0;
2116
2961
  const lines = [`${engine} chat models for this machine, best first:`];
2117
2962
  ranked.forEach((model2, index) => {
2118
2963
  const notes = [
@@ -2120,8 +2965,9 @@ function formatAvailableChatModels(input) {
2120
2965
  installed.has(model2.id) ? "installed" : "",
2121
2966
  model2.id === pinned ? "in use" : ""
2122
2967
  ].filter(Boolean);
2968
+ const claim = measured ? ` ${(measured.get(model2.id) ?? "not measured").padEnd(measuredWidth)}` : "";
2123
2969
  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(", ")})` : ""}`
2970
+ ` ${model2.id.padEnd(width)} ${formatDownloadSize(model2.approxSizeBytes).padStart(7)} ${FIT_LABEL[model2.fit].padEnd(22)}${claim} ${model2.name}${notes.length > 0 ? ` (${notes.join(", ")})` : ""}`
2125
2971
  );
2126
2972
  });
2127
2973
  const flag = providerFlag(engine, input.platformDefault);
@@ -2131,8 +2977,18 @@ function formatAvailableChatModels(input) {
2131
2977
  `Download one with \`gezel model pull <id>${flag}\`. The smallest is ${smallest.id} (${formatDownloadSize(smallest.approxSizeBytes)}).`,
2132
2978
  `\`gezel model use <id>${flag}\` picks the installed model chats use.`
2133
2979
  );
2980
+ if (measured) {
2981
+ lines.push(
2982
+ '"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.'
2983
+ );
2984
+ }
2134
2985
  return lines.join("\n");
2135
2986
  }
2987
+ function measuredClaimsFor(dataset, ids, device) {
2988
+ const claims = /* @__PURE__ */ new Map();
2989
+ for (const id of ids) claims.set(id, measuredClaim2(measuredResultFor2(dataset, id, device)));
2990
+ return claims;
2991
+ }
2136
2992
  async function useChatModel(client, id, options) {
2137
2993
  const order = options.requested ? [options.requested] : [options.platformDefault, ...["mlx", "llama-cpp", "ds4"]].filter(
2138
2994
  (engine2, index, all) => all.indexOf(engine2) === index
@@ -2469,7 +3325,7 @@ async function settledFirstRunConfig(client, options = {}) {
2469
3325
  let config = await client.getConfig();
2470
3326
  for (let attempt = 0; attempt < attempts; attempt += 1) {
2471
3327
  if (config.firstRunCompleted || config.provider !== "copilot") return config;
2472
- await new Promise((resolve6) => setTimeout(resolve6, delayMs));
3328
+ await new Promise((resolve7) => setTimeout(resolve7, delayMs));
2473
3329
  config = await client.getConfig();
2474
3330
  }
2475
3331
  return config;
@@ -2674,7 +3530,7 @@ var RunOutput = class {
2674
3530
  };
2675
3531
 
2676
3532
  // src/secrets-command.ts
2677
- import { GezelApiError as GezelApiError3 } from "@bendyline/gezel-client";
3533
+ import { GezelApiError as GezelApiError4 } from "@bendyline/gezel-client";
2678
3534
  var credentialFlags = {
2679
3535
  githubToken: "hasGithubToken",
2680
3536
  openaiApiKey: "hasOpenaiApiKey",
@@ -2728,7 +3584,7 @@ async function writeCredential(client, patch) {
2728
3584
  try {
2729
3585
  await client.updateConfig(patch);
2730
3586
  } catch (error) {
2731
- const status = error instanceof GezelApiError3 ? ` (HTTP ${error.status})` : "";
3587
+ const status = error instanceof GezelApiError4 ? ` (HTTP ${error.status})` : "";
2732
3588
  throw new CliError(
2733
3589
  `Could not update the credential${status}. Check the service connection and permissions.`
2734
3590
  );
@@ -2960,6 +3816,33 @@ function resolveRestoreSelection(review, opts) {
2960
3816
  return { items, skipped };
2961
3817
  }
2962
3818
 
3819
+ // src/task-output.ts
3820
+ import { mkdir as mkdir3, writeFile as writeFile4 } from "fs/promises";
3821
+ import { dirname as dirname4, isAbsolute as isAbsolute2, join as join4, relative, resolve as resolve5, sep } from "path";
3822
+ async function copyTaskOutput(client, projectId, artifactDir, outDir) {
3823
+ const root = resolve5(outDir);
3824
+ const listing = await client.listProjectArtifacts(projectId, artifactDir, true);
3825
+ const copied = [];
3826
+ for (const file of listing.files) {
3827
+ if (file.isDirectory) continue;
3828
+ const rel = relative(artifactDir, file.path).split(sep).join("/");
3829
+ if (!rel || rel.startsWith("..") || isAbsolute2(rel)) continue;
3830
+ if (rel === "inputs" || rel.startsWith("inputs/")) continue;
3831
+ const target = join4(root, rel);
3832
+ if (relative(root, target).startsWith("..")) continue;
3833
+ const blob = await client.fetchProjectArtifactBlob(projectId, file.path);
3834
+ await mkdir3(dirname4(target), { recursive: true });
3835
+ await writeFile4(target, Buffer.from(await blob.arrayBuffer()));
3836
+ copied.push(rel);
3837
+ }
3838
+ if (listing.truncated) {
3839
+ throw new CliError(
3840
+ `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.`
3841
+ );
3842
+ }
3843
+ return copied;
3844
+ }
3845
+
2963
3846
  // src/unknown-command.ts
2964
3847
  function unknownCommandMessage(operands, known) {
2965
3848
  const word = operands[0] ?? "";
@@ -3007,7 +3890,7 @@ function editDistance(a, b) {
3007
3890
 
3008
3891
  // src/workflow-command.ts
3009
3892
  import { realpath as realpath2 } from "fs/promises";
3010
- import { isAbsolute as isAbsolute2, relative, resolve as resolve5 } from "path";
3893
+ import { isAbsolute as isAbsolute3, relative as relative2, resolve as resolve6 } from "path";
3011
3894
  import { pathToFileURL } from "url";
3012
3895
  import {
3013
3896
  craftbookFromDoc,
@@ -3024,10 +3907,10 @@ function validateWorkflowCraftbook(document) {
3024
3907
  }
3025
3908
  async function runWorkflow(client, projectId, workspace, file, args, log = console.error, invocation) {
3026
3909
  const named = /^[a-z][a-z0-9-]*$/.test(file);
3027
- const path = await realpath2(resolve5(workspace, named ? `.gezel/workflows/${file}.mjs` : file));
3910
+ const path = await realpath2(resolve6(workspace, named ? `.gezel/workflows/${file}.mjs` : file));
3028
3911
  if (invocation) {
3029
- const local = relative(await realpath2(workspace), path);
3030
- if (isAbsolute2(local) || local === ".." || local.startsWith("../") || local.startsWith("..\\")) {
3912
+ const local = relative2(await realpath2(workspace), path);
3913
+ if (isAbsolute3(local) || local === ".." || local.startsWith("../") || local.startsWith("..\\")) {
3031
3914
  throw new CliError("A craftbook workflow module must remain inside its project workspace.");
3032
3915
  }
3033
3916
  }
@@ -3046,7 +3929,7 @@ async function runWorkflow(client, projectId, workspace, file, args, log = conso
3046
3929
  return module.run({
3047
3930
  client,
3048
3931
  projectId,
3049
- workspace: resolve5(workspace),
3932
+ workspace: resolve6(workspace),
3050
3933
  args,
3051
3934
  ...invocation ?? {},
3052
3935
  log,
@@ -3108,6 +3991,16 @@ async function runWorkflow(client, projectId, workspace, file, args, log = conso
3108
3991
  });
3109
3992
  }
3110
3993
 
3994
+ // src/bin/node-version.ts
3995
+ var MINIMUM_NODE_MAJOR = 24;
3996
+ function unsupportedNodeMessage(version) {
3997
+ const major = Number.parseInt(version, 10);
3998
+ if (!Number.isFinite(major) || major >= MINIMUM_NODE_MAJOR) return void 0;
3999
+ return `Gezel needs Node.js ${MINIMUM_NODE_MAJOR} or newer (found v${version}).
4000
+ Install Node.js ${MINIMUM_NODE_MAJOR} or later from https://nodejs.org, then run the command again.
4001
+ `;
4002
+ }
4003
+
3111
4004
  // src/bin/gezel.ts
3112
4005
  var program = new Command();
3113
4006
  program.name("gezel").description("Gezel \u2014 assemble a team of AI companions (gezels) and put them to work.").addHelpText(
@@ -3124,8 +4017,12 @@ program.name("gezel").description("Gezel \u2014 assemble a team of AI companions
3124
4017
  "Use this folder as the active project (default and bare flag: cwd)."
3125
4018
  );
3126
4019
  var cliGlobals = () => program.opts();
4020
+ var connectForInspection = (opts) => opts.start === false ? connectRunning(cliGlobals()) : connectOwned(cliGlobals());
3127
4021
  registerSecretCommands(program, () => connectOwned(cliGlobals()));
4022
+ registerAccountCommands(program, async () => (await connectOwned(cliGlobals())).accounts);
4023
+ registerIntegrationCommands(program, () => connectOwned(cliGlobals()));
3128
4024
  registerMcpCommands(program, () => connectOwned(cliGlobals()));
4025
+ registerBenchCommands(program, () => connectOwned(cliGlobals()));
3129
4026
  registerSecurityCommands(program, () => connectOwned(cliGlobals()));
3130
4027
  registerGrowthCommand(program, () => connectOwned(cliGlobals()));
3131
4028
  program.hook("preAction", () => {
@@ -3203,6 +4100,9 @@ program.command("start").description("Start the Gezel daemon (no-op if already r
3203
4100
  "--web",
3204
4101
  "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
4102
  ).option("--open", "With --web, open the printed URL in your default browser.").option(
4103
+ "--accounts",
4104
+ "With --web, sign in with an account instead of a one-time URL; the first run prints a link to create one."
4105
+ ).option(
3206
4106
  "--restart",
3207
4107
  "With --web or --port, stop a running daemon started without them and start a new one."
3208
4108
  ).action(
@@ -3226,6 +4126,7 @@ program.command("start").description("Start the Gezel daemon (no-op if already r
3226
4126
  if (opts.web) {
3227
4127
  spawnEnv.GEZEL_WEB = "1";
3228
4128
  spawnEnv.GEZEL_INSECURE_TRANSPORT = "1";
4129
+ if (opts.accounts) spawnEnv.GEZEL_WEB_ACCOUNTS = "1";
3229
4130
  }
3230
4131
  if (opts.foreground) {
3231
4132
  await startForeground(spawnEnv);
@@ -3270,7 +4171,11 @@ Restart it ${wanted} with \`${[...retry, "--restart"].join(" ")}\`, or stop it f
3270
4171
  console.log(
3271
4172
  `gezeld running (version ${health2.version}) on port ${new URL(result.baseUrl).port}`
3272
4173
  );
3273
- if (opts.web) await printWebUrl(result.baseUrl, opts.open === true);
4174
+ if (opts.web && opts.accounts) {
4175
+ await printAccountsWebUrl(result.client.accounts, result.baseUrl, opts.open === true);
4176
+ } else if (opts.web) {
4177
+ await printWebUrl(result.baseUrl, opts.open === true);
4178
+ }
3274
4179
  return;
3275
4180
  }
3276
4181
  const client = await connectOwned(cliGlobals(), { announceSpawn: false });
@@ -3282,15 +4187,30 @@ async function runtimeServes(runtime, want) {
3282
4187
  if (want.port !== void 0 && runtime.port !== want.port) return false;
3283
4188
  if (!want.web) return true;
3284
4189
  if (new URL(runtime.baseUrl).protocol !== "http:") return false;
3285
- const { readFile: readFile4 } = await import("fs/promises");
4190
+ const { readFile: readFile5 } = await import("fs/promises");
3286
4191
  const { gezelPaths: gezelPaths2 } = await import("@bendyline/gezel/paths");
3287
- const token = await readFile4(gezelPaths2().runtime.webUiToken, "utf8").catch(() => "");
4192
+ const token = await readFile5(gezelPaths2().runtime.webUiToken, "utf8").catch(() => "");
3288
4193
  return token.trim().length > 0;
3289
4194
  }
4195
+ async function printAccountsWebUrl(client, baseUrl, open) {
4196
+ const origin = new URL(baseUrl).origin;
4197
+ const state = await client.getSignInState();
4198
+ let url = `${origin}/`;
4199
+ if (state.setupRequired) {
4200
+ const link = await client.createSetupLink();
4201
+ if (link.code) url = `${origin}/?setup=${encodeURIComponent(link.code)}`;
4202
+ }
4203
+ console.log("");
4204
+ console.log(
4205
+ state.setupRequired ? ` Create your account \u2192 ${url}` : ` Gezel web UI \u2192 ${url} (sign in with your account)`
4206
+ );
4207
+ console.log("");
4208
+ if (open) await openInBrowser(url);
4209
+ }
3290
4210
  async function printWebUrl(baseUrl, open) {
3291
- const { readFile: readFile4 } = await import("fs/promises");
4211
+ const { readFile: readFile5 } = await import("fs/promises");
3292
4212
  const { gezelPaths: gezelPaths2 } = await import("@bendyline/gezel/paths");
3293
- const token = (await readFile4(gezelPaths2().runtime.webUiToken, "utf8").catch(() => "")).trim();
4213
+ const token = (await readFile5(gezelPaths2().runtime.webUiToken, "utf8").catch(() => "")).trim();
3294
4214
  if (!token) {
3295
4215
  throw new CliError(
3296
4216
  "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 +4256,10 @@ async function startForeground(env2) {
3336
4256
  process.on("SIGINT", requestStop);
3337
4257
  process.on("SIGTERM", requestStop);
3338
4258
  try {
3339
- await new Promise((resolve6) => {
4259
+ await new Promise((resolve7) => {
3340
4260
  child.on("exit", (code) => {
3341
4261
  process.exitCode = code ?? 0;
3342
- resolve6();
4262
+ resolve7();
3343
4263
  });
3344
4264
  });
3345
4265
  } finally {
@@ -3468,11 +4388,11 @@ program.command("stop").description(
3468
4388
  }
3469
4389
  });
3470
4390
  async function clearStaleRuntime(stoppedPid, opts = {}) {
3471
- const { readFile: readFile4, rm: rm3 } = await import("fs/promises");
4391
+ const { readFile: readFile5, rm: rm3 } = await import("fs/promises");
3472
4392
  const { gezelPaths: gezelPaths2 } = await import("@bendyline/gezel/paths");
3473
4393
  const runtime = gezelPaths2().runtime;
3474
4394
  const recorded = Number.parseInt(
3475
- (await readFile4(runtime.pid, "utf8").catch(() => "")).trim(),
4395
+ (await readFile5(runtime.pid, "utf8").catch(() => "")).trim(),
3476
4396
  10
3477
4397
  );
3478
4398
  if (recorded !== stoppedPid || !opts.pidReused && isProcessAlive2(stoppedPid)) return;
@@ -3685,7 +4605,7 @@ Examples:
3685
4605
  "named craftbook parameter (repeatable)",
3686
4606
  (value, values) => [...values, value],
3687
4607
  []
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(
4608
+ ).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
4609
  "--strict-sandbox",
3690
4610
  "require OS network isolation for custom scripts (CLI launches otherwise trust this recipe snapshot)"
3691
4611
  ).addOption(new Option(SHORTHAND_FLAG).hideHelp()).action(
@@ -3765,9 +4685,17 @@ Examples:
3765
4685
  trustScripts: !opts.strictSandbox,
3766
4686
  roleBasedNameOnlyMode: true
3767
4687
  });
3768
- if (opts.wait) {
4688
+ if (opts.wait || opts.out) {
3769
4689
  console.error(`started ${created.ref} \u2014 ${created.title}`);
3770
- await printTaskWait(client, created.ref, { ...opts, timeoutMs });
4690
+ const waited = await printTaskWait(client, created.ref, { ...opts, timeoutMs });
4691
+ if (opts.out && waited.outcome === "complete") {
4692
+ const dir = waited.task.artifactDir;
4693
+ if (!dir) throw new CliError(`${created.ref} finished without a task folder to copy.`);
4694
+ const copied = await copyTaskOutput(client, projectId, dir, opts.out);
4695
+ console.error(
4696
+ `copied ${copied.length} file${copied.length === 1 ? "" : "s"} to ${opts.out}`
4697
+ );
4698
+ }
3771
4699
  } else
3772
4700
  console.log(
3773
4701
  opts.json ? JSON.stringify(created) : `started ${created.ref} \u2014 ${created.title}`
@@ -3813,12 +4741,13 @@ async function printTaskWait(client, ref, opts) {
3813
4741
  console.error(`See its notes with \`gezel task notes ${result.task.ref}\`.`);
3814
4742
  }
3815
4743
  process.exitCode = result.exitCode;
4744
+ return result;
3816
4745
  }
3817
4746
  var craftbook = program.command("craftbook").description("Browse the craftbooks `gezel do` can start");
3818
4747
  craftbook.command("list [words...]").description(
3819
4748
  "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 connectOwned(cliGlobals());
4749
+ ).option("--json", "emit the list as JSON").option("--no-start", "Use a running service only; never start one").action(async (words, opts) => {
4750
+ const client = await connectForInspection(opts);
3822
4751
  const preview = await previewRunProject(client, cliGlobals());
3823
4752
  const projectId = preview.projectId ?? "default";
3824
4753
  const [config, result] = await Promise.all([
@@ -4018,6 +4947,9 @@ handboek.command("export").description("Render the Handboek as a static HTML sit
4018
4947
  ).option("--og-out <dir>", "directory to render Open Graph cards into; must be outside --out").option(
4019
4948
  "--og-base <url>",
4020
4949
  "absolute URL the card directory is served from (e.g. https://gezel.com/og/); required with --og-out"
4950
+ ).option(
4951
+ "--apps-out <dir>",
4952
+ "also write the apps library (gezel.com/apps) into this directory, outside --out"
4021
4953
  ).action(
4022
4954
  async (opts) => {
4023
4955
  if (Boolean(opts.ogOut) !== Boolean(opts.ogBase)) {
@@ -4033,10 +4965,15 @@ handboek.command("export").description("Render the Handboek as a static HTML sit
4033
4965
  siteUrl: opts.siteUrl,
4034
4966
  canonicalBase: opts.canonicalBase,
4035
4967
  ogOut: opts.ogOut,
4036
- ogBase: opts.ogBase
4968
+ ogBase: opts.ogBase,
4969
+ appsOut: opts.appsOut
4037
4970
  });
4038
4971
  console.log(`Handboek exported: ${result.pages} pages \u2192 ${result.out}`);
4972
+ if (result.apps) {
4973
+ console.log(`Apps library: ${result.apps.apps} apps, ${result.apps.demos} with demos`);
4974
+ }
4039
4975
  for (const id of result.skipped) console.error(` skipped (no body): ${id}`);
4976
+ for (const note of result.warnings) console.error(` data table: ${note}`);
4040
4977
  const cards = result.cards;
4041
4978
  if (cards?.skipped) {
4042
4979
  console.error(` no Open Graph cards: ${cards.skipped}`);
@@ -4636,16 +5573,27 @@ model.command("context <id> [tokens]").description("Show or set a model context
4636
5573
  );
4637
5574
  }
4638
5575
  );
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 connectOwned(cliGlobals());
5576
+ 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) => {
5577
+ const client = await connectForInspection(opts);
4641
5578
  const provider = resolveModelProvider(opts.provider);
4642
5579
  if (opts.available) {
4643
5580
  const available = await availableChatModels(client, provider);
5581
+ const health = await client.health().catch(() => null);
5582
+ const device = {
5583
+ platform: health?.platform ?? process.platform,
5584
+ arch: process.arch,
5585
+ label: health?.platform ?? process.platform
5586
+ };
4644
5587
  console.log(
4645
5588
  formatAvailableChatModels({
4646
5589
  engine: provider,
4647
5590
  platformDefault: resolveOnDeviceProvider3(process.platform, process.arch),
4648
- ...available
5591
+ ...available,
5592
+ measured: measuredClaimsFor(
5593
+ SCORECARD,
5594
+ available.ranked.map((m) => m.id),
5595
+ device
5596
+ )
4649
5597
  })
4650
5598
  );
4651
5599
  return;
@@ -4712,6 +5660,10 @@ program.command("doctor").description("Check the Gezel installation").action(asy
4712
5660
  console.log(
4713
5661
  `machine engine: healthy (${broker.baseUrl}) version=${broker.version} \u2014 compute broker; the product API is the per-user daemon`
4714
5662
  );
5663
+ } else if (broker?.present && broker.healthy === false && broker.staleRuntimeDir) {
5664
+ console.log(
5665
+ `machine service: not running; its runtime files were left behind in ${broker.staleRuntimeDir} (remove them if you uninstalled the Gezel app)`
5666
+ );
4715
5667
  } else if (broker?.present && broker.healthy === false) {
4716
5668
  console.log(`machine service: runtime files present but unreachable (port ${broker.port})`);
4717
5669
  } else if (broker?.present) {
@@ -4722,6 +5674,7 @@ program.command("doctor").description("Check the Gezel installation").action(asy
4722
5674
  console.log("machine service: not installed");
4723
5675
  }
4724
5676
  console.log(`runtime file: ${runtime ? "present" : "missing"}`);
5677
+ let serviceReachable = Boolean(system);
4725
5678
  if (runtime) {
4726
5679
  const alive = isProcessAlive2(runtime.pid);
4727
5680
  console.log(` port=${runtime.port} pid=${runtime.pid} alive=${alive}`);
@@ -4733,12 +5686,59 @@ program.command("doctor").description("Check the Gezel installation").action(asy
4733
5686
  ...runtime.cert ? { fetch: createTrustingFetch2({ cert: runtime.cert }) } : {}
4734
5687
  });
4735
5688
  const health = await client.health();
5689
+ serviceReachable = true;
4736
5690
  const engineNote = health.machineEngineConnected !== void 0 ? ` machine engine connected: ${health.machineEngineConnected ? "yes" : "no"}` : "";
4737
5691
  console.log(` role=${health.serviceRole ?? "user"}${engineNote}`);
4738
5692
  } catch {
4739
5693
  }
4740
5694
  }
4741
5695
  }
5696
+ let modelId;
5697
+ let fitnessAdmitted = null;
5698
+ if (serviceReachable || globals.connect) {
5699
+ try {
5700
+ await withTransientConnection(globals, async (client) => {
5701
+ const [config, fitness, health] = await Promise.all([
5702
+ client.getConfig(),
5703
+ client.listModelFitness().catch(() => ({
5704
+ records: [],
5705
+ probing: []
5706
+ })),
5707
+ client.health().catch(() => null)
5708
+ ]);
5709
+ const provider = config.provider ?? "llama-cpp";
5710
+ modelId = config.defaultModel?.[provider];
5711
+ const key = modelId ? `${provider}:${modelId}` : "";
5712
+ const entry = fitness.records.find((r) => r.key === key);
5713
+ if (entry?.record.status === "probed" && !entry.stale)
5714
+ fitnessAdmitted = entry.record.admitted;
5715
+ const device = {
5716
+ platform: health?.platform ?? process.platform,
5717
+ arch: process.arch,
5718
+ label: health?.platform ?? process.platform
5719
+ };
5720
+ for (const line of renderDoctorModel({
5721
+ provider,
5722
+ modelId,
5723
+ fitness: entry,
5724
+ probing: fitness.probing.includes(key),
5725
+ dataset: SCORECARD,
5726
+ device
5727
+ })) {
5728
+ console.log(line);
5729
+ }
5730
+ });
5731
+ } catch {
5732
+ }
5733
+ }
5734
+ console.log(
5735
+ doctorVerdict({
5736
+ nodeOk: unsupportedNodeMessage(process.versions.node) === void 0,
5737
+ serviceReachable,
5738
+ modelId,
5739
+ fitnessAdmitted
5740
+ })
5741
+ );
4742
5742
  });
4743
5743
  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
5744
  "--content <what>",