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.
@@ -378,6 +378,29 @@ G.GufaApp = function GufaApp(props) {
378
378
  const [workspaceSessions, setWorkspaceSessions] = useState({ status: 'idle', sessions: [], groups: [], sessionIds: [], archivedSessionIds: [] })
379
379
  const [workspaceIndex, setWorkspaceIndex] = useState([])
380
380
  const [recentCurrentIds, setRecentCurrentIds] = useState([])
381
+ /* 会话运行状态(与经典侧边栏同源:uiSession.sessionStatus,含 running/pendingInteraction/completionUnread) */
382
+ const [sessionStatuses, setSessionStatuses] = useState(() => new Map())
383
+ const [sessionStatusReady, setSessionStatusReady] = useState(false)
384
+ useEffect(() => {
385
+ const ui = G.ctx === null || G.ctx === undefined ? undefined : G.ctx.get('uiSession')
386
+ const source = ui?.sessionStatus
387
+ if (source === undefined || source === null || typeof source.getSnapshot !== 'function') return undefined
388
+ setSessionStatusReady(true)
389
+ const sync = () => {
390
+ try {
391
+ const snapshot = source.getSnapshot()
392
+ if (snapshot instanceof Map) setSessionStatuses(new Map(snapshot))
393
+ } catch {
394
+ /* ignore */
395
+ }
396
+ }
397
+ sync()
398
+ if (typeof source.subscribe !== 'function') return undefined
399
+ const dispose = source.subscribe(sync)
400
+ return () => {
401
+ if (typeof dispose === 'function') dispose()
402
+ }
403
+ }, [])
381
404
  const [sessionGroupOpen, setSessionGroupOpen] = useState({})
382
405
  const [workspaceBusy, setWorkspaceBusy] = useState(false)
383
406
  const [branchInput, setBranchInput] = useState('')
@@ -1002,24 +1025,29 @@ G.GufaApp = function GufaApp(props) {
1002
1025
  }, [])
1003
1026
 
1004
1027
  /* ── Git Graph(提交图标签页) ─────────────────────────────────────── */
