dsh-gufa-code 1.0.2 → 1.1.1

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 CHANGED
@@ -42,6 +42,8 @@ dsh plugin add dsh-gufa-code
42
42
  - 多标签、按扩展名语法高亮、面包屑、状态栏(分支 / 行列 / 保存状态);
43
43
  - 保存走磁盘版本冲突检测 + 原子写;未保存标记;
44
44
  - 资源管理器右键:新建 / 重命名 / 删除 / 复制 / 粘贴 / 打开所在文件夹 / 两文件对比;
45
+ - **从 Finder 粘贴/拖入文件**:系统剪贴板里复制的文件可直接 ⌘V 粘进资源管理器(写入选中的目录,重名自动加「副本」),也可从 Finder 直接拖进文件树;
46
+ - **粘贴文件到聊天框 = @引用**:在 Finder 复制文件后在右侧对话输入框 ⌘V,会自动匹配项目内同名同内容文件并插入 `@相对路径` 引用(图片仍按 DSH 默认附件处理);
45
47
  - 支持 Ctrl/Cmd 多选、软删除与 `⌘Z` 撤销;
46
48
  - **Git diff**:Monaco diff 视图,红绿强对比、自动定位第一处改动,工作区一侧可编辑并自动保存;
47
49
  - **两文件对比**:任选两个文件,左右都可编辑(本地草稿,保存时写回)。
@@ -62,6 +64,7 @@ dsh plugin add dsh-gufa-code
62
64
 
63
65
  - 右侧停靠的就是 **官方 DSH 会话本体**:工具调用、自动读写文件、审批、斜杠命令、上下文引用、会话历史全部可用;
64
66
  - 工具条:新建会话 / 会话列表 / 打开完整对话 / 收起;
67
+ - **会话弹窗里可以直接切换工作区**:点弹窗右上角的工作区名,选任意工作区后下方会话列表随之切换,点会话即打开(IDE 项目同时切到该工作区),不用再先切左侧工作区;
65
68
  - 会话里的文件链接、diff 标签页属于 DSH 右侧栏,被覆盖层挡住时点「打开完整对话」即可查看。
66
69
 
