Skip to content

feat(webui): the title bar says which checkout you are looking at - #130

Merged
fengzhi09 merged 1 commit into
mainfrom
feat/version-badge
Sep 30, 2026
Merged

fengzhi09 merged 1 commit into
mainfrom
feat/version-badge

Conversation

@fengzhi09

Copy link
Copy Markdown
Collaborator

背景(用户反馈 F-4)

我希望 webui 标题栏合适的位置上显示当前的分支名称、commit 短编号、和提交时间,方便我确认版本。

后端

/api/git/status 的返回体扩两个字段,无新端点:

字段 来源 为什么这么取
headSha git log -1 --format=%h 用 git 自己的缩写长度,不写死 7 —— 大仓库会自动加长,而你要粘进 git show,截掉就不对了
headCommittedAt %cI 提交者时间,不是作者时间

headCommittedAt 的选择理由值得单说:rebase / amend / cherry-pick 会把提交者时间推到当下,而作者时间停在最初那次写入。用作者时间会把刚 rebase 的分支显示成几个月前——而这个仓库的分支几乎全是 squash/rebase 出来的。

走既有 execFile 边界与既有 assertWorkspacePath 门(不引入第二个越权判断点),与 git status 并发发起,墙钟仍是一次往返。

边界:

  • 非 git 目录 → 两字段不出现
  • unborn HEAD → ok:true + 两字段 null
  • 顺带修掉既有 bug:## No commits yet on main 原会被正则读成分支名 "No"

标题栏

位置:标题行的最右端(ml-auto),在运行状态指示之后。

标题回答「我在看什么」,标识回答「我看的是哪个检出」——一左一右成对。

形态 分支 + 短编号 + 相对时间;点击短编号复制(真按钮 + aria-label + 1.2 秒「已复制」反馈)。字号、色板、hover 全部沿用同区域既有控件,没有自造视觉。

三种情况元素完全不在 DOM 里

非 git 目录 · unborn HEAD · 请求失败/未返回。

空壳胶囊是「看起来能用、实际什么都不说」的控件——宁可没有。

不轮询

一次调用是一次真实 git status 索引刷新。版本身份在提交或切分支时变,而非按时间表变。相对时间那半零成本——挂在标题栏本来就有的 useTicker(1000) 上。Git 面板已定「工作区变化 + 显式刷新」的先例。

端到端截图

.tickets/webui-parity/ 下:

文件 内容
shot-07-final-wide.png 1440px 三段齐活
shot-08-final-copied.png 点击后「已复制」
shot-09-final-900px.png 900px 窄屏:时间隐藏,分支 + 短编号仍在
shot-03-badge-absent-nonrepo.png 非 git 目录:标题栏在、标识完全不在

隔离实例显式设了 MINIMAX_DATA_DIR、独立端口 18093、自建 dist。

变异验证 5/5 全红

其中变异 2 第一次是绿的——原断言用共用夹具(只有一次提交、作者时间恰好等于提交者时间),%aI 与 %cI 无法区分,看着在验「提交者时间」其实只验了 ISO 格式。补了 GIT_AUTHOR_DATE=2020-01-02 / GIT_COMMITTER_DATE=2026-10-01 的分离夹具(带前置断言确保两日期确实不同)后重跑即红。

门禁

门禁 退出码 结果
pnpm webui:typecheck / typecheck 0 —
pnpm test:webapp 0 1863/1863
pnpm test:webui ×3 0 / 0 / 0 2192 pass / 0 fail / 2 skipped
pnpm check:source 0 4903 files
check-docs-alignment.mjs 0 —

顺带修掉的两个既有布局缺陷(实跑量出来的)

  1. pr-20 预留位按三个按钮算,但实际渲染四个 —— 标识被压住 68px
  2. 会话标题按钮缺 min-w-0 —— 420px 下标识被榨成零宽盒子

这两处本就必须改才不压控件,但它们是既有行的属性,review 时值得单独看一眼。

意外验证:时钟偏差护栏

首次种子提交时间在 14 小时之后,标识只渲染分支 + 短编号、时间段整个不出现——不打印「-14 小时前」。

文档

docs/webui.md + docs/webui.zh-CN.md 同批改(用户可见行为,双语同权);packages/webui/docs/API.md + API.zh-CN.md 的 GET /api/git/status 小节同步两个新字段。

🤖 Generated with DeepSeek Harness

Branch, short sha, and when it landed — a left pair with the title:
the title answers "what am I reading", this answers "which build".

headSha uses git's own abbreviation rather than a fixed seven, so a
large repository lengthens it instead of truncating away the digits
you would paste into git show. headCommittedAt is the committer time,
not the author time: rebase, amend and cherry-pick push the committer
time to now while the author time stays at the first write, so an
author timestamp would show a just-rebased branch as months old.

No polling. One call is one real index refresh, and a checkout's
identity changes on commit or branch switch rather than on a timer;
the relative-time half rides the ticker the title bar already had.
Nothing renders for a non-git directory, an unborn HEAD, or a failed
request — an empty pill is a control that looks useful and says
nothing.
@fengzhi09
fengzhi09 merged commit b66257c into main Sep 30, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant