@bendyline/gezel-cli 1.2.14 → 1.3.1
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 +63 -16
- package/dist/app-author-command.js +4 -4
- package/dist/app-command.js +10 -3
- package/dist/app-guide.js +1 -1
- package/dist/bin/gezel-main.js +1156 -380
- package/dist/handboek-export.js +99 -37
- package/dist/knowledge-command.js +29 -9
- package/dist/tui/index.js +61 -31
- package/package.json +7 -7
package/dist/bin/gezel-main.js
CHANGED
|
@@ -4,10 +4,6 @@
|
|
|
4
4
|
import { basename as basename4, isAbsolute as isAbsolutePath, join as joinPath } from "path";
|
|
5
5
|
import {
|
|
6
6
|
GEZEL_VERSION,
|
|
7
|
-
IMAGE_ASPECT_RATIOS,
|
|
8
|
-
IMAGE_QUALITIES,
|
|
9
|
-
ImageAspectRatioSchema,
|
|
10
|
-
ImageQualitySchema,
|
|
11
7
|
SCORECARD,
|
|
12
8
|
evaluateApiCompat as evaluateApiCompat2,
|
|
13
9
|
getLogLevel as getLogLevel2,
|
|
@@ -34,6 +30,11 @@ import { resolveOnDeviceProvider as resolveOnDeviceProvider3 } from "@bendyline/
|
|
|
34
30
|
import { Command, Option } from "commander";
|
|
35
31
|
|
|
36
32
|
// src/account-command.ts
|
|
33
|
+
import {
|
|
34
|
+
OLLAMA_EMULATION_PORT,
|
|
35
|
+
containerPublicBase,
|
|
36
|
+
ollamaEmulationAddresses
|
|
37
|
+
} from "@bendyline/gezel";
|
|
37
38
|
import { GezelApiError as GezelApiError2, apiErrorMessage } from "@bendyline/gezel-client";
|
|
38
39
|
|
|
39
40
|
// src/connection.ts
|
|
@@ -313,7 +314,14 @@ async function connectForRun(globals) {
|
|
|
313
314
|
process.env.GEZEL_SKIP_SYSTEM_BOOTSTRAP = "1";
|
|
314
315
|
}
|
|
315
316
|
const { startService } = await import("@bendyline/gezel-service");
|
|
316
|
-
const
|
|
317
|
+
const levelBeforeService = getLogLevel();
|
|
318
|
+
if (!process.env.GEZEL_LOG_LEVEL) setLogLevel("info");
|
|
319
|
+
const svc = await startService({ port: 0, role: "user", logOutput: "file" }).catch(
|
|
320
|
+
(error) => {
|
|
321
|
+
setLogLevel(levelBeforeService);
|
|
322
|
+
throw error;
|
|
323
|
+
}
|
|
324
|
+
);
|
|
317
325
|
const scheme = svc.cert ? "https" : "http";
|
|
318
326
|
const baseUrl = `${scheme}://127.0.0.1:${svc.port}`;
|
|
319
327
|
const client = new GezelClient({
|
|
@@ -327,7 +335,11 @@ async function connectForRun(globals) {
|
|
|
327
335
|
let stopPromise;
|
|
328
336
|
const stop = () => {
|
|
329
337
|
stopPromise ??= (async () => {
|
|
330
|
-
|
|
338
|
+
try {
|
|
339
|
+
await svc.stop();
|
|
340
|
+
} finally {
|
|
341
|
+
setLogLevel(levelBeforeService);
|
|
342
|
+
}
|
|
331
343
|
try {
|
|
332
344
|
const paths = gezelPaths();
|
|
333
345
|
const pid = (await readFile(paths.runtime.pid, "utf8")).trim();
|
|
@@ -779,6 +791,175 @@ async function resolveTuiProject(client, globals) {
|
|
|
779
791
|
return resolveCommandProject(client, globals);
|
|
780
792
|
}
|
|
781
793
|
|
|
794
|
+
// src/settings-command.ts
|
|
795
|
+
import {
|
|
796
|
+
classifySecurityLevel,
|
|
797
|
+
projectManagedWorkspaceWritable,
|
|
798
|
+
resolveSecurityPolicy,
|
|
799
|
+
securityCapabilitiesOf,
|
|
800
|
+
securityPolicyForLevel
|
|
801
|
+
} from "@bendyline/gezel";
|
|
802
|
+
var SECURITY_LEVEL_LABELS = {
|
|
803
|
+
"super-lockdown": "Super Lockdown",
|
|
804
|
+
lockdown: "Lockdown",
|
|
805
|
+
free: "Unrestricted",
|
|
806
|
+
custom: "Custom"
|
|
807
|
+
};
|
|
808
|
+
function policyWithCapability(config, key, enabled) {
|
|
809
|
+
const caps = { ...securityCapabilitiesOf(resolveSecurityPolicy(config)), [key]: enabled };
|
|
810
|
+
return { level: classifySecurityLevel(caps), ...caps };
|
|
811
|
+
}
|
|
812
|
+
function policyWithExternalServices(config, enabled) {
|
|
813
|
+
return policyWithCapability(config, "allowExternalServices", enabled);
|
|
814
|
+
}
|
|
815
|
+
var SECURITY_SWITCHES = [
|
|
816
|
+
{
|
|
817
|
+
command: "external-services",
|
|
818
|
+
key: "allowExternalServices",
|
|
819
|
+
label: "External services",
|
|
820
|
+
description: "Show or set on/off for model-initiated external services, including web search"
|
|
821
|
+
},
|
|
822
|
+
{
|
|
823
|
+
command: "run-package-scripts",
|
|
824
|
+
key: "allowPackageScriptExecution",
|
|
825
|
+
label: "Run package scripts",
|
|
826
|
+
description: "Show or set on/off for Gezel running package scripts and installed package binaries (outside the sandbox, with network access)"
|
|
827
|
+
},
|
|
828
|
+
{
|
|
829
|
+
command: "edit-package-scripts",
|
|
830
|
+
key: "allowPackageScriptEdits",
|
|
831
|
+
label: "Edit package scripts",
|
|
832
|
+
description: "Show or set on/off for Gezel adding or changing the scripts in package.json"
|
|
833
|
+
}
|
|
834
|
+
];
|
|
835
|
+
var CAPABILITY_LABELS = [
|
|
836
|
+
["allowExternalChat", "Cloud models"],
|
|
837
|
+
["allowFileEdits", "File edits and the model\u2019s Git tools"],
|
|
838
|
+
["allowScriptExecution", "Sandboxed scripts"],
|
|
839
|
+
["allowAppNetwork", "Update checks and the connector syncs you start"],
|
|
840
|
+
["allowExternalServices", "Web search, mail and other outside services"],
|
|
841
|
+
["allowPackageScriptExecution", "Run package scripts"],
|
|
842
|
+
["allowPackageScriptEdits", "Edit package scripts"]
|
|
843
|
+
];
|
|
844
|
+
var LEVEL_ALIASES = {
|
|
845
|
+
"super-lockdown": "super-lockdown",
|
|
846
|
+
superlockdown: "super-lockdown",
|
|
847
|
+
lockdown: "lockdown",
|
|
848
|
+
free: "free",
|
|
849
|
+
unrestricted: "free"
|
|
850
|
+
};
|
|
851
|
+
function parseSecurityLevel(input) {
|
|
852
|
+
const level = LEVEL_ALIASES[input.trim().toLowerCase()];
|
|
853
|
+
if (!level) {
|
|
854
|
+
throw new CliError(
|
|
855
|
+
`Unknown security level "${input}". Choose super-lockdown, lockdown, or free (shown as Unrestricted in Settings).`
|
|
856
|
+
);
|
|
857
|
+
}
|
|
858
|
+
return level;
|
|
859
|
+
}
|
|
860
|
+
function describeSecurityLevel(policy) {
|
|
861
|
+
const caps = securityCapabilitiesOf(resolveSecurityPolicy({ securityPolicy: policy }));
|
|
862
|
+
const level = classifySecurityLevel(caps);
|
|
863
|
+
const width = Math.max(...CAPABILITY_LABELS.map(([, label]) => label.length));
|
|
864
|
+
return [
|
|
865
|
+
`Security level: ${SECURITY_LEVEL_LABELS[level]}${level === "custom" ? "" : ` (${level})`}`,
|
|
866
|
+
...CAPABILITY_LABELS.map(
|
|
867
|
+
([key, label]) => ` ${label.padEnd(width)} ${caps[key] ? "on" : "off"}`
|
|
868
|
+
)
|
|
869
|
+
];
|
|
870
|
+
}
|
|
871
|
+
function enabledValue(state) {
|
|
872
|
+
if (state === void 0) return void 0;
|
|
873
|
+
if (state === "on") return true;
|
|
874
|
+
if (state === "off") return false;
|
|
875
|
+
throw new CliError("Use on or off.");
|
|
876
|
+
}
|
|
877
|
+
function registerSecurityCommands(program2, connect) {
|
|
878
|
+
const security = program2.command("security").description("Inspect or explicitly change security settings");
|
|
879
|
+
security.command("level [action] [level]").description(
|
|
880
|
+
"Show the security level, or set a preset: `level set super-lockdown|lockdown|free`"
|
|
881
|
+
).option("--json", "Output the level and its capabilities as JSON").action(
|
|
882
|
+
async (action, requested, options) => {
|
|
883
|
+
if (action !== void 0 && action !== "show" && action !== "set") {
|
|
884
|
+
throw new CliError("Use `gezel security level`, `level show`, or `level set <level>`.");
|
|
885
|
+
}
|
|
886
|
+
if (action === "set" && requested === void 0) {
|
|
887
|
+
throw new CliError("Name a level: super-lockdown, lockdown, or free.");
|
|
888
|
+
}
|
|
889
|
+
if (action !== "set" && requested !== void 0) {
|
|
890
|
+
throw new CliError("To change the level, use `gezel security level set <level>`.");
|
|
891
|
+
}
|
|
892
|
+
const next = action === "set" ? parseSecurityLevel(requested) : void 0;
|
|
893
|
+
const client = await connect();
|
|
894
|
+
const policy = next ? securityPolicyForLevel(next) : {
|
|
895
|
+
level: "custom",
|
|
896
|
+
...securityCapabilitiesOf(resolveSecurityPolicy(await client.getConfig()))
|
|
897
|
+
};
|
|
898
|
+
if (next) await client.updateConfig({ securityPolicy: policy });
|
|
899
|
+
if (options.json) {
|
|
900
|
+
const caps = securityCapabilitiesOf(resolveSecurityPolicy({ securityPolicy: policy }));
|
|
901
|
+
console.log(JSON.stringify({ level: classifySecurityLevel(caps), ...caps }));
|
|
902
|
+
return;
|
|
903
|
+
}
|
|
904
|
+
for (const line of describeSecurityLevel(policy)) console.log(line);
|
|
905
|
+
}
|
|
906
|
+
);
|
|
907
|
+
for (const setting of SECURITY_SWITCHES) {
|
|
908
|
+
security.command(`${setting.command} [state]`).description(setting.description).option("--json", "Output the setting as JSON").action(async (state, options) => {
|
|
909
|
+
const enabled = enabledValue(state);
|
|
910
|
+
const client = await connect();
|
|
911
|
+
const config = await client.getConfig();
|
|
912
|
+
const policy = resolveSecurityPolicy(config);
|
|
913
|
+
if (enabled !== void 0) {
|
|
914
|
+
await client.updateConfig({
|
|
915
|
+
securityPolicy: policyWithCapability(config, setting.key, enabled)
|
|
916
|
+
});
|
|
917
|
+
}
|
|
918
|
+
const value = enabled ?? policy[setting.key];
|
|
919
|
+
console.log(
|
|
920
|
+
options.json ? JSON.stringify({ [setting.key]: value }) : `${setting.label}: ${value ? "on" : "off"}`
|
|
921
|
+
);
|
|
922
|
+
});
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
function registerGrowthCommand(program2, connect) {
|
|
926
|
+
program2.command("growth [state]").description("Show or set on/off for crew growth: XP and the level-ups it offers").option("--json", "Output the setting as JSON").action(async (state, options) => {
|
|
927
|
+
const enabled = enabledValue(state);
|
|
928
|
+
const client = await connect();
|
|
929
|
+
const config = enabled === void 0 ? await client.getConfig() : await client.updateConfig({ growth: { enabled } });
|
|
930
|
+
const value = config.growth?.enabled !== false;
|
|
931
|
+
console.log(
|
|
932
|
+
options.json ? JSON.stringify({ growthEnabled: value }) : `Growth (XP and level-ups): ${value ? "on" : "off"}`
|
|
933
|
+
);
|
|
934
|
+
});
|
|
935
|
+
}
|
|
936
|
+
function registerProjectSettingsCommands(env2, connect, projectFor) {
|
|
937
|
+
env2.command("indexing [state]").description("Show or set on/off for background workspace indexing in the current project").option("--json", "Output the project setting as JSON").action(async (state, options) => {
|
|
938
|
+
const enabled = enabledValue(state);
|
|
939
|
+
const client = await connect();
|
|
940
|
+
const projectId = await projectFor(client);
|
|
941
|
+
const project = enabled === void 0 ? await client.getProject(projectId) : await client.updateProject(projectId, { indexingEnabled: enabled });
|
|
942
|
+
const result = { projectId, indexingEnabled: project.indexingEnabled !== false };
|
|
943
|
+
console.log(
|
|
944
|
+
options.json ? JSON.stringify(result) : `${projectId}: workspace indexing ${result.indexingEnabled ? "on" : "off"}`
|
|
945
|
+
);
|
|
946
|
+
});
|
|
947
|
+
env2.command("edits [state]").description(
|
|
948
|
+
"Show or set on/off for Gezel changing files in the current project's folder (off for a folder until you allow it)"
|
|
949
|
+
).option("--json", "Output the project setting as JSON").action(async (state, options) => {
|
|
950
|
+
const enabled = enabledValue(state);
|
|
951
|
+
const client = await connect();
|
|
952
|
+
const projectId = await projectFor(client);
|
|
953
|
+
const project = enabled === void 0 ? await client.getProject(projectId) : await client.updateProject(projectId, {
|
|
954
|
+
managedWorkspaceWritePolicy: enabled ? "allow" : "deny"
|
|
955
|
+
});
|
|
956
|
+
const result = { projectId, editsAllowed: projectManagedWorkspaceWritable(project) };
|
|
957
|
+
console.log(
|
|
958
|
+
options.json ? JSON.stringify(result) : `${projectId}: ${result.editsAllowed ? "Gezel may change files in this project" : "Gezel may not change files in this project (read-only)"}`
|
|
959
|
+
);
|
|
960
|
+
});
|
|
961
|
+
}
|
|
962
|
+
|
|
782
963
|
// src/account-command.ts
|
|
783
964
|
async function readNewPassword(options, input = process.stdin, write = (text) => process.stderr.write(text)) {
|
|
784
965
|
if (options.passwordStdin) {
|
|
@@ -922,8 +1103,221 @@ function registerAccountCommands(program2, connect, output = console.log, input
|
|
|
922
1103
|
${url}` : `Setup code: ${code}`);
|
|
923
1104
|
});
|
|
924
1105
|
}
|
|
925
|
-
|
|
926
|
-
|
|
1106
|
+
var THIS_COMPUTER = {
|
|
1107
|
+
env: process.env,
|
|
1108
|
+
async ollamaAnswering() {
|
|
1109
|
+
try {
|
|
1110
|
+
const response = await fetch(`${ollamaEmulationAddresses().ollama}/api/version`, {
|
|
1111
|
+
signal: AbortSignal.timeout(1e3)
|
|
1112
|
+
});
|
|
1113
|
+
return response.ok && response.headers.get("x-gezel-ollama-emulation") === "1";
|
|
1114
|
+
} catch {
|
|
1115
|
+
return false;
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
};
|
|
1119
|
+
function keyedAddress(client, env2) {
|
|
1120
|
+
if (env2.GEZEL_CONTAINER === "1") {
|
|
1121
|
+
return { baseUrl: `${containerPublicBase(env2)}/v1`, ownCertificate: false, container: true };
|
|
1122
|
+
}
|
|
1123
|
+
const base = client.getBaseUrl();
|
|
1124
|
+
return { baseUrl: `${base}/v1`, ownCertificate: base.startsWith("https://"), container: false };
|
|
1125
|
+
}
|
|
1126
|
+
var OWN_CERTIFICATE_NOTE = "It is served with Gezel's own certificate, which a program has to trust or skip checking.";
|
|
1127
|
+
var OLLAMA_SWITCH = "gezel integrations ollama on";
|
|
1128
|
+
function describeAppAddresses(input) {
|
|
1129
|
+
const { keyed, emulation } = input;
|
|
1130
|
+
const lines = [];
|
|
1131
|
+
if (!input.appsAllowed) {
|
|
1132
|
+
lines.push(
|
|
1133
|
+
'Apps are not allowed to connect to this Gezel ("Allow apps to connect" is off in Settings \u2192 Integrations). These addresses answer once it is on.',
|
|
1134
|
+
""
|
|
1135
|
+
);
|
|
1136
|
+
}
|
|
1137
|
+
lines.push('With an app key ("gezel integrations token create <app>"):', ` ${keyed.baseUrl}`);
|
|
1138
|
+
if (keyed.ownCertificate) lines.push(` ${OWN_CERTIFICATE_NOTE}`);
|
|
1139
|
+
if (keyed.container) return lines;
|
|
1140
|
+
const plain = ollamaEmulationAddresses();
|
|
1141
|
+
lines.push("");
|
|
1142
|
+
if (!emulation.on) {
|
|
1143
|
+
lines.push(
|
|
1144
|
+
`Without a key, over plain HTTP on a fixed port: off. "${OLLAMA_SWITCH}" turns it on:`,
|
|
1145
|
+
` ${plain.openai}`
|
|
1146
|
+
);
|
|
1147
|
+
} else if (emulation.answering === false) {
|
|
1148
|
+
lines.push(
|
|
1149
|
+
`Ollama emulation is on, but Gezel is not answering on port ${OLLAMA_EMULATION_PORT}. Another program may hold the port (Ollama itself, or another person's Gezel); the service log says which.`
|
|
1150
|
+
);
|
|
1151
|
+
} else {
|
|
1152
|
+
lines.push(
|
|
1153
|
+
"Without a key, over plain HTTP on a fixed port (Ollama emulation is on):",
|
|
1154
|
+
` ${plain.openai} OpenAI-style`,
|
|
1155
|
+
` ${plain.ollama} Ollama`
|
|
1156
|
+
);
|
|
1157
|
+
}
|
|
1158
|
+
return lines;
|
|
1159
|
+
}
|
|
1160
|
+
function isThisComputer(baseUrl) {
|
|
1161
|
+
try {
|
|
1162
|
+
return ["127.0.0.1", "localhost", "[::1]"].includes(new URL(baseUrl).hostname);
|
|
1163
|
+
} catch {
|
|
1164
|
+
return false;
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
var APP_ERRORS = {
|
|
1168
|
+
verification_code_required: "This request needs the code the app is showing. Add --code <code>.",
|
|
1169
|
+
verification_code_invalid: "That code does not match the one the app is showing.",
|
|
1170
|
+
verification_attempts_exceeded: "Too many wrong codes. Ask the app to connect again, then approve the new request.",
|
|
1171
|
+
grant_expired: "That request ran out. Ask the app to connect again.",
|
|
1172
|
+
grant_not_found: "That request is gone. Ask the app to connect again."
|
|
1173
|
+
};
|
|
1174
|
+
async function appsRequest(client, method, path, body) {
|
|
1175
|
+
const response = await client.getFetch()(`${client.getBaseUrl()}/v1/apps${path}`, {
|
|
1176
|
+
method,
|
|
1177
|
+
headers: {
|
|
1178
|
+
...client.authHeader(),
|
|
1179
|
+
...body === void 0 ? {} : { "content-type": "application/json" }
|
|
1180
|
+
},
|
|
1181
|
+
...body === void 0 ? {} : { body: JSON.stringify(body) }
|
|
1182
|
+
});
|
|
1183
|
+
const data = await response.json().catch(() => ({}));
|
|
1184
|
+
if (!response.ok) {
|
|
1185
|
+
const code = typeof data.error === "string" ? data.error : "";
|
|
1186
|
+
throw new CliError(
|
|
1187
|
+
APP_ERRORS[code] ?? `Gezel refused (${response.status}${code ? `: ${code}` : ""}).`
|
|
1188
|
+
);
|
|
1189
|
+
}
|
|
1190
|
+
return data;
|
|
1191
|
+
}
|
|
1192
|
+
async function appRoster(client) {
|
|
1193
|
+
const roster = await appsRequest(client, "GET", "");
|
|
1194
|
+
if (!Array.isArray(roster.apps) || !Array.isArray(roster.grants)) {
|
|
1195
|
+
throw new CliError("This Gezel service did not answer with its connected apps.");
|
|
1196
|
+
}
|
|
1197
|
+
return roster;
|
|
1198
|
+
}
|
|
1199
|
+
function waitingRequests(roster) {
|
|
1200
|
+
return roster.grants.filter((grant) => grant.status === "pending" && grant.kind !== "device");
|
|
1201
|
+
}
|
|
1202
|
+
async function waitingRequestFor(client, appId) {
|
|
1203
|
+
const waiting = waitingRequests(await appRoster(client));
|
|
1204
|
+
const grant = waiting.find((candidate) => candidate.appId === appId);
|
|
1205
|
+
if (grant) return grant;
|
|
1206
|
+
throw new CliError(
|
|
1207
|
+
waiting.length > 0 ? `${appId} is not waiting for approval. Waiting now: ${waiting.map((g) => g.appId).join(", ")}.` : `No app is waiting for approval. A request lasts ten minutes; ask ${appId} to connect again.`
|
|
1208
|
+
);
|
|
1209
|
+
}
|
|
1210
|
+
function registerIntegrationCommands(program2, connect, output = console.log, host = THIS_COMPUTER) {
|
|
1211
|
+
const integrations = program2.command("integrations").description("Connect other apps to this Gezel");
|
|
1212
|
+
integrations.command("address").description("Show where other programs reach this Gezel's models").option("--json", "Output as JSON").action(async (options) => {
|
|
1213
|
+
const client = await connect();
|
|
1214
|
+
const endpoints = (await client.getConfig()).openaiEndpoints ?? {};
|
|
1215
|
+
const keyed = keyedAddress(client, host.env);
|
|
1216
|
+
const on = endpoints.emulateOllama === true;
|
|
1217
|
+
const answering = on && !keyed.container && isThisComputer(client.getBaseUrl()) ? await host.ollamaAnswering() : null;
|
|
1218
|
+
if (options.json) {
|
|
1219
|
+
return output(
|
|
1220
|
+
JSON.stringify({
|
|
1221
|
+
baseUrl: keyed.baseUrl,
|
|
1222
|
+
needsKey: true,
|
|
1223
|
+
ownCertificate: keyed.ownCertificate,
|
|
1224
|
+
appsAllowed: endpoints.enabled !== false,
|
|
1225
|
+
...keyed.container ? {} : { ollamaEmulation: { on, answering, ...ollamaEmulationAddresses() } }
|
|
1226
|
+
})
|
|
1227
|
+
);
|
|
1228
|
+
}
|
|
1229
|
+
output(
|
|
1230
|
+
describeAppAddresses({
|
|
1231
|
+
keyed,
|
|
1232
|
+
appsAllowed: endpoints.enabled !== false,
|
|
1233
|
+
emulation: { on, answering }
|
|
1234
|
+
}).join("\n")
|
|
1235
|
+
);
|
|
1236
|
+
});
|
|
1237
|
+
integrations.command("ollama [state]").description(
|
|
1238
|
+
`Show or set on/off for a plain-HTTP port programs on this computer can use without a key (Ollama emulation, port ${OLLAMA_EMULATION_PORT})`
|
|
1239
|
+
).option("--json", "Output as JSON").action(async (state, options) => {
|
|
1240
|
+
const wanted = enabledValue(state);
|
|
1241
|
+
const client = await connect();
|
|
1242
|
+
const endpoints = (await client.getConfig()).openaiEndpoints ?? {};
|
|
1243
|
+
let on = endpoints.emulateOllama === true;
|
|
1244
|
+
if (wanted !== void 0) {
|
|
1245
|
+
const { emulateOllama: _previous, ...rest } = endpoints;
|
|
1246
|
+
const updated = await plainly(
|
|
1247
|
+
() => client.updateConfig({
|
|
1248
|
+
openaiEndpoints: wanted ? { ...rest, emulateOllama: true } : rest
|
|
1249
|
+
})
|
|
1250
|
+
);
|
|
1251
|
+
on = updated.openaiEndpoints?.emulateOllama === true;
|
|
1252
|
+
if (wanted && !on) {
|
|
1253
|
+
throw new CliError("This build of Gezel does not offer the plain-HTTP port.");
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
const plain = ollamaEmulationAddresses();
|
|
1257
|
+
if (options.json) {
|
|
1258
|
+
return output(JSON.stringify({ emulateOllama: on, ...on ? plain : {} }));
|
|
1259
|
+
}
|
|
1260
|
+
const lines = [`Ollama emulation: ${on ? "on" : "off"}`];
|
|
1261
|
+
if (on && endpoints.enabled === false) {
|
|
1262
|
+
lines.push(
|
|
1263
|
+
'Apps are not allowed to connect to this Gezel, so the port stays closed. Turn on "Allow apps to connect" in Settings \u2192 Integrations.'
|
|
1264
|
+
);
|
|
1265
|
+
} else if (on && host.env.GEZEL_CONTAINER === "1") {
|
|
1266
|
+
lines.push(
|
|
1267
|
+
`In a container this port answers only inside the container. From outside, use ${keyedAddress(client, host.env).baseUrl} with an app key.`
|
|
1268
|
+
);
|
|
1269
|
+
} else if (on) {
|
|
1270
|
+
lines.push(
|
|
1271
|
+
"Programs on this computer can use your models without a key:",
|
|
1272
|
+
` ${plain.openai} OpenAI-style`,
|
|
1273
|
+
` ${plain.ollama} Ollama`,
|
|
1274
|
+
...wanted ? ['It stays on until you run "gezel integrations ollama off".'] : []
|
|
1275
|
+
);
|
|
1276
|
+
}
|
|
1277
|
+
output(lines.join("\n"));
|
|
1278
|
+
});
|
|
1279
|
+
integrations.command("list").description("Show the apps connected to this Gezel and the ones waiting for your approval").option("--json", "Output as JSON").action(async (options) => {
|
|
1280
|
+
const roster = await appRoster(await connect());
|
|
1281
|
+
const waiting = waitingRequests(roster);
|
|
1282
|
+
const label = (app) => `${app.appId}${app.appName && app.appName !== app.appId ? ` ${app.appName}` : ""} (${app.scopes.join(", ")})`;
|
|
1283
|
+
const lines = [];
|
|
1284
|
+
if (waiting.length > 0) {
|
|
1285
|
+
lines.push("Waiting for your approval:");
|
|
1286
|
+
for (const grant of waiting) {
|
|
1287
|
+
lines.push(
|
|
1288
|
+
` ${label(grant)}${grant.verificationRequired ? " needs the code it shows" : ""}`
|
|
1289
|
+
);
|
|
1290
|
+
}
|
|
1291
|
+
lines.push('Answer with "gezel integrations approve <appId>" or "deny <appId>".', "");
|
|
1292
|
+
}
|
|
1293
|
+
const connected = roster.apps.filter(
|
|
1294
|
+
(app) => !app.appId.startsWith("session:") && !app.appId.startsWith("harness:")
|
|
1295
|
+
);
|
|
1296
|
+
if (options.json) return output(JSON.stringify({ waiting, connected }));
|
|
1297
|
+
lines.push(connected.length > 0 ? "Connected:" : "No apps are connected.");
|
|
1298
|
+
for (const app of connected) lines.push(` ${label(app)}`);
|
|
1299
|
+
output(lines.join("\n"));
|
|
1300
|
+
});
|
|
1301
|
+
integrations.command("approve <appId>").description("Let an app that asked to connect use this Gezel").option("--code <code>", "The code the app shows, when it asks for more than model access").action(async (appId, options) => {
|
|
1302
|
+
const client = await connect();
|
|
1303
|
+
const grant = await waitingRequestFor(client, appId);
|
|
1304
|
+
await appsRequest(
|
|
1305
|
+
client,
|
|
1306
|
+
"POST",
|
|
1307
|
+
`/grant/${encodeURIComponent(grant.id)}/approve`,
|
|
1308
|
+
options.code ? { verificationCode: options.code } : {}
|
|
1309
|
+
);
|
|
1310
|
+
output(
|
|
1311
|
+
`${appId} is connected (${grant.scopes.join(", ")}). Revoke it with "gezel integrations token revoke ${appId}".`
|
|
1312
|
+
);
|
|
1313
|
+
});
|
|
1314
|
+
integrations.command("deny <appId>").description("Turn down an app that asked to connect").action(async (appId) => {
|
|
1315
|
+
const client = await connect();
|
|
1316
|
+
const grant = await waitingRequestFor(client, appId);
|
|
1317
|
+
await appsRequest(client, "POST", `/grant/${encodeURIComponent(grant.id)}/deny`);
|
|
1318
|
+
output(`${appId} was turned down.`);
|
|
1319
|
+
});
|
|
1320
|
+
const token = integrations.command("token").description("Make or revoke an app key");
|
|
927
1321
|
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
1322
|
"--scope <scope...>",
|
|
929
1323
|
"What the key may do: openai, knowledge, images, product or cli (default: openai)"
|
|
@@ -935,14 +1329,19 @@ function registerIntegrationCommands(program2, connect, output = console.log) {
|
|
|
935
1329
|
...options.scope?.length ? { scopes: options.scope } : {}
|
|
936
1330
|
})
|
|
937
1331
|
);
|
|
938
|
-
|
|
1332
|
+
const where = keyedAddress(client, host.env);
|
|
1333
|
+
if (options.json) return output(JSON.stringify({ ...created, baseUrl: where.baseUrl }));
|
|
939
1334
|
output(
|
|
940
1335
|
[
|
|
941
1336
|
`Key for ${created.appId} (${created.scopes.join(", ")}):`,
|
|
942
1337
|
` ${created.token}`,
|
|
943
1338
|
"",
|
|
944
|
-
"Use it as the API key, with
|
|
945
|
-
|
|
1339
|
+
"Use it as the API key, with this base URL:",
|
|
1340
|
+
` ${where.baseUrl}`,
|
|
1341
|
+
...where.ownCertificate ? [
|
|
1342
|
+
`${OWN_CERTIFICATE_NOTE} For plain HTTP on a fixed port, see "gezel integrations address".`
|
|
1343
|
+
] : [],
|
|
1344
|
+
'The key is shown once. Revoke it with "gezel integrations token revoke".'
|
|
946
1345
|
].join("\n")
|
|
947
1346
|
);
|
|
948
1347
|
});
|
|
@@ -963,6 +1362,7 @@ import {
|
|
|
963
1362
|
import { resolveOnDeviceProvider } from "@bendyline/gezel/native";
|
|
964
1363
|
|
|
965
1364
|
// src/model-pull.ts
|
|
1365
|
+
import { dirname as dirname2 } from "path";
|
|
966
1366
|
async function pullChatModel(client, engine, id, writeProgress) {
|
|
967
1367
|
let lastPct = -1;
|
|
968
1368
|
let pullError;
|
|
@@ -993,6 +1393,16 @@ async function pullChatModel(client, engine, id, writeProgress) {
|
|
|
993
1393
|
else await client.installLlamaCppModel(id, onEvent);
|
|
994
1394
|
if (pullError) throw new CliError(`download failed: ${pullError}`);
|
|
995
1395
|
}
|
|
1396
|
+
async function findSharedModel(client, engine, id) {
|
|
1397
|
+
if (engine === "mlx") {
|
|
1398
|
+
const { models: models2 } = await client.listMlxModels();
|
|
1399
|
+
const found2 = models2.find((model2) => model2.id === id && model2.readOnly === true);
|
|
1400
|
+
return found2 ? { location: found2.modelDir, updateAvailable: found2.updateAvailable === true } : null;
|
|
1401
|
+
}
|
|
1402
|
+
const { models } = engine === "ds4" ? await client.listDs4Models() : await client.listLlamaCppModels();
|
|
1403
|
+
const found = models.find((model2) => model2.id === id && model2.readOnly === true);
|
|
1404
|
+
return found ? { location: dirname2(found.weightsPath), updateAvailable: found.updateAvailable === true } : null;
|
|
1405
|
+
}
|
|
996
1406
|
async function waitForMlxRuntime(client, writeProgress, options = {}) {
|
|
997
1407
|
const pollMs = options.pollMs ?? 1e3;
|
|
998
1408
|
const now = options.now ?? Date.now;
|
|
@@ -1271,160 +1681,6 @@ function errorMessage(error) {
|
|
|
1271
1681
|
return error instanceof Error ? error.message : String(error);
|
|
1272
1682
|
}
|
|
1273
1683
|
|
|
1274
|
-
// src/settings-command.ts
|
|
1275
|
-
import {
|
|
1276
|
-
classifySecurityLevel,
|
|
1277
|
-
resolveSecurityPolicy,
|
|
1278
|
-
securityCapabilitiesOf,
|
|
1279
|
-
securityPolicyForLevel
|
|
1280
|
-
} from "@bendyline/gezel";
|
|
1281
|
-
var SECURITY_LEVEL_LABELS = {
|
|
1282
|
-
"super-lockdown": "Super Lockdown",
|
|
1283
|
-
lockdown: "Lockdown",
|
|
1284
|
-
free: "Unrestricted",
|
|
1285
|
-
custom: "Custom"
|
|
1286
|
-
};
|
|
1287
|
-
function policyWithCapability(config, key, enabled) {
|
|
1288
|
-
const caps = { ...securityCapabilitiesOf(resolveSecurityPolicy(config)), [key]: enabled };
|
|
1289
|
-
return { level: classifySecurityLevel(caps), ...caps };
|
|
1290
|
-
}
|
|
1291
|
-
function policyWithExternalServices(config, enabled) {
|
|
1292
|
-
return policyWithCapability(config, "allowExternalServices", enabled);
|
|
1293
|
-
}
|
|
1294
|
-
var SECURITY_SWITCHES = [
|
|
1295
|
-
{
|
|
1296
|
-
command: "external-services",
|
|
1297
|
-
key: "allowExternalServices",
|
|
1298
|
-
label: "External services",
|
|
1299
|
-
description: "Show or set on/off for model-initiated external services, including web search"
|
|
1300
|
-
},
|
|
1301
|
-
{
|
|
1302
|
-
command: "run-package-scripts",
|
|
1303
|
-
key: "allowPackageScriptExecution",
|
|
1304
|
-
label: "Run package scripts",
|
|
1305
|
-
description: "Show or set on/off for gezels running package scripts and installed package binaries (outside the sandbox, with network access)"
|
|
1306
|
-
},
|
|
1307
|
-
{
|
|
1308
|
-
command: "edit-package-scripts",
|
|
1309
|
-
key: "allowPackageScriptEdits",
|
|
1310
|
-
label: "Edit package scripts",
|
|
1311
|
-
description: "Show or set on/off for gezels adding or changing the scripts in package.json"
|
|
1312
|
-
}
|
|
1313
|
-
];
|
|
1314
|
-
var CAPABILITY_LABELS = [
|
|
1315
|
-
["allowExternalChat", "Cloud models"],
|
|
1316
|
-
["allowFileEdits", "File edits and the model\u2019s Git tools"],
|
|
1317
|
-
["allowScriptExecution", "Sandboxed scripts"],
|
|
1318
|
-
["allowAppNetwork", "Update checks and the connector syncs you start"],
|
|
1319
|
-
["allowExternalServices", "Web search, mail and other outside services"],
|
|
1320
|
-
["allowPackageScriptExecution", "Run package scripts"],
|
|
1321
|
-
["allowPackageScriptEdits", "Edit package scripts"]
|
|
1322
|
-
];
|
|
1323
|
-
var LEVEL_ALIASES = {
|
|
1324
|
-
"super-lockdown": "super-lockdown",
|
|
1325
|
-
superlockdown: "super-lockdown",
|
|
1326
|
-
lockdown: "lockdown",
|
|
1327
|
-
free: "free",
|
|
1328
|
-
unrestricted: "free"
|
|
1329
|
-
};
|
|
1330
|
-
function parseSecurityLevel(input) {
|
|
1331
|
-
const level = LEVEL_ALIASES[input.trim().toLowerCase()];
|
|
1332
|
-
if (!level) {
|
|
1333
|
-
throw new CliError(
|
|
1334
|
-
`Unknown security level "${input}". Choose super-lockdown, lockdown, or free (shown as Unrestricted in Settings).`
|
|
1335
|
-
);
|
|
1336
|
-
}
|
|
1337
|
-
return level;
|
|
1338
|
-
}
|
|
1339
|
-
function describeSecurityLevel(policy) {
|
|
1340
|
-
const caps = securityCapabilitiesOf(resolveSecurityPolicy({ securityPolicy: policy }));
|
|
1341
|
-
const level = classifySecurityLevel(caps);
|
|
1342
|
-
const width = Math.max(...CAPABILITY_LABELS.map(([, label]) => label.length));
|
|
1343
|
-
return [
|
|
1344
|
-
`Security level: ${SECURITY_LEVEL_LABELS[level]}${level === "custom" ? "" : ` (${level})`}`,
|
|
1345
|
-
...CAPABILITY_LABELS.map(
|
|
1346
|
-
([key, label]) => ` ${label.padEnd(width)} ${caps[key] ? "on" : "off"}`
|
|
1347
|
-
)
|
|
1348
|
-
];
|
|
1349
|
-
}
|
|
1350
|
-
function enabledValue(state) {
|
|
1351
|
-
if (state === void 0) return void 0;
|
|
1352
|
-
if (state === "on") return true;
|
|
1353
|
-
if (state === "off") return false;
|
|
1354
|
-
throw new CliError("Use on or off.");
|
|
1355
|
-
}
|
|
1356
|
-
function registerSecurityCommands(program2, connect) {
|
|
1357
|
-
const security = program2.command("security").description("Inspect or explicitly change security settings");
|
|
1358
|
-
security.command("level [action] [level]").description(
|
|
1359
|
-
"Show the security level, or set a preset: `level set super-lockdown|lockdown|free`"
|
|
1360
|
-
).option("--json", "Output the level and its capabilities as JSON").action(
|
|
1361
|
-
async (action, requested, options) => {
|
|
1362
|
-
if (action !== void 0 && action !== "show" && action !== "set") {
|
|
1363
|
-
throw new CliError("Use `gezel security level`, `level show`, or `level set <level>`.");
|
|
1364
|
-
}
|
|
1365
|
-
if (action === "set" && requested === void 0) {
|
|
1366
|
-
throw new CliError("Name a level: super-lockdown, lockdown, or free.");
|
|
1367
|
-
}
|
|
1368
|
-
if (action !== "set" && requested !== void 0) {
|
|
1369
|
-
throw new CliError("To change the level, use `gezel security level set <level>`.");
|
|
1370
|
-
}
|
|
1371
|
-
const next = action === "set" ? parseSecurityLevel(requested) : void 0;
|
|
1372
|
-
const client = await connect();
|
|
1373
|
-
const policy = next ? securityPolicyForLevel(next) : {
|
|
1374
|
-
level: "custom",
|
|
1375
|
-
...securityCapabilitiesOf(resolveSecurityPolicy(await client.getConfig()))
|
|
1376
|
-
};
|
|
1377
|
-
if (next) await client.updateConfig({ securityPolicy: policy });
|
|
1378
|
-
if (options.json) {
|
|
1379
|
-
const caps = securityCapabilitiesOf(resolveSecurityPolicy({ securityPolicy: policy }));
|
|
1380
|
-
console.log(JSON.stringify({ level: classifySecurityLevel(caps), ...caps }));
|
|
1381
|
-
return;
|
|
1382
|
-
}
|
|
1383
|
-
for (const line of describeSecurityLevel(policy)) console.log(line);
|
|
1384
|
-
}
|
|
1385
|
-
);
|
|
1386
|
-
for (const setting of SECURITY_SWITCHES) {
|
|
1387
|
-
security.command(`${setting.command} [state]`).description(setting.description).option("--json", "Output the setting as JSON").action(async (state, options) => {
|
|
1388
|
-
const enabled = enabledValue(state);
|
|
1389
|
-
const client = await connect();
|
|
1390
|
-
const config = await client.getConfig();
|
|
1391
|
-
const policy = resolveSecurityPolicy(config);
|
|
1392
|
-
if (enabled !== void 0) {
|
|
1393
|
-
await client.updateConfig({
|
|
1394
|
-
securityPolicy: policyWithCapability(config, setting.key, enabled)
|
|
1395
|
-
});
|
|
1396
|
-
}
|
|
1397
|
-
const value = enabled ?? policy[setting.key];
|
|
1398
|
-
console.log(
|
|
1399
|
-
options.json ? JSON.stringify({ [setting.key]: value }) : `${setting.label}: ${value ? "on" : "off"}`
|
|
1400
|
-
);
|
|
1401
|
-
});
|
|
1402
|
-
}
|
|
1403
|
-
}
|
|
1404
|
-
function registerGrowthCommand(program2, connect) {
|
|
1405
|
-
program2.command("growth [state]").description("Show or set on/off for gezel growth: XP and the level-ups it offers").option("--json", "Output the setting as JSON").action(async (state, options) => {
|
|
1406
|
-
const enabled = enabledValue(state);
|
|
1407
|
-
const client = await connect();
|
|
1408
|
-
const config = enabled === void 0 ? await client.getConfig() : await client.updateConfig({ growth: { enabled } });
|
|
1409
|
-
const value = config.growth?.enabled !== false;
|
|
1410
|
-
console.log(
|
|
1411
|
-
options.json ? JSON.stringify({ growthEnabled: value }) : `Growth (XP and level-ups): ${value ? "on" : "off"}`
|
|
1412
|
-
);
|
|
1413
|
-
});
|
|
1414
|
-
}
|
|
1415
|
-
function registerProjectSettingsCommands(env2, connect, projectFor) {
|
|
1416
|
-
env2.command("indexing [state]").description("Show or set on/off for background workspace indexing in the current project").option("--json", "Output the project setting as JSON").action(async (state, options) => {
|
|
1417
|
-
const enabled = enabledValue(state);
|
|
1418
|
-
const client = await connect();
|
|
1419
|
-
const projectId = await projectFor(client);
|
|
1420
|
-
const project = enabled === void 0 ? await client.getProject(projectId) : await client.updateProject(projectId, { indexingEnabled: enabled });
|
|
1421
|
-
const result = { projectId, indexingEnabled: project.indexingEnabled !== false };
|
|
1422
|
-
console.log(
|
|
1423
|
-
options.json ? JSON.stringify(result) : `${projectId}: workspace indexing ${result.indexingEnabled ? "on" : "off"}`
|
|
1424
|
-
);
|
|
1425
|
-
});
|
|
1426
|
-
}
|
|
1427
|
-
|
|
1428
1684
|
// src/craftbook-setup.ts
|
|
1429
1685
|
var BRAVE_KEY_URL = "https://brave.com/search/api/";
|
|
1430
1686
|
var SEARCH_CHECK = { query: "Gezel web search check", limit: 1 };
|
|
@@ -1487,7 +1743,7 @@ ${lines.join("\n")}
|
|
|
1487
1743
|
const to = SECURITY_LEVEL_LABELS[next.level];
|
|
1488
1744
|
const change = from === to ? "" : ` This changes your security level from ${from} to ${to}.`;
|
|
1489
1745
|
const yes = await prompter.confirm(
|
|
1490
|
-
`Turn on External services, so
|
|
1746
|
+
`Turn on External services, so Gezel can search the web and read web pages?${change} [y/N] `
|
|
1491
1747
|
);
|
|
1492
1748
|
if (!yes) stop(gap);
|
|
1493
1749
|
await client.updateConfig({ securityPolicy: next });
|
|
@@ -1499,7 +1755,7 @@ ${lines.join("\n")}
|
|
|
1499
1755
|
const to = SECURITY_LEVEL_LABELS[next.level];
|
|
1500
1756
|
const change = from === to ? "" : ` This changes your security level from ${from} to ${to}.`;
|
|
1501
1757
|
const yes = await prompter.confirm(
|
|
1502
|
-
`Let
|
|
1758
|
+
`Let Gezel run package scripts such as ${gap.commands[0]}? They run outside the sandbox, as your account, with network access, and Gezel asks before each new command.${change} [y/N] `
|
|
1503
1759
|
);
|
|
1504
1760
|
if (!yes) stop(gap);
|
|
1505
1761
|
await client.updateConfig({ securityPolicy: next });
|
|
@@ -1697,9 +1953,9 @@ function describeGap(gap, sizes) {
|
|
|
1697
1953
|
const why = gap.reasons.length > 0 ? ` (${gap.reasons.join("; ")})` : "";
|
|
1698
1954
|
switch (gap.kind) {
|
|
1699
1955
|
case "external-services":
|
|
1700
|
-
return `External services are off, so
|
|
1956
|
+
return `External services are off, so Gezel cannot reach the web${why}.`;
|
|
1701
1957
|
case "package-scripts":
|
|
1702
|
-
return `Run package scripts is off, so
|
|
1958
|
+
return `Run package scripts is off, so Gezel cannot run ${gap.commands.join(", ")}${why}.`;
|
|
1703
1959
|
case "web-search":
|
|
1704
1960
|
return gap.keyMissing ? `Web search needs a Brave Search API key, and none is set${why}.` : `Web search is not set to Brave Search${why}.`;
|
|
1705
1961
|
case "model": {
|
|
@@ -1772,6 +2028,32 @@ async function installedChatModels(client, engine) {
|
|
|
1772
2028
|
const { models } = engine === "mlx" ? await client.listMlxModels() : engine === "ds4" ? await client.listDs4Models() : await client.listLlamaCppModels();
|
|
1773
2029
|
return models.map((model2) => model2.id);
|
|
1774
2030
|
}
|
|
2031
|
+
function chatModelInUse(config, engine, listedIds) {
|
|
2032
|
+
if (config.provider !== engine) return void 0;
|
|
2033
|
+
const external = engine === "mlx" ? config.mlxBaseUrl || config.mlxModelPath : engine === "ds4" ? config.ds4BaseUrl || config.ds4ModelPath : config.llamaCppBaseUrl || config.llamaCppModelPath;
|
|
2034
|
+
if (external) return void 0;
|
|
2035
|
+
const pinned = config.defaultModel?.[engine];
|
|
2036
|
+
if (pinned && listedIds.includes(pinned)) return pinned;
|
|
2037
|
+
if (pinned && engine === "mlx") return void 0;
|
|
2038
|
+
return listedIds[0];
|
|
2039
|
+
}
|
|
2040
|
+
function formatInstalledChatModels(engine, models, config) {
|
|
2041
|
+
if (models.length === 0) {
|
|
2042
|
+
return `(no local ${engine} models \u2014 \`gezel model list --available\` shows ones to download)`;
|
|
2043
|
+
}
|
|
2044
|
+
const inUse = chatModelInUse(
|
|
2045
|
+
config,
|
|
2046
|
+
engine,
|
|
2047
|
+
models.map((model2) => model2.id)
|
|
2048
|
+
);
|
|
2049
|
+
const width = Math.max(28, ...models.map((model2) => model2.id.length));
|
|
2050
|
+
return models.map((model2) => {
|
|
2051
|
+
const notes = [model2.readOnly ? "shared" : "", model2.id === inUse ? "in use" : ""].filter(
|
|
2052
|
+
Boolean
|
|
2053
|
+
);
|
|
2054
|
+
return `${model2.id.padEnd(width)} ${(model2.approxSizeBytes / 1e9).toFixed(2).padStart(6)} GB ${model2.name}${notes.length > 0 ? ` (${notes.join(", ")})` : ""}`;
|
|
2055
|
+
}).join("\n");
|
|
2056
|
+
}
|
|
1775
2057
|
function providerFlag(engine, platformDefault) {
|
|
1776
2058
|
return engine === platformDefault ? "" : ` --provider ${engine}`;
|
|
1777
2059
|
}
|
|
@@ -1785,32 +2067,35 @@ async function availableChatModels(client, engine) {
|
|
|
1785
2067
|
if (engine === "ds4") {
|
|
1786
2068
|
throw new CliError("`--available` lists mlx and llama-cpp models; pass one with --provider.");
|
|
1787
2069
|
}
|
|
1788
|
-
const [memory, catalog, installed, config] = await Promise.all([
|
|
2070
|
+
const [memory, catalog, installed, config, native2] = await Promise.all([
|
|
1789
2071
|
client.getMemoryProfile(),
|
|
1790
2072
|
client.listCatalogItems("chat-model"),
|
|
1791
2073
|
installedChatModels(client, engine),
|
|
1792
|
-
client.getConfig()
|
|
2074
|
+
client.getConfig(),
|
|
2075
|
+
client.getNativeEngineStatus?.().catch(() => void 0)
|
|
1793
2076
|
]);
|
|
1794
|
-
const
|
|
2077
|
+
const inUse = chatModelInUse(config, engine, installed);
|
|
2078
|
+
const gpuUnmeasured = engine === "llama-cpp" && memory.source === "system-ram-fallback" && !!native2?.platformKey && !native2.engines.some((entry) => entry.name === "llama-server" && entry.installed);
|
|
1795
2079
|
return {
|
|
1796
2080
|
ranked: rankChatModels(catalog.items, recoDevice(memory), engine),
|
|
1797
2081
|
installed: new Set(installed),
|
|
1798
|
-
...
|
|
2082
|
+
...inUse ? { inUse } : {},
|
|
2083
|
+
...gpuUnmeasured ? { gpuUnmeasured } : {}
|
|
1799
2084
|
};
|
|
1800
2085
|
}
|
|
1801
2086
|
function formatAvailableChatModels(input) {
|
|
1802
|
-
const { engine, ranked, installed,
|
|
2087
|
+
const { engine, ranked, installed, inUse, measured, gpuUnmeasured } = input;
|
|
1803
2088
|
if (ranked.length === 0) return `(no ${engine} chat models in the catalog for this machine)`;
|
|
1804
2089
|
const width = Math.max(...ranked.map((model2) => model2.id.length));
|
|
1805
2090
|
const measuredWidth = measured ? Math.max("not measured".length, ...ranked.map((m) => (measured.get(m.id) ?? "").length)) : 0;
|
|
1806
2091
|
const lines = [
|
|
1807
|
-
`${engine} chat models for this machine, the recommended first download on top, then by catalog ranking:`
|
|
2092
|
+
gpuUnmeasured ? `${engine} chat models, ranked by this computer's main memory only (its graphics card is not measured yet):` : `${engine} chat models for this machine, the recommended first download on top, then by catalog ranking:`
|
|
1808
2093
|
];
|
|
1809
2094
|
ranked.forEach((model2, index) => {
|
|
1810
2095
|
const notes = [
|
|
1811
|
-
index === 0 ? "recommended" : "",
|
|
2096
|
+
index === 0 && !gpuUnmeasured ? "recommended" : "",
|
|
1812
2097
|
installed.has(model2.id) ? "installed" : "",
|
|
1813
|
-
model2.id ===
|
|
2098
|
+
model2.id === inUse ? "in use" : ""
|
|
1814
2099
|
].filter(Boolean);
|
|
1815
2100
|
const claim = measured ? ` ${(measured.get(model2.id) ?? "not measured").padEnd(measuredWidth)}` : "";
|
|
1816
2101
|
lines.push(
|
|
@@ -1819,6 +2104,12 @@ function formatAvailableChatModels(input) {
|
|
|
1819
2104
|
});
|
|
1820
2105
|
const flag = providerFlag(engine, input.platformDefault);
|
|
1821
2106
|
const smallest = [...ranked].sort((a, b) => a.approxSizeBytes - b.approxSizeBytes)[0];
|
|
2107
|
+
if (gpuUnmeasured) {
|
|
2108
|
+
lines.push(
|
|
2109
|
+
"",
|
|
2110
|
+
"Gezel reads a graphics card through its engine, which is not installed yet. Run `gezel native install`, then list again to see the model recommended for this computer."
|
|
2111
|
+
);
|
|
2112
|
+
}
|
|
1822
2113
|
lines.push(
|
|
1823
2114
|
"",
|
|
1824
2115
|
`Download one with \`gezel model pull <id>${flag}\`. The smallest is ${smallest.id} (${formatDownloadSize(smallest.approxSizeBytes)}).`,
|
|
@@ -1908,7 +2199,9 @@ async function checkRunReadiness(client, gezelId, env2 = process.env) {
|
|
|
1908
2199
|
const installed = provider === "mlx" ? await client.listMlxModels() : await client.listLlamaCppModels();
|
|
1909
2200
|
const installedIds = installed.models.map((model2) => model2.id);
|
|
1910
2201
|
const pinned = config.defaultModel?.[provider];
|
|
1911
|
-
const engineMissing =
|
|
2202
|
+
const engineMissing = !native2.engines.some(
|
|
2203
|
+
(engine) => engine.name === ENGINE_BINARY[provider] && engine.installed
|
|
2204
|
+
);
|
|
1912
2205
|
const modelReady = pinned ? installedIds.includes(pinned) : installedIds.length > 0;
|
|
1913
2206
|
if (!engineMissing && modelReady) return READY;
|
|
1914
2207
|
return {
|
|
@@ -2549,9 +2842,14 @@ function detailText(details) {
|
|
|
2549
2842
|
// src/craftbook-command.ts
|
|
2550
2843
|
import { setTimeout as delay } from "timers/promises";
|
|
2551
2844
|
import {
|
|
2845
|
+
PROJECT_EDITS_CLI_COMMAND,
|
|
2552
2846
|
composeCraftbookLaunch,
|
|
2553
2847
|
createAwakeTimeout,
|
|
2554
|
-
|
|
2848
|
+
isRuntimeTemplateDefault,
|
|
2849
|
+
paramAsksUser,
|
|
2850
|
+
paramInputSpec,
|
|
2851
|
+
projectManagedWorkspaceWritable as projectManagedWorkspaceWritable2,
|
|
2852
|
+
stepWorkspaceDeliverableFiles
|
|
2555
2853
|
} from "@bendyline/gezel";
|
|
2556
2854
|
|
|
2557
2855
|
// src/tui/craftbook-start.ts
|
|
@@ -2633,13 +2931,19 @@ function checkParamValue(key, def, value) {
|
|
|
2633
2931
|
if (typeof def.minLength === "number" && value.trim().length < def.minLength)
|
|
2634
2932
|
throw new CliError(`${key} is too short`);
|
|
2635
2933
|
}
|
|
2636
|
-
function
|
|
2934
|
+
function craftbookBareSlots(book) {
|
|
2637
2935
|
const schema = book.paramSchema ?? {};
|
|
2638
2936
|
const properties = schema.properties ?? {};
|
|
2639
2937
|
const required = new Set(Array.isArray(schema.required) ? schema.required : []);
|
|
2640
|
-
|
|
2938
|
+
return Object.keys(properties).filter(
|
|
2641
2939
|
(key) => required.has(key) && properties[key].default === void 0 && paramAsksUser(properties[key], key)
|
|
2642
2940
|
);
|
|
2941
|
+
}
|
|
2942
|
+
function parseCraftbookArguments(book, tokens, named = []) {
|
|
2943
|
+
const schema = book.paramSchema ?? {};
|
|
2944
|
+
const properties = schema.properties ?? {};
|
|
2945
|
+
const required = new Set(Array.isArray(schema.required) ? schema.required : []);
|
|
2946
|
+
const slots = craftbookBareSlots(book);
|
|
2643
2947
|
const params = {};
|
|
2644
2948
|
const requestWords = [];
|
|
2645
2949
|
const set = (key, value, token) => {
|
|
@@ -2680,6 +2984,119 @@ function craftbookDoLaunch(craftbook2, { params, request }) {
|
|
|
2680
2984
|
});
|
|
2681
2985
|
return { description: launch.description, craftbookParams: launch.params };
|
|
2682
2986
|
}
|
|
2987
|
+
function craftbookFolderFiles(craftbook2) {
|
|
2988
|
+
const files = /* @__PURE__ */ new Set();
|
|
2989
|
+
for (const step of craftbook2.steps ?? []) {
|
|
2990
|
+
for (const file of stepWorkspaceDeliverableFiles(step)) files.add(file);
|
|
2991
|
+
}
|
|
2992
|
+
return [...files];
|
|
2993
|
+
}
|
|
2994
|
+
function nameFolderFiles(files) {
|
|
2995
|
+
const named = files.filter((file) => !isRuntimeTemplateDefault(file));
|
|
2996
|
+
if (named.length === 0) return "its results";
|
|
2997
|
+
const rest = files.length - 1;
|
|
2998
|
+
return rest === 0 ? named[0] : `${named[0]} and ${rest} more file${rest === 1 ? "" : "s"}`;
|
|
2999
|
+
}
|
|
3000
|
+
async function ensureProjectEdits(client, options) {
|
|
3001
|
+
const files = craftbookFolderFiles(options.craftbook);
|
|
3002
|
+
if (files.length === 0) return;
|
|
3003
|
+
const project = await client.getProject(options.projectId);
|
|
3004
|
+
if (projectManagedWorkspaceWritable2(project)) return;
|
|
3005
|
+
const what = nameFolderFiles(files);
|
|
3006
|
+
const where = project.workingDir ?? "this project";
|
|
3007
|
+
const turnOn = async () => {
|
|
3008
|
+
await client.updateProject(options.projectId, { managedWorkspaceWritePolicy: "allow" });
|
|
3009
|
+
};
|
|
3010
|
+
if (options.allow) {
|
|
3011
|
+
await turnOn();
|
|
3012
|
+
options.write(`Gezel may now change files in ${where} (--allow-edits).
|
|
3013
|
+
`);
|
|
3014
|
+
return;
|
|
3015
|
+
}
|
|
3016
|
+
const saves = `${options.craftbook.name} saves ${what} into ${where}, and Gezel may not change files there yet.`;
|
|
3017
|
+
if (options.prompter) {
|
|
3018
|
+
if (await options.prompter.confirm(`${saves} Allow it? [y/N] `)) {
|
|
3019
|
+
await turnOn();
|
|
3020
|
+
options.write("Project edits: on\n");
|
|
3021
|
+
return;
|
|
3022
|
+
}
|
|
3023
|
+
}
|
|
3024
|
+
options.write(
|
|
3025
|
+
`${saves} If it stops for that, run \`${PROJECT_EDITS_CLI_COMMAND}\` here, or start it with --allow-edits.
|
|
3026
|
+
`
|
|
3027
|
+
);
|
|
3028
|
+
}
|
|
3029
|
+
function taskInputFailure(err, book, params) {
|
|
3030
|
+
if (!(err instanceof Error) || err.name !== "GezelApiError") return null;
|
|
3031
|
+
const details = err.details;
|
|
3032
|
+
if (!details || typeof details !== "object") return null;
|
|
3033
|
+
const { code, param, error } = details;
|
|
3034
|
+
if (code !== "task-input" || typeof param !== "string") return null;
|
|
3035
|
+
const value = params[param];
|
|
3036
|
+
const lines = [
|
|
3037
|
+
`${book.name} did not start: ${typeof error === "string" ? error : `${param} is not usable.`}`
|
|
3038
|
+
];
|
|
3039
|
+
if (value && /\s/.test(value.trim())) {
|
|
3040
|
+
lines.push(
|
|
3041
|
+
`It read "${value}" as ${param}, which comes before your request:`,
|
|
3042
|
+
` gezel do ${book.command} <${param}> "your request"`
|
|
3043
|
+
);
|
|
3044
|
+
}
|
|
3045
|
+
lines.push(`\`gezel craftbook show ${book.command}\` lists what it takes.`);
|
|
3046
|
+
return new CliError(lines.join("\n"));
|
|
3047
|
+
}
|
|
3048
|
+
function firstParagraph(text) {
|
|
3049
|
+
return (text ?? "").split(/\n\s*\n/)[0]?.replace(/\s+/g, " ").trim() ?? "";
|
|
3050
|
+
}
|
|
3051
|
+
function paramAccepts(property) {
|
|
3052
|
+
const input = paramInputSpec(property);
|
|
3053
|
+
if (input) {
|
|
3054
|
+
const kinds = input.accept ? ` (${input.accept.join(", ")})` : "";
|
|
3055
|
+
return input.kind === "folder" ? "a folder or file in this project" : `a file in this project${kinds}`;
|
|
3056
|
+
}
|
|
3057
|
+
if (Array.isArray(property.enum)) return `one of: ${property.enum.map(String).join(", ")}`;
|
|
3058
|
+
if (property.type === "boolean") return "true or false";
|
|
3059
|
+
if (property.type === "number" || property.type === "integer") return "a number";
|
|
3060
|
+
return "text";
|
|
3061
|
+
}
|
|
3062
|
+
function describeCraftbook(book, craftbook2) {
|
|
3063
|
+
const schema = craftbook2.paramSchema ?? {};
|
|
3064
|
+
const properties = schema.properties ?? {};
|
|
3065
|
+
const required = new Set(Array.isArray(schema.required) ? schema.required : []);
|
|
3066
|
+
const slots = craftbookBareSlots(craftbook2);
|
|
3067
|
+
const asked = Object.keys(properties).filter((key) => paramAsksUser(properties[key], key));
|
|
3068
|
+
const lines = [`${book.command} \u2014 ${book.name}`];
|
|
3069
|
+
const about = firstParagraph(craftbook2.description);
|
|
3070
|
+
if (about) lines.push(about);
|
|
3071
|
+
lines.push("", "Start it:");
|
|
3072
|
+
lines.push(
|
|
3073
|
+
` gezel do ${[book.command, ...slots.map((key) => `<${key}>`)].join(" ")} "your request"`
|
|
3074
|
+
);
|
|
3075
|
+
if (asked.length > 0) {
|
|
3076
|
+
const width = Math.max(...asked.map((key) => key.length));
|
|
3077
|
+
lines.push("", "Takes:");
|
|
3078
|
+
for (const key of asked) {
|
|
3079
|
+
const property = properties[key];
|
|
3080
|
+
const need = required.has(key) && property.default === void 0 ? "required" : "optional";
|
|
3081
|
+
const fallback = property.default !== void 0 && !isRuntimeTemplateDefault(property.default) ? `, default ${String(property.default)}` : "";
|
|
3082
|
+
const note = firstParagraph(
|
|
3083
|
+
typeof property.title === "string" ? property.title : typeof property.description === "string" ? property.description : ""
|
|
3084
|
+
);
|
|
3085
|
+
lines.push(
|
|
3086
|
+
` ${key.padEnd(width)} ${need}, ${paramAccepts(property)}${fallback}${note ? ` \u2014 ${note}` : ""}`
|
|
3087
|
+
);
|
|
3088
|
+
}
|
|
3089
|
+
const named = asked.filter((key) => !slots.includes(key));
|
|
3090
|
+
if (named.length > 0)
|
|
3091
|
+
lines.push(`Set the optional ones by name, for example ${named[0]}=value.`);
|
|
3092
|
+
}
|
|
3093
|
+
const files = craftbookFolderFiles(craftbook2);
|
|
3094
|
+
lines.push(
|
|
3095
|
+
"",
|
|
3096
|
+
files.length > 0 ? `Saves ${nameFolderFiles(files)} into the project folder, so the project must allow edits (\`${PROJECT_EDITS_CLI_COMMAND}\`, or --allow-edits).` : "Saves its results in the task's own folder; add --out <dir> to copy them out."
|
|
3097
|
+
);
|
|
3098
|
+
return lines.join("\n");
|
|
3099
|
+
}
|
|
2683
3100
|
var READ_RETRY_DELAYS = [250, 750, 1500];
|
|
2684
3101
|
function transientTaskReadError(error) {
|
|
2685
3102
|
const codes = /ECONNRESET|ECONNREFUSED|ECONNABORTED|EPIPE|ETIMEDOUT|EHOSTUNREACH|ENETUNREACH|EAI_AGAIN|UND_ERR_(?:SOCKET|CONNECT_TIMEOUT)|NGHTTP2_ENHANCE_YOUR_CALM|Connect Timeout Error|socket hang up|other side closed/;
|
|
@@ -2780,15 +3197,22 @@ function summarizeTaskNote(text, maxLength = 240) {
|
|
|
2780
3197
|
const summary = heading && sentence ? `${heading}: ${sentence}` : heading || sentence;
|
|
2781
3198
|
return summary.length > maxLength ? `${summary.slice(0, maxLength - 1).trimEnd()}\u2026` : summary;
|
|
2782
3199
|
}
|
|
2783
|
-
async function
|
|
2784
|
-
if (result.outcome !== "blocked") return
|
|
3200
|
+
async function blockedTaskDetails(client, result) {
|
|
3201
|
+
if (result.outcome !== "blocked") return {};
|
|
2785
3202
|
if (result.questionIds?.length) {
|
|
2786
|
-
return
|
|
3203
|
+
return {
|
|
3204
|
+
reason: "Gezel is waiting for your answer to a question. Answer it in the Gezel app or the interactive `gezel` terminal."
|
|
3205
|
+
};
|
|
3206
|
+
}
|
|
3207
|
+
if (result.task.status === "draft") {
|
|
3208
|
+
return { reason: "The task is still a draft and has not started." };
|
|
2787
3209
|
}
|
|
2788
|
-
if (result.task.status === "draft") return "The task is still a draft and has not started.";
|
|
2789
3210
|
const { notes } = await client.listTaskNotes(result.task.projectId, result.task.num).catch(() => ({ notes: [] }));
|
|
2790
3211
|
const latest = [...notes].sort((a, b) => a.at.localeCompare(b.at)).at(-1);
|
|
2791
|
-
|
|
3212
|
+
if (!latest) return {};
|
|
3213
|
+
const reason = summarizeTaskNote(latest.text) || void 0;
|
|
3214
|
+
const hint = latest.text.includes(PROJECT_EDITS_CLI_COMMAND) ? `Allow it with \`${PROJECT_EDITS_CLI_COMMAND}\` in the project's folder, then continue with \`gezel task resume ${result.task.ref}\`.` : void 0;
|
|
3215
|
+
return { ...reason ? { reason } : {}, ...hint ? { hint } : {} };
|
|
2792
3216
|
}
|
|
2793
3217
|
function filterCraftbooks(books, words) {
|
|
2794
3218
|
const needles = words.map((word) => word.trim().toLowerCase()).filter(Boolean);
|
|
@@ -2905,7 +3329,8 @@ var CHECK_LABELS = {
|
|
|
2905
3329
|
toolRoundTrip: "answers a tool call",
|
|
2906
3330
|
throughput: "decodes fast enough",
|
|
2907
3331
|
reasoningBudget: "bounded reasoning",
|
|
2908
|
-
contextFit: "room for a prompt"
|
|
3332
|
+
contextFit: "room for a prompt",
|
|
3333
|
+
coherence: "writes readable replies"
|
|
2909
3334
|
};
|
|
2910
3335
|
function renderFitness(entry, probing) {
|
|
2911
3336
|
if (probing) return ["fitness check: running now"];
|
|
@@ -3021,7 +3446,7 @@ var CLI_ENGAGEMENT_MODES = [
|
|
|
3021
3446
|
name: "full-play",
|
|
3022
3447
|
mode: "proactive",
|
|
3023
3448
|
label: "Full play",
|
|
3024
|
-
description: "Everything runs, including proactive nudges and
|
|
3449
|
+
description: "Everything runs, including proactive nudges and handoffs."
|
|
3025
3450
|
}
|
|
3026
3451
|
];
|
|
3027
3452
|
var MODE_ALIASES = {
|
|
@@ -3048,9 +3473,17 @@ var CLI_ENGAGEMENT_MODE_USAGE = CLI_ENGAGEMENT_MODES.map((option) => option.name
|
|
|
3048
3473
|
"|"
|
|
3049
3474
|
);
|
|
3050
3475
|
|
|
3476
|
+
// src/generate-command.ts
|
|
3477
|
+
import {
|
|
3478
|
+
IMAGE_ASPECT_RATIOS,
|
|
3479
|
+
IMAGE_QUALITIES,
|
|
3480
|
+
ImageAspectRatioSchema,
|
|
3481
|
+
ImageQualitySchema
|
|
3482
|
+
} from "@bendyline/gezel";
|
|
3483
|
+
|
|
3051
3484
|
// src/generate.ts
|
|
3052
3485
|
import { mkdir as mkdir2, readFile as readFile4, writeFile as writeFile3 } from "fs/promises";
|
|
3053
|
-
import { basename as basename2, dirname as
|
|
3486
|
+
import { basename as basename2, dirname as dirname3, resolve as resolve2 } from "path";
|
|
3054
3487
|
async function resolvePromptText(parts, file, label) {
|
|
3055
3488
|
const inline = (parts ?? []).join(" ").trim();
|
|
3056
3489
|
if (file) {
|
|
@@ -3087,16 +3520,150 @@ function floatOpt(name, v) {
|
|
|
3087
3520
|
if (!Number.isFinite(n)) throw new CliError(`--${name} must be a number (got "${v}").`);
|
|
3088
3521
|
return n;
|
|
3089
3522
|
}
|
|
3523
|
+
async function readPictureOpt(path) {
|
|
3524
|
+
let data;
|
|
3525
|
+
try {
|
|
3526
|
+
data = await readFile4(path);
|
|
3527
|
+
} catch (err) {
|
|
3528
|
+
throw new CliError(
|
|
3529
|
+
`could not read --image ${path}: ${err instanceof Error ? err.message : String(err)}`
|
|
3530
|
+
);
|
|
3531
|
+
}
|
|
3532
|
+
const ext = path.toLowerCase().split(".").pop();
|
|
3533
|
+
const mimeType = ext === "jpg" || ext === "jpeg" ? "image/jpeg" : ext === "webp" ? "image/webp" : ext === "gif" ? "image/gif" : "image/png";
|
|
3534
|
+
return { data: data.toString("base64"), mimeType };
|
|
3535
|
+
}
|
|
3090
3536
|
async function saveArtifact(client, projectId, artifactPath, output) {
|
|
3091
3537
|
const rel = artifactPath.replace(/^artifacts\//, "");
|
|
3092
3538
|
const blob = await client.fetchProjectArtifactBlob(projectId, rel);
|
|
3093
3539
|
const bytes = Buffer.from(await blob.arrayBuffer());
|
|
3094
3540
|
const dest = output ? resolve2(output) : resolve2(process.cwd(), basename2(artifactPath));
|
|
3095
|
-
await mkdir2(
|
|
3541
|
+
await mkdir2(dirname3(dest), { recursive: true });
|
|
3096
3542
|
await writeFile3(dest, bytes);
|
|
3097
3543
|
return dest;
|
|
3098
3544
|
}
|
|
3099
3545
|
|
|
3546
|
+
// src/generate-command.ts
|
|
3547
|
+
function registerGenerateCommands(program2, connect) {
|
|
3548
|
+
program2.command("create-image [prompt...]").description("Generate an image from a prompt (or --file) via the configured image engine").option("-f, --file <path>", "read the prompt from a text file instead of the argument").option("-m, --model <id>", "image model catalog id (default: the engine default)").option("-n, --negative <text>", "negative prompt").option("-W, --width <px>", "width in pixels").option("-H, --height <px>", "height in pixels").option("-a, --aspect <ratio>", `aspect ratio: ${IMAGE_ASPECT_RATIOS.join(", ")}`).option("-q, --quality <tier>", `size tier: ${IMAGE_QUALITIES.join(", ")} (default: standard)`).option("-s, --steps <n>", "sampler steps (default: the model recommendation)").option("--seed <n>", "seed for reproducible output").option("-p, --project <id>", "project to write the artifact under", "default").option("-o, --output <path>", "write the image here (default: ./<artifact name>)").action(
|
|
3549
|
+
async (promptParts, opts) => {
|
|
3550
|
+
const aspect = enumOpt("aspect", opts.aspect, ImageAspectRatioSchema);
|
|
3551
|
+
const quality = enumOpt("quality", opts.quality, ImageQualitySchema);
|
|
3552
|
+
const prompt = await resolvePromptText(promptParts, opts.file, "prompt");
|
|
3553
|
+
const client = await connect();
|
|
3554
|
+
const projectId = opts.project ?? "default";
|
|
3555
|
+
const width = intOpt("width", opts.width);
|
|
3556
|
+
const height = intOpt("height", opts.height);
|
|
3557
|
+
const steps = intOpt("steps", opts.steps);
|
|
3558
|
+
const seed = intOpt("seed", opts.seed);
|
|
3559
|
+
console.error(`generating image${opts.model ? ` (model ${opts.model})` : ""}...`);
|
|
3560
|
+
let res;
|
|
3561
|
+
try {
|
|
3562
|
+
res = await client.generateImage({
|
|
3563
|
+
prompt,
|
|
3564
|
+
projectId,
|
|
3565
|
+
...opts.model ? { model: opts.model } : {},
|
|
3566
|
+
...opts.negative ? { negativePrompt: opts.negative } : {},
|
|
3567
|
+
...width !== void 0 ? { width } : {},
|
|
3568
|
+
...height !== void 0 ? { height } : {},
|
|
3569
|
+
...aspect ? { aspectRatio: aspect } : {},
|
|
3570
|
+
...quality ? { quality } : {},
|
|
3571
|
+
...steps !== void 0 ? { steps } : {},
|
|
3572
|
+
...seed !== void 0 ? { seed } : {}
|
|
3573
|
+
});
|
|
3574
|
+
} catch (err) {
|
|
3575
|
+
throw new CliError(
|
|
3576
|
+
`image generation failed: ${err instanceof Error ? err.message : String(err)}`
|
|
3577
|
+
);
|
|
3578
|
+
}
|
|
3579
|
+
const dest = await saveArtifact(client, projectId, res.artifactPath, opts.output);
|
|
3580
|
+
const m = res.meta;
|
|
3581
|
+
console.log(dest);
|
|
3582
|
+
console.error(
|
|
3583
|
+
` model=${m.model} seed=${m.seed} steps=${m.steps} size=${m.widthPx}x${m.heightPx} time=${(m.durationMs / 1e3).toFixed(1)}s`
|
|
3584
|
+
);
|
|
3585
|
+
}
|
|
3586
|
+
);
|
|
3587
|
+
program2.command("create-video [prompt...]").description(
|
|
3588
|
+
"Generate a video from a prompt (or --file), or animate a picture (--image), via the configured video engine"
|
|
3589
|
+
).option("-f, --file <path>", "read the prompt from a text file instead of the argument").option("-m, --model <id>", "video model catalog id (default: the engine default)").option("-n, --negative <text>", "negative prompt").option("-W, --width <px>", "width in pixels").option("-H, --height <px>", "height in pixels").option("-i, --image <path>", "a picture to animate; it becomes the first frame").option("-a, --aspect <ratio>", `aspect ratio: ${IMAGE_ASPECT_RATIOS.join(", ")}`).option("--frames <n>", "number of frames").option("--fps <n>", "frames per second").option("-s, --steps <n>", "sampler steps").option("--seed <n>", "seed for reproducible output").option("-p, --project <id>", "project to write the artifact under", "default").option("-o, --output <path>", "write the video here (default: ./<artifact name>)").action(
|
|
3590
|
+
async (promptParts, opts) => {
|
|
3591
|
+
const prompt = await resolvePromptText(promptParts, opts.file, "prompt");
|
|
3592
|
+
const aspect = enumOpt("aspect", opts.aspect, ImageAspectRatioSchema);
|
|
3593
|
+
const picture = opts.image ? await readPictureOpt(opts.image) : void 0;
|
|
3594
|
+
const client = await connect();
|
|
3595
|
+
const projectId = opts.project ?? "default";
|
|
3596
|
+
const width = intOpt("width", opts.width);
|
|
3597
|
+
const height = intOpt("height", opts.height);
|
|
3598
|
+
const numFrames = intOpt("frames", opts.frames);
|
|
3599
|
+
const fps = intOpt("fps", opts.fps);
|
|
3600
|
+
const steps = intOpt("steps", opts.steps);
|
|
3601
|
+
const seed = intOpt("seed", opts.seed);
|
|
3602
|
+
console.error(
|
|
3603
|
+
`generating video${opts.model ? ` (model ${opts.model})` : ""} \u2014 this can take a while...`
|
|
3604
|
+
);
|
|
3605
|
+
let res;
|
|
3606
|
+
try {
|
|
3607
|
+
res = await client.generateVideo({
|
|
3608
|
+
prompt,
|
|
3609
|
+
projectId,
|
|
3610
|
+
...opts.model ? { model: opts.model } : {},
|
|
3611
|
+
...opts.negative ? { negativePrompt: opts.negative } : {},
|
|
3612
|
+
...width !== void 0 ? { width } : {},
|
|
3613
|
+
...height !== void 0 ? { height } : {},
|
|
3614
|
+
...aspect ? { aspectRatio: aspect } : {},
|
|
3615
|
+
...picture ? { inputImage: picture, requireImageToVideo: true } : {},
|
|
3616
|
+
...numFrames !== void 0 ? { numFrames } : {},
|
|
3617
|
+
...fps !== void 0 ? { fps } : {},
|
|
3618
|
+
...steps !== void 0 ? { steps } : {},
|
|
3619
|
+
...seed !== void 0 ? { seed } : {}
|
|
3620
|
+
});
|
|
3621
|
+
} catch (err) {
|
|
3622
|
+
throw new CliError(
|
|
3623
|
+
`video generation failed: ${err instanceof Error ? err.message : String(err)}`
|
|
3624
|
+
);
|
|
3625
|
+
}
|
|
3626
|
+
const dest = await saveArtifact(client, projectId, res.artifactPath, opts.output);
|
|
3627
|
+
const m = res.meta;
|
|
3628
|
+
console.log(dest);
|
|
3629
|
+
console.error(
|
|
3630
|
+
` model=${m.model} seed=${m.seed} ${m.widthPx}x${m.heightPx} frames=${m.numFrames} fps=${m.fps} time=${(m.durationMs / 1e3).toFixed(1)}s`
|
|
3631
|
+
);
|
|
3632
|
+
for (const note of m.settingsNotes ?? []) console.error(` note: ${note}`);
|
|
3633
|
+
}
|
|
3634
|
+
);
|
|
3635
|
+
program2.command("create-audio [text...]").description("Synthesize speech from text (or --file) via the configured TTS engine").option("-f, --file <path>", "read the text from a file instead of the argument").option("-m, --model <id>", "TTS model catalog id (default: the engine default)").option("--voice <id>", "voice id (default: the model or crew member default)").option("--speed <x>", "speed multiplier, 0.25-4 (default: 1.0)").option("-p, --project <id>", "project to write the artifact under", "default").option("-o, --output <path>", "write the audio here (default: ./<artifact name>)").action(
|
|
3636
|
+
async (textParts, opts) => {
|
|
3637
|
+
const text = await resolvePromptText(textParts, opts.file, "text");
|
|
3638
|
+
const client = await connect();
|
|
3639
|
+
const projectId = opts.project ?? "default";
|
|
3640
|
+
const speed = floatOpt("speed", opts.speed);
|
|
3641
|
+
console.error("synthesizing speech...");
|
|
3642
|
+
let res;
|
|
3643
|
+
try {
|
|
3644
|
+
res = await client.synthesizeSpeech({
|
|
3645
|
+
text,
|
|
3646
|
+
projectId,
|
|
3647
|
+
...opts.model ? { model: opts.model } : {},
|
|
3648
|
+
...opts.voice ? { voice: opts.voice } : {},
|
|
3649
|
+
...speed !== void 0 ? { speed } : {}
|
|
3650
|
+
});
|
|
3651
|
+
} catch (err) {
|
|
3652
|
+
throw new CliError(
|
|
3653
|
+
`speech synthesis failed: ${err instanceof Error ? err.message : String(err)}`
|
|
3654
|
+
);
|
|
3655
|
+
}
|
|
3656
|
+
if (!res.artifactPath) throw new CliError("speech synthesis returned no saved audio");
|
|
3657
|
+
const dest = await saveArtifact(client, projectId, res.artifactPath, opts.output);
|
|
3658
|
+
const m = res.meta;
|
|
3659
|
+
console.log(dest);
|
|
3660
|
+
console.error(
|
|
3661
|
+
` voice=${m.voice} model=${m.model} ${m.durationSeconds.toFixed(1)}s @ ${m.sampleRate}Hz`
|
|
3662
|
+
);
|
|
3663
|
+
}
|
|
3664
|
+
);
|
|
3665
|
+
}
|
|
3666
|
+
|
|
3100
3667
|
// src/knowledge-install.ts
|
|
3101
3668
|
import { existsSync as existsSync2 } from "fs";
|
|
3102
3669
|
import { resolve as resolve3 } from "path";
|
|
@@ -3249,7 +3816,7 @@ function registerMcpCommands(program2, connect, output = console.log) {
|
|
|
3249
3816
|
// src/model-export.ts
|
|
3250
3817
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
3251
3818
|
import { rename, rm as rm2, stat } from "fs/promises";
|
|
3252
|
-
import { basename as basename3, dirname as
|
|
3819
|
+
import { basename as basename3, dirname as dirname4, isAbsolute, resolve as resolve4 } from "path";
|
|
3253
3820
|
import {
|
|
3254
3821
|
modelBytesFromResponse,
|
|
3255
3822
|
portableGezmodelFilename,
|
|
@@ -3292,8 +3859,8 @@ async function exportModelToFile(client, id, options) {
|
|
|
3292
3859
|
if (!options.force && await isExistingFile(target)) {
|
|
3293
3860
|
throw new CliError(`${target} already exists. Pass --force to overwrite it.`);
|
|
3294
3861
|
}
|
|
3295
|
-
if (!await isExistingDirectory(
|
|
3296
|
-
throw new CliError(`${
|
|
3862
|
+
if (!await isExistingDirectory(dirname4(target))) {
|
|
3863
|
+
throw new CliError(`${dirname4(target)} does not exist.`);
|
|
3297
3864
|
}
|
|
3298
3865
|
let pulled = false;
|
|
3299
3866
|
if (!await isInstalled(client, engine, id)) {
|
|
@@ -3367,15 +3934,28 @@ function progressWriter(stream, options = {}) {
|
|
|
3367
3934
|
stream.write(text);
|
|
3368
3935
|
};
|
|
3369
3936
|
}
|
|
3370
|
-
const intervalMs = options.intervalMs ??
|
|
3937
|
+
const intervalMs = options.intervalMs ?? 6e4;
|
|
3371
3938
|
const now = options.now ?? Date.now;
|
|
3372
3939
|
let lastLine = "";
|
|
3373
3940
|
let lastAt = Number.NEGATIVE_INFINITY;
|
|
3941
|
+
let series;
|
|
3374
3942
|
return (text) => {
|
|
3375
3943
|
const finished = text.endsWith("\n");
|
|
3376
3944
|
const line = text.replace(/\r/g, "").trim();
|
|
3377
3945
|
if (!line || line === lastLine) return;
|
|
3378
|
-
if (
|
|
3946
|
+
if (finished) {
|
|
3947
|
+
series = void 0;
|
|
3948
|
+
} else {
|
|
3949
|
+
const percent = /(\d{1,3})%/.exec(line);
|
|
3950
|
+
if (percent) {
|
|
3951
|
+
const label = line.slice(0, percent.index).replace(/\d+/g, "#").trim();
|
|
3952
|
+
const quarter = Math.floor(Number(percent[1]) / 25);
|
|
3953
|
+
if (series?.label === label && (quarter <= series.quarter || quarter > 3)) return;
|
|
3954
|
+
series = { label, quarter };
|
|
3955
|
+
} else if (now() - lastAt < intervalMs) {
|
|
3956
|
+
return;
|
|
3957
|
+
}
|
|
3958
|
+
}
|
|
3379
3959
|
stream.write(`${line}
|
|
3380
3960
|
`);
|
|
3381
3961
|
lastLine = line;
|
|
@@ -3443,11 +4023,26 @@ async function resolveRunGezel(client, ref) {
|
|
|
3443
4023
|
const candidates = gezels.filter((gezel) => match.labels.includes(gezel.name));
|
|
3444
4024
|
throw ambiguous(ref, candidates);
|
|
3445
4025
|
}
|
|
3446
|
-
throw new CliError(`No
|
|
4026
|
+
throw new CliError(`No crew member matches "${ref}". Run \`gezel agent list\` to see your crew.`);
|
|
4027
|
+
}
|
|
4028
|
+
async function resolveCrewMember(client, ref) {
|
|
4029
|
+
const wanted = ref.trim();
|
|
4030
|
+
const { gezels } = await client.listGezels();
|
|
4031
|
+
const byId = gezels.find((gezel) => gezel.id === wanted);
|
|
4032
|
+
if (byId) return byId.id;
|
|
4033
|
+
const query = wanted.toLowerCase();
|
|
4034
|
+
const sameName = gezels.filter((gezel) => gezel.name.trim().toLowerCase() === query);
|
|
4035
|
+
if (sameName.length === 1) return sameName[0].id;
|
|
4036
|
+
if (sameName.length > 1) throw ambiguous(ref, sameName);
|
|
4037
|
+
throw new CliError(
|
|
4038
|
+
`No crew member with the id or name "${ref}". Run \`gezel agent list\` to see your crew.`
|
|
4039
|
+
);
|
|
3447
4040
|
}
|
|
3448
4041
|
function ambiguous(ref, candidates) {
|
|
3449
4042
|
const listed = candidates.map((gezel) => `${gezel.name} (${gezel.id})`).join(", ");
|
|
3450
|
-
return new CliError(
|
|
4043
|
+
return new CliError(
|
|
4044
|
+
`"${ref}" matches more than one crew member: ${listed}. Pass the id instead.`
|
|
4045
|
+
);
|
|
3451
4046
|
}
|
|
3452
4047
|
|
|
3453
4048
|
// src/run-progress.ts
|
|
@@ -3510,15 +4105,47 @@ var RunProgress = class {
|
|
|
3510
4105
|
};
|
|
3511
4106
|
|
|
3512
4107
|
// src/run-prompt.ts
|
|
3513
|
-
|
|
4108
|
+
import { fstatSync } from "fs";
|
|
4109
|
+
var PIPED_FIRST_DATA_MS = 200;
|
|
4110
|
+
var S_IFMT = 61440;
|
|
4111
|
+
var S_IFREG = 32768;
|
|
4112
|
+
var S_IFIFO = 4096;
|
|
4113
|
+
var S_IFSOCK = 49152;
|
|
4114
|
+
function detectStdinKind(stat2 = fstatSync, isTTY = process.stdin.isTTY) {
|
|
4115
|
+
if (isTTY) return "tty";
|
|
4116
|
+
let type;
|
|
4117
|
+
try {
|
|
4118
|
+
type = stat2(0).mode & S_IFMT;
|
|
4119
|
+
} catch {
|
|
4120
|
+
return "none";
|
|
4121
|
+
}
|
|
4122
|
+
if (type === S_IFREG) return "file";
|
|
4123
|
+
if (type === S_IFIFO || type === S_IFSOCK) return "pipe";
|
|
4124
|
+
return "none";
|
|
4125
|
+
}
|
|
4126
|
+
async function resolveRunPrompt(parts, input = process.stdin, options = {}) {
|
|
3514
4127
|
if (parts?.length !== 1 || parts[0] !== "-") {
|
|
3515
4128
|
const prompt2 = (parts ?? []).join(" ").trim();
|
|
3516
4129
|
if (!prompt2) throw new CliError('usage: gezel run "<prompt>" or gezel run -');
|
|
3517
|
-
|
|
4130
|
+
const kind = options.stdinKind ?? (input === process.stdin ? detectStdinKind() : input.isTTY ? "tty" : "none");
|
|
4131
|
+
if (kind !== "file" && kind !== "pipe") return prompt2;
|
|
4132
|
+
const piped = await readPiped(
|
|
4133
|
+
input,
|
|
4134
|
+
kind === "pipe" ? options.firstDataMs ?? PIPED_FIRST_DATA_MS : void 0
|
|
4135
|
+
);
|
|
4136
|
+
return piped?.trim() ? `${prompt2}
|
|
4137
|
+
|
|
4138
|
+
${piped}` : prompt2;
|
|
3518
4139
|
}
|
|
3519
4140
|
if (input.isTTY) {
|
|
3520
4141
|
throw new CliError("gezel run - requires piped input or a redirected file.");
|
|
3521
4142
|
}
|
|
4143
|
+
const prompt = await readAll(input);
|
|
4144
|
+
if (!prompt.trim())
|
|
4145
|
+
throw new CliError("gezel run - received empty input. Supply a prompt on stdin.");
|
|
4146
|
+
return prompt;
|
|
4147
|
+
}
|
|
4148
|
+
async function readAll(input) {
|
|
3522
4149
|
const chunks = [];
|
|
3523
4150
|
try {
|
|
3524
4151
|
for await (const chunk of input) {
|
|
@@ -3529,10 +4156,54 @@ async function resolveRunPrompt(parts, input = process.stdin) {
|
|
|
3529
4156
|
`Could not read prompt from stdin: ${error instanceof Error ? error.message : String(error)}`
|
|
3530
4157
|
);
|
|
3531
4158
|
}
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
4159
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
4160
|
+
}
|
|
4161
|
+
async function readPiped(input, firstDataMs) {
|
|
4162
|
+
const iterator = input[Symbol.asyncIterator]();
|
|
4163
|
+
let first;
|
|
4164
|
+
try {
|
|
4165
|
+
if (firstDataMs === void 0) {
|
|
4166
|
+
first = await iterator.next();
|
|
4167
|
+
} else {
|
|
4168
|
+
let timer;
|
|
4169
|
+
const silent = new Promise((resolve7) => {
|
|
4170
|
+
timer = setTimeout(() => resolve7("silent"), firstDataMs);
|
|
4171
|
+
});
|
|
4172
|
+
const next = iterator.next();
|
|
4173
|
+
const result = await Promise.race([next, silent]).finally(() => clearTimeout(timer));
|
|
4174
|
+
if (result === "silent") {
|
|
4175
|
+
next.catch(() => {
|
|
4176
|
+
});
|
|
4177
|
+
letGo(input);
|
|
4178
|
+
return void 0;
|
|
4179
|
+
}
|
|
4180
|
+
first = result;
|
|
4181
|
+
}
|
|
4182
|
+
} catch (error) {
|
|
4183
|
+
throw new CliError(
|
|
4184
|
+
`Could not read the piped text from stdin: ${error instanceof Error ? error.message : String(error)}`
|
|
4185
|
+
);
|
|
4186
|
+
}
|
|
4187
|
+
if (first.done) return void 0;
|
|
4188
|
+
const chunks = [toBuffer(first.value)];
|
|
4189
|
+
try {
|
|
4190
|
+
for (let next = await iterator.next(); !next.done; next = await iterator.next()) {
|
|
4191
|
+
chunks.push(toBuffer(next.value));
|
|
4192
|
+
}
|
|
4193
|
+
} catch (error) {
|
|
4194
|
+
throw new CliError(
|
|
4195
|
+
`Could not read the piped text from stdin: ${error instanceof Error ? error.message : String(error)}`
|
|
4196
|
+
);
|
|
4197
|
+
}
|
|
4198
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
4199
|
+
}
|
|
4200
|
+
function toBuffer(chunk) {
|
|
4201
|
+
return Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
4202
|
+
}
|
|
4203
|
+
function letGo(input) {
|
|
4204
|
+
const stream = input;
|
|
4205
|
+
stream.pause?.();
|
|
4206
|
+
stream.unref?.();
|
|
3536
4207
|
}
|
|
3537
4208
|
|
|
3538
4209
|
// src/run-reply.ts
|
|
@@ -3952,7 +4623,7 @@ function formatBackupPlan(plan) {
|
|
|
3952
4623
|
byKind.set(item.kind, bucket);
|
|
3953
4624
|
}
|
|
3954
4625
|
const labels = {
|
|
3955
|
-
gezel: "
|
|
4626
|
+
gezel: "crew members",
|
|
3956
4627
|
project: "projects",
|
|
3957
4628
|
"document-root": "documents",
|
|
3958
4629
|
"memory-root": "memories about you",
|
|
@@ -3974,7 +4645,8 @@ function formatRestoreReview(review) {
|
|
|
3974
4645
|
];
|
|
3975
4646
|
for (const item of review.items) {
|
|
3976
4647
|
const flag = item.conflict === "exists" ? " [already here]" : "";
|
|
3977
|
-
|
|
4648
|
+
const kind = item.kind === "gezel" ? "crew member" : item.kind;
|
|
4649
|
+
lines.push(` ${pad(formatBytes2(item.bytes), 10)} ${kind}: ${item.label}${flag}`);
|
|
3978
4650
|
}
|
|
3979
4651
|
if (review.items.length === 0) lines.push(" (this backup is empty)");
|
|
3980
4652
|
if (review.warnings.length > 0) {
|
|
@@ -4003,23 +4675,32 @@ function resolveRestoreSelection(review, opts) {
|
|
|
4003
4675
|
}
|
|
4004
4676
|
|
|
4005
4677
|
// src/task-output.ts
|
|
4006
|
-
import {
|
|
4007
|
-
import {
|
|
4678
|
+
import { constants } from "fs";
|
|
4679
|
+
import { access, mkdir as mkdir3, writeFile as writeFile4 } from "fs/promises";
|
|
4680
|
+
import { dirname as dirname5, isAbsolute as isAbsolute2, join as join4, relative, resolve as resolve5, sep } from "path";
|
|
4681
|
+
import { taskDeliverableCandidates } from "@bendyline/gezel";
|
|
4682
|
+
function madeFiles(files, artifactDir) {
|
|
4683
|
+
const made = [];
|
|
4684
|
+
for (const file of files) {
|
|
4685
|
+
if (file.isDirectory) continue;
|
|
4686
|
+
const name = relative(artifactDir, file.path).split(sep).join("/");
|
|
4687
|
+
if (!name || name.startsWith("..") || isAbsolute2(name)) continue;
|
|
4688
|
+
if (name === "inputs" || name.startsWith("inputs/")) continue;
|
|
4689
|
+
made.push({ path: file.path, name });
|
|
4690
|
+
}
|
|
4691
|
+
return made;
|
|
4692
|
+
}
|
|
4008
4693
|
async function copyTaskOutput(client, projectId, artifactDir, outDir) {
|
|
4009
4694
|
const root = resolve5(outDir);
|
|
4010
4695
|
const listing = await client.listProjectArtifacts(projectId, artifactDir, true);
|
|
4011
4696
|
const copied = [];
|
|
4012
|
-
for (const
|
|
4013
|
-
|
|
4014
|
-
const rel = relative(artifactDir, file.path).split(sep).join("/");
|
|
4015
|
-
if (!rel || rel.startsWith("..") || isAbsolute2(rel)) continue;
|
|
4016
|
-
if (rel === "inputs" || rel.startsWith("inputs/")) continue;
|
|
4017
|
-
const target = join4(root, rel);
|
|
4697
|
+
for (const { path, name } of madeFiles(listing.files, artifactDir)) {
|
|
4698
|
+
const target = join4(root, name);
|
|
4018
4699
|
if (relative(root, target).startsWith("..")) continue;
|
|
4019
|
-
const blob = await client.fetchProjectArtifactBlob(projectId,
|
|
4020
|
-
await mkdir3(
|
|
4700
|
+
const blob = await client.fetchProjectArtifactBlob(projectId, path);
|
|
4701
|
+
await mkdir3(dirname5(target), { recursive: true });
|
|
4021
4702
|
await writeFile4(target, Buffer.from(await blob.arrayBuffer()));
|
|
4022
|
-
copied.push(
|
|
4703
|
+
copied.push(name);
|
|
4023
4704
|
}
|
|
4024
4705
|
if (listing.truncated) {
|
|
4025
4706
|
throw new CliError(
|
|
@@ -4028,6 +4709,113 @@ async function copyTaskOutput(client, projectId, artifactDir, outDir) {
|
|
|
4028
4709
|
}
|
|
4029
4710
|
return copied;
|
|
4030
4711
|
}
|
|
4712
|
+
var LOCATE_LIMIT = 100;
|
|
4713
|
+
async function describeTaskOutput(client, task2, canRead = readableHere) {
|
|
4714
|
+
const folderRelativePath = task2.artifactDir ?? null;
|
|
4715
|
+
const made = folderRelativePath ? madeFiles(
|
|
4716
|
+
(await client.listProjectArtifacts(task2.projectId, folderRelativePath, true)).files,
|
|
4717
|
+
folderRelativePath
|
|
4718
|
+
) : [];
|
|
4719
|
+
const madePaths = new Set(made.map((file) => file.path.toLowerCase()));
|
|
4720
|
+
const locate = async (file) => client.resolveReferenceFileLocation(task2.projectId, file).then((located) => located.path).catch(() => null);
|
|
4721
|
+
let deliverable = null;
|
|
4722
|
+
for (const candidate of taskDeliverableCandidates(
|
|
4723
|
+
task2,
|
|
4724
|
+
made.map((file) => ({ kind: "artifact", path: file.path }))
|
|
4725
|
+
).slice(0, 5)) {
|
|
4726
|
+
if (candidate.kind === "artifact") {
|
|
4727
|
+
if (!madePaths.has(candidate.path.toLowerCase())) continue;
|
|
4728
|
+
deliverable = { file: candidate, path: await locate(candidate) };
|
|
4729
|
+
break;
|
|
4730
|
+
}
|
|
4731
|
+
const path = await locate(candidate);
|
|
4732
|
+
if (path) {
|
|
4733
|
+
deliverable = { file: candidate, path };
|
|
4734
|
+
break;
|
|
4735
|
+
}
|
|
4736
|
+
}
|
|
4737
|
+
const files = [];
|
|
4738
|
+
const add = async (file, path, isDeliverable) => files.push({
|
|
4739
|
+
kind: file.kind,
|
|
4740
|
+
relativePath: file.path,
|
|
4741
|
+
path,
|
|
4742
|
+
readable: path !== null && await canRead(path),
|
|
4743
|
+
deliverable: isDeliverable
|
|
4744
|
+
});
|
|
4745
|
+
if (deliverable) await add(deliverable.file, deliverable.path, true);
|
|
4746
|
+
let folder = null;
|
|
4747
|
+
for (const file of made) {
|
|
4748
|
+
const ref = { kind: "artifact", path: file.path };
|
|
4749
|
+
if (deliverable?.file.kind === "artifact" && sameFile(deliverable.file.path, file.path)) {
|
|
4750
|
+
folder ??= hostFolder(deliverable.path, file.name);
|
|
4751
|
+
continue;
|
|
4752
|
+
}
|
|
4753
|
+
const path = files.length < LOCATE_LIMIT ? await locate(ref) : null;
|
|
4754
|
+
folder ??= hostFolder(path, file.name);
|
|
4755
|
+
await add(ref, path, false);
|
|
4756
|
+
}
|
|
4757
|
+
return {
|
|
4758
|
+
folderRelativePath,
|
|
4759
|
+
folder,
|
|
4760
|
+
folderReadable: folder !== null && await canRead(folder),
|
|
4761
|
+
files
|
|
4762
|
+
};
|
|
4763
|
+
}
|
|
4764
|
+
function withCopiedOutput(output, outDir) {
|
|
4765
|
+
const folder = resolve5(outDir);
|
|
4766
|
+
const prefix = output.folderRelativePath ? `${output.folderRelativePath}/` : null;
|
|
4767
|
+
return {
|
|
4768
|
+
...output,
|
|
4769
|
+
folder,
|
|
4770
|
+
folderReadable: true,
|
|
4771
|
+
files: output.files.map(
|
|
4772
|
+
(file) => file.kind === "artifact" && prefix && file.relativePath.startsWith(prefix) ? {
|
|
4773
|
+
...file,
|
|
4774
|
+
path: join4(folder, ...file.relativePath.slice(prefix.length).split("/")),
|
|
4775
|
+
readable: true
|
|
4776
|
+
} : file
|
|
4777
|
+
)
|
|
4778
|
+
};
|
|
4779
|
+
}
|
|
4780
|
+
function formatTaskOutput(output, ref, opts = {}) {
|
|
4781
|
+
const lines = [];
|
|
4782
|
+
const result = output.files.find((file) => file.deliverable);
|
|
4783
|
+
if (result) {
|
|
4784
|
+
lines.push(
|
|
4785
|
+
result.readable && result.path ? `Result: ${result.path}` : `Result: ${result.relativePath}, kept by the Gezel service`
|
|
4786
|
+
);
|
|
4787
|
+
}
|
|
4788
|
+
const prefix = output.folderRelativePath ? `${output.folderRelativePath}/` : "";
|
|
4789
|
+
const others = output.files.filter((file) => !file.deliverable && file.kind === "artifact").map(
|
|
4790
|
+
(file) => prefix && file.relativePath.startsWith(prefix) ? file.relativePath.slice(prefix.length) : file.relativePath
|
|
4791
|
+
);
|
|
4792
|
+
if (others.length > 0) {
|
|
4793
|
+
const shown = others.length > 6 ? [...others.slice(0, 5), `and ${others.length - 5} more`] : others;
|
|
4794
|
+
lines.push(`${result ? "Also made" : "Made"}: ${shown.join(", ")}`);
|
|
4795
|
+
}
|
|
4796
|
+
const inFolder = output.files.some((file) => file.kind === "artifact");
|
|
4797
|
+
if (inFolder && output.folder && output.folderReadable) lines.push(`Folder: ${output.folder}`);
|
|
4798
|
+
const hint = inFolder && !opts.copied ? `${output.folderReadable ? "Copy them next to you" : "They are kept by the Gezel service; copy them here"} with \`gezel task wait ${ref} --out <folder>\`.` : null;
|
|
4799
|
+
return { lines, hint };
|
|
4800
|
+
}
|
|
4801
|
+
function sameFile(a, b) {
|
|
4802
|
+
return a.toLowerCase() === b.toLowerCase();
|
|
4803
|
+
}
|
|
4804
|
+
function hostFolder(path, nameInFolder) {
|
|
4805
|
+
if (!path) return null;
|
|
4806
|
+
let end = path.length;
|
|
4807
|
+
for (let depth = nameInFolder.split("/").length; depth > 0; depth -= 1) {
|
|
4808
|
+
end = Math.max(path.lastIndexOf("/", end - 1), path.lastIndexOf("\\", end - 1));
|
|
4809
|
+
if (end <= 0) return null;
|
|
4810
|
+
}
|
|
4811
|
+
return path.slice(0, end);
|
|
4812
|
+
}
|
|
4813
|
+
async function readableHere(path) {
|
|
4814
|
+
return access(path, constants.R_OK).then(
|
|
4815
|
+
() => true,
|
|
4816
|
+
() => false
|
|
4817
|
+
);
|
|
4818
|
+
}
|
|
4031
4819
|
|
|
4032
4820
|
// src/unknown-command.ts
|
|
4033
4821
|
function unknownCommandMessage(operands, known) {
|
|
@@ -4110,7 +4898,7 @@ async function runWorkflow(client, projectId, workspace, file, args, log = conso
|
|
|
4110
4898
|
...params ? { params } : {},
|
|
4111
4899
|
...book?.paramSchema ? { paramSchema: book.paramSchema } : {},
|
|
4112
4900
|
prompter: terminalPrompter(),
|
|
4113
|
-
write: (
|
|
4901
|
+
write: stderrProgress()
|
|
4114
4902
|
});
|
|
4115
4903
|
return module.run({
|
|
4116
4904
|
client,
|
|
@@ -4189,7 +4977,7 @@ Install Node.js ${MINIMUM_NODE_MAJOR} or later from https://nodejs.org, then run
|
|
|
4189
4977
|
|
|
4190
4978
|
// src/bin/gezel.ts
|
|
4191
4979
|
var program = new Command();
|
|
4192
|
-
program.name("gezel").description("Gezel \u2014
|
|
4980
|
+
program.name("gezel").description("Gezel \u2014 put AI to work on your files and projects, from your own computer.").addHelpText(
|
|
4193
4981
|
"after",
|
|
4194
4982
|
"\nAny craftbook also runs by name: `gezel <craftbook> \u2026` is `gezel do <craftbook> \u2026`."
|
|
4195
4983
|
).version(GEZEL_VERSION).option(
|
|
@@ -4203,7 +4991,7 @@ program.name("gezel").description("Gezel \u2014 assemble a team of AI companions
|
|
|
4203
4991
|
"Use this folder as the active project (default and bare flag: cwd)."
|
|
4204
4992
|
).option(
|
|
4205
4993
|
"--download",
|
|
4206
|
-
"Download what a command needs (the on-device engine and the recommended model) without asking, printing each step. Also GEZEL_AUTO_DOWNLOAD=1."
|
|
4994
|
+
"Download what a command needs (the on-device engine and the recommended model, or DuckDB for knowledge export-parquet) without asking, printing each step. Also GEZEL_AUTO_DOWNLOAD=1."
|
|
4207
4995
|
);
|
|
4208
4996
|
var cliGlobals = () => program.opts();
|
|
4209
4997
|
var connectForInspection = (opts) => opts.start === false ? connectRunning(cliGlobals()) : connectOwned(cliGlobals());
|
|
@@ -4706,15 +5494,19 @@ program.command("mode [mode]").description("Show or set AI activity (read-only,
|
|
|
4706
5494
|
const current = cliEngagementModeOption(updated.aiEngagementMode);
|
|
4707
5495
|
console.log(`AI mode \u2192 ${current.name} \u2014 ${current.description}`);
|
|
4708
5496
|
});
|
|
4709
|
-
program.command("run [prompt...]").description("
|
|
5497
|
+
program.command("run [prompt...]").description("Send a prompt to Gezel and print the reply (use - to read stdin)").option("-g, --gezel <ref>", "crew member id or name (default: this project's crew lead)").addHelpText(
|
|
4710
5498
|
"after",
|
|
4711
5499
|
`
|
|
4712
5500
|
Examples:
|
|
4713
5501
|
gezel run "Summarize this project"
|
|
5502
|
+
gezel run "Summarize these notes" < notes.txt
|
|
4714
5503
|
printf 'Summarize these notes:\\nThe launch is Friday.\\n' | gezel run -
|
|
4715
5504
|
gezel run - < prompt.txt
|
|
4716
5505
|
|
|
4717
5506
|
A sole - reads UTF-8 stdin to EOF. Empty input is rejected.
|
|
5507
|
+
With a prompt, text piped or redirected to stdin is sent after it,
|
|
5508
|
+
separated by a blank line. A pipe that sends nothing within a moment is
|
|
5509
|
+
left unread; use - to wait for a slow one.
|
|
4718
5510
|
Replies go to stdout; diagnostics go to stderr.
|
|
4719
5511
|
With no model set up yet, a run in a terminal first offers to download one,
|
|
4720
5512
|
then runs the prompt.`
|
|
@@ -4740,7 +5532,7 @@ then runs the prompt.`
|
|
|
4740
5532
|
const gezelId = opts.gezel ? await resolveRunGezel(client, opts.gezel) : await ensureCliProjectLead(client, projectId);
|
|
4741
5533
|
let readiness = await checkRunReadiness(client, gezelId);
|
|
4742
5534
|
if (!readiness.ready && autoDownloadRequested(cliGlobals())) {
|
|
4743
|
-
await downloadForRun(client, { gezelId, write: (
|
|
5535
|
+
await downloadForRun(client, { gezelId, write: stderrProgress() });
|
|
4744
5536
|
readiness = await checkRunReadiness(client, gezelId);
|
|
4745
5537
|
} else if (!readiness.ready && canOfferRunSetup()) {
|
|
4746
5538
|
const tuiModule = "../tui/index.js";
|
|
@@ -4812,10 +5604,17 @@ program.command("do <craftbook...>").description(
|
|
|
4812
5604
|
`
|
|
4813
5605
|
Bare values fill the craftbook's required parameters in order; key=value sets any
|
|
4814
5606
|
parameter; every other word is your request, which becomes the task description.
|
|
4815
|
-
\`gezel craftbook list\` shows the craftbooks you can start here
|
|
5607
|
+
\`gezel craftbook list\` shows the craftbooks you can start here, and
|
|
5608
|
+
\`gezel craftbook show <craftbook>\` what one takes and where it saves.
|
|
5609
|
+
|
|
5610
|
+
A folder Gezel was pointed at starts read-only. A craftbook that saves into the
|
|
5611
|
+
folder asks first at a terminal; in a script, add --allow-edits.
|
|
5612
|
+
|
|
5613
|
+
When a task completes, --wait prints where its result is; --out <dir> also
|
|
5614
|
+
copies everything it made into that folder.
|
|
4816
5615
|
|
|
4817
5616
|
Examples:
|
|
4818
|
-
gezel do summarize-long "Summarize notes.txt for the board"
|
|
5617
|
+
gezel do summarize-long "Summarize notes.txt for the board" --out ./board-summary
|
|
4819
5618
|
gezel do ship feature/login --wait
|
|
4820
5619
|
gezel do powerpoint-deck "A deck about Delft" audience=investors`
|
|
4821
5620
|
).option(
|
|
@@ -4824,6 +5623,9 @@ Examples:
|
|
|
4824
5623
|
(value, values) => [...values, value],
|
|
4825
5624
|
[]
|
|
4826
5625
|
).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(
|
|
5626
|
+
"--allow-edits",
|
|
5627
|
+
"let Gezel change files in this project's folder, when the craftbook saves into it"
|
|
5628
|
+
).option(
|
|
4827
5629
|
"--strict-sandbox",
|
|
4828
5630
|
"require OS network isolation for custom scripts (CLI launches otherwise trust this recipe snapshot)"
|
|
4829
5631
|
).addOption(new Option(SHORTHAND_FLAG).hideHelp()).action(
|
|
@@ -4904,23 +5706,24 @@ Examples:
|
|
|
4904
5706
|
return;
|
|
4905
5707
|
}
|
|
4906
5708
|
await setUp();
|
|
5709
|
+
await ensureProjectEdits(client, {
|
|
5710
|
+
projectId,
|
|
5711
|
+
craftbook: craftbook2,
|
|
5712
|
+
allow: opts.allowEdits === true,
|
|
5713
|
+
prompter: terminalPrompter(),
|
|
5714
|
+
write: stderrProgress()
|
|
5715
|
+
});
|
|
4907
5716
|
const created = await client.createTask(projectId, {
|
|
4908
5717
|
...craftbookStartRequest(book),
|
|
4909
5718
|
...craftbookDoLaunch(craftbook2, parsed),
|
|
4910
5719
|
trustScripts: !opts.strictSandbox,
|
|
4911
5720
|
roleBasedNameOnlyMode: true
|
|
5721
|
+
}).catch((err) => {
|
|
5722
|
+
throw taskInputFailure(err, book, parsed.params) ?? err;
|
|
4912
5723
|
});
|
|
4913
5724
|
if (opts.wait || opts.out) {
|
|
4914
5725
|
console.error(`started ${created.ref} \u2014 ${created.title}`);
|
|
4915
|
-
|
|
4916
|
-
if (opts.out && waited.outcome === "complete") {
|
|
4917
|
-
const dir = waited.task.artifactDir;
|
|
4918
|
-
if (!dir) throw new CliError(`${created.ref} finished without a task folder to copy.`);
|
|
4919
|
-
const copied = await copyTaskOutput(client, projectId, dir, opts.out);
|
|
4920
|
-
console.error(
|
|
4921
|
-
`copied ${copied.length} file${copied.length === 1 ? "" : "s"} to ${opts.out}`
|
|
4922
|
-
);
|
|
4923
|
-
}
|
|
5726
|
+
await printTaskWait(client, created.ref, { ...opts, timeoutMs });
|
|
4924
5727
|
} else
|
|
4925
5728
|
console.log(
|
|
4926
5729
|
opts.json ? JSON.stringify(created) : `started ${created.ref} \u2014 ${created.title}`
|
|
@@ -4953,16 +5756,54 @@ function printWorkflowResult(result, json) {
|
|
|
4953
5756
|
async function printTaskWait(client, ref, opts) {
|
|
4954
5757
|
const result = await waitForTask(client, ref, {
|
|
4955
5758
|
timeoutMs: opts.timeoutMs,
|
|
4956
|
-
onProgress: (task2) =>
|
|
4957
|
-
|
|
4958
|
-
|
|
5759
|
+
onProgress: (task2) => {
|
|
5760
|
+
if (task2.status === "complete" || task2.status === "canceled") return;
|
|
5761
|
+
console.error(
|
|
5762
|
+
`${task2.ref}: ${task2.status}${task2.activeStepId ? ` (${task2.activeStepId})` : ""}`
|
|
5763
|
+
);
|
|
5764
|
+
}
|
|
4959
5765
|
});
|
|
4960
|
-
const reason = await
|
|
4961
|
-
|
|
4962
|
-
|
|
4963
|
-
)
|
|
5766
|
+
const { reason, hint } = await blockedTaskDetails(client, result);
|
|
5767
|
+
let copied;
|
|
5768
|
+
let output;
|
|
5769
|
+
if (result.outcome === "complete") {
|
|
5770
|
+
if (opts.out) {
|
|
5771
|
+
const dir = result.task.artifactDir;
|
|
5772
|
+
if (!dir) throw new CliError(`${result.task.ref} finished without a task folder to copy.`);
|
|
5773
|
+
const files = await copyTaskOutput(client, result.task.projectId, dir, opts.out);
|
|
5774
|
+
copied = { folder: resolvePath(opts.out), files };
|
|
5775
|
+
if (!opts.json)
|
|
5776
|
+
console.error(
|
|
5777
|
+
`copied ${files.length} file${files.length === 1 ? "" : "s"} to ${copied.folder}`
|
|
5778
|
+
);
|
|
5779
|
+
}
|
|
5780
|
+
output = await describeTaskOutput(client, result.task).catch(() => void 0);
|
|
5781
|
+
}
|
|
5782
|
+
if (opts.json) {
|
|
5783
|
+
console.log(
|
|
5784
|
+
JSON.stringify({
|
|
5785
|
+
...result,
|
|
5786
|
+
...reason ? { reason } : {},
|
|
5787
|
+
...hint ? { hint } : {},
|
|
5788
|
+
...output ? { output } : {},
|
|
5789
|
+
...copied ? { copied } : {}
|
|
5790
|
+
})
|
|
5791
|
+
);
|
|
5792
|
+
} else {
|
|
5793
|
+
console.log(`${result.task.ref}: ${result.outcome}`);
|
|
5794
|
+
if (output) {
|
|
5795
|
+
const shown = formatTaskOutput(
|
|
5796
|
+
copied ? withCopiedOutput(output, copied.folder) : output,
|
|
5797
|
+
result.task.ref,
|
|
5798
|
+
{ copied: copied !== void 0 }
|
|
5799
|
+
);
|
|
5800
|
+
for (const line of shown.lines) console.log(line);
|
|
5801
|
+
if (shown.hint) console.error(shown.hint);
|
|
5802
|
+
}
|
|
5803
|
+
}
|
|
4964
5804
|
if (!opts.json && result.outcome === "blocked") {
|
|
4965
5805
|
if (reason) console.error(reason);
|
|
5806
|
+
if (hint) console.error(hint);
|
|
4966
5807
|
console.error(`See its notes with \`gezel task notes ${result.task.ref}\`.`);
|
|
4967
5808
|
}
|
|
4968
5809
|
process.exitCode = result.exitCode;
|
|
@@ -5005,17 +5846,38 @@ craftbook.command("list [words...]").description(
|
|
|
5005
5846
|
}
|
|
5006
5847
|
const width = Math.min(32, Math.max(...books.map((book) => book.command.length)) + 2);
|
|
5007
5848
|
for (const book of books) console.log(`${book.command.padEnd(width)}${book.name}`);
|
|
5008
|
-
console.error(
|
|
5009
|
-
|
|
5849
|
+
console.error(
|
|
5850
|
+
`
|
|
5851
|
+
Start one with \`gezel do <command> "<your request>"\`. \`gezel craftbook show <command>\` says what it takes first.`
|
|
5852
|
+
);
|
|
5853
|
+
});
|
|
5854
|
+
craftbook.command("show <command...>").description("Show what a craftbook does, what it takes, and the command that starts it").option("--json", "emit the craftbook as JSON").option("--no-start", "Use a running service only; never start one").action(async (words, opts) => {
|
|
5855
|
+
const client = await connectForInspection(opts);
|
|
5856
|
+
const preview = await previewRunProject(client, cliGlobals());
|
|
5857
|
+
const projectId = preview.projectId ?? "default";
|
|
5858
|
+
const [config, result] = await Promise.all([
|
|
5859
|
+
client.getConfig(),
|
|
5860
|
+
client.listProjectCraftbooks(projectId)
|
|
5861
|
+
]);
|
|
5862
|
+
const books = normalizeCraftbooks(result.items, config.showWorkInProgressFeatures === true);
|
|
5863
|
+
const { book, args } = resolveCraftbookInvocation(books, words);
|
|
5864
|
+
if (args.length > 0) throw new CliError(`craftbook not found: ${words.join(" ")}`);
|
|
5865
|
+
const { craftbook: full } = await client.getCraftbook(book.id, {
|
|
5866
|
+
projectId,
|
|
5867
|
+
source: book.source,
|
|
5868
|
+
version: book.version
|
|
5869
|
+
});
|
|
5870
|
+
console.log(opts.json ? JSON.stringify(full) : describeCraftbook(book, full));
|
|
5010
5871
|
});
|
|
5011
|
-
var agent = program.command("agent").description("Manage your
|
|
5012
|
-
agent.command("output-limit <
|
|
5013
|
-
"Show or set one
|
|
5014
|
-
).option("--json", "Output the
|
|
5872
|
+
var agent = program.command("agent").description("Manage your crew (your AI companions)");
|
|
5873
|
+
agent.command("output-limit <crew-member> [tokens]").description(
|
|
5874
|
+
"Show or set one crew member's output-token limit (by id or name), including reasoning; auto clears its override"
|
|
5875
|
+
).option("--json", "Output the override as JSON").action(async (ref, tokens, opts) => {
|
|
5015
5876
|
if (tokens !== void 0 && tokens !== "auto" && (!/^\d+$/.test(tokens) || !Number.isSafeInteger(Number(tokens)) || Number(tokens) < 1)) {
|
|
5016
5877
|
throw new CliError("Output limit must be a positive integer, or auto.");
|
|
5017
5878
|
}
|
|
5018
5879
|
const client = await connectOwned(cliGlobals());
|
|
5880
|
+
const id = await resolveCrewMember(client, ref);
|
|
5019
5881
|
const { parsed } = await client.getGezel(id);
|
|
5020
5882
|
const tuning = { ...parsed.frontmatter.tuning };
|
|
5021
5883
|
const sampling = { ...tuning.sampling };
|
|
@@ -5031,22 +5893,23 @@ agent.command("output-limit <id> [tokens]").description(
|
|
|
5031
5893
|
opts.json ? JSON.stringify(result) : `${id}: ${result.outputTokens === null ? "auto (inherits model/profile defaults)" : `${result.outputTokens} output tokens, including reasoning`}`
|
|
5032
5894
|
);
|
|
5033
5895
|
});
|
|
5034
|
-
agent.command("list").description("List your
|
|
5896
|
+
agent.command("list").description("List your crew").action(async () => {
|
|
5035
5897
|
const client = await connectOwned(cliGlobals());
|
|
5036
5898
|
const res = await client.listGezels();
|
|
5037
5899
|
for (const a of res.gezels) {
|
|
5038
5900
|
console.log(`${a.id.padEnd(20)} ${a.name}`);
|
|
5039
5901
|
}
|
|
5040
5902
|
});
|
|
5041
|
-
agent.command("create <name>").description("
|
|
5903
|
+
agent.command("create <name>").description("Add a crew member").option("-d, --description <text>", "description").option("-m, --model <model>", "model identifier").action(async (name, opts) => {
|
|
5042
5904
|
const client = await connectOwned(cliGlobals());
|
|
5043
5905
|
const created = await client.createGezel({ name, ...opts });
|
|
5044
|
-
console.log(`created
|
|
5906
|
+
console.log(`created crew member ${created.id}`);
|
|
5045
5907
|
});
|
|
5046
|
-
agent.command("show <
|
|
5908
|
+
agent.command("show <crew-member>").description("Show one crew member, by id or name").action(async (ref) => {
|
|
5047
5909
|
const client = await connectOwned(cliGlobals());
|
|
5910
|
+
const id = await resolveCrewMember(client, ref);
|
|
5048
5911
|
const a = await client.getGezel(id).catch((err) => {
|
|
5049
|
-
throw isNotFound(err) ? new CliError(`No
|
|
5912
|
+
throw isNotFound(err) ? new CliError(`No crew member with id "${id}". Run \`gezel agent list\` to see your crew.`) : err;
|
|
5050
5913
|
});
|
|
5051
5914
|
console.log(a.parsed.source);
|
|
5052
5915
|
});
|
|
@@ -5157,8 +6020,8 @@ skills.command("convert <path>").description("Convert a SKILL.md file to a craft
|
|
|
5157
6020
|
for (const note of result.notes) console.error(`note: ${note}`);
|
|
5158
6021
|
if (result.persona) console.error(`persona: ${result.persona.role}`);
|
|
5159
6022
|
});
|
|
5160
|
-
var handboek = program.command("handboek").description("The built-in documentation (
|
|
5161
|
-
handboek.command("export").description("Render
|
|
6023
|
+
var handboek = program.command("handboek").description("The built-in documentation (Help)");
|
|
6024
|
+
handboek.command("export").description("Render Help as a static HTML site for gezel.com (no daemon)").requiredOption("--out <dir>", "output directory").option(
|
|
5162
6025
|
"--css <href>",
|
|
5163
6026
|
"extra stylesheet to link on every page; relative hrefs resolve against the export root. Repeatable.",
|
|
5164
6027
|
(href, prior) => [...prior, href],
|
|
@@ -5197,7 +6060,7 @@ handboek.command("export").description("Render the Handboek as a static HTML sit
|
|
|
5197
6060
|
appsOut: opts.appsOut,
|
|
5198
6061
|
openInGezel: opts.openInGezel === true
|
|
5199
6062
|
});
|
|
5200
|
-
console.log(`
|
|
6063
|
+
console.log(`Help exported: ${result.pages} pages \u2192 ${result.out}`);
|
|
5201
6064
|
if (result.apps) {
|
|
5202
6065
|
console.log(`Apps library: ${result.apps.apps} apps, ${result.apps.demos} with demos`);
|
|
5203
6066
|
}
|
|
@@ -5242,8 +6105,21 @@ knowledge.command("export-parquet <path>").description(
|
|
|
5242
6105
|
"DuckDB CLI to use (default: $GEZEL_DUCKDB_BIN or the one gezel installed)"
|
|
5243
6106
|
).action(async (path, opts) => {
|
|
5244
6107
|
const { runKnowledgeExportParquet } = await loadKnowledgeCommand();
|
|
5245
|
-
await runKnowledgeExportParquet(
|
|
6108
|
+
await runKnowledgeExportParquet(
|
|
6109
|
+
path,
|
|
6110
|
+
opts,
|
|
6111
|
+
autoDownloadRequested(cliGlobals()) ? { fetchDuckdb: fetchDuckdbForCli } : {}
|
|
6112
|
+
);
|
|
5246
6113
|
});
|
|
6114
|
+
async function fetchDuckdbForCli() {
|
|
6115
|
+
process.stderr.write("No DuckDB CLI found; downloading it (--download)\u2026\n");
|
|
6116
|
+
const client = await connectOwned(cliGlobals());
|
|
6117
|
+
const status = await installNativeToolkit(client, {
|
|
6118
|
+
engines: ["duckdb"],
|
|
6119
|
+
output: { writeProgress: stderrProgress() }
|
|
6120
|
+
});
|
|
6121
|
+
return status.engines.find((engine) => engine.name === "duckdb" && engine.installed)?.path;
|
|
6122
|
+
}
|
|
5247
6123
|
knowledge.command("search <path> <query>").description("Search a catalog file offline (full-text; --semantic adds vector search)").option("--semantic", "embed the query with the catalog profile (loads the model)").option("--latitude <degrees>", "radius center latitude", Number).option("--longitude <degrees>", "radius center longitude", Number).option("--radius-meters <meters>", "subject radius in meters", Number).option("--limit <n>", "maximum results", (v) => Number.parseInt(v, 10), 10).action(async (path, query, opts) => {
|
|
5248
6124
|
const { runKnowledgeSearch } = await loadKnowledgeCommand();
|
|
5249
6125
|
await runKnowledgeSearch(path, query, opts);
|
|
@@ -5475,7 +6351,7 @@ for (const verb of ["wait", "resume"]) {
|
|
|
5475
6351
|
"--timeout <seconds>",
|
|
5476
6352
|
"wait budget in seconds; timeout leaves the task running",
|
|
5477
6353
|
"7200"
|
|
5478
|
-
).option("--json", "emit one JSON result on stdout").action(async (ref, opts) => {
|
|
6354
|
+
).option("--out <dir>", "when it completes, copy what the task made into this folder").option("--json", "emit one JSON result on stdout").action(async (ref, opts) => {
|
|
5479
6355
|
const timeoutMs = positiveSeconds(opts.timeout);
|
|
5480
6356
|
const client = await connectOwned(cliGlobals());
|
|
5481
6357
|
if (verb === "resume") {
|
|
@@ -5499,7 +6375,7 @@ task.command("list").description("List tasks across every project").option("-s,
|
|
|
5499
6375
|
);
|
|
5500
6376
|
}
|
|
5501
6377
|
});
|
|
5502
|
-
task.command("create <projectId> <title>").description("Create a task with a single phase").option("-a, --assignee <gezelId>", "
|
|
6378
|
+
task.command("create <projectId> <title>").description("Create a task with a single phase").option("-a, --assignee <gezelId>", "crew member id to assign (default: user)").option("-p, --phase <name>", "first phase name", "Main").option("-d, --description <text>", "task description \u2014 what done looks like (min 40 chars)").action(
|
|
5503
6379
|
async (projectId, title, opts) => {
|
|
5504
6380
|
const description = opts.description ?? `${title} \u2014 fill in the task description. Cover what done looks like, key constraints, and any links the assignee will need.`;
|
|
5505
6381
|
const client = await connectOwned(cliGlobals());
|
|
@@ -5546,114 +6422,7 @@ ${warning.text}`)
|
|
|
5546
6422
|
].join("\n\n") || "(no task notes)"
|
|
5547
6423
|
);
|
|
5548
6424
|
});
|
|
5549
|
-
program
|
|
5550
|
-
async (promptParts, opts) => {
|
|
5551
|
-
const aspect = enumOpt("aspect", opts.aspect, ImageAspectRatioSchema);
|
|
5552
|
-
const quality = enumOpt("quality", opts.quality, ImageQualitySchema);
|
|
5553
|
-
const prompt = await resolvePromptText(promptParts, opts.file, "prompt");
|
|
5554
|
-
const client = await connectOwned(cliGlobals());
|
|
5555
|
-
const projectId = opts.project ?? "default";
|
|
5556
|
-
const width = intOpt("width", opts.width);
|
|
5557
|
-
const height = intOpt("height", opts.height);
|
|
5558
|
-
const steps = intOpt("steps", opts.steps);
|
|
5559
|
-
const seed = intOpt("seed", opts.seed);
|
|
5560
|
-
console.error(`generating image${opts.model ? ` (model ${opts.model})` : ""}...`);
|
|
5561
|
-
let res;
|
|
5562
|
-
try {
|
|
5563
|
-
res = await client.generateImage({
|
|
5564
|
-
prompt,
|
|
5565
|
-
projectId,
|
|
5566
|
-
...opts.model ? { model: opts.model } : {},
|
|
5567
|
-
...opts.negative ? { negativePrompt: opts.negative } : {},
|
|
5568
|
-
...width !== void 0 ? { width } : {},
|
|
5569
|
-
...height !== void 0 ? { height } : {},
|
|
5570
|
-
...aspect ? { aspectRatio: aspect } : {},
|
|
5571
|
-
...quality ? { quality } : {},
|
|
5572
|
-
...steps !== void 0 ? { steps } : {},
|
|
5573
|
-
...seed !== void 0 ? { seed } : {}
|
|
5574
|
-
});
|
|
5575
|
-
} catch (err) {
|
|
5576
|
-
throw new CliError(
|
|
5577
|
-
`image generation failed: ${err instanceof Error ? err.message : String(err)}`
|
|
5578
|
-
);
|
|
5579
|
-
}
|
|
5580
|
-
const dest = await saveArtifact(client, projectId, res.artifactPath, opts.output);
|
|
5581
|
-
const m = res.meta;
|
|
5582
|
-
console.log(dest);
|
|
5583
|
-
console.error(
|
|
5584
|
-
` model=${m.model} seed=${m.seed} steps=${m.steps} size=${m.widthPx}x${m.heightPx} time=${(m.durationMs / 1e3).toFixed(1)}s`
|
|
5585
|
-
);
|
|
5586
|
-
}
|
|
5587
|
-
);
|
|
5588
|
-
program.command("create-video [prompt...]").description("Generate a video from a prompt (or --file) via the configured video engine").option("-f, --file <path>", "read the prompt from a text file instead of the argument").option("-m, --model <id>", "video model catalog id (default: the engine default)").option("-n, --negative <text>", "negative prompt").option("-W, --width <px>", "width in pixels").option("-H, --height <px>", "height in pixels").option("--frames <n>", "number of frames").option("--fps <n>", "frames per second").option("-s, --steps <n>", "sampler steps").option("--seed <n>", "seed for reproducible output").option("-p, --project <id>", "project to write the artifact under", "default").option("-o, --output <path>", "write the video here (default: ./<artifact name>)").action(
|
|
5589
|
-
async (promptParts, opts) => {
|
|
5590
|
-
const prompt = await resolvePromptText(promptParts, opts.file, "prompt");
|
|
5591
|
-
const client = await connectOwned(cliGlobals());
|
|
5592
|
-
const projectId = opts.project ?? "default";
|
|
5593
|
-
const width = intOpt("width", opts.width);
|
|
5594
|
-
const height = intOpt("height", opts.height);
|
|
5595
|
-
const numFrames = intOpt("frames", opts.frames);
|
|
5596
|
-
const fps = intOpt("fps", opts.fps);
|
|
5597
|
-
const steps = intOpt("steps", opts.steps);
|
|
5598
|
-
const seed = intOpt("seed", opts.seed);
|
|
5599
|
-
console.error(
|
|
5600
|
-
`generating video${opts.model ? ` (model ${opts.model})` : ""} \u2014 this can take a while...`
|
|
5601
|
-
);
|
|
5602
|
-
let res;
|
|
5603
|
-
try {
|
|
5604
|
-
res = await client.generateVideo({
|
|
5605
|
-
prompt,
|
|
5606
|
-
projectId,
|
|
5607
|
-
...opts.model ? { model: opts.model } : {},
|
|
5608
|
-
...opts.negative ? { negativePrompt: opts.negative } : {},
|
|
5609
|
-
...width !== void 0 ? { width } : {},
|
|
5610
|
-
...height !== void 0 ? { height } : {},
|
|
5611
|
-
...numFrames !== void 0 ? { numFrames } : {},
|
|
5612
|
-
...fps !== void 0 ? { fps } : {},
|
|
5613
|
-
...steps !== void 0 ? { steps } : {},
|
|
5614
|
-
...seed !== void 0 ? { seed } : {}
|
|
5615
|
-
});
|
|
5616
|
-
} catch (err) {
|
|
5617
|
-
throw new CliError(
|
|
5618
|
-
`video generation failed: ${err instanceof Error ? err.message : String(err)}`
|
|
5619
|
-
);
|
|
5620
|
-
}
|
|
5621
|
-
const dest = await saveArtifact(client, projectId, res.artifactPath, opts.output);
|
|
5622
|
-
const m = res.meta;
|
|
5623
|
-
console.log(dest);
|
|
5624
|
-
console.error(
|
|
5625
|
-
` model=${m.model} seed=${m.seed} ${m.widthPx}x${m.heightPx} frames=${m.numFrames} fps=${m.fps} time=${(m.durationMs / 1e3).toFixed(1)}s`
|
|
5626
|
-
);
|
|
5627
|
-
}
|
|
5628
|
-
);
|
|
5629
|
-
program.command("create-audio [text...]").description("Synthesize speech from text (or --file) via the configured TTS engine").option("-f, --file <path>", "read the text from a file instead of the argument").option("-m, --model <id>", "TTS model catalog id (default: the engine default)").option("--voice <id>", "voice id (default: the model/gezel default)").option("--speed <x>", "speed multiplier, 0.25-4 (default: 1.0)").option("-p, --project <id>", "project to write the artifact under", "default").option("-o, --output <path>", "write the audio here (default: ./<artifact name>)").action(async (textParts, opts) => {
|
|
5630
|
-
const text = await resolvePromptText(textParts, opts.file, "text");
|
|
5631
|
-
const client = await connectOwned(cliGlobals());
|
|
5632
|
-
const projectId = opts.project ?? "default";
|
|
5633
|
-
const speed = floatOpt("speed", opts.speed);
|
|
5634
|
-
console.error("synthesizing speech...");
|
|
5635
|
-
let res;
|
|
5636
|
-
try {
|
|
5637
|
-
res = await client.synthesizeSpeech({
|
|
5638
|
-
text,
|
|
5639
|
-
projectId,
|
|
5640
|
-
...opts.model ? { model: opts.model } : {},
|
|
5641
|
-
...opts.voice ? { voice: opts.voice } : {},
|
|
5642
|
-
...speed !== void 0 ? { speed } : {}
|
|
5643
|
-
});
|
|
5644
|
-
} catch (err) {
|
|
5645
|
-
throw new CliError(
|
|
5646
|
-
`speech synthesis failed: ${err instanceof Error ? err.message : String(err)}`
|
|
5647
|
-
);
|
|
5648
|
-
}
|
|
5649
|
-
if (!res.artifactPath) throw new CliError("speech synthesis returned no saved audio");
|
|
5650
|
-
const dest = await saveArtifact(client, projectId, res.artifactPath, opts.output);
|
|
5651
|
-
const m = res.meta;
|
|
5652
|
-
console.log(dest);
|
|
5653
|
-
console.error(
|
|
5654
|
-
` voice=${m.voice} model=${m.model} ${m.durationSeconds.toFixed(1)}s @ ${m.sampleRate}Hz`
|
|
5655
|
-
);
|
|
5656
|
-
});
|
|
6425
|
+
registerGenerateCommands(program, () => connectOwned(cliGlobals()));
|
|
5657
6426
|
var native = program.command("native").description("Manage native engine binaries");
|
|
5658
6427
|
native.command("install").description(
|
|
5659
6428
|
"Download, verify, and activate the native inference toolkit (or one engine with --engine)"
|
|
@@ -5834,18 +6603,11 @@ model.command("list").description("List downloaded chat models, or with --availa
|
|
|
5834
6603
|
);
|
|
5835
6604
|
return;
|
|
5836
6605
|
}
|
|
5837
|
-
const { models } =
|
|
5838
|
-
|
|
5839
|
-
|
|
5840
|
-
|
|
5841
|
-
|
|
5842
|
-
return;
|
|
5843
|
-
}
|
|
5844
|
-
for (const m of models) {
|
|
5845
|
-
console.log(
|
|
5846
|
-
`${m.id.padEnd(28)} ${(m.approxSizeBytes / 1e9).toFixed(2).padStart(6)} GB ${m.name}`
|
|
5847
|
-
);
|
|
5848
|
-
}
|
|
6606
|
+
const [{ models }, config] = await Promise.all([
|
|
6607
|
+
provider === "mlx" ? client.listMlxModels() : provider === "ds4" ? client.listDs4Models() : client.listLlamaCppModels(),
|
|
6608
|
+
client.getConfig()
|
|
6609
|
+
]);
|
|
6610
|
+
console.log(formatInstalledChatModels(provider, models, config));
|
|
5849
6611
|
});
|
|
5850
6612
|
model.command("pull <id>").description(
|
|
5851
6613
|
"Download a local chat model from the catalog (e.g. qwen3.5-2b-q4, about 1.5 GB; `gezel model list --available` shows what fits)"
|
|
@@ -5853,7 +6615,21 @@ model.command("pull <id>").description(
|
|
|
5853
6615
|
const client = await connectOwned(cliGlobals());
|
|
5854
6616
|
const provider = resolveModelProvider(opts.provider);
|
|
5855
6617
|
const progress = stderrProgress();
|
|
5856
|
-
await
|
|
6618
|
+
await ensureModelEngines(client, [provider], progress);
|
|
6619
|
+
const shared = await findSharedModel(client, provider, id);
|
|
6620
|
+
if (shared) {
|
|
6621
|
+
progress(
|
|
6622
|
+
`${id} is already on this computer in a shared model store, so nothing was downloaded: ${shared.location}
|
|
6623
|
+
`
|
|
6624
|
+
);
|
|
6625
|
+
if (shared.updateAvailable) {
|
|
6626
|
+
progress(
|
|
6627
|
+
"The catalog has a newer version. The Gezel that shares this copy updates it when it updates its models.\n"
|
|
6628
|
+
);
|
|
6629
|
+
}
|
|
6630
|
+
} else {
|
|
6631
|
+
await pullChatModel(client, provider, id, progress);
|
|
6632
|
+
}
|
|
5857
6633
|
if (provider === "mlx") await waitForMlxRuntime(client, progress);
|
|
5858
6634
|
if (await pinPulledModel(client, provider, id) === "pinned") {
|
|
5859
6635
|
process.stderr.write(`${id} is now the default ${provider} model.
|
|
@@ -6022,7 +6798,7 @@ program.command("cleanup").description("Show or reclaim the space Gezel is using
|
|
|
6022
6798
|
console.log(formatCleanupResult(job));
|
|
6023
6799
|
if (job.status === "error") process.exitCode = 1;
|
|
6024
6800
|
});
|
|
6025
|
-
program.command("backup <file>").description("Write your
|
|
6801
|
+
program.command("backup <file>").description("Write your crew, projects, and documents to a backup file").option("--no-workspaces", "Leave project working files out of the backup").option("--dry-run", "Show what would be included without writing the file").action(async (file, opts) => {
|
|
6026
6802
|
const client = await connectOwned(cliGlobals());
|
|
6027
6803
|
const outPath = resolvePath(file);
|
|
6028
6804
|
const excludeWorkspaces = opts.workspaces === false;
|
|
@@ -6041,12 +6817,12 @@ program.command("backup <file>").description("Write your gezels, projects, and d
|
|
|
6041
6817
|
console.log(`
|
|
6042
6818
|
Wrote ${outPath}`);
|
|
6043
6819
|
});
|
|
6044
|
-
program.command("restore <file>").description("Restore
|
|
6820
|
+
program.command("restore <file>").description("Restore your crew, projects, and documents from a backup file").option("--list", "Show what the backup holds without restoring anything").option(
|
|
6045
6821
|
"--only <item...>",
|
|
6046
6822
|
"Restore just these items, by id (repeatable, e.g. --only tamsin roof-survey)"
|
|
6047
6823
|
).option("--replace", "Overwrite items that already exist here").option(
|
|
6048
6824
|
"--settings",
|
|
6049
|
-
"Also restore which
|
|
6825
|
+
"Also restore which crew members hold roles such as the Meester (never providers, folders or security)"
|
|
6050
6826
|
).action(
|
|
6051
6827
|
async (file, opts) => {
|
|
6052
6828
|
const client = await connectOwned(cliGlobals());
|