dsh-gufa-code 1.3.117 → 1.3.133

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.
@@ -403,6 +403,146 @@
403
403
  const GUFA_LSP_WARMED = new Set()
404
404
  const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'def', 'func', 'fn', 'type', 'export', 'lsp'])
405
405
 
406
+ /* ── 原生 DefinitionProvider + editor opener ─────────────────────────
407
+ * Cmd+点击 / F12 都交给 Monaco 自己的 `editor.action.revealDefinition`;
408
+ * 定义解析走 Host API(JS/TS 用 code.definition,Python 用 pyright 的 lsp.definition),
409
+ * 打开文件由 registerEditorOpener 转成 App 的 editor:open-at,多个结果交给 Monaco 原生 peek。
410
+ */
411
+ /* JS/TS 的 F12 交回 Monaco 原生 TS DefinitionProvider(之前被我们关掉过);
412
+ Cmd+点击在 click handler 里直接走 Host LanguageService 以拿到最准结果。 */
413
+ const GUFA_DEFINITION_LANGUAGES = ['python']
414
+ function gufaRegisterDefinitionInfrastructure(monaco) {
415
+ try {
416
+ if (monaco === null || monaco === undefined) return
417
+ if (G.__gufaDefinitionInfra === true) return
418
+ if (monaco.languages === null || monaco.languages === undefined || typeof monaco.languages.registerDefinitionProvider !== 'function') return
419
+ G.__gufaDefinitionInfra = true
420
+ const rootAt = () => (typeof G.projectRoot === 'string' ? G.projectRoot.replace(/\\/g, '/').replace(/\/+$/, '') : '')
421
+ const pathOfModel = (model) => {
422
+ const root = rootAt()
423
+ if (root === '' || model === null || model === undefined) return null
424
+ let absolute = ''
425
+ try {
426
+ absolute = model.uri?.fsPath ?? (typeof model.uri?.path === 'string' ? decodeURIComponent(model.uri.path) : '')
427
+ } catch {
428
+ return null
429
+ }
430
+ absolute = String(absolute).replace(/\\/g, '/')
431
+ if (!absolute.startsWith(`${root}/`)) return null
432
+ return { root, path: absolute.slice(root.length + 1) }
433
+ }
434
+ const locationsOf = (root, matches, word, monacoNs) => {
435
+ const list = Array.isArray(matches) ? matches : []
436
+ const result = []
437
+ const seen = new Set()
438
+ for (const match of list.slice(0, 10)) {
439
+ if (match === null || typeof match !== 'object' || typeof match.path !== 'string') continue
440
+ /* TS lib 定义(parseInt/Promise 等)走 readTsLib 只读标签,不交给 Monaco 原生动作 */
441
+ if (match.external === true || typeof match.absolutePath === 'string') continue
442
+ const line = Math.max(1, Math.trunc(Number(match.line) || 1))
443
+ const column = Math.max(1, Math.trunc(Number(match.column) || 1))
444
+ const key = `${match.path}:${line}:${column}`
445
+ if (seen.has(key)) continue
446
+ seen.add(key)
447
+ const uri = gufaModelUri(monacoNs, root, match.path)
448
+ const range = new monacoNs.Range(line, column, line, column + Math.max(1, word.length))
449
+ result.push({ uri, range })
450
+ }
451
+ return result
452
+ }
453
+ for (const language of GUFA_DEFINITION_LANGUAGES) {
454
+ try {
455
+ monaco.languages.registerDefinitionProvider(language, {
456
+ async provideDefinition(model, position, token) {
457
+ if (token !== null && token !== undefined && token.isCancellationRequested === true) return []
458
+ const info = pathOfModel(model)
459
+ if (info === null) return []
460
+ const wordInfo = typeof model.getWordAtPosition === 'function' ? model.getWordAtPosition(position) : null
461
+ const word = wordInfo !== null && wordInfo !== undefined && typeof wordInfo.word === 'string' ? wordInfo.word : ''
462
+ try {
463
+ let result = null
464
+ if (language === 'python') {
465
+ result = await G.api('lsp.definition', {
466
+ root: info.root,
467
+ path: info.path,
468
+ line: position.lineNumber,
469
+ column: position.column,
470
+ language: 'python',
471
+ content: model.getValue(),
472
+ })
473
+ } else {
474
+ /* LanguageService 解析定义(TS 编译器),比正则项目搜索准确;
475
+ JS/TS 不再回退到 code.definition,避免“宁可跳错也不空着”。 */
476
+ result = await G.api('code.tsDefinition', {
477
+ root: info.root,
478
+ path: info.path,
479
+ line: position.lineNumber,
480
+ column: position.column,
481
+ content: model.getValue(),
482
+ })
483
+ }
484
+ if (token !== null && token !== undefined && token.isCancellationRequested === true) return []
485
+ return locationsOf(info.root, result !== null && result !== undefined ? result.matches : null, word, monaco)
486
+ } catch {
487
+ return []
488
+ }
489
+ },
490
+ })
491
+ } catch {
492
+ /* 单个语言注册失败不影响其它语言 */
493
+ }
494
+ }
495
+ try {
496
+ if (typeof monaco.editor.registerEditorOpener === 'function') {
497
+ monaco.editor.registerEditorOpener({
498
+ openCodeEditor(source, resource, selectionOrPosition) {
499
+ const root = rootAt()
500
+ if (root === '') return false
501
+ let absolute = ''
502
+ try {
503
+ absolute = resource?.fsPath ?? (typeof resource?.path === 'string' ? decodeURIComponent(resource.path) : '')
504
+ } catch {
505
+ return false
506
+ }
507
+ absolute = String(absolute).replace(/\\/g, '/')
508
+ const selection = selectionOrPosition !== null && selectionOrPosition !== undefined && selectionOrPosition.selection !== undefined
509
+ ? selectionOrPosition.selection
510
+ : selectionOrPosition
511
+ const line = Math.max(1, Math.trunc(Number(selection?.startLineNumber ?? selection?.lineNumber ?? 1) || 1))
512
+ const column = Math.max(1, Math.trunc(Number(selection?.startColumn ?? selection?.column ?? 1) || 1))
513
+ if (absolute.startsWith(`${root}/`)) {
514
+ try {
515
+ G.bus.emit('editor:open-at', { path: absolute.slice(root.length + 1), line, column })
516
+ } catch {
517
+ return false
518
+ }
519
+ return true
520
+ }
521
+ /* 系统内置 API 的定义在 TS worker 的 lib 里(parseInt 等):按 basename 交给只读标签打开 */
522
+ const baseName = absolute.slice(absolute.lastIndexOf('/') + 1)
523
+ if (/^lib\.[A-Za-z0-9._-]+\.d\.ts$/.test(baseName)) {
524
+ try {
525
+ G.bus.emit('editor:open-external', { absolutePath: '', libName: baseName, path: baseName, line, column })
526
+ } catch {
527
+ return false
528
+ }
529
+ return true
530
+ }
531
+ return false
532
+ },
533
+ })
534
+ }
535
+ } catch {
536
+ /* ignore */
537
+ }
538
+ } catch {
539
+ /* ignore */
540
+ }
541
+ }
542
+
543
+ /* 诊断波浪线已关闭(用户要求);Host lint 也不再在每次输入后跑 tsc,省 CPU */
544
+ const GUFA_LINT_ENABLED = false
545
+
406
546
  /* ── model / URI ────────────────────────────────────────────────────── */
