dsh-gufa-code 1.3.95 → 1.3.97

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
@@ -44,6 +44,7 @@ dsh plugin add dsh-gufa-code
44
44
  - **Copilot 风格 Tab 行内补全**:光标停/打字后,基于 Harness 自己的 DeepSeek 模型(默认 `deepseek-flash`,不需要额外 Copilot 订阅)流式生成灰色 ghost text,Tab 接受、Esc 忽略;支持 JS/TS/Python/Java/Go/Rust/C++/C#/JSON/YAML/Shell 等常见语言;
45
45
  - 保存走磁盘版本冲突检测 + 原子写;未保存标记;
46
46
  - **⌘/Ctrl + 点击跳转定义 / 方法实现**:Python 走 **Pyright 语言服务(LSP)**,JS/TS 走 Monaco 内置 TypeScript 语言服务(点击前会按需把当前文件的 import 依赖加载进 Monaco,跨文件变量/函数由 TS 语言服务解析);其他语言暂用项目级定义搜索兜底;优先走 Monaco 语言服务;目标文件没在 Monaco 里打开、或语言没有内置语言服务时,自动用项目级定义搜索兜底(函数 / 类 / 方法 / const / type 等声明)。兜底会解析 import/require 直接定位来源文件,并跳过压缩产物/大文件;同一个文件里的声明、import 命中的定义、目录距离近的定义直接跳,只有多个真正同名的声明才弹「跳转到定义」列表,点同名属性/变量时不会拿远端无关的 const 来凑数;按住 ⌘/Ctrl 悬停时,可跳转的符号会显示下划线 + 手型光标;
47
+ - **⌘⇧N 新开实例窗口**:用古法编程自带原生 helper 打开一个普通 Harness 窗口(同一 Web GUI、共享登录态);macOS 已支持,Windows/Linux 待 helper 实现 full 模式;
47
48
  - **全局搜索 / 替换**(左栏放大镜 / `⌘⇧F`):整个项目的文本搜索,支持区分大小写、正则、包含/排除文件(glob);结果按文件分组、高亮匹配,点击跳转行列;替换栏支持保留大小写(AB)、全部替换(需确认)、按文件替换(悬停文件头铅笔)、按单行匹配替换与忽略(悬停结果行);替换前会自动保存未落盘的编辑器内容;Git 项目用 `git ls-files` 枚举文件(尊重 `.gitignore`、含未跟踪文件),非 Git 项目遍历目录并自动跳过 `node_modules` 等依赖/缓存目录;摸鱼悬浮窗里同样可用;
48
49
  - 资源管理器文件/文件夹可直接**拖进右侧输入框**变成 @引用;
49
50
  - 资源管理器右键:新建 / 重命名 / 删除 / 复制 / 粘贴 / 打开所在文件夹 / 两文件对比;
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.95'
19
+ G.BUILD = '1.3.97'
20
20
  G.PANEL_ID = 'gufa-code'
21
21
  /** 从哪个工作区点进来的(工作区菜单/节点按钮写入,App 启动时消费)。 */
22
22
  G.pendingEntryWorkspace = null
