peer-bridge 0.0.0-stage → 0.7.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.ko.md +202 -0
- package/README.md +242 -2
- package/adapters/antigravity/bin/agy-hook.mjs +24 -0
- package/adapters/antigravity/hooks.json +23 -0
- package/adapters/antigravity/mcp_config.json +8 -0
- package/adapters/antigravity/plugin.json +4 -0
- package/adapters/antigravity/rules/AGENTS.md +6 -0
- package/adapters/antigravity/skills/peer-bridge/SKILL.md +19 -0
- package/adapters/claude/.claude-plugin/plugin.json +5 -0
- package/adapters/claude/.mcp.json +8 -0
- package/adapters/claude/bin/cc-hook.mjs +20 -0
- package/adapters/claude/hooks/hooks.json +46 -0
- package/adapters/claude/skills/peer-bridge/SKILL.md +19 -0
- package/adapters/codex/bin/codex-hook.mjs +10 -0
- package/adapters/codex/config.toml.example +5 -0
- package/adapters/codex/hooks.json +44 -0
- package/adapters/codex/skills/peer-bridge/SKILL.md +12 -0
- package/adapters/gemini/bin/gemini-hook.mjs +10 -0
- package/adapters/gemini/settings.json +51 -0
- package/adapters/gemini/skills/peer-bridge/SKILL.md +12 -0
- package/adapters/paseo/SKILL.md +24 -0
- package/bin/pbridge-mcp.mjs +37 -0
- package/bin/pbridge-tui.mjs +7 -0
- package/bin/pbridge.mjs +5 -0
- package/bin/pbridged.mjs +16 -0
- package/package.json +57 -4
- package/scripts/postinstall.mjs +25 -0
- package/scripts/preuninstall.mjs +20 -0
- package/skills/peer-bridge/SKILL.md +70 -0
- package/src/adapters/antigravity/hooks.mjs +207 -0
- package/src/adapters/claude/hooks.mjs +204 -0
- package/src/adapters/codex/hooks.mjs +142 -0
- package/src/adapters/gemini/hooks.mjs +159 -0
- package/src/adapters/installer.mjs +328 -0
- package/src/cli/main.mjs +785 -0
- package/src/client/rpc.mjs +243 -0
- package/src/config.mjs +154 -0
- package/src/daemon/broker.mjs +1799 -0
- package/src/daemon/resolver.mjs +200 -0
- package/src/daemon/server.mjs +221 -0
- package/src/index.mjs +60 -0
- package/src/mcp/server.mjs +668 -0
- package/src/orchestrator/workflows.mjs +496 -0
- package/src/project.mjs +81 -0
- package/src/protocol.mjs +203 -0
- package/src/runtime/conv-api.mjs +101 -0
- package/src/runtime/host-discovery.mjs +635 -0
- package/src/runtime/native-claude.mjs +88 -0
- package/src/runtime/paseo.mjs +289 -0
- package/src/runtime/workers.mjs +751 -0
- package/src/skills.mjs +115 -0
- package/src/storage/db.mjs +704 -0
- package/src/tui/render.mjs +472 -0
- package/src/tui/viewer.mjs +443 -0
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import readline from 'node:readline';
|
|
4
|
+
import { spawnSync } from 'node:child_process';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { getConfig } from '../config.mjs';
|
|
7
|
+
import { detectDefaultProjectCwd, getProjectLabel, normalizeProjectPath } from '../project.mjs';
|
|
8
|
+
import { callRpc, isDaemonRunning, subscribeMonitor } from '../client/rpc.mjs';
|
|
9
|
+
import { discoverHostPeers, mergeAllPeers } from '../runtime/host-discovery.mjs';
|
|
10
|
+
import { StateDB, sanitizePeerForClient } from '../storage/db.mjs';
|
|
11
|
+
import { renderFrame } from './render.mjs';
|
|
12
|
+
|
|
13
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
14
|
+
const PBRIDGE_BIN = path.resolve(__dirname, '../../bin/pbridge.mjs');
|
|
15
|
+
const RUNTIME_CYCLE = ['all', 'cc', 'agy', 'codex', 'gemini', 'paseo'];
|
|
16
|
+
|
|
17
|
+
export async function collectMonitorSnapshot(config, opts = {}) {
|
|
18
|
+
const includeHost = !opts.brokerOnly;
|
|
19
|
+
const includeStopped = !opts.hideStopped;
|
|
20
|
+
const runtime = opts.runtime && opts.runtime !== 'all' ? opts.runtime : null;
|
|
21
|
+
const cwd = opts.cwd || null;
|
|
22
|
+
|
|
23
|
+
if (!opts.noDaemon && (await isDaemonRunning({ config }))) {
|
|
24
|
+
const snap = await callRpc(
|
|
25
|
+
'monitor.snapshot',
|
|
26
|
+
{
|
|
27
|
+
include_offline: includeStopped,
|
|
28
|
+
include_host: includeHost,
|
|
29
|
+
runtime,
|
|
30
|
+
cwd,
|
|
31
|
+
},
|
|
32
|
+
{ config, timeoutMs: 3000 },
|
|
33
|
+
);
|
|
34
|
+
return snap;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Standalone fallback when pbridged daemon is not running
|
|
38
|
+
let brokerPeers = [];
|
|
39
|
+
if (fs.existsSync(config.dbPath)) {
|
|
40
|
+
let db = null;
|
|
41
|
+
try {
|
|
42
|
+
db = new StateDB(config.dbPath);
|
|
43
|
+
brokerPeers = db.listPeers({ includeOffline: includeStopped }).map(sanitizePeerForClient);
|
|
44
|
+
} catch {
|
|
45
|
+
brokerPeers = [];
|
|
46
|
+
} finally {
|
|
47
|
+
try {
|
|
48
|
+
db?.close();
|
|
49
|
+
} catch {
|
|
50
|
+
// ignore
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const hostPeers = includeHost
|
|
56
|
+
? await discoverHostPeers(config, {
|
|
57
|
+
includeStopped,
|
|
58
|
+
skipPidCheck: Boolean(opts.skipPidCheck),
|
|
59
|
+
paseoClientFactory: opts.paseoClientFactory || null,
|
|
60
|
+
})
|
|
61
|
+
: [];
|
|
62
|
+
|
|
63
|
+
const { peers, counts } = mergeAllPeers(brokerPeers, hostPeers, {
|
|
64
|
+
runtime,
|
|
65
|
+
cwd,
|
|
66
|
+
includeStopped,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
daemon: null,
|
|
71
|
+
active_workflows: 0,
|
|
72
|
+
counts,
|
|
73
|
+
peers,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function launchInTmux(config, opts) {
|
|
78
|
+
if (!process.env.TMUX) {
|
|
79
|
+
const msg =
|
|
80
|
+
'--tmux-split / --tmux-popup requires an active tmux session. Run `pbridge tui` directly in a standard terminal.\n';
|
|
81
|
+
process.stderr.write(msg);
|
|
82
|
+
return { ok: false, reason: 'not_in_tmux' };
|
|
83
|
+
}
|
|
84
|
+
const forwardArgs = [config.nodeBin, PBRIDGE_BIN, 'tui'];
|
|
85
|
+
if (opts.runtime && opts.runtime !== 'all') forwardArgs.push('--runtime', String(opts.runtime));
|
|
86
|
+
if (opts.allProjects) forwardArgs.push('--all');
|
|
87
|
+
if (opts.cwd) forwardArgs.push('--cwd', String(opts.cwd));
|
|
88
|
+
if (opts.brokerOnly) forwardArgs.push('--broker-only');
|
|
89
|
+
if (opts.hideStopped) forwardArgs.push('--active');
|
|
90
|
+
|
|
91
|
+
const tmuxArgs = opts.tmuxPopup
|
|
92
|
+
? ['display-popup', '-E', '-d', process.cwd(), '-w', '88%', '-h', '82%', ...forwardArgs]
|
|
93
|
+
: ['split-window', '-h', '-c', process.cwd(), '-l', '48%', ...forwardArgs];
|
|
94
|
+
|
|
95
|
+
const res = spawnSync(config.tmuxBin || 'tmux', tmuxArgs, { stdio: 'inherit' });
|
|
96
|
+
return { ok: res.status === 0, status: res.status };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export async function runTuiViewer(opts = {}) {
|
|
100
|
+
const config = getConfig(opts.config || {});
|
|
101
|
+
|
|
102
|
+
if (opts.tmuxSplit || opts.tmuxPopup) {
|
|
103
|
+
return launchInTmux(config, opts);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const initialRuntime =
|
|
107
|
+
opts.runtime && RUNTIME_CYCLE.includes(String(opts.runtime).toLowerCase())
|
|
108
|
+
? String(opts.runtime).toLowerCase()
|
|
109
|
+
: 'all';
|
|
110
|
+
|
|
111
|
+
const detectedProjectCwd = opts.cwd
|
|
112
|
+
? normalizeProjectPath(opts.cwd)
|
|
113
|
+
: detectDefaultProjectCwd(opts.launchCwd || process.cwd());
|
|
114
|
+
const initialScopeMode = opts.allProjects ? 'all' : detectedProjectCwd ? 'project' : 'all';
|
|
115
|
+
const getEffectiveCwd = (scopeMode) => (scopeMode === 'project' ? detectedProjectCwd : null);
|
|
116
|
+
|
|
117
|
+
const snapshot = await collectMonitorSnapshot(config, {
|
|
118
|
+
runtime: initialRuntime,
|
|
119
|
+
cwd: getEffectiveCwd(initialScopeMode),
|
|
120
|
+
brokerOnly: Boolean(opts.brokerOnly),
|
|
121
|
+
hideStopped: Boolean(opts.hideStopped),
|
|
122
|
+
noDaemon: Boolean(opts.noDaemon),
|
|
123
|
+
skipPidCheck: Boolean(opts.skipPidCheck),
|
|
124
|
+
paseoClientFactory: opts.paseoClientFactory || null,
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
if (opts.json) {
|
|
128
|
+
process.stdout.write(`${JSON.stringify(snapshot, null, 2)}\n`);
|
|
129
|
+
return snapshot;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const isTty = Boolean(process.stdout.isTTY && process.stdin.isTTY);
|
|
133
|
+
if (opts.once || !isTty) {
|
|
134
|
+
const cols = Number(opts.width || process.stdout.columns || 100);
|
|
135
|
+
const frame = renderFrame(
|
|
136
|
+
{
|
|
137
|
+
daemon: snapshot.daemon,
|
|
138
|
+
activeWorkflows: snapshot.active_workflows || 0,
|
|
139
|
+
counts: snapshot.counts,
|
|
140
|
+
peers: snapshot.peers,
|
|
141
|
+
runtimeFilter: initialRuntime,
|
|
142
|
+
hideStopped: Boolean(opts.hideStopped),
|
|
143
|
+
scopeMode: initialScopeMode,
|
|
144
|
+
projectCwd: detectedProjectCwd,
|
|
145
|
+
selectedIndex: 0,
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
width: cols,
|
|
149
|
+
height: Math.max(12, snapshot.peers.length + 12),
|
|
150
|
+
color: Boolean(process.stdout.isTTY && !process.env.NO_COLOR),
|
|
151
|
+
compact: true,
|
|
152
|
+
},
|
|
153
|
+
);
|
|
154
|
+
process.stdout.write(`${frame.lines.join('\n')}\n`);
|
|
155
|
+
return snapshot;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Interactive TTY full-screen loop
|
|
159
|
+
const state = {
|
|
160
|
+
daemon: snapshot.daemon,
|
|
161
|
+
activeWorkflows: snapshot.active_workflows || 0,
|
|
162
|
+
counts: snapshot.counts,
|
|
163
|
+
peers: snapshot.peers,
|
|
164
|
+
runtimeFilter: initialRuntime,
|
|
165
|
+
hideStopped: Boolean(opts.hideStopped),
|
|
166
|
+
scopeMode: initialScopeMode,
|
|
167
|
+
projectCwd: detectedProjectCwd,
|
|
168
|
+
selectedIndex: 0,
|
|
169
|
+
scrollOffset: 0,
|
|
170
|
+
confirmClosePeer: null,
|
|
171
|
+
statusMessage: null,
|
|
172
|
+
flatRows: [],
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
let statusTimer = null;
|
|
176
|
+
const setStatus = (level, text, ttlMs = 4000) => {
|
|
177
|
+
state.statusMessage = { level, text };
|
|
178
|
+
if (statusTimer) clearTimeout(statusTimer);
|
|
179
|
+
statusTimer = setTimeout(() => {
|
|
180
|
+
state.statusMessage = null;
|
|
181
|
+
draw();
|
|
182
|
+
}, ttlMs);
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
const draw = () => {
|
|
186
|
+
const width = process.stdout.columns || 100;
|
|
187
|
+
const height = process.stdout.rows || 30;
|
|
188
|
+
const frame = renderFrame(state, {
|
|
189
|
+
width,
|
|
190
|
+
height,
|
|
191
|
+
color: !process.env.NO_COLOR,
|
|
192
|
+
});
|
|
193
|
+
state.flatRows = frame.flatRows;
|
|
194
|
+
state.selectedIndex = frame.selectedIndex;
|
|
195
|
+
process.stdout.write(`\x1b[H\x1b[2J${frame.lines.join('\n')}`);
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
let refreshing = false;
|
|
199
|
+
let pendingRefresh = false;
|
|
200
|
+
const refresh = async () => {
|
|
201
|
+
if (refreshing) {
|
|
202
|
+
pendingRefresh = true;
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
refreshing = true;
|
|
206
|
+
try {
|
|
207
|
+
const prevSelectedId = state.flatRows[state.selectedIndex]?.id || null;
|
|
208
|
+
const snap = await collectMonitorSnapshot(config, {
|
|
209
|
+
runtime: state.runtimeFilter,
|
|
210
|
+
cwd: getEffectiveCwd(state.scopeMode),
|
|
211
|
+
brokerOnly: Boolean(opts.brokerOnly),
|
|
212
|
+
hideStopped: state.hideStopped,
|
|
213
|
+
noDaemon: Boolean(opts.noDaemon),
|
|
214
|
+
});
|
|
215
|
+
state.daemon = snap.daemon;
|
|
216
|
+
state.activeWorkflows = snap.active_workflows || 0;
|
|
217
|
+
state.counts = snap.counts;
|
|
218
|
+
state.peers = snap.peers;
|
|
219
|
+
|
|
220
|
+
draw();
|
|
221
|
+
if (prevSelectedId) {
|
|
222
|
+
const nextIdx = state.flatRows.findIndex((p) => p.id === prevSelectedId);
|
|
223
|
+
if (nextIdx >= 0 && nextIdx !== state.selectedIndex) {
|
|
224
|
+
state.selectedIndex = nextIdx;
|
|
225
|
+
draw();
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
} catch {
|
|
229
|
+
// keep previous frame on transient error
|
|
230
|
+
} finally {
|
|
231
|
+
refreshing = false;
|
|
232
|
+
if (pendingRefresh) {
|
|
233
|
+
pendingRefresh = false;
|
|
234
|
+
setTimeout(() => refresh(), 40);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
let sub = null;
|
|
240
|
+
let debounceTimer = null;
|
|
241
|
+
const scheduleRefresh = () => {
|
|
242
|
+
if (debounceTimer) return;
|
|
243
|
+
debounceTimer = setTimeout(() => {
|
|
244
|
+
debounceTimer = null;
|
|
245
|
+
refresh();
|
|
246
|
+
}, 50);
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
const connectMonitor = async () => {
|
|
250
|
+
if (opts.noDaemon || sub) return;
|
|
251
|
+
if (!(await isDaemonRunning({ config }))) return;
|
|
252
|
+
try {
|
|
253
|
+
const conn = subscribeMonitor(
|
|
254
|
+
{
|
|
255
|
+
include_offline: !state.hideStopped,
|
|
256
|
+
include_host: !opts.brokerOnly,
|
|
257
|
+
runtime: state.runtimeFilter === 'all' ? null : state.runtimeFilter,
|
|
258
|
+
cwd: getEffectiveCwd(state.scopeMode),
|
|
259
|
+
},
|
|
260
|
+
() => scheduleRefresh(),
|
|
261
|
+
{
|
|
262
|
+
config,
|
|
263
|
+
onDisconnect: () => {
|
|
264
|
+
sub = null;
|
|
265
|
+
scheduleRefresh();
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
);
|
|
269
|
+
await conn.ready;
|
|
270
|
+
sub = conn;
|
|
271
|
+
} catch {
|
|
272
|
+
sub = null;
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
return new Promise((resolve) => {
|
|
277
|
+
let cleanedUp = false;
|
|
278
|
+
const cleanup = () => {
|
|
279
|
+
if (cleanedUp) return;
|
|
280
|
+
cleanedUp = true;
|
|
281
|
+
if (pollTimer) clearInterval(pollTimer);
|
|
282
|
+
if (statusTimer) clearTimeout(statusTimer);
|
|
283
|
+
if (debounceTimer) clearTimeout(debounceTimer);
|
|
284
|
+
try {
|
|
285
|
+
sub?.close();
|
|
286
|
+
} catch {
|
|
287
|
+
// ignore
|
|
288
|
+
}
|
|
289
|
+
process.stdout.off('resize', draw);
|
|
290
|
+
process.stdin.off('keypress', onKeypress);
|
|
291
|
+
if (process.stdin.isTTY) {
|
|
292
|
+
try {
|
|
293
|
+
process.stdin.setRawMode(false);
|
|
294
|
+
} catch {
|
|
295
|
+
// ignore
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
process.stdin.pause();
|
|
299
|
+
process.stdout.write('\x1b[?25h\x1b[?1049l');
|
|
300
|
+
resolve({ exited: true });
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
const onKeypress = async (str, key = {}) => {
|
|
304
|
+
if (key.ctrl && key.name === 'c') {
|
|
305
|
+
cleanup();
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
if (state.confirmClosePeer) {
|
|
310
|
+
const target = state.confirmClosePeer;
|
|
311
|
+
if (str === 'y' || str === 'Y' || key.name === 'return') {
|
|
312
|
+
state.confirmClosePeer = null;
|
|
313
|
+
draw();
|
|
314
|
+
try {
|
|
315
|
+
await callRpc(
|
|
316
|
+
'peer.close',
|
|
317
|
+
{
|
|
318
|
+
peer_id: target.peer_id,
|
|
319
|
+
policy: 'archive',
|
|
320
|
+
reason: 'Closed via pbridge tui',
|
|
321
|
+
},
|
|
322
|
+
{ config, timeoutMs: 15_000 },
|
|
323
|
+
);
|
|
324
|
+
setStatus('info', `Stopped spawned peer: ${target.handle}`);
|
|
325
|
+
} catch (err) {
|
|
326
|
+
setStatus('error', `Failed to stop ${target.handle}: ${err.message}`);
|
|
327
|
+
}
|
|
328
|
+
await refresh();
|
|
329
|
+
} else {
|
|
330
|
+
state.confirmClosePeer = null;
|
|
331
|
+
setStatus('info', 'Stop cancelled.', 2000);
|
|
332
|
+
draw();
|
|
333
|
+
}
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
if (str === 'q' || key.name === 'escape') {
|
|
338
|
+
cleanup();
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
if (key.name === 'up' || str === 'k') {
|
|
342
|
+
if (state.flatRows.length > 0) {
|
|
343
|
+
state.selectedIndex = Math.max(0, state.selectedIndex - 1);
|
|
344
|
+
draw();
|
|
345
|
+
}
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
if (key.name === 'down' || str === 'j') {
|
|
349
|
+
if (state.flatRows.length > 0) {
|
|
350
|
+
state.selectedIndex = Math.min(state.flatRows.length - 1, state.selectedIndex + 1);
|
|
351
|
+
draw();
|
|
352
|
+
}
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
if (str === 'g' || key.name === 'home') {
|
|
356
|
+
state.selectedIndex = 0;
|
|
357
|
+
draw();
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
if (str === 'G' || key.name === 'end') {
|
|
361
|
+
if (state.flatRows.length > 0) {
|
|
362
|
+
state.selectedIndex = state.flatRows.length - 1;
|
|
363
|
+
draw();
|
|
364
|
+
}
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
if (str === 'f') {
|
|
368
|
+
const curIdx = RUNTIME_CYCLE.indexOf(state.runtimeFilter);
|
|
369
|
+
state.runtimeFilter = RUNTIME_CYCLE[(curIdx + 1) % RUNTIME_CYCLE.length];
|
|
370
|
+
state.selectedIndex = 0;
|
|
371
|
+
await refresh();
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
if (str === 'p') {
|
|
375
|
+
if (!state.projectCwd) {
|
|
376
|
+
setStatus('warn', 'Launched outside a project directory; showing all projects.', 3000);
|
|
377
|
+
draw();
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
state.scopeMode = state.scopeMode === 'project' ? 'all' : 'project';
|
|
381
|
+
state.selectedIndex = 0;
|
|
382
|
+
state.scrollOffset = 0;
|
|
383
|
+
await refresh();
|
|
384
|
+
setStatus(
|
|
385
|
+
'info',
|
|
386
|
+
state.scopeMode === 'project'
|
|
387
|
+
? `Scope: project (${getProjectLabel(state.projectCwd)})`
|
|
388
|
+
: 'Scope: all projects',
|
|
389
|
+
2000,
|
|
390
|
+
);
|
|
391
|
+
draw();
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
if (str === 'a') {
|
|
395
|
+
state.hideStopped = !state.hideStopped;
|
|
396
|
+
state.selectedIndex = 0;
|
|
397
|
+
await refresh();
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
if (str === 'r') {
|
|
401
|
+
await refresh();
|
|
402
|
+
setStatus('info', 'Refreshed peer list.', 1500);
|
|
403
|
+
draw();
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
if (str === 'x' || key.name === 'delete' || key.name === 'backspace') {
|
|
407
|
+
const peer = state.flatRows[state.selectedIndex];
|
|
408
|
+
if (!peer) return;
|
|
409
|
+
if (!peer.can_close) {
|
|
410
|
+
const kindLabel = peer.origin === 'host' ? 'host session' : 'attached external session';
|
|
411
|
+
const reason =
|
|
412
|
+
peer.origin === 'spawned'
|
|
413
|
+
? `${peer.handle} is already stopped.`
|
|
414
|
+
: `Protected: ${peer.handle} (${kindLabel}) cannot be stopped. Only peer-bridge spawned peers can be stopped.`;
|
|
415
|
+
setStatus('warn', reason, 4500);
|
|
416
|
+
draw();
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
state.confirmClosePeer = peer;
|
|
420
|
+
draw();
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
process.stdout.write('\x1b[?1049h\x1b[?25l');
|
|
425
|
+
readline.emitKeypressEvents(process.stdin);
|
|
426
|
+
process.stdin.setRawMode(true);
|
|
427
|
+
process.stdin.resume();
|
|
428
|
+
process.stdin.on('keypress', onKeypress);
|
|
429
|
+
process.stdout.on('resize', draw);
|
|
430
|
+
process.once('SIGINT', cleanup);
|
|
431
|
+
process.once('SIGTERM', cleanup);
|
|
432
|
+
|
|
433
|
+
draw();
|
|
434
|
+
connectMonitor();
|
|
435
|
+
|
|
436
|
+
const pollTimer = setInterval(async () => {
|
|
437
|
+
if (!sub && !opts.noDaemon) {
|
|
438
|
+
await connectMonitor();
|
|
439
|
+
}
|
|
440
|
+
await refresh();
|
|
441
|
+
}, 2500);
|
|
442
|
+
});
|
|
443
|
+
}
|