dsh-gufa-code 1.3.0 → 1.3.1

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,7 +11521,7 @@ 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 的窗口尺寸(只读尺寸,不录屏)。请在「系统设置 → 隐私与安全性 → 屏幕录制」里勾选 **DeepSeek Harness**(若列表只显示自己,请重启一次 DeepSeek Harness 让权限生效),然后点「重试」。'),
11465
11525
  h(
11466
11526
  'div',
11467
11527
  { className: 'gufa-row', style: { gap: 8, marginTop: 12 } },
@@ -12132,6 +12192,16 @@ const GUFA_PLUGIN = {
12132
12192
  window.setTimeout(cleanStaleSidebarLayouts, 1500)
12133
12193
  window.setTimeout(cleanStaleSidebarLayouts, 5000)
12134
12194
 
12195
+ // 弹窗/菜单打开时把覆盖层整体抬到右侧停靠会话之上(否则会被盖住)
12196
+ try {
12197
+ if (typeof G.installPopupLayerWatch === 'function') {
12198
+ const disposePopupWatch = G.installPopupLayerWatch(ctx)
12199
+ if (typeof disposePopupWatch === 'function') ctx.effect(() => disposePopupWatch, 'gufa-code: popup layer watch')
12200
+ }
12201
+ } catch (error) {
12202
+ console.error('[gufa-code] 安装弹窗层级监听失败', error)
12203
+ }
12204
+
12135
12205
  // 外部弹窗(设置等)打开时降低停靠层,避免遮挡弹窗导致关不掉
12136
12206
  try {
12137
12207
  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,23 +530,32 @@ 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 void GufaPrintPermissionResult(void) {
534
+ NSDictionary *out = @{@"ok": @NO, @"permission": @"screen-recording"};
535
+ NSData *json = [NSJSONSerialization dataWithJSONObject:out options:0 error:NULL];
536
+ if (json != nil) fwrite(json.bytes, 1, json.length, stdout);
537
+ fputc('\n', stdout);
538
+ }
539
+
540
+ /** 没权限时 CGWindowList 只返回「自己这个 App」的窗口;据此判断权限,而不是信 CGPreflight。 */
541
+ static BOOL GufaRowsHaveForeignWindows(NSArray<NSDictionary *> *rows) {
542
+ NSString *own = NSProcessInfo.processInfo.processName;
543
+ for (NSDictionary *row in rows) {
544
+ NSString *owner = row[@"owner"];
545
+ if ([owner isKindOfClass:[NSString class]] && owner.length > 0
546
+ && ![owner isEqualToString:@"DeepSeek Harness"] && ![owner isEqualToString:own]) {
547
+ return YES;
548
+ }
546
549
  }
550
+ return NO;
551
+ }
552
+
553
+ static int GufaListWindowsMode(void) {
547
554
  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);
555
+ if (rows.count == 0 || !GufaRowsHaveForeignWindows(rows)) {
556
+ /* 触发一次系统授权提示(授权后重新点「重试」即可) */
557
+ CGRequestScreenCaptureAccess();
558
+ GufaPrintPermissionResult();
554
559
  return 2;
555
560
  }
556
561
  NSDictionary *out = @{@"ok": @YES, @"windows": rows};
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-gufa-code",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "古法编程 · AI 辅助:一键把 DSH 主面板变成 VS Code 风格 IDE(Monaco 编辑器、文件树、Git、SSH、真实终端 + 右侧官方会话);主张亲手写、每个改动心中有数,AI 是助理、你是第一责任人",
5
5
  "icon": "icon.svg",
6
6
  "keywords": [
@@ -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,7 +2164,7 @@ 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 的窗口尺寸(只读尺寸,不录屏)。请在「系统设置 → 隐私与安全性 → 屏幕录制」里勾选 **DeepSeek Harness**(若列表只显示自己,请重启一次 DeepSeek Harness 让权限生效),然后点「重试」。'),
2168
2168
  h(
2169
2169
  'div',
2170
2170
  { className: 'gufa-row', style: { gap: 8, marginTop: 12 } },
@@ -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') {