dsh-remote-vs 0.25.0 → 0.27.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 (109) hide show
  1. package/README.en.md +12 -15
  2. package/README.md +11 -12
  3. package/THIRD-PARTY-NOTICES.md +193 -0
  4. package/lib/client.js +7313 -79961
  5. package/lib/index.js +1529 -964
  6. package/lib/p2-router-fs.js +1 -1
  7. package/lib/types/client/CodeEditor.d.ts +22 -0
  8. package/lib/types/client/OutlinePanel.d.ts +22 -0
  9. package/lib/types/client/ProcessesSection.d.ts +19 -0
  10. package/lib/types/client/RemoteExplorer.d.ts +53 -0
  11. package/lib/types/client/api.d.ts +42 -3
  12. package/lib/types/client/blame-model.d.ts +77 -0
  13. package/lib/types/client/changes/review-state.d.ts +19 -0
  14. package/lib/types/client/connection.d.ts +16 -0
  15. package/lib/types/client/i18n.d.ts +1 -1
  16. package/lib/types/client/outline-model.d.ts +59 -0
  17. package/lib/types/client/request-gate.d.ts +110 -0
  18. package/lib/types/client/scm/DiffView.d.ts +45 -7
  19. package/lib/types/client/scm/actions.d.ts +43 -4
  20. package/lib/types/client/store.d.ts +71 -0
  21. package/lib/types/client/vsc/FindWidget.d.ts +6 -0
  22. package/lib/types/client/vsc/blame.d.ts +19 -0
  23. package/lib/types/client/vsc/change-marks.d.ts +16 -6
  24. package/lib/types/client/vsc/editor-keymap.d.ts +35 -1
  25. package/lib/types/client/vsc/kit.d.ts +11 -2
  26. package/lib/types/client/vsc/preview-document.d.ts +46 -0
  27. package/lib/types/client/vsc/preview-model.d.ts +31 -0
  28. package/lib/types/client/vsc/preview-services.d.ts +24 -0
  29. package/lib/types/client/vsc/save-shortcut.d.ts +21 -0
  30. package/lib/types/client/vsc/terminal-theme.d.ts +28 -2
  31. package/lib/types/forward.d.ts +12 -0
  32. package/lib/types/fs-ops.d.ts +42 -0
  33. package/lib/types/git-ops.d.ts +18 -0
  34. package/lib/types/http.d.ts +2 -0
  35. package/lib/types/keygen.d.ts +9 -0
  36. package/lib/types/monitor.d.ts +8 -0
  37. package/lib/types/notices.d.ts +16 -1
  38. package/lib/types/p2/helper-rpc.d.ts +45 -0
  39. package/lib/types/processes.d.ts +43 -0
  40. package/lib/types/protocol.d.ts +34 -0
  41. package/lib/types/routes.d.ts +2 -0
  42. package/lib/types/store.d.ts +7 -0
  43. package/lib/types/terminal.d.ts +8 -0
  44. package/lib/types/view-settings.d.ts +5 -0
  45. package/lib/{worlds-B7gEDBzC.js → worlds-RG8K5eom.js} +113 -15
  46. package/package.json +3 -1
  47. package/src/client/CodeEditor.tsx +194 -9
  48. package/src/client/DirectoryFlow.tsx +16 -0
  49. package/src/client/DoctorPanel.tsx +70 -7
  50. package/src/client/EditorPane.tsx +574 -42
  51. package/src/client/HostsView.tsx +12 -3
  52. package/src/client/MonitorView.tsx +16 -5
  53. package/src/client/OutlinePanel.tsx +287 -0
  54. package/src/client/ProcessesSection.tsx +292 -0
  55. package/src/client/RemoteDirectoryPicker.tsx +12 -0
  56. package/src/client/RemoteExplorer.tsx +929 -40
  57. package/src/client/RemoteRoot.tsx +147 -22
  58. package/src/client/SearchView.tsx +8 -0
  59. package/src/client/TerminalSnippets.tsx +83 -8
  60. package/src/client/api.ts +114 -13
  61. package/src/client/blame-model.ts +242 -0
  62. package/src/client/changes/ChangesDock.tsx +188 -6
  63. package/src/client/changes/changes.css +10 -3
  64. package/src/client/changes/review-state.ts +34 -0
  65. package/src/client/connection.ts +29 -0
  66. package/src/client/downloads.ts +49 -4
  67. package/src/client/i18n.ts +276 -8
  68. package/src/client/index.tsx +4 -0
  69. package/src/client/outline-model.ts +775 -0
  70. package/src/client/request-gate.ts +221 -0
  71. package/src/client/scm/CommitPane.tsx +20 -2
  72. package/src/client/scm/DiffView.tsx +343 -117
  73. package/src/client/scm/HistoryPanel.tsx +61 -3
  74. package/src/client/scm/RepoPicker.tsx +1 -1
  75. package/src/client/scm/ScmPanel.tsx +391 -87
  76. package/src/client/scm/actions.ts +150 -14
  77. package/src/client/store.tsx +426 -14
  78. package/src/client/ui.tsx +4 -0
  79. package/src/client/vsc/FindWidget.tsx +24 -9
  80. package/src/client/vsc/blame.ts +147 -0
  81. package/src/client/vsc/breadcrumb.tsx +91 -3
  82. package/src/client/vsc/change-marks.ts +93 -44
  83. package/src/client/vsc/editor-keymap.ts +59 -1
  84. package/src/client/vsc/file-icons.tsx +17 -3
  85. package/src/client/vsc/kit.tsx +29 -20
  86. package/src/client/vsc/preview-document.tsx +323 -0
  87. package/src/client/vsc/preview-model.ts +216 -0
  88. package/src/client/vsc/preview-services.ts +118 -0
  89. package/src/client/vsc/save-shortcut.ts +47 -1
  90. package/src/client/vsc/terminal-theme.ts +44 -18
  91. package/src/client/vsc/vsc.css +6509 -5458
  92. package/src/forward.ts +47 -9
  93. package/src/fs-ops.ts +124 -4
  94. package/src/git-ops.ts +54 -3
  95. package/src/http.ts +35 -4
  96. package/src/keygen.ts +55 -4
  97. package/src/monitor.ts +13 -0
  98. package/src/notices.ts +23 -1
  99. package/src/p2/helper-rpc.ts +113 -7
  100. package/src/p2/worlds.ts +14 -1
  101. package/src/processes.ts +177 -0
  102. package/src/protocol.ts +37 -0
  103. package/src/routes.ts +330 -43
  104. package/src/sftp.ts +51 -14
  105. package/src/store.ts +10 -0
  106. package/src/terminal.ts +73 -26
  107. package/src/view-settings.ts +50 -10
  108. package/lib/types/client/Dialog.d.ts +0 -14
  109. package/src/client/Dialog.tsx +0 -76
@@ -0,0 +1,221 @@
1
+ /**
2
+ * Request priority gate: a foreground request never waits, background ones yield.
3
+ *
4
+ * The symptom this exists for: switching the remote workspace made the tree
5
+ * crawl. The switch starts a full `git status` walk of the new repository
6
+ * (minutes on an AOSP monorepo) while the tree itself needs a handful of small
7
+ * foreground reads. A browser gives ONE origin six connections, so the walk —
8
+ * probe + status + branch header, three at once — filled the pool and the
9
+ * directory listing queued behind it. Measured on the reported trees: the git
10
+ * walk took 8–9 s (1.6–1.9 s with `-uno`), and during that window a purely
11
+ * in-memory Host route (`/status`, normally < 1 ms) answered in 2.7–4.6 s. The
12
+ * directory list itself was 175–180 ms; the rest was queueing.
13
+ *
14
+ * The contract is one sentence per direction:
15
+ *
16
+ * - FOREGROUND — every request somebody is waiting on (directory list, file
17
+ * read/write, session cwd, connection status, terminal exec): it never waits
18
+ * for a background slot. It only bumps a counter, so a background request that
19
+ * is already running cannot hold it up (that one still owns a TCP connection,
20
+ * which is what `maxBackground` and the abort in `store.readGit` are for).
21
+ * - BACKGROUND — repository-wide git walks: started only while NO foreground
22
+ * request is in flight and fewer than `maxBackground` background requests run.
23
+ * Otherwise queued (FIFO). `maxBackground: 1` is deliberate: the walk's own
24
+ * steps (probe, status, branch header) are work on ONE repository, and letting
25
+ * three of them hold three connections is exactly the pool exhaustion this
26
+ * gate exists to prevent.
27
+ *
28
+ * Aborting: a queued entry leaves the queue and rejects with `AbortError`. A
29
+ * request that already STARTED cannot be un-sent — its slot is released the
30
+ * moment its signal aborts (a cancelled fetch frees its connection right away,
31
+ * and the channel must not depend on the transport noticing), while the outcome
32
+ * of the underlying promise stays the transport's business: a real `fetch`
33
+ * rejects with `AbortError`, which is what the store sees. A signal that is
34
+ * ALREADY aborted when the request is handed over is passed to the transport
35
+ * unchanged — `fetch` refuses it at once, and deciding that here would swallow
36
+ * a step of a read that chose to keep going.
37
+ *
38
+ * Kept dependency-free (no store, no React, no fetch) on purpose: a node gate
39
+ * imports this class and proves the ordering with its own deferreds, and the
40
+ * store/api wiring is a one-liner at each call site.
41
+ */
42
+
43
+ /** What `pending()` reports: counts only, never the queued closures. */
44
+ export interface RequestGatePending {
45
+ /** Foreground requests in flight. */
46
+ foreground: number
47
+ /** Background requests in flight. */
48
+ background: number
49
+ /** Background requests waiting for a slot. */
50
+ queued: number
51
+ }
52
+
53
+ /** One background request, either queued or running. */
54
+ interface BackgroundEntry {
55
+ /** The request itself (a `fetch` wrapped in a closure by `api.call`). */
56
+ readonly run: () => Promise<unknown>
57
+ /** Hand the transport's answer to the caller (no-op once settled/aborted). */
58
+ readonly resolve: (value: unknown) => void
59
+ /** Hand the transport's failure to the caller (queued-abort uses it too). */
60
+ readonly reject: (error: unknown) => void
61
+ /** Removes this entry's abort listener (set by `runBackground`). */
62
+ readonly detach: () => void
63
+ /**
64
+ * Gives the background slot back. A no-op while the entry is still queued;
65
+ * `pump` replaces it with the real release when the request starts.
66
+ */
67
+ release: () => void
68
+ }
69
+
70
+ /**
71
+ * The cancellation error a queued background request rejects with when its
72
+ * signal aborts (`AbortError`, the same name `fetch` uses for its own aborts).
73
+ */
74
+ export function requestAbortError(): Error {
75
+ if (typeof DOMException === 'function') return new DOMException('Aborted', 'AbortError')
76
+ const error = new Error('Aborted')
77
+ error.name = 'AbortError'
78
+ return error
79
+ }
80
+
81
+ /**
82
+ * True when `error` is an abort, not a failure.
83
+ *
84
+ * Callers that cancelled a request on purpose (a workspace switch) must not
85
+ * report it: "the read you superseded was cancelled" is not an error the user
86
+ * can act on.
87
+ */
88
+ export function isRequestAbort(error: unknown): boolean {
89
+ return typeof error === 'object' && error !== null
90
+ && (error as { name?: unknown }).name === 'AbortError'
91
+ }
92
+
93
+ /**
94
+ * The gate itself.
95
+ *
96
+ * One instance per page is enough and is what `api.ts` uses; the class is
97
+ * exported so a gate can drive several independent instances with its own
98
+ * timings instead of sharing module state.
99
+ */
100
+ export class RequestGate {
101
+ /** Foreground requests in flight. */
102
+ private foregroundCount = 0
103
+ /** Background requests in flight (a slot is held until it settles or aborts). */
104
+ private backgroundCount = 0
105
+ /** Background requests waiting for a slot, in arrival order (FIFO). */
106
+ private readonly queued: BackgroundEntry[] = []
107
+
108
+ /**
109
+ * @param maxBackground - how many background requests may run at once.
110
+ * `1` is the client's choice; see the module comment.
111
+ */
112
+ constructor(private readonly maxBackground = 1) {}
113
+
114
+ /** Run one foreground request. It never waits for a background slot. */
115
+ async runForeground<T>(fn: () => Promise<T>): Promise<T> {
116
+ this.foregroundCount += 1
117
+ try {
118
+ return await fn()
119
+ } finally {
120
+ this.foregroundCount -= 1
121
+ // The last foreground request is gone: the background channel may start.
122
+ if (this.foregroundCount === 0) this.pump()
123
+ }
124
+ }
125
+
126
+ /**
127
+ * Run one background request, waiting for a slot.
128
+ *
129
+ * @param signal - a QUEUED request leaves the queue and rejects with
130
+ * `AbortError`; a request that already started releases its slot at once
131
+ * (its own `fetch` gets the same signal, so the transport is cancelled too).
132
+ * An already-aborted signal is handed to the transport, which refuses it.
133
+ */
134
+ runBackground<T>(fn: () => Promise<T>, signal?: AbortSignal): Promise<T> {
135
+ return new Promise<T>((resolve, reject) => {
136
+ let settled = false
137
+ let detach = (): void => {}
138
+ const entry: BackgroundEntry = {
139
+ run: () => fn() as Promise<unknown>,
140
+ resolve: (value) => {
141
+ if (settled) return
142
+ settled = true
143
+ detach()
144
+ entry.release()
145
+ resolve(value as T)
146
+ },
147
+ reject: (error) => {
148
+ if (settled) return
149
+ settled = true
150
+ detach()
151
+ entry.release()
152
+ reject(error)
153
+ },
154
+ detach: () => detach(),
155
+ release: () => {},
156
+ }
157
+ if (signal !== undefined) {
158
+ const onAbort = (): void => {
159
+ const at = this.queued.indexOf(entry)
160
+ if (at >= 0) {
161
+ // Never started: the cancellation is the caller's answer.
162
+ this.queued.splice(at, 1)
163
+ entry.reject(requestAbortError())
164
+ return
165
+ }
166
+ // Already running: give the slot back NOW. The transport is cancelled
167
+ // through the same signal (a real fetch rejects and the caller sees
168
+ // the AbortError); a transport that ignores it keeps the promise, but
169
+ // must not wedge every later background read behind a dead walk.
170
+ entry.release()
171
+ }
172
+ signal.addEventListener('abort', onAbort, { once: true })
173
+ detach = () => signal.removeEventListener('abort', onAbort)
174
+ }
175
+ this.queued.push(entry)
176
+ this.pump()
177
+ })
178
+ }
179
+
180
+ /** Snapshot of the counts (gates assert ordering with this). */
181
+ pending(): RequestGatePending {
182
+ return { foreground: this.foregroundCount, background: this.backgroundCount, queued: this.queued.length }
183
+ }
184
+
185
+ /**
186
+ * Start as many queued background requests as the rule allows.
187
+ *
188
+ * Called when a foreground request finishes, when a background one settles and
189
+ * when a running one's signal aborts. A background request that is RUNNING is
190
+ * never recalled (a fetch cannot be un-sent), so a foreground request arriving
191
+ * mid-walk simply runs alongside it until it settles.
192
+ */
193
+ private pump(): void {
194
+ while (this.foregroundCount === 0 && this.backgroundCount < this.maxBackground && this.queued.length > 0) {
195
+ const entry = this.queued.shift() as BackgroundEntry
196
+ this.backgroundCount += 1
197
+ let released = false
198
+ // The real release: give the slot back once, then let the next entry in.
199
+ entry.release = () => {
200
+ if (released) return
201
+ released = true
202
+ this.backgroundCount -= 1
203
+ this.pump()
204
+ }
205
+ // A deferred call turns a synchronous throw into a rejection, and the slot
206
+ // is given back before the next entry is considered.
207
+ void Promise.resolve()
208
+ .then(entry.run)
209
+ .then(entry.resolve, entry.reject)
210
+ .finally(entry.release)
211
+ }
212
+ }
213
+ }
214
+
215
+ /** The one gate the client uses (see `api.call`). */
216
+ export const requestGate = new RequestGate(1)
217
+
218
+ /** Snapshot of {@link requestGate} — for gates that assert the wiring. */
219
+ export function pending(): RequestGatePending {
220
+ return requestGate.pending()
221
+ }
@@ -33,7 +33,7 @@ import type { Lang } from '../i18n.ts'
33
33
  import { buildCommitReviewPrompt, diffByteLength, pickReviewMode } from '../ai-review.ts'
