@bendyline/gezel-cli 1.0.0 → 1.0.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/dist/tui/index.js CHANGED
@@ -7,39 +7,135 @@ import { render } from "ink";
7
7
  import { Box as Box6, Text as Text6, useApp, useInput as useInput4, useStdout } from "ink";
8
8
  import { useCallback, useEffect as useEffect3, useMemo, useRef as useRef2, useState as useState4 } from "react";
9
9
 
10
- // src/tui/active-access.ts
10
+ // src/connection.ts
11
+ import { createHash, randomUUID } from "crypto";
12
+ import { chmod, mkdir, readFile, rm, writeFile } from "fs/promises";
13
+ import { homedir } from "os";
14
+ import { basename, dirname, join, resolve } from "path";
15
+ import { pickRandomNameWithGender } from "@bendyline/gezel";
11
16
  import {
12
- normalizeCodexPermissionMode,
13
- projectWorkspaceWritable,
14
- resolveSandboxCopilot
15
- } from "@bendyline/gezel";
17
+ GezelSdkError,
18
+ authorizeLocal,
19
+ authorizeLocalOwner
20
+ } from "@bendyline/gezel-app-sdk";
21
+ import {
22
+ GezelApiError,
23
+ GezelClient,
24
+ createTrustingFetch,
25
+ electronNativeBinCandidates,
26
+ isProcessAlive,
27
+ readRuntime,
28
+ readSystemServiceEndpoint,
29
+ resolveDaemonEntry,
30
+ systemSharedAssetsDir
31
+ } from "@bendyline/gezel-client/node";
32
+ import { gezelPaths } from "@bendyline/gezel/paths";
33
+ var CliError = class extends Error {
34
+ constructor(message) {
35
+ super(message);
36
+ this.name = "CliError";
37
+ }
38
+ };
39
+ async function ensureCliProjectLead(client, projectId) {
40
+ const project = await client.getProject(projectId);
41
+ if (project.voormanGezelId) return project.voormanGezelId;
42
+ if (project.mode === "solo" && project.gezelIds?.[0]) return project.gezelIds[0];
43
+ const { gezels } = await client.listGezels();
44
+ let voorman = gezels.find(
45
+ (gezel) => gezel.templateId === "voorman" || gezel.role?.trim().toLowerCase() === "voorman"
46
+ );
47
+ if (!voorman) {
48
+ const { name, gender } = pickRandomNameWithGender();
49
+ voorman = await client.createGezelFromTemplate("voorman", { name, gender });
50
+ }
51
+ const updated = await client.updateProject(projectId, { voormanGezelId: voorman.id });
52
+ if (!updated.voormanGezelId) {
53
+ throw new CliError(`project "${updated.name}" has no voorman`);
54
+ }
55
+ return updated.voormanGezelId;
56
+ }
57
+
58
+ // src/engagement-mode.ts
59
+ var CLI_ENGAGEMENT_MODES = [
60
+ {
61
+ name: "read-only",
62
+ mode: "off",
63
+ label: "Read-only",
64
+ description: "AI is paused; browse projects and history without starting AI work."
65
+ },
66
+ {
67
+ name: "reactive",
68
+ mode: "reactive",
69
+ label: "Reactive",
70
+ description: "AI replies to messages; autonomous task work stays paused."
71
+ },
72
+ {
73
+ name: "reactive+tasks",
74
+ mode: "scheduled",
75
+ label: "Reactive + tasks",
76
+ description: "Messages, task work, and schedules run without proactive nudges."
77
+ },
78
+ {
79
+ name: "full-play",
80
+ mode: "proactive",
81
+ label: "Full play",
82
+ description: "Everything runs, including proactive nudges and cross-gezel work."
83
+ }
84
+ ];
85
+ var MODE_ALIASES = {
86
+ "read-only": "off",
87
+ readonly: "off",
88
+ off: "off",
89
+ reactive: "reactive",
90
+ "reactive-only": "reactive",
91
+ "reactive+tasks": "scheduled",
92
+ "tasks+reactive": "scheduled",
93
+ scheduled: "scheduled",
94
+ "full-play": "proactive",
95
+ fullplay: "proactive",
96
+ proactive: "proactive"
97
+ };
98
+ function parseCliEngagementMode(input) {
99
+ const normalized = input.trim().toLowerCase().replace(/\s*\+\s*/g, "+").replace(/[\s_]+/g, "-");
100
+ return MODE_ALIASES[normalized] ?? null;
101
+ }
102
+ function cliEngagementModeOption(mode) {
103
+ return CLI_ENGAGEMENT_MODES.find((option) => option.mode === (mode ?? "proactive"));
104
+ }
105
+ var CLI_ENGAGEMENT_MODE_USAGE = CLI_ENGAGEMENT_MODES.map((option) => option.name).join(
106
+ "|"
107
+ );
108
+
109
+ // src/tui/active-access.ts
110
+ import * as GezelCore from "@bendyline/gezel";
16
111
  function activeAccessMode(opts) {
112
+ const resolveAccess = Reflect.get(GezelCore, "resolveGezelWorkspaceAccess");
113
+ if (resolveAccess) {
114
+ const access = resolveAccess(opts);
115
+ if (access.nativeAccess === "reviewed") return "reviewed edits";
116
+ if (access.nativeAccess === "full") return "full access";
117
+ return access.effectiveWritable ? "editable" : "read-only";
118
+ }
17
119
  const { provider, project, gezel, config } = opts;
18
120
  if (provider === "codex-cli") {
19
- const mode = normalizeCodexPermissionMode(
121
+ const mode = GezelCore.normalizeCodexPermissionMode(
20
122
  project?.codexPermissionMode ?? gezel?.codexPermissionMode ?? gezel?.claudePermissionMode ?? config?.codexCli?.defaultPermissionMode
21
123
  );
22
- switch (mode) {
23
- case "plan":
24
- return "read-only";
25
- case "edit":
26
- return "editable";
27
- case "reviewed":
28
- return "reviewed edits";
29
- case "full":
30
- return "full access";
31
- }
124
+ if (mode === "plan") return "read-only";
125
+ if (mode === "reviewed") return "reviewed edits";
126
+ if (mode === "full") return "full access";
127
+ return "editable";
32
128
  }
33
129
  if (provider === "anthropic-cli") {
34
- const mode = gezel?.claudePermissionMode ?? config?.anthropicCli?.defaultPermissionMode ?? "acceptEdits";
130
+ const mode = project?.claudePermissionMode ?? gezel?.claudePermissionMode ?? config?.anthropicCli?.defaultPermissionMode ?? "acceptEdits";
35
131
  if (mode === "plan") return "read-only";
36
132
  if (mode === "bypassPermissions") return "full access";
37
133
  return "editable";
38
134
  }
39
- if (provider === "copilot" && !resolveSandboxCopilot(config?.sandboxCopilot, gezel?.sandboxCopilot)) {
135
+ if (provider === "copilot" && !GezelCore.resolveSandboxCopilot(config?.sandboxCopilot, gezel?.sandboxCopilot)) {
40
136
  return "editable";
41
137
  }
42
- return projectWorkspaceWritable(project) ? "editable" : "read-only";
138
+ return GezelCore.projectWorkspaceWritable(project) ? "editable" : "read-only";
43
139
  }
44
140
 
45
141
  // src/tui/commands.ts
@@ -48,6 +144,7 @@ var SLASH_COMMANDS = [
48
144
  { name: "help", description: "show the command reference" },
49
145
  { name: "project", description: "switch active project" },
50
146
  { name: "gezel", description: "switch active gezel" },
147
+ { name: "mode", description: "set AI activity: read-only through full play" },
51
148
  { name: "model", description: "switch engine and model" },
52
149
  { name: "thread", description: "switch the active chat thread" },
53
150
  { name: "task", description: "list and manage project tasks" },
@@ -71,6 +168,17 @@ var NIGHT_SHIFT_SUBCOMMANDS = [
71
168
  { name: "list", description: "show current and upcoming night-shift work" }
72
169
  ];
73
170
  function suggestSlashWordwheel(input, craftbooks) {
171
+ const modeMatch = input.match(/^\/mode\s+(.*)$/i);
172
+ if (modeMatch) {
173
+ const query = (modeMatch[1] ?? "").trim().toLowerCase();
174
+ return CLI_ENGAGEMENT_MODES.filter((option) => option.name.startsWith(query)).map((option) => ({
175
+ key: `mode:${option.name}`,
176
+ label: `/mode ${option.name}`,
177
+ description: option.description,
178
+ submit: `/mode ${option.name}`,
179
+ completion: `/mode ${option.name}`
180
+ }));
181
+ }
74
182
  const nightShiftMatch = input.match(/^\/nightshift\s+(.*)$/i);
75
183
  if (nightShiftMatch) {
76
184
  const query = (nightShiftMatch[1] ?? "").trim().toLowerCase();
@@ -1212,13 +1320,13 @@ async function consumeWithReconnect(open, handler, signal) {
1212
1320
  }
1213
1321
  }
1214
1322
  function abortableDelay(ms, signal) {
1215
- return new Promise((resolve) => {
1323
+ return new Promise((resolve2) => {
1216
1324
  const timer = setTimeout(done, ms);
1217
1325
  signal.addEventListener("abort", done, { once: true });
1218
1326
  function done() {
1219
1327
  clearTimeout(timer);
1220
1328
  signal.removeEventListener("abort", done);
1221
- resolve();
1329
+ resolve2();
1222
1330
  }
1223
1331
  });
1224
1332
  }
@@ -1240,6 +1348,7 @@ function useTerminalSize() {
1240
1348
  }
1241
1349
  var HELP = [
1242
1350
  "/project \u2014 switch project /gezel \u2014 switch gezel /model \u2014 switch engine + model",
1351
+ "/mode \u2014 choose read-only, reactive, reactive+tasks, or full-play AI activity",
1243
1352
  "/thread \u2014 switch or start a chat thread",
1244
1353
  "/task \u2014 list, inspect, create, edit, assign, or change task status",
1245
1354
  "/start \u2014 choose a craftbook and start it as a task",
@@ -1410,6 +1519,38 @@ function App(props) {
1410
1519
  },
1411
1520
  [client, note]
1412
1521
  );
1522
+ const switchProject = useCallback(
1523
+ async (id) => {
1524
+ setOverlay(null);
1525
+ const project = projects.find((candidate) => candidate.id === id);
1526
+ if (!project || id === projectId) return;
1527
+ try {
1528
+ const gezelId = project.voormanGezelId ?? await ensureCliProjectLead(client, id);
1529
+ setProjectId(id);
1530
+ setProjectName(project.name);
1531
+ setActiveGezelId(gezelId);
1532
+ setRows([]);
1533
+ setTurns(/* @__PURE__ */ new Map());
1534
+ setActiveRuns(/* @__PURE__ */ new Set());
1535
+ setPendingInput(null);
1536
+ setPendingQuestions([]);
1537
+ setThreads([]);
1538
+ setActiveThreadTitle(null);
1539
+ setTasks([]);
1540
+ setCraftbooks([]);
1541
+ setCraftbookProjectType(null);
1542
+ setSuggestedCraftbookIds(/* @__PURE__ */ new Set());
1543
+ setCraftbooksNeedingSetup(/* @__PURE__ */ new Set());
1544
+ setStartCategoryId(null);
1545
+ setManagedTaskRef(null);
1546
+ setTaskPrompt(null);
1547
+ await ensureSession(gezelId, id);
1548
+ } catch (err) {
1549
+ note(`could not switch project: ${errMsg(err)}`, "error");
1550
+ }
1551
+ },
1552
+ [client, ensureSession, note, projectId, projects]
1553
+ );
1413
1554
  const openThreadPicker = useCallback(async () => {
1414
1555
  if (!activeGezelId) return note("no active gezel yet.", "error");
1415
1556
  if (threadsLoading) return;
@@ -1473,15 +1614,17 @@ function App(props) {
1473
1614
  id: p.id,
1474
1615
  name: p.name,
1475
1616
  workingDir: p.workingDir,
1617
+ voormanGezelId: p.voormanGezelId,
1618
+ managedWorkspaceWritePolicy: p.managedWorkspaceWritePolicy,
1476
1619
  allowGezelWrites: p.allowGezelWrites,
1477
- codexPermissionMode: p.codexPermissionMode
1620
+ codexPermissionMode: p.codexPermissionMode,
1621
+ claudePermissionMode: p.claudePermissionMode
1478
1622
  }))
1479
1623
  );
1480
- const gezelId = cfg.meesterGezelId ?? gz.gezels[0]?.id ?? null;
1624
+ const gezelId = props.initialGezelId;
1481
1625
  setActiveGezelId(gezelId);
1482
1626
  setStatus(null);
1483
- if (gezelId) await ensureSession(gezelId, projectId);
1484
- else note("no gezels available \u2014 create one with `gezel agent create`.", "error");
1627
+ await ensureSession(gezelId, projectId);
1485
1628
  } catch (err) {
1486
1629
  if (!cancelled) setStatus(`Failed to connect: ${errMsg(err)}`);
1487
1630
  }
@@ -1577,6 +1720,25 @@ function App(props) {
1577
1720
  const rememberTask = useCallback((task) => {
1578
1721
  setTasks((current) => sortTasks([...current.filter((item) => item.ref !== task.ref), task]));
1579
1722
  }, []);
1723
+ const applyEngagementMode = useCallback(
1724
+ async (requested) => {
1725
+ const next = parseCliEngagementMode(requested);
1726
+ if (!next) {
1727
+ note(`usage: /mode ${CLI_ENGAGEMENT_MODE_USAGE}`, "error");
1728
+ return;
1729
+ }
1730
+ const option = cliEngagementModeOption(next);
1731
+ setOverlay(null);
1732
+ try {
1733
+ const updated = await client.updateConfig({ aiEngagementMode: next });
1734
+ setConfig(updated);
1735
+ note(`AI mode \u2192 ${option.label}. ${option.description}`);
1736
+ } catch (err) {
1737
+ note(`could not change AI mode: ${errMsg(err)}`, "error");
1738
+ }
1739
+ },
1740
+ [client, note]
1741
+ );
1580
1742
  const startCraftbook = useCallback(
1581
1743
  async (book) => {
1582
1744
  setOverlay(null);
@@ -1770,6 +1932,10 @@ function App(props) {
1770
1932
  return setOverlay("project");
1771
1933
  case "gezel":
1772
1934
  return setOverlay("gezel");
1935
+ case "mode":
1936
+ if (!rest.trim()) return setOverlay("engagement-mode");
1937
+ await applyEngagementMode(rest);
1938
+ return;
1773
1939
  case "model": {
1774
1940
  if (!activeGezelId || !activeGezel) return note("no active gezel yet.", "error");
1775
1941
  if (activeGezel.fixedFunction) {
@@ -1919,6 +2085,7 @@ function App(props) {
1919
2085
  [
1920
2086
  activeGezel,
1921
2087
  activeGezelId,
2088
+ applyEngagementMode,
1922
2089
  client,
1923
2090
  config,
1924
2091
  craftbooks,
@@ -2028,29 +2195,7 @@ function App(props) {
2028
2195
  title: "Switch project",
2029
2196
  items: projects.map((p) => ({ label: p.name, value: p.id, hint: p.workingDir })),
2030
2197
  onCancel: () => setOverlay(null),
2031
- onSelect: (id) => {
2032
- setOverlay(null);
2033
- const p = projects.find((x) => x.id === id);
2034
- if (!p || id === projectId) return;
2035
- setProjectId(id);
2036
- setProjectName(p.name);
2037
- setRows([]);
2038
- setTurns(/* @__PURE__ */ new Map());
2039
- setActiveRuns(/* @__PURE__ */ new Set());
2040
- setPendingInput(null);
2041
- setPendingQuestions([]);
2042
- setThreads([]);
2043
- setActiveThreadTitle(null);
2044
- setTasks([]);
2045
- setCraftbooks([]);
2046
- setCraftbookProjectType(null);
2047
- setSuggestedCraftbookIds(/* @__PURE__ */ new Set());
2048
- setCraftbooksNeedingSetup(/* @__PURE__ */ new Set());
2049
- setStartCategoryId(null);
2050
- setManagedTaskRef(null);
2051
- setTaskPrompt(null);
2052
- if (activeGezelId) void ensureSession(activeGezelId, id);
2053
- }
2198
+ onSelect: (id) => void switchProject(id)
2054
2199
  }
2055
2200
  ) : null,
2056
2201
  overlay === "gezel" ? /* @__PURE__ */ jsx6(
@@ -2073,6 +2218,20 @@ function App(props) {
2073
2218
  }
2074
2219
  }
2075
2220
  ) : null,
2221
+ overlay === "engagement-mode" ? /* @__PURE__ */ jsx6(
2222
+ Picker,
2223
+ {
2224
+ title: "Choose AI engagement mode",
2225
+ items: CLI_ENGAGEMENT_MODES.map((option) => ({
2226
+ label: option.label,
2227
+ value: option.name,
2228
+ hint: option.description
2229
+ })),
2230
+ initialValue: cliEngagementModeOption(config?.aiEngagementMode).name,
2231
+ onCancel: () => setOverlay(null),
2232
+ onSelect: (selected) => void applyEngagementMode(selected)
2233
+ }
2234
+ ) : null,
2076
2235
  overlay === "model" ? /* @__PURE__ */ jsx6(
2077
2236
  Picker,
2078
2237
  {
@@ -3078,7 +3237,7 @@ function errorMessage(error) {
3078
3237
  return error instanceof Error ? error.message : String(error);
3079
3238
  }
3080
3239
  function delay(ms) {
3081
- return new Promise((resolve) => setTimeout(resolve, ms));
3240
+ return new Promise((resolve2) => setTimeout(resolve2, ms));
3082
3241
  }
3083
3242
 
3084
3243
  // src/tui/index.tsx
@@ -3090,7 +3249,8 @@ async function launchTui(opts) {
3090
3249
  {
3091
3250
  client: opts.client,
3092
3251
  initialProjectId: opts.projectId,
3093
- initialProjectName: opts.projectName
3252
+ initialProjectName: opts.projectName,
3253
+ initialGezelId: opts.gezelId
3094
3254
  }
3095
3255
  ) }),
3096
3256
  // We own Ctrl+C (interrupt-then-exit); don't let ink exit on the first press.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bendyline/gezel-cli",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "The `gezel` command-line tool.",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -44,11 +44,11 @@
44
44
  "!dist/**/*.map"
45
45
  ],
46
46
  "dependencies": {
47
- "@bendyline/gezel": "1.0.0",
48
- "@bendyline/gezel-app-sdk": "1.0.0",
49
- "@bendyline/gezel-catalog": "1.0.0",
50
- "@bendyline/gezel-client": "1.0.0",
51
- "@bendyline/gezel-service": "1.0.0",
47
+ "@bendyline/gezel": "1.0.2",
48
+ "@bendyline/gezel-app-sdk": "1.0.2",
49
+ "@bendyline/gezel-catalog": "1.0.2",
50
+ "@bendyline/gezel-client": "1.0.2",
51
+ "@bendyline/gezel-service": "1.0.2",
52
52
  "@bendyline/squisq": "2.7.1",
53
53
  "@bendyline/squisq-formats": "2.4.3",
54
54
  "@bendyline/squisq-react": "2.7.1",