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
|
@@ -0,0 +1,216 @@
|
|
|
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 =
|
|
9
|
+
| 'text' | 'image' | 'markdown' | 'html' | 'svg' | 'table' | 'pdf' | 'office' | 'media'
|
|
10
|
+
|
|
11
|
+
const IMAGE_EXTENSIONS = new Set(['png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp', 'ico', 'avif'])
|
|
12
|
+
|
|
13
|
+
const KIND_BY_EXTENSION: Readonly<Record<string, PreviewKind>> = {
|
|
14
|
+
md: 'markdown', markdown: 'markdown', mdown: 'markdown', mkd: 'markdown', mdx: 'markdown',
|
|
15
|
+
html: 'html', htm: 'html', xhtml: 'html',
|
|
16
|
+
csv: 'table', tsv: 'table',
|
|
17
|
+
svg: 'svg',
|
|
18
|
+
pdf: 'pdf',
|
|
19
|
+
// Only the six extensions a LibreOffice/office-kit conversion can actually
|
|
20
|
+
// claim; odt/ods/odp/docm/... fall through to the binary notice instead of a
|
|
21
|
+
// guaranteed conversion error.
|
|
22
|
+
doc: 'office', docx: 'office', ppt: 'office', pptx: 'office', xls: 'office', xlsx: 'office',
|
|
23
|
+
mp3: 'media', wav: 'media', ogg: 'media', oga: 'media', opus: 'media', m4a: 'media',
|
|
24
|
+
aac: 'media', flac: 'media', weba: 'media', mp4: 'media', m4v: 'media', webm: 'media',
|
|
25
|
+
ogv: 'media', mov: 'media',
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const MEDIA_MIME: Readonly<Record<string, { kind: 'audio' | 'video'; mime: string }>> = {
|
|
29
|
+
mp3: { kind: 'audio', mime: 'audio/mpeg' },
|
|
30
|
+
wav: { kind: 'audio', mime: 'audio/wav' },
|
|
31
|
+
ogg: { kind: 'audio', mime: 'audio/ogg' },
|
|
32
|
+
oga: { kind: 'audio', mime: 'audio/ogg' },
|
|
33
|
+
opus: { kind: 'audio', mime: 'audio/ogg' },
|
|
34
|
+
m4a: { kind: 'audio', mime: 'audio/mp4' },
|
|
35
|
+
aac: { kind: 'audio', mime: 'audio/aac' },
|
|
36
|
+
flac: { kind: 'audio', mime: 'audio/flac' },
|
|
37
|
+
weba: { kind: 'audio', mime: 'audio/webm' },
|
|
38
|
+
mp4: { kind: 'video', mime: 'video/mp4' },
|
|
39
|
+
m4v: { kind: 'video', mime: 'video/mp4' },
|
|
40
|
+
webm: { kind: 'video', mime: 'video/webm' },
|
|
41
|
+
ogv: { kind: 'video', mime: 'video/ogg' },
|
|
42
|
+
mov: { kind: 'video', mime: 'video/quicktime' },
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function extensionOf(path: string): string {
|
|
46
|
+
const name = path.slice(Math.max(path.lastIndexOf('/'), path.lastIndexOf('\\')) + 1)
|
|
47
|
+
const dot = name.lastIndexOf('.')
|
|
48
|
+
return dot <= 0 ? '' : name.slice(dot + 1).toLowerCase()
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function previewKindOf(path: string): PreviewKind {
|
|
52
|
+
const ext = extensionOf(path)
|
|
53
|
+
if (IMAGE_EXTENSIONS.has(ext)) return 'image'
|
|
54
|
+
return Object.hasOwn(KIND_BY_EXTENSION, ext) ? KIND_BY_EXTENSION[ext] as PreviewKind : 'text'
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function isBytePreview(kind: PreviewKind): kind is 'pdf' | 'office' | 'media' {
|
|
58
|
+
return kind === 'pdf' || kind === 'office' || kind === 'media'
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function hasTextSource(kind: PreviewKind): boolean {
|
|
62
|
+
return kind === 'markdown' || kind === 'html' || kind === 'svg' || kind === 'table'
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function previewKindLabel(kind: PreviewKind): string | undefined {
|
|
66
|
+
const labels: Record<PreviewKind, string | undefined> = {
|
|
67
|
+
text: undefined,
|
|
68
|
+
image: 'Image',
|
|
69
|
+
markdown: 'Markdown',
|
|
70
|
+
html: 'HTML',
|
|
71
|
+
svg: 'SVG',
|
|
72
|
+
table: 'Table',
|
|
73
|
+
pdf: 'PDF',
|
|
74
|
+
office: 'Office',
|
|
75
|
+
media: 'Media',
|
|
76
|
+
}
|
|
77
|
+
return labels[kind]
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function mediaTypeOf(path: string): { kind: 'audio' | 'video'; mime: string } | undefined {
|
|
81
|
+
return MEDIA_MIME[extensionOf(path)]
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function tableDelimiterOf(path: string): string {
|
|
85
|
+
return extensionOf(path) === 'tsv' ? '\t' : ','
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface TableLimits {
|
|
89
|
+
maxRows: number
|
|
90
|
+
maxColumns: number
|
|
91
|
+
maxCells: number
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export const DEFAULT_TABLE_LIMITS: TableLimits = {
|
|
95
|
+
maxRows: 5000,
|
|
96
|
+
maxColumns: 512,
|
|
97
|
+
maxCells: 200_000,
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface TableData {
|
|
101
|
+
rows: string[][]
|
|
102
|
+
columns: number
|
|
103
|
+
truncated: boolean
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** RFC 4180 parser with explicit row/column/cell bounds. */
|
|
107
|
+
export function parseDelimited(
|
|
108
|
+
text: string,
|
|
109
|
+
delimiter: string,
|
|
110
|
+
limits: TableLimits = DEFAULT_TABLE_LIMITS,
|
|
111
|
+
): TableData {
|
|
112
|
+
if (limits.maxColumns <= 0 || limits.maxRows <= 0) {
|
|
113
|
+
return { rows: [], columns: 0, truncated: text.trim() !== '' }
|
|
114
|
+
}
|
|
115
|
+
const rows: string[][] = []
|
|
116
|
+
let row: string[] = []
|
|
117
|
+
let field = ''
|
|
118
|
+
let quoted = false
|
|
119
|
+
let columns = 0
|
|
120
|
+
let stoppedAt = -1
|
|
121
|
+
let dropped = false
|
|
122
|
+
let touched = false
|
|
123
|
+
|
|
124
|
+
const finishField = (): boolean => {
|
|
125
|
+
if (row.length >= limits.maxColumns) return false
|
|
126
|
+
row.push(field)
|
|
127
|
+
field = ''
|
|
128
|
+
touched = true
|
|
129
|
+
return true
|
|
130
|
+
}
|
|
131
|
+
const finishRow = (at: number): boolean => {
|
|
132
|
+
if (!finishField()) {
|
|
133
|
+
if (touched && rows.length < limits.maxRows) {
|
|
134
|
+
if (row.length > columns) columns = row.length
|
|
135
|
+
rows.push(row)
|
|
136
|
+
}
|
|
137
|
+
row = []
|
|
138
|
+
field = ''
|
|
139
|
+
touched = false
|
|
140
|
+
dropped = true
|
|
141
|
+
stoppedAt = at
|
|
142
|
+
return false
|
|
143
|
+
}
|
|
144
|
+
if (!touched || (row.length === 1 && row[0] === '')) {
|
|
145
|
+
row = []
|
|
146
|
+
touched = false
|
|
147
|
+
return true
|
|
148
|
+
}
|
|
149
|
+
if (rows.length >= limits.maxRows) {
|
|
150
|
+
dropped = true
|
|
151
|
+
stoppedAt = at
|
|
152
|
+
return false
|
|
153
|
+
}
|
|
154
|
+
if (rows.length > 0 && (rows.length + 1) * Math.max(columns, row.length) > limits.maxCells) {
|
|
155
|
+
dropped = true
|
|
156
|
+
stoppedAt = at
|
|
157
|
+
return false
|
|
158
|
+
}
|
|
159
|
+
if (row.length > columns) columns = row.length
|
|
160
|
+
rows.push(row)
|
|
161
|
+
row = []
|
|
162
|
+
touched = false
|
|
163
|
+
return true
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const source = text.charCodeAt(0) === 0xfeff ? text.slice(1) : text
|
|
167
|
+
for (let index = 0; index < source.length; index += 1) {
|
|
168
|
+
const char = source[index] as string
|
|
169
|
+
if (quoted) {
|
|
170
|
+
if (char === '"') {
|
|
171
|
+
if (source[index + 1] === '"') {
|
|
172
|
+
field += '"'
|
|
173
|
+
index += 1
|
|
174
|
+
} else {
|
|
175
|
+
quoted = false
|
|
176
|
+
}
|
|
177
|
+
} else {
|
|
178
|
+
field += char
|
|
179
|
+
}
|
|
180
|
+
continue
|
|
181
|
+
}
|
|
182
|
+
if (char === '"' && field === '') {
|
|
183
|
+
quoted = true
|
|
184
|
+
touched = true
|
|
185
|
+
continue
|
|
186
|
+
}
|
|
187
|
+
if (char === delimiter) {
|
|
188
|
+
if (!finishField()) {
|
|
189
|
+
if (touched && rows.length < limits.maxRows) {
|
|
190
|
+
if (row.length > columns) columns = row.length
|
|
191
|
+
rows.push(row)
|
|
192
|
+
}
|
|
193
|
+
row = []
|
|
194
|
+
field = ''
|
|
195
|
+
touched = false
|
|
196
|
+
dropped = true
|
|
197
|
+
stoppedAt = index
|
|
198
|
+
break
|
|
199
|
+
}
|
|
200
|
+
continue
|
|
201
|
+
}
|
|
202
|
+
if (char === '\r') {
|
|
203
|
+
if (source[index + 1] === '\n') index += 1
|
|
204
|
+
if (!finishRow(index)) break
|
|
205
|
+
continue
|
|
206
|
+
}
|
|
207
|
+
if (char === '\n') {
|
|
208
|
+
if (!finishRow(index)) break
|
|
209
|
+
continue
|
|
210
|
+
}
|
|
211
|
+
field += char
|
|
212
|
+
touched = true
|
|
213
|
+
}
|
|
214
|
+
if (stoppedAt === -1 && (touched || field !== '' || row.length > 0)) finishRow(source.length)
|
|
215
|
+
return { rows, columns, truncated: dropped }
|
|
216
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
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
|
+
|
|
13
|
+
export type PreviewFailureReason = 'unavailable' | 'too-large' | 'not-found' | 'remote' | 'failed'
|
|
14
|
+
|
|
15
|
+
export type PreviewBytesResult =
|
|
16
|
+
| { ok: true; data: Uint8Array; size: number }
|
|
17
|
+
| { ok: false; reason: PreviewFailureReason; detail: string }
|
|
18
|
+
|
|
19
|
+
type RemoteCallResult =
|
|
20
|
+
| { ok: true; value: { data: Uint8Array; bytes?: number } }
|
|
21
|
+
| { ok: false; error: { code?: unknown; message?: unknown; details?: unknown } }
|
|
22
|
+
|
|
23
|
+
interface WorkspaceFilesRemote {
|
|
24
|
+
readBytes?: (sessionId: string, path: string, options: Record<string, unknown>, signal?: AbortSignal) => Promise<RemoteCallResult>
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface OfficeKitRemote {
|
|
28
|
+
render?: (sessionId: string, path: string, priority: 'foreground' | 'background', signal?: AbortSignal) => Promise<RemoteCallResult>
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let rootCtx: Context | undefined
|
|
32
|
+
|
|
33
|
+
export function installPreviewServices(ctx: Context): () => void {
|
|
34
|
+
rootCtx = ctx
|
|
35
|
+
return () => {
|
|
36
|
+
if (rootCtx === ctx) rootCtx = undefined
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function remoteNamespace(name: string): Record<string, unknown> | undefined {
|
|
41
|
+
const ctx = rootCtx
|
|
42
|
+
if (ctx === undefined) return undefined
|
|
43
|
+
try {
|
|
44
|
+
const raw: unknown = (ctx as unknown as { get(service: string): unknown }).get(name)
|
|
45
|
+
return typeof raw === 'object' && raw !== null ? raw as Record<string, unknown> : undefined
|
|
46
|
+
} catch {
|
|
47
|
+
return undefined
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function failureReason(code: string, reason?: string): PreviewFailureReason {
|
|
52
|
+
const lowered = `${code} ${reason ?? ''}`.toLowerCase()
|
|
53
|
+
if (lowered.includes('too-large') || lowered.includes('too_large')) return 'too-large'
|
|
54
|
+
if (lowered.includes('workspace-file/not-found') || lowered.includes('not-regular-file')) return 'not-found'
|
|
55
|
+
if (lowered.includes('unavailable') || lowered.includes('missing')) return 'unavailable'
|
|
56
|
+
return 'failed'
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function toBytesResult(outcome: RemoteCallResult | undefined, fallbackDetail: string): PreviewBytesResult {
|
|
60
|
+
if (outcome === undefined) return { ok: false, reason: 'unavailable', detail: fallbackDetail }
|
|
61
|
+
if (outcome.ok) {
|
|
62
|
+
const data = outcome.value.data
|
|
63
|
+
if (!(data instanceof Uint8Array) || data.byteLength === 0) {
|
|
64
|
+
return { ok: false, reason: 'failed', detail: 'empty payload' }
|
|
65
|
+
}
|
|
66
|
+
return { ok: true, data, size: typeof outcome.value.bytes === 'number' ? outcome.value.bytes : data.byteLength }
|
|
67
|
+
}
|
|
68
|
+
const code = typeof outcome.error.code === 'string' ? outcome.error.code : ''
|
|
69
|
+
const message = typeof outcome.error.message === 'string' ? outcome.error.message : ''
|
|
70
|
+
const details = outcome.error.details
|
|
71
|
+
const reason = typeof details === 'object' && details !== null
|
|
72
|
+
&& typeof (details as { reason?: unknown }).reason === 'string'
|
|
73
|
+
? (details as { reason: string }).reason
|
|
74
|
+
: undefined
|
|
75
|
+
return {
|
|
76
|
+
ok: false,
|
|
77
|
+
reason: failureReason(code, reason),
|
|
78
|
+
detail: [code, reason, message].filter(part => typeof part === 'string' && part !== '').join(': '),
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export async function readWorkspaceBytes(
|
|
83
|
+
sessionId: string,
|
|
84
|
+
path: string,
|
|
85
|
+
signal?: AbortSignal,
|
|
86
|
+
): Promise<PreviewBytesResult> {
|
|
87
|
+
if (sessionId === '') return { ok: false, reason: 'unavailable', detail: 'no session' }
|
|
88
|
+
const service = remoteNamespace('remote.workspaceFiles') as WorkspaceFilesRemote | undefined
|
|
89
|
+
if (typeof service?.readBytes !== 'function') {
|
|
90
|
+
return { ok: false, reason: 'unavailable', detail: 'remote.workspaceFiles is not mounted' }
|
|
91
|
+
}
|
|
92
|
+
let outcome: RemoteCallResult
|
|
93
|
+
try {
|
|
94
|
+
outcome = await service.readBytes(sessionId, path, {}, signal)
|
|
95
|
+
} catch (error) {
|
|
96
|
+
return { ok: false, reason: 'failed', detail: error instanceof Error ? error.message : String(error) }
|
|
97
|
+
}
|
|
98
|
+
return toBytesResult(outcome, 'remote.workspaceFiles is not mounted')
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export async function renderOfficePdf(
|
|
102
|
+
sessionId: string,
|
|
103
|
+
path: string,
|
|
104
|
+
signal?: AbortSignal,
|
|
105
|
+
): Promise<PreviewBytesResult> {
|
|
106
|
+
if (sessionId === '') return { ok: false, reason: 'unavailable', detail: 'no session' }
|
|
107
|
+
const service = remoteNamespace('remote.officeKit') as OfficeKitRemote | undefined
|
|
108
|
+
if (typeof service?.render !== 'function') {
|
|
109
|
+
return { ok: false, reason: 'unavailable', detail: 'remote.officeKit is not mounted' }
|
|
110
|
+
}
|
|
111
|
+
let outcome: RemoteCallResult
|
|
112
|
+
try {
|
|
113
|
+
outcome = await service.render(sessionId, path, 'foreground', signal)
|
|
114
|
+
} catch (error) {
|
|
115
|
+
return { ok: false, reason: 'failed', detail: error instanceof Error ? error.message : String(error) }
|
|
116
|
+
}
|
|
117
|
+
return toBytesResult(outcome, 'remote.officeKit is not mounted')
|
|
118
|
+
}
|