67
70
  ### 外观
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}
@@ -9281,6 +9333,9 @@ G.GufaApp = function GufaApp(props) {
9281
9333
  const sessionTitle = useSessions !== undefined ? useSessions(selectSessionTitle) : null
9282
9334
  const currentSessionId = useSessions !== undefined ? useSessions(selectMainSessionId) : null
9283
9335
  const [sessionsOpen, setSessionsOpen] = useState(false)
9336
+ /* 会话弹窗里选中的工作区(null = 跟随当前 IDE 项目) */
9337
+ const [sessionWorkspacePath, setSessionWorkspacePath] = useState(null)
9338
+ const [sessionWorkspacePicker, setSessionWorkspacePicker] = useState(false)
9284
9339
  const recentSessionsJson = useSessions !== undefined ? useSessions(selectRecentSessionsJson) : '[]'
9285
9340
  const recentSessionsRaw = useMemo(() => {
9286
9341
  let parsed
@@ -9912,13 +9967,15 @@ G.GufaApp = function GufaApp(props) {
9912
9967
 
9913
9968
  /* 「仅切换 IDE 项目」:项目固定为用户手动打开的目录,不跟随 DSH 会话/工作区 */
9914
9969
  const projectPinnedRef = useRef(false)
9970
+ /* 会话弹窗里选了别的工作区的会话:右侧会话保持不动,不再自动把 IDE 项目切过去 */
9971
+ const sessionPinnedRef = useRef(false)
9915
9972
 
9916
9973
  /* ── 右侧 AI 面板与当前工作区保持一致 ─────────────────────────────────
9917
9974
  * ChatDock 停靠的是 DSH「主视图会话」,但主视图会话可能属于别的工作区
9918
9975
  * (重启恢复、手动切换会话后常见)。项目根变化时自动切到当前工作区的会话。 */
9919
9976
  const dockSyncRef = useRef('')
9920
9977
  useEffect(() => {
9921
- if (projectPinnedRef.current === true) return undefined
9978
+ if (projectPinnedRef.current === true || sessionPinnedRef.current === true) return undefined
9922
9979
  if (project === null || typeof project.root !== 'string' || project.root === '') return undefined
9923
9980
  if (dockSyncRef.current === project.root) return undefined
9924
9981
  if (typeof sessionCwd === 'string' && sessionCwd !== '' && sessionCwd === project.root) {
@@ -10171,6 +10228,7 @@ G.GufaApp = function GufaApp(props) {
10171
10228
  const switchWorkspace = useCallback(async (workspace) => {
10172
10229
  if (workspace === null || workspace === undefined) return
10173
10230
  projectPinnedRef.current = false
10231
+ sessionPinnedRef.current = false
10174
10232
  const service = workspaceService()
10175
10233
  try {
10176
10234
  if (service !== undefined && service !== null && typeof service.openWorkspace === 'function' && typeof workspace.id === 'string') {
@@ -10211,6 +10269,7 @@ G.GufaApp = function GufaApp(props) {
10211
10269
  if (workspace === null || workspace === undefined || typeof workspace.path !== 'string' || workspace.path === '') return
10212
10270
  try {
10213
10271
  projectPinnedRef.current = true
10272
+ sessionPinnedRef.current = false
10214
10273
  await openProjectPath(workspace.path)
10215
10274
  closeWorkspaceDialog()
10216
10275
  showBanner('已切换 IDE 项目(当前会话保持不变)', 'success')
@@ -10294,6 +10353,7 @@ G.GufaApp = function GufaApp(props) {
10294
10353
  /* 经典界面里切换工作区时:当前主视图会话的 cwd 变化 → 跟随打开对应项目 */
10295
10354
  const lastSessionCwdRef = useRef(null)
10296
10355
  useEffect(() => {
10356
+ if (sessionPinnedRef.current === true) return
10297
10357
  if (typeof sessionCwd !== 'string' || sessionCwd === '') return
10298
10358
  const previous = lastSessionCwdRef.current
10299
10359
  lastSessionCwdRef.current = sessionCwd
@@ -10308,7 +10368,14 @@ G.GufaApp = function GufaApp(props) {
10308
10368
  setRecentCurrentIds((current) => (current.includes(currentSessionId) ? current : [currentSessionId, ...current].slice(0, 12)))
10309
10369
  }, [currentSessionId])
10310
10370
 
10311
- /* 切换会话弹窗:打开时向 Host 拉取「当前工作区的会话」(经典侧边栏同源数据) */
10371
+ useEffect(() => {
10372
+ if (sessionsOpen === true) return undefined
10373
+ setSessionWorkspacePath(null)
10374
+ setSessionWorkspacePicker(false)
10375
+ return undefined
10376
+ }, [sessionsOpen])
10377
+
10378
+ /* 切换会话弹窗:打开时向 Host 拉取「弹窗里选中工作区的会话」(经典侧边栏同源数据) */
10312
10379
  useEffect(() => {
10313
10380
  if (sessionsOpen !== true) return undefined
10314
10381
  if (project === null || typeof project.root !== 'string' || project.root === '') {
@@ -10316,10 +10383,11 @@ G.GufaApp = function GufaApp(props) {
10316
10383
  return undefined
10317
10384
  }
10318
10385
  let cancelled = false
10386
+ const dialogPath = sessionWorkspacePath !== null && sessionWorkspacePath !== '' ? sessionWorkspacePath : project.root
10319
10387
  setWorkspaceSessions({ status: 'loading', sessions: [], groups: [] })
10320
10388
  void Promise.all([
10321
10389
  G.api('workspaces.list', {}).catch(() => ({ workspaces: [] })),
10322
- G.api('workspaces.sessions', { path: project.root, currentSessionId: currentSessionId ?? '' }).catch(() => ({ groups: [] })),
10390
+ G.api('workspaces.sessions', { path: dialogPath, currentSessionId: currentSessionId ?? '' }).catch(() => ({ groups: [] })),
10323
10391
  ])
10324
10392
  .then(([listValue, sessionsValue]) => {
10325
10393
  if (cancelled) return
@@ -10333,7 +10401,7 @@ G.GufaApp = function GufaApp(props) {
10333
10401
  } catch {
10334
10402
  /* ignore */
10335
10403
  }
10336
- const firstGroup = groups.find((group) => group.path === project.root) ?? groups[0]
10404
+ const firstGroup = groups.find((group) => group.path === dialogPath) ?? groups[0]
10337
10405
  setWorkspaceSessions((previous) => {
10338
10406
  const nextSessions = Array.isArray(sessionsValue?.sessions)
10339
10407
  ? sessionsValue.sessions
@@ -10360,7 +10428,7 @@ G.GufaApp = function GufaApp(props) {
10360
10428
  return () => {
10361
10429
  cancelled = true
10362
10430
  }
10363
- }, [sessionsOpen, project?.root, currentSessionId])
10431
+ }, [sessionsOpen, project?.root, currentSessionId, sessionWorkspacePath])
10364
10432
 
10365
10433
  /* ── 退出(关闭覆盖层,回到 DSH 界面) ─────────────────────────────── */
10366
10434
  const exitMode = useCallback(() => {
@@ -10434,6 +10502,52 @@ G.GufaApp = function GufaApp(props) {
10434
10502
  }
10435
10503
  }, [])
10436
10504
 
10505
+ /* 从会话弹窗打开会话:可同时切换到该会话所属工作区的项目 */
10506
+ const openSessionInWorkspace = useCallback((sessionId, workspacePath) => {
10507
+ const service = workspaceService()
10508
+ const path = typeof workspacePath === 'string' ? workspacePath : ''
10509
+ /* 只切右侧会话:选了别的工作区的会话时,左侧项目/工作区保持不动 */
10510
+ sessionPinnedRef.current = path !== '' && project !== null && path !== project.root
10511
+ lastSessionCwdRef.current = null
10512
+ try {
10513
+ if (service !== undefined && service !== null && typeof service.openSession === 'function') service.openSession(sessionId)
10514
+ else setBanner('当前界面不支持切换会话')
10515
+ setBanner('')
10516
+ } catch (error) {
10517
+ setBanner(G.errorText(error))
10518
+ }
10519
+ }, [project])
10520
+
10521
+ /* 从会话弹窗新建会话:在弹窗选中的工作区里新建,并切换 IDE 项目 */
10522
+ const startNewSessionInWorkspace = useCallback((workspacePath) => {
10523
+ const service = workspaceService()
10524
+ const path = typeof workspacePath === 'string' ? workspacePath : ''
10525
+ void (async () => {
10526
+ let workspaceId = null
10527
+ try {
10528
+ const value = await G.api('workspaces.list', {})
10529
+ const list = Array.isArray(value?.workspaces) ? value.workspaces : []
10530
+ const matched = list.find((item) => item !== null && item.path === path)
10531
+ if (matched !== undefined && typeof matched.id === 'string') workspaceId = matched.id
10532
+ } catch {
10533
+ workspaceId = null
10534
+ }
10535
+ try {
10536
+ if (service !== undefined && service !== null && typeof service.startSession === 'function') {
10537
+ /* 只新建会话,不切左侧项目;跨工作区时 pin 住避免自动同步 */
10538
+ sessionPinnedRef.current = path !== '' && project !== null && path !== project.root
10539
+ if (workspaceId !== null) service.startSession(workspaceId)
10540
+ else service.startSession()
10541
+ setBanner('')
10542
+ } else {
10543
+ setBanner('当前界面不支持新建会话')
10544
+ }
10545
+ } catch (error) {
10546
+ setBanner(G.errorText(error))
10547
+ }
10548
+ })()
10549
+ }, [project])
10550
+
10437
10551
  const activeFileForChat = useMemo(() => {
10438
10552
  if (activeTab === null || activeTab.kind === 'diff' || activeTab.kind === 'graph') return null
10439
10553
  return { path: activeTab.path, content: activeTab.content ?? '', language: activeTab.language }
@@ -11177,7 +11291,13 @@ G.GufaApp = function GufaApp(props) {
11177
11291
  const currentRoot = project !== null && typeof project.root === 'string' ? project.root : ''
11178
11292
  const currentWorkspace = workspaceIndex.find((item) => item !== null && item.path === currentRoot)
11179
11293
  const currentWorkspaceId = currentWorkspace !== undefined && typeof currentWorkspace.id === 'string' ? currentWorkspace.id : ''
11180
- const hostGroup = hostGroups.find((group) => (currentWorkspaceId !== '' ? group.workspaceId === currentWorkspaceId : group.path === currentRoot))
11294
+ const dialogPath = sessionWorkspacePath !== null && sessionWorkspacePath !== '' ? sessionWorkspacePath : currentRoot
11295
+ const dialogWorkspace = workspaceIndex.find((item) => item !== null && item.path === dialogPath)
11296
+ const dialogWorkspaceId = dialogWorkspace !== undefined && typeof dialogWorkspace.id === 'string' ? dialogWorkspace.id : ''
11297
+ const dialogWorkspaceTitle = dialogWorkspace !== undefined && typeof dialogWorkspace.title === 'string' && dialogWorkspace.title !== ''
11298
+ ? dialogWorkspace.title
11299
+ : dialogPath !== '' ? G.basename(dialogPath) : ''
11300
+ const hostGroup = hostGroups.find((group) => (dialogWorkspaceId !== '' ? group.workspaceId === dialogWorkspaceId : group.path === dialogPath))
11181
11301
  const localTitleById = new Map(
11182
11302
  recentSessionsRaw.filter((row) => row !== null && typeof row === 'object' && typeof row.id === 'string').map((row) => [row.id, row.title]),
11183
11303
  )
@@ -11239,7 +11359,7 @@ G.GufaApp = function GufaApp(props) {
11239
11359
  if (fromStore !== undefined && fromStore.blank === true) continue
11240
11360
  // 只保留属于当前工作区的会话(切换工作区后不要带出旧工作区的会话)
11241
11361
  if (fromStore !== undefined && typeof fromStore.workspaceId === 'string' && fromStore.workspaceId !== '' && workspaceSessions.workspaceId !== undefined && workspaceSessions.workspaceId !== '' && fromStore.workspaceId !== workspaceSessions.workspaceId) continue
11242
- if (fromStore !== undefined && typeof fromStore.cwd === 'string' && fromStore.cwd !== '' && project !== null && typeof project.root === 'string' && fromStore.cwd !== project.root) continue
11362
+ if (fromStore !== undefined && typeof fromStore.cwd === 'string' && fromStore.cwd !== '' && dialogPath !== '' && fromStore.cwd !== dialogPath) continue
11243
11363
  const title = localTitleById.get(id) ?? (fromStore !== undefined ? fromStore.title : '')
11244
11364
  if (typeof title !== 'string' || title === '') continue
11245
11365
  retained.push({ id, title, when: localWhenById.get(id) ?? (fromStore !== undefined ? fromStore.when : Date.now()) })
@@ -11270,7 +11390,7 @@ G.GufaApp = function GufaApp(props) {
11270
11390
  title: session.title,
11271
11391
  onClick: () => {
11272
11392
  close()
11273
- openSession(session.id)
11393
+ openSessionInWorkspace(session.id, dialogPath)
11274
11394
  },
11275
11395
  },
11276
11396
  h(G.Icon, { name: 'message', size: 14 }),
@@ -11300,9 +11420,49 @@ G.GufaApp = function GufaApp(props) {
11300
11420
  { className: 'gufa-modal-head' },
11301
11421
  h(G.Icon, { name: 'history', size: 14 }),
11302
11422
  h('span', { style: { flex: '1 1 auto' } }, t('dock.sessionsTitle')),
11303
- project !== null ? h('span', { className: 'gufa-session-workspace' }, project.name) : null,
11423
+ project !== null
11424
+ ? h(
11425
+ 'button',
11426
+ {
11427
+ type: 'button',
11428
+ className: 'gufa-session-workspace gufa-session-workspace-btn',
11429
+ title: '选择工作区(下方会话列表随之切换)',
11430
+ onClick: () => setSessionWorkspacePicker((value) => !value),
11431
+ },
11432
+ h(G.Icon, { name: 'folder-open', size: 12 }),
11433
+ h('span', null, dialogWorkspaceTitle !== '' ? dialogWorkspaceTitle : project.name),
11434
+ h(G.Icon, { name: sessionWorkspacePicker ? 'chevron-up' : 'chevron-down', size: 12 }),
11435
+ )
11436
+ : null,
11304
11437
  h(G.IconButton, { className: 'gufa-modal-close', title: t('common.close'), onClick: close }, h(G.Icon, { name: 'close', size: 14 })),
11305
11438
  ),
11439
+ sessionWorkspacePicker
11440
+ ? h(
11441
+ 'div',
11442
+ { className: 'gufa-session-workspace-picker gufa-scroll' },
11443
+ workspaceIndex.length === 0
11444
+ ? h('div', { className: 'gufa-hint', style: { padding: '8px 12px' } }, t('workspace.empty'))
11445
+ : workspaceIndex.map((workspace) =>
11446
+ h(
11447
+ 'button',
11448
+ {
11449
+ key: workspace.id,
11450
+ type: 'button',
11451
+ className: 'gufa-session-workspace-option',
11452
+ 'data-current': dialogPath === workspace.path ? '' : undefined,
11453
+ title: workspace.path,
11454
+ onClick: () => {
11455
+ setSessionWorkspacePath(workspace.path)
11456
+ setSessionWorkspacePicker(false)
11457
+ },
11458
+ },
11459
+ h(G.Icon, { name: 'folder-open', size: 13 }),
11460
+ h('span', { className: 'gufa-session-workspace-option-title' }, workspace.title !== '' ? workspace.title : G.basename(workspace.path)),
11461
+ h('span', { className: 'gufa-session-workspace-option-path' }, workspace.path),
11462
+ ),
11463
+ ),
11464
+ )
11465
+ : null,
11306
11466
  h(
11307
11467
  'div',
11308
11468
  { className: 'gufa-modal-body' },
@@ -11315,7 +11475,7 @@ G.GufaApp = function GufaApp(props) {
11315
11475
  h(
11316
11476
  'div',
11317
11477
  { className: 'gufa-modal-foot' },
11318
- h(G.Button, { icon: 'plus', onClick: () => { close(); startNewSession() } }, t('dock.newSession')),
11478
+ h(G.Button, { icon: 'plus', onClick: () => { close(); startNewSessionInWorkspace(dialogPath) } }, t('dock.newSession')),
11319
11479
  h(G.Button, { onClick: close }, t('common.close')),
11320
11480
  ),
11321
11481
  ),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-gufa-code",
3
- "version": "1.0.2",
3
+ "version": "1.1.1",
4
4
  "description": "古法编程 · AI 辅助:在 DSH Web 界面一键进入 VS Code 风格 IDE(Monaco 编辑器、文件树、Git、SSH、真实终端与右侧 AI 聊天)",
5
5
  "icon": "icon.svg",
6
6
  "keywords": [
@@ -1078,6 +1078,19 @@ html[data-gufa-ide] [role="dialog"] {
1078
1078
  .gufa-session-group-count{font-size:10.5px;opacity:.6;font-variant-numeric:tabular-nums}
1079
1079
  .gufa-session-group[data-current] .gufa-session-group-head{color:var(--gufa-text)}
1080
1080
  .gufa-session-group .gufa-session-row{margin-left:10px}
1081
+ .gufa-session-workspace-btn{display:inline-flex;align-items:center;gap:4px;border:1px solid var(--gufa-border);background:var(--gufa-layer2);
1082
+ color:var(--gufa-text-dim);border-radius:7px;padding:2px 8px;font:inherit;font-size:11.5px;cursor:pointer;max-width:260px}
1083
+ .gufa-session-workspace-btn:hover{background:var(--gufa-hover);color:var(--gufa-text)}
1084
+ .gufa-session-workspace-btn span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
1085
+ .gufa-session-workspace-picker{display:flex;flex-direction:column;gap:2px;padding:6px 10px;max-height:220px;overflow:auto;
1086
+ border-top:1px solid var(--gufa-border);border-bottom:1px solid var(--gufa-border);background:var(--gufa-layer)}
1087
+ .gufa-session-workspace-option{display:flex;align-items:center;gap:8px;width:100%;padding:6px 8px;border:0;border-radius:7px;
1088
+ background:transparent;color:var(--gufa-text);font:inherit;font-size:12px;cursor:pointer;text-align:left}
1089
+ .gufa-session-workspace-option:hover{background:var(--gufa-hover)}
1090
+ .gufa-session-workspace-option[data-current]{background:var(--gufa-active)}
1091
+ .gufa-session-workspace-option-title{flex:0 0 auto;font-weight:550}
1092
+ .gufa-session-workspace-option-path{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
1093
+ color:var(--gufa-text-dim);font-size:10.5px;text-align:right}
1081
1094
  .gufa-session-workspace{font-size:11px;color:var(--gufa-text-dim);max-width:40%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
1082
1095
  .gufa-session-row-title{flex:1 1 auto;overflow:hidden;text-overflow:ellipsis}
1083
1096
  .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}
@@ -1121,6 +1134,19 @@ html[data-gufa-ide] [role="dialog"] {
1121
1134
  .gufa-session-group-count{font-size:10.5px;opacity:.6;font-variant-numeric:tabular-nums}
1122
1135
  .gufa-session-group[data-current] .gufa-session-group-head{color:var(--gufa-text)}
1123
1136
  .gufa-session-group .gufa-session-row{margin-left:10px}
1137
+ .gufa-session-workspace-btn{display:inline-flex;align-items:center;gap:4px;border:1px solid var(--gufa-border);background:var(--gufa-layer2);
1138
+ color:var(--gufa-text-dim);border-radius:7px;padding:2px 8px;font:inherit;font-size:11.5px;cursor:pointer;max-width:260px}
1139
+ .gufa-session-workspace-btn:hover{background:var(--gufa-hover);color:var(--gufa-text)}
1140
+ .gufa-session-workspace-btn span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
1141
+ .gufa-session-workspace-picker{display:flex;flex-direction:column;gap:2px;padding:6px 10px;max-height:220px;overflow:auto;
1142
+ border-top:1px solid var(--gufa-border);border-bottom:1px solid var(--gufa-border);background:var(--gufa-layer)}
1143
+ .gufa-session-workspace-option{display:flex;align-items:center;gap:8px;width:100%;padding:6px 8px;border:0;border-radius:7px;
1144
+ background:transparent;color:var(--gufa-text);font:inherit;font-size:12px;cursor:pointer;text-align:left}
1145
+ .gufa-session-workspace-option:hover{background:var(--gufa-hover)}
1146
+ .gufa-session-workspace-option[data-current]{background:var(--gufa-active)}
1147
+ .gufa-session-workspace-option-title{flex:0 0 auto;font-weight:550}
1148
+ .gufa-session-workspace-option-path{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
1149
+ color:var(--gufa-text-dim);font-size:10.5px;text-align:right}
1124
1150
  .gufa-session-workspace{font-size:11px;color:var(--gufa-text-dim);max-width:40%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
1125
1151
  .gufa-session-row-title{flex:1 1 auto;overflow:hidden;text-overflow:ellipsis}
1126
1152
  .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}
@@ -1164,6 +1190,19 @@ html[data-gufa-ide] [role="dialog"] {
1164
1190
  .gufa-session-group-count{font-size:10.5px;opacity:.6;font-variant-numeric:tabular-nums}
1165
1191
  .gufa-session-group[data-current] .gufa-session-group-head{color:var(--gufa-text)}
1166
1192
  .gufa-session-group .gufa-session-row{margin-left:10px}
1193
+ .gufa-session-workspace-btn{display:inline-flex;align-items:center;gap:4px;border:1px solid var(--gufa-border);background:var(--gufa-layer2);
1194
+ color:var(--gufa-text-dim);border-radius:7px;padding:2px 8px;font:inherit;font-size:11.5px;cursor:pointer;max-width:260px}
1195
+ .gufa-session-workspace-btn:hover{background:var(--gufa-hover);color:var(--gufa-text)}
1196
+ .gufa-session-workspace-btn span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
1197
+ .gufa-session-workspace-picker{display:flex;flex-direction:column;gap:2px;padding:6px 10px;max-height:220px;overflow:auto;
1198
+ border-top:1px solid var(--gufa-border);border-bottom:1px solid var(--gufa-border);background:var(--gufa-layer)}
1199
+ .gufa-session-workspace-option{display:flex;align-items:center;gap:8px;width:100%;padding:6px 8px;border:0;border-radius:7px;
1200
+ background:transparent;color:var(--gufa-text);font:inherit;font-size:12px;cursor:pointer;text-align:left}
1201
+ .gufa-session-workspace-option:hover{background:var(--gufa-hover)}
1202
+ .gufa-session-workspace-option[data-current]{background:var(--gufa-active)}
1203
+ .gufa-session-workspace-option-title{flex:0 0 auto;font-weight:550}
1204
+ .gufa-session-workspace-option-path{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
1205
+ color:var(--gufa-text-dim);font-size:10.5px;text-align:right}
1167
1206
  .gufa-session-workspace{font-size:11px;color:var(--gufa-text-dim);max-width:40%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
1168
1207
  .gufa-session-row-title{flex:1 1 auto;overflow:hidden;text-overflow:ellipsis}
1169
1208
  .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}
@@ -1207,6 +1246,19 @@ html[data-gufa-ide] [role="dialog"] {
1207
1246
  .gufa-session-group-count{font-size:10.5px;opacity:.6;font-variant-numeric:tabular-nums}
1208
1247
  .gufa-session-group[data-current] .gufa-session-group-head{color:var(--gufa-text)}
1209
1248
  .gufa-session-group .gufa-session-row{margin-left:10px}
1249
+ .gufa-session-workspace-btn{display:inline-flex;align-items:center;gap:4px;border:1px solid var(--gufa-border);background:var(--gufa-layer2);
1250
+ color:var(--gufa-text-dim);border-radius:7px;padding:2px 8px;font:inherit;font-size:11.5px;cursor:pointer;max-width:260px}
1251
+ .gufa-session-workspace-btn:hover{background:var(--gufa-hover);color:var(--gufa-text)}
1252
+ .gufa-session-workspace-btn span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
1253
+ .gufa-session-workspace-picker{display:flex;flex-direction:column;gap:2px;padding:6px 10px;max-height:220px;overflow:auto;
1254
+ border-top:1px solid var(--gufa-border);border-bottom:1px solid var(--gufa-border);background:var(--gufa-layer)}
1255
+ .gufa-session-workspace-option{display:flex;align-items:center;gap:8px;width:100%;padding:6px 8px;border:0;border-radius:7px;
1256
+ background:transparent;color:var(--gufa-text);font:inherit;font-size:12px;cursor:pointer;text-align:left}
1257
+ .gufa-session-workspace-option:hover{background:var(--gufa-hover)}
1258
+ .gufa-session-workspace-option[data-current]{background:var(--gufa-active)}
1259
+ .gufa-session-workspace-option-title{flex:0 0 auto;font-weight:550}
1260
+ .gufa-session-workspace-option-path{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
1261
+ color:var(--gufa-text-dim);font-size:10.5px;text-align:right}
1210
1262
  .gufa-session-workspace{font-size:11px;color:var(--gufa-text-dim);max-width:40%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
1211
1263
  .gufa-session-row-title{flex:1 1 auto;overflow:hidden;text-overflow:ellipsis}
1212
1264
  .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}
@@ -155,6 +155,9 @@ G.GufaApp = function GufaApp(props) {
155
155
  const sessionTitle = useSessions !== undefined ? useSessions(selectSessionTitle) : null
156
156
  const currentSessionId = useSessions !== undefined ? useSessions(selectMainSessionId) : null
157
157
  const [sessionsOpen, setSessionsOpen] = useState(false)
158
+ /* 会话弹窗里选中的工作区(null = 跟随当前 IDE 项目) */
159
+ const [sessionWorkspacePath, setSessionWorkspacePath] = useState(null)
160
+ const [sessionWorkspacePicker, setSessionWorkspacePicker] = useState(false)
158
161
  const recentSessionsJson = useSessions !== undefined ? useSessions(selectRecentSessionsJson) : '[]'
159
162
  const recentSessionsRaw = useMemo(() => {
160
163
  let parsed
@@ -786,13 +789,15 @@ G.GufaApp = function GufaApp(props) {
786
789
 
787
790
  /* 「仅切换 IDE 项目」:项目固定为用户手动打开的目录,不跟随 DSH 会话/工作区 */
788
791
  const projectPinnedRef = useRef(false)
792
+ /* 会话弹窗里选了别的工作区的会话:右侧会话保持不动,不再自动把 IDE 项目切过去 */
793
+ const sessionPinnedRef = useRef(false)
789
794
 
790
795
  /* ── 右侧 AI 面板与当前工作区保持一致 ─────────────────────────────────
791
796
  * ChatDock 停靠的是 DSH「主视图会话」,但主视图会话可能属于别的工作区
792
797
  * (重启恢复、手动切换会话后常见)。项目根变化时自动切到当前工作区的会话。 */
793
798
  const dockSyncRef = useRef('')
794
799
  useEffect(() => {
795
- if (projectPinnedRef.current === true) return undefined
800
+ if (projectPinnedRef.current === true || sessionPinnedRef.current === true) return undefined
796
801
  if (project === null || typeof project.root !== 'string' || project.root === '') return undefined
797
802
  if (dockSyncRef.current === project.root) return undefined
798
803
  if (typeof sessionCwd === 'string' && sessionCwd !== '' && sessionCwd === project.root) {
@@ -1045,6 +1050,7 @@ G.GufaApp = function GufaApp(props) {
1045
1050
  const switchWorkspace = useCallback(async (workspace) => {
1046
1051
  if (workspace === null || workspace === undefined) return
1047
1052
  projectPinnedRef.current = false
1053
+ sessionPinnedRef.current = false
1048
1054
  const service = workspaceService()
1049
1055
  try {
1050
1056
  if (service !== undefined && service !== null && typeof service.openWorkspace === 'function' && typeof workspace.id === 'string') {
@@ -1085,6 +1091,7 @@ G.GufaApp = function GufaApp(props) {
1085
1091
  if (workspace === null || workspace === undefined || typeof workspace.path !== 'string' || workspace.path === '') return
1086
1092
  try {
1087
1093
  projectPinnedRef.current = true
1094
+ sessionPinnedRef.current = false
1088
1095
  await openProjectPath(workspace.path)
1089
1096
  closeWorkspaceDialog()
1090
1097
  showBanner('已切换 IDE 项目(当前会话保持不变)', 'success')
@@ -1168,6 +1175,7 @@ G.GufaApp = function GufaApp(props) {
1168
1175
  /* 经典界面里切换工作区时:当前主视图会话的 cwd 变化 → 跟随打开对应项目 */
1169
1176
  const lastSessionCwdRef = useRef(null)
1170
1177
  useEffect(() => {
1178
+ if (sessionPinnedRef.current === true) return
1171
1179
  if (typeof sessionCwd !== 'string' || sessionCwd === '') return
1172
1180
  const previous = lastSessionCwdRef.current
1173
1181
  lastSessionCwdRef.current = sessionCwd
@@ -1182,7 +1190,14 @@ G.GufaApp = function GufaApp(props) {
1182
1190
  setRecentCurrentIds((current) => (current.includes(currentSessionId) ? current : [currentSessionId, ...current].slice(0, 12)))
1183
1191
  }, [currentSessionId])
1184
1192
 
1185
- /* 切换会话弹窗:打开时向 Host 拉取「当前工作区的会话」(经典侧边栏同源数据) */
1193
+ useEffect(() => {
1194
+ if (sessionsOpen === true) return undefined
1195
+ setSessionWorkspacePath(null)
1196
+ setSessionWorkspacePicker(false)
1197
+ return undefined
1198
+ }, [sessionsOpen])
1199
+
1200
+ /* 切换会话弹窗:打开时向 Host 拉取「弹窗里选中工作区的会话」(经典侧边栏同源数据) */
1186
1201
  useEffect(() => {
1187
1202
  if (sessionsOpen !== true) return undefined
1188
1203
  if (project === null || typeof project.root !== 'string' || project.root === '') {
@@ -1190,10 +1205,11 @@ G.GufaApp = function GufaApp(props) {
1190
1205
  return undefined
1191
1206
  }
1192
1207
  let cancelled = false
1208
+ const dialogPath = sessionWorkspacePath !== null && sessionWorkspacePath !== '' ? sessionWorkspacePath : project.root
1193
1209
  setWorkspaceSessions({ status: 'loading', sessions: [], groups: [] })
1194
1210
  void Promise.all([
1195
1211
  G.api('workspaces.list', {}).catch(() => ({ workspaces: [] })),
1196
- G.api('workspaces.sessions', { path: project.root, currentSessionId: currentSessionId ?? '' }).catch(() => ({ groups: [] })),
1212
+ G.api('workspaces.sessions', { path: dialogPath, currentSessionId: currentSessionId ?? '' }).catch(() => ({ groups: [] })),
1197
1213
  ])
1198
1214
  .then(([listValue, sessionsValue]) => {
1199
1215
  if (cancelled) return
@@ -1207,7 +1223,7 @@ G.GufaApp = function GufaApp(props) {
1207
1223
  } catch {
1208
1224
  /* ignore */
1209
1225
  }
1210
- const firstGroup = groups.find((group) => group.path === project.root) ?? groups[0]
1226
+ const firstGroup = groups.find((group) => group.path === dialogPath) ?? groups[0]
1211
1227
  setWorkspaceSessions((previous) => {
1212
1228
  const nextSessions = Array.isArray(sessionsValue?.sessions)
1213
1229
  ? sessionsValue.sessions
@@ -1234,7 +1250,7 @@ G.GufaApp = function GufaApp(props) {
1234
1250
  return () => {
1235
1251
  cancelled = true
1236
1252
  }
1237
- }, [sessionsOpen, project?.root, currentSessionId])
1253
+ }, [sessionsOpen, project?.root, currentSessionId, sessionWorkspacePath])
1238
1254
 
1239
1255
  /* ── 退出(关闭覆盖层,回到 DSH 界面) ─────────────────────────────── */
1240
1256
  const exitMode = useCallback(() => {
@@ -1308,6 +1324,52 @@ G.GufaApp = function GufaApp(props) {
1308
1324
  }
1309
1325
  }, [])
1310
1326
 
1327
+ /* 从会话弹窗打开会话:可同时切换到该会话所属工作区的项目 */
1328
+ const openSessionInWorkspace = useCallback((sessionId, workspacePath) => {
1329
+ const service = workspaceService()
1330
+ const path = typeof workspacePath === 'string' ? workspacePath : ''
1331
+ /* 只切右侧会话:选了别的工作区的会话时,左侧项目/工作区保持不动 */
1332
+ sessionPinnedRef.current = path !== '' && project !== null && path !== project.root
1333
+ lastSessionCwdRef.current = null
1334
+ try {
1335
+ if (service !== undefined && service !== null && typeof service.openSession === 'function') service.openSession(sessionId)
1336
+ else setBanner('当前界面不支持切换会话')
1337
+ setBanner('')
1338
+ } catch (error) {
1339
+ setBanner(G.errorText(error))
1340
+ }
1341
+ }, [project])
1342
+
1343
+ /* 从会话弹窗新建会话:在弹窗选中的工作区里新建,并切换 IDE 项目 */
1344
+ const startNewSessionInWorkspace = useCallback((workspacePath) => {
1345
+ const service = workspaceService()
1346
+ const path = typeof workspacePath === 'string' ? workspacePath : ''
1347
+ void (async () => {
1348
+ let workspaceId = null
1349
+ try {
1350
+ const value = await G.api('workspaces.list', {})
1351
+ const list = Array.isArray(value?.workspaces) ? value.workspaces : []
1352
+ const matched = list.find((item) => item !== null && item.path === path)
1353
+ if (matched !== undefined && typeof matched.id === 'string') workspaceId = matched.id
1354
+ } catch {
1355
+ workspaceId = null
1356
+ }
1357
+ try {
1358
+ if (service !== undefined && service !== null && typeof service.startSession === 'function') {
1359
+ /* 只新建会话,不切左侧项目;跨工作区时 pin 住避免自动同步 */
1360
+ sessionPinnedRef.current = path !== '' && project !== null && path !== project.root
1361
+ if (workspaceId !== null) service.startSession(workspaceId)
1362
+ else service.startSession()
1363
+ setBanner('')
1364
+ } else {
1365
+ setBanner('当前界面不支持新建会话')
1366
+ }
1367
+ } catch (error) {
1368
+ setBanner(G.errorText(error))
1369
+ }
1370
+ })()
1371
+ }, [project])
1372
+
1311
1373
  const activeFileForChat = useMemo(() => {
1312
1374
  if (activeTab === null || activeTab.kind === 'diff' || activeTab.kind === 'graph') return null
1313
1375
  return { path: activeTab.path, content: activeTab.content ?? '', language: activeTab.language }
@@ -2051,7 +2113,13 @@ G.GufaApp = function GufaApp(props) {
2051
2113
  const currentRoot = project !== null && typeof project.root === 'string' ? project.root : ''
2052
2114
  const currentWorkspace = workspaceIndex.find((item) => item !== null && item.path === currentRoot)
2053
2115
  const currentWorkspaceId = currentWorkspace !== undefined && typeof currentWorkspace.id === 'string' ? currentWorkspace.id : ''
2054
- const hostGroup = hostGroups.find((group) => (currentWorkspaceId !== '' ? group.workspaceId === currentWorkspaceId : group.path === currentRoot))
2116
+ const dialogPath = sessionWorkspacePath !== null && sessionWorkspacePath !== '' ? sessionWorkspacePath : currentRoot
2117
+ const dialogWorkspace = workspaceIndex.find((item) => item !== null && item.path === dialogPath)
2118
+ const dialogWorkspaceId = dialogWorkspace !== undefined && typeof dialogWorkspace.id === 'string' ? dialogWorkspace.id : ''
2119
+ const dialogWorkspaceTitle = dialogWorkspace !== undefined && typeof dialogWorkspace.title === 'string' && dialogWorkspace.title !== ''
2120
+ ? dialogWorkspace.title
2121
+ : dialogPath !== '' ? G.basename(dialogPath) : ''
2122
+ const hostGroup = hostGroups.find((group) => (dialogWorkspaceId !== '' ? group.workspaceId === dialogWorkspaceId : group.path === dialogPath))
2055
2123
  const localTitleById = new Map(
2056
2124
  recentSessionsRaw.filter((row) => row !== null && typeof row === 'object' && typeof row.id === 'string').map((row) => [row.id, row.title]),
2057
2125
  )
@@ -2113,7 +2181,7 @@ G.GufaApp = function GufaApp(props) {
2113
2181
  if (fromStore !== undefined && fromStore.blank === true) continue
2114
2182
  // 只保留属于当前工作区的会话(切换工作区后不要带出旧工作区的会话)
2115
2183
  if (fromStore !== undefined && typeof fromStore.workspaceId === 'string' && fromStore.workspaceId !== '' && workspaceSessions.workspaceId !== undefined && workspaceSessions.workspaceId !== '' && fromStore.workspaceId !== workspaceSessions.workspaceId) continue
2116
- if (fromStore !== undefined && typeof fromStore.cwd === 'string' && fromStore.cwd !== '' && project !== null && typeof project.root === 'string' && fromStore.cwd !== project.root) continue
2184
+ if (fromStore !== undefined && typeof fromStore.cwd === 'string' && fromStore.cwd !== '' && dialogPath !== '' && fromStore.cwd !== dialogPath) continue
2117
2185
  const title = localTitleById.get(id) ?? (fromStore !== undefined ? fromStore.title : '')
2118
2186
  if (typeof title !== 'string' || title === '') continue
2119
2187
  retained.push({ id, title, when: localWhenById.get(id) ?? (fromStore !== undefined ? fromStore.when : Date.now()) })
@@ -2144,7 +2212,7 @@ G.GufaApp = function GufaApp(props) {
2144
2212
  title: session.title,
2145
2213
  onClick: () => {
2146
2214
  close()
2147
- openSession(session.id)
2215
+ openSessionInWorkspace(session.id, dialogPath)
2148
2216
  },
2149
2217
  },
2150
2218
  h(G.Icon, { name: 'message', size: 14 }),
@@ -2174,9 +2242,49 @@ G.GufaApp = function GufaApp(props) {
2174
2242
  { className: 'gufa-modal-head' },
2175
2243
  h(G.Icon, { name: 'history', size: 14 }),
2176
2244
  h('span', { style: { flex: '1 1 auto' } }, t('dock.sessionsTitle')),
2177
- project !== null ? h('span', { className: 'gufa-session-workspace' }, project.name) : null,
2245
+ project !== null
2246
+ ? h(
2247
+ 'button',
2248
+ {
2249
+ type: 'button',
2250
+ className: 'gufa-session-workspace gufa-session-workspace-btn',
2251
+ title: '选择工作区(下方会话列表随之切换)',
2252
+ onClick: () => setSessionWorkspacePicker((value) => !value),
2253
+ },
2254
+ h(G.Icon, { name: 'folder-open', size: 12 }),
2255
+ h('span', null, dialogWorkspaceTitle !== '' ? dialogWorkspaceTitle : project.name),
2256
+ h(G.Icon, { name: sessionWorkspacePicker ? 'chevron-up' : 'chevron-down', size: 12 }),
2257
+ )
2258
+ : null,
2178
2259
  h(G.IconButton, { className: 'gufa-modal-close', title: t('common.close'), onClick: close }, h(G.Icon, { name: 'close', size: 14 })),
2179
2260
  ),
2261
+ sessionWorkspacePicker
2262
+ ? h(
2263
+ 'div',
2264
+ { className: 'gufa-session-workspace-picker gufa-scroll' },
2265
+ workspaceIndex.length === 0
2266
+ ? h('div', { className: 'gufa-hint', style: { padding: '8px 12px' } }, t('workspace.empty'))
2267
+ : workspaceIndex.map((workspace) =>
2268
+ h(
2269
+ 'button',
2270
+ {
2271
+ key: workspace.id,
2272
+ type: 'button',
2273
+ className: 'gufa-session-workspace-option',
2274
+ 'data-current': dialogPath === workspace.path ? '' : undefined,
2275
+ title: workspace.path,
2276
+ onClick: () => {
2277
+ setSessionWorkspacePath(workspace.path)
2278
+ setSessionWorkspacePicker(false)
2279
+ },
2280
+ },
2281
+ h(G.Icon, { name: 'folder-open', size: 13 }),
2282
+ h('span', { className: 'gufa-session-workspace-option-title' }, workspace.title !== '' ? workspace.title : G.basename(workspace.path)),
2283
+ h('span', { className: 'gufa-session-workspace-option-path' }, workspace.path),
2284
+ ),
2285
+ ),
2286
+ )
2287
+ : null,
2180
2288
  h(
2181
2289
  'div',
2182
2290
  { className: 'gufa-modal-body' },
@@ -2189,7 +2297,7 @@ G.GufaApp = function GufaApp(props) {
2189
2297
  h(
2190
2298
  'div',
2191
2299
  { className: 'gufa-modal-foot' },
2192
- h(G.Button, { icon: 'plus', onClick: () => { close(); startNewSession() } }, t('dock.newSession')),
2300
+ h(G.Button, { icon: 'plus', onClick: () => { close(); startNewSessionInWorkspace(dialogPath) } }, t('dock.newSession')),
2193
2301
  h(G.Button, { onClick: close }, t('common.close')),
2194
2302
  ),
2195
2303
  ),