@lethevimlet/sshift 1.7.6 → 1.7.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lethevimlet/sshift",
3
- "version": "1.7.6",
3
+ "version": "1.7.8",
4
4
  "description": "Web-based SSH + SFTP terminal client with tabs and bookmarks",
5
5
  "main": "src/server/index.js",
6
6
  "bin": {
@@ -25,7 +25,7 @@ const selfsigned = require('selfsigned');
25
25
  const httpolyglot = require('httpolyglot');
26
26
 
27
27
  // Import utilities
28
- const { ensureConfig, loadConfig, getPort, getBindAddress, getEnableHttps, getHttpRedirect, getCertPath, getKeyPath, getDataDir, getLegacyDataDir, isPasswordSet, USER_INSTALL_DIR } = require('./utils/config');
28
+ const { ensureConfig, loadConfig, getPort, getBindAddress, getEnableHttps, getHttpRedirect, getCertPath, getKeyPath, getDataDir, getLegacyDataDir, isPasswordSet, USER_INSTALL_DIR, migrateLegacyPackageConfig } = require('./utils/config');
29
29
 
30
30
  // Import services
31
31
  const { sshManager, sftpManager } = require('./services');
@@ -214,6 +214,11 @@ let actuallyHttps = false;
214
214
 
215
215
  // Async initialization function
216
216
  async function initializeServer() {
217
+ // Rescue legacy package-directory configs BEFORE anything else: they
218
+ // are destroyed by the next `npm install -g` (GUI update). Must run
219
+ // before ensureConfig(), which would otherwise consider the package-
220
+ // dir config "existing" and skip creating the durable user-space one.
221
+ migrateLegacyPackageConfig();
217
222
  ensureConfig();
218
223
 
219
224
  if (enableHttps) {
@@ -11,8 +11,16 @@ const crypto = require('crypto');
11
11
  // Get user's home directory
12
12
  const HOME_DIR = os.homedir();
13
13
 
14
- // User install directory for config
15
- const USER_INSTALL_DIR = path.join(HOME_DIR, '.local', 'share', 'sshift');
14
+ // User install directory for config. SSHIFT_DATA_DIR overrides it — used
15
+ // by the Docker image to point the app at a mounted volume so that
16
+ // config.json (bookmarks, folders, settings) and the self-signed
17
+ // certificates survive container recreation on image updates. Without
18
+ // it, a Docker install writes to $HOME/.local/share/sshift inside the
19
+ // container's ephemeral writable layer and loses everything whenever the
20
+ // container is recreated (docker compose pull && up -d).
21
+ const USER_INSTALL_DIR = process.env.SSHIFT_DATA_DIR
22
+ ? path.resolve(process.env.SSHIFT_DATA_DIR)
23
+ : path.join(HOME_DIR, '.local', 'share', 'sshift');
16
24
 
17
25
  // Config paths - prioritize package directory, then user install directory
18
26
  const PACKAGE_DIR = path.join(__dirname, '..', '..', '..');
@@ -302,7 +310,55 @@ function getDataDir() {
302
310
  }
303
311
 
304
312
  /**
305
- * Get the legacy data directory (package directory) used before
313
+ * Legacy package-directory config migration.
314
+ *
315
+ * Versions before ~v1.3.x (pre May 2026) created config.json INSIDE the
316
+ * npm package directory (<npm-global>/node_modules/@lethevimlet/sshift/).
317
+ * The search order still prefers those paths, so legacy installs keep
318
+ * working — but they are a time bomb: `npm install -g` (used by the GUI
319
+ * update and manual updates) replaces the package directory wholesale
320
+ * and DESTROYS such configs (verified: bookmarks vanish on update).
321
+ *
322
+ * This copies a legacy package-dir config to the user install directory
323
+ * (which survives npm updates) BEFORE an update can delete it. The
324
+ * package-dir file is left in place (it still wins the search order),
325
+ * but once an update removes it the user-space copy takes over
326
+ * seamlessly with all bookmarks/folders/settings intact.
327
+ *
328
+ * No-op when a user-space config already exists or when no package-dir
329
+ * config is present.
330
+ *
331
+ * @returns {string|null} Path the config was migrated to, or null
332
+ */
333
+ function migrateLegacyPackageConfig() {
334
+ const userConfigPath = path.join(USER_INSTALL_DIR, '.env', 'config.json');
335
+ if (fs.existsSync(userConfigPath)) return null;
336
+
337
+ const legacyPaths = [
338
+ path.join(PACKAGE_DIR, '.env', 'config.json'),
339
+ path.join(PACKAGE_DIR, 'config.json'),
340
+ ];
341
+
342
+ for (const legacyPath of legacyPaths) {
343
+ if (fs.existsSync(legacyPath)) {
344
+ try {
345
+ fs.mkdirSync(path.dirname(userConfigPath), { recursive: true });
346
+ fs.copyFileSync(legacyPath, userConfigPath);
347
+ console.log('[CONFIG] Legacy package-directory config detected — copied to', userConfigPath);
348
+ console.log('[CONFIG] The package-dir copy is left in place; the user-space copy now');
349
+ console.log('[CONFIG] guarantees settings/bookmarks survive the next npm update.');
350
+ return userConfigPath;
351
+ } catch (e) {
352
+ console.warn('[CONFIG] Failed to migrate package-directory config:', e.message);
353
+ return null;
354
+ }
355
+ }
356
+ }
357
+ return null;
358
+ }
359
+
360
+ /**
361
+ * Get legacy data directory (package directory) used before
306
362
  * certs were moved to user space. Used for migration only.
307
363
  * @returns {string|null} Path to legacy data directory, or null if N/A
308
364
  */
@@ -476,6 +532,7 @@ module.exports = {
476
532
  getConfigPath,
477
533
  loadConfig,
478
534
  saveConfig,
535
+ migrateLegacyPackageConfig,
479
536
  getPort,
480
537
  getBindAddress,
481
538
  getSSHKeepaliveSettings,
@@ -4436,7 +4436,21 @@ const wheelHandler = (e) => {
4436
4436
  this.socket.emit('ssh-data', { sessionId: this.activeSessionId, data: keySequence });
4437
4437
  console.log('[SSHIFT] Sent mobile key:', keyName, 'sequence:', keySequence);
4438
4438
  }
4439
-
4439
+
4440
+ // Keys-bar keys change the remote line/cursor in ways the hidden
4441
+ // textarea cannot model (Tab completes a word, arrows move the
4442
+ // cursor mid-line, Ctrl+C/U/D abort or clear the line, Esc aborts).
4443
+ // The textarea diff assumes the remote cursor sits at the END of
4444
+ // the sent baseline — that model is dead now. Reset the field and
4445
+ // baseline so typing continues from a clean slate: new input
4446
+ // appends at the remote cursor position, exactly like a real
4447
+ // keyboard. _resetInputTracking is composition-guarded, so an
4448
+ // in-flight Gboard composition is not corrupted mid-word (the
4449
+ // reset is deferred to compositionend).
4450
+ if (this.isMobile && session.mobileHandler && session.mobileHandler.hiddenTextarea) {
4451
+ session.mobileHandler._resetInputTracking();
4452
+ }
4453
+
4440
4454
  // Focus terminal after sending key
4441
4455
  if (this.isMobile && session.mobileHandler && session.mobileHandler.hiddenTextarea) {
4442
4456
  session.mobileHandler._focusHiddenTextarea();
@@ -4774,6 +4788,11 @@ const wheelHandler = (e) => {
4774
4788
  if (data.noTerminalState) {
4775
4789
  console.log('[SSHIFT] No terminal state on server, clearing syncing flag');
4776
4790
  session.syncing = false;
4791
+ // No serialized state is coming — the data buffered during the
4792
+ // sync window is the ONLY output this client has received.
4793
+ // Drain it or it stays stuck (permanently missing rows in
4794
+ // line-diff TUI screens — the stale/black-line bug).
4795
+ this._drainSyncBuffer(session);
4777
4796
  }
4778
4797
 
4779
4798
  // Handle controller status
@@ -9606,17 +9625,23 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
9606
9625
  // into the normal write path and schedule a flush. Called when a sync
9607
9626
  // completes (or is aborted) so no live output is lost.
9608
9627
  _drainSyncBuffer(session) {
9609
- if (!session || !session.terminal) { session.syncBuffer = []; return; }
9628
+ if (!session) return;
9610
9629
  const buffered = session.syncBuffer || [];
9611
9630
  session.syncBuffer = [];
9612
- if (buffered.length > 0) {
9631
+ if (buffered.length === 0) return;
9632
+ if (!session.terminal) {
9633
+ // Terminal not created yet — keep the data in the regular write
9634
+ // buffer; its terminal-not-ready retry path flushes it once the
9635
+ // terminal exists. Never discard live output.
9613
9636
  session.writeChunks.push(...buffered);
9614
- if (!session.writeRAF) {
9615
- const sessionId = session.id;
9616
- session.writeRAF = requestAnimationFrame(() => {
9617
- this._flushWriteChunks(sessionId);
9618
- });
9619
- }
9637
+ return;
9638
+ }
9639
+ session.writeChunks.push(...buffered);
9640
+ if (!session.writeRAF) {
9641
+ const sessionId = session.id;
9642
+ session.writeRAF = requestAnimationFrame(() => {
9643
+ this._flushWriteChunks(sessionId);
9644
+ });
9620
9645
  }
9621
9646
  }
9622
9647
 
@@ -1561,23 +1561,24 @@ class MobileTerminalHandler {
1561
1561
  // Do NOT clear the textarea on refocus. The diff baseline
1562
1562
  // (_sentValue) tracks exactly what was sent to the terminal, so
1563
1563
  // stale-looking content is NOT stale: textarea, baseline and the
1564
- // remote prompt line all agree, and Gboard's own model of the
1565
- // field (from its last focus query) agrees too.
1564
+ // remote prompt line all agree. Clearing here (v1.7.0 behaviour)
1565
+ // is a programmatic assignment INVISIBLE to Gboard, desyncing its
1566
+ // field model — the "hel" + autocomplete → "helhel" bug. Keeping
1567
+ // the text lets the IME operate on the real pending line so
1568
+ // suggestion taps send only the true delta.
1566
1569
  //
1567
- // Wiping the value here (the old behaviour) is a programmatic
1568
- // assignment that is INVISIBLE to Gboard: the keyboard keeps its
1569
- // cached model ("hel"), the field is now empty, and the next
1570
- // suggestion tap re-inserts text computed from the stale model.
1571
- // The diff then treats that fragment as brand-new text and sends
1572
- // it on top of what the terminal already echoed — the classic
1573
- // "hel" + autocomplete → "helhel" duplication. Keeping the
1574
- // textarea intact keeps the IME, the field and the baseline in
1575
- // sync; autocomplete diffs then send only the true delta.
1576
- //
1577
- // Genuine context switches (session teardown, Enter/newline,
1578
- // Tab key, selection start) still reset explicitly via
1579
- // _resetInputTracking().
1570
+ // CRITICAL: the diff is append-at-end semantics (longest common
1571
+ // prefix from the END of the sent baseline). After a programmatic
1572
+ // focus() the caret typically lands at position 0 (NOT at the end
1573
+ // of the text), so the next keystroke would be inserted at the
1574
+ // START of the field — the diff then sees total divergence and
1575
+ // re-sends the ENTIRE field, retyping already-echoed words on
1576
+ // every keystroke after a tap (the "repeats words without
1577
+ // autocomplete" regression). Force the caret to the end so typing
1578
+ // appends, matching both the diff and the remote prompt cursor.
1579
+ const len = this.hiddenTextarea.value.length;
1580
1580
  this.hiddenTextarea.focus();
1581
+ try { this.hiddenTextarea.setSelectionRange(len, len); } catch (_) {}
1581
1582
  this._keyboardCollapsed = false;
1582
1583
  }
1583
1584
  }