1005
- const openGitGraph = useCallback(() => {
1028
+ const openGitGraph = useCallback((repo) => {
1006
1029
  if (project === null) return
1007
- const path = 'gufa-graph'
1030
+ const repoPath = repo !== null && repo !== undefined && typeof repo.path === 'string' ? repo.path : null
1031
+ const repoRel = repo !== null && repo !== undefined && typeof repo.rel === 'string' ? repo.rel : ''
1032
+ const path = repoPath !== null && repoRel !== '' ? `gufa-graph:${repoRel}` : 'gufa-graph'
1008
1033
  setTabs((current) => {
1009
- if (current.some((tab) => tab !== null && tab.path === path)) return current
1010
- return [...current, { path, title: 'Git Graph', kind: 'graph' }]
1034
+ const existing = current.find((tab) => tab !== null && tab.path === path)
1035
+ if (existing !== undefined) return current.map((tab) => (tab !== null && tab.path === path ? { ...tab, gitRepo: repoPath, gitRepoRel: repoRel } : tab))
1036
+ return [...current, { path, title: 'Git Graph', kind: 'graph', gitRepo: repoPath, gitRepoRel: repoRel }]
1011
1037
  })
1012
1038
  setActivePath(path)
1013
1039
  }, [project])
1014
1040
 
1015
1041
  /* Git Graph:点开某次提交里的文件 → 提交版本 diff(父提交 vs 该提交) */
1016
- const openCommitFile = useCallback(async (commit, file) => {
1042
+ const openCommitFile = useCallback(async (commit, file, repoCtx) => {
1017
1043
  if (project === null || commit === null || commit === undefined || file === null || file === undefined) return
1018
1044
  if (typeof file.path !== 'string' || file.path === '' || typeof commit.hash !== 'string') return
1045
+ const repoRoot = repoCtx !== null && repoCtx !== undefined && typeof repoCtx.path === 'string' ? repoCtx.path : undefined
1046
+ const repoRel = repoCtx !== null && repoCtx !== undefined && typeof repoCtx.rel === 'string' ? repoCtx.rel : ''
1019
1047
  try {
1020
1048
  const [leftResult, rightResult] = await Promise.all([
1021
- G.api('git.fileVersion', { root: project.root, path: file.path, hash: commit.hash, parent: true }).catch(() => ({ text: '' })),
1022
- G.api('git.fileVersion', { root: project.root, path: file.path, hash: commit.hash }).catch(() => ({ text: '' })),
1049
+ G.api('git.fileVersion', { root: project.root, repo: repoRoot, path: file.path, hash: commit.hash, parent: true }).catch(() => ({ text: '' })),
1050
+ G.api('git.fileVersion', { root: project.root, repo: repoRoot, path: file.path, hash: commit.hash }).catch(() => ({ text: '' })),
1023
1051
  ])
1024
1052
  const path = `gufa-commit:${commit.hash.slice(0, 10)}:${file.path}`
1025
1053
  const leftText = typeof leftResult?.text === 'string' ? leftResult.text : ''
@@ -1049,8 +1077,11 @@ G.GufaApp = function GufaApp(props) {
1049
1077
  }, [project])
1050
1078
 
1051
1079
  /* 分支切换 / 新建 ──────────────────────────────────────────────── */
1052
- const openBranchMenu = useCallback((event) => {
1053
- if (project === null || project.isGit !== true) return
1080
+ const openBranchMenu = useCallback((event, repo) => {
1081
+ if (project === null) return
1082
+ const repoPath = repo !== null && repo !== undefined && typeof repo.path === 'string' ? repo.path : undefined
1083
+ /* 工作区根目录不是 Git 仓库时,仍允许对子目录仓库切换分支 */
1084
+ if (repoPath === undefined && project.isGit !== true) return
1054
1085
  let placement = { x: 12, top: 40 }
1055
1086
  try {
1056
1087
  const rect = event !== null && event !== undefined && event.currentTarget !== null
@@ -1066,8 +1097,8 @@ G.GufaApp = function GufaApp(props) {
1066
1097
  /* ignore */
1067
1098
  }
1068
1099
  setBranchInput('')
1069
- setBranchMenu({ ...placement, loading: true, branches: [], error: '' })
1070
- void G.api('git.branches', { root: project.root })
1100
+ setBranchMenu({ ...placement, repo: repoPath, loading: true, branches: [], error: '' })
1101
+ void G.api('git.branches', { root: project.root, repo: repoPath })
1071
1102
  .then((value) => {
1072
1103
  setBranchMenu((current) => (current === null ? current : { ...current, loading: false, branches: Array.isArray(value?.branches) ? value.branches : [] }))
1073
1104
  })
@@ -1102,7 +1133,7 @@ G.GufaApp = function GufaApp(props) {
1102
1133
  const checkoutBranch = useCallback(async (name) => {
1103
1134
  if (project === null || typeof name !== 'string' || name === '') return
1104
1135
  try {
1105
- await G.api('git.checkout', { root: project.root, branch: name })
1136
+ await G.api('git.checkout', { root: project.root, repo: branchMenu?.repo, branch: name })
1106
1137
  closeBranchMenu()
1107
1138
  setGitRefreshToken((token) => token + 1)
1108
1139
  setRefreshToken((token) => token + 1)
@@ -1110,14 +1141,14 @@ G.GufaApp = function GufaApp(props) {
1110
1141
  } catch (error) {
1111
1142
  setBranchMenu((current) => (current === null ? current : { ...current, error: G.errorText(error) }))
1112
1143
  }
1113
- }, [project, closeBranchMenu, refreshGit])
1144
+ }, [project, branchMenu, closeBranchMenu, refreshGit])
1114
1145
 
1115
1146
  const createBranch = useCallback(async () => {
1116
1147
  if (project === null) return
1117
1148
  const name = branchInput.trim()
1118
1149
  if (name === '') return
1119
1150
  try {
1120
- await G.api('git.createBranch', { root: project.root, name })
1151
+ await G.api('git.createBranch', { root: project.root, repo: branchMenu?.repo, name })
1121
1152
  closeBranchMenu()
1122
1153
  setGitRefreshToken((token) => token + 1)
1123
1154
  setRefreshToken((token) => token + 1)
@@ -1125,7 +1156,7 @@ G.GufaApp = function GufaApp(props) {
1125
1156
  } catch (error) {
1126
1157
  setBranchMenu((current) => (current === null ? current : { ...current, error: G.errorText(error) }))
1127
1158
  }
1128
- }, [project, branchInput, closeBranchMenu, refreshGit])
1159
+ }, [project, branchMenu, branchInput, closeBranchMenu, refreshGit])
1129
1160
 
1130
1161
  /* ── 删除(无确认弹窗,软删除到临时目录,⌘Z 可撤销) ──────────────── */
1131
1162
  const deleteEntry = useCallback(async (path) => {
@@ -1196,7 +1227,12 @@ G.GufaApp = function GufaApp(props) {
1196
1227
  /* ── Git diff / 两文件对比(Monaco DiffEditor) ────────────────────── */
1197
1228
  const openDiffForChange = useCallback(async (change) => {
1198
1229
  if (project === null || change === null || typeof change !== 'object' || typeof change.path !== 'string') return
1199
- const existing = tabs.find((item) => item.path === change.path)
1230
+ /* 嵌套仓库:diff 的路径是仓库内相对路径,编辑器/文件读写的 path 需要补上仓库相对工作区的前缀 */
1231
+ const repoRoot = typeof change.repo === 'string' && change.repo !== '' ? change.repo : null
1232
+ const repoRel = typeof change.repoRel === 'string' ? change.repoRel : ''
1233
+ const wsPath = repoRel !== '' ? `${repoRel}/${change.path}` : change.path
1234
+ const gitBody = repoRoot !== null ? { root: project.root, repo: repoRoot } : { root: project.root }
1235
+ const existing = tabs.find((item) => item.path === wsPath)
1200
1236
  if (existing !== undefined && existing !== null && existing.kind !== 'diff' && existing.dirty === true) {
1201
1237
  setBanner('该文件有未保存修改,请先保存后再查看 diff')
1202
1238
  return
@@ -1205,14 +1241,14 @@ G.GufaApp = function GufaApp(props) {
1205
1241
  /* 文件可能已删除(工作树删掉/暂存区删除):读不到就按空处理,仍然展示差异 */
1206
1242
  let file = null
1207
1243
  try {
1208
- file = await G.api('fs.read', { root: project.root, path: change.path })
1244
+ file = await G.api('fs.read', { root: project.root, path: wsPath })
1209
1245
  } catch {
1210
1246
  file = null
1211
1247
  }
1212
1248
  let left = ''
1213
1249
  try {
1214
1250
  const shown = await G.api('git.show', {
1215
- root: project.root,
1251
+ ...gitBody,
1216
1252
  path: change.path,
1217
1253
  rev: change.staged === true ? 'head' : 'index',
1218
1254
  })
@@ -1224,14 +1260,14 @@ G.GufaApp = function GufaApp(props) {
1224
1260
  if (change.staged === true) {
1225
1261
  /* 暂存区 diff = HEAD ↔ 索引;右侧必须用索引内容,而不是工作树(工作树可能还有未暂存改动) */
1226
1262
  try {
1227
- const indexDoc = await G.api('git.show', { root: project.root, path: change.path, rev: 'index' })
1263
+ const indexDoc = await G.api('git.show', { ...gitBody, path: change.path, rev: 'index' })
1228
1264
  rightContent = typeof indexDoc.text === 'string' ? indexDoc.text : ''
1229
1265
  } catch {
1230
1266
  rightContent = ''
1231
1267
  }
1232
1268
  }
1233
1269
  const tab = {
1234
- path: change.path,
1270
+ path: wsPath,
1235
1271
  title: `${G.basename(change.path)}(${change.staged === true ? '暂存区' : '工作树'})`,
1236
1272
  kind: 'diff',
1237
1273
  content: rightContent,
@@ -1240,17 +1276,17 @@ G.GufaApp = function GufaApp(props) {
1240
1276
  dirty: false,
1241
1277
  language: file?.language ?? 'plaintext',
1242
1278
  size: file?.size,
1243
- diff: { left, staged: change.staged === true, editable: change.staged !== true },
1279
+ diff: { left, staged: change.staged === true, editable: change.staged !== true, gitRepo: repoRoot },
1244
1280
  diffKey: Date.now(),
1245
1281
  }
1246
1282
  setTabs((current) => {
1247
- const index = current.findIndex((item) => item.path === change.path)
1283
+ const index = current.findIndex((item) => item.path === wsPath)
1248
1284
  if (index === -1) return [...current, tab]
1249
1285
  const next = current.slice()
1250
1286
  next[index] = { ...next[index], ...tab }
1251
1287
  return next
1252
1288
  })
1253
- setActivePath(change.path)
1289
+ setActivePath(wsPath)
1254
1290
  setBanner('')
1255
1291
  } catch (error) {
1256
1292
  setBanner(G.errorText(error))
@@ -2614,8 +2650,8 @@ G.GufaApp = function GufaApp(props) {
2614
2650
  onStatus: setGitStatus,
2615
2651
  onOpenFile: (path) => void openFile(path),
2616
2652
  onOpenDiff: (change) => void openDiffForChange(change),
2617
- onOpenBranches: (event) => openBranchMenu(event),
2618
- onOpenGraph: () => openGitGraph(),
2653
+ onOpenBranches: (event, repo) => openBranchMenu(event, repo),
2654
+ onOpenGraph: (repo) => openGitGraph(repo),
2619
2655
  onChanged: () => { setRefreshToken((token) => token + 1) },
2620
2656
  })),
2621
2657
  h('div', { key: 'ssh', style: { display: ui.view === 'ssh' ? 'flex' : 'none', flex: '1 1 auto', minHeight: 0, flexDirection: 'column' } },
@@ -2910,9 +2946,10 @@ G.GufaApp = function GufaApp(props) {
2910
2946
  : activeTab.kind === 'graph'
2911
2947
  ? h(G.GitGraphView, {
2912
2948
  root: project?.root ?? null,
2949
+ repo: activeTab.gitRepo ?? null,
2913
2950
  refreshToken: gitRefreshToken,
2914
2951
  onRefresh: () => setGitRefreshToken((token) => token + 1),
2915
- onOpenCommitFile: (commit, file) => void openCommitFile(commit, file),
2952
+ onOpenCommitFile: (commit, file) => void openCommitFile(commit, file, { path: activeTab.gitRepo, rel: activeTab.gitRepoRel }),
2916
2953
  })
2917
2954
  : h(G.EditorPane, {
2918
2955
  tabs,
@@ -3492,8 +3529,22 @@ G.GufaApp = function GufaApp(props) {
3492
3529
  return true
3493
3530
  })
3494
3531
  .map((row) => ({ id: row.id, title: row.title, when: row.when }))
3495
- const renderSessionRow = (session, extraKey) =>
3496
- h(
3532
+ /* 会话状态:与经典侧边栏同款(16px 状态点 / 运行中 spinner / 待办用紧凑文案替换时间) */
3533
+ const sessionStatusOf = (id) => {
3534
+ if (sessionStatusReady !== true) return { state: 'idle', label: t('session.status.idle') }
3535
+ const status = sessionStatuses instanceof Map ? sessionStatuses.get(id) : undefined
3536
+ const pending = status?.pendingInteraction?.kind
3537
+ if (pending === 'approval') return { state: 'warning', label: t('session.status.approval'), trailing: t('session.status.compact.approval') }
3538
+ if (pending === 'plan-review') return { state: 'warning', label: t('session.status.planReview'), trailing: t('session.status.compact.planReview') }
3539
+ if (pending === 'question') return { state: 'warning', label: t('session.status.question'), trailing: t('session.status.compact.question') }
3540
+ if (status?.running === true) return { state: 'ongoing', label: t('session.status.running') }
3541
+ if (status?.completionUnread === true) return { state: 'done', label: t('session.status.done') }
3542
+ return { state: 'idle', label: t('session.status.idle') }
3543
+ }
3544
+ const renderSessionRow = (session, extraKey) => {
3545
+ const view = sessionStatusOf(session.id)
3546
+ const trailing = view?.trailing
3547
+ return h(
3497
3548
  'button',
3498
3549
  {
3499
3550
  key: extraKey,
@@ -3506,12 +3557,27 @@ G.GufaApp = function GufaApp(props) {
3506
3557
  openSessionInWorkspace(session.id, dialogPath)
3507
3558
  },
3508
3559
  },
3509
- h(G.Icon, { name: 'message', size: 14 }),
3560
+ h(
3561
+ 'span',
3562
+ { className: 'gufa-session-row-status' },
3563
+ view !== null && view.state !== 'idle'
3564
+ ? h('span', {
3565
+ className: view.state === 'ongoing' ? 'gufa-session-state-spinner' : 'gufa-session-state-dot',
3566
+ 'data-state': view.state,
3567
+ title: view.label,
3568
+ role: 'img',
3569
+ 'aria-label': view.label,
3570
+ })
3571
+ : null,
3572
+ ),
3510
3573
  h('span', { className: 'gufa-session-row-title' }, session.title),
3511
- typeof session.when === 'number' && session.when > 0 && typeof G.relativeTime === 'function'
3512
- ? h('span', { className: 'gufa-session-row-when' }, G.relativeTime(session.when))
3513
- : null,
3574
+ trailing !== undefined
3575
+ ? h('span', { className: 'gufa-session-row-when' }, trailing)
3576
+ : typeof session.when === 'number' && session.when > 0 && typeof G.relativeTime === 'function'
3577
+ ? h('span', { className: 'gufa-session-row-when' }, G.relativeTime(session.when))
3578
+ : null,
3514
3579
  )
3580
+ }
3515
3581
  try {
3516
3582
  if (window.__gufaSessionsDiag === undefined || window.__gufaSessionsDiag > 0) {
3517
3583
  window.__gufaSessionsDiag = (window.__gufaSessionsDiag ?? 3) - 1