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.
- package/README.en.md +112 -28
- package/README.md +84 -25
- package/THIRD-PARTY-NOTICES.md +7 -2
- package/lib/client.js +1237 -254
- package/lib/index.js +821 -17
- package/lib/types/changes/recorder.d.ts +119 -2
- package/lib/types/client/CodeEditor.d.ts +29 -0
- package/lib/types/client/OutlinePanel.d.ts +22 -0
- package/lib/types/client/ProcessesSection.d.ts +19 -0
- package/lib/types/client/api.d.ts +22 -2
- package/lib/types/client/blame-model.d.ts +77 -0
- package/lib/types/client/changes/apply-failure.d.ts +41 -0
- package/lib/types/client/changes/block-confirm.d.ts +97 -0
- package/lib/types/client/changes/diff-outcome.d.ts +56 -0
- package/lib/types/client/changes/freshness.d.ts +51 -0
- package/lib/types/client/changes/model.d.ts +19 -1
- package/lib/types/client/changes/session-diff.d.ts +100 -0
- package/lib/types/client/changes/staleness.d.ts +98 -0
- package/lib/types/client/changes/turn-reverted.d.ts +82 -0
- package/lib/types/client/changes/turn-view.d.ts +131 -0
- package/lib/types/client/changes/undo-affordance.d.ts +44 -10
- package/lib/types/client/changes/undo-target.d.ts +12 -0
- package/lib/types/client/i18n.d.ts +1 -1
- package/lib/types/client/outline-model.d.ts +59 -0
- package/lib/types/client/scm/actions.d.ts +12 -1
- package/lib/types/client/store.d.ts +109 -1
- package/lib/types/client/vsc/blame.d.ts +19 -0
- package/lib/types/client/vsc/change-marks.d.ts +21 -0
- package/lib/types/client/vsc/kit.d.ts +0 -2
- package/lib/types/client/vsc/preview-document.d.ts +46 -0
- package/lib/types/client/vsc/preview-model.d.ts +31 -0
- package/lib/types/client/vsc/preview-services.d.ts +24 -0
- package/lib/types/git-ops.d.ts +18 -0
- package/lib/types/processes.d.ts +43 -0
- package/lib/types/protocol.d.ts +133 -1
- package/package.json +2 -1
- package/src/changes/recorder.ts +851 -8
- package/src/client/CodeEditor.tsx +86 -4
- package/src/client/EditorPane.tsx +581 -41
- package/src/client/MonitorView.tsx +16 -5
- package/src/client/OutlinePanel.tsx +287 -0
- package/src/client/ProcessesSection.tsx +292 -0
- package/src/client/api.ts +38 -3
- package/src/client/blame-model.ts +242 -0
- package/src/client/changes/ChangesDock.tsx +539 -54
- package/src/client/changes/apply-failure.ts +73 -0
- package/src/client/changes/block-confirm.ts +180 -0
- package/src/client/changes/changes.css +45 -0
- package/src/client/changes/diff-outcome.ts +97 -0
- package/src/client/changes/freshness.ts +68 -0
- package/src/client/changes/model.ts +56 -1
- package/src/client/changes/session-diff.ts +187 -0
- package/src/client/changes/staleness.ts +148 -0
- package/src/client/changes/turn-reverted.ts +254 -0
- package/src/client/changes/turn-view.ts +195 -0
- package/src/client/changes/undo-affordance.ts +295 -63
- package/src/client/changes/undo-target.ts +12 -0
- package/src/client/i18n.ts +294 -2
- package/src/client/index.tsx +4 -0
- package/src/client/outline-model.ts +775 -0
- package/src/client/scm/DiffView.tsx +32 -13
- package/src/client/scm/HistoryPanel.tsx +38 -1
- package/src/client/scm/actions.ts +55 -2
- package/src/client/store.tsx +446 -21
- package/src/client/vsc/blame.ts +147 -0
- package/src/client/vsc/change-marks.ts +21 -0
- package/src/client/vsc/kit.tsx +3 -11
- package/src/client/vsc/preview-document.tsx +326 -0
- package/src/client/vsc/preview-model.ts +216 -0
- package/src/client/vsc/preview-services.ts +118 -0
- package/src/client/vsc/vsc.css +965 -39
- package/src/git-ops.ts +34 -0
- package/src/processes.ts +177 -0
- package/src/protocol.ts +138 -1
- package/src/routes.ts +138 -9
package/src/client/api.ts
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
type HelperAvailability,
|
|
12
12
|
type ImportReport,
|
|
13
13
|
type RemoteChangesDiff,
|
|
14
|
+
type RemoteChangesListRequest,
|
|
14
15
|
type RemoteChangesSummary,
|
|
15
16
|
type RemoteConnectionStatus,
|
|
16
17
|
type RemoteDeployState,
|
|
@@ -21,6 +22,8 @@ import {
|
|
|
21
22
|
type RemoteHostSummary,
|
|
22
23
|
type RemoteListenPortsResult,
|
|
23
24
|
type RemoteMetricsResult,
|
|
25
|
+
type RemoteProcessKillResult,
|
|
26
|
+
type RemoteProcessesResult,
|
|
24
27
|
type RemotePluginMeta,
|
|
25
28
|
type RemoteProbe,
|
|
26
29
|
type RemoteRead,
|
|
@@ -640,13 +643,23 @@ export const api = {
|
|
|
640
643
|
* is opened for review.
|
|
641
644
|
*/
|
|
642
645
|
changes: {
|
|
643
|
-
|
|
644
|
-
|
|
646
|
+
/**
|
|
647
|
+
* @param force - `⟳` semantics: tracked scan now AND re-arm the slow new-file
|
|
648
|
+
* walk (expensive; a deliberate click).
|
|
649
|
+
* @param trackedOnly - "user came back to the page": tracked files now, but the
|
|
650
|
+
* slow walk keeps its cadence/write-off (see `RemoteChangesListRequest`).
|
|
651
|
+
*/
|
|
652
|
+
list: (sessionId: string, force = false, repoSubdir = '', trackedOnly = false) => {
|
|
653
|
+
const body: RemoteChangesListRequest = {
|
|
645
654
|
op: 'list',
|
|
646
655
|
sessionId,
|
|
647
656
|
...(force ? { force: true } : {}),
|
|
657
|
+
...(trackedOnly ? { trackedOnly: true } : {}),
|
|
648
658
|
...(repoSubdir === '' ? {} : { repoSubdir }),
|
|
649
|
-
}
|
|
659
|
+
}
|
|
660
|
+
return post<{ summary: RemoteChangesSummary | null }>(REMOTE_API.changes, body)
|
|
661
|
+
.then(r => r.summary ?? null)
|
|
662
|
+
},
|
|
650
663
|
diff: (sessionId: string, path: string, repoSubdir = '') =>
|
|
651
664
|
post<{ diff: RemoteChangesDiff | null }>(REMOTE_API.changes, {
|
|
652
665
|
op: 'diff',
|
|
@@ -654,6 +667,22 @@ export const api = {
|
|
|
654
667
|
path,
|
|
655
668
|
...(repoSubdir === '' ? {} : { repoSubdir }),
|
|
656
669
|
}).then(r => r.diff ?? null),
|
|
670
|
+
/**
|
|
671
|
+
* The same comparison, but against the previous completed turn's close
|
|
672
|
+
* instead of the session baseline (the panel's 「本轮」 scope).
|
|
673
|
+
*
|
|
674
|
+
* Answers `unavailable` / `stale` (with a reason) instead of hunks when the
|
|
675
|
+
* host has no cached per-turn contents or the file moved on after the turn —
|
|
676
|
+
* the client must fall back to `diff` (session view) rather than paint lines
|
|
677
|
+
* that no longer exist.
|
|
678
|
+
*/
|
|
679
|
+
turnDiff: (sessionId: string, path: string, repoSubdir = '') =>
|
|
680
|
+
post<{ diff: RemoteChangesDiff | null }>(REMOTE_API.changes, {
|
|
681
|
+
op: 'turnDiff',
|
|
682
|
+
sessionId,
|
|
683
|
+
path,
|
|
684
|
+
...(repoSubdir === '' ? {} : { repoSubdir }),
|
|
685
|
+
}).then(r => r.diff ?? null),
|
|
657
686
|
},
|
|
658
687
|
// -- routing mode (volatile, persists to the profile patch)
|
|
659
688
|
setRoutingMode: (mode: 'off' | 'shadow' | 'enforce') =>
|
|
@@ -712,6 +741,12 @@ export const api = {
|
|
|
712
741
|
*/
|
|
713
742
|
listenPorts: (alias: string) =>
|
|
714
743
|
call<RemoteListenPortsResult>(`${REMOTE_API.listenPorts}?alias=${encodeURIComponent(alias)}`),
|
|
744
|
+
/** One bounded remote process table (per-host cache on the Host side). */
|
|
745
|
+
processes: (alias: string, refresh = false) =>
|
|
746
|
+
call<RemoteProcessesResult>(`${REMOTE_API.processes}?alias=${encodeURIComponent(alias)}${refresh ? '&refresh=1' : ''}`),
|
|
747
|
+
/** Signal one PID from the latest snapshot; the route rejects unknown PIDs. */
|
|
748
|
+
killProcess: (alias: string, pid: number, signal: 'TERM' | 'KILL') =>
|
|
749
|
+
post<RemoteProcessKillResult>(REMOTE_API.processes, { alias, pid, signal }),
|
|
715
750
|
/**
|
|
716
751
|
* One host's live metrics sample.
|
|
717
752
|
*
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure parsing/formatting for `git blame` (and the shared vocabulary the
|
|
3
|
+
* editor UI uses for a line's provenance). No CodeMirror and no DOM here, so
|
|
4
|
+
* the gate can feed it real porcelain output.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { GitCommit } from '../protocol.ts'
|
|
8
|
+
import { unquoteGitPath } from '../git-format.ts'
|
|
9
|
+
|
|
10
|
+
/** One blamed line: 1-based final line number plus the commit that owns it. */
|
|
11
|
+
export interface BlameLine {
|
|
12
|
+
line: number
|
|
13
|
+
hash: string
|
|
14
|
+
author: string
|
|
15
|
+
email: string
|
|
16
|
+
/** Author timestamp, seconds since the epoch (git's `author-time`). */
|
|
17
|
+
time: number
|
|
18
|
+
summary: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** A run of consecutive lines owned by the same commit. */
|
|
22
|
+
export interface BlameRun {
|
|
23
|
+
from: number
|
|
24
|
+
to: number
|
|
25
|
+
hash: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** One `--follow` file-history row, plus the name the file had in that commit. */
|
|
29
|
+
export interface FileHistoryCommit extends GitCommit {
|
|
30
|
+
/** Path to show/diff for THIS commit (old name before a rename). */
|
|
31
|
+
path: string
|
|
32
|
+
/** Rename source when this commit renamed the file. */
|
|
33
|
+
origPath?: string
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const HEADER = /^([0-9a-f]{40,64}) \d+ (\d+)(?: \d+)?$/
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Parse `git blame --line-porcelain`.
|
|
40
|
+
*
|
|
41
|
+
* `--line-porcelain` repeats the commit header and metadata for every line (no
|
|
42
|
+
* previous-commit grouping), which keeps this parser stateless: a header starts
|
|
43
|
+
* a record, the metadata lines fill it, and the tab-prefixed content line ends
|
|
44
|
+
* it. Lines that do not match the shape are ignored rather than aborting the
|
|
45
|
+
* whole read — a partially understood blame is still useful.
|
|
46
|
+
*/
|
|
47
|
+
export function parseBlamePorcelain(stdout: string): BlameLine[] {
|
|
48
|
+
const rows: BlameLine[] = []
|
|
49
|
+
let current: {
|
|
50
|
+
hash: string
|
|
51
|
+
line: number
|
|
52
|
+
author?: string
|
|
53
|
+
email?: string
|
|
54
|
+
time?: number
|
|
55
|
+
summary?: string
|
|
56
|
+
} | undefined
|
|
57
|
+
for (const raw of stdout.split('\n')) {
|
|
58
|
+
const line = raw.endsWith('\r') ? raw.slice(0, -1) : raw
|
|
59
|
+
const header = HEADER.exec(line)
|
|
60
|
+
if (header !== null) {
|
|
61
|
+
current = { hash: header[1] as string, line: Number(header[2]) }
|
|
62
|
+
continue
|
|
63
|
+
}
|
|
64
|
+
if (current === undefined) continue
|
|
65
|
+
if (line.startsWith('\t')) {
|
|
66
|
+
rows.push({
|
|
67
|
+
line: current.line,
|
|
68
|
+
hash: current.hash,
|
|
69
|
+
author: current.author ?? '',
|
|
70
|
+
email: current.email ?? '',
|
|
71
|
+
time: current.time ?? 0,
|
|
72
|
+
summary: current.summary ?? '',
|
|
73
|
+
})
|
|
74
|
+
current = undefined
|
|
75
|
+
continue
|
|
76
|
+
}
|
|
77
|
+
const space = line.indexOf(' ')
|
|
78
|
+
if (space < 0) continue
|
|
79
|
+
const key = line.slice(0, space)
|
|
80
|
+
const value = line.slice(space + 1)
|
|
81
|
+
if (key === 'author') current.author = value
|
|
82
|
+
else if (key === 'author-mail') current.email = value.replace(/^<|>$/g, '')
|
|
83
|
+
else if (key === 'author-time') current.time = Number(value) || 0
|
|
84
|
+
else if (key === 'summary') current.summary = value
|
|
85
|
+
}
|
|
86
|
+
return rows
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Group consecutive lines of one commit; non-adjacent runs stay separate. */
|
|
90
|
+
export function blameRuns(rows: readonly BlameLine[]): BlameRun[] {
|
|
91
|
+
const runs: BlameRun[] = []
|
|
92
|
+
let previous: BlameLine | undefined
|
|
93
|
+
for (const row of rows) {
|
|
94
|
+
if (previous !== undefined && previous.hash === row.hash && previous.line + 1 === row.line) {
|
|
95
|
+
const run = runs[runs.length - 1]
|
|
96
|
+
if (run !== undefined) run.to = row.line
|
|
97
|
+
} else {
|
|
98
|
+
runs.push({ from: row.line, to: row.line, hash: row.hash })
|
|
99
|
+
}
|
|
100
|
+
previous = row
|
|
101
|
+
}
|
|
102
|
+
return runs
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Short author name for the narrow blame gutter. */
|
|
106
|
+
export function shortAuthor(author: string): string {
|
|
107
|
+
const name = author.trim()
|
|
108
|
+
if (name === '') return '?'
|
|
109
|
+
return name.length <= 10 ? name : `${name.slice(0, 9)}…`
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Relative age labels, deliberately compact (`now`, `5m`, `3h`, `2d`, `4w`,
|
|
114
|
+
* `3mo`, `2y`) because this text lives in a gutter.
|
|
115
|
+
*/
|
|
116
|
+
export function relativeBlameTime(timeSeconds: number, nowSeconds: number = Math.floor(Date.now() / 1000)): string {
|
|
117
|
+
if (!Number.isFinite(timeSeconds) || timeSeconds <= 0) return '?'
|
|
118
|
+
const diff = Math.max(0, nowSeconds - timeSeconds)
|
|
119
|
+
if (diff < 60) return 'now'
|
|
120
|
+
if (diff < 3600) return `${Math.floor(diff / 60)}m`
|
|
121
|
+
if (diff < 86_400) return `${Math.floor(diff / 3600)}h`
|
|
122
|
+
if (diff < 7 * 86_400) return `${Math.floor(diff / 86_400)}d`
|
|
123
|
+
if (diff < 30 * 86_400) return `${Math.floor(diff / (7 * 86_400))}w`
|
|
124
|
+
if (diff < 365 * 86_400) return `${Math.floor(diff / (30 * 86_400))}mo`
|
|
125
|
+
return `${Math.floor(diff / (365 * 86_400))}y`
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** One-line gutter label: author initials/name plus relative age. */
|
|
129
|
+
export function blameLabel(row: BlameLine, nowSeconds: number = Math.floor(Date.now() / 1000)): string {
|
|
130
|
+
return `${shortAuthor(row.author)} · ${relativeBlameTime(row.time, nowSeconds)}`
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Hover text: full attribution. The browser renders `title` as plain text, so
|
|
135
|
+
* no markup is needed (and no translator dependency leaks into the model).
|
|
136
|
+
*/
|
|
137
|
+
export function blameTitle(row: BlameLine): string {
|
|
138
|
+
const when = row.time > 0 ? new Date(row.time * 1000).toLocaleString() : 'unknown date'
|
|
139
|
+
const email = row.email === '' ? '' : `\n${row.email}`
|
|
140
|
+
return `${row.author || 'unknown author'}${email}\n${when}\n${row.hash}\n${row.summary}`.trim()
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** False for git's all-zero "not committed yet" pseudo-commit. */
|
|
144
|
+
export function isCommittedBlame(hash: string): boolean {
|
|
145
|
+
return !/^0{40,64}$/.test(hash)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* The next `-L` window to request, or undefined when the viewport is covered.
|
|
150
|
+
*
|
|
151
|
+
* Pure and exported so the gate can prove the "3000-line file only asks for
|
|
152
|
+
* the visible window" requirement without a browser. `overscan` keeps a small
|
|
153
|
+
* buffer above/below so a normal scroll does not immediately need a new call.
|
|
154
|
+
*/
|
|
155
|
+
export function planBlameWindow(
|
|
156
|
+
first: number,
|
|
157
|
+
last: number,
|
|
158
|
+
total: number,
|
|
159
|
+
covered: ReadonlySet<number>,
|
|
160
|
+
overscan = 40,
|
|
161
|
+
): { from: number; to: number } | undefined {
|
|
162
|
+
if (!Number.isFinite(first) || !Number.isFinite(last) || !Number.isFinite(total) || total < 1) return undefined
|
|
163
|
+
const from = Math.max(1, Math.min(first, total) - Math.max(0, Math.floor(overscan)))
|
|
164
|
+
const to = Math.min(total, Math.max(last, first) + Math.max(0, Math.floor(overscan)))
|
|
165
|
+
if (to < from) return undefined
|
|
166
|
+
for (let line = from; line <= to; line += 1) {
|
|
167
|
+
if (!covered.has(line)) return { from, to }
|
|
168
|
+
}
|
|
169
|
+
return undefined
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
interface NameStatusRow {
|
|
173
|
+
path: string
|
|
174
|
+
origPath?: string
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Parse one `--name-status` row; C/R rows carry an old path as well. */
|
|
178
|
+
function parseNameStatusRow(raw: string): NameStatusRow | undefined {
|
|
179
|
+
const fields = raw.split('\t')
|
|
180
|
+
if (fields.length < 2) return undefined
|
|
181
|
+
const status = fields[0] as string
|
|
182
|
+
const first = fields[1] as string
|
|
183
|
+
const second = fields[2] as string | undefined
|
|
184
|
+
const path = unquoteGitPath(second ?? first)
|
|
185
|
+
if (path === '') return undefined
|
|
186
|
+
const origPath = second === undefined ? undefined : unquoteGitPath(first)
|
|
187
|
+
return status.startsWith('R') || status.startsWith('C')
|
|
188
|
+
? { path, ...(origPath === undefined ? {} : { origPath }) }
|
|
189
|
+
: { path }
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Parse `git log --follow --name-status -M` output into per-commit rows.
|
|
194
|
+
*
|
|
195
|
+
* `--follow` reports the file under its name AT THAT COMMIT. Starting from the
|
|
196
|
+
* current name and walking newest→oldest, each rename row supplies the next
|
|
197
|
+
* (older) name, so a click on an old history row opens the right path instead
|
|
198
|
+
* of an empty diff for the current name.
|
|
199
|
+
*/
|
|
200
|
+
export function parseFileHistory(stdout: string, currentPath: string): FileHistoryCommit[] {
|
|
201
|
+
const commits: FileHistoryCommit[] = []
|
|
202
|
+
let wanted = currentPath
|
|
203
|
+
for (const block of stdout.split('\0')) {
|
|
204
|
+
const lines = block.replace(/^\r?\n/, '').split(/\r?\n/).filter(line => line.trim() !== '')
|
|
205
|
+
if (lines.length === 0) continue
|
|
206
|
+
const [hash, parents, author, email, date, refs, subject] = (lines[0] as string).split('\x1f') as [
|
|
207
|
+
string, string, string, string, string, string, string,
|
|
208
|
+
]
|
|
209
|
+
if (!/^[0-9a-f]{4,64}$/.test((hash ?? '').trim())) continue
|
|
210
|
+
const statuses = lines.slice(1).flatMap(line => {
|
|
211
|
+
const row = parseNameStatusRow(line)
|
|
212
|
+
return row === undefined ? [] : [row]
|
|
213
|
+
})
|
|
214
|
+
let path = wanted
|
|
215
|
+
let origPath: string | undefined
|
|
216
|
+
const rename = statuses.find(row => row.path === wanted && row.origPath !== undefined)
|
|
217
|
+
if (rename !== undefined) {
|
|
218
|
+
path = wanted
|
|
219
|
+
origPath = rename.origPath
|
|
220
|
+
wanted = rename.origPath as string
|
|
221
|
+
} else if (statuses.some(row => row.path === wanted)) {
|
|
222
|
+
path = wanted
|
|
223
|
+
} else if (statuses.length === 1) {
|
|
224
|
+
// A path-limited log normally has one status row; trust it when the
|
|
225
|
+
// rename chain did not line up (e.g. a merge or an unusual rename).
|
|
226
|
+
path = (statuses[0] as NameStatusRow).path
|
|
227
|
+
origPath = (statuses[0] as NameStatusRow).origPath
|
|
228
|
+
}
|
|
229
|
+
commits.push({
|
|
230
|
+
hash: (hash as string).trim(),
|
|
231
|
+
parents: (parents ?? '').trim() === '' ? [] : (parents as string).trim().split(' '),
|
|
232
|
+
author: (author ?? '').trim(),
|
|
233
|
+
email: (email ?? '').trim(),
|
|
234
|
+
date: Number(date) || 0,
|
|
235
|
+
refs: (refs ?? '').split(',').map(item => item.trim()).filter(item => item !== ''),
|
|
236
|
+
subject: (subject ?? '').trim(),
|
|
237
|
+
path,
|
|
238
|
+
...(origPath === undefined ? {} : { origPath }),
|
|
239
|
+
})
|
|
240
|
+
}
|
|
241
|
+
return commits
|
|
242
|
+
}
|