dsh-remote-vs 0.26.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 (46) hide show
  1. package/README.en.md +4 -11
  2. package/README.md +4 -8
  3. package/THIRD-PARTY-NOTICES.md +7 -2
  4. package/lib/client.js +6622 -5821
  5. package/lib/index.js +275 -1
  6. package/lib/types/client/CodeEditor.d.ts +14 -0
  7. package/lib/types/client/OutlinePanel.d.ts +22 -0
  8. package/lib/types/client/ProcessesSection.d.ts +19 -0
  9. package/lib/types/client/api.d.ts +5 -1
  10. package/lib/types/client/blame-model.d.ts +77 -0
  11. package/lib/types/client/i18n.d.ts +1 -1
  12. package/lib/types/client/outline-model.d.ts +59 -0
  13. package/lib/types/client/scm/actions.d.ts +12 -1
  14. package/lib/types/client/store.d.ts +18 -0
  15. package/lib/types/client/vsc/blame.d.ts +19 -0
  16. package/lib/types/client/vsc/kit.d.ts +0 -2
  17. package/lib/types/client/vsc/preview-document.d.ts +46 -0
  18. package/lib/types/client/vsc/preview-model.d.ts +31 -0
  19. package/lib/types/client/vsc/preview-services.d.ts +24 -0
  20. package/lib/types/git-ops.d.ts +18 -0
  21. package/lib/types/processes.d.ts +43 -0
  22. package/lib/types/protocol.d.ts +34 -0
  23. package/package.json +2 -1
  24. package/src/client/CodeEditor.tsx +43 -1
  25. package/src/client/EditorPane.tsx +520 -37
  26. package/src/client/MonitorView.tsx +16 -5
  27. package/src/client/OutlinePanel.tsx +287 -0
  28. package/src/client/ProcessesSection.tsx +292 -0
  29. package/src/client/api.ts +8 -0
  30. package/src/client/blame-model.ts +242 -0
  31. package/src/client/i18n.ts +194 -0
  32. package/src/client/index.tsx +4 -0
  33. package/src/client/outline-model.ts +775 -0
  34. package/src/client/scm/HistoryPanel.tsx +38 -1
  35. package/src/client/scm/actions.ts +55 -2
  36. package/src/client/store.tsx +54 -5
  37. package/src/client/vsc/blame.ts +147 -0
  38. package/src/client/vsc/kit.tsx +3 -11
  39. package/src/client/vsc/preview-document.tsx +323 -0
  40. package/src/client/vsc/preview-model.ts +216 -0
  41. package/src/client/vsc/preview-services.ts +118 -0
  42. package/src/client/vsc/vsc.css +6509 -5716
  43. package/src/git-ops.ts +34 -0
  44. package/src/processes.ts +177 -0
  45. package/src/protocol.ts +37 -0
  46. package/src/routes.ts +118 -0
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Document previews for remote files.
3
+ *
4
+ * Text sources (Markdown/HTML/SVG/CSV) are rendered from the editor buffer. PDF,
5
+ * audio/video and Office bytes never pass through `fs.read` (it is a UTF-8 API
6
+ * with a 4 MiB cap): they are streamed from the existing `/download` route into
7
+ * a blob URL, and Office is first converted to PDF by a LibreOffice already
8
+ * present on the REMOTE host. When that engine is missing the notice says so;
9
+ * the plugin never claims a corrupt file.
10
+ */
11
+ import { type ReactNode } from 'react';
12
+ /** Never assemble a larger preview body than this in the tab. */
13
+ export declare const MAX_PREVIEW_BYTES: number;
14
+ export declare function officeExtensionOf(path: string): string | undefined;
15
+ /**
16
+ * Convert one remote Office document to PDF on the remote host.
17
+ *
18
+ * Paths and the extension are quoted/validated here; the only value that ends
19
+ * up in the shell is the remote path. A missing engine is reported as
20
+ * `@@RVS_NO_SOFFICE` (notice), not as a corrupt document.
21
+ */
22
+ export declare function officeConvertCommand(path: string): string;
23
+ /** Fetch one remote file body through the streaming download route. */
24
+ export declare function fetchRemoteBytes(alias: string, path: string, signal?: AbortSignal): Promise<Uint8Array>;
25
+ export declare function BytePreview(props: {
26
+ alias: string;
27
+ path: string;
28
+ /** DSH session; lets the host workspaceFiles/officeKit remotes resolve the
29
+ * same remote workspace before the plugin's own download fallback. */
30
+ sessionId?: string;
31
+ kind: 'pdf' | 'office' | 'media';
32
+ revision: number;
33
+ t: (key: string) => string;
34
+ }): ReactNode;
35
+ export declare function SvgPreview(props: {
36
+ path: string;
37
+ text: string;
38
+ truncated: boolean;
39
+ t: (key: string) => string;
40
+ }): ReactNode;
41
+ export declare function TablePreview(props: {
42
+ path: string;
43
+ text: string;
44
+ truncated: boolean;
45
+ t: (key: string) => string;
46
+ }): ReactNode;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Remote document preview classification and table parsing.
3
+ *
4
+ * Pure functions only (no React/DOM/fetch): the editor shell, the preview
5
+ * component and the gate all read the same classification, and CSV/TSV parsing
6
+ * can be tested in Node.
7
+ */
8
+ export type PreviewKind = 'text' | 'image' | 'markdown' | 'html' | 'svg' | 'table' | 'pdf' | 'office' | 'media';
9
+ export declare function extensionOf(path: string): string;
10
+ export declare function previewKindOf(path: string): PreviewKind;
11
+ export declare function isBytePreview(kind: PreviewKind): kind is 'pdf' | 'office' | 'media';
12
+ export declare function hasTextSource(kind: PreviewKind): boolean;
13
+ export declare function previewKindLabel(kind: PreviewKind): string | undefined;
14
+ export declare function mediaTypeOf(path: string): {
15
+ kind: 'audio' | 'video';
16
+ mime: string;
17
+ } | undefined;
18
+ export declare function tableDelimiterOf(path: string): string;
19
+ export interface TableLimits {
20
+ maxRows: number;
21
+ maxColumns: number;
22
+ maxCells: number;
23
+ }
24
+ export declare const DEFAULT_TABLE_LIMITS: TableLimits;
25
+ export interface TableData {
26
+ rows: string[][];
27
+ columns: number;
28
+ truncated: boolean;
29
+ }
30
+ /** RFC 4180 parser with explicit row/column/cell bounds. */
31
+ export declare function parseDelimited(text: string, delimiter: string, limits?: TableLimits): TableData;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Host Client-Remote access for document previews.
3
+ *
4
+ * The reference local-workbench implementation reads bytes through
5
+ * `remote.workspaceFiles.readBytes` and converts Office through
6
+ * `remote.officeKit.render`. dsh-remote-vs replaces the global `fs` with a
7
+ * transparent RouterFs, so those services can route a remote session's
8
+ * workspace; this module keeps them as SOFT services (ctx.get) and reports
9
+ * `unavailable` when a profile does not mount them.
10
+ */
11
+ import type { Context } from '@deepseek-ai/cordis';
12
+ export type PreviewFailureReason = 'unavailable' | 'too-large' | 'not-found' | 'remote' | 'failed';
13
+ export type PreviewBytesResult = {
14
+ ok: true;
15
+ data: Uint8Array;
16
+ size: number;
17
+ } | {
18
+ ok: false;
19
+ reason: PreviewFailureReason;
20
+ detail: string;
21
+ };
22
+ export declare function installPreviewServices(ctx: Context): () => void;
23
+ export declare function readWorkspaceBytes(sessionId: string, path: string, signal?: AbortSignal): Promise<PreviewBytesResult>;
24
+ export declare function renderOfficePdf(sessionId: string, path: string, signal?: AbortSignal): Promise<PreviewBytesResult>;
@@ -137,6 +137,24 @@ export declare function commitPatchCommand(workdir: string, ref: string): string
137
137
  export declare function commitFileDiffCommand(workdir: string, ref: string, paths: readonly string[]): string;
