@lethevimlet/sshift 1.9.4 → 1.9.6

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
@@ -274,7 +274,7 @@ See [Configuration > Plugins](docs/configuration.md#plugins) for full details.
274
274
  ### Remote Control (local assistants)
275
275
 
276
276
  The opt-in `remote-control` plugin exposes a **loopback-only, token-protected** HTTP API so a
277
- local assistant (for example a voice assistant's MCP server) can list and switch tabs, open
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
279
  presses Enter; submitting is always a separate, explicit key request.
280
280
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lethevimlet/sshift",
3
- "version": "1.9.4",
3
+ "version": "1.9.6",
4
4
  "description": "Web-based SSH + SFTP terminal client with tabs and bookmarks",
5
5
  "main": "src/server/index.js",
6
6
  "bin": {
@@ -25,6 +25,8 @@
25
25
  * GET /v1/bookmarks → { bookmarks: [{ id, name, type, folder }] }
26
26
  * GET /v1/screen?sessionId=&history=N
27
27
  * POST /v1/switch { sessionId }
28
+ * POST /v1/rename { sessionId, name } → renames the tab on every browser
29
+ * POST /v1/close { sessionId } → closes the tab (ends its SSH session) everywhere
28
30
  * POST /v1/open { bookmarkId } → opens it on ONE connected browser
29
31
  * POST /v1/type { sessionId?, text }
30
32
  * POST /v1/key { sessionId?, key, repeat? }
@@ -160,6 +162,8 @@ class RemoteControlPlugin {
160
162
  case 'GET /v1/bookmarks': return send(200, { bookmarks: this.ctx.getBookmarks() });
161
163
  case 'GET /v1/screen': return send(200, this.screen(url.searchParams.get('sessionId'), url.searchParams.get('history')));
162
164
  case 'POST /v1/switch': return send(200, this.switchTab(body.sessionId));
165
+ case 'POST /v1/rename': return send(200, this.renameTab(body.sessionId, body.name));
166
+ case 'POST /v1/close': return send(200, this.closeTab(body.sessionId));
163
167
  case 'POST /v1/open': return send(200, await this.open(body.bookmarkId));
164
168
  case 'POST /v1/type': return send(200, await this.type(body.sessionId, body.text));
165
169
  case 'POST /v1/key': return send(200, await this.key(body.sessionId, body.key, body.repeat));
@@ -234,6 +238,22 @@ class RemoteControlPlugin {
234
238
  return { switched: true, sessionId, name: tab?.name || null };
235
239
  }
236
240
 
241
+ closeTab(sessionId) {
242
+ if (typeof sessionId !== 'string' || !sessionId) throw new HttpError(400, 'sessionId required');
243
+ const tab = this.ctx.getTabs().tabs.find(t => t.sessionId === sessionId);
244
+ if (!tab) throw new HttpError(404, 'Tab not found');
245
+ if (typeof this.ctx.closeTab !== 'function' || !this.ctx.closeTab(sessionId)) throw new HttpError(404, 'Tab not found');
246
+ return { closed: true, sessionId, name: tab.name, position: tab.position };
247
+ }
248
+
249
+ renameTab(sessionId, name) {
250
+ if (typeof sessionId !== 'string' || !sessionId) throw new HttpError(400, 'sessionId required');
251
+ const clean = typeof name === 'string' ? name.trim().replace(/\s+/g, ' ') : '';
252
+ if (!clean || clean.length > 40 || /[\x00-\x1f\x7f-\x9f]/.test(clean)) throw new HttpError(400, 'name must be 1-40 printable characters');
253
+ if (typeof this.ctx.renameTab !== 'function' || !this.ctx.renameTab(sessionId, clean)) throw new HttpError(404, 'Tab not found');
254
+ return { renamed: true, sessionId, name: clean };
255
+ }
256
+
237
257
  async open(bookmarkId) {
238
258
  const bookmark = this.ctx.getBookmarks().find(b => b.id === bookmarkId);
239
259
  if (!bookmark) throw new HttpError(404, 'Bookmark not found');
@@ -26,6 +26,8 @@
26
26
  * - ctx.getTerminalText(sessionId, options) - Plain-text screen (+ history) and input modes
27
27
  * - ctx.getTabs() - Open tabs in order, with the focused session
28
28
  * - ctx.switchTab(sessionId) - Focus a tab on every connected client
29
+ * - ctx.renameTab(sessionId, name) - Rename a tab on the server and every client
30
+ * - ctx.closeTab(sessionId) - Close a tab (ends its session) everywhere
29
31
  * - ctx.getBookmarks() - Bookmark names/types (never credentials)
30
32
  * - ctx.requestClientAction(event, data, opts) - Ask exactly ONE connected client to act
31
33
  * - ctx.getDataDir() - User data directory (private plugin state)
@@ -300,6 +302,29 @@ class PluginManager {
300
302
  return true;
301
303
  },
302
304
 
305
+ closeTab(sessionId) {
306
+ // Same as a user closing the tab: end the SSH/SFTP session and remove it everywhere.
307
+ const tm = self.tabManager;
308
+ const tab = tm && tm.getTab(sessionId);
309
+ if (!tab) return false;
310
+ tm.clearCloseTimer(sessionId);
311
+ tm.removeTab(sessionId);
312
+ if (tab.type === 'ssh' && self.sshManager) self.sshManager.disconnect(sessionId);
313
+ if (tab.type === 'sftp') {
314
+ try { require('../services').sftpManager.disconnect(sessionId); } catch (e) { /* ignore */ }
315
+ }
316
+ if (self.io) { self.io.emit('tab-closed', { sessionId }); self.io.emit('sessions-updated'); }
317
+ return true;
318
+ },
319
+
320
+ renameTab(sessionId, name) {
321
+ const tm = self.tabManager;
322
+ if (!tm || !tm.getTab(sessionId)) return false;
323
+ tm.updateTabName(sessionId, name);
324
+ if (self.io) self.io.emit('tab-renamed', { sessionId, name });
325
+ return true;
326
+ },
327
+
303
328
  getBookmarks() {
304
329
  const { loadConfig } = require('../utils/config');
305
330
  const config = loadConfig();
@@ -4873,7 +4873,7 @@ const wheelHandler = (e) => {
4873
4873
  if (tab) {
4874
4874
  const nameSpan = tab.querySelector('.tab-name');
4875
4875
  if (nameSpan) {
4876
- nameSpan.textContent = this.escapeHtml(data.name);
4876
+ nameSpan.textContent = data.name; // textContent is already safe; escaping here showed "&"
4877
4877
  }
4878
4878
  }
4879
4879