@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/ui.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { center, CheckboxGroup, createChart, createFilter, createImage, createMarkdown, createSpring, defaultTheme, Dialog, drawBox, drawImage, drawLines, drawMatches, drawSparkline, Input, inset, Listbox, matchesShortcut, paint, ScrollArea, split, Table, Tabs, text, Textarea, truncate, widthOf, } from "tui";
|
|
1
|
+
import { center, CheckboxGroup, createChart, createFilter, createImage, createMarkdown, createSpring, defaultTheme, Dialog, drawBox, drawImage, drawLines, drawMatches, drawSparkline, Input, inset, Listbox, matchesShortcut, paint, ScrollArea, split, Table, Tabs, text, Textarea, truncate, widthOf, wrap, } from "tui";
|
|
2
|
+
import { AppHostManager } from "./app-host.js";
|
|
2
3
|
import { loadDemoSurfaces } from "./demo.js";
|
|
3
4
|
import { focusOriginPane, openExternally, sendToOriginPane } from "./multiplexer.js";
|
|
4
|
-
import {
|
|
5
|
+
import { extractSelectionText, markdownLineText, paintSelectionHighlight, wordBoundsAtColumn, } from "./selection.js";
|
|
6
|
+
import { captureNoteContext, formatBytes, formatFeedbackSummary, sortTableRows } from "./state.js";
|
|
7
|
+
import { drawUiSurface, uiFooterHints } from "./ui-surface.js";
|
|
5
8
|
const SERIES_COLORS = ["#7aa2ff", "#5fd787", "#f5a623", "#ff7a90", "#bb9af7", "#7dcfff"];
|
|
6
9
|
export const bypaneTheme = {
|
|
7
10
|
...defaultTheme,
|
|
@@ -25,10 +28,186 @@ export function createBypaneUi(store, socketPath, hooks = {}) {
|
|
|
25
28
|
// Per-surface render caches
|
|
26
29
|
const imageCache = new Map();
|
|
27
30
|
const chartCache = new Map();
|
|
31
|
+
const canvasCache = new Map();
|
|
28
32
|
const filterCache = new Map();
|
|
29
33
|
const tabSpring = createSpring(0, { stiffness: 260, damping: 26 });
|
|
30
34
|
let mdEngine = null;
|
|
31
35
|
let lastActiveId = "";
|
|
36
|
+
let lastFrame = null;
|
|
37
|
+
const lastWorkerFocus = new Map();
|
|
38
|
+
const focusedAppRev = new Map();
|
|
39
|
+
const dragSelections = new Map();
|
|
40
|
+
function clearSelection(surface) {
|
|
41
|
+
if (!surface)
|
|
42
|
+
return;
|
|
43
|
+
dragSelections.delete(surface.id);
|
|
44
|
+
if (surface.kind === "markdown" || surface.kind === "file") {
|
|
45
|
+
surface.selection = undefined;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function attachTextSelection(frame, surface, vpRect, offset, scrollTo, plainLines, textStartX, layoutWidth, joinWrapped, trackLineNumbers) {
|
|
49
|
+
let sel = dragSelections.get(surface.id);
|
|
50
|
+
if (sel && joinWrapped && sel.layoutWidth !== layoutWidth) {
|
|
51
|
+
dragSelections.delete(surface.id);
|
|
52
|
+
surface.selection = undefined;
|
|
53
|
+
sel = undefined;
|
|
54
|
+
}
|
|
55
|
+
if (sel && (sel.dragging || surface.selection?.text)) {
|
|
56
|
+
paintSelectionHighlight(frame, vpRect, offset, textStartX, sel, plainLines.length);
|
|
57
|
+
}
|
|
58
|
+
if (!frame.mouse || plainLines.length === 0 || vpRect.rows <= 0 || vpRect.columns <= 0)
|
|
59
|
+
return;
|
|
60
|
+
const maxTextCol = Math.max(0, vpRect.x + vpRect.columns - textStartX - 1);
|
|
61
|
+
frame.regions.push({
|
|
62
|
+
rect: vpRect,
|
|
63
|
+
owner: frame.owner,
|
|
64
|
+
trapped: frame.trapDepth > 0,
|
|
65
|
+
press: null,
|
|
66
|
+
mouse: (k) => {
|
|
67
|
+
const m = k.mouse;
|
|
68
|
+
if (!m)
|
|
69
|
+
return false;
|
|
70
|
+
// Let ScrollArea handle wheel scrolling cleanly.
|
|
71
|
+
if (m.action === "scroll-up" ||
|
|
72
|
+
m.action === "scroll-down" ||
|
|
73
|
+
m.action === "scroll-left" ||
|
|
74
|
+
m.action === "scroll-right") {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
const docRow = Math.max(0, Math.min(plainLines.length - 1, offset + (m.y - vpRect.y)));
|
|
78
|
+
const docCol = Math.max(0, Math.min(maxTextCol, m.x - textStartX));
|
|
79
|
+
const cur = dragSelections.get(surface.id);
|
|
80
|
+
if (m.action === "press" && m.button === "left") {
|
|
81
|
+
const now = Date.now();
|
|
82
|
+
const isDouble = cur?.lastClickAt !== undefined &&
|
|
83
|
+
now - cur.lastClickAt < 380 &&
|
|
84
|
+
cur.lastClickRow === docRow &&
|
|
85
|
+
Math.abs((cur.lastClickCol ?? -99) - docCol) <= 1;
|
|
86
|
+
if (isDouble) {
|
|
87
|
+
const bounds = wordBoundsAtColumn(plainLines[docRow] ?? "", docCol);
|
|
88
|
+
if (bounds) {
|
|
89
|
+
const wordSel = {
|
|
90
|
+
anchorRow: docRow,
|
|
91
|
+
anchorCol: bounds.startCol,
|
|
92
|
+
focusRow: docRow,
|
|
93
|
+
focusCol: bounds.endCol,
|
|
94
|
+
dragging: false,
|
|
95
|
+
layoutWidth,
|
|
96
|
+
lastClickAt: 0,
|
|
97
|
+
};
|
|
98
|
+
dragSelections.set(surface.id, wordSel);
|
|
99
|
+
const extracted = extractSelectionText(plainLines, wordSel, joinWrapped);
|
|
100
|
+
surface.selection = extracted.text
|
|
101
|
+
? {
|
|
102
|
+
text: extracted.text,
|
|
103
|
+
...(trackLineNumbers
|
|
104
|
+
? { startLine: extracted.startRow + 1, endLine: extracted.endRow + 1 }
|
|
105
|
+
: {}),
|
|
106
|
+
}
|
|
107
|
+
: undefined;
|
|
108
|
+
if (surface.selection) {
|
|
109
|
+
store.setToast("Selected word — press 'n' to comment, 'y' to copy, Esc to clear", "info", 2600);
|
|
110
|
+
}
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
surface.selection = undefined;
|
|
115
|
+
dragSelections.set(surface.id, {
|
|
116
|
+
anchorRow: docRow,
|
|
117
|
+
anchorCol: docCol,
|
|
118
|
+
focusRow: docRow,
|
|
119
|
+
focusCol: docCol,
|
|
120
|
+
dragging: true,
|
|
121
|
+
layoutWidth,
|
|
122
|
+
lastClickAt: now,
|
|
123
|
+
lastClickRow: docRow,
|
|
124
|
+
lastClickCol: docCol,
|
|
125
|
+
});
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
if (m.action === "drag" && m.button === "left" && cur?.dragging) {
|
|
129
|
+
if (m.y <= vpRect.y && offset > 0) {
|
|
130
|
+
scrollTo(offset - 1);
|
|
131
|
+
}
|
|
132
|
+
else if (m.y >= vpRect.y + vpRect.rows - 1 && offset + vpRect.rows < plainLines.length) {
|
|
133
|
+
scrollTo(offset + 1);
|
|
134
|
+
}
|
|
135
|
+
cur.focusRow = docRow;
|
|
136
|
+
cur.focusCol = docCol;
|
|
137
|
+
const extracted = extractSelectionText(plainLines, cur, joinWrapped);
|
|
138
|
+
surface.selection = extracted.text
|
|
139
|
+
? {
|
|
140
|
+
text: extracted.text,
|
|
141
|
+
...(trackLineNumbers
|
|
142
|
+
? { startLine: extracted.startRow + 1, endLine: extracted.endRow + 1 }
|
|
143
|
+
: {}),
|
|
144
|
+
}
|
|
145
|
+
: undefined;
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
if (m.action === "release" && cur?.dragging) {
|
|
149
|
+
cur.dragging = false;
|
|
150
|
+
if (cur.anchorRow === cur.focusRow && cur.anchorCol === cur.focusCol) {
|
|
151
|
+
surface.selection = undefined;
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
const extracted = extractSelectionText(plainLines, cur, joinWrapped);
|
|
155
|
+
surface.selection = extracted.text
|
|
156
|
+
? {
|
|
157
|
+
text: extracted.text,
|
|
158
|
+
...(trackLineNumbers
|
|
159
|
+
? { startLine: extracted.startRow + 1, endLine: extracted.endRow + 1 }
|
|
160
|
+
: {}),
|
|
161
|
+
}
|
|
162
|
+
: undefined;
|
|
163
|
+
if (surface.selection) {
|
|
164
|
+
store.setToast("Selected fragment — press 'n' to comment, 'y' to copy, Esc to clear", "info", 2600);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
return false;
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
const appHost = new AppHostManager(store, {
|
|
174
|
+
onRedraw: () => {
|
|
175
|
+
lastFrame?.redraw();
|
|
176
|
+
},
|
|
177
|
+
onSubmit: (surface) => {
|
|
178
|
+
if (lastFrame && (surface.origin?.paneId || hooks.onSendFeedback)) {
|
|
179
|
+
triggerSendFeedback(lastFrame, surface);
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
onSend: (surface, message) => {
|
|
183
|
+
if (!lastFrame)
|
|
184
|
+
return;
|
|
185
|
+
const base = formatFeedbackSummary(surface);
|
|
186
|
+
const payload = message.trim() ? `${base}\n${message.trim()}` : base;
|
|
187
|
+
const res = hooks.onSendFeedback
|
|
188
|
+
? hooks.onSendFeedback(surface, payload)
|
|
189
|
+
: sendToOriginPane(surface.origin, payload);
|
|
190
|
+
if (res.ok) {
|
|
191
|
+
const now = Date.now();
|
|
192
|
+
for (const n of surface.notes) {
|
|
193
|
+
if (n.sentAt === undefined)
|
|
194
|
+
n.sentAt = now;
|
|
195
|
+
}
|
|
196
|
+
store.setToast(`Sent update via ${res.via}`, "success");
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
lastFrame.copy(payload);
|
|
200
|
+
store.setToast("Copied update to clipboard (no mux origin pane)", "info");
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
onCopy: (val) => {
|
|
204
|
+
lastFrame?.copy(val);
|
|
205
|
+
store.setToast("Copied to clipboard", "success", 1800);
|
|
206
|
+
},
|
|
207
|
+
});
|
|
208
|
+
const unsubscribeStore = store.subscribe(() => {
|
|
209
|
+
appHost.reconcile(store.activeSurface()?.id ?? "");
|
|
210
|
+
});
|
|
32
211
|
function getMarkdown(frame) {
|
|
33
212
|
if (!mdEngine) {
|
|
34
213
|
mdEngine = createMarkdown(frame.styles, frame.theme);
|
|
@@ -75,6 +254,24 @@ export function createBypaneUi(store, socketPath, hooks = {}) {
|
|
|
75
254
|
? "✓ "
|
|
76
255
|
: "× ";
|
|
77
256
|
}
|
|
257
|
+
if (surface.kind === "ui" && surface.submission.status !== "idle") {
|
|
258
|
+
return surface.submission.status === "pending"
|
|
259
|
+
? "● "
|
|
260
|
+
: surface.submission.status === "submitted"
|
|
261
|
+
? "✓ "
|
|
262
|
+
: "× ";
|
|
263
|
+
}
|
|
264
|
+
if (surface.kind === "app") {
|
|
265
|
+
if (surface.runtimeStatus === "error")
|
|
266
|
+
return "! ";
|
|
267
|
+
if (surface.submission.status !== "idle") {
|
|
268
|
+
return surface.submission.status === "pending"
|
|
269
|
+
? "● "
|
|
270
|
+
: surface.submission.status === "submitted"
|
|
271
|
+
? "✓ "
|
|
272
|
+
: "× ";
|
|
273
|
+
}
|
|
274
|
+
}
|
|
78
275
|
return surface.unread ? "• " : "";
|
|
79
276
|
}
|
|
80
277
|
function computeTabLabels(columns) {
|
|
@@ -82,9 +279,9 @@ export function createBypaneUi(store, socketPath, hooks = {}) {
|
|
|
82
279
|
if (count === 0)
|
|
83
280
|
return [];
|
|
84
281
|
const avail = Math.max(12, columns - 2);
|
|
85
|
-
// Reserve space for padding (" " + label + " ") and index/badge prefix so all tabs fit cleanly.
|
|
282
|
+
// Reserve space for padding (" " + label + " ") and index/badge prefix ("1:• ") so all tabs fit cleanly.
|
|
86
283
|
const perTabBudget = Math.max(7, Math.floor(avail / count));
|
|
87
|
-
const maxTitleChars = Math.max(
|
|
284
|
+
const maxTitleChars = Math.max(3, Math.min(20, perTabBudget - 6));
|
|
88
285
|
let x = 1;
|
|
89
286
|
return store.surfaces.map((s, i) => {
|
|
90
287
|
const prefix = `${i < 9 ? `${i + 1}:` : ""}${badgeText(s)}`;
|
|
@@ -201,9 +398,13 @@ export function createBypaneUi(store, socketPath, hooks = {}) {
|
|
|
201
398
|
return;
|
|
202
399
|
rule(frame, rect.y, rect);
|
|
203
400
|
text(frame, rect.x + 1, rect.y, ` Notes (${surface.notes.length}) `, frame.theme.primary, rect);
|
|
401
|
+
const avail = Math.max(8, rect.columns - 4);
|
|
402
|
+
const maxCtx = Math.max(10, Math.floor(avail * 0.45));
|
|
204
403
|
for (let i = 0; i < Math.min(rect.rows - 1, surface.notes.length); i++) {
|
|
205
404
|
const note = surface.notes[surface.notes.length - 1 - i];
|
|
206
|
-
|
|
405
|
+
const bullet = note.sentAt !== undefined ? "✓" : "•";
|
|
406
|
+
const line = note.context ? `[${truncate(note.context, maxCtx)}] ${note.text}` : note.text;
|
|
407
|
+
text(frame, rect.x + 2, rect.y + 1 + i, `${bullet} ${truncate(line, avail)}`, frame.theme.muted, rect);
|
|
207
408
|
}
|
|
208
409
|
}
|
|
209
410
|
function drawMarkdownSurface(frame, body, surface) {
|
|
@@ -213,14 +414,18 @@ export function createBypaneUi(store, socketPath, hooks = {}) {
|
|
|
213
414
|
const [docArea, checkArea, noteArea] = split(body, "rows", [-1, checklistRows, notesRows]);
|
|
214
415
|
if (docArea && docArea.rows > 0) {
|
|
215
416
|
const inner = inset(docArea, [0, 1]);
|
|
417
|
+
const layoutWidth = Math.max(10, inner.columns - 1);
|
|
216
418
|
const md = getMarkdown(frame);
|
|
217
|
-
const lines = md.lines(surface.content,
|
|
419
|
+
const lines = md.lines(surface.content, layoutWidth);
|
|
420
|
+
const plainLines = lines.map(markdownLineText);
|
|
218
421
|
ScrollArea.Root(frame, {
|
|
219
422
|
id: `md-scroll-${surface.id}`,
|
|
220
423
|
label: `${surface.title} document`,
|
|
221
424
|
total: lines.length,
|
|
222
425
|
}, (area) => ScrollArea.Viewport(area, inner, (vp) => {
|
|
223
|
-
|
|
426
|
+
const offset = vp.api.offset();
|
|
427
|
+
drawLines(frame, vp.rect, lines, offset);
|
|
428
|
+
attachTextSelection(frame, surface, vp.rect, offset, (n) => vp.api.scrollTo(n), plainLines, vp.rect.x, layoutWidth, true, false);
|
|
224
429
|
}));
|
|
225
430
|
}
|
|
226
431
|
if (hasChecklist && checkArea && checkArea.rows >= 2) {
|
|
@@ -282,7 +487,7 @@ export function createBypaneUi(store, socketPath, hooks = {}) {
|
|
|
282
487
|
}
|
|
283
488
|
}
|
|
284
489
|
else {
|
|
285
|
-
const rawLines = (surface.content ?? "").split(/\r?\n/);
|
|
490
|
+
const rawLines = (surface.content ?? "").split(/\r?\n/).map((l) => l.replace(/\t/g, " "));
|
|
286
491
|
const gutterW = Math.max(3, String(rawLines.length).length) + 2;
|
|
287
492
|
const defaultOffset = surface.highlightStart !== undefined ? Math.max(0, surface.highlightStart - 4) : 0;
|
|
288
493
|
const hiStart = surface.highlightStart ?? -1;
|
|
@@ -303,9 +508,10 @@ export function createBypaneUi(store, socketPath, hooks = {}) {
|
|
|
303
508
|
}
|
|
304
509
|
const numStr = `${String(lineNum).padStart(gutterW - 2, " ")} ${isHi ? "▎" : "│"}`;
|
|
305
510
|
text(frame, vp.rect.x, y, numStr, isHi ? frame.theme.primary : frame.theme.muted, vp.rect);
|
|
306
|
-
const lineText =
|
|
511
|
+
const lineText = rawLines[offset + row] ?? "";
|
|
307
512
|
text(frame, vp.rect.x + gutterW + 1, y, lineText, isHi ? { fg: "#e6edf7", bg: "#1c2840" } : 0, vp.rect);
|
|
308
513
|
}
|
|
514
|
+
attachTextSelection(frame, surface, vp.rect, offset, (n) => vp.api.scrollTo(n), rawLines, vp.rect.x + gutterW + 1, vp.rect.columns, false, true);
|
|
309
515
|
}));
|
|
310
516
|
}
|
|
311
517
|
}
|
|
@@ -699,6 +905,156 @@ export function createBypaneUi(store, socketPath, hooks = {}) {
|
|
|
699
905
|
if (noteArea && notesRows > 0)
|
|
700
906
|
drawNotesStrip(frame, noteArea, surface);
|
|
701
907
|
}
|
|
908
|
+
function drawAppSurface(frame, body, surface) {
|
|
909
|
+
const showStatusRow = surface.submission.status !== "idle";
|
|
910
|
+
const notesRows = surface.notes.length > 0 ? Math.min(4, surface.notes.length + 1) : 0;
|
|
911
|
+
const [statusRow, mainArea, noteArea] = split(body, "rows", [showStatusRow ? 1 : 0, -1, notesRows]);
|
|
912
|
+
if (showStatusRow && statusRow) {
|
|
913
|
+
const sub = surface.submission;
|
|
914
|
+
if (sub.status === "pending") {
|
|
915
|
+
text(frame, statusRow.x + 1, statusRow.y, "● ACTION REQUIRED", { fg: "#f5a623", bold: true }, statusRow);
|
|
916
|
+
text(frame, statusRow.x + 20, statusRow.y, "Interact below to submit (Esc cancels)", frame.theme.muted, statusRow);
|
|
917
|
+
}
|
|
918
|
+
else if (sub.status === "submitted") {
|
|
919
|
+
const badge = `✓ SUBMITTED (${sub.action})`;
|
|
920
|
+
const x1 = text(frame, statusRow.x + 1, statusRow.y, badge, frame.theme.success, statusRow);
|
|
921
|
+
text(frame, x1 + 2, statusRow.y, "Interact and resubmit anytime", frame.theme.muted, statusRow);
|
|
922
|
+
}
|
|
923
|
+
else if (sub.status === "cancelled") {
|
|
924
|
+
text(frame, statusRow.x + 1, statusRow.y, "× CANCELLED", frame.theme.destructive, statusRow);
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
if (mainArea && mainArea.rows > 0 && mainArea.columns > 0) {
|
|
928
|
+
appHost.sync(surface, mainArea.columns, mainArea.rows, true);
|
|
929
|
+
if (surface.runtimeStatus === "error") {
|
|
930
|
+
const card = inset(mainArea, [1, 2]);
|
|
931
|
+
if (card.rows >= 4 && card.columns >= 16) {
|
|
932
|
+
const inner = drawBox(frame.cells, card, {
|
|
933
|
+
title: `App Error · ${truncate(surface.title, 28)}`,
|
|
934
|
+
style: frame.styles.style(frame.theme.destructive),
|
|
935
|
+
});
|
|
936
|
+
const pad = inset(inner, [0, 1]);
|
|
937
|
+
const errLines = wrap(surface.runtimeError || "Unknown worker error", Math.max(10, pad.columns));
|
|
938
|
+
let y = pad.y;
|
|
939
|
+
for (const line of errLines) {
|
|
940
|
+
if (y >= pad.y + pad.rows - 2)
|
|
941
|
+
break;
|
|
942
|
+
text(frame, pad.x, y++, line, frame.theme.destructive, pad);
|
|
943
|
+
}
|
|
944
|
+
if (pad.rows >= 2) {
|
|
945
|
+
text(frame, pad.x, pad.y + pad.rows - 1, truncate("Fix the module and re-push with the same --id to hot-reload.", pad.columns), frame.theme.muted, pad);
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
else {
|
|
950
|
+
const meta = appHost.getFrameMeta(surface.id);
|
|
951
|
+
const slotPrefix = `app-slot:${surface.id}:`;
|
|
952
|
+
const viewportId = `app-viewport:${surface.id}`;
|
|
953
|
+
const isAppFocused = !noteDialogOpen &&
|
|
954
|
+
!helpOpen &&
|
|
955
|
+
(frame.focused === viewportId || frame.focused.startsWith(slotPrefix));
|
|
956
|
+
const blitted = appHost.blit(surface.id, frame, mainArea, isAppFocused);
|
|
957
|
+
if (!blitted) {
|
|
958
|
+
const pad = inset(mainArea, [1, 2]);
|
|
959
|
+
text(frame, pad.x, pad.y, `Starting custom tui app (${surface.title})…`, frame.theme.muted, pad);
|
|
960
|
+
}
|
|
961
|
+
else if (focusedAppRev.get(surface.id) !== surface.revision) {
|
|
962
|
+
focusedAppRev.set(surface.id, surface.revision);
|
|
963
|
+
if (!noteDialogOpen &&
|
|
964
|
+
!helpOpen &&
|
|
965
|
+
(frame.focused === "" || frame.focused.startsWith("workspace-tabs"))) {
|
|
966
|
+
frame.focused =
|
|
967
|
+
meta.focusables.length > 0
|
|
968
|
+
? `${slotPrefix}${meta.focused || meta.focusables[0]}`
|
|
969
|
+
: viewportId;
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
const forwardKey = (k) => {
|
|
973
|
+
// Always keep Ctrl shortcuts responsive for bypane workspace chrome.
|
|
974
|
+
if (matchesShortcut(k, "ctrl+e") ||
|
|
975
|
+
matchesShortcut(k, "alt+n") ||
|
|
976
|
+
matchesShortcut(k, "ctrl+s") ||
|
|
977
|
+
matchesShortcut(k, "ctrl+w")) {
|
|
978
|
+
return false;
|
|
979
|
+
}
|
|
980
|
+
if (k.name === "escape" && surface.submission.status === "pending" && !meta.hasTrap) {
|
|
981
|
+
return false;
|
|
982
|
+
}
|
|
983
|
+
if (!meta.textInputFocused && !meta.hasTrap && k.name === "char" && !k.ctrl && !k.alt) {
|
|
984
|
+
const ch = k.text;
|
|
985
|
+
if ((ch >= "1" && ch <= "9") || ch === "[" || ch === "]" || ch === "?") {
|
|
986
|
+
return false;
|
|
987
|
+
}
|
|
988
|
+
if (!surface.captureKeys && (ch === "n" || ch === "s" || ch === "w" || ch === "g" || ch === "y" || ch === "q")) {
|
|
989
|
+
return false;
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
appHost.sendKey(surface.id, k);
|
|
993
|
+
return true;
|
|
994
|
+
};
|
|
995
|
+
const trapped = frame.trapDepth > 0;
|
|
996
|
+
if (meta.focusables.length > 0) {
|
|
997
|
+
for (const wfId of meta.focusables) {
|
|
998
|
+
frame.focusables.push({
|
|
999
|
+
id: `${slotPrefix}${wfId}`,
|
|
1000
|
+
trapped,
|
|
1001
|
+
keys: forwardKey,
|
|
1002
|
+
});
|
|
1003
|
+
}
|
|
1004
|
+
const prevWorker = lastWorkerFocus.get(surface.id) ?? "";
|
|
1005
|
+
if (meta.focused && meta.focused !== prevWorker) {
|
|
1006
|
+
// Worker moved focus internally (e.g. via mouse click): mirror to host focus slot.
|
|
1007
|
+
lastWorkerFocus.set(surface.id, meta.focused);
|
|
1008
|
+
if (!noteDialogOpen && !helpOpen && !frame.focused.startsWith("workspace-tabs")) {
|
|
1009
|
+
frame.focused = `${slotPrefix}${meta.focused}`;
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
else if (frame.focused.startsWith(slotPrefix)) {
|
|
1013
|
+
// Host moved focus via Tab / Shift+Tab: push to worker.
|
|
1014
|
+
const targetWf = frame.focused.slice(slotPrefix.length);
|
|
1015
|
+
if (targetWf && targetWf !== prevWorker) {
|
|
1016
|
+
lastWorkerFocus.set(surface.id, targetWf);
|
|
1017
|
+
appHost.sendFocus(surface.id, targetWf);
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
else if (frame.focused === "" && meta.focused) {
|
|
1021
|
+
lastWorkerFocus.set(surface.id, meta.focused);
|
|
1022
|
+
frame.focused = `${slotPrefix}${meta.focused}`;
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
else {
|
|
1026
|
+
frame.focusables.push({
|
|
1027
|
+
id: viewportId,
|
|
1028
|
+
trapped,
|
|
1029
|
+
keys: forwardKey,
|
|
1030
|
+
});
|
|
1031
|
+
}
|
|
1032
|
+
if (frame.mouse) {
|
|
1033
|
+
const owner = meta.focusables.length > 0
|
|
1034
|
+
? `${slotPrefix}${meta.focused || meta.focusables[0]}`
|
|
1035
|
+
: viewportId;
|
|
1036
|
+
frame.regions.push({
|
|
1037
|
+
rect: mainArea,
|
|
1038
|
+
owner,
|
|
1039
|
+
trapped,
|
|
1040
|
+
press: null,
|
|
1041
|
+
mouse: (k) => {
|
|
1042
|
+
if (!k.mouse)
|
|
1043
|
+
return false;
|
|
1044
|
+
appHost.sendMouse(surface.id, {
|
|
1045
|
+
...k.mouse,
|
|
1046
|
+
x: k.mouse.x - mainArea.x,
|
|
1047
|
+
y: k.mouse.y - mainArea.y,
|
|
1048
|
+
}, k.ctrl, k.alt, k.shift);
|
|
1049
|
+
return true;
|
|
1050
|
+
},
|
|
1051
|
+
});
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
if (noteArea && notesRows > 0)
|
|
1056
|
+
drawNotesStrip(frame, noteArea, surface);
|
|
1057
|
+
}
|
|
702
1058
|
function drawFooter(frame, rect, active) {
|
|
703
1059
|
rule(frame, rect.y, rect);
|
|
704
1060
|
const barY = rect.y + 1;
|
|
@@ -719,27 +1075,44 @@ export function createBypaneUi(store, socketPath, hooks = {}) {
|
|
|
719
1075
|
hints.push("d demo", "? help", "q quit");
|
|
720
1076
|
}
|
|
721
1077
|
else {
|
|
722
|
-
if (
|
|
723
|
-
hints.push(
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
1078
|
+
if ((active.kind === "markdown" || active.kind === "file") && active.selection?.text) {
|
|
1079
|
+
hints.push("n comment selection", "y copy", "Esc clear");
|
|
1080
|
+
}
|
|
1081
|
+
else {
|
|
1082
|
+
if (store.surfaces.length > 1)
|
|
1083
|
+
hints.push(`1-${Math.min(9, store.surfaces.length)} tabs`);
|
|
1084
|
+
if (active.kind === "table" || active.kind === "log")
|
|
1085
|
+
hints.push("/ filter");
|
|
1086
|
+
if (active.kind === "table")
|
|
1087
|
+
hints.push("r sort", "y copy");
|
|
1088
|
+
if (active.kind === "file" || active.kind === "image")
|
|
1089
|
+
hints.push("o open");
|
|
1090
|
+
if (active.kind === "markdown" && active.checklist.length > 0)
|
|
1091
|
+
hints.push("Tab checks");
|
|
1092
|
+
if (active.kind === "markdown" || (active.kind === "file" && !active.binary))
|
|
1093
|
+
hints.push("drag select");
|
|
1094
|
+
if (active.kind === "ui")
|
|
1095
|
+
hints.push(...uiFooterHints(active.root));
|
|
1096
|
+
if (active.kind === "app" && active.hints && active.hints.length > 0)
|
|
1097
|
+
hints.push(...active.hints);
|
|
1098
|
+
if (active.kind === "app" && active.captureKeys) {
|
|
1099
|
+
hints.push("Ctrl+E note", "Ctrl+S send", "Ctrl+W close", "?");
|
|
1100
|
+
}
|
|
1101
|
+
else {
|
|
1102
|
+
hints.push("n note", "s send");
|
|
1103
|
+
if (active.origin?.paneId)
|
|
1104
|
+
hints.push("g origin");
|
|
1105
|
+
hints.push("w close", "?");
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
736
1108
|
}
|
|
737
1109
|
text(frame, rect.x + 1, barY, truncate(hints.join(" · "), rect.columns - 2), frame.theme.muted, rect);
|
|
738
1110
|
}
|
|
739
1111
|
function drawOverlays(frame) {
|
|
740
1112
|
if (noteDialogOpen) {
|
|
741
1113
|
const active = store.activeSurface();
|
|
742
|
-
const
|
|
1114
|
+
const noteCtx = active ? captureNoteContext(active) : undefined;
|
|
1115
|
+
const dialogRect = center(frame.rect, Math.min(60, Math.max(28, frame.rect.columns - 6)), noteCtx ? 8 : 7);
|
|
743
1116
|
Dialog.Root(frame, {
|
|
744
1117
|
id: "note-dialog",
|
|
745
1118
|
label: "Add note",
|
|
@@ -750,7 +1123,14 @@ export function createBypaneUi(store, socketPath, hooks = {}) {
|
|
|
750
1123
|
},
|
|
751
1124
|
}, (dlg) => Dialog.Content(dlg, dialogRect, (content) => {
|
|
752
1125
|
const inner = inset(content.rect, [0, 1]);
|
|
753
|
-
|
|
1126
|
+
const canAutoSend = Boolean(active && (active.origin?.paneId || hooks.onSendFeedback));
|
|
1127
|
+
text(frame, inner.x, inner.y, canAutoSend
|
|
1128
|
+
? "Leave feedback for the agent (Enter sends · Esc closes):"
|
|
1129
|
+
: "Leave feedback for the agent (Enter saves · Esc closes):", frame.theme.muted, inner);
|
|
1130
|
+
if (noteCtx) {
|
|
1131
|
+
const prefixEnd = text(frame, inner.x, inner.y + 1, "Scope: ", frame.theme.primary, inner);
|
|
1132
|
+
text(frame, prefixEnd, inner.y + 1, truncate(noteCtx, Math.max(6, inner.columns - 7)), frame.theme.code, inner);
|
|
1133
|
+
}
|
|
754
1134
|
Input.Root(frame, {
|
|
755
1135
|
id: "note-input",
|
|
756
1136
|
label: "Note text",
|
|
@@ -760,15 +1140,22 @@ export function createBypaneUi(store, socketPath, hooks = {}) {
|
|
|
760
1140
|
noteDraft = val;
|
|
761
1141
|
},
|
|
762
1142
|
onSubmit: (val) => {
|
|
763
|
-
|
|
764
|
-
|
|
1143
|
+
const created = active ? store.addNote(active.id, val) : null;
|
|
1144
|
+
if (active && created) {
|
|
1145
|
+
if (active.origin?.paneId || hooks.onSendFeedback) {
|
|
1146
|
+
triggerSendFeedback(frame, active, created);
|
|
1147
|
+
}
|
|
1148
|
+
else {
|
|
1149
|
+
store.setToast("Note saved (press 's' to copy)", "success");
|
|
1150
|
+
}
|
|
1151
|
+
clearSelection(active);
|
|
765
1152
|
}
|
|
766
1153
|
noteDraft = "";
|
|
767
1154
|
noteDialogOpen = false;
|
|
768
1155
|
},
|
|
769
1156
|
}, (root) => Input.Field(root, {
|
|
770
1157
|
x: inner.x,
|
|
771
|
-
y: inner.y + 2,
|
|
1158
|
+
y: inner.y + (noteCtx ? 3 : 2),
|
|
772
1159
|
columns: Math.max(8, inner.columns),
|
|
773
1160
|
rows: 1,
|
|
774
1161
|
}));
|
|
@@ -809,7 +1196,9 @@ export function createBypaneUi(store, socketPath, hooks = {}) {
|
|
|
809
1196
|
}
|
|
810
1197
|
}
|
|
811
1198
|
function view(frame) {
|
|
1199
|
+
lastFrame = frame;
|
|
812
1200
|
const active = store.activeSurface();
|
|
1201
|
+
appHost.reconcile(active?.id ?? "");
|
|
813
1202
|
const headerRows = store.surfaces.length > 0 ? 3 : 2;
|
|
814
1203
|
const [headerRect, bodyRect, footerRect] = split(frame.rect, "rows", [headerRows, -1, 2]);
|
|
815
1204
|
if (headerRect)
|
|
@@ -840,6 +1229,22 @@ export function createBypaneUi(store, socketPath, hooks = {}) {
|
|
|
840
1229
|
else if (active.kind === "ask") {
|
|
841
1230
|
drawAskSurface(frame, bodyRect, active);
|
|
842
1231
|
}
|
|
1232
|
+
else if (active.kind === "ui") {
|
|
1233
|
+
drawUiSurface(frame, bodyRect, active, store, {
|
|
1234
|
+
charts: chartCache,
|
|
1235
|
+
canvases: canvasCache,
|
|
1236
|
+
getMarkdown,
|
|
1237
|
+
drawNotesStrip,
|
|
1238
|
+
onUiSubmit: (f, surface) => {
|
|
1239
|
+
if (surface.origin?.paneId || hooks.onSendFeedback) {
|
|
1240
|
+
triggerSendFeedback(f, surface);
|
|
1241
|
+
}
|
|
1242
|
+
},
|
|
1243
|
+
});
|
|
1244
|
+
}
|
|
1245
|
+
else if (active.kind === "app") {
|
|
1246
|
+
drawAppSurface(frame, bodyRect, active);
|
|
1247
|
+
}
|
|
843
1248
|
}
|
|
844
1249
|
if (headerRect)
|
|
845
1250
|
drawTabsBar(frame, headerRect);
|
|
@@ -847,13 +1252,23 @@ export function createBypaneUi(store, socketPath, hooks = {}) {
|
|
|
847
1252
|
drawFooter(frame, footerRect, active);
|
|
848
1253
|
drawOverlays(frame);
|
|
849
1254
|
}
|
|
850
|
-
function triggerSendFeedback(frame, active) {
|
|
851
|
-
const summary = formatFeedbackSummary(active);
|
|
1255
|
+
function triggerSendFeedback(frame, active, singleNote) {
|
|
1256
|
+
const summary = formatFeedbackSummary(active, singleNote ? { singleNote } : undefined);
|
|
852
1257
|
const res = hooks.onSendFeedback
|
|
853
1258
|
? hooks.onSendFeedback(active, summary)
|
|
854
1259
|
: sendToOriginPane(active.origin, summary);
|
|
855
1260
|
if (res.ok) {
|
|
856
|
-
|
|
1261
|
+
const now = Date.now();
|
|
1262
|
+
if (singleNote) {
|
|
1263
|
+
singleNote.sentAt = now;
|
|
1264
|
+
}
|
|
1265
|
+
else {
|
|
1266
|
+
for (const n of active.notes) {
|
|
1267
|
+
if (n.sentAt === undefined)
|
|
1268
|
+
n.sentAt = now;
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
store.setToast(singleNote ? `Sent note via ${res.via}` : `Sent feedback via ${res.via}`, "success");
|
|
857
1272
|
}
|
|
858
1273
|
else {
|
|
859
1274
|
frame.copy(summary);
|
|
@@ -882,10 +1297,22 @@ export function createBypaneUi(store, socketPath, hooks = {}) {
|
|
|
882
1297
|
frame.focused = "";
|
|
883
1298
|
return true;
|
|
884
1299
|
}
|
|
1300
|
+
if (active && (active.kind === "markdown" || active.kind === "file") && active.selection) {
|
|
1301
|
+
clearSelection(active);
|
|
1302
|
+
return true;
|
|
1303
|
+
}
|
|
885
1304
|
if (active && active.kind === "ask" && active.answer.status === "pending") {
|
|
886
1305
|
store.cancelAsk(active.id);
|
|
887
1306
|
return true;
|
|
888
1307
|
}
|
|
1308
|
+
if (active && active.kind === "ui" && active.submission.status === "pending") {
|
|
1309
|
+
store.cancelUi(active.id);
|
|
1310
|
+
return true;
|
|
1311
|
+
}
|
|
1312
|
+
if (active && active.kind === "app" && active.submission.status === "pending") {
|
|
1313
|
+
store.cancelApp(active.id);
|
|
1314
|
+
return true;
|
|
1315
|
+
}
|
|
889
1316
|
return false;
|
|
890
1317
|
}
|
|
891
1318
|
// Ctrl shortcuts work reliably even from inside Lists / Tables (never collide with typeahead or Ctrl+N/P nav).
|
|
@@ -962,9 +1389,14 @@ export function createBypaneUi(store, socketPath, hooks = {}) {
|
|
|
962
1389
|
return true;
|
|
963
1390
|
}
|
|
964
1391
|
if (ch === "y" && active) {
|
|
1392
|
+
if ((active.kind === "markdown" || active.kind === "file") && active.selection?.text) {
|
|
1393
|
+
frame.copy(active.selection.text);
|
|
1394
|
+
store.setToast("Copied selected fragment to clipboard", "success", 1800);
|
|
1395
|
+
return true;
|
|
1396
|
+
}
|
|
965
1397
|
const textToCopy = active.kind === "file" || active.kind === "image"
|
|
966
1398
|
? active.path
|
|
967
|
-
: formatFeedbackSummary(active);
|
|
1399
|
+
: formatFeedbackSummary(active, { includeAllNotes: true });
|
|
968
1400
|
frame.copy(textToCopy);
|
|
969
1401
|
store.setToast("Copied to clipboard", "success", 1800);
|
|
970
1402
|
return true;
|
|
@@ -1002,19 +1434,33 @@ export function createBypaneUi(store, socketPath, hooks = {}) {
|
|
|
1002
1434
|
return false;
|
|
1003
1435
|
}
|
|
1004
1436
|
function allowAgentStep(step) {
|
|
1005
|
-
// Strictly prevent agents from answering or submitting human-only
|
|
1437
|
+
// Strictly prevent agents from answering or submitting human-only gates or editing human notes.
|
|
1006
1438
|
if (step.ref.startsWith("ask-")) {
|
|
1007
1439
|
return step.action === "highlight" || step.action === "focus";
|
|
1008
1440
|
}
|
|
1441
|
+
if (step.ref.startsWith("ui-submit-")) {
|
|
1442
|
+
return step.action === "focus";
|
|
1443
|
+
}
|
|
1009
1444
|
if (step.ref.startsWith("note-") || step.component === "dialog") {
|
|
1010
1445
|
return false;
|
|
1011
1446
|
}
|
|
1012
|
-
// Also block untargeted key presses/typing while a pending ask
|
|
1447
|
+
// Also block untargeted key presses/typing while a pending ask, ui, or app gate is active.
|
|
1013
1448
|
const active = store.activeSurface();
|
|
1014
|
-
if (
|
|
1449
|
+
if (active?.kind === "app" &&
|
|
1450
|
+
active.submission.status === "pending" &&
|
|
1451
|
+
(!step.ref || step.ref.startsWith("app-slot:") || step.ref.startsWith("app-viewport:"))) {
|
|
1452
|
+
return false;
|
|
1453
|
+
}
|
|
1454
|
+
if (!step.ref &&
|
|
1455
|
+
((active?.kind === "ask" && active.answer.status === "pending") ||
|
|
1456
|
+
(active?.kind === "ui" && active.submission.status === "pending"))) {
|
|
1015
1457
|
return false;
|
|
1016
1458
|
}
|
|
1017
1459
|
return true;
|
|
1018
1460
|
}
|
|
1019
|
-
|
|
1461
|
+
function dispose() {
|
|
1462
|
+
unsubscribeStore();
|
|
1463
|
+
appHost.disposeAll();
|
|
1464
|
+
}
|
|
1465
|
+
return { view, keys, allowAgentStep, dispose };
|
|
1020
1466
|
}
|