407
547
 
408
548
  /**
@@ -737,13 +877,32 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
737
877
  } catch (error) {
738
878
  /* 模板语言注册失败不影响编辑器 */
739
879
  }
740
- /* 诊断改由 Host 的 TypeScript 编译器提供(dsh-app worker 不可靠),
741
- 关闭 Monaco worker 诊断避免重复/后台报错;补全建议仍由 worker 提供。 */
880
+ try {
881
+ gufaRegisterDefinitionInfrastructure(monaco)
882
+ } catch {
883
+ /* ignore */
884
+ }
885
+ /* 错误诊断恢复 Monaco 原生 TS worker:语法/语义/类型错误都正常画线。
886
+ Monaco 的 javascriptDefaults 默认关掉了 JS 语义诊断(noSemanticValidation=true),
887
+ 这里显式打开并开 checkJs,否则 .js 里只有语法错误、没有未定义变量等诊断。 */
742
888
  try {
743
889
  const typescriptLanguages = monaco.languages.typescript
744
- const diagnosticsOff = { noSemanticValidation: true, noSyntaxValidation: true }
745
- typescriptLanguages?.typescriptDefaults?.setDiagnosticsOptions(diagnosticsOff)
746
- typescriptLanguages?.javascriptDefaults?.setDiagnosticsOptions(diagnosticsOff)
890
+ if (typescriptLanguages !== null && typescriptLanguages !== undefined) {
891
+ const diagnosticsOn = { noSemanticValidation: false, noSyntaxValidation: false }
892
+ typescriptLanguages.typescriptDefaults?.setDiagnosticsOptions(diagnosticsOn)
893
+ typescriptLanguages.javascriptDefaults?.setDiagnosticsOptions(diagnosticsOn)
894
+ typescriptLanguages.javascriptDefaults?.setCompilerOptions({
895
+ allowNonTsExtensions: true,
896
+ allowJs: true,
897
+ checkJs: true,
898
+ target: 99,
899
+ moduleResolution: 2,
900
+ module: 99,
901
+ jsx: 1,
902
+ esModuleInterop: true,
903
+ allowSyntheticDefaultImports: true,
904
+ })
905
+ }
747
906
  } catch (error) {
748
907
  /* ignore */
749
908
  }
