@bendyline/gezel-cli 1.0.3 → 1.0.5
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 +8 -3
- package/dist/bin/gezel-main.js +1663 -0
- package/dist/bin/gezel.js +4 -6005
- package/dist/tui/index.js +1259 -221
- package/package.json +9 -9
package/dist/tui/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { render } from "ink";
|
|
|
5
5
|
|
|
6
6
|
// src/tui/App.tsx
|
|
7
7
|
import { Box as Box6, Text as Text6, useApp, useInput as useInput4, useStdout } from "ink";
|
|
8
|
-
import { useCallback, useEffect as
|
|
8
|
+
import { useCallback as useCallback2, useEffect as useEffect4, useMemo, useRef as useRef3, useState as useState5 } from "react";
|
|
9
9
|
|
|
10
10
|
// src/connection.ts
|
|
11
11
|
import { createHash, randomUUID } from "crypto";
|
|
@@ -41,7 +41,24 @@ var CliError = class extends Error {
|
|
|
41
41
|
async function ensureCliProjectLead(client, projectId) {
|
|
42
42
|
const project = await client.getProject(projectId);
|
|
43
43
|
if (project.voormanGezelId) return project.voormanGezelId;
|
|
44
|
-
if (project.mode === "solo"
|
|
44
|
+
if (project.mode === "solo") {
|
|
45
|
+
if (project.gezelIds?.[0]) return project.gezelIds[0];
|
|
46
|
+
if (project.workingDir) {
|
|
47
|
+
const { gezels: gezels2 } = await client.listGezels();
|
|
48
|
+
let builder = gezels2.find(
|
|
49
|
+
(gezel) => gezel.templateId === "builder" || gezel.role?.trim().toLowerCase() === "builder"
|
|
50
|
+
);
|
|
51
|
+
if (!builder) {
|
|
52
|
+
const { name, gender } = pickRandomNameWithGender();
|
|
53
|
+
builder = await client.createGezelFromTemplate("builder", { name, gender });
|
|
54
|
+
}
|
|
55
|
+
const updated2 = await client.updateProject(projectId, { voormanGezelId: builder.id });
|
|
56
|
+
if (!updated2.voormanGezelId) {
|
|
57
|
+
throw new CliError(`project "${updated2.name}" has no Builder`);
|
|
58
|
+
}
|
|
59
|
+
return updated2.voormanGezelId;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
45
62
|
const { gezels } = await client.listGezels();
|
|
46
63
|
let voorman = gezels.find(
|
|
47
64
|
(gezel) => gezel.templateId === "voorman" || gezel.role?.trim().toLowerCase() === "voorman"
|
|
@@ -140,6 +157,147 @@ function activeAccessMode(opts) {
|
|
|
140
157
|
return GezelCore.projectWorkspaceWritable(project) ? "editable" : "read-only";
|
|
141
158
|
}
|
|
142
159
|
|
|
160
|
+
// src/tui/buffered-state.ts
|
|
161
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
162
|
+
function useBufferedState(initial, intervalMs) {
|
|
163
|
+
const [rendered, setRendered] = useState(initial);
|
|
164
|
+
const valueRef = useRef(rendered);
|
|
165
|
+
const timerRef = useRef(null);
|
|
166
|
+
const cancelTimer = useCallback(() => {
|
|
167
|
+
if (timerRef.current === null) return;
|
|
168
|
+
clearTimeout(timerRef.current);
|
|
169
|
+
timerRef.current = null;
|
|
170
|
+
}, []);
|
|
171
|
+
const apply = useCallback(
|
|
172
|
+
(update, buffered) => {
|
|
173
|
+
const current = valueRef.current;
|
|
174
|
+
const next = typeof update === "function" ? update(current) : update;
|
|
175
|
+
valueRef.current = next;
|
|
176
|
+
if (!buffered) {
|
|
177
|
+
cancelTimer();
|
|
178
|
+
setRendered(next);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
if (Object.is(current, next) || timerRef.current !== null) return;
|
|
182
|
+
timerRef.current = setTimeout(() => {
|
|
183
|
+
timerRef.current = null;
|
|
184
|
+
setRendered(valueRef.current);
|
|
185
|
+
}, intervalMs);
|
|
186
|
+
},
|
|
187
|
+
[cancelTimer, intervalMs]
|
|
188
|
+
);
|
|
189
|
+
const setImmediate = useCallback(
|
|
190
|
+
(update) => apply(update, false),
|
|
191
|
+
[apply]
|
|
192
|
+
);
|
|
193
|
+
const setBuffered = useCallback((update) => apply(update, true), [apply]);
|
|
194
|
+
useEffect(() => cancelTimer, [cancelTimer]);
|
|
195
|
+
return [rendered, setImmediate, setBuffered];
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// src/tui/open-command.ts
|
|
199
|
+
var MAX_RECENT_REFERENCES = 12;
|
|
200
|
+
function rememberCliOpenReferences(current, observed, max = MAX_RECENT_REFERENCES) {
|
|
201
|
+
const next = [...current];
|
|
202
|
+
for (const reference2 of observed) {
|
|
203
|
+
const index = next.findIndex((candidate) => candidate.key === reference2.key);
|
|
204
|
+
if (index !== -1) next.splice(index, 1);
|
|
205
|
+
next.unshift(reference2);
|
|
206
|
+
}
|
|
207
|
+
return next.slice(0, max);
|
|
208
|
+
}
|
|
209
|
+
function cliOpenReferencesFromEvent(env) {
|
|
210
|
+
if (env.event.type === "tool") {
|
|
211
|
+
return referencesFromTool(env.event, env.projectId);
|
|
212
|
+
}
|
|
213
|
+
if (env.event.type === "complete" || env.event.type === "user_message") {
|
|
214
|
+
return referencesFromMessage(env.event.message, env.projectId);
|
|
215
|
+
}
|
|
216
|
+
return [];
|
|
217
|
+
}
|
|
218
|
+
function cliOpenReferencesFromSession(session) {
|
|
219
|
+
let recent = [];
|
|
220
|
+
for (const message of session.messages) {
|
|
221
|
+
recent = rememberCliOpenReferences(recent, referencesFromMessage(message, session.projectId));
|
|
222
|
+
}
|
|
223
|
+
return recent;
|
|
224
|
+
}
|
|
225
|
+
function resolveCliOpenTarget(input, recentReferences) {
|
|
226
|
+
const query = normalizeLookup(input);
|
|
227
|
+
if (query === "workspace" || query === "artifacts") {
|
|
228
|
+
return { type: "folder", folder: query };
|
|
229
|
+
}
|
|
230
|
+
if (!query) return null;
|
|
231
|
+
const exact = recentReferences.find((reference2) => normalizeLookup(reference2.path) === query);
|
|
232
|
+
if (exact) return { type: "reference", reference: exact };
|
|
233
|
+
const basenameMatches = recentReferences.filter(
|
|
234
|
+
(reference2) => normalizeLookup(basename2(reference2.path)) === query
|
|
235
|
+
);
|
|
236
|
+
return basenameMatches.length === 1 ? { type: "reference", reference: basenameMatches[0] } : null;
|
|
237
|
+
}
|
|
238
|
+
function referencesFromMessage(message, projectId) {
|
|
239
|
+
const references = [];
|
|
240
|
+
for (const tool of message.toolCalls ?? []) {
|
|
241
|
+
references.push(...referencesFromTool(tool, projectId));
|
|
242
|
+
}
|
|
243
|
+
for (const path of message.referencedArtifacts ?? []) {
|
|
244
|
+
references.push(reference("artifact", path, projectId));
|
|
245
|
+
}
|
|
246
|
+
return references;
|
|
247
|
+
}
|
|
248
|
+
function referencesFromTool(tool, projectId) {
|
|
249
|
+
if (!tool.success) return [];
|
|
250
|
+
const references = [];
|
|
251
|
+
for (const media of [...tool.images ?? [], ...tool.audios ?? [], ...tool.videos ?? []]) {
|
|
252
|
+
references.push(reference("artifact", media.path, projectId));
|
|
253
|
+
}
|
|
254
|
+
const kind = classifyTool(tool.name);
|
|
255
|
+
if (!kind) return references;
|
|
256
|
+
const paths = tool.paths && tool.paths.length > 0 ? tool.paths : tool.path ? [tool.path] : [];
|
|
257
|
+
for (const path of paths) references.push(reference(kind, path, projectId));
|
|
258
|
+
return references;
|
|
259
|
+
}
|
|
260
|
+
function classifyTool(name) {
|
|
261
|
+
const normalized = name.replaceAll("-", "_").toLowerCase();
|
|
262
|
+
if (["read_artifact", "write_artifact"].includes(normalized)) return "artifact";
|
|
263
|
+
if (["read_document", "write_document"].includes(normalized)) return "document";
|
|
264
|
+
if ([
|
|
265
|
+
"readfile",
|
|
266
|
+
"read_file",
|
|
267
|
+
"read_files",
|
|
268
|
+
"writefile",
|
|
269
|
+
"write_file",
|
|
270
|
+
"replace_in_file",
|
|
271
|
+
"replace_lines",
|
|
272
|
+
"insert_at_marker",
|
|
273
|
+
"apply_patch"
|
|
274
|
+
].includes(normalized)) {
|
|
275
|
+
return "workspace";
|
|
276
|
+
}
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
function reference(kind, path, projectId) {
|
|
280
|
+
return {
|
|
281
|
+
key: `${projectId}:${kind}:${normalizeLookup(path)}`,
|
|
282
|
+
kind,
|
|
283
|
+
path,
|
|
284
|
+
projectId
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
function normalizeCliOpenLookup(value) {
|
|
288
|
+
return normalizeLookup(value);
|
|
289
|
+
}
|
|
290
|
+
function cliOpenBasename(path) {
|
|
291
|
+
return basename2(path);
|
|
292
|
+
}
|
|
293
|
+
function normalizeLookup(value) {
|
|
294
|
+
return value.trim().replaceAll("\\", "/").toLowerCase();
|
|
295
|
+
}
|
|
296
|
+
function basename2(path) {
|
|
297
|
+
const normalized = path.replaceAll("\\", "/");
|
|
298
|
+
return normalized.slice(normalized.lastIndexOf("/") + 1);
|
|
299
|
+
}
|
|
300
|
+
|
|
143
301
|
// src/tui/commands.ts
|
|
144
302
|
var SLASH_COMMAND_WORDWHEEL_SIZE = 4;
|
|
145
303
|
var SLASH_COMMANDS = [
|
|
@@ -148,9 +306,12 @@ var SLASH_COMMANDS = [
|
|
|
148
306
|
{ name: "gezel", description: "switch active gezel" },
|
|
149
307
|
{ name: "allow", description: "allow a project permission" },
|
|
150
308
|
{ name: "disallow", description: "disallow a project permission" },
|
|
309
|
+
{ name: "show", description: "show optional chat details" },
|
|
310
|
+
{ name: "hide", description: "hide optional chat details" },
|
|
151
311
|
{ name: "mode", description: "set AI activity: read-only through full play" },
|
|
152
312
|
{ name: "model", description: "switch engine and model" },
|
|
153
313
|
{ name: "thread", description: "switch the active chat thread" },
|
|
314
|
+
{ name: "open", description: "open a project folder or recent chat file" },
|
|
154
315
|
{ name: "task", description: "list and manage project tasks" },
|
|
155
316
|
{ name: "do", description: "do a task from a craftbook" },
|
|
156
317
|
{ name: "continue", description: "process due and active project tasks" },
|
|
@@ -174,6 +335,18 @@ var NIGHT_SHIFT_SUBCOMMANDS = [
|
|
|
174
335
|
var MODEL_SUBCOMMANDS = [
|
|
175
336
|
{ name: "download", description: "choose and download a new on-device model" }
|
|
176
337
|
];
|
|
338
|
+
var CHAT_DETAIL_TARGETS = [
|
|
339
|
+
{
|
|
340
|
+
name: "thinking",
|
|
341
|
+
showDescription: "show model thinking inline as it streams",
|
|
342
|
+
hideDescription: "hide model thinking and keep only the activity count"
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
name: "writes",
|
|
346
|
+
showDescription: "show file, artifact, and note content as it streams",
|
|
347
|
+
hideDescription: "hide streamed write content and keep compact tool activity"
|
|
348
|
+
}
|
|
349
|
+
];
|
|
177
350
|
var PROJECT_PERMISSIONS = [
|
|
178
351
|
{
|
|
179
352
|
name: "edits",
|
|
@@ -198,7 +371,35 @@ function parseProjectPermissionName(input) {
|
|
|
198
371
|
const normalized = input.trim().toLowerCase();
|
|
199
372
|
return PROJECT_PERMISSIONS.find((permission) => permission.name === normalized)?.name;
|
|
200
373
|
}
|
|
201
|
-
function suggestSlashWordwheel(input, craftbooks) {
|
|
374
|
+
function suggestSlashWordwheel(input, craftbooks, recentReferences = []) {
|
|
375
|
+
const openMatch = input.match(/^\/open\s+(.*)$/i);
|
|
376
|
+
if (openMatch) {
|
|
377
|
+
const query = normalizeCliOpenLookup(openMatch[1] ?? "");
|
|
378
|
+
const matches = (candidate) => !query || normalizeCliOpenLookup(candidate).includes(query);
|
|
379
|
+
const folders = ["workspace", "artifacts"].filter(matches).map((folder) => ({
|
|
380
|
+
key: `open:folder:${folder}`,
|
|
381
|
+
label: `/open ${folder}`,
|
|
382
|
+
description: `open the project ${folder} folder`,
|
|
383
|
+
submit: `/open ${folder}`,
|
|
384
|
+
completion: `/open ${folder}`
|
|
385
|
+
}));
|
|
386
|
+
const seen = /* @__PURE__ */ new Set();
|
|
387
|
+
const files = [];
|
|
388
|
+
for (const reference2 of recentReferences) {
|
|
389
|
+
if (seen.has(reference2.key)) continue;
|
|
390
|
+
seen.add(reference2.key);
|
|
391
|
+
if (!matches(reference2.path) && !matches(cliOpenBasename(reference2.path))) continue;
|
|
392
|
+
files.push({
|
|
393
|
+
key: `open:reference:${reference2.key}`,
|
|
394
|
+
label: `/open ${reference2.path}`,
|
|
395
|
+
description: `open recent ${reference2.kind}`,
|
|
396
|
+
submit: `/open ${reference2.path}`,
|
|
397
|
+
completion: `/open ${reference2.path}`
|
|
398
|
+
});
|
|
399
|
+
if (files.length >= 8) break;
|
|
400
|
+
}
|
|
401
|
+
return [...folders, ...files];
|
|
402
|
+
}
|
|
202
403
|
const modelMatch = input.match(/^\/model\s+(.*)$/i);
|
|
203
404
|
if (modelMatch) {
|
|
204
405
|
const query = (modelMatch[1] ?? "").trim().toLowerCase();
|
|
@@ -224,6 +425,18 @@ function suggestSlashWordwheel(input, craftbooks) {
|
|
|
224
425
|
})
|
|
225
426
|
);
|
|
226
427
|
}
|
|
428
|
+
const detailMatch = input.match(/^\/(show|hide)\s+(.*)$/i);
|
|
429
|
+
if (detailMatch) {
|
|
430
|
+
const command = (detailMatch[1] ?? "").toLowerCase();
|
|
431
|
+
const query = (detailMatch[2] ?? "").trim().toLowerCase();
|
|
432
|
+
return CHAT_DETAIL_TARGETS.filter((target) => target.name.startsWith(query)).map((target) => ({
|
|
433
|
+
key: `${command}:${target.name}`,
|
|
434
|
+
label: `/${command} ${target.name}`,
|
|
435
|
+
description: command === "show" ? target.showDescription : target.hideDescription,
|
|
436
|
+
submit: `/${command} ${target.name}`,
|
|
437
|
+
completion: `/${command} ${target.name}`
|
|
438
|
+
}));
|
|
439
|
+
}
|
|
227
440
|
const modeMatch = input.match(/^\/mode\s+(.*)$/i);
|
|
228
441
|
if (modeMatch) {
|
|
229
442
|
const query = (modeMatch[1] ?? "").trim().toLowerCase();
|
|
@@ -306,26 +519,157 @@ function parseInput(raw, cliMode) {
|
|
|
306
519
|
import { GEZEL_VERSION } from "@bendyline/gezel";
|
|
307
520
|
import { Box, Text } from "ink";
|
|
308
521
|
|
|
522
|
+
// src/tui/write-stream.ts
|
|
523
|
+
var WRITE_PAYLOAD_FIELDS = {
|
|
524
|
+
save_memory: "text",
|
|
525
|
+
write_file: "content",
|
|
526
|
+
append_to_file: "content",
|
|
527
|
+
replace_in_file: "replace",
|
|
528
|
+
replace_lines: "content",
|
|
529
|
+
apply_patch: "diff",
|
|
530
|
+
insert_at_marker: "content",
|
|
531
|
+
write_artifact: "content",
|
|
532
|
+
write_document: "content",
|
|
533
|
+
write_task_note: "text"
|
|
534
|
+
};
|
|
535
|
+
function isStreamedWriteTool(name) {
|
|
536
|
+
return writePayloadField(name) !== void 0;
|
|
537
|
+
}
|
|
538
|
+
function createWriteStreamState(toolName) {
|
|
539
|
+
return {
|
|
540
|
+
toolName,
|
|
541
|
+
phase: "seeking",
|
|
542
|
+
carry: "",
|
|
543
|
+
escaped: false,
|
|
544
|
+
unicodeEscape: null
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
function appendWriteArgumentChunk(state, chunk) {
|
|
548
|
+
if (state.phase === "done" || chunk.length === 0) return { state, text: "" };
|
|
549
|
+
let next = { ...state };
|
|
550
|
+
let input = chunk;
|
|
551
|
+
if (next.phase === "seeking") {
|
|
552
|
+
const field = writePayloadField(next.toolName);
|
|
553
|
+
if (!field) return { state: { ...next, phase: "done", carry: "" }, text: "" };
|
|
554
|
+
const combined = next.carry + chunk;
|
|
555
|
+
const match = payloadStartPattern(field).exec(combined);
|
|
556
|
+
if (!match || match.index === void 0) {
|
|
557
|
+
const carryChars = Math.max(64, field.length + 16);
|
|
558
|
+
return {
|
|
559
|
+
state: { ...next, carry: combined.slice(-carryChars) },
|
|
560
|
+
text: ""
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
input = combined.slice(match.index + match[0].length);
|
|
564
|
+
next = { ...next, phase: "reading", carry: "" };
|
|
565
|
+
}
|
|
566
|
+
let text = "";
|
|
567
|
+
for (const char of input) {
|
|
568
|
+
if (next.unicodeEscape !== null) {
|
|
569
|
+
const unicodeEscape = next.unicodeEscape + char;
|
|
570
|
+
if (unicodeEscape.length < 4) {
|
|
571
|
+
next = { ...next, unicodeEscape };
|
|
572
|
+
continue;
|
|
573
|
+
}
|
|
574
|
+
const code = Number.parseInt(unicodeEscape, 16);
|
|
575
|
+
text += Number.isNaN(code) ? `\\u${unicodeEscape}` : String.fromCharCode(code);
|
|
576
|
+
next = { ...next, unicodeEscape: null, escaped: false };
|
|
577
|
+
continue;
|
|
578
|
+
}
|
|
579
|
+
if (next.escaped) {
|
|
580
|
+
if (char === "u") {
|
|
581
|
+
next = { ...next, unicodeEscape: "" };
|
|
582
|
+
continue;
|
|
583
|
+
}
|
|
584
|
+
text += decodeEscape(char);
|
|
585
|
+
next = { ...next, escaped: false };
|
|
586
|
+
continue;
|
|
587
|
+
}
|
|
588
|
+
if (char === "\\") {
|
|
589
|
+
next = { ...next, escaped: true };
|
|
590
|
+
continue;
|
|
591
|
+
}
|
|
592
|
+
if (char === '"') {
|
|
593
|
+
next = { ...next, phase: "done", carry: "" };
|
|
594
|
+
break;
|
|
595
|
+
}
|
|
596
|
+
text += char;
|
|
597
|
+
}
|
|
598
|
+
return { state: next, text };
|
|
599
|
+
}
|
|
600
|
+
function writePayloadField(name) {
|
|
601
|
+
if (!name) return void 0;
|
|
602
|
+
const normalized = normalizeToolName(name);
|
|
603
|
+
return WRITE_PAYLOAD_FIELDS[normalized];
|
|
604
|
+
}
|
|
605
|
+
function normalizeToolName(name) {
|
|
606
|
+
return name.trim().replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/[\s-]+/g, "_").toLowerCase();
|
|
607
|
+
}
|
|
608
|
+
function payloadStartPattern(field) {
|
|
609
|
+
return new RegExp(`"${field.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}"\\s*:\\s*"`);
|
|
610
|
+
}
|
|
611
|
+
function decodeEscape(char) {
|
|
612
|
+
switch (char) {
|
|
613
|
+
case "b":
|
|
614
|
+
return "\b";
|
|
615
|
+
case "f":
|
|
616
|
+
return "\f";
|
|
617
|
+
case "n":
|
|
618
|
+
return "\n";
|
|
619
|
+
case "r":
|
|
620
|
+
return "\r";
|
|
621
|
+
case "t":
|
|
622
|
+
return " ";
|
|
623
|
+
default:
|
|
624
|
+
return char;
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
|
|
309
628
|
// src/tui/feed.ts
|
|
310
629
|
var MAX_ROWS = 200;
|
|
630
|
+
var MAX_FEED_ROW_CHARS = 8e3;
|
|
631
|
+
function capFeedText(text) {
|
|
632
|
+
return text.length > MAX_FEED_ROW_CHARS ? text.slice(0, MAX_FEED_ROW_CHARS + 1) : text;
|
|
633
|
+
}
|
|
634
|
+
function appendFeedText(current, chunk) {
|
|
635
|
+
if (current.length > MAX_FEED_ROW_CHARS || chunk.length === 0) return current;
|
|
636
|
+
const remaining = MAX_FEED_ROW_CHARS + 1 - current.length;
|
|
637
|
+
return current + chunk.slice(0, remaining);
|
|
638
|
+
}
|
|
311
639
|
var counter = 0;
|
|
312
640
|
function nextKey() {
|
|
313
641
|
counter += 1;
|
|
314
642
|
return `r${counter}`;
|
|
315
643
|
}
|
|
316
|
-
function reduceFeed(rows, env) {
|
|
644
|
+
function reduceFeed(rows, env, opts = {}) {
|
|
317
645
|
const { sessionId, gezelId, event } = env;
|
|
318
646
|
const cap = (next) => next.length > MAX_ROWS ? next.slice(next.length - MAX_ROWS) : next;
|
|
319
647
|
switch (event.type) {
|
|
648
|
+
case "user_message_pending": {
|
|
649
|
+
const key = `startup-${sessionId}`;
|
|
650
|
+
const pending = {
|
|
651
|
+
key,
|
|
652
|
+
sessionId,
|
|
653
|
+
gezelId,
|
|
654
|
+
kind: "pending",
|
|
655
|
+
text: capFeedText(event.preview),
|
|
656
|
+
open: false
|
|
657
|
+
};
|
|
658
|
+
const idx = rows.findIndex((row) => row.key === key);
|
|
659
|
+
if (idx === -1) return cap([...rows, pending]);
|
|
660
|
+
const next = rows.slice();
|
|
661
|
+
next[idx] = pending;
|
|
662
|
+
return next;
|
|
663
|
+
}
|
|
320
664
|
case "user_message":
|
|
321
665
|
return cap([
|
|
322
|
-
...rows,
|
|
666
|
+
...withoutStartupPending(rows, sessionId),
|
|
323
667
|
{
|
|
324
668
|
key: nextKey(),
|
|
325
669
|
sessionId,
|
|
326
670
|
gezelId,
|
|
327
671
|
kind: "user",
|
|
328
|
-
text: event.message.content,
|
|
672
|
+
text: capFeedText(event.message.content),
|
|
329
673
|
open: false
|
|
330
674
|
}
|
|
331
675
|
]);
|
|
@@ -336,7 +680,7 @@ function reduceFeed(rows, env) {
|
|
|
336
680
|
sessionId,
|
|
337
681
|
gezelId,
|
|
338
682
|
kind: "pending",
|
|
339
|
-
text: event.preview,
|
|
683
|
+
text: capFeedText(event.preview),
|
|
340
684
|
open: false
|
|
341
685
|
};
|
|
342
686
|
const idx = rows.findIndex((row) => row.key === key);
|
|
@@ -347,43 +691,72 @@ function reduceFeed(rows, env) {
|
|
|
347
691
|
}
|
|
348
692
|
case "queue_removed":
|
|
349
693
|
return rows.filter((row) => row.key !== `queue-${event.queueId}`);
|
|
694
|
+
case "reasoning_delta": {
|
|
695
|
+
const settled = closeWriteRows(rows, sessionId);
|
|
696
|
+
if (opts.showThinking === false) return settled;
|
|
697
|
+
const idx = findOpenRow(settled, sessionId, "thinking");
|
|
698
|
+
const open = idx === -1 ? void 0 : settled[idx];
|
|
699
|
+
if (!open) {
|
|
700
|
+
return cap([
|
|
701
|
+
...settled,
|
|
702
|
+
{
|
|
703
|
+
key: nextKey(),
|
|
704
|
+
sessionId,
|
|
705
|
+
gezelId,
|
|
706
|
+
kind: "thinking",
|
|
707
|
+
text: capFeedText(event.content),
|
|
708
|
+
open: true
|
|
709
|
+
}
|
|
710
|
+
]);
|
|
711
|
+
}
|
|
712
|
+
const next = settled.slice();
|
|
713
|
+
const text = appendFeedText(open.text, event.content);
|
|
714
|
+
if (text === open.text) return settled;
|
|
715
|
+
next[idx] = { ...open, text };
|
|
716
|
+
return next;
|
|
717
|
+
}
|
|
350
718
|
case "delta": {
|
|
351
|
-
const
|
|
352
|
-
const
|
|
719
|
+
const settled = closeWriteRows(closeOpenRows(rows, sessionId, "thinking"), sessionId);
|
|
720
|
+
const idx = findOpenAssistant(settled, sessionId);
|
|
721
|
+
const open = idx === -1 ? void 0 : settled[idx];
|
|
353
722
|
if (!open) {
|
|
354
723
|
return cap([
|
|
355
|
-
...
|
|
724
|
+
...settled,
|
|
356
725
|
{
|
|
357
726
|
key: nextKey(),
|
|
358
727
|
sessionId,
|
|
359
728
|
gezelId,
|
|
360
729
|
kind: "assistant",
|
|
361
|
-
text: event.content,
|
|
730
|
+
text: capFeedText(event.content),
|
|
362
731
|
open: true
|
|
363
732
|
}
|
|
364
733
|
]);
|
|
365
734
|
}
|
|
366
|
-
const next =
|
|
367
|
-
|
|
735
|
+
const next = settled.slice();
|
|
736
|
+
const text = appendFeedText(open.text, event.content);
|
|
737
|
+
if (text === open.text) return settled;
|
|
738
|
+
next[idx] = { ...open, text };
|
|
368
739
|
return next;
|
|
369
740
|
}
|
|
370
741
|
case "complete": {
|
|
371
|
-
const
|
|
372
|
-
const
|
|
373
|
-
const
|
|
742
|
+
const settled = closeWriteRows(closeOpenRows(rows, sessionId, "thinking"), sessionId);
|
|
743
|
+
const idx = findOpenAssistant(settled, sessionId);
|
|
744
|
+
const open = idx === -1 ? void 0 : settled[idx];
|
|
745
|
+
const text = capFeedText(event.message.content);
|
|
374
746
|
if (!open) {
|
|
375
747
|
return cap([
|
|
376
|
-
...
|
|
748
|
+
...settled,
|
|
377
749
|
{ key: nextKey(), sessionId, gezelId, kind: "assistant", text, open: false }
|
|
378
750
|
]);
|
|
379
751
|
}
|
|
380
|
-
const next =
|
|
752
|
+
const next = settled.slice();
|
|
381
753
|
next[idx] = { ...open, text: text || open.text, open: false };
|
|
382
754
|
return next;
|
|
383
755
|
}
|
|
384
|
-
case "tool":
|
|
756
|
+
case "tool": {
|
|
757
|
+
const settled = closeWriteRows(closeOpenRows(rows, sessionId, "thinking"), sessionId);
|
|
385
758
|
return cap([
|
|
386
|
-
...
|
|
759
|
+
...settled,
|
|
387
760
|
{
|
|
388
761
|
key: nextKey(),
|
|
389
762
|
sessionId,
|
|
@@ -393,6 +766,14 @@ function reduceFeed(rows, env) {
|
|
|
393
766
|
open: false
|
|
394
767
|
}
|
|
395
768
|
]);
|
|
769
|
+
}
|
|
770
|
+
case "tool_args_delta": {
|
|
771
|
+
const settled = closeOpenRows(rows, sessionId, "thinking");
|
|
772
|
+
if (opts.showWrites !== true) {
|
|
773
|
+
return closeWriteRows(settled, sessionId);
|
|
774
|
+
}
|
|
775
|
+
return appendWriteStream(settled, sessionId, gezelId, event.name, event.content);
|
|
776
|
+
}
|
|
396
777
|
case "awaiting_gezel":
|
|
397
778
|
return cap([
|
|
398
779
|
...rows,
|
|
@@ -413,7 +794,7 @@ function reduceFeed(rows, env) {
|
|
|
413
794
|
sessionId: "local",
|
|
414
795
|
gezelId: "",
|
|
415
796
|
kind: "note",
|
|
416
|
-
text: `task \xB7 ${event.summary}
|
|
797
|
+
text: capFeedText(`task \xB7 ${event.summary}`),
|
|
417
798
|
open: false,
|
|
418
799
|
taskEvent: {
|
|
419
800
|
kind: event.kind,
|
|
@@ -421,22 +802,46 @@ function reduceFeed(rows, env) {
|
|
|
421
802
|
}
|
|
422
803
|
}
|
|
423
804
|
]);
|
|
424
|
-
case "error":
|
|
805
|
+
case "error": {
|
|
806
|
+
const settled = withoutStartupPending(
|
|
807
|
+
closeWriteRows(closeOpenRows(rows, sessionId, "thinking"), sessionId),
|
|
808
|
+
sessionId
|
|
809
|
+
);
|
|
425
810
|
return cap([
|
|
426
|
-
...
|
|
427
|
-
{
|
|
811
|
+
...settled,
|
|
812
|
+
{
|
|
813
|
+
key: nextKey(),
|
|
814
|
+
sessionId,
|
|
815
|
+
gezelId,
|
|
816
|
+
kind: "error",
|
|
817
|
+
text: capFeedText(event.error),
|
|
818
|
+
open: false
|
|
819
|
+
}
|
|
428
820
|
]);
|
|
429
|
-
|
|
430
|
-
|
|
821
|
+
}
|
|
822
|
+
case "done": {
|
|
823
|
+
const settled = withoutStartupPending(closeWriteRows(rows, sessionId), sessionId);
|
|
824
|
+
return settled.map((r) => r.sessionId === sessionId && r.open ? { ...r, open: false } : r);
|
|
825
|
+
}
|
|
431
826
|
default:
|
|
432
827
|
return rows;
|
|
433
828
|
}
|
|
434
829
|
}
|
|
435
|
-
function sessionToFeedRows(session) {
|
|
830
|
+
function sessionToFeedRows(session, opts = {}) {
|
|
436
831
|
const rows = [];
|
|
437
832
|
for (const message of session.messages) {
|
|
438
833
|
if (message.hidden) continue;
|
|
439
834
|
if (message.role === "assistant") {
|
|
835
|
+
if (opts.showThinking !== false && message.reasoning?.trim()) {
|
|
836
|
+
rows.push({
|
|
837
|
+
key: nextKey(),
|
|
838
|
+
sessionId: session.id,
|
|
839
|
+
gezelId: message.from?.gezelId ?? session.gezelId,
|
|
840
|
+
kind: "thinking",
|
|
841
|
+
text: capFeedText(message.reasoning),
|
|
842
|
+
open: false
|
|
843
|
+
});
|
|
844
|
+
}
|
|
440
845
|
for (const tool of message.toolCalls ?? []) {
|
|
441
846
|
rows.push({
|
|
442
847
|
key: nextKey(),
|
|
@@ -454,7 +859,7 @@ function sessionToFeedRows(session) {
|
|
|
454
859
|
sessionId: session.id,
|
|
455
860
|
gezelId: message.from?.gezelId ?? session.gezelId,
|
|
456
861
|
kind: message.role === "user" && !message.from ? "user" : message.from ? "assistant" : message.role,
|
|
457
|
-
text: message.content,
|
|
862
|
+
text: capFeedText(message.content),
|
|
458
863
|
open: false
|
|
459
864
|
});
|
|
460
865
|
}
|
|
@@ -464,7 +869,7 @@ function sessionToFeedRows(session) {
|
|
|
464
869
|
sessionId: session.id,
|
|
465
870
|
gezelId: session.gezelId,
|
|
466
871
|
kind: "error",
|
|
467
|
-
text: session.lastTurnError,
|
|
872
|
+
text: capFeedText(session.lastTurnError),
|
|
468
873
|
open: false
|
|
469
874
|
});
|
|
470
875
|
}
|
|
@@ -472,7 +877,8 @@ function sessionToFeedRows(session) {
|
|
|
472
877
|
}
|
|
473
878
|
function reduceTurns(turns, env) {
|
|
474
879
|
const { sessionId, event } = env;
|
|
475
|
-
const
|
|
880
|
+
const prior = turns.get(sessionId);
|
|
881
|
+
const set = (label, outputChars = prior?.outputChars ?? 0, activeToolName = prior?.activeToolName ?? null) => new Map(turns).set(sessionId, { label, outputChars, activeToolName });
|
|
476
882
|
const clear = () => {
|
|
477
883
|
if (!turns.has(sessionId)) return turns;
|
|
478
884
|
const m = new Map(turns);
|
|
@@ -480,20 +886,34 @@ function reduceTurns(turns, env) {
|
|
|
480
886
|
return m;
|
|
481
887
|
};
|
|
482
888
|
switch (event.type) {
|
|
889
|
+
case "user_message_pending":
|
|
890
|
+
return set("preparing chat", 0, null);
|
|
483
891
|
case "user_message":
|
|
484
|
-
return set("thinking\u2026");
|
|
892
|
+
return set("thinking\u2026", 0, null);
|
|
485
893
|
case "queued":
|
|
486
894
|
return set(event.aheadOf > 0 ? `queued \xB7 ${event.aheadOf} ahead` : "queued");
|
|
487
895
|
case "intent":
|
|
488
|
-
return set(event.label);
|
|
896
|
+
return set(event.label, void 0, null);
|
|
489
897
|
case "engine_phase":
|
|
490
|
-
return set(phaseLabel(event));
|
|
898
|
+
return set(phaseLabel(event, prior?.outputChars ?? 0), void 0, null);
|
|
491
899
|
case "delta":
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
return set(
|
|
900
|
+
case "reasoning_delta": {
|
|
901
|
+
const outputChars = (prior?.outputChars ?? 0) + event.content.length;
|
|
902
|
+
return set(generationLabel(outputChars), outputChars, null);
|
|
903
|
+
}
|
|
904
|
+
case "tool_args_delta": {
|
|
905
|
+
const outputChars = (prior?.outputChars ?? 0) + event.content.length;
|
|
906
|
+
const name = event.name.trim() || prior?.activeToolName || null;
|
|
907
|
+
return set(runningToolLabel(name, outputChars), outputChars, name);
|
|
908
|
+
}
|
|
909
|
+
case "tool": {
|
|
910
|
+
const name = event.name.trim() || prior?.activeToolName || null;
|
|
911
|
+
return set(runningToolLabel(name, prior?.outputChars ?? 0), void 0, name);
|
|
912
|
+
}
|
|
913
|
+
case "heartbeat":
|
|
914
|
+
return event.label ? set(heartbeatLabel(event.label), void 0, null) : turns;
|
|
495
915
|
case "awaiting_gezel":
|
|
496
|
-
return set("awaiting gezel");
|
|
916
|
+
return set("awaiting gezel", void 0, null);
|
|
497
917
|
case "error":
|
|
498
918
|
case "done":
|
|
499
919
|
return clear();
|
|
@@ -501,7 +921,11 @@ function reduceTurns(turns, env) {
|
|
|
501
921
|
return turns;
|
|
502
922
|
}
|
|
503
923
|
}
|
|
504
|
-
function
|
|
924
|
+
function withoutStartupPending(rows, sessionId) {
|
|
925
|
+
const key = `startup-${sessionId}`;
|
|
926
|
+
return rows.some((row) => row.key === key) ? rows.filter((row) => row.key !== key) : rows;
|
|
927
|
+
}
|
|
928
|
+
function phaseLabel(event, outputChars) {
|
|
505
929
|
const pct = event.progress !== void 0 ? ` ${Math.round(event.progress * 100)}%` : "";
|
|
506
930
|
switch (event.phase) {
|
|
507
931
|
case "starting":
|
|
@@ -511,15 +935,40 @@ function phaseLabel(event) {
|
|
|
511
935
|
case "prefill":
|
|
512
936
|
return `reading prompt${pct}`;
|
|
513
937
|
case "generating":
|
|
514
|
-
return
|
|
938
|
+
return generationLabel(outputChars);
|
|
515
939
|
default:
|
|
516
940
|
return "ready";
|
|
517
941
|
}
|
|
518
942
|
}
|
|
943
|
+
function generationLabel(outputChars) {
|
|
944
|
+
if (!Number.isFinite(outputChars) || outputChars <= 0) return "generating";
|
|
945
|
+
const tokens = Math.max(1, Math.round(outputChars / 4));
|
|
946
|
+
return `generating \xB7 ~${tokens.toLocaleString("en-US")} ${tokens === 1 ? "token" : "tokens"}`;
|
|
947
|
+
}
|
|
948
|
+
function runningToolLabel(name, outputChars = 0) {
|
|
949
|
+
const base = name ? `running tool \xB7 ${name}` : "running tool";
|
|
950
|
+
if (!isStreamedWriteTool(name) || outputChars <= 0) return base;
|
|
951
|
+
const tokens = Math.max(1, Math.round(outputChars / 4));
|
|
952
|
+
return `${base} \xB7 ~${tokens.toLocaleString("en-US")} ${tokens === 1 ? "token" : "tokens"}`;
|
|
953
|
+
}
|
|
954
|
+
function heartbeatLabel(label) {
|
|
955
|
+
const trimmed = label.trim();
|
|
956
|
+
if (/^(thinking|reasoning|streaming|preparing|working)(?:\b|$)/i.test(trimmed) || /^(running|updating|searching|awaiting|using)(?:\b|$)/i.test(trimmed)) {
|
|
957
|
+
return trimmed;
|
|
958
|
+
}
|
|
959
|
+
return runningToolLabel(trimmed || null);
|
|
960
|
+
}
|
|
519
961
|
function appendNote(rows, text, kind = "note") {
|
|
520
962
|
const next = [
|
|
521
963
|
...rows,
|
|
522
|
-
{
|
|
964
|
+
{
|
|
965
|
+
key: nextKey(),
|
|
966
|
+
sessionId: "local",
|
|
967
|
+
gezelId: "",
|
|
968
|
+
kind,
|
|
969
|
+
text: capFeedText(text),
|
|
970
|
+
open: false
|
|
971
|
+
}
|
|
523
972
|
];
|
|
524
973
|
return next.length > MAX_ROWS ? next.slice(next.length - MAX_ROWS) : next;
|
|
525
974
|
}
|
|
@@ -536,7 +985,7 @@ function finalizeShellRun(rows, runId, message) {
|
|
|
536
985
|
sessionId: `term-${runId}`,
|
|
537
986
|
gezelId: "",
|
|
538
987
|
kind: "shell",
|
|
539
|
-
text: text ? `${text}${footer}` : footer.trimStart(),
|
|
988
|
+
text: capFeedText(text ? `${text}${footer}` : footer.trimStart()),
|
|
540
989
|
open: false
|
|
541
990
|
}
|
|
542
991
|
];
|
|
@@ -545,7 +994,11 @@ function finalizeShellRun(rows, runId, message) {
|
|
|
545
994
|
const row = rows[idx];
|
|
546
995
|
if (!row) return rows;
|
|
547
996
|
const next = rows.slice();
|
|
548
|
-
next[idx] = {
|
|
997
|
+
next[idx] = {
|
|
998
|
+
...row,
|
|
999
|
+
open: false,
|
|
1000
|
+
text: capFeedText(`${row.text.replace(/\s+$/, "")}${footer}`)
|
|
1001
|
+
};
|
|
549
1002
|
return next;
|
|
550
1003
|
}
|
|
551
1004
|
function shellFooter(message) {
|
|
@@ -568,7 +1021,7 @@ function appendShellChunk(rows, runId, chunk) {
|
|
|
568
1021
|
sessionId: `term-${runId}`,
|
|
569
1022
|
gezelId: "",
|
|
570
1023
|
kind: "shell",
|
|
571
|
-
text: chunk,
|
|
1024
|
+
text: capFeedText(chunk),
|
|
572
1025
|
open: true
|
|
573
1026
|
}
|
|
574
1027
|
];
|
|
@@ -576,17 +1029,84 @@ function appendShellChunk(rows, runId, chunk) {
|
|
|
576
1029
|
}
|
|
577
1030
|
const row = rows[idx];
|
|
578
1031
|
if (!row) return rows;
|
|
1032
|
+
const text = appendFeedText(row.text, chunk);
|
|
1033
|
+
if (text === row.text) return rows;
|
|
579
1034
|
const next = rows.slice();
|
|
580
|
-
next[idx] = { ...row, text
|
|
1035
|
+
next[idx] = { ...row, text };
|
|
581
1036
|
return next;
|
|
582
1037
|
}
|
|
583
1038
|
function findOpenAssistant(rows, sessionId) {
|
|
1039
|
+
return findOpenRow(rows, sessionId, "assistant");
|
|
1040
|
+
}
|
|
1041
|
+
function findOpenRow(rows, sessionId, kind) {
|
|
584
1042
|
for (let i = rows.length - 1; i >= 0; i--) {
|
|
585
1043
|
const r = rows[i];
|
|
586
|
-
if (r && r.sessionId === sessionId && r.kind ===
|
|
1044
|
+
if (r && r.sessionId === sessionId && r.kind === kind && r.open) return i;
|
|
587
1045
|
}
|
|
588
1046
|
return -1;
|
|
589
1047
|
}
|
|
1048
|
+
function closeOpenRows(rows, sessionId, kind) {
|
|
1049
|
+
let changed = false;
|
|
1050
|
+
const next = rows.map((row) => {
|
|
1051
|
+
if (row.sessionId !== sessionId || row.kind !== kind || !row.open) return row;
|
|
1052
|
+
changed = true;
|
|
1053
|
+
return { ...row, open: false };
|
|
1054
|
+
});
|
|
1055
|
+
return changed ? next : rows;
|
|
1056
|
+
}
|
|
1057
|
+
function appendWriteStream(rows, sessionId, gezelId, eventToolName, chunk) {
|
|
1058
|
+
let idx = findOpenRow(rows, sessionId, "write");
|
|
1059
|
+
let open = idx === -1 ? void 0 : rows[idx];
|
|
1060
|
+
const toolName = eventToolName.trim() || open?.writeStream?.toolName || "";
|
|
1061
|
+
if (!isStreamedWriteTool(toolName)) return closeWriteRows(rows, sessionId);
|
|
1062
|
+
let currentRows = rows;
|
|
1063
|
+
if (open?.writeStream?.toolName !== toolName) {
|
|
1064
|
+
currentRows = closeWriteRows(rows, sessionId);
|
|
1065
|
+
idx = -1;
|
|
1066
|
+
open = void 0;
|
|
1067
|
+
}
|
|
1068
|
+
const decoded = appendWriteArgumentChunk(
|
|
1069
|
+
open?.writeStream ?? createWriteStreamState(toolName),
|
|
1070
|
+
chunk
|
|
1071
|
+
);
|
|
1072
|
+
if (!open) {
|
|
1073
|
+
const next2 = [
|
|
1074
|
+
...currentRows,
|
|
1075
|
+
{
|
|
1076
|
+
key: nextKey(),
|
|
1077
|
+
sessionId,
|
|
1078
|
+
gezelId,
|
|
1079
|
+
kind: "write",
|
|
1080
|
+
text: capFeedText(decoded.text),
|
|
1081
|
+
open: true,
|
|
1082
|
+
writeStream: decoded.state
|
|
1083
|
+
}
|
|
1084
|
+
];
|
|
1085
|
+
return next2.length > MAX_ROWS ? next2.slice(next2.length - MAX_ROWS) : next2;
|
|
1086
|
+
}
|
|
1087
|
+
const next = currentRows.slice();
|
|
1088
|
+
next[idx] = {
|
|
1089
|
+
...open,
|
|
1090
|
+
text: appendFeedText(open.text, decoded.text),
|
|
1091
|
+
writeStream: decoded.state
|
|
1092
|
+
};
|
|
1093
|
+
return next;
|
|
1094
|
+
}
|
|
1095
|
+
function closeWriteRows(rows, sessionId) {
|
|
1096
|
+
let changed = false;
|
|
1097
|
+
const next = [];
|
|
1098
|
+
for (const row of rows) {
|
|
1099
|
+
if (row.sessionId !== sessionId || row.kind !== "write" || !row.writeStream) {
|
|
1100
|
+
next.push(row);
|
|
1101
|
+
continue;
|
|
1102
|
+
}
|
|
1103
|
+
changed = true;
|
|
1104
|
+
if (!row.text) continue;
|
|
1105
|
+
const { writeStream: _writeStream, ...settled } = row;
|
|
1106
|
+
next.push({ ...settled, open: false });
|
|
1107
|
+
}
|
|
1108
|
+
return changed ? next : rows;
|
|
1109
|
+
}
|
|
590
1110
|
function toolLabel(event) {
|
|
591
1111
|
return toolRowText(event);
|
|
592
1112
|
}
|
|
@@ -597,7 +1117,7 @@ function toolRowText(call) {
|
|
|
597
1117
|
const flat = detail?.replace(/\s+/g, " ").trim();
|
|
598
1118
|
const clipped = flat && flat.length > MAX_TOOL_DETAIL_CHARS ? `${flat.slice(0, MAX_TOOL_DETAIL_CHARS - 1)}\u2026` : flat;
|
|
599
1119
|
const failed = call.success === false ? ` \xB7 failed${call.errorMessage ? `: ${call.errorMessage}` : ""}` : "";
|
|
600
|
-
return `\u{1F527} ${name}${clipped ? ` \xB7 ${clipped}` : ""}${failed}
|
|
1120
|
+
return capFeedText(`\u{1F527} ${name}${clipped ? ` \xB7 ${clipped}` : ""}${failed}`);
|
|
601
1121
|
}
|
|
602
1122
|
function gezelLabel(gezelId, gezels, boring) {
|
|
603
1123
|
const g = gezels.find((x) => x.id === gezelId);
|
|
@@ -735,6 +1255,8 @@ var KIND_COLOR = {
|
|
|
735
1255
|
user: "white",
|
|
736
1256
|
pending: "yellow",
|
|
737
1257
|
assistant: "cyan",
|
|
1258
|
+
thinking: "magenta",
|
|
1259
|
+
write: "yellow",
|
|
738
1260
|
tool: "yellow",
|
|
739
1261
|
note: "magenta",
|
|
740
1262
|
error: "red",
|
|
@@ -742,7 +1264,8 @@ var KIND_COLOR = {
|
|
|
742
1264
|
};
|
|
743
1265
|
function ChatFeed(props) {
|
|
744
1266
|
const { rows, gezels, boring, focusedSessionId, visible = 16 } = props;
|
|
745
|
-
const
|
|
1267
|
+
const visibleRows = rows.filter((row) => row.kind !== "write" || row.text.length > 0);
|
|
1268
|
+
const shown = visibleRows.slice(Math.max(0, visibleRows.length - visible));
|
|
746
1269
|
return /* @__PURE__ */ jsx(Box, { flexDirection: "column", flexGrow: 1, marginBottom: 1, children: shown.length === 0 ? /* @__PURE__ */ jsxs(Box, { flexDirection: "row", children: [
|
|
747
1270
|
/* @__PURE__ */ jsx(Text, { color: "yellow", children: TABLE_LOGO }),
|
|
748
1271
|
/* @__PURE__ */ jsxs(Box, { flexDirection: "column", marginLeft: 3, children: [
|
|
@@ -757,7 +1280,7 @@ function ChatFeed(props) {
|
|
|
757
1280
|
if (row.kind === "shell" && row.sessionId.startsWith("term-")) {
|
|
758
1281
|
return /* @__PURE__ */ jsx(Text, { wrap: "wrap", children: clip(row.text) }, row.key);
|
|
759
1282
|
}
|
|
760
|
-
const who = row.kind === "user" ? "you" : row.kind === "pending" ? "pending" : row.gezelId ? gezelLabel(row.gezelId, gezels, boring) : row.kind === "tool" ? "tool" : row.kind === "shell" ? "shell" : row.kind === "error" ? "error" : "system";
|
|
1283
|
+
const who = row.kind === "user" ? "you" : row.kind === "pending" ? "pending" : row.kind === "thinking" ? "thinking" : row.kind === "write" ? "writing" : row.gezelId ? gezelLabel(row.gezelId, gezels, boring) : row.kind === "tool" ? "tool" : row.kind === "shell" ? "shell" : row.kind === "error" ? "error" : "system";
|
|
761
1284
|
const isFocused = focusedSessionId && row.sessionId === focusedSessionId;
|
|
762
1285
|
return /* @__PURE__ */ jsxs(Box, { flexDirection: "row", children: [
|
|
763
1286
|
/* @__PURE__ */ jsx(Text, { dimColor: !isFocused, color: isFocused ? "green" : void 0, children: isFocused ? "\u258E" : " " }),
|
|
@@ -766,9 +1289,16 @@ function ChatFeed(props) {
|
|
|
766
1289
|
who,
|
|
767
1290
|
": "
|
|
768
1291
|
] }),
|
|
769
|
-
/* @__PURE__ */ jsx(
|
|
770
|
-
|
|
771
|
-
|
|
1292
|
+
/* @__PURE__ */ jsx(
|
|
1293
|
+
Text,
|
|
1294
|
+
{
|
|
1295
|
+
color: KIND_COLOR[row.kind],
|
|
1296
|
+
dimColor: row.kind === "pending" || row.kind === "thinking" || row.kind === "write",
|
|
1297
|
+
children: clip(
|
|
1298
|
+
row.taskEvent ? taskEventText(row, gezels, boring) : row.kind === "assistant" ? humanizeToolMarkup(row.text) : row.text
|
|
1299
|
+
)
|
|
1300
|
+
}
|
|
1301
|
+
)
|
|
772
1302
|
] })
|
|
773
1303
|
] }, row.key);
|
|
774
1304
|
}) });
|
|
@@ -793,20 +1323,19 @@ function taskEventText(row, gezels, boring) {
|
|
|
793
1323
|
return row.text;
|
|
794
1324
|
}
|
|
795
1325
|
}
|
|
796
|
-
var MAX_CHARS = 8e3;
|
|
797
1326
|
function clip(text) {
|
|
798
1327
|
const t = text.replace(/\s+$/, "");
|
|
799
|
-
return t.length >
|
|
1328
|
+
return t.length > MAX_FEED_ROW_CHARS ? `${t.slice(0, MAX_FEED_ROW_CHARS)}
|
|
800
1329
|
\u2026 (truncated)` : t;
|
|
801
1330
|
}
|
|
802
1331
|
|
|
803
1332
|
// src/tui/components/Picker.tsx
|
|
804
1333
|
import { Box as Box2, Text as Text2, useInput } from "ink";
|
|
805
|
-
import { useState } from "react";
|
|
1334
|
+
import { useState as useState2 } from "react";
|
|
806
1335
|
import { Fragment, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
807
1336
|
function Picker(props) {
|
|
808
1337
|
const { title, items, initialValue, windowSize, onSelect, onCancel } = props;
|
|
809
|
-
const [index, setIndex] =
|
|
1338
|
+
const [index, setIndex] = useState2(() => {
|
|
810
1339
|
const initialIndex = initialValue ? items.findIndex((item) => item.value === initialValue) : -1;
|
|
811
1340
|
return Math.max(initialIndex, 0);
|
|
812
1341
|
});
|
|
@@ -866,7 +1395,7 @@ function Picker(props) {
|
|
|
866
1395
|
// src/tui/components/PromptLine.tsx
|
|
867
1396
|
import { Box as Box4, Text as Text4, useInput as useInput2 } from "ink";
|
|
868
1397
|
import TextInput from "ink-text-input";
|
|
869
|
-
import { useEffect, useState as
|
|
1398
|
+
import { useEffect as useEffect2, useState as useState3 } from "react";
|
|
870
1399
|
|
|
871
1400
|
// src/tui/components/EnginePill.tsx
|
|
872
1401
|
import { Box as Box3, Text as Text3 } from "ink";
|
|
@@ -916,14 +1445,15 @@ function PromptLine(props) {
|
|
|
916
1445
|
active,
|
|
917
1446
|
history,
|
|
918
1447
|
craftbooks,
|
|
1448
|
+
recentOpenReferences,
|
|
919
1449
|
pendingPrompt,
|
|
920
1450
|
pendingMode,
|
|
921
1451
|
onChange,
|
|
922
1452
|
onSubmit
|
|
923
1453
|
} = props;
|
|
924
|
-
const [cursor, setCursor] =
|
|
925
|
-
const [suggestionIndex, setSuggestionIndex] =
|
|
926
|
-
const suggestions = active && !pendingPrompt ? suggestSlashWordwheel(value, craftbooks) : [];
|
|
1454
|
+
const [cursor, setCursor] = useState3(history.length);
|
|
1455
|
+
const [suggestionIndex, setSuggestionIndex] = useState3(0);
|
|
1456
|
+
const suggestions = active && !pendingPrompt ? suggestSlashWordwheel(value, craftbooks, recentOpenReferences) : [];
|
|
927
1457
|
const activeSuggestionIndex = Math.min(suggestionIndex, Math.max(0, suggestions.length - 1));
|
|
928
1458
|
const suggestionWindowStart = Math.min(
|
|
929
1459
|
Math.max(0, activeSuggestionIndex - SLASH_COMMAND_WORDWHEEL_SIZE + 1),
|
|
@@ -941,7 +1471,7 @@ function PromptLine(props) {
|
|
|
941
1471
|
const selected = suggestions[activeSuggestionIndex];
|
|
942
1472
|
onSubmit(selected ? selected.submit : submittedValue);
|
|
943
1473
|
};
|
|
944
|
-
|
|
1474
|
+
useEffect2(() => {
|
|
945
1475
|
setCursor(history.length);
|
|
946
1476
|
}, [history.length]);
|
|
947
1477
|
useInput2(
|
|
@@ -1042,19 +1572,94 @@ function compactThreadTitle(title) {
|
|
|
1042
1572
|
// src/tui/components/QuestionPrompt.tsx
|
|
1043
1573
|
import { Box as Box5, Text as Text5, useInput as useInput3 } from "ink";
|
|
1044
1574
|
import TextInput2 from "ink-text-input";
|
|
1045
|
-
import { useState as
|
|
1046
|
-
|
|
1047
|
-
|
|
1575
|
+
import { useState as useState4 } from "react";
|
|
1576
|
+
|
|
1577
|
+
// src/tui/question-presentation.ts
|
|
1578
|
+
var TUI_APPROVAL_INTENTS = /* @__PURE__ */ new Set([
|
|
1579
|
+
"npm-install-approval",
|
|
1580
|
+
"command-approval",
|
|
1581
|
+
"tool-permission",
|
|
1582
|
+
"toolset-install-approval",
|
|
1583
|
+
"image-generation-approval",
|
|
1584
|
+
"video-generation-approval",
|
|
1585
|
+
"schedule-approval"
|
|
1586
|
+
]);
|
|
1587
|
+
function canAnswerQuestionInTui(question) {
|
|
1588
|
+
return !question.intent || TUI_APPROVAL_INTENTS.has(question.intent.kind);
|
|
1589
|
+
}
|
|
1590
|
+
function choicesForQuestion(question) {
|
|
1591
|
+
if (question.choices && question.choices.length > 0) return question.choices;
|
|
1592
|
+
switch (question.intent?.kind) {
|
|
1593
|
+
case "command-approval":
|
|
1594
|
+
return ["Approve", "Decline"];
|
|
1595
|
+
case "tool-permission":
|
|
1596
|
+
return ["Allow", "Deny"];
|
|
1597
|
+
case "toolset-install-approval":
|
|
1598
|
+
return ["Install", "Not now"];
|
|
1599
|
+
case "image-generation-approval":
|
|
1600
|
+
case "video-generation-approval":
|
|
1601
|
+
return ["Allow once", "Always allow", "Decline"];
|
|
1602
|
+
case "schedule-approval":
|
|
1603
|
+
return ["Enable schedule", "Keep paused"];
|
|
1604
|
+
default:
|
|
1605
|
+
return [];
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
function allowsWriteIn(question) {
|
|
1609
|
+
return question.intent ? false : question.allowWriteIn ?? true;
|
|
1610
|
+
}
|
|
1611
|
+
function questionHeading(question, askerLabel) {
|
|
1612
|
+
switch (question.intent?.kind) {
|
|
1613
|
+
case "npm-install-approval":
|
|
1614
|
+
return "npm package approval";
|
|
1615
|
+
case "command-approval":
|
|
1616
|
+
return "Command approval";
|
|
1617
|
+
case "tool-permission":
|
|
1618
|
+
return "Tool permission";
|
|
1619
|
+
case "toolset-install-approval":
|
|
1620
|
+
return "Toolset install approval";
|
|
1621
|
+
case "image-generation-approval":
|
|
1622
|
+
return "Image generation approval";
|
|
1623
|
+
case "video-generation-approval":
|
|
1624
|
+
return "Video generation approval";
|
|
1625
|
+
case "schedule-approval":
|
|
1626
|
+
return "Schedule approval";
|
|
1627
|
+
default:
|
|
1628
|
+
return `${askerLabel} asks`;
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
function npmApprovalPackages(question) {
|
|
1632
|
+
if (question.intent?.kind !== "npm-install-approval") return [];
|
|
1633
|
+
const intent = question.intent;
|
|
1634
|
+
if (Array.isArray(intent.packages) && intent.packages.length > 0) return intent.packages;
|
|
1635
|
+
if (intent.package && intent.version) {
|
|
1636
|
+
return [{ package: intent.package, version: intent.version }];
|
|
1637
|
+
}
|
|
1638
|
+
return [];
|
|
1639
|
+
}
|
|
1048
1640
|
function questionOptionCount(question) {
|
|
1049
|
-
|
|
1050
|
-
|
|
1641
|
+
if (question.intent?.kind === "npm-install-approval") {
|
|
1642
|
+
return npmApprovalPackages(question).length > 0 ? 3 : 1;
|
|
1643
|
+
}
|
|
1644
|
+
const choices = choicesForQuestion(question).length;
|
|
1645
|
+
const writeIn = allowsWriteIn(question);
|
|
1051
1646
|
const submit = question.multiSelect === true && choices > 0;
|
|
1052
1647
|
return choices + (writeIn ? 1 : 0) + (submit ? 1 : 0);
|
|
1053
1648
|
}
|
|
1649
|
+
|
|
1650
|
+
// src/tui/components/QuestionPrompt.tsx
|
|
1651
|
+
import { Fragment as Fragment3, jsx as jsx4, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
1652
|
+
var QUESTION_OPTION_WINDOW_SIZE = 4;
|
|
1054
1653
|
function QuestionPrompt(props) {
|
|
1654
|
+
if (props.question.intent?.kind === "npm-install-approval") {
|
|
1655
|
+
return /* @__PURE__ */ jsx4(NpmInstallApprovalPrompt, { ...props });
|
|
1656
|
+
}
|
|
1657
|
+
return /* @__PURE__ */ jsx4(StandardQuestionPrompt, { ...props });
|
|
1658
|
+
}
|
|
1659
|
+
function StandardQuestionPrompt(props) {
|
|
1055
1660
|
const { client, question, askerLabel, active, onAnswered } = props;
|
|
1056
|
-
const choices = question
|
|
1057
|
-
const allowWriteIn = question
|
|
1661
|
+
const choices = choicesForQuestion(question);
|
|
1662
|
+
const allowWriteIn = allowsWriteIn(question);
|
|
1058
1663
|
const multiSelect = question.multiSelect === true;
|
|
1059
1664
|
const options = [
|
|
1060
1665
|
...choices.map(
|
|
@@ -1063,12 +1668,12 @@ function QuestionPrompt(props) {
|
|
|
1063
1668
|
...allowWriteIn ? [{ kind: "write-in", label: "Other\u2026" }] : [],
|
|
1064
1669
|
...multiSelect && choices.length > 0 ? [{ kind: "submit", label: "Submit selections" }] : []
|
|
1065
1670
|
];
|
|
1066
|
-
const [optionIndex, setOptionIndex] =
|
|
1067
|
-
const [selected, setSelected] =
|
|
1068
|
-
const [writing, setWriting] =
|
|
1069
|
-
const [writeIn, setWriteIn] =
|
|
1070
|
-
const [submitting, setSubmitting] =
|
|
1071
|
-
const [error, setError] =
|
|
1671
|
+
const [optionIndex, setOptionIndex] = useState4(0);
|
|
1672
|
+
const [selected, setSelected] = useState4(() => /* @__PURE__ */ new Set());
|
|
1673
|
+
const [writing, setWriting] = useState4(choices.length === 0 && allowWriteIn);
|
|
1674
|
+
const [writeIn, setWriteIn] = useState4("");
|
|
1675
|
+
const [submitting, setSubmitting] = useState4(false);
|
|
1676
|
+
const [error, setError] = useState4(null);
|
|
1072
1677
|
const activeOptionIndex = Math.min(optionIndex, Math.max(0, options.length - 1));
|
|
1073
1678
|
const windowStart = Math.min(
|
|
1074
1679
|
Math.max(0, activeOptionIndex - QUESTION_OPTION_WINDOW_SIZE + 1),
|
|
@@ -1140,10 +1745,7 @@ function QuestionPrompt(props) {
|
|
|
1140
1745
|
{ isActive: active }
|
|
1141
1746
|
);
|
|
1142
1747
|
return /* @__PURE__ */ jsxs5(Box5, { flexDirection: "column", borderStyle: "round", borderColor: "yellow", paddingX: 1, children: [
|
|
1143
|
-
/* @__PURE__ */
|
|
1144
|
-
askerLabel,
|
|
1145
|
-
" asks"
|
|
1146
|
-
] }),
|
|
1748
|
+
/* @__PURE__ */ jsx4(Text5, { bold: true, color: "yellow", children: questionHeading(question, askerLabel) }),
|
|
1147
1749
|
/* @__PURE__ */ jsx4(Text5, { wrap: "wrap", children: question.prompt }),
|
|
1148
1750
|
writing ? /* @__PURE__ */ jsxs5(Fragment3, { children: [
|
|
1149
1751
|
/* @__PURE__ */ jsxs5(Box5, { children: [
|
|
@@ -1185,6 +1787,128 @@ function QuestionPrompt(props) {
|
|
|
1185
1787
|
error ? /* @__PURE__ */ jsx4(Text5, { color: "red", children: error }) : null
|
|
1186
1788
|
] });
|
|
1187
1789
|
}
|
|
1790
|
+
var NPM_DECISIONS = [
|
|
1791
|
+
{ value: "install", label: "Install" },
|
|
1792
|
+
{ value: "always", label: "Always allow" },
|
|
1793
|
+
{ value: "decline", label: "Decline" }
|
|
1794
|
+
];
|
|
1795
|
+
function NpmInstallApprovalPrompt(props) {
|
|
1796
|
+
const { client, question, active, onAnswered } = props;
|
|
1797
|
+
const packages = npmApprovalPackages(question);
|
|
1798
|
+
const [packageIndex, setPackageIndex] = useState4(0);
|
|
1799
|
+
const [optionIndex, setOptionIndex] = useState4(0);
|
|
1800
|
+
const [decisions, setDecisions] = useState4(
|
|
1801
|
+
() => packages.map(() => void 0)
|
|
1802
|
+
);
|
|
1803
|
+
const [submitting, setSubmitting] = useState4(false);
|
|
1804
|
+
const [error, setError] = useState4(null);
|
|
1805
|
+
const currentPackage = packages[packageIndex];
|
|
1806
|
+
const submit = async (nextDecisions) => {
|
|
1807
|
+
if (submitting) return;
|
|
1808
|
+
setError(null);
|
|
1809
|
+
setSubmitting(true);
|
|
1810
|
+
const body = packages.length === 0 ? { declined: true } : {
|
|
1811
|
+
npmInstallDecisions: packages.map((entry, index) => ({
|
|
1812
|
+
package: entry.package,
|
|
1813
|
+
version: entry.version,
|
|
1814
|
+
decision: nextDecisions[index] ?? "decline"
|
|
1815
|
+
}))
|
|
1816
|
+
};
|
|
1817
|
+
try {
|
|
1818
|
+
onAnswered(await client.answerQuestion(question.id, body));
|
|
1819
|
+
} catch (err) {
|
|
1820
|
+
setError(err instanceof Error ? err.message : String(err));
|
|
1821
|
+
setSubmitting(false);
|
|
1822
|
+
}
|
|
1823
|
+
};
|
|
1824
|
+
useInput3(
|
|
1825
|
+
(_input, key) => {
|
|
1826
|
+
if (submitting) return;
|
|
1827
|
+
if (!currentPackage) {
|
|
1828
|
+
if (key.return) void submit([]);
|
|
1829
|
+
return;
|
|
1830
|
+
}
|
|
1831
|
+
if (key.upArrow) {
|
|
1832
|
+
setOptionIndex((index) => index <= 0 ? NPM_DECISIONS.length - 1 : index - 1);
|
|
1833
|
+
return;
|
|
1834
|
+
}
|
|
1835
|
+
if (key.downArrow) {
|
|
1836
|
+
setOptionIndex((index) => index >= NPM_DECISIONS.length - 1 ? 0 : index + 1);
|
|
1837
|
+
return;
|
|
1838
|
+
}
|
|
1839
|
+
if (key.leftArrow && packageIndex > 0) {
|
|
1840
|
+
const previousIndex = packageIndex - 1;
|
|
1841
|
+
const previousDecision = decisions[previousIndex];
|
|
1842
|
+
setPackageIndex(previousIndex);
|
|
1843
|
+
setOptionIndex(
|
|
1844
|
+
Math.max(
|
|
1845
|
+
0,
|
|
1846
|
+
NPM_DECISIONS.findIndex((item) => item.value === previousDecision)
|
|
1847
|
+
)
|
|
1848
|
+
);
|
|
1849
|
+
setError(null);
|
|
1850
|
+
return;
|
|
1851
|
+
}
|
|
1852
|
+
if (!key.return) return;
|
|
1853
|
+
const decision = NPM_DECISIONS[optionIndex]?.value ?? "decline";
|
|
1854
|
+
const nextDecisions = decisions.slice();
|
|
1855
|
+
nextDecisions[packageIndex] = decision;
|
|
1856
|
+
setDecisions(nextDecisions);
|
|
1857
|
+
if (packageIndex >= packages.length - 1) {
|
|
1858
|
+
void submit(nextDecisions);
|
|
1859
|
+
return;
|
|
1860
|
+
}
|
|
1861
|
+
const nextPackageIndex = packageIndex + 1;
|
|
1862
|
+
const nextDecision = nextDecisions[nextPackageIndex];
|
|
1863
|
+
setPackageIndex(nextPackageIndex);
|
|
1864
|
+
setOptionIndex(
|
|
1865
|
+
Math.max(
|
|
1866
|
+
0,
|
|
1867
|
+
NPM_DECISIONS.findIndex((item) => item.value === nextDecision)
|
|
1868
|
+
)
|
|
1869
|
+
);
|
|
1870
|
+
setError(null);
|
|
1871
|
+
},
|
|
1872
|
+
{ isActive: active }
|
|
1873
|
+
);
|
|
1874
|
+
return /* @__PURE__ */ jsxs5(Box5, { flexDirection: "column", borderStyle: "round", borderColor: "yellow", paddingX: 1, children: [
|
|
1875
|
+
/* @__PURE__ */ jsx4(Text5, { bold: true, color: "yellow", children: "npm package approval" }),
|
|
1876
|
+
currentPackage ? /* @__PURE__ */ jsxs5(Fragment3, { children: [
|
|
1877
|
+
/* @__PURE__ */ jsxs5(Text5, { wrap: "wrap", children: [
|
|
1878
|
+
"A gezel wants to install ",
|
|
1879
|
+
packages.length === 1 ? "this package" : "packages",
|
|
1880
|
+
" outside the pre-vetted list."
|
|
1881
|
+
] }),
|
|
1882
|
+
/* @__PURE__ */ jsxs5(Text5, { children: [
|
|
1883
|
+
/* @__PURE__ */ jsxs5(Text5, { bold: true, children: [
|
|
1884
|
+
currentPackage.package,
|
|
1885
|
+
"@",
|
|
1886
|
+
currentPackage.version
|
|
1887
|
+
] }),
|
|
1888
|
+
packages.length > 1 ? ` \xB7 package ${packageIndex + 1}/${packages.length}` : ""
|
|
1889
|
+
] }),
|
|
1890
|
+
NPM_DECISIONS.map((option, index) => {
|
|
1891
|
+
const focused = index === optionIndex;
|
|
1892
|
+
const selected = decisions[packageIndex] === option.value;
|
|
1893
|
+
return /* @__PURE__ */ jsxs5(Text5, { color: focused ? "cyan" : void 0, children: [
|
|
1894
|
+
focused ? "\u203A " : " ",
|
|
1895
|
+
selected ? "[x] " : "",
|
|
1896
|
+
option.label
|
|
1897
|
+
] }, option.value);
|
|
1898
|
+
}),
|
|
1899
|
+
/* @__PURE__ */ jsxs5(Text5, { dimColor: true, children: [
|
|
1900
|
+
"\u2191/\u2193 choose \xB7 Enter answer",
|
|
1901
|
+
packageIndex > 0 ? " \xB7 \u2190 previous package" : ""
|
|
1902
|
+
] })
|
|
1903
|
+
] }) : /* @__PURE__ */ jsxs5(Fragment3, { children: [
|
|
1904
|
+
/* @__PURE__ */ jsx4(Text5, { color: "red", children: "This approval has no package details." }),
|
|
1905
|
+
/* @__PURE__ */ jsx4(Text5, { color: "cyan", children: "\u203A Decline and dismiss" }),
|
|
1906
|
+
/* @__PURE__ */ jsx4(Text5, { dimColor: true, children: "Enter dismiss" })
|
|
1907
|
+
] }),
|
|
1908
|
+
submitting ? /* @__PURE__ */ jsx4(Text5, { color: "yellow", children: "Submitting\u2026" }) : null,
|
|
1909
|
+
error ? /* @__PURE__ */ jsx4(Text5, { color: "red", children: error }) : null
|
|
1910
|
+
] });
|
|
1911
|
+
}
|
|
1188
1912
|
function toggleSet(current, value) {
|
|
1189
1913
|
const next = new Set(current);
|
|
1190
1914
|
if (next.has(value)) next.delete(value);
|
|
@@ -1592,21 +2316,21 @@ function modelFitLabel(fit) {
|
|
|
1592
2316
|
}
|
|
1593
2317
|
|
|
1594
2318
|
// src/tui/question-queue.ts
|
|
1595
|
-
function
|
|
1596
|
-
return questions.filter((question) => !question.answer &&
|
|
2319
|
+
function pendingQuestionsForTui(questions) {
|
|
2320
|
+
return questions.filter((question) => !question.answer && canAnswerQuestionInTui(question)).slice().sort((a, b) => a.createdAt.localeCompare(b.createdAt));
|
|
1597
2321
|
}
|
|
1598
2322
|
function updatePendingQuestion(questions, question) {
|
|
1599
2323
|
const withoutCurrent = questions.filter((candidate) => candidate.id !== question.id);
|
|
1600
|
-
return
|
|
2324
|
+
return pendingQuestionsForTui(question.answer ? withoutCurrent : [...withoutCurrent, question]);
|
|
1601
2325
|
}
|
|
1602
2326
|
|
|
1603
2327
|
// src/tui/streams.ts
|
|
1604
2328
|
import { streamProjectChatEvents, streamTerminalEvents } from "@bendyline/gezel-client";
|
|
1605
|
-
import { useEffect as
|
|
2329
|
+
import { useEffect as useEffect3, useRef as useRef2 } from "react";
|
|
1606
2330
|
function useProjectEvents(client, projectId, handler) {
|
|
1607
|
-
const handlerRef =
|
|
2331
|
+
const handlerRef = useRef2(handler);
|
|
1608
2332
|
handlerRef.current = handler;
|
|
1609
|
-
|
|
2333
|
+
useEffect3(() => {
|
|
1610
2334
|
const controller = new AbortController();
|
|
1611
2335
|
void consumeWithReconnect(
|
|
1612
2336
|
async function* () {
|
|
@@ -1626,9 +2350,9 @@ function useProjectEvents(client, projectId, handler) {
|
|
|
1626
2350
|
}, [client, projectId]);
|
|
1627
2351
|
}
|
|
1628
2352
|
function useTerminalEvents(client, projectId, handler) {
|
|
1629
|
-
const handlerRef =
|
|
2353
|
+
const handlerRef = useRef2(handler);
|
|
1630
2354
|
handlerRef.current = handler;
|
|
1631
|
-
|
|
2355
|
+
useEffect3(() => {
|
|
1632
2356
|
const controller = new AbortController();
|
|
1633
2357
|
void consumeWithReconnect(
|
|
1634
2358
|
async function* () {
|
|
@@ -1678,8 +2402,8 @@ function abortableDelay(ms, signal) {
|
|
|
1678
2402
|
import { jsx as jsx5, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
1679
2403
|
function useTerminalSize() {
|
|
1680
2404
|
const { stdout } = useStdout();
|
|
1681
|
-
const [size, setSize] =
|
|
1682
|
-
|
|
2405
|
+
const [size, setSize] = useState5({ rows: stdout?.rows ?? 24, columns: stdout?.columns ?? 80 });
|
|
2406
|
+
useEffect4(() => {
|
|
1683
2407
|
if (!stdout) return;
|
|
1684
2408
|
const onResize = () => setSize({ rows: stdout.rows ?? 24, columns: stdout.columns ?? 80 });
|
|
1685
2409
|
stdout.on("resize", onResize);
|
|
@@ -1695,8 +2419,11 @@ var HELP = [
|
|
|
1695
2419
|
"/allow edits \u2014 allow tool edits /disallow edits \u2014 make tool edits read-only",
|
|
1696
2420
|
"/allow codexedits|claudeedits \u2014 allow provider-native project edits",
|
|
1697
2421
|
"/disallow codexedits|claudeedits \u2014 put that provider in read-only plan mode",
|
|
2422
|
+
"/show thinking \u2014 show model reasoning inline /hide thinking \u2014 hide it",
|
|
2423
|
+
"/show writes \u2014 stream write contents inline /hide writes \u2014 hide them (default)",
|
|
1698
2424
|
"/mode \u2014 choose read-only, reactive, reactive+tasks, or full-play AI activity",
|
|
1699
2425
|
"/thread \u2014 switch or start a chat thread",
|
|
2426
|
+
"/open workspace|artifacts|<recent file> \u2014 open a folder or file from chat",
|
|
1700
2427
|
"/task \u2014 list, inspect, create, edit, assign, or change task status",
|
|
1701
2428
|
"/do \u2014 choose a craftbook and start it as a task",
|
|
1702
2429
|
"/continue \u2014 process due schedules and active tasks in this project",
|
|
@@ -1710,49 +2437,54 @@ var READ_ONLY_BOOT_NOTE = "Note: this folder is read-only to gezel, and can be u
|
|
|
1710
2437
|
function App(props) {
|
|
1711
2438
|
const { client } = props;
|
|
1712
2439
|
const { exit } = useApp();
|
|
1713
|
-
const [config, setConfig] =
|
|
1714
|
-
const [gezels, setGezels] =
|
|
1715
|
-
const [projects, setProjects] =
|
|
1716
|
-
const [threads, setThreads] =
|
|
1717
|
-
const [tasks, setTasks] =
|
|
1718
|
-
const [craftbooks, setCraftbooks] =
|
|
1719
|
-
const [craftbookProjectType, setCraftbookProjectType] =
|
|
1720
|
-
const [suggestedCraftbookIds, setSuggestedCraftbookIds] =
|
|
1721
|
-
const [craftbooksNeedingSetup, setCraftbooksNeedingSetup] =
|
|
2440
|
+
const [config, setConfig] = useState5(null);
|
|
2441
|
+
const [gezels, setGezels] = useState5([]);
|
|
2442
|
+
const [projects, setProjects] = useState5([]);
|
|
2443
|
+
const [threads, setThreads] = useState5([]);
|
|
2444
|
+
const [tasks, setTasks] = useState5([]);
|
|
2445
|
+
const [craftbooks, setCraftbooks] = useState5([]);
|
|
2446
|
+
const [craftbookProjectType, setCraftbookProjectType] = useState5(null);
|
|
2447
|
+
const [suggestedCraftbookIds, setSuggestedCraftbookIds] = useState5(() => /* @__PURE__ */ new Set());
|
|
2448
|
+
const [craftbooksNeedingSetup, setCraftbooksNeedingSetup] = useState5(
|
|
1722
2449
|
() => /* @__PURE__ */ new Set()
|
|
1723
2450
|
);
|
|
1724
|
-
const [startCategoryId, setStartCategoryId] =
|
|
1725
|
-
const [modelChoices, setModelChoices] =
|
|
1726
|
-
const [modelDownloadChoices, setModelDownloadChoices] =
|
|
1727
|
-
const [modelDownloadProgress, setModelDownloadProgress] =
|
|
2451
|
+
const [startCategoryId, setStartCategoryId] = useState5(null);
|
|
2452
|
+
const [modelChoices, setModelChoices] = useState5([]);
|
|
2453
|
+
const [modelDownloadChoices, setModelDownloadChoices] = useState5([]);
|
|
2454
|
+
const [modelDownloadProgress, setModelDownloadProgress] = useState5(
|
|
1728
2455
|
null
|
|
1729
2456
|
);
|
|
1730
|
-
const [modelDownloadReturn, setModelDownloadReturn] =
|
|
1731
|
-
const [modelChoicesLoading, setModelChoicesLoading] =
|
|
1732
|
-
const [threadsLoading, setThreadsLoading] =
|
|
1733
|
-
const [pendingQuestions, setPendingQuestions] =
|
|
1734
|
-
const [projectId, setProjectId] =
|
|
1735
|
-
const [projectName, setProjectName] =
|
|
1736
|
-
const [activeGezelId, setActiveGezelId] =
|
|
1737
|
-
const [ownSessionId, setOwnSessionId] =
|
|
1738
|
-
const [focusedSessionId, setFocusedSessionId] =
|
|
1739
|
-
const [activeThreadTitle, setActiveThreadTitle] =
|
|
1740
|
-
const [mode, setMode] =
|
|
1741
|
-
const [overlay, setOverlay] =
|
|
1742
|
-
const [value, setValue] =
|
|
1743
|
-
const [rows, setRows] =
|
|
1744
|
-
const [turns, setTurns] =
|
|
1745
|
-
const [
|
|
1746
|
-
const
|
|
1747
|
-
const [
|
|
1748
|
-
const [
|
|
1749
|
-
const [
|
|
1750
|
-
const [
|
|
1751
|
-
const [
|
|
2457
|
+
const [modelDownloadReturn, setModelDownloadReturn] = useState5(null);
|
|
2458
|
+
const [modelChoicesLoading, setModelChoicesLoading] = useState5(false);
|
|
2459
|
+
const [threadsLoading, setThreadsLoading] = useState5(false);
|
|
2460
|
+
const [pendingQuestions, setPendingQuestions] = useState5([]);
|
|
2461
|
+
const [projectId, setProjectId] = useState5(props.initialProjectId);
|
|
2462
|
+
const [projectName, setProjectName] = useState5(props.initialProjectName);
|
|
2463
|
+
const [activeGezelId, setActiveGezelId] = useState5(null);
|
|
2464
|
+
const [ownSessionId, setOwnSessionId] = useState5(null);
|
|
2465
|
+
const [focusedSessionId, setFocusedSessionId] = useState5(null);
|
|
2466
|
+
const [activeThreadTitle, setActiveThreadTitle] = useState5(null);
|
|
2467
|
+
const [mode, setMode] = useState5("chat");
|
|
2468
|
+
const [overlay, setOverlay] = useState5(null);
|
|
2469
|
+
const [value, setValue] = useState5("");
|
|
2470
|
+
const [rows, setRows, setRowsBuffered] = useBufferedState([], 50);
|
|
2471
|
+
const [turns, setTurns, setTurnsBuffered] = useBufferedState(() => /* @__PURE__ */ new Map(), 50);
|
|
2472
|
+
const [recentOpenReferences, setRecentOpenReferences] = useState5([]);
|
|
2473
|
+
const recentOpenReferencesRef = useRef3([]);
|
|
2474
|
+
const [status, setStatus] = useState5("Connecting\u2026");
|
|
2475
|
+
const [history, setHistory] = useState5([]);
|
|
2476
|
+
const [activeRuns, setActiveRuns] = useState5(() => /* @__PURE__ */ new Set());
|
|
2477
|
+
const [pendingInput, setPendingInput] = useState5(null);
|
|
2478
|
+
const [managedTaskRef, setManagedTaskRef] = useState5(null);
|
|
2479
|
+
const [taskPrompt, setTaskPrompt] = useState5(null);
|
|
2480
|
+
const [exitArmed, setExitArmed] = useState5(false);
|
|
2481
|
+
useEffect4(() => {
|
|
2482
|
+
props.diagnostics?.recordReactCommit();
|
|
2483
|
+
});
|
|
1752
2484
|
const pendingQuestion = pendingQuestions[0];
|
|
1753
2485
|
const { rows: termRows, columns: termColumns } = useTerminalSize();
|
|
1754
2486
|
const shellColumns = Math.min(500, Math.max(20, termColumns - 2));
|
|
1755
|
-
const wordwheelCount = overlay === null && !pendingInput && !pendingQuestion ? suggestSlashWordwheel(value, craftbooks).length : 0;
|
|
2487
|
+
const wordwheelCount = overlay === null && !pendingInput && !pendingQuestion ? suggestSlashWordwheel(value, craftbooks, recentOpenReferences).length : 0;
|
|
1756
2488
|
const wordwheelRows = wordwheelCount > 0 ? Math.min(SLASH_COMMAND_WORDWHEEL_SIZE, wordwheelCount) + 1 : 0;
|
|
1757
2489
|
const questionRows = pendingQuestion ? Math.min(QUESTION_OPTION_WINDOW_SIZE, Math.max(1, questionOptionCount(pendingQuestion))) + 4 : 0;
|
|
1758
2490
|
const modelPickerWindowSize = Math.max(4, Math.min(10, termRows - 12));
|
|
@@ -1771,19 +2503,23 @@ function App(props) {
|
|
|
1771
2503
|
const effectiveModel = activeGezel?.model ?? (effectiveProvider ? config?.defaultModel?.[effectiveProvider] : void 0);
|
|
1772
2504
|
const statusLabel = useMemo(() => {
|
|
1773
2505
|
if (turns.size === 0) return void 0;
|
|
1774
|
-
|
|
2506
|
+
const turn = focusedSessionId && turns.get(focusedSessionId) || ownSessionId && turns.get(ownSessionId) || turns.values().next().value;
|
|
2507
|
+
return turn?.label;
|
|
1775
2508
|
}, [turns, focusedSessionId, ownSessionId]);
|
|
1776
|
-
const note =
|
|
2509
|
+
const note = useCallback2(
|
|
1777
2510
|
(text, kind = "note") => setRows((r) => appendNote(r, text, kind)),
|
|
1778
|
-
[]
|
|
2511
|
+
[setRows]
|
|
1779
2512
|
);
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
2513
|
+
useEffect4(() => {
|
|
2514
|
+
recentOpenReferencesRef.current = recentOpenReferences;
|
|
2515
|
+
}, [recentOpenReferences]);
|
|
2516
|
+
const gezelIds = useRef3(/* @__PURE__ */ new Set());
|
|
2517
|
+
const gezelRefreshInFlight = useRef3(false);
|
|
2518
|
+
const applyGezelSnapshot = useCallback2((next) => {
|
|
1783
2519
|
gezelIds.current = new Set(next.map((gezel) => gezel.id));
|
|
1784
2520
|
setGezels(next);
|
|
1785
2521
|
}, []);
|
|
1786
|
-
const refreshGezels =
|
|
2522
|
+
const refreshGezels = useCallback2(async () => {
|
|
1787
2523
|
if (gezelRefreshInFlight.current) return;
|
|
1788
2524
|
gezelRefreshInFlight.current = true;
|
|
1789
2525
|
try {
|
|
@@ -1794,8 +2530,8 @@ function App(props) {
|
|
|
1794
2530
|
gezelRefreshInFlight.current = false;
|
|
1795
2531
|
}
|
|
1796
2532
|
}, [applyGezelSnapshot, client]);
|
|
1797
|
-
const taskLoadSequence =
|
|
1798
|
-
const refreshTasks =
|
|
2533
|
+
const taskLoadSequence = useRef3(0);
|
|
2534
|
+
const refreshTasks = useCallback2(async () => {
|
|
1799
2535
|
const sequence = ++taskLoadSequence.current;
|
|
1800
2536
|
try {
|
|
1801
2537
|
const res = await client.listProjectTasks(projectId);
|
|
@@ -1804,8 +2540,8 @@ function App(props) {
|
|
|
1804
2540
|
} catch {
|
|
1805
2541
|
}
|
|
1806
2542
|
}, [client, projectId]);
|
|
1807
|
-
const craftbookLoadSequence =
|
|
1808
|
-
const refreshCraftbooks =
|
|
2543
|
+
const craftbookLoadSequence = useRef3(0);
|
|
2544
|
+
const refreshCraftbooks = useCallback2(async () => {
|
|
1809
2545
|
const sequence = ++craftbookLoadSequence.current;
|
|
1810
2546
|
const result = await client.listProjectCraftbooks(projectId);
|
|
1811
2547
|
if (sequence !== craftbookLoadSequence.current) return [];
|
|
@@ -1819,10 +2555,25 @@ function App(props) {
|
|
|
1819
2555
|
useProjectEvents(
|
|
1820
2556
|
client,
|
|
1821
2557
|
projectId,
|
|
1822
|
-
|
|
2558
|
+
useCallback2(
|
|
1823
2559
|
(env) => {
|
|
1824
|
-
|
|
1825
|
-
|
|
2560
|
+
props.diagnostics?.recordChatEvent(env);
|
|
2561
|
+
const streaming = env.event.type === "delta" || env.event.type === "reasoning_delta" || env.event.type === "tool_args_delta";
|
|
2562
|
+
const updateRows = streaming ? setRowsBuffered : setRows;
|
|
2563
|
+
const updateTurns = streaming ? setTurnsBuffered : setTurns;
|
|
2564
|
+
updateRows(
|
|
2565
|
+
(r) => reduceFeed(r, env, {
|
|
2566
|
+
showThinking: config?.cliShowThinking !== false,
|
|
2567
|
+
showWrites: config?.cliShowWrites === true
|
|
2568
|
+
})
|
|
2569
|
+
);
|
|
2570
|
+
updateTurns((t) => reduceTurns(t, env));
|
|
2571
|
+
const observedReferences = cliOpenReferencesFromEvent(env);
|
|
2572
|
+
if (observedReferences.length > 0) {
|
|
2573
|
+
setRecentOpenReferences(
|
|
2574
|
+
(current) => rememberCliOpenReferences(current, observedReferences)
|
|
2575
|
+
);
|
|
2576
|
+
}
|
|
1826
2577
|
const eventGezelId = env.gezelId || (env.event.type === "task_event" ? env.event.gezelId : void 0);
|
|
1827
2578
|
if (eventGezelId && !gezelIds.current.has(eventGezelId)) void refreshGezels();
|
|
1828
2579
|
if (env.event.type === "task_event") void refreshTasks();
|
|
@@ -1840,43 +2591,58 @@ function App(props) {
|
|
|
1840
2591
|
setPendingQuestions((questions) => updatePendingQuestion(questions, question));
|
|
1841
2592
|
}
|
|
1842
2593
|
},
|
|
1843
|
-
[
|
|
2594
|
+
[
|
|
2595
|
+
config?.cliShowThinking,
|
|
2596
|
+
config?.cliShowWrites,
|
|
2597
|
+
ownSessionId,
|
|
2598
|
+
props.diagnostics,
|
|
2599
|
+
refreshGezels,
|
|
2600
|
+
refreshTasks,
|
|
2601
|
+
setRows,
|
|
2602
|
+
setRowsBuffered,
|
|
2603
|
+
setTurns,
|
|
2604
|
+
setTurnsBuffered
|
|
2605
|
+
]
|
|
1844
2606
|
)
|
|
1845
2607
|
);
|
|
1846
2608
|
useTerminalEvents(
|
|
1847
2609
|
client,
|
|
1848
2610
|
projectId,
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
if (!
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
2611
|
+
useCallback2(
|
|
2612
|
+
(env) => {
|
|
2613
|
+
props.diagnostics?.recordTerminalEvent(env);
|
|
2614
|
+
switch (env.kind) {
|
|
2615
|
+
case "runStarted":
|
|
2616
|
+
setActiveRuns((s) => new Set(s).add(env.runId));
|
|
2617
|
+
return;
|
|
2618
|
+
case "outputChunk":
|
|
2619
|
+
setRowsBuffered((r) => appendShellChunk(r, env.runId, env.chunk));
|
|
2620
|
+
return;
|
|
2621
|
+
case "inputRequested":
|
|
2622
|
+
setPendingInput({ runId: env.runId, mode: env.mode, promptLine: env.promptLine });
|
|
2623
|
+
setRows((r) => appendNote(r, `\u2328 waiting for input \u2014 ${env.promptLine}`, "note"));
|
|
2624
|
+
return;
|
|
2625
|
+
case "message": {
|
|
2626
|
+
const runId = env.runId;
|
|
2627
|
+
if (!runId) return;
|
|
2628
|
+
setActiveRuns((s) => {
|
|
2629
|
+
if (!s.has(runId)) return s;
|
|
2630
|
+
const n = new Set(s);
|
|
2631
|
+
n.delete(runId);
|
|
2632
|
+
return n;
|
|
2633
|
+
});
|
|
2634
|
+
setPendingInput((p) => p?.runId === runId ? null : p);
|
|
2635
|
+
setRows((r) => finalizeShellRun(r, runId, env.message));
|
|
2636
|
+
return;
|
|
2637
|
+
}
|
|
2638
|
+
default:
|
|
2639
|
+
return;
|
|
1873
2640
|
}
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
}, [])
|
|
2641
|
+
},
|
|
2642
|
+
[props.diagnostics, setRows, setRowsBuffered]
|
|
2643
|
+
)
|
|
1878
2644
|
);
|
|
1879
|
-
const ensureSession =
|
|
2645
|
+
const ensureSession = useCallback2(
|
|
1880
2646
|
async (gezelId, pid) => {
|
|
1881
2647
|
try {
|
|
1882
2648
|
const session = await client.createChatSession({
|
|
@@ -1895,7 +2661,7 @@ function App(props) {
|
|
|
1895
2661
|
},
|
|
1896
2662
|
[client, note, boring]
|
|
1897
2663
|
);
|
|
1898
|
-
const switchProject =
|
|
2664
|
+
const switchProject = useCallback2(
|
|
1899
2665
|
async (id) => {
|
|
1900
2666
|
setOverlay(null);
|
|
1901
2667
|
const project = projects.find((candidate) => candidate.id === id);
|
|
@@ -1906,6 +2672,7 @@ function App(props) {
|
|
|
1906
2672
|
setProjectName(project.name);
|
|
1907
2673
|
setActiveGezelId(gezelId);
|
|
1908
2674
|
setRows([]);
|
|
2675
|
+
setRecentOpenReferences([]);
|
|
1909
2676
|
setTurns(/* @__PURE__ */ new Map());
|
|
1910
2677
|
setActiveRuns(/* @__PURE__ */ new Set());
|
|
1911
2678
|
setPendingInput(null);
|
|
@@ -1925,9 +2692,9 @@ function App(props) {
|
|
|
1925
2692
|
note(`could not switch project: ${errMsg(err)}`, "error");
|
|
1926
2693
|
}
|
|
1927
2694
|
},
|
|
1928
|
-
[client, ensureSession, note, projectId, projects]
|
|
2695
|
+
[client, ensureSession, note, projectId, projects, setRows, setTurns]
|
|
1929
2696
|
);
|
|
1930
|
-
const openModelPicker =
|
|
2697
|
+
const openModelPicker = useCallback2(async () => {
|
|
1931
2698
|
if (!activeGezelId || !activeGezel) return note("no active gezel yet.", "error");
|
|
1932
2699
|
if (activeGezel.fixedFunction) {
|
|
1933
2700
|
return note("this gezel runs a fixed tool and does not use a chat model.", "error");
|
|
@@ -1945,7 +2712,7 @@ function App(props) {
|
|
|
1945
2712
|
setModelChoicesLoading(false);
|
|
1946
2713
|
}
|
|
1947
2714
|
}, [activeGezel, activeGezelId, client, config, modelChoicesLoading, note]);
|
|
1948
|
-
const openModelDownloadPicker =
|
|
2715
|
+
const openModelDownloadPicker = useCallback2(
|
|
1949
2716
|
async (returnTo = null) => {
|
|
1950
2717
|
if (!activeGezelId || !activeGezel) return note("no active gezel yet.", "error");
|
|
1951
2718
|
if (activeGezel.fixedFunction) {
|
|
@@ -1977,7 +2744,7 @@ function App(props) {
|
|
|
1977
2744
|
},
|
|
1978
2745
|
[activeGezel, activeGezelId, client, config, modelChoicesLoading, note, openModelPicker]
|
|
1979
2746
|
);
|
|
1980
|
-
const openThreadPicker =
|
|
2747
|
+
const openThreadPicker = useCallback2(async () => {
|
|
1981
2748
|
if (!activeGezelId) return note("no active gezel yet.", "error");
|
|
1982
2749
|
if (threadsLoading) return;
|
|
1983
2750
|
setThreadsLoading(true);
|
|
@@ -1991,7 +2758,7 @@ function App(props) {
|
|
|
1991
2758
|
setThreadsLoading(false);
|
|
1992
2759
|
}
|
|
1993
2760
|
}, [activeGezelId, client, note, projectId, threadsLoading]);
|
|
1994
|
-
const switchThread =
|
|
2761
|
+
const switchThread = useCallback2(
|
|
1995
2762
|
async (sessionId) => {
|
|
1996
2763
|
setOverlay(null);
|
|
1997
2764
|
try {
|
|
@@ -2002,14 +2769,15 @@ function App(props) {
|
|
|
2002
2769
|
setOwnSessionId(session.id);
|
|
2003
2770
|
setFocusedSessionId(session.id);
|
|
2004
2771
|
setActiveThreadTitle(displayThreadTitle(session.title));
|
|
2005
|
-
setRows(sessionToFeedRows(session));
|
|
2772
|
+
setRows(sessionToFeedRows(session, { showThinking: config?.cliShowThinking !== false }));
|
|
2773
|
+
setRecentOpenReferences(cliOpenReferencesFromSession(session));
|
|
2006
2774
|
} catch (err) {
|
|
2007
2775
|
note(`could not switch thread: ${errMsg(err)}`, "error");
|
|
2008
2776
|
}
|
|
2009
2777
|
},
|
|
2010
|
-
[activeGezelId, client, note, projectId]
|
|
2778
|
+
[activeGezelId, client, config?.cliShowThinking, note, projectId, setRows]
|
|
2011
2779
|
);
|
|
2012
|
-
const startNewThread =
|
|
2780
|
+
const startNewThread = useCallback2(async () => {
|
|
2013
2781
|
setOverlay(null);
|
|
2014
2782
|
if (!activeGezelId) return note("no active gezel yet.", "error");
|
|
2015
2783
|
try {
|
|
@@ -2022,12 +2790,13 @@ function App(props) {
|
|
|
2022
2790
|
setFocusedSessionId(session.id);
|
|
2023
2791
|
setActiveThreadTitle(displayThreadTitle(session.title));
|
|
2024
2792
|
setRows([]);
|
|
2793
|
+
setRecentOpenReferences([]);
|
|
2025
2794
|
setThreads((current) => [session, ...current.filter((item) => item.id !== session.id)]);
|
|
2026
2795
|
} catch (err) {
|
|
2027
2796
|
note(`could not start a thread: ${errMsg(err)}`, "error");
|
|
2028
2797
|
}
|
|
2029
|
-
}, [activeGezelId, client, note, projectId,
|
|
2030
|
-
|
|
2798
|
+
}, [activeGezelId, boring, client, note, projectId, setRows]);
|
|
2799
|
+
useEffect4(() => {
|
|
2031
2800
|
let cancelled = false;
|
|
2032
2801
|
(async () => {
|
|
2033
2802
|
try {
|
|
@@ -2072,25 +2841,25 @@ function App(props) {
|
|
|
2072
2841
|
cancelled = true;
|
|
2073
2842
|
};
|
|
2074
2843
|
}, []);
|
|
2075
|
-
|
|
2844
|
+
useEffect4(() => {
|
|
2076
2845
|
let cancelled = false;
|
|
2077
2846
|
setPendingQuestions([]);
|
|
2078
2847
|
void client.listQuestions({ projectId, pending: true }).then((result) => {
|
|
2079
|
-
if (!cancelled) setPendingQuestions(
|
|
2848
|
+
if (!cancelled) setPendingQuestions(pendingQuestionsForTui(result.questions));
|
|
2080
2849
|
}).catch(() => {
|
|
2081
2850
|
});
|
|
2082
2851
|
return () => {
|
|
2083
2852
|
cancelled = true;
|
|
2084
2853
|
};
|
|
2085
2854
|
}, [client, projectId]);
|
|
2086
|
-
|
|
2855
|
+
useEffect4(() => {
|
|
2087
2856
|
void refreshTasks();
|
|
2088
2857
|
const id = setInterval(() => void refreshTasks(), 3e4);
|
|
2089
2858
|
return () => {
|
|
2090
2859
|
clearInterval(id);
|
|
2091
2860
|
};
|
|
2092
2861
|
}, [refreshTasks]);
|
|
2093
|
-
|
|
2862
|
+
useEffect4(() => {
|
|
2094
2863
|
void refreshCraftbooks().catch(() => {
|
|
2095
2864
|
});
|
|
2096
2865
|
}, [refreshCraftbooks]);
|
|
@@ -2147,7 +2916,7 @@ function App(props) {
|
|
|
2147
2916
|
}
|
|
2148
2917
|
return items;
|
|
2149
2918
|
}, [rows, gezels, ownSessionId, gezelLine, boring]);
|
|
2150
|
-
const cancelActive =
|
|
2919
|
+
const cancelActive = useCallback2(async () => {
|
|
2151
2920
|
const sessions = [...turns.keys()];
|
|
2152
2921
|
const runs = [...activeRuns];
|
|
2153
2922
|
if (sessions.length === 0 && runs.length === 0) return false;
|
|
@@ -2157,10 +2926,10 @@ function App(props) {
|
|
|
2157
2926
|
]);
|
|
2158
2927
|
return true;
|
|
2159
2928
|
}, [turns, activeRuns, client, projectId]);
|
|
2160
|
-
const rememberTask =
|
|
2929
|
+
const rememberTask = useCallback2((task) => {
|
|
2161
2930
|
setTasks((current) => sortTasks([...current.filter((item) => item.ref !== task.ref), task]));
|
|
2162
2931
|
}, []);
|
|
2163
|
-
const applyEngagementMode =
|
|
2932
|
+
const applyEngagementMode = useCallback2(
|
|
2164
2933
|
async (requested) => {
|
|
2165
2934
|
const next = parseCliEngagementMode(requested);
|
|
2166
2935
|
if (!next) {
|
|
@@ -2179,7 +2948,7 @@ function App(props) {
|
|
|
2179
2948
|
},
|
|
2180
2949
|
[client, note]
|
|
2181
2950
|
);
|
|
2182
|
-
const applyProjectPermission =
|
|
2951
|
+
const applyProjectPermission = useCallback2(
|
|
2183
2952
|
async (permission, allowed) => {
|
|
2184
2953
|
const permissionName = parseProjectPermissionName(permission);
|
|
2185
2954
|
if (!permissionName) {
|
|
@@ -2210,12 +2979,46 @@ function App(props) {
|
|
|
2210
2979
|
},
|
|
2211
2980
|
[client, note, projectId, projectName]
|
|
2212
2981
|
);
|
|
2213
|
-
const
|
|
2982
|
+
const applyChatDetailVisibility = useCallback2(
|
|
2983
|
+
async (requested, visible) => {
|
|
2984
|
+
const target = requested.trim().toLowerCase();
|
|
2985
|
+
if (target !== "thinking" && target !== "writes") {
|
|
2986
|
+
note(`usage: /${visible ? "show" : "hide"} thinking|writes`, "error");
|
|
2987
|
+
return;
|
|
2988
|
+
}
|
|
2989
|
+
try {
|
|
2990
|
+
const updated = await client.updateConfig(
|
|
2991
|
+
target === "thinking" ? { cliShowThinking: visible } : { cliShowWrites: visible }
|
|
2992
|
+
);
|
|
2993
|
+
setConfig(updated);
|
|
2994
|
+
if (!visible) {
|
|
2995
|
+
const kind = target === "thinking" ? "thinking" : "write";
|
|
2996
|
+
setRows((current) => current.filter((row) => row.kind !== kind));
|
|
2997
|
+
}
|
|
2998
|
+
if (target === "thinking") {
|
|
2999
|
+
note(
|
|
3000
|
+
visible ? "Thinking is now shown inline." : "Thinking is now hidden. The live token count still includes it."
|
|
3001
|
+
);
|
|
3002
|
+
} else {
|
|
3003
|
+
note(
|
|
3004
|
+
visible ? "Write content is now shown inline as it streams." : "Write content is now hidden. Tool token counts remain visible."
|
|
3005
|
+
);
|
|
3006
|
+
}
|
|
3007
|
+
} catch (err) {
|
|
3008
|
+
note(`could not ${visible ? "show" : "hide"} ${target}: ${errMsg(err)}`, "error");
|
|
3009
|
+
}
|
|
3010
|
+
},
|
|
3011
|
+
[client, note, setRows]
|
|
3012
|
+
);
|
|
3013
|
+
const startCraftbook = useCallback2(
|
|
2214
3014
|
async (book) => {
|
|
2215
3015
|
setOverlay(null);
|
|
2216
3016
|
note(`starting ${book.name}\u2026`);
|
|
2217
3017
|
try {
|
|
2218
|
-
const created = await client.createTask(projectId,
|
|
3018
|
+
const created = await client.createTask(projectId, {
|
|
3019
|
+
...craftbookStartRequest(book),
|
|
3020
|
+
roleBasedNameOnlyMode: boring
|
|
3021
|
+
});
|
|
2219
3022
|
rememberTask(created);
|
|
2220
3023
|
setManagedTaskRef(created.ref);
|
|
2221
3024
|
note(`started ${created.ref} \u2014 ${created.title}`);
|
|
@@ -2223,9 +3026,9 @@ function App(props) {
|
|
|
2223
3026
|
note(`could not start ${book.name}: ${errMsg(err)}`, "error");
|
|
2224
3027
|
}
|
|
2225
3028
|
},
|
|
2226
|
-
[client, note, projectId, rememberTask]
|
|
3029
|
+
[boring, client, note, projectId, rememberTask]
|
|
2227
3030
|
);
|
|
2228
|
-
const submitTaskPrompt =
|
|
3031
|
+
const submitTaskPrompt = useCallback2(
|
|
2229
3032
|
async (raw) => {
|
|
2230
3033
|
const prompt = taskPrompt;
|
|
2231
3034
|
if (!prompt) return;
|
|
@@ -2242,7 +3045,8 @@ function App(props) {
|
|
|
2242
3045
|
title: text,
|
|
2243
3046
|
description: `${text} \u2014 complete this task and verify that the result meets the requested outcome.`,
|
|
2244
3047
|
assignee: { kind: "user" },
|
|
2245
|
-
steps: [{ name: "Main" }]
|
|
3048
|
+
steps: [{ name: "Main" }],
|
|
3049
|
+
roleBasedNameOnlyMode: boring
|
|
2246
3050
|
});
|
|
2247
3051
|
rememberTask(created);
|
|
2248
3052
|
setManagedTaskRef(created.ref);
|
|
@@ -2261,9 +3065,9 @@ function App(props) {
|
|
|
2261
3065
|
note(`task update failed: ${errMsg(err)}`, "error");
|
|
2262
3066
|
}
|
|
2263
3067
|
},
|
|
2264
|
-
[client, note, projectId, rememberTask, taskPrompt, tasks]
|
|
3068
|
+
[boring, client, note, projectId, rememberTask, taskPrompt, tasks]
|
|
2265
3069
|
);
|
|
2266
|
-
const applyTaskStatus =
|
|
3070
|
+
const applyTaskStatus = useCallback2(
|
|
2267
3071
|
async (status2) => {
|
|
2268
3072
|
const task = managedTask;
|
|
2269
3073
|
if (!task) return setOverlay("task");
|
|
@@ -2279,7 +3083,7 @@ function App(props) {
|
|
|
2279
3083
|
},
|
|
2280
3084
|
[client, managedTask, note, rememberTask]
|
|
2281
3085
|
);
|
|
2282
|
-
const applyTaskAssignee =
|
|
3086
|
+
const applyTaskAssignee = useCallback2(
|
|
2283
3087
|
async (value2) => {
|
|
2284
3088
|
const task = managedTask;
|
|
2285
3089
|
if (!task) return setOverlay("task");
|
|
@@ -2299,7 +3103,7 @@ function App(props) {
|
|
|
2299
3103
|
},
|
|
2300
3104
|
[client, managedTask, note, rememberTask]
|
|
2301
3105
|
);
|
|
2302
|
-
const runInput =
|
|
3106
|
+
const runInput = useCallback2(
|
|
2303
3107
|
async (raw) => {
|
|
2304
3108
|
if (pendingInput) {
|
|
2305
3109
|
const target = pendingInput;
|
|
@@ -2396,7 +3200,7 @@ function App(props) {
|
|
|
2396
3200
|
turns
|
|
2397
3201
|
]
|
|
2398
3202
|
);
|
|
2399
|
-
const runCommand =
|
|
3203
|
+
const runCommand = useCallback2(
|
|
2400
3204
|
async (name, rest) => {
|
|
2401
3205
|
switch (name) {
|
|
2402
3206
|
case "help":
|
|
@@ -2413,6 +3217,12 @@ function App(props) {
|
|
|
2413
3217
|
case "disallow":
|
|
2414
3218
|
await applyProjectPermission(rest, false);
|
|
2415
3219
|
return;
|
|
3220
|
+
case "show":
|
|
3221
|
+
await applyChatDetailVisibility(rest, true);
|
|
3222
|
+
return;
|
|
3223
|
+
case "hide":
|
|
3224
|
+
await applyChatDetailVisibility(rest, false);
|
|
3225
|
+
return;
|
|
2416
3226
|
case "mode":
|
|
2417
3227
|
if (!rest.trim()) return setOverlay("engagement-mode");
|
|
2418
3228
|
await applyEngagementMode(rest);
|
|
@@ -2426,6 +3236,33 @@ function App(props) {
|
|
|
2426
3236
|
case "thread":
|
|
2427
3237
|
await openThreadPicker();
|
|
2428
3238
|
return;
|
|
3239
|
+
case "open": {
|
|
3240
|
+
const target = resolveCliOpenTarget(rest, recentOpenReferencesRef.current);
|
|
3241
|
+
if (!target) {
|
|
3242
|
+
return note(
|
|
3243
|
+
"usage: /open workspace|artifacts|<recent file> (type /open and a space to browse)",
|
|
3244
|
+
"error"
|
|
3245
|
+
);
|
|
3246
|
+
}
|
|
3247
|
+
try {
|
|
3248
|
+
if (target.type === "folder") {
|
|
3249
|
+
const result = await client.revealProject(projectId, target.folder);
|
|
3250
|
+
note(`opened ${target.folder}: ${result.path}`);
|
|
3251
|
+
} else {
|
|
3252
|
+
const result = await client.revealProjectReference(target.reference.projectId, {
|
|
3253
|
+
kind: target.reference.kind,
|
|
3254
|
+
path: target.reference.path
|
|
3255
|
+
});
|
|
3256
|
+
setRecentOpenReferences(
|
|
3257
|
+
(current) => rememberCliOpenReferences(current, [target.reference])
|
|
3258
|
+
);
|
|
3259
|
+
note(`revealed ${target.reference.path}: ${result.path}`);
|
|
3260
|
+
}
|
|
3261
|
+
} catch (err) {
|
|
3262
|
+
note(`open failed: ${errMsg(err)}`, "error");
|
|
3263
|
+
}
|
|
3264
|
+
return;
|
|
3265
|
+
}
|
|
2429
3266
|
case "task":
|
|
2430
3267
|
setManagedTaskRef(null);
|
|
2431
3268
|
return setOverlay("task");
|
|
@@ -2550,6 +3387,7 @@ function App(props) {
|
|
|
2550
3387
|
[
|
|
2551
3388
|
applyEngagementMode,
|
|
2552
3389
|
applyProjectPermission,
|
|
3390
|
+
applyChatDetailVisibility,
|
|
2553
3391
|
client,
|
|
2554
3392
|
craftbooks,
|
|
2555
3393
|
note,
|
|
@@ -2561,10 +3399,12 @@ function App(props) {
|
|
|
2561
3399
|
projectName,
|
|
2562
3400
|
refreshCraftbooks,
|
|
2563
3401
|
refreshTasks,
|
|
3402
|
+
setRows,
|
|
3403
|
+
setTurns,
|
|
2564
3404
|
startCraftbook
|
|
2565
3405
|
]
|
|
2566
3406
|
);
|
|
2567
|
-
const applyModelSelection =
|
|
3407
|
+
const applyModelSelection = useCallback2(
|
|
2568
3408
|
async (choice) => {
|
|
2569
3409
|
setOverlay(null);
|
|
2570
3410
|
if (!activeGezelId || !activeGezel || !config) return;
|
|
@@ -2594,17 +3434,21 @@ function App(props) {
|
|
|
2594
3434
|
},
|
|
2595
3435
|
[activeGezel, activeGezelId, client, config, ensureSession, note, projectId]
|
|
2596
3436
|
);
|
|
2597
|
-
const applyModelChoice =
|
|
3437
|
+
const applyModelChoice = useCallback2(
|
|
2598
3438
|
async (value2) => {
|
|
2599
3439
|
await applyModelSelection(modelChoices.find((item) => item.value === value2));
|
|
2600
3440
|
},
|
|
2601
3441
|
[applyModelSelection, modelChoices]
|
|
2602
3442
|
);
|
|
2603
|
-
const installModelDownload =
|
|
3443
|
+
const installModelDownload = useCallback2(
|
|
2604
3444
|
async (value2) => {
|
|
2605
3445
|
const choice = modelDownloadChoices.find((candidate) => candidate.value === value2);
|
|
2606
3446
|
if (!choice) return;
|
|
2607
3447
|
let terminalError = null;
|
|
3448
|
+
const companionResult = {
|
|
3449
|
+
name: null,
|
|
3450
|
+
error: null
|
|
3451
|
+
};
|
|
2608
3452
|
setModelDownloadProgress({
|
|
2609
3453
|
choice,
|
|
2610
3454
|
bytesWritten: 0,
|
|
@@ -2614,6 +3458,10 @@ function App(props) {
|
|
|
2614
3458
|
});
|
|
2615
3459
|
const onEvent = (event) => {
|
|
2616
3460
|
if (event.type === "error") terminalError = event.error;
|
|
3461
|
+
if (event.type === "companion") {
|
|
3462
|
+
companionResult.name = event.name;
|
|
3463
|
+
if (event.error) companionResult.error = event.error;
|
|
3464
|
+
}
|
|
2617
3465
|
const progress = readModelDownloadProgress(choice, event);
|
|
2618
3466
|
if (progress) setModelDownloadProgress(progress);
|
|
2619
3467
|
};
|
|
@@ -2638,7 +3486,17 @@ function App(props) {
|
|
|
2638
3486
|
installedChoice
|
|
2639
3487
|
]);
|
|
2640
3488
|
setModelDownloadProgress(null);
|
|
2641
|
-
|
|
3489
|
+
if (companionResult.name && companionResult.error) {
|
|
3490
|
+
note(
|
|
3491
|
+
`downloaded ${choice.model.name}; ${companionResult.name} image reader could not be added: ${companionResult.error}. Switching this gezel to ${choice.model.name}\u2026`
|
|
3492
|
+
);
|
|
3493
|
+
} else if (companionResult.name) {
|
|
3494
|
+
note(
|
|
3495
|
+
`downloaded ${choice.model.name} with ${companionResult.name} for image reading; switching this gezel to it\u2026`
|
|
3496
|
+
);
|
|
3497
|
+
} else {
|
|
3498
|
+
note(`downloaded ${choice.model.name}; switching this gezel to it\u2026`);
|
|
3499
|
+
}
|
|
2642
3500
|
await applyModelSelection(installedChoice);
|
|
2643
3501
|
} catch (err) {
|
|
2644
3502
|
setModelDownloadProgress(null);
|
|
@@ -2648,7 +3506,7 @@ function App(props) {
|
|
|
2648
3506
|
},
|
|
2649
3507
|
[applyModelSelection, client, modelDownloadChoices, note]
|
|
2650
3508
|
);
|
|
2651
|
-
const cancelModelDownload =
|
|
3509
|
+
const cancelModelDownload = useCallback2(async () => {
|
|
2652
3510
|
const progress = modelDownloadProgress;
|
|
2653
3511
|
if (!progress) return;
|
|
2654
3512
|
try {
|
|
@@ -2666,7 +3524,7 @@ function App(props) {
|
|
|
2666
3524
|
else setOverlay(null);
|
|
2667
3525
|
}
|
|
2668
3526
|
}, [client, modelDownloadProgress, modelDownloadReturn, note, openModelPicker]);
|
|
2669
|
-
const onSubmit =
|
|
3527
|
+
const onSubmit = useCallback2(
|
|
2670
3528
|
(raw) => {
|
|
2671
3529
|
setValue("");
|
|
2672
3530
|
const trimmed = raw.trim();
|
|
@@ -2677,7 +3535,7 @@ function App(props) {
|
|
|
2677
3535
|
},
|
|
2678
3536
|
[runInput, pendingInput, taskPrompt]
|
|
2679
3537
|
);
|
|
2680
|
-
const cancelActiveRef =
|
|
3538
|
+
const cancelActiveRef = useRef3(cancelActive);
|
|
2681
3539
|
cancelActiveRef.current = cancelActive;
|
|
2682
3540
|
useInput4(
|
|
2683
3541
|
(input, key) => {
|
|
@@ -2985,7 +3843,7 @@ function App(props) {
|
|
|
2985
3843
|
active: pendingInput === null,
|
|
2986
3844
|
onAnswered: (question) => {
|
|
2987
3845
|
setPendingQuestions((questions) => updatePendingQuestion(questions, question));
|
|
2988
|
-
setFocusedSessionId(question.sessionId);
|
|
3846
|
+
if (question.sessionId) setFocusedSessionId(question.sessionId);
|
|
2989
3847
|
}
|
|
2990
3848
|
},
|
|
2991
3849
|
pendingQuestion.id
|
|
@@ -3006,6 +3864,7 @@ function App(props) {
|
|
|
3006
3864
|
active: overlay === null && (!pendingQuestion || pendingInput !== null || taskPrompt !== null),
|
|
3007
3865
|
history,
|
|
3008
3866
|
craftbooks,
|
|
3867
|
+
recentOpenReferences,
|
|
3009
3868
|
pendingPrompt: pendingInput?.promptLine ?? taskPrompt?.promptLine,
|
|
3010
3869
|
pendingMode: pendingInput?.mode ?? (taskPrompt ? "text" : void 0),
|
|
3011
3870
|
onChange: setValue,
|
|
@@ -3016,15 +3875,17 @@ function App(props) {
|
|
|
3016
3875
|
}
|
|
3017
3876
|
function ModelDownloadProgressPanel(props) {
|
|
3018
3877
|
const { progress, onCancel } = props;
|
|
3878
|
+
const companion = progress.companion;
|
|
3019
3879
|
useInput4((input, key) => {
|
|
3020
3880
|
if (key.escape || key.ctrl && input === "c") onCancel();
|
|
3021
3881
|
});
|
|
3022
3882
|
const transferred = progress.totalBytes ? `${formatModelBytes(progress.bytesWritten)} / ${formatModelBytes(progress.totalBytes)}` : formatModelBytes(progress.bytesWritten);
|
|
3023
3883
|
return /* @__PURE__ */ jsxs6(Box6, { flexDirection: "column", borderStyle: "round", borderColor: "yellow", paddingX: 1, children: [
|
|
3024
|
-
/* @__PURE__ */
|
|
3025
|
-
|
|
3026
|
-
progress.choice.model.name
|
|
3027
|
-
|
|
3884
|
+
/* @__PURE__ */ jsx5(Text6, { bold: true, color: "yellow", children: companion ? `Adding image reader: ${companion.name}` : `Downloading ${progress.choice.model.name}` }),
|
|
3885
|
+
companion ? /* @__PURE__ */ jsxs6(Text6, { children: [
|
|
3886
|
+
progress.choice.model.name,
|
|
3887
|
+
" is ready. This separate helper reads images for it."
|
|
3888
|
+
] }) : null,
|
|
3028
3889
|
/* @__PURE__ */ jsxs6(Text6, { children: [
|
|
3029
3890
|
progress.pct == null ? "Working\u2026" : `${progress.pct}%`,
|
|
3030
3891
|
" \xB7 ",
|
|
@@ -3052,7 +3913,11 @@ function readModelDownloadProgress(choice, event) {
|
|
|
3052
3913
|
bytesWritten: event.bytesWritten,
|
|
3053
3914
|
totalBytes: event.totalBytes,
|
|
3054
3915
|
pct: event.totalBytes > 0 ? Math.min(100, Math.floor(event.bytesWritten / event.totalBytes * 100)) : null,
|
|
3055
|
-
|
|
3916
|
+
companion: {
|
|
3917
|
+
kind: event.kind,
|
|
3918
|
+
id: event.id,
|
|
3919
|
+
name: event.name
|
|
3920
|
+
}
|
|
3056
3921
|
};
|
|
3057
3922
|
}
|
|
3058
3923
|
return null;
|
|
@@ -3164,13 +4029,13 @@ function formatTaskDetails(task, gezels, boring) {
|
|
|
3164
4029
|
// src/tui/components/BootstrapGate.tsx
|
|
3165
4030
|
import { formatModelAttribution as formatModelAttribution3 } from "@bendyline/gezel";
|
|
3166
4031
|
import { Box as Box7, Text as Text7, useApp as useApp2, useInput as useInput5 } from "ink";
|
|
3167
|
-
import { useCallback as
|
|
4032
|
+
import { useCallback as useCallback3, useEffect as useEffect5, useState as useState6 } from "react";
|
|
3168
4033
|
import { Fragment as Fragment4, jsx as jsx6, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
3169
4034
|
var MAX_ALTERNATIVE_MODELS = 6;
|
|
3170
4035
|
function BootstrapGate(props) {
|
|
3171
4036
|
const { client, children } = props;
|
|
3172
4037
|
const { exit } = useApp2();
|
|
3173
|
-
const [screen, setScreen] =
|
|
4038
|
+
const [screen, setScreen] = useState6({
|
|
3174
4039
|
kind: "loading",
|
|
3175
4040
|
message: "Checking this device\u2026"
|
|
3176
4041
|
});
|
|
@@ -3184,7 +4049,7 @@ function BootstrapGate(props) {
|
|
|
3184
4049
|
// deliberate second-press exit.
|
|
3185
4050
|
{ isActive: screen.kind !== "ready" }
|
|
3186
4051
|
);
|
|
3187
|
-
const prepareModels =
|
|
4052
|
+
const prepareModels = useCallback3(
|
|
3188
4053
|
async (context) => {
|
|
3189
4054
|
setScreen({ kind: "loading", message: "Finding the best models for this device\u2026" });
|
|
3190
4055
|
const installedChat = context.provider === "mlx" ? await client.listMlxModels() : await client.listLlamaCppModels();
|
|
@@ -3267,7 +4132,7 @@ function BootstrapGate(props) {
|
|
|
3267
4132
|
},
|
|
3268
4133
|
[client]
|
|
3269
4134
|
);
|
|
3270
|
-
const initialize =
|
|
4135
|
+
const initialize = useCallback3(async () => {
|
|
3271
4136
|
try {
|
|
3272
4137
|
setScreen({ kind: "loading", message: "Checking this device\u2026" });
|
|
3273
4138
|
const [memory, chatCatalog] = await Promise.all([
|
|
@@ -3310,10 +4175,10 @@ function BootstrapGate(props) {
|
|
|
3310
4175
|
});
|
|
3311
4176
|
}
|
|
3312
4177
|
}, [client, prepareModels]);
|
|
3313
|
-
|
|
4178
|
+
useEffect5(() => {
|
|
3314
4179
|
void initialize();
|
|
3315
4180
|
}, [initialize]);
|
|
3316
|
-
const installNative =
|
|
4181
|
+
const installNative = useCallback3(
|
|
3317
4182
|
async (context, missing) => {
|
|
3318
4183
|
const retry = () => void installNative(context, missing);
|
|
3319
4184
|
if (!context.nativeStatus.pinned) {
|
|
@@ -3346,7 +4211,7 @@ function BootstrapGate(props) {
|
|
|
3346
4211
|
},
|
|
3347
4212
|
[client, prepareModels]
|
|
3348
4213
|
);
|
|
3349
|
-
const installModels =
|
|
4214
|
+
const installModels = useCallback3(
|
|
3350
4215
|
async (plan, choice) => {
|
|
3351
4216
|
if (choice.kind === "skip") {
|
|
3352
4217
|
setScreen({ kind: "ready" });
|
|
@@ -3481,11 +4346,12 @@ function BootstrapGate(props) {
|
|
|
3481
4346
|
0
|
|
3482
4347
|
);
|
|
3483
4348
|
const workshopDownloadBytes = accessoryBytes + (best && !bestInstalled ? best.approxSizeBytes : 0);
|
|
4349
|
+
const workshopHelperLabels = screen.plan.accessories.map(accessoryKindLabel).join(", ");
|
|
3484
4350
|
const options = [
|
|
3485
4351
|
...best ? [
|
|
3486
4352
|
{
|
|
3487
4353
|
label: `Recommended workshop set \u2014 ${bootstrapChatModelLabel(best)} + ${screen.plan.accessories.length} helpers`,
|
|
3488
|
-
hint: `${bestInstalled ? "chat model already available \xB7 " : ""}${workshopDownloadBytes > 0 ? formatDownloadSize(workshopDownloadBytes) : "already available"}`,
|
|
4354
|
+
hint: `${bestInstalled ? "chat model already available \xB7 " : ""}${workshopDownloadBytes > 0 ? formatDownloadSize(workshopDownloadBytes) : "already available"}${workshopHelperLabels ? ` \xB7 includes ${workshopHelperLabels}` : ""}`,
|
|
3489
4355
|
value: "bundle"
|
|
3490
4356
|
},
|
|
3491
4357
|
{
|
|
@@ -3586,7 +4452,7 @@ function recoDevice(memory) {
|
|
|
3586
4452
|
};
|
|
3587
4453
|
}
|
|
3588
4454
|
function BootstrapChoiceList(props) {
|
|
3589
|
-
const [index, setIndex] =
|
|
4455
|
+
const [index, setIndex] = useState6(0);
|
|
3590
4456
|
const options = props.options;
|
|
3591
4457
|
useInput5((input, key) => {
|
|
3592
4458
|
if (key.upArrow) {
|
|
@@ -3674,7 +4540,9 @@ async function installChatModel(client, model, onEvent) {
|
|
|
3674
4540
|
if (model.provider === "mlx") {
|
|
3675
4541
|
await client.installMlxModel(model.id, listener);
|
|
3676
4542
|
} else {
|
|
3677
|
-
await client.installLlamaCppModel(model.id, listener
|
|
4543
|
+
await client.installLlamaCppModel(model.id, listener, void 0, {
|
|
4544
|
+
skipCompanion: true
|
|
4545
|
+
});
|
|
3678
4546
|
}
|
|
3679
4547
|
if (terminalError) throw new Error(terminalError);
|
|
3680
4548
|
}
|
|
@@ -3695,7 +4563,7 @@ async function installAccessory(client, model, onEvent) {
|
|
|
3695
4563
|
}
|
|
3696
4564
|
if (terminalError) throw new Error(terminalError);
|
|
3697
4565
|
}
|
|
3698
|
-
function updateDownloadProgress(setScreen, job, index, total, event, title = "
|
|
4566
|
+
function updateDownloadProgress(setScreen, job, index, total, event, title = "Downloading local models from Hugging Face (huggingface.co)") {
|
|
3699
4567
|
let pct = null;
|
|
3700
4568
|
let detail = job.label;
|
|
3701
4569
|
if (event.type === "progress") {
|
|
@@ -3708,7 +4576,24 @@ function updateDownloadProgress(setScreen, job, index, total, event, title = "In
|
|
|
3708
4576
|
} else if (event.type === "retrying" && "attempt" in event) {
|
|
3709
4577
|
detail = `${job.label} \xB7 retrying ${event.attempt}/${event.maxAttempts}`;
|
|
3710
4578
|
} else if (event.type === "verifying") {
|
|
4579
|
+
pct = 100;
|
|
3711
4580
|
detail = `${job.label} \xB7 verifying`;
|
|
4581
|
+
} else if (event.type === "extracting-metadata") {
|
|
4582
|
+
pct = 100;
|
|
4583
|
+
detail = `${job.label} \xB7 reading model details`;
|
|
4584
|
+
} else if (event.type === "companion") {
|
|
4585
|
+
const name = "name" in event && typeof event.name === "string" ? event.name : "Image reader";
|
|
4586
|
+
const written = event.bytesWritten;
|
|
4587
|
+
const all = event.totalBytes;
|
|
4588
|
+
if (typeof written === "number" && typeof all === "number" && all > 0) {
|
|
4589
|
+
pct = Math.min(100, Math.floor(written / all * 100));
|
|
4590
|
+
detail = `${name} \xB7 image reader \xB7 ${formatDownloadSize(written)} of ${formatDownloadSize(all)}`;
|
|
4591
|
+
} else {
|
|
4592
|
+
detail = `${name} \xB7 image reader`;
|
|
4593
|
+
}
|
|
4594
|
+
if ("error" in event && typeof event.error === "string") {
|
|
4595
|
+
detail = `${name} \xB7 image reader unavailable: ${event.error}`;
|
|
4596
|
+
}
|
|
3712
4597
|
} else if (event.type === "done") {
|
|
3713
4598
|
pct = 100;
|
|
3714
4599
|
detail = `${job.label} \xB7 ready`;
|
|
@@ -3747,6 +4632,20 @@ function nativeLabel(engine) {
|
|
|
3747
4632
|
return "ds4";
|
|
3748
4633
|
}
|
|
3749
4634
|
}
|
|
4635
|
+
function accessoryKindLabel(model) {
|
|
4636
|
+
switch (model.kind) {
|
|
4637
|
+
case "image":
|
|
4638
|
+
return "image generator";
|
|
4639
|
+
case "recognition":
|
|
4640
|
+
return "image reader";
|
|
4641
|
+
case "stt":
|
|
4642
|
+
return "speech recognition";
|
|
4643
|
+
case "tts":
|
|
4644
|
+
return "voice";
|
|
4645
|
+
case "video":
|
|
4646
|
+
return "video generator";
|
|
4647
|
+
}
|
|
4648
|
+
}
|
|
3750
4649
|
function fitLabel(fit) {
|
|
3751
4650
|
if (fit === "fits-offload") return "fits with offload";
|
|
3752
4651
|
if (fit === "fits") return "good fit";
|
|
@@ -3760,14 +4659,149 @@ function delay(ms) {
|
|
|
3760
4659
|
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
3761
4660
|
}
|
|
3762
4661
|
|
|
4662
|
+
// src/tui/memory-diagnostics.ts
|
|
4663
|
+
import { appendFile, mkdir as mkdir2 } from "fs/promises";
|
|
4664
|
+
import { join as join2 } from "path";
|
|
4665
|
+
import { performance } from "perf_hooks";
|
|
4666
|
+
import { getHeapStatistics } from "v8";
|
|
4667
|
+
import { gezelHome, gezelPaths as gezelPaths2 } from "@bendyline/gezel/paths";
|
|
4668
|
+
var DEFAULT_SAMPLE_INTERVAL_MS = 15e3;
|
|
4669
|
+
var DEFAULT_MEASURE_LIMIT = 2e3;
|
|
4670
|
+
var DEFAULT_PRESSURE_HEAP_BYTES = 256 * 1024 * 1024;
|
|
4671
|
+
var DEFAULT_GROWTH_LOG_BYTES = 64 * 1024 * 1024;
|
|
4672
|
+
var COMMIT_CLEANUP_INTERVAL = 250;
|
|
4673
|
+
function clearRetainedPerformanceMeasures(timeline = performance, limit = DEFAULT_MEASURE_LIMIT) {
|
|
4674
|
+
const count = timeline.getEntriesByType("measure").length;
|
|
4675
|
+
if (count <= limit) return 0;
|
|
4676
|
+
timeline.clearMeasures();
|
|
4677
|
+
return count;
|
|
4678
|
+
}
|
|
4679
|
+
function startTuiRuntimeDiagnostics(options = {}) {
|
|
4680
|
+
const home = options.home ?? gezelHome();
|
|
4681
|
+
const logsDir = gezelPaths2(home).logs;
|
|
4682
|
+
const timeline = options.timeline ?? performance;
|
|
4683
|
+
const measureLimit = options.performanceMeasureLimit ?? DEFAULT_MEASURE_LIMIT;
|
|
4684
|
+
const pressureHeapBytes = options.pressureHeapBytes ?? DEFAULT_PRESSURE_HEAP_BYTES;
|
|
4685
|
+
const growthLogBytes = options.growthLogBytes ?? DEFAULT_GROWTH_LOG_BYTES;
|
|
4686
|
+
const alwaysLog = options.alwaysLog ?? process.env.GEZEL_TUI_MEMORY_DIAGNOSTICS?.trim() === "1";
|
|
4687
|
+
const eventTypes = {};
|
|
4688
|
+
const counters = {
|
|
4689
|
+
chatEvents: 0,
|
|
4690
|
+
streamFragments: 0,
|
|
4691
|
+
streamChars: 0,
|
|
4692
|
+
terminalEvents: 0,
|
|
4693
|
+
terminalChunks: 0,
|
|
4694
|
+
terminalChars: 0,
|
|
4695
|
+
reactCommits: 0
|
|
4696
|
+
};
|
|
4697
|
+
let stopped = false;
|
|
4698
|
+
let lastLoggedHeapUsed = 0;
|
|
4699
|
+
let peakHeapUsed = 0;
|
|
4700
|
+
let peakRss = 0;
|
|
4701
|
+
let writeChain = Promise.resolve();
|
|
4702
|
+
const sample = (phase, force = false, measuresCleared = 0) => {
|
|
4703
|
+
const memory = process.memoryUsage();
|
|
4704
|
+
const heap = getHeapStatistics();
|
|
4705
|
+
peakHeapUsed = Math.max(peakHeapUsed, memory.heapUsed);
|
|
4706
|
+
peakRss = Math.max(peakRss, memory.rss);
|
|
4707
|
+
const performanceMeasures = timeline.getEntriesByType("measure").length;
|
|
4708
|
+
const cleared = measuresCleared || clearRetainedPerformanceMeasures(timeline, measureLimit);
|
|
4709
|
+
const shouldWrite = force || alwaysLog || cleared > 0 || memory.heapUsed >= pressureHeapBytes || memory.heapUsed - lastLoggedHeapUsed >= growthLogBytes;
|
|
4710
|
+
if (!shouldWrite) return;
|
|
4711
|
+
lastLoggedHeapUsed = memory.heapUsed;
|
|
4712
|
+
const at = (/* @__PURE__ */ new Date()).toISOString();
|
|
4713
|
+
const record = {
|
|
4714
|
+
type: "tui.memory",
|
|
4715
|
+
version: 1,
|
|
4716
|
+
at,
|
|
4717
|
+
phase,
|
|
4718
|
+
pid: process.pid,
|
|
4719
|
+
nodeEnv: process.env.NODE_ENV ?? null,
|
|
4720
|
+
nodeVersion: process.version,
|
|
4721
|
+
uptimeMs: Math.round(process.uptime() * 1e3),
|
|
4722
|
+
memory: {
|
|
4723
|
+
rss: memory.rss,
|
|
4724
|
+
heapUsed: memory.heapUsed,
|
|
4725
|
+
heapTotal: memory.heapTotal,
|
|
4726
|
+
external: memory.external,
|
|
4727
|
+
arrayBuffers: memory.arrayBuffers,
|
|
4728
|
+
peakHeapUsed,
|
|
4729
|
+
peakRss,
|
|
4730
|
+
heapSizeLimit: heap.heap_size_limit,
|
|
4731
|
+
totalAvailableSize: heap.total_available_size,
|
|
4732
|
+
mallocedMemory: heap.malloced_memory,
|
|
4733
|
+
peakMallocedMemory: heap.peak_malloced_memory,
|
|
4734
|
+
nativeContexts: heap.number_of_native_contexts,
|
|
4735
|
+
detachedContexts: heap.number_of_detached_contexts
|
|
4736
|
+
},
|
|
4737
|
+
activeResources: countActiveResources(),
|
|
4738
|
+
performanceMeasures,
|
|
4739
|
+
measuresCleared: cleared,
|
|
4740
|
+
counters: { ...counters },
|
|
4741
|
+
eventTypes: { ...eventTypes }
|
|
4742
|
+
};
|
|
4743
|
+
const file = join2(logsDir, `tui-memory-${at.slice(0, 10)}.jsonl`);
|
|
4744
|
+
writeChain = writeChain.then(async () => {
|
|
4745
|
+
await mkdir2(logsDir, { recursive: true });
|
|
4746
|
+
await appendFile(file, `${JSON.stringify(record)}
|
|
4747
|
+
`, "utf8");
|
|
4748
|
+
}).catch(() => void 0);
|
|
4749
|
+
};
|
|
4750
|
+
sample("startup", true);
|
|
4751
|
+
const interval = setInterval(
|
|
4752
|
+
() => sample("interval"),
|
|
4753
|
+
options.intervalMs ?? DEFAULT_SAMPLE_INTERVAL_MS
|
|
4754
|
+
);
|
|
4755
|
+
interval.unref();
|
|
4756
|
+
return {
|
|
4757
|
+
recordChatEvent(env) {
|
|
4758
|
+
counters.chatEvents += 1;
|
|
4759
|
+
eventTypes[env.event.type] = (eventTypes[env.event.type] ?? 0) + 1;
|
|
4760
|
+
if (env.event.type === "delta" || env.event.type === "reasoning_delta" || env.event.type === "tool_args_delta") {
|
|
4761
|
+
counters.streamFragments += 1;
|
|
4762
|
+
counters.streamChars += env.event.content.length;
|
|
4763
|
+
}
|
|
4764
|
+
},
|
|
4765
|
+
recordTerminalEvent(env) {
|
|
4766
|
+
counters.terminalEvents += 1;
|
|
4767
|
+
if (env.kind === "outputChunk") {
|
|
4768
|
+
counters.terminalChunks += 1;
|
|
4769
|
+
counters.terminalChars += env.chunk.length;
|
|
4770
|
+
}
|
|
4771
|
+
},
|
|
4772
|
+
recordReactCommit() {
|
|
4773
|
+
counters.reactCommits += 1;
|
|
4774
|
+
if (counters.reactCommits % COMMIT_CLEANUP_INTERVAL !== 0) return;
|
|
4775
|
+
const cleared = clearRetainedPerformanceMeasures(timeline, measureLimit);
|
|
4776
|
+
if (cleared > 0) sample("performance_cleanup", true, cleared);
|
|
4777
|
+
},
|
|
4778
|
+
async stop() {
|
|
4779
|
+
if (stopped) return;
|
|
4780
|
+
stopped = true;
|
|
4781
|
+
clearInterval(interval);
|
|
4782
|
+
sample("shutdown", true);
|
|
4783
|
+
await writeChain;
|
|
4784
|
+
}
|
|
4785
|
+
};
|
|
4786
|
+
}
|
|
4787
|
+
function countActiveResources() {
|
|
4788
|
+
const counts = {};
|
|
4789
|
+
for (const resource of process.getActiveResourcesInfo()) {
|
|
4790
|
+
counts[resource] = (counts[resource] ?? 0) + 1;
|
|
4791
|
+
}
|
|
4792
|
+
return counts;
|
|
4793
|
+
}
|
|
4794
|
+
|
|
3763
4795
|
// src/tui/index.tsx
|
|
3764
4796
|
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
3765
4797
|
async function launchTui(opts) {
|
|
4798
|
+
const diagnostics = startTuiRuntimeDiagnostics();
|
|
3766
4799
|
const instance = render(
|
|
3767
4800
|
/* @__PURE__ */ jsx7(BootstrapGate, { client: opts.client, children: /* @__PURE__ */ jsx7(
|
|
3768
4801
|
App,
|
|
3769
4802
|
{
|
|
3770
4803
|
client: opts.client,
|
|
4804
|
+
diagnostics,
|
|
3771
4805
|
initialProjectId: opts.projectId,
|
|
3772
4806
|
initialProjectName: opts.projectName,
|
|
3773
4807
|
initialGezelId: opts.gezelId
|
|
@@ -3776,7 +4810,11 @@ async function launchTui(opts) {
|
|
|
3776
4810
|
// We own Ctrl+C (interrupt-then-exit); don't let ink exit on the first press.
|
|
3777
4811
|
{ exitOnCtrlC: false }
|
|
3778
4812
|
);
|
|
3779
|
-
|
|
4813
|
+
try {
|
|
4814
|
+
await instance.waitUntilExit();
|
|
4815
|
+
} finally {
|
|
4816
|
+
await diagnostics.stop();
|
|
4817
|
+
}
|
|
3780
4818
|
}
|
|
3781
4819
|
export {
|
|
3782
4820
|
launchTui
|