dsh-gufa-code 1.0.0 → 1.0.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.md +1 -4
- package/client.js +403 -26
- package/docs/screenshot-ide.jpg +0 -0
- package/host/fs.js +95 -0
- package/host/git.js +0 -112
- package/package.json +3 -2
- package/screenshots.json +3 -0
- package/scripts/test-editor.mjs +4 -13
- package/src/client/00-core.js +5 -0
- package/src/client/20-editor.js +54 -9
- package/src/client/50-panels.js +96 -0
- package/src/client/58-insert-ref.js +156 -0
- package/src/client/90-app.js +48 -17
- package/src/client/99-main.js +41 -0
- package/vendor/monaco/vs/worker-bootstrap.js +16 -0
- package/docs/screenshot-editor.jpg +0 -0
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
> 在 DeepSeek Harness 里一键进入 VS Code 风格的 IDE 模式:左边写代码,右边就是当前 DSH 会话本人 —— 它会改文件、跑终端、提审批,你全看得见。
|
|
5
5
|
|
|
6
6
|
<p align="center">
|
|
7
|
-
<img src="docs/screenshot-ide.jpg" width="
|
|
7
|
+
<img src="docs/screenshot-ide.jpg" width="900" alt="古法编程 IDE 模式:左侧资源管理器与 Monaco 编辑器,右侧官方 DSH 会话">
|
|
8
8
|
</p>
|
|
9
9
|
|
|
10
10
|
## 这是什么
|
|
@@ -17,9 +17,6 @@
|
|
|
17
17
|
|
|
18
18
|
从哪个工作区点进来,IDE 就打开哪个工作区,右侧也自动是你在这个工作区正在聊的那个会话。
|
|
19
19
|
|
|
20
|
-
<p align="center">
|
|
21
|
-
<img src="docs/screenshot-editor.jpg" width="820" alt="编辑器与皮肤背景">
|
|
22
|
-
</p>
|
|
23
20
|
|
|
24
21
|
## 安装
|
|
25
22
|
|
package/client.js
CHANGED
|
@@ -1249,6 +1249,8 @@ html[data-platform=darwin][data-fullscreen] .gufa-titlebar{height:44px;padding-l
|
|
|
1249
1249
|
.gufa-project{appearance:none;border:0;background:transparent;font:inherit;color:inherit;cursor:pointer}
|
|
1250
1250
|
.gufa-project:hover{background:var(--gufa-hover)}
|
|
1251
1251
|
.gufa-workspace-row{height:auto;min-height:38px;padding:5px 8px}
|
|
1252
|
+
.gufa-workspace-row-wrap{display:flex;align-items:center;gap:4px}
|
|
1253
|
+
.gufa-workspace-row-wrap .gufa-workspace-row{flex:1 1 auto;min-width:0}
|
|
1252
1254
|
.gufa-workspace-title{display:block;font-size:12px;line-height:1.3}
|
|
1253
1255
|
.gufa-workspace-path{display:block;font-size:10.5px;color:var(--gufa-text-dim);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
1254
1256
|
.gufa-project{display:flex;align-items:center;gap:6px;min-width:0;margin-left:6px;padding:3px 9px;border-radius:7px;
|
|
@@ -1327,6 +1329,9 @@ html[data-platform=darwin][data-fullscreen] .gufa-titlebar{height:44px;padding-l
|
|
|
1327
1329
|
.gufa-tree-row[data-selected]{background:var(--gufa-active)}
|
|
1328
1330
|
.gufa-tree-row[data-kind="dir"]{color:var(--gufa-text)}
|
|
1329
1331
|
.gufa-tree-name{overflow:hidden;text-overflow:ellipsis;flex:1 1 auto;min-width:0}
|
|
1332
|
+
.gufa-explorer-notice{margin:4px 10px 0;padding:3px 8px;border-radius:6px;font-size:11px;line-height:1.5;color:var(--gufa-text);
|
|
1333
|
+
background:color-mix(in srgb, var(--gufa-accent) 14%, transparent);border:0.5px solid color-mix(in srgb, var(--gufa-accent) 40%, transparent);
|
|
1334
|
+
overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
1330
1335
|
.gufa-tree-chevron{width:14px;flex:0 0 auto;opacity:.7;display:flex;align-items:center;justify-content:center}
|
|
1331
1336
|
.gufa-tree-icon{width:15px;flex:0 0 auto;opacity:.85;display:flex;align-items:center;justify-content:center}
|
|
1332
1337
|
.gufa-tree-badge{font-size:10px;color:var(--gufa-accent);flex:0 0 auto;font-weight:600}
|
|
@@ -2139,7 +2144,14 @@ G.FooterAction = function FooterAction(props) {
|
|
|
2139
2144
|
) {
|
|
2140
2145
|
return
|
|
2141
2146
|
}
|
|
2142
|
-
const
|
|
2147
|
+
const workerBase = (() => {
|
|
2148
|
+
try {
|
|
2149
|
+
return new URL(G.asset('monaco'), G.serverBase()).href
|
|
2150
|
+
} catch {
|
|
2151
|
+
return G.asset('monaco')
|
|
2152
|
+
}
|
|
2153
|
+
})()
|
|
2154
|
+
const getWorker = (moduleId, label) => gufaCreateMonacoWorker(workerBase, label)
|
|
2143
2155
|
if (existing !== undefined && existing !== null && typeof existing === 'object') {
|
|
2144
2156
|
existing.getWorker = getWorker
|
|
2145
2157
|
return
|
|
@@ -2158,13 +2170,35 @@ G.FooterAction = function FooterAction(props) {
|
|
|
2158
2170
|
}
|
|
2159
2171
|
|
|
2160
2172
|
function gufaCreateMonacoWorker(base, label) {
|
|
2161
|
-
const
|
|
2162
|
-
const
|
|
2173
|
+
const name = typeof label === 'string' && label !== '' ? label : 'gufa-monaco-worker'
|
|
2174
|
+
const watch = (worker, sourceUrl) => {
|
|
2175
|
+
try {
|
|
2176
|
+
worker.addEventListener('error', (event) => {
|
|
2177
|
+
void G.api('dev.log', {
|
|
2178
|
+
message: `monaco-worker-error src=${sourceUrl} message=${String(event && event.message)} file=${String(event && event.filename)} line=${String(event && event.lineno)}`,
|
|
2179
|
+
}).catch(() => {})
|
|
2180
|
+
})
|
|
2181
|
+
worker.addEventListener('messageerror', () => {
|
|
2182
|
+
void G.api('dev.log', { message: `monaco-worker-messageerror src=${sourceUrl}` }).catch(() => {})
|
|
2183
|
+
})
|
|
2184
|
+
void G.api('dev.log', { message: `monaco-worker-created src=${sourceUrl}` }).catch(() => {})
|
|
2185
|
+
} catch {
|
|
2186
|
+
/* ignore */
|
|
2187
|
+
}
|
|
2188
|
+
return worker
|
|
2189
|
+
}
|
|
2163
2190
|
try {
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2191
|
+
const url = `${G.asset('monaco')}/worker-bootstrap.js?v=3`
|
|
2192
|
+
return watch(new Worker(url, { name }), url)
|
|
2193
|
+
} catch (error) {
|
|
2194
|
+
const blob = new Blob([gufaWorkerScript(base)], { type: 'text/javascript' })
|
|
2195
|
+
const url = URL.createObjectURL(blob)
|
|
2196
|
+
void G.api('dev.log', { message: `monaco-worker-construct-failed ${String(error && error.message)} fallback=blob` }).catch(() => {})
|
|
2197
|
+
try {
|
|
2198
|
+
return watch(new Worker(url, { name }), url)
|
|
2199
|
+
} finally {
|
|
2200
|
+
window.setTimeout(() => URL.revokeObjectURL(url), 10000)
|
|
2201
|
+
}
|
|
2168
2202
|
}
|
|
2169
2203
|
}
|
|
2170
2204
|
|
|
@@ -2397,6 +2431,8 @@ G.FooterAction = function FooterAction(props) {
|
|
|
2397
2431
|
const diffEditorRef = useRef(null)
|
|
2398
2432
|
const diffModelsRef = useRef([])
|
|
2399
2433
|
const diffSignatureRef = useRef(null)
|
|
2434
|
+
const diffAnchorsRef = useRef([])
|
|
2435
|
+
const diffZoneIdsRef = useRef([])
|
|
2400
2436
|
const monacoRef = useRef(null)
|
|
2401
2437
|
const modelsRef = useRef(new Map()) /* path -> ITextModel */
|
|
2402
2438
|
const viewStatesRef = useRef(new Map()) /* path -> editor view state(滚动/光标) */
|
|
@@ -2861,6 +2897,8 @@ G.FooterAction = function FooterAction(props) {
|
|
|
2861
2897
|
}
|
|
2862
2898
|
diffModelsRef.current = []
|
|
2863
2899
|
diffSignatureRef.current = null
|
|
2900
|
+
diffAnchorsRef.current = []
|
|
2901
|
+
diffZoneIdsRef.current = []
|
|
2864
2902
|
}
|
|
2865
2903
|
if (status !== 'ready' || activeIsDiff !== true) {
|
|
2866
2904
|
disposeDiff()
|
|
@@ -2884,7 +2922,7 @@ G.FooterAction = function FooterAction(props) {
|
|
|
2884
2922
|
const language = typeof tab.language === 'string' && tab.language !== '' ? tab.language : 'plaintext'
|
|
2885
2923
|
const key = encodeURIComponent(String(tab.path))
|
|
2886
2924
|
const suffix = String(Date.now())
|
|
2887
|
-
const leftText = tab.diff.compare === true && typeof tab.compareLeft === 'string' ? tab.compareLeft : tab.diff.left
|
|
2925
|
+
const leftText = tab.diff.compare === true && typeof tab.compareLeft === 'string' ? tab.compareLeft : String(tab.diff.left ?? '')
|
|
2888
2926
|
const originalModel = monaco.editor.createModel(String(leftText ?? ''), language, monaco.Uri.parse(`gufa-diff://original/${key}/${suffix}`))
|
|
2889
2927
|
const modifiedModel = monaco.editor.createModel(String(tab.content ?? ''), language, monaco.Uri.parse(`gufa-diff://modified/${key}/${suffix}`))
|
|
2890
2928
|
let instance
|
|
@@ -2971,6 +3009,17 @@ G.FooterAction = function FooterAction(props) {
|
|
|
2971
3009
|
} catch {
|
|
2972
3010
|
/* ignore */
|
|
2973
3011
|
}
|
|
3012
|
+
/* 诊断:2 秒后如果差异仍然是 null,说明 Monaco worker 没起来(dsh-app:// 下的 worker 限制) */
|
|
3013
|
+
window.setTimeout(() => {
|
|
3014
|
+
try {
|
|
3015
|
+
const changes = typeof instance.getLineChanges === 'function' ? instance.getLineChanges() : null
|
|
3016
|
+
void G.api('dev.log', {
|
|
3017
|
+
message: `diff-open path=${tab.path} leftLen=${String(leftText ?? '').length} rightLen=${String(tab.content ?? '').length} hostW=${host !== null ? host.clientWidth : -1} changes=${Array.isArray(changes) ? changes.length : String(changes)}`,
|
|
3018
|
+
}).catch(() => {})
|
|
3019
|
+
} catch {
|
|
3020
|
+
/* ignore */
|
|
3021
|
+
}
|
|
3022
|
+
}, 2000)
|
|
2974
3023
|
return () => {
|
|
2975
3024
|
try {
|
|
2976
3025
|
sub.dispose()
|
|
@@ -3093,7 +3142,8 @@ G.FooterAction = function FooterAction(props) {
|
|
|
3093
3142
|
const changes = typeof instance.getLineChanges === 'function' ? instance.getLineChanges() : null
|
|
3094
3143
|
if (changes === null || changes === undefined || changes.length === 0) return
|
|
3095
3144
|
const editor = instance.getModifiedEditor()
|
|
3096
|
-
const
|
|
3145
|
+
const position = editor.getPosition()
|
|
3146
|
+
const line = position === null ? 0 : position.lineNumber
|
|
3097
3147
|
let target = direction > 0 ? changes.find((item) => item.modifiedStartLineNumber > line) : [...changes].reverse().find((item) => item.modifiedEndLineNumber < line)
|
|
3098
3148
|
if (target === undefined) target = direction > 0 ? changes[0] : changes[changes.length - 1]
|
|
3099
3149
|
if (target === undefined) return
|
|
@@ -6221,6 +6271,8 @@ G.Explorer = function Explorer(props) {
|
|
|
6221
6271
|
const [clipboard, setClipboard] = useState(null)
|
|
6222
6272
|
const [menu, setMenu] = useState(null)
|
|
6223
6273
|
const [menuError, setMenuError] = useState('')
|
|
6274
|
+
const [notice, setNotice] = useState('')
|
|
6275
|
+
const containerRef = useRef(null)
|
|
6224
6276
|
const flatRows = []
|
|
6225
6277
|
const kindByPathRef = useRef(new Map())
|
|
6226
6278
|
const problems = G.useProblems()
|
|
@@ -6327,6 +6379,69 @@ G.Explorer = function Explorer(props) {
|
|
|
6327
6379
|
}
|
|
6328
6380
|
}
|
|
6329
6381
|
|
|
6382
|
+
const noticeRef = useRef(0)
|
|
6383
|
+
const showNotice = (text) => {
|
|
6384
|
+
setNotice(text)
|
|
6385
|
+
noticeRef.current += 1
|
|
6386
|
+
const token = noticeRef.current
|
|
6387
|
+
window.setTimeout(() => {
|
|
6388
|
+
if (noticeRef.current === token) setNotice('')
|
|
6389
|
+
}, 3200)
|
|
6390
|
+
}
|
|
6391
|
+
|
|
6392
|
+
const readFileBase64 = (file) => new Promise((resolve, reject) => {
|
|
6393
|
+
const reader = new FileReader()
|
|
6394
|
+
reader.onload = () => {
|
|
6395
|
+
const text = String(reader.result ?? '')
|
|
6396
|
+
const comma = text.indexOf(',')
|
|
6397
|
+
resolve(comma >= 0 ? text.slice(comma + 1) : '')
|
|
6398
|
+
}
|
|
6399
|
+
reader.onerror = () => reject(reader.error ?? new Error('读取文件失败'))
|
|
6400
|
+
reader.readAsDataURL(file)
|
|
6401
|
+
})
|
|
6402
|
+
|
|
6403
|
+
/** 把系统剪贴板 / Finder 拖入的文件写入目标目录。@returns 是否接管了这次事件 */
|
|
6404
|
+
const uploadFiles = async (fileList, dir) => {
|
|
6405
|
+
const files = Array.from(fileList ?? []).filter((file) => file !== null && typeof file === 'object' && typeof file.size === 'number')
|
|
6406
|
+
if (files.length === 0) return false
|
|
6407
|
+
const total = files.reduce((sum, file) => sum + (file.size || 0), 0)
|
|
6408
|
+
if (total <= 0) {
|
|
6409
|
+
showNotice('这个剪贴板项没有可读取的文件内容(文件夹暂不支持,请拖入文件)')
|
|
6410
|
+
return true
|
|
6411
|
+
}
|
|
6412
|
+
if (total > 300 * 1024 * 1024) {
|
|
6413
|
+
showNotice(`文件太大(${Math.round(total / 1024 / 1024)}MB),超过 300MB 上限`)
|
|
6414
|
+
return true
|
|
6415
|
+
}
|
|
6416
|
+
const targetDir = typeof dir === 'string' ? dir : ''
|
|
6417
|
+
showNotice(`正在写入 ${files.length} 个文件…`)
|
|
6418
|
+
try {
|
|
6419
|
+
const payload = []
|
|
6420
|
+
for (const file of files) {
|
|
6421
|
+
payload.push({ name: file.name !== '' ? file.name : 'file', data: await readFileBase64(file) })
|
|
6422
|
+
}
|
|
6423
|
+
const result = await G.api('fs.upload', { root, dir: targetDir, files: payload })
|
|
6424
|
+
const written = Array.isArray(result?.written) ? result.written : []
|
|
6425
|
+
await loadDir(targetDir)
|
|
6426
|
+
await loadDir('')
|
|
6427
|
+
props.onChanged?.()
|
|
6428
|
+
showNotice(`已粘贴 ${written.length} 个文件到 ${targetDir === '' ? '项目根目录' : targetDir}`)
|
|
6429
|
+
} catch (error) {
|
|
6430
|
+
showNotice(`粘贴失败:${G.errorText(error)}`)
|
|
6431
|
+
}
|
|
6432
|
+
return true
|
|
6433
|
+
}
|
|
6434
|
+
|
|
6435
|
+
/** 拖放目标所在的目录(拖到文件行 → 其父目录;拖到文件夹行 → 该文件夹)。 */
|
|
6436
|
+
const dropTargetDir = (target) => {
|
|
6437
|
+
const element = target instanceof Element ? target.closest('[data-edrv-path]') : null
|
|
6438
|
+
if (element === null) return selectedDir()
|
|
6439
|
+
const path = element.getAttribute('data-edrv-path') ?? ''
|
|
6440
|
+
if (path === '') return ''
|
|
6441
|
+
const kind = element.getAttribute('data-kind')
|
|
6442
|
+
return kind === 'dir' ? path : projectDirOf(path)
|
|
6443
|
+
}
|
|
6444
|
+
|
|
6330
6445
|
const revealPath = (path) => {
|
|
6331
6446
|
void G.api('fs.reveal', { root, path }).catch((error) => setMenuError(G.errorText(error)))
|
|
6332
6447
|
}
|
|
@@ -6415,9 +6530,12 @@ G.Explorer = function Explorer(props) {
|
|
|
6415
6530
|
'data-selected': multi.length > 0 ? (multi.includes(entry.path) ? '' : undefined) : selected !== null && selected.path === entry.path ? '' : undefined,
|
|
6416
6531
|
'data-kind': entry.kind,
|
|
6417
6532
|
'data-git-status': status !== undefined ? status : undefined,
|
|
6533
|
+
/* 给 dsh-drag-ref 用:把资源管理器行变成可拖拽的 @ 引用来源 */
|
|
6534
|
+
'data-edrv-path': entry.path,
|
|
6418
6535
|
style: { paddingLeft: 8 + depth * 14 },
|
|
6419
6536
|
title: entry.path,
|
|
6420
6537
|
onClick: (event) => {
|
|
6538
|
+
containerRef.current?.focus?.()
|
|
6421
6539
|
rememberKind(entry)
|
|
6422
6540
|
if (event.metaKey || event.ctrlKey) {
|
|
6423
6541
|
event.preventDefault()
|
|
@@ -6441,6 +6559,8 @@ G.Explorer = function Explorer(props) {
|
|
|
6441
6559
|
{ className: 'gufa-tree-chevron' },
|
|
6442
6560
|
isDir ? h(G.Icon, { name: isExpanded ? 'chevron-down' : 'chevron-right', size: 12 }) : null,
|
|
6443
6561
|
),
|
|
6562
|
+
/* dsh-drag-ref 用非空的 .edrv-tree-chev 文本判断「这是文件夹」 */
|
|
6563
|
+
isDir ? h('span', { className: 'edrv-tree-chev', style: { display: 'none' } }, '▸') : null,
|
|
6444
6564
|
h('span', { className: 'gufa-tree-icon' }, h(G.Icon, { name: isDir ? (isExpanded ? 'folder-open' : 'folder') : 'file', size: 14 })),
|
|
6445
6565
|
h('span', { className: 'gufa-tree-name' }, entry.name),
|
|
6446
6566
|
isDir && changedDirs.has(entry.path) ? h('span', { className: 'gufa-tree-problem', 'data-level': 'dir', title: t('explorer.changedDir') }) : null,
|
|
@@ -6462,8 +6582,31 @@ G.Explorer = function Explorer(props) {
|
|
|
6462
6582
|
return h(
|
|
6463
6583
|
'div',
|
|
6464
6584
|
{
|
|
6585
|
+
ref: containerRef,
|
|
6465
6586
|
style: { display: 'flex', flexDirection: 'column', height: '100%', minHeight: 0, outline: 'none' },
|
|
6466
6587
|
tabIndex: 0,
|
|
6588
|
+
onPaste: (event) => {
|
|
6589
|
+
const files = event.clipboardData?.files
|
|
6590
|
+
if (files !== undefined && files !== null && files.length > 0) {
|
|
6591
|
+
event.preventDefault()
|
|
6592
|
+
event.stopPropagation()
|
|
6593
|
+
void uploadFiles(files, selectedDir())
|
|
6594
|
+
}
|
|
6595
|
+
},
|
|
6596
|
+
onDragOver: (event) => {
|
|
6597
|
+
const types = event.dataTransfer?.types
|
|
6598
|
+
if (types === undefined || types === null || !Array.from(types).includes('Files')) return
|
|
6599
|
+
event.preventDefault()
|
|
6600
|
+
event.stopPropagation()
|
|
6601
|
+
event.dataTransfer.dropEffect = 'copy'
|
|
6602
|
+
},
|
|
6603
|
+
onDrop: (event) => {
|
|
6604
|
+
const files = event.dataTransfer?.files
|
|
6605
|
+
if (files === undefined || files === null || files.length === 0) return
|
|
6606
|
+
event.preventDefault()
|
|
6607
|
+
event.stopPropagation()
|
|
6608
|
+
void uploadFiles(files, dropTargetDir(event.target))
|
|
6609
|
+
},
|
|
6467
6610
|
onKeyDown: (event) => {
|
|
6468
6611
|
if (event.key === 'Enter') {
|
|
6469
6612
|
if (selected === null) return
|
|
@@ -6501,6 +6644,9 @@ G.Explorer = function Explorer(props) {
|
|
|
6501
6644
|
h(G.IconButton, { title: t('explorer.newFolder'), onClick: () => props.onNewFolder?.(selectedDir()) }, h(G.Icon, { name: 'folder', size: 14 })),
|
|
6502
6645
|
h(G.IconButton, { title: t('explorer.refresh'), onClick: () => void loadDir('') }, h(G.Icon, { name: 'refresh', size: 13 })),
|
|
6503
6646
|
),
|
|
6647
|
+
notice !== ''
|
|
6648
|
+
? h('div', { className: 'gufa-explorer-notice', title: notice }, notice)
|
|
6649
|
+
: null,
|
|
6504
6650
|
h(
|
|
6505
6651
|
'div',
|
|
6506
6652
|
{ className: 'gufa-panel-body gufa-scroll' },
|
|
@@ -7634,6 +7780,165 @@ G.BackdropStrengthSlider = function BackdropStrengthSlider(props) {
|
|
|
7634
7780
|
G.__backdrop = { read: G.readSkinBackdropMeta }
|
|
7635
7781
|
|
|
7636
7782
|
|
|
7783
|
+
/* ─────────────────────── 58-insert-ref.js ─────────────────────── */
|
|
7784
|
+
/**
|
|
7785
|
+
* 58-insert-ref:把系统剪贴板里的文件粘贴进对话输入框时,插入 `@相对路径` 引用。
|
|
7786
|
+
*
|
|
7787
|
+
* 浏览器/Electron 的剪贴板只给 File 内容、不给磁盘路径,所以流程是:
|
|
7788
|
+
* File → 名称/size/sha256 → Host(fs.matchFiles) 在项目内匹配同名同内容文件 → 插入 @引用。
|
|
7789
|
+
* 图片保持 DSH 默认的附件行为(不拦截)。
|
|
7790
|
+
*/
|
|
7791
|
+
|
|
7792
|
+
/** 轻量提示条(复用 drag-ref 的观感)。 */
|
|
7793
|
+
G.refToast = function refToast(text, kind) {
|
|
7794
|
+
try {
|
|
7795
|
+
let host = document.getElementById('gufa-ref-toast')
|
|
7796
|
+
if (host === null) {
|
|
7797
|
+
host = document.createElement('div')
|
|
7798
|
+
host.id = 'gufa-ref-toast'
|
|
7799
|
+
host.style.cssText = 'position:fixed;left:50%;bottom:96px;transform:translateX(-50%);z-index:2147483000;max-width:70vw;padding:7px 14px;border-radius:999px;font:12px/1.5 system-ui,sans-serif;box-shadow:0 6px 20px rgba(16,24,40,.18);pointer-events:none;white-space:pre-wrap'
|
|
7800
|
+
document.body.appendChild(host)
|
|
7801
|
+
}
|
|
7802
|
+
host.textContent = String(text)
|
|
7803
|
+
host.style.background = kind === 'err' ? 'rgba(180,35,24,.92)' : kind === 'ok' ? 'rgba(6,118,71,.92)' : 'rgba(28,30,38,.92)'
|
|
7804
|
+
host.style.color = '#fff'
|
|
7805
|
+
clearTimeout(G.refToast.timer)
|
|
7806
|
+
G.refToast.timer = window.setTimeout(() => {
|
|
7807
|
+
if (host.parentNode !== null) host.parentNode.removeChild(host)
|
|
7808
|
+
}, 3200)
|
|
7809
|
+
} catch {
|
|
7810
|
+
/* ignore */
|
|
7811
|
+
}
|
|
7812
|
+
}
|
|
7813
|
+
|
|
7814
|
+
/** 把相对路径变成 @ 引用文本(含空格的路径加引号)。 */
|
|
7815
|
+
G.mentionOfPath = function mentionOfPath(path) {
|
|
7816
|
+
const rel = String(path ?? '').replace(/\\/g, '/')
|
|
7817
|
+
if (rel === '') return ''
|
|
7818
|
+
return /\s/u.test(rel) ? `@"${rel}"` : `@${rel}`
|
|
7819
|
+
}
|
|
7820
|
+
|
|
7821
|
+
/** 取文件 sha256(hex)。 */
|
|
7822
|
+
G.sha256OfFile = async function sha256OfFile(file) {
|
|
7823
|
+
const buffer = await file.arrayBuffer()
|
|
7824
|
+
const digest = await crypto.subtle.digest('SHA-256', buffer)
|
|
7825
|
+
return Array.from(new Uint8Array(digest)).map((byte) => byte.toString(16).padStart(2, '0')).join('')
|
|
7826
|
+
}
|
|
7827
|
+
|
|
7828
|
+
/** 把文本插入当前对话输入框:优先官方 input 服务,失败退回 contenteditable 插入。 */
|
|
7829
|
+
G.insertIntoComposer = function insertIntoComposer(text) {
|
|
7830
|
+
if (typeof text !== 'string' || text === '') return false
|
|
7831
|
+
try {
|
|
7832
|
+
const sessionEl = document.querySelector('[data-conversation-session]')
|
|
7833
|
+
const sessionId = sessionEl === null ? '' : String(sessionEl.getAttribute('data-conversation-session') ?? '')
|
|
7834
|
+
const sessions = G.ctx === null || G.ctx === undefined ? undefined : G.ctx.get('sessions')
|
|
7835
|
+
const conversation = G.ctx === null || G.ctx === undefined ? undefined : G.ctx.get('conversation')
|
|
7836
|
+
if (sessionId !== '' && sessions !== undefined && conversation !== undefined && typeof sessions.scope === 'function') {
|
|
7837
|
+
const actx = sessions.scope(sessionId)
|
|
7838
|
+
if (actx !== undefined) {
|
|
7839
|
+
const input = conversation.input.for(actx)
|
|
7840
|
+
const snapshot = input?.state?.getSnapshot?.()
|
|
7841
|
+
if (snapshot !== undefined && input !== null && input !== undefined) {
|
|
7842
|
+
const offset = String(snapshot.draft ?? '').length
|
|
7843
|
+
const span = { start: offset, end: offset, draftRev: snapshot.draftRev }
|
|
7844
|
+
if (typeof input.insertText === 'function' && input.insertText(text, span) === true) return true
|
|
7845
|
+
if (typeof input.insertReference === 'function') {
|
|
7846
|
+
const mention = G.mentionOfPath(text.replace(/^@/, ''))
|
|
7847
|
+
if (mention !== '' && input.insertReference({ source: 'reference', ref: mention, label: text.replace(/^@/, ''), appearance: 'file', clipboardText: mention }, span) === true) return true
|
|
7848
|
+
}
|
|
7849
|
+
}
|
|
7850
|
+
}
|
|
7851
|
+
}
|
|
7852
|
+
} catch {
|
|
7853
|
+
/* fall through */
|
|
7854
|
+
}
|
|
7855
|
+
try {
|
|
7856
|
+
const editor = document.querySelector('[data-conversation-region="composer"] [contenteditable="true"]') || document.querySelector('[data-conversation-region="composer"]')
|
|
7857
|
+
if (editor === null) return false
|
|
7858
|
+
editor.focus()
|
|
7859
|
+
if (document.execCommand('insertText', false, text)) return true
|
|
7860
|
+
} catch {
|
|
7861
|
+
/* ignore */
|
|
7862
|
+
}
|
|
7863
|
+
return false
|
|
7864
|
+
}
|
|
7865
|
+
|
|
7866
|
+
/**
|
|
7867
|
+
* 安装「粘贴文件 → @引用」监听。
|
|
7868
|
+
* @param {object} ctx client 根 context
|
|
7869
|
+
* @returns {() => void} 卸载器
|
|
7870
|
+
*/
|
|
7871
|
+
G.installChatFilePaste = function installChatFilePaste(ctx) {
|
|
7872
|
+
if (typeof document === 'undefined') return () => {}
|
|
7873
|
+
let disposed = false
|
|
7874
|
+
|
|
7875
|
+
const handleFiles = async (files) => {
|
|
7876
|
+
const list = Array.from(files)
|
|
7877
|
+
if (list.length === 0) return
|
|
7878
|
+
const root = typeof G.projectRoot === 'string' ? G.projectRoot : ''
|
|
7879
|
+
if (root === '') {
|
|
7880
|
+
G.refToast('还没有打开项目,无法把文件转成 @ 引用', 'err')
|
|
7881
|
+
return
|
|
7882
|
+
}
|
|
7883
|
+
const payloads = []
|
|
7884
|
+
for (const file of list) {
|
|
7885
|
+
try {
|
|
7886
|
+
payloads.push({ name: file.name !== '' ? file.name : 'file', size: file.size, sha256: await G.sha256OfFile(file) })
|
|
7887
|
+
} catch {
|
|
7888
|
+
/* 读取失败的文件跳过 */
|
|
7889
|
+
}
|
|
7890
|
+
}
|
|
7891
|
+
if (payloads.length === 0) {
|
|
7892
|
+
G.refToast('粘贴的文件读取失败', 'err')
|
|
7893
|
+
return
|
|
7894
|
+
}
|
|
7895
|
+
let matches = []
|
|
7896
|
+
try {
|
|
7897
|
+
const result = await G.api('fs.matchFiles', { root, files: payloads })
|
|
7898
|
+
matches = Array.isArray(result?.matches) ? result.matches : []
|
|
7899
|
+
} catch (error) {
|
|
7900
|
+
G.refToast(`匹配项目文件失败:${G.errorText(error)}`, 'err')
|
|
7901
|
+
return
|
|
7902
|
+
}
|
|
7903
|
+
if (disposed) return
|
|
7904
|
+
const refs = []
|
|
7905
|
+
const missing = []
|
|
7906
|
+
for (const match of matches) {
|
|
7907
|
+
if (typeof match?.path === 'string' && match.path !== '') refs.push(G.mentionOfPath(match.path))
|
|
7908
|
+
else missing.push(String(match?.name ?? ''))
|
|
7909
|
+
}
|
|
7910
|
+
if (refs.length > 0) {
|
|
7911
|
+
const inserted = G.insertIntoComposer(refs.join(' ') + ' ')
|
|
7912
|
+
if (inserted) G.refToast(`已插入 ${refs.length} 个文件引用`, 'ok')
|
|
7913
|
+
else G.refToast('插入引用失败:输入框不可用', 'err')
|
|
7914
|
+
}
|
|
7915
|
+
if (missing.length > 0) {
|
|
7916
|
+
G.refToast(`${missing.join('、')} 不在当前项目里,未插入引用(可先粘贴到资源管理器导入项目)`, 'err')
|
|
7917
|
+
}
|
|
7918
|
+
}
|
|
7919
|
+
|
|
7920
|
+
const onPaste = (event) => {
|
|
7921
|
+
const files = event.clipboardData === null || event.clipboardData === undefined ? undefined : event.clipboardData.files
|
|
7922
|
+
if (files === undefined || files === null || files.length === 0) return
|
|
7923
|
+
const target = event.target
|
|
7924
|
+
const inConversation = target instanceof Element && (target.closest('[data-conversation-region="composer"]') !== null || target.closest('[data-conversation-content]') !== null)
|
|
7925
|
+
if (!inConversation) return
|
|
7926
|
+
const list = Array.from(files)
|
|
7927
|
+
/* 图片保留 DSH 默认的附件粘贴行为 */
|
|
7928
|
+
if (list.every((file) => typeof file.type === 'string' && file.type.startsWith('image/'))) return
|
|
7929
|
+
event.preventDefault()
|
|
7930
|
+
event.stopPropagation()
|
|
7931
|
+
void handleFiles(list)
|
|
7932
|
+
}
|
|
7933
|
+
|
|
7934
|
+
document.addEventListener('paste', onPaste, true)
|
|
7935
|
+
return () => {
|
|
7936
|
+
disposed = true
|
|
7937
|
+
document.removeEventListener('paste', onPaste, true)
|
|
7938
|
+
}
|
|
7939
|
+
}
|
|
7940
|
+
|
|
7941
|
+
|
|
7637
7942
|
/* ─────────────────────── 60-dock.js ─────────────────────── */
|
|
7638
7943
|
/**
|
|
7639
7944
|
* 60-dock:把官方 DSH 会话面板「停靠」进古法编程右侧的 AI 栏。
|
|
@@ -9042,6 +9347,7 @@ G.GufaApp = function GufaApp(props) {
|
|
|
9042
9347
|
|
|
9043
9348
|
/* ── 项目打开 ──────────────────────────────────────────────────────── */
|
|
9044
9349
|
const applyProject = useCallback((value) => {
|
|
9350
|
+
G.projectRoot = typeof value?.root === 'string' ? value.root : null
|
|
9045
9351
|
setProject(value)
|
|
9046
9352
|
writeJson(GUFA_LS.project, value?.root ?? null)
|
|
9047
9353
|
setTabs([])
|
|
@@ -9604,11 +9910,15 @@ G.GufaApp = function GufaApp(props) {
|
|
|
9604
9910
|
}))
|
|
9605
9911
|
}, [])
|
|
9606
9912
|
|
|
9913
|
+
/* 「仅切换 IDE 项目」:项目固定为用户手动打开的目录,不跟随 DSH 会话/工作区 */
|
|
9914
|
+
const projectPinnedRef = useRef(false)
|
|
9915
|
+
|
|
9607
9916
|
/* ── 右侧 AI 面板与当前工作区保持一致 ─────────────────────────────────
|
|
9608
9917
|
* ChatDock 停靠的是 DSH「主视图会话」,但主视图会话可能属于别的工作区
|
|
9609
9918
|
* (重启恢复、手动切换会话后常见)。项目根变化时自动切到当前工作区的会话。 */
|
|
9610
9919
|
const dockSyncRef = useRef('')
|
|
9611
9920
|
useEffect(() => {
|
|
9921
|
+
if (projectPinnedRef.current === true) return undefined
|
|
9612
9922
|
if (project === null || typeof project.root !== 'string' || project.root === '') return undefined
|
|
9613
9923
|
if (dockSyncRef.current === project.root) return undefined
|
|
9614
9924
|
if (typeof sessionCwd === 'string' && sessionCwd !== '' && sessionCwd === project.root) {
|
|
@@ -9860,6 +10170,7 @@ G.GufaApp = function GufaApp(props) {
|
|
|
9860
10170
|
/* 点击左侧工作区名 → 切换已有工作区(与经典模式同一份 workspace 列表) */
|
|
9861
10171
|
const switchWorkspace = useCallback(async (workspace) => {
|
|
9862
10172
|
if (workspace === null || workspace === undefined) return
|
|
10173
|
+
projectPinnedRef.current = false
|
|
9863
10174
|
const service = workspaceService()
|
|
9864
10175
|
try {
|
|
9865
10176
|
if (service !== undefined && service !== null && typeof service.openWorkspace === 'function' && typeof workspace.id === 'string') {
|
|
@@ -9895,6 +10206,20 @@ G.GufaApp = function GufaApp(props) {
|
|
|
9895
10206
|
}, [openProjectPath, closeWorkspaceDialog, showBanner])
|
|
9896
10207
|
|
|
9897
10208
|
/* 新建工作区:走经典模式同样的「选目录 → 创建 workspace → 打开并新建会话」 */
|
|
10209
|
+
/* 只切换 IDE 项目目录,不切换 DSH 会话/工作区(方便在同一个会话里边看别的项目边聊) */
|
|
10210
|
+
const pinProjectOnly = useCallback(async (workspace) => {
|
|
10211
|
+
if (workspace === null || workspace === undefined || typeof workspace.path !== 'string' || workspace.path === '') return
|
|
10212
|
+
try {
|
|
10213
|
+
projectPinnedRef.current = true
|
|
10214
|
+
await openProjectPath(workspace.path)
|
|
10215
|
+
closeWorkspaceDialog()
|
|
10216
|
+
showBanner('已切换 IDE 项目(当前会话保持不变)', 'success')
|
|
10217
|
+
} catch (error) {
|
|
10218
|
+
projectPinnedRef.current = false
|
|
10219
|
+
setBanner(G.errorText(error))
|
|
10220
|
+
}
|
|
10221
|
+
}, [openProjectPath, closeWorkspaceDialog, showBanner])
|
|
10222
|
+
|
|
9898
10223
|
const createWorkspace = useCallback(async () => {
|
|
9899
10224
|
const ui = workspaceService()
|
|
9900
10225
|
const registry = workspacesService()
|
|
@@ -10677,25 +11002,36 @@ G.GufaApp = function GufaApp(props) {
|
|
|
10677
11002
|
? h('div', { className: 'gufa-hint', style: { padding: '10px 8px' } }, t('workspace.empty'))
|
|
10678
11003
|
: workspaceDialog.workspaces.map((workspace) =>
|
|
10679
11004
|
h(
|
|
10680
|
-
'
|
|
10681
|
-
{
|
|
10682
|
-
key: workspace.id,
|
|
10683
|
-
type: 'button',
|
|
10684
|
-
className: 'gufa-branch-row gufa-workspace-row',
|
|
10685
|
-
'data-current': project !== null && project.root === workspace.path ? '' : undefined,
|
|
10686
|
-
title: workspace.path,
|
|
10687
|
-
onClick: () => void switchWorkspace(workspace),
|
|
10688
|
-
},
|
|
10689
|
-
h(G.Icon, { name: 'folder-open', size: 13 }),
|
|
11005
|
+
'div',
|
|
11006
|
+
{ key: workspace.id, className: 'gufa-workspace-row-wrap' },
|
|
10690
11007
|
h(
|
|
10691
|
-
'
|
|
10692
|
-
{
|
|
10693
|
-
|
|
10694
|
-
|
|
11008
|
+
'button',
|
|
11009
|
+
{
|
|
11010
|
+
type: 'button',
|
|
11011
|
+
className: 'gufa-branch-row gufa-workspace-row',
|
|
11012
|
+
'data-current': project !== null && project.root === workspace.path ? '' : undefined,
|
|
11013
|
+
title: `切换工作区 + 会话:${workspace.path}`,
|
|
11014
|
+
onClick: () => void switchWorkspace(workspace),
|
|
11015
|
+
},
|
|
11016
|
+
h(G.Icon, { name: 'folder-open', size: 13 }),
|
|
11017
|
+
h(
|
|
11018
|
+
'span',
|
|
11019
|
+
{ className: 'gufa-branch-name' },
|
|
11020
|
+
h('span', { className: 'gufa-workspace-title' }, workspace.title !== '' ? workspace.title : G.basename(workspace.path)),
|
|
11021
|
+
h('span', { className: 'gufa-workspace-path' }, workspace.path),
|
|
11022
|
+
),
|
|
11023
|
+
project !== null && project.root === workspace.path
|
|
11024
|
+
? h('span', { className: 'gufa-branch-tag' }, t('workspace.current'))
|
|
11025
|
+
: null,
|
|
10695
11026
|
),
|
|
10696
|
-
|
|
10697
|
-
|
|
10698
|
-
:
|
|
11027
|
+
h(G.IconButton, {
|
|
11028
|
+
title: '只切换 IDE 项目(保持当前会话)',
|
|
11029
|
+
onClick: (event) => {
|
|
11030
|
+
event.preventDefault()
|
|
11031
|
+
event.stopPropagation()
|
|
11032
|
+
void pinProjectOnly(workspace)
|
|
11033
|
+
},
|
|
11034
|
+
}, h(G.Icon, { name: 'panel-left', size: 13 })),
|
|
10699
11035
|
),
|
|
10700
11036
|
),
|
|
10701
11037
|
),
|
|
@@ -11321,6 +11657,47 @@ const GUFA_PLUGIN = {
|
|
|
11321
11657
|
/* ignore */
|
|
11322
11658
|
}
|
|
11323
11659
|
|
|
11660
|
+
/* ── 清理「每会话右侧面板布局」里由 dsh-vscode-mode 留下的『文件编辑』标签 ──
|
|
11661
|
+
* 官方右侧栏会把每个会话的布局持久化到 localStorage(键 dsh.sidebar-right.v1.<sessionId>),
|
|
11662
|
+
* 切换会话时恢复该布局 → 历史上被 vscode-mode 写过标签的会话会「自动展开右侧栏」。
|
|
11663
|
+
* 这里在页面加载后清理这些残留键,让会话恢复成默认(收起)状态。 */
|
|
11664
|
+
const cleanStaleSidebarLayouts = () => {
|
|
11665
|
+
try {
|
|
11666
|
+
const keys = []
|
|
11667
|
+
for (let index = 0; index < window.localStorage.length; index += 1) {
|
|
11668
|
+
const key = window.localStorage.key(index)
|
|
11669
|
+
if (key !== null && key.startsWith('dsh.sidebar-right.v1.')) keys.push(key)
|
|
11670
|
+
}
|
|
11671
|
+
let removed = 0
|
|
11672
|
+
for (const key of keys) {
|
|
11673
|
+
const raw = window.localStorage.getItem(key)
|
|
11674
|
+
if (raw === null) continue
|
|
11675
|
+
if (raw.includes('edrvEditor') || raw.includes('vscode-mode')) {
|
|
11676
|
+
window.localStorage.removeItem(key)
|
|
11677
|
+
removed += 1
|
|
11678
|
+
}
|
|
11679
|
+
}
|
|
11680
|
+
if (removed > 0) {
|
|
11681
|
+
void G.api('dev.log', { message: `sidebar-layout-cleanup removed=${removed}/${keys.length}` }).catch(() => {})
|
|
11682
|
+
}
|
|
11683
|
+
} catch {
|
|
11684
|
+
/* localStorage 不可用时忽略 */
|
|
11685
|
+
}
|
|
11686
|
+
}
|
|
11687
|
+
cleanStaleSidebarLayouts()
|
|
11688
|
+
window.setTimeout(cleanStaleSidebarLayouts, 1500)
|
|
11689
|
+
window.setTimeout(cleanStaleSidebarLayouts, 5000)
|
|
11690
|
+
|
|
11691
|
+
// 聊天框:粘贴系统文件 → 自动插入 @文件引用(内容匹配项目内文件后插入)
|
|
11692
|
+
try {
|
|
11693
|
+
if (typeof G.installChatFilePaste === 'function') {
|
|
11694
|
+
const disposeChatPaste = G.installChatFilePaste(ctx)
|
|
11695
|
+
if (typeof disposeChatPaste === 'function') ctx.effect(() => disposeChatPaste, 'gufa-code: chat file paste')
|
|
11696
|
+
}
|
|
11697
|
+
} catch (error) {
|
|
11698
|
+
console.error('[gufa-code] 安装聊天框文件粘贴失败', error)
|
|
11699
|
+
}
|
|
11700
|
+
|
|
11324
11701
|
// 样式(随插件 context 卸载自动移除)
|
|
11325
11702
|
ctx.effect(() => G.injectStyles(), 'gufa-code: styles')
|
|
11326
11703
|
|
package/docs/screenshot-ide.jpg
CHANGED
|
Binary file
|