@vibest/cli 0.0.1-beta.19 → 0.0.1-beta.20
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/bin/vibest.cjs +23 -13
- package/harnesses/agy/.agents/plugins/vibest/hook.sh +48 -0
- package/harnesses/agy/.agents/plugins/vibest/hooks.json +38 -0
- package/harnesses/agy/.agents/plugins/vibest/plugin.json +5 -0
- package/harnesses/agy/.agents/plugins/vibest/skills/delegate/SKILL.md +66 -0
- package/harnesses/agy/.agents/plugins/vibest/skills/pipeline/SKILL.md +57 -0
- package/harnesses/agy/index.js +1405 -0
- package/harnesses/claude/.claude-plugin/plugin.json +2 -2
- package/harnesses/claude/README.md +17 -17
- package/harnesses/claude/hooks/hooks.json +1 -1
- package/harnesses/claude/hooks/register.mjs +154 -101
- package/harnesses/claude/skills/delegate/SKILL.md +18 -18
- package/harnesses/claude/skills/pipeline/SKILL.md +14 -14
- package/harnesses/cursor/.cursor-plugin/plugin.json +2 -2
- package/harnesses/cursor/hooks/hooks.json +3 -0
- package/harnesses/cursor/hooks/vibest.sh +3 -3
- package/harnesses/cursor/index.js +1340 -0
- package/harnesses/cursor/skills/delegate/SKILL.md +18 -18
- package/harnesses/cursor/skills/pipeline/SKILL.md +14 -14
- package/harnesses/pi/extension.mjs +643 -1112
- package/harnesses/pi/presentation.mjs +1023 -0
- package/harnesses/pi/skills/delegate/SKILL.md +18 -18
- package/harnesses/pi/skills/pipeline/SKILL.md +14 -14
- package/herdr-plugin/README.md +2 -2
- package/herdr-plugin/bin/vibest.sh +1 -1
- package/herdr-plugin/herdr-plugin.toml +5 -5
- package/package.json +17 -16
|
@@ -0,0 +1,1023 @@
|
|
|
1
|
+
// src/presentation.ts
|
|
2
|
+
import { UserMessageComponent } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
import { TuiAltScreen } from "@earendil-works/pi-tui";
|
|
4
|
+
|
|
5
|
+
// src/tui/tool-groups.ts
|
|
6
|
+
import { truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
7
|
+
|
|
8
|
+
// ../../../node_modules/.pnpm/effect@4.0.2/node_modules/effect/dist/Pipeable.js
|
|
9
|
+
var pipeArguments = (self, args) => {
|
|
10
|
+
switch (args.length) {
|
|
11
|
+
case 0:
|
|
12
|
+
return self;
|
|
13
|
+
case 1:
|
|
14
|
+
return args[0](self);
|
|
15
|
+
case 2:
|
|
16
|
+
return args[1](args[0](self));
|
|
17
|
+
case 3:
|
|
18
|
+
return args[2](args[1](args[0](self)));
|
|
19
|
+
case 4:
|
|
20
|
+
return args[3](args[2](args[1](args[0](self))));
|
|
21
|
+
case 5:
|
|
22
|
+
return args[4](args[3](args[2](args[1](args[0](self)))));
|
|
23
|
+
case 6:
|
|
24
|
+
return args[5](args[4](args[3](args[2](args[1](args[0](self))))));
|
|
25
|
+
case 7:
|
|
26
|
+
return args[6](args[5](args[4](args[3](args[2](args[1](args[0](self)))))));
|
|
27
|
+
case 8:
|
|
28
|
+
return args[7](args[6](args[5](args[4](args[3](args[2](args[1](args[0](self))))))));
|
|
29
|
+
case 9:
|
|
30
|
+
return args[8](args[7](args[6](args[5](args[4](args[3](args[2](args[1](args[0](self)))))))));
|
|
31
|
+
default: {
|
|
32
|
+
let ret = self;
|
|
33
|
+
for (let i = 0, len = args.length;i < len; i++) {
|
|
34
|
+
ret = args[i](ret);
|
|
35
|
+
}
|
|
36
|
+
return ret;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
var Prototype = {
|
|
41
|
+
pipe() {
|
|
42
|
+
return pipeArguments(this, arguments);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
var Class = /* @__PURE__ */ function() {
|
|
46
|
+
function PipeableBase() {}
|
|
47
|
+
PipeableBase.prototype = Prototype;
|
|
48
|
+
return PipeableBase;
|
|
49
|
+
}();
|
|
50
|
+
|
|
51
|
+
// ../../../node_modules/.pnpm/effect@4.0.2/node_modules/effect/dist/Function.js
|
|
52
|
+
var dual = function(arity, body) {
|
|
53
|
+
if (typeof arity === "function") {
|
|
54
|
+
return function() {
|
|
55
|
+
return arity(arguments) ? body.apply(this, arguments) : (self) => body(self, ...arguments);
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
switch (arity) {
|
|
59
|
+
case 0:
|
|
60
|
+
case 1:
|
|
61
|
+
throw new RangeError(`Invalid arity ${arity}`);
|
|
62
|
+
case 2:
|
|
63
|
+
return function(a, b) {
|
|
64
|
+
if (arguments.length >= 2) {
|
|
65
|
+
return body(a, b);
|
|
66
|
+
}
|
|
67
|
+
return function(self) {
|
|
68
|
+
return body(self, a);
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
case 3:
|
|
72
|
+
return function(a, b, c) {
|
|
73
|
+
if (arguments.length >= 3) {
|
|
74
|
+
return body(a, b, c);
|
|
75
|
+
}
|
|
76
|
+
return function(self) {
|
|
77
|
+
return body(self, a, b);
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
default:
|
|
81
|
+
return function() {
|
|
82
|
+
if (arguments.length >= arity) {
|
|
83
|
+
return body.apply(this, arguments);
|
|
84
|
+
}
|
|
85
|
+
const args = arguments;
|
|
86
|
+
return function(self) {
|
|
87
|
+
return body(self, ...args);
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
var identity = (a) => a;
|
|
93
|
+
var constant = (value) => () => value;
|
|
94
|
+
var constTrue = /* @__PURE__ */ constant(true);
|
|
95
|
+
var constFalse = /* @__PURE__ */ constant(false);
|
|
96
|
+
var constUndefined = /* @__PURE__ */ constant(undefined);
|
|
97
|
+
var constVoid = constUndefined;
|
|
98
|
+
function pipe(a, ...args) {
|
|
99
|
+
return pipeArguments(a, args);
|
|
100
|
+
}
|
|
101
|
+
function memoize(f) {
|
|
102
|
+
const cache = new WeakMap;
|
|
103
|
+
return (a) => {
|
|
104
|
+
const cached = cache.get(a);
|
|
105
|
+
if (cached !== undefined)
|
|
106
|
+
return cached;
|
|
107
|
+
const result = f(a);
|
|
108
|
+
cache.set(a, result);
|
|
109
|
+
return result;
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function memoizeIdempotent(f) {
|
|
113
|
+
const cache = new WeakMap;
|
|
114
|
+
return (a) => {
|
|
115
|
+
const cached = cache.get(a);
|
|
116
|
+
if (cached !== undefined)
|
|
117
|
+
return cached;
|
|
118
|
+
const result = f(a);
|
|
119
|
+
cache.set(a, result);
|
|
120
|
+
if (result !== a) {
|
|
121
|
+
cache.set(result, result);
|
|
122
|
+
}
|
|
123
|
+
return result;
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// ../../../node_modules/.pnpm/effect@4.0.2/node_modules/effect/dist/Predicate.js
|
|
128
|
+
function isString(input) {
|
|
129
|
+
return typeof input === "string";
|
|
130
|
+
}
|
|
131
|
+
function isNumber(input) {
|
|
132
|
+
return typeof input === "number";
|
|
133
|
+
}
|
|
134
|
+
function isBoolean(input) {
|
|
135
|
+
return typeof input === "boolean";
|
|
136
|
+
}
|
|
137
|
+
function isSymbol(input) {
|
|
138
|
+
return typeof input === "symbol";
|
|
139
|
+
}
|
|
140
|
+
function isPropertyKey(u) {
|
|
141
|
+
return isString(u) || isNumber(u) || isSymbol(u);
|
|
142
|
+
}
|
|
143
|
+
function isFunction(input) {
|
|
144
|
+
return typeof input === "function";
|
|
145
|
+
}
|
|
146
|
+
function isUndefined(input) {
|
|
147
|
+
return input === undefined;
|
|
148
|
+
}
|
|
149
|
+
function isNotUndefined(input) {
|
|
150
|
+
return input !== undefined;
|
|
151
|
+
}
|
|
152
|
+
function isNotNull(input) {
|
|
153
|
+
return input !== null;
|
|
154
|
+
}
|
|
155
|
+
function isNullish(input) {
|
|
156
|
+
return input === null || input === undefined;
|
|
157
|
+
}
|
|
158
|
+
function isNotNullish(input) {
|
|
159
|
+
return input != null;
|
|
160
|
+
}
|
|
161
|
+
function isNever(_) {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
function isUnknown(_) {
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
function isObjectOrArray(input) {
|
|
168
|
+
return typeof input === "object" && input !== null;
|
|
169
|
+
}
|
|
170
|
+
function isObject(input) {
|
|
171
|
+
return typeof input === "object" && input !== null && !Array.isArray(input);
|
|
172
|
+
}
|
|
173
|
+
function isObjectKeyword(input) {
|
|
174
|
+
return typeof input === "object" && input !== null || isFunction(input);
|
|
175
|
+
}
|
|
176
|
+
var hasProperty = /* @__PURE__ */ dual(2, (self, property) => isObjectKeyword(self) && (property in self));
|
|
177
|
+
var isTagged = /* @__PURE__ */ dual(2, (self, tag) => hasProperty(self, "_tag") && self["_tag"] === tag);
|
|
178
|
+
function isError(input) {
|
|
179
|
+
return input instanceof Error;
|
|
180
|
+
}
|
|
181
|
+
function isIterable(input) {
|
|
182
|
+
return hasProperty(input, Symbol.iterator) || isString(input);
|
|
183
|
+
}
|
|
184
|
+
// src/tui/tool-groups.ts
|
|
185
|
+
var isFields = (value) => isObjectOrArray(value) && !Array.isArray(value);
|
|
186
|
+
var isMessage = (value) => isObjectOrArray(value);
|
|
187
|
+
var PREFERRED_ARGS = new Map([
|
|
188
|
+
["read", ["path", "file_path"]],
|
|
189
|
+
["write", ["path", "file_path"]],
|
|
190
|
+
["edit", ["path", "file_path"]],
|
|
191
|
+
["ls", ["path"]],
|
|
192
|
+
["bash", ["command"]],
|
|
193
|
+
["powershell", ["command"]],
|
|
194
|
+
["grep", ["pattern"]],
|
|
195
|
+
["find", ["pattern", "path"]],
|
|
196
|
+
["tool_search", ["query"]]
|
|
197
|
+
]);
|
|
198
|
+
function tool_groups_default(pi) {
|
|
199
|
+
let open = null;
|
|
200
|
+
let runActive = false;
|
|
201
|
+
const groups = [];
|
|
202
|
+
const byId = new Map;
|
|
203
|
+
const calls = new Map;
|
|
204
|
+
const invalidators = new Map;
|
|
205
|
+
const expandedById = new Map;
|
|
206
|
+
let bodyGroup = new WeakMap;
|
|
207
|
+
let replaying = false;
|
|
208
|
+
function gutter(width, outputPad) {
|
|
209
|
+
const room = Math.max(1, Math.floor(width) || 1);
|
|
210
|
+
let pad = Math.max(0, Math.floor(Number(outputPad) || 0));
|
|
211
|
+
if (pad * 2 >= room)
|
|
212
|
+
pad = Math.max(0, Math.floor((room - 1) / 2));
|
|
213
|
+
return { pad, limit: Math.max(1, room - pad * 2) };
|
|
214
|
+
}
|
|
215
|
+
function indent(lines, pad) {
|
|
216
|
+
if (!pad)
|
|
217
|
+
return lines;
|
|
218
|
+
const prefix = " ".repeat(pad);
|
|
219
|
+
return lines.map((line) => prefix + line);
|
|
220
|
+
}
|
|
221
|
+
function frameLines(renderers, component, width, outputPad) {
|
|
222
|
+
if (renderers?.renderShell === "self")
|
|
223
|
+
return component.render(width);
|
|
224
|
+
const { pad, limit } = gutter(width, outputPad);
|
|
225
|
+
return indent(component.render(limit), pad);
|
|
226
|
+
}
|
|
227
|
+
function frameComponent(renderers, component, outputPad) {
|
|
228
|
+
if (renderers?.renderShell === "self")
|
|
229
|
+
return component;
|
|
230
|
+
return {
|
|
231
|
+
invalidate() {
|
|
232
|
+
component.invalidate?.();
|
|
233
|
+
},
|
|
234
|
+
render(width) {
|
|
235
|
+
return frameLines(renderers, component, width, outputPad);
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
function wrapText(text, width) {
|
|
240
|
+
return wrapTextWithAnsi(String(text ?? ""), Math.max(1, width || 1));
|
|
241
|
+
}
|
|
242
|
+
function oneLine(text, limit) {
|
|
243
|
+
const flat = String(text ?? "").replace(/\s+/g, " ").trim();
|
|
244
|
+
if (!flat)
|
|
245
|
+
return "";
|
|
246
|
+
if (flat.length <= limit)
|
|
247
|
+
return flat;
|
|
248
|
+
return flat.slice(0, Math.max(1, limit - 1)) + "…";
|
|
249
|
+
}
|
|
250
|
+
function primaryArg(name, args) {
|
|
251
|
+
if (args === undefined || args === null)
|
|
252
|
+
return "";
|
|
253
|
+
if (!isFields(args))
|
|
254
|
+
return oneLine(isString(args) ? args : JSON.stringify(args), 40);
|
|
255
|
+
const preferred = PREFERRED_ARGS.get(name) ?? ["path", "file_path", "command", "query", "pattern", "url"];
|
|
256
|
+
const sensitive = /token|secret|password|authorization|credential|api[_-]?key/i;
|
|
257
|
+
for (const key of preferred) {
|
|
258
|
+
if (sensitive.test(key))
|
|
259
|
+
continue;
|
|
260
|
+
const value = args[key];
|
|
261
|
+
if (isString(value) && value)
|
|
262
|
+
return oneLine(value, 40);
|
|
263
|
+
}
|
|
264
|
+
for (const [key, value] of Object.entries(args)) {
|
|
265
|
+
if (sensitive.test(key) || key === "script" || key === "content" || key === "edits")
|
|
266
|
+
continue;
|
|
267
|
+
if (isString(value) && value)
|
|
268
|
+
return oneLine(value, 40);
|
|
269
|
+
}
|
|
270
|
+
return "";
|
|
271
|
+
}
|
|
272
|
+
function resultText(result) {
|
|
273
|
+
const texts = [];
|
|
274
|
+
if (Array.isArray(result?.content)) {
|
|
275
|
+
for (const part of result.content)
|
|
276
|
+
if (part?.type === "text" && part.text)
|
|
277
|
+
texts.push(part.text);
|
|
278
|
+
}
|
|
279
|
+
const line = texts.join(`
|
|
280
|
+
`).split(`
|
|
281
|
+
`).find((item) => item.trim()) ?? "";
|
|
282
|
+
return line.trim();
|
|
283
|
+
}
|
|
284
|
+
function compactText(member, limit) {
|
|
285
|
+
const extra = calls.get(member.id);
|
|
286
|
+
const name = member.name || extra?.name || member.id;
|
|
287
|
+
const arg = primaryArg(name, member.args ?? extra?.args);
|
|
288
|
+
const isError = member.isError || extra?.isError;
|
|
289
|
+
const text = resultText(member.result ?? extra?.result);
|
|
290
|
+
const summary = isError ? text ? "Error · " + oneLine(text, 40) : "Error" : oneLine(text, 40);
|
|
291
|
+
let line = arg ? name + " " + arg : name;
|
|
292
|
+
if (summary)
|
|
293
|
+
line += " · " + summary;
|
|
294
|
+
return wrapTextWithAnsi(line, limit);
|
|
295
|
+
}
|
|
296
|
+
function nestedLines(parentId, limit) {
|
|
297
|
+
const lines = [];
|
|
298
|
+
for (const call of calls.values()) {
|
|
299
|
+
if (call.parentId !== parentId || byId.has(call.id))
|
|
300
|
+
continue;
|
|
301
|
+
lines.push(...compactText(call, limit));
|
|
302
|
+
}
|
|
303
|
+
return lines;
|
|
304
|
+
}
|
|
305
|
+
function showNative(ctx, group) {
|
|
306
|
+
if (ctx?.expanded !== true || !group)
|
|
307
|
+
return false;
|
|
308
|
+
if (group.members.length < 2)
|
|
309
|
+
return true;
|
|
310
|
+
if (group.members[0]?.id !== ctx.toolCallId)
|
|
311
|
+
return true;
|
|
312
|
+
return group.members.every((member) => expandedById.get(member.id) === true);
|
|
313
|
+
}
|
|
314
|
+
function plainCall(name, args, width) {
|
|
315
|
+
const lines = wrapText(name, width);
|
|
316
|
+
if (isFields(args)) {
|
|
317
|
+
for (const [key, value] of Object.entries(args)) {
|
|
318
|
+
const shown = isString(value) ? value : JSON.stringify(value);
|
|
319
|
+
lines.push(...wrapText(key + ": " + shown, width));
|
|
320
|
+
}
|
|
321
|
+
} else if (args !== undefined) {
|
|
322
|
+
lines.push(...wrapText(JSON.stringify(args), width));
|
|
323
|
+
}
|
|
324
|
+
return lines;
|
|
325
|
+
}
|
|
326
|
+
function plainResult(result, isError, width) {
|
|
327
|
+
const texts = [];
|
|
328
|
+
if (Array.isArray(result?.content)) {
|
|
329
|
+
for (const part of result.content)
|
|
330
|
+
if (part?.type === "text" && part.text)
|
|
331
|
+
texts.push(part.text);
|
|
332
|
+
}
|
|
333
|
+
const lines = [];
|
|
334
|
+
if (isError)
|
|
335
|
+
lines.push(...wrapText("Error", width));
|
|
336
|
+
lines.push(...wrapText(texts.join(`
|
|
337
|
+
`), width));
|
|
338
|
+
return lines.filter((line) => line !== "");
|
|
339
|
+
}
|
|
340
|
+
function reset() {
|
|
341
|
+
open = null;
|
|
342
|
+
groups.length = 0;
|
|
343
|
+
byId.clear();
|
|
344
|
+
calls.clear();
|
|
345
|
+
expandedById.clear();
|
|
346
|
+
bodyGroup = new WeakMap;
|
|
347
|
+
}
|
|
348
|
+
function finish(group) {
|
|
349
|
+
if (!group || group.settled)
|
|
350
|
+
return;
|
|
351
|
+
group.settled = true;
|
|
352
|
+
for (const member of group.members)
|
|
353
|
+
member.isPartial = false;
|
|
354
|
+
ping(group.members[0]?.id);
|
|
355
|
+
}
|
|
356
|
+
function newGroup() {
|
|
357
|
+
open = { settled: false, expanded: false, members: [] };
|
|
358
|
+
groups.push(open);
|
|
359
|
+
return open;
|
|
360
|
+
}
|
|
361
|
+
function place(id, name, group, args) {
|
|
362
|
+
const current = byId.get(id);
|
|
363
|
+
if (current === group) {
|
|
364
|
+
const row = group.members.find((item) => item.id === id);
|
|
365
|
+
if (row && name)
|
|
366
|
+
row.name = name;
|
|
367
|
+
if (row && args !== undefined)
|
|
368
|
+
row.args = args;
|
|
369
|
+
return group;
|
|
370
|
+
}
|
|
371
|
+
if (current) {
|
|
372
|
+
const oldAnchor = current.members[0];
|
|
373
|
+
current.members = current.members.filter((item) => item.id !== id);
|
|
374
|
+
if (oldAnchor && oldAnchor.id !== id)
|
|
375
|
+
ping(oldAnchor.id);
|
|
376
|
+
}
|
|
377
|
+
const row = { id, name: name || id, isError: false, isPartial: false, args };
|
|
378
|
+
group.members.push(row);
|
|
379
|
+
byId.set(id, group);
|
|
380
|
+
const anchor = group.members[0];
|
|
381
|
+
if (anchor !== row)
|
|
382
|
+
ping(anchor.id);
|
|
383
|
+
return group;
|
|
384
|
+
}
|
|
385
|
+
function ping(id) {
|
|
386
|
+
if (!replaying && id)
|
|
387
|
+
invalidators.get(id)?.();
|
|
388
|
+
}
|
|
389
|
+
function note(message) {
|
|
390
|
+
if (!isMessage(message))
|
|
391
|
+
return;
|
|
392
|
+
if (message.role === "user" || message.role === "custom" && message.display) {
|
|
393
|
+
finish(open);
|
|
394
|
+
open = null;
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
if (message.role === "toolResult") {
|
|
398
|
+
const nested = message.nestedCalls?.calls;
|
|
399
|
+
if (!Array.isArray(nested))
|
|
400
|
+
return;
|
|
401
|
+
for (const call of nested) {
|
|
402
|
+
if (!call?.id || calls.has(call.id))
|
|
403
|
+
continue;
|
|
404
|
+
remember(call.id, {
|
|
405
|
+
name: call.name,
|
|
406
|
+
args: call.arguments,
|
|
407
|
+
parentId: message.toolCallId,
|
|
408
|
+
isError: call.status === "error",
|
|
409
|
+
isPartial: call.status === "unfinished"
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
if (message.role !== "assistant" || !Array.isArray(message.content))
|
|
415
|
+
return;
|
|
416
|
+
const toolCalls = message.content.filter((part) => part?.type === "toolCall" && part.id);
|
|
417
|
+
const hasBody = message.content.some((part) => part?.type === "text" && String(part.text ?? "").trim());
|
|
418
|
+
if (!hasBody) {
|
|
419
|
+
for (const call of toolCalls)
|
|
420
|
+
if (!byId.has(call.id))
|
|
421
|
+
place(call.id, call.name, open ?? newGroup(), call.arguments);
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
let group = bodyGroup.get(message);
|
|
425
|
+
if (!group) {
|
|
426
|
+
if (open)
|
|
427
|
+
finish(open);
|
|
428
|
+
group = newGroup();
|
|
429
|
+
bodyGroup.set(message, group);
|
|
430
|
+
}
|
|
431
|
+
for (const call of toolCalls)
|
|
432
|
+
place(call.id, call.name, group, call.arguments);
|
|
433
|
+
}
|
|
434
|
+
function remember(id, fields) {
|
|
435
|
+
let row = calls.get(id);
|
|
436
|
+
if (!row) {
|
|
437
|
+
row = { id, name: "", isError: false, isPartial: false };
|
|
438
|
+
calls.set(id, row);
|
|
439
|
+
}
|
|
440
|
+
if (fields.name)
|
|
441
|
+
row.name = fields.name;
|
|
442
|
+
if (fields.args !== undefined)
|
|
443
|
+
row.args = fields.args;
|
|
444
|
+
if (fields.parentId)
|
|
445
|
+
row.parentId = fields.parentId;
|
|
446
|
+
if (fields.isError !== undefined)
|
|
447
|
+
row.isError = fields.isError;
|
|
448
|
+
if (fields.isPartial !== undefined)
|
|
449
|
+
row.isPartial = fields.isPartial;
|
|
450
|
+
if (fields.result !== undefined)
|
|
451
|
+
row.result = fields.result;
|
|
452
|
+
const owner = byId.get(row.parentId || id);
|
|
453
|
+
ping(owner?.members[0]?.id);
|
|
454
|
+
return row;
|
|
455
|
+
}
|
|
456
|
+
function pathPart(verb, one, many, ops) {
|
|
457
|
+
if (!ops.length)
|
|
458
|
+
return;
|
|
459
|
+
const paths = [];
|
|
460
|
+
for (const op of ops) {
|
|
461
|
+
const path = isFields(op.args) ? op.args.path ?? op.args.file_path : undefined;
|
|
462
|
+
if (!isString(path) || !path)
|
|
463
|
+
return verb + " " + ops.length;
|
|
464
|
+
paths.push(path);
|
|
465
|
+
}
|
|
466
|
+
const count = new Set(paths).size;
|
|
467
|
+
return verb + " " + count + " " + (count === 1 ? one : many);
|
|
468
|
+
}
|
|
469
|
+
function times(n, one, many) {
|
|
470
|
+
return "Ran " + n + " " + (n === 1 ? one : many);
|
|
471
|
+
}
|
|
472
|
+
function summarize(group) {
|
|
473
|
+
const seen = new Map;
|
|
474
|
+
for (const member of group.members) {
|
|
475
|
+
const extra = calls.get(member.id);
|
|
476
|
+
seen.set(member.id, {
|
|
477
|
+
name: member.name || extra?.name,
|
|
478
|
+
args: member.args ?? extra?.args,
|
|
479
|
+
isError: member.isError || extra?.isError,
|
|
480
|
+
isPartial: member.isPartial || extra?.isPartial
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
for (const call of calls.values()) {
|
|
484
|
+
if (!call.parentId || !seen.has(call.parentId) || seen.has(call.id))
|
|
485
|
+
continue;
|
|
486
|
+
seen.set(call.id, call);
|
|
487
|
+
}
|
|
488
|
+
const all = [...seen.values()];
|
|
489
|
+
const named = (name) => all.filter((item) => item.name === name);
|
|
490
|
+
const parts = [];
|
|
491
|
+
const code = named("codemode");
|
|
492
|
+
if (code.length)
|
|
493
|
+
parts.push("Ran " + code.length + " codemode");
|
|
494
|
+
const read = pathPart("Read", "file", "files", named("read"));
|
|
495
|
+
if (read)
|
|
496
|
+
parts.push(read);
|
|
497
|
+
const write = pathPart("Wrote", "file", "files", named("write"));
|
|
498
|
+
if (write)
|
|
499
|
+
parts.push(write);
|
|
500
|
+
const edit = pathPart("Edited", "file", "files", named("edit"));
|
|
501
|
+
if (edit)
|
|
502
|
+
parts.push(edit);
|
|
503
|
+
const shell = named("bash").length + named("powershell").length;
|
|
504
|
+
if (shell)
|
|
505
|
+
parts.push(times(shell, "shell command", "shell commands"));
|
|
506
|
+
const grep = named("grep").length;
|
|
507
|
+
if (grep)
|
|
508
|
+
parts.push(times(grep, "content search", "content searches"));
|
|
509
|
+
const find = named("find").length;
|
|
510
|
+
if (find)
|
|
511
|
+
parts.push(times(find, "file search", "file searches"));
|
|
512
|
+
const listed = pathPart("Listed", "directory", "directories", named("ls"));
|
|
513
|
+
if (listed)
|
|
514
|
+
parts.push(listed);
|
|
515
|
+
const search = named("tool_search").length;
|
|
516
|
+
if (search)
|
|
517
|
+
parts.push(times(search, "tool search", "tool searches"));
|
|
518
|
+
const known = new Set([
|
|
519
|
+
"codemode",
|
|
520
|
+
"read",
|
|
521
|
+
"write",
|
|
522
|
+
"edit",
|
|
523
|
+
"bash",
|
|
524
|
+
"powershell",
|
|
525
|
+
"grep",
|
|
526
|
+
"find",
|
|
527
|
+
"ls",
|
|
528
|
+
"tool_search"
|
|
529
|
+
]);
|
|
530
|
+
const other = all.filter((item) => item.name && !known.has(item.name)).length;
|
|
531
|
+
if (other)
|
|
532
|
+
parts.push(times(other, "other tool call", "other tool calls"));
|
|
533
|
+
const failed = all.filter((item) => item.isError).length;
|
|
534
|
+
if (failed)
|
|
535
|
+
parts.push(failed + " failed");
|
|
536
|
+
return parts.length ? parts : [group.members.length + " tools"];
|
|
537
|
+
}
|
|
538
|
+
function callPath(args) {
|
|
539
|
+
const path = isFields(args) ? args.path ?? args.file_path : undefined;
|
|
540
|
+
return isString(path) && path ? path : undefined;
|
|
541
|
+
}
|
|
542
|
+
function activity(call) {
|
|
543
|
+
const path = callPath(call.args);
|
|
544
|
+
if (call.name === "read")
|
|
545
|
+
return path ? "Reading " + path + "…" : "Reading…";
|
|
546
|
+
if (call.name === "write")
|
|
547
|
+
return path ? "Writing " + path + "…" : "Writing…";
|
|
548
|
+
if (call.name === "edit")
|
|
549
|
+
return path ? "Editing " + path + "…" : "Editing…";
|
|
550
|
+
if (call.name === "ls")
|
|
551
|
+
return path ? "Listing " + path + "…" : "Listing…";
|
|
552
|
+
if (call.name)
|
|
553
|
+
return "Running " + call.name + "…";
|
|
554
|
+
return "Working…";
|
|
555
|
+
}
|
|
556
|
+
function belongs(call, memberIds) {
|
|
557
|
+
let current = call;
|
|
558
|
+
const seen = new Set;
|
|
559
|
+
while (current && !seen.has(current.id)) {
|
|
560
|
+
if (memberIds.has(current.id))
|
|
561
|
+
return true;
|
|
562
|
+
seen.add(current.id);
|
|
563
|
+
current = current.parentId ? calls.get(current.parentId) : undefined;
|
|
564
|
+
}
|
|
565
|
+
return false;
|
|
566
|
+
}
|
|
567
|
+
function header(group) {
|
|
568
|
+
if (!runActive || group.settled)
|
|
569
|
+
return summarize(group);
|
|
570
|
+
const memberIds = new Set(group.members.map((member) => member.id));
|
|
571
|
+
const partial = [];
|
|
572
|
+
for (const member of group.members) {
|
|
573
|
+
const extra = calls.get(member.id);
|
|
574
|
+
if (member.isPartial || extra?.isPartial)
|
|
575
|
+
partial.push(Object.assign({ id: member.id }, member, extra || {}));
|
|
576
|
+
}
|
|
577
|
+
for (const call of calls.values()) {
|
|
578
|
+
if (!call.isPartial || partial.some((item) => item.id === call.id))
|
|
579
|
+
continue;
|
|
580
|
+
if (belongs(call, memberIds))
|
|
581
|
+
partial.push(call);
|
|
582
|
+
}
|
|
583
|
+
const covered = new Set;
|
|
584
|
+
for (const call of partial) {
|
|
585
|
+
let parent = call.parentId;
|
|
586
|
+
while (parent) {
|
|
587
|
+
covered.add(parent);
|
|
588
|
+
parent = calls.get(parent)?.parentId;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
const parts = partial.flatMap((call) => covered.has(call.id) ? [] : [activity(call)]);
|
|
592
|
+
if (!parts.length)
|
|
593
|
+
parts.push("Working…");
|
|
594
|
+
const failed = summarize(group).filter((part) => part.endsWith(" failed"));
|
|
595
|
+
return parts.concat(failed);
|
|
596
|
+
}
|
|
597
|
+
function fit(parts, width) {
|
|
598
|
+
const limit = Math.max(1, width || 1);
|
|
599
|
+
const lines = [];
|
|
600
|
+
let line = "";
|
|
601
|
+
for (const part of parts) {
|
|
602
|
+
const piece = truncateToWidth(part, limit, "");
|
|
603
|
+
const next = line ? line + " · " + piece : piece;
|
|
604
|
+
if (line && visibleWidth(next) > limit) {
|
|
605
|
+
lines.push(line);
|
|
606
|
+
line = piece;
|
|
607
|
+
} else {
|
|
608
|
+
line = next;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
if (line)
|
|
612
|
+
lines.push(line);
|
|
613
|
+
return lines;
|
|
614
|
+
}
|
|
615
|
+
function visibleEntries(ctx) {
|
|
616
|
+
const build = ctx?.sessionManager?.buildContextEntries;
|
|
617
|
+
if (!isFunction(build))
|
|
618
|
+
return;
|
|
619
|
+
const entries = build.call(ctx.sessionManager);
|
|
620
|
+
return Array.isArray(entries) ? entries : undefined;
|
|
621
|
+
}
|
|
622
|
+
function replay(ctx) {
|
|
623
|
+
const entries = visibleEntries(ctx);
|
|
624
|
+
if (!entries)
|
|
625
|
+
return;
|
|
626
|
+
replaying = true;
|
|
627
|
+
reset();
|
|
628
|
+
for (const entry of entries) {
|
|
629
|
+
if (entry?.type === "message")
|
|
630
|
+
note(entry.message);
|
|
631
|
+
else if (entry?.type === "custom_message")
|
|
632
|
+
note({ role: "custom", display: entry.display });
|
|
633
|
+
}
|
|
634
|
+
replaying = false;
|
|
635
|
+
for (const id of invalidators.keys())
|
|
636
|
+
if (!byId.has(id))
|
|
637
|
+
invalidators.delete(id);
|
|
638
|
+
for (const invalidate of invalidators.values())
|
|
639
|
+
invalidate();
|
|
640
|
+
}
|
|
641
|
+
function stopRun() {
|
|
642
|
+
runActive = false;
|
|
643
|
+
for (const call of calls.values())
|
|
644
|
+
call.isPartial = false;
|
|
645
|
+
for (const group of groups)
|
|
646
|
+
for (const member of group.members)
|
|
647
|
+
member.isPartial = false;
|
|
648
|
+
finish(open);
|
|
649
|
+
for (const invalidate of invalidators.values())
|
|
650
|
+
invalidate();
|
|
651
|
+
}
|
|
652
|
+
let unwatch = null;
|
|
653
|
+
function watch(manager) {
|
|
654
|
+
unwatch?.();
|
|
655
|
+
unwatch = null;
|
|
656
|
+
const original = manager?.appendCustomMessageEntry;
|
|
657
|
+
if (!isFunction(original))
|
|
658
|
+
return;
|
|
659
|
+
const own = Object.getOwnPropertyDescriptor(manager, "appendCustomMessageEntry");
|
|
660
|
+
let active = true;
|
|
661
|
+
const wrapper = function(...args) {
|
|
662
|
+
const id = original.apply(this, args);
|
|
663
|
+
if (active)
|
|
664
|
+
note({ role: "custom", display: args[2] });
|
|
665
|
+
return id;
|
|
666
|
+
};
|
|
667
|
+
try {
|
|
668
|
+
manager.appendCustomMessageEntry = wrapper;
|
|
669
|
+
} catch {
|
|
670
|
+
return;
|
|
671
|
+
}
|
|
672
|
+
unwatch = () => {
|
|
673
|
+
active = false;
|
|
674
|
+
if (manager.appendCustomMessageEntry !== wrapper)
|
|
675
|
+
return;
|
|
676
|
+
if (own)
|
|
677
|
+
Object.defineProperty(manager, "appendCustomMessageEntry", own);
|
|
678
|
+
else
|
|
679
|
+
delete manager.appendCustomMessageEntry;
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
pi.on("session_start", (_event, ctx) => {
|
|
683
|
+
runActive = false;
|
|
684
|
+
watch(ctx?.sessionManager);
|
|
685
|
+
replay(ctx);
|
|
686
|
+
});
|
|
687
|
+
pi.on("session_shutdown", () => {
|
|
688
|
+
unwatch?.();
|
|
689
|
+
unwatch = null;
|
|
690
|
+
});
|
|
691
|
+
pi.on("session_compact", (_event, ctx) => replay(ctx));
|
|
692
|
+
pi.on("session_tree", (_event, ctx) => replay(ctx));
|
|
693
|
+
pi.on("agent_start", () => {
|
|
694
|
+
runActive = true;
|
|
695
|
+
});
|
|
696
|
+
pi.on("agent_end", () => stopRun());
|
|
697
|
+
pi.on("message_start", (event) => note(event?.message));
|
|
698
|
+
pi.on("message_update", (event) => note(event?.message));
|
|
699
|
+
pi.on("tool_execution_start", (event) => {
|
|
700
|
+
if (!event?.toolCallId)
|
|
701
|
+
return;
|
|
702
|
+
runActive = true;
|
|
703
|
+
remember(event.toolCallId, {
|
|
704
|
+
name: event.toolName,
|
|
705
|
+
args: event.args,
|
|
706
|
+
parentId: event.parentToolCallId,
|
|
707
|
+
isPartial: true
|
|
708
|
+
});
|
|
709
|
+
});
|
|
710
|
+
pi.on("tool_execution_end", (event) => {
|
|
711
|
+
if (!event?.toolCallId)
|
|
712
|
+
return;
|
|
713
|
+
remember(event.toolCallId, {
|
|
714
|
+
name: event.toolName,
|
|
715
|
+
args: event.args,
|
|
716
|
+
parentId: event.parentToolCallId,
|
|
717
|
+
isError: event.isError === true,
|
|
718
|
+
isPartial: false,
|
|
719
|
+
result: event.result
|
|
720
|
+
});
|
|
721
|
+
});
|
|
722
|
+
pi.registerToolRenderer((toolName, next) => {
|
|
723
|
+
const later = next();
|
|
724
|
+
if (later?.isVibestToolGroups === true)
|
|
725
|
+
return later;
|
|
726
|
+
return {
|
|
727
|
+
isVibestToolGroups: true,
|
|
728
|
+
renderShell: "self",
|
|
729
|
+
renderCall(args, theme, ctx) {
|
|
730
|
+
if (ctx?.toolCallId)
|
|
731
|
+
expandedById.set(ctx.toolCallId, ctx.expanded === true);
|
|
732
|
+
if (ctx?.invalidate)
|
|
733
|
+
invalidators.set(ctx.toolCallId, ctx.invalidate);
|
|
734
|
+
let group = byId.get(ctx.toolCallId);
|
|
735
|
+
if (!group)
|
|
736
|
+
group = place(ctx.toolCallId, toolName, open ?? newGroup(), args);
|
|
737
|
+
const row = group.members.find((item) => item.id === ctx.toolCallId);
|
|
738
|
+
if (row) {
|
|
739
|
+
row.name = toolName;
|
|
740
|
+
if (args !== undefined)
|
|
741
|
+
row.args = args;
|
|
742
|
+
}
|
|
743
|
+
const renderers = (() => {
|
|
744
|
+
try {
|
|
745
|
+
return next();
|
|
746
|
+
} catch {
|
|
747
|
+
return;
|
|
748
|
+
}
|
|
749
|
+
})();
|
|
750
|
+
let native;
|
|
751
|
+
if (renderers?.renderCall) {
|
|
752
|
+
try {
|
|
753
|
+
native = renderers.renderCall(args, theme, {
|
|
754
|
+
...ctx,
|
|
755
|
+
expanded: true,
|
|
756
|
+
lastComponent: ctx.lastComponent?.native
|
|
757
|
+
});
|
|
758
|
+
} catch {
|
|
759
|
+
native = undefined;
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
const body = native ? frameComponent(renderers, native, ctx.outputPad) : {
|
|
763
|
+
render(innerWidth) {
|
|
764
|
+
const { pad, limit } = gutter(innerWidth, ctx.outputPad);
|
|
765
|
+
return indent(plainCall(toolName, args, limit), pad);
|
|
766
|
+
}
|
|
767
|
+
};
|
|
768
|
+
return {
|
|
769
|
+
native,
|
|
770
|
+
invalidate() {
|
|
771
|
+
native?.invalidate?.();
|
|
772
|
+
},
|
|
773
|
+
render(width) {
|
|
774
|
+
const current = byId.get(ctx.toolCallId);
|
|
775
|
+
if (!current)
|
|
776
|
+
return [];
|
|
777
|
+
const isAnchor = current.members[0]?.id === ctx.toolCallId;
|
|
778
|
+
if (isAnchor && ctx.expanded !== current.expanded) {
|
|
779
|
+
current.expanded = ctx.expanded;
|
|
780
|
+
const ids = current.members.map((member) => member.id);
|
|
781
|
+
queueMicrotask(() => {
|
|
782
|
+
for (const id of ids)
|
|
783
|
+
if (id !== ctx.toolCallId)
|
|
784
|
+
invalidators.get(id)?.();
|
|
785
|
+
});
|
|
786
|
+
}
|
|
787
|
+
const { pad, limit } = gutter(width, ctx.outputPad);
|
|
788
|
+
const paint = (line) => isFunction(theme?.fg) ? theme.fg("muted", line) : line;
|
|
789
|
+
const title = indent(fit(header(current), limit).map(paint), pad);
|
|
790
|
+
if (!current.expanded)
|
|
791
|
+
return isAnchor ? title : [];
|
|
792
|
+
if (showNative(ctx, current))
|
|
793
|
+
return isAnchor ? [...title, ...body.render(width)] : body.render(width);
|
|
794
|
+
const row = current.members.find((item) => item.id === ctx.toolCallId);
|
|
795
|
+
const lines = indent(compactText(row, limit), pad);
|
|
796
|
+
if (isAnchor)
|
|
797
|
+
lines.unshift(...title);
|
|
798
|
+
lines.push(...indent(nestedLines(ctx.toolCallId, limit), pad));
|
|
799
|
+
return lines;
|
|
800
|
+
}
|
|
801
|
+
};
|
|
802
|
+
},
|
|
803
|
+
renderResult(result, options, theme, ctx) {
|
|
804
|
+
if (ctx?.toolCallId)
|
|
805
|
+
expandedById.set(ctx.toolCallId, ctx.expanded === true);
|
|
806
|
+
const group = byId.get(ctx.toolCallId) ?? place(ctx.toolCallId, toolName, open ?? newGroup());
|
|
807
|
+
const row = group.members.find((item) => item.id === ctx.toolCallId);
|
|
808
|
+
const changed = row.result !== result || row.isError !== ctx.isError || row.isPartial !== ctx.isPartial;
|
|
809
|
+
row.result = result;
|
|
810
|
+
row.isError = ctx.isError;
|
|
811
|
+
row.isPartial = ctx.isPartial;
|
|
812
|
+
if (row !== group.members[0] && changed)
|
|
813
|
+
ping(group.members[0]?.id);
|
|
814
|
+
const renderers = (() => {
|
|
815
|
+
try {
|
|
816
|
+
return next();
|
|
817
|
+
} catch {
|
|
818
|
+
return;
|
|
819
|
+
}
|
|
820
|
+
})();
|
|
821
|
+
let native;
|
|
822
|
+
if (renderers?.renderResult) {
|
|
823
|
+
try {
|
|
824
|
+
native = renderers.renderResult(result, { ...options, expanded: true }, theme, {
|
|
825
|
+
...ctx,
|
|
826
|
+
lastComponent: ctx.lastComponent?.native
|
|
827
|
+
});
|
|
828
|
+
} catch {
|
|
829
|
+
native = undefined;
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
const body = native ? frameComponent(renderers, native, ctx.outputPad) : {
|
|
833
|
+
render(innerWidth) {
|
|
834
|
+
const { pad, limit } = gutter(innerWidth, ctx.outputPad);
|
|
835
|
+
return indent(plainResult(result, ctx.isError, limit), pad);
|
|
836
|
+
}
|
|
837
|
+
};
|
|
838
|
+
return {
|
|
839
|
+
native,
|
|
840
|
+
invalidate() {
|
|
841
|
+
native?.invalidate?.();
|
|
842
|
+
},
|
|
843
|
+
render(width) {
|
|
844
|
+
const current = byId.get(ctx.toolCallId);
|
|
845
|
+
if (!current?.expanded || !showNative(ctx, current))
|
|
846
|
+
return [];
|
|
847
|
+
return body.render(width);
|
|
848
|
+
}
|
|
849
|
+
};
|
|
850
|
+
}
|
|
851
|
+
};
|
|
852
|
+
});
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
// src/tui/user-message-padding.ts
|
|
856
|
+
var isLease = (value) => hasProperty(value, "by") && value.by === compactUserMessages;
|
|
857
|
+
function readLease(proto) {
|
|
858
|
+
const lease = Object.getOwnPropertyDescriptor(proto, "vibestCompactUserMessagesLease")?.value;
|
|
859
|
+
return isLease(lease) ? lease : undefined;
|
|
860
|
+
}
|
|
861
|
+
function writeLease(proto, lease) {
|
|
862
|
+
if (lease)
|
|
863
|
+
Object.defineProperty(proto, "vibestCompactUserMessagesLease", {
|
|
864
|
+
value: lease,
|
|
865
|
+
configurable: true,
|
|
866
|
+
enumerable: false,
|
|
867
|
+
writable: false
|
|
868
|
+
});
|
|
869
|
+
else
|
|
870
|
+
Reflect.deleteProperty(proto, "vibestCompactUserMessagesLease");
|
|
871
|
+
}
|
|
872
|
+
function compact(original, width) {
|
|
873
|
+
const ZONE_A = "\x1B]133;A\x07";
|
|
874
|
+
const ZONE_B = "\x1B]133;B\x07";
|
|
875
|
+
const ZONE_C = "\x1B]133;C\x07";
|
|
876
|
+
const INVERTED = ZONE_B + ZONE_C + ZONE_A;
|
|
877
|
+
const LEADING = ZONE_A + ZONE_B + ZONE_C;
|
|
878
|
+
const children = this.children;
|
|
879
|
+
const restores = [];
|
|
880
|
+
try {
|
|
881
|
+
if (Array.isArray(children)) {
|
|
882
|
+
for (const child of children) {
|
|
883
|
+
if (!isObjectOrArray(child) || !hasProperty(child, "paddingY") || !hasProperty(child, "render"))
|
|
884
|
+
continue;
|
|
885
|
+
const { paddingY, render: childRender } = child;
|
|
886
|
+
if (!isNumber(paddingY) || !Number.isInteger(paddingY) || paddingY <= 0)
|
|
887
|
+
continue;
|
|
888
|
+
if (!isFunction(childRender))
|
|
889
|
+
continue;
|
|
890
|
+
const descriptor = Object.getOwnPropertyDescriptor(child, "render");
|
|
891
|
+
child.render = function(innerWidth) {
|
|
892
|
+
const lines = childRender.call(this, innerWidth);
|
|
893
|
+
if (!Array.isArray(lines) || lines.length <= paddingY * 2)
|
|
894
|
+
return lines;
|
|
895
|
+
return lines.slice(paddingY, lines.length - paddingY);
|
|
896
|
+
};
|
|
897
|
+
restores.push(() => {
|
|
898
|
+
if (descriptor)
|
|
899
|
+
Object.defineProperty(child, "render", descriptor);
|
|
900
|
+
else
|
|
901
|
+
Reflect.deleteProperty(child, "render");
|
|
902
|
+
});
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
const lines = original.call(this, width);
|
|
906
|
+
if (!Array.isArray(lines) || lines.length !== 1 || !isString(lines[0]) || !lines[0].startsWith(INVERTED))
|
|
907
|
+
return lines;
|
|
908
|
+
const copy = lines.slice();
|
|
909
|
+
copy[0] = LEADING + lines[0].slice(INVERTED.length);
|
|
910
|
+
return copy;
|
|
911
|
+
} finally {
|
|
912
|
+
for (let i = restores.length - 1;i >= 0; i--)
|
|
913
|
+
restores[i]();
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
function isFramePaint(paint, lease, nativePaint) {
|
|
917
|
+
if (!isFunction(paint))
|
|
918
|
+
return false;
|
|
919
|
+
if (lease?.paint === paint || nativePaint === paint)
|
|
920
|
+
return true;
|
|
921
|
+
return paint.toString().includes("renderLayoutFrame");
|
|
922
|
+
}
|
|
923
|
+
function compactUserMessages(pi, classes) {
|
|
924
|
+
const owner = {};
|
|
925
|
+
let nativeRender;
|
|
926
|
+
let nativePaint;
|
|
927
|
+
let release = null;
|
|
928
|
+
function install() {
|
|
929
|
+
const message = classes.UserMessageComponent?.prototype;
|
|
930
|
+
const alt = classes.TuiAltScreen?.prototype;
|
|
931
|
+
const render = message?.render;
|
|
932
|
+
const paint = alt?.["doRender"];
|
|
933
|
+
if (!message || !alt || !isFunction(render))
|
|
934
|
+
return () => {};
|
|
935
|
+
let lease = readLease(message);
|
|
936
|
+
if (!isFramePaint(paint, lease, nativePaint))
|
|
937
|
+
return () => {};
|
|
938
|
+
if (lease)
|
|
939
|
+
lease.owners.add(owner);
|
|
940
|
+
else if ((nativeRender === undefined || render === nativeRender) && (nativePaint === undefined || paint === nativePaint)) {
|
|
941
|
+
let framing = false;
|
|
942
|
+
const next = {
|
|
943
|
+
by: compactUserMessages,
|
|
944
|
+
owners: new Set([owner]),
|
|
945
|
+
render(width) {
|
|
946
|
+
if (!next.active || !framing)
|
|
947
|
+
return render.call(this, width);
|
|
948
|
+
return compact.call(this, render, width);
|
|
949
|
+
},
|
|
950
|
+
paint() {
|
|
951
|
+
if (!next.active)
|
|
952
|
+
return paint.call(this);
|
|
953
|
+
framing = true;
|
|
954
|
+
try {
|
|
955
|
+
return paint.call(this);
|
|
956
|
+
} finally {
|
|
957
|
+
framing = false;
|
|
958
|
+
}
|
|
959
|
+
},
|
|
960
|
+
renderOriginal: render,
|
|
961
|
+
paintOriginal: paint,
|
|
962
|
+
active: true
|
|
963
|
+
};
|
|
964
|
+
writeLease(message, next);
|
|
965
|
+
try {
|
|
966
|
+
message.render = next.render;
|
|
967
|
+
} catch (error) {
|
|
968
|
+
writeLease(message, undefined);
|
|
969
|
+
throw error;
|
|
970
|
+
}
|
|
971
|
+
try {
|
|
972
|
+
alt["doRender"] = next.paint;
|
|
973
|
+
} catch (error) {
|
|
974
|
+
message.render = render;
|
|
975
|
+
writeLease(message, undefined);
|
|
976
|
+
throw error;
|
|
977
|
+
}
|
|
978
|
+
lease = next;
|
|
979
|
+
} else
|
|
980
|
+
return () => {};
|
|
981
|
+
const held = lease;
|
|
982
|
+
nativeRender = held.renderOriginal;
|
|
983
|
+
nativePaint = held.paintOriginal;
|
|
984
|
+
let released = false;
|
|
985
|
+
return () => {
|
|
986
|
+
if (released)
|
|
987
|
+
return;
|
|
988
|
+
released = true;
|
|
989
|
+
held.owners.delete(owner);
|
|
990
|
+
if (held.owners.size > 0)
|
|
991
|
+
return;
|
|
992
|
+
held.active = false;
|
|
993
|
+
if (message.render === held.render)
|
|
994
|
+
message.render = held.renderOriginal;
|
|
995
|
+
if (alt["doRender"] === held.paint)
|
|
996
|
+
alt["doRender"] = held.paintOriginal;
|
|
997
|
+
if (readLease(message) === held)
|
|
998
|
+
writeLease(message, undefined);
|
|
999
|
+
};
|
|
1000
|
+
}
|
|
1001
|
+
pi.on("session_start", (_event, ctx) => {
|
|
1002
|
+
if (ctx?.mode !== "tui" || !ctx.hasUI) {
|
|
1003
|
+
release?.();
|
|
1004
|
+
release = null;
|
|
1005
|
+
return;
|
|
1006
|
+
}
|
|
1007
|
+
release?.();
|
|
1008
|
+
release = install();
|
|
1009
|
+
});
|
|
1010
|
+
pi.on("session_shutdown", () => {
|
|
1011
|
+
release?.();
|
|
1012
|
+
release = null;
|
|
1013
|
+
});
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
// src/presentation.ts
|
|
1017
|
+
var presentation_default = (api) => {
|
|
1018
|
+
tool_groups_default(api);
|
|
1019
|
+
compactUserMessages(api, { UserMessageComponent, TuiAltScreen });
|
|
1020
|
+
};
|
|
1021
|
+
export {
|
|
1022
|
+
presentation_default as default
|
|
1023
|
+
};
|