当前项目已经具备一套比较清晰的分层和跨端通信骨架:
IServiceAccessor + RPC 服务链路访问业务能力IPlatformService 只承载必须经过宿主环境的动作,不承载常规业务逻辑Git 功能如果要长期可维护,应该复用现有服务架构,而不是走新的直连路径。
Types -> Config -> Repo -> Service -> Runtime -> UI 依赖方向内IPlatformService推荐新增 IGitService,走现有 RPC 服务链路。
原因:
这也符合当前 IPlatformService 的职责边界:它只放 native dialog、窗口控制、外链打开之类“必须穿越宿主边界”的操作。
GitService,本地 / 远程都走同一服务协议这是推荐方案。
flowchart LR
UI["UI / Hooks / Side Pane"] --> Runtime["useGitRepository / useGitActions"]
Runtime --> RPC["RPC Channel"]
RPC --> Service["IGitService"]
Service --> Repo["GitCliRepo"]
Repo --> Provider["GitCommandProvider"]
Provider --> Git["System Git CLI"]
建议新增 Git 领域 DTO,放到 packages/shared/src/git.ts,并在 packages/shared/src/index.ts 导出。
建议至少包含:
GitRepositorySummary
workspacePathrepoRootworkspaceInRepoPathbranchNameheadRefTypeaheadbehindisDirtyisGitAvailableisRepositoryGitFileChange
pathrepoRelativePathworkspaceRelativePathxykindisStagedisUntrackedisConflictedGitDiffRequestGitDiffResultGitIdentity
userNameuserEmailnameSourceemailSource建议新增 Git 领域配置层,负责:
建议文件:
packages/services/src/git/config.ts为了符合项目里“横切关注点通过 Providers 进入”的原则,Git 域内部建议显式引入 Provider 层。
建议至少拆成两个 provider:
GitCommandProvider
git 命令GitEnvironmentProvider
Provider 层只做“如何执行”和“如何适配环境”,不做 Git 业务语义。
Repo 层是对 Git CLI 的薄封装,不承载 UI 语义。
建议文件:
packages/services/src/git/repo/gitCliRepo.ts建议职责:
resolveRepository(workspacePath)getStatus(workspacePath)getDiff(workspacePath, path, staged)stage(workspacePath, paths)unstage(workspacePath, paths)discard(workspacePath, paths, stagedScope)commit(workspacePath, message)getIdentity(workspacePath)Service 层对 UI 暴露稳定语义,并隐藏 Git CLI 细节。
建议文件:
packages/services/src/git/git.tspackages/services/src/git/gitService.ts建议对外接口:
getRepositorySummarygetChangesgetDiffgetBranchComparisonstagePathsunstagePathsdiscardPathscommitgetIdentityrefresh如果后续需要订阅式刷新,再补动态事件:
onDynamicRepositoryEvent(workspacePath)UI 层只通过 hooks 消费 IGitService。
当前 hooks:
packages/ui/src/hooks/useGitRepository.tspackages/ui/src/hooks/useGitActions.tspackages/ui/src/hooks/useGitAutoRefresh.tsUI 组件建议:
GitPaneGitRepositoryHeaderGitChangeSourceSelectGitChangesTreeGitDiffPanelGitCommitPanelGit pane 左侧建议有一个变更来源下拉,不同模式切换不同的数据来源。
建议支持四种模式:
未暂存
getChanges / getDiff已暂存
HEAD 的改动getChanges / getDiff全部分支更改
getBranchComparison上一轮更改
IGitService这里建议把“Git pane”理解为“统一的改动审阅面板”,而不是把每一种视图都硬塞成 Git service 的职责。
其中:
IGitService上一轮更改 属于会话级改动审阅,只在 Git pane 里共用一套树和 diff 展示壳,保持只读这样做的好处是:
上一轮更改 不需要为了 UI 入口位置而伪装成 Git 数据createLocalServices() 注册本地 GitServicefile/system/terminal 一样,来自远端服务结论:
file/system/terminal 对齐,而不是和 setting 对齐推荐坚持使用系统 Git CLI,而不是引入 JS Git 实现。
原因:
includeIf、平台默认路径、Git for Windows 等真实环境建议命令:
git rev-parse --show-toplevelgit status --porcelain=v2 --branch -zgit config --get user.namegit config --get user.emailgit config --list --show-origin --nullgit diff --no-ext-diff -- <path>git diff --cached --no-ext-diff -- <path>git diff @{upstream}...HEAD --git add -- <path...>git restore --staged -- <path...>git restore --worktree -- <path...>git commit -m <message>workspacePath 不一定等于 repoRoot。
例如:
因此 Git 域必须同时保留三类路径:
workspacePathrepoRootworkspaceInRepoPath推荐行为:
repoRoot 执行 Git这样能避免 workspace 打开的是子目录时,直接看到整仓库其它区域变更而产生困惑。
根据项目约束,涉及交互和复杂状态切换的能力需要补日志。
建议:
packages/ui/src/logger.tsGitCommandProvider 不默认打印每条 Git 命令;Git 探测和状态查询属于高频内部细节,
需要排查时优先在上层一次性生命周期、失败分支或专门调试入口补充有边界的日志。不要记录:
当前右侧共享 pane 已经统一承载 browser 和 code-viewer。
推荐扩展为:
browsercode-viewergit而不是在左侧 WorkspaceSidebar 再新增一个与 task 并列的大导航区。
原因:
IGitService上一轮更改 的数据复用方式,后续结合现有 task store 再细化GitService