dsh-gufa-code 1.3.49 → 1.3.51

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.
Files changed (34) hide show
  1. package/README.md +14 -4
  2. package/client.js +59 -1
  3. package/desktop/float/GufaFloat.m +12 -0
  4. package/desktop/float/PLATFORM-PROTOCOL.md +120 -0
  5. package/desktop/float/bin/README.md +12 -0
  6. package/desktop/float/bin/gufa-float-macos-arm64 +0 -0
  7. package/desktop/float/bin/gufa-float-macos-universal +0 -0
  8. package/desktop/float/bin/gufa-float-macos-x64 +0 -0
  9. package/desktop/float/bin/linux-x64/gufa-float-linux +0 -0
  10. package/desktop/float/bin/win-x64/gufa-float-win.exe +0 -0
  11. package/desktop/float/linux/Makefile +85 -0
  12. package/desktop/float/linux/README-LINUX.md +219 -0
  13. package/desktop/float/linux/json.c +498 -0
  14. package/desktop/float/linux/json.h +56 -0
  15. package/desktop/float/linux/log.c +48 -0
  16. package/desktop/float/linux/log.h +19 -0
  17. package/desktop/float/linux/main.c +1271 -0
  18. package/desktop/float/linux/x11.c +608 -0
  19. package/desktop/float/linux/x11.h +118 -0
  20. package/desktop/float/win/CMakeLists.txt +159 -0
  21. package/desktop/float/win/README-WIN.md +184 -0
  22. package/desktop/float/win/json.h +505 -0
  23. package/desktop/float/win/main.cpp +2246 -0
  24. package/desktop/float//345/217/244/346/263/225/347/274/226/347/250/213/346/202/254/346/265/256/345/261/202.app/Contents/Info.plist +2 -2
  25. package/desktop/float//345/217/244/346/263/225/347/274/226/347/250/213/346/202/254/346/265/256/345/261/202.app/Contents/MacOS/gufa-float +0 -0
  26. package/docs/FLOAT-ACCEPTANCE.md +85 -0
  27. package/docs/MODES.md +7 -0
  28. package/host/dev.js +384 -57
  29. package/package.json +1 -1
  30. package/scripts/build-float-linux.sh +15 -0
  31. package/scripts/build-float-macos.sh +1 -0
  32. package/scripts/build-float-win.ps1 +33 -0
  33. package/src/client/00-core.js +3 -0
  34. package/src/client/90-app.js +55 -0
package/host/dev.js CHANGED
@@ -4,13 +4,14 @@
4
4
  */
5
5
  import { appendFileSync, existsSync, readFileSync, writeFileSync } from 'node:fs'
6
6
  import { readFile, rm } from 'node:fs/promises'
