dsh-gufa-code 1.3.109 → 1.3.113

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
@@ -41,6 +41,7 @@ dsh plugin add dsh-gufa-code
41
41
  - Monaco 编辑器(离线随包分发,无需联网下载);Monaco 自带 81 种语言全部映射(ABAP、Apex、Clojure、Elixir、F#、GraphQL、HCL/Terraform、Julia、Objective-C、Pascal、Perl、Protobuf、R、RST、Scheme、Solidity、SystemVerilog/Verilog、Tcl、TypeSpec、VB、WGSL、Bicep、Batch、CoffeeScript、Cypher、DAX、Logstash/ECL、MIPS、Power Query、Q#、Redis、SPARQL、Structured Text、Modula-3、ATS、Pony 系列等);
42
42
  - **HTML 模板语法高亮**:EJS / Eta、ERB、Nunjucks / Jinja2(`.njk/.nunjucks/.jinja/.jinja2/.j2`)、Blade(`.blade.php`)、Haml、Slim,以及 Monaco 内置的 Handlebars / Mustache / Pug / Twig / Liquid / Razor / FreeMarker;扩展名自动识别;
43
43
  - 多标签、按扩展名语法高亮、面包屑、状态栏(分支 / 行列 / 保存状态);
44
+ - **AI/外部修改自动刷新**:已打开的标签每 1.6s 检查一次磁盘 mtime/size,AI 在会话里改完代码后编辑器自动换成新内容(保留光标位置),不需要关闭重开;点击文件树里的已打开文件也会重新对齐磁盘;有未保存修改时不会覆盖用户内容;
44
45
  - **Copilot 风格 Tab 行内补全**:光标停/打字后,基于 Harness 自己的 DeepSeek 模型(默认 `deepseek-flash`,不需要额外 Copilot 订阅)流式生成灰色 ghost text,Tab 接受、Esc 忽略;支持 JS/TS/Python/Java/Go/Rust/C++/C#/JSON/YAML/Shell 等常见语言;
45
46
  - 保存走磁盘版本冲突检测 + 原子写;未保存标记;
46
47
  - **⌘/Ctrl + 点击跳转定义 / 方法实现**:Python 走 **Pyright 语言服务(LSP)**,JS/TS 走 Monaco 内置 TypeScript 语言服务(点击前会按需把当前文件的 import 依赖加载进 Monaco,跨文件变量/函数由 TS 语言服务解析);其他语言暂用项目级定义搜索兜底;优先走 Monaco 语言服务;目标文件没在 Monaco 里打开、或语言没有内置语言服务时,自动用项目级定义搜索兜底(函数 / 类 / 方法 / const / type 等声明)。兜底会解析 import/require 直接定位来源文件,并跳过压缩产物/大文件;同一个文件里的声明、import 命中的定义、目录距离近的定义直接跳,只有多个真正同名的声明才弹「跳转到定义」列表,点同名属性/变量时不会拿远端无关的 const 来凑数;按住 ⌘/Ctrl 悬停时,可跳转的符号会显示下划线 + 手型光标;
@@ -63,7 +64,7 @@ dsh plugin add dsh-gufa-code
63
64
  ### 左侧面板
64
65
 
65
66
  - **资源管理器**:懒加载文件树、Git 状态颜色、错误/问题点、目录改动标记;
66
- - **源代码管理**:分支、ahead/behind(点击可推送/拉取)、更改列表、暂存/取消暂存、提交(`⌘⇧↵`,自动暂存未暂存改动)、Git Graph(泳道图 + 提交文件 + 查看某次提交的文件)、撤销上次提交、丢弃全部、逐文件还原;
67
+ - **源代码管理**:分支、ahead/behind(点击可推送/拉取)、更改列表、暂存/取消暂存、提交(`⌘⇧↵`,只提交已暂存的改动;未暂存改动需先手动「全部暂存」)、Git Graph(泳道图 + 提交文件 + 查看某次提交的文件)、撤销上次提交、丢弃全部、逐文件还原;
67
68
  - **SSH**:解析 `~/.ssh/config`,点一下就在终端里 `ssh <alias>`;
68
69
  - **终端**:真实 PTY + xterm,多标签、新建/关闭、自动 resize、明暗主题,SSH 与任意命令都行。
69
70
 
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.109'
19
+ G.BUILD = '1.3.113'
20
20
  G.PANEL_ID = 'gufa-code'
21
21
  /** 从哪个工作区点进来的(工作区菜单/节点按钮写入,App 启动时消费)。 */
22
22
  G.pendingEntryWorkspace = null
@@ -261,7 +261,7 @@ const DICT_ZH = {
261
261
  'git.pull': '拉取',
262
262
  'git.noUpstreamHint': '当前分支还没有上游:点标题栏 ↑ 推送一次即可自动创建上游(git push -u)',
263
263
  'git.discardFile': '还原该文件的改动',
264
- 'git.autoStageHint': '提交时会自动暂存所有未暂存改动(也可以先手动选择要暂存的文件)',
264
+ 'git.commitStagedOnlyHint': '只提交「已暂存」的改动;未暂存的改动会留在工作区',
265
265
  'git.commitNeedsMessage': '请先填写提交信息,再按 ⌘⇧↵ 提交',
266
266
  'git.more': '更多操作',
267
267
  'git.viewDiff': '查看改动对比',
@@ -511,7 +511,7 @@ const DICT_EN = {
511
511
  'git.pull': 'Pull',
512
512
  'git.noUpstreamHint': 'No upstream for this branch yet: click ↑ in the header to push once (auto git push -u)',
513
513
  'git.discardFile': 'Revert this file',
514
- 'git.autoStageHint': 'Committing auto-stages all unstaged changes',
514
+ 'git.commitStagedOnlyHint': 'Only staged changes are committed; unstaged changes stay in the working tree',
515
515
  'git.commitNeedsMessage': 'Write a commit message first, then press ⌘⇧↵',
516
516
  'git.more': 'More actions',
517
517
  'git.viewDiff': 'View diff',
@@ -3852,6 +3852,53 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
3852
3852
  /* ignore */
3853
3853
  }
3854
3854
 
3855
+ /* 外部/AI 修改磁盘后由 App 轮询发现,通过 bus 通知编辑器热替换 model 内容 */
3856
+ try {
3857
+ if (G.bus !== null && G.bus !== undefined && typeof G.bus.on === 'function') {
3858
+ const offExternalReload = G.bus.on('editor:external-reload', (detail) => {
3859
+ if (detail === null || detail === undefined || typeof detail.path !== 'string' || typeof detail.content !== 'string') return
3860
+ const target = modelsRef.current.get(detail.path)
3861
+ if (target === null || target === undefined) return
3862
+ let content = ''
3863
+ try {
3864
+ content = target.getValue()
3865
+ } catch {
3866
+ return
3867
+ }
3868
+ if (content === detail.content) return
3869
+ const active = modelPathRef.current === detail.path
3870
+ let position = null
3871
+ let scrollTop = 0
3872
+ if (active) {
3873
+ try {
3874
+ position = instance.getPosition()
3875
+ scrollTop = instance.getScrollTop()
3876
+ } catch {
3877
+ position = null
3878
+ }
3879
+ }
3880
+ suppressChangeRef.current = true
3881
+ try {
3882
+ target.setValue(detail.content)
3883
+ } finally {
3884
+ suppressChangeRef.current = false
3885
+ }
3886
+ lastPropContentRef.current.set(detail.path, detail.content)
3887
+ if (active && position !== null && position !== undefined) {
3888
+ try {
3889
+ instance.setPosition(position)
3890
+ instance.setScrollTop(scrollTop)
3891
+ } catch {
3892
+ /* ignore */
3893
+ }
3894
+ }
3895
+ })
3896
+ if (typeof offExternalReload === 'function') subscriptions.push({ dispose: offExternalReload })
3897
+ }
3898
+ } catch {
3899
+ /* ignore */
3900
+ }
3901
+
3855
3902
  G.__gufaEditorDebug = {
3856
3903
  focus: () => {
3857
3904
  try {
@@ -8754,10 +8801,12 @@ G.GitPanel = function GitPanel(props) {
8754
8801
  setError(t('git.commitNeedsMessage'))
8755
8802
  return
8756
8803
  }
8804
+ if (staged.length === 0) {
8805
+ setError(t('git.noStagedHint'))
8806
+ return
8807
+ }
8757
8808
  void act(async () => {
8758
- // 直接点「提交」或按快捷键时:未暂存的改动自动全部暂存,再提交
8759
- const toStage = changes.filter((item) => item.staged !== true).map((item) => item.path)
8760
- if (toStage.length > 0) await G.api('git.stage', { root, paths: toStage })
8809
+ /* 只提交「已暂存」的改动;未暂存改动保持原样(需要时用「全部暂存」) */
8761
8810
  await G.api('git.commit', { root, message: text })
8762
8811
  setMessage('')
8763
8812
  })
@@ -8943,15 +8992,15 @@ G.GitPanel = function GitPanel(props) {
8943
8992
  },
8944
8993
  )
8945
8994
  : null,
8946
- changes.length > 0 && unstaged.length > 0
8947
- ? h('div', { className: 'gufa-hint' }, t('git.autoStageHint'))
8995
+ changes.length > 0
8996
+ ? h('div', { className: 'gufa-hint' }, staged.length === 0 ? t('git.noStagedHint') : t('git.commitStagedOnlyHint'))
8948
8997
  : null,
8949
8998
  changes.length > 0
8950
8999
  ? h(
8951
9000
  'div',
8952
9001
  { className: 'gufa-row', style: { justifyContent: 'flex-end', alignItems: 'center', gap: 8 } },
8953
9002
  staged.length > 0 ? h('span', { className: 'gufa-hint' }, `${t('git.staged')} (${staged.length})`) : null,
8954
- h(G.Button, { disabled: pending || message.trim() === '', primary: true, onClick: commit }, pending ? h(G.Spinner) : null, t('git.commit')),
9003
+ h(G.Button, { disabled: pending || message.trim() === '' || staged.length === 0, primary: true, onClick: commit }, pending ? h(G.Spinner) : null, t('git.commit')),
8955
9004
  )
8956
9005
  : null,
8957
9006
  staged.length > 0 ? h('div', { className: 'gufa-hint' }, `${t('git.staged')} (${staged.length})`) : null,
@@ -12105,6 +12154,7 @@ G.GufaApp = function GufaApp(props) {
12105
12154
  /* 编辑器内容缓冲:Monaco 每次按键只写这里,300ms 停顿后才同步进 tabs(保存/自动保存直接读缓冲)。 */
12106
12155
  const editorBuffersRef = useRef(new Map())
12107
12156
  const tabsRef = useRef([])
12157
+ const reloadTabFromDiskRef = useRef(null)
12108
12158
  const flushTimerRef = useRef(null)
12109
12159
  const selectionTimerRef = useRef(null)
12110
12160
  const pendingSelectionRef = useRef(null)
@@ -12331,6 +12381,12 @@ G.GufaApp = function GufaApp(props) {
12331
12381
  flushBuffersRef.current?.()
12332
12382
  const existing = tabs.find((tab) => tab.path === path)
12333
12383
  if (existing !== undefined) {
12384
+ /* 已经打开的文件再次点击:先对齐磁盘最新版本(AI/外部修改后不用关掉重开) */
12385
+ try {
12386
+ await reloadTabFromDiskRef.current?.(path)
12387
+ } catch {
12388
+ /* ignore */
12389
+ }
12334
12390
  setActivePath(path)
12335
12391
  return
12336
12392
  }
@@ -12417,6 +12473,84 @@ G.GufaApp = function GufaApp(props) {
12417
12473
  })
12418
12474
  }, [])
12419
12475
 
12476
+ /* 把某个已打开标签重新对齐磁盘内容(AI/外部修改检测、点击文件树时使用)。
12477
+ 有未保存修改(dirty)时绝不覆盖用户内容。 */
12478
+ const reloadTabFromDisk = useCallback(async (path) => {
12479
+ if (project === null) return false
12480
+ const tab = (tabsRef.current ?? []).find((item) => item !== null && item !== undefined && item.path === path)
12481
+ if (tab === undefined || tab.kind === 'diff' || tab.kind === 'graph') return false
12482
+ try {
12483
+ const doc = await G.api('fs.read', { root: project.root, path })
12484
+ const latest = (tabsRef.current ?? []).find((item) => item !== null && item !== undefined && item.path === path)
12485
+ if (latest === undefined || latest.dirty === true) return false
12486
+ if (latest.revision === doc.revision && latest.content === doc.content) return false
12487
+ editorBuffersRef.current.delete(path)
12488
+ patchTab(path, {
12489
+ content: doc.content,
12490
+ revision: doc.revision,
12491
+ savedRevision: doc.revision,
12492
+ savedContent: doc.content,
12493
+ dirty: false,
12494
+ size: doc.size,
12495
+ mtimeMs: doc.mtimeMs,
12496
+ })
12497
+ try {
12498
+ G.bus.emit('editor:external-reload', { path, content: doc.content })
12499
+ } catch {
12500
+ /* ignore */
12501
+ }
12502
+ return true
12503
+ } catch {
12504
+ return false
12505
+ }
12506
+ }, [project, patchTab])
12507
+ reloadTabFromDiskRef.current = reloadTabFromDisk
12508
+
12509
+ /* AI/外部进程修改磁盘文件:轮询已打开且未修改的标签,自动同步编辑器和标签内容。
12510
+ 1.6s 一次 fs.mtimes(只 stat),发现 mtime/size 变化才 fs.read 全文。 */
12511
+ useEffect(() => {
12512
+ if (project === null) return undefined
12513
+ let cancelled = false
12514
+ let busy = false
12515
+ const sync = async () => {
12516
+ if (busy || cancelled || document.visibilityState !== 'visible') return
12517
+ busy = true
12518
+ try {
12519
+ const open = (tabsRef.current ?? []).filter((tab) => tab !== null && tab !== undefined
12520
+ && typeof tab.path === 'string' && tab.kind !== 'diff' && tab.kind !== 'graph')
12521
+ const clean = open.filter((tab) => tab.dirty !== true).slice(0, 24)
12522
+ if (clean.length === 0) return
12523
+ let result = null
12524
+ try {
12525
+ result = await G.api('fs.mtimes', { root: project.root, paths: clean.map((tab) => tab.path) })
12526
+ } catch {
12527
+ return
12528
+ }
12529
+ const files = result !== null && result !== undefined && result.files !== null && result.files !== undefined ? result.files : {}
12530
+ for (const tab of clean) {
12531
+ if (cancelled) break
12532
+ const info = files[tab.path]
12533
+ if (info === null || info === undefined || info.missing === true) continue
12534
+ if (Number(info.mtimeMs) === Number(tab.mtimeMs) && Number(info.size) === Number(tab.size)) continue
12535
+ await reloadTabFromDisk(tab.path)
12536
+ }
12537
+ } finally {
12538
+ busy = false
12539
+ }
12540
+ }
12541
+ const timer = window.setInterval(() => { void sync() }, 1600)
12542
+ const onVisible = () => { if (document.visibilityState === 'visible') void sync() }
12543
+ window.addEventListener('focus', onVisible)
12544
+ document.addEventListener('visibilitychange', onVisible)
12545
+ void sync()
12546
+ return () => {
12547
+ cancelled = true
12548
+ window.clearInterval(timer)
12549
+ window.removeEventListener('focus', onVisible)
12550
+ document.removeEventListener('visibilitychange', onVisible)
12551
+ }
12552
+ }, [project, reloadTabFromDisk])
12553
+
12420
12554
  /* 把缓冲内容写回 tabs(停顿 / 保存 / 切换标签时调用),不会在每次按键触发渲染。 */
12421
12555
  const flushEditorBuffers = useCallback(() => {
12422
12556
  const buffers = editorBuffersRef.current
@@ -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.109</string>
11
- <key>CFBundleVersion</key><string>1.3.109</string>
10
+ <key>CFBundleShortVersionString</key><string>1.3.113</string>
11
+ <key>CFBundleVersion</key><string>1.3.113</string>
12
12
  <key>LSUIElement</key><true/>
13
13
  <key>NSHighResolutionCapable</key><true/>
14
14
  <key>NSPrincipalClass</key><string>NSApplication</string>
@@ -63,6 +63,19 @@
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
 
66
+ ## 0.12 AI/外部修改后编辑器自动刷新(1.3.112)
67
+
68
+ - 不能只在 Git 签名变化时刷新资源管理器:已打开标签的**内容**不会自己变,用户必须关掉重开;点击文件树时 `openFile` 对已存在标签只 `setActivePath`,也不会重新读盘。
69
+ - 方案:Host 新增 `fs.mtimes`(批量 stat,只返回 mtimeMs/size,不读全文);客户端每 1.6s 对可见窗口里的已打开干净标签轮询,mtime/size 变了才 `fs.read` 并更新 tab;`dirty` 标签绝不覆盖。
70
+ - 更新 Monaco model 不能只靠 App 的 props 同步:编辑器聚焦时同步 effect 会故意跳过外部内容以避免覆盖输入。App 通过 `G.bus.emit('editor:external-reload', {path, content})` 通知 EditorPane 直接 `model.setValue`,用 `suppressChangeRef` 防止把这次更新当用户输入回传,并恢复光标/滚动;同时写 `lastPropContentRef` 避免后续 props 同步再灌一次。
71
+ - 点击已打开文件(文件树/搜索)时也要先 `reloadTabFromDisk`,否则用户点文件列表看不到 AI 改动。
72
+
73
+ ## 0.13 Git 提交只提交已暂存(1.3.113)
74
+
75
+ - 旧实现里客户端点「提交」会先 `git.stage` 所有未暂存文件再 `git.commit`,导致用户只想提交暂存区却把所有改动都提交了。**提交按钮/⌘⇧↵ 绝不能自动暂存**。
76
+ - 正确行为:`staged.length === 0` 时直接提示 `git.noStagedHint` 并禁用提交;有暂存时只调 `git.commit`(Host 本来就是 `git commit -m`,只消费 index)。未暂存改动保留在工作区,需要时用「全部暂存」。
77
+ - 单测覆盖:暂存 `src/staged.ts`、保留未跟踪 `src/unstaged.ts` 后提交,断言 unstaged 文件不在 HEAD 且仍出现在 status 的未暂存列表里。
78
+
66
79
  ## 1. 弹窗/菜单层级:只有一个正确做法(反复踩过多次,最终定案)
67
80
 
68
81
  **现象**:弹窗被右侧「古法 AI」聊天栏压住、只显示一半、关闭按钮点不到;或者反过来把官方设置/会话弹窗盖住。
package/host/fs.js CHANGED
@@ -346,6 +346,23 @@ export function register(router, env) {
346
346
  return { path: relativePath(root, absolute), entries: rows }
347
347
  })
348
348
 
349
+ /* 批量取 mtime/size:客户端轮询已打开文件是否被 AI/外部修改,避免每个文件都 fs.read 全文 */
350
+ router.method('fs.mtimes', async (body) => {
351
+ const root = await projectOf(env, body)
352
+ const paths = Array.isArray(body.paths) ? body.paths.filter((value) => typeof value === 'string' && value !== '').slice(0, 100) : []
353
+ const files = {}
354
+ for (const path of paths) {
355
+ try {
356
+ const absolute = await resolveProjectPath(root, path)
357
+ const info = await stat(absolute)
358
+ files[path] = { mtimeMs: info.mtimeMs, size: info.size, missing: false }
359
+ } catch {
360
+ files[path] = { missing: true }
361
+ }
362
+ }
363
+ return { files }
364
+ })
365
+
349
366
  router.method('fs.read', async (body) => {
350
367
  const root = await projectOf(env, body)
351
368
  const absolute = await resolveProjectPath(root, body.path)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-gufa-code",
3
- "version": "1.3.109",
3
+ "version": "1.3.113",
4
4
  "description": "古法编程 · AI 辅助:一键把 DSH 主面板变成 VS Code 风格 IDE(Monaco 编辑器、文件树、Git、SSH、真实终端 + 右侧官方会话);主张亲手写、每个改动心中有数,AI 是助理、你是第一责任人",
5
5
  "icon": "icon.svg",
6
6
  "keywords": [
@@ -126,6 +126,13 @@ try {
126
126
  ['.babelrc', 'json'], ['.gitconfig', 'ini'],
127
127
  ]
128
128
  for (const [file, expected] of languageCases) check(`languageOf ${file} -> ${expected}`, fs.languageOf(file) === expected, fs.languageOf(file))
129
+ console.log('fs.mtimes')
130
+ const mtimes = await call(router, 'fs.mtimes', { root, paths: ['src/main.ts', 'missing-file.txt'] })
131
+ check('fs.mtimes returns mtime/size', typeof mtimes.files['src/main.ts']?.mtimeMs === 'number' && mtimes.files['src/main.ts']?.size > 0)
132
+ check('fs.mtimes marks missing file', mtimes.files['missing-file.txt']?.missing === true)
133
+ const missingMtimes = await call(router, 'fs.mtimes', { root, paths: [] })
134
+ check('fs.mtimes handles empty list', missingMtimes.files !== null && typeof missingMtimes.files === 'object' && Object.keys(missingMtimes.files).length === 0)
135
+
129
136
  console.log('fs.search')
130
137
  await call(router, 'fs.create', { root, path: 'search.txt', kind: 'file' })
131
138
  await call(router, 'fs.write', { root, path: 'search.txt', content: 'Alpha beta\nBETA gamma\nbeta BETA\n' })
@@ -171,6 +178,21 @@ try {
171
178
  check('git.show HEAD content', headShow.text === 'const answer = 42\n', JSON.stringify(headShow.text))
172
179
  const indexShow = await call(router, 'git.show', { root, path: 'src/main.ts', rev: 'index' })
173
180
  check('git.show index content', indexShow.text === 'const answer = 42\n', JSON.stringify(indexShow.text))
181
+ /* 只提交已暂存改动:未暂存文件不能进 commit */
182
+ await call(router, 'fs.create', { root, path: 'src/staged.ts', kind: 'file' })
183
+ await call(router, 'fs.write', { root, path: 'src/staged.ts', content: 'export const stagedOnly = 1\n' })
184
+ await call(router, 'fs.create', { root, path: 'src/unstaged.ts', kind: 'file' })
185
+ await call(router, 'fs.write', { root, path: 'src/unstaged.ts', content: 'export const unstagedOnly = 2\n' })
186
+ await call(router, 'git.stage', { root, paths: ['src/staged.ts'] })
187
+ await call(router, 'git.commit', { root, message: 'feat: staged only' })
188
+ const afterStagedOnly = await call(router, 'git.status', { root })
189
+ check('commit keeps unstaged file out', afterStagedOnly.changes.some((change) => change.path === 'src/unstaged.ts' && change.staged !== true), JSON.stringify(afterStagedOnly.changes))
190
+ check('commit includes staged file', !afterStagedOnly.changes.some((change) => change.path === 'src/staged.ts'), JSON.stringify(afterStagedOnly.changes))
191
+ const stagedOnlyHead = await call(router, 'git.show', { root, path: 'src/staged.ts', rev: 'head' })
192
+ check('staged file in commit', stagedOnlyHead.text === 'export const stagedOnly = 1\n', JSON.stringify(stagedOnlyHead.text))
193
+ const unstagedHead = await call(router, 'git.show', { root, path: 'src/unstaged.ts', rev: 'head' })
194
+ check('unstaged file not in commit', unstagedHead.missing === true)
195
+
174
196
  const gitSearch = await call(router, 'fs.search', { root, query: 'answer' })
175
197
  check('search uses git file list', gitSearch.viaGit === true, String(gitSearch.viaGit))
176
198
  check('search finds committed file', gitSearch.files.some((file) => file.path === 'src/main.ts'))
@@ -253,7 +253,7 @@ const DICT_ZH = {
253
253
  'git.pull': '拉取',
254
254
  'git.noUpstreamHint': '当前分支还没有上游:点标题栏 ↑ 推送一次即可自动创建上游(git push -u)',
255
255
  'git.discardFile': '还原该文件的改动',
256
- 'git.autoStageHint': '提交时会自动暂存所有未暂存改动(也可以先手动选择要暂存的文件)',
256
+ 'git.commitStagedOnlyHint': '只提交「已暂存」的改动;未暂存的改动会留在工作区',
257
257
  'git.commitNeedsMessage': '请先填写提交信息,再按 ⌘⇧↵ 提交',
258
258
  'git.more': '更多操作',
259
259
  'git.viewDiff': '查看改动对比',
@@ -503,7 +503,7 @@ const DICT_EN = {
503
503
  'git.pull': 'Pull',
504
504
  'git.noUpstreamHint': 'No upstream for this branch yet: click ↑ in the header to push once (auto git push -u)',
505
505
  'git.discardFile': 'Revert this file',
506
- 'git.autoStageHint': 'Committing auto-stages all unstaged changes',
506
+ 'git.commitStagedOnlyHint': 'Only staged changes are committed; unstaged changes stay in the working tree',
507
507
  'git.commitNeedsMessage': 'Write a commit message first, then press ⌘⇧↵',
508
508
  'git.more': 'More actions',
509
509
  'git.viewDiff': 'View diff',
@@ -1228,6 +1228,53 @@ const GUFA_DEFINITION_STRONG_KINDS = new Set(['function', 'class', 'method', 'de
1228
1228
  /* ignore */
1229
1229
  }
1230
1230
 
1231
+ /* 外部/AI 修改磁盘后由 App 轮询发现,通过 bus 通知编辑器热替换 model 内容 */
1232
+ try {
1233
+ if (G.bus !== null && G.bus !== undefined && typeof G.bus.on === 'function') {
1234
+ const offExternalReload = G.bus.on('editor:external-reload', (detail) => {
1235
+ if (detail === null || detail === undefined || typeof detail.path !== 'string' || typeof detail.content !== 'string') return
1236
+ const target = modelsRef.current.get(detail.path)
1237
+ if (target === null || target === undefined) return
1238
+ let content = ''
1239
+ try {
1240
+ content = target.getValue()
1241
+ } catch {
1242
+ return
1243
+ }
1244
+ if (content === detail.content) return
1245
+ const active = modelPathRef.current === detail.path
1246
+ let position = null
1247
+ let scrollTop = 0
1248
+ if (active) {
1249
+ try {
1250
+ position = instance.getPosition()
1251
+ scrollTop = instance.getScrollTop()
1252
+ } catch {
1253
+ position = null
1254
+ }
1255
+ }
1256
+ suppressChangeRef.current = true
1257
+ try {
1258
+ target.setValue(detail.content)
1259
+ } finally {
1260
+ suppressChangeRef.current = false
1261
+ }
1262
+ lastPropContentRef.current.set(detail.path, detail.content)
1263
+ if (active && position !== null && position !== undefined) {
1264
+ try {
1265
+ instance.setPosition(position)
1266
+ instance.setScrollTop(scrollTop)
1267
+ } catch {
1268
+ /* ignore */
1269
+ }
1270
+ }
1271
+ })
1272
+ if (typeof offExternalReload === 'function') subscriptions.push({ dispose: offExternalReload })
1273
+ }
1274
+ } catch {
1275
+ /* ignore */
1276
+ }
1277
+
1231
1278
  G.__gufaEditorDebug = {
1232
1279
  focus: () => {
1233
1280
  try {
@@ -1147,10 +1147,12 @@ G.GitPanel = function GitPanel(props) {
1147
1147
  setError(t('git.commitNeedsMessage'))
1148
1148
  return
1149
1149
  }
1150
+ if (staged.length === 0) {
1151
+ setError(t('git.noStagedHint'))
1152
+ return
1153
+ }
1150
1154
  void act(async () => {
1151
- // 直接点「提交」或按快捷键时:未暂存的改动自动全部暂存,再提交
1152
- const toStage = changes.filter((item) => item.staged !== true).map((item) => item.path)
1153
- if (toStage.length > 0) await G.api('git.stage', { root, paths: toStage })
1155
+ /* 只提交「已暂存」的改动;未暂存改动保持原样(需要时用「全部暂存」) */
1154
1156
  await G.api('git.commit', { root, message: text })
1155
1157
  setMessage('')
1156
1158
  })
@@ -1336,15 +1338,15 @@ G.GitPanel = function GitPanel(props) {
1336
1338
  },
1337
1339
  )
1338
1340
  : null,
1339
- changes.length > 0 && unstaged.length > 0
1340
- ? h('div', { className: 'gufa-hint' }, t('git.autoStageHint'))
1341
+ changes.length > 0
1342
+ ? h('div', { className: 'gufa-hint' }, staged.length === 0 ? t('git.noStagedHint') : t('git.commitStagedOnlyHint'))
1341
1343
  : null,
1342
1344
  changes.length > 0
1343
1345
  ? h(
1344
1346
  'div',
1345
1347
  { className: 'gufa-row', style: { justifyContent: 'flex-end', alignItems: 'center', gap: 8 } },
1346
1348
  staged.length > 0 ? h('span', { className: 'gufa-hint' }, `${t('git.staged')} (${staged.length})`) : null,
1347
- h(G.Button, { disabled: pending || message.trim() === '', primary: true, onClick: commit }, pending ? h(G.Spinner) : null, t('git.commit')),
1349
+ h(G.Button, { disabled: pending || message.trim() === '' || staged.length === 0, primary: true, onClick: commit }, pending ? h(G.Spinner) : null, t('git.commit')),
1348
1350
  )
1349
1351
  : null,
1350
1352
  staged.length > 0 ? h('div', { className: 'gufa-hint' }, `${t('git.staged')} (${staged.length})`) : null,
@@ -255,6 +255,7 @@ G.GufaApp = function GufaApp(props) {
255
255
  /* 编辑器内容缓冲:Monaco 每次按键只写这里,300ms 停顿后才同步进 tabs(保存/自动保存直接读缓冲)。 */
256
256
  const editorBuffersRef = useRef(new Map())
257
257
  const tabsRef = useRef([])
258
+ const reloadTabFromDiskRef = useRef(null)
258
259
  const flushTimerRef = useRef(null)
259
260
  const selectionTimerRef = useRef(null)
260
261
  const pendingSelectionRef = useRef(null)
@@ -481,6 +482,12 @@ G.GufaApp = function GufaApp(props) {
481
482
  flushBuffersRef.current?.()
482
483
  const existing = tabs.find((tab) => tab.path === path)
483
484
  if (existing !== undefined) {
485
+ /* 已经打开的文件再次点击:先对齐磁盘最新版本(AI/外部修改后不用关掉重开) */
486
+ try {
487
+ await reloadTabFromDiskRef.current?.(path)
488
+ } catch {
489
+ /* ignore */
490
+ }
484
491
  setActivePath(path)
485
492
  return
486
493
  }
@@ -567,6 +574,84 @@ G.GufaApp = function GufaApp(props) {
567
574
  })
568
575
  }, [])
569
576
 
577
+ /* 把某个已打开标签重新对齐磁盘内容(AI/外部修改检测、点击文件树时使用)。
578
+ 有未保存修改(dirty)时绝不覆盖用户内容。 */
579
+ const reloadTabFromDisk = useCallback(async (path) => {
580
+ if (project === null) return false
581
+ const tab = (tabsRef.current ?? []).find((item) => item !== null && item !== undefined && item.path === path)
582
+ if (tab === undefined || tab.kind === 'diff' || tab.kind === 'graph') return false
583
+ try {
584
+ const doc = await G.api('fs.read', { root: project.root, path })
585
+ const latest = (tabsRef.current ?? []).find((item) => item !== null && item !== undefined && item.path === path)
586
+ if (latest === undefined || latest.dirty === true) return false
587
+ if (latest.revision === doc.revision && latest.content === doc.content) return false
588
+ editorBuffersRef.current.delete(path)
589
+ patchTab(path, {
590
+ content: doc.content,
591
+ revision: doc.revision,
592
+ savedRevision: doc.revision,
593
+ savedContent: doc.content,
594
+ dirty: false,
595
+ size: doc.size,
596
+ mtimeMs: doc.mtimeMs,
597
+ })
598
+ try {
599
+ G.bus.emit('editor:external-reload', { path, content: doc.content })
600
+ } catch {
601
+ /* ignore */
602
+ }
603
+ return true
604
+ } catch {
605
+ return false
606
+ }
607
+ }, [project, patchTab])
608
+ reloadTabFromDiskRef.current = reloadTabFromDisk
609
+
610
+ /* AI/外部进程修改磁盘文件:轮询已打开且未修改的标签,自动同步编辑器和标签内容。
611
+ 1.6s 一次 fs.mtimes(只 stat),发现 mtime/size 变化才 fs.read 全文。 */
612
+ useEffect(() => {
613
+ if (project === null) return undefined
614
+ let cancelled = false
615
+ let busy = false
616
+ const sync = async () => {
617
+ if (busy || cancelled || document.visibilityState !== 'visible') return
618
+ busy = true
619
+ try {
620
+ const open = (tabsRef.current ?? []).filter((tab) => tab !== null && tab !== undefined
621
+ && typeof tab.path === 'string' && tab.kind !== 'diff' && tab.kind !== 'graph')
622
+ const clean = open.filter((tab) => tab.dirty !== true).slice(0, 24)
623
+ if (clean.length === 0) return
624
+ let result = null
625
+ try {
626
+ result = await G.api('fs.mtimes', { root: project.root, paths: clean.map((tab) => tab.path) })
627
+ } catch {
628
+ return
629
+ }
630
+ const files = result !== null && result !== undefined && result.files !== null && result.files !== undefined ? result.files : {}
631
+ for (const tab of clean) {
632
+ if (cancelled) break
633
+ const info = files[tab.path]
634
+ if (info === null || info === undefined || info.missing === true) continue
635
+ if (Number(info.mtimeMs) === Number(tab.mtimeMs) && Number(info.size) === Number(tab.size)) continue
636
+ await reloadTabFromDisk(tab.path)
637
+ }
638
+ } finally {
639
+ busy = false
640
+ }
641
+ }
642
+ const timer = window.setInterval(() => { void sync() }, 1600)
643
+ const onVisible = () => { if (document.visibilityState === 'visible') void sync() }
644
+ window.addEventListener('focus', onVisible)
645
+ document.addEventListener('visibilitychange', onVisible)
646
+ void sync()
647
+ return () => {
648
+ cancelled = true
649
+ window.clearInterval(timer)
650
+ window.removeEventListener('focus', onVisible)
651
+ document.removeEventListener('visibilitychange', onVisible)
652
+ }
653
+ }, [project, reloadTabFromDisk])
654
+
570
655
  /* 把缓冲内容写回 tabs(停顿 / 保存 / 切换标签时调用),不会在每次按键触发渲染。 */
571
656
  const flushEditorBuffers = useCallback(() => {
572
657
  const buffers = editorBuffersRef.current