@@ -909,8 +1068,9 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
909
1068
  /* ignore */
910
1069
  }
911
1070
  }
1071
+ /* Cmd 悬停只给单词换颜色(蓝色),不加下划线、不弹原生 link 提示框。 */
912
1072
  const showHoverDecoration = (position, wordInfo) => {
913
- if (wordInfo === null || wordInfo === undefined) return clearHoverDecoration()
1073
+ if (wordInfo === null || wordInfo === undefined || position === null || position === undefined) return clearHoverDecoration()
914
1074
  let range = null
915
1075
  try {
916
1076
  range = new monaco.Range(position.lineNumber, wordInfo.startColumn, position.lineNumber, wordInfo.endColumn)
@@ -919,68 +1079,28 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
919
1079
  }
920
1080
  try {
921
1081
  hover.decorationIds = instance.deltaDecorations(hover.decorationIds, [
922
- { range, options: { inlineClassName: 'gufa-def-link', stickiness: 1 } },
1082
+ { range, options: { inlineClassName: 'gufa-def-link-color', stickiness: 1 } },
923
1083
  ])
924
1084
  } catch {
925
1085
  /* ignore */
926
1086
  }
927
- try {
928
- editorDom.classList.add('gufa-def-hover')
929
- } catch {
930
- /* ignore */
931
- }
932
1087
  }
933
1088
  const evaluateHoverPosition = (position, wordInfo) => {
934
1089
  if (!hover.meta) {
935
1090
  clearHoverDecoration()
936
1091
  return
937
1092
  }
938
- const model = instance.getModel()
939
1093
  const word = wordInfo !== null && wordInfo !== undefined && typeof wordInfo.word === 'string' ? wordInfo.word : ''
940
- const path = modelPathRef.current
941
- const root = modelsRootRef.current
942
- if (position === null || position === undefined || model === null || model === undefined
943
- || word.length < 2 || path === null || path === undefined || root === null || root === undefined || root === '') {
1094
+ if (position === null || position === undefined || word.length < 2) {
944
1095
  clearHoverDecoration()
945
1096
  return
946
1097
  }
947
- hover.lastPosition = position
948
- hover.lastWordInfo = wordInfo
949
- const key = `${path}|${word}`
1098
+ /* 不再为了下划线去跑项目级定义搜索:按住 Cmd 立刻标出当前单词,
1099
+ 真正解析只发生在点击时。之前 hover 的 host 扫描是「难用/卡」的主要来源。 */
1100
+ const key = `${position.lineNumber}:${wordInfo.startColumn}:${wordInfo.endColumn}`
1101
+ if (hover.lastKey === key && hover.decorationIds.length > 0) return
950
1102
  hover.lastKey = key
951
- const cached = hover.cache.get(key)
952
- if (cached === 'none') {
953
- clearHoverDecoration()
954
- return
955
- }
956
- if (cached === 'yes') {
957
- showHoverDecoration(position, wordInfo)
958
- return
959
- }
960
- if (hover.timer !== 0) {
961
- window.clearTimeout(hover.timer)
962
- hover.timer = 0
963
- }
964
- const seq = ++hover.seq
965
- hover.timer = window.setTimeout(() => {
966
- hover.timer = 0
967
- if (!hover.meta || seq !== hover.seq) return
968
- void queryDefinitions(position, word, model, path, root).then((result) => {
969
- if (!hover.meta || seq !== hover.seq || hover.lastKey !== key) return
970
- const decision = decideDefinition(result)
971
- if (decision.kind === 'none') {
972
- if (hover.cache.size > 100) hover.cache.clear()
973
- hover.cache.set(key, 'none')
974
- clearHoverDecoration()
975
- return
976
- }
977
- if (hover.cache.size > 100) hover.cache.clear()
978
- hover.cache.set(key, 'yes')
979
- showHoverDecoration(position, wordInfo)
980
- }).catch(() => {
981
- /* ignore */
982
- })
983
- }, 130)
1103
+ showHoverDecoration(position, wordInfo)
984
1104
  }
985
1105
  /* 用 Monaco 自己的 onMouseMove(带修饰键状态 + 精确 position),
986
1106
  不依赖 DOM mousedown/getTargetAtClientPoint 的坐标系与包含关系。 */
@@ -1091,13 +1211,66 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
1091
1211
  } catch {
1092
1212
  /* ignore */
1093
1213
  }