138
138
  /** One file's content at a revision (`rev` may also be `:0` for the index). */
139
139
  export declare function fileAtRevCommand(workdir: string, rev: string, path: string): string;
140
+ /**
141
+ * One inclusive line window of `git blame` for a repo-relative file.
142
+ *
143
+ * The window is part of the command (not a post-filter): blame is one of the
144
+ * reads that can be very expensive on a large file, and the editor only ever
145
+ * needs the lines around the viewport. `--line-porcelain` repeats the commit
146
+ * header for every line, so the parser is stateless (see `blame-model.ts`).
147
+ */
148
+ export declare function blameCommand(workdir: string, path: string, from: number, to: number): string;
149
+ /**
150
+ * Commits that touched one file, newest first, with rename following.
151
+ *
152
+ * `--follow` works only for a single path; the format matches `parseLog`, so
153
+ * the existing history row type is reused without a second parser.
154
+ */
155
+ export declare function fileHistoryCommand(workdir: string, path: string, max?: number): string;
156
+ /** One commit's header fields, even when it is older than the log window. */
157
+ export declare function commitMetaCommand(workdir: string, ref: string): string;
140
158
  /** Local + remote-tracking branches with their upstream and tip. */
141
159
  export declare function allBranchesCommand(workdir: string): string;
