dsh-remote-vs 0.23.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 (81) hide show
  1. package/README.en.md +49 -15
  2. package/README.md +40 -14
  3. package/lib/client.js +45978 -43338
  4. package/lib/index.js +388 -90
  5. package/lib/p2-router-fs.js +1 -1
  6. package/lib/types/client/CodeEditor.d.ts +17 -0
  7. package/lib/types/client/EditorPane.d.ts +16 -5
  8. package/lib/types/client/FloatingPlaceholder.d.ts +16 -5
  9. package/lib/types/client/RemoteEditorView.d.ts +13 -10
  10. package/lib/types/client/RemoteRoot.d.ts +5 -5
  11. package/lib/types/client/SettingsHosts.d.ts +3 -0
  12. package/lib/types/client/TerminalSnippets.d.ts +36 -0
  13. package/lib/types/client/TerminalView.d.ts +1 -1
  14. package/lib/types/client/XTerm.d.ts +33 -0
  15. package/lib/types/client/api.d.ts +4 -1
  16. package/lib/types/client/auto-open-remote.d.ts +41 -0
  17. package/lib/types/client/editor-capability.d.ts +27 -0
  18. package/lib/types/client/i18n.d.ts +1 -1
  19. package/lib/types/client/store.d.ts +59 -4
  20. package/lib/types/client/terminal-input.d.ts +23 -0
  21. package/lib/types/client/terminal-snippets.d.ts +86 -0
  22. package/lib/types/client/use-remote-chat-target.d.ts +2 -0
  23. package/lib/types/client/view-settings.d.ts +40 -0
  24. package/lib/types/client/vsc/breadcrumb.d.ts +30 -0
  25. package/lib/types/client/vsc/editor-caret.d.ts +32 -0
  26. package/lib/types/client/vsc/editor-langs.d.ts +9 -0
  27. package/lib/types/client/vsc/editor-settings.d.ts +55 -0
  28. package/lib/types/client/vsc/image-preview.d.ts +36 -0
  29. package/lib/types/client/vsc/kit.d.ts +2 -0
  30. package/lib/types/client/vsc/terminal-clipboard.d.ts +15 -0
  31. package/lib/types/client/vsc/terminal-line.d.ts +25 -0
  32. package/lib/types/client/vsc/terminal-links.d.ts +62 -0
  33. package/lib/types/client/vsc/terminal-theme.d.ts +22 -0
  34. package/lib/types/client/vsc/terminal-writer.d.ts +52 -0
  35. package/lib/types/paths.d.ts +9 -0
  36. package/lib/types/pool.d.ts +25 -0
  37. package/lib/types/protocol.d.ts +35 -0
  38. package/lib/types/routes.d.ts +7 -0
  39. package/lib/types/terminal.d.ts +25 -1
  40. package/lib/types/view-settings.d.ts +26 -0
  41. package/lib/{worlds-DXdP4SMn.js → worlds-B7gEDBzC.js} +13 -1
  42. package/package.json +36 -36
  43. package/src/client/CodeEditor.tsx +54 -2
  44. package/src/client/EditorPane.tsx +485 -107
  45. package/src/client/FloatingPlaceholder.tsx +34 -5
  46. package/src/client/RemoteEditorView.tsx +14 -11
  47. package/src/client/RemoteRoot.tsx +20 -125
  48. package/src/client/SettingsHosts.tsx +81 -3
  49. package/src/client/TerminalSnippets.tsx +357 -0
  50. package/src/client/TerminalView.tsx +50 -1
  51. package/src/client/XTerm.tsx +228 -58
  52. package/src/client/api.ts +7 -0
  53. package/src/client/auto-open-remote.ts +439 -0
  54. package/src/client/editor-capability.ts +42 -0
  55. package/src/client/i18n.ts +158 -6
  56. package/src/client/index.tsx +30 -6
  57. package/src/client/store.tsx +165 -13
  58. package/src/client/terminal-input.ts +44 -0
  59. package/src/client/terminal-snippets.ts +216 -0
  60. package/src/client/use-remote-chat-target.ts +1 -1
  61. package/src/client/view-settings.ts +99 -0
  62. package/src/client/vsc/breadcrumb.tsx +251 -0
  63. package/src/client/vsc/editor-caret.ts +30 -0
  64. package/src/client/vsc/editor-langs.ts +20 -0
  65. package/src/client/vsc/editor-settings.ts +146 -0
  66. package/src/client/vsc/editor-theme.ts +4 -5
  67. package/src/client/vsc/image-preview.tsx +110 -0
  68. package/src/client/vsc/kit.tsx +20 -1
  69. package/src/client/vsc/terminal-clipboard.ts +19 -0
  70. package/src/client/vsc/terminal-line.ts +101 -0
  71. package/src/client/vsc/terminal-links.ts +166 -0
  72. package/src/client/vsc/terminal-theme.ts +71 -0
  73. package/src/client/vsc/terminal-writer.ts +112 -0
  74. package/src/client/vsc/vsc.css +687 -48
  75. package/src/index.ts +6 -0
  76. package/src/paths.ts +13 -0
  77. package/src/pool.ts +99 -27
  78. package/src/protocol.ts +45 -0
  79. package/src/routes.ts +47 -0
  80. package/src/terminal.ts +160 -6
  81. package/src/view-settings.ts +133 -0
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Terminal OUTPUT writer: an ordered, coalescing buffer between the WebSocket
3
+ * frames and `term.write`.
4
+ *
5
+ * Why this is not just `term.write(frame.d)` per frame, and NOT a chain of
6
+ * `write(..., callback)`:
7
+ *
8
+ * - xterm parses writes in slices of a few milliseconds; handing it one string
9
+ * per frame costs per-call overhead on a busy stream (`cat`, `dmesg`).
10
+ * - chaining on the write CALLBACK couples our queue to xterm's parse/render
11
+ * completion. A callback is delivered after the data is parsed AND rendered,
12
+ * and rendering is driven by the browser's frames — a throttled window, an
13
+ * occluded tab or a very large previous chunk delays it, and while it is
14
+ * delayed this queue refuses to hand xterm anything new. That is exactly the
15
+ * "typing sometimes has no echo for a while, then it catches up" symptom:
16
+ * the echo was sitting in our queue behind a callback that had not fired yet.
17
+ *
18
+ * So: order is preserved by APPENDING to one buffer and flushing it on a timer
19
+ * (or immediately when the buffer is large). Nothing here waits for a write to
20
+ * finish — xterm's own queue already serialises the chunks we hand it.
21
+ *
22
+ * Pure for the gate (`scripts/check-terminal-writer.mjs`): the scheduler and the
23
+ * write sink are injected, no DOM, no timers at import time.
24
+ */
25
+
26
+ /** Dependencies of {@link createTerminalWriter}. */
27
+ export interface TerminalWriterDeps {
28
+ /** Hand one chunk to the terminal (xterm's `write`). Must not throw. */
29
+ write: (text: string) => void
30
+ /** Schedule one flush; the default is `setTimeout(run, 0)`. */
31
+ schedule?: (run: () => void) => unknown
32
+ /**
33
+ * Largest string handed to `write` in one call.
34
+ *
35
+ * Joining a multi-megabyte backlog into ONE string would itself block the main
36
+ * thread (and the join is O(total) on every flush), so a big queue is written
37
+ * in pieces and the rest is scheduled immediately.
38
+ */
39
+ maxChunkChars?: number
40
+ }
41
+
42
+ /** Handle returned by {@link createTerminalWriter}. */
43
+ export interface TerminalWriter {
44
+ /** Append output; the returned value is ignored (kept for symmetry/tests). */
45
+ push: (text: string) => void
46
+ /** Flush everything right now (tab closing, exit frame). */
47
+ flush: () => void
48
+ /** Characters still waiting (diagnostics/tests). */
49
+ pendingChars: () => number
50
+ }
51
+
52
+ /** Default cap for one `write` call (256 Ki UTF-16 units). */
53
+ export const WRITER_MAX_CHUNK_CHARS = 256 * 1024
54
+
55
+ /** Create one ordered, coalescing writer. */
56
+ export function createTerminalWriter(deps: TerminalWriterDeps): TerminalWriter {
57
+ const schedule = deps.schedule ?? ((run: () => void) => setTimeout(run, 0))
58
+ const maxChunk = deps.maxChunkChars ?? WRITER_MAX_CHUNK_CHARS
59
+ /** Queued chunks, in arrival order (joined only at flush time). */
60
+ let queue: string[] = []
61
+ let queuedChars = 0
62
+ let scheduled = false
63
+
64
+ const take = (limit: number): string => {
65
+ // Walk whole CHUNKS until the limit would be exceeded, so a normal burst
66
+ // (small frames) costs one join and a huge backlog is split without slicing
67
+ // a surrogate pair in half.
68
+ let taken = ''
69
+ while (queue.length > 0) {
70
+ const head = queue[0] as string
71
+ if (taken !== '' && taken.length + head.length > limit) break
72
+ queue.shift()
73
+ queuedChars -= head.length
74
+ taken += head
75
+ if (taken.length >= limit) break
76
+ }
77
+ return taken
78
+ }
79
+
80
+ const flush = (): void => {
81
+ scheduled = false
82
+ if (queue.length === 0) return
83
+ const chunk = take(maxChunk)
84
+ if (chunk === '') return
85
+ deps.write(chunk)
86
+ // More to send: keep the ORDER and get back to the event loop first, so a
87
+ // long backlog cannot starve input handling (keystrokes are separate tasks).
88
+ if (queue.length > 0) scheduleFlush()
89
+ }
90
+
91
+ const scheduleFlush = (): void => {
92
+ if (scheduled) return
93
+ scheduled = true
94
+ schedule(flush)
95
+ }
96
+
97
+ return {
98
+ push: (text: string): void => {
99
+ if (text === '') return
100
+ queue.push(text)
101
+ queuedChars += text.length
102
+ // A large buffer is flushed at once (the timer would only add latency);
103
+ // a small one waits one tick so a burst of frames becomes one write.
104
+ if (queuedChars >= maxChunk) flush()
105
+ else scheduleFlush()
106
+ },
107
+ flush: (): void => {
108
+ flush()
109
+ },
110
+ pendingChars: (): number => queuedChars,
111
+ }
112
+ }