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,439 @@
1
+ /**
2
+ * Frame-wide behaviour behind the two view preferences from Settings → 远程主机
3
+ * (`REMOTE_API.viewSettings`):
4
+ *
5
+ * - `autoOpenRemoteWorkspace` — the first time a session THIS PLUGIN considers
6
+ * remote appears on screen in this page lifetime, open the plugin's own
7
+ * right-panel page. Once per session, never for a local session, and never
8
+ * revisited after a manual close (the "already handled" bookkeeping lives in
9
+ * this closure and dies with the page);
10
+ * - `remoteWorkspaceWidthRatio` — when that page is opened, the right column
11
+ * ends up at that share of the window width (and a save while the panel is
12
+ * open applies immediately).
13
+ *
14
+ * It lives OUTSIDE every component on purpose: the page it opens is usually
15
+ * CLOSED, so no seat of ours is mounted when the trigger happens — the settings
16
+ * dialog, the conversation view and the explorer tab can all be unmounted while
17
+ * a new remote session appears.
18
+ *
19
+ * "Remote" is decided from this plugin's own knowledge only:
20
+ * - the on-screen session comes from `ctx.sidebarRight.mounted`, the same
21
+ * sanctioned source the `@file` buttons use;
22
+ * - a session is remote when its host-confirmed workspace path — or, failing
23
+ * that, its live working directory — is one of the alias directories this
24
+ * plugin materialized for a binding. That is exactly the resolution the click
25
+ * router already performs (`bindingForSessionCwd`), fed by this plugin's own
26
+ * `/workspaces` route. No other plugin's API is involved.
27
+ *
28
+ * The width has NO public API in DSH: the supported user path is the column's
29
+ * drag handle, so it is driven there — a synthetic pointer sequence on
30
+ * `[data-side="rightbar"]` (see `resizeRightbar`), with the pointer-capture
31
+ * methods neutralised for exactly one dispatch and restored immediately after
32
+ * (leaving them overridden would break the user's own drag for the rest of the
33
+ * page's life).
34
+ */
35
+ import type { Context } from '@deepseek-ai/cordis'
36
+ import { clampViewWidthRatio } from '../protocol.ts'
37
+ import { api } from './api.ts'
38
+ import { NATIVE_TAB_KIND } from './NativeExplorer.tsx'
39
+ import { bindingForSessionCwd, type RemoteOpenBindings } from './remote-file-open-target.ts'
40
+ import { mountedSessionId, workspacePathOf } from './use-remote-chat-target.ts'
41
+ import { currentViewSettings, loadViewSettings, subscribeViewSettings } from './view-settings.ts'
42
+
43
+ /** The column's drag handle: the only supported way to set its width. */
44
+ const RIGHTBAR_HANDLE = '[data-side="rightbar"]'
45
+ /** The column element, on DSH releases that tag it (else the frame's grid is read). */
46
+ const RIGHTBAR_COLUMN = '[data-rightbar-col]'
47
+ /** DSH's own bounds for the column; mirrored so the target is where a drag would land. */
48
+ const RIGHTBAR_MIN_WIDTH = 300
49
+ const RIGHTBAR_MAX_RATIO = 0.7
50
+ /** On-screen session poll (the `mounted` feed is read per tick, not subscribed). */
51
+ const POLL_MS = 1_500
52
+ /** Retry period while the host cannot answer the preferences at all. */
53
+ const SETTINGS_RETRY_MS = 10_000
54
+ /** Frames the newly opened panel may take to render its handle (~10 s at 60 fps). */
55
+ const HANDLE_FRAME_BUDGET = 600
56
+ /** Attempts at proving one session remote before the answer is "not proven". */
57
+ const CLASSIFY_ATTEMPTS = 10
58
+ /** How long one `/workspaces` answer is reused while it lists bindings. */
59
+ const BINDINGS_TTL_MS = 30_000
60
+
61
+ /** The narrow slice of `ctx.sidebarRight` this module touches (soft read). */
62
+ interface SidebarRightLike {
63
+ openTab?: (kind: string) => void
64
+ isExpanded?: () => boolean
65
+ /** Active tab of the active pane (record shape: `{ id, kind, … }`). */
66
+ active?: () => { kind?: string } | undefined
67
+ }
68
+
69
+ /** This plugin's right-panel face, or `undefined` on a host without the seat. */
70
+ function softSidebarRight(ctx: Context): SidebarRightLike | undefined {
71
+ try {
72
+ const raw = (ctx as unknown as { get(name: string): unknown }).get('sidebarRight')
73
+ return typeof raw === 'object' && raw !== null ? (raw as SidebarRightLike) : undefined
74
+ } catch {
75
+ return undefined
76
+ }
77
+ }
78
+
79
+ /**
80
+ * Whether this plugin's own page is the tab the right column is showing.
81
+ *
82
+ * The column is ONE panel shared by every sidebar page, so a width that belongs
83
+ * to the remote workspace may only be committed while the remote workspace is
84
+ * the page on screen; any other answer leaves the panel alone.
85
+ */
86
+ function ownTabActive(ctx: Context): boolean {
87
+ try {
88
+ return softSidebarRight(ctx)?.active?.()?.kind === NATIVE_TAB_KIND
89
+ } catch {
90
+ return false
91
+ }
92
+ }
93
+
94
+ /**
95
+ * Install the behaviour; returns the teardown for the client entry's effect.
96
+ *
97
+ * @param ctx - client plugin context (only soft service reads).
98
+ */
99
+ export function installAutoOpenRemote(ctx: Context): () => void {
100
+ /** Sessions this page lifetime already decided about — never revisited. */
101
+ const decided = new Set<string>()
102
+ /** Sessions being classified right now (one probe per session at a time). */
103
+ const deciding = new Set<string>()
104
+ /** Spend so far on sessions that could not be classified yet. */
105
+ const attempts = new Map<string, number>()
106
+ /** Binding table from the plugin's own `/workspaces` route (bounded reuse). */
107
+ let bindings: RemoteOpenBindings | undefined
108
+ let bindingsAt = 0
109
+ /** Next time a failed preferences load may be retried. */
110
+ let settingsRetryAt = 0
111
+ /** Cancels the handle poll of a superseded width change. */
112
+ let pollToken = 0
113
+ let disposed = false
114
+ let lastRatio = currentViewSettings()?.remoteWorkspaceWidthRatio
115
+ let timer: ReturnType<typeof setInterval> | undefined
116
+
117
+ /** Binding table, refetched when stale or when it lists nothing (a new workspace). */
118
+ const openBindings = async (): Promise<RemoteOpenBindings | undefined> => {
119
+ if (bindings !== undefined && bindings.bindings.length > 0 && Date.now() - bindingsAt < BINDINGS_TTL_MS) {
120
+ return bindings
121
+ }
122
+ try {
123
+ const answer = await api.getWorkspaces()
124
+ bindings = { bindings: answer.workspaces, aliasPaths: answer.aliasPaths }
125
+ bindingsAt = Date.now()
126
+ return bindings
127
+ } catch {
128
+ // An older host answers 404 for the route, a broken host nothing: either
129
+ // way the answer is "cannot prove", never "not remote".
130
+ bindings = undefined
131
+ return undefined
132
+ }
133
+ }
134
+
135
+ /**
136
+ * Prove whether one session works in a remote workspace.
137
+ *
138
+ * `remote`/`local` are proofs; `unknown` means it cannot be decided YET (host
139
+ * down, the workspaces service still settling) and the caller may retry.
140
+ */
141
+ const classify = async (sessionId: string): Promise<'remote' | 'local' | 'unknown'> => {
142
+ const table = await openBindings()
143
+ if (table === undefined) return 'unknown'
144
+ // No binding at all: nothing on this profile can be remote.
145
+ if (table.bindings.length === 0) return 'local'
146
+ const workspace = workspacePathOf(ctx, sessionId)
147
+ if (workspace !== undefined) {
148
+ // The host's own workspace membership is the strongest evidence: a remote
149
+ // session's workspace IS the alias directory of exactly one binding.
150
+ return bindingForSessionCwd(table, workspace) !== undefined ? 'remote' : 'local'
151
+ }
152
+ // No membership (or the workspaces service is not ready yet): the session's
153
+ // own cwd is the last resort, the same order `followSessionWorkspace` uses.
154
+ let cwd: string | undefined
155
+ try {
156
+ cwd = (await api.sessionCwd(sessionId)).cwd
157
+ } catch {
158
+ return 'unknown'
159
+ }
160
+ if (cwd === undefined || cwd === '') return 'unknown'
161
+ return bindingForSessionCwd(table, cwd) !== undefined ? 'remote' : 'local'
162
+ }
163
+
164
+ /** Poll for the drag handle, then move the column to `ratio` of the frame. */
165
+ const applyWidth = (ratio: number): void => {
166
+ const token = (pollToken += 1)
167
+ let frames = HANDLE_FRAME_BUDGET
168
+ const step = (): void => {
169
+ if (disposed || token !== pollToken) return
170
+ const handle = document.querySelector<HTMLElement>(RIGHTBAR_HANDLE)
171
+ // Only ever resize the column while THIS plugin's page is the one on
172
+ // screen: the right column is shared with every other sidebar page (the
173
+ // local workbench among them), and a width meant for the remote workspace
174
+ // must not restyle a panel showing something else.
175
+ if (handle !== null && ownTabActive(ctx) && resizeRightbar(handle, ratio)) return
176
+ frames -= 1
177
+ // The panel renders its handle in the frame it becomes visible, so a poll
178
+ // corrects a restored panel immediately instead of on a timer.
179
+ if (frames > 0) requestAnimationFrame(step)
180
+ }
181
+ requestAnimationFrame(step)
182
+ }
183
+
184
+ /**
185
+ * Open this plugin's own right-panel page, then size it.
186
+ *
187
+ * @returns false when there was nothing to open — the seat has not mounted
188
+ * this session's surface yet, the better-sidebar surface owns the tab, or an
189
+ * older host never registered our page. The caller retries within its budget
190
+ * and then gives up (a permanent "no page of ours" must not be fought).
191
+ */
192
+ const openPage = (ratio: number): boolean => {
193
+ const sidebar = softSidebarRight(ctx)
194
+ if (typeof sidebar?.openTab !== 'function') return false
195
+ try {
196
+ sidebar.openTab(NATIVE_TAB_KIND)
197
+ } catch {
198
+ return false
199
+ }
200
+ applyWidth(ratio)
201
+ return true
202
+ }
203
+
204
+ /**
205
+ * Record one pass that could not decide; after {@link CLASSIFY_ATTEMPTS} the
206
+ * session is treated as "not ours" so it is never probed for the whole page's
207
+ * lifetime. The safe answer is always the one that does not open a panel.
208
+ */
209
+ const noteAttempt = (sessionId: string): void => {
210
+ const spent = (attempts.get(sessionId) ?? 0) + 1
211
+ if (spent < CLASSIFY_ATTEMPTS) {
212
+ attempts.set(sessionId, spent)
213
+ return
214
+ }
215
+ attempts.delete(sessionId)
216
+ decided.add(sessionId)
217
+ }
218
+
219
+ /** Decide one session, once. */
220
+ const decide = async (sessionId: string): Promise<void> => {
221
+ deciding.add(sessionId)
222
+ try {
223
+ const kind = await classify(sessionId)
224
+ if (disposed) return
225
+ if (kind === 'unknown') {
226
+ noteAttempt(sessionId)
227
+ return
228
+ }
229
+ attempts.delete(sessionId)
230
+ decided.add(sessionId)
231
+ if (kind !== 'remote') return
232
+ // The setting is read again here: it may have been saved while the
233
+ // session was being classified.
234
+ const settings = currentViewSettings()
235
+ if (settings?.autoOpenRemoteWorkspace !== true) return
236
+ if (openPage(settings.remoteWorkspaceWidthRatio)) return
237
+ // The page could not be opened yet (the session's surface may still be
238
+ // minting): undo the decision and retry on a later pulse.
239
+ decided.delete(sessionId)
240
+ noteAttempt(sessionId)
241
+ } finally {
242
+ deciding.delete(sessionId)
243
+ }
244
+ }
245
+
246
+ /** One on-screen-session pulse. */
247
+ const tick = (): void => {
248
+ if (disposed) return
249
+ const sessionId = mountedSessionId(ctx)
250
+ if (sessionId === undefined || decided.has(sessionId) || deciding.has(sessionId)) return
251
+ if (currentViewSettings() === undefined) {
252
+ // The host may not be up yet (or is an older build without the route):
253
+ // retry at a human pace instead of every tick, and never guess the answer.
254
+ const now = Date.now()
255
+ if (now >= settingsRetryAt) {
256
+ settingsRetryAt = now + SETTINGS_RETRY_MS
257
+ void loadViewSettings(true)
258
+ }
259
+ return
260
+ }
261
+ void decide(sessionId)
262
+ }
263
+
264
+ // A SAVE is an explicit user request: when the panel is already open, the new
265
+ // share applies in place. A load (page start, or the retry after a failed one)
266
+ // must not resize a panel the user opened by hand, and a save that leaves the
267
+ // share alone (the auto-open toggle) must not touch the panel either.
268
+ const unsubscribe = subscribeViewSettings((next, source) => {
269
+ const previous = lastRatio
270
+ lastRatio = next.remoteWorkspaceWidthRatio
271
+ if (source !== 'save' || previous === next.remoteWorkspaceWidthRatio) return
272
+ const sidebar = softSidebarRight(ctx)
273
+ // Expanded is not enough: the column may be showing another plugin's page
274
+ // (the local workbench among them), and its width is not ours to change.
275
+ if (typeof sidebar?.isExpanded === 'function' && sidebar.isExpanded() && ownTabActive(ctx)) {
276
+ applyWidth(next.remoteWorkspaceWidthRatio)
277
+ }
278
+ })
279
+
280
+ void loadViewSettings()
281
+ timer = setInterval(tick, POLL_MS)
282
+ timer.unref?.()
283
+
284
+ return () => {
285
+ disposed = true
286
+ pollToken += 1
287
+ unsubscribe()
288
+ if (timer !== undefined) {
289
+ clearInterval(timer)
290
+ timer = undefined
291
+ }
292
+ }
293
+ }
294
+
295
+ /**
296
+ * Move the right column to `ratio` of the frame width through the drag handle.
297
+ *
298
+ * A drag commits `setRightbar(base - dx)` with `base` measured at pointer-down,
299
+ * so one synthetic down/up pair whose clientX delta is `current - target` lands
300
+ * exactly on `target` (DSH clamps the column itself, but the target is clamped
301
+ * here too so a narrow window cannot ask for the impossible).
302
+ */
303
+ function resizeRightbar(handle: HTMLElement, ratio: number): boolean {
304
+ const viewport = document.documentElement.clientWidth
305
+ if (viewport <= 0) return false
306
+ const target = Math.min(
307
+ Math.max(Math.round(viewport * clampViewWidthRatio(ratio)), RIGHTBAR_MIN_WIDTH),
308
+ Math.max(RIGHTBAR_MIN_WIDTH, Math.round(viewport * RIGHTBAR_MAX_RATIO)),
309
+ )
310
+ const current = currentRightbarWidth(handle, viewport)
311
+ if (current === undefined) return false
312
+ const dx = Math.round(current) - target
313
+ if (Math.abs(dx) < 1) return true
314
+ const origin = Math.round(handle.getBoundingClientRect().left)
315
+ withNeutralPointerCapture(handle, () => {
316
+ withoutTrackTransition(handle, () => {
317
+ dispatchPointer(handle, 'pointerdown', origin)
318
+ dispatchPointer(handle, 'pointerup', origin + dx)
319
+ })
320
+ })
321
+ return true
322
+ }
323
+
324
+ /**
325
+ * The width the drag will commit AGAINST (`base` in `setRightbar(base - dx)`).
326
+ *
327
+ * First choice is the handle's own `left`: DSH positions it at
328
+ * `viewport - normal.rightbar`, which IS the base a pointer-down measures, so it
329
+ * stays exact even while the column animates or is clamped narrower than the
330
+ * committed value. Then the rendered width, from the tagged column (releases
331
+ * that mark it), the frame's resolved third grid track (the column IS that
332
+ * track, and computed values are resolved pixels), and finally the handle's
333
+ * geometry — the 8 px handle is centred on the column's inner edge, so its left
334
+ * edge sits at `viewport - width - 4`.
335
+ */
336
+ function currentRightbarWidth(handle: HTMLElement, viewport: number): number | undefined {
337
+ const positioned = Number.parseFloat(handle.style.left)
338
+ if (Number.isFinite(positioned) && positioned >= 0 && positioned <= viewport) {
339
+ const width = viewport - positioned
340
+ // A reading below the plausible minimum means the column has not settled
341
+ // yet (a restored panel animating in). Treating it as the base turns the
342
+ // delta into a huge overshoot that lands on DSH's 70 % clamp — the panel
343
+ // then opens far wider than the configured share (2026-11-23 report).
344
+ if (width >= RIGHTBAR_MIN_WIDTH / 2) return width
345
+ }
346
+ const column = document.querySelector<HTMLElement>(RIGHTBAR_COLUMN)
347
+ if (column !== null) {
348
+ const width = column.getBoundingClientRect().width
349
+ if (width > 0) return width
350
+ }
351
+ const frame = handle.parentElement
352
+ if (frame !== null) {
353
+ const tracks = getComputedStyle(frame).gridTemplateColumns.trim().split(/\s+/)
354
+ const track = tracks[tracks.length - 1]
355
+ const width = track === undefined ? Number.NaN : Number.parseFloat(track)
356
+ if (Number.isFinite(width) && width > 0) return width
357
+ }
358
+ const fallback = viewport - handle.getBoundingClientRect().left - 4
359
+ return fallback > 0 ? fallback : undefined
360
+ }
361
+
362
+ /** Dispatch one pointer event the drag handle's own handlers accept. */
363
+ function dispatchPointer(handle: HTMLElement, type: 'pointerdown' | 'pointerup', clientX: number): void {
364
+ const rect = handle.getBoundingClientRect()
365
+ handle.dispatchEvent(new PointerEvent(type, {
366
+ bubbles: true,
367
+ cancelable: true,
368
+ composed: true,
369
+ pointerId: 1,
370
+ pointerType: 'mouse',
371
+ isPrimary: true,
372
+ button: 0,
373
+ buttons: type === 'pointerdown' ? 1 : 0,
374
+ clientX,
375
+ clientY: Math.round(rect.top + rect.height / 2),
376
+ }))
377
+ }
378
+
379
+ /** Pointer-capture methods replaced for one dispatch and then removed again. */
380
+ const CAPTURE_METHODS = ['setPointerCapture', 'hasPointerCapture', 'releasePointerCapture'] as const
381
+
382
+ /**
383
+ * Run one synthetic drag with the pointer-capture API neutralised.
384
+ *
385
+ * The handle captures the pointer on `pointerdown` (`setPointerCapture`), which
386
+ * throws for an id no real pointer owns — a synthetic pointer can never become
387
+ * the capture target. The three methods are therefore replaced for the duration
388
+ * of ONE dispatch and removed immediately afterwards: leaving them overridden on
389
+ * the handle would break the user's own drag for the rest of the page's life.
390
+ */
391
+ function withNeutralPointerCapture(handle: HTMLElement, run: () => void): void {
392
+ const saved = CAPTURE_METHODS.map(name => Object.getOwnPropertyDescriptor(handle, name))
393
+ for (const name of CAPTURE_METHODS) {
394
+ Object.defineProperty(handle, name, {
395
+ configurable: true,
396
+ writable: true,
397
+ // A capture that is not held answers false; the setters are no-ops.
398
+ value: name === 'hasPointerCapture' ? () => false : () => undefined,
399
+ })
400
+ }
401
+ try {
402
+ run()
403
+ } finally {
404
+ CAPTURE_METHODS.forEach((name, index) => {
405
+ const previous = saved[index]
406
+ if (previous === undefined) Reflect.deleteProperty(handle, name)
407
+ else Object.defineProperty(handle, name, previous)
408
+ })
409
+ }
410
+ }
411
+
412
+ /**
413
+ * Commit the width without DSH's track animation sweeping the column.
414
+ *
415
+ * The frame animates `grid-template-columns` while it switches tracks, so a
416
+ * programmatic width landing mid-animation would animate too. The frame (and the
417
+ * tagged column, when the release has one) is pinned to `transition: none` for
418
+ * the dispatch and restored on the next frame.
419
+ */
420
+ function withoutTrackTransition(handle: HTMLElement, run: () => void): void {
421
+ const frame = handle.parentElement
422
+ const column = document.querySelector<HTMLElement>(RIGHTBAR_COLUMN)
423
+ const targets: HTMLElement[] = []
424
+ for (const candidate of [frame, column]) {
425
+ if (candidate instanceof HTMLElement) targets.push(candidate)
426
+ }
427
+ if (targets.length === 0) {
428
+ run()
429
+ return
430
+ }
431
+ const previous = targets.map(target => target.style.transition)
432
+ for (const target of targets) target.style.transition = 'none'
433
+ run()
434
+ requestAnimationFrame(() => {
435
+ targets.forEach((target, index) => {
436
+ target.style.transition = previous[index] ?? ''
437
+ })
438
+ })
439
+ }
@@ -0,0 +1,42 @@
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
+
21
+ /** Live seats on this page (0 = nothing of ours can render an editor). */
22
+ let seats = 0
23
+
24
+ /** One seat became available (a tab/view registration succeeded). */
25
+ export function noteEditorSeatAvailable(): void {
26
+ seats += 1
27
+ }
28
+
29
+ /** One seat went away (a registration was disposed); never negative. */
30
+ export function noteEditorSeatGone(): void {
31
+ seats = Math.max(0, seats - 1)
32
+ }
33
+
34
+ /** How many seats exist right now. */
35
+ export function editorSeatCount(): number {
36
+ return seats
37
+ }
38
+
39
+ /** Test-only reset (the gate drives the counter directly). */
40
+ export function resetEditorSeatsForTests(): void {
41
+ seats = 0
42
+ }