dsh-gufa-code 1.3.50 → 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.
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,7 +22,6 @@ 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)
@@ -274,7 +274,9 @@ export function register(router, env) {
274
274
  if (parsed === null || parsed.ok !== true) throw new ApiError('list-failed', '读取 Windows 窗口列表失败', 500)
275
275
  let apps = parsed.apps
276
276
  if (!Array.isArray(apps)) apps = apps === null || apps === undefined ? [] : [apps]
277
- apps = apps.filter((row) => row !== null && typeof row === 'object' && Number(row.pid) > 0 && typeof row.title === 'string' && row.title !== '')
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 }))
278
280
  return { ok: true, accessibility: true, apps }
279
281
  }
280
282
 
@@ -319,7 +321,7 @@ export function register(router, env) {
319
321
  } catch {
320
322
  /* ignore */
321
323
  }
322
- apps.push({ pid, owner, title, bundleId: owner, windowNumber: apps.length + 1, frontmost: 0 })
324
+ apps.push({ pid, name: owner, owner, title, bundleId: owner, windowNumber: apps.length + 1, frontmost: 0 })
323
325
  }
324
326
  return { ok: true, accessibility: true, apps }
325
327
  }
@@ -422,6 +424,132 @@ export function register(router, env) {
422
424
  }
423
425
  })
