dsh-remote-vs 0.24.0 → 0.25.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.
Files changed (61) hide show
  1. package/README.en.md +40 -10
  2. package/README.md +31 -9
  3. package/lib/client.js +2616 -542
  4. package/lib/index.js +186 -40
  5. package/lib/types/client/CodeEditor.d.ts +17 -0
  6. package/lib/types/client/EditorPane.d.ts +16 -5
  7. package/lib/types/client/FloatingPlaceholder.d.ts +16 -5
  8. package/lib/types/client/RemoteEditorView.d.ts +13 -10
  9. package/lib/types/client/RemoteRoot.d.ts +5 -5
  10. package/lib/types/client/TerminalSnippets.d.ts +36 -0
  11. package/lib/types/client/TerminalView.d.ts +1 -1
  12. package/lib/types/client/XTerm.d.ts +33 -0
  13. package/lib/types/client/editor-capability.d.ts +27 -0
  14. package/lib/types/client/i18n.d.ts +1 -1
  15. package/lib/types/client/store.d.ts +59 -4
  16. package/lib/types/client/terminal-input.d.ts +23 -0
  17. package/lib/types/client/terminal-snippets.d.ts +86 -0
  18. package/lib/types/client/vsc/breadcrumb.d.ts +30 -0
  19. package/lib/types/client/vsc/editor-caret.d.ts +32 -0
  20. package/lib/types/client/vsc/editor-langs.d.ts +9 -0
  21. package/lib/types/client/vsc/editor-settings.d.ts +55 -0
  22. package/lib/types/client/vsc/image-preview.d.ts +36 -0
  23. package/lib/types/client/vsc/kit.d.ts +2 -0
  24. package/lib/types/client/vsc/terminal-clipboard.d.ts +15 -0
  25. package/lib/types/client/vsc/terminal-line.d.ts +25 -0
  26. package/lib/types/client/vsc/terminal-links.d.ts +62 -0
  27. package/lib/types/client/vsc/terminal-theme.d.ts +22 -0
  28. package/lib/types/client/vsc/terminal-writer.d.ts +52 -0
  29. package/lib/types/pool.d.ts +25 -0
  30. package/lib/types/terminal.d.ts +25 -1
  31. package/package.json +1 -1
  32. package/src/client/CodeEditor.tsx +54 -2
  33. package/src/client/EditorPane.tsx +485 -107
  34. package/src/client/FloatingPlaceholder.tsx +34 -5
  35. package/src/client/RemoteEditorView.tsx +14 -11
  36. package/src/client/RemoteRoot.tsx +20 -125
  37. package/src/client/TerminalSnippets.tsx +357 -0
  38. package/src/client/TerminalView.tsx +50 -1
  39. package/src/client/XTerm.tsx +228 -58
  40. package/src/client/auto-open-remote.ts +11 -9
  41. package/src/client/editor-capability.ts +42 -0
  42. package/src/client/i18n.ts +148 -6
  43. package/src/client/index.tsx +22 -6
  44. package/src/client/store.tsx +165 -13
  45. package/src/client/terminal-input.ts +44 -0
  46. package/src/client/terminal-snippets.ts +216 -0
  47. package/src/client/vsc/breadcrumb.tsx +251 -0
  48. package/src/client/vsc/editor-caret.ts +30 -0
  49. package/src/client/vsc/editor-langs.ts +20 -0
  50. package/src/client/vsc/editor-settings.ts +146 -0
  51. package/src/client/vsc/editor-theme.ts +4 -5
  52. package/src/client/vsc/image-preview.tsx +110 -0
  53. package/src/client/vsc/kit.tsx +20 -1
  54. package/src/client/vsc/terminal-clipboard.ts +19 -0
  55. package/src/client/vsc/terminal-line.ts +101 -0
  56. package/src/client/vsc/terminal-links.ts +166 -0
  57. package/src/client/vsc/terminal-theme.ts +71 -0
  58. package/src/client/vsc/terminal-writer.ts +112 -0
  59. package/src/client/vsc/vsc.css +687 -48
  60. package/src/pool.ts +99 -27
  61. package/src/terminal.ts +160 -6
