@bendyline/gezel-cli 1.0.5 → 1.0.6

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.
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/bin/gezel.ts
4
- import { basename as basename3 } from "path";
4
+ import { basename as basename3, isAbsolute as isAbsolutePath, join as joinPath } from "path";
5
5
  import { GEZEL_VERSION } from "@bendyline/gezel";
6
6
  import {
7
7
  streamChatEvents
@@ -802,6 +802,187 @@ function installSignalCleanup(cleanup, options = {}) {
802
802
  };
803
803
  }
804
804
 
805
+ // src/storage-format.ts
806
+ function formatBytes2(bytes) {
807
+ if (bytes >= 1024 ** 3) return `${(bytes / 1024 ** 3).toFixed(1)} GB`;
808
+ if (bytes >= 1024 ** 2) return `${(bytes / 1024 ** 2).toFixed(0)} MB`;
809
+ if (bytes >= 1024) return `${(bytes / 1024).toFixed(0)} KB`;
810
+ return `${bytes} B`;
811
+ }
812
+ function formatStorageSummary(summary) {
813
+ const lines = [`Gezel storage in ${summary.home}`, ""];
814
+ lines.push(...group("Can be downloaded again", summary, "redownloadable"));
815
+ lines.push(...group("Your content", summary, "user-content"));
816
+ lines.push(
817
+ ...group("Program files (the uninstaller removes these)", summary, "uninstaller-owned")
818
+ );
819
+ lines.push(
820
+ `Total: ${formatBytes2(summary.redownloadableBytes)} re-downloadable, ${formatBytes2(summary.userContentBytes)} your content`
821
+ );
822
+ const external = summary.categories.flatMap((c) => c.external).sort((a, b) => a.path.localeCompare(b.path));
823
+ if (external.length > 0) {
824
+ lines.push("", "Outside the Gezel folder \u2014 not measured or removed by Gezel:");
825
+ for (const entry of external) {
826
+ lines.push(` ${entry.path}`);
827
+ }
828
+ }
829
+ return lines.join("\n");
830
+ }
831
+ function group(heading, summary, cls) {
832
+ const categories = summary.categories.filter((c) => c.class === cls && c.bytes > 0).sort((a, b) => b.bytes - a.bytes);
833
+ if (categories.length === 0) return [];
834
+ const lines = [`${heading}:`];
835
+ for (const c of categories) {
836
+ lines.push(` ${pad(formatBytes2(c.bytes), 10)} ${c.label}`);
837
+ }
838
+ lines.push("");
839
+ return lines;
840
+ }
841
+ function pad(text, width) {
842
+ return text.padStart(width, " ");
843
+ }
844
+ var CLEANUP_FLAG_CATEGORIES = {
845
+ models: ["models"],
846
+ engines: ["native-engines", "engine-caches"],
847
+ toolsets: ["toolsets"],
848
+ caches: ["gilde-cache", "derived-caches"],
849
+ redownloadable: [
850
+ "models",
851
+ "native-engines",
852
+ "engine-caches",
853
+ "toolsets",
854
+ "gilde-cache",
855
+ "derived-caches"
856
+ ]
857
+ };
858
+ var CLEANUP_CONTENT_CATEGORIES = {
859
+ gezels: ["gezels"],
860
+ projects: ["projects"],
861
+ documents: ["documents"],
862
+ settings: ["settings"],
863
+ all: ["gezels", "projects", "documents", "settings"]
864
+ };
865
+ function resolveCleanupSelection(flags) {
866
+ const categories = /* @__PURE__ */ new Set();
867
+ for (const [flag, ids] of Object.entries(CLEANUP_FLAG_CATEGORIES)) {
868
+ if (flags[flag] === true) for (const id of ids) categories.add(id);
869
+ }
870
+ let destroysUserContent = false;
871
+ if (flags.content !== void 0) {
872
+ const choice = flags.content;
873
+ const ids = CLEANUP_CONTENT_CATEGORIES[choice];
874
+ if (!ids) {
875
+ throw new Error(
876
+ `Unknown --content value "${flags.content}". Choose one of: ${Object.keys(
877
+ CLEANUP_CONTENT_CATEGORIES
878
+ ).join(", ")}.`
879
+ );
880
+ }
881
+ for (const id of ids) categories.add(id);
882
+ destroysUserContent = true;
883
+ }
884
+ return { categories: [...categories], destroysUserContent };
885
+ }
886
+ function formatCleanupResult(job) {
887
+ const lines = [];
888
+ if (job.status === "error") {
889
+ lines.push(`Cleanup failed: ${job.error ?? "unknown error"}`);
890
+ } else if (job.status === "cancelled") {
891
+ lines.push(`Cleanup stopped early. Freed ${formatBytes2(job.bytesDone)} before stopping.`);
892
+ } else {
893
+ lines.push(`Freed ${formatBytes2(job.bytesDone)} across ${job.itemsDone} item(s).`);
894
+ }
895
+ if (job.skippedExternal.length > 0) {
896
+ lines.push("", "Left alone (stored outside the Gezel folder):");
897
+ for (const skipped of job.skippedExternal) {
898
+ lines.push(` ${skipped.label} \u2014 ${skipped.path}`);
899
+ }
900
+ }
901
+ if (job.restartRequired) {
902
+ lines.push("", "Restart Gezel to pick up the changes.");
903
+ }
904
+ return lines.join("\n");
905
+ }
906
+ function formatCleanupPreview(summary, categories) {
907
+ const selected = new Set(categories);
908
+ const chosen = summary.categories.filter((c) => selected.has(c.id));
909
+ const total = chosen.reduce((sum, c) => sum + c.bytes, 0);
910
+ const lines = ["This will delete:"];
911
+ for (const c of chosen) {
912
+ lines.push(` ${pad(formatBytes2(c.bytes), 10)} ${c.label}`);
913
+ }
914
+ if (chosen.length === 0) lines.push(" (nothing \u2014 these categories are already empty)");
915
+ lines.push("", `Frees about ${formatBytes2(total)}.`);
916
+ const external = chosen.flatMap((c) => c.external);
917
+ if (external.length > 0) {
918
+ lines.push("", "Not touched (stored outside the Gezel folder):");
919
+ for (const entry of external) lines.push(` ${entry.path}`);
920
+ }
921
+ const userContent = chosen.filter((c) => c.class === "user-content");
922
+ if (userContent.length > 0) {
923
+ lines.push("", "WARNING: this includes content only you have. Gezel cannot download it again.");
924
+ }
925
+ return lines.join("\n");
926
+ }
927
+ function formatBackupPlan(plan) {
928
+ const lines = ["This backup will include:"];
929
+ const byKind = /* @__PURE__ */ new Map();
930
+ for (const item of plan.items) {
931
+ const bucket = byKind.get(item.kind) ?? { count: 0, bytes: 0 };
932
+ bucket.count += 1;
933
+ bucket.bytes += item.bytes;
934
+ byKind.set(item.kind, bucket);
935
+ }
936
+ const labels = {
937
+ gezel: "gezels",
938
+ project: "projects",
939
+ "document-root": "documents",
940
+ "settings-file": "settings files"
941
+ };
942
+ for (const [kind, bucket] of byKind) {
943
+ lines.push(` ${pad(formatBytes2(bucket.bytes), 10)} ${bucket.count} ${labels[kind] ?? kind}`);
944
+ }
945
+ if (plan.items.length === 0) lines.push(" (nothing yet \u2014 this install has no content)");
946
+ lines.push("", `About ${formatBytes2(plan.totalBytes)} total.`);
947
+ lines.push("Saved credentials are never included; reconnect services after restoring.");
948
+ for (const warning of plan.warnings) lines.push(` note: ${warning}`);
949
+ return lines.join("\n");
950
+ }
951
+ function formatRestoreReview(review) {
952
+ const lines = [
953
+ `Backup from Gezel ${review.gezelVersion}, made ${new Date(review.createdAt).toLocaleString()}`,
954
+ ""
955
+ ];
956
+ for (const item of review.items) {
957
+ const flag = item.conflict === "exists" ? " [already here]" : "";
958
+ lines.push(` ${pad(formatBytes2(item.bytes), 10)} ${item.kind}: ${item.label}${flag}`);
959
+ }
960
+ if (review.items.length === 0) lines.push(" (this backup is empty)");
961
+ if (review.warnings.length > 0) {
962
+ lines.push("");
963
+ for (const warning of review.warnings) lines.push(` note: ${warning}`);
964
+ }
965
+ return lines.join("\n");
966
+ }
967
+ function resolveRestoreSelection(review, opts) {
968
+ const wanted = opts.only && opts.only.length > 0 ? new Set(opts.only) : null;
969
+ const items = [];
970
+ const skipped = [];
971
+ for (const item of review.items) {
972
+ if (wanted && !wanted.has(`${item.kind}:${item.id}`) && !wanted.has(item.id)) continue;
973
+ if (item.conflict === "exists" && !opts.replace) {
974
+ skipped.push(`${item.label} (already here \u2014 use --replace to overwrite)`);
975
+ continue;
976
+ }
977
+ items.push({
978
+ kind: item.kind,
979
+ id: item.id,
980
+ action: item.conflict === "exists" ? "replace" : "add"
981
+ });
982
+ }
983
+ return { items, skipped };
984
+ }
985
+
805
986
  // src/tui/craftbook-start.ts
