dsh-gufa-code 1.3.50 → 1.3.52

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,15 +2,16 @@
2
2
  * 开发/诊断信息:供客户端在启动时探测「Host 半是否为最新代码」。
3
3
  * 旧版本 Host(没有本方法)会让 api('dev.version') 返回 not-found,客户端据此提示重启 Harness。
4
4
  */
5
- import { appendFileSync, existsSync, readFileSync, writeFileSync } from 'node:fs'
5
+ import { appendFileSync, existsSync, mkdirSync, 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,176 @@ export function register(router, env) {
422
424
  }
423
425
  })
424
426
 
427
+ /** 摸鱼自检:返回平台/helper/运行时依赖/显示环境信息,供客户端「自检」按钮展示与用户反馈。 */
428
+ const collectFloatDiagnostics = 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
+
553
+ router.method('float.diagnostics', collectFloatDiagnostics)
554
+
555
+ /** 保存自检报告(诊断 JSON + 日志尾部)到 ~/.dsh,并在文件管理器里选中,方便用户一次性发回。 */
556
+ router.method('float.saveReport', async () => {
557
+ const data = await collectFloatDiagnostics()
558
+ const reportDir = join(homedir(), '.dsh')
559
+ const reportPath = join(reportDir, `gufa-float-report-${Date.now()}.txt`)
560
+ const lines = [
561
+ '古法编程 · 摸鱼自检报告',
562
+ `generatedAt=${new Date().toISOString()}`,
563
+ '---- diagnostics JSON ----',
564
+ JSON.stringify(data, null, 2),
565
+ '',
566
+ '---- logs ----',
567
+ ]
568
+ const logCandidates = ['/tmp/gufa-code-debug.log', join(tmpdir(), 'gufa-float-debug.log'), '/tmp/gufa-float-debug.log']
569
+ for (const logPath of logCandidates) {
570
+ lines.push(`## ${logPath}`)
571
+ try {
572
+ const raw = readFileSync(logPath, 'utf8')
573
+ const tail = raw.split('\n').filter((line) => line !== '').slice(-300)
574
+ if (tail.length === 0) lines.push('(empty)')
575
+ else lines.push(...tail)
576
+ } catch (error) {
577
+ lines.push(`(unreadable: ${String(error?.code ?? error)})`)
578
+ }
579
+ lines.push('')
580
+ }
581
+ try {
582
+ mkdirSync(reportDir, { recursive: true })
583
+ writeFileSync(reportPath, lines.join('\n'), { mode: 0o600 })
584
+ } catch (error) {
585
+ throw new ApiError('save-failed', `保存自检报告失败:${String(error?.message ?? error)}`, 500)
586
+ }
587
+ try {
588
+ if (isMac) spawn('open', ['-R', reportPath], { detached: true, stdio: 'ignore' }).unref()
589
+ else if (isWin) spawn('explorer', ['/select,', reportPath], { detached: true, stdio: 'ignore' }).unref()
590
+ else spawn('xdg-open', [reportDir], { detached: true, stdio: 'ignore' }).unref()
591
+ } catch {
592
+ /* 打不开文件管理器不影响保存结果 */
593
+ }
594
+ return { ok: true, path: reportPath }
595
+ })
596
+
425
597
  router.method('float.openPrivacy', async () => {
426
598
  if (!isMac) return { ok: false }
427
599
  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.52",
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,10 @@ 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)
164
+ /* 自检「保存报告」的结果路径/错误(显示在弹窗底部) */
165
+ const [floatReport, setFloatReport] = useState('')
162
166
  /* 摸鱼模式(悬浮窗实例)与界面透明度 */
163
167
  const [moyuMode] = useState(() => G.isFloatMode())
164
168
  const [floatAlpha, setFloatAlpha] = useState(() => {
@@ -961,6 +965,21 @@ G.GufaApp = function GufaApp(props) {
961
965
  }
962
966
  }, [floatBusy])
963
967
 
968
+ /* 摸鱼自检:平台/helper/WebView2/辅助功能/X11 等现场信息,方便真机反馈 */
969
+ const openFloatDoctor = useCallback(async () => {
970
+ setFloatReport('')
971
+ setFloatDoctor({ status: 'loading', data: null, error: '' })
972
+ try {
973
+ const value = await G.api('float.diagnostics')
974
+ setFloatDoctor({ status: 'ok', data: value ?? null, error: '' })
975
+ } catch (error) {
976
+ setFloatDoctor({ status: 'error', data: null, error: G.errorText(error) })
977
+ }
978
+ }, [])
979
+ const floatDoctorText = floatDoctor !== null && floatDoctor.data !== null
980
+ ? JSON.stringify(floatDoctor.data, null, 2)
981
+ : (floatDoctor !== null && typeof floatDoctor.error === 'string' ? floatDoctor.error : '')
982
+
964
983
  /* 选中某个 App 窗口 → 启动悬浮层并吸附它 */
965
984
  /* 当前编辑器状态快照(进出摸鱼都以它为准) */
966
985
  const buildFloatSnapshot = useCallback(() => ({
@@ -2552,6 +2571,7 @@ G.GufaApp = function GufaApp(props) {
2552
2571
  'div',
2553
2572
  { className: 'gufa-modal-foot' },
2554
2573
  h(G.IconButton, { title: '刷新列表', onClick: () => void openFloatPicker() }, h(G.Icon, { name: 'refresh', size: 14 })),
2574
+ h(G.Button, { onClick: () => void openFloatDoctor() }, '自检'),
2555
2575
  h('span', { style: { flex: '1 1 auto' } }),
2556
2576
  h(G.Button, { onClick: () => void startFloatFree() }, '自由悬浮(不吸附)'),
2557
2577
  h(G.Button, { onClick: () => setFloatPicker(null) }, t('common.close')),
@@ -2559,6 +2579,59 @@ G.GufaApp = function GufaApp(props) {
2559
2579
  ),
2560
2580
  )
2561
2581
  : null),
2582
+ G.portal(floatDoctor !== null
2583
+ ? h(
2584
+ 'div',
2585
+ {
2586
+ className: 'gufa-float-backdrop',
2587
+ onMouseDown: (event) => { if (event.target === event.currentTarget) setFloatDoctor(null) },
2588
+ },
2589
+ h(
2590
+ 'div',
2591
+ { className: 'gufa-modal gufa-doctor', role: 'dialog', 'aria-modal': 'true', 'aria-label': '摸鱼自检' },
2592
+ h(
2593
+ 'div',
2594
+ { className: 'gufa-modal-head' },
2595
+ h(G.Icon, { name: 'monitor', size: 15 }),
2596
+ h('span', { style: { flex: '1 1 auto' } }, '摸鱼自检(复制发给开发者排查)'),
2597
+ h(G.IconButton, { title: t('common.close'), onClick: () => setFloatDoctor(null) }, h(G.Icon, { name: 'close', size: 14 })),
2598
+ ),
2599
+ h(
2600
+ 'div',
2601
+ { className: 'gufa-modal-body', style: { padding: 0 } },
2602
+ floatDoctor.status === 'loading'
2603
+ ? h('div', { className: 'gufa-graph-loading', style: { height: 90 } }, h(G.Spinner), '正在检查平台 / helper / 运行时…')
2604
+ : floatDoctor.status === 'error'
2605
+ ? h('div', { className: 'gufa-float-permission' }, h('div', { className: 'gufa-error-banner' }, floatDoctor.error))
2606
+ : h('pre', { className: 'gufa-doctor-pre gufa-scroll' }, floatDoctorText),
2607
+ ),
2608
+ h(
2609
+ 'div',
2610
+ { className: 'gufa-modal-foot' },
2611
+ floatReport !== '' ? h('span', { className: 'gufa-hint', style: { flex: '1 1 auto', minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, floatReport) : h('span', { style: { flex: '1 1 auto' } }),
2612
+ floatDoctor.status === 'ok'
2613
+ ? h(
2614
+ G.Button,
2615
+ {
2616
+ onClick: () => {
2617
+ void G.api('float.saveReport').then((value) => {
2618
+ setFloatReport(typeof value?.path === 'string' ? `已保存:${value.path}` : '已保存')
2619
+ }).catch((error) => {
2620
+ setFloatReport(`保存失败:${G.errorText(error)}`)
2621
+ })
2622
+ },
2623
+ },
2624
+ '保存报告',
2625
+ )
2626
+ : null,
2627
+ floatDoctor.status === 'ok'
2628
+ ? h(G.Button, { onClick: () => { void navigator.clipboard?.writeText(floatDoctorText) } }, '复制')
2629
+ : null,
2630
+ h(G.Button, { onClick: () => setFloatDoctor(null) }, t('common.close')),
2631
+ ),
2632
+ ),
2633
+ )
2634
+ : null),
2562
2635
  G.portal(sessionsOpen ? renderSessionsDialog() : null),
2563
2636
  G.portal(shortcutsOpen ? renderShortcutsDialog() : null),
2564
2637
  )