@@ -119,6 +119,7 @@ const DICT_ZH = {
119
119
  'shortcuts.toggleTerminal': '显示 / 隐藏终端',
120
120
  'shortcuts.toggleSidebar': '显示 / 隐藏左侧栏',
121
121
  'shortcuts.closeTab': '关闭当前标签页',
122
+ 'shortcuts.newWindow': '新建一个实例窗口',
122
123
  'shortcuts.explorer': '聚焦资源管理器',
123
124
  'shortcuts.search': '聚焦全局搜索',
124
125
  'shortcuts.git': '聚焦源代码管理',
@@ -376,6 +377,7 @@ const DICT_EN = {
376
377
  'shortcuts.toggleTerminal': 'Toggle terminal panel',
377
378
  'shortcuts.toggleSidebar': 'Toggle sidebar',
378
379
  'shortcuts.closeTab': 'Close current tab',
380
+ 'shortcuts.newWindow': 'New window',
379
381
  'shortcuts.explorer': 'Focus explorer',
380
382
  'shortcuts.search': 'Focus search',
381
383
  'shortcuts.git': 'Focus source control',
@@ -11360,6 +11362,7 @@ G.shortcutAction = function shortcutAction(event) {
11360
11362
  if (key === 'h' || key === 'u') return 'panelSsh'
11361
11363
  if (key === 'b') return 'toggleSidebar'
11362
11364
  if (key === 'w') return 'closeTab'
11365
+ if (key === 'n') return 'newWindow'
11363
11366
  if (isBackquote) return 'newTerminal'
11364
11367
  if (key === '/' || key === '?') return 'shortcuts'
11365
11368
  if (key === 'enter' || code === 'Enter' || code === 'NumpadEnter') return 'commit'
@@ -11790,6 +11793,7 @@ G.SHORTCUTS = [
11790
11793
  { action: 'toggleTerminal', labelKey: 'shortcuts.toggleTerminal', keys: ['J'], shift: false, macText: '⌘J / ⌃`', otherText: 'Ctrl+J / Ctrl+`' },
11791
11794
  { action: 'toggleSidebar', labelKey: 'shortcuts.toggleSidebar', keys: ['B'], shift: false },
11792
11795
  { action: 'closeTab', labelKey: 'shortcuts.closeTab', keys: ['W'], shift: false },
11796
+ { action: 'newWindow', labelKey: 'shortcuts.newWindow', keys: ['N'], shift: true },
11793
11797
  { action: 'panelExplorer', labelKey: 'shortcuts.explorer', keys: ['E'], shift: true },
11794
11798
  { action: 'panelSearch', labelKey: 'shortcuts.search', keys: ['F'], shift: true },
11795
11799
  { action: 'panelGit', labelKey: 'shortcuts.git', keys: ['G'], shift: true },
@@ -13944,6 +13948,19 @@ G.GufaApp = function GufaApp(props) {
13944
13948
  const next = tabs[(index - 1 + tabs.length) % tabs.length]
13945
13949
  if (next !== undefined) setActivePath(next.path)
13946
13950
  },
13951
+ newWindow: () => {
13952
+ /* Host 用古法编程原生 helper 开一个普通窗口,加载同一个 Web GUI;
13953
+ helper 缺失/平台不支持时回退到浏览器新窗口。 */
13954
+ void G.api('app.newWindow', {}).catch((error) => {
13955
+ let opened = null
13956
+ try { opened = window.open(location.href, '_blank') } catch { opened = null }
13957
+ if (opened !== null && opened !== undefined) {
13958
+ try { opened.focus() } catch { /* ignore */ }
13959
+ return
13960
+ }
13961
+ try { G.refToast(`打开新窗口失败:${G.errorText(error)}`, 'err') } catch { /* ignore */ }
13962
+ })
13963
+ },
13947
13964
  shortcutsDialog: () => setShortcutsOpen((open) => open === false),
13948
13965
  shortcuts: () => {
13949
13966
  // 编辑器内 ⌘/ 是「切换行注释」(VS Code 一致),其他位置才打开快捷键列表
@@ -135,6 +135,7 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
135
135
  @property (nonatomic, strong) NSDictionary *options;
136
136
  @property (nonatomic, assign) EventHotKeyRef hotKeyRef;
137
137
  @property (nonatomic, assign) BOOL following;
138
+ @property (nonatomic, assign) BOOL fullMode;
138
139
  @property (nonatomic, assign) pid_t followPid;
139
140
  @property (nonatomic, copy) NSString *followTitle;
140
141
  @property (nonatomic, assign) AXUIElementRef followWindowRef;
@@ -178,6 +179,11 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
178
179
  self.frameKey = @"gufa-float-frame-v1";
179
180
  self.clickThrough = NO;
180
181
  [self parseOptions];
182
+ self.fullMode = [self.options[@"full"] boolValue];
183
+ if (self.fullMode) {
184
+ self.frameKey = @"gufa-instance-frame-v1";
185
+ [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
186
+ }
181
187
  if ([self.options[@"controlPath"] isKindOfClass:[NSString class]]) self.controlPath = self.options[@"controlPath"];
182
188
  [self watchControlFile];
183
189
  /* 先激活目标 App:等它切到自己的 Space/全屏 Space 后再创建悬浮窗,
@@ -190,13 +196,15 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
190
196
  __strong typeof(weakSelf) self = weakSelf;
191
197
  if (self == nil) return;
192
198
  [self buildWindow];
193
- [self buildStatusItem];
194
- [self registerToggleHotKey];
195
- /* 摸鱼:等目标 App 到前台后隐藏 DSH 主窗口(⌘H 效果) */
196
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.45 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
197
- GufaSetMainAppHidden(YES);
198
- });
199
- [self beginningFollowFromOptions];
199
+ if (!self.fullMode) {
200
+ [self buildStatusItem];
201
+ [self registerToggleHotKey];
202
+ /* 摸鱼:等目标 App 到前台后隐藏 DSH 主窗口(⌘H 效果) */
203
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.45 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
204
+ GufaSetMainAppHidden(YES);
205
+ });
206
+ [self beginningFollowFromOptions];
207
+ }
200
208
  [self loadWebContent];
201
209
  });
