@bendyline/gezel-cli 1.2.1 → 1.2.3
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 +38 -6
- package/dist/app-author-command.js +2 -0
- package/dist/app-command.js +2 -0
- package/dist/bin/gezel-main.js +47 -8
- package/dist/knowledge-command.js +92 -15
- package/dist/tui/index.js +9 -0
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -54,17 +54,26 @@ With no connection flags, the CLI follows this order:
|
|
|
54
54
|
service that stops with the command. The interactive TUI
|
|
55
55
|
retains ownership when it starts a daemon itself, so exiting the TUI runs
|
|
56
56
|
the daemon's complete shutdown path and cleans up its local engine children.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
|
|
58
|
+
For the per-user local daemon, the CLI connects with your same-user owner
|
|
59
|
+
credential from the protected runtime directory. This works on first use and
|
|
60
|
+
when adopting an already-running daemon, with no desktop approval prompt. The
|
|
61
|
+
npm package is sufficient for local CLI use; you do not need to install or open
|
|
62
|
+
the desktop app.
|
|
62
63
|
|
|
63
64
|
`gezel run` has one deliberate lifecycle exception: if no user daemon exists,
|
|
64
65
|
it starts a user-role service in-process for that one invocation and stops it
|
|
65
66
|
afterward. It does not take that fallback after a denied grant or when a live
|
|
66
67
|
daemon is unhealthy.
|
|
67
68
|
|
|
69
|
+
External service connections use a separate authorization path: an explicit
|
|
70
|
+
`--connect <url>`, or an older `legacy-full` machine service selected in step 1,
|
|
71
|
+
requires a CLI-scoped grant. If there is no valid saved grant or supplied
|
|
72
|
+
`--token`, the terminal shows a six-character code and waits for you to approve
|
|
73
|
+
**Gezel CLI** in the Gezel app. The resulting revocable credential is saved
|
|
74
|
+
under `~/.gezel/cli/tokens/` for that service. A valid saved grant or explicit
|
|
75
|
+
`--token` lets the connection proceed without that interaction.
|
|
76
|
+
|
|
68
77
|
The per-user daemon owns gezels, projects, settings, credentials, and
|
|
69
78
|
conversations with ordinary user filesystem permissions. It discovers the
|
|
70
79
|
machine engine broker independently for centralized model downloads and local
|
|
@@ -170,10 +179,33 @@ export async function run({ client, projectId, workspace, args, log, runCraftboo
|
|
|
170
179
|
|
|
171
180
|
Run it with `gezel workflow storyify c23n --json`. The module receives the
|
|
172
181
|
public `GezelClient`, the directory's project id, its absolute workspace,
|
|
173
|
-
arguments, a stderr logger,
|
|
182
|
+
arguments, a stderr logger, `complete(request)` (below), and
|
|
183
|
+
`runCraftbook(id, params, options)`. That helper
|
|
174
184
|
starts a **project** craftbook and waits; options include `timeoutMs`, a saved
|
|
175
185
|
`taskRef` to follow, `parentTaskRef` to link the child to its batch, and
|
|
176
186
|
`onCreated(task)` to checkpoint the new reference.
|
|
187
|
+
When a step needs model judgment on input the driver already holds — extract
|
|
188
|
+
the facts in this page, check this paragraph against these quotations — use
|
|
189
|
+
`complete(request)` instead of a craftbook. It makes one bounded call on the
|
|
190
|
+
project's engine queue and returns `{ content, json?, jsonError?, elapsedMs }`:
|
|
191
|
+
|
|
192
|
+
```js
|
|
193
|
+
const { json } = await complete({
|
|
194
|
+
gezelId: 'checker', // or provider + model
|
|
195
|
+
system: 'You are a meticulous fact-checker.',
|
|
196
|
+
prompt: `FACTS:\n${facts}\n\nSENTENCES:\n${sentences}`,
|
|
197
|
+
jsonSchema: verdictSchema, // grammar-constrained on local engines
|
|
198
|
+
thinking: false, // skip a local model's reasoning phase
|
|
199
|
+
maxTokens: 4000,
|
|
200
|
+
timeoutMs: 300_000,
|
|
201
|
+
label: 'check · Taylorville ¶3',
|
|
202
|
+
});
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
No tools, session or transcript are involved, so there is nothing to read
|
|
206
|
+
back and nothing to save: the driver validates the answer and persists what it
|
|
207
|
+
keeps. Use a craftbook when the work genuinely needs tools or a person.
|
|
208
|
+
|
|
177
209
|
For drivers that generate craftbook documents, `validateCraftbook(document)`
|
|
178
210
|
checks the same schema and step contracts as the daemon and returns the runtime
|
|
179
211
|
craftbook. Call it before installing files or freezing a batch checkpoint;
|
|
@@ -277,6 +277,7 @@ import {
|
|
|
277
277
|
getLogLevel,
|
|
278
278
|
getLogOutput,
|
|
279
279
|
pickRandomNameWithGender,
|
|
280
|
+
projectLeadGezelId,
|
|
280
281
|
setLogLevel,
|
|
281
282
|
setLogOutput
|
|
282
283
|
} from "@bendyline/gezel";
|
|
@@ -293,6 +294,7 @@ import {
|
|
|
293
294
|
discoverOrSpawn,
|
|
294
295
|
electronNativeBinCandidates,
|
|
295
296
|
ensureProjectForFolder as ensureClientProjectForFolder,
|
|
297
|
+
forbiddenProjectFolderName,
|
|
296
298
|
isProcessAlive,
|
|
297
299
|
readRuntime,
|
|
298
300
|
readSystemServiceEndpoint,
|
package/dist/app-command.js
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
getLogLevel,
|
|
15
15
|
getLogOutput,
|
|
16
16
|
pickRandomNameWithGender,
|
|
17
|
+
projectLeadGezelId,
|
|
17
18
|
setLogLevel,
|
|
18
19
|
setLogOutput
|
|
19
20
|
} from "@bendyline/gezel";
|
|
@@ -30,6 +31,7 @@ import {
|
|
|
30
31
|
discoverOrSpawn,
|
|
31
32
|
electronNativeBinCandidates,
|
|
32
33
|
ensureProjectForFolder as ensureClientProjectForFolder,
|
|
34
|
+
forbiddenProjectFolderName,
|
|
33
35
|
isProcessAlive,
|
|
34
36
|
readRuntime,
|
|
35
37
|
readSystemServiceEndpoint,
|
package/dist/bin/gezel-main.js
CHANGED
|
@@ -65,6 +65,7 @@ import {
|
|
|
65
65
|
getLogLevel,
|
|
66
66
|
getLogOutput,
|
|
67
67
|
pickRandomNameWithGender,
|
|
68
|
+
projectLeadGezelId,
|
|
68
69
|
setLogLevel,
|
|
69
70
|
setLogOutput
|
|
70
71
|
} from "@bendyline/gezel";
|
|
@@ -81,6 +82,7 @@ import {
|
|
|
81
82
|
discoverOrSpawn,
|
|
82
83
|
electronNativeBinCandidates,
|
|
83
84
|
ensureProjectForFolder as ensureClientProjectForFolder,
|
|
85
|
+
forbiddenProjectFolderName,
|
|
84
86
|
isProcessAlive,
|
|
85
87
|
readRuntime,
|
|
86
88
|
readSystemServiceEndpoint,
|
|
@@ -619,9 +621,37 @@ async function ensureProjectForFolder(client, folderPath) {
|
|
|
619
621
|
});
|
|
620
622
|
return result.projectId;
|
|
621
623
|
}
|
|
624
|
+
var DEFAULT_PROJECT_ID = "default";
|
|
625
|
+
function defaultProjectNotice(folder, name) {
|
|
626
|
+
return `Using the Default project: gezel does not make a project of ${name} (${folder}). To work in a project, run gezel from its folder or pass --project <folder>.
|
|
627
|
+
`;
|
|
628
|
+
}
|
|
629
|
+
async function resolveCommandProject(client, globals) {
|
|
630
|
+
const p = globals.project;
|
|
631
|
+
const folder = resolve(typeof p === "string" ? p : process.cwd());
|
|
632
|
+
try {
|
|
633
|
+
return await ensureProjectForFolder(client, folder);
|
|
634
|
+
} catch (err) {
|
|
635
|
+
const name = forbiddenProjectFolderName(err);
|
|
636
|
+
if (!name) throw err;
|
|
637
|
+
if (p === true || typeof p === "string") {
|
|
638
|
+
throw new CliError(
|
|
639
|
+
`gezel does not make a project of ${name} (${folder}). Pass --project with a project folder, or leave out --project to use the Default project.`
|
|
640
|
+
);
|
|
641
|
+
}
|
|
642
|
+
process.stderr.write(defaultProjectNotice(folder, name));
|
|
643
|
+
return DEFAULT_PROJECT_ID;
|
|
644
|
+
}
|
|
645
|
+
}
|
|
622
646
|
async function ensureCliProjectLead(client, projectId) {
|
|
623
647
|
const project = await client.getProject(projectId);
|
|
624
648
|
if (project.voormanGezelId) return project.voormanGezelId;
|
|
649
|
+
if (project.id === DEFAULT_PROJECT_ID) {
|
|
650
|
+
const { meesterGezelId } = await client.getConfig();
|
|
651
|
+
const lead = projectLeadGezelId(project, meesterGezelId);
|
|
652
|
+
if (!lead) throw new CliError("the Default project has no Meester yet");
|
|
653
|
+
return lead;
|
|
654
|
+
}
|
|
625
655
|
if (project.mode === "solo") {
|
|
626
656
|
if (project.gezelIds?.[0]) return project.gezelIds[0];
|
|
627
657
|
if (project.workingDir) {
|
|
@@ -655,14 +685,10 @@ async function ensureCliProjectLead(client, projectId) {
|
|
|
655
685
|
return updated.voormanGezelId;
|
|
656
686
|
}
|
|
657
687
|
async function resolveRunProject(client, globals) {
|
|
658
|
-
|
|
659
|
-
const folder = p === void 0 || p === true || p === false ? process.cwd() : p;
|
|
660
|
-
return ensureProjectForFolder(client, folder);
|
|
688
|
+
return resolveCommandProject(client, globals);
|
|
661
689
|
}
|
|
662
690
|
async function resolveTuiProject(client, globals) {
|
|
663
|
-
|
|
664
|
-
const folder = p === void 0 || p === true || p === false ? process.cwd() : p;
|
|
665
|
-
return ensureProjectForFolder(client, folder);
|
|
691
|
+
return resolveCommandProject(client, globals);
|
|
666
692
|
}
|
|
667
693
|
|
|
668
694
|
// src/craftbook-command.ts
|
|
@@ -1766,6 +1792,9 @@ async function runWorkflow(client, projectId, workspace, file, args, log = conso
|
|
|
1766
1792
|
...invocation ?? {},
|
|
1767
1793
|
log,
|
|
1768
1794
|
validateCraftbook: validateWorkflowCraftbook,
|
|
1795
|
+
// A bounded model call whose input the driver already holds. Cheaper and
|
|
1796
|
+
// more reliable than a task that must read its input back through tools.
|
|
1797
|
+
complete: (request, signal) => client.completeInProject(projectId, request, signal),
|
|
1769
1798
|
runCraftbook: async (id, params, options = {}) => {
|
|
1770
1799
|
let ref = options.taskRef;
|
|
1771
1800
|
if (!ref) {
|
|
@@ -2509,7 +2538,7 @@ knowledge.command("init <dir>").description("Scaffold a catalog folder (catalog.
|
|
|
2509
2538
|
const { runKnowledgeInit } = await loadKnowledgeCommand();
|
|
2510
2539
|
await runKnowledgeInit(dir);
|
|
2511
2540
|
});
|
|
2512
|
-
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) => {
|
|
2541
|
+
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").option("--skip-images", "Build without image assets, keeping image alt text").action(async (dir, opts) => {
|
|
2513
2542
|
const { runKnowledgeBuild } = await loadKnowledgeCommand();
|
|
2514
2543
|
await runKnowledgeBuild(dir, opts);
|
|
2515
2544
|
});
|
|
@@ -2530,10 +2559,20 @@ knowledge.command("export-parquet <path>").description(
|
|
|
2530
2559
|
const { runKnowledgeExportParquet } = await loadKnowledgeCommand();
|
|
2531
2560
|
await runKnowledgeExportParquet(path, opts);
|
|
2532
2561
|
});
|
|
2533
|
-
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) => {
|
|
2562
|
+
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) => {
|
|
2534
2563
|
const { runKnowledgeSearch } = await loadKnowledgeCommand();
|
|
2535
2564
|
await runKnowledgeSearch(path, query, opts);
|
|
2536
2565
|
});
|
|
2566
|
+
knowledge.command("nearby <path>").description("Find articles near a coordinate in a catalog file, offline").requiredOption("--latitude <degrees>", "center latitude", Number).requiredOption("--longitude <degrees>", "center longitude", Number).requiredOption("--radius-meters <meters>", "subject radius in meters", Number).option("--limit <n>", "page size (maximum 500)", Number, 50).option("--json", "emit document metadata and distances as JSON").action(
|
|
2567
|
+
async (path, opts) => {
|
|
2568
|
+
const { runKnowledgeNearby } = await loadKnowledgeCommand();
|
|
2569
|
+
await runKnowledgeNearby(
|
|
2570
|
+
path,
|
|
2571
|
+
{ latitude: opts.latitude, longitude: opts.longitude, radiusMeters: opts.radiusMeters },
|
|
2572
|
+
opts
|
|
2573
|
+
);
|
|
2574
|
+
}
|
|
2575
|
+
);
|
|
2537
2576
|
knowledge.command("available").description("List the knowledge catalogs the gilde offers for download").action(async () => {
|
|
2538
2577
|
const client = await connectOwned(cliGlobals());
|
|
2539
2578
|
const { catalogs } = await client.listAvailableKnowledgeCatalogs();
|
|
@@ -3,10 +3,14 @@
|
|
|
3
3
|
// src/knowledge-command.ts
|
|
4
4
|
import { createHash as createHash2 } from "crypto";
|
|
5
5
|
import { existsSync } from "fs";
|
|
6
|
-
import { mkdir as mkdir2, mkdtemp, readFile as readFile2, rm as rm2, stat, writeFile as writeFile2 } from "fs/promises";
|
|
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
|
-
import { basename as basename2, dirname as dirname2, join as join2, relative, resolve as resolve2 } from "path";
|
|
9
|
-
import {
|
|
8
|
+
import { basename as basename2, dirname as dirname2, isAbsolute, join as join2, relative, resolve as resolve2 } from "path";
|
|
9
|
+
import {
|
|
10
|
+
KnowledgeIdSchema,
|
|
11
|
+
KnowledgeRadiusSchema,
|
|
12
|
+
formatKnowledgeUri
|
|
13
|
+
} from "@bendyline/gezel";
|
|
10
14
|
import {
|
|
11
15
|
CatalogHandle,
|
|
12
16
|
EmbedderUnavailableError,
|
|
@@ -34,6 +38,7 @@ import {
|
|
|
34
38
|
getLogLevel,
|
|
35
39
|
getLogOutput,
|
|
36
40
|
pickRandomNameWithGender,
|
|
41
|
+
projectLeadGezelId,
|
|
37
42
|
setLogLevel,
|
|
38
43
|
setLogOutput
|
|
39
44
|
} from "@bendyline/gezel";
|
|
@@ -50,6 +55,7 @@ import {
|
|
|
50
55
|
discoverOrSpawn,
|
|
51
56
|
electronNativeBinCandidates,
|
|
52
57
|
ensureProjectForFolder as ensureClientProjectForFolder,
|
|
58
|
+
forbiddenProjectFolderName,
|
|
53
59
|
isProcessAlive,
|
|
54
60
|
readRuntime,
|
|
55
61
|
readSystemServiceEndpoint,
|
|
@@ -99,6 +105,15 @@ function embeddingRuntimeMissingMessage() {
|
|
|
99
105
|
"The Gezel desktop app already includes it, and full-text search works without it."
|
|
100
106
|
].join("\n");
|
|
101
107
|
}
|
|
108
|
+
async function holdsMarkdown(dir) {
|
|
109
|
+
const entries = await readdir(dir, { withFileTypes: true }).catch(() => []);
|
|
110
|
+
const visible = entries.filter((e) => !e.name.startsWith(".") && e.name !== "node_modules");
|
|
111
|
+
if (visible.some((e) => e.isFile() && /\.(md|markdown)$/i.test(e.name))) return true;
|
|
112
|
+
for (const entry of visible) {
|
|
113
|
+
if (entry.isDirectory() && await holdsMarkdown(join2(dir, entry.name))) return true;
|
|
114
|
+
}
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
102
117
|
async function runKnowledgeInit(dir) {
|
|
103
118
|
const root = resolve2(dir);
|
|
104
119
|
const configPath = join2(root, CATALOG_JSON);
|
|
@@ -107,7 +122,8 @@ async function runKnowledgeInit(dir) {
|
|
|
107
122
|
() => false
|
|
108
123
|
);
|
|
109
124
|
if (exists) throw new CliError(`${configPath} already exists`);
|
|
110
|
-
await
|
|
125
|
+
const inPlace = await holdsMarkdown(root);
|
|
126
|
+
await mkdir2(inPlace ? root : join2(root, CONTENT_DIR, "Getting Started"), { recursive: true });
|
|
111
127
|
const id = sanitizeCatalogId(basename2(root));
|
|
112
128
|
const config = {
|
|
113
129
|
id,
|
|
@@ -121,16 +137,25 @@ async function runKnowledgeInit(dir) {
|
|
|
121
137
|
};
|
|
122
138
|
await writeFile2(configPath, `${JSON.stringify(config, null, 2)}
|
|
123
139
|
`, "utf8");
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
140
|
+
if (!inPlace) {
|
|
141
|
+
await writeFile2(
|
|
142
|
+
join2(root, CONTENT_DIR, "Getting Started", "welcome.md"),
|
|
143
|
+
"# Welcome\n\nPut Markdown files under content/ \u2014 folders become the table of contents.\n",
|
|
144
|
+
"utf8"
|
|
145
|
+
);
|
|
146
|
+
}
|
|
129
147
|
console.log(`Initialized knowledge catalog at ${root}`);
|
|
130
148
|
console.log(` ${CATALOG_JSON} \u2014 identity, license, embedding profile`);
|
|
131
|
-
|
|
149
|
+
if (inPlace) {
|
|
150
|
+
const toc = await detectTableOfContents(root);
|
|
151
|
+
console.log(
|
|
152
|
+
` The Markdown already in this folder is the content (table of contents: ${describeToc(toc, root)})`
|
|
153
|
+
);
|
|
154
|
+
} else {
|
|
155
|
+
console.log(` ${CONTENT_DIR}/ \u2014 Markdown content (folders become topics)`);
|
|
156
|
+
}
|
|
132
157
|
console.log(
|
|
133
|
-
" An outline the tree already has is honored: SUMMARY.md, an mkdocs.yml nav, _toc.yml, or Hugo _index.md pages"
|
|
158
|
+
" An outline the tree already has is honored: SUMMARY.md, an mkdocs.yml nav, _toc.yml, docfx toc.yml files, or Hugo _index.md pages"
|
|
134
159
|
);
|
|
135
160
|
console.log(`Build with: gezel knowledge build ${dir}`);
|
|
136
161
|
}
|
|
@@ -165,9 +190,14 @@ async function resolveContentRoot(root, config) {
|
|
|
165
190
|
}
|
|
166
191
|
return root;
|
|
167
192
|
}
|
|
193
|
+
function displayPath(root, path) {
|
|
194
|
+
const rel = relative(root, path);
|
|
195
|
+
if (rel === "") return ".";
|
|
196
|
+
return rel.startsWith("..") || isAbsolute(rel) ? path : rel;
|
|
197
|
+
}
|
|
168
198
|
function describeToc(toc, root) {
|
|
169
199
|
const source = toc.format === "folders" ? "folders" : toc.format === "hugo" ? "Hugo conventions (_index.md, weight)" : toc.format;
|
|
170
|
-
return toc.path ? `${source} (${
|
|
200
|
+
return toc.path ? `${source} (${displayPath(root, toc.path)})` : source;
|
|
171
201
|
}
|
|
172
202
|
async function runKnowledgeBuild(dir, opts, deps = {}) {
|
|
173
203
|
const root = resolve2(dir);
|
|
@@ -179,8 +209,10 @@ async function runKnowledgeBuild(dir, opts, deps = {}) {
|
|
|
179
209
|
uri: { publisherId: config.publisher.id, catalogId: config.id },
|
|
180
210
|
...config.ignore ? { ignore: config.ignore } : {},
|
|
181
211
|
toc,
|
|
212
|
+
skipImages: opts.skipImages ?? false,
|
|
182
213
|
onWarning: (message) => console.warn(`warning: ${message}`)
|
|
183
214
|
});
|
|
215
|
+
console.log(`Content: ${displayPath(root, contentRoot)}`);
|
|
184
216
|
console.log(`Table of contents: ${describeToc(source.toc, root)}`);
|
|
185
217
|
const profileId = config.profile ?? "bge-small-en-v1.5@1";
|
|
186
218
|
const profile = knowledgeEmbeddingProfile(profileId);
|
|
@@ -221,6 +253,8 @@ async function runKnowledgeBuild(dir, opts, deps = {}) {
|
|
|
221
253
|
countTokens: (text) => embedder.countTokens(text),
|
|
222
254
|
workDir,
|
|
223
255
|
assets: source.assets,
|
|
256
|
+
invalidAssets: "warn",
|
|
257
|
+
onWarning: (message) => console.warn(`warning: ${message}`),
|
|
224
258
|
...signKeyPem ? { finalizeManifest: (manifest) => signManifest(manifest, signKeyPem) } : {},
|
|
225
259
|
onProgress: ({ done, total }) => {
|
|
226
260
|
if (!process.stderr.isTTY || total === 0) return;
|
|
@@ -297,6 +331,16 @@ async function runKnowledgeInspect(path) {
|
|
|
297
331
|
for (const [key, value] of rows) console.log(`${key.padEnd(width)} ${value}`);
|
|
298
332
|
}
|
|
299
333
|
async function runKnowledgeSearch(path, query, opts, deps = {}) {
|
|
334
|
+
const supplied = [opts.latitude, opts.longitude, opts.radiusMeters].filter(
|
|
335
|
+
(value) => value !== void 0
|
|
336
|
+
).length;
|
|
337
|
+
if (supplied !== 0 && supplied !== 3)
|
|
338
|
+
throw new CliError("Provide --latitude, --longitude and --radius-meters together.");
|
|
339
|
+
const spatial = supplied ? KnowledgeRadiusSchema.parse({
|
|
340
|
+
latitude: opts.latitude,
|
|
341
|
+
longitude: opts.longitude,
|
|
342
|
+
radiusMeters: opts.radiusMeters
|
|
343
|
+
}) : void 0;
|
|
300
344
|
const limit = Math.min(50, Math.max(1, opts.limit ?? 10));
|
|
301
345
|
const { rootDir, cleanup } = await materializeCatalog(path);
|
|
302
346
|
try {
|
|
@@ -305,7 +349,8 @@ async function runKnowledgeSearch(path, query, opts, deps = {}) {
|
|
|
305
349
|
);
|
|
306
350
|
const handle = CatalogHandle.open(rootDir);
|
|
307
351
|
try {
|
|
308
|
-
const
|
|
352
|
+
const allowed = spatial ? new Set(handle.spatialMatches(spatial).keys()) : void 0;
|
|
353
|
+
const docHits = handle.searchDocumentsFts(query, limit, allowed);
|
|
309
354
|
if (docHits.length > 0) {
|
|
310
355
|
console.log("Documents:");
|
|
311
356
|
for (const hit of docHits) {
|
|
@@ -318,7 +363,8 @@ async function runKnowledgeSearch(path, query, opts, deps = {}) {
|
|
|
318
363
|
let chunkHits = handle.searchChunksFts(
|
|
319
364
|
query,
|
|
320
365
|
handle.shards.map((s) => s.id),
|
|
321
|
-
Math.ceil(limit / Math.max(1, handle.shards.length))
|
|
366
|
+
Math.ceil(limit / Math.max(1, handle.shards.length)),
|
|
367
|
+
allowed
|
|
322
368
|
);
|
|
323
369
|
if (opts.semantic) {
|
|
324
370
|
const embedder = await (deps.createEmbedder ?? defaultCreateEmbedder)(
|
|
@@ -326,7 +372,10 @@ async function runKnowledgeSearch(path, query, opts, deps = {}) {
|
|
|
326
372
|
);
|
|
327
373
|
try {
|
|
328
374
|
const vector = await embedder.embedQuery(query);
|
|
329
|
-
chunkHits = [
|
|
375
|
+
chunkHits = [
|
|
376
|
+
...handle.searchSemantic(vector, { finalK: limit, allowedDocumentIds: allowed, query }),
|
|
377
|
+
...chunkHits
|
|
378
|
+
];
|
|
330
379
|
} finally {
|
|
331
380
|
await embedder.dispose().catch(() => {
|
|
332
381
|
});
|
|
@@ -444,6 +493,33 @@ async function runKnowledgeExportParquet(path, opts) {
|
|
|
444
493
|
` written with DuckDB ${report.duckdbVersion}; report in ${join2(outDir, "parquet-manifest.json")}`
|
|
445
494
|
);
|
|
446
495
|
}
|
|
496
|
+
async function runKnowledgeNearby(path, radius, opts = {}) {
|
|
497
|
+
const spatial = KnowledgeRadiusSchema.parse(radius);
|
|
498
|
+
const { rootDir, cleanup } = await materializeCatalog(path);
|
|
499
|
+
try {
|
|
500
|
+
const manifest = JSON.parse(
|
|
501
|
+
await readFile2(join2(rootDir, "manifest.json"), "utf8")
|
|
502
|
+
);
|
|
503
|
+
const handle = CatalogHandle.open(rootDir);
|
|
504
|
+
try {
|
|
505
|
+
const result = handle.nearbyDocuments(spatial, { limit: opts.limit });
|
|
506
|
+
if (opts.json) console.log(JSON.stringify(result, null, 2));
|
|
507
|
+
else {
|
|
508
|
+
console.log(
|
|
509
|
+
`${result.total} articles within ${(spatial.radiusMeters / 1e3).toFixed(1)} km`
|
|
510
|
+
);
|
|
511
|
+
for (const doc of result.documents)
|
|
512
|
+
console.log(
|
|
513
|
+
` ${(doc.distanceMeters / 1e3).toFixed(2)} km ${doc.title} ${formatKnowledgeUri({ publisherId: manifest.publisher.id, catalogId: manifest.id, documentId: doc.id })}`
|
|
514
|
+
);
|
|
515
|
+
}
|
|
516
|
+
} finally {
|
|
517
|
+
handle.close();
|
|
518
|
+
}
|
|
519
|
+
} finally {
|
|
520
|
+
await cleanup();
|
|
521
|
+
}
|
|
522
|
+
}
|
|
447
523
|
export {
|
|
448
524
|
contentSha256,
|
|
449
525
|
embeddingRuntimeMissingMessage,
|
|
@@ -451,6 +527,7 @@ export {
|
|
|
451
527
|
runKnowledgeExportParquet,
|
|
452
528
|
runKnowledgeInit,
|
|
453
529
|
runKnowledgeInspect,
|
|
530
|
+
runKnowledgeNearby,
|
|
454
531
|
runKnowledgeSearch,
|
|
455
532
|
runKnowledgeValidate
|
|
456
533
|
};
|
package/dist/tui/index.js
CHANGED
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
getLogLevel,
|
|
20
20
|
getLogOutput,
|
|
21
21
|
pickRandomNameWithGender,
|
|
22
|
+
projectLeadGezelId,
|
|
22
23
|
setLogLevel,
|
|
23
24
|
setLogOutput
|
|
24
25
|
} from "@bendyline/gezel";
|
|
@@ -35,6 +36,7 @@ import {
|
|
|
35
36
|
discoverOrSpawn,
|
|
36
37
|
electronNativeBinCandidates,
|
|
37
38
|
ensureProjectForFolder as ensureClientProjectForFolder,
|
|
39
|
+
forbiddenProjectFolderName,
|
|
38
40
|
isProcessAlive,
|
|
39
41
|
readRuntime,
|
|
40
42
|
readSystemServiceEndpoint,
|
|
@@ -49,9 +51,16 @@ var CliError = class extends Error {
|
|
|
49
51
|
this.name = "CliError";
|
|
50
52
|
}
|
|
51
53
|
};
|
|
54
|
+
var DEFAULT_PROJECT_ID = "default";
|
|
52
55
|
async function ensureCliProjectLead(client, projectId) {
|
|
53
56
|
const project = await client.getProject(projectId);
|
|
54
57
|
if (project.voormanGezelId) return project.voormanGezelId;
|
|
58
|
+
if (project.id === DEFAULT_PROJECT_ID) {
|
|
59
|
+
const { meesterGezelId } = await client.getConfig();
|
|
60
|
+
const lead = projectLeadGezelId(project, meesterGezelId);
|
|
61
|
+
if (!lead) throw new CliError("the Default project has no Meester yet");
|
|
62
|
+
return lead;
|
|
63
|
+
}
|
|
55
64
|
if (project.mode === "solo") {
|
|
56
65
|
if (project.gezelIds?.[0]) return project.gezelIds[0];
|
|
57
66
|
if (project.workingDir) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bendyline/gezel-cli",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
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.3",
|
|
48
|
+
"@bendyline/gezel-app-sdk": "1.1.3",
|
|
49
|
+
"@bendyline/gezel-catalog": "1.2.3",
|
|
50
|
+
"@bendyline/gezel-client": "1.2.3",
|
|
51
|
+
"@bendyline/gezel-knowledge": "1.2.3",
|
|
52
|
+
"@bendyline/gezel-service": "1.2.3",
|
|
53
|
+
"@bendyline/squisq": "2.11.13",
|
|
54
|
+
"@bendyline/squisq-formats": "2.6.12",
|
|
55
|
+
"@bendyline/squisq-react": "2.11.15",
|
|
56
56
|
"commander": "^15.0.0",
|
|
57
57
|
"ink": "^7.1.1",
|
|
58
58
|
"ink-text-input": "^6.0.0",
|