142
160
  /** Every configured remote with its URLs. */
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Remote process snapshots for the monitor page.
3
+ *
4
+ * Same model as `listen-ports.ts`: one bounded POSIX probe (GNU `ps`, a BSD
5
+ * `ps` fallback, then an explicit `none`), with all parsing done host-side so
6
+ * the browser only receives a bounded table. A process is never killed by a
7
+ * command assembled in the browser: the route validates the PID against the
8
+ * latest snapshot and builds the one signal command here.
9
+ */
10
+ import type { RemoteProcessesResult } from './protocol.ts';
11
+ /** Marker proving which probe branch actually ran. */
12
+ export declare const PROCESSES_MARK = "@@RVS-PROCS";
13
+ /** Budget for the whole probe; a stuck process table must not pin a channel. */
14
+ export declare const PROCESSES_TIMEOUT_MS = 15000;
15
+ /** Hard cap on rows per snapshot (a container host can have thousands). */
16
+ export declare const PROCESSES_MAX = 500;
17
+ /** Longest command string sent to the browser per row. */
18
+ export declare const PROCESS_COMMAND_MAX = 300;
19
+ /**
20
+ * One bounded probe.
21
+ *
22
+ * GNU first (`--sort` + `etimes`), then the portable `ps aux` table for BSD /
23
+ * old systems (`ppid` and elapsed time are unknown there). The marker
24
+ * line is printed BEFORE the table so an interrupted probe is distinguishable
25
+ * from a genuinely empty one; the final marker lets the parser reject a
26
+ * truncated run.
27
+ */
28
+ export declare function processesCommand(max?: number): string;
29
+ /** A kill signal the route accepts; never an arbitrary string from the client. */
30
+ export type KillSignal = 'TERM' | 'KILL';
31
+ export declare function isKillSignal(value: unknown): value is KillSignal;
32
+ /** Assert a PID a process snapshot may contain (1 is the remote init). */
33
+ export declare function assertProcessPid(value: unknown): number;
34
+ /**
35
+ * Build the one kill command. The PID has already passed the snapshot check;
36
+ * single-quoting it keeps the command shape uniform with every other builder.
37
+ */
38
+ export declare function killCommand(pid: number, signal: KillSignal): string;
39
+ /**
40
+ * Parse one probe. `exitCode === null` (channel died) or a missing end marker
41
+ * means `unknown`, never an empty process table.
42
+ */
43
+ export declare function parseProcesses(stdout: string, exitCode: number | null): RemoteProcessesResult;
@@ -41,6 +41,8 @@ export declare const REMOTE_API: {
41
41
  readonly listenPorts: "/api/dsh-remote/listen-ports";
42
42
  /** Live system metrics for the monitor panel (one bounded probe per host). */
43
43
  readonly metrics: "/api/dsh-remote/metrics";
44
+ /** One bounded process table for the monitor page, plus TERM/KILL actions. */
45
+ readonly processes: "/api/dsh-remote/processes";
44
46
  };
45
47
  /**
46
48
  * Most entries one multi-selection download may archive. The selection rides in
@@ -695,6 +697,38 @@ export interface RemoteListenPortsResult {
695
697
  /** Why the probe could not be used, when it could not. */
696
698
  error?: string;
697
699
  }
700
+ /** One row of the remote process table. */
701
+ export interface RemoteProcess {
702
+ pid: number;
703
+ /** Parent PID; 0 on a BSD `ps aux` table that does not print it. */
704
+ ppid: number;
705
+ user: string;
706
+ cpuPercent: number;
707
+ memPercent: number;
708
+ /** Elapsed seconds when the probe can provide them; null on BSD `ps aux`. */
709
+ elapsedSeconds: number | null;
710
+ command: string;
711
+ }
712
+ /**
713
+ * The remote process probe's answer.
714
+ *
715
+ * `tool: 'none' | 'unknown'` means "cannot enumerate", never "no processes";
716
+ * the monitor page must explain that instead of rendering an empty table.
717
+ */
718
+ export interface RemoteProcessesResult {
719
+ tool: 'gnu' | 'bsd' | 'none' | 'unknown';
720
+ processes: RemoteProcess[];
721
+ truncated: boolean;
722
+ error?: string;
723
+ }
724
+ /** Result of one TERM/KILL request (the route validates the PID first). */
725
+ export interface RemoteProcessKillResult {
726
+ ok: boolean;
727
+ pid: number;
728
+ signal: 'TERM' | 'KILL';
729
+ /** Remote error text when the signal was refused. */
730
+ error?: string;
731
+ }
698
732
  /**
699
733
  * How one host metrics sample ended.
700
734
  *
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-remote-vs",
3
3
  "description": "VSCode-style remote development for DSH: SSH host manager (key/password), helper deploy pipeline with version check, remote file explorer + editor + terminal in dsh-better-sidebar.",
4
- "version": "0.26.0",
4
+ "version": "0.27.0",
5
5
  "icon": "icon.svg",
6
6
  "keywords": [
7
7
  "dsh",
@@ -150,6 +150,7 @@
150
150
  "@deepseek-ai/dsh-api-remotes": "0.2.2-rc.5",
151
151
  "@deepseek-ai/dsh-bash-local": "0.2.2-rc.5",
152
152
  "@deepseek-ai/dsh-client-locale": "0.2.2-rc.5",
153
+ "@deepseek-ai/dsh-client-ui-primitives": "0.2.2-rc.5",
153
154
  "@deepseek-ai/dsh-client-ui-renderer": "0.2.2-rc.5",
154
155
  "@deepseek-ai/dsh-client-ui-settings": "0.2.2-rc.5",
155
156
  "@deepseek-ai/dsh-client-ui-sidebar-right": "0.2.2-rc.5",
@@ -129,6 +129,9 @@ const wrapCompartment = new Compartment()
129
129
  */
