@bendyline/gezel-cli 1.0.6 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -8,8 +8,8 @@ as ordinary files you can `cat` and `grep`, and talks to whichever LLM provider
8
8
  you point it at. No cloud service of ours stands between you and the model.
9
9
 
10
10
  ```bash
11
- npm install -g @bendyline/gezel-cli
12
- gezel
11
+ npm install @bendyline/gezel-cli
12
+ npx gezel
13
13
  ```
14
14
 
15
15
  On a clean machine, the TUI stays in first-time setup until you decide what to
@@ -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 plus every recommended image, speech, reading, and video
21
- helper that fits this device.
22
- 2. The best chat model only.
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
@@ -150,7 +151,7 @@ Run `gezel --help` for the full list. The most-used ones:
150
151
  | `gezel agent list\|create\|show` | Manage your gezels |
151
152
  | `gezel env list\|create\|install` | Manage projects and their packages |
152
153
  | `gezel task list\|create\|show` | Manage tasks |
153
- | `gezel model list\|pull` | Manage on-device chat models |
154
+ | `gezel model list\|pull\|export` | Manage on-device chat models. `export <id> [file]` downloads the catalog model if needed, then writes a portable, checksum-verified `.gezmodel` you can move to another machine |
154
155
  | `gezel native install\|list\|status` | Manage native engine binaries |
155
156
  | `gezel create-image\|create-video\|create-audio` | Generate media |
156
157
  | `gezel skills import\|convert` | Import and convert skills |
