@bypane/cli 0.0.0-stage → 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/dist/skill.js ADDED
@@ -0,0 +1,219 @@
1
+ import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import { dirname, join } from "node:path";
4
+ export const SKILL_MARKER = '<!-- Installed by "bypane skill setup". Remove with "bypane skill remove". -->';
5
+ export const BYPANE_SKILL_MD = `---
6
+ name: bypane
7
+ description: >
8
+ Use bypane to project interactive visual surfaces (Markdown plans with
9
+ checklists, QuickLook files and PNG images, filterable tables, braille charts,
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.
16
+ license: MIT
17
+ ---
18
+
19
+ # bypane
20
+
21
+ \`bypane\` is a 2 ms companion terminal pane shared between you and the user.
22
+ Inside Rex or tmux, calling \`bypane\` auto-splits a companion pane beside the
23
+ active pane without stealing focus.
24
+
25
+ ## When to use bypane
26
+
27
+ - **Plans & checklists (\`markdown\`):** Push multi-step plans with \`- [ ]\` tasks
28
+ instead of printing long walls of text in chat. The user can toggle tasks
29
+ directly and leave notes (\`n\`); read their edits back with \`state\`.
30
+ - **Files, screenshots & binaries (\`show\`):** Push code snippets with line
31
+ ranges (\`path:start-end\`), PNG screenshots (rendered inline via Kitty/Ghostty
32
+ or half-blocks), or binary files (PDFs, videos, archives) so the user can
33
+ press \`o\` to open them on their local host (\`rex open\` / \`open\`).
34
+ - **Comparisons & data (\`table\` / \`chart\` / \`log\`):** Push structured rows as a
35
+ filterable, sortable table, numeric series as a braille chart, or streaming
36
+ output as a live log surface.
37
+ - **Branching human decisions (\`ask\`):** Use \`ask\` for explicit select,
38
+ multiselect, text, or confirm prompts. \`ask\` is strictly human-gated—agents
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\`).
52
+
53
+ Do not use \`bypane\` for short one-line replies or routine command noise.
54
+
55
+ ## Using MCP vs. CLI
56
+
57
+ Prefer the \`bypane_*\` MCP tools when the \`bypane\` MCP server is attached;
58
+ otherwise call the \`bypane\` CLI directly over shell (both speak to the exact
59
+ same workspace socket).
60
+
61
+ ### MCP tools (\`bypane mcp\`)
62
+
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\`)
66
+ - \`bypane_append_log\` — append lines to an existing \`log\` surface
67
+ - \`bypane_ask\` — human-gated \`select\` | \`multiselect\` | \`text\` | \`confirm\` (blocks until submitted unless \`wait: false\`)
68
+ - \`bypane_list\` — list open tabs and active surface
69
+ - \`bypane_state\` — read checked tasks, human notes, selected rows, and \`ask\` answers
70
+ - \`bypane_close\` — close a surface tab
71
+ - \`bypane_snapshot\` / \`bypane_act\` — inspect live UI components or perform non-destructive actions (tab switch, scroll, filter, pre-highlight)
72
+
73
+ ### CLI commands
74
+
75
+ If \`bypane\` is not on \`PATH\`, prefix commands with \`npx -y @bypane/cli ...\`.
76
+
77
+ \`\`\`bash
78
+ # Show Markdown, code with highlighted lines, PNG images, or binary QuickLook
79
+ bypane show PLAN.md
80
+ bypane show src/server.ts:40-85
81
+ bypane show screenshot.png --caption "After layout fix"
82
+ bypane show report.pdf
83
+
84
+ # Push inline Markdown with interactive checkboxes
85
+ bypane md --id plan --title "Rollout Plan" <<'EOF'
86
+ # Rollout
87
+ - [x] Run unit tests
88
+ - [ ] Verify staging metrics
89
+ - [ ] Tag release
90
+ EOF
91
+
92
+ # Pipe JSON array or CSV/TSV into a filterable, sortable table
93
+ cat benchmarks.json | bypane table --id bench --title "Benchmarks"
94
+
95
+ # Render a braille chart
96
+ bypane chart --id latency --title "Latency" --unit ms \\
97
+ --series p50:14,12,13,11 --series p99:41,38,34,29
98
+
99
+ # Present a human-gated decision (prints JSON answer when user submits)
100
+ bypane ask --id deploy --title "Deploy" --mode select \\
101
+ --prompt "Pick rollout channel" --option canary --option prod
102
+
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)
129
+ bypane state
130
+ bypane state plan
131
+ \`\`\`
132
+
133
+ ## Updating in place & reading feedback
134
+
135
+ - Reuse \`--id <stable-id>\` (or \`id\` in MCP) when updating an existing plan,
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.
141
+ `;
142
+ function homeDir(overrideHome) {
143
+ return overrideHome || process.env.HOME || homedir();
144
+ }
145
+ export function discoverSkillTargets(overrideHome, cwd = process.cwd()) {
146
+ const home = homeDir(overrideHome);
147
+ const candidates = [
148
+ {
149
+ id: "agents",
150
+ label: "~/.agents/skills/bypane (universal: Codex, Antigravity, OpenCode, Claude)",
151
+ root: join(home, ".agents"),
152
+ file: join(home, ".agents", "skills", "bypane", "SKILL.md"),
153
+ alwaysShow: true,
154
+ },
155
+ {
156
+ id: "claude",
157
+ label: "~/.claude/skills/bypane (Claude Code)",
158
+ root: join(home, ".claude"),
159
+ file: join(home, ".claude", "skills", "bypane", "SKILL.md"),
160
+ },
161
+ {
162
+ id: "codex",
163
+ label: "~/.codex/skills/bypane (Codex)",
164
+ root: join(home, ".codex"),
165
+ file: join(home, ".codex", "skills", "bypane", "SKILL.md"),
166
+ },
167
+ {
168
+ id: "project",
169
+ label: "./.agents/skills/bypane (current project only)",
170
+ root: cwd,
171
+ file: join(cwd, ".agents", "skills", "bypane", "SKILL.md"),
172
+ alwaysShow: true,
173
+ },
174
+ ];
175
+ return candidates.map((c) => {
176
+ const installed = existsSync(c.file);
177
+ let managed = false;
178
+ if (installed) {
179
+ try {
180
+ managed = readFileSync(c.file, "utf8").includes(SKILL_MARKER);
181
+ }
182
+ catch {
183
+ managed = false;
184
+ }
185
+ }
186
+ return {
187
+ id: c.id,
188
+ label: c.label,
189
+ path: c.file,
190
+ detected: c.alwaysShow ? c.id === "agents" : existsSync(c.root),
191
+ installed,
192
+ managed,
193
+ };
194
+ });
195
+ }
196
+ export function formatInstalledSkill() {
197
+ // Insert marker right after frontmatter closing "---" so frontmatter stays valid YAML.
198
+ const endFm = BYPANE_SKILL_MD.indexOf("\n---\n", 4);
199
+ if (endFm < 0)
200
+ return `${SKILL_MARKER}\n\n${BYPANE_SKILL_MD}`;
201
+ const splitAt = endFm + 5;
202
+ return `${BYPANE_SKILL_MD.slice(0, splitAt)}\n${SKILL_MARKER}\n${BYPANE_SKILL_MD.slice(splitAt)}`;
203
+ }
204
+ export function installSkillTo(filePath) {
205
+ const existed = existsSync(filePath);
206
+ mkdirSync(dirname(filePath), { recursive: true });
207
+ writeFileSync(filePath, formatInstalledSkill(), "utf8");
208
+ return { path: filePath, status: existed ? "updated" : "installed" };
209
+ }
210
+ export function removeSkillFrom(filePath, force = false) {
211
+ if (!existsSync(filePath))
212
+ return { path: filePath, status: "missing" };
213
+ const content = readFileSync(filePath, "utf8");
214
+ if (!force && !content.includes(SKILL_MARKER)) {
215
+ return { path: filePath, status: "unmanaged" };
216
+ }
217
+ rmSync(dirname(filePath), { recursive: true, force: true });
218
+ return { path: filePath, status: "removed" };
219
+ }