202
210
  }
@@ -350,21 +358,23 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
350
358
  }
351
359
  }
352
360
 
361
+ NSWindowStyleMask styleMask = self.fullMode
362
+ ? (NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable)
363
+ : (NSWindowStyleMaskBorderless | NSWindowStyleMaskResizable);
353
364
  self.window = [[GufaFloatWindow alloc] initWithContentRect:frame
354
- styleMask:(NSWindowStyleMaskBorderless | NSWindowStyleMaskResizable)
365
+ styleMask:styleMask
355
366
  backing:NSBackingStoreBuffered
356
367
  defer:NO];
357
- self.window.opaque = NO;
358
- self.window.backgroundColor = NSColor.clearColor;
368
+ self.window.opaque = self.fullMode ? YES : NO;
369
+ self.window.backgroundColor = self.fullMode ? [NSColor colorWithCalibratedRed:0.07 green:0.07 blue:0.08 alpha:1.0] : NSColor.clearColor;
359
370
  self.window.hasShadow = YES;
360
- /* 高于普通浮动窗口(歌词、置顶小工具等),确保真正盖住被跟随的 App */
361
- self.window.level = NSStatusWindowLevel;
371
+ self.window.level = self.fullMode ? NSNormalWindowLevel : NSStatusWindowLevel;
362
372
  /* 固定吸附:默认不加入所有 Space(否则用户滑动切屏时摸鱼窗会跟着跑到当前屏);
363
373
  只有「自由悬浮」模式才允许出现在所有 Space。 */
364
- self.window.collectionBehavior = (NSWindowCollectionBehaviorFullScreenAuxiliary
365
- | NSWindowCollectionBehaviorIgnoresCycle);
374
+ self.window.collectionBehavior = self.fullMode ? NSWindowCollectionBehaviorDefault
375
+ : (NSWindowCollectionBehaviorFullScreenAuxiliary | NSWindowCollectionBehaviorIgnoresCycle);
366
376
  self.window.minSize = NSMakeSize(520, 360);
367
- self.window.title = @"古法编程悬浮层";
377
+ self.window.title = self.fullMode ? @"DeepSeek Harness" : @"古法编程悬浮层";
368
378
 
369
379
  NSView *container = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, frame.size.width, frame.size.height)];
370
380
  container.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
@@ -374,7 +384,7 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
374
384
  config.websiteDataStore = [WKWebsiteDataStore defaultDataStore];