424
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
+
425
553
  router.method('float.openPrivacy', async () => {
426
554
  if (!isMac) return { ok: false }
427
555
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-gufa-code",
3
- "version": "1.3.50",
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": [
@@ -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
  }
@@ -1285,6 +1285,9 @@ html[data-gufa-ide] [role="dialog"] {
1285
1285
  .gufa-float-owner{font-size:12.5px;font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
1286
1286
  .gufa-float-title{font-size:11px;color:var(--gufa-text-dim);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
1287
1287
  .gufa-float-size{flex:0 0 auto;font-size:10.5px;color:var(--gufa-text-dim);font-variant-numeric:tabular-nums}
1288
+ .gufa-doctor{width:min(760px,94vw);max-height:min(720px,86vh);display:flex;flex-direction:column}
1289
+ .gufa-doctor-pre{margin:0;padding:12px 14px;font:11.5px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace;
1290
+ white-space:pre-wrap;word-break:break-all;background:transparent;color:var(--gufa-text);overflow:auto;flex:1 1 auto}
1288
1291
  .gufa-float-permission{padding:16px}
1289
1292
  .gufa-float-permission-title{font-size:13px;font-weight:600;margin-bottom:6px}
1290
1293
  .gufa-session-workspace-btn{display:inline-flex;align-items:center;gap:4px;border:1px solid var(--gufa-border);background:var(--gufa-layer2);
@@ -159,6 +159,8 @@ G.GufaApp = function GufaApp(props) {
159
159
  const [floatBusy, setFloatBusy] = useState(false)
160
160
  /* 摸鱼窗口选择器:null | {status:'loading'|'ready'|'permission'|'error', windows:[], error:''} */
161
161
  const [floatPicker, setFloatPicker] = useState(null)
162
+ /* 摸鱼自检:null | {status:'loading'|'ok'|'error', data:null|object, error:''} */
163
+ const [floatDoctor, setFloatDoctor] = useState(null)
162
164
  /* 摸鱼模式(悬浮窗实例)与界面透明度 */
163
165
  const [moyuMode] = useState(() => G.isFloatMode())
164
166
  const [floatAlpha, setFloatAlpha] = useState(() => {
@@ -961,6 +963,20 @@ G.GufaApp = function GufaApp(props) {
961
963
  }
962
964
  }, [floatBusy])
963
965
 
966
+ /* 摸鱼自检:平台/helper/WebView2/辅助功能/X11 等现场信息,方便真机反馈 */
967
+ const openFloatDoctor = useCallback(async () => {
968
+ setFloatDoctor({ status: 'loading', data: null, error: '' })
969
+ try {
970
+ const value = await G.api('float.diagnostics')
971
+ setFloatDoctor({ status: 'ok', data: value ?? null, error: '' })
972
+ } catch (error) {
973
+ setFloatDoctor({ status: 'error', data: null, error: G.errorText(error) })
974
+ }
975
+ }, [])
976
+ const floatDoctorText = floatDoctor !== null && floatDoctor.data !== null
977
+ ? JSON.stringify(floatDoctor.data, null, 2)
978
+ : (floatDoctor !== null && typeof floatDoctor.error === 'string' ? floatDoctor.error : '')
979
+
964
980
  /* 选中某个 App 窗口 → 启动悬浮层并吸附它 */
965
981
  /* 当前编辑器状态快照(进出摸鱼都以它为准) */
966
982
  const buildFloatSnapshot = useCallback(() => ({
@@ -2552,6 +2568,7 @@ G.GufaApp = function GufaApp(props) {
2552
2568
  'div',
2553
2569
  { className: 'gufa-modal-foot' },
2554
2570
  h(G.IconButton, { title: '刷新列表', onClick: () => void openFloatPicker() }, h(G.Icon, { name: 'refresh', size: 14 })),
2571
+ h(G.Button, { onClick: () => void openFloatDoctor() }, '自检'),
2555
2572
  h('span', { style: { flex: '1 1 auto' } }),
2556
2573
  h(G.Button, { onClick: () => void startFloatFree() }, '自由悬浮(不吸附)'),
2557
2574
  h(G.Button, { onClick: () => setFloatPicker(null) }, t('common.close')),
@@ -2559,6 +2576,44 @@ G.GufaApp = function GufaApp(props) {
2559
2576
  ),
2560
2577
  )
2561
2578
  : null),
2579
+ G.portal(floatDoctor !== null
2580
+ ? h(
2581
+ 'div',
2582
+ {
2583
+ className: 'gufa-float-backdrop',
2584
+ onMouseDown: (event) => { if (event.target === event.currentTarget) setFloatDoctor(null) },
2585
+ },
2586
+ h(
2587
+ 'div',
2588
+ { className: 'gufa-modal gufa-doctor', role: 'dialog', 'aria-modal': 'true', 'aria-label': '摸鱼自检' },
2589
+ h(
2590
+ 'div',
2591
+ { className: 'gufa-modal-head' },
2592
+ h(G.Icon, { name: 'monitor', size: 15 }),
2593
+ h('span', { style: { flex: '1 1 auto' } }, '摸鱼自检(复制发给开发者排查)'),
2594
+ h(G.IconButton, { title: t('common.close'), onClick: () => setFloatDoctor(null) }, h(G.Icon, { name: 'close', size: 14 })),
2595
+ ),
2596
+ h(
2597
+ 'div',
2598
+ { className: 'gufa-modal-body', style: { padding: 0 } },
2599
+ floatDoctor.status === 'loading'
2600
+ ? h('div', { className: 'gufa-graph-loading', style: { height: 90 } }, h(G.Spinner), '正在检查平台 / helper / 运行时…')
2601
+ : floatDoctor.status === 'error'
2602
+ ? h('div', { className: 'gufa-float-permission' }, h('div', { className: 'gufa-error-banner' }, floatDoctor.error))
2603
+ : h('pre', { className: 'gufa-doctor-pre gufa-scroll' }, floatDoctorText),
2604
+ ),
2605
+ h(
2606
+ 'div',
2607
+ { className: 'gufa-modal-foot' },
2608
+ h('span', { style: { flex: '1 1 auto' } }),
2609
+ floatDoctor.status === 'ok'
2610
+ ? h(G.Button, { onClick: () => { void navigator.clipboard?.writeText(floatDoctorText) } }, '复制')
2611
+ : null,
2612
+ h(G.Button, { onClick: () => setFloatDoctor(null) }, t('common.close')),
2613
+ ),
2614
+ ),
2615
+ )
2616
+ : null),
2562
2617
  G.portal(sessionsOpen ? renderSessionsDialog() : null),
2563
2618
  G.portal(shortcutsOpen ? renderShortcutsDialog() : null),
2564
2619
  )