@@ -0,0 +1,465 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/app-author-command.ts
4
+ import { mkdir as mkdir2, readFile as readFile2, readdir, stat, writeFile as writeFile2 } from "fs/promises";
5
+ import { dirname as dirname2, isAbsolute, join as join2 } from "path";
6
+ import {
7
+ GezappSourceError,
8
+ packGezappFromSource,
9
+ readGezapp,
10
+ renderGezappAuthoringSchemaFiles,
11
+ validateGezappSource,
12
+ verifyGezapp
13
+ } from "@bendyline/gezel-service/gezapp";
14
+
15
+ // src/app-scaffold.ts
16
+ var SCAFFOLD_ID_PATTERN = /^[a-z0-9][a-z0-9-]{1,63}$/;
17
+ function titleCase(id) {
18
+ return id.split("-").map((part) => part ? part[0].toUpperCase() + part.slice(1) : part).join(" ");
19
+ }
20
+ function shard(id) {
21
+ return id.slice(0, 2).toLowerCase();
22
+ }
23
+ var json = (value) => `${JSON.stringify(value, null, 2)}
24
+ `;
25
+ var STORE_SCRIPT = `import { type InferredInput, defineScript, gezel } from '@bendyline/gezel-sdk';
26
+
27
+ export const meta = defineScript({
28
+ name: 'records-store',
29
+ description: 'Add and list records in data.json.',
30
+ kind: 'action',
31
+ inputs: {
32
+ action: { type: 'string', description: "'add' or 'list'.", default: 'list' },
33
+ title: { type: 'string', description: 'Title for a new record.', default: '' },
34
+ },
35
+ outputs: {
36
+ records: { type: 'json', description: 'The records after the operation.' },
37
+ },
38
+ requires: ['workspace.read', 'workspace.write'],
39
+ } as const);
40
+
41
+ const input = gezel.input as InferredInput<typeof meta>;
42
+ const raw = await gezel.fs.read('data.json').catch(() => '{"records":[]}');
43
+ const data = JSON.parse(raw) as { records: Array<{ title: string; at: string }> };
44
+ if (input.action === 'add' && input.title) {
45
+ data.records.push({ title: input.title, at: new Date().toISOString() });
46
+ await gezel.fs.write('data.json', JSON.stringify(data, null, 2));
47
+ }
48
+ gezel.output({ records: data.records });
49
+ `;
50
+ function dashboardHtml(name) {
51
+ return `<!doctype html>
52
+ <html lang="en">
53
+ <head>
54
+ <meta charset="utf-8" />
55
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
56
+ <style>
57
+ :root {
58
+ color-scheme: light dark;
59
+ --bg: #f7f4ee;
60
+ --ink: #2c2925;
61
+ --card: #fffdf9;
62
+ --line: #d9d2c6;
63
+ }
64
+ @media (prefers-color-scheme: dark) {
65
+ :root {
66
+ --bg: #211e1a;
67
+ --ink: #e8e2d8;
68
+ --card: #2b2723;
69
+ --line: #47413a;
70
+ }
71
+ }
72
+ body {
73
+ margin: 0;
74
+ padding: 1.5rem;
75
+ background: var(--bg);
76
+ color: var(--ink);
77
+ font: 15px/1.5 system-ui, sans-serif;
78
+ }
79
+ h1 { font-size: 1.2rem; margin: 0 0 1rem; }
80
+ ul { list-style: none; margin: 0; padding: 0; }
81
+ li {
82
+ background: var(--card);
83
+ border: 1px solid var(--line);
84
+ border-radius: 4px;
85
+ padding: 0.5rem 0.75rem;
86
+ margin-bottom: 0.5rem;
87
+ }
88
+ button {
89
+ background: var(--card);
90
+ color: var(--ink);
91
+ border: 1px solid var(--line);
92
+ border-radius: 4px;
93
+ padding: 0.4rem 0.9rem;
94
+ cursor: pointer;
95
+ }
96
+ </style>
97
+ </head>
98
+ <body>
99
+ <h1>${name}</h1>
100
+ <ul id="records"></ul>
101
+ <button id="add">Add a record</button>
102
+ <script>
103
+ const list = document.querySelector('#records');
104
+ function render(data) {
105
+ list.replaceChildren();
106
+ for (const record of data.records) {
107
+ const item = document.createElement('li');
108
+ item.textContent = record.title + ' \u2014 ' + record.at.slice(0, 10);
109
+ list.append(item);
110
+ }
111
+ }
112
+ async function refresh() {
113
+ render(await gezel.data.read('data.json', { as: 'json' }));
114
+ }
115
+ gezel.data.watch('data.json', refresh);
116
+ document.querySelector('#add').addEventListener('click', async () => {
117
+ await gezel.tools.invoke('add_record', { title: 'Added from the page' });
118
+ await refresh();
119
+ });
120
+ refresh();
121
+ </script>
122
+ </body>
123
+ </html>
124
+ `;
125
+ }
126
+ function scaffoldGezappSource(id, opts) {
127
+ if (!SCAFFOLD_ID_PATTERN.test(id)) {
128
+ throw new Error(
129
+ `"${id}" is not a valid app id \u2014 use lowercase letters, digits, and hyphens (2-64 chars)`
130
+ );
131
+ }
132
+ const name = opts?.name ?? titleCase(id);
133
+ const roleId = `${id}-lead`;
134
+ const typeDir = `items/project-types/${shard(id)}/${id}`;
135
+ const roleDir = `items/gezel-templates/${shard(roleId)}/${roleId}`;
136
+ const files = [
137
+ [
138
+ "gezapp.json",
139
+ json({
140
+ format: "gezel-ai-app-source",
141
+ schemaVersion: 1
142
+ })
143
+ ],
144
+ [
145
+ "README.md",
146
+ `# ${name}
147
+
148
+ An AI App source folder scaffolded by \`gezel app new\`.
149
+
150
+ The loop:
151
+
152
+ 1. Edit the files under \`items/\` (schemas: \`gezel app schemas --out schemas\`).
153
+ 2. \`gezel app validate .\`
154
+ 3. \`gezel app pack .\`
155
+ 4. \`gezel app add ${id}-1.0.0.gezapp --yes\` then \`gezel app apply ${id}\` in a project folder.
156
+ `
157
+ ],
158
+ [
159
+ `${typeDir}/manifest.json`,
160
+ json({
161
+ schemaVersion: 1,
162
+ kind: "project-type",
163
+ id,
164
+ name,
165
+ description: `A focused ${name} workspace with one gezel and a records store.`,
166
+ tags: [],
167
+ maintainer: { name: "Your name" },
168
+ license: "MIT",
169
+ yankedVersions: []
170
+ })
171
+ ],
172
+ [
173
+ `${typeDir}/versions/1.0.0/manifest.json`,
174
+ json({
175
+ schemaVersion: 1,
176
+ version: "1.0.0",
177
+ releasedAt: (/* @__PURE__ */ new Date()).toISOString(),
178
+ mode: "solo",
179
+ leadLabel: "Keeper",
180
+ params: {
181
+ type: "object",
182
+ properties: {
183
+ focus: {
184
+ type: "string",
185
+ title: "What is this workspace about?",
186
+ default: "everyday records"
187
+ }
188
+ }
189
+ },
190
+ nameTemplate: `{{focus}} ${name}`,
191
+ aboutTemplate: "about.md",
192
+ missionTemplate: "mission.md",
193
+ gezels: [{ templateId: roleId, voorman: true }],
194
+ tools: [
195
+ {
196
+ name: "add_record",
197
+ description: "Add one record to data.json.",
198
+ script: "records-store",
199
+ inputs: {
200
+ type: "object",
201
+ properties: { title: { type: "string" } },
202
+ required: ["title"]
203
+ },
204
+ bind: { action: "add" }
205
+ }
206
+ ],
207
+ workspaceSeed: ["data.json"],
208
+ ...opts?.withPage ? {
209
+ pages: {
210
+ entry: "dashboard/index.html",
211
+ api: 1,
212
+ reads: [{ source: "workspace", path: "data.json" }],
213
+ tools: ["add_record"]
214
+ }
215
+ } : {}
216
+ })
217
+ ],
218
+ [
219
+ `${typeDir}/versions/1.0.0/about.md`,
220
+ `This project is a ${name} workspace focused on {{focus}}.
221
+
222
+ Records live in data.json; use the add_record tool rather than editing it by hand.
223
+ `
224
+ ],
225
+ [
226
+ `${typeDir}/versions/1.0.0/mission.md`,
227
+ `- Keep data.json accurate and current.
228
+ - Add a record whenever the user mentions something worth keeping.
229
+ `
230
+ ],
231
+ [`${typeDir}/versions/1.0.0/data.json`, json({ records: [] })],
232
+ [`${typeDir}/versions/1.0.0/scripts/records-store.ts`, STORE_SCRIPT],
233
+ [
234
+ `${roleDir}/manifest.json`,
235
+ json({
236
+ schemaVersion: 1,
237
+ kind: "gezel-template",
238
+ id: roleId,
239
+ name: `${name} Keeper`,
240
+ description: `The resident keeper of a ${name} workspace.`,
241
+ role: "Keeper",
242
+ tags: [],
243
+ maintainer: { name: "Your name" },
244
+ license: "MIT",
245
+ yankedVersions: []
246
+ })
247
+ ],
248
+ [
249
+ `${roleDir}/versions/1.0.0/manifest.json`,
250
+ json({
251
+ schemaVersion: 1,
252
+ version: "1.0.0",
253
+ releasedAt: (/* @__PURE__ */ new Date()).toISOString(),
254
+ about: "about.md"
255
+ })
256
+ ],
257
+ [
258
+ `${roleDir}/versions/1.0.0/about.md`,
259
+ `You are the keeper of this ${name} workspace.
260
+
261
+ Working style: short, warm answers. When the user mentions something worth keeping, add it with the add_record tool and confirm in one line. Never edit data.json by hand.
262
+ `
263
+ ]
264
+ ];
265
+ if (opts?.withPage) {
266
+ files.push([`${typeDir}/versions/1.0.0/pages/dashboard/index.html`, dashboardHtml(name)]);
267
+ }
268
+ return files;
269
+ }
270
+
271
+ // src/connection.ts
272
+ import { createHash, randomUUID } from "crypto";
273
+ import { chmod, mkdir, readFile, rm, writeFile } from "fs/promises";
274
+ import { homedir } from "os";
275
+ import { basename, dirname, join, resolve } from "path";
276
+ import { pickRandomNameWithGender } from "@bendyline/gezel";
277
+ import {
278
+ GezelSdkError,
279
+ authorizeLocal,
280
+ authorizeLocalOwner
281
+ } from "@bendyline/gezel-app-sdk";
282
+ import {
283
+ GezelApiError,
284
+ GezelClient,
285
+ LiveDaemonUnhealthyError,
286
+ createTrustingFetch,
287
+ discoverOrSpawn,
288
+ electronNativeBinCandidates,
289
+ isProcessAlive,
290
+ readRuntime,
291
+ readSystemServiceEndpoint,
292
+ resolveDaemonEntry,
293
+ stopOwnedDaemon,
294
+ systemSharedAssetsDir
295
+ } from "@bendyline/gezel-client/node";
296
+ import { gezelPaths } from "@bendyline/gezel/paths";
297
+ var CliError = class extends Error {
298
+ constructor(message) {
299
+ super(message);
300
+ this.name = "CliError";
301
+ }
302
+ };
303
+
304
+ // src/app-author-command.ts
305
+ function resolvePath(input) {
306
+ return isAbsolute(input) ? input : join2(process.cwd(), input);
307
+ }
308
+ function formatFinding(finding) {
309
+ const where = finding.file || ".";
310
+ const pointer = finding.pointer ? ` #${finding.pointer}` : "";
311
+ return `${finding.severity.toUpperCase()} ${where}${pointer} - ${finding.rule}: ${finding.message}`;
312
+ }
313
+ function printFindings(findings) {
314
+ for (const finding of findings) console.log(formatFinding(finding));
315
+ return {
316
+ errors: findings.filter((finding) => finding.severity === "error").length,
317
+ warnings: findings.filter((finding) => finding.severity === "warn").length
318
+ };
319
+ }
320
+ async function statKind(path) {
321
+ try {
322
+ const info = await stat(path);
323
+ return info.isDirectory() ? "dir" : "file";
324
+ } catch {
325
+ return null;
326
+ }
327
+ }
328
+ async function runAppValidate(target, opts = {}) {
329
+ const path = resolvePath(target);
330
+ const kind = await statKind(path);
331
+ if (!kind) throw new CliError(`No such file or folder: ${target}`);
332
+ let findings;
333
+ let entry = null;
334
+ if (kind === "dir") {
335
+ const result = await validateGezappSource(path);
336
+ findings = result.findings;
337
+ entry = result.manifest?.entry ?? null;
338
+ } else {
339
+ let parsed;
340
+ try {
341
+ parsed = readGezapp(await readFile2(path));
342
+ } catch (err) {
343
+ throw new CliError(err instanceof Error ? err.message : String(err));
344
+ }
345
+ entry = parsed.manifest.entry;
346
+ findings = verifyGezapp(parsed).errors.map((message) => ({
347
+ severity: "error",
348
+ file: "",
349
+ pointer: "",
350
+ rule: "package-verify",
351
+ message
352
+ }));
353
+ }
354
+ const ok = !findings.some((finding) => finding.severity === "error");
355
+ if (opts.json) {
356
+ console.log(JSON.stringify({ ok, entry, findings }, null, 2));
357
+ } else {
358
+ const { errors, warnings } = printFindings(findings);
359
+ if (ok) {
360
+ const suffix = warnings > 0 ? ` (${warnings} warning${warnings === 1 ? "" : "s"})` : "";
361
+ console.log(
362
+ `OK \u2014 ${entry ? `${entry.projectType}@${entry.version}` : "package"} is valid${suffix}.`
363
+ );
364
+ } else {
365
+ console.log(
366
+ `${errors} error${errors === 1 ? "" : "s"}, ${warnings} warning${warnings === 1 ? "" : "s"}.`
367
+ );
368
+ }
369
+ }
370
+ if (!ok) process.exitCode = 1;
371
+ }
372
+ async function runAppPack(folder, opts = {}) {
373
+ const dir = resolvePath(folder);
374
+ if (await statKind(dir) !== "dir") throw new CliError(`No such folder: ${folder}`);
375
+ try {
376
+ const packed = await packGezappFromSource(dir);
377
+ const out = resolvePath(
378
+ opts.out ?? `${packed.manifest.entry.projectType}-${packed.manifest.entry.version}.gezapp`
379
+ );
380
+ await writeFile2(out, packed.buffer);
381
+ if (opts.json) {
382
+ console.log(
383
+ JSON.stringify(
384
+ { ok: true, path: out, manifest: packed.manifest, findings: packed.findings },
385
+ null,
386
+ 2
387
+ )
388
+ );
389
+ return;
390
+ }
391
+ printFindings(packed.findings);
392
+ const items = packed.manifest.items.map((item) => `${item.kind} ${item.id}@${item.version}`).join(", ");
393
+ console.log(`Packed ${packed.manifest.name} ${packed.manifest.entry.version} -> ${out}`);
394
+ console.log(` items: ${items}`);
395
+ if (packed.manifest.dependencies.length > 0) {
396
+ console.log(
397
+ ` dependency locks: ${packed.manifest.dependencies.map((dependency) => `${dependency.kind} ${dependency.id}@${dependency.version}`).join(", ")}`
398
+ );
399
+ }
400
+ console.log(` ${packed.buffer.length.toLocaleString()} bytes`);
401
+ } catch (err) {
402
+ if (!(err instanceof GezappSourceError)) throw err;
403
+ if (opts.json) {
404
+ console.log(JSON.stringify({ ok: false, findings: err.findings }, null, 2));
405
+ } else {
406
+ const { errors } = printFindings(err.findings);
407
+ console.log(`Not packed \u2014 fix the ${errors} error${errors === 1 ? "" : "s"} above.`);
408
+ }
409
+ process.exitCode = 1;
410
+ }
411
+ }
412
+ async function runAppNew(id, opts = {}) {
413
+ if (!SCAFFOLD_ID_PATTERN.test(id)) {
414
+ throw new CliError(
415
+ `"${id}" is not a valid app id \u2014 use lowercase letters, digits, and hyphens (2-64 chars).`
416
+ );
417
+ }
418
+ const target = join2(opts.dir ? resolvePath(opts.dir) : process.cwd(), id);
419
+ const existing = await statKind(target);
420
+ if (existing === "file") throw new CliError(`${target} already exists.`);
421
+ if (existing === "dir" && (await readdir(target)).length > 0) {
422
+ throw new CliError(`${target} already exists and is not empty.`);
423
+ }
424
+ const files = scaffoldGezappSource(id, {
425
+ ...opts.withPage ? { withPage: true } : {}
426
+ });
427
+ for (const [rel, content] of files) {
428
+ const abs = join2(target, rel);
429
+ await mkdir2(dirname2(abs), { recursive: true });
430
+ await writeFile2(abs, content);
431
+ }
432
+ console.log(`Scaffolded ${id} (${files.length} files) in ${target}`);
433
+ console.log("Next:");
434
+ console.log(" 1. Edit items/ \u2014 start with the two about.md files and the version manifest.");
435
+ console.log(` 2. gezel app validate ${id}`);
436
+ console.log(` 3. gezel app pack ${id}`);
437
+ console.log(` 4. gezel app add ${id}-1.0.0.gezapp --yes && gezel app apply ${id}`);
438
+ }
439
+ async function runAppSchemas(opts = {}) {
440
+ const files = renderGezappAuthoringSchemaFiles();
441
+ if (opts.json) {
442
+ const byName = {};
443
+ for (const [filename, content] of files) byName[filename] = JSON.parse(content);
444
+ console.log(JSON.stringify(byName, null, 2));
445
+ return;
446
+ }
447
+ if (opts.out) {
448
+ const dir = resolvePath(opts.out);
449
+ await mkdir2(dir, { recursive: true });
450
+ for (const [filename, content] of files) {
451
+ await writeFile2(join2(dir, filename), content);
452
+ }
453
+ console.log(`Wrote ${files.length} JSON Schemas to ${dir}`);
454
+ return;
455
+ }
456
+ for (const [filename] of files) console.log(filename);
457
+ console.log("");
458
+ console.log("Use --out <dir> to write the files, or --json for one combined object.");
459
+ }
460
+ export {
461
+ runAppNew,
462
+ runAppPack,
463
+ runAppSchemas,
464
+ runAppValidate
465
+ };