dsh-gufa-code 1.3.59 → 1.3.61

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/client.js CHANGED
@@ -16,7 +16,7 @@ const GUFA_NS = 'gufa-code'
16
16
  const G = {}
17
17
  G.NS = GUFA_NS
18
18
  /** 客户端构建标记(排查页面是否加载了新代码时看标题栏) */
19
- G.BUILD = '1.3.59'
19
+ G.BUILD = '1.3.61'
20
20
  G.PANEL_ID = 'gufa-code'
21
21
  /** 从哪个工作区点进来的(工作区菜单/节点按钮写入,App 启动时消费)。 */
22
22
  G.pendingEntryWorkspace = null
@@ -9964,6 +9964,8 @@ G.GufaApp = function GufaApp(props) {
9964
9964
  const [gitRefreshToken, setGitRefreshToken] = useState(0)
9965
9965
  const [sshRefreshToken, setSshRefreshToken] = useState(0)
9966
9966
  const [gitStatus, setGitStatus] = useState(null)
9967
+ const gitSignatureRef = useRef('')
9968
+ const gitInFlightRef = useRef(false)
9967
9969
  const [modal, setModal] = useState(null)
9968
9970
  const [shortcutsOpen, setShortcutsOpen] = useState(false)
9969
9971
  const [trashUndo, setTrashUndo] = useState([])
@@ -10087,13 +10089,31 @@ G.GufaApp = function GufaApp(props) {
10087
10089
  const refreshGit = useCallback(async () => {
10088
10090
  if (project === null || project.isGit !== true) {
10089
10091
  setGitStatus(null)
10092
+ gitSignatureRef.current = ''
10090
10093
  return
10091
10094
  }
10095
+ if (gitInFlightRef.current) return
10096
+ gitInFlightRef.current = true
10092
10097
  try {
10093
10098
  const value = await G.api('git.status', { root: project.root })
10094
10099
  setGitStatus(value)
10100
+ /* 轮询时如果发现工作区状态变化(AI/外部修改了文件),顺带刷新资源管理器与 Git 面板 */
10101
+ const signature = JSON.stringify({
10102
+ branch: value?.branch ?? '',
10103
+ changes: (Array.isArray(value?.changes) ? value.changes : [])
10104
+ .map((change) => `${String(change?.path ?? '')}:${String(change?.status ?? '')}`)
10105
+ .sort(),
10106
+ })
10107
+ const previous = gitSignatureRef.current
10108
+ gitSignatureRef.current = signature
10109
+ if (previous !== '' && previous !== signature) {
10110
+ setRefreshToken((token) => token + 1)
10111
+ setGitRefreshToken((token) => token + 1)
10112
+ }
10095
10113
  } catch {
10096
10114
  setGitStatus(null)
10115
+ } finally {
10116
+ gitInFlightRef.current = false
10097
10117
  }
10098
10118
  }, [project])
10099
10119
 
@@ -10101,6 +10121,34 @@ G.GufaApp = function GufaApp(props) {
10101
10121
  void refreshGit()
10102
10122
  }, [refreshGit, gitRefreshToken])
10103
10123
 
10124
+ /* AI/外部进程改了文件时,Git 面板与资源管理器要能自动出现标识,不需要手动点 Git 按钮。
10125
+ - 3.5s 轮询 git.status(窗口可见时);状态签名变化 → 刷新 Git 面板 + 资源管理器
10126
+ - 非 Git 项目:6s 静默重读已加载目录,至少能看到外部新建/删除的文件 */
10127
+ useEffect(() => {
10128
+ if (project === null) return undefined
10129
+ const tickGit = () => {
10130
+ if (document.visibilityState !== 'visible') return
10131
+ void refreshGit()
10132
+ }
10133
+ const tickTree = () => {
10134
+ if (document.visibilityState !== 'visible') return
10135
+ if (project.isGit !== true) setRefreshToken((token) => token + 1)
10136
+ }
10137
+ const onVisible = () => {
10138
+ if (document.visibilityState === 'visible') void refreshGit()
10139
+ }
10140
+ const gitTimer = window.setInterval(tickGit, 3500)
10141
+ const treeTimer = window.setInterval(tickTree, 6000)
10142
+ window.addEventListener('focus', onVisible)
10143
+ document.addEventListener('visibilitychange', onVisible)
10144
+ return () => {
10145
+ window.clearInterval(gitTimer)
10146
+ window.clearInterval(treeTimer)
10147
+ window.removeEventListener('focus', onVisible)
10148
+ document.removeEventListener('visibilitychange', onVisible)
10149
+ }
10150
+ }, [project, refreshGit])
10151
+
10104
10152
  const gitStatuses = useMemo(() => {
10105
10153
  const map = {}
10106
10154
  for (const change of gitStatus?.changes ?? []) map[change.path] = change.status
@@ -13350,7 +13398,19 @@ const GUFA_PLUGIN = {
13350
13398
  /* ignore */
13351
13399
  }
13352
13400
  }
13353
- void G.api('dev.log', { message: `float-hittest ${probeAt(135, 713)} | ${probeAt(300, 713)} | ${probeAt(900, 500)} | ${probeAt(1500, 60)} | modal[${modalInfo}] | rows[${rows.slice(0, 12).join(' ; ')}]` }).catch(() => {})
13401
+ // 可输入控件位置(用于自动化验证复制/粘贴)
13402
+ let inputs = []
13403
+ try {
13404
+ for (const node of document.querySelectorAll('textarea, input, [contenteditable="true"]')) {
13405
+ const rect = node.getBoundingClientRect()
13406
+ if (rect.width < 30 || rect.height < 12) continue
13407
+ inputs.push(`${node.tagName}@${Math.round(rect.left)},${Math.round(rect.top)},${Math.round(rect.width)}x${Math.round(rect.height)}`)
13408
+ if (inputs.length >= 8) break
13409
+ }
13410
+ } catch {
13411
+ inputs = ['err']
13412
+ }
13413
+ void G.api('dev.log', { message: `float-hittest ${probeAt(135, 713)} | ${probeAt(300, 713)} | ${probeAt(900, 500)} | ${probeAt(1500, 60)} | modal[${modalInfo}] | rows[${rows.slice(0, 12).join(' ; ')}] | inputs[${inputs.join(' ; ')}]` }).catch(() => {})
13354
13414
  }, 5000)