1214
+ /* Cmd+点击直接用 Host 的准确解析,避免依赖 Monaco 原生 action/worker:
1215
+ - JS/TS:TypeScript LanguageService(含 parseInt 等系统 lib);
1216
+ - Python:pyright lsp.definition。 */
1217
+ const clickLanguage = typeof model.getLanguageId === 'function' ? model.getLanguageId() : ''
1218
+ if (clickLanguage === 'javascript' || clickLanguage === 'typescript') {
1219
+ try {
1220
+ const resolved = await G.api('code.tsDefinition', {
1221
+ root,
1222
+ path,
1223
+ line: position.lineNumber,
1224
+ column: position.column,
1225
+ content: model.getValue(),
1226
+ })
1227
+ const matches = resolved !== null && resolved !== undefined && Array.isArray(resolved.matches) ? resolved.matches : []
1228
+ const internal = matches.find((item) => item !== null && item !== undefined && item.external !== true && typeof item.path === 'string' && item.path !== '')
1229
+ if (internal !== undefined) {
1230
+ G.bus.emit('editor:open-at', { path: internal.path, line: internal.line, column: internal.column })
1231
+ } else {
1232
+ const external = matches.find((item) => item !== null && item !== undefined && item.external === true && typeof item.absolutePath === 'string')
1233
+ if (external !== undefined) {
1234
+ G.bus.emit('editor:open-external', {
1235
+ absolutePath: external.absolutePath,
1236
+ path: typeof external.path === 'string' ? external.path : '',
1237
+ line: external.line,
1238
+ column: external.column,
1239
+ })
1240
+ }
1241
+ }
1242
+ } catch {
1243
+ /* 解析失败不跳错 */
1244
+ }
1245
+ clearHoverDecoration()
1246
+ return
1247
+ }
1248
+ if (clickLanguage === 'python') {
1249
+ try {
1250
+ const resolved = await G.api('lsp.definition', {
1251
+ root,
1252
+ path,
1253
+ line: position.lineNumber,
1254
+ column: position.column,
1255
+ language: 'python',
1256
+ content: model.getValue(),
1257
+ })
1258
+ const matches = resolved !== null && resolved !== undefined && Array.isArray(resolved.matches) ? resolved.matches : []
1259
+ const first = matches.find((item) => item !== null && item !== undefined && typeof item.path === 'string' && item.path !== '')
1260
+ if (first !== undefined) G.bus.emit('editor:open-at', { path: first.path, line: first.line, column: first.column })
1261
+ } catch {
1262
+ /* ignore */
1263
+ }
1264
+ clearHoverDecoration()
1265
+ return
1266
+ }
1267
+ /* 其它语言:保留 Monaco 原生 action 兜底 */
1094
1268
  try {
1095
- await preloadTsDependencies(model, path, root)
1269
+ instance.focus()
1270
+ instance.setPosition(position)
1096
1271
  } catch {
1097
1272
  /* ignore */
1098
1273
  }
