@bypane/cli 0.0.0-stage → 0.1.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,177 @@
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, and human-gated decisions) into a companion terminal pane beside
11
+ the user's chat. Use when sharing plans, screenshots, binary files, comparison
12
+ tables, metric series, or multi-option decisions that are easier to inspect or
13
+ act on spatially than in scrolling chat text.
14
+ license: MIT
15
+ ---
16
+
17
+ # bypane
18
+
19
+ \`bypane\` is a 2 ms companion terminal pane shared between you and the user.
20
+ Inside Rex or tmux, calling \`bypane\` auto-splits a companion pane beside the
21
+ active pane without stealing focus.
22
+
23
+ ## When to use bypane
24
+
25
+ - **Plans & checklists (\`markdown\`):** Push multi-step plans with \`- [ ]\` tasks
26
+ instead of printing long walls of text in chat. The user can toggle tasks
27
+ directly and leave notes (\`n\`); read their edits back with \`state\`.
28
+ - **Files, screenshots & binaries (\`show\`):** Push code snippets with line
29
+ ranges (\`path:start-end\`), PNG screenshots (rendered inline via Kitty/Ghostty
30
+ or half-blocks), or binary files (PDFs, videos, archives) so the user can
31
+ press \`o\` to open them on their local host (\`rex open\` / \`open\`).
32
+ - **Comparisons & data (\`table\` / \`chart\` / \`log\`):** Push structured rows as a
33
+ filterable, sortable table, numeric series as a braille chart, or streaming
34
+ output as a live log surface.
35
+ - **Branching human decisions (\`ask\`):** Use \`ask\` for explicit select,
36
+ multiselect, text, or confirm prompts. \`ask\` is strictly human-gated—agents
37
+ can pre-highlight an option, never submit on the user's behalf.
38
+
39
+ Do not use \`bypane\` for short one-line replies or routine command noise.
40
+
41
+ ## Using MCP vs. CLI
42
+
43
+ Prefer the \`bypane_*\` MCP tools when the \`bypane\` MCP server is attached;
44
+ otherwise call the \`bypane\` CLI directly over shell (both speak to the exact
45
+ same workspace socket).
46
+
47
+ ### MCP tools (\`bypane mcp\`)
48
+
49
+ - \`bypane_present\` — show or update \`markdown\`, \`file\`, \`image\`, \`table\`, \`chart\`, or \`log\`
50
+ - \`bypane_append_log\` — append lines to an existing \`log\` surface
51
+ - \`bypane_ask\` — human-gated \`select\` | \`multiselect\` | \`text\` | \`confirm\` (blocks until submitted unless \`wait: false\`)
52
+ - \`bypane_list\` — list open tabs and active surface
53
+ - \`bypane_state\` — read checked tasks, human notes, selected rows, and \`ask\` answers
54
+ - \`bypane_close\` — close a surface tab
55
+ - \`bypane_snapshot\` / \`bypane_act\` — inspect live UI components or perform non-destructive actions (tab switch, scroll, filter, pre-highlight)
56
+
57
+ ### CLI commands
58
+
59
+ If \`bypane\` is not on \`PATH\`, prefix commands with \`npx -y @bypane/cli ...\`.
60
+
61
+ \`\`\`bash
62
+ # Show Markdown, code with highlighted lines, PNG images, or binary QuickLook
63
+ bypane show PLAN.md
64
+ bypane show src/server.ts:40-85
65
+ bypane show screenshot.png --caption "After layout fix"
66
+ bypane show report.pdf
67
+
68
+ # Push inline Markdown with interactive checkboxes
69
+ bypane md --id plan --title "Rollout Plan" <<'EOF'
70
+ # Rollout
71
+ - [x] Run unit tests
72
+ - [ ] Verify staging metrics
73
+ - [ ] Tag release
74
+ EOF
75
+
76
+ # Pipe JSON array or CSV/TSV into a filterable, sortable table
77
+ cat benchmarks.json | bypane table --id bench --title "Benchmarks"
78
+
79
+ # Render a braille chart
80
+ bypane chart --id latency --title "Latency" --unit ms \\
81
+ --series p50:14,12,13,11 --series p99:41,38,34,29
82
+
83
+ # Present a human-gated decision (prints JSON answer when user submits)
84
+ bypane ask --id deploy --title "Deploy" --mode select \\
85
+ --prompt "Pick rollout channel" --option canary --option prod
86
+
87
+ # Read back human edits (checked tasks, notes, selected table rows)
88
+ bypane state
89
+ bypane state plan
90
+ \`\`\`
91
+
92
+ ## Updating in place & reading feedback
93
+
94
+ - Reuse \`--id <stable-id>\` (or \`id\` in MCP) when updating an existing plan,
95
+ table, or chart so you refresh the same tab instead of spawning duplicates.
96
+ - When the user presses \`s\` in \`bypane\`, a compact \`[bypane · <Title> (<kind>)]\`
97
+ summary of their checked items, selected row, or notes is sent into your
98
+ pane—treat it as direct user feedback on that surface.
99
+ `;
100
+ function homeDir(overrideHome) {
101
+ return overrideHome || process.env.HOME || homedir();
102
+ }
103
+ export function discoverSkillTargets(overrideHome, cwd = process.cwd()) {
104
+ const home = homeDir(overrideHome);
105
+ const candidates = [
106
+ {
107
+ id: "agents",
108
+ label: "~/.agents/skills/bypane (universal: Codex, Antigravity, OpenCode, Claude)",
109
+ root: join(home, ".agents"),
110
+ file: join(home, ".agents", "skills", "bypane", "SKILL.md"),
111
+ alwaysShow: true,
112
+ },
113
+ {
114
+ id: "claude",
115
+ label: "~/.claude/skills/bypane (Claude Code)",
116
+ root: join(home, ".claude"),
117
+ file: join(home, ".claude", "skills", "bypane", "SKILL.md"),
118
+ },
119
+ {
120
+ id: "codex",
121
+ label: "~/.codex/skills/bypane (Codex)",
122
+ root: join(home, ".codex"),
123
+ file: join(home, ".codex", "skills", "bypane", "SKILL.md"),
124
+ },
125
+ {
126
+ id: "project",
127
+ label: "./.agents/skills/bypane (current project only)",
128
+ root: cwd,
129
+ file: join(cwd, ".agents", "skills", "bypane", "SKILL.md"),
130
+ alwaysShow: true,
131
+ },
132
+ ];
133
+ return candidates.map((c) => {
134
+ const installed = existsSync(c.file);
135
+ let managed = false;
136
+ if (installed) {
137
+ try {
138
+ managed = readFileSync(c.file, "utf8").includes(SKILL_MARKER);
139
+ }
140
+ catch {
141
+ managed = false;
142
+ }
143
+ }
144
+ return {
145
+ id: c.id,
146
+ label: c.label,
147
+ path: c.file,
148
+ detected: c.alwaysShow ? c.id === "agents" : existsSync(c.root),
149
+ installed,
150
+ managed,
151
+ };
152
+ });
153
+ }
154
+ export function formatInstalledSkill() {
155
+ // Insert marker right after frontmatter closing "---" so frontmatter stays valid YAML.
156
+ const endFm = BYPANE_SKILL_MD.indexOf("\n---\n", 4);
157
+ if (endFm < 0)
158
+ return `${SKILL_MARKER}\n\n${BYPANE_SKILL_MD}`;
159
+ const splitAt = endFm + 5;
160
+ return `${BYPANE_SKILL_MD.slice(0, splitAt)}\n${SKILL_MARKER}\n${BYPANE_SKILL_MD.slice(splitAt)}`;
161
+ }
162
+ export function installSkillTo(filePath) {
163
+ const existed = existsSync(filePath);
164
+ mkdirSync(dirname(filePath), { recursive: true });
165
+ writeFileSync(filePath, formatInstalledSkill(), "utf8");
166
+ return { path: filePath, status: existed ? "updated" : "installed" };
167
+ }
168
+ export function removeSkillFrom(filePath, force = false) {
169
+ if (!existsSync(filePath))
170
+ return { path: filePath, status: "missing" };
171
+ const content = readFileSync(filePath, "utf8");
172
+ if (!force && !content.includes(SKILL_MARKER)) {
173
+ return { path: filePath, status: "unmanaged" };
174
+ }
175
+ rmSync(dirname(filePath), { recursive: true, force: true });
176
+ return { path: filePath, status: "removed" };
177
+ }