dsh-gufa-code 1.3.0 → 1.3.2

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/README.md CHANGED
@@ -99,6 +99,11 @@ node scripts/test-editor.mjs
99
99
  # 修改 host/*.js 后无需重启(请求级热重载);修改 client 后重新构建并刷新页面
100
100
  ```
101
101
 
102
+ > 加新功能/新浮层前先看 [`docs/KNOWN-PITFALLS.md`](docs/KNOWN-PITFALLS.md)(层级、TCC 权限、Monaco worker 三个坑)。
103
+
104
+ ```sh
105
+ ```
106
+
102
107
  ## License
103
108
 
104
109
  MIT
package/client.js CHANGED
@@ -1056,6 +1056,8 @@ html[data-gufa-float] #root .gufa-overlay-root *,
1056
1056
  html[data-gufa-float] #root [data-gufa-dock] *{visibility:visible!important}
1057
1057
  /* 桌宠提到覆盖层之上:同时兼容 @linxin666/dsh-pet(data-dsh-pet-root)与官方 dsh-pet(.dsh-pet-root) */
1058
1058
  html[data-gufa-ide] .dsh-pet-root{z-index:2147483400!important}
1059
+ /* 古法自己的弹窗/菜单打开时:整个覆盖层临时抬到右侧停靠会话(z-index 2147483040)之上 */
1060
+ html[data-gufa-popup] .gufa-overlay-root{z-index:2147483300!important}
1059
1061
  /* 外部弹窗(DSH 设置等)打开时:停靠会话与桌宠降到弹窗之下,保证弹窗完整可点可关 */
1060
1062
  html[data-gufa-external-modal] [data-gufa-dock]{z-index:2!important}
1061
1063
  html[data-gufa-external-modal] .dsh-pet-root{z-index:2!important}
@@ -8107,6 +8109,64 @@ G.installDialogLayerWatch = function installDialogLayerWatch(ctx) {
8107
8109
  }
8108
8110
 
8109
8111
 
8112
+ /* ─────────────────────── 59-popup-layer.js ─────────────────────── */
8113
+ /**
8114
+ * 59-popup-layer:弹窗/菜单层级修正。
8115
+ *
8116
+ * 背景(踩坑记录,见 docs/KNOWN-PITFALLS.md):
8117
+ * 古法编程的界面都在 `.gufa-overlay-root`(z-index:1)这个层叠上下文里,而右侧停靠的
8118
+ * 官方会话根节点是 body 级 fixed、z-index 2147483040。任何在 root 内部弹出的
8119
+ * modal / menu / popover,如果只设自己的 z-index,都会被困在 root 的上下文里,
8120
+ * 被停靠会话盖住(表现为「弹窗被右侧聊天挡一半、点不到关闭」)。
8121
+ *
8122
+ * 修法:检测 root 内是否出现 popup,出现时给 html 加 `data-gufa-popup`,
8123
+ * 由 CSS 把整个 overlay root 临时抬到停靠会话之上。
8124
+ */
8125
+
8126
+ G.installPopupLayerWatch = function installPopupLayerWatch(ctx) {
8127
+ if (typeof document === 'undefined') return () => {}
8128
+ const ATTR = 'data-gufa-popup'
8129
+ const SELECTOR = [
8130
+ '[role="menu"]',
8131
+ '[role="listbox"]',
8132
+ '[role="dialog"]',
8133
+ '.gufa-modal',
8134
+ '.gufa-float-backdrop',
8135
+ '.gufa-branch-dialog-backdrop',
8136
+ '.gufa-session-backdrop',
8137
+ '.gufa-shortcuts-backdrop',
8138
+ ].join(',')
8139
+
8140
+ const sync = () => {
8141
+ try {
8142
+ const root = document.querySelector('.gufa-root')
8143
+ const popup = root === null ? null : root.querySelector(SELECTOR)
8144
+ const open = popup !== null
8145
+ if ((document.documentElement.getAttribute(ATTR) === '1') === open) return
8146
+ if (open) document.documentElement.setAttribute(ATTR, '1')
8147
+ else document.documentElement.removeAttribute(ATTR)
8148
+ } catch {
8149
+ /* ignore */
8150
+ }
8151
+ }
8152
+
8153
+ let observer = null
8154
+ try {
8155
+ observer = new MutationObserver(sync)
8156
+ observer.observe(document.documentElement, { childList: true, subtree: true, attributes: true, attributeFilter: ['class', 'style', 'data-state', 'aria-hidden'] })
8157
+ } catch {
8158
+ observer = null
8159
+ }
8160
+ sync()
8161
+ const timer = window.setInterval(sync, 400)
8162
+ return () => {
8163
+ if (observer !== null) observer.disconnect()
8164
+ window.clearInterval(timer)
8165
+ document.documentElement.removeAttribute(ATTR)
8166
+ }
8167
+ }
8168
+
8169
+
8110
8170
  /* ─────────────────────── 60-dock.js ─────────────────────── */
8111
8171
  /**
8112
8172
  * 60-dock:把官方 DSH 会话面板「停靠」进古法编程右侧的 AI 栏。
@@ -11461,11 +11521,12 @@ G.GufaApp = function GufaApp(props) {
11461
11521
  'div',
11462
11522
  { className: 'gufa-float-permission' },
11463
11523
  h('div', { className: 'gufa-float-permission-title' }, '需要「屏幕录制」权限'),
11464
- h('div', { className: 'gufa-hint' }, '摸鱼模式需要读取其他 App 窗口的尺寸(只读尺寸,不录屏)。请在「系统设置 → 隐私与安全性 → 屏幕录制」里允许 DeepSeek Harness / gufa-float,然后点重试。'),
11524
+ h('div', { className: 'gufa-hint' }, '摸鱼列表需要读取其他 App 的窗口尺寸(只读尺寸,不录屏)。系统只认悬浮层 App 自己的授权:请在「系统设置 → 隐私与安全性 → 屏幕录制」里点左下角「+」,添加「古法编程悬浮层.app」并打开开关(DeepSeek Harness 的开关也保持打开)。加好后点「重试」。'),
11465
11525
  h(
11466
11526
  'div',
11467
- { className: 'gufa-row', style: { gap: 8, marginTop: 12 } },
11527
+ { className: 'gufa-row', style: { gap: 8, marginTop: 12, flexWrap: 'wrap' } },
11468
11528
  h(G.Button, { primary: true, onClick: () => void G.api('float.openPrivacy').catch(() => {}) }, '打开系统设置'),
11529
+ h(G.Button, { onClick: () => void G.api('float.revealHelper').catch(() => {}) }, '在 Finder 中显示悬浮层 App'),
11469
11530
  h(G.Button, { onClick: () => void openFloatPicker() }, '重试'),
11470
11531
  ),
11471
11532
  )
@@ -12132,6 +12193,16 @@ const GUFA_PLUGIN = {
12132
12193
  window.setTimeout(cleanStaleSidebarLayouts, 1500)
12133
12194
  window.setTimeout(cleanStaleSidebarLayouts, 5000)
12134
12195
 
12196
+ // 弹窗/菜单打开时把覆盖层整体抬到右侧停靠会话之上(否则会被盖住)
12197
+ try {
12198
+ if (typeof G.installPopupLayerWatch === 'function') {
12199
+ const disposePopupWatch = G.installPopupLayerWatch(ctx)
12200
+ if (typeof disposePopupWatch === 'function') ctx.effect(() => disposePopupWatch, 'gufa-code: popup layer watch')
12201
+ }
12202
+ } catch (error) {
12203
+ console.error('[gufa-code] 安装弹窗层级监听失败', error)
12204
+ }
12205
+
12135
12206
  // 外部弹窗(设置等)打开时降低停靠层,避免遮挡弹窗导致关不掉
12136
12207
  try {
12137
12208
  if (typeof G.installDialogLayerWatch === 'function') {
@@ -19,6 +19,7 @@ static const EventHotKeyID GufaToggleHotKey = {'gufa', 1};
19
19
 
20
20
  /* SIGTERM 时先把主窗口(DeepSeek Harness)唤回前台,再退出,实现「退出摸鱼」 */
21
21
  static void GufaInstallTermHandler(void);
22
+ static BOOL GufaRowsHaveForeignWindows(NSArray<NSDictionary *> *rows);
22
23
 
23
24
  @class GufaAppDelegate;
24
25
 
@@ -327,14 +328,9 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
327
328
  }
328
329
 
329
330
  - (void)chooseFollowWindow:(id)sender {
330
- if (!CGPreflightScreenCaptureAccess()) {
331
- CGRequestScreenCaptureAccess();
332
- [self showPermissionGuide];
333
- return;
334
- }
335
331
  NSArray<NSDictionary *> *rows = [self visibleWindows];
336
- /* 只有一个窗口 = 权限没生效,仍是我们自己 */
337
- if (rows.count == 0) {
332
+ if (rows.count == 0 || !GufaRowsHaveForeignWindows(rows)) {
333
+ CGRequestScreenCaptureAccess();
338
334
  [self showPermissionGuide];
339
335
  return;
340
336
  }
@@ -534,35 +530,54 @@ static NSArray<NSDictionary *> *GufaEnumerateWindows(void) {
534
530
  return rows;
535
531
  }
536
532
 
537
- static int GufaListWindowsMode(void) {
538
- BOOL granted = CGPreflightScreenCaptureAccess();
539
- if (!granted) {
540
- CGRequestScreenCaptureAccess();
541
- NSDictionary *out = @{@"ok": @NO, @"permission": @"screen-recording"};
542
- NSData *json = [NSJSONSerialization dataWithJSONObject:out options:0 error:NULL];
543
- fwrite(json.bytes, 1, json.length, stdout);
544
- fputc('\n', stdout);
545
- return 2;
533
+ static NSString *GufaOutputPath = nil;
534
+
535
+ static void GufaEmitJSON(NSDictionary *out) {
536
+ NSData *json = [NSJSONSerialization dataWithJSONObject:out options:0 error:NULL];
537
+ if (json == nil) return;
538
+ if (GufaOutputPath.length > 0) {
539
+ [json writeToFile:GufaOutputPath atomically:YES];
540
+ return;
546
541
  }
542
+ fwrite(json.bytes, 1, json.length, stdout);
543
+ fputc('\n', stdout);
544
+ }
545
+
546
+ static void GufaPrintPermissionResult(void) {
547
+ GufaEmitJSON(@{@"ok": @NO, @"permission": @"screen-recording"});
548
+ }
549
+
550
+ /** 没权限时 CGWindowList 只返回「自己这个 App」的窗口;据此判断权限,而不是信 CGPreflight。 */
551
+ static BOOL GufaRowsHaveForeignWindows(NSArray<NSDictionary *> *rows) {
552
+ NSString *own = NSProcessInfo.processInfo.processName;
553
+ for (NSDictionary *row in rows) {
554
+ NSString *owner = row[@"owner"];
555
+ if ([owner isKindOfClass:[NSString class]] && owner.length > 0
556
+ && ![owner isEqualToString:@"DeepSeek Harness"] && ![owner isEqualToString:own]) {
557
+ return YES;
558
+ }
559
+ }
560
+ return NO;
561
+ }
562
+
563
+ static int GufaListWindowsMode(void) {
547
564
  NSArray<NSDictionary *> *rows = GufaEnumerateWindows();
548
- if (rows.count == 0) {
549
- /* CGRequestScreenCaptureAccess 授权后同一进程内可能还需要重启;提示前端重试 */
550
- NSDictionary *out = @{@"ok": @NO, @"permission": @"screen-recording"};
551
- NSData *json = [NSJSONSerialization dataWithJSONObject:out options:0 error:NULL];
552
- fwrite(json.bytes, 1, json.length, stdout);
553
- fputc('\n', stdout);
565
+ if (rows.count == 0 || !GufaRowsHaveForeignWindows(rows)) {
566
+ /* 触发一次系统授权提示(授权后重新点「重试」即可) */
567
+ CGRequestScreenCaptureAccess();
568
+ GufaPrintPermissionResult();
554
569
  return 2;
555
570
  }
556
- NSDictionary *out = @{@"ok": @YES, @"windows": rows};
557
- NSData *json = [NSJSONSerialization dataWithJSONObject:out options:0 error:NULL];
558
- fwrite(json.bytes, 1, json.length, stdout);
559
- fputc('\n', stdout);
571
+ GufaEmitJSON(@{@"ok": @YES, @"windows": rows});
560
572
  return 0;
561
573
  }
562
574
 
563
575
  int main(int argc, const char *argv[]) {
564
576
  if (argc > 1 && strcmp(argv[1], "--list-windows") == 0) {
565
577
  @autoreleasepool {
578
+ for (int i = 2; i + 1 < argc; i++) {
579
+ if (strcmp(argv[i], "--out") == 0) GufaOutputPath = [NSString stringWithUTF8String:argv[i + 1]];
580
+ }
566
581
  return GufaListWindowsMode();
567
582
  }
568
583
  }
@@ -0,0 +1,16 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>CFBundleIdentifier</key><string>com.gufa.float</string>
6
+ <key>CFBundleName</key><string>古法编程悬浮层</string>
7
+ <key>CFBundleDisplayName</key><string>古法编程悬浮层</string>
8
+ <key>CFBundleExecutable</key><string>gufa-float</string>
9
+ <key>CFBundlePackageType</key><string>APPL</string>
10
+ <key>CFBundleShortVersionString</key><string>1.3.1</string>
11
+ <key>CFBundleVersion</key><string>1.3.1</string>
12
+ <key>LSUIElement</key><true/>
13
+ <key>NSHighResolutionCapable</key><true/>
14
+ <key>NSPrincipalClass</key><string>NSApplication</string>
15
+ </dict>
16
+ </plist>
@@ -0,0 +1,115 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>files</key>
6
+ <dict/>
7
+ <key>files2</key>
8
+ <dict/>
9
+ <key>rules</key>
10
+ <dict>
11
+ <key>^Resources/</key>
12
+ <true/>
13
+ <key>^Resources/.*\.lproj/</key>
14
+ <dict>
15
+ <key>optional</key>
16
+ <true/>
17
+ <key>weight</key>
18
+ <real>1000</real>
19
+ </dict>
20
+ <key>^Resources/.*\.lproj/locversion.plist$</key>
21
+ <dict>
22
+ <key>omit</key>
23
+ <true/>
24
+ <key>weight</key>
25
+ <real>1100</real>
26
+ </dict>
27
+ <key>^Resources/Base\.lproj/</key>
28
+ <dict>
29
+ <key>weight</key>
30
+ <real>1010</real>
31
+ </dict>
32
+ <key>^version.plist$</key>
33
+ <true/>
34
+ </dict>
35
+ <key>rules2</key>
36
+ <dict>
37
+ <key>.*\.dSYM($|/)</key>
38
+ <dict>
39
+ <key>weight</key>
40
+ <real>11</real>
41
+ </dict>
42
+ <key>^(.*/)?\.DS_Store$</key>
43
+ <dict>
44
+ <key>omit</key>
45
+ <true/>
46
+ <key>weight</key>
47
+ <real>2000</real>
48
+ </dict>
49
+ <key>^(Frameworks|SharedFrameworks|PlugIns|Plug-ins|XPCServices|Helpers|MacOS|Library/(Automator|Spotlight|LoginItems))/</key>
50
+ <dict>
51
+ <key>nested</key>
52
+ <true/>
53
+ <key>weight</key>
54
+ <real>10</real>
55
+ </dict>
56
+ <key>^.*</key>
57
+ <true/>
58
+ <key>^Info\.plist$</key>
59
+ <dict>
60
+ <key>omit</key>
61
+ <true/>
62
+ <key>weight</key>
63
+ <real>20</real>
64
+ </dict>
65
+ <key>^PkgInfo$</key>
66
+ <dict>
67
+ <key>omit</key>
68
+ <true/>
69
+ <key>weight</key>
70
+ <real>20</real>
71
+ </dict>
72
+ <key>^Resources/</key>
73
+ <dict>
74
+ <key>weight</key>
75
+ <real>20</real>
76
+ </dict>
77
+ <key>^Resources/.*\.lproj/</key>
78
+ <dict>
79
+ <key>optional</key>
80
+ <true/>
81
+ <key>weight</key>
82
+ <real>1000</real>
83
+ </dict>
84
+ <key>^Resources/.*\.lproj/locversion.plist$</key>
85
+ <dict>
86
+ <key>omit</key>
87
+ <true/>
88
+ <key>weight</key>
89
+ <real>1100</real>
90
+ </dict>
91
+ <key>^Resources/Base\.lproj/</key>
92
+ <dict>
93
+ <key>weight</key>
94
+ <real>1010</real>
95
+ </dict>
96
+ <key>^[^/]+$</key>
97
+ <dict>
98
+ <key>nested</key>
99
+ <true/>
100
+ <key>weight</key>
101
+ <real>10</real>
102
+ </dict>
103
+ <key>^embedded\.provisionprofile$</key>
104
+ <dict>
105
+ <key>weight</key>
106
+ <real>20</real>
107
+ </dict>
108
+ <key>^version\.plist$</key>
109
+ <dict>
110
+ <key>weight</key>
111
+ <real>20</real>
112
+ </dict>
113
+ </dict>
114
+ </dict>
115
+ </plist>
@@ -0,0 +1,39 @@
1
+ # 已知坑(踩过的,别再踩)
2
+
3
+ > 这份清单记录已经犯过、并且容易再犯的错误。加新功能前先扫一遍。
4
+
5
+ ## 1. 古法编程里的浮层会被右侧停靠会话盖住(反复踩)
6
+
7
+ **现象**:弹窗/菜单只显示一半;关闭按钮点不到;列表被右侧「古法 AI」聊天栏压住;点击穿透的弹窗挡在聊天栏下面。
8
+
9
+ **原因**:
10
+ - 古法编程的所有界面都在 `.gufa-overlay-root` 里,它是 `z-index:1` 的层叠上下文;
11
+ - 右侧停靠的官方会话根节点是 **body 级** `position:fixed; z-index:2147483040`;
12
+ - 所以 root 内弹窗自己的 `z-index` 写多大都没用,出不了 root 的层叠上下文,必然被会话盖住。
13
+
14
+ **正确做法(三选一)**:
15
+ 1. 古法自己的弹窗/菜单:打开时把 root 抬起来 —— 现有 `59-popup-layer.js` 会自动检测 root 内出现的
16
+ `[role=menu] / [role=dialog] / [role=listbox] / .gufa-modal / .gufa-float-backdrop` 等,
17
+ 给 `<html>` 加 `data-gufa-popup`,CSS 把 `.gufa-overlay-root` 抬到 `z-index:2147483300`;
18
+ 新增全屏浮层时**必须**把它的类名加进 `59-popup-layer.js` 的 SELECTOR。
19
+ 2. 外部(DSH 官方)弹窗:`59-dialog-layer.js` 检测 body 级 `[role="dialog"][aria-modal="true"]`,
20
+ 加 `data-gufa-external-modal`,CSS 把停靠会话降到 `z-index:2`。
21
+ 3. 任何新浮层提交前:**在有右侧会话打开的情况下**实测它是否完整可见、可关闭。
22
+
23
+ **禁止**:只在浮层自身上写一个很高的 `z-index` 就交付。
24
+
25
+ ## 2. macOS 屏幕录制权限 + 悬浮层 helper
26
+
27
+ - helper 每次重新编译(代码签名变化)后,TCC 里旧的「屏幕录制」授权可能失效;
28
+ - `CGPreflightScreenCaptureAccess()` **不可靠**:可能返回 true,但 `CGWindowListCopyWindowInfo`
29
+ 只返回自己 App 的窗口(表现为摸鱼列表里只有 DeepSeek Harness 自己);
30
+ - 判断权限要**看列表内容**:是否出现非 `DeepSeek Harness` 的 owner(helper 里 `GufaRowsHaveForeignWindows`);
31
+ - 授权对象是 **DeepSeek Harness**(helper 以它作为 responsible app 继承权限);
32
+ 授权后如果列表仍只显示自己,**重启一次 DeepSeek Harness** 再试。
33
+
34
+ ## 3. Monaco worker:dsh-app:// 下不能 importScripts 相对路径
35
+
36
+ - 现象:Git diff 永远没有红绿、`getLineChanges()` 一直为空;
37
+ - 原因:页面源是 `dsh-app://`,Monaco 默认 blob worker 里 `importScripts('/gufa-code/...')` 是非法 URL;
38
+ - 修法:worker 用同源 `vendor/monaco/vs/worker-bootstrap.js` 作为入口,里面只做
39
+ `MonacoEnvironment.baseUrl` + `importScripts(workerMain.js)`;**不要**先加载 AMD `loader.js`(模块系统冲突)。
package/host/dev.js CHANGED
@@ -3,6 +3,8 @@
3
3
  * 旧版本 Host(没有本方法)会让 api('dev.version') 返回 not-found,客户端据此提示重启 Harness。
