@bendyline/gezel-cli 1.0.6 → 1.1.0
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 +7 -6
- package/dist/app-author-command.js +465 -0
- package/dist/app-command.js +686 -0
- package/dist/bin/gezel-main.js +529 -44
- package/dist/handboek-export.js +713 -30
- package/dist/knowledge-command.js +395 -0
- package/dist/tui/index.js +417 -82
- package/package.json +10 -9
package/dist/bin/gezel-main.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/bin/gezel.ts
|
|
4
|
-
import { basename as
|
|
5
|
-
import { GEZEL_VERSION } from "@bendyline/gezel";
|
|
4
|
+
import { basename as basename4, isAbsolute as isAbsolutePath, join as joinPath } from "path";
|
|
5
|
+
import { GEZEL_VERSION, getLogOutput, setLogOutput } from "@bendyline/gezel";
|
|
6
6
|
import {
|
|
7
|
+
GezelApiError as GezelApiError2,
|
|
7
8
|
streamChatEvents
|
|
8
9
|
} from "@bendyline/gezel-client";
|
|
9
10
|
import {
|
|
@@ -32,6 +33,7 @@ import {
|
|
|
32
33
|
import {
|
|
33
34
|
GezelApiError,
|
|
34
35
|
GezelClient,
|
|
36
|
+
LiveDaemonUnhealthyError,
|
|
35
37
|
createTrustingFetch,
|
|
36
38
|
discoverOrSpawn,
|
|
37
39
|
electronNativeBinCandidates,
|
|
@@ -167,34 +169,44 @@ function resolveStartPortEnv(portFlag, preferCanonical) {
|
|
|
167
169
|
if (portFlag !== void 0) return String(portFlag);
|
|
168
170
|
return preferCanonical ? void 0 : "0";
|
|
169
171
|
}
|
|
170
|
-
async function
|
|
171
|
-
applyHome(globals);
|
|
172
|
-
const preferred = await connectPreferredService(globals);
|
|
173
|
-
if (preferred) return { kind: "owned", ...preferred };
|
|
172
|
+
async function authorizeLocalOwnedDaemon(deps = {}) {
|
|
174
173
|
try {
|
|
175
|
-
const
|
|
176
|
-
storageKey: localTokenStorageKey(),
|
|
174
|
+
const authorized = await (deps.authorizeOwner ?? authorizeLocalOwner)({
|
|
177
175
|
daemon: {
|
|
176
|
+
daemonEntry: resolveDaemonEntry(import.meta.url),
|
|
178
177
|
spawnIfMissing: false,
|
|
179
178
|
...process.env.GEZEL_HOME ? { home: process.env.GEZEL_HOME } : {}
|
|
180
179
|
}
|
|
181
180
|
});
|
|
182
|
-
|
|
183
|
-
connected,
|
|
184
|
-
"The approved Gezel CLI authorization"
|
|
185
|
-
);
|
|
186
|
-
return { kind: "owned", ...authorized };
|
|
181
|
+
return await (deps.connect ?? defaultConnectAsOwner)(authorized);
|
|
187
182
|
} catch (error) {
|
|
183
|
+
if (error instanceof LiveDaemonUnhealthyError) {
|
|
184
|
+
throw unhealthyLocalDaemonError(error.pid, error.baseUrl);
|
|
185
|
+
}
|
|
188
186
|
if (!(error instanceof GezelSdkError) || error.code !== "daemon_not_running") {
|
|
189
187
|
throw cliGrantError(error, "the local Gezel daemon");
|
|
190
188
|
}
|
|
191
|
-
const runtime = await readRuntime();
|
|
192
|
-
if (runtime && isProcessAlive(runtime.pid)) {
|
|
193
|
-
throw
|
|
194
|
-
`The local Gezel daemon (pid ${runtime.pid}) is running but did not answer at ${runtime.baseUrl}. Stop or repair it before retrying.`
|
|
195
|
-
);
|
|
189
|
+
const runtime = await (deps.readRuntimeFn ?? readRuntime)();
|
|
190
|
+
if (runtime && (deps.isProcessAliveFn ?? isProcessAlive)(runtime.pid)) {
|
|
191
|
+
throw unhealthyLocalDaemonError(runtime.pid, runtime.baseUrl);
|
|
196
192
|
}
|
|
193
|
+
return null;
|
|
197
194
|
}
|
|
195
|
+
}
|
|
196
|
+
function defaultConnectAsOwner(authorized) {
|
|
197
|
+
return connectionFromAuthorization(authorized, "The local Gezel owner authorization");
|
|
198
|
+
}
|
|
199
|
+
function unhealthyLocalDaemonError(pid, baseUrl) {
|
|
200
|
+
return new CliError(
|
|
201
|
+
`The local Gezel daemon (pid ${pid}) is running but did not answer at ${baseUrl}. Stop or repair it before retrying.`
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
async function connectForRun(globals) {
|
|
205
|
+
applyHome(globals);
|
|
206
|
+
const preferred = await connectPreferredService(globals);
|
|
207
|
+
if (preferred) return { kind: "owned", ...preferred };
|
|
208
|
+
const owned = await authorizeLocalOwnedDaemon();
|
|
209
|
+
if (owned) return { kind: "owned", ...owned };
|
|
198
210
|
await prepareStandaloneAssets();
|
|
199
211
|
if (process.env.GEZEL_SKIP_SYSTEM_BOOTSTRAP === void 0) {
|
|
200
212
|
process.env.GEZEL_SKIP_SYSTEM_BOOTSTRAP = "1";
|
|
@@ -230,6 +242,7 @@ async function connectForRun(globals) {
|
|
|
230
242
|
}
|
|
231
243
|
var CLI_APP_ID_PREFIX = "gezel-cli";
|
|
232
244
|
var CLI_APPROVAL_TIMEOUT_SEC = 300;
|
|
245
|
+
var PENDING_GRANT_MINUTES = 10;
|
|
233
246
|
function isSystemProductServiceRole(role) {
|
|
234
247
|
return role === void 0 || role === "legacy-full";
|
|
235
248
|
}
|
|
@@ -385,6 +398,11 @@ function cliGrantError(error, target) {
|
|
|
385
398
|
"The Gezel CLI approval request expired. Run the command again to get a new code."
|
|
386
399
|
);
|
|
387
400
|
}
|
|
401
|
+
if (error.code === "grant_already_pending") {
|
|
402
|
+
return new CliError(
|
|
403
|
+
`An earlier Gezel CLI connection request to ${target} is still waiting to be approved, so a new code cannot be issued yet. Approve or dismiss it in Gezel under Settings \u2192 Connected Apps, or wait ${PENDING_GRANT_MINUTES} minutes for it to expire and run this command again.`
|
|
404
|
+
);
|
|
405
|
+
}
|
|
388
406
|
if (error.code === "daemon_not_running") {
|
|
389
407
|
return new CliError(
|
|
390
408
|
"No local Gezel daemon is running. Start the Gezel app or run `gezel start`, then try again."
|
|
@@ -482,9 +500,6 @@ function fileTokenStorage(storageKey) {
|
|
|
482
500
|
delete: deleteToken
|
|
483
501
|
};
|
|
484
502
|
}
|
|
485
|
-
function localTokenStorageKey() {
|
|
486
|
-
return "local-user-daemon";
|
|
487
|
-
}
|
|
488
503
|
async function ensureProjectForFolder(client, folderPath) {
|
|
489
504
|
const wd = resolve(folderPath);
|
|
490
505
|
const eq = (a, b) => !!a && (process.platform === "win32" ? a.toLowerCase() === b.toLowerCase() : a === b);
|
|
@@ -646,6 +661,194 @@ async function saveArtifact(client, projectId, artifactPath, output) {
|
|
|
646
661
|
return dest;
|
|
647
662
|
}
|
|
648
663
|
|
|
664
|
+
// src/knowledge-install.ts
|
|
665
|
+
import { existsSync } from "fs";
|
|
666
|
+
import { resolve as resolve3 } from "path";
|
|
667
|
+
import { KNOWLEDGE_ID_PATTERN } from "@bendyline/gezel";
|
|
668
|
+
var SHA256_PATTERN = /^[0-9a-f]{64}$/i;
|
|
669
|
+
function resolveKnowledgeInstallSource(source, expectedSha256, opts = {}) {
|
|
670
|
+
if (/^https?:\/\//i.test(source)) {
|
|
671
|
+
if (expectedSha256 && !SHA256_PATTERN.test(expectedSha256)) {
|
|
672
|
+
throw new CliError("--sha256 must be exactly 64 hexadecimal characters.");
|
|
673
|
+
}
|
|
674
|
+
assertCatalogOnlyOptions(opts, "URL");
|
|
675
|
+
return {
|
|
676
|
+
kind: "url",
|
|
677
|
+
url: source,
|
|
678
|
+
...expectedSha256 ? { expectedSha256: expectedSha256.toLowerCase() } : {}
|
|
679
|
+
};
|
|
680
|
+
}
|
|
681
|
+
if (expectedSha256) {
|
|
682
|
+
throw new CliError("--sha256 is only valid for URL installs.");
|
|
683
|
+
}
|
|
684
|
+
if (looksLikeCatalogId(source)) {
|
|
685
|
+
return {
|
|
686
|
+
kind: "catalog",
|
|
687
|
+
id: source,
|
|
688
|
+
...opts.version ? { version: opts.version } : {},
|
|
689
|
+
...opts.privatePlacement ? { placement: "user" } : {}
|
|
690
|
+
};
|
|
691
|
+
}
|
|
692
|
+
assertCatalogOnlyOptions(opts, "file");
|
|
693
|
+
return { kind: "file", path: resolve3(source) };
|
|
694
|
+
}
|
|
695
|
+
function looksLikeCatalogId(source) {
|
|
696
|
+
if (source.includes("/") || source.includes("\\") || source.endsWith(".gezk")) return false;
|
|
697
|
+
if (!KNOWLEDGE_ID_PATTERN.test(source)) return false;
|
|
698
|
+
return !existsSync(source);
|
|
699
|
+
}
|
|
700
|
+
function assertCatalogOnlyOptions(opts, kind) {
|
|
701
|
+
if (opts.version)
|
|
702
|
+
throw new CliError(`--version is only valid for catalog ids, not ${kind} installs.`);
|
|
703
|
+
if (opts.privatePlacement) {
|
|
704
|
+
throw new CliError(`--private is only valid for catalog ids, not ${kind} installs.`);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
// src/model-export.ts
|
|
709
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
710
|
+
import { rename, rm as rm2, stat } from "fs/promises";
|
|
711
|
+
import { basename as basename3, dirname as dirname3, isAbsolute, resolve as resolve4 } from "path";
|
|
712
|
+
import {
|
|
713
|
+
modelBytesFromResponse,
|
|
714
|
+
portableGezmodelFilename,
|
|
715
|
+
verifyModelBundleArchive,
|
|
716
|
+
writeModelBundleResponse
|
|
717
|
+
} from "@bendyline/gezel-client/node";
|
|
718
|
+
async function resolveExportPath(id, destination, cwd) {
|
|
719
|
+
const fallback = portableGezmodelFilename(id);
|
|
720
|
+
if (!destination) return resolve4(cwd, fallback);
|
|
721
|
+
const full = isAbsolute(destination) ? resolve4(destination) : resolve4(cwd, destination);
|
|
722
|
+
const endsWithSeparator = /[/\\]$/.test(destination);
|
|
723
|
+
const isDirectory = endsWithSeparator || await isExistingDirectory(full);
|
|
724
|
+
if (isDirectory) return resolve4(full, fallback);
|
|
725
|
+
return full.toLowerCase().endsWith(".gezmodel") ? full : `${full}.gezmodel`;
|
|
726
|
+
}
|
|
727
|
+
async function isExistingDirectory(path) {
|
|
728
|
+
try {
|
|
729
|
+
return (await stat(path)).isDirectory();
|
|
730
|
+
} catch {
|
|
731
|
+
return false;
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
async function isExistingFile(path) {
|
|
735
|
+
try {
|
|
736
|
+
return (await stat(path)).isFile();
|
|
737
|
+
} catch {
|
|
738
|
+
return false;
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
async function isInstalled(client, engine, id) {
|
|
742
|
+
const { models } = engine === "mlx" ? await client.listMlxModels() : engine === "ds4" ? await client.listDs4Models() : await client.listLlamaCppModels();
|
|
743
|
+
return models.some((model2) => model2.id === id);
|
|
744
|
+
}
|
|
745
|
+
async function pull(client, engine, id, output) {
|
|
746
|
+
let lastPct = -1;
|
|
747
|
+
let pullError;
|
|
748
|
+
const onEvent = (ev) => {
|
|
749
|
+
if (ev.type === "progress") {
|
|
750
|
+
const written = "bytesWrittenAll" in ev ? ev.bytesWrittenAll : ev.bytesWritten;
|
|
751
|
+
const total = "totalBytesAll" in ev ? ev.totalBytesAll : ev.totalBytes ?? 0;
|
|
752
|
+
const pct = total > 0 ? Math.floor(written / total * 100) : 0;
|
|
753
|
+
if (pct === lastPct) return;
|
|
754
|
+
lastPct = pct;
|
|
755
|
+
output.writeProgress(
|
|
756
|
+
`\rdownloading ${id} (${engine}): ${String(pct).padStart(3)}% ${formatGb(written)}/${formatGb(total)} GB`
|
|
757
|
+
);
|
|
758
|
+
} else if (ev.type === "retrying") {
|
|
759
|
+
output.writeProgress(`
|
|
760
|
+
retry ${ev.attempt}/${ev.maxAttempts}: ${ev.reason}
|
|
761
|
+
`);
|
|
762
|
+
} else if (ev.type === "error") {
|
|
763
|
+
pullError = ev.error;
|
|
764
|
+
output.writeProgress("\n");
|
|
765
|
+
} else if (ev.type === "done" && !pullError) {
|
|
766
|
+
output.writeProgress(`\rdownloaded ${id} (${engine})${" ".repeat(48)}
|
|
767
|
+
`);
|
|
768
|
+
}
|
|
769
|
+
};
|
|
770
|
+
if (engine === "mlx") await client.installMlxModel(id, onEvent);
|
|
771
|
+
else if (engine === "ds4") await client.installDs4Model(id, onEvent);
|
|
772
|
+
else await client.installLlamaCppModel(id, onEvent);
|
|
773
|
+
if (pullError) throw new CliError(`download failed: ${pullError}`);
|
|
774
|
+
}
|
|
775
|
+
async function exportModelToFile(client, id, options) {
|
|
776
|
+
const { engine, cwd, output, signal } = options;
|
|
777
|
+
const target = await resolveExportPath(id, options.destination, cwd);
|
|
778
|
+
if (!options.force && await isExistingFile(target)) {
|
|
779
|
+
throw new CliError(`${target} already exists. Pass --force to overwrite it.`);
|
|
780
|
+
}
|
|
781
|
+
if (!await isExistingDirectory(dirname3(target))) {
|
|
782
|
+
throw new CliError(`${dirname3(target)} does not exist.`);
|
|
783
|
+
}
|
|
784
|
+
let pulled = false;
|
|
785
|
+
if (!await isInstalled(client, engine, id)) {
|
|
786
|
+
if (options.skipPull) {
|
|
787
|
+
throw new CliError(
|
|
788
|
+
`model "${id}" is not installed for ${engine}. Run \`gezel model pull ${id}\` first, or drop --no-pull.`
|
|
789
|
+
);
|
|
790
|
+
}
|
|
791
|
+
await pull(client, engine, id, output);
|
|
792
|
+
pulled = true;
|
|
793
|
+
}
|
|
794
|
+
const name = basename3(target);
|
|
795
|
+
const partial = `${target}.partial-${randomUUID2()}`;
|
|
796
|
+
try {
|
|
797
|
+
output.writeProgress(`preparing ${name}
|
|
798
|
+
`);
|
|
799
|
+
const response = await client.exportModelBundle(engine, id, signal);
|
|
800
|
+
const modelBytes = modelBytesFromResponse(response);
|
|
801
|
+
const bytesWritten = await writeModelBundleResponse(
|
|
802
|
+
response,
|
|
803
|
+
partial,
|
|
804
|
+
({ bytesCompleted, bytesTotal }) => {
|
|
805
|
+
output.writeProgress(`\rwriting ${name}: ${progressText(bytesCompleted, bytesTotal)}`);
|
|
806
|
+
},
|
|
807
|
+
signal
|
|
808
|
+
);
|
|
809
|
+
output.writeProgress(`\rwriting ${name}: ${progressText(bytesWritten, modelBytes)}
|
|
810
|
+
`);
|
|
811
|
+
await verifyModelBundleArchive(
|
|
812
|
+
partial,
|
|
813
|
+
({ bytesCompleted, bytesTotal }) => {
|
|
814
|
+
output.writeProgress(`\rverifying ${name}: ${progressText(bytesCompleted, bytesTotal)}`);
|
|
815
|
+
},
|
|
816
|
+
signal
|
|
817
|
+
);
|
|
818
|
+
output.writeProgress(`\rverifying ${name}: done${" ".repeat(32)}
|
|
819
|
+
`);
|
|
820
|
+
signal?.throwIfAborted();
|
|
821
|
+
await publish(partial, target);
|
|
822
|
+
return { path: target, bytesWritten, pulled };
|
|
823
|
+
} catch (error) {
|
|
824
|
+
await rm2(partial, { force: true }).catch(() => {
|
|
825
|
+
});
|
|
826
|
+
throw error;
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
async function publish(partial, target) {
|
|
830
|
+
const backup = `${target}.backup-${randomUUID2()}`;
|
|
831
|
+
const backedUp = await isExistingFile(target);
|
|
832
|
+
if (backedUp) await rename(target, backup);
|
|
833
|
+
try {
|
|
834
|
+
await rename(partial, target);
|
|
835
|
+
} catch (error) {
|
|
836
|
+
if (backedUp) await rename(backup, target).catch(() => {
|
|
837
|
+
});
|
|
838
|
+
throw error;
|
|
839
|
+
}
|
|
840
|
+
if (backedUp) await rm2(backup, { force: true }).catch(() => {
|
|
841
|
+
});
|
|
842
|
+
}
|
|
843
|
+
function progressText(bytesCompleted, bytesTotal) {
|
|
844
|
+
if (!bytesTotal) return `${formatGb(bytesCompleted)} GB`;
|
|
845
|
+
const pct = Math.floor(bytesCompleted / bytesTotal * 100);
|
|
846
|
+
return `${String(pct).padStart(3)}% ${formatGb(bytesCompleted)}/${formatGb(bytesTotal)} GB`;
|
|
847
|
+
}
|
|
848
|
+
function formatGb(bytes) {
|
|
849
|
+
return (bytes / 1e9).toFixed(2);
|
|
850
|
+
}
|
|
851
|
+
|
|
649
852
|
// src/tui/bootstrap.ts
|
|
650
853
|
import {
|
|
651
854
|
computeModelFit,
|
|
@@ -985,7 +1188,10 @@ function resolveRestoreSelection(review, opts) {
|
|
|
985
1188
|
|
|
986
1189
|
// src/tui/craftbook-start.ts
|
|
987
1190
|
import {
|
|
1191
|
+
CRAFTBOOK_CATEGORY_FAMILY_META,
|
|
1192
|
+
CRAFTBOOK_CATEGORY_META,
|
|
988
1193
|
CRAFTBOOK_ROLE_META,
|
|
1194
|
+
resolveCraftbookCategory,
|
|
989
1195
|
visibleCatalogItems
|
|
990
1196
|
} from "@bendyline/gezel";
|
|
991
1197
|
function normalizeCraftbooks(items, showWorkInProgressFeatures = false) {
|
|
@@ -1003,7 +1209,8 @@ function normalizeCraftbooks(items, showWorkInProgressFeatures = false) {
|
|
|
1003
1209
|
source: item.sourceId === "project" ? "project" : item.sourceId === "local" ? "local" : "bundled",
|
|
1004
1210
|
stepCount: manifest.steps.length,
|
|
1005
1211
|
tags: manifest.tags ?? [],
|
|
1006
|
-
role: manifest.role ?? "general"
|
|
1212
|
+
role: manifest.role ?? "general",
|
|
1213
|
+
category: resolveCraftbookCategory(manifest)
|
|
1007
1214
|
});
|
|
1008
1215
|
}
|
|
1009
1216
|
return [...byId.values()].sort((left, right) => left.name.localeCompare(right.name));
|
|
@@ -1051,7 +1258,7 @@ program.action(async () => {
|
|
|
1051
1258
|
const { client } = connection;
|
|
1052
1259
|
const projectId = await resolveTuiProject(client, globals);
|
|
1053
1260
|
const gezelId = await ensureCliProjectLead(client, projectId);
|
|
1054
|
-
let projectName =
|
|
1261
|
+
let projectName = basename4(process.cwd()) || "workspace";
|
|
1055
1262
|
try {
|
|
1056
1263
|
const { projects } = await client.listProjects();
|
|
1057
1264
|
projectName = projects.find((p) => p.id === projectId)?.name ?? projectName;
|
|
@@ -1180,10 +1387,10 @@ async function startForeground(env2) {
|
|
|
1180
1387
|
process.on("SIGINT", requestStop);
|
|
1181
1388
|
process.on("SIGTERM", requestStop);
|
|
1182
1389
|
try {
|
|
1183
|
-
await new Promise((
|
|
1390
|
+
await new Promise((resolve5) => {
|
|
1184
1391
|
child.on("exit", (code) => {
|
|
1185
1392
|
process.exitCode = code ?? 0;
|
|
1186
|
-
|
|
1393
|
+
resolve5();
|
|
1187
1394
|
});
|
|
1188
1395
|
});
|
|
1189
1396
|
} finally {
|
|
@@ -1322,13 +1529,19 @@ program.command("run [prompt...]").description("Run a prompt through a gezel and
|
|
|
1322
1529
|
process.exitCode = 1;
|
|
1323
1530
|
return;
|
|
1324
1531
|
}
|
|
1325
|
-
const
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
}
|
|
1330
|
-
});
|
|
1532
|
+
const previousLogOutput = getLogOutput();
|
|
1533
|
+
setLogOutput("stderr");
|
|
1534
|
+
let conn;
|
|
1535
|
+
let removeSignalCleanup;
|
|
1331
1536
|
try {
|
|
1537
|
+
conn = await connectForRun(cliGlobals());
|
|
1538
|
+
removeSignalCleanup = installSignalCleanup(conn.stop, {
|
|
1539
|
+
onError: (error) => {
|
|
1540
|
+
console.error(
|
|
1541
|
+
`shutdown failed: ${error instanceof Error ? error.message : String(error)}`
|
|
1542
|
+
);
|
|
1543
|
+
}
|
|
1544
|
+
});
|
|
1332
1545
|
const { client } = conn;
|
|
1333
1546
|
const projectId = await resolveRunProject(client, cliGlobals());
|
|
1334
1547
|
const gezelId = opts.gezel ?? await ensureCliProjectLead(client, projectId);
|
|
@@ -1358,8 +1571,12 @@ ${ev.error}`);
|
|
|
1358
1571
|
if (printed) process.stdout.write("\n");
|
|
1359
1572
|
if (errored) process.exitCode = 1;
|
|
1360
1573
|
} finally {
|
|
1361
|
-
removeSignalCleanup();
|
|
1362
|
-
|
|
1574
|
+
removeSignalCleanup?.();
|
|
1575
|
+
try {
|
|
1576
|
+
if (conn?.stop) await conn.stop();
|
|
1577
|
+
} finally {
|
|
1578
|
+
setLogOutput(previousLogOutput);
|
|
1579
|
+
}
|
|
1363
1580
|
}
|
|
1364
1581
|
});
|
|
1365
1582
|
program.command("do <craftbook...>").description("Start a craftbook as a task in the current directory's project").action(async (craftbookParts) => {
|
|
@@ -1513,16 +1730,265 @@ handboek.command("export").description("Render the Handboek as a static HTML sit
|
|
|
1513
1730
|
).option(
|
|
1514
1731
|
"--site-url <url>",
|
|
1515
1732
|
"URL of the surrounding site; adds a wordmark link back out of the docs"
|
|
1516
|
-
).
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1733
|
+
).option(
|
|
1734
|
+
"--canonical-base <url>",
|
|
1735
|
+
"absolute URL the export root is published at (e.g. https://gezel.com/docs/); enables canonical and Open Graph tags"
|
|
1736
|
+
).option("--og-out <dir>", "directory to render Open Graph cards into; must be outside --out").option(
|
|
1737
|
+
"--og-base <url>",
|
|
1738
|
+
"absolute URL the card directory is served from (e.g. https://gezel.com/og/); required with --og-out"
|
|
1739
|
+
).action(
|
|
1740
|
+
async (opts) => {
|
|
1741
|
+
if (Boolean(opts.ogOut) !== Boolean(opts.ogBase)) {
|
|
1742
|
+
console.error("--og-out and --og-base go together: cards need a directory and a URL.");
|
|
1743
|
+
process.exitCode = 1;
|
|
1744
|
+
return;
|
|
1745
|
+
}
|
|
1746
|
+
const handboekModule = "../handboek-export.js";
|
|
1747
|
+
const { runHandboekExport } = await import(handboekModule);
|
|
1748
|
+
const result = await runHandboekExport({
|
|
1749
|
+
out: opts.out,
|
|
1750
|
+
css: opts.css,
|
|
1751
|
+
siteUrl: opts.siteUrl,
|
|
1752
|
+
canonicalBase: opts.canonicalBase,
|
|
1753
|
+
ogOut: opts.ogOut,
|
|
1754
|
+
ogBase: opts.ogBase
|
|
1755
|
+
});
|
|
1756
|
+
console.log(`Handboek exported: ${result.pages} pages \u2192 ${result.out}`);
|
|
1757
|
+
for (const id of result.skipped) console.error(` skipped (no body): ${id}`);
|
|
1758
|
+
const cards = result.cards;
|
|
1759
|
+
if (cards?.skipped) {
|
|
1760
|
+
console.error(` no Open Graph cards: ${cards.skipped}`);
|
|
1761
|
+
} else if (cards) {
|
|
1762
|
+
console.log(
|
|
1763
|
+
`Open Graph cards: ${cards.rendered} rendered, ${cards.reused} reused, ${cards.swept} swept`
|
|
1764
|
+
);
|
|
1765
|
+
for (const id of cards.failed) console.error(` card failed: ${id}`);
|
|
1766
|
+
}
|
|
1767
|
+
}
|
|
1768
|
+
);
|
|
1769
|
+
var knowledge = program.command("knowledge").description("Build, validate, inspect and search .gezk knowledge catalogs (no daemon)");
|
|
1770
|
+
var loadKnowledgeCommand = async () => {
|
|
1771
|
+
const knowledgeModule = "../knowledge-command.js";
|
|
1772
|
+
return await import(knowledgeModule);
|
|
1773
|
+
};
|
|
1774
|
+
knowledge.command("init <dir>").description("Scaffold a catalog folder (catalog.json + content/)").action(async (dir) => {
|
|
1775
|
+
const { runKnowledgeInit } = await loadKnowledgeCommand();
|
|
1776
|
+
await runKnowledgeInit(dir);
|
|
1777
|
+
});
|
|
1778
|
+
knowledge.command("build <dir>").description("Compile a catalog folder into a .gezk archive").option("--out <file>", "output path (default <dir>/<id>-<version>.gezk)").option("--sign-key <pemfile>", "Ed25519 private key (PKCS#8 PEM) to sign the manifest").action(async (dir, opts) => {
|
|
1779
|
+
const { runKnowledgeBuild } = await loadKnowledgeCommand();
|
|
1780
|
+
await runKnowledgeBuild(dir, opts);
|
|
1781
|
+
});
|
|
1782
|
+
knowledge.command("validate <path>").description("Verify a .gezk archive or extracted catalog directory").option("--deep", "also run quick_check, vector alignment, self-KNN and smoke queries").action(async (path, opts) => {
|
|
1783
|
+
const { runKnowledgeValidate } = await loadKnowledgeCommand();
|
|
1784
|
+
await runKnowledgeValidate(path, opts);
|
|
1785
|
+
});
|
|
1786
|
+
knowledge.command("inspect <path>").description("Print a catalog summary from its manifest").action(async (path) => {
|
|
1787
|
+
const { runKnowledgeInspect } = await loadKnowledgeCommand();
|
|
1788
|
+
await runKnowledgeInspect(path);
|
|
1789
|
+
});
|
|
1790
|
+
knowledge.command("export-parquet <path>").description(
|
|
1791
|
+
"Write the Parquet companion (documents, chunks, topics) of a .gezk archive or extracted catalog"
|
|
1792
|
+
).option("--out <dir>", "output directory (default: <archive>-parquet beside the archive)").option(
|
|
1793
|
+
"--duckdb <binary>",
|
|
1794
|
+
"DuckDB CLI to use (default: $GEZEL_DUCKDB_BIN or the one gezel installed)"
|
|
1795
|
+
).action(async (path, opts) => {
|
|
1796
|
+
const { runKnowledgeExportParquet } = await loadKnowledgeCommand();
|
|
1797
|
+
await runKnowledgeExportParquet(path, opts);
|
|
1798
|
+
});
|
|
1799
|
+
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("--limit <n>", "maximum results", (v) => Number.parseInt(v, 10), 10).action(async (path, query, opts) => {
|
|
1800
|
+
const { runKnowledgeSearch } = await loadKnowledgeCommand();
|
|
1801
|
+
await runKnowledgeSearch(path, query, opts);
|
|
1802
|
+
});
|
|
1803
|
+
knowledge.command("available").description("List the knowledge catalogs the gilde offers for download").action(async () => {
|
|
1804
|
+
const client = await connectOwned(cliGlobals());
|
|
1805
|
+
const { catalogs } = await client.listAvailableKnowledgeCatalogs();
|
|
1806
|
+
if (catalogs.length === 0) {
|
|
1807
|
+
console.log("The catalog offers no knowledge catalogs for this build.");
|
|
1808
|
+
return;
|
|
1809
|
+
}
|
|
1810
|
+
for (const c of catalogs) {
|
|
1811
|
+
const state = c.installing ? "downloading" : c.installed ? c.installed.updateAvailable ? `installed ${c.installed.version} \u2014 update to ${c.version} available` : "installed" : c.incompleteDownload ? "partial download \u2014 install resumes it" : c.sharedOnDevice ? "on this device \u2014 install adopts it" : "available";
|
|
1812
|
+
const size = `${(c.archiveBytes / (1024 * 1024)).toFixed(0)} MB`;
|
|
1813
|
+
console.log(
|
|
1814
|
+
`${c.id.padEnd(28)} ${c.version.padEnd(10)} ${c.language.padEnd(4)} ${String(c.documents).padStart(7)} docs ${size.padStart(8)} ${state}`
|
|
1815
|
+
);
|
|
1816
|
+
}
|
|
1817
|
+
});
|
|
1818
|
+
knowledge.command("install <source>").description("Install a .gezk catalog into the running gezel (catalog id, file path, or URL)").option("--sha256 <digest>", "optional expected SHA-256 digest for URL installs").option("--version <version>", "catalog ids only: the version to install (default: newest)").option("--private", "catalog ids only: keep the catalog in your own home, never machine-shared").action(
|
|
1819
|
+
async (source, opts) => {
|
|
1820
|
+
const installSource = resolveKnowledgeInstallSource(source, opts.sha256, {
|
|
1821
|
+
...opts.version ? { version: opts.version } : {},
|
|
1822
|
+
...opts.private ? { privatePlacement: true } : {}
|
|
1823
|
+
});
|
|
1824
|
+
const client = await connectOwned(cliGlobals());
|
|
1825
|
+
let started;
|
|
1826
|
+
try {
|
|
1827
|
+
started = await client.installKnowledgeCatalog({ source: installSource });
|
|
1828
|
+
} catch (err) {
|
|
1829
|
+
if (err instanceof GezelApiError2 && err.status === 403) {
|
|
1830
|
+
throw new CliError(
|
|
1831
|
+
"Downloading knowledge catalogs needs app network access, which the security policy turns off (Settings \u2192 Security)."
|
|
1832
|
+
);
|
|
1833
|
+
}
|
|
1834
|
+
throw err;
|
|
1835
|
+
}
|
|
1836
|
+
if (started.alreadyRunning)
|
|
1837
|
+
console.error("Attaching to the install that is already running.");
|
|
1838
|
+
let done;
|
|
1839
|
+
let failure;
|
|
1840
|
+
const tty = process.stderr.isTTY;
|
|
1841
|
+
await client.subscribeKnowledgeInstall(started.jobId, (event) => {
|
|
1842
|
+
if (event.type === "progress") {
|
|
1843
|
+
const pct = event.bytesTotal > 0 ? ` (${Math.floor(event.bytesDone / event.bytesTotal * 100)}%)` : "";
|
|
1844
|
+
if (tty) process.stderr.write(`\r${event.phase}${pct} `);
|
|
1845
|
+
} else if (event.type === "retrying") {
|
|
1846
|
+
if (tty) process.stderr.write("\n");
|
|
1847
|
+
console.error(
|
|
1848
|
+
`Retrying (${event.attempt}/${event.maxAttempts}) in ${Math.round(event.delayMs / 1e3)}s: ${event.reason}`
|
|
1849
|
+
);
|
|
1850
|
+
} else if (event.type === "verifying") {
|
|
1851
|
+
if (tty) process.stderr.write("\rverifying ");
|
|
1852
|
+
} else if (event.type === "done") {
|
|
1853
|
+
done = event;
|
|
1854
|
+
} else {
|
|
1855
|
+
failure = event.error;
|
|
1856
|
+
}
|
|
1857
|
+
});
|
|
1858
|
+
if (tty) process.stderr.write("\n");
|
|
1859
|
+
if (failure) throw new CliError(`install failed: ${failure}`);
|
|
1860
|
+
if (!done) throw new CliError("install ended without a result");
|
|
1861
|
+
const placement = done.storageScope === "machine-shared" ? "shared on this device" : "private";
|
|
1862
|
+
console.log(
|
|
1863
|
+
`Installed ${done.ref.catalogId}@${done.ref.version} (${placement}) \u2014 enabled for search.`
|
|
1864
|
+
);
|
|
1865
|
+
if (done.warning) console.error(`Note: ${done.warning}`);
|
|
1866
|
+
}
|
|
1867
|
+
);
|
|
1868
|
+
knowledge.command("list").description("List catalogs installed in the running gezel").action(async () => {
|
|
1869
|
+
const client = await connectOwned(cliGlobals());
|
|
1870
|
+
const { catalogs } = await client.listKnowledgeCatalogs();
|
|
1871
|
+
if (catalogs.length === 0) {
|
|
1872
|
+
console.log("No knowledge catalogs installed. Add one with: gezel knowledge install <file>");
|
|
1873
|
+
return;
|
|
1874
|
+
}
|
|
1875
|
+
for (const c of catalogs) {
|
|
1876
|
+
const state = c.disabledReason ? `quarantined \u2014 ${c.disabledReason}` : c.enabled ? c.mounted ? "active" : "enabled" : "disabled";
|
|
1877
|
+
const size = c.sizeBytes ? ` ${(c.sizeBytes / (1024 * 1024)).toFixed(1)} MB` : "";
|
|
1878
|
+
const update = c.availableVersion ? ` \u2014 update to ${c.availableVersion} available` : "";
|
|
1879
|
+
console.log(
|
|
1880
|
+
`${c.ref.catalogId.padEnd(24)} ${c.ref.version.padEnd(10)} ${String(c.documents ?? "?").padStart(6)} docs${size} ${state} (${c.source})${update}`
|
|
1881
|
+
);
|
|
1882
|
+
}
|
|
1883
|
+
});
|
|
1884
|
+
knowledge.command("remove <catalogId>").description("Remove an installed catalog and its private files").action(async (catalogId) => {
|
|
1885
|
+
const client = await connectOwned(cliGlobals());
|
|
1886
|
+
const { ok } = await client.removeKnowledgeCatalog(catalogId).catch((err) => {
|
|
1887
|
+
throw new CliError(err instanceof Error ? err.message : String(err));
|
|
1888
|
+
});
|
|
1889
|
+
if (!ok) throw new CliError(`catalog not found: ${catalogId}`);
|
|
1890
|
+
console.log(`Removed ${catalogId}.`);
|
|
1891
|
+
});
|
|
1892
|
+
knowledge.command("find <query>").description("Search installed catalogs through the running gezel").option("--limit <n>", "maximum results", (v) => Number.parseInt(v, 10), 10).action(async (query, opts) => {
|
|
1893
|
+
const client = await connectOwned(cliGlobals());
|
|
1894
|
+
const { results } = await client.searchKnowledge({
|
|
1895
|
+
query,
|
|
1896
|
+
...opts.limit ? { maxResults: opts.limit } : {}
|
|
1523
1897
|
});
|
|
1524
|
-
|
|
1525
|
-
|
|
1898
|
+
if (results.length === 0) {
|
|
1899
|
+
console.log(`No results for "${query}".`);
|
|
1900
|
+
process.exitCode = 1;
|
|
1901
|
+
return;
|
|
1902
|
+
}
|
|
1903
|
+
for (const r of results) {
|
|
1904
|
+
console.log(`${r.title} ${r.uri ?? ""}`);
|
|
1905
|
+
if (r.snippet) console.log(` ${r.snippet.replace(/\s+/g, " ").slice(0, 160)}`);
|
|
1906
|
+
}
|
|
1907
|
+
});
|
|
1908
|
+
var appCmd = program.command("app").description("Manage AI Apps (.gezapp) installed on this machine");
|
|
1909
|
+
var loadAppCommand = async () => {
|
|
1910
|
+
const appModule = "../app-command.js";
|
|
1911
|
+
return await import(appModule);
|
|
1912
|
+
};
|
|
1913
|
+
var loadAppAuthorCommand = async () => {
|
|
1914
|
+
const appAuthorModule = "../app-author-command.js";
|
|
1915
|
+
return await import(appAuthorModule);
|
|
1916
|
+
};
|
|
1917
|
+
appCmd.command("add <file>").description("Install a .gezapp AI App (idempotent; a newer version upgrades)").option("--yes", "skip the confirmation prompt").option("--force", "allow downgrading to an older version").option("--json", "print the machine-readable result").action(async (file, opts) => {
|
|
1918
|
+
const { runAppAdd } = await loadAppCommand();
|
|
1919
|
+
await runAppAdd(await connectOwned(cliGlobals()), file, opts);
|
|
1920
|
+
});
|
|
1921
|
+
appCmd.command("update <file>").description("Upgrade an installed AI App from a newer .gezapp").option("--force", "allow downgrading to an older version").option("--json", "print the machine-readable result").action(async (file, opts) => {
|
|
1922
|
+
const { runAppUpdate } = await loadAppCommand();
|
|
1923
|
+
await runAppUpdate(await connectOwned(cliGlobals()), file, opts);
|
|
1924
|
+
});
|
|
1925
|
+
appCmd.command("list").description("List installed AI Apps").option("--json", "print the machine-readable result").action(async (opts) => {
|
|
1926
|
+
const { runAppList } = await loadAppCommand();
|
|
1927
|
+
await runAppList(await connectOwned(cliGlobals()), opts);
|
|
1928
|
+
});
|
|
1929
|
+
appCmd.command("show <appId>").description("Show one installed AI App: manifest, dependencies, applied projects").option("--json", "print the machine-readable result").action(async (appId, opts) => {
|
|
1930
|
+
const { runAppShow } = await loadAppCommand();
|
|
1931
|
+
await runAppShow(await connectOwned(cliGlobals()), appId, opts);
|
|
1932
|
+
});
|
|
1933
|
+
appCmd.command("remove <appId>").description("Uninstall an AI App (projects it outfitted keep their copies)").option("--yes", "skip the confirmation prompt").option("--keep-files", "unregister only; leave the version dirs on disk").action(async (appId, opts) => {
|
|
1934
|
+
const { runAppRemove } = await loadAppCommand();
|
|
1935
|
+
await runAppRemove(await connectOwned(cliGlobals()), appId, opts);
|
|
1936
|
+
});
|
|
1937
|
+
appCmd.command("enable <appId>").description("Enable a disabled AI App").action(async (appId) => {
|
|
1938
|
+
const { runAppSetEnabled } = await loadAppCommand();
|
|
1939
|
+
await runAppSetEnabled(await connectOwned(cliGlobals()), appId, true);
|
|
1940
|
+
});
|
|
1941
|
+
var appCommandFolder = () => {
|
|
1942
|
+
const p = cliGlobals().project;
|
|
1943
|
+
return p === void 0 || p === true || p === false ? process.cwd() : p;
|
|
1944
|
+
};
|
|
1945
|
+
appCmd.command("apply <appId>").description("Apply an installed AI App to this folder (links or creates a project here)").option("--version <version>", "pin a specific installed type version").option(
|
|
1946
|
+
"--param <key=value>",
|
|
1947
|
+
"set an adoption param (repeatable)",
|
|
1948
|
+
(pair, prior) => [...prior, pair],
|
|
1949
|
+
[]
|
|
1950
|
+
).option("--yes", "skip the confirmation prompt").option("--refresh", "re-apply even when this version is already applied").option("--force", "apply over a different app already applied here").option("--json", "print the machine-readable result").action(
|
|
1951
|
+
async (appId, opts) => {
|
|
1952
|
+
const { runAppApply } = await loadAppCommand();
|
|
1953
|
+
await runAppApply(await connectOwned(cliGlobals()), appId, appCommandFolder(), opts);
|
|
1954
|
+
}
|
|
1955
|
+
);
|
|
1956
|
+
appCmd.command("status").description("Show this folder's applied AI App, drift, and available updates").option("--json", "print the machine-readable result").action(async (opts) => {
|
|
1957
|
+
const { runAppStatus } = await loadAppCommand();
|
|
1958
|
+
await runAppStatus(await connectOwned(cliGlobals()), appCommandFolder(), opts);
|
|
1959
|
+
});
|
|
1960
|
+
appCmd.command("serve [target...]").description(
|
|
1961
|
+
"Serve this folder's applied AI App as a shareable mini-site (`serve status` / `serve stop` manage sites)"
|
|
1962
|
+
).option("--port <n>", "fixed port (default: ephemeral)", (v) => Number.parseInt(v, 10)).option("--host <ip>", "bind address, an IP literal (default 127.0.0.1)").option(
|
|
1963
|
+
"--allow-host <name>",
|
|
1964
|
+
"accept this reverse-proxy/tunnel hostname (repeatable)",
|
|
1965
|
+
(name, prior) => [...prior, name],
|
|
1966
|
+
[]
|
|
1967
|
+
).option("--chat", "let visitors chat with the project lead (no tools)").option("--public", "skip the site key \u2014 anyone reaching the port may visit").option("--key <site-key>", "pin the site key for a stable share link (min 24 chars)").option("--detach", "leave the site running in the daemon and exit").option("--open", "open the share link in a browser").option("--all", "with `serve stop`: stop every site").option("--json", "print the machine-readable result").action(
|
|
1968
|
+
async (target, opts) => {
|
|
1969
|
+
const { runAppServe } = await loadAppCommand();
|
|
1970
|
+
await runAppServe(await connectOwned(cliGlobals()), target ?? [], appCommandFolder(), opts);
|
|
1971
|
+
}
|
|
1972
|
+
);
|
|
1973
|
+
appCmd.command("disable <appId>").description("Disable an AI App without uninstalling it").action(async (appId) => {
|
|
1974
|
+
const { runAppSetEnabled } = await loadAppCommand();
|
|
1975
|
+
await runAppSetEnabled(await connectOwned(cliGlobals()), appId, false);
|
|
1976
|
+
});
|
|
1977
|
+
appCmd.command("new <id>").description("Scaffold a minimal AI App source folder").option("--dir <parent>", "parent directory (defaults to the current folder)").option("--with-page", "include an Output page wired to the example tool").action(async (id, opts) => {
|
|
1978
|
+
const { runAppNew } = await loadAppAuthorCommand();
|
|
1979
|
+
await runAppNew(id, opts);
|
|
1980
|
+
});
|
|
1981
|
+
appCmd.command("validate <target>").description("Validate an AI App source folder or .gezapp file (no daemon needed)").option("--json", "print the machine-readable findings").action(async (target, opts) => {
|
|
1982
|
+
const { runAppValidate } = await loadAppAuthorCommand();
|
|
1983
|
+
await runAppValidate(target, opts);
|
|
1984
|
+
});
|
|
1985
|
+
appCmd.command("pack <folder>").description("Validate and pack an AI App source folder into a .gezapp").option("-o, --out <file>", "output path (defaults to <appId>-<version>.gezapp)").option("--json", "print the machine-readable result").action(async (folder, opts) => {
|
|
1986
|
+
const { runAppPack } = await loadAppAuthorCommand();
|
|
1987
|
+
await runAppPack(folder, opts);
|
|
1988
|
+
});
|
|
1989
|
+
appCmd.command("schemas").description("The JSON Schemas an AI App author codes against, rendered from this build").option("--out <dir>", "write the schema files into a directory").option("--json", "print one combined JSON object").action(async (opts) => {
|
|
1990
|
+
const { runAppSchemas } = await loadAppAuthorCommand();
|
|
1991
|
+
await runAppSchemas(opts);
|
|
1526
1992
|
});
|
|
1527
1993
|
var task = program.command("task").description("Manage tasks");
|
|
1528
1994
|
task.command("list").description("List tasks across every project").option("-s, --status <status>", "filter by status (paused|active|complete|canceled)").action(async (opts) => {
|
|
@@ -1795,6 +2261,22 @@ model.command("pull <id>").description("Download a local chat model from the cat
|
|
|
1795
2261
|
}
|
|
1796
2262
|
if (pullError) throw new CliError(`pull failed: ${pullError}`);
|
|
1797
2263
|
});
|
|
2264
|
+
model.command("export <id> [file]").description("Export a catalog model to a portable .gezmodel (downloads it first if needed)").option("-p, --provider <engine>", "mlx | llama-cpp | ds4 (default: platform default)").option("-f, --force", "Overwrite an existing file").option("--no-pull", "Fail instead of downloading a model that is not installed yet").action(async (id, file, opts) => {
|
|
2265
|
+
const client = await connectOwned(cliGlobals());
|
|
2266
|
+
const result = await exportModelToFile(client, id, {
|
|
2267
|
+
engine: resolveModelProvider(opts.provider),
|
|
2268
|
+
cwd: process.cwd(),
|
|
2269
|
+
...file ? { destination: file } : {},
|
|
2270
|
+
...opts.force ? { force: true } : {},
|
|
2271
|
+
...opts.pull === false ? { skipPull: true } : {},
|
|
2272
|
+
output: {
|
|
2273
|
+
writeProgress: (text) => {
|
|
2274
|
+
process.stderr.write(text);
|
|
2275
|
+
}
|
|
2276
|
+
}
|
|
2277
|
+
});
|
|
2278
|
+
console.log(`exported ${id} to ${result.path} (${(result.bytesWritten / 1e9).toFixed(2)} GB)`);
|
|
2279
|
+
});
|
|
1798
2280
|
program.command("doctor").description("Check the Gezel installation").action(async () => {
|
|
1799
2281
|
const globals = cliGlobals();
|
|
1800
2282
|
const system = globals.connect ? null : await findHealthySystemService(globals);
|
|
@@ -1966,7 +2448,10 @@ async function pollStorageJob(client, jobId) {
|
|
|
1966
2448
|
}
|
|
1967
2449
|
}
|
|
1968
2450
|
program.parseAsync(process.argv).catch((err) => {
|
|
1969
|
-
if (err instanceof CliError
|
|
1970
|
-
|
|
2451
|
+
if (err instanceof CliError || err instanceof Error && err.name === "CliError") {
|
|
2452
|
+
console.error(err.message);
|
|
2453
|
+
} else {
|
|
2454
|
+
console.error(err);
|
|
2455
|
+
}
|
|
1971
2456
|
process.exit(1);
|
|
1972
2457
|
});
|