dsh-remote 1.1.1 → 1.1.2
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 +3 -1
- package/README.md +3 -1
- package/lib/client.js +356 -54
- package/lib/index.js +21 -3
- package/lib/local-copy.js +129 -0
- package/lib/local-mutation.js +8 -0
- package/lib/mirror-paths.js +34 -0
- package/lib/routes-fs.js +13 -29
- package/lib/sftp-surface.js +16 -0
- package/package.json +2 -2
package/README.en.md
CHANGED
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
|
|
11
11
|
Maintained by [@flymysql](https://github.com/flymysql) · [Homepage](https://flymysql.github.io/dsh-remote/) · [Usage stats](https://flymysql.github.io/dsh-remote/stats/) · [Blog](https://gitpull.cn) · [Discussions](https://github.com/flymysql/dsh-remote/discussions) · [Issues](https://github.com/flymysql/dsh-remote/issues) · [中文说明](https://github.com/flymysql/dsh-remote/blob/main/README.md)
|
|
12
12
|
|
|
13
|
+

|
|
14
|
+
|
|
13
15
|
Turn SSH hosts into everyday development workspaces in [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness): browse remote files, edit code, run terminals and let the agent work on the same remote project. Multiple workspaces can use different hosts in parallel.
|
|
14
16
|
|
|
15
17
|
**IDE mode: files on the left, editor in the center, native agent conversation on the right.** Resize columns or switch panes on narrow screens. Returning to the normal layout keeps tasks and unsaved edits.
|
|
@@ -28,7 +30,7 @@ After installation or an upgrade, restart DSH Web and refresh the page. Check au
|
|
|
28
30
|
|
|
29
31
|
1. **Configure a host**: open Settings → Remote workspaces to edit SSH configuration or save credentials. Connectivity checks run automatically; no manual connection step is required.
|
|
30
32
|
2. **Create a workspace**: Add workspace → Remote, then choose a host and folder. Each workspace binds its own host; settings have no folder selection or global active host.
|
|
31
|
-
3. **Develop remotely**: open workspace files or enter IDE mode to edit, search, run commands and collaborate with the agent.
|
|
33
|
+
3. **Develop remotely**: open workspace files or enter IDE mode to edit with syntax highlighting, search, run commands and collaborate with the agent. Files open ready to edit.
|
|
32
34
|
|
|
33
35
|
<img src="https://raw.githubusercontent.com/flymysql/dsh-remote/main/docs/shots/workspace-picker-browse.png" alt="Remote folder picker with fixed path and confirmation controls and a large directory list" width="720"/>
|
|
34
36
|
|
package/README.md
CHANGED
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
|
|
11
11
|
由 [@flymysql](https://github.com/flymysql) 维护 · [主页](https://flymysql.github.io/dsh-remote/) · [用量统计](https://flymysql.github.io/dsh-remote/stats/) · [博客](https://gitpull.cn) · [讨论区](https://github.com/flymysql/dsh-remote/discussions) · [Issue](https://github.com/flymysql/dsh-remote/issues) · [English](https://github.com/flymysql/dsh-remote/blob/main/README.en.md)
|
|
12
12
|
|
|
13
|
+

|
|
14
|
+
|
|
13
15
|
在 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) 中,把 SSH 主机变成日常开发工作区:浏览远程文件、编辑代码、运行终端,让 Agent 在同一远端完成任务。多个工作区可并行连接不同主机。
|
|
14
16
|
|
|
15
17
|
**IDE 模式:左侧文件,中间编辑器,右侧原生 Agent 会话。** 可调整栏宽;窄屏切换文件、编辑器与会话。切回普通布局保留任务和未保存编辑。
|
|
@@ -28,7 +30,7 @@ dsh plugin --profile web add dsh-remote
|
|
|
28
30
|
|
|
29
31
|
1. **配置主机**:设置 → 远程工作区,编辑 SSH 配置或保存主机凭据;打开设置会自动检查连通性,无需手动“连接”。
|
|
30
32
|
2. **创建工作区**:添加工作区 → 远程,选择主机与目录。每个工作区独立绑定主机,设置页不选目录或“当前远程机”。
|
|
31
|
-
3. **开始开发**:打开工作区文件或切换 IDE
|
|
33
|
+
3. **开始开发**:打开工作区文件或切换 IDE 模式,文件打开即可编辑并显示语法高亮,在远端搜索、运行命令并与 Agent 协作。
|
|
32
34
|
|
|
33
35
|
<img src="https://raw.githubusercontent.com/flymysql/dsh-remote/main/docs/shots/workspace-picker-browse.png" alt="选择远程目录:固定路径与确认栏,目录列表占据弹窗主要区域" width="720"/>
|
|
34
36
|
|
package/lib/client.js
CHANGED
|
@@ -27,7 +27,7 @@ window.__ModuleLoader__.load({
|
|
|
27
27
|
|
|
28
28
|
const React = require('react')
|
|
29
29
|
const name = 'dsh-remote'
|
|
30
|
-
const CLIENT_VERSION = '1.1.
|
|
30
|
+
const CLIENT_VERSION = '1.1.2'
|
|
31
31
|
|
|
32
32
|
// ── optional host primitives ────────────────────────────────────────────
|
|
33
33
|
// Issue #74: a remote session's .md link must open over SFTP, NOT via the
|
|
@@ -153,6 +153,19 @@ window.__ModuleLoader__.load({
|
|
|
153
153
|
'changes.partialDiff': "差异较大,当前仅显示部分内容。",
|
|
154
154
|
'changes.chooseFile': "选择改动文件查看差异。",
|
|
155
155
|
|
|
156
|
+
'ide.welcome': '欢迎',
|
|
157
|
+
'ide.welcomeTitle': '远程开发工作区',
|
|
158
|
+
'ide.welcomeHint': '从左侧打开文件,即可在这里开始编辑。',
|
|
159
|
+
'ide.guideFiles': '浏览与搜索',
|
|
160
|
+
'ide.guideFilesHint': '在左侧展开目录,或搜索远端文件、目录和内容。',
|
|
161
|
+
'ide.guideEdit': '编辑与保存',
|
|
162
|
+
'ide.guideEditHint': '文件直接打开为可编辑状态。使用 Ctrl / ⌘ + S 保存到远端。',
|
|
163
|
+
'ide.guideAgent': '与 Agent 协作',
|
|
164
|
+
'ide.guideAgentHint': '在右侧描述任务,运行构建并核对输出;点击诊断可跳转源码。',
|
|
165
|
+
'ide.guideLayout': '调整工作空间',
|
|
166
|
+
'ide.guideLayoutHint': '拖动分隔线调整栏宽;窄屏可切换文件、编辑器和会话。',
|
|
167
|
+
'ide.documentation': '使用指南',
|
|
168
|
+
'ide.tools': '会话工具', 'ide.toolsHint': '展开或收起会话附加工具与连接信息',
|
|
156
169
|
'ide.enter': 'IDE 模式', 'ide.exit': '返回普通模式', 'ide.files': '文件',
|
|
157
170
|
'ide.editor': '编辑器', 'ide.chat': '会话', 'ide.openEditor': '打开编辑区',
|
|
158
171
|
'ide.chooseFile': '从左侧选择远程文件,在这里编辑。',
|
|
@@ -617,6 +630,7 @@ window.__ModuleLoader__.load({
|
|
|
617
630
|
'file.saveToRemote': '保存到远程',
|
|
618
631
|
'file.saving': '保存中…',
|
|
619
632
|
'file.cancel': '取消',
|
|
633
|
+
'file.discardChanges': '放弃更改',
|
|
620
634
|
'file.edit': '编辑',
|
|
621
635
|
'file.download': '下载',
|
|
622
636
|
'file.loading': '加载中…',
|
|
@@ -629,6 +643,11 @@ window.__ModuleLoader__.load({
|
|
|
629
643
|
'file.saveHint': 'Ctrl/⌘+S 保存',
|
|
630
644
|
'file.downloaded': '已下载到本地镜像{local}',
|
|
631
645
|
'file.downloadedAt': ': {path}',
|
|
646
|
+
'file.localCopyMissing': '远端没有此文件,但本地镜像中有同名副本。',
|
|
647
|
+
'file.localCopyHelp': '可先只读查看,确认后上传到远端。上传仅创建新文件,不覆盖已有文件。',
|
|
648
|
+
'file.localCopyView': '查看本地副本',
|
|
649
|
+
'file.localCopyPublish': '上传到远端并打开',
|
|
650
|
+
'file.localCopySource': '本地镜像副本 · 只读,尚未上传到远端',
|
|
632
651
|
'file.readFail': '远程读取失败: {msg}',
|
|
633
652
|
'file.listFail': '远程目录读取失败: {msg}',
|
|
634
653
|
// Issue #55: a file link in a remote Session cannot be mapped onto the
|
|
@@ -694,6 +713,19 @@ window.__ModuleLoader__.load({
|
|
|
694
713
|
'changes.partialDiff': "This diff is large; showing partial content.",
|
|
695
714
|
'changes.chooseFile': "Select a changed file to inspect its diff.",
|
|
696
715
|
|
|
716
|
+
'ide.welcome': 'Welcome',
|
|
717
|
+
'ide.welcomeTitle': 'Your remote development workspace',
|
|
718
|
+
'ide.welcomeHint': 'Open a file on the left to start editing here.',
|
|
719
|
+
'ide.guideFiles': 'Browse and search',
|
|
720
|
+
'ide.guideFilesHint': 'Expand folders on the left, or search remote files, folders and contents.',
|
|
721
|
+
'ide.guideEdit': 'Edit and save',
|
|
722
|
+
'ide.guideEditHint': 'Files open ready to edit. Use Ctrl / ⌘ + S to save to the remote host.',
|
|
723
|
+
'ide.guideAgent': 'Work with your agent',
|
|
724
|
+
'ide.guideAgentHint': 'Describe a task on the right, build and review output. Click diagnostics to open source.',
|
|
725
|
+
'ide.guideLayout': 'Arrange your workspace',
|
|
726
|
+
'ide.guideLayoutHint': 'Drag separators to resize columns. Switch panes on narrow screens.',
|
|
727
|
+
'ide.documentation': 'User guide',
|
|
728
|
+
'ide.tools': 'Chat tools', 'ide.toolsHint': 'Show or hide extra conversation tools and connection details',
|
|
697
729
|
'ide.enter': 'IDE mode', 'ide.exit': 'Return to standard mode', 'ide.files': 'Files',
|
|
698
730
|
'ide.editor': 'Editor', 'ide.chat': 'Chat', 'ide.openEditor': 'Open editor area',
|
|
699
731
|
'ide.chooseFile': 'Choose a remote file on the left to edit it here.',
|
|
@@ -1151,6 +1183,7 @@ window.__ModuleLoader__.load({
|
|
|
1151
1183
|
'file.saveToRemote': 'Save to remote',
|
|
1152
1184
|
'file.saving': 'Saving…',
|
|
1153
1185
|
'file.cancel': 'Cancel',
|
|
1186
|
+
'file.discardChanges': 'Discard changes',
|
|
1154
1187
|
'file.edit': 'Edit',
|
|
1155
1188
|
'file.download': 'Download',
|
|
1156
1189
|
'file.loading': 'Loading…',
|
|
@@ -1163,6 +1196,11 @@ window.__ModuleLoader__.load({
|
|
|
1163
1196
|
'file.saveHint': 'Ctrl/⌘+S to save',
|
|
1164
1197
|
'file.downloaded': 'Downloaded to local mirror{local}',
|
|
1165
1198
|
'file.downloadedAt': ': {path}',
|
|
1199
|
+
'file.localCopyMissing': 'This file is missing remotely. A copy exists in the local mirror.',
|
|
1200
|
+
'file.localCopyHelp': 'Preview the local copy, then upload it. Upload creates a new remote file and never replaces an existing file.',
|
|
1201
|
+
'file.localCopyView': 'View local copy',
|
|
1202
|
+
'file.localCopyPublish': 'Upload and open remotely',
|
|
1203
|
+
'file.localCopySource': 'Local mirror copy · Read only, not uploaded',
|
|
1166
1204
|
'file.readFail': 'Failed to read remote: {msg}',
|
|
1167
1205
|
'file.listFail': 'Failed to list remote directory: {msg}',
|
|
1168
1206
|
'file.markdown.copy': 'Copy',
|
|
@@ -1285,7 +1323,12 @@ window.__ModuleLoader__.load({
|
|
|
1285
1323
|
if (body) { opts.headers['Content-Type'] = 'application/json'; opts.body = JSON.stringify(body) }
|
|
1286
1324
|
const res = await fetch(apiPath(path), opts)
|
|
1287
1325
|
const data = await res.json().catch(() => ({}))
|
|
1288
|
-
if (!res.ok)
|
|
1326
|
+
if (!res.ok) {
|
|
1327
|
+
const error = new Error(trHostError((data && (data.error || data.message))) || 'HTTP ' + res.status)
|
|
1328
|
+
error.code = data?.code
|
|
1329
|
+
error.localCopy = data?.localCopy
|
|
1330
|
+
throw error
|
|
1331
|
+
}
|
|
1289
1332
|
return data
|
|
1290
1333
|
}
|
|
1291
1334
|
|
|
@@ -3991,7 +4034,9 @@ window.__ModuleLoader__.load({
|
|
|
3991
4034
|
|
|
3992
4035
|
function readRemoteFile(path, maxBytes, sessionId) {
|
|
3993
4036
|
return api('POST', '/dsh-remote/read', withSessionBody({ path, maxBytes }, sessionId)).catch((e) => {
|
|
3994
|
-
|
|
4037
|
+
const error = new Error(tr('file.readFail', { msg: ((e && e.message) || e) }))
|
|
4038
|
+
error.code = e?.code; error.localCopy = e?.localCopy
|
|
4039
|
+
throw error
|
|
3995
4040
|
})
|
|
3996
4041
|
}
|
|
3997
4042
|
|
|
@@ -4935,7 +4980,7 @@ window.__ModuleLoader__.load({
|
|
|
4935
4980
|
)
|
|
4936
4981
|
}
|
|
4937
4982
|
|
|
4938
|
-
// ── Remote file tab (
|
|
4983
|
+
// ── Remote file tab (live read, editable text and conflict-aware saves) ──
|
|
4939
4984
|
/**
|
|
4940
4985
|
* The host's MarkdownText reads chrome strings off `labels` while rendering
|
|
4941
4986
|
* fenced code blocks (`labels.code.*`) and footnotes (`labels.footnotes`),
|
|
@@ -4977,6 +5022,155 @@ window.__ModuleLoader__.load({
|
|
|
4977
5022
|
return { text: text.slice(0, lineStart) + indented + text.slice(blockEnd), start: Math.max(lineStart, start + firstAdjustment), end: Math.max(lineStart, end + adjustment) }
|
|
4978
5023
|
}
|
|
4979
5024
|
|
|
5025
|
+
// Keeps the native textarea as the editor: selection, IME, accessibility,
|
|
5026
|
+
// clipboard and the browser undo stack never depend on token DOM nodes.
|
|
5027
|
+
function HighlightedEditor(props) {
|
|
5028
|
+
const value = String(props.value ?? '')
|
|
5029
|
+
const lang = languageForPathFn ? languageForPathFn(props.path || '') : undefined
|
|
5030
|
+
const highlight = useCodeHighlighterFn ? useCodeHighlighterFn(lang) : null
|
|
5031
|
+
const lines = React.useMemo(() => value.split('\n'), [value])
|
|
5032
|
+
const large = value.length > 300000 || lines.length > 10000
|
|
5033
|
+
const tokenLines = React.useMemo(() => {
|
|
5034
|
+
if (!highlight || large) return null
|
|
5035
|
+
try {
|
|
5036
|
+
const result = highlight(value)
|
|
5037
|
+
if (!Array.isArray(result)) return null
|
|
5038
|
+
// Never hide native text behind stale, clipped or malformed tokens.
|
|
5039
|
+
if (!lines.every((line, index) => Array.isArray(result[index] || []) && (result[index] || []).every(token => token && typeof token.text === 'string') && (result[index] || []).map(token => token.text).join('') === line)) return null
|
|
5040
|
+
return result
|
|
5041
|
+
} catch { return null }
|
|
5042
|
+
}, [highlight, value, lines, large])
|
|
5043
|
+
const ownEditorRef = React.useRef(null)
|
|
5044
|
+
const paintRef = React.useRef(null)
|
|
5045
|
+
const gutterRef = React.useRef(null)
|
|
5046
|
+
const compositionRef = React.useRef(false)
|
|
5047
|
+
const publishedRef = React.useRef(0)
|
|
5048
|
+
const [composing, setComposing] = React.useState(false)
|
|
5049
|
+
const [metrics, setMetrics] = React.useState({ width: 0, gutterHeights: [] })
|
|
5050
|
+
const layoutEffect = React.useLayoutEffect || React.useEffect
|
|
5051
|
+
const lineHeight = 20
|
|
5052
|
+
const marked = new Set(props.matchingLines || [])
|
|
5053
|
+
const colored = !!tokenLines && !composing
|
|
5054
|
+
const paintText = !composing && !large
|
|
5055
|
+
const typography = {
|
|
5056
|
+
fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Consolas, monospace', fontSize: 13,
|
|
5057
|
+
lineHeight: lineHeight + 'px', fontWeight: 400, fontStyle: 'normal', fontVariantLigatures: 'none',
|
|
5058
|
+
fontKerning: 'none', fontFeatureSettings: '"liga" 0, "calt" 0', letterSpacing: 0,
|
|
5059
|
+
tabSize: 2, textIndent: 0, textAlign: 'left', textTransform: 'none', direction: 'ltr',
|
|
5060
|
+
whiteSpace: props.wrap ? 'pre-wrap' : 'pre', overflowWrap: props.wrap ? 'anywhere' : 'normal', wordBreak: 'normal',
|
|
5061
|
+
}
|
|
5062
|
+
const syncScroll = node => {
|
|
5063
|
+
if (paintRef.current) paintRef.current.style.transform = 'translate(' + (-node.scrollLeft) + 'px,' + (-node.scrollTop) + 'px)'
|
|
5064
|
+
if (gutterRef.current) gutterRef.current.style.transform = 'translateY(' + (-node.scrollTop) + 'px)'
|
|
5065
|
+
}
|
|
5066
|
+
const publish = event => { publishedRef.current++; props.onChange?.(event) }
|
|
5067
|
+
const notifySelection = node => props.onSelect?.({ currentTarget: node, target: node })
|
|
5068
|
+
const measure = () => {
|
|
5069
|
+
const node = ownEditorRef.current, paint = paintRef.current
|
|
5070
|
+
if (!node || !paint) return
|
|
5071
|
+
const heights = Array.from(paint.children, row => row.getBoundingClientRect().height)
|
|
5072
|
+
setMetrics(previous => previous.width === node.clientWidth && previous.gutterHeights.length === heights.length && heights.every((height, index) => height === previous.gutterHeights[index])
|
|
5073
|
+
? previous : { width: node.clientWidth, gutterHeights: heights })
|
|
5074
|
+
syncScroll(node)
|
|
5075
|
+
}
|
|
5076
|
+
layoutEffect(() => {
|
|
5077
|
+
const node = ownEditorRef.current
|
|
5078
|
+
measure()
|
|
5079
|
+
if (!node || typeof ResizeObserver !== 'function') return undefined
|
|
5080
|
+
const observer = new ResizeObserver(measure)
|
|
5081
|
+
observer.observe(node)
|
|
5082
|
+
if (paintRef.current) observer.observe(paintRef.current)
|
|
5083
|
+
return () => observer.disconnect()
|
|
5084
|
+
}, [])
|
|
5085
|
+
layoutEffect(measure, [value, props.wrap, tokenLines, metrics.width])
|
|
5086
|
+
const revealLine = (requested, select) => {
|
|
5087
|
+
const node = ownEditorRef.current, paint = paintRef.current
|
|
5088
|
+
if (!node || !paint || !Number.isFinite(Number(requested))) return
|
|
5089
|
+
const number = Math.max(1, Math.min(lines.length, Math.trunc(Number(requested))))
|
|
5090
|
+
const row = paint.children[number - 1]
|
|
5091
|
+
if (select) {
|
|
5092
|
+
const offset = lines.slice(0, number - 1).reduce((sum, line) => sum + line.length + 1, 0)
|
|
5093
|
+
try { node.focus({ preventScroll: true }) } catch { node.focus() }
|
|
5094
|
+
node.setSelectionRange(offset, offset)
|
|
5095
|
+
notifySelection(node)
|
|
5096
|
+
}
|
|
5097
|
+
node.scrollTop = Math.max(0, (row ? row.offsetTop : 10 + (number - 1) * lineHeight) - (node.clientHeight - (row ? row.offsetHeight : lineHeight)) / 2)
|
|
5098
|
+
if (select) node.scrollLeft = 0
|
|
5099
|
+
syncScroll(node)
|
|
5100
|
+
props.onScroll?.({ currentTarget: node, target: node })
|
|
5101
|
+
}
|
|
5102
|
+
layoutEffect(() => {
|
|
5103
|
+
const node = ownEditorRef.current
|
|
5104
|
+
if (!node) return undefined
|
|
5105
|
+
node.dshScrollToLine = line => revealLine(line, false)
|
|
5106
|
+
return () => { delete node.dshScrollToLine }
|
|
5107
|
+
}, [value, props.wrap])
|
|
5108
|
+
layoutEffect(() => {
|
|
5109
|
+
if (!props.jumpLine) return undefined
|
|
5110
|
+
const schedule = typeof requestAnimationFrame === 'function' ? requestAnimationFrame : callback => setTimeout(callback, 0)
|
|
5111
|
+
const cancel = typeof cancelAnimationFrame === 'function' ? cancelAnimationFrame : clearTimeout
|
|
5112
|
+
const frame = schedule(() => revealLine(props.jumpLine, true))
|
|
5113
|
+
return () => cancel(frame)
|
|
5114
|
+
}, [props.path, props.jumpLine, props.jumpRevision])
|
|
5115
|
+
layoutEffect(() => { if (props.currentMatchLine) revealLine(props.currentMatchLine, false) }, [props.currentMatchLine])
|
|
5116
|
+
const indentSelection = (node, reverse) => {
|
|
5117
|
+
const transform = props.indent || indentRemoteDraft
|
|
5118
|
+
const result = transform(node.value, node.selectionStart, node.selectionEnd, reverse)
|
|
5119
|
+
if (result.text === node.value) return
|
|
5120
|
+
// Replace only the changed range. Native insertText records a genuine
|
|
5121
|
+
// editing transaction; assigning .value would discard browser undo.
|
|
5122
|
+
const before = node.value
|
|
5123
|
+
let from = 0, oldEnd = before.length, newEnd = result.text.length
|
|
5124
|
+
while (from < oldEnd && from < newEnd && before[from] === result.text[from]) from++
|
|
5125
|
+
while (oldEnd > from && newEnd > from && before[oldEnd - 1] === result.text[newEnd - 1]) { oldEnd--; newEnd-- }
|
|
5126
|
+
const published = publishedRef.current
|
|
5127
|
+
node.setSelectionRange(from, oldEnd)
|
|
5128
|
+
let inserted = false
|
|
5129
|
+
try { inserted = document.execCommand('insertText', false, result.text.slice(from, newEnd)) } catch { /* unsupported browser */ }
|
|
5130
|
+
if (!inserted || node.value !== result.text) node.setRangeText(result.text.slice(from, newEnd), from, oldEnd, 'end')
|
|
5131
|
+
// execCommand fires React's input event on supported browsers. The
|
|
5132
|
+
// fallback must publish explicitly, without emitting a duplicate edit.
|
|
5133
|
+
if (publishedRef.current === published) publish({ currentTarget: node, target: node })
|
|
5134
|
+
node.setSelectionRange(result.start, result.end)
|
|
5135
|
+
notifySelection(node)
|
|
5136
|
+
syncScroll(node)
|
|
5137
|
+
}
|
|
5138
|
+
return React.createElement('div', {
|
|
5139
|
+
'data-rw-highlight-editor': '', 'data-rw-editor-highlighted': colored ? 'true' : 'false',
|
|
5140
|
+
style: { position: 'relative', flex: 1, minHeight: 0, minWidth: 0, display: 'flex', overflow: 'hidden', ...typography, background: 'transparent' },
|
|
5141
|
+
},
|
|
5142
|
+
React.createElement('style', {}, '[data-rw-editor-input]::selection{background:rgba(74,144,226,.32);color:inherit;-webkit-text-fill-color:inherit}'),
|
|
5143
|
+
React.createElement('div', { 'aria-hidden': true, 'data-rw-editor-gutter': '', style: { display: large ? 'none' : undefined, flex: '0 0 ' + (Math.max(3, String(lines.length).length) + 2) + 'ch', overflow: 'hidden', borderRight: '1px solid ' + T.border, color: T.muted, userSelect: 'none', ...typography } },
|
|
5144
|
+
React.createElement('div', { ref: gutterRef, style: { paddingTop: 10, paddingBottom: 10 } }, (large ? [] : lines).map((_, index) => React.createElement('div', { key: index, style: { height: metrics.gutterHeights[index] || lineHeight, textAlign: 'right', paddingRight: 10, boxSizing: 'border-box' } }, index + 1)))),
|
|
5145
|
+
React.createElement('div', { style: { position: 'relative', flex: 1, minWidth: 0, minHeight: 0, overflow: 'hidden' } },
|
|
5146
|
+
React.createElement('pre', { ref: paintRef, 'aria-hidden': true, 'data-rw-editor-paint': '', style: { ...typography, position: 'absolute', left: 0, top: 0, margin: 0, border: 0, padding: '10px 12px', boxSizing: 'border-box', width: metrics.width || '100%', pointerEvents: 'none', visibility: paintText ? 'visible' : 'hidden', color: T.label } },
|
|
5147
|
+
(large ? [] : lines).map((line, index) => React.createElement('span', {
|
|
5148
|
+
key: index + (Number(props.jumpLine) === index + 1 ? '-jump-' + String(props.jumpRevision || 0) : ''),
|
|
5149
|
+
'data-line': index + 1, 'data-rw-editor-line': index + 1,
|
|
5150
|
+
className: [Number(props.jumpLine) === index + 1 ? 'dsh-rw-line-flash' : '', props.currentMatchLine === index + 1 ? 'dsh-rw-code-current' : marked.has(index + 1) ? 'dsh-rw-code-hit' : ''].filter(Boolean).join(' ') || undefined,
|
|
5151
|
+
style: { display: 'block', minHeight: lineHeight, ...typography },
|
|
5152
|
+
}, tokenLines && tokenLines[index]?.length
|
|
5153
|
+
? tokenLines[index].map((token, tokenIndex) => React.createElement('span', { key: tokenIndex, 'data-rw-editor-token': '', style: { color: token.style?.color || T.label } }, token.text))
|
|
5154
|
+
: line || '\u200b'))),
|
|
5155
|
+
React.createElement('textarea', {
|
|
5156
|
+
ref: node => { ownEditorRef.current = node; if (typeof props.editorRef === 'function') props.editorRef(node); else if (props.editorRef) props.editorRef.current = node },
|
|
5157
|
+
'data-rw-editor-input': '', 'aria-label': props['aria-label'], value, wrap: props.wrap ? 'soft' : 'off',
|
|
5158
|
+
spellCheck: false, autoCorrect: 'off', autoCapitalize: 'off', autoComplete: 'off',
|
|
5159
|
+
onChange: publish, onSelect: props.onSelect,
|
|
5160
|
+
onScroll: event => { syncScroll(event.currentTarget); props.onScroll?.(event) },
|
|
5161
|
+
onCompositionStart: () => { compositionRef.current = true; setComposing(true) },
|
|
5162
|
+
onCompositionEnd: event => { compositionRef.current = false; setComposing(false); publish(event) },
|
|
5163
|
+
onKeyDown: event => {
|
|
5164
|
+
if (compositionRef.current || event.isComposing || event.nativeEvent?.isComposing) return
|
|
5165
|
+
if (event.key === 'Tab') { event.preventDefault(); indentSelection(event.currentTarget, event.shiftKey); return }
|
|
5166
|
+
props.onKeyDown?.(event)
|
|
5167
|
+
},
|
|
5168
|
+
style: { ...typography, position: 'absolute', inset: 0, width: '100%', height: '100%', padding: '10px 12px', boxSizing: 'border-box', border: 0, outline: 'none', margin: 0, resize: 'none', background: 'transparent', color: paintText ? 'transparent' : T.label, WebkitTextFillColor: paintText ? 'transparent' : T.label, caretColor: T.label, overflow: 'auto' },
|
|
5169
|
+
}),
|
|
5170
|
+
),
|
|
5171
|
+
)
|
|
5172
|
+
}
|
|
5173
|
+
|
|
4980
5174
|
const remoteDrafts = new Map()
|
|
4981
5175
|
const pendingFileSaves = new Map()
|
|
4982
5176
|
function RemoteFileTab(props) {
|
|
@@ -4986,6 +5180,11 @@ window.__ModuleLoader__.load({
|
|
|
4986
5180
|
const [data, setData] = React.useState(() => fileViewMemory.get(String(fileSessionId || '') + '\0' + path)?.data || null)
|
|
4987
5181
|
const [err, setErr] = React.useState('')
|
|
4988
5182
|
const [loading, setLoading] = React.useState(true)
|
|
5183
|
+
const [localCopy, setLocalCopy] = React.useState(null)
|
|
5184
|
+
const [localPreview, setLocalPreview] = React.useState(null)
|
|
5185
|
+
const [copyBusy, setCopyBusy] = React.useState(false)
|
|
5186
|
+
const copyRequestRef = React.useRef(null)
|
|
5187
|
+
const copyGenerationRef = React.useRef(0)
|
|
4989
5188
|
const [edit, setEdit] = React.useState(false)
|
|
4990
5189
|
const [draft, setDraft] = React.useState('')
|
|
4991
5190
|
const [saving, setSaving] = React.useState(false)
|
|
@@ -5000,7 +5199,7 @@ window.__ModuleLoader__.load({
|
|
|
5000
5199
|
const remoteTerminal = useRemoteTerminal(fileSessionId)
|
|
5001
5200
|
const cachedView = fileViewMemory.get(draftKey)
|
|
5002
5201
|
const [wrap, setWrap] = React.useState(() => !!cachedView?.wrap)
|
|
5003
|
-
const [sourceMode, setSourceMode] = React.useState(() =>
|
|
5202
|
+
const [sourceMode, setSourceMode] = React.useState(() => cachedView?.sourceMode !== false)
|
|
5004
5203
|
const [findOpen, setFindOpen] = React.useState(false)
|
|
5005
5204
|
const [findQuery, setFindQuery] = React.useState('')
|
|
5006
5205
|
const [findIndex, setFindIndex] = React.useState(0)
|
|
@@ -5013,14 +5212,14 @@ window.__ModuleLoader__.load({
|
|
|
5013
5212
|
React.useEffect(() => () => { if (copyTimerRef.current) clearTimeout(copyTimerRef.current) }, [])
|
|
5014
5213
|
React.useEffect(() => {
|
|
5015
5214
|
const view = fileViewMemory.get(draftKey)
|
|
5016
|
-
setWrap(!!view?.wrap); setSourceMode(
|
|
5215
|
+
setWrap(!!view?.wrap); setSourceMode(view?.sourceMode !== false)
|
|
5017
5216
|
setFindOpen(false); setFindQuery(''); setFindIndex(0)
|
|
5018
5217
|
rememberRemoteSelection(fileSessionId, path)
|
|
5019
5218
|
}, [draftKey])
|
|
5020
5219
|
React.useEffect(() => { if (findOpen) { findRef.current?.focus(); findRef.current?.select() } }, [findOpen])
|
|
5021
5220
|
React.useEffect(() => {
|
|
5022
5221
|
if (loading || props.jumpLine) return
|
|
5023
|
-
const node = scrollRef.current
|
|
5222
|
+
const node = editorRef.current || scrollRef.current
|
|
5024
5223
|
const view = fileViewMemory.get(draftKey)
|
|
5025
5224
|
if (node && view) { node.scrollTop = view.scrollTop || 0; node.scrollLeft = view.scrollLeft || 0 }
|
|
5026
5225
|
}, [loading, draftKey])
|
|
@@ -5039,7 +5238,13 @@ window.__ModuleLoader__.load({
|
|
|
5039
5238
|
}
|
|
5040
5239
|
const showExplorer = () => {
|
|
5041
5240
|
rememberRemoteSelection(fileSessionId, path)
|
|
5042
|
-
if (SIDEBAR_RIGHT?.
|
|
5241
|
+
if (remoteIdeState.enabled && SIDEBAR_RIGHT?.mounted?.getSnapshot?.() === fileSessionId) {
|
|
5242
|
+
const rows = document.querySelectorAll?.('[data-rw-ide-tree] [data-rw-tree-row]') || []
|
|
5243
|
+
const row = Array.from(rows).find(node => node.getAttribute('data-rw-tree-row') === path) || rows[0]
|
|
5244
|
+
row?.focus(); return
|
|
5245
|
+
}
|
|
5246
|
+
if (SIDEBAR_RIGHT?.openTabIn) SIDEBAR_RIGHT.openTabIn(fileSessionId, NATIVE_EXPLORER)
|
|
5247
|
+
else if (SIDEBAR_RIGHT?.openTab) SIDEBAR_RIGHT.openTab(NATIVE_EXPLORER)
|
|
5043
5248
|
}
|
|
5044
5249
|
const updateCursor = (node) => {
|
|
5045
5250
|
const before = node.value.slice(0, node.selectionStart)
|
|
@@ -5050,7 +5255,7 @@ window.__ModuleLoader__.load({
|
|
|
5050
5255
|
const saveTokenRef = React.useRef(null)
|
|
5051
5256
|
const discardDraft = async (reload) => {
|
|
5052
5257
|
if (dirty && !(await discardConfirm.ask(tr('file.discardConfirm')))) return
|
|
5053
|
-
remoteDrafts.delete(draftKey); setEdit(
|
|
5258
|
+
remoteDrafts.delete(draftKey); setDraft(originalText); setEdit(!!data && !data.binary && !data.image && !data.truncated); setErr(''); setSaveConflict(false)
|
|
5054
5259
|
if (reload === true) load()
|
|
5055
5260
|
}
|
|
5056
5261
|
const changeDraft = (text) => {
|
|
@@ -5079,27 +5284,57 @@ window.__ModuleLoader__.load({
|
|
|
5079
5284
|
footnotes: tr('file.markdown.footnotes'),
|
|
5080
5285
|
}
|
|
5081
5286
|
|
|
5082
|
-
const originalText = (data && data.content != null ? data.content : '').replace(/\n…\[truncated:.*$/, '')
|
|
5287
|
+
const originalText = (data && data.content != null ? data.content : '').replace(/\n…\[truncated:.*$/, '').replace(/\r\n/g, '\n')
|
|
5083
5288
|
const dirty = edit && draft !== originalText
|
|
5084
5289
|
|
|
5085
5290
|
const load = () => {
|
|
5291
|
+
if (props.visible === false) return
|
|
5086
5292
|
if (!path) { setLoading(false); return }
|
|
5087
5293
|
let cancelled = false
|
|
5088
|
-
|
|
5294
|
+
const cached = fileViewMemory.get(draftKey)?.data || null
|
|
5295
|
+
const generation = ++copyGenerationRef.current; copyRequestRef.current = null
|
|
5296
|
+
setLocalCopy(null); setLocalPreview(null); setCopyBusy(false)
|
|
5297
|
+
setLoading(true); setErr(''); setData(cached); setEdit(!!cached && !cached.binary && !cached.image && !cached.truncated); setSaveConflict(false)
|
|
5298
|
+
setDraft(remoteDrafts.get(draftKey)?.text ?? String(cached?.content || '').replace(/\r\n/g, '\n'))
|
|
5089
5299
|
readRemoteFile(path, 256 * 1024, fileSessionId)
|
|
5090
|
-
.then((d) => { if (!cancelled && fileViewRef.current === draftKey) {
|
|
5300
|
+
.then((d) => { if (!cancelled && fileViewRef.current === draftKey && copyGenerationRef.current === generation) {
|
|
5091
5301
|
keepView({ data: d }); setData(d); setLoading(false)
|
|
5092
5302
|
const saved = remoteDrafts.get(draftKey)
|
|
5093
5303
|
if (saved) { setDraft(saved.text); setEdit(true); setSaveConflict(!!d.truncated || (saved.baseMtime != null && d.mtime !== saved.baseMtime) || (saved.baseRevision != null && saved.baseRevision !== d.revision)) }
|
|
5304
|
+
else { setDraft(String(d.content || '').replace(/\r\n/g, '\n')); setEdit(!d.binary && !d.image && !d.truncated && typeof d.content === 'string') }
|
|
5305
|
+
} })
|
|
5306
|
+
.catch((e) => { if (!cancelled && fileViewRef.current === draftKey && copyGenerationRef.current === generation) {
|
|
5307
|
+
if (e?.code === 'REMOTE_FILE_MISSING_LOCAL_COPY' && e.localCopy?.available) {
|
|
5308
|
+
setLocalCopy(e.localCopy); setData(null); setEdit(false); keepView({ data: null }); setErr('')
|
|
5309
|
+
} else setErr(String((e && e.message) || e))
|
|
5310
|
+
setLoading(false)
|
|
5094
5311
|
} })
|
|
5095
|
-
.catch((e) => { if (!cancelled && fileViewRef.current === draftKey) { setErr(String((e && e.message) || e)); setLoading(false) } })
|
|
5096
5312
|
return () => { cancelled = true }
|
|
5097
5313
|
}
|
|
5098
|
-
React.useEffect(load, [path, fileSessionId, props.navigationRevision])
|
|
5314
|
+
React.useEffect(load, [path, fileSessionId, props.navigationRevision, props.visible])
|
|
5315
|
+
|
|
5316
|
+
const recoverLocalCopy = async (publish) => {
|
|
5317
|
+
if (!fileSessionId || copyRequestRef.current || (publish && !localPreview?.localRevision)) return
|
|
5318
|
+
const request = { key: draftKey, generation: copyGenerationRef.current }
|
|
5319
|
+
const isCurrent = () => fileViewRef.current === draftKey && copyRequestRef.current === request && copyGenerationRef.current === request.generation
|
|
5320
|
+
copyRequestRef.current = request
|
|
5321
|
+
setCopyBusy(true); setErr('')
|
|
5322
|
+
try {
|
|
5323
|
+
const result = await api('POST', '/dsh-remote/local-copy/' + (publish ? 'publish' : 'read'),
|
|
5324
|
+
withSessionBody({ path, ...(publish ? { expectedLocalRevision: localPreview.localRevision } : {}) }, fileSessionId))
|
|
5325
|
+
if (!isCurrent()) return
|
|
5326
|
+
if (publish) { setLocalCopy(null); setLocalPreview(null); load() }
|
|
5327
|
+
else setLocalPreview(result)
|
|
5328
|
+
} catch (error) {
|
|
5329
|
+
if (isCurrent()) setErr(String(error?.message || error))
|
|
5330
|
+
} finally {
|
|
5331
|
+
if (isCurrent()) { copyRequestRef.current = null; setCopyBusy(false) }
|
|
5332
|
+
}
|
|
5333
|
+
}
|
|
5099
5334
|
|
|
5100
5335
|
const startEdit = () => {
|
|
5101
5336
|
if (!data || data.binary || data.image || data.truncated) return
|
|
5102
|
-
setDraft((data.content != null ? data.content : '').replace(/\n…\[truncated:.*$/, ''))
|
|
5337
|
+
setDraft((data.content != null ? data.content : '').replace(/\n…\[truncated:.*$/, '').replace(/\r\n/g, '\n'))
|
|
5103
5338
|
setEdit(true); setErr(''); setSaveConflict(false)
|
|
5104
5339
|
}
|
|
5105
5340
|
const saveRemote = () => {
|
|
@@ -5127,7 +5362,7 @@ window.__ModuleLoader__.load({
|
|
|
5127
5362
|
if (fileViewRef.current !== draftKey) return
|
|
5128
5363
|
setCopyNote(tr(newerDraft ? 'workbench.savedWithDraft' : 'workbench.saved'))
|
|
5129
5364
|
if (newerDraft) { setData(savedData); setDraft(latest.text); setEdit(true); setSaveConflict(false) }
|
|
5130
|
-
else { setEdit(
|
|
5365
|
+
else { setData(savedData); setDraft(submittedText); setEdit(true); setSaveConflict(false) }
|
|
5131
5366
|
})
|
|
5132
5367
|
.catch((e) => { if (fileViewRef.current === draftKey) setErr(String((e && e.message) || e)) })
|
|
5133
5368
|
.finally(() => { if (pendingFileSaves.get(draftKey) === request) pendingFileSaves.delete(draftKey); if (saveTokenRef.current === draftKey) saveTokenRef.current = null; if (fileViewRef.current === draftKey) setSaving(false) })
|
|
@@ -5160,6 +5395,7 @@ window.__ModuleLoader__.load({
|
|
|
5160
5395
|
if (!findOpen || !activeMatch) return
|
|
5161
5396
|
if (edit && editorRef.current) {
|
|
5162
5397
|
editorRef.current.setSelectionRange(activeMatch.start, activeMatch.end)
|
|
5398
|
+
editorRef.current.dshScrollToLine?.(activeMatch.line)
|
|
5163
5399
|
} else {
|
|
5164
5400
|
scrollRef.current?.querySelector('[data-line="' + activeMatch.line + '"]')?.scrollIntoView({ block: 'center' })
|
|
5165
5401
|
}
|
|
@@ -5180,15 +5416,15 @@ window.__ModuleLoader__.load({
|
|
|
5180
5416
|
React.createElement(WorkbenchAction, { icon: 'terminal', label: tr('workbench.openTerminal'), disabled: remoteTerminal.pending, onClick: remoteTerminal.open }),
|
|
5181
5417
|
edit ? React.createElement(React.Fragment, null,
|
|
5182
5418
|
React.createElement('button', { type: 'button', className: 'dsh-rw-btn dsh-rw-primary', style: { ...primaryBtnS, padding: '4px 10px', fontSize: 12 }, onClick: saveRemote, disabled: saving || !dirty || saveConflict, title: tr('file.saveHint') }, saving ? tr('file.saving') : tr('file.saveToRemote')),
|
|
5183
|
-
React.createElement('button', { type: 'button', className: 'dsh-rw-btn', style: { ...buttonS, padding: '4px 8px', fontSize: 12 }, onClick: () => discardDraft(false) }, tr('file.
|
|
5184
|
-
: React.createElement('button', { type: 'button', className: 'dsh-rw-btn', style: { ...buttonS, padding: '4px 10px', fontSize: 12 }, onClick: startEdit, disabled: loading || !data || data.binary || data.image || data.truncated, title: data && data.truncated ? tr('file.incompletePreview') : tr('file.edit') }, tr('file.edit')),
|
|
5419
|
+
React.createElement('button', { type: 'button', className: 'dsh-rw-btn', style: { ...buttonS, padding: '4px 8px', fontSize: 12 }, onClick: () => discardDraft(false), disabled: !dirty || saving }, tr('file.discardChanges')))
|
|
5420
|
+
: React.createElement('button', { type: 'button', className: 'dsh-rw-btn', style: { ...buttonS, padding: '4px 10px', fontSize: 12 }, onClick: startEdit, disabled: loading || !!localCopy || !data || data.binary || data.image || data.truncated, title: data && data.truncated ? tr('file.incompletePreview') : tr('file.edit') }, tr('file.edit')),
|
|
5185
5421
|
),
|
|
5186
5422
|
React.createElement('div', { style: { display: 'flex', alignItems: 'center', gap: 6, padding: '4px 10px', borderBottom: '1px solid ' + T.border } },
|
|
5187
5423
|
React.createElement(WorkbenchAction, { icon: 'folder', label: tr('workbench.backToFiles'), onClick: showExplorer }),
|
|
5188
5424
|
React.createElement('span', { className: 'dsh-rw-path', style: { flex: 1 }, title: path }, path),
|
|
5189
5425
|
React.createElement(WorkbenchAction, { icon: 'copy', label: tr('workbench.copyPath'), onClick: () => copy(path) }),
|
|
5190
|
-
|
|
5191
|
-
isMarkdown
|
|
5426
|
+
React.createElement(WorkbenchAction, { icon: 'refresh', label: tr('explorer.refresh'), disabled: loading || saving, onClick: load }),
|
|
5427
|
+
isMarkdown ? React.createElement('button', { type: 'button', className: 'dsh-rw-btn', style: { ...buttonS, padding: '3px 8px', fontSize: 11 }, onClick: () => { setSourceMode(!sourceMode); keepView({ sourceMode: !sourceMode }) } }, sourceMode ? tr('workbench.preview') : tr('workbench.source')) : null),
|
|
5192
5428
|
findOpen ? React.createElement('div', { style: { display: 'flex', gap: 4, alignItems: 'center', padding: '6px 10px', borderBottom: '1px solid ' + T.border, background: T.bg } },
|
|
5193
5429
|
React.createElement('input', { ref: findRef, className: 'dsh-rw-input', 'aria-label': tr('workbench.find'), placeholder: tr('workbench.find'), value: findQuery, onChange: (e) => setFindQuery(e.target.value), onKeyDown: (e) => {
|
|
5194
5430
|
if (e.isComposing) return
|
|
@@ -5203,36 +5439,41 @@ window.__ModuleLoader__.load({
|
|
|
5203
5439
|
tr('file.conflictHelp'),
|
|
5204
5440
|
React.createElement('button', { type: 'button', className: 'dsh-rw-btn', style: { ...buttonS, marginLeft: 8 }, onClick: () => copyToClipboard(draft) }, tr('file.copyDraft')),
|
|
5205
5441
|
React.createElement('button', { type: 'button', className: 'dsh-rw-btn', style: { ...buttonS, marginLeft: 8 }, onClick: () => discardDraft(true) }, tr('file.discardReload'))) : null,
|
|
5442
|
+
localCopy ? React.createElement('div', { 'data-rw-local-copy-recovery': '', role: 'status', 'aria-busy': copyBusy, style: { padding: '12px', borderBottom: '1px solid ' + T.border, fontSize: 12, lineHeight: 1.6, background: T.bg } },
|
|
5443
|
+
React.createElement('strong', null, tr('file.localCopyMissing')),
|
|
5444
|
+
React.createElement('div', { style: { color: T.muted, marginTop: 4 } }, tr('file.localCopyHelp')),
|
|
5445
|
+
copyBusy ? React.createElement('div', { style: { marginTop: 4, color: T.muted } }, tr('file.loading')) : null,
|
|
5446
|
+
React.createElement('div', { style: { display: 'flex', flexWrap: 'wrap', gap: 8, marginTop: 10 } },
|
|
5447
|
+
React.createElement('button', { type: 'button', className: 'dsh-rw-btn', style: buttonS, disabled: copyBusy, onClick: () => recoverLocalCopy(false) }, tr('file.localCopyView')),
|
|
5448
|
+
localPreview?.localRevision ? React.createElement('button', { type: 'button', className: 'dsh-rw-btn dsh-rw-primary', style: primaryBtnS, disabled: copyBusy, onClick: () => recoverLocalCopy(true) }, tr('file.localCopyPublish')) : null)) : null,
|
|
5206
5449
|
discardConfirm.node,
|
|
5207
5450
|
React.createElement('div', { ref: scrollRef, className: wrap ? 'dsh-rw-code-wrap' : '', onScroll: (e) => keepView({ scrollTop: e.currentTarget.scrollTop, scrollLeft: e.currentTarget.scrollLeft }), style: { flex: 1, overflow: 'auto', minHeight: 0, display: 'flex', flexDirection: 'column', position: 'relative' } },
|
|
5208
5451
|
err ? React.createElement('div', { style: { color: T.danger, padding: '8px 12px', fontSize: 13, flexShrink: 0 } }, err, !edit ? React.createElement('button', { type: 'button', className: 'dsh-rw-btn', style: { ...buttonS, marginLeft: 8 }, onClick: load }, tr('project.retry')) : null) : null,
|
|
5209
|
-
|
|
5452
|
+
localPreview ? React.createElement('div', { 'data-rw-local-copy-preview': '', style: { padding: 12 } },
|
|
5453
|
+
React.createElement('div', { style: { color: T.warn, fontSize: 12, marginBottom: 12 } }, tr('file.localCopySource')),
|
|
5454
|
+
String(localPreview.content || '').length > 300000 || String(localPreview.content || '').split('\n', 10002).length > 10000
|
|
5455
|
+
? React.createElement('pre', { 'data-rw-local-copy-large': '', tabIndex: 0, style: { fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Consolas, monospace', fontSize: 13, lineHeight: 1.55, whiteSpace: wrap ? 'pre-wrap' : 'pre', margin: 0, tabSize: 2 } }, localPreview.content || '')
|
|
5456
|
+
: React.createElement(CodeView, { code: localPreview.content || '', path, wrap }))
|
|
5457
|
+
: loading && !data ? React.createElement('div', { style: { opacity: 0.7, padding: 12, fontSize: 13 } }, tr('file.loading'))
|
|
5210
5458
|
: (data && data.binary
|
|
5211
5459
|
? React.createElement('div', { style: { padding: 12, fontSize: 13, color: T.warn } },
|
|
5212
5460
|
tr('file.binary', { size: (data.size != null ? data.size + ' bytes' : tr('file.unknownSize')) }))
|
|
5213
5461
|
: data && data.image
|
|
5214
5462
|
? React.createElement('div', { style: { flex: 1, display: 'flex', alignItems: 'center', justifyContent: 'center', padding: 12, minHeight: 0 } },
|
|
5215
5463
|
React.createElement('img', { src: `data:${data.mime};base64,${data.content}`, alt: baseName, style: { maxWidth: '100%', maxHeight: '100%', objectFit: 'contain' } }))
|
|
5216
|
-
: (edit
|
|
5217
|
-
? React.createElement(
|
|
5218
|
-
|
|
5219
|
-
|
|
5220
|
-
|
|
5221
|
-
|
|
5222
|
-
|
|
5223
|
-
|
|
5224
|
-
|
|
5225
|
-
|
|
5226
|
-
|
|
5227
|
-
|
|
5228
|
-
changeDraft(result.text)
|
|
5229
|
-
setTimeout(() => { node.setSelectionRange(result.start, result.end); updateCursor(node) }, 0)
|
|
5230
|
-
}
|
|
5231
|
-
if ((e.metaKey || e.ctrlKey) && e.key === 's') { e.preventDefault(); if (!e.isComposing && !saving && dirty && !saveConflict) saveRemote() }
|
|
5232
|
-
if (e.key === 'Escape') { e.preventDefault(); e.currentTarget.blur() }
|
|
5464
|
+
: (edit && (!isMarkdown || sourceMode)
|
|
5465
|
+
? React.createElement(HighlightedEditor, {
|
|
5466
|
+
editorRef, path, wrap, indent: indentRemoteDraft, 'aria-label': tr('file.edit') + ' ' + baseName,
|
|
5467
|
+
value: draft, jumpLine: props.jumpLine || null, jumpRevision: props.navigationRevision,
|
|
5468
|
+
matchingLines: findOpen ? matches.map(match => match.line) : [], currentMatchLine: findOpen && activeMatch ? activeMatch.line : null,
|
|
5469
|
+
onSelect: event => updateCursor(event.currentTarget),
|
|
5470
|
+
onChange: event => { changeDraft(event.target.value); updateCursor(event.target) },
|
|
5471
|
+
onScroll: event => keepView({ scrollTop: event.currentTarget.scrollTop, scrollLeft: event.currentTarget.scrollLeft }),
|
|
5472
|
+
onKeyDown: event => {
|
|
5473
|
+
if (event.isComposing || event.nativeEvent?.isComposing) return
|
|
5474
|
+
if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === 's') { event.preventDefault(); if (!saving && dirty && !saveConflict) saveRemote() }
|
|
5475
|
+
if (event.key === 'Escape') { event.preventDefault(); event.currentTarget.blur() }
|
|
5233
5476
|
},
|
|
5234
|
-
spellCheck: false,
|
|
5235
|
-
style: { width: '100%', height: '100%', flex: 1, boxSizing: 'border-box', border: 'none', outline: 'none', resize: 'none', background: 'transparent', color: T.label, fontSize: 13, lineHeight: 1.55, fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Consolas, monospace', padding: '10px 12px', whiteSpace: wrap ? 'pre-wrap' : 'pre', overflowWrap: wrap ? 'anywhere' : 'normal' },
|
|
5236
5477
|
})
|
|
5237
5478
|
: (isMarkdown && !sourceMode && MarkdownText
|
|
5238
5479
|
// Render remote markdown with the host renderer instead of a
|
|
@@ -5246,9 +5487,9 @@ window.__ModuleLoader__.load({
|
|
|
5246
5487
|
fontSize: 13, lineHeight: 1.55, fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Consolas, monospace',
|
|
5247
5488
|
whiteSpace: 'pre-wrap', wordBreak: 'break-word', color: T.label,
|
|
5248
5489
|
},
|
|
5249
|
-
}, originalText),
|
|
5490
|
+
}, edit ? draft : originalText),
|
|
5250
5491
|
},
|
|
5251
|
-
React.createElement(MarkdownText, { text: originalText, variant: 'body', labels: markdownLabels })),
|
|
5492
|
+
React.createElement(MarkdownText, { text: edit ? draft : originalText, variant: 'body', labels: markdownLabels })),
|
|
5252
5493
|
(data && data.truncated)
|
|
5253
5494
|
? React.createElement('div', { style: { color: T.warn, fontSize: 12, marginTop: 8 } }, tr('file.truncated'))
|
|
5254
5495
|
: null)
|
|
@@ -5267,7 +5508,7 @@ window.__ModuleLoader__.load({
|
|
|
5267
5508
|
React.createElement('span', {}, data && data.size != null ? humanSize(data.size) : ''),
|
|
5268
5509
|
React.createElement('span', {}, baseName.includes('.') ? baseName.split('.').pop().toUpperCase() : 'TEXT'),
|
|
5269
5510
|
data?.eol ? React.createElement('span', {}, data.eol === 'crlf' ? 'CRLF' : data.eol === 'mixed' ? tr('file.mixedEol') : 'LF') : null,
|
|
5270
|
-
React.createElement('span', { style: { marginLeft: 'auto', color: copyNote ? T.ok : T.muted } }, copyNote || (loading && data ? tr('workbench.refreshing') : edit ? tr('file.editing') : tr('file.readonly')))),
|
|
5511
|
+
React.createElement('span', { style: { marginLeft: 'auto', color: copyNote ? T.ok : T.muted } }, copyNote || (localPreview ? tr('file.localCopySource') : loading && data ? tr('workbench.refreshing') : edit ? tr('file.editing') : tr('file.readonly')))),
|
|
5271
5512
|
)
|
|
5272
5513
|
}
|
|
5273
5514
|
|
|
@@ -5345,6 +5586,7 @@ window.__ModuleLoader__.load({
|
|
|
5345
5586
|
const NATIVE_EXPLORER = 'dsh-remote/explorer'
|
|
5346
5587
|
const NATIVE_FILE = 'dsh-remote/file'
|
|
5347
5588
|
const NATIVE_CHANGES = 'dsh-remote/changes'
|
|
5589
|
+
const NATIVE_WELCOME = 'dsh-remote/welcome'
|
|
5348
5590
|
// Issue #55: the address the CORE emits for a file link, which is NOT the
|
|
5349
5591
|
// one this plugin mints for its own explorer. A model-emitted
|
|
5350
5592
|
// `[x](src/main.c)` (or a `@src/main.c` chip) is turned into
|
|
@@ -5474,7 +5716,7 @@ window.__ModuleLoader__.load({
|
|
|
5474
5716
|
function NativeFile(props) {
|
|
5475
5717
|
const info = props.useTabInfo()
|
|
5476
5718
|
const path = remoteFilePath(info.tab.navigation.address)
|
|
5477
|
-
return React.createElement(RemoteFileTab, { key: path, tab: { path }, scope: { sessionId: props.sessionId }, jumpLine: Number.isSafeInteger(info.tab.navigation.params?.line) && info.tab.navigation.params.line > 0 ? info.tab.navigation.params.line : null, navigationRevision: info.tab.navigation.revision })
|
|
5719
|
+
return React.createElement(RemoteFileTab, { key: path, tab: { path }, scope: { sessionId: props.sessionId }, visible: info.tab.visible, jumpLine: Number.isSafeInteger(info.tab.navigation.params?.line) && info.tab.navigation.params.line > 0 ? info.tab.navigation.params.line : null, navigationRevision: info.tab.navigation.revision })
|
|
5478
5720
|
}
|
|
5479
5721
|
/**
|
|
5480
5722
|
* The body for a CORE file link in a remote Session (issue #55).
|
|
@@ -5524,7 +5766,7 @@ window.__ModuleLoader__.load({
|
|
|
5524
5766
|
return React.createElement(RemoteFileTab, {
|
|
5525
5767
|
key: remotePath,
|
|
5526
5768
|
tab: { path: remotePath },
|
|
5527
|
-
scope: { sessionId },
|
|
5769
|
+
scope: { sessionId }, visible: info.tab.visible,
|
|
5528
5770
|
// Current hosts pass line numbers as navigation params; retain support
|
|
5529
5771
|
// for older address-carried anchors. Invalid params must not mask them.
|
|
5530
5772
|
jumpLine: (parsed && parsed.line) || paramsLine || null,
|
|
@@ -5653,9 +5895,10 @@ window.__ModuleLoader__.load({
|
|
|
5653
5895
|
try { syncExplorerType() } catch (e) { console.warn('[dsh-remote] start-page card handover skipped:', e) }
|
|
5654
5896
|
}, 'dsh-remote.start-card-owner')
|
|
5655
5897
|
})
|
|
5898
|
+
inner.effect(() => tabs.register({ id: NATIVE_WELCOME, kind: NATIVE_WELCOME, title: () => tr('ide.welcome') }), 'dsh-remote.native-welcome-type')
|
|
5656
5899
|
inner.effect(() => tabs.register({ id: NATIVE_CHANGES, kind: NATIVE_CHANGES, title: () => tr('changes.title') }), 'dsh-remote.native-changes-type')
|
|
5657
5900
|
inner.effect(() => tabs.register({
|
|
5658
|
-
id: NATIVE_FILE, kind: NATIVE_FILE,
|
|
5901
|
+
id: NATIVE_FILE, kind: NATIVE_FILE, keepMounted: true,
|
|
5659
5902
|
patterns: ['dsh-resource://dsh-remote/**'],
|
|
5660
5903
|
title: (address) => remoteFilePath(address).split(/[\\/]/).pop() || tr('explorer.tabTitle'),
|
|
5661
5904
|
}), 'dsh-remote.native-file-type')
|
|
@@ -5679,7 +5922,7 @@ window.__ModuleLoader__.load({
|
|
|
5679
5922
|
inner.effect(() => {
|
|
5680
5923
|
try {
|
|
5681
5924
|
const dispose = tabs.register({
|
|
5682
|
-
id: NATIVE_LINK, kind: NATIVE_LINK,
|
|
5925
|
+
id: NATIVE_LINK, kind: NATIVE_LINK, keepMounted: true,
|
|
5683
5926
|
// Specificity beats bundle order: the registry ranks longest-glob-first,
|
|
5684
5927
|
// and ties fall to registration order (which we do not control). Another
|
|
5685
5928
|
// extension claiming `dsh-resource://file/**` used to win those ties and
|
|
@@ -5727,6 +5970,7 @@ window.__ModuleLoader__.load({
|
|
|
5727
5970
|
slots.register({ name: 'sidebar.right.pane.tab', key: NATIVE_EXPLORER }, NativeExplorer),
|
|
5728
5971
|
slots.register({ name: 'sidebar.right.pane.tab', key: NATIVE_FILE }, NativeFile),
|
|
5729
5972
|
slots.register({ name: 'sidebar.right.pane.tab', key: NATIVE_CHANGES }, NativeChanges),
|
|
5973
|
+
slots.register({ name: 'sidebar.right.pane.tab', key: NATIVE_WELCOME }, RemoteIdeWelcome),
|
|
5730
5974
|
]
|
|
5731
5975
|
// Only register the link body when its type was accepted: a body under a
|
|
5732
5976
|
// kind nothing claims would never render, and on a build that rejected
|
|
@@ -6121,12 +6365,38 @@ window.__ModuleLoader__.load({
|
|
|
6121
6365
|
[data-rw-ide-navigation]{display:flex;gap:3px}
|
|
6122
6366
|
[data-rw-ide-navigation] button[aria-pressed=true]{background:var(--dsw-alias-interactive-bg-hover,#eee);font-weight:600}
|
|
6123
6367
|
@media(max-width:600px){[data-rw-ide-header]{gap:5px;padding:0 6px}[data-rw-ide-title]{display:none}[data-rw-ide-header] button{font-size:11px!important;padding:4px 6px!important}}
|
|
6368
|
+
/* Reversible IDE-only header adapter for DSH 0.2.1/0.2.2.
|
|
6369
|
+
* Uses published slot/DOM markers rather than compiled class names.
|
|
6370
|
+
* Removing data-rw-ide-chat restores all native host styles automatically. */
|
|
6371
|
+
[data-rw-ide-chat] header[data-window-drag]{display:flex!important;flex-direction:column!important;flex:none!important;gap:0!important;min-height:0!important;height:auto!important;padding:10px 12px 0!important;box-sizing:border-box!important;overflow:visible!important}
|
|
6372
|
+
[data-rw-ide-chat] header[data-window-drag] div:has(>[data-conversation-header-corner]){display:grid!important;grid-template-columns:minmax(0,1fr) auto!important;grid-template-rows:auto auto!important;align-items:start!important;gap:6px 4px!important;min-width:0!important;width:100%!important;padding:0!important;min-height:0!important;container-type:normal!important}
|
|
6373
|
+
[data-rw-ide-chat] header[data-window-drag] div:has(>nav){display:flex!important;flex-direction:column!important;align-items:stretch!important;gap:5px!important;grid-column:1!important;grid-row:1!important;min-width:0!important;max-width:100%!important;margin:0!important;padding:0!important;mask-image:none!important;overflow:visible!important}
|
|
6374
|
+
[data-rw-ide-chat] header[data-window-drag] nav{display:flex!important;min-width:0!important;max-width:100%!important;overflow:hidden!important}
|
|
6375
|
+
[data-rw-ide-chat] header[data-window-drag] nav>span{min-width:0!important;max-width:100%!important;flex-shrink:1!important}
|
|
6376
|
+
[data-rw-ide-chat] header[data-window-drag] nav>span>span:last-child{min-width:0!important;max-width:100%!important;overflow:hidden!important;text-overflow:ellipsis!important;white-space:nowrap!important}
|
|
6377
|
+
[data-rw-ide-chat] header[data-window-drag] div:has(>[data-slot="conversation.session.header.actions"]){display:flex!important;flex-wrap:wrap!important;gap:5px!important;align-items:center!important;min-width:0!important;max-width:100%!important;margin:0!important;padding:0!important}
|
|
6378
|
+
[data-rw-ide-chat] header[data-window-drag] div:has(>[data-slot="conversation.session.header.utilities"]){display:flex!important;flex-wrap:wrap!important;align-items:center!important;gap:5px!important;grid-column:1/-1!important;grid-row:2!important;min-width:0!important;max-width:100%!important;margin:0!important;padding:0!important}
|
|
6379
|
+
[data-rw-ide-chat] header[data-window-drag] [data-dsh-remote-chip]{max-width:100%!important;min-width:0!important;flex-shrink:1!important}
|
|
6380
|
+
[data-rw-ide-chat] [data-conversation-header-corner]{grid-column:2!important;grid-row:1!important;align-self:start!important;min-width:0!important;margin:0!important;padding:0!important}
|
|
6381
|
+
[data-rw-ide-chat] header[data-window-drag] div:has(>[data-conversation-tabs]){display:flex!important;flex-wrap:nowrap!important;align-items:flex-end!important;gap:8px!important;min-width:0!important;width:100%!important;margin:6px 0 0!important;padding:0!important;min-height:32px!important;position:relative!important}
|
|
6382
|
+
[data-rw-ide-chat] [data-conversation-tabs]{display:flex!important;flex-wrap:nowrap!important;align-items:stretch!important;gap:16px!important;flex:1!important;min-width:0!important;max-width:100%!important;overflow-x:auto!important;scrollbar-width:none!important}
|
|
6383
|
+
[data-rw-ide-chat] [data-conversation-tabs]>[role="tab"]{flex:none!important;min-height:32px!important;margin:0!important;padding:7px 2px 8px!important;box-sizing:border-box!important}
|
|
6384
|
+
[data-rw-ide-chat] header[data-window-drag] button{max-width:100%}
|
|
6385
|
+
/* The shell already has a persistent Return to standard mode action. */
|
|
6386
|
+
[data-rw-ide-chat] [data-rw-ide-toggle]{display:none!important}
|
|
6387
|
+
|
|
6388
|
+
/* Keep the default conversation header compact; preserve every extension
|
|
6389
|
+
* action behind the shell's explicit Chat tools disclosure. */
|
|
6390
|
+
[data-rw-ide-chat]:not([data-rw-ide-tools-expanded]) header[data-window-drag] div:has(>[data-slot="conversation.session.header.actions"]),
|
|
6391
|
+
[data-rw-ide-chat]:not([data-rw-ide-tools-expanded]) header[data-window-drag] div:has(>[data-slot="conversation.session.header.utilities"]){display:none!important}
|
|
6392
|
+
[data-rw-ide-chat]:not([data-rw-ide-tools-expanded]) header[data-window-drag] div:has(>[data-conversation-header-corner]){grid-template-rows:auto!important}
|
|
6393
|
+
|
|
6124
6394
|
`
|
|
6125
6395
|
// Returns a disposer that restores only the attributes/variables we own.
|
|
6126
6396
|
// No innerHTML, appendChild, React portal, clone or second conversation.
|
|
6127
6397
|
function remoteIdeDock(node, kind) {
|
|
6128
6398
|
const marker = 'data-rw-ide-' + kind
|
|
6129
|
-
const names = [marker, 'data-rw-ide-hidden', 'inert']
|
|
6399
|
+
const names = [marker, 'data-rw-ide-hidden', 'data-rw-ide-tools-expanded', 'inert']
|
|
6130
6400
|
const attrs = names.map(name => [name, node.getAttribute(name)])
|
|
6131
6401
|
const vars = ['--rw-ide-x', '--rw-ide-y', '--rw-ide-w', '--rw-ide-h']
|
|
6132
6402
|
const values = vars.map(name => [name, node.style.getPropertyValue(name), node.style.getPropertyPriority(name)])
|
|
@@ -6153,12 +6423,39 @@ window.__ModuleLoader__.load({
|
|
|
6153
6423
|
},
|
|
6154
6424
|
}
|
|
6155
6425
|
}
|
|
6426
|
+
function RemoteIdeWelcome() {
|
|
6427
|
+
return React.createElement('article', { 'data-rw-ide-welcome': '', style: { boxSizing: 'border-box', width: '100%', minHeight: '100%', padding: 'clamp(24px,5vw,64px)', color: T.label, overflowWrap: 'anywhere' } },
|
|
6428
|
+
React.createElement('div', { style: { maxWidth: 560, margin: 'auto' } },
|
|
6429
|
+
React.createElement('div', { style: { display: 'flex', alignItems: 'center', gap: 10, color: T.muted, fontSize: 12, marginBottom: 14 } }, React.createElement(WorkbenchIcon, { name: 'remote', size: 24 }), 'dsh / remote'),
|
|
6430
|
+
React.createElement('h1', { style: { fontSize: 'clamp(20px,2vw,28px)', lineHeight: 1.4, fontWeight: 600, margin: '0 0 10px' } }, tr('ide.welcomeTitle')),
|
|
6431
|
+
React.createElement('p', { style: { fontSize: 13, lineHeight: 1.7, margin: '0 0 32px', color: T.muted } }, tr('ide.welcomeHint')),
|
|
6432
|
+
React.createElement('div', { style: { display: 'grid', gap: 24 } }, ['Files','Edit','Agent','Layout'].map((key, index) => React.createElement('section', { key, style: { display: 'flex', gap: 14 } },
|
|
6433
|
+
React.createElement('span', { 'aria-hidden': true, style: { color: T.muted, fontFamily: 'monospace', fontSize: 12, paddingTop: 2 } }, String(index + 1).padStart(2, '0')),
|
|
6434
|
+
React.createElement('div', {}, React.createElement('h2', { style: { fontSize: 13, fontWeight: 600, margin: '0 0 6px' } }, tr({ Files: 'ide.guideFiles', Edit: 'ide.guideEdit', Agent: 'ide.guideAgent', Layout: 'ide.guideLayout' }[key])), React.createElement('p', { style: { color: T.muted, fontSize: 12, lineHeight: 1.75, margin: 0 } }, tr({ Files: 'ide.guideFilesHint', Edit: 'ide.guideEditHint', Agent: 'ide.guideAgentHint', Layout: 'ide.guideLayoutHint' }[key])))))),
|
|
6435
|
+
React.createElement('a', { href: 'https://github.com/flymysql/dsh-remote#readme', target: '_blank', rel: 'noopener noreferrer', style: { display: 'inline-block', color: T.muted, fontSize: 12, marginTop: 32 } }, tr('ide.documentation'))))
|
|
6436
|
+
}
|
|
6437
|
+
// Replace the empty guide or a redundant explorer (already in the left
|
|
6438
|
+
// column). Existing files, terminals and drafts
|
|
6439
|
+
// are untouched, and each action is fenced to the session still on screen.
|
|
6440
|
+
function ensureRemoteIdeWelcome(controller, sessionId) {
|
|
6441
|
+
if (!controller || controller.mounted?.getSnapshot?.() !== sessionId || typeof controller.active !== 'function') return false
|
|
6442
|
+
const tab = controller.active()
|
|
6443
|
+
if (typeof controller.openTabIn !== 'function') return false
|
|
6444
|
+
if (!tab) { controller.openTabIn(sessionId, NATIVE_WELCOME); return true }
|
|
6445
|
+
if (!['guide', NATIVE_EXPLORER].includes(tab.kind) || !tab.id) return false
|
|
6446
|
+
controller.openTabIn(sessionId, NATIVE_WELCOME, { replaceTab: tab.id })
|
|
6447
|
+
controller.closeIn?.(sessionId, tab.id)
|
|
6448
|
+
return true
|
|
6449
|
+
}
|
|
6156
6450
|
function RemoteIdeShell() {
|
|
6157
6451
|
const state = useRemoteIdeState()
|
|
6158
6452
|
const [sessionId, setSessionId] = React.useState('')
|
|
6159
6453
|
const [, refresh] = React.useState(0)
|
|
6160
6454
|
const [width, setWidth] = React.useState(() => typeof window.innerWidth === 'number' ? window.innerWidth : 1280)
|
|
6161
6455
|
const [mobilePane, setMobilePane] = React.useState('chat')
|
|
6456
|
+
const [toolsExpanded, setToolsExpanded] = React.useState(false)
|
|
6457
|
+
const toolsExpandedRef = React.useRef(false)
|
|
6458
|
+
toolsExpandedRef.current = toolsExpanded
|
|
6162
6459
|
const [availability, setAvailability] = React.useState({ chat: true, editor: true })
|
|
6163
6460
|
const [expanded, setExpanded] = React.useState([])
|
|
6164
6461
|
const editorSeat = React.useRef(null), chatSeat = React.useRef(null), shellRef = React.useRef(null)
|
|
@@ -6180,7 +6477,11 @@ window.__ModuleLoader__.load({
|
|
|
6180
6477
|
window.addEventListener('resize', onResize)
|
|
6181
6478
|
return () => { unsubscribers.forEach(dispose => dispose?.()); mirrorWatchers.delete(update); window.removeEventListener('resize', onResize); dragCleanup.current?.() }
|
|
6182
6479
|
}, [controller])
|
|
6183
|
-
React.useEffect(() => { setExpanded(explorerMemory.get(sessionId)?.expanded || []) }, [sessionId])
|
|
6480
|
+
React.useEffect(() => { setExpanded(explorerMemory.get(sessionId)?.expanded || []); setToolsExpanded(false) }, [sessionId])
|
|
6481
|
+
React.useEffect(() => {
|
|
6482
|
+
const chat = document.querySelector('[data-rw-ide-chat]')
|
|
6483
|
+
chat?.toggleAttribute('data-rw-ide-tools-expanded', toolsExpanded)
|
|
6484
|
+
}, [active, sessionId, toolsExpanded])
|
|
6184
6485
|
React.useEffect(() => {
|
|
6185
6486
|
if (!active) return
|
|
6186
6487
|
const node = document.createElement('style')
|
|
@@ -6200,6 +6501,7 @@ window.__ModuleLoader__.load({
|
|
|
6200
6501
|
const update = () => {
|
|
6201
6502
|
frame = 0
|
|
6202
6503
|
if (stopped) return
|
|
6504
|
+
ensureRemoteIdeWelcome(controller, sessionId)
|
|
6203
6505
|
if (!dockChat?.node.isConnected) {
|
|
6204
6506
|
dockChat?.dispose()
|
|
6205
6507
|
const content = find('[data-conversation-content][data-conversation-session]', 'data-conversation-session')
|
|
@@ -6213,7 +6515,7 @@ window.__ModuleLoader__.load({
|
|
|
6213
6515
|
}
|
|
6214
6516
|
const chatRect = chatSeat.current?.getBoundingClientRect()
|
|
6215
6517
|
const editorRect = editorSeat.current?.getBoundingClientRect()
|
|
6216
|
-
if (dockChat && chatRect) dockChat.position(chatRect, chatRect.width > 0 && chatRect.height > 0)
|
|
6518
|
+
if (dockChat && chatRect) { dockChat.position(chatRect, chatRect.width > 0 && chatRect.height > 0); dockChat.node.toggleAttribute('data-rw-ide-tools-expanded', toolsExpandedRef.current) }
|
|
6217
6519
|
if (dockEditor && editorRect) dockEditor.position(editorRect, editorRect.width > 0 && editorRect.height > 0)
|
|
6218
6520
|
const chat = !!dockChat
|
|
6219
6521
|
const editor = !!dockEditor && dockEditor.node.getAttribute('aria-hidden') !== 'true'
|
|
@@ -6223,10 +6525,9 @@ window.__ModuleLoader__.load({
|
|
|
6223
6525
|
const observer = typeof ResizeObserver === 'function' ? new ResizeObserver(schedule) : null
|
|
6224
6526
|
observer?.observe(editorSeat.current); observer?.observe(chatSeat.current)
|
|
6225
6527
|
// React may replace roots during session navigation. Child-list changes
|
|
6226
|
-
// are coalesced
|
|
6227
|
-
|
|
6228
|
-
|
|
6229
|
-
}) : null
|
|
6528
|
+
// are coalesced, including a newly opened empty guide. Character data
|
|
6529
|
+
// and style attributes are not observed during token streaming.
|
|
6530
|
+
const mutations = typeof MutationObserver === 'function' ? new MutationObserver(schedule) : null
|
|
6230
6531
|
mutations?.observe(document.body, { childList: true, subtree: true })
|
|
6231
6532
|
const unsub = controller.openTabs?.subscribe?.(schedule)
|
|
6232
6533
|
window.addEventListener('resize', schedule)
|
|
@@ -6275,6 +6576,7 @@ window.__ModuleLoader__.load({
|
|
|
6275
6576
|
key: pane, type: 'button', style: { ...buttonS, padding: '4px 9px', fontSize: 12 },
|
|
6276
6577
|
'aria-pressed': mobilePane === pane, onClick: () => setMobilePane(pane),
|
|
6277
6578
|
}, tr({ files: 'ide.files', editor: 'ide.editor', chat: 'ide.chat' }[pane])))) : null,
|
|
6579
|
+
React.createElement('button', { type: 'button', 'data-rw-ide-tools-toggle': '', 'aria-expanded': toolsExpanded, style: { ...buttonS, padding: '4px 9px', fontSize: 12 }, title: tr('ide.toolsHint'), onClick: () => setToolsExpanded(value => !value) }, tr('ide.tools')),
|
|
6278
6580
|
React.createElement('button', { type: 'button', 'data-rw-ide-exit': '', style: { ...buttonS, padding: '4px 9px', fontSize: 12 }, title: tr('ide.help'), onClick: () => remoteIdeSet({ enabled: false }) }, tr('ide.exit'))),
|
|
6279
6581
|
React.createElement('div', { 'data-rw-ide-body': '', style: { gridTemplateColumns: sizes.narrow ? 'minmax(0,1fr)' : sizes.left + 'px 6px minmax(320px,1fr) 6px ' + sizes.right + 'px' } },
|
|
6280
6582
|
React.createElement('aside', { 'data-rw-ide-tree': '', 'aria-label': tr('ide.files'), style: { display: sizes.narrow && mobilePane !== 'files' ? 'none' : undefined } },
|
package/lib/index.js
CHANGED
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
// Plugin Config MUST be a schemastery schema (zod rejects the undefined row config).
|
|
21
21
|
import { WorkspaceSearches, createSearchRoutes } from './workspace-search.js'
|
|
22
22
|
import { createGitRoutes } from './remote-git.js'
|
|
23
|
+
import { LOCAL_MUTATION_TOOLS, remoteLocalMutationDecision } from './local-mutation.js'
|
|
23
24
|
import { fileChange, changeOutput, presentFileChange } from './file-changes.js'
|
|
24
25
|
import { captureRemoteFile, atomicRemoteWrite } from './remote-write.js'
|
|
25
26
|
import z from '@deepseek-ai/schemastery'
|
|
@@ -1704,7 +1705,13 @@ export async function apply(ctx, config) {
|
|
|
1704
1705
|
const resolveRequestBinding = async (req, body = {}) => {
|
|
1705
1706
|
const hint = requestSessionHint(req, body)
|
|
1706
1707
|
let cwd = hint.local
|
|
1707
|
-
if (
|
|
1708
|
+
if (hint.sessionId) {
|
|
1709
|
+
const recorded = lookupSessionCwd(hint.sessionId, { sessions: sessionsSvc(), dshHome: dshBase() })
|
|
1710
|
+
if (!recorded || hint.local && path.resolve(recorded) !== path.resolve(hint.local)) {
|
|
1711
|
+
throw Object.assign(new Error('Session workspace context is unavailable or mismatched; refusing to use another session or the active machine.'), { httpStatus: 403 })
|
|
1712
|
+
}
|
|
1713
|
+
cwd = recorded
|
|
1714
|
+
}
|
|
1708
1715
|
if (cwd) {
|
|
1709
1716
|
const { remotePath, machine, mirrorDir } = resolveMirrorForLocal(cwd)
|
|
1710
1717
|
if (remotePath && machine) {
|
|
@@ -1846,6 +1853,13 @@ export async function apply(ctx, config) {
|
|
|
1846
1853
|
return b
|
|
1847
1854
|
}
|
|
1848
1855
|
|
|
1856
|
+
if (typeof ctx.on === 'function') {
|
|
1857
|
+
ctx.on('tools/pre-execute', async (exec, next) => {
|
|
1858
|
+
if (!LOCAL_MUTATION_TOOLS.has(exec?.name)) return next()
|
|
1859
|
+
return remoteLocalMutationDecision(exec, bindingFor(exec)) || next()
|
|
1860
|
+
})
|
|
1861
|
+
}
|
|
1862
|
+
|
|
1849
1863
|
// ── remote sandbox semantics ──────────────────────────────────────────────
|
|
1850
1864
|
// A local session is confined by ctx.sandboxPolicy; a REMOTE command used to
|
|
1851
1865
|
// run under no policy at all, so a read-only session could mutate any file on
|
|
@@ -1902,7 +1916,10 @@ export async function apply(ctx, config) {
|
|
|
1902
1916
|
if (mode === 'danger-full-access') return
|
|
1903
1917
|
const b = (() => { try { return bindingFor(exec) } catch { return null } })()
|
|
1904
1918
|
const workspaceRoot = (b && b.ws) || ''
|
|
1905
|
-
|
|
1919
|
+
// Check the execution-world path the rw_* body will actually use. Raw
|
|
1920
|
+
// relative and mirror-local paths must resolve exactly as resolveRemoteArg.
|
|
1921
|
+
const targetPath = opts.path == null ? opts.path : resolveRemoteWorkspacePath(workspaceRoot, opts.path, b?.mirrorDir || '')
|
|
1922
|
+
const verdict = checkRemoteSandbox({ mode, operation, path: targetPath, workspaceRoot })
|
|
1906
1923
|
if (verdict.allowed) return
|
|
1907
1924
|
const err = remoteSandboxDenial(verdict)
|
|
1908
1925
|
if (opts.tool) err.message = `${opts.tool}: ${err.message}`
|
|
@@ -3196,7 +3213,8 @@ export async function apply(ctx, config) {
|
|
|
3196
3213
|
'Use the rw_* tools (rw_list_dir / rw_read_file / rw_write_file / rw_edit / rw_exec / rw_search / rw_sync / rw_push / rw_download / rw_upload) to inspect and act on files on the remote host. Treat this directory as the working root for this task.\n' +
|
|
3197
3214
|
`\`@path\` mentions in this conversation name files under THAT remote root (\`@src/main.c\` = ${shown}/src/main.c). ` +
|
|
3198
3215
|
'The rw_* tools take such paths as workspace-relative and resolve them against this root. ' +
|
|
3199
|
-
`The harness's built-in local tools (read / write / edit / grep / glob / working_directory / local shell) only see the LOCAL mirror of this directory${mirrorNote}, which stays empty until rw_sync — use rw_read_file / rw_list_dir / rw_search / rw_exec for remote files, or rw_download to fetch a specific remote file locally
|
|
3216
|
+
`The harness's built-in local tools (read / write / edit / grep / glob / working_directory / local shell) only see the LOCAL mirror of this directory${mirrorNote}, which stays empty until rw_sync — use rw_read_file / rw_list_dir / rw_search / rw_exec for remote files, or rw_download to fetch a specific remote file locally.\n` +
|
|
3217
|
+
'Creating a file with local write/edit, a local shell, or Python does NOT save it on the remote host. Native write/edit mutations are refused in remote sessions: use rw_write_file / rw_edit or rw_exec to create and modify remote results. For an already-local artifact, explicitly use rw_push / rw_upload and verify it through rw_read_file or rw_stat before claiming it is saved remotely or giving a remote file link. run_code/PTC remains available for orchestration; its raw local filesystem IO is still LOCAL.\n' +
|
|
3200
3218
|
extra
|
|
3201
3219
|
)
|
|
3202
3220
|
},
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// Recovery for an explicitly identified local mirror copy. A remote read never
|
|
2
|
+
// substitutes these bytes, and publishing uses SFTP exclusive creation.
|
|
3
|
+
import { open, lstat, realpath } from 'node:fs/promises'
|
|
4
|
+
import path from 'node:path'
|
|
5
|
+
import { mirrorDownloadTarget, assertDownloadHasNoSymlinks } from './mirror-paths.js'
|
|
6
|
+
import { requestSessionHint } from './binding.js'
|
|
7
|
+
import { remoteRevision, missingRemoteFile } from './remote-write.js'
|
|
8
|
+
import { normalizeRemotePath, remoteDirname, mkdirRemoteDirs, joinRemotePath } from './paths.js'
|
|
9
|
+
|
|
10
|
+
const HARD_CAP = 2 * 1024 * 1024
|
|
11
|
+
const failure = (message, httpStatus, code) => Object.assign(new Error(message), { httpStatus, code })
|
|
12
|
+
const changed = () => failure('本地副本已变化,请重新查看后再上传。', 409, 'LOCAL_COPY_CHANGED')
|
|
13
|
+
const unsupported = () => failure('仅支持查看和上传完整的 UTF-8 文本副本;此文件不是受支持的文本。', 415, 'LOCAL_COPY_UNSUPPORTED')
|
|
14
|
+
const sameFile = (a, b) => a.dev === b.dev && a.ino === b.ino && a.size === b.size && a.mtimeMs === b.mtimeMs && a.ctimeMs === b.ctimeMs
|
|
15
|
+
|
|
16
|
+
async function checkRemoteParents(sftp, binding, target, allowMissing) {
|
|
17
|
+
const root = normalizeRemotePath(binding.ws)
|
|
18
|
+
const grammar = /^(?:[a-z]:[\\/]|\\\\)/i.test(root) ? path.win32 : path.posix
|
|
19
|
+
const relative = grammar.relative(root, remoteDirname(target))
|
|
20
|
+
let current = root
|
|
21
|
+
for (const part of ['', ...relative.split(grammar.sep).filter(Boolean)]) {
|
|
22
|
+
if (part) current = joinRemotePath(current, part)
|
|
23
|
+
let stat
|
|
24
|
+
try { stat = await sftp.lstat(current) }
|
|
25
|
+
catch (error) { if (allowMissing && missingRemoteFile(error)) return; throw error }
|
|
26
|
+
if (stat.isSymbolicLink?.() || !stat.isDirectory?.()) throw failure('远端父路径不是普通目录或含符号链接,未上传。', 403, 'LOCAL_COPY_UNSAFE_REMOTE_PATH')
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function resolveCopy(binding, target) {
|
|
31
|
+
if (!binding.bound || !binding.ws || !binding.mirrorDir) throw failure('An explicitly bound remote session is required', 403, 'LOCAL_COPY_UNBOUND')
|
|
32
|
+
const local = mirrorDownloadTarget(binding.mirrorDir, binding.ws, target)
|
|
33
|
+
assertDownloadHasNoSymlinks(binding.mirrorDir, local)
|
|
34
|
+
const root = await realpath(binding.mirrorDir), physical = await realpath(local)
|
|
35
|
+
const within = path.relative(root, physical)
|
|
36
|
+
if (!within || path.isAbsolute(within) || within.split(path.sep).includes('..')) throw failure('The local copy is outside this session workspace mirror', 403, 'LOCAL_COPY_UNSAFE')
|
|
37
|
+
const stat = await lstat(local)
|
|
38
|
+
if (!stat.isFile() || stat.isSymbolicLink()) throw failure('The local copy must be a regular file without symbolic links', 403, 'LOCAL_COPY_UNSAFE')
|
|
39
|
+
return { local, stat, relativePath: path.relative(path.resolve(binding.mirrorDir), local).split(path.sep).join('/') }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export async function localCopyInfo(binding, target) {
|
|
43
|
+
if (!binding.bound || !binding.mirrorDir) return null
|
|
44
|
+
try {
|
|
45
|
+
const copy = await resolveCopy(binding, target)
|
|
46
|
+
return { available: true, source: 'local-mirror', relativePath: copy.relativePath, size: copy.stat.size, mtime: Math.floor(copy.stat.mtimeMs / 1000) }
|
|
47
|
+
} catch (error) {
|
|
48
|
+
// A remote missing-file response is still truthful when a local candidate
|
|
49
|
+
// cannot be offered safely. Do not disclose files behind links/outside root.
|
|
50
|
+
if (error.code === 'ENOENT' || error.code === 'ENOTDIR' || error.httpStatus === 403) return null
|
|
51
|
+
throw error
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export async function readLocalCopy(binding, target, { maxFileBytes = 0 } = {}) {
|
|
56
|
+
let copy
|
|
57
|
+
try { copy = await resolveCopy(binding, target) }
|
|
58
|
+
catch (error) { if (error.code === 'ENOENT' || error.code === 'ENOTDIR') throw failure('本地副本已不存在。', 404, 'LOCAL_COPY_NOT_FOUND'); throw error }
|
|
59
|
+
const cap = maxFileBytes > 0 ? Math.min(maxFileBytes, HARD_CAP) : HARD_CAP
|
|
60
|
+
if (copy.stat.size > cap) throw failure(`本地副本超过 ${cap} bytes 的文本恢复上限。`, 413, 'LOCAL_COPY_TOO_LARGE')
|
|
61
|
+
if (/\.(?:png|jpe?g|gif|webp|bmp|ico|avif|pdf)$/i.test(target)) throw unsupported()
|
|
62
|
+
const handle = await open(copy.local, 'r')
|
|
63
|
+
let bytes
|
|
64
|
+
try {
|
|
65
|
+
const before = await handle.stat()
|
|
66
|
+
if (!sameFile(copy.stat, before)) throw changed()
|
|
67
|
+
// Resolve and recheck after opening; a replaced file or parent link must
|
|
68
|
+
// never turn an apparent mirror read into an unrelated local read.
|
|
69
|
+
const verified = await resolveCopy(binding, target)
|
|
70
|
+
if (!sameFile(copy.stat, verified.stat)) throw changed()
|
|
71
|
+
const buffer = Buffer.alloc(copy.stat.size + 1)
|
|
72
|
+
let offset = 0
|
|
73
|
+
while (offset < buffer.length) {
|
|
74
|
+
const result = await handle.read(buffer, offset, buffer.length - offset, offset)
|
|
75
|
+
if (!result.bytesRead) break
|
|
76
|
+
offset += result.bytesRead
|
|
77
|
+
}
|
|
78
|
+
if (offset !== copy.stat.size || !sameFile(copy.stat, await handle.stat())) throw changed()
|
|
79
|
+
bytes = buffer.subarray(0, offset)
|
|
80
|
+
} finally { await handle.close() }
|
|
81
|
+
if (bytes.includes(0)) throw unsupported()
|
|
82
|
+
let text
|
|
83
|
+
try { text = new TextDecoder('utf-8', { fatal: true }).decode(bytes) } catch { throw unsupported() }
|
|
84
|
+
return { bytes, preview: { ok: true, source: 'local-mirror', readOnly: true, path: target,
|
|
85
|
+
relativePath: copy.relativePath, content: text.replace(/\r\n/g, '\n'), localRevision: remoteRevision(bytes),
|
|
86
|
+
size: bytes.length, mtime: Math.floor(copy.stat.mtimeMs / 1000), binary: false, image: false, truncated: false } }
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export async function publishLocalCopy(binding, target, expectedLocalRevision, options = {}) {
|
|
90
|
+
if (typeof expectedLocalRevision !== 'string' || !/^[a-f0-9]{64}$/.test(expectedLocalRevision)) throw failure('A localRevision from the complete local-copy preview is required', 400, 'LOCAL_COPY_REVISION_REQUIRED')
|
|
91
|
+
const { bytes, preview } = await readLocalCopy(binding, target, options)
|
|
92
|
+
if (preview.localRevision !== expectedLocalRevision) throw changed()
|
|
93
|
+
const sftp = await binding.pool.sftp()
|
|
94
|
+
const existing = await sftp.lstat(target).catch(error => { if (missingRemoteFile(error)) return null; throw error })
|
|
95
|
+
if (existing) throw failure('远端已有同名文件,未覆盖。请重新读取并比较。', 409, 'REMOTE_FILE_EXISTS')
|
|
96
|
+
await checkRemoteParents(sftp, binding, target, true)
|
|
97
|
+
await mkdirRemoteDirs(sftp, remoteDirname(target))
|
|
98
|
+
await checkRemoteParents(sftp, binding, target, false)
|
|
99
|
+
try {
|
|
100
|
+
// This flag is forwarded to SSH_FXP_OPEN as CREAT|EXCL. A concurrent file
|
|
101
|
+
// appearing after lstat MUST fail at the server; no replace/rename follows.
|
|
102
|
+
await sftp.createFileExclusive(target, bytes)
|
|
103
|
+
} catch (error) {
|
|
104
|
+
if (error.exclusiveFileCreated) throw failure('上传未完整完成,远端可能留下新建的不完整文件;请检查远端后再重试。', 502, 'LOCAL_COPY_UPLOAD_INCOMPLETE')
|
|
105
|
+
if (error.exclusiveOpenFailed && [4, 11, 'EEXIST'].includes(error.code)) {
|
|
106
|
+
const appeared = await sftp.lstat(target).catch(probe => { if (missingRemoteFile(probe)) return null; throw error })
|
|
107
|
+
if (appeared) throw failure('远端已出现同名文件,上传未覆盖该文件;请重新读取并检查。', 409, 'REMOTE_FILE_EXISTS')
|
|
108
|
+
}
|
|
109
|
+
throw error
|
|
110
|
+
}
|
|
111
|
+
return { ok: true, source: 'remote', path: target, bytes: bytes.length, revision: remoteRevision(bytes) }
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function createLocalCopyRoutes({ sendJson, readBody, resolveRequestBinding, config, audit, onRemoteMutation = () => {} }) {
|
|
115
|
+
return ['read', 'publish'].map(action => ({ kind: 'exact', path: '/dsh-remote/local-copy/' + action, async handler(req, res) {
|
|
116
|
+
if (req.method !== 'POST') return sendJson(res, 405, { ok: false, error: 'method not allowed' })
|
|
117
|
+
try {
|
|
118
|
+
const body = JSON.parse((await readBody(req)) || '{}'), hint = requestSessionHint(req, body)
|
|
119
|
+
if (!hint.sessionId && !hint.local) throw failure('An explicit sessionId or local workspace context is required', 403, 'LOCAL_COPY_UNBOUND')
|
|
120
|
+
if (typeof body.path !== 'string' || !body.path.trim()) throw failure('path is required', 400, 'LOCAL_COPY_PATH_REQUIRED')
|
|
121
|
+
const target = normalizeRemotePath(body.path), binding = await resolveRequestBinding(req, body)
|
|
122
|
+
if (action === 'read') return sendJson(res, 200, (await readLocalCopy(binding, target, config)).preview)
|
|
123
|
+
const result = await publishLocalCopy(binding, target, body.expectedLocalRevision, config)
|
|
124
|
+
audit?.('publish-local-copy', `publish ${target}`, 0, binding)
|
|
125
|
+
onRemoteMutation()
|
|
126
|
+
return sendJson(res, 200, result)
|
|
127
|
+
} catch (error) { return sendJson(res, error.httpStatus || 500, { ok: false, error: error.message || String(error), ...(error.code ? { code: error.code } : {}) }) }
|
|
128
|
+
} }))
|
|
129
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Native filesystem tools operate on the host mirror, not its SSH origin.
|
|
2
|
+
// Use the same gate for root native calls and nested PTC dispatches.
|
|
3
|
+
export const LOCAL_MUTATION_TOOLS = new Set(['write', 'edit', 'str_replace_editor'])
|
|
4
|
+
export function remoteLocalMutationDecision(exec, binding) {
|
|
5
|
+
if (!binding?.bound || !LOCAL_MUTATION_TOOLS.has(exec?.name)) return null
|
|
6
|
+
if (exec.name === 'str_replace_editor' && exec.arguments?.command === 'view') return null
|
|
7
|
+
return { kind: 'deny', reason: `${exec.name} was not executed: this session is a REMOTE workspace, but this tool writes only the LOCAL mirror. Use rw_write_file to create remote files or rw_edit to modify them; workspace-relative paths and local-mirror paths are accepted. A local write does not publish a remote file or make a remote file link valid. If a local artifact already exists, explicitly upload it with rw_push/rw_upload and verify it remotely before reporting a remote link.` }
|
|
8
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Files crossing between a remote workspace and its local mirror must obey
|
|
2
|
+
// both path grammars and must never traverse local symlinks.
|
|
3
|
+
import { lstatSync } from 'node:fs'
|
|
4
|
+
import path from 'node:path'
|
|
5
|
+
import { normalizeRemotePath } from './paths.js'
|
|
6
|
+
|
|
7
|
+
const unsafeDownload = () => Object.assign(new Error('The download destination must be a regular file inside this workspace mirror'), { httpStatus: 403 })
|
|
8
|
+
|
|
9
|
+
// Remote POSIX names may contain backslashes that become separators on a
|
|
10
|
+
// Windows host. Resolve in each filesystem's own grammar, never by prefix.
|
|
11
|
+
export function mirrorDownloadTarget(base, workspace, remote, localPath = path) {
|
|
12
|
+
const remotePath = /^(?:[a-z]:[\\/]|\\\\)/i.test(workspace) ? path.win32 : path.posix
|
|
13
|
+
const relative = remotePath.relative(normalizeRemotePath(workspace), normalizeRemotePath(remote))
|
|
14
|
+
if (!relative || remotePath.isAbsolute(relative) || relative.split(remotePath.sep).some(part => part === '..') || relative.includes('\0')) throw unsafeDownload()
|
|
15
|
+
const parts = relative.split(remotePath.sep)
|
|
16
|
+
// This local-only record determines the session's remote identity.
|
|
17
|
+
if (parts.length === 1 && (localPath.sep === '\\' ? parts[0].toLowerCase() : parts[0]) === '.dsh-remote-meta.json') throw unsafeDownload()
|
|
18
|
+
if (localPath.sep === '\\' && parts.some(part => /[<>:"|?*\\\x00-\x1f]/.test(part) || /[. ]$/.test(part) || /^(con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i.test(part))) throw unsafeDownload()
|
|
19
|
+
const root = localPath.resolve(base), target = localPath.resolve(root, ...parts)
|
|
20
|
+
const within = localPath.relative(root, target)
|
|
21
|
+
if (!within || localPath.isAbsolute(within) || within.split(localPath.sep).some(part => part === '..')) throw unsafeDownload()
|
|
22
|
+
return target
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function assertDownloadHasNoSymlinks(base, target) {
|
|
26
|
+
const root = path.resolve(base)
|
|
27
|
+
let current = root
|
|
28
|
+
for (const segment of ['', ...path.relative(root, target).split(path.sep)]) {
|
|
29
|
+
if (segment) current = path.join(current, segment)
|
|
30
|
+
try { if (lstatSync(current).isSymbolicLink()) throw unsafeDownload() }
|
|
31
|
+
catch (error) { if (error.code !== 'ENOENT') throw error }
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
package/lib/routes-fs.js
CHANGED
|
@@ -6,8 +6,11 @@
|
|
|
6
6
|
// same mirror binding as rw_* tools and never fall back to the active machine.
|
|
7
7
|
// URLSearchParams already decodes query paths. Another decoding pass corrupts
|
|
8
8
|
// literal percent characters and names containing sequences such as `%2F`.
|
|
9
|
-
import {
|
|
9
|
+
import { mkdirSync } from 'node:fs'
|
|
10
10
|
import path from 'node:path'
|
|
11
|
+
import { mirrorDownloadTarget, assertDownloadHasNoSymlinks } from './mirror-paths.js'
|
|
12
|
+
export { mirrorDownloadTarget } from './mirror-paths.js'
|
|
13
|
+
import { createLocalCopyRoutes, localCopyInfo } from './local-copy.js'
|
|
11
14
|
import {
|
|
12
15
|
normalizeRemotePath, joinRemotePath, remoteDirname, mkdirRemoteDirs, toDisplayPath,
|
|
13
16
|
} from './paths.js'
|
|
@@ -15,34 +18,6 @@ import { requestSessionHint } from './binding.js'
|
|
|
15
18
|
import { captureRemoteFile, atomicRemoteWrite, remoteRevision, missingRemoteFile } from './remote-write.js'
|
|
16
19
|
import { listDirStructured, listRemoteDrives, removeRemoteTree, previewRemoteFile } from './remote-fs.js'
|
|
17
20
|
|
|
18
|
-
const unsafeDownload = () => Object.assign(new Error('The download destination must be a regular file inside this workspace mirror'), { httpStatus: 403 })
|
|
19
|
-
|
|
20
|
-
// Remote POSIX names may contain backslashes that become separators on a
|
|
21
|
-
// Windows host. Resolve in each filesystem's own grammar, never by prefix.
|
|
22
|
-
export function mirrorDownloadTarget(base, workspace, remote, localPath = path) {
|
|
23
|
-
const remotePath = /^(?:[a-z]:[\\/]|\\\\)/i.test(workspace) ? path.win32 : path.posix
|
|
24
|
-
const relative = remotePath.relative(normalizeRemotePath(workspace), normalizeRemotePath(remote))
|
|
25
|
-
if (!relative || remotePath.isAbsolute(relative) || relative.split(remotePath.sep).some(part => part === '..') || relative.includes('\0')) throw unsafeDownload()
|
|
26
|
-
const parts = relative.split(remotePath.sep)
|
|
27
|
-
// This local-only record determines the session's remote identity.
|
|
28
|
-
if (parts.length === 1 && (localPath.sep === '\\' ? parts[0].toLowerCase() : parts[0]) === '.dsh-remote-meta.json') throw unsafeDownload()
|
|
29
|
-
if (localPath.sep === '\\' && parts.some(part => /[<>:"|?*\\\x00-\x1f]/.test(part) || /[. ]$/.test(part) || /^(con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i.test(part))) throw unsafeDownload()
|
|
30
|
-
const root = localPath.resolve(base), target = localPath.resolve(root, ...parts)
|
|
31
|
-
const within = localPath.relative(root, target)
|
|
32
|
-
if (!within || localPath.isAbsolute(within) || within.split(localPath.sep).some(part => part === '..')) throw unsafeDownload()
|
|
33
|
-
return target
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function assertDownloadHasNoSymlinks(base, target) {
|
|
37
|
-
const root = path.resolve(base)
|
|
38
|
-
let current = root
|
|
39
|
-
for (const segment of ['', ...path.relative(root, target).split(path.sep)]) {
|
|
40
|
-
if (segment) current = path.join(current, segment)
|
|
41
|
-
try { if (lstatSync(current).isSymbolicLink()) throw unsafeDownload() }
|
|
42
|
-
catch (error) { if (error.code !== 'ENOENT') throw error }
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
21
|
export function createFsRoutes({
|
|
47
22
|
sendJson,
|
|
48
23
|
readBody,
|
|
@@ -81,6 +56,7 @@ export function createFsRoutes({
|
|
|
81
56
|
}
|
|
82
57
|
|
|
83
58
|
return [
|
|
59
|
+
...createLocalCopyRoutes({ sendJson, readBody, resolveRequestBinding, config, audit, onRemoteMutation }),
|
|
84
60
|
{
|
|
85
61
|
kind: 'exact',
|
|
86
62
|
path: '/dsh-remote/ls',
|
|
@@ -179,6 +155,14 @@ export function createFsRoutes({
|
|
|
179
155
|
})
|
|
180
156
|
return sendJson(res, 200, preview)
|
|
181
157
|
} catch (err) {
|
|
158
|
+
if (missingRemoteFile(err)) {
|
|
159
|
+
const localCopy = await localCopyInfo(b, target)
|
|
160
|
+
return sendJson(res, 404, { ok: false, source: 'remote', path: target,
|
|
161
|
+
code: localCopy ? 'REMOTE_FILE_MISSING_LOCAL_COPY' : 'REMOTE_FILE_NOT_FOUND',
|
|
162
|
+
error: localCopy ? '远端不存在此文件。本地镜像有同名副本,但尚未确认上传;可只读查看后显式上传。' : '远端不存在此文件。',
|
|
163
|
+
...(localCopy ? { localCopy } : {}),
|
|
164
|
+
})
|
|
165
|
+
}
|
|
182
166
|
return sendJson(res, 500, { ok: false, error: 'read failed: ' + ((err && err.message) || err) })
|
|
183
167
|
}
|
|
184
168
|
} catch (err) {
|
package/lib/sftp-surface.js
CHANGED
|
@@ -101,6 +101,22 @@ export function buildSftpSurface(sftp, { commandTimeoutMs, onTimeout }) {
|
|
|
101
101
|
setstat: (p, attrs) => withTimeout((d, a, cb) => sftp.setstat(d, a, cb))(P(p), attrs),
|
|
102
102
|
readFile: (p) => withTimeout((d, cb) => sftp.readFile(d, cb))(P(p)),
|
|
103
103
|
writeFile: (p, data, options) => withTimeout((d, data2, cb) => options ? sftp.writeFile(d, data2, options, cb) : sftp.writeFile(d, data2, cb))(P(p), data),
|
|
104
|
+
// Recovery publishing must reserve the destination on the SERVER. Never
|
|
105
|
+
// replace an existing file, including one created by a concurrent request.
|
|
106
|
+
createFileExclusive: async (p, data) => {
|
|
107
|
+
let created = false
|
|
108
|
+
try {
|
|
109
|
+
await withTimeout((d, bytes, cb) => {
|
|
110
|
+
sftp.open(d, 'wx', { mode: 0o600 }, (error, handle) => {
|
|
111
|
+
if (error) { error.exclusiveOpenFailed = true; return cb(error) }
|
|
112
|
+
created = true
|
|
113
|
+
sftp.write(handle, bytes, 0, bytes.length, 0, writeError => {
|
|
114
|
+
sftp.close(handle, closeError => cb(writeError || closeError))
|
|
115
|
+
})
|
|
116
|
+
})
|
|
117
|
+
})(P(p), data)
|
|
118
|
+
} catch (error) { error.exclusiveFileCreated = created; throw error }
|
|
119
|
+
},
|
|
104
120
|
fastGet: (p, lp) => withTimeout((d, l, cb) => sftp.fastGet(d, l, cb))(P(p), lp),
|
|
105
121
|
fastPut: (lp, p) => withTimeout((l, d, cb) => sftp.fastPut(l, d, cb))(lp, P(p)),
|
|
106
122
|
// Range read for oversized previews: never downloads the whole file.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-remote",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Remote SSH development for DeepSeek Harness: optional IDE layout, remote file and content search, native editor and terminal tabs, Git diffs, and agent tools with compiler diagnostics.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "flymysql <flyphp@outlook.com>",
|
|
@@ -102,6 +102,6 @@
|
|
|
102
102
|
"test:coverage": "node scripts/coverage-union.mjs",
|
|
103
103
|
"test:coverage:gate": "node scripts/coverage-union.mjs --gate 70 --file-gate 60"
|
|
104
104
|
},
|
|
105
|
-
"readme": "[English](https://github.com/flymysql/dsh-remote/blob/main/README.en.md) · **中文**\n\n# dsh-remote\n\n[](https://www.npmjs.com/package/dsh-remote)\n[](https://www.npmjs.com/package/dsh-remote)\n[](https://www.npmjs.com/package/dsh-remote)\n[](https://github.com/flymysql/dsh-remote/blob/main/LICENSE)\n[](https://github.com/topics/dsh-plugin)\n\n由 [@flymysql](https://github.com/flymysql) 维护 · [主页](https://flymysql.github.io/dsh-remote/) · [用量统计](https://flymysql.github.io/dsh-remote/stats/) · [博客](https://gitpull.cn) · [讨论区](https://github.com/flymysql/dsh-remote/discussions) · [Issue](https://github.com/flymysql/dsh-remote/issues) · [English](https://github.com/flymysql/dsh-remote/blob/main/README.en.md)\n\n在 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) 中,把 SSH 主机变成日常开发工作区:浏览远程文件、编辑代码、运行终端,让 Agent 在同一远端完成任务。多个工作区可并行连接不同主机。\n\n**IDE 模式:左侧文件,中间编辑器,右侧原生 Agent 会话。** 可调整栏宽;窄屏切换文件、编辑器与会话。切回普通布局保留任务和未保存编辑。\n\n<img src=\"https://raw.githubusercontent.com/flymysql/dsh-remote/main/docs/shots/workbench-ide.png\" alt=\"DSH 远程工作区 IDE 模式:远程文件树、代码编辑器和原生 Agent 会话三栏\" width=\"1200\"/>\n\n## 安装\n\n```bash\ndsh plugin --profile web add dsh-remote\n```\n\n安装或升级后,重启 DSH Web 并刷新页面。自动更新状态在设置 → 远程工作区 → 插件偏好中查看。\n\n## 3 步开始\n\n1. **配置主机**:设置 → 远程工作区,编辑 SSH 配置或保存主机凭据;打开设置会自动检查连通性,无需手动“连接”。\n2. **创建工作区**:添加工作区 → 远程,选择主机与目录。每个工作区独立绑定主机,设置页不选目录或“当前远程机”。\n3. **开始开发**:打开工作区文件或切换 IDE
|
|
105
|
+
"readme": "[English](https://github.com/flymysql/dsh-remote/blob/main/README.en.md) · **中文**\n\n# dsh-remote\n\n[](https://www.npmjs.com/package/dsh-remote)\n[](https://www.npmjs.com/package/dsh-remote)\n[](https://www.npmjs.com/package/dsh-remote)\n[](https://github.com/flymysql/dsh-remote/blob/main/LICENSE)\n[](https://github.com/topics/dsh-plugin)\n\n由 [@flymysql](https://github.com/flymysql) 维护 · [主页](https://flymysql.github.io/dsh-remote/) · [用量统计](https://flymysql.github.io/dsh-remote/stats/) · [博客](https://gitpull.cn) · [讨论区](https://github.com/flymysql/dsh-remote/discussions) · [Issue](https://github.com/flymysql/dsh-remote/issues) · [English](https://github.com/flymysql/dsh-remote/blob/main/README.en.md)\n\n\n\n在 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) 中,把 SSH 主机变成日常开发工作区:浏览远程文件、编辑代码、运行终端,让 Agent 在同一远端完成任务。多个工作区可并行连接不同主机。\n\n**IDE 模式:左侧文件,中间编辑器,右侧原生 Agent 会话。** 可调整栏宽;窄屏切换文件、编辑器与会话。切回普通布局保留任务和未保存编辑。\n\n<img src=\"https://raw.githubusercontent.com/flymysql/dsh-remote/main/docs/shots/workbench-ide.png\" alt=\"DSH 远程工作区 IDE 模式:远程文件树、代码编辑器和原生 Agent 会话三栏\" width=\"1200\"/>\n\n## 安装\n\n```bash\ndsh plugin --profile web add dsh-remote\n```\n\n安装或升级后,重启 DSH Web 并刷新页面。自动更新状态在设置 → 远程工作区 → 插件偏好中查看。\n\n## 3 步开始\n\n1. **配置主机**:设置 → 远程工作区,编辑 SSH 配置或保存主机凭据;打开设置会自动检查连通性,无需手动“连接”。\n2. **创建工作区**:添加工作区 → 远程,选择主机与目录。每个工作区独立绑定主机,设置页不选目录或“当前远程机”。\n3. **开始开发**:打开工作区文件或切换 IDE 模式,文件打开即可编辑并显示语法高亮,在远端搜索、运行命令并与 Agent 协作。\n\n<img src=\"https://raw.githubusercontent.com/flymysql/dsh-remote/main/docs/shots/workspace-picker-browse.png\" alt=\"选择远程目录:固定路径与确认栏,目录列表占据弹窗主要区域\" width=\"720\"/>\n\n## 日常开发\n\n### 搜索远端文件与内容\n\n文件、目录和内容递归搜索,无需先展开目录或同步镜像。默认界面只显示搜索范围与进度摘要;按需展开搜索选项、扫描详情,支持大小写、忽略项、停止与重试。点击结果进入目录或文件对应行。\n\n<img src=\"https://raw.githubusercontent.com/flymysql/dsh-remote/main/docs/shots/workbench-search-results.png\" alt=\"简洁远程搜索:名称搜索结果包含嵌套目录与文件\" width=\"675\"/>\n\n### 查看远端 Git 改动\n\n分别查看工作区和已暂存 diff,筛选文件,点击改动行定位源码。面板只读,不提交或修改暂存区。\n\n<img src=\"https://raw.githubusercontent.com/flymysql/dsh-remote/main/docs/shots/workbench-git.png\" alt=\"远端 Git 工作区与已暂存改动、文件列表和源码 diff\" width=\"675\"/>\n\n### 在远端运行终端\n\n终端进入当前会话的远程目录;像素鱼欢迎图后接真实 SSH shell。已保存凭据可自动应答,支持多终端并行。\n\n<img src=\"https://raw.githubusercontent.com/flymysql/dsh-remote/main/docs/shots/workbench-terminal.png\" alt=\"DSH 远程终端:像素鱼欢迎图与实际 SSH 命令输出\" width=\"1000\"/>\n\n### 与 Agent 一起修改和构建\n\n工具卡展示已应用改动、实际退出码和构建输出,编译诊断可跳转源码。编辑器保存会检测远端冲突、保留 CRLF,并保护保存期间继续输入的内容。\n\n<img src=\"https://raw.githubusercontent.com/flymysql/dsh-remote/main/docs/shots/workbench-applied-diff.png\" alt=\"Agent 远程编辑成功后的已应用 diff、路径与增删行数\" width=\"485\"/>\n\n## 兼容与边界\n\n- 主要面向 **DSH Web 0.2.x**;0.2.2 需要 **Node.js ≥24.9**。旧版宿主回退、Desktop/TUI 与 Agent diff 差异见[兼容说明](https://github.com/flymysql/dsh-remote/blob/main/docs/reference.zh.md#dsh-版本兼容性)。\n- 文件栏直接访问远端;镜像按需同步。草稿在当前页面内存,崩溃或强制退出仍可能丢失。\n- 不提供远端语言服务、扩展宿主或调试器。Agent 使用配置的 SSH 身份执行命令,请只配置可信主机。\n\n## 文档与社区\n\n[完整工具与配置参考](https://github.com/flymysql/dsh-remote/blob/main/docs/reference.zh.md) · [排障](https://github.com/flymysql/dsh-remote/blob/main/docs/troubleshooting.md) · [升级指南](https://github.com/flymysql/dsh-remote/blob/main/docs/migration-1.0.md) · [更新记录](https://github.com/flymysql/dsh-remote/blob/main/CHANGELOG.md)\n\n[主页](https://flymysql.github.io/dsh-remote/) · [讨论区](https://github.com/flymysql/dsh-remote/discussions) · [反馈问题](https://github.com/flymysql/dsh-remote/issues) · [贡献指南](https://github.com/flymysql/dsh-remote/blob/main/CONTRIBUTING.md) · [贡献者与致谢](#贡献者与致谢)\n\n由 [@flymysql](https://github.com/flymysql) 与社区共同维护 · [MIT](https://github.com/flymysql/dsh-remote/blob/main/LICENSE)\n\n### 贡献者与致谢\n\n感谢每一位让这个项目更好的朋友(头像可点进主页;按提交数排序,机器人不计):\n\n<p align=\"left\">\n <a href=\"https://github.com/flymysql\"><img src=\"https://avatars.githubusercontent.com/u/37113068?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@flymysql\" title=\"@flymysql\" /></a>\n <a href=\"https://github.com/baiseraku\"><img src=\"https://avatars.githubusercontent.com/u/139727690?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@baiseraku\" title=\"@baiseraku\" /></a>\n <a href=\"https://github.com/glzhangzhi\"><img src=\"https://avatars.githubusercontent.com/u/36995275?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@glzhangzhi\" title=\"@glzhangzhi\" /></a>\n <a href=\"https://github.com/hjwsm1989\"><img src=\"https://avatars.githubusercontent.com/u/1067541?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@hjwsm1989\" title=\"@hjwsm1989\" /></a>\n <a href=\"https://github.com/j10ha0\"><img src=\"https://avatars.githubusercontent.com/u/72346906?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@j10ha0\" title=\"@j10ha0\" /></a>\n <a href=\"https://github.com/FoolishWiser\"><img src=\"https://avatars.githubusercontent.com/u/104308087?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@FoolishWiser\" title=\"@FoolishWiser\" /></a>\n <a href=\"https://github.com/kakaa-nju\"><img src=\"https://avatars.githubusercontent.com/u/79886619?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@kakaa-nju\" title=\"@kakaa-nju\" /></a>\n <a href=\"https://github.com/4FMTWRV\"><img src=\"https://avatars.githubusercontent.com/u/190457700?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@4FMTWRV\" title=\"@4FMTWRV\" /></a>\n <a href=\"https://github.com/dahaipeng\"><img src=\"https://avatars.githubusercontent.com/u/25660610?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@dahaipeng\" title=\"@dahaipeng\" /></a>\n <a href=\"https://github.com/davidlin2k\"><img src=\"https://avatars.githubusercontent.com/u/17074619?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@davidlin2k\" title=\"@davidlin2k\" /></a>\n <a href=\"https://github.com/FlintyLemming\"><img src=\"https://avatars.githubusercontent.com/u/19165511?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@FlintyLemming\" title=\"@FlintyLemming\" /></a>\n <a href=\"https://github.com/GDWhisper\"><img src=\"https://avatars.githubusercontent.com/u/129148123?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@GDWhisper\" title=\"@GDWhisper\" /></a>\n <a href=\"https://github.com/YiHui-Liu\"><img src=\"https://avatars.githubusercontent.com/u/30190271?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@YiHui-Liu\" title=\"@YiHui-Liu\" /></a>\n <a href=\"https://github.com/Minggle\"><img src=\"https://avatars.githubusercontent.com/u/35053182?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@Minggle\" title=\"@Minggle\" /></a>\n <a href=\"https://github.com/nekomona\"><img src=\"https://avatars.githubusercontent.com/u/25474483?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@nekomona\" title=\"@nekomona\" /></a>\n <a href=\"https://github.com/shis23\"><img src=\"https://avatars.githubusercontent.com/u/189869650?s=80&v=4\" width=\"40\" height=\"40\" alt=\"@shis23\" title=\"@shis23\" /></a>\n</p>\n\n<details>\n<summary>贡献记录与早期贡献者</summary>\n\n近期的亮点贡献(欢迎随时加入这个名单):\n\n| 贡献者 | 做了什么 |\n| --- | --- |\n| [@baiseraku](https://github.com/baiseraku) | 整个 dsh-tui 适配层([#92](https://github.com/flymysql/dsh-remote/pull/92))+ 底栏机器名修正([#98](https://github.com/flymysql/dsh-remote/pull/98)) |\n| [@hjwsm1989](https://github.com/hjwsm1989) | 远程 .md 渲染连环两道:memo 守卫([#102](https://github.com/flymysql/dsh-remote/pull/102))+ labels 契约([#107](https://github.com/flymysql/dsh-remote/pull/107)) |\n| [@shis23](https://github.com/shis23) | rw_sync 路径映射纠偏 + SFTP 超时韧性([#105](https://github.com/flymysql/dsh-remote/pull/105)) |\n| [@davidlin2k](https://github.com/davidlin2k) | 无凭据机器走用户自有 ssh([#100](https://github.com/flymysql/dsh-remote/pull/100)) |\n| [@GDWhisper](https://github.com/GDWhisper) | 目录补全逐字符重连修复([#42](https://github.com/flymysql/dsh-remote/pull/42),issue #41) |\n| [@glzhangzhi](https://github.com/glzhangzhi) | 多远端会话的连接池隔离(issue #25 的主体修复) |\n\n早期已合并 PR 的贡献者(考古名单):\n\n\n\n[@dahaipeng](https://github.com/dahaipeng) (#31) ·\n[@YiHui-Liu](https://github.com/YiHui-Liu) (#28) ·\n[@nekomona](https://github.com/nekomona) (#24) ·\n[@zhz1667](https://github.com/zhz1667) (#43) ·\n[FoolishWiser](https://github.com/FoolishWiser) (#17) ·\n[@jace1cch](https://github.com/jace1cch) (#16) ·\n[@Minggle](https://github.com/Minggle) (#10) ·\n[4FMTWRV](https://github.com/4FMTWRV) (#6) ·\n[glzhangzhi](https://github.com/glzhangzhi)(per-session SSH 连接池修复)\n\n> 名单随版本更新;头像墙之外的每一份 issue 报告、复现步骤、根因线索同样珍贵——\n> 本仓库近半修复的起点都是一条写清楚的 issue。\n\n</details>\n",
|
|
106
106
|
"readmeFilename": "README.md"
|
|
107
107
|
}
|