7
- import { homedir, tmpdir } from 'node:os'
7
+ import { homedir, release, 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'
11
11
  import { fileURLToPath } from 'node:url'
12
12
  import { ApiError } from './context.js'
13
13
 
14
+ const PLUGIN_ROOT = join(dirname(fileURLToPath(import.meta.url)), '..')
14
15
  const DEBUG_LOG_PATH = '/tmp/gufa-code-debug.log'
15
16
  const FLOAT_PREFS_PATH = join(homedir(), '.dsh', 'gufa-float-prefs.json')
16
17
  const PLUGIN_VERSION = (() => {
@@ -21,22 +22,62 @@ const PLUGIN_VERSION = (() => {
21
22
  return 'dev'
22
23
  }
23
24
  })()
24
- const PLUGIN_ROOT = join(dirname(fileURLToPath(import.meta.url)), '..')
25
25
  /* 悬浮层子进程放在 globalThis:host 模块热重载后仍能持有同一个句柄 */
26
26
  const floatState = globalThis.__gufaFloatState ?? (globalThis.__gufaFloatState = { child: null, startedAt: 0 })
27
27
  const runFile = promisify(execFile)
28
28
 
29
- /** 查找当前平台编译好的悬浮层 helper(P0 只支持 macOS)。 */
29
+ /** 查找当前平台编译好的悬浮层 helper。 */
30
30
  function floatBinaryPath() {
31
- const arch = process.arch === 'arm64' ? 'arm64' : 'x64'
32
- const candidates = [`gufa-float-macos-${arch}`, 'gufa-float-macos-universal', 'gufa-float-macos-arm64', 'gufa-float-macos-x64']
33
- for (const name of candidates) {
34
- const full = join(PLUGIN_ROOT, 'desktop', 'float', 'bin', name)
31
+ const root = join(PLUGIN_ROOT, 'desktop', 'float', 'bin')
32
+ let candidates = []
33
+ if (process.platform === 'darwin') {
34
+ const arch = process.arch === 'arm64' ? 'arm64' : 'x64'
35
+ candidates = [
36
+ join(root, `gufa-float-macos-${arch}`),
37
+ join(root, 'gufa-float-macos-universal'),
38
+ join(root, 'gufa-float-macos-arm64'),
39
+ join(root, 'gufa-float-macos-x64'),
40
+ ]
41
+ } else if (process.platform === 'win32') {
42
+ candidates = [
43
+ join(root, 'win-x64', 'gufa-float-win.exe'),
44
+ join(root, 'gufa-float-win.exe'),
45
+ ]
46
+ } else if (process.platform === 'linux') {
47
+ candidates = [
48
+ join(root, 'linux-x64', 'gufa-float-linux'),
49
+ join(root, 'linux-x64', 'gufa-float-linux-x64'),
50
+ join(root, 'gufa-float-linux'),
51
+ ]
52
+ }
53
+ for (const full of candidates) {
35
54
  if (existsSync(full)) return full
36
55
  }
37
56
  return null
38
57
  }
39
58
 
59
+ /** 当前平台是否支持摸鱼悬浮层(helper 未构建时返回原因)。 */
60
+ function floatSupportStatus() {
61
+ const binary = floatBinaryPath()
62
+ if (process.platform !== 'darwin' && process.platform !== 'win32' && process.platform !== 'linux') {
63
+ return { supported: false, reason: 'unsupported-platform', platform: process.platform, binary: null }
64
+ }
65
+ if (binary === null) {
66
+ return {
67
+ supported: false,
68
+ reason: 'missing-helper',
69
+ platform: process.platform,
70
+ binary: null,
71
+ hint: process.platform === 'darwin'
72
+ ? '运行 ./scripts/build-float-macos.sh 构建悬浮层'
73
+ : (process.platform === 'win32'
74
+ ? '按 desktop/float/win/README-WIN.md 用 CMake + WebView2 SDK 构建(CI windows job 会产出 gufa-float-win.exe)'
75
+ : '运行 ./scripts/build-float-linux.sh(或 CI 的 linux job 构建产物)'),
76
+ }
77
+ }
78
+ return { supported: true, reason: '', platform: process.platform, binary }
79
+ }
80
+
40
81
  function floatRunning() {
41
82
  return floatState.child !== null && floatState.child.exitCode === null && floatState.child.signalCode === null
42
83
  }
@@ -56,11 +97,17 @@ export function register(router, env) {
56
97
 
57
98
 
58
99
 
59
- /* ── 桌面悬浮层 / 摸鱼模式(macOS) ────────────────────────────────
60
- * 通过 .app bundle 启动 helper:TCC(屏幕录制)按 bundle 身份授权,
61
- * 用户在「系统设置 → 隐私与安全性 → 屏幕录制」里添加「古法编程悬浮层.app」即可。
100
+ /* ── 桌面悬浮层 / 摸鱼模式(跨平台:macOS / Windows / Linux) ─────────
101
+ * helper 协议见 desktop/float/PLATFORM-PROTOCOL.md:
102
+ * - Host 用 spawn(binary, [payloadJson]) 启动 helper;
103
+ * - 退出统一走 controlPath 控制文件(helper 自己恢复 DSH 主窗口后退出);
104
+ * - float.windows 统一返回 { ok, accessibility, apps:[{pid,owner,title,bundleId,windowNumber,icon}] }。
62
105
  */
106
+ const isMac = process.platform === 'darwin'
107
+ const isWin = process.platform === 'win32'
108
+ const isLinux = process.platform === 'linux'
63
109
  const appBundlePath = () => {
110
+ if (!isMac) return null
64
111
  const candidates = [
65
112
  join(PLUGIN_ROOT, 'desktop', 'float', '古法编程悬浮层.app'),
66
113
  join(PLUGIN_ROOT, 'desktop', 'float', 'GufaFloat.app'),
@@ -70,38 +117,77 @@ export function register(router, env) {
70
117
  }
71
118
  return null
72
119
  }
73
- const floatProcessPatterns = ['gufa-float-macos-', '古法编程悬浮层.app/Contents/MacOS/gufa-float']
120
+ const floatProcessPatterns = isMac
121
+ ? ['gufa-float-macos-', '古法编程悬浮层.app/Contents/MacOS/gufa-float']
122
+ : (isWin ? ['gufa-float-win'] : ['gufa-float-linux'])
74
123
 
124
+ /** 列出本插件的 helper 进程(优先用自己 spawn 的 child,再加系统进程扫描兜底)。 */
75
125
  const listFloatPids = async () => {
76
126
  const pids = new Set()
77
- for (const pattern of floatProcessPatterns) {
127
+ const tracked = floatState.child !== null && floatState.child.exitCode === null ? floatState.child.pid : null
128
+ if (Number.isFinite(tracked) && tracked > 0) pids.add(tracked)
129
+ if (isMac || isLinux) {
130
+ for (const pattern of floatProcessPatterns) {
131
+ try {
132
+ const { stdout } = await runFile('pgrep', ['-f', pattern], { timeout: 3000 })
133
+ for (const line of String(stdout ?? '').split('\n')) {
134
+ const pid = Number(line.trim())
135
+ if (Number.isFinite(pid) && pid > 0) pids.add(pid)
136
+ }
137
+ } catch {
138
+ /* 没匹配到 */
139
+ }
140
+ }
141
+ } else if (isWin) {
142
+ const alive = []
143
+ for (const pid of pids) {
144
+ try { process.kill(pid, 0); alive.push(pid) } catch { /* 已退出 */ }
145
+ }
146
+ pids.clear()
147
+ for (const pid of alive) pids.add(pid)
78
148
  try {
79
- const { stdout } = await runFile('pgrep', ['-f', pattern], { timeout: 3000 })
149
+ const { stdout } = await runFile('tasklist', ['/FI', 'IMAGENAME eq gufa-float-win.exe', '/FO', 'CSV', '/NH'], { timeout: 5000 })
80
150
  for (const line of String(stdout ?? '').split('\n')) {
81
- const pid = Number(line.trim())
82
- if (Number.isFinite(pid) && pid > 0) pids.add(pid)
151
+ const match = /^"([^"]+)","(\d+)"/.exec(line.trim())
152
+ if (match !== null) {
153
+ const pid = Number(match[2])
154
+ if (Number.isFinite(pid) && pid > 0) pids.add(pid)
155
+ }
83
156
  }
84
157
  } catch {
85
- /* 没匹配到 */
158
+ /* tasklist 不可用:只用 child pid */
86
159
  }
87
160
  }
88
161
  return [...pids]
89
162
  }
90
163
  const floatRunningAsync = async () => (await listFloatPids()).length > 0
91
164
 
92
- const openApp = (args) => new Promise((resolve, reject) => {
93
- const app = appBundlePath()
94
- if (app === null) {
95
- reject(new ApiError('missing-helper', '悬浮层 App 未构建,请先运行 scripts/build-float-macos.sh', 500))
96
- return
165
+ /** 强制退出/异常兜底:把 DSH 主窗口恢复显示并前置(正常情况下 helper 自己会恢复)。 */
166
+ const restoreDshWindowFallback = async () => {
167
+ try {
168
+ if (isMac) {
169
+ spawn('/usr/bin/osascript', ['-e', 'tell application "System Events" to set visible of process "DeepSeek Harness" to true'], { detached: true, stdio: 'ignore' }).unref()
170
+ spawn('open', ['-b', 'com.deepseek.dsh'], { detached: true, stdio: 'ignore' }).unref()
171
+ } else if (isWin) {
172
+ const ps = [
173
+ "$sig = '[DllImport(\"user32.dll\")] public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); [DllImport(\"user32.dll\")] public static extern bool SetForegroundWindow(IntPtr hWnd);'",
174
+ '$t = Add-Type -MemberDefinition $sig -Name Win32F -Namespace GufaF -PassThru',
175
+ "Get-Process -ErrorAction SilentlyContinue | Where-Object { $_.MainWindowHandle -ne 0 -and $_.ProcessName -like '*DeepSeek*' } | ForEach-Object { [void]$t::ShowWindow($_.MainWindowHandle, 5); [void]$t::SetForegroundWindow($_.MainWindowHandle) }",
176
+ ].join('\n')
177
+ spawn('powershell', ['-NoProfile', '-NonInteractive', '-Command', ps], { detached: true, stdio: 'ignore' }).unref()
178
+ } else if (isLinux) {
179
+ for (const [command, args] of [['wmctrl', ['-a', 'DeepSeek Harness']], ['xdotool', ['search', '--name', 'DeepSeek Harness', 'windowactivate']]]) {
180
+ try {
181
+ spawn(command, args, { detached: true, stdio: 'ignore' }).unref()
182
+ } catch {
183
+ /* ignore */
184
+ }
185
+ }
186
+ }
187
+ } catch {
188
+ /* ignore */
97
189
  }
98
- const child = spawn('open', ['-n', app, '--args', ...args], { detached: true, stdio: 'ignore' })
99
- child.once('error', reject)
100
- child.once('exit', (code) => {
101
- if (code === 0) resolve()
102
- else reject(new ApiError('open-failed', `悬浮层启动失败(open exit ${code})`, 500))
103
- })
104
- })
190
+ }
105
191
 
106
192
  const killFloat = async () => {
107
193
  const pids = await listFloatPids()
@@ -117,35 +203,40 @@ export function register(router, env) {
117
203
  } catch {
118
204
  /* ignore */
119
205
  }
120
- const deadline = Date.now() + 4000
206
+ const deadline = Date.now() + 6000
121
207
  while (Date.now() < deadline) {
122
208
  if ((await listFloatPids()).length === 0) break
123
209
  await new Promise((resolve) => setTimeout(resolve, 150))
124
210
  }
125
211
  }
126
- /* 兜底:还在就 SIGTERM/SIGKILL;被强杀时用 osascript 把 DSH 主窗口恢复显示 */
212
+ /* 兜底:还在就强杀;被强杀时用平台命令把 DSH 主窗口恢复显示 */
127
213
  let forced = false
128
214
  for (const pid of await listFloatPids()) {
129
215
  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
216
  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()
217
+ if (isWin) {
218
+ spawn('taskkill', ['/PID', String(pid), '/T', '/F'], { detached: true, stdio: 'ignore' }).unref()
219
+ } else {
220
+ process.kill(pid, 'SIGTERM')
221
+ }
140
222
  } catch {
141
223
  /* ignore */
142
224
  }
225
+ }
226
+ await new Promise((resolve) => setTimeout(resolve, 500))
227
+ for (const pid of await listFloatPids()) {
228
+ forced = true
143
229
  try {
144
- spawn('open', ['-b', 'com.deepseek.dsh'], { detached: true, stdio: 'ignore' }).unref()
230
+ if (isWin) {
231
+ spawn('taskkill', ['/PID', String(pid), '/T', '/F'], { detached: true, stdio: 'ignore' }).unref()
232
+ } else {
233
+ process.kill(pid, 'SIGKILL')
234
+ }
145
235
  } catch {
146
236
  /* ignore */
147
237
  }
148
238
  }
239
+ if (forced) await restoreDshWindowFallback()
149
240
  try {
150
241
  if (typeof floatState.controlPath === 'string' && floatState.controlPath !== '') await rm(floatState.controlPath, { force: true })
151
242
  } catch {
@@ -155,32 +246,137 @@ export function register(router, env) {
155
246
  floatState.child = null
156
247
  }
157
248
 
249
+ /** macOS:用 .app 身份启动 helper(列表接口的兜底路线,能继承/单独授权辅助功能)。 */
250
+ const openApp = (args) => new Promise((resolve, reject) => {
251
+ const app = appBundlePath()
252
+ if (app === null) {
253
+ reject(new ApiError('missing-helper', '悬浮层 App 未构建,请先运行 scripts/build-float-macos.sh', 500))
254
+ return
255
+ }
256
+ const child = spawn('open', ['-n', app, '--args', ...args], { detached: true, stdio: 'ignore' })
257
+ child.once('error', reject)
258
+ child.once('exit', (code) => {
259
+ if (code === 0) resolve()
260
+ else reject(new ApiError('open-failed', `悬浮层启动失败(open exit ${code})`, 500))
261
+ })
262
+ })
263
+
264
+ /** Windows:PowerShell 枚举有主窗口的进程。 */
265
+ const listFloatWindowsWin = async () => {
266
+ const script = [
267
+ '$rows = @();',
268
+ "Get-Process -ErrorAction SilentlyContinue | Where-Object { $_.MainWindowHandle -ne 0 -and $_.MainWindowTitle -ne '' } | ForEach-Object { $rows += [pscustomobject]@{ pid = $_.Id; owner = $_.ProcessName; title = $_.MainWindowTitle; bundleId = ''; windowNumber = [int64]$_.MainWindowHandle; frontmost = 0 } };",
269
+ "ConvertTo-Json -InputObject ([pscustomobject]@{ ok = $true; accessibility = $true; apps = @($rows) }) -Compress -Depth 5",
270
+ ].join('\n')
271
+ const { stdout } = await runFile('powershell', ['-NoProfile', '-NonInteractive', '-Command', script], { timeout: 20_000, maxBuffer: 8 * 1024 * 1024 })
272
+ let parsed = null
273
+ try { parsed = JSON.parse(String(stdout ?? '').trim()) } catch { parsed = null }
274
+ if (parsed === null || parsed.ok !== true) throw new ApiError('list-failed', '读取 Windows 窗口列表失败', 500)
275
+ let apps = parsed.apps
276
+ if (!Array.isArray(apps)) apps = apps === null || apps === undefined ? [] : [apps]
277
+ const helperPids = new Set(await listFloatPids())
278
+ apps = apps.filter((row) => row !== null && typeof row === 'object' && Number(row.pid) > 0 && typeof row.title === 'string' && row.title !== '' && !helperPids.has(Number(row.pid)))
279
+ apps = apps.map((row) => ({ ...row, name: typeof row.name === 'string' && row.name !== '' ? row.name : row.owner }))
280
+ return { ok: true, accessibility: true, apps }
281
+ }
282
+
283
+ /** Linux(X11):优先用 helper 自己的 --list-windows(X11 直读,无需 wmctrl),失败再退回 wmctrl。 */
284
+ const listFloatWindowsLinux = async () => {
285
+ const support = floatSupportStatus()
286
+ if (support.supported && typeof support.binary === 'string') {
287
+ const outPath = join(tmpdir(), `gufa-float-win-list-${process.pid}-${Date.now()}.json`)
288
+ try {
289
+ await runFile(support.binary, ['--list-windows', '--out', outPath], { timeout: 12_000 })
290
+ const raw = await readFile(outPath, 'utf8')
291
+ const parsed = JSON.parse(raw.trim())
292
+ if (parsed !== null && parsed.ok === true && Array.isArray(parsed.apps)) {
293
+ await rm(outPath, { force: true }).catch(() => {})
294
+ return { ok: true, accessibility: true, apps: parsed.apps }
295
+ }
296
+ } catch {
297
+ /* helper 不支持/失败:退回 wmctrl */
298
+ }
299
+ try { await rm(outPath, { force: true }) } catch { /* ignore */ }
300
+ }
301
+ let stdout = ''
302
+ try {
303
+ ({ stdout } = await runFile('wmctrl', ['-lp'], { timeout: 6000 }))
304
+ } catch {
305
+ throw new ApiError('missing-tool', 'Linux 下列出窗口失败:请重新构建 helper,或安装 wmctrl(sudo apt install wmctrl)', 500)
306
+ }
307
+ const apps = []
308
+ const seen = new Set()
309
+ for (const line of String(stdout ?? '').split('\n')) {
310
+ const match = /^0x[0-9a-fA-F]+\s+\d+\s+(\d+)\s+(.*)$/.exec(line.trim())
311
+ if (match === null) continue
312
+ const pid = Number(match[1])
313
+ const title = match[2].trim()
314
+ if (!Number.isFinite(pid) || pid <= 0 || title === '') continue
315
+ const key = `${pid}:${title}`
316
+ if (seen.has(key)) continue
317
+ seen.add(key)
318
+ let owner = String(pid)
319
+ try {
320
+ owner = readFileSync(`/proc/${pid}/comm`, 'utf8').trim() || owner
321
+ } catch {
322
+ /* ignore */
323
+ }
324
+ apps.push({ pid, name: owner, owner, title, bundleId: owner, windowNumber: apps.length + 1, frontmost: 0 })
325
+ }
326
+ return { ok: true, accessibility: true, apps }
327
+ }
328
+
158
329
  router.method('float.status', async () => {
330
+ const support = floatSupportStatus()
159
331
  const running = await floatRunningAsync()
160
332
  return {
161
- supported: process.platform === 'darwin' && appBundlePath() !== null,
333
+ supported: support.supported,
162
334
  platform: process.platform,
335
+ reason: support.reason,
336
+ hint: support.hint,
163
337
  running,
164
338
  pid: running ? (await listFloatPids())[0] ?? null : null,
165
- app: appBundlePath(),
339
+ app: isMac ? appBundlePath() : support.binary,
166
340
  }
167
341
  })
168
342
 
169
- /** 在 Finder 里显示悬浮层 App,便于用户在「屏幕录制」里手动添加。 */
343
+ /** 打开 helper 所在位置(macOS 在 Finder 显示 App;Windows 在资源管理器选中 exe;Linux 打开目录)。 */
170
344
  router.method('float.revealHelper', async () => {
171
- const app = appBundlePath()
172
- if (app === null) throw new ApiError('missing-helper', '悬浮层 App 未构建', 500)
345
+ const support = floatSupportStatus()
346
+ if (isMac) {
347
+ const app = appBundlePath()
348
+ if (app === null) throw new ApiError('missing-helper', '悬浮层 App 未构建', 500)
349
+ try {
350
+ spawn('open', ['-R', app], { detached: true, stdio: 'ignore' }).unref()
351
+ return { ok: true, app }
352
+ } catch {
353
+ return { ok: false, app }
354
+ }
355
+ }
356
+ if (!support.supported) throw new ApiError('missing-helper', support.hint ?? '悬浮层程序未构建', 500)
173
357
  try {
174
- spawn('open', ['-R', app], { detached: true, stdio: 'ignore' }).unref()
175
- return { ok: true, app }
358
+ if (isWin) spawn('explorer', ['/select,', support.binary], { detached: true, stdio: 'ignore' }).unref()
359
+ else spawn('xdg-open', [dirname(support.binary)], { detached: true, stdio: 'ignore' }).unref()
360
+ return { ok: true, app: support.binary }
176
361
  } catch {
177
- return { ok: false, app }
362
+ return { ok: false, app: support.binary }
178
363
  }
179
364
  })
180
365
 
181
- /** 列出可吸附的 App 窗口(通过 .app 身份启动 helper,输出到临时文件)。 */
366
+ /** 列出可吸附的 App 窗口(三平台统一返回 {ok, accessibility, apps})。 */
182
367
  router.method('float.windows', async () => {
183
- if (process.platform !== 'darwin') throw new ApiError('unsupported', '摸鱼模式目前只支持 macOS', 400)
368
+ const support = floatSupportStatus()
369
+ if (!support.supported) {
370
+ const message = support.reason === 'unsupported-platform'
371
+ ? '摸鱼模式暂不支持当前平台'
372
+ : (support.hint ?? '悬浮层程序未构建')
373
+ throw new ApiError('unsupported', message, 400)
374
+ }
375
+ if (!isMac) {
376
+ const list = isWin ? await listFloatWindowsWin() : await listFloatWindowsLinux()
377
+ debugLog(`float-windows platform=${process.platform} apps=${list.apps.length}`)
378
+ return list
379
+ }
184
380
  if (appBundlePath() === null) throw new ApiError('missing-helper', '悬浮层 App 未构建,请先运行 scripts/build-float-macos.sh', 500)
185
381
  const binary = floatBinaryPath()
186
382
  const outPath = join(tmpdir(), `gufa-float-windows-${process.pid}-${Date.now()}.json`)
@@ -203,7 +399,6 @@ export function register(router, env) {
203
399
  }
204
400
  }
205
401
  try {
206
- /* 路线 A:直接从 Host 进程 spawn(responsible app = DeepSeek Harness,可继承 DSH 的屏幕录制授权) */
207
402
  if (binary !== null) {
208
403
  try {
209
404
  await runFile(binary, ['--list-windows', '--out', outPath], { timeout: 12_000 })
@@ -215,7 +410,6 @@ export function register(router, env) {
215
410
  if (parsed !== null && parsed.ok === true) return parsed
216
411
  try { await rm(outPath, { force: true }) } catch { /* ignore */ }
217
412
  }
218
- /* 路线 B:通过 .app 身份启动(用户给「古法编程悬浮层.app」单独授权) */
219
413
  await openApp(['--list-windows', '--out', outPath])
220
414
  const parsed = await readResult()
221
415
  debugLog(`float-windows route=app ok=${String(parsed !== null && parsed.ok === true)} permission=${String(parsed !== null ? parsed.permission : 'none')}`)
@@ -230,8 +424,134 @@ export function register(router, env) {
230
424
  }
231
425
  })
232
426
 
427
+ /** 摸鱼自检:返回平台/helper/运行时依赖/显示环境信息,供客户端「自检」按钮展示与用户反馈。 */
428
+ router.method('float.diagnostics', async () => {
429
+ const support = floatSupportStatus()
430
+ const result = {
431
+ plugin: { version: PLUGIN_VERSION },
432
+ runtime: {
433
+ platform: process.platform,
434
+ arch: process.arch,
435
+ osRelease: release(),
436
+ execPath: process.execPath,
437
+ pid: process.pid,
438
+ ppid: process.ppid,
439
+ node: process.version,
440
+ },
441
+ float: {
442
+ supported: support.supported,
443
+ reason: support.reason,
444
+ hint: support.hint ?? '',
445
+ running: await floatRunningAsync(),
446
+ helper: null,
447
+ app: isMac ? appBundlePath() : support.binary,
448
+ controlPath: typeof floatState.controlPath === 'string' ? floatState.controlPath : '',
449
+ },
450
+ display: {},
451
+ deps: {},
452
+ tools: {},
453
+ notes: [],
454
+ }
455
+ /* helper 本身:路径 / 是否存在 / --version 输出 */
456
+ const binary = floatBinaryPath()
457
+ if (binary !== null) {
458
+ const helper = { path: binary, exists: existsSync(binary), version: '', versionError: '' }
459
+ try {
460
+ const { stdout, stderr } = await runFile(binary, ['--version'], { timeout: 6000 })
461
+ helper.version = String(stdout ?? '').trim().slice(0, 200)
462
+ if (helper.version === '') helper.version = String(stderr ?? '').trim().slice(0, 200)
463
+ } catch (error) {
464
+ helper.versionError = String(error?.message ?? error).slice(0, 200)
465
+ }
466
+ result.float.helper = helper
467
+ }
468
+ if (!support.supported) result.notes.push(support.hint ?? '悬浮层程序未构建')
469
+ if (isMac) {
470
+ result.display = { kind: 'macos' }
471
+ /* 辅助功能权限:helper --list-windows 会返回 accessibility 字段 */
472
+ let trusted = null
473
+ if (binary !== null) {
474
+ const outPath = join(tmpdir(), `gufa-float-doctor-${process.pid}-${Date.now()}.json`)
475
+ try {
476
+ await runFile(binary, ['--list-windows', '--out', outPath], { timeout: 10_000 })
477
+ const raw = await readFile(outPath, 'utf8')
478
+ const parsed = JSON.parse(raw.trim())
479
+ trusted = parsed !== null && typeof parsed === 'object'
480
+ ? (parsed.accessibility === true ? true : (parsed.accessibility === false ? false : null))
481
+ : null
482
+ result.display.accessibilityPermission = trusted
483
+ if (parsed !== null && typeof parsed.permissionError === 'string') result.display.permissionError = parsed.permissionError
484
+ } catch (error) {
485
+ result.display.accessibilityProbeError = String(error?.message ?? error).slice(0, 200)
486
+ } finally {
487
+ try { await rm(outPath, { force: true }) } catch { /* ignore */ }
488
+ }
489
+ if (trusted === false) result.notes.push('缺少「辅助功能」权限:系统设置 → 隐私与安全性 → 辅助功能 → 勾选 DeepSeek Harness,然后重启 DSH')
490
+ }
491
+ } else if (isWin) {
492
+ result.display = { sessionName: process.env.SESSIONNAME ?? '', windowStation: process.env.WINDOWSTATION ?? '' }
493
+ /* WebView2 Runtime:查注册表(HKLM WOW6432Node / HKLM / HKCU) */
494
+ const ps = [
495
+ "$paths = @('HKLM:\\SOFTWARE\\WOW6432Node\\Microsoft\\EdgeUpdate\\Clients\\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}','HKLM:\\SOFTWARE\\Microsoft\\EdgeUpdate\\Clients\\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}','HKCU:\\SOFTWARE\\Microsoft\\EdgeUpdate\\Clients\\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}')",
496
+ "$pv = ''; foreach ($p in $paths) { try { $v = (Get-ItemProperty -Path $p -Name pv -ErrorAction Stop).pv; if ($v) { $pv = $v; break } } catch {} }",
497
+ "Write-Output $pv",
498
+ ].join('\n')
499
+ try {
500
+ const { stdout } = await runFile('powershell', ['-NoProfile', '-NonInteractive', '-Command', ps], { timeout: 15_000 })
501
+ result.deps.webview2Runtime = String(stdout ?? '').trim()
502
+ } catch (error) {
503
+ result.deps.webview2RuntimeError = String(error?.message ?? error).slice(0, 200)
504
+ }
505
+ if (result.deps.webview2Runtime === '') result.notes.push('未检测到 WebView2 Runtime(Win10/11 的 Edge 通常自带;缺失请从微软官网安装)')
506
+ try {
507
+ const { stdout } = await runFile('powershell', ['-NoProfile', '-NonInteractive', '-Command', '$PSVersionTable.PSVersion.ToString()'], { timeout: 8000 })
508
+ result.tools.powershell = String(stdout ?? '').trim()
509
+ } catch { result.tools.powershell = 'missing' }
510
+ } else if (isLinux) {
511
+ result.display = {
512
+ DISPLAY: process.env.DISPLAY ?? '',
513
+ WAYLAND_DISPLAY: process.env.WAYLAND_DISPLAY ?? '',
514
+ XDG_SESSION_TYPE: process.env.XDG_SESSION_TYPE ?? '',
515
+ XDG_CURRENT_DESKTOP: process.env.XDG_CURRENT_DESKTOP ?? '',
516
+ }
517
+ if ((process.env.DISPLAY ?? '') === '' && (process.env.WAYLAND_DISPLAY ?? '') === '') {
518
+ result.notes.push('没有检测到 DISPLAY/WAYLAND_DISPLAY:请在图形桌面会话里启动 DSH')
519
+ } else if ((process.env.DISPLAY ?? '') === '' && (process.env.WAYLAND_DISPLAY ?? '') !== '') {
520
+ result.notes.push('当前是纯 Wayland 会话:摸鱼只能自由悬浮(无法跟随/隐藏其它窗口);有 XWayland 时可用 GDK_BACKEND=x11 启动 DSH')
521
+ }
522
+ try {
523
+ const { stdout } = await runFile('ldconfig', ['-p'], { timeout: 8000, maxBuffer: 8 * 1024 * 1024 })
524
+ const text = String(stdout ?? '')
525
+ result.deps.gtk3 = /libgtk-3\.so/.test(text)
526
+ result.deps.webkit2gtk41 = /libwebkit2gtk-4\.1\.so/.test(text)
527
+ result.deps.webkit2gtk40 = /libwebkit2gtk-4\.0\.so/.test(text)
528
+ result.deps.libsoup3 = /libsoup-3\.0\.so/.test(text)
529
+ result.deps.libsoup24 = /libsoup-2\.4\.so/.test(text)
530
+ } catch (error) {
531
+ result.deps.ldconfigError = String(error?.message ?? error).slice(0, 200)
532
+ }
533
+ if (!result.deps.gtk3 || (!result.deps.webkit2gtk41 && !result.deps.webkit2gtk40)) {
534
+ result.notes.push('缺少 GTK3/WebKit2GTK 运行库:sudo apt install libgtk-3-0 libwebkit2gtk-4.1-0 libsoup-3.0-0')
535
+ }
536
+ for (const tool of ['wmctrl', 'xdotool']) {
537
+ try {
538
+ const { stdout } = await runFile('sh', ['-c', `command -v ${tool}`], { timeout: 4000 })
539
+ result.tools[tool] = String(stdout ?? '').trim()
540
+ } catch {
541
+ result.tools[tool] = ''
542
+ }
543
+ }
544
+ if (result.tools.wmctrl === '') result.notes.push('未安装 wmctrl:列窗口会优先用 helper 自带实现;装 wmctrl 可作兜底(sudo apt install wmctrl)')
545
+ } else {
546
+ result.display = { kind: process.platform }
547
+ result.notes.push('当前平台暂不支持摸鱼模式')
548
+ }
549
+ try { debugLog(`float-diagnostics platform=${process.platform} supported=${support.supported} helper=${binary ?? 'none'} notes=${result.notes.length}`) } catch { /* ignore */ }
550
+ return result
551
+ })
552
+
233
553
  router.method('float.openPrivacy', async () => {
234
- if (process.platform !== 'darwin') return { ok: false }
554
+ if (!isMac) return { ok: false }
235
555
  try {
236
556
  spawn('open', ['x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility'], { detached: true, stdio: 'ignore' }).unref()
237
557
  return { ok: true }
@@ -241,8 +561,14 @@ export function register(router, env) {
241
561
  })
242
562
 
243
563
  router.method('float.start', async (body) => {
244
- if (process.platform !== 'darwin') throw new ApiError('unsupported', '摸鱼模式目前只支持 macOS', 400)
245
- if (appBundlePath() === null) throw new ApiError('missing-helper', '悬浮层 App 未构建,请先运行 scripts/build-float-macos.sh', 500)
564
+ const support = floatSupportStatus()
565
+ if (!support.supported) {
566
+ const message = support.reason === 'unsupported-platform'
567
+ ? '摸鱼模式暂不支持当前平台'
568
+ : (support.hint ?? '悬浮层程序未构建')
569
+ throw new ApiError('unsupported', message, 400)
570
+ }
571
+ if (isMac && appBundlePath() === null) throw new ApiError('missing-helper', '悬浮层 App 未构建,请先运行 scripts/build-float-macos.sh', 500)
246
572
  const follow = body !== null && typeof body === 'object' && body.follow !== null && typeof body.follow === 'object'
247
573
  ? {
248
574
  pid: Number(body.follow.pid) || 0,
@@ -264,7 +590,7 @@ export function register(router, env) {
264
590
  const authUrl = connection.authenticatedUrl(`${base}/`)
265
591
  const state = body !== null && typeof body === 'object' && body.state !== null && typeof body.state === 'object' ? body.state : null
266
592
  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'}`)
593
+ debugLog(`float-start-state platform=${process.platform} 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
594
  } catch {
269
595
  /* ignore */
270
596
  }
@@ -279,12 +605,13 @@ export function register(router, env) {
279
605
  state: state ?? undefined,
280
606
  alpha: Number.isFinite(alphaPref) && alphaPref >= 20 && alphaPref <= 100 ? Math.round(alphaPref) : undefined,
281
607
  build: PLUGIN_VERSION,
608
+ ownerPid: process.ppid,
282
609
  controlPath,
283
610
  })
284
611
  floatState.controlPath = controlPath
285
612
  const binary = floatBinaryPath()
286
613
  if (binary === null) throw new ApiError('missing-helper', '悬浮层程序未构建', 500)
287
- const child = spawn(binary, [payload], { detached: true, stdio: 'ignore' })
614
+ const child = spawn(binary, [payload], { detached: true, stdio: 'ignore', windowsHide: false })
288
615
  child.unref()
289
616
  floatState.child = child
290
617
  floatState.startedAt = Date.now()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-gufa-code",
3
- "version": "1.3.49",
3
+ "version": "1.3.51",
4
4
  "description": "古法编程 · AI 辅助:一键把 DSH 主面板变成 VS Code 风格 IDE(Monaco 编辑器、文件树、Git、SSH、真实终端 + 右侧官方会话);主张亲手写、每个改动心中有数,AI 是助理、你是第一责任人",
5
5
  "icon": "icon.svg",
6
6
  "keywords": [
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env bash
2
+ # 在 Linux 本机构建摸鱼悬浮层 helper(X11 + GTK3 + WebKit2GTK),并放到 host 期望的位置。
3
+ # 依赖:sudo apt install build-essential pkg-config libgtk-3-dev libwebkit2gtk-4.1-dev
4
+ set -euo pipefail
5
+ cd "$(dirname "$0")/.."
6
+ if [ "$(uname -s)" != "Linux" ]; then
7
+ echo "build-float-linux.sh 只能在 Linux 上运行;macOS/Windows 请用 GitHub Actions(.github/workflows/build-float.yml)构建。" >&2
8
+ exit 1
9
+ fi
10
+ make -C desktop/float/linux -j"$(nproc)"
11
+ mkdir -p desktop/float/bin/linux-x64
12
+ cp desktop/float/linux/gufa-float-linux desktop/float/bin/linux-x64/gufa-float-linux
13
+ chmod +x desktop/float/bin/linux-x64/gufa-float-linux
14
+ echo "built: desktop/float/bin/linux-x64/gufa-float-linux"
15
+ echo "提示:列窗口需要 wmctrl(sudo apt install wmctrl),或直接用 helper 自带 --list-windows。"
@@ -20,6 +20,7 @@ trap 'rm -f "$TMP_ARM" "$TMP_X64"' EXIT
20
20
  compile_arch() {
21
21
  local arch="$1" out="$2"
22
22
  clang -fobjc-arc -O2 -arch "$arch" \
23
+ -DGUFA_FLOAT_VERSION="\"${VERSION}\"" \
23
24
  -framework AppKit -framework WebKit -framework Carbon \
24
25
  -o "$out" "$SRC"
25
26
  }