dsh-remote-vs 0.26.0 → 0.28.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 (75) hide show
  1. package/README.en.md +112 -28
  2. package/README.md +84 -25
  3. package/THIRD-PARTY-NOTICES.md +7 -2
  4. package/lib/client.js +1237 -254
  5. package/lib/index.js +821 -17
  6. package/lib/types/changes/recorder.d.ts +119 -2
  7. package/lib/types/client/CodeEditor.d.ts +29 -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/api.d.ts +22 -2
  11. package/lib/types/client/blame-model.d.ts +77 -0
  12. package/lib/types/client/changes/apply-failure.d.ts +41 -0
  13. package/lib/types/client/changes/block-confirm.d.ts +97 -0
  14. package/lib/types/client/changes/diff-outcome.d.ts +56 -0
  15. package/lib/types/client/changes/freshness.d.ts +51 -0
  16. package/lib/types/client/changes/model.d.ts +19 -1
  17. package/lib/types/client/changes/session-diff.d.ts +100 -0
  18. package/lib/types/client/changes/staleness.d.ts +98 -0
  19. package/lib/types/client/changes/turn-reverted.d.ts +82 -0
  20. package/lib/types/client/changes/turn-view.d.ts +131 -0
  21. package/lib/types/client/changes/undo-affordance.d.ts +44 -10
  22. package/lib/types/client/changes/undo-target.d.ts +12 -0
  23. package/lib/types/client/i18n.d.ts +1 -1
  24. package/lib/types/client/outline-model.d.ts +59 -0
  25. package/lib/types/client/scm/actions.d.ts +12 -1
  26. package/lib/types/client/store.d.ts +109 -1
  27. package/lib/types/client/vsc/blame.d.ts +19 -0
  28. package/lib/types/client/vsc/change-marks.d.ts +21 -0
  29. package/lib/types/client/vsc/kit.d.ts +0 -2
  30. package/lib/types/client/vsc/preview-document.d.ts +46 -0
  31. package/lib/types/client/vsc/preview-model.d.ts +31 -0
  32. package/lib/types/client/vsc/preview-services.d.ts +24 -0
  33. package/lib/types/git-ops.d.ts +18 -0
  34. package/lib/types/processes.d.ts +43 -0
  35. package/lib/types/protocol.d.ts +133 -1
  36. package/package.json +2 -1
  37. package/src/changes/recorder.ts +851 -8
  38. package/src/client/CodeEditor.tsx +86 -4
  39. package/src/client/EditorPane.tsx +581 -41
  40. package/src/client/MonitorView.tsx +16 -5
  41. package/src/client/OutlinePanel.tsx +287 -0
  42. package/src/client/ProcessesSection.tsx +292 -0
  43. package/src/client/api.ts +38 -3
  44. package/src/client/blame-model.ts +242 -0
  45. package/src/client/changes/ChangesDock.tsx +539 -54
  46. package/src/client/changes/apply-failure.ts +73 -0
  47. package/src/client/changes/block-confirm.ts +180 -0
  48. package/src/client/changes/changes.css +45 -0
  49. package/src/client/changes/diff-outcome.ts +97 -0
  50. package/src/client/changes/freshness.ts +68 -0
  51. package/src/client/changes/model.ts +56 -1
  52. package/src/client/changes/session-diff.ts +187 -0
  53. package/src/client/changes/staleness.ts +148 -0
  54. package/src/client/changes/turn-reverted.ts +254 -0
  55. package/src/client/changes/turn-view.ts +195 -0
  56. package/src/client/changes/undo-affordance.ts +295 -63
  57. package/src/client/changes/undo-target.ts +12 -0
  58. package/src/client/i18n.ts +294 -2
  59. package/src/client/index.tsx +4 -0
  60. package/src/client/outline-model.ts +775 -0
  61. package/src/client/scm/DiffView.tsx +32 -13
  62. package/src/client/scm/HistoryPanel.tsx +38 -1
  63. package/src/client/scm/actions.ts +55 -2
  64. package/src/client/store.tsx +446 -21
  65. package/src/client/vsc/blame.ts +147 -0
  66. package/src/client/vsc/change-marks.ts +21 -0
  67. package/src/client/vsc/kit.tsx +3 -11
  68. package/src/client/vsc/preview-document.tsx +326 -0
  69. package/src/client/vsc/preview-model.ts +216 -0
  70. package/src/client/vsc/preview-services.ts +118 -0
  71. package/src/client/vsc/vsc.css +965 -39
  72. package/src/git-ops.ts +34 -0
  73. package/src/processes.ts +177 -0
  74. package/src/protocol.ts +138 -1
  75. package/src/routes.ts +138 -9