1099
- const beforePath = modelPathRef.current
1100
- const beforePosition = instance.getPosition()
1101
1274
  try {
1102
1275
  const action = typeof instance.getAction === 'function' ? instance.getAction('editor.action.revealDefinition') : null
1103
1276
  if (action !== null && action !== undefined) {
@@ -1107,37 +1280,8 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
1107
1280
  } catch {
1108
1281
  /* ignore */
1109
1282
  }
1110
- await new Promise((resolve) => { window.setTimeout(resolve, 160) })
1111
- let monacoHandled = false
1112
- try {
1113
- const afterPosition = instance.getPosition()
1114
- monacoHandled = modelPathRef.current !== beforePath
1115
- || (beforePosition !== null && beforePosition !== undefined && afterPosition !== null && afterPosition !== undefined
1116
- && (afterPosition.lineNumber !== beforePosition.lineNumber || afterPosition.column !== beforePosition.column))
1117
- || document.querySelector('.monaco-editor .peekview-widget, .monaco-editor .reference-zone-widget') !== null
1118
- } catch {
1119
- monacoHandled = false
1120
- }
1283
+ await new Promise((resolve) => { window.setTimeout(resolve, 200) })
1121
1284
  clearHoverDecoration()
1122
- if (monacoHandled) return
1123
- try {
1124
- const result = await queryDefinitions(position, word, model, path, root)
1125
- const decision = decideDefinition(result)
1126
- if (decision.kind === 'open') {
1127
- G.bus.emit('editor:open-at', { path: decision.match.path, line: decision.match.line, column: decision.match.column })
1128
- return
1129
- }
1130
- if (decision.kind === 'pick') {
1131
- G.bus.emit('definition:pick', {
1132
- word: result !== null && result !== undefined && typeof result.word === 'string' ? result.word : word,
1133
- matches: decision.matches,
1134
- x: event.clientX,
1135
- y: event.clientY,
1136
- })
1137
- }
1138
- } catch {
1139
- /* ignore */
1140
- }
1141
1285
  }
1142
1286
  document.addEventListener('mousedown', onDefinitionClick, true)
1143
1287
  document.addEventListener('keydown', onMetaDown, true)
@@ -1163,6 +1307,88 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
1163
1307
  } catch {
1164
1308
  /* ignore */
1165
1309
  }
1310
+ /* 外部/AI 修改磁盘后由 App 轮询发现,通过 bus 通知编辑器热替换 model 内容。
1311
+ (1.3.117 删 AI Tab 时误删过这一段,1.3.125 恢复) */
1312
+ try {
1313
+ if (G.bus !== null && G.bus !== undefined && typeof G.bus.on === 'function') {
1314
+ const offExternalReload = G.bus.on('editor:external-reload', (detail) => {
1315
+ if (detail === null || detail === undefined || typeof detail.path !== 'string' || typeof detail.content !== 'string') return
1316
+ const target = modelsRef.current.get(detail.path)
1317
+ if (target === null || target === undefined) return
1318
+ let content = ''
1319
+ try {
1320
+ content = target.getValue()
1321
+ } catch {
1322
+ return
1323
+ }
1324
+ if (content === detail.content) return
1325
+ const active = modelPathRef.current === detail.path
1326
+ let position = null
1327
+ let scrollTop = 0
1328
+ if (active) {
1329
+ try {
1330
+ position = instance.getPosition()
1331
+ scrollTop = instance.getScrollTop()
1332
+ } catch {
1333
+ position = null
1334
+ }
1335
+ }
1336
+ suppressChangeRef.current = true
1337
+ try {
1338
+ target.setValue(detail.content)
1339
+ } finally {
1340
+ suppressChangeRef.current = false
1341
+ }
1342
+ lastPropContentRef.current.set(detail.path, detail.content)
1343
+ if (active && position !== null && position !== undefined) {
1344
+ try {
1345
+ instance.setPosition(position)
1346
+ instance.setScrollTop(scrollTop)
1347
+ } catch {
1348
+ /* ignore */
1349
+ }
1350
+ }
1351
+ })
1352
+ if (typeof offExternalReload === 'function') subscriptions.push({ dispose: offExternalReload })
1353
+ }
1354
+ } catch {
1355
+ /* ignore */
1356
+ }
1357
+
1358
+ /* 拖拽分割条期间暂停 Monaco automaticLayout:
1359
+ 宽度每帧变化时 Monaco layout() 会跟着重排整块编辑器,是「不跟手」的大头;
1360
+ 拖拽先只动容器/别的面板,松手后再 layout 一次。 */
1361
+ try {
1362
+ if (G.bus !== null && G.bus !== undefined && typeof G.bus.on === 'function') {
1363
+ const offResizeStart = G.bus.on('layout:resize-start', () => {
1364
+ try {
1365
+ instance.updateOptions({ automaticLayout: false })
1366
+ } catch {
1367
+ /* ignore */
1368
+ }
1369
+ })
1370
+ const offResizeEnd = G.bus.on('layout:resize-end', () => {
1371
+ const relayout = () => {
1372
+ try {
1373
+ instance.updateOptions({ automaticLayout: true })
1374
+ instance.layout()
1375
+ } catch {
1376
+ /* ignore */
1377
+ }
1378
+ }
1379
+ if (typeof requestAnimationFrame === 'function') {
1380
+ requestAnimationFrame(() => requestAnimationFrame(relayout))
1381
+ } else {
1382
+ window.setTimeout(relayout, 32)
1383
+ }
1384
+ })
1385
+ if (typeof offResizeStart === 'function') subscriptions.push({ dispose: offResizeStart })
1386
+ if (typeof offResizeEnd === 'function') subscriptions.push({ dispose: offResizeEnd })
1387
+ }
1388
+ } catch {
1389
+ /* ignore */
1390
+ }
1391
+
1166
1392
  G.__gufaEditorDebug = {
1167
1393
  focus: () => {
1168
1394
  try {
@@ -1226,6 +1452,7 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
1226
1452
  lintTimers.clear()
1227
1453
  }
1228
1454
  const runLint = async (model, path) => {
1455
+ if (GUFA_LINT_ENABLED !== true) return
1229
1456
  if (model === null || model === undefined || typeof path !== 'string' || path === '') return
1230
1457
  const language = typeof model.getLanguageId === 'function' ? model.getLanguageId() : ''
1231
1458
  if (language !== 'javascript' && language !== 'typescript') return
@@ -1263,6 +1490,7 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
1263
1490
  }
1264
1491
  }
1265
1492
  const scheduleLint = (model, path) => {
1493
+ if (GUFA_LINT_ENABLED !== true) return
1266
1494
  if (model === null || model === undefined || typeof path !== 'string' || path === '') return
1267
1495
  const previous = lintTimers.get(path)
1268
1496
  if (previous !== undefined) window.clearTimeout(previous)
@@ -1353,6 +1581,20 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
1353
1581
  }
1354
1582
  }, [attempt, reportCursor, disposeAllModels])
