dsh-gufa-code 1.3.104 → 1.3.109
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 +19 -1
- package/desktop/float/bin/gufa-float-macos-arm64 +0 -0
- package/desktop/float/bin/gufa-float-macos-universal +0 -0
- package/desktop/float/bin/gufa-float-macos-x64 +0 -0
- package/desktop/float//345/217/244/346/263/225/347/274/226/347/250/213/346/202/254/346/265/256/345/261/202.app/Contents/Info.plist +2 -2
- package/desktop/float//345/217/244/346/263/225/347/274/226/347/250/213/346/202/254/346/265/256/345/261/202.app/Contents/MacOS/gufa-float +0 -0
- package/docs/KNOWN-PITFALLS.md +1 -1
- package/host/completion.js +29 -1
- package/host/fs.js +11 -3
- package/package.json +1 -1
- package/src/client/20-editor.js +7 -0
- package/src/client/90-app.js +11 -0
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.
|
|
19
|
+
G.BUILD = '1.3.109'
|
|
20
20
|
G.PANEL_ID = 'gufa-code'
|
|
21
21
|
/** 从哪个工作区点进来的(工作区菜单/节点按钮写入,App 启动时消费)。 */
|
|
22
22
|
G.pendingEntryWorkspace = null
|
|
@@ -3105,6 +3105,13 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
|
|
|
3105
3105
|
scrollbar: { verticalScrollbarSize: 10, horizontalScrollbarSize: 10, useShadows: false },
|
|
3106
3106
|
mouseWheelZoom: false,
|
|
3107
3107
|
contextmenu: true,
|
|
3108
|
+
/* 基础代码联想:显式打开自动补全与单词建议,避免依赖 Monaco 版本默认值 */
|
|
3109
|
+
quickSuggestions: { other: true, comments: false, strings: false },
|
|
3110
|
+
quickSuggestionsDelay: 10,
|
|
3111
|
+
suggestOnTriggerCharacters: true,
|
|
3112
|
+
wordBasedSuggestions: 'currentDocument',
|
|
3113
|
+
acceptSuggestionOnEnter: 'on',
|
|
3114
|
+
tabCompletion: 'on',
|
|
3108
3115
|
inlineSuggest: { enabled: true, showToolbar: 'never' },
|
|
3109
3116
|
}
|
|
3110
3117
|
}
|
|
@@ -13133,6 +13140,7 @@ G.GufaApp = function GufaApp(props) {
|
|
|
13133
13140
|
const consumeExitStateRef = useRef(false)
|
|
13134
13141
|
useEffect(() => {
|
|
13135
13142
|
if (G.isFloatMode()) return undefined
|
|
13143
|
+
if (G.instanceBoot === true) return undefined
|
|
13136
13144
|
let running = false
|
|
13137
13145
|
const consume = async () => {
|
|
13138
13146
|
if (running) return
|
|
@@ -13290,6 +13298,11 @@ G.GufaApp = function GufaApp(props) {
|
|
|
13290
13298
|
const entryWorkspaceSyncedRef = useRef(false)
|
|
13291
13299
|
useEffect(() => {
|
|
13292
13300
|
if (entryWorkspaceSyncedRef.current) return
|
|
13301
|
+
/* 实例窗口:保持空工作区,不跟随主窗口/DSH 当前会话自动打开项目 */
|
|
13302
|
+
if (G.instanceBoot === true) {
|
|
13303
|
+
entryWorkspaceSyncedRef.current = true
|
|
13304
|
+
return
|
|
13305
|
+
}
|
|
13293
13306
|
/* 悬浮层(摸鱼):项目/会话由主窗口状态注入,不做「入口工作区」同步 */
|
|
13294
13307
|
if (G.isFloatMode()) {
|
|
13295
13308
|
entryWorkspaceSyncedRef.current = true
|
|
@@ -13614,6 +13627,11 @@ G.GufaApp = function GufaApp(props) {
|
|
|
13614
13627
|
const lastSessionCwdRef = useRef(null)
|
|
13615
13628
|
useEffect(() => {
|
|
13616
13629
|
if (sessionPinnedRef.current === true) return
|
|
13630
|
+
/* 实例窗口:不跟随会话 cwd 自动打开项目 */
|
|
13631
|
+
if (G.instanceBoot === true) {
|
|
13632
|
+
lastSessionCwdRef.current = sessionCwd
|
|
13633
|
+
return
|
|
13634
|
+
}
|
|
13617
13635
|
/* 悬浮层里项目由主窗口状态注入,不跟随(Web 版客户端自己的)会话 cwd 切换 */
|
|
13618
13636
|
if (G.isFloatMode()) {
|
|
13619
13637
|
lastSessionCwdRef.current = sessionCwd
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -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.
|
|
11
|
-
<key>CFBundleVersion</key><string>1.3.
|
|
10
|
+
<key>CFBundleShortVersionString</key><string>1.3.109</string>
|
|
11
|
+
<key>CFBundleVersion</key><string>1.3.109</string>
|
|
12
12
|
<key>LSUIElement</key><true/>
|
|
13
13
|
<key>NSHighResolutionCapable</key><true/>
|
|
14
14
|
<key>NSPrincipalClass</key><string>NSApplication</string>
|
|
Binary file
|
package/docs/KNOWN-PITFALLS.md
CHANGED
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
- 实现:复用插件自带的原生 helper(`desktop/float/GufaFloat.m`),payload 传 `{full:true, authUrl, appUrl}` —— helper 建普通标题栏窗口、Regular 激活策略、跳过摸鱼 localStorage/隐藏主窗/吸附,加载同一个 DSH Web GUI;鉴权复用它已有的 `connection.authenticatedUrl()` token 流程。
|
|
60
60
|
- 客户端 ⌘⇧N 必须先调 Host `app.newWindow`,失败才回退 `window.open`(Electron 的 setWindowOpenHandler 会 deny 并用外部浏览器打开 http(s),不是应用内窗口)。
|
|
61
61
|
- 新窗口与 Electron 主窗口共享的是 **同一个 Host/服务端**,但 UI 进程独立(WKWebView,不走 Electron preload);所以别让新窗口依赖 `window.dshDesktop` 之类的 Electron preload API。
|
|
62
|
-
- **实例窗口不继承主窗口项目**(用户明确要求新窗口用来操作别的工作区):helper full 模式只清空 localStorage 里的 `gufa-code:float/float-state/project/ui/tabs/mode`,URL 带 `?gufa-instance=1`;客户端 boot 时反复调 `G.enterGufa()` 直到 `.gufa-overlay-root`
|
|
62
|
+
- **实例窗口不继承主窗口项目**(用户明确要求新窗口用来操作别的工作区):helper full 模式只清空 localStorage 里的 `gufa-code:float/float-state/project/ui/tabs/mode`,URL 带 `?gufa-instance=1`;客户端 boot 时反复调 `G.enterGufa()` 直到 `.gufa-overlay-root` 挂载。`G.instanceBoot` 必须同时挡住**所有**会自动打开项目的 effect:boot 的 sessionCwd 分支、入口工作区同步、会话 cwd 跟随(`lastSessionCwdRef`)、`float.consumeExitState`,否则 DSH 恢复当前会话后会把工作区带进新窗口。
|
|
63
63
|
- helper 的 WKWebView data store 与摸鱼悬浮层共享;full 模式必须清残留标记,否则新窗口会误进摸鱼 UI 或恢复上次项目。
|
|
64
64
|
- **全屏继承**:客户端用 `innerWidth/innerHeight` 对比 `screen.width/height` 和 `screen.availWidth/availHeight` 判断当前是否全屏,payload 传 `fullscreen:true`,helper 在窗口显示后 `toggleFullScreen`;不要依赖 Electron preload 或 AX 查询(Host 在 Node 模式进程里拿不到 Electron)。
|
|
65
65
|
|
package/host/completion.js
CHANGED
|
@@ -20,6 +20,7 @@ const SUPPORTED = new Set([
|
|
|
20
20
|
'csharp', 'cpp', 'c', 'shell', 'yaml', 'sql', 'php', 'ruby',
|
|
21
21
|
])
|
|
22
22
|
|
|
23
|
+
|
|
23
24
|
function sanitize(text) {
|
|
24
25
|
let value = String(text ?? '')
|
|
25
26
|
/* 去掉模型偶尔带出的 markdown 围栏 */
|
|
@@ -44,6 +45,26 @@ function selectionOf(ctx) {
|
|
|
44
45
|
return undefined
|
|
45
46
|
}
|
|
46
47
|
|
|
48
|
+
const effortCache = new Map()
|
|
49
|
+
|
|
50
|
+
/** 补全要求低延迟:优先选最小 reasoning effort(不同模型 id 不同,如 off/minimal/low)。 */
|
|
51
|
+
async function pickReasoningEffort(llm, provider, model) {
|
|
52
|
+
const key = `${provider}|${model}`
|
|
53
|
+
if (effortCache.has(key)) return effortCache.get(key)
|
|
54
|
+
let chosen = ''
|
|
55
|
+
try {
|
|
56
|
+
const info = await llm.resolveModelInfo(provider, model)
|
|
57
|
+
const efforts = info !== null && info !== undefined && info.reasoning !== null && info.reasoning !== undefined && Array.isArray(info.reasoning.efforts)
|
|
58
|
+
? info.reasoning.efforts.map((entry) => String(entry?.id ?? '')).filter((id) => id !== '')
|
|
59
|
+
: []
|
|
60
|
+
chosen = efforts.find((id) => /^(off|none|minimal|low)$/i.test(id)) ?? efforts[0] ?? ''
|
|
61
|
+
} catch {
|
|
62
|
+
chosen = ''
|
|
63
|
+
}
|
|
64
|
+
effortCache.set(key, chosen)
|
|
65
|
+
return chosen
|
|
66
|
+
}
|
|
67
|
+
|
|
47
68
|
export async function suggest(body, env) {
|
|
48
69
|
if (typeof body.prefix !== 'string' && typeof body.suffix !== 'string') throw badRequest('prefix is required')
|
|
49
70
|
const ctx = env.ctx
|
|
@@ -79,15 +100,19 @@ export async function suggest(body, env) {
|
|
|
79
100
|
'Insertion:',
|
|
80
101
|
].join('\n')
|
|
81
102
|
|
|
103
|
+
const reasoningEffort = await pickReasoningEffort(llm, provider, model)
|
|
82
104
|
const controller = new AbortController()
|
|
83
105
|
const timer = setTimeout(() => controller.abort(), 9000)
|
|
84
106
|
let text = ''
|
|
85
107
|
let failure = null
|
|
108
|
+
let finishKind = ''
|
|
109
|
+
let usage = null
|
|
86
110
|
const startedAt = Date.now()
|
|
87
111
|
try {
|
|
88
112
|
const stream = llm.stream({
|
|
89
113
|
provider,
|
|
90
114
|
model,
|
|
115
|
+
...(reasoningEffort === '' ? {} : { reasoningEffort }),
|
|
91
116
|
system: SYSTEM_PROMPT,
|
|
92
117
|
messages: [{ role: 'user', content: [{ type: 'text', text: userPrompt }] }],
|
|
93
118
|
maxTokens: 160,
|
|
@@ -99,8 +124,10 @@ export async function suggest(body, env) {
|
|
|
99
124
|
if (chunk === null || typeof chunk !== 'object') continue
|
|
100
125
|
if (chunk.type === 'text-delta' && typeof chunk.text === 'string') text += chunk.text
|
|
101
126
|
if (chunk.type === 'reasoning-delta') continue
|
|
127
|
+
if (chunk.type === 'usage') usage = chunk.usage
|
|
102
128
|
if (chunk.type === 'finish') {
|
|
103
129
|
const reason = chunk.reason
|
|
130
|
+
finishKind = reason !== null && typeof reason === 'object' && typeof reason.kind === 'string' ? reason.kind : ''
|
|
104
131
|
if (reason !== null && typeof reason === 'object' && (reason.kind === 'error' || reason.kind === 'aborted')) {
|
|
105
132
|
failure = reason.failure ?? { message: reason.kind }
|
|
106
133
|
}
|
|
@@ -117,10 +144,11 @@ export async function suggest(body, env) {
|
|
|
117
144
|
if (controller.signal.aborted) throw new ApiError('llm-timeout', '补全请求超时', 504)
|
|
118
145
|
throw new ApiError('llm-failed', `补全模型调用失败:${message}`, 502)
|
|
119
146
|
}
|
|
147
|
+
const sanitized = sanitize(text)
|
|
120
148
|
return {
|
|
121
149
|
provider,
|
|
122
150
|
model,
|
|
123
|
-
text:
|
|
151
|
+
text: sanitized,
|
|
124
152
|
latencyMs: Date.now() - startedAt,
|
|
125
153
|
}
|
|
126
154
|
}
|
package/host/fs.js
CHANGED
|
@@ -13,7 +13,6 @@ import { tmpdir } from 'node:os'
|
|
|
13
13
|
import { dirname, extname, isAbsolute, join, relative, resolve, sep } from 'node:path'
|
|
14
14
|
import { ApiError, badRequest } from './context.js'
|
|
15
15
|
import { registerLsp } from './lsp.js'
|
|
16
|
-
import { registerCompletion } from './completion.js'
|
|
17
16
|
|
|
18
17
|
const TEXT_LIMIT = 4 * 1024 * 1024
|
|
19
18
|
const runCommand = promisify(execFile)
|
|
@@ -286,8 +285,17 @@ export function register(router, env) {
|
|
|
286
285
|
/* Python 语言服务(LSP/pyright):/lsp/definition API;Cmd+点击与悬停由客户端调用 */
|
|
287
286
|
registerLsp(router, env)
|
|
288
287
|
|
|
289
|
-
/* Tab 行内补全:借用 Harness
|
|
290
|
-
|
|
288
|
+
/* Tab 行内补全:借用 Harness 自己的模型服务(completion.js 用带 mtime 的动态 import,改它免重启) */
|
|
289
|
+
router.method('completion.suggest', async (body) => {
|
|
290
|
+
let stamp = '0'
|
|
291
|
+
try {
|
|
292
|
+
stamp = String(statSync(new URL('./completion.js', import.meta.url)).mtimeMs)
|
|
293
|
+
} catch {
|
|
294
|
+
stamp = '0'
|
|
295
|
+
}
|
|
296
|
+
const module = await import(new URL(`./completion.js?gufa-completion=${stamp}`, import.meta.url).href)
|
|
297
|
+
return module.suggest(body, env)
|
|
298
|
+
})
|
|
291
299
|
|
|
292
300
|
/* ⌘⇧N:打开新的 Harness 实例窗口(Electron 单实例下新建 BrowserWindow)。
|
|
293
301
|
app-window.js 用带 mtime 的动态 import,改它不必重启 Host。 */
|
package/package.json
CHANGED
package/src/client/20-editor.js
CHANGED
|
@@ -481,6 +481,13 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
|
|
|
481
481
|
scrollbar: { verticalScrollbarSize: 10, horizontalScrollbarSize: 10, useShadows: false },
|
|
482
482
|
mouseWheelZoom: false,
|
|
483
483
|
contextmenu: true,
|
|
484
|
+
/* 基础代码联想:显式打开自动补全与单词建议,避免依赖 Monaco 版本默认值 */
|
|
485
|
+
quickSuggestions: { other: true, comments: false, strings: false },
|
|
486
|
+
quickSuggestionsDelay: 10,
|
|
487
|
+
suggestOnTriggerCharacters: true,
|
|
488
|
+
wordBasedSuggestions: 'currentDocument',
|
|
489
|
+
acceptSuggestionOnEnter: 'on',
|
|
490
|
+
tabCompletion: 'on',
|
|
484
491
|
inlineSuggest: { enabled: true, showToolbar: 'never' },
|
|
485
492
|
}
|
|
486
493
|
}
|
package/src/client/90-app.js
CHANGED
|
@@ -1290,6 +1290,7 @@ G.GufaApp = function GufaApp(props) {
|
|
|
1290
1290
|
const consumeExitStateRef = useRef(false)
|
|
1291
1291
|
useEffect(() => {
|
|
1292
1292
|
if (G.isFloatMode()) return undefined
|
|
1293
|
+
if (G.instanceBoot === true) return undefined
|
|
1293
1294
|
let running = false
|
|
1294
1295
|
const consume = async () => {
|
|
1295
1296
|
if (running) return
|
|
@@ -1447,6 +1448,11 @@ G.GufaApp = function GufaApp(props) {
|
|
|
1447
1448
|
const entryWorkspaceSyncedRef = useRef(false)
|
|
1448
1449
|
useEffect(() => {
|
|
1449
1450
|
if (entryWorkspaceSyncedRef.current) return
|
|
1451
|
+
/* 实例窗口:保持空工作区,不跟随主窗口/DSH 当前会话自动打开项目 */
|
|
1452
|
+
if (G.instanceBoot === true) {
|
|
1453
|
+
entryWorkspaceSyncedRef.current = true
|
|
1454
|
+
return
|
|
1455
|
+
}
|
|
1450
1456
|
/* 悬浮层(摸鱼):项目/会话由主窗口状态注入,不做「入口工作区」同步 */
|
|
1451
1457
|
if (G.isFloatMode()) {
|
|
1452
1458
|
entryWorkspaceSyncedRef.current = true
|
|
@@ -1771,6 +1777,11 @@ G.GufaApp = function GufaApp(props) {
|
|
|
1771
1777
|
const lastSessionCwdRef = useRef(null)
|
|
1772
1778
|
useEffect(() => {
|
|
1773
1779
|
if (sessionPinnedRef.current === true) return
|
|
1780
|
+
/* 实例窗口:不跟随会话 cwd 自动打开项目 */
|
|
1781
|
+
if (G.instanceBoot === true) {
|
|
1782
|
+
lastSessionCwdRef.current = sessionCwd
|
|
1783
|
+
return
|
|
1784
|
+
}
|
|
1774
1785
|
/* 悬浮层里项目由主窗口状态注入,不跟随(Web 版客户端自己的)会话 cwd 切换 */
|
|
1775
1786
|
if (G.isFloatMode()) {
|
|
1776
1787
|
lastSessionCwdRef.current = sessionCwd
|