dsh-gufa-code 1.3.9 → 1.3.48

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/host/dev.js CHANGED
@@ -2,9 +2,9 @@
2
2
  * 开发/诊断信息:供客户端在启动时探测「Host 半是否为最新代码」。
3
3
  * 旧版本 Host(没有本方法)会让 api('dev.version') 返回 not-found,客户端据此提示重启 Harness。
4
4
  */
5
- import { appendFileSync, existsSync } from 'node:fs'
5
+ import { appendFileSync, existsSync, readFileSync, writeFileSync } from 'node:fs'
6
6
  import { readFile, rm } from 'node:fs/promises'
7
- import { tmpdir } from 'node:os'
7
+ import { homedir, tmpdir } from 'node:os'
8
8
  import { execFile, spawn } from 'node:child_process'
9
9
  import { promisify } from 'node:util'
10
10
  import { dirname, join } from 'node:path'
@@ -12,6 +12,15 @@ import { fileURLToPath } from 'node:url'
12
12
  import { ApiError } from './context.js'
13
13
 
14
14
  const DEBUG_LOG_PATH = '/tmp/gufa-code-debug.log'
15
+ const FLOAT_PREFS_PATH = join(homedir(), '.dsh', 'gufa-float-prefs.json')
16
+ const PLUGIN_VERSION = (() => {
17
+ try {
18
+ const pkg = JSON.parse(readFileSync(join(PLUGIN_ROOT, 'package.json'), 'utf8'))
19
+ return typeof pkg.version === 'string' ? pkg.version : 'dev'
20
+ } catch {
21
+ return 'dev'
22
+ }
23
+ })()
15
24
  const PLUGIN_ROOT = join(dirname(fileURLToPath(import.meta.url)), '..')
16
25
  /* 悬浮层子进程放在 globalThis:host 模块热重载后仍能持有同一个句柄 */
17
26
  const floatState = globalThis.__gufaFloatState ?? (globalThis.__gufaFloatState = { child: null, startedAt: 0 })