package/lib/index.js CHANGED
@@ -657,6 +657,24 @@ function isConnectionFailure(error) {
657
657
  var RemotePool = class {
658
658
  store;
659
659
  conns = /* @__PURE__ */ new Map();
660
+ /**
661
+ * Dedicated connections for PTY shells (one per alias).
662
+ *
663
+ * Why a SECOND connection instead of a channel on the shared one: ssh2
664
+ * multiplexes channels over ONE TCP connection, and SSH has no per-channel
665
+ * priority or flow control. A large SFTP transfer / git output on that
666
+ * connection therefore delays everything else on it — including the echo of a
667
+ * keystroke — which is exactly the "typing stutters when something else is
668
+ * moving data" report. A terminal gets its own connection, so its bytes never
669
+ * queue behind browse/exec traffic, and shells stop consuming the shared
670
+ * connection's channel budget as well.
671
+ *
672
+ * Cost: one extra SSH handshake per alias the first time a terminal opens,
673
+ * plus one held TCP connection per host with a terminal. `shell()` falls back
674
+ * to the shared connection if this one cannot be established at all, so a host
675
+ * that refuses extra connections still gets a working terminal.
676
+ */
677
+ shellConns = /* @__PURE__ */ new Map();
660
678
  /** TOFU fingerprints observed this process (alias -> sha256). */
661
679
  hostKeys = /* @__PURE__ */ new Map();
662
680
  /** Per-alias `setsid --wait` capability, probed once (see supportsSetsid). */
@@ -673,18 +691,13 @@ var RemotePool = class {
673
691
  /** Drop one pooled connection (call after host update/delete). */
674
692
  drop(alias) {
675
693
  this.evictBrowse(alias);
676
- const pooled = this.conns.get(alias);
677
694
  this.setsidProbes.delete(alias);
678
- if (pooled === void 0) return;
679
- this.conns.delete(alias);
680
- if (pooled.timer !== void 0) clearTimeout(pooled.timer);
681
- try {
682
- pooled.conn.end();
683
- } catch {}
695
+ this.evictFrom(this.conns, alias);
696
+ this.evictFrom(this.shellConns, alias);
684
697
  }
685
698
  /** Close every pooled connection. */
686
699
  dispose() {
687
- for (const alias of [...this.conns.keys()]) this.drop(alias);
700
+ for (const alias of /* @__PURE__ */ new Set([...this.conns.keys(), ...this.shellConns.keys()])) this.drop(alias);
688
701
  }
689
702
  /**
690
703
  * Forget one alias's connection HEALTH (host edited/removed), not just its
@@ -715,7 +728,7 @@ var RemotePool = class {
715
728
  return {
716
729
  alias,
717
730
  state: entry?.state ?? "idle",
718
- open: pooled !== void 0 && pooled.connecting === void 0,
731
+ open: pooled !== void 0 && pooled.connecting === void 0 || this.shellConns.get(alias)?.connecting === void 0 && this.shellConns.has(alias),
719
732
  ...entry?.okAt === void 0 ? {} : { okAt: entry.okAt },
720
733
  ...entry?.errorAt === void 0 ? {} : { errorAt: entry.errorAt },
721
734
  ...entry?.error === void 0 ? {} : { error: entry.error }
@@ -1047,8 +1060,23 @@ var RemotePool = class {
1047
1060
  }
1048
1061
  /** Open an interactive PTY shell. The caller owns the channel lifecycle. */
1049
1062
  async shell(alias, opts = {}) {
1050
- const conn = await this.acquire(alias);
1051
- this.hold(alias);
1063
+ /**
1064
+ * Prefer the DEDICATED PTY connection so terminal bytes never queue behind
1065
+ * SFTP/git/exec traffic on the shared one (SSH has no channel priority).
1066
+ * A host that refuses the extra connection still gets a terminal: the fallback
1067
+ * is the shared connection, exactly the old behaviour.
1068
+ */
1069
+ let conn;
1070
+ let dedicated = true;
1071
+ try {
1072
+ conn = await this.acquireShell(alias);
1073
+ this.holdIn(this.shellConns, alias);
1074
+ } catch (error) {
1075
+ dedicated = false;
1076
+ conn = await this.acquire(alias);
1077
+ this.hold(alias);
1078
+ if (!(error instanceof Error) || !isConnectionFailure(error)) console.warn("[dsh-remote-vs] dedicated PTY connection failed; using the shared one:", error);
1079
+ }
1052
1080
  try {
1053
1081
  const channel = await new Promise((resolve, reject) => {
1054
1082
  conn.shell({
@@ -1060,11 +1088,15 @@ var RemotePool = class {
1060
1088
  else resolve(stream);
1061
1089
  });
1062
1090
  });
1063
- channel.once("close", () => this.release(alias));
1091
+ channel.once("close", () => {
1092
+ if (dedicated) this.releaseIn(this.shellConns, alias);
1093
+ else this.release(alias);
1094
+ });
1064
1095
  this.markOk(alias);
1065
1096
  return channel;
1066
1097
  } catch (error) {
1067
- this.release(alias);
1098
+ if (dedicated) this.releaseIn(this.shellConns, alias);
1099
+ else this.release(alias);
1068
1100
  if (isConnectionFailure(error)) this.markError(alias, error);
1069
1101
  throw error;
1070
1102
  }
@@ -1604,7 +1636,10 @@ var RemotePool = class {
1604
1636
  }
1605
1637
  /** Hold the connection against idle eviction (balanced by release). */
1606
1638
  hold(alias) {
1607
- const pooled = this.conns.get(alias);
1639
+ this.holdIn(this.conns, alias);
1640
+ }
1641
+ holdIn(map, alias) {
1642
+ const pooled = map.get(alias);
1608
1643
  if (pooled === void 0) return;
1609
1644
  pooled.held += 1;
1610
1645
  pooled.lastUse = Date.now();
@@ -1614,17 +1649,27 @@ var RemotePool = class {
1614
1649
  }
1615
1650
  }
1616
1651
  release(alias) {
1617
- const pooled = this.conns.get(alias);
1652
+ this.releaseIn(this.conns, alias);
1653
+ }
1654
+ releaseIn(map, alias) {
1655
+ const pooled = map.get(alias);
1618
1656
  if (pooled === void 0) return;
1619
1657
  if (pooled.held > 0) pooled.held -= 1;
1620
1658
  pooled.lastUse = Date.now();
1621
1659
  if (pooled.held > 0) return;
1622
1660
  if (pooled.timer !== void 0) clearTimeout(pooled.timer);
1623
- pooled.timer = setTimeout(() => this.drop(alias), IDLE_MS);
1661
+ pooled.timer = setTimeout(() => this.evictFrom(map, alias), IDLE_MS);
1624
1662
  if (typeof pooled.timer === "object" && "unref" in pooled.timer) pooled.timer.unref();
1625
1663
  }
1626
1664
  async acquire(alias) {
1627
- const pooled = this.conns.get(alias);
1665
+ return this.acquireIn(this.conns, alias);
1666
+ }
1667
+ /** `acquire` for the dedicated PTY connection map. */
1668
+ async acquireShell(alias) {
1669
+ return this.acquireIn(this.shellConns, alias);
1670
+ }
1671
+ async acquireIn(map, alias) {
1672
+ const pooled = map.get(alias);
1628
1673
  if (pooled !== void 0 && pooled.connecting !== void 0) return pooled.connecting;
1629
1674
  if (pooled !== void 0) {
1630
1675
  pooled.lastUse = Date.now();
@@ -1637,7 +1682,7 @@ var RemotePool = class {
1637
1682
  connecting: void 0,
1638
1683
  held: 0
1639
1684
  };
1640
- this.conns.set(alias, entry);
1685
+ map.set(alias, entry);
1641
1686
  /**
1642
1687
  * The entry object IS the ownership token: `drop()` deletes it and a later
1643
1688
  * `acquire()` creates a NEW one, so comparing identity answers "does this
@@ -1650,7 +1695,7 @@ var RemotePool = class {
1650
1695
  * failure check, a failed OLD dial deletes the NEW entry by alias.
1651
1696
  */
1652
1697
  entry.connecting = this.dial(alias).then((conn) => {
1653
- if (this.conns.get(alias) !== entry) {
1698
+ if (map.get(alias) !== entry) {
1654
1699
  try {
1655
1700
  conn.end();
1656
1701
  } catch {}
@@ -1660,24 +1705,34 @@ var RemotePool = class {
1660
1705
  entry.connecting = void 0;
1661
1706
  this.markOk(alias);
1662
1707
  conn.on("close", () => {
1663
- if (this.conns.get(alias) !== entry) return;
1708
+ if (map.get(alias) !== entry) return;
1664
1709
  this.markError(alias, /* @__PURE__ */ new Error("connection closed"));
1665
- this.drop(alias);
1710
+ this.evictFrom(map, alias);
1666
1711
  });
1667
1712
  conn.on("error", (error) => {
1668
- if (this.conns.get(alias) !== entry) return;
1713
+ if (map.get(alias) !== entry) return;
1669
1714
  this.markError(alias, error);
1670
- this.drop(alias);
1715
+ this.evictFrom(map, alias);
1671
1716
  });
1672
- this.release(alias);
1717
+ this.releaseIn(map, alias);
1673
1718
  return conn;
1674
1719
  }, (error) => {
1675
- if (this.conns.get(alias) === entry) this.conns.delete(alias);
1720
+ if (map.get(alias) === entry) map.delete(alias);
1676
1721
  this.markError(alias, error);
1677
1722
  throw error;
1678
1723
  });
1679
1724
  return entry.connecting;
1680
1725
  }
1726
+ /** Evict ONE alias from ONE map (host removal drops both maps explicitly). */
1727
+ evictFrom(map, alias) {
1728
+ const pooled = map.get(alias);
1729
+ if (pooled === void 0) return;
1730
+ map.delete(alias);
1731
+ if (pooled.timer !== void 0) clearTimeout(pooled.timer);
1732
+ try {
1733
+ pooled.conn.end();
1734
+ } catch {}
1735
+ }
1681
1736
  /**
1682
1737
  * The ssh2 client factory.
1683
1738
  *
@@ -2735,12 +2790,44 @@ const EMPTY_SOCKET_TTL_MS = 10 * 6e4;
2735
2790
  * The retained ceiling is therefore this mark plus ssh2's window (2 MiB) plus
2736
2791
  * whatever is in flight — bounded, but not exactly 4 MiB.
2737
2792
  *
2793
+ * The mark is RESPONSIVENESS, not just memory: everything already handed to a
2794
+ * socket has to be parsed and painted by the browser before a later keystroke's
2795
+ * echo can appear, so a large mark means "type during a huge dump and wait
2796
+ * seconds". 2 MiB still absorbs a burst comfortably (a keystroke is bytes) while
2797
+ * keeping the worst-case echo delay down; ssh2's own 2 MiB window is the part we
2798
+ * cannot shrink from here.
2799
+ *
2738
2800
  * The counter is per session, not per socket: one lagging socket pauses the
2739
2801
  * channel for every socket attached to that shell. That is deliberate — the
2740
2802
  * alternative is letting the slowest consumer grow the host process.
2741
2803
  */
2742
- const OUT_HIGH_WATER = 4 * 1024 * 1024;
2743
- const OUT_LOW_WATER = 1 * 1024 * 1024;
2804
+ const OUT_HIGH_WATER = 2 * 1024 * 1024;
2805
+ const OUT_LOW_WATER = 512 * 1024;
2806
+ /** Default window for coalescing output frames (0 = one frame per chunk). */
2807
+ const OUT_COALESCE_MS = 8;
2808
+ /**
2809
+ * Flush immediately past this much buffered text (measured in UTF-16 code
2810
+ * units, i.e. `String.length`): a producer faster than the window must not turn
2811
+ * into an unbounded string copy (the channel backpressure bounds the bytes
2812
+ * handed to the SOCKETS, not this buffer).
2813
+ *
2814
+ * Code units rather than bytes on purpose: converting to a byte count would
2815
+ * copy the whole buffer on every chunk just to compare a threshold. CJK/emoji
2816
+ * output therefore flushes at up to ~3x this many bytes, which is still far
2817
+ * below the 1 MiB client-frame cap this path never approaches (it is the
2818
+ * client→host direction).
2819
+ */
2820
+ const OUT_COALESCE_CHARS = 64 * 1024;
2821
+ /**
2822
+ * How long the output must have been quiet for the NEXT chunk to be sent at once.
2823
+ *
2824
+ * A terminal echoes what the user types. Holding that echo for the coalescing
2825
+ * window is invisible at 8 ms — but under load the window itself is a timer in
2826
+ * an event loop shared with the agent, and the delay adds up. After a quiet
2827
+ * period the chunk is therefore flushed synchronously; only a running stream
2828
+ * (where `lastFlushAt` is fresh) is batched.
2829
+ */
2830
+ const OUT_ECHO_IDLE_MS = 24;
2744
2831
  /**
2745
2832
  * The largest client frame accepted, in bytes.
2746
2833
  *
@@ -2761,9 +2848,15 @@ const TERMINAL_MAX_FRAME_BYTES = 1024 * 1024;
2761
2848
  const WS_OPEN = 1;
2762
2849
  var TerminalSessionRegistry = class {
2763
2850
  pool;
2851
+ options;
2764
2852
  sessions = /* @__PURE__ */ new Map();
2765
- constructor(pool) {
2853
+ constructor(pool, options = {}) {
2766
2854
  this.pool = pool;
2855
+ this.options = options;
2856
+ }
2857
+ /** The window this registry coalesces within (`0` = every chunk is a frame). */
2858
+ get coalesceMs() {
2859
+ return this.options.coalesceMs ?? OUT_COALESCE_MS;
2767
2860
  }
2768
2861
  /** Open a shell and attach the first socket. */
2769
2862
  async open(ws, alias, cols, rows) {
@@ -2793,6 +2886,10 @@ var TerminalSessionRegistry = class {
2793
2886
  sockets: /* @__PURE__ */ new Set(),
2794
2887
  pending: 0,
2795
2888
  paused: false,
2889
+ outBuffer: "",
2890
+ outTimer: void 0,
2891
+ lastFlushAt: 0,
2892
+ outstanding: /* @__PURE__ */ new Map(),
2796
2893
  reap: void 0,
2797
2894
  outDecoder: new StringDecoder("utf8"),
2798
2895
  errDecoder: new StringDecoder("utf8")
@@ -2800,25 +2897,17 @@ var TerminalSessionRegistry = class {
2800
2897
  this.sessions.set(id, session);
2801
2898
  channel.on("data", (chunk) => {
2802
2899
  const text = session.outDecoder.write(chunk);
2803
- if (text !== "") this.broadcast(session, {
2804
- t: "out",
2805
- d: text
2806
- });
2900
+ if (text !== "") this.queueOut(session, text);
2807
2901
  });
2808
2902
  channel.stderr.on("data", (chunk) => {
2809
2903
  const text = session.errDecoder.write(chunk);
2810
- if (text !== "") this.broadcast(session, {
2811
- t: "out",
2812
- d: text
2813
- });
2904
+ if (text !== "") this.queueOut(session, text);
2814
2905
  });
2815
2906
  channel.on("close", (code) => {
2816
2907
  session.alive = false;
2817
2908
  session.exitCode = code;
2818
- for (const tail of [session.outDecoder.end(), session.errDecoder.end()]) if (tail !== "") this.broadcast(session, {
2819
- t: "out",
2820
- d: tail
2821
- });
2909
+ for (const tail of [session.outDecoder.end(), session.errDecoder.end()]) if (tail !== "") this.queueOut(session, tail);
2910
+ this.flushOut(session);
2822
2911
  this.broadcast(session, {
2823
2912
  t: "exit",
2824
2913
  code
@@ -2852,6 +2941,7 @@ var TerminalSessionRegistry = class {
2852
2941
  const session = this.sessions.get(id);
2853
2942
  if (session === void 0 || !session.alive) return false;
2854
2943
  this.hookSocket(session, ws);
2944
+ this.flushOut(session);
2855
2945
  this.send(ws, {
2856
2946
  t: "ready",
2857
2947
  id
@@ -2864,6 +2954,7 @@ var TerminalSessionRegistry = class {
2864
2954
  if (session === void 0) return false;
2865
2955
  this.sessions.delete(id);
2866
2956
  this.cancelReap(session);
2957
+ this.flushOut(session);
2867
2958
  try {
2868
2959
  session.channel.close();
2869
2960
  } catch {}
@@ -2871,6 +2962,8 @@ var TerminalSessionRegistry = class {
2871
2962
  socket.close(1e3);
2872
2963
  } catch {}
2873
2964
  session.sockets.clear();
2965
+ session.outstanding.clear();
2966
+ session.pending = 0;
2874
2967
  return true;
2875
2968
  }
2876
2969
  /** Close every session (plugin unload). */
@@ -2909,9 +3002,17 @@ var TerminalSessionRegistry = class {
2909
3002
  } catch {}
2910
3003
  });
2911
3004
  const detach = () => {
3005
+ this.flushOut(session);
3006
+ const unsettled = session.outstanding.get(ws);
3007
+ if (unsettled !== void 0) {
3008
+ session.outstanding.delete(ws);
3009
+ session.pending = Math.max(0, session.pending - unsettled);
3010
+ if (session.pending <= OUT_LOW_WATER) this.setPaused(session, false);
3011
+ }
2912
3012
  session.sockets.delete(ws);
2913
3013
  if (session.sockets.size > 0) return;
2914
3014
  session.pending = 0;
3015
+ session.outstanding.clear();
2915
3016
  this.setPaused(session, false);
2916
3017
  this.armReap(session);
2917
3018
  };
@@ -2944,6 +3045,45 @@ var TerminalSessionRegistry = class {
2944
3045
  clearTimeout(session.reap);
2945
3046
  session.reap = void 0;
2946
3047
  }
3048
+ /**
3049
+ * Queue one output chunk and schedule the coalesced frame.
3050
+ *
3051
+ * `coalesceMs === 0` broadcasts immediately (the checks rely on that
3052
+ * synchrony). A chunk that arrives after an idle gap is also sent at once —
3053
+ * that is the interactive echo path (a keystroke must not wait for the
3054
+ * window) — while a stream that keeps producing coalesces.
3055
+ */
3056
+ queueOut(session, text) {
3057
+ if (text === "") return;
3058
+ const idle = Date.now() - session.lastFlushAt >= OUT_ECHO_IDLE_MS;
3059
+ session.outBuffer += text;
3060
+ if (session.outBuffer.length >= OUT_COALESCE_CHARS || this.coalesceMs <= 0 || idle) {
3061
+ this.flushOut(session);
3062
+ return;
3063
+ }
3064
+ if (session.outTimer !== void 0) return;
3065
+ const timer = setTimeout(() => {
3066
+ session.outTimer = void 0;
3067
+ this.flushOut(session);
3068
+ }, this.coalesceMs);
3069
+ timer.unref?.();
3070
+ session.outTimer = timer;
3071
+ }
3072
+ /** Send the buffered output as ONE `out` frame (no-op when empty). */
3073
+ flushOut(session) {
3074
+ if (session.outTimer !== void 0) {
3075
+ clearTimeout(session.outTimer);
3076
+ session.outTimer = void 0;
3077
+ }
3078
+ if (session.outBuffer === "") return;
3079
+ const text = session.outBuffer;
3080
+ session.outBuffer = "";
3081
+ session.lastFlushAt = Date.now();
3082
+ this.broadcast(session, {
3083
+ t: "out",
3084
+ d: text
3085
+ });
3086
+ }
2947
3087
  setPaused(session, paused) {
2948
3088
  if (session.paused === paused) return;
2949
3089
  session.paused = paused;
@@ -2965,10 +3105,16 @@ var TerminalSessionRegistry = class {
2965
3105
  const done = () => {
2966
3106
  if (settled) return;
2967
3107
  settled = true;
3108
+ const left = session.outstanding.get(socket);
3109
+ if (left === void 0) return;
3110
+ const remaining = Math.max(0, left - size);
3111
+ if (remaining === 0) session.outstanding.delete(socket);
3112
+ else session.outstanding.set(socket, remaining);
2968
3113
  session.pending = Math.max(0, session.pending - size);
2969
3114
  if (session.pending <= OUT_LOW_WATER) this.setPaused(session, false);
2970
3115
  };
2971
3116
  session.pending += size;
3117
+ session.outstanding.set(socket, (session.outstanding.get(socket) ?? 0) + size);
2972
3118
  try {
2973
3119
  socket.send(text, done);
2974
3120
  } catch {
@@ -20,6 +20,8 @@ export interface CodeEditorViewState {
20
20
  head: number;
21
21
  }[];
22
22
  }
23
+ export { caretOf, type CodeEditorCaret } from './vsc/editor-caret.ts';
24
+ import { type CodeEditorCaret as CodeEditorCaretType } from './vsc/editor-caret.ts';
23
25
  export interface CodeEditorHandle {
24
26
  getContent: () => string;
25
27
  isDirty: () => boolean;
@@ -61,6 +63,21 @@ export declare const CodeEditor: import("react").ForwardRefExoticComponent<{
61
63
  readOnly?: boolean;
62
64
  /** Parent sub-tab visibility (views stay mounted; remeasure on show). */
63
65
  visible?: boolean;
66
+ /**
67
+ * Soft wrap long lines.
68
+ *
69
+ * `undefined` = the historical behaviour (wrap on) for callers that do not
70
+ * own the preference (diff panes); `false` turns it off.
71
+ */
72
+ wrap?: boolean;
73
+ /**
74
+ * Reports the 1-based caret line/column plus the selected character count.
75
+ *
76
+ * The status bar needs it and CodeMirror only exposes selection changes
77
+ * through an update listener, so the editor reports instead of the parent
78
+ * polling a ref. Called once with the initial position, then on every move.
79
+ */
80
+ onCaretChange?: (caret: CodeEditorCaretType) => void;
64
81
  /** Chat-insert target: absent/disabled hides the selection popup. */
65
82
  ctx?: Context;
66
83
  sessionId?: string | undefined;
@@ -1,11 +1,22 @@
1
1
  /**
2
2
  * The editor area: one tab strip for code files, previews and diffs, an info
3
- * row, and the body dispatch.
3
+ * row, the body, and (in the full-width conversation-view variant) a status bar.
4
4
  *
5
- * The `@文件` insertion and the selection→conversation popup are preserved
6
- * from the previous editor: `CodeEditor` still receives the chat target, and
7
- * every code pane is the same CodeMirror buffer with Ctrl+S wired to the
8
- * remote write route.
5
+ * The chrome follows the local sidebar plugin's editor (same tab strip, info
6
+ * row, empty states, status bar, image preview and editor background tokens),
7
+ * while every remote-only capability stays exactly where it was: the remote
8
+ * read/write routes, the save-conflict banner and its on-demand difference, the
9
+ * diff tabs, markdown/HTML previews, session change marks and the offline
10
+ * read-only degradation.
11
+ *
12
+ * Three variants share this component, chosen from the store's effective
13
+ * surface — never from a prop, so a surface can never mount two live buffers:
14
+ * - `sidebar`: the docked pane — a FULL-COLUMN rail page and the default seat
15
+ * (opening a file switches the rail to it; closing the last file switches
16
+ * back to the directory);
17
+ * - `center`: the conversation-view tab next to 对话 / 轨迹 (optional, full
18
+ * width, breadcrumb + status bar);
19
+ * - `float`: the frame-wide floating window (its own font zoom applies).
9
20
  */
10
21
  import { type ReactNode } from 'react';
11
22
  /**
@@ -1,9 +1,20 @@
1
1
  /**
2
2
  * What the centre conversation view and the sidebar fallback show while the
3
- * editor is popped out: the editor itself is a single instance and lives in the
4
- * floating window, so these surfaces must not mount a second one (that would
5
- * be two live CodeMirror buffers for one tab — the exact defect `EditorPane`'s
6
- * header warns about). A dock button keeps the surface from looking broken.
3
+ * editor lives somewhere else: the editor itself is a single instance, so these
4
+ * surfaces must not mount a second one (that would be two live CodeMirror
5
+ * buffers for one tab — the exact defect `EditorPane`'s header warns about).
6
+ *
7
+ * Three such places exist now that the DOCKED sidebar pane is the default seat:
8
+ * - `float`: the editor is popped out into the frame-wide window;
9
+ * - `sidebar`: the editor is docked in the sidebar column, and the
10
+ * conversation-view tab is only its optional full-width seat;
11
+ * - `center`: the reverse — the conversation tab owns the editor, and the
12
+ * sidebar's editor page explains how to bring it back.
13
+ * A button per mode keeps the surface from looking broken.
7
14
  */
8
15
  import type { ReactNode } from 'react';
9
- export declare function FloatingEditorPlaceholder(): ReactNode;
16
+ /** Which seat currently owns the editor. */
17
+ export type PlaceholderMode = 'float' | 'sidebar' | 'center';
18
+ export declare function FloatingEditorPlaceholder(props: {
19
+ mode?: PlaceholderMode;
20
+ }): ReactNode;
@@ -1,11 +1,12 @@
1
1
  /**
2
- * The conversation-view tab: the same editor tab strip, previews and diff as
3
- * the sidebar, mounted next to 对话 / 轨迹 at full width.
2
+ * The conversation-view tab: the same editor (tab strip, previews, diff, status
3
+ * bar) mounted next to 对话 / 轨迹 at full width.
4
4
  *
5
- * Registered into the `conversation.view` slot when that slot exists; the
6
- * sidebar then keeps the whole column for the explorer. Both surfaces read
7
- * the same module-level store, so a diff opened from source control appears
8
- * here, and a save here repaints the sidebar's change list.
5
+ * This is the OPTIONAL seat now: the docked sidebar pane is the default one, so
6
+ * a file click lands there and this tab shows a "docked in the sidebar"
7
+ * placeholder until the editor's own surface button moves it here. Both seats
8
+ * read the same module-level store, so a diff opened from source control
9
+ * appears here too and a save here repaints the sidebar's change list.
9
10
  *
10
11
  * While the editor floats (`editorSurface === 'float'`) this tab is NOT the
11
12
  * editor's mount any more, so it renders a placeholder instead: mounting a
@@ -14,10 +15,12 @@
14
15
  import type { Context } from '@deepseek-ai/cordis';
15
16
  import type { ReactNode } from 'react';
16
17
  /**
17
- * The conversation-view body. The editor surface flag is owned by the client
18
- * entry (registration success decides it), NOT by this component: the view
19
- * may be unmounted while another conversation tab is selected, and flipping
20
- * the flag here would make the sidebar's rail flicker on every tab switch.
18
+ * The conversation-view body. The editor surface flag is the STORE's (the
19
+ * docked pane is the default; this view renders only while the user has moved
20
+ * the editor here), and deliberately not derived from this component's own
21
+ * mount: the view is unmounted while another conversation tab is selected, so
22
+ * inferring the surface from mount/unmount would flip the sidebar's rail — and
23
+ * its editor — on every host tab switch.
21
24
  */
22
25
  export declare function RemoteEditorView(props: {
23
26
  ctx: Context;
@@ -2,11 +2,11 @@
2
2
  * Sidebar surface (better-sidebar tab, or the native right-Sidebar fallback):
3
3
  * a VS Code-style activity rail plus one column that shows the active view.
4
4
  *
5
- * The editor itself lives in the conversation view next to 轨迹 whenever that
6
- * registration succeeds (`editorSurface === 'center'`), so the tree keeps the
7
- * whole column; on a host where the conversation slot is unavailable the old
8
- * split (panel above the editor) still applies and nothing becomes
9
- * unreachable.
5
+ * The DOCKED editor is the default seat (`editorSurface === 'sidebar'`) and it
6
+ * is a FULL-COLUMN rail page — one view at a time, like the local sidebar
7
+ * plugin: opening a file switches the column to the editor, and closing its last
8
+ * file switches back to the directory. The conversation-view tab next to 轨迹 is
9
+ * the OPTIONAL full-width seat the editor's own button switches to.
10
10
  */
11
11
  import type { Context } from '@deepseek-ai/cordis';
12
12
  import { type ReactNode } from 'react';
@@ -0,0 +1,36 @@
1
+ /**
2
+ * The "常用指令" panel above the terminal: a personal library of NAME + COMMAND
3
+ * pairs that paste into the active terminal's command line WITHOUT pressing
4
+ * Enter (misclick safety: the user still reviews and runs it).
5
+ *
6
+ * Why it is a popover rather than a dock: the terminal needs the whole column
7
+ * for output; the list is opened deliberately, used once, and dismissed. The
8
+ * panel is portaled with fixed coordinates so the terminal's own scroller and
9
+ * the sidebar's `overflow: hidden` cannot clip it.
10
+ *
11
+ * Snapshot + subscribe come from `terminal-snippets.ts` (one list shared with the
12
+ * Ctrl+B quick-add shortcut, which `XTerm` reports as a counter prop).
13
+ */
14
+ import { type ReactNode } from 'react';
15
+ /** Props of the panel (plus the button that opens it). */
16
+ export interface TerminalSnippetsProps {
17
+ /** Translator. */
18
+ t: (key: string) => string;
19
+ /** Insert one command into the active terminal; false when none is mounted. */
20
+ onInsert: (command: string) => boolean;
21
+ /** Bumped by the Ctrl+B shortcut; each change opens the ADD dialog. */
22
+ addRequest: number;
23
+ /**
24
+ * Draft the Ctrl+B form starts with (the terminal selection, else the line
25
+ * reconstructed from keystrokes). Empty for the panel's own "+" button.
26
+ */
27
+ addContent: string;
28
+ }
29
+ /**
30
+ * The panel.
31
+ *
32
+ * Kept in one component on purpose: the button, the popover, the form and their
33
+ * shared focus/dismissal rules are one interaction, and splitting them would
34
+ * need a context for four pieces of state.
35
+ */
36
+ export declare function TerminalSnippets(props: TerminalSnippetsProps): ReactNode;
@@ -9,7 +9,7 @@
9
9
  */
10
10
  import { type ReactNode } from 'react';
11
11
  import type { RemoteHostSummary } from '../protocol.ts';
12
- import type { TerminalRequest } from './store.tsx';
12
+ import { type TerminalRequest } from './store.tsx';
13
13
  /** First mount claims the panel, so a single-surface profile renders at once. */
14
14
  export declare function claimTerminalOwnerIfNone(id: symbol): void;
15
15
  /** Whether `id` is the surface that currently owns the terminal panel. */
@@ -20,4 +20,37 @@ export declare function XTerm(props: {
20
20
  initialInput?: string;
21
21
  /** Translator for the right-click menu (copy / paste / select all). */
22
22
  t: (key: string) => string;
23
+ /** Tab identity, used by the snippet panel to target THIS terminal. */
24
+ tabId: string;
25
+ /**
26
+ * Ctrl/Cmd+B inside the terminal: open the "add snippet" form.
27
+ *
28
+ * Receives a best-effort draft so the form can pre-fill its command: the
29
+ * current terminal SELECTION when there is one (the user picked exactly what
30
+ * they want), else the line reconstructed from this session's keystrokes.
31
+ *
32
+ * Absent → the keystroke stays the shell's (readline's backward-char), which
33
+ * is what a host that did not wire the panel should keep.
34
+ */
35
+ onQuickAddSnippet?: (draft: {
36
+ selection?: string;
37
+ line?: string;
38
+ }) => void;
39
+ /**
40
+ * Remote home directory of this tab's host, when known.
41
+ *
42
+ * Used to resolve a `~/x` token printed by the shell. The SSH user's home is
43
+ * the only honest source — the terminal protocol carries no home directory.
44
+ */
45
+ home?: string;
46
+ /**
47
+ * Ctrl/Cmd + click on a path printed in the terminal.
48
+ *
49
+ * Receives the path AS PRINTED plus the hints that make sense of a relative
50
+ * one: the shell's cwd when it reports it (OSC 7) and the remote home.
51
+ */
52
+ onPathClick?: (token: string, context: {
53
+ cwd?: string;
54
+ home?: string;
55
+ }) => void;
23
56
  }): ReactNode;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Whether this page has ANY seat that can render the plugin's editor.
3
+ *
4
+ * Why not "is an `EditorPane` mounted right now": the editor panels are
5
+ * lazy/keep-alive (the sidebar's editor page is only rendered after the rail has
6
+ * visited it, and the conversation-view seat only exists while its host tab is
7
+ * selected). That made the first file click after a page load fall back to the
8
+ * host's native preview — which cannot resolve remote paths at all — even though
9
+ * our editor was one click away. The question the interceptor must answer is
10
+ * "could this file be shown in our editor in this page", i.e. a seat exists.
11
+ *
12
+ * Seats are registered exactly where a surface is registered:
13
+ * - the better-sidebar tab (`index.tsx` `goBetter`),
14
+ * - the native right-sidebar page (`registerNativeExplorer` returning a
15
+ * disposer),
16
+ * - the conversation-view tab (`conversation.view` registration).
17
+ *
18
+ * Pure module (no React/DOM) so the gate can drive register/unregister.
19
+ */
20
+ /** One seat became available (a tab/view registration succeeded). */
21
+ export declare function noteEditorSeatAvailable(): void;
22
+ /** One seat went away (a registration was disposed); never negative. */
23
+ export declare function noteEditorSeatGone(): void;
24
+ /** How many seats exist right now. */
25
+ export declare function editorSeatCount(): number;
26
+ /** Test-only reset (the gate drives the counter directly). */
27
+ export declare function resetEditorSeatsForTests(): void;