dsh-gufa-code 1.3.201 → 1.3.210

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 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.201'
19
+ G.BUILD = '1.3.210'
20
20
  G.PANEL_ID = 'gufa-code'
21
21
  /** 从哪个工作区点进来的(工作区菜单/节点按钮写入,App 启动时消费)。 */
22
22
  G.pendingEntryWorkspace = null
@@ -112,6 +112,15 @@ const DICT_ZH = {
112
112
  'dock.live': '已连接 DSH 会话',
113
113
  'dock.newSession': '新建会话',
114
114
  'dock.sessions': '切换会话(当前工作区)',
115
+ 'session.status.running': '进行中',
116
+ 'session.status.idle': '空闲',
117
+ 'session.status.done': '已完成',
118
+ 'session.status.approval': '等待审批',
119
+ 'session.status.planReview': '计划待审',
120
+ 'session.status.compact.approval': '待审批',
121
+ 'session.status.compact.planReview': '计划待审',
122
+ 'session.status.compact.question': '待回答',
123
+ 'session.status.question': '等待回答',
115
124
  'dock.sessionsTitle': '切换会话',
116
125
  'shortcuts.title': '古法编程快捷键',
117
126
  'shortcuts.save': '保存当前文件',
@@ -230,6 +239,8 @@ const DICT_ZH = {
230
239
  'explorer.rename': '重命名',
231
240
  'explorer.copy': '复制',
232
241
  'explorer.paste': '粘贴',
242
+ 'explorer.pasteEmpty': '系统剪贴板里没有可粘贴的文件或文件夹',
243
+ 'explorer.pasteDone': '已粘贴 {count} 项',
233
244
  'explorer.revealInFinder': '打开所在文件夹',
234
245
  'explorer.compareSelected': '对比',
235
246
  'explorer.changedDir': '目录内有改动',
@@ -243,6 +254,10 @@ const DICT_ZH = {
243
254
  'git.branch': '分支',
244
255
  'git.changes': '更改',
245
256
  'git.noRepo': '当前工作区不是 Git 仓库',
257
+ 'git.repos': 'Git 仓库',
258
+ 'git.deleteUntrackedFile': '删除新文件',
259
+ 'git.deleteUntrackedConfirm': '删除这个未跟踪的新文件?\n{path}\n删除后无法恢复。',
260
+ 'git.workspaceRoot': '工作区根目录',
246
261
  'git.noChanges': '工作区干净',
247
262
  'git.stage': '暂存',
248
263
  'git.unstage': '取消暂存',
@@ -289,8 +304,8 @@ const DICT_ZH = {
289
304
  'diff.next': '下一处差异',
290
305
  'diff.revertFile': '还原文件',
291
306
  'diff.stageFile': '暂存文件',
292
- 'git.discardAll': '撤销所有未暂存改动',
293
- 'git.discardConfirm': '再点一次确认撤销(未跟踪文件不会被删除)',
307
+ 'git.discardAll': '撤销所有改动(含未跟踪新文件)',
308
+ 'git.discardConfirm': '再点一次确认:未跟踪的新文件也会被删除',
294
309
  'git.committed': '已提交',
295
310
  'git.refresh': '刷新',
296
311
  'git.staged': '已暂存',
@@ -372,6 +387,15 @@ const DICT_EN = {
372
387
  'dock.live': 'Connected to the DSH session',
373
388
  'dock.newSession': 'New session',
374
389
  'dock.sessions': 'Switch session (current workspace)',
390
+ 'session.status.running': 'Running',
391
+ 'session.status.idle': 'Idle',
392
+ 'session.status.done': 'Completed',
393
+ 'session.status.approval': 'Waiting approval',
394
+ 'session.status.planReview': 'Plan awaiting review',
395
+ 'session.status.compact.approval': 'Approval',
396
+ 'session.status.compact.planReview': 'Plan review',
397
+ 'session.status.compact.question': 'Answer',
398
+ 'session.status.question': 'Waiting answer',
375
399
  'dock.sessionsTitle': 'Switch session',
376
400
  'shortcuts.title': 'Gufa Code shortcuts',
377
401
  'shortcuts.save': 'Save current file',
@@ -481,6 +505,8 @@ const DICT_EN = {
481
505
  'explorer.rename': 'Rename',
482
506
  'explorer.copy': 'Copy',
483
507
  'explorer.paste': 'Paste',
508
+ 'explorer.pasteEmpty': 'No files or folders found in the system clipboard',
509
+ 'explorer.pasteDone': 'Pasted {count} item(s)',
484
510
  'explorer.revealInFinder': 'Open Containing Folder',
485
511
  'explorer.compareSelected': 'Compare',
486
512
  'explorer.changedDir': 'Contains changes',
@@ -494,6 +520,10 @@ const DICT_EN = {
494
520
  'git.branch': 'Branch',
495
521
  'git.changes': 'Changes',
496
522
  'git.noRepo': 'This workspace is not a Git repository',
523
+ 'git.repos': 'Git repositories',
524
+ 'git.deleteUntrackedFile': 'Delete new file',
525
+ 'git.deleteUntrackedConfirm': 'Delete this untracked file?\n{path}\nThis cannot be undone.',
526
+ 'git.workspaceRoot': 'Workspace root',
497
527
  'git.noChanges': 'Working tree clean',
498
528
  'git.stage': 'Stage',
499
529
  'git.unstage': 'Unstage',
@@ -540,8 +570,8 @@ const DICT_EN = {
540
570
  'diff.next': 'Next change',
541
571
  'diff.revertFile': 'Revert file',
542
572
  'diff.stageFile': 'Stage file',
543
- 'git.discardAll': 'Discard all unstaged changes',
544
- 'git.discardConfirm': 'Click again to confirm (untracked files are kept)',
573
+ 'git.discardAll': 'Discard all changes (including untracked files)',
574
+ 'git.discardConfirm': 'Click again to confirm: untracked files will be deleted',
545
575
  'git.committed': 'Committed',
546
576
  'git.refresh': 'Refresh',
547
577
  'git.staged': 'Staged',
@@ -1450,6 +1480,13 @@ html[data-gufa-ide] [role="dialog"] {
1450
1480
  .gufa-session-workspace{font-size:11px;color:var(--gufa-text-dim);max-width:40%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
1451
1481
  .gufa-session-row-title{flex:1 1 auto;overflow:hidden;text-overflow:ellipsis}
1452
1482
  .gufa-session-row-when{flex:0 0 auto;font-size:10.5px;color:var(--gufa-solid-text-dim, var(--dsw-alias-label-secondary));font-variant-numeric:tabular-nums}
1483
+ .gufa-session-row-status{width:16px;height:16px;flex:0 0 auto;display:inline-flex;align-items:center;justify-content:center}
1484
+ .gufa-session-state-dot{position:relative;display:inline-block;width:16px;height:16px;color:var(--dsw-alias-state-idle-primary,var(--gufa-solid-text-dim, #8b949e))}
1485
+ .gufa-session-state-dot::after{content:"";position:absolute;inset:30%;border-radius:50%;background:currentColor}
1486
+ .gufa-session-state-dot[data-state="done"]{color:var(--dsw-alias-state-success-primary,#3fb950)}
1487
+ .gufa-session-state-dot[data-state="warning"]{color:var(--dsw-alias-state-warn-primary,#d29922)}
1488
+ .gufa-session-state-spinner{display:inline-block;width:13px;height:13px;border-radius:50%;border:1.5px solid color-mix(in srgb, var(--dsw-alias-state-business-primary, var(--gufa-accent)) 22%, transparent);border-top-color:var(--dsw-alias-state-business-primary, var(--gufa-accent));animation:gufa-session-spin 1s linear infinite}
1489
+ @keyframes gufa-session-spin{to{transform:rotate(360deg)}}
1453
1490
  .gufa-strength-range{-webkit-appearance:none;appearance:none;width:86px;height:3px;border-radius:2px;margin:0;cursor:pointer;outline:none;
1454
1491
  background:color-mix(in srgb, var(--gufa-text) 22%, transparent)}
1455
1492
  /* IDE 模式下:官方 MenuSurface/Menu 弹层通过 portal 挂到 body 且自身没有 z-index,
@@ -1827,8 +1864,18 @@ html[data-platform=darwin][data-fullscreen] .gufa-titlebar{height:44px;padding-l
1827
1864
  .gufa-git-change:hover{background:var(--gufa-hover)}
1828
1865
  .gufa-git-status{width:15px;flex:0 0 auto;text-align:center;font-weight:700;font-size:11px;color:var(--gufa-accent)}
1829
1866
  .gufa-git-status[data-kind="D"]{color:var(--dsw-alias-state-error-primary)}
1830
- .gufa-git-status[data-kind="??"]{color:var(--dsw-alias-state-success-primary)}
1867
+ .gufa-git-status[data-kind="U"],.gufa-git-status[data-kind="??"]{color:var(--dsw-alias-state-success-primary)}
1831
1868
  .gufa-git-path{flex:1 1 auto;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:12px;direction:rtl;text-align:left}
1869
+ .gufa-git-repos{border-bottom:1px solid var(--gufa-border);padding:4px 6px 6px;flex:0 0 auto}
1870
+ .gufa-git-repos-head{display:flex;align-items:center;justify-content:space-between;padding:2px 4px 4px;font-size:11px;font-weight:600;color:var(--gufa-text-dim)}
1871
+ .gufa-git-repos-list{display:flex;flex-direction:column;gap:1px;max-height:min(30vh,220px);overflow:auto}
1872
+ .gufa-git-repo-row{display:flex;align-items:center;gap:7px;width:100%;height:30px;padding:0 7px;border:0;border-radius:6px;background:transparent;color:var(--gufa-text);font:inherit;font-size:12px;cursor:pointer;text-align:left;min-width:0}
1873
+ .gufa-git-repo-row:hover{background:var(--gufa-hover)}
1874
+ .gufa-git-repo-row[data-active]{background:var(--gufa-active)}
1875
+ .gufa-git-repo-meta{display:flex;flex-direction:column;min-width:0;flex:1 1 auto;line-height:1.25}
1876
+ .gufa-git-repo-name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-weight:550}
1877
+ .gufa-git-repo-branch{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:10.5px;color:var(--gufa-text-dim)}
1878
+ .gufa-git-repo-sync{flex:0 0 auto;font-size:10.5px;color:var(--gufa-text-dim);font-variant-numeric:tabular-nums}
1832
1879
  .gufa-badge{display:inline-flex;align-items:center;justify-content:center;min-width:17px;height:17px;padding:0 5px;border-radius:9px;
1833
1880
  background:var(--gufa-accent);color:#fff;font-size:10px;font-weight:700}
1834
1881
  .gufa-ssh-host{display:flex;align-items:center;gap:8px;height:30px;padding:0 10px;cursor:pointer;border-radius:6px;min-width:0}
@@ -7815,6 +7862,7 @@ function gufaGraphRow(props) {
7815
7862
  G.GitGraphView = function GitGraphView(props) {
7816
7863
  const t = G.useT()
7817
7864
  const root = typeof props.root === 'string' && props.root !== '' ? props.root : null
7865
+ const repo = typeof props.repo === 'string' && props.repo !== '' ? props.repo : undefined
7818
7866
  const [state, setState] = useState({ status: 'loading', commits: [], branch: '', error: '' })
7819
7867
  const [selected, setSelected] = useState(null)
7820
7868
  const [detail, setDetail] = useState({ status: 'idle', files: [], error: '' })
@@ -7828,7 +7876,7 @@ G.GitGraphView = function GitGraphView(props) {
7828
7876
  }
7829
7877
  let cancelled = false
7830
7878
  setState((current) => ({ ...current, status: current.commits.length === 0 ? 'loading' : 'refreshing', error: '' }))
7831
- void G.api('git.graph', { root, all: showAll })
7879
+ void G.api('git.graph', { root, repo, all: showAll })
7832
7880
  .then((value) => {
7833
7881
  if (cancelled) return
7834
7882
  setState({
@@ -7845,7 +7893,7 @@ G.GitGraphView = function GitGraphView(props) {
7845
7893
  return () => {
7846
7894
  cancelled = true
7847
7895
  }
7848
- }, [root, props.refreshToken, showAll])
7896
+ }, [root, repo, props.refreshToken, showAll])
7849
7897
 
7850
7898
  /* 选中提交后拉取改动文件列表 */
7851
7899
  useEffect(() => {
@@ -7855,7 +7903,7 @@ G.GitGraphView = function GitGraphView(props) {
7855
7903
  }
7856
7904
  let cancelled = false
7857
7905
  setDetail({ status: 'loading', files: [], error: '' })
7858
- void G.api('git.commitFiles', { root, hash: selected.hash })
7906
+ void G.api('git.commitFiles', { root, repo, hash: selected.hash })
7859
7907
  .then((value) => {
7860
7908
  if (cancelled) return
7861
7909
  setDetail({ status: 'ready', files: Array.isArray(value?.files) ? value.files : [], error: '' })
@@ -8123,20 +8171,47 @@ G.Explorer = function Explorer(props) {
8123
8171
  setMenuError('')
8124
8172
  }
8125
8173
 
8174
+ /* 内置剪贴板(IDE 内复制/剪切)优先;没有时读系统剪贴板里的文件/文件夹路径(Finder/资源管理器复制)。 */
8126
8175
  const pasteInto = async (dir) => {
8127
- if (clipboard === null || clipboard.entries.length === 0) return
8128
8176
  const target = typeof dir === 'string' ? dir : ''
8177
+ if (clipboard !== null && clipboard.entries.length > 0) {
8178
+ try {
8179
+ await G.api('fs.copy', { root, from: clipboard.entries, to: target })
8180
+ setMenuError('')
8181
+ await loadDir(target)
8182
+ await loadDir('')
8183
+ props.onChanged?.()
8184
+ } catch (error) {
8185
+ setMenuError(G.errorText(error))
8186
+ }
8187
+ return
8188
+ }
8129
8189
  try {
8130
- await G.api('fs.copy', { root, from: clipboard.entries, to: target })
8131
- setMenuError('')
8132
- await loadDir(target)
8133
- await loadDir('')
8134
- props.onChanged?.()
8190
+ const result = await G.api('fs.pasteClipboard', { root, to: target })
8191
+ const copied = Array.isArray(result?.copied) ? result.copied : []
8192
+ const failed = Array.isArray(result?.failed) ? result.failed : []
8193
+ if (copied.length > 0) {
8194
+ setMenuError('')
8195
+ await loadDir(target)
8196
+ await loadDir('')
8197
+ props.onChanged?.()
8198
+ showNotice(t('explorer.pasteDone').replace('{count}', String(copied.length)))
8199
+ } else {
8200
+ setMenuError(String(failed[0]?.error ?? t('explorer.pasteEmpty')))
8201
+ }
8135
8202
  } catch (error) {
8136
- setMenuError(G.errorText(error))
8203
+ if (error?.code === 'clipboard-empty') showNotice(t('explorer.pasteEmpty'))
8204
+ else setMenuError(G.errorText(error))
8137
8205
  }
8138
8206
  }
8139
8207
 
8208
+ /* 切到 Finder/资源管理器复制文件时 IDE 会失焦:清掉内置剪贴板,避免 Cmd+V 粘到旧的 IDE 内复制内容 */
8209
+ useEffect(() => {
8210
+ const clear = () => setClipboard(null)
8211
+ window.addEventListener('blur', clear)
8212
+ return () => window.removeEventListener('blur', clear)
8213
+ }, [])
8214
+
8140
8215
  const noticeRef = useRef(0)
8141
8216
  const showNotice = (text) => {
8142
8217
  setNotice(text)
@@ -8351,6 +8426,14 @@ G.Explorer = function Explorer(props) {
8351
8426
  event.preventDefault()
8352
8427
  event.stopPropagation()
8353
8428
  void uploadFiles(files, selectedDir())
8429
+ return
8430
+ }
8431
+ /* 系统剪贴板里复制的是文件/文件夹时,Chromium 的 paste 事件拿不到 files,走 Host 读剪贴板路径 */
8432
+ const types = event.clipboardData?.types
8433
+ if (types !== undefined && types !== null && (Array.from(types).includes('Files') || Array.from(types).includes('text/uri-list'))) {
8434
+ event.preventDefault()
8435
+ event.stopPropagation()
8436
+ void pasteInto(selectedDir())
8354
8437
  }
8355
8438
  },
8356
8439
  onDragOver: (event) => {
@@ -8386,7 +8469,7 @@ G.Explorer = function Explorer(props) {
8386
8469
  if (key === 'c') {
8387
8470
  event.preventDefault()
8388
8471
  copySelection(selectedPaths())
8389
- } else if (key === 'v' && clipboard !== null) {
8472
+ } else if (key === 'v') {
8390
8473
  event.preventDefault()
8391
8474
  void pasteInto(selectedDir())
8392
8475
  } else if (key === 'backspace' || event.key === 'Delete') {
@@ -8447,9 +8530,7 @@ G.Explorer = function Explorer(props) {
8447
8530
  },
8448
8531
  h(G.MenuItem, { icon: 'plus', label: t('explorer.newFile'), onClick: closeBlank(() => props.onNewFile?.('')) }),
8449
8532
  h(G.MenuItem, { icon: 'folder', label: t('explorer.newFolder'), onClick: closeBlank(() => props.onNewFolder?.('')) }),
8450
- clipboard !== null
8451
- ? h(G.MenuItem, { icon: 'folder-open', label: t('explorer.paste'), onClick: closeBlank(() => void pasteInto('')) })
8452
- : null,
8533
+ h(G.MenuItem, { icon: 'folder-open', label: t('explorer.paste'), onClick: closeBlank(() => void pasteInto('')) }),
8453
8534
  h(G.MenuItem, { icon: 'refresh', label: t('explorer.refresh'), onClick: closeBlank(() => refreshAll()) }),
8454
8535
  h(G.MenuItem, { icon: 'files', label: '全部折叠', onClick: closeBlank(() => setExpanded({})) }),
8455
8536
  h(G.MenuItem, { icon: 'folder-open', label: t('explorer.revealInFinder'), onClick: closeBlank(() => revealPath('')) }),
@@ -8484,9 +8565,7 @@ G.Explorer = function Explorer(props) {
8484
8565
  })
8485
8566
  : null,
8486
8567
  h(G.MenuItem, { icon: 'files', label: t('explorer.copy'), onClick: closeAnd(() => copySelection(entries.map((item) => item.path))) }),
8487
- clipboard !== null
8488
- ? h(G.MenuItem, { icon: 'folder-open', label: t('explorer.paste'), onClick: closeAnd(() => void pasteInto(targetDir)) })
8489
- : null,
8568
+ h(G.MenuItem, { icon: 'folder-open', label: t('explorer.paste'), onClick: closeAnd(() => void pasteInto(targetDir)) }),
8490
8569
  single
8491
8570
  ? h(G.MenuItem, { icon: 'folder-open', label: t('explorer.revealInFinder'), onClick: closeAnd(() => revealPath(menu.path)) })
8492
8571
  : null,
@@ -9068,9 +9147,12 @@ G.SearchPanel = function SearchPanel(props) {
9068
9147
  }
9069
9148
 
9070
9149
  /* ── 源代码管理(Git) ─────────────────────────────────────────────────── */
9071
- G.GitPanel = function GitPanel(props) {
9150
+ G.GitRepoDetail = function GitRepoDetail(props) {
9072
9151
  const t = G.useT()
9073
9152
  const root = props.root
9153
+ const repo = props.repo !== null && props.repo !== undefined ? props.repo : null
9154
+ const repoParam = repo !== null && typeof repo.path === 'string' && repo.path !== '' ? repo.path : undefined
9155
+ const changeWithRepo = (change) => (repoParam !== undefined && change !== null && typeof change === 'object' ? { ...change, repo: repoParam, repoRel: repo.rel ?? '' } : change)
9074
9156
  const [status, setStatus] = useState(null)
9075
9157
  const [error, setError] = useState('')
9076
9158
  const [pending, setPending] = useState(false)
@@ -9093,10 +9175,10 @@ G.GitPanel = function GitPanel(props) {
9093
9175
  }
9094
9176
  setError('')
9095
9177
  try {
9096
- const value = await G.api('git.status', { root: target })
9178
+ const value = await G.api('git.status', { root: target, repo: repoParam })
9097
9179
  setStatus(value)
9098
9180
  try {
9099
- onStatusRef.current?.(value)
9181
+ onStatusRef.current?.(repoParam !== undefined ? { ...value, repo: repoParam } : value)
9100
9182
  } catch {
9101
9183
  /* 通知失败不影响面板 */
9102
9184
  }
@@ -9105,13 +9187,13 @@ G.GitPanel = function GitPanel(props) {
9105
9187
  // 失败也不要停在「加载中」:给一个空状态让错误可见
9106
9188
  setStatus((current) => current ?? { isGit: true, branch: '', ahead: 0, behind: 0, changes: [] })
9107
9189
  }
9108
- }, [])
9190
+ }, [repoParam])
9109
9191
 
9110
9192
  /* 手动刷新:先 fetch 远端,再读 status(否则 behind 可能是 0) */
9111
9193
  const refreshRemote = useCallback(async () => {
9112
9194
  const target = rootRef.current
9113
9195
  if (target) {
9114
- try { await G.api('git.fetch', { root: target }) } catch { /* 离线等失败不打扰 */ }
9196
+ try { await G.api('git.fetch', { root: target, repo: repoParam }) } catch { /* 离线等失败不打扰 */ }
9115
9197
  }
9116
9198
  await refresh()
9117
9199
  }, [refresh])
@@ -9121,7 +9203,7 @@ G.GitPanel = function GitPanel(props) {
9121
9203
  setStatus(null)
9122
9204
  setMessage('')
9123
9205
  void refresh()
9124
- }, [root, refresh])
9206
+ }, [root, repoParam, refresh])
9125
9207
 
9126
9208
  /* 外部刷新令牌:保留当前内容,仅后台刷新 */
9127
9209
  useEffect(() => {
@@ -9145,18 +9227,18 @@ G.GitPanel = function GitPanel(props) {
9145
9227
 
9146
9228
  /* 推送 / 拉取:点 ↑/↓ 直接执行 */
9147
9229
  const push = () => void act(async () => {
9148
- await G.api('git.push', { root })
9230
+ await G.api('git.push', { root, repo: repoParam })
9149
9231
  })
9150
9232
  const pull = () => void act(async () => {
9151
- await G.api('git.pull', { root })
9233
+ await G.api('git.pull', { root, repo: repoParam })
9152
9234
  })
9153
9235
 
9154
9236
  /* 推送 / 拉取(新建分支还没有上游时也能直接发布:Host 会自动 -u <remote> <branch>) */
9155
9237
  const pushBranch = () => void act(async () => {
9156
- await G.api('git.push', { root })
9238
+ await G.api('git.push', { root, repo: repoParam })
9157
9239
  })
9158
9240
  const pullBranch = () => void act(async () => {
9159
- await G.api('git.pull', { root })
9241
+ await G.api('git.pull', { root, repo: repoParam })
9160
9242
  })
9161
9243
 
9162
9244
  /* 一键撤销所有未暂存改动:第一次点击进入「再点确认」,3 秒后自动取消 */
@@ -9168,7 +9250,7 @@ G.GitPanel = function GitPanel(props) {
9168
9250
  }
9169
9251
  setDiscardArmed(false)
9170
9252
  void act(async () => {
9171
- await G.api('git.discardAll', { root })
9253
+ await G.api('git.discardAll', { root, repo: repoParam })
9172
9254
  })
9173
9255
  }
9174
9256
 
@@ -9194,9 +9276,9 @@ G.GitPanel = function GitPanel(props) {
9194
9276
  /* 有已暂存改动时只提交暂存内容;一个都没暂存时才自动全部暂存再提交(快捷模式) */
9195
9277
  if (staged.length === 0) {
9196
9278
  const toStage = changes.filter((item) => item.staged !== true).map((item) => item.path)
9197
- if (toStage.length > 0) await G.api('git.stage', { root, paths: toStage })
9279
+ if (toStage.length > 0) await G.api('git.stage', { root, repo: repoParam, paths: toStage })
9198
9280
  }
9199
- await G.api('git.commit', { root, message: text })
9281
+ await G.api('git.commit', { root, repo: repoParam, message: text })
9200
9282
  setMessage('')
9201
9283
  })
9202
9284
  }
@@ -9250,20 +9332,20 @@ G.GitPanel = function GitPanel(props) {
9250
9332
  h(
9251
9333
  'div',
9252
9334
  { className: 'gufa-panel-head' },
9253
- h('span', { className: 'gufa-panel-head-title' }, t('activity.git')),
9335
+ h('span', { className: 'gufa-panel-head-title' }, repo !== null && repo.rel ? repo.rel : t('activity.git')),
9254
9336
  changes.length > 0 ? h('span', { className: 'gufa-badge' }, String(changes.length)) : null,
9255
9337
  unstaged.length > 0
9256
9338
  ? h(G.IconButton, {
9257
9339
  title: t('git.stageAll'),
9258
9340
  disabled: pending,
9259
- onClick: () => void act(async () => { await G.api('git.stage', { root, paths: unstaged.map((item) => item.path) }) }),
9341
+ onClick: () => void act(async () => { await G.api('git.stage', { root, repo: repoParam, paths: unstaged.map((item) => item.path) }) }),
9260
9342
  }, h(G.Icon, { name: 'plus', size: 13 }))
9261
9343
  : null,
9262
9344
  staged.length > 0
9263
9345
  ? h(G.IconButton, {
9264
9346
  title: t('git.unstageAll'),
9265
9347
  disabled: pending,
9266
- onClick: () => void act(async () => { await G.api('git.unstage', { root, paths: staged.map((item) => item.path) }) }),
9348
+ onClick: () => void act(async () => { await G.api('git.unstage', { root, repo: repoParam, paths: staged.map((item) => item.path) }) }),
9267
9349
  }, h(G.Icon, { name: 'minus', size: 13 }))
9268
9350
  : null,
9269
9351
  unstaged.length > 0
@@ -9304,7 +9386,7 @@ G.GitPanel = function GitPanel(props) {
9304
9386
  h('span', { className: 'gufa-git-sync-count' }, String(status?.behind ?? 0)),
9305
9387
  )
9306
9388
  : null,
9307
- h(G.IconButton, { title: t('graph.open'), onClick: () => props.onOpenGraph?.() }, h(G.Icon, { name: 'graph', size: 13 })),
9389
+ h(G.IconButton, { title: t('graph.open'), onClick: () => props.onOpenGraph?.(repo) }, h(G.Icon, { name: 'graph', size: 13 })),
9308
9390
  h(G.IconButton, { title: t('git.refresh'), disabled: pending, onClick: () => void refreshRemote() }, h(G.Icon, { name: 'refresh', size: 13 })),
9309
9391
  h(G.IconButton, {
9310
9392
  title: t('git.more'),
@@ -9334,7 +9416,7 @@ G.GitPanel = function GitPanel(props) {
9334
9416
  className: 'gufa-row',
9335
9417
  style: { color: 'var(--gufa-text-dim)', fontSize: 11.5, cursor: 'pointer' },
9336
9418
  title: t('git.branchSwitchHint'),
9337
- onClick: (event) => props.onOpenBranches?.(event),
9419
+ onClick: (event) => props.onOpenBranches?.(event, repo),
9338
9420
  },
9339
9421
  h(G.Icon, { name: 'branch', size: 13 }),
9340
9422
  h('span', { style: { color: 'var(--gufa-text)', fontWeight: 600 } }, status.branch || '—'),
@@ -9400,9 +9482,9 @@ G.GitPanel = function GitPanel(props) {
9400
9482
  change,
9401
9483
  pending,
9402
9484
  staged: true,
9403
- onOpen: () => props.onOpenDiff?.(change),
9485
+ onOpen: () => props.onOpenDiff?.(changeWithRepo(change)),
9404
9486
  onContextMenu: (event, rowChange) => setRowMenu({ ...clampMenuPosition(event.clientX, event.clientY, 200, 200), change: rowChange }),
9405
- onAction: () => void act(async () => G.api('git.unstage', { root, paths: [change.path] })),
9487
+ onAction: () => void act(async () => G.api('git.unstage', { root, repo: repoParam, paths: [change.path] })),
9406
9488
  actionLabel: t('git.unstage'),
9407
9489
  actionIcon: 'minus',
9408
9490
  }),
@@ -9413,11 +9495,15 @@ G.GitPanel = function GitPanel(props) {
9413
9495
  key: `u:${change.path}`,
9414
9496
  change,
9415
9497
  pending,
9416
- onOpen: () => props.onOpenDiff?.(change),
9498
+ onOpen: () => props.onOpenDiff?.(changeWithRepo(change)),
9417
9499
  onContextMenu: (event, rowChange) => setRowMenu({ ...clampMenuPosition(event.clientX, event.clientY, 200, 200), change: rowChange }),
9418
- onRevert: () => void act(async () => G.api('git.discard', { root, paths: [change.path] })),
9419
- revertLabel: t('git.discardFile'),
9420
- onAction: () => void act(async () => G.api('git.stage', { root, paths: [change.path] })),
9500
+ onRevert: () => {
9501
+ if (change.untracked === true
9502
+ && window.confirm(t('git.deleteUntrackedConfirm').replace('{path}', change.path)) !== true) return
9503
+ void act(async () => G.api('git.discard', { root, repo: repoParam, paths: [change.path] }))
9504
+ },
9505
+ revertLabel: change.untracked === true ? t('git.deleteUntrackedFile') : t('git.discardFile'),
9506
+ onAction: () => void act(async () => G.api('git.stage', { root, repo: repoParam, paths: [change.path] })),
9421
9507
  actionLabel: t('git.stage'),
9422
9508
  actionIcon: 'plus',
9423
9509
  }),
@@ -9437,14 +9523,14 @@ G.GitPanel = function GitPanel(props) {
9437
9523
  ? h(G.MenuItem, {
9438
9524
  icon: 'plus',
9439
9525
  label: t('git.stageAll'),
9440
- onClick: menuAction(() => void act(async () => { await G.api('git.stage', { root, paths: unstaged.map((item) => item.path) }) })),
9526
+ onClick: menuAction(() => void act(async () => { await G.api('git.stage', { root, repo: repoParam, paths: unstaged.map((item) => item.path) }) })),
9441
9527
  })
9442
9528
  : null,
9443
9529
  staged.length > 0
9444
9530
  ? h(G.MenuItem, {
9445
9531
  icon: 'minus',
9446
9532
  label: t('git.unstageAll'),
9447
- onClick: menuAction(() => void act(async () => { await G.api('git.unstage', { root, paths: staged.map((item) => item.path) }) })),
9533
+ onClick: menuAction(() => void act(async () => { await G.api('git.unstage', { root, repo: repoParam, paths: staged.map((item) => item.path) }) })),
9448
9534
  })
9449
9535
  : null,
9450
9536
  unstaged.length > 0
@@ -9452,18 +9538,18 @@ G.GitPanel = function GitPanel(props) {
9452
9538
  icon: 'undo',
9453
9539
  label: t('git.discardAll'),
9454
9540
  danger: true,
9455
- onClick: menuAction(() => void act(async () => { await G.api('git.discardAll', { root }) })),
9541
+ onClick: menuAction(() => void act(async () => { await G.api('git.discardAll', { root, repo: repoParam }) })),
9456
9542
  })
9457
9543
  : null,
9458
9544
  h(G.MenuItem, {
9459
9545
  icon: 'arrow-left',
9460
9546
  label: t('git.undoLastCommit'),
9461
- onClick: menuAction(() => void act(async () => { await G.api('git.undoLastCommit', { root }) })),
9547
+ onClick: menuAction(() => void act(async () => { await G.api('git.undoLastCommit', { root, repo: repoParam }) })),
9462
9548
  }),
9463
9549
  h(G.MenuItem, {
9464
9550
  icon: 'graph',
9465
9551
  label: t('graph.open'),
9466
- onClick: menuAction(() => props.onOpenGraph?.()),
9552
+ onClick: menuAction(() => props.onOpenGraph?.(repo)),
9467
9553
  }),
9468
9554
  )),
9469
9555
  rowMenu === null
@@ -9475,24 +9561,29 @@ G.GitPanel = function GitPanel(props) {
9475
9561
  style: { left: rowMenu.x, top: rowMenu.y, position: 'fixed', minWidth: 190 },
9476
9562
  onMouseDown: (event) => event.stopPropagation(),
9477
9563
  },
9478
- h(G.MenuItem, { icon: 'code', label: t('git.viewDiff'), onClick: menuAction(() => props.onOpenDiff?.(rowMenu.change)) }),
9564
+ h(G.MenuItem, { icon: 'code', label: t('git.viewDiff'), onClick: menuAction(() => props.onOpenDiff?.(changeWithRepo(rowMenu.change))) }),
9479
9565
  rowMenu.change.staged === true
9480
9566
  ? h(G.MenuItem, {
9481
9567
  icon: 'minus',
9482
9568
  label: t('git.unstage'),
9483
- onClick: menuAction(() => void act(async () => { await G.api('git.unstage', { root, paths: [rowMenu.change.path] }) })),
9569
+ onClick: menuAction(() => void act(async () => { await G.api('git.unstage', { root, repo: repoParam, paths: [rowMenu.change.path] }) })),
9484
9570
  })
9485
9571
  : h(G.MenuItem, {
9486
9572
  icon: 'plus',
9487
9573
  label: t('git.stage'),
9488
- onClick: menuAction(() => void act(async () => { await G.api('git.stage', { root, paths: [rowMenu.change.path] }) })),
9574
+ onClick: menuAction(() => void act(async () => { await G.api('git.stage', { root, repo: repoParam, paths: [rowMenu.change.path] }) })),
9489
9575
  }),
9490
9576
  rowMenu.change.staged !== true
9491
9577
  ? h(G.MenuItem, {
9492
9578
  icon: 'undo',
9493
- label: t('git.discardFile'),
9579
+ label: rowMenu.change.untracked === true ? t('git.deleteUntrackedFile') : t('git.discardFile'),
9494
9580
  danger: true,
9495
- onClick: menuAction(() => void act(async () => { await G.api('git.discard', { root, paths: [rowMenu.change.path] }) })),
9581
+ onClick: menuAction(() => {
9582
+ const change = rowMenu.change
9583
+ if (change.untracked === true
9584
+ && window.confirm(t('git.deleteUntrackedConfirm').replace('{path}', change.path)) !== true) return
9585
+ void act(async () => { await G.api('git.discard', { root, repo: repoParam, paths: [change.path] }) })
9586
+ }),
9496
9587
  })
9497
9588
  : null,
9498
9589
  h(G.MenuItem, { icon: 'files', label: t('git.copyPath'), onClick: menuAction(() => copyText(rowMenu.change.path)) }),
@@ -9500,8 +9591,159 @@ G.GitPanel = function GitPanel(props) {
9500
9591
  )
9501
9592
  }
9502
9593
 
9594
+ /* ── 源代码管理:工作区内所有 Git 仓库列表(根仓库 + 子目录仓库),逐仓库操作 ── */
9595
+ G.GitPanel = function GitPanel(props) {
9596
+ const t = G.useT()
9597
+ const workspaceRoot = props.root
9598
+ const [repos, setRepos] = useState(null)
9599
+ const [activePath, setActivePath] = useState(null)
9600
+ const [summaries, setSummaries] = useState({})
9601
+ const [reloadToken, setReloadToken] = useState(0)
9602
+ const [summaryTick, setSummaryTick] = useState(0)
9603
+
9604
+ useEffect(() => {
9605
+ let cancelled = false
9606
+ setRepos(null)
9607
+ if (!workspaceRoot) {
9608
+ setRepos([])
9609
+ return () => { cancelled = true }
9610
+ }
9611
+ void G.api('git.repos', { root: workspaceRoot })
9612
+ .then((value) => {
9613
+ if (cancelled) return
9614
+ const list = Array.isArray(value?.repos) ? value.repos : []
9615
+ setRepos(list)
9616
+ setActivePath((current) => (list.some((item) => item.path === current) ? current : (list[0]?.path ?? null)))
9617
+ })
9618
+ .catch(() => {
9619
+ if (cancelled) return
9620
+ /* 旧 Host 没有 git.repos:退回原来的单仓库模式 */
9621
+ const fallback = [{ path: workspaceRoot, rel: '', name: G.basename(workspaceRoot), isRoot: true }]
9622
+ setRepos(fallback)
9623
+ setActivePath(workspaceRoot)
9624
+ })
9625
+ return () => { cancelled = true }
9626
+ }, [workspaceRoot, props.refreshToken, reloadToken])
9627
+
9628
+ useEffect(() => {
9629
+ if (!workspaceRoot || repos === null || repos.length === 0) return undefined
9630
+ let cancelled = false
9631
+ void Promise.all(repos.map(async (repo) => {
9632
+ try {
9633
+ const status = await G.api('git.status', { root: workspaceRoot, repo: repo.path })
9634
+ return [repo.path, status]
9635
+ } catch {
9636
+ return [repo.path, null]
9637
+ }
9638
+ })).then((entries) => {
9639
+ if (cancelled) return
9640
+ setSummaries(Object.fromEntries(entries))
9641
+ })
9642
+ return () => { cancelled = true }
9643
+ }, [workspaceRoot, repos, props.refreshToken, summaryTick])
9644
+
9645
+ /* 子目录仓库的变化不会被工作区根目录的轮询发现,面板打开时每 5s 刷新一次各仓库摘要 */
9646
+ useEffect(() => {
9647
+ if (!workspaceRoot) return undefined
9648
+ const timer = window.setInterval(() => setSummaryTick((tick) => tick + 1), 5000)
9649
+ return () => window.clearInterval(timer)
9650
+ }, [workspaceRoot])
9651
+
9652
+ const handleStatus = (value) => {
9653
+ const repoPath = typeof value?.repo === 'string' ? value.repo : null
9654
+ if (repoPath !== null) setSummaries((current) => ({ ...current, [repoPath]: value }))
9655
+ let forwarded = value
9656
+ if (repoPath !== null && Array.isArray(value?.changes)) {
9657
+ const repo = repos?.find((item) => item.path === repoPath)
9658
+ if (repo !== undefined && repo.rel !== '') {
9659
+ forwarded = { ...value, changes: value.changes.map((change) => ({ ...change, path: `${repo.rel}/${change.path}` })) }
9660
+ }
9661
+ }
9662
+ props.onStatus?.(forwarded)
9663
+ }
9664
+
9665
+ const activeRepo = repos !== null && activePath !== null
9666
+ ? repos.find((item) => item.path === activePath) ?? null
9667
+ : null
9668
+ const showList = repos !== null && repos.length > 1
9669
+ const detailProps = {
9670
+ root: workspaceRoot,
9671
+ refreshToken: props.refreshToken,
9672
+ onStatus: handleStatus,
9673
+ onOpenFile: props.onOpenFile,
9674
+ onOpenDiff: props.onOpenDiff,
9675
+ onOpenBranches: props.onOpenBranches,
9676
+ onOpenGraph: props.onOpenGraph,
9677
+ onChanged: props.onChanged,
9678
+ }
9679
+
9680
+ return h(
9681
+ 'div',
9682
+ { style: { display: 'flex', flexDirection: 'column', height: '100%', minHeight: 0 } },
9683
+ showList
9684
+ ? h(
9685
+ 'div',
9686
+ { className: 'gufa-git-repos' },
9687
+ h(
9688
+ 'div',
9689
+ { className: 'gufa-git-repos-head' },
9690
+ h('span', null, `${t('git.repos')} (${repos.length})`),
9691
+ h(G.IconButton, {
9692
+ title: t('git.refresh'),
9693
+ onClick: () => setReloadToken((token) => token + 1),
9694
+ }, h(G.Icon, { name: 'refresh', size: 12 })),
9695
+ ),
9696
+ h(
9697
+ 'div',
9698
+ { className: 'gufa-git-repos-list gufa-scroll' },
9699
+ ...repos.map((repo) => {
9700
+ const summary = summaries[repo.path]
9701
+ const changeCount = Array.isArray(summary?.changes) ? summary.changes.length : 0
9702
+ const ahead = Number(summary?.ahead ?? 0)
9703
+ const behind = Number(summary?.behind ?? 0)
9704
+ return h(
9705
+ 'button',
9706
+ {
9707
+ key: repo.path,
9708
+ type: 'button',
9709
+ className: 'gufa-git-repo-row',
9710
+ 'data-active': repo.path === activePath ? '' : undefined,
9711
+ title: repo.path,
9712
+ onClick: () => setActivePath(repo.path),
9713
+ },
9714
+ h(G.Icon, { name: 'git', size: 13 }),
9715
+ h(
9716
+ 'span',
9717
+ { className: 'gufa-git-repo-meta' },
9718
+ h('span', { className: 'gufa-git-repo-name' }, repo.rel === '' ? t('git.workspaceRoot') : repo.rel),
9719
+ h('span', { className: 'gufa-git-repo-branch' }, summary?.branch || '—'),
9720
+ ),
9721
+ changeCount > 0 ? h('span', { className: 'gufa-badge' }, String(changeCount)) : null,
9722
+ ahead > 0 ? h('span', { className: 'gufa-git-repo-sync' }, `↑${ahead}`) : null,
9723
+ behind > 0 ? h('span', { className: 'gufa-git-repo-sync' }, `↓${behind}`) : null,
9724
+ )
9725
+ }),
9726
+ ),
9727
+ )
9728
+ : null,
9729
+ h(
9730
+ 'div',
9731
+ { style: { flex: '1 1 auto', minHeight: 0, display: 'flex', flexDirection: 'column' } },
9732
+ repos === null
9733
+ ? h('div', { className: 'gufa-panel-body' }, h(G.Empty, { title: t('common.loading') }))
9734
+ : h(G.GitRepoDetail, {
9735
+ key: activeRepo !== null ? activeRepo.path : 'root',
9736
+ ...detailProps,
9737
+ repo: activeRepo,
9738
+ }),
9739
+ ),
9740
+ )
9741
+ }
9742
+
9503
9743
  G.GitChangeRow = function GitChangeRow(props) {
9504
9744
  const change = props.change
9745
+ /* 未跟踪文件在 git porcelain 里是 ??,面板里显示成更直观的 U(Untracked) */
9746
+ const displayStatus = change.untracked === true || change.status === '??' ? 'U' : change.status
9505
9747
  return h(
9506
9748
  'div',
9507
9749
  {
@@ -9515,7 +9757,7 @@ G.GitChangeRow = function GitChangeRow(props) {
9515
9757
  },
9516
9758
  style: { cursor: 'pointer' },
9517
9759
  },
9518
- h('span', { className: 'gufa-git-status', 'data-kind': change.status }, change.status),
9760
+ h('span', { className: 'gufa-git-status', 'data-kind': displayStatus }, displayStatus),
9519
9761
  h('span', { className: 'gufa-git-path', style: { flex: '1 1 auto' } }, change.path),
9520
9762
  props.staged !== true && typeof props.onRevert === 'function'
9521
9763
  ? h(
@@ -12275,6 +12517,12 @@ G.installShortcutIntegration = function installShortcutIntegration(service) {
12275
12517
 
12276
12518
  // 经典模式:不碰任何 DSH 原生命令
12277
12519
  if (G.mode.get() !== true) {
12520
+ /* IDE 模式退出时把 dispatch 补丁还原,经典模式继续走 DSH 原生派发 */
12521
+ if (registry.__gufaDispatchPatched === true && typeof registry.__gufaOriginalDispatch === 'function') {
12522
+ registry.dispatch = registry.__gufaOriginalDispatch
12523
+ delete registry.__gufaOriginalDispatch
12524
+ delete registry.__gufaDispatchPatched
12525
+ }
12278
12526
  try {
12279
12527
  if (window !== undefined && window !== null) {
12280
12528
  if (window.__gufaClassicShortcutLogs === undefined) window.__gufaClassicShortcutLogs = 3
@@ -12314,6 +12562,22 @@ G.installShortcutIntegration = function installShortcutIntegration(service) {
12314
12562
  'edrv.prevTab': 'prevTab',
12315
12563
  'edrv.nextTab': 'nextTab',
12316
12564
  }
12565
+ /* DSH 升级/用户自定义可能把 Cmd+K 改绑到别的命令 id:以当前快捷键目录为准,
12566
+ 把实际占用「主修饰键+K」的命令也改派成 clearTerminal(默认仍是 session.search)。 */
12567
+ try {
12568
+ const rows = registry.catalog !== null && registry.catalog !== undefined && typeof registry.catalog.getSnapshot === 'function'
12569
+ ? registry.catalog.getSnapshot()
12570
+ : []
12571
+ const wanted = G.isMacPlatform() ? '⌘K' : 'Ctrl+K'
12572
+ for (const row of Array.isArray(rows) ? rows : []) {
12573
+ const keys = Array.isArray(row?.keys) ? row.keys : []
12574
+ if (keys.join('') !== wanted) continue
12575
+ if (typeof row?.id !== 'string' || row.id === '') continue
12576
+ if (typeof commandActions[row.id] !== 'string') commandActions[row.id] = 'clearTerminal'
12577
+ }
12578
+ } catch {
12579
+ /* ignore */
12580
+ }
12317
12581
  service.__gufaCommandActions = commandActions
12318
12582
  const wrapped = []
12319
12583
  const commands = registry.commands
@@ -12330,6 +12594,10 @@ G.installShortcutIntegration = function installShortcutIntegration(service) {
12330
12594
  status: 'handled',
12331
12595
  run: () => {
12332
12596
  try {
12597
+ if ((window.__gufaCommandRemapLogs ?? 0) < 20) {
12598
+ window.__gufaCommandRemapLogs = (window.__gufaCommandRemapLogs ?? 0) + 1
12599
+ void G.api('dev.log', { message: `command-remap ${id} -> ${mapped}` }).catch(() => {})
12600
+ }
12333
12601
  if (mapped.startsWith('editor:')) {
12334
12602
  if (G.bus !== null && G.bus !== undefined) G.bus.emit('editor:command', mapped.slice('editor:'.length))
12335
12603
  return
@@ -12370,7 +12638,79 @@ G.installShortcutIntegration = function installShortcutIntegration(service) {
12370
12638
  service.__gufaPatchedCommands.push({ command, originalResolve })
12371
12639
  wrapped.push(id)
12372
12640
  }
12641
+ /* 懒加载的命令(例如 workspace 的 session.search 可能晚于插件初始化才注册):
12642
+ 包一次 commands.set,注册时立即补上 resolve 改派,避免 Cmd+K 又退回原生搜索。 */
12643
+ try {
12644
+ if (typeof commands.set === 'function' && commands.__gufaSetPatched !== true) {
12645
+ const originalSet = commands.set
12646
+ commands.set = function gufaShortcutCommandsSet(id, command) {
12647
+ const result = originalSet.call(this, id, command)
12648
+ try {
12649
+ const mapped = service.__gufaCommandActions === null || service.__gufaCommandActions === undefined
12650
+ ? undefined
12651
+ : service.__gufaCommandActions[id]
12652
+ if (typeof mapped === 'string' && command !== null && command !== undefined
12653
+ && typeof command.resolve === 'function' && command.__gufaWrapped !== true) {
12654
+ const originalResolve = command.resolve
12655
+ try {
12656
+ Object.defineProperty(command, '__gufaOriginalResolve', { value: originalResolve, configurable: true })
12657
+ } catch {
12658
+ /* ignore */
12659
+ }
12660
+ command.resolve = makeResolve(id, originalResolve)
12661
+ try {
12662
+ Object.defineProperty(command, '__gufaWrapped', { value: true, configurable: true })
12663
+ } catch {
12664
+ /* ignore */
12665
+ }
12666
+ if (Array.isArray(service.__gufaPatchedCommands) !== true) service.__gufaPatchedCommands = []
12667
+ service.__gufaPatchedCommands.push({ command, originalResolve })
12668
+ }
12669
+ } catch {
12670
+ /* ignore */
12671
+ }
12672
+ return result
12673
+ }
12674
+ commands.__gufaSetPatched = true
12675
+ }
12676
+ } catch {
12677
+ /* ignore */
12678
+ }
12373
12679
  }
12680
+ /* 兜底:如果 Cmd+K 在 DSH 里存在快捷键冲突,dispatch 会在调用 command.resolve 之前就
12681
+ 把按键 consume 掉(表现为快捷键完全没反应)。IDE 模式下直接在 dispatch 最前面接管
12682
+ 主修饰键+K → 清空终端,不依赖具体 command id 是否被包到。 */
12683
+ try {
12684
+ if (typeof registry.dispatch === 'function' && registry.__gufaDispatchPatched !== true) {
12685
+ const originalDispatch = registry.dispatch
12686
+ registry.dispatch = function gufaIdeDispatch(gesture, context, consume) {
12687
+ try {
12688
+ if (G.mode.get() === true
12689
+ && typeof document !== 'undefined'
12690
+ && document.querySelector('.gufa-overlay-root') !== null
12691
+ && typeof window.__gufaIdeShortcutDispatch === 'function') {
12692
+ const mac = G.isMacPlatform()
12693
+ const primary = mac ? gesture?.meta === true && gesture?.control !== true : gesture?.control === true
12694
+ if (primary && gesture?.code === 'KeyK' && gesture?.shift !== true && gesture?.alt !== true) {
12695
+ if (typeof consume === 'function') consume()
12696
+ if (gesture?.repeat !== true) {
12697
+ try { window.__gufaIdeShortcutDispatch('clearTerminal') } catch { /* ignore */ }
12698
+ }
12699
+ return { status: 'handled', commandId: 'gufa.ide.clearTerminal' }
12700
+ }
12701
+ }
12702
+ } catch {
12703
+ /* ignore */
12704
+ }
12705
+ return originalDispatch.call(this, gesture, context, consume)
12706
+ }
12707
+ registry.__gufaOriginalDispatch = originalDispatch
12708
+ registry.__gufaDispatchPatched = true
12709
+ }
12710
+ } catch {
12711
+ /* ignore */
12712
+ }
12713
+
12374
12714
  // ── 命令表/配置尚未就绪时重试(插件加载可能早于 ui-layout 注册命令)──
12375
12715
  const expected = Object.keys(commandActions).length
12376
12716
  try {
@@ -13015,6 +13355,29 @@ G.GufaApp = function GufaApp(props) {
13015
13355
  const [workspaceSessions, setWorkspaceSessions] = useState({ status: 'idle', sessions: [], groups: [], sessionIds: [], archivedSessionIds: [] })
13016
13356
  const [workspaceIndex, setWorkspaceIndex] = useState([])
13017
13357
  const [recentCurrentIds, setRecentCurrentIds] = useState([])
13358
+ /* 会话运行状态(与经典侧边栏同源:uiSession.sessionStatus,含 running/pendingInteraction/completionUnread) */
13359
+ const [sessionStatuses, setSessionStatuses] = useState(() => new Map())
13360
+ const [sessionStatusReady, setSessionStatusReady] = useState(false)
13361
+ useEffect(() => {
13362
+ const ui = G.ctx === null || G.ctx === undefined ? undefined : G.ctx.get('uiSession')
13363
+ const source = ui?.sessionStatus
13364
+ if (source === undefined || source === null || typeof source.getSnapshot !== 'function') return undefined
13365
+ setSessionStatusReady(true)
13366
+ const sync = () => {
13367
+ try {
13368
+ const snapshot = source.getSnapshot()
13369
+ if (snapshot instanceof Map) setSessionStatuses(new Map(snapshot))
13370
+ } catch {
13371
+ /* ignore */
13372
+ }
13373
+ }
13374
+ sync()
13375
+ if (typeof source.subscribe !== 'function') return undefined
13376
+ const dispose = source.subscribe(sync)
13377
+ return () => {
13378
+ if (typeof dispose === 'function') dispose()
13379
+ }
13380
+ }, [])
13018
13381
  const [sessionGroupOpen, setSessionGroupOpen] = useState({})
13019
13382
  const [workspaceBusy, setWorkspaceBusy] = useState(false)
13020
13383
  const [branchInput, setBranchInput] = useState('')
@@ -13639,24 +14002,29 @@ G.GufaApp = function GufaApp(props) {
13639
14002
  }, [])
13640
14003
 
13641
14004
  /* ── Git Graph(提交图标签页) ─────────────────────────────────────── */
13642
- const openGitGraph = useCallback(() => {
14005
+ const openGitGraph = useCallback((repo) => {
13643
14006
  if (project === null) return
13644
- const path = 'gufa-graph'
14007
+ const repoPath = repo !== null && repo !== undefined && typeof repo.path === 'string' ? repo.path : null
14008
+ const repoRel = repo !== null && repo !== undefined && typeof repo.rel === 'string' ? repo.rel : ''
14009
+ const path = repoPath !== null && repoRel !== '' ? `gufa-graph:${repoRel}` : 'gufa-graph'
13645
14010
  setTabs((current) => {
13646
- if (current.some((tab) => tab !== null && tab.path === path)) return current
13647
- return [...current, { path, title: 'Git Graph', kind: 'graph' }]
14011
+ const existing = current.find((tab) => tab !== null && tab.path === path)
14012
+ if (existing !== undefined) return current.map((tab) => (tab !== null && tab.path === path ? { ...tab, gitRepo: repoPath, gitRepoRel: repoRel } : tab))
14013
+ return [...current, { path, title: 'Git Graph', kind: 'graph', gitRepo: repoPath, gitRepoRel: repoRel }]
13648
14014
  })
13649
14015
  setActivePath(path)
13650
14016
  }, [project])
13651
14017
 
13652
14018
  /* Git Graph:点开某次提交里的文件 → 提交版本 diff(父提交 vs 该提交) */
13653
- const openCommitFile = useCallback(async (commit, file) => {
14019
+ const openCommitFile = useCallback(async (commit, file, repoCtx) => {
13654
14020
  if (project === null || commit === null || commit === undefined || file === null || file === undefined) return
13655
14021
  if (typeof file.path !== 'string' || file.path === '' || typeof commit.hash !== 'string') return
14022
+ const repoRoot = repoCtx !== null && repoCtx !== undefined && typeof repoCtx.path === 'string' ? repoCtx.path : undefined
14023
+ const repoRel = repoCtx !== null && repoCtx !== undefined && typeof repoCtx.rel === 'string' ? repoCtx.rel : ''
13656
14024
  try {
13657
14025
  const [leftResult, rightResult] = await Promise.all([
13658
- G.api('git.fileVersion', { root: project.root, path: file.path, hash: commit.hash, parent: true }).catch(() => ({ text: '' })),
13659
- G.api('git.fileVersion', { root: project.root, path: file.path, hash: commit.hash }).catch(() => ({ text: '' })),
14026
+ G.api('git.fileVersion', { root: project.root, repo: repoRoot, path: file.path, hash: commit.hash, parent: true }).catch(() => ({ text: '' })),
14027
+ G.api('git.fileVersion', { root: project.root, repo: repoRoot, path: file.path, hash: commit.hash }).catch(() => ({ text: '' })),
13660
14028
  ])
13661
14029
  const path = `gufa-commit:${commit.hash.slice(0, 10)}:${file.path}`
13662
14030
  const leftText = typeof leftResult?.text === 'string' ? leftResult.text : ''
@@ -13686,8 +14054,11 @@ G.GufaApp = function GufaApp(props) {
13686
14054
  }, [project])
13687
14055
 
13688
14056
  /* 分支切换 / 新建 ──────────────────────────────────────────────── */
13689
- const openBranchMenu = useCallback((event) => {
13690
- if (project === null || project.isGit !== true) return
14057
+ const openBranchMenu = useCallback((event, repo) => {
14058
+ if (project === null) return
14059
+ const repoPath = repo !== null && repo !== undefined && typeof repo.path === 'string' ? repo.path : undefined
14060
+ /* 工作区根目录不是 Git 仓库时,仍允许对子目录仓库切换分支 */
14061
+ if (repoPath === undefined && project.isGit !== true) return
13691
14062
  let placement = { x: 12, top: 40 }
13692
14063
  try {
13693
14064
  const rect = event !== null && event !== undefined && event.currentTarget !== null
@@ -13703,8 +14074,8 @@ G.GufaApp = function GufaApp(props) {
13703
14074
  /* ignore */
13704
14075
  }
13705
14076
  setBranchInput('')
13706
- setBranchMenu({ ...placement, loading: true, branches: [], error: '' })
13707
- void G.api('git.branches', { root: project.root })
14077
+ setBranchMenu({ ...placement, repo: repoPath, loading: true, branches: [], error: '' })
14078
+ void G.api('git.branches', { root: project.root, repo: repoPath })
13708
14079
  .then((value) => {
13709
14080
  setBranchMenu((current) => (current === null ? current : { ...current, loading: false, branches: Array.isArray(value?.branches) ? value.branches : [] }))
13710
14081
  })
@@ -13739,7 +14110,7 @@ G.GufaApp = function GufaApp(props) {
13739
14110
  const checkoutBranch = useCallback(async (name) => {
13740
14111
  if (project === null || typeof name !== 'string' || name === '') return
13741
14112
  try {
13742
- await G.api('git.checkout', { root: project.root, branch: name })
14113
+ await G.api('git.checkout', { root: project.root, repo: branchMenu?.repo, branch: name })
13743
14114
  closeBranchMenu()
13744
14115
  setGitRefreshToken((token) => token + 1)
13745
14116
  setRefreshToken((token) => token + 1)
@@ -13747,14 +14118,14 @@ G.GufaApp = function GufaApp(props) {
13747
14118
  } catch (error) {
13748
14119
  setBranchMenu((current) => (current === null ? current : { ...current, error: G.errorText(error) }))
13749
14120
  }
13750
- }, [project, closeBranchMenu, refreshGit])
14121
+ }, [project, branchMenu, closeBranchMenu, refreshGit])
13751
14122
 
13752
14123
  const createBranch = useCallback(async () => {
13753
14124
  if (project === null) return
13754
14125
  const name = branchInput.trim()
13755
14126
  if (name === '') return
13756
14127
  try {
13757
- await G.api('git.createBranch', { root: project.root, name })
14128
+ await G.api('git.createBranch', { root: project.root, repo: branchMenu?.repo, name })
13758
14129
  closeBranchMenu()
13759
14130
  setGitRefreshToken((token) => token + 1)
13760
14131
  setRefreshToken((token) => token + 1)
@@ -13762,7 +14133,7 @@ G.GufaApp = function GufaApp(props) {
13762
14133
  } catch (error) {
13763
14134
  setBranchMenu((current) => (current === null ? current : { ...current, error: G.errorText(error) }))
13764
14135
  }
13765
- }, [project, branchInput, closeBranchMenu, refreshGit])
14136
+ }, [project, branchMenu, branchInput, closeBranchMenu, refreshGit])
13766
14137
 
13767
14138
  /* ── 删除(无确认弹窗,软删除到临时目录,⌘Z 可撤销) ──────────────── */
13768
14139
  const deleteEntry = useCallback(async (path) => {
@@ -13833,7 +14204,12 @@ G.GufaApp = function GufaApp(props) {
13833
14204
  /* ── Git diff / 两文件对比(Monaco DiffEditor) ────────────────────── */
13834
14205
  const openDiffForChange = useCallback(async (change) => {
13835
14206
  if (project === null || change === null || typeof change !== 'object' || typeof change.path !== 'string') return
13836
- const existing = tabs.find((item) => item.path === change.path)
14207
+ /* 嵌套仓库:diff 的路径是仓库内相对路径,编辑器/文件读写的 path 需要补上仓库相对工作区的前缀 */
14208
+ const repoRoot = typeof change.repo === 'string' && change.repo !== '' ? change.repo : null
14209
+ const repoRel = typeof change.repoRel === 'string' ? change.repoRel : ''
14210
+ const wsPath = repoRel !== '' ? `${repoRel}/${change.path}` : change.path
14211
+ const gitBody = repoRoot !== null ? { root: project.root, repo: repoRoot } : { root: project.root }
14212
+ const existing = tabs.find((item) => item.path === wsPath)
13837
14213
  if (existing !== undefined && existing !== null && existing.kind !== 'diff' && existing.dirty === true) {
13838
14214
  setBanner('该文件有未保存修改,请先保存后再查看 diff')
13839
14215
  return
@@ -13842,14 +14218,14 @@ G.GufaApp = function GufaApp(props) {
13842
14218
  /* 文件可能已删除(工作树删掉/暂存区删除):读不到就按空处理,仍然展示差异 */
13843
14219
  let file = null
13844
14220
  try {
13845
- file = await G.api('fs.read', { root: project.root, path: change.path })
14221
+ file = await G.api('fs.read', { root: project.root, path: wsPath })
13846
14222
  } catch {
13847
14223
  file = null
13848
14224
  }
13849
14225
  let left = ''
13850
14226
  try {
13851
14227
  const shown = await G.api('git.show', {
13852
- root: project.root,
14228
+ ...gitBody,
13853
14229
  path: change.path,
13854
14230
  rev: change.staged === true ? 'head' : 'index',
13855
14231
  })
@@ -13861,14 +14237,14 @@ G.GufaApp = function GufaApp(props) {
13861
14237
  if (change.staged === true) {
13862
14238
  /* 暂存区 diff = HEAD ↔ 索引;右侧必须用索引内容,而不是工作树(工作树可能还有未暂存改动) */
13863
14239
  try {
13864
- const indexDoc = await G.api('git.show', { root: project.root, path: change.path, rev: 'index' })
14240
+ const indexDoc = await G.api('git.show', { ...gitBody, path: change.path, rev: 'index' })
13865
14241
  rightContent = typeof indexDoc.text === 'string' ? indexDoc.text : ''
13866
14242
  } catch {
13867
14243
  rightContent = ''
13868
14244
  }
13869
14245
  }
13870
14246
  const tab = {
13871
- path: change.path,
14247
+ path: wsPath,
13872
14248
  title: `${G.basename(change.path)}(${change.staged === true ? '暂存区' : '工作树'})`,
13873
14249
  kind: 'diff',
13874
14250
  content: rightContent,
@@ -13877,17 +14253,17 @@ G.GufaApp = function GufaApp(props) {
13877
14253
  dirty: false,
13878
14254
  language: file?.language ?? 'plaintext',
13879
14255
  size: file?.size,
13880
- diff: { left, staged: change.staged === true, editable: change.staged !== true },
14256
+ diff: { left, staged: change.staged === true, editable: change.staged !== true, gitRepo: repoRoot },
13881
14257
  diffKey: Date.now(),
13882
14258
  }
13883
14259
  setTabs((current) => {
13884
- const index = current.findIndex((item) => item.path === change.path)
14260
+ const index = current.findIndex((item) => item.path === wsPath)
13885
14261
  if (index === -1) return [...current, tab]
13886
14262
  const next = current.slice()
13887
14263
  next[index] = { ...next[index], ...tab }
13888
14264
  return next
13889
14265
  })
13890
- setActivePath(change.path)
14266
+ setActivePath(wsPath)
13891
14267
  setBanner('')
13892
14268
  } catch (error) {
13893
14269
  setBanner(G.errorText(error))
@@ -15251,8 +15627,8 @@ G.GufaApp = function GufaApp(props) {
15251
15627
  onStatus: setGitStatus,
15252
15628
  onOpenFile: (path) => void openFile(path),
15253
15629
  onOpenDiff: (change) => void openDiffForChange(change),
15254
- onOpenBranches: (event) => openBranchMenu(event),
15255
- onOpenGraph: () => openGitGraph(),
15630
+ onOpenBranches: (event, repo) => openBranchMenu(event, repo),
15631
+ onOpenGraph: (repo) => openGitGraph(repo),
15256
15632
  onChanged: () => { setRefreshToken((token) => token + 1) },
15257
15633
  })),
15258
15634
  h('div', { key: 'ssh', style: { display: ui.view === 'ssh' ? 'flex' : 'none', flex: '1 1 auto', minHeight: 0, flexDirection: 'column' } },
@@ -15547,9 +15923,10 @@ G.GufaApp = function GufaApp(props) {
15547
15923
  : activeTab.kind === 'graph'
15548
15924
  ? h(G.GitGraphView, {
15549
15925
  root: project?.root ?? null,
15926
+ repo: activeTab.gitRepo ?? null,
15550
15927
  refreshToken: gitRefreshToken,
15551
15928
  onRefresh: () => setGitRefreshToken((token) => token + 1),
15552
- onOpenCommitFile: (commit, file) => void openCommitFile(commit, file),
15929
+ onOpenCommitFile: (commit, file) => void openCommitFile(commit, file, { path: activeTab.gitRepo, rel: activeTab.gitRepoRel }),
15553
15930
  })
15554
15931
  : h(G.EditorPane, {
15555
15932
  tabs,
@@ -16129,8 +16506,22 @@ G.GufaApp = function GufaApp(props) {
16129
16506
  return true
16130
16507
  })
16131
16508
  .map((row) => ({ id: row.id, title: row.title, when: row.when }))
16132
- const renderSessionRow = (session, extraKey) =>
16133
- h(
16509
+ /* 会话状态:与经典侧边栏同款(16px 状态点 / 运行中 spinner / 待办用紧凑文案替换时间) */
16510
+ const sessionStatusOf = (id) => {
16511
+ if (sessionStatusReady !== true) return { state: 'idle', label: t('session.status.idle') }
16512
+ const status = sessionStatuses instanceof Map ? sessionStatuses.get(id) : undefined
16513
+ const pending = status?.pendingInteraction?.kind
16514
+ if (pending === 'approval') return { state: 'warning', label: t('session.status.approval'), trailing: t('session.status.compact.approval') }
16515
+ if (pending === 'plan-review') return { state: 'warning', label: t('session.status.planReview'), trailing: t('session.status.compact.planReview') }
16516
+ if (pending === 'question') return { state: 'warning', label: t('session.status.question'), trailing: t('session.status.compact.question') }
16517
+ if (status?.running === true) return { state: 'ongoing', label: t('session.status.running') }
16518
+ if (status?.completionUnread === true) return { state: 'done', label: t('session.status.done') }
16519
+ return { state: 'idle', label: t('session.status.idle') }
16520
+ }
16521
+ const renderSessionRow = (session, extraKey) => {
16522
+ const view = sessionStatusOf(session.id)
16523
+ const trailing = view?.trailing
16524
+ return h(
16134
16525
  'button',
16135
16526
  {
16136
16527
  key: extraKey,
@@ -16143,12 +16534,27 @@ G.GufaApp = function GufaApp(props) {
16143
16534
  openSessionInWorkspace(session.id, dialogPath)
16144
16535
  },
16145
16536
  },
16146
- h(G.Icon, { name: 'message', size: 14 }),
16537
+ h(
16538
+ 'span',
16539
+ { className: 'gufa-session-row-status' },
16540
+ view !== null && view.state !== 'idle'
16541
+ ? h('span', {
16542
+ className: view.state === 'ongoing' ? 'gufa-session-state-spinner' : 'gufa-session-state-dot',
16543
+ 'data-state': view.state,
16544
+ title: view.label,
16545
+ role: 'img',
16546
+ 'aria-label': view.label,
16547
+ })
16548
+ : null,
16549
+ ),
16147
16550
  h('span', { className: 'gufa-session-row-title' }, session.title),
16148
- typeof session.when === 'number' && session.when > 0 && typeof G.relativeTime === 'function'
16149
- ? h('span', { className: 'gufa-session-row-when' }, G.relativeTime(session.when))
16150
- : null,
16551
+ trailing !== undefined
16552
+ ? h('span', { className: 'gufa-session-row-when' }, trailing)
16553
+ : typeof session.when === 'number' && session.when > 0 && typeof G.relativeTime === 'function'
16554
+ ? h('span', { className: 'gufa-session-row-when' }, G.relativeTime(session.when))
16555
+ : null,
16151
16556
  )
16557
+ }
16152
16558
  try {
16153
16559
  if (window.__gufaSessionsDiag === undefined || window.__gufaSessionsDiag > 0) {
16154
16560
  window.__gufaSessionsDiag = (window.__gufaSessionsDiag ?? 3) - 1