Skip to content

feat(web): zoom-to-selection (brush) for the session context-trajectory chart - #2492

Merged
ranxianglei merged 5 commits into
masterfrom
wt-2489-ework-daemon
Oct 15, 2026
Merged

ranxianglei merged 5 commits into
masterfrom
wt-2489-ework-daemon

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #2489

Long sessions (e.g. 962 requests/day from #917 @xfyang728's screenshot) pack every sample into the fixed 960px canvas: hover hit-columns drop below 1px past ~944 samples and fold marks already needed pixel-bucket merging to stay legible. This adds the requested Zoom-to-Selection so any range can be inspected.

What

  • Brush: horizontal drag on the chart selects a sample range [i0..i1] → the SAME trajectorySvg renderer re-runs over lines[i0..i1] only; folds/seam events are time-filtered into the visible window. X-axis becomes equidistant again, Y-axis auto-fits the visible segment (window ceiling line stays visible when relevant). Pure client-side — no server round-trip, no new endpoint.
  • Status + reset: while zoomed, a status row shows 当前视图 #a–#b(start → end) plus a reset button; double-clicking the chart or pressing Esc resets to the full view. Nested zooms compose (a brush inside a zoomed view maps back to absolute indices).
  • Min selection width: drags covering fewer than 5 samples are treated as clicks and ignored, as are full-width drags.
  • Wheel-zoom / pan mode are explicitly out of scope for this issue (issue non-goal 4).

Implementation notes

  • Chart geometry constants hoisted (TRAJ_W/H/PL/PR/PT/PB) so the gesture code shares the renderer's math; trajectorySvg output is byte-identical for unchanged inputs.
  • The #traj-chart wrap now starts empty and is filled by a single render path (bindTrajectoryBrush → trajRender), so full and zoomed states go through the same code.
  • Seam extraction hoisted to detailSeam/detailSeamActive helpers (logic verbatim, shared by the card HTML and the brush state).
  • One global Escape keydown listener (registered once at page init), mousedown/dblclick bound per detail render like the existing bind* handlers.

Tests

  • tests/web-trajectory-brush.test.ts: hermetic mini-DOM driving the real client IIFE via vm.
    • Golden: unzoomed SVG byte-stable vs tests/golden/web-trajectory/small-full.svg (covers window ceiling, baseline, burst-fold merge, cause bands, seam marks); regen script scripts/update-web-trajectory-golden.ts.
    • E2E on a 1200-sample fixture: default view identity (embedded render == direct renderer call), hover columns widen 1px→7.4px after brushing ~120 samples, x-ticks re-equispaced, maxY recomputed (480K→129K), fold/seam marks filtered by time, nested zoom maps back to absolute indices, all three reset paths restore the exact full-view SVG, narrow/full-width drags ignored, brush overlay appears during drag and is removed on release.
  • i18n liveness gate passes (3 new keys, zh+en, placeholders matched).

Config surface

None added — pure Web UI rendering capability, per the issue's non-goals (no server endpoint, no ledger model change, no config fields/env vars).

Behavior-change disclosure

  • Default (unzoomed) chart rendering is unchanged for identical inputs — proven by the golden test and the default-view identity assertion. Internally the SVG string now lands in #traj-chart via one extra synchronous write right after host.innerHTML instead of being inlined in the initial HTML string; final DOM is identical.
  • .chart-wrap gains position: relative (only used by this chart, grep-verified) to anchor the brush overlay.
  • New visual affordances: crosshair cursor over the chart and a one-line zoom hint under the legend (i18n'd).

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: wt-2489-ework-daemon (64dcac6)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.3619-pr.2492.e5ff940

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr2492.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 PR Review — zoom-to-selection (brush) #2489

Reviewed the full diff (8 files, +602/−15) against issue #2489's acceptance criteria, ran the web-UI test lanes locally, and pushed two review findings to the branch. Current head: 7fdcfdd67.

① Direction check (原 issue): ✅ The mechanism is right — the ledger data is already client-side in the detail payload, so zoom = re-running the same trajectorySvg renderer over a filtered slice. No server round-trip, no new endpoint, no config surface, which is exactly what #2489's non-goals demand. Nested-zoom composition (brush-in-zoom → absolute indices), min-5-sample guard, full-width-drag ignore, and the three reset paths (button / dblclick / Esc) all match the acceptance list.

② Regression audit (既有行为清点) — touched paths and their existing behaviors:

③ Defect found & fixed (the important one): trajVisible() time-filtered fold/seam marks even in the full view, while the pre-#2489 renderer clamped out-of-sample-range marks to the nearest edge (idx < 0 → lines.length - 1). So any session whose last event is a trailing compress (fold timestamp after the last usage sample) or carries an early seam would silently lose marks in the default view — making the "identical inputs → identical SVG" acceptance criterion hold only when every event timestamp happens to fall inside the sample range. Fix (commit 7fdcfdd67): full view passes the unfiltered lists straight through; time-filtering applies only to zoomed windows (where a foreign mark would land on the wrong sample). New hermetic test drives a late-fold + early-seam fixture through the real client IIFE and asserts embedded-render == direct-renderer-call byte equality plus both marks rendering.

④ CI state: the earlier red unused-exports job (10 INTERNAL_ONLY exports in the two new test files) was already fixed by the author session in 03f02d7c3 — I verified byte-equivalence with my own fix attempt and did not duplicate it. Full local pass on the final tree: typecheck clean, web-trajectory-brush 3/3 (incl. golden + my new parity test), all 7 other web-UI test files 43/43, unused-exports gate clean. Remote CI on 7fdcfdd67 is running — I'll follow up if anything is red.

⑤ Test quality: assertions have teeth — exact hover-column counts (1200→121), exact column width (7.4), exact maxY recompute (480K→129K), tick re-equispacing, nested-zoom absolute mapping ([410,430]), all three reset paths restoring the exact full-view SVG, narrow/full-width drags ignored, overlay lifecycle during drag. Golden follows #1304 discipline (regen script + justification requirement). The window.bili_trajSvg/bili_trajZoom test seams match the file's existing window.bili_* pattern.


结构化八问

  1. 是什么问题:feat(web): add zoom-to-selection (brush) to the session context-trajectory chart #2489 要求长会话轨迹图支持框选放大;本 PR 是纯客户端实现(同一渲染器重跑过滤切片)。
  2. 什么原因导致的(缺陷侧):放大功能把「按时间窗过滤 fold/seam 标记」错误地应用到了全量视图——旧版渲染器对越界标记是钳位到边缘渲染,新代码直接丢弃。
  3. 影响范围与严重程度:仅影响含越界时间戳事件的会话(典型:最后一次请求以 compress 结尾、fold 时间戳晚于最后一条采样)的默认视图,少画 1~N 条虚线/实线标记;数据全在范围内时输出逐字节一致。属边界条件渲染缺失,非功能性损坏。已在 7fdcfdd67 修复并加回归测试钉住。
  4. 怎么修复的:全量视图直通未过滤列表给渲染器(恢复 feat(web): add zoom-to-selection (brush) to the session context-trajectory chart #2489 之前的钳位语义),时间过滤只作用于缩放窗口;hermetic mini-DOM 驱动真实 IIFE 断言「嵌入渲染 == 直接渲染调用」字节相等。
  5. 是否有回归问题:修复方向是恢复既有行为而非改变它。逐项:默认渲染(修复后无条件字节一致 ✅)、seam 卡片提取(逐行比对 verbatim ✅)、详情关闭状态重置(纯新增 ✅)、.chart-wrap CSS(选择器独占、纯增量 ✅)、i18n 三键 zh/en 占位符匹配 ✅。与 master 当前改动(locale pin/conflict banner/fmtW B 档/narrow panels)无语义交集,已逐一 diff 确认;fmtW 只动 B 档,图表刻度在 K/M 档不受影响。
  6. 是否破坏缓存:不涉及——纯 Web UI 渲染层,无缓存/重试/游标/去重路径触碰;服务端零改动。
  7. 是否改了设计方向:不涉及。仍为单渲染器 + 客户端切片,未引入新架构面;wheel-zoom/pan 按 non-goal 明确排除。
  8. 是否引入了新的配置:无——无 env/config/CLI flag(i18n 三键属 UI 文案,非配置面)。

行为变更披露(old→new):相对 PR 原 head(03f02d7c3),默认视图对越界 fold/seam 标记从「静默丢弃」恢复为「钳位到边缘渲染」(即 #2489 之前 bilio 的既有行为)——这是把验收标准从条件成立变为无条件成立,不是漂移;范围内数据两种实现的输出完全相同(golden + identity 断言双重证明)。

分支状态备注:分支基点仍在 f2b84b6c2(落后 master 若干提交)。我在本地完整 rebase 到当前 master 验证过:零冲突、全套 web 测试 + typecheck 绿;最终为避免对作者会话正在活动的分支做 force-push,改为在其最新 tip 上叠加我的单个修复 commit(fast-forward)。合并前建议作者或 owner 顺手 rebase 一次 master(GitHub 侧已确认 mergeable=true)。

结论:可合 —— 待 7fdcfdd67 的 CI 全绿即可人工合并(merge 保留 human-only)。CI 结果出来我会在本线程跟进。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Follow-up to my review above — CI on 7fdcfdd67 came back 22/24 green; both test (windows-latest) jobs (node 22 + node 24) failed. Root-caused, reproduced, and now fixed. Full detail below; verdict updated at the end.

The Windows failure: golden file EOL, not code

  • Failure: exactly ONE test per Windows job — not ok 4807 - #2489: golden — unzoomed trajectory SVG is byte-stable (5152 tests total, fail 1). The diff is only \n vs \r\n inside the <title> hover texts. Ubuntu matrix passed because its git defaults to autocrlf=false.
  • Mechanism: the new golden tests/golden/web-trajectory/small-full.svg legitimately contains real newlines (title text spans ~29 lines; blob is stored LF, verified CR count in blob = 0). Git-for-Windows' default core.autocrlf=true rewrites them to CRLF at checkout, so readFileSync sees CRLF while the renderer emits LF → byte-compare fails. This repo already hit this exact class for the wire-contract goldens (test: wire-contract anti-regression system — parity fakes, goldens, unified ledger #1305) — .gitattributes pins tests/golden/wire-contract/*.json text eol=lf, but the new web-trajectory/ golden was added without an entry.
  • Not a code defect: my regression test (#2489: full view passes out-of-sample-range fold/seam marks through unfiltered) passed on both Windows jobs, and all 5130 other tests passed there. The brush implementation itself is platform-clean.

Verification done locally (targeted, per testing discipline)

  1. Repro: CRLF-converted the golden in the working tree → same single test fails (pass 2 / fail 1); restored LF → pass 3 / fail 0.
  2. Fix proof: simulated the Windows checkout (core.autocrlf=true + forced re-checkout): with the attribute, the golden checks out with 0 CRs while a control file (README.md) under the same config got 553 CRs — proving the conversion path was live and the attribute is what protects the golden.

The fix

One line in .gitattributes, the established #1305 mechanism:

tests/golden/web-trajectory/*.svg text eol=lf

Note: while I was preparing this, the author session independently pushed daf37c622 fix(golden): pin web-trajectory SVG golden to LF checkout on Windows (#2489) with byte-identical content (I diffed my prepared commit against it — zero difference) and discarded my duplicate rather than stacking a second identical commit on the branch.

CI on daf37c622

24/24 check runs green, including both previously-failing windows-latest test jobs.


中文结论(更新版)

  1. 是什么问题:PR 新增的字节级 golden(SVG 含真实换行)在 Windows CI 检出时被 autocrlf 转成 CRLF,与渲染器 LF 输出字节比对失败——纯测试基建问题,非功能缺陷。
  2. 什么原因导致的:.gitattributes 的 eol=lf 规则(test: wire-contract anti-regression system — parity fakes, goldens, unified ledger #1305 为 wire-contract goldens 立的)未覆盖新目录 tests/golden/web-trajectory/;Windows runner 默认 core.autocrlf=true 在检出时转换换行。
  3. 影响范围与严重程度:仅两个 windows-latest 测试 job(ubuntu 不受影响);功能本身零影响(Win 上其余 5130 个测试全绿)。
  4. 怎么修复的:.gitattributes 增一行 tests/golden/web-trajectory/*.svg text eol=lf(复用 test: wire-contract anti-regression system — parity fakes, goldens, unified ledger #1305 既有机制,在 VCS 层强制 LF 检出,而非在测试里做 EOL 归一化掩盖问题)。作者会话已独立提交同一修复 daf37c622,我验证内容逐字节相同后丢弃了自己的重复提交。
  5. 是否有回归问题:无。本地定向复现(CRLF→必挂、LF→全过)+ autocrlf 模拟(带属性时 golden 0 CR、对照组 README 553 CR)双重验证;daf37c622 上 24/24 全绿。
  6. 是否破坏缓存:不涉及。
  7. 是否改了设计方向:不涉及。行为变更披露维持首条回复的结论(全视图越界 fold/seam 标记从「静默丢弃」恢复为「钳位到边缘渲染」,即 feat(web): add zoom-to-selection (brush) to the session context-trajectory chart #2489 之前的语义;样本范围内数据两种实现字节一致)。
  8. 是否引入了新的配置:不涉及。

判定:可合。 CI 全绿(daf37c622,24/24)。唯一遗留:分支 base(f2b84b6c2)落后 master——我已本地完整 rebase 验证过零冲突且全绿,合并前 rebase 或走 merge queue 均可,由 owner 定。

awork added 5 commits October 14, 2026 18:17
…red (#2489 byte parity)

The zoom feature time-filtered fold/seam marks even in the FULL view, silently
dropping any mark whose timestamp falls outside the sample range — while the
pre-#2489 renderer clamped such marks to the nearest edge. That made the
'identical inputs -> identical SVG' acceptance criterion hold only when all
event timestamps happen to be in-range. Full view now hands the unfiltered
lists straight to the renderer (zoomed windows keep their time filter), and a
regression test pins a late fold + early seam round-tripping unchanged.
…rer (#2489)

Rebased onto master, where #2929 replaced the three fixed horizontal
x-axis labels with pixel-thinned rotated ones (tStep = ceil(24/barW))
and added a vertical spine line per miss-cause band. The full-view
fixture now gets ticks on seq 1200/1167/.../12 instead of 1/600/1200;
zoomed-window assertions are unchanged (their grids still include the
asserted seqs). Golden regenerated via scripts/update-web-trajectory-golden.ts.
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.465-master.a2a6db3 (rolling master tag).

npm install -g billion-context@0.0.465-master.a2a6db3  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

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.

feat(web): add zoom-to-selection (brush) to the session context-trajectory chart

1 participant