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
@@ -8,16 +8,18 @@
8
8
  * messages a user can act on (missing identity, no upstream, conflicts, ...).
9
9
  */
10
10
  import { REMOTE_API } from '../../protocol.ts'
11
- import type { GitBranch, GitCommitFile, GitRemote, GitStash, GitStatusDetail, RemoteExecResult, RemoteRead } from '../../protocol.ts'
12
- import { assertRef, messageCommand, parseMessage, shQuote } from '../../git-format.ts'
11
+ import type { GitBranch, GitCommit, GitCommitFile, GitRemote, GitStash, GitStatusDetail, RemoteExecResult, RemoteRead } from '../../protocol.ts'
12
+ import { assertRef, messageCommand, parseLog, parseMessage, shQuote } from '../../git-format.ts'
13
13
  import {
14
14
  addRemoteCommand,
15
15
  allBranchesCommand,
16
16
  applyPatchCommand,
17
+ blameCommand,
17
18
  branchHeaderCommand,
18
19
  checkoutCommand,
19
20
  cleanUntrackedCommand,
20
21
  commitCommand,
22
+ commitMetaCommand,
21
23
  commitFileDiffCommand,
22
24
  commitFilesCommand,
23
25
  commitPatchCommand,
@@ -25,10 +27,12 @@ import {
25
27
  deleteBranchCommand,
26
28
  diffCommand,
27
29
  fetchCommand,
30
+ fileHistoryCommand,
28
31
  fileAtRevCommand,
29
32
  gitErrorHint,
30
33
  GIT_CAP,
31
34
  headMessageCommand,
35
+ initCommand,
32
36
  mergeCommand,
33
37
  parseAllBranches,
34
38
  parseCommitFiles,
@@ -61,7 +65,9 @@ import {
61
65
  statusPathsCommand,
62
66
  unstageCommand,
63
67
  } from '../../git-ops.ts'
64
- import { api, gitTimeoutMs } from '../api.ts'
68
+ import { parseBlamePorcelain, parseFileHistory, type BlameLine, type FileHistoryCommit } from '../blame-model.ts'
69
+ import { api, gitTimeoutMs, type RequestOptions } from '../api.ts'
70
+ import { isRequestAbort } from '../request-gate.ts'
65
71
  import { appendExecOutput, networkBudgetMs, networkCommands, type PushTarget } from '../exec-output.ts'
66
72
  import { timeoutSeconds } from '../../timeouts.ts'
67
73
 
@@ -101,19 +107,61 @@ function failureOf(result: RemoteExecResult, timeoutMs: number): GitOpError {
101
107
  return new GitOpError(hint ?? detail ?? result.error ?? `git failed [exit code: ${result.exitCode ?? '?'}]`)
102
108
  }
103
109
 
110
+ /**
111
+ * Per-command options for {@link run} / {@link tryRun}.
112
+ *
113
+ * `background` puts the command on the request gate's git channel: it waits
114
+ * while a foreground request is in flight and only one such command runs at a
115
+ * time. ONLY the repository-wide READ paths use it (`probeRepoRoot`,
116
+ * `loadStatusDetail`, `loadHead`), because those are the walks a workspace
117
+ * switch starts and the ones that must never make the directory listing queue
118
+ * behind them. Every verb the user is waiting on (stage, commit, push, the
119
+ * bounded probes, the search) stays foreground and is unaffected.
120
+ *
121
+ * `signal` cancels the command: the HTTP request is aborted (and, while still
122
+ * queued, is taken out of the queue) — the store's `readGit` uses it to release
123
+ * the connections of a workspace the user just left.
124
+ */
125
+ export interface RunOptions {
126
+ background?: boolean
127
+ signal?: AbortSignal
128
+ }
129
+
130
+ /** Map {@link RunOptions} onto the HTTP layer's {@link RequestOptions}. */
131
+ function requestOptionsOf(options: RunOptions): RequestOptions {
132
+ return {
133
+ ...(options.background === true ? { background: true } : {}),
134
+ ...(options.signal === undefined ? {} : { signal: options.signal }),
135
+ }
136
+ }
137
+
104
138
  /** Run one command, raising a readable error on a non-zero exit. */
105
- async function run(alias: string, command: string, timeoutMs = normalTimeoutMs()): Promise<RemoteExecResult> {
106
- const result = await api.exec(alias, command, timeoutMs)
139
+ async function run(
140
+ alias: string,
141
+ command: string,
142
+ timeoutMs = normalTimeoutMs(),
143
+ options: RunOptions = {},
144
+ ): Promise<RemoteExecResult> {
145
+ const result = await api.exec(alias, command, timeoutMs, requestOptionsOf(options))
107
146
  if (result.success) return result
108
147
  throw failureOf(result, timeoutMs)
109
148
  }
110
149
 
111
150
  /** Run one command tolerating failure (returns '' instead). */
112
- async function tryRun(alias: string, command: string, timeoutMs = normalTimeoutMs()): Promise<string> {
151
+ async function tryRun(
152
+ alias: string,
153
+ command: string,
154
+ timeoutMs = normalTimeoutMs(),
155
+ options: RunOptions = {},
156
+ ): Promise<string> {
113
157
  try {
114
- const result = await api.exec(alias, command, timeoutMs)
158
+ const result = await api.exec(alias, command, timeoutMs, requestOptionsOf(options))
115
159
  return result.success ? result.stdout : ''
116
- } catch {
160
+ } catch (error) {
161
+ // A cancelled command is not "no answer": swallowing it would let the
162
+ // sibling half of a `Promise.all` land with a placeholder value (an aborted
163
+ // HEAD write once cached `detached: true`).
164
+ if (isRequestAbort(error)) throw error
117
165
  return ''
118
166
  }
119
167
  }
@@ -146,11 +194,22 @@ export type RepoRootProbe =
146
194
  | { kind: 'failed'; error: string }
147
195
 
148
196
  /** The repository root, or WHY the probe could not answer. */
149
- export async function probeRepoRoot(alias: string, workspaceRoot: string): Promise<RepoRootProbe> {
197
+ export async function probeRepoRoot(
198
+ alias: string,
199
+ workspaceRoot: string,
200
+ signal?: AbortSignal,
201
+ ): Promise<RepoRootProbe> {
150
202
  let result: RemoteExecResult
151
203
  try {
152
- result = await api.exec(alias, repoProbeDetailCommand(workspaceRoot), normalTimeoutMs())
204
+ result = await api.exec(alias, repoProbeDetailCommand(workspaceRoot), normalTimeoutMs(), {
205
+ // The probe is the FIRST step of a workspace switch's background walk: on
206
+ // a large tree it is a full `rev-parse` + `cd` over SSH, and it must yield
207
+ // to the listing the user is waiting on.
208
+ background: true,
209
+ ...(signal === undefined ? {} : { signal }),
210
+ })
153
211
  } catch (error) {
212
+ if (isRequestAbort(error)) throw error
154
213
  // The transport/route failed before any git exit code existed.
155
214
  return { kind: 'failed', error: error instanceof Error ? error.message : String(error) }
156
215
  }
@@ -171,8 +230,13 @@ export async function findRepos(alias: string, workspaceRoot: string): Promise<s
171
230
  }
172
231
 
173
232
  /** Every changed path plus the ignored half. */
174
- export async function loadStatusDetail(alias: string, root: string): Promise<GitStatusDetail> {
175
- const out = await run(alias, statusDetailCommand(root))
233
+ export async function loadStatusDetail(alias: string, root: string, signal?: AbortSignal): Promise<GitStatusDetail> {
234
+ // The walk itself: the expensive half of a switch (8–9 s on the reported AOSP
235
+ // trees), so it runs on the git channel and yields to every foreground read.
236
+ const out = await run(alias, statusDetailCommand(root), normalTimeoutMs(), {
237
+ background: true,
238
+ ...(signal === undefined ? {} : { signal }),
239
+ })
176
240
  return parseStatusDetail(out.stdout)
177
241
  }
178
242
 
@@ -212,9 +276,20 @@ export async function probeStatusDir(alias: string, root: string, dir: string):
212
276
  }
213
277
 
214
278
  /** Current branch with its ahead/behind counters (detached HEAD tolerated). */
215
- export async function loadHead(alias: string, root: string): Promise<{ branch: string; detached: boolean; ahead: number; behind: number }> {
216
- const out = await tryRun(alias, branchHeaderCommand(root), 60_000)
279
+ export async function loadHead(
280
+ alias: string,
281
+ root: string,
282
+ signal?: AbortSignal,
283
+ ): Promise<{ branch: string; detached: boolean; ahead: number; behind: number }> {
284
+ const out = await tryRun(alias, branchHeaderCommand(root), 60_000, {
285
+ background: true,
286
+ ...(signal === undefined ? {} : { signal }),
287
+ })
217
288
  const first = (out.split('\0')[0] ?? out.split('\n')[0] ?? '').replace(/^## /, '').trim()
289
+ // An empty repository reports `## No commits yet on <branch>`: the branch name
290
+ // lives AFTER the words, and the generic pattern below would read "No".
291
+ const unborn = /^No commits yet on (\S+)$/.exec(first)
292
+ if (unborn !== null) return { branch: unborn[1] as string, detached: false, ahead: 0, behind: 0 }
218
293
  if (first === '' || first.startsWith('HEAD (no branch')) return { branch: 'HEAD', detached: true, ahead: 0, behind: 0 }
219
294
  const match = /^([^\s.]+(?:\.\.\.[^\s[]+)?)(?: \[(?:ahead (\d+))?(?:, )?(?:behind (\d+))?\])?/.exec(first)
220
295
  if (match === null) return { branch: first, detached: false, ahead: 0, behind: 0 }
@@ -354,6 +429,55 @@ export async function loadCommitPatch(alias: string, root: string, hash: string)
354
429
  return { text: out.stdout, truncated: bytes >= GIT_CAP }
355
430
  }
356
431
 
432
+ /** One viewport window of `git blame` for a repo-relative path. */
433
+ export async function loadBlame(
434
+ alias: string,
435
+ root: string,
436
+ path: string,
437
+ from: number,
438
+ to: number,
439
+ options: RunOptions = {},
440
+ ): Promise<BlameLine[]> {
441
+ const result = await run(alias, blameCommand(root, path, from, to), 60_000, options)
442
+ const rows = parseBlamePorcelain(result.stdout)
443
+ // `capped()` pipes through `head`, so git's non-zero exit is hidden; a
444
+ // `no such path` / `has only 0 lines` diagnosis still arrives on stderr and
445
+ // must not be rendered as "this window has no blame data".
446
+ if (rows.length === 0 && result.stderr.trim() !== '') {
447
+ throw new GitOpError(gitErrorHint(result.stderr) ?? result.stderr.trim())
448
+ }
449
+ return rows
450
+ }
451
+
452
+ /**
453
+ * Commits that touched one path. `--follow` makes renames visible as history
454
+ * of the CURRENT name, which is exactly what the editor's file-history menu
455
+ * promises; the rows use the same shape as the repository log.
456
+ */
457
+ export async function loadFileHistory(
458
+ alias: string,
459
+ root: string,
460
+ path: string,
461
+ max = 100,
462
+ ): Promise<FileHistoryCommit[]> {
463
+ const result = await run(alias, fileHistoryCommand(root, path, max), 60_000)
464
+ const rows = parseFileHistory(result.stdout, path)
465
+ if (rows.length === 0 && result.stderr.trim() !== '') {
466
+ throw new GitOpError(gitErrorHint(result.stderr) ?? result.stderr.trim())
467
+ }
468
+ return rows
469
+ }
470
+
471
+ /** One commit header when the hash is older than the loaded log window. */
472
+ export async function loadCommit(alias: string, root: string, hash: string): Promise<GitCommit | undefined> {
473
+ const result = await run(alias, commitMetaCommand(root, hash), 60_000)
474
+ const commit = parseLog(result.stdout)[0]
475
+ if (commit === undefined && result.stderr.trim() !== '') {
476
+ throw new GitOpError(gitErrorHint(result.stderr) ?? result.stderr.trim())
477
+ }
478
+ return commit
479
+ }
480
+
357
481
  /** Local + remote-tracking branches. */
358
482
  export async function loadBranches(alias: string, root: string, current: string): Promise<GitBranch[]> {
359
483
  const out = await run(alias, allBranchesCommand(root), 60_000)
@@ -374,6 +498,18 @@ export async function loadStashes(alias: string, root: string): Promise<GitStash
374
498
 
375
499
  // ------------------------------------------------------------ write paths
376
500
 
501
+ /**
502
+ * Initialize a repository in place (`git init`).
503
+ *
504
+ * The panel's "not a repository" state used to be a dead end (the only offer
505
+ * was "browse somewhere else") while the command builder had no caller at all.
506
+ * The caller refreshes the status afterwards — that read re-probes the
507
+ * directory, so the panel moves to the normal view without another discovery.
508
+ */
509
+ export async function initRepo(alias: string, root: string): Promise<string> {
510
+ return (await run(alias, initCommand(root), 60_000)).stdout
511
+ }
512
+
377
513
  /** Stage paths (additions, edits, deletions, renames). */
378
514
  export async function stagePaths(alias: string, root: string, paths: readonly string[]): Promise<void> {
379
515
  if (paths.length === 0) return