@@ -627,7 +627,9 @@ export function DiffView(props: { tab: EditorTab; visible: boolean; offline?: bo
627
627
 
628
628
  // Seed the editable buffer the first time the "变更后" pane is shown.
629
629
  useEffect(() => {
630
- if (mode !== 'after' || tab.staged || tab.text !== '' || tab.loading) return
630
+ // A session diff's "after" side is a read-only pane (§sessionReadOnly): there
631
+ // is no buffer to seed, so no extra read either.
632
+ if (mode !== 'after' || tab.staged || tab.sessionDiff !== undefined || tab.text !== '' || tab.loading) return
631
633
  let cancelled = false
632
634
  void (async () => {
633
635
  try {
@@ -674,7 +676,7 @@ export function DiffView(props: { tab: EditorTab; visible: boolean; offline?: bo
674
676
  */
675
677
  const codeSide = mode === 'before'
676
678
  ? beforeSide
677
- : mode === 'after' && tab.staged
679
+ : mode === 'after' && (tab.staged || tab.sessionDiff !== undefined)
678
680
  ? afterSide
679
681
  : NO_TOKENS
680
682
  const codeWindow = useScrollWindow(codeSide.lineCount, CODE_PAD_TOP)
@@ -847,7 +849,15 @@ export function DiffView(props: { tab: EditorTab; visible: boolean; offline?: bo
847
849
  )
848
850
  }
849
851
 
850
- const editable = mode === 'after' && !tab.staged && props.offline !== true && !tab.truncated
852
+ /**
853
+ * 会话改动面板打开的只读 diff(`EditorTab.sessionDiff`)。
854
+ *
855
+ * 它比较的是**会话账本**(会话起点为基线),两侧都不是"可写的工作区副本":改前
856
+ * 是按 hunk 还原出来的基线,改后是一次独立读取。所以既不能编辑「变更后」,也不能
857
+ * 提供 hunk 的暂存/撤销 —— 那些动作的入参是 `git diff` 的补丁,不是这里的。
858
+ */
859
+ const sessionReadOnly = tab.sessionDiff !== undefined
860
+ const editable = mode === 'after' && !tab.staged && !sessionReadOnly && props.offline !== true && !tab.truncated
851
861
  /**
852
862
  * The gutter hunk buttons obey the same refusal as `runHunk` (see
853
863
  * `hunkBlockReason`), and a disabled button names the REAL reason when it has
@@ -893,13 +903,19 @@ export function DiffView(props: { tab: EditorTab; visible: boolean; offline?: bo
893
903
  the exact reason whenever the binding gate refuses. The glyph is
894
904
  text because the icon set has no "AI" mark — the same precedent as
895
905
  the search options' `Aa` / `.*` glyphs in `kit.tsx`. */}
896
- <IconButton
897
- title={reviewBlocked ?? t('scm.aiReview')}
898
- onClick={reviewWithAi}
899
- disabled={reviewBlocked !== undefined}
900
- >
901
- <span className="rvs-glyph" aria-hidden="true" style={{ fontSize: 12 }}>AI</span>
902
- </IconButton>
906
+ {/* 会话只读 diff 不提供 AI 审查:那条 prompt 写的是"哪个工作区/仓库目录/
907
+ 哪个路径"(`store.alias` + `store.repoRoot`),而这一页的基线是会话账本、
908
+ 路径是面板的显示路径 —— 两者可能不是同一个绑定,指错地方的 prompt 比没有
909
+ 更糟。要审查会话改动,从面板左键打开文件那条路走。 */}
910
+ {!sessionReadOnly && (
911
+ <IconButton
912
+ title={reviewBlocked ?? t('scm.aiReview')}
913
+ onClick={reviewWithAi}
914
+ disabled={reviewBlocked !== undefined}
915
+ >
916
+ <span className="rvs-glyph" aria-hidden="true" style={{ fontSize: 12 }}>AI</span>
917
+ </IconButton>
918
+ )}
903
919
  <IconButton title={t('scm.reloadDiff')} onClick={() => { void reload() }} disabled={busy}>
904
920
  <IconRefresh size={13} />
905
921
  </IconButton>
@@ -957,9 +973,12 @@ export function DiffView(props: { tab: EditorTab; visible: boolean; offline?: bo
957
973
  // index is the lookup — the linear `find` was one scan per row.
958
974
  const hunk = row.hunk >= 0 ? model.hunks[row.hunk] : undefined
959
975
  const startOfHunk = hunk !== undefined && hunk.startRow === row.id
976
+ // 只读的会话 diff 没有 hunk 写动作:整行只留一个色点(指示"这里
977
+ // 有一处改动"),不给暂存/撤销那两个会打到别处的按钮。
978
+ const changed = row.oldDel || row.newAdd
960
979
  return (
961
980
  <div key={row.id} className="rvs-gutter-line">
962
- {startOfHunk && hunk !== undefined && (
981
+ {startOfHunk && hunk !== undefined && !sessionReadOnly && (
963
982
  <span className="rvs-hunk-btns">
964
983
  {hunkBusy === hunk.index
965
984
  ? <MiniSpinner />
@@ -989,7 +1008,7 @@ export function DiffView(props: { tab: EditorTab; visible: boolean; offline?: bo
989
1008
  )}
990
1009
  </span>
991
1010
  )}
992
- {!startOfHunk && (row.oldDel || row.newAdd) && (
1011
+ {(!startOfHunk || sessionReadOnly) && changed && (
993
1012
  <span className="rvs-gutter-dot" style={{ background: row.oldDel ? 'var(--rvs-git-d)' : 'var(--rvs-git-a)' }} />
994
1013
  )}
995
1014
  </div>
@@ -1021,7 +1040,7 @@ export function DiffView(props: { tab: EditorTab; visible: boolean; offline?: bo
1021
1040
  </div>
1022
1041
  )}
1023
1042
  {mode === 'after' && (
1024
- tab.staged
1043
+ tab.staged || sessionReadOnly
1025
1044
  ? (
1026
1045
  <div className="rvs-code rvs-scroll" ref={codeWindow.attach} onScroll={codeWindow.onScroll}>
1027
1046
  <CodeLines tokens={codeSide} range={codeWindow.range} emptyText={t('scm.emptySide')} />
@@ -26,7 +26,7 @@ import type { GitCommit, GitCommitFile } from '../../protocol.ts'
26
26
  import { GIT_LOG_MAX } from '../../git-format.ts'
27
27
  import { api } from '../api.ts'
28
28
  import { gitReadSettleMs, shallowEqual, useExplorerSelector, type ExplorerValue } from '../store.tsx'
29
- import { checkoutCommit, joinRemote, loadCommitFiles, loadCommitMessage, loadCommitPatch } from './actions.ts'
29
+ import { checkoutCommit, joinRemote, loadCommit, loadCommitFiles, loadCommitMessage, loadCommitPatch } from './actions.ts'
30
30
  import { CommitPane } from './CommitPane.tsx'
31
31
  import { isHistoryTab, needsPatchLoad, refBadgeClass, refBadgeLabel, type HistoryTab } from './commit-model.ts'
32
32
  import { ReadQueue } from './read-queue.ts'
@@ -44,6 +44,16 @@ import {
44
44
  } from '../vsc/kit.tsx'
45
45
 
46
46
  const ROW_H = 22
47
+
48
+ /**
49
+ * Last `commitFocus` request consumed by ANY mounted panel instance.
50
+ *
51
+ * The request lives in the store until overwritten, and the panel re-renders
52
+ * whenever the log refreshes; without this module-level watermark a click on
53
+ * blame would be replayed over the user's later manual selection (and across
54
+ * repository switches). Same rule as `revealRequest`/`terminalRequest`.
55
+ */
56
+ let consumedCommitFocusId = 0
47
57
  const LANE_W = 13
48
58
  const PAD_X = 9
49
59
  const LANE_COLORS = ['#e2b714', '#4ec9b0', '#58a6ff', '#d2a8ff', '#ff7b72', '#79c0ff', '#7ee787', '#ffa657']
@@ -226,6 +236,7 @@ const selectHistoryStore = (snapshot: ExplorerValue) => ({
226
236
  openCommitFile: snapshot.openCommitFile,
227
237
  revealInExplorer: snapshot.revealInExplorer,
228
238
  openTerminalAt: snapshot.openTerminalAt,
239
+ commitFocus: snapshot.commitFocus,
229
240
  })
230
241
 
231
242
  export function HistoryPanel(): ReactNode {
@@ -349,6 +360,32 @@ export function HistoryPanel(): ReactNode {
349
360
  setFocusPath(undefined)
350
361
  }, [repoKey])
351
362
 
363
+ // Blame / file-history entries only know a hash: the editor asks the store to
364
+ // show it here, and the log above owns the row object the detail pane needs.
365
+ // Declared AFTER the repository-switch reset so a first mount cannot clear the
366
+ // selection that this request just set.
367
+ useEffect(() => {
368
+ const request = store.commitFocus
369
+ if (request === undefined) return
370
+ if (request.id === consumedCommitFocusId) return
371
+ consumedCommitFocusId = request.id
372
+ setSelectedHash(request.hash)
373
+ setFocusPath(undefined)
374
+ // Blame can point at a commit older than the loaded graph window; fetch its
375
+ // header so the detail pane still opens instead of selecting nothing.
376
+ const live = rows.some(commit => commit.hash === request.hash)
377
+ if (live || selectedSnapshot?.hash === request.hash || alias === '' || repoRoot === undefined) return
378
+ let cancelled = false
379
+ void loadCommit(alias, repoRoot, request.hash)
380
+ .then((commit) => {
381
+ if (!cancelled && commit !== undefined) setSelectedSnapshot(commit)
382
+ })
383
+ .catch(() => {
384
+ // A stale/invalid hash is not worth a toast: the rail is still usable.
385
+ })
386
+ return () => { cancelled = true }
387
+ }, [store.commitFocus?.id, rows, selectedSnapshot?.hash, alias, repoRoot])
388
+
352
389
  // Message + file list: what 提交详情 and 内容 need. The patch is NOT read here
353
390
  // (see the lazy effect below), so clicking through commits stays cheap.
354
391
  useEffect(() => {
@@ -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,6 +27,7 @@ import {
25
27
  deleteBranchCommand,
26
28
  diffCommand,
27
29
  fetchCommand,
30
+ fileHistoryCommand,
28
31
  fileAtRevCommand,
29
32
  gitErrorHint,
30
33
  GIT_CAP,
@@ -62,6 +65,7 @@ import {
62
65
  statusPathsCommand,
63
66
  unstageCommand,
64
67
  } from '../../git-ops.ts'
68
+ import { parseBlamePorcelain, parseFileHistory, type BlameLine, type FileHistoryCommit } from '../blame-model.ts'
65
69
  import { api, gitTimeoutMs, type RequestOptions } from '../api.ts'
66
70
  import { isRequestAbort } from '../request-gate.ts'
67
71
  import { appendExecOutput, networkBudgetMs, networkCommands, type PushTarget } from '../exec-output.ts'
@@ -425,6 +429,55 @@ export async function loadCommitPatch(alias: string, root: string, hash: string)
425
429
  return { text: out.stdout, truncated: bytes >= GIT_CAP }
426
430
  }
427
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
+
428
481
  /** Local + remote-tracking branches. */
429
482
  export async function loadBranches(alias: string, root: string, current: string): Promise<GitBranch[]> {
430
483
  const out = await run(alias, allBranchesCommand(root), 60_000)