13355
13415
  }
13356
13416
  } catch {
@@ -1088,6 +1088,29 @@ static AXUIElementRef GufaCopyAXWindow(pid_t pid, NSString *title) {
1088
1088
  return found;
1089
1089
  }
1090
1090
 
1091
+ /* WKWebView 的「复制/粘贴/剪切」在 macOS 上依赖 App 菜单的 key equivalent
1092
+ (Cmd+C/V/X 由主菜单转发成 copy:/paste:/cut: action)。
1093
+ 悬浮层是独立进程且没有主菜单,不加这个的话编辑器/输入框里复制粘贴全部失效。
1094
+ 注意只加剪切/复制/粘贴:Cmd+Z / Cmd+A / Cmd+F 等交给网页自己处理(Monaco 有自己的实现),
1095
+ 加进菜单反而会拦截网页快捷键。 */
1096
+ static void GufaInstallEditMenu(void) {
1097
+ NSMenu *mainMenu = [[NSMenu alloc] init];
1098
+ NSMenuItem *appMenuItem = [[NSMenuItem alloc] init];
1099
+ [mainMenu addItem:appMenuItem];
1100
+ NSMenu *appMenu = [[NSMenu alloc] initWithTitle:@"古法编程悬浮层"];
1101
+ appMenuItem.submenu = appMenu;
1102
+ [appMenu addItemWithTitle:@"关于古法编程悬浮层" action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
1103
+
1104
+ NSMenuItem *editMenuItem = [[NSMenuItem alloc] init];
1105
+ [mainMenu addItem:editMenuItem];
1106
+ NSMenu *editMenu = [[NSMenu alloc] initWithTitle:@"编辑"];
1107
+ editMenuItem.submenu = editMenu;
1108
+ [editMenu addItemWithTitle:@"剪切" action:@selector(cut:) keyEquivalent:@"x"];
1109
+ [editMenu addItemWithTitle:@"复制" action:@selector(copy:) keyEquivalent:@"c"];
1110
+ [editMenu addItemWithTitle:@"粘贴" action:@selector(paste:) keyEquivalent:@"v"];
1111
+ NSApp.mainMenu = mainMenu;
1112
+ }
1113
+
1091
1114
  int main(int argc, const char *argv[]) {
1092
1115
  if (argc > 1 && (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-v") == 0)) {
1093
1116
  printf("gufa-float-macos %s\n", GUFA_FLOAT_VERSION);
@@ -1108,6 +1131,7 @@ int main(int argc, const char *argv[]) {
1108
1131
  @autoreleasepool {
1109
1132
  [NSApplication sharedApplication];
1110
1133
  [NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory];
1134
+ GufaInstallEditMenu();
1111
1135
  GufaInstallTermHandler();
1112
1136
  GufaAppDelegate *delegate = [[GufaAppDelegate alloc] init];
1113
1137
  NSApp.delegate = delegate;
@@ -7,8 +7,8 @@
7
7
  <key>CFBundleDisplayName</key><string>古法编程悬浮层</string>
8
8
  <key>CFBundleExecutable</key><string>gufa-float</string>
9
9
  <key>CFBundlePackageType</key><string>APPL</string>
10
- <key>CFBundleShortVersionString</key><string>1.3.59</string>
11
- <key>CFBundleVersion</key><string>1.3.59</string>
10
+ <key>CFBundleShortVersionString</key><string>1.3.61</string>
11
+ <key>CFBundleVersion</key><string>1.3.61</string>
12
12
  <key>LSUIElement</key><true/>
13
13
  <key>NSHighResolutionCapable</key><true/>
14
14
  <key>NSPrincipalClass</key><string>NSApplication</string>
@@ -129,6 +129,27 @@
129
129
  - 刷新按钮改为 `refreshAll()`:重读「根目录 + 所有已加载目录」;
130
130
  - 窗口 `focus` / `visibilitychange`(可见)时防抖 180ms 自动 `refreshAll()`,从 Finder 切回来无需手动刷新。
131
131
 
132
+ ## 摸鱼窗口里复制/粘贴失效(1.3.60 修复)
133
+
134
+ macOS 上 WKWebView 的「复制/粘贴/剪切」是**通过 App 主菜单的 key equivalent** 转成 `copy:/paste:/cut:` 再走 responder chain 的。
135
+ 悬浮层是独立进程、没有主菜单,所以 Cmd+C/V 在编辑器、输入框里全部失效。
136
+
137
+ 修复:helper 安装 `NSApp.mainMenu`,只添加「编辑 → 剪切/复制/粘贴」三项(Cmd+X/C/V)。
138
+ **不要**把 Cmd+Z / Cmd+A / Cmd+F 加进菜单:Monaco 自己处理这些快捷键,菜单会拦截并走 WebView 原生选择/撤销,行为反而错乱。
139
+
140
+ 验证:悬浮层聊天输入框 Cmd+V → 粘贴成功,Cmd+A+C 后 `pbpaste` 内容正确;
141
+ 编辑器(.gitignore)里 Cmd+V 插入成功并自动保存,Cmd+A+C 后 `pbpaste` 为整个文件文本。
142
+
143
+ ## AI 改代码后 Git/资源管理器标识不刷新(1.3.61 修复)
144
+
145
+ 问题:AI(或任何外部进程)改了文件后,Git 面板和资源管理器的修改标识要手动点一下 Git 按钮才出现。
146
+ 原因:之前只在「本插件自己的操作」(保存、新建、删除、切换面板)后刷新 git 状态;
147
+ AI 是通过 Host 工具直接写盘,客户端收不到任何通知。
148
+
149
+ 修复:窗口可见时每 3.5s 轮询一次 `git.status`,计算「分支 + changes 路径/状态」签名,
150
+ 签名变化就自动刷新 Git 面板和资源管理器;非 Git 项目每 6s 静默重读已加载目录。
151
+ 窗口 focus / visibilitychange 时也会立即刷新一次。
152
+
132
153
  ## 5.1 摸鱼会话框比编辑器黑:官方会话根节点自己又画了一层底
133
154
 
134
155
  - 现象:摸鱼里编辑器/终端都统一了,右侧会话框看起来明显更黑更实。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-gufa-code",
3
- "version": "1.3.59",
3
+ "version": "1.3.61",
4
4
  "description": "古法编程 · AI 辅助:一键把 DSH 主面板变成 VS Code 风格 IDE(Monaco 编辑器、文件树、Git、SSH、真实终端 + 右侧官方会话);主张亲手写、每个改动心中有数,AI 是助理、你是第一责任人",
5
5
  "icon": "icon.svg",
6
6
  "keywords": [
@@ -263,6 +263,8 @@ G.GufaApp = function GufaApp(props) {
263
263
  const [gitRefreshToken, setGitRefreshToken] = useState(0)
264
264
  const [sshRefreshToken, setSshRefreshToken] = useState(0)
265
265
  const [gitStatus, setGitStatus] = useState(null)
266
+ const gitSignatureRef = useRef('')
267
+ const gitInFlightRef = useRef(false)
266
268
  const [modal, setModal] = useState(null)
267
269
  const [shortcutsOpen, setShortcutsOpen] = useState(false)
268
270
  const [trashUndo, setTrashUndo] = useState([])
@@ -386,13 +388,31 @@ G.GufaApp = function GufaApp(props) {
386
388
  const refreshGit = useCallback(async () => {
387
389
  if (project === null || project.isGit !== true) {
388
390
  setGitStatus(null)
391
+ gitSignatureRef.current = ''
389
392
  return
390
393
  }
394
+ if (gitInFlightRef.current) return
395
+ gitInFlightRef.current = true
391
396
  try {
392
397
  const value = await G.api('git.status', { root: project.root })
393
398
  setGitStatus(value)
399
+ /* 轮询时如果发现工作区状态变化(AI/外部修改了文件),顺带刷新资源管理器与 Git 面板 */
400
+ const signature = JSON.stringify({
401
+ branch: value?.branch ?? '',
402
+ changes: (Array.isArray(value?.changes) ? value.changes : [])
403
+ .map((change) => `${String(change?.path ?? '')}:${String(change?.status ?? '')}`)
404
+ .sort(),
405
+ })
406
+ const previous = gitSignatureRef.current
407
+ gitSignatureRef.current = signature
408
+ if (previous !== '' && previous !== signature) {
409
+ setRefreshToken((token) => token + 1)
410
+ setGitRefreshToken((token) => token + 1)
411
+ }
394
412
  } catch {
395
413
  setGitStatus(null)
414
+ } finally {
415
+ gitInFlightRef.current = false
396
416
  }
397
417
  }, [project])
398
418
 
@@ -400,6 +420,34 @@ G.GufaApp = function GufaApp(props) {
400
420
  void refreshGit()
401
421
  }, [refreshGit, gitRefreshToken])
402
422
 
423
+ /* AI/外部进程改了文件时,Git 面板与资源管理器要能自动出现标识,不需要手动点 Git 按钮。
424
+ - 3.5s 轮询 git.status(窗口可见时);状态签名变化 → 刷新 Git 面板 + 资源管理器
425
+ - 非 Git 项目:6s 静默重读已加载目录,至少能看到外部新建/删除的文件 */
426
+ useEffect(() => {
427
+ if (project === null) return undefined
428
+ const tickGit = () => {
429
+ if (document.visibilityState !== 'visible') return
430
+ void refreshGit()
431
+ }
432
+ const tickTree = () => {
433
+ if (document.visibilityState !== 'visible') return
434
+ if (project.isGit !== true) setRefreshToken((token) => token + 1)
435
+ }
436
+ const onVisible = () => {
437
+ if (document.visibilityState === 'visible') void refreshGit()
438
+ }
439
+ const gitTimer = window.setInterval(tickGit, 3500)
440
+ const treeTimer = window.setInterval(tickTree, 6000)
441
+ window.addEventListener('focus', onVisible)
442
+ document.addEventListener('visibilitychange', onVisible)
443
+ return () => {
444
+ window.clearInterval(gitTimer)
445
+ window.clearInterval(treeTimer)
446
+ window.removeEventListener('focus', onVisible)
447
+ document.removeEventListener('visibilitychange', onVisible)
448
+ }
449
+ }, [project, refreshGit])
450
+
403
451
  const gitStatuses = useMemo(() => {
404
452
  const map = {}
405
453
  for (const change of gitStatus?.changes ?? []) map[change.path] = change.status
@@ -546,7 +546,19 @@ const GUFA_PLUGIN = {
546
546
  /* ignore */
547
547
  }
548
548
  }
549
- void G.api('dev.log', { message: `float-hittest ${probeAt(135, 713)} | ${probeAt(300, 713)} | ${probeAt(900, 500)} | ${probeAt(1500, 60)} | modal[${modalInfo}] | rows[${rows.slice(0, 12).join(' ; ')}]` }).catch(() => {})
549
+ // 可输入控件位置(用于自动化验证复制/粘贴)
550
+ let inputs = []
551
+ try {
552
+ for (const node of document.querySelectorAll('textarea, input, [contenteditable="true"]')) {
553
+ const rect = node.getBoundingClientRect()
554
+ if (rect.width < 30 || rect.height < 12) continue
555
+ inputs.push(`${node.tagName}@${Math.round(rect.left)},${Math.round(rect.top)},${Math.round(rect.width)}x${Math.round(rect.height)}`)
556
+ if (inputs.length >= 8) break
557
+ }
558
+ } catch {
559
+ inputs = ['err']
560
+ }
561
+ void G.api('dev.log', { message: `float-hittest ${probeAt(135, 713)} | ${probeAt(300, 713)} | ${probeAt(900, 500)} | ${probeAt(1500, 60)} | modal[${modalInfo}] | rows[${rows.slice(0, 12).join(' ; ')}] | inputs[${inputs.join(' ; ')}]` }).catch(() => {})
550
562
  }, 5000)
551
563
  }
552
564
  } catch {