@bypane/cli 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +77 -22
- package/dist/app-host.js +408 -0
- package/dist/app-protocol.js +1 -0
- package/dist/app-worker.js +556 -0
- package/dist/cli.js +134 -0
- package/dist/demo.js +264 -0
- package/dist/expr.js +460 -0
- package/dist/mcp.js +114 -5
- package/dist/multiplexer.js +4 -2
- package/dist/primitives.js +669 -0
- package/dist/selection.js +170 -0
- package/dist/setup.js +22 -21
- package/dist/skill.js +52 -10
- package/dist/state.js +446 -19
- package/dist/ui-surface.js +744 -0
- package/dist/ui.js +482 -36
- package/examples/spring-studio.ts +420 -0
- package/package.json +2 -1
- package/skills/bypane/SKILL.md +52 -10
package/dist/expr.js
ADDED
|
@@ -0,0 +1,460 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safe, zero-eval, scriptc-compatible expression and template evaluator
|
|
3
|
+
* for reactive declarative `ui` surfaces in bypane.
|
|
4
|
+
*/
|
|
5
|
+
const TWO_CHAR_OPS = new Set(["==", "!=", "<=", ">=", "&&", "||"]);
|
|
6
|
+
const ONE_CHAR_OPS = new Set(["+", "-", "*", "/", "%", "<", ">", "!"]);
|
|
7
|
+
function tokenize(src) {
|
|
8
|
+
const tokens = [];
|
|
9
|
+
let i = 0;
|
|
10
|
+
const n = src.length;
|
|
11
|
+
while (i < n) {
|
|
12
|
+
const ch = src[i];
|
|
13
|
+
if (ch === " " || ch === "\t" || ch === "\n" || ch === "\r") {
|
|
14
|
+
i++;
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
if ((ch >= "0" && ch <= "9") || (ch === "." && i + 1 < n && src[i + 1] >= "0" && src[i + 1] <= "9")) {
|
|
18
|
+
const start = i;
|
|
19
|
+
let seenDot = false;
|
|
20
|
+
while (i < n) {
|
|
21
|
+
const c = src[i];
|
|
22
|
+
if (c >= "0" && c <= "9") {
|
|
23
|
+
i++;
|
|
24
|
+
}
|
|
25
|
+
else if (c === "." && !seenDot) {
|
|
26
|
+
seenDot = true;
|
|
27
|
+
i++;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const text = src.slice(start, i);
|
|
34
|
+
tokens.push({ kind: "num", text, num: Number(text) });
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (ch === '"' || ch === "'") {
|
|
38
|
+
const quote = ch;
|
|
39
|
+
i++;
|
|
40
|
+
let out = "";
|
|
41
|
+
while (i < n && src[i] !== quote) {
|
|
42
|
+
if (src[i] === "\\" && i + 1 < n) {
|
|
43
|
+
const next = src[i + 1];
|
|
44
|
+
out += next === "n" ? "\n" : next === "t" ? "\t" : next;
|
|
45
|
+
i += 2;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
out += src[i];
|
|
49
|
+
i++;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (i < n && src[i] === quote)
|
|
53
|
+
i++;
|
|
54
|
+
tokens.push({ kind: "str", text: out });
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if ((ch >= "a" && ch <= "z") || (ch >= "A" && ch <= "Z") || ch === "_" || ch === "$") {
|
|
58
|
+
const start = i;
|
|
59
|
+
while (i < n) {
|
|
60
|
+
const c = src[i];
|
|
61
|
+
if ((c >= "a" && c <= "z") ||
|
|
62
|
+
(c >= "A" && c <= "Z") ||
|
|
63
|
+
(c >= "0" && c <= "9") ||
|
|
64
|
+
c === "_" ||
|
|
65
|
+
c === "$") {
|
|
66
|
+
i++;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
tokens.push({ kind: "ident", text: src.slice(start, i) });
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (i + 1 < n && TWO_CHAR_OPS.has(src.slice(i, i + 2))) {
|
|
76
|
+
tokens.push({ kind: "op", text: src.slice(i, i + 2) });
|
|
77
|
+
i += 2;
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
if (ONE_CHAR_OPS.has(ch)) {
|
|
81
|
+
tokens.push({ kind: "op", text: ch });
|
|
82
|
+
i++;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (ch === "(") {
|
|
86
|
+
tokens.push({ kind: "lparen", text: ch });
|
|
87
|
+
i++;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (ch === ")") {
|
|
91
|
+
tokens.push({ kind: "rparen", text: ch });
|
|
92
|
+
i++;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (ch === ",") {
|
|
96
|
+
tokens.push({ kind: "comma", text: ch });
|
|
97
|
+
i++;
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
if (ch === ".") {
|
|
101
|
+
tokens.push({ kind: "dot", text: ch });
|
|
102
|
+
i++;
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (ch === "?") {
|
|
106
|
+
tokens.push({ kind: "qmark", text: ch });
|
|
107
|
+
i++;
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
if (ch === ":") {
|
|
111
|
+
tokens.push({ kind: "colon", text: ch });
|
|
112
|
+
i++;
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
i++;
|
|
116
|
+
}
|
|
117
|
+
tokens.push({ kind: "eof", text: "" });
|
|
118
|
+
return tokens;
|
|
119
|
+
}
|
|
120
|
+
function toNum(v) {
|
|
121
|
+
if (typeof v === "number")
|
|
122
|
+
return Number.isFinite(v) ? v : 0;
|
|
123
|
+
if (typeof v === "boolean")
|
|
124
|
+
return v ? 1 : 0;
|
|
125
|
+
if (typeof v === "string") {
|
|
126
|
+
const n = Number(v);
|
|
127
|
+
return Number.isFinite(n) ? n : 0;
|
|
128
|
+
}
|
|
129
|
+
return 0;
|
|
130
|
+
}
|
|
131
|
+
function callBuiltin(name, args) {
|
|
132
|
+
switch (name) {
|
|
133
|
+
case "min":
|
|
134
|
+
return args.length ? Math.min(...args.map(toNum)) : 0;
|
|
135
|
+
case "max":
|
|
136
|
+
return args.length ? Math.max(...args.map(toNum)) : 0;
|
|
137
|
+
case "clamp": {
|
|
138
|
+
const v = toNum(args[0]);
|
|
139
|
+
const lo = toNum(args[1]);
|
|
140
|
+
const hi = toNum(args[2]);
|
|
141
|
+
return Math.max(lo, Math.min(hi, v));
|
|
142
|
+
}
|
|
143
|
+
case "round": {
|
|
144
|
+
const v = toNum(args[0]);
|
|
145
|
+
const digits = args.length >= 2 ? Math.max(0, Math.min(6, Math.trunc(toNum(args[1])))) : 0;
|
|
146
|
+
if (digits === 0)
|
|
147
|
+
return Math.round(v);
|
|
148
|
+
const factor = Math.pow(10, digits);
|
|
149
|
+
return Math.round(v * factor) / factor;
|
|
150
|
+
}
|
|
151
|
+
case "floor":
|
|
152
|
+
return Math.floor(toNum(args[0]));
|
|
153
|
+
case "ceil":
|
|
154
|
+
return Math.ceil(toNum(args[0]));
|
|
155
|
+
case "abs":
|
|
156
|
+
return Math.abs(toNum(args[0]));
|
|
157
|
+
case "sqrt":
|
|
158
|
+
return Math.sqrt(Math.max(0, toNum(args[0])));
|
|
159
|
+
case "pow":
|
|
160
|
+
return Math.pow(toNum(args[0]), toNum(args[1]));
|
|
161
|
+
case "sin":
|
|
162
|
+
return Math.sin(toNum(args[0]));
|
|
163
|
+
case "cos":
|
|
164
|
+
return Math.cos(toNum(args[0]));
|
|
165
|
+
case "exp":
|
|
166
|
+
return Math.exp(toNum(args[0]));
|
|
167
|
+
case "log":
|
|
168
|
+
return Math.log(Math.max(1e-9, toNum(args[0])));
|
|
169
|
+
case "fixed": {
|
|
170
|
+
const v = toNum(args[0]);
|
|
171
|
+
const d = args.length >= 2 ? Math.max(0, Math.min(6, Math.trunc(toNum(args[1])))) : 2;
|
|
172
|
+
return v.toFixed(d);
|
|
173
|
+
}
|
|
174
|
+
case "len": {
|
|
175
|
+
const v = args[0];
|
|
176
|
+
if (typeof v === "string" || Array.isArray(v))
|
|
177
|
+
return v.length;
|
|
178
|
+
return 0;
|
|
179
|
+
}
|
|
180
|
+
case "upper":
|
|
181
|
+
return String(args[0] ?? "").toUpperCase();
|
|
182
|
+
case "lower":
|
|
183
|
+
return String(args[0] ?? "").toLowerCase();
|
|
184
|
+
case "if":
|
|
185
|
+
return args[0] ? args[1] : args[2];
|
|
186
|
+
default:
|
|
187
|
+
return undefined;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
class Parser {
|
|
191
|
+
tokens;
|
|
192
|
+
scope;
|
|
193
|
+
pos = 0;
|
|
194
|
+
constructor(tokens, scope) {
|
|
195
|
+
this.tokens = tokens;
|
|
196
|
+
this.scope = scope;
|
|
197
|
+
}
|
|
198
|
+
peek() {
|
|
199
|
+
return this.tokens[this.pos] ?? { kind: "eof", text: "" };
|
|
200
|
+
}
|
|
201
|
+
next() {
|
|
202
|
+
const t = this.peek();
|
|
203
|
+
if (this.pos < this.tokens.length - 1)
|
|
204
|
+
this.pos++;
|
|
205
|
+
return t;
|
|
206
|
+
}
|
|
207
|
+
matchOp(op) {
|
|
208
|
+
const t = this.peek();
|
|
209
|
+
if (t.kind === "op" && t.text === op) {
|
|
210
|
+
this.next();
|
|
211
|
+
return true;
|
|
212
|
+
}
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
parse() {
|
|
216
|
+
return this.parseTernary();
|
|
217
|
+
}
|
|
218
|
+
parseTernary() {
|
|
219
|
+
const cond = this.parseOr();
|
|
220
|
+
if (this.peek().kind === "qmark") {
|
|
221
|
+
this.next();
|
|
222
|
+
const whenTrue = this.parseTernary();
|
|
223
|
+
if (this.peek().kind === "colon")
|
|
224
|
+
this.next();
|
|
225
|
+
const whenFalse = this.parseTernary();
|
|
226
|
+
return cond ? whenTrue : whenFalse;
|
|
227
|
+
}
|
|
228
|
+
return cond;
|
|
229
|
+
}
|
|
230
|
+
parseOr() {
|
|
231
|
+
let left = this.parseAnd();
|
|
232
|
+
while (this.matchOp("||")) {
|
|
233
|
+
const right = this.parseAnd();
|
|
234
|
+
left = left || right;
|
|
235
|
+
}
|
|
236
|
+
return left;
|
|
237
|
+
}
|
|
238
|
+
parseAnd() {
|
|
239
|
+
let left = this.parseEquality();
|
|
240
|
+
while (this.matchOp("&&")) {
|
|
241
|
+
const right = this.parseEquality();
|
|
242
|
+
left = left && right;
|
|
243
|
+
}
|
|
244
|
+
return left;
|
|
245
|
+
}
|
|
246
|
+
parseEquality() {
|
|
247
|
+
let left = this.parseComparison();
|
|
248
|
+
while (true) {
|
|
249
|
+
if (this.matchOp("==")) {
|
|
250
|
+
const right = this.parseComparison();
|
|
251
|
+
left = left === right;
|
|
252
|
+
}
|
|
253
|
+
else if (this.matchOp("!=")) {
|
|
254
|
+
const right = this.parseComparison();
|
|
255
|
+
left = left !== right;
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
break;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return left;
|
|
262
|
+
}
|
|
263
|
+
parseComparison() {
|
|
264
|
+
let left = this.parseAdditive();
|
|
265
|
+
while (true) {
|
|
266
|
+
if (this.matchOp("<"))
|
|
267
|
+
left = toNum(left) < toNum(this.parseAdditive());
|
|
268
|
+
else if (this.matchOp("<="))
|
|
269
|
+
left = toNum(left) <= toNum(this.parseAdditive());
|
|
270
|
+
else if (this.matchOp(">"))
|
|
271
|
+
left = toNum(left) > toNum(this.parseAdditive());
|
|
272
|
+
else if (this.matchOp(">="))
|
|
273
|
+
left = toNum(left) >= toNum(this.parseAdditive());
|
|
274
|
+
else
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
277
|
+
return left;
|
|
278
|
+
}
|
|
279
|
+
parseAdditive() {
|
|
280
|
+
let left = this.parseMultiplicative();
|
|
281
|
+
while (true) {
|
|
282
|
+
if (this.matchOp("+")) {
|
|
283
|
+
const right = this.parseMultiplicative();
|
|
284
|
+
if (typeof left === "string" || typeof right === "string") {
|
|
285
|
+
left = `${formatExprValue(left)}${formatExprValue(right)}`;
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
left = toNum(left) + toNum(right);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
else if (this.matchOp("-")) {
|
|
292
|
+
left = toNum(left) - toNum(this.parseMultiplicative());
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
break;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return left;
|
|
299
|
+
}
|
|
300
|
+
parseMultiplicative() {
|
|
301
|
+
let left = this.parseUnary();
|
|
302
|
+
while (true) {
|
|
303
|
+
if (this.matchOp("*")) {
|
|
304
|
+
left = toNum(left) * toNum(this.parseUnary());
|
|
305
|
+
}
|
|
306
|
+
else if (this.matchOp("/")) {
|
|
307
|
+
const denom = toNum(this.parseUnary());
|
|
308
|
+
left = denom === 0 ? 0 : toNum(left) / denom;
|
|
309
|
+
}
|
|
310
|
+
else if (this.matchOp("%")) {
|
|
311
|
+
const denom = toNum(this.parseUnary());
|
|
312
|
+
left = denom === 0 ? 0 : toNum(left) % denom;
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
break;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return left;
|
|
319
|
+
}
|
|
320
|
+
parseUnary() {
|
|
321
|
+
if (this.matchOp("!"))
|
|
322
|
+
return !this.parseUnary();
|
|
323
|
+
if (this.matchOp("-"))
|
|
324
|
+
return -toNum(this.parseUnary());
|
|
325
|
+
if (this.matchOp("+"))
|
|
326
|
+
return toNum(this.parseUnary());
|
|
327
|
+
return this.parsePrimary();
|
|
328
|
+
}
|
|
329
|
+
parsePrimary() {
|
|
330
|
+
const t = this.peek();
|
|
331
|
+
if (t.kind === "num") {
|
|
332
|
+
this.next();
|
|
333
|
+
return t.num ?? 0;
|
|
334
|
+
}
|
|
335
|
+
if (t.kind === "str") {
|
|
336
|
+
this.next();
|
|
337
|
+
return t.text;
|
|
338
|
+
}
|
|
339
|
+
if (t.kind === "lparen") {
|
|
340
|
+
this.next();
|
|
341
|
+
const val = this.parseTernary();
|
|
342
|
+
if (this.peek().kind === "rparen")
|
|
343
|
+
this.next();
|
|
344
|
+
return val;
|
|
345
|
+
}
|
|
346
|
+
if (t.kind === "ident") {
|
|
347
|
+
this.next();
|
|
348
|
+
const name = t.text;
|
|
349
|
+
if (this.peek().kind === "lparen") {
|
|
350
|
+
this.next();
|
|
351
|
+
const args = [];
|
|
352
|
+
if (this.peek().kind !== "rparen") {
|
|
353
|
+
while (true) {
|
|
354
|
+
args.push(this.parseTernary());
|
|
355
|
+
if (this.peek().kind === "comma") {
|
|
356
|
+
this.next();
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
break;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
if (this.peek().kind === "rparen")
|
|
364
|
+
this.next();
|
|
365
|
+
return callBuiltin(name, args);
|
|
366
|
+
}
|
|
367
|
+
let cur;
|
|
368
|
+
if (name === "true")
|
|
369
|
+
cur = true;
|
|
370
|
+
else if (name === "false")
|
|
371
|
+
cur = false;
|
|
372
|
+
else if (name === "null")
|
|
373
|
+
cur = null;
|
|
374
|
+
else if (name === "state")
|
|
375
|
+
cur = this.scope;
|
|
376
|
+
else
|
|
377
|
+
cur = this.scope[name];
|
|
378
|
+
while (this.peek().kind === "dot") {
|
|
379
|
+
this.next();
|
|
380
|
+
const prop = this.next();
|
|
381
|
+
if (prop.kind !== "ident")
|
|
382
|
+
break;
|
|
383
|
+
if (cur === null || cur === undefined) {
|
|
384
|
+
cur = undefined;
|
|
385
|
+
}
|
|
386
|
+
else if ((typeof cur === "string" || Array.isArray(cur)) && prop.text === "length") {
|
|
387
|
+
cur = cur.length;
|
|
388
|
+
}
|
|
389
|
+
else if (typeof cur === "object") {
|
|
390
|
+
cur = cur[prop.text];
|
|
391
|
+
}
|
|
392
|
+
else {
|
|
393
|
+
cur = undefined;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
return cur;
|
|
397
|
+
}
|
|
398
|
+
return undefined;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
export function formatExprValue(v) {
|
|
402
|
+
if (v === undefined || v === null)
|
|
403
|
+
return "";
|
|
404
|
+
if (typeof v === "number") {
|
|
405
|
+
if (!Number.isFinite(v))
|
|
406
|
+
return "0";
|
|
407
|
+
if (Number.isInteger(v))
|
|
408
|
+
return String(v);
|
|
409
|
+
return String(Math.round(v * 1000) / 1000);
|
|
410
|
+
}
|
|
411
|
+
if (typeof v === "boolean")
|
|
412
|
+
return v ? "true" : "false";
|
|
413
|
+
if (Array.isArray(v))
|
|
414
|
+
return v.map(formatExprValue).join(", ");
|
|
415
|
+
return String(v);
|
|
416
|
+
}
|
|
417
|
+
export function evalExpr(expr, scope) {
|
|
418
|
+
const trimmed = expr.trim();
|
|
419
|
+
if (!trimmed)
|
|
420
|
+
return "";
|
|
421
|
+
const parser = new Parser(tokenize(trimmed), scope);
|
|
422
|
+
return parser.parse();
|
|
423
|
+
}
|
|
424
|
+
const TEMPLATE_RE = /\{\{([\s\S]*?)\}\}/g;
|
|
425
|
+
export function interpolateText(template, scope) {
|
|
426
|
+
if (!template.includes("{{"))
|
|
427
|
+
return template;
|
|
428
|
+
return template.replace(TEMPLATE_RE, (_m, inner) => {
|
|
429
|
+
const val = evalExpr(inner, scope);
|
|
430
|
+
return formatExprValue(val);
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
export function evalNumber(input, scope, fallback = 0) {
|
|
434
|
+
if (typeof input === "number")
|
|
435
|
+
return Number.isFinite(input) ? input : fallback;
|
|
436
|
+
if (typeof input !== "string")
|
|
437
|
+
return fallback;
|
|
438
|
+
const trimmed = input.trim();
|
|
439
|
+
if (!trimmed)
|
|
440
|
+
return fallback;
|
|
441
|
+
const unwrapped = trimmed.startsWith("{{") && trimmed.endsWith("}}")
|
|
442
|
+
? trimmed.slice(2, -2).trim()
|
|
443
|
+
: trimmed;
|
|
444
|
+
const val = evalExpr(unwrapped, scope);
|
|
445
|
+
const num = typeof val === "number" ? val : Number(val);
|
|
446
|
+
return Number.isFinite(num) ? num : fallback;
|
|
447
|
+
}
|
|
448
|
+
export function evalSeriesValues(spec, scope) {
|
|
449
|
+
if (Array.isArray(spec)) {
|
|
450
|
+
return spec.map((item) => evalNumber(item, scope, 0));
|
|
451
|
+
}
|
|
452
|
+
const points = Math.max(2, Math.min(240, Math.trunc(spec.points || 16)));
|
|
453
|
+
const out = [];
|
|
454
|
+
for (let i = 0; i < points; i++) {
|
|
455
|
+
const t = points > 1 ? i / (points - 1) : 0;
|
|
456
|
+
const val = evalNumber(spec.expr, { ...scope, i, t, n: points }, 0);
|
|
457
|
+
out.push(val);
|
|
458
|
+
}
|
|
459
|
+
return out;
|
|
460
|
+
}
|
package/dist/mcp.js
CHANGED
|
@@ -4,17 +4,18 @@ const PROTOCOL_VERSIONS = ["2025-11-25", "2025-06-18", "2025-03-26", "2024-11-05
|
|
|
4
4
|
const TOOLS = [
|
|
5
5
|
{
|
|
6
6
|
name: "bypane_present",
|
|
7
|
-
description: "Show or update a visual surface in the user's companion bypane terminal pane (auto-opens a split pane in Rex or tmux if not running). Supports markdown (with interactive checkboxes), file (code/text/binary QuickLook), image (inline PNG), table, chart (braille), and
|
|
7
|
+
description: "Show or update a visual surface in the user's companion bypane terminal pane (auto-opens a split pane in Rex or tmux if not running). Supports markdown (with interactive checkboxes), file (code/text/binary QuickLook), image (inline PNG), table, chart (braille), log, and ui (declarative composable generative TUI with sliders, timelines, meters, toggles, charts, and reactive state).",
|
|
8
8
|
inputSchema: {
|
|
9
9
|
type: "object",
|
|
10
10
|
required: ["kind"],
|
|
11
11
|
properties: {
|
|
12
12
|
id: { type: "string", description: "Stable surface ID to update an existing tab in place." },
|
|
13
|
-
kind: { type: "string", enum: ["markdown", "file", "image", "table", "chart", "log"] },
|
|
13
|
+
kind: { type: "string", enum: ["markdown", "file", "image", "table", "chart", "log", "ui", "app"] },
|
|
14
14
|
title: { type: "string", description: "Short tab title." },
|
|
15
15
|
focus: { type: "boolean", description: "Whether to focus this tab (default true for new tabs)." },
|
|
16
16
|
content: { type: "string", description: "Markdown or inline text content (for kind=markdown or file)." },
|
|
17
|
-
path: { type: "string", description: "File or
|
|
17
|
+
path: { type: "string", description: "File, image, or .ts/.js app module path (for kind=file, image, or app)." },
|
|
18
|
+
code: { type: "string", description: "Inline TypeScript/JavaScript tui-sdk app source (for kind=app)." },
|
|
18
19
|
caption: { type: "string", description: "Optional caption (for kind=image or chart)." },
|
|
19
20
|
highlightStart: { type: "number", description: "1-based start line to highlight (for kind=file)." },
|
|
20
21
|
highlightEnd: { type: "number", description: "1-based end line to highlight (for kind=file)." },
|
|
@@ -46,6 +47,61 @@ const TOOLS = [
|
|
|
46
47
|
max: { type: "number" },
|
|
47
48
|
lines: { type: "array", items: { type: "string" }, description: "Log lines (for kind=log)." },
|
|
48
49
|
append: { type: "boolean", description: "Append lines instead of replacing (for kind=log)." },
|
|
50
|
+
root: {
|
|
51
|
+
type: "object",
|
|
52
|
+
description: "Declarative UiNode tree (for kind=ui). Containers: col, row, box, divider. Display: text, badge, stat, markdown, meter, sparkline, chart, canvas, table. Controls: slider, toggle, segmented, select, checkboxes, input, timeline (steps|gantt), button.",
|
|
53
|
+
},
|
|
54
|
+
state: {
|
|
55
|
+
type: "object",
|
|
56
|
+
description: "Initial reactive state map referenced by control `bind` keys and `{{expr}}` formulas (for kind=ui).",
|
|
57
|
+
},
|
|
58
|
+
preserveState: { type: "boolean", description: "Preserve user-edited state when updating same id (default true)." },
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
annotations: { readOnlyHint: false, destructiveHint: false },
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: "bypane_ui",
|
|
65
|
+
description: "Render a custom generative terminal UI in bypane using composable tui-sdk primitives: layout (col, row, box, divider), visuals (text, badge, stat, markdown, meter, sparkline, chart, canvas, table), and interactive controls (slider, toggle, segmented, select, checkboxes, input, timeline [steps|gantt], button). Supports safe reactive `{{expr}}` templates and formula-driven charts/meters. Set `wait: true` with a `submit: true` button for human-gated submission.",
|
|
66
|
+
inputSchema: {
|
|
67
|
+
type: "object",
|
|
68
|
+
required: ["title", "root"],
|
|
69
|
+
properties: {
|
|
70
|
+
id: { type: "string", description: "Stable surface ID to update in place." },
|
|
71
|
+
title: { type: "string", description: "Short tab title." },
|
|
72
|
+
root: {
|
|
73
|
+
type: "object",
|
|
74
|
+
description: "Root UiNode tree (e.g. `{ type: 'col', gap: 1, children: [...] }`). Controls bind to `state[bind]`; text/stat/meter/chart support `{{expr}}` expressions (math: min, max, clamp, round, sqrt, fixed, sin, cos).",
|
|
75
|
+
},
|
|
76
|
+
state: { type: "object", description: "Initial state values bound to interactive controls." },
|
|
77
|
+
preserveState: { type: "boolean", description: "Preserve user edits on in-place updates (default true)." },
|
|
78
|
+
wait: {
|
|
79
|
+
type: "boolean",
|
|
80
|
+
description: "Block until the human presses a `submit: true` button or cancels (default false).",
|
|
81
|
+
},
|
|
82
|
+
timeoutMs: { type: "number", description: "Optional wait timeout in milliseconds." },
|
|
83
|
+
focus: { type: "boolean", description: "Focus this tab (default true)." },
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
annotations: { readOnlyHint: false, destructiveHint: false },
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
name: "bypane_app",
|
|
90
|
+
description: "Run a custom agent-authored TypeScript/JavaScript `tui` SDK view inside an isolated companion worker process (for arbitrary canvases, shaders, physics/spring visualizers, custom interactive timelines, multi-pane layouts, or games). Module may import anything from `\"tui\"` (drawBox, drawShader, drawCanvas, createCanvas, createChart, createSpring, Listbox, Table, Input, ScrollArea, split, inset, rgb, …) and `\"bypane/primitives\"` (Slider, Toggle, Segmented, Timeline, Button). Export `default function (ctx) { return { view(frame) {}, keys?(key, frame) {}, fps?, hints?, captureKeys?, summary?, dispose? } }` or named `export function view(frame, ctx)`. `ctx` provides `{ id, title, state, setState(patch), submit(action, patch?), send(msg, patch?), toast(msg, tone?), redraw(), onState(fn) }`. Omit `path`/`code` with an existing `id` and `state` to stream live data into a running app without restarting it.",
|
|
91
|
+
inputSchema: {
|
|
92
|
+
type: "object",
|
|
93
|
+
properties: {
|
|
94
|
+
id: { type: "string", description: "Stable surface ID (reuse to hot-reload code or stream live state)." },
|
|
95
|
+
title: { type: "string", description: "Short tab title." },
|
|
96
|
+
path: { type: "string", description: "Path to a .ts/.js/.mjs module exporting a bypane app." },
|
|
97
|
+
code: { type: "string", description: "Inline TypeScript/JavaScript module source." },
|
|
98
|
+
state: { type: "object", description: "Initial state (or live state patch when omitting path/code)." },
|
|
99
|
+
wait: {
|
|
100
|
+
type: "boolean",
|
|
101
|
+
description: "Block until the human triggers `ctx.submit(...)` or cancels (default false).",
|
|
102
|
+
},
|
|
103
|
+
timeoutMs: { type: "number", description: "Optional wait timeout in milliseconds." },
|
|
104
|
+
focus: { type: "boolean", description: "Focus this tab (default true)." },
|
|
49
105
|
},
|
|
50
106
|
},
|
|
51
107
|
annotations: { readOnlyHint: false, destructiveHint: false },
|
|
@@ -160,6 +216,55 @@ export async function handleMcpToolCall(session, toolName, rawArgs, autoDock = t
|
|
|
160
216
|
const payload = { ...args, origin };
|
|
161
217
|
ipcReq = { id: reqId, op: "present", payload };
|
|
162
218
|
}
|
|
219
|
+
else if (toolName === "bypane_ui") {
|
|
220
|
+
const root = (args.root ?? args.body);
|
|
221
|
+
const payload = {
|
|
222
|
+
id: typeof args.id === "string" ? args.id : undefined,
|
|
223
|
+
kind: "ui",
|
|
224
|
+
title: typeof args.title === "string" ? args.title : "Interactive UI",
|
|
225
|
+
root,
|
|
226
|
+
state: isObj(args.state) ? args.state : undefined,
|
|
227
|
+
preserveState: typeof args.preserveState === "boolean" ? args.preserveState : undefined,
|
|
228
|
+
wait: Boolean(args.wait),
|
|
229
|
+
origin,
|
|
230
|
+
focus: args.focus !== false,
|
|
231
|
+
};
|
|
232
|
+
if (args.wait === true) {
|
|
233
|
+
ipcReq = {
|
|
234
|
+
id: reqId,
|
|
235
|
+
op: "ui_wait",
|
|
236
|
+
payload,
|
|
237
|
+
timeoutMs: typeof args.timeoutMs === "number" ? args.timeoutMs : undefined,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
ipcReq = { id: reqId, op: "present", payload };
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
else if (toolName === "bypane_app") {
|
|
245
|
+
const payload = {
|
|
246
|
+
id: typeof args.id === "string" ? args.id : undefined,
|
|
247
|
+
kind: "app",
|
|
248
|
+
title: typeof args.title === "string" ? args.title : undefined,
|
|
249
|
+
path: typeof args.path === "string" ? args.path : undefined,
|
|
250
|
+
code: typeof args.code === "string" ? args.code : undefined,
|
|
251
|
+
state: isObj(args.state) ? args.state : undefined,
|
|
252
|
+
wait: Boolean(args.wait),
|
|
253
|
+
origin,
|
|
254
|
+
focus: args.focus !== false,
|
|
255
|
+
};
|
|
256
|
+
if (args.wait === true) {
|
|
257
|
+
ipcReq = {
|
|
258
|
+
id: reqId,
|
|
259
|
+
op: "app_wait",
|
|
260
|
+
payload,
|
|
261
|
+
timeoutMs: typeof args.timeoutMs === "number" ? args.timeoutMs : undefined,
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
ipcReq = { id: reqId, op: "present", payload };
|
|
266
|
+
}
|
|
267
|
+
}
|
|
163
268
|
else if (toolName === "bypane_append_log") {
|
|
164
269
|
const surfaceId = String(args.surfaceId ?? "");
|
|
165
270
|
const lines = Array.isArray(args.lines) ? args.lines.map((l) => String(l)) : [];
|
|
@@ -232,7 +337,11 @@ export async function handleMcpToolCall(session, toolName, rawArgs, autoDock = t
|
|
|
232
337
|
}
|
|
233
338
|
try {
|
|
234
339
|
const res = await sendIpc(session, ipcReq, {
|
|
235
|
-
autoDock: autoDock &&
|
|
340
|
+
autoDock: autoDock &&
|
|
341
|
+
(toolName === "bypane_present" ||
|
|
342
|
+
toolName === "bypane_ui" ||
|
|
343
|
+
toolName === "bypane_app" ||
|
|
344
|
+
toolName === "bypane_ask"),
|
|
236
345
|
});
|
|
237
346
|
if (!res.ok) {
|
|
238
347
|
return { text: res.error || "bypane error", isError: true };
|
|
@@ -283,7 +392,7 @@ export function serveMcpStdio(session) {
|
|
|
283
392
|
protocolVersion: version,
|
|
284
393
|
capabilities: { tools: {} },
|
|
285
394
|
serverInfo: { name: "bypane", title: "bypane", version: "0.1.0" },
|
|
286
|
-
instructions: "bypane is a visual companion terminal pane beside the user's chat. Use bypane_present
|
|
395
|
+
instructions: "bypane is a visual companion terminal pane beside the user's chat. Use bypane_present for Markdown plans/checklists, files/images, tables, charts, or logs; bypane_ui to compose custom generative terminal UIs (sliders, toggles, segmented controls, interactive timelines, reactive meters/charts, and buttons); bypane_ask for human-only decisions; and bypane_state to read back interactive state and notes.",
|
|
287
396
|
});
|
|
288
397
|
}
|
|
289
398
|
else if (method === "ping") {
|
package/dist/multiplexer.js
CHANGED
|
@@ -217,9 +217,11 @@ export function openExternally(target) {
|
|
|
217
217
|
export function sendToOriginPane(origin, text) {
|
|
218
218
|
const mux = origin?.mux;
|
|
219
219
|
const paneId = origin?.paneId;
|
|
220
|
+
// End with a blank line so consecutive push-backs never glue onto the previous line in chat composers.
|
|
221
|
+
const payload = text.endsWith("\n") ? text : `${text}\n\n`;
|
|
220
222
|
if (mux === "rex" && paneId) {
|
|
221
223
|
try {
|
|
222
|
-
execFileSync("rex", ["send", "-b", paneId,
|
|
224
|
+
execFileSync("rex", ["send", "-b", paneId, payload], {
|
|
223
225
|
encoding: "utf8",
|
|
224
226
|
timeout: 3000,
|
|
225
227
|
stdio: ["ignore", "pipe", "pipe"],
|
|
@@ -232,7 +234,7 @@ export function sendToOriginPane(origin, text) {
|
|
|
232
234
|
}
|
|
233
235
|
if (mux === "tmux" && paneId) {
|
|
234
236
|
try {
|
|
235
|
-
execFileSync("tmux", ["send-keys", "-t", paneId, "-l",
|
|
237
|
+
execFileSync("tmux", ["send-keys", "-t", paneId, "-l", payload], {
|
|
236
238
|
encoding: "utf8",
|
|
237
239
|
timeout: 3000,
|
|
238
240
|
stdio: ["ignore", "pipe", "pipe"],
|