375
385
  /* 文档开始前注入:悬浮模式标记 + 主窗口状态(项目/UI 布局/打开的标签页/会话),
376
386
  让悬浮窗里的古法编程「接着主窗口继续干活」,而不是一个空白的新实例。 */
377
- NSMutableString *bootstrap = [NSMutableString stringWithString:@"try{localStorage.setItem('gufa-code:float','1');"];
387
+ NSMutableString *bootstrap = self.fullMode ? [NSMutableString string] : [NSMutableString stringWithString:@"try{localStorage.setItem('gufa-code:float','1');"];
378
388
  NSDictionary *state = [self.options[@"state"] isKindOfClass:[NSDictionary class]] ? self.options[@"state"] : nil;
379
389
  if (state != nil) {
380
390
  NSData *stateJson = [NSJSONSerialization dataWithJSONObject:state options:0 error:NULL];
@@ -403,11 +413,13 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
403
413
  }
404
414
  }
405
415
  }
406
- [bootstrap appendString:@"}catch(e){}"];
407
- WKUserScript *floatMarker = [[WKUserScript alloc] initWithSource:bootstrap
408
- injectionTime:WKUserScriptInjectionTimeAtDocumentStart
409
- forMainFrameOnly:YES];
410
- [config.userContentController addUserScript:floatMarker];
416
+ if (!self.fullMode) {
417
+ [bootstrap appendString:@"}catch(e){}"];
418
+ WKUserScript *floatMarker = [[WKUserScript alloc] initWithSource:bootstrap
419
+ injectionTime:WKUserScriptInjectionTimeAtDocumentStart
420
+ forMainFrameOnly:YES];
421
+ [config.userContentController addUserScript:floatMarker];
422
+ }
411
423
  self.webView = [[WKWebView alloc] initWithFrame:container.bounds configuration:config];
412
424
  self.webView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
413
425
  self.navigation = [[GufaNavigationDelegate alloc] init];
@@ -416,12 +428,14 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
416
428
  [self.webView setValue:@NO forKey:@"drawsBackground"];
417
429
  [container addSubview:self.webView];
418
430
 
419
- CGFloat stripHeight = 22.0;
420
- GufaDragStrip *strip = [[GufaDragStrip alloc] initWithFrame:NSMakeRect(0, frame.size.height - stripHeight, frame.size.width, stripHeight)];
421
- strip.autoresizingMask = NSViewWidthSizable | NSViewMinYMargin;
422
- strip.menu = self.mainMenu;
423
- [container addSubview:strip];
424
- self.dragStrip = strip;
431
+ if (!self.fullMode) {
432
+ CGFloat stripHeight = 22.0;
433
+ GufaDragStrip *strip = [[GufaDragStrip alloc] initWithFrame:NSMakeRect(0, frame.size.height - stripHeight, frame.size.width, stripHeight)];
434
+ strip.autoresizingMask = NSViewWidthSizable | NSViewMinYMargin;
435
+ strip.menu = self.mainMenu;
436
+ [container addSubview:strip];
437
+ self.dragStrip = strip;
438
+ }
425
439
 
426
440
  self.window.contentView = container;
427
441
  if (self.window.frame.size.width < 400 || self.window.frame.size.height < 300) {
@@ -472,6 +486,10 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
472
486
  self.navigation.pendingLoad = ^{
473
487
  __strong typeof(weakSelf) self = weakSelf;
474
488
  if (self == nil) return;
489
+ if (self.fullMode) {
490
+ [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:appUrl ?: @""]]];
491
+ return;
492
+ }
475
493
  /* 鉴权 cookie 已在 token URL 重定向时写入;这里用 JS 写 localStorage(避开 URL 长度/转义问题),
476
494
  再跳到带 gufa-float 标记的干净地址,客户端据此自动进入摸鱼模式并恢复状态。 */
477
495
  NSMutableString *js = [NSMutableString stringWithString:@"try{"];
@@ -529,9 +547,9 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
529
547
  NSString *build = [self.options[@"build"] isKindOfClass:[NSString class]] ? self.options[@"build"] : @"";
530
548
  NSString *lastBuild = [[NSUserDefaults standardUserDefaults] stringForKey:@"gufa-float-build"];
531
549
  BOOL versionChanged = build.length == 0 || lastBuild == nil || ![lastBuild isEqualToString:build];
532
- NSSet<NSString *> *types = versionChanged
533
- ? [WKWebsiteDataStore allWebsiteDataTypes]
534
- : [NSSet setWithObjects:WKWebsiteDataTypeMemoryCache, nil];
550
+ NSSet<NSString *> *types = self.fullMode
551
+ ? [NSSet setWithObjects:WKWebsiteDataTypeMemoryCache, nil]
552
+ : (versionChanged ? [WKWebsiteDataStore allWebsiteDataTypes] : [NSSet setWithObjects:WKWebsiteDataTypeMemoryCache, nil]);
535
553
  [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:types modifiedSince:[NSDate dateWithTimeIntervalSince1970:0] completionHandler:^{
536
554
  if (build.length > 0) [[NSUserDefaults standardUserDefaults] setObject:build forKey:@"gufa-float-build"];
537
555
  dispatch_async(dispatch_get_main_queue(), ^{
@@ -559,6 +577,10 @@ static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef even
559
577
  if (httpCookie != nil) {
560
578
  WKHTTPCookieStore *store = [WKWebsiteDataStore defaultDataStore].httpCookieStore;
561
579
  [store setCookie:httpCookie completionHandler:^{
580
+ if (self.fullMode) {
581
+ [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.options[@"appUrl"] ?: @""]]];
582
+ return;
583
+ }
562
584
  NSURLComponents *components = [NSURLComponents componentsWithString:self.options[@"appUrl"] ?: @""];
563
585
  components.queryItems = @[[NSURLQueryItem queryItemWithName:@"gufa-float" value:@"1"]];
564
586
  [self.webView loadRequest:[NSURLRequest requestWithURL:components.URL]];
@@ -1129,8 +1151,14 @@ int main(int argc, const char *argv[]) {
1129
1151
  }
1130
1152
  }
1131
1153
  @autoreleasepool {
1154
+ BOOL fullWindow = NO;
1155
+ if (argc > 1 && argc < 3) {
1156
+ NSData *payloadData = [[NSString stringWithUTF8String:argv[1]] dataUsingEncoding:NSUTF8StringEncoding];
1157
+ id parsed = payloadData != nil ? [NSJSONSerialization JSONObjectWithData:payloadData options:0 error:NULL] : nil;
1158
+ if ([parsed isKindOfClass:[NSDictionary class]]) fullWindow = [parsed[@"full"] boolValue];
1159
+ }
1132
1160
  [NSApplication sharedApplication];
1133
- [NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory];
1161
+ [NSApp setActivationPolicy:fullWindow ? NSApplicationActivationPolicyRegular : NSApplicationActivationPolicyAccessory];
1134
1162
  GufaInstallEditMenu();
1135
1163
  GufaInstallTermHandler();
1136
1164
  GufaAppDelegate *delegate = [[GufaAppDelegate alloc] init];
@@ -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.95</string>
11
- <key>CFBundleVersion</key><string>1.3.95</string>
10
+ <key>CFBundleShortVersionString</key><string>1.3.97</string>
11
+ <key>CFBundleVersion</key><string>1.3.97</string>
12
12
  <key>LSUIElement</key><true/>
13
13
  <key>NSHighResolutionCapable</key><true/>
14
14
  <key>NSPrincipalClass</key><string>NSApplication</string>
@@ -53,6 +53,13 @@
53
53
  - 有多个语言共享扩展名(`.p` Pascal、`.m` Objective-C、`.v` Verilog、`.cls` Apex、`.pp` Ruby/Pascal、`.s` MIPS、`.config` XML 等)时,按 Monaco 默认取一个;用户项目里如果扩展名含义不同,改 `LANG_BY_EXT` 一行即可。
54
54
  - 点开头文件(`.babelrc/.eslintrc/.jshintrc/.jscsrc/.bowerrc` → json、`.gitconfig` → ini、`.rprofile` → r)要在 `languageOf` 的 `lastIndexOf('.')` 之前特判,否则会被当成 plaintext。
55
55
 
56
+ ## 0.11 ⌘⇧N 新实例窗口(1.3.97)
57
+
58
+ - Electron 桌面壳是单实例应用(`requestSingleInstanceLock`),且只有 Electron main 能 `new BrowserWindow`;插件 Host 跑在独立的 Node 模式进程里,**没有 electron 模块**(`import('electron')` 会解析到 npm 包而不是内建模块),不能在 Host 里开原生 BrowserWindow。
59
+ - 实现:复用插件自带的原生 helper(`desktop/float/GufaFloat.m`),payload 传 `{full:true, authUrl, appUrl}` —— helper 建普通标题栏窗口、Regular 激活策略、跳过摸鱼 localStorage/隐藏主窗/吸附,加载同一个 DSH Web GUI;鉴权复用它已有的 `connection.authenticatedUrl()` token 流程。
60
+ - 客户端 ⌘⇧N 必须先调 Host `app.newWindow`,失败才回退 `window.open`(Electron 的 setWindowOpenHandler 会 deny 并用外部浏览器打开 http(s),不是应用内窗口)。
61
+ - 新窗口与 Electron 主窗口共享的是 **同一个 Host/服务端**,但 UI 进程独立(WKWebView,不走 Electron preload);所以别让新窗口依赖 `window.dshDesktop` 之类的 Electron preload API。
62
+
56
63
  ## 1. 弹窗/菜单层级:只有一个正确做法(反复踩过多次,最终定案)
57
64
 
58
65
  **现象**:弹窗被右侧「古法 AI」聊天栏压住、只显示一半、关闭按钮点不到;或者反过来把官方设置/会话弹窗盖住。
@@ -0,0 +1,75 @@
1
+ /**
2
+ * ⌘⇧N:新开一个 Harness 实例窗口。
3
+ *
4
+ * 桌面壳是 Electron 单实例应用,且主窗口只有 dsh-desktop-host 的 Node 进程可以管理;
5
+ * 插件 Host 运行在独立 Node 进程里,没法直接 new BrowserWindow。这里复用古法编程
6
+ * 自带的原生 helper(desktop/float,跨平台 WKWebView/WebView2/WebKit2GTK),给它传
7
+ * `{ full: true }` 就打开一个普通窗口,加载同一个 DSH Web GUI(用 connection 签发的
8
+ * 一次性鉴权 URL,和摸鱼悬浮层同一套登录逻辑)。
9
+ */
10
+ import { spawn } from 'node:child_process'
11
+ import { existsSync, readFileSync } from 'node:fs'
12
+ import { dirname, join } from 'node:path'
13
+ import { fileURLToPath } from 'node:url'
14
+
15
+ import { ApiError } from './context.js'
16
+ import { floatBinaryCandidates } from './float-platform.js'
17
+
18
+ const PLUGIN_ROOT = join(dirname(fileURLToPath(import.meta.url)), '..')
19
+
20
+ const PLUGIN_VERSION = (() => {
21
+ try {
22
+ const pkg = JSON.parse(readFileSync(join(PLUGIN_ROOT, 'package.json'), 'utf8'))
23
+ return typeof pkg.version === 'string' ? pkg.version : 'dev'
24
+ } catch {
25
+ return 'dev'
26
+ }
27
+ })()
28
+
29
+ function floatBinaryPath() {
30
+ const root = join(PLUGIN_ROOT, 'desktop', 'float', 'bin')
31
+ for (const full of floatBinaryCandidates(process.platform, process.arch, root)) {
32
+ if (existsSync(full)) return full
33
+ }
34
+ return null
35
+ }
36
+
37
+ export async function newWindow(body, env) {
38
+ if (process.platform !== 'darwin') {
39
+ throw new ApiError('unsupported-platform', '实例窗口目前只支持 macOS(Windows/Linux helper 尚未实现 full 模式)', 501)
40
+ }
41
+ const binary = floatBinaryPath()
42
+ if (binary === null) throw new ApiError('missing-helper', '实例窗口 helper 未构建(desktop/float/bin)', 500)
43
+ const webServer = env.ctx.get('webServer')
44
+ const connection = env.ctx.get('connection')
45
+ if (webServer === undefined || webServer === null || connection === undefined || connection === null || typeof connection.authenticatedUrl !== 'function') {
46
+ throw new ApiError('unavailable', '当前 Host 不提供 Web 服务地址,无法打开实例窗口', 500)
47
+ }
48
+ const base = `${webServer.protocol}//127.0.0.1:${String(webServer.port)}`
49
+ const authUrl = connection.authenticatedUrl(`${base}/`)
50
+ const payload = JSON.stringify({
51
+ full: true,
52
+ authUrl,
53
+ appUrl: `${base}/`,
54
+ title: 'DeepSeek Harness',
55
+ build: PLUGIN_VERSION,
56
+ ownerPid: process.ppid,
57
+ })
58
+ try {
59
+ const child = spawn(binary, [payload], {
60
+ detached: true,
61
+ stdio: 'ignore',
62
+ windowsHide: false,
63
+ env: { ...process.env, GUFA_FLOAT_PAYLOAD: payload },
64
+ })
65
+ child.unref()
66
+ void body
67
+ return { ok: true, pid: child.pid ?? null }
68
+ } catch (error) {
69
+ throw new ApiError('new-window-failed', `打开实例窗口失败:${String(error?.message ?? error)}`, 500)
70
+ }
71
+ }
72
+
73
+ export function registerAppWindow(router, env) {
74
+ router.method('app.newWindow', (body) => newWindow(body, env))
75
+ }
package/host/fs.js CHANGED
@@ -289,6 +289,19 @@ export function register(router, env) {
289
289
  /* Tab 行内补全:借用 Harness 自己的模型服务 */
290
290
  registerCompletion(router, env)
291
291
 
292
+ /* ⌘⇧N:打开新的 Harness 实例窗口(Electron 单实例下新建 BrowserWindow)。
293
+ app-window.js 用带 mtime 的动态 import,改它不必重启 Host。 */
294
+ router.method('app.newWindow', async (body) => {
295
+ let stamp = '0'
296
+ try {
297
+ stamp = String(statSync(new URL('./app-window.js', import.meta.url)).mtimeMs)
298
+ } catch {
299
+ stamp = '0'
300
+ }
301
+ const module = await import(new URL(`./app-window.js?gufa-app-window=${stamp}`, import.meta.url).href)
302
+ return module.newWindow(body, env)
303
+ })
304
+
292
305
  /* 代码导航(Cmd+点击跳定义):实现放在 code.js,但 Host 热重载只按 host/*.js 的 mtime
293
306
  触发,因此这里用带 mtime 的 query 动态 import,code.js 改动后下一次请求就能热生效。 */
294
307
  router.method('code.definition', async (body) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-gufa-code",
3
- "version": "1.3.95",
3
+ "version": "1.3.97",
4
4
  "description": "古法编程 · AI 辅助:一键把 DSH 主面板变成 VS Code 风格 IDE(Monaco 编辑器、文件树、Git、SSH、真实终端 + 右侧官方会话);主张亲手写、每个改动心中有数,AI 是助理、你是第一责任人",
5
5
  "icon": "icon.svg",
6
6
  "keywords": [
@@ -111,6 +111,7 @@ const DICT_ZH = {
111
111
  'shortcuts.toggleTerminal': '显示 / 隐藏终端',
112
112
  'shortcuts.toggleSidebar': '显示 / 隐藏左侧栏',
113
113
  'shortcuts.closeTab': '关闭当前标签页',
114
+ 'shortcuts.newWindow': '新建一个实例窗口',
114
115
  'shortcuts.explorer': '聚焦资源管理器',
115
116
  'shortcuts.search': '聚焦全局搜索',
116
117
  'shortcuts.git': '聚焦源代码管理',
@@ -368,6 +369,7 @@ const DICT_EN = {
368
369
  'shortcuts.toggleTerminal': 'Toggle terminal panel',
369
370
  'shortcuts.toggleSidebar': 'Toggle sidebar',
370
371
  'shortcuts.closeTab': 'Close current tab',
372
+ 'shortcuts.newWindow': 'New window',
371
373
  'shortcuts.explorer': 'Focus explorer',
372
374
  'shortcuts.search': 'Focus search',
373
375
  'shortcuts.git': 'Focus source control',
@@ -51,6 +51,7 @@ G.shortcutAction = function shortcutAction(event) {
51
51
  if (key === 'h' || key === 'u') return 'panelSsh'
52
52
  if (key === 'b') return 'toggleSidebar'
53
53
  if (key === 'w') return 'closeTab'
54
+ if (key === 'n') return 'newWindow'
54
55
  if (isBackquote) return 'newTerminal'
55
56
  if (key === '/' || key === '?') return 'shortcuts'
56
57
  if (key === 'enter' || code === 'Enter' || code === 'NumpadEnter') return 'commit'
@@ -481,6 +482,7 @@ G.SHORTCUTS = [
481
482
  { action: 'toggleTerminal', labelKey: 'shortcuts.toggleTerminal', keys: ['J'], shift: false, macText: '⌘J / ⌃`', otherText: 'Ctrl+J / Ctrl+`' },
482
483
  { action: 'toggleSidebar', labelKey: 'shortcuts.toggleSidebar', keys: ['B'], shift: false },
483
484
  { action: 'closeTab', labelKey: 'shortcuts.closeTab', keys: ['W'], shift: false },
485
+ { action: 'newWindow', labelKey: 'shortcuts.newWindow', keys: ['N'], shift: true },
484
486
  { action: 'panelExplorer', labelKey: 'shortcuts.explorer', keys: ['E'], shift: true },
485
487
  { action: 'panelSearch', labelKey: 'shortcuts.search', keys: ['F'], shift: true },
486
488
  { action: 'panelGit', labelKey: 'shortcuts.git', keys: ['G'], shift: true },
@@ -2107,6 +2107,19 @@ G.GufaApp = function GufaApp(props) {
2107
2107
  const next = tabs[(index - 1 + tabs.length) % tabs.length]
2108
2108
  if (next !== undefined) setActivePath(next.path)
2109
2109
  },
2110
+ newWindow: () => {
2111
+ /* Host 用古法编程原生 helper 开一个普通窗口,加载同一个 Web GUI;
2112
+ helper 缺失/平台不支持时回退到浏览器新窗口。 */
2113
+ void G.api('app.newWindow', {}).catch((error) => {
2114
+ let opened = null
2115
+ try { opened = window.open(location.href, '_blank') } catch { opened = null }
2116
+ if (opened !== null && opened !== undefined) {
2117
+ try { opened.focus() } catch { /* ignore */ }
2118
+ return
2119
+ }
2120
+ try { G.refToast(`打开新窗口失败:${G.errorText(error)}`, 'err') } catch { /* ignore */ }
2121
+ })
2122
+ },
2110
2123
  shortcutsDialog: () => setShortcutsOpen((open) => open === false),
2111
2124
  shortcuts: () => {
2112
2125
  // 编辑器内 ⌘/ 是「切换行注释」(VS Code 一致),其他位置才打开快捷键列表