34
34
  import { appendToDraft, canInsertDraft, sameLocalDir } from '../composer.ts'
35
35
  import { GIT_CAP } from '../../git-ops.ts'
36
- import { useExplorer } from '../store.tsx'
36
+ import { shallowEqual, useExplorerSelector, type ExplorerValue } from '../store.tsx'
37
37
  import { useRemoteChatTarget } from '../use-remote-chat-target.ts'
38
38
  import {
39
39
  ContextMenu,
@@ -456,6 +456,24 @@ function contentBody(
456
456
  )
457
457
  }
458
458
 
459
+ /**
460
+ * The store fields the 差异 tab reads — and only those.
461
+ *
462
+ * Only the AI-review wiring needs the store here (the commit/body/files/patch
463
+ * arrive as props), so subscribing to the whole snapshot meant the patch view —
464
+ * up to a capped commit patch, thousands of rows — repainted on every save, git
465
+ * refresh and rail switch. The slice is the workspace identity a review prompt
466
+ * names plus the draft channel (`ctx`).
467
+ */
468
+ const selectCommitStore = (snapshot: ExplorerValue) => ({
469
+ ctx: snapshot.ctx,
470
+ workspace: snapshot.workspace,
471
+ aliasPaths: snapshot.aliasPaths,
472
+ alias: snapshot.alias,
473
+ repoRoot: snapshot.repoRoot,
474
+ root: snapshot.root,
475
+ })
476
+
459
477
  function DiffTab(props: CommitPaneProps & { hidden: boolean; wrap: boolean; onToggleWrap: () => void }): ReactNode {
460
478
  const { t } = props
461
479
  const model = useMemo(() => buildCommitPatch(props.patch ?? ''), [props.patch])
@@ -490,7 +508,7 @@ function DiffTab(props: CommitPaneProps & { hidden: boolean; wrap: boolean; onTo
490
508
  * extra remote round trip; `patchTruncated` comes from the loader that
491
509
  * computed the byte cap — the one place that knows the read was cut.
492
510
  */
493
- const store = useExplorer()
511
+ const store = useExplorerSelector(selectCommitStore, shallowEqual)
494
512
  const chat = useRemoteChatTarget(store.ctx)
495
513
  const viewedAliasPath = store.workspace === undefined ? undefined : store.aliasPaths[store.workspace.id]
496
514
  const chatEnabled = chat.sessionId !== undefined