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/README.md +3 -0
- package/client.js +575 -35
- package/host/fs.js +95 -0
- package/host/git.js +0 -112
- package/package.json +1 -1
- package/scripts/test-editor.mjs +4 -13
- package/src/client/00-core.js +57 -0
- package/src/client/20-editor.js +54 -9
- package/src/client/50-panels.js +96 -0
- package/src/client/58-insert-ref.js +156 -0
- package/src/client/90-app.js +168 -26
- package/src/client/99-main.js +41 -0
- package/vendor/monaco/vs/worker-bootstrap.js +16 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 58-insert-ref:把系统剪贴板里的文件粘贴进对话输入框时,插入 `@相对路径` 引用。
|
|
3
|
+
*
|
|
4
|
+
* 浏览器/Electron 的剪贴板只给 File 内容、不给磁盘路径,所以流程是:
|
|
5
|
+
* File → 名称/size/sha256 → Host(fs.matchFiles) 在项目内匹配同名同内容文件 → 插入 @引用。
|
|
6
|
+
* 图片保持 DSH 默认的附件行为(不拦截)。
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** 轻量提示条(复用 drag-ref 的观感)。 */
|
|
10
|
+
G.refToast = function refToast(text, kind) {
|
|
11
|
+
try {
|
|
12
|
+
let host = document.getElementById('gufa-ref-toast')
|
|
13
|
+
if (host === null) {
|
|
14
|
+
host = document.createElement('div')
|
|
15
|
+
host.id = 'gufa-ref-toast'
|
|
16
|
+
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'
|
|
17
|
+
document.body.appendChild(host)
|
|
18
|
+
}
|
|
19
|
+
host.textContent = String(text)
|
|
20
|
+
host.style.background = kind === 'err' ? 'rgba(180,35,24,.92)' : kind === 'ok' ? 'rgba(6,118,71,.92)' : 'rgba(28,30,38,.92)'
|
|
21
|
+
host.style.color = '#fff'
|
|
22
|
+
clearTimeout(G.refToast.timer)
|
|
23
|
+
G.refToast.timer = window.setTimeout(() => {
|
|
24
|
+
if (host.parentNode !== null) host.parentNode.removeChild(host)
|
|
25
|
+
}, 3200)
|
|
26
|
+
} catch {
|
|
27
|
+
/* ignore */
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** 把相对路径变成 @ 引用文本(含空格的路径加引号)。 */
|
|
32
|
+
G.mentionOfPath = function mentionOfPath(path) {
|
|
33
|
+
const rel = String(path ?? '').replace(/\\/g, '/')
|
|
34
|
+
if (rel === '') return ''
|
|
35
|
+
return /\s/u.test(rel) ? `@"${rel}"` : `@${rel}`
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** 取文件 sha256(hex)。 */
|
|
39
|
+
G.sha256OfFile = async function sha256OfFile(file) {
|
|
40
|
+
const buffer = await file.arrayBuffer()
|
|
41
|
+
const digest = await crypto.subtle.digest('SHA-256', buffer)
|
|
42
|
+
return Array.from(new Uint8Array(digest)).map((byte) => byte.toString(16).padStart(2, '0')).join('')
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** 把文本插入当前对话输入框:优先官方 input 服务,失败退回 contenteditable 插入。 */
|
|
46
|
+
G.insertIntoComposer = function insertIntoComposer(text) {
|
|
47
|
+
if (typeof text !== 'string' || text === '') return false
|
|
48
|
+
try {
|
|
49
|
+
const sessionEl = document.querySelector('[data-conversation-session]')
|
|
50
|
+
const sessionId = sessionEl === null ? '' : String(sessionEl.getAttribute('data-conversation-session') ?? '')
|
|
51
|
+
const sessions = G.ctx === null || G.ctx === undefined ? undefined : G.ctx.get('sessions')
|
|
52
|
+
const conversation = G.ctx === null || G.ctx === undefined ? undefined : G.ctx.get('conversation')
|
|
53
|
+
if (sessionId !== '' && sessions !== undefined && conversation !== undefined && typeof sessions.scope === 'function') {
|
|
54
|
+
const actx = sessions.scope(sessionId)
|
|
55
|
+
if (actx !== undefined) {
|
|
56
|
+
const input = conversation.input.for(actx)
|
|
57
|
+
const snapshot = input?.state?.getSnapshot?.()
|
|
58
|
+
if (snapshot !== undefined && input !== null && input !== undefined) {
|
|
59
|
+
const offset = String(snapshot.draft ?? '').length
|
|
60
|
+
const span = { start: offset, end: offset, draftRev: snapshot.draftRev }
|
|
61
|
+
if (typeof input.insertText === 'function' && input.insertText(text, span) === true) return true
|
|
62
|
+
if (typeof input.insertReference === 'function') {
|
|
63
|
+
const mention = G.mentionOfPath(text.replace(/^@/, ''))
|
|
64
|
+
if (mention !== '' && input.insertReference({ source: 'reference', ref: mention, label: text.replace(/^@/, ''), appearance: 'file', clipboardText: mention }, span) === true) return true
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
} catch {
|
|
70
|
+
/* fall through */
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
const editor = document.querySelector('[data-conversation-region="composer"] [contenteditable="true"]') || document.querySelector('[data-conversation-region="composer"]')
|
|
74
|
+
if (editor === null) return false
|
|
75
|
+
editor.focus()
|
|
76
|
+
if (document.execCommand('insertText', false, text)) return true
|
|
77
|
+
} catch {
|
|
78
|
+
/* ignore */
|
|
79
|
+
}
|
|
80
|
+
return false
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* 安装「粘贴文件 → @引用」监听。
|
|
85
|
+
* @param {object} ctx client 根 context
|
|
86
|
+
* @returns {() => void} 卸载器
|
|
87
|
+
*/
|
|
88
|
+
G.installChatFilePaste = function installChatFilePaste(ctx) {
|
|
89
|
+
if (typeof document === 'undefined') return () => {}
|
|
90
|
+
let disposed = false
|
|
91
|
+
|
|
92
|
+
const handleFiles = async (files) => {
|
|
93
|
+
const list = Array.from(files)
|
|
94
|
+
if (list.length === 0) return
|
|
95
|
+
const root = typeof G.projectRoot === 'string' ? G.projectRoot : ''
|
|
96
|
+
if (root === '') {
|
|
97
|
+
G.refToast('还没有打开项目,无法把文件转成 @ 引用', 'err')
|
|
98
|
+
return
|
|
99
|
+
}
|
|
100
|
+
const payloads = []
|
|
101
|
+
for (const file of list) {
|
|
102
|
+
try {
|
|
103
|
+
payloads.push({ name: file.name !== '' ? file.name : 'file', size: file.size, sha256: await G.sha256OfFile(file) })
|
|
104
|
+
} catch {
|
|
105
|
+
/* 读取失败的文件跳过 */
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (payloads.length === 0) {
|
|
109
|
+
G.refToast('粘贴的文件读取失败', 'err')
|
|
110
|
+
return
|
|
111
|
+
}
|
|
112
|
+
let matches = []
|
|
113
|
+
try {
|
|
114
|
+
const result = await G.api('fs.matchFiles', { root, files: payloads })
|
|
115
|
+
matches = Array.isArray(result?.matches) ? result.matches : []
|
|
116
|
+
} catch (error) {
|
|
117
|
+
G.refToast(`匹配项目文件失败:${G.errorText(error)}`, 'err')
|
|
118
|
+
return
|
|
119
|
+
}
|
|
120
|
+
if (disposed) return
|
|
121
|
+
const refs = []
|
|
122
|
+
const missing = []
|
|
123
|
+
for (const match of matches) {
|
|
124
|
+
if (typeof match?.path === 'string' && match.path !== '') refs.push(G.mentionOfPath(match.path))
|
|
125
|
+
else missing.push(String(match?.name ?? ''))
|
|
126
|
+
}
|
|
127
|
+
if (refs.length > 0) {
|
|
128
|
+
const inserted = G.insertIntoComposer(refs.join(' ') + ' ')
|
|
129
|
+
if (inserted) G.refToast(`已插入 ${refs.length} 个文件引用`, 'ok')
|
|
130
|
+
else G.refToast('插入引用失败:输入框不可用', 'err')
|
|
131
|
+
}
|
|
132
|
+
if (missing.length > 0) {
|
|
133
|
+
G.refToast(`${missing.join('、')} 不在当前项目里,未插入引用(可先粘贴到资源管理器导入项目)`, 'err')
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const onPaste = (event) => {
|
|
138
|
+
const files = event.clipboardData === null || event.clipboardData === undefined ? undefined : event.clipboardData.files
|
|
139
|
+
if (files === undefined || files === null || files.length === 0) return
|
|
140
|
+
const target = event.target
|
|
141
|
+
const inConversation = target instanceof Element && (target.closest('[data-conversation-region="composer"]') !== null || target.closest('[data-conversation-content]') !== null)
|
|
142
|
+
if (!inConversation) return
|
|
143
|
+
const list = Array.from(files)
|
|
144
|
+
/* 图片保留 DSH 默认的附件粘贴行为 */
|
|
145
|
+
if (list.every((file) => typeof file.type === 'string' && file.type.startsWith('image/'))) return
|
|
146
|
+
event.preventDefault()
|
|
147
|
+
event.stopPropagation()
|
|
148
|
+
void handleFiles(list)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
document.addEventListener('paste', onPaste, true)
|
|
152
|
+
return () => {
|
|
153
|
+
disposed = true
|
|
154
|
+
document.removeEventListener('paste', onPaste, true)
|
|
155
|
+
}
|
|
156
|
+
}
|
package/src/client/90-app.js
CHANGED
|
@@ -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
|
|
@@ -221,6 +224,7 @@ G.GufaApp = function GufaApp(props) {
|
|
|
221
224
|
|
|
222
225
|
/* ── 项目打开 ──────────────────────────────────────────────────────── */
|
|
223
226
|
const applyProject = useCallback((value) => {
|
|
227
|
+
G.projectRoot = typeof value?.root === 'string' ? value.root : null
|
|
224
228
|
setProject(value)
|
|
225
229
|
writeJson(GUFA_LS.project, value?.root ?? null)
|
|
226
230
|
setTabs([])
|
|
@@ -783,11 +787,15 @@ G.GufaApp = function GufaApp(props) {
|
|
|
783
787
|
}))
|
|
784
788
|
}, [])
|
|
785
789
|
|
|
790
|
+
/* 「仅切换 IDE 项目」:项目固定为用户手动打开的目录,不跟随 DSH 会话/工作区 */
|
|
791
|
+
const projectPinnedRef = useRef(false)
|
|
792
|
+
|
|
786
793
|
/* ── 右侧 AI 面板与当前工作区保持一致 ─────────────────────────────────
|
|
787
794
|
* ChatDock 停靠的是 DSH「主视图会话」,但主视图会话可能属于别的工作区
|
|
788
795
|
* (重启恢复、手动切换会话后常见)。项目根变化时自动切到当前工作区的会话。 */
|
|
789
796
|
const dockSyncRef = useRef('')
|
|
790
797
|
useEffect(() => {
|
|
798
|
+
if (projectPinnedRef.current === true) return undefined
|
|
791
799
|
if (project === null || typeof project.root !== 'string' || project.root === '') return undefined
|
|
792
800
|
if (dockSyncRef.current === project.root) return undefined
|
|
793
801
|
if (typeof sessionCwd === 'string' && sessionCwd !== '' && sessionCwd === project.root) {
|
|
@@ -1039,6 +1047,7 @@ G.GufaApp = function GufaApp(props) {
|
|
|
1039
1047
|
/* 点击左侧工作区名 → 切换已有工作区(与经典模式同一份 workspace 列表) */
|
|
1040
1048
|
const switchWorkspace = useCallback(async (workspace) => {
|
|
1041
1049
|
if (workspace === null || workspace === undefined) return
|
|
1050
|
+
projectPinnedRef.current = false
|
|
1042
1051
|
const service = workspaceService()
|
|
1043
1052
|
try {
|
|
1044
1053
|
if (service !== undefined && service !== null && typeof service.openWorkspace === 'function' && typeof workspace.id === 'string') {
|
|
@@ -1074,6 +1083,20 @@ G.GufaApp = function GufaApp(props) {
|
|
|
1074
1083
|
}, [openProjectPath, closeWorkspaceDialog, showBanner])
|
|
1075
1084
|
|
|
1076
1085
|
/* 新建工作区:走经典模式同样的「选目录 → 创建 workspace → 打开并新建会话」 */
|
|
1086
|
+
/* 只切换 IDE 项目目录,不切换 DSH 会话/工作区(方便在同一个会话里边看别的项目边聊) */
|
|
1087
|
+
const pinProjectOnly = useCallback(async (workspace) => {
|
|
1088
|
+
if (workspace === null || workspace === undefined || typeof workspace.path !== 'string' || workspace.path === '') return
|
|
1089
|
+
try {
|
|
1090
|
+
projectPinnedRef.current = true
|
|
1091
|
+
await openProjectPath(workspace.path)
|
|
1092
|
+
closeWorkspaceDialog()
|
|
1093
|
+
showBanner('已切换 IDE 项目(当前会话保持不变)', 'success')
|
|
1094
|
+
} catch (error) {
|
|
1095
|
+
projectPinnedRef.current = false
|
|
1096
|
+
setBanner(G.errorText(error))
|
|
1097
|
+
}
|
|
1098
|
+
}, [openProjectPath, closeWorkspaceDialog, showBanner])
|
|
1099
|
+
|
|
1077
1100
|
const createWorkspace = useCallback(async () => {
|
|
1078
1101
|
const ui = workspaceService()
|
|
1079
1102
|
const registry = workspacesService()
|
|
@@ -1162,7 +1185,14 @@ G.GufaApp = function GufaApp(props) {
|
|
|
1162
1185
|
setRecentCurrentIds((current) => (current.includes(currentSessionId) ? current : [currentSessionId, ...current].slice(0, 12)))
|
|
1163
1186
|
}, [currentSessionId])
|
|
1164
1187
|
|
|
1165
|
-
|
|
1188
|
+
useEffect(() => {
|
|
1189
|
+
if (sessionsOpen === true) return undefined
|
|
1190
|
+
setSessionWorkspacePath(null)
|
|
1191
|
+
setSessionWorkspacePicker(false)
|
|
1192
|
+
return undefined
|
|
1193
|
+
}, [sessionsOpen])
|
|
1194
|
+
|
|
1195
|
+
/* 切换会话弹窗:打开时向 Host 拉取「弹窗里选中工作区的会话」(经典侧边栏同源数据) */
|
|
1166
1196
|
useEffect(() => {
|
|
1167
1197
|
if (sessionsOpen !== true) return undefined
|
|
1168
1198
|
if (project === null || typeof project.root !== 'string' || project.root === '') {
|
|
@@ -1170,10 +1200,11 @@ G.GufaApp = function GufaApp(props) {
|
|
|
1170
1200
|
return undefined
|
|
1171
1201
|
}
|
|
1172
1202
|
let cancelled = false
|
|
1203
|
+
const dialogPath = sessionWorkspacePath !== null && sessionWorkspacePath !== '' ? sessionWorkspacePath : project.root
|
|
1173
1204
|
setWorkspaceSessions({ status: 'loading', sessions: [], groups: [] })
|
|
1174
1205
|
void Promise.all([
|
|
1175
1206
|
G.api('workspaces.list', {}).catch(() => ({ workspaces: [] })),
|
|
1176
|
-
G.api('workspaces.sessions', { path:
|
|
1207
|
+
G.api('workspaces.sessions', { path: dialogPath, currentSessionId: currentSessionId ?? '' }).catch(() => ({ groups: [] })),
|
|
1177
1208
|
])
|
|
1178
1209
|
.then(([listValue, sessionsValue]) => {
|
|
1179
1210
|
if (cancelled) return
|
|
@@ -1187,7 +1218,7 @@ G.GufaApp = function GufaApp(props) {
|
|
|
1187
1218
|
} catch {
|
|
1188
1219
|
/* ignore */
|
|
1189
1220
|
}
|
|
1190
|
-
const firstGroup = groups.find((group) => group.path ===
|
|
1221
|
+
const firstGroup = groups.find((group) => group.path === dialogPath) ?? groups[0]
|
|
1191
1222
|
setWorkspaceSessions((previous) => {
|
|
1192
1223
|
const nextSessions = Array.isArray(sessionsValue?.sessions)
|
|
1193
1224
|
? sessionsValue.sessions
|
|
@@ -1214,7 +1245,7 @@ G.GufaApp = function GufaApp(props) {
|
|
|
1214
1245
|
return () => {
|
|
1215
1246
|
cancelled = true
|
|
1216
1247
|
}
|
|
1217
|
-
}, [sessionsOpen, project?.root, currentSessionId])
|
|
1248
|
+
}, [sessionsOpen, project?.root, currentSessionId, sessionWorkspacePath])
|
|
1218
1249
|
|
|
1219
1250
|
/* ── 退出(关闭覆盖层,回到 DSH 界面) ─────────────────────────────── */
|
|
1220
1251
|
const exitMode = useCallback(() => {
|
|
@@ -1288,6 +1319,60 @@ G.GufaApp = function GufaApp(props) {
|
|
|
1288
1319
|
}
|
|
1289
1320
|
}, [])
|
|
1290
1321
|
|
|
1322
|
+
/* 从会话弹窗打开会话:可同时切换到该会话所属工作区的项目 */
|
|
1323
|
+
const openSessionInWorkspace = useCallback((sessionId, workspacePath) => {
|
|
1324
|
+
projectPinnedRef.current = false
|
|
1325
|
+
const service = workspaceService()
|
|
1326
|
+
const path = typeof workspacePath === 'string' ? workspacePath : ''
|
|
1327
|
+
void (async () => {
|
|
1328
|
+
try {
|
|
1329
|
+
if (service !== undefined && service !== null && typeof service.openSession === 'function') service.openSession(sessionId)
|
|
1330
|
+
else setBanner('当前界面不支持切换会话')
|
|
1331
|
+
} catch (error) {
|
|
1332
|
+
setBanner(G.errorText(error))
|
|
1333
|
+
}
|
|
1334
|
+
if (path !== '' && project !== null && project.root !== path) {
|
|
1335
|
+
try {
|
|
1336
|
+
await openProjectPath(path)
|
|
1337
|
+
setBanner('')
|
|
1338
|
+
} catch (error) {
|
|
1339
|
+
setBanner(G.errorText(error))
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
})()
|
|
1343
|
+
}, [project, openProjectPath])
|
|
1344
|
+
|
|
1345
|
+
/* 从会话弹窗新建会话:在弹窗选中的工作区里新建,并切换 IDE 项目 */
|
|
1346
|
+
const startNewSessionInWorkspace = useCallback((workspacePath) => {
|
|
1347
|
+
projectPinnedRef.current = false
|
|
1348
|
+
const service = workspaceService()
|
|
1349
|
+
const path = typeof workspacePath === 'string' ? workspacePath : ''
|
|
1350
|
+
void (async () => {
|
|
1351
|
+
let workspaceId = null
|
|
1352
|
+
try {
|
|
1353
|
+
const value = await G.api('workspaces.list', {})
|
|
1354
|
+
const list = Array.isArray(value?.workspaces) ? value.workspaces : []
|
|
1355
|
+
const matched = list.find((item) => item !== null && item.path === path)
|
|
1356
|
+
if (matched !== undefined && typeof matched.id === 'string') workspaceId = matched.id
|
|
1357
|
+
} catch {
|
|
1358
|
+
workspaceId = null
|
|
1359
|
+
}
|
|
1360
|
+
try {
|
|
1361
|
+
if (service !== undefined && service !== null && typeof service.startSession === 'function') {
|
|
1362
|
+
if (workspaceId !== null) service.startSession(workspaceId)
|
|
1363
|
+
else service.startSession()
|
|
1364
|
+
} else {
|
|
1365
|
+
setBanner('当前界面不支持新建会话')
|
|
1366
|
+
return
|
|
1367
|
+
}
|
|
1368
|
+
if (path !== '' && project !== null && project.root !== path) await openProjectPath(path)
|
|
1369
|
+
setBanner('')
|
|
1370
|
+
} catch (error) {
|
|
1371
|
+
setBanner(G.errorText(error))
|
|
1372
|
+
}
|
|
1373
|
+
})()
|
|
1374
|
+
}, [project, openProjectPath])
|
|
1375
|
+
|
|
1291
1376
|
const activeFileForChat = useMemo(() => {
|
|
1292
1377
|
if (activeTab === null || activeTab.kind === 'diff' || activeTab.kind === 'graph') return null
|
|
1293
1378
|
return { path: activeTab.path, content: activeTab.content ?? '', language: activeTab.language }
|
|
@@ -1856,25 +1941,36 @@ G.GufaApp = function GufaApp(props) {
|
|
|
1856
1941
|
? h('div', { className: 'gufa-hint', style: { padding: '10px 8px' } }, t('workspace.empty'))
|
|
1857
1942
|
: workspaceDialog.workspaces.map((workspace) =>
|
|
1858
1943
|
h(
|
|
1859
|
-
'
|
|
1860
|
-
{
|
|
1861
|
-
key: workspace.id,
|
|
1862
|
-
type: 'button',
|
|
1863
|
-
className: 'gufa-branch-row gufa-workspace-row',
|
|
1864
|
-
'data-current': project !== null && project.root === workspace.path ? '' : undefined,
|
|
1865
|
-
title: workspace.path,
|
|
1866
|
-
onClick: () => void switchWorkspace(workspace),
|
|
1867
|
-
},
|
|
1868
|
-
h(G.Icon, { name: 'folder-open', size: 13 }),
|
|
1944
|
+
'div',
|
|
1945
|
+
{ key: workspace.id, className: 'gufa-workspace-row-wrap' },
|
|
1869
1946
|
h(
|
|
1870
|
-
'
|
|
1871
|
-
{
|
|
1872
|
-
|
|
1873
|
-
|
|
1947
|
+
'button',
|
|
1948
|
+
{
|
|
1949
|
+
type: 'button',
|
|
1950
|
+
className: 'gufa-branch-row gufa-workspace-row',
|
|
1951
|
+
'data-current': project !== null && project.root === workspace.path ? '' : undefined,
|
|
1952
|
+
title: `切换工作区 + 会话:${workspace.path}`,
|
|
1953
|
+
onClick: () => void switchWorkspace(workspace),
|
|
1954
|
+
},
|
|
1955
|
+
h(G.Icon, { name: 'folder-open', size: 13 }),
|
|
1956
|
+
h(
|
|
1957
|
+
'span',
|
|
1958
|
+
{ className: 'gufa-branch-name' },
|
|
1959
|
+
h('span', { className: 'gufa-workspace-title' }, workspace.title !== '' ? workspace.title : G.basename(workspace.path)),
|
|
1960
|
+
h('span', { className: 'gufa-workspace-path' }, workspace.path),
|
|
1961
|
+
),
|
|
1962
|
+
project !== null && project.root === workspace.path
|
|
1963
|
+
? h('span', { className: 'gufa-branch-tag' }, t('workspace.current'))
|
|
1964
|
+
: null,
|
|
1874
1965
|
),
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
:
|
|
1966
|
+
h(G.IconButton, {
|
|
1967
|
+
title: '只切换 IDE 项目(保持当前会话)',
|
|
1968
|
+
onClick: (event) => {
|
|
1969
|
+
event.preventDefault()
|
|
1970
|
+
event.stopPropagation()
|
|
1971
|
+
void pinProjectOnly(workspace)
|
|
1972
|
+
},
|
|
1973
|
+
}, h(G.Icon, { name: 'panel-left', size: 13 })),
|
|
1878
1974
|
),
|
|
1879
1975
|
),
|
|
1880
1976
|
),
|
|
@@ -2020,7 +2116,13 @@ G.GufaApp = function GufaApp(props) {
|
|
|
2020
2116
|
const currentRoot = project !== null && typeof project.root === 'string' ? project.root : ''
|
|
2021
2117
|
const currentWorkspace = workspaceIndex.find((item) => item !== null && item.path === currentRoot)
|
|
2022
2118
|
const currentWorkspaceId = currentWorkspace !== undefined && typeof currentWorkspace.id === 'string' ? currentWorkspace.id : ''
|
|
2023
|
-
const
|
|
2119
|
+
const dialogPath = sessionWorkspacePath !== null && sessionWorkspacePath !== '' ? sessionWorkspacePath : currentRoot
|
|
2120
|
+
const dialogWorkspace = workspaceIndex.find((item) => item !== null && item.path === dialogPath)
|
|
2121
|
+
const dialogWorkspaceId = dialogWorkspace !== undefined && typeof dialogWorkspace.id === 'string' ? dialogWorkspace.id : ''
|
|
2122
|
+
const dialogWorkspaceTitle = dialogWorkspace !== undefined && typeof dialogWorkspace.title === 'string' && dialogWorkspace.title !== ''
|
|
2123
|
+
? dialogWorkspace.title
|
|
2124
|
+
: dialogPath !== '' ? G.basename(dialogPath) : ''
|
|
2125
|
+
const hostGroup = hostGroups.find((group) => (dialogWorkspaceId !== '' ? group.workspaceId === dialogWorkspaceId : group.path === dialogPath))
|
|
2024
2126
|
const localTitleById = new Map(
|
|
2025
2127
|
recentSessionsRaw.filter((row) => row !== null && typeof row === 'object' && typeof row.id === 'string').map((row) => [row.id, row.title]),
|
|
2026
2128
|
)
|
|
@@ -2082,7 +2184,7 @@ G.GufaApp = function GufaApp(props) {
|
|
|
2082
2184
|
if (fromStore !== undefined && fromStore.blank === true) continue
|
|
2083
2185
|
// 只保留属于当前工作区的会话(切换工作区后不要带出旧工作区的会话)
|
|
2084
2186
|
if (fromStore !== undefined && typeof fromStore.workspaceId === 'string' && fromStore.workspaceId !== '' && workspaceSessions.workspaceId !== undefined && workspaceSessions.workspaceId !== '' && fromStore.workspaceId !== workspaceSessions.workspaceId) continue
|
|
2085
|
-
if (fromStore !== undefined && typeof fromStore.cwd === 'string' && fromStore.cwd !== '' &&
|
|
2187
|
+
if (fromStore !== undefined && typeof fromStore.cwd === 'string' && fromStore.cwd !== '' && dialogPath !== '' && fromStore.cwd !== dialogPath) continue
|
|
2086
2188
|
const title = localTitleById.get(id) ?? (fromStore !== undefined ? fromStore.title : '')
|
|
2087
2189
|
if (typeof title !== 'string' || title === '') continue
|
|
2088
2190
|
retained.push({ id, title, when: localWhenById.get(id) ?? (fromStore !== undefined ? fromStore.when : Date.now()) })
|
|
@@ -2113,7 +2215,7 @@ G.GufaApp = function GufaApp(props) {
|
|
|
2113
2215
|
title: session.title,
|
|
2114
2216
|
onClick: () => {
|
|
2115
2217
|
close()
|
|
2116
|
-
|
|
2218
|
+
openSessionInWorkspace(session.id, dialogPath)
|
|
2117
2219
|
},
|
|
2118
2220
|
},
|
|
2119
2221
|
h(G.Icon, { name: 'message', size: 14 }),
|
|
@@ -2143,9 +2245,49 @@ G.GufaApp = function GufaApp(props) {
|
|
|
2143
2245
|
{ className: 'gufa-modal-head' },
|
|
2144
2246
|
h(G.Icon, { name: 'history', size: 14 }),
|
|
2145
2247
|
h('span', { style: { flex: '1 1 auto' } }, t('dock.sessionsTitle')),
|
|
2146
|
-
project !== null
|
|
2248
|
+
project !== null
|
|
2249
|
+
? h(
|
|
2250
|
+
'button',
|
|
2251
|
+
{
|
|
2252
|
+
type: 'button',
|
|
2253
|
+
className: 'gufa-session-workspace gufa-session-workspace-btn',
|
|
2254
|
+
title: '选择工作区(下方会话列表随之切换)',
|
|
2255
|
+
onClick: () => setSessionWorkspacePicker((value) => !value),
|
|
2256
|
+
},
|
|
2257
|
+
h(G.Icon, { name: 'folder-open', size: 12 }),
|
|
2258
|
+
h('span', null, dialogWorkspaceTitle !== '' ? dialogWorkspaceTitle : project.name),
|
|
2259
|
+
h(G.Icon, { name: sessionWorkspacePicker ? 'chevron-up' : 'chevron-down', size: 12 }),
|
|
2260
|
+
)
|
|
2261
|
+
: null,
|
|
2147
2262
|
h(G.IconButton, { className: 'gufa-modal-close', title: t('common.close'), onClick: close }, h(G.Icon, { name: 'close', size: 14 })),
|
|
2148
2263
|
),
|
|
2264
|
+
sessionWorkspacePicker
|
|
2265
|
+
? h(
|
|
2266
|
+
'div',
|
|
2267
|
+
{ className: 'gufa-session-workspace-picker gufa-scroll' },
|
|
2268
|
+
workspaceIndex.length === 0
|
|
2269
|
+
? h('div', { className: 'gufa-hint', style: { padding: '8px 12px' } }, t('workspace.empty'))
|
|
2270
|
+
: workspaceIndex.map((workspace) =>
|
|
2271
|
+
h(
|
|
2272
|
+
'button',
|
|
2273
|
+
{
|
|
2274
|
+
key: workspace.id,
|
|
2275
|
+
type: 'button',
|
|
2276
|
+
className: 'gufa-session-workspace-option',
|
|
2277
|
+
'data-current': dialogPath === workspace.path ? '' : undefined,
|
|
2278
|
+
title: workspace.path,
|
|
2279
|
+
onClick: () => {
|
|
2280
|
+
setSessionWorkspacePath(workspace.path)
|
|
2281
|
+
setSessionWorkspacePicker(false)
|
|
2282
|
+
},
|
|
2283
|
+
},
|
|
2284
|
+
h(G.Icon, { name: 'folder-open', size: 13 }),
|
|
2285
|
+
h('span', { className: 'gufa-session-workspace-option-title' }, workspace.title !== '' ? workspace.title : G.basename(workspace.path)),
|
|
2286
|
+
h('span', { className: 'gufa-session-workspace-option-path' }, workspace.path),
|
|
2287
|
+
),
|
|
2288
|
+
),
|
|
2289
|
+
)
|
|
2290
|
+
: null,
|
|
2149
2291
|
h(
|
|
2150
2292
|
'div',
|
|
2151
2293
|
{ className: 'gufa-modal-body' },
|
|
@@ -2158,7 +2300,7 @@ G.GufaApp = function GufaApp(props) {
|
|
|
2158
2300
|
h(
|
|
2159
2301
|
'div',
|
|
2160
2302
|
{ className: 'gufa-modal-foot' },
|
|
2161
|
-
h(G.Button, { icon: 'plus', onClick: () => { close();
|
|
2303
|
+
h(G.Button, { icon: 'plus', onClick: () => { close(); startNewSessionInWorkspace(dialogPath) } }, t('dock.newSession')),
|
|
2162
2304
|
h(G.Button, { onClick: close }, t('common.close')),
|
|
2163
2305
|
),
|
|
2164
2306
|
),
|
package/src/client/99-main.js
CHANGED
|
@@ -225,6 +225,47 @@ const GUFA_PLUGIN = {
|
|
|
225
225
|
/* ignore */
|
|
226
226
|
}
|
|
227
227
|
|
|
228
|
+
/* ── 清理「每会话右侧面板布局」里由 dsh-vscode-mode 留下的『文件编辑』标签 ──
|
|
229
|
+
* 官方右侧栏会把每个会话的布局持久化到 localStorage(键 dsh.sidebar-right.v1.<sessionId>),
|
|
230
|
+
* 切换会话时恢复该布局 → 历史上被 vscode-mode 写过标签的会话会「自动展开右侧栏」。
|
|
231
|
+
* 这里在页面加载后清理这些残留键,让会话恢复成默认(收起)状态。 */
|
|
232
|
+
const cleanStaleSidebarLayouts = () => {
|
|
233
|
+
try {
|
|
234
|
+
const keys = []
|
|
235
|
+
for (let index = 0; index < window.localStorage.length; index += 1) {
|
|
236
|
+
const key = window.localStorage.key(index)
|
|
237
|
+
if (key !== null && key.startsWith('dsh.sidebar-right.v1.')) keys.push(key)
|
|
238
|
+
}
|
|
239
|
+
let removed = 0
|
|
240
|
+
for (const key of keys) {
|
|
241
|
+
const raw = window.localStorage.getItem(key)
|
|
242
|
+
if (raw === null) continue
|
|
243
|
+
if (raw.includes('edrvEditor') || raw.includes('vscode-mode')) {
|
|
244
|
+
window.localStorage.removeItem(key)
|
|
245
|
+
removed += 1
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
if (removed > 0) {
|
|
249
|
+
void G.api('dev.log', { message: `sidebar-layout-cleanup removed=${removed}/${keys.length}` }).catch(() => {})
|
|
250
|
+
}
|
|
251
|
+
} catch {
|
|
252
|
+
/* localStorage 不可用时忽略 */
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
cleanStaleSidebarLayouts()
|
|
256
|
+
window.setTimeout(cleanStaleSidebarLayouts, 1500)
|
|
257
|
+
window.setTimeout(cleanStaleSidebarLayouts, 5000)
|
|
258
|
+
|
|
259
|
+
// 聊天框:粘贴系统文件 → 自动插入 @文件引用(内容匹配项目内文件后插入)
|
|
260
|
+
try {
|
|
261
|
+
if (typeof G.installChatFilePaste === 'function') {
|
|
262
|
+
const disposeChatPaste = G.installChatFilePaste(ctx)
|
|
263
|
+
if (typeof disposeChatPaste === 'function') ctx.effect(() => disposeChatPaste, 'gufa-code: chat file paste')
|
|
264
|
+
}
|
|
265
|
+
} catch (error) {
|
|
266
|
+
console.error('[gufa-code] 安装聊天框文件粘贴失败', error)
|
|
267
|
+
}
|
|
268
|
+
|
|
228
269
|
// 样式(随插件 context 卸载自动移除)
|
|
229
270
|
ctx.effect(() => G.injectStyles(), 'gufa-code: styles')
|
|
230
271
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/**
|
|
3
|
+
* Monaco worker 引导脚本(古法编程离线资产)。
|
|
4
|
+
*
|
|
5
|
+
* 与 Monaco 官方 AMD 用法一致:只设置 MonacoEnvironment.baseUrl + importScripts(workerMain.js),
|
|
6
|
+
* workerMain 内部自带的模块加载逻辑会按 baseUrl 去 importScripts 各依赖模块。
|
|
7
|
+
* (不要在这里再 importScripts(loader.js):worker 里 loader 与 workerMain 的模块系统会冲突,
|
|
8
|
+
* 表现为 workerMain 里 “X is not a function”。)
|
|
9
|
+
*/
|
|
10
|
+
(function () {
|
|
11
|
+
var href = String(self.location.href || '')
|
|
12
|
+
var base = href.replace(/\/worker-bootstrap\.js(?:\?.*)?$/, '')
|
|
13
|
+
if (base === href || base === '') base = '/gufa-code/asset/monaco'
|
|
14
|
+
self.MonacoEnvironment = { baseUrl: base + '/' }
|
|
15
|
+
importScripts(base + '/base/worker/workerMain.js')
|
|
16
|
+
})()
|