4
4
  */
5
5
  import { appendFileSync, existsSync } from 'node:fs'
6
+ import { readFile, rm } from 'node:fs/promises'
7
+ import { tmpdir } from 'node:os'
6
8
  import { execFile, spawn } from 'node:child_process'
7
9
  import { promisify } from 'node:util'
8
10
  import { dirname, join } from 'node:path'
@@ -43,36 +45,115 @@ export function register(router, env) {
43
45
  const startedAt = new Date().toISOString()
44
46
  const ctx = env?.ctx ?? router.ctx
45
47
 
46
- /* ── 桌面悬浮层(P0,macOS) ─────────────────────────────────────── */
47
- router.method('float.status', async () => ({
48
- supported: process.platform === 'darwin' && floatBinaryPath() !== null,
49
- platform: process.platform,
50
- running: floatRunning(),
51
- pid: floatRunning() ? floatState.child.pid : null,
52
- binary: floatBinaryPath(),
53
- }))
48
+ /* ── 桌面悬浮层 / 摸鱼模式(macOS) ────────────────────────────────
49
+ * 通过 .app bundle 启动 helper:TCC(屏幕录制)按 bundle 身份授权,
50
+ * 用户在「系统设置 → 隐私与安全性 → 屏幕录制」里添加「古法编程悬浮层.app」即可。
51
+ */
52
+ const appBundlePath = () => {
53
+ const candidates = [
54
+ join(PLUGIN_ROOT, 'desktop', 'float', '古法编程悬浮层.app'),
55
+ join(PLUGIN_ROOT, 'desktop', 'float', 'GufaFloat.app'),
56
+ ]
57
+ for (const candidate of candidates) {
58
+ if (existsSync(candidate)) return candidate
59
+ }
60
+ return null
61
+ }
62
+ const floatProcessPattern = '古法编程悬浮层.app/Contents/MacOS/gufa-float'
54
63
 
55
- /** 列出可吸附的 App 窗口(spawn helper 的 --list-windows 模式,JSON 输出)。 */
56
- router.method('float.windows', async () => {
57
- if (process.platform !== 'darwin') throw new ApiError('unsupported', '摸鱼模式目前只支持 macOS', 400)
58
- const binary = floatBinaryPath()
59
- if (binary === null) throw new ApiError('missing-helper', '悬浮层程序未构建,请先运行 scripts/build-float-macos.sh', 500)
60
- let stdout = ''
64
+ const listFloatPids = async () => {
61
65
  try {
62
- const result = await runFile(binary, ['--list-windows'], { timeout: 10_000, maxBuffer: 8 * 1024 * 1024 })
63
- stdout = String(result.stdout ?? '')
64
- } catch (error) {
65
- stdout = String(error && error.stdout || '')
66
+ const { stdout } = await runFile('pgrep', ['-f', floatProcessPattern], { timeout: 3000 })
67
+ return String(stdout ?? '').split('\n').map((line) => Number(line.trim())).filter((pid) => Number.isFinite(pid) && pid > 0)
68
+ } catch {
69
+ return []
70
+ }
71
+ }
72
+ const floatRunningAsync = async () => (await listFloatPids()).length > 0
73
+
74
+ const openApp = (args) => new Promise((resolve, reject) => {
75
+ const app = appBundlePath()
76
+ if (app === null) {
77
+ reject(new ApiError('missing-helper', '悬浮层 App 未构建,请先运行 scripts/build-float-macos.sh', 500))
78
+ return
79
+ }
80
+ const child = spawn('open', ['-n', app, '--args', ...args], { detached: true, stdio: 'ignore' })
81
+ child.once('error', reject)
82
+ child.once('exit', (code) => {
83
+ if (code === 0) resolve()
84
+ else reject(new ApiError('open-failed', `悬浮层启动失败(open exit ${code})`, 500))
85
+ })
86
+ })
87
+
88
+ const killFloat = async () => {
89
+ const pids = await listFloatPids()
90
+ for (const pid of pids) {
91
+ try {
92
+ process.kill(pid, 'SIGTERM')
93
+ } catch {
94
+ /* ignore */
95
+ }
96
+ }
97
+ if (pids.length > 0) await new Promise((resolve) => setTimeout(resolve, 400))
98
+ floatState.child = null
99
+ }
100
+
101
+ router.method('float.status', async () => {
102
+ const running = await floatRunningAsync()
103
+ return {
104
+ supported: process.platform === 'darwin' && appBundlePath() !== null,
105
+ platform: process.platform,
106
+ running,
107
+ pid: running ? (await listFloatPids())[0] ?? null : null,
108
+ app: appBundlePath(),
66
109
  }
67
- const line = stdout.trim().split('\n').filter(Boolean).pop() ?? ''
68
- let parsed = null
110
+ })
111
+
112
+ /** 在 Finder 里显示悬浮层 App,便于用户在「屏幕录制」里手动添加。 */
113
+ router.method('float.revealHelper', async () => {
114
+ const app = appBundlePath()
115
+ if (app === null) throw new ApiError('missing-helper', '悬浮层 App 未构建', 500)
69
116
  try {
70
- parsed = JSON.parse(line)
117
+ spawn('open', ['-R', app], { detached: true, stdio: 'ignore' }).unref()
118
+ return { ok: true, app }
71
119
  } catch {
72
- parsed = null
120
+ return { ok: false, app }
121
+ }
122
+ })
123
+
124
+ /** 列出可吸附的 App 窗口(通过 .app 身份启动 helper,输出到临时文件)。 */
125
+ router.method('float.windows', async () => {
126
+ if (process.platform !== 'darwin') throw new ApiError('unsupported', '摸鱼模式目前只支持 macOS', 400)
127
+ if (appBundlePath() === null) throw new ApiError('missing-helper', '悬浮层 App 未构建,请先运行 scripts/build-float-macos.sh', 500)
128
+ const outPath = join(tmpdir(), `gufa-float-windows-${process.pid}-${Date.now()}.json`)
129
+ try {
130
+ await openApp(['--list-windows', '--out', outPath])
131
+ const deadline = Date.now() + 10_000
132
+ let raw = ''
133
+ while (Date.now() < deadline) {
134
+ try {
135
+ raw = await readFile(outPath, 'utf8')
136
+ if (raw.trim() !== '') break
137
+ } catch {
138
+ /* 还没写出来 */
139
+ }
140
+ await new Promise((resolve) => setTimeout(resolve, 120))
141
+ }
142
+ let parsed = null
143
+ try {
144
+ parsed = JSON.parse(raw.trim())
145
+ } catch {
146
+ parsed = null
147
+ }
148
+ if (parsed === null) throw new ApiError('list-failed', '读取窗口列表失败(helper 无输出)', 500)
149
+ return parsed
150
+ } finally {
151
+ try {
152
+ await rm(outPath, { force: true })
153
+ } catch {
154
+ /* ignore */
155
+ }
73
156
  }
74
- if (parsed === null) throw new ApiError('list-failed', '读取窗口列表失败(helper 无输出)', 500)
75
- return parsed
76
157
  })
77
158
 
78
159
  router.method('float.openPrivacy', async () => {
@@ -86,71 +167,36 @@ export function register(router, env) {
86
167
  })
87
168
 
88
169
  router.method('float.start', async (body) => {
89
- if (process.platform !== 'darwin') throw new ApiError('unsupported', '桌面悬浮层目前只支持 macOS', 400)
90
- const binary = floatBinaryPath()
91
- if (binary === null) throw new ApiError('missing-helper', '悬浮层程序未构建,请先运行 scripts/build-float-macos.sh', 500)
170
+ if (process.platform !== 'darwin') throw new ApiError('unsupported', '摸鱼模式目前只支持 macOS', 400)
171
+ if (appBundlePath() === null) throw new ApiError('missing-helper', '悬浮层 App 未构建,请先运行 scripts/build-float-macos.sh', 500)
92
172
  const follow = body !== null && typeof body === 'object' && body.follow !== null && typeof body.follow === 'object'
93
173
  ? { windowNumber: Number(body.follow.windowNumber) || 0, pid: Number(body.follow.pid) || 0 }
94
174
  : null
95
175
  if (follow !== null && follow.windowNumber > 0) {
96
- /* 切换摸鱼目标:先关掉旧悬浮层再起一个新的 */
97
- if (floatRunning()) {
98
- try {
99
- floatState.child.kill('SIGTERM')
100
- } catch {
101
- /* ignore */
102
- }
103
- await new Promise((resolve) => setTimeout(resolve, 500))
104
- }
105
- } else if (floatRunning()) {
106
- return { running: true, pid: floatState.child.pid }
107
- }
108
- let webServer
109
- let connection
110
- try {
111
- webServer = ctx.get('webServer')
112
- connection = ctx.get('connection')
113
- } catch {
114
- /* ignore */
176
+ await killFloat()
177
+ } else if (await floatRunningAsync()) {
178
+ return { running: true, pid: (await listFloatPids())[0] ?? null }
115
179
  }
180
+ const webServer = ctx.get('webServer')
181
+ const connection = ctx.get('connection')
116
182
  if (webServer === undefined || webServer === null || connection === undefined || connection === null || typeof connection.authenticatedUrl !== 'function') {
117
183
  throw new ApiError('unavailable', '当前 Host 不提供 Web 服务地址,无法启动悬浮层', 500)
118
184
  }
119
185
  const base = `${webServer.protocol}//127.0.0.1:${String(webServer.port)}`
120
186
  const authUrl = connection.authenticatedUrl(`${base}/`)
121
187
  const payload = JSON.stringify({ authUrl, appUrl: `${base}/`, follow: follow !== null && follow.windowNumber > 0 ? follow : undefined })
122
- let child
123
- try {
124
- child = spawn(binary, [payload], { detached: true, stdio: 'ignore' })
125
- } catch (error) {
126
- throw new ApiError('spawn-failed', `悬浮层启动失败:${String(error && error.message || error)}`, 500)
127
- }
128
- child.unref()
129
- floatState.child = child
188
+ await openApp([payload])
189
+ await new Promise((resolve) => setTimeout(resolve, 300))
190
+ const pids = await listFloatPids()
130
191
  floatState.startedAt = Date.now()
131
- child.once('exit', () => {
132
- if (floatState.child === child) floatState.child = null
133
- })
134
- return { running: true, pid: child.pid ?? null }
192
+ return { running: pids.length > 0, pid: pids[0] ?? null }
135
193
  })
136
194
 
137
195
  router.method('float.stop', async () => {
138
- if (floatRunning()) {
139
- try {
140
- floatState.child.kill('SIGTERM')
141
- } catch {
142
- /* ignore */
143
- }
144
- }
145
- floatState.child = null
196
+ await killFloat()
146
197
  return { running: false }
147
198
  })
148
199
 
149
- router.method('dev.log', async (body) => {
150
- const message = body !== null && typeof body === 'object' && typeof body.message === 'string' ? body.message : ''
151
- if (message !== '') debugLog(message)
152
- return { ok: true }
153
- })
154
200
  router.method('dev.version', async () => ({
155
201
  name: 'dsh-gufa-code',
156
202
  version: '1.0.0',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-gufa-code",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "description": "古法编程 · AI 辅助:一键把 DSH 主面板变成 VS Code 风格 IDE(Monaco 编辑器、文件树、Git、SSH、真实终端 + 右侧官方会话);主张亲手写、每个改动心中有数,AI 是助理、你是第一责任人",
5
5
  "icon": "icon.svg",
6
6
  "keywords": [
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env bash
2
- # 构建 macOS 悬浮层 helper(P0):Objective-C + AppKit + WebKit,避免本机 Swift/SDK 版本不匹配问题。
2
+ # 构建 macOS 悬浮层 helper(P0/P1):Objective-C + AppKit + WebKit。
3
+ # 产物 1:可直接启动的二进制(Host spawn 用)
4
+ # 产物 2:.app bundle(方便用户在「屏幕录制」隐私列表里手动添加)
3
5
  set -euo pipefail
4
6
  cd "$(dirname "$0")/.."
5
7
  mkdir -p desktop/float/bin
@@ -7,5 +9,31 @@ ARCH="$(uname -m)"
7
9
  OUT="desktop/float/bin/gufa-float-macos-${ARCH}"
8
10
  clang -fobjc-arc -O2 -framework AppKit -framework WebKit -framework Carbon -o "$OUT" desktop/float/GufaFloat.m
9
11
  chmod +x "$OUT"
10
- codesign --force --sign - "$OUT" >/dev/null 2>&1 || true
12
+ # 带稳定的 code identifier 签名(TCC 按它识别,避免每次构建都换身份字符串)
13
+ codesign --force --sign - -i com.gufa.float "$OUT" >/dev/null 2>&1 || true
14
+
15
+ APP="desktop/float/古法编程悬浮层.app"
16
+ rm -rf "$APP"
17
+ mkdir -p "$APP/Contents/MacOS"
18
+ cp "$OUT" "$APP/Contents/MacOS/gufa-float"
19
+ cat > "$APP/Contents/Info.plist" <<'PLIST'
20
+ <?xml version="1.0" encoding="UTF-8"?>
21
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
22
+ <plist version="1.0">
23
+ <dict>
24
+ <key>CFBundleIdentifier</key><string>com.gufa.float</string>
25
+ <key>CFBundleName</key><string>古法编程悬浮层</string>
26
+ <key>CFBundleDisplayName</key><string>古法编程悬浮层</string>
27
+ <key>CFBundleExecutable</key><string>gufa-float</string>
28
+ <key>CFBundlePackageType</key><string>APPL</string>
29
+ <key>CFBundleShortVersionString</key><string>1.3.1</string>
30
+ <key>CFBundleVersion</key><string>1.3.1</string>
31
+ <key>LSUIElement</key><true/>
32
+ <key>NSHighResolutionCapable</key><true/>
33
+ <key>NSPrincipalClass</key><string>NSApplication</string>
34
+ </dict>
35
+ </plist>
36
+ PLIST
37
+ codesign --force --deep --sign - "$APP" >/dev/null 2>&1 || true
11
38
  echo "built: $OUT"
39
+ echo "built: $APP"
@@ -1048,6 +1048,8 @@ html[data-gufa-float] #root .gufa-overlay-root *,
1048
1048
  html[data-gufa-float] #root [data-gufa-dock] *{visibility:visible!important}
1049
1049
  /* 桌宠提到覆盖层之上:同时兼容 @linxin666/dsh-pet(data-dsh-pet-root)与官方 dsh-pet(.dsh-pet-root) */
1050
1050
  html[data-gufa-ide] .dsh-pet-root{z-index:2147483400!important}
1051
+ /* 古法自己的弹窗/菜单打开时:整个覆盖层临时抬到右侧停靠会话(z-index 2147483040)之上 */
1052
+ html[data-gufa-popup] .gufa-overlay-root{z-index:2147483300!important}
1051
1053
  /* 外部弹窗(DSH 设置等)打开时:停靠会话与桌宠降到弹窗之下,保证弹窗完整可点可关 */
1052
1054
  html[data-gufa-external-modal] [data-gufa-dock]{z-index:2!important}
1053
1055
  html[data-gufa-external-modal] .dsh-pet-root{z-index:2!important}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * 59-popup-layer:弹窗/菜单层级修正。
3
+ *
4
+ * 背景(踩坑记录,见 docs/KNOWN-PITFALLS.md):
5
+ * 古法编程的界面都在 `.gufa-overlay-root`(z-index:1)这个层叠上下文里,而右侧停靠的
6
+ * 官方会话根节点是 body 级 fixed、z-index 2147483040。任何在 root 内部弹出的
7
+ * modal / menu / popover,如果只设自己的 z-index,都会被困在 root 的上下文里,
8
+ * 被停靠会话盖住(表现为「弹窗被右侧聊天挡一半、点不到关闭」)。
9
+ *
10
+ * 修法:检测 root 内是否出现 popup,出现时给 html 加 `data-gufa-popup`,
11
+ * 由 CSS 把整个 overlay root 临时抬到停靠会话之上。
12
+ */
13
+
14
+ G.installPopupLayerWatch = function installPopupLayerWatch(ctx) {
15
+ if (typeof document === 'undefined') return () => {}
16
+ const ATTR = 'data-gufa-popup'
17
+ const SELECTOR = [
18
+ '[role="menu"]',
19
+ '[role="listbox"]',
20
+ '[role="dialog"]',
21
+ '.gufa-modal',
22
+ '.gufa-float-backdrop',
23
+ '.gufa-branch-dialog-backdrop',
24
+ '.gufa-session-backdrop',
25
+ '.gufa-shortcuts-backdrop',
26
+ ].join(',')
27
+
28
+ const sync = () => {
29
+ try {
30
+ const root = document.querySelector('.gufa-root')
31
+ const popup = root === null ? null : root.querySelector(SELECTOR)
32
+ const open = popup !== null
33
+ if ((document.documentElement.getAttribute(ATTR) === '1') === open) return
34
+ if (open) document.documentElement.setAttribute(ATTR, '1')
35
+ else document.documentElement.removeAttribute(ATTR)
36
+ } catch {
37
+ /* ignore */
38
+ }
39
+ }
40
+
41
+ let observer = null
42
+ try {
43
+ observer = new MutationObserver(sync)
44
+ observer.observe(document.documentElement, { childList: true, subtree: true, attributes: true, attributeFilter: ['class', 'style', 'data-state', 'aria-hidden'] })
45
+ } catch {
46
+ observer = null
47
+ }
48
+ sync()
49
+ const timer = window.setInterval(sync, 400)
50
+ return () => {
51
+ if (observer !== null) observer.disconnect()
52
+ window.clearInterval(timer)
53
+ document.documentElement.removeAttribute(ATTR)
54
+ }
55
+ }
@@ -2164,11 +2164,12 @@ G.GufaApp = function GufaApp(props) {
2164
2164
  'div',
2165
2165
  { className: 'gufa-float-permission' },
2166
2166
  h('div', { className: 'gufa-float-permission-title' }, '需要「屏幕录制」权限'),
2167
- h('div', { className: 'gufa-hint' }, '摸鱼模式需要读取其他 App 窗口的尺寸(只读尺寸,不录屏)。请在「系统设置 → 隐私与安全性 → 屏幕录制」里允许 DeepSeek Harness / gufa-float,然后点重试。'),
2167
+ h('div', { className: 'gufa-hint' }, '摸鱼列表需要读取其他 App 的窗口尺寸(只读尺寸,不录屏)。系统只认悬浮层 App 自己的授权:请在「系统设置 → 隐私与安全性 → 屏幕录制」里点左下角「+」,添加「古法编程悬浮层.app」并打开开关(DeepSeek Harness 的开关也保持打开)。加好后点「重试」。'),
2168
2168
  h(
2169
2169
  'div',
2170
- { className: 'gufa-row', style: { gap: 8, marginTop: 12 } },
2170
+ { className: 'gufa-row', style: { gap: 8, marginTop: 12, flexWrap: 'wrap' } },
2171
2171
  h(G.Button, { primary: true, onClick: () => void G.api('float.openPrivacy').catch(() => {}) }, '打开系统设置'),
2172
+ h(G.Button, { onClick: () => void G.api('float.revealHelper').catch(() => {}) }, '在 Finder 中显示悬浮层 App'),
2172
2173
  h(G.Button, { onClick: () => void openFloatPicker() }, '重试'),
2173
2174
  ),
2174
2175
  )
@@ -256,6 +256,16 @@ const GUFA_PLUGIN = {
256
256
  window.setTimeout(cleanStaleSidebarLayouts, 1500)
257
257
  window.setTimeout(cleanStaleSidebarLayouts, 5000)
258
258
 
259
+ // 弹窗/菜单打开时把覆盖层整体抬到右侧停靠会话之上(否则会被盖住)
260
+ try {
261
+ if (typeof G.installPopupLayerWatch === 'function') {
262
+ const disposePopupWatch = G.installPopupLayerWatch(ctx)
263
+ if (typeof disposePopupWatch === 'function') ctx.effect(() => disposePopupWatch, 'gufa-code: popup layer watch')
264
+ }
265
+ } catch (error) {
266
+ console.error('[gufa-code] 安装弹窗层级监听失败', error)
267
+ }
268
+
259
269
  // 外部弹窗(设置等)打开时降低停靠层,避免遮挡弹窗导致关不掉
260
270
  try {
261
271
  if (typeof G.installDialogLayerWatch === 'function') {