806
987
  import {
807
988
  CRAFTBOOK_ROLE_META,
@@ -1656,6 +1837,134 @@ program.command("doctor").description("Check the Gezel installation").action(asy
1656
1837
  }
1657
1838
  }
1658
1839
  });
1840
+ program.command("cleanup").description("Show or reclaim the space Gezel is using on this device").option("--refresh", "Re-measure instead of using the cached sizes").option("--models", "Delete downloaded models").option("--engines", "Delete engine binaries and their caches").option("--toolsets", "Delete installed tools and the automation browser").option("--caches", "Delete catalog content and generated indexes").option("--redownloadable", "Delete everything Gezel can download again").option(
1841
+ "--content <what>",
1842
+ "Delete your own content: gezels, projects, documents, settings, or all"
1843
+ ).option("--dry-run", "Show what would be deleted without deleting anything").option("--yes", "Skip the confirmation prompt").action(async (opts) => {
1844
+ const client = await connectOwned(cliGlobals());
1845
+ const selection = resolveCleanupSelection(opts);
1846
+ if (selection.categories.length === 0) {
1847
+ const summary2 = await client.storageSummary(opts.refresh ? { refresh: true } : void 0);
1848
+ console.log(formatStorageSummary(summary2));
1849
+ if (!opts.dryRun) {
1850
+ console.log(
1851
+ "\nTo reclaim space, re-run with --redownloadable (safe: Gezel downloads these again)."
1852
+ );
1853
+ }
1854
+ return;
1855
+ }
1856
+ const summary = await client.storageSummary({ refresh: true });
1857
+ console.log(formatCleanupPreview(summary, selection.categories));
1858
+ if (opts.dryRun) {
1859
+ console.log("\nDry run \u2014 nothing was deleted.");
1860
+ return;
1861
+ }
1862
+ if (selection.destroysUserContent) {
1863
+ const confirmed = await confirmByTyping(
1864
+ 'This permanently deletes content only you have. Type "delete my content" to continue: ',
1865
+ "delete my content"
1866
+ );
1867
+ if (!confirmed) {
1868
+ console.log("Cancelled.");
1869
+ return;
1870
+ }
1871
+ } else if (!opts.yes) {
1872
+ const confirmed = await confirmByTyping('Delete these? Type "yes" to continue: ', "yes");
1873
+ if (!confirmed) {
1874
+ console.log("Cancelled.");
1875
+ return;
1876
+ }
1877
+ }
1878
+ const { jobId } = await client.startCleanup({
1879
+ categories: selection.categories,
1880
+ ...selection.destroysUserContent ? { confirmUserContent: true } : {}
1881
+ });
1882
+ const job = await pollStorageJob(client, jobId);
1883
+ console.log(formatCleanupResult(job));
1884
+ if (job.status === "error") process.exitCode = 1;
1885
+ });
1886
+ program.command("backup <file>").description("Write your gezels, projects, and documents to a backup file").option("--no-workspaces", "Leave project working files out of the backup").option("--dry-run", "Show what would be included without writing the file").action(async (file, opts) => {
1887
+ const client = await connectOwned(cliGlobals());
1888
+ const outPath = resolvePath(file);
1889
+ const excludeWorkspaces = opts.workspaces === false;
1890
+ const plan = await client.planBackup({ destPath: outPath, excludeWorkspaces });
1891
+ console.log(formatBackupPlan(plan));
1892
+ if (opts.dryRun) {
1893
+ console.log("\nDry run \u2014 no file was written.");
1894
+ return;
1895
+ }
1896
+ if (plan.items.length === 0) throw new CliError("There is nothing to back up yet.");
1897
+ const { jobId } = await client.startBackup({ outPath, excludeWorkspaces });
1898
+ const job = await pollStorageJob(client, jobId);
1899
+ if (job.status === "error") {
1900
+ throw new CliError(`Backup failed: ${job.error ?? "unknown error"}`);
1901
+ }
1902
+ console.log(`
1903
+ Wrote ${outPath}`);
1904
+ });
1905
+ program.command("restore <file>").description("Restore gezels, projects, and documents from a backup file").option("--list", "Show what the backup holds without restoring anything").option(
1906
+ "--only <item...>",
1907
+ "Restore just these items, by id (repeatable, e.g. --only tamsin roof-survey)"
1908
+ ).option("--replace", "Overwrite items that already exist here").option("--settings", "Also restore preferences from the backup").action(
1909
+ async (file, opts) => {
1910
+ const client = await connectOwned(cliGlobals());
1911
+ const review = await client.scanRestore({ path: resolvePath(file) });
1912
+ console.log(formatRestoreReview(review));
1913
+ if (opts.list) return;
1914
+ const selection = resolveRestoreSelection(review, opts);
1915
+ for (const note of selection.skipped) console.log(` skipping ${note}`);
1916
+ if (selection.items.length === 0) {
1917
+ console.log("\nNothing to restore.");
1918
+ await client.cancelRestore(review.restoreId);
1919
+ return;
1920
+ }
1921
+ const { jobId } = await client.confirmRestore(review.restoreId, {
1922
+ items: selection.items,
1923
+ ...opts.settings ? { settings: true } : {}
1924
+ });
1925
+ const job = await pollStorageJob(client, jobId);
1926
+ if (job.status === "error") {
1927
+ throw new CliError(`Restore failed: ${job.error ?? "unknown error"}`);
1928
+ }
1929
+ console.log(`
1930
+ Restored ${selection.items.length} item(s).`);
1931
+ if (job.restartRequired) console.log("Restart Gezel to see them.");
1932
+ }
1933
+ );
1934
+ function resolvePath(file) {
1935
+ return isAbsolutePath(file) ? file : joinPath(process.cwd(), file);
1936
+ }
1937
+ async function confirmByTyping(prompt, required) {
1938
+ if (!process.stdin.isTTY) {
1939
+ throw new CliError(
1940
+ "Refusing to delete without a confirmation. Re-run in a terminal, or use --dry-run to preview."
1941
+ );
1942
+ }
1943
+ const { createInterface } = await import("readline/promises");
1944
+ const rl = createInterface({ input: process.stdin, output: process.stderr });
1945
+ try {
1946
+ const answer = await rl.question(prompt);
1947
+ return answer.trim().toLowerCase() === required;
1948
+ } finally {
1949
+ rl.close();
1950
+ }
1951
+ }
1952
+ async function pollStorageJob(client, jobId) {
1953
+ for (; ; ) {
1954
+ const job = await client.getStorageJob(jobId);
1955
+ if (job.status === "done" || job.status === "error" || job.status === "cancelled") {
1956
+ if (process.stderr.isTTY) process.stderr.write("\n");
1957
+ return job;
1958
+ }
1959
+ if (process.stderr.isTTY) {
1960
+ const label = job.currentLabel ? ` ${job.currentLabel}` : "";
1961
+ process.stderr.write(
1962
+ `\r${job.phase ?? "working"}${label} \u2014 ${job.itemsDone}/${job.totalItems} `
1963
+ );
1964
+ }
1965
+ await new Promise((r) => setTimeout(r, 250));
1966
+ }
1967
+ }
1659
1968
  program.parseAsync(process.argv).catch((err) => {
1660
1969
  if (err instanceof CliError) console.error(err.message);
1661
1970
  else console.error(err);
@@ -226,25 +226,36 @@ body.hb {
226
226
  max-width: 100%;
227
227
  margin: 0 0 1.25rem;
228
228
  }
229
+ /* A step down from body copy: the model scorecard puts eight columns of
230
+ figures inside a 42rem reading measure, and at prose size the numbers get
231
+ less room than the words around them. */
229
232
  .hb-article table {
230
233
  border-collapse: collapse;
231
234
  width: 100%;
232
- font-size: 0.9rem;
235
+ font-size: 0.82rem;
236
+ line-height: 1.45;
233
237
  }
234
238
  /* Prose cells wrap. Catalog tables pair a short name against a full sentence
235
239
  of description, so white-space:nowrap would push the description off the
236
- page and force a horizontal scroll to read every row. */
240
+ page and force a horizontal scroll to read every row.
241
+
242
+ break-word, not anywhere: both keep an over-long token from spilling out
243
+ of the table, but "anywhere" also lets the browser count a single
244
+ character as a column's minimum width, so a squeezed table shreds its
245
+ headings mid-word ("Rea" / "ds" / "at"). With break-word a column never
246
+ narrows past its longest word, and the excess goes to the scroller. */
237
247
  .hb-article th, .hb-article td {
238
248
  border: 1px solid var(--hb-border);
239
- padding: 0.45rem 0.7rem;
249
+ padding: 0.4rem 0.45rem;
240
250
  text-align: left;
241
251
  vertical-align: top;
242
- overflow-wrap: anywhere;
252
+ overflow-wrap: break-word;
253
+ min-width: 3rem;
243
254
  }
244
255
  .hb-article th { background: var(--hb-inset); font-weight: 600; }
245
256
  /* Keep the leading label column from collapsing to one word per line while
246
257
  the description column takes the slack. */
247
- .hb-article tbody td:first-child { min-width: 11rem; }
258
+ .hb-article tbody td:first-child { min-width: 6rem; }
248
259
 
249
260
  .hb-watch { max-width: var(--hb-measure); margin: 1.25rem 0 0; font-size: 0.9rem; }
250
261
 
package/dist/tui/index.js CHANGED
@@ -4,6 +4,9 @@
4
4
  import { render } from "ink";
5
5
 
6
6
  // src/tui/App.tsx
7
+ import {
8
+ pickRandomNameWithGender as pickRandomNameWithGender2
9
+ } from "@bendyline/gezel";
7
10
  import { Box as Box6, Text as Text6, useApp, useInput as useInput4, useStdout } from "ink";
8
11
  import { useCallback as useCallback2, useEffect as useEffect4, useMemo, useRef as useRef3, useState as useState5 } from "react";
9
12
 
@@ -240,8 +243,14 @@ function referencesFromMessage(message, projectId) {
240
243
  for (const tool of message.toolCalls ?? []) {
241
244
  references.push(...referencesFromTool(tool, projectId));
242
245
  }
243
- for (const path of message.referencedArtifacts ?? []) {
244
- references.push(reference("artifact", path, projectId));
246
+ if (message.referencedFiles?.length) {
247
+ for (const file of message.referencedFiles) {
248
+ references.push(reference(file.kind, file.path, projectId));
249
+ }
250
+ } else {
251
+ for (const path of message.referencedArtifacts ?? []) {
252
+ references.push(reference("artifact", path, projectId));
253
+ }
245
254
  }
246
255
  return references;
247
256
  }
@@ -303,7 +312,7 @@ var SLASH_COMMAND_WORDWHEEL_SIZE = 4;
303
312
  var SLASH_COMMANDS = [
304
313
  { name: "help", description: "show the command reference" },
305
314
  { name: "project", description: "switch active project" },
306
- { name: "gezel", description: "switch active gezel" },
315
+ { name: "gezel", description: "switch gezel, or bring a role onto the project" },
307
316
  { name: "allow", description: "allow a project permission" },
308
317
  { name: "disallow", description: "disallow a project permission" },
309
318
  { name: "show", description: "show optional chat details" },
@@ -1373,13 +1382,18 @@ function Picker(props) {
1373
1382
  ] }) : null,
1374
1383
  visibleItems.map((item, offset) => {
1375
1384
  const itemIndex = start + offset;
1376
- return /* @__PURE__ */ jsxs2(Text2, { color: itemIndex === index ? "green" : void 0, children: [
1377
- itemIndex === index ? "\u276F " : " ",
1378
- item.label,
1379
- item.hint ? /* @__PURE__ */ jsxs2(Text2, { dimColor: true, children: [
1380
- " \u2014 ",
1381
- item.hint
1382
- ] }) : null
1385
+ const previousSection = offset === 0 ? void 0 : visibleItems[offset - 1]?.section;
1386
+ const showSection = item.section !== void 0 && item.section !== previousSection;
1387
+ return /* @__PURE__ */ jsxs2(Box2, { flexDirection: "column", children: [
1388
+ showSection ? /* @__PURE__ */ jsx2(Text2, { dimColor: true, children: item.section }) : null,
1389
+ /* @__PURE__ */ jsxs2(Text2, { color: itemIndex === index ? "green" : void 0, children: [
1390
+ itemIndex === index ? "\u276F " : " ",
1391
+ item.label,
1392
+ item.hint ? /* @__PURE__ */ jsxs2(Text2, { dimColor: true, children: [
1393
+ " \u2014 ",
1394
+ item.hint
1395
+ ] }) : null
1396
+ ] })
1383
1397
  ] }, item.value);
1384
1398
  }),
1385
1399
  start + visibleItems.length < items.length ? /* @__PURE__ */ jsxs2(Text2, { dimColor: true, children: [
@@ -2002,6 +2016,167 @@ function craftbookStartRequest(book) {
2002
2016
  };
2003
2017
  }
2004
2018
 
2019
+ // src/tui/gezel-picker.ts
2020
+ import {
2021
+ getProjectType,
2022
+ resolveProjectTypeId
2023
+ } from "@bendyline/gezel";
2024
+ var GEZEL_VALUE_PREFIX = "gezel:";
2025
+ var TEMPLATE_VALUE_PREFIX = "template:";
2026
+ var CORE_ROLE_ORDER = [
2027
+ "voorman",
2028
+ "builder",
2029
+ "developer",
2030
+ "reviewer",
2031
+ "planner",
2032
+ "researcher",
2033
+ "designer",
2034
+ "copywriter",
2035
+ "meester",
2036
+ "image-generator",
2037
+ "video-generator"
2038
+ ];
2039
+ var SECTION_IN_PROJECT = "In this project";
2040
+ var SECTION_RECOMMENDED = "Recommended for this project";
2041
+ var SECTION_OTHER_GEZELS = "Your other gezels";
2042
+ var SECTION_CORE = "Core roles";
2043
+ var SECTION_MORE = "More roles";
2044
+ var DEFAULT_HINT_WIDTH = 76;
2045
+ function clip2(text, width) {
2046
+ const flat = text.replace(/\s+/g, " ").trim();
2047
+ if (flat.length <= width) return flat;
2048
+ return `${flat.slice(0, Math.max(1, width - 1)).trimEnd()}\u2026`;
2049
+ }
2050
+ function roleIdentity(value) {
2051
+ return (value ?? "").trim().toLowerCase();
2052
+ }
2053
+ function displayName(gezel, roleBasedNameOnly) {
2054
+ if (roleBasedNameOnly) return gezel.roleBasedName ?? gezel.role ?? gezel.id;
2055
+ return gezel.name;
2056
+ }
2057
+ function affinityRanks(project) {
2058
+ const type = getProjectType(resolveProjectTypeId(project ?? {}));
2059
+ const out = /* @__PURE__ */ new Map();
2060
+ let rank = 0;
2061
+ const add = (role) => {
2062
+ if (!out.has(role.templateId)) out.set(role.templateId, { rank: rank++, reason: role.reason });
2063
+ };
2064
+ for (const role of type?.gezelRoles.default ?? []) add(role);
2065
+ for (const role of type?.gezelRoles.suggested ?? []) add(role);
2066
+ return out;
2067
+ }
2068
+ function gezelHint(gezel, templatesById, roleBasedNameOnly) {
2069
+ const role = roleBasedNameOnly ? void 0 : gezel.roleBasedName ?? gezel.role;
2070
+ const about = gezel.description ?? (gezel.templateId ? templatesById.get(gezel.templateId)?.description : void 0);
2071
+ return [role, about].filter(Boolean).join(" \xB7 ");
2072
+ }
2073
+ function buildGezelPickerItems(inputs) {
2074
+ const {
2075
+ gezels,
2076
+ templates,
2077
+ memberIds,
2078
+ project,
2079
+ roleBasedNameOnly = false,
2080
+ hintWidth = DEFAULT_HINT_WIDTH
2081
+ } = inputs;
2082
+ const templatesById = new Map(templates.map((t) => [t.id, t]));
2083
+ const members = new Set(memberIds);
2084
+ const affinity = affinityRanks(project);
2085
+ const filledTemplateIds = new Set(gezels.flatMap((g) => g.templateId ? [g.templateId] : []));
2086
+ const filledRoleIdentities = new Set(
2087
+ gezels.flatMap((g) => [roleIdentity(g.role), roleIdentity(g.roleBasedName)].filter(Boolean))
2088
+ );
2089
+ const coreRank = new Map(CORE_ROLE_ORDER.map((id, index) => [id, index]));
2090
+ const items = [];
2091
+ const push = (section, item) => {
2092
+ items.push({ ...item, section });
2093
+ };
2094
+ const gezelItem = (gezel) => ({
2095
+ label: displayName(gezel, roleBasedNameOnly),
2096
+ value: `${GEZEL_VALUE_PREFIX}${gezel.id}`,
2097
+ hint: clip2(gezelHint(gezel, templatesById, roleBasedNameOnly), hintWidth)
2098
+ });
2099
+ const templateItem = (template, reason) => ({
2100
+ label: template.name,
2101
+ value: `${TEMPLATE_VALUE_PREFIX}${template.id}`,
2102
+ hint: clip2(reason ?? template.description, hintWidth)
2103
+ });
2104
+ const onProject = gezels.filter((g) => members.has(g.id));
2105
+ for (const gezel of sortByName(onProject, roleBasedNameOnly)) {
2106
+ push(SECTION_IN_PROJECT, gezelItem(gezel));
2107
+ }
2108
+ const offProject = gezels.filter((g) => !members.has(g.id));
2109
+ const affinityFor = (gezel) => {
2110
+ if (gezel.templateId && affinity.has(gezel.templateId)) return affinity.get(gezel.templateId);
2111
+ for (const [templateId, entry] of affinity) {
2112
+ const template = templatesById.get(templateId);
2113
+ if (!template) continue;
2114
+ if (roleIdentity(template.role) === roleIdentity(gezel.role) || roleIdentity(template.name) === roleIdentity(gezel.roleBasedName)) {
2115
+ return entry;
2116
+ }
2117
+ }
2118
+ return void 0;
2119
+ };
2120
+ const recommendedGezels = offProject.flatMap((gezel) => {
2121
+ const entry = affinityFor(gezel);
2122
+ return entry ? [{ gezel, entry }] : [];
2123
+ }).sort((a, b) => a.entry.rank - b.entry.rank);
2124
+ const recommendedGezelIds = new Set(recommendedGezels.map((r) => r.gezel.id));
2125
+ const availableTemplates = templates.filter(
2126
+ (template) => !filledTemplateIds.has(template.id) && !filledRoleIdentities.has(roleIdentity(template.role)) && !filledRoleIdentities.has(roleIdentity(template.name))
2127
+ );
2128
+ const recommendedTemplates = availableTemplates.flatMap((template) => {
2129
+ const entry = affinity.get(template.id);
2130
+ return entry ? [{ template, entry }] : [];
2131
+ }).sort((a, b) => a.entry.rank - b.entry.rank);
2132
+ const recommendedTemplateIds = new Set(recommendedTemplates.map((r) => r.template.id));
2133
+ for (const { gezel, entry } of recommendedGezels) {
2134
+ push(SECTION_RECOMMENDED, { ...gezelItem(gezel), hint: clip2(entry.reason, hintWidth) });
2135
+ }
2136
+ for (const { template, entry } of recommendedTemplates) {
2137
+ push(SECTION_RECOMMENDED, templateItem(template, entry.reason));
2138
+ }
2139
+ for (const gezel of sortByName(
2140
+ offProject.filter((g) => !recommendedGezelIds.has(g.id)),
2141
+ roleBasedNameOnly
2142
+ )) {
2143
+ push(SECTION_OTHER_GEZELS, gezelItem(gezel));
2144
+ }
2145
+ const remaining = availableTemplates.filter((t) => !recommendedTemplateIds.has(t.id));
2146
+ const core = remaining.filter((t) => coreRank.has(t.id)).sort((a, b) => (coreRank.get(a.id) ?? 0) - (coreRank.get(b.id) ?? 0));
2147
+ const more = remaining.filter((t) => !coreRank.has(t.id)).sort((a, b) => a.name.localeCompare(b.name));
2148
+ for (const template of core) push(SECTION_CORE, templateItem(template));
2149
+ for (const template of more) push(SECTION_MORE, templateItem(template));
2150
+ return items;
2151
+ }
2152
+ function sortByName(gezels, roleBasedNameOnly) {
2153
+ return [...gezels].sort(
2154
+ (a, b) => displayName(a, roleBasedNameOnly).localeCompare(displayName(b, roleBasedNameOnly))
2155
+ );
2156
+ }
2157
+ function resolveGezelArg(arg, inputs) {
2158
+ const query = arg.trim().toLowerCase();
2159
+ if (!query) return { kind: "unknown" };
2160
+ const { gezels, templates } = inputs;
2161
+ const gezelKeys = (g) => [g.id, g.name, g.roleBasedName, g.role].map(roleIdentity).filter(Boolean);
2162
+ const templateKeys = (t) => [t.id, t.role, t.name].map(roleIdentity).filter(Boolean);
2163
+ const exactGezel = gezels.find((g) => gezelKeys(g).includes(query));
2164
+ if (exactGezel) return { kind: "gezel", gezelId: exactGezel.id };
2165
+ const exactTemplate = templates.find((t) => templateKeys(t).includes(query));
2166
+ if (exactTemplate) return { kind: "template", templateId: exactTemplate.id };
2167
+ const prefixGezels = gezels.filter((g) => gezelKeys(g).some((k) => k.startsWith(query)));
2168
+ if (prefixGezels.length === 1) return { kind: "gezel", gezelId: prefixGezels[0].id };
2169
+ if (prefixGezels.length > 1) {
2170
+ return { kind: "ambiguous", labels: prefixGezels.map((g) => g.name) };
2171
+ }
2172
+ const prefixTemplates = templates.filter((t) => templateKeys(t).some((k) => k.startsWith(query)));
2173
+ if (prefixTemplates.length === 1) return { kind: "template", templateId: prefixTemplates[0].id };
2174
+ if (prefixTemplates.length > 1) {
2175
+ return { kind: "ambiguous", labels: prefixTemplates.map((t) => t.name) };
2176
+ }
2177
+ return { kind: "unknown" };
2178
+ }
2179
+
2005
2180
  // src/tui/model-picker.ts
2006
2181
  import {
2007
2182
  formatModelAttribution as formatModelAttribution2
@@ -2414,7 +2589,8 @@ function useTerminalSize() {
2414
2589
  return size;
2415
2590
  }
2416
2591
  var HELP = [
2417
- "/project \u2014 switch project /gezel \u2014 switch gezel /model \u2014 switch engine + model",
2592
+ "/project \u2014 switch project /model \u2014 switch engine + model",
2593
+ "/gezel \u2014 switch gezel or bring on a role /gezel <role or name> \u2014 go straight there",
2418
2594
  "/model download \u2014 choose and download a new on-device model",
2419
2595
  "/allow edits \u2014 allow tool edits /disallow edits \u2014 make tool edits read-only",
2420
2596
  "/allow codexedits|claudeedits \u2014 allow provider-native project edits",
@@ -2457,6 +2633,8 @@ function App(props) {
2457
2633
  const [modelDownloadReturn, setModelDownloadReturn] = useState5(null);
2458
2634
  const [modelChoicesLoading, setModelChoicesLoading] = useState5(false);
2459
2635
  const [threadsLoading, setThreadsLoading] = useState5(false);
2636
+ const [gezelPickerItems, setGezelPickerItems] = useState5([]);
2637
+ const [roleTemplates, setRoleTemplates] = useState5([]);
2460
2638
  const [pendingQuestions, setPendingQuestions] = useState5([]);
2461
2639
  const [projectId, setProjectId] = useState5(props.initialProjectId);
2462
2640
  const [projectName, setProjectName] = useState5(props.initialProjectName);
@@ -2488,7 +2666,8 @@ function App(props) {
2488
2666
  const wordwheelRows = wordwheelCount > 0 ? Math.min(SLASH_COMMAND_WORDWHEEL_SIZE, wordwheelCount) + 1 : 0;
2489
2667
  const questionRows = pendingQuestion ? Math.min(QUESTION_OPTION_WINDOW_SIZE, Math.max(1, questionOptionCount(pendingQuestion))) + 4 : 0;
2490
2668
  const modelPickerWindowSize = Math.max(4, Math.min(10, termRows - 12));
2491
- const inventoryPickerRows = overlay === "model" || overlay === "model-download" || overlay === "start-category" || overlay === "start-craftbook" ? modelPickerWindowSize + 5 : 0;
2669
+ const gezelPickerWindowSize = Math.max(4, Math.min(10, termRows - 17));
2670
+ const inventoryPickerRows = overlay === "model" || overlay === "model-download" || overlay === "start-category" || overlay === "start-craftbook" ? modelPickerWindowSize + 5 : overlay === "gezel" ? gezelPickerWindowSize + 10 : 0;
2492
2671
  const visibleRows = Math.max(
2493
2672
  4,
2494
2673
  termRows - 7 - wordwheelRows - questionRows - inventoryPickerRows
@@ -2694,6 +2873,119 @@ function App(props) {
2694
2873
  },
2695
2874
  [client, ensureSession, note, projectId, projects, setRows, setTurns]
2696
2875
  );
2876
+ const loadRoleTemplates = useCallback2(async () => {
2877
+ if (roleTemplates.length > 0) return roleTemplates;
2878
+ try {
2879
+ const { items } = await client.listCatalogItems("gezel-template");
2880
+ const byId = /* @__PURE__ */ new Map();
2881
+ for (const item of items) {
2882
+ const manifest = item.manifest;
2883
+ if (manifest.kind !== "gezel-template" || byId.has(manifest.id)) continue;
2884
+ byId.set(manifest.id, {
2885
+ id: manifest.id,
2886
+ name: manifest.name,
2887
+ role: manifest.role,
2888
+ description: manifest.description
2889
+ });
2890
+ }
2891
+ const loaded = [...byId.values()];
2892
+ setRoleTemplates(loaded);
2893
+ return loaded;
2894
+ } catch (err) {
2895
+ note(`could not load the role catalog: ${errMsg(err)}`, "error");
2896
+ return [];
2897
+ }
2898
+ }, [client, note, roleTemplates]);
2899
+ const promoteSoloProject = useCallback2(
2900
+ async (joinedGezelId) => {
2901
+ try {
2902
+ const project = await client.getProject(projectId);
2903
+ if (project.mode !== "solo") return;
2904
+ if (project.voormanGezelId === joinedGezelId) return;
2905
+ await client.updateProject(projectId, { mode: "crew" });
2906
+ note("this job is now a crew project \u2014 gezels here can delegate and recruit.");
2907
+ } catch (err) {
2908
+ note(`could not switch this job to a crew project: ${errMsg(err)}`, "error");
2909
+ }
2910
+ },
2911
+ [client, note, projectId]
2912
+ );
2913
+ const useGezel = useCallback2(
2914
+ async (gezelId) => {
2915
+ if (gezelId === activeGezelId) return;
2916
+ try {
2917
+ const { added } = await client.addGezelToProject(projectId, gezelId);
2918
+ if (added) await promoteSoloProject(gezelId);
2919
+ } catch (err) {
2920
+ note(`could not add to the project roster: ${errMsg(err)}`, "error");
2921
+ }
2922
+ setActiveGezelId(gezelId);
2923
+ setThreads([]);
2924
+ setActiveThreadTitle(null);
2925
+ await ensureSession(gezelId, projectId);
2926
+ },
2927
+ [activeGezelId, client, ensureSession, note, projectId, promoteSoloProject]
2928
+ );
2929
+ const recruitGezel = useCallback2(
2930
+ async (templateId) => {
2931
+ note(`recruiting ${templateId}\u2026`);
2932
+ try {
2933
+ const { name, gender } = pickRandomNameWithGender2();
2934
+ const gezel = await client.createGezelFromTemplate(templateId, { name, gender });
2935
+ await refreshGezels();
2936
+ note(`${gezel.name} joined the project as ${gezel.role ?? templateId}.`);
2937
+ await useGezel(gezel.id);
2938
+ } catch (err) {
2939
+ note(`could not recruit ${templateId}: ${errMsg(err)}`, "error");
2940
+ }
2941
+ },
2942
+ [client, note, refreshGezels, useGezel]
2943
+ );
2944
+ const openGezelPicker = useCallback2(async () => {
2945
+ const templates = await loadRoleTemplates();
2946
+ let project = null;
2947
+ try {
2948
+ project = await client.getProject(projectId);
2949
+ } catch {
2950
+ }
2951
+ setGezelPickerItems(
2952
+ buildGezelPickerItems({
2953
+ gezels,
2954
+ templates,
2955
+ memberIds: [
2956
+ // Without the project record we only know the gezel we are talking
2957
+ // to. Claiming the whole roster is "in this project" would be a
2958
+ // guess the header presents as fact.
2959
+ ...project?.gezelIds ?? (activeGezelId ? [activeGezelId] : []),
2960
+ ...project?.voormanGezelId ? [project.voormanGezelId] : []
2961
+ ],
2962
+ ...project ? { project } : {},
2963
+ roleBasedNameOnly: boring,
2964
+ hintWidth: Math.max(24, shellColumns - 34)
2965
+ })
2966
+ );
2967
+ setOverlay("gezel");
2968
+ }, [activeGezelId, boring, client, gezels, loadRoleTemplates, projectId, shellColumns]);
2969
+ const ensureGezelByName = useCallback2(
2970
+ async (arg) => {
2971
+ const templates = await loadRoleTemplates();
2972
+ const resolved = resolveGezelArg(arg, { gezels, templates });
2973
+ switch (resolved.kind) {
2974
+ case "gezel":
2975
+ return useGezel(resolved.gezelId);
2976
+ case "template":
2977
+ return recruitGezel(resolved.templateId);
2978
+ case "ambiguous":
2979
+ return note(
2980
+ `"${arg}" matches ${resolved.labels.join(", ")} \u2014 be more specific.`,
2981
+ "error"
2982
+ );
2983
+ default:
2984
+ return note(`no gezel or role matches "${arg}". Type /gezel to browse.`, "error");
2985
+ }
2986
+ },
2987
+ [gezels, loadRoleTemplates, note, recruitGezel, useGezel]
2988
+ );
2697
2989
  const openModelPicker = useCallback2(async () => {
2698
2990
  if (!activeGezelId || !activeGezel) return note("no active gezel yet.", "error");
2699
2991
  if (activeGezel.fixedFunction) {
@@ -3209,8 +3501,11 @@ function App(props) {
3209
3501
  return;
3210
3502
  case "project":
3211
3503
  return setOverlay("project");
3212
- case "gezel":
3213
- return setOverlay("gezel");
3504
+ case "gezel": {
3505
+ const target = rest.trim();
3506
+ if (target) return ensureGezelByName(target);
3507
+ return openGezelPicker();
3508
+ }
3214
3509
  case "allow":
3215
3510
  await applyProjectPermission(rest, true);
3216
3511
  return;
@@ -3390,8 +3685,10 @@ function App(props) {
3390
3685
  applyChatDetailVisibility,
3391
3686
  client,
3392
3687
  craftbooks,
3688
+ ensureGezelByName,
3393
3689
  note,
3394
3690
  exit,
3691
+ openGezelPicker,
3395
3692
  openModelDownloadPicker,
3396
3693
  openModelPicker,
3397
3694
  openThreadPicker,
@@ -3594,20 +3891,17 @@ function App(props) {
3594
3891
  overlay === "gezel" ? /* @__PURE__ */ jsx5(
3595
3892
  Picker,
3596
3893
  {
3597
- title: "Switch gezel",
3598
- items: gezels.map((g) => ({
3599
- label: boring ? g.roleBasedName ?? g.role ?? g.id : g.name,
3600
- value: g.id,
3601
- hint: g.role
3602
- })),
3894
+ title: "Switch gezel, or bring on a role",
3895
+ items: gezelPickerItems,
3896
+ windowSize: gezelPickerWindowSize,
3603
3897
  onCancel: () => setOverlay(null),
3604
- onSelect: (id) => {
3898
+ onSelect: (value2) => {
3605
3899
  setOverlay(null);
3606
- if (id === activeGezelId) return;
3607
- setActiveGezelId(id);
3608
- setThreads([]);
3609
- setActiveThreadTitle(null);
3610
- void ensureSession(id, projectId);
3900
+ if (value2.startsWith(TEMPLATE_VALUE_PREFIX)) {
3901
+ void recruitGezel(value2.slice(TEMPLATE_VALUE_PREFIX.length));
3902
+ return;
3903
+ }
3904
+ void useGezel(value2.slice(GEZEL_VALUE_PREFIX.length));
3611
3905
  }
3612
3906
  }
3613
3907
  ) : null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bendyline/gezel-cli",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "The `gezel` command-line tool.",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -44,14 +44,14 @@
44
44
  "!dist/**/*.map"
45
45
  ],
46
46
  "dependencies": {
47
- "@bendyline/gezel": "1.0.5",
48
- "@bendyline/gezel-app-sdk": "1.0.5",
49
- "@bendyline/gezel-catalog": "1.0.5",
50
- "@bendyline/gezel-client": "1.0.5",
51
- "@bendyline/gezel-service": "1.0.5",
52
- "@bendyline/squisq": "2.7.1",
53
- "@bendyline/squisq-formats": "2.4.4",
54
- "@bendyline/squisq-react": "2.7.2",
47
+ "@bendyline/gezel": "1.0.6",
48
+ "@bendyline/gezel-app-sdk": "1.0.6",
49
+ "@bendyline/gezel-catalog": "1.0.6",
50
+ "@bendyline/gezel-client": "1.0.6",
51
+ "@bendyline/gezel-service": "1.0.6",
52
+ "@bendyline/squisq": "2.8.0",
53
+ "@bendyline/squisq-formats": "2.4.5",
54
+ "@bendyline/squisq-react": "2.8.0",
55
55
  "commander": "^15.0.0",
56
56
  "ink": "^7.1.1",
57
57
  "ink-text-input": "^6.0.0",