44 Commits
Author SHA1 Message Date
fenghpandCursor 646665f3a3 refactor: 更新挂起更改处理逻辑与组件交互
- 将 `onToggleExcluded` 方法重命名为 `onSetExcluded`,并更新相关调用,支持批量设置挂起更改的 Included/Excluded 状态。
- 在 `ChangesPanel` 组件中实现目录树结构,支持折叠与三态复选功能,提升用户体验。
- 修改 `Checkbox` 组件以支持不确定状态的显示,增强视觉反馈。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-27 11:48:49 +08:00
fenghpandCursor 24de23ee61 feat: 增加父进程看护机制与操作来源标识
- 新增 startParentWatchdog 方法,监控宿主进程状态,确保后端在宿主崩溃时自动退出,避免端口占用。
- 在 API 请求中引入 X-MacTFS-Source 请求头,区分来自 MCP(AI)与手动操作的请求,增强操作日志的可追溯性。
- 更新操作日志结构,记录操作来源,支持在前端进行来源过滤展示。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-26 14:15:08 +08:00
fenghp 3cf42cdbaf 添加 mcp 说明 2026-06-23 17:49:58 +08:00
fenghpandCursor b03ca2c4d5 fix: 补上 main.cjs 缺失的 MCP_HOST 常量,修复打包版主进程启动崩溃
新增的 MCP_SSE_URL / MCP_HEALTHZ_URL 引用了未定义的 MCP_HOST,
导致主进程模块加载即抛 ReferenceError(开发态未触发,仅安装版暴露)。
补上 const MCP_HOST = "127.0.0.1"。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-23 11:25:23 +08:00
fenghpandCursor 03eb61520f build: 将 mactfs-mcp 以 esbuild 单文件打进 .app
- mactfs-mcp 增加 esbuild 与 build:bundle 脚本,产出单文件 dist-bundle/index.cjs
  (免带 node_modules),用 .cjs 规避 type:module 下的 ESM 误判
- mactfsui extraResources 增加 { from: ../mactfs-mcp/dist-bundle, to: mcp },
  dist 链路加入 prepare:mcp(自动 install + build:bundle)
- Electron resolveMcpEntry 打包态改为命中 Resources/mcp/index.cjs
- 同步更新 mactfs-mcp/README 与打包构建文档(移除「MCP 未打进 .app」的旧限制)

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-23 11:17:00 +08:00
fenghpandCursor 9018a6c90e feat: 顶栏新增 TFS 连接测试与 MCP 状态/日志查看
- 后端新增只读端点 POST /api/session/test:用已存配置真正回连一次 TFS,
  验证服务可达与认证有效,不改动会话/配置状态,返回耗时与 Collection 数
- 顶栏加「测试 TFS 连接」按钮:手动触发,图标按结果变色(绿=正常/红=断开),
  结果走右上角 toast
- Electron 将 MCP 子进程 stdio 由 ignore 改为管道捕获,环形缓冲保留最近 500 行;
  跟踪运行状态(pid/运行时长/重启次数/退出码)并探活 /healthz,新增 get-mcp-status
  / get-mcp-logs 两个 IPC,经 preload 与 lib/electron 暴露
- 顶栏加「MCP 服务状态」入口,新增 McpStatusDialog 展示状态摘要与运行日志
  (打开期间每 2 秒刷新、自动滚到底部)

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-23 11:05:19 +08:00
fenghpandCursor e9f942e695 feat: 新增 mactfs-mcp 服务(AI 改文件前自动签出/加入)
- mactfs-mcp:通过 SSE 暴露 tfs_checkout / tfs_add,转调本机 Java 后端操作 TFS
- 后端 MacTfsCoreService/MacTfsServer 新增文件状态查询等接口,供 MCP 执行前校验
- Electron 随客户端拉起并回收 MCP 子进程(父死自杀、崩溃自动重拉)
- tfs_checkout 默认行为:新文件自动 add、本地落后自动 get-latest 后再签出
  (可分别用 autoAdd=false / getLatestIfStale=false 关闭;dryRun 无副作用)
- 新增 docs/打包构建与MCP使用指南.md

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-23 10:31:31 +08:00
fenghpandCursor 627adc907e docs: README 补充未签名应用首次打开方法(xattr 去隔离 + 隐私与安全性)
新增「下载安装」章节,指向 GitHub Releases 并区分 arm64/x64 安装包;
说明 Gatekeeper 拦截后的两种解除方式(系统设置仍要打开 / xattr 去隔离属性)。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-16 17:17:56 +08:00
fenghpandCursor b2b2f49db6 chore: 将 main 整棵树对齐到 feature 分支(移除并行分支遗留文件与重复声明,确保可构建)
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-16 14:37:39 +08:00
fenghpandCursor 1dfe081713 fix: 移除合并产生的大小写重复文件 AGENTS.md(保留 Agents.md)
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-16 14:35:32 +08:00
fenghp a107ec1f2c Merge feature/ui-macos-restyle into main
合并 macOS 原生风 UI 改版分支,冲突以 feature 分支为准
(feature 为当前维护主线,取代 main 上的并行前端尝试)。

Co-authored-by: Cursor <cursoragent@cursor.com>

# Conflicts:
#	task/frontend/FE-001-实现Electron启动服务与API客户端.md
#	task/frontend/FE-002-实现登录配置页.md
#	task/frontend/FE-003-实现VS风格主布局.md
#	task/frontend/FE-004-实现Collection服务端目录树.md
#	task/frontend/FE-005-实现中间目录文件列表.md
#	task/frontend/FE-006-实现Mapping创建流程.md
#	task/frontend/FE-007-实现目录对比页面.md
#	task/frontend/FE-008-实现右侧挂起更改面板.md
#	task/frontend/FE-009-实现文件操作交互.md
#	task/frontend/FE-010-实现签入流程.md
#	task/frontend/FE-011-实现历史记录界面.md
#	task/frontend/FE-012-实现文件Diff界面.md
#	task/frontend/FE-013-实现操作日志面板.md
2026-06-16 14:33:47 +08:00
fenghpandCursor 4681ff914f docs: 新增项目 README(含 AI 生成声明与亮色演示截图)
- 根目录新增 README:介绍、架构、环境、快速开始、用法,并声明纯 AI 生成
- docs/screenshots 新增 5 张亮色演示截图(假数据,非真实服务器)
- 精简 mactfsui/README 默认模板为指向根 README 的说明

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-16 14:30:17 +08:00
fenghpandCursor e1a5793a62 release: Electron打包(electron-builder) + JDK运行时按需从Azul下载
- mactfsui 增加 electron-builder 配置与 dist/prepare:runtime 脚本,打包 universal DMG,服务端随 extraResources 内置 x64 JRE 与 jar
- main.cjs 打包态解析 jre-x64/server/lib,新增 app:// 自定义协议加载前端静态资源避免白屏
- prepare-runtime.mjs 本地无 JDK 时自动从 Azul 下载并校验 sha256 后解压,避免把 206M JDK 入库
- 整理 .gitignore:忽略 dist-app/runtime/icon.iconset 及 aarch64 JDK

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-16 12:37:10 +08:00
fenghpandCursor fcf7952ee3 体验: 顶栏改程序名+Collection胶囊,画布卡片层次强化,修复侧栏长文本截断无省略号
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-12 20:46:40 +08:00
fenghpandCursor 08bb38b188 体验: toast改macOS通知风圆徽毛玻璃卡片,移除明暗主题切换仅保留亮色
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-12 20:15:53 +08:00
fenghpandCursor fe8b23225a 体验: 工作台改画布卡片式布局,toast提示移到右上角加彩色强调条更显眼
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-11 21:06:56 +08:00
fenghpandCursor 2768eafd93 frontend: FE-034 macOS风UI改版回归验收,真实TFS走查13项通过并归档关键截图
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-11 20:37:44 +08:00
fenghpandCursor 380280bace frontend: FE-033 明暗主题三态切换并跟随系统,防闪白+全局过渡+Monaco同步
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-11 20:31:25 +08:00
fenghpandCursor 4703a03f21 frontend: FE-032 轻量toast接管动作通知+日志滑入+按钮按压与勾选动画
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-11 20:24:57 +08:00
fenghpandCursor 261778732d frontend: FE-031 弹窗统一macOS Sheet风格,顶部锚定下滑出场+分层阴影
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-11 20:21:49 +08:00
fenghpandCursor 581cfb559c frontend: FE-030 目录树与文件列表精致化,图标体系+骨架屏+空状态+行级联动效+表头固定与滚动条修正
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-11 20:18:35 +08:00
fenghpandCursor c0f613fcb6 frontend: FE-029 Finder式工作台外壳,毛玻璃侧栏+透明工具栏+折叠过渡动画+动作图标化
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-11 20:14:46 +08:00
fenghpandCursor eec2cc85a3 frontend: FE-028 macOS风登录页,毛玻璃品牌区大logo+分步动效+最近连接+密码切换+失败抖动
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-11 20:11:08 +08:00
fenghpandCursor 3d1ffd0e81 frontend: FE-027 隐藏式标题栏+窗口vibrancy毛玻璃+防白闪+启动最大化+顶栏拖拽
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-11 20:07:57 +08:00
fenghpandCursor b19c6895a3 frontend: FE-026 macOS设计基建,系统字体+macOS蓝主色+半透明材质变量+圆角阴影动效令牌
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-11 20:04:38 +08:00
fenghpandCursor fbd16013e6 需求: macOS原生风UI改版需求文档与任务拆分(FE-026~034),与现代工具风分支并行对比
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-11 16:53:46 +08:00
fenghpandCursor b1a5b2f16b 体验: 目录对比改为先确认选项再执行,避免进入弹窗即自动对比与切换选项重复对比
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-11 15:59:22 +08:00
fenghpandCursor bba6e89a16 体验: 目录对比改为忽略仅本地存在的项(如 node_modules),勾选后跳过本地全量扫描提速
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-11 15:53:40 +08:00
fenghpandCursor b247a18155 体验: 目录对比执行签出等动作后自动重新对比,新增忽略仅服务器存在项的过滤开关
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-11 15:31:12 +08:00
fenghpandCursor b156f505eb 修复: 目录对比漏报未签出的纯本地修改,文件变为可写即按本地已修改处理(对齐 VS writable 判定)
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-11 15:22:18 +08:00
fenghpandCursor b3454eb157 品牌: 项目更名为 MacTFS,Electron 窗口与程序坞使用根目录 logo 图标
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-11 15:04:49 +08:00
fenghpandCursor fe4c573585 优化: 添加本地文件改为扫描式(FE-025修订),目录对比自动筛出本地新增项勾选添加
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-11 14:39:20 +08:00
fenghpandCursor 75c8e00e19 功能: 右键支持在访达中打开与添加本地文件到版本控制(FE-025),中间区域空白处提供当前目录菜单
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-11 14:23:13 +08:00
fenghpandCursor 6910563078 功能: 实现分支间合并向导(FE-024),候选变更集可全部或单个合并,冲突走冲突弹窗
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-11 13:31:25 +08:00
fenghpandCursor cfa4141c1a 功能: 文件与目录支持分支(FE-023),pendBranch 产生挂起更改审查后签入
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-11 13:26:12 +08:00
fenghpandCursor f09b8f95b4 功能: 顶栏新增工作区集中管理弹窗(FE-022),支持 Mapping 新增删除与修改本地路径
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-11 13:21:29 +08:00
fenghpandCursor 63f7111bcd 功能: 历史记录支持回滚变更集与回滚到变更集(FE-021),结果为挂起更改审查后签入
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-11 13:17:24 +08:00
fenghpandCursor 4ba868482b 功能: 文件与目录支持重命名(FE-020),挂起面板展示旧名→新名
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-11 13:11:55 +08:00
fenghpandCursor 23062e8333 功能: 右键新增属性弹窗与获取特定版本(FE-019),服务端新增 /api/items/info
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-11 12:58:11 +08:00
fenghpandCursor 0c2324b1db 需求: 梳理第二批工作台增强需求并拆分 FE-019~024 任务(属性/获取特定版本/重命名/回滚/工作区管理/分支合并)
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-11 12:47:30 +08:00
fenghpandCursor 0418a93890 修复: Diff 统一视图下出现两列紧贴行号,启用 compactMode 仅保留新版行号
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-11 12:30:23 +08:00
fenghp acb388d22d 完成阶段5前端重构并固定后端JDK 2026-06-09 15:09:25 +08:00
fenghp 1bc913c54e Merge codex/frontend 2026-06-09 10:08:06 +08:00
fenghp 8692edd2dd Add frontend workspace UI and refactor plan 2026-06-09 10:07:22 +08:00
106 changed files with 11467 additions and 526 deletions
+1
View File
@@ -32,6 +32,7 @@ workspace/
# Local JDK
zulu8.94.0.17-ca-jdk8.0.492-macosx_x64/
zulu8.94.0.17-ca-jdk8.0.492-macosx_aarch64/
# E2E 截图
**/.e2e-shots/
+237
View File
@@ -0,0 +1,237 @@
# macTFS
> 🤖 **本项目由 Claude(Anthropic AI)生成**:从产品需求、前后端代码,到这份 README 和界面截图,均为纯 AI 生成的实验性作品。
>
> 🤖 _Built entirely by Claude (Anthropic's AI). Requirements, code, this README, and screenshots are all AI-generated._
> macOS 上的 TFS(Azure DevOps Server)版本控制客户端 —— 脱离 IDE 宿主,独立运行的桌面应用 + 本地 HTTP API。
macTFS 让你在 **macOS(含 Apple Silicon)** 上直接对 **TFS / TFVC** 仓库做日常版本控制:获取最新、签出、签入、查看历史、目录与文件对比……不再依赖 Windows + Visual Studio,也不用为了一个 TFS 插件背着一整个 IntelliJ。
它由一个 **Electron 桌面前端** 和一个 **常驻本地 Java 服务** 组成。Java 服务复用微软官方的 TFS Java SDK 与 TFS 通信,并把能力封装成 `127.0.0.1` 上的 REST API —— 所以除了图形界面,你也可以用 `curl` / 脚本 / CI 直接调用。
---
## 截图
> 以下为演示数据,非真实服务器内容。
### 连接 TFS
| 填写连接信息 | 选择 Collection |
| :---: | :---: |
| ![连接页](docs/screenshots/connect.png) | ![选择 Collection](docs/screenshots/collections.png) |
### 工作台
三栏布局:左侧服务端目录树、中间文件列表、右侧挂起更改与签入、底部操作日志。
![工作台](docs/screenshots/workspace.png)
### 对比与 Diff
| 目录对比 | 文件 Diff(Monaco) |
| :---: | :---: |
| ![目录对比](docs/screenshots/compare.png) | ![文件 Diff](docs/screenshots/diff.png) |
---
## 下载安装
普通用户无需自行构建,直接到 [GitHub Releases](https://github.com/Farewell0375/MacTFS/releases/latest) 下载对应芯片的安装包:
| 安装包 | 适用机型 |
| --- | --- |
| `MacTFS-<版本>-arm64.dmg` | Apple Silicon(M 系列芯片) |
| `MacTFS-<版本>-x64.dmg` | Intel 芯片 |
打开 DMG,把 `MacTFS.app` 拖进「应用程序」即可。
### 首次打开:应用未签名怎么办
本应用**未做 Apple 代码签名 / 公证**,首次打开 macOS 的 Gatekeeper 会拦截,提示「无法验证开发者」或「"MacTFS" 已损坏,无法打开」。这是未签名应用的正常现象,二选一解除即可:
**方法一 · 图形界面**
1. 双击 `MacTFS.app`,弹窗里先点「完成 / 取消」。
2. 打开 **系统设置 → 隐私与安全性**,下拉到「安全性」区域,会看到一条「已阻止使用 MacTFS」的提示,点 **仍要打开**。
3. 再次确认,之后即可正常启动。
**方法二 · 终端去掉隔离属性(推荐,最省事)**
把应用拖进「应用程序」后,在终端执行下面这条命令,去掉 macOS 给下载文件打的隔离标记(quarantine):
```bash
xattr -dr com.apple.quarantine /Applications/MacTFS.app
```
执行后直接双击即可打开。若仍提示「已损坏」,再用这条(会清除全部扩展属性):
```bash
sudo xattr -cr /Applications/MacTFS.app
```
> 这些步骤只是绕过「未签名」拦截,应用本身不会因此被修改。介意签名/公证的话,需要 Apple 开发者账号自行签名。
---
## 为什么做它
- **macOS 上几乎没有顺手的 TFVC 客户端。** 微软官方的 Team Explorer Everywhere 只剩命令行 / 老 Eclipse 插件且基本停更;IntelliJ 的 TFS 插件又必须绑着 IDE。
- **想要一个能独立运行、界面现代、对 Apple Silicon 友好的桌面工具。** 这就是 macTFS 的目标——为自己/小团队打造的「天天能用」的工具。
- **顺带提供 HTTP API。** 让 TFS 操作能被脚本和 CI 复用,而不只是点界面。
---
## 核心功能
- **连接与认证**:配置 TFS 服务器地址、NTLM 账号密码,测试连接、保持会话。
- **Collection / Workspace / Mapping**:选择项目集合,自动确保默认工作区,集中管理服务端路径 ↔ 本地路径映射。
- **服务端目录浏览**:左侧目录树 + 中间文件列表,同步导航、右键菜单统一动作。
- **文件同步**:Get Latest、获取指定版本 / Changeset。
- **签出签入闭环**:Checkout / Checkin / Add / Delete / Undo,签入附注释。
- **本地变更管理**:扫描并展示 Pending Changes,分组签入。
- **历史与对比**:文件 / 路径历史、Changeset 详情、本地 vs 云端 Diff、版本间对比、目录对比。
- **macOS 原生观感**:仿 Finder 的工作台、Sheet 风格弹窗与轻量动效。
- **操作日志**:底部可折叠控制台实时展示操作与错误。
> 完整的需求与 API 清单见 [`docs/mactfs-prd.md`](docs/mactfs-prd.md)。
---
## 技术架构
```
┌──────────────────────────────────────────────────────────┐
│ 消费端:Electron UI │ curl │ 脚本 │ CI Pipeline │
└──────────────────────────┬───────────────────────────────┘
│ HTTP REST (localhost:38765)
▼
┌──────────────────────────────────────────────────────────┐
│ mactfs-server(Java 8 + SparkJava) │
│ HTTP 路由 · 会话管理 · 配置存储 · TFS 核心服务层 │
└──────────────────────────┬───────────────────────────────┘
▼
┌──────────────────────────────────────────────────────────┐
│ Microsoft TFS SDK(tfsIntegration/lib) │
│ SOAP 通信 · NTLM 认证 · 版本控制 │
└──────────────────────────────────────────────────────────┘
```
| 层级 | 技术 |
| --- | --- |
| 前端 | Electron + React 19 + React Router 7 + shadcn/ui + Tailwind CSS 4 + Monaco |
| 后端 | Java 8 + SparkJava(内嵌 HTTP 服务) |
| TFS 内核 | Microsoft TFS Java SDK(SOAP / NTLM) |
| 运行环境 | Zulu JDK 8 **x86_64** + Rosetta 2(见下方说明) |
> ⚠️ **为什么固定 x64 JDK:** TFS SDK 的 JNI 原生库只含 i386/x86_64,没有 arm64 切片。因此服务端 JVM 固定走 x64,在 Apple Silicon 上经 Rosetta 2 运行;Electron 界面本身仍是原生。
---
## 环境要求
- macOS 12+(Intel 或 Apple Silicon;Apple Silicon 需安装 Rosetta 2)
- [pnpm](https://pnpm.io/)(前端包管理)
- 首次构建需联网(自动下载 x64 JDK,见下)
- 目标 TFS:TFS 2015 及以下(TFVC)
---
## 快速开始
### 1. 克隆
```bash
git clone <你的仓库地址> mactfs
cd mactfs/mactfsui
pnpm install
```
### 2. 准备 x64 JDK(自动)
服务端需要一个 x64 的 JDK 8。仓库**不**收录这个 200M+ 的二进制,而是按需从 Azul 官方下载并校验:
```bash
cd mactfsui
pnpm prepare:runtime
```
脚本会检测本地是否已有 `zulu8.94.0.17-ca-jdk8.0.492-macosx_x64/`,没有就从 Azul 下载 → 校验 sha256 → 解压到仓库根目录。`pnpm dist` 会自动先跑这一步。
### 3. 构建后端
```bash
cd mactfs
../tfsIntegration/gradlew installDist
```
> 后端从 `mactfs/build/install/mactfs/lib/` 加载运行,改了 Java 代码必须重新 `installDist`。
### 4. 开发模式运行(推荐)
```bash
cd mactfsui
pnpm electron:dev
```
会同时拉起 vite 开发服务器和 Electron 窗口;Electron 发现后端没运行时会自动拉起它,退出时自动回收。
### 5. 打包成桌面应用(.app / .dmg)
```bash
cd mactfsui
pnpm dist
```
产物输出到 `mactfsui/dist-app/`(universal DMG,内置精简后的 x64 JRE 与服务端 jar)。
> 启动 / 停止 / 重启 / 排错的完整说明见 [`服务启停指南.md`](服务启停指南.md)。
---
## 使用流程
1. **连接**:填入 TFS 服务器地址、认证方式(NTLM)、账号 / 域 / 密码,点测试连接。
2. **选择 Collection**:登录成功后选择要操作的项目集合,系统自动确保默认 Workspace。
3. **建立映射**:在目录树或文件列表上「映射到本地」,把服务端路径绑到本地目录(可选立即 Get Latest)。
4. **同步文件**:对映射执行 Get Latest,或获取指定版本。
5. **改 → 签出 → 签入**:编辑文件后在右侧 Changes 面板查看 Pending Changes,填注释签入。
6. **历史 / 对比**:右键查看历史、Changeset 详情,或做本地 vs 云端、版本间、目录级的 Diff。
### 也可以直接调 API
服务监听 `127.0.0.1:38765`,token 存在 `~/.mactfs/server-token`:
```bash
TOKEN=$(cat ~/.mactfs/server-token)
curl -s -H "Authorization: Bearer $TOKEN" http://127.0.0.1:38765/api/health
```
完整 API 清单见 [`docs/mactfs-prd.md`](docs/mactfs-prd.md) 第四章。
---
## 目录结构
```
mydev/
├── mactfs/ # Java 后端:CLI + 本地 HTTP API 服务
├── mactfsui/ # Electron + React 桌面前端
│ ├── app/ # 前端源码(页面、组件、API client)
│ ├── electron/ # Electron 主进程 / preload
│ └── scripts/ # 打包辅助脚本(prepare-runtime.mjs 等)
├── tfsIntegration/ # 微软 TFS Java SDK 及原生库(构建依赖)
├── docs/ # PRD、需求、截图等文档
├── task/ # 分阶段开发任务单
└── testing/ # 端到端 / 接口测试报告
```
---
## 第三方依赖与许可
- 本项目通过 `tfsIntegration/` 下的 **Microsoft TFS Java SDK** 与 TFS 通信,其分发受微软相应许可约束。
- x64 JDK 由 [Azul Zulu](https://www.azul.com/downloads/) 提供,按需下载,不随仓库分发。
> macTFS 是面向个人 / 小团队的工具型项目,主要解决「在 Mac 上用老 TFS」这一具体痛点。
@@ -0,0 +1,156 @@
# macTFS 工作台增强需求·第二批(属性 / 重命名 / 回滚 / 工作区管理 / 分支合并)
## 一、背景
第一批增强(FE-014 ~ FE-017,见 [mactfs-ui-enhancement-requirements.md](/Users/fenghp/Desktop/DEV/project/mydev/docs/mactfs-ui-enhancement-requirements.md))
完成后,用户继续按 Visual Studio Source Control Explorer 的日常用法试用工作台,
提出第二批功能缺口。本文档收口这批需求,作为 `task/frontend` 中 FE-019 ~ FE-024 的需求来源。
## 二、用户反馈原文与解读
### 2.1 选中文件 / 文件夹缺少「高级」能力
- 原文:选中文件和文件夹的时候,需要一个高级功能。高级功能至少有属性:显示服务器地址、本地地址。
还有获取特定版本功能,根据历史变更集,获取这个变更集的内容(相当于整体代码回滚到这个变更集提交的时候)。
- 解读:
- 「属性」对应 VS 的 Properties 面板:展示服务器路径、本地路径、映射状态、挂起状态、最新版本号等
- 「获取特定版本」对应 VS 的 Get Specific Version 对话框:不必先打开历史弹窗,
右键即可选择 / 输入 changeset,把该对象(含目录递归)的本地内容切到那个版本
- 与 FE-014 已实现的「历史弹窗 → 获取此版本」互补:那是从历史入口走,这次要求从对象右键直达,
并提供 changeset 选择器
### 2.2 缺少重命名、回滚
- 原文:缺少重命名、回滚等功能。
- 解读:
- 重命名 = TFS pendRename:产生 rename 挂起更改,签入后服务器生效
- 回滚 = TFS Rollback:把某个 changeset 的改动反做(或回滚到某 changeset 之后的全部改动反做),
产生挂起更改,由用户审查后签入,区别于 2.1 的「获取特定版本」(后者只动本地工作区不产生挂起更改)
### 2.3 缺少工作区集中管理
- 原文:缺少管理工作区的功能。一个工作区下有很多 mapping,肯定是需要一个集中管理的地方,比如删除或者修改。
- 解读:对应 VS 的 Manage Workspaces / Edit Workspace 对话框。当前 mapping 只能在目录树逐个右键
「映射 / 取消映射」,需要一个集中入口:查看 workspace 信息 + 全部 mapping 列表,支持新增、删除、修改本地路径。
### 2.4 缺少分支与合并
- 原文:缺少分支和合并的功能。
- 解读:对应 VS 的 Branch / Merge:
- 分支:把源路径在服务器上分叉出目标路径(pendBranch + 签入)
- 合并:把源分支的 changeset 合并到目标分支,冲突进入冲突处理,结果是挂起更改,审查后签入
## 三、可行性盘点(现状 → 需要补什么)
| 能力 | TFS SDK 支持 | core 现状 | server 现状 | 前端现状 | 结论 |
|---|---|---|---|---|---|
| 属性(服务器/本地路径等) | `VersionControlClient.getItem` | 路径推导已有(mapping.ts) | 缺 item 详情接口 | 缺属性弹窗 | 主要是前端 + 1 个轻量接口 |
| 获取特定版本 | `ChangesetVersionSpec` | 已有 `getVersion`(FE-014) | 已有 `/api/files/get-version` | 仅历史弹窗入口 | 纯前端(右键直达 + 版本选择器) |
| 重命名 | `Workspace.pendRename` | 缺 | 缺 | 缺 | 全链路新增 |
| 回滚 | `Workspace.rollback`(RollbackOptions) | 缺 | 缺 | 缺 | 全链路新增 |
| 工作区管理 | `Workspace.update` / 现有 mapping API | mapping 增删已有 | `GET/POST/DELETE /api/mappings` 已有 | 仅目录树右键 | 主要是前端集中管理弹窗 |
| 分支 | `Workspace.pendBranch` / `createBranch` | 缺 | 缺 | 缺 | 全链路新增 |
| 合并 | `Workspace.merge` + `getMergeCandidates`;冲突复用 `listConflicts/applyConflict` | 缺 merge | 缺 | 冲突弹窗已有 | 全链路新增,冲突流程复用 |
SDK 均为 `com.microsoft.tfs.sdk-14.0.1.jar` 已验证存在的公开方法,无协议层风险。
## 四、需求定义
### R5 对象属性与获取特定版本(FE-019,P0)
- 右键菜单新增「属性…」与「获取特定版本…」(文件与目录均有)
- 属性弹窗内容:
- 服务器路径、本地路径(未映射明确显示「未映射」)
- 对象类型(文件 / 目录)、映射状态、挂起状态
- 服务器侧最新 changeset、签入时间、签入人(来自新增 item 详情接口)
- 文件补充:大小、编码(SDK item 信息自带)
- 获取特定版本弹窗:
- changeset 输入框 + 「从历史选择…」(内嵌该对象历史列表,点选回填)
- 明确提示:会覆盖该对象本地内容(目录为递归覆盖),等价整体切到该变更集时刻
- 确认后调用既有 `/api/files/get-version`,完成后刷新目录列表与挂起更改
- server 新增 `GET /api/items/info?serverPath=`(item 详情,供属性弹窗)
### R6 重命名(FE-020,P0)
- core 新增 `rename(serverPath, newName)`:`Workspace.pendRename`,要求对象已映射
- server 新增 `POST /api/files/rename`
- 前端:
- 右键「重命名…」弹窗:输入新名称,前端校验(非空、不含 `/ \ : * ? " < > |`、与原名不同)
- 产生 rename 挂起更改:挂起面板显示「旧名 → 新名」,可 undo 撤销,checkin 后生效
- 完成后刷新目录树、列表与挂起更改
### R7 回滚(FE-021,P1)
- core 新增 `rollback(serverPath, mode, changeset)`:
- `single`:仅反做该 changeset(VS Rollback Entire Changeset)
- `toVersion`:反做该 changeset 之后的全部改动(VS Rollback to a Specific Version)
- server 新增 `POST /api/files/rollback`
- 前端:
- 历史弹窗记录行新增「回滚此变更集…」「回滚到此变更集…」(带确认弹窗,说明只产生挂起更改不会直接入库)
- 回滚产生冲突时进入既有冲突弹窗
- 完成后刷新挂起更改,由用户审查并签入
### R8 工作区与 Mapping 集中管理(FE-022,P1)
- 顶栏新增「工作区」入口,打开集中管理弹窗:
- 工作区信息:名称、Owner、Computer、服务器、Collection
- Mapping 列表:服务器路径、本地路径、本地目录是否存在
- 操作:新增(复用既有映射弹窗逻辑)、删除(确认弹窗,说明不会删除本地文件)、
修改本地路径(实现为删旧 + 加新,提示将重新获取)
- server 复用既有 `GET/POST/DELETE /api/mappings`,不强制新增接口
### R9 分支(FE-023,P1)
- core 新增 `branch(sourceServerPath, targetServerPath, changeset?)`:`pendBranch`(默认 latest,可指定 changeset)
- server 新增 `POST /api/files/branch`
- 前端:
- 右键「分支…」弹窗:默认目标 `源路径-branch`,可编辑;可选基于指定 changeset
- 产生 branch 挂起更改,审查后签入;完成后刷新目录树
- 目标路径父目录必须已映射(pendBranch 需要本地落盘),未满足时弹窗给出明确提示
### R10 合并(FE-024,P1)
- core 新增:
- `mergeCandidates(source, target)`:`getMergeCandidates`,返回待合并 changeset 列表
- `merge(source, target, changeset?)`:默认合并全部候选,可指定单个 changeset
- server 新增 `GET /api/files/merge-candidates`、`POST /api/files/merge`
- 前端:
- 右键「合并…」向导弹窗:源(当前对象)→ 目标路径(必须已映射);
展示候选 changeset 列表,支持「全部合并」或选择单个
- 冲突进入既有冲突弹窗;结果为挂起更改,审查后签入
- 完成后刷新挂起更改
### R11 访达打开与添加本地文件(FE-025,P0,第二批追加)
- 用户反馈原文:缺少右键文件或文件夹时「在访达中打开」(进入到访达的本目录);
右键文件夹或在中间区域右键时,缺少添加文件的功能(本地新增的文件加入 TFS 控制)。
- 在访达中打开:
- 文件:访达中显示并选中该文件(`shell.showItemInFolder`)
- 目录:直接进入该目录(`shell.openPath`)
- 仅 Electron 环境可用;未映射对象置灰
- 添加本地文件(修订:按用户反馈改为扫描式,不手动找文件):
- 目录右键与中间区域空白处右键提供「添加本地文件…」
- 自动对该目录执行目录对比(`POST /api/compare/folder` 递归),筛出 `localOnly`
(本地新增、服务器不存在)的文件 / 目录
- 弹窗列表勾选(默认全选,支持全选 / 清空),确认后批量
`POST /api/files/add` 产生 pendingAdd 挂起更改,完成后刷新
- 中间区域空白处右键 = 当前目录的完整右键菜单(与目录树右键一致)
## 五、优先级与排期建议
| 任务 | 内容 | 优先级 | 理由 |
|---|---|---|---|
| FE-019 | 属性 + 获取特定版本 | P0 | 用户明确点名;后端基本就绪,见效最快 |
| FE-020 | 重命名 | P0 | 日常高频操作,缺失影响基本可用性 |
| FE-021 | 回滚 | P1 | 重要但低频,依赖挂起更改/冲突链路已稳定 |
| FE-022 | 工作区管理 | P1 | 提升管理效率,API 已就绪纯前端 |
| FE-023 | 分支 | P1 | 团队工作流需要,先于合并 |
| FE-024 | 合并 | P1 | 依赖分支;冲突流程复用既有弹窗 |
## 六、不在本批范围
- Shelve / Unshelve
- Work Item 关联、Check-in Policy
- 多 Workspace 创建 / 切换 / 删除(仅展示与管理当前 Workspace 的 Mapping)
- 二进制三方合并编辑器(合并冲突仍走既有「取本地 / 取服务器」冲突弹窗)
- 移动(Move 跨目录),第一步只做同目录重命名
+127
View File
@@ -0,0 +1,127 @@
# macTFS UI 风格改版需求(macOS 现代化 / 精致化 / 动效)
## 一、背景
macTFS 功能层面已完成 FE-001 ~ FE-025,三栏工作台、弹窗体系、挂起更改与签入链路均可用。但当前 UI 是「功能优先」的默认 shadcn 风格:
- 全局使用 Roboto Slab 衬线字体,与 macOS 原生观感不符
- 登录页只有一张简单表单卡片,元素少、缺少品牌感
- 窗口使用系统默认标题栏,没有 macOS 原生质感(毛玻璃、隐藏式标题栏)
- 几乎没有过渡动效:弹窗、面板折叠、列表加载都是瞬时切换
- 明暗主题虽有 token 定义,但没有切换入口、也不跟随系统
本批需求目标:在**不改任何业务逻辑与接口**的前提下,把整体 UI 升级为「精致、现代、macOS 原生感、富动效」的风格。
> 说明:本分支(`feature/ui-macos-restyle`)做 macOS 原生风方案;姊妹分支 `feature/ui-modern-restyle` 做 Codex/CC Switch 现代工具风方案,两套并行对比。
## 二、用户诉求原文与解读
> 「我希望的 ui 风格是更精致,有 macos 风格,动效更多,登录页元素多点,反正就是希望比较现代一些。」
解读为四个方向:
| 诉求 | 落地方向 |
|---|---|
| 更精致 | 统一设计令牌(颜色/圆角/阴影/间距/图标),细化悬停、选中、禁用等状态 |
| macOS 风格 | 系统字体栈、隐藏式标题栏 + 毛玻璃、Finder 式侧栏、Sheet 式弹窗、跟随系统明暗 |
| 动效更多 | 建立统一动效规范:弹窗出入场、面板折叠、列表级联、骨架屏、微交互 |
| 登录页元素多点 | 品牌区 + 分步表单 + 背景氛围 + 最近连接 + 连接过程动效 |
## 三、现状盘点
| 现状 | 文件 | 问题 |
|---|---|---|
| 主题 token | `mactfsui/app/app.css` | 衬线字体、紫色主色、无 macOS 质感变量,dark 主题无入口 |
| Electron 窗口 | `mactfsui/electron/main.cjs` | 默认标题栏,无 vibrancy / hiddenInset |
| 登录页 | `app/components/app/connect-view.tsx` | 单卡片表单,无品牌区、无动效、无最近连接 |
| 工作台 | `app/components/app/workspace-shell.tsx`、`top-bar.tsx` | 布局可用但视觉平淡,折叠无动画 |
| 目录树 / 文件列表 | `app/components/explorer/source-tree-panel.tsx`、`folder-items-panel.tsx` | 行样式简单,加载无骨架屏,空状态简陋 |
| 弹窗(13 个) | `app/components/explorer/*-dialog.tsx`、`app/components/app/*` | 风格不一,出入场无动效 |
| 反馈 | `changes-panel.tsx`、`console-panel.tsx` | 无 toast,操作反馈靠日志面板 |
技术栈现状:React 19 + React Router 7 + Tailwind CSS 4 + radix-ui/shadcn + tw-animate-css + lucide-react + Electron 42。动效优先用 CSS / tw-animate-css,复杂编排可引入 `motion`(原 framer-motion)。
## 四、需求定义
### U1 macOS 设计基建(FE-026,P0)
- 字体切换为系统字体栈(`-apple-system, BlinkMacSystemFont, "SF Pro", "PingFang SC"…`),仅代码/Diff 保留等宽字体
- 重定义颜色令牌:macOS 蓝为主色(accentColor 风格),中性灰分级、分隔线、半透明材质变量
- 统一圆角(macOS 常用 6/10/14px 档位)、阴影(弹窗/浮层分层阴影)、间距档位
- 建立动效令牌:统一时长(150/220/320ms)、缓动曲线(ease-out-quart、spring 近似)
- 完整 light/dark 两套 token,预留 vibrancy 透明背景变量
### U2 Electron 窗口 macOS 化(FE-027,P0)
- `titleBarStyle: "hiddenInset"`,红绿灯融入顶栏,顶栏设置可拖拽区域
- 开启窗口 vibrancy(`under-window` 或 `sidebar` 材质),侧栏呈毛玻璃
- 窗口最小尺寸、默认尺寸与圆角阴影核对
- 兼容退化:非 macOS 或 vibrancy 不可用时回退为纯色背景
### U3 登录页改版(FE-028,P0)
- 左右分栏:左侧品牌区(logo、产品名、标语、版本号、氛围背景动效),右侧连接表单
- 表单分步过渡动效:连接表单 → Collection 选择,左右滑动 + 淡入淡出
- 新增元素:密码可见性切换、记住最近服务器(本地存储多条,可一键填充)、连接状态指示灯、服务健康状态展示
- 连接中动效:按钮内 spinner + 步骤文案渐变;失败时表单抖动 + 错误条
- Collection 选择改为卡片式列表,悬停浮起、选中高亮动画
### U4 工作台外壳与顶栏改版(FE-029,P0)
- 顶栏融合红绿灯区域,按 macOS 工具栏风格重排(上下文信息居左、动作按钮居右、图标化)
- 左侧目录树面板改 Finder 式侧栏:毛玻璃背景、分组标题、圆角选中条
- 三栏折叠/展开增加宽度过渡动画,底部操作台滑入滑出
- 面板间分隔线与留白统一
### U5 目录树与文件列表精致化(FE-030,P0)
- 树节点与文件行:统一行高、圆角悬停/选中态、展开箭头旋转动画、子级展开渐入
- 文件图标体系:按扩展名区分图标与颜色,文件夹/分支/映射目录差异化
- 加载骨架屏替代文字 loading;空状态配插图式占位(图标 + 引导文案)
- 状态徽标(pendingEdit/Add/Delete、未下载等)配色与形状统一
### U6 弹窗体系统一(FE-031,P1)
- 13 个弹窗统一为 macOS Sheet 风格:顶部标题区、内容区、底部按钮区结构一致
- 出入场动效统一:缩放 + 淡入(spring 曲线),遮罩淡入
- 弹窗内表格、表单控件按新 token 对齐;大弹窗(History/Compare/Diff)支持更合理的留白与分区
### U7 操作反馈与微交互(FE-032,P1)
- 引入轻量 toast(成功/失败/进行中),与日志面板互补
- 挂起更改面板、日志面板按新风格改版;新日志条目滑入动画
- 按钮、复选框、输入框等控件微交互:按压缩放、聚焦光环、hover 过渡
- 长操作(GetLatest、Checkin、目录对比)显示进度反馈动效
### U8 明暗主题跟随系统(FE-033,P1)
- 跟随 macOS 系统外观自动切换 light/dark,顶栏提供手动三态开关(跟随/亮/暗)
- 切换瞬间全局颜色过渡动画
- 校验全部面板与弹窗在 dark 下的对比度与可读性
### U9 改版回归验收(FE-034,P0)
- 改版完成后按 `TFS-AI测试流程.md` 大纲做 UI 链路回归:登录、浏览、Mapping、GetLatest、签出签入、历史、Diff、目录对比
- 确认零业务逻辑变化:`app/lib` 与接口契约不动
- typecheck 通过、关键页面截图存档
## 五、优先级与排期建议
| 顺序 | 任务 | 优先级 | 依赖 |
|---|---|---|---|
| 1 | FE-026 设计基建 | P0 | 无 |
| 2 | FE-027 窗口 macOS 化 | P0 | FE-026 |
| 3 | FE-028 登录页改版 | P0 | FE-026 |
| 4 | FE-029 工作台外壳改版 | P0 | FE-026、FE-027 |
| 5 | FE-030 目录树与文件列表 | P0 | FE-029 |
| 6 | FE-031 弹窗体系统一 | P1 | FE-026 |
| 7 | FE-032 反馈与微交互 | P1 | FE-026 |
| 8 | FE-033 明暗主题 | P1 | FE-026 ~ FE-032 |
| 9 | FE-034 回归验收 | P0 | 全部 |
## 六、不在本批范围
- 任何业务逻辑、接口契约、服务端代码改动
- 新功能(本批只做视觉与交互层)
- Windows / Linux 适配(仅保证不崩溃的回退样式)
- Monaco Diff 内部主题深度定制(仅跟随明暗主题切换)
Binary file not shown.

After

Width:  |  Height:  |  Size: 120 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 314 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 252 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 325 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 167 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 378 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 289 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 278 KiB

+255
View File
@@ -0,0 +1,255 @@
# macTFS 打包构建 & MCP 使用配置指南
本文分两大块:
1. **打包构建**:怎么把整个项目从源码构建成可分发的 macOS 桌面应用(`.app` / `.dmg`)。
2. **MCP 工具**:`mactfs-mcp` 能做什么、怎么在 AI 客户端(Cursor / Claude 等)里配置使用。
> 日常「启动 / 停止 / 重启」服务的操作见根目录 [`服务启停指南.md`](../服务启停指南.md),本文不重复。
---
## 一、项目组成与端口
运行态由三个进程组成,全部只监听本机(`127.0.0.1`):
| 进程 | 是什么 | 监听 |
|---|---|---|
| Java 后端 | `com.mydev.mactfs.server.MacTfsServer`,复用微软 TFS SDK 与 TFS 通信 | `127.0.0.1:38765` |
| Electron 前端 | 桌面界面(开发态由 vite 提供页面 `localhost:5173`) | 窗口 |
| mactfs-mcp | 给 AI 客户端用的 SSE 服务(改文件前自动签出) | `127.0.0.1:38766/sse` |
**进程关系(重点)**:
```
Electron 客户端(你启动的)
├─ 自动拉起 Java 后端 127.0.0.1:38765
└─ 自动拉起 mactfs-mcp 127.0.0.1:38766/sse
退出 Electron → 两个子进程一并回收(孤儿进程会被「父死自杀」看护清掉)
```
- 后端 / MCP 都由 Electron 按需拉起、随之退出,所以**日常只需启动前端**。
- MCP 还会看护父进程 PID,Electron 异常退出时自杀;崩溃后 Electron 会自动重拉(2 秒后)。
- 登录 token 存在 `~/.mactfs/server-token`,三个进程共用同一份。
---
## 二、环境要求
- macOS 12+(Intel 或 Apple Silicon;Apple Silicon 需装 Rosetta 2)
- [pnpm](https://pnpm.io/)(前端 / MCP 包管理)
- Node ≥ 18(开发 MCP 用)
- 首次构建需联网(自动从 Azul 下载 x64 JDK)
- 目标 TFS:TFS 2015 及以下(TFVC)
> ⚠️ **为什么固定 x64 JDK**:TFS SDK 的 JNI 原生库只含 i386/x86_64,没有 arm64 切片。所以服务端 JVM 固定走 x64,在 Apple Silicon 上经 Rosetta 2 运行;Electron 界面本身仍是原生 universal。
---
## 三、从零打包成桌面应用(.app / .dmg)
下面是一套**完整顺序**,第一次构建建议逐步执行;之后只改了某一层就只重跑对应步骤。
### 步骤 1 · 安装前端依赖
```bash
cd mactfsui
pnpm install
```
### 步骤 2 · 准备 x64 JDK(打包用运行时)
```bash
cd mactfsui
pnpm prepare:runtime
```
脚本逻辑(`scripts/prepare-runtime.mjs`):
- 检测仓库根是否已有 `zulu8.94.0.17-ca-jdk8.0.492-macosx_x64/`;没有就从 Azul 官方下载 → 校验 sha256 → 解压到仓库根目录。
- 再把精简后的运行时复制到 `mactfsui/runtime/jdk-x64`(去掉 `src.zip`、`demo`、`man` 等无用部分缩小体积)。
- 打包时这个 `runtime/jdk-x64` 会被复制进 `.app` 的 `Resources/jre-x64`。
> `pnpm dist` 会自动先跑这一步,所以你也可以跳过手动执行;单独跑只是为了提前下载/排错。
### 步骤 3 · 构建 Java 后端
```bash
cd mactfs
../tfsIntegration/gradlew installDist
```
- 产物落在 `mactfs/build/install/mactfs/lib/`(含全部依赖 jar 与 `native/` JNI 库)。
- 打包时这个目录会被复制进 `.app` 的 `Resources/server/lib`。
- **改了 Java 代码必须重新 `installDist`**,只跑 `gradlew build` 不更新这个运行目录。
### 步骤 4 · 构建 MCP
```bash
cd mactfs-mcp
pnpm install
pnpm build # 开发态:tsc 编译,产物在 dist/
pnpm build:bundle # 打包态:esbuild 单文件,产物在 dist-bundle/index.cjs
```
- 开发态 Electron 从 `mactfs-mcp/dist/index.js` 拉起 MCP,所以**改完 MCP 代码必须重新 `pnpm build`**。
- 打包态用 esbuild 单文件 `dist-bundle/index.cjs`(免带 node_modules);`pnpm dist` 已通过 `prepare:mcp` 自动生成它,无需手动跑。
### 步骤 5 · 打包
```bash
cd mactfsui
pnpm dist
```
`pnpm dist` 等价于:`pnpm build`(打包前端页面)→ `pnpm prepare:runtime`(准备 JDK)→ `electron-builder --mac --arm64 --x64`。
**产物输出**:`mactfsui/dist-app/`,生成 arm64 与 x64 两个 DMG:
| 安装包 | 适用机型 |
|---|---|
| `MacTFS-<版本>-arm64.dmg` | Apple Silicon(M 系列) |
| `MacTFS-<版本>-x64.dmg` | Intel |
打包配置见 `mactfsui/package.json` 的 `build` 字段:`appId=com.mydev.mactfs`,`extraResources` 把后端 lib、x64 JRE 与 **MCP 单文件包** 带进 `Resources/`,`identity: null`(不签名)。
### MCP 已随 .app 一起打包
`extraResources` 现包含三项,分别落到 `.app/Contents/Resources/` 下:
| from | to | 内容 |
|---|---|---|
| `../mactfs/build/install/mactfs/lib` | `server/lib` | Java 后端 jar + JNI native |
| `runtime/jdk-x64` | `jre-x64` | x64 JRE |
| `../mactfs-mcp/dist-bundle` | `mcp` | MCP esbuild 单文件 `index.cjs` |
启动时 `resolveMcpEntry()` 打包态命中 `Resources/mcp/index.cjs`,由 Electron 自带 Node 拉起。所以**正式 .app 也自带 MCP**,AI 自动签出在安装版里同样可用(前提是客户端在运行)。
---
## 四、开发模式运行(推荐日常使用)
```bash
cd mactfsui
pnpm electron:dev
```
一条命令同时拉起 vite(`localhost:5173`)+ Electron 窗口,Electron 再按需自动拉起后端与 MCP。
前置:首次需先跑过 **步骤 3(`installDist`)** 和 **步骤 4(MCP `pnpm build`)**,否则后端 / MCP 起不来。
---
## 五、mactfs-mcp 工具:能做什么 & 怎么用
### 5.1 它是什么
一个 SSE(`http://127.0.0.1:38766/sse`)小服务,让支持 MCP 的 AI 客户端在**改 TFS 受控文件之前自动签出**。它自己不直接连 TFS,而是把请求转成调本机 Java 后端的 REST 接口,由后端经微软 SDK 操作 TFS。
```
AI 客户端 ──SSE──▶ mactfs-mcp ──HTTP(REST+Token)──▶ Java 后端(38765) ──▶ TFS
```
> 前提:MacTFS 桌面客户端正在运行(否则 38766 端口不存在,AI 连接会被拒)——这就是「客户端开着才能用」的天然绑定。
### 5.2 在 Cursor 中配置
**默认无需 token**,配置里只写一个 URL 即可(MCP 调后端用的 token 会自动从 `~/.mactfs/server-token` 读取):
```json
{
"mcpServers": {
"mactfs": { "url": "http://127.0.0.1:38766/sse" }
}
}
```
### 5.3 两个工具
#### `tfs_checkout` — 签出(改已有文件前用)
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| `paths` | `string[]` | 必填 | 文件本地绝对路径(也兼容 `$/` 服务端路径) |
| `dryRun` | `boolean?` | false | 只校验、不真正签出/加入/拉最新 |
| `getLatestIfStale` | `boolean?` | **true** | 本地落后时自动先获取最新再签出;传 `false` 则仅警告 |
| `autoAdd` | `boolean?` | **true** | 遇到服务端尚不存在的新文件时自动加入版本控制;传 `false` 则仅提示改用 `tfs_add` |
执行前校验流水线:连接 → 是否映射 → 是否已签出 → 是否新文件 → 是否未下载 → 是否落后 → 签出。
**默认行为(已内置)**:
- 新文件 → **自动 `add` 加入版本控制**(除非 `autoAdd=false`)。
- 本地落后 → **自动先 `get-latest` 再签出**(除非 `getLatestIfStale=false`)。
- `dryRun=true` 时只报告「会怎么做」,**不会**真的 add / 拉最新(无副作用)。
#### `tfs_add` — 加入版本控制(新建文件用)
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| `paths` | `string[]` | 必填 | 要加入版本控制的文件本地绝对路径 |
| `dryRun` | `boolean?` | false | 只校验、不真正加入 |
每个路径都会返回结构化结果,`action` 取值:`checkedOut / alreadyCheckedOut / added / alreadyAdded / skipped / error`,并附一段人话 `message`。
### 5.4 可选:开启更严格的本机鉴权
默认靠「仅监听 127.0.0.1 + 随客户端绑定」两道保护,AI 端不用带 token。若想防止同机其它程序连本 MCP,给 MCP 进程设 `MACTFS_MCP_REQUIRE_TOKEN=1`,再在配置里带上 token:
```json
{
"mcpServers": {
"mactfs": {
"url": "http://127.0.0.1:38766/sse",
"headers": { "Authorization": "Bearer 这里粘贴 server-token 内容" }
}
}
}
```
也可用查询参数:`"url": "http://127.0.0.1:38766/sse?token=server-token内容"`。
### 5.5 环境变量
| 变量 | 默认 | 说明 |
|---|---|---|
| `MACTFS_API_BASE_URL` | `http://127.0.0.1:38765` | Java 后端地址 |
| `MACTFS_MCP_HOST` / `MACTFS_MCP_PORT` | `127.0.0.1` / `38766` | SSE 监听地址 |
| `MACTFS_TOKEN_FILE` | `~/.mactfs/server-token` | Bearer Token 文件(自动读取) |
| `MACTFS_MCP_REQUIRE_TOKEN` | 关 | 设 `1` 时要求 AI 客户端连接也带 token |
| `MACTFS_PARENT_PID` | 无 | 父进程 pid,设置后启用「父死则自杀」 |
| `MACTFS_MCP_HEALTH_TRIES` / `_INTERVAL_MS` | `60` / `1000` | 启动时等待后端就绪的轮询次数 / 间隔 |
| `MACTFS_MCP_HTTP_TIMEOUT_MS` | `30000` | 调 Java 后端的 HTTP 超时 |
> Electron 自动拉起 MCP 时,会注入 `MACTFS_PARENT_PID`、`MACTFS_API_BASE_URL`、`MACTFS_TOKEN_FILE`、`MACTFS_MCP_PORT`。
---
## 六、验证与排错
### 验证后端
```bash
TOKEN=$(cat ~/.mactfs/server-token)
curl -s -H "Authorization: Bearer $TOKEN" http://127.0.0.1:38765/api/health
# 返回 "success":true 即正常
```
### 验证 MCP
```bash
curl -s http://127.0.0.1:38766/healthz
# 返回 {"ok":true,"name":"mactfs-mcp",...} 即在跑
```
### 常见问题
| 现象 | 原因与处理 |
|---|---|
| MCP 端口 38766 连不上 | MacTFS 客户端没开,或开发态没先 `pnpm build` 过 MCP |
| 改了 MCP 代码不生效 | 忘了在 `mactfs-mcp` 重新 `pnpm build`(Electron 加载的是 `dist/`) |
| 改了 Java 代码不生效 | 忘了 `gradlew installDist` 或没重启后端 |
| 打包后的 .app 里 MCP 不工作 | 确认打包前生成了 `mactfs-mcp/dist-bundle/index.cjs`(`pnpm dist` 会自动跑 `prepare:mcp`) |
| 工具返回 `skipped / notMapped` | 文件不在任何 TFS 映射目录下,本就无需签出,可直接继续 |
| 工具返回 `notConnected` | 后端 38765 没起来,确认 MacTFS 客户端在运行 |
| 接口全部 401 | token 不一致,确认用的是 `~/.mactfs/server-token` 的最新值 |
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

+4
View File
@@ -0,0 +1,4 @@
node_modules/
dist/
dist-bundle/
*.log
+213
View File
@@ -0,0 +1,213 @@
# mactfs-mcp
让任意支持 MCP 的 AI 客户端(Cursor / Claude / Codex 等)在**修改受 TFS 版本控制的文件之前自动校验并签出**。
本服务暴露 `tfs_checkout`、`tfs_add` 两个工具,背后调用 MacTFS 本地 Java 服务(`127.0.0.1:38765`)完成实际签出(TFVC pendEdit)/ 加入(pendAdd)。
## 两种接入模式
| 模式 | 启动方式 | 适用客户端 | 说明 |
|---|---|---|---|
| **SSE**(默认) | 由 MacTFS 桌面客户端拉起,监听 `127.0.0.1:38766/sse` | **Cursor**(支持填 URL) | 随客户端启停,端口存在才能连 |
| **stdio** | `mactfs-mcp --mcp-stdio`(由 AI 客户端以子进程拉起) | **Codex / Claude 等**(只认「启动一个命令」) | 不占 38766 端口,直连 38765 Java 后端;后端没起时工具返回 notConnected |
> 为什么要两种:Cursor 天生支持「填个网址就连」(SSE),而 Codex / Claude 的配置默认是「给我一个能启动的程序」(stdio),没法直接贴 SSE 地址。stdio 模式就是为后者准备的通用入口。
## 与客户端绑定
本 MCP **由 MacTFS 桌面客户端(Electron)拉起、随客户端退出而回收**:
```
Electron 客户端(运行中)
├─ Java 后端 127.0.0.1:38765
└─ mactfs-mcp 127.0.0.1:38766/sse ← AI 客户端用 URL 连接
└─ HTTP → Java 后端 → TFS
退出客户端 → 两个子进程都被回收 → AI 连接被拒(天然绑定)
```
- 只有客户端开着,`38766` 端口才存在,AI 才能用。
- MCP 还会看护父进程(`MACTFS_PARENT_PID`),客户端异常退出时自杀,避免孤儿进程。
## 工具:`tfs_checkout`
在编辑受 TFS 管控的已有文件前调用。
入参:
| 参数 | 类型 | 说明 |
|---|---|---|
| `paths` | `string[]` | 文件本地绝对路径(也兼容 `$/` 服务端路径) |
| `dryRun` | `boolean?` | 只做执行前校验、不真正签出 |
| `getLatestIfStale` | `boolean?` | 本地落后于服务器时自动先获取最新再签出(默认 false,仅警告) |
执行前校验流水线:连接 → 是否映射 → 是否已签出 → 是否新文件 → 是否未下载 → 是否落后 → 签出。
每个路径返回结构化结果,`action` 为 `checkedOut | alreadyCheckedOut | skipped | error`,并附人话 `message`。
## 在 Cursor 中配置
**默认无需 token**,配置里只写一个 URL 即可(MCP 调后端用的 token 会自动从 `~/.mactfs/server-token` 读取,AI 端不用管):
```json
{
"mcpServers": {
"mactfs": { "url": "http://127.0.0.1:38766/sse" }
}
}
```
> 前提:MacTFS 桌面客户端正在运行(否则 38766 端口不存在,连接会被拒)——这就是「客户端开着才能用」的绑定。
### 可选:开启更严格的本机鉴权
如果想防止同机其它程序连本 MCP,给 MCP 进程设环境变量 `MACTFS_MCP_REQUIRE_TOKEN=1`,再在配置里带上 token:
```json
{
"mcpServers": {
"mactfs": {
"url": "http://127.0.0.1:38766/sse",
"headers": { "Authorization": "Bearer 这里粘贴server-token内容" }
}
}
}
```
也可用查询参数:`"url": "http://127.0.0.1:38766/sse?token=server-token内容"`。
## 在 Codex / Claude 中配置(stdio 模式)
Cursor 支持「填个 URL 直接连」(SSE),而 **Codex / Claude 的配置是「给我一个能启动的命令」**(stdio),没法直接贴 SSE 地址。
为此本 MCP 增加了 `--mcp-stdio` 模式:启动后**不监听 38766 端口、不起 SSE**,直接通过 stdin/stdout 与 AI 客户端通信,背后仍调用 38765 Java 后端。
### 前提(务必先确认)
1. **MacTFS 桌面客户端正在运行**(Java 后端 38765 在跑)。后端没起时工具不会报错崩溃,只会返回 `notConnected`,等后端起来即可正常用。
2. **本机装了 Node 18+**(`node -v` 能输出版本)。stdio 进程由 AI 客户端拉起,需要一个 Node 运行时来跑那个单文件。
- 不想另装 Node?见文末「免装 Node:复用 app 自带 Electron」。
### 第 1 步:确定入口文件的绝对路径
入口就是 esbuild 打出的单文件 `index.cjs`,两种来源任选其一:
| 场景 | 绝对路径(示例,按你机器实际替换) |
|---|---|
| **已安装 app**(推荐) | `/Applications/MacTFS.app/Contents/Resources/mcp/index.cjs` |
| **本仓库开发态** | `/Users/你的用户名/.../mydev/mactfs-mcp/dist-bundle/index.cjs` |
> 开发态若还没生成单文件,先在 `mactfs-mcp/` 下执行 `pnpm build:bundle`(产物在 `dist-bundle/index.cjs`)。
> 也可以直接用 tsc 产物 `dist/index.js`(同样加 `--mcp-stdio`),效果一致。
### 第 2 步:按客户端写配置(把路径换成你的真实路径)
**Codex CLI**(`~/.codex/config.toml`):
```toml
[mcp_servers.mactfs]
command = "node"
args = ["/Applications/MacTFS.app/Contents/Resources/mcp/index.cjs", "--mcp-stdio"]
```
**Claude Desktop**(`~/Library/Application Support/Claude/claude_desktop_config.json`):
```json
{
"mcpServers": {
"mactfs": {
"command": "node",
"args": ["/Applications/MacTFS.app/Contents/Resources/mcp/index.cjs", "--mcp-stdio"]
}
}
}
```
**Claude Code**(命令行,一条搞定):
```bash
claude mcp add mactfs -- node /Applications/MacTFS.app/Contents/Resources/mcp/index.cjs --mcp-stdio
```
> 改完配置后**重启对应客户端**(Codex 重开会话 / Claude 退出重进),让它重新读取配置并拉起 MCP。
### 第 3 步:验证是否生效
- Codex / Claude 的工具列表里应能看到 `tfs_checkout`、`tfs_add` 两个工具。
- 想在命令行先自测,可临时手动跑:
```bash
node /Applications/MacTFS.app/Contents/Resources/mcp/index.cjs --mcp-stdio
# 正常会在 stderr 打印:[mactfs-mcp] stdio transport connected
# 然后阻塞等待 stdin 的 JSON-RPC(Ctrl+C 退出即可)
```
### 可选 A:免装 Node —— 复用 app 自带的 Electron 当 Node
安装包里已经带了 Electron,可让它「以 Node 模式」运行,无需另装 Node:
```json
{
"mcpServers": {
"mactfs": {
"command": "/Applications/MacTFS.app/Contents/MacOS/MacTFS",
"args": ["/Applications/MacTFS.app/Contents/Resources/mcp/index.cjs", "--mcp-stdio"],
"env": { "ELECTRON_RUN_AS_NODE": "1" }
}
}
}
```
`ELECTRON_RUN_AS_NODE=1` 让这个 app 二进制不弹窗、纯当 Node 跑脚本。这样**所有路径都在安装包内部,零外部依赖**。
### 可选 B:不另起进程,桥接现成的 SSE 服务
如果只是想复用 app 已经在跑的 SSE(38766),不想再由客户端拉起 stdio 进程,Claude 侧可用桥接:
```bash
npx -y mcp-remote http://127.0.0.1:38766/sse
```
把它作为客户端的 `command`,即可把 SSE 转成 stdio。
### 几点说明(不是问题,但要知道)
- **生命周期**:stdio 进程由 AI 客户端启停,不再随 MacTFS app 开关绑定。但真正干活的是 38765 Java 后端 —— app 没开时工具只返回 `notConnected`,不会误操作,安全。
- **多客户端不冲突**:stdio 模式**不占 38766 端口**,Cursor 的 SSE 与 Codex/Claude 的多个 stdio 进程可同时存在,各自连同一个 38765 后端,互不干扰。
- **鉴权**:stdio 是本机父子进程直连,无需 token;`MACTFS_MCP_REQUIRE_TOKEN` 只对 SSE 连接生效。
## 环境变量
| 变量 | 默认 | 说明 |
|---|---|---|
| `MACTFS_API_BASE_URL` | `http://127.0.0.1:38765` | Java 后端地址 |
| `MACTFS_MCP_HOST` / `MACTFS_MCP_PORT` | `127.0.0.1` / `38766` | SSE 监听地址 |
| `MACTFS_TOKEN_FILE` | `~/.mactfs/server-token` | Bearer Token 文件(MCP 调后端用,自动读取) |
| `MACTFS_MCP_REQUIRE_TOKEN` | 关 | 设 `1` 时要求 AI 客户端连接也带 token |
| `MACTFS_PARENT_PID` | 无 | 父进程 pid,设置后启用「父死则自杀」 |
| `MACTFS_MCP_HEALTH_TRIES` / `_INTERVAL_MS` | `60` / `1000` | 启动时等待后端就绪的轮询 |
## 开发
```bash
pnpm install
pnpm build # 产物在 dist/
pnpm dev # tsx watch 热更新
pnpm typecheck
```
Electron 开发态会自动从 `mactfs-mcp/dist/index.js` 拉起本服务,所以改完记得 `pnpm build`。
## 打包进 .app
打包态用 **esbuild 把整个 MCP 打成单文件**(免带 node_modules),再随 electron-builder 落到 `Resources/mcp/index.cjs`:
```bash
pnpm build:bundle # 产物 dist-bundle/index.cjs(单文件 CJS)
```
`mactfsui` 侧已接好:
- `package.json` 的 `extraResources` 增加 `{ from: "../mactfs-mcp/dist-bundle", to: "mcp" }`,把单文件包复制进 `Resources/mcp/`。
- `pnpm dist` 链路里加了 `prepare:mcp`(自动 `pnpm install` + `build:bundle`),打包前会自动生成最新单文件包。
- Electron 主进程 `resolveMcpEntry()` 打包态命中 `Resources/mcp/index.cjs`,用 Electron 自带 Node(`ELECTRON_RUN_AS_NODE`)拉起。
> 打包态用 `.cjs`(CJS),开发态仍用 `dist/index.js`(tsc 的 ESM 产物 + node_modules),两条路径互不影响。
+34
View File
@@ -0,0 +1,34 @@
{
"name": "mactfs-mcp",
"version": "0.1.0",
"private": true,
"description": "MacTFS MCP 服务:让任意 AI 客户端在改文件前自动校验并签出 TFS 文件。与 MacTFS 桌面客户端绑定运行。",
"type": "module",
"bin": {
"mactfs-mcp": "dist/index.js"
},
"main": "dist/index.js",
"scripts": {
"build": "tsc -p tsconfig.json",
"build:bundle": "esbuild src/index.ts --bundle --platform=node --format=cjs --target=node18 --outfile=dist-bundle/index.cjs",
"dev": "tsx watch src/index.ts",
"start": "node dist/index.js",
"start:bundle": "node dist-bundle/index.cjs",
"typecheck": "tsc -p tsconfig.json --noEmit"
},
"dependencies": {
"@modelcontextprotocol/sdk": "^1.20.0",
"express": "^4.21.2",
"zod": "^3.25.0"
},
"devDependencies": {
"@types/express": "^5.0.0",
"@types/node": "^22.10.0",
"esbuild": "^0.28.1",
"tsx": "^4.19.2",
"typescript": "^5.9.3"
},
"engines": {
"node": ">=18"
}
}
+1428
View File
File diff suppressed because it is too large Load Diff
+13
View File
@@ -0,0 +1,13 @@
import { Client } from "@modelcontextprotocol/sdk/client/index.js"
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js"
const transport = new SSEClientTransport(new URL("http://127.0.0.1:38766/sse"))
const client = new Client({ name: "probe", version: "1.0.0" })
await client.connect(transport)
const tools = await client.listTools()
console.log("TOOLS:", tools.tools.map((t) => t.name).join(", "))
for (const t of tools.tools) {
console.log("-", t.name, "::", JSON.stringify(Object.keys(t.inputSchema?.properties ?? {})))
}
await client.close()
process.exit(0)
+269
View File
@@ -0,0 +1,269 @@
import path from "node:path"
import { tfsClient } from "./tfs-client.js"
import type {
FileStatus,
PendAction,
PendItemResult,
PendReason,
} from "./types.js"
export interface PendOptions {
dryRun?: boolean
/** 本地落后于服务器时是否先自动获取最新再签出。默认 true,传 false 才退回仅警告。 */
getLatestIfStale?: boolean
/** 遇到服务端尚不存在的新文件时是否自动加入版本控制(add)。默认 true,传 false 才退回仅提示。 */
autoAdd?: boolean
}
/**
* 组装单条结果,缺省字段从已知的 FileStatus 回填。
*/
function item(
filePath: string,
serverPath: string | null,
action: PendAction,
reason: PendReason,
message: string,
status?: FileStatus,
): PendItemResult {
return {
path: filePath,
serverPath: serverPath ?? status?.serverPath ?? null,
action,
reason,
mapped: status?.mapped ?? false,
pendingEdit: status?.pendingEdit ?? false,
localVersion: status?.localVersion ?? 0,
latestVersion: status?.latestVersion ?? 0,
upToDate: status?.upToDate ?? false,
message,
}
}
/**
* 连接预检:返回 null 表示后端可用,否则返回给所有路径的统一失败结果。
*/
async function connectionGuard(paths: string[]): Promise<PendItemResult[] | null> {
const health = await tfsClient.health()
if (health.ok) {
return null
}
return paths.map((p) =>
item(
p,
null,
"error",
"notConnected",
`连不上本地 MacTFS 服务(${health.errorMessage ?? "服务未运行"})。请确认 MacTFS 客户端已打开。`,
),
)
}
/** 读取单个本地文件状态,失败时返回 null(调用方据此产出 error 结果)。 */
async function loadStatus(localPath: string): Promise<FileStatus | { error: string }> {
const resp = await tfsClient.fileStatus(localPath)
if (!resp.ok || !resp.data || !resp.data.status) {
return { error: resp.errorMessage ?? "未知错误" }
}
return resp.data.status
}
/**
* 真正执行签出(pendEdit)。checkoutArg 可为本地绝对路径或服务端路径。
*/
async function doCheckout(
checkoutArg: string,
serverPath: string | null,
status?: FileStatus,
): Promise<PendItemResult> {
const resp = await tfsClient.checkout([checkoutArg], false)
if (!resp.ok || !resp.data) {
return item(checkoutArg, serverPath, "error", "error", `签出失败:${resp.errorMessage ?? "未知错误"}`, status)
}
const result = resp.data.result
if (result.failures && result.failures.length > 0) {
return item(checkoutArg, serverPath, "error", "error", `签出未成功:${result.failures.join(";")}`, status)
}
return item(checkoutArg, serverPath, "checkedOut", "ok", `已签出(影响 ${result.affected} 项),可以开始修改。`, status)
}
/**
* 真正执行加入版本控制(pendAdd),只接受本地路径。
*/
async function doAdd(localPath: string, status: FileStatus): Promise<PendItemResult> {
const resp = await tfsClient.add([localPath], false)
if (!resp.ok || !resp.data) {
return item(localPath, status.serverPath, "error", "error", `加入版本控制失败:${resp.errorMessage ?? "未知错误"}`, status)
}
const result = resp.data.result
if (result.failures && result.failures.length > 0) {
return item(localPath, status.serverPath, "error", "error", `加入未成功:${result.failures.join(";")}`, status)
}
return item(localPath, status.serverPath, "added", "ok", `已加入版本控制(影响 ${result.affected} 项),签入后服务器生效。`, status)
}
/**
* 对单个路径跑「签出」校验流水线:
* 映射 → 已签出 → 新文件 → 未下载 → 是否落后 → 真正签出。
*/
async function checkoutOne(raw: string, options: PendOptions): Promise<PendItemResult> {
if (raw.startsWith("$/")) {
if (options.dryRun) {
return item(raw, raw, "skipped", "ok", "服务端路径,dryRun 跳过实际签出。")
}
return doCheckout(raw, raw)
}
const localPath = path.resolve(raw)
const status = await loadStatus(localPath)
if ("error" in status) {
return item(localPath, null, "error", "error", `查询文件状态失败:${status.error}`)
}
if (!status.mapped) {
return item(localPath, status.serverPath, "skipped", "notMapped", "该文件不在任何 TFS 映射目录下,无需签出。", status)
}
if (status.pendingEdit) {
return item(localPath, status.serverPath, "alreadyCheckedOut", "ok", "文件已处于签出状态,可直接修改。", status)
}
if (!status.serverExists) {
if (options.autoAdd === false) {
return item(localPath, status.serverPath, "skipped", "newFileNeedsAdd", "这是服务端尚不存在的新文件,请改用 tfs_add 加入版本控制。", status)
}
if (!status.exists) {
return item(localPath, status.serverPath, "skipped", "notExist", "这是新文件但本地不存在;请先创建文件再加入版本控制。", status)
}
if (status.pendingChangeType === "pendingAdd") {
return item(localPath, status.serverPath, "alreadyAdded", "ok", "文件已挂起新增,无需重复加入。", status)
}
if (options.dryRun) {
return item(localPath, status.serverPath, "skipped", "ok", "校验通过:这是新文件,将自动加入版本控制(dryRun 未真正执行)。", status)
}
return doAdd(localPath, status)
}
if (!status.exists || status.status === "notDownloaded") {
return item(localPath, status.serverPath, "skipped", "notDownloaded", "本地尚未下载该文件,请先获取最新。", status)
}
const stale = !status.upToDate || status.status === "remoteChanged" || status.status === "bothChanged"
const autoGetLatest = options.getLatestIfStale !== false
if (stale && !autoGetLatest) {
return item(
localPath,
status.serverPath,
"skipped",
"stale",
`本地版本(${status.localVersion})落后于服务器最新(${status.latestVersion})。已按 getLatestIfStale=false 跳过;若要在旧版本上修改请自行处理。`,
status,
)
}
if (stale) {
if (options.dryRun) {
return item(
localPath,
status.serverPath,
"skipped",
"ok",
`校验通过:本地落后(${status.localVersion}→${status.latestVersion}),将先自动获取最新再签出(dryRun 未真正执行)。`,
status,
)
}
const gl = await tfsClient.getLatest(status.serverPath ?? undefined, false)
if (!gl.ok) {
return item(localPath, status.serverPath, "error", "stale", `自动获取最新失败:${gl.errorMessage ?? "未知错误"}`, status)
}
}
if (options.dryRun) {
return item(localPath, status.serverPath, "skipped", "ok", "校验通过:可签出(dryRun 未真正执行)。", status)
}
return doCheckout(localPath, status.serverPath, status)
}
/**
* 对单个路径跑「加入版本控制」校验流水线:
* 映射 → 本地存在 → 已加入 → 是否已受控(应改签出) → 真正 add。
*/
async function addOne(raw: string, options: PendOptions): Promise<PendItemResult> {
const localPath = path.resolve(raw)
const status = await loadStatus(localPath)
if ("error" in status) {
return item(localPath, null, "error", "error", `查询文件状态失败:${status.error}`)
}
if (!status.mapped) {
return item(localPath, status.serverPath, "skipped", "notMapped", "该文件不在任何 TFS 映射目录下,无法加入版本控制。", status)
}
if (!status.exists) {
return item(localPath, status.serverPath, "skipped", "notExist", "本地文件不存在;请先创建文件再加入版本控制。", status)
}
if (status.pendingChangeType === "pendingAdd") {
return item(localPath, status.serverPath, "alreadyAdded", "ok", "文件已挂起新增,无需重复加入。", status)
}
if (status.serverExists) {
return item(localPath, status.serverPath, "skipped", "alreadyTracked", "该文件已在版本控制中;若要修改请用 tfs_checkout 签出,而非加入。", status)
}
if (options.dryRun) {
return item(localPath, status.serverPath, "skipped", "ok", "校验通过:可加入版本控制(dryRun 未真正执行)。", status)
}
return doAdd(localPath, status)
}
/**
* tfs_checkout 主流程。
*/
export async function runCheckout(rawPaths: string[], options: PendOptions): Promise<PendItemResult[]> {
const paths = rawPaths.map((p) => p.trim()).filter((p) => p.length > 0)
if (paths.length === 0) {
return []
}
const guard = await connectionGuard(paths)
if (guard) {
return guard
}
const results: PendItemResult[] = []
for (const raw of paths) {
results.push(await checkoutOne(raw, options))
}
return results
}
/**
* tfs_add 主流程。
*/
export async function runAdd(rawPaths: string[], options: PendOptions): Promise<PendItemResult[]> {
const paths = rawPaths.map((p) => p.trim()).filter((p) => p.length > 0)
if (paths.length === 0) {
return []
}
const guard = await connectionGuard(paths)
if (guard) {
return guard
}
const results: PendItemResult[] = []
for (const raw of paths) {
results.push(await addOne(raw, options))
}
return results
}
const ACTION_TAGS: Record<PendAction, string> = {
checkedOut: "✓ 已签出",
alreadyCheckedOut: "✓ 已签出(无需重复)",
added: "✓ 已加入",
alreadyAdded: "✓ 已加入(无需重复)",
skipped: "• 跳过",
error: "✗ 失败",
}
/**
* 把结构化结果汇总成一段人话 summary,方便 AI 与人快速读懂。
*/
export function summarize(results: PendItemResult[]): string {
if (results.length === 0) {
return "未提供任何文件路径。"
}
return results.map((r) => `${ACTION_TAGS[r.action]} ${r.path} — ${r.message}`).join("\n")
}
+60
View File
@@ -0,0 +1,60 @@
import fs from "node:fs"
import os from "node:os"
import path from "node:path"
/** 读取整数环境变量,非法或缺省时回退默认值。 */
function intEnv(name: string, fallback: number): number {
const raw = process.env[name]
if (!raw) {
return fallback
}
const value = Number.parseInt(raw, 10)
return Number.isFinite(value) ? value : fallback
}
// MacTFS 本地 Java 服务地址,与 Electron / 前端约定一致(127.0.0.1:38765)。
export const TFS_API_BASE_URL =
process.env.MACTFS_API_BASE_URL ?? "http://127.0.0.1:38765"
// MCP SSE 监听地址,AI 客户端通过 http://127.0.0.1:38766/sse 连接。
export const MCP_HOST = process.env.MACTFS_MCP_HOST ?? "127.0.0.1"
export const MCP_PORT = intEnv("MACTFS_MCP_PORT", 38766)
// 本地 Bearer Token 文件,与 Java 服务、Electron 复用同一份。
export const TOKEN_FILE =
process.env.MACTFS_TOKEN_FILE ?? path.join(os.homedir(), ".mactfs", "server-token")
// 启动时等待 Java 后端就绪的最大轮询次数与间隔(毫秒)。
export const HEALTH_WAIT_TRIES = intEnv("MACTFS_MCP_HEALTH_TRIES", 60)
export const HEALTH_WAIT_INTERVAL_MS = intEnv("MACTFS_MCP_HEALTH_INTERVAL_MS", 1000)
// 父进程(Electron)pid:用于「父死则自杀」的看护,避免遗留孤儿进程。
export const PARENT_PID = (() => {
const raw = process.env.MACTFS_PARENT_PID
if (!raw) {
return null
}
const value = Number.parseInt(raw, 10)
return Number.isFinite(value) && value > 0 ? value : null
})()
// HTTP 调用 Java 服务的默认超时(毫秒)。
export const HTTP_TIMEOUT_MS = intEnv("MACTFS_MCP_HTTP_TIMEOUT_MS", 30000)
// 是否要求 AI 客户端连接 SSE 时携带 token。
// 默认关闭:已有「仅监听 127.0.0.1 + 随客户端生命周期绑定」两道保护,AI 端无需配置 token。
// 设 MACTFS_MCP_REQUIRE_TOKEN=1 可开启更严格的本机鉴权。
export const MCP_REQUIRE_TOKEN = (process.env.MACTFS_MCP_REQUIRE_TOKEN ?? "").trim() === "1"
/**
* 读取本地 Bearer Token,文件缺失或为空时返回 null。
* Token 由 Java 服务在 ~/.mactfs/server-token 生成。
*/
export function readToken(): string | null {
try {
const value = fs.readFileSync(TOKEN_FILE, "utf8").trim()
return value.length > 0 ? value : null
} catch {
return null
}
}
+11
View File
@@ -0,0 +1,11 @@
import { startServer, startStdioServer } from "./server.js"
// --mcp-stdio:以 stdio 模式运行(供 Codex / Claude 等用「命令启动子进程」接入);
// 缺省仍走 SSE 模式(供 Cursor 用 URL 接入、由 MacTFS 桌面客户端拉起)。
const useStdio = process.argv.includes("--mcp-stdio")
const run = useStdio ? startStdioServer : startServer
run().catch((error) => {
process.stderr.write(`[mactfs-mcp] fatal: ${error instanceof Error ? error.stack ?? error.message : String(error)}\n`)
process.exit(1)
})
+241
View File
@@ -0,0 +1,241 @@
import express from "express"
import type { Request } from "express"
import { z } from "zod"
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"
import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js"
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
import {
HEALTH_WAIT_INTERVAL_MS,
HEALTH_WAIT_TRIES,
MCP_HOST,
MCP_PORT,
MCP_REQUIRE_TOKEN,
PARENT_PID,
readToken,
} from "./config.js"
import { runAdd, runCheckout, summarize } from "./checkout.js"
import { tfsClient } from "./tfs-client.js"
const SERVER_NAME = "mactfs-mcp"
const SERVER_VERSION = "0.1.0"
/** 简单延时。 */
function delay(ms: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms))
}
/** stderr 日志,SSE 走 HTTP,stdout 可用但统一打 stderr 更安全。 */
function log(message: string): void {
process.stderr.write(`[mactfs-mcp] ${message}\n`)
}
/**
* 校验请求是否允许连接。
* 默认不强制 token(已有 127.0.0.1 + 客户端绑定两道保护);
* 仅当 MACTFS_MCP_REQUIRE_TOKEN=1 时,才要求 Authorization: Bearer 或 ?token=。
*/
function authorized(req: Request): boolean {
if (!MCP_REQUIRE_TOKEN) {
return true
}
const expected = readToken()
if (!expected) {
return true
}
const auth = req.headers["authorization"]
if (typeof auth === "string" && auth.startsWith("Bearer ") && auth.slice(7).trim() === expected) {
return true
}
const queryToken = req.query.token
if (typeof queryToken === "string" && queryToken === expected) {
return true
}
return false
}
/**
* 创建一个 MCP server 实例并注册工具。每个 SSE 连接用独立实例,避免跨连接状态串扰。
*/
function createMcpServer(): McpServer {
const mcp = new McpServer({ name: SERVER_NAME, version: SERVER_VERSION })
mcp.registerTool(
"tfs_checkout",
{
title: "TFS 签出文件",
description:
"在修改受 TFS 版本控制的文件之前调用本工具签出(checkout / pendEdit)。" +
"会先做执行前校验:是否在映射目录内、是否已签出、是否为新文件、本地是否落后于服务器最新版本。" +
"凡是即将编辑、且位于 MacTFS 映射目录下的已有文件,都应先调用本工具。" +
"默认行为:遇到服务端尚不存在的新文件会自动加入版本控制(add);本地版本落后时会自动先获取最新再签出。" +
"返回每个文件的处理结果(checkedOut / alreadyCheckedOut / added / alreadyAdded / skipped / error)。",
inputSchema: {
paths: z
.array(z.string())
.min(1)
.describe("要签出的文件本地绝对路径列表(也兼容 $/ 开头的服务端路径)"),
dryRun: z
.boolean()
.optional()
.describe("只做执行前校验、不真正签出/加入/获取最新,用于预检"),
getLatestIfStale: z
.boolean()
.optional()
.describe("当本地版本落后于服务器时,自动先获取最新再签出(默认 true;传 false 则仅警告、不自动获取)"),
autoAdd: z
.boolean()
.optional()
.describe("遇到服务端尚不存在的新文件时,自动加入版本控制(add)(默认 true;传 false 则仅提示改用 tfs_add)"),
},
},
async ({ paths, dryRun, getLatestIfStale, autoAdd }) => {
const results = await runCheckout(paths, { dryRun, getLatestIfStale, autoAdd })
const text = `${summarize(results)}\n\n${JSON.stringify({ results }, null, 2)}`
return { content: [{ type: "text" as const, text }] }
},
)
mcp.registerTool(
"tfs_add",
{
title: "TFS 加入版本控制",
description:
"为 MacTFS 映射目录下、尚未纳入版本控制的【新建文件】执行加入(add / pendAdd)。" +
"新建文件请在写入磁盘后调用本工具(此时文件已存在于本地)。" +
"会先做执行前校验:是否在映射目录内、本地是否存在、是否已加入、是否其实已受控(已受控应改用 tfs_checkout)。" +
"返回每个文件的处理结果(added / alreadyAdded / skipped / error)。",
inputSchema: {
paths: z
.array(z.string())
.min(1)
.describe("要加入版本控制的文件本地绝对路径列表"),
dryRun: z
.boolean()
.optional()
.describe("只做执行前校验、不真正加入,用于预检"),
},
},
async ({ paths, dryRun }) => {
const results = await runAdd(paths, { dryRun })
const text = `${summarize(results)}\n\n${JSON.stringify({ results }, null, 2)}`
return { content: [{ type: "text" as const, text }] }
},
)
return mcp
}
/**
* 启动「父进程(Electron)看护」:父进程消失则自杀,避免遗留孤儿。
*/
function startParentWatchdog(): void {
const pid = PARENT_PID
if (pid === null) {
return
}
log(`watching parent pid ${pid}`)
setInterval(() => {
try {
process.kill(pid, 0)
} catch {
log("parent process gone, exiting")
process.exit(0)
}
}, 3000)
}
/**
* 等待 Java 后端 health 就绪;超过上限仍未就绪则降级继续(工具会返回 notConnected)。
*/
async function waitForBackend(): Promise<boolean> {
for (let attempt = 0; attempt < HEALTH_WAIT_TRIES; attempt += 1) {
const health = await tfsClient.health()
if (health.ok) {
return true
}
await delay(HEALTH_WAIT_INTERVAL_MS)
}
return false
}
/**
* 启动 MCP SSE 服务:等待后端、注册路由、监听端口、挂看护。
*/
export async function startServer(): Promise<void> {
startParentWatchdog()
log("waiting for MacTFS backend ...")
const ready = await waitForBackend()
if (ready) {
log("backend ready")
} else {
log("backend not ready after wait, starting in degraded mode")
}
const app = express()
const transports: Record<string, SSEServerTransport> = {}
app.get("/sse", async (req, res) => {
if (!authorized(req)) {
res.status(401).json({ error: "unauthorized" })
return
}
const transport = new SSEServerTransport("/messages", res)
transports[transport.sessionId] = transport
res.on("close", () => {
delete transports[transport.sessionId]
})
const mcp = createMcpServer()
try {
await mcp.connect(transport)
} catch (error) {
log(`sse connect error: ${error instanceof Error ? error.message : String(error)}`)
}
})
app.post("/messages", async (req, res) => {
if (!authorized(req)) {
res.status(401).json({ error: "unauthorized" })
return
}
const sessionId = typeof req.query.sessionId === "string" ? req.query.sessionId : ""
const transport = transports[sessionId]
if (!transport) {
res.status(400).json({ error: "no transport for sessionId" })
return
}
await transport.handlePostMessage(req, res)
})
app.get("/healthz", (_req, res) => {
res.json({ ok: true, name: SERVER_NAME, version: SERVER_VERSION })
})
app.listen(MCP_PORT, MCP_HOST, () => {
log(`SSE listening on http://${MCP_HOST}:${MCP_PORT}/sse`)
})
}
/**
* 启动 MCP stdio 服务:供 Codex / Claude 等「以命令启动子进程」方式接入的通用客户端使用。
*
* 与 SSE 模式的差异:
* - 不监听 38766 端口、不起 express,AI 客户端直接通过 stdin/stdout 与本进程通信。
* - 直连 38765 Java 后端(tfsClient 已走 MACTFS_API_BASE_URL);后端未起时工具会返回 notConnected。
* - 必须尽快 connect,让客户端的 initialize 握手立即完成,故不在启动时阻塞等待后端,
* 仅在后台探测一次后端就绪并打日志(stderr,绝不写 stdout,避免污染 JSON-RPC 通道)。
*/
export async function startStdioServer(): Promise<void> {
startParentWatchdog()
void waitForBackend().then((ready) => {
log(ready ? "backend ready" : "backend not ready, running in degraded mode (tools will report notConnected)")
})
const mcp = createMcpServer()
const transport = new StdioServerTransport()
await mcp.connect(transport)
log("stdio transport connected")
}
+103
View File
@@ -0,0 +1,103 @@
import { HTTP_TIMEOUT_MS, TFS_API_BASE_URL, readToken } from "./config.js"
import type {
ApiResponse,
ApiResult,
FileOperationResult,
FileStatus,
HealthData,
} from "./types.js"
/**
* 发起一次对 Java 服务的请求,自动带 Bearer Token、统一封装结果与错误。
* 任何网络/解析失败都收敛成 { ok:false },绝不抛异常,保证 MCP 不被打断。
*/
async function request<T>(
method: string,
path: string,
options: { query?: Record<string, string | undefined>; body?: unknown } = {},
): Promise<ApiResponse<T>> {
const token = readToken()
const url = new URL(path, TFS_API_BASE_URL)
if (options.query) {
for (const [key, value] of Object.entries(options.query)) {
if (value !== undefined && value !== null) {
url.searchParams.set(key, value)
}
}
}
const headers: Record<string, string> = {
Accept: "application/json",
// 标记本次请求来自 MCP(AI),供后端操作日志区分「AI 操作 / 手动操作」。
"X-MacTFS-Source": "mcp",
}
if (token) {
headers.Authorization = `Bearer ${token}`
}
const init: RequestInit = { method, headers }
if (options.body !== undefined) {
headers["Content-Type"] = "application/json;charset=utf-8"
init.body = JSON.stringify(options.body)
}
const controller = new AbortController()
const timer = setTimeout(() => controller.abort(), HTTP_TIMEOUT_MS)
init.signal = controller.signal
let response: Response
try {
response = await fetch(url, init)
} catch (error) {
clearTimeout(timer)
const message = error instanceof Error ? error.message : String(error)
return { ok: false, status: 0, data: null, errorMessage: `无法连接本地服务:${message}` }
}
clearTimeout(timer)
let result: ApiResult<T> | null = null
try {
result = (await response.json()) as ApiResult<T>
} catch {
result = null
}
const ok = response.ok && result?.success === true
return {
ok,
status: response.status,
data: result?.data ?? null,
errorMessage: ok
? null
: result?.errorMessage || result?.message || `请求失败(HTTP ${response.status})`,
}
}
// 统一的 Java 服务客户端,MCP 只通过本对象访问后端。
export const tfsClient = {
/** 健康检查,返回 { connected } 等服务状态。 */
health() {
return request<HealthData>("GET", "/api/health")
},
/** 查询单个本地文件的 TFS 状态(依赖后端新增的 /api/files/status)。 */
fileStatus(localPath: string) {
return request<{ status: FileStatus }>("GET", "/api/files/status", { query: { localPath } })
},
/** 对给定路径执行签出(pendEdit),paths 可为本地绝对路径或服务端路径。 */
checkout(paths: string[], recursive = false) {
return request<{ result: FileOperationResult }>("POST", "/api/files/checkout", {
body: { paths, recursive },
})
},
/** 将本地新增文件加入 pending add,paths 为本地绝对路径。 */
add(paths: string[], recursive = false) {
return request<{ result: FileOperationResult }>("POST", "/api/files/add", {
body: { paths, recursive },
})
},
/** 获取最新(用于 getLatestIfStale 场景),serverPath 缺省按当前 Workspace 全量。 */
getLatest(serverPath: string | undefined, recursive = false) {
return request<{ result: unknown }>("POST", "/api/files/get-latest", {
body: { serverPath, recursive, force: false },
})
},
}
+77
View File
@@ -0,0 +1,77 @@
// 与 Java 后端 ApiResult 对齐的统一响应外壳。
export interface ApiResult<T = Record<string, unknown>> {
success: boolean
message?: string
errorMessage?: string
operation?: string
data: T
}
// HTTP 客户端对外返回结构,统一封装网络层与业务层。
export interface ApiResponse<T = Record<string, unknown>> {
ok: boolean
status: number
data: T | null
errorMessage: string | null
}
// /api/health 返回的 data 字段。
export interface HealthData {
status?: string
connected?: boolean
}
// /api/files/status(新增)返回的单文件状态。
export interface FileStatus {
localPath: string
serverPath: string | null
mapped: boolean
exists: boolean
serverExists: boolean
pendingEdit: boolean
pendingChangeType: string | null
localVersion: number
latestVersion: number
upToDate: boolean
status: string
}
// /api/files/checkout 返回的 result 字段。
export interface FileOperationResult {
operation: string
affected: number
failures: string[]
}
// tfs_checkout / tfs_add 对每个路径返回的结构化结果(共用一套结构)。
export type PendAction =
| "checkedOut"
| "alreadyCheckedOut"
| "added"
| "alreadyAdded"
| "skipped"
| "error"
export type PendReason =
| "ok"
| "notConnected"
| "clientNotRunning"
| "notMapped"
| "newFileNeedsAdd"
| "notDownloaded"
| "stale"
| "notExist"
| "alreadyTracked"
| "error"
export interface PendItemResult {
path: string
serverPath: string | null
action: PendAction
reason: PendReason
mapped: boolean
pendingEdit: boolean
localVersion: number
latestVersion: number
upToDate: boolean
message: string
}
+18
View File
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"lib": ["ES2022"],
"outDir": "dist",
"rootDir": "src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"declaration": false,
"sourceMap": true,
"resolveJsonModule": true
},
"include": ["src/**/*.ts"]
}
@@ -214,7 +214,7 @@ public class MacTfsCli {
private static String readServerToken() throws Exception {
File tokenFile = serverTokenFile();
if (!tokenFile.exists()) {
throw new IllegalArgumentException("Token file not found: " + tokenFile.getAbsolutePath() + ". Start macTFS API server first.");
throw new IllegalArgumentException("Token file not found: " + tokenFile.getAbsolutePath() + ". Start MacTFS API server first.");
}
String token = new String(java.nio.file.Files.readAllBytes(tokenFile.toPath()), Charset.forName("UTF-8")).trim();
if (token.length() == 0) {
@@ -235,7 +235,8 @@ public class TfsPhaseOneService {
required(merged, "workspace"),
required(merged, "server-path"),
merged.getProperty("local-path"),
!"false".equalsIgnoreCase(merged.getProperty("recursive"))
!"false".equalsIgnoreCase(merged.getProperty("recursive")),
!"false".equalsIgnoreCase(merged.getProperty("include-local-only"))
);
Map<String, Object> data = new LinkedHashMap<String, Object>();
data.put("diffs", folderDiffsToMaps(result.getData()));
@@ -13,7 +13,9 @@ import com.microsoft.tfs.core.clients.framework.location.ConnectOptions;
import com.microsoft.tfs.core.clients.versioncontrol.GetItemsOptions;
import com.microsoft.tfs.core.clients.versioncontrol.GetOptions;
import com.microsoft.tfs.core.clients.versioncontrol.GetStatus;
import com.microsoft.tfs.core.clients.versioncontrol.MergeFlags;
import com.microsoft.tfs.core.clients.versioncontrol.PendChangesOptions;
import com.microsoft.tfs.core.clients.versioncontrol.RollbackOptions;
import com.microsoft.tfs.core.clients.versioncontrol.VersionControlClient;
import com.microsoft.tfs.core.clients.versioncontrol.WorkspaceLocation;
import com.microsoft.tfs.core.clients.versioncontrol.WorkspaceOptions;
@@ -30,6 +32,7 @@ import com.microsoft.tfs.core.clients.versioncontrol.soapextensions.Item;
import com.microsoft.tfs.core.clients.versioncontrol.soapextensions.ItemSet;
import com.microsoft.tfs.core.clients.versioncontrol.soapextensions.ItemType;
import com.microsoft.tfs.core.clients.versioncontrol.soapextensions.LockLevel;
import com.microsoft.tfs.core.clients.versioncontrol.soapextensions.MergeCandidate;
import com.microsoft.tfs.core.clients.versioncontrol.soapextensions.PendingChange;
import com.microsoft.tfs.core.clients.versioncontrol.soapextensions.PendingSet;
import com.microsoft.tfs.core.clients.versioncontrol.soapextensions.RecursionType;
@@ -61,7 +64,7 @@ import java.util.Map;
import java.util.Set;
/**
* macTFS 核心服务层,封装 TFS 连接、目录、Workspace、文件操作、历史和 Diff 能力。
* MacTFS 核心服务层,封装 TFS 连接、目录、Workspace、文件操作、历史和 Diff 能力。
*/
public class MacTfsCoreService {
@@ -136,7 +139,7 @@ public class MacTfsCoreService {
}
/**
* 查询或创建 Collection 默认 Workspace,未传名称时按 macTFS 规则生成。
* 查询或创建 Collection 默认 Workspace,未传名称时按 MacTFS 规则生成。
*/
public CoreOperationResult<TfsWorkspaceInfo> ensureWorkspace(final TfsConnectionConfig config,
final String collectionName,
@@ -393,6 +396,157 @@ public class MacTfsCoreService {
});
}
/**
* 分支:把源服务端路径分叉到目标路径(pendBranch 产生挂起更改,签入后服务器生效)。
* 目标路径所在父目录必须已映射;changesetId 为 null 时基于 latest。
*/
public CoreOperationResult<TfsFileOperationResult> branch(final TfsConnectionConfig config,
final String collectionName,
final String workspaceName,
final String sourceServerPath,
final String targetServerPath,
final Integer changesetId) {
return execute("branch", new CoreCallable<TfsFileOperationResult>() {
@Override
public TfsFileOperationResult call(List<String> logs) throws Exception {
Workspace workspace = loadWorkspace(config, collectionName, workspaceName);
String source = normalizeServerPath(require(sourceServerPath, "sourceServerPath"));
String target = normalizeServerPath(require(targetServerPath, "targetServerPath"));
if (source.equals(target)) {
throw new IllegalArgumentException("Target path is same as source path");
}
VersionSpec version = changesetId == null
? LatestVersionSpec.INSTANCE
: new ChangesetVersionSpec(changesetId.intValue());
int affected = workspace.pendBranch(source, target, version, LockLevel.NONE, RecursionType.FULL, GetOptions.NONE, PendChangesOptions.NONE);
logs.add("Branch pended: " + source + " -> " + target);
return new TfsFileOperationResult("branch", affected, Collections.<String>emptyList());
}
});
}
/**
* 查询源 → 目标的待合并变更集候选列表(对应 VS Merge 向导的候选页)。
*/
public CoreOperationResult<List<TfsHistoryEntry>> mergeCandidates(final TfsConnectionConfig config,
final String collectionName,
final String workspaceName,
final String sourceServerPath,
final String targetServerPath) {
return execute("mergeCandidates", new CoreCallable<List<TfsHistoryEntry>>() {
@Override
public List<TfsHistoryEntry> call(List<String> logs) throws Exception {
Workspace workspace = loadWorkspace(config, collectionName, workspaceName);
String source = normalizeServerPath(require(sourceServerPath, "sourceServerPath"));
String target = normalizeServerPath(require(targetServerPath, "targetServerPath"));
MergeCandidate[] candidates = workspace.getMergeCandidates(source, target, RecursionType.FULL, MergeFlags.NONE);
List<TfsHistoryEntry> result = new ArrayList<TfsHistoryEntry>();
if (candidates != null) {
for (MergeCandidate candidate : candidates) {
Changeset changeset = candidate.getChangeset();
if (changeset == null) {
continue;
}
result.add(new TfsHistoryEntry(
source,
nameOf(source),
candidate.isPartial() ? "partial merge" : "merge",
"",
changeset.getChangesetID(),
emptyToDefault(changeset.getOwnerDisplayName(), changeset.getOwner()),
changeset.getDate() == null ? null : Long.valueOf(changeset.getDate().getTimeInMillis()),
changeset.getComment()
));
}
}
logs.add("Merge candidates: " + result.size());
return result;
}
});
}
/**
* 合并:把源分支的改动合并到目标分支(产生挂起更改,冲突走冲突处理)。
* changesetId 为 null 时合并全部候选,否则仅合并该变更集。
*/
public CoreOperationResult<TfsGetLatestResult> merge(final TfsConnectionConfig config,
final String collectionName,
final String workspaceName,
final String sourceServerPath,
final String targetServerPath,
final Integer changesetId) {
return execute("merge", new CoreCallable<TfsGetLatestResult>() {
@Override
public TfsGetLatestResult call(List<String> logs) throws Exception {
Workspace workspace = loadWorkspace(config, collectionName, workspaceName);
String source = normalizeServerPath(require(sourceServerPath, "sourceServerPath"));
String target = normalizeServerPath(require(targetServerPath, "targetServerPath"));
VersionSpec from = changesetId == null ? null : new ChangesetVersionSpec(changesetId.intValue());
VersionSpec to = changesetId == null ? LatestVersionSpec.INSTANCE : new ChangesetVersionSpec(changesetId.intValue());
GetStatus status = workspace.merge(source, target, from, to, LockLevel.NONE, RecursionType.FULL, MergeFlags.NONE);
logs.add("Merge " + source + " -> " + target + " operations=" + status.getNumOperations() + " conflicts=" + status.getNumConflicts());
return toGetLatestResult(status);
}
});
}
/**
* 回滚变更集(只产生挂起更改,需用户审查后签入):
* mode=single 仅反做该 changeset;mode=toVersion 反做该 changeset 之后的全部改动。
*/
public CoreOperationResult<TfsGetLatestResult> rollback(final TfsConnectionConfig config,
final String collectionName,
final String workspaceName,
final String serverPath,
final String mode,
final int changesetId) {
return execute("rollback", new CoreCallable<TfsGetLatestResult>() {
@Override
public TfsGetLatestResult call(List<String> logs) throws Exception {
Workspace workspace = loadWorkspace(config, collectionName, workspaceName);
ItemSpec[] specs = new ItemSpec[] {
new ItemSpec(normalizeServerPath(require(serverPath, "serverPath")), RecursionType.FULL)
};
boolean toVersion = "toVersion".equalsIgnoreCase(require(mode, "mode"));
ChangesetVersionSpec changesetSpec = new ChangesetVersionSpec(changesetId);
GetStatus status = toVersion
? workspace.rollback(specs, LatestVersionSpec.INSTANCE, null, changesetSpec, LockLevel.NONE, RollbackOptions.TO_VERSION)
: workspace.rollback(specs, LatestVersionSpec.INSTANCE, changesetSpec, changesetSpec, LockLevel.NONE, RollbackOptions.NONE);
logs.add("Rollback mode=" + mode + " changeset=" + changesetId + " operations=" + status.getNumOperations());
return toGetLatestResult(status);
}
});
}
/**
* 重命名已映射的文件或目录(同目录改名):产生 rename 挂起更改,签入后服务器生效。
*/
public CoreOperationResult<TfsFileOperationResult> rename(final TfsConnectionConfig config,
final String collectionName,
final String workspaceName,
final String serverPath,
final String newName) {
return execute("rename", new CoreCallable<TfsFileOperationResult>() {
@Override
public TfsFileOperationResult call(List<String> logs) throws Exception {
Workspace workspace = loadWorkspace(config, collectionName, workspaceName);
String oldPath = normalizeServerPath(require(serverPath, "serverPath"));
String name = require(newName, "newName").trim();
if (name.contains("/") || name.contains("\\")) {
throw new IllegalArgumentException("Invalid new name: " + newName);
}
int slash = oldPath.lastIndexOf('/');
String newPath = oldPath.substring(0, slash + 1) + name;
if (newPath.equals(oldPath)) {
throw new IllegalArgumentException("New name is same as current name");
}
int affected = workspace.pendRename(oldPath, newPath, LockLevel.NONE, GetOptions.NONE, true, PendChangesOptions.NONE);
logs.add("Rename pended: " + oldPath + " -> " + newPath);
return new TfsFileOperationResult("rename", affected, Collections.<String>emptyList());
}
});
}
/**
* 按选中的 pending changes 执行 checkin,comment 为空时直接拒绝。
*/
@@ -425,7 +579,8 @@ public class MacTfsCoreService {
final String workspaceName,
final String serverPath,
final String localPath,
final boolean recursive) {
final boolean recursive,
final boolean includeLocalOnly) {
return execute("compareFolder", new CoreCallable<List<TfsFolderDiffItem>>() {
@Override
public List<TfsFolderDiffItem> call(List<String> logs) throws Exception {
@@ -439,7 +594,10 @@ public class MacTfsCoreService {
}
Map<String, ExtendedItem> serverItems = queryExtendedItems(workspace, normalizedServerPath, recursive);
Map<String, PendingChange> pendingChanges = mapPendingChanges(queryPendingChanges(workspace, Arrays.asList(normalizedServerPath), recursive));
Set<String> localFiles = scanLocalFiles(new File(normalizedLocalPath), recursive);
// 不统计仅本地存在的项时直接跳过本地全量扫描(如 node_modules 大目录),只对比两端都有的文件。
Set<String> localFiles = includeLocalOnly
? scanLocalFiles(new File(normalizedLocalPath), recursive)
: new LinkedHashSet<String>();
Map<String, TfsFolderDiffItem> result = new LinkedHashMap<String, TfsFolderDiffItem>();
for (Map.Entry<String, ExtendedItem> entry : serverItems.entrySet()) {
@@ -584,6 +742,182 @@ public class MacTfsCoreService {
});
}
/**
* 查询单个服务端对象(文件或目录)的属性信息:最新版本、签入时间与签入人,文件附带大小与编码。
* 签入人与备注来自最近一条历史记录(Item 本身不携带提交人信息)。
*/
public CoreOperationResult<TfsItemInfo> getItemInfo(final TfsConnectionConfig config,
final String collectionName,
final String serverPath) {
return execute("getItemInfo", new CoreCallable<TfsItemInfo>() {
@Override
public TfsItemInfo call(List<String> logs) throws Exception {
CoreConnection connection = connectCollection(config, collectionName);
Item item = connection.versionControlClient.getItem(
require(serverPath, "serverPath"),
LatestVersionSpec.INSTANCE,
DeletedState.NON_DELETED,
GetItemsOptions.NONE
);
boolean folder = isFolder(item.getItemType());
int changeset = item.getChangeSetID();
Long checkinDate = item.getCheckinDate() == null ? null : Long.valueOf(item.getCheckinDate().getTimeInMillis());
String author = "";
String comment = "";
Changeset[] changesets = connection.versionControlClient.queryHistory(
item.getServerItem(),
LatestVersionSpec.INSTANCE,
0,
folder ? RecursionType.FULL : RecursionType.NONE,
null,
null,
null,
1,
false,
true,
false,
false
);
if (changesets != null && changesets.length > 0 && changesets[0] != null) {
Changeset latest = changesets[0];
author = emptyToDefault(latest.getOwnerDisplayName(), latest.getOwner());
comment = latest.getComment() == null ? "" : latest.getComment();
// 目录的最新变动以子树最近一次签入为准(Item 自身的 changeset 不含子项变动)。
changeset = latest.getChangesetID();
if (latest.getDate() != null) {
checkinDate = Long.valueOf(latest.getDate().getTimeInMillis());
}
}
TfsItemInfo info = new TfsItemInfo(
item.getServerItem(),
folder,
changeset,
checkinDate,
author,
comment,
folder ? null : Long.valueOf(item.getContentLength()),
folder || item.getEncoding() == null ? null : item.getEncoding().getName()
);
logs.add("Item info loaded: " + item.getServerItem());
return info;
}
});
}
/**
* 查询单个本地文件的 TFS 状态(是否映射 / 是否已签出 / 本地与最新版本对比),
* 供 MCP 在 AI 改文件前做执行前校验。整条逻辑复用目录对比的状态判定。
*/
public CoreOperationResult<TfsFileStatus> fileStatus(final TfsConnectionConfig config,
final String collectionName,
final String workspaceName,
final String localPath) {
return execute("fileStatus", new CoreCallable<TfsFileStatus>() {
@Override
public TfsFileStatus call(List<String> logs) throws Exception {
Workspace workspace = loadWorkspace(config, collectionName, workspaceName);
String absolute = new File(require(localPath, "localPath")).getAbsolutePath();
boolean exists = new File(absolute).exists();
String serverPath = mappedServerPathOf(workspace, absolute);
if (serverPath == null) {
logs.add("File not mapped: " + absolute);
return TfsFileStatus.notMapped(absolute, exists);
}
ExtendedItem item = queryExtendedItem(workspace, serverPath);
PendingChange pendingChange = findPendingChange(workspace, serverPath);
String pendingChangeType = pendingChange == null ? null : toPendingStatus(pendingChange);
boolean pendingEdit = pendingChange != null && pendingChange.isEdit();
int localVersion = item == null ? 0 : item.getLocalVersion();
int latestVersion = item == null ? 0 : item.getLatestVersion();
boolean serverExists = latestVersion > 0;
String status;
if (item == null) {
status = exists ? "localOnly" : "notDownloaded";
} else {
status = resolveDiffStatus(item, pendingChange, new File(absolute));
}
boolean upToDate = serverExists && localVersion > 0 && localVersion >= latestVersion;
logs.add("File status: " + serverPath + " local=" + localVersion + " latest=" + latestVersion + " status=" + status);
return new TfsFileStatus(absolute, serverPath, true, exists, serverExists, pendingEdit,
pendingChangeType, localVersion, latestVersion, upToDate, status);
}
});
}
/**
* 将本地绝对路径解析为映射的服务端路径,取最深(最长)匹配的映射根;未命中任何映射返回 null。
*/
private String mappedServerPathOf(Workspace workspace, String absoluteLocalPath) {
WorkingFolder[] folders = workspace.getFolders();
if (folders == null) {
return null;
}
String best = null;
String bestRoot = null;
for (WorkingFolder folder : folders) {
if (folder.getLocalItem() == null) {
continue;
}
String localRoot = new File(folder.getLocalItem()).getAbsolutePath();
boolean underRoot = absoluteLocalPath.equals(localRoot)
|| absoluteLocalPath.startsWith(localRoot + File.separator);
if (!underRoot) {
continue;
}
if (bestRoot != null && localRoot.length() <= bestRoot.length()) {
continue;
}
bestRoot = localRoot;
String serverRoot = normalizeServerPath(folder.getServerItem());
String relative = absoluteLocalPath.substring(localRoot.length()).replace(File.separatorChar, '/');
while (relative.startsWith("/")) {
relative = relative.substring(1);
}
best = relative.isEmpty() ? serverRoot : serverRoot + "/" + relative;
}
return best;
}
/**
* 查询单个服务端路径对应的 ExtendedItem(本地版本 / 最新版本 / 类型),无则返回 null。
*/
private ExtendedItem queryExtendedItem(Workspace workspace, String serverPath) {
ExtendedItem[][] groups = workspace.getExtendedItems(
new ItemSpec[]{new ItemSpec(normalizeServerPath(serverPath), RecursionType.NONE)},
DeletedState.NON_DELETED,
ItemType.ANY,
GetItemsOptions.NONE
);
if (groups == null) {
return null;
}
for (ExtendedItem[] group : groups) {
if (group == null) {
continue;
}
for (ExtendedItem item : group) {
if (item != null) {
return item;
}
}
}
return null;
}
/**
* 查询单个服务端路径上的挂起更改,无则返回 null。
*/
private PendingChange findPendingChange(Workspace workspace, String serverPath) {
PendingChange[] changes = queryPendingChanges(workspace, Arrays.asList(serverPath), false);
String normalized = normalizeServerPath(serverPath).toLowerCase();
for (PendingChange change : changes) {
if (change.getServerItem() != null && change.getServerItem().toLowerCase().equals(normalized)) {
return change;
}
}
return null;
}
/**
* 生成本地文件和服务器 latest 的文本 diff。
*/
@@ -1021,8 +1355,12 @@ public class MacTfsCoreService {
}
boolean exists = localFile != null && localFile.exists();
boolean remoteChanged = item.getLocalVersion() > 0 && item.getLatestVersion() > item.getLocalVersion();
// mtime 只能作为远端版本变化时的辅助信号,避免 Get Latest 后因本地时间晚于签入时间误报本地修改。
boolean localModified = remoteChanged && exists && item.getCheckinDate() != null && localFile.lastModified() > item.getCheckinDate().getTimeInMillis();
// 服务器工作区下文件取下来默认只读,变为可写说明被本地解锁修改过(对齐 VS 的 writable 判定),
// 这样未签出的纯本地修改也能在目录对比中暴露出来。
boolean writableFile = exists && !isFolder(item.getItemType()) && localFile.canWrite();
// mtime 仅作为远端版本变化时的辅助信号,避免 Get Latest 后因本地时间晚于签入时间误报本地修改。
boolean mtimeNewer = exists && item.getCheckinDate() != null && localFile.lastModified() > item.getCheckinDate().getTimeInMillis();
boolean localModified = writableFile || (remoteChanged && mtimeNewer);
if (!exists && item.getLocalVersion() > 0) {
return "localDeleted";
}
@@ -1106,7 +1444,9 @@ public class MacTfsCoreService {
isFolder(change.getItemType()),
toPendingStatus(change),
change.getChangeType() == null ? "" : change.getChangeType().toUIString(false),
change.getVersion()
change.getVersion(),
// rename 挂起更改携带原路径,供 UI 展示「旧名 → 新名」。
change.isRename() ? change.getSourceServerItem() : null
));
}
return result;
@@ -1676,8 +2016,9 @@ public class MacTfsCoreService {
private final String status;
private final String changeType;
private final int version;
private final String sourceServerPath;
public TfsPendingChangeInfo(String serverPath, String localPath, String name, boolean folder, String status, String changeType, int version) {
public TfsPendingChangeInfo(String serverPath, String localPath, String name, boolean folder, String status, String changeType, int version, String sourceServerPath) {
this.serverPath = serverPath;
this.localPath = localPath;
this.name = name;
@@ -1685,6 +2026,7 @@ public class MacTfsCoreService {
this.status = status;
this.changeType = changeType;
this.version = version;
this.sourceServerPath = sourceServerPath;
}
public String getServerPath() {
@@ -1714,6 +2056,10 @@ public class MacTfsCoreService {
public int getVersion() {
return version;
}
public String getSourceServerPath() {
return sourceServerPath;
}
}
public static class TfsFileOperationResult {
@@ -1902,6 +2248,139 @@ public class MacTfsCoreService {
}
}
public static class TfsItemInfo {
private final String serverPath;
private final boolean folder;
private final int changeset;
private final Long checkinDate;
private final String author;
private final String comment;
private final Long size;
private final String encoding;
public TfsItemInfo(String serverPath, boolean folder, int changeset, Long checkinDate,
String author, String comment, Long size, String encoding) {
this.serverPath = serverPath;
this.folder = folder;
this.changeset = changeset;
this.checkinDate = checkinDate;
this.author = author;
this.comment = comment;
this.size = size;
this.encoding = encoding;
}
public String getServerPath() {
return serverPath;
}
public boolean isFolder() {
return folder;
}
public int getChangeset() {
return changeset;
}
public Long getCheckinDate() {
return checkinDate;
}
public String getAuthor() {
return author;
}
public String getComment() {
return comment;
}
public Long getSize() {
return size;
}
public String getEncoding() {
return encoding;
}
}
public static class TfsFileStatus {
private final String localPath;
private final String serverPath;
private final boolean mapped;
private final boolean exists;
private final boolean serverExists;
private final boolean pendingEdit;
private final String pendingChangeType;
private final int localVersion;
private final int latestVersion;
private final boolean upToDate;
private final String status;
public TfsFileStatus(String localPath, String serverPath, boolean mapped, boolean exists, boolean serverExists,
boolean pendingEdit, String pendingChangeType, int localVersion, int latestVersion,
boolean upToDate, String status) {
this.localPath = localPath;
this.serverPath = serverPath;
this.mapped = mapped;
this.exists = exists;
this.serverExists = serverExists;
this.pendingEdit = pendingEdit;
this.pendingChangeType = pendingChangeType;
this.localVersion = localVersion;
this.latestVersion = latestVersion;
this.upToDate = upToDate;
this.status = status;
}
public static TfsFileStatus notMapped(String localPath, boolean exists) {
return new TfsFileStatus(localPath, null, false, exists, false, false, null, 0, 0, false, "notMapped");
}
public String getLocalPath() {
return localPath;
}
public String getServerPath() {
return serverPath;
}
public boolean isMapped() {
return mapped;
}
public boolean isExists() {
return exists;
}
public boolean isServerExists() {
return serverExists;
}
public boolean isPendingEdit() {
return pendingEdit;
}
public String getPendingChangeType() {
return pendingChangeType;
}
public int getLocalVersion() {
return localVersion;
}
public int getLatestVersion() {
return latestVersion;
}
public boolean isUpToDate() {
return upToDate;
}
public String getStatus() {
return status;
}
}
public static class TfsConflictInfo {
private final int conflictId;
private final String type;
@@ -14,9 +14,11 @@ import com.mydev.mactfs.core.MacTfsCoreService.TfsConflictResolution;
import com.mydev.mactfs.core.MacTfsCoreService.TfsConnectionConfig;
import com.mydev.mactfs.core.MacTfsCoreService.TfsFileContent;
import com.mydev.mactfs.core.MacTfsCoreService.TfsFileOperationResult;
import com.mydev.mactfs.core.MacTfsCoreService.TfsFileStatus;
import com.mydev.mactfs.core.MacTfsCoreService.TfsFolderDiffItem;
import com.mydev.mactfs.core.MacTfsCoreService.TfsGetLatestResult;
import com.mydev.mactfs.core.MacTfsCoreService.TfsHistoryEntry;
import com.mydev.mactfs.core.MacTfsCoreService.TfsItemInfo;
import com.mydev.mactfs.core.MacTfsCoreService.TfsMappingInfo;
import com.mydev.mactfs.core.MacTfsCoreService.TfsPendingChangeInfo;
import com.mydev.mactfs.core.MacTfsCoreService.TfsServerItem;
@@ -51,7 +53,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
/**
* macTFS 第二阶段本地 API 服务入口,负责 HTTP 路由、Token 校验、配置、会话、日志和超时控制。
* MacTFS 第二阶段本地 API 服务入口,负责 HTTP 路由、Token 校验、配置、会话、日志和超时控制。
*/
public class MacTfsServer {
@@ -92,8 +94,66 @@ public class MacTfsServer {
registerFilters();
registerRoutes();
Spark.awaitInitialization();
System.out.println("macTFS API server listening on http://" + HOST + ":" + PORT);
System.out.println("macTFS token file: " + tokenStore.getTokenFile().getAbsolutePath());
System.out.println("MacTFS API server listening on http://" + HOST + ":" + PORT);
System.out.println("MacTFS token file: " + tokenStore.getTokenFile().getAbsolutePath());
startParentWatchdog();
}
/**
* 启动父进程看护:当拉起本服务的宿主(Electron)进程消失时自动退出,
* 避免宿主被强制结束 / 崩溃后遗留「占着 38765 端口」的孤儿后端。
* 依据环境变量 MACTFS_PARENT_PID(由宿主 spawn 时写入);未设置则不启用(如 CLI / 手动启动)。
*/
private void startParentWatchdog() {
String raw = System.getenv("MACTFS_PARENT_PID");
if (raw == null || raw.trim().isEmpty()) {
return;
}
final long parentPid;
try {
parentPid = Long.parseLong(raw.trim());
} catch (NumberFormatException exception) {
return;
}
Thread watchdog = new Thread(new Runnable() {
@Override
public void run() {
while (true) {
try {
Thread.sleep(3000L);
} catch (InterruptedException exception) {
return;
}
if (!isProcessAlive(parentPid)) {
System.out.println("MacTFS parent process " + parentPid + " gone, exiting.");
System.exit(0);
}
}
}
}, "mactfs-parent-watchdog");
watchdog.setDaemon(true);
watchdog.start();
System.out.println("MacTFS watching parent pid " + parentPid);
}
/**
* 判断给定 pid 的进程是否存活:macOS / Linux 上用 `/bin/kill -0 <pid>` 探测,退出码 0 即存活。
* 探测自身出现异常时按「存活」处理,宁可不退也不误杀正在服务的后端。
*/
private boolean isProcessAlive(long pid) {
try {
Process probe = new ProcessBuilder("/bin/kill", "-0", String.valueOf(pid))
.redirectErrorStream(true)
.start();
boolean finished = probe.waitFor(5, TimeUnit.SECONDS);
if (!finished) {
probe.destroyForcibly();
return true;
}
return probe.exitValue() == 0;
} catch (Exception exception) {
return true;
}
}
/**
@@ -149,7 +209,7 @@ public class MacTfsServer {
private void registerFilters() {
Spark.before((request, response) -> {
response.header("Access-Control-Allow-Origin", "*");
response.header("Access-Control-Allow-Headers", "Authorization, Content-Type");
response.header("Access-Control-Allow-Headers", "Authorization, Content-Type, X-MacTFS-Source");
response.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
if ("OPTIONS".equalsIgnoreCase(request.requestMethod())) {
throw Spark.halt(204, "");
@@ -219,6 +279,22 @@ public class MacTfsServer {
}
}));
// 只读连通性探测:用当前会话/已存配置真正回连一次 TFS,验证服务是否仍可达、认证是否仍有效。
// 不修改任何会话或配置状态,供顶栏「连接测试」手动触发;耗时见返回的 coreDurationMs。
Spark.post("/api/session/test", (request, response) -> handle(request, response, "testConnection", TIMEOUT_CONNECT_MS, new ApiCallable() {
@Override
public ApiResult call(Request request) throws Exception {
AppConfig config = requestConfig(readBody(request));
CoreOperationResult<ConnectionSummary> result = coreService.testConnection(toTfsConfig(config));
Map<String, Object> data = new LinkedHashMap<String, Object>();
if (result.getData() != null) {
data.put("serverUri", result.getData().getServerUri());
data.put("collectionCount", Integer.valueOf(result.getData().getCollectionCount()));
}
return fromCore(result, data);
}
}));
Spark.get("/api/collections", (request, response) -> handle(request, response, "listCollections", TIMEOUT_DIRECTORY_MS, new ApiCallable() {
@Override
public ApiResult call(Request request) throws Exception {
@@ -446,6 +522,71 @@ public class MacTfsServer {
}
}));
Spark.get("/api/files/merge-candidates", (request, response) -> handle(request, response, "mergeCandidates", TIMEOUT_HISTORY_MS, new ApiCallable() {
@Override
public ApiResult call(Request request) throws Exception {
AppConfig config = requestConfig(new LinkedHashMap<String, Object>());
CoreOperationResult<List<TfsHistoryEntry>> result = coreService.mergeCandidates(toTfsConfig(config), require(config.collection, "collection"), require(config.workspace, "workspace"), require(request.queryParams("sourceServerPath"), "sourceServerPath"), require(request.queryParams("targetServerPath"), "targetServerPath"));
Map<String, Object> data = new LinkedHashMap<String, Object>();
data.put("candidates", result.getData() == null ? Collections.emptyList() : result.getData());
return fromCore(result, data);
}
}));
Spark.post("/api/files/merge", (request, response) -> handle(request, response, "merge", TIMEOUT_LONG_WRITE_MS, new ApiCallable() {
@Override
public ApiResult call(Request request) throws Exception {
Map<String, Object> body = readBody(request);
AppConfig config = requestConfig(body);
Number changeset = (Number) body.get("changeset");
CoreOperationResult<TfsGetLatestResult> result = coreService.merge(toTfsConfig(config), require(config.collection, "collection"), require(config.workspace, "workspace"), require(stringValue(body, "sourceServerPath"), "sourceServerPath"), require(stringValue(body, "targetServerPath"), "targetServerPath"), changeset == null ? null : Integer.valueOf(changeset.intValue()));
Map<String, Object> data = new LinkedHashMap<String, Object>();
data.put("result", result.getData());
return fromCore(result, data);
}
}));
Spark.post("/api/files/branch", (request, response) -> handle(request, response, "branch", TIMEOUT_LONG_WRITE_MS, new ApiCallable() {
@Override
public ApiResult call(Request request) throws Exception {
Map<String, Object> body = readBody(request);
AppConfig config = requestConfig(body);
Number changeset = (Number) body.get("changeset");
CoreOperationResult<TfsFileOperationResult> result = coreService.branch(toTfsConfig(config), require(config.collection, "collection"), require(config.workspace, "workspace"), require(stringValue(body, "sourceServerPath"), "sourceServerPath"), require(stringValue(body, "targetServerPath"), "targetServerPath"), changeset == null ? null : Integer.valueOf(changeset.intValue()));
Map<String, Object> data = new LinkedHashMap<String, Object>();
data.put("result", result.getData());
return fromCore(result, data);
}
}));
Spark.post("/api/files/rollback", (request, response) -> handle(request, response, "rollback", TIMEOUT_LONG_WRITE_MS, new ApiCallable() {
@Override
public ApiResult call(Request request) throws Exception {
Map<String, Object> body = readBody(request);
AppConfig config = requestConfig(body);
Number changeset = (Number) body.get("changeset");
if (changeset == null) {
throw new IllegalArgumentException("changeset is required");
}
CoreOperationResult<TfsGetLatestResult> result = coreService.rollback(toTfsConfig(config), require(config.collection, "collection"), require(config.workspace, "workspace"), require(stringValue(body, "serverPath"), "serverPath"), require(stringValue(body, "mode"), "mode"), changeset.intValue());
Map<String, Object> data = new LinkedHashMap<String, Object>();
data.put("result", result.getData());
return fromCore(result, data);
}
}));
Spark.post("/api/files/rename", (request, response) -> handle(request, response, "rename", TIMEOUT_DEFAULT_MS, new ApiCallable() {
@Override
public ApiResult call(Request request) throws Exception {
Map<String, Object> body = readBody(request);
AppConfig config = requestConfig(body);
CoreOperationResult<TfsFileOperationResult> result = coreService.rename(toTfsConfig(config), require(config.collection, "collection"), require(config.workspace, "workspace"), require(stringValue(body, "serverPath"), "serverPath"), require(stringValue(body, "newName"), "newName"));
Map<String, Object> data = new LinkedHashMap<String, Object>();
data.put("result", result.getData());
return fromCore(result, data);
}
}));
Spark.get("/api/files/content", (request, response) -> handle(request, response, "fileContent", TIMEOUT_DIFF_MS, new ApiCallable() {
@Override
public ApiResult call(Request request) throws Exception {
@@ -467,6 +608,33 @@ public class MacTfsServer {
}
}));
Spark.get("/api/files/status", (request, response) -> handle(request, response, "fileStatus", TIMEOUT_DEFAULT_MS, new ApiCallable() {
@Override
public ApiResult call(Request request) throws Exception {
AppConfig config = requestConfig(new LinkedHashMap<String, Object>());
CoreOperationResult<TfsFileStatus> result = coreService.fileStatus(
toTfsConfig(config),
require(config.collection, "collection"),
require(config.workspace, "workspace"),
require(request.queryParams("localPath"), "localPath")
);
Map<String, Object> data = new LinkedHashMap<String, Object>();
data.put("status", result.getData());
return fromCore(result, data);
}
}));
Spark.get("/api/items/info", (request, response) -> handle(request, response, "itemInfo", TIMEOUT_DEFAULT_MS, new ApiCallable() {
@Override
public ApiResult call(Request request) throws Exception {
AppConfig config = requestConfig(new LinkedHashMap<String, Object>());
CoreOperationResult<TfsItemInfo> result = coreService.getItemInfo(toTfsConfig(config), require(config.collection, "collection"), require(request.queryParams("serverPath"), "serverPath"));
Map<String, Object> data = new LinkedHashMap<String, Object>();
data.put("item", result.getData());
return fromCore(result, data);
}
}));
Spark.get("/api/pending-changes", (request, response) -> handle(request, response, "pendingChanges", TIMEOUT_DEFAULT_MS, new ApiCallable() {
@Override
public ApiResult call(Request request) throws Exception {
@@ -520,7 +688,7 @@ public class MacTfsServer {
public ApiResult call(Request request) throws Exception {
Map<String, Object> body = readBody(request);
AppConfig config = requestConfig(body);
CoreOperationResult<List<TfsFolderDiffItem>> result = coreService.compareFolder(toTfsConfig(config), require(config.collection, "collection"), require(config.workspace, "workspace"), require(stringValue(body, "serverPath"), "serverPath"), stringValue(body, "localPath"), booleanValue(body, "recursive", true));
CoreOperationResult<List<TfsFolderDiffItem>> result = coreService.compareFolder(toTfsConfig(config), require(config.collection, "collection"), require(config.workspace, "workspace"), require(stringValue(body, "serverPath"), "serverPath"), stringValue(body, "localPath"), booleanValue(body, "recursive", true), booleanValue(body, "includeLocalOnly", true));
Map<String, Object> data = new LinkedHashMap<String, Object>();
data.put("diffs", result.getData() == null ? Collections.emptyList() : result.getData());
return fromCore(result, data);
@@ -631,6 +799,7 @@ public class MacTfsServer {
*/
private String handle(Request request, Response response, String operation, long timeoutMs, ApiCallable callable) throws Exception {
long startedAt = System.currentTimeMillis();
String source = resolveSource(request);
ApiResult result;
Future<ApiResult> future = executorService.submit(new Callable<ApiResult>() {
@Override
@@ -654,10 +823,22 @@ public class MacTfsServer {
result.startedAt = startedAt;
result.endedAt = endedAt;
response.status(result.status);
logStore.add(operation, summarize(request), startedAt, endedAt, result);
logStore.add(operation, summarize(request), startedAt, endedAt, result, source);
return objectMapper.writeValueAsString(result);
}
/**
* 判定本次请求来源:mcp(AI 通过 MCP 调用)或 ui(桌面端手动操作)。
* 依据自定义请求头 X-MacTFS-Source;缺省或未知一律按 ui 处理,兼容未带该头的旧客户端。
*/
private String resolveSource(Request request) {
String raw = request.headers("X-MacTFS-Source");
if (raw != null && "mcp".equalsIgnoreCase(raw.trim())) {
return "mcp";
}
return "ui";
}
/**
* 从当前会话或配置文件读取连接配置,并允许请求体覆盖当前操作相关字段。
*/
@@ -1182,7 +1363,7 @@ public class MacTfsServer {
/**
* 追加一次 API 操作日志,记录开始、结束、耗时和失败原因。
*/
synchronized void add(String operation, String summary, long startedAt, long endedAt, ApiResult result) {
synchronized void add(String operation, String summary, long startedAt, long endedAt, ApiResult result, String source) {
OperationLogEntry entry = new OperationLogEntry();
entry.operation = operation;
entry.summary = summary;
@@ -1191,6 +1372,7 @@ public class MacTfsServer {
entry.durationMs = endedAt - startedAt;
entry.success = result.success;
entry.errorMessage = result.errorMessage;
entry.source = source;
logs.add(entry);
while (logs.size() > MAX_LOGS) {
logs.remove(0);
@@ -1213,5 +1395,7 @@ public class MacTfsServer {
public long durationMs;
public boolean success;
public String errorMessage;
/** 操作来源:mcp(AI)或 ui(手动)。 */
public String source;
}
}
+5
View File
@@ -5,3 +5,8 @@
# React Router
/.react-router/
/build/
# electron-builder 打包产物与生成的运行时(体积大,不入库)
/dist-app/
/runtime/
/build-resources/icon.iconset/
+8 -15
View File
@@ -1,21 +1,14 @@
# React Router + shadcn/ui
# mactfsui
This is a template for a new React Router project with React, TypeScript, and shadcn/ui.
macTFS 的 Electron + React 桌面前端。完整的项目介绍、截图、环境要求与使用说明请见仓库根目录的 [README](../README.md)。
## Adding components
To add components to your app, run the following command:
## 常用命令
```bash
npx shadcn@latest add button
pnpm install # 安装依赖
pnpm electron:dev # 开发模式(vite + Electron,自动拉起后端)
pnpm prepare:runtime # 准备 x64 JDK(本地缺失时自动从 Azul 下载)
pnpm dist # 打包 macOS 桌面应用到 dist-app/
```
This will place the ui components in the `components` directory.
## Using components
To use the components in your app, import them as follows:
```tsx
import { Button } from "@/components/ui/button";
```
启动 / 停止 / 重启 / 排错见根目录的 [`服务启停指南.md`](../服务启停指南.md)。
+84 -68
View File
@@ -1,13 +1,20 @@
@import "tailwindcss";
@import "tw-animate-css";
@import "shadcn/tailwind.css";
@import "@fontsource-variable/roboto-slab";
/* 应用只有亮色主题:保留 class 方案的 dark 变体定义,使组件库模板中残留的
dark: 工具类永远不会命中(根节点不再挂 .dark),避免回退到系统媒体查询。 */
@custom-variant dark (&:is(.dark *));
/*
* macOS 原生风设计基建(FE-026)
* 基调:系统字体 + macOS 蓝主色 + 中性灰分级 + 半透明材质(vibrancy)变量。
* 动效约定:快 150ms / 标准 220ms / 慢 320ms,缓动 ease-out-quart / spring 近似。
*/
@theme inline {
--font-heading: var(--font-serif);
--font-serif: 'Roboto Slab Variable', serif;
--font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
--font-heading: var(--font-sans);
--font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
--color-sidebar-ring: var(--sidebar-ring);
--color-sidebar-border: var(--sidebar-border);
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
@@ -39,6 +46,7 @@
--color-card: var(--card);
--color-foreground: var(--foreground);
--color-background: var(--background);
/* 圆角档位:macOS 常用 6/8/10/14px(--radius = 10px) */
--radius-sm: calc(var(--radius) * 0.6);
--radius-md: calc(var(--radius) * 0.8);
--radius-lg: var(--radius);
@@ -46,75 +54,63 @@
--radius-2xl: calc(var(--radius) * 1.8);
--radius-3xl: calc(var(--radius) * 2.2);
--radius-4xl: calc(var(--radius) * 2.6);
/* 阴影分层:卡片极轻 / 浮层轻 / 弹窗(Sheet)明显 */
--shadow-card: 0 0 0 0.5px rgb(0 0 0 / 0.03), 0 1px 1px rgb(0 0 0 / 0.04), 0 4px 14px rgb(0 0 0 / 0.06);
--shadow-overlay: 0 4px 16px rgb(0 0 0 / 0.1), 0 1px 3px rgb(0 0 0 / 0.06);
--shadow-dialog: 0 18px 50px rgb(0 0 0 / 0.22), 0 4px 12px rgb(0 0 0 / 0.1);
/* 缓动曲线 */
--ease-out-quart: cubic-bezier(0.25, 1, 0.5, 1);
--ease-spring: cubic-bezier(0.34, 1.3, 0.64, 1);
/* 反馈动效:表单错误抖动 */
--animate-shake: shake 0.4s var(--ease-out-quart);
@keyframes shake {
10%, 90% { transform: translateX(-1px); }
20%, 80% { transform: translateX(2px); }
30%, 50%, 70% { transform: translateX(-3px); }
40%, 60% { transform: translateX(3px); }
}
}
:root {
--background: oklch(1 0 0);
--foreground: oklch(0.145 0 0);
--background: oklch(0.98 0.002 286);
--foreground: oklch(0.22 0.006 286);
--card: oklch(1 0 0);
--card-foreground: oklch(0.145 0 0);
--card-foreground: oklch(0.22 0.006 286);
--popover: oklch(1 0 0);
--popover-foreground: oklch(0.145 0 0);
--primary: oklch(0.488 0.243 264.376);
--primary-foreground: oklch(0.97 0.014 254.604);
--secondary: oklch(0.967 0.001 286.375);
--secondary-foreground: oklch(0.21 0.006 285.885);
--muted: oklch(0.97 0 0);
--muted-foreground: oklch(0.556 0 0);
--accent: oklch(0.488 0.243 264.376);
--accent-foreground: oklch(0.97 0.014 254.604);
--destructive: oklch(0.577 0.245 27.325);
--border: oklch(0.922 0 0);
--input: oklch(0.922 0 0);
--ring: oklch(0.708 0 0);
--popover-foreground: oklch(0.22 0.006 286);
/* macOS 系统蓝(≈ #007AFF),仅用于主按钮、选中态、状态点 */
--primary: oklch(0.585 0.205 256.5);
--primary-foreground: oklch(0.99 0.002 286);
--secondary: oklch(0.957 0.004 286);
--secondary-foreground: oklch(0.22 0.006 286);
--muted: oklch(0.957 0.004 286);
--muted-foreground: oklch(0.55 0.012 285);
/* accent 为中性悬停底色 */
--accent: oklch(0.94 0.004 286);
--accent-foreground: oklch(0.22 0.006 286);
--destructive: oklch(0.59 0.24 27.5);
--border: oklch(0.905 0.004 286);
--input: oklch(0.905 0.004 286);
--ring: oklch(0.62 0.19 256.5);
--chart-1: oklch(0.809 0.105 251.813);
--chart-2: oklch(0.623 0.214 259.815);
--chart-3: oklch(0.546 0.245 262.881);
--chart-4: oklch(0.488 0.243 264.376);
--chart-5: oklch(0.424 0.199 265.638);
--radius: 0.875rem;
--sidebar: oklch(0.985 0 0);
--sidebar-foreground: oklch(0.145 0 0);
--sidebar-primary: oklch(0.546 0.245 262.881);
--sidebar-primary-foreground: oklch(0.97 0.014 254.604);
--sidebar-accent: oklch(0.97 0 0);
--sidebar-accent-foreground: oklch(0.205 0 0);
--sidebar-border: oklch(0.922 0 0);
--sidebar-ring: oklch(0.708 0 0);
}
.dark {
--background: oklch(0.145 0 0);
--foreground: oklch(0.985 0 0);
--card: oklch(0.205 0 0);
--card-foreground: oklch(0.985 0 0);
--popover: oklch(0.205 0 0);
--popover-foreground: oklch(0.985 0 0);
--primary: oklch(0.424 0.199 265.638);
--primary-foreground: oklch(0.97 0.014 254.604);
--secondary: oklch(0.274 0.006 286.033);
--secondary-foreground: oklch(0.985 0 0);
--muted: oklch(0.269 0 0);
--muted-foreground: oklch(0.708 0 0);
--accent: oklch(0.424 0.199 265.638);
--accent-foreground: oklch(0.97 0.014 254.604);
--destructive: oklch(0.704 0.191 22.216);
--border: oklch(1 0 0 / 10%);
--input: oklch(1 0 0 / 15%);
--ring: oklch(0.556 0 0);
--chart-1: oklch(0.809 0.105 251.813);
--chart-2: oklch(0.623 0.214 259.815);
--chart-3: oklch(0.546 0.245 262.881);
--chart-4: oklch(0.488 0.243 264.376);
--chart-5: oklch(0.424 0.199 265.638);
--sidebar: oklch(0.205 0 0);
--sidebar-foreground: oklch(0.985 0 0);
--sidebar-primary: oklch(0.623 0.214 259.815);
--sidebar-primary-foreground: oklch(0.97 0.014 254.604);
--sidebar-accent: oklch(0.269 0 0);
--sidebar-accent-foreground: oklch(0.985 0 0);
--sidebar-border: oklch(1 0 0 / 10%);
--sidebar-ring: oklch(0.556 0 0);
--chart-2: oklch(0.7 0.165 254);
--chart-3: oklch(0.585 0.205 256.5);
--chart-4: oklch(0.5 0.21 259);
--chart-5: oklch(0.43 0.19 262);
--radius: 0.625rem;
/* 侧栏半透明材质:vibrancy 开启时透出窗口毛玻璃,关闭时回退近实色 */
--sidebar: oklch(0.962 0.003 286 / 72%);
--sidebar-foreground: oklch(0.22 0.006 286);
--sidebar-primary: oklch(0.585 0.205 256.5);
--sidebar-primary-foreground: oklch(0.99 0.002 286);
--sidebar-accent: oklch(0.88 0.005 286 / 80%);
--sidebar-border: oklch(0.89 0.004 286);
--sidebar-ring: oklch(0.62 0.19 256.5);
/* 动效时长:快 / 标准 / 慢 */
--motion-fast: 150ms;
--motion-base: 220ms;
--motion-slow: 320ms;
}
@layer base {
@@ -125,6 +121,26 @@
@apply bg-background text-foreground;
}
html {
@apply font-serif;
@apply font-sans;
}
}
}
/* vibrancy 模式(FE-027 在 macOS Electron 下挂载):页面底透明,毛玻璃从半透明侧栏透出 */
html.vibrancy,
html.vibrancy body {
background: transparent;
}
/* 工作台画布底色:比卡片深一档的中性灰,让白色卡片浮起;vibrancy 下半透明透出窗口毛玻璃。 */
@utility canvas-surface {
background-color: oklch(0.934 0.004 286 / 0.85);
}
/* 隐藏式标题栏下的窗口拖拽区域:顶栏整体可拖动,交互控件单独豁免。 */
@utility app-drag {
-webkit-app-region: drag;
}
@utility app-no-drag {
-webkit-app-region: no-drag;
}
+282 -122
View File
@@ -1,10 +1,13 @@
import { useCallback, useEffect, useState, type ChangeEvent } from "react"
import { Check, Clock3, Eye, EyeOff, Loader2 } from "lucide-react"
import { Button } from "~/components/ui/button"
import { Input } from "~/components/ui/input"
import { Label } from "~/components/ui/label"
import { api } from "~/lib/api"
import type { AppConfig, Collection } from "~/lib/api"
import { getServiceStatus } from "~/lib/electron"
import { loadRecentServers, saveRecentServer, type RecentServer } from "~/lib/recent-servers"
import type { WorkspaceSession } from "~/lib/tfs/session"
import { cn } from "~/lib/utils"
@@ -28,6 +31,7 @@ const EMPTY_FORM: ConnectFormState = {
/**
* 连接入口:连接 TFS、加载并确认 Collection、确保默认 Workspace,成功后回调固定上下文。
* macOS 风:左侧毛玻璃品牌区(大 logo + 一句话),右侧表单,带分阶段过渡与最近连接。
*/
export function ConnectView({ onReady }: { onReady: (session: WorkspaceSession) => void }) {
const [phase, setPhase] = useState<ConnectPhase>("form")
@@ -37,9 +41,15 @@ export function ConnectView({ onReady }: { onReady: (session: WorkspaceSession)
const [busy, setBusy] = useState(false)
const [busyText, setBusyText] = useState("")
const [error, setError] = useState<string | null>(null)
const [showPassword, setShowPassword] = useState(false)
const [recent, setRecent] = useState<RecentServer[]>([])
const [serviceOk, setServiceOk] = useState<boolean | null>(null)
// 每次失败自增,作为 key 触发表单抖动动画重放。
const [shakeCount, setShakeCount] = useState(0)
useEffect(() => {
let active = true
setRecent(loadRecentServers())
void (async () => {
const result = await api.getConfig()
if (!active) {
@@ -58,6 +68,12 @@ export function ConnectView({ onReady }: { onReady: (session: WorkspaceSession)
}
}
})()
void (async () => {
const status = await getServiceStatus()
if (active) {
setServiceOk(status.running)
}
})()
return () => {
active = false
}
@@ -71,6 +87,27 @@ export function ConnectView({ onReady }: { onReady: (session: WorkspaceSession)
setForm((prev) => ({ ...prev, [key]: value }))
}
/**
* 失败统一处理:展示错误条并触发表单抖动。
*/
const failWith = useCallback((message: string) => {
setError(message)
setShakeCount((count) => count + 1)
}, [])
/**
* 用一条最近连接记录填充表单(不含密码)。
*/
const applyRecent = useCallback((item: RecentServer) => {
setError(null)
setForm((prev) => ({
...prev,
serverUri: item.serverUri,
domain: item.domain,
username: item.username,
}))
}, [])
/**
* 连接 TFS 并加载当前账号可见的 Collection 列表。
*/
@@ -88,23 +125,30 @@ export function ConnectView({ onReady }: { onReady: (session: WorkspaceSession)
const connectResult = await api.connect(payload)
if (!connectResult.ok) {
setBusy(false)
setError(connectResult.errorMessage ?? "连接失败")
failWith(connectResult.errorMessage ?? "连接失败")
return
}
setBusyText("正在加载 Collection…")
const collectionsResult = await api.listCollections()
setBusy(false)
if (!collectionsResult.ok) {
setError(collectionsResult.errorMessage ?? "加载 Collection 失败")
failWith(collectionsResult.errorMessage ?? "加载 Collection 失败")
return
}
setRecent(
saveRecentServer({
serverUri: form.serverUri.trim(),
domain: form.domain.trim(),
username: form.username.trim(),
}),
)
const list = collectionsResult.data?.collections ?? []
setCollections(list)
setSelectedCollection((prev) =>
list.some((item) => item.name === prev) ? prev : list[0]?.name ?? "",
)
setPhase("collection")
}, [form])
}, [form, failWith])
/**
* 确认 Collection 后确保默认 Workspace,并把固定上下文回调给上层。
@@ -120,7 +164,7 @@ export function ConnectView({ onReady }: { onReady: (session: WorkspaceSession)
setBusy(false)
const workspace = ensureResult.data?.workspace
if (!ensureResult.ok || !workspace) {
setError(ensureResult.errorMessage ?? "确保 Workspace 失败")
failWith(ensureResult.errorMessage ?? "确保 Workspace 失败")
return
}
onReady({
@@ -129,7 +173,7 @@ export function ConnectView({ onReady }: { onReady: (session: WorkspaceSession)
workspace: workspace.name,
mappings: workspace.mappings ?? [],
})
}, [selectedCollection, form.serverUri, onReady])
}, [selectedCollection, form.serverUri, onReady, failWith])
const canConnect =
form.serverUri.trim().length > 0 &&
@@ -137,131 +181,247 @@ export function ConnectView({ onReady }: { onReady: (session: WorkspaceSession)
form.password.length > 0
return (
<div className="flex min-h-svh items-center justify-center bg-muted/40 p-6">
<div className="w-full max-w-md rounded-lg border bg-background p-6 shadow-sm">
<div className="space-y-1">
<h1 className="text-base font-semibold">macTFS</h1>
<p className="text-sm text-muted-foreground">
{phase === "form" ? "连接 TFS 服务器" : "选择 Collection"}
</p>
<div className="relative flex min-h-svh">
{/* 隐藏式标题栏下登录页的窗口拖拽区 */}
<div className="app-drag absolute inset-x-0 top-0 z-10 h-10" />
{/* 左侧品牌区:半透明材质(vibrancy 下呈毛玻璃),大 logo + 一句话 */}
<aside className="relative hidden w-[42%] max-w-md min-w-80 flex-col border-r bg-sidebar md:flex">
<div className="flex flex-1 flex-col items-center justify-center gap-5 p-10">
<img src="/logo.png" alt="MacTFS" className="size-24 drop-shadow-2xl" />
<div className="text-center">
<p className="text-2xl font-semibold tracking-tight">MacTFS</p>
<p className="mt-1.5 text-sm text-muted-foreground">macOS 上的 TFS 源码管理工作台</p>
</div>
</div>
{phase === "form" && (
<form
className="mt-5 space-y-3"
onSubmit={(event) => {
event.preventDefault()
if (canConnect && !busy) {
void handleConnect()
}
}}
>
<div className="space-y-1.5">
<Label htmlFor="serverUri">服务器地址</Label>
<Input
id="serverUri"
placeholder="http://tfs.example.com:8080/tfs"
value={form.serverUri}
onChange={updateField("serverUri")}
disabled={busy}
/>
</div>
<div className="space-y-1.5">
<Label htmlFor="domain">域(可选)</Label>
<Input
id="domain"
placeholder="DOMAIN"
value={form.domain}
onChange={updateField("domain")}
disabled={busy}
/>
</div>
<div className="space-y-1.5">
<Label htmlFor="username">用户名</Label>
<Input
id="username"
autoComplete="username"
value={form.username}
onChange={updateField("username")}
disabled={busy}
/>
</div>
<div className="space-y-1.5">
<Label htmlFor="password">密码</Label>
<Input
id="password"
type="password"
autoComplete="current-password"
value={form.password}
onChange={updateField("password")}
disabled={busy}
/>
</div>
{error && <p className="text-sm text-destructive">{error}</p>}
<Button type="submit" className="w-full" disabled={!canConnect || busy}>
{busy ? busyText || "处理中…" : "连接 TFS"}
</Button>
</form>
)}
{phase === "collection" && (
<div className="mt-5 space-y-4">
{collections.length === 0 ? (
<p className="text-sm text-muted-foreground">当前账号没有可见的 Collection。</p>
) : (
<ul className="max-h-64 space-y-1 overflow-y-auto">
{collections.map((collection) => {
const active = collection.name === selectedCollection
return (
<li key={collection.id || collection.name}>
<button
type="button"
onClick={() => setSelectedCollection(collection.name)}
disabled={busy}
className={cn(
"flex w-full items-center justify-between rounded-md border px-3 py-2 text-left text-sm transition-colors",
active
? "border-primary bg-primary/10 text-foreground"
: "border-border bg-background hover:bg-muted",
)}
>
<span className="font-medium">{collection.name}</span>
{active && <span className="text-xs text-primary">已选择</span>}
</button>
</li>
)
})}
</ul>
<div className="flex items-center gap-2 p-6 text-xs text-muted-foreground">
<span
className={cn(
"size-1.5 rounded-full",
serviceOk == null ? "bg-muted-foreground/50" : serviceOk ? "bg-emerald-500" : "bg-red-500",
)}
/>
{serviceOk == null
? "正在检测本地服务…"
: serviceOk
? "本地服务运行中 · 127.0.0.1:38765"
: "本地服务未就绪"}
</div>
</aside>
{error && <p className="text-sm text-destructive">{error}</p>}
{/* 右侧表单区 */}
<main className="flex flex-1 items-center justify-center bg-background p-6">
<div className="w-full max-w-sm">
{phase === "form" && (
<div
key={`form-${shakeCount}`}
className={cn(
"animate-in fade-in slide-in-from-left-2 duration-200",
error != null && "animate-shake",
)}
>
<div className="space-y-1">
<h1 className="text-xl font-semibold tracking-tight">连接 TFS</h1>
<p className="text-sm text-muted-foreground">
使用域账号连接 Team Foundation Server
</p>
</div>
<div className="flex items-center justify-between gap-2">
<Button
type="button"
variant="ghost"
size="sm"
onClick={() => {
setError(null)
setPhase("form")
<form
className="mt-6 space-y-4"
onSubmit={(event) => {
event.preventDefault()
if (canConnect && !busy) {
void handleConnect()
}
}}
disabled={busy}
>
返回
</Button>
<Button
type="button"
onClick={() => void handleEnter()}
disabled={busy || !selectedCollection}
>
{busy ? busyText || "处理中…" : "进入工作台"}
</Button>
<div className="space-y-1.5">
<Label htmlFor="serverUri">服务器地址</Label>
<Input
id="serverUri"
placeholder="http://tfs.example.com:8080/tfs"
value={form.serverUri}
onChange={updateField("serverUri")}
disabled={busy}
/>
</div>
<div className="grid grid-cols-2 gap-3">
<div className="space-y-1.5">
<Label htmlFor="domain">域(可选)</Label>
<Input
id="domain"
placeholder="DOMAIN"
value={form.domain}
onChange={updateField("domain")}
disabled={busy}
/>
</div>
<div className="space-y-1.5">
<Label htmlFor="username">用户名</Label>
<Input
id="username"
autoComplete="username"
value={form.username}
onChange={updateField("username")}
disabled={busy}
/>
</div>
</div>
<div className="space-y-1.5">
<Label htmlFor="password">密码</Label>
<div className="relative">
<Input
id="password"
type={showPassword ? "text" : "password"}
autoComplete="current-password"
className="pr-9"
value={form.password}
onChange={updateField("password")}
disabled={busy}
/>
<button
type="button"
tabIndex={-1}
onClick={() => setShowPassword((prev) => !prev)}
className="absolute top-1/2 right-2 -translate-y-1/2 rounded-sm p-1 text-muted-foreground transition-colors duration-150 hover:text-foreground"
aria-label={showPassword ? "隐藏密码" : "显示密码"}
>
{showPassword ? <Eye className="size-4" /> : <EyeOff className="size-4" />}
</button>
</div>
</div>
{error && (
<p className="rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-sm text-destructive">
{error}
</p>
)}
<Button type="submit" className="w-full" disabled={!canConnect || busy}>
{busy && <Loader2 className="size-4 animate-spin" />}
{busy ? busyText || "处理中…" : "连接 TFS"}
</Button>
</form>
{recent.length > 0 && (
<div className="mt-6 space-y-2">
<p className="flex items-center gap-1.5 text-xs text-muted-foreground">
<Clock3 className="size-3.5" />
最近连接
</p>
<ul className="space-y-1.5">
{recent.map((item) => (
<li key={`${item.serverUri}-${item.username}`}>
<button
type="button"
onClick={() => applyRecent(item)}
disabled={busy}
className="flex w-full items-center justify-between gap-2 rounded-md border bg-card px-3 py-2 text-left shadow-card transition-colors duration-150 hover:bg-muted/60"
>
<span className="min-w-0">
<span className="block truncate font-mono text-xs">
{item.serverUri}
</span>
<span className="block text-xs text-muted-foreground">
{item.domain ? `${item.domain} \\ ` : ""}
{item.username}
</span>
</span>
<span className="shrink-0 text-xs text-primary">填充</span>
</button>
</li>
))}
</ul>
</div>
)}
</div>
</div>
)}
</div>
)}
{phase === "collection" && (
<div
key={`collection-${shakeCount}`}
className={cn(
"animate-in fade-in slide-in-from-right-4 duration-200",
error != null && "animate-shake",
)}
>
<div className="space-y-1">
<h1 className="text-xl font-semibold tracking-tight">选择 Collection</h1>
<p className="text-sm text-muted-foreground">
已连接 <span className="font-mono text-xs">{form.serverUri.trim()}</span>
</p>
</div>
<div className="mt-6 space-y-4">
{collections.length === 0 ? (
<p className="rounded-md border bg-card px-3 py-6 text-center text-sm text-muted-foreground">
当前账号没有可见的 Collection。
</p>
) : (
<ul className="max-h-72 space-y-2 overflow-y-auto">
{collections.map((collection) => {
const active = collection.name === selectedCollection
return (
<li key={collection.id || collection.name}>
<button
type="button"
onClick={() => setSelectedCollection(collection.name)}
disabled={busy}
className={cn(
"flex w-full items-center justify-between rounded-lg border px-3.5 py-3 text-left text-sm transition-colors duration-150",
active
? "border-primary/60 bg-primary/5"
: "bg-card shadow-card hover:bg-muted/60",
)}
>
<span className={cn(active && "font-medium")}>{collection.name}</span>
{active && (
<span className="animate-in zoom-in-75 fade-in flex size-4.5 items-center justify-center rounded-full bg-primary text-primary-foreground duration-150">
<Check className="size-3" />
</span>
)}
</button>
</li>
)
})}
</ul>
)}
{error && (
<p className="rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-sm text-destructive">
{error}
</p>
)}
<div className="flex items-center justify-between gap-2">
<Button
type="button"
variant="ghost"
size="sm"
onClick={() => {
setError(null)
setPhase("form")
}}
disabled={busy}
>
返回
</Button>
<Button
type="button"
onClick={() => void handleEnter()}
disabled={busy || !selectedCollection}
>
{busy && <Loader2 className="size-4 animate-spin" />}
{busy ? busyText || "处理中…" : "进入工作台"}
</Button>
</div>
</div>
</div>
)}
</div>
</main>
</div>
)
}
@@ -0,0 +1,196 @@
import { useCallback, useEffect, useRef, useState } from "react"
import { RefreshCw } from "lucide-react"
import { Badge } from "~/components/ui/badge"
import { Button } from "~/components/ui/button"
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "~/components/ui/dialog"
import { ScrollArea } from "~/components/ui/scroll-area"
import { getMcpLogs, getMcpStatus } from "~/lib/electron"
import type { McpLogEntry, McpStatus } from "~/lib/electron"
import { cn } from "~/lib/utils"
// 弹窗打开时的自动刷新间隔(毫秒)。
const REFRESH_INTERVAL_MS = 2000
/**
* 把毫秒时间戳格式化为 HH:mm:ss,供日志行展示。
*/
function formatLogTime(value: number): string {
const date = new Date(value)
const pad = (input: number) => String(input).padStart(2, "0")
return `${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`
}
/**
* 把运行时长(毫秒)格式化为 Xs / Xm Ys / Xh Ym。
*/
function formatUptime(ms: number): string {
if (ms <= 0) {
return "—"
}
const totalSeconds = Math.floor(ms / 1000)
const seconds = totalSeconds % 60
const minutes = Math.floor(totalSeconds / 60) % 60
const hours = Math.floor(totalSeconds / 3600)
if (hours > 0) {
return `${hours}h ${minutes}m`
}
if (minutes > 0) {
return `${minutes}m ${seconds}s`
}
return `${seconds}s`
}
/**
* MCP 服务状态弹窗:展示子进程运行状态(运行中 / healthz 探活 / pid / 运行时长 /
* 重启次数 / 上次退出码)与最近 500 行运行日志。打开期间每 2 秒自动刷新,日志自动滚到底部。
*/
export function McpStatusDialog({ onClose }: { onClose: () => void }) {
const [status, setStatus] = useState<McpStatus | null>(null)
const [logs, setLogs] = useState<McpLogEntry[]>([])
const [loading, setLoading] = useState(true)
const logEndRef = useRef<HTMLDivElement | null>(null)
const refresh = useCallback(async () => {
const [nextStatus, nextLogs] = await Promise.all([getMcpStatus(), getMcpLogs()])
setStatus(nextStatus)
setLogs(nextLogs)
setLoading(false)
}, [])
useEffect(() => {
void refresh()
const timer = setInterval(() => void refresh(), REFRESH_INTERVAL_MS)
return () => clearInterval(timer)
}, [refresh])
// 日志更新后滚到底部,始终看到最新输出。
useEffect(() => {
logEndRef.current?.scrollIntoView({ block: "end" })
}, [logs])
const running = status?.running ?? false
const healthy = status?.healthy ?? false
return (
<Dialog open onOpenChange={(open) => !open && onClose()}>
<DialogContent className="flex max-h-[80svh] flex-col sm:max-w-3xl">
<DialogHeader>
<DialogTitle>MCP 服务状态</DialogTitle>
<DialogDescription className="font-mono text-xs">
{status?.sseUrl ?? "http://127.0.0.1:38766/sse"}
</DialogDescription>
</DialogHeader>
{/* 状态摘要 */}
<div className="grid shrink-0 grid-cols-2 gap-x-6 gap-y-2 rounded-lg border bg-muted/30 px-4 py-3 text-xs sm:grid-cols-3">
<StatusItem label="进程">
{running ? (
<Badge variant="default">运行中</Badge>
) : (
<Badge variant="destructive">已停止</Badge>
)}
</StatusItem>
<StatusItem label="探活 /healthz">
<span className="inline-flex items-center gap-1.5">
<span
className={cn(
"size-2 rounded-full",
healthy ? "bg-emerald-500" : "bg-red-500",
)}
/>
{healthy ? "可达" : "不可达"}
</span>
</StatusItem>
<StatusItem label="PID">
<span className="font-mono">{status?.pid ?? "—"}</span>
</StatusItem>
<StatusItem label="运行时长">
<span className="font-mono">{formatUptime(status?.uptimeMs ?? 0)}</span>
</StatusItem>
<StatusItem label="重启次数">
<span className="font-mono">{status?.restartCount ?? 0}</span>
</StatusItem>
<StatusItem label="上次退出码">
<span className="font-mono">{status?.lastExitCode ?? "—"}</span>
</StatusItem>
</div>
{status?.lastError && (
<p className="shrink-0 rounded-md bg-destructive/10 px-3 py-1.5 text-xs text-destructive">
{status.lastError}
</p>
)}
{!status?.entryResolved && (
<p className="shrink-0 rounded-md bg-amber-500/10 px-3 py-1.5 text-xs text-amber-600">
未找到 MCP 入口(开发态请先在 mactfs-mcp 执行 pnpm build)。
</p>
)}
{/* 运行日志 */}
<div className="flex min-h-0 flex-1 flex-col overflow-hidden rounded-lg border">
<div className="flex h-8 shrink-0 items-center gap-2 border-b bg-muted/40 px-3">
<span className="text-[11px] font-medium tracking-wider text-muted-foreground uppercase">
运行日志
</span>
<span className="ml-auto text-xs text-muted-foreground">
{logs.length > 0 && `${logs.length} 行`}
</span>
</div>
<ScrollArea className="min-h-0 flex-1">
{logs.length === 0 ? (
<p className="px-3 py-2 text-xs text-muted-foreground">
{loading ? "正在加载日志…" : "暂无日志输出"}
</p>
) : (
<div className="px-3 py-1.5 font-mono text-[11px] leading-relaxed">
{logs.map((entry, index) => (
<div
key={`${entry.ts}-${index}`}
className={cn(
"flex gap-2 whitespace-pre-wrap break-all",
entry.stream === "stderr" ? "text-destructive" : "text-foreground/80",
)}
>
<span className="shrink-0 text-muted-foreground">{formatLogTime(entry.ts)}</span>
<span className="min-w-0">{entry.line}</span>
</div>
))}
<div ref={logEndRef} />
</div>
)}
</ScrollArea>
</div>
<DialogFooter>
<Button variant="ghost" size="sm" onClick={() => void refresh()} disabled={loading}>
<RefreshCw className={cn(loading && "animate-spin")} />
刷新
</Button>
<Button variant="ghost" size="sm" onClick={onClose}>
关闭
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
)
}
/**
* 状态摘要中的单项:上方标签、下方值。
*/
function StatusItem({ label, children }: { label: string; children: React.ReactNode }) {
return (
<div className="flex flex-col gap-1">
<span className="text-[11px] text-muted-foreground">{label}</span>
<span className="text-foreground">{children}</span>
</div>
)
}
+121 -23
View File
@@ -1,11 +1,18 @@
import { PanelBottom, PanelLeft, PanelRight } from "lucide-react"
import { Activity, FolderCog, Loader2, PanelBottom, PanelLeft, PanelRight, PlugZap, Unplug } from "lucide-react"
import { useCallback, useState } from "react"
import { Button } from "~/components/ui/button"
import { Separator } from "~/components/ui/separator"
import { Tooltip, TooltipContent, TooltipTrigger } from "~/components/ui/tooltip"
import { showToast } from "~/components/ui/toaster"
import { api } from "~/lib/api"
import { isMacElectron } from "~/lib/platform"
import type { WorkspaceSession } from "~/lib/tfs/session"
import { cn } from "~/lib/utils"
// 顶栏 TFS 连接测试的四态:未测 / 测试中 / 正常 / 断开。
type TfsTestStatus = "idle" | "testing" | "ok" | "fail"
// 三个可折叠面板的显隐状态,由 WorkspaceShell 持有。
export interface PanelVisibility {
tree: boolean
@@ -14,40 +21,86 @@ export interface PanelVisibility {
}
/**
* 顶部上下文栏:展示固定的 Server / Collection / Workspace 上下文,
* 以及面板折叠开关与重新连接入口,不承载对象级操作。
* 顶部上下文栏:仿 Finder 的居中上下文胶囊展示 Collection / Workspace
* (悬停查看服务器地址),右侧为面板折叠开关与重新连接入口,不承载对象级操作。
*/
export function TopBar({
session,
panels,
onTogglePanel,
onReconnect,
onManageWorkspace,
onOpenMcpStatus,
}: {
session: WorkspaceSession
panels: PanelVisibility
onTogglePanel: (panel: keyof PanelVisibility) => void
onReconnect: () => void
onManageWorkspace: () => void
onOpenMcpStatus: () => void
}) {
// 隐藏式标题栏下顶栏整体作为拖拽区,并为左上角红绿灯预留空间。
const macInset = isMacElectron()
// 连接测试状态:手动触发,真正回连一次 TFS,结果走右上角 toast + 图标变色。
const [tfsStatus, setTfsStatus] = useState<TfsTestStatus>("idle")
const runTfsTest = useCallback(async () => {
setTfsStatus("testing")
showToast({ id: "tfs-test", kind: "loading", text: "正在测试 TFS 连接…" })
const resp = await api.testTfsConnection()
if (resp.ok) {
setTfsStatus("ok")
const ms = resp.data?.coreDurationMs
showToast({
id: "tfs-test",
kind: "success",
text: typeof ms === "number" ? `TFS 连接正常(${ms}ms)` : "TFS 连接正常",
})
} else {
setTfsStatus("fail")
showToast({ id: "tfs-test", kind: "error", text: `TFS 连接失败:${resp.errorMessage ?? "未知错误"}` })
}
}, [])
const tfsTestTip =
tfsStatus === "testing"
? "正在测试 TFS 连接…"
: tfsStatus === "ok"
? "TFS 连接正常,点击重新测试"
: tfsStatus === "fail"
? "TFS 连接异常,点击重新测试"
: "测试 TFS 连接"
return (
<header className="flex h-12 shrink-0 items-center justify-between gap-3 border-b bg-background px-3">
<div className="flex min-w-0 items-center gap-2 text-sm">
<span className="shrink-0 font-semibold">macTFS</span>
<Separator orientation="vertical" className="h-4!" />
<span className="hidden shrink-0 text-xs text-muted-foreground lg:inline">
服务器
</span>
<span className="hidden max-w-56 truncate font-mono text-xs lg:inline">
{session.serverUri}
</span>
<Separator orientation="vertical" className="hidden h-4! lg:block" />
<span className="shrink-0 text-xs text-muted-foreground">Collection</span>
<span className="max-w-40 truncate text-xs font-medium">{session.collection}</span>
<Separator orientation="vertical" className="h-4!" />
<span className="shrink-0 text-xs text-muted-foreground">Workspace</span>
<span className="max-w-44 truncate font-mono text-xs">{session.workspace}</span>
<header
className={cn(
"app-drag flex h-12 shrink-0 items-center justify-between gap-3 px-3",
macInset && "pl-20",
)}
>
{/* 左侧:程序名 + Collection 胶囊;服务器地址与工作区收进悬停提示 */}
<div className="flex min-w-0 items-center gap-2.5">
<span className="shrink-0 text-sm font-medium">MacTFS</span>
<Tooltip>
<TooltipTrigger asChild>
<div className="app-no-drag flex h-7 min-w-0 items-center rounded-lg bg-foreground/5 px-3 text-xs text-muted-foreground transition-colors hover:bg-foreground/8 hover:text-foreground">
<span className="truncate">{session.collection}</span>
</div>
</TooltipTrigger>
<TooltipContent side="bottom" className="text-xs">
<div className="space-y-0.5">
<p>
服务器 <span className="font-mono">{session.serverUri}</span>
</p>
<p>
工作区 <span className="font-mono">{session.workspace}</span>
</p>
</div>
</TooltipContent>
</Tooltip>
</div>
<div className="flex shrink-0 items-center gap-1">
<div className="app-no-drag flex shrink-0 items-center gap-1">
<PanelToggle
label="源码目录面板"
active={panels.tree}
@@ -70,9 +123,54 @@ export function TopBar({
<PanelBottom />
</PanelToggle>
<Separator orientation="vertical" className="mx-1 h-4!" />
<Button size="sm" variant="outline" onClick={onReconnect}>
重新连接
</Button>
<Tooltip>
<TooltipTrigger asChild>
<Button
size="icon-sm"
variant="ghost"
onClick={runTfsTest}
disabled={tfsStatus === "testing"}
aria-label="测试 TFS 连接"
>
{tfsStatus === "testing" ? (
<Loader2 className="animate-spin" />
) : (
<PlugZap
className={cn(
tfsStatus === "ok" && "text-emerald-500",
tfsStatus === "fail" && "text-red-500",
tfsStatus === "idle" && "text-muted-foreground",
)}
/>
)}
</Button>
</TooltipTrigger>
<TooltipContent side="bottom">{tfsTestTip}</TooltipContent>
</Tooltip>
<Tooltip>
<TooltipTrigger asChild>
<Button size="icon-sm" variant="ghost" onClick={onOpenMcpStatus} aria-label="MCP 服务状态">
<Activity />
</Button>
</TooltipTrigger>
<TooltipContent side="bottom">MCP 服务状态与日志</TooltipContent>
</Tooltip>
<Tooltip>
<TooltipTrigger asChild>
<Button size="icon-sm" variant="ghost" onClick={onManageWorkspace} aria-label="工作区与映射管理">
<FolderCog />
</Button>
</TooltipTrigger>
<TooltipContent side="bottom">工作区与映射管理</TooltipContent>
</Tooltip>
<Tooltip>
<TooltipTrigger asChild>
<Button size="icon-sm" variant="ghost" onClick={onReconnect} aria-label="重新连接">
<Unplug />
</Button>
</TooltipTrigger>
<TooltipContent side="bottom">重新连接</TooltipContent>
</Tooltip>
</div>
</header>
)
@@ -1,10 +1,16 @@
import { ConfirmDialog } from "~/components/app/confirm-dialog"
import { AddFilesDialog } from "~/components/explorer/add-files-dialog"
import { BranchDialog } from "~/components/explorer/branch-dialog"
import { CompareDialog } from "~/components/explorer/compare-dialog"
import { ConflictDialog } from "~/components/explorer/conflict-dialog"
import { DiffDialog } from "~/components/explorer/diff-dialog"
import { FileViewDialog } from "~/components/explorer/file-view-dialog"
import { GetVersionDialog } from "~/components/explorer/get-version-dialog"
import { HistoryDialog } from "~/components/explorer/history-dialog"
import { MappingDialog } from "~/components/explorer/mapping-dialog"
import { MergeDialog } from "~/components/explorer/merge-dialog"
import { PropertiesDialog } from "~/components/explorer/properties-dialog"
import { RenameDialog } from "~/components/explorer/rename-dialog"
import type { WorkspaceDialogState } from "~/hooks/use-file-actions"
import type { MappingInfo } from "~/lib/api"
import type { FileActionId, FileTarget } from "~/lib/tfs"
@@ -23,6 +29,11 @@ export function WorkspaceDialogs({
onConflictsResolved,
onForceGetConfirmed,
onGetVersion,
onRenameConfirmed,
onRollback,
onBranchConfirmed,
onMergeConfirmed,
onAddFilesConfirmed,
}: {
dialog: WorkspaceDialogState
mappings: MappingInfo[]
@@ -33,6 +44,19 @@ export function WorkspaceDialogs({
onConflictsResolved: () => void
onForceGetConfirmed: (serverPath: string, folder: boolean) => Promise<void>
onGetVersion: (serverPath: string, changeset: number, folder: boolean) => Promise<boolean>
onRenameConfirmed: (serverPath: string, newName: string) => Promise<boolean>
onRollback: (serverPath: string, mode: "single" | "toVersion", changeset: number) => Promise<boolean>
onBranchConfirmed: (
sourceServerPath: string,
targetServerPath: string,
changeset: number | undefined,
) => Promise<boolean>
onMergeConfirmed: (
sourceServerPath: string,
targetServerPath: string,
changeset: number | undefined,
) => Promise<boolean>
onAddFilesConfirmed: (localPaths: string[]) => Promise<boolean>
}) {
if (!dialog) {
return null
@@ -59,6 +83,7 @@ export function WorkspaceDialogs({
})
}
onGetVersion={onGetVersion}
onRollback={onRollback}
/>
)
case "compare":
@@ -89,6 +114,56 @@ export function WorkspaceDialogs({
onResolved={onConflictsResolved}
/>
)
case "properties":
return <PropertiesDialog target={dialog.target} onClose={onClose} />
case "rename":
return (
<RenameDialog
serverPath={dialog.serverPath}
folder={dialog.folder}
onConfirm={(newName) => onRenameConfirmed(dialog.serverPath, newName)}
onClose={onClose}
/>
)
case "branch":
return (
<BranchDialog
sourceServerPath={dialog.serverPath}
mappings={mappings}
onConfirm={(targetServerPath, changeset) =>
onBranchConfirmed(dialog.serverPath, targetServerPath, changeset)
}
onClose={onClose}
/>
)
case "merge":
return (
<MergeDialog
sourceServerPath={dialog.serverPath}
mappings={mappings}
onMerge={(targetServerPath, changeset) =>
onMergeConfirmed(dialog.serverPath, targetServerPath, changeset)
}
onClose={onClose}
/>
)
case "addFiles":
return (
<AddFilesDialog
serverPath={dialog.serverPath}
onConfirm={onAddFilesConfirmed}
onClose={onClose}
/>
)
case "getVersion":
return (
<GetVersionDialog
serverPath={dialog.serverPath}
folder={dialog.folder}
onConfirm={(changeset) => onGetVersion(dialog.serverPath, changeset, dialog.folder)}
onClose={onClose}
/>
)
case "confirmForceGet":
return (
<ConfirmDialog
+67 -22
View File
@@ -1,11 +1,14 @@
import { useCallback, useState } from "react"
import { useCallback, useEffect, useState } from "react"
import { McpStatusDialog } from "~/components/app/mcp-status-dialog"
import { TopBar, type PanelVisibility } from "~/components/app/top-bar"
import { WorkspaceDialogs } from "~/components/app/workspace-dialogs"
import { FolderItemsPanel } from "~/components/explorer/folder-items-panel"
import { SourceTreePanel } from "~/components/explorer/source-tree-panel"
import { WorkspaceManageDialog } from "~/components/explorer/workspace-manage-dialog"
import { ChangesPanel } from "~/components/inspector/changes-panel"
import { ConsolePanel } from "~/components/logs/console-panel"
import { Toaster, showToast } from "~/components/ui/toaster"
import { TooltipProvider } from "~/components/ui/tooltip"
import { useFileActions } from "~/hooks/use-file-actions"
import { usePendingChanges } from "~/hooks/use-pending-changes"
@@ -38,6 +41,10 @@ export function WorkspaceShell({
// 中间列表 / 底部日志刷新令牌:文件操作完成后递增触发重新加载。
const [itemsRefreshToken, setItemsRefreshToken] = useState(0)
const [logsRefreshToken, setLogsRefreshToken] = useState(0)
// 工作区集中管理弹窗显隐。
const [manageOpen, setManageOpen] = useState(false)
// MCP 状态弹窗显隐。
const [mcpOpen, setMcpOpen] = useState(false)
/**
* 切换指定面板的展开 / 收起状态。
@@ -68,34 +75,40 @@ export function WorkspaceShell({
refreshLogs,
})
// 把动作编排的 notice 转成右上角 toast:固定 id 让「正在…」与结果复用同一条目。
useEffect(() => {
if (!actions.notice) {
return
}
const { kind, text } = actions.notice
showToast({
id: "action",
kind: kind === "error" ? "error" : text.startsWith("正在") ? "loading" : "success",
text,
})
}, [actions.notice])
return (
<TooltipProvider>
<div className="flex h-svh flex-col overflow-hidden bg-background">
{/* 毛玻璃画布 + 卡片化面板:半透明画布透出 vibrancy,四个面板为圆角卡片留缝隙 */}
<div className="canvas-surface flex h-svh flex-col overflow-hidden">
<TopBar
session={session}
panels={panels}
onTogglePanel={togglePanel}
onReconnect={onReconnect}
onManageWorkspace={() => setManageOpen(true)}
onOpenMcpStatus={() => setMcpOpen(true)}
/>
{actions.notice && (
<div className="flex min-h-0 flex-1 px-2 pb-2">
{/* 左右面板保持挂载,通过宽度 + 间距过渡实现折叠 / 展开动画 */}
<div
className={cn(
"flex shrink-0 items-center gap-2 border-b px-3 py-1 text-xs",
actions.notice.kind === "error"
? "bg-destructive/10 text-destructive"
: "bg-primary/5 text-foreground",
"flex min-h-0 shrink-0 overflow-hidden transition-[width,margin] duration-250 ease-out-quart",
panels.tree ? "mr-2 w-[280px]" : "mr-0 w-0",
)}
>
{actions.actionBusy && (
<span className="size-2 animate-pulse rounded-full bg-primary" />
)}
{actions.notice.text}
</div>
)}
<div className="flex min-h-0 flex-1">
{panels.tree && (
<SourceTreePanel
collection={session.collection}
mappings={session.mappings}
@@ -103,7 +116,7 @@ export function WorkspaceShell({
onNavigate={onNavigate}
onFileAction={actions.handleFileAction}
/>
)}
</div>
<FolderItemsPanel
session={session}
selectedServerPath={selectedServerPath}
@@ -113,7 +126,12 @@ export function WorkspaceShell({
onFileAction={actions.handleFileAction}
onRefresh={refreshItems}
/>
{panels.changes && (
<div
className={cn(
"flex min-h-0 shrink-0 justify-end overflow-hidden transition-[width,margin] duration-250 ease-out-quart",
panels.changes ? "ml-2 w-[340px]" : "ml-0 w-0",
)}
>
<ChangesPanel
mappings={session.mappings}
pendingChanges={pending.pendingChanges}
@@ -121,21 +139,27 @@ export function WorkspaceShell({
loading={pending.loading}
error={pending.error}
checkinBusy={actions.checkinBusy}
onToggleExcluded={pending.toggleExcluded}
onSetExcluded={pending.setExcluded}
onCheckin={actions.handleCheckin}
onFileAction={actions.handleFileAction}
onRefresh={() => void pending.refresh()}
/>
)}
</div>
</div>
{panels.console && (
{/* 底部操作台通过高度过渡实现滑入滑出 */}
<div
className={cn(
"box-border shrink-0 overflow-hidden px-2 transition-[height] duration-250 ease-out-quart",
panels.console ? "h-[188px] pb-2" : "h-0",
)}
>
<ConsolePanel
refreshToken={logsRefreshToken}
busy={actions.actionBusy || actions.checkinBusy}
busyText={actions.notice?.kind === "info" ? actions.notice.text : null}
/>
)}
</div>
<WorkspaceDialogs
dialog={actions.dialog}
@@ -147,7 +171,28 @@ export function WorkspaceShell({
onConflictsResolved={actions.handleConflictsResolved}
onForceGetConfirmed={actions.handleForceGetConfirmed}
onGetVersion={actions.runGetVersion}
onRenameConfirmed={actions.handleRenameConfirmed}
onRollback={actions.runRollback}
onBranchConfirmed={actions.handleBranchConfirmed}
onMergeConfirmed={actions.handleMergeConfirmed}
onAddFilesConfirmed={actions.handleAddFilesConfirmed}
/>
{manageOpen && (
<WorkspaceManageDialog
session={session}
onClose={() => setManageOpen(false)}
onMappingsChanged={(mappings) => {
// Mapping 变化影响树映射标识与列表状态列,统一刷新。
onMappingsChanged(mappings)
refreshItems()
}}
/>
)}
{mcpOpen && <McpStatusDialog onClose={() => setMcpOpen(false)} />}
<Toaster />
</div>
</TooltipProvider>
)
@@ -0,0 +1,197 @@
import { useEffect, useMemo, useState } from "react"
import { FileText, FolderClosed, Loader2 } from "lucide-react"
import { Button } from "~/components/ui/button"
import { Checkbox } from "~/components/ui/checkbox"
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "~/components/ui/dialog"
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "~/components/ui/table"
import { api } from "~/lib/api"
import type { FolderDiffItem } from "~/lib/api"
/**
* 添加本地文件弹窗:对选中目录执行目录对比(递归),
* 自动筛出本地新增(localOnly)的文件 / 目录,勾选后批量加入版本控制(pendingAdd)。
*/
export function AddFilesDialog({
serverPath,
onConfirm,
onClose,
}: {
serverPath: string
/** 确认添加所选本地路径,由编排层调用接口并刷新,返回是否成功。 */
onConfirm: (localPaths: string[]) => Promise<boolean>
onClose: () => void
}) {
const [items, setItems] = useState<FolderDiffItem[]>([])
const [loading, setLoading] = useState(true)
const [error, setError] = useState<string | null>(null)
// 勾选集合:以本地路径为键,默认全选。
const [selected, setSelected] = useState<Set<string>>(new Set())
const [busy, setBusy] = useState(false)
useEffect(() => {
let active = true
void (async () => {
setLoading(true)
const result = await api.compareFolder({ serverPath, recursive: true })
if (!active) {
return
}
setLoading(false)
if (!result.ok) {
setError(result.errorMessage ?? "目录扫描失败")
return
}
setError(null)
const localOnly = (result.data?.diffs ?? []).filter(
(item) => item.status === "localOnly" && item.localPath,
)
setItems(localOnly)
setSelected(new Set(localOnly.map((item) => item.localPath)))
})()
return () => {
active = false
}
}, [serverPath])
const allChecked = items.length > 0 && selected.size === items.length
const selectedPaths = useMemo(
() => items.filter((item) => selected.has(item.localPath)).map((item) => item.localPath),
[items, selected],
)
/**
* 勾选 / 取消勾选单项。
*/
const toggle = (localPath: string) => {
setSelected((prev) => {
const next = new Set(prev)
if (next.has(localPath)) {
next.delete(localPath)
} else {
next.add(localPath)
}
return next
})
}
return (
<Dialog open onOpenChange={(open) => !open && !busy && onClose()}>
<DialogContent className="flex max-h-[80svh] flex-col sm:max-w-2xl">
<DialogHeader>
<DialogTitle>添加本地文件</DialogTitle>
<DialogDescription className="font-mono text-xs">{serverPath}</DialogDescription>
</DialogHeader>
<div className="min-h-0 flex-1 overflow-auto rounded-md border">
{loading ? (
<div className="flex h-32 items-center justify-center gap-2 text-sm text-muted-foreground">
<Loader2 className="size-4 animate-spin" />
正在扫描本地新增文件…
</div>
) : error ? (
<div className="flex h-32 items-center justify-center text-sm text-destructive">{error}</div>
) : items.length === 0 ? (
<div className="flex h-32 items-center justify-center px-6 text-center text-sm text-muted-foreground">
没有发现本地新增的文件,本地内容与服务器一致
</div>
) : (
<Table>
<TableHeader className="sticky top-0 z-10 bg-background">
<TableRow className="hover:bg-transparent">
<TableHead className="h-8 w-8">
<Checkbox
checked={allChecked}
onCheckedChange={(value) =>
setSelected(
value === true
? new Set(items.map((item) => item.localPath))
: new Set(),
)
}
aria-label="全选 / 清空"
/>
</TableHead>
<TableHead className="h-8 text-xs text-muted-foreground">名称</TableHead>
<TableHead className="h-8 text-xs text-muted-foreground">本地路径</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{items.map((item) => (
<TableRow
key={item.localPath}
className="cursor-pointer select-none"
onClick={() => toggle(item.localPath)}
>
<TableCell className="py-1.5">
<Checkbox
checked={selected.has(item.localPath)}
onCheckedChange={() => toggle(item.localPath)}
aria-label={`选择 ${item.name}`}
/>
</TableCell>
<TableCell className="py-1.5">
<span className="flex items-center gap-1.5">
{item.folder ? (
<FolderClosed className="size-3.5 shrink-0 text-muted-foreground" />
) : (
<FileText className="size-3.5 shrink-0 text-muted-foreground" />
)}
<span className="truncate text-sm">{item.name}</span>
</span>
</TableCell>
<TableCell
className="max-w-0 truncate py-1.5 font-mono text-xs text-muted-foreground"
title={item.localPath}
>
{item.localPath}
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
)}
</div>
<p className="shrink-0 text-xs text-muted-foreground">
添加后产生「挂起新增」,可在挂起更改面板审查、撤销,签入后进入服务器;目录会连同其内容一并添加。
</p>
<DialogFooter>
<Button variant="ghost" onClick={onClose} disabled={busy}>
取消
</Button>
<Button
disabled={selectedPaths.length === 0 || busy}
onClick={() => {
void (async () => {
setBusy(true)
const ok = await onConfirm(selectedPaths)
setBusy(false)
if (ok) {
onClose()
}
})()
}}
>
{busy ? "正在添加…" : `添加所选(${selectedPaths.length} 项)`}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
)
}
@@ -0,0 +1,138 @@
import { useState } from "react"
import { Button } from "~/components/ui/button"
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "~/components/ui/dialog"
import { Input } from "~/components/ui/input"
import { Label } from "~/components/ui/label"
import type { MappingInfo } from "~/lib/api"
import { getParentPath, resolveLocalPath } from "~/lib/tfs"
/**
* 分支弹窗:把源路径分叉到目标路径(pendBranch 产生挂起更改,签入后服务器生效)。
* 目标路径父目录必须已映射(分支内容需要落盘到本地工作区);可选基于指定 changeset。
*/
export function BranchDialog({
sourceServerPath,
mappings,
onConfirm,
onClose,
}: {
sourceServerPath: string
mappings: MappingInfo[]
/** 确认分支,由编排层调用接口并刷新,返回是否成功。 */
onConfirm: (targetServerPath: string, changeset: number | undefined) => Promise<boolean>
onClose: () => void
}) {
const [target, setTarget] = useState(`${sourceServerPath}-branch`)
const [changesetInput, setChangesetInput] = useState("")
const [busy, setBusy] = useState(false)
const trimmed = target.trim()
const parentPath = trimmed.length > 2 ? getParentPath(trimmed) : null
const parentMapped = parentPath != null && resolveLocalPath(mappings, parentPath) != null
const targetLocalPath = trimmed.length > 2 ? resolveLocalPath(mappings, trimmed) : null
const changesetTrimmed = changesetInput.trim()
const changesetValid = changesetTrimmed.length === 0 || /^\d+$/.test(changesetTrimmed)
const validation =
!trimmed.startsWith("$/") || trimmed.length <= 2
? "目标路径必须以 $/ 开头"
: trimmed === sourceServerPath
? "目标路径不能与源路径相同"
: trimmed.startsWith(`${sourceServerPath}/`)
? "目标路径不能位于源路径内部"
: !parentMapped
? "目标路径所在父目录未映射,请先在工作区中映射"
: !changesetValid
? "changeset 必须是数字"
: null
/**
* 执行分支:成功后由上层刷新并关闭弹窗。
*/
const handleConfirm = () => {
void (async () => {
setBusy(true)
const ok = await onConfirm(
trimmed,
changesetTrimmed.length === 0 ? undefined : Number(changesetTrimmed),
)
setBusy(false)
if (ok) {
onClose()
}
})()
}
return (
<Dialog open onOpenChange={(open) => !open && !busy && onClose()}>
<DialogContent className="sm:max-w-xl">
<DialogHeader>
<DialogTitle>分支</DialogTitle>
<DialogDescription>
从源路径创建分支,结果为 branch 挂起更改,签入后服务器生效
</DialogDescription>
</DialogHeader>
<div className="space-y-4">
<div className="space-y-1.5">
<Label>源路径</Label>
<p className="rounded-md border bg-muted/40 px-2.5 py-1.5 font-mono text-xs">
{sourceServerPath}
</p>
</div>
<div className="space-y-1.5">
<Label htmlFor="branchTarget">目标路径</Label>
<Input
id="branchTarget"
value={target}
onChange={(event) => setTarget(event.target.value)}
disabled={busy}
className="font-mono text-xs"
/>
{targetLocalPath != null && validation == null && (
<p className="break-all font-mono text-xs text-muted-foreground">
本地落盘:{targetLocalPath}
</p>
)}
</div>
<div className="space-y-1.5">
<Label htmlFor="branchChangeset">基于 changeset(可选,默认 latest)</Label>
<Input
id="branchChangeset"
value={changesetInput}
onChange={(event) => setChangesetInput(event.target.value)}
placeholder="留空表示最新版本"
disabled={busy}
inputMode="numeric"
className="w-56 font-mono text-xs"
/>
</div>
{validation != null && <p className="text-xs text-destructive">{validation}</p>}
<p className="text-xs text-muted-foreground">
分支只产生挂起更改,可在挂起更改面板审查、撤销,签入后目标路径才会出现在服务器上。
</p>
</div>
<DialogFooter>
<Button variant="ghost" onClick={onClose} disabled={busy}>
取消
</Button>
<Button disabled={validation != null || busy} onClick={handleConfirm}>
{busy ? "正在创建分支…" : "创建分支"}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
)
}
@@ -1,4 +1,4 @@
import { useCallback, useEffect, useMemo, useState } from "react"
import { useCallback, useMemo, useState } from "react"
import { FileText, FolderClosed, Loader2, RefreshCw } from "lucide-react"
import { FileTargetMenu } from "~/components/app/file-target-menu"
@@ -9,6 +9,7 @@ import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "~/components/ui/dialog"
@@ -30,6 +31,9 @@ import { cn } from "~/lib/utils"
* 目录对比弹窗:对已映射目录执行本地与服务端对比,
* 默认隐藏 upToDate,支持状态筛选、刷新重比,结果项走统一右键菜单。
*/
// 在对比弹窗内直接执行、完成后需要刷新对比结果的动作。
const ACTIONS_NEED_RECOMPARE: FileActionId[] = ["checkout", "getLatest", "undo", "delete", "add"]
export function CompareDialog({
serverPath,
mappings,
@@ -39,33 +43,51 @@ export function CompareDialog({
serverPath: string
mappings: MappingInfo[]
onClose: () => void
onFileAction: (target: FileTarget, action: FileActionId) => void
onFileAction: (target: FileTarget, action: FileActionId) => void | Promise<void>
}) {
// 先选项后对比:setup 阶段确认选项,result 阶段展示对比结果。
const [phase, setPhase] = useState<"setup" | "result">("setup")
const [diffs, setDiffs] = useState<FolderDiffItem[]>([])
const [loading, setLoading] = useState(true)
const [loading, setLoading] = useState(false)
const [error, setError] = useState<string | null>(null)
const [showUpToDate, setShowUpToDate] = useState(false)
// 忽略仅本地存在的项(如 node_modules):勾选后只对比两端都有的文件,并跳过本地全量扫描。
const [ignoreLocalOnly, setIgnoreLocalOnly] = useState(false)
// 状态筛选:空集合表示不过滤(除 upToDate 开关外)。
const [statusFilter, setStatusFilter] = useState<Set<string>>(new Set())
/**
* 执行(或重新执行)目录对比。
* 执行(或重新执行)目录对比;忽略仅本地存在的项时由后端直接跳过本地扫描。
*/
const runCompare = useCallback(async () => {
setLoading(true)
setError(null)
const result = await api.compareFolder({ serverPath, recursive: true })
const result = await api.compareFolder({
serverPath,
recursive: true,
includeLocalOnly: !ignoreLocalOnly,
})
setLoading(false)
if (!result.ok) {
setError(result.errorMessage ?? "目录对比失败")
return
}
setDiffs(result.data?.diffs ?? [])
}, [serverPath])
}, [serverPath, ignoreLocalOnly])
useEffect(() => {
void runCompare()
}, [runCompare])
/**
* 转发右键动作:签出 / 获取 / 撤销等就地执行的动作完成后自动重新对比,
* 让结果状态(如 签出编辑)立即反映最新事实。
*/
const handleAction = useCallback(
async (target: FileTarget, action: FileActionId) => {
await onFileAction(target, action)
if (ACTIONS_NEED_RECOMPARE.includes(action)) {
await runCompare()
}
},
[onFileAction, runCompare],
)
// 结果中出现过的状态(不含 upToDate),用于生成筛选 chips。
const presentStatuses = useMemo(() => {
@@ -104,11 +126,56 @@ export function CompareDialog({
})
}, [])
// 选项确认阶段:先确定对比方式再执行,避免反复触发全量对比。
if (phase === "setup") {
return (
<Dialog open onOpenChange={(open) => !open && onClose()}>
<DialogContent className="sm:max-w-lg">
<DialogHeader>
<DialogTitle>目录对比</DialogTitle>
<DialogDescription className="font-mono text-xs">{serverPath}</DialogDescription>
</DialogHeader>
<div className="space-y-3 rounded-md border bg-muted/30 p-4">
<label className="flex items-start gap-2 text-sm">
<Checkbox
checked={ignoreLocalOnly}
onCheckedChange={(value) => setIgnoreLocalOnly(value === true)}
className="mt-0.5"
/>
<span>
<span className="font-medium">忽略仅本地存在的项</span>
<span className="mt-1 block text-xs leading-5 text-muted-foreground">
只对比两端都有的文件;仅本地存在的项(如 node_modules、构建产物)不计入差异,
并跳过本地全量扫描,大目录速度更快。
</span>
</span>
</label>
</div>
<DialogFooter>
<Button variant="ghost" onClick={onClose}>
取消
</Button>
<Button
onClick={() => {
setPhase("result")
void runCompare()
}}
>
开始对比
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
)
}
return (
<Dialog open onOpenChange={(open) => !open && onClose()}>
<DialogContent className="flex h-[88svh] max-h-[88svh] flex-col sm:max-w-[90vw]">
<DialogHeader>
<DialogTitle>目录对比</DialogTitle>
<DialogTitle>目录对比{ignoreLocalOnly ? "(已忽略仅本地存在的项)" : ""}</DialogTitle>
<DialogDescription className="font-mono text-xs">{serverPath}</DialogDescription>
</DialogHeader>
@@ -134,6 +201,14 @@ export function CompareDialog({
/>
显示最新项
</label>
<Button
variant="outline"
size="sm"
onClick={() => setPhase("setup")}
disabled={loading}
>
调整选项
</Button>
<Button
variant="outline"
size="sm"
@@ -181,7 +256,11 @@ export function CompareDialog({
compareStatus: diff.status,
})
return (
<FileTargetMenu key={diff.serverPath} target={target} onAction={onFileAction}>
<FileTargetMenu
key={diff.serverPath}
target={target}
onAction={(menuTarget, action) => void handleAction(menuTarget, action)}
>
<TableRow className="cursor-default select-none">
<TableCell className="py-1.5">
<span className="flex items-center gap-1.5">
@@ -167,7 +167,7 @@ export function ConflictDialog({
</DialogHeader>
<div className="flex shrink-0 items-center gap-2">
<Badge variant="secondary" className="rounded-md bg-red-500/10 text-red-700 dark:text-red-400">
<Badge variant="secondary" className="rounded-md bg-red-500/10 text-red-700">
{conflicts.length} 个冲突
</Badge>
<span className="text-xs text-muted-foreground">
@@ -46,13 +46,6 @@ function splitDiffSides(raw: string[]): { original: string; modified: string } {
return { original: original.join("\n"), modified: modified.join("\n") }
}
/**
* 判断当前应用是否处于暗色主题(class 方案),用于选择 Monaco 主题。
*/
function isDarkTheme(): boolean {
return typeof document !== "undefined" && document.documentElement.classList.contains("dark")
}
/**
* 文本 Diff 弹窗:基于 Monaco DiffEditor 渲染,支持 本地 vs 服务器 latest
* 与 两个历史版本 对比。提供统一 / 左右分栏视图、上一处 / 下一处差异导航、
@@ -140,8 +133,10 @@ export function DiffDialog({
originalEditable: false,
automaticLayout: true,
renderSideBySide: viewMode === "split",
// 统一视图下隐藏旧版行号列,避免出现两列紧贴的行号。
compactMode: viewMode === "unified",
hideUnchangedRegions: { enabled: onlyChanges },
theme: isDarkTheme() ? "mactfs-dark" : "mactfs-light",
theme: "mactfs-light",
fontSize: 12,
lineHeight: 20,
fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Monaco, "Courier New", monospace',
@@ -182,7 +177,10 @@ export function DiffDialog({
*/
const switchView = useCallback((mode: "unified" | "split") => {
setViewMode(mode)
editorRef.current?.updateOptions({ renderSideBySide: mode === "split" })
editorRef.current?.updateOptions({
renderSideBySide: mode === "split",
compactMode: mode === "unified",
})
if (typeof sessionStorage !== "undefined") {
sessionStorage.setItem(VIEW_MODE_KEY, mode)
}
@@ -245,10 +243,10 @@ export function DiffDialog({
<div className="flex shrink-0 flex-wrap items-center gap-2 text-xs">
{diff && (
<>
<Badge variant="secondary" className="rounded-md bg-red-500/10 text-red-700 dark:text-red-400">
<Badge variant="secondary" className="rounded-md bg-red-500/10 text-red-700">
− {diff.sourceLabel}
</Badge>
<Badge variant="secondary" className="rounded-md bg-green-500/10 text-green-700 dark:text-green-400">
<Badge variant="secondary" className="rounded-md bg-green-500/10 text-green-700">
+ {diff.targetLabel}
</Badge>
<span className="text-muted-foreground">{changedCount} 行差异</span>
@@ -0,0 +1,111 @@
import {
Database,
File,
FileArchive,
FileCode,
FileImage,
FileJson,
FileSpreadsheet,
FileTerminal,
FileText,
FolderClosed,
FolderOpen,
FolderSymlink,
type LucideIcon,
} from "lucide-react"
import { cn } from "~/lib/utils"
// 扩展名 -> 图标与配色的映射规则,未命中走默认文件图标。
const FILE_ICON_RULES: { exts: string[]; icon: LucideIcon; className: string }[] = [
{
exts: ["ts", "tsx", "js", "jsx", "java", "cs", "py", "go", "rs", "c", "cpp", "h", "vue", "css", "scss", "html"],
icon: FileCode,
className: "text-blue-600",
},
{
exts: ["json", "xml", "yml", "yaml", "toml", "config", "properties", "gradle"],
icon: FileJson,
className: "text-amber-600",
},
{
exts: ["md", "txt", "doc", "docx", "pdf", "rtf"],
icon: FileText,
className: "text-zinc-500",
},
{
exts: ["sql", "db"],
icon: Database,
className: "text-violet-600",
},
{
exts: ["png", "jpg", "jpeg", "gif", "svg", "webp", "ico", "icns"],
icon: FileImage,
className: "text-emerald-600",
},
{
exts: ["zip", "rar", "7z", "tar", "gz", "jar"],
icon: FileArchive,
className: "text-orange-600",
},
{
exts: ["xls", "xlsx", "csv"],
icon: FileSpreadsheet,
className: "text-green-600",
},
{
exts: ["sh", "bat", "cmd", "ps1", "zsh"],
icon: FileTerminal,
className: "text-zinc-600",
},
]
/**
* 取文件名扩展名(小写,无点);无扩展名返回空串。
*/
function extOf(name: string): string {
const index = name.lastIndexOf(".")
return index > 0 ? name.slice(index + 1).toLowerCase() : ""
}
/**
* 文件 / 文件夹图标:文件按扩展名区分图标与配色,
* 文件夹区分普通(蓝色)与已映射(FolderSymlink 主色),展开态用 FolderOpen。
*/
export function FileIcon({
name,
folder,
mapped = false,
expanded = false,
className,
}: {
name: string
folder: boolean
mapped?: boolean
expanded?: boolean
className?: string
}) {
if (folder) {
const Icon = mapped ? FolderSymlink : expanded ? FolderOpen : FolderClosed
return (
<Icon
className={cn(
"size-3.5 shrink-0",
mapped ? "text-primary" : "text-sky-600",
className,
)}
/>
)
}
const rule = FILE_ICON_RULES.find((item) => item.exts.includes(extOf(name)))
const Icon = rule?.icon ?? File
return (
<Icon
className={cn(
"size-3.5 shrink-0",
rule?.className ?? "text-muted-foreground",
className,
)}
/>
)
}
@@ -1,9 +1,10 @@
import { useEffect, useMemo, useState } from "react"
import { FileText, FolderClosed, Loader2, RefreshCw } from "lucide-react"
import { AlertCircle, FolderOpen, RefreshCw } from "lucide-react"
import { Button } from "~/components/ui/button"
import { FileTargetMenu } from "~/components/app/file-target-menu"
import { FileIcon } from "~/components/explorer/file-icon"
import { Badge } from "~/components/ui/badge"
import {
Table,
@@ -117,9 +118,18 @@ export function FolderItemsPanel({
const currentLocalPath = resolveLocalPath(session.mappings, selectedServerPath)
const selectedRow = rows.find((row) => row.item.serverPath === selectedItemPath)
// 中间区域空白处右键的目标:当前目录本身(与目录树右键同一套菜单)。
const currentFolderTarget = makeFileTarget({
source: "list",
folder: true,
serverPath: selectedServerPath,
mappings: session.mappings,
pendingStatus: pendingByServerPath[selectedServerPath] ?? null,
})
return (
<section className="flex h-full min-w-0 flex-1 flex-col bg-background">
<div className="flex h-9 shrink-0 items-center gap-2 border-b px-3">
<section className="flex h-full min-w-0 flex-1 flex-col overflow-hidden rounded-xl border bg-card shadow-card">
<div className="flex h-9 shrink-0 items-center gap-2 border-b bg-muted/40 px-3">
<span className="shrink-0 text-xs text-muted-foreground">当前路径</span>
<span className="min-w-0 truncate font-mono text-xs">{selectedServerPath}</span>
<span className="ml-auto shrink-0 text-xs text-muted-foreground">
@@ -142,23 +152,27 @@ export function FolderItemsPanel({
</Button>
</div>
<div className="min-h-0 flex-1 overflow-auto">
<FileTargetMenu target={currentFolderTarget} onAction={onFileAction}>
{/* 由 table-container 自身承担纵横滚动:表头 sticky 不随内容滚走,横向滚动条始终贴可视区底部 */}
<div className="min-h-0 flex-1 overflow-hidden [&_[data-slot=table-container]]:h-full [&_[data-slot=table-container]]:overflow-auto">
{loading ? (
<div className="flex h-full items-center justify-center gap-2 text-sm text-muted-foreground">
<Loader2 className="size-4 animate-spin" />
正在加载目录…
</div>
<ItemsSkeleton />
) : error ? (
<div className="flex h-full items-center justify-center p-6 text-sm text-destructive">
{error}
<div className="flex h-full flex-col items-center justify-center gap-2 p-6">
<AlertCircle className="size-8 text-destructive/60" />
<p className="text-sm text-destructive">{error}</p>
</div>
) : rows.length === 0 ? (
<div className="flex h-full items-center justify-center text-sm text-muted-foreground">
当前目录为空
<div className="flex h-full flex-col items-center justify-center gap-2 p-6 text-center">
<FolderOpen className="size-8 text-muted-foreground/50" />
<p className="text-sm text-muted-foreground">当前目录为空</p>
<p className="text-xs text-muted-foreground/70">
右键空白处可对当前目录执行获取、映射或添加本地文件
</p>
</div>
) : (
<Table>
<TableHeader className="sticky top-0 z-10 bg-background">
<TableHeader className="sticky top-0 z-10 bg-[oklch(0.972_0.003_286)]">
<TableRow className="hover:bg-transparent">
<TableHead className="h-8 text-xs text-muted-foreground">名称</TableHead>
<TableHead className="h-8 w-24 text-xs text-muted-foreground">状态</TableHead>
@@ -172,7 +186,7 @@ export function FolderItemsPanel({
</TableRow>
</TableHeader>
<TableBody>
{rows.map((row) => {
{rows.map((row, index) => {
const selected = row.item.serverPath === selectedItemPath
const target = makeFileTarget({
source: "list",
@@ -189,9 +203,14 @@ export function FolderItemsPanel({
>
<TableRow
data-state={selected ? "selected" : undefined}
className="cursor-default select-none"
className="animate-in fade-in cursor-default select-none fill-mode-backwards duration-200"
style={{ animationDelay: `${Math.min(index, 12) * 18}ms` }}
onClick={() => setSelectedItemPath(row.item.serverPath)}
onContextMenu={() => setSelectedItemPath(row.item.serverPath)}
onContextMenu={(event) => {
// 阻止冒泡到外层「当前目录」菜单,避免双菜单。
event.stopPropagation()
setSelectedItemPath(row.item.serverPath)
}}
onDoubleClick={() => {
if (row.item.folder) {
onNavigate(row.item.serverPath)
@@ -200,19 +219,20 @@ export function FolderItemsPanel({
>
<TableCell className="py-1.5">
<span className="flex items-center gap-1.5" title={row.item.serverPath}>
{row.item.folder ? (
<FolderClosed className="size-3.5 shrink-0 text-muted-foreground" />
) : (
<FileText className="size-3.5 shrink-0 text-muted-foreground" />
)}
<FileIcon
name={row.item.name}
folder={row.item.folder}
mapped={row.item.folder && row.localPath != null}
/>
<span className="truncate text-sm">{row.item.name}</span>
</span>
</TableCell>
<TableCell className="py-1.5">
<Badge
variant="secondary"
className={cn("rounded-md", statusBadgeClass(row.localState))}
className={cn("gap-1.5 rounded-md", statusBadgeClass(row.localState))}
>
<span className="size-1.5 rounded-full bg-current opacity-60" />
{statusLabel(row.localState)}
</Badge>
</TableCell>
@@ -233,6 +253,7 @@ export function FolderItemsPanel({
</Table>
)}
</div>
</FileTargetMenu>
<div className="flex h-8 shrink-0 items-center gap-2 border-t px-3 text-xs text-muted-foreground">
{selectedRow ? (
@@ -254,3 +275,25 @@ export function FolderItemsPanel({
</section>
)
}
/**
* 目录加载骨架屏:模拟表格行的占位条,替代纯文字 loading。
*/
function ItemsSkeleton() {
return (
<div className="space-y-2 p-3">
{Array.from({ length: 9 }).map((_, index) => (
<div
key={index}
className="flex animate-pulse items-center gap-3"
style={{ animationDelay: `${index * 80}ms` }}
>
<span className="size-4 rounded bg-muted" />
<span className="h-3.5 rounded bg-muted" style={{ width: `${160 + ((index * 53) % 120)}px` }} />
<span className="h-3.5 w-14 rounded-full bg-muted" />
<span className="ml-auto h-3 w-28 rounded bg-muted" />
</div>
))}
</div>
)
}
@@ -0,0 +1,171 @@
import { useEffect, useState } from "react"
import { Loader2 } from "lucide-react"
import { Button } from "~/components/ui/button"
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "~/components/ui/dialog"
import { Input } from "~/components/ui/input"
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "~/components/ui/table"
import { api } from "~/lib/api"
import type { HistoryEntry } from "~/lib/api"
import { cn, formatDateTime } from "~/lib/utils"
/**
* 获取特定版本弹窗:输入或从该对象历史中点选 changeset,
* 确认后把对象本地内容整体切到该变更集时刻(目录为递归覆盖),
* 对应 VS 的 Get Specific Version + Overwrite。
*/
export function GetVersionDialog({
serverPath,
folder,
onConfirm,
onClose,
}: {
serverPath: string
folder: boolean
/** 确认后执行获取,由编排层调用 get-version 接口并刷新。 */
onConfirm: (changeset: number) => Promise<boolean>
onClose: () => void
}) {
const [input, setInput] = useState("")
const [entries, setEntries] = useState<HistoryEntry[]>([])
const [loading, setLoading] = useState(true)
const [error, setError] = useState<string | null>(null)
const [busy, setBusy] = useState(false)
useEffect(() => {
let active = true
void (async () => {
setLoading(true)
const result = await api.getHistory({ path: serverPath, folder })
if (!active) {
return
}
setLoading(false)
if (!result.ok) {
setError(result.errorMessage ?? "历史加载失败")
return
}
setError(null)
setEntries(result.data?.history ?? [])
})()
return () => {
active = false
}
}, [serverPath, folder])
const changeset = /^\d+$/.test(input.trim()) ? Number(input.trim()) : null
const valid = changeset != null && changeset > 0
return (
<Dialog open onOpenChange={(open) => !open && !busy && onClose()}>
<DialogContent className="flex max-h-[80svh] flex-col sm:max-w-2xl">
<DialogHeader>
<DialogTitle>获取特定版本</DialogTitle>
<DialogDescription className="font-mono text-xs">{serverPath}</DialogDescription>
</DialogHeader>
<div className="flex shrink-0 items-center gap-2">
<span className="text-sm text-muted-foreground">Changeset</span>
<Input
value={input}
onChange={(event) => setInput(event.target.value)}
placeholder="输入编号或从下方历史点选"
className="h-8 w-56 font-mono text-sm"
inputMode="numeric"
/>
</div>
<div className="min-h-0 flex-1 overflow-auto rounded-md border">
{loading ? (
<div className="flex h-32 items-center justify-center gap-2 text-sm text-muted-foreground">
<Loader2 className="size-4 animate-spin" />
正在加载历史…
</div>
) : error ? (
<div className="flex h-32 items-center justify-center text-sm text-destructive">{error}</div>
) : entries.length === 0 ? (
<div className="flex h-32 items-center justify-center text-sm text-muted-foreground">
没有历史记录,可直接输入 changeset 编号
</div>
) : (
<Table>
<TableHeader className="sticky top-0 z-10 bg-background">
<TableRow className="hover:bg-transparent">
<TableHead className="h-8 w-24 text-xs text-muted-foreground">Changeset</TableHead>
<TableHead className="h-8 w-28 text-xs text-muted-foreground">作者</TableHead>
<TableHead className="h-8 w-36 text-xs text-muted-foreground">时间</TableHead>
<TableHead className="h-8 text-xs text-muted-foreground">注释</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{entries.map((entry) => (
<TableRow
key={`${entry.changeset}-${entry.serverPath}`}
className={cn(
"cursor-pointer select-none",
changeset === entry.changeset && "bg-primary/10 hover:bg-primary/10",
)}
onClick={() => setInput(String(entry.changeset))}
>
<TableCell className="py-1.5 font-mono text-xs">{entry.changeset}</TableCell>
<TableCell className="max-w-0 truncate py-1.5 text-xs">{entry.author}</TableCell>
<TableCell className="py-1.5 text-xs text-muted-foreground">
{formatDateTime(entry.date)}
</TableCell>
<TableCell className="max-w-0 truncate py-1.5 text-xs" title={entry.comment}>
{entry.comment || "—"}
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
)}
</div>
<p className="shrink-0 text-xs font-medium text-destructive">
确认后{folder ? "该目录(递归)" : "该文件"}的本地内容会被所选版本覆盖,
本地未签入的修改无法恢复。
</p>
<DialogFooter>
<Button variant="ghost" onClick={onClose} disabled={busy}>
取消
</Button>
<Button
variant="destructive"
disabled={!valid || busy}
onClick={() => {
if (changeset == null) {
return
}
void (async () => {
setBusy(true)
const ok = await onConfirm(changeset)
setBusy(false)
if (ok) {
onClose()
}
})()
}}
>
{busy ? "正在获取…" : changeset != null ? `获取 C${changeset}` : "获取此版本"}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
)
}
@@ -44,6 +44,13 @@ interface VersionConfirm {
folder: boolean
}
// 「回滚」待确认信息:single 仅反做该变更集,toVersion 反做其后全部改动。
interface RollbackConfirm {
serverPath: string
changeset: number
mode: "single" | "toVersion"
}
/**
* History 弹窗:展示文件或目录历史(最近记录)。
* 目录历史可下钻 changeset 影响文件;changeset 文件支持右键查看此版本 /
@@ -56,12 +63,14 @@ export function HistoryDialog({
onClose,
onDiffRevisions,
onGetVersion,
onRollback,
}: {
serverPath: string
folder: boolean
onClose: () => void
onDiffRevisions?: (serverPath: string, source: number, target: number) => void
onGetVersion?: (serverPath: string, changeset: number, folder: boolean) => Promise<boolean>
onRollback?: (serverPath: string, mode: "single" | "toVersion", changeset: number) => Promise<boolean>
}) {
const [target, setTarget] = useState<HistoryTarget>({ serverPath, folder })
// 下钻历史目标栈:从 changeset 文件进入单文件历史后可逐级返回。
@@ -78,6 +87,8 @@ export function HistoryDialog({
// 文件历史勾选的 changeset(最多两个),用于版本对比。
const [selected, setSelected] = useState<number[]>([])
const [confirmVersion, setConfirmVersion] = useState<VersionConfirm | null>(null)
// 「回滚」待确认信息。
const [confirmRollback, setConfirmRollback] = useState<RollbackConfirm | null>(null)
// 「查看此版本内容」叠加的文件查看弹窗目标。
const [viewVersion, setViewVersion] = useState<{ serverPath: string; changeset: number } | null>(null)
@@ -238,8 +249,9 @@ export function HistoryDialog({
</TableHeader>
<TableBody>
{entries.map((entry) => (
<ContextMenu key={`${entry.changeset}-${entry.serverPath}`}>
<ContextMenuTrigger asChild>
<TableRow
key={`${entry.changeset}-${entry.serverPath}`}
className="cursor-default select-none"
onDoubleClick={() => {
if (target.folder) {
@@ -296,6 +308,54 @@ export function HistoryDialog({
</TableCell>
)}
</TableRow>
</ContextMenuTrigger>
{(onGetVersion || onRollback) && (
<ContextMenuContent className="w-60">
{onGetVersion && (
<ContextMenuItem
onSelect={() =>
setConfirmVersion({
serverPath: target.serverPath,
changeset: entry.changeset,
folder: target.folder,
})
}
>
获取此版本(C{entry.changeset})…
</ContextMenuItem>
)}
{onGetVersion && onRollback && <ContextMenuSeparator />}
{onRollback && (
<>
<ContextMenuItem
variant="destructive"
onSelect={() =>
setConfirmRollback({
serverPath: target.serverPath,
changeset: entry.changeset,
mode: "single",
})
}
>
回滚此变更集(C{entry.changeset})…
</ContextMenuItem>
<ContextMenuItem
variant="destructive"
onSelect={() =>
setConfirmRollback({
serverPath: target.serverPath,
changeset: entry.changeset,
mode: "toVersion",
})
}
>
回滚到此变更集(C{entry.changeset})…
</ContextMenuItem>
</>
)}
</ContextMenuContent>
)}
</ContextMenu>
))}
</TableBody>
</Table>
@@ -352,6 +412,40 @@ export function HistoryDialog({
/>
)}
{confirmRollback && onRollback && (
<ConfirmDialog
title={
confirmRollback.mode === "single"
? `回滚变更集 C${confirmRollback.changeset}`
: `回滚到变更集 C${confirmRollback.changeset}`
}
description={
<>
<p>
将对 <span className="font-mono text-xs">{confirmRollback.serverPath}</span>{" "}
{confirmRollback.mode === "single"
? `反做变更集 C${confirmRollback.changeset} 的改动。`
: `反做 C${confirmRollback.changeset} 之后的全部改动(回到该变更集时刻的内容)。`}
</p>
<p className="mt-2">
回滚只会产生挂起更改,不会直接写入服务器;可在挂起更改面板审查、撤销,确认无误后签入。
</p>
</>
}
confirmLabel="执行回滚"
danger
onConfirm={async () => {
await onRollback(
confirmRollback.serverPath,
confirmRollback.mode,
confirmRollback.changeset,
)
setConfirmRollback(null)
}}
onClose={() => setConfirmRollback(null)}
/>
)}
{viewVersion && (
<FileViewDialog
serverPath={viewVersion.serverPath}
@@ -0,0 +1,228 @@
import { useCallback, useState } from "react"
import { Loader2, Search } from "lucide-react"
import { Button } from "~/components/ui/button"
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "~/components/ui/dialog"
import { Input } from "~/components/ui/input"
import { Label } from "~/components/ui/label"
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "~/components/ui/table"
import { api } from "~/lib/api"
import type { HistoryEntry, MappingInfo } from "~/lib/api"
import { resolveLocalPath } from "~/lib/tfs"
import { cn, formatDateTime } from "~/lib/utils"
/**
* 合并向导弹窗:源(当前对象)→ 目标路径(必须已映射),
* 加载待合并 changeset 候选后支持「全部合并」或选择单个合并;
* 结果为挂起更改,冲突由编排层进入既有冲突弹窗。
*/
export function MergeDialog({
sourceServerPath,
mappings,
onMerge,
onClose,
}: {
sourceServerPath: string
mappings: MappingInfo[]
/** 执行合并(changeset 为 undefined 表示全部),由编排层调用接口并刷新。 */
onMerge: (targetServerPath: string, changeset: number | undefined) => Promise<boolean>
onClose: () => void
}) {
const [target, setTarget] = useState("")
const [candidates, setCandidates] = useState<HistoryEntry[] | null>(null)
const [loading, setLoading] = useState(false)
const [selected, setSelected] = useState<number | null>(null)
const [busy, setBusy] = useState(false)
const [error, setError] = useState<string | null>(null)
const trimmed = target.trim()
const targetMapped = trimmed.length > 2 && resolveLocalPath(mappings, trimmed) != null
const validation =
trimmed.length === 0
? null
: !trimmed.startsWith("$/") || trimmed.length <= 2
? "目标路径必须以 $/ 开头"
: trimmed === sourceServerPath
? "目标路径不能与源路径相同"
: !targetMapped
? "目标路径未映射,请先在工作区中映射"
: null
const targetReady = trimmed.length > 2 && validation == null
/**
* 加载源 → 目标的待合并候选列表。
*/
const loadCandidates = useCallback(async () => {
setLoading(true)
setError(null)
setSelected(null)
const result = await api.mergeCandidates({
sourceServerPath,
targetServerPath: trimmed,
})
setLoading(false)
if (!result.ok) {
setCandidates(null)
setError(result.errorMessage ?? "候选查询失败(请确认源与目标存在分支关系)")
return
}
setCandidates(result.data?.candidates ?? [])
}, [sourceServerPath, trimmed])
/**
* 执行合并:changeset 为 undefined 表示合并全部候选。
*/
const handleMerge = useCallback(
(changeset: number | undefined) => {
void (async () => {
setBusy(true)
const ok = await onMerge(trimmed, changeset)
setBusy(false)
if (ok) {
onClose()
}
})()
},
[onMerge, trimmed, onClose],
)
return (
<Dialog open onOpenChange={(open) => !open && !busy && onClose()}>
<DialogContent className="flex max-h-[85svh] flex-col sm:max-w-2xl">
<DialogHeader>
<DialogTitle>合并</DialogTitle>
<DialogDescription>
将源分支的变更集合并到目标分支,结果为挂起更改,冲突需逐个处理
</DialogDescription>
</DialogHeader>
<div className="shrink-0 space-y-3">
<div className="space-y-1.5">
<Label>源路径</Label>
<p className="rounded-md border bg-muted/40 px-2.5 py-1.5 font-mono text-xs">
{sourceServerPath}
</p>
</div>
<div className="space-y-1.5">
<Label htmlFor="mergeTarget">目标路径(必须已映射)</Label>
<div className="flex gap-2">
<Input
id="mergeTarget"
value={target}
onChange={(event) => {
setTarget(event.target.value)
setCandidates(null)
}}
placeholder="$/Project/Branch"
disabled={busy}
className="font-mono text-xs"
/>
<Button
variant="outline"
size="sm"
className="h-9 shrink-0"
disabled={!targetReady || loading || busy}
onClick={() => void loadCandidates()}
>
<Search data-icon="inline-start" />
查询候选
</Button>
</div>
{validation != null && <p className="text-xs text-destructive">{validation}</p>}
</div>
</div>
<div className="min-h-0 flex-1 overflow-auto rounded-md border">
{loading ? (
<div className="flex h-32 items-center justify-center gap-2 text-sm text-muted-foreground">
<Loader2 className="size-4 animate-spin" />
正在查询待合并变更集…
</div>
) : candidates == null ? (
<div className="flex h-32 items-center justify-center px-6 text-center text-sm text-muted-foreground">
输入目标路径并点击「查询候选」,查看可合并的变更集
</div>
) : candidates.length === 0 ? (
<div className="flex h-32 items-center justify-center text-sm text-muted-foreground">
没有待合并的变更集,两个分支已同步
</div>
) : (
<Table>
<TableHeader className="sticky top-0 z-10 bg-background">
<TableRow className="hover:bg-transparent">
<TableHead className="h-8 w-24 text-xs text-muted-foreground">Changeset</TableHead>
<TableHead className="h-8 w-24 text-xs text-muted-foreground">类型</TableHead>
<TableHead className="h-8 w-28 text-xs text-muted-foreground">作者</TableHead>
<TableHead className="h-8 w-36 text-xs text-muted-foreground">时间</TableHead>
<TableHead className="h-8 text-xs text-muted-foreground">注释</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{candidates.map((entry) => (
<TableRow
key={entry.changeset}
className={cn(
"cursor-pointer select-none",
selected === entry.changeset && "bg-primary/10 hover:bg-primary/10",
)}
onClick={() =>
setSelected((prev) => (prev === entry.changeset ? null : entry.changeset))
}
>
<TableCell className="py-1.5 font-mono text-xs">{entry.changeset}</TableCell>
<TableCell className="py-1.5 text-xs">{entry.changeType}</TableCell>
<TableCell className="max-w-0 truncate py-1.5 text-xs">{entry.author}</TableCell>
<TableCell className="py-1.5 text-xs text-muted-foreground">
{formatDateTime(entry.date)}
</TableCell>
<TableCell className="max-w-0 truncate py-1.5 text-xs" title={entry.comment}>
{entry.comment || "—"}
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
)}
</div>
{error && <p className="shrink-0 text-sm text-destructive">{error}</p>}
<p className="shrink-0 text-xs text-muted-foreground">
合并只产生挂起更改,不会直接写入服务器;出现冲突会进入冲突处理弹窗,签入前可撤销。
</p>
<DialogFooter>
<Button variant="ghost" onClick={onClose} disabled={busy}>
取消
</Button>
<Button
variant="outline"
disabled={!targetReady || busy || candidates == null || candidates.length === 0 || selected == null}
onClick={() => handleMerge(selected ?? undefined)}
>
合并所选({selected != null ? `C${selected}` : "未选择"})
</Button>
<Button
disabled={!targetReady || busy || candidates == null || candidates.length === 0}
onClick={() => handleMerge(undefined)}
>
{busy ? "正在合并…" : "全部合并"}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
)
}
@@ -0,0 +1,186 @@
import { useEffect, useState } from "react"
import { Check, Copy, Loader2 } from "lucide-react"
import { Badge } from "~/components/ui/badge"
import { Button } from "~/components/ui/button"
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
} from "~/components/ui/dialog"
import { api } from "~/lib/api"
import type { ItemInfo } from "~/lib/api"
import type { FileTarget } from "~/lib/tfs"
import { statusBadgeClass, statusLabel } from "~/lib/tfs"
import { formatDateTime } from "~/lib/utils"
/**
* 把字节数格式化为可读大小(B / KB / MB)。
*/
function formatSize(size: number | null): string {
if (size == null) {
return "—"
}
if (size < 1024) {
return `${size} B`
}
if (size < 1024 * 1024) {
return `${(size / 1024).toFixed(1)} KB`
}
return `${(size / 1024 / 1024).toFixed(2)} MB`
}
/**
* 对象属性弹窗:展示服务器路径、本地路径、映射与挂起状态,
* 以及服务器侧最新版本信息(changeset / 时间 / 提交人),文件附带大小与编码。
*/
export function PropertiesDialog({
target,
onClose,
}: {
target: FileTarget
onClose: () => void
}) {
const [info, setInfo] = useState<ItemInfo | null>(null)
const [loading, setLoading] = useState(true)
const [error, setError] = useState<string | null>(null)
useEffect(() => {
let active = true
void (async () => {
setLoading(true)
const result = await api.getItemInfo({ serverPath: target.serverPath })
if (!active) {
return
}
setLoading(false)
if (!result.ok || !result.data) {
setError(result.errorMessage ?? "属性加载失败")
return
}
setError(null)
setInfo(result.data.item)
})()
return () => {
active = false
}
}, [target.serverPath])
return (
<Dialog open onOpenChange={(open) => !open && onClose()}>
<DialogContent className="sm:max-w-xl">
<DialogHeader>
<DialogTitle>属性</DialogTitle>
<DialogDescription className="font-mono text-xs">
{target.serverPath}
</DialogDescription>
</DialogHeader>
<div className="space-y-1 text-sm">
<PropertyRow label="对象类型" value={target.folder ? "目录" : "文件"} />
<PropertyRow label="服务器路径" value={target.serverPath} mono copyable />
<PropertyRow
label="本地路径"
value={target.localPath ?? "未映射"}
mono={target.localPath != null}
copyable={target.localPath != null}
muted={target.localPath == null}
/>
<PropertyRow
label="映射状态"
value={
<Badge variant="secondary" className={statusBadgeClass(target.mapped ? "mapped" : "notMapped")}>
{target.mapped ? (target.mappingRoot ? "映射根目录" : "已映射") : "未映射"}
</Badge>
}
/>
<PropertyRow
label="挂起状态"
value={
target.pendingStatus ? (
<Badge variant="secondary" className={statusBadgeClass(target.pendingStatus)}>
{statusLabel(target.pendingStatus)}
</Badge>
) : (
"无挂起更改"
)
}
muted={target.pendingStatus == null}
/>
<div className="my-2 border-t" />
{loading ? (
<div className="flex h-24 items-center justify-center gap-2 text-sm text-muted-foreground">
<Loader2 className="size-4 animate-spin" />
正在加载服务器信息…
</div>
) : error ? (
<div className="flex h-24 items-center justify-center text-sm text-destructive">{error}</div>
) : info ? (
<>
<PropertyRow label="最新 Changeset" value={`C${info.changeset}`} mono />
<PropertyRow label="签入时间" value={formatDateTime(info.checkinDate)} />
<PropertyRow label="签入人" value={info.author || "—"} />
<PropertyRow label="签入备注" value={info.comment || "—"} muted={!info.comment} />
{!info.folder && (
<>
<PropertyRow label="文件大小" value={formatSize(info.size)} />
<PropertyRow label="编码" value={info.encoding ?? "—"} />
</>
)}
</>
) : null}
</div>
</DialogContent>
</Dialog>
)
}
/**
* 单行属性:左侧标签 + 右侧值,可选等宽字体与复制按钮。
*/
function PropertyRow({
label,
value,
mono,
copyable,
muted,
}: {
label: string
value: React.ReactNode
mono?: boolean
copyable?: boolean
muted?: boolean
}) {
const [copied, setCopied] = useState(false)
return (
<div className="flex items-start gap-3 py-0.5">
<span className="w-24 shrink-0 pt-0.5 text-xs text-muted-foreground">{label}</span>
<span
className={`min-w-0 flex-1 break-all ${mono ? "font-mono text-xs leading-5" : "text-sm"} ${muted ? "text-muted-foreground" : ""}`}
>
{value}
</span>
{copyable && typeof value === "string" && (
<Button
variant="ghost"
size="icon-sm"
className="shrink-0"
title="复制"
onClick={() => {
void navigator.clipboard.writeText(value).then(() => {
setCopied(true)
setTimeout(() => setCopied(false), 1500)
})
}}
>
{copied ? <Check className="text-green-600" /> : <Copy />}
</Button>
)}
</div>
)
}
@@ -0,0 +1,113 @@
import { useMemo, useState } from "react"
import { Button } from "~/components/ui/button"
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "~/components/ui/dialog"
import { Input } from "~/components/ui/input"
// Windows / TFS 路径名非法字符。
const INVALID_NAME_PATTERN = /[\\/:*?"<>|]/
/**
* 重命名弹窗:同目录改名,校验非空、非法字符与同名;
* 确认后产生 rename 挂起更改(由编排层调用接口并刷新)。
*/
export function RenameDialog({
serverPath,
folder,
onConfirm,
onClose,
}: {
serverPath: string
folder: boolean
/** 确认重命名,由编排层执行 API 与刷新,返回是否成功。 */
onConfirm: (newName: string) => Promise<boolean>
onClose: () => void
}) {
const currentName = useMemo(
() => serverPath.slice(serverPath.lastIndexOf("/") + 1),
[serverPath],
)
const [name, setName] = useState(currentName)
const [busy, setBusy] = useState(false)
const trimmed = name.trim()
const validation =
trimmed.length === 0
? "名称不能为空"
: INVALID_NAME_PATTERN.test(trimmed)
? '名称不能包含 / \\ : * ? " < > | 字符'
: trimmed === currentName
? "新名称与当前名称相同"
: null
return (
<Dialog open onOpenChange={(open) => !open && !busy && onClose()}>
<DialogContent className="sm:max-w-md">
<DialogHeader>
<DialogTitle>重命名{folder ? "目录" : "文件"}</DialogTitle>
<DialogDescription className="font-mono text-xs">{serverPath}</DialogDescription>
</DialogHeader>
<div className="space-y-2">
<Input
value={name}
onChange={(event) => setName(event.target.value)}
autoFocus
onFocus={(event) => {
// 文件默认选中主名部分,便于直接输入新名称。
const dot = folder ? -1 : currentName.lastIndexOf(".")
event.target.setSelectionRange(0, dot > 0 ? dot : currentName.length)
}}
onKeyDown={(event) => {
if (event.key === "Enter" && validation == null && !busy) {
event.preventDefault()
void (async () => {
setBusy(true)
const ok = await onConfirm(trimmed)
setBusy(false)
if (ok) {
onClose()
}
})()
}
}}
/>
{validation != null && trimmed !== currentName && (
<p className="text-xs text-destructive">{validation}</p>
)}
<p className="text-xs text-muted-foreground">
重命名会产生挂起更改,签入后服务器才会生效;签入前可在挂起更改面板撤销。
</p>
</div>
<DialogFooter>
<Button variant="ghost" onClick={onClose} disabled={busy}>
取消
</Button>
<Button
disabled={validation != null || busy}
onClick={() => {
void (async () => {
setBusy(true)
const ok = await onConfirm(trimmed)
setBusy(false)
if (ok) {
onClose()
}
})()
}}
>
{busy ? "正在重命名…" : "重命名"}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
)
}
@@ -1,7 +1,8 @@
import { useCallback, useEffect, useRef, useState } from "react"
import { ChevronRight, FolderClosed, FolderOpen, Loader2, RefreshCw } from "lucide-react"
import { ChevronRight, Loader2, RefreshCw } from "lucide-react"
import { FileTargetMenu } from "~/components/app/file-target-menu"
import { FileIcon } from "~/components/explorer/file-icon"
import { Button } from "~/components/ui/button"
import { ScrollArea } from "~/components/ui/scroll-area"
import { api } from "~/lib/api"
@@ -12,6 +13,7 @@ import {
getAncestorPaths,
makeFileTarget,
normalizeServerPath,
resolveLocalPath,
} from "~/lib/tfs"
import { cn } from "~/lib/utils"
@@ -127,9 +129,11 @@ export function SourceTreePanel({
)
return (
<aside className="flex h-full w-[280px] shrink-0 flex-col border-r bg-sidebar">
<div className="flex h-9 shrink-0 items-center gap-2 border-b px-3">
<span className="text-xs font-medium text-muted-foreground">源码目录</span>
<aside className="flex h-full w-[280px] shrink-0 flex-col overflow-hidden rounded-xl border bg-card shadow-card">
<div className="flex h-9 shrink-0 items-center gap-2 border-b bg-muted/40 px-3">
<span className="text-[11px] font-medium tracking-wider text-muted-foreground uppercase">
源码目录
</span>
<span className="ml-auto max-w-28 truncate text-xs text-muted-foreground">{collection}</span>
<Button
variant="ghost"
@@ -200,6 +204,7 @@ function TreeNode({
const isSelected = selectedServerPath === path
// 未加载前默认认为可能有子目录;加载后子目录为空则视为叶子。
const isLeaf = children != null && children.length === 0
const isMapped = resolveLocalPath(mappings, path) != null
const target = makeFileTarget({ source: "tree", folder: true, serverPath: path, mappings })
return (
@@ -207,10 +212,11 @@ function TreeNode({
<FileTargetMenu target={target} onAction={onFileAction}>
<div
className={cn(
"group flex h-7 items-center rounded-md pr-1",
isSelected ? "bg-primary/10" : "hover:bg-muted",
"group flex h-7 items-center rounded-md pr-1 transition-colors duration-150",
isSelected ? "bg-sidebar-accent" : "hover:bg-sidebar-accent/60",
)}
style={{ paddingLeft: `${depth * 14 + 2}px` }}
title={path}
>
<span className="flex size-5 shrink-0 items-center justify-center">
{isLoading ? (
@@ -220,10 +226,13 @@ function TreeNode({
type="button"
aria-label={isExpanded ? "收起目录" : "展开目录"}
onClick={() => onToggle(path)}
className="flex size-5 items-center justify-center rounded text-muted-foreground hover:text-foreground"
className="flex size-5 items-center justify-center rounded text-muted-foreground transition-colors duration-150 hover:text-foreground"
>
<ChevronRight
className={cn("size-3.5 transition-transform", isExpanded && "rotate-90")}
className={cn(
"size-3.5 transition-transform duration-200 ease-out-quart",
isExpanded && "rotate-90",
)}
/>
</button>
)}
@@ -233,11 +242,7 @@ function TreeNode({
onClick={() => onSelect(path)}
className="flex min-w-0 flex-1 items-center gap-1.5 text-left"
>
{isExpanded && !isLeaf ? (
<FolderOpen className="size-3.5 shrink-0 text-muted-foreground" />
) : (
<FolderClosed className="size-3.5 shrink-0 text-muted-foreground" />
)}
<FileIcon name={name} folder mapped={isMapped} expanded={isExpanded && !isLeaf} />
<span
className={cn(
"truncate text-sm",
@@ -249,23 +254,26 @@ function TreeNode({
</button>
</div>
</FileTargetMenu>
{isExpanded &&
children?.map((child) => (
<TreeNode
key={child.serverPath}
path={child.serverPath}
name={child.name}
depth={depth + 1}
mappings={mappings}
childrenByPath={childrenByPath}
expanded={expanded}
loadingPaths={loadingPaths}
selectedServerPath={selectedServerPath}
onToggle={onToggle}
onSelect={onSelect}
onFileAction={onFileAction}
/>
))}
{isExpanded && children != null && children.length > 0 && (
<div className="animate-in fade-in slide-in-from-top-1 duration-200">
{children.map((child) => (
<TreeNode
key={child.serverPath}
path={child.serverPath}
name={child.name}
depth={depth + 1}
mappings={mappings}
childrenByPath={childrenByPath}
expanded={expanded}
loadingPaths={loadingPaths}
selectedServerPath={selectedServerPath}
onToggle={onToggle}
onSelect={onSelect}
onFileAction={onFileAction}
/>
))}
</div>
)}
</div>
)
}
@@ -0,0 +1,468 @@
import { useCallback, useEffect, useState } from "react"
import { FolderSearch, Loader2, Pencil, Plus, Trash2 } from "lucide-react"
import { ConfirmDialog } from "~/components/app/confirm-dialog"
import { MappingDialog } from "~/components/explorer/mapping-dialog"
import { Badge } from "~/components/ui/badge"
import { Button } from "~/components/ui/button"
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "~/components/ui/dialog"
import { Input } from "~/components/ui/input"
import { Label } from "~/components/ui/label"
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "~/components/ui/table"
import { api } from "~/lib/api"
import type { CheckMappingTargetResult, MappingInfo, WorkspaceInfo } from "~/lib/api"
import { isElectron, pathsExist, selectDirectory } from "~/lib/electron"
import type { WorkspaceSession } from "~/lib/tfs"
/**
* 工作区集中管理弹窗:展示 Workspace 信息与全部 Mapping,
* 支持新增、删除与修改本地路径(删旧 + 加新),对齐 VS 的 Edit Workspace。
*/
export function WorkspaceManageDialog({
session,
onClose,
onMappingsChanged,
}: {
session: WorkspaceSession
onClose: () => void
/** Mapping 集合变化(新增 / 删除 / 修改)后回调上层刷新。 */
onMappingsChanged: (mappings: MappingInfo[]) => void
}) {
const [info, setInfo] = useState<WorkspaceInfo | null>(null)
// 各 Mapping 本地目录存在性(null 表示无法检测,如非 Electron 环境)。
const [existsMap, setExistsMap] = useState<Record<string, boolean> | null>(null)
const [error, setError] = useState<string | null>(null)
// 新增映射:输入服务端路径后打开既有 MappingDialog。
const [addServerPath, setAddServerPath] = useState("")
const [addOpen, setAddOpen] = useState(false)
const [editMapping, setEditMapping] = useState<MappingInfo | null>(null)
const [confirmDelete, setConfirmDelete] = useState<MappingInfo | null>(null)
// Workspace 详细信息(Owner / Computer)通过 ensure 接口幂等获取。
useEffect(() => {
let active = true
void (async () => {
const result = await api.ensureWorkspace({})
if (!active) {
return
}
if (result.ok && result.data) {
setInfo(result.data.workspace)
}
})()
return () => {
active = false
}
}, [])
// Mapping 集合变化时重新检测本地目录存在性。
useEffect(() => {
let active = true
void (async () => {
const result = await pathsExist(session.mappings.map((mapping) => mapping.localPath))
if (active) {
setExistsMap(result)
}
})()
return () => {
active = false
}
}, [session.mappings])
/**
* 删除 Mapping(仅解除映射,不删除本地文件),成功后回调上层刷新。
*/
const handleDelete = useCallback(
async (mapping: MappingInfo) => {
const result = await api.deleteMapping({ serverPath: mapping.serverPath })
if (!result.ok) {
setError(result.errorMessage ?? "删除 Mapping 失败")
return
}
setError(null)
onMappingsChanged(result.data?.mappings ?? [])
},
[onMappingsChanged],
)
const trimmedAddPath = addServerPath.trim()
const addPathValid = trimmedAddPath.startsWith("$/") && trimmedAddPath.length > 2
return (
<Dialog open onOpenChange={(open) => !open && onClose()}>
<DialogContent className="flex max-h-[85svh] flex-col sm:max-w-3xl">
<DialogHeader>
<DialogTitle>工作区管理</DialogTitle>
<DialogDescription>查看 Workspace 信息,集中管理全部本地映射</DialogDescription>
</DialogHeader>
<div className="grid shrink-0 grid-cols-2 gap-x-6 gap-y-1 rounded-md border bg-muted/30 px-3 py-2 text-xs">
<InfoRow label="Workspace" value={session.workspace} mono />
<InfoRow label="服务器" value={session.serverUri} mono />
<InfoRow label="Collection" value={session.collection} />
<InfoRow label="Owner" value={info?.ownerName ?? "…"} />
<InfoRow label="Computer" value={info?.computer ?? "…"} />
<InfoRow label="Mapping 数量" value={String(session.mappings.length)} />
</div>
<div className="flex shrink-0 items-end gap-2">
<div className="min-w-0 flex-1 space-y-1">
<Label htmlFor="addServerPath" className="text-xs">
新增映射的服务端路径
</Label>
<Input
id="addServerPath"
value={addServerPath}
onChange={(event) => setAddServerPath(event.target.value)}
placeholder="$/Project/Folder"
className="h-8 font-mono text-xs"
/>
</div>
<Button
size="sm"
disabled={!addPathValid}
onClick={() => setAddOpen(true)}
title={addPathValid ? undefined : "请输入以 $/ 开头的服务端路径"}
>
<Plus data-icon="inline-start" />
新增映射…
</Button>
</div>
<div className="min-h-0 flex-1 overflow-auto rounded-md border">
{session.mappings.length === 0 ? (
<div className="flex h-32 items-center justify-center text-sm text-muted-foreground">
当前 Workspace 还没有任何映射
</div>
) : (
<Table>
<TableHeader className="sticky top-0 z-10 bg-background">
<TableRow className="hover:bg-transparent">
<TableHead className="h-8 text-xs text-muted-foreground">服务端路径</TableHead>
<TableHead className="h-8 text-xs text-muted-foreground">本地路径</TableHead>
<TableHead className="h-8 w-20 text-xs text-muted-foreground">本地目录</TableHead>
<TableHead className="h-8 w-20 text-xs text-muted-foreground" />
</TableRow>
</TableHeader>
<TableBody>
{session.mappings.map((mapping) => {
const exists = existsMap?.[mapping.localPath]
return (
<TableRow key={mapping.serverPath} className="cursor-default select-none">
<TableCell
className="max-w-0 truncate py-1.5 font-mono text-xs"
title={mapping.serverPath}
>
{mapping.serverPath}
</TableCell>
<TableCell
className="max-w-0 truncate py-1.5 font-mono text-xs"
title={mapping.localPath}
>
{mapping.localPath}
</TableCell>
<TableCell className="py-1.5">
{existsMap == null ? (
<span className="text-xs text-muted-foreground">无法检测</span>
) : exists ? (
<Badge variant="secondary" className="bg-muted text-foreground/80">
存在
</Badge>
) : (
<Badge
variant="secondary"
className="bg-red-500/10 text-red-700"
>
不存在
</Badge>
)}
</TableCell>
<TableCell className="py-1.5">
<div className="flex items-center gap-0.5">
<Button
variant="ghost"
size="icon-sm"
title="修改本地路径…"
onClick={() => setEditMapping(mapping)}
>
<Pencil />
</Button>
<Button
variant="ghost"
size="icon-sm"
className="text-destructive hover:text-destructive"
title="删除映射…"
onClick={() => setConfirmDelete(mapping)}
>
<Trash2 />
</Button>
</div>
</TableCell>
</TableRow>
)
})}
</TableBody>
</Table>
)}
</div>
{error && <p className="shrink-0 text-sm text-destructive">{error}</p>}
<p className="shrink-0 text-xs text-muted-foreground">
删除映射只解除服务端目录与本地目录的关联,不会删除本地已下载的文件。
</p>
{addOpen && (
<MappingDialog
serverPath={trimmedAddPath}
onClose={() => setAddOpen(false)}
onCreated={(mappings) => {
onMappingsChanged(mappings)
setAddOpen(false)
setAddServerPath("")
}}
/>
)}
{editMapping && (
<EditMappingDialog
mapping={editMapping}
onClose={() => setEditMapping(null)}
onChanged={(mappings) => {
onMappingsChanged(mappings)
setEditMapping(null)
}}
/>
)}
{confirmDelete && (
<ConfirmDialog
title="删除映射"
description={
<>
<p>
将解除 <span className="font-mono text-xs">{confirmDelete.serverPath}</span>{" "}
与本地目录的映射。
</p>
<p className="mt-2 text-muted-foreground">
本地已下载的文件不会被删除;该目录下的挂起更改将无法继续签入。
</p>
</>
}
confirmLabel="删除映射"
danger
onConfirm={async () => {
await handleDelete(confirmDelete)
setConfirmDelete(null)
}}
onClose={() => setConfirmDelete(null)}
/>
)}
</DialogContent>
</Dialog>
)
}
/**
* 工作区信息单行展示。
*/
function InfoRow({ label, value, mono }: { label: string; value: string; mono?: boolean }) {
return (
<div className="flex min-w-0 items-center gap-2">
<span className="w-24 shrink-0 text-muted-foreground">{label}</span>
<span className={`min-w-0 truncate ${mono ? "font-mono" : ""}`} title={value}>
{value}
</span>
</div>
)
}
/**
* 修改 Mapping 本地路径弹窗:选择新的本地父目录并预校验,
* 确认后按「删旧 + 加新」方式调整映射(不迁移本地内容)。
*/
function EditMappingDialog({
mapping,
onClose,
onChanged,
}: {
mapping: MappingInfo
onClose: () => void
onChanged: (mappings: MappingInfo[]) => void
}) {
const [parentPath, setParentPath] = useState("")
const [check, setCheck] = useState<CheckMappingTargetResult | null>(null)
const [checking, setChecking] = useState(false)
const [busy, setBusy] = useState(false)
const [error, setError] = useState<string | null>(null)
/**
* 通过系统目录选择器选择新的本地父目录。
*/
const handleBrowse = useCallback(async () => {
const selected = await selectDirectory()
if (selected) {
setParentPath(selected)
}
}, [])
// 与创建映射一致:父目录变化时由后端预校验最终目标路径。
useEffect(() => {
const trimmed = parentPath.trim()
if (trimmed.length === 0) {
setCheck(null)
return
}
let active = true
setChecking(true)
const timer = setTimeout(() => {
void (async () => {
const result = await api.checkMappingTarget({
serverPath: mapping.serverPath,
localParentPath: trimmed,
})
if (!active) {
return
}
setChecking(false)
if (!result.ok || !result.data) {
setCheck(null)
setError(result.errorMessage ?? "目标路径校验失败")
return
}
setError(null)
setCheck(result.data)
})()
}, 300)
return () => {
active = false
clearTimeout(timer)
}
}, [parentPath, mapping.serverPath])
const exists = check?.exists === true
const canConfirm = check != null && !exists && !busy && !checking
/**
* 删旧 + 加新调整映射本地路径,成功后回调最新 mappings。
*/
const handleConfirm = useCallback(async () => {
if (!check) {
return
}
setBusy(true)
setError(null)
const removed = await api.deleteMapping({ serverPath: mapping.serverPath })
if (!removed.ok) {
setBusy(false)
setError(removed.errorMessage ?? "删除原映射失败")
return
}
const added = await api.addMapping({
serverPath: mapping.serverPath,
localPath: check.targetPath,
getLatest: false,
})
setBusy(false)
if (!added.ok) {
setError(`${added.errorMessage ?? "创建新映射失败"}(原映射已删除,请重新映射)`)
return
}
const mappings = await api.listMappings()
onChanged(mappings.data?.mappings ?? [])
}, [check, mapping.serverPath, onChanged])
return (
<Dialog open onOpenChange={(open) => !open && !busy && onClose()}>
<DialogContent className="sm:max-w-lg">
<DialogHeader>
<DialogTitle>修改本地路径</DialogTitle>
<DialogDescription className="font-mono text-xs">{mapping.serverPath}</DialogDescription>
</DialogHeader>
<div className="space-y-4">
<div className="space-y-1.5">
<Label>当前本地路径</Label>
<p className="rounded-md border bg-muted/40 px-2.5 py-1.5 font-mono text-xs">
{mapping.localPath}
</p>
</div>
<div className="space-y-1.5">
<Label htmlFor="newParentPath">新的本地父目录</Label>
<div className="flex gap-2">
<Input
id="newParentPath"
placeholder="/Users/me/tfs"
value={parentPath}
onChange={(event) => setParentPath(event.target.value)}
disabled={busy}
className="font-mono text-xs"
/>
{isElectron() && (
<Button
type="button"
variant="outline"
size="icon"
onClick={() => void handleBrowse()}
disabled={busy}
aria-label="浏览本地目录"
>
<FolderSearch />
</Button>
)}
</div>
</div>
{checking && (
<p className="flex items-center gap-1.5 text-xs text-muted-foreground">
<Loader2 className="size-3 animate-spin" />
正在校验目标路径…
</p>
)}
{check && !checking && (
<div className="space-y-1.5">
<Label>新映射路径</Label>
<p className="rounded-md border bg-muted/40 px-2.5 py-1.5 font-mono text-xs">
{check.targetPath}
</p>
{exists && (
<p className="text-xs font-medium text-destructive">目标目录已存在,禁止映射</p>
)}
</div>
)}
<p className="text-xs text-muted-foreground">
修改方式为「删除原映射 + 创建新映射」:原本地目录内容保留但不再与服务端关联,
新目录需重新执行获取最新。
</p>
{error && <p className="text-sm text-destructive">{error}</p>}
</div>
<DialogFooter>
<Button variant="ghost" onClick={onClose} disabled={busy}>
取消
</Button>
<Button onClick={() => void handleConfirm()} disabled={!canConfirm}>
{busy ? "正在修改…" : "修改本地路径"}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
)
}
@@ -1,7 +1,8 @@
import { useCallback, useMemo, useState } from "react"
import { FileText, FolderClosed, ListChecks, Loader2, RefreshCw } from "lucide-react"
import { ChevronRight, ListChecks, Loader2, RefreshCw } from "lucide-react"
import { FileTargetMenu } from "~/components/app/file-target-menu"
import { FileIcon } from "~/components/explorer/file-icon"
import { Badge } from "~/components/ui/badge"
import { Button } from "~/components/ui/button"
import { Checkbox } from "~/components/ui/checkbox"
@@ -9,12 +10,112 @@ import { ScrollArea } from "~/components/ui/scroll-area"
import { Textarea } from "~/components/ui/textarea"
import type { MappingInfo, PendingChange } from "~/lib/api"
import type { FileActionId, FileTarget } from "~/lib/tfs"
import { makeFileTarget, statusBadgeClass, statusLabel } from "~/lib/tfs"
import {
SERVER_ROOT_PATH,
makeFileTarget,
normalizeServerPath,
statusBadgeClass,
statusLabel,
} from "~/lib/tfs"
import { cn } from "~/lib/utils"
// 挂起更改目录树节点:目录节点聚合子项,文件/变更目录节点携带 change。
interface ChangeNode {
path: string
name: string
isDir: boolean
change: PendingChange | null
children: Map<string, ChangeNode>
}
/**
* 右侧 Changes 面板:Pending Changes 的 Included / Excluded 分组维护、
* 项级右键菜单,以及作为签入唯一入口的 comment + Checkin 区域。
* 把扁平的挂起更改按 serverPath 还原成目录树。中间目录自动补齐为目录节点,
* 末段挂载对应 change(变更本身是目录时该节点 isDir=true,可继续容纳子项)。
*/
function buildChangeTree(changes: PendingChange[]): ChangeNode {
const root: ChangeNode = {
path: SERVER_ROOT_PATH,
name: SERVER_ROOT_PATH,
isDir: true,
change: null,
children: new Map(),
}
for (const change of changes) {
const normalized = normalizeServerPath(change.serverPath)
const relative =
normalized === SERVER_ROOT_PATH ? "" : normalized.slice(SERVER_ROOT_PATH.length)
const segments = relative.length > 0 ? relative.split("/") : []
let current = root
let currentPath = SERVER_ROOT_PATH
segments.forEach((segment, index) => {
currentPath =
currentPath === SERVER_ROOT_PATH
? `${SERVER_ROOT_PATH}${segment}`
: `${currentPath}/${segment}`
let child = current.children.get(segment)
if (!child) {
child = { path: currentPath, name: segment, isDir: true, change: null, children: new Map() }
current.children.set(segment, child)
}
if (index === segments.length - 1) {
child.change = change
child.isDir = change.folder
}
current = child
})
}
return root
}
/**
* 收集某节点子树内全部挂起更改的 serverPath(含节点自身的 change),
* 用于目录节点的计数与三态复选。
*/
function collectChangePaths(node: ChangeNode): string[] {
const result: string[] = []
const walk = (current: ChangeNode) => {
if (current.change) {
result.push(current.change.serverPath)
}
for (const child of current.children.values()) {
walk(child)
}
}
walk(node)
return result
}
// 目录/文件混排排序:目录在前,名称不区分大小写升序。
function sortNodes(nodes: ChangeNode[]): ChangeNode[] {
return [...nodes].sort((a, b) => {
if (a.isDir !== b.isDir) {
return a.isDir ? -1 : 1
}
return a.name.localeCompare(b.name, undefined, { sensitivity: "base" })
})
}
/**
* 路径压缩:把「只有单个子目录且自身无变更」的目录链合并为一行(VS Code 风格),
* 返回最终展示节点与合并后的名称。
*/
function compactDir(node: ChangeNode): { node: ChangeNode; label: string } {
let current = node
const parts = [node.name]
while (current.isDir && !current.change && current.children.size === 1) {
const only = [...current.children.values()][0]
if (!only.isDir) {
break
}
parts.push(only.name)
current = only
}
return { node: current, label: parts.join("/") }
}
/**
* 右侧 Changes 面板:以服务端目录树呈现 Pending Changes,目录节点支持折叠与
* 三态复选(级联子项 Included / Excluded),并作为签入唯一入口提供 comment + Checkin。
*/
export function ChangesPanel({
mappings,
@@ -23,7 +124,7 @@ export function ChangesPanel({
loading,
error,
checkinBusy,
onToggleExcluded,
onSetExcluded,
onCheckin,
onFileAction,
onRefresh,
@@ -34,24 +135,40 @@ export function ChangesPanel({
loading: boolean
error: string | null
checkinBusy: boolean
onToggleExcluded: (serverPath: string) => void
onSetExcluded: (serverPaths: string[], excluded: boolean) => void
onCheckin: (paths: string[], comment: string) => Promise<boolean>
onFileAction: (target: FileTarget, action: FileActionId) => void
onRefresh: () => void
}) {
const [comment, setComment] = useState("")
// 已折叠的目录 path 集合;默认全部展开。
const [collapsed, setCollapsed] = useState<Set<string>>(new Set())
const tree = useMemo(() => buildChangeTree(pendingChanges), [pendingChanges])
const rootChildren = useMemo(() => sortNodes([...tree.children.values()]), [tree])
const included = useMemo(
() => pendingChanges.filter((change) => !excludedKeys.has(change.serverPath)),
[pendingChanges, excludedKeys],
)
const excluded = useMemo(
() => pendingChanges.filter((change) => excludedKeys.has(change.serverPath)),
[pendingChanges, excludedKeys],
)
const canCheckin = included.length > 0 && comment.trim().length > 0 && !checkinBusy
/**
* 折叠 / 展开目录节点。
*/
const toggleCollapsed = useCallback((path: string) => {
setCollapsed((prev) => {
const next = new Set(prev)
if (next.has(path)) {
next.delete(path)
} else {
next.add(path)
}
return next
})
}, [])
/**
* 提交签入:只提交 Included 项,成功后清空注释。
*/
@@ -66,9 +183,11 @@ export function ChangesPanel({
}, [onCheckin, included, comment])
return (
<aside className="flex h-full w-[340px] shrink-0 flex-col border-l bg-sidebar">
<div className="flex h-9 shrink-0 items-center gap-2 border-b px-3">
<span className="text-xs font-medium text-muted-foreground">挂起更改</span>
<aside className="flex h-full w-[340px] shrink-0 flex-col overflow-hidden rounded-xl border bg-card shadow-card">
<div className="flex h-9 shrink-0 items-center gap-2 border-b bg-muted/40 px-3">
<span className="text-[11px] font-medium tracking-wider text-muted-foreground uppercase">
挂起更改
</span>
{pendingChanges.length > 0 && (
<span className="ml-auto text-xs text-muted-foreground">{pendingChanges.length} 项</span>
)}
@@ -104,38 +223,19 @@ export function ChangesPanel({
) : (
<ScrollArea className="min-h-0 flex-1">
<div className="p-2">
<GroupHeader label="Included" count={included.length} />
{included.length === 0 && (
<p className="px-2 py-1.5 text-xs text-muted-foreground">
没有要签入的更改,勾选下方 Excluded 项可移回
</p>
)}
{included.map((change) => (
<PendingRow
key={change.serverPath}
change={change}
included
{rootChildren.map((node) => (
<ChangeTreeNode
key={node.path}
node={node}
depth={0}
mappings={mappings}
onToggleExcluded={onToggleExcluded}
excludedKeys={excludedKeys}
collapsed={collapsed}
onToggleCollapsed={toggleCollapsed}
onSetExcluded={onSetExcluded}
onFileAction={onFileAction}
/>
))}
{excluded.length > 0 && (
<>
<GroupHeader label="Excluded" count={excluded.length} className="mt-3" />
{excluded.map((change) => (
<PendingRow
key={change.serverPath}
change={change}
included={false}
mappings={mappings}
onToggleExcluded={onToggleExcluded}
onFileAction={onFileAction}
/>
))}
</>
)}
</div>
</ScrollArea>
)}
@@ -150,9 +250,7 @@ export function ChangesPanel({
className="resize-none text-sm"
/>
<div className="flex items-center justify-between gap-2">
<span className="text-xs text-muted-foreground">
将签入 {included.length} 项
</span>
<span className="text-xs text-muted-foreground">将签入 {included.length} 项</span>
<Button size="sm" disabled={!canCheckin} onClick={() => void handleCheckin()}>
{checkinBusy ? (
<>
@@ -173,39 +271,155 @@ export function ChangesPanel({
}
/**
* 分组标题行。
* 目录树节点:目录节点渲染折叠箭头 + 三态复选 + 计数并递归子节点;
* 文件 / 变更目录节点渲染单项复选 + 状态徽标,整行支持统一右键菜单。
*/
function GroupHeader({
label,
count,
className,
function ChangeTreeNode({
node,
depth,
mappings,
excludedKeys,
collapsed,
onToggleCollapsed,
onSetExcluded,
onFileAction,
}: {
label: string
count: number
className?: string
node: ChangeNode
depth: number
mappings: MappingInfo[]
excludedKeys: Set<string>
collapsed: Set<string>
onToggleCollapsed: (path: string) => void
onSetExcluded: (serverPaths: string[], excluded: boolean) => void
onFileAction: (target: FileTarget, action: FileActionId) => void
}) {
// 纯目录节点(自身无 change)做路径压缩;变更节点保持原样。
const { node: displayNode, label } =
node.isDir && !node.change ? compactDir(node) : { node, label: node.name }
const indent = depth * 12 + 4
const change = displayNode.change
// 叶子:文件,或没有子项的变更目录。
const isLeaf = !displayNode.isDir || displayNode.children.size === 0
if (isLeaf && change) {
return (
<LeafRow
node={displayNode}
label={label}
change={change}
indent={indent}
mappings={mappings}
excluded={excludedKeys.has(change.serverPath)}
onSetExcluded={onSetExcluded}
onFileAction={onFileAction}
/>
)
}
// 目录节点:聚合子树变更,决定三态与计数。
const descendantPaths = collectChangePaths(displayNode)
const excludedCount = descendantPaths.filter((path) => excludedKeys.has(path)).length
const checkboxState: boolean | "indeterminate" =
excludedCount === 0 ? true : excludedCount === descendantPaths.length ? false : "indeterminate"
const expanded = !collapsed.has(displayNode.path)
const children = sortNodes([...displayNode.children.values()])
// 已全部 Included 时点击改为全部排除,否则全部移回 Included。
const handleToggle = () => onSetExcluded(descendantPaths, checkboxState === true)
const header = (
<div
className="flex h-8 cursor-default items-center gap-1.5 rounded-md pr-2 select-none hover:bg-muted"
style={{ paddingLeft: `${indent}px` }}
title={displayNode.path}
>
<button
type="button"
aria-label={expanded ? "收起目录" : "展开目录"}
onClick={() => onToggleCollapsed(displayNode.path)}
className="flex size-4 shrink-0 items-center justify-center rounded text-muted-foreground transition-colors hover:text-foreground"
>
<ChevronRight
className={cn("size-3.5 transition-transform duration-200", expanded && "rotate-90")}
/>
</button>
<Checkbox
checked={checkboxState}
onCheckedChange={handleToggle}
aria-label={checkboxState === true ? "排除该目录全部更改" : "签入该目录全部更改"}
/>
<FileIcon name={label} folder mapped={false} expanded={expanded} />
<span className="min-w-0 flex-1 truncate text-sm font-medium">{label}</span>
{change && (
<Badge
variant="secondary"
className={cn("shrink-0 gap-1.5 rounded-md", statusBadgeClass(change.status))}
>
<span className="size-1.5 rounded-full bg-current opacity-60" />
{statusLabel(change.status)}
</Badge>
)}
<span className="shrink-0 text-[11px] text-muted-foreground/70">{descendantPaths.length}</span>
</div>
)
return (
<div className={cn("flex items-center gap-1.5 px-2 py-1", className)}>
<span className="text-xs font-medium text-muted-foreground">{label}</span>
<span className="text-xs text-muted-foreground/70">{count}</span>
<div>
{change ? (
<FolderTargetMenu
node={displayNode}
change={change}
mappings={mappings}
onFileAction={onFileAction}
>
{header}
</FolderTargetMenu>
) : (
header
)}
{expanded && children.length > 0 && (
<div>
{children.map((child) => (
<ChangeTreeNode
key={child.path}
node={child}
depth={depth + 1}
mappings={mappings}
excludedKeys={excludedKeys}
collapsed={collapsed}
onToggleCollapsed={onToggleCollapsed}
onSetExcluded={onSetExcluded}
onFileAction={onFileAction}
/>
))}
</div>
)}
</div>
)
}
/**
* 单条挂起更改:勾选维护 Included / Excluded,整行支持统一右键菜单。
* 文件 / 变更目录叶子行:复选框维护 Included / Excluded,整行支持统一右键菜单。
*/
function PendingRow({
function LeafRow({
node,
label,
change,
included,
indent,
mappings,
onToggleExcluded,
excluded,
onSetExcluded,
onFileAction,
}: {
node: ChangeNode
label: string
change: PendingChange
included: boolean
indent: number
mappings: MappingInfo[]
onToggleExcluded: (serverPath: string) => void
excluded: boolean
onSetExcluded: (serverPaths: string[], excluded: boolean) => void
onFileAction: (target: FileTarget, action: FileActionId) => void
}) {
const target = makeFileTarget({
@@ -215,38 +429,65 @@ function PendingRow({
mappings,
pendingStatus: change.status,
})
const displayName =
change.status === "pendingRename" && change.sourceServerPath
? `${change.sourceServerPath.slice(change.sourceServerPath.lastIndexOf("/") + 1)} → ${change.name}`
: label
return (
<FileTargetMenu target={target} onAction={onFileAction}>
<div
className={cn(
"flex h-9 cursor-default items-center gap-2 rounded-md px-2 select-none hover:bg-muted",
!included && "opacity-60",
"flex h-8 cursor-default items-center gap-1.5 rounded-md pr-2 select-none hover:bg-muted",
excluded && "opacity-60",
)}
style={{ paddingLeft: `${indent + 22}px` }}
title={change.serverPath}
>
<Checkbox
checked={included}
onCheckedChange={() => onToggleExcluded(change.serverPath)}
aria-label={included ? "移到 Excluded" : "移回 Included"}
checked={!excluded}
onCheckedChange={() => onSetExcluded([change.serverPath], !excluded)}
aria-label={!excluded ? "移到 Excluded" : "移回 Included"}
/>
{change.folder ? (
<FolderClosed className="size-3.5 shrink-0 text-muted-foreground" />
) : (
<FileText className="size-3.5 shrink-0 text-muted-foreground" />
)}
<span className="min-w-0 flex-1">
<span className="block truncate text-sm">{change.name}</span>
<span className="block truncate font-mono text-[10px] leading-3 text-muted-foreground">
{change.serverPath}
</span>
</span>
<FileIcon name={node.name} folder={change.folder} />
<span className="min-w-0 flex-1 truncate text-sm">{displayName}</span>
<Badge
variant="secondary"
className={cn("shrink-0 rounded-md", statusBadgeClass(change.status))}
className={cn("shrink-0 gap-1.5 rounded-md", statusBadgeClass(change.status))}
>
<span className="size-1.5 rounded-full bg-current opacity-60" />
{statusLabel(change.status)}
</Badge>
</div>
</FileTargetMenu>
)
}
/**
* 变更目录节点的右键菜单包装:复用统一动作模型,对目录类挂起更改提供动作。
*/
function FolderTargetMenu({
node,
change,
mappings,
onFileAction,
children,
}: {
node: ChangeNode
change: PendingChange
mappings: MappingInfo[]
onFileAction: (target: FileTarget, action: FileActionId) => void
children: React.ReactNode
}) {
const target = makeFileTarget({
source: "pending",
folder: true,
serverPath: node.path,
mappings,
pendingStatus: change.status,
})
return (
<FileTargetMenu target={target} onAction={onFileAction}>
{children}
</FileTargetMenu>
)
}
+125 -15
View File
@@ -1,12 +1,23 @@
import { useCallback, useEffect, useMemo, useState } from "react"
import { CheckCircle2, Loader2, RefreshCw, XCircle } from "lucide-react"
import { Bot, CheckCircle2, Loader2, RefreshCw, User, XCircle } from "lucide-react"
import { Badge } from "~/components/ui/badge"
import { Button } from "~/components/ui/button"
import { ScrollArea } from "~/components/ui/scroll-area"
import { api } from "~/lib/api"
import type { OperationLogEntry } from "~/lib/api"
import type { OperationLogEntry, OperationSource } from "~/lib/api"
import { cn, formatDateTime } from "~/lib/utils"
// 来源过滤选项:全部 / 仅手动 / 仅 AI。
type SourceFilter = "all" | "ui" | "mcp"
/**
* 归一化操作来源:旧记录可能缺省 source,统一按「手动(ui)」处理。
*/
function normalizeSource(entry: OperationLogEntry): OperationSource {
return entry.source === "mcp" ? "mcp" : "ui"
}
/**
* 把毫秒耗时格式化为可读文本。
*/
@@ -33,6 +44,7 @@ export function ConsolePanel({
const [logs, setLogs] = useState<OperationLogEntry[]>([])
const [loading, setLoading] = useState(false)
const [error, setError] = useState<string | null>(null)
const [sourceFilter, setSourceFilter] = useState<SourceFilter>("all")
/**
* 拉取最近操作日志。
@@ -53,25 +65,61 @@ export function ConsolePanel({
void loadLogs()
}, [loadLogs, refreshToken])
// 最新的操作排在最上面。
const ordered = useMemo(
() => [...logs].sort((a, b) => b.startedAt - a.startedAt),
[logs],
)
// 各来源计数,供过滤按钮展示数量。
const counts = useMemo(() => {
let mcp = 0
for (const entry of logs) {
if (normalizeSource(entry) === "mcp") {
mcp += 1
}
}
return { all: logs.length, mcp, ui: logs.length - mcp }
}, [logs])
// 按来源过滤后,最新的操作排在最上面。
const ordered = useMemo(() => {
const filtered =
sourceFilter === "all"
? logs
: logs.filter((entry) => normalizeSource(entry) === sourceFilter)
return [...filtered].sort((a, b) => b.startedAt - a.startedAt)
}, [logs, sourceFilter])
return (
<footer className="flex h-[180px] shrink-0 flex-col border-t bg-background">
<div className="flex h-8 shrink-0 items-center gap-2 border-b px-3">
<span className="text-xs font-medium text-muted-foreground">操作日志</span>
<footer className="flex h-full flex-col overflow-hidden rounded-xl border bg-card shadow-card">
<div className="flex h-8 shrink-0 items-center gap-2 border-b bg-muted/40 px-3">
<span className="text-[11px] font-medium tracking-wider text-muted-foreground uppercase">
操作日志
</span>
{busy && (
<span className="flex items-center gap-1.5 text-xs text-primary">
<Loader2 className="size-3 animate-spin" />
{busyText ?? "正在执行…"}
</span>
)}
<span className="ml-auto text-xs text-muted-foreground">
{ordered.length > 0 && `${ordered.length} 条`}
</span>
{/* 来源过滤:全部 / 手动 / AI */}
<div className="ml-auto flex items-center gap-0.5 rounded-md border bg-background/60 p-0.5">
<SourceFilterButton
active={sourceFilter === "all"}
label="全部"
count={counts.all}
onClick={() => setSourceFilter("all")}
/>
<SourceFilterButton
active={sourceFilter === "ui"}
label="手动"
count={counts.ui}
onClick={() => setSourceFilter("ui")}
/>
<SourceFilterButton
active={sourceFilter === "mcp"}
label="AI"
count={counts.mcp}
onClick={() => setSourceFilter("mcp")}
/>
</div>
<Button
variant="ghost"
size="icon-xs"
@@ -88,14 +136,21 @@ export function ConsolePanel({
<p className="px-3 py-2 text-xs text-destructive">{error}</p>
) : ordered.length === 0 ? (
<p className="px-3 py-2 text-xs text-muted-foreground">
{loading ? "正在加载操作日志…" : "暂无操作日志"}
{loading
? "正在加载操作日志…"
: sourceFilter === "mcp"
? "暂无 AI 操作记录"
: sourceFilter === "ui"
? "暂无手动操作记录"
: "暂无操作日志"}
</p>
) : (
<ul className="px-2 py-1">
{ordered.map((entry, index) => (
<li
key={`${entry.startedAt}-${entry.operation}-${index}`}
className="flex h-7 items-center gap-2 rounded px-1.5 text-xs hover:bg-muted"
className="animate-in fade-in slide-in-from-top-1 flex h-7 items-center gap-2 rounded fill-mode-backwards px-1.5 text-xs duration-200 transition-colors hover:bg-muted"
style={{ animationDelay: `${Math.min(index, 6) * 25}ms` }}
title={entry.errorMessage ?? entry.summary}
>
{entry.success ? (
@@ -103,6 +158,7 @@ export function ConsolePanel({
) : (
<XCircle className="size-3.5 shrink-0 text-destructive" />
)}
<SourceBadge source={normalizeSource(entry)} />
<span className="w-36 shrink-0 truncate font-mono text-muted-foreground">
{entry.operation}
</span>
@@ -126,3 +182,57 @@ export function ConsolePanel({
</footer>
)
}
/**
* 来源过滤按钮:高亮当前选中项,并显示该来源的记录条数。
*/
function SourceFilterButton({
active,
label,
count,
onClick,
}: {
active: boolean
label: string
count: number
onClick: () => void
}) {
return (
<button
type="button"
onClick={onClick}
className={cn(
"rounded px-1.5 py-0.5 text-[11px] leading-none transition-colors",
active
? "bg-primary text-primary-foreground"
: "text-muted-foreground hover:bg-muted hover:text-foreground",
)}
>
{label}
<span className={cn("ml-1 tabular-nums", active ? "opacity-80" : "opacity-60")}>{count}</span>
</button>
)
}
/**
* 来源徽章:AI(MCP 调用)用主色高亮,手动(桌面端)用中性色,便于一眼区分。
*/
function SourceBadge({ source }: { source: OperationSource }) {
if (source === "mcp") {
return (
<Badge
variant="secondary"
className="h-4 shrink-0 gap-0.5 px-1 text-[10px] bg-violet-500/15 text-violet-600 dark:text-violet-300"
>
<Bot className="size-2.5" />
AI
</Badge>
)
}
return (
<Badge variant="outline" className="h-4 shrink-0 gap-0.5 px-1 text-[10px] text-muted-foreground">
<User className="size-2.5" />
手动
</Badge>
)
}
+1 -1
View File
@@ -5,7 +5,7 @@ import { Slot } from "radix-ui"
import { cn } from "~/lib/utils"
const buttonVariants = cva(
"group/button inline-flex shrink-0 items-center justify-center rounded-lg border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
"group/button inline-flex shrink-0 items-center justify-center rounded-lg border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all duration-150 outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px active:not-aria-[haspopup]:scale-[0.98] disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
{
variants: {
variant: {
+5 -5
View File
@@ -2,27 +2,27 @@ import * as React from "react"
import { Checkbox as CheckboxPrimitive } from "radix-ui"
import { cn } from "~/lib/utils"
import { CheckIcon } from "lucide-react"
import { CheckIcon, MinusIcon } from "lucide-react"
function Checkbox({
className,
...props
}: React.ComponentProps<typeof CheckboxPrimitive.Root>) {
const indeterminate = props.checked === "indeterminate"
return (
<CheckboxPrimitive.Root
data-slot="checkbox"
className={cn(
"peer relative flex size-4 shrink-0 items-center justify-center rounded-[4px] border border-input transition-colors outline-none group-has-disabled/field:opacity-50 after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 aria-invalid:aria-checked:border-primary dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-checked:border-primary data-checked:bg-primary data-checked:text-primary-foreground dark:data-checked:bg-primary",
"peer relative flex size-4 shrink-0 items-center justify-center rounded-[4px] border border-input transition-colors outline-none group-has-disabled/field:opacity-50 after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 aria-invalid:aria-checked:border-primary dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-checked:border-primary data-checked:bg-primary data-checked:text-primary-foreground dark:data-checked:bg-primary data-[state=checked]:border-primary data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground data-[state=indeterminate]:border-primary data-[state=indeterminate]:bg-primary data-[state=indeterminate]:text-primary-foreground",
className
)}
{...props}
>
<CheckboxPrimitive.Indicator
data-slot="checkbox-indicator"
className="grid place-content-center text-current transition-none [&>svg]:size-3.5"
className="animate-in zoom-in-50 fade-in grid place-content-center text-current duration-150 [&>svg]:size-3.5"
>
<CheckIcon
/>
{indeterminate ? <MinusIcon /> : <CheckIcon />}
</CheckboxPrimitive.Indicator>
</CheckboxPrimitive.Root>
)
+3 -3
View File
@@ -37,7 +37,7 @@ function DialogOverlay({
<DialogPrimitive.Overlay
data-slot="dialog-overlay"
className={cn(
"fixed inset-0 isolate z-50 bg-black/10 duration-100 supports-backdrop-filter:backdrop-blur-xs data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0",
"fixed inset-0 isolate z-50 bg-black/20 duration-200 supports-backdrop-filter:backdrop-blur-xs data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0 data-closed:duration-150",
className
)}
{...props}
@@ -59,7 +59,7 @@ function DialogContent({
<DialogPrimitive.Content
data-slot="dialog-content"
className={cn(
"fixed top-1/2 left-1/2 z-50 grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-4 rounded-xl bg-popover p-4 text-sm text-popover-foreground ring-1 ring-foreground/10 duration-100 outline-none sm:max-w-sm data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",
"ease-spring fixed top-12 left-1/2 z-50 grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 gap-4 rounded-xl border bg-popover p-4 text-sm text-popover-foreground shadow-dialog duration-200 outline-none sm:max-w-sm data-open:animate-in data-open:fade-in-0 data-open:slide-in-from-top-6 data-closed:animate-out data-closed:fade-out-0 data-closed:slide-out-to-top-4 data-closed:duration-150 data-closed:ease-out",
className
)}
{...props}
@@ -128,7 +128,7 @@ function DialogTitle({
<DialogPrimitive.Title
data-slot="dialog-title"
className={cn(
"font-heading text-base leading-none font-medium",
"font-heading text-base leading-none font-semibold tracking-tight",
className
)}
{...props}
+4 -2
View File
@@ -16,7 +16,9 @@ function ScrollArea({
>
<ScrollAreaPrimitive.Viewport
data-slot="scroll-area-viewport"
className="size-full rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-1"
// Radix 默认给内容包一层 display:table + min-width:100% 的 div,会让内容按
// 自身宽度撑开导致 truncate 失效、文字被面板边缘硬切;改为 block 占满视口宽度。
className="size-full rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-1 [&>div]:block! [&>div]:w-full [&>div]:min-w-0!"
>
{children}
</ScrollAreaPrimitive.Viewport>
@@ -44,7 +46,7 @@ function ScrollBar({
>
<ScrollAreaPrimitive.ScrollAreaThumb
data-slot="scroll-area-thumb"
className="relative flex-1 rounded-full bg-border"
className="relative flex-1 rounded-full bg-foreground/25 transition-colors hover:bg-foreground/40"
/>
</ScrollAreaPrimitive.ScrollAreaScrollbar>
)
+1 -1
View File
@@ -55,7 +55,7 @@ function TableRow({ className, ...props }: React.ComponentProps<"tr">) {
<tr
data-slot="table-row"
className={cn(
"border-b transition-colors hover:bg-muted/50 has-aria-expanded:bg-muted/50 data-[state=selected]:bg-muted",
"border-b transition-colors hover:bg-muted/50 has-aria-expanded:bg-muted/50 data-[state=selected]:bg-primary/8 data-[state=selected]:hover:bg-primary/10",
className
)}
{...props}
+138
View File
@@ -0,0 +1,138 @@
import { useEffect, useState } from "react"
import { Check, Loader2, X } from "lucide-react"
import { cn } from "~/lib/utils"
// 轻量 toast:success / error 自动消失,loading 常驻直到被同 id 更新或手动关闭。
export type ToastKind = "success" | "error" | "loading"
export interface ToastItem {
id: string
kind: ToastKind
text: string
}
type Listener = (toasts: ToastItem[]) => void
// 模块级单例状态,让任意调用方无需 context 即可弹出 toast。
let currentToasts: ToastItem[] = []
const listeners = new Set<Listener>()
const dismissTimers = new Map<string, ReturnType<typeof setTimeout>>()
const AUTO_DISMISS_MS = 3200
const MAX_VISIBLE = 4
/**
* 通知所有挂载中的 Toaster 重新渲染。
*/
function emit() {
for (const listener of listeners) {
listener(currentToasts)
}
}
/**
* 关闭指定 toast。
*/
export function dismissToast(id: string) {
const timer = dismissTimers.get(id)
if (timer) {
clearTimeout(timer)
dismissTimers.delete(id)
}
currentToasts = currentToasts.filter((item) => item.id !== id)
emit()
}
/**
* 展示或更新一条 toast:同 id 复用同一条目并重置自动消失计时;
* loading 类型不自动消失,等待后续同 id 的 success / error 替换。
*/
export function showToast(input: { id?: string; kind: ToastKind; text: string }): string {
const id = input.id ?? `toast-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`
const existing = currentToasts.find((item) => item.id === id)
const next: ToastItem = { id, kind: input.kind, text: input.text }
currentToasts = existing
? currentToasts.map((item) => (item.id === id ? next : item))
: [...currentToasts.slice(-(MAX_VISIBLE - 1)), next]
const timer = dismissTimers.get(id)
if (timer) {
clearTimeout(timer)
dismissTimers.delete(id)
}
if (input.kind !== "loading") {
dismissTimers.set(
id,
setTimeout(() => dismissToast(id), AUTO_DISMISS_MS),
)
}
emit()
return id
}
// toast 类型对应的状态徽标:macOS 通知风的彩色小圆徽(成功绿 / 失败红),loading 用旋转图标。
const KIND_BADGES: Record<"success" | "error", { icon: typeof Check; chipClass: string }> = {
success: { icon: Check, chipClass: "bg-emerald-500" },
error: { icon: X, chipClass: "bg-destructive" },
}
/**
* toast 挂载点:固定在窗口右上角(顶栏下方),新条目自上滑入,点击可关闭。
* 视觉对齐 macOS 系统通知:白色毛玻璃圆角卡片 + 彩色状态圆徽 + 柔和投影,无彩色边框。
*/
export function Toaster() {
const [items, setItems] = useState<ToastItem[]>([])
useEffect(() => {
const listener: Listener = (toasts) => setItems([...toasts])
listeners.add(listener)
setItems([...currentToasts])
return () => {
listeners.delete(listener)
}
}, [])
if (items.length === 0) {
return null
}
return (
<div className="pointer-events-none fixed top-14 right-4 z-[60] flex flex-col items-end gap-2.5">
{items.map((item) => (
<button
key={item.id}
type="button"
onClick={() => dismissToast(item.id)}
className="animate-in fade-in slide-in-from-top-2 ease-out-quart pointer-events-auto flex w-fit max-w-[360px] min-w-[200px] items-center gap-2.5 rounded-xl border border-black/8 bg-popover/90 py-2.5 pr-4 pl-3 text-left shadow-[0_8px_24px_rgb(0_0_0/0.12),0_2px_6px_rgb(0_0_0/0.06)] backdrop-blur-xl duration-300"
>
{item.kind === "loading" ? (
<Loader2 className="size-4.5 shrink-0 animate-spin text-primary" />
) : (
<ToastBadge kind={item.kind} />
)}
<span className="min-w-0 text-[13px] leading-snug font-medium break-words text-foreground">
{item.text}
</span>
</button>
))}
</div>
)
}
/**
* 成功 / 失败的彩色圆形徽标:实色圆底 + 白色粗描边图标。
*/
function ToastBadge({ kind }: { kind: "success" | "error" }) {
const badge = KIND_BADGES[kind]
const Icon = badge.icon
return (
<span
className={cn(
"flex size-5 shrink-0 items-center justify-center rounded-full",
badge.chipClass,
)}
>
<Icon className="size-3 text-white" strokeWidth={3.2} />
</span>
)
}
+211 -2
View File
@@ -3,9 +3,10 @@ import { useCallback, useState } from "react"
import type { DiffRequest } from "~/components/explorer/diff-dialog"
import { api } from "~/lib/api"
import type { MappingInfo } from "~/lib/api"
import { isElectron, revealPath } from "~/lib/electron"
import type { FileActionId, FileTarget } from "~/lib/tfs"
// 当前打开的业务弹窗:Mapping / History / 目录对比 / 文件查看 / Diff / 冲突处理 / 覆盖类确认。
// 当前打开的业务弹窗:Mapping / History / 目录对比 / 文件查看 / Diff / 冲突处理 / 覆盖类确认 / 属性 / 获取特定版本。
export type WorkspaceDialogState =
| { kind: "mapping"; serverPath: string }
| { kind: "history"; serverPath: string; folder: boolean }
@@ -14,6 +15,12 @@ export type WorkspaceDialogState =
| { kind: "diff"; request: DiffRequest }
| { kind: "conflicts"; serverPath: string }
| { kind: "confirmForceGet"; serverPath: string; folder: boolean }
| { kind: "properties"; target: FileTarget }
| { kind: "getVersion"; serverPath: string; folder: boolean }
| { kind: "rename"; serverPath: string; folder: boolean }
| { kind: "branch"; serverPath: string }
| { kind: "merge"; serverPath: string }
| { kind: "addFiles"; serverPath: string }
| null
// 顶部细条通知:信息(操作摘要)或错误。
@@ -108,6 +115,48 @@ export function useFileActions({
[refreshItems, refreshLogs, refreshPendingChanges],
)
/**
* 执行变更集回滚(产生挂起更改,不直接入库),由历史弹窗中的确认操作触发;
* 出现冲突时进入统一冲突弹窗,完成后刷新挂起更改与目录列表。
*/
const runRollback = useCallback(
async (
serverPath: string,
mode: "single" | "toVersion",
changeset: number,
): Promise<boolean> => {
setNotice({
kind: "info",
text: mode === "single" ? `正在回滚变更集 C${changeset}…` : `正在回滚到 C${changeset}…`,
})
const result = await api.rollback({ serverPath, mode, changeset })
refreshLogs()
if (!result.ok || !result.data) {
setNotice({ kind: "error", text: result.errorMessage ?? "回滚失败" })
return false
}
const summary = result.data.result
const parts = [`产生挂起更改 ${summary.operations} 项`]
if (summary.conflicts > 0) {
parts.push(`冲突 ${summary.conflicts} 项`)
}
if (summary.failures > 0) {
parts.push(`失败 ${summary.failures} 项`)
}
setNotice({
kind: summary.conflicts > 0 || summary.failures > 0 ? "error" : "info",
text: `回滚完成:${parts.join(",")},请在挂起更改面板审查后签入`,
})
await refreshPendingChanges()
refreshItems()
if (summary.conflicts > 0) {
setDialog({ kind: "conflicts", serverPath })
}
return true
},
[refreshItems, refreshLogs, refreshPendingChanges],
)
/**
* 执行 Checkout:先 Get Latest,出现冲突时进入统一冲突弹窗;
* 无冲突则签出并提示跳过 / 失败项,完成后刷新挂起更改。
@@ -200,6 +249,47 @@ export function useFileActions({
folder: target.folder,
})
break
case "getSpecificVersion":
// 覆盖类危险操作:弹窗内选择 changeset 并确认后执行。
setDialog({
kind: "getVersion",
serverPath: target.serverPath,
folder: target.folder,
})
break
case "properties":
setDialog({ kind: "properties", target })
break
case "rename":
setDialog({ kind: "rename", serverPath: target.serverPath, folder: target.folder })
break
case "branch":
setDialog({ kind: "branch", serverPath: target.serverPath })
break
case "merge":
setDialog({ kind: "merge", serverPath: target.serverPath })
break
case "revealInFinder": {
if (!target.localPath) {
return
}
if (!isElectron()) {
setNotice({ kind: "error", text: "「在访达中打开」仅桌面应用支持" })
return
}
const revealed = await revealPath(target.localPath, target.folder)
if (!revealed) {
setNotice({ kind: "error", text: "本地路径不存在,请先获取最新" })
}
break
}
case "addLocalFiles":
// 扫描式添加:弹窗内目录对比筛出本地新增项,勾选后批量 pend add。
if (!target.mapped) {
return
}
setDialog({ kind: "addFiles", serverPath: target.serverPath })
break
case "checkout":
setActionBusy(true)
setNotice({ kind: "info", text: "正在签出…" })
@@ -263,7 +353,7 @@ export function useFileActions({
break
}
},
[onMappingsChanged, runGetLatest, runCheckout, runFileOperation, refreshLogs],
[onMappingsChanged, runGetLatest, runCheckout, runFileOperation, refreshLogs, refreshItems, refreshPendingChanges],
)
/**
@@ -315,6 +405,120 @@ export function useFileActions({
setNotice({ kind: "info", text: "冲突处理完成,已刷新状态" })
}, [refreshItems, refreshPendingChanges, refreshLogs])
/**
* 重命名确认后执行:产生 rename 挂起更改并刷新目录列表与挂起更改。
*/
const handleRenameConfirmed = useCallback(
async (serverPath: string, newName: string): Promise<boolean> => {
setNotice({ kind: "info", text: "正在重命名…" })
const result = await api.renameFile({ serverPath, newName })
refreshLogs()
if (!result.ok || !result.data) {
setNotice({ kind: "error", text: result.errorMessage ?? "重命名失败" })
return false
}
setNotice({
kind: "info",
text: `已挂起重命名为「${newName}」,签入后服务器生效`,
})
await refreshPendingChanges()
refreshItems()
return true
},
[refreshItems, refreshLogs, refreshPendingChanges],
)
/**
* 分支确认后执行:产生 branch 挂起更改并刷新挂起更改与目录列表。
*/
const handleBranchConfirmed = useCallback(
async (
sourceServerPath: string,
targetServerPath: string,
changeset: number | undefined,
): Promise<boolean> => {
setNotice({ kind: "info", text: "正在创建分支…" })
const result = await api.branch({ sourceServerPath, targetServerPath, changeset })
refreshLogs()
if (!result.ok || !result.data) {
setNotice({ kind: "error", text: result.errorMessage ?? "创建分支失败" })
return false
}
setNotice({
kind: "info",
text: `已挂起分支 ${result.data.result.affected} 项(${targetServerPath}),请在挂起更改面板审查后签入`,
})
await refreshPendingChanges()
refreshItems()
return true
},
[refreshItems, refreshLogs, refreshPendingChanges],
)
/**
* 合并确认后执行:产生挂起更改并刷新,冲突自动进入冲突弹窗(针对目标路径)。
*/
const handleMergeConfirmed = useCallback(
async (
sourceServerPath: string,
targetServerPath: string,
changeset: number | undefined,
): Promise<boolean> => {
setNotice({
kind: "info",
text: changeset == null ? "正在合并全部候选变更集…" : `正在合并变更集 C${changeset}…`,
})
const result = await api.merge({ sourceServerPath, targetServerPath, changeset })
refreshLogs()
if (!result.ok || !result.data) {
setNotice({ kind: "error", text: result.errorMessage ?? "合并失败" })
return false
}
const summary = result.data.result
const parts = [`产生挂起更改 ${summary.operations} 项`]
if (summary.conflicts > 0) {
parts.push(`冲突 ${summary.conflicts} 项`)
}
if (summary.failures > 0) {
parts.push(`失败 ${summary.failures} 项`)
}
setNotice({
kind: summary.conflicts > 0 || summary.failures > 0 ? "error" : "info",
text: `合并完成:${parts.join(",")},请在挂起更改面板审查后签入`,
})
await refreshPendingChanges()
refreshItems()
if (summary.conflicts > 0) {
setDialog({ kind: "conflicts", serverPath: targetServerPath })
}
return true
},
[refreshItems, refreshLogs, refreshPendingChanges],
)
/**
* 添加本地文件确认后执行:批量 pend add 并刷新挂起更改与目录列表。
*/
const handleAddFilesConfirmed = useCallback(
async (localPaths: string[]): Promise<boolean> => {
setNotice({ kind: "info", text: "正在添加到版本控制…" })
const result = await api.addFiles({ paths: localPaths })
refreshLogs()
if (!result.ok || !result.data) {
setNotice({ kind: "error", text: result.errorMessage ?? "添加失败" })
return false
}
setNotice({
kind: "info",
text: `已加入版本控制 ${result.data.result.affected} 项,请在挂起更改面板审查后签入`,
})
await refreshPendingChanges()
refreshItems()
return true
},
[refreshItems, refreshLogs, refreshPendingChanges],
)
/**
* 强制获取确认后执行:覆盖本地并关闭确认弹窗。
*/
@@ -348,6 +552,11 @@ export function useFileActions({
handleMappingCreated,
handleConflictsResolved,
handleForceGetConfirmed,
handleRenameConfirmed,
handleBranchConfirmed,
handleMergeConfirmed,
handleAddFilesConfirmed,
runGetVersion,
runRollback,
}
}
+14 -7
View File
@@ -40,15 +40,22 @@ export function usePendingChanges() {
}, [refresh])
/**
* 切换某条挂起更改的 Included / Excluded 归属。
* 批量设置一组挂起更改的 Included / Excluded 归属。
* 单项勾选传单元素数组,目录节点级联传子树全部 serverPath。
* excluded=true 全部排除,false 全部移回 Included。
*/
const toggleExcluded = useCallback((serverPath: string) => {
const setExcluded = useCallback((serverPaths: string[], excluded: boolean) => {
if (serverPaths.length === 0) {
return
}
setExcludedKeys((prev) => {
const next = new Set(prev)
if (next.has(serverPath)) {
next.delete(serverPath)
} else {
next.add(serverPath)
for (const serverPath of serverPaths) {
if (excluded) {
next.add(serverPath)
} else {
next.delete(serverPath)
}
}
return next
})
@@ -70,6 +77,6 @@ export function usePendingChanges() {
excludedKeys,
pendingByServerPath,
refresh,
toggleExcluded,
setExcluded,
}
}
+2
View File
@@ -45,6 +45,8 @@ async function request<T = Record<string, unknown>>(
const token = await getToken()
const headers: Record<string, string> = {
Accept: "application/json",
// 标记本次请求来自桌面端手动操作,供后端操作日志区分「AI 操作 / 手动操作」。
"X-MacTFS-Source": "ui",
}
if (token) {
headers.Authorization = `Bearer ${token}`
+59 -1
View File
@@ -13,10 +13,12 @@ import type {
FolderDiffItem,
GetLatestResult,
HistoryEntry,
ItemInfo,
MappingInfo,
OperationLogEntry,
PendingChange,
ServerItem,
TestConnectionResult,
TextDiff,
WorkspaceContext,
WorkspaceInfo,
@@ -46,6 +48,14 @@ export function connect(config: Partial<AppConfig> = {}) {
return apiClient.post<ConnectResult>("/api/session/connect", { body: config })
}
/**
* 只读探测当前 TFS 连接是否仍可用(真正回连一次),不改变会话/配置状态。
* 供顶栏「连接测试」手动触发;成功返回 serverUri / collectionCount / 耗时。
*/
export function testTfsConnection() {
return apiClient.post<TestConnectionResult>("/api/session/test")
}
/**
* 列出当前账号可见的 Collection。
*/
@@ -159,6 +169,41 @@ export function undoFiles(body: FileActionBody) {
return apiClient.post<{ result: FileOperationResult }>("/api/files/undo", { body })
}
/**
* 重命名文件或目录(同目录改名),产生 rename 挂起更改。
*/
export function renameFile(body: { serverPath: string; newName: string }) {
return apiClient.post<{ result: FileOperationResult }>("/api/files/rename", { body })
}
/**
* 回滚变更集(只产生挂起更改):single 仅反做该 changeset,toVersion 反做其后全部改动。
*/
export function rollback(body: { serverPath: string; mode: "single" | "toVersion"; changeset: number }) {
return apiClient.post<{ result: GetLatestResult }>("/api/files/rollback", { body })
}
/**
* 分支:把源路径分叉到目标路径(产生 branch 挂起更改),changeset 缺省为 latest。
*/
export function branch(body: { sourceServerPath: string; targetServerPath: string; changeset?: number }) {
return apiClient.post<{ result: FileOperationResult }>("/api/files/branch", { body })
}
/**
* 查询源 → 目标的待合并变更集候选列表。
*/
export function mergeCandidates(params: { sourceServerPath: string; targetServerPath: string }) {
return apiClient.get<{ candidates: HistoryEntry[] }>("/api/files/merge-candidates", { query: params })
}
/**
* 合并:源 → 目标(产生挂起更改,冲突走冲突处理),changeset 缺省为合并全部候选。
*/
export function merge(body: { sourceServerPath: string; targetServerPath: string; changeset?: number }) {
return apiClient.post<{ result: GetLatestResult }>("/api/files/merge", { body })
}
/**
* 读取当前 Workspace 的挂起更改。
*/
@@ -173,6 +218,13 @@ export function checkin(body: { paths?: string[]; comment: string }) {
return apiClient.post<{ checkin: CheckinResult }>("/api/checkin", { body })
}
/**
* 读取服务端对象(文件或目录)的属性信息,供属性弹窗展示。
*/
export function getItemInfo(params: { serverPath: string }) {
return apiClient.get<{ item: ItemInfo }>("/api/items/info", { query: params })
}
/**
* 读取服务器内容(latest 或指定 changeset),或读取本地映射文件内容。
*/
@@ -182,8 +234,14 @@ export function getFileContent(params: { serverPath?: string; localPath?: string
/**
* 对已映射目录执行目录对比。
* includeLocalOnly=false 时跳过本地全量扫描,仅本地存在的项(如 node_modules)不计入差异。
*/
export function compareFolder(body: { serverPath: string; localPath?: string; recursive?: boolean }) {
export function compareFolder(body: {
serverPath: string
localPath?: string
recursive?: boolean
includeLocalOnly?: boolean
}) {
return apiClient.post<{ diffs: FolderDiffItem[] }>("/api/compare/folder", { body })
}
+2
View File
@@ -15,9 +15,11 @@ export type {
FolderDiffItem,
GetLatestResult,
HistoryEntry,
ItemInfo,
MappingConfig,
MappingInfo,
OperationLogEntry,
OperationSource,
PendingChange,
ServerItem,
TextDiff,
+28
View File
@@ -51,6 +51,13 @@ export interface ConnectResult {
collectionCount?: number
}
// 连接测试结果,对应 /api/session/test(只读探测);coreDurationMs 为本次回连耗时。
export interface TestConnectionResult {
serverUri?: string
collectionCount?: number
coreDurationMs?: number
}
// Collection 信息,对应 core TfsCollectionInfo。
export interface Collection {
name: string
@@ -128,6 +135,8 @@ export interface PendingChange {
status: string
changeType: string
version: number
/** rename 挂起更改的原服务端路径,其余为 null。 */
sourceServerPath: string | null
}
// 签入结果,对应 core TfsCheckinResult。
@@ -159,6 +168,20 @@ export interface HistoryEntry {
comment: string
}
// 服务端对象属性信息,对应 core TfsItemInfo(属性弹窗用)。
export interface ItemInfo {
serverPath: string
folder: boolean
changeset: number
checkinDate: number | null
author: string
comment: string
/** 文件大小(字节),目录为 null。 */
size: number | null
/** 文件编码名称,目录为 null。 */
encoding: string | null
}
// 文件内容,对应 core TfsFileContent,binary / tooLarge 时 content 为空串。
export interface FileContent {
serverPath: string
@@ -199,6 +222,9 @@ export interface ConflictResolutionResult {
remainingConflicts: number
}
// 操作来源:mcp 为 AI 通过 MCP 调用,ui 为桌面端手动操作。旧记录可能缺省。
export type OperationSource = "mcp" | "ui"
// 操作日志项,对应服务端 OperationLogEntry。
export interface OperationLogEntry {
operation: string
@@ -208,4 +234,6 @@ export interface OperationLogEntry {
durationMs: number
success: boolean
errorMessage: string | null
/** 操作来源:mcp(AI)/ ui(手动);旧记录可能为 undefined,按手动处理。 */
source?: OperationSource
}
+45 -1
View File
@@ -1,4 +1,4 @@
import type { MactfsBridge, ServiceStatus } from "./types"
import type { MactfsBridge, McpLogEntry, McpStatus, ServiceStatus } from "./types"
const DEFAULT_BASE_URL = "http://127.0.0.1:38765"
@@ -85,6 +85,50 @@ export async function pathsExist(paths: string[]): Promise<Record<string, boolea
return bridge.pathsExist(paths)
}
/**
* 在访达中打开本地路径(目录直接进入,文件定位选中),非 Electron 环境返回 false。
*/
export async function revealPath(targetPath: string, isFolder: boolean): Promise<boolean> {
const bridge = getBridge()
if (!bridge) {
return false
}
return bridge.revealPath(targetPath, isFolder)
}
/**
* 查询 MCP 子进程运行状态,非 Electron 环境返回未运行占位。
*/
export async function getMcpStatus(): Promise<McpStatus> {
const bridge = getBridge()
if (!bridge) {
return {
running: false,
healthy: false,
pid: null,
sseUrl: "http://127.0.0.1:38766/sse",
startedAt: null,
uptimeMs: 0,
restartCount: 0,
lastExitCode: null,
lastError: "当前不在 Electron 桌面环境,无法访问 MCP 服务",
entryResolved: false,
}
}
return bridge.getMcpStatus()
}
/**
* 读取 MCP 子进程运行日志(最近 500 行),非 Electron 环境返回空数组。
*/
export async function getMcpLogs(): Promise<McpLogEntry[]> {
const bridge = getBridge()
if (!bridge) {
return []
}
return bridge.getMcpLogs()
}
/**
* 构造非 Electron 环境下的占位服务状态。
*/
+4 -1
View File
@@ -1,11 +1,14 @@
export type { MactfsBridge, ServiceHealth, ServiceStatus } from "./types"
export type { MactfsBridge, McpLogEntry, McpStatus, ServiceHealth, ServiceStatus } from "./types"
export {
getApiBaseUrl,
getBridge,
getMcpLogs,
getMcpStatus,
getServiceStatus,
getToken,
isElectron,
pathsExist,
revealPath,
selectDirectory,
startService,
} from "./bridge"
+24
View File
@@ -17,6 +17,27 @@ export interface ServiceStatus {
error: string | null
}
// MCP 子进程运行状态,由 Electron 主进程汇总(含 /healthz 探活)。
export interface McpStatus {
running: boolean
healthy: boolean
pid: number | null
sseUrl: string
startedAt: number | null
uptimeMs: number
restartCount: number
lastExitCode: number | null
lastError: string | null
entryResolved: boolean
}
// MCP 单行运行日志(来自子进程 stdout/stderr)。
export interface McpLogEntry {
ts: number
stream: "stdout" | "stderr"
line: string
}
// preload 暴露到 window.mactfs 的窄接口契约。
export interface MactfsBridge {
isElectron: true
@@ -26,6 +47,9 @@ export interface MactfsBridge {
startService(): Promise<ServiceStatus>
selectDirectory(): Promise<string | null>
pathsExist(paths: string[]): Promise<Record<string, boolean>>
revealPath(targetPath: string, isFolder: boolean): Promise<boolean>
getMcpStatus(): Promise<McpStatus>
getMcpLogs(): Promise<McpLogEntry[]>
}
declare global {
-28
View File
@@ -54,34 +54,6 @@ monaco.editor.defineTheme("mactfs-light", {
},
})
monaco.editor.defineTheme("mactfs-dark", {
base: "vs-dark",
inherit: true,
rules: [],
colors: {
"editor.background": "#1b1b1b",
"editor.foreground": "#fafafa",
"editor.lineHighlightBackground": "#ffffff08",
"editorLineNumber.foreground": "#6b6b6b",
"editorLineNumber.activeForeground": "#a3a3a3",
"editorCursor.foreground": "#818cf8",
"focusBorder": "#00000000",
"diffEditor.insertedTextBackground": "#22c55e30",
"diffEditor.insertedLineBackground": "#22c55e17",
"diffEditor.removedTextBackground": "#ef444430",
"diffEditor.removedLineBackground": "#ef444417",
"diffEditorGutter.insertedLineBackground": "#22c55e24",
"diffEditorGutter.removedLineBackground": "#ef444424",
"diffEditorOverview.insertedForeground": "#22c55e99",
"diffEditorOverview.removedForeground": "#ef444499",
"diffEditor.unchangedRegionBackground": "#222222",
"diffEditor.unchangedRegionForeground": "#9c9c9c",
"scrollbarSlider.background": "#ffffff1f",
"scrollbarSlider.hoverBackground": "#ffffff33",
"scrollbarSlider.activeBackground": "#ffffff40",
},
})
/**
* 按文件路径后缀匹配 Monaco 已注册语言,匹配不到时回退纯文本。
*/
+11
View File
@@ -0,0 +1,11 @@
/**
* 是否运行在 macOS 的 Electron 窗口内。
* 用于判断隐藏式标题栏与 vibrancy 场景:需要为红绿灯预留空间并启用顶栏拖拽。
*/
export function isMacElectron(): boolean {
if (typeof navigator === "undefined") {
return false
}
const ua = navigator.userAgent
return ua.includes("Electron") && ua.includes("Macintosh")
}
+47
View File
@@ -0,0 +1,47 @@
// 登录页「最近连接」本地记录,仅存非敏感字段(不存密码)。
export interface RecentServer {
serverUri: string
domain: string
username: string
lastUsedAt: number
}
const STORAGE_KEY = "mactfs.recent-servers"
const MAX_ENTRIES = 5
/**
* 读取最近连接记录,本地存储不可用或数据损坏时返回空列表。
*/
export function loadRecentServers(): RecentServer[] {
if (typeof window === "undefined") {
return []
}
try {
const raw = window.localStorage.getItem(STORAGE_KEY)
if (!raw) {
return []
}
const parsed = JSON.parse(raw) as RecentServer[]
return Array.isArray(parsed) ? parsed : []
} catch {
return []
}
}
/**
* 写入一条最近连接记录:按 serverUri + username 去重置顶,最多保留 5 条。
*/
export function saveRecentServer(entry: Omit<RecentServer, "lastUsedAt">): RecentServer[] {
const next: RecentServer[] = [
{ ...entry, lastUsedAt: Date.now() },
...loadRecentServers().filter(
(item) => item.serverUri !== entry.serverUri || item.username !== entry.username,
),
].slice(0, MAX_ENTRIES)
try {
window.localStorage.setItem(STORAGE_KEY, JSON.stringify(next))
} catch {
// 本地存储写入失败不影响连接流程
}
return next
}
+81
View File
@@ -32,7 +32,9 @@ export type FileActionId =
| "unmap"
| "getLatest"
| "forceGetLatest"
| "getSpecificVersion"
| "checkout"
| "rename"
| "delete"
| "undo"
| "add"
@@ -40,6 +42,11 @@ export type FileActionId =
| "history"
| "viewFile"
| "diffLocalLatest"
| "branch"
| "merge"
| "revealInFinder"
| "addLocalFiles"
| "properties"
// 单个菜单项:是否可用与置灰原因。
export interface FileMenuItem {
@@ -138,6 +145,12 @@ function buildFolderMenu(target: FileTarget): FileMenuItem[][] {
enabled: target.mapped,
reason: target.mapped ? undefined : NOT_MAPPED_REASON,
},
{
id: "rename",
label: "重命名…",
enabled: target.mapped,
reason: target.mapped ? undefined : NOT_MAPPED_REASON,
},
{
id: "delete",
label: "挂起删除",
@@ -165,6 +178,21 @@ function buildFolderMenu(target: FileTarget): FileMenuItem[][] {
sections.push(mappingActions)
}
sections.push([
{
id: "revealInFinder",
label: "在访达中打开",
enabled: target.mapped,
reason: target.mapped ? undefined : NOT_MAPPED_REASON,
},
{
id: "addLocalFiles",
label: "添加本地文件…",
enabled: target.mapped,
reason: target.mapped ? undefined : NOT_MAPPED_REASON,
},
])
sections.push([
{
id: "compare",
@@ -173,11 +201,31 @@ function buildFolderMenu(target: FileTarget): FileMenuItem[][] {
reason: target.mapped ? undefined : NOT_MAPPED_REASON,
},
{ id: "history", label: "查看历史", enabled: true },
{ id: "branch", label: "分支…", enabled: true },
{ id: "merge", label: "合并…", enabled: true },
])
sections.push(buildAdvancedSection(target))
return sections
}
/**
* 高级动作分组:获取特定版本(按 changeset 覆盖本地)与属性弹窗。
*/
function buildAdvancedSection(target: FileTarget): FileMenuItem[] {
return [
{
id: "getSpecificVersion",
label: "获取特定版本…",
enabled: target.mapped,
danger: true,
reason: target.mapped ? undefined : NOT_MAPPED_REASON,
},
{ id: "properties", label: "属性…", enabled: true },
]
}
/**
* 文件菜单:查看 / 比较 / 历史 + 本地工作区动作,按挂起状态控制可用性。
* pendingAdd 文件不展示服务器比较与历史入口;pendingEdit 禁止直接 Get Latest 覆盖。
@@ -199,6 +247,12 @@ function buildFileItemMenu(target: FileTarget): FileMenuItem[][] {
})
viewActions.push({ id: "history", label: "查看历史", enabled: true })
}
viewActions.push({
id: "revealInFinder",
label: "在访达中显示",
enabled: target.mapped,
reason: target.mapped ? undefined : NOT_MAPPED_REASON,
})
sections.push(viewActions)
// Pending Changes 列表项以撤销为主,不再重复签出 / 删除入口。
@@ -206,6 +260,10 @@ function buildFileItemMenu(target: FileTarget): FileMenuItem[][] {
sections.push([
{ id: "undo", label: "撤销更改", enabled: true, danger: true },
])
// pendingAdd 项服务端尚不存在,属性查询无意义。
if (!isPendingAdd) {
sections.push([{ id: "properties", label: "属性…", enabled: true }])
}
return sections
}
@@ -236,6 +294,20 @@ function buildFileItemMenu(target: FileTarget): FileMenuItem[][] {
? "存在挂起更改"
: undefined,
},
{
id: "rename",
label: "重命名…",
enabled: target.mapped && pending !== "pendingAdd" && pending !== "pendingDelete" && pending !== "pendingRename",
reason: !target.mapped
? NOT_MAPPED_REASON
: pending === "pendingAdd"
? "挂起新增,签入后才能重命名"
: pending === "pendingDelete"
? "已挂起删除"
: pending === "pendingRename"
? "已挂起重命名"
: undefined,
},
{
id: "delete",
label: "挂起删除",
@@ -256,5 +328,14 @@ function buildFileItemMenu(target: FileTarget): FileMenuItem[][] {
]
sections.push(workspaceActions)
// pendingAdd 文件服务端尚不存在,不提供分支、合并、属性与获取特定版本。
if (!isPendingAdd) {
sections.push([
{ id: "branch", label: "分支…", enabled: true },
{ id: "merge", label: "合并…", enabled: true },
])
sections.push(buildAdvancedSection(target))
}
return sections
}
+12 -12
View File
@@ -21,18 +21,18 @@ export const STATUS_LABELS: Record<string, string> = {
// 业务状态对应的 badge 配色(Tailwind class),按 Agents.md 状态色规则。
export const STATUS_BADGE_CLASSES: Record<string, string> = {
localModified: "bg-blue-500/10 text-blue-700 dark:text-blue-400",
remoteChanged: "bg-violet-500/10 text-violet-700 dark:text-violet-400",
bothChanged: "bg-red-500/15 text-red-700 dark:text-red-400",
localOnly: "bg-green-500/10 text-green-700 dark:text-green-400",
remoteOnly: "bg-violet-500/10 text-violet-700 dark:text-violet-400",
notDownloaded: "bg-amber-500/10 text-amber-700 dark:text-amber-400",
localDeleted: "bg-red-500/10 text-red-700 dark:text-red-400",
pendingEdit: "bg-blue-500/10 text-blue-700 dark:text-blue-400",
pendingAdd: "bg-green-500/10 text-green-700 dark:text-green-400",
pendingDelete: "bg-red-500/10 text-red-700 dark:text-red-400",
pendingRename: "bg-blue-500/10 text-blue-700 dark:text-blue-400",
pending: "bg-blue-500/10 text-blue-700 dark:text-blue-400",
localModified: "bg-blue-500/10 text-blue-700",
remoteChanged: "bg-violet-500/10 text-violet-700",
bothChanged: "bg-red-500/15 text-red-700",
localOnly: "bg-green-500/10 text-green-700",
remoteOnly: "bg-violet-500/10 text-violet-700",
notDownloaded: "bg-amber-500/10 text-amber-700",
localDeleted: "bg-red-500/10 text-red-700",
pendingEdit: "bg-blue-500/10 text-blue-700",
pendingAdd: "bg-green-500/10 text-green-700",
pendingDelete: "bg-red-500/10 text-red-700",
pendingRename: "bg-blue-500/10 text-blue-700",
pending: "bg-blue-500/10 text-blue-700",
upToDate: "bg-muted text-muted-foreground",
notMapped: "bg-muted text-muted-foreground",
mapped: "bg-muted text-foreground/80",
+6
View File
@@ -16,6 +16,12 @@ export function Layout({ children }: { children: React.ReactNode }) {
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
{/* 首屏前标记 vibrancy 环境(macOS Electron 下透出窗口毛玻璃) */}
<script
dangerouslySetInnerHTML={{
__html: `(function(){try{var ua=navigator.userAgent;if(ua.includes("Electron")&&ua.includes("Macintosh"))document.documentElement.classList.add("vibrancy")}catch(e){}})()`,
}}
/>
<Meta />
<Links />
</head>
+8 -1
View File
@@ -11,6 +11,13 @@ import type { WorkspaceSession } from "~/lib/tfs/session"
// 顶层视图状态:检测服务、服务未就绪、连接入口、已进入工作台。
type AppPhase = "checking" | "blocked" | "connect" | "workspace"
/**
* 页面标题(同时作为 Electron 窗口标题)。
*/
export function meta() {
return [{ title: "MacTFS" }]
}
/**
* 第一版前端入口:先确保本地服务就绪,再走连接 / Collection / Workspace 流程,
* 进入工作台后持有固定上下文,并统一维护左树与中间列表共享的当前路径(FE-004)。
@@ -88,7 +95,7 @@ export default function Home() {
return (
<div className="flex min-h-svh items-center justify-center bg-muted/40 p-6">
<div className="w-full max-w-md rounded-lg border bg-background p-6 shadow-sm">
<h1 className="text-base font-semibold">macTFS</h1>
<h1 className="text-base font-semibold">MacTFS</h1>
<p className="mt-1 text-sm text-muted-foreground">本地源码管理工作台</p>
{phase === "checking" && (
Binary file not shown.
+341 -13
View File
@@ -1,4 +1,4 @@
const { app, BrowserWindow, ipcMain, dialog } = require("electron")
const { app, BrowserWindow, ipcMain, dialog, shell, nativeImage, protocol } = require("electron")
const path = require("node:path")
const fs = require("node:fs")
const os = require("node:os")
@@ -10,12 +10,171 @@ const API_PORT = 38765
const API_BASE_URL = `http://${API_HOST}:${API_PORT}`
const SERVER_MAIN_CLASS = "com.mydev.mactfs.server.MacTfsServer"
const TOKEN_FILE = path.join(os.homedir(), ".mactfs", "server-token")
// MCP SSE 服务地址:随客户端拉起、随客户端退出回收,实现「客户端开着才能用」的绑定。
const MCP_HOST = "127.0.0.1"
const MCP_PORT = 38766
const MCP_RESTART_DELAY_MS = 2000
const HEALTH_TIMEOUT_MS = 2000
const START_POLL_TIMES = 30
const START_POLL_INTERVAL_MS = 1000
// 自定义协议:以 app://bundle/ 提供前端静态资源。
// 打包后构建产物使用绝对路径(/assets/...),用 file:// 会指向磁盘根目录导致白屏,故走自定义协议从 build/client 映射。
const APP_SCHEME = "app"
const APP_ORIGIN = `${APP_SCHEME}://bundle/`
const MIME_BY_EXT = {
".html": "text/html",
".js": "text/javascript",
".mjs": "text/javascript",
".css": "text/css",
".json": "application/json",
".map": "application/json",
".ico": "image/x-icon",
".png": "image/png",
".jpg": "image/jpeg",
".jpeg": "image/jpeg",
".gif": "image/gif",
".svg": "image/svg+xml",
".webp": "image/webp",
".ttf": "font/ttf",
".woff": "font/woff",
".woff2": "font/woff2",
".wasm": "application/wasm",
}
// 必须在 app ready 之前注册自定义协议的特权(标准协议 + 安全上下文)。
protocol.registerSchemesAsPrivileged([
{
scheme: APP_SCHEME,
privileges: { standard: true, secure: true, supportFetchAPI: true, stream: true },
},
])
/**
* 注册 app:// 协议处理器:把请求路径映射到 build/client 下的静态文件,找不到时回退到 index.html(适配前端路由)。
*/
function registerAppProtocol() {
const clientRoot = path.join(__dirname, "..", "build", "client")
protocol.handle(APP_SCHEME, async (request) => {
let relativePath = decodeURIComponent(new URL(request.url).pathname)
if (!relativePath || relativePath === "/") {
relativePath = "/index.html"
}
let filePath = path.normalize(path.join(clientRoot, relativePath))
if (!filePath.startsWith(clientRoot) || !fs.existsSync(filePath)) {
filePath = path.join(clientRoot, "index.html")
}
const data = await fs.promises.readFile(filePath)
const contentType = MIME_BY_EXT[path.extname(filePath).toLowerCase()] || "application/octet-stream"
return new Response(data, { headers: { "content-type": contentType } })
})
}
// 记录由本进程拉起的服务端子进程,便于应用退出时回收。
let serverProcess = null
// 记录由本进程拉起的 MCP 子进程;应用退出时一并回收。
let mcpProcess = null
// 标记应用是否正在退出,用于区分「主动退出」与「子进程崩溃需重拉」。
let appQuitting = false
// MCP 运行状态与日志环形缓冲:供「MCP 状态」弹窗展示,最多保留最近 500 行。
const MCP_LOG_MAX_LINES = 500
const MCP_SSE_URL = `http://${MCP_HOST}:${MCP_PORT}/sse`
const MCP_HEALTHZ_URL = `http://${MCP_HOST}:${MCP_PORT}/healthz`
const mcpLogBuffer = []
const mcpLineRemainder = { stdout: "", stderr: "" }
let mcpStartedAt = 0
let mcpRestartCount = 0
let mcpLastExitCode = null
let mcpLastError = null
/**
* 向环形缓冲追加一行 MCP 日志,超出上限时丢弃最旧的行。
*/
function pushMcpLine(stream, line) {
if (typeof line !== "string" || line.length === 0) {
return
}
mcpLogBuffer.push({ ts: Date.now(), stream, line })
if (mcpLogBuffer.length > MCP_LOG_MAX_LINES) {
mcpLogBuffer.splice(0, mcpLogBuffer.length - MCP_LOG_MAX_LINES)
}
}
/**
* 按行切分子进程输出(保留跨 chunk 的半行余量),逐行写入缓冲。
*/
function appendMcpLog(stream, chunk) {
const combined = (mcpLineRemainder[stream] || "") + chunk.toString()
const parts = combined.split(/\r?\n/)
mcpLineRemainder[stream] = parts.pop() || ""
for (const part of parts) {
pushMcpLine(stream, part)
}
}
/**
* 把残留的半行刷入缓冲(用于进程退出时收尾)。
*/
function flushMcpRemainder() {
for (const stream of ["stdout", "stderr"]) {
if (mcpLineRemainder[stream]) {
pushMcpLine(stream, mcpLineRemainder[stream])
mcpLineRemainder[stream] = ""
}
}
}
/**
* 探测 MCP 的 /healthz 是否可达,返回 { ok, body? },不抛异常。
*/
function pingMcpHealthz() {
return new Promise((resolve) => {
const request = http.request(MCP_HEALTHZ_URL, { method: "GET", timeout: 1500 }, (response) => {
let raw = ""
response.on("data", (chunk) => {
raw += chunk
})
response.on("end", () => {
if (response.statusCode !== 200) {
resolve({ ok: false })
return
}
try {
resolve({ ok: true, body: JSON.parse(raw) })
} catch (error) {
resolve({ ok: true })
}
})
})
request.on("timeout", () => {
request.destroy()
resolve({ ok: false })
})
request.on("error", () => resolve({ ok: false }))
request.end()
})
}
/**
* 汇总 MCP 当前状态:进程是否在跑、pid、运行时长、重启次数,并探活 /healthz。
*/
async function getMcpStatus() {
const running = !!(mcpProcess && mcpProcess.exitCode === null)
const healthz = running ? await pingMcpHealthz() : { ok: false }
return {
running,
healthy: healthz.ok,
pid: running ? mcpProcess.pid : null,
sseUrl: MCP_SSE_URL,
startedAt: mcpStartedAt || null,
uptimeMs: running && mcpStartedAt ? Date.now() - mcpStartedAt : 0,
restartCount: mcpRestartCount,
lastExitCode: mcpLastExitCode,
lastError: mcpLastError,
entryResolved: resolveMcpEntry() != null,
}
}
/**
* 计算项目根目录,main.cjs 位于 mactfsui/electron 下,上溯两级即为单仓库根目录。
@@ -24,19 +183,30 @@ function resolveProjectRoot() {
return path.resolve(__dirname, "..", "..")
}
// 服务端 JVM 固定使用 x64:TFS 的 JNI 原生库(libnative_*.jnilib)只含 i386/x86_64,无 arm64 切片,
// 用 arm64 JVM 加载会 UnsatisfiedLinkError。Apple Silicon 上 x64 JVM 经 Rosetta 2 运行;
// 服务端是 IO 密集型,Rosetta 开销可接受。UI(Electron)走 universal 原生,已解决界面卡顿。
const PACKAGED_JRE_DIR = "jre-x64"
const DEV_JDK_DIR = "zulu8.94.0.17-ca-jdk8.0.492-macosx_x64"
/**
* 解析运行服务端使用的 Java 可执行文件,优先项目内置 zulu8,其次 JAVA_HOME,最后 PATH 上的 java。
* 解析运行服务端使用的 Java 可执行文件:固定 x64 内置 zulu8,其次 JAVA_HOME,最后 PATH 上的 java。
*/
function resolveJavaBin() {
// 打包态:x64 JRE 随 extraResources 落在 Resources/jre-x64 下。
if (app.isPackaged) {
const packaged = path.join(process.resourcesPath, PACKAGED_JRE_DIR, "bin", "java")
if (fs.existsSync(packaged)) {
return packaged
}
// 兼容旧单架构包结构(Resources/jre)。
const legacy = path.join(process.resourcesPath, "jre", "bin", "java")
if (fs.existsSync(legacy)) {
return legacy
}
}
const projectRoot = resolveProjectRoot()
const bundled = path.join(
projectRoot,
"zulu8.94.0.17-ca-jdk8.0.492-macosx_x64",
"Contents",
"Home",
"bin",
"java",
)
const bundled = path.join(projectRoot, DEV_JDK_DIR, "Contents", "Home", "bin", "java")
if (fs.existsSync(bundled)) {
return bundled
}
@@ -53,6 +223,13 @@ function resolveJavaBin() {
* 解析服务端 classpath,优先使用 application 安装包 lib 目录(已包含全部运行依赖)。
*/
function resolveServerClasspath() {
// 打包态:服务端 jar 随 extraResources 落在 Resources/server/lib 下。
if (app.isPackaged) {
const packagedLib = path.join(process.resourcesPath, "server", "lib")
if (fs.existsSync(packagedLib)) {
return path.join(packagedLib, "*")
}
}
const installLib = path.join(
resolveProjectRoot(),
"mactfs",
@@ -71,6 +248,13 @@ function resolveServerClasspath() {
* 解析 TFS native 库目录,供 SDK 加载 JNI 库。
*/
function resolveNativeDirectory() {
// 打包态:JNI native 库随服务端 lib 一起落在 Resources/server/lib/native 下。
if (app.isPackaged) {
const packagedNative = path.join(process.resourcesPath, "server", "lib", "native")
if (fs.existsSync(packagedNative)) {
return packagedNative
}
}
const projectRoot = resolveProjectRoot()
const installNative = path.join(
projectRoot,
@@ -192,7 +376,9 @@ async function startService() {
}
args.push(SERVER_MAIN_CLASS)
serverProcess = spawn(resolveJavaBin(), args, {
cwd: path.join(resolveProjectRoot(), "mactfs"),
cwd: app.isPackaged ? process.resourcesPath : path.join(resolveProjectRoot(), "mactfs"),
// 传入父进程 pid,让 Java 后端自我看护:宿主崩溃 / 被强杀时它也会自己退出,避免遗留占用 38765 的孤儿。
env: { ...process.env, MACTFS_PARENT_PID: String(process.pid) },
stdio: "ignore",
})
serverProcess.on("exit", () => {
@@ -212,6 +398,78 @@ async function startService() {
}
}
/**
* 解析 MCP 入口脚本:打包态优先 Resources/mcp,开发态用单仓库内 mactfs-mcp/dist。
*/
function resolveMcpEntry() {
if (app.isPackaged) {
// 打包态:esbuild 单文件包随 extraResources 落在 Resources/mcp/index.cjs。
const packaged = path.join(process.resourcesPath, "mcp", "index.cjs")
if (fs.existsSync(packaged)) {
return packaged
}
}
// 开发态:tsc 产物(ESM + node_modules)。
const dev = path.join(resolveProjectRoot(), "mactfs-mcp", "dist", "index.js")
if (fs.existsSync(dev)) {
return dev
}
return null
}
/**
* 拉起 MCP 子进程(用 Electron 自带 Node 运行,避免依赖系统 node)。
* 通过 MACTFS_PARENT_PID 让 MCP 看护父进程,父死则自杀;崩溃后自动重拉。
*/
function startMcp() {
if (mcpProcess && mcpProcess.exitCode === null) {
return
}
const entry = resolveMcpEntry()
if (!entry) {
mcpLastError = "未找到 MCP 入口(开发态请先在 mactfs-mcp 执行 pnpm build)"
pushMcpLine("stderr", `[mactfs] ${mcpLastError}`)
console.error(`[mactfs] ${mcpLastError}`)
return
}
mcpLastError = null
mcpStartedAt = Date.now()
// stdout/stderr 改为管道捕获,写入环形缓冲供 UI 查看(原来是 ignore,日志被丢弃)。
mcpProcess = spawn(process.execPath, [entry], {
cwd: path.dirname(entry),
env: {
...process.env,
ELECTRON_RUN_AS_NODE: "1",
MACTFS_PARENT_PID: String(process.pid),
MACTFS_API_BASE_URL: API_BASE_URL,
MACTFS_TOKEN_FILE: TOKEN_FILE,
MACTFS_MCP_PORT: String(MCP_PORT),
},
stdio: ["ignore", "pipe", "pipe"],
})
pushMcpLine("stdout", `[mactfs] 已拉起 MCP 子进程 pid=${mcpProcess.pid}`)
if (mcpProcess.stdout) {
mcpProcess.stdout.on("data", (chunk) => appendMcpLog("stdout", chunk))
}
if (mcpProcess.stderr) {
mcpProcess.stderr.on("data", (chunk) => appendMcpLog("stderr", chunk))
}
mcpProcess.on("error", (error) => {
mcpLastError = error.message
pushMcpLine("stderr", `[mactfs] MCP 子进程启动失败:${error.message}`)
})
mcpProcess.on("exit", (code, signal) => {
flushMcpRemainder()
mcpLastExitCode = code
mcpProcess = null
pushMcpLine("stderr", `[mactfs] MCP 子进程退出 code=${code} signal=${signal ?? ""}`)
if (!appQuitting) {
mcpRestartCount += 1
setTimeout(startMcp, MCP_RESTART_DELAY_MS)
}
})
}
/**
* 批量检测本地绝对路径是否存在,供渲染层展示“已映射未下载”状态。
*/
@@ -236,6 +494,8 @@ function registerIpcHandlers() {
ipcMain.handle("mactfs:get-token", () => readToken())
ipcMain.handle("mactfs:get-service-status", () => checkHealth())
ipcMain.handle("mactfs:start-service", () => startService())
ipcMain.handle("mactfs:get-mcp-status", () => getMcpStatus())
ipcMain.handle("mactfs:get-mcp-logs", () => mcpLogBuffer.slice())
ipcMain.handle("mactfs:select-directory", async () => {
const result = await dialog.showOpenDialog({
properties: ["openDirectory", "createDirectory"],
@@ -246,15 +506,61 @@ function registerIpcHandlers() {
return result.filePaths[0]
})
ipcMain.handle("mactfs:paths-exist", (event, paths) => pathsExist(paths))
ipcMain.handle("mactfs:reveal-path", async (event, targetPath, isFolder) => {
if (typeof targetPath !== "string" || targetPath.length === 0 || !fs.existsSync(targetPath)) {
return false
}
// 目录直接进入访达中的该目录,文件则在访达中定位并选中。
if (isFolder) {
const error = await shell.openPath(targetPath)
return error === ""
}
shell.showItemInFolder(targetPath)
return true
})
}
/**
* 解析应用图标路径:开发态用 public/logo.png,打包态用构建产物中的 logo.png。
*/
function resolveAppIcon() {
const candidates = [
path.join(__dirname, "..", "public", "logo.png"),
path.join(__dirname, "..", "build", "client", "logo.png"),
]
for (const candidate of candidates) {
if (fs.existsSync(candidate)) {
return candidate
}
}
return null
}
/**
* 创建 Electron 主窗口,开发环境加载本地服务,生产环境加载构建后的静态页面。
*/
function createWindow() {
const iconPath = resolveAppIcon()
const isMac = process.platform === "darwin"
const mainWindow = new BrowserWindow({
width: 1280,
height: 840,
minWidth: 980,
minHeight: 640,
title: "MacTFS",
// 预设背景并延迟显示,避免启动白闪;macOS 下背景透明以透出 vibrancy 毛玻璃。
show: false,
backgroundColor: isMac ? "#00000000" : "#f9f9fa",
// macOS 隐藏系统标题栏 + 窗口级毛玻璃材质;其它平台回退系统标题栏与实色背景。
...(isMac
? {
titleBarStyle: "hiddenInset",
trafficLightPosition: { x: 16, y: 16 },
vibrancy: "sidebar",
visualEffectState: "followWindow",
}
: {}),
...(iconPath ? { icon: nativeImage.createFromPath(iconPath) } : {}),
webPreferences: {
preload: path.join(__dirname, "preload.cjs"),
contextIsolation: true,
@@ -262,17 +568,34 @@ function createWindow() {
},
})
mainWindow.once("ready-to-show", () => {
// 启动即铺满当前屏幕可视区域(保留程序坞与菜单栏,非独立全屏 Space)。
mainWindow.maximize()
mainWindow.show()
})
if (process.env.NODE_ENV === "development") {
mainWindow.loadURL("http://localhost:5173")
return
}
mainWindow.loadFile(path.join(__dirname, "../build/client/index.html"))
// 生产/打包态走自定义协议,保证前端的绝对资源路径(/assets/...)可被正确解析。
mainWindow.loadURL(APP_ORIGIN)
}
app.setName("MacTFS")
app.whenReady().then(() => {
// macOS 程序坞图标在开发态需要显式设置(BrowserWindow icon 仅对 Windows / Linux 生效)。
const iconPath = resolveAppIcon()
if (process.platform === "darwin" && iconPath && app.dock) {
app.dock.setIcon(nativeImage.createFromPath(iconPath))
}
registerAppProtocol()
registerIpcHandlers()
createWindow()
// 随客户端拉起 MCP;它会自行等待后端就绪,端口随客户端退出而消失。
startMcp()
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) {
@@ -287,8 +610,13 @@ app.on("window-all-closed", () => {
}
})
// 应用退出时回收由本进程拉起的服务端,避免遗留孤儿进程。
// 应用退出时回收由本进程拉起的服务端与 MCP,避免遗留孤儿进程。
app.on("will-quit", () => {
appQuitting = true
if (mcpProcess && mcpProcess.exitCode === null) {
mcpProcess.kill()
mcpProcess = null
}
if (serverProcess && serverProcess.exitCode === null) {
serverProcess.kill()
serverProcess = null
+18
View File
@@ -39,4 +39,22 @@ contextBridge.exposeInMainWorld("mactfs", {
pathsExist(paths) {
return ipcRenderer.invoke("mactfs:paths-exist", paths)
},
/**
* 在访达中打开:目录直接进入,文件定位并选中。
*/
revealPath(targetPath, isFolder) {
return ipcRenderer.invoke("mactfs:reveal-path", targetPath, isFolder)
},
/**
* 查询 MCP 子进程运行状态(含 /healthz 探活)。
*/
getMcpStatus() {
return ipcRenderer.invoke("mactfs:get-mcp-status")
},
/**
* 读取 MCP 子进程运行日志(最近 500 行)。
*/
getMcpLogs() {
return ipcRenderer.invoke("mactfs:get-mcp-logs")
},
})
+50 -1
View File
@@ -1,18 +1,66 @@
{
"name": "mactfsui",
"private": true,
"version": "1.0.0",
"description": "MacTFS - 面向 macOS 的 TFS 客户端(前端 + 内置 Java 服务)",
"author": "mydev",
"type": "module",
"main": "electron/main.cjs",
"scripts": {
"build": "react-router build",
"dev": "react-router dev",
"electron": "electron electron/main.cjs",
"electron:dev": "concurrently -k \"pnpm dev\" \"NO_PROXY=localhost,127.0.0.1 wait-on http://localhost:5173 && NODE_ENV=development electron electron/main.cjs\"",
"start": "pnpm build && pnpm electron",
"prepare:runtime": "node scripts/prepare-runtime.mjs",
"prepare:mcp": "pnpm --dir ../mactfs-mcp install && pnpm --dir ../mactfs-mcp run build:bundle",
"dist": "pnpm build && pnpm prepare:runtime && pnpm prepare:mcp && electron-builder --mac --arm64 --x64",
"typecheck": "react-router typegen && tsc",
"format": "prettier --write \"**/*.{ts,tsx}\""
},
"build": {
"appId": "com.mydev.mactfs",
"productName": "MacTFS",
"directories": {
"buildResources": "build-resources",
"output": "dist-app"
},
"files": [
"electron/**/*",
"build/client/**/*",
"package.json",
"!node_modules/**/*"
],
"extraResources": [
{
"from": "../mactfs/build/install/mactfs/lib",
"to": "server/lib"
},
{
"from": "runtime/jdk-x64",
"to": "jre-x64"
},
{
"from": "../mactfs-mcp/dist-bundle",
"to": "mcp"
}
],
"mac": {
"target": [
{
"target": "dmg",
"arch": [
"arm64",
"x64"
]
}
],
"category": "public.app-category.developer-tools",
"icon": "build-resources/icon.icns",
"identity": null
}
},
"dependencies": {
"@fontsource-variable/roboto-slab": "^5.2.8",
"@react-router/node": "7.13.1",
"@react-router/serve": "7.13.1",
"class-variance-authority": "^0.7.1",
@@ -36,6 +84,7 @@
"@types/react-dom": "^19.2.3",
"concurrently": "^9.2.1",
"electron": "^42.2.0",
"electron-builder": "^26.15.3",
"playwright-core": "^1.60.0",
"prettier": "^3.8.1",
"prettier-plugin-tailwindcss": "^0.7.2",
+1459 -8
View File
File diff suppressed because it is too large Load Diff
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

+127
View File
@@ -0,0 +1,127 @@
// FE-034 补充回归:目录已被既有 Workspace 映射(含用户真实挂起更改),
// 因此跳过创建/取消映射,只验证 目录对比、签出→Diff→撤销(仅 ai-smoke 文件)、操作日志。
import { _electron as electron } from "playwright-core"
import { mkdirSync } from "node:fs"
import path from "node:path"
const ROOT = process.cwd()
const SHOT_DIR = path.join(ROOT, ".e2e-shots")
mkdirSync(SHOT_DIR, { recursive: true })
const TEST_TREE_CHAIN = ["北京排水集团人力系统", "5SRC", "MicroFront", "subapp_pm", "mactfs"]
const SMOKE_FILE = "ai-smoke-20260606051038.txt"
const results = []
/** 记录一步结果并打印。 */
function record(step, ok, detail = "") {
results.push({ step, ok, detail })
console.log(`${ok ? "PASS" : "FAIL"} | ${step}${detail ? " | " + detail : ""}`)
}
/** 截图保存。 */
async function shot(win, name) {
await win.screenshot({ path: path.join(SHOT_DIR, `${name}.png`) })
}
const app = await electron.launch({
args: ["electron/main.cjs"],
cwd: ROOT,
env: { ...process.env, NODE_ENV: "development" },
})
try {
const win = await app.firstWindow()
win.setDefaultTimeout(90000)
// 进入工作台并导航到测试目录
await win.getByRole("button", { name: "连接 TFS" }).waitFor({ timeout: 90000 })
await win.getByRole("button", { name: "连接 TFS" }).click()
await win.getByText("选择 Collection").waitFor({ timeout: 120000 })
await win.locator("ul button", { hasText: "PKUSEHR" }).first().click()
await win.getByRole("button", { name: "进入工作台" }).click()
await win.getByText("源码目录").waitFor({ timeout: 120000 })
const tree = win.locator("aside").first()
for (const name of TEST_TREE_CHAIN) {
const node = tree.getByText(name, { exact: true }).first()
await node.waitFor({ timeout: 120000 })
await node.click()
await win.waitForTimeout(2500)
}
record("0 进入工作台并导航到测试目录", true)
// A. 目录对比(目录已映射 → 菜单应可用;忽略仅本地/仅服务器项保持默认)
await tree.getByText("mactfs", { exact: true }).first().click({ button: "right" })
const compareItem = win.getByRole("menuitem", { name: "目录对比", exact: true })
await compareItem.waitFor({ timeout: 10000 })
await compareItem.click()
await win.locator("[data-slot=dialog-title]", { hasText: "目录对比" }).waitFor()
await shot(win, "12-compare-options")
// 新交互:先确认选项再执行
const startButton = win.getByRole("button", { name: /开始对比|执行对比|对比/ }).first()
if ((await startButton.count()) > 0) {
await startButton.click()
}
await win.waitForTimeout(10000)
const compareText = await win.locator("[data-slot=dialog-content]").innerText()
record("A 目录对比弹窗", !compareText.includes("目录对比失败"), compareText.slice(0, 100).replace(/\n/g, " "))
await shot(win, "12-compare")
await win.keyboard.press("Escape")
await win.locator("[data-slot=dialog-content]").waitFor({ state: "detached", timeout: 10000 }).catch(() => {})
await win.waitForTimeout(800)
// B. 签出 ai-smoke 文件 → 挂起更改出现 → 与最新版本比较 → 撤销(只动这一个文件)
const fileRow = win.locator("section table tbody tr").filter({ hasText: SMOKE_FILE }).first()
await fileRow.click({ button: "right" })
const checkoutItem = win.getByRole("menuitem", { name: "签出编辑", exact: true })
await checkoutItem.waitFor({ timeout: 10000 })
await checkoutItem.click()
await win.waitForTimeout(15000)
const pendingPanel = await win.locator("aside").nth(1).innerText()
const hasPending = pendingPanel.includes(SMOKE_FILE)
record("B1 签出文件产生挂起更改", hasPending, "")
await shot(win, "13-pending")
if (hasPending) {
const row = win.locator("aside").nth(1).getByText(SMOKE_FILE).first()
await row.click({ button: "right" })
const diffItem = win.getByRole("menuitem", { name: "与最新版本比较", exact: true })
if ((await diffItem.count()) > 0) {
await diffItem.click()
await win.waitForTimeout(8000)
const diffText = await win.locator("[data-slot=dialog-content]").innerText()
record("B2 本地 vs latest Diff(Monaco)", diffText.includes("差异") || diffText.includes("一致"), diffText.slice(0, 80).replace(/\n/g, " "))
await shot(win, "14-diff")
await win.keyboard.press("Escape")
await win.locator("[data-slot=dialog-content]").waitFor({ state: "detached", timeout: 10000 }).catch(() => {})
await win.waitForTimeout(800)
}
// 仅撤销 ai-smoke 这一个文件,避免影响用户已有挂起更改
await row.click({ button: "right" })
await win.getByRole("menuitem", { name: "撤销更改", exact: true }).click()
await win.waitForTimeout(12000)
const afterUndo = await win.locator("aside").nth(1).innerText()
record("B3 撤销该文件挂起更改", !afterUndo.includes(SMOKE_FILE), "")
await shot(win, "15-undone")
}
// C. 操作日志面板有真实记录
const consoleText = await win.locator("footer").innerText()
record("C 操作日志记录", /checkout|undo|connect|serverTree|folderDiff|compare/i.test(consoleText), consoleText.split("\n").slice(0, 5).join(" | "))
await shot(win, "16-console")
} catch (error) {
record("EXCEPTION", false, String(error).slice(0, 300))
try {
const win = await app.firstWindow()
await shot(win, "98-exception")
} catch {}
} finally {
await app.close().catch(() => {})
}
console.log("\n==== RESULT SUMMARY ====")
for (const item of results) {
console.log(`${item.ok ? "✅" : "❌"} ${item.step}${item.detail ? " — " + item.detail : ""}`)
}
const failed = results.filter((item) => !item.ok).length
console.log(`\n${results.length - failed}/${results.length} passed`)
process.exit(failed > 0 ? 1 : 0)
+12
View File
@@ -57,6 +57,18 @@ try {
record("3 进入工作台(固定上下文)", topbar.includes("PKUSEHR"), topbar.replace(/\n/g, " "))
await shot(win, "03-workspace")
// 3.5 明暗主题三态切换(FE-033 回归):跟随系统 → 亮 → 暗 → 跟随系统
const themeButton = win.getByRole("button", { name: /主题:/ })
await themeButton.click()
await win.waitForTimeout(400)
await themeButton.click()
await win.waitForTimeout(600)
const darkApplied = await win.evaluate(() => document.documentElement.classList.contains("dark"))
record("3.5 主题切换到暗色", darkApplied, "")
await shot(win, "03b-dark-workspace")
await themeButton.click()
await win.waitForTimeout(600)
// 4. 逐级展开目录树到指定测试目录(懒加载真实数据)
const tree = win.locator("aside").first()
for (const name of TEST_TREE_CHAIN) {
+81
View File
@@ -0,0 +1,81 @@
import { existsSync, rmSync, cpSync, mkdtempSync } from "node:fs"
import { execFileSync } from "node:child_process"
import { tmpdir } from "node:os"
import { join, resolve, dirname } from "node:path"
import { fileURLToPath } from "node:url"
const here = dirname(fileURLToPath(import.meta.url))
const projectRoot = resolve(here, "..", "..")
// 服务端 JVM 固定 x64:TFS 的 JNI 原生库只含 i386/x86_64(无 arm64),arm64 JVM 无法加载。
// 因此 universal 包内只随附 x64 JRE,在 Apple Silicon 上经 Rosetta 2 运行服务端。
//
// JDK 体积大且是第三方二进制,不入库(见 .gitignore)。本地缺失时从 Azul 官方按需下载,
// 校验 sha256 后解压到仓库根目录,再继续复制流程。
const JDK_DIR_NAME = "zulu8.94.0.17-ca-jdk8.0.492-macosx_x64"
const JDK_URL = `https://cdn.azul.com/zulu/bin/${JDK_DIR_NAME}.tar.gz`
const JDK_SHA256 =
"5114b269b88e3d89b0d6b2c28af0c96b5489f340fbaded8fa17613b2adca180c"
const source = join(projectRoot, JDK_DIR_NAME, "Contents", "Home")
const dest = resolve(here, "..", "runtime", "jdk-x64")
function ensureJdkPresent() {
if (existsSync(join(source, "bin", "java"))) {
return
}
console.log("[prepare-runtime] 未找到本地 x64 JDK,开始从 Azul 下载…")
console.log("[prepare-runtime] URL:", JDK_URL)
const workDir = mkdtempSync(join(tmpdir(), "mactfs-jdk-"))
const archive = join(workDir, "zulu.tar.gz")
try {
execFileSync(
"curl",
["-fsSL", "--retry", "3", "--max-time", "600", "-o", archive, JDK_URL],
{ stdio: "inherit" },
)
const actualSha = execFileSync("shasum", ["-a", "256", archive])
.toString()
.trim()
.split(/\s+/)[0]
if (actualSha !== JDK_SHA256) {
throw new Error(
`JDK sha256 校验失败:期望 ${JDK_SHA256},实际 ${actualSha}`,
)
}
console.log("[prepare-runtime] sha256 校验通过,解压到", projectRoot)
execFileSync("tar", ["xzf", archive, "-C", projectRoot], {
stdio: "inherit",
})
} finally {
rmSync(workDir, { recursive: true, force: true })
}
if (!existsSync(join(source, "bin", "java"))) {
console.error("[prepare-runtime] 下载解压后仍未找到 x64 JDK:", source)
process.exit(1)
}
}
ensureJdkPresent()
console.log("[prepare-runtime] 复制 x64 JDK ->", dest)
rmSync(dest, { recursive: true, force: true })
cpSync(source, dest, { recursive: true })
// 运行服务用不到的部分,复制后删除以缩小打包体积(仍保留 bin/java + jre + lib)。
const drop = ["src.zip", "demo", "sample", "man", "include"]
for (const name of drop) {
rmSync(join(dest, name), { recursive: true, force: true })
}
if (!existsSync(join(dest, "bin", "java"))) {
console.error("[prepare-runtime] 精简后 bin/java 缺失,终止。")
process.exit(1)
}
console.log("[prepare-runtime] x64 JRE 准备完成:", dest)
+49
View File
@@ -0,0 +1,49 @@
// 快速视觉确认:进入工作台后截图亮色 / 暗色画布卡片布局,不做任何写操作。
import { _electron as electron } from "playwright-core"
import { mkdirSync } from "node:fs"
import path from "node:path"
const ROOT = process.cwd()
const SHOT_DIR = path.join(ROOT, ".e2e-shots")
mkdirSync(SHOT_DIR, { recursive: true })
const app = await electron.launch({
args: ["electron/main.cjs"],
cwd: ROOT,
env: { ...process.env, NODE_ENV: "development" },
})
try {
const win = await app.firstWindow()
win.setDefaultTimeout(90000)
await win.getByRole("button", { name: "连接 TFS" }).waitFor({ timeout: 90000 })
await win.screenshot({ path: path.join(SHOT_DIR, "20-connect-v2.png") })
await win.getByRole("button", { name: "连接 TFS" }).click()
await win.getByText("选择 Collection").waitFor({ timeout: 120000 })
await win.screenshot({ path: path.join(SHOT_DIR, "21-collections-v2.png") })
await win.locator("ul button", { hasText: "PKUSEHR" }).first().click()
await win.getByRole("button", { name: "进入工作台" }).click()
await win.getByText("源码目录").waitFor({ timeout: 120000 })
await win.waitForTimeout(6000)
await win.screenshot({ path: path.join(SHOT_DIR, "22-workspace-cards.png") })
// 验证表头 sticky:滚动文件列表后表头应仍可见
await win.evaluate(() => {
const container = document.querySelector('[data-slot="table-container"]')
if (container) {
container.scrollTop = 400
}
})
await win.waitForTimeout(600)
await win.screenshot({ path: path.join(SHOT_DIR, "24-sticky-header.png") })
const themeButton = win.getByRole("button", { name: /主题:/ })
await themeButton.click()
await win.waitForTimeout(400)
await themeButton.click()
await win.waitForTimeout(800)
await win.screenshot({ path: path.join(SHOT_DIR, "23-workspace-cards-dark.png") })
await themeButton.click()
await win.waitForTimeout(400)
console.log("screenshots done")
} finally {
await app.close().catch(() => {})
}
+21 -3
View File
@@ -31,14 +31,14 @@ blocked
| Core | 12 | 12 | 100% |
| Server API | 10 | 10 | 100% |
| CLI | 2 | 2 | 100% |
| Frontend | 18 | 18 | 100% |
| Frontend | 34 | 34 | 100% |
| Feature E2E | 0 | 5 | 0% |
| Release | 0 | 4 | 0% |
| Overall | 42 | 51 | 82% |
| Overall | 58 | 67 | 87% |
## 当前阶段
Feature E2E(前端阶段含增强已全部完成)
UI 风格改版·macOS 原生风方案完成(分支 `feature/ui-macos-restyle`,FE-026 ~ FE-034 全部 done;姊妹分支 `feature/ui-modern-restyle` 的现代工具风方案也已完成,两套可并行对比体验,截图见 [docs/ui-restyle-screenshots](/Users/fenghp/Desktop/DEV/project/mydev/docs/ui-restyle-screenshots))
## 前端规范
@@ -46,7 +46,9 @@ Feature E2E(前端阶段含增强已全部完成)
## 下一步任务
- 两个 UI 分支对比体验后选定方案
- [FEATURE-001-连接与目录浏览端到端验收.md](/Users/fenghp/Desktop/DEV/project/mydev/task/feature/FEATURE-001-连接与目录浏览端到端验收.md)(需要真实 TFS 环境)
- UI 改版完成后再回到 [FEATURE-001-连接与目录浏览端到端验收.md](/Users/fenghp/Desktop/DEV/project/mydev/task/feature/FEATURE-001-连接与目录浏览端到端验收.md)(需要真实 TFS 环境)
## Core
@@ -109,6 +111,22 @@ Feature E2E(前端阶段含增强已全部完成)
| [FE-016-优化Diff与历史弹窗体验.md](/Users/fenghp/Desktop/DEV/project/mydev/task/frontend/FE-016-优化Diff与历史弹窗体验.md) | done | P1 |
| [FE-017-实现工作台手动刷新.md](/Users/fenghp/Desktop/DEV/project/mydev/task/frontend/FE-017-实现工作台手动刷新.md) | done | P1 |
| [FE-018-Diff弹窗替换为MonacoDiffEditor.md](/Users/fenghp/Desktop/DEV/project/mydev/task/frontend/FE-018-Diff弹窗替换为MonacoDiffEditor.md) | done | P1 |
| [FE-019-实现对象属性与获取特定版本.md](/Users/fenghp/Desktop/DEV/project/mydev/task/frontend/FE-019-实现对象属性与获取特定版本.md) | done | P0 |
| [FE-020-实现重命名.md](/Users/fenghp/Desktop/DEV/project/mydev/task/frontend/FE-020-实现重命名.md) | done | P0 |
| [FE-021-实现变更集回滚.md](/Users/fenghp/Desktop/DEV/project/mydev/task/frontend/FE-021-实现变更集回滚.md) | done | P1 |
| [FE-022-实现工作区与Mapping集中管理.md](/Users/fenghp/Desktop/DEV/project/mydev/task/frontend/FE-022-实现工作区与Mapping集中管理.md) | done | P1 |
| [FE-023-实现分支.md](/Users/fenghp/Desktop/DEV/project/mydev/task/frontend/FE-023-实现分支.md) | done | P1 |
| [FE-024-实现合并.md](/Users/fenghp/Desktop/DEV/project/mydev/task/frontend/FE-024-实现合并.md) | done | P1 |
| [FE-025-实现访达打开与添加本地文件.md](/Users/fenghp/Desktop/DEV/project/mydev/task/frontend/FE-025-实现访达打开与添加本地文件.md) | done | P0 |
| [FE-026-建立macOS设计基建.md](/Users/fenghp/Desktop/DEV/project/mydev/task/frontend/FE-026-建立macOS设计基建.md) | done | P0 |
| [FE-027-Electron窗口macOS化.md](/Users/fenghp/Desktop/DEV/project/mydev/task/frontend/FE-027-Electron窗口macOS化.md) | done | P0 |
| [FE-028-重设计登录页.md](/Users/fenghp/Desktop/DEV/project/mydev/task/frontend/FE-028-重设计登录页.md) | done | P0 |
| [FE-029-工作台外壳与顶栏改版.md](/Users/fenghp/Desktop/DEV/project/mydev/task/frontend/FE-029-工作台外壳与顶栏改版.md) | done | P0 |
| [FE-030-目录树与文件列表精致化.md](/Users/fenghp/Desktop/DEV/project/mydev/task/frontend/FE-030-目录树与文件列表精致化.md) | done | P0 |
| [FE-031-弹窗体系统一macOS风格.md](/Users/fenghp/Desktop/DEV/project/mydev/task/frontend/FE-031-弹窗体系统一macOS风格.md) | done | P1 |
| [FE-032-操作反馈与微交互.md](/Users/fenghp/Desktop/DEV/project/mydev/task/frontend/FE-032-操作反馈与微交互.md) | done | P1 |
| [FE-033-明暗主题跟随系统.md](/Users/fenghp/Desktop/DEV/project/mydev/task/frontend/FE-033-明暗主题跟随系统.md) | done | P1 |
| [FE-034-UI改版回归验收.md](/Users/fenghp/Desktop/DEV/project/mydev/task/frontend/FE-034-UI改版回归验收.md) | done | P0 |
## Feature E2E
@@ -0,0 +1,113 @@
# FE-019 实现对象属性与获取特定版本
## 状态
done
## 优先级
P0
## 所属阶段
frontend
## 依赖任务
- FE-014
- FE-015
## 需求来源
- [docs/mactfs-ui-enhancement-requirements-2.md](/Users/fenghp/Desktop/DEV/project/mydev/docs/mactfs-ui-enhancement-requirements-2.md) R5
## 目标
为选中的文件 / 文件夹提供「高级」能力:属性弹窗(服务器路径、本地路径、映射与挂起状态、
服务器最新版本信息),以及右键直达的「获取特定版本…」(按 changeset 把对象本地内容
整体切到该变更集时刻),对齐 VS 的 Properties 与 Get Specific Version。
## 实现范围
- server 新增 `GET /api/items/info?serverPath=`:返回对象类型、最新 changeset、
签入时间、签入人,文件补充大小与编码(core 用 `VersionControlClient.getItem`)
- 前端 API 层补充 `itemInfo`
- 右键菜单(文件与目录、树 / 列表 / 挂起 / 对比来源均可见)新增:
- 「属性…」:弹窗展示服务器路径、本地路径(未映射显示「未映射」)、对象类型、
映射状态、挂起状态、服务器最新版本信息;路径支持一键复制
- 「获取特定版本…」:弹窗内 changeset 输入框 + 「从历史选择…」内嵌历史列表点选回填;
明确提示会覆盖本地内容(目录递归);确认后调用既有 `/api/files/get-version`
- 完成后刷新目录列表与挂起更改
- 未映射对象:「获取特定版本…」置灰并给出原因
## 不在范围
- 不做按日期 / 标签的版本规格(仅 changeset)
- 不做回滚(产生挂起更改的反做走 FE-021)
- 不改历史弹窗既有「获取此版本」入口
## 涉及文件
- [mactfs/src/main/java/com/mydev/mactfs/core/MacTfsCoreService.java](/Users/fenghp/Desktop/DEV/project/mydev/mactfs/src/main/java/com/mydev/mactfs/core/MacTfsCoreService.java)
- [mactfs/src/main/java/com/mydev/mactfs/server/MacTfsServer.java](/Users/fenghp/Desktop/DEV/project/mydev/mactfs/src/main/java/com/mydev/mactfs/server/MacTfsServer.java)
- [mactfsui/app/lib/api](/Users/fenghp/Desktop/DEV/project/mydev/mactfsui/app/lib/api)
- [mactfsui/app/lib/tfs/actions.ts](/Users/fenghp/Desktop/DEV/project/mydev/mactfsui/app/lib/tfs/actions.ts)
- [mactfsui/app/hooks/use-file-actions.ts](/Users/fenghp/Desktop/DEV/project/mydev/mactfsui/app/hooks/use-file-actions.ts)
- [mactfsui/app/components/app/workspace-dialogs.tsx](/Users/fenghp/Desktop/DEV/project/mydev/mactfsui/app/components/app/workspace-dialogs.tsx)
- [mactfsui/app/components/explorer](/Users/fenghp/Desktop/DEV/project/mydev/mactfsui/app/components/explorer)
## 验收标准
- 文件 / 目录右键可打开「属性…」,服务器路径与本地路径展示正确,未映射对象明确标识
- 属性弹窗展示服务器侧最新 changeset、签入时间、签入人;文件展示大小与编码
- 右键「获取特定版本…」可输入或从历史点选 changeset,确认后本地内容切到该版本
- 目录执行获取特定版本为递归覆盖,完成后目录列表与挂起更改刷新
- 服务端构建通过、前端 typecheck 通过
## 测试方式
```bash
cd /Users/fenghp/Desktop/DEV/project/mydev/mactfs
../tfsIntegration/gradlew --no-daemon build installDist
cd /Users/fenghp/Desktop/DEV/project/mydev/mactfsui
pnpm typecheck
```
## 完成记录
### 实际修改文件
- `mactfs/src/main/java/com/mydev/mactfs/core/MacTfsCoreService.java`:新增 `getItemInfo`(`getItem` 取最新版本 / 大小 / 编码,`queryHistory` 限 1 条取签入人 / 时间 / 备注,目录按子树最近签入计)与数据类 `TfsItemInfo`
- `mactfs/src/main/java/com/mydev/mactfs/server/MacTfsServer.java`:新增 `GET /api/items/info`
- `mactfsui/app/lib/api/types.ts`:新增 `ItemInfo` 类型
- `mactfsui/app/lib/api/endpoints.ts` / `index.ts`:新增 `getItemInfo` 接口封装与类型导出
- `mactfsui/app/lib/tfs/actions.ts`:`FileActionId` 新增 `properties` / `getSpecificVersion`;目录与文件菜单尾部新增高级分组(获取特定版本… 危险态、属性…);pending 来源仅提供属性(pendingAdd 不提供)
- `mactfsui/app/hooks/use-file-actions.ts`:弹窗状态新增 `properties` / `getVersion`,动作分发打开对应弹窗
- `mactfsui/app/components/explorer/properties-dialog.tsx`(新增):属性弹窗(服务器 / 本地路径可复制、映射与挂起状态 badge、最新 changeset / 签入时间 / 签入人 / 备注、文件大小与编码)
- `mactfsui/app/components/explorer/get-version-dialog.tsx`(新增):获取特定版本弹窗(changeset 输入 + 历史列表点选回填 + 覆盖警示 + 确认执行)
- `mactfsui/app/components/app/workspace-dialogs.tsx`:渲染两个新弹窗,`getVersion` 复用既有 `runGetVersion` 编排(含刷新与通知)
### 实际实现内容
- 右键菜单(树 / 列表,文件与目录)尾部新增高级分组:「获取特定版本…」「属性…」;未映射对象获取特定版本置灰并给出原因
- 属性弹窗本地信息即时展示(路径 / 映射 / 挂起),服务器信息异步加载;路径一键复制
- 获取特定版本弹窗内嵌该对象历史(最近 100 条)点选回填,也可手动输入 changeset;确认后调用既有 `/api/files/get-version`(目录递归覆盖),完成后刷新目录列表与挂起更改
### 已执行测试
- `../tfsIntegration/gradlew --no-daemon build installDist`:通过
- `pnpm typecheck`:通过
### 未执行测试及原因
- 真实 TFS 环境下的属性值与获取特定版本落盘验证:本机无真实 TFS 环境,待 FEATURE 阶段执行
### 是否满足验收标准
- 属性弹窗展示服务器 / 本地路径、未映射标识、最新版本信息、文件大小与编码:满足(代码层面)
- 右键直达获取特定版本(输入 / 历史点选)并递归覆盖后刷新:满足(代码层面)
- 服务端构建与前端 typecheck 通过:满足
### 遗留问题
- 属性弹窗的签入人来自最近一条历史,深目录大子树首次查询可能稍慢(服务端已限 1 条)
+115
View File
@@ -0,0 +1,115 @@
# FE-020 实现重命名
## 状态
done
## 优先级
P0
## 所属阶段
frontend
## 依赖任务
- FE-010
- FE-013
## 需求来源
- [docs/mactfs-ui-enhancement-requirements-2.md](/Users/fenghp/Desktop/DEV/project/mydev/docs/mactfs-ui-enhancement-requirements-2.md) R6
## 目标
为已映射的文件 / 文件夹提供重命名能力:产生 rename 挂起更改,可撤销,签入后服务器生效,
对齐 VS Source Control Explorer 的 Rename。
## 实现范围
- core 新增 `rename(serverPath, newName)`:`Workspace.pendRename`,对象须已映射;
返回结果复用 `TfsFileOperationResult`
- server 新增 `POST /api/files/rename`(参数 `serverPath`、`newName`)
- 前端 API 层补充 `rename`
- 右键菜单新增「重命名…」(树 / 列表来源,文件与目录均可):
- 弹窗输入新名称,校验:非空、不含 `/ \ : * ? " < > |`、与原名不同
- 已有挂起 rename 或未映射时置灰并给出原因
- 挂起更改面板展示 rename 状态(`pendingRename`),显示「旧名 → 新名」
- rename 挂起更改支持 undo 撤销、checkin 签入(复用既有流程)
- 完成后刷新目录树、目录列表与挂起更改
## 不在范围
- 不做跨目录移动(Move)
- 不做批量重命名
- 不处理大小写仅变化的特殊冲突场景(记录遗留问题即可)
## 涉及文件
- [mactfs/src/main/java/com/mydev/mactfs/core/MacTfsCoreService.java](/Users/fenghp/Desktop/DEV/project/mydev/mactfs/src/main/java/com/mydev/mactfs/core/MacTfsCoreService.java)
- [mactfs/src/main/java/com/mydev/mactfs/server/MacTfsServer.java](/Users/fenghp/Desktop/DEV/project/mydev/mactfs/src/main/java/com/mydev/mactfs/server/MacTfsServer.java)
- [mactfsui/app/lib/api](/Users/fenghp/Desktop/DEV/project/mydev/mactfsui/app/lib/api)
- [mactfsui/app/lib/tfs/actions.ts](/Users/fenghp/Desktop/DEV/project/mydev/mactfsui/app/lib/tfs/actions.ts)
- [mactfsui/app/lib/tfs/status.ts](/Users/fenghp/Desktop/DEV/project/mydev/mactfsui/app/lib/tfs/status.ts)
- [mactfsui/app/hooks/use-file-actions.ts](/Users/fenghp/Desktop/DEV/project/mydev/mactfsui/app/hooks/use-file-actions.ts)
- [mactfsui/app/components/inspector/changes-panel.tsx](/Users/fenghp/Desktop/DEV/project/mydev/mactfsui/app/components/inspector/changes-panel.tsx)
- [mactfsui/app/components/app/workspace-dialogs.tsx](/Users/fenghp/Desktop/DEV/project/mydev/mactfsui/app/components/app/workspace-dialogs.tsx)
## 验收标准
- 已映射文件 / 目录右键「重命名…」可输入新名称并提交
- 重命名后产生 rename 挂起更改,挂起面板显示「旧名 → 新名」
- undo 可撤销重命名(本地名称还原);checkin 后服务器生效
- 非法名称、重复名称、未映射对象有明确校验与置灰提示
- 服务端构建通过、前端 typecheck 通过
## 测试方式
```bash
cd /Users/fenghp/Desktop/DEV/project/mydev/mactfs
../tfsIntegration/gradlew --no-daemon build installDist
cd /Users/fenghp/Desktop/DEV/project/mydev/mactfsui
pnpm typecheck
```
真实 TFS 的 rename 签入验证须用户确认后执行。
## 完成记录
### 实际修改文件
- `mactfs/src/main/java/com/mydev/mactfs/core/MacTfsCoreService.java`:新增 `rename`(`Workspace.pendRename`,同目录改名,校验非法字符与同名);`TfsPendingChangeInfo` 新增 `sourceServerPath`(rename 携带原路径)
- `mactfs/src/main/java/com/mydev/mactfs/server/MacTfsServer.java`:新增 `POST /api/files/rename`
- `mactfsui/app/lib/api/types.ts`:`PendingChange` 新增 `sourceServerPath`
- `mactfsui/app/lib/api/endpoints.ts`:新增 `renameFile`
- `mactfsui/app/lib/tfs/actions.ts`:`FileActionId` 新增 `rename`;目录与文件菜单新增「重命名…」(未映射 / pendingAdd / pendingDelete / pendingRename 置灰并给出原因)
- `mactfsui/app/components/explorer/rename-dialog.tsx`(新增):重命名弹窗(默认选中主名、Enter 提交、非法字符 / 同名校验、说明挂起生效规则)
- `mactfsui/app/hooks/use-file-actions.ts`:弹窗状态新增 `rename`,新增 `handleRenameConfirmed`(执行后刷新挂起更改与目录列表)
- `mactfsui/app/components/app/workspace-dialogs.tsx` / `workspace-shell.tsx`:渲染并接线重命名弹窗
- `mactfsui/app/components/inspector/changes-panel.tsx`:pendingRename 项展示「旧名 → 新名」
### 实际实现内容
- 已映射文件 / 目录右键「重命名…」:弹窗输入新名称(文件自动选中主名),校验非空、非法字符(`/ \ : * ? " < > |`)、与原名不同
- 提交后产生 rename 挂起更改:挂起面板以「旧名 → 新名」展示,badge 为「挂起重命名」;可 undo 撤销、checkin 后服务器生效(复用既有流程)
- 完成后自动刷新挂起更改与目录列表
### 已执行测试
- `../tfsIntegration/gradlew --no-daemon build installDist`:通过
- `pnpm typecheck`:通过
### 未执行测试及原因
- 真实 TFS 的 rename 挂起与签入验证:本机无真实 TFS 环境,待 FEATURE 阶段执行
### 是否满足验收标准
- 重命名入口、校验、挂起展示「旧名 → 新名」、undo / checkin 复用:满足(代码层面)
- 服务端构建与前端 typecheck 通过:满足
### 遗留问题
- 大小写仅变化的重命名在不区分大小写的服务器上行为未验证(已在不在范围中声明)
- 目录树节点名在签入前仍显示旧名(rename 仅挂起,签入后刷新树即可)
@@ -0,0 +1,111 @@
# FE-021 实现变更集回滚
## 状态
done
## 优先级
P1
## 所属阶段
frontend
## 依赖任务
- FE-009
- FE-010
- FE-019
## 需求来源
- [docs/mactfs-ui-enhancement-requirements-2.md](/Users/fenghp/Desktop/DEV/project/mydev/docs/mactfs-ui-enhancement-requirements-2.md) R7
## 目标
提供 TFS Rollback 能力:把某个变更集的改动反做(或回滚到某变更集,反做其后的全部改动),
产生挂起更改由用户审查后签入,对齐 VS 的 Rollback Entire Changeset / Rollback to a Specific Version。
与「获取特定版本」(只动本地、不产生挂起更改)形成互补。
## 实现范围
- core 新增 `rollback(serverPath, mode, changeset)`:`Workspace.rollback` + `RollbackOptions`
- `single`:仅反做该 changeset
- `toVersion`:反做该 changeset 之后的全部改动
- server 新增 `POST /api/files/rollback`(参数 `serverPath`、`mode`、`changeset`)
- 前端 API 层补充 `rollback`
- 历史弹窗记录行新增「回滚此变更集…」「回滚到此变更集…」:
- 确认弹窗说明:只产生挂起更改、不会直接入库、签入前可撤销
- 对象未映射时置灰并给出原因
- 回滚产生冲突时进入既有冲突弹窗流程
- 完成后刷新挂起更改与目录列表,通知用户到挂起面板审查并签入
## 不在范围
- 不做自动签入(回滚结果必须人工审查)
- 不做跨对象批量回滚(仅当前历史弹窗目标对象范围内)
- 不做三方合并编辑器
## 涉及文件
- [mactfs/src/main/java/com/mydev/mactfs/core/MacTfsCoreService.java](/Users/fenghp/Desktop/DEV/project/mydev/mactfs/src/main/java/com/mydev/mactfs/core/MacTfsCoreService.java)
- [mactfs/src/main/java/com/mydev/mactfs/server/MacTfsServer.java](/Users/fenghp/Desktop/DEV/project/mydev/mactfs/src/main/java/com/mydev/mactfs/server/MacTfsServer.java)
- [mactfsui/app/lib/api](/Users/fenghp/Desktop/DEV/project/mydev/mactfsui/app/lib/api)
- [mactfsui/app/hooks/use-file-actions.ts](/Users/fenghp/Desktop/DEV/project/mydev/mactfsui/app/hooks/use-file-actions.ts)
- [mactfsui/app/components/explorer/history-dialog.tsx](/Users/fenghp/Desktop/DEV/project/mydev/mactfsui/app/components/explorer/history-dialog.tsx)
- [mactfsui/app/components/app/workspace-dialogs.tsx](/Users/fenghp/Desktop/DEV/project/mydev/mactfsui/app/components/app/workspace-dialogs.tsx)
## 验收标准
- 历史记录可执行「回滚此变更集…」,确认后产生对应的反做挂起更改
- 历史记录可执行「回滚到此变更集…」,其后全部改动被反做为挂起更改
- 回滚结果可在挂起面板审查、可 undo、可签入
- 回滚遇到本地修改冲突时进入冲突弹窗
- 服务端构建通过、前端 typecheck 通过
## 测试方式
```bash
cd /Users/fenghp/Desktop/DEV/project/mydev/mactfs
../tfsIntegration/gradlew --no-daemon build installDist
cd /Users/fenghp/Desktop/DEV/project/mydev/mactfsui
pnpm typecheck
```
真实 TFS 的回滚签入验证须用户确认后执行。
## 完成记录
### 实际修改文件
- `mactfs/src/main/java/com/mydev/mactfs/core/MacTfsCoreService.java`:新增 `rollback`(`Workspace.rollback`;`single` 模式 from=to=该 changeset,`toVersion` 模式 `RollbackOptions.TO_VERSION` 反做其后全部改动;复用 `TfsGetLatestResult` 返回 operations / conflicts / failures)
- `mactfs/src/main/java/com/mydev/mactfs/server/MacTfsServer.java`:新增 `POST /api/files/rollback`(长写超时)
- `mactfsui/app/lib/api/endpoints.ts`:新增 `rollback`
- `mactfsui/app/hooks/use-file-actions.ts`:新增 `runRollback`(执行后刷新挂起更改与目录列表,conflicts>0 自动进入冲突弹窗)
- `mactfsui/app/components/explorer/history-dialog.tsx`:历史记录行新增右键菜单(获取此版本… / 回滚此变更集… / 回滚到此变更集…)与回滚确认弹窗(说明只产生挂起更改)
- `mactfsui/app/components/app/workspace-dialogs.tsx` / `workspace-shell.tsx`:透传 `onRollback`
### 实际实现内容
- 历史弹窗每条记录右键提供两种回滚:「回滚此变更集」(仅反做该提交)与「回滚到此变更集」(反做其后全部改动,回到该时刻内容)
- 确认弹窗明确:回滚只产生挂起更改、不直接写服务器、可撤销、需签入;执行后顶部通知展示 operations / conflicts / failures 统计并提示去挂起面板审查
- 回滚冲突自动进入既有冲突弹窗;挂起更改可 undo / checkin(复用既有流程)
### 已执行测试
- `pnpm typecheck`:通过
- `../tfsIntegration/gradlew --no-daemon build installDist`:通过
### 未执行测试及原因
- 真实 TFS 的回滚挂起与签入验证:本机无真实 TFS 环境,待 FEATURE 阶段执行
### 是否满足验收标准
- 两种回滚入口 + 确认弹窗 + 挂起审查 / 撤销 / 签入 + 冲突进冲突弹窗:满足(代码层面)
- 服务端构建与前端 typecheck 通过:满足
### 遗留问题
- `toVersion` 模式的 from=null + TO_VERSION 语义对齐 .NET SDK 文档,真实服务器行为待验证
@@ -0,0 +1,112 @@
# FE-022 实现工作区与 Mapping 集中管理
## 状态
done
## 优先级
P1
## 所属阶段
frontend
## 依赖任务
- FE-007
- FE-013
## 需求来源
- [docs/mactfs-ui-enhancement-requirements-2.md](/Users/fenghp/Desktop/DEV/project/mydev/docs/mactfs-ui-enhancement-requirements-2.md) R8
## 目标
提供工作区集中管理入口:在一个弹窗内查看 Workspace 信息和全部 Mapping,
支持新增、删除、修改本地路径,替代只能在目录树逐个右键操作的现状,
对齐 VS 的 Edit Workspace 对话框。
## 实现范围
- 顶栏新增「工作区」按钮,打开集中管理弹窗:
- 工作区信息区:名称、Owner、Computer、服务器地址、Collection
- Mapping 表格:服务器路径、本地路径、本地目录是否存在(不存在标红提示)
- Mapping 操作:
- 新增:复用既有映射弹窗逻辑(选择服务器路径 + 本地父目录),完成后可触发 Get Latest
- 删除:确认弹窗,说明不会删除本地已下载文件;调用既有 `DELETE /api/mappings`
- 修改本地路径:实现为「删旧 + 加新」,确认弹窗提示将按新路径重新获取
- 操作完成后刷新工作区上下文(mappings)、目录树映射标识与挂起更改
- server 复用既有 `GET/POST/DELETE /api/mappings`,原则上不新增接口;
如需 Workspace 详细信息可扩展既有 `/api/workspace/context` 返回字段
## 不在范围
- 不做多 Workspace 创建 / 切换 / 删除
- 不做 cloak(遮蔽)类型的 mapping
- 不迁移本地已下载内容(修改本地路径后由用户自行决定是否重新获取)
## 涉及文件
- [mactfsui/app/components/app/top-bar.tsx](/Users/fenghp/Desktop/DEV/project/mydev/mactfsui/app/components/app/top-bar.tsx)
- [mactfsui/app/components/app/workspace-shell.tsx](/Users/fenghp/Desktop/DEV/project/mydev/mactfsui/app/components/app/workspace-shell.tsx)
- [mactfsui/app/components/app/workspace-dialogs.tsx](/Users/fenghp/Desktop/DEV/project/mydev/mactfsui/app/components/app/workspace-dialogs.tsx)
- [mactfsui/app/components/explorer/mapping-dialog.tsx](/Users/fenghp/Desktop/DEV/project/mydev/mactfsui/app/components/explorer/mapping-dialog.tsx)
- [mactfsui/app/lib/api](/Users/fenghp/Desktop/DEV/project/mydev/mactfsui/app/lib/api)
- [mactfsui/app/lib/tfs/session.ts](/Users/fenghp/Desktop/DEV/project/mydev/mactfsui/app/lib/tfs/session.ts)
- [mactfs/src/main/java/com/mydev/mactfs/server/MacTfsServer.java](/Users/fenghp/Desktop/DEV/project/mydev/mactfs/src/main/java/com/mydev/mactfs/server/MacTfsServer.java)
## 验收标准
- 顶栏可打开工作区管理弹窗,正确展示 Workspace 信息与全部 Mapping
- 可在弹窗内新增 Mapping,与目录树右键映射效果一致
- 可删除 Mapping(带确认),目录树映射标识同步更新
- 可修改 Mapping 本地路径(删旧加新),有重新获取提示
- 本地目录不存在的 Mapping 有醒目标识
- 前端 typecheck 通过
## 测试方式
```bash
cd /Users/fenghp/Desktop/DEV/project/mydev/mactfsui
pnpm typecheck
```
## 完成记录
### 实际修改文件
- `mactfsui/app/components/explorer/workspace-manage-dialog.tsx`(新增):集中管理弹窗
- 工作区信息区:Workspace / 服务器 / Collection / Owner / Computer / Mapping 数量(Owner、Computer 通过幂等的 `POST /api/workspace/ensure` 获取,未新增服务端接口)
- Mapping 表格:服务端路径、本地路径、本地目录存在性(Electron `pathsExist` 批量检测,不存在标红)
- 新增:输入服务端路径(校验 `$/` 前缀)→ 复用既有 `MappingDialog`(父目录选择 + 后端预校验 + 可选立即获取)
- 删除:确认弹窗(说明不删除本地文件),调用既有 `DELETE /api/mappings`
- 修改本地路径:内置 `EditMappingDialog`,选择新父目录 → `check-target` 预校验 → 「删旧 + 加新」,提示需重新获取
- `mactfsui/app/components/app/top-bar.tsx`:顶栏新增「工作区」按钮
- `mactfsui/app/components/app/workspace-shell.tsx`:持有弹窗显隐,Mapping 变化后统一刷新 mappings 与目录列表
### 实际实现内容
- 顶栏「工作区」一键打开集中管理弹窗,无需到目录树逐个右键
- 全部 mapping 一屏可见,本地目录缺失(已映射未下载 / 被手动删除)醒目标红
- 三类操作(新增 / 删除 / 改路径)完成后目录树映射标识、列表状态列同步刷新
- 未新增服务端接口,全部复用既有 mappings API
### 已执行测试
- `pnpm typecheck`:通过
- 服务端无改动,无需重新构建(沿用 FE-021 构建产物)
### 未执行测试及原因
- 真实 TFS 环境的映射增删改落盘验证:本机无环境,待 FEATURE 阶段执行
### 是否满足验收标准
- 工作区信息与全部 Mapping 展示、增 / 删 / 改、本地目录缺失标识:满足(代码层面)
- 前端 typecheck 通过:满足
### 遗留问题
- 「修改本地路径」中删旧成功但加新失败时会处于无映射状态(已在弹窗错误提示中说明需重新映射)
- 删除映射后该子树挂起更改的处理沿用服务端默认行为,未做额外清理
+111
View File
@@ -0,0 +1,111 @@
# FE-023 实现分支
## 状态
done
## 优先级
P1
## 所属阶段
frontend
## 依赖任务
- FE-010
- FE-019
## 需求来源
- [docs/mactfs-ui-enhancement-requirements-2.md](/Users/fenghp/Desktop/DEV/project/mydev/docs/mactfs-ui-enhancement-requirements-2.md) R9
## 目标
为服务端目录 / 文件提供分支能力:从源路径分叉出目标路径(pendBranch 产生挂起更改,
签入后服务器生效),对齐 VS Source Control Explorer 的 Branch。
## 实现范围
- core 新增 `branch(sourceServerPath, targetServerPath, changeset?)`:
`Workspace.pendBranch`,默认基于 latest,可指定 changeset
- server 新增 `POST /api/files/branch`
- 前端 API 层补充 `branch`
- 右键菜单新增「分支…」(树 / 列表来源):
- 弹窗:源路径只读展示;目标路径默认 `源路径-branch` 可编辑;
可选「基于指定 changeset」(输入或从历史点选,复用 FE-019 版本选择器)
- 校验:目标路径不能与源相同、不能已存在;目标父目录必须已映射(pendBranch 需本地落盘),
未满足时给出明确提示
- 分支产生 branch 挂起更改,挂起面板可见、可 undo、可签入(复用既有流程)
- 完成后刷新目录树与挂起更改
## 不在范围
- 不做分支可视化(Branch Hierarchy 图)
- 不做「转换为分支对象」(Convert to Branch)
- 不做合并(FE-024)
## 涉及文件
- [mactfs/src/main/java/com/mydev/mactfs/core/MacTfsCoreService.java](/Users/fenghp/Desktop/DEV/project/mydev/mactfs/src/main/java/com/mydev/mactfs/core/MacTfsCoreService.java)
- [mactfs/src/main/java/com/mydev/mactfs/server/MacTfsServer.java](/Users/fenghp/Desktop/DEV/project/mydev/mactfs/src/main/java/com/mydev/mactfs/server/MacTfsServer.java)
- [mactfsui/app/lib/api](/Users/fenghp/Desktop/DEV/project/mydev/mactfsui/app/lib/api)
- [mactfsui/app/lib/tfs/actions.ts](/Users/fenghp/Desktop/DEV/project/mydev/mactfsui/app/lib/tfs/actions.ts)
- [mactfsui/app/hooks/use-file-actions.ts](/Users/fenghp/Desktop/DEV/project/mydev/mactfsui/app/hooks/use-file-actions.ts)
- [mactfsui/app/components/app/workspace-dialogs.tsx](/Users/fenghp/Desktop/DEV/project/mydev/mactfsui/app/components/app/workspace-dialogs.tsx)
## 验收标准
- 右键「分支…」可对目录 / 文件发起分支,目标路径校验正确
- 分支产生 branch 挂起更改,签入后服务器出现目标路径内容
- 可基于指定 changeset 分支
- 目标父目录未映射时有明确提示
- 服务端构建通过、前端 typecheck 通过
## 测试方式
```bash
cd /Users/fenghp/Desktop/DEV/project/mydev/mactfs
../tfsIntegration/gradlew --no-daemon build installDist
cd /Users/fenghp/Desktop/DEV/project/mydev/mactfsui
pnpm typecheck
```
真实 TFS 的分支签入验证须用户确认后执行。
## 完成记录
### 实际修改文件
- `mactfs/src/main/java/com/mydev/mactfs/core/MacTfsCoreService.java`:新增 `branch`(`Workspace.pendBranch`,默认 latest 可指定 changeset,校验目标 ≠ 源)
- `mactfs/src/main/java/com/mydev/mactfs/server/MacTfsServer.java`:新增 `POST /api/files/branch`
- `mactfsui/app/lib/api/endpoints.ts`:新增 `branch`
- `mactfsui/app/lib/tfs/actions.ts`:`FileActionId` 新增 `branch`;目录菜单(对比 / 历史分组)与文件菜单(非 pendingAdd)新增「分支…」
- `mactfsui/app/components/explorer/branch-dialog.tsx`(新增):分支弹窗(目标路径默认 `源-branch` 可编辑、可选基于 changeset、展示目标本地落盘路径)
- `mactfsui/app/hooks/use-file-actions.ts`:弹窗状态新增 `branch`,新增 `handleBranchConfirmed`(执行后刷新挂起更改与目录列表)
- `mactfsui/app/components/app/workspace-dialogs.tsx` / `workspace-shell.tsx`:渲染并接线分支弹窗
### 实际实现内容
- 右键「分支…」打开弹窗:目标路径校验(`$/` 前缀、≠ 源、不在源内部、父目录必须已映射并给出明确提示)、changeset 数字校验(留空 = latest)
- 校验通过后展示目标的本地落盘路径;确认后产生 branch 挂起更改,顶部通知提示去挂起面板审查后签入
- 挂起的 branch 更改可 undo / checkin(复用既有流程)
### 已执行测试
- `pnpm typecheck`:通过
- `../tfsIntegration/gradlew --no-daemon build installDist`:通过
### 未执行测试及原因
- 真实 TFS 的 pendBranch 与签入后服务器分支验证:本机无环境,待 FEATURE 阶段执行
### 是否满足验收标准
- 分支入口、目标校验、指定 changeset、挂起审查 / 签入:满足(代码层面)
- 服务端构建与前端 typecheck 通过:满足
### 遗留问题
- 不做分支可视化与 Convert to Branch(已声明不在范围)
+115
View File
@@ -0,0 +1,115 @@
# FE-024 实现合并
## 状态
done
## 优先级
P1
## 所属阶段
frontend
## 依赖任务
- FE-009
- FE-023
## 需求来源
- [docs/mactfs-ui-enhancement-requirements-2.md](/Users/fenghp/Desktop/DEV/project/mydev/docs/mactfs-ui-enhancement-requirements-2.md) R10
## 目标
提供分支间合并能力:查看待合并变更集候选,执行合并产生挂起更改,
冲突进入既有冲突弹窗,审查后签入,对齐 VS 的 Merge 向导。
## 实现范围
- core 新增:
- `mergeCandidates(sourceServerPath, targetServerPath)`:`Workspace.getMergeCandidates`
- `merge(sourceServerPath, targetServerPath, changeset?)`:`Workspace.merge`,
默认合并全部候选,可指定单个 changeset
- server 新增 `GET /api/files/merge-candidates`、`POST /api/files/merge`
- 前端 API 层补充 `mergeCandidates`、`merge`
- 右键菜单新增「合并…」(树 / 列表来源,作为合并源):
- 向导弹窗:源路径只读;目标路径输入(必须已映射,校验给出原因)
- 加载并展示候选 changeset 列表(编号、提交人、时间、备注);空列表提示无可合并内容
- 支持「全部合并」或选择单个 changeset 合并
- 确认弹窗说明:只产生挂起更改、冲突需要逐个处理、签入前可撤销
- 合并冲突进入既有冲突弹窗流程(listConflicts / applyConflict)
- 完成后刷新挂起更改,引导用户审查并签入
## 不在范围
- 不做三方合并编辑器(内容冲突仍按「取本地 / 取服务器」处理)
- 不做 baseless merge(无分支关系的强制合并)
- 不做合并历史可视化
## 涉及文件
- [mactfs/src/main/java/com/mydev/mactfs/core/MacTfsCoreService.java](/Users/fenghp/Desktop/DEV/project/mydev/mactfs/src/main/java/com/mydev/mactfs/core/MacTfsCoreService.java)
- [mactfs/src/main/java/com/mydev/mactfs/server/MacTfsServer.java](/Users/fenghp/Desktop/DEV/project/mydev/mactfs/src/main/java/com/mydev/mactfs/server/MacTfsServer.java)
- [mactfsui/app/lib/api](/Users/fenghp/Desktop/DEV/project/mydev/mactfsui/app/lib/api)
- [mactfsui/app/lib/tfs/actions.ts](/Users/fenghp/Desktop/DEV/project/mydev/mactfsui/app/lib/tfs/actions.ts)
- [mactfsui/app/hooks/use-file-actions.ts](/Users/fenghp/Desktop/DEV/project/mydev/mactfsui/app/hooks/use-file-actions.ts)
- [mactfsui/app/components/app/workspace-dialogs.tsx](/Users/fenghp/Desktop/DEV/project/mydev/mactfsui/app/components/app/workspace-dialogs.tsx)
- [mactfsui/app/components/explorer/conflict-dialog.tsx](/Users/fenghp/Desktop/DEV/project/mydev/mactfsui/app/components/explorer/conflict-dialog.tsx)
## 验收标准
- 「合并…」向导可展示源 → 目标的候选 changeset 列表
- 可执行全部合并与单个 changeset 合并,结果为挂起更改
- 合并冲突进入冲突弹窗并可逐个处理
- 合并结果可在挂起面板审查、可 undo、可签入
- 服务端构建通过、前端 typecheck 通过
## 测试方式
```bash
cd /Users/fenghp/Desktop/DEV/project/mydev/mactfs
../tfsIntegration/gradlew --no-daemon build installDist
cd /Users/fenghp/Desktop/DEV/project/mydev/mactfsui
pnpm typecheck
```
真实 TFS 的合并签入验证须用户确认后执行。
## 完成记录
### 实际修改文件
- `mactfs/src/main/java/com/mydev/mactfs/core/MacTfsCoreService.java`:新增 `mergeCandidates`(`getMergeCandidates`,复用 `TfsHistoryEntry` 输出候选)与 `merge`(`Workspace.merge`;changeset 为空合并全部候选 `(null, latest)`,指定时仅合并该变更集 `(C, C)`;复用 `TfsGetLatestResult` 返回 operations / conflicts / failures)
- `mactfs/src/main/java/com/mydev/mactfs/server/MacTfsServer.java`:新增 `GET /api/files/merge-candidates`、`POST /api/files/merge`
- `mactfsui/app/lib/api/endpoints.ts`:新增 `mergeCandidates`、`merge`
- `mactfsui/app/lib/tfs/actions.ts`:`FileActionId` 新增 `merge`;目录与文件(非 pendingAdd)菜单新增「合并…」
- `mactfsui/app/components/explorer/merge-dialog.tsx`(新增):合并向导(源只读、目标路径校验须已映射、查询候选列表、点选单个或全部合并、挂起与冲突说明)
- `mactfsui/app/hooks/use-file-actions.ts`:弹窗状态新增 `merge`,新增 `handleMergeConfirmed`(刷新挂起更改与目录列表,conflicts>0 自动以目标路径进入冲突弹窗)
- `mactfsui/app/components/app/workspace-dialogs.tsx` / `workspace-shell.tsx`:渲染并接线合并向导
### 实际实现内容
- 右键「合并…」打开向导:目标路径必须已映射(校验给出原因);「查询候选」展示待合并 changeset(编号 / 类型 / 作者 / 时间 / 注释),空列表提示已同步
- 支持「全部合并」与「合并所选」(点选候选行选中 / 取消);执行后顶部通知展示统计并提示去挂起面板审查后签入
- 合并冲突自动进入既有冲突弹窗(listConflicts / applyConflict,按「取本地 / 取服务器」处理)
### 已执行测试
- `pnpm typecheck`:通过
- `../tfsIntegration/gradlew --no-daemon build installDist`:通过
### 未执行测试及原因
- 真实 TFS 的候选查询、合并挂起与冲突处理验证:本机无环境,待 FEATURE 阶段执行
### 是否满足验收标准
- 候选列表、全部 / 单个合并、冲突进冲突弹窗、挂起审查 / 撤销 / 签入:满足(代码层面)
- 服务端构建与前端 typecheck 通过:满足
### 遗留问题
- 不支持 baseless merge 与三方合并编辑器(已声明不在范围)
- 候选「合并所选」一次仅支持单个 changeset,连续区间合并可后续增强
@@ -0,0 +1,110 @@
# FE-025 实现访达打开与添加本地文件
## 状态
done
## 优先级
P0
## 所属阶段
frontend
## 依赖任务
- FE-006
- FE-011
## 需求来源
- [docs/mactfs-ui-enhancement-requirements-2.md](/Users/fenghp/Desktop/DEV/project/mydev/docs/mactfs-ui-enhancement-requirements-2.md) R11
## 目标
补齐两个日常操作缺口:右键对象「在访达中打开」(文件定位选中、目录直接进入),
以及目录右键 / 中间区域空白处右键「添加本地文件…」(把本地新增文件加入 TFS 版本控制)。
## 实现范围
- Electron main 新增 IPC:`reveal-path`(`shell.showItemInFolder` / `shell.openPath`)、
`select-files`(系统多选文件选择器,支持默认目录)
- preload / bridge / 类型契约同步暴露 `revealPath`、`selectFiles`
- 动作模型新增 `revealInFinder`、`addLocalFiles`:
- 文件菜单「在访达中显示」;目录菜单「在访达中打开」(未映射置灰)
- 目录菜单「添加本地文件…」(未映射置灰)
- 中间文件列表空白区域右键 = 当前目录的完整右键菜单(行内右键阻止冒泡避免双菜单)
- 添加流程(修订为扫描式):目录对比(递归)筛出 localOnly 项 → 弹窗勾选(默认全选)→
批量 `POST /api/files/add` → 刷新挂起更改与目录列表
- 非 Electron 环境:两个动作给出「仅桌面应用支持」提示
## 不在范围
- 不做拖拽添加文件
- 不做新建文件 / 文件夹
- 不改既有目录对比 localOnly「加入版本控制」入口
## 涉及文件
- [mactfsui/electron/main.cjs](/Users/fenghp/Desktop/DEV/project/mydev/mactfsui/electron/main.cjs)
- [mactfsui/electron/preload.cjs](/Users/fenghp/Desktop/DEV/project/mydev/mactfsui/electron/preload.cjs)
- [mactfsui/app/lib/electron](/Users/fenghp/Desktop/DEV/project/mydev/mactfsui/app/lib/electron)
- [mactfsui/app/lib/tfs/actions.ts](/Users/fenghp/Desktop/DEV/project/mydev/mactfsui/app/lib/tfs/actions.ts)
- [mactfsui/app/hooks/use-file-actions.ts](/Users/fenghp/Desktop/DEV/project/mydev/mactfsui/app/hooks/use-file-actions.ts)
- [mactfsui/app/components/explorer/folder-items-panel.tsx](/Users/fenghp/Desktop/DEV/project/mydev/mactfsui/app/components/explorer/folder-items-panel.tsx)
## 验收标准
- 已映射文件右键「在访达中显示」可在访达中定位选中该文件
- 已映射目录右键「在访达中打开」可直接进入该目录
- 目录右键与中间空白区域右键可「添加本地文件…」,自动扫描出本地新增项,勾选添加后产生 pendingAdd 并刷新
- 没有本地新增项时弹窗明确提示「本地内容与服务器一致」
- 未映射对象两个动作置灰并给出原因;前端 typecheck 通过
## 测试方式
```bash
cd /Users/fenghp/Desktop/DEV/project/mydev/mactfsui
pnpm typecheck
```
## 完成记录
### 实际修改文件
- `mactfsui/electron/main.cjs`:新增 IPC `mactfs:reveal-path`(目录 `shell.openPath` 直接进入,文件 `shell.showItemInFolder` 定位选中,路径不存在返回 false)
- `mactfsui/electron/preload.cjs`:暴露 `revealPath`
- `mactfsui/app/lib/electron/types.ts` / `bridge.ts` / `index.ts`:桥接契约与封装(非 Electron 环境优雅降级)
- `mactfsui/app/lib/tfs/actions.ts`:`FileActionId` 新增 `revealInFinder`、`addLocalFiles`;文件菜单「在访达中显示」、目录菜单「在访达中打开」+「添加本地文件…」(未映射置灰)
- `mactfsui/app/components/explorer/add-files-dialog.tsx`(新增):扫描式添加弹窗(目录对比递归筛 localOnly、勾选列表默认全选、支持全选 / 清空、批量添加)
- `mactfsui/app/hooks/use-file-actions.ts`:`revealInFinder` 执行逻辑(失败提示先获取最新);`addLocalFiles` 打开扫描弹窗;新增 `handleAddFilesConfirmed`(批量 pend add 后刷新挂起更改与目录列表)
- `mactfsui/app/components/app/workspace-dialogs.tsx` / `workspace-shell.tsx`:渲染并接线添加弹窗
- `mactfsui/app/components/explorer/folder-items-panel.tsx`:中间区域空白处右键 = 当前目录完整菜单(行内右键 stopPropagation 防止双菜单)
### 实际实现内容
- 「在访达中打开 / 显示」:目录直接进入访达对应目录;文件在访达中定位并选中;本地路径不存在(未下载)时提示先获取最新;非 Electron 提示仅桌面应用支持
- 「添加本地文件…」(按用户反馈修订为扫描式):自动对该目录做递归目录对比,筛出 localOnly(本地新增)的文件 / 目录,弹窗勾选(默认全选)后批量加入版本控制;无新增项时明确提示本地与服务器一致
- 添加结果为 pendingAdd 挂起更改,挂起面板可见、可撤销、签入后进入服务器
- 中间列表空白处右键提供当前目录的完整右键菜单,与目录树右键一致
### 已执行测试
- `pnpm typecheck`:通过
- 服务端无改动,无需重新构建
### 未执行测试及原因
- 访达交互为 Electron 原生能力,需桌面应用人工验证(`pnpm electron:dev`)
- 扫描式添加依赖真实 TFS 目录对比结果,待 FEATURE 阶段验证
### 是否满足验收标准
- 访达打开 / 显示、扫描式添加本地文件(勾选 / 全选 / 无新增提示)、空白区域右键、未映射置灰:满足(代码层面)
- 前端 typecheck 通过:满足
### 遗留问题
- 不支持拖拽添加与新建文件 / 文件夹(已声明不在范围)
- 大目录递归对比首次扫描可能较慢(沿用目录对比既有性能特征)
@@ -0,0 +1,74 @@
# FE-026 建立macOS设计基建
## 状态
done
## 优先级
P0
## 所属阶段
frontend
## 依赖任务
无
## 需求来源
- [docs/mactfs-ui-restyle-requirements.md](/Users/fenghp/Desktop/DEV/project/mydev/docs/mactfs-ui-restyle-requirements.md) U1
## 目标
把全局设计令牌升级为 macOS 现代风格,作为后续所有 UI 改版任务的统一基础。
## 实现范围
- 字体切换为系统字体栈(`-apple-system, BlinkMacSystemFont, "PingFang SC"` 等),移除 Roboto Slab 作为全局字体;代码/Diff 场景保留等宽字体
- 重定义颜色令牌:macOS 蓝主色、中性灰分级、分隔线、半透明材质变量,light/dark 两套完整定义
- 统一圆角档位(约 6/10/14px)、分层阴影(卡片/浮层/弹窗)、间距档位
- 建立动效令牌:统一时长(150/220/320ms)与缓动曲线变量
- 预留 vibrancy 透明背景变量(供 FE-027 使用)
## 不在范围
- 不改任何组件结构与业务逻辑
- 不实现主题切换入口(FE-033 做)
- 不改 Electron 窗口配置(FE-027 做)
## 涉及文件
- `mactfsui/app/app.css`
- `mactfsui/package.json`(如需移除字体依赖或引入 motion)
## 验收标准
- 全局字体为系统字体栈,界面文字观感与 macOS 原生应用一致
- light/dark 两套 token 完整、可用
- 圆角、阴影、动效时长全部来自统一变量,无散落魔法值
- `pnpm typecheck` 通过,现有页面无功能回归
## 测试方式
```bash
cd mactfsui && pnpm typecheck && pnpm electron:dev
```
## 完成记录
- 实际修改文件:
- `mactfsui/app/app.css`
- `mactfsui/package.json`、`mactfsui/pnpm-lock.yaml`(移除 `@fontsource-variable/roboto-slab`)
- 实际实现内容:
- 全局字体切换为系统字体栈(SF Pro / PingFang SC 优先),`html` 改 `font-sans`;新增 `--font-mono` 等宽令牌
- 主色改为 macOS 系统蓝(light ≈ #007AFF、dark ≈ #0A84FF),`--accent` 与主色解耦改中性悬停色
- 中性灰分级 light/dark 两套完整定义(dark 深灰非纯黑)
- 半透明材质变量:`--sidebar` / `--sidebar-accent` 带透明度,配套 `html.vibrancy` 时页面底透明(供 FE-027 毛玻璃透出),vibrancy 未开启时半透明叠在实色上近似实色、可安全回退
- 圆角基准 0.875rem → 0.625rem(6/8/10/14px 档位);阴影分层 card/overlay/dialog;动效令牌 150/220/320ms + ease-out-quart / spring
- 测试结果:
- `pnpm typecheck` 通过、`pnpm build` 通过
- 视觉走查随 FE-027 ~ FE-034 进行
- 遗留问题:
- 无
@@ -0,0 +1,77 @@
# FE-027 Electron窗口macOS化
## 状态
done
## 优先级
P0
## 所属阶段
frontend
## 依赖任务
- FE-026
## 需求来源
- [docs/mactfs-ui-restyle-requirements.md](/Users/fenghp/Desktop/DEV/project/mydev/docs/mactfs-ui-restyle-requirements.md) U2
## 目标
让应用窗口具备 macOS 原生质感:隐藏式标题栏、红绿灯融入顶栏、毛玻璃材质。
## 实现范围
- BrowserWindow 配置 `titleBarStyle: "hiddenInset"`,校准 trafficLightPosition
- 顶栏对应区域设置 `-webkit-app-region: drag`,交互控件设置 no-drag
- 开启窗口 vibrancy(`sidebar` 或 `under-window` 材质),配合 FE-026 的透明背景变量让侧栏呈毛玻璃
- 核对窗口默认尺寸与最小尺寸
- 非 macOS 或 vibrancy 不可用时回退纯色背景,不影响功能
## 不在范围
- 顶栏内容与布局重排(FE-029 做)
- 打包签名相关配置(RELEASE 阶段做)
## 涉及文件
- `mactfsui/electron/main.cjs`
- `mactfsui/app/components/app/top-bar.tsx`(仅拖拽区域标记)
- `mactfsui/app/app.css`(透明背景接线)
## 验收标准
- 窗口无系统标题栏,红绿灯悬浮于顶栏内且不遮挡控件
- 顶栏空白区可拖动窗口,按钮等控件可正常点击
- 侧栏可见毛玻璃效果;关闭 vibrancy 时回退正常
- 全部既有功能无回归
## 测试方式
```bash
cd mactfsui && pnpm electron:dev
```
## 完成记录
- 实际修改文件:
- `mactfsui/electron/main.cjs`
- `mactfsui/app/components/app/top-bar.tsx`(拖拽区域 + 红绿灯留白)
- `mactfsui/app/app.css`(app-drag / app-no-drag 工具类)
- `mactfsui/app/root.tsx`(首屏前挂载 html.vibrancy 标记)
- 新增 `mactfsui/app/lib/platform.ts`
- 实际实现内容:
- macOS 下 `titleBarStyle: "hiddenInset"` + `trafficLightPosition {16,16}`,非 macOS 回退系统标题栏
- 开启窗口 vibrancy(`sidebar` 材质,followWindow);macOS 背景设全透明配合 `html.vibrancy body { background: transparent }` 让毛玻璃可透出;非 macOS 用实色背景
- `show:false + ready-to-show` 显示并默认最大化铺满屏幕(带上现代风分支已确认的体验决策)
- `minWidth 980 / minHeight 640`
- 顶栏 `app-drag` 拖拽 + 控件 `app-no-drag`,macOS Electron 下 `pl-20` 为红绿灯留白
- 测试结果:
- `pnpm typecheck` 通过、`pnpm build` 通过,产物确认 app-drag / vibrancy 已编译
- 毛玻璃透出效果在 FE-029 侧栏完成后整体截图验证
- 遗留问题:
- 登录页(无顶栏)拖拽区在 FE-028 补充
@@ -0,0 +1,77 @@
# FE-028 重设计登录页
## 状态
done
## 优先级
P0
## 所属阶段
frontend
## 依赖任务
- FE-026
## 需求来源
- [docs/mactfs-ui-restyle-requirements.md](/Users/fenghp/Desktop/DEV/project/mydev/docs/mactfs-ui-restyle-requirements.md) U3
## 目标
把登录页从单张表单卡片升级为有品牌感、有动效、元素丰富的现代登录页。
## 实现范围
- 左右分栏布局:左侧品牌区(logo、产品名、标语、版本号、氛围背景动效),右侧连接表单卡片
- 表单 → Collection 选择两阶段切换增加滑动 + 淡入淡出过渡
- 新增:密码可见性切换按钮、最近连接记录(localStorage 多条、一键填充)、本地服务健康状态指示灯
- 连接中按钮内 spinner、阶段文案过渡;连接失败表单抖动 + 错误提示条
- Collection 列表改卡片式:悬停浮起、选中高亮过渡
- 保持现有 `api.connect / listCollections / ensureWorkspace` 调用链路不变
## 不在范围
- 不改连接协议与认证方式
- 不改 `app/lib/api` 接口契约(最近连接仅存前端本地)
## 涉及文件
- `mactfsui/app/components/app/connect-view.tsx`
- 新增 `mactfsui/app/lib/recent-servers.ts`(或等价的本地存储工具)
## 验收标准
- 登录页具备品牌区与氛围背景,观感现代精致
- 两阶段切换有流畅过渡动效
- 最近连接可保存、可一键填充;密码可见性切换可用
- 连接成功进入工作台的链路与改版前完全一致
## 测试方式
```bash
cd mactfsui && pnpm typecheck && pnpm electron:dev
# 手工验证:连接真实 TFS → 选择 Collection → 进入工作台
```
## 完成记录
- 实际修改文件:
- `mactfsui/app/components/app/connect-view.tsx`(整体重写)
- 新增 `mactfsui/app/lib/recent-servers.ts`
- `mactfsui/app/app.css`(shake 抖动动画令牌)
- 实际实现内容:
- 左右分栏:左侧 `bg-sidebar` 半透明品牌区(vibrancy 下呈毛玻璃),居中大 logo(drop-shadow 跟随透明轮廓)+「MacTFS」+ 一句话描述 + 底部服务健康指示灯(吸收现代风分支用户反馈:品牌区只放大 logo + 一句话)
- 表单 → Collection 两阶段滑动淡入过渡;密码可见性切换;最近连接(localStorage 5 条去重置顶、一键填充、不存密码)
- 连接中按钮 spinner + 阶段文案;失败错误条 + 表单抖动
- Collection 卡片式选择:选中 = 主色细边框 + 浅主色底 + 蓝色对勾(zoom 入场),未选中 hover 仅底色微变(直接采用对比分支已确认的选中样式)
- 登录页顶部 `app-drag` 拖拽条(补 FE-027 遗留)
- `api.connect / listCollections / ensureWorkspace` 链路不变
- 测试结果:
- `pnpm typecheck` 通过、`pnpm build` 通过,shake 动画已编译
- 真实连接流程随 FE-034 回归验证
- 遗留问题:
- 无

Some files were not shown because too many files have changed in this diff Show More