130
130
  const changeMarksCompartment = new Compartment()
131
131
 
132
+ /** Compartment holding the inline blame gutter; empty until the pane has data. */
133
+ const blameCompartment = new Compartment()
134
+
132
135
  /** True while CodeMirror's own highlighter has produced token spans. */
133
136
  function primaryColored(host: Element): boolean {
134
137
  return host.querySelector('[class*="rvs-ck-"]') !== null
@@ -148,6 +151,8 @@ import {
148
151
  type ChangeMark,
149
152
  type ChangeSet,
150
153
  } from './vsc/change-marks.ts'
154
+ import { blameExtension, blameViewportReporter } from './vsc/blame.ts'
155
+ import type { BlameLine } from './blame-model.ts'
151
156
  import { DEFAULT_UNDO_LABEL, undoAffordance } from './changes/undo-affordance.ts'
152
157
 
153
158
  /**
@@ -200,6 +205,19 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
200
205
  * 加入本功能之前完全一致。
201
206
  */
202
207
  changeSet?: ChangeSet | null
208
+ /**
209
+ * Line→commit map for the inline blame gutter. `undefined`/empty removes the
210
+ * gutter entirely, so diff panes and files without blame data keep their old
211
+ * layout.
212
+ */
213
+ blame?: ReadonlyMap<number, BlameLine> | null
214
+ /** Clicking a blame cell asks the pane to reveal that commit. */
215
+ onOpenBlame?: (entry: BlameLine) => void
216
+ /**
217
+ * Reports the visible 1-based line range. The pane uses it to fetch blame one
218
+ * window at a time; CodeMirror is the only code that knows the viewport.
219
+ */
220
+ onViewport?: (first: number, last: number) => void
203
221
  /**
204
222
  * 用户在某一处改动上按下「撤销这处改动」时回调。
205
223
  *
@@ -433,6 +451,27 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
433
451
  }
434
452
  }, [props.changeSet, undoArmed, view, t])
435
453
 
454
+ /**
455
+ * Blame gutter: install/replace it when the pane hands over a new window.
456
+ *
457
+ * The map identity changes as viewport windows land, so comparing it is the
458
+ * only cheap "same data" test; the extension itself is small and rebuilding
459
+ * it costs one compartment transaction, not a document change.
460
+ */
461
+ useEffect(() => {
462
+ const current = viewRef.current
463
+ if (current === undefined) return
464
+ const entries = props.blame
465
+ const extension = entries !== undefined && entries !== null && entries.size > 0
466
+ ? blameExtension(entries, entry => { propsRef.current.onOpenBlame?.(entry) })
467
+ : []
468
+ try {
469
+ current.dispatch({ effects: blameCompartment.reconfigure(extension) })
470
+ } catch {
471
+ // Disposed.
472
+ }
473
+ }, [props.blame])
474
+
436
475
  /**
437
476
  * 跳到某个改动点。
438
477
  *
@@ -625,7 +664,7 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
625
664
  revealRange: (from, to) => {
626
665
  const current = viewRef.current
627
666
  if (current === undefined) return
628
- revealRange(current, from, to)
667
+ revealRange(current, from, to, setLitPosition)
629
668
  },
630
669
  getChangeStale: () => viewRef.current?.state.field(changeStaleField, false) === true,
631
670
  }), [])
@@ -824,6 +863,9 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
824
863
  // Session-change marks, off until a `changeSet` prop arrives (see
825
864
  // `changeMarksCompartment`).
826
865
  changeMarksCompartment.of([]),
866
+ // Inline blame, off until the pane has fetched a window.
867
+ blameCompartment.of([]),
868
+ blameViewportReporter((first, last) => { propsRef.current.onViewport?.(first, last) }),
827
869
  wrapCompartment.of(propsRef.current.wrap === false ? [] : EditorView.lineWrapping),
828
870
  readOnlyCompartment.of(EditorState.readOnly.of(propsRef.current.readOnly === true)),
829
871
  ...langFor(propsRef.current.path),