@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
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { clusterAt, clusterEnd, clusterWidth } from "tui";
|
|
2
|
+
export function normalizeSelection(sel) {
|
|
3
|
+
if (sel.anchorRow < sel.focusRow || (sel.anchorRow === sel.focusRow && sel.anchorCol <= sel.focusCol)) {
|
|
4
|
+
return {
|
|
5
|
+
startRow: sel.anchorRow,
|
|
6
|
+
startCol: sel.anchorCol,
|
|
7
|
+
endRow: sel.focusRow,
|
|
8
|
+
endCol: sel.focusCol,
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
return {
|
|
12
|
+
startRow: sel.focusRow,
|
|
13
|
+
startCol: sel.focusCol,
|
|
14
|
+
endRow: sel.anchorRow,
|
|
15
|
+
endCol: sel.anchorCol,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export function markdownLineText(line) {
|
|
19
|
+
let out = "";
|
|
20
|
+
for (const span of line)
|
|
21
|
+
out += span.text;
|
|
22
|
+
return out;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Slices `text` by inclusive display-column range `[startCol, endCol]` using grapheme cluster widths.
|
|
26
|
+
*/
|
|
27
|
+
export function sliceByColumns(str, startCol, endCol) {
|
|
28
|
+
if (!str || endCol < startCol || endCol < 0)
|
|
29
|
+
return "";
|
|
30
|
+
const lo = Math.max(0, startCol);
|
|
31
|
+
let col = 0;
|
|
32
|
+
let idx = 0;
|
|
33
|
+
let out = "";
|
|
34
|
+
while (idx < str.length) {
|
|
35
|
+
const packed = clusterAt(str, idx);
|
|
36
|
+
const end = clusterEnd(packed);
|
|
37
|
+
const w = Math.max(1, clusterWidth(packed));
|
|
38
|
+
const nextCol = col + w;
|
|
39
|
+
if (nextCol > lo && col <= endCol) {
|
|
40
|
+
out += str.slice(idx, end);
|
|
41
|
+
}
|
|
42
|
+
col = nextCol;
|
|
43
|
+
idx = end;
|
|
44
|
+
if (col > endCol)
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Finds the display-column bounds `[startCol, endCol]` of the word at display column `targetCol`.
|
|
51
|
+
*/
|
|
52
|
+
export function wordBoundsAtColumn(str, targetCol) {
|
|
53
|
+
if (!str)
|
|
54
|
+
return null;
|
|
55
|
+
const cells = [];
|
|
56
|
+
let col = 0;
|
|
57
|
+
let idx = 0;
|
|
58
|
+
while (idx < str.length) {
|
|
59
|
+
const packed = clusterAt(str, idx);
|
|
60
|
+
const end = clusterEnd(packed);
|
|
61
|
+
const w = Math.max(1, clusterWidth(packed));
|
|
62
|
+
const ch = str.slice(idx, end);
|
|
63
|
+
const isWord = /[\p{L}\p{N}_\-./]/u.test(ch);
|
|
64
|
+
cells.push({ ch, col, w, isWord });
|
|
65
|
+
col += w;
|
|
66
|
+
idx = end;
|
|
67
|
+
}
|
|
68
|
+
if (cells.length === 0)
|
|
69
|
+
return null;
|
|
70
|
+
let hit = cells.findIndex((c) => targetCol >= c.col && targetCol < c.col + c.w);
|
|
71
|
+
if (hit < 0)
|
|
72
|
+
return null;
|
|
73
|
+
const wantWord = cells[hit].isWord;
|
|
74
|
+
if (!wantWord && /\s/.test(cells[hit].ch))
|
|
75
|
+
return null;
|
|
76
|
+
let left = hit;
|
|
77
|
+
while (left > 0 && cells[left - 1].isWord === wantWord && !/\s/.test(cells[left - 1].ch)) {
|
|
78
|
+
left--;
|
|
79
|
+
}
|
|
80
|
+
let right = hit;
|
|
81
|
+
while (right + 1 < cells.length && cells[right + 1].isWord === wantWord && !/\s/.test(cells[right + 1].ch)) {
|
|
82
|
+
right++;
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
startCol: cells[left].col,
|
|
86
|
+
endCol: cells[right].col + cells[right].w - 1,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Extracts selected text across rendered rows. For wrapped Markdown (`joinWrapped: true`),
|
|
91
|
+
* non-empty adjacent lines join with a single space while blank lines preserve paragraph breaks.
|
|
92
|
+
*/
|
|
93
|
+
export function extractSelectionText(lines, sel, joinWrapped) {
|
|
94
|
+
const { startRow, startCol, endRow, endCol } = normalizeSelection(sel);
|
|
95
|
+
const r0 = Math.max(0, Math.min(lines.length - 1, startRow));
|
|
96
|
+
const r1 = Math.max(0, Math.min(lines.length - 1, endRow));
|
|
97
|
+
if (lines.length === 0)
|
|
98
|
+
return { text: "", startRow: r0, endRow: r1 };
|
|
99
|
+
if (r0 === r1) {
|
|
100
|
+
const snippet = sliceByColumns(lines[r0] ?? "", startCol, endCol).trim();
|
|
101
|
+
return { text: snippet, startRow: r0, endRow: r1 };
|
|
102
|
+
}
|
|
103
|
+
const parts = [];
|
|
104
|
+
for (let r = r0; r <= r1; r++) {
|
|
105
|
+
const raw = lines[r] ?? "";
|
|
106
|
+
if (r === r0) {
|
|
107
|
+
parts.push(sliceByColumns(raw, startCol, Number.MAX_SAFE_INTEGER).trimEnd());
|
|
108
|
+
}
|
|
109
|
+
else if (r === r1) {
|
|
110
|
+
parts.push(sliceByColumns(raw, 0, endCol).trimEnd());
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
parts.push(raw.trimEnd());
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (!joinWrapped) {
|
|
117
|
+
return { text: parts.join("\n").trim(), startRow: r0, endRow: r1 };
|
|
118
|
+
}
|
|
119
|
+
// Join wrapped prose lines smoothly while preserving intentional blank-line paragraph breaks.
|
|
120
|
+
let out = "";
|
|
121
|
+
for (let i = 0; i < parts.length; i++) {
|
|
122
|
+
const p = parts[i].trim();
|
|
123
|
+
if (!p) {
|
|
124
|
+
if (out && !out.endsWith("\n\n"))
|
|
125
|
+
out += "\n\n";
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
if (!out || out.endsWith("\n")) {
|
|
129
|
+
out += p;
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
out += ` ${p}`;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return { text: out.trim(), startRow: r0, endRow: r1 };
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Overlays selection highlighting onto already-drawn cells inside `rect`, preserving every character.
|
|
139
|
+
*/
|
|
140
|
+
export function paintSelectionHighlight(frame, rect, offset, textStartX, sel, lineCount) {
|
|
141
|
+
const { startRow, startCol, endRow, endCol } = normalizeSelection(sel);
|
|
142
|
+
if (startRow === endRow && startCol === endCol && !sel.dragging)
|
|
143
|
+
return;
|
|
144
|
+
if (lineCount <= 0)
|
|
145
|
+
return;
|
|
146
|
+
const hiStyle = frame.styles.style(frame.theme.highlight);
|
|
147
|
+
const cells = frame.cells;
|
|
148
|
+
const maxTextCols = Math.max(0, rect.x + rect.columns - textStartX);
|
|
149
|
+
if (maxTextCols <= 0)
|
|
150
|
+
return;
|
|
151
|
+
for (let vRow = 0; vRow < rect.rows; vRow++) {
|
|
152
|
+
const docRow = offset + vRow;
|
|
153
|
+
if (docRow < startRow || docRow > endRow || docRow >= lineCount)
|
|
154
|
+
continue;
|
|
155
|
+
const y = rect.y + vRow;
|
|
156
|
+
if (y < 0 || y >= cells.rows)
|
|
157
|
+
continue;
|
|
158
|
+
const c0 = docRow === startRow ? Math.max(0, startCol) : 0;
|
|
159
|
+
const c1 = docRow === endRow ? Math.min(maxTextCols - 1, endCol) : maxTextCols - 1;
|
|
160
|
+
if (c1 < c0)
|
|
161
|
+
continue;
|
|
162
|
+
const rowOffset = y * cells.columns;
|
|
163
|
+
for (let col = c0; col <= c1; col++) {
|
|
164
|
+
const x = textStartX + col;
|
|
165
|
+
if (x < textStartX || x >= rect.x + rect.columns || x >= cells.columns)
|
|
166
|
+
continue;
|
|
167
|
+
cells.styles[rowOffset + x] = hiStyle;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
package/dist/setup.js
CHANGED
|
@@ -102,6 +102,7 @@ function mcpCommandSpec(cliAvailable) {
|
|
|
102
102
|
return { command: "node", args: [cliPath, "mcp"], shell: `node ${cliPath} mcp`, viaNpx: false };
|
|
103
103
|
}
|
|
104
104
|
export async function runSetupWizard(options = {}) {
|
|
105
|
+
const out = options.writeOut ?? ((s) => process.stdout.write(s));
|
|
105
106
|
const existingConfig = loadConfig(options.overrideHome);
|
|
106
107
|
const targets = discoverSkillTargets(options.overrideHome);
|
|
107
108
|
const rex = detectRexIdentity();
|
|
@@ -120,9 +121,9 @@ export async function runSetupWizard(options = {}) {
|
|
|
120
121
|
const detectedHarnesses = targets.filter((t) => t.detected && t.id !== "project").map((t) => t.id);
|
|
121
122
|
if (detectedHarnesses.length > 0)
|
|
122
123
|
envParts.push(`skill dirs: ${detectedHarnesses.join(", ")}`);
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
124
|
+
out("\n");
|
|
125
|
+
out(`${styled(ANSI.accent + ANSI.bold, "◈ bypane setup")}\n`);
|
|
126
|
+
out(`${styled(ANSI.dim, ` Detected: ${envParts.join(" · ")}`)}\n\n`);
|
|
126
127
|
let chosenSkillIds;
|
|
127
128
|
let layoutChoice;
|
|
128
129
|
let showMcpSnippet;
|
|
@@ -217,43 +218,43 @@ export async function runSetupWizard(options = {}) {
|
|
|
217
218
|
installedPaths.push(installSkillTo(target.path));
|
|
218
219
|
}
|
|
219
220
|
spin?.stop("bypane configured");
|
|
220
|
-
|
|
221
|
+
out("\n");
|
|
221
222
|
if (installRes.status === "installed") {
|
|
222
|
-
|
|
223
|
+
out(` ${styled(ANSI.green, "✓")} CLI installed permanently (${installRes.via})\n`);
|
|
223
224
|
if (installRes.pathMissing) {
|
|
224
|
-
|
|
225
|
+
out(` ${styled(ANSI.amber, "Note: add ~/.local/bin to your PATH to run `bypane` directly.")}\n`);
|
|
225
226
|
}
|
|
226
227
|
}
|
|
227
228
|
else if (installRes.status === "already_installed") {
|
|
228
|
-
|
|
229
|
+
out(` ${styled(ANSI.green, "✓")} CLI ready on PATH (\`bypane\`)\n`);
|
|
229
230
|
}
|
|
230
231
|
else if (installRes.status === "failed") {
|
|
231
|
-
|
|
232
|
+
out(` ${styled(ANSI.amber, "!")} Could not install \`bypane\` globally (${installRes.error ?? "offline"}) — falling back to \`npx -y ${NPM_PACKAGE}\`\n`);
|
|
232
233
|
}
|
|
233
|
-
|
|
234
|
-
|
|
234
|
+
out(` ${styled(ANSI.green, "✓")} Config saved: ${savedConfigPath}\n`);
|
|
235
|
+
out(` ${styled(ANSI.dim, nextConfig.autoDock ? `auto-dock: ${nextConfig.splitDirection} (${nextConfig.splitRatio}%)` : "auto-dock: manual")}\n`);
|
|
235
236
|
if (installedPaths.length > 0) {
|
|
236
237
|
for (const item of installedPaths) {
|
|
237
|
-
|
|
238
|
+
out(` ${styled(ANSI.green, "✓")} Skill ${item.status}: ${item.path}\n`);
|
|
238
239
|
}
|
|
239
240
|
}
|
|
240
241
|
else {
|
|
241
|
-
|
|
242
|
+
out(` ${styled(ANSI.dim, "·")} No skill files installed (run \`bypane skill setup\` anytime)\n`);
|
|
242
243
|
}
|
|
243
244
|
if (showMcpSnippet) {
|
|
244
245
|
const cliAvailable = installRes.status === "installed" ||
|
|
245
246
|
installRes.status === "already_installed" ||
|
|
246
247
|
isBypaneOnPath();
|
|
247
248
|
const mcp = mcpCommandSpec(cliAvailable);
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
249
|
+
out("\n");
|
|
250
|
+
out(`${styled(ANSI.bold, "Optional MCP registration:")}\n`);
|
|
251
|
+
out(` ${styled(ANSI.dim, "# Claude Code")}\n`);
|
|
252
|
+
out(` claude mcp add bypane -- ${mcp.shell}\n`);
|
|
253
|
+
out(` ${styled(ANSI.dim, "# Generic JSON (Codex / OpenCode / Antigravity / Cursor)")}\n`);
|
|
254
|
+
out(` ${JSON.stringify({ mcpServers: { bypane: { command: mcp.command, args: mcp.args } } })}\n`);
|
|
254
255
|
}
|
|
255
256
|
if (!options.yes && process.stdin.isTTY && canAutoDock() && options.onLaunchDemo) {
|
|
256
|
-
|
|
257
|
+
out("\n");
|
|
257
258
|
const tryDemo = await confirm({
|
|
258
259
|
theme: bypaneTheme,
|
|
259
260
|
message: "Open a live demo pane right now to test it?",
|
|
@@ -265,8 +266,8 @@ export async function runSetupWizard(options = {}) {
|
|
|
265
266
|
await options.onLaunchDemo();
|
|
266
267
|
}
|
|
267
268
|
else {
|
|
268
|
-
|
|
269
|
-
|
|
269
|
+
out("\n");
|
|
270
|
+
out(`${styled(ANSI.dim, "Next: run `bypane --demo` (or `bypane demo` inside Rex/tmux) to see all surfaces live.")}\n`);
|
|
270
271
|
}
|
|
271
272
|
}
|
|
272
273
|
export function runSkillSubcommand(sub, flags, overrideHome) {
|
package/dist/skill.js
CHANGED
|
@@ -7,10 +7,12 @@ name: bypane
|
|
|
7
7
|
description: >
|
|
8
8
|
Use bypane to project interactive visual surfaces (Markdown plans with
|
|
9
9
|
checklists, QuickLook files and PNG images, filterable tables, braille charts,
|
|
10
|
-
live logs,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
live logs, human-gated decisions, and custom generative TUIs with sliders,
|
|
11
|
+
toggles, segmented pickers, meters, and interactive timelines) into a companion
|
|
12
|
+
terminal pane beside the user's chat. Use when sharing plans, screenshots,
|
|
13
|
+
binary files, comparison tables, metric series, multi-option decisions, or
|
|
14
|
+
bespoke interactive controls that are easier to comprehend and manipulate
|
|
15
|
+
spatially than in scrolling chat text.
|
|
14
16
|
license: MIT
|
|
15
17
|
---
|
|
16
18
|
|
|
@@ -35,6 +37,18 @@ active pane without stealing focus.
|
|
|
35
37
|
- **Branching human decisions (\`ask\`):** Use \`ask\` for explicit select,
|
|
36
38
|
multiselect, text, or confirm prompts. \`ask\` is strictly human-gated—agents
|
|
37
39
|
can pre-highlight an option, never submit on the user's behalf.
|
|
40
|
+
- **Custom generative TUIs (\`ui\`):** When a preset isn't enough, compose an
|
|
41
|
+
interactive surface from \`tui-sdk\` primitives—\`col\`, \`row\`, \`box\`, \`divider\`,
|
|
42
|
+
\`text\`, \`badge\`, \`stat\`, \`markdown\`, \`meter\`, \`sparkline\`, \`chart\`, \`canvas\`,
|
|
43
|
+
\`table\`, \`slider\`, \`toggle\`, \`segmented\`, \`select\`, \`checkboxes\`, \`input\`,
|
|
44
|
+
\`timeline\` (\`steps\` | \`gantt\`), and \`button\`—with reactive \`{{expr}}\` formulas,
|
|
45
|
+
human-gated \`submit: true\` buttons, and automatic state push-back.
|
|
46
|
+
- **Arbitrary \`tui-sdk\` apps (\`app\`):** When you need custom drawing, shaders,
|
|
47
|
+
live animations, interactive canvases, physics/motion visualizers, or bespoke
|
|
48
|
+
multi-pane tools beyond declarative primitives, push a TypeScript/JavaScript
|
|
49
|
+
module with \`bypane app\` / \`bypane_app\`. It runs inside an isolated worker
|
|
50
|
+
with full access to \`"tui"\` and \`"bypane/primitives"\`, sharing \`bypane\`'s
|
|
51
|
+
tabs, scoped notes (\`n\`), and push-back (\`ctx.submit\`, \`ctx.send\`, \`s\`).
|
|
38
52
|
|
|
39
53
|
Do not use \`bypane\` for short one-line replies or routine command noise.
|
|
40
54
|
|
|
@@ -46,7 +60,9 @@ same workspace socket).
|
|
|
46
60
|
|
|
47
61
|
### MCP tools (\`bypane mcp\`)
|
|
48
62
|
|
|
49
|
-
- \`bypane_present\` — show or update \`markdown\`, \`file\`, \`image\`, \`table\`, \`chart\`, or \`
|
|
63
|
+
- \`bypane_present\` — show or update \`markdown\`, \`file\`, \`image\`, \`table\`, \`chart\`, \`log\`, \`ui\`, or \`app\`
|
|
64
|
+
- \`bypane_ui\` — compose a custom generative terminal UI tree (\`root\`, \`state\`, optional \`wait: true\` with human-gated \`submit: true\` button)
|
|
65
|
+
- \`bypane_app\` — run arbitrary TypeScript/JavaScript \`tui\` SDK code in an isolated companion worker (\`path\` or inline \`code\`, live \`state\` streaming, optional \`wait: true\` with \`ctx.submit\`)
|
|
50
66
|
- \`bypane_append_log\` — append lines to an existing \`log\` surface
|
|
51
67
|
- \`bypane_ask\` — human-gated \`select\` | \`multiselect\` | \`text\` | \`confirm\` (blocks until submitted unless \`wait: false\`)
|
|
52
68
|
- \`bypane_list\` — list open tabs and active surface
|
|
@@ -84,7 +100,32 @@ bypane chart --id latency --title "Latency" --unit ms \\
|
|
|
84
100
|
bypane ask --id deploy --title "Deploy" --mode select \\
|
|
85
101
|
--prompt "Pick rollout channel" --option canary --option prod
|
|
86
102
|
|
|
87
|
-
#
|
|
103
|
+
# Compose a generative interactive UI (sliders, timelines, reactive stats/charts)
|
|
104
|
+
bypane ui --id tuner --title "Rollout Tuner" --wait <<'EOF'
|
|
105
|
+
{
|
|
106
|
+
"state": { "replicas": 4, "canaryPct": 20, "region": "us-east", "autoRollback": true },
|
|
107
|
+
"root": {
|
|
108
|
+
"type": "col", "gap": 1,
|
|
109
|
+
"children": [
|
|
110
|
+
{ "type": "row", "gap": 1, "children": [
|
|
111
|
+
{ "type": "box", "title": "Cost", "child": { "type": "stat", "label": "{{replicas}} pods", "value": "\${{replicas * 38}}/mo" } },
|
|
112
|
+
{ "type": "box", "title": "Exposure", "child": { "type": "meter", "value": "{{canaryPct}}", "min": 0, "max": 100 } }
|
|
113
|
+
]},
|
|
114
|
+
{ "type": "slider", "bind": "replicas", "label": "Replicas", "min": 1, "max": 16, "step": 1, "unit": "pods" },
|
|
115
|
+
{ "type": "slider", "bind": "canaryPct", "label": "Canary", "min": 5, "max": 100, "step": 5, "unit": "%" },
|
|
116
|
+
{ "type": "segmented", "bind": "region", "label": "Region", "options": ["us-east", "eu-west", "global"] },
|
|
117
|
+
{ "type": "toggle", "bind": "autoRollback", "label": "Auto-rollback on error spike" },
|
|
118
|
+
{ "type": "button", "action": "apply", "label": "Apply Rollout", "variant": "primary", "submit": true }
|
|
119
|
+
]
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
EOF
|
|
123
|
+
|
|
124
|
+
# Run an arbitrary custom tui-sdk TypeScript app (or stream live state updates)
|
|
125
|
+
bypane app examples/spring-studio.ts --id spring --title "Spring Studio"
|
|
126
|
+
bypane app --id spring --state '{"stiffness":320,"damping":20}'
|
|
127
|
+
|
|
128
|
+
# Read back human edits (checked tasks, notes, selected table rows, UI/app state)
|
|
88
129
|
bypane state
|
|
89
130
|
bypane state plan
|
|
90
131
|
\`\`\`
|
|
@@ -92,10 +133,11 @@ bypane state plan
|
|
|
92
133
|
## Updating in place & reading feedback
|
|
93
134
|
|
|
94
135
|
- Reuse \`--id <stable-id>\` (or \`id\` in MCP) when updating an existing plan,
|
|
95
|
-
table, or
|
|
96
|
-
- When the user
|
|
97
|
-
|
|
98
|
-
|
|
136
|
+
table, chart, UI, or app so you refresh the same tab instead of spawning duplicates.
|
|
137
|
+
- When the user highlights a Markdown/code fragment and adds a note (\`n\` → \`Enter\`),
|
|
138
|
+
clicks a \`submit\` button, or presses \`s\` in \`bypane\`, a compact \`[bypane · <Title> (<kind>)]\`
|
|
139
|
+
block with the active state or \`Quote:\` snippet is sent into your pane without duplicating
|
|
140
|
+
previously transmitted notes.
|
|
99
141
|
`;
|
|
100
142
|
function homeDir(overrideHome) {
|
|
101
143
|
return overrideHome || process.env.HOME || homedir();
|