@@ -96,14 +105,53 @@ export function register(router, env) {
96
105
 
97
106
  const killFloat = async () => {
98
107
  const pids = await listFloatPids()
99
- for (const pid of pids) {
108
+ if (pids.length === 0) {
109
+ floatState.child = null
110
+ floatState.controlPath = null
111
+ return
112
+ }
113
+ /* 优先用控制文件让 helper 优雅退出(它会先恢复 DSH 主窗口) */
114
+ if (typeof floatState.controlPath === 'string' && floatState.controlPath !== '') {
100
115
  try {
101
- process.kill(pid, 'SIGTERM')
116
+ writeFileSync(floatState.controlPath, 'exit')
102
117
  } catch {
103
118
  /* ignore */
104
119
  }
120
+ const deadline = Date.now() + 4000
121
+ while (Date.now() < deadline) {
122
+ if ((await listFloatPids()).length === 0) break
123
+ await new Promise((resolve) => setTimeout(resolve, 150))
124
+ }
125
+ }
126
+ /* 兜底:还在就 SIGTERM/SIGKILL;被强杀时用 osascript 把 DSH 主窗口恢复显示 */
127
+ let forced = false
128
+ for (const pid of await listFloatPids()) {
129
+ forced = true
130
+ try { process.kill(pid, 'SIGTERM') } catch { /* ignore */ }
131
+ }
132
+ await new Promise((resolve) => setTimeout(resolve, 400))
133
+ for (const pid of await listFloatPids()) {
134
+ forced = true
135
+ try { process.kill(pid, 'SIGKILL') } catch { /* ignore */ }
136
+ }
137
+ if (forced) {
138
+ try {
139
+ spawn('/usr/bin/osascript', ['-e', 'tell application "System Events" to set visible of process "DeepSeek Harness" to true'], { detached: true, stdio: 'ignore' }).unref()
140
+ } catch {
141
+ /* ignore */
142
+ }
143
+ try {
144
+ spawn('open', ['-b', 'com.deepseek.dsh'], { detached: true, stdio: 'ignore' }).unref()
145
+ } catch {
146
+ /* ignore */
147
+ }
148
+ }
149
+ try {
150
+ if (typeof floatState.controlPath === 'string' && floatState.controlPath !== '') await rm(floatState.controlPath, { force: true })
151
+ } catch {
152
+ /* ignore */
105
153
  }
106
- if (pids.length > 0) await new Promise((resolve) => setTimeout(resolve, 400))
154
+ floatState.controlPath = null
107
155
  floatState.child = null
108
156
  }
109
157
 
@@ -215,12 +263,25 @@ export function register(router, env) {
215
263
  const base = `${webServer.protocol}//127.0.0.1:${String(webServer.port)}`
216
264
  const authUrl = connection.authenticatedUrl(`${base}/`)
217
265
  const state = body !== null && typeof body === 'object' && body.state !== null && typeof body.state === 'object' ? body.state : null
266
+ try {
267
+ debugLog(`float-start-state project=${String(state !== null && state.projectRoot) } tabs=${state !== null && Array.isArray(state.tabs) ? state.tabs.length : 'none'} active=${state !== null && typeof state.activePath === 'string' ? state.activePath : 'none'} ui=${state !== null && state.ui !== null && typeof state.ui === 'object' ? JSON.stringify(state.ui) : 'none'} session=${state !== null && typeof state.sessionId === 'string' ? state.sessionId : 'none'}`)
268
+ } catch {
269
+ /* ignore */
270
+ }
271
+ const controlPath = join(tmpdir(), `gufa-float-exit-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`)
272
+ try { await rm(controlPath, { force: true }) } catch { /* ignore */ }
273
+ const prefs = readFloatPrefs()
274
+ const alphaPref = Number(prefs.alpha)
218
275
  const payload = JSON.stringify({
219
276
  authUrl,
220
277
  appUrl: `${base}/`,
221
278
  follow: follow !== null && follow.pid > 0 ? follow : undefined,
222
279
  state: state ?? undefined,
280
+ alpha: Number.isFinite(alphaPref) && alphaPref >= 20 && alphaPref <= 100 ? Math.round(alphaPref) : undefined,
281
+ build: PLUGIN_VERSION,
282
+ controlPath,
223
283
  })
284
+ floatState.controlPath = controlPath
224
285
  const binary = floatBinaryPath()
225
286
  if (binary === null) throw new ApiError('missing-helper', '悬浮层程序未构建', 500)
226
287
  const child = spawn(binary, [payload], { detached: true, stdio: 'ignore' })
@@ -232,11 +293,69 @@ export function register(router, env) {
232
293
  return { running: pids.length > 0 || child.exitCode === null, pid: child.pid ?? pids[0] ?? null }
233
294
  })
234
295
 
296
+ /** 悬浮层退出摸鱼:把当前状态(项目/标签页/UI/会话)暂存给主窗口。 */
297
+ router.method('float.saveExitState', async (body) => {
298
+ const state = body !== null && typeof body === 'object' && body.state !== null && typeof body.state === 'object' ? body.state : null
299
+ if (state === null) throw badRequest('state is required')
300
+ floatState.exitState = state
301
+ floatState.exitStateAt = Date.now()
302
+ return { ok: true }
303
+ })
304
+
305
+ /** 主窗口取回退出摸鱼时的状态(取一次即清空,10 分钟内有效)。 */
306
+ router.method('float.consumeExitState', async () => {
307
+ const state = floatState.exitState ?? null
308
+ const at = floatState.exitStateAt ?? 0
309
+ floatState.exitState = null
310
+ floatState.exitStateAt = 0
311
+ if (state === null || Date.now() - at > 10 * 60 * 1000) return { state: null }
312
+ return { state }
313
+ })
314
+
315
+ /* 悬浮层偏好(摸鱼界面透明度等):存在 ~/.dsh/gufa-float-prefs.json,摸鱼窗口每次新建时沿用 */
316
+ const readFloatPrefs = () => {
317
+ try {
318
+ const raw = readFileSync(FLOAT_PREFS_PATH, 'utf8')
319
+ const parsed = JSON.parse(raw)
320
+ if (parsed !== null && typeof parsed === 'object') return parsed
321
+ } catch {
322
+ /* ignore */
323
+ }
324
+ return {}
325
+ }
326
+ const writeFloatPrefs = (patch) => {
327
+ try {
328
+ const next = { ...readFloatPrefs(), ...(patch !== null && typeof patch === 'object' ? patch : {}) }
329
+ writeFileSync(FLOAT_PREFS_PATH, JSON.stringify(next))
330
+ return next
331
+ } catch {
332
+ return readFloatPrefs()
333
+ }
334
+ }
335
+ router.method('float.getPrefs', async () => {
336
+ const prefs = readFloatPrefs()
337
+ const alpha = Number(prefs.alpha)
338
+ return { alpha: Number.isFinite(alpha) && alpha >= 20 && alpha <= 100 ? Math.round(alpha) : 55 }
339
+ })
340
+ router.method('float.setPrefs', async (body) => {
341
+ const alpha = Number(body?.alpha)
342
+ if (!Number.isFinite(alpha) || alpha < 20 || alpha > 100) throw new ApiError('bad-request', 'alpha 需在 20-100 之间', 400)
343
+ writeFloatPrefs({ alpha: Math.round(alpha) })
344
+ return { ok: true }
345
+ })
346
+
235
347
  router.method('float.stop', async () => {
236
348
  await killFloat()
237
349
  return { running: false }
238
350
  })
239
351
 
352
+ /* 客户端诊断日志(曾经被误删导致所有 client:* 日志丢失) */
353
+ router.method('dev.log', async (body) => {
354
+ const message = body !== null && typeof body === 'object' && typeof body.message === 'string' ? body.message : ''
355
+ if (message !== '') debugLog(message)
356
+ return { ok: true }
357
+ })
358
+
240
359
  router.method('dev.version', async () => ({
241
360
  name: 'dsh-gufa-code',
242
361
  version: '1.0.0',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-gufa-code",
3
- "version": "1.3.9",
3
+ "version": "1.3.48",
4
4
  "description": "古法编程 · AI 辅助:一键把 DSH 主面板变成 VS Code 风格 IDE(Monaco 编辑器、文件树、Git、SSH、真实终端 + 右侧官方会话);主张亲手写、每个改动心中有数,AI 是助理、你是第一责任人",
5
5
  "icon": "icon.svg",
6
6
  "keywords": [
@@ -32,7 +32,11 @@ const footer = `
32
32
  })
33
33
  `
34
34
 
35
- const output = header + body + footer
35
+ const pkg = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'))
36
+ const version = typeof pkg.version === 'string' && pkg.version !== '' ? pkg.version : '0.0.0'
37
+ /* 版本号统一由 package.json 注入,避免 00-core 里手写的 G.BUILD 忘记更新 */
38
+ const versionedBody = body.replaceAll("G.BUILD = 'dev'", `G.BUILD = '${version}'`)
39
+ const output = header + versionedBody + footer
36
40
  writeFileSync(join(root, 'client.js'), output, 'utf8')
37
41
  console.log(`build-client: ${files.length} parts -> client.js (${(Buffer.byteLength(output) / 1024).toFixed(1)} KB)`)
38
42
  if (process.argv.includes('--list')) console.log(files.join('\n'))
@@ -7,6 +7,8 @@ const GUFA_NS = 'gufa-code'
7
7
  /** 全局命名空间:所有零件通过 G.xxx 共享能力与组件。 */
8
8
  const G = {}
9
9
  G.NS = GUFA_NS
10
+ /** 客户端构建标记(排查页面是否加载了新代码时看标题栏) */
11
+ G.BUILD = 'dev'
10
12
  G.PANEL_ID = 'gufa-code'
11
13
  /** 从哪个工作区点进来的(工作区菜单/节点按钮写入,App 启动时消费)。 */
12
14
  G.pendingEntryWorkspace = null
@@ -39,6 +41,16 @@ G.portal = (function createPortalHelper() {
39
41
  G.hooks = { useState, useEffect, useRef, useMemo, useCallback, useLayoutEffect }
40
42
 
41
43
  /* ── 悬浮层状态:helper 通过 URL 参数 ?gufa-state=<base64url(JSON)> 传主窗口快照 ── */
44
+ /** 三种界面状态:classic(无标记)/ gufa(data-gufa-ide)/ moyu(data-gufa-float)。
45
+ * 判断一律用 DOM 标记,不要用 localStorage 或状态对象,避免主窗口被摸鱼状态污染。 */
46
+ G.isFloatMode = function isFloatMode() {
47
+ try {
48
+ return typeof document !== 'undefined' && document.documentElement.hasAttribute('data-gufa-float')
49
+ } catch {
50
+ return false
51
+ }
52
+ }
53
+
42
54
  G.floatState = (function readFloatState() {
43
55
  if (typeof window === 'undefined' || typeof document === 'undefined') return null
44
56
  try {
@@ -1066,24 +1078,101 @@ G.errorText = (error) => {
1066
1078
  G.CSS = `
1067
1079
  .gufa-overlay-root{position:fixed;inset:0;z-index:1;display:flex;box-sizing:border-box;background:var(--gufa-solid-bg, var(--dsw-alias-bg-base));pointer-events:auto;overflow:hidden}
1068
1080
  .gufa-backdrop{position:absolute;inset:0;z-index:0;overflow:hidden;pointer-events:none}
1069
- /* 桌面悬浮层模式:整窗半透明(0.55),顶部留出 22px 拖动条 */
1081
+ /* 桌面悬浮层(摸鱼)模式:整窗半透明,透明度由 --gufa-float-alpha 控制(标题栏滑块) */
1082
+ html[data-gufa-float]{--gufa-float-alpha:0.55}
1070
1083
  html[data-gufa-float] body{background:transparent!important}
1071
1084
  html[data-gufa-float] .gufa-overlay-root,
1072
1085
  html[data-gufa-float] .gufa-root{
1073
- --gufa-solid-bg:rgba(13,15,19,0.55);--gufa-bg:rgba(13,15,19,0.55);
1074
- --gufa-solid-layer:rgba(20,22,27,0.55);--gufa-layer:rgba(20,22,27,0.55);
1075
- --gufa-solid-layer2:rgba(26,28,34,0.55);--gufa-layer2:rgba(26,28,34,0.55);
1076
- --gufa-solid-overlay:rgba(30,33,40,0.72);
1086
+ --gufa-solid-bg:rgba(13,15,19,var(--gufa-float-alpha))!important;--gufa-bg:rgba(13,15,19,var(--gufa-float-alpha))!important;
1087
+ --gufa-solid-layer:rgba(20,22,27,var(--gufa-float-alpha))!important;--gufa-layer:rgba(20,22,27,var(--gufa-float-alpha))!important;
1088
+ --gufa-solid-layer2:rgba(26,28,34,var(--gufa-float-alpha))!important;--gufa-layer2:rgba(26,28,34,var(--gufa-float-alpha))!important;
1089
+ --gufa-solid-overlay:rgba(30,33,40,calc(var(--gufa-float-alpha) + 0.17))!important;
1090
+ --gufa-solid-sidebar:rgba(18,20,24,var(--gufa-float-alpha))!important;
1091
+ /* 官方组件用 --dsw-alias-*:在覆盖层内也统一成同一个透明度,100% 时完全遮住底层 */
1092
+ --dsw-alias-bg-base:rgba(13,15,19,var(--gufa-float-alpha))!important;
1093
+ --dsw-alias-bg-layer-1:rgba(20,22,27,var(--gufa-float-alpha))!important;
1094
+ --dsw-alias-bg-layer-2:rgba(26,28,34,var(--gufa-float-alpha))!important;
1095
+ --dsw-alias-bg-overlay:rgba(30,33,40,calc(var(--gufa-float-alpha) + 0.17))!important;
1096
+ }
1097
+ /* 顶部 22px 拖动条区域也跟随透明度,否则 100% 时仍能透出被吸附 App(实测 1.3.27 的破绽) */
1098
+ html[data-gufa-float] .gufa-overlay-root::before{
1099
+ content:'';position:fixed;top:0;left:0;right:0;height:22px;pointer-events:none;
1100
+ background:rgba(13,15,19,var(--gufa-float-alpha));z-index:1;
1077
1101
  }
1078
1102
  html[data-gufa-float] .gufa-overlay-root{background:transparent!important;padding-top:22px;box-sizing:border-box}
1079
- html[data-gufa-float] .gufa-backdrop{opacity:0.5}
1080
- /* 悬浮模式:右侧停靠的官方会话内部也半透明(DSH 主题变量在停靠根上覆盖) */
1103
+ /* 摸鱼:整窗只保留「覆盖层根节点」这一层半透明底,其余面板/会话/终端全部透明,
1104
+ 保证编辑器、会话框、终端框看到的透明度完全一致(都等于滑块的 alpha)。 */
1105
+ html[data-gufa-float] .gufa-overlay-root{background:rgba(13,15,19,var(--gufa-float-alpha))!important}
1106
+ html[data-gufa-float] .gufa-root,
1107
+ html[data-gufa-float] .gufa-shell,
1108
+ html[data-gufa-float] .gufa-main,
1109
+ html[data-gufa-float] .gufa-main-row,
1110
+ html[data-gufa-float] .gufa-sidepanel,
1111
+ html[data-gufa-float] .gufa-editor-area,
1112
+ html[data-gufa-float] .gufa-chatpane,
1113
+ html[data-gufa-float] .gufa-termpane,
1114
+ html[data-gufa-float] .gufa-termhead,
1115
+ html[data-gufa-float] .gufa-termbody,
1116
+ html[data-gufa-float] .gufa-termview,
1117
+ html[data-gufa-float] .gufa-titlebar,
1118
+ html[data-gufa-float] .gufa-activity,
1119
+ html[data-gufa-float] .gufa-tabs,
1120
+ html[data-gufa-float] .gufa-statusbar,
1121
+ html[data-gufa-float] [data-gufa-dock],
1122
+ html[data-gufa-float] [data-gufa-dock] > *{background:transparent!important}
1123
+ /* 官方会话停靠层(toolbar/host)自带底色,摸鱼里一并透明,避免会话框叠两层 */
1124
+ html[data-gufa-float] .gufa-dock-toolbar,
1125
+ html[data-gufa-float] .gufa-dock-host,
1126
+ html[data-gufa-float] .gufa-chatdock{background:transparent!important}
1127
+ /* 官方会话/组件在摸鱼里也用透明 token,避免和覆盖层底叠成两层 */
1128
+ html[data-gufa-float] .gufa-root,
1129
+ html[data-gufa-float] .gufa-overlay-root,
1130
+ html[data-gufa-float] [data-gufa-dock]{
1131
+ --dsw-alias-bg-base:transparent!important;
1132
+ --dsw-alias-bg-layer-1:transparent!important;
1133
+ --dsw-alias-bg-layer-2:transparent!important;
1134
+ --dsw-alias-bg-overlay:transparent!important;
1135
+ }
1136
+ /* 终端面板:古法编程(带皮肤背景)时和编辑器区域一样透出背景;摸鱼时跟随滑块 */
1137
+ .gufa-termpane{background:var(--gufa-bg)}
1138
+ .gufa-termhead{background:var(--gufa-layer)}
1139
+ .gufa-termbody,
1140
+ .gufa-termview{background:transparent!important}
1141
+ .gufa-root[data-backdrop="on"] .gufa-termpane{background:color-mix(in srgb, var(--gufa-bg) 46%, transparent)}
1142
+ .gufa-root[data-backdrop="on"] .gufa-termhead{background:color-mix(in srgb, var(--gufa-layer) 64%, transparent)}
1143
+ html[data-gufa-float] .gufa-termpane{background:transparent!important}
1144
+ html[data-gufa-float] .gufa-termhead{background:transparent!important}
1145
+ /* xterm 自带的黑色底(xterm.css 默认 .xterm-viewport{background:#000})必须清掉,
1146
+ 否则古法编程和摸鱼里的终端内容区永远是黑的(外层透明也没用) */
1147
+ .gufa-termview .xterm,
1148
+ .gufa-termview .xterm .xterm-viewport,
1149
+ .gufa-termview .xterm .xterm-screen{background-color:transparent!important;background-image:none!important}
1150
+ /* 摸鱼模式不显示皮肤(梁圣)背景:包括古法自己的复刻层和第三方皮肤插件在 body/html 上画的层 */
1151
+ html[data-gufa-float],
1152
+ html[data-gufa-float] body,
1153
+ html[data-gufa-float] #root{background-image:none!important;background-color:transparent!important}
1154
+ /* 皮肤插件可能用 html::before/::after 画背景层,摸鱼里一并清掉 */
1155
+ html[data-gufa-float]::before,
1156
+ html[data-gufa-float]::after{display:none!important;content:none!important;background:none!important}
1157
+ html[data-gufa-float] .liang-skin-backdrop,
1158
+ html[data-gufa-float] .liang-ambient,
1159
+ html[data-gufa-float] .liang-skin-portrait,
1160
+ html[data-gufa-float] .liang-skin-root,
1161
+ html[data-gufa-float] #root>[class*="skin"],
1162
+ html[data-gufa-float] #root>[class*="backdrop"]{display:none!important}
1163
+ /* 摸鱼模式不显示皮肤(梁圣)背景 */
1164
+ html[data-gufa-float] .gufa-backdrop,
1165
+ html[data-gufa-float] .gufa-backdrop-page,
1166
+ html[data-gufa-float] .gufa-backdrop-glow,
1167
+ html[data-gufa-float] .gufa-backdrop-portrait{display:none!important}
1168
+ /* 悬浮模式:右侧停靠的官方会话根节点不再自己画底(整窗只有覆盖层那一层),
1169
+ 否则会和覆盖层叠成两层,会话框看起来明显更黑更实 */
1081
1170
  html[data-gufa-float] [data-gufa-dock]{
1082
- --dsw-alias-bg-base:rgba(13,15,19,0.55);
1083
- --dsw-alias-bg-layer-1:rgba(20,22,27,0.55);
1084
- --dsw-alias-bg-layer-2:rgba(26,28,34,0.55);
1085
- --dsw-alias-bg-overlay:rgba(30,33,40,0.72);
1086
- background:rgba(13,15,19,0.55)!important;
1171
+ --dsw-alias-bg-base:transparent!important;
1172
+ --dsw-alias-bg-layer-1:transparent!important;
1173
+ --dsw-alias-bg-layer-2:transparent!important;
1174
+ --dsw-alias-bg-overlay:transparent!important;
1175
+ background:transparent!important;
1087
1176
  }
1088
1177
  html[data-gufa-float] [data-gufa-dock] [data-conversation-scroll],
1089
1178
  html[data-gufa-float] [data-gufa-dock] [data-conversation-content]{background:transparent!important}
@@ -1169,7 +1258,16 @@ html[data-gufa-ide] [role="dialog"] {
1169
1258
  /* 层级契约(见 docs/KNOWN-PITFALLS.md):
1170
1259
  1 = 古法覆盖层;2147483040 = 右侧停靠会话;2147483060 = 官方 DSH 菜单/弹窗;
1171
1260
  2147483100 = 古法 portal(所有弹窗/菜单);2147483200 = toast。 */
1172
- #gufa-portal-root{position:fixed;inset:0;z-index:2147483100;pointer-events:none}
1261
+ #gufa-portal-root{position:fixed;inset:0;z-index:2147483100;pointer-events:none;
1262
+ /* portal 在 body 层,拿不到 .gufa-root 上的主题变量;这里补齐一套(固色变量由 60-dock 同步写入 inline) */
1263
+ --gufa-accent:#c0392b;--gufa-accent-soft:color-mix(in srgb, var(--gufa-accent) 16%, transparent);
1264
+ --gufa-bg:var(--gufa-solid-bg, var(--dsw-alias-bg-base, #17181c));--gufa-layer:var(--gufa-solid-layer, var(--dsw-alias-bg-layer-1, #1d1f24));
1265
+ --gufa-layer2:var(--gufa-solid-layer2, var(--dsw-alias-bg-layer-2, #23262c));
1266
+ --gufa-solid-overlay-bg:var(--gufa-solid-overlay, var(--dsw-alias-bg-overlay, #2a2d34));
1267
+ --gufa-border:var(--dsw-alias-border-l1, rgba(255,255,255,0.1));--gufa-border-strong:var(--dsw-alias-border-l2, rgba(255,255,255,0.18));
1268
+ --gufa-text:var(--gufa-solid-text, var(--dsw-alias-label-primary, #f4f1e8));--gufa-text-dim:var(--gufa-solid-text-dim, var(--dsw-alias-label-secondary, rgba(244,241,232,0.66)));
1269
+ --gufa-hover:color-mix(in srgb, var(--gufa-text) 7%, transparent);--gufa-active:color-mix(in srgb, var(--gufa-text) 11%, transparent);
1270
+ color:var(--gufa-text);font-size:13px;line-height:1.45}
1173
1271
  #gufa-portal-root>*{pointer-events:auto}
1174
1272
  /* 摸鱼模式:App 窗口选择器 */
1175
1273
  .gufa-float-backdrop{position:fixed;inset:0;z-index:2147483200;display:flex;align-items:center;justify-content:center;
@@ -1397,9 +1495,29 @@ html[data-windows-titlebar] .gufa-overlay-root{padding-top:var(--dsh-windows-tit
1397
1495
  html[data-platform=darwin] .gufa-titlebar{height:48px;padding-left:86px}
1398
1496
  html[data-platform=darwin][data-fullscreen] .gufa-titlebar{height:44px;padding-left:16px}
1399
1497
  .gufa-titlebar button,.gufa-titlebar input,.gufa-titlebar .gufa-project,.gufa-titlebar-action{-webkit-app-region:no-drag}
1498
+ /* 摸鱼入口按钮:带框的两个字 */
1499
+ .gufa-moyu-btn{display:inline-flex;align-items:center;justify-content:center;height:26px;padding:0 12px;border-radius:8px;
1500
+ border:1px solid var(--gufa-border-strong);background:color-mix(in srgb, var(--gufa-accent) 14%, transparent);
1501
+ color:var(--gufa-text);font-size:12px;font-weight:600;letter-spacing:1px;cursor:pointer;white-space:nowrap}
1502
+ .gufa-moyu-btn:hover{background:color-mix(in srgb, var(--gufa-accent) 24%, transparent);border-color:var(--gufa-accent)}
1503
+ .gufa-moyu-btn:disabled{opacity:.55;cursor:default}
1504
+ /* 退出摸鱼按钮(原「返回经典模式」位置) */
1505
+ .gufa-moyu-exit{display:inline-flex;align-items:center;justify-content:center;height:28px;padding:0 14px;border-radius:8px;
1506
+ border:1px solid color-mix(in srgb, var(--gufa-accent) 60%, transparent);
1507
+ background:color-mix(in srgb, var(--gufa-accent) 20%, transparent);color:var(--gufa-text);
1508
+ font-size:12px;font-weight:600;cursor:pointer;white-space:nowrap}
1509
+ .gufa-moyu-exit:hover{background:color-mix(in srgb, var(--gufa-accent) 34%, transparent)}
1510
+ .gufa-moyu-exit:disabled{opacity:.55;cursor:default}
1511
+ /* 摸鱼界面透明度滑块 */
1512
+ .gufa-moyu-alpha{display:inline-flex;align-items:center;gap:8px;height:26px;padding:0 10px;border-radius:8px;
1513
+ border:1px solid var(--gufa-border);background:color-mix(in srgb, var(--gufa-layer2) 70%, transparent);font-size:11.5px;color:var(--gufa-text-dim)}
1514
+ .gufa-moyu-alpha-label{white-space:nowrap}
1515
+ .gufa-moyu-alpha-range{width:120px;accent-color:var(--gufa-accent);cursor:pointer}
1516
+ .gufa-moyu-alpha-value{min-width:34px;text-align:right;font-variant-numeric:tabular-nums}
1400
1517
  .gufa-brand{display:flex;align-items:center;gap:8px;min-width:0}
1401
1518
  .gufa-brand-logo{width:24px;height:24px;flex:0 0 auto}
1402
1519
  .gufa-brand-name{font-weight:650;font-size:14px;letter-spacing:.02em;white-space:nowrap}
1520
+ .gufa-build-tag{font-size:9.5px;color:var(--gufa-text-dim);opacity:.6;letter-spacing:.3px;flex:0 0 auto}
1403
1521
  .gufa-brand-sub{font-size:10px;letter-spacing:.18em;color:var(--gufa-text-dim);white-space:nowrap}
1404
1522
  .gufa-project{appearance:none;border:0;background:transparent;font:inherit;color:inherit;cursor:pointer}
1405
1523
  .gufa-project:hover{background:var(--gufa-hover)}
@@ -259,6 +259,17 @@ function gufaTermPalette(props) {
259
259
  * @param {string} mode 'dark' | 'light'
260
260
  * @param {object|null} palette 插件合成的实色调色板(优先于 mode)
261
261
  */
262
+ function gufaTermFloatMode() {
263
+ try {
264
+ return typeof G.isFloatMode === 'function' && G.isFloatMode() === true
265
+ } catch {
266
+ return false
267
+ }
268
+ }
269
+
270
+ /** 摸鱼窗口里终端容器的半透明底色(跟随标题栏透明度滑块) */
271
+ const GUFA_TERM_FLOAT_BG = 'rgba(30,30,30,var(--gufa-float-alpha))'
272
+
262
273
  function gufaTermTheme(mode, palette) {
263
274
  const dark = palette !== null && palette !== undefined && typeof palette.isDark === 'boolean' ? palette.isDark : mode === 'dark'
264
275
  if (dark) {
@@ -285,7 +296,11 @@ function gufaTermTheme(mode, palette) {
285
296
  brightCyan: '#29b8db',
286
297
  brightWhite: '#e5e5e5',
287
298
  }
288
- return gufaApplyPaletteToTermTheme(darkTheme, palette)
299
+ const themed = gufaApplyPaletteToTermTheme(darkTheme, palette)
300
+ /* xterm 自身永远画透明底:背景色由外层容器用 IDE 调色板/透明度变量统一上色 */
301
+ themed.background = 'rgba(0,0,0,0)'
302
+ themed.cursorAccent = 'rgba(0,0,0,0)'
303
+ return themed
289
304
  }
290
305
  const light = {
291
306
  background: '#ffffff',
@@ -310,7 +325,10 @@ function gufaTermTheme(mode, palette) {
310
325
  brightCyan: '#0598bc',
311
326
  brightWhite: '#a5a5a5',
312
327
  }
313
- return gufaApplyPaletteToTermTheme(light, palette)
328
+ const themed = gufaApplyPaletteToTermTheme(light, palette)
329
+ themed.background = 'rgba(0,0,0,0)'
330
+ themed.cursorAccent = 'rgba(0,0,0,0)'
331
+ return themed
314
332
  }
315
333
 
316
334
  /** 把皮肤实色调色板叠加到 xterm 主题(背景/前景/光标/选区跟随滑动变祖)。 */
@@ -788,6 +806,7 @@ function GufaTerminalView(props) {
788
806
  try {
789
807
  const terminal = new props.assets.Terminal({
790
808
  allowProposedApi: false,
809
+ allowTransparency: true,
791
810
  convertEol: false,
792
811
  cursorBlink: true,
793
812
  cursorStyle: 'bar',
@@ -1029,7 +1048,9 @@ function GufaTerminalView(props) {
1029
1048
 
1030
1049
  const monoFont = 'ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace'
1031
1050
  const fallbackTheme = gufaTermTheme(props.theme, palette)
1032
- const background = fallbackTheme.background
1051
+ /* 终端背景由外层 .gufa-termpane 统一提供(和编辑器区域同一套透明度规则) */
1052
+ const shellBackground = 'transparent'
1053
+ const background = 'transparent'
1033
1054
  const foreground = fallbackTheme.foreground
1034
1055
 
1035
1056
  const body = fallback
@@ -1101,6 +1122,7 @@ function GufaTerminalView(props) {
1101
1122
  return h(
1102
1123
  'div',
1103
1124
  {
1125
+ className: 'gufa-termview',
1104
1126
  style: {
1105
1127
  display: props.active === true ? 'flex' : 'none',
1106
1128
  flexDirection: 'column',
@@ -1108,7 +1130,6 @@ function GufaTerminalView(props) {
1108
1130
  minHeight: 0,
1109
1131
  minWidth: 0,
1110
1132
  position: 'relative',
1111
- background,
1112
1133
  },
1113
1134
  },
1114
1135
  body,
@@ -1160,6 +1181,9 @@ G.TerminalPane = function TerminalPane(props) {
1160
1181
  const theme = props.theme === 'light' ? 'light' : 'dark'
1161
1182
  const visible = props.visible !== false
1162
1183
  const [assets, setAssets] = useState({ status: 'loading', Terminal: null, FitAddon: null, error: '' })
1184
+ /* 未显式传 palette 时(例如古法编程主模式),从 IDE 主题 token 算一份实色调色板,
1185
+ 让 xterm 的文字/选区颜色与周围面板一致,而不是永远用浅色主题 */
1186
+ const [computedPalette, setComputedPalette] = useState(null)
1163
1187
  const [sessions, setSessions] = useState([])
1164
1188
  const [activeId, setActiveId] = useState(null)
1165
1189
  const [error, setError] = useState('')
@@ -1179,6 +1203,25 @@ G.TerminalPane = function TerminalPane(props) {
1179
1203
  useEffect(() => {
1180
1204
  sessionsRef.current = sessions
1181
1205
  }, [sessions])
1206
+ useEffect(() => {
1207
+ if (props.palette !== null && props.palette !== undefined) return undefined
1208
+ let cancelled = false
1209
+ const compute = () => {
1210
+ try {
1211
+ const el = sizeRef.current
1212
+ const value = typeof G.resolveSolidPalette === 'function' ? G.resolveSolidPalette(el) : null
1213
+ if (!cancelled && value !== null && value !== undefined) setComputedPalette(value)
1214
+ } catch {
1215
+ /* ignore */
1216
+ }
1217
+ }
1218
+ compute()
1219
+ const timer = window.setTimeout(compute, 400)
1220
+ return () => {
1221
+ cancelled = true
1222
+ window.clearTimeout(timer)
1223
+ }
1224
+ }, [props.palette])
1182
1225
  useEffect(() => {
1183
1226
  activeRef.current = activeId
1184
1227
  }, [activeId])
@@ -1427,7 +1470,7 @@ G.TerminalPane = function TerminalPane(props) {
1427
1470
  active: session.id === activeId,
1428
1471
  visible,
1429
1472
  theme,
1430
- palette: props.palette,
1473
+ palette: props.palette !== null && props.palette !== undefined ? props.palette : computedPalette,
1431
1474
  assets,
1432
1475
  register: registerChannel,
1433
1476
  unregister: unregisterChannel,
@@ -1444,6 +1487,7 @@ G.TerminalPane = function TerminalPane(props) {
1444
1487
  return h(
1445
1488
  'div',
1446
1489
  {
1490
+ className: 'gufa-termpane',
1447
1491
  style: {
1448
1492
  height,
1449
1493
  flex: '0 0 auto',
@@ -1452,12 +1496,12 @@ G.TerminalPane = function TerminalPane(props) {
1452
1496
  minHeight: 0,
1453
1497
  minWidth: 0,
1454
1498
  borderTop: '1px solid var(--gufa-border)',
1455
- background: 'var(--gufa-bg)',
1456
1499
  },
1457
1500
  },
1458
1501
  h(
1459
1502
  'div',
1460
1503
  {
1504
+ className: 'gufa-termhead',
1461
1505
  style: {
1462
1506
  display: 'flex',
1463
1507
  alignItems: 'center',
@@ -1466,7 +1510,6 @@ G.TerminalPane = function TerminalPane(props) {
1466
1510
  padding: '0 6px 0 8px',
1467
1511
  flex: '0 0 auto',
1468
1512
  borderBottom: '1px solid var(--gufa-border)',
1469
- background: 'var(--gufa-layer)',
1470
1513
  minWidth: 0,
1471
1514
  },
1472
1515
  },
@@ -1503,7 +1546,7 @@ G.TerminalPane = function TerminalPane(props) {
1503
1546
  : null,
1504
1547
  h(
1505
1548
  'div',
1506
- { ref: sizeRef, style: { position: 'relative', flex: '1 1 auto', display: 'flex', flexDirection: 'column', minHeight: 0, minWidth: 0, background: theme === 'dark' ? '#1e1e1e' : '#ffffff' } },
1549
+ { ref: sizeRef, className: 'gufa-termbody', style: { position: 'relative', flex: '1 1 auto', display: 'flex', flexDirection: 'column', minHeight: 0, minWidth: 0 } },
1507
1550
  body,
1508
1551
  ),
1509
1552
  )
@@ -328,7 +328,10 @@ G.BackdropParticles = function BackdropParticles(props) {
328
328
  const canvasRef = useRef(null)
329
329
  const strengthRaw = typeof props.strength === 'number' && Number.isFinite(props.strength) ? props.strength : 1
330
330
  const strength = Math.max(0, Math.min(1, strengthRaw))
331
+ /* 摸鱼窗口里背景层是被 CSS 隐藏的:完全不要创建 canvas / 跑动画,省 CPU 与内存 */
332
+ const skipFloat = typeof G.isFloatMode === 'function' && G.isFloatMode() === true
331
333
  useEffect(() => {
334
+ if (skipFloat) return undefined
332
335
  const canvas = canvasRef.current
333
336
  if (canvas === null || canvas === undefined) return undefined
334
337
  const context = canvas.getContext('2d')
@@ -341,7 +344,7 @@ G.BackdropParticles = function BackdropParticles(props) {
341
344
  }
342
345
  if (reduced) return undefined
343
346
 
344
- const dpr = Math.min(1.5, window.devicePixelRatio || 1)
347
+ const dpr = Math.min(1.25, window.devicePixelRatio || 1)
345
348
  let width = 0
346
349
  let height = 0
347
350
  const resize = () => {
@@ -397,9 +400,11 @@ G.BackdropParticles = function BackdropParticles(props) {
397
400
  const pointer = { x: -1e4, y: -1e4, down: false }
398
401
  let last = 0
399
402
  let raf = 0
403
+ let paused = document.visibilityState === 'hidden'
400
404
  const tick = (now) => {
405
+ if (paused) { raf = 0; return }
401
406
  raf = window.requestAnimationFrame(tick)
402
- if (now - last < 33) return
407
+ if (now - last < 40) return
403
408
  const dt = Math.min(0.048, (last === 0 ? 0.016 : (now - last) / 1000))
404
409
  last = now
405
410
  context.clearRect(0, 0, width, height)
@@ -456,13 +461,28 @@ G.BackdropParticles = function BackdropParticles(props) {
456
461
  }
457
462
  const onPointerDown = () => { pointer.down = true }
458
463
  const onPointerUp = () => { pointer.down = false }
464
+ const resume = () => {
465
+ paused = false
466
+ last = 0
467
+ if (raf === 0) raf = window.requestAnimationFrame(tick)
468
+ }
469
+ const pause = () => {
470
+ paused = true
471
+ if (raf !== 0) { window.cancelAnimationFrame(raf); raf = 0 }
472
+ }
473
+ const onVisibility = () => { if (document.visibilityState === 'hidden') pause(); else resume() }
474
+ const onBlur = () => pause()
475
+ const onFocus = () => resume()
476
+ document.addEventListener('visibilitychange', onVisibility)
477
+ window.addEventListener('blur', onBlur)
478
+ window.addEventListener('focus', onFocus)
459
479
  window.addEventListener('pointermove', onPointerMove)
460
480
  window.addEventListener('pointerdown', onPointerDown)
461
481
  window.addEventListener('pointerup', onPointerUp)
462
482
  window.addEventListener('pointerleave', onPointerLeave)
463
483
  window.addEventListener('resize', resize)
464
484
  resize()
465
- raf = window.requestAnimationFrame(tick)
485
+ if (!paused) raf = window.requestAnimationFrame(tick)
466
486
  try {
467
487
  void G.api('dev.log', { message: `particles-start count=${activeCount} size=2-5.2css dpr=${dpr} canvas=${width}x${height}` }).catch(() => {})
468
488
  } catch {
@@ -470,13 +490,17 @@ G.BackdropParticles = function BackdropParticles(props) {
470
490
  }
471
491
  return () => {
472
492
  if (raf !== 0) window.cancelAnimationFrame(raf)
493
+ document.removeEventListener('visibilitychange', onVisibility)
494
+ window.removeEventListener('blur', onBlur)
495
+ window.removeEventListener('focus', onFocus)
473
496
  window.removeEventListener('pointermove', onPointerMove)
474
497
  window.removeEventListener('pointerdown', onPointerDown)
475
498
  window.removeEventListener('pointerup', onPointerUp)
476
499
  window.removeEventListener('pointerleave', onPointerLeave)
477
500
  window.removeEventListener('resize', resize)
478
501
  }
479
- }, [strength])
502
+ }, [strength, skipFloat])
503
+ if (skipFloat) return null
480
504
  return h('canvas', { ref: canvasRef, className: 'gufa-backdrop-particles', 'aria-hidden': 'true', style: { mixBlendMode: 'screen' } })
481
505
  }
482
506
 
@@ -580,6 +580,21 @@ G.OverlayHost = function OverlayHost(props) {
580
580
  root.style.setProperty('--gufa-solid-sidebar', palette.sidebar)
581
581
  root.style.setProperty('--gufa-solid-text', palette.text)
582
582
  root.style.setProperty('--gufa-solid-text-dim', palette.textDim)
583
+ /* 弹窗 portal 挂在 body 上,拿不到 root 上的 inline 变量,这里同步一份 */
584
+ try {
585
+ const portalHost = document.getElementById('gufa-portal-root')
586
+ if (portalHost !== null) {
587
+ portalHost.style.setProperty('--gufa-solid-bg', palette.bg)
588
+ portalHost.style.setProperty('--gufa-solid-layer', palette.layer)
589
+ portalHost.style.setProperty('--gufa-solid-layer2', palette.layer2)
590
+ portalHost.style.setProperty('--gufa-solid-overlay', palette.overlay)
591
+ portalHost.style.setProperty('--gufa-solid-sidebar', palette.sidebar)
592
+ portalHost.style.setProperty('--gufa-solid-text', palette.text)
593
+ portalHost.style.setProperty('--gufa-solid-text-dim', palette.textDim)
594
+ }
595
+ } catch {
596
+ /* ignore */
597
+ }
583
598
  if (typeof G.applyPopupTheme === 'function') G.applyPopupTheme(palette)
584
599
  try {
585
600
  if (window.__gufaApplyLogs === undefined) window.__gufaApplyLogs = 10