Repository navigation
feat(worktree): 会话关闭卡加「清理 worktree」按钮,只删 botmux 自动建的干净 worktree - #2319
Merged
Merged
Conversation
botmux 不自动回收自己建的 worktree(关闭的会话可能还要回看),改为在会话关闭卡上 给一个由人点击的「清理 worktree」按钮(#698): - 新增 botmux-worktrees.json 创建记录(目录 + main + 分支 + dev/ino),只在真正 `git worktree add` 成功的路径写入:auto-worktree / `/tw`、`/repo wt`、选仓卡的 worktree 按钮(整批成功后)、XPI 独立任务;复用已有 worktree(reused)不写。 - 关闭卡只在会话工作目录位于记录过、且目录身份未变的 worktree 内时显示按钮; 按钮只带 session_id,不带路径;带按钮的卡才加 update_multi,旧卡逐字节不变。 - 点击:过 canOperate(关闭会话按所在群取上下文)→ 先回「正在检查」卡 → ACK 后 在 worktree 锁内复核:会话仍是 closed、无 active 会话在用、无进程 cwd 在目录内、 无未提交/未跟踪改动、无未推送提交,任何一项查不了也按拒绝处理并逐条写明原因; 全部通过才 `git worktree remove`(不加 --force,不删分支),结果原地更新到卡上, 拒绝时保留按钮可重试。 - 进程占用探测只读:Linux 读 /proc/<pid>/cwd,其它平台用 lsof,拿不到就当无法确认。 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
deepcoldy
requested review from
47seek,
LucasIcarus,
xiaoxueSunn and
xiongz-c
as code owners
October 25, 2026 05:47
Owner
Author
|
已 squash 合入(0e3f5a4a7b),感谢。评审中确认的 follow-up,均不阻断,供后续 PR 处理:
以上为自动评审的初步整理,最终以维护者审阅为准。 |
deepcoldy
pushed a commit
that referenced
this pull request
Oct 25, 2026
- 首审 P2:活进程探测之后、真正删除之前再读一次 mtime,探测后被恢复的会话 scratch / 重新起 host 的网关目录不再被删 - #2319 已合入同类 cwd 探测,按约定由后合的本 PR 收敛:findLiveProcessReferences 移入 utils/dir-process-probe.ts,两者共用 procfs pid 枚举 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🚀 Released in v3.52.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #698
改了什么
按维护者定的做法:不做自动回收。只在会话关闭卡上加一个「🧹 清理 worktree」按钮,由人点了才删。
git worktree add出来的 worktree 里(子目录也算),并且目录还是当初建的那一个(dev/ino 一致)。其余情况关闭卡和原来逐字节相同。<dataDir>/botmux-worktrees.json(services/botmux-worktree-store.ts)。每个新建 worktree 的地方,在git worktree add成功后各加一行记录,记下目录、main checkout、分支,以及目录的 dev/ino。写失败只打 warn,不影响会话启动。会写记录的入口:/tw:只记真正新建的。/repo wt。reuseExisting):新增的WorktreeCreation.reused标记会让记录跳过。/repo wt和选仓卡在会话运行中切换 worktree 时,会关掉旧会话、新建会话行,而且有三条提交路径。挂在会话上就要穿透全部三条,漏一条就会出错。在git worktree add成功的那一刻记录,四个创建点各加一行就够了;这份记录也更直接地证明了「这个目录是 botmux 建的」。点击后的核对(
core/session-worktree-cleanup.ts)。卡片回调只带session_id,路径从会话库和创建记录重新读取,从不信任卡片里的路径:canOperate)能点。已关闭的会话按它所在的群判断权限;处理函数里会再查一遍。/proc/<pid>/cwd,macOS 跑一次lsof -d cwd。只做探测,不给任何进程发信号;无法确认也算拒绝;--force的git worktree remove,不删分支。删完同时删掉这条创建记录。截图(合成数据,本地近似渲染)
改前(没有 botmux worktree 的会话,本 PR 之后也是这样):
botmux 建的 worktree,显示按钮:
点击后:正在检查 / 因为有改动被拒绝 / 已删除:
影响面
card-builder.buildSessionClosedCard/closed-session-card:新增可选参数,不传时输出不变。card-handler:新增一个动作分支;已关闭会话的权限上下文回退原来只对resume生效,现在这个动作也走它。card-action-routes:敏感动作清单加一项。git-worktree:WorktreeCreation多一个可选的reused字段;新增removeCleanWorktree;原来的removeRepoWorktree没动。/twworktree 里,其它已关闭会话的关闭卡上也会出按钮;只要还有 active 会话在用就会拒绝。对老用户的影响与依据
card-builder-wire-golden和closed-session-card不改就全过,测试里也断言了「非 botmux 目录 → config 仍只有wide_screen_mode」。botmux-worktrees.json,只增不改已有格式。update_multi: true,这样结果能原地更新。已知限制
/proc探测工具(utils/process-references.ts),和本 PR 的utils/dir-process-probe.ts有重叠。两个 PR 各自独立可合,后合的那个负责收敛成一个。验证
bun run build:通过;tsc --noEmit:通过。session-worktree-cleanup、session-worktree-cleanup-card、card-handler-worktree-cleanup、dir-process-probe、botmux-worktree-store。核心流程用真实临时 git 仓库加git worktree add构造场景。占用目录的进程是测试自己 spawn 的sleep,用拿到的句柄收尾。handleSessionWorktreeCleanupAction和cleanupSessionWorktree。飞书里真机点按钮需要部署,按任务要求没有部署。/proccwd 不匹配--forcebranch -Dupdate_multi🤖 Generated with Claude Code