@bendyline/gezel-cli 1.2.2 → 1.2.4
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 +99 -16
- package/dist/app-author-command.js +1 -1
- package/dist/app-command.js +3 -3
- package/dist/bin/gezel-main.js +995 -453
- package/dist/handboek-export.js +564 -8
- package/dist/knowledge-command.js +82 -7
- package/dist/tui/index.js +5 -2
- package/package.json +10 -10
|
@@ -6,7 +6,11 @@ import { existsSync } from "fs";
|
|
|
6
6
|
import { mkdir as mkdir2, mkdtemp, readFile as readFile2, readdir, rm as rm2, stat, writeFile as writeFile2 } from "fs/promises";
|
|
7
7
|
import { homedir as homedir2, tmpdir } from "os";
|
|
8
8
|
import { basename as basename2, dirname as dirname2, isAbsolute, join as join2, relative, resolve as resolve2 } from "path";
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
KnowledgeIdSchema,
|
|
11
|
+
KnowledgeRadiusSchema,
|
|
12
|
+
formatKnowledgeUri
|
|
13
|
+
} from "@bendyline/gezel";
|
|
10
14
|
import {
|
|
11
15
|
CatalogHandle,
|
|
12
16
|
EmbedderUnavailableError,
|
|
@@ -27,7 +31,7 @@ import {
|
|
|
27
31
|
|
|
28
32
|
// src/connection.ts
|
|
29
33
|
import { createHash, randomUUID } from "crypto";
|
|
30
|
-
import { chmod, mkdir, readFile, rm, writeFile } from "fs/promises";
|
|
34
|
+
import { chmod, mkdir, readFile, realpath, rm, writeFile } from "fs/promises";
|
|
31
35
|
import { homedir } from "os";
|
|
32
36
|
import { basename, dirname, join, resolve } from "path";
|
|
33
37
|
import {
|
|
@@ -70,6 +74,26 @@ var CliError = class extends Error {
|
|
|
70
74
|
// src/knowledge-command.ts
|
|
71
75
|
var CATALOG_JSON = "catalog.json";
|
|
72
76
|
var CONTENT_DIR = "content";
|
|
77
|
+
async function defaultCreateMediaEmbedder(profile) {
|
|
78
|
+
const { createCatalogMediaEmbedder } = await import("@bendyline/gezel-service/media");
|
|
79
|
+
return createCatalogMediaEmbedder(profile, {
|
|
80
|
+
cacheDir: hfCacheDir(),
|
|
81
|
+
onWarning: (message) => console.warn(`warning: ${message}`)
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
function withAssetAttribution(assets, attribution) {
|
|
85
|
+
if (!attribution) return assets;
|
|
86
|
+
const known = new Set(assets.map((a) => a.path));
|
|
87
|
+
for (const key of Object.keys(attribution)) {
|
|
88
|
+
const path = key.startsWith("assets/") ? key : `assets/${key}`;
|
|
89
|
+
if (!known.has(path))
|
|
90
|
+
console.warn(`warning: catalog.json assets: '${key}' is not an asset of this catalog`);
|
|
91
|
+
}
|
|
92
|
+
return assets.map((asset) => {
|
|
93
|
+
const entry = attribution[asset.path] ?? attribution[asset.path.replace(/^assets\//, "")];
|
|
94
|
+
return entry ? { ...asset, attribution: entry } : asset;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
73
97
|
function hfCacheDir() {
|
|
74
98
|
if (process.env.GEZEL_HF_CACHE_DIR) return process.env.GEZEL_HF_CACHE_DIR;
|
|
75
99
|
const home = process.env.GEZEL_HOME ?? join2(homedir2(), ".gezel");
|
|
@@ -205,6 +229,7 @@ async function runKnowledgeBuild(dir, opts, deps = {}) {
|
|
|
205
229
|
uri: { publisherId: config.publisher.id, catalogId: config.id },
|
|
206
230
|
...config.ignore ? { ignore: config.ignore } : {},
|
|
207
231
|
toc,
|
|
232
|
+
skipImages: opts.skipImages ?? false,
|
|
208
233
|
onWarning: (message) => console.warn(`warning: ${message}`)
|
|
209
234
|
});
|
|
210
235
|
console.log(`Content: ${displayPath(root, contentRoot)}`);
|
|
@@ -221,6 +246,7 @@ async function runKnowledgeBuild(dir, opts, deps = {}) {
|
|
|
221
246
|
);
|
|
222
247
|
console.log("Loading the embedding model (first run downloads it)\u2026");
|
|
223
248
|
const embedder = await (deps.createEmbedder ?? defaultCreateEmbedder)(profileId);
|
|
249
|
+
const media = profile.media ? await (deps.createMediaEmbedder ?? defaultCreateMediaEmbedder)(profile) : null;
|
|
224
250
|
const signKeyPem = opts.signKey ? await readFile2(resolve2(opts.signKey), "utf8") : null;
|
|
225
251
|
const outputPath = resolve2(opts.out ?? join2(root, `${config.id}-${config.version}.gezk`));
|
|
226
252
|
const workDir = await mkdtemp(join2(tmpdir(), "gezk-build-"));
|
|
@@ -247,7 +273,10 @@ async function runKnowledgeBuild(dir, opts, deps = {}) {
|
|
|
247
273
|
embed: (texts) => embedder.embed(texts),
|
|
248
274
|
countTokens: (text) => embedder.countTokens(text),
|
|
249
275
|
workDir,
|
|
250
|
-
assets: source.assets,
|
|
276
|
+
assets: withAssetAttribution(source.assets, config.assets),
|
|
277
|
+
...media ? { embedMedia: media.embedMedia } : {},
|
|
278
|
+
invalidAssets: "warn",
|
|
279
|
+
onWarning: (message) => console.warn(`warning: ${message}`),
|
|
251
280
|
...signKeyPem ? { finalizeManifest: (manifest) => signManifest(manifest, signKeyPem) } : {},
|
|
252
281
|
onProgress: ({ done, total }) => {
|
|
253
282
|
if (!process.stderr.isTTY || total === 0) return;
|
|
@@ -259,12 +288,15 @@ async function runKnowledgeBuild(dir, opts, deps = {}) {
|
|
|
259
288
|
}
|
|
260
289
|
});
|
|
261
290
|
if (process.stderr.isTTY && lastPct >= 0) process.stderr.write("\n");
|
|
291
|
+
const mediaRows = report.media.image + report.media.video + report.media.audio;
|
|
262
292
|
console.log(
|
|
263
|
-
`Wrote ${outputPath} \u2014 ${report.documents} documents, ${report.chunks} chunks, ${report.shards} shard${report.shards === 1 ? "" : "s"}, ${formatBytes(report.archiveBytes)}${report.manifest.signature ? `, signed (key ${report.manifest.signature.keyId})` : ""}`
|
|
293
|
+
`Wrote ${outputPath} \u2014 ${report.documents} documents, ${report.chunks} chunks, ${mediaRows > 0 ? `${mediaRows} media rows, ` : ""}${report.shards} shard${report.shards === 1 ? "" : "s"}, ${formatBytes(report.archiveBytes)}${report.manifest.signature ? `, signed (key ${report.manifest.signature.keyId})` : ""}`
|
|
264
294
|
);
|
|
265
295
|
} finally {
|
|
266
296
|
await embedder.dispose().catch(() => {
|
|
267
297
|
});
|
|
298
|
+
await media?.dispose().catch(() => {
|
|
299
|
+
});
|
|
268
300
|
await rm2(workDir, { recursive: true, force: true });
|
|
269
301
|
}
|
|
270
302
|
}
|
|
@@ -324,6 +356,16 @@ async function runKnowledgeInspect(path) {
|
|
|
324
356
|
for (const [key, value] of rows) console.log(`${key.padEnd(width)} ${value}`);
|
|
325
357
|
}
|
|
326
358
|
async function runKnowledgeSearch(path, query, opts, deps = {}) {
|
|
359
|
+
const supplied = [opts.latitude, opts.longitude, opts.radiusMeters].filter(
|
|
360
|
+
(value) => value !== void 0
|
|
361
|
+
).length;
|
|
362
|
+
if (supplied !== 0 && supplied !== 3)
|
|
363
|
+
throw new CliError("Provide --latitude, --longitude and --radius-meters together.");
|
|
364
|
+
const spatial = supplied ? KnowledgeRadiusSchema.parse({
|
|
365
|
+
latitude: opts.latitude,
|
|
366
|
+
longitude: opts.longitude,
|
|
367
|
+
radiusMeters: opts.radiusMeters
|
|
368
|
+
}) : void 0;
|
|
327
369
|
const limit = Math.min(50, Math.max(1, opts.limit ?? 10));
|
|
328
370
|
const { rootDir, cleanup } = await materializeCatalog(path);
|
|
329
371
|
try {
|
|
@@ -332,7 +374,8 @@ async function runKnowledgeSearch(path, query, opts, deps = {}) {
|
|
|
332
374
|
);
|
|
333
375
|
const handle = CatalogHandle.open(rootDir);
|
|
334
376
|
try {
|
|
335
|
-
const
|
|
377
|
+
const allowed = spatial ? new Set(handle.spatialMatches(spatial).keys()) : void 0;
|
|
378
|
+
const docHits = handle.searchDocumentsFts(query, limit, allowed);
|
|
336
379
|
if (docHits.length > 0) {
|
|
337
380
|
console.log("Documents:");
|
|
338
381
|
for (const hit of docHits) {
|
|
@@ -345,7 +388,8 @@ async function runKnowledgeSearch(path, query, opts, deps = {}) {
|
|
|
345
388
|
let chunkHits = handle.searchChunksFts(
|
|
346
389
|
query,
|
|
347
390
|
handle.shards.map((s) => s.id),
|
|
348
|
-
Math.ceil(limit / Math.max(1, handle.shards.length))
|
|
391
|
+
Math.ceil(limit / Math.max(1, handle.shards.length)),
|
|
392
|
+
allowed
|
|
349
393
|
);
|
|
350
394
|
if (opts.semantic) {
|
|
351
395
|
const embedder = await (deps.createEmbedder ?? defaultCreateEmbedder)(
|
|
@@ -353,7 +397,10 @@ async function runKnowledgeSearch(path, query, opts, deps = {}) {
|
|
|
353
397
|
);
|
|
354
398
|
try {
|
|
355
399
|
const vector = await embedder.embedQuery(query);
|
|
356
|
-
chunkHits = [
|
|
400
|
+
chunkHits = [
|
|
401
|
+
...handle.searchSemantic(vector, { finalK: limit, allowedDocumentIds: allowed, query }),
|
|
402
|
+
...chunkHits
|
|
403
|
+
];
|
|
357
404
|
} finally {
|
|
358
405
|
await embedder.dispose().catch(() => {
|
|
359
406
|
});
|
|
@@ -471,6 +518,33 @@ async function runKnowledgeExportParquet(path, opts) {
|
|
|
471
518
|
` written with DuckDB ${report.duckdbVersion}; report in ${join2(outDir, "parquet-manifest.json")}`
|
|
472
519
|
);
|
|
473
520
|
}
|
|
521
|
+
async function runKnowledgeNearby(path, radius, opts = {}) {
|
|
522
|
+
const spatial = KnowledgeRadiusSchema.parse(radius);
|
|
523
|
+
const { rootDir, cleanup } = await materializeCatalog(path);
|
|
524
|
+
try {
|
|
525
|
+
const manifest = JSON.parse(
|
|
526
|
+
await readFile2(join2(rootDir, "manifest.json"), "utf8")
|
|
527
|
+
);
|
|
528
|
+
const handle = CatalogHandle.open(rootDir);
|
|
529
|
+
try {
|
|
530
|
+
const result = handle.nearbyDocuments(spatial, { limit: opts.limit });
|
|
531
|
+
if (opts.json) console.log(JSON.stringify(result, null, 2));
|
|
532
|
+
else {
|
|
533
|
+
console.log(
|
|
534
|
+
`${result.total} articles within ${(spatial.radiusMeters / 1e3).toFixed(1)} km`
|
|
535
|
+
);
|
|
536
|
+
for (const doc of result.documents)
|
|
537
|
+
console.log(
|
|
538
|
+
` ${(doc.distanceMeters / 1e3).toFixed(2)} km ${doc.title} ${formatKnowledgeUri({ publisherId: manifest.publisher.id, catalogId: manifest.id, documentId: doc.id })}`
|
|
539
|
+
);
|
|
540
|
+
}
|
|
541
|
+
} finally {
|
|
542
|
+
handle.close();
|
|
543
|
+
}
|
|
544
|
+
} finally {
|
|
545
|
+
await cleanup();
|
|
546
|
+
}
|
|
547
|
+
}
|
|
474
548
|
export {
|
|
475
549
|
contentSha256,
|
|
476
550
|
embeddingRuntimeMissingMessage,
|
|
@@ -478,6 +552,7 @@ export {
|
|
|
478
552
|
runKnowledgeExportParquet,
|
|
479
553
|
runKnowledgeInit,
|
|
480
554
|
runKnowledgeInspect,
|
|
555
|
+
runKnowledgeNearby,
|
|
481
556
|
runKnowledgeSearch,
|
|
482
557
|
runKnowledgeValidate
|
|
483
558
|
};
|
package/dist/tui/index.js
CHANGED
|
@@ -12,7 +12,7 @@ import { useCallback as useCallback2, useEffect as useEffect4, useMemo, useRef a
|
|
|
12
12
|
|
|
13
13
|
// src/connection.ts
|
|
14
14
|
import { createHash, randomUUID } from "crypto";
|
|
15
|
-
import { chmod, mkdir, readFile, rm, writeFile } from "fs/promises";
|
|
15
|
+
import { chmod, mkdir, readFile, realpath, rm, writeFile } from "fs/promises";
|
|
16
16
|
import { homedir } from "os";
|
|
17
17
|
import { basename, dirname, join, resolve } from "path";
|
|
18
18
|
import {
|
|
@@ -2235,6 +2235,7 @@ function normalizeCraftbooks(items, showWorkInProgressFeatures = false) {
|
|
|
2235
2235
|
...manifest.description ? { description: manifest.description } : {},
|
|
2236
2236
|
version: manifest.version,
|
|
2237
2237
|
sourceId: item.sourceId,
|
|
2238
|
+
command: manifest.command ?? manifest.id,
|
|
2238
2239
|
source: item.sourceId === "project" ? "project" : item.sourceId === "local" ? "local" : "bundled",
|
|
2239
2240
|
stepCount: manifest.steps.length,
|
|
2240
2241
|
tags: manifest.tags ?? [],
|
|
@@ -2309,7 +2310,9 @@ function countLabel(count) {
|
|
|
2309
2310
|
}
|
|
2310
2311
|
function findCraftbook(books, value) {
|
|
2311
2312
|
const query = value.trim().toLowerCase();
|
|
2312
|
-
return books.find(
|
|
2313
|
+
return books.find(
|
|
2314
|
+
(book) => book.id.toLowerCase() === query || book.command?.toLowerCase() === query || book.name.toLowerCase() === query
|
|
2315
|
+
);
|
|
2313
2316
|
}
|
|
2314
2317
|
function craftbookStartRequest(book) {
|
|
2315
2318
|
const summary = book.description?.trim();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bendyline/gezel-cli",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.4",
|
|
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.2.
|
|
48
|
-
"@bendyline/gezel-app-sdk": "1.1.
|
|
49
|
-
"@bendyline/gezel-catalog": "1.2.
|
|
50
|
-
"@bendyline/gezel-client": "1.2.
|
|
51
|
-
"@bendyline/gezel-knowledge": "1.2.
|
|
52
|
-
"@bendyline/gezel-service": "1.2.
|
|
53
|
-
"@bendyline/squisq": "2.11.
|
|
54
|
-
"@bendyline/squisq-formats": "2.6.
|
|
55
|
-
"@bendyline/squisq-react": "2.11.
|
|
47
|
+
"@bendyline/gezel": "1.2.4",
|
|
48
|
+
"@bendyline/gezel-app-sdk": "1.1.4",
|
|
49
|
+
"@bendyline/gezel-catalog": "1.2.4",
|
|
50
|
+
"@bendyline/gezel-client": "1.2.4",
|
|
51
|
+
"@bendyline/gezel-knowledge": "1.2.4",
|
|
52
|
+
"@bendyline/gezel-service": "1.2.4",
|
|
53
|
+
"@bendyline/squisq": "2.11.17",
|
|
54
|
+
"@bendyline/squisq-formats": "2.6.17",
|
|
55
|
+
"@bendyline/squisq-react": "2.11.19",
|
|
56
56
|
"commander": "^15.0.0",
|
|
57
57
|
"ink": "^7.1.1",
|
|
58
58
|
"ink-text-input": "^6.0.0",
|