dsh-gufa-code 1.3.215 → 1.3.234

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.
@@ -191,6 +191,162 @@ G.installWorkspaceMenuEntry = function installWorkspaceMenuEntry(ctx) {
191
191
  }
192
192
  }
193
193
 
194
+ /** 经典模式聊天标题行的文本入口:和「智能体团队」同款 link 样式,但文案直接叫「古法编程」。 */
195
+ G.GufaHeaderEntry = function GufaHeaderEntry() {
196
+ const ideVisible = G.useMode()
197
+ if (ideVisible === true) return null
198
+ return h(
199
+ 'button',
200
+ {
201
+ type: 'button',
202
+ className: 'gufa-header-entry',
203
+ title: '进入古法编程(当前聊天的工作区)',
204
+ 'aria-label': '古法编程',
205
+ onClick: (event) => {
206
+ try {
207
+ event.preventDefault()
208
+ event.stopPropagation()
209
+ } catch {
210
+ /* ignore */
211
+ }
212
+ try {
213
+ G.pendingSessionEntry = true
214
+ G.enterGufa()
215
+ } catch (error) {
216
+ console.error('[gufa-code] 进入古法编程失败', error)
217
+ }
218
+ },
219
+ },
220
+ h('span', { className: 'gufa-header-entry-label' }, '古法编程'),
221
+ )
222
+ }
223
+
224
+ /** 文件关联打开:订阅 Host 的 open.watch 事件(不再轮询文件),处理成功后 ack。 */
225
+ G.installOpenWithHandler = function installOpenWithHandler(ctx) {
226
+ if (typeof window === 'undefined' || typeof document === 'undefined') return () => {}
227
+ let skip = false
228
+ try {
229
+ skip = typeof G.isFloatMode === 'function' && G.isFloatMode() === true
230
+ if (!skip && /[?&]gufa-instance=1/.test(String(location.search || ''))) skip = true
231
+ if (!skip && /welcome|update/i.test(String(location.href || ''))) skip = true
232
+ } catch {
233
+ skip = false
234
+ }
235
+ if (skip) return () => {}
236
+ let stopped = false
237
+ let busy = false
238
+ let lastToken = ''
239
+ let abortStream = null
240
+ let reconnectTimer = 0
241
+ let retryTimer = 0
242
+ let logs = 20
243
+ const log = (message) => {
244
+ if (logs <= 0) return
245
+ logs -= 1
246
+ try { void G.api('dev.log', { message }).catch(() => {}) } catch { /* ignore */ }
247
+ }
248
+ const sleep = (ms) => new Promise((resolve) => { window.setTimeout(resolve, ms) })
249
+ const ideReady = () => {
250
+ try {
251
+ return G.mode.get() === true
252
+ && G.ideBootDone === true
253
+ && typeof G.ideOpenPaths === 'function'
254
+ && document.querySelector('.gufa-overlay-root') !== null
255
+ } catch {
256
+ return false
257
+ }
258
+ }
259
+ const waitIdeReady = async (maxAttempts = 100) => {
260
+ for (let attempt = 0; attempt < maxAttempts && stopped !== true; attempt += 1) {
261
+ if (ideReady()) return true
262
+ await sleep(200)
263
+ }
264
+ return false
265
+ }
266
+ const openEntries = async (entries) => {
267
+ if (!ideReady()) {
268
+ log(`open-with enter ide mode=${G.mode.get() === true} hook=${typeof G.ideOpenPaths === 'function'} boot=${G.ideBootDone === true}`)
269
+ try {
270
+ G.pendingOpenEntries = entries
271
+ G.pendingSessionEntry = false
272
+ G.enterGufa()
273
+ } catch {
274
+ return false
275
+ }
276
+ /* 必须等 IDE 覆盖层真正挂载 + App 初始 boot 完成,否则旧项目会覆盖刚打开的工作区 */
277
+ if (!(await waitIdeReady())) return false
278
+ }
279
+ const result = await G.ideOpenPaths(entries)
280
+ return result !== false
281
+ }
282
+ const handlePending = async (event) => {
283
+ if (stopped || busy) return
284
+ const entries = event !== null && event !== undefined && Array.isArray(event.entries) ? event.entries : []
285
+ const token = event !== null && event !== undefined && typeof event.token === 'string' ? event.token : ''
286
+ if (entries.length === 0 || token === '' || token === lastToken) return
287
+ G.openWithActive = true
288
+ busy = true
289
+ log(`open-with pending token=${token} entries=${entries.length} paths=${entries.map((entry) => entry.path).join('|')}`)
290
+ const ok = await openEntries(entries)
291
+ busy = false
292
+ if (stopped) return
293
+ if (ok) {
294
+ lastToken = token
295
+ await G.api('open.ack', { token }).catch(() => {})
296
+ G.openWithActive = false
297
+ log(`open-with ack token=${token}`)
298
+ return
299
+ }
300
+ log(`open-with retry token=${token}`)
301
+ if (retryTimer !== 0) window.clearTimeout(retryTimer)
302
+ retryTimer = window.setTimeout(() => {
303
+ retryTimer = 0
304
+ void handlePending(event)
305
+ }, 3000)
306
+ }
307
+ const scheduleReconnect = (delay = 1500) => {
308
+ if (stopped) return
309
+ if (reconnectTimer !== 0) return
310
+ reconnectTimer = window.setTimeout(() => {
311
+ reconnectTimer = 0
312
+ connect()
313
+ }, delay)
314
+ }
315
+ const connect = () => {
316
+ if (stopped) return
317
+ try {
318
+ abortStream = G.stream('open.watch', {}, (event) => {
319
+ if (event === null || event === undefined) return
320
+ if (event.type === 'pending') void handlePending(event)
321
+ else if (event.type === 'error') scheduleReconnect()
322
+ }, () => scheduleReconnect())
323
+ log('open-with stream connected')
324
+ } catch {
325
+ scheduleReconnect(3000)
326
+ }
327
+ }
328
+ const start = () => {
329
+ if (stopped) return
330
+ void G.api('open.ensure', {}).catch(() => {})
331
+ connect()
332
+ }
333
+ try {
334
+ if (typeof ctx?.inject === 'function') ctx.inject(['layout'], () => start())
335
+ else start()
336
+ } catch {
337
+ start()
338
+ }
339
+ return () => {
340
+ stopped = true
341
+ if (reconnectTimer !== 0) window.clearTimeout(reconnectTimer)
342
+ if (retryTimer !== 0) window.clearTimeout(retryTimer)
343
+ reconnectTimer = 0
344
+ retryTimer = 0
345
+ try { if (typeof abortStream === 'function') abortStream() } catch { /* ignore */ }
346
+ abortStream = null
347
+ }
348
+ }
349
+
194
350
  /** 「更多」菜单里的入口行:点击进入古法编程(从当前工作区进入)。 */
195
351
  G.MoreMenuEntry = function MoreMenuEntry(props) {
196
352
  return h(
@@ -781,6 +937,14 @@ const GUFA_PLUGIN = {
781
937
  }
782
938
  }, 2500)
783
939
 
940
+ // 系统文件「打开方式」:自动安装打开器并轮询 pending 文件请求。
941
+ try {
942
+ const disposeOpenWith = G.installOpenWithHandler(ctx)
943
+ if (typeof disposeOpenWith === 'function') ctx.effect(() => disposeOpenWith, 'gufa-code: open-with handler')
944
+ } catch (error) {
945
+ console.error('[gufa-code] 文件关联打开器安装失败', error)
946
+ }
947
+
784
948
  // 入口:工作区行的「...」菜单里注入「古法编程」一行。
785
949
  try {
786
950
  const disposeMenuEntry = G.installWorkspaceMenuEntry(ctx)
@@ -789,6 +953,19 @@ const GUFA_PLUGIN = {
789
953
  console.error('[gufa-code] 安装工作区菜单入口失败', error)
790
954
  }
791
955
 
956
+ // 经典模式聊天右上角工具区:在头像菜单左侧的空位放「古法编程」文本入口。
957
+ try {
958
+ ctx.inject(['slots'], (scope) => {
959
+ scope.slots.inject('conversation.session.header.utilities', () => scope.slots.register({
960
+ name: 'conversation.session.header.utilities',
961
+ id: 'gufa-code-entry',
962
+ order: -100,
963
+ }, G.GufaHeaderEntry))
964
+ })
965
+ } catch (error) {
966
+ console.error('[gufa-code] 聊天头部入口注册失败', error)
967
+ }
968
+
792
969
  // 面板注册:入口注入到工作区行的「...」菜单里(DSH 未提供该菜单的 slot)。
793
970
  ctx.inject(['slots'], (scope) => {
794
971
  // main key 仅作安全网:若侧边栏把主面板切到 gufa-code(点击拦截失效时),