@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/LICENSE +21 -0
- package/README.md +188 -2
- 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 +810 -0
- package/dist/config.js +42 -0
- package/dist/demo.js +430 -0
- package/dist/expr.js +460 -0
- package/dist/ipc.js +201 -0
- package/dist/mcp.js +416 -0
- package/dist/multiplexer.js +281 -0
- package/dist/png.js +208 -0
- package/dist/primitives.js +669 -0
- package/dist/selection.js +170 -0
- package/dist/setup.js +329 -0
- package/dist/skill.js +219 -0
- package/dist/state.js +1147 -0
- package/dist/types.js +1 -0
- package/dist/ui-surface.js +744 -0
- package/dist/ui.js +1466 -0
- package/examples/spring-studio.ts +420 -0
- package/package.json +58 -4
- package/skills/bypane/SKILL.md +136 -0
package/dist/mcp.js
ADDED
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
import { sendIpc } from "./ipc.js";
|
|
2
|
+
import { detectCallerOrigin } from "./multiplexer.js";
|
|
3
|
+
const PROTOCOL_VERSIONS = ["2025-11-25", "2025-06-18", "2025-03-26", "2024-11-05"];
|
|
4
|
+
const TOOLS = [
|
|
5
|
+
{
|
|
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), log, and ui (declarative composable generative TUI with sliders, timelines, meters, toggles, charts, and reactive state).",
|
|
8
|
+
inputSchema: {
|
|
9
|
+
type: "object",
|
|
10
|
+
required: ["kind"],
|
|
11
|
+
properties: {
|
|
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", "ui", "app"] },
|
|
14
|
+
title: { type: "string", description: "Short tab title." },
|
|
15
|
+
focus: { type: "boolean", description: "Whether to focus this tab (default true for new tabs)." },
|
|
16
|
+
content: { type: "string", description: "Markdown or inline text content (for kind=markdown or file)." },
|
|
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)." },
|
|
19
|
+
caption: { type: "string", description: "Optional caption (for kind=image or chart)." },
|
|
20
|
+
highlightStart: { type: "number", description: "1-based start line to highlight (for kind=file)." },
|
|
21
|
+
highlightEnd: { type: "number", description: "1-based end line to highlight (for kind=file)." },
|
|
22
|
+
columns: {
|
|
23
|
+
type: "array",
|
|
24
|
+
description: "Table columns as strings or { key, label, width?, align? } (for kind=table).",
|
|
25
|
+
items: {},
|
|
26
|
+
},
|
|
27
|
+
rows: {
|
|
28
|
+
type: "array",
|
|
29
|
+
description: "Table rows as string arrays or objects keyed by column key (for kind=table).",
|
|
30
|
+
items: {},
|
|
31
|
+
},
|
|
32
|
+
series: {
|
|
33
|
+
type: "array",
|
|
34
|
+
description: "Chart series [{ name, values: number[], color? }] (for kind=chart).",
|
|
35
|
+
items: {
|
|
36
|
+
type: "object",
|
|
37
|
+
required: ["name", "values"],
|
|
38
|
+
properties: {
|
|
39
|
+
name: { type: "string" },
|
|
40
|
+
values: { type: "array", items: { type: "number" } },
|
|
41
|
+
color: { type: "string" },
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
unit: { type: "string", description: "Unit suffix for chart values (e.g. 'ms', '%')." },
|
|
46
|
+
min: { type: "number" },
|
|
47
|
+
max: { type: "number" },
|
|
48
|
+
lines: { type: "array", items: { type: "string" }, description: "Log lines (for kind=log)." },
|
|
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)." },
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
annotations: { readOnlyHint: false, destructiveHint: false },
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
name: "bypane_append_log",
|
|
111
|
+
description: "Append one or more lines to an existing bypane log surface.",
|
|
112
|
+
inputSchema: {
|
|
113
|
+
type: "object",
|
|
114
|
+
required: ["surfaceId", "lines"],
|
|
115
|
+
properties: {
|
|
116
|
+
surfaceId: { type: "string" },
|
|
117
|
+
lines: { type: "array", items: { type: "string" } },
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
annotations: { readOnlyHint: false, destructiveHint: false },
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
name: "bypane_ask",
|
|
124
|
+
description: "Present an interactive human-only decision prompt (select, multiselect, text, or confirm) in bypane. By default waits until the user submits or cancels; agents cannot submit on the user's behalf.",
|
|
125
|
+
inputSchema: {
|
|
126
|
+
type: "object",
|
|
127
|
+
required: ["mode", "prompt"],
|
|
128
|
+
properties: {
|
|
129
|
+
id: { type: "string" },
|
|
130
|
+
title: { type: "string" },
|
|
131
|
+
mode: { type: "string", enum: ["select", "multiselect", "text", "confirm"] },
|
|
132
|
+
prompt: { type: "string", description: "Clear question for the user." },
|
|
133
|
+
context: { type: "string", description: "Optional Markdown context shown above the prompt." },
|
|
134
|
+
options: {
|
|
135
|
+
type: "array",
|
|
136
|
+
description: "Choices as strings or { value, label } (for select/multiselect).",
|
|
137
|
+
items: {},
|
|
138
|
+
},
|
|
139
|
+
defaultValue: { description: "Default option value (string) or values (string[])." },
|
|
140
|
+
placeholder: { type: "string" },
|
|
141
|
+
confirmLabel: { type: "string" },
|
|
142
|
+
cancelLabel: { type: "string" },
|
|
143
|
+
wait: { type: "boolean", description: "Block until human submits (default true)." },
|
|
144
|
+
timeoutMs: { type: "number", description: "Optional wait timeout in milliseconds." },
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
annotations: { readOnlyHint: false, destructiveHint: false },
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
name: "bypane_list",
|
|
151
|
+
description: "List all open surfaces/tabs in the user's bypane workspace.",
|
|
152
|
+
inputSchema: { type: "object", properties: {} },
|
|
153
|
+
annotations: { readOnlyHint: true, destructiveHint: false },
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
name: "bypane_state",
|
|
157
|
+
description: "Read the current interactive state of a surface (or the entire active workspace): checked Markdown tasks, human-added notes, selected table rows, active filters, and ask answers.",
|
|
158
|
+
inputSchema: {
|
|
159
|
+
type: "object",
|
|
160
|
+
properties: {
|
|
161
|
+
surfaceId: { type: "string", description: "Optional surface ID; omits to return workspace + active surface." },
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
annotations: { readOnlyHint: true, destructiveHint: false },
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
name: "bypane_close",
|
|
168
|
+
description: "Close a surface tab by ID (or the currently active tab).",
|
|
169
|
+
inputSchema: {
|
|
170
|
+
type: "object",
|
|
171
|
+
properties: {
|
|
172
|
+
surfaceId: { type: "string" },
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
annotations: { readOnlyHint: false, destructiveHint: true },
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
name: "bypane_snapshot",
|
|
179
|
+
description: "Read the live rendered TUI screen and interactive component tree via tui/agent.",
|
|
180
|
+
inputSchema: { type: "object", properties: {} },
|
|
181
|
+
annotations: { readOnlyHint: true, destructiveHint: false },
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
name: "bypane_act",
|
|
185
|
+
description: "Perform non-destructive UI actions on visible bypane components (e.g. open tab, scroll, filter, pre-highlight). Human-gated ask submissions and notes are strictly blocked.",
|
|
186
|
+
inputSchema: {
|
|
187
|
+
type: "object",
|
|
188
|
+
required: ["steps"],
|
|
189
|
+
properties: {
|
|
190
|
+
steps: {
|
|
191
|
+
type: "array",
|
|
192
|
+
items: {
|
|
193
|
+
type: "object",
|
|
194
|
+
required: ["ref", "action"],
|
|
195
|
+
properties: {
|
|
196
|
+
ref: { type: "string" },
|
|
197
|
+
action: { type: "string" },
|
|
198
|
+
args: { type: "array", items: { type: "string" } },
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
annotations: { readOnlyHint: false, destructiveHint: false },
|
|
205
|
+
},
|
|
206
|
+
];
|
|
207
|
+
function isObj(v) {
|
|
208
|
+
return v !== null && typeof v === "object" && !Array.isArray(v);
|
|
209
|
+
}
|
|
210
|
+
export async function handleMcpToolCall(session, toolName, rawArgs, autoDock = true) {
|
|
211
|
+
const args = isObj(rawArgs) ? rawArgs : {};
|
|
212
|
+
const reqId = `mcp-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`;
|
|
213
|
+
const origin = detectCallerOrigin("mcp");
|
|
214
|
+
let ipcReq;
|
|
215
|
+
if (toolName === "bypane_present") {
|
|
216
|
+
const payload = { ...args, origin };
|
|
217
|
+
ipcReq = { id: reqId, op: "present", payload };
|
|
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
|
+
}
|
|
268
|
+
else if (toolName === "bypane_append_log") {
|
|
269
|
+
const surfaceId = String(args.surfaceId ?? "");
|
|
270
|
+
const lines = Array.isArray(args.lines) ? args.lines.map((l) => String(l)) : [];
|
|
271
|
+
ipcReq = { id: reqId, op: "append_log", surfaceId, lines };
|
|
272
|
+
}
|
|
273
|
+
else if (toolName === "bypane_ask") {
|
|
274
|
+
const payload = {
|
|
275
|
+
id: typeof args.id === "string" ? args.id : undefined,
|
|
276
|
+
kind: "ask",
|
|
277
|
+
title: typeof args.title === "string" ? args.title : "Decision",
|
|
278
|
+
mode: args.mode || "select",
|
|
279
|
+
prompt: String(args.prompt ?? ""),
|
|
280
|
+
context: typeof args.context === "string" ? args.context : undefined,
|
|
281
|
+
options: Array.isArray(args.options) ? args.options : undefined,
|
|
282
|
+
defaultValue: args.defaultValue,
|
|
283
|
+
placeholder: typeof args.placeholder === "string" ? args.placeholder : undefined,
|
|
284
|
+
confirmLabel: typeof args.confirmLabel === "string" ? args.confirmLabel : undefined,
|
|
285
|
+
cancelLabel: typeof args.cancelLabel === "string" ? args.cancelLabel : undefined,
|
|
286
|
+
origin,
|
|
287
|
+
focus: true,
|
|
288
|
+
};
|
|
289
|
+
const wait = args.wait !== false;
|
|
290
|
+
if (wait) {
|
|
291
|
+
ipcReq = {
|
|
292
|
+
id: reqId,
|
|
293
|
+
op: "ask_wait",
|
|
294
|
+
payload,
|
|
295
|
+
timeoutMs: typeof args.timeoutMs === "number" ? args.timeoutMs : undefined,
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
ipcReq = { id: reqId, op: "present", payload };
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
else if (toolName === "bypane_list") {
|
|
303
|
+
ipcReq = { id: reqId, op: "list" };
|
|
304
|
+
}
|
|
305
|
+
else if (toolName === "bypane_state") {
|
|
306
|
+
ipcReq = {
|
|
307
|
+
id: reqId,
|
|
308
|
+
op: "get_state",
|
|
309
|
+
surfaceId: typeof args.surfaceId === "string" ? args.surfaceId : undefined,
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
else if (toolName === "bypane_close") {
|
|
313
|
+
ipcReq = {
|
|
314
|
+
id: reqId,
|
|
315
|
+
op: "close",
|
|
316
|
+
surfaceId: typeof args.surfaceId === "string" ? args.surfaceId : undefined,
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
else if (toolName === "bypane_snapshot") {
|
|
320
|
+
ipcReq = { id: reqId, op: "snapshot" };
|
|
321
|
+
}
|
|
322
|
+
else if (toolName === "bypane_act") {
|
|
323
|
+
const steps = Array.isArray(args.steps)
|
|
324
|
+
? args.steps.map((s) => {
|
|
325
|
+
const obj = isObj(s) ? s : {};
|
|
326
|
+
return {
|
|
327
|
+
ref: String(obj.ref ?? ""),
|
|
328
|
+
action: String(obj.action ?? ""),
|
|
329
|
+
args: Array.isArray(obj.args) ? obj.args.map((a) => String(a)) : [],
|
|
330
|
+
};
|
|
331
|
+
})
|
|
332
|
+
: [];
|
|
333
|
+
ipcReq = { id: reqId, op: "act", steps };
|
|
334
|
+
}
|
|
335
|
+
else {
|
|
336
|
+
return { text: `Unknown tool "${toolName}"`, isError: true };
|
|
337
|
+
}
|
|
338
|
+
try {
|
|
339
|
+
const res = await sendIpc(session, ipcReq, {
|
|
340
|
+
autoDock: autoDock &&
|
|
341
|
+
(toolName === "bypane_present" ||
|
|
342
|
+
toolName === "bypane_ui" ||
|
|
343
|
+
toolName === "bypane_app" ||
|
|
344
|
+
toolName === "bypane_ask"),
|
|
345
|
+
});
|
|
346
|
+
if (!res.ok) {
|
|
347
|
+
return { text: res.error || "bypane error", isError: true };
|
|
348
|
+
}
|
|
349
|
+
return { text: JSON.stringify(res.data ?? { ok: true }, null, 2), isError: false };
|
|
350
|
+
}
|
|
351
|
+
catch (err) {
|
|
352
|
+
return { text: err.message, isError: true };
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
export function serveMcpStdio(session) {
|
|
356
|
+
const send = (msg) => process.stdout.write(`${msg}\n`);
|
|
357
|
+
const reply = (id, result) => send(JSON.stringify({ jsonrpc: "2.0", id, result }));
|
|
358
|
+
const fail = (id, code, message) => send(JSON.stringify({ jsonrpc: "2.0", id, error: { code, message } }));
|
|
359
|
+
const decoder = new TextDecoder();
|
|
360
|
+
let buf = "";
|
|
361
|
+
process.stdin.on("data", (chunk) => {
|
|
362
|
+
buf += decoder.decode(chunk, { stream: true });
|
|
363
|
+
let nl = buf.indexOf("\n");
|
|
364
|
+
while (nl >= 0) {
|
|
365
|
+
const line = buf.slice(0, nl).trim();
|
|
366
|
+
buf = buf.slice(nl + 1);
|
|
367
|
+
if (line)
|
|
368
|
+
void onMessage(line);
|
|
369
|
+
nl = buf.indexOf("\n");
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
async function onMessage(line) {
|
|
373
|
+
let parsed;
|
|
374
|
+
try {
|
|
375
|
+
parsed = JSON.parse(line);
|
|
376
|
+
}
|
|
377
|
+
catch {
|
|
378
|
+
fail(null, -32700, "Invalid JSON");
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
if (!isObj(parsed) || typeof parsed.method !== "string")
|
|
382
|
+
return;
|
|
383
|
+
const method = parsed.method;
|
|
384
|
+
const id = parsed.id ?? null;
|
|
385
|
+
const params = isObj(parsed.params) ? parsed.params : {};
|
|
386
|
+
if (id === null)
|
|
387
|
+
return;
|
|
388
|
+
if (method === "initialize") {
|
|
389
|
+
const asked = typeof params.protocolVersion === "string" ? params.protocolVersion : "";
|
|
390
|
+
const version = PROTOCOL_VERSIONS.includes(asked) ? asked : PROTOCOL_VERSIONS[0];
|
|
391
|
+
reply(id, {
|
|
392
|
+
protocolVersion: version,
|
|
393
|
+
capabilities: { tools: {} },
|
|
394
|
+
serverInfo: { name: "bypane", title: "bypane", version: "0.1.0" },
|
|
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.",
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
else if (method === "ping") {
|
|
399
|
+
reply(id, {});
|
|
400
|
+
}
|
|
401
|
+
else if (method === "tools/list") {
|
|
402
|
+
reply(id, { tools: TOOLS });
|
|
403
|
+
}
|
|
404
|
+
else if (method === "tools/call") {
|
|
405
|
+
const toolName = typeof params.name === "string" ? params.name : "";
|
|
406
|
+
const result = await handleMcpToolCall(session, toolName, params.arguments);
|
|
407
|
+
reply(id, {
|
|
408
|
+
content: [{ type: "text", text: result.text }],
|
|
409
|
+
isError: result.isError,
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
else {
|
|
413
|
+
fail(id, -32601, `Unknown method "${method}"`);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|