@bendyline/gezel-cli 1.0.7 → 1.1.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 +4 -3
- package/dist/app-author-command.js +1 -0
- package/dist/app-command.js +1 -0
- package/dist/bin/gezel-main.js +132 -45
- package/dist/knowledge-command.js +98 -14
- package/dist/tui/index.js +50 -36
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -17,9 +17,10 @@ install. It offers the verified Gezel native toolkit first, downloaded from
|
|
|
17
17
|
the [Gezel GitHub Releases](https://github.com/bendyline/gezel/releases/), then
|
|
18
18
|
device-ranked model choices:
|
|
19
19
|
|
|
20
|
-
1. The best chat model
|
|
21
|
-
|
|
22
|
-
2.
|
|
20
|
+
1. The best chat model for this device, by itself. This is the recommended
|
|
21
|
+
default and keeps the first download small.
|
|
22
|
+
2. An optional complete workshop set that adds every recommended image,
|
|
23
|
+
speech, reading, and video helper that fits this device.
|
|
23
24
|
3. Other compatible chat-only models, ordered for this device.
|
|
24
25
|
|
|
25
26
|
Downloads show live progress and activate inside the running daemon, so setup
|
package/dist/app-command.js
CHANGED
package/dist/bin/gezel-main.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { basename as basename4, isAbsolute as isAbsolutePath, join as joinPath } from "path";
|
|
5
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);
|
|
@@ -647,13 +662,16 @@ async function saveArtifact(client, projectId, artifactPath, output) {
|
|
|
647
662
|
}
|
|
648
663
|
|
|
649
664
|
// src/knowledge-install.ts
|
|
665
|
+
import { existsSync } from "fs";
|
|
650
666
|
import { resolve as resolve3 } from "path";
|
|
667
|
+
import { KNOWLEDGE_ID_PATTERN } from "@bendyline/gezel";
|
|
651
668
|
var SHA256_PATTERN = /^[0-9a-f]{64}$/i;
|
|
652
|
-
function resolveKnowledgeInstallSource(source, expectedSha256) {
|
|
669
|
+
function resolveKnowledgeInstallSource(source, expectedSha256, opts = {}) {
|
|
653
670
|
if (/^https?:\/\//i.test(source)) {
|
|
654
671
|
if (expectedSha256 && !SHA256_PATTERN.test(expectedSha256)) {
|
|
655
672
|
throw new CliError("--sha256 must be exactly 64 hexadecimal characters.");
|
|
656
673
|
}
|
|
674
|
+
assertCatalogOnlyOptions(opts, "URL");
|
|
657
675
|
return {
|
|
658
676
|
kind: "url",
|
|
659
677
|
url: source,
|
|
@@ -663,8 +681,29 @@ function resolveKnowledgeInstallSource(source, expectedSha256) {
|
|
|
663
681
|
if (expectedSha256) {
|
|
664
682
|
throw new CliError("--sha256 is only valid for URL installs.");
|
|
665
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");
|
|
666
693
|
return { kind: "file", path: resolve3(source) };
|
|
667
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
|
+
}
|
|
668
707
|
|
|
669
708
|
// src/model-export.ts
|
|
670
709
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
@@ -1748,37 +1787,84 @@ knowledge.command("inspect <path>").description("Print a catalog summary from it
|
|
|
1748
1787
|
const { runKnowledgeInspect } = await loadKnowledgeCommand();
|
|
1749
1788
|
await runKnowledgeInspect(path);
|
|
1750
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
|
+
});
|
|
1751
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) => {
|
|
1752
1800
|
const { runKnowledgeSearch } = await loadKnowledgeCommand();
|
|
1753
1801
|
await runKnowledgeSearch(path, query, opts);
|
|
1754
1802
|
});
|
|
1755
|
-
knowledge.command("
|
|
1756
|
-
const installSource = resolveKnowledgeInstallSource(source, opts.sha256);
|
|
1803
|
+
knowledge.command("available").description("List the knowledge catalogs the gilde offers for download").action(async () => {
|
|
1757
1804
|
const client = await connectOwned(cliGlobals());
|
|
1758
|
-
const {
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
}
|
|
1770
|
-
if (job.finished) {
|
|
1771
|
-
if (process.stderr.isTTY) process.stderr.write("\n");
|
|
1772
|
-
if (job.error) throw new CliError(`install failed: ${job.error}`);
|
|
1773
|
-
const doneEvent = job.events.find((e) => e.type === "done");
|
|
1774
|
-
console.log(
|
|
1775
|
-
`Installed ${doneEvent?.ref?.catalogId ?? "catalog"}@${doneEvent?.ref?.version ?? ""} \u2014 enabled for search.`
|
|
1776
|
-
);
|
|
1777
|
-
return;
|
|
1778
|
-
}
|
|
1779
|
-
await new Promise((r) => setTimeout(r, 250));
|
|
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
|
+
);
|
|
1780
1816
|
}
|
|
1781
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
|
+
);
|
|
1782
1868
|
knowledge.command("list").description("List catalogs installed in the running gezel").action(async () => {
|
|
1783
1869
|
const client = await connectOwned(cliGlobals());
|
|
1784
1870
|
const { catalogs } = await client.listKnowledgeCatalogs();
|
|
@@ -1789,8 +1875,9 @@ knowledge.command("list").description("List catalogs installed in the running ge
|
|
|
1789
1875
|
for (const c of catalogs) {
|
|
1790
1876
|
const state = c.disabledReason ? `quarantined \u2014 ${c.disabledReason}` : c.enabled ? c.mounted ? "active" : "enabled" : "disabled";
|
|
1791
1877
|
const size = c.sizeBytes ? ` ${(c.sizeBytes / (1024 * 1024)).toFixed(1)} MB` : "";
|
|
1878
|
+
const update = c.availableVersion ? ` \u2014 update to ${c.availableVersion} available` : "";
|
|
1792
1879
|
console.log(
|
|
1793
|
-
`${c.ref.catalogId.padEnd(24)} ${c.ref.version.padEnd(10)} ${String(c.documents ?? "?").padStart(6)} docs${size} ${state}`
|
|
1880
|
+
`${c.ref.catalogId.padEnd(24)} ${c.ref.version.padEnd(10)} ${String(c.documents ?? "?").padStart(6)} docs${size} ${state} (${c.source})${update}`
|
|
1794
1881
|
);
|
|
1795
1882
|
}
|
|
1796
1883
|
});
|
|
@@ -2,21 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
// src/knowledge-command.ts
|
|
4
4
|
import { createHash as createHash2 } from "crypto";
|
|
5
|
+
import { existsSync } from "fs";
|
|
5
6
|
import { mkdir as mkdir2, mkdtemp, readFile as readFile2, rm as rm2, stat, writeFile as writeFile2 } from "fs/promises";
|
|
6
7
|
import { homedir as homedir2, tmpdir } from "os";
|
|
7
|
-
import { basename as basename2, join as join2, resolve as resolve2 } from "path";
|
|
8
|
+
import { basename as basename2, dirname as dirname2, join as join2, relative, resolve as resolve2 } from "path";
|
|
8
9
|
import { KnowledgeIdSchema, formatKnowledgeUri } from "@bendyline/gezel";
|
|
9
10
|
import {
|
|
10
11
|
CatalogHandle,
|
|
11
12
|
EmbedderUnavailableError,
|
|
12
|
-
GEZEL_MARKDOWN_CHUNKS_2,
|
|
13
13
|
KNOWLEDGE_EMBEDDING_PROFILES,
|
|
14
|
+
MARKDOWN_CHUNKS_2,
|
|
14
15
|
compileKnowledgeCatalog,
|
|
15
16
|
createProfileEmbedder,
|
|
17
|
+
detectTableOfContents,
|
|
16
18
|
extractGezkVerified,
|
|
17
19
|
knowledgeEmbeddingProfile,
|
|
18
20
|
loadMarkdownCatalog,
|
|
19
21
|
readGezkManifest,
|
|
22
|
+
readMkdocsDocsDir,
|
|
20
23
|
signManifest,
|
|
21
24
|
validateExtractedCatalog
|
|
22
25
|
} from "@bendyline/gezel-knowledge";
|
|
@@ -35,6 +38,7 @@ import {
|
|
|
35
38
|
import {
|
|
36
39
|
GezelApiError,
|
|
37
40
|
GezelClient,
|
|
41
|
+
LiveDaemonUnhealthyError,
|
|
38
42
|
createTrustingFetch,
|
|
39
43
|
discoverOrSpawn,
|
|
40
44
|
electronNativeBinCandidates,
|
|
@@ -93,7 +97,7 @@ async function runKnowledgeInit(dir) {
|
|
|
93
97
|
language: "en",
|
|
94
98
|
publisher: { id, name: basename2(root) },
|
|
95
99
|
license: { name: "All rights reserved", attributionRequired: false },
|
|
96
|
-
profile: "
|
|
100
|
+
profile: "bge-small-en-v1.5@1"
|
|
97
101
|
};
|
|
98
102
|
await writeFile2(configPath, `${JSON.stringify(config, null, 2)}
|
|
99
103
|
`, "utf8");
|
|
@@ -105,24 +109,60 @@ async function runKnowledgeInit(dir) {
|
|
|
105
109
|
console.log(`Initialized knowledge catalog at ${root}`);
|
|
106
110
|
console.log(` ${CATALOG_JSON} \u2014 identity, license, embedding profile`);
|
|
107
111
|
console.log(` ${CONTENT_DIR}/ \u2014 Markdown content (folders become topics)`);
|
|
112
|
+
console.log(
|
|
113
|
+
" An outline the tree already has is honored: SUMMARY.md, an mkdocs.yml nav, _toc.yml, or Hugo _index.md pages"
|
|
114
|
+
);
|
|
108
115
|
console.log(`Build with: gezel knowledge build ${dir}`);
|
|
109
116
|
}
|
|
110
117
|
function sanitizeCatalogId(name) {
|
|
111
118
|
const slug = name.toLowerCase().normalize("NFKD").replace(/\p{Mark}/gu, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 63);
|
|
112
119
|
return KnowledgeIdSchema.safeParse(slug).success ? slug : "my-catalog";
|
|
113
120
|
}
|
|
114
|
-
async function
|
|
115
|
-
|
|
116
|
-
const config = await readCatalogConfig(root);
|
|
117
|
-
const contentDir = join2(root, CONTENT_DIR);
|
|
118
|
-
const hasContentDir = await stat(contentDir).then(
|
|
121
|
+
async function isDirectory(path) {
|
|
122
|
+
return stat(path).then(
|
|
119
123
|
(s) => s.isDirectory(),
|
|
120
124
|
() => false
|
|
121
125
|
);
|
|
122
|
-
|
|
123
|
-
|
|
126
|
+
}
|
|
127
|
+
async function resolveContentRoot(root, config) {
|
|
128
|
+
if (config.content) {
|
|
129
|
+
const dir = resolve2(root, config.content);
|
|
130
|
+
if (!await isDirectory(dir)) {
|
|
131
|
+
throw new CliError(
|
|
132
|
+
`${CATALOG_JSON} names content '${config.content}', which is not a directory`
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
return dir;
|
|
136
|
+
}
|
|
137
|
+
const contentDir = join2(root, CONTENT_DIR);
|
|
138
|
+
if (await isDirectory(contentDir)) return contentDir;
|
|
139
|
+
if (config.toc === void 0 || config.toc.format === "mkdocs") {
|
|
140
|
+
const mkdocs = config.toc?.path ? resolve2(root, config.toc.path) : [join2(root, "mkdocs.yml"), join2(root, "mkdocs.yaml")].find((p) => existsSync(p));
|
|
141
|
+
if (mkdocs && existsSync(mkdocs)) {
|
|
142
|
+
const docsDir = await readMkdocsDocsDir(mkdocs);
|
|
143
|
+
if (await isDirectory(docsDir)) return docsDir;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return root;
|
|
147
|
+
}
|
|
148
|
+
function describeToc(toc, root) {
|
|
149
|
+
const source = toc.format === "folders" ? "folders" : toc.format === "hugo" ? "Hugo conventions (_index.md, weight)" : toc.format;
|
|
150
|
+
return toc.path ? `${source} (${relative(root, toc.path) || toc.path})` : source;
|
|
151
|
+
}
|
|
152
|
+
async function runKnowledgeBuild(dir, opts, deps = {}) {
|
|
153
|
+
const root = resolve2(dir);
|
|
154
|
+
const config = await readCatalogConfig(root);
|
|
155
|
+
const contentRoot = await resolveContentRoot(root, config);
|
|
156
|
+
const toc = config.toc ?? await detectTableOfContents(contentRoot, root);
|
|
157
|
+
const source = await loadMarkdownCatalog(contentRoot, {
|
|
158
|
+
language: config.language,
|
|
159
|
+
uri: { publisherId: config.publisher.id, catalogId: config.id },
|
|
160
|
+
...config.ignore ? { ignore: config.ignore } : {},
|
|
161
|
+
toc,
|
|
162
|
+
onWarning: (message) => console.warn(`warning: ${message}`)
|
|
124
163
|
});
|
|
125
|
-
|
|
164
|
+
console.log(`Table of contents: ${describeToc(source.toc, root)}`);
|
|
165
|
+
const profileId = config.profile ?? "bge-small-en-v1.5@1";
|
|
126
166
|
const profile = knowledgeEmbeddingProfile(profileId);
|
|
127
167
|
if (!profile) {
|
|
128
168
|
throw new CliError(
|
|
@@ -130,7 +170,7 @@ async function runKnowledgeBuild(dir, opts, deps = {}) {
|
|
|
130
170
|
);
|
|
131
171
|
}
|
|
132
172
|
console.log(
|
|
133
|
-
`Building ${config.id}@${config.version}: ${source.documents.length} documents, profile ${profileId}`
|
|
173
|
+
`Building ${config.id}@${config.version}: ${source.documents.length} documents, ${source.assets.length} assets, profile ${profileId}`
|
|
134
174
|
);
|
|
135
175
|
console.log("Loading the embedding model (first run downloads it)\u2026");
|
|
136
176
|
const embedder = await (deps.createEmbedder ?? defaultCreateEmbedder)(profileId);
|
|
@@ -156,10 +196,11 @@ async function runKnowledgeBuild(dir, opts, deps = {}) {
|
|
|
156
196
|
})(),
|
|
157
197
|
outputPath,
|
|
158
198
|
embeddingProfile: embedder.profile,
|
|
159
|
-
chunkingProfile:
|
|
199
|
+
chunkingProfile: MARKDOWN_CHUNKS_2,
|
|
160
200
|
embed: (texts) => embedder.embed(texts),
|
|
161
201
|
countTokens: (text) => embedder.countTokens(text),
|
|
162
202
|
workDir,
|
|
203
|
+
assets: source.assets,
|
|
163
204
|
...signKeyPem ? { finalizeManifest: (manifest) => signManifest(manifest, signKeyPem) } : {},
|
|
164
205
|
onProgress: ({ done, total }) => {
|
|
165
206
|
if (!process.stderr.isTTY || total === 0) return;
|
|
@@ -250,7 +291,7 @@ async function runKnowledgeSearch(path, query, opts, deps = {}) {
|
|
|
250
291
|
for (const hit of docHits) {
|
|
251
292
|
const doc = handle.getDocument(hit.documentId);
|
|
252
293
|
console.log(
|
|
253
|
-
` ${doc?.title ?? hit.documentId} ${formatKnowledgeUri({ catalogId: manifest.id, documentId: hit.documentId })}`
|
|
294
|
+
` ${doc?.title ?? hit.documentId} ${formatKnowledgeUri({ publisherId: manifest.publisher.id, catalogId: manifest.id, documentId: hit.documentId })}`
|
|
254
295
|
);
|
|
255
296
|
}
|
|
256
297
|
}
|
|
@@ -277,6 +318,7 @@ async function runKnowledgeSearch(path, query, opts, deps = {}) {
|
|
|
277
318
|
console.log(opts.semantic ? "Passages (semantic + full-text):" : "Passages (full-text):");
|
|
278
319
|
for (const hit of deduped.slice(0, limit)) {
|
|
279
320
|
const uri = formatKnowledgeUri({
|
|
321
|
+
publisherId: manifest.publisher.id,
|
|
280
322
|
catalogId: manifest.id,
|
|
281
323
|
documentId: hit.documentId,
|
|
282
324
|
fragment: { chunk: hit.chunkUid }
|
|
@@ -341,9 +383,51 @@ function formatBytes(bytes) {
|
|
|
341
383
|
function contentSha256(bytes) {
|
|
342
384
|
return createHash2("sha256").update(bytes).digest("hex");
|
|
343
385
|
}
|
|
386
|
+
async function runKnowledgeExportParquet(path, opts) {
|
|
387
|
+
const { DUCKDB_VERSION, duckdbInstalledBinary } = await import("@bendyline/gezel/native");
|
|
388
|
+
const { exportCatalogParquet, findDuckdbBinary } = await import("@bendyline/gezel-knowledge");
|
|
389
|
+
const resolved = resolve2(path);
|
|
390
|
+
const info = await stat(resolved).catch(() => null);
|
|
391
|
+
if (!info) throw new CliError(`no such catalog: ${resolved}`);
|
|
392
|
+
const source = info.isDirectory() ? { rootDir: resolved } : { archivePath: resolved };
|
|
393
|
+
const outDir = opts.out ? resolve2(opts.out) : join2(dirname2(resolved), `${basename2(resolved).replace(/\.gezk$/i, "")}-parquet`);
|
|
394
|
+
const installed = duckdbInstalledBinary(process.env.GEZEL_HOME ?? join2(homedir2(), ".gezel"));
|
|
395
|
+
const binaryPath = opts.duckdb ?? process.env.GEZEL_DUCKDB_BIN?.trim() ?? (await stat(installed).catch(() => null) ? installed : await findDuckdbBinary());
|
|
396
|
+
if (!binaryPath) {
|
|
397
|
+
throw new CliError(
|
|
398
|
+
`no DuckDB CLI found \u2014 open a data feature in gezel once (it installs DuckDB ${DUCKDB_VERSION}), install DuckDB yourself, or pass --duckdb <binary>`
|
|
399
|
+
);
|
|
400
|
+
}
|
|
401
|
+
const report = await exportCatalogParquet({
|
|
402
|
+
source,
|
|
403
|
+
outDir,
|
|
404
|
+
duckdb: { binaryPath, ...opts.duckdb ? {} : { expectedVersion: DUCKDB_VERSION } },
|
|
405
|
+
onProgress: (event) => {
|
|
406
|
+
if (!process.stderr.isTTY) return;
|
|
407
|
+
if (event.phase === "extract") process.stderr.write("extracting the archive\u2026\n");
|
|
408
|
+
else if (event.phase === "stage") {
|
|
409
|
+
process.stderr.write(
|
|
410
|
+
`staged ${event.table}${event.shardId !== void 0 ? ` shard ${event.shardId}` : ""}: ${event.rows} rows
|
|
411
|
+
`
|
|
412
|
+
);
|
|
413
|
+
} else process.stderr.write(`writing ${event.file}
|
|
414
|
+
`);
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
console.log(`Parquet companion of ${report.catalogId}@${report.version} \u2192 ${outDir}`);
|
|
418
|
+
for (const file of report.files) {
|
|
419
|
+
console.log(
|
|
420
|
+
` ${file.path.padEnd(24)} ${String(file.rows).padStart(9)} rows ${(file.sizeBytes / (1024 * 1024)).toFixed(1).padStart(8)} MB ${file.sha256.slice(0, 16)}\u2026`
|
|
421
|
+
);
|
|
422
|
+
}
|
|
423
|
+
console.log(
|
|
424
|
+
` written with DuckDB ${report.duckdbVersion}; report in ${join2(outDir, "parquet-manifest.json")}`
|
|
425
|
+
);
|
|
426
|
+
}
|
|
344
427
|
export {
|
|
345
428
|
contentSha256,
|
|
346
429
|
runKnowledgeBuild,
|
|
430
|
+
runKnowledgeExportParquet,
|
|
347
431
|
runKnowledgeInit,
|
|
348
432
|
runKnowledgeInspect,
|
|
349
433
|
runKnowledgeSearch,
|
package/dist/tui/index.js
CHANGED
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
import {
|
|
25
25
|
GezelApiError,
|
|
26
26
|
GezelClient,
|
|
27
|
+
LiveDaemonUnhealthyError,
|
|
27
28
|
createTrustingFetch,
|
|
28
29
|
discoverOrSpawn,
|
|
29
30
|
electronNativeBinCandidates,
|
|
@@ -1521,36 +1522,47 @@ function ChatFeed(props) {
|
|
|
1521
1522
|
const { rows, gezels, boring, focusedSessionId, visible = 16 } = props;
|
|
1522
1523
|
const visibleRows = rows.filter((row) => row.kind !== "write" || row.text.length > 0);
|
|
1523
1524
|
const shown = visibleRows.slice(Math.max(0, visibleRows.length - visible));
|
|
1524
|
-
return /* @__PURE__ */ jsx(
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1525
|
+
return /* @__PURE__ */ jsx(
|
|
1526
|
+
Box,
|
|
1527
|
+
{
|
|
1528
|
+
flexDirection: "column",
|
|
1529
|
+
flexGrow: 1,
|
|
1530
|
+
maxHeight: visible,
|
|
1531
|
+
overflowY: "hidden",
|
|
1532
|
+
justifyContent: "flex-end",
|
|
1533
|
+
marginBottom: 1,
|
|
1534
|
+
children: shown.length === 0 ? /* @__PURE__ */ jsxs(Box, { flexDirection: "row", children: [
|
|
1535
|
+
/* @__PURE__ */ jsx(Text, { color: "yellow", children: TABLE_LOGO }),
|
|
1536
|
+
/* @__PURE__ */ jsxs(Box, { flexDirection: "column", marginLeft: 3, children: [
|
|
1537
|
+
/* @__PURE__ */ jsxs(Text, { children: [
|
|
1538
|
+
"gezel ",
|
|
1539
|
+
GEZEL_VERSION
|
|
1540
|
+
] }),
|
|
1541
|
+
/* @__PURE__ */ jsx(Text, { dimColor: true, children: "Type a message to begin" }),
|
|
1542
|
+
/* @__PURE__ */ jsx(Text, { dimColor: true, children: "/help for commands" })
|
|
1543
|
+
] })
|
|
1544
|
+
] }) : shown.map((row) => {
|
|
1545
|
+
const rowStyle = CHAT_FEED_ROW_STYLES[row.kind];
|
|
1546
|
+
if (row.kind === "shell" && row.sessionId.startsWith("term-")) {
|
|
1547
|
+
return /* @__PURE__ */ jsx(Box, { flexShrink: 0, children: /* @__PURE__ */ jsx(Text, { wrap: "wrap", children: clip(row.text) }) }, row.key);
|
|
1548
|
+
}
|
|
1549
|
+
const who = row.kind === "user" ? "you" : row.kind === "pending" ? "pending" : row.kind === "thinking" ? "thinking" : row.kind === "write" ? "writing" : row.gezelId ? gezelLabel(row.gezelId, gezels, boring) : row.kind === "tool" ? "tool" : row.kind === "shell" ? "shell" : row.kind === "error" ? "error" : "system";
|
|
1550
|
+
const isFocused = focusedSessionId && row.sessionId === focusedSessionId;
|
|
1551
|
+
return /* @__PURE__ */ jsxs(Box, { flexDirection: "row", flexShrink: 0, children: [
|
|
1552
|
+
/* @__PURE__ */ jsx(Text, { dimColor: !isFocused, color: isFocused ? "green" : void 0, children: isFocused ? "\u258E" : " " }),
|
|
1553
|
+
/* @__PURE__ */ jsxs(Text, { wrap: "wrap", children: [
|
|
1554
|
+
/* @__PURE__ */ jsxs(Text, { bold: true, color: rowStyle.color, children: [
|
|
1555
|
+
who,
|
|
1556
|
+
": "
|
|
1557
|
+
] }),
|
|
1558
|
+
/* @__PURE__ */ jsx(Text, { color: rowStyle.color, dimColor: rowStyle.dimColor, children: clip(
|
|
1559
|
+
row.taskEvent ? taskEventText(row, gezels, boring) : row.kind === "assistant" ? humanizeToolMarkup(row.text) : row.text
|
|
1560
|
+
) })
|
|
1561
|
+
] })
|
|
1562
|
+
] }, row.key);
|
|
1563
|
+
})
|
|
1538
1564
|
}
|
|
1539
|
-
|
|
1540
|
-
const isFocused = focusedSessionId && row.sessionId === focusedSessionId;
|
|
1541
|
-
return /* @__PURE__ */ jsxs(Box, { flexDirection: "row", children: [
|
|
1542
|
-
/* @__PURE__ */ jsx(Text, { dimColor: !isFocused, color: isFocused ? "green" : void 0, children: isFocused ? "\u258E" : " " }),
|
|
1543
|
-
/* @__PURE__ */ jsxs(Text, { wrap: "wrap", children: [
|
|
1544
|
-
/* @__PURE__ */ jsxs(Text, { bold: true, color: rowStyle.color, children: [
|
|
1545
|
-
who,
|
|
1546
|
-
": "
|
|
1547
|
-
] }),
|
|
1548
|
-
/* @__PURE__ */ jsx(Text, { color: rowStyle.color, dimColor: rowStyle.dimColor, children: clip(
|
|
1549
|
-
row.taskEvent ? taskEventText(row, gezels, boring) : row.kind === "assistant" ? humanizeToolMarkup(row.text) : row.text
|
|
1550
|
-
) })
|
|
1551
|
-
] })
|
|
1552
|
-
] }, row.key);
|
|
1553
|
-
}) });
|
|
1565
|
+
);
|
|
1554
1566
|
}
|
|
1555
1567
|
function taskEventText(row, gezels, boring) {
|
|
1556
1568
|
const event = row.taskEvent;
|
|
@@ -4963,15 +4975,17 @@ function BootstrapGate(props) {
|
|
|
4963
4975
|
const options = [
|
|
4964
4976
|
...best ? [
|
|
4965
4977
|
{
|
|
4966
|
-
label: `Recommended
|
|
4967
|
-
hint: `${bestInstalled ? "chat model already available \xB7 " : ""}${workshopDownloadBytes > 0 ? formatDownloadSize(workshopDownloadBytes) : "already available"}${workshopHelperLabels ? ` \xB7 includes ${workshopHelperLabels}` : ""}`,
|
|
4968
|
-
value: "bundle"
|
|
4969
|
-
},
|
|
4970
|
-
{
|
|
4971
|
-
label: `${bestInstalled ? "Use" : "Download"} ${bootstrapChatModelLabel(best)} only`,
|
|
4978
|
+
label: `Recommended \u2014 ${bestInstalled ? "Use" : "Download"} ${bootstrapChatModelLabel(best)}`,
|
|
4972
4979
|
hint: `recommended for this device \xB7 ${bestInstalled ? "already available" : formatDownloadSize(best.approxSizeBytes)}`,
|
|
4973
4980
|
value: bestInstalled ? `installed:${best.id}` : `chat:${best.id}`
|
|
4974
|
-
}
|
|
4981
|
+
},
|
|
4982
|
+
...screen.plan.accessories.length > 0 ? [
|
|
4983
|
+
{
|
|
4984
|
+
label: `Complete workshop set \u2014 ${bootstrapChatModelLabel(best)} + ${screen.plan.accessories.length} ${screen.plan.accessories.length === 1 ? "helper" : "helpers"}`,
|
|
4985
|
+
hint: `optional \xB7 ${bestInstalled ? "chat model already available \xB7 " : ""}${workshopDownloadBytes > 0 ? formatDownloadSize(workshopDownloadBytes) : "already available"}${workshopHelperLabels ? ` \xB7 includes ${workshopHelperLabels}` : ""}`,
|
|
4986
|
+
value: "bundle"
|
|
4987
|
+
}
|
|
4988
|
+
] : []
|
|
4975
4989
|
] : [],
|
|
4976
4990
|
...screen.plan.installedChatModels.filter((model) => model.id !== best?.id).map((model) => ({
|
|
4977
4991
|
label: `Use ${model.name ?? model.id}${model.attribution ? ` (${model.attribution})` : ""}`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bendyline/gezel-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "The `gezel` command-line tool.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -44,15 +44,15 @@
|
|
|
44
44
|
"!dist/**/*.map"
|
|
45
45
|
],
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@bendyline/gezel": "1.
|
|
48
|
-
"@bendyline/gezel-app-sdk": "1.0.
|
|
49
|
-
"@bendyline/gezel-catalog": "1.
|
|
50
|
-
"@bendyline/gezel-client": "1.
|
|
51
|
-
"@bendyline/gezel-knowledge": "1.
|
|
52
|
-
"@bendyline/gezel-service": "1.
|
|
53
|
-
"@bendyline/squisq": "2.
|
|
54
|
-
"@bendyline/squisq-formats": "2.
|
|
55
|
-
"@bendyline/squisq-react": "2.
|
|
47
|
+
"@bendyline/gezel": "1.1.1",
|
|
48
|
+
"@bendyline/gezel-app-sdk": "1.0.9",
|
|
49
|
+
"@bendyline/gezel-catalog": "1.1.1",
|
|
50
|
+
"@bendyline/gezel-client": "1.1.1",
|
|
51
|
+
"@bendyline/gezel-knowledge": "1.1.1",
|
|
52
|
+
"@bendyline/gezel-service": "1.1.1",
|
|
53
|
+
"@bendyline/squisq": "2.11.3",
|
|
54
|
+
"@bendyline/squisq-formats": "2.6.3",
|
|
55
|
+
"@bendyline/squisq-react": "2.11.3",
|
|
56
56
|
"commander": "^15.0.0",
|
|
57
57
|
"ink": "^7.1.1",
|
|
58
58
|
"ink-text-input": "^6.0.0",
|