dsh-ssh-pty 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.
@@ -0,0 +1,509 @@
1
+ // Human takeover web surface for dsh-ssh-terminal: a loopback-only page that
2
+ // mirrors live SSH sessions (viewport + cursor) and lets the person type into
3
+ // the PTY directly (2FA / passwords / menu choices / vim), so secrets never
4
+ // pass through the model. Route shapes follow @deepseek-ai/dsh-host-webserver:
5
+ // WebRoute { kind, path, handler(req, res) } and WebUpgradeRoute { path, handler(req, socket, head) }.
6
+ import { WebSocketServer } from 'ws';
7
+
8
+ const MAX_INPUT_CHARS = 8192;
9
+ const POLL_MS = 150;
10
+
11
+ // ------------------------------------------------------------- loopback fence
12
+ function isIPv4Loopback(v4) {
13
+ const parts = v4.split('.');
14
+ return parts.length === 4 && parts[0] === '127' && parts.every((p) => /^\d{1,3}$/.test(p) && Number(p) <= 255);
15
+ }
16
+
17
+ function isLoopbackAddress(address) {
18
+ if (address === undefined) return false;
19
+ const normalized = String(address).toLowerCase();
20
+ if (normalized === '::1') return true;
21
+ if (normalized.startsWith('::ffff:')) return isIPv4Loopback(normalized.slice('::ffff:'.length));
22
+ return isIPv4Loopback(normalized);
23
+ }
24
+
25
+ function isLoopbackHostname(hostname) {
26
+ if (hostname === 'localhost' || hostname === '[::1]') return true;
27
+ return isIPv4Loopback(hostname);
28
+ }
29
+
30
+ /** Loopback socket + loopback Host + no forwarding headers + same-origin markers. */
31
+ function isLoopbackRequest(req) {
32
+ if (!isLoopbackAddress(req.socket?.remoteAddress)) return false;
33
+ if (req.headers['cf-connecting-ip'] !== undefined || req.headers['x-forwarded-for'] !== undefined) return false;
34
+ const host = req.headers.host;
35
+ if (typeof host !== 'string') return false;
36
+ let hostUrl;
37
+ try {
38
+ hostUrl = new URL('http://' + host);
39
+ } catch {
40
+ return false;
41
+ }
42
+ if (!isLoopbackHostname(hostUrl.hostname)) return false;
43
+ if (req.headers['sec-fetch-site'] === 'cross-site') return false;
44
+ const origin = req.headers.origin;
45
+ if (origin === undefined) return true;
46
+ try {
47
+ return new URL(origin).host === hostUrl.host;
48
+ } catch {
49
+ return false;
50
+ }
51
+ }
52
+
53
+ function writeJson(res, status, body) {
54
+ res.writeHead(status, {
55
+ 'content-type': 'application/json; charset=utf-8',
56
+ 'referrer-policy': 'no-referrer',
57
+ });
58
+ res.end(JSON.stringify(body));
59
+ }
60
+
61
+ async function readJsonBody(req, maxBytes = 64 * 1024) {
62
+ const chunks = [];
63
+ let size = 0;
64
+ for await (const chunk of req) {
65
+ size += chunk.length;
66
+ if (size > maxBytes) {
67
+ req.destroy();
68
+ return null;
69
+ }
70
+ chunks.push(chunk);
71
+ }
72
+ const text = Buffer.concat(chunks).toString('utf8');
73
+ if (text === '') return null;
74
+ try {
75
+ return JSON.parse(text);
76
+ } catch {
77
+ return null;
78
+ }
79
+ }
80
+
81
+ function sessionRow(session) {
82
+ const status = session.status();
83
+ return {
84
+ id: session.sessionId,
85
+ alias: session.alias,
86
+ host: session.host.hostname ?? session.alias,
87
+ port: session.host.port ?? 22,
88
+ user: session.host.user ?? '',
89
+ status: status.kind,
90
+ exitCode: status.kind === 'exited' ? status.exitCode : undefined,
91
+ cols: session.emulator.cols,
92
+ rows: session.emulator.rows,
93
+ ownerId: session.ownerId,
94
+ ownerName: session.ownerName,
95
+ createdAt: session.createdAt,
96
+ idleMs: session.statusValue.kind === 'running' ? Date.now() - session.lastOutputAt : undefined,
97
+ };
98
+ }
99
+
100
+ // ------------------------------------------------------------------- the page
101
+ const PAGE_HTML = `<!doctype html>
102
+ <html lang="zh">
103
+ <head>
104
+ <meta charset="utf-8">
105
+ <meta name="viewport" content="width=device-width, initial-scale=1">
106
+ <title>dsh-ssh-terminal 人工接管</title>
107
+ <style>
108
+ :root { color-scheme: dark; }
109
+ * { box-sizing: border-box; }
110
+ body { margin: 0; font-family: "Segoe UI", "Microsoft YaHei", sans-serif; background: #0d1117; color: #e6edf3; }
111
+ header { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: #161b22; border-bottom: 1px solid #30363d; }
112
+ header h1 { font-size: 15px; margin: 0; font-weight: 600; white-space: nowrap; }
113
+ select, button, input { background: #21262d; color: #e6edf3; border: 1px solid #30363d; border-radius: 6px; padding: 5px 9px; font-size: 13px; }
114
+ select { min-width: 260px; }
115
+ button { cursor: pointer; }
116
+ button:hover { background: #30363d; }
117
+ #wsState { font-size: 12px; padding: 2px 8px; border-radius: 10px; background: #30363d; }
118
+ #wsState.on { color: #3fb950; }
119
+ #wsState.off { color: #f85149; }
120
+ main { padding: 10px 14px 0; }
121
+ #vp { background: #101418; border: 1px solid #30363d; border-radius: 8px; padding: 10px 12px; margin: 0;
122
+ font: 13px/1.3 Consolas, "Cascadia Mono", monospace; white-space: pre; overflow: auto; min-height: 320px;
123
+ max-height: calc(100vh - 330px); tab-size: 8; }
124
+ #vp .cur { background: #e6edf3; color: #101418; border-radius: 1px; }
125
+ #bar { display: flex; gap: 14px; font-size: 12px; color: #8b949e; padding: 6px 4px; flex-wrap: wrap; }
126
+ .row { display: flex; align-items: center; gap: 8px; padding: 6px 14px; flex-wrap: wrap; }
127
+ .row label { font-size: 12px; color: #8b949e; }
128
+ #text { flex: 1 1 320px; }
129
+ .keys button { padding: 4px 8px; font: 12px Consolas, monospace; }
130
+ .hint { color: #6e7681; font-size: 12px; }
131
+ a { color: #58a6ff; }
132
+ </style>
133
+ </head>
134
+ <body>
135
+ <header>
136
+ <h1>SSH 人工接管</h1>
137
+ <select id="sess"><option value="">— 选择会话 —</option></select>
138
+ <button id="refresh">刷新</button>
139
+ <span id="wsState" class="off">未连接</span>
140
+ </header>
141
+ <main>
142
+ <pre id="vp">未选择会话。从上方选择一个 SSH 会话连接。
143
+
144
+ 用法:
145
+ · 聚焦本页任意位置后直接敲键盘 —— 按键原样发进终端(Enter/方向键/Esc/Ctrl+C 等都支持)。
146
+ · 中文/粘贴文本用下方输入框,点「发送+回车」。
147
+ · 密码与验证码不会回显是正常的(服务端不回显),直接输入后回车即可。</pre>
148
+ <div id="bar"><span id="bAlias">—</span><span id="bStatus"></span><span id="bCursor"></span><span id="bSize"></span></div>
149
+ </main>
150
+ <div class="row">
151
+ <input id="text" placeholder="输入文本(支持中文/粘贴)…" autocomplete="off">
152
+ <button id="sendNl">发送+回车</button>
153
+ <button id="sendRaw">仅发送</button>
154
+ <label><input type="checkbox" id="enterSend" checked> 输入框内回车=发送+回车</label>
155
+ </div>
156
+ <div class="row keys">
157
+ <span class="hint">快捷键:</span>
158
+ <button data-k="\\x03">Ctrl+C</button>
159
+ <button data-k="\\x04">Ctrl+D</button>
160
+ <button data-k="\\x1a">Ctrl+Z</button>
161
+ <button data-k="\\x1b">Esc</button>
162
+ <button data-k="\\t">Tab</button>
163
+ <span class="hint"> 尺寸:</span>
164
+ <input id="cols" type="number" min="20" max="500" style="width:70px" value="120">
165
+ <span class="hint">×</span>
166
+ <input id="rows" type="number" min="10" max="200" style="width:60px" value="40">
167
+ <button id="applySize">应用</button>
168
+ <span style="flex:1"></span>
169
+ <button id="detach">断开观察</button>
170
+ <button id="closeSess" style="color:#f85149">关闭会话</button>
171
+ </div>
172
+ <div class="row"><span class="hint">安全说明:本页仅监听本机回环连接;在此输入的密码/验证码直接写入 SSH 通道,不经过模型。</span></div>
173
+ <script>
174
+ (function () {
175
+ var API = location.pathname.replace(/\\/ui$/, '');
176
+ var sessSel = document.getElementById('sess');
177
+ var vp = document.getElementById('vp');
178
+ var wsState = document.getElementById('wsState');
179
+ var text = document.getElementById('text');
180
+ var ws = null, selected = '', lastSize = '', reconnectTimer = null;
181
+
182
+ function esc(s) { return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;'); }
183
+ function escChar(c) { return c === ' ' ? ' ' : esc(c); }
184
+
185
+ function renderWithCursor(textStr, x, y) {
186
+ var lines = textStr.split('\\n');
187
+ if (y >= 0 && y < lines.length && x >= 0) {
188
+ var line = lines[y];
189
+ if (x <= line.length) {
190
+ lines[y] = esc(line.slice(0, x)) + '<span class="cur">' + escChar(line[x] || ' ') + '</span>' + esc(line.slice(x + 1));
191
+ vp.innerHTML = lines.join('\\n');
192
+ return;
193
+ }
194
+ }
195
+ vp.innerHTML = esc(textStr);
196
+ }
197
+
198
+ function setState(state, cls) { wsState.textContent = state; wsState.className = cls; }
199
+ function setBar(frame) {
200
+ document.getElementById('bAlias').textContent = (frame.alias || selected) + ' ' + (frame.host || '');
201
+ document.getElementById('bStatus').textContent = frame.status && frame.status.kind === 'running' ? '运行中' : '已退出' + (frame.exitCode !== undefined && frame.exitCode !== null ? ' (code ' + frame.exitCode + ')' : '');
202
+ document.getElementById('bCursor').textContent = '光标 (' + frame.cursor.x + ',' + frame.cursor.y + ')';
203
+ document.getElementById('bSize').textContent = frame.cols + '×' + frame.rows;
204
+ if (lastSize !== frame.cols + 'x' + frame.rows) {
205
+ document.getElementById('cols').value = frame.cols;
206
+ document.getElementById('rows').value = frame.rows;
207
+ lastSize = frame.cols + 'x' + frame.rows;
208
+ }
209
+ }
210
+
211
+ function closeWs() {
212
+ if (reconnectTimer) { clearTimeout(reconnectTimer); reconnectTimer = null; }
213
+ if (ws) { try { ws.onclose = null; ws.close(); } catch (e) {} ws = null; }
214
+ }
215
+ function attach(id) {
216
+ closeWs();
217
+ selected = id || '';
218
+ if (!id) { setState('未连接', 'off'); vp.textContent = '未选择会话。'; return; }
219
+ setState('连接中…', 'off');
220
+ var proto = location.protocol === 'https:' ? 'wss:' : 'ws:';
221
+ ws = new WebSocket(proto + '//' + location.host + API + '/ws?session=' + encodeURIComponent(id));
222
+ ws.onopen = function () { setState('已连接', 'on'); };
223
+ ws.onmessage = function (ev) {
224
+ var frame;
225
+ try { frame = JSON.parse(ev.data); } catch (e) { return; }
226
+ if (frame.type === 'snapshot') { renderWithCursor(frame.text, frame.cursor.x, frame.cursor.y); setBar(frame); }
227
+ else if (frame.type === 'exit') {
228
+ setState('会话已退出', 'off');
229
+ vp.innerHTML += '\\n<span style="color:#f85149">— 会话已退出 ' + (frame.error ? ':' + esc(frame.error) : '') + ' —</span>';
230
+ refreshSessions();
231
+ } else if (frame.type === 'error') { setState('错误:' + frame.message, 'off'); }
232
+ };
233
+ ws.onclose = function () {
234
+ setState('断开', 'off');
235
+ if (selected) reconnectTimer = setTimeout(function () { refreshSessions().then(function () { if (selected) attach(selected); }); }, 1500);
236
+ };
237
+ }
238
+
239
+ function send(data) { if (ws && ws.readyState === 1 && data) ws.send(JSON.stringify({ type: 'input', data: data })); }
240
+
241
+ var refreshSessions = function () {
242
+ return fetch(API + '/sessions').then(function (r) { return r.json(); }).then(function (data) {
243
+ var list = data.sessions || [];
244
+ var current = selected;
245
+ sessSel.innerHTML = '';
246
+ var head = document.createElement('option');
247
+ head.value = ''; head.textContent = '— 选择会话 (' + list.length + ') —';
248
+ sessSel.appendChild(head);
249
+ list.forEach(function (s) {
250
+ var opt = document.createElement('option');
251
+ opt.value = s.id;
252
+ opt.textContent = '#' + s.id + ' ' + s.alias + ' (' + s.user + '@' + s.host + ':' + s.port + ') ' + (s.status === 'running' ? '●运行中' : '○已退出') + (s.ownerName ? ' [' + s.ownerName + ']' : '');
253
+ sessSel.appendChild(opt);
254
+ });
255
+ if (current && list.some(function (s) { return s.id === current; })) sessSel.value = current;
256
+ else { selected = ''; if (ws) closeWs(); setState('未连接', 'off'); }
257
+ }).catch(function () {});
258
+ };
259
+
260
+ sessSel.addEventListener('change', function () { attach(sessSel.value); });
261
+ document.getElementById('refresh').addEventListener('click', refreshSessions);
262
+ document.getElementById('sendNl').addEventListener('click', function () { send(text.value + '\\r'); text.value = ''; });
263
+ document.getElementById('sendRaw').addEventListener('click', function () { send(text.value); text.value = ''; });
264
+ document.getElementById('enterSend').addEventListener('change', function () {});
265
+ text.addEventListener('keydown', function (e) {
266
+ if (e.key === 'Enter' && document.getElementById('enterSend').checked) {
267
+ e.preventDefault(); send(text.value + '\\r'); text.value = '';
268
+ }
269
+ });
270
+ Array.prototype.forEach.call(document.querySelectorAll('.keys button[data-k]'), function (btn) {
271
+ btn.addEventListener('click', function () { send(btn.getAttribute('data-k')); });
272
+ });
273
+ document.getElementById('applySize').addEventListener('click', function () {
274
+ if (ws && ws.readyState === 1) ws.send(JSON.stringify({ type: 'resize', cols: Number(document.getElementById('cols').value), rows: Number(document.getElementById('rows').value) }));
275
+ });
276
+ document.getElementById('detach').addEventListener('click', function () { attach(''); sessSel.value = ''; });
277
+ document.getElementById('closeSess').addEventListener('click', function () {
278
+ if (!selected) return;
279
+ if (!window.confirm('关闭会话 ' + selected + '?远端 shell 将被结束。')) return;
280
+ fetch(API + '/close', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ id: selected }) })
281
+ .then(function () { attach(''); return refreshSessions(); });
282
+ });
283
+
284
+ document.addEventListener('keydown', function (e) {
285
+ if (!ws || ws.readyState !== 1) return;
286
+ if (e.target === text || e.target.tagName === 'INPUT' || e.target.tagName === 'SELECT' || e.target.tagName === 'BUTTON') return;
287
+ if (e.metaKey) return;
288
+ var data = null;
289
+ if (e.ctrlKey) {
290
+ var k = e.key.toLowerCase();
291
+ if (k >= 'a' && k <= 'z') data = String.fromCharCode(e.key.toUpperCase().charCodeAt(0) - 64);
292
+ else if (e.key === ' ') data = '\\x00';
293
+ } else {
294
+ switch (e.key) {
295
+ case 'Enter': data = '\\r'; break;
296
+ case 'Backspace': data = '\\x7f'; break;
297
+ case 'Tab': data = '\\t'; break;
298
+ case 'Escape': data = '\\x1b'; break;
299
+ case 'ArrowUp': data = '\\x1b[A'; break;
300
+ case 'ArrowDown': data = '\\x1b[B'; break;
301
+ case 'ArrowRight': data = '\\x1b[C'; break;
302
+ case 'ArrowLeft': data = '\\x1b[D'; break;
303
+ case 'Home': data = '\\x1b[H'; break;
304
+ case 'End': data = '\\x1b[F'; break;
305
+ case 'PageUp': data = '\\x1b[5~'; break;
306
+ case 'PageDown': data = '\\x1b[6~'; break;
307
+ case 'Delete': data = '\\x1b[3~'; break;
308
+ case 'Insert': data = '\\x1b[2~'; break;
309
+ case 'F1': data = '\\x1bOP'; break;
310
+ case 'F2': data = '\\x1bOQ'; break;
311
+ case 'F3': data = '\\x1bOR'; break;
312
+ case 'F4': data = '\\x1bOS'; break;
313
+ case 'F5': data = '\\x1b[15~'; break;
314
+ case 'F6': data = '\\x1b[17~'; break;
315
+ case 'F7': data = '\\x1b[18~'; break;
316
+ case 'F8': data = '\\x1b[19~'; break;
317
+ case 'F9': data = '\\x1b[20~'; break;
318
+ case 'F10': data = '\\x1b[21~'; break;
319
+ case 'F11': data = '\\x1b[23~'; break;
320
+ case 'F12': data = '\\x1b[24~'; break;
321
+ default: if (e.key.length === 1 && !e.altKey) data = e.key;
322
+ }
323
+ }
324
+ if (data !== null) { e.preventDefault(); send(data); }
325
+ });
326
+
327
+ refreshSessions();
328
+ setInterval(refreshSessions, 2500);
329
+ })();
330
+ </script>
331
+ </body>
332
+ </html>
333
+ `;
334
+
335
+ // ---------------------------------------------------------------- route maker
336
+ /**
337
+ * Builds the takeover routes + WebSocket upgrade against the live backend.
338
+ * @param deps {{ backend: import('./backend.js').SshTerminalBackend, resolve: () => any }}
339
+ */
340
+ export function makeTakeover(deps) {
341
+ const { backend, resolve } = deps;
342
+ const wss = new WebSocketServer({ noServer: true });
343
+
344
+ const guard = (req, res) => {
345
+ if (!resolve().takeoverEnabled) {
346
+ writeJson(res, 403, { error: 'takeover page disabled by config' });
347
+ return false;
348
+ }
349
+ if (!isLoopbackRequest(req)) {
350
+ writeJson(res, 403, { error: 'forbidden: loopback-only' });
351
+ return false;
352
+ }
353
+ return true;
354
+ };
355
+
356
+ const routes = [
357
+ {
358
+ kind: 'exact',
359
+ path: '/api/dsh-ssh-terminal/sessions',
360
+ handler: (req, res) => {
361
+ if (!guard(req, res)) return;
362
+ if ((req.method ?? 'GET') !== 'GET') {
363
+ writeJson(res, 405, { error: 'method not allowed' });
364
+ return;
365
+ }
366
+ const sessions = [...backend.sessions.values()].map(sessionRow);
367
+ writeJson(res, 200, { version: '0.1.0', sessions });
368
+ },
369
+ },
370
+ {
371
+ kind: 'exact',
372
+ path: '/api/dsh-ssh-terminal/close',
373
+ handler: async (req, res) => {
374
+ if (!guard(req, res)) return;
375
+ if ((req.method ?? 'POST') !== 'POST') {
376
+ writeJson(res, 405, { error: 'method not allowed' });
377
+ return;
378
+ }
379
+ const body = await readJsonBody(req);
380
+ const id = typeof body?.id === 'string' ? body.id : '';
381
+ const session = id ? backend.sessions.get(id) : undefined;
382
+ if (!session) {
383
+ writeJson(res, 404, { error: 'session not found: ' + id });
384
+ return;
385
+ }
386
+ await session.close('closed by user from takeover page');
387
+ writeJson(res, 200, { ok: true });
388
+ },
389
+ },
390
+ {
391
+ kind: 'exact',
392
+ path: '/api/dsh-ssh-terminal/ui',
393
+ handler: (req, res) => {
394
+ if (!guard(req, res)) return;
395
+ if ((req.method ?? 'GET') !== 'GET' && req.method !== 'HEAD') {
396
+ writeJson(res, 405, { error: 'method not allowed' });
397
+ return;
398
+ }
399
+ res.writeHead(200, {
400
+ 'content-type': 'text/html; charset=utf-8',
401
+ 'cache-control': 'no-store',
402
+ 'referrer-policy': 'no-referrer',
403
+ 'x-content-type-options': 'nosniff',
404
+ });
405
+ res.end(req.method === 'HEAD' ? undefined : PAGE_HTML);
406
+ },
407
+ },
408
+ ];
409
+
410
+ const upgrade = {
411
+ path: '/api/dsh-ssh-terminal/ws',
412
+ handler: (req, socket, head) => {
413
+ const deny = (code, text) => {
414
+ try {
415
+ socket.write('HTTP/1.1 ' + code + ' ' + text + '\r\nConnection: close\r\n\r\n');
416
+ } catch {
417
+ // socket gone
418
+ }
419
+ socket.destroy();
420
+ };
421
+ if (!resolve().takeoverEnabled) return deny(403, 'Forbidden');
422
+ if (!isLoopbackRequest(req)) return deny(403, 'Forbidden');
423
+ const url = new URL(req.url ?? '/', 'http://localhost');
424
+ const sessionId = url.searchParams.get('session');
425
+ if (!sessionId) return deny(400, 'Bad Request');
426
+ wss.handleUpgrade(req, socket, head, (ws) => {
427
+ const session = backend.sessions.get(sessionId);
428
+ if (!session) {
429
+ try {
430
+ ws.send(JSON.stringify({ type: 'error', message: 'session not found: ' + sessionId }));
431
+ } catch {
432
+ // socket raced away
433
+ }
434
+ try {
435
+ ws.close(1000);
436
+ } catch {
437
+ // already closed
438
+ }
439
+ return;
440
+ }
441
+ let lastSent = '';
442
+ let exited = false;
443
+ const sendSnapshot = () => {
444
+ const text = session.renderViewport();
445
+ const cursor = session.cursor();
446
+ const status = session.status();
447
+ const cols = session.emulator.cols;
448
+ const rows = session.emulator.rows;
449
+ const key = text + '\u0000' + cursor.x + ',' + cursor.y + '\u0000' + cols + 'x' + rows;
450
+ if (key === lastSent) return;
451
+ lastSent = key;
452
+ try {
453
+ ws.send(
454
+ JSON.stringify({
455
+ type: 'snapshot',
456
+ text,
457
+ cursor,
458
+ cols,
459
+ rows,
460
+ status,
461
+ alias: session.alias,
462
+ host: session.host.hostname ?? session.alias,
463
+ exitCode: status.kind === 'exited' ? status.exitCode : undefined,
464
+ }),
465
+ );
466
+ } catch {
467
+ // socket gone; the close handler stops the poll
468
+ }
469
+ };
470
+ sendSnapshot();
471
+ const poll = setInterval(() => {
472
+ if (session.statusValue.kind !== 'running') {
473
+ if (!exited) {
474
+ exited = true;
475
+ const status = session.status();
476
+ try {
477
+ ws.send(JSON.stringify({ type: 'exit', code: status.exitCode ?? null, error: session.exitError }));
478
+ } catch {
479
+ // socket gone
480
+ }
481
+ }
482
+ return;
483
+ }
484
+ sendSnapshot();
485
+ }, POLL_MS);
486
+ ws.on('message', (raw) => {
487
+ let frame;
488
+ try {
489
+ frame = JSON.parse(String(raw));
490
+ } catch {
491
+ return;
492
+ }
493
+ if (frame.type === 'input') {
494
+ if (typeof frame.data === 'string' && frame.data.length > 0 && frame.data.length <= MAX_INPUT_CHARS) {
495
+ session.write(frame.data);
496
+ }
497
+ } else if (frame.type === 'resize') {
498
+ session.resize(frame.cols, frame.rows);
499
+ lastSent = '';
500
+ }
501
+ });
502
+ ws.on('close', () => clearInterval(poll));
503
+ ws.on('error', () => clearInterval(poll));
504
+ });
505
+ },
506
+ };
507
+
508
+ return { routes, upgrade };
509
+ }
package/locale/en.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "SSH controlled terminal",
4
+ "description": "Adds an \"ssh\" terminal backend so agents can drive interactive SSH sessions (bastion menus, vim, top) through the terminal tools while one-time codes and passwords are typed by the human."
5
+ }
6
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "SSH 受控终端",
4
+ "description": "新增 ssh 终端后端,让 agent 通过终端工具驱动交互式 SSH 会话(堡垒机菜单、vim、top),二次验证码与密码由用户亲自输入。"
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,6 +1,48 @@
1
1
  {
2
2
  "name": "dsh-ssh-pty",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Controlled SSH terminals for DeepSeek Harness: an ssh terminal backend that lets agents drive interactive SSH sessions with the terminal tools while bastion one-time codes and passwords are typed by the human.",
5
+ "type": "module",
6
+ "main": "./lib/index.js",
7
+ "exports": {
8
+ ".": "./lib/index.js",
9
+ "./package.json": "./package.json",
10
+ "./locale/*.json": "./locale/*.json",
11
+ "./icon": "./icon.svg"
12
+ },
13
+ "files": [
14
+ "lib/**/*.js",
15
+ "locale/*.json",
16
+ "cordis.patch.yml",
17
+ "README.md",
18
+ "LICENSE",
19
+ "icon.svg"
20
+ ],
21
+ "engines": {
22
+ "node": ">=22"
23
+ },
24
+ "dsh": {
25
+ "engines": {
26
+ "dsh": ">=0.2.2-rc.3"
27
+ },
28
+ "bundle": {
29
+ "patch": "./cordis.patch.yml"
30
+ }
31
+ },
32
+ "dependencies": {
33
+ "@deepseek-ai/schemastery": "^3.19.0",
34
+ "@xterm/headless": "^6.0.0",
35
+ "ssh2": "^1.17.0",
36
+ "ws": "^8.18.0"
37
+ },
38
+ "keywords": [
39
+ "dsh",
40
+ "dsh-bundle",
41
+ "dsh-plugin",
42
+ "ssh",
43
+ "terminal",
44
+ "pty",
45
+ "bastion"
46
+ ],
47
+ "license": "MIT"
48
+ }