@bendyline/gezel-cli 1.2.0 → 1.2.2

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 CHANGED
@@ -45,7 +45,13 @@ With no connection flags, the CLI follows this order:
45
45
  2. Discover the logged-in user's product daemon through the same pinned
46
46
  runtime discovery used by the Gezel app SDK. Its actual dynamic port and
47
47
  pinned TLS certificate come from `~/.gezel/runtime`; management commands
48
- may start that user-role daemon when it is absent. The interactive TUI
48
+ may start that user-role daemon when it is absent, and say so on stderr
49
+ because it keeps running afterwards (`gezel stop --daemon` ends it). A
50
+ daemon the CLI starts keeps its own log in
51
+ `~/.gezel/logs/service-YYYY-MM-DD.log` (rolled at 10 MB, kept 7 days).
52
+ Read-only diagnostics such as `gezel native status` and `native list`
53
+ never leave one behind: with no daemon running they answer from a
54
+ service that stops with the command. The interactive TUI
49
55
  retains ownership when it starts a daemon itself, so exiting the TUI runs
50
56
  the daemon's complete shutdown path and cleans up its local engine children.
51
57
  3. On first use, the terminal waits while the Gezel app asks you to approve
@@ -164,10 +170,33 @@ export async function run({ client, projectId, workspace, args, log, runCraftboo
164
170
 
165
171
  Run it with `gezel workflow storyify c23n --json`. The module receives the
166
172
  public `GezelClient`, the directory's project id, its absolute workspace,
167
- arguments, a stderr logger, and `runCraftbook(id, params, options)`. That helper
173
+ arguments, a stderr logger, `complete(request)` (below), and
174
+ `runCraftbook(id, params, options)`. That helper
168
175
  starts a **project** craftbook and waits; options include `timeoutMs`, a saved
169
176
  `taskRef` to follow, `parentTaskRef` to link the child to its batch, and
170
177
  `onCreated(task)` to checkpoint the new reference.
178
+ When a step needs model judgment on input the driver already holds — extract
179
+ the facts in this page, check this paragraph against these quotations — use
180
+ `complete(request)` instead of a craftbook. It makes one bounded call on the
181
+ project's engine queue and returns `{ content, json?, jsonError?, elapsedMs }`:
182
+
183
+ ```js
184
+ const { json } = await complete({
185
+ gezelId: 'checker', // or provider + model
186
+ system: 'You are a meticulous fact-checker.',
187
+ prompt: `FACTS:\n${facts}\n\nSENTENCES:\n${sentences}`,
188
+ jsonSchema: verdictSchema, // grammar-constrained on local engines
189
+ thinking: false, // skip a local model's reasoning phase
190
+ maxTokens: 4000,
191
+ timeoutMs: 300_000,
192
+ label: 'check · Taylorville ¶3',
193
+ });
194
+ ```
195
+
196
+ No tools, session or transcript are involved, so there is nothing to read
197
+ back and nothing to save: the driver validates the answer and persists what it
198
+ keeps. Use a craftbook when the work genuinely needs tools or a person.
199
+
171
200
  For drivers that generate craftbook documents, `validateCraftbook(document)`
172
201
  checks the same schema and step contracts as the daemon and returns the runtime
173
202
  craftbook. Call it before installing files or freezing a batch checkpoint;
@@ -218,6 +247,21 @@ you can use:
218
247
  - Gezel and project management (`gezel agent`, `gezel project`, `gezel task`)
219
248
  - Skills and handbook export (`gezel skills convert`, `gezel handboek export`) —
220
249
  these need no running daemon at all
250
+ - Knowledge catalogs you already have: `gezel knowledge validate`, `inspect`
251
+ and full-text `search` work offline, with no daemon
252
+
253
+ Building a catalog (`gezel knowledge build`) and `gezel knowledge search
254
+ --semantic` also need the embedding runtime, which an npm install leaves out.
255
+ Add it where Gezel is installed (drop `-g` for a project install); the desktop
256
+ app already includes it:
257
+
258
+ ```bash
259
+ npm install -g @huggingface/transformers@^3.8.1
260
+ ```
261
+
262
+ In a project install, also add the `overrides` from the
263
+ [`@bendyline/gezel-service` README](https://www.npmjs.com/package/@bendyline/gezel-service):
264
+ Transformers still asks for a `sharp` release that `npm audit` flags.
221
265
 
222
266
  ## Running models on your own machine
223
267
 
@@ -273,7 +273,14 @@ import { createHash, randomUUID } from "crypto";
273
273
  import { chmod, mkdir, readFile, rm, writeFile } from "fs/promises";
274
274
  import { homedir } from "os";
275
275
  import { basename, dirname, join, resolve } from "path";
276
- import { pickRandomNameWithGender } from "@bendyline/gezel";
276
+ import {
277
+ getLogLevel,
278
+ getLogOutput,
279
+ pickRandomNameWithGender,
280
+ projectLeadGezelId,
281
+ setLogLevel,
282
+ setLogOutput
283
+ } from "@bendyline/gezel";
277
284
  import {
278
285
  GezelSdkError,
279
286
  authorizeLocal,
@@ -287,6 +294,7 @@ import {
287
294
  discoverOrSpawn,
288
295
  electronNativeBinCandidates,
289
296
  ensureProjectForFolder as ensureClientProjectForFolder,
297
+ forbiddenProjectFolderName,
290
298
  isProcessAlive,
291
299
  readRuntime,
292
300
  readSystemServiceEndpoint,
@@ -10,7 +10,14 @@ import { createHash, randomUUID } from "crypto";
10
10
  import { chmod, mkdir, readFile, rm, writeFile } from "fs/promises";
11
11
  import { homedir } from "os";
12
12
  import { basename, dirname, join, resolve } from "path";
13
- import { pickRandomNameWithGender } from "@bendyline/gezel";
13
+ import {
14
+ getLogLevel,
15
+ getLogOutput,
16
+ pickRandomNameWithGender,
17
+ projectLeadGezelId,
18
+ setLogLevel,
19
+ setLogOutput
20
+ } from "@bendyline/gezel";
14
21
  import {
15
22
  GezelSdkError,
16
23
  authorizeLocal,
@@ -24,6 +31,7 @@ import {
24
31
  discoverOrSpawn,
25
32
  electronNativeBinCandidates,
26
33
  ensureProjectForFolder as ensureClientProjectForFolder,
34
+ forbiddenProjectFolderName,
27
35
  isProcessAlive,
28
36
  readRuntime,
29
37
  readSystemServiceEndpoint,
@@ -4,13 +4,12 @@
4
4
  import { basename as basename4, isAbsolute as isAbsolutePath, join as joinPath } from "path";
5
5
  import {
6
6
  GEZEL_VERSION,
7
- getLogLevel,
8
- getLogOutput,
9
- setLogLevel,
10
- setLogOutput
7
+ getLogLevel as getLogLevel2,
8
+ getLogOutput as getLogOutput2,
9
+ setLogLevel as setLogLevel2,
10
+ setLogOutput as setLogOutput2
11
11
  } from "@bendyline/gezel";
12
12
  import {
13
- GezelApiError as GezelApiError3,
14
13
  streamChatEvents
15
14
  } from "@bendyline/gezel-client";
16
15
  import {
@@ -62,7 +61,14 @@ import { createHash, randomUUID } from "crypto";
62
61
  import { chmod, mkdir, readFile, rm, writeFile } from "fs/promises";
63
62
  import { homedir } from "os";
64
63
  import { basename, dirname, join, resolve } from "path";
65
- import { pickRandomNameWithGender } from "@bendyline/gezel";
64
+ import {
65
+ getLogLevel,
66
+ getLogOutput,
67
+ pickRandomNameWithGender,
68
+ projectLeadGezelId,
69
+ setLogLevel,
70
+ setLogOutput
71
+ } from "@bendyline/gezel";
66
72
  import {
67
73
  GezelSdkError,
68
74
  authorizeLocal,
@@ -76,6 +82,7 @@ import {
76
82
  discoverOrSpawn,
77
83
  electronNativeBinCandidates,
78
84
  ensureProjectForFolder as ensureClientProjectForFolder,
85
+ forbiddenProjectFolderName,
79
86
  isProcessAlive,
80
87
  readRuntime,
81
88
  readSystemServiceEndpoint,
@@ -84,6 +91,31 @@ import {
84
91
  systemSharedAssetsDir
85
92
  } from "@bendyline/gezel-client/node";
86
93
  import { gezelPaths } from "@bendyline/gezel/paths";
94
+
95
+ // src/signal-cleanup.ts
96
+ function installSignalCleanup(cleanup, options = {}) {
97
+ if (!cleanup) return () => {
98
+ };
99
+ const host = options.host ?? process;
100
+ let cleanupPromise;
101
+ const onSignal = (signal) => {
102
+ host.exitCode = signal === "SIGINT" ? 130 : 143;
103
+ cleanupPromise ??= cleanup().catch((error) => {
104
+ options.onError?.(error);
105
+ host.exitCode = 1;
106
+ });
107
+ };
108
+ const onSigint = () => onSignal("SIGINT");
109
+ const onSigterm = () => onSignal("SIGTERM");
110
+ host.on("SIGINT", onSigint);
111
+ host.on("SIGTERM", onSigterm);
112
+ return () => {
113
+ host.off("SIGINT", onSigint);
114
+ host.off("SIGTERM", onSigterm);
115
+ };
116
+ }
117
+
118
+ // src/connection.ts
87
119
  var CliError = class extends Error {
88
120
  constructor(message) {
89
121
  super(message);
@@ -131,7 +163,7 @@ function resolveDevHome(globals) {
131
163
  process.env.GEZEL_HOME = join(homedir(), ".gezel-dev");
132
164
  }
133
165
  }
134
- async function connectOwned(globals) {
166
+ async function connectOwned(globals, options = {}) {
135
167
  applyHome(globals);
136
168
  const preferred = await connectPreferredService(globals);
137
169
  if (preferred) return preferred.client;
@@ -148,6 +180,9 @@ async function connectOwned(globals) {
148
180
  ...process.env.GEZEL_HOME ? { home: process.env.GEZEL_HOME } : {}
149
181
  }
150
182
  });
183
+ if (authorized.daemon.mode === "spawned" && options.announceSpawn !== false) {
184
+ process.stderr.write(spawnedDaemonNotice(authorized.daemon.pid));
185
+ }
151
186
  const connected = await connectionFromAuthorization(
152
187
  authorized,
153
188
  "The local Gezel owner authorization"
@@ -166,6 +201,8 @@ async function connectForTui(globals) {
166
201
  daemonEntry: resolveDaemonEntry(import.meta.url),
167
202
  detached: false,
168
203
  stdio: "pipe",
204
+ // The pipes below are drained and discarded, so the daemon keeps its own log.
205
+ writeLogFile: true,
169
206
  env: cliUserDaemonEnv(process.env.GEZEL_HOME, await shouldPreferCanonicalPort()),
170
207
  ...process.env.GEZEL_HOME ? { home: process.env.GEZEL_HOME } : {},
171
208
  timeoutMs: 2e4
@@ -279,6 +316,39 @@ async function connectForRun(globals) {
279
316
  };
280
317
  return { kind: "owned", client, baseUrl, stop };
281
318
  }
319
+ function spawnedDaemonNotice(pid) {
320
+ const which = pid === void 0 ? "" : ` (pid ${pid})`;
321
+ return `Started the Gezel background service${which}; it keeps running after this command. Stop it with \`gezel stop --daemon\`.
322
+ `;
323
+ }
324
+ async function withTransientConnection(globals, fn) {
325
+ const previousLogOutput = getLogOutput();
326
+ setLogOutput("stderr");
327
+ const previousLogLevel = getLogLevel();
328
+ if (!process.env.GEZEL_LOG_LEVEL && previousLogLevel === "info") setLogLevel("warn");
329
+ let conn;
330
+ let removeSignalCleanup;
331
+ try {
332
+ conn = await connectForRun(globals);
333
+ removeSignalCleanup = installSignalCleanup(conn.stop, {
334
+ onError: (error) => {
335
+ process.stderr.write(
336
+ `shutdown failed: ${error instanceof Error ? error.message : String(error)}
337
+ `
338
+ );
339
+ }
340
+ });
341
+ return await fn(conn.client);
342
+ } finally {
343
+ removeSignalCleanup?.();
344
+ try {
345
+ if (conn?.stop) await conn.stop();
346
+ } finally {
347
+ setLogOutput(previousLogOutput);
348
+ setLogLevel(previousLogLevel);
349
+ }
350
+ }
351
+ }
282
352
  var CLI_APP_ID_PREFIX = "gezel-cli";
283
353
  var CLI_APPROVAL_TIMEOUT_SEC = 300;
284
354
  var PENDING_GRANT_MINUTES = 10;
@@ -551,9 +621,37 @@ async function ensureProjectForFolder(client, folderPath) {
551
621
  });
552
622
  return result.projectId;
553
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
+ }
554
646
  async function ensureCliProjectLead(client, projectId) {
555
647
  const project = await client.getProject(projectId);
556
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
+ }
557
655
  if (project.mode === "solo") {
558
656
  if (project.gezelIds?.[0]) return project.gezelIds[0];
559
657
  if (project.workingDir) {
@@ -587,14 +685,10 @@ async function ensureCliProjectLead(client, projectId) {
587
685
  return updated.voormanGezelId;
588
686
  }
589
687
  async function resolveRunProject(client, globals) {
590
- const p = globals.project;
591
- const folder = p === void 0 || p === true || p === false ? process.cwd() : p;
592
- return ensureProjectForFolder(client, folder);
688
+ return resolveCommandProject(client, globals);
593
689
  }
594
690
  async function resolveTuiProject(client, globals) {
595
- const p = globals.project;
596
- const folder = p === void 0 || p === true || p === false ? process.cwd() : p;
597
- return ensureProjectForFolder(client, folder);
691
+ return resolveCommandProject(client, globals);
598
692
  }
599
693
 
600
694
  // src/craftbook-command.ts
@@ -766,7 +860,12 @@ async function waitForTask(client, ref, options) {
766
860
  signal
767
861
  )
768
862
  );
769
- const questionIds = questions.filter((q) => q.taskRef && refs.has(q.taskRef)).map((q) => q.id);
863
+ const questionIds = questions.filter(
864
+ (q) => q.taskRef && refs.has(q.taskRef) && // A service pause card is a historical notification. Actual task
865
+ // status above decides whether it is still paused; real session
866
+ // questions and permissions must continue to block observation.
867
+ !(q.sessionId === "" && q.intent?.kind === "task-paused")
868
+ ).map((q) => q.id);
770
869
  if (questionIds.length) return { task: task2, outcome: "blocked", exitCode: 2, questionIds };
771
870
  }
772
871
  if (budget.expired()) return { task: task2, outcome: "timeout", exitCode: 3 };
@@ -1430,29 +1529,6 @@ function registerProjectSettingsCommands(env2, connect, projectFor) {
1430
1529
  });
1431
1530
  }
1432
1531
 
1433
- // src/signal-cleanup.ts
1434
- function installSignalCleanup(cleanup, options = {}) {
1435
- if (!cleanup) return () => {
1436
- };
1437
- const host = options.host ?? process;
1438
- let cleanupPromise;
1439
- const onSignal = (signal) => {
1440
- host.exitCode = signal === "SIGINT" ? 130 : 143;
1441
- cleanupPromise ??= cleanup().catch((error) => {
1442
- options.onError?.(error);
1443
- host.exitCode = 1;
1444
- });
1445
- };
1446
- const onSigint = () => onSignal("SIGINT");
1447
- const onSigterm = () => onSignal("SIGTERM");
1448
- host.on("SIGINT", onSigint);
1449
- host.on("SIGTERM", onSigterm);
1450
- return () => {
1451
- host.off("SIGINT", onSigint);
1452
- host.off("SIGTERM", onSigterm);
1453
- };
1454
- }
1455
-
1456
1532
  // src/storage-format.ts
1457
1533
  function formatBytes2(bytes) {
1458
1534
  if (bytes >= 1024 ** 3) return `${(bytes / 1024 ** 3).toFixed(1)} GB`;
@@ -1716,6 +1792,9 @@ async function runWorkflow(client, projectId, workspace, file, args, log = conso
1716
1792
  ...invocation ?? {},
1717
1793
  log,
1718
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),
1719
1798
  runCraftbook: async (id, params, options = {}) => {
1720
1799
  let ref = options.taskRef;
1721
1800
  if (!ref) {
@@ -1861,7 +1940,7 @@ program.command("start").description("Start the Gezel daemon (no-op if already r
1861
1940
  if (opts.web) await printWebUrl(result.baseUrl, opts.open === true);
1862
1941
  return;
1863
1942
  }
1864
- const client = await connectOwned(cliGlobals());
1943
+ const client = await connectOwned(cliGlobals(), { announceSpawn: false });
1865
1944
  const health = await client.health();
1866
1945
  console.log(`gezeld running (version ${health.version})`);
1867
1946
  });
@@ -2096,10 +2175,10 @@ program.command("run [prompt...]").description("Run a prompt through a gezel and
2096
2175
  process.exitCode = 1;
2097
2176
  return;
2098
2177
  }
2099
- const previousLogOutput = getLogOutput();
2100
- setLogOutput("stderr");
2101
- const previousLogLevel = getLogLevel();
2102
- if (!process.env.GEZEL_LOG_LEVEL && previousLogLevel === "info") setLogLevel("warn");
2178
+ const previousLogOutput = getLogOutput2();
2179
+ setLogOutput2("stderr");
2180
+ const previousLogLevel = getLogLevel2();
2181
+ if (!process.env.GEZEL_LOG_LEVEL && previousLogLevel === "info") setLogLevel2("warn");
2103
2182
  let conn;
2104
2183
  let removeSignalCleanup;
2105
2184
  try {
@@ -2150,8 +2229,8 @@ ${ev.error}`);
2150
2229
  try {
2151
2230
  if (conn?.stop) await conn.stop();
2152
2231
  } finally {
2153
- setLogOutput(previousLogOutput);
2154
- setLogLevel(previousLogLevel);
2232
+ setLogOutput2(previousLogOutput);
2233
+ setLogLevel2(previousLogLevel);
2155
2234
  }
2156
2235
  }
2157
2236
  });
@@ -2506,17 +2585,7 @@ knowledge.command("install <source>").description("Install a .gezk catalog into
2506
2585
  ...opts.private ? { privatePlacement: true } : {}
2507
2586
  });
2508
2587
  const client = await connectOwned(cliGlobals());
2509
- let started;
2510
- try {
2511
- started = await client.installKnowledgeCatalog({ source: installSource });
2512
- } catch (err) {
2513
- if (err instanceof GezelApiError3 && err.status === 403) {
2514
- throw new CliError(
2515
- "Downloading knowledge catalogs needs app network access, which the security policy turns off (Settings \u2192 Security)."
2516
- );
2517
- }
2518
- throw err;
2519
- }
2588
+ const started = await client.installKnowledgeCatalog({ source: installSource });
2520
2589
  if (started.alreadyRunning)
2521
2590
  console.error("Attaching to the install that is already running.");
2522
2591
  let done;
@@ -2864,6 +2933,7 @@ program.command("create-audio [text...]").description("Synthesize speech from te
2864
2933
  `speech synthesis failed: ${err instanceof Error ? err.message : String(err)}`
2865
2934
  );
2866
2935
  }
2936
+ if (!res.artifactPath) throw new CliError("speech synthesis returned no saved audio");
2867
2937
  const dest = await saveArtifact(client, projectId, res.artifactPath, opts.output);
2868
2938
  const m = res.meta;
2869
2939
  console.log(dest);
@@ -2889,12 +2959,18 @@ ${formatNativeStatus(installed)}`
2889
2959
  );
2890
2960
  });
2891
2961
  native.command("list").description("List native executables and their install state").action(async () => {
2892
- const client = await connectOwned(cliGlobals());
2893
- console.log(formatNativeList(await client.getNativeEngineStatus()));
2962
+ const status = await withTransientConnection(
2963
+ cliGlobals(),
2964
+ (client) => client.getNativeEngineStatus()
2965
+ );
2966
+ console.log(formatNativeList(status));
2894
2967
  });
2895
2968
  native.command("status").description("Show native release, platform, backend, and toolkit status").action(async () => {
2896
- const client = await connectOwned(cliGlobals());
2897
- console.log(formatNativeStatus(await client.getNativeEngineStatus()));
2969
+ const status = await withTransientConnection(
2970
+ cliGlobals(),
2971
+ (client) => client.getNativeEngineStatus()
2972
+ );
2973
+ console.log(formatNativeStatus(status));
2898
2974
  });
2899
2975
  var image = program.command("image").description("Manage image-generation models");
2900
2976
  image.command("status").description("Show the image engine status and local model count").action(async () => {
package/dist/bin/gezel.js CHANGED
@@ -1,6 +1,22 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ // src/bin/node-version.ts
4
+ var MINIMUM_NODE_MAJOR = 24;
5
+ function unsupportedNodeMessage(version) {
6
+ const major = Number.parseInt(version, 10);
7
+ if (!Number.isFinite(major) || major >= MINIMUM_NODE_MAJOR) return void 0;
8
+ return `Gezel needs Node.js ${MINIMUM_NODE_MAJOR} or newer (found v${version}).
9
+ Install Node.js ${MINIMUM_NODE_MAJOR} or later from https://nodejs.org, then run the command again.
10
+ `;
11
+ }
12
+
3
13
  // src/bin/gezel-launcher.ts
4
14
  if (!process.env.NODE_ENV) process.env.NODE_ENV = "production";
5
15
  var mainModule = "./gezel-main.js";
6
- await import(mainModule);
16
+ var unsupported = unsupportedNodeMessage(process.versions.node);
17
+ if (unsupported) {
18
+ process.stderr.write(unsupported);
19
+ process.exitCode = 1;
20
+ } else {
21
+ await import(mainModule);
22
+ }
@@ -3,15 +3,16 @@
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";
8
+ import { basename as basename2, dirname as dirname2, isAbsolute, join as join2, relative, resolve as resolve2 } from "path";
9
9
  import { KnowledgeIdSchema, formatKnowledgeUri } from "@bendyline/gezel";
10
10
  import {
11
11
  CatalogHandle,
12
12
  EmbedderUnavailableError,
13
13
  KNOWLEDGE_EMBEDDING_PROFILES,
14
14
  MARKDOWN_CHUNKS_2,
15
+ TRANSFORMERS_PEER_RANGE,
15
16
  compileKnowledgeCatalog,
16
17
  createProfileEmbedder,
17
18
  detectTableOfContents,
@@ -29,7 +30,14 @@ import { createHash, randomUUID } from "crypto";
29
30
  import { chmod, mkdir, readFile, rm, writeFile } from "fs/promises";
30
31
  import { homedir } from "os";
31
32
  import { basename, dirname, join, resolve } from "path";
32
- import { pickRandomNameWithGender } from "@bendyline/gezel";
33
+ import {
34
+ getLogLevel,
35
+ getLogOutput,
36
+ pickRandomNameWithGender,
37
+ projectLeadGezelId,
38
+ setLogLevel,
39
+ setLogOutput
40
+ } from "@bendyline/gezel";
33
41
  import {
34
42
  GezelSdkError,
35
43
  authorizeLocal,
@@ -43,6 +51,7 @@ import {
43
51
  discoverOrSpawn,
44
52
  electronNativeBinCandidates,
45
53
  ensureProjectForFolder as ensureClientProjectForFolder,
54
+ forbiddenProjectFolderName,
46
55
  isProcessAlive,
47
56
  readRuntime,
48
57
  readSystemServiceEndpoint,
@@ -76,10 +85,31 @@ async function defaultCreateEmbedder(profileId) {
76
85
  try {
77
86
  return await createProfileEmbedder(profile, { cacheDir: hfCacheDir() });
78
87
  } catch (err) {
79
- if (err instanceof EmbedderUnavailableError) throw new CliError(err.message);
88
+ if (err instanceof EmbedderUnavailableError) {
89
+ throw new CliError(err.runtimeMissing ? embeddingRuntimeMissingMessage() : err.message);
90
+ }
80
91
  throw err;
81
92
  }
82
93
  }
94
+ function embeddingRuntimeMissingMessage() {
95
+ const spec = `@huggingface/transformers@${TRANSFORMERS_PEER_RANGE}`;
96
+ return [
97
+ "Building a catalog and --semantic search need the embedding runtime, which an npm install of Gezel leaves out.",
98
+ "Add it where Gezel is installed:",
99
+ ` npm install -g ${spec} if you installed gezel with npm install -g`,
100
+ ` npm install ${spec} in the project where you installed gezel`,
101
+ "The Gezel desktop app already includes it, and full-text search works without it."
102
+ ].join("\n");
103
+ }
104
+ async function holdsMarkdown(dir) {
105
+ const entries = await readdir(dir, { withFileTypes: true }).catch(() => []);
106
+ const visible = entries.filter((e) => !e.name.startsWith(".") && e.name !== "node_modules");
107
+ if (visible.some((e) => e.isFile() && /\.(md|markdown)$/i.test(e.name))) return true;
108
+ for (const entry of visible) {
109
+ if (entry.isDirectory() && await holdsMarkdown(join2(dir, entry.name))) return true;
110
+ }
111
+ return false;
112
+ }
83
113
  async function runKnowledgeInit(dir) {
84
114
  const root = resolve2(dir);
85
115
  const configPath = join2(root, CATALOG_JSON);
@@ -88,7 +118,8 @@ async function runKnowledgeInit(dir) {
88
118
  () => false
89
119
  );
90
120
  if (exists) throw new CliError(`${configPath} already exists`);
91
- await mkdir2(join2(root, CONTENT_DIR, "Getting Started"), { recursive: true });
121
+ const inPlace = await holdsMarkdown(root);
122
+ await mkdir2(inPlace ? root : join2(root, CONTENT_DIR, "Getting Started"), { recursive: true });
92
123
  const id = sanitizeCatalogId(basename2(root));
93
124
  const config = {
94
125
  id,
@@ -102,16 +133,25 @@ async function runKnowledgeInit(dir) {
102
133
  };
103
134
  await writeFile2(configPath, `${JSON.stringify(config, null, 2)}
104
135
  `, "utf8");
105
- await writeFile2(
106
- join2(root, CONTENT_DIR, "Getting Started", "welcome.md"),
107
- "# Welcome\n\nPut Markdown files under content/ \u2014 folders become the table of contents.\n",
108
- "utf8"
109
- );
136
+ if (!inPlace) {
137
+ await writeFile2(
138
+ join2(root, CONTENT_DIR, "Getting Started", "welcome.md"),
139
+ "# Welcome\n\nPut Markdown files under content/ \u2014 folders become the table of contents.\n",
140
+ "utf8"
141
+ );
142
+ }
110
143
  console.log(`Initialized knowledge catalog at ${root}`);
111
144
  console.log(` ${CATALOG_JSON} \u2014 identity, license, embedding profile`);
112
- console.log(` ${CONTENT_DIR}/ \u2014 Markdown content (folders become topics)`);
145
+ if (inPlace) {
146
+ const toc = await detectTableOfContents(root);
147
+ console.log(
148
+ ` The Markdown already in this folder is the content (table of contents: ${describeToc(toc, root)})`
149
+ );
150
+ } else {
151
+ console.log(` ${CONTENT_DIR}/ \u2014 Markdown content (folders become topics)`);
152
+ }
113
153
  console.log(
114
- " An outline the tree already has is honored: SUMMARY.md, an mkdocs.yml nav, _toc.yml, or Hugo _index.md pages"
154
+ " 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"
115
155
  );
116
156
  console.log(`Build with: gezel knowledge build ${dir}`);
117
157
  }
@@ -146,9 +186,14 @@ async function resolveContentRoot(root, config) {
146
186
  }
147
187
  return root;
148
188
  }
189
+ function displayPath(root, path) {
190
+ const rel = relative(root, path);
191
+ if (rel === "") return ".";
192
+ return rel.startsWith("..") || isAbsolute(rel) ? path : rel;
193
+ }
149
194
  function describeToc(toc, root) {
150
195
  const source = toc.format === "folders" ? "folders" : toc.format === "hugo" ? "Hugo conventions (_index.md, weight)" : toc.format;
151
- return toc.path ? `${source} (${relative(root, toc.path) || toc.path})` : source;
196
+ return toc.path ? `${source} (${displayPath(root, toc.path)})` : source;
152
197
  }
153
198
  async function runKnowledgeBuild(dir, opts, deps = {}) {
154
199
  const root = resolve2(dir);
@@ -162,6 +207,7 @@ async function runKnowledgeBuild(dir, opts, deps = {}) {
162
207
  toc,
163
208
  onWarning: (message) => console.warn(`warning: ${message}`)
164
209
  });
210
+ console.log(`Content: ${displayPath(root, contentRoot)}`);
165
211
  console.log(`Table of contents: ${describeToc(source.toc, root)}`);
166
212
  const profileId = config.profile ?? "bge-small-en-v1.5@1";
167
213
  const profile = knowledgeEmbeddingProfile(profileId);
@@ -427,6 +473,7 @@ async function runKnowledgeExportParquet(path, opts) {
427
473
  }
428
474
  export {
429
475
  contentSha256,
476
+ embeddingRuntimeMissingMessage,
430
477
  runKnowledgeBuild,
431
478
  runKnowledgeExportParquet,
432
479
  runKnowledgeInit,
package/dist/tui/index.js CHANGED
@@ -15,7 +15,14 @@ import { createHash, randomUUID } from "crypto";
15
15
  import { chmod, mkdir, readFile, rm, writeFile } from "fs/promises";
16
16
  import { homedir } from "os";
17
17
  import { basename, dirname, join, resolve } from "path";
18
- import { pickRandomNameWithGender } from "@bendyline/gezel";
18
+ import {
19
+ getLogLevel,
20
+ getLogOutput,
21
+ pickRandomNameWithGender,
22
+ projectLeadGezelId,
23
+ setLogLevel,
24
+ setLogOutput
25
+ } from "@bendyline/gezel";
19
26
  import {
20
27
  GezelSdkError,
21
28
  authorizeLocal,
@@ -29,6 +36,7 @@ import {
29
36
  discoverOrSpawn,
30
37
  electronNativeBinCandidates,
31
38
  ensureProjectForFolder as ensureClientProjectForFolder,
39
+ forbiddenProjectFolderName,
32
40
  isProcessAlive,
33
41
  readRuntime,
34
42
  readSystemServiceEndpoint,
@@ -43,9 +51,16 @@ var CliError = class extends Error {
43
51
  this.name = "CliError";
44
52
  }
45
53
  };
54
+ var DEFAULT_PROJECT_ID = "default";
46
55
  async function ensureCliProjectLead(client, projectId) {
47
56
  const project = await client.getProject(projectId);
48
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
+ }
49
64
  if (project.mode === "solo") {
50
65
  if (project.gezelIds?.[0]) return project.gezelIds[0];
51
66
  if (project.workingDir) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bendyline/gezel-cli",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "The `gezel` command-line tool.",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -44,12 +44,12 @@
44
44
  "!dist/**/*.map"
45
45
  ],
46
46
  "dependencies": {
47
- "@bendyline/gezel": "1.2.0",
48
- "@bendyline/gezel-app-sdk": "1.1.0",
49
- "@bendyline/gezel-catalog": "1.2.0",
50
- "@bendyline/gezel-client": "1.2.0",
51
- "@bendyline/gezel-knowledge": "1.2.0",
52
- "@bendyline/gezel-service": "1.2.0",
47
+ "@bendyline/gezel": "1.2.2",
48
+ "@bendyline/gezel-app-sdk": "1.1.2",
49
+ "@bendyline/gezel-catalog": "1.2.2",
50
+ "@bendyline/gezel-client": "1.2.2",
51
+ "@bendyline/gezel-knowledge": "1.2.2",
52
+ "@bendyline/gezel-service": "1.2.2",
53
53
  "@bendyline/squisq": "2.11.11",
54
54
  "@bendyline/squisq-formats": "2.6.11",
55
55
  "@bendyline/squisq-react": "2.11.13",