@stage-labs/metro 0.1.0-beta.65 → 0.1.0-beta.66
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stage-labs/metro",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.66",
|
|
4
4
|
"description": "The metro command line. Sign in once per machine, then hand your MCP connector list to Claude Code without the credentials touching disk, argv or shell history.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
1
2
|
import type { IncomingMessage, Server } from 'node:http';
|
|
2
3
|
import type { Duplex } from 'node:stream';
|
|
3
4
|
import { WebSocketServer, type RawData, type WebSocket } from 'ws';
|
|
@@ -19,10 +20,28 @@ export interface TerminalSocketDeps {
|
|
|
19
20
|
const rawBytes = (data: RawData): Buffer =>
|
|
20
21
|
Buffer.isBuffer(data) ? data : Array.isArray(data) ? Buffer.concat(data) : Buffer.from(data);
|
|
21
22
|
|
|
23
|
+
export const resizeWindowArgs = (session: string, cols: number, rows: number): string[] => [
|
|
24
|
+
'resize-window',
|
|
25
|
+
'-t',
|
|
26
|
+
`${session}:`,
|
|
27
|
+
'-x',
|
|
28
|
+
String(cols),
|
|
29
|
+
'-y',
|
|
30
|
+
String(rows),
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
function sizeTmuxWindow(command: string[], session: string, cols: number, rows: number): void {
|
|
34
|
+
if (command[0] !== 'tmux') return;
|
|
35
|
+
const child = spawn('tmux', resizeWindowArgs(session, cols, rows), { stdio: 'ignore' });
|
|
36
|
+
child.on('error', (err) => {
|
|
37
|
+
log.debug({ err: errMsg(err) }, 'terminal: resize-window failed');
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
22
41
|
const dimension = (raw: unknown, fallback: number): number =>
|
|
23
42
|
typeof raw === 'number' && Number.isInteger(raw) && raw > 1 && raw <= MAX_DIMENSION ? raw : fallback;
|
|
24
43
|
|
|
25
|
-
function runTerminal(ws: WebSocket, command: string[], subject: string): void {
|
|
44
|
+
function runTerminal(ws: WebSocket, command: string[], subject: string, session: string): void {
|
|
26
45
|
const terminal = new Bun.Terminal({
|
|
27
46
|
cols: DEFAULT_COLS,
|
|
28
47
|
rows: DEFAULT_ROWS,
|
|
@@ -43,8 +62,12 @@ function runTerminal(ws: WebSocket, command: string[], subject: string): void {
|
|
|
43
62
|
}
|
|
44
63
|
try {
|
|
45
64
|
const control: unknown = JSON.parse(bytes.toString('utf8'));
|
|
46
|
-
if (isRecord(control) && 'cols' in control)
|
|
47
|
-
|
|
65
|
+
if (isRecord(control) && 'cols' in control) {
|
|
66
|
+
const cols = dimension(control.cols, DEFAULT_COLS);
|
|
67
|
+
const rows = dimension(control.rows, DEFAULT_ROWS);
|
|
68
|
+
terminal.resize(cols, rows);
|
|
69
|
+
sizeTmuxWindow(command, session, cols, rows);
|
|
70
|
+
}
|
|
48
71
|
} catch (err) {
|
|
49
72
|
log.warn({ err: errMsg(err) }, 'terminal: bad control frame');
|
|
50
73
|
}
|
|
@@ -85,7 +108,7 @@ export function attachTerminalSockets(server: Server, deps: TerminalSocketDeps):
|
|
|
85
108
|
return;
|
|
86
109
|
}
|
|
87
110
|
wss.handleUpgrade(req, socket, head, (ws) => {
|
|
88
|
-
runTerminal(ws, deps.command(grant.session), grant.subject);
|
|
111
|
+
runTerminal(ws, deps.command(grant.session), grant.subject, grant.session);
|
|
89
112
|
});
|
|
90
113
|
});
|
|
91
114
|
}
|
package/runtime/runtime.json
CHANGED