1355
1583
 
1584
+ /* TS 内置 lib(parseInt 等)标签是只读预览 */
1585
+ const activeExternal = activeTab !== null && activeTab.external === true
1586
+ useEffect(() => {
1587
+ if (status !== 'ready') return undefined
1588
+ const instance = editorRef.current
1589
+ if (instance === null || instance === undefined) return undefined
1590
+ try {
1591
+ instance.updateOptions({ readOnly: activeExternal })
1592
+ } catch {
1593
+ /* ignore */
1594
+ }
1595
+ return undefined
1596
+ }, [activeExternal, status])
1597
+
1356
1598
  /* ── 同步 tabs ↔ models,并切换当前 model ──────────────────────── */
1357
1599
  useEffect(() => {
1358
1600
  if (status !== 'ready') return
@@ -558,6 +558,8 @@ function GufaTerminalView(props) {
558
558
 
559
559
  const fitNow = () => {
560
560
  if (fit === null || term === null || disposed) return
561
+ /* 拖分割条时尺寸每帧都在变,xterm.fit() 很重;等 layout:resize-end 一次算到位 */
562
+ if (G.__gufaSplitterDragging === true) return
561
563
  const host = hostRef.current
562
564
  if (host === null || host.clientWidth <= 0 || host.clientHeight <= 0) return
563
565
  try {
@@ -959,12 +961,19 @@ function GufaTerminalView(props) {
959
961
  openFrame = window.requestAnimationFrame(tryOpen)
960
962
  }
961
963
  props.register(terminalId, channel)
964
+ const offLayoutEnd = G.bus === null || G.bus === undefined || typeof G.bus.on !== 'function'
965
+ ? () => {}
966
+ : G.bus.on('layout:resize-end', () => {
967
+ fitNow()
968
+ sendCurrentSize()
969
+ })
962
970
 
963
971
  startStream()
964
972
  if (mode === 'xterm') tryOpen()
965
973
 
966
974
  return () => {
967
975
  disposed = true
976
+ try { offLayoutEnd() } catch { /* ignore */ }
968
977
  if (retryTimer !== null) clearTimeout(retryTimer)
969
978
  if (replayTimer !== null) clearTimeout(replayTimer)
970
979
  if (openFrame !== 0) window.cancelAnimationFrame(openFrame)
@@ -1489,7 +1498,7 @@ G.TerminalPane = function TerminalPane(props) {
1489
1498
  {
1490
1499
  className: 'gufa-termpane',
1491
1500
  style: {
1492
- height,
1501
+ height: `var(--gufa-h-terminal, ${height}px)`,
1493
1502
  flex: '0 0 auto',
1494
1503
  display: 'flex',
1495
1504
  flexDirection: 'column',
@@ -469,6 +469,31 @@ G.ChatDock = function ChatDock(props) {
469
469
  }
470
470
  }, [active, undock, props.backdrop])
471
471
 
472
+ /* 拖拽分割条时的轻量重定位:只改宿主几何,不 getComputedStyle、不读自身 rect、不 setState。
473
+ 完整 tick 每次都会 getComputedStyle + 最多两次 getBoundingClientRect,按帧跑会把拖拽拖卡。 */
474
+ const lightTickRef = useRef(null)
475
+ const lightTick = useCallback(() => {
476
+ const host = hostRef.current
477
+ if (host === null) return
478
+ const root = dockRef.current.root
479
+ if (root === null) return
480
+ try {
481
+ const rect = host.getBoundingClientRect()
482
+ if (!(rect.width >= 80 && rect.height >= 80)) return
483
+ root.style.position = 'fixed'
484
+ root.style.left = `${Math.round(rect.left)}px`
485
+ root.style.top = `${Math.round(rect.top)}px`
486
+ root.style.width = `${Math.round(rect.width)}px`
487
+ root.style.height = `${Math.round(rect.height)}px`
488
+ root.style.setProperty('--dsh-conversation-column-width', `${Math.round(rect.width)}px`)
489
+ } catch {
490
+ /* ignore */
491
+ }
492
+ }, [])
493
+ useEffect(() => {
494
+ lightTickRef.current = lightTick
495
+ }, [lightTick])
496
+
472
497
  useEffect(() => {
473
498
  tickRef.current = tick
474
499
  }, [tick])
@@ -513,6 +538,36 @@ G.ChatDock = function ChatDock(props) {
513
538
  tickRef.current?.()
514
539
  }, [props.width, props.backdrop])
515
540
 
541
+ // 拖拽过程中宽高每帧变化(App 不重渲染),DSH 浮层需要跟着宿主矩形逐帧重定位
542
+ useEffect(() => {
543
+ if (G.bus === undefined || G.bus === null || typeof G.bus.on !== 'function') return undefined
544
+ let frame = 0
545
+ let lastTickAt = 0
546
+ const off = G.bus.on('layout:resize', (detail) => {
547
+ /* 只有横向聊天栏/宽度变化才需要动 DSH 浮层;终端高度拖拽不用每帧重定位 */
548
+ const varName = detail !== null && detail !== undefined && typeof detail.varName === 'string' ? detail.varName : ''
549
+ if (varName !== '' && varName !== '--gufa-w-chat') return
550
+ /* 拖拽中 20fps 足够跟上视觉;每帧 getBoundingClientRect 会强制布局,反而拖慢分割条 */
551
+ const now = Date.now()
552
+ if (now - lastTickAt < 45) return
553
+ lastTickAt = now
554
+ if (frame !== 0) return
555
+ frame = typeof requestAnimationFrame === 'function' ? requestAnimationFrame(() => {
556
+ frame = 0
557
+ lightTickRef.current?.()
558
+ }) : window.setTimeout(() => { frame = 0; lightTickRef.current?.() }, 16)
559
+ })
560
+ return () => {
561
+ try { off?.() } catch { /* ignore */ }
562
+ if (frame !== 0) {
563
+ try {
564
+ if (typeof cancelAnimationFrame === 'function') cancelAnimationFrame(frame)
565
+ else window.clearTimeout(frame)
566
+ } catch { /* ignore */ }
567
+ }
568
+ }
569
+ }, [])
570
+
516
571
  const newSession = useCallback(() => {
517
572
  const ui = G.ctx === null || G.ctx === undefined ? undefined : G.ctx.get('uiWorkspace')
518
573
  if (ui === undefined || ui === null || typeof ui.startSession !== 'function') {