@lethevimlet/sshift 1.9.7 → 1.9.8
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/README.md
CHANGED
|
@@ -276,7 +276,8 @@ See [Configuration > Plugins](docs/configuration.md#plugins) for full details.
|
|
|
276
276
|
The opt-in `remote-control` plugin exposes a **loopback-only, token-protected** HTTP API so a
|
|
277
277
|
local assistant (for example a voice assistant's MCP server) can list, switch and rename tabs, open
|
|
278
278
|
bookmarks, read a terminal's screen as plain text, type text and press keys. Typing never
|
|
279
|
-
presses Enter; submitting is always a separate, explicit key request.
|
|
279
|
+
presses Enter; submitting is always a separate, explicit key request. It works with no sshift
|
|
280
|
+
page open: SSH bookmarks are connected by the server itself, and pages show those tabs when opened.
|
|
280
281
|
|
|
281
282
|
```json
|
|
282
283
|
{ "plugins": [{ "name": "remote-control", "enabled": true, "config": { "port": 8044 } }] }
|
package/package.json
CHANGED
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
* POST /v1/switch { sessionId }
|
|
28
28
|
* POST /v1/rename { sessionId, name } → renames the tab on every browser
|
|
29
29
|
* POST /v1/close { sessionId } → closes the tab (ends its SSH session) everywhere
|
|
30
|
-
* POST /v1/open { bookmarkId } →
|
|
30
|
+
* POST /v1/open { bookmarkId } → SSH: the server connects it (no browser needed) and every
|
|
31
|
+
* open page attaches; SFTP: opened by ONE connected browser
|
|
31
32
|
* POST /v1/type { sessionId?, text }
|
|
32
33
|
* POST /v1/key { sessionId?, key, repeat? }
|
|
33
34
|
* sessionId defaults to the focused tab.
|
|
@@ -260,6 +261,17 @@ class RemoteControlPlugin {
|
|
|
260
261
|
const bookmark = this.ctx.getBookmarks().find(b => b.id === bookmarkId);
|
|
261
262
|
if (!bookmark) throw new HttpError(404, 'Bookmark not found');
|
|
262
263
|
if (!['ssh', 'sftp'].includes(bookmark.type)) throw new HttpError(409, 'Only SSH/SFTP bookmarks can be opened');
|
|
264
|
+
// SSH: the server connects it itself — works with no browser open; open pages attach to the tab.
|
|
265
|
+
if (bookmark.type === 'ssh' && typeof this.ctx.openBookmark === 'function') {
|
|
266
|
+
let opened;
|
|
267
|
+
try {
|
|
268
|
+
opened = await this.ctx.openBookmark(bookmarkId);
|
|
269
|
+
} catch (err) {
|
|
270
|
+
throw new HttpError(err.status || 502, err.message);
|
|
271
|
+
}
|
|
272
|
+
this.ctx.switchTab(opened.sessionId);
|
|
273
|
+
return { opened: true, sessionId: opened.sessionId, name: opened.name, connected: true, headless: true };
|
|
274
|
+
}
|
|
263
275
|
const before = new Set(this.ctx.getTabs().tabs.map(t => t.sessionId));
|
|
264
276
|
const claim = await this.ctx.requestClientAction('remote-open-bookmark', { bookmarkId });
|
|
265
277
|
if (!claim.claimed) {
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
* - ctx.closeTab(sessionId) - Close a tab (ends its session) everywhere
|
|
31
31
|
* - ctx.getBookmarks() - Bookmark names/types (never credentials)
|
|
32
32
|
* - ctx.requestClientAction(event, data, opts) - Ask exactly ONE connected client to act
|
|
33
|
+
* - ctx.openBookmark(bookmarkId) - Connect an SSH bookmark on the server (no browser needed)
|
|
33
34
|
* - ctx.getDataDir() - User data directory (private plugin state)
|
|
34
35
|
*
|
|
35
36
|
* Plugins that hold resources (servers, timers) should implement destroy();
|
|
@@ -341,6 +342,12 @@ class PluginManager {
|
|
|
341
342
|
return self.requestClientAction(event, data, options);
|
|
342
343
|
},
|
|
343
344
|
|
|
345
|
+
// Connect an SSH bookmark on the server (no browser needed); browsers attach via tab-opened.
|
|
346
|
+
async openBookmark(bookmarkId, options = {}) {
|
|
347
|
+
const { openBookmarkHeadless } = require('../services/headless-open');
|
|
348
|
+
return openBookmarkHeadless(self.io, bookmarkId, options);
|
|
349
|
+
},
|
|
350
|
+
|
|
344
351
|
getDataDir() {
|
|
345
352
|
const { getDataDir } = require('../utils/config');
|
|
346
353
|
return getDataDir();
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Open an SSH bookmark on the SERVER, without any browser page.
|
|
3
|
+
*
|
|
4
|
+
* Used by automation (the remote-control plugin → voice assistants): the
|
|
5
|
+
* server connects the bookmark itself with a stand-in socket, registers the
|
|
6
|
+
* tab, and tells every connected browser through the normal `tab-opened`
|
|
7
|
+
* broadcast, so open pages attach exactly as they do for a tab opened on
|
|
8
|
+
* another device. Pages opened later get it through `open-tabs`.
|
|
9
|
+
*
|
|
10
|
+
* Credentials are read from the stored bookmark on the server; they are never
|
|
11
|
+
* broadcast (the browsers only receive name/host/port/username). Encrypted
|
|
12
|
+
* bookmarks work only while the server holds the unlock key (after a login).
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const crypto = require('crypto');
|
|
16
|
+
const { loadConfig, getStickySetting, getScrollback } = require('../utils/config');
|
|
17
|
+
const { getDecryptedBookmarks } = require('../utils/bookmark-encryption');
|
|
18
|
+
const tabManager = require('../utils/tab-manager');
|
|
19
|
+
const sshManager = require('./ssh-manager');
|
|
20
|
+
|
|
21
|
+
// Size of the server-side terminal until a browser attaches and resizes it.
|
|
22
|
+
// Wider than the 80x24 default so coding agents (Claude Code, opencode) and
|
|
23
|
+
// screen reads by the assistant are not cramped.
|
|
24
|
+
const HEADLESS_COLS = 120;
|
|
25
|
+
const HEADLESS_ROWS = 36;
|
|
26
|
+
|
|
27
|
+
class HeadlessOpenError extends Error {
|
|
28
|
+
constructor(status, message) { super(message); this.status = status; }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// A Socket.IO-shaped object that receives nothing: the session's output goes to
|
|
32
|
+
// the `session-<id>` room (browsers that join later) and to the headless terminal.
|
|
33
|
+
function standInSocket() {
|
|
34
|
+
const noop = () => {};
|
|
35
|
+
return { id: `headless-${crypto.randomUUID()}`, emit: noop, join: noop, leave: noop, to: () => ({ emit: noop }) };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function openBookmarkHeadless(io, bookmarkId, { cols = HEADLESS_COLS, rows = HEADLESS_ROWS } = {}) {
|
|
39
|
+
const config = loadConfig();
|
|
40
|
+
let bookmarks;
|
|
41
|
+
try {
|
|
42
|
+
bookmarks = getDecryptedBookmarks(config);
|
|
43
|
+
} catch (err) {
|
|
44
|
+
if (err.code === 'BOOKMARKS_LOCKED') throw new HeadlessOpenError(409, 'Bookmarks are encrypted and locked; log in to sshift once to unlock them');
|
|
45
|
+
throw err;
|
|
46
|
+
}
|
|
47
|
+
const bookmark = bookmarks.find(b => b.id === bookmarkId);
|
|
48
|
+
if (!bookmark) throw new HeadlessOpenError(404, 'Bookmark not found');
|
|
49
|
+
if ((bookmark.type || 'ssh') !== 'ssh') throw new HeadlessOpenError(409, 'Only SSH bookmarks can be opened without a browser');
|
|
50
|
+
|
|
51
|
+
const name = bookmark.name || bookmark.host || 'SSH';
|
|
52
|
+
const publicData = { name, host: bookmark.host, port: bookmark.port || 22, username: bookmark.username };
|
|
53
|
+
const socket = standInSocket();
|
|
54
|
+
let sessionId;
|
|
55
|
+
try {
|
|
56
|
+
sessionId = await sshManager.connect(socket, {
|
|
57
|
+
...publicData,
|
|
58
|
+
password: bookmark.password || '',
|
|
59
|
+
privateKey: bookmark.privateKey || '',
|
|
60
|
+
passphrase: bookmark.passphrase || '',
|
|
61
|
+
cols, rows,
|
|
62
|
+
sshKeepaliveInterval: config.sshKeepaliveInterval || 10000,
|
|
63
|
+
sshKeepaliveCountMax: config.sshKeepaliveCountMax || 1000,
|
|
64
|
+
scrollback: getScrollback()
|
|
65
|
+
});
|
|
66
|
+
} catch (err) {
|
|
67
|
+
throw new HeadlessOpenError(502, `Could not connect ${name}: ${err.message}`);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Nobody is attached: no controller, so the first browser that joins gets control.
|
|
71
|
+
const session = sshManager.sessions.get(sessionId);
|
|
72
|
+
if (session) {
|
|
73
|
+
session.sockets.delete(socket.id);
|
|
74
|
+
if (session.controllerSocket === socket.id) session.controllerSocket = null;
|
|
75
|
+
}
|
|
76
|
+
tabManager.addTab(sessionId, {
|
|
77
|
+
name,
|
|
78
|
+
type: 'ssh',
|
|
79
|
+
connectionData: publicData,
|
|
80
|
+
activeSockets: new Set(),
|
|
81
|
+
sticky: getStickySetting(),
|
|
82
|
+
openedHeadless: true
|
|
83
|
+
});
|
|
84
|
+
if (io) {
|
|
85
|
+
io.emit('tab-opened', { sessionId, name, type: 'ssh', connectionData: publicData });
|
|
86
|
+
io.emit('sessions-updated');
|
|
87
|
+
}
|
|
88
|
+
return { sessionId, name };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
module.exports = { openBookmarkHeadless, HeadlessOpenError, HEADLESS_COLS, HEADLESS_ROWS };
|
|
@@ -383,6 +383,10 @@ class SSHManager {
|
|
|
383
383
|
// Now join the session room to receive future updates
|
|
384
384
|
socket.join(`session-${sessionId}`);
|
|
385
385
|
session.sockets.add(socket.id);
|
|
386
|
+
// Nobody holds control (a server-opened tab, or every client left): the
|
|
387
|
+
// joining client takes it, otherwise its input would be dropped until a
|
|
388
|
+
// manual "take control".
|
|
389
|
+
if (!session.controllerSocket) session.controllerSocket = socket.id;
|
|
386
390
|
console.log(`[SSH] Socket ${socket.id} joined session ${sessionId}`);
|
|
387
391
|
|
|
388
392
|
// Notify client that they've joined, including whether terminal state was sent
|