dsh-gufa-code 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/client.js CHANGED
@@ -1086,6 +1086,19 @@ html[data-gufa-ide] [role="dialog"] {
1086
1086
  .gufa-session-group-count{font-size:10.5px;opacity:.6;font-variant-numeric:tabular-nums}
1087
1087
  .gufa-session-group[data-current] .gufa-session-group-head{color:var(--gufa-text)}
1088
1088
  .gufa-session-group .gufa-session-row{margin-left:10px}
1089
+ .gufa-session-workspace-btn{display:inline-flex;align-items:center;gap:4px;border:1px solid var(--gufa-border);background:var(--gufa-layer2);
1090
+ color:var(--gufa-text-dim);border-radius:7px;padding:2px 8px;font:inherit;font-size:11.5px;cursor:pointer;max-width:260px}
1091
+ .gufa-session-workspace-btn:hover{background:var(--gufa-hover);color:var(--gufa-text)}
1092
+ .gufa-session-workspace-btn span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
1093
+ .gufa-session-workspace-picker{display:flex;flex-direction:column;gap:2px;padding:6px 10px;max-height:220px;overflow:auto;
1094
+ border-top:1px solid var(--gufa-border);border-bottom:1px solid var(--gufa-border);background:var(--gufa-layer)}
1095
+ .gufa-session-workspace-option{display:flex;align-items:center;gap:8px;width:100%;padding:6px 8px;border:0;border-radius:7px;
1096
+ background:transparent;color:var(--gufa-text);font:inherit;font-size:12px;cursor:pointer;text-align:left}
1097
+ .gufa-session-workspace-option:hover{background:var(--gufa-hover)}
1098
+ .gufa-session-workspace-option[data-current]{background:var(--gufa-active)}
1099
+ .gufa-session-workspace-option-title{flex:0 0 auto;font-weight:550}
1100
+ .gufa-session-workspace-option-path{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
1101
+ color:var(--gufa-text-dim);font-size:10.5px;text-align:right}
1089
1102
  .gufa-session-workspace{font-size:11px;color:var(--gufa-text-dim);max-width:40%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
1090
1103
  .gufa-session-row-title{flex:1 1 auto;overflow:hidden;text-overflow:ellipsis}
1091
1104
  .gufa-session-row-when{flex:0 0 auto;font-size:10.5px;color:var(--gufa-solid-text-dim, var(--dsw-alias-label-secondary));font-variant-numeric:tabular-nums}
@@ -1129,6 +1142,19 @@ html[data-gufa-ide] [role="dialog"] {
1129
1142
  .gufa-session-group-count{font-size:10.5px;opacity:.6;font-variant-numeric:tabular-nums}
1130
1143
  .gufa-session-group[data-current] .gufa-session-group-head{color:var(--gufa-text)}
1131
1144
  .gufa-session-group .gufa-session-row{margin-left:10px}
1145
+ .gufa-session-workspace-btn{display:inline-flex;align-items:center;gap:4px;border:1px solid var(--gufa-border);background:var(--gufa-layer2);
1146
+ color:var(--gufa-text-dim);border-radius:7px;padding:2px 8px;font:inherit;font-size:11.5px;cursor:pointer;max-width:260px}
1147
+ .gufa-session-workspace-btn:hover{background:var(--gufa-hover);color:var(--gufa-text)}
1148
+ .gufa-session-workspace-btn span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
1149
+ .gufa-session-workspace-picker{display:flex;flex-direction:column;gap:2px;padding:6px 10px;max-height:220px;overflow:auto;
1150
+ border-top:1px solid var(--gufa-border);border-bottom:1px solid var(--gufa-border);background:var(--gufa-layer)}
1151
+ .gufa-session-workspace-option{display:flex;align-items:center;gap:8px;width:100%;padding:6px 8px;border:0;border-radius:7px;
1152
+ background:transparent;color:var(--gufa-text);font:inherit;font-size:12px;cursor:pointer;text-align:left}
1153
+ .gufa-session-workspace-option:hover{background:var(--gufa-hover)}
1154
+ .gufa-session-workspace-option[data-current]{background:var(--gufa-active)}
1155
+ .gufa-session-workspace-option-title{flex:0 0 auto;font-weight:550}
1156
+ .gufa-session-workspace-option-path{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
1157
+ color:var(--gufa-text-dim);font-size:10.5px;text-align:right}
1132
1158
  .gufa-session-workspace{font-size:11px;color:var(--gufa-text-dim);max-width:40%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
1133
1159
  .gufa-session-row-title{flex:1 1 auto;overflow:hidden;text-overflow:ellipsis}
1134
1160
  .gufa-session-row-when{flex:0 0 auto;font-size:10.5px;color:var(--gufa-solid-text-dim, var(--dsw-alias-label-secondary));font-variant-numeric:tabular-nums}
@@ -1172,6 +1198,19 @@ html[data-gufa-ide] [role="dialog"] {
1172
1198
  .gufa-session-group-count{font-size:10.5px;opacity:.6;font-variant-numeric:tabular-nums}
1173
1199
  .gufa-session-group[data-current] .gufa-session-group-head{color:var(--gufa-text)}
1174
1200
  .gufa-session-group .gufa-session-row{margin-left:10px}
1201
+ .gufa-session-workspace-btn{display:inline-flex;align-items:center;gap:4px;border:1px solid var(--gufa-border);background:var(--gufa-layer2);
1202
+ color:var(--gufa-text-dim);border-radius:7px;padding:2px 8px;font:inherit;font-size:11.5px;cursor:pointer;max-width:260px}
1203
+ .gufa-session-workspace-btn:hover{background:var(--gufa-hover);color:var(--gufa-text)}
1204
+ .gufa-session-workspace-btn span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
1205
+ .gufa-session-workspace-picker{display:flex;flex-direction:column;gap:2px;padding:6px 10px;max-height:220px;overflow:auto;
1206
+ border-top:1px solid var(--gufa-border);border-bottom:1px solid var(--gufa-border);background:var(--gufa-layer)}
1207
+ .gufa-session-workspace-option{display:flex;align-items:center;gap:8px;width:100%;padding:6px 8px;border:0;border-radius:7px;
1208
+ background:transparent;color:var(--gufa-text);font:inherit;font-size:12px;cursor:pointer;text-align:left}
1209
+ .gufa-session-workspace-option:hover{background:var(--gufa-hover)}
1210
+ .gufa-session-workspace-option[data-current]{background:var(--gufa-active)}
1211
+ .gufa-session-workspace-option-title{flex:0 0 auto;font-weight:550}
1212
+ .gufa-session-workspace-option-path{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
1213
+ color:var(--gufa-text-dim);font-size:10.5px;text-align:right}
1175
1214
  .gufa-session-workspace{font-size:11px;color:var(--gufa-text-dim);max-width:40%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
1176
1215
  .gufa-session-row-title{flex:1 1 auto;overflow:hidden;text-overflow:ellipsis}
1177
1216
  .gufa-session-row-when{flex:0 0 auto;font-size:10.5px;color:var(--gufa-solid-text-dim, var(--dsw-alias-label-secondary));font-variant-numeric:tabular-nums}
@@ -1215,6 +1254,19 @@ html[data-gufa-ide] [role="dialog"] {
1215
1254
  .gufa-session-group-count{font-size:10.5px;opacity:.6;font-variant-numeric:tabular-nums}
1216
1255
  .gufa-session-group[data-current] .gufa-session-group-head{color:var(--gufa-text)}
1217
1256
  .gufa-session-group .gufa-session-row{margin-left:10px}
1257
+ .gufa-session-workspace-btn{display:inline-flex;align-items:center;gap:4px;border:1px solid var(--gufa-border);background:var(--gufa-layer2);
1258
+ color:var(--gufa-text-dim);border-radius:7px;padding:2px 8px;font:inherit;font-size:11.5px;cursor:pointer;max-width:260px}
1259
+ .gufa-session-workspace-btn:hover{background:var(--gufa-hover);color:var(--gufa-text)}
1260
+ .gufa-session-workspace-btn span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
1261
+ .gufa-session-workspace-picker{display:flex;flex-direction:column;gap:2px;padding:6px 10px;max-height:220px;overflow:auto;
1262
+ border-top:1px solid var(--gufa-border);border-bottom:1px solid var(--gufa-border);background:var(--gufa-layer)}
1263
+ .gufa-session-workspace-option{display:flex;align-items:center;gap:8px;width:100%;padding:6px 8px;border:0;border-radius:7px;
1264
+ background:transparent;color:var(--gufa-text);font:inherit;font-size:12px;cursor:pointer;text-align:left}
1265
+ .gufa-session-workspace-option:hover{background:var(--gufa-hover)}
1266
+ .gufa-session-workspace-option[data-current]{background:var(--gufa-active)}
1267
+ .gufa-session-workspace-option-title{flex:0 0 auto;font-weight:550}
1268
+ .gufa-session-workspace-option-path{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
1269
+ color:var(--gufa-text-dim);font-size:10.5px;text-align:right}
1218
1270
  .gufa-session-workspace{font-size:11px;color:var(--gufa-text-dim);max-width:40%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
1219
1271
  .gufa-session-row-title{flex:1 1 auto;overflow:hidden;text-overflow:ellipsis}
1220
1272
  .gufa-session-row-when{flex:0 0 auto;font-size:10.5px;color:var(--gufa-solid-text-dim, var(--dsw-alias-label-secondary));font-variant-numeric:tabular-nums}
@@ -1249,6 +1301,8 @@ html[data-platform=darwin][data-fullscreen] .gufa-titlebar{height:44px;padding-l
1249
1301
  .gufa-project{appearance:none;border:0;background:transparent;font:inherit;color:inherit;cursor:pointer}
1250
1302
  .gufa-project:hover{background:var(--gufa-hover)}
1251
1303
  .gufa-workspace-row{height:auto;min-height:38px;padding:5px 8px}
1304
+ .gufa-workspace-row-wrap{display:flex;align-items:center;gap:4px}
1305
+ .gufa-workspace-row-wrap .gufa-workspace-row{flex:1 1 auto;min-width:0}
1252
1306
  .gufa-workspace-title{display:block;font-size:12px;line-height:1.3}
1253
1307
  .gufa-workspace-path{display:block;font-size:10.5px;color:var(--gufa-text-dim);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
1254
1308
  .gufa-project{display:flex;align-items:center;gap:6px;min-width:0;margin-left:6px;padding:3px 9px;border-radius:7px;
@@ -1327,6 +1381,9 @@ html[data-platform=darwin][data-fullscreen] .gufa-titlebar{height:44px;padding-l
1327
1381
  .gufa-tree-row[data-selected]{background:var(--gufa-active)}
1328
1382
  .gufa-tree-row[data-kind="dir"]{color:var(--gufa-text)}
1329
1383
  .gufa-tree-name{overflow:hidden;text-overflow:ellipsis;flex:1 1 auto;min-width:0}
1384
+ .gufa-explorer-notice{margin:4px 10px 0;padding:3px 8px;border-radius:6px;font-size:11px;line-height:1.5;color:var(--gufa-text);
1385
+ background:color-mix(in srgb, var(--gufa-accent) 14%, transparent);border:0.5px solid color-mix(in srgb, var(--gufa-accent) 40%, transparent);
1386
+ overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
1330
1387
  .gufa-tree-chevron{width:14px;flex:0 0 auto;opacity:.7;display:flex;align-items:center;justify-content:center}
1331
1388
  .gufa-tree-icon{width:15px;flex:0 0 auto;opacity:.85;display:flex;align-items:center;justify-content:center}
1332
1389
  .gufa-tree-badge{font-size:10px;color:var(--gufa-accent);flex:0 0 auto;font-weight:600}
@@ -2139,7 +2196,14 @@ G.FooterAction = function FooterAction(props) {
2139
2196
  ) {
2140
2197
  return
2141
2198
  }
2142
- const getWorker = (moduleId, label) => gufaCreateMonacoWorker(G.asset('monaco'), label)
2199
+ const workerBase = (() => {
2200
+ try {
2201
+ return new URL(G.asset('monaco'), G.serverBase()).href
2202
+ } catch {
2203
+ return G.asset('monaco')
2204
+ }
2205
+ })()
2206
+ const getWorker = (moduleId, label) => gufaCreateMonacoWorker(workerBase, label)
2143
2207
  if (existing !== undefined && existing !== null && typeof existing === 'object') {
2144
2208
  existing.getWorker = getWorker
2145
2209
  return
@@ -2158,13 +2222,35 @@ G.FooterAction = function FooterAction(props) {
2158
2222
  }
2159
2223
 
2160
2224
  function gufaCreateMonacoWorker(base, label) {
2161
- const blob = new Blob([gufaWorkerScript(base)], { type: 'text/javascript' })
2162
- const url = URL.createObjectURL(blob)
2225
+ const name = typeof label === 'string' && label !== '' ? label : 'gufa-monaco-worker'
2226
+ const watch = (worker, sourceUrl) => {
2227
+ try {
2228
+ worker.addEventListener('error', (event) => {
2229
+ void G.api('dev.log', {
2230
+ message: `monaco-worker-error src=${sourceUrl} message=${String(event && event.message)} file=${String(event && event.filename)} line=${String(event && event.lineno)}`,
2231
+ }).catch(() => {})
2232
+ })
2233
+ worker.addEventListener('messageerror', () => {
2234
+ void G.api('dev.log', { message: `monaco-worker-messageerror src=${sourceUrl}` }).catch(() => {})
2235
+ })
2236
+ void G.api('dev.log', { message: `monaco-worker-created src=${sourceUrl}` }).catch(() => {})
2237
+ } catch {
2238
+ /* ignore */
2239
+ }
2240
+ return worker
2241
+ }
2163
2242
  try {
2164
- return new Worker(url, { name: typeof label === 'string' && label !== '' ? label : 'gufa-monaco-worker' })
2165
- } finally {
2166
- /* Worker 已取到脚本;延迟 revoke,避免个别浏览器创建阶段就失效。 */
2167
- window.setTimeout(() => URL.revokeObjectURL(url), 10000)
2243
+ const url = `${G.asset('monaco')}/worker-bootstrap.js?v=3`
2244
+ return watch(new Worker(url, { name }), url)
2245
+ } catch (error) {
2246
+ const blob = new Blob([gufaWorkerScript(base)], { type: 'text/javascript' })
2247
+ const url = URL.createObjectURL(blob)
2248
+ void G.api('dev.log', { message: `monaco-worker-construct-failed ${String(error && error.message)} fallback=blob` }).catch(() => {})
2249
+ try {
2250
+ return watch(new Worker(url, { name }), url)
2251
+ } finally {
2252
+ window.setTimeout(() => URL.revokeObjectURL(url), 10000)
2253
+ }
2168
2254
  }
2169
2255
  }
2170
2256
 
@@ -2397,6 +2483,8 @@ G.FooterAction = function FooterAction(props) {
2397
2483
  const diffEditorRef = useRef(null)
2398
2484
  const diffModelsRef = useRef([])
2399
2485
  const diffSignatureRef = useRef(null)
2486
+ const diffAnchorsRef = useRef([])
2487
+ const diffZoneIdsRef = useRef([])
2400
2488
  const monacoRef = useRef(null)
2401
2489
  const modelsRef = useRef(new Map()) /* path -> ITextModel */
2402
2490
  const viewStatesRef = useRef(new Map()) /* path -> editor view state(滚动/光标) */
@@ -2861,6 +2949,8 @@ G.FooterAction = function FooterAction(props) {
2861
2949
  }
2862
2950
  diffModelsRef.current = []
2863
2951
  diffSignatureRef.current = null
2952
+ diffAnchorsRef.current = []
2953
+ diffZoneIdsRef.current = []
2864
2954
  }
2865
2955
  if (status !== 'ready' || activeIsDiff !== true) {
2866
2956
  disposeDiff()
@@ -2884,7 +2974,7 @@ G.FooterAction = function FooterAction(props) {
2884
2974
  const language = typeof tab.language === 'string' && tab.language !== '' ? tab.language : 'plaintext'
2885
2975
  const key = encodeURIComponent(String(tab.path))
2886
2976
  const suffix = String(Date.now())
2887
- const leftText = tab.diff.compare === true && typeof tab.compareLeft === 'string' ? tab.compareLeft : tab.diff.left
2977
+ const leftText = tab.diff.compare === true && typeof tab.compareLeft === 'string' ? tab.compareLeft : String(tab.diff.left ?? '')
2888
2978
  const originalModel = monaco.editor.createModel(String(leftText ?? ''), language, monaco.Uri.parse(`gufa-diff://original/${key}/${suffix}`))
2889
2979
  const modifiedModel = monaco.editor.createModel(String(tab.content ?? ''), language, monaco.Uri.parse(`gufa-diff://modified/${key}/${suffix}`))
2890
2980
  let instance
@@ -2971,6 +3061,17 @@ G.FooterAction = function FooterAction(props) {
2971
3061
  } catch {
2972
3062
  /* ignore */
2973
3063
  }
3064
+ /* 诊断:2 秒后如果差异仍然是 null,说明 Monaco worker 没起来(dsh-app:// 下的 worker 限制) */
3065
+ window.setTimeout(() => {
3066
+ try {
3067
+ const changes = typeof instance.getLineChanges === 'function' ? instance.getLineChanges() : null
3068
+ void G.api('dev.log', {
3069
+ 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)}`,
3070
+ }).catch(() => {})
3071
+ } catch {
3072
+ /* ignore */
3073
+ }
3074
+ }, 2000)
2974
3075
  return () => {
2975
3076
  try {
2976
3077
  sub.dispose()
@@ -3093,7 +3194,8 @@ G.FooterAction = function FooterAction(props) {
3093
3194
  const changes = typeof instance.getLineChanges === 'function' ? instance.getLineChanges() : null
3094
3195
  if (changes === null || changes === undefined || changes.length === 0) return
3095
3196
  const editor = instance.getModifiedEditor()
3096
- const line = editor.getPosition() === null ? 0 : editor.getPosition().lineNumber
3197
+ const position = editor.getPosition()
3198
+ const line = position === null ? 0 : position.lineNumber
3097
3199
  let target = direction > 0 ? changes.find((item) => item.modifiedStartLineNumber > line) : [...changes].reverse().find((item) => item.modifiedEndLineNumber < line)
3098
3200
  if (target === undefined) target = direction > 0 ? changes[0] : changes[changes.length - 1]
3099
3201
  if (target === undefined) return
@@ -6221,6 +6323,8 @@ G.Explorer = function Explorer(props) {
6221
6323
  const [clipboard, setClipboard] = useState(null)
6222
6324
  const [menu, setMenu] = useState(null)
6223
6325
  const [menuError, setMenuError] = useState('')
6326
+ const [notice, setNotice] = useState('')
6327
+ const containerRef = useRef(null)
6224
6328
  const flatRows = []
6225
6329
  const kindByPathRef = useRef(new Map())
6226
6330
  const problems = G.useProblems()
@@ -6327,6 +6431,69 @@ G.Explorer = function Explorer(props) {
6327
6431
  }
6328
6432
  }
6329
6433
 
6434
+ const noticeRef = useRef(0)
6435
+ const showNotice = (text) => {
6436
+ setNotice(text)
6437
+ noticeRef.current += 1
6438
+ const token = noticeRef.current
6439
+ window.setTimeout(() => {
6440
+ if (noticeRef.current === token) setNotice('')
6441
+ }, 3200)
6442
+ }
6443
+
6444
+ const readFileBase64 = (file) => new Promise((resolve, reject) => {
6445
+ const reader = new FileReader()
6446
+ reader.onload = () => {
6447
+ const text = String(reader.result ?? '')
6448
+ const comma = text.indexOf(',')
6449
+ resolve(comma >= 0 ? text.slice(comma + 1) : '')
6450
+ }
6451
+ reader.onerror = () => reject(reader.error ?? new Error('读取文件失败'))
6452
+ reader.readAsDataURL(file)
6453
+ })
6454
+
6455
+ /** 把系统剪贴板 / Finder 拖入的文件写入目标目录。@returns 是否接管了这次事件 */
6456
+ const uploadFiles = async (fileList, dir) => {
6457
+ const files = Array.from(fileList ?? []).filter((file) => file !== null && typeof file === 'object' && typeof file.size === 'number')
6458
+ if (files.length === 0) return false
6459
+ const total = files.reduce((sum, file) => sum + (file.size || 0), 0)
6460
+ if (total <= 0) {
6461
+ showNotice('这个剪贴板项没有可读取的文件内容(文件夹暂不支持,请拖入文件)')
6462
+ return true
6463
+ }
6464
+ if (total > 300 * 1024 * 1024) {
6465
+ showNotice(`文件太大(${Math.round(total / 1024 / 1024)}MB),超过 300MB 上限`)
6466
+ return true
6467
+ }
6468
+ const targetDir = typeof dir === 'string' ? dir : ''
6469
+ showNotice(`正在写入 ${files.length} 个文件…`)
6470
+ try {
6471
+ const payload = []
6472
+ for (const file of files) {
6473
+ payload.push({ name: file.name !== '' ? file.name : 'file', data: await readFileBase64(file) })
6474
+ }
6475
+ const result = await G.api('fs.upload', { root, dir: targetDir, files: payload })
6476
+ const written = Array.isArray(result?.written) ? result.written : []
6477
+ await loadDir(targetDir)
6478
+ await loadDir('')
6479
+ props.onChanged?.()
6480
+ showNotice(`已粘贴 ${written.length} 个文件到 ${targetDir === '' ? '项目根目录' : targetDir}`)
6481
+ } catch (error) {
6482
+ showNotice(`粘贴失败:${G.errorText(error)}`)
6483
+ }
6484
+ return true
6485
+ }
6486
+
6487
+ /** 拖放目标所在的目录(拖到文件行 → 其父目录;拖到文件夹行 → 该文件夹)。 */
6488
+ const dropTargetDir = (target) => {
6489
+ const element = target instanceof Element ? target.closest('[data-edrv-path]') : null
6490
+ if (element === null) return selectedDir()
6491
+ const path = element.getAttribute('data-edrv-path') ?? ''
6492
+ if (path === '') return ''
6493
+ const kind = element.getAttribute('data-kind')
6494
+ return kind === 'dir' ? path : projectDirOf(path)
6495
+ }
6496
+
6330
6497
  const revealPath = (path) => {
6331
6498
  void G.api('fs.reveal', { root, path }).catch((error) => setMenuError(G.errorText(error)))
6332
6499
  }
@@ -6415,9 +6582,12 @@ G.Explorer = function Explorer(props) {
6415
6582
  'data-selected': multi.length > 0 ? (multi.includes(entry.path) ? '' : undefined) : selected !== null && selected.path === entry.path ? '' : undefined,
6416
6583
  'data-kind': entry.kind,
6417
6584
  'data-git-status': status !== undefined ? status : undefined,
6585
+ /* 给 dsh-drag-ref 用:把资源管理器行变成可拖拽的 @ 引用来源 */
6586
+ 'data-edrv-path': entry.path,
6418
6587
  style: { paddingLeft: 8 + depth * 14 },
6419
6588
  title: entry.path,
6420
6589
  onClick: (event) => {
6590
+ containerRef.current?.focus?.()
6421
6591
  rememberKind(entry)
6422
6592
  if (event.metaKey || event.ctrlKey) {
6423
6593
  event.preventDefault()
@@ -6441,6 +6611,8 @@ G.Explorer = function Explorer(props) {
6441
6611
  { className: 'gufa-tree-chevron' },
6442
6612
  isDir ? h(G.Icon, { name: isExpanded ? 'chevron-down' : 'chevron-right', size: 12 }) : null,
6443
6613
  ),
6614
+ /* dsh-drag-ref 用非空的 .edrv-tree-chev 文本判断「这是文件夹」 */
6615
+ isDir ? h('span', { className: 'edrv-tree-chev', style: { display: 'none' } }, '▸') : null,
6444
6616
  h('span', { className: 'gufa-tree-icon' }, h(G.Icon, { name: isDir ? (isExpanded ? 'folder-open' : 'folder') : 'file', size: 14 })),
6445
6617
  h('span', { className: 'gufa-tree-name' }, entry.name),
6446
6618
  isDir && changedDirs.has(entry.path) ? h('span', { className: 'gufa-tree-problem', 'data-level': 'dir', title: t('explorer.changedDir') }) : null,
@@ -6462,8 +6634,31 @@ G.Explorer = function Explorer(props) {
6462
6634
  return h(
6463
6635
  'div',
6464
6636
  {
6637
+ ref: containerRef,
6465
6638
  style: { display: 'flex', flexDirection: 'column', height: '100%', minHeight: 0, outline: 'none' },
6466
6639
  tabIndex: 0,
6640
+ onPaste: (event) => {
6641
+ const files = event.clipboardData?.files
6642
+ if (files !== undefined && files !== null && files.length > 0) {
6643
+ event.preventDefault()
6644
+ event.stopPropagation()
6645
+ void uploadFiles(files, selectedDir())
6646
+ }
6647
+ },
6648
+ onDragOver: (event) => {
6649
+ const types = event.dataTransfer?.types
6650
+ if (types === undefined || types === null || !Array.from(types).includes('Files')) return
6651
+ event.preventDefault()
6652
+ event.stopPropagation()
6653
+ event.dataTransfer.dropEffect = 'copy'
6654
+ },
6655
+ onDrop: (event) => {
6656
+ const files = event.dataTransfer?.files
6657
+ if (files === undefined || files === null || files.length === 0) return
6658
+ event.preventDefault()
6659
+ event.stopPropagation()
6660
+ void uploadFiles(files, dropTargetDir(event.target))
6661
+ },
6467
6662
  onKeyDown: (event) => {
6468
6663
  if (event.key === 'Enter') {
6469
6664
  if (selected === null) return
@@ -6501,6 +6696,9 @@ G.Explorer = function Explorer(props) {
6501
6696
  h(G.IconButton, { title: t('explorer.newFolder'), onClick: () => props.onNewFolder?.(selectedDir()) }, h(G.Icon, { name: 'folder', size: 14 })),
6502
6697
  h(G.IconButton, { title: t('explorer.refresh'), onClick: () => void loadDir('') }, h(G.Icon, { name: 'refresh', size: 13 })),
6503
6698
  ),
6699
+ notice !== ''
6700
+ ? h('div', { className: 'gufa-explorer-notice', title: notice }, notice)
6701
+ : null,
6504
6702
  h(
6505
6703
  'div',
6506
6704
  { className: 'gufa-panel-body gufa-scroll' },
@@ -7634,6 +7832,165 @@ G.BackdropStrengthSlider = function BackdropStrengthSlider(props) {
7634
7832
  G.__backdrop = { read: G.readSkinBackdropMeta }
7635
7833
 
7636
7834
 
7835
+ /* ─────────────────────── 58-insert-ref.js ─────────────────────── */
7836
+ /**
7837
+ * 58-insert-ref:把系统剪贴板里的文件粘贴进对话输入框时,插入 `@相对路径` 引用。
7838
+ *
7839
+ * 浏览器/Electron 的剪贴板只给 File 内容、不给磁盘路径,所以流程是:
7840
+ * File → 名称/size/sha256 → Host(fs.matchFiles) 在项目内匹配同名同内容文件 → 插入 @引用。
7841
+ * 图片保持 DSH 默认的附件行为(不拦截)。
7842
+ */
7843
+
7844
+ /** 轻量提示条(复用 drag-ref 的观感)。 */
7845
+ G.refToast = function refToast(text, kind) {
7846
+ try {
7847
+ let host = document.getElementById('gufa-ref-toast')
7848
+ if (host === null) {
7849
+ host = document.createElement('div')
7850
+ host.id = 'gufa-ref-toast'
7851
+ 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'
7852
+ document.body.appendChild(host)
7853
+ }
7854
+ host.textContent = String(text)
7855
+ host.style.background = kind === 'err' ? 'rgba(180,35,24,.92)' : kind === 'ok' ? 'rgba(6,118,71,.92)' : 'rgba(28,30,38,.92)'
7856
+ host.style.color = '#fff'
7857
+ clearTimeout(G.refToast.timer)
7858
+ G.refToast.timer = window.setTimeout(() => {
7859
+ if (host.parentNode !== null) host.parentNode.removeChild(host)
7860
+ }, 3200)
7861
+ } catch {
7862
+ /* ignore */
7863
+ }
7864
+ }
7865
+
7866
+ /** 把相对路径变成 @ 引用文本(含空格的路径加引号)。 */
7867
+ G.mentionOfPath = function mentionOfPath(path) {
7868
+ const rel = String(path ?? '').replace(/\\/g, '/')
7869
+ if (rel === '') return ''
7870
+ return /\s/u.test(rel) ? `@"${rel}"` : `@${rel}`
7871
+ }
7872
+
7873
+ /** 取文件 sha256(hex)。 */
7874
+ G.sha256OfFile = async function sha256OfFile(file) {
7875
+ const buffer = await file.arrayBuffer()
7876
+ const digest = await crypto.subtle.digest('SHA-256', buffer)
7877
+ return Array.from(new Uint8Array(digest)).map((byte) => byte.toString(16).padStart(2, '0')).join('')
7878
+ }
7879
+
7880
+ /** 把文本插入当前对话输入框:优先官方 input 服务,失败退回 contenteditable 插入。 */
7881
+ G.insertIntoComposer = function insertIntoComposer(text) {
7882
+ if (typeof text !== 'string' || text === '') return false
7883
+ try {
7884
+ const sessionEl = document.querySelector('[data-conversation-session]')
7885
+ const sessionId = sessionEl === null ? '' : String(sessionEl.getAttribute('data-conversation-session') ?? '')
7886
+ const sessions = G.ctx === null || G.ctx === undefined ? undefined : G.ctx.get('sessions')
7887
+ const conversation = G.ctx === null || G.ctx === undefined ? undefined : G.ctx.get('conversation')
7888
+ if (sessionId !== '' && sessions !== undefined && conversation !== undefined && typeof sessions.scope === 'function') {
7889
+ const actx = sessions.scope(sessionId)
7890
+ if (actx !== undefined) {
7891
+ const input = conversation.input.for(actx)
7892
+ const snapshot = input?.state?.getSnapshot?.()
7893
+ if (snapshot !== undefined && input !== null && input !== undefined) {
7894
+ const offset = String(snapshot.draft ?? '').length
7895
+ const span = { start: offset, end: offset, draftRev: snapshot.draftRev }
7896
+ if (typeof input.insertText === 'function' && input.insertText(text, span) === true) return true
7897
+ if (typeof input.insertReference === 'function') {
7898
+ const mention = G.mentionOfPath(text.replace(/^@/, ''))
7899
+ if (mention !== '' && input.insertReference({ source: 'reference', ref: mention, label: text.replace(/^@/, ''), appearance: 'file', clipboardText: mention }, span) === true) return true
7900
+ }
7901
+ }
7902
+ }
7903
+ }
7904
+ } catch {
7905
+ /* fall through */
7906
+ }
7907
+ try {
7908
+ const editor = document.querySelector('[data-conversation-region="composer"] [contenteditable="true"]') || document.querySelector('[data-conversation-region="composer"]')
7909
+ if (editor === null) return false
7910
+ editor.focus()
7911
+ if (document.execCommand('insertText', false, text)) return true
7912
+ } catch {
7913
+ /* ignore */
7914
+ }
7915
+ return false
7916
+ }
7917
+
7918
+ /**
7919
+ * 安装「粘贴文件 → @引用」监听。
7920
+ * @param {object} ctx client 根 context
7921
+ * @returns {() => void} 卸载器
7922
+ */
7923
+ G.installChatFilePaste = function installChatFilePaste(ctx) {
7924
+ if (typeof document === 'undefined') return () => {}
7925
+ let disposed = false
7926
+
7927
+ const handleFiles = async (files) => {
7928
+ const list = Array.from(files)
7929
+ if (list.length === 0) return
7930
+ const root = typeof G.projectRoot === 'string' ? G.projectRoot : ''
7931
+ if (root === '') {
7932
+ G.refToast('还没有打开项目,无法把文件转成 @ 引用', 'err')
7933
+ return
7934
+ }
7935
+ const payloads = []
7936
+ for (const file of list) {
7937
+ try {
7938
+ payloads.push({ name: file.name !== '' ? file.name : 'file', size: file.size, sha256: await G.sha256OfFile(file) })
7939
+ } catch {
7940
+ /* 读取失败的文件跳过 */
7941
+ }
7942
+ }
7943
+ if (payloads.length === 0) {
7944
+ G.refToast('粘贴的文件读取失败', 'err')
7945
+ return
7946
+ }
7947
+ let matches = []
7948
+ try {
7949
+ const result = await G.api('fs.matchFiles', { root, files: payloads })
7950
+ matches = Array.isArray(result?.matches) ? result.matches : []
7951
+ } catch (error) {
7952
+ G.refToast(`匹配项目文件失败:${G.errorText(error)}`, 'err')
7953
+ return
7954
+ }
7955
+ if (disposed) return
7956
+ const refs = []
7957
+ const missing = []
7958
+ for (const match of matches) {
7959
+ if (typeof match?.path === 'string' && match.path !== '') refs.push(G.mentionOfPath(match.path))
7960
+ else missing.push(String(match?.name ?? ''))
7961
+ }
7962
+ if (refs.length > 0) {
7963
+ const inserted = G.insertIntoComposer(refs.join(' ') + ' ')
7964
+ if (inserted) G.refToast(`已插入 ${refs.length} 个文件引用`, 'ok')
7965
+ else G.refToast('插入引用失败:输入框不可用', 'err')
7966
+ }
7967
+ if (missing.length > 0) {
7968
+ G.refToast(`${missing.join('、')} 不在当前项目里,未插入引用(可先粘贴到资源管理器导入项目)`, 'err')
7969
+ }
7970
+ }
7971
+
7972
+ const onPaste = (event) => {
7973
+ const files = event.clipboardData === null || event.clipboardData === undefined ? undefined : event.clipboardData.files
7974
+ if (files === undefined || files === null || files.length === 0) return
7975
+ const target = event.target
7976
+ const inConversation = target instanceof Element && (target.closest('[data-conversation-region="composer"]') !== null || target.closest('[data-conversation-content]') !== null)
7977
+ if (!inConversation) return
7978
+ const list = Array.from(files)
7979
+ /* 图片保留 DSH 默认的附件粘贴行为 */
7980
+ if (list.every((file) => typeof file.type === 'string' && file.type.startsWith('image/'))) return
7981
+ event.preventDefault()
7982
+ event.stopPropagation()
7983
+ void handleFiles(list)
7984
+ }
7985
+
7986
+ document.addEventListener('paste', onPaste, true)
7987
+ return () => {
7988
+ disposed = true
7989
+ document.removeEventListener('paste', onPaste, true)
7990
+ }
7991
+ }
7992
+
7993
+
7637
7994
  /* ─────────────────────── 60-dock.js ─────────────────────── */
7638
7995
  /**
7639
7996
  * 60-dock:把官方 DSH 会话面板「停靠」进古法编程右侧的 AI 栏。
@@ -8976,6 +9333,9 @@ G.GufaApp = function GufaApp(props) {
8976
9333
  const sessionTitle = useSessions !== undefined ? useSessions(selectSessionTitle) : null
8977
9334
  const currentSessionId = useSessions !== undefined ? useSessions(selectMainSessionId) : null
8978
9335
  const [sessionsOpen, setSessionsOpen] = useState(false)
9336
+ /* 会话弹窗里选中的工作区(null = 跟随当前 IDE 项目) */
9337
+ const [sessionWorkspacePath, setSessionWorkspacePath] = useState(null)
9338
+ const [sessionWorkspacePicker, setSessionWorkspacePicker] = useState(false)
8979
9339
  const recentSessionsJson = useSessions !== undefined ? useSessions(selectRecentSessionsJson) : '[]'
8980
9340
  const recentSessionsRaw = useMemo(() => {
8981
9341
  let parsed
@@ -9042,6 +9402,7 @@ G.GufaApp = function GufaApp(props) {
9042
9402
 
9043
9403
  /* ── 项目打开 ──────────────────────────────────────────────────────── */
9044
9404
  const applyProject = useCallback((value) => {
9405
+ G.projectRoot = typeof value?.root === 'string' ? value.root : null
9045
9406
  setProject(value)
9046
9407
  writeJson(GUFA_LS.project, value?.root ?? null)
9047
9408
  setTabs([])
@@ -9604,11 +9965,15 @@ G.GufaApp = function GufaApp(props) {
9604
9965
  }))
9605
9966
  }, [])
9606
9967
 
9968
+ /* 「仅切换 IDE 项目」:项目固定为用户手动打开的目录,不跟随 DSH 会话/工作区 */
9969
+ const projectPinnedRef = useRef(false)
9970
+
9607
9971
  /* ── 右侧 AI 面板与当前工作区保持一致 ─────────────────────────────────
9608
9972
  * ChatDock 停靠的是 DSH「主视图会话」,但主视图会话可能属于别的工作区
9609
9973
  * (重启恢复、手动切换会话后常见)。项目根变化时自动切到当前工作区的会话。 */
9610
9974
  const dockSyncRef = useRef('')
9611
9975
  useEffect(() => {
9976
+ if (projectPinnedRef.current === true) return undefined
9612
9977
  if (project === null || typeof project.root !== 'string' || project.root === '') return undefined
9613
9978
  if (dockSyncRef.current === project.root) return undefined
9614
9979
  if (typeof sessionCwd === 'string' && sessionCwd !== '' && sessionCwd === project.root) {
@@ -9860,6 +10225,7 @@ G.GufaApp = function GufaApp(props) {
9860
10225
  /* 点击左侧工作区名 → 切换已有工作区(与经典模式同一份 workspace 列表) */
9861
10226
  const switchWorkspace = useCallback(async (workspace) => {
9862
10227
  if (workspace === null || workspace === undefined) return
10228
+ projectPinnedRef.current = false
9863
10229
  const service = workspaceService()
9864
10230
  try {
9865
10231
  if (service !== undefined && service !== null && typeof service.openWorkspace === 'function' && typeof workspace.id === 'string') {
@@ -9895,6 +10261,20 @@ G.GufaApp = function GufaApp(props) {
9895
10261
  }, [openProjectPath, closeWorkspaceDialog, showBanner])
9896
10262
 
9897
10263
  /* 新建工作区:走经典模式同样的「选目录 → 创建 workspace → 打开并新建会话」 */
10264
+ /* 只切换 IDE 项目目录,不切换 DSH 会话/工作区(方便在同一个会话里边看别的项目边聊) */
10265
+ const pinProjectOnly = useCallback(async (workspace) => {
10266
+ if (workspace === null || workspace === undefined || typeof workspace.path !== 'string' || workspace.path === '') return
10267
+ try {
10268
+ projectPinnedRef.current = true
10269
+ await openProjectPath(workspace.path)
10270
+ closeWorkspaceDialog()
10271
+ showBanner('已切换 IDE 项目(当前会话保持不变)', 'success')
10272
+ } catch (error) {
10273
+ projectPinnedRef.current = false
10274
+ setBanner(G.errorText(error))
10275
+ }
10276
+ }, [openProjectPath, closeWorkspaceDialog, showBanner])
10277
+
9898
10278
  const createWorkspace = useCallback(async () => {
9899
10279
  const ui = workspaceService()
9900
10280
  const registry = workspacesService()
@@ -9983,7 +10363,14 @@ G.GufaApp = function GufaApp(props) {
9983
10363
  setRecentCurrentIds((current) => (current.includes(currentSessionId) ? current : [currentSessionId, ...current].slice(0, 12)))
9984
10364
  }, [currentSessionId])
9985
10365
 
9986
- /* 切换会话弹窗:打开时向 Host 拉取「当前工作区的会话」(经典侧边栏同源数据) */
10366
+ useEffect(() => {
10367
+ if (sessionsOpen === true) return undefined
10368
+ setSessionWorkspacePath(null)
10369
+ setSessionWorkspacePicker(false)
10370
+ return undefined
10371
+ }, [sessionsOpen])
10372
+
10373
+ /* 切换会话弹窗:打开时向 Host 拉取「弹窗里选中工作区的会话」(经典侧边栏同源数据) */
9987
10374
  useEffect(() => {
9988
10375
  if (sessionsOpen !== true) return undefined
9989
10376
  if (project === null || typeof project.root !== 'string' || project.root === '') {
@@ -9991,10 +10378,11 @@ G.GufaApp = function GufaApp(props) {
9991
10378
  return undefined
9992
10379
  }
9993
10380
  let cancelled = false
10381
+ const dialogPath = sessionWorkspacePath !== null && sessionWorkspacePath !== '' ? sessionWorkspacePath : project.root
9994
10382
  setWorkspaceSessions({ status: 'loading', sessions: [], groups: [] })
9995
10383
  void Promise.all([
9996
10384
  G.api('workspaces.list', {}).catch(() => ({ workspaces: [] })),
9997
- G.api('workspaces.sessions', { path: project.root, currentSessionId: currentSessionId ?? '' }).catch(() => ({ groups: [] })),
10385
+ G.api('workspaces.sessions', { path: dialogPath, currentSessionId: currentSessionId ?? '' }).catch(() => ({ groups: [] })),
9998
10386
  ])
9999
10387
  .then(([listValue, sessionsValue]) => {
10000
10388
  if (cancelled) return
@@ -10008,7 +10396,7 @@ G.GufaApp = function GufaApp(props) {
10008
10396
  } catch {
10009
10397
  /* ignore */
10010
10398
  }
10011
- const firstGroup = groups.find((group) => group.path === project.root) ?? groups[0]
10399
+ const firstGroup = groups.find((group) => group.path === dialogPath) ?? groups[0]
10012
10400
  setWorkspaceSessions((previous) => {
10013
10401
  const nextSessions = Array.isArray(sessionsValue?.sessions)
10014
10402
  ? sessionsValue.sessions
@@ -10035,7 +10423,7 @@ G.GufaApp = function GufaApp(props) {
10035
10423
  return () => {
10036
10424
  cancelled = true
10037
10425
  }
10038
- }, [sessionsOpen, project?.root, currentSessionId])
10426
+ }, [sessionsOpen, project?.root, currentSessionId, sessionWorkspacePath])
10039
10427
 
10040
10428
  /* ── 退出(关闭覆盖层,回到 DSH 界面) ─────────────────────────────── */
10041
10429
  const exitMode = useCallback(() => {
@@ -10109,6 +10497,60 @@ G.GufaApp = function GufaApp(props) {
10109
10497
  }
10110
10498
  }, [])
10111
10499
 
10500
+ /* 从会话弹窗打开会话:可同时切换到该会话所属工作区的项目 */
10501
+ const openSessionInWorkspace = useCallback((sessionId, workspacePath) => {
10502
+ projectPinnedRef.current = false
10503
+ const service = workspaceService()
10504
+ const path = typeof workspacePath === 'string' ? workspacePath : ''
10505
+ void (async () => {
10506
+ try {
10507
+ if (service !== undefined && service !== null && typeof service.openSession === 'function') service.openSession(sessionId)
10508
+ else setBanner('当前界面不支持切换会话')
10509
+ } catch (error) {
10510
+ setBanner(G.errorText(error))
10511
+ }
10512
+ if (path !== '' && project !== null && project.root !== path) {
10513
+ try {
10514
+ await openProjectPath(path)
10515
+ setBanner('')
10516
+ } catch (error) {
10517
+ setBanner(G.errorText(error))
10518
+ }
10519
+ }
10520
+ })()
10521
+ }, [project, openProjectPath])
10522
+
10523
+ /* 从会话弹窗新建会话:在弹窗选中的工作区里新建,并切换 IDE 项目 */
10524
+ const startNewSessionInWorkspace = useCallback((workspacePath) => {
10525
+ projectPinnedRef.current = false
10526
+ const service = workspaceService()
10527
+ const path = typeof workspacePath === 'string' ? workspacePath : ''
10528
+ void (async () => {
10529
+ let workspaceId = null
10530
+ try {
10531
+ const value = await G.api('workspaces.list', {})
10532
+ const list = Array.isArray(value?.workspaces) ? value.workspaces : []
10533
+ const matched = list.find((item) => item !== null && item.path === path)
10534
+ if (matched !== undefined && typeof matched.id === 'string') workspaceId = matched.id
10535
+ } catch {
10536
+ workspaceId = null
10537
+ }
10538
+ try {
10539
+ if (service !== undefined && service !== null && typeof service.startSession === 'function') {
10540
+ if (workspaceId !== null) service.startSession(workspaceId)
10541
+ else service.startSession()
10542
+ } else {
10543
+ setBanner('当前界面不支持新建会话')
10544
+ return
10545
+ }
10546
+ if (path !== '' && project !== null && project.root !== path) await openProjectPath(path)
10547
+ setBanner('')
10548
+ } catch (error) {
10549
+ setBanner(G.errorText(error))
10550
+ }
10551
+ })()
10552
+ }, [project, openProjectPath])
10553
+
10112
10554
  const activeFileForChat = useMemo(() => {
10113
10555
  if (activeTab === null || activeTab.kind === 'diff' || activeTab.kind === 'graph') return null
10114
10556
  return { path: activeTab.path, content: activeTab.content ?? '', language: activeTab.language }
@@ -10677,25 +11119,36 @@ G.GufaApp = function GufaApp(props) {
10677
11119
  ? h('div', { className: 'gufa-hint', style: { padding: '10px 8px' } }, t('workspace.empty'))
10678
11120
  : workspaceDialog.workspaces.map((workspace) =>
10679
11121
  h(
10680
- 'button',
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 }),
11122
+ 'div',
11123
+ { key: workspace.id, className: 'gufa-workspace-row-wrap' },
10690
11124
  h(
10691
- 'span',
10692
- { className: 'gufa-branch-name' },
10693
- h('span', { className: 'gufa-workspace-title' }, workspace.title !== '' ? workspace.title : G.basename(workspace.path)),
10694
- h('span', { className: 'gufa-workspace-path' }, workspace.path),
11125
+ 'button',
11126
+ {
11127
+ type: 'button',
11128
+ className: 'gufa-branch-row gufa-workspace-row',
11129
+ 'data-current': project !== null && project.root === workspace.path ? '' : undefined,
11130
+ title: `切换工作区 + 会话:${workspace.path}`,
11131
+ onClick: () => void switchWorkspace(workspace),
11132
+ },
11133
+ h(G.Icon, { name: 'folder-open', size: 13 }),
11134
+ h(
11135
+ 'span',
11136
+ { className: 'gufa-branch-name' },
11137
+ h('span', { className: 'gufa-workspace-title' }, workspace.title !== '' ? workspace.title : G.basename(workspace.path)),
11138
+ h('span', { className: 'gufa-workspace-path' }, workspace.path),
11139
+ ),
11140
+ project !== null && project.root === workspace.path
11141
+ ? h('span', { className: 'gufa-branch-tag' }, t('workspace.current'))
11142
+ : null,
10695
11143
  ),
10696
- project !== null && project.root === workspace.path
10697
- ? h('span', { className: 'gufa-branch-tag' }, t('workspace.current'))
10698
- : null,
11144
+ h(G.IconButton, {
11145
+ title: '只切换 IDE 项目(保持当前会话)',
11146
+ onClick: (event) => {
11147
+ event.preventDefault()
11148
+ event.stopPropagation()
11149
+ void pinProjectOnly(workspace)
11150
+ },
11151
+ }, h(G.Icon, { name: 'panel-left', size: 13 })),
10699
11152
  ),
10700
11153
  ),
10701
11154
  ),
@@ -10841,7 +11294,13 @@ G.GufaApp = function GufaApp(props) {
10841
11294
  const currentRoot = project !== null && typeof project.root === 'string' ? project.root : ''
10842
11295
  const currentWorkspace = workspaceIndex.find((item) => item !== null && item.path === currentRoot)
10843
11296
  const currentWorkspaceId = currentWorkspace !== undefined && typeof currentWorkspace.id === 'string' ? currentWorkspace.id : ''
10844
- const hostGroup = hostGroups.find((group) => (currentWorkspaceId !== '' ? group.workspaceId === currentWorkspaceId : group.path === currentRoot))
11297
+ const dialogPath = sessionWorkspacePath !== null && sessionWorkspacePath !== '' ? sessionWorkspacePath : currentRoot
11298
+ const dialogWorkspace = workspaceIndex.find((item) => item !== null && item.path === dialogPath)
11299
+ const dialogWorkspaceId = dialogWorkspace !== undefined && typeof dialogWorkspace.id === 'string' ? dialogWorkspace.id : ''
11300
+ const dialogWorkspaceTitle = dialogWorkspace !== undefined && typeof dialogWorkspace.title === 'string' && dialogWorkspace.title !== ''
11301
+ ? dialogWorkspace.title
11302
+ : dialogPath !== '' ? G.basename(dialogPath) : ''
11303
+ const hostGroup = hostGroups.find((group) => (dialogWorkspaceId !== '' ? group.workspaceId === dialogWorkspaceId : group.path === dialogPath))
10845
11304
  const localTitleById = new Map(
10846
11305
  recentSessionsRaw.filter((row) => row !== null && typeof row === 'object' && typeof row.id === 'string').map((row) => [row.id, row.title]),
10847
11306
  )
@@ -10903,7 +11362,7 @@ G.GufaApp = function GufaApp(props) {
10903
11362
  if (fromStore !== undefined && fromStore.blank === true) continue
10904
11363
  // 只保留属于当前工作区的会话(切换工作区后不要带出旧工作区的会话)
10905
11364
  if (fromStore !== undefined && typeof fromStore.workspaceId === 'string' && fromStore.workspaceId !== '' && workspaceSessions.workspaceId !== undefined && workspaceSessions.workspaceId !== '' && fromStore.workspaceId !== workspaceSessions.workspaceId) continue
10906
- if (fromStore !== undefined && typeof fromStore.cwd === 'string' && fromStore.cwd !== '' && project !== null && typeof project.root === 'string' && fromStore.cwd !== project.root) continue
11365
+ if (fromStore !== undefined && typeof fromStore.cwd === 'string' && fromStore.cwd !== '' && dialogPath !== '' && fromStore.cwd !== dialogPath) continue
10907
11366
  const title = localTitleById.get(id) ?? (fromStore !== undefined ? fromStore.title : '')
10908
11367
  if (typeof title !== 'string' || title === '') continue
10909
11368
  retained.push({ id, title, when: localWhenById.get(id) ?? (fromStore !== undefined ? fromStore.when : Date.now()) })
@@ -10934,7 +11393,7 @@ G.GufaApp = function GufaApp(props) {
10934
11393
  title: session.title,
10935
11394
  onClick: () => {
10936
11395
  close()
10937
- openSession(session.id)
11396
+ openSessionInWorkspace(session.id, dialogPath)
10938
11397
  },
10939
11398
  },
10940
11399
  h(G.Icon, { name: 'message', size: 14 }),
@@ -10964,9 +11423,49 @@ G.GufaApp = function GufaApp(props) {
10964
11423
  { className: 'gufa-modal-head' },
10965
11424
  h(G.Icon, { name: 'history', size: 14 }),
10966
11425
  h('span', { style: { flex: '1 1 auto' } }, t('dock.sessionsTitle')),
10967
- project !== null ? h('span', { className: 'gufa-session-workspace' }, project.name) : null,
11426
+ project !== null
11427
+ ? h(
11428
+ 'button',
11429
+ {
11430
+ type: 'button',
11431
+ className: 'gufa-session-workspace gufa-session-workspace-btn',
11432
+ title: '选择工作区(下方会话列表随之切换)',
11433
+ onClick: () => setSessionWorkspacePicker((value) => !value),
11434
+ },
11435
+ h(G.Icon, { name: 'folder-open', size: 12 }),
11436
+ h('span', null, dialogWorkspaceTitle !== '' ? dialogWorkspaceTitle : project.name),
11437
+ h(G.Icon, { name: sessionWorkspacePicker ? 'chevron-up' : 'chevron-down', size: 12 }),
11438
+ )
11439
+ : null,
10968
11440
  h(G.IconButton, { className: 'gufa-modal-close', title: t('common.close'), onClick: close }, h(G.Icon, { name: 'close', size: 14 })),
10969
11441
  ),
11442
+ sessionWorkspacePicker
11443
+ ? h(
11444
+ 'div',
11445
+ { className: 'gufa-session-workspace-picker gufa-scroll' },
11446
+ workspaceIndex.length === 0
11447
+ ? h('div', { className: 'gufa-hint', style: { padding: '8px 12px' } }, t('workspace.empty'))
11448
+ : workspaceIndex.map((workspace) =>
11449
+ h(
11450
+ 'button',
11451
+ {
11452
+ key: workspace.id,
11453
+ type: 'button',
11454
+ className: 'gufa-session-workspace-option',
11455
+ 'data-current': dialogPath === workspace.path ? '' : undefined,
11456
+ title: workspace.path,
11457
+ onClick: () => {
11458
+ setSessionWorkspacePath(workspace.path)
11459
+ setSessionWorkspacePicker(false)
11460
+ },
11461
+ },
11462
+ h(G.Icon, { name: 'folder-open', size: 13 }),
11463
+ h('span', { className: 'gufa-session-workspace-option-title' }, workspace.title !== '' ? workspace.title : G.basename(workspace.path)),
11464
+ h('span', { className: 'gufa-session-workspace-option-path' }, workspace.path),
11465
+ ),
11466
+ ),
11467
+ )
11468
+ : null,
10970
11469
  h(
10971
11470
  'div',
10972
11471
  { className: 'gufa-modal-body' },
@@ -10979,7 +11478,7 @@ G.GufaApp = function GufaApp(props) {
10979
11478
  h(
10980
11479
  'div',
10981
11480
  { className: 'gufa-modal-foot' },
10982
- h(G.Button, { icon: 'plus', onClick: () => { close(); startNewSession() } }, t('dock.newSession')),
11481
+ h(G.Button, { icon: 'plus', onClick: () => { close(); startNewSessionInWorkspace(dialogPath) } }, t('dock.newSession')),
10983
11482
  h(G.Button, { onClick: close }, t('common.close')),
10984
11483
  ),
10985
11484
  ),
@@ -11321,6 +11820,47 @@ const GUFA_PLUGIN = {
11321
11820
  /* ignore */
11322
11821
  }
11323
11822
 
11823
+ /* ── 清理「每会话右侧面板布局」里由 dsh-vscode-mode 留下的『文件编辑』标签 ──
11824
+ * 官方右侧栏会把每个会话的布局持久化到 localStorage(键 dsh.sidebar-right.v1.<sessionId>),
11825
+ * 切换会话时恢复该布局 → 历史上被 vscode-mode 写过标签的会话会「自动展开右侧栏」。
11826
+ * 这里在页面加载后清理这些残留键,让会话恢复成默认(收起)状态。 */
11827
+ const cleanStaleSidebarLayouts = () => {
11828
+ try {
11829
+ const keys = []
11830
+ for (let index = 0; index < window.localStorage.length; index += 1) {
11831
+ const key = window.localStorage.key(index)
11832
+ if (key !== null && key.startsWith('dsh.sidebar-right.v1.')) keys.push(key)
11833
+ }
11834
+ let removed = 0
11835
+ for (const key of keys) {
11836
+ const raw = window.localStorage.getItem(key)
11837
+ if (raw === null) continue
11838
+ if (raw.includes('edrvEditor') || raw.includes('vscode-mode')) {
11839
+ window.localStorage.removeItem(key)
11840
+ removed += 1
11841
+ }
11842
+ }
11843
+ if (removed > 0) {
11844
+ void G.api('dev.log', { message: `sidebar-layout-cleanup removed=${removed}/${keys.length}` }).catch(() => {})
11845
+ }
11846
+ } catch {
11847
+ /* localStorage 不可用时忽略 */
11848
+ }
11849
+ }
11850
+ cleanStaleSidebarLayouts()
11851
+ window.setTimeout(cleanStaleSidebarLayouts, 1500)
11852
+ window.setTimeout(cleanStaleSidebarLayouts, 5000)
11853
+
11854
+ // 聊天框:粘贴系统文件 → 自动插入 @文件引用(内容匹配项目内文件后插入)
11855
+ try {
11856
+ if (typeof G.installChatFilePaste === 'function') {
11857
+ const disposeChatPaste = G.installChatFilePaste(ctx)
11858
+ if (typeof disposeChatPaste === 'function') ctx.effect(() => disposeChatPaste, 'gufa-code: chat file paste')
11859
+ }
11860
+ } catch (error) {
11861
+ console.error('[gufa-code] 安装聊天框文件粘贴失败', error)
11862
+ }
11863
+
11324
11864
  // 样式(随插件 context 卸载自动移除)
11325
11865
  ctx.effect(() => G.injectStyles(